{"version":3,"file":"Application.mjs","sources":["../src/Application.ts"],"sourcesContent":["import { autoDetectRenderer, extensions, ExtensionType } from 'pixijs/core';\nimport { Container } from 'pixijs/display';\n\nimport type { ICanvas, IRenderer, IRendererOptionsAuto, Rectangle } from 'pixijs/core';\nimport type { IDestroyOptions } from 'pixijs/display';\n\n/**\n * Any plugin that's usable for Application should contain these methods.\n * @memberof PIXI\n */\nexport interface IApplicationPlugin\n{\n    /**\n     * Called when Application is constructed, scoped to Application instance.\n     * Passes in `options` as the only argument, which are Application constructor options.\n     * @param {object} options - Application options.\n     */\n    init(options: IApplicationOptions): void;\n    /** Called when destroying Application, scoped to Application instance. */\n    destroy(): void;\n}\n\n/**\n * Application options supplied to constructor.\n * @memberof PIXI\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface IApplicationOptions extends IRendererOptionsAuto, GlobalMixins.IApplicationOptions {}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface Application extends GlobalMixins.Application {}\n\n/**\n * Convenience class to create a new PixiJS application.\n *\n * This class automatically creates the renderer, ticker and root container.\n * @example\n * import { Application, Sprite } from 'pixijs/browser';\n *\n * // Create the application\n * const app = new Application();\n *\n * // Add the view to the DOM\n * document.body.appendChild(app.view);\n *\n * // ex, add display objects\n * app.stage.addChild(Sprite.from('something.png'));\n * @class\n * @memberof PIXI\n */\nexport class Application<VIEW extends ICanvas = ICanvas>\n{\n    /** Collection of installed plugins. */\n    static _plugins: IApplicationPlugin[] = [];\n\n    /**\n     * The root display container that's rendered.\n     * @member {PIXI.Container}\n     */\n    public stage: Container = new Container();\n\n    /**\n     * WebGL renderer if available, otherwise CanvasRenderer.\n     * @member {PIXI.Renderer|PIXI.CanvasRenderer}\n     */\n    public renderer: IRenderer<VIEW>;\n\n    /**\n     * @param {PIXI.IApplicationOptions} [options] - The optional application and renderer parameters.\n     * @param {boolean} [options.antialias=false] -\n     *  **WebGL Only.** Whether to enable anti-aliasing. This may affect performance.\n     * @param {boolean} [options.autoDensity=false] -\n     *  Whether the CSS dimensions of the renderer's view should be resized automatically.\n     * @param {boolean} [options.autoStart=true] - Automatically starts the rendering after the construction.\n     *  **Note**: Setting this parameter to `false` does NOT stop the shared ticker even if you set\n     *  `options.sharedTicker` to `true` in case that it is already started. Stop it by your own.\n     * @param {number|string} [options.background] - Alias for `options.backgroundColor`.\n     * @param {number} [options.backgroundAlpha=1] -\n     *  Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).\n     * @param {number|string} [options.backgroundColor=0x000000] -\n     *  The background color used to clear the canvas. It accepts hex numbers (e.g. `0xff0000`),\n     *  hex strings (e.g. `'#f00'` or `'#ff0000'`) or color names (e.g. `'red'`).\n     * @param {boolean} [options.clearBeforeRender=true] - Whether to clear the canvas before new render passes.\n     * @param {PIXI.IRenderingContext} [options.context] - **WebGL Only.** User-provided WebGL rendering context object.\n     * @param {boolean} [options.forceCanvas=false] -\n     *  Force using {@link PIXI.CanvasRenderer}, even if WebGL is available. This option only is available when\n     *  using **pixijs/browser/legacy** or **pixijs/renderer/canvas** packages, otherwise it will throw an error.\n     * @param {number} [options.height=600] - The height of the renderer's view.\n     * @param {boolean} [options.hello=false] - Whether to log the version and type information of renderer to console.\n     * @param {string} [options.powerPreference] -\n     *  **WebGL Only.** A hint indicating what configuration of GPU is suitable for the WebGL context,\n     *  can be `'default'`, `'high-performance'` or `'low-power'`.\n     *  Setting to `'high-performance'` will prioritize rendering performance over power consumption,\n     *  while setting to `'low-power'` will prioritize power saving over rendering performance.\n     * @param {boolean} [options.premultipliedAlpha=true] -\n     *  **WebGL Only.** Whether the compositor will assume the drawing buffer contains colors with premultiplied alpha.\n     * @param {boolean} [options.preserveDrawingBuffer=false] -\n     *  **WebGL Only.** Whether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve\n     *  its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.\n     * @param {Window|HTMLElement} [options.resizeTo] - Element to automatically resize stage to.\n     * @param {number} [options.resolution=PIXI.settings.RESOLUTION] -\n     *  The resolution / device pixel ratio of the renderer.\n     * @param {boolean} [options.sharedTicker=false] - `true` to use `Ticker.shared`, `false` to create new ticker.\n     *  If set to `false`, you cannot register a handler to occur before anything that runs on the shared ticker.\n     *  The system ticker will always run before both the shared ticker and the app ticker.\n     * @param {boolean|'notMultiplied'} [options.useContextAlpha=true] -\n     *  **Deprecated since 7.0.0, use `premultipliedAlpha` and `backgroundAlpha` instead.** \\\n     *  Pass-through value for canvas' context attribute `alpha`. This option is for cases where the\n     *  canvas needs to be opaque, possibly for performance reasons on some older devices.\n     *  If you want to set transparency, please use `backgroundAlpha`. \\\n     *  **WebGL Only:** When set to `'notMultiplied'`, the canvas' context attribute `alpha` will be\n     *  set to `true` and `premultipliedAlpha` will be to `false`.\n     * @param {PIXI.ICanvas} [options.view=null] -\n     *  The canvas to use as the view. If omitted, a new canvas will be created.\n     * @param {number} [options.width=800] - The width of the renderer's view.\n     */\n    constructor(options?: IApplicationOptions)\n    {\n        // The default options\n        options = Object.assign({\n            forceCanvas: false,\n        }, options);\n\n        this.renderer = autoDetectRenderer<VIEW>(options);\n\n        // install plugins here\n        Application._plugins.forEach((plugin) =>\n        {\n            plugin.init.call(this, options);\n        });\n    }\n\n    /** Render the current stage. */\n    public render(): void\n    {\n        this.renderer.render(this.stage);\n    }\n\n    /**\n     * Reference to the renderer's canvas element.\n     * @member {PIXI.ICanvas}\n     * @readonly\n     */\n    get view(): VIEW\n    {\n        return this.renderer.view;\n    }\n\n    /**\n     * Reference to the renderer's screen rectangle. Its safe to use as `filterArea` or `hitArea` for the whole screen.\n     * @member {PIXI.Rectangle}\n     * @readonly\n     */\n    get screen(): Rectangle\n    {\n        return this.renderer.screen;\n    }\n\n    /**\n     * Destroy and don't use after this.\n     * @param {boolean} [removeView=false] - Automatically remove canvas from DOM.\n     * @param {object|boolean} [stageOptions] - Options parameter. A boolean will act as if all options\n     *  have been set to that value\n     * @param {boolean} [stageOptions.children=false] - if set to true, all the children will have their destroy\n     *  method called as well. 'stageOptions' will be passed on to those calls.\n     * @param {boolean} [stageOptions.texture=false] - Only used for child Sprites if stageOptions.children is set\n     *  to true. Should it destroy the texture of the child sprite\n     * @param {boolean} [stageOptions.baseTexture=false] - Only used for child Sprites if stageOptions.children is set\n     *  to true. Should it destroy the base texture of the child sprite\n     */\n    public destroy(removeView?: boolean, stageOptions?: IDestroyOptions | boolean): void\n    {\n        // Destroy plugins in the opposite order\n        // which they were constructed\n        const plugins = Application._plugins.slice(0);\n\n        plugins.reverse();\n        plugins.forEach((plugin) =>\n        {\n            plugin.destroy.call(this);\n        });\n\n        this.stage.destroy(stageOptions);\n        this.stage = null;\n\n        this.renderer.destroy(removeView);\n        this.renderer = null;\n    }\n}\n\nextensions.handleByList(ExtensionType.Application, Application._plugins);\n"],"names":[],"mappings":";;;AAkDO,MAAM,eAAN,MACP;AAAA,EAiEI,YAAY,OACZ,EAAA;AA1DA,IAAO,IAAA,CAAA,KAAA,GAAmB,IAAI,SAAU,EAAA,CAAA;AA4DpC,IAAA,OAAA,GAAU,OAAO,MAAO,CAAA;AAAA,MACpB,WAAa,EAAA,KAAA;AAAA,OACd,OAAO,CAAA,CAAA;AAEV,IAAK,IAAA,CAAA,QAAA,GAAW,mBAAyB,OAAO,CAAA,CAAA;AAGhD,IAAY,YAAA,CAAA,QAAA,CAAS,OAAQ,CAAA,CAAC,MAC9B,KAAA;AACI,MAAO,MAAA,CAAA,IAAA,CAAK,IAAK,CAAA,IAAA,EAAM,OAAO,CAAA,CAAA;AAAA,KACjC,CAAA,CAAA;AAAA,GACL;AAAA,EAGA,MACA,GAAA;AACI,IAAK,IAAA,CAAA,QAAA,CAAS,MAAO,CAAA,IAAA,CAAK,KAAK,CAAA,CAAA;AAAA,GACnC;AAAA,EAOA,IAAI,IACJ,GAAA;AACI,IAAA,OAAO,KAAK,QAAS,CAAA,IAAA,CAAA;AAAA,GACzB;AAAA,EAOA,IAAI,MACJ,GAAA;AACI,IAAA,OAAO,KAAK,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