-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (53 loc) · 1.74 KB
/
index.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
const prefixElement = document.querySelector('#prefix');
const colorElement = document.querySelector('#color');
const stepElement = document.querySelector('#step');
const resultElement = document.querySelector('#result');
const build = () => {
const prefix = prefixElement.value;
const colorString = colorElement.value;
const step = parseFloat(stepElement.value);
if (!colorString || !step) {
return;
}
const palette = [
{
degree: 0,
color: tinycolor(colorString),
},
];
for (let degree = step; degree < 50; degree += step) {
palette.unshift({
degree: -degree,
color: tinycolor(colorString).darken(degree),
});
palette.push({
degree,
color: tinycolor(colorString).lighten(degree),
});
}
const bullshitStep = step * 10;
resultElement.innerHTML = '';
for (let format of ['hex', 'rgb']) {
let degree = bullshitStep;
const formatContainer = document.createElement('div');
formatContainer.innerHTML = `<div class="text-muted ${
format !== 'hex' ? 'mt-5' : ''
}">/* ${format} */</div>`;
for (let element of palette) {
const variant = document.createElement('div');
variant.classList.add('variant');
variant.innerHTML = `<span class="color">${prefix}${degree}: ${element.color.toString(
format
)};</span>`;
variant.style.setProperty('--color', element.color.toString());
formatContainer.appendChild(variant);
degree += bullshitStep;
}
resultElement.appendChild(formatContainer);
}
};
build();
prefixElement.addEventListener('keyup', build);
colorElement.addEventListener('keyup', build);
stepElement.addEventListener('keyup', build);
document.querySelector('#year').innerHTML = new Date().getFullYear();