Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Jun 3, 2024
1 parent 89836ef commit 675c89b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion ui-src/parser/creators/createComponentLibrary.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { componentsLibrary } from '@plugin/ComponentLibrary';

import { PenpotFile } from '@ui/lib/types/penpotFile';
import { symbolBlendMode, symbolFills } from '@ui/parser/creators/symbols';
import { uiComponents } from '@ui/parser/libraries';

import { createItems } from '.';
Expand All @@ -12,10 +13,12 @@ export const createComponentLibrary = (file: PenpotFile) => {
return;
}

const { children = [], ...rest } = component;
const { children = [], fills, blendMode, ...rest } = component;

file.startComponent({
...rest,
fills: symbolFills(fills),
blendMode: symbolBlendMode(blendMode),
id: uiComponent.componentId,
componentId: uiComponent.componentId,
mainInstancePage: uiComponent.mainInstancePage,
Expand Down
23 changes: 20 additions & 3 deletions ui-src/parser/creators/createText.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import { PenpotFile } from '@ui/lib/types/penpotFile';
import { TextShape } from '@ui/lib/types/shapes/textShape';
import { TextContent, TextShape } from '@ui/lib/types/shapes/textShape';
import { parseFigmaId } from '@ui/parser';
import { symbolBlendMode } from '@ui/parser/creators/symbols';
import { symbolBlendMode, symbolFills } from '@ui/parser/creators/symbols';

export const createText = (
file: PenpotFile,
{ type, blendMode, figmaId, figmaRelatedId, ...rest }: TextShape
{ type, blendMode, figmaId, content, figmaRelatedId, ...rest }: TextShape
) => {
file.createText({
id: parseFigmaId(file, figmaId),
shapeRef: parseFigmaId(file, figmaRelatedId, true),
content: parseContent(content),
blendMode: symbolBlendMode(blendMode),
...rest
});
};

const parseContent = (content: TextContent | undefined): TextContent | undefined => {
if (!content) return;

content.children?.forEach(paragraphSet => {
paragraphSet.children.forEach(paragraph => {
paragraph.children.forEach(textNode => {
textNode.fills = symbolFills(textNode.fills);
});

paragraph.fills = symbolFills(paragraph.fills);
});
});

return content;
};

0 comments on commit 675c89b

Please sign in to comment.