UNPKG

wix-style-react

Version:
35 lines (33 loc) 840 B
import Color from 'color'; import mapValue from '../utils/operators/mapValue'; export function safeColor(input) { var allowEmpty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; try { if (allowEmpty) { return input ? Color(input) : Color().alpha(0); } return Color(input); } catch (error) { return null; } } export function getHexOrEmpty(_color) { return isTransparent(_color) ? '' : _color.hex(); } export function getRgbOrEmpty(_color) { return isTransparent(_color) ? { r: '', g: '', b: '' } : mapValue(_color.rgb().object(), Math.round); } export function getHsbOrEmpty(_color) { return isTransparent(_color) ? { h: '', s: '', l: '' } : _color.hsl().round().object(); } export function isTransparent(_color) { return _color.alpha() === 0; }