{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"orbit","type":"registry:ui","title":"Orbit","description":"Items circling a center on one or more rings, staying upright and showing labels on hover.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/orbit.tsx","type":"registry:ui","content":"\"use client\";\n\nimport {\n  animate,\n  AnimatePresence,\n  motion,\n  useAnimationFrame,\n  useMotionValue,\n  useReducedMotion,\n  useTransform,\n  type MotionValue,\n} from \"motion/react\";\nimport { useState, type FocusEvent, type ReactNode } from \"react\";\n\nexport type OrbitItem = { icon: ReactNode; label: string };\n\nexport type OrbitRing = {\n  /** Distance from the center, in pixels. */\n  radius: number;\n  /** Seconds for one lap. */\n  speed: number;\n  items: OrbitItem[];\n  /** Turn this ring the other way. */\n  reverse?: boolean;\n};\n\ntype OrbitProps = {\n  rings: OrbitRing[];\n  /** Content in the middle. */\n  center?: ReactNode;\n  /** Turn every ring the other way. */\n  reverse?: boolean;\n  /** Ease to a stop while the pointer or keyboard focus is on the orbit. */\n  pauseOnHover?: boolean;\n  /** Item size, in pixels. */\n  itemSize?: number;\n  /** Draw the ring paths. */\n  showRings?: boolean;\n  /** Accessible name of the item list. */\n  label?: string;\n  className?: string;\n};\n\nconst TAU = Math.PI * 2;\n\n/** Items circling a center on one or more rings. They stay upright, and show their label on hover or focus. */\nexport function Orbit({\n  rings,\n  center,\n  reverse = false,\n  pauseOnHover = true,\n  itemSize = 44,\n  showRings = true,\n  label = \"Orbit\",\n  className = \"\",\n}: OrbitProps) {\n  const reduce = Boolean(useReducedMotion());\n  // 1 is full speed, 0 is stopped.\n  const pace = useMotionValue(1);\n  const reach = Math.max(0, ...rings.map((r) => r.radius));\n  const box = reach * 2 + itemSize;\n\n  function setPaused(paused: boolean) {\n    if (!pauseOnHover) return;\n    animate(pace, paused ? 0 : 1, { duration: paused ? 0.4 : 0.7, ease: \"easeOut\" });\n  }\n\n  return (\n    <div\n      className={`relative shrink-0 ${className}`}\n      style={{ width: box, height: box }}\n      onPointerEnter={() => setPaused(true)}\n      onPointerLeave={() => setPaused(false)}\n      onFocus={() => setPaused(true)}\n      onBlur={(e: FocusEvent<HTMLDivElement>) => {\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setPaused(false);\n      }}\n    >\n      {showRings\n        ? rings.map((ring, i) => (\n            <div\n              key={i}\n              aria-hidden=\"true\"\n              className=\"pointer-events-none absolute left-1/2 top-1/2 rounded-full border border-dashed border-ink-500\"\n              style={{ width: ring.radius * 2, height: ring.radius * 2, marginLeft: -ring.radius, marginTop: -ring.radius }}\n            />\n          ))\n        : null}\n      {center ? <div className=\"absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2\">{center}</div> : null}\n      <ul aria-label={label} className=\"absolute inset-0\">\n        {rings.map((ring, i) => (\n          <Ring\n            key={i}\n            ring={ring}\n            direction={(ring.reverse ? -1 : 1) * (reverse ? -1 : 1)}\n            pace={pace}\n            itemSize={itemSize}\n            reduce={reduce}\n          />\n        ))}\n      </ul>\n    </div>\n  );\n}\n\ntype RingProps = {\n  ring: OrbitRing;\n  direction: number;\n  pace: MotionValue<number>;\n  itemSize: number;\n  reduce: boolean;\n};\n\nfunction Ring({ ring, direction, pace, itemSize, reduce }: RingProps) {\n  const angle = useMotionValue(0);\n\n  useAnimationFrame((_, delta) => {\n    if (reduce || ring.speed <= 0) return;\n    const step = direction * pace.get() * (TAU / ring.speed) * (Math.min(delta, 64) / 1000);\n    angle.set((angle.get() + step) % TAU);\n  });\n\n  return (\n    <>\n      {ring.items.map((item, i) => (\n        <OrbitNode\n          key={`${item.label}-${i}`}\n          item={item}\n          angle={angle}\n          offset={(i / ring.items.length) * TAU}\n          radius={ring.radius}\n          size={itemSize}\n          reduce={reduce}\n        />\n      ))}\n    </>\n  );\n}\n\ntype OrbitNodeProps = {\n  item: OrbitItem;\n  angle: MotionValue<number>;\n  offset: number;\n  radius: number;\n  size: number;\n  reduce: boolean;\n};\n\nfunction OrbitNode({ item, angle, offset, radius, size, reduce }: OrbitNodeProps) {\n  const [active, setActive] = useState(false);\n  // Position from the angle instead of rotating the ring, so the item itself never turns.\n  const x = useTransform(angle, (a) => Math.cos(a + offset - Math.PI / 2) * radius);\n  const y = useTransform(angle, (a) => Math.sin(a + offset - Math.PI / 2) * radius);\n\n  return (\n    <motion.li\n      className=\"absolute left-1/2 top-1/2\"\n      style={{ x, y, width: size, height: size, marginLeft: -size / 2, marginTop: -size / 2, zIndex: active ? 10 : 1 }}\n    >\n      <span\n        tabIndex={0}\n        onPointerEnter={() => setActive(true)}\n        onPointerLeave={() => setActive(false)}\n        onFocus={() => setActive(true)}\n        onBlur={() => setActive(false)}\n        className=\"grid size-full place-items-center rounded-full border border-ink-600 bg-ink-800 text-bone shadow-[0_10px_24px_-12px_rgb(0_0_0/0.9)] transition-colors hover:border-ember/60 [&>svg]:size-1/2\"\n      >\n        {item.icon}\n        <span className=\"sr-only\">{item.label}</span>\n      </span>\n      <AnimatePresence>\n        {active ? (\n          <motion.span\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute bottom-full left-1/2 mb-2 -translate-x-1/2 whitespace-nowrap rounded-lg border border-ink-600 bg-ink-800 px-2.5 py-1 text-xs font-semibold text-bone shadow-lg\"\n            initial={{ opacity: 0, y: reduce ? 0 : 4 }}\n            animate={{ opacity: 1, y: 0 }}\n            exit={{ opacity: 0 }}\n            transition={{ duration: 0.15 }}\n          >\n            {item.label}\n          </motion.span>\n        ) : null}\n      </AnimatePresence>\n    </motion.li>\n  );\n}\n"}]}