UNPKG

kinetic-slider

Version:

A WebGL-powered kinetic slider component using PIXI.js

1 lines 4.26 kB
{"version":3,"file":"grayscaleFilter.cjs","sources":["../../../src/filters/grayscaleFilter.ts"],"sourcesContent":["import { GrayscaleFilter } from 'pixi-filters';\nimport { type GrayscaleFilterConfig, type FilterResult } from './types';\nimport { ShaderResourceManager } from '../managers/ShaderResourceManager';\n\n/**\n * Creates a Grayscale filter that converts the image to grayscale\n *\n * The GrayscaleFilter is a simple filter that removes all color information,\n * resulting in a black and white image. This filter doesn't have any configurable\n * parameters - it's either on or off.\n * Uses shader pooling for better performance.\n *\n * @param config - Configuration for the Grayscale filter\n * @returns FilterResult with the filter instance and control functions\n */\nexport function createGrayscaleFilter(config: GrayscaleFilterConfig): FilterResult {\n // Get shader manager instance\n const shaderManager = ShaderResourceManager.getInstance();\n\n // Create the filter - GrayscaleFilter has no constructor parameters\n const filter = new GrayscaleFilter();\n\n // Create a unique key for this filter - grayscale filter has no configuration\n // so we can use a static key\n const shaderKey = 'grayscale-filter';\n\n // Register filter with shader manager\n try {\n shaderManager.registerFilter(filter, shaderKey);\n } catch (error) {\n console.warn('Error registering grayscale filter with shader manager:', error);\n }\n\n /**\n * Update the filter's intensity\n * Since GrayscaleFilter doesn't have configurable intensity,\n * we'll treat intensity as a binary on/off switch.\n *\n * @param intensity - New intensity value (0-10 scale)\n */\n const updateIntensity = (intensity: number): void => {\n // GrayscaleFilter doesn't have a way to adjust intensity\n // We're treating it as a binary on/off effect\n // If the filter was applied through the FilterFactory, it's already \"on\"\n\n // For future compatibility, if the filter ever gets updated to support\n // intensity, we'll keep this function\n\n // The filter's natural state is full grayscale, so we don't need\n // to do anything here with the intensity parameter\n };\n\n /**\n * Reset the filter to initial configuration values or defaults\n */\n const reset = (): void => {\n // Check if enabled property exists and was specified in config\n if ('enabled' in filter && config.enabled !== undefined) {\n filter.enabled = config.enabled;\n }\n\n // Even though GrayscaleFilter doesn't have configurable intensity,\n // if we've stored the initial intensity in the config, we can use\n // updateIntensity to reset to that initial state for consistency\n if (config.intensity !== undefined) {\n updateIntensity(config.intensity);\n }\n };\n\n /**\n * Release any WebGL resources used by this filter\n */\n const dispose = (): void => {\n try {\n shaderManager.releaseFilter(filter, shaderKey);\n } catch (error) {\n console.warn('Error releasing grayscale filter shader:', error);\n }\n filter.destroy();\n };\n\n return { filter, updateIntensity, reset, dispose };\n}"],"names":["ShaderResourceManager","GrayscaleFilter"],"mappings":";;;;;AAeO,SAAS,sBAAsB,MAA6C,EAAA;AAE/E,EAAM,MAAA,aAAA,GAAgBA,4CAAsB,WAAY,EAAA;AAGxD,EAAM,MAAA,MAAA,GAAS,IAAIC,2BAAgB,EAAA;AAInC,EAAA,MAAM,SAAY,GAAA,kBAAA;AAGlB,EAAI,IAAA;AACA,IAAc,aAAA,CAAA,cAAA,CAAe,QAAQ,SAAS,CAAA;AAAA,WACzC,KAAO,EAAA;AACZ,IAAQ,OAAA,CAAA,IAAA,CAAK,2DAA2D,KAAK,CAAA;AAAA;AAUjF,EAAM,MAAA,eAAA,GAAkB,CAAC,SAA4B,KAAA;AAAA,GAUrD;AAKA,EAAA,MAAM,QAAQ,MAAY;AAEtB,IAAA,IAAI,SAAa,IAAA,MAAA,IAAU,MAAO,CAAA,OAAA,KAAY,MAAW,EAAA;AACrD,MAAA,MAAA,CAAO,UAAU,MAAO,CAAA,OAAA;AAAA;AAM5B,IAAI,IAAA,MAAA,CAAO,cAAc,MAAW,EAAA;AAChC,MAAA,eAAA,CAAgB,OAAO,SAAS,CAAA;AAAA;AACpC,GACJ;AAKA,EAAA,MAAM,UAAU,MAAY;AACxB,IAAI,IAAA;AACA,MAAc,aAAA,CAAA,aAAA,CAAc,QAAQ,SAAS,CAAA;AAAA,aACxC,KAAO,EAAA;AACZ,MAAQ,OAAA,CAAA,IAAA,CAAK,4CAA4C,KAAK,CAAA;AAAA;AAElE,IAAA,MAAA,CAAO,OAAQ,EAAA;AAAA,GACnB;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,eAAiB,EAAA,KAAA,EAAO,OAAQ,EAAA;AACrD;;;;"}