wix-style-react
Version:
50 lines (44 loc) • 959 B
JavaScript
import React from 'react';
import { isUrl } from '../utils/UrlUtils';
import gradient from 'gradient-parser';
import resolveColor from 'color';
export var parseColor = function parseColor(fill) {
if (typeof fill !== 'string') {
return;
}
try {
return resolveColor(fill);
} catch (_unused) {
return;
}
};
export var parseGradient = function parseGradient(fill) {
if (typeof fill !== 'string') {
return;
}
try {
return gradient.parse(fill);
} catch (_unused2) {
return;
}
};
export var parseUrl = function parseUrl(fill) {
if (typeof fill !== 'string') {
return;
}
if (isUrl(fill)) {
return fill;
}
if (/.jpg|.png|.svg/.test(fill)) {
return "".concat(location.hostname, "/").concat(fill);
}
return;
};
export var parseElement = function parseElement(fill) {
if (typeof fill !== 'string') {
if ( /*#__PURE__*/React.isValidElement(fill)) {
return fill;
}
}
return;
};