{"version":3,"file":"filter-glow.mjs","sources":["../src/GlowFilter.ts"],"sourcesContent":["import { vertex } from '@tools/fragments';\nimport fragment from './glow.frag';\nimport { Filter, utils } from '@pixi/core';\n\ninterface GlowFilterOptions\n{\n    distance: number;\n    outerStrength: number;\n    innerStrength: number;\n    color: number;\n    quality: number;\n    knockout: boolean;\n    alpha: number;\n}\n\n/**\n * GlowFilter, originally by mishaa\n * [codepen]{@link http://codepen.io/mishaa/pen/raKzrm}.<br>\n * ![original](../tools/screenshots/dist/original.png)![filter](../tools/screenshots/dist/glow.png)\n * @class\n *\n * @extends PIXI.Filter\n * @see {@link https://www.npmjs.com/package/@pixi/filter-glow|@pixi/filter-glow}\n * @see {@link https://www.npmjs.com/package/pixi-filters|pixi-filters}\n *\n * @example\n *  someSprite.filters = [\n *      new GlowFilter({ distance: 15, outerStrength: 2 })\n *  ];\n */\nclass GlowFilter extends Filter\n{\n    /** Default values for options. */\n    static readonly defaults: GlowFilterOptions = {\n        distance: 10,\n        outerStrength: 4,\n        innerStrength: 0,\n        color: 0xffffff,\n        quality: 0.1,\n        knockout: false,\n        alpha: 1,\n    };\n\n    /**\n     * @param {number} [options] - Options for glow.\n     * @param {number} [options.distance=10] - The distance of the glow. Make it 2 times more for resolution=2.\n     *        It can't be changed after filter creation.\n     * @param {number} [options.outerStrength=4] - The strength of the glow outward from the edge of the sprite.\n     * @param {number} [options.innerStrength=0] - The strength of the glow inward from the edge of the sprite.\n     * @param {number} [options.color=0xffffff] - The color of the glow.\n     * @param {number} [options.quality=0.1] - A number between 0 and 1 that describes the quality of the glow.\n     *        The higher the number the less performant.\n     * @param {boolean} [options.knockout=false] - Toggle to hide the contents and only show glow.\n     */\n    constructor(options?: Partial<GlowFilterOptions>)\n    {\n        const opts: GlowFilterOptions = Object.assign({}, GlowFilter.defaults, options);\n        const {\n            outerStrength,\n            innerStrength,\n            color,\n            knockout,\n            quality,\n            alpha } = opts;\n\n        const distance = Math.round(opts.distance);\n\n        super(vertex, fragment\n            .replace(/__ANGLE_STEP_SIZE__/gi, `${(1 / quality / distance).toFixed(7)}`)\n            .replace(/__DIST__/gi, `${distance.toFixed(0)}.0`));\n\n        this.uniforms.glowColor = new Float32Array([0, 0, 0, 1]);\n        this.uniforms.alpha = 1;\n\n        Object.assign(this, {\n            color,\n            outerStrength,\n            innerStrength,\n            padding: distance,\n            knockout,\n            alpha,\n        });\n    }\n\n    /**\n     * The color of the glow.\n     * @default 0xFFFFFF\n     */\n    get color(): number\n    {\n        return utils.rgb2hex(this.uniforms.glowColor);\n    }\n    set color(value: number)\n    {\n        utils.hex2rgb(value, this.uniforms.glowColor);\n    }\n\n    /**\n     * The strength of the glow outward from the edge of the sprite.\n     * @default 4\n     */\n    get outerStrength(): number\n    {\n        return this.uniforms.outerStrength;\n    }\n    set outerStrength(value: number)\n    {\n        this.uniforms.outerStrength = value;\n    }\n\n    /**\n     * The strength of the glow inward from the edge of the sprite.\n     * @default 0\n     */\n    get innerStrength(): number\n    {\n        return this.uniforms.innerStrength;\n    }\n    set innerStrength(value: number)\n    {\n        this.uniforms.innerStrength = value;\n    }\n\n    /**\n     * Only draw the glow, not the texture itself\n     * @default false\n     */\n    get knockout(): boolean\n    {\n        return this.uniforms.knockout;\n    }\n    set knockout(value: boolean)\n    {\n        this.uniforms.knockout = value;\n    }\n\n    /**\n     * The alpha value of the glow\n     * @default 1\n     */\n    get alpha(): number\n    {\n        return this.uniforms.alpha;\n    }\n    set alpha(value: number)\n    {\n        this.uniforms.alpha = value;\n    }\n}\n\nexport { GlowFilter };\nexport type { GlowFilterOptions };\n"],"names":["_GlowFilter","Filter","options","opts","outerStrength","innerStrength","color","knockout","quality","alpha","distance","vertex","fragment","utils","value","GlowFilter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BA,MAAMA,EAAN,cAAyBC,CACzB,CAuBI,YAAYC,EACZ,CACI,MAAM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