kinetic-slider
Version:
A WebGL-powered kinetic slider component using PIXI.js
85 lines (81 loc) • 2.96 kB
JavaScript
;
var pixiFilters = require('pixi-filters');
var ShaderResourceManager = require('../managers/ShaderResourceManager.cjs');
const shaderManager = ShaderResourceManager.ShaderResourceManager.getInstance();
function createDropShadowFilter(config) {
const options = {};
if (config.alpha !== void 0) options.alpha = config.alpha;
if (config.blur !== void 0) options.blur = config.blur;
if (config.color !== void 0) options.color = config.color;
if (config.offset !== void 0) options.offset = config.offset;
if (config.offsetX !== void 0) options.offsetX = config.offsetX;
if (config.offsetY !== void 0) options.offsetY = config.offsetY;
if (config.pixelSize !== void 0) options.pixelSize = config.pixelSize;
if (config.pixelSizeX !== void 0) options.pixelSizeX = config.pixelSizeX;
if (config.pixelSizeY !== void 0) options.pixelSizeY = config.pixelSizeY;
if (config.quality !== void 0) options.quality = config.quality;
if (config.shadowOnly !== void 0) options.shadowOnly = config.shadowOnly;
const filter = new pixiFilters.DropShadowFilter(options);
const shaderKey = `dropshadow-${config.quality || 3}-${config.blur || 2}-${config.alpha || 1}`;
try {
shaderManager.getShaderProgram(shaderKey, filter);
} catch (error) {
console.warn("Failed to register dropShadow 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 "blur":
filter.blur = normalizedIntensity * 2;
break;
case "offsetX":
filter.offsetX = normalizedIntensity * 2;
break;
case "offsetY":
filter.offsetY = normalizedIntensity * 2;
break;
default:
filter.blur = normalizedIntensity * 2;
}
} else {
filter.blur = normalizedIntensity * 2;
filter.offsetX = 2 + normalizedIntensity;
filter.offsetY = 2 + normalizedIntensity;
}
};
updateIntensity(config.intensity);
const reset = () => {
if ("alpha" in filter) {
filter.alpha = config.alpha !== void 0 ? config.alpha : 1;
}
if ("enabled" in filter) {
filter.enabled = config.enabled !== void 0 ? config.enabled : true;
}
if (config.intensity !== void 0) {
updateIntensity(config.intensity);
}
};
const dispose = () => {
try {
shaderManager.releaseShader(shaderKey);
} catch (error) {
console.warn("Failed to release dropShadow filter shader:", error);
}
if (filter.destroy) {
filter.destroy();
}
};
const result = {
filter,
updateIntensity,
reset,
dispose
};
return result;
}
exports.createDropShadowFilter = createDropShadowFilter;
//# sourceMappingURL=dropShadowFilter.cjs.map