From bd3bf548c27f6be204cf89d98944b76ccdd01078 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Thu, 18 Apr 2024 19:17:05 -0700
Subject: feat(badges): limit rotation

---
 src/lib/FallbackBadge.svelte | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'src/lib/FallbackBadge.svelte')

diff --git a/src/lib/FallbackBadge.svelte b/src/lib/FallbackBadge.svelte
index 8e5c9a5d..f7953e30 100644
--- a/src/lib/FallbackBadge.svelte
+++ b/src/lib/FallbackBadge.svelte
@@ -22,7 +22,7 @@
 	const mouse = tweened(
 		{ x: 0, y: 0 },
 		{
-			duration: 1,
+			duration: 75,
 			easing: cubicOut
 		}
 	);
@@ -40,6 +40,7 @@
 	const handleMouseMove = (event: MouseEvent) => {
 		const boundingRectangle = badgeReference.getBoundingClientRect();
 		const factor = 1.25;
+		const limit = 50;
 
 		if ($mouse.x === 0 && $mouse.y === 0) $mouse = { x: event.clientX, y: event.clientY };
 
@@ -47,6 +48,8 @@
 			(-(event.clientX - boundingRectangle.left - boundingRectangle.width / 2) - $mouse.x) * factor;
 		$mouse.y +=
 			(-(event.clientY - boundingRectangle.top - boundingRectangle.height / 2) - $mouse.y) * factor;
+		$mouse.x = Math.max(Math.min($mouse.x, limit), -limit);
+		$mouse.y = Math.max(Math.min($mouse.y, limit), -limit);
 	};
 
 	const handleMouseLeave = () => {
-- 
cgit v1.2.3

