const batteryLevel = batteryPercent => ({ "-2": "not connected", "-1": "charging" })[batteryPercent] ?? batteryPercent + "%"; const batteryIcon = batteryPercent => ({ "-2": "action-unavailable", "-1": "battery-ac-adapter" })[batteryPercent] ?? "audio-headphones-symbolic"; const interpolateColor = (c0, c1, f) => { // https://stackoverflow.com/a/63775249 if(isNaN(f)) return "transparent"; c0 = c0.replace('#', '').match(/.{1,2}/g).map(oct => parseInt(oct, 16) * (1-f)); c1 = c1.replace('#', '').match(/.{1,2}/g).map(oct => parseInt(oct, 16) * f); return "#" + [0, 1, 2] .map(i => Math.min(Math.round(c0[i] + c1[i]), 255)) .reduce((a, v) => ((a << 8) + v), 0) .toString(16) .padStart(6, "0"); };