2024-05-29 12:52:21 +02:00
|
|
|
import { PenpotFile } from '@ui/lib/types/penpotFile';
|
2024-06-03 17:29:33 +02:00
|
|
|
import { TextContent, TextShape } from '@ui/lib/types/shapes/textShape';
|
2024-05-30 17:54:37 +02:00
|
|
|
import { parseFigmaId } from '@ui/parser';
|
2024-06-18 11:20:51 +02:00
|
|
|
import { symbolFills, symbolStrokes } from '@ui/parser/creators/symbols';
|
2024-05-29 12:52:21 +02:00
|
|
|
|
2024-05-30 17:54:37 +02:00
|
|
|
export const createText = (
|
|
|
|
file: PenpotFile,
|
2024-06-18 11:20:51 +02:00
|
|
|
{ type, figmaId, figmaRelatedId, ...shape }: TextShape
|
2024-05-30 17:54:37 +02:00
|
|
|
) => {
|
2024-06-18 11:20:51 +02:00
|
|
|
shape.id = parseFigmaId(file, figmaId);
|
|
|
|
shape.shapeRef = parseFigmaId(file, figmaRelatedId, true);
|
|
|
|
shape.content = parseContent(shape.content);
|
|
|
|
shape.strokes = symbolStrokes(shape.strokes);
|
|
|
|
|
|
|
|
file.createText(shape);
|
2024-05-29 12:52:21 +02:00
|
|
|
};
|
2024-06-03 17:29:33 +02:00
|
|
|
|
|
|
|
const parseContent = (content: TextContent | undefined): TextContent | undefined => {
|
|
|
|
if (!content) return;
|
|
|
|
|
|
|
|
content.children?.forEach(paragraphSet => {
|
|
|
|
paragraphSet.children.forEach(paragraph => {
|
|
|
|
paragraph.children.forEach(textNode => {
|
2024-06-19 15:58:13 +02:00
|
|
|
textNode.fills = symbolFills(textNode.fillStyleId, textNode.fills);
|
2024-06-03 17:29:33 +02:00
|
|
|
});
|
|
|
|
|
2024-06-19 15:58:13 +02:00
|
|
|
paragraph.fills = symbolFills(paragraph.fillStyleId, paragraph.fills);
|
2024-06-03 17:29:33 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return content;
|
|
|
|
};
|