-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
160 lines (125 loc) · 4.91 KB
/
index.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/npm/colormangle@latest/colormangle.js"></script>
<link rel="stylesheet" href="style.css">
<title>colormangle.js</title>
<div id="test1"></div>
<div id="test2"></div>
<div id="test3" style="color: #018281"></div>
<div id="adjust1">Adjust Brightness</div>
<div id="adjust2">Adjust Luminance</div>
<div id="adjust3">Adjust Saturation</div>
<hr>
<div class="colorBox" id="textColor">Text Color</div>
<br>
<input style='margin: 8px;' id='backgroundSelector' type="color" value='#018281'>
<hr>
<p style='margin: 8px;'>Color Scheme</p>
<div id="schemeDemo">
<div id="head">
<h2>HEAD</h2>
<p>Text text text</p>
</div>
<div id="content">
<div id="menu">
<p>Menu</p>
<p>Non Select</p>
<p>Selected</p>
</div>
<div id="article">
<p>CONTENT</p>
<p id="contentFocus">CONTENT Focus</p>
<p id="textButton">Text Button</p>
<p id="alert">Alert message</p>
</div>
</div>
<div id="somethingelse">
<p>SOMETHINGELSE</p>
<h4 id="button">BUTTON</h4>
</div>
<div id="foot">
FOOT
</div>
</div>
<input style='margin: 8px;' id='colorSelector' type="color" value='#FFD43B'>
<input style='margin: 8px;' id='darkmodeSelector' type="checkbox"> Dark Mode
<div id="colorScheme"></div>
<div id='varList' style="text-align:left;white-space: break-spaces;"></div>
<script>
let color1 = '#3bb0b0';
let cm = new ColorMangle(color1);
let test1 = document.getElementById('test1');
let test2 = document.getElementById('test2');
let test3 = document.getElementById('test3');
test1.innerText = color1; // insert text in a box
test1.style.color = cm.textColor(); // text color
test1.style.backgroundColor = color1; // background color
let amount = 30;
let a1 = cm.adjustBrightness(amount);
let a2 = cm.adjustLuminance(amount);
let a3 = cm.adjustSaturation(amount);
document.getElementById('adjust1').style.backgroundColor = a1;
document.getElementById('adjust2').style.backgroundColor = a2;
document.getElementById('adjust3').style.backgroundColor = a3;
let color2 = cm.rgba();
test2.innerText = color2.string;
test2.style.color = color2.string;
test2.style.backgroundColor = 'rgba(0, 0, 0, 0.1)';
test3.innerText = `Contrast ratio between ${color1} | #004abf is: ${cm.contrastRatio('#004abf')}`;
let darkmode = false;
let colorSelector = document.getElementById('colorSelector');
let colorScheme = new ColorMangle(colorSelector.value);
let currentColorScheme = colorScheme.colorScheme(colorSelector.value, darkmode);
let colorSchemeElements = document.getElementById('colorScheme');
let listColor = (cs) => {
colorSchemeElements.innerHTML = '';
let varList = document.getElementById('varList');
varList.innerHTML = '';
let pre = '';
for (let k in cs) {
varList.innerHTML += `* @property {string} ${k}` + '\n';
let body = document.getElementsByTagName('body')[0];
body.style.setProperty(k, cs[k]);
let curr = k.split('-')[2].split('_')[0];
if (pre && curr !== pre) {
let hr = document.createElement('hr');
colorSchemeElements.append(hr);
}
pre = curr;
let c = cs[k];
let colorBox = document.createElement('div');
colorBox.classList.add('colorBox');
colorBox.style.backgroundColor = c;
let cssVar = document.createElement('p');
cssVar.innerHTML = `${k}\n${c}`;
let textColor = colorScheme.textColor(1, c);
cssVar.style.color = textColor;
colorBox.append(cssVar);
colorSchemeElements.append(colorBox);
}
};
let currColor = document.getElementById('backgroundSelector').value;
listColor(currentColorScheme);
colorSelector.addEventListener('input', (e) => {
currColor = e.target.value;
currentColorScheme = colorScheme.colorScheme(currColor, darkmode);
listColor(currentColorScheme);
});
let darkmodeSelector = document.getElementById('darkmodeSelector');
darkmodeSelector.addEventListener('input', (e) => {
darkmode = e.target.checked;
currentColorScheme = colorScheme.colorScheme(colorSelector.value, darkmode);
listColor(currentColorScheme);
});
let textColor = (e) => {
let color = e?.target?.value || document.getElementById('backgroundSelector').value;
document.getElementById('textColor').style.backgroundColor = color;
document.getElementById('textColor').style.color = colorScheme.textColor(1, color);
};
textColor();
document.getElementById('backgroundSelector').addEventListener('input', (e) => {
textColor();
});
</script>
</html>