MCPcopy Index your code
hub / github.com/bernaferrari/FigmaToCode / htmlContainer

Function htmlContainer

packages/backend/src/html/htmlMain.ts:576–659  ·  view source on GitHub ↗
(
  node: SceneNode &
    SceneNodeMixin &
    BlendMixin &
    LayoutMixin &
    GeometryMixin &
    MinimalBlendMixin,
  children: string,
  additionalStyles: string[] = [],
  settings: HTMLSettings,
)

Source from the content-addressed store, hash-verified

574// properties named propSomething always take care of ","
575// sometimes a property might not exist, so it doesn't add ","
576const htmlContainer = async (
577 node: SceneNode &
578 SceneNodeMixin &
579 BlendMixin &
580 LayoutMixin &
581 GeometryMixin &
582 MinimalBlendMixin,
583 children: string,
584 additionalStyles: string[] = [],
585 settings: HTMLSettings,
586): Promise<string> => {
587 // ignore the view when size is zero or less
588 if (node.width <= 0 || node.height <= 0) {
589 return children;
590 }
591
592 const builder = new HtmlDefaultBuilder(node, settings)
593 .commonPositionStyles()
594 .commonShapeStyles();
595
596 if (builder.styles || additionalStyles) {
597 let tag = "div";
598 let src = "";
599
600 if (nodeHasImageFill(node)) {
601 const altNode = node as AltNode<ExportableNode>;
602 const hasChildren = "children" in node && node.children.length > 0;
603 let imgUrl = "";
604
605 if (
606 settings.embedImages &&
607 (settings as PluginSettings).framework === "HTML"
608 ) {
609 imgUrl = (await exportNodeAsBase64PNG(altNode, hasChildren)) ?? "";
610 } else {
611 imgUrl = getPlaceholderImage(node.width, node.height);
612 }
613
614 if (hasChildren) {
615 builder.addStyles(
616 formatWithJSX(
617 "background-image",
618 settings.htmlGenerationMode === "jsx",
619 `url(${imgUrl})`,
620 ),
621 );
622 } else {
623 tag = "img";
624 src = ` src="${imgUrl}"`;
625 }
626 }
627
628 const build = builder.build(additionalStyles);
629 const mode = settings.htmlGenerationMode || "html";
630
631 // For styled-components mode
632 if (mode === "styled-components" && builder.cssClassName) {
633 const componentName = cssCollection[builder.cssClassName].componentName;

Callers 2

convertNodeFunction · 0.85
htmlFrameFunction · 0.85

Calls 8

nodeHasImageFillFunction · 0.90
exportNodeAsBase64PNGFunction · 0.90
getPlaceholderImageFunction · 0.90
formatWithJSXFunction · 0.90
indentStringFunction · 0.90
commonShapeStylesMethod · 0.45
commonPositionStylesMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected