UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 3.19 kB
{ "version": 3, "sources": ["../../../src/components/font-sizes/utils.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { kebabCase } = unlock( componentsPrivateApis );\n\n/**\n * Returns the font size object based on an array of named font sizes and the namedFontSize and customFontSize values.\n * \tIf namedFontSize is undefined or not found in fontSizes an object with just the size value based on customFontSize is returned.\n *\n * @param {Array} fontSizes Array of font size objects containing at least the \"name\" and \"size\" values as properties.\n * @param {?string} fontSizeAttribute Content of the font size attribute (slug).\n * @param {?number} customFontSizeAttribute Contents of the custom font size attribute (value).\n *\n * @return {?Object} If fontSizeAttribute is set and an equal slug is found in fontSizes it returns the font size object for that slug.\n * \t\t\t\t\t Otherwise, an object with just the size value based on customFontSize is returned.\n */\nexport const getFontSize = (\n\tfontSizes,\n\tfontSizeAttribute,\n\tcustomFontSizeAttribute\n) => {\n\tif ( fontSizeAttribute ) {\n\t\tconst fontSizeObject = fontSizes?.find(\n\t\t\t( { slug } ) => slug === fontSizeAttribute\n\t\t);\n\t\tif ( fontSizeObject ) {\n\t\t\treturn fontSizeObject;\n\t\t}\n\t}\n\treturn {\n\t\tsize: customFontSizeAttribute,\n\t};\n};\n\n/**\n * Returns the corresponding font size object for a given value.\n *\n * @param {Array} fontSizes Array of font size objects.\n * @param {number} value Font size value.\n *\n * @return {Object} Font size object.\n */\nexport function getFontSizeObjectByValue( fontSizes, value ) {\n\tconst fontSizeObject = fontSizes?.find( ( { size } ) => size === value );\n\tif ( fontSizeObject ) {\n\t\treturn fontSizeObject;\n\t}\n\n\treturn {\n\t\tsize: value,\n\t};\n}\n\n/**\n * Returns a class based on fontSizeName.\n *\n * @param {string} fontSizeSlug Slug of the fontSize.\n *\n * @return {string | undefined} String with the class corresponding to the fontSize passed.\n * The class is generated by appending 'has-' followed by fontSizeSlug in kebabCase and ending with '-font-size'.\n */\nexport function getFontSizeClass( fontSizeSlug ) {\n\tif ( ! fontSizeSlug ) {\n\t\treturn;\n\t}\n\n\treturn `has-${ kebabCase( fontSizeSlug ) }-font-size`;\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAqD;AAKrD,yBAAuB;AAEvB,IAAM,EAAE,UAAU,QAAI,2BAAQ,kBAAAA,WAAsB;AAa7C,IAAM,cAAc,CAC1B,WACA,mBACA,4BACI;AACJ,MAAK,mBAAoB;AACxB,UAAM,iBAAiB,WAAW;AAAA,MACjC,CAAE,EAAE,KAAK,MAAO,SAAS;AAAA,IAC1B;AACA,QAAK,gBAAiB;AACrB,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO;AAAA,IACN,MAAM;AAAA,EACP;AACD;AAUO,SAAS,yBAA0B,WAAW,OAAQ;AAC5D,QAAM,iBAAiB,WAAW,KAAM,CAAE,EAAE,KAAK,MAAO,SAAS,KAAM;AACvE,MAAK,gBAAiB;AACrB,WAAO;AAAA,EACR;AAEA,SAAO;AAAA,IACN,MAAM;AAAA,EACP;AACD;AAUO,SAAS,iBAAkB,cAAe;AAChD,MAAK,CAAE,cAAe;AACrB;AAAA,EACD;AAEA,SAAO,OAAQ,UAAW,YAAa,CAAE;AAC1C;", "names": ["componentsPrivateApis"] }