UNPKG

kinetic-slider

Version:

A WebGL-powered kinetic slider component using PIXI.js

83 lines (79 loc) 2.56 kB
'use strict'; var pixiFilters = require('pixi-filters'); var pixi_js = require('pixi.js'); var ShaderResourceManager = require('../managers/ShaderResourceManager.cjs'); function createSimpleLightmapFilter(config) { const shaderManager = ShaderResourceManager.ShaderResourceManager.getInstance(); let lightMapTexture = config.lightMap; if (typeof config.lightMap === "string") { lightMapTexture = pixi_js.Texture.EMPTY; pixi_js.Assets.load(config.lightMap).then((texture) => { if (filter) { filter.lightMap = texture; } }).catch((error) => { console.error(`Failed to load lightMap texture: ${config.lightMap}`, error); }); } let colorValue; if (config.color !== void 0) { if (typeof config.color === "number") { colorValue = config.color; } } const colorHex = (colorValue || 0).toString(16); const shaderKey = `simple-lightmap-filter-${colorHex}`; const filter = new pixiFilters.SimpleLightmapFilter( lightMapTexture, // lightMap texture colorValue || 0, // ambient color as number (default black) config.alpha // alpha value ); try { shaderManager.registerFilter(filter, shaderKey); } catch (error) { console.warn("Error registering simple lightmap filter with shader manager:", error); } const updateIntensity = (intensity) => { const normalizedIntensity = Math.max(0, Math.min(10, intensity)); if (config.primaryProperty) { switch (config.primaryProperty) { case "alpha": filter.alpha = normalizedIntensity / 10; break; case "brightness": filter.alpha = normalizedIntensity / 10; break; case "colorIntensity": filter.alpha = normalizedIntensity / 10; break; default: filter.alpha = normalizedIntensity / 10; } } else { filter.alpha = normalizedIntensity / 10; } }; updateIntensity(config.intensity); const reset = () => { filter.alpha = config.alpha !== void 0 ? config.alpha : 1; if (colorValue !== void 0) { filter.color = colorValue; } else { filter.color = 0; } }; const dispose = () => { try { shaderManager.releaseFilter(filter, shaderKey); } catch (error) { console.warn("Error releasing simple lightmap filter shader:", error); } filter.destroy(); }; return { filter, updateIntensity, reset, dispose }; } exports.createSimpleLightmapFilter = createSimpleLightmapFilter; //# sourceMappingURL=simpleLightmapFilter.cjs.map