function rgbToHex(r, g, b) {
return ((r << 16) | (g << 8) | b).toString(16);
}
function hexToRgba(hex, opacity = 1) {
return {
r: parseInt("0x" + hex.slice(1, 3)),
g: parseInt("0x" + hex.slice(3, 5)),
b: parseInt("0x" + hex.slice(5, 7))
}
}
function getColorLevel(color) {
const {
r,
g,
b
} = hexToRgba(color)
return r * 0.299 + g * 0.587 + b * 0.114
}