{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dotted-globe",
  "title": "Dotted Globe",
  "author": "VenusUI",
  "description": "A WebGL sphere of evenly spaced dots that slowly turns; drag or use the arrow keys to spin it.",
  "dependencies": [
    "three",
    "@react-three/fiber"
  ],
  "devDependencies": [
    "@types/three"
  ],
  "registryDependencies": [
    "https://venusui.com/r/use-scene-state.json"
  ],
  "files": [
    {
      "path": "registry/default/ui/dotted-globe.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Canvas, useFrame } from \"@react-three/fiber\"\nimport type { Points } from \"three\"\n\nimport { cn } from \"@/lib/utils\"\nimport { useSceneState } from \"@/registry/default/hooks/use-scene-state\"\n\ninterface DottedGlobeProps {\n  /** Number of dots on the sphere. */\n  dots?: number\n  /** Dot size in pixels. */\n  dotSize?: number\n  /** Rotation speed in radians per second. */\n  speed?: number\n  /** Accessible description of the graphic. */\n  label?: string\n  className?: string\n}\n\n/** Evenly spread points on a unit sphere (Fibonacci lattice). */\nfunction spherePoints(count: number): Float32Array {\n  const positions = new Float32Array(count * 3)\n  const golden = Math.PI * (3 - Math.sqrt(5))\n  for (let i = 0; i < count; i++) {\n    const y = 1 - (i / (count - 1)) * 2\n    const radius = Math.sqrt(1 - y * y)\n    const theta = golden * i\n    positions.set([Math.cos(theta) * radius, y, Math.sin(theta) * radius], i * 3)\n  }\n  return positions\n}\n\ninterface DragState {\n  active: boolean\n  x: number\n  y: number\n  /** Rotation still to apply, in radians, gathered from pointer and keyboard. */\n  pendingX: number\n  pendingY: number\n}\n\ninterface PendingRotation {\n  x: number\n  y: number\n  dragging: boolean\n}\n\ninterface GlobeProps {\n  dots: number\n  dotSize: number\n  speed: number\n  color: string\n  /** Returns (and clears) rotation gathered from drags and arrow keys since the last frame. */\n  takeRotation: () => PendingRotation\n}\n\nfunction Globe({ dots, dotSize, speed, color, takeRotation }: GlobeProps) {\n  const ref = React.useRef<Points>(null)\n  const positions = React.useMemo(() => spherePoints(dots), [dots])\n\n  useFrame((_, delta) => {\n    const globe = ref.current\n    if (!globe) return\n    const pending = takeRotation()\n    if (!pending.dragging) globe.rotation.y += speed * delta\n    globe.rotation.y += pending.y\n    globe.rotation.x = Math.max(-1.2, Math.min(1.2, globe.rotation.x + pending.x))\n  })\n\n  return (\n    <points ref={ref} rotation={[0.35, 0, 0]}>\n      <bufferGeometry>\n        <bufferAttribute attach=\"attributes-position\" args={[positions, 3]} />\n      </bufferGeometry>\n      <pointsMaterial color={color} size={dotSize} sizeAttenuation={false} transparent opacity={0.85} />\n    </points>\n  )\n}\n\n/**\n * A sphere of evenly spaced dots that slowly turns. Drag it, or focus it and\n * use the arrow keys, to spin it. Dots use the CSS text color, so it follows\n * your theme. Rendering pauses off screen; with reduced motion it only moves\n * when you drag it.\n */\nfunction DottedGlobe({ dots = 1600, dotSize = 2, speed = 0.15, label = \"Rotating globe made of dots\", className }: DottedGlobeProps) {\n  const ref = React.useRef<HTMLDivElement>(null)\n  const { color, active, reducedMotion } = useSceneState(ref)\n  const drag = React.useRef<DragState>({ active: false, x: 0, y: 0, pendingX: 0, pendingY: 0 })\n  const [interacting, setInteracting] = React.useState(false)\n\n  function nudge(dx: number, dy: number) {\n    drag.current.pendingY += dx\n    drag.current.pendingX += dy\n  }\n\n  const takeRotation = React.useCallback((): PendingRotation => {\n    const state = drag.current\n    const pending = { x: state.pendingX, y: state.pendingY, dragging: state.active }\n    state.pendingX = 0\n    state.pendingY = 0\n    return pending\n  }, [])\n\n  return (\n    <div\n      ref={ref}\n      role=\"img\"\n      aria-label={`${label}. Drag or use the arrow keys to rotate.`}\n      tabIndex={0}\n      data-slot=\"dotted-globe\"\n      className={cn(\n        \"relative aspect-square w-full max-w-md cursor-grab touch-none rounded-full text-foreground outline-none focus-visible:ring-3 focus-visible:ring-ring/50 active:cursor-grabbing\",\n        className\n      )}\n      onPointerDown={(event) => {\n        event.currentTarget.setPointerCapture(event.pointerId)\n        drag.current.active = true\n        drag.current.x = event.clientX\n        drag.current.y = event.clientY\n        setInteracting(true)\n      }}\n      onPointerMove={(event) => {\n        if (!drag.current.active) return\n        nudge((event.clientX - drag.current.x) * 0.008, (event.clientY - drag.current.y) * 0.008)\n        drag.current.x = event.clientX\n        drag.current.y = event.clientY\n      }}\n      onPointerUp={() => {\n        drag.current.active = false\n        setInteracting(false)\n      }}\n      onPointerCancel={() => {\n        drag.current.active = false\n        setInteracting(false)\n      }}\n      onKeyDown={(event) => {\n        const step = 0.15\n        const moves: Record<string, [number, number]> = {\n          ArrowLeft: [-step, 0],\n          ArrowRight: [step, 0],\n          ArrowUp: [0, -step],\n          ArrowDown: [0, step],\n        }\n        const move = moves[event.key]\n        if (!move) return\n        event.preventDefault()\n        nudge(...move)\n        setInteracting(true)\n        setTimeout(() => setInteracting(false), 300)\n      }}\n    >\n      <Canvas\n        camera={{ position: [0, 0, 2.6], fov: 45 }}\n        dpr={[1, 2]}\n        frameloop={active || interacting ? \"always\" : \"demand\"}\n        fallback={<p className=\"p-4 text-sm text-muted-foreground\">3D graphics are not available in this browser.</p>}\n      >\n        <Globe dots={dots} dotSize={dotSize} speed={reducedMotion ? 0 : speed} color={color} takeRotation={takeRotation} />\n      </Canvas>\n    </div>\n  )\n}\n\nexport { DottedGlobe, type DottedGlobeProps }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "3d",
    "backgrounds",
    "interactive"
  ],
  "type": "registry:ui"
}