function hasDarkBackground(map, actual) {
    const light = map.getLights().filter(({type}) => type === 'ambient')[0],
        lightColorElements = parseCSSColor(light.properties.color),
        lightIntensity = light.properties.intensity,
        lr = lightColorElements[0] / 255 * lightIntensity,
        lg = lightColorElements[1] / 255 * lightIntensity,
        lb = lightColorElements[2] / 255 * lightIntensity;

    if (actual) {
        return BG_LAYER_IDS.reduce((value, id) => {
            const paintProperties = map.style.getOwnLayer(id).paint,
                {r, g, b} = paintProperties.get('background-color'),
                a = paintProperties.get('background-opacity');
            return value + luminance({r: r * lr * a, g: g * lg * a, b: b * lb * a});
        }, 0) < .5;
    }

    return BG_LAYER_IDS.reduce((value, id) => {
        const [r, g, b] = parseCSSColor(map.getPaintProperty(id, 'background-color')),
            a = valueOrDefault(map.getPaintProperty(id, 'background-opacity'), 1);
        return value + luminance({r: r * lr * a, g: g * lg * a, b: b * lb * a});
    }, 0) < 127.5;
}
Checks if the background color of the map is dark.
@param {mapboxgl.Map} map - Mapbox's Map object
@param {boolean} actual - If true, the result is based on the current background color.
    Otherwise, the result is based on the target background color
@returns {boolean} True if the background color of the map is dark