Merge pull request #373 from Xyphyn/new-theme-handler
feat: remake theme handling
This commit is contained in:
13 files changed
+684
-281
No files matched your search
@@ -15,7 +15,6 @@ It is designed for all features to have an appealing and intuitive design, while
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Self-hosting
|
## Self-hosting
|
||||||
|
|
||||||
Put Photon on your own domain for easier onboarding.
|
Put Photon on your own domain for easier onboarding.
|
||||||
@@ -66,7 +65,8 @@ These are the most important environment variables that you can change:
|
|||||||
| PUBLIC_FAVICON | URL | `/img/logo-background.svg |
|
| PUBLIC_FAVICON | URL | `/img/logo-background.svg |
|
||||||
| PUBLIC_SSR_ENABLED | `bool` | `false` |
|
| PUBLIC_SSR_ENABLED | `bool` | `false` |
|
||||||
| PUBLIC_MIGRATE_COOKIE | `bool` | `false` |
|
| PUBLIC_MIGRATE_COOKIE | `bool` | `false` |
|
||||||
| PUBLIC_THEME | system\|dark\|light | system |
|
| PUBLIC_THEME | JSON | Photon's default colors |
|
||||||
|
| PUBLIC_COLORSCHEME | system\|dark\|light | system |
|
||||||
| PUBLIC_EXPANDABLE_IMAGES | `bool` | true |
|
| PUBLIC_EXPANDABLE_IMAGES | `bool` | true |
|
||||||
| PUBLIC_MARK_READ_POSTS | `bool` | true |
|
| PUBLIC_MARK_READ_POSTS | `bool` | true |
|
||||||
| PUBLIC_DEFAULT_FEED_SORT | `SortType` | Active |
|
| PUBLIC_DEFAULT_FEED_SORT | `SortType` | Active |
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Color } from '$lib/ui/colors'
|
|
||||||
import {
|
import {
|
||||||
ArrowDownCircle,
|
ArrowDownCircle,
|
||||||
ArrowUp,
|
ArrowUp,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
top: boolean | null
|
top: boolean | null
|
||||||
noGap: boolean | null
|
noGap: boolean | null
|
||||||
},
|
},
|
||||||
screenWidth: number,
|
screenWidth: number
|
||||||
): {
|
): {
|
||||||
noGap: boolean
|
noGap: boolean
|
||||||
top: boolean
|
top: boolean
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
export const calculatePadding = (
|
export const calculatePadding = (
|
||||||
panel: boolean,
|
panel: boolean,
|
||||||
top: boolean,
|
top: boolean,
|
||||||
content: boolean,
|
content: boolean
|
||||||
): {
|
): {
|
||||||
top: number
|
top: number
|
||||||
class: string
|
class: string
|
||||||
@@ -62,13 +62,13 @@
|
|||||||
})
|
})
|
||||||
export let contentPadding: Readable<ReturnType<typeof calculatePadding>> =
|
export let contentPadding: Readable<ReturnType<typeof calculatePadding>> =
|
||||||
derived(dockProps, ($dockProps, set) =>
|
derived(dockProps, ($dockProps, set) =>
|
||||||
set(calculatePadding($dockProps.noGap, $dockProps.top, true)),
|
set(calculatePadding($dockProps.noGap, $dockProps.top, true))
|
||||||
)
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { userSettings } from '$lib/settings.js'
|
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 { routes } from '$lib/util.js'
|
||||||
import { derived, writable, type Readable, type Writable } from 'svelte/store'
|
import { derived, writable, type Readable, type Writable } from 'svelte/store'
|
||||||
|
|
||||||
@@ -84,8 +84,8 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
class="shell {$$props.class}"
|
class="shell bg-slate-50 dark:bg-zinc-950 {$$props.class}"
|
||||||
style={colorsToVars($colors)}
|
style={$themeVars}
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
<div
|
<div
|
||||||
@@ -109,10 +109,10 @@
|
|||||||
: 'border rounded-full'}
|
: 'border rounded-full'}
|
||||||
|
|
||||||
dark:bg-transparent transition-colors duration-500
|
dark:bg-transparent transition-colors duration-500
|
||||||
pointer-events-auto {topPanel
|
pointer-events-auto backdrop-blur-xl {topPanel
|
||||||
? 'bg-slate-50 dark:bg-zinc-950 border-slate-100 dark:border-zinc-900'
|
? 'bg-slate-50/50 dark:bg-zinc-950/90 border-slate-100 dark:border-zinc-900'
|
||||||
: `border-slate-200 dark:border-zinc-800 shadow-2xl backdrop-blur-xl
|
: `border-slate-200 dark:border-zinc-800 shadow-2xl
|
||||||
dark:backdrop-brightness-[25%] bg-[#ffffff]/75`}"
|
bg-white/50 dark:bg-zinc-925/70`}"
|
||||||
{title}
|
{title}
|
||||||
style="transition: border-radius 250ms;"
|
style="transition: border-radius 250ms;"
|
||||||
/>
|
/>
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
>
|
>
|
||||||
<slot
|
<slot
|
||||||
name="sidebar"
|
name="sidebar"
|
||||||
class="hidden md:flex sticky top-0 left-0 max-w-full h-max bg-slate-50 dark:bg-zinc-950
|
class="hidden md:flex sticky top-0 left-0 h-max bg-slate-50 dark:bg-zinc-950
|
||||||
z-40
|
z-40
|
||||||
{sidePadding.class}"
|
{sidePadding.class}"
|
||||||
style="grid-area: sidebar; width: 100% !important;"
|
style="grid-area: sidebar; width: 100% !important;"
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
<slot
|
<slot
|
||||||
name="main"
|
name="main"
|
||||||
class="w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
|
class="w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
|
||||||
{$contentPadding.class}"
|
{$contentPadding.class} main"
|
||||||
style="grid-area: main"
|
style="grid-area: main"
|
||||||
/>
|
/>
|
||||||
<slot
|
<slot
|
||||||
@@ -163,6 +163,11 @@
|
|||||||
grid-template-areas: 'main';
|
grid-template-areas: 'main';
|
||||||
justify-items: start;
|
justify-items: start;
|
||||||
}
|
}
|
||||||
|
.content > * {
|
||||||
|
width: 100%; /* Full width for immediate children */
|
||||||
|
max-width: 100rem; /* Limit width */
|
||||||
|
padding: 0 1rem; /* Add some padding on smaller screens */
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
.content {
|
.content {
|
||||||
@@ -174,13 +179,25 @@
|
|||||||
|
|
||||||
@media (min-width: 1280px) {
|
@media (min-width: 1280px) {
|
||||||
.content {
|
.content {
|
||||||
grid-template-columns: 20% 1fr 20%;
|
grid-template-columns: 20% 60% 20%;
|
||||||
justify-items: end center start;
|
justify-items: end center start;
|
||||||
grid-template-areas: 'sidebar main suffix';
|
grid-template-areas: 'sidebar main suffix';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.limit-width {
|
.content:is(.limit-width) {
|
||||||
max-width: 100rem;
|
grid-template-columns: 1fr 2fr 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.content:is(.limit-width) > *:first-child) {
|
||||||
|
max-width: 20rem;
|
||||||
|
justify-self: end;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.content:is(.limit-width) > *:last-child) {
|
||||||
|
max-width: 20rem;
|
||||||
|
justify-self: start;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
UserCircle,
|
UserCircle,
|
||||||
UserGroup,
|
UserGroup,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { legacyTheme } from '$lib/ui/colors'
|
import { colorScheme } from '$lib/ui/colors'
|
||||||
import { userSettings } from '$lib/settings'
|
import { userSettings } from '$lib/settings'
|
||||||
import { site } from '$lib/lemmy'
|
import { site } from '$lib/lemmy'
|
||||||
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
||||||
@@ -127,11 +127,11 @@
|
|||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuButton class="!py-0">
|
<MenuButton class="!py-0">
|
||||||
<Icon
|
<Icon
|
||||||
src={$legacyTheme == 'system'
|
src={$colorScheme == 'system'
|
||||||
? ComputerDesktop
|
? ComputerDesktop
|
||||||
: $legacyTheme == 'light'
|
: $colorScheme == 'light'
|
||||||
? Sun
|
? Sun
|
||||||
: $legacyTheme == 'dark'
|
: $colorScheme == 'dark'
|
||||||
? Moon
|
? Moon
|
||||||
: Moon}
|
: Moon}
|
||||||
mini
|
mini
|
||||||
@@ -142,7 +142,7 @@
|
|||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
<div class="contents" on:click|stopPropagation={() => {}}>
|
<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="system">{$t('nav.menu.colorscheme.system')}</option>
|
||||||
<option value="light">{$t('nav.menu.colorscheme.light')}</option>
|
<option value="light">{$t('nav.menu.colorscheme.light')}</option>
|
||||||
<option value="dark">{$t('nav.menu.colorscheme.dark')}</option>
|
<option value="dark">{$t('nav.menu.colorscheme.dark')}</option>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { resumables, type ResumableItem } from '$lib/lemmy/item'
|
import { resumables, type ResumableItem } from '$lib/lemmy/item'
|
||||||
import { userSettings } from '$lib/settings'
|
import { userSettings } from '$lib/settings'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { legacyTheme } from '$lib/ui/colors'
|
import { colorScheme } from '$lib/ui/colors'
|
||||||
import { fullCommunityName } from '$lib/util'
|
import { fullCommunityName } from '$lib/util'
|
||||||
import {
|
import {
|
||||||
ArrowRightOnRectangle,
|
ArrowRightOnRectangle,
|
||||||
@@ -354,21 +354,21 @@ export function getGroups(
|
|||||||
name: t.get('nav.commands.setColorTo', {
|
name: t.get('nav.commands.setColorTo', {
|
||||||
default: t.get('nav.menu.colorscheme.system'),
|
default: t.get('nav.menu.colorscheme.system'),
|
||||||
}),
|
}),
|
||||||
handle: () => legacyTheme.set('system'),
|
handle: () => colorScheme.set('system'),
|
||||||
icon: ComputerDesktop,
|
icon: ComputerDesktop,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: t.get('nav.commands.setColorTo', {
|
name: t.get('nav.commands.setColorTo', {
|
||||||
default: t.get('nav.menu.colorscheme.light'),
|
default: t.get('nav.menu.colorscheme.light'),
|
||||||
}),
|
}),
|
||||||
handle: () => legacyTheme.set('light'),
|
handle: () => colorScheme.set('light'),
|
||||||
icon: Sun,
|
icon: Sun,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: t.get('nav.commands.setColorTo', {
|
name: t.get('nav.commands.setColorTo', {
|
||||||
default: t.get('nav.menu.colorscheme.dark'),
|
default: t.get('nav.menu.colorscheme.dark'),
|
||||||
}),
|
}),
|
||||||
handle: () => legacyTheme.set('dark'),
|
handle: () => colorScheme.set('dark'),
|
||||||
icon: Moon,
|
icon: Moon,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -359,6 +359,18 @@
|
|||||||
"resetWarning": {
|
"resetWarning": {
|
||||||
"title": "Reset Theme",
|
"title": "Reset Theme",
|
||||||
"description": "This will reset all of your colors to the default. It is recommended to export your theme before this."
|
"description": "This will reset all of your colors to the default. It is recommended to export your theme before this."
|
||||||
|
},
|
||||||
|
"preset": {
|
||||||
|
"title": "Can't be modified",
|
||||||
|
"description": "This is a default theme, and can't be modified.",
|
||||||
|
"delete": {
|
||||||
|
"title": "Delete Theme",
|
||||||
|
"confirm": "Confirm"
|
||||||
|
},
|
||||||
|
"default": "Default",
|
||||||
|
"classic": "Classic",
|
||||||
|
"imported": "Your Theme",
|
||||||
|
"new": "New Theme"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"community": {
|
"community": {
|
||||||
|
|||||||
+181
-150
@@ -1,184 +1,178 @@
|
|||||||
/**
|
import {
|
||||||
* This enum represents a UI color as tailwind classes.
|
derived,
|
||||||
*/
|
get,
|
||||||
|
writable,
|
||||||
export enum Color {
|
type Stores,
|
||||||
'accent' = 'border border-black dark:border-white bg-black text-white\
|
type Updater,
|
||||||
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',
|
type Unsubscriber,
|
||||||
'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',
|
type Writable,
|
||||||
'secondary' = 'hover:bg-black/10 hover:dark:bg-white/10 text-black dark:text-white fill-black dark:fill-white',
|
type Readable,
|
||||||
'danger' = 'border border-red-500 bg-red-500 text-white hover:text-red-500 hover:bg-transparent',
|
} from 'svelte/store'
|
||||||
'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 { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
|
import { getDefaultTheme, presets } from './presets'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
|
||||||
interface ColorData {
|
type ColorScheme = 'system' | 'light' | 'dark'
|
||||||
theme: number
|
|
||||||
themes: Colors[]
|
export interface ThemeData {
|
||||||
|
scheme: ColorScheme
|
||||||
|
themes: Theme[]
|
||||||
|
currentTheme: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Theme {
|
export interface Theme {
|
||||||
colors: Colors
|
|
||||||
name: string
|
|
||||||
id: number
|
id: number
|
||||||
|
colors: ThemeColors
|
||||||
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Colors {
|
export interface ThemeColors {
|
||||||
slate: {
|
[scheme: string]: {
|
||||||
25?: string
|
[key: string]: 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultColors = {
|
export function hexToRgb(value: string) {
|
||||||
slate: {
|
// Regular expression to match valid hex color codes
|
||||||
25: `var(--c-s-25,#fcfdfe)`,
|
const hexRegex = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
|
||||||
50: `var(--c-s-50,#f8fafc)`,
|
|
||||||
100: `var(--c-s-100,#f1f5f9)`,
|
if (!hexRegex.test(value)) {
|
||||||
200: `var(--c-s-200,#e2e8f0)`,
|
return value // Not a valid hex color
|
||||||
300: `var(--c-s-300,#cbd5e1)`,
|
}
|
||||||
400: `var(--c-s-400,#94a3b8)`,
|
|
||||||
500: `var(--c-s-500,#64748b)`,
|
// Remove # if present
|
||||||
600: `var(--c-s-600,#475569)`,
|
let hex = value.replace('#', '')
|
||||||
700: `var(--c-s-700,#334155)`,
|
|
||||||
800: `var(--c-s-800,#1e293b)`,
|
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
||||||
900: `var(--c-s-900,#0f172a`,
|
if (hex.length === 3) {
|
||||||
950: `var(--c-s-950,#020617)`,
|
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
|
||||||
},
|
}
|
||||||
zinc: {
|
|
||||||
50: `var(--c-z-50,#fafafa)`,
|
// Convert to RGB values
|
||||||
100: `var(--c-z-100,#f4f4f5)`,
|
const r = parseInt(hex.substring(0, 2), 16)
|
||||||
200: `var(--c-z-200,#e4e4e7)`,
|
const g = parseInt(hex.substring(2, 4), 16)
|
||||||
300: `var(--c-z-300,#d4d4d8)`,
|
const b = parseInt(hex.substring(4, 6), 16)
|
||||||
400: `var(--c-z-400,#a1a1aa)`,
|
|
||||||
500: `var(--c-z-500,#71717a)`,
|
return `${r} ${g} ${b}`
|
||||||
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 let colors = writable<Colors>({
|
export function rgbToHex(rgbString: string): string {
|
||||||
slate: {},
|
const rgb = rgbString.split(' ')
|
||||||
zinc: {},
|
|
||||||
primary: {},
|
|
||||||
other: {},
|
|
||||||
})
|
|
||||||
|
|
||||||
export function colorsToVars(colors: Colors): string {
|
if (rgb.length !== 3) {
|
||||||
let vars: string[] = []
|
return rgbString
|
||||||
for (let category in colors) {
|
}
|
||||||
for (let shade in colors[category as keyof Colors]) {
|
|
||||||
if (category)
|
const [r, g, b] = rgb.map((val) => {
|
||||||
// @ts-ignore
|
const num = parseInt(val, 10)
|
||||||
vars.push(
|
if (isNaN(num) || num < 0 || num > 255) {
|
||||||
`--c-${category.slice(0, 1)}-${shade}:${colors[category][shade]}`
|
return 0
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
return num
|
||||||
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))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 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)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (browser) {
|
function themeStore(
|
||||||
loadColors()
|
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
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const configuredLegacyTheme = env.PUBLIC_LEGACYTHEME ?? 'system'
|
export let themeData = writable<ThemeData>(
|
||||||
export const legacyTheme = writable<'system' | 'light' | 'dark'>(
|
loadTheme() ?? {
|
||||||
configuredLegacyTheme as 'system' | 'light' | 'dark'
|
scheme: 'system',
|
||||||
|
themes: presets,
|
||||||
|
currentTheme: 0,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export const toggleLegacyTheme = () => {
|
themeData.subscribe((themeData) => {
|
||||||
legacyTheme.update((legacyTheme) => {
|
if (browser) {
|
||||||
if (legacyTheme == 'light') {
|
const filteredThemes = themeData.themes.filter((t) => t.id > 0)
|
||||||
return 'dark'
|
localStorage.setItem(
|
||||||
} else if (legacyTheme == 'dark') {
|
'themeData',
|
||||||
return 'system'
|
JSON.stringify({
|
||||||
} else {
|
...themeData,
|
||||||
return 'light'
|
themes: filteredThemes,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export let theme = themeStore(
|
||||||
|
themeData,
|
||||||
|
(data) =>
|
||||||
|
data.themes.find((t) => t.id == data.currentTheme) ?? getDefaultTheme()
|
||||||
|
)
|
||||||
|
|
||||||
|
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') {
|
if (typeof window != 'undefined') {
|
||||||
return get(legacyTheme) == 'system'
|
return get(colorScheme) == 'system'
|
||||||
? window.matchMedia('(prefers-color-scheme: dark)').matches
|
? window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||||
: get(legacyTheme) == 'dark'
|
: get(colorScheme) == 'dark'
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof localStorage != 'undefined') {
|
function loadColorScheme() {
|
||||||
const localLegacyTheme: 'system' | 'light' | 'dark' =
|
const localColorScheme: ColorScheme =
|
||||||
(localStorage.getItem('legacyTheme') as 'system' | 'light' | 'dark') ||
|
(localStorage.getItem('colorScheme') as ColorScheme) ||
|
||||||
configuredLegacyTheme
|
configuredColorScheme
|
||||||
|
|
||||||
legacyTheme.update((legacyTheme) => localLegacyTheme)
|
colorScheme.update((colorScheme) => localColorScheme)
|
||||||
|
|
||||||
legacyTheme.subscribe((legacyTheme) => {
|
colorScheme.subscribe((colorScheme) => {
|
||||||
if (typeof document != 'undefined') {
|
if (typeof document != 'undefined') {
|
||||||
const prefersDark = window.matchMedia(
|
const prefersDark = window.matchMedia(
|
||||||
'(prefers-color-scheme: dark)'
|
'(prefers-color-scheme: dark)'
|
||||||
@@ -186,13 +180,50 @@ if (typeof localStorage != 'undefined') {
|
|||||||
|
|
||||||
const html = document.querySelector('html')
|
const html = document.querySelector('html')
|
||||||
|
|
||||||
if (legacyTheme == 'system') {
|
if (colorScheme == 'system') {
|
||||||
html?.classList.toggle('dark', prefersDark)
|
html?.classList.toggle('dark', prefersDark)
|
||||||
} else {
|
} else {
|
||||||
html?.classList.toggle('dark', legacyTheme === 'dark')
|
html?.classList.toggle('dark', colorScheme === 'dark')
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorage.setItem('legacyTheme', legacyTheme)
|
localStorage.setItem('colorScheme', colorScheme)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadTheme() {
|
||||||
|
if (!browser) return
|
||||||
|
const localTheme = localStorage.getItem('themeData')
|
||||||
|
|
||||||
|
if (localTheme) {
|
||||||
|
const data = JSON.parse(localTheme)
|
||||||
|
if (!data) return
|
||||||
|
data.themes = [...presets, ...data.themes]
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (browser) {
|
||||||
|
try {
|
||||||
|
loadColorScheme()
|
||||||
|
} catch (e) {}
|
||||||
|
try {
|
||||||
|
const oldColors = localStorage.getItem('colors')
|
||||||
|
if (oldColors) {
|
||||||
|
themeData.update((td) => ({
|
||||||
|
...td,
|
||||||
|
themes: [
|
||||||
|
...td.themes,
|
||||||
|
{
|
||||||
|
id: Math.max(...td.themes.map((t) => t.id)) + 1,
|
||||||
|
colors: JSON.parse(oldColors),
|
||||||
|
name: t.get('routes.theme.preset.imported') ?? 'Your Theme',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}))
|
||||||
|
localStorage.removeItem('colors')
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
import { env } from '$env/dynamic/public'
|
||||||
|
import type { Theme, ThemeColors } from './colors'
|
||||||
|
|
||||||
|
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: '250 253 255',
|
||||||
|
100: '243 244 246',
|
||||||
|
300: '209 213 219',
|
||||||
|
400: '156 163 175',
|
||||||
|
500: '107 114 128',
|
||||||
|
600: '75 85 99',
|
||||||
|
700: '55 65 81',
|
||||||
|
800: '22 31 45',
|
||||||
|
900: '12 18 32',
|
||||||
|
925: '8 12 25',
|
||||||
|
950: '3 7 18',
|
||||||
|
},
|
||||||
|
primary: {
|
||||||
|
100: '241 245 249',
|
||||||
|
900: '15 23 42',
|
||||||
|
},
|
||||||
|
other: {
|
||||||
|
black: `0 0 0`,
|
||||||
|
white: `255 255 255`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDefaultTheme(): Theme {
|
||||||
|
return {
|
||||||
|
id: 0,
|
||||||
|
colors: getDefaultColors(),
|
||||||
|
name: 'Default',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const presets: Theme[] = [
|
||||||
|
getDefaultTheme(),
|
||||||
|
{
|
||||||
|
colors: {
|
||||||
|
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: '250 250 250',
|
||||||
|
100: '244 244 245',
|
||||||
|
200: '228 228 231',
|
||||||
|
300: '212 212 216',
|
||||||
|
400: '161 161 170',
|
||||||
|
500: '113 113 122',
|
||||||
|
600: '82 82 91',
|
||||||
|
700: '52 52 59',
|
||||||
|
800: '31 31 36',
|
||||||
|
900: '18 18 21',
|
||||||
|
925: '12 12 14',
|
||||||
|
950: '9 9 11',
|
||||||
|
},
|
||||||
|
primary: {
|
||||||
|
100: '241 245 249',
|
||||||
|
900: '15 23 42',
|
||||||
|
},
|
||||||
|
other: {
|
||||||
|
black: '0 0 0',
|
||||||
|
white: '255 255 255',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
id: -1,
|
||||||
|
name: 'Classic',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
colors: {
|
||||||
|
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: '30 30 30',
|
||||||
|
800: '22 22 22',
|
||||||
|
900: '10 10 10',
|
||||||
|
925: '0 0 0',
|
||||||
|
950: `0 0 0`,
|
||||||
|
},
|
||||||
|
primary: {
|
||||||
|
100: '241 245 249',
|
||||||
|
900: '15 23 42',
|
||||||
|
},
|
||||||
|
other: {
|
||||||
|
black: `0 0 0`,
|
||||||
|
white: `255 255 255`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
id: -2,
|
||||||
|
name: 'AMOLED',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
colors: {
|
||||||
|
zinc: {
|
||||||
|
50: '205 214 244',
|
||||||
|
100: '186 194 222',
|
||||||
|
200: '166 173 200',
|
||||||
|
300: '147 153 178',
|
||||||
|
400: '127 132 156',
|
||||||
|
500: '108 112 134',
|
||||||
|
600: '88 91 112',
|
||||||
|
700: '69 71 90',
|
||||||
|
800: '49 50 68',
|
||||||
|
900: '30 30 46',
|
||||||
|
925: '24 24 37',
|
||||||
|
950: '17 17 27',
|
||||||
|
},
|
||||||
|
primary: {
|
||||||
|
100: '166 227 161',
|
||||||
|
900: '114 135 253',
|
||||||
|
},
|
||||||
|
other: {
|
||||||
|
white: '255 255 255',
|
||||||
|
},
|
||||||
|
slate: {},
|
||||||
|
},
|
||||||
|
id: -3,
|
||||||
|
name: 'Catppuccin',
|
||||||
|
},
|
||||||
|
]
|
||||||
+18
-27
@@ -9,12 +9,11 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { pwaInfo } from 'virtual:pwa-info'
|
import { pwaInfo } from 'virtual:pwa-info'
|
||||||
import {
|
import {
|
||||||
colors,
|
colorScheme,
|
||||||
colorsToVars,
|
inDarkColorScheme,
|
||||||
defaultColors,
|
rgbToHex,
|
||||||
inDarkLegacyTheme,
|
theme,
|
||||||
legacyTheme,
|
themeVars,
|
||||||
type Colors,
|
|
||||||
} from '$lib/ui/colors.js'
|
} from '$lib/ui/colors.js'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
|
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
|
||||||
@@ -28,6 +27,7 @@
|
|||||||
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
||||||
import { LINKED_INSTANCE_URL } from '$lib/instance'
|
import { LINKED_INSTANCE_URL } from '$lib/instance'
|
||||||
import { locale } from '$lib/translations'
|
import { locale } from '$lib/translations'
|
||||||
|
import { getDefaultColors } from '$lib/ui/presets'
|
||||||
|
|
||||||
nProgress.configure({
|
nProgress.configure({
|
||||||
minimum: 0.4,
|
minimum: 0.4,
|
||||||
@@ -51,7 +51,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : ''
|
$: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : ''
|
||||||
$: darklegacyTheme = $legacyTheme && inDarkLegacyTheme()
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (browser) {
|
if (browser) {
|
||||||
@@ -59,37 +58,29 @@
|
|||||||
history.replaceState(
|
history.replaceState(
|
||||||
null,
|
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')
|
document.body.querySelector('.loader')?.classList.add('hidden')
|
||||||
|
themeVars.subscribe((vars) => {
|
||||||
|
document.body.setAttribute('style', vars)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$: title = routes[($page.route.id as keyof typeof routes) ?? '']
|
$: 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>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<meta name="theme-color" content={themeColor} />
|
|
||||||
{#if $site?.site_view}
|
{#if $site?.site_view}
|
||||||
<title>{$site?.site_view.site.name}</title>
|
<title>{$site?.site_view.site.name}</title>
|
||||||
|
<meta
|
||||||
|
name="theme-color"
|
||||||
|
content={rgbToHex(
|
||||||
|
$colorScheme && inDarkColorScheme()
|
||||||
|
? $theme.colors.zinc?.[925] ?? getDefaultColors().zinc[925]
|
||||||
|
: $theme.colors.slate?.[25] ?? getDefaultColors().slate[25]
|
||||||
|
)}
|
||||||
|
/>
|
||||||
{#if LINKED_INSTANCE_URL}
|
{#if LINKED_INSTANCE_URL}
|
||||||
<link rel="icon" href={$site?.site_view?.site.icon} />
|
<link rel="icon" href={$site?.site_view?.site.icon} />
|
||||||
<meta name="description" content={$site?.site_view?.site.description} />
|
<meta name="description" content={$site?.site_view?.site.description} />
|
||||||
|
|||||||
+128
-46
@@ -3,30 +3,32 @@
|
|||||||
Button,
|
Button,
|
||||||
Material,
|
Material,
|
||||||
Modal,
|
Modal,
|
||||||
|
Note,
|
||||||
TextArea,
|
TextArea,
|
||||||
action,
|
action,
|
||||||
modal,
|
modal,
|
||||||
toast,
|
toast,
|
||||||
} from 'mono-svelte'
|
} from 'mono-svelte'
|
||||||
import { defaultColors, type Colors, colors } from '$lib/ui/colors'
|
|
||||||
import {
|
import {
|
||||||
ArrowDownTray,
|
ArrowDownTray,
|
||||||
ArrowPath,
|
ArrowPath,
|
||||||
ArrowUpTray,
|
ArrowUpTray,
|
||||||
Bookmark,
|
Bookmark,
|
||||||
|
CheckCircle,
|
||||||
Icon,
|
Icon,
|
||||||
|
Plus,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import ColorSwatch from './ColorSwatch.svelte'
|
import ColorSwatch from './ColorSwatch.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import { calculateVars, hexToRgb, theme, themeData } from '$lib/ui/colors'
|
||||||
const c = defaultColors
|
import { getDefaultColors } from '$lib/ui/presets'
|
||||||
|
import ThemePreset from './ThemePreset.svelte'
|
||||||
const svelteIntellisenseSucks = (): (keyof Colors)[] =>
|
|
||||||
['slate', 'zinc', 'other'] as (keyof Colors)[]
|
|
||||||
|
|
||||||
let importing = false
|
let importing = false
|
||||||
let importText = ''
|
let importText = ''
|
||||||
|
|
||||||
|
$: defaultColors = getDefaultColors()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if importing}
|
{#if importing}
|
||||||
@@ -37,7 +39,7 @@
|
|||||||
if (importText == '') {
|
if (importText == '') {
|
||||||
throw new Error('Import is empty')
|
throw new Error('Import is empty')
|
||||||
}
|
}
|
||||||
$colors = JSON.parse(importText)
|
$theme.colors = JSON.parse(importText)
|
||||||
toast({ content: $t('message.success'), type: 'success' })
|
toast({ content: $t('message.success'), type: 'success' })
|
||||||
importing = false
|
importing = false
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -54,19 +56,52 @@
|
|||||||
|
|
||||||
<div class="flex flex-col gap-4 h-full">
|
<div class="flex flex-col gap-4 h-full">
|
||||||
<Header>Theme</Header>
|
<Header>Theme</Header>
|
||||||
|
<div
|
||||||
|
class="grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-4
|
||||||
|
gap-4 overflow-auto max-h-72"
|
||||||
|
>
|
||||||
|
{#each $themeData.themes as theme}
|
||||||
|
<ThemePreset bind:theme />
|
||||||
|
{/each}
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
const newTheme = {
|
||||||
|
id: Math.max(...$themeData.themes.map((t) => t.id)) + 1,
|
||||||
|
colors: getDefaultColors(),
|
||||||
|
name: $t('routes.theme.preset.new'),
|
||||||
|
}
|
||||||
|
|
||||||
|
$themeData.themes = [...$themeData.themes, newTheme]
|
||||||
|
|
||||||
|
$themeData.currentTheme = newTheme.id
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<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">
|
<div class="flex items-center gap-4">
|
||||||
<Button
|
<Button
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
importing = !importing
|
importing = !importing
|
||||||
}}
|
}}
|
||||||
size="lg"
|
size="lg"
|
||||||
|
disabled={$theme.id <= 0}
|
||||||
>
|
>
|
||||||
<Icon src={ArrowUpTray} size="16" mini />
|
<Icon src={ArrowUpTray} size="16" mini />
|
||||||
{$t('routes.theme.import')}
|
{$t('routes.theme.import')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
navigator.clipboard.writeText(JSON.stringify($colors))
|
navigator.clipboard.writeText(JSON.stringify($theme.colors))
|
||||||
toast({ content: 'Copied theme to clipboard.' })
|
toast({ content: 'Copied theme to clipboard.' })
|
||||||
}}
|
}}
|
||||||
size="lg"
|
size="lg"
|
||||||
@@ -75,6 +110,7 @@
|
|||||||
{$t('routes.theme.export')}
|
{$t('routes.theme.export')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
disabled={$theme.id <= 0}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
modal({
|
modal({
|
||||||
actions: [
|
actions: [
|
||||||
@@ -84,7 +120,7 @@
|
|||||||
}),
|
}),
|
||||||
action({
|
action({
|
||||||
action: () => {
|
action: () => {
|
||||||
$colors = { other: {}, primary: {}, zinc: {}, slate: {} }
|
$theme.colors = { other: {}, primary: {}, zinc: {}, slate: {} }
|
||||||
},
|
},
|
||||||
content: $t('routes.theme.reset'),
|
content: $t('routes.theme.reset'),
|
||||||
close: true,
|
close: true,
|
||||||
@@ -101,43 +137,89 @@
|
|||||||
{$t('routes.theme.reset')}
|
{$t('routes.theme.reset')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<Material color="transparent" class="items-center gap-x-4 color-grid gap-y-2">
|
{#if $theme.id <= 0}
|
||||||
<h1 class="text-2xl font-bold col-span-2">{$t('routes.theme.accent')}</h1>
|
<Note>
|
||||||
<ColorSwatch
|
{$t('routes.theme.preset.description')}
|
||||||
backgroundColor={defaultColors.primary[900]}
|
</Note>
|
||||||
bind:value={$colors.primary[900]}
|
{/if}
|
||||||
class="!w-12 !h-12 col-span-1"
|
<div
|
||||||
/>
|
class="relative"
|
||||||
<ColorSwatch
|
class:opacity-50={$theme.id <= 0}
|
||||||
backgroundColor={defaultColors.primary[100]}
|
class:pointer-events-none={$theme.id <= 0}
|
||||||
bind:value={$colors.primary[100]}
|
>
|
||||||
class="!w-12 !h-12 col-span-1"
|
<Material
|
||||||
/>
|
color="transparent"
|
||||||
<span class="font-semibold text-base">
|
class="items-center gap-x-4 color-grid gap-y-2"
|
||||||
{$t('nav.menu.colorscheme.light')}
|
>
|
||||||
</span>
|
<h1 class="text-2xl font-bold col-span-2">{$t('routes.theme.accent')}</h1>
|
||||||
<span class="font-semibold text-base">
|
<ColorSwatch
|
||||||
{$t('nav.menu.colorscheme.dark')}
|
value={$theme.colors.primary?.[900]}
|
||||||
</span>
|
on:change={(e) => {
|
||||||
</Material>
|
$theme.colors.primary[900] = e.detail
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
}}
|
||||||
{#each svelteIntellisenseSucks() as category}
|
backgroundColor={defaultColors.primary[900]}
|
||||||
<Material color="transparent" class="flex flex-col gap-2">
|
on:contextmenu={(e) => {
|
||||||
<h1 class="capitalize font-semibold text-lg">{category}</h1>
|
e.preventDefault()
|
||||||
<div class="flex flex-row gap-1 flex-wrap items-center space-evenly">
|
$theme.colors.primary[900] =
|
||||||
{#each Object.keys(c[category]) as shade}
|
// @ts-ignore
|
||||||
<div class="flex flex-col gap-0.5 w-10 group">
|
defaultColors.primary[900]
|
||||||
<!--@ts-ignore-->
|
|
||||||
<ColorSwatch
|
return true
|
||||||
bind:value={$colors[category][shade]}
|
}}
|
||||||
backgroundColor={defaultColors[category][shade]}
|
class="!w-12 !h-12 col-span-1"
|
||||||
/>
|
/>
|
||||||
<span class="font-medium capitalize">{shade}</span>
|
<ColorSwatch
|
||||||
</div>
|
value={$theme.colors.primary?.[100]}
|
||||||
{/each}
|
on:change={(e) => {
|
||||||
</div>
|
$theme.colors.primary[100] = e.detail
|
||||||
</Material>
|
}}
|
||||||
{/each}
|
backgroundColor={defaultColors.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">
|
||||||
|
{$t('nav.menu.colorscheme.light')}
|
||||||
|
</span>
|
||||||
|
<span class="font-semibold text-base">
|
||||||
|
{$t('nav.menu.colorscheme.dark')}
|
||||||
|
</span>
|
||||||
|
</Material>
|
||||||
|
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||||
|
{#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.entries(value) as [shade, color]}
|
||||||
|
<div class="flex flex-col gap-0.5 w-10 group">
|
||||||
|
<!--@ts-ignore-->
|
||||||
|
<ColorSwatch
|
||||||
|
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>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</Material>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="flex items-center gap-2 sm:gap-8 flex-col sm:flex-row mt-auto mx-auto text-sm text-slate-600 dark:text-zinc-400"
|
class="flex items-center gap-2 sm:gap-8 flex-col sm:flex-row mt-auto mx-auto text-sm text-slate-600 dark:text-zinc-400"
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let backgroundColor: string = ''
|
import { hexToRgb } from '$lib/ui/colors'
|
||||||
|
import { createEventDispatcher } from 'svelte'
|
||||||
|
|
||||||
export let value: string
|
export let value: string
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher<{ change: string }>()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="w-full h-8 relative rounded-md border dark:border-zinc-600 hover:dark:border-zinc-400
|
class="w-full h-8 relative rounded-md border dark:border-zinc-600 hover:dark:border-zinc-400
|
||||||
transition-colors {$$props.class}"
|
transition-colors {$$props.class}"
|
||||||
style="background-color: {backgroundColor}"
|
style="background-color: rgb({value});"
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
class="rounded-md border cursor-pointer absolute top-0 left-0 w-full h-full opacity-0"
|
class="rounded-md border cursor-pointer absolute top-0 left-0 w-full h-full opacity-0"
|
||||||
type="color"
|
type="color"
|
||||||
bind:value
|
bind:value
|
||||||
|
on:change={() => dispatch('change', hexToRgb(value))}
|
||||||
|
on:contextmenu
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
import { calculateVars, themeData, type Theme } from '$lib/ui/colors'
|
||||||
|
import { action, Button, Material, modal, TextInput } from 'mono-svelte'
|
||||||
|
import { CheckCircle, Icon, Trash } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
export let theme: Theme
|
||||||
|
|
||||||
|
let editingName = false
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<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 p-0.5"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style="{calculateVars(theme)};"
|
||||||
|
class="h-20 w-full rounded-lg rounded-b-none flex flex-row flex-wrap p-3 gap-2
|
||||||
|
bg-slate-25 dark:bg-zinc-925"
|
||||||
|
>
|
||||||
|
<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
|
||||||
|
class="w-3 h-3 bg-primary-900 dark:bg-primary-100 rounded-full ml-auto"
|
||||||
|
/>
|
||||||
|
</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 flex items-center gap-1 justify-between">
|
||||||
|
{#if editingName}
|
||||||
|
<form on:submit|preventDefault={() => (editingName = false)}>
|
||||||
|
<TextInput bind:value={theme.name}></TextInput>
|
||||||
|
</form>
|
||||||
|
{:else}
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
if (theme.id > 0) editingName = true
|
||||||
|
}}
|
||||||
|
class="text-left font-medium text-lg font-display"
|
||||||
|
>
|
||||||
|
{theme.name}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
{#if theme.id > 0}
|
||||||
|
<Button
|
||||||
|
color="ghost"
|
||||||
|
size="square-md"
|
||||||
|
class="flex-shrink-0"
|
||||||
|
on:click={() => {
|
||||||
|
modal({
|
||||||
|
actions: [
|
||||||
|
action({
|
||||||
|
close: true,
|
||||||
|
type: 'secondary',
|
||||||
|
content: $t('common.cancel'),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
close: true,
|
||||||
|
content: $t('routes.theme.preset.delete.confirm'),
|
||||||
|
type: 'danger',
|
||||||
|
action: () => {
|
||||||
|
const index = $themeData.themes
|
||||||
|
.map((t) => t.id)
|
||||||
|
.indexOf(theme.id)
|
||||||
|
|
||||||
|
$themeData.themes = $themeData.themes.toSpliced(index, 1)
|
||||||
|
if (theme.id == $themeData.currentTheme) {
|
||||||
|
$themeData.currentTheme = 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
type: 'error',
|
||||||
|
body: '',
|
||||||
|
title: $t('routes.theme.preset.delete.title'),
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon src={Trash} size="16" mini slot="prefix" />
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</Material>
|
||||||
|
</button>
|
||||||
+28
-28
@@ -30,39 +30,39 @@ export default {
|
|||||||
},
|
},
|
||||||
colors: {
|
colors: {
|
||||||
slate: {
|
slate: {
|
||||||
25: 'var(--c-s-25,#fcfdfe)',
|
25: 'rgb(var(--c-s-25,252 253 254) / <alpha-value>)',
|
||||||
50: `var(--c-s-50,${colors.slate[50]})`,
|
50: 'rgb(var(--c-s-50,248 250 252) / <alpha-value>)',
|
||||||
100: `var(--c-s-100,${colors.slate[100]})`,
|
100: 'rgb(var(--c-s-100,241 245 249) / <alpha-value>)',
|
||||||
200: `var(--c-s-200,#e8edf4)`,
|
200: 'rgb(var(--c-s-200,226 232 240) / <alpha-value>)',
|
||||||
300: `var(--c-s-300,${colors.slate[300]})`,
|
300: 'rgb(var(--c-s-300,203 213 225) / <alpha-value>)',
|
||||||
400: `var(--c-s-400,${colors.slate[400]})`,
|
400: 'rgb(var(--c-s-400,148 163 184) / <alpha-value>)',
|
||||||
500: `var(--c-s-500,${colors.slate[500]})`,
|
500: 'rgb(var(--c-s-500,100 116 139) / <alpha-value>)',
|
||||||
600: `var(--c-s-600,${colors.slate[600]})`,
|
600: 'rgb(var(--c-s-600,71 85 105) / <alpha-value>)',
|
||||||
700: `var(--c-s-700,${colors.slate[700]})`,
|
700: 'rgb(var(--c-s-700,51 65 85) / <alpha-value>)',
|
||||||
800: `var(--c-s-800,${colors.slate[800]})`,
|
800: 'rgb(var(--c-s-800,30 41 59) / <alpha-value>)',
|
||||||
900: `var(--c-s-900,${colors.slate[900]})`,
|
900: 'rgb(var(--c-s-900,15 23 42) / <alpha-value>)',
|
||||||
950: `var(--c-s-950,${colors.slate[950]})`,
|
950: 'rgb(var(--c-s-950,2 6 23) / <alpha-value>)',
|
||||||
},
|
},
|
||||||
zinc: {
|
zinc: {
|
||||||
50: `var(--c-z-50,${colors.zinc[50]})`,
|
50: `rgb(var(--c-z-50,249 250 251) / <alpha-value>)`,
|
||||||
100: `var(--c-z-100,${colors.zinc[100]})`,
|
100: `rgb(var(--c-z-100,243 244 246) / <alpha-value>)`,
|
||||||
200: `var(--c-z-200,${colors.zinc[200]})`,
|
200: `rgb(var(--c-z-200,229 231 235) / <alpha-value>)`,
|
||||||
300: `var(--c-z-300,${colors.zinc[300]})`,
|
300: `rgb(var(--c-z-300,209 213 219) / <alpha-value>)`,
|
||||||
400: `var(--c-z-400,${colors.zinc[400]})`,
|
400: `rgb(var(--c-z-400,156 163 175) / <alpha-value>)`,
|
||||||
500: `var(--c-z-500,${colors.zinc[500]})`,
|
500: `rgb(var(--c-z-500,107 114 128) / <alpha-value>)`,
|
||||||
600: `var(--c-z-600,${colors.zinc[600]})`,
|
600: `rgb(var(--c-z-600,75 85 99) / <alpha-value>)`,
|
||||||
700: 'var(--c-z-700,#34343b)',
|
700: 'rgb(var(--c-z-700,50 60 76) / <alpha-value>)',
|
||||||
800: 'var(--c-z-800,#1f1f24)',
|
800: 'rgb(var(--c-z-800,22 31 45) / <alpha-value>)',
|
||||||
900: 'var(--c-z-900,#121215)',
|
900: 'rgb(var(--c-z-900,17 24 39) / <alpha-value>)',
|
||||||
925: 'var(--c-z-925,#0c0c0e)',
|
925: 'rgb(var(--c-z-925,8 12 25) / <alpha-value>)',
|
||||||
950: `var(--c-z-950,${colors.zinc[950]})`,
|
950: `rgb(var(--c-z-950,5 9 16) / <alpha-value>)`,
|
||||||
},
|
},
|
||||||
primary: {
|
primary: {
|
||||||
100: 'var(--c-p-100,#f1f5f9)',
|
100: 'rgb(var(--c-p-100,241 245 249) / <alpha-value>)',
|
||||||
900: 'var(--c-p-900,#0f172a)',
|
900: 'rgb(var(--c-p-900,15 23 42) / <alpha-value>)',
|
||||||
},
|
},
|
||||||
black: `#000`,
|
black: `rgb(var(--c-o-black,0 0 0) / <alpha-value>)`,
|
||||||
white: `var(--c-o-white,#fff)`,
|
white: `rgb(var(--c-o-white,255 255 255) / <alpha-value>)`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user