0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 21:53:27 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/text/gfonts/translateGoogleFont.ts
Alex Sánchez 58f7b0ab2c
Local Fonts (#81)
* moved validate font logic

* google fonts working

* fixes

* minor improvements

* fix linter

* local fonts

* fixes

* Changeset

* changeset

* refactor

* refactor

* update branch

* minor fix

* move files around

* try to refactor

* refactor

* add todo

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor move files to their concrete location

---------

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
2024-04-30 08:00:11 +02:00

23 lines
744 B
TypeScript

import slugify from 'slugify';
import { translateFontVariantId } from '@plugin/translators/text/gfonts';
import { FontId } from '@ui/lib/types/text/textContent';
import { items as gfonts } from './gfonts.json';
import { GoogleFont } from './googleFont';
export const translateGoogleFont = (fontName: FontName, fontWeight: number): FontId | undefined => {
const googleFont = getGoogleFont(fontName);
if (googleFont === undefined) return;
return {
fontId: `gfont-${slugify(fontName.family.toLowerCase())}`,
fontVariantId: translateFontVariantId(googleFont, fontName, fontWeight)
};
};
const getGoogleFont = (fontName: FontName): GoogleFont | undefined => {
return gfonts.find(font => font.family === fontName.family);
};