mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
add checking for bad choices
This commit is contained in:
1 parent
49e8d6f85a
commit
3cfbb99ece
3 files changed
+26
-10
No files matched your search
@@ -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 (
|
||||
|
||||
@@ -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<UserRoomPro
|
||||
const cardColor =
|
||||
shadeColor(backgroundColor, isBackgroundDark ? -80 : 80) ?? color.Background.Container;
|
||||
const textColor =
|
||||
(fetchedBrightness === 'dark' && '#FFFFFF') ||
|
||||
(fetchedBrightness === 'light' && '#000000') ||
|
||||
((fetchedBrightness === 'dark' || isTooDark(innerColor)) && '#FFFFFF') ||
|
||||
((fetchedBrightness === 'light' || isTooBright(innerColor)) && '#000000') ||
|
||||
undefined;
|
||||
|
||||
return (
|
||||
|
||||
@@ -7,10 +7,10 @@ export function shadeColor(initialColor: string, percent: number) {
|
||||
let G = Math.min(parseInt(initialColor.substring(3, 5), 16) * ratio, 255);
|
||||
let B = Math.min(parseInt(initialColor.substring(5, 7), 16) * ratio, 255);
|
||||
|
||||
if (R <= 0 && G <= 0 && B <= 0 && percent > 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;
|
||||
}
|
||||
Reference in new issue
Block a user