<template>
  <div class="mouse-follower" ref="follower">
    <div class="follower-dot"></div>
    <div class="follower-ring"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { gsap } from 'gsap'

// 定义组件名称
defineOptions({
  name: 'MouseFollower'
})

const follower = ref<HTMLElement>()
let mouseX = 0
let mouseY = 0
let followerX = 0
let followerY = 0

const updateMousePosition = (e: MouseEvent) => {
  mouseX = e.clientX
  mouseY = e.clientY
}

const animateFollower = () => {
  followerX += (mouseX - followerX) * 0.1
  followerY += (mouseY - followerY) * 0.1
  
  if (follower.value) {
    gsap.set(follower.value, {
      x: followerX - 20,
      y: followerY - 20
    })
  }
  
  requestAnimationFrame(animateFollower)
}

onMounted(() => {
  window.addEventListener('mousemove', updateMousePosition)
  animateFollower()
})

onUnmounted(() => {
  window.removeEventListener('mousemove', updateMousePosition)
})
</script>

<style scoped>
.mouse-follower {
  position: fixed;
  top: 0;
  left: 0;
  width: 40px;
  height: 40px;
  pointer-events: none;
  z-index: 9998;
  mix-blend-mode: difference;
}

.follower-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.follower-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}
</style>
