From 54df5ead1eb33a58cf5f349f45e4806b570634df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=C3=A1nchez?= Date: Mon, 13 May 2024 13:23:28 +0200 Subject: [PATCH] Fix Text Image Fills (#102) * fix text image fills (pending on develop release in penpot app) * changeset --- .changeset/big-seas-try.md | 5 +++ plugin-src/translators/translateFills.ts | 3 +- ui-src/converters/createPenpotText.ts | 45 ++---------------------- 3 files changed, 9 insertions(+), 44 deletions(-) create mode 100644 .changeset/big-seas-try.md diff --git a/.changeset/big-seas-try.md b/.changeset/big-seas-try.md new file mode 100644 index 0000000..67ca2aa --- /dev/null +++ b/.changeset/big-seas-try.md @@ -0,0 +1,5 @@ +--- +"penpot-exporter": patch +--- + +Fix text image fills diff --git a/plugin-src/translators/translateFills.ts b/plugin-src/translators/translateFills.ts index 840df2d..1620f48 100644 --- a/plugin-src/translators/translateFills.ts +++ b/plugin-src/translators/translateFills.ts @@ -66,7 +66,8 @@ const translateImage = async (imageHash: string | null): Promise { +export const createPenpotText = (file: PenpotFile, { type, blendMode, ...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) - }; -};