File size: 829 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
/* IMPORT */
import _ from '~/utils';
import ChannelsReusable from '~/channels/reusable';
import Color from '~/color';
import change from '~/methods/change';
import type {Channels} from '~/types';
/* TYPES */
type IRgba = {
( color: string | Channels, opacity: number ): string,
( r: number, g: number, b: number, a?: number ): string
};
/* MAIN */
const rgba: IRgba = ( r: string | Channels | number, g: number, b: number = 0, a: number = 1 ): string => { //TSC: `b` shouldn't have a default value
if ( typeof r !== 'number' ) return change ( r, { a: g } );
const channels = ChannelsReusable.set ({
r: _.channel.clamp.r ( r ),
g: _.channel.clamp.g ( g ),
b: _.channel.clamp.b ( b ),
a: _.channel.clamp.a ( a )
});
return Color.stringify ( channels );
};
/* EXPORT */
export default rgba;
|