From 2d3dd7fd0e2697b657b7c932fd59501a6d703f84 Mon Sep 17 00:00:00 2001
From: Azalea <22280294+hykilpikonna@users.noreply.github.com>
Date: Fri, 21 Nov 2025 12:09:31 +0800
Subject: [PATCH] [+] View transition
---
src/routes/+layout.svelte | 74 ++++++++++++++++++++++++++++++++++++---
1 file changed, 69 insertions(+), 5 deletions(-)
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index d303a95..210311b 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -6,18 +6,82 @@
import "../style/material.scss"
import '@unocss/reset/normalize.css'
import '@unocss/reset/tailwind-v4.css'
+ import type { LayoutProps } from "./$types"
+ import { onNavigate } from '$app/navigation'
- import AppBar from "../components/appbar/AppBar.svelte"
- import type { LayoutProps } from "./$types";
+ let { data, children }: LayoutProps = $props()
- let { data, children }: LayoutProps = $props();
-
+ // This function is called when the user navigates to a new page, it will start the view transition
+ onNavigate((navigation) => {
+ if (!document.startViewTransition) return
+
+ const direction = navigation.delta && navigation.delta < 0 ? 'back' : 'forward'
+ console.log(direction)
+ document.documentElement.dataset.transitionDirection = direction
+
+ return new Promise((resolve) => {
+ document.startViewTransition(async () => {
+ resolve()
+ await navigation.complete
+ })
+ })
+ })