0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-06 23:00:55 -05:00
penpot-exporter-figma-plugin/ui-src/converters/createPenpotText.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-05-13 03:12:58 -05:00
import { PenpotFile } from '@ui/lib/types/penpotFile';
import {
Paragraph,
ParagraphSet,
TextContent,
TextNode,
TextShape
} from '@ui/lib/types/shapes/textShape';
2024-04-16 04:24:53 -05:00
import { translateUiBlendMode } from '@ui/translators';
2024-04-08 10:50:01 -05:00
export const createPenpotText = (
file: PenpotFile,
{ type, blendMode, content, ...rest }: TextShape
) => {
file.createText({
2024-04-16 04:24:53 -05:00
blendMode: translateUiBlendMode(blendMode),
content: fixContentFills(content), //@TODO: fix text image fills
...rest
2024-04-08 10:50:01 -05:00
});
};
const fixContentFills = (content?: TextContent): TextContent | undefined => {
if (!content) return;
return {
...content,
children: content.children?.map(children => fixParagraphSetFills(children))
};
};
const fixParagraphSetFills = (paragraphSet: ParagraphSet): ParagraphSet => {
return {
...paragraphSet,
children: paragraphSet.children.map(paragraph => fixParagraphFills(paragraph))
};
};
const fixParagraphFills = (paragraph: Paragraph): Paragraph => {
return {
...paragraph,
fills: paragraph.fills?.filter(fill => fill.fillImage === undefined),
children: paragraph.children.map(child => fixTextNodeFills(child))
};
};
const fixTextNodeFills = (textNode: TextNode): TextNode => {
return {
...textNode,
fills: textNode.fills?.filter(fill => fill.fillImage === undefined)
};
};