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

Function htmlMain

packages/backend/src/html/htmlMain.ts:311–348  ·  view source on GitHub ↗
(
  sceneNode: Array<SceneNode>,
  settings: PluginSettings,
  isPreview: boolean = false,
)

Source from the content-addressed store, hash-verified

309}
310
311export const htmlMain = async (
312 sceneNode: Array<SceneNode>,
313 settings: PluginSettings,
314 isPreview: boolean = false,
315): Promise<HtmlOutput> => {
316 isPreviewGlobal = isPreview;
317 previousExecutionCache = [];
318 cssCollection = {};
319 resetClassNameCounters(); // Reset counters for each new generation
320
321 let htmlContent = await htmlWidgetGenerator(sceneNode, settings);
322
323 // remove the initial \n that is made in Container.
324 if (htmlContent.length > 0 && htmlContent.startsWith("\n")) {
325 htmlContent = htmlContent.slice(1, htmlContent.length);
326 }
327
328 // Always return an object with html property
329 const output: HtmlOutput = { html: htmlContent };
330
331 // Handle different HTML generation modes
332 const mode = settings.htmlGenerationMode || "html";
333
334 if (mode !== "html") {
335 // Generate component code for non-html modes
336 output.html = generateComponentCode(htmlContent, sceneNode, mode);
337
338 // For svelte mode, we don't need separate CSS as it's included in the component
339 if (mode === "svelte" && Object.keys(cssCollection).length > 0) {
340 // CSS is already included in the Svelte component
341 }
342 } else if (Object.keys(cssCollection).length > 0) {
343 // For plain HTML with CSS, include CSS separately
344 output.css = getCollectedCSS();
345 }
346
347 return output;
348};
349
350export const generateHTMLPreview = async (
351 nodes: SceneNode[],

Callers 3

convertToCodeFunction · 0.90
codegenModeFunction · 0.90
generateHTMLPreviewFunction · 0.85

Calls 4

resetClassNameCountersFunction · 0.85
htmlWidgetGeneratorFunction · 0.85
generateComponentCodeFunction · 0.85
getCollectedCSSFunction · 0.85

Tested by

no test coverage detected