Import/export chat styles

This commit is contained in:
Fedor Indutny
2024-07-15 13:58:55 -07:00
committed by GitHub
parent 6fb76e00c4
commit 8f2061e11d
15 changed files with 663 additions and 47 deletions

View File

@@ -1,6 +1,8 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { hslToRGB } from '../../util/hslToRGB';
function getRatio(min: number, max: number, value: number) {
return (value - min) / (max - min);
}
@@ -22,30 +24,6 @@ function getHSLValues(percentage: number): [number, number, number] {
return [338 * ratio, 1, 0.5];
}
// https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative
function hslToRGB(
h: number,
s: number,
l: number
): {
r: number;
g: number;
b: number;
} {
const a = s * Math.min(l, 1 - l);
function f(n: number): number {
const k = (n + h / 30) % 12;
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
}
return {
r: Math.round(255 * f(0)),
g: Math.round(255 * f(8)),
b: Math.round(255 * f(4)),
};
}
export function getHSL(percentage: number): string {
const [h, s, l] = getHSLValues(percentage);
return `hsl(${h}, ${s * 100}%, ${l * 100}%)`;