@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.
476 lines (475 loc) • 23.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.rangeColorToRgb = rangeColorToRgb;
exports.colorToRgb = colorToRgb;
exports.rangeColorToHsl = rangeColorToHsl;
exports.rgbToHsl = rgbToHsl;
exports.stringToAlpha = stringToAlpha;
exports.stringToRgb = stringToRgb;
exports.hslToRgb = hslToRgb;
exports.hslToRgbFloat = hslToRgbFloat;
exports.hslaToRgba = hslaToRgba;
exports.getRandomRgbColor = getRandomRgbColor;
exports.getStyleFromRgb = getStyleFromRgb;
exports.getStyleFromHsl = getStyleFromHsl;
exports.colorMix = colorMix;
exports.getLinkColor = getLinkColor;
exports.getLinkRandomColor = getLinkRandomColor;
exports.getHslFromAnimation = getHslFromAnimation;
exports.getHslAnimationFromHsl = getHslAnimationFromHsl;
exports.updateColorValue = updateColorValue;
exports.updateColor = updateColor;
exports.alterHsl = alterHsl;
const MathUtils_js_1 = require("./MathUtils.js");
const Constants_js_1 = require("../Core/Utils/Constants.js");
const TypeUtils_js_1 = require("./TypeUtils.js");
const AlterType_js_1 = require("../Enums/Types/AlterType.js");
const AnimationStatus_js_1 = require("../Enums/AnimationStatus.js");
const HdrMode_js_1 = require("../Enums/Modes/HdrMode.js");
const Utils_js_1 = require("./Utils.js");
const styleCache = new Map(), maxStyleCacheSize = 2000, rgbFixedPrecision = 2, hslFixedPrecision = 2, hdrRgbFixedPrecision = 4, hdrHslFixedPrecision = 4, sdrReferenceWhiteNits = 203, acesA = 2.51, acesB = 0.03, acesC = 2.43, acesD = 0.59, acesE = 0.14, saturationBoost = 1.15, lightnessBoost = 1.05, temperatureR = 1.05, temperatureB = 0.95, contrastFactor = 1.1, luminanceR = 0.2126, luminanceG = 0.7152, luminanceB = 0.0722, dynamicLuminanceFactor = 2, channelCount = 3, srgbThreshold = 0.04045, srgbDivisor = 12.92, srgbOffset = 0.055, srgbScale = 1.055, srgbExponent = 2.4, linearThreshold = 0.0031308, linearScale = 12.92;
function getCachedStyle(key, generator) {
let cached = styleCache.get(key);
if (!cached) {
cached = generator();
if (styleCache.size > maxStyleCacheSize) {
styleCache.clear();
}
styleCache.set(key, cached);
}
return cached;
}
function acesFilmic(x) {
return (0, MathUtils_js_1.clamp)((x * (acesA * x + acesB)) / (x * (acesC * x + acesD) + acesE), Constants_js_1.none, Constants_js_1.one);
}
function srgbToLinear(c) {
return c <= srgbThreshold ? c / srgbDivisor : Math.pow((c + srgbOffset) / srgbScale, srgbExponent);
}
function linearToSrgb(c) {
return c <= linearThreshold ? c * linearScale : srgbScale * Math.pow(c, Constants_js_1.one / srgbExponent) - srgbOffset;
}
function applyHdrModeAdjustments(r, g, b, mode, maxChannel) {
switch (mode) {
case HdrMode_js_1.HdrMode.vivid: {
const avg = (r + g + b) / channelCount;
return {
b: (0, MathUtils_js_1.clamp)((0, MathUtils_js_1.clamp)(avg + (b - avg) * saturationBoost, Constants_js_1.none, maxChannel) * lightnessBoost, Constants_js_1.none, maxChannel),
g: (0, MathUtils_js_1.clamp)((0, MathUtils_js_1.clamp)(avg + (g - avg) * saturationBoost, Constants_js_1.none, maxChannel) * lightnessBoost, Constants_js_1.none, maxChannel),
r: (0, MathUtils_js_1.clamp)((0, MathUtils_js_1.clamp)(avg + (r - avg) * saturationBoost, Constants_js_1.none, maxChannel) * lightnessBoost, Constants_js_1.none, maxChannel),
};
}
case HdrMode_js_1.HdrMode.cinematic: {
const tempR = r * temperatureR, tempB = b * temperatureB, avg = (tempR + g + tempB) / channelCount;
return {
b: (0, MathUtils_js_1.clamp)(avg + (tempB - avg) * contrastFactor, Constants_js_1.none, maxChannel),
g: (0, MathUtils_js_1.clamp)(avg + (g - avg) * contrastFactor, Constants_js_1.none, maxChannel),
r: (0, MathUtils_js_1.clamp)(avg + (tempR - avg) * contrastFactor, Constants_js_1.none, maxChannel),
};
}
case HdrMode_js_1.HdrMode.dynamic: {
const luminance = luminanceR * r + luminanceG * g + luminanceB * b, vividWeight = Math.min(Constants_js_1.one, luminance * dynamicLuminanceFactor), naturalWeight = Constants_js_1.one - vividWeight, avg = (r + g + b) / channelCount, vividR = (0, MathUtils_js_1.clamp)(avg + (r - avg) * saturationBoost, Constants_js_1.none, maxChannel) * lightnessBoost, vividG = (0, MathUtils_js_1.clamp)(avg + (g - avg) * saturationBoost, Constants_js_1.none, maxChannel) * lightnessBoost, vividB = (0, MathUtils_js_1.clamp)(avg + (b - avg) * saturationBoost, Constants_js_1.none, maxChannel) * lightnessBoost;
return {
b: (0, MathUtils_js_1.clamp)(b * naturalWeight + vividB * vividWeight, Constants_js_1.none, maxChannel),
g: (0, MathUtils_js_1.clamp)(g * naturalWeight + vividG * vividWeight, Constants_js_1.none, maxChannel),
r: (0, MathUtils_js_1.clamp)(r * naturalWeight + vividR * vividWeight, Constants_js_1.none, maxChannel),
};
}
case HdrMode_js_1.HdrMode.standard:
return { b, g, r };
case HdrMode_js_1.HdrMode.natural:
default:
return { b, g, r };
}
}
function stringToRgba(pluginManager, input) {
if (!input) {
return;
}
for (const manager of pluginManager.colorManagers.values()) {
if (manager.accepts(input)) {
return manager.parseString(input);
}
}
return undefined;
}
function rangeColorToRgb(pluginManager, input, index, useIndex = true) {
if (!input) {
return;
}
const color = (0, TypeUtils_js_1.isString)(input) ? { value: input } : input;
if ((0, TypeUtils_js_1.isString)(color.value)) {
return colorToRgb(pluginManager, color.value, index, useIndex);
}
if ((0, TypeUtils_js_1.isArray)(color.value)) {
const value = (0, Utils_js_1.itemFromArray)(color.value, index, useIndex);
if (!value) {
return;
}
return rangeColorToRgb(pluginManager, {
value,
});
}
for (const manager of pluginManager.colorManagers.values()) {
const res = manager.handleRangeColor(color);
if (res) {
return res;
}
}
return undefined;
}
function colorToRgb(pluginManager, input, index, useIndex = true) {
if (!input) {
return;
}
const color = (0, TypeUtils_js_1.isString)(input) ? { value: input } : input;
if ((0, TypeUtils_js_1.isString)(color.value)) {
return color.value === Constants_js_1.randomColorValue ? getRandomRgbColor() : stringToRgb(pluginManager, color.value);
}
if ((0, TypeUtils_js_1.isArray)(color.value)) {
const value = (0, Utils_js_1.itemFromArray)(color.value, index, useIndex);
if (!value) {
return;
}
return colorToRgb(pluginManager, {
value,
});
}
for (const manager of pluginManager.colorManagers.values()) {
const res = manager.handleColor(color);
if (res) {
return res;
}
}
return undefined;
}
function rangeColorToHsl(pluginManager, color, index, useIndex = true) {
const rgb = rangeColorToRgb(pluginManager, color, index, useIndex);
return rgb ? rgbToHsl(rgb) : undefined;
}
function rgbToHsl(color) {
const r1 = color.r / Constants_js_1.rgbMax, g1 = color.g / Constants_js_1.rgbMax, b1 = color.b / Constants_js_1.rgbMax, max = Math.max(r1, g1, b1), min = Math.min(r1, g1, b1), res = {
h: Constants_js_1.hMin,
l: (max + min) * Constants_js_1.half,
s: Constants_js_1.sMin,
};
if (max !== min) {
res.s = res.l < Constants_js_1.half ? (max - min) / (max + min) : (max - min) / (Constants_js_1.double - max - min);
if (r1 === max) {
res.h = (g1 - b1) / (max - min);
}
else if (g1 === max) {
res.h = Constants_js_1.double + (b1 - r1) / (max - min);
}
else {
res.h = Constants_js_1.double * Constants_js_1.double + (r1 - g1) / (max - min);
}
}
res.l *= Constants_js_1.lMax;
res.s *= Constants_js_1.sMax;
res.h *= Constants_js_1.hPhase;
if (res.h < Constants_js_1.hMin) {
res.h += Constants_js_1.hMax;
}
if (res.h >= Constants_js_1.hMax) {
res.h -= Constants_js_1.hMax;
}
return res;
}
function stringToAlpha(pluginManager, input) {
return stringToRgba(pluginManager, input)?.a;
}
function stringToRgb(pluginManager, input) {
return stringToRgba(pluginManager, input);
}
function hslChannel(temp1, temp2, temp3) {
const temp3Min = 0, temp3Max = 1;
if (temp3 < temp3Min) {
temp3++;
}
if (temp3 > temp3Max) {
temp3--;
}
if (temp3 * Constants_js_1.sextuple < temp3Max) {
return temp1 + (temp2 - temp1) * Constants_js_1.sextuple * temp3;
}
if (temp3 * Constants_js_1.double < temp3Max) {
return temp2;
}
if (temp3 * Constants_js_1.triple < temp3Max * Constants_js_1.double) {
const temp3Offset = Constants_js_1.double / Constants_js_1.triple;
return temp1 + (temp2 - temp1) * (temp3Offset - temp3) * Constants_js_1.sextuple;
}
return temp1;
}
function hslToRgb(hsl) {
const h = ((hsl.h % Constants_js_1.hMax) + Constants_js_1.hMax) % Constants_js_1.hMax, s = Math.max(Constants_js_1.sMin, Math.min(Constants_js_1.sMax, hsl.s)), l = Math.max(Constants_js_1.lMin, Math.min(Constants_js_1.lMax, hsl.l)), hNormalized = h / Constants_js_1.hMax, sNormalized = s / Constants_js_1.sMax, lNormalized = l / Constants_js_1.lMax;
if (s === Constants_js_1.sMin) {
const grayscaleValue = Math.round(lNormalized * Constants_js_1.rgbMax);
return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
}
const temp2 = lNormalized < Constants_js_1.half
? lNormalized * (Constants_js_1.sNormalizedOffset + sNormalized)
: lNormalized + sNormalized - lNormalized * sNormalized, temp1 = Constants_js_1.double * lNormalized - temp2, phaseThird = Constants_js_1.phaseNumerator / Constants_js_1.triple, red = Math.min(Constants_js_1.rgbMax, Constants_js_1.rgbMax * hslChannel(temp1, temp2, hNormalized + phaseThird)), green = Math.min(Constants_js_1.rgbMax, Constants_js_1.rgbMax * hslChannel(temp1, temp2, hNormalized)), blue = Math.min(Constants_js_1.rgbMax, Constants_js_1.rgbMax * hslChannel(temp1, temp2, hNormalized - phaseThird));
return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
}
function hslToRgbFloat(hsl) {
const h = ((hsl.h % Constants_js_1.hMax) + Constants_js_1.hMax) % Constants_js_1.hMax, s = Math.max(Constants_js_1.sMin, Math.min(Constants_js_1.sMax, hsl.s)), l = Math.max(Constants_js_1.lMin, Math.min(Constants_js_1.lMax, hsl.l)), hNormalized = h / Constants_js_1.hMax, sNormalized = s / Constants_js_1.sMax, lNormalized = l / Constants_js_1.lMax;
if (s === Constants_js_1.sMin) {
const grayscaleValue = lNormalized * Constants_js_1.rgbMax;
return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
}
const temp2 = lNormalized < Constants_js_1.half
? lNormalized * (Constants_js_1.sNormalizedOffset + sNormalized)
: lNormalized + sNormalized - lNormalized * sNormalized, temp1 = Constants_js_1.double * lNormalized - temp2, phaseThird = Constants_js_1.phaseNumerator / Constants_js_1.triple, red = Math.min(Constants_js_1.rgbMax, Constants_js_1.rgbMax * hslChannel(temp1, temp2, hNormalized + phaseThird)), green = Math.min(Constants_js_1.rgbMax, Constants_js_1.rgbMax * hslChannel(temp1, temp2, hNormalized)), blue = Math.min(Constants_js_1.rgbMax, Constants_js_1.rgbMax * hslChannel(temp1, temp2, hNormalized - phaseThird));
return { r: red, g: green, b: blue };
}
function hslaToRgba(hsla) {
const rgbResult = hslToRgb(hsla);
return {
a: hsla.a,
b: rgbResult.b,
g: rgbResult.g,
r: rgbResult.r,
};
}
function getRandomRgbColor(min, hdr) {
const fixedMin = min ?? Constants_js_1.defaultRgbMin;
if (hdr) {
return {
r: (0, MathUtils_js_1.getRandomInRange)(fixedMin, Constants_js_1.rgbMax),
g: (0, MathUtils_js_1.getRandomInRange)(fixedMin, Constants_js_1.rgbMax),
b: (0, MathUtils_js_1.getRandomInRange)(fixedMin, Constants_js_1.rgbMax),
};
}
const fixedMax = Constants_js_1.rgbMax + Constants_js_1.identity, getRgbInRangeValue = () => Math.floor((0, MathUtils_js_1.getRandomInRange)(fixedMin, fixedMax));
return {
b: getRgbInRangeValue(),
g: getRgbInRangeValue(),
r: getRgbInRangeValue(),
};
}
function getStyleFromRgb(color, hdr, opacity, peakNits, mode) {
const rgbPrecision = hdr ? hdrRgbFixedPrecision : rgbFixedPrecision, op = opacity ?? Constants_js_1.defaultOpacity, key = hdr
? `rgb-${color.r.toFixed(rgbPrecision)}-${color.g.toFixed(rgbPrecision)}-${color.b.toFixed(rgbPrecision)}-hdr-${op.toString()}-${(peakNits ?? Constants_js_1.maxNits).toString()}-${mode ?? HdrMode_js_1.HdrMode.standard}`
: `rgb-${color.r.toFixed(rgbPrecision)}-${color.g.toFixed(rgbPrecision)}-${color.b.toFixed(rgbPrecision)}-sdr-${op.toString()}`;
return getCachedStyle(key, () => hdr ? getHdrStyleFromRgb(color, opacity, peakNits, mode) : getSdrStyleFromRgb(color, opacity));
}
function getHdrStyleFromRgb(color, opacity, peakNits = Constants_js_1.maxNits, mode = HdrMode_js_1.HdrMode.standard) {
const headroom = peakNits / sdrReferenceWhiteNits, middleGray = 0.18, mapped = hdrToneMapColor(color, headroom, middleGray, mode);
return `color(display-p3 ${mapped.r.toString()} ${mapped.g.toString()} ${mapped.b.toString()} / ${(opacity ?? Constants_js_1.defaultOpacity).toString()})`;
}
function hdrToneMapColor(color, headroom, middleGray, mode) {
const rNorm = color.r / Constants_js_1.rgbMax, gNorm = color.g / Constants_js_1.rgbMax, bNorm = color.b / Constants_js_1.rgbMax;
if (mode !== HdrMode_js_1.HdrMode.natural && mode !== HdrMode_js_1.HdrMode.vivid && mode !== HdrMode_js_1.HdrMode.cinematic && mode !== HdrMode_js_1.HdrMode.dynamic) {
return { b: bNorm, g: gNorm, r: rNorm };
}
const maxChannel = Math.max(Constants_js_1.one, headroom), luminance = luminanceR * rNorm + luminanceG * gNorm + luminanceB * bNorm, mappedLuminance = hdrToneMap(luminance, headroom, middleGray), scale = luminance > Constants_js_1.none ? mappedLuminance / luminance : Constants_js_1.one;
return applyHdrModeAdjustments((0, MathUtils_js_1.clamp)(rNorm * scale, Constants_js_1.none, maxChannel), (0, MathUtils_js_1.clamp)(gNorm * scale, Constants_js_1.none, maxChannel), (0, MathUtils_js_1.clamp)(bNorm * scale, Constants_js_1.none, maxChannel), mode, maxChannel);
}
function hdrToneMap(normalized, headroom, middleGray) {
if (normalized <= middleGray) {
return acesFilmic(normalized);
}
const expanded = normalized + (normalized - middleGray) * (headroom - Constants_js_1.one);
return acesFilmic(expanded);
}
function getSdrStyleFromRgb(color, opacity) {
return `rgba(${color.r.toString()}, ${color.g.toString()}, ${color.b.toString()}, ${(opacity ?? Constants_js_1.defaultOpacity).toString()})`;
}
function getStyleFromHsl(color, hdr, opacity, peakNits, mode) {
const hslPrecision = hdr ? hdrHslFixedPrecision : hslFixedPrecision, op = opacity ?? Constants_js_1.defaultOpacity, key = hdr
? `hsl-${color.h.toFixed(hslPrecision)}-${color.s.toFixed(hslPrecision)}-${color.l.toFixed(hslPrecision)}-hdr-${op.toString()}-${(peakNits ?? Constants_js_1.maxNits).toString()}-${mode ?? HdrMode_js_1.HdrMode.standard}`
: `hsl-${color.h.toFixed(hslPrecision)}-${color.s.toFixed(hslPrecision)}-${color.l.toFixed(hslPrecision)}-sdr-${op.toString()}`;
return getCachedStyle(key, () => hdr
? getStyleFromRgb(hslToRgbFloat(color), true, opacity, peakNits, mode)
: `hsla(${color.h.toString()}, ${color.s.toString()}%, ${color.l.toString()}%, ${op.toString()})`);
}
function colorMix(color1, color2, size1, size2, hdr) {
let rgb1 = color1, rgb2 = color2;
if (!("r" in rgb1)) {
rgb1 = hdr ? hslToRgbFloat(color1) : hslToRgb(color1);
}
if (!("r" in rgb2)) {
rgb2 = hdr ? hslToRgbFloat(color2) : hslToRgb(color2);
}
if (hdr) {
const lin1 = {
b: srgbToLinear(rgb1.b / Constants_js_1.rgbMax),
g: srgbToLinear(rgb1.g / Constants_js_1.rgbMax),
r: srgbToLinear(rgb1.r / Constants_js_1.rgbMax),
}, lin2 = {
b: srgbToLinear(rgb2.b / Constants_js_1.rgbMax),
g: srgbToLinear(rgb2.g / Constants_js_1.rgbMax),
r: srgbToLinear(rgb2.r / Constants_js_1.rgbMax),
}, totalWeight = size1 + size2;
return {
b: linearToSrgb((lin1.b * size1 + lin2.b * size2) / totalWeight) * Constants_js_1.rgbMax,
g: linearToSrgb((lin1.g * size1 + lin2.g * size2) / totalWeight) * Constants_js_1.rgbMax,
r: linearToSrgb((lin1.r * size1 + lin2.r * size2) / totalWeight) * Constants_js_1.rgbMax,
};
}
return {
b: (0, MathUtils_js_1.mix)(rgb1.b, rgb2.b, size1, size2),
g: (0, MathUtils_js_1.mix)(rgb1.g, rgb2.g, size1, size2),
r: (0, MathUtils_js_1.mix)(rgb1.r, rgb2.r, size1, size2),
};
}
function getLinkColor(p1, p2, linkColor, hdr) {
if (linkColor === Constants_js_1.randomColorValue) {
return getRandomRgbColor();
}
else if (linkColor === Constants_js_1.midColorValue) {
const sourceColor = p1.getFillColor() ?? p1.getStrokeColor(), destColor = p2?.getFillColor() ?? p2?.getStrokeColor();
if (sourceColor && destColor && p2) {
return colorMix(sourceColor, destColor, p1.getRadius(), p2.getRadius(), hdr);
}
else {
const hslColor = sourceColor ?? destColor;
if (hslColor) {
return hslToRgb(hslColor);
}
}
}
else {
return linkColor;
}
return undefined;
}
function getLinkRandomColor(pluginManager, optColor, blink, consent) {
const color = (0, TypeUtils_js_1.isString)(optColor) ? optColor : optColor.value;
if (color === Constants_js_1.randomColorValue) {
if (consent) {
return rangeColorToRgb(pluginManager, {
value: color,
});
}
if (blink) {
return Constants_js_1.randomColorValue;
}
return Constants_js_1.midColorValue;
}
else if (color === Constants_js_1.midColorValue) {
return Constants_js_1.midColorValue;
}
else {
return rangeColorToRgb(pluginManager, {
value: color,
});
}
}
function getHslFromAnimation(animation) {
return animation === undefined
? undefined
: {
h: animation.h.value,
s: animation.s.value,
l: animation.l.value,
};
}
function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
const resColor = {
h: {
enable: false,
value: hsl.h,
min: Constants_js_1.hMin,
max: Constants_js_1.hMax,
},
s: {
enable: false,
value: hsl.s,
min: Constants_js_1.sMin,
max: Constants_js_1.sMax,
},
l: {
enable: false,
value: hsl.l,
min: Constants_js_1.lMin,
max: Constants_js_1.lMax,
},
};
if (animationOptions) {
setColorAnimation(resColor.h, animationOptions.h, reduceFactor);
setColorAnimation(resColor.s, animationOptions.s, reduceFactor);
setColorAnimation(resColor.l, animationOptions.l, reduceFactor);
}
return resColor;
}
function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
colorValue.enable = colorAnimation.enable;
colorValue.min = colorAnimation.min;
colorValue.max = colorAnimation.max;
if (colorValue.enable) {
colorValue.velocity = ((0, MathUtils_js_1.getRangeValue)(colorAnimation.speed) / Constants_js_1.percentDenominator) * reduceFactor;
colorValue.decay = Constants_js_1.decayOffset - (0, MathUtils_js_1.getRangeValue)(colorAnimation.decay);
colorValue.status = AnimationStatus_js_1.AnimationStatus.increasing;
colorValue.loops = Constants_js_1.defaultLoops;
colorValue.maxLoops = (0, MathUtils_js_1.getRangeValue)(colorAnimation.count);
colorValue.time = Constants_js_1.defaultTime;
colorValue.delayTime = (0, MathUtils_js_1.getRangeValue)(colorAnimation.delay) * Constants_js_1.millisecondsToSeconds;
if (!colorAnimation.sync) {
colorValue.velocity *= (0, MathUtils_js_1.getRandom)();
colorValue.value *= (0, MathUtils_js_1.getRandom)();
}
colorValue.initialValue = colorValue.value;
colorValue.offset = (0, MathUtils_js_1.setRangeValue)(colorAnimation.offset);
}
else {
colorValue.velocity = Constants_js_1.defaultVelocity;
}
}
function updateColorValue(data, decrease, delta, _hdr) {
const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minOffset = 0, velocityFactor = 3.6;
if (!data.enable ||
((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
return;
}
data.time ??= 0;
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
data.time += delta.value;
}
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
return;
}
const offset = data.offset ? (0, MathUtils_js_1.randomInRangeValue)(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = data.max, min = data.min;
if (!decrease || data.status === AnimationStatus_js_1.AnimationStatus.increasing) {
data.value += velocity;
if (data.value > max) {
data.loops ??= 0;
data.loops++;
if (decrease) {
data.status = AnimationStatus_js_1.AnimationStatus.decreasing;
}
else {
data.value -= max;
}
}
}
else {
data.value -= velocity;
if (data.value < min) {
data.loops ??= 0;
data.loops++;
data.status = AnimationStatus_js_1.AnimationStatus.increasing;
}
}
if (data.velocity && decay !== identity) {
data.velocity *= decay;
}
data.value = (0, MathUtils_js_1.clamp)(data.value, min, max);
}
function updateColor(color, delta, hdr) {
if (!color) {
return;
}
const { h, s, l } = color;
updateColorValue(h, false, delta, hdr);
updateColorValue(s, true, delta, hdr);
updateColorValue(l, true, delta, hdr);
}
function alterHsl(color, type, value) {
return {
h: color.h,
s: color.s,
l: color.l + (type === AlterType_js_1.AlterType.darken ? -Constants_js_1.lFactor : Constants_js_1.lFactor) * value,
};
}