Files
Momento/memento-note/lib/inline-boot-scripts.ts
Antigravity afbb0dfc2d
All checks were successful
CI / Lint, Unit Tests & Build (push) Successful in 6m57s
CI / Deploy production (on server) (push) Successful in 24s
fix(ui): thème, textes et lisibilité restants de la revue
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>
2026-08-30 21:13:07 +00:00

64 lines
2.5 KiB
TypeScript

/**
* Scripts boot inline dans le <head> (évite next/script + warning React 19
* « Scripts inside React components are never executed… »).
* Doivent rester synchrones et sans import.
*/
export const THEME_INIT_SCRIPT = `(function () {
try {
var root = document.documentElement;
var fallback = root.getAttribute('data-server-theme') || 'light';
var defaultAccent = root.getAttribute('data-server-accent') || '#A47148';
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';
try {
document.cookie = 'memento-theme=' + encodeURIComponent(theme) + '; path=/; max-age=31536000; SameSite=Lax';
if (!stored) localStorage.setItem('theme-preference', theme);
} catch (e) {}
var wantsDark = false;
if (theme === 'auto') {
wantsDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
} else if (theme === 'dark' || theme === 'midnight') {
wantsDark = true;
}
if (wantsDark) root.classList.add('dark');
else root.classList.remove('dark');
try { root.style.colorScheme = wantsDark ? 'dark' : 'light'; } catch (e) {}
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 effectiveAccent = defaultAccent || accentStored || '#A47148';
root.style.setProperty('--color-brand-accent', effectiveAccent);
if (defaultAccent && accentStored !== defaultAccent) {
try { localStorage.setItem('accent-color', defaultAccent); } catch (e) {}
}
} catch (e) {
console.error('Theme script error', e);
}
})();`
export const DIRECTION_INIT_SCRIPT = `(function () {
try {
var lang = localStorage.getItem('user-language');
if (!lang) {
var c = document.cookie.split(';').map(function (s) { return s.trim(); })
.find(function (s) { return s.startsWith('user-language='); });
if (c) lang = c.split('=')[1];
}
if (lang === 'fa' || lang === 'ar') {
document.documentElement.dir = 'rtl';
document.documentElement.lang = lang;
}
} catch (e) {}
})();`