function colorPreferenceToComponents()

in lib/prepare.js [632:673]


function colorPreferenceToComponents (pref) {
    if (!pref || !pref.match(/^(#[0-9A-Fa-f]{3}|(0x|#)([0-9A-Fa-f]{2})?[0-9A-Fa-f]{6})$/)) {
        return {
            platform: 'ios',
            reference: 'systemBackgroundColor'
        };
    }

    let red = 'FF';
    let green = 'FF';
    let blue = 'FF';
    let alpha = 1.0;

    if (pref[0] === '#' && pref.length === 4) {
        red = pref[1] + pref[1];
        green = pref[2] + pref[2];
        blue = pref[3] + pref[3];
    }

    if (pref.length >= 7 && (pref[0] === '#' || pref.substring(0, 2) === '0x')) {
        let offset = pref[0] === '#' ? 1 : 2;

        if (pref.substring(offset).length === 8) {
            alpha = parseInt(pref.substring(offset, offset + 2), 16) / 255.0;
            offset += 2;
        }

        red = pref.substring(offset, offset + 2);
        green = pref.substring(offset + 2, offset + 4);
        blue = pref.substring(offset + 4, offset + 6);
    }

    return {
        'color-space': 'srgb',
        components: {
            red: '0x' + red.toUpperCase(),
            green: '0x' + green.toUpperCase(),
            blue: '0x' + blue.toUpperCase(),
            alpha: alpha.toFixed(3)
        }
    };
}