2016-09-18 22:47:33 -08:00
|
|
|
const Color = require('color');
|
|
|
|
|
|
|
|
|
|
// returns a background color that's in hex
|
|
|
|
|
// format including the alpha channel (e.g.: `#00000050`)
|
|
|
|
|
// input can be any css value (rgb, hsl, string…)
|
2016-09-21 06:27:11 -08:00
|
|
|
module.exports = function toElectronBackgroundColor(bgColor) {
|
2016-09-18 22:47:33 -08:00
|
|
|
const color = Color(bgColor);
|
2016-09-21 06:27:11 -08:00
|
|
|
if (color.alpha() === 1) {
|
2016-09-18 22:47:33 -08:00
|
|
|
return color.hexString();
|
|
|
|
|
}
|
2016-09-21 06:27:11 -08:00
|
|
|
// (╯°□°)╯︵ ┻━┻
|
|
|
|
|
return '#' + Math.floor(color.alpha() * 100) + color.hexString().substr(1);
|
2016-09-18 22:47:33 -08:00
|
|
|
};
|