// @flow import parseToHsl from './parseToHsl' import toColorString from './toColorString' /** * Returns the complement of the provided color. This is identical to adjustHue(180, ). * * @example * // Styles as object usage * const styles = { * background: complement('#448'), * background: complement('rgba(204,205,100,0.7)'), * } * * // styled-components usage * const div = styled.div` * background: ${complement('#448')}; * background: ${complement('rgba(204,205,100,0.7)')}; * ` * * // CSS in JS Output * element { * background: "#884"; * background: "rgba(153,153,153,0.7)"; * } */ export default function complement(color: string): string { if (color === 'transparent') return color const hslColor = parseToHsl(color) return toColorString({ ...hslColor, hue: (hslColor.hue + 180) % 360, }) }