feat: remake theme handling

This commit is contained in:
Xylight committed 2024-07-24 21:32:10 -07:00
1 parent 18d2e8fc1e
commit 3aa948891a
10 files changed
+413 -249

No files matched your search

+2 -29
View File
@@ -8,14 +8,7 @@
import Sidebar from '$lib/components/ui/sidebar/Sidebar.svelte'
// @ts-ignore
import { pwaInfo } from 'virtual:pwa-info'
import {
colors,
colorsToVars,
defaultColors,
inDarkLegacyTheme,
legacyTheme,
type Colors,
} from '$lib/ui/colors.js'
import { colorScheme } from '$lib/ui/colors.js'
import { userSettings } from '$lib/settings.js'
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
import { onMount } from 'svelte'
@@ -51,7 +44,6 @@
}
$: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : ''
$: darklegacyTheme = $legacyTheme && inDarkLegacyTheme()
onMount(() => {
if (browser) {
@@ -59,35 +51,16 @@
history.replaceState(
null,
'',
window.location.toString().replace('#main', ''),
window.location.toString().replace('#main', '')
)
}
window
.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', (event) => {
darklegacyTheme = inDarkLegacyTheme()
themeColor = getMetaColor($colors)
})
document.body.querySelector('.loader')?.classList.add('hidden')
}
})
$: title = routes[($page.route.id as keyof typeof routes) ?? '']
$: browser ? document.body.setAttribute('style', colorsToVars($colors)) : ''
// svelte reactivity goof
const getMetaColor = (colors: Colors): string | undefined => {
const regex = /var\([^,]+,\s*(#[0-9A-Fa-f]{6})\)/m
return darklegacyTheme
? colors.zinc?.[925] ?? defaultColors.zinc[925].match(regex)?.[1]
: colors.slate?.[25] ?? defaultColors.slate[25].match(regex)?.[1]
}
$: themeColor = getMetaColor($colors)
</script>
<svelte:head>
<meta name="theme-color" content={themeColor} />
{#if $site?.site_view}
<title>{$site?.site_view.site.name}</title>
{#if LINKED_INSTANCE_URL}