UNPKG

@wordpress/components

Version:
59 lines (49 loc) 1.55 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.getFontSize = getFontSize; exports.getHeadingFontSize = getHeadingFontSize; exports.HEADING_FONT_SIZES = exports.PRESET_FONT_SIZES = exports.BASE_FONT_SIZE = void 0; var _configValues = _interopRequireDefault(require("../../utils/config-values")); /** * External dependencies */ // eslint-disable-next-line no-restricted-imports /** * Internal dependencies */ const BASE_FONT_SIZE = 13; exports.BASE_FONT_SIZE = BASE_FONT_SIZE; const PRESET_FONT_SIZES = { body: BASE_FONT_SIZE, caption: 10, footnote: 11, largeTitle: 28, subheadline: 12, title: 20 }; exports.PRESET_FONT_SIZES = PRESET_FONT_SIZES; const HEADING_FONT_SIZES = [1, 2, 3, 4, 5, 6].flatMap(n => [n, n.toString()]); exports.HEADING_FONT_SIZES = HEADING_FONT_SIZES; function getFontSize(size = BASE_FONT_SIZE) { if (size in PRESET_FONT_SIZES) { return getFontSize(PRESET_FONT_SIZES[size]); } if (typeof size !== 'number') { const parsed = parseFloat(size); if (Number.isNaN(parsed)) return size; size = parsed; } const ratio = `(${size} / ${BASE_FONT_SIZE})`; return `calc(${ratio} * ${_configValues.default.fontSize})`; } function getHeadingFontSize(size = 3) { if (!HEADING_FONT_SIZES.includes(size)) { return getFontSize(size); } const headingSize = `fontSizeH${size}`; return _configValues.default[headingSize]; } //# sourceMappingURL=font-size.js.map