Skip to content

Commit 87d8944

Browse files
authored
Merge pull request #15 from pathsim/feat/radial-theme-transition
Add radial theme transition
2 parents 0f1c313 + 54dd296 commit 87d8944

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/app.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
* Adapted from PathView for documentation site
33
*/
44

5+
/* Theme transition — radial reveal via View Transitions API */
6+
::view-transition-old(root),
7+
::view-transition-new(root) {
8+
animation: none;
9+
mix-blend-mode: normal;
10+
}
11+
::view-transition-old(root) {
12+
z-index: 1;
13+
}
14+
::view-transition-new(root) {
15+
z-index: 9999;
16+
}
17+
518
:root {
619
/* ===== SURFACES ===== */
720
--surface: #08080c;

src/routes/+layout.svelte

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,24 @@
7575
await Promise.all([initializeSearch(packages), initializeCrossref(packages)]);
7676
}
7777
78-
function toggleTheme() {
79-
theme = theme === 'dark' ? 'light' : 'dark';
80-
document.documentElement.setAttribute('data-theme', theme);
81-
localStorage.setItem('theme', theme);
78+
function toggleTheme(e: MouseEvent) {
79+
const apply = () => {
80+
theme = theme === 'dark' ? 'light' : 'dark';
81+
document.documentElement.setAttribute('data-theme', theme);
82+
localStorage.setItem('theme', theme);
83+
};
84+
85+
if (!document.startViewTransition) { apply(); return; }
86+
87+
const x = e.clientX, y = e.clientY;
88+
const maxRadius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y));
89+
const transition = document.startViewTransition(apply);
90+
transition.ready.then(() => {
91+
document.documentElement.animate(
92+
{ clipPath: [`circle(0px at ${x}px ${y}px)`, `circle(${maxRadius}px at ${x}px ${y}px)`] },
93+
{ duration: 500, easing: 'ease-out', pseudoElement: '::view-transition-new(root)' }
94+
);
95+
});
8296
}
8397
8498
function openMobileMenu() {

0 commit comments

Comments
 (0)