{"version":3,"file":"ResizePlugin.mjs","sources":["../src/ResizePlugin.ts"],"sourcesContent":["import { extensions, ExtensionType } from '@pixi/core';\n\nimport type { ExtensionMetadata, Renderer } from '@pixi/core';\n\ntype ResizeableRenderer = Pick;\n\nexport interface ResizePluginOptions\n{\n /**\n * Element to automatically resize stage to.\n * @memberof PIXI.IApplicationOptions\n */\n resizeTo?: Window | HTMLElement;\n}\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 public static render: () => 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: ResizePluginOptions): 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 this.render();\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\nextensions.add(ResizePlugin);\n"],"names":[],"mappings":";AAoBO,MAAM,aACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBI,OAAO,KAAK,SACZ;AACW,WAAA;AAAA,MAAe;AAAA,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAQxB;AAAA,QACI,IAAI,KACJ;AACI,qBAAW,oBAAoB,UAAU,KAAK,WAAW,GACzD,KAAK,YAAY,KACb,QAEA,WAAW,iBAAiB,UAAU,KAAK,WAAW,GACtD,KAAK,OAAO;AAAA,QAEpB;AAAA,QACA,MACA;AACI,iBAAO,KAAK;AAAA,QAChB;AAAA,MACJ;AAAA,IAAA,GASJ,KAAK,cAAc,MACnB;AACS,WAAK,cAKV,KAAK,aAAa,GAGlB,KAAK,YAAY,sBAAsB,MAAM,KAAK,OAAA,CAAQ;AAAA,IAAA,GAS9D,KAAK,eAAe,MACpB;AACQ,WAAK,cAEL,qBAAqB,KAAK,SAA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