{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "analog-clock",
  "title": "Analog Clock",
  "author": "VenusUI",
  "description": "A station clock whose needle waits at twelve; drag the minute hand to set it by hand.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/analog-clock.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { RotateCcw } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface AnalogClockProps extends React.ComponentProps<\"div\"> {\n  /** IANA time zone, for example \"Asia/Tokyo\". Defaults to the visitor's own. */\n  timeZone?: string\n  /** Shown under the dial, for example a city. */\n  label?: string\n}\n\nconst mod = (value: number, by: number) => ((value % by) + by) % by\n\nfunction formatTime(totalMinutes: number) {\n  const hour = Math.floor(mod(totalMinutes, 720) / 60) || 12\n  const minute = String(mod(totalMinutes, 60)).padStart(2, \"0\")\n  return `${hour}:${minute} ${mod(totalMinutes, 1440) < 720 ? \"AM\" : \"PM\"}`\n}\n\n/**\n * A station clock. The needle sweeps round, waits at twelve, and the minute\n * hand clicks forward. Drag the minute hand, or use the arrow keys, to set\n * the clock by hand; \"Back to now\" returns it to the real time.\n */\nfunction AnalogClock({ timeZone, label, className, ...props }: AnalogClockProps) {\n  const hourHand = React.useRef<SVGGElement>(null)\n  const minuteHand = React.useRef<SVGGElement>(null)\n  const secondHand = React.useRef<SVGGElement>(null)\n  const dial = React.useRef<SVGSVGElement>(null)\n  const offset = React.useRef(0)\n  const shownMinutes = React.useRef(0)\n  const dragging = React.useRef(false)\n  const [time, setTime] = React.useState<string | null>(null)\n  const [adjusted, setAdjusted] = React.useState(false)\n\n  React.useEffect(() => {\n    const parts = timeZone\n      ? new Intl.DateTimeFormat(\"en-US\", { timeZone, hourCycle: \"h23\", hour: \"numeric\", minute: \"numeric\" })\n      : null\n    const rotate = (hand: SVGGElement | null, angle: number) => hand?.setAttribute(\"transform\", `rotate(${angle.toFixed(2)} 100 100)`)\n    let frame = 0\n    let lastLabel = \"\"\n\n    const tick = () => {\n      const now = new Date()\n      let minutes = now.getHours() * 60 + now.getMinutes()\n      if (parts) {\n        const read = (type: string) => Number(parts.formatToParts(now).find((part) => part.type === type)?.value ?? 0)\n        minutes = read(\"hour\") * 60 + read(\"minute\")\n      }\n      const seconds = now.getSeconds() + now.getMilliseconds() / 1000\n      const total = minutes + offset.current\n      shownMinutes.current = total\n      const settle = dragging.current ? 1 : 1 - (1 - Math.min(1, seconds / 0.25)) ** 3\n      rotate(hourHand.current, mod(total, 720) / 2)\n      rotate(minuteHand.current, (mod(total, 60) - 1 + settle) * 6)\n      rotate(secondHand.current, Math.min(1, seconds / 58.5) * 360)\n      const next = formatTime(total)\n      if (next !== lastLabel) {\n        lastLabel = next\n        setTime(next)\n      }\n      frame = requestAnimationFrame(tick)\n    }\n\n    frame = requestAnimationFrame(tick)\n    return () => cancelAnimationFrame(frame)\n  }, [timeZone])\n\n  const nudge = (minutes: number) => {\n    offset.current += minutes\n    setAdjusted(offset.current !== 0)\n  }\n\n  const dragTo = (event: React.PointerEvent) => {\n    const box = dial.current?.getBoundingClientRect()\n    if (!box) return\n    const angle = Math.atan2(event.clientX - (box.left + box.width / 2), box.top + box.height / 2 - event.clientY)\n    const target = mod(Math.round((angle / (Math.PI * 2)) * 60), 60)\n    nudge(mod(target - mod(shownMinutes.current, 60) + 30, 60) - 30)\n  }\n\n  return (\n    <div data-slot=\"analog-clock\" className={cn(\"flex w-64 max-w-full flex-col items-center gap-3\", className)} {...props}>\n      <svg ref={dial} viewBox=\"0 0 200 200\" className=\"w-full touch-none drop-shadow-[0_14px_18px_rgb(0_0_0/0.3)]\" role=\"group\" aria-label={label ? `Clock, ${label}` : \"Clock\"}>\n        <circle cx=\"100\" cy=\"100\" r=\"98\" fill=\"#27272a\" />\n        <circle cx=\"100\" cy=\"100\" r=\"93\" fill=\"#a1a1aa\" />\n        <circle cx=\"100\" cy=\"100\" r=\"90\" fill=\"#fafaf7\" />\n        {Array.from({ length: 60 }, (_, i) => (\n          <line key={i} x1=\"100\" y1=\"14\" x2=\"100\" y2={i % 5 === 0 ? 25 : 18} stroke=\"#18181b\" strokeWidth={i % 5 === 0 ? 2.6 : 0.8} transform={`rotate(${i * 6} 100 100)`} />\n        ))}\n        {[12, 3, 6, 9].map((hour) => {\n          const angle = (hour / 12) * Math.PI * 2\n          return (\n            <text key={hour} x={(100 + 62 * Math.sin(angle)).toFixed(2)} y={(100 - 62 * Math.cos(angle)).toFixed(2)} textAnchor=\"middle\" dominantBaseline=\"central\" fontSize=\"15\" fontWeight=\"600\" fill=\"#18181b\" fontFamily=\"ui-sans-serif, system-ui, sans-serif\">\n              {hour}\n            </text>\n          )\n        })}\n        <g ref={hourHand} transform=\"rotate(304 100 100)\">\n          <path d=\"M96.5 116h7l-1.2-64a2.3 2.3 0 0 0-4.6 0Z\" fill=\"#18181b\" />\n        </g>\n        <g\n          ref={minuteHand}\n          transform=\"rotate(48 100 100)\"\n          role=\"slider\"\n          tabIndex={0}\n          aria-label=\"Set the minutes\"\n          aria-valuemin={0}\n          aria-valuemax={59}\n          aria-valuenow={time ? Number(time.split(\":\")[1].slice(0, 2)) : 0}\n          aria-valuetext={time ?? undefined}\n          onKeyDown={(event) => {\n            const step = { ArrowRight: 1, ArrowUp: 1, ArrowLeft: -1, ArrowDown: -1, PageUp: 5, PageDown: -5 }[event.key]\n            if (!step) return\n            event.preventDefault()\n            nudge(step)\n          }}\n          onPointerDown={(event) => {\n            event.currentTarget.setPointerCapture(event.pointerId)\n            dragging.current = true\n          }}\n          onPointerMove={(event) => {\n            if (dragging.current) dragTo(event)\n          }}\n          onPointerUp={() => {\n            dragging.current = false\n          }}\n          onPointerCancel={() => {\n            dragging.current = false\n          }}\n          className=\"cursor-grab outline-none active:cursor-grabbing [&:focus-visible>path]:fill-blue-700\"\n        >\n          <rect x=\"90\" y=\"18\" width=\"20\" height=\"104\" fill=\"transparent\" />\n          <path d=\"M97.4 120h5.2l-.9-96a1.7 1.7 0 0 0-3.4 0Z\" fill=\"#18181b\" />\n        </g>\n        <g ref={secondHand} className=\"pointer-events-none\">\n          <path d=\"M99.5 132h1V30l2.2 9h-5.4l2.2-9Z\" fill=\"#b45309\" />\n          <circle cx=\"100\" cy=\"100\" r=\"4.5\" fill=\"#b45309\" />\n          <circle cx=\"100\" cy=\"100\" r=\"1.5\" fill=\"#fafaf7\" />\n        </g>\n      </svg>\n      <div className=\"flex min-h-8 flex-wrap items-center justify-center gap-x-3 gap-y-1 text-sm\">\n        {label ? <span className=\"font-medium\">{label}</span> : null}\n        <time className=\"font-mono text-muted-foreground tabular-nums\">{time ?? \" \"}</time>\n        {adjusted ? (\n          <button\n            type=\"button\"\n            onClick={() => nudge(-offset.current)}\n            className=\"inline-flex items-center gap-1 rounded-md px-1.5 py-1 text-xs text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50\"\n          >\n            <RotateCcw aria-hidden=\"true\" className=\"size-3\" />\n            Back to now\n          </button>\n        ) : null}\n      </div>\n    </div>\n  )\n}\n\nexport { AnalogClock }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "data-display",
    "interactive"
  ],
  "type": "registry:ui"
}