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

@pixi/ticker

Package Overview
Dependencies
Maintainers
2
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/ticker - npm Package Compare versions

Comparing version 7.2.4 to 7.3.0-rc

15

lib/const.js

@@ -1,15 +0,4 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var UPDATE_PRIORITY = /* @__PURE__ */ ((UPDATE_PRIORITY2) => {
UPDATE_PRIORITY2[UPDATE_PRIORITY2["INTERACTION"] = 50] = "INTERACTION";
UPDATE_PRIORITY2[UPDATE_PRIORITY2["HIGH"] = 25] = "HIGH";
UPDATE_PRIORITY2[UPDATE_PRIORITY2["NORMAL"] = 0] = "NORMAL";
UPDATE_PRIORITY2[UPDATE_PRIORITY2["LOW"] = -25] = "LOW";
UPDATE_PRIORITY2[UPDATE_PRIORITY2["UTILITY"] = -50] = "UTILITY";
return UPDATE_PRIORITY2;
})(UPDATE_PRIORITY || {});
"use strict";
var UPDATE_PRIORITY = /* @__PURE__ */ ((UPDATE_PRIORITY2) => (UPDATE_PRIORITY2[UPDATE_PRIORITY2.INTERACTION = 50] = "INTERACTION", UPDATE_PRIORITY2[UPDATE_PRIORITY2.HIGH = 25] = "HIGH", UPDATE_PRIORITY2[UPDATE_PRIORITY2.NORMAL = 0] = "NORMAL", UPDATE_PRIORITY2[UPDATE_PRIORITY2.LOW = -25] = "LOW", UPDATE_PRIORITY2[UPDATE_PRIORITY2.UTILITY = -50] = "UTILITY", UPDATE_PRIORITY2))(UPDATE_PRIORITY || {});
exports.UPDATE_PRIORITY = UPDATE_PRIORITY;
//# sourceMappingURL=const.js.map

14

lib/index.js

@@ -1,12 +0,4 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
require('./settings.js');
var _const = require('./const.js');
var Ticker = require('./Ticker.js');
var TickerPlugin = require('./TickerPlugin.js');
"use strict";
require("./settings.js");
var _const = require("./const.js"), Ticker = require("./Ticker.js"), TickerPlugin = require("./TickerPlugin.js");
exports.UPDATE_PRIORITY = _const.UPDATE_PRIORITY;

@@ -13,0 +5,0 @@ exports.Ticker = Ticker.Ticker;

@@ -1,10 +0,13 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var settings = require('@pixi/settings');
var utils = require('@pixi/utils');
var Ticker = require('./Ticker.js');
"use strict";
var settings = require("@pixi/settings"), utils = require("@pixi/utils"), Ticker = require("./Ticker.js");
Object.defineProperties(settings.settings, {
/**
* Target frames per millisecond.
* @static
* @name TARGET_FPMS
* @memberof PIXI.settings
* @type {number}
* @deprecated since 7.1.0
* @see PIXI.Ticker.targetFPMS
*/
TARGET_FPMS: {

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

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

@@ -1,66 +0,72 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _const = require('./const.js');
var TickerListener = require('./TickerListener.js');
const _Ticker = class {
"use strict";
var _const = require("./const.js"), TickerListener = require("./TickerListener.js");
const _Ticker = class _Ticker2 {
constructor() {
this.autoStart = false;
this.deltaTime = 1;
this.lastTime = -1;
this.speed = 1;
this.started = false;
this._requestId = null;
this._maxElapsedMS = 100;
this._minElapsedMS = 0;
this._protected = false;
this._lastFrame = -1;
this._head = new TickerListener.TickerListener(null, null, Infinity);
this.deltaMS = 1 / _Ticker.targetFPMS;
this.elapsedMS = 1 / _Ticker.targetFPMS;
this._tick = (time) => {
this._requestId = null;
if (this.started) {
this.update(time);
if (this.started && this._requestId === null && this._head.next) {
this._requestId = requestAnimationFrame(this._tick);
}
}
this.autoStart = !1, this.deltaTime = 1, this.lastTime = -1, this.speed = 1, this.started = !1, this._requestId = null, this._maxElapsedMS = 100, this._minElapsedMS = 0, this._protected = !1, this._lastFrame = -1, this._head = new TickerListener.TickerListener(null, null, 1 / 0), this.deltaMS = 1 / _Ticker2.targetFPMS, this.elapsedMS = 1 / _Ticker2.targetFPMS, this._tick = (time) => {
this._requestId = null, this.started && (this.update(time), this.started && this._requestId === null && this._head.next && (this._requestId = requestAnimationFrame(this._tick)));
};
}
/**
* Conditionally requests a new animation frame.
* If a frame has not already been requested, and if the internal
* emitter has listeners, a new frame is requested.
* @private
*/
_requestIfNeeded() {
if (this._requestId === null && this._head.next) {
this.lastTime = performance.now();
this._lastFrame = this.lastTime;
this._requestId = requestAnimationFrame(this._tick);
}
this._requestId === null && this._head.next && (this.lastTime = performance.now(), this._lastFrame = this.lastTime, this._requestId = requestAnimationFrame(this._tick));
}
/**
* Conditionally cancels a pending animation frame.
* @private
*/
_cancelIfNeeded() {
if (this._requestId !== null) {
cancelAnimationFrame(this._requestId);
this._requestId = null;
}
this._requestId !== null && (cancelAnimationFrame(this._requestId), this._requestId = null);
}
/**
* Conditionally requests a new animation frame.
* If the ticker has been started it checks if a frame has not already
* been requested, and if the internal emitter has listeners. If these
* conditions are met, a new frame is requested. If the ticker has not
* been started, but autoStart is `true`, then the ticker starts now,
* and continues with the previous conditions to request a new frame.
* @private
*/
_startIfPossible() {
if (this.started) {
this._requestIfNeeded();
} else if (this.autoStart) {
this.start();
}
this.started ? this._requestIfNeeded() : this.autoStart && this.start();
}
/**
* Register a handler for tick events. Calls continuously unless
* it is removed or the ticker is stopped.
* @param fn - The listener function to be added for updates
* @param context - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns This instance of a ticker
*/
add(fn, context, priority = _const.UPDATE_PRIORITY.NORMAL) {
return this._addListener(new TickerListener.TickerListener(fn, context, priority));
}
/**
* Add a handler for the tick event which is only execute once.
* @param fn - The listener function to be added for one update
* @param context - The listener context
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting
* @returns This instance of a ticker
*/
addOnce(fn, context, priority = _const.UPDATE_PRIORITY.NORMAL) {
return this._addListener(new TickerListener.TickerListener(fn, context, priority, true));
return this._addListener(new TickerListener.TickerListener(fn, context, priority, !0));
}
/**
* Internally adds the event handler so that it can be sorted by priority.
* Priority allows certain handler (user, AnimatedSprite, Interaction) to be run
* before the rendering.
* @private
* @param listener - Current listener being added.
* @returns This instance of a ticker
*/
_addListener(listener) {
let current = this._head.next;
let previous = this._head;
if (!current) {
let current = this._head.next, previous = this._head;
if (!current)
listener.connect(previous);
} else {
while (current) {
else {
for (; current; ) {
if (listener.priority > current.priority) {

@@ -70,49 +76,43 @@ listener.connect(previous);

}
previous = current;
current = current.next;
previous = current, current = current.next;
}
if (!listener.previous) {
listener.connect(previous);
}
listener.previous || listener.connect(previous);
}
this._startIfPossible();
return this;
return this._startIfPossible(), this;
}
/**
* Removes any handlers matching the function and context parameters.
* If no handlers are left after removing, then it cancels the animation frame.
* @param fn - The listener function to be removed
* @param context - The listener context to be removed
* @returns This instance of a ticker
*/
remove(fn, context) {
let listener = this._head.next;
while (listener) {
if (listener.match(fn, context)) {
listener = listener.destroy();
} else {
listener = listener.next;
}
}
if (!this._head.next) {
this._cancelIfNeeded();
}
return this;
for (; listener; )
listener.match(fn, context) ? listener = listener.destroy() : listener = listener.next;
return this._head.next || this._cancelIfNeeded(), this;
}
/**
* The number of listeners on this ticker, calculated by walking through linked list
* @readonly
* @member {number}
*/
get count() {
if (!this._head) {
if (!this._head)
return 0;
}
let count = 0;
let current = this._head;
while (current = current.next) {
let count = 0, current = this._head;
for (; current = current.next; )
count++;
}
return count;
}
/** Starts the ticker. If the ticker has listeners a new animation frame is requested at this point. */
start() {
if (!this.started) {
this.started = true;
this._requestIfNeeded();
}
this.started || (this.started = !0, this._requestIfNeeded());
}
/** Stops the ticker. If the ticker has requested an animation frame it is canceled at this point. */
stop() {
if (this.started) {
this.started = false;
this._cancelIfNeeded();
}
this.started && (this.started = !1, this._cancelIfNeeded());
}
/** Destroy the ticker and don't use after this. Calling this method removes all references to internal events. */
destroy() {

@@ -122,42 +122,60 @@ if (!this._protected) {

let listener = this._head.next;
while (listener) {
listener = listener.destroy(true);
}
this._head.destroy();
this._head = null;
for (; listener; )
listener = listener.destroy(!0);
this._head.destroy(), this._head = null;
}
}
/**
* Triggers an update. An update entails setting the
* current {@link PIXI.Ticker#elapsedMS},
* the current {@link PIXI.Ticker#deltaTime},
* invoking all listeners with current deltaTime,
* and then finally setting {@link PIXI.Ticker#lastTime}
* with the value of currentTime that was provided.
* This method will be called automatically by animation
* frame callbacks if the ticker instance has been started
* and listeners are added.
* @param {number} [currentTime=performance.now()] - the current time of execution
*/
update(currentTime = performance.now()) {
let elapsedMS;
if (currentTime > this.lastTime) {
elapsedMS = this.elapsedMS = currentTime - this.lastTime;
if (elapsedMS > this._maxElapsedMS) {
elapsedMS = this._maxElapsedMS;
}
elapsedMS *= this.speed;
if (this._minElapsedMS) {
if (elapsedMS = this.elapsedMS = currentTime - this.lastTime, elapsedMS > this._maxElapsedMS && (elapsedMS = this._maxElapsedMS), elapsedMS *= this.speed, this._minElapsedMS) {
const delta = currentTime - this._lastFrame | 0;
if (delta < this._minElapsedMS) {
if (delta < this._minElapsedMS)
return;
}
this._lastFrame = currentTime - delta % this._minElapsedMS;
}
this.deltaMS = elapsedMS;
this.deltaTime = this.deltaMS * _Ticker.targetFPMS;
this.deltaMS = elapsedMS, this.deltaTime = this.deltaMS * _Ticker2.targetFPMS;
const head = this._head;
let listener = head.next;
while (listener) {
for (; listener; )
listener = listener.emit(this.deltaTime);
}
if (!head.next) {
this._cancelIfNeeded();
}
} else {
head.next || this._cancelIfNeeded();
} else
this.deltaTime = this.deltaMS = this.elapsedMS = 0;
}
this.lastTime = currentTime;
}
/**
* The frames per second at which this ticker is running.
* The default is approximately 60 in most modern browsers.
* **Note:** This does not factor in the value of
* {@link PIXI.Ticker#speed}, which is specific
* to scaling {@link PIXI.Ticker#deltaTime}.
* @member {number}
* @readonly
*/
get FPS() {
return 1e3 / this.elapsedMS;
}
/**
* Manages the maximum amount of milliseconds allowed to
* elapse between invoking {@link PIXI.Ticker#update}.
* This value is used to cap {@link PIXI.Ticker#deltaTime},
* but does not effect the measured value of {@link PIXI.Ticker#FPS}.
* When setting this property it is clamped to a value between
* `0` and `Ticker.targetFPMS * 1000`.
* @member {number}
* @default 10
*/
get minFPS() {

@@ -167,16 +185,21 @@ return 1e3 / this._maxElapsedMS;

set minFPS(fps) {
const minFPS = Math.min(this.maxFPS, fps);
const minFPMS = Math.min(Math.max(0, minFPS) / 1e3, _Ticker.targetFPMS);
const minFPS = Math.min(this.maxFPS, fps), minFPMS = Math.min(Math.max(0, minFPS) / 1e3, _Ticker2.targetFPMS);
this._maxElapsedMS = 1 / minFPMS;
}
/**
* Manages the minimum amount of milliseconds required to
* elapse between invoking {@link PIXI.Ticker#update}.
* This will effect the measured value of {@link PIXI.Ticker#FPS}.
* If it is set to `0`, then there is no limit; PixiJS will render as many frames as it can.
* Otherwise it will be at least `minFPS`
* @member {number}
* @default 0
*/
get maxFPS() {
if (this._minElapsedMS) {
return Math.round(1e3 / this._minElapsedMS);
}
return 0;
return this._minElapsedMS ? Math.round(1e3 / this._minElapsedMS) : 0;
}
set maxFPS(fps) {
if (fps === 0) {
if (fps === 0)
this._minElapsedMS = 0;
} else {
else {
const maxFPS = Math.max(this.minFPS, fps);

@@ -186,23 +209,72 @@ this._minElapsedMS = 1 / (maxFPS / 1e3);

}
/**
* The shared ticker instance used by {@link PIXI.AnimatedSprite} and by
* {@link PIXI.VideoResource} to update animation frames / video textures.
*
* It may also be used by {@link PIXI.Application} if created with the `sharedTicker` option property set to true.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
* Please follow the examples for usage, including how to opt-out of auto-starting the shared ticker.
* @example
* import { Ticker } from 'pixi.js';
*
* const ticker = Ticker.shared;
* // Set this to prevent starting this ticker when listeners are added.
* // By default this is true only for the PIXI.Ticker.shared instance.
* ticker.autoStart = false;
*
* // FYI, call this to ensure the ticker is stopped. It should be stopped
* // if you have not attempted to render anything yet.
* ticker.stop();
*
* // Call this when you are ready for a running shared ticker.
* ticker.start();
* @example
* import { autoDetectRenderer, Container } from 'pixi.js';
*
* // You may use the shared ticker to render...
* const renderer = autoDetectRenderer();
* const stage = new Container();
* document.body.appendChild(renderer.view);
* ticker.add((time) => renderer.render(stage));
*
* // Or you can just update it manually.
* ticker.autoStart = false;
* ticker.stop();
* const animate = (time) => {
* ticker.update(time);
* renderer.render(stage);
* requestAnimationFrame(animate);
* };
* animate(performance.now());
* @member {PIXI.Ticker}
* @static
*/
static get shared() {
if (!_Ticker._shared) {
const shared = _Ticker._shared = new _Ticker();
shared.autoStart = true;
shared._protected = true;
if (!_Ticker2._shared) {
const shared = _Ticker2._shared = new _Ticker2();
shared.autoStart = !0, shared._protected = !0;
}
return _Ticker._shared;
return _Ticker2._shared;
}
/**
* The system ticker instance used by {@link PIXI.BasePrepare} for core timing
* functionality that shouldn't usually need to be paused, unlike the `shared`
* ticker which drives visual animations and rendering which may want to be paused.
*
* The property {@link PIXI.Ticker#autoStart} is set to `true` for this instance.
* @member {PIXI.Ticker}
* @static
*/
static get system() {
if (!_Ticker._system) {
const system = _Ticker._system = new _Ticker();
system.autoStart = true;
system._protected = true;
if (!_Ticker2._system) {
const system = _Ticker2._system = new _Ticker2();
system.autoStart = !0, system._protected = !0;
}
return _Ticker._system;
return _Ticker2._system;
}
};
_Ticker.targetFPMS = 0.06;
let Ticker = _Ticker;
Ticker.targetFPMS = 0.06;
exports.Ticker = Ticker;
//# sourceMappingURL=Ticker.js.map

@@ -1,61 +0,57 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
"use strict";
class TickerListener {
constructor(fn, context = null, priority = 0, once = false) {
this.next = null;
this.previous = null;
this._destroyed = false;
this.fn = fn;
this.context = context;
this.priority = priority;
this.once = once;
/**
* Constructor
* @private
* @param fn - The listener function to be added for one update
* @param context - The listener context
* @param priority - The priority for emitting
* @param once - If the handler should fire once
*/
constructor(fn, context = null, priority = 0, once = !1) {
this.next = null, this.previous = null, this._destroyed = !1, this.fn = fn, this.context = context, this.priority = priority, this.once = once;
}
/**
* Simple compare function to figure out if a function and context match.
* @private
* @param fn - The listener function to be added for one update
* @param context - The listener context
* @returns `true` if the listener match the arguments
*/
match(fn, context = null) {
return this.fn === fn && this.context === context;
}
/**
* Emit by calling the current function.
* @private
* @param deltaTime - time since the last emit.
* @returns Next ticker
*/
emit(deltaTime) {
if (this.fn) {
if (this.context) {
this.fn.call(this.context, deltaTime);
} else {
this.fn(deltaTime);
}
}
this.fn && (this.context ? this.fn.call(this.context, deltaTime) : this.fn(deltaTime));
const redirect = this.next;
if (this.once) {
this.destroy(true);
}
if (this._destroyed) {
this.next = null;
}
return redirect;
return this.once && this.destroy(!0), this._destroyed && (this.next = null), redirect;
}
/**
* Connect to the list.
* @private
* @param previous - Input node, previous listener
*/
connect(previous) {
this.previous = previous;
if (previous.next) {
previous.next.previous = this;
}
this.next = previous.next;
previous.next = this;
this.previous = previous, previous.next && (previous.next.previous = this), this.next = previous.next, previous.next = this;
}
destroy(hard = false) {
this._destroyed = true;
this.fn = null;
this.context = null;
if (this.previous) {
this.previous.next = this.next;
}
if (this.next) {
this.next.previous = this.previous;
}
/**
* Destroy and don't use after this.
* @private
* @param hard - `true` to remove the `next` reference, this
* is considered a hard destroy. Soft destroy maintains the next reference.
* @returns The listener to redirect while emitting or removing.
*/
destroy(hard = !1) {
this._destroyed = !0, this.fn = null, this.context = null, this.previous && (this.previous.next = this.next), this.next && (this.next.previous = this.previous);
const redirect = this.next;
this.next = hard ? null : redirect;
this.previous = null;
return redirect;
return this.next = hard ? null : redirect, this.previous = null, redirect;
}
}
exports.TickerListener = TickerListener;
//# sourceMappingURL=TickerListener.js.map

@@ -1,46 +0,40 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var extensions = require('@pixi/extensions');
var _const = require('./const.js');
var Ticker = require('./Ticker.js');
"use strict";
var extensions = require("@pixi/extensions"), _const = require("./const.js"), Ticker = require("./Ticker.js");
class TickerPlugin {
/**
* Initialize the plugin with scope of application instance
* @static
* @private
* @param {object} [options] - See application options
*/
static init(options) {
options = Object.assign({
autoStart: true,
sharedTicker: false
}, options);
Object.defineProperty(this, "ticker", {
set(ticker) {
if (this._ticker) {
this._ticker.remove(this.render, this);
autoStart: !0,
sharedTicker: !1
}, options), Object.defineProperty(
this,
"ticker",
{
set(ticker) {
this._ticker && this._ticker.remove(this.render, this), this._ticker = ticker, ticker && ticker.add(this.render, this, _const.UPDATE_PRIORITY.LOW);
},
get() {
return this._ticker;
}
this._ticker = ticker;
if (ticker) {
ticker.add(this.render, this, _const.UPDATE_PRIORITY.LOW);
}
},
get() {
return this._ticker;
}
});
this.stop = () => {
), this.stop = () => {
this._ticker.stop();
};
this.start = () => {
}, this.start = () => {
this._ticker.start();
};
this._ticker = null;
this.ticker = options.sharedTicker ? Ticker.Ticker.shared : new Ticker.Ticker();
if (options.autoStart) {
this.start();
}
}, this._ticker = null, this.ticker = options.sharedTicker ? Ticker.Ticker.shared : new Ticker.Ticker(), options.autoStart && this.start();
}
/**
* Clean up the ticker, scoped to application.
* @static
* @private
*/
static destroy() {
if (this._ticker) {
const oldTicker = this._ticker;
this.ticker = null;
oldTicker.destroy();
this.ticker = null, oldTicker.destroy();
}

@@ -51,4 +45,3 @@ }

extensions.extensions.add(TickerPlugin);
exports.TickerPlugin = TickerPlugin;
//# sourceMappingURL=TickerPlugin.js.map
{
"name": "@pixi/ticker",
"version": "7.2.4",
"version": "7.3.0-rc",
"main": "lib/index.js",

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

"dependencies": {
"@pixi/extensions": "7.2.4",
"@pixi/settings": "7.2.4",
"@pixi/utils": "7.2.4"
"@pixi/extensions": "7.3.0-rc",
"@pixi/settings": "7.3.0-rc",
"@pixi/utils": "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