UNPKG

kinetic-slider

Version:

A WebGL-powered kinetic slider component using PIXI.js

69 lines (65 loc) 2.62 kB
'use strict'; var pixiFilters = require('pixi-filters'); var ShaderResourceManager = require('../managers/ShaderResourceManager.cjs'); function createHslAdjustmentFilter(config) { const shaderManager = ShaderResourceManager.ShaderResourceManager.getInstance(); const options = {}; if (config.alpha !== void 0) options.alpha = config.alpha; if (config.colorize !== void 0) options.colorize = config.colorize; if (config.hue !== void 0) options.hue = config.hue; if (config.lightness !== void 0) options.lightness = config.lightness; if (config.saturation !== void 0) options.saturation = config.saturation; const colorizeStr = options.colorize ? "colorize" : "nocolorize"; const shaderKey = `hsl-adjustment-filter-${colorizeStr}`; const filter = new pixiFilters.HslAdjustmentFilter(options); try { shaderManager.registerFilter(filter, shaderKey); } catch (error) { console.warn("Error registering HSL adjustment filter with shader manager:", error); } const updateIntensity = (intensity) => { const normalizedIntensity = Math.max(0, Math.min(10, intensity)); if (config.primaryProperty) { switch (config.primaryProperty) { case "hue": filter.hue = -180 + normalizedIntensity * 36; break; case "saturation": filter.saturation = -1 + normalizedIntensity / 5; break; case "lightness": filter.lightness = -1 + normalizedIntensity / 5; break; case "alpha": filter.alpha = normalizedIntensity / 10; break; default: filter.saturation = -1 + normalizedIntensity / 5; } } else { filter.saturation = -1 + normalizedIntensity / 5; } }; updateIntensity(config.intensity); const reset = () => { filter.alpha = config.alpha !== void 0 ? config.alpha : 1; filter.colorize = config.colorize !== void 0 ? config.colorize : false; filter.hue = config.hue !== void 0 ? config.hue : 0; filter.lightness = config.lightness !== void 0 ? config.lightness : 0; filter.saturation = config.saturation !== void 0 ? config.saturation : 0; if (config.intensity !== void 0) { updateIntensity(config.intensity); } }; const dispose = () => { try { shaderManager.releaseFilter(filter, shaderKey); } catch (error) { console.warn("Error releasing HSL adjustment filter shader:", error); } filter.destroy(); }; return { filter, updateIntensity, reset, dispose }; } exports.createHslAdjustmentFilter = createHslAdjustmentFilter; //# sourceMappingURL=hslAdjustmentFilter.cjs.map