UNPKG

@wordpress/components

Version:
82 lines (69 loc) 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.serializeGradient = serializeGradient; exports.serializeGradientColor = serializeGradientColor; exports.serializeGradientColorStop = serializeGradientColorStop; exports.serializeGradientOrientation = serializeGradientOrientation; exports.serializeGradientPosition = serializeGradientPosition; /** * External dependencies */ function serializeGradientColor(_ref) { let { type, value } = _ref; if (type === 'literal') { return value; } if (type === 'hex') { return `#${value}`; } return `${type}(${value.join(',')})`; } function serializeGradientPosition(position) { if (!position) { return ''; } const { value, type } = position; return `${value}${type}`; } function serializeGradientColorStop(_ref2) { let { type, value, length } = _ref2; return `${serializeGradientColor({ type, value })} ${serializeGradientPosition(length)}`; } function serializeGradientOrientation(orientation) { if (Array.isArray(orientation) || !orientation || orientation.type !== 'angular') { return; } return `${orientation.value}deg`; } function serializeGradient(_ref3) { let { type, orientation, colorStops } = _ref3; const serializedOrientation = serializeGradientOrientation(orientation); const serializedColorStops = colorStops.sort((colorStop1, colorStop2) => { const getNumericStopValue = colorStop => { var _colorStop$length; return (colorStop === null || colorStop === void 0 ? void 0 : (_colorStop$length = colorStop.length) === null || _colorStop$length === void 0 ? void 0 : _colorStop$length.value) === undefined ? 0 : parseInt(colorStop.length.value); }; return getNumericStopValue(colorStop1) - getNumericStopValue(colorStop2); }).map(serializeGradientColorStop); return `${type}(${[serializedOrientation, ...serializedColorStops].filter(Boolean).join(',')})`; } //# sourceMappingURL=serializer.js.map