UNPKG

@sitecore/sc-contenthub-blok

Version:

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

95 lines 3.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isRTL = exports.isLTR = exports.isValidColorName = exports.getEmptyImmutableObject = exports.EMPTY_IMMUTABLE_OBJECT = exports.getEmptyImmutableArray = exports.EMPTY_IMMUTABLE_ARRAY = exports.copyToClipboard = exports.isFunction = exports.capitalizeString = exports.transparentize = exports.normalizeFontNames = exports.getStyle = exports.normalizeColor = exports.documentStyle = void 0; const color_1 = __importDefault(require("color")); const color_string_1 = __importDefault(require("color-string")); exports.documentStyle = getComputedStyle(document.documentElement); const normalizeColor = (color) => { return color_string_1.default.to.rgb(color_string_1.default.get.rgb(color)); }; exports.normalizeColor = normalizeColor; const getStyle = (className) => { return exports.documentStyle.getPropertyValue(className).toString().trim(); }; exports.getStyle = getStyle; const normalizeFontNames = (fonts) => { if (fonts === "" || !fonts) { return ""; } return fonts .replace("! default", "") .split(",") .map((fontName) => `'${fontName.trim()}'`) .join(",") .trim(); }; exports.normalizeFontNames = normalizeFontNames; const transparentize = (color, amount) => { return (0, color_1.default)(color).fade(amount).string(); }; exports.transparentize = transparentize; const capitalizeString = (str) => { if (!str) return str; return str.charAt(0).toUpperCase() + str.slice(1); }; exports.capitalizeString = capitalizeString; const isFunction = (f) => { return typeof f === "function"; }; exports.isFunction = isFunction; const copyToClipboard = async (text) => { await navigator.clipboard.writeText(text); }; exports.copyToClipboard = copyToClipboard; exports.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 */ const getEmptyImmutableArray = () => exports.EMPTY_IMMUTABLE_ARRAY; exports.getEmptyImmutableArray = getEmptyImmutableArray; exports.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 */ const getEmptyImmutableObject = () => exports.EMPTY_IMMUTABLE_OBJECT; exports.getEmptyImmutableObject = getEmptyImmutableObject; 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); }; exports.isValidColorName = isValidColorName; exports.isLTR = document?.dir ? document.dir === "ltr" : true; exports.isRTL = !exports.isLTR; //# sourceMappingURL=utils.js.map