feat: remake theme handling
This commit is contained in:
1 parent
18d2e8fc1e
commit
3aa948891a
10 files changed
+413
-249
No files matched your search
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { Color } from '$lib/ui/colors'
|
||||
import {
|
||||
ArrowDownCircle,
|
||||
ArrowUp,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
top: boolean | null
|
||||
noGap: boolean | null
|
||||
},
|
||||
screenWidth: number,
|
||||
screenWidth: number
|
||||
): {
|
||||
noGap: boolean
|
||||
top: boolean
|
||||
@@ -35,7 +35,7 @@
|
||||
export const calculatePadding = (
|
||||
panel: boolean,
|
||||
top: boolean,
|
||||
content: boolean,
|
||||
content: boolean
|
||||
): {
|
||||
top: number
|
||||
class: string
|
||||
@@ -62,13 +62,13 @@
|
||||
})
|
||||
export let contentPadding: Readable<ReturnType<typeof calculatePadding>> =
|
||||
derived(dockProps, ($dockProps, set) =>
|
||||
set(calculatePadding($dockProps.noGap, $dockProps.top, true)),
|
||||
set(calculatePadding($dockProps.noGap, $dockProps.top, true))
|
||||
)
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { colors, colorsToVars } from '$lib/ui/colors'
|
||||
import { themeVars } from '$lib/ui/colors'
|
||||
import { routes } from '$lib/util.js'
|
||||
import { derived, writable, type Readable, type Writable } from 'svelte/store'
|
||||
|
||||
@@ -82,11 +82,7 @@
|
||||
|
||||
<svelte:window bind:innerWidth={$screenWidth} />
|
||||
|
||||
<div
|
||||
{...$$restProps}
|
||||
class="shell {$$props.class}"
|
||||
style={colorsToVars($colors)}
|
||||
>
|
||||
<div {...$$restProps} class="shell {$$props.class}" style={$themeVars}>
|
||||
<slot />
|
||||
<div
|
||||
class="
|
||||
@@ -112,7 +108,7 @@
|
||||
pointer-events-auto {topPanel
|
||||
? 'bg-slate-50 dark:bg-zinc-950 border-slate-100 dark:border-zinc-900'
|
||||
: `border-slate-200 dark:border-zinc-800 shadow-2xl backdrop-blur-xl
|
||||
dark:backdrop-brightness-[25%] bg-[#ffffff]/75`}"
|
||||
bg-white/50 dark:bg-zinc-925/70`}"
|
||||
{title}
|
||||
style="transition: border-radius 250ms;"
|
||||
/>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
import { legacyTheme } from '$lib/ui/colors'
|
||||
import { colorScheme } from '$lib/ui/colors'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { site } from '$lib/lemmy'
|
||||
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
||||
@@ -127,11 +127,11 @@
|
||||
</MenuButton>
|
||||
<MenuButton class="!py-0">
|
||||
<Icon
|
||||
src={$legacyTheme == 'system'
|
||||
src={$colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
: $legacyTheme == 'light'
|
||||
: $colorScheme == 'light'
|
||||
? Sun
|
||||
: $legacyTheme == 'dark'
|
||||
: $colorScheme == 'dark'
|
||||
? Moon
|
||||
: Moon}
|
||||
mini
|
||||
@@ -142,7 +142,7 @@
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<div class="contents" on:click|stopPropagation={() => {}}>
|
||||
<Select bind:value={$legacyTheme} class="ml-auto my-auto w-24" size="sm">
|
||||
<Select bind:value={$colorScheme} class="ml-auto my-auto w-24" size="sm">
|
||||
<option value="system">{$t('nav.menu.colorscheme.system')}</option>
|
||||
<option value="light">{$t('nav.menu.colorscheme.light')}</option>
|
||||
<option value="dark">{$t('nav.menu.colorscheme.dark')}</option>
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { resumables, type ResumableItem } from '$lib/lemmy/item'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { t } from '$lib/translations'
|
||||
import { legacyTheme } from '$lib/ui/colors'
|
||||
import { colorScheme } from '$lib/ui/colors'
|
||||
import { fullCommunityName } from '$lib/util'
|
||||
import {
|
||||
ArrowRightOnRectangle,
|
||||
@@ -354,21 +354,21 @@ export function getGroups(
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.system'),
|
||||
}),
|
||||
handle: () => legacyTheme.set('system'),
|
||||
handle: () => colorScheme.set('system'),
|
||||
icon: ComputerDesktop,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.light'),
|
||||
}),
|
||||
handle: () => legacyTheme.set('light'),
|
||||
handle: () => colorScheme.set('light'),
|
||||
icon: Sun,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.dark'),
|
||||
}),
|
||||
handle: () => legacyTheme.set('dark'),
|
||||
handle: () => colorScheme.set('dark'),
|
||||
icon: Moon,
|
||||
},
|
||||
],
|
||||
|
||||
+161
-155
@@ -1,184 +1,190 @@
|
||||
/**
|
||||
* This enum represents a UI color as tailwind classes.
|
||||
*/
|
||||
|
||||
export enum Color {
|
||||
'accent' = 'border border-black dark:border-white bg-black text-white\
|
||||
dark:bg-white dark:text-black hover:text-inherit hover:bg-transparent hover:dark:bg-transparent active:bg-black/10 active:dark:bg-white/10',
|
||||
'ghost' = 'bg-black/5 dark:bg-white/5 hover:bg-black/10 hover:dark:bg-white/10 text-black dark:text-white border border-transparent',
|
||||
'secondary' = 'hover:bg-black/10 hover:dark:bg-white/10 text-black dark:text-white fill-black dark:fill-white',
|
||||
'danger' = 'border border-red-500 bg-red-500 text-white hover:text-red-500 hover:bg-transparent',
|
||||
'dangerSecondary' = 'hover:bg-red-500 text-red-500 hover:text-white',
|
||||
'border' = 'border border-slate-200 dark:border-zinc-700 bg-slate-100 dark:bg-zinc-800 hover:bg-slate-200 hover:dark:bg-zinc-700',
|
||||
'borderDark' = 'border border-slate-200 dark:border-zinc-800 bg-slate-100 dark:bg-zinc-900 hover:bg-slate-200 hover:dark:bg-zinc-800',
|
||||
}
|
||||
|
||||
import { get, writable } from 'svelte/store'
|
||||
import {
|
||||
derived,
|
||||
get,
|
||||
writable,
|
||||
type Stores,
|
||||
type Updater,
|
||||
type Unsubscriber,
|
||||
type Writable,
|
||||
type Readable,
|
||||
} from 'svelte/store'
|
||||
import { env } from '$env/dynamic/public'
|
||||
import { browser } from '$app/environment'
|
||||
import { presets } from './presets'
|
||||
|
||||
interface ColorData {
|
||||
theme: number
|
||||
themes: Colors[]
|
||||
type ColorScheme = 'system' | 'light' | 'dark'
|
||||
|
||||
interface ThemeData {
|
||||
scheme: ColorScheme
|
||||
themes: Theme[]
|
||||
currentTheme: number
|
||||
}
|
||||
|
||||
interface Theme {
|
||||
colors: Colors
|
||||
name: string
|
||||
export interface Theme {
|
||||
id: number
|
||||
colors: ThemeColors
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface Colors {
|
||||
slate: {
|
||||
25?: string
|
||||
50?: string
|
||||
100?: string
|
||||
200?: string
|
||||
400?: string
|
||||
500?: string
|
||||
600?: string
|
||||
700?: string
|
||||
800?: string
|
||||
900?: string
|
||||
925?: string
|
||||
950?: string
|
||||
}
|
||||
zinc: {
|
||||
100?: string
|
||||
200?: string
|
||||
300?: string
|
||||
400?: string
|
||||
500?: string
|
||||
600?: string
|
||||
700?: string
|
||||
800?: string
|
||||
900?: string
|
||||
925?: string
|
||||
950?: string
|
||||
}
|
||||
primary: {
|
||||
100?: string
|
||||
900?: string
|
||||
}
|
||||
other: {
|
||||
black?: string
|
||||
white?: string
|
||||
interface ThemeColors {
|
||||
[scheme: string]: {
|
||||
[key: string]: string
|
||||
}
|
||||
}
|
||||
|
||||
export const defaultColors = {
|
||||
slate: {
|
||||
25: `var(--c-s-25,#fcfdfe)`,
|
||||
50: `var(--c-s-50,#f8fafc)`,
|
||||
100: `var(--c-s-100,#f1f5f9)`,
|
||||
200: `var(--c-s-200,#e2e8f0)`,
|
||||
300: `var(--c-s-300,#cbd5e1)`,
|
||||
400: `var(--c-s-400,#94a3b8)`,
|
||||
500: `var(--c-s-500,#64748b)`,
|
||||
600: `var(--c-s-600,#475569)`,
|
||||
700: `var(--c-s-700,#334155)`,
|
||||
800: `var(--c-s-800,#1e293b)`,
|
||||
900: `var(--c-s-900,#0f172a`,
|
||||
950: `var(--c-s-950,#020617)`,
|
||||
},
|
||||
zinc: {
|
||||
50: `var(--c-z-50,#fafafa)`,
|
||||
100: `var(--c-z-100,#f4f4f5)`,
|
||||
200: `var(--c-z-200,#e4e4e7)`,
|
||||
300: `var(--c-z-300,#d4d4d8)`,
|
||||
400: `var(--c-z-400,#a1a1aa)`,
|
||||
500: `var(--c-z-500,#71717a)`,
|
||||
600: `var(--c-z-600,#52525b)`,
|
||||
700: 'var(--c-z-700,#34343b)',
|
||||
800: 'var(--c-z-800,#1f1f24)',
|
||||
900: 'var(--c-z-900,#121215)',
|
||||
925: 'var(--c-z-925,#0c0c0e)',
|
||||
950: `var(--c-z-950,#09090b)`,
|
||||
},
|
||||
primary: {
|
||||
100: 'var(--c-p-100,#f1f5f9)',
|
||||
900: 'var(--c-p-900,#0f172a)',
|
||||
},
|
||||
other: {
|
||||
black: `#000`,
|
||||
white: `var(--c-o-white,#fff)`,
|
||||
},
|
||||
export function getDefaultColors(): ThemeColors {
|
||||
return env.PUBLIC_THEME
|
||||
? JSON.parse(env.PUBLIC_THEME)
|
||||
: {
|
||||
slate: {
|
||||
25: '252 253 254',
|
||||
50: '248 250 252',
|
||||
100: '241 245 249',
|
||||
200: '226 232 240',
|
||||
300: '203 213 225',
|
||||
400: '148 163 184',
|
||||
500: '100 116 139',
|
||||
600: '71 85 105',
|
||||
700: '51 65 85',
|
||||
800: '30 41 59',
|
||||
900: '15 23 42',
|
||||
950: '2 6 23',
|
||||
},
|
||||
zinc: {
|
||||
50: `249 250 251`,
|
||||
100: `243 244 246`,
|
||||
200: `229 231 235`,
|
||||
300: `209 213 219`,
|
||||
400: `156 163 175`,
|
||||
500: `107 114 128`,
|
||||
600: `75 85 99`,
|
||||
700: '50 60 76',
|
||||
800: '22 31 45',
|
||||
900: '17 24 39',
|
||||
925: '8 12 25',
|
||||
950: `5 9 16`,
|
||||
},
|
||||
primary: {
|
||||
100: 'var(--c-p-100,241 245 249)',
|
||||
900: 'var(--c-p-900,15 23 42)',
|
||||
},
|
||||
other: {
|
||||
black: `var(--c-o-black,0 0 0)`,
|
||||
white: `var(--c-o-white,255 255 255)`,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export let colors = writable<Colors>({
|
||||
slate: {},
|
||||
zinc: {},
|
||||
primary: {},
|
||||
other: {},
|
||||
export function getDefaultTheme(): Theme {
|
||||
return {
|
||||
id: 0,
|
||||
colors: getDefaultColors(),
|
||||
name: 'Default',
|
||||
}
|
||||
}
|
||||
|
||||
export function hexToRgb(value: string) {
|
||||
// Regular expression to match valid hex color codes
|
||||
const hexRegex = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
|
||||
|
||||
if (!hexRegex.test(value)) {
|
||||
return value // Not a valid hex color
|
||||
}
|
||||
|
||||
// Remove # if present
|
||||
let hex = value.replace('#', '')
|
||||
|
||||
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
||||
if (hex.length === 3) {
|
||||
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
|
||||
}
|
||||
|
||||
// Convert to RGB values
|
||||
const r = parseInt(hex.substring(0, 2), 16)
|
||||
const g = parseInt(hex.substring(2, 4), 16)
|
||||
const b = parseInt(hex.substring(4, 6), 16)
|
||||
|
||||
return `${r} ${g} ${b}`
|
||||
}
|
||||
|
||||
function themeStore(
|
||||
data: Writable<ThemeData>,
|
||||
fn: (
|
||||
values: ThemeData,
|
||||
set: (value: Theme) => void,
|
||||
update: (fn: Updater<Theme>) => void
|
||||
) => any
|
||||
) {
|
||||
const derive: Readable<Theme> = derived(data, fn)
|
||||
const { subscribe } = derive
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
set: (value: Theme) => {
|
||||
data.update((data) => {
|
||||
let index = data.themes.findIndex((t) => t.id == value.id)
|
||||
data.themes[index] = value
|
||||
return data
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export let themeData = writable<ThemeData>({
|
||||
scheme: 'system',
|
||||
themes: presets,
|
||||
currentTheme: 0,
|
||||
})
|
||||
|
||||
export function colorsToVars(colors: Colors): string {
|
||||
let vars: string[] = []
|
||||
for (let category in colors) {
|
||||
for (let shade in colors[category as keyof Colors]) {
|
||||
if (category)
|
||||
// @ts-ignore
|
||||
vars.push(
|
||||
`--c-${category.slice(0, 1)}-${shade}:${colors[category][shade]}`
|
||||
)
|
||||
}
|
||||
}
|
||||
return vars.join(';')
|
||||
}
|
||||
|
||||
export const colorToVar = (
|
||||
category: keyof Colors,
|
||||
shade: keyof (keyof Colors)
|
||||
): string => `--c-${category.slice(0, 2)}-${shade.toString()}`
|
||||
|
||||
function loadColors() {
|
||||
const loaded = localStorage.getItem('colors')
|
||||
if (loaded) {
|
||||
colors.set(JSON.parse(loaded))
|
||||
}
|
||||
colors.subscribe((v) => {
|
||||
localStorage.setItem('colors', JSON.stringify(v))
|
||||
})
|
||||
}
|
||||
|
||||
if (browser) {
|
||||
loadColors()
|
||||
}
|
||||
|
||||
const configuredLegacyTheme = env.PUBLIC_LEGACYTHEME ?? 'system'
|
||||
export const legacyTheme = writable<'system' | 'light' | 'dark'>(
|
||||
configuredLegacyTheme as 'system' | 'light' | 'dark'
|
||||
export let theme = themeStore(
|
||||
themeData,
|
||||
(data) =>
|
||||
data.themes.find((t) => t.id == data.currentTheme) ?? getDefaultTheme()
|
||||
)
|
||||
|
||||
export const toggleLegacyTheme = () => {
|
||||
legacyTheme.update((legacyTheme) => {
|
||||
if (legacyTheme == 'light') {
|
||||
return 'dark'
|
||||
} else if (legacyTheme == 'dark') {
|
||||
return 'system'
|
||||
} else {
|
||||
return 'light'
|
||||
export function calculateVars(theme: Theme) {
|
||||
let cssVariables = ''
|
||||
|
||||
for (const [scheme, colors] of Object.entries(theme.colors)) {
|
||||
for (const [key, value] of Object.entries(colors)) {
|
||||
cssVariables += `--c-${scheme[0]}-${key}:${hexToRgb(value)}; `
|
||||
}
|
||||
}
|
||||
|
||||
return cssVariables.trim()
|
||||
}
|
||||
|
||||
export const themeVars = derived(theme, (t) => calculateVars(t as Theme))
|
||||
|
||||
const configuredColorScheme = env.PUBLIC_COLORSCHEME ?? 'system'
|
||||
export const colorScheme = writable<ColorScheme>(
|
||||
configuredColorScheme as ColorScheme
|
||||
)
|
||||
|
||||
export const toggleColorScheme = () => {
|
||||
colorScheme.update((colorScheme) => {
|
||||
if (colorScheme == 'light') return 'dark'
|
||||
else if (colorScheme == 'dark') return 'system'
|
||||
else return 'light'
|
||||
})
|
||||
}
|
||||
|
||||
export const inDarkLegacyTheme = (): boolean => {
|
||||
export const inDarkColorScheme = (): boolean => {
|
||||
if (typeof window != 'undefined') {
|
||||
return get(legacyTheme) == 'system'
|
||||
return get(colorScheme) == 'system'
|
||||
? window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
: get(legacyTheme) == 'dark'
|
||||
: get(colorScheme) == 'dark'
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if (typeof localStorage != 'undefined') {
|
||||
const localLegacyTheme: 'system' | 'light' | 'dark' =
|
||||
(localStorage.getItem('legacyTheme') as 'system' | 'light' | 'dark') ||
|
||||
configuredLegacyTheme
|
||||
const localColorScheme: ColorScheme =
|
||||
(localStorage.getItem('colorScheme') as ColorScheme) ||
|
||||
configuredColorScheme
|
||||
|
||||
legacyTheme.update((legacyTheme) => localLegacyTheme)
|
||||
colorScheme.update((colorScheme) => localColorScheme)
|
||||
|
||||
legacyTheme.subscribe((legacyTheme) => {
|
||||
colorScheme.subscribe((colorScheme) => {
|
||||
if (typeof document != 'undefined') {
|
||||
const prefersDark = window.matchMedia(
|
||||
'(prefers-color-scheme: dark)'
|
||||
@@ -186,13 +192,13 @@ if (typeof localStorage != 'undefined') {
|
||||
|
||||
const html = document.querySelector('html')
|
||||
|
||||
if (legacyTheme == 'system') {
|
||||
if (colorScheme == 'system') {
|
||||
html?.classList.toggle('dark', prefersDark)
|
||||
} else {
|
||||
html?.classList.toggle('dark', legacyTheme === 'dark')
|
||||
html?.classList.toggle('dark', colorScheme === 'dark')
|
||||
}
|
||||
|
||||
localStorage.setItem('legacyTheme', legacyTheme)
|
||||
localStorage.setItem('colorScheme', colorScheme)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { getDefaultColors, getDefaultTheme, type Theme } from './colors'
|
||||
|
||||
export const presets: Theme[] = [
|
||||
getDefaultTheme(),
|
||||
{
|
||||
colors: {
|
||||
slate: {
|
||||
25: '#fcfdfe',
|
||||
50: '#f8fafc',
|
||||
100: '#f1f5f9',
|
||||
200: '#e2e8f0',
|
||||
300: '#cbd5e1',
|
||||
400: '#94a3b8',
|
||||
500: '#64748b',
|
||||
600: '#475569',
|
||||
700: '#334155',
|
||||
800: '#1e293b',
|
||||
900: '#0f172a',
|
||||
950: '#020617',
|
||||
},
|
||||
zinc: {
|
||||
50: '#fafafa',
|
||||
100: '#f4f4f5',
|
||||
200: '#e4e4e7',
|
||||
300: '#d4d4d8',
|
||||
400: '#a1a1aa',
|
||||
500: '#71717a',
|
||||
600: '#52525b',
|
||||
700: '#34343b',
|
||||
800: '#1f1f24',
|
||||
900: '#121215',
|
||||
925: '#0c0c0e',
|
||||
950: '#09090b',
|
||||
},
|
||||
primary: {
|
||||
100: '#f1f5f9',
|
||||
900: '#0f172a',
|
||||
},
|
||||
other: {
|
||||
black: '#000000',
|
||||
white: '#ffffff',
|
||||
},
|
||||
},
|
||||
id: -1,
|
||||
name: 'Classic',
|
||||
},
|
||||
{
|
||||
colors: {
|
||||
zinc: {
|
||||
50: '#cdd6f4',
|
||||
100: '#bac2de',
|
||||
200: '#a6adc8',
|
||||
300: '#9399b2',
|
||||
400: '#7f849c',
|
||||
500: '#6c7086',
|
||||
600: '#585b70',
|
||||
700: '#45475a',
|
||||
800: '#313244',
|
||||
900: '#1e1e2e',
|
||||
925: '#181825',
|
||||
950: '#11111b',
|
||||
},
|
||||
primary: {
|
||||
100: '#a6e3a1',
|
||||
900: '#7287fd',
|
||||
},
|
||||
other: {
|
||||
white: '#ffffff',
|
||||
},
|
||||
slate: {},
|
||||
},
|
||||
id: -2,
|
||||
name: 'Catppuccin',
|
||||
},
|
||||
]
|
||||
@@ -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}
|
||||
|
||||
+124
-15
@@ -8,25 +8,30 @@
|
||||
modal,
|
||||
toast,
|
||||
} from 'mono-svelte'
|
||||
import { defaultColors, type Colors, colors } from '$lib/ui/colors'
|
||||
import {
|
||||
ArrowDownTray,
|
||||
ArrowPath,
|
||||
ArrowUpTray,
|
||||
Bookmark,
|
||||
CheckCircle,
|
||||
Icon,
|
||||
Plus,
|
||||
} from 'svelte-hero-icons'
|
||||
import ColorSwatch from './ColorSwatch.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
|
||||
const c = defaultColors
|
||||
|
||||
const svelteIntellisenseSucks = (): (keyof Colors)[] =>
|
||||
['slate', 'zinc', 'other'] as (keyof Colors)[]
|
||||
import {
|
||||
calculateVars,
|
||||
getDefaultColors,
|
||||
hexToRgb,
|
||||
theme,
|
||||
themeData,
|
||||
} from '$lib/ui/colors'
|
||||
|
||||
let importing = false
|
||||
let importText = ''
|
||||
|
||||
$: defaultColors = getDefaultColors()
|
||||
</script>
|
||||
|
||||
{#if importing}
|
||||
@@ -37,7 +42,7 @@
|
||||
if (importText == '') {
|
||||
throw new Error('Import is empty')
|
||||
}
|
||||
$colors = JSON.parse(importText)
|
||||
$theme.colors = JSON.parse(importText)
|
||||
toast({ content: $t('message.success'), type: 'success' })
|
||||
importing = false
|
||||
} catch (err) {
|
||||
@@ -54,6 +59,70 @@
|
||||
|
||||
<div class="flex flex-col gap-4 h-full">
|
||||
<Header>Theme</Header>
|
||||
<div class="flex flex-row items-center gap-4 overflow-auto h-36">
|
||||
{#each $themeData.themes as theme}
|
||||
<button
|
||||
class="h-full"
|
||||
on:click={() => ($themeData.currentTheme = theme.id)}
|
||||
>
|
||||
<Material
|
||||
padding="none"
|
||||
class="{theme.id == $themeData.currentTheme
|
||||
? 'ring-2 ring-inset ring-primary-900 dark:ring-primary-100'
|
||||
: ''} flex relative cursor-pointer h-full flex-col text-left"
|
||||
>
|
||||
<div
|
||||
style="{calculateVars(theme)}; --bg-dark: {hexToRgb(
|
||||
theme.colors.zinc?.[925]
|
||||
)}; --bg-light: {hexToRgb(theme.colors.slate?.[25])} margin: 2px;"
|
||||
class="h-20 w-48 rounded-lg rounded-b-none flex flex-row flex-wrap p-4 gap-2
|
||||
theme-bg"
|
||||
>
|
||||
<div class="text-slate-900 dark:text-zinc-100 text-xs">
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
|
||||
</div>
|
||||
<div
|
||||
class="bg-white dark:bg-zinc-900 w-8 h-4 rounded-sm border border-slate-200 dark:border-zinc-800"
|
||||
/>
|
||||
</div>
|
||||
{#if theme.id == $themeData.currentTheme}
|
||||
<Icon
|
||||
src={CheckCircle}
|
||||
size="20"
|
||||
solid
|
||||
class="absolute top-0 right-0 m-2 text-primary-900 dark:text-primary-100"
|
||||
/>
|
||||
{/if}
|
||||
<div class="px-4 py-2">
|
||||
<span class="font-medium text-lg font-display">{theme.name}</span>
|
||||
</div>
|
||||
</Material>
|
||||
</button>
|
||||
{/each}
|
||||
<button
|
||||
on:click={() => {
|
||||
$themeData.themes = [
|
||||
...$themeData.themes,
|
||||
{
|
||||
id: Math.max(...$themeData.themes.map((t) => t.id)) + 1,
|
||||
colors: getDefaultColors(),
|
||||
name: `New Theme`,
|
||||
},
|
||||
]
|
||||
}}
|
||||
>
|
||||
<Material
|
||||
color="none"
|
||||
padding="sm"
|
||||
class="border-dashed border-2 border-slate-400 dark:border-zinc-600
|
||||
text-slate-400 dark:text-zinc-600 hover:border-slate-600 dark:hover:border-zinc-400
|
||||
grid place-items-center w-14 h-14"
|
||||
rounding="xl"
|
||||
>
|
||||
<Icon src={Plus} size="28" />
|
||||
</Material>
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<Button
|
||||
on:click={() => {
|
||||
@@ -66,7 +135,7 @@
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => {
|
||||
navigator.clipboard.writeText(JSON.stringify($colors))
|
||||
navigator.clipboard.writeText(JSON.stringify($theme.colors))
|
||||
toast({ content: 'Copied theme to clipboard.' })
|
||||
}}
|
||||
size="lg"
|
||||
@@ -84,7 +153,7 @@
|
||||
}),
|
||||
action({
|
||||
action: () => {
|
||||
$colors = { other: {}, primary: {}, zinc: {}, slate: {} }
|
||||
$theme.colors = { other: {}, primary: {}, zinc: {}, slate: {} }
|
||||
},
|
||||
content: $t('routes.theme.reset'),
|
||||
close: true,
|
||||
@@ -104,13 +173,35 @@
|
||||
<Material color="transparent" class="items-center gap-x-4 color-grid gap-y-2">
|
||||
<h1 class="text-2xl font-bold col-span-2">{$t('routes.theme.accent')}</h1>
|
||||
<ColorSwatch
|
||||
value={$theme.colors.primary?.[900]}
|
||||
on:change={(e) => {
|
||||
$theme.colors.primary[900] = e.detail
|
||||
}}
|
||||
backgroundColor={defaultColors.primary[900]}
|
||||
bind:value={$colors.primary[900]}
|
||||
on:contextmenu={(e) => {
|
||||
e.preventDefault()
|
||||
$theme.colors.primary[900] =
|
||||
// @ts-ignore
|
||||
defaultColors.primary[900]
|
||||
|
||||
return true
|
||||
}}
|
||||
class="!w-12 !h-12 col-span-1"
|
||||
/>
|
||||
<ColorSwatch
|
||||
value={$theme.colors.primary?.[100]}
|
||||
on:change={(e) => {
|
||||
$theme.colors.primary[100] = e.detail
|
||||
}}
|
||||
backgroundColor={defaultColors.primary[100]}
|
||||
bind:value={$colors.primary[100]}
|
||||
on:contextmenu={(e) => {
|
||||
e.preventDefault()
|
||||
$theme.colors.primary[100] =
|
||||
// @ts-ignore
|
||||
defaultColors.primary[100]
|
||||
|
||||
return true
|
||||
}}
|
||||
class="!w-12 !h-12 col-span-1"
|
||||
/>
|
||||
<span class="font-semibold text-base">
|
||||
@@ -121,16 +212,26 @@
|
||||
</span>
|
||||
</Material>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||
{#each svelteIntellisenseSucks() as category}
|
||||
{#each Object.entries(defaultColors) as [category, value]}
|
||||
<Material color="transparent" class="flex flex-col gap-2">
|
||||
<h1 class="capitalize font-semibold text-lg">{category}</h1>
|
||||
<div class="flex flex-row gap-1 flex-wrap items-center space-evenly">
|
||||
{#each Object.keys(c[category]) as shade}
|
||||
{#each Object.entries(value) as [shade, color]}
|
||||
<div class="flex flex-col gap-0.5 w-10 group">
|
||||
<!--@ts-ignore-->
|
||||
<ColorSwatch
|
||||
bind:value={$colors[category][shade]}
|
||||
backgroundColor={defaultColors[category][shade]}
|
||||
bind:value={$theme.colors[category][shade]}
|
||||
on:change={(e) => {
|
||||
$theme.colors[category][shade] = e.detail
|
||||
}}
|
||||
on:contextmenu={(e) => {
|
||||
e.preventDefault()
|
||||
$theme.colors[category][shade] =
|
||||
// @ts-ignore
|
||||
defaultColors[category][shade]
|
||||
|
||||
return true
|
||||
}}
|
||||
/>
|
||||
<span class="font-medium capitalize">{shade}</span>
|
||||
</div>
|
||||
@@ -159,4 +260,12 @@
|
||||
display: grid;
|
||||
grid-template-columns: min-content min-content;
|
||||
}
|
||||
|
||||
.theme-bg {
|
||||
background-color: rgb(var(--bg-light));
|
||||
}
|
||||
|
||||
.dark .theme-bg {
|
||||
background-color: rgb(var(--bg-dark));
|
||||
}
|
||||
</style>
|
||||
@@ -1,16 +1,22 @@
|
||||
<script lang="ts">
|
||||
export let backgroundColor: string = ''
|
||||
import { hexToRgb } from '$lib/ui/colors'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
|
||||
export let value: string
|
||||
|
||||
const dispatch = createEventDispatcher<{ change: string }>()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="w-full h-8 relative rounded-md border dark:border-zinc-600 hover:dark:border-zinc-400
|
||||
transition-colors {$$props.class}"
|
||||
style="background-color: {backgroundColor}"
|
||||
style="background-color: rgb({value});"
|
||||
>
|
||||
<input
|
||||
class="rounded-md border cursor-pointer absolute top-0 left-0 w-full h-full opacity-0"
|
||||
type="color"
|
||||
bind:value
|
||||
on:change={() => dispatch('change', hexToRgb(value))}
|
||||
on:contextmenu
|
||||
/>
|
||||
</div>
|
||||
+28
-28
@@ -30,39 +30,39 @@ export default {
|
||||
},
|
||||
colors: {
|
||||
slate: {
|
||||
25: 'var(--c-s-25,#fcfdfe)',
|
||||
50: `var(--c-s-50,${colors.slate[50]})`,
|
||||
100: `var(--c-s-100,${colors.slate[100]})`,
|
||||
200: `var(--c-s-200,#e8edf4)`,
|
||||
300: `var(--c-s-300,${colors.slate[300]})`,
|
||||
400: `var(--c-s-400,${colors.slate[400]})`,
|
||||
500: `var(--c-s-500,${colors.slate[500]})`,
|
||||
600: `var(--c-s-600,${colors.slate[600]})`,
|
||||
700: `var(--c-s-700,${colors.slate[700]})`,
|
||||
800: `var(--c-s-800,${colors.slate[800]})`,
|
||||
900: `var(--c-s-900,${colors.slate[900]})`,
|
||||
950: `var(--c-s-950,${colors.slate[950]})`,
|
||||
25: 'rgb(var(--c-s-25,252 253 254) / <alpha-value>)',
|
||||
50: 'rgb(var(--c-s-50,248 250 252) / <alpha-value>)',
|
||||
100: 'rgb(var(--c-s-100,241 245 249) / <alpha-value>)',
|
||||
200: 'rgb(var(--c-s-200,226 232 240) / <alpha-value>)',
|
||||
300: 'rgb(var(--c-s-300,203 213 225) / <alpha-value>)',
|
||||
400: 'rgb(var(--c-s-400,148 163 184) / <alpha-value>)',
|
||||
500: 'rgb(var(--c-s-500,100 116 139) / <alpha-value>)',
|
||||
600: 'rgb(var(--c-s-600,71 85 105) / <alpha-value>)',
|
||||
700: 'rgb(var(--c-s-700,51 65 85) / <alpha-value>)',
|
||||
800: 'rgb(var(--c-s-800,30 41 59) / <alpha-value>)',
|
||||
900: 'rgb(var(--c-s-900,15 23 42) / <alpha-value>)',
|
||||
950: 'rgb(var(--c-s-950,2 6 23) / <alpha-value>)',
|
||||
},
|
||||
zinc: {
|
||||
50: `var(--c-z-50,${colors.zinc[50]})`,
|
||||
100: `var(--c-z-100,${colors.zinc[100]})`,
|
||||
200: `var(--c-z-200,${colors.zinc[200]})`,
|
||||
300: `var(--c-z-300,${colors.zinc[300]})`,
|
||||
400: `var(--c-z-400,${colors.zinc[400]})`,
|
||||
500: `var(--c-z-500,${colors.zinc[500]})`,
|
||||
600: `var(--c-z-600,${colors.zinc[600]})`,
|
||||
700: 'var(--c-z-700,#34343b)',
|
||||
800: 'var(--c-z-800,#1f1f24)',
|
||||
900: 'var(--c-z-900,#121215)',
|
||||
925: 'var(--c-z-925,#0c0c0e)',
|
||||
950: `var(--c-z-950,${colors.zinc[950]})`,
|
||||
50: `rgb(var(--c-z-50,249 250 251) / <alpha-value>)`,
|
||||
100: `rgb(var(--c-z-100,243 244 246) / <alpha-value>)`,
|
||||
200: `rgb(var(--c-z-200,229 231 235) / <alpha-value>)`,
|
||||
300: `rgb(var(--c-z-300,209 213 219) / <alpha-value>)`,
|
||||
400: `rgb(var(--c-z-400,156 163 175) / <alpha-value>)`,
|
||||
500: `rgb(var(--c-z-500,107 114 128) / <alpha-value>)`,
|
||||
600: `rgb(var(--c-z-600,75 85 99) / <alpha-value>)`,
|
||||
700: 'rgb(var(--c-z-700,50 60 76) / <alpha-value>)',
|
||||
800: 'rgb(var(--c-z-800,22 31 45) / <alpha-value>)',
|
||||
900: 'rgb(var(--c-z-900,17 24 39) / <alpha-value>)',
|
||||
925: 'rgb(var(--c-z-925,8 12 25) / <alpha-value>)',
|
||||
950: `rgb(var(--c-z-950,5 9 16) / <alpha-value>)`,
|
||||
},
|
||||
primary: {
|
||||
100: 'var(--c-p-100,#f1f5f9)',
|
||||
900: 'var(--c-p-900,#0f172a)',
|
||||
100: 'rgb(var(--c-p-100,241 245 249) / <alpha-value>)',
|
||||
900: 'rgb(var(--c-p-900,15 23 42) / <alpha-value>)',
|
||||
},
|
||||
black: `#000`,
|
||||
white: `var(--c-o-white,#fff)`,
|
||||
black: `rgb(var(--c-o-black,0 0 0) / <alpha-value>)`,
|
||||
white: `rgb(var(--c-o-white,255 255 255) / <alpha-value>)`,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user