nightTab/js/theme.js

77 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-12-26 08:45:53 +01:00
var theme = (function() {
var render = function() {
2018-12-26 08:45:53 +01:00
var html = helper.e("html");
2019-01-07 15:42:14 +01:00
var color = state.get().layout.theme.current;
html.style.setProperty("--accent", color.r + ", " + color.g + ", " + color.b);
2018-12-26 08:45:53 +01:00
};
2019-01-07 15:42:14 +01:00
var random = function() {
if (state.get().layout.theme.random.active) {
var randomVal = function(min, max) {
return Math.floor(Math.random() * (max - min) + 1) + min;
2019-01-07 15:42:14 +01:00
};
var color = {
any: function() {
return {
h: randomVal(0, 360),
s: randomVal(0, 100),
l: randomVal(0, 100)
};
},
light: function() {
return {
h: randomVal(0, 360),
s: randomVal(50, 90),
l: randomVal(50, 90)
};
},
dark: function() {
return {
h: randomVal(0, 360),
s: randomVal(10, 50),
l: randomVal(10, 50)
};
},
pastel: function() {
return {
h: randomVal(0, 360),
s: 100,
l: 80
};
},
saturated: function() {
return {
h: randomVal(0, 360),
s: 100,
l: 50
};
}
};
var hsl = color[state.get().layout.theme.random.style]();
var randomColor = helper.hslToRgb({
h: hsl.h,
s: (hsl.s / 100),
l: (hsl.l / 100)
});
2019-01-07 15:42:14 +01:00
state.change({
path: "layout.theme.current",
value: randomColor
});
};
};
2018-12-26 08:45:53 +01:00
var init = function() {
2019-01-07 15:42:14 +01:00
random();
render();
2018-12-26 08:45:53 +01:00
};
// exposed methods
return {
init: init,
2019-01-07 15:42:14 +01:00
random: random,
2018-12-26 08:45:53 +01:00
render: render
};
})();