import { getFrameworkRuntime } from './js-preprocessors.js'; import { extractBareImports, buildImportMapTag } from './import-map.js'; /** * Generate standalone HTML string from fiddle data. */ export function generateStandaloneHtml({ title, html, css, js, mode, extraCss = '', isModule = false, tailwind = false, renderedHtml = null, previewTheme = 'light', resources = [] }) { const runtime = getFrameworkRuntime(mode); const allCss = extraCss ? `${css}\n${extraCss}` : css; const finalHtml = renderedHtml || html; const finalJs = renderedHtml ? '' : js; let bodyContent; if (mode === 'vue' || mode === 'svelte') { bodyContent = finalHtml ? `${finalHtml}\n${runtime.bodyHtml}` : runtime.bodyHtml; } else if (runtime.bodyHtml) { bodyContent = `${finalHtml}\n${runtime.bodyHtml}`; } else { bodyContent = finalHtml; } const effectiveIsModule = isModule || mode === 'svelte'; let importMapTag = ''; if (effectiveIsModule && finalJs) { const bareImports = extractBareImports(finalJs); if (bareImports.length) { importMapTag = buildImportMapTag(bareImports); } } let scripts = ''; if (finalJs) { if (effectiveIsModule) { scripts = `