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
Alex Sánchez dddc457281
Images (#89)
* 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>
2024-05-09 16:59:27 +02:00

51 lines
1.3 KiB
TypeScript

import { PenpotFile } from '@ui/lib/penpot';
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)
};
};