Utility function to detect background colour and select either light or dark default hometown logo

This commit is contained in:
Emma Winston
2019-09-17 16:57:08 +01:00
parent 87ad6ac03a
commit 2ebe82c49b
3 changed files with 38 additions and 2 deletions

View File

@ -0,0 +1,21 @@
export function svgSelect(light, dark) {
var svgbg = window.getComputedStyle(document.getElementsByClassName("drawer__inner")[0], null).getPropertyValue("background-color");
var rgbArray = ((svgbg.replace(/[^0-9,]/g, "")).split(",")).map(Number).map(x => x/255);
for ( var i = 0; i < rgbArray.length; ++i ) {
if ( rgbArray[i] <= 0.03928 ) {
rgbArray[i] = rgbArray[i] / 12.92
} else {
rgbArray[i] = Math.pow( ( rgbArray[i] + 0.055 ) / 1.055, 2.4);
}
}
var luminance = 0.2126 * rgbArray[0] + 0.7152 * rgbArray[1] + 0.0722 * rgbArray[2];
if ( luminance <= 0.179 ) {
return light;
} else {
return dark;
}
}