UNPKG

@gechiui/components

Version:
62 lines (57 loc) 1.38 kB
/** * External dependencies */ import { compact, get } from 'lodash'; export function serializeGradientColor(_ref) { let { type, value } = _ref; if (type === 'literal') { return value; } if (type === 'hex') { return `#${value}`; } return `${type}(${value.join(',')})`; } export function serializeGradientPosition(position) { if (!position) { return ''; } const { value, type } = position; return `${value}${type}`; } export function serializeGradientColorStop(_ref2) { let { type, value, length } = _ref2; return `${serializeGradientColor({ type, value })} ${serializeGradientPosition(length)}`; } export function serializeGradientOrientation(orientation) { if (!orientation || orientation.type !== 'angular') { return; } return `${orientation.value}deg`; } export function serializeGradient(_ref3) { let { type, orientation, colorStops } = _ref3; const serializedOrientation = serializeGradientOrientation(orientation); const serializedColorStops = colorStops.sort((colorStop1, colorStop2) => { return get(colorStop1, ['length', 'value'], 0) - get(colorStop2, ['length', 'value'], 0); }).map(serializeGradientColorStop); return `${type}(${compact([serializedOrientation, ...serializedColorStops]).join(',')})`; } //# sourceMappingURL=serializer.js.map