0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-05 06:10:52 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/partials/transformText.ts
Jordi Sala Morales 044b09207b
Fix empty text layers (#120)
* Fix empty texts

* add changelog
2024-05-27 18:13:19 +02:00

43 lines
1.3 KiB
TypeScript

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