build/lib/light.js
function createRGBProxy(raw = false) {
    function get(me, key) {
        switch (key) {
            case "color": {
                if (typeof me.color === "string" && rgbRegex.test(me.color)) {
                    // predefined color, return it
                    return me.color;
                }
                else {
                    // calculate it from hue/saturation
                    const { r, g, b } = conversions_1.conversions.rgbFromHSV(me.hue, me.saturation / 100, 1);
                    return conversions_1.conversions.rgbToString(r, g, b);
                }
            }
            default: return me[key];
        }
    }
    function set(me, key, value) {
        switch (key) {
            case "color": {
                if (predefined_colors_1.predefinedColors.has(value)) {
                    // its a predefined color, use the predefined values
                    const definition = predefined_colors_1.predefinedColors.get(value); // we checked with `has`
                    if (raw) {
                        me.hue = definition.hue_raw;
                        me.saturation = definition.saturation_raw;
                    }
                    else {
                        me.hue = definition.hue;
                        me.saturation = definition.saturation;
                    }
                }
                else {
                    // only accept HEX colors
                    if (rgbRegex.test(value)) {
                        // calculate the X/Y values
                        const { r, g, b } = conversions_1.conversions.rgbFromString(value);
                        const { h, s /* ignore v */ } = conversions_1.conversions.rgbToHSV(r, g, b);
                        if (raw) {
                            me.hue = Math.round(h / 360 * predefined_colors_1.MAX_COLOR);
                            me.saturation = Math.round(s * predefined_colors_1.MAX_COLOR);
                        }
                        else {
                            me.hue = h;
                            me.saturation = s * 100;
                        }
                    }
                }
                break;
            }
            default: me[key] = value;
        }
        return true;
    }
    return { get, set };
}
function createRGBProxy(raw = false) {
    function get(me, key) {
        switch (key) {
            case "color": {
                if (typeof me.color === "string" && rgbRegex.test(me.color)) {
                    // predefined color, return it
                    return me.color;
                }
                else {
                    // calculate it from hue/saturation
                    const { r, g, b } = conversions_1.conversions.rgbFromHSV(me.hue, me.saturation / 100, 1);
                    return conversions_1.conversions.rgbToString(r, g, b);
                }
            }
            default: return me[key];
        }
    }
    function set(me, key, value) {
        switch (key) {
            case "color": {
                if (predefined_colors_1.predefinedColors.has(value)) {
                    // its a predefined color, use the predefined values
                    const definition = predefined_colors_1.predefinedColors.get(value); // we checked with `has`
                    if (raw) {
                        me.hue = definition.hue_raw;
                        me.saturation = definition.saturation_raw;
                    }
                    else {
                        me.hue = definition.hue;
                        me.saturation = definition.saturation;
                    }
                }
                else {
                    // only accept HEX colors
                    if (rgbRegex.test(value)) {
                        // calculate the X/Y values
                        const { r, g, b } = conversions_1.conversions.rgbFromString(value);
                        const { h, s /* ignore v */ } = conversions_1.conversions.rgbToHSV(r, g, b);
                        if (raw) {
                            me.hue = Math.round(h / 360 * predefined_colors_1.MAX_COLOR);
                            me.saturation = Math.round(s * predefined_colors_1.MAX_COLOR);
                        }
                        else {
                            me.hue = h;
                            me.saturation = s * 100;
                        }
                    }
                }
                break;
            }
            default: me[key] = value;
        }
        return true;
    }
    return { get, set };
}
function createRGBProxy ( raw = false ) { function get ( me , key ) { switch ( key ) { case "color" : { if ( typeof me . color === "string" && rgbRegex . test ( me . color ) ) { // predefined color, return it return me . color ; } else { // calculate it from hue/saturation const { r , g , b } = conversions_1 . conversions . rgbFromHSV ( me . hue , me . saturation / 100 , 1 ) ; return conversions_1 . conversions . rgbToString ( r , g , b ) ; } } default : return me [ key ] ; } } function set ( me , key , value ) { switch ( key ) { case "color" : { if ( predefined_colors_1 . predefinedColors . has ( value ) ) { // its a predefined color, use the predefined values const definition = predefined_colors_1 . predefinedColors . get ( value ) ; // we checked with `has` if ( raw ) { me . hue = definition . hue_raw ; me . saturation = definition . saturation_raw ; } else { me . hue = definition . hue ; me . saturation = definition . saturation ; } } else { // only accept HEX colors if ( rgbRegex . test ( value ) ) { // calculate the X/Y values const { r , g , b } = conversions_1 . conversions . rgbFromString ( value ) ; const { h , s /* ignore v */ } = conversions_1 . conversions . rgbToHSV ( r , g , b ) ; if ( raw ) { me . hue = Math . round ( h / 360 * predefined_colors_1 . MAX_COLOR ) ; me . saturation = Math . round ( s * predefined_colors_1 . MAX_COLOR ) ; } else { me . hue = h ; me . saturation = s * 100 ; } } } break ; } default : me [ key ] = value ; } return true ; } return { get , set } ; }
Creates a proxy for an RGB lamp,
which converts RGB color to CIE xy
Creates a proxy for an RGB lamp which converts RGB color to CIE xy