forked from zombieFox/nightTab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.js
More file actions
129 lines (120 loc) · 2.96 KB
/
Copy paththeme.js
File metadata and controls
129 lines (120 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var theme = (function() {
var toggle = function() {
var style = {
dark: function() {
helper.setObject({
object: state.get(),
path: "theme.style",
newValue: "light"
})
},
light: function() {
helper.setObject({
object: state.get(),
path: "theme.style",
newValue: "dark"
})
}
};
style[state.get().theme.style]();
};
var render = {
theme: function() {
_renderTheme();
},
radius: function() {
_renderRadius();
},
accent: {
color: function() {
_renderAccentColor();
},
random: function() {
_renderAccentRandom();
}
}
};
var _renderTheme = function() {
var html = helper.e("html");
helper.removeClass(html, "is-theme-style-dark");
helper.removeClass(html, "is-theme-style-light");
helper.addClass(html, "is-theme-style-" + state.get().theme.style);
};
var _renderRadius = function() {
var html = helper.e("html");
html.style.setProperty("--theme-radius", state.get().theme.radius + "rem");
};
var _renderAccentColor = function() {
var html = helper.e("html");
var color = state.get().theme.accent.current;
html.style.setProperty("--theme-accent", color.r + ", " + color.g + ", " + color.b);
};
var _renderAccentRandom = function() {
if (state.get().theme.accent.random.active) {
var randomVal = function(min, max) {
return Math.floor(Math.random() * (max - min) + 1) + min;
};
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: 50,
l: 80
};
},
saturated: function() {
return {
h: randomVal(0, 360),
s: 100,
l: 50
};
}
};
var hsl = color[state.get().theme.accent.random.style]();
var randomColor = helper.hslToRgb({
h: hsl.h,
s: (hsl.s / 100),
l: (hsl.l / 100)
});
helper.setObject({
object: state.get(),
path: "theme.accent.current",
newValue: randomColor
});
helper.e(".control-theme-accent-current").value = helper.rgbToHex(randomColor);
};
};
var init = function() {
render.theme();
render.accent.random();
render.accent.color();
render.radius();
};
// exposed methods
return {
render: render,
toggle: toggle,
init: init
};
})();