Files
Compass/web/public/init-theme.js
Martin Braquet e3b743f87b Add font preference selector in settings (#28)
* Add font preference selector in settings

* Consolidate font family config into shared global constant

* Revert "Consolidate font family config into shared global constant"

This reverts commit 789ddc98e1.

* Fix
2026-02-16 12:24:45 +01:00

22 lines
954 B
JavaScript

// run this in <head> as blocking to prevent flash of unstyled content. See theme-provider.tsx
{
const localTheme = localStorage.getItem('theme')
const theme = localTheme ? JSON.parse(localTheme) : 'auto'
if (theme === 'dark' || (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark')
}
const localFontPreference = localStorage.getItem('font-preference')
const fontPreference = localFontPreference ? JSON.parse(localFontPreference) : 'atkinson'
const fontFamilies = {
atkinson: '"Atkinson Hyperlegible Next", Georgia, "Times New Roman", Times, serif',
'system-sans': '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif',
'classic-serif': 'Georgia, "Times New Roman", Times, serif',
}
document.documentElement.style.setProperty('--font-main', fontFamilies[fontPreference] ?? fontFamilies.atkinson)
}