From 38709395d43bb3703ebaca46baecec990097792d Mon Sep 17 00:00:00 2001 From: not-nullptr Date: Mon, 11 Nov 2024 20:09:45 +0000 Subject: [PATCH] feat: page transitions --- src/app.css | 2 +- src/lib/animation/index.ts | 118 ++++++++++++++++++++++++++++++++ src/lib/store/index.svelte.ts | 11 +++ src/routes/+layout.svelte | 102 ++++++++++++++++++++++++++- src/routes/+layout.ts | 6 ++ src/routes/+page.svelte | 15 ++-- src/routes/convert/+page.svelte | 33 +++++++++ tailwind.config.ts | 21 +++--- 8 files changed, 285 insertions(+), 23 deletions(-) create mode 100644 src/lib/animation/index.ts create mode 100644 src/lib/store/index.svelte.ts create mode 100644 src/routes/+layout.ts create mode 100644 src/routes/convert/+page.svelte diff --git a/src/app.css b/src/app.css index 95cbd27..913bf79 100644 --- a/src/app.css +++ b/src/app.css @@ -18,5 +18,5 @@ } body { - @apply text-foreground bg-background font-body; + @apply text-foreground bg-background font-body overflow-x-hidden; } diff --git a/src/lib/animation/index.ts b/src/lib/animation/index.ts new file mode 100644 index 0000000..3d12513 --- /dev/null +++ b/src/lib/animation/index.ts @@ -0,0 +1,118 @@ +import type { EasingFunction, TransitionConfig } from "svelte/transition"; + +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; + +const remap = ( + value: number, + low1: number, + high1: number, + low2: number, + high2: number, +) => low2 + ((high2 - low2) * (value - low1)) / (high1 - low1); + +const choose = ( + direction: "in" | "out" | "both", + defaultValue: number, + inValue?: number, + outValue?: number, +) => + direction !== "out" + ? typeof inValue === "number" + ? inValue + : defaultValue + : typeof outValue === "number" + ? outValue + : defaultValue; + +export const blur = ( + _: HTMLElement, + config: + | Partial<{ + blurMultiplier: number; + duration: number; + easing: EasingFunction; + scale: { + start: number; + end: number; + }; + x: { + start: number; + end: number; + }; + y: { + start: number; + end: number; + }; + delay: number; + opacity: boolean; + }> + | undefined, + dir: { + direction: "in" | "out" | "both"; + }, +): TransitionConfig => { + const prefersReducedMotion = window.matchMedia( + "(prefers-reduced-motion: reduce)", + ).matches; + if (typeof config?.opacity === "undefined" && config) config.opacity = true; + return { + delay: config?.delay || 0, + duration: prefersReducedMotion ? 0 : config?.duration || 300, + css: (t) => + prefersReducedMotion + ? "" + : `filter: blur(${(1 - t) * (config?.blurMultiplier || 1)}px); opacity: ${config?.opacity ? t : 1}; transform: translate(${remap( + t, + 0, + 1, + choose( + dir.direction, + 0, + config?.x?.start, + config?.x?.end, + ), + choose( + dir.direction, + 0, + config?.x?.end, + config?.x?.start, + ), + )}px, ${remap( + t, + 0, + 1, + choose( + dir.direction, + 0, + config?.y?.start, + config?.y?.end, + ), + choose( + dir.direction, + 0, + config?.y?.end, + config?.y?.start, + ), + )}px) scale(${remap( + t, + 0, + 1, + choose( + dir.direction, + 0.9, + config?.scale?.start, + config?.scale?.end, + ), + choose( + dir.direction, + 1, + config?.scale?.end, + config?.scale?.start, + ), + )});`, + easing: config?.easing, + }; +}; diff --git a/src/lib/store/index.svelte.ts b/src/lib/store/index.svelte.ts new file mode 100644 index 0000000..1db8e3e --- /dev/null +++ b/src/lib/store/index.svelte.ts @@ -0,0 +1,11 @@ +class Files { + public files = $state([]); + public conversionTypes = $state([]); + public downloadFns = $state<(() => void)[]>([]); + public beenToConverterPage = $state(false); + public shouldShowAlert = $derived( + !this.beenToConverterPage && this.files.length > 0, + ); +} + +export const files = new Files(); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index fe4774e..a939317 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,7 +1,105 @@ -{@render children()} \ No newline at end of file +
+
+
+ {#each Object.entries(links) as [name, link] (link)} + + {/each} +
+
+ {#key data.pathname} +
+
+ {@render children()} +
+
+ {/key} +
+
diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts new file mode 100644 index 0000000..15b6d04 --- /dev/null +++ b/src/routes/+layout.ts @@ -0,0 +1,6 @@ +export const load = ({ url }) => { + const { pathname } = url; + return { + pathname, + }; +}; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 0f62ecf..9b95aeb 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,18 +1,15 @@ -
- -
+