diff --git a/frontend/src/app/features/author-browser/components/author-card/author-card.component.html b/frontend/src/app/features/author-browser/components/author-card/author-card.component.html index a02761d6b..42ab0a3df 100644 --- a/frontend/src/app/features/author-browser/components/author-card/author-card.component.html +++ b/frontend/src/app/features/author-browser/components/author-card/author-card.component.html @@ -1,4 +1,10 @@ -
+
@if (hasPhoto) { - +
diff --git a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.html b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.html index 94b1423d2..853e874ce 100644 --- a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.html +++ b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.html @@ -1,4 +1,4 @@ -
+ @if (showOledDarkModeToggle()) { +
+ + + +
+ } +
{ @@ -41,6 +40,7 @@ export const passwordMatchValidator: ValidatorFn = (control: AbstractControl): V InputText, Password, Select, + ToggleSwitch, TranslocoDirective, TranslocoPipe, ], @@ -66,10 +66,12 @@ export class UserProfileDialogComponent { private readonly t = inject(TranslocoService); private readonly destroyRef = inject(DestroyRef); protected readonly activeLang = toSignal(this.t.langChanges$, {initialValue: this.t.getActiveLang()}); - protected readonly selectedThemePreference = computed(() => this.configService.appState().themePreference ?? DEFAULT_APP_THEME); - protected readonly selectedAppearancePreference = computed(() => this.configService.appState().appearancePreference ?? 'system'); + protected readonly selectedThemePreference = computed(() => this.configService.appState().themePreference); + protected readonly selectedAppearancePreference = computed(() => this.configService.appState().appearancePreference); + protected readonly oledDarkMode = computed(() => this.configService.appState().oledDarkMode); + protected readonly showOledDarkModeToggle = computed(() => this.configService.effectiveAppearance() === 'dark'); protected readonly selectedCustomPrimary = computed( - () => this.configService.appState().customPrimary ?? DEFAULT_CUSTOM_PRIMARY, + () => this.configService.appState().customPrimary, ); protected readonly customPrimaryOptions = CUSTOM_PRIMARY_OPTIONS; protected readonly themeOptions = computed(() => { diff --git a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar-item-row.component.scss b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar-item-row.component.scss index 8f1d49fc2..60076398a 100644 --- a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar-item-row.component.scss +++ b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar-item-row.component.scss @@ -41,7 +41,7 @@ } .sidebar-item-container.active-route-container { - background-color: color-mix(in srgb, var(--color-primary) 8%, transparent); + background-color: var(--color-active-surface); } .sidebar-item-link { @@ -233,7 +233,7 @@ a.sidebar-item-link.active-route { } .sidebar-item-container.active-route-container { - background-color: color-mix(in srgb, var(--color-primary) 8%, transparent); + background-color: var(--color-active-surface); } .sidebar-item-container:has(:focus-visible) { diff --git a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.scss b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.scss index 510310d0f..c428067df 100644 --- a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.scss +++ b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.scss @@ -233,7 +233,7 @@ &.active-route { color: var(--color-primary-text); - background-color: color-mix(in srgb, var(--color-primary) 8%, transparent); + background-color: var(--color-active-surface); .sidebar-footer-action-label { color: inherit; @@ -598,7 +598,7 @@ } &.active-route { - background-color: color-mix(in srgb, var(--color-primary) 8%, transparent); + background-color: var(--color-active-surface); color: var(--color-primary-text); } } diff --git a/frontend/src/app/shared/layout/theme/theme-palette-extend.ts b/frontend/src/app/shared/layout/theme/theme-palette-extend.ts index a57b7cee0..1cee387ad 100644 --- a/frontend/src/app/shared/layout/theme/theme-palette-extend.ts +++ b/frontend/src/app/shared/layout/theme/theme-palette-extend.ts @@ -51,6 +51,18 @@ const appHighlight = { focusColor: 'var(--color-primary-text)', }; +const contentSurface = { + background: 'var(--color-page)', + borderColor: 'var(--color-border)', + color: 'var(--color-text)', +}; + +const overlaySurface = { + background: 'var(--color-card)', + borderColor: 'var(--color-border)', + color: 'var(--color-text)', +}; + function buildAppTokenPalette(prefix: 'primary' | 'surface', stops: readonly string[]): ColorPalette { return Object.fromEntries( stops.map((stop) => [stop, `var(--color-${prefix}-${stop})`]) @@ -87,10 +99,19 @@ function buildPrimePalettePreset(theme: ResolvedThemePalettes): object { const AppPrimePreset = definePreset(Aura, { semantic: { colorScheme: { - light: { content: { background: 'var(--color-page)' } }, + light: { + content: contentSurface, + overlay: { + popover: overlaySurface, + modal: overlaySurface, + }, + }, dark: { - content: { background: 'var(--color-page)' }, - // Card menus are surface.800; Aura default hover is also 800 — use app surface-hover mix. + content: contentSurface, + overlay: { + popover: overlaySurface, + modal: overlaySurface, + }, navigation: { item: { focusBackground: 'color-mix(in srgb, {text.color}, transparent 92%)', diff --git a/frontend/src/app/shared/model/app-state.model.spec.ts b/frontend/src/app/shared/model/app-state.model.spec.ts index 5bdc40964..d2bc203d8 100644 --- a/frontend/src/app/shared/model/app-state.model.spec.ts +++ b/frontend/src/app/shared/model/app-state.model.spec.ts @@ -1,32 +1,12 @@ -import {describe, expect, expectTypeOf, it} from 'vitest'; +import {describe, expect, it} from 'vitest'; import { APP_THEME_OPTIONS, - AppearancePreference, - AppState, - AppTheme, - CustomPrimary, DEFAULT_APP_THEME, THEME_REGISTRY, } from './app-state.model'; describe('app-state.model', () => { - it('supports partially specified visual theme state', () => { - const appState: AppState = { - themePreference: DEFAULT_APP_THEME, - appearancePreference: 'system', - }; - - expect(appState.themePreference).toBe(DEFAULT_APP_THEME); - expect(appState.appearancePreference).toBe('system'); - }); - - it('keeps each field optional and constrained to supported values', () => { - expectTypeOf().toEqualTypeOf(); - expectTypeOf().toEqualTypeOf(); - expectTypeOf().toEqualTypeOf(); - }); - it('derives theme options from the registry', () => { expect(APP_THEME_OPTIONS).toBe(THEME_REGISTRY); expect(APP_THEME_OPTIONS.some(option => option.name === DEFAULT_APP_THEME)).toBe(true); diff --git a/frontend/src/app/shared/model/app-state.model.ts b/frontend/src/app/shared/model/app-state.model.ts index eb0c91ac5..21bdba424 100644 --- a/frontend/src/app/shared/model/app-state.model.ts +++ b/frontend/src/app/shared/model/app-state.model.ts @@ -12,7 +12,8 @@ export { export type {AppTheme, CustomPrimary} from './theme-registry'; export interface AppState { - themePreference?: AppTheme; - appearancePreference?: AppearancePreference; - customPrimary?: CustomPrimary; + themePreference: AppTheme; + appearancePreference: AppearancePreference; + customPrimary: CustomPrimary; + oledDarkMode: boolean; } diff --git a/frontend/src/app/shared/service/app-config.service.spec.ts b/frontend/src/app/shared/service/app-config.service.spec.ts index a773de30f..9f8972cac 100644 --- a/frontend/src/app/shared/service/app-config.service.spec.ts +++ b/frontend/src/app/shared/service/app-config.service.spec.ts @@ -67,6 +67,7 @@ describe('AppConfigService', () => { vi.spyOn(window, 'getComputedStyle').mockReturnValue(computedStyle); root.classList.remove('dark'); delete root.dataset['appTheme']; + delete root.dataset['oledDarkMode']; TestBed.resetTestingModule(); TestBed.configureTestingModule({ @@ -84,6 +85,7 @@ describe('AppConfigService', () => { rootStyle.cssText = ''; root.classList.remove('dark'); delete root.dataset['appTheme']; + delete root.dataset['oledDarkMode']; vi.restoreAllMocks(); vi.unstubAllGlobals(); }); @@ -93,6 +95,7 @@ describe('AppConfigService', () => { themePreference: 'grimmory', appearancePreference: 'system', customPrimary: 'orange', + oledDarkMode: false, }); expect(localStorageMock.getItem('appConfigState')).toBeNull(); expect(root.dataset['appTheme']).toBe('grimmory'); @@ -145,6 +148,7 @@ describe('AppConfigService', () => { themePreference: 'grimmory', appearancePreference: 'system', customPrimary: 'orange', + oledDarkMode: false, }); expect(root.dataset['appTheme']).toBe('grimmory'); expect(root.classList.contains('dark')).toBe(false); @@ -152,6 +156,23 @@ describe('AppConfigService', () => { themePreference: 'grimmory', appearancePreference: 'system', customPrimary: 'orange', + oledDarkMode: false, })); }); + + it('applies OLED mode only when the effective appearance is dark', () => { + service.setOledDarkMode(true); + + expect(root.dataset['oledDarkMode']).toBeUndefined(); + + service.setAppearancePreference('dark'); + + expect(root.classList.contains('dark')).toBe(true); + expect(root.dataset['oledDarkMode']).toBe('true'); + + service.setAppearancePreference('light'); + + expect(root.classList.contains('dark')).toBe(false); + expect(root.dataset['oledDarkMode']).toBeUndefined(); + }); }); diff --git a/frontend/src/app/shared/service/app-config.service.ts b/frontend/src/app/shared/service/app-config.service.ts index 7971d2e64..b6b2d20f5 100644 --- a/frontend/src/app/shared/service/app-config.service.ts +++ b/frontend/src/app/shared/service/app-config.service.ts @@ -22,6 +22,8 @@ type StoredAppState = Partial & { surface?: unknown; }; +type AppStatePatch = Partial; + interface LoadedAppState { state: AppState; shouldPersist: boolean; @@ -33,8 +35,10 @@ interface LoadedAppState { export class AppConfigService { private readonly STORAGE_KEY = 'appConfigState'; readonly themes = APP_THEME_OPTIONS; - private readonly appStateSignal = signal({}); + private readonly appStateSignal = signal(this.withDefaults({})); + private readonly effectiveAppearanceSignal = signal<'light' | 'dark'>('dark'); readonly appState = this.appStateSignal.asReadonly(); + readonly effectiveAppearance = this.effectiveAppearanceSignal.asReadonly(); document = inject(DOCUMENT); platformId = inject(PLATFORM_ID); faviconService = inject(FaviconService); @@ -61,7 +65,11 @@ export class AppConfigService { this.updateAppState({appearancePreference}); } - private updateAppState(patch: AppState): void { + setOledDarkMode(oledDarkMode: boolean): void { + this.updateAppState({oledDarkMode}); + } + + private updateAppState(patch: AppStatePatch): void { const state = this.withDefaults({ ...this.appStateSignal(), ...patch, @@ -103,6 +111,7 @@ export class AppConfigService { themePreference: state.themePreference, appearancePreference: state.appearancePreference, customPrimary: state.customPrimary, + oledDarkMode: state.oledDarkMode, }); } @@ -110,22 +119,23 @@ export class AppConfigService { return 'preset' in state || 'primary' in state || 'surface' in state; } - private withDefaults(state: AppState): AppState { + private withDefaults(state: AppStatePatch): AppState { return { themePreference: this.resolveThemePreference(state.themePreference), appearancePreference: this.resolveAppearancePreference(state.appearancePreference), customPrimary: this.resolveCustomPrimary(state.customPrimary), + oledDarkMode: state.oledDarkMode === true, }; } - private resolveCustomPrimary(customPrimary: AppState['customPrimary']): CustomPrimary { + private resolveCustomPrimary(customPrimary: AppStatePatch['customPrimary']): CustomPrimary { if (customPrimary && CUSTOM_PRIMARY_OPTIONS.includes(customPrimary)) { return customPrimary; } return DEFAULT_CUSTOM_PRIMARY; } - private resolveThemePreference(themePreference: AppState['themePreference']): AppTheme { + private resolveThemePreference(themePreference: AppStatePatch['themePreference']): AppTheme { if (themePreference && this.themes.some((option) => option.name === themePreference)) { return themePreference; } @@ -133,7 +143,7 @@ export class AppConfigService { return DEFAULT_APP_THEME; } - private resolveAppearancePreference(appearancePreference: AppState['appearancePreference']): AppearancePreference { + private resolveAppearancePreference(appearancePreference: AppStatePatch['appearancePreference']): AppearancePreference { if (appearancePreference === 'light' || appearancePreference === 'dark' || appearancePreference === 'system') { return appearancePreference; } @@ -152,12 +162,12 @@ export class AppConfigService { private saveAppState(state: AppState): void { if (isPlatformBrowser(this.platformId)) { - localStorage.setItem(this.STORAGE_KEY, JSON.stringify(this.withDefaults(state))); + localStorage.setItem(this.STORAGE_KEY, JSON.stringify(state)); } } applyCurrentTheme(): void { - this.applyAppState(this.withDefaults(this.appStateSignal())); + this.applyAppState(this.appStateSignal()); } private applyAppState(state: AppState): void { @@ -177,8 +187,14 @@ export class AppConfigService { const appearancePreference = this.resolveAppearancePreference(state.appearancePreference); const effective = this.effectiveAppearancePreference(appearancePreference); + this.effectiveAppearanceSignal.set(effective); root.dataset['appTheme'] = theme; root.classList.toggle('dark', effective === 'dark'); + if (state.oledDarkMode && effective === 'dark') { + root.dataset['oledDarkMode'] = 'true'; + } else { + delete root.dataset['oledDarkMode']; + } root.style.setProperty('color-scheme', effective); this.applyCustomPrimary(root, theme, this.resolveCustomPrimary(state.customPrimary)); this.syncSystemSchemeListener(appearancePreference); diff --git a/frontend/src/app/shared/styles/_panel-shared.scss b/frontend/src/app/shared/styles/_panel-shared.scss index 6ff43d7a7..3bd84b9bb 100644 --- a/frontend/src/app/shared/styles/_panel-shared.scss +++ b/frontend/src/app/shared/styles/_panel-shared.scss @@ -9,6 +9,7 @@ padding: 1.5rem 1.5rem 1.25rem; border-radius: 10px 10px 0 0; border: 1px solid var(--border-color); + background: var(--color-card); box-shadow: 0 2px 6px rgb(0 0 0 / 8%); .header-icon-wrapper { diff --git a/frontend/src/assets/styles/compat.scss b/frontend/src/assets/styles/compat.scss index 56bd9a146..4994b10c0 100644 --- a/frontend/src/assets/styles/compat.scss +++ b/frontend/src/assets/styles/compat.scss @@ -112,6 +112,11 @@ } } +.p-dialog .p-dialog-header, +.dialog-header { + background: var(--color-page) !important; +} + .dialog-xs.p-dialog { width: 90vw; max-width: 400px; diff --git a/frontend/src/assets/styles/tailwind.css b/frontend/src/assets/styles/tailwind.css index 2158a2a1f..b593044c4 100644 --- a/frontend/src/assets/styles/tailwind.css +++ b/frontend/src/assets/styles/tailwind.css @@ -40,7 +40,9 @@ --color-page: var(--color-surface-50); --color-card: var(--color-surface-0); --color-border: var(--color-surface-200); + --color-card-outline: transparent; --color-surface-hover: color-mix(in srgb, var(--color-text) 8%, transparent); + --color-active-surface: color-mix(in srgb, var(--color-primary) 8%, transparent); --color-text: var(--color-surface-950); --color-text-secondary: var(--color-surface-600); --color-text-muted: var(--color-surface-500); @@ -60,7 +62,9 @@ --color-page: var(--color-surface-50); --color-card: var(--color-surface-0); --color-border: var(--color-surface-200); + --color-card-outline: transparent; --color-surface-hover: color-mix(in srgb, var(--color-text) 8%, transparent); + --color-active-surface: color-mix(in srgb, var(--color-primary) 8%, transparent); --color-text: var(--color-surface-950); --color-text-secondary: var(--color-surface-600); --color-text-muted: var(--color-surface-500); @@ -490,6 +494,15 @@ --color-surface-950: var(--color-zinc-950); } +.dark[data-oled-dark-mode="true"] { + --color-app: #000000; + --color-page: #000000; + --color-card: #000000; + --color-border: color-mix(in srgb, var(--color-text) 18%, transparent); + --color-card-outline: color-mix(in srgb, var(--color-text) 14%, transparent); + --color-active-surface: color-mix(in srgb, var(--color-primary) 14%, transparent); +} + @source inline("bg-{red,orange,amber,yellow,lime,green,emerald,teal,cyan,sky,blue,indigo,violet,purple,fuchsia,pink,rose}-{50,100,200,300,400,500,600,700,800,900,950}"); @source not "../embedpdf-frame.html"; diff --git a/frontend/src/assets/styles/utilities.scss b/frontend/src/assets/styles/utilities.scss index 9f0268162..508e26988 100644 --- a/frontend/src/assets/styles/utilities.scss +++ b/frontend/src/assets/styles/utilities.scss @@ -30,6 +30,21 @@ --control-bg: color-mix(in srgb, var(--color-surface-0) 6%, var(--color-card)); background: var(--color-card); + box-shadow: inset 0 0 0 1px var(--color-card-outline); +} + +.surface-card-outline { + position: relative; + + &::after { + content: ""; + position: absolute; + inset: 0; + z-index: 5; + border-radius: inherit; + box-shadow: inset 0 0 0 1px var(--color-card-outline); + pointer-events: none; + } } .gradient-divider { diff --git a/frontend/src/i18n/en/settings-view.json b/frontend/src/i18n/en/settings-view.json index c1b07de33..bc9ea3b0a 100644 --- a/frontend/src/i18n/en/settings-view.json +++ b/frontend/src/i18n/en/settings-view.json @@ -8,7 +8,8 @@ }, "theme": { "sectionTitle": "Display", - "sectionDesc": "Pick your preferred app theme and appearance mode for this browser." + "sectionDesc": "Pick your preferred app theme and appearance mode for this browser.", + "oledDarkMode": "OLED dark mode" }, "librarySort": { "sectionTitle": "Library and Shelf View & Sort Preferences",