@wordpress/components
Version:
UI components for WordPress.
51 lines (50 loc) • 2.09 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// packages/components/src/custom-gradient-picker/serializer.ts
function serializeGradientColor({ type, value }) {
if (type === "literal") return value;
if (type === "hex") return `#${value}`;
if (type === "var") return `var(${value})`;
if (type === "hsl") {
const [hue, saturation, lightness] = value;
return `hsl(${hue},${saturation}%,${lightness}%)`;
}
if (type === "hsla") {
const [hue, saturation, lightness, alpha = "1"] = value;
return `hsla(${hue},${saturation}%,${lightness}%,${alpha})`;
}
return `${type}(${value.join(",")})`;
}
function serializeGradientPosition(position) {
if (!position) return "";
const { value, type } = position;
if (type === "calc") return `calc(${value})`;
return `${value}${type}`;
}
function serializeGradientColorStop({ type, value, length }) {
return `${serializeGradientColor({
type,
value
})} ${serializeGradientPosition(length)}`;
}
function serializeGradientOrientation(orientation) {
if (Array.isArray(orientation) || !orientation || orientation.type !== "angular") return;
return `${orientation.value}${orientation.unit}`;
}
function serializeGradient({ type, colorInterpolation, orientation, colorStops }) {
return `${type}(${[[colorInterpolation, serializeGradientOrientation(orientation)].filter(Boolean).join(" "), ...colorStops.sort((colorStop1, colorStop2) => {
const getNumericStopValue = (colorStop) => {
return colorStop?.length?.value === void 0 ? 0 : parseInt(colorStop.length.value);
};
return getNumericStopValue(colorStop1) - getNumericStopValue(colorStop2);
}).map(serializeGradientColorStop)].filter(Boolean).join(",")})`;
}
exports.serializeGradient = serializeGradient;
exports.serializeGradientColor = serializeGradientColor;
exports.serializeGradientColorStop = serializeGradientColorStop;
exports.serializeGradientOrientation = serializeGradientOrientation;
exports.serializeGradientPosition = serializeGradientPosition;
//# sourceMappingURL=serializer.cjs.map