From 63cfb0cd1c0d54abc565d528f3591433ec078248 Mon Sep 17 00:00:00 2001 From: Rodrigo Luglio Date: Tue, 1 Oct 2024 18:33:28 -0300 Subject: [PATCH] fix saturation 0 bug with math max --- src/lib/generator/syntaxColors.ts | 13 ++++++++----- src/lib/generator/uiColors.ts | 8 +++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lib/generator/syntaxColors.ts b/src/lib/generator/syntaxColors.ts index 9ea70f7..b7efb38 100644 --- a/src/lib/generator/syntaxColors.ts +++ b/src/lib/generator/syntaxColors.ts @@ -2,6 +2,7 @@ import { randomInteger } from '@/lib/utils/math' import { adjustCommentColor, ensureReadability } from './colorUtils' import { SyntaxColors } from '@/lib/types/colors' import Color from 'color' +import { Exo_2 } from 'next/font/google' export function generateSyntaxColors( backgroundColor: string, @@ -23,7 +24,10 @@ export function generateSyntaxColors( highContrast: boolean = true ) => { const hue = (schemeHues[hueIndex % schemeHues.length] + hueShift) % 360 - const saturation = Math.min(100, syntaxSaturation * saturationMultiplier) + const saturation = Math.max( + 2, + Math.min(100, syntaxSaturation * saturationMultiplier) + ) const lightness = Math.min( 100, Math.max( @@ -281,11 +285,10 @@ export function updateSyntaxColorsWithSaturation( saturationMultiplier: number ) => { const hsl = Color(color).hsl() - let newSaturation = Math.min( - 100, - newSyntaxSaturation * saturationMultiplier + let newSaturation = Math.max( + 2, + Math.min(100, newSyntaxSaturation * saturationMultiplier) ) - if (newSaturation < 2) newSaturation = 2 return Color.hsl(hsl.hue(), newSaturation, hsl.lightness()).hex() } diff --git a/src/lib/generator/uiColors.ts b/src/lib/generator/uiColors.ts index 009bc6b..d71ff5f 100644 --- a/src/lib/generator/uiColors.ts +++ b/src/lib/generator/uiColors.ts @@ -39,7 +39,7 @@ export function generateThemeColors( hue = (hue + randomHueShift + 360) % 360 saturation = Math.max( - 0, + 2, Math.min(100, saturation + randomSaturationShift) ) lightness = Math.max(0, Math.min(100, lightness + randomLightnessShift)) @@ -203,8 +203,10 @@ export function updateThemeColorsWithSaturation( saturationMultiplier: number ) => { const hsl = Color(color).hsl() - let newSaturation = Math.min(100, newUiSaturation * saturationMultiplier) - if (newSaturation < 2) newSaturation = 2 + let newSaturation = Math.max( + 2, + Math.min(100, newUiSaturation * saturationMultiplier) + ) return Color.hsl(hsl.hue(), newSaturation, hsl.lightness()).hex() }