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/ui-src/converters/createPenpotText.ts
2024-05-13 10:12:58 +02:00

51 lines
1.3 KiB
TypeScript

import { PenpotFile } from '@ui/lib/types/penpotFile';
import {
Paragraph,
ParagraphSet,
TextContent,
TextNode,
TextShape
} from '@ui/lib/types/shapes/textShape';
import { translateUiBlendMode } from '@ui/translators';
export const createPenpotText = (
file: PenpotFile,
{ type, blendMode, content, ...rest }: TextShape
) => {
file.createText({
blendMode: translateUiBlendMode(blendMode),
content: fixContentFills(content), //@TODO: fix text image fills
...rest
});
};
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)
};
};