From bbd49d4634e99026edb9dd5ce4388cd2b65ad8b8 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Thu, 2 Nov 2023 15:45:04 +0000 Subject: [PATCH] stream_color: Extract function to get corrected color. --- web/src/stream_color.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/web/src/stream_color.ts b/web/src/stream_color.ts index 9693a54ea4..4de8981c53 100644 --- a/web/src/stream_color.ts +++ b/web/src/stream_color.ts @@ -1,3 +1,4 @@ +import type {Colord} from "colord"; import {colord, extend} from "colord"; import lchPlugin from "colord/plugins/lch"; import mixPlugin from "colord/plugins/mix"; @@ -25,7 +26,7 @@ export function update_stream_recipient_color($stream_header: JQuery): void { } } -export function get_stream_privacy_icon_color(hex_color: string): string { +export function get_corrected_color(hex_color: string): Colord { // LCH stands for Lightness, Chroma, and Hue. // This function restricts Lightness of a color to be between 20 to 75. const color = colord(hex_color).toLch(); @@ -36,13 +37,17 @@ export function get_stream_privacy_icon_color(hex_color: string): string { } else if (color.l > max_color_l) { color.l = max_color_l; } - return colord(color).toHex(); + return colord(color); +} + +export function get_stream_privacy_icon_color(hex_color: string): string { + return get_corrected_color(hex_color).toHex(); } export function get_recipient_bar_color(color: string): string { // Mixes 50% of color to 40% of white (light theme) / black (dark theme). const using_dark_theme = settings_data.using_dark_theme(); - color = get_stream_privacy_icon_color(color); + color = get_corrected_color(color).toHex(); return colord(using_dark_theme ? "#000000" : "#f9f9f9") .mix(color, using_dark_theme ? 0.38 : 0.22) .toHex();