@tsparticles/plugin-hsl-color
Version:
tsParticles HSL color plugin
71 lines (65 loc) • 6.22 kB
JavaScript
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
/* Plugin v4.3.2 */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsparticles/engine')) :
typeof define === 'function' && define.amd ? define(['exports', '@tsparticles/engine'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.__tsParticlesInternals = global.__tsParticlesInternals || {}, global.__tsParticlesInternals.plugins = global.__tsParticlesInternals.plugins || {}, global.__tsParticlesInternals.plugins.hslColor = global.__tsParticlesInternals.plugins.hslColor || {}), global.__tsParticlesInternals.engine));
})(this, (function (exports, engine) { 'use strict';
var HslIndexes;
(function (HslIndexes) {
HslIndexes[HslIndexes["h"] = 1] = "h";
HslIndexes[HslIndexes["s"] = 2] = "s";
HslIndexes[HslIndexes["l"] = 3] = "l";
HslIndexes[HslIndexes["a"] = 5] = "a";
})(HslIndexes || (HslIndexes = {}));
const hslRegex = /hsla?\(\s*(\d+)\s*[\s,]\s*(\d+)%\s*[\s,]\s*(\d+)%\s*([\s,]\s*(0|1|0?\.\d+|(\d{1,3})%)\s*)?\)/i;
class HslColorManager {
accepts(input) {
return input.startsWith("hsl");
}
handleColor(color) {
const colorValue = color.value, hslColor = colorValue.hsl ?? color.value;
if (!("h" in hslColor) || !("s" in hslColor) || !("l" in hslColor)) {
return;
}
return engine.hslToRgb(hslColor);
}
handleRangeColor(color) {
const colorValue = color.value, hslColor = colorValue.hsl ?? color.value;
if (!("h" in hslColor) || !("s" in hslColor) || !("l" in hslColor)) {
return;
}
return engine.hslToRgb({
h: engine.getRangeValue(hslColor.h),
l: engine.getRangeValue(hslColor.l),
s: engine.getRangeValue(hslColor.s),
});
}
parseString(input) {
if (!this.accepts(input)) {
return;
}
const result = hslRegex.exec(input), minLength = 4, defaultAlpha = 1, radix = 10;
return result
? engine.hslaToRgba({
a: result.length > minLength ? engine.parseAlpha(result[HslIndexes.a]) : defaultAlpha,
h: Number.parseInt(result[HslIndexes.h] ?? "0", radix),
l: Number.parseInt(result[HslIndexes.l] ?? "0", radix),
s: Number.parseInt(result[HslIndexes.s] ?? "0", radix),
})
: undefined;
}
}
async function loadHslColorPlugin(engine) {
engine.checkVersion("4.3.2");
await engine.pluginManager.register(e => {
e.pluginManager.addColorManager("hsl", new HslColorManager());
});
}
const globalObject = globalThis;
globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {};
globalObject.loadHslColorPlugin = loadHslColorPlugin;
exports.loadHslColorPlugin = loadHslColorPlugin;
}));
Object.assign(globalThis.window || globalThis, { loadHslColorPlugin: (globalThis.__tsParticlesInternals.plugins.hslColor || {}).loadHslColorPlugin });
delete (globalThis.window || globalThis).tsparticlesInternalExports;