{"version":3,"file":"ZoomBlurFilter.mjs","sources":["../../src/zoom-blur/ZoomBlurFilter.ts"],"sourcesContent":["import { Filter, GlProgram, GpuProgram, PointData } from 'pixi.js';\nimport { vertex, wgslVertex } from '../defaults';\nimport fragment from './zoom-blur.frag';\nimport source from './zoom-blur.wgsl';\n\n/** Options for the ZoomBlurFilter constructor. */\nexport interface ZoomBlurFilterOptions\n{\n    /**\n     * Sets the strength of the zoom blur effect\n     * @default 0.1\n     */\n    strength?: number;\n    /**\n     * The `x` and `y` offset coordinates to change the position of the center of the circle of effect.\n     * This should be a size 2 array or an object containing `x` and `y` values, you cannot change types\n     * once defined in the constructor\n     * @default {x:0,y:0}\n     */\n    center?: PointData | number[];\n    /**\n     * The inner radius of zoom. The part in inner circle won't apply zoom blur effect\n     * @default 0\n     */\n    innerRadius?: number;\n    /**\n     * Outer radius of the effect. less than `0` equates to infinity\n     * @default -1\n     */\n    radius?: number;\n    /**\n     * On older iOS devices, it's better to not go above `13.0`.\n     * Decreasing this value will produce a lower-quality blur effect with more dithering\n     * @default 32\n     */\n    maxKernelSize?: number;\n}\n\n/**\n * The ZoomFilter applies a Zoom blur to an object.<br>\n * ![original](../screenshots/original.png)![filter](../screenshots/zoom-blur.png)\n *\n * @class\n * @extends Filter\n */\nexport class ZoomBlurFilter extends Filter\n{\n    /** Default values for options. */\n    public static readonly DEFAULT_OPTIONS: ZoomBlurFilterOptions = {\n        strength: 0.1,\n        center: { x: 0, y: 0 },\n        innerRadius: 0,\n        radius: -1,\n        maxKernelSize: 32,\n    };\n\n    public uniforms: {\n        uStrength: number;\n        uCenter: PointData;\n        uRadii: Float32Array\n    };\n\n    /**\n     * @param options - Options for the ZoomBlurFilter constructor.\n     */\n    constructor(options?: ZoomBlurFilterOptions)\n    {\n        options = { ...ZoomBlurFilter.DEFAULT_OPTIONS, ...options };\n\n        const kernelSize = options.maxKernelSize ?? 32;\n\n        const gpuProgram = GpuProgram.from({\n            vertex: {\n                source: wgslVertex,\n                entryPoint: 'mainVertex',\n            },\n            fragment: {\n                source: source.replace('${MAX_KERNEL_SIZE}', kernelSize.toFixed(1)),\n                entryPoint: 'mainFragment',\n            },\n        });\n\n        const glProgram = GlProgram.from({\n            vertex,\n            fragment: fragment.replace('${MAX_KERNEL_SIZE}', kernelSize.toFixed(1)),\n            name: 'zoom-blur-filter',\n        });\n\n        super({\n            gpuProgram,\n            glProgram,\n            resources: {\n                zoomBlurUniforms: {\n                    uStrength: { value: options.strength, type: 'f32' },\n                    uCenter: { value: { x: 0, y: 0 }, type: 'vec2<f32>' },\n                    uRadii: { value: new Float32Array(2), type: 'vec2<f32>' },\n                }\n            },\n        });\n\n        this.uniforms = this.resources.zoomBlurUniforms.uniforms;\n\n        Object.assign(this, options);\n    }\n\n    /**\n     * Sets the strength of the zoom blur effect\n     * @default 0.1\n     */\n    get strength(): number { return this.uniforms.uStrength; }\n    set strength(value: number) { this.uniforms.uStrength = value; }\n\n    /**\n     * The center of the zoom\n     * @default {x:0,y:0}\n     */\n    get center(): PointData { return this.uniforms.uCenter; }\n    set center(value: PointData | number[])\n    {\n        if (Array.isArray(value))\n        {\n            value = { x: value[0], y: value[1] };\n        }\n\n        this.uniforms.uCenter = value;\n    }\n\n    /**\n     * Sets the center of the effect in normalized screen coords on the `x` axis\n     * @default 0\n     */\n    get centerX(): number { return this.uniforms.uCenter.x; }\n    set centerX(value: number) { this.uniforms.uCenter.x = value; }\n\n    /**\n     * Sets the center of the effect in normalized screen coords on the `y` axis\n     * @default 0\n     */\n    get centerY(): number { return this.uniforms.uCenter.y; }\n    set centerY(value: number) { this.uniforms.uCenter.y = value; }\n\n    /**\n     * The inner radius of zoom. The part in inner circle won't apply zoom blur effect\n     * @default 0\n     */\n    get innerRadius(): number { return this.uniforms.uRadii[0]; }\n    set innerRadius(value: number) { this.uniforms.uRadii[0] = value; }\n\n    /**\n     * Outer radius of the effect. less than `0` equates to infinity\n     * @default -1\n     */\n    get radius(): number { return this.uniforms.uRadii[1]; }\n    set radius(value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