2018-12-26 08:45:53 +01:00
|
|
|
var theme = (function() {
|
|
|
|
|
2019-01-03 23:30:27 +01:00
|
|
|
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;
|
2019-01-03 23:30:27 +01:00
|
|
|
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() {
|
2019-01-14 19:50:48 +01:00
|
|
|
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
|
|
|
};
|
2019-01-14 19:50:48 +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),
|
2019-01-15 13:24:57 +01:00
|
|
|
s: 50,
|
2019-01-14 19:50:48 +01:00
|
|
|
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();
|
2019-01-03 23:30:27 +01:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|