@wordpress/components
Version:
UI components for WordPress.
26 lines (25 loc) • 1.11 kB
JavaScript
// packages/components/src/font-size-picker/utils.ts
/**
* Some themes use css vars for their font sizes, so until we
* have the way of calculating them don't display them.
*
* @param value The value that is checked.
* @return Whether the value is a simple css value.
*/
function isSimpleCssValue(value) {
return /^[\d\.]+(px|em|rem|vw|vh|%|svw|lvw|dvw|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax|cqw|cqh|cqi|cqb|cqmin|cqmax)?$/i.test(String(value));
}
/**
* Generates hint text for a font size.
* This function returns the hint provided by the consumer, if any.
* If no hint is provided, it falls back to showing the size value for simple CSS values.
*
* @param fontSize The font size object to generate hint text for.
* @return The hint text provided by the consumer, or the size value for simple CSS values, or undefined.
*/
function generateFontSizeHint(fontSize) {
if (fontSize.hint) return fontSize.hint;
if (isSimpleCssValue(fontSize.size)) return String(fontSize.size);
}
export { generateFontSizeHint, isSimpleCssValue };
//# sourceMappingURL=utils.mjs.map