| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /*!
- * @pixi/app - v6.5.10
- * Compiled Thu, 06 Jul 2023 15:25:11 UTC
- *
- * @pixi/app is licensed under the MIT License.
- * http://www.opensource.org/licenses/mit-license
- */
- import { ExtensionType, extensions, autoDetectRenderer } from '@pixi/core';
- import { Container } from '@pixi/display';
- import { deprecation } from '@pixi/utils';
- /**
- * Middleware for for Application's resize functionality
- * @private
- * @class
- */
- var ResizePlugin = /** @class */ (function () {
- function ResizePlugin() {
- }
- /**
- * Initialize the plugin with scope of application instance
- * @static
- * @private
- * @param {object} [options] - See application options
- */
- ResizePlugin.init = function (options) {
- var _this = this;
- Object.defineProperty(this, 'resizeTo',
- /**
- * The HTML element or window to automatically resize the
- * renderer's view element to match width and height.
- * @member {Window|HTMLElement}
- * @name resizeTo
- * @memberof PIXI.Application#
- */
- {
- set: function (dom) {
- globalThis.removeEventListener('resize', this.queueResize);
- this._resizeTo = dom;
- if (dom) {
- globalThis.addEventListener('resize', this.queueResize);
- this.resize();
- }
- },
- get: function () {
- return this._resizeTo;
- },
- });
- /**
- * Resize is throttled, so it's safe to call this multiple times per frame and it'll
- * only be called once.
- * @memberof PIXI.Application#
- * @method queueResize
- * @private
- */
- this.queueResize = function () {
- if (!_this._resizeTo) {
- return;
- }
- _this.cancelResize();
- // // Throttle resize events per raf
- _this._resizeId = requestAnimationFrame(function () { return _this.resize(); });
- };
- /**
- * Cancel the resize queue.
- * @memberof PIXI.Application#
- * @method cancelResize
- * @private
- */
- this.cancelResize = function () {
- if (_this._resizeId) {
- cancelAnimationFrame(_this._resizeId);
- _this._resizeId = null;
- }
- };
- /**
- * Execute an immediate resize on the renderer, this is not
- * throttled and can be expensive to call many times in a row.
- * Will resize only if `resizeTo` property is set.
- * @memberof PIXI.Application#
- * @method resize
- */
- this.resize = function () {
- if (!_this._resizeTo) {
- return;
- }
- // clear queue resize
- _this.cancelResize();
- var width;
- var height;
- // Resize to the window
- if (_this._resizeTo === globalThis.window) {
- width = globalThis.innerWidth;
- height = globalThis.innerHeight;
- }
- // Resize to other HTML entities
- else {
- var _a = _this._resizeTo, clientWidth = _a.clientWidth, clientHeight = _a.clientHeight;
- width = clientWidth;
- height = clientHeight;
- }
- _this.renderer.resize(width, height);
- };
- // On resize
- this._resizeId = null;
- this._resizeTo = null;
- this.resizeTo = options.resizeTo || null;
- };
- /**
- * Clean up the ticker, scoped to application
- * @static
- * @private
- */
- ResizePlugin.destroy = function () {
- globalThis.removeEventListener('resize', this.queueResize);
- this.cancelResize();
- this.cancelResize = null;
- this.queueResize = null;
- this.resizeTo = null;
- this.resize = null;
- };
- /** @ignore */
- ResizePlugin.extension = ExtensionType.Application;
- return ResizePlugin;
- }());
- /**
- * Convenience class to create a new PIXI application.
- *
- * This class automatically creates the renderer, ticker and root container.
- * @example
- * // Create the application
- * const app = new PIXI.Application();
- *
- * // Add the view to the DOM
- * document.body.appendChild(app.view);
- *
- * // ex, add display objects
- * app.stage.addChild(PIXI.Sprite.from('something.png'));
- * @class
- * @memberof PIXI
- */
- var Application = /** @class */ (function () {
- /**
- * @param {PIXI.IApplicationOptions} [options] - The optional application and renderer parameters.
- * @param {boolean} [options.antialias=false] -
- * **WebGL Only.** Whether to enable anti-aliasing. This may affect performance.
- * @param {boolean} [options.autoDensity=false] -
- * Whether the CSS dimensions of the renderer's view should be resized automatically.
- * @param {boolean} [options.autoStart=true] - Automatically starts the rendering after the construction.
- * **Note**: Setting this parameter to false does NOT stop the shared ticker even if you set
- * `options.sharedTicker` to `true` in case that it is already started. Stop it by your own.
- * @param {number} [options.backgroundAlpha=1] -
- * Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).
- * @param {number} [options.backgroundColor=0x000000] -
- * The background color used to clear the canvas. It accepts hex numbers (e.g. `0xff0000`).
- * @param {boolean} [options.clearBeforeRender=true] - Whether to clear the canvas before new render passes.
- * @param {PIXI.IRenderingContext} [options.context] - **WebGL Only.** User-provided WebGL rendering context object.
- * @param {boolean} [options.forceCanvas=false] -
- * Force using {@link PIXI.CanvasRenderer}, even if WebGL is available. This option only is available when
- * using **pixi.js-legacy** or **@pixi/canvas-renderer** packages, otherwise it is ignored.
- * @param {number} [options.height=600] - The height of the renderer's view.
- * @param {string} [options.powerPreference] -
- * **WebGL Only.** A hint indicating what configuration of GPU is suitable for the WebGL context,
- * can be `'default'`, `'high-performance'` or `'low-power'`.
- * Setting to `'high-performance'` will prioritize rendering performance over power consumption,
- * while setting to `'low-power'` will prioritize power saving over rendering performance.
- * @param {boolean} [options.premultipliedAlpha=true] -
- * **WebGL Only.** Whether the compositor will assume the drawing buffer contains colors with premultiplied alpha.
- * @param {boolean} [options.preserveDrawingBuffer=false] -
- * **WebGL Only.** Whether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve
- * its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.
- * @param {Window|HTMLElement} [options.resizeTo] - Element to automatically resize stage to.
- * @param {number} [options.resolution=PIXI.settings.RESOLUTION] -
- * The resolution / device pixel ratio of the renderer.
- * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.Loader.shared, `false` to create new Loader.
- * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker.
- * If set to `false`, you cannot register a handler to occur before anything that runs on the shared ticker.
- * The system ticker will always run before both the shared ticker and the app ticker.
- * @param {boolean} [options.transparent] -
- * **Deprecated since 6.0.0, Use `backgroundAlpha` instead.** \
- * `true` sets `backgroundAlpha` to `0`, `false` sets `backgroundAlpha` to `1`.
- * @param {boolean|'notMultiplied'} [options.useContextAlpha=true] -
- * Pass-through value for canvas' context attribute `alpha`. This option is for cases where the
- * canvas needs to be opaque, possibly for performance reasons on some older devices.
- * If you want to set transparency, please use `backgroundAlpha`. \
- * **WebGL Only:** When set to `'notMultiplied'`, the canvas' context attribute `alpha` will be
- * set to `true` and `premultipliedAlpha` will be to `false`.
- * @param {HTMLCanvasElement} [options.view=null] -
- * The canvas to use as the view. If omitted, a new canvas will be created.
- * @param {number} [options.width=800] - The width of the renderer's view.
- */
- function Application(options) {
- var _this = this;
- /**
- * The root display container that's rendered.
- * @member {PIXI.Container}
- */
- this.stage = new Container();
- // The default options
- options = Object.assign({
- forceCanvas: false,
- }, options);
- this.renderer = autoDetectRenderer(options);
- // install plugins here
- Application._plugins.forEach(function (plugin) {
- plugin.init.call(_this, options);
- });
- }
- /**
- * Use the {@link PIXI.extensions.add} API to register plugins.
- * @deprecated since 6.5.0
- * @static
- * @param {PIXI.IApplicationPlugin} plugin - Plugin being installed
- */
- Application.registerPlugin = function (plugin) {
- deprecation('6.5.0', 'Application.registerPlugin() is deprecated, use extensions.add()');
- extensions.add({
- type: ExtensionType.Application,
- ref: plugin,
- });
- };
- /** Render the current stage. */
- Application.prototype.render = function () {
- this.renderer.render(this.stage);
- };
- Object.defineProperty(Application.prototype, "view", {
- /**
- * Reference to the renderer's canvas element.
- * @member {HTMLCanvasElement}
- * @readonly
- */
- get: function () {
- return this.renderer.view;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(Application.prototype, "screen", {
- /**
- * Reference to the renderer's screen rectangle. Its safe to use as `filterArea` or `hitArea` for the whole screen.
- * @member {PIXI.Rectangle}
- * @readonly
- */
- get: function () {
- return this.renderer.screen;
- },
- enumerable: false,
- configurable: true
- });
- /**
- * Destroy and don't use after this.
- * @param {boolean} [removeView=false] - Automatically remove canvas from DOM.
- * @param {object|boolean} [stageOptions] - Options parameter. A boolean will act as if all options
- * have been set to that value
- * @param {boolean} [stageOptions.children=false] - if set to true, all the children will have their destroy
- * method called as well. 'stageOptions' will be passed on to those calls.
- * @param {boolean} [stageOptions.texture=false] - Only used for child Sprites if stageOptions.children is set
- * to true. Should it destroy the texture of the child sprite
- * @param {boolean} [stageOptions.baseTexture=false] - Only used for child Sprites if stageOptions.children is set
- * to true. Should it destroy the base texture of the child sprite
- */
- Application.prototype.destroy = function (removeView, stageOptions) {
- var _this = this;
- // Destroy plugins in the opposite order
- // which they were constructed
- var plugins = Application._plugins.slice(0);
- plugins.reverse();
- plugins.forEach(function (plugin) {
- plugin.destroy.call(_this);
- });
- this.stage.destroy(stageOptions);
- this.stage = null;
- this.renderer.destroy(removeView);
- this.renderer = null;
- };
- /** Collection of installed plugins. */
- Application._plugins = [];
- return Application;
- }());
- extensions.handleByList(ExtensionType.Application, Application._plugins);
- extensions.add(ResizePlugin);
- export { Application, ResizePlugin };
- //# sourceMappingURL=app.mjs.map
|