import { existsSync, readFileSync } from "node:fs"; import { join } from "node:path"; import { parseHTML } from "linkedom"; import { rewriteAssetPaths, rewriteCssAssetUrls } from "../../compiler/rewriteSubCompPaths.js"; /** * Build a standalone HTML page for a sub-composition. * * Uses the project's own index.html `` so all dependencies (GSAP, fonts, * Lottie, reset styles, runtime) are preserved — instead of building a minimal * page from scratch that would miss important scripts/styles. */ export function buildSubCompositionHtml( projectDir: string, compPath: string, runtimeUrl: string, baseHref?: string, ): string | null { const compFile = join(projectDir, compPath); if (!existsSync(compFile)) return null; const rawComp = readFileSync(compFile, "utf-8"); // Extract content from