0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-05 06:10:52 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/text/translateStyleTextSegments.ts
Alex Sánchez 672567614b
Use Fill Styles to generate fills more efficiently (#180)
* first commit

* change esbuild

* changeset
2024-06-19 15:58:13 +02:00

48 lines
1.6 KiB
TypeScript

import { transformFills } from '@plugin/transformers/partials';
import { translateFontId } from '@plugin/translators/text/font';
import { StyleTextSegment, translateParagraphProperties } from '@plugin/translators/text/paragraph';
import {
translateFontStyle,
translateHorizontalAlign,
translateLetterSpacing,
translateLineHeight,
translateTextDecoration,
translateTextTransform
} from '@plugin/translators/text/properties';
import { TextNode as PenpotTextNode, TextStyle } from '@ui/lib/types/shapes/textShape';
export const translateStyleTextSegments = (
node: TextNode,
segments: StyleTextSegment[]
): PenpotTextNode[] => {
const partials = segments.map(segment => ({
textNode: translateStyleTextSegment(node, segment),
segment
}));
return translateParagraphProperties(node, partials);
};
export const transformTextStyle = (node: TextNode, segment: StyleTextSegment): TextStyle => {
return {
...translateFontId(segment.fontName, segment.fontWeight),
fontFamily: segment.fontName.family,
fontSize: segment.fontSize.toString(),
fontStyle: translateFontStyle(segment.fontName.style),
fontWeight: segment.fontWeight.toString(),
textAlign: translateHorizontalAlign(node.textAlignHorizontal),
textDecoration: translateTextDecoration(segment),
textTransform: translateTextTransform(segment),
letterSpacing: translateLetterSpacing(segment),
lineHeight: translateLineHeight(segment)
};
};
const translateStyleTextSegment = (node: TextNode, segment: StyleTextSegment): PenpotTextNode => {
return {
text: segment.characters,
...transformTextStyle(node, segment),
...transformFills(segment)
};
};