{"version":3,"file":"AsciiFilter.mjs","sources":["../../src/ascii/AsciiFilter.ts"],"sourcesContent":["import { Color, ColorSource, deprecation, Filter, GlProgram, GpuProgram } from 'pixi.js';\nimport { vertex, wgslVertex } from '../defaults';\nimport fragment from './ascii.frag';\nimport source from './ascii.wgsl';\n\n// This WebGPU filter has been ported from the WebGL renderer that was originally created by Vico (@vicocotea)\n\n/** Options for AsciiFilter constructor. */\nexport interface AsciiFilterOptions\n{\n    /**\n     * The pixel size used by the filter\n     * @default 8\n     */\n    size?: number;\n    /**\n     * A color to set the ascii characters to. If not set, the color will be taken from the source.\n     * @example [1.0, 1.0, 1.0] = 0xffffff\n     * @default 0x000000\n     */\n    color?: ColorSource;\n    /**\n     * Determine whether or not to replace the source colors with the provided.\n     *\n     * Will automatically be assigned to `true` if `color` is provided.\n     * Set `replaceColor` to `false` to prevent that.\n     * @default false\n     */\n    replaceColor?: boolean;\n}\n\n/**\n * An ASCII filter.<br>\n * ![original](../screenshots/original.png)![filter](../screenshots/ascii.png)\n *\n * @class\n * @extends Filter\n */\nexport class AsciiFilter extends Filter\n{\n    /** Default values for options. */\n    public static readonly DEFAULT_OPTIONS: AsciiFilterOptions = {\n        size: 8,\n        color: 0xffffff,\n        replaceColor: false,\n    };\n\n    public uniforms: {\n        uSize: number;\n        uColor: Float32Array;\n        uReplaceColor: number;\n    };\n\n    private _color!: Color;\n\n    /**\n     * Constructor.\n     * @param {AsciiFilterOptions} options - The options of the ASCII filter.\n     */\n    constructor(options?: AsciiFilterOptions);\n    /**\n     * @deprecated since 6.0.0\n     *\n     * @param {number} [size=8] - Size of the font\n     */\n    constructor(size: number);\n    /** @ignore */\n    constructor(...args: [AsciiFilterOptions?] | [number])\n    {\n        let options = args[0] ?? {};\n\n        if (typeof options === 'number')\n        {\n            // eslint-disable-next-line max-len\n            deprecation('6.0.0', 'AsciiFilter constructor params are now options object. See params: { size, color, replaceColor }');\n\n            options = { size: options };\n        }\n\n        const replaceColor = options?.color && options.replaceColor !== false;\n\n        options = { ...AsciiFilter.DEFAULT_OPTIONS, ...options } as AsciiFilterOptions;\n\n        const gpuProgram = GpuProgram.from({\n            vertex: {\n                source: wgslVertex,\n                entryPoint: 'mainVertex',\n            },\n            fragment: {\n                source,\n                entryPoint: 'mainFragment',\n            },\n        });\n\n        const glProgram = GlProgram.from({\n            vertex,\n            fragment,\n            name: 'ascii-filter',\n        });\n\n        super({\n            gpuProgram,\n            glProgram,\n            resources: {\n                asciiUniforms: {\n                    uSize: { value: options.size, type: 'f32' },\n                    uColor: { value: new Float32Array(3), type: 'vec3<f32>' },\n                    uReplaceColor: { value: Number(replaceColor), type: 'f32' },\n                },\n            },\n        });\n\n        this.uniforms = this.resources.asciiUniforms.uniforms;\n        this._color = new Color();\n        this.color = options.color ?? 0xffffff;\n    }\n\n    /**\n     * The pixel size used by the filter.\n     * @default 8\n     */\n    get size(): number { return this.uniforms.uSize; }\n    set size(value: number) { this.uniforms.uSize = value; }\n\n    /**\n     * The resulting color of the ascii characters, as a 3 component RGB or numerical hex\n     * @example [1.0, 1.0, 1.0] = 0xffffff\n     * @default 0xffffff\n     */\n    get color(): ColorSource { return this._color.value as ColorSource; }\n    set color(value: ColorSource)\n    {\n        this._color.setValue(value);\n        const [r, g, b] = this._color.toArray();\n\n        this.uniforms.uColor[0] = r;\n        this.uniforms.uColor[1] = g;\n        this.uniforms.uColor[2] = b;\n    }\n\n    /**\n     * Determine whether or not to replace the source colors with the provided.\n     */\n    get replaceColor(): boolean { return this.uniforms.uReplaceColor > 0.5; }\n    set replaceColor(value: boolean) { this.uniforms.uReplaceColor = value ? 1 : 0; }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAsCO,MAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,MACjC,CAAA;AAAA;AAAA,EA4BI,eAAe,IACf,EAAA;AACI,IAAA,IAAI,OAAU,GAAA,IAAA,CAAK,CAAC,CAAA,IAAK,EAAC,CAAA;AAE1B,IAAI,IAAA,OAAO,YAAY,QACv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