Improve theme auto background color

Should keep more of the original color, which previously got "washed out" because it was darkened/lightened too much
This commit is contained in:
schroda
2026-01-02 21:12:38 +01:00
parent 1d54a24adf
commit a317d55320
2 changed files with 16 additions and 11 deletions

View File

@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## [Unreleased] (Preview) ## [Unreleased] (Preview)
### Changed
- (**Theme**) Improve automatic theme background colors
## [20251230.01] (r2937) - 2025-12-30 ## [20251230.01] (r2937) - 2025-12-30
### Added ### Added

View File

@@ -8,9 +8,7 @@
import { import {
createTheme as createMuiTheme, createTheme as createMuiTheme,
darken,
Direction, Direction,
lighten,
responsiveFontSizes, responsiveFontSizes,
Theme, Theme,
TypeBackground, TypeBackground,
@@ -21,13 +19,14 @@ import { useCallback } from 'react';
import { deepmerge } from '@mui/utils'; import { deepmerge } from '@mui/utils';
import { Palette } from '@vibrant/color'; import { Palette } from '@vibrant/color';
import { PaletteBackgroundChannel } from 'node_modules/@mui/material/esm/styles/createThemeWithVars'; import { PaletteBackgroundChannel } from 'node_modules/@mui/material/esm/styles/createThemeWithVars';
import { complement } from 'polished'; import { complement, hsl, parseToHsl } from 'polished';
import { MediaQuery } from '@/base/utils/MediaQuery.tsx'; import { MediaQuery } from '@/base/utils/MediaQuery.tsx';
import { AppTheme } from '@/features/theme/services/AppThemes.ts'; import { AppTheme } from '@/features/theme/services/AppThemes.ts';
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts'; import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
import { applyStyles } from '@/base/utils/ApplyStyles.ts'; import { applyStyles } from '@/base/utils/ApplyStyles.ts';
import { TAppThemeContext, ThemeMode } from '@/features/theme/AppTheme.types.ts'; import { TAppThemeContext, ThemeMode } from '@/features/theme/AppTheme.types.ts';
import { ThemeFontLoader } from '@/features/theme/services/ThemeFontLoader.ts'; import { ThemeFontLoader } from '@/features/theme/services/ThemeFontLoader.ts';
import { coerceIn } from '@/lib/HelperFunctions.ts';
const SCROLLBAR_SIZE = 14; const SCROLLBAR_SIZE = 14;
@@ -44,15 +43,21 @@ const getBackgroundColor = (
}; };
} }
const createColors = (color: string, lightnessPaper: number, lightnessDefault: number) => {
const colorHsl = parseToHsl(color);
return {
paper: hsl(colorHsl.hue, coerceIn(colorHsl.saturation + 0.15, 0, 1), lightnessPaper),
default: hsl(colorHsl.hue, coerceIn(colorHsl.saturation + 0.15, 0, 1), lightnessDefault),
};
};
if (type === 'light' && !!theme.colorSchemes.light) { if (type === 'light' && !!theme.colorSchemes.light) {
if (typeof appTheme.colorSchemes?.light === 'object' && appTheme.colorSchemes.light.palette?.background) { if (typeof appTheme.colorSchemes?.light === 'object' && appTheme.colorSchemes.light.palette?.background) {
return appTheme.colorSchemes.light.palette.background; return appTheme.colorSchemes.light.palette.background;
} }
return { return createColors(theme.colorSchemes.light.palette.primary.dark, 0.87, 0.93);
paper: lighten(theme.colorSchemes.light.palette.primary.dark, 0.7),
default: lighten(theme.colorSchemes.light.palette.primary.dark, 0.8),
};
} }
if (type === 'dark' && !!theme.colorSchemes.dark) { if (type === 'dark' && !!theme.colorSchemes.dark) {
@@ -60,10 +65,7 @@ const getBackgroundColor = (
return appTheme.colorSchemes.dark.palette.background; return appTheme.colorSchemes.dark.palette.background;
} }
return { return createColors(theme.colorSchemes.dark.palette.primary.dark, 0.06, 0.03);
paper: darken(theme.colorSchemes.dark.palette.primary.dark, 0.8),
default: darken(theme.colorSchemes.dark.palette.primary.dark, 0.9),
};
} }
return undefined; return undefined;