Skip to content

Commit

Permalink
refactor(color): update css()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 29, 2021
1 parent afc300c commit 655dd32
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/color/src/css/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ const CSS_CONVERSIONS: Partial<Record<ColorMode, Fn<any, string>>> = {
* @param col - source color
*/
export const css = (src: Exclude<MaybeColor, IParsedColor>) => {
if (isString(src)) return src;
if (isNumber(src)) return int32Css(src);
if ((<TypedColor<any>>src).mode) {
const asCss = CSS_CONVERSIONS[(<TypedColor<any>>src).mode];
if (asCss) return asCss(src);
return CSS_CONVERSIONS.rgb!(
convert([], src, "rgb", (<TypedColor<any>>src).mode)
);
}
return srgbCss(src);
let asCss: Fn<any, string> | undefined;
return isString(src)
? src
: isNumber(src)
? int32Css(src)
: (<TypedColor<any>>src).mode
? (asCss = CSS_CONVERSIONS[(<TypedColor<any>>src).mode])
? asCss(src)
: CSS_CONVERSIONS.rgb!(
convert([], src, "rgb", (<TypedColor<any>>src).mode)
)
: srgbCss(src);
};

0 comments on commit 655dd32

Please sign in to comment.