mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 21:53:27 -05:00
dddc457281
* wip * wip * fix something? * wip * wip * wip * fixes * fixes * stroke image * wip * fixes * fixes * remove old code * fix translate fills * remove penpot public uri * remove old code * fix return undefineds * updated packages * finish refactor --------- Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { translateFills } from '@plugin/translators';
|
|
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 = async (
|
|
node: TextNode,
|
|
segments: StyleTextSegment[]
|
|
): Promise<PenpotTextNode[]> => {
|
|
const partials = await Promise.all(
|
|
segments.map(async segment => ({
|
|
textNode: await translateStyleTextSegment(node, segment),
|
|
segment
|
|
}))
|
|
);
|
|
|
|
return translateParagraphProperties(node, partials);
|
|
};
|
|
|
|
export const transformTextStyle = (
|
|
node: TextNode,
|
|
segment: StyleTextSegment
|
|
): Partial<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 = async (
|
|
node: TextNode,
|
|
segment: StyleTextSegment
|
|
): Promise<PenpotTextNode> => {
|
|
return {
|
|
fills: await translateFills(segment.fills, node.width, node.height),
|
|
text: segment.characters,
|
|
...transformTextStyle(node, segment)
|
|
};
|
|
};
|