a tool for shared writing and social publishing

fixing some color logic stuff

+11 -45
+1 -35
components/ThemeManager/PublicationThemeProvider.tsx
··· 171 171 ...localOverrides, 172 172 showPageBackground, 173 173 }; 174 - let newAccentContrast; 175 - let sortedAccents = [newTheme.accent1, newTheme.accent2].sort((a, b) => { 176 - return ( 177 - getColorDifference( 178 - colorToString(b, "rgb"), 179 - colorToString( 180 - showPageBackground ? newTheme.bgPage : newTheme.bgLeaflet, 181 - "rgb", 182 - ), 183 - ) - 184 - getColorDifference( 185 - colorToString(a, "rgb"), 186 - colorToString( 187 - showPageBackground ? newTheme.bgPage : newTheme.bgLeaflet, 188 - "rgb", 189 - ), 190 - ) 191 - ); 192 - }); 193 - if ( 194 - getColorDifference( 195 - colorToString(sortedAccents[0], "rgb"), 196 - colorToString(newTheme.primary, "rgb"), 197 - ) < 0.15 && 198 - getColorDifference( 199 - colorToString(sortedAccents[1], "rgb"), 200 - colorToString( 201 - showPageBackground ? newTheme.bgPage : newTheme.bgLeaflet, 202 - "rgb", 203 - ), 204 - ) > 0.08 205 - ) { 206 - newAccentContrast = sortedAccents[1]; 207 - } else newAccentContrast = sortedAccents[0]; 174 + 208 175 return { 209 176 ...newTheme, 210 - accentContrast: newAccentContrast, 211 177 }; 212 178 }, [pubTheme, localOverrides, showPageBackground]); 213 179 return {
+10 -10
components/ThemeManager/ThemeProvider.tsx
··· 134 134 // pageBg should inherit from leafletBg 135 135 const bgPage = 136 136 !showPageBackground && !hasBackgroundImage ? bgLeaflet : bgPageProp; 137 - // set accent contrast to the accent color that has the highest contrast with the page background 137 + 138 138 let accentContrast; 139 - 140 - //sorting the accents by contrast on background 141 139 let sortedAccents = [accent1, accent2].sort((a, b) => { 140 + // sort accents by contrast against the background 142 141 return ( 143 142 getColorDifference( 144 143 colorToString(b, "rgb"), ··· 150 149 ) 151 150 ); 152 151 }); 153 - 154 - // if the contrast-y accent is too similar to the primary text color, 155 - // and the not contrast-y option is different from the backgrond, 156 - // then use the not contrasty option 157 - 158 152 if ( 153 + // if the contrast-y accent is too similar to text color 159 154 getColorDifference( 160 155 colorToString(sortedAccents[0], "rgb"), 161 156 colorToString(primary, "rgb"), 162 157 ) < 0.15 && 158 + // and if the other accent is different enough from the background 163 159 getColorDifference( 164 160 colorToString(sortedAccents[1], "rgb"), 165 161 colorToString(showPageBackground ? bgPage : bgLeaflet, "rgb"), 166 - ) > 0.08 162 + ) > 0.31 167 163 ) { 164 + //then choose the less contrast-y accent 168 165 accentContrast = sortedAccents[1]; 169 - } else accentContrast = sortedAccents[0]; 166 + } else { 167 + // otherwise, choose the more contrast-y option 168 + accentContrast = sortedAccents[0]; 169 + } 170 170 171 171 useEffect(() => { 172 172 if (local) return;