-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.js
130 lines (129 loc) · 6.29 KB
/
interface.js
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
130
const settings = {
themeSettings : {
mainColor : 'slate',
accentColor : 'amber',
warningColor : 'red',
textColor: 'amber',
brightness : 3, //1-5
contrast : 2, //1-3
lowClrVal : 200,
midClrVal : 500,
highClrVal : 700,
color_choices : ['zinc','yellow','violet','teal','stone','slate','sky','rose','red','purple','pink','prange','neutral','lime','indigo','green','gray','fuchsia','emerald','cyan','blue','amber'],
rounded : 'md',
cellOverflow : 'x-scroll',
precision : 2,
},
colors : {
textColorLight : 'text-amber-200',
textColorDark : 'text-amber-800',
mainColorLow : `bg-slate-200`,
mainColorMid : `bg-slate-500`,
mainColorHigh : `bg-slate-700`,
accentColorLow : `bg-amber-200`,
accentColorMid : `bg-amber-500`,
accentColorHigh : `bg-amber-700`,
warningColorLow : `bg-red-200`,
warningColorMid : `bg-red-500`,
warningColorHigh : `bg-red-700`,
},
getColors : {
textColorLight : function(){return `text-${this.themeSettings.accentColor}-200`},
textColorDark : function(){return `text-${this.themeSettings.accentColor}-800`},
mainColorLow : function(){return `bg-${this.themeSettings.mainColor}-${this.themeSettings.lowClrVal}`},
mainColorMid : function(){return `bg-${this.themeSettings.mainColor}-${this.themeSettings.midClrVal}`},
mainColorHigh : function(){return `bg-${this.themeSettings.mainColor}-${this.themeSettings.highClrVal}`},
accentColorLow : function(){return `bg-${this.themeSettings.accentColor}-${this.themeSettings.lowClrVal}`},
accentColorMid : function(){return `bg-${this.themeSettings.accentColor}-${this.themeSettings.midClrVal}`},
accentColorHigh : function(){return `bg-${this.themeSettings.accentColor}-${this.themeSettings.highClrVal}`},
warningColorLow : function(){return `bg-${this.themeSettings.warningColor}-${this.themeSettings.lowClrVal}`},
warningColorMid : function(){return `bg-${this.themeSettings.warningColor}-${this.themeSettings.midClrVal}`},
warningColorHigh : function(){return `bg-${this.themeSettings.warningColor}-${this.themeSettings.highClrVal}`},
},
setBrightness : function(brightness) {
console.log(this.themeSettings)
this.themeSettings.brightness = brightness;
this.storeSettings();
this.refreshValues();
},
setContrast : function(contrast) {
this.themeSettings.contrast = contrast;
this.storeSettings();
this.refreshValues();
},
setTextColor : function(textColor) {
this.themeSettings.textColor = textColor;
this.storeSettings();
const oldClrs = [this.colors.textColorDark,this.colors.textColorLight];
oldClrs.forEach(clr => this.refreshNodes(clr));
// this.refreshTextClrs();
},
setMainColor : function(mainColor) {
this.themeSettings.mainColor = mainColor;
this.storeSettings();
const oldClrs = [this.colors.mainColorHigh,this.colors.mainColorMid,this.colors.mainColorLow];
oldClrs.forEach(clr => this.refreshNodes(clr));
// this.refreshMainClrs();
},
setAccentColor : function(accentColor) {
this.themeSettings.accentColor = accentColor;
this.storeSettings();
const oldClrs = [this.colors.accentColorHigh,this.colors.accentColorMid,this.colors.accentColorLow];
oldClrs.forEach(clr => this.refreshNodes(clr));
// this.refreshAccentClrs();
},
setWarningColor : function(warningColor) {
this.themeSettings.warningColor = warningColor;
this.storeSettings();
const oldClrs = [this.colors.warningColorHigh,this.colors.warningColorMid,this.colors.warningColorLow]
oldClrs.forEach(clr => this.refreshNodes(clr));
// this.refreshWarningClrs();
},
storeSettings : function() {
localStorage.setItem('settings',JSON.stringify(this.themeSettings));
},
loadSettings : function() {
storedSettings = localStorage.getItem('setttings');
this.themeSettings = Object.keys(storeSettings).length ? JSON : [];
},
refreshValues : function() {
midMap = {1:300,2:400,3:500,4:600,5:700};
this.midClrVal = midMap[this.brightness];
this.lowClrVal = Math.max(((3-this.contrast)*100),50);
this.highClrVal = Math.min(((this.contrast)*100)+this.midClrVal,950);
// this.refreshAllClrs();
},
refreshTextClrs: function() {
this.colors.textColorDark = `bg-${this.themeSettings.textColor}-800`;
this.colors.textColorLight = `bg-${this.themeSettings.textColor}-200`;
// return [this.colors.textColorDark,this.colors.textColorLight];
},
refreshMainClrs : function() {
this.colors.mainColorLow = `bg-${this.themeSettings.mainColor}-${this.themeSettings.lowClrVal}`;
this.colors.mainColorMid = `bg-${this.themeSettings.mainColor}-${this.themeSettings.midClrVal}`;
this.colors.mainColorHigh = `bg-${this.themeSettings.mainColor}-${this.themeSettings.highClrVal}`;
},
refreshAccentClrs : function() {
this.colors.accentColorLow = `bg-${this.themeSettings.accentColor}-${this.themeSettings.lowClrVal}`;
this.colors.accentColorMid = `bg-${this.themeSettings.accentColor}-${this.themeSettings.midClrVal}`;
this.colors.accentColorHigh = `bg-${this.themeSettings.accentColor}-${this.themeSettings.highClrVal}`;
},
refreshWarningClrs : function() {
this.colors.warningColorLow = `bg-${this.themeSettings.warningColor}-${this.themeSettings.lowClrVal}`;
this.colors.warningColorMid = `bg-${this.themeSettings.warningColor}-${this.themeSettings.midClrVal}`;
this.colors.warningColorHigh = `bg-${this.themeSettings.warningColor}-${this.themeSettings.highClrVal}`;
},
refreshAllClrs : function() {
this.refreshMainClrs();
this.refreshAccentClrs();
this.refreshWarningClrs();
},
refreshNodes : function(classvalue) {
const nodes = document.querySelectorAll(`.${classvalue}`)
nodes.forEach(node => {
clrInd = Array.from(node.classlist).indexOf(color);
node.classlist[clrInd] = this.getColors[oldClr]();
});
this.colors[oldClr] = this.getColors[oldClr]()
},
}