@@ -2,6 +2,9 @@ import type { RemovableRef } from '@vueuse/core'
22import { useLocalStorage } from '@vueuse/core'
33import { ACCENT_COLORS } from '#shared/utils/constants'
44import type { LocaleObject } from '@nuxtjs/i18n'
5+ import { BACKGROUND_THEMES } from '#shared/utils/constants'
6+
7+ type BackgroundThemeId = keyof typeof BACKGROUND_THEMES
58
69type AccentColorId = keyof typeof ACCENT_COLORS
710
@@ -15,6 +18,8 @@ export interface AppSettings {
1518 includeTypesInInstall : boolean
1619 /** Accent color theme */
1720 accentColorId : AccentColorId | null
21+ /** Preferred background shade */
22+ preferredBackgroundTheme : BackgroundThemeId | null
1823 /** Hide platform-specific packages (e.g., @scope/pkg-linux-x64) from search results */
1924 hidePlatformPackages : boolean
2025 /** User-selected locale */
@@ -30,6 +35,7 @@ const DEFAULT_SETTINGS: AppSettings = {
3035 accentColorId : null ,
3136 hidePlatformPackages : true ,
3237 selectedLocale : null ,
38+ preferredBackgroundTheme : null ,
3339 sidebar : {
3440 collapsed : [ ] ,
3541 } ,
@@ -93,3 +99,28 @@ export function useAccentColor() {
9399 setAccentColor,
94100 }
95101}
102+
103+ export function useBackgroundTheme ( ) {
104+ const backgroundThemes = Object . entries ( BACKGROUND_THEMES ) . map ( ( [ id , value ] ) => ( {
105+ id : id as BackgroundThemeId ,
106+ name : id ,
107+ value,
108+ } ) )
109+
110+ const { settings } = useSettings ( )
111+
112+ function setBackgroundTheme ( id : BackgroundThemeId | null ) {
113+ if ( id ) {
114+ document . documentElement . dataset . bgTheme = id
115+ } else {
116+ document . documentElement . removeAttribute ( 'data-bg-theme' )
117+ }
118+ settings . value . preferredBackgroundTheme = id
119+ }
120+
121+ return {
122+ backgroundThemes,
123+ selectedBackgroundTheme : computed ( ( ) => settings . value . preferredBackgroundTheme ) ,
124+ setBackgroundTheme,
125+ }
126+ }
0 commit comments