Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const blendColor = (from: Color | string, to: Color | string) => {
const fromColor = typeof from === 'string' ? color.parse(from) : from;
const toColor = typeof to === 'string' ? color.parse(to) : to;
let blended = { ...fromColor };
// Only use the sqrt blending function for rgba and hex
const blendFunc =
(from as HSLA).hue !== undefined ||
(typeof from === 'string' && hsla.test(from as string))
? getValueFromProgress
: blend;
return (v: number) => {
blended = { ...blended };
for (const key in blended) {
if (key !== 'alpha' && blended.hasOwnProperty(key)) {
blended[key] = blendFunc(fromColor[key], toColor[key], v);
}
}
blended.alpha = getValueFromProgress(fromColor.alpha, toColor.alpha, v);
return blended;
};
};