Skip to content

Commit 6c777cc

Browse files
authored
Merge pull request #4 from pathsim/feat/radial-theme-transition
Add radial theme transition
2 parents 9ae117d + ee4bc18 commit 6c777cc

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/app.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
* Aligned with pathsim-docs for consistency
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
@@ -24,10 +24,24 @@
2424
document.documentElement.setAttribute('data-theme', theme);
2525
});
2626
27-
function toggleTheme() {
28-
theme = theme === 'dark' ? 'light' : 'dark';
29-
localStorage.setItem('theme', theme);
30-
document.documentElement.setAttribute('data-theme', theme);
27+
function toggleTheme(e: MouseEvent) {
28+
const apply = () => {
29+
theme = theme === 'dark' ? 'light' : 'dark';
30+
localStorage.setItem('theme', theme);
31+
document.documentElement.setAttribute('data-theme', theme);
32+
};
33+
34+
if (!document.startViewTransition) { apply(); return; }
35+
36+
const x = e.clientX, y = e.clientY;
37+
const maxRadius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y));
38+
const transition = document.startViewTransition(apply);
39+
transition.ready.then(() => {
40+
document.documentElement.animate(
41+
{ clipPath: [`circle(0px at ${x}px ${y}px)`, `circle(${maxRadius}px at ${x}px ${y}px)`] },
42+
{ duration: 500, easing: 'ease-out', pseudoElement: '::view-transition-new(root)' }
43+
);
44+
});
3145
}
3246
</script>
3347

0 commit comments

Comments
 (0)