{"version":3,"file":"ViewSystem.mjs","sources":["../../src/view/ViewSystem.ts"],"sourcesContent":["import { extensions, ExtensionType } from 'pixijs/extensions';\nimport { Rectangle } from 'pixijs/math';\nimport { settings } from 'pixijs/settings';\n\nimport type { ExtensionMetadata } from 'pixijs/extensions';\nimport type { ICanvas } from 'pixijs/settings';\nimport type { IRenderer } from '../IRenderer';\nimport type { ISystem } from '../system/ISystem';\n\n/**\n * Options passed to the ViewSystem\n * @memberof PIXI\n */\nexport interface ViewOptions\n{\n    /** The width of the screen. */\n    width: number\n    /** The height of the screen. */\n    height: number\n    /** The canvas to use as a view, optional. */\n    view?: ICanvas;\n    /** Resizes renderer view in CSS pixels to allow for resolutions other than 1. */\n    autoDensity?: boolean\n    /** The resolution / device pixel ratio of the renderer. */\n    resolution?: number\n}\n\n/**\n * The view system manages the main canvas that is attached to the DOM.\n * This main role is to deal with how the holding the view reference and dealing with how it is resized.\n * @memberof PIXI\n */\nexport class ViewSystem implements ISystem<ViewOptions, boolean>\n{\n    /** @ignore */\n    static extension: ExtensionMetadata = {\n        type: [\n            ExtensionType.RendererSystem,\n            ExtensionType.CanvasRendererSystem\n        ],\n        name: '_view',\n    };\n\n    private renderer: IRenderer;\n\n    /**\n     * The resolution / device pixel ratio of the renderer.\n     * @member {number}\n     * @default PIXI.settings.RESOLUTION\n     */\n    public resolution: number;\n\n    /**\n     * Measurements of the screen. (0, 0, screenWidth, screenHeight).\n     *\n     * Its safe to use as filterArea or hitArea for the whole stage.\n     * @member {PIXI.Rectangle}\n     */\n    public screen: Rectangle;\n\n    /**\n     * The canvas element that everything is drawn to.\n     * @member {PIXI.ICanvas}\n     */\n    public element: ICanvas;\n\n    /**\n     * Whether CSS dimensions of canvas view should be resized to screen dimensions automatically.\n     * @member {boolean}\n     */\n    public autoDensity: boolean;\n\n    constructor(renderer: IRenderer)\n    {\n        this.renderer = renderer;\n    }\n\n    /**\n     * initiates the view system\n     * @param {PIXI.ViewOptions} options - the options for the view\n     */\n    init(options: ViewOptions): void\n    {\n        this.screen = new Rectangle(0, 0, options.width, options.height);\n\n        this.element = options.view || settings.ADAPTER.createCanvas() as ICanvas;\n\n        this.resolution = options.resolution || settings.RESOLUTION;\n\n        this.autoDensity = !!options.autoDensity;\n    }\n\n    /**\n     * Resizes the screen and canvas to the specified dimensions.\n     * @param desiredScreenWidth - The new width of the screen.\n     * @param desiredScreenHeight - The new height of the screen.\n     */\n    resizeView(desiredScreenWidth: number, desiredScreenHeight: number): void\n    {\n        this.element.width = Math.round(desiredScreenWidth * this.resolution);\n        this.element.height = Math.round(desiredScreenHeight * this.resolution);\n\n        const screenWidth = this.element.width / this.resolution;\n        const screenHeight = this.element.height / this.resolution;\n\n        this.screen.width = screenWidth;\n        this.screen.height = screenHeight;\n\n        if (this.autoDensity)\n        {\n            this.element.style.width = `${screenWidth}px`;\n            this.element.style.height = `${screenHeight}px`;\n        }\n\n        /**\n         * Fired after view has been resized.\n         * @event PIXI.Renderer#resize\n         * @param {number} screenWidth - The new width of the screen.\n         * @param {number} screenHeight - The new height of the screen.\n         */\n        this.renderer.emit('resize', screenWidth, screenHeight);\n        this.renderer.runners.resize.emit(this.screen.width, this.screen.height);\n    }\n\n    /**\n     * Destroys this System and optionally removes the canvas from the dom.\n     * @param {boolean} [removeView=false] - Whether to remove the canvas from the DOM.\n     */\n    destroy(removeView: boolean): void\n    {\n        // ka boom!\n        if (removeView)\n        {\n            this.element.parentNode?.removeChild(this.element);\n        }\n\n        this.renderer = null;\n        this.element = null;\n        this.screen = null;\n    }\n}\n\nextensions.add(ViewSystem);\n"],"names":[],"mappings":";;;;AAgCO,MAAM,UACb,CAAA;AAAA,EAuCI,YAAY,QACZ,EAAA;AACI,IAAA,IAAA,CAAK,QAAW,GAAA,QAAA,CAAA;AAAA,GACpB;AAAA,EAMA,KAAK,OACL,EAAA;AACI,IAAK,IAAA,CAAA,MAAA,GAAS,IAAI,SAAU,CAAA,CAAA,EAAG,GAAG,OAAQ,CAAA,KAAA,EAAO,QAA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