2022-04-21 22:51:48 +00:00
|
|
|
import { reactive } from 'vue'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { preferenceStore as preferences } from '@/stores'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-20 09:34:15 +00:00
|
|
|
import bgRosePetal from '@/../img/themes/bg-rose-petals.svg'
|
|
|
|
import bgPurpleWaves from '@/../img/themes/bg-purple-waves.svg'
|
|
|
|
import bgPopCulture from '@/../img/themes/bg-pop-culture.jpg'
|
|
|
|
import bgJungle from '@/../img/themes/bg-jungle.jpg'
|
|
|
|
import bgMountains from '@/../img/themes/bg-mountains.jpg'
|
|
|
|
import bgPines from '@/../img/themes/bg-pines.jpg'
|
|
|
|
import bgNemo from '@/../img/themes/bg-nemo.jpg'
|
|
|
|
import bgCat from '@/../img/themes/bg-cat.jpg'
|
2022-07-04 17:47:46 +00:00
|
|
|
import { clone } from 'lodash'
|
2022-04-20 09:34:15 +00:00
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
export const themeStore = {
|
2022-07-04 17:47:46 +00:00
|
|
|
defaultProperties: {
|
|
|
|
'--color-text-primary': undefined,
|
|
|
|
'--color-text-secondary': undefined,
|
|
|
|
'--color-bg-primary': undefined,
|
|
|
|
'--color-bg-secondary': undefined,
|
|
|
|
'--color-highlight': undefined,
|
|
|
|
'--bg-image': undefined,
|
|
|
|
'--bg-position': undefined,
|
|
|
|
'--bg-attachment': undefined,
|
|
|
|
'--bg-size': undefined
|
|
|
|
} as Record<ThemeableProperty, string>,
|
|
|
|
|
2022-04-21 22:51:48 +00:00
|
|
|
state: reactive({
|
2022-04-15 14:24:30 +00:00
|
|
|
themes: [
|
|
|
|
{
|
|
|
|
id: 'classic',
|
|
|
|
thumbnailColor: '#181818'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'violet',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailColor: '#31094e',
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#31094e'
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'oak',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailColor: '#560d25',
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#560d25'
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'slate',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailColor: '#29434e',
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#29434e'
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'madison',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailColor: '#0e3463',
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#0e3463',
|
|
|
|
'--color-bg-highlight': '#fbab18'
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'astronaut',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailColor: '#2a3074',
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#2a3074'
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'chocolate',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailColor: '#3f2724',
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#3f2724'
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'laura',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailColor: '#126673',
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#126673',
|
|
|
|
'--color-highlight': 'rgba(10, 244, 255, .64)'
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'rose-petals',
|
|
|
|
name: '…Has Its Thorns',
|
|
|
|
thumbnailColor: '#7d083b',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailUrl: bgRosePetal,
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#7d083b',
|
|
|
|
'--bg-image': `url(${bgRosePetal})`
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'purple-waves',
|
|
|
|
name: 'Waves of Fortune',
|
|
|
|
thumbnailColor: '#44115c',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailUrl: bgPurpleWaves,
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#44115c',
|
|
|
|
'--bg-image': `url(${bgPurpleWaves})`
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'pop-culture',
|
|
|
|
thumbnailColor: '#ad0937',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailUrl: bgPopCulture,
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#ad0937',
|
|
|
|
'--color-highlight': 'rgba(234, 208, 110, .9)',
|
|
|
|
'--bg-image': `url(${bgPopCulture})`
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'jungle',
|
|
|
|
name: 'Welcome to the Jungle',
|
|
|
|
thumbnailColor: '#0f0f03',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailUrl: bgJungle,
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#0f0f03',
|
|
|
|
'--bg-image': `url(${bgJungle})`
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'mountains',
|
|
|
|
name: 'Rocky Mountain High',
|
|
|
|
thumbnailColor: '#0e2656',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailUrl: bgMountains,
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#0e2656',
|
|
|
|
'--bg-image': `url(${bgMountains})`
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'pines',
|
|
|
|
name: 'In the Pines',
|
|
|
|
thumbnailColor: '#06090c',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailUrl: bgPines,
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#06090c',
|
|
|
|
'--color-highlight': '#5984b9',
|
|
|
|
'--bg-image': `url(${bgPines})`
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'nemo',
|
|
|
|
thumbnailColor: '#031724',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailUrl: bgNemo,
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#031724',
|
|
|
|
'--bg-image': `url(${bgNemo})`
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'cat',
|
|
|
|
name: 'What\'s New Pussycat?',
|
|
|
|
thumbnailColor: '#000',
|
2022-07-04 17:47:46 +00:00
|
|
|
thumbnailUrl: bgCat,
|
|
|
|
properties: {
|
|
|
|
'--color-bg-primary': '#000',
|
|
|
|
'--bg-image': `url(${bgCat})`,
|
|
|
|
'--bg-position': 'left'
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
] as Theme[]
|
2022-04-21 22:51:48 +00:00
|
|
|
}),
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
init () {
|
2022-07-04 17:47:46 +00:00
|
|
|
for (let key in this.defaultProperties) {
|
|
|
|
this.defaultProperties[key] = document.documentElement.style.getPropertyValue(key)
|
|
|
|
}
|
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
this.applyThemeFromPreference()
|
|
|
|
},
|
|
|
|
|
|
|
|
setTheme (theme: Theme) {
|
|
|
|
document.documentElement.setAttribute('data-theme', theme.id)
|
2022-07-04 17:47:46 +00:00
|
|
|
let properties = Object.assign(clone(this.defaultProperties), theme.properties ?? {})
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-04 17:47:46 +00:00
|
|
|
for (let key in properties) {
|
|
|
|
document.documentElement.style.setProperty(key, properties[key])
|
|
|
|
}
|
|
|
|
|
|
|
|
preferences.theme = theme.id
|
2022-04-21 22:51:48 +00:00
|
|
|
this.state.themes.forEach(t => (t.selected = t.id === theme.id))
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
|
2022-04-21 22:51:48 +00:00
|
|
|
getThemeById (id: string) {
|
2022-04-15 14:24:30 +00:00
|
|
|
return this.state.themes.find(theme => theme.id === id)
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultTheme (): Theme {
|
|
|
|
return this.getThemeById('classic')!
|
|
|
|
},
|
|
|
|
|
|
|
|
applyThemeFromPreference (): void {
|
|
|
|
const theme = preferences.theme
|
|
|
|
? (this.getThemeById(preferences.theme) ?? this.getDefaultTheme())
|
|
|
|
: this.getDefaultTheme()
|
|
|
|
|
|
|
|
this.setTheme(theme)
|
|
|
|
}
|
|
|
|
}
|