Move variants guessing to a separate class
This commit is contained in:
+29
-25
@@ -28,7 +28,7 @@ class Switcher {
|
|||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
this.theme = new Themer();
|
this.theme = new Themer();
|
||||||
this.variants = this._guess_theme_variants_from(this.theme.current);
|
this.variants = Variants.guess_from(this.theme.current);
|
||||||
this.theme.listen(this._on_theme_change.bind(this));
|
this.theme.listen(this._on_theme_change.bind(this));
|
||||||
|
|
||||||
this.nightlight = new Nightlighter();
|
this.nightlight = new Nightlighter();
|
||||||
@@ -65,30 +65,6 @@ class Switcher {
|
|||||||
this._apply_theme_variant();
|
this._apply_theme_variant();
|
||||||
}
|
}
|
||||||
|
|
||||||
_guess_theme_variants_from(name) {
|
|
||||||
const variants = {};
|
|
||||||
variants.original = name;
|
|
||||||
|
|
||||||
if ( name.includes('HighContrast') ) {
|
|
||||||
variants.day = 'HighContrast';
|
|
||||||
variants.night = 'HighContrastInverse';
|
|
||||||
}
|
|
||||||
else if ( name.match(/Materia.*-compact/g) ) {
|
|
||||||
variants.day = name.replace(/-dark(?!er)/g, '');
|
|
||||||
variants.night = variants.day.replace(/(-light)?-compact/g, '-dark-compact');
|
|
||||||
}
|
|
||||||
else if ( name.includes('Arc') ) {
|
|
||||||
variants.day = name.replace(/-Dark(?!er)/g, '');
|
|
||||||
variants.night = variants.day.replace('-Darker', '') + '-Dark';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
variants.day = name.replace(/-dark(?!er)/g, '');
|
|
||||||
variants.night = variants.day.replace(/(-light)?(-darker)?/g, '') + '-dark';
|
|
||||||
}
|
|
||||||
|
|
||||||
return variants;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -171,6 +147,34 @@ class Nightlighter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Variants {
|
||||||
|
|
||||||
|
static guess_from(name) {
|
||||||
|
const variants = {};
|
||||||
|
variants.original = name;
|
||||||
|
|
||||||
|
if ( name.includes('HighContrast') ) {
|
||||||
|
variants.day = 'HighContrast';
|
||||||
|
variants.night = 'HighContrastInverse';
|
||||||
|
}
|
||||||
|
else if ( name.match(/Materia.*-compact/g) ) {
|
||||||
|
variants.day = name.replace(/-dark(?!er)/g, '');
|
||||||
|
variants.night = variants.day.replace(/(-light)?-compact/g, '-dark-compact');
|
||||||
|
}
|
||||||
|
else if ( name.includes('Arc') ) {
|
||||||
|
variants.day = name.replace(/-Dark(?!er)/g, '');
|
||||||
|
variants.night = variants.day.replace('-Darker', '') + '-Dark';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
variants.day = name.replace(/-dark(?!er)/g, '');
|
||||||
|
variants.night = variants.day.replace(/(-light)?(-darker)?/g, '') + '-dark';
|
||||||
|
}
|
||||||
|
|
||||||
|
return variants;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
return new Switcher();
|
return new Switcher();
|
||||||
|
|||||||
Reference in New Issue
Block a user