From 3aa948891a65f3da14d9f551fbc06a24551d45eb Mon Sep 17 00:00:00 2001 From: Xylight Date: Wed, 24 Jul 2024 21:32:10 -0700 Subject: [PATCH 01/11] feat: remake theme handling --- .../lemmy/comment/CommentVote.svelte | 1 - src/lib/components/ui/layout/Shell.svelte | 16 +- src/lib/components/ui/navbar/Profile.svelte | 10 +- .../components/ui/navbar/commands/actions.ts | 8 +- src/lib/ui/colors.ts | 316 +++++++++--------- src/lib/ui/presets.ts | 75 +++++ src/routes/+layout.svelte | 31 +- src/routes/theme/+page.svelte | 139 +++++++- src/routes/theme/ColorSwatch.svelte | 10 +- tailwind.config.js | 56 ++-- 10 files changed, 413 insertions(+), 249 deletions(-) create mode 100644 src/lib/ui/presets.ts diff --git a/src/lib/components/lemmy/comment/CommentVote.svelte b/src/lib/components/lemmy/comment/CommentVote.svelte index 4725b814..a7db5a1f 100644 --- a/src/lib/components/lemmy/comment/CommentVote.svelte +++ b/src/lib/components/lemmy/comment/CommentVote.svelte @@ -1,5 +1,4 @@ - {#if $site?.site_view} {$site?.site_view.site.name} {#if LINKED_INSTANCE_URL} diff --git a/src/routes/theme/+page.svelte b/src/routes/theme/+page.svelte index 2b039f4c..f7fee54e 100644 --- a/src/routes/theme/+page.svelte +++ b/src/routes/theme/+page.svelte @@ -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() {#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 @@
Theme
+
+ {#each $themeData.themes as theme} + + {/each} + +
+ {/each}
- -

{$t('routes.theme.accent')}

- { - $theme.colors.primary[900] = e.detail - }} - backgroundColor={defaultColors.primary[900]} - on:contextmenu={(e) => { - e.preventDefault() - $theme.colors.primary[900] = - // @ts-ignore - defaultColors.primary[900] + {#if $theme.id <= 0} + + {$t('routes.theme.preset.description')} + + {/if} +
+ +

{$t('routes.theme.accent')}

+ { + $theme.colors.primary[900] = e.detail + }} + backgroundColor={defaultColors.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" - /> - { - $theme.colors.primary[100] = e.detail - }} - 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" + /> + { + $theme.colors.primary[100] = e.detail + }} + 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" - /> - - {$t('nav.menu.colorscheme.light')} - - - {$t('nav.menu.colorscheme.dark')} - -
-
- {#each Object.entries(defaultColors) as [category, value]} - -

{category}

-
- {#each Object.entries(value) as [shade, color]} -
- - { - $theme.colors[category][shade] = e.detail - }} - on:contextmenu={(e) => { - e.preventDefault() - $theme.colors[category][shade] = - // @ts-ignore - defaultColors[category][shade] + return true + }} + class="!w-12 !h-12 col-span-1" + /> + + {$t('nav.menu.colorscheme.light')} + + + {$t('nav.menu.colorscheme.dark')} + + +
+ {#each Object.entries(defaultColors) as [category, value]} + +

{category}

+
+ {#each Object.entries(value) as [shade, color]} +
+ + { + $theme.colors[category][shade] = e.detail + }} + on:contextmenu={(e) => { + e.preventDefault() + $theme.colors[category][shade] = + // @ts-ignore + defaultColors[category][shade] - return true - }} - /> - {shade} -
- {/each} -
-
- {/each} + return true + }} + /> + {shade} +
+ {/each} +
+ + {/each} +
diff --git a/src/routes/theme/ThemePreset.svelte b/src/routes/theme/ThemePreset.svelte new file mode 100644 index 00000000..2e01dd52 --- /dev/null +++ b/src/routes/theme/ThemePreset.svelte @@ -0,0 +1,79 @@ + + + +
+ + From 926af69ec551e422b9faa80528c34c95f9b9fa3c Mon Sep 17 00:00:00 2001 From: Xylight Date: Thu, 25 Jul 2024 11:35:13 -0700 Subject: [PATCH 03/11] feat: add theme deletion --- src/lib/ui/presets.ts | 10 ++--- src/routes/theme/+page.svelte | 5 ++- src/routes/theme/ThemePreset.svelte | 68 +++++++++++++++-------------- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/lib/ui/presets.ts b/src/lib/ui/presets.ts index 7c0d14af..232c3044 100644 --- a/src/lib/ui/presets.ts +++ b/src/lib/ui/presets.ts @@ -27,18 +27,18 @@ export function getDefaultColors(): ThemeColors { 500: '107 114 128', 600: '75 85 99', 700: '55 65 81', - 800: '31 41 55', + 800: '22 31 45', 900: '17 24 39', 925: '8 12 25', 950: '3 7 18', }, primary: { - 100: 'var(--c-p-100,241 245 249)', - 900: 'var(--c-p-900,15 23 42)', + 100: '241 245 249', + 900: '15 23 42', }, other: { - black: `var(--c-o-black,0 0 0)`, - white: `var(--c-o-white,255 255 255)`, + black: `0 0 0`, + white: `255 255 255`, }, } } diff --git a/src/routes/theme/+page.svelte b/src/routes/theme/+page.svelte index 71b62b69..5c3f7752 100644 --- a/src/routes/theme/+page.svelte +++ b/src/routes/theme/+page.svelte @@ -56,7 +56,10 @@
Theme
-
+
{#each $themeData.themes as theme} {/each} diff --git a/src/routes/theme/ThemePreset.svelte b/src/routes/theme/ThemePreset.svelte index 2e01dd52..357315d4 100644 --- a/src/routes/theme/ThemePreset.svelte +++ b/src/routes/theme/ThemePreset.svelte @@ -1,7 +1,7 @@ + {/if} {#if theme.id > 0}