2024-04-29 08:44:49 -05:00
|
|
|
import { transformFills } from '@plugin/transformers/partials';
|
2024-05-07 05:18:15 -05:00
|
|
|
import { transformTextStyle, translateStyleTextSegments } from '@plugin/translators/text';
|
|
|
|
import { translateGrowType, translateVerticalAlign } from '@plugin/translators/text/properties';
|
2024-04-29 08:44:49 -05:00
|
|
|
|
2024-05-29 03:30:56 -05:00
|
|
|
import { TextAttributes, TextShape } from '@ui/lib/types/shapes/textShape';
|
2024-04-29 08:44:49 -05:00
|
|
|
|
2024-05-29 03:30:56 -05:00
|
|
|
export const transformText = async (
|
|
|
|
node: TextNode
|
|
|
|
): Promise<TextAttributes & Pick<TextShape, 'growType'>> => {
|
2024-04-29 08:44:49 -05:00
|
|
|
const styledTextSegments = node.getStyledTextSegments([
|
|
|
|
'fontName',
|
|
|
|
'fontSize',
|
|
|
|
'fontWeight',
|
|
|
|
'lineHeight',
|
|
|
|
'letterSpacing',
|
|
|
|
'textCase',
|
|
|
|
'textDecoration',
|
2024-05-07 05:18:15 -05:00
|
|
|
'indentation',
|
|
|
|
'listOptions',
|
2024-04-29 08:44:49 -05:00
|
|
|
'fills'
|
|
|
|
]);
|
|
|
|
|
|
|
|
return {
|
|
|
|
content: {
|
|
|
|
type: 'root',
|
|
|
|
verticalAlign: translateVerticalAlign(node.textAlignVertical),
|
2024-05-27 11:13:19 -05:00
|
|
|
children: styledTextSegments.length
|
|
|
|
? [
|
2024-04-29 08:44:49 -05:00
|
|
|
{
|
2024-05-27 11:13:19 -05:00
|
|
|
type: 'paragraph-set',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
type: 'paragraph',
|
|
|
|
children: await translateStyleTextSegments(node, styledTextSegments),
|
|
|
|
...transformTextStyle(node, styledTextSegments[0]),
|
|
|
|
...(await transformFills(node))
|
|
|
|
}
|
|
|
|
]
|
2024-04-29 08:44:49 -05:00
|
|
|
}
|
|
|
|
]
|
2024-05-27 11:13:19 -05:00
|
|
|
: undefined
|
2024-04-29 08:44:49 -05:00
|
|
|
},
|
|
|
|
growType: translateGrowType(node)
|
|
|
|
};
|
|
|
|
};
|