@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
31 lines (28 loc) • 693 B
text/typescript
import type { FontFace, FontFamily } from '@wordpress/core-data';
export function getFontsOutline(
fonts: FontFamily[]
): Record< string, Record< string, boolean > > {
return fonts.reduce(
( acc, font ) => ( {
...acc,
[ font.slug ]: ( font?.fontFace || [] ).reduce(
( faces, face ) => ( {
...faces,
[ `${ face.fontStyle }-${ face.fontWeight }` ]: true,
} ),
{}
),
} ),
{}
);
}
export function isFontFontFaceInOutline(
slug: string,
face: FontFace | null,
outline: Record< string, Record< string, boolean > >
): boolean {
if ( ! face ) {
return !! outline[ slug ];
}
return !! outline[ slug ]?.[ `${ face.fontStyle }-${ face.fontWeight }` ];
}