Spaces:
Sleeping
Sleeping
Download src/lib/stores/performance.ts from veltrixcode/lofi: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/veltrixcode/lofi/resolve/main/src/lib/stores/performance.ts
- Command line
-
hf download hf://spaces/veltrixcode/lofi/src/lib/stores/performance.ts
-
curl -L -o performance.ts https://huggingface.co/spaces/veltrixcode/lofi/resolve/main/src/lib/stores/performance.ts
1.21 kB
| import { derived, readable } from 'svelte/store'; | |
| import { browser } from '$app/environment'; | |
| import { userPreferencesStore } from './userPreferences'; | |
| import { type PerformanceLevel } from '$lib/utils/performance'; | |
| /** | |
| * Derived store that provides the effective performance level | |
| * based on user preferences. | |
| */ | |
| export const effectivePerformanceLevel = derived( | |
| userPreferencesStore, | |
| ($prefs): PerformanceLevel => { | |
| return $prefs.performanceMode as PerformanceLevel; | |
| } | |
| ); | |
| /** | |
| * Store that tracks if user prefers reduced motion | |
| */ | |
| export const reducedMotion = readable(false, (set) => { | |
| if (!browser) { | |
| return; | |
| } | |
| const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)'); | |
| set(mediaQuery.matches); | |
| const handler = (e: MediaQueryListEvent) => { | |
| set(e.matches); | |
| }; | |
| mediaQuery.addEventListener('change', handler); | |
| return () => { | |
| mediaQuery.removeEventListener('change', handler); | |
| }; | |
| }); | |
| /** | |
| * Derived store that determines if animations should be enabled | |
| */ | |
| export const animationsEnabled = derived( | |
| [effectivePerformanceLevel, reducedMotion], | |
| ([$perfLevel, $reducedMotion]) => { | |
| if ($reducedMotion) { | |
| return false; | |
| } | |
| return $perfLevel !== 'low'; | |
| } | |
| ); | |