aboutsummaryrefslogtreecommitdiff
path: root/llama.cpp/tools/server/webui/.storybook/ModeWatcherDecorator.svelte
blob: 8bded8b3f1e64c1ca2efdb7424b1221df6988124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<script lang="ts">
	import { ModeWatcher } from 'mode-watcher';
	import { onMount } from 'svelte';

	interface Props {
		children?: any;
	}

	let { children }: Props = $props();

	onMount(() => {
		const root = document.documentElement;
		const theme = localStorage.getItem('mode-watcher-mode') || 'system';

		if (theme === 'dark') {
			root.classList.add('dark');
		} else if (theme === 'light') {
			root.classList.remove('dark');
		} else {
			const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
			if (prefersDark) {
				root.classList.add('dark');
			} else {
				root.classList.remove('dark');
			}
		}
	});
</script>

<ModeWatcher />

{#if children}
	{@const Component = children}

	<Component />
{/if}