2024-05-13 10:04:13 -05:00
|
|
|
import { translateFills } from '@plugin/translators/fills';
|
2024-05-07 05:18:15 -05:00
|
|
|
import { translateFontId } from '@plugin/translators/text/font';
|
|
|
|
import { StyleTextSegment, translateParagraphProperties } from '@plugin/translators/text/paragraph';
|
2024-05-03 06:23:07 -05:00
|
|
|
import {
|
|
|
|
translateFontStyle,
|
|
|
|
translateHorizontalAlign,
|
|
|
|
translateLetterSpacing,
|
|
|
|
translateLineHeight,
|
|
|
|
translateTextDecoration,
|
|
|
|
translateTextTransform
|
2024-05-07 05:18:15 -05:00
|
|
|
} from '@plugin/translators/text/properties';
|
2024-05-03 06:23:07 -05:00
|
|
|
|
2024-05-06 01:06:14 -05:00
|
|
|
import { TextNode as PenpotTextNode, TextStyle } from '@ui/lib/types/shapes/textShape';
|
2024-05-03 06:23:07 -05:00
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
export const translateStyleTextSegments = (
|
2024-05-03 06:23:07 -05:00
|
|
|
node: TextNode,
|
|
|
|
segments: StyleTextSegment[]
|
2024-06-05 05:36:49 -05:00
|
|
|
): PenpotTextNode[] => {
|
|
|
|
const partials = segments.map(segment => ({
|
|
|
|
textNode: translateStyleTextSegment(node, segment),
|
|
|
|
segment
|
|
|
|
}));
|
2024-05-03 06:23:07 -05:00
|
|
|
|
2024-05-07 05:18:15 -05:00
|
|
|
return translateParagraphProperties(node, partials);
|
2024-05-03 06:23:07 -05:00
|
|
|
};
|
|
|
|
|
2024-05-29 03:30:56 -05:00
|
|
|
export const transformTextStyle = (node: TextNode, segment: StyleTextSegment): TextStyle => {
|
2024-05-03 06:23:07 -05:00
|
|
|
return {
|
|
|
|
...translateFontId(segment.fontName, segment.fontWeight),
|
|
|
|
fontFamily: segment.fontName.family,
|
|
|
|
fontSize: segment.fontSize.toString(),
|
|
|
|
fontStyle: translateFontStyle(segment.fontName.style),
|
|
|
|
fontWeight: segment.fontWeight.toString(),
|
|
|
|
textAlign: translateHorizontalAlign(node.textAlignHorizontal),
|
|
|
|
textDecoration: translateTextDecoration(segment),
|
|
|
|
textTransform: translateTextTransform(segment),
|
|
|
|
letterSpacing: translateLetterSpacing(segment),
|
|
|
|
lineHeight: translateLineHeight(segment)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
const translateStyleTextSegment = (node: TextNode, segment: StyleTextSegment): PenpotTextNode => {
|
2024-05-03 06:23:07 -05:00
|
|
|
return {
|
2024-06-05 05:36:49 -05:00
|
|
|
fills: translateFills(segment.fills),
|
2024-05-03 06:23:07 -05:00
|
|
|
text: segment.characters,
|
|
|
|
...transformTextStyle(node, segment)
|
|
|
|
};
|
|
|
|
};
|