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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 663 additions and 47 deletions

26
ts/util/hslToRGB.ts Normal file
View file

@ -0,0 +1,26 @@
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative
export 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)),
};
}