UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

37 lines (36 loc) 1.24 kB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; /** * Converts a camelCased CSS property name to a hyphenated CSS property name. * * @param property - CamelCased CSS property name. * @returns Hyphenated CSS property name. */ function hyphenate(property) { // Ignored via go/ees005 // eslint-disable-next-line require-unicode-regexp // Ignored via go/ees005 // eslint-disable-next-line require-unicode-regexp return property.replace(/[A-Z]/g, function (match) { return "-".concat(match.toLowerCase()); }).replace(/^ms/, '-ms'); } /** * Converts a CSS properties object to a CSS string. * @param properties - CSS properties object. * @returns CSS string. */ export function convertToInlineCss(properties) { var cssString = Object.entries(properties).sort(function (_ref, _ref2) { var _ref3 = _slicedToArray(_ref, 1), a = _ref3[0]; var _ref4 = _slicedToArray(_ref2, 1), b = _ref4[0]; return a.localeCompare(b); }).map(function (_ref5) { var _ref6 = _slicedToArray(_ref5, 2), property = _ref6[0], value = _ref6[1]; return "".concat(property.startsWith('--') ? property : hyphenate(property), ": ").concat(value, ";"); }).join(' '); return cssString; }