|
|
@ -161,6 +161,9 @@ export class RootScope extends EventListenerBase<{ |
|
|
|
caption_length_max: 1024, |
|
|
|
caption_length_max: 1024, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public themeColor: string; |
|
|
|
|
|
|
|
private _themeColorElem: Element; |
|
|
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
|
|
|
|
|
|
|
@ -188,6 +191,25 @@ export class RootScope extends EventListenerBase<{ |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get themeColorElem() { |
|
|
|
|
|
|
|
if(this._themeColorElem !== undefined) { |
|
|
|
|
|
|
|
return this._themeColorElem; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this._themeColorElem = document.head.querySelector('[name="theme-color"]') as Element || null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public setThemeColor(color = this.themeColor) { |
|
|
|
|
|
|
|
if(!color) { |
|
|
|
|
|
|
|
color = this.isNight() ? '#212121' : '#ffffff'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const themeColorElem = this.themeColorElem; |
|
|
|
|
|
|
|
if(themeColorElem) { |
|
|
|
|
|
|
|
themeColorElem.setAttribute('content', color); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public setThemeListener() { |
|
|
|
public setThemeListener() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); |
|
|
|
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); |
|
|
@ -216,13 +238,14 @@ export class RootScope extends EventListenerBase<{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public setTheme() { |
|
|
|
public setTheme() { |
|
|
|
const isNight = this.getTheme().name === 'night'; |
|
|
|
const isNight = this.isNight(); |
|
|
|
const colorScheme = document.head.querySelector('[name="color-scheme"]'); |
|
|
|
const colorScheme = document.head.querySelector('[name="color-scheme"]'); |
|
|
|
if(colorScheme) { |
|
|
|
if(colorScheme) { |
|
|
|
colorScheme.setAttribute('content', isNight ? 'dark' : 'light'); |
|
|
|
colorScheme.setAttribute('content', isNight ? 'dark' : 'light'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
document.documentElement.classList.toggle('night', isNight); |
|
|
|
document.documentElement.classList.toggle('night', isNight); |
|
|
|
|
|
|
|
this.setThemeColor(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get isOverlayActive() { |
|
|
|
get isOverlayActive() { |
|
|
@ -234,6 +257,10 @@ export class RootScope extends EventListenerBase<{ |
|
|
|
this.dispatchEvent('overlay_toggle', this.isOverlayActive); |
|
|
|
this.dispatchEvent('overlay_toggle', this.isOverlayActive); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public isNight() { |
|
|
|
|
|
|
|
return this.getTheme().name === 'night'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public getTheme(name: Theme['name'] = this.settings.theme === 'system' ? this.systemTheme : this.settings.theme) { |
|
|
|
public getTheme(name: Theme['name'] = this.settings.theme === 'system' ? this.systemTheme : this.settings.theme) { |
|
|
|
return this.settings.themes.find(t => t.name === name); |
|
|
|
return this.settings.themes.find(t => t.name === name); |
|
|
|
} |
|
|
|
} |
|
|
|