({
children,
className = "",
innerId,
maxRotation = 10,
glowOpacity = 0.2,
shadowBlur = 30,
parallaxOffset = 40,
transitionDuration = "0.6s",
backgroundImage = null,
enableGlow = true,
enableShadow = true,
enableParallax = true,
hoverPadding = 12,
trackOnWindow = false,
}: ThreeDCardProps)
| 27 | innerId, |
| 28 | maxRotation = 10, |
| 29 | glowOpacity = 0.2, |
| 30 | shadowBlur = 30, |
| 31 | parallaxOffset = 40, |
| 32 | transitionDuration = "0.6s", |
| 33 | backgroundImage = null, |
| 34 | enableGlow = true, |
| 35 | enableShadow = true, |
| 36 | enableParallax = true, |
| 37 | hoverPadding = 12, |
| 38 | trackOnWindow = false, |
| 39 | }: ThreeDCardProps) { |
| 40 | const cardRef = useRef<HTMLDivElement>(null); |
| 41 | |
| 42 | const [prefersReducedMotion, setPrefersReducedMotion] = useState(false); |
| 43 | const [transform, setTransform] = useState({ |
| 44 | glowX: 50, |
| 45 | glowY: 50, |
| 46 | isHovered: false, |
| 47 | rotateX: 0, |
| 48 | rotateY: 0, |
| 49 | shadowX: 0, |
| 50 | shadowY: 20, |
| 51 | }); |
| 52 | |
| 53 | useEffect(() => { |
| 54 | const media = window.matchMedia("(prefers-reduced-motion: reduce)"); |
| 55 | const syncPreference = () => setPrefersReducedMotion(media.matches); |
| 56 | |
| 57 | syncPreference(); |
| 58 | media.addEventListener("change", syncPreference); |
| 59 | return () => media.removeEventListener("change", syncPreference); |
| 60 | }, []); |
| 61 | |
| 62 | const handleMouseMove = useCallback( |
| 63 | (e: React.MouseEvent<HTMLDivElement>) => { |
| 64 | if (prefersReducedMotion || trackOnWindow) { |
| 65 | return; |
| 66 | } |
| 67 | if (!cardRef.current) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | const rect = cardRef.current.getBoundingClientRect(); |
| 72 | const { width, height, left, top } = rect; |
| 73 | |
| 74 | // Mouse events are attached to a padded "hit area" wrapper to avoid |
| 75 | // enter/leave jitter when the card tilts away from the cursor. |
| 76 | // Clamp so motion in the padding doesn't create extreme rotations. |
| 77 | const mouseX = Math.min(width, Math.max(0, e.clientX - left)); |
| 78 | const mouseY = Math.min(height, Math.max(0, e.clientY - top)); |
| 79 | |
| 80 | const xPct = mouseX / width - 0.5; |
| 81 | const yPct = mouseY / height - 0.5; |
| 82 | |
| 83 | const newRotateX = yPct * -1 * maxRotation; |
| 84 | const newRotateY = xPct * maxRotation; |
| 85 | |
| 86 | setTransform((prev) => ({ |
nothing calls this directly
no outgoing calls
no test coverage detected