{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"circular-text","type":"registry:ui","title":"Circular Text","description":"Text set evenly around a slowly turning ring, with a slot in the middle for an icon or logo.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/circular-text.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { motion, useAnimationFrame, useMotionValue, useReducedMotion, useSpring } from \"motion/react\";\nimport { useEffect, useId, useRef, useState, type ReactNode } from \"react\";\n\ntype CircularTextProps = {\n  text: string;\n  /** Seconds for one full turn. 0 keeps the ring still. */\n  duration?: number;\n  /** What the ring does while hovered or while something inside it has focus. */\n  hoverEffect?: \"speedUp\" | \"pause\" | \"reverse\";\n  /** Width and height of the ring in pixels. */\n  size?: number;\n  fontSize?: number;\n  /** How many times the text goes around the ring. */\n  repeat?: number;\n  /** Placed after each repetition, so the seam looks like every other gap. */\n  separator?: string;\n  /** Content for the middle of the ring, such as an icon or a logo. */\n  children?: ReactNode;\n  className?: string;\n};\n\n/** Text set around a circle that turns slowly, with a slot in the middle for an icon or logo. */\nexport function CircularText({\n  text,\n  duration = 20,\n  hoverEffect = \"speedUp\",\n  size = 200,\n  fontSize = 15,\n  repeat = 2,\n  separator = \" • \",\n  children,\n  className = \"\",\n}: CircularTextProps) {\n  const pathId = `ring-${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  const reduce = useReducedMotion();\n  const [engaged, setEngaged] = useState(false);\n  const measureRef = useRef<SVGTextElement>(null);\n  const textRef = useRef<SVGTextElement>(null);\n\n  const base = !reduce && duration > 0 ? 360 / duration : 0;\n  const goal = !engaged ? base : hoverEffect === \"speedUp\" ? base * 4 : hoverEffect === \"pause\" ? 0 : -base;\n  const rotate = useMotionValue(0);\n  // Degrees per second, eased so speed changes never jerk.\n  const rate = useSpring(goal, { stiffness: 60, damping: 18 });\n\n  useEffect(() => {\n    rate.set(goal);\n  }, [goal, rate]);\n\n  useAnimationFrame((_, delta) => {\n    const r = rate.get();\n    if (Math.abs(r) < 0.01) return;\n    rotate.set((rotate.get() + (r * delta) / 1000) % 360);\n  });\n\n  const content = Array.from({ length: Math.max(1, Math.round(repeat)) }, () => `${text}${separator}`).join(\"\");\n  const c = size / 2;\n  const r = Math.max(4, c - fontSize * 0.9);\n  const circumference = 2 * Math.PI * r;\n  const path = `M ${c} ${c - r} A ${r} ${r} 0 1 1 ${c} ${c + r} A ${r} ${r} 0 1 1 ${c} ${c - r}`;\n\n  // Spread the letters so the text fills the ring exactly, whatever its length or font.\n  useEffect(() => {\n    const measure = measureRef.current;\n    const ring = textRef.current;\n    if (!measure || !ring) return;\n    let alive = true;\n    const fit = () => {\n      if (!alive) return;\n      const natural = measure.getComputedTextLength();\n      const chars = Array.from(content).length;\n      if (natural > 0 && chars > 0) ring.style.letterSpacing = `${(circumference - natural) / chars}px`;\n    };\n    fit();\n    document.fonts?.ready.then(fit);\n    return () => {\n      alive = false;\n    };\n  }, [content, circumference, fontSize]);\n\n  return (\n    <div\n      className={`relative inline-grid shrink-0 place-items-center ${className}`}\n      style={{ width: size, height: size }}\n      onPointerEnter={() => setEngaged(true)}\n      onPointerLeave={() => setEngaged(false)}\n      onFocus={() => setEngaged(true)}\n      onBlur={() => setEngaged(false)}\n    >\n      <span className=\"sr-only\">{text}</span>\n      <motion.div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ rotate }}>\n        <svg viewBox={`0 0 ${size} ${size}`} width={size} height={size} className=\"overflow-visible\">\n          <defs>\n            <path id={pathId} d={path} fill=\"none\" />\n          </defs>\n          <text ref={measureRef} fontSize={fontSize} visibility=\"hidden\" style={{ letterSpacing: 0, whiteSpace: \"pre\" }}>\n            {content}\n          </text>\n          <text ref={textRef} fontSize={fontSize} fill=\"currentColor\" style={{ whiteSpace: \"pre\" }}>\n            <textPath href={`#${pathId}`}>{content}</textPath>\n          </text>\n        </svg>\n      </motion.div>\n      {children ? <div className=\"relative\">{children}</div> : null}\n    </div>\n  );\n}\n"}]}