diff --git a/src/interface/components/SkeletonLoader.svelte b/src/interface/components/SkeletonLoader.svelte index 17e23ade..ffe8cf51 100644 --- a/src/interface/components/SkeletonLoader.svelte +++ b/src/interface/components/SkeletonLoader.svelte @@ -1,5 +1,8 @@ -
+
diff --git a/src/interface/components/store/Header.svelte b/src/interface/components/store/Header.svelte index f0ec96ab..f8648f6b 100644 --- a/src/interface/components/store/Header.svelte +++ b/src/interface/components/store/Header.svelte @@ -71,7 +71,7 @@ role="tab" aria-selected={activePage === tab.id} onclick={() => setActivePage(tab.id)} - class="relative z-10 h-10 flex-1 whitespace-nowrap rounded-full px-4 text-base transition-colors duration-200 + class="relative z-10 h-10 flex-1 whitespace-nowrap rounded-full px-4 text-lg transition-colors duration-200 {activePage === tab.id ? 'font-semibold text-zinc-900 dark:text-white' : 'text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-white'}" diff --git a/src/interface/components/store/ThemeModal.svelte b/src/interface/components/store/ThemeModal.svelte index 838bdd20..c89e0414 100644 --- a/src/interface/components/store/ThemeModal.svelte +++ b/src/interface/components/store/ThemeModal.svelte @@ -9,6 +9,10 @@ flavourCarouselImageUrl, masterCarouselImageUrl, masterGridDisplayDownloadCount, } from '@/interface/utils/themeStoreFlavours' +import { +getThemeApplyButtonStyles, +resolveStoreVariantAccentColor, +} from '@/interface/utils/themeListFilters' let { theme, currentThemes, @@ -23,6 +27,7 @@ toggleFavorite, isLoggedIn, onRequestSignIn, selectedThemeId = '', +installedThemeColors = {}, } = $props<{ theme: Theme | null currentThemes: string[] @@ -38,7 +43,16 @@ toggleFavorite?: (theme: Theme) => void isLoggedIn?: boolean onRequestSignIn?: () => void selectedThemeId?: string +installedThemeColors?: Record }>() +function variantApplyStyles(variantId: string) { +if (!theme) { +return getThemeApplyButtonStyles(undefined) +} +return getThemeApplyButtonStyles( +resolveStoreVariantAccentColor(theme, variantId, installedThemeColors), +) +} const modalDisplayDownloadCount = $derived.by(() => { const t = theme if (!t) return 0 @@ -110,7 +124,7 @@ $effect(() => { if (displayTheme && modalElement) { animate( modalElement, -{ y: [500, 0], opacity: [0, 1] }, +{ y: [16, 0], opacity: [0, 1], scale: [0.98, 1] }, { type: 'spring', stiffness: 150, @@ -122,7 +136,7 @@ damping: 20, const hideModal = (relatedTheme = null) => { animate( modalElement, -{ y: [10, 500], opacity: [1, 0] }, +{ y: [0, 16], opacity: [1, 0], scale: [1, 0.98] }, { type: 'spring', stiffness: 150, @@ -170,7 +184,7 @@ else await runRemove(theme.id) }
{ if (e.target === e.currentTarget) hideModal() }} @@ -183,7 +197,7 @@ transition:fade
e.stopPropagation()} onkeydown={(e) => e.stopPropagation()} role="dialog" @@ -191,7 +205,7 @@ aria-modal="true" tabindex="-1" > {#if theme} -
+
@@ -383,7 +398,8 @@ class="relative w-full overflow-hidden rounded-2xl min-h-[9.5rem] sm:min-h-[11re type="button" onclick={(e) => { e.stopPropagation(); scrollHeroToFlavourIndex(flavourIdx); void runApply(f.id) }} disabled={installingId !== null} -class="px-3 py-1.5 text-sm font-semibold rounded-lg bg-emerald-500 text-white hover:bg-emerald-600 disabled:opacity-70" +style={variantApplyStyles(f.id).apply} +class="px-3 py-1.5 text-sm font-semibold rounded-lg hover:brightness-90 disabled:opacity-70" > Apply @@ -450,7 +466,8 @@ aria-label={theme.is_favorited ? 'Unfavorite' : 'Favorite'} @@ -459,7 +476,8 @@ Applied type="button" onclick={() => runApply(theme.id)} disabled={installingId !== null} -class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] text-white rounded-lg bg-emerald-600 hover:bg-emerald-700 transition-all duration-200 hover:scale-105 active:scale-95 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 disabled:opacity-70" +style={variantApplyStyles(theme.id).apply} +class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] rounded-lg transition-all duration-200 hover:brightness-90 active:scale-95 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-70" > {#if installingId === theme.id} @@ -500,11 +518,11 @@ class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] text-bla {/if}
{#if relatedThemes.length > 0} -
+

Related themes

-
+
{#each relatedThemes as relatedTheme (relatedTheme.id)}
-
+
{#if themes} {#each visibleThemes as theme (theme.id)} - -
-
{'\uecb3'}
-
- Got a Theme Idea? -

Transform it into a stunning theme!

-
-
+
+ {'\uecb3'} + View theme creation docs {:else if listMode === 'downloaded'} {/if} -
- +
+ {#if showThemes || showBackgrounds} +
+ +
+ {/if} {#if showBackgrounds} diff --git a/src/interface/pages/store.svelte b/src/interface/pages/store.svelte index 3c2531b0..5df465ca 100644 --- a/src/interface/pages/store.svelte +++ b/src/interface/pages/store.svelte @@ -54,6 +54,7 @@ let displayTheme = $state(null); let currentThemes = $state([]); let selectedThemeId = $state(''); + let installedThemeColors = $state>({}); let error = $state(null); let fetchAttempt = $state(0); @@ -76,6 +77,9 @@ const themes = await themeManager.getAvailableThemes(); currentThemes = themes.filter(theme => theme !== null).map(theme => theme.id); selectedThemeId = themeManager.getSelectedThemeId() || ''; + installedThemeColors = Object.fromEntries( + themes.filter((theme) => theme != null).map((theme) => [theme.id, theme.defaultColour]), + ); }; const setDisplayTheme = (theme: Theme | null) => { @@ -313,6 +317,7 @@ isLoggedIn={cloudLoggedIn} onRequestSignIn={() => (showSignInOverlay = true)} {selectedThemeId} + {installedThemeColors} onInstall={async (themeId: string) => { if (displayTheme) await installThemeFromStore(themeId, displayTheme); }} diff --git a/src/interface/utils/themeListFilters.test.ts b/src/interface/utils/themeListFilters.test.ts index 1167b79d..7cd6b603 100644 --- a/src/interface/utils/themeListFilters.test.ts +++ b/src/interface/utils/themeListFilters.test.ts @@ -1,6 +1,11 @@ import type { CustomTheme } from '@/types/CustomThemes'; import type { Theme } from '@/interface/types/Theme'; -import { filterThemesByMode, isStoreThemeInstalled } from './themeListFilters'; +import { + filterThemesByMode, + getThemeApplyButtonStyles, + isStoreThemeInstalled, + resolveStoreVariantAccentColor, +} from './themeListFilters'; function makeCustomTheme(overrides: Partial & Pick): CustomTheme { return { @@ -66,3 +71,36 @@ describe('isStoreThemeInstalled', () => { expect(isStoreThemeInstalled(theme, ['other-theme'])).toBe(false); }); }); + +describe('resolveStoreVariantAccentColor', () => { + it('prefers installed theme colour for the variant id', () => { + const theme = makeStoreTheme({ + id: 'master-1', + name: 'Master', + flavours: [{ id: 'flavour-1', name: 'Dark', accent_color: '#111111', cover_image: '' }], + }); + expect(resolveStoreVariantAccentColor(theme, 'flavour-1', { 'flavour-1': '#ff0000' })).toBe('#ff0000'); + }); + + it('falls back to flavour accent when not installed locally', () => { + const theme = makeStoreTheme({ + id: 'master-1', + name: 'Master', + flavours: [{ id: 'flavour-1', name: 'Dark', accent_color: '#112233', cover_image: '' }], + }); + expect(resolveStoreVariantAccentColor(theme, 'flavour-1')).toBe('#112233'); + }); +}); + +describe('getThemeApplyButtonStyles', () => { + it('uses the theme accent as the apply button background', () => { + const styles = getThemeApplyButtonStyles('#ff0000'); + expect(styles.apply).toContain('background-color: #FF0000'); + }); + + it('uses a muted version of the accent for the applied state', () => { + const styles = getThemeApplyButtonStyles('#ff0000'); + expect(styles.applied).toContain('background-color:'); + expect(styles.applied).toContain('color: #FF0000'); + }); +}); diff --git a/src/interface/utils/themeListFilters.ts b/src/interface/utils/themeListFilters.ts index 1ff72799..41e54e10 100644 --- a/src/interface/utils/themeListFilters.ts +++ b/src/interface/utils/themeListFilters.ts @@ -1,8 +1,11 @@ import type { CustomTheme } from '@/types/CustomThemes'; import type { Theme } from '@/interface/types/Theme'; +import { parseCssColor } from '@/seqta/ui/colors/parseCssColor'; export type ThemeListMode = 'downloaded' | 'custom' | 'all'; +const DEFAULT_THEME_ACCENT = 'rgba(0, 123, 255, 1)'; + export function filterThemesByMode(themes: CustomTheme[], mode: ThemeListMode): CustomTheme[] { if (mode === 'all') return themes; if (mode === 'custom') return themes.filter((theme) => theme.isEditable === true); @@ -14,3 +17,37 @@ export function isStoreThemeInstalled(theme: Theme, installedIds: string[]): boo if (installed.has(theme.id)) return true; return (theme.flavours ?? []).some((flavour) => installed.has(flavour.id)); } + +export function resolveStoreVariantAccentColor( + theme: Theme, + variantId: string, + installedThemeColors: Record = {}, +): string { + const installed = installedThemeColors[variantId]?.trim(); + if (installed) return installed; + + const flavour = theme.flavours?.find((entry) => entry.id === variantId); + if (flavour?.accent_color?.trim()) return flavour.accent_color.trim(); + + if (variantId === theme.id) { + const firstFlavourAccent = theme.flavours?.find((entry) => entry.accent_color?.trim())?.accent_color?.trim(); + if (firstFlavourAccent) return firstFlavourAccent; + } + + return DEFAULT_THEME_ACCENT; +} + +export type ThemeApplyButtonStyles = { + apply: string; + applied: string; +}; + +export function getThemeApplyButtonStyles(accentColor: string | undefined): ThemeApplyButtonStyles { + const parsed = parseCssColor(accentColor?.trim() || DEFAULT_THEME_ACCENT, DEFAULT_THEME_ACCENT); + const onAccent = parsed.lightness() >= 60 ? '#18181b' : '#ffffff'; + + return { + apply: `background-color: ${parsed.hex()}; color: ${onAccent};`, + applied: `background-color: ${parsed.alpha(0.18).string()}; color: ${parsed.hex()};`, + }; +} diff --git a/src/test/mocks/color.ts b/src/test/mocks/color.ts index 585602a5..e0b8c121 100644 --- a/src/test/mocks/color.ts +++ b/src/test/mocks/color.ts @@ -18,13 +18,28 @@ function toHexByte(value: number): string { } function createColor(channels: ColorChannels) { + const hex = () => + `#${toHexByte(channels.r)}${toHexByte(channels.g)}${toHexByte(channels.b)}`.toUpperCase(); + const color = { red: () => clampByte(channels.r), green: () => clampByte(channels.g), blue: () => clampByte(channels.b), - alpha: () => clampAlpha(channels.a), - hex: () => - `#${toHexByte(channels.r)}${toHexByte(channels.g)}${toHexByte(channels.b)}`, + hex, + lightness: () => { + const r = channels.r / 255; + const g = channels.g / 255; + const b = channels.b / 255; + const max = Math.max(r, g, b); + const min = Math.min(r, g, b); + return ((max + min) / 2) * 100; + }, + string: () => { + if (channels.a < 1) { + return `rgba(${clampByte(channels.r)}, ${clampByte(channels.g)}, ${clampByte(channels.b)}, ${clampAlpha(channels.a)})`; + } + return hex(); + }, }; return {