0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 13:43:03 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/transformTextNode.ts

60 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-04-15 11:30:51 -05:00
import {
transformBlend,
transformDimensionAndPosition,
2024-04-22 07:35:59 -05:00
transformEffects,
transformFills,
transformProportion,
transformSceneNode,
transformStrokes,
transformTextStyle
2024-04-15 11:30:51 -05:00
} from '@plugin/transformers/partials';
import {
translateGrowType,
translateStyledTextSegments,
translateVerticalAlign
} from '@plugin/translators';
import { TextShape } from '@ui/lib/types/text/textShape';
export const transformTextNode = (node: TextNode, baseX: number, baseY: number): TextShape => {
const styledTextSegments = node.getStyledTextSegments([
'fontName',
'fontSize',
'fontWeight',
'lineHeight',
'letterSpacing',
'textCase',
'textDecoration',
'fills'
]);
return {
type: 'text',
name: node.name,
content: {
type: 'root',
verticalAlign: translateVerticalAlign(node.textAlignVertical),
children: [
{
type: 'paragraph-set',
children: [
{
type: 'paragraph',
children: translateStyledTextSegments(node, styledTextSegments),
...(styledTextSegments.length ? transformTextStyle(node, styledTextSegments[0]) : {}),
...transformFills(node)
}
]
}
]
2024-04-15 11:18:58 -05:00
},
growType: translateGrowType(node),
2024-04-15 11:30:51 -05:00
...transformDimensionAndPosition(node, baseX, baseY),
2024-04-22 07:35:59 -05:00
...transformEffects(node),
2024-04-15 11:30:51 -05:00
...transformSceneNode(node),
...transformBlend(node),
...transformProportion(node),
...transformStrokes(node)
};
};