MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / HtmlTextBuilder

Class HtmlTextBuilder

packages/backend/src/html/htmlTextBuilder.ts:16–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14} from "./htmlMain";
15
16export class HtmlTextBuilder extends HtmlDefaultBuilder {
17 constructor(node: TextNode, settings: HTMLSettings) {
18 super(node, settings);
19 }
20
21 // Override htmlElement to ensure text nodes use paragraph elements
22 get htmlElement(): string {
23 return "p";
24 }
25
26 getTextSegments(node: TextNode): {
27 style: string;
28 text: string;
29 openTypeFeatures: { [key: string]: boolean };
30 className?: string;
31 componentName?: string;
32 }[] {
33 const segments = (node as any)
34 .styledTextSegments as StyledTextSegmentSubset[];
35 if (!segments) {
36 return [];
37 }
38
39 return segments.map((segment, index) => {
40 // Prepare additional CSS properties from layer blur and drop shadow effects.
41 const additionalStyles: { [key: string]: string } = {};
42
43 const layerBlurStyle = this.getLayerBlurStyle();
44 if (layerBlurStyle) {
45 additionalStyles.filter = layerBlurStyle;
46 }
47 const textShadowStyle = this.getTextShadowStyle();
48 if (textShadowStyle) {
49 additionalStyles["text-shadow"] = textShadowStyle;
50 }
51
52 const styleAttributes = formatMultipleJSX(
53 {
54 color: htmlColorFromFills(segment.fills as any),
55 "font-size": segment.fontSize,
56 "font-family": segment.fontName.family,
57 "font-style": this.getFontStyle(segment.fontName.style),
58 "font-weight": `${segment.fontWeight}`,
59 "text-decoration": this.textDecoration(segment.textDecoration),
60 "text-transform": this.textTransform(segment.textCase),
61 "line-height": this.lineHeight(segment.lineHeight, segment.fontSize),
62 "letter-spacing": this.letterSpacing(
63 segment.letterSpacing,
64 segment.fontSize,
65 ),
66 // "text-indent": segment.indentation,
67 "word-wrap": "break-word",
68 ...additionalStyles,
69 },
70 this.isJSX,
71 );
72
73 let chars = segment.characters;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected