From 9031254e3753a55672e694cc13ef6ec1d69b7934 Mon Sep 17 00:00:00 2001 From: JovannMC Date: Wed, 5 Feb 2025 17:00:32 +0300 Subject: [PATCH] small optimizations also fix isMobile's resize event --- src/lib/animation/index.ts | 18 +++++++++++++++--- src/lib/sections/settings/Appearance.svelte | 4 ++-- src/lib/store/index.svelte.ts | 11 +++++++---- src/routes/+layout.svelte | 13 ++++++++----- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/lib/animation/index.ts b/src/lib/animation/index.ts index 319cee8..8590482 100644 --- a/src/lib/animation/index.ts +++ b/src/lib/animation/index.ts @@ -1,4 +1,4 @@ -import { isMobile } from "$lib/store/index.svelte"; +import { isMobile, motion } from "$lib/store/index.svelte"; import type { AnimationConfig, FlipParams } from "svelte/animate"; import { cubicOut } from "svelte/easing"; import { @@ -8,19 +8,31 @@ import { type FlyParams, } from "svelte/transition"; +// Subscribe to stores +let motionEnabled = true; +let isMobileDevice = false; + +motion.subscribe(value => { + motionEnabled = value; +}); + +isMobile.subscribe(value => { + isMobileDevice = value; +}); + export const transition = "linear(0,0.006,0.025 2.8%,0.101 6.1%,0.539 18.9%,0.721 25.3%,0.849 31.5%,0.937 38.1%,0.968 41.8%,0.991 45.7%,1.006 50.1%,1.015 55%,1.017 63.9%,1.001)"; export const duration = 500; export function fade(node: HTMLElement, options: FadeParams) { - if (localStorage.getItem("motion") === "false") return {}; + if (!motionEnabled) return {}; const animation = svelteFade(node, options); return animation; } export function fly(node: HTMLElement, options: FlyParams) { - if (localStorage.getItem("motion") === "false" || isMobile) return {}; + if (!motionEnabled || isMobileDevice) return {}; const animation = svelteFly(node, options); return animation; } diff --git a/src/lib/sections/settings/Appearance.svelte b/src/lib/sections/settings/Appearance.svelte index 5cdbccf..5398522 100644 --- a/src/lib/sections/settings/Appearance.svelte +++ b/src/lib/sections/settings/Appearance.svelte @@ -1,6 +1,6 @@