UNPKG

@sitecore/sc-contenthub-blok

Version:

A UI library for [Sitecore Content Hub](https://doc.sitecore.com/ch/).

79 lines 2.42 kB
import Color from "color"; import colorString from "color-string"; export const documentStyle = getComputedStyle(document.documentElement); export const normalizeColor = (color) => { return colorString.to.rgb(colorString.get.rgb(color)); }; export const getStyle = (className) => { return documentStyle.getPropertyValue(className).toString().trim(); }; export const normalizeFontNames = (fonts) => { if (fonts === "" || !fonts) { return ""; } return fonts .replace("! default", "") .split(",") .map((fontName) => `'${fontName.trim()}'`) .join(",") .trim(); }; export const transparentize = (color, amount) => { return Color(color).fade(amount).string(); }; export const capitalizeString = (str) => { if (!str) return str; return str.charAt(0).toUpperCase() + str.slice(1); }; export const isFunction = (f) => { return typeof f === "function"; }; export const copyToClipboard = async (text) => { await navigator.clipboard.writeText(text); }; export const EMPTY_IMMUTABLE_ARRAY = Object.freeze([]); /** * Helper function returning an empty immutable array. * This can for example be used as a default value for array props when so desired. * Note: Errors will be thrown at runtime when code tries to modify the returned array. * @returns An empty immutable array */ export const getEmptyImmutableArray = () => EMPTY_IMMUTABLE_ARRAY; export const EMPTY_IMMUTABLE_OBJECT = Object.freeze({}); /** * Helper function returning an empty immutable object. * This can for example be used as a default value for object props when so desired. * Note: Errors will be thrown at runtime when code tries to modify the returned object. * @returns An empty immutable array */ export const getEmptyImmutableObject = () => EMPTY_IMMUTABLE_OBJECT; export const isValidColorName = (color) => { if (!color) { return false; } return [ "red", "pink", "purple", "blue", "cyan", "teal", "green", "yellow", "orange", "gray", "theme-color", "gen-ai", "ai", "danger", "success", "warning", "info", "neutral", "primary", ].includes(color); }; export const isLTR = document?.dir ? document.dir === "ltr" : true; export const isRTL = !isLTR; //# sourceMappingURL=utils.js.map