{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "world-clock",
  "title": "World Clock",
  "author": "VenusUI",
  "description": "Real analog clocks for several cities with smooth second hands and day and night faces.",
  "files": [
    {
      "path": "registry/default/ui/world-clock.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface ClockZone {\n  city: string\n  /** IANA time zone, e.g. \"Asia/Tokyo\". */\n  timeZone: string\n}\n\ninterface WorldClockProps extends React.ComponentProps<\"ul\"> {\n  zones: ClockZone[]\n}\n\ninterface Parts {\n  hours: number\n  minutes: number\n  seconds: number\n}\n\n/** The wall-clock time in a zone, from Intl (no time-zone library needed). */\nfunction partsIn(timeZone: string, date: Date): Parts {\n  const parts = new Intl.DateTimeFormat(\"en-GB\", { timeZone, hour: \"numeric\", minute: \"numeric\", second: \"numeric\", hourCycle: \"h23\" }).formatToParts(date)\n  const get = (type: string) => Number(parts.find((p) => p.type === type)?.value ?? 0)\n  return { hours: get(\"hour\"), minutes: get(\"minute\"), seconds: get(\"second\") }\n}\n\n/** The zone's UTC offset in minutes at `date`, e.g. 540 for Tokyo. */\nfunction utcOffset(timeZone: string, date: Date) {\n  const parts = new Intl.DateTimeFormat(\"en-US\", {\n    timeZone,\n    year: \"numeric\",\n    month: \"numeric\",\n    day: \"numeric\",\n    hour: \"numeric\",\n    minute: \"numeric\",\n    hourCycle: \"h23\",\n  }).formatToParts(date)\n  const get = (type: string) => Number(parts.find((p) => p.type === type)?.value ?? 0)\n  const asUtc = Date.UTC(get(\"year\"), get(\"month\") - 1, get(\"day\"), get(\"hour\"), get(\"minute\"))\n  return Math.round((asUtc - Math.floor(date.getTime() / 60000) * 60000) / 60000)\n}\n\n/** Hours ahead of or behind the viewer, e.g. \"+8h\", \"-13.5h\" or \"Same time\". */\nfunction offsetLabel(timeZone: string, date: Date) {\n  const diff = utcOffset(timeZone, date) + date.getTimezoneOffset()\n  if (diff === 0) return \"Same time\"\n  const h = diff / 60\n  return `${h > 0 ? \"+\" : \"\"}${Number.isInteger(h) ? h : h.toFixed(1)}h`\n}\n\nconst pad = (n: number) => String(n).padStart(2, \"0\")\n\n/**\n * Analog clocks for several cities. Hands move smoothly (one shared\n * animation frame loop updates them directly, without re-rendering); faces\n * turn dark at night in that city. With reduced motion the second hand\n * ticks once a second.\n */\nfunction WorldClock({ zones, className, ...props }: WorldClockProps) {\n  const hands = React.useRef(new Map<string, { hour: HTMLElement | null; minute: HTMLElement | null; second: HTMLElement | null; digital: HTMLElement | null }>())\n  const times = React.useRef(new Map<string, Parts>())\n  const [snapshot, setSnapshot] = React.useState<{ night: boolean[]; offsets: string[] } | null>(null)\n  // Restart the loop only when the zones themselves change, not when a new\n  // array with the same zones is passed on every render.\n  const zoneKey = zones.map((z) => `${z.city}@${z.timeZone}`).join(\"|\")\n  const zonesRef = React.useRef(zones)\n  React.useEffect(() => {\n    zonesRef.current = zones\n  })\n\n  React.useEffect(() => {\n    const zones = zonesRef.current\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n    let frame = 0\n    let interval = 0\n    let lastSecond = -1\n    let lastMinute = -1\n\n    const update = () => {\n      const now = new Date()\n      if (now.getSeconds() !== lastSecond) {\n        lastSecond = now.getSeconds()\n        // Once a second, read each zone's wall time (Intl is too slow for every frame).\n        zones.forEach((zone) => {\n          const parts = partsIn(zone.timeZone, now)\n          times.current.set(zone.timeZone, parts)\n          const digital = hands.current.get(zone.timeZone)?.digital\n          if (digital) digital.textContent = `${pad(parts.hours)}:${pad(parts.minutes)}`\n        })\n        // Once a minute, update day/night faces and offsets (this does re-render).\n        if (now.getMinutes() !== lastMinute) {\n          lastMinute = now.getMinutes()\n          setSnapshot({\n            night: zones.map((z) => {\n              const h = times.current.get(z.timeZone)?.hours ?? 12\n              return h < 6 || h >= 19\n            }),\n            offsets: zones.map((z) => offsetLabel(z.timeZone, now)),\n          })\n        }\n      }\n      const ms = reduced ? 0 : now.getMilliseconds()\n      zones.forEach((zone) => {\n        const el = hands.current.get(zone.timeZone)\n        const p = times.current.get(zone.timeZone)\n        if (!el || !p) return\n        const s = p.seconds + ms / 1000\n        const m = p.minutes + s / 60\n        const h = (p.hours % 12) + m / 60\n        if (el.second) el.second.style.transform = `rotate(${s * 6}deg)`\n        if (el.minute) el.minute.style.transform = `rotate(${m * 6}deg)`\n        if (el.hour) el.hour.style.transform = `rotate(${h * 30}deg)`\n      })\n    }\n\n    if (reduced) {\n      update()\n      interval = window.setInterval(update, 1000)\n    } else {\n      const loop = () => {\n        update()\n        frame = requestAnimationFrame(loop)\n      }\n      frame = requestAnimationFrame(loop)\n    }\n    return () => {\n      cancelAnimationFrame(frame)\n      clearInterval(interval)\n    }\n  }, [zoneKey])\n\n  const register = (timeZone: string, key: \"hour\" | \"minute\" | \"second\" | \"digital\") => (el: HTMLElement | null) => {\n    const entry = hands.current.get(timeZone) ?? { hour: null, minute: null, second: null, digital: null }\n    entry[key] = el\n    hands.current.set(timeZone, entry)\n  }\n\n  return (\n    <ul data-slot=\"world-clock\" className={cn(\"flex flex-wrap justify-center gap-6\", className)} {...props}>\n      {zones.map((zone, i) => {\n        const night = snapshot?.night[i] ?? false\n        return (\n          <li key={zone.timeZone} className=\"flex w-32 flex-col items-center gap-3\">\n            <span\n              aria-hidden=\"true\"\n              className={cn(\n                \"relative block aspect-square w-full rounded-full transition-colors duration-700\",\n                night\n                  ? \"bg-neutral-900 text-white shadow-[inset_0_0_0_6px_rgb(64_64_64),0_10px_24px_-12px_rgb(0_0_0/0.6)]\"\n                  : \"bg-white text-neutral-900 shadow-[inset_0_0_0_6px_rgb(229_229_229),0_10px_24px_-12px_rgb(0_0_0/0.35)]\"\n              )}\n            >\n              {/* Hour marks */}\n              {Array.from({ length: 12 }, (_, h) => (\n                <span key={h} className=\"absolute inset-[9%]\" style={{ transform: `rotate(${h * 30}deg)` }}>\n                  <span className={cn(\"absolute top-0 left-1/2 -translate-x-1/2 rounded-full bg-current\", h % 3 === 0 ? \"h-[10%] w-[3%]\" : \"h-[6%] w-[2%] opacity-50\")} />\n                </span>\n              ))}\n              {snapshot ? (\n                <>\n                  <span ref={register(zone.timeZone, \"hour\")} className=\"absolute inset-0\">\n                    <span className=\"absolute bottom-1/2 left-1/2 h-[26%] w-[4.5%] -translate-x-1/2 rounded-full bg-current\" />\n                  </span>\n                  <span ref={register(zone.timeZone, \"minute\")} className=\"absolute inset-0\">\n                    <span className=\"absolute bottom-1/2 left-1/2 h-[37%] w-[3%] -translate-x-1/2 rounded-full bg-current\" />\n                  </span>\n                  <span ref={register(zone.timeZone, \"second\")} className=\"absolute inset-0\">\n                    <span className=\"absolute bottom-[42%] left-1/2 h-[46%] w-[1.5%] -translate-x-1/2 rounded-full bg-orange-500\" />\n                  </span>\n                </>\n              ) : null}\n              <span className=\"absolute top-1/2 left-1/2 size-[7%] -translate-1/2 rounded-full bg-orange-500 ring-2 ring-current\" />\n            </span>\n            <span className=\"text-center\">\n              <span className=\"block text-sm font-medium\">{zone.city}</span>\n              <span className=\"block text-xs text-muted-foreground\">\n                <span ref={register(zone.timeZone, \"digital\")} className=\"font-mono tabular-nums\">\n                  --:--\n                </span>\n                {snapshot ? ` · ${snapshot.offsets[i]}` : null}\n              </span>\n            </span>\n          </li>\n        )\n      })}\n    </ul>\n  )\n}\n\nexport { WorldClock }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "data-display"
  ],
  "type": "registry:ui"
}