Les boutons suivent la couleur d’apparence, les libellés trop petits ou trop techniques sont clarifiés, et le catalogue des fournisseurs se met à jour tout seul. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.9 KiB
TypeScript
44 lines
1.9 KiB
TypeScript
/**
|
||
* Script inline exécuté avant l’hydratation : 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;
|
||
try {
|
||
document.cookie = 'memento-theme=' + encodeURIComponent(theme) + '; path=/; max-age=31536000; SameSite=Lax';
|
||
if (!stored) localStorage.setItem('theme-preference', theme);
|
||
} catch (e) {}
|
||
var wantsDark = theme === 'dark' || theme === 'midnight' || (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||
if (wantsDark) root.classList.add('dark');
|
||
else root.classList.remove('dark');
|
||
if (theme === 'auto' || theme === 'dark' || theme === 'light') root.removeAttribute('data-theme');
|
||
else {
|
||
root.setAttribute('data-theme', theme);
|
||
}
|
||
root.setAttribute('data-applied-theme', theme);
|
||
var accentStored = localStorage.getItem('accent-color');
|
||
var serverAccent = ${JSON.stringify(defaultAccent)};
|
||
var effectiveAccent = serverAccent || accentStored || '#A47148';
|
||
root.style.setProperty('--color-brand-accent', effectiveAccent);
|
||
if (serverAccent && accentStored !== serverAccent) {
|
||
try { localStorage.setItem('accent-color', serverAccent); } catch (e) {}
|
||
}
|
||
} catch (e) {
|
||
console.error('Theme script error', e);
|
||
}
|
||
})();
|
||
`.trim()
|
||
}
|