Files
Momento/memento-note/lib/theme-script.ts
Antigravity 18ffd76c1e fix(chart): improve error handling and color variety
- Add quotaExceeded flag to response for better error UX
- Show dedicated quota exceeded state with upgrade button
- Improve AI prompt to better detect data patterns
- Add chart type-specific colors (blue, indigo, emerald, violet, etc.)
- Replace generic primary/10 colors with varied accent colors

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 09:19:52 +00:00

40 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Script inline exécuté avant lhydratation : même logique que `applyDocumentTheme`.
*/
import { normalizeThemeId } from './apply-document-theme'
export function getThemeScript(serverTheme: string = 'light', serverAccentColor: string | null = null) {
const fallback = normalizeThemeId(serverTheme)
const defaultAccent = serverAccentColor || '#A47148'
return `
(function() {
try {
var fallback = ${JSON.stringify(fallback)};
var stored = localStorage.getItem('theme-preference');
var raw = stored || fallback;
if (raw === 'slate') raw = 'light';
var allowed = { light:1, dark:1, auto:1, sepia:1, midnight:1, rose:1, green:1, lavender:1, sand:1, ocean:1, sunset:1, blue:1 };
var theme = allowed[raw] ? raw : 'light';
var root = document.documentElement;
root.classList.remove('dark');
root.removeAttribute('data-theme');
if (theme === 'auto') {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) root.classList.add('dark');
} else if (theme === 'dark') {
root.classList.add('dark');
} else if (theme === 'light') {
/* :root papier */
} else {
root.setAttribute('data-theme', theme);
if (theme === 'midnight') root.classList.add('dark');
}
var accentStored = localStorage.getItem('accent-color');
var effectiveAccent = accentStored || ${JSON.stringify(defaultAccent)};
root.style.setProperty('--color-brand-accent', effectiveAccent);
} catch (e) {
console.error('Theme script error', e);
}
})();
`.trim()
}