-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathutils.js
49 lines (42 loc) · 1.28 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
*
* @param {string} variation The variation name.
*
* @return {string} The variation class name.
*/
export function getVariationClassName( variation ) {
if ( ! variation ) {
return '';
}
return `is-style-${ variation }`;
}
function getFontFamilyFromSetting( fontFamilies, setting ) {
if ( ! setting ) {
return null;
}
const fontFamilyVariable = setting.replace( 'var(', '' ).replace( ')', '' );
const fontFamilySlug = fontFamilyVariable?.split( '--' ).slice( -1 )[ 0 ];
return fontFamilies.find(
( fontFamily ) => fontFamily.slug === fontFamilySlug
);
}
export function getFontFamilies( themeJson ) {
const fontFamilies = themeJson?.settings?.typography?.fontFamilies?.theme; // TODO this could not be under theme.
const bodyFontFamilySetting = themeJson?.styles?.typography?.fontFamily;
const bodyFontFamily = getFontFamilyFromSetting(
fontFamilies,
bodyFontFamilySetting
);
const headingFontFamilySetting =
themeJson?.styles?.elements?.heading?.typography?.fontFamily;
let headingFontFamily;
if ( ! headingFontFamilySetting ) {
headingFontFamily = bodyFontFamily;
} else {
headingFontFamily = getFontFamilyFromSetting(
fontFamilies,
themeJson?.styles?.elements?.heading?.typography?.fontFamily
);
}
return [ bodyFontFamily, headingFontFamily ];
}