Match TallStackUI's theme fallback before first paint
The inline theme script treated an unknown stored "dark-theme" value as light, while tallstackui_darkTheme() treats it as "system", so a dark OS could flash the light theme. Also move an inline comment in AppServiceProvider into the method's PHPDoc. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -14,12 +14,13 @@
|
||||
Apply the stored theme before the first paint. TallStackUI's
|
||||
tallstackui_darkTheme() keeps it in localStorage ("dark-theme"),
|
||||
but only runs once Alpine starts, which would flash the light theme.
|
||||
Like the package, any value other than dark/light (true/false) means "system".
|
||||
--}}
|
||||
<script>
|
||||
(() => {
|
||||
const stored = localStorage.getItem('dark-theme');
|
||||
const dark = stored === 'dark' || stored === 'true'
|
||||
|| ((stored === null || stored === 'system') && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
|| (stored !== 'light' && stored !== 'false' && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
document.documentElement.classList.toggle('dark', dark);
|
||||
})();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user