import { THEME_STORAGE_KEY } from './theme-provider'; /** * Returns a string containing an IIFE to inject in the document `
` * before any styles or React code loads. It reads the stored theme * preference (or falls back to prefers-color-scheme) and sets * `data-theme` on `` synchronously, so consumers never see a * flash of the wrong theme before ThemeProvider hydrates. * * Usage (Next.js, Astro, Remix, or hand-rolled SSR): * * * * * * The script is intentionally small (<500 bytes) so it doesn't hurt LCP. */ export function getThemeFoucScript(storageKey: string = THEME_STORAGE_KEY): string { // The script body is a single expression so a minifier can inline it verbatim. // It deliberately avoids optional chaining and nullish coalescing to stay // compatible with older SSR targets that don't transpile inline