1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

added profile quick info

This commit is contained in:
Fedor Katurov 2022-07-19 14:58:28 +07:00
parent fa17aac056
commit 1241d2c784
9 changed files with 131 additions and 64 deletions

View file

@ -1,6 +1,7 @@
import { darken, desaturate, parseToHsla } from 'color2k';
import { adjustHue, darken, desaturate, parseToHsla } from 'color2k';
import { DEFAULT_DOMINANT_COLOR } from '~/constants/node';
import { stringToColour } from '~/utils/dom';
export const normalizeBrightColor = (color?: string, saturationExp = 3, lightnessExp = 3) => {
if (!color) {
@ -14,3 +15,23 @@ export const normalizeBrightColor = (color?: string, saturationExp = 3, lightnes
const desaturated = saturationExp > 1 ? desaturate(color, saturation ** saturationExp) : color;
return lightnessExp > 1 ? darken(desaturated, lightness ** lightnessExp) : desaturated;
};
export const generateColorTriplet = (val: string, saturation: number, lightness: number) => {
const color = normalizeBrightColor(stringToColour(val), saturation, lightness);
return [
color,
normalizeBrightColor(adjustHue(color, 45), saturation, lightness),
normalizeBrightColor(adjustHue(color, 90), saturation, lightness),
];
};
export const generateGradientFromColor = (
val: string,
saturation = 3,
lightness = 3,
angle = 155
) => {
const [color, second, third] = generateColorTriplet(val, saturation, lightness);
return `linear-gradient(${angle}deg, ${color}, ${second}, ${third})`;
};