From 3cfbb99ece5d4e2755eef51ce6be33d358badc56 Mon Sep 17 00:00:00 2001 From: Shea Duma Date: Thu, 23 Apr 2026 03:05:51 +0300 Subject: [PATCH] add checking for bad choices --- src/app/components/user-profile/UserHero.tsx | 6 ++--- .../user-profile/UserRoomProfile.tsx | 6 ++--- src/app/utils/shadeColor.ts | 24 +++++++++++++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/app/components/user-profile/UserHero.tsx b/src/app/components/user-profile/UserHero.tsx index 3613978fb..16935912b 100644 --- a/src/app/components/user-profile/UserHero.tsx +++ b/src/app/components/user-profile/UserHero.tsx @@ -30,7 +30,7 @@ import { AvatarPresence, PresenceBadge } from '$components/presence'; import { UserAvatar } from '$components/user-avatar'; import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze'; import { useUserProfile } from '$hooks/useUserProfile'; -import { shadeColor } from '$utils/shadeColor'; +import { isTooBright, isTooDark, shadeColor } from '$utils/shadeColor'; import * as css from './styles.css'; type UserHeroProps = { @@ -79,8 +79,8 @@ export function UserHero({ userId, avatarUrl, bannerUrl, presence, autoplayGifs const cardColor = shadeColor(backgroundColor, isBackgroundDark ? -80 : 80) ?? standardColors.Background.Container; const textColor = - (fetchedBrightness === 'dark' && '#FFFFFF') || - (fetchedBrightness === 'light' && '#000000') || + ((fetchedBrightness === 'dark' || isTooDark(cardColor)) && '#FFFFFF') || + ((fetchedBrightness === 'light' || isTooBright(cardColor)) && '#000000') || undefined; return ( diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index 9602b54b7..f312ada46 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -48,7 +48,7 @@ import { filterPronounsByLanguage } from '$utils/pronouns'; import { useSetting } from '$state/hooks/settings'; import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl'; import { TextViewerContent } from '$components/text-viewer'; -import { shadeColor } from '$utils/shadeColor'; +import { isTooBright, isTooDark, isTooExtreme, shadeColor } from '$utils/shadeColor'; import { CreatorChip } from './CreatorChip'; import { UserInviteAlert, UserBanAlert, UserModeration, UserKickAlert } from './UserModeration'; import { PowerChip } from './PowerChip'; @@ -497,8 +497,8 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly 0) { - R = R <= 0 ? Math.max(178 - R, 0) : R; - G = G <= 0 ? Math.max(178 - G, 0) : G; - B = B <= 0 ? Math.max(178 - B, 0) : B; + if (R <= 8 && G <= 8 && B <= 8 && percent > 0) { + R = R <= 8 ? Math.max(178 - R, 0) : R; + G = G <= 8 ? Math.max(178 - G, 0) : G; + B = B <= 8 ? Math.max(178 - B, 0) : B; } const RR = Math.floor(R).toString(16).padStart(2, '0'); @@ -19,3 +19,19 @@ export function shadeColor(initialColor: string, percent: number) { return `#${RR}${GG}${BB}`; } + +export function isTooDark(color?: string) { + if (!color) return false; + const R = parseInt(color.substring(1, 3), 16); + const G = parseInt(color.substring(3, 5), 16); + const B = parseInt(color.substring(5, 7), 16); + return (R + G + B) / 3 < 64; +} + +export function isTooBright(color?: string) { + if (!color) return false; + const R = parseInt(color.substring(1, 3), 16); + const G = parseInt(color.substring(3, 5), 16); + const B = parseInt(color.substring(5, 7), 16); + return (R + G + B) / 3 > 192; +}