diff --git a/src/lib/ui/colors.ts b/src/lib/ui/colors.ts index 87630457..7c3382f7 100644 --- a/src/lib/ui/colors.ts +++ b/src/lib/ui/colors.ts @@ -57,6 +57,28 @@ export function hexToRgb(value: string) { return `${r} ${g} ${b}` } +export function rgbToHex(rgbString: string): string { + const rgb = rgbString.split(' ') + + if (rgb.length !== 3) { + return rgbString + } + + const [r, g, b] = rgb.map((val) => { + const num = parseInt(val, 10) + if (isNaN(num) || num < 0 || num > 255) { + return 0 + } + return num + }) + + // Convert to hex and pad with zeros if necessary + const toHex = (n: number) => n.toString(16).padStart(2, '0') + + // Return the hex color code + return `#${toHex(r)}${toHex(g)}${toHex(b)}` +} + function themeStore( data: Writable, fn: ( diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 18299877..46eb4e52 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -8,7 +8,12 @@ import Sidebar from '$lib/components/ui/sidebar/Sidebar.svelte' // @ts-ignore import { pwaInfo } from 'virtual:pwa-info' - import { colorScheme } from '$lib/ui/colors.js' + import { + colorScheme, + inDarkColorScheme, + rgbToHex, + theme, + } from '$lib/ui/colors.js' import { userSettings } from '$lib/settings.js' import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte' import { onMount } from 'svelte' @@ -21,6 +26,7 @@ import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte' import { LINKED_INSTANCE_URL } from '$lib/instance' import { locale } from '$lib/translations' + import { getDefaultColors } from '$lib/ui/presets' nProgress.configure({ minimum: 0.4, @@ -63,6 +69,14 @@ {#if $site?.site_view} {$site?.site_view.site.name} + {#if LINKED_INSTANCE_URL}