0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-10 17:10:06 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/partials/transformText.ts
2024-05-06 08:06:14 +02:00

43 lines
1.1 KiB
TypeScript

import { transformFills } from '@plugin/transformers/partials';
import {
transformTextStyle,
translateGrowType,
translateStyleTextSegments,
translateVerticalAlign
} from '@plugin/translators/text';
import { TextShape } from '@ui/lib/types/shapes/textShape';
export const transformText = (node: TextNode): Partial<TextShape> => {
const styledTextSegments = node.getStyledTextSegments([
'fontName',
'fontSize',
'fontWeight',
'lineHeight',
'letterSpacing',
'textCase',
'textDecoration',
'fills'
]);
return {
content: {
type: 'root',
verticalAlign: translateVerticalAlign(node.textAlignVertical),
children: [
{
type: 'paragraph-set',
children: [
{
type: 'paragraph',
children: translateStyleTextSegments(node, styledTextSegments),
...(styledTextSegments.length ? transformTextStyle(node, styledTextSegments[0]) : {}),
...transformFills(node)
}
]
}
]
},
growType: translateGrowType(node)
};
};