{"version":3,"file":"autoDetectRenderer.mjs","sources":["../src/autoDetectRenderer.ts"],"sourcesContent":["import { extensions, ExtensionType } from 'pixijs/extensions';\n\nimport type { ICanvas } from 'pixijs/settings';\nimport type { IRenderer, IRendererOptions } from './IRenderer';\n\n/**\n * Renderer options supplied to `autoDetectRenderer`.\n * @memberof PIXI\n */\nexport interface IRendererOptionsAuto extends IRendererOptions\n{\n    forceCanvas?: boolean;\n}\n\nexport interface IRendererConstructor<VIEW extends ICanvas = ICanvas>\n{\n    test(options?: IRendererOptionsAuto): boolean;\n    new (options?: IRendererOptionsAuto): IRenderer<VIEW>;\n}\n\n/**\n * Collection of installed Renderers.\n * @ignore\n */\nconst renderers: IRendererConstructor<ICanvas>[] = [];\n\nextensions.handleByList(ExtensionType.Renderer, renderers);\n\n/**\n * This helper function will automatically detect which renderer you should be using.\n * WebGL is the preferred renderer as it is a lot faster. If WebGL is not supported by\n * the browser then this function will return a canvas renderer.\n * @memberof PIXI\n * @function autoDetectRenderer\n * @param {PIXI.IRendererOptionsAuto} [options] - The optional 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 {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 {number} [options.resolution=PIXI.settings.RESOLUTION] -\n *  The resolution / device pixel ratio of the renderer.\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 * @returns Returns {@link PIXI.Renderer} if WebGL is available, otherwise {@link PIXI.CanvasRenderer}.\n */\nexport function autoDetectRenderer<VIEW extends ICanvas = ICanvas>(options?: IRendererOptionsAuto): IRenderer<VIEW>\n{\n    for (const RendererType of renderers)\n    {\n        if (RendererType.test(options))\n        {\n            return new RendererType(options) as IRenderer<VIEW>;\n        }\n    }\n\n    throw new Error('Unable to auto-detect a suitable renderer.');\n}\n"],"names":[],"mappings":";;AAwBA,MAAM,YAA6C,EAAC,CAAA;AAEpD,UAAW,CAAA,YAAA,CAAa,aAAc,CAAA,QAAA,EAAU,SAAS,CAAA,CAAA;AAkDlD,SAAA,kBAAA,CAA4D,OACnE,EAAA;AACI,EAAA,KAAA,MAAW,gBAAgB,SAC3B,EAAA;AACI,IAAI,IAAA,YAAA,CAAa,IAAK,CAAA,OAAO,CAC7B,EAAA;AACI,MAAO,OAAA,IAAI,aAAa,OAAO,CAAA,CAAA;AAAA,KACnC;AAAA,GACJ;AAEA,EAAM,MAAA,IAAI,MAAM,4CAA4C,CAAA,CAAA;AAChE;;;;"}