{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "map-block",
  "title": "Map Block",
  "description": "A live delivery map for a dashboard: a drawn city with river, parks and roads, drivers moving along dashed routes that fill in as they go, stops that tick off, a sidebar with ETAs and progress, filters for on-time and delayed, click to zoom to a driver with a stops card, drag to pan and zoom controls.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/map-block/map-block.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype Pt = [number, number];\n\nexport interface Delivery {\n  id: string;\n  driver: string;\n  avatar?: string;\n  vehicle: string;\n  /** Route as points in the 800 × 520 map space. */\n  route: Pt[];\n  stops: { name: string; at: number }[];\n  /** Starting progress along the route, 0–1. */\n  start: number;\n  /** Progress per second. */\n  speed: number;\n  status: \"on-time\" | \"delayed\";\n  color: string;\n}\n\nexport interface MapBlockProps {\n  title?: string;\n  deliveries?: Delivery[];\n  /** Pause the simulated movement. */\n  paused?: boolean;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", card: \"#121212\", border: \"rgba(255,255,255,0.09)\", chip: \"rgba(255,255,255,0.06)\", land: \"#141414\", block: \"#1A1A1A\", road: \"#262626\", major: \"#303030\", water: \"#0F1B26\", park: \"#122016\", on: \"#F5F4F1\", onText: \"#0A0A0A\", green: \"#4ADE80\", amber: \"#FBBF24\", ring: \"rgba(245,244,241,0.6)\", label: \"rgba(245,244,241,0.28)\", shadow: \"0 18px 40px -16px rgba(0,0,0,0.8)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.4)\", card: \"#FFFFFF\", border: \"rgba(10,10,10,0.09)\", chip: \"rgba(10,10,10,0.05)\", land: \"#F1F0EC\", block: \"#E7E5DF\", road: \"#FFFFFF\", major: \"#FFFFFF\", water: \"#CFE3F1\", park: \"#D7EBCF\", on: \"#0A0A0A\", onText: \"#FAFAF8\", green: \"#15803D\", amber: \"#B45309\", ring: \"rgba(10,10,10,0.5)\", label: \"rgba(10,10,10,0.35)\", shadow: \"0 18px 40px -20px rgba(0,0,0,0.25)\" },\n};\n\nconst ROADS: Pt[][] = [\n  [[0, 120], [800, 120]],\n  [[0, 260], [260, 260], [420, 300], [800, 300]],\n  [[0, 420], [800, 420]],\n  [[120, 0], [120, 520]],\n  [[300, 0], [300, 520]],\n  [[520, 0], [520, 520]],\n  [[680, 0], [680, 520]],\n  [[60, 520], [300, 260], [520, 120], [760, 0]],\n];\nconst MINOR: Pt[][] = [\n  [[0, 190], [800, 190]],\n  [[0, 350], [800, 350]],\n  [[0, 480], [800, 480]],\n  [[210, 0], [210, 520]],\n  [[410, 0], [410, 520]],\n  [[600, 0], [600, 520]],\n  [[750, 0], [750, 520]],\n];\n\nconst DEFAULT_DELIVERIES: Delivery[] = [\n  { id: \"d1\", driver: \"Amara D.\", avatar: \"/demo/45.webp\", vehicle: \"Van 12\", color: \"#FB923C\", status: \"on-time\", start: 0.08, speed: 0.018, route: [[120, 480], [120, 260], [300, 260], [300, 120], [520, 120], [680, 120], [680, 300]], stops: [{ name: \"Riverside Café\", at: 0.34 }, { name: \"Halcyon HQ\", at: 0.66 }, { name: \"Dock 4\", at: 1 }] },\n  { id: \"d2\", driver: \"Jonas W.\", avatar: \"/demo/42.webp\", vehicle: \"Bike 3\", color: \"#60A5FA\", status: \"delayed\", start: 0.3, speed: 0.012, route: [[750, 480], [600, 480], [600, 350], [410, 350], [410, 190], [210, 190]], stops: [{ name: \"Elm Pharmacy\", at: 0.45 }, { name: \"Library\", at: 1 }] },\n  { id: \"d3\", driver: \"Sofia R.\", avatar: \"/demo/44.webp\", vehicle: \"Van 7\", color: \"#4ADE80\", status: \"on-time\", start: 0.15, speed: 0.015, route: [[0, 420], [300, 420], [520, 420], [520, 300], [680, 300], [800, 300]], stops: [{ name: \"Market Hall\", at: 0.4 }, { name: \"Studio Nine\", at: 0.7 }, { name: \"East Depot\", at: 1 }] },\n];\nconst PLACES: { name: string; at: Pt }[] = [\n  { name: \"Old Town\", at: [180, 70] },\n  { name: \"Harbour\", at: [610, 470] },\n  { name: \"Westpark\", at: [60, 330] },\n  { name: \"Tech Quarter\", at: [600, 60] },\n];\n\nfunction lengths(route: Pt[]) {\n  const segs = route.slice(1).map((pt, i) => Math.hypot(pt[0] - route[i][0], pt[1] - route[i][1]));\n  return { segs, total: segs.reduce((a, b) => a + b, 0) };\n}\nfunction pointAt(route: Pt[], t: number): Pt {\n  const { segs, total } = lengths(route);\n  let d = Math.max(0, Math.min(1, t)) * total;\n  for (let i = 0; i < segs.length; i++) {\n    if (d <= segs[i]) {\n      const f = segs[i] ? d / segs[i] : 0;\n      return [route[i][0] + (route[i + 1][0] - route[i][0]) * f, route[i][1] + (route[i + 1][1] - route[i][1]) * f];\n    }\n    d -= segs[i];\n  }\n  return route[route.length - 1];\n}\nconst toPath = (pts: Pt[]) => pts.map((pt, i) => `${i ? \"L\" : \"M\"}${pt[0]},${pt[1]}`).join(\" \");\nfunction partial(route: Pt[], t: number): Pt[] {\n  const { segs, total } = lengths(route);\n  let d = t * total;\n  const out: Pt[] = [route[0]];\n  for (let i = 0; i < segs.length; i++) {\n    if (d >= segs[i]) {\n      out.push(route[i + 1]);\n      d -= segs[i];\n    } else {\n      out.push(pointAt(route, t));\n      break;\n    }\n  }\n  return out;\n}\n\nconst W = 800;\nconst H = 520;\n\nexport function MapBlock({ title = \"Live deliveries\", deliveries = DEFAULT_DELIVERIES, paused = false, theme = \"dark\", className }: MapBlockProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId().replace(/:/g, \"\");\n  const [elapsed, setElapsed] = React.useState(0);\n  const [selected, setSelected] = React.useState<string | null>(null);\n  const [view, setView] = React.useState({ k: 1, x: 0, y: 0 });\n  const [filter, setFilter] = React.useState<\"all\" | \"on-time\" | \"delayed\">(\"all\");\n  const [dragging, setDragging] = React.useState(false);\n  const drag = React.useRef<{ sx: number; sy: number; x: number; y: number; moved: boolean } | null>(null);\n  const svgRef = React.useRef<SVGSVGElement>(null);\n\n  React.useEffect(() => {\n    if (paused || reduce) return;\n    const t = setInterval(() => setElapsed((e) => e + 0.08), 80);\n    return () => clearInterval(t);\n  }, [paused, reduce]);\n\n  const progress = (d: Delivery) => Math.min(1, d.start + d.speed * elapsed);\n  const list = deliveries.filter((d) => filter === \"all\" || d.status === filter);\n  const sel = deliveries.find((d) => d.id === selected) ?? null;\n  const clamp = (v: { k: number; x: number; y: number }) => {\n    const k = Math.max(1, Math.min(3, v.k));\n    return { k, x: Math.min(0, Math.max(W - W * k, v.x)), y: Math.min(0, Math.max(H - H * k, v.y)) };\n  };\n  const focusOn = (d: Delivery | null) => {\n    setSelected(d?.id ?? null);\n    if (!d) return setView({ k: 1, x: 0, y: 0 });\n    const [px, py] = pointAt(d.route, progress(d));\n    const k = 2;\n    setView(clamp({ k, x: W / 2 - px * k, y: H / 2 - py * k }));\n  };\n  const zoom = (f: number) =>\n    setView((v) => {\n      const k = Math.max(1, Math.min(3, v.k * f));\n      const cx = W / 2;\n      const cy = H / 2;\n      return clamp({ k, x: cx - ((cx - v.x) / v.k) * k, y: cy - ((cy - v.y) / v.k) * k });\n    });\n  const toLocal = (e: React.PointerEvent) => {\n    const r = svgRef.current!.getBoundingClientRect();\n    return { x: ((e.clientX - r.left) / r.width) * W, y: ((e.clientY - r.top) / r.height) * H };\n  };\n\n  const onTime = deliveries.filter((d) => d.status === \"on-time\").length;\n  const eta = (d: Delivery) => Math.max(0, Math.round(((1 - progress(d)) / d.speed) / 6));\n  const nextStop = (d: Delivery) => d.stops.find((s) => s.at > progress(d) + 0.001) ?? d.stops[d.stops.length - 1];\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const selPt = sel ? pointAt(sel.route, progress(sel)) : null;\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-6xl px-4 py-10 @[640px]:px-6 @[640px]:py-14\">\n        <div className=\"grid overflow-hidden rounded-2xl border @[880px]:grid-cols-[300px_1fr]\" style={{ background: p.card, borderColor: p.border }}>\n          {/* Sidebar */}\n          <div className=\"flex min-w-0 flex-col border-b @[880px]:border-r @[880px]:border-b-0\" style={{ borderColor: p.border }}>\n            <div className=\"p-4\">\n              <h2 className=\"m-0 flex items-center gap-2 text-[16px] font-semibold tracking-[-0.01em]\">\n                <span className=\"relative flex h-2 w-2\">\n                  {!paused && !reduce && <span className=\"absolute inline-flex h-full w-full animate-ping rounded-full opacity-60\" style={{ background: p.green }} />}\n                  <span className=\"relative h-2 w-2 rounded-full\" style={{ background: p.green }} />\n                </span>\n                {title}\n              </h2>\n              <dl className=\"m-0 mt-3 grid grid-cols-3 gap-2 text-center\">\n                {[\n                  [\"Active\", String(deliveries.length)],\n                  [\"On time\", `${Math.round((onTime / deliveries.length) * 100)}%`],\n                  [\"Avg ETA\", `${Math.round(deliveries.reduce((s, d) => s + eta(d), 0) / deliveries.length)}m`],\n                ].map(([k, v]) => (\n                  <div key={k} className=\"rounded-lg px-2 py-2\" style={{ background: p.chip }}>\n                    <dt className=\"text-[11px]\" style={{ color: p.faint }}>\n                      {k}\n                    </dt>\n                    <dd className=\"m-0 text-[15px] font-semibold tabular-nums\">{v}</dd>\n                  </div>\n                ))}\n              </dl>\n              <div role=\"radiogroup\" aria-label=\"Filter deliveries\" className=\"mt-3 flex rounded-lg border p-0.5\" style={{ borderColor: p.border }}>\n                {(\n                  [\n                    [\"all\", \"All\"],\n                    [\"on-time\", \"On time\"],\n                    [\"delayed\", \"Delayed\"],\n                  ] as const\n                ).map(([id, l]) => (\n                  <button key={id} type=\"button\" role=\"radio\" aria-checked={filter === id} onClick={() => setFilter(id)} className={cn(\"relative h-7 flex-1 cursor-pointer rounded-md border-0 bg-transparent text-[12.5px]\", focus)} style={{ color: filter === id ? p.text : p.faint, ...ring }}>\n                    {filter === id && <motion.span layoutId={`${uid}-f`} className=\"absolute inset-0 rounded-md\" style={{ background: p.chip }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 38 }} />}\n                    <span className=\"relative\">{l}</span>\n                  </button>\n                ))}\n              </div>\n            </div>\n            <ul className=\"m-0 flex-1 list-none overflow-y-auto border-t p-2 @[880px]:max-h-[420px]\" style={{ borderColor: p.border }} aria-label=\"Deliveries\">\n              {list.map((d) => {\n                const on = selected === d.id;\n                const pr = progress(d);\n                return (\n                  <li key={d.id}>\n                    <button type=\"button\" aria-pressed={on} onClick={() => focusOn(on ? null : d)} className={cn(\"flex w-full cursor-pointer items-center gap-3 rounded-xl border-0 px-2.5 py-2.5 text-left\", focus)} style={{ background: on ? p.chip : \"transparent\", color: p.text, ...ring }}>\n                      <span className=\"relative shrink-0\">\n                        {d.avatar ? (\n                          // eslint-disable-next-line @next/next/no-img-element\n                          <img src={d.avatar} alt=\"\" className=\"h-9 w-9 rounded-full object-cover\" />\n                        ) : (\n                          <span className=\"flex h-9 w-9 items-center justify-center rounded-full text-[12px] font-semibold\" style={{ background: p.chip }}>\n                            {d.driver[0]}\n                          </span>\n                        )}\n                        <span className=\"absolute -right-0.5 -bottom-0.5 h-3 w-3 rounded-full border-2\" style={{ background: d.color, borderColor: p.card }} aria-hidden=\"true\" />\n                      </span>\n                      <span className=\"min-w-0 flex-1\">\n                        <span className=\"flex items-center justify-between gap-2\">\n                          <span className=\"truncate text-[13.5px] font-medium\">{d.driver}</span>\n                          <span className=\"text-[12px] font-semibold tabular-nums\" style={{ color: pr >= 1 ? p.green : p.text }}>\n                            {pr >= 1 ? \"Done\" : `${eta(d)} min`}\n                          </span>\n                        </span>\n                        <span className=\"mt-0.5 flex items-center justify-between gap-2 text-[12px]\" style={{ color: p.faint }}>\n                          <span className=\"truncate\">\n                            {d.vehicle} · {nextStop(d).name}\n                          </span>\n                          <span style={{ color: d.status === \"delayed\" ? p.amber : p.green }}>{d.status === \"delayed\" ? \"Delayed\" : \"On time\"}</span>\n                        </span>\n                        <span className=\"mt-2 block h-1 overflow-hidden rounded-full\" style={{ background: p.chip }} role=\"progressbar\" aria-label={`${d.driver} route progress`} aria-valuenow={Math.round(pr * 100)} aria-valuemin={0} aria-valuemax={100}>\n                          <span className=\"block h-full rounded-full\" style={{ width: `${pr * 100}%`, background: d.color }} />\n                        </span>\n                      </span>\n                    </button>\n                  </li>\n                );\n              })}\n            </ul>\n          </div>\n\n          {/* Map */}\n          <div className=\"relative min-w-0 overflow-hidden\" style={{ background: p.land }}>\n            <svg\n              ref={svgRef}\n              viewBox={`0 0 ${W} ${H}`}\n              className=\"block aspect-[800/520] w-full cursor-grab touch-none select-none active:cursor-grabbing\"\n              role=\"img\"\n              aria-label={`City map with ${deliveries.length} drivers. ${sel ? `Showing ${sel.driver}.` : \"\"}`}\n              onPointerDown={(e) => {\n                const l = toLocal(e);\n                drag.current = { sx: l.x, sy: l.y, x: view.x, y: view.y, moved: false };\n                (e.target as Element).setPointerCapture?.(e.pointerId);\n              }}\n              onPointerMove={(e) => {\n                const dr = drag.current;\n                if (!dr) return;\n                const l = toLocal(e);\n                if (Math.abs(l.x - dr.sx) + Math.abs(l.y - dr.sy) > 3) dr.moved = true;\n                if (dr.moved) {\n                  setDragging(true);\n                  setView((v) => clamp({ k: v.k, x: dr.x + (l.x - dr.sx), y: dr.y + (l.y - dr.sy) }));\n                }\n              }}\n              onPointerUp={() => {\n                drag.current = null;\n                setDragging(false);\n              }}\n              onDoubleClick={() => zoom(1.5)}\n            >\n              <motion.g initial={false} animate={{ x: view.x, y: view.y, scale: view.k }} transition={dragging || reduce ? { duration: 0 } : { type: \"spring\", stiffness: 120, damping: 22 }} style={{ originX: 0, originY: 0, transformBox: \"view-box\" }}>\n                <rect width={W} height={H} fill={p.land} />\n                {/* city blocks */}\n                {Array.from({ length: 8 }, (_, cx) =>\n                  Array.from({ length: 6 }, (_, cy) => <rect key={`${cx}-${cy}`} x={cx * 100 + 14} y={cy * 90 + 12} width={72} height={64} rx={6} fill={p.block} />),\n                )}\n                <path d=\"M0,300 C120,330 160,250 260,270 S420,360 520,330 S700,250 800,280 L800,330 C700,300 640,380 520,385 S340,320 260,320 S100,380 0,350 Z\" fill={p.water} />\n                <rect x={330} y={20} width={160} height={80} rx={10} fill={p.park} />\n                <rect x={20} y={300} width={80} height={100} rx={10} fill={p.park} />\n                {MINOR.map((r, i) => (\n                  <path key={`m${i}`} d={toPath(r)} stroke={p.road} strokeWidth={4} fill=\"none\" />\n                ))}\n                {ROADS.map((r, i) => (\n                  <path key={`r${i}`} d={toPath(r)} stroke={p.major} strokeWidth={8} fill=\"none\" strokeLinecap=\"round\" />\n                ))}\n                {PLACES.map((pl) => (\n                  <text key={pl.name} x={pl.at[0]} y={pl.at[1]} fill={p.label} fontSize={11} fontWeight={600} letterSpacing=\"0.08em\" textAnchor=\"middle\" style={{ textTransform: \"uppercase\" }} fontFamily=\"ui-sans-serif, system-ui\">\n                    {pl.name}\n                  </text>\n                ))}\n                {/* routes */}\n                {deliveries.map((d) => {\n                  const dim = sel && sel.id !== d.id;\n                  const hidden = filter !== \"all\" && d.status !== filter;\n                  return (\n                    <g key={d.id} opacity={hidden ? 0.15 : dim ? 0.35 : 1}>\n                      <path d={toPath(d.route)} stroke={d.color} strokeOpacity={0.3} strokeWidth={sel?.id === d.id ? 6 : 4} fill=\"none\" strokeLinejoin=\"round\" strokeDasharray=\"2 8\" strokeLinecap=\"round\" />\n                      <path d={toPath(partial(d.route, progress(d)))} stroke={d.color} strokeWidth={sel?.id === d.id ? 6 : 4} fill=\"none\" strokeLinejoin=\"round\" strokeLinecap=\"round\" />\n                      {d.stops.map((s) => {\n                        const [sx, sy] = pointAt(d.route, s.at);\n                        const passed = progress(d) >= s.at;\n                        return <circle key={s.name} cx={sx} cy={sy} r={6} fill={passed ? d.color : p.card} stroke={d.color} strokeWidth={2.5} />;\n                      })}\n                    </g>\n                  );\n                })}\n                {/* drivers */}\n                {deliveries.map((d) => {\n                  const [x, y] = pointAt(d.route, progress(d));\n                  const hidden = filter !== \"all\" && d.status !== filter;\n                  return (\n                    <g key={`v${d.id}`} transform={`translate(${x},${y})`} opacity={hidden ? 0.2 : 1} style={{ cursor: \"pointer\" }} onClick={() => !drag.current?.moved && focusOn(d)}>\n                      {!reduce && <circle r={16} fill={d.color} opacity={0.18}>\n                        <animate attributeName=\"r\" values=\"10;20;10\" dur=\"2s\" repeatCount=\"indefinite\" />\n                      </circle>}\n                      <circle r={9} fill={d.color} stroke={p.card} strokeWidth={3} />\n                    </g>\n                  );\n                })}\n              </motion.g>\n            </svg>\n\n            {/* Popup */}\n            <AnimatePresence>\n              {sel && selPt && (\n                <motion.div key={sel.id} initial={reduce ? false : { opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"pointer-events-auto absolute top-3 left-3 w-56 rounded-xl border p-3\" style={{ background: p.card, borderColor: p.border, boxShadow: p.shadow }} role=\"status\">\n                  <div className=\"flex items-center justify-between\">\n                    <span className=\"text-[13px] font-semibold\">{sel.driver}</span>\n                    <button type=\"button\" aria-label=\"Close driver details\" onClick={() => focusOn(null)} className={cn(\"flex h-6 w-6 cursor-pointer items-center justify-center rounded-md border-0 bg-transparent\", focus)} style={{ color: p.faint, ...ring }}>\n                      ×\n                    </button>\n                  </div>\n                  <p className=\"m-0 mt-0.5 text-[12px]\" style={{ color: p.faint }}>\n                    {sel.vehicle} · {Math.round(progress(sel) * 100)}% of route\n                  </p>\n                  <ol className=\"m-0 mt-2.5 flex list-none flex-col gap-1.5 p-0\">\n                    {sel.stops.map((s) => {\n                      const done = progress(sel) >= s.at;\n                      return (\n                        <li key={s.name} className=\"flex items-center gap-2 text-[12.5px]\" style={{ color: done ? p.faint : p.text, textDecoration: done ? \"line-through\" : undefined }}>\n                          <span className=\"h-2 w-2 rounded-full border-2\" style={{ borderColor: sel.color, background: done ? sel.color : \"transparent\" }} aria-hidden=\"true\" />\n                          {s.name}\n                        </li>\n                      );\n                    })}\n                  </ol>\n                </motion.div>\n              )}\n            </AnimatePresence>\n\n            {/* Zoom */}\n            <div className=\"absolute right-3 bottom-3 flex flex-col overflow-hidden rounded-lg border\" style={{ borderColor: p.border, background: p.card, boxShadow: p.shadow }}>\n              {[\n                [\"Zoom in\", \"+\", () => zoom(1.4)],\n                [\"Zoom out\", \"−\", () => zoom(1 / 1.4)],\n                [\"Reset view\", \"⤢\", () => focusOn(null)],\n              ].map(([label, ch, fn], i) => (\n                <button key={label as string} type=\"button\" aria-label={label as string} onClick={fn as () => void} className={cn(\"flex h-8 w-8 cursor-pointer items-center justify-center border-0 bg-transparent text-[15px]\", i > 0 && \"border-t\", focus, \"focus-visible:ring-inset\")} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                  {ch as string}\n                </button>\n              ))}\n            </div>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default MapBlock;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}