mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2025-01-23 07:48:41 -05:00
21 lines
651 B
TypeScript
21 lines
651 B
TypeScript
|
import { GoogleFont } from './googleFont';
|
||
|
|
||
|
export const translateFontVariantId = (
|
||
|
googleFont: GoogleFont,
|
||
|
fontName: FontName,
|
||
|
fontWeight: number
|
||
|
) => {
|
||
|
// check match directly by style
|
||
|
const variant = googleFont.variants?.find(variant => variant === fontName.style.toLowerCase());
|
||
|
|
||
|
if (variant !== undefined) return variant;
|
||
|
|
||
|
// check match by style and weight
|
||
|
const italic = fontName.style.toLowerCase().includes('italic') ? 'italic' : '';
|
||
|
const variantWithWeight = googleFont.variants?.find(
|
||
|
variant => variant === `${fontWeight.toString()}${italic}`
|
||
|
);
|
||
|
|
||
|
if (variantWithWeight !== undefined) return variantWithWeight;
|
||
|
};
|