{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "word-magnet",
  "type": "registry:ui",
  "title": "Word Magnet",
  "description": "Interactive magnetic word clouds that attract toward the cursor.",
  "dependencies": [
    "react",
    "motion"
  ],
  "devDependencies": [
    "@types/react"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "ui/word-magnet.tsx",
      "content": "'use client';\n\nimport React, { useEffect, useRef, useState, startTransition } from 'react';\nimport { motion, useSpring, useMotionValue, type MotionValue } from 'motion/react';\nimport { cn } from '@/lib/utils';\n\ninterface WordMagnetProps {\n  /**\n   * The text content to display\n   */\n  text?: string;\n  /**\n   * Interaction radius in pixels\n   */\n  radius?: number;\n  /**\n   * Repulsion force (0.1 to 1.0)\n   */\n  force?: number;\n  /**\n   * Spring damping (5 to 50)\n   */\n  damping?: number;\n  /**\n   * Delay before returning to original position in ms\n   */\n  returnDelay?: number;\n  /**\n   * Text color\n   */\n  textColor?: string;\n  /**\n   * Font styling object\n   */\n  font?: React.CSSProperties;\n  /**\n   * Disable interaction on mobile devices\n   */\n  disableOnMobile?: boolean;\n  /**\n   * CSS overflow property\n   */\n  overflow?: 'visible' | 'hidden' | 'scroll' | 'auto';\n  /**\n   * Additional class names\n   */\n  className?: string;\n  /**\n   * Inline styles\n   */\n  style?: React.CSSProperties;\n}\n\nexport default function WordMagnet({\n  text = 'Hover over these words and watch them dance',\n  radius = 130,\n  force = 0.45,\n  damping = 28,\n  returnDelay = 400,\n  textColor = '#000000',\n  font = {\n    fontSize: '32px',\n    fontWeight: 600, // Semibold\n    letterSpacing: '-0.03em',\n    lineHeight: '1.2em',\n  },\n  disableOnMobile = false,\n  overflow = 'visible',\n  className,\n  style,\n}: WordMagnetProps) {\n  const containerRef = useRef<HTMLDivElement>(null);\n  const [words, setWords] = useState<string[]>([]);\n  const [isMobile, setIsMobile] = useState(false);\n\n  // Motion values to track mouse position relative to container\n  const mouseX = useMotionValue(0);\n  const mouseY = useMotionValue(0);\n  const lastMoveTime = useRef(0);\n  const throttleDelay = 16; // ~60fps\n\n  // Detect mobile\n  useEffect(() => {\n    if (typeof window !== 'undefined') {\n      const checkMobile = () => {\n        startTransition(() => {\n          setIsMobile(window.innerWidth < 768 || 'ontouchstart' in window);\n        });\n      };\n      checkMobile();\n      window.addEventListener('resize', checkMobile);\n      return () => window.removeEventListener('resize', checkMobile);\n    }\n  }, []);\n\n  // Split text into words\n  useEffect(() => {\n    startTransition(() => {\n      setWords(text.split(' ').filter((word) => word.length > 0));\n    });\n  }, [text]);\n\n  // Track mouse and touch movement\n  useEffect(() => {\n    if (disableOnMobile && isMobile) return;\n\n    const updateCoords = (clientX: number, clientY: number) => {\n      const now = Date.now();\n      if (now - lastMoveTime.current < throttleDelay) return;\n      lastMoveTime.current = now;\n\n      if (containerRef.current) {\n        const rect = containerRef.current.getBoundingClientRect();\n        mouseX.set(clientX - rect.left);\n        mouseY.set(clientY - rect.top);\n      }\n    };\n\n    const handleMouseMove = (e: MouseEvent) => {\n      updateCoords(e.clientX, e.clientY);\n    };\n\n    const handleTouch = (e: TouchEvent) => {\n      if (e.touches.length > 0) {\n        updateCoords(e.touches[0].clientX, e.touches[0].clientY);\n      }\n    };\n\n    window.addEventListener('mousemove', handleMouseMove);\n    window.addEventListener('touchstart', handleTouch, { passive: true });\n    window.addEventListener('touchmove', handleTouch, { passive: true });\n    return () => {\n      window.removeEventListener('mousemove', handleMouseMove);\n      window.removeEventListener('touchstart', handleTouch);\n      window.removeEventListener('touchmove', handleTouch);\n    };\n  }, [mouseX, mouseY, isMobile, disableOnMobile]);\n\n  const isDisabled = disableOnMobile && isMobile;\n\n  return (\n    <div\n      ref={containerRef}\n      className={cn('flex flex-wrap items-center justify-center gap-[0.5em]', className)}\n      style={{\n        ...style,\n        position: 'relative',\n        overflow,\n        color: textColor,\n        ...font,\n      }}\n    >\n      {words.map((word, index) => (\n        <Word\n          key={`${word}-${index}`}\n          word={word}\n          mouseX={mouseX}\n          mouseY={mouseY}\n          radius={radius}\n          force={force}\n          damping={damping}\n          returnDelay={returnDelay}\n          disabled={isDisabled}\n        />\n      ))}\n    </div>\n  );\n}\n\ninterface WordProps {\n  word: string;\n  mouseX: MotionValue<number>;\n  mouseY: MotionValue<number>;\n  radius: number;\n  force: number;\n  damping: number;\n  returnDelay: number;\n  disabled: boolean;\n}\n\nfunction Word({ word, mouseX, mouseY, radius, force, damping, returnDelay, disabled }: WordProps) {\n  const wordRef = useRef<HTMLSpanElement>(null);\n\n  // Spring animations for x and y displacement\n  const x = useSpring(0, { damping, stiffness: 200 });\n  const y = useSpring(0, { damping, stiffness: 200 });\n\n  const returnTimeout = useRef<number | null>(null);\n\n  useEffect(() => {\n    if (disabled) return;\n\n    const unsubscribeX = mouseX.on('change', (latestX) => {\n      if (!wordRef.current) return;\n\n      // Get word position relative to the container (which mouseX/Y are relative to)\n      // The parent container is the offsetParent\n      const offsetParent = wordRef.current.offsetParent as HTMLElement;\n      if (!offsetParent) return;\n\n      const rect = wordRef.current.getBoundingClientRect();\n      const parentRect = offsetParent.getBoundingClientRect();\n\n      // Center of the word relative to the container\n      const wordCenterX = rect.left - parentRect.left + rect.width / 2;\n      const wordCenterY = rect.top - parentRect.top + rect.height / 2;\n\n      const currentMouseY = mouseY.get();\n\n      const dx = wordCenterX - latestX;\n      const dy = wordCenterY - currentMouseY;\n      const distance = Math.sqrt(dx * dx + dy * dy);\n\n      if (distance < radius) {\n        const angle = Math.atan2(dy, dx);\n        // Repel force calculation\n        const repelForce = ((radius - distance) / radius) * force * 100;\n\n        const offsetX = Math.cos(angle) * repelForce;\n        const offsetY = Math.sin(angle) * repelForce;\n\n        x.set(offsetX);\n        y.set(offsetY);\n\n        if (returnTimeout.current !== null) {\n          window.clearTimeout(returnTimeout.current);\n        }\n\n        returnTimeout.current = window.setTimeout(() => {\n          x.set(0);\n          y.set(0);\n        }, returnDelay);\n      }\n    });\n\n    const unsubscribeY = mouseY.on('change', () => {\n      if (!wordRef.current) return;\n      const offsetParent = wordRef.current.offsetParent as HTMLElement;\n      if (!offsetParent) return;\n\n      const rect = wordRef.current.getBoundingClientRect();\n      const parentRect = offsetParent.getBoundingClientRect();\n\n      const wordCenterX = rect.left - parentRect.left + rect.width / 2;\n      const wordCenterY = rect.top - parentRect.top + rect.height / 2;\n\n      const mouseXVal = mouseX.get();\n      const mouseYVal = mouseY.get();\n\n      const dx = wordCenterX - mouseXVal;\n      const dy = wordCenterY - mouseYVal;\n      const distance = Math.sqrt(dx * dx + dy * dy);\n\n      if (distance < radius) {\n        const angle = Math.atan2(dy, dx);\n        const repelForce = ((radius - distance) / radius) * force * 100;\n        const offsetX = Math.cos(angle) * repelForce;\n        const offsetY = Math.sin(angle) * repelForce;\n        x.set(offsetX);\n        y.set(offsetY);\n\n        if (returnTimeout.current !== null) {\n          window.clearTimeout(returnTimeout.current);\n        }\n        returnTimeout.current = window.setTimeout(() => {\n          x.set(0);\n          y.set(0);\n        }, returnDelay);\n      }\n    });\n\n    return () => {\n      unsubscribeX();\n      unsubscribeY();\n      if (returnTimeout.current !== null) {\n        window.clearTimeout(returnTimeout.current);\n      }\n    };\n  }, [mouseX, mouseY, radius, force, x, y, returnDelay, disabled]);\n\n  if (disabled) {\n    return <span className=\"inline-block whitespace-nowrap\">{word}</span>;\n  }\n\n  return (\n    <motion.span ref={wordRef} className=\"inline-block whitespace-nowrap\" style={{ x, y }}>\n      {word}\n    </motion.span>\n  );\n}\n",
      "type": "registry:ui"
    }
  ]
}