From 18d880dea364ac504591da7e45af6239cbdcc7f7 Mon Sep 17 00:00:00 2001 From: celine Date: Fri, 16 Jan 2026 17:04:04 -0500 Subject: [PATCH] fixing some color logic stuff --- .../ThemeManager/PublicationThemeProvider.tsx | 36 +------------------ components/ThemeManager/ThemeProvider.tsx | 20 +++++------ 2 files changed, 11 insertions(+), 45 deletions(-) diff --git a/components/ThemeManager/PublicationThemeProvider.tsx b/components/ThemeManager/PublicationThemeProvider.tsx index c21302c1..142520fe 100644 --- a/components/ThemeManager/PublicationThemeProvider.tsx +++ b/components/ThemeManager/PublicationThemeProvider.tsx @@ -171,43 +171,9 @@ export const useLocalPubTheme = ( ...localOverrides, showPageBackground, }; - let newAccentContrast; - let sortedAccents = [newTheme.accent1, newTheme.accent2].sort((a, b) => { - return ( - getColorDifference( - colorToString(b, "rgb"), - colorToString( - showPageBackground ? newTheme.bgPage : newTheme.bgLeaflet, - "rgb", - ), - ) - - getColorDifference( - colorToString(a, "rgb"), - colorToString( - showPageBackground ? newTheme.bgPage : newTheme.bgLeaflet, - "rgb", - ), - ) - ); - }); - if ( - getColorDifference( - colorToString(sortedAccents[0], "rgb"), - colorToString(newTheme.primary, "rgb"), - ) < 0.15 && - getColorDifference( - colorToString(sortedAccents[1], "rgb"), - colorToString( - showPageBackground ? newTheme.bgPage : newTheme.bgLeaflet, - "rgb", - ), - ) > 0.08 - ) { - newAccentContrast = sortedAccents[1]; - } else newAccentContrast = sortedAccents[0]; + return { ...newTheme, - accentContrast: newAccentContrast, }; }, [pubTheme, localOverrides, showPageBackground]); return { diff --git a/components/ThemeManager/ThemeProvider.tsx b/components/ThemeManager/ThemeProvider.tsx index a6211c17..5d00768c 100644 --- a/components/ThemeManager/ThemeProvider.tsx +++ b/components/ThemeManager/ThemeProvider.tsx @@ -134,11 +134,10 @@ export const BaseThemeProvider = ({ // pageBg should inherit from leafletBg const bgPage = !showPageBackground && !hasBackgroundImage ? bgLeaflet : bgPageProp; - // set accent contrast to the accent color that has the highest contrast with the page background - let accentContrast; - //sorting the accents by contrast on background + let accentContrast; let sortedAccents = [accent1, accent2].sort((a, b) => { + // sort accents by contrast against the background return ( getColorDifference( colorToString(b, "rgb"), @@ -150,23 +149,24 @@ export const BaseThemeProvider = ({ ) ); }); - - // if the contrast-y accent is too similar to the primary text color, - // and the not contrast-y option is different from the backgrond, - // then use the not contrasty option - if ( + // if the contrast-y accent is too similar to text color getColorDifference( colorToString(sortedAccents[0], "rgb"), colorToString(primary, "rgb"), ) < 0.15 && + // and if the other accent is different enough from the background getColorDifference( colorToString(sortedAccents[1], "rgb"), colorToString(showPageBackground ? bgPage : bgLeaflet, "rgb"), - ) > 0.08 + ) > 0.31 ) { + //then choose the less contrast-y accent accentContrast = sortedAccents[1]; - } else accentContrast = sortedAccents[0]; + } else { + // otherwise, choose the more contrast-y option + accentContrast = sortedAccents[0]; + } useEffect(() => { if (local) return; -- 2.51.2