@wordpress/components
Version:
UI components for WordPress.
1 lines • 1.72 kB
Source Map (JSON)
{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/font-size-picker/utils.ts"],"sourcesContent":["import type { FontSizePickerProps, FontSize } from './types';\n\n/**\n * Some themes use css vars for their font sizes, so until we\n * have the way of calculating them don't display them.\n *\n * @param value The value that is checked.\n * @return Whether the value is a simple css value.\n */\nexport function isSimpleCssValue(\n\tvalue: NonNullable< FontSizePickerProps[ 'value' ] >\n) {\n\tconst sizeRegex =\n\t\t/^[\\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;\n\treturn sizeRegex.test( String( value ) );\n}\n\n/**\n * Generates hint text for a font size.\n * This function returns the hint provided by the consumer, if any.\n * If no hint is provided, it falls back to showing the size value for simple CSS values.\n *\n * @param fontSize The font size object to generate hint text for.\n * @return The hint text provided by the consumer, or the size value for simple CSS values, or undefined.\n */\nexport function generateFontSizeHint( fontSize: FontSize ): string | undefined {\n\t// If the font size already has a hint, use it\n\tif ( fontSize.hint ) {\n\t\treturn fontSize.hint;\n\t}\n\n\t// Fallback to showing the size value if it's a simple CSS value\n\tif ( isSimpleCssValue( fontSize.size ) ) {\n\t\treturn String( fontSize.size );\n\t}\n\n\treturn undefined;\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,iBACf,OACC;CAGD,OAAO,iKAAU,KAAM,OAAQ,KAAM,CAAE;AACxC;;;;;;;;;AAUA,SAAgB,qBAAsB,UAAyC;CAE9E,IAAK,SAAS,MACb,OAAO,SAAS;CAIjB,IAAK,iBAAkB,SAAS,IAAK,GACpC,OAAO,OAAQ,SAAS,IAAK;AAI/B"}