/** * 主题初始化 - 在 React 水合前执行,避免主题闪烁 * 优先读全局 nomadro-theme,回退 nomadvip-theme;默认夜间 */ export const themeInitScript = ` (function() { try { var theme = localStorage.getItem('nomadro-theme') || localStorage.getItem('nomadvip-theme'); var resolved = theme === 'light' ? 'light' : (theme === 'dark' ? 'dark' : (theme === 'system' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : 'dark')); var root = document.documentElement; root.classList.remove('light', 'dark'); root.classList.add(resolved); root.dataset.theme = resolved; } catch (e) { document.documentElement.classList.add('dark'); document.documentElement.dataset.theme = 'dark'; } })(); `;