| 1 |
- {"version":3,"file":"app.mjs","sources":["../../src/ResizePlugin.ts","../../src/Application.ts","../../src/index.ts"],"sourcesContent":["import type { ExtensionMetadata, Renderer } from '@pixi/core';\nimport { ExtensionType } from '@pixi/core';\nimport type { IApplicationOptions } from './Application';\n\ntype ResizeableRenderer = Pick<Renderer, 'resize'>;\n\n/**\n * Middleware for for Application's resize functionality\n * @private\n * @class\n */\nexport class ResizePlugin\n{\n /** @ignore */\n static extension: ExtensionMetadata = ExtensionType.Application;\n\n public static resizeTo: Window | HTMLElement;\n public static resize: () => void;\n public static renderer: ResizeableRenderer;\n public static queueResize: () => void;\n private static _resizeId: number;\n private static _resizeTo: Window | HTMLElement;\n private static cancelResize: () => void;\n\n /**\n * Initialize the plugin with scope of application instance\n * @static\n * @private\n * @param {object} [options] - See application options\n */\n static init(options?: IApplicationOptions): void\n {\n Object.defineProperty(this, 'resizeTo',\n /**\n * The HTML element or window to automatically resize the\n * renderer's view element to match width and height.\n * @member {Window|HTMLElement}\n * @name resizeTo\n * @memberof PIXI.Application#\n */\n {\n set(dom: Window | HTMLElement)\n {\n globalThis.removeEventListener('resize', this.queueResize);\n this._resizeTo = dom;\n if (dom)\n {\n globalThis.addEventListener('resize', this.queueResize);\n this.resize();\n }\n },\n get()\n {\n return this._resizeTo;\n },\n });\n\n /**\n * Resize is throttled, so it's safe to call this multiple times per frame and it'll\n * only be called once.\n * @memberof PIXI.Application#\n * @method queueResize\n * @private\n */\n this.queueResize = (): void =>\n {\n if (!this._resizeTo)\n {\n return;\n }\n\n this.cancelResize();\n\n // // Throttle resize events per raf\n this._resizeId = requestAnimationFrame(() => this.resize());\n };\n\n /**\n * Cancel the resize queue.\n * @memberof PIXI.Application#\n * @method cancelResize\n * @private\n */\n this.cancelResize = (): void =>\n {\n if (this._resizeId)\n {\n cancelAnimationFrame(this._resizeId);\n this._resizeId = null;\n }\n };\n\n /**\n * Execute an immediate resize on the renderer, this is not\n * throttled and can be expensive to call many times in a row.\n * Will resize only if `resizeTo` property is set.\n * @memberof PIXI.Application#\n * @method resize\n */\n this.resize = (): void =>\n {\n if (!this._resizeTo)\n {\n return;\n }\n\n // clear queue resize\n this.cancelResize();\n\n let width: number;\n let height: number;\n\n // Resize to the window\n if (this._resizeTo === globalThis.window)\n {\n width = globalThis.innerWidth;\n height = globalThis.innerHeight;\n }\n // Resize to other HTML entities\n else\n {\n const { clientWidth, clientHeight } = this._resizeTo as HTMLElement;\n\n width = clientWidth;\n height = clientHeight;\n }\n\n this.renderer.resize(width, height);\n };\n\n // On resize\n this._resizeId = null;\n this._resizeTo = null;\n this.resizeTo = options.resizeTo || null;\n }\n\n /**\n * Clean up the ticker, scoped to application\n * @static\n * @private\n */\n static destroy(): void\n {\n globalThis.removeEventListener('resize', this.queueResize);\n this.cancelResize();\n this.cancelResize = null;\n this.queueResize = null;\n this.resizeTo = null;\n this.resize = null;\n }\n}\n","import { Container } from '@pixi/display';\nimport { autoDetectRenderer, extensions, ExtensionType } from '@pixi/core';\n\nimport type { Rectangle } from '@pixi/math';\nimport type { Renderer, IRendererOptionsAuto, AbstractRenderer } from '@pixi/core';\nimport type { IDestroyOptions } from '@pixi/display';\nimport { deprecation } from '@pixi/utils';\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 PIXI application.\n *\n * This class automatically creates the renderer, ticker and root container.\n * @example\n * // Create the application\n * const app = new PIXI.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(PIXI.Sprite.from('something.png'));\n * @class\n * @memberof PIXI\n */\nexport class Application\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: Renderer | AbstractRenderer;\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} [options.backgroundAlpha=1] -\n * Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).\n * @param {number} [options.backgroundColor=0x000000] -\n * The background color used to clear the canvas. It accepts hex numbers (e.g. `0xff0000`).\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 **pixi.js-legacy** or **@pixi/canvas-renderer** packages, otherwise it is ignored.\n * @param {number} [options.height=600] - The height of the renderer's view.\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.sharedLoader=false] - `true` to use PIXI.Loader.shared, `false` to create new Loader.\n * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.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} [options.transparent] -\n * **Deprecated since 6.0.0, Use `backgroundAlpha` instead.** \\\n * `true` sets `backgroundAlpha` to `0`, `false` sets `backgroundAlpha` to `1`.\n * @param {boolean|'notMultiplied'} [options.useContextAlpha=true] -\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 {HTMLCanvasElement} [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(options);\n\n // install plugins here\n Application._plugins.forEach((plugin) =>\n {\n plugin.init.call(this, options);\n });\n }\n\n /**\n * Use the {@link PIXI.extensions.add} API to register plugins.\n * @deprecated since 6.5.0\n * @static\n * @param {PIXI.IApplicationPlugin} plugin - Plugin being installed\n */\n static registerPlugin(plugin: IApplicationPlugin): void\n {\n // #if _DEBUG\n deprecation('6.5.0', 'Application.registerPlugin() is deprecated, use extensions.add()');\n // #endif\n extensions.add({\n type: ExtensionType.Application,\n ref: plugin,\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 {HTMLCanvasElement}\n * @readonly\n */\n get view(): HTMLCanvasElement\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","import { ResizePlugin } from './ResizePlugin';\nimport { extensions } from '@pixi/core';\n\nextensions.add(ResizePlugin);\n\nexport * from './Application';\nexport { ResizePlugin };\n"],"names":[],"mappings":";;;;;;;;;;;AAMA;;;;AAIG;AACH,IAAA,YAAA,kBAAA,YAAA;AAAA,IAAA,SAAA,YAA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