tsparticles-engine
Version:
Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.
42 lines (41 loc) • 1.43 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.RgbColorManager = void 0;
const NumberUtils_1 = require("./NumberUtils");
class RgbColorManager {
constructor() {
this.key = "rgb";
this.stringPrefix = "rgb";
}
handleColor(color) {
const colorValue = color.value, rgbColor = colorValue.rgb ?? color.value;
if (rgbColor.r !== undefined) {
return rgbColor;
}
}
handleRangeColor(color) {
const colorValue = color.value, rgbColor = colorValue.rgb ?? color.value;
if (rgbColor.r !== undefined) {
return {
r: (0, NumberUtils_1.getRangeValue)(rgbColor.r),
g: (0, NumberUtils_1.getRangeValue)(rgbColor.g),
b: (0, NumberUtils_1.getRangeValue)(rgbColor.b),
};
}
}
parseString(input) {
if (!input.startsWith(this.stringPrefix)) {
return;
}
const regex = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.%]+)\s*)?\)/i, result = regex.exec(input);
return result
? {
a: result.length > 4 ? (0, NumberUtils_1.parseAlpha)(result[5]) : 1,
b: parseInt(result[3], 10),
g: parseInt(result[2], 10),
r: parseInt(result[1], 10),
}
: undefined;
}
}
exports.RgbColorManager = RgbColorManager;
;