{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "maps-02",
  "title": "Map of live runs",
  "description": "A dotted world map of six regions joined by routes: each run handed off travels its route as a light in the colour of its agent and lands with a ring while the count rolls, and every region is a button whose bubble says how many runs it holds now.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/mesh-tile.json",
    "https://ui.ndekocode.dev/r/motion-dotted-map.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/maps/maps-02/index.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { useDocumentVisible } from '@/registry/ndeko/hooks/use-agent-run';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { seriesColorOf } from '@/registry/ndeko/lib/agent-run';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport {\n  AGENT_IDS,\n  AGENTS,\n  MAP_TITLE,\n  REGIONS,\n  type AgentId,\n  type RegionId,\n} from './data';\nimport { MapStage } from './map-stage';\nimport {\n  INITIAL,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  totalRunsOf,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nfunction liveWordOf(count: number) {\n  if (count === 1) {\n    return 'run live';\n  }\n  return 'runs live';\n}\n\nfunction regionsWordOf(count: number) {\n  if (count === 1) {\n    return '1 region';\n  }\n  return `${count} regions`;\n}\n\nfunction AgentEntry({ id }: { id: AgentId }) {\n  const agent = AGENTS[id];\n  const color = seriesColorOf(agent.series);\n\n  return (\n    <span className='flex items-center gap-1.5'>\n      <MeshTile seed={agent.name} color={color} size='sm' />\n      {agent.name}\n    </span>\n  );\n}\n\n/** What the marks of the map mean: a light takes the colour of the agent whose run it carries. */\nfunction Legend() {\n  return (\n    <ul\n      aria-label='Legend'\n      className='text-muted-foreground flex flex-wrap items-center gap-x-5 gap-y-2 text-xs'\n    >\n      <li className='flex items-center gap-1.5'>\n        <span\n          aria-hidden='true'\n          className='bg-primary ring-card size-2.5 rounded-full ring-2'\n        />\n        Region, larger with more runs\n      </li>\n      <li className='flex items-center gap-1.5'>\n        <span\n          aria-hidden='true'\n          className='bg-foreground/30 h-px w-4 rounded-full'\n        />\n        Route\n      </li>\n      <li className='flex flex-wrap items-center gap-x-3 gap-y-1'>\n        <span>Run handed off by</span>\n        {AGENT_IDS.map((id) => (\n          <AgentEntry key={id} id={id} />\n        ))}\n      </li>\n    </ul>\n  );\n}\n\nexport default function Maps02() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const isVisible = useDocumentVisible();\n  const isOnScreen = isInView && isVisible;\n  const total = totalRunsOf(state);\n  const canReplay = isFinished && !isAutoplaying;\n  const message = spokenUnless(isAutoplaying, state.notice);\n  const regionsWord = regionsWordOf(REGIONS.length);\n\n  function toggle(id: RegionId) {\n    act({ type: 'toggled', id });\n  }\n\n  function clear() {\n    act({ type: 'cleared' });\n  }\n\n  return (\n    <div\n      ref={ref}\n      className='bg-background text-foreground @container min-h-dvh w-full'\n    >\n      <div className='mx-auto flex max-w-5xl flex-col gap-4 p-4 @3xl:gap-5 @3xl:p-8'>\n        <header className='flex flex-wrap items-end gap-x-4 gap-y-3'>\n          <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n            <h1 className='text-lg font-semibold text-balance'>{MAP_TITLE}</h1>\n            <p className='text-muted-foreground flex flex-wrap items-center gap-x-2 gap-y-1 text-xs'>\n              Runs handed off between {regionsWord}\n              <Badge variant='secondary'>Illustrative</Badge>\n            </p>\n          </div>\n          <ReplayButton\n            isShown={canReplay}\n            onReplay={restart}\n            label='Replay the map'\n          />\n          <p className='flex items-baseline gap-1.5'>\n            <MotionNumber\n              value={total}\n              className='text-2xl leading-8 font-semibold'\n            />\n            <span className='text-muted-foreground text-xs'>\n              {liveWordOf(total)}\n            </span>\n          </p>\n        </header>\n\n        <div className='bg-foreground/[0.03] rounded-xl p-3 @2xl:p-6'>\n          <MapStage\n            runs={state.runs}\n            flights={state.flights}\n            landings={state.landings}\n            selectedId={state.selectedId}\n            pressed={pressed}\n            isActive={isOnScreen}\n            onToggle={toggle}\n            onClear={clear}\n          />\n        </div>\n\n        <Legend />\n      </div>\n      <LiveRegion message={message} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/maps-02/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/maps/maps-02/map-stage.tsx",
      "content": "'use client';\n\nimport { useEffect, useLayoutEffect, useRef } from 'react';\n\nimport { DottedMap } from '@/components/core/dotted-map';\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { seriesColorOf } from '@/registry/ndeko/lib/agent-run';\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport {\n  AGENTS,\n  regionOf,\n  REGIONS,\n  ROUTES,\n  routeBetween,\n  touchesRegion,\n  type Region,\n  type RegionId,\n} from './data';\nimport {\n  arcPathOf,\n  bendOf,\n  pointOf,\n  shareOf,\n  VIEW_BOX,\n  VIEW_WIDTH,\n  type MapPoint,\n  type Share,\n} from './projection';\nimport { FLIGHT_MS, pinnedLineOf, type Flight } from './session';\n\n/** The first half of a parabola, as an easing: fast away from the chord, slow at the top. */\nconst RISE = 'cubic-bezier(0.3333, 0.6667, 0.6667, 1)';\n\n/** The second half: slow from the top, fast back onto the chord. */\nconst FALL = 'cubic-bezier(0.3333, 0, 0.6667, 0.3333)';\n\n/** A marker this close to the top of the map opens its bubble below, inside the map. */\nconst NEAR_TOP = 0.35;\n\nconst DOT_SCALE_MIN = 0.75;\n\nconst DOT_SCALE_MAX = 1.35;\n\nconst DOT_SCALE_PER_RUN = 0.035;\n\nconst ROUTE_LINE =\n  'fill-none stroke-[1.25px] transition-[stroke] duration-200 [vector-effect:non-scaling-stroke]';\n\nconst MARKER = [\n  'group/marker absolute size-6 -translate-x-1/2 -translate-y-1/2 cursor-pointer rounded-full outline-none',\n  'transition-[scale,background-color] duration-150 ease-(--ease-out-strong) active:scale-[0.97]',\n  'hover:z-10 focus-visible:z-10 data-[pinned=true]:z-10',\n  'focus-visible:ring-ring focus-visible:ring-offset-background focus-visible:ring-2 focus-visible:ring-offset-2',\n].join(' ');\n\nconst DOT =\n  'bg-primary size-3 rounded-full transition-[scale,box-shadow] duration-300 ease-(--ease-out-strong)';\n\nconst LANDING_RING =\n  'ring-primary/60 absolute size-3 scale-[2.6] rounded-full opacity-0 ring-1 transition-[scale,opacity] duration-700 ease-(--ease-out-strong) starting:scale-100 starting:opacity-100';\n\nconst BUBBLE = [\n  'surface-raised pointer-events-none absolute left-1/2 z-10 w-max max-w-48 rounded-lg px-2 py-1 text-start text-xs leading-4',\n  'opacity-0 transition-opacity duration-100',\n  'group-hover/marker:opacity-100 group-focus-visible/marker:opacity-100 group-data-[pinned=true]/marker:opacity-100',\n].join(' ');\n\ntype DrawnRoute = {\n  id: string;\n  from: RegionId;\n  to: RegionId;\n  path: string;\n};\n\nfunction placeOf(id: RegionId): MapPoint {\n  const region = regionOf(id);\n  return pointOf(region.latitude, region.longitude);\n}\n\nconst DRAWN_ROUTES: DrawnRoute[] = ROUTES.map((route) => {\n  const from = placeOf(route.from);\n  const to = placeOf(route.to);\n  const path = arcPathOf(from, to);\n  return { ...route, path };\n});\n\nfunction shareOfRegion(id: RegionId) {\n  const point = placeOf(id);\n  return shareOf(point);\n}\n\nfunction percentOf(share: number) {\n  const percent = share * 100;\n  return `${percent}%`;\n}\n\nfunction anchorStyleOf(share: Share) {\n  return { left: percentOf(share.left), top: percentOf(share.top) };\n}\n\nfunction clamp(value: number, min: number, max: number) {\n  const atLeast = Math.max(value, min);\n  return Math.min(atLeast, max);\n}\n\n/** A busier region draws a larger dot. */\nfunction dotStyleOf(runs: number) {\n  const grown = runs * DOT_SCALE_PER_RUN;\n  const raw = DOT_SCALE_MIN + grown;\n  const scale = clamp(raw, DOT_SCALE_MIN, DOT_SCALE_MAX);\n  return { scale: String(scale) };\n}\n\nfunction dotRingOf(isPinned: boolean) {\n  if (isPinned) {\n    return 'ring-primary/25 ring-4';\n  }\n  return 'ring-card ring-2';\n}\n\nfunction routeToneOf(isLit: boolean) {\n  if (isLit) {\n    return 'stroke-primary/70';\n  }\n  return 'stroke-foreground/20';\n}\n\nfunction bubblePlaceOf(isNearTop: boolean) {\n  if (isNearTop) {\n    return 'top-full mt-1';\n  }\n  return 'bottom-full mb-1';\n}\n\n/** The bubble slides from its left edge to its right edge as its marker crosses the map, so it never leaves it. */\nfunction bubbleShiftOf(share: Share) {\n  const percent = share.left * 100;\n  return { transform: `translateX(-${percent}%)` };\n}\n\nfunction runsNowWordOf(count: number) {\n  if (count === 1) {\n    return 'run now';\n  }\n  return 'runs now';\n}\n\ntype Motion = {\n  travel: Keyframe[];\n  bend: Keyframe[];\n};\n\n/** The bend of the route a flight follows, whichever way it travels it, so the light stays on the drawn line. */\nfunction routeBendOf(flight: Flight) {\n  const route = routeBetween(flight.from, flight.to);\n  let fromId = flight.from;\n  let toId = flight.to;\n  if (route) {\n    fromId = route.from;\n    toId = route.to;\n  }\n  const from = placeOf(fromId);\n  const to = placeOf(toId);\n  return bendOf(from, to);\n}\n\n/**\n * A quadratic curve is the straight line between its ends plus a parabola away from it. The light\n * travels the line on one element and the parabola on the one inside it, both on transform.\n */\nfunction motionOf(flight: Flight, scale: number): Motion {\n  const from = placeOf(flight.from);\n  const to = placeOf(flight.to);\n  const bend = routeBendOf(flight);\n  const spanX = to.x - from.x;\n  const spanY = to.y - from.y;\n  const dx = spanX * scale;\n  const dy = spanY * scale;\n  const topX = bend.x * scale;\n  const topY = bend.y * scale;\n  const travel = [\n    { translate: '0px 0px', opacity: 0 },\n    { opacity: 1, offset: 0.12 },\n    { opacity: 1, offset: 0.86 },\n    { translate: `${dx}px ${dy}px`, opacity: 0 },\n  ];\n  const lift = [\n    { translate: '0px 0px', easing: RISE },\n    { translate: `${topX}px ${topY}px`, offset: 0.5, easing: FALL },\n    { translate: '0px 0px' },\n  ];\n  return { travel, bend: lift };\n}\n\nfunction RouteLayer({ selectedId }: { selectedId: RegionId | null }) {\n  return (\n    <svg\n      viewBox={VIEW_BOX}\n      aria-hidden='true'\n      className='pointer-events-none absolute inset-0 size-full overflow-visible'\n    >\n      {DRAWN_ROUTES.map((route) => {\n        const isLit = touchesRegion(route, selectedId);\n        return (\n          <path\n            key={route.id}\n            d={route.path}\n            className={cn(ROUTE_LINE, routeToneOf(isLit))}\n          />\n        );\n      })}\n    </svg>\n  );\n}\n\ntype FlightLightProps = {\n  flight: Flight;\n  /** False off screen and in a hidden tab: the light waits where it is, as the session does. */\n  isActive: boolean;\n};\n\n/** One light, once: it leaves when its run departs and fades as the run lands. */\nfunction FlightLight({ flight, isActive }: FlightLightProps) {\n  const travelRef = useRef<HTMLSpanElement>(null);\n  const bendRef = useRef<HTMLSpanElement>(null);\n  const animations = useRef<Animation[]>([]);\n  const start = shareOfRegion(flight.from);\n  const agent = AGENTS[flight.agentId];\n  const color = seriesColorOf(agent.series);\n  const dotStyle = { backgroundColor: color };\n\n  useLayoutEffect(() => {\n    const travel = travelRef.current;\n    const bend = bendRef.current;\n    const overlay = travel?.closest<HTMLElement>('[data-map-overlay]');\n    const hasElements = travel !== null && bend !== null;\n    if (!hasElements || !overlay) {\n      return;\n    }\n    const scale = overlay.clientWidth / VIEW_WIDTH;\n    const motion = motionOf(flight, scale);\n    const timing: KeyframeAnimationOptions = {\n      duration: FLIGHT_MS,\n      fill: 'forwards',\n    };\n    const moving = travel.animate(motion.travel, timing);\n    const bending = bend.animate(motion.bend, timing);\n    animations.current = [moving, bending];\n    return () => {\n      moving.cancel();\n      bending.cancel();\n      animations.current = [];\n    };\n  }, [flight]);\n\n  /** A finished light is never paused: playing it again would send it back to its start. */\n  useEffect(() => {\n    for (const animation of animations.current) {\n      const isRunning = animation.playState === 'running';\n      const isPaused = animation.playState === 'paused';\n      const shouldPause = !isActive && isRunning;\n      const shouldResume = isActive && isPaused;\n      if (shouldPause) {\n        animation.pause();\n      }\n      if (shouldResume) {\n        animation.play();\n      }\n    }\n  }, [isActive]);\n\n  return (\n    <span\n      aria-hidden='true'\n      style={anchorStyleOf(start)}\n      className='pointer-events-none absolute size-0'\n    >\n      <span ref={travelRef} className='absolute opacity-0'>\n        <span ref={bendRef} className='absolute'>\n          <span\n            style={dotStyle}\n            className='ring-card absolute -top-1 -left-1 size-2 rounded-full ring-2'\n          />\n        </span>\n      </span>\n    </span>\n  );\n}\n\ntype RegionMarkerProps = {\n  region: Region;\n  runs: number;\n  isPinned: boolean;\n  isPressed: boolean;\n  /** The flight that landed here last: a ring answers each new one. */\n  landingId: string | undefined;\n  onToggle: (id: RegionId) => void;\n};\n\nfunction RegionMarker({\n  region,\n  runs,\n  isPinned,\n  isPressed,\n  landingId,\n  onToggle,\n}: RegionMarkerProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const share = shareOfRegion(region.id);\n  const isNearTop = share.top < NEAR_TOP;\n  const hasLanding = landingId !== undefined;\n  const showsRing = hasLanding && !shouldReduceMotion;\n\n  return (\n    <span style={anchorStyleOf(share)} className='absolute size-0'>\n      <button\n        type='button'\n        aria-pressed={isPinned}\n        aria-label={pinnedLineOf(region.id, runs)}\n        data-pinned={isPinned}\n        onClick={() => onToggle(region.id)}\n        className={cn(MARKER, pressedQuietOf(isPressed))}\n      >\n        <span\n          aria-hidden='true'\n          className='absolute inset-0 flex items-center justify-center'\n        >\n          {showsRing && <span key={landingId} className={LANDING_RING} />}\n          <span\n            style={dotStyleOf(runs)}\n            className={cn(DOT, dotRingOf(isPinned))}\n          />\n        </span>\n        <span\n          aria-hidden='true'\n          style={bubbleShiftOf(share)}\n          className={cn(BUBBLE, bubblePlaceOf(isNearTop))}\n        >\n          <span className='block font-medium'>\n            {region.name}, {region.place}\n          </span>\n          <span className='text-muted-foreground flex items-baseline gap-1'>\n            <MotionNumber value={runs} />\n            {runsNowWordOf(runs)}\n          </span>\n        </span>\n      </button>\n    </span>\n  );\n}\n\nexport type MapStageProps = {\n  runs: Record<RegionId, number>;\n  flights: Flight[];\n  landings: Partial<Record<RegionId, string>>;\n  selectedId: RegionId | null;\n  /** The marker a demonstration presses, shown held down. */\n  pressed: string | null;\n  isActive: boolean;\n  onToggle: (id: RegionId) => void;\n  onClear: () => void;\n};\n\n/**\n * The dotted map with an overlay drawn in its own units: routes as curves, a light along a route for\n * each run handed off, and a button on each region. Under reduced motion the routes stay drawn and\n * still, and no light travels.\n */\nexport function MapStage({\n  runs,\n  flights,\n  landings,\n  selectedId,\n  pressed,\n  isActive,\n  onToggle,\n  onClear,\n}: MapStageProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const showsFlights = !shouldReduceMotion;\n\n  function clearOnEscape(event: React.KeyboardEvent<HTMLDivElement>) {\n    const isEscape = event.key === 'Escape';\n    const hasPinned = selectedId !== null;\n    if (isEscape && hasPinned) {\n      onClear();\n    }\n  }\n\n  return (\n    <div className='relative'>\n      <DottedMap\n        label='World map of live runs'\n        dotClassName='text-foreground/15'\n      />\n      <div\n        data-map-overlay\n        onKeyDown={clearOnEscape}\n        className='absolute inset-0'\n      >\n        <RouteLayer selectedId={selectedId} />\n        {showsFlights &&\n          flights.map((flight) => (\n            <FlightLight key={flight.id} flight={flight} isActive={isActive} />\n          ))}\n        {REGIONS.map((region) => (\n          <RegionMarker\n            key={region.id}\n            region={region}\n            runs={runs[region.id]}\n            isPinned={region.id === selectedId}\n            isPressed={pressed === `marker-${region.id}`}\n            landingId={landings[region.id]}\n            onToggle={onToggle}\n          />\n        ))}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/maps-02/map-stage.tsx"
    },
    {
      "path": "registry/ndeko/blocks/maps/maps-02/projection.ts",
      "content": "/**\n * The dotted map is equirectangular: 106 by 40 units over these bounds, drawn in a view box with\n * half a unit of edge. Its overlay places points the same way, so markers sit on the land dots.\n */\nconst MAP_WIDTH = 106;\n\nconst MAP_HEIGHT = 40;\n\nconst EDGE = 0.5;\n\nconst LONGITUDE_MIN = -180;\n\nconst LONGITUDE_SPAN = 360;\n\nconst LATITUDE_MAX = 80;\n\nconst LATITUDE_SPAN = 136;\n\nconst BOTH_EDGES = EDGE * 2;\n\nexport const VIEW_WIDTH = MAP_WIDTH + BOTH_EDGES;\n\nconst VIEW_HEIGHT = MAP_HEIGHT + BOTH_EDGES;\n\nexport const VIEW_BOX = `${-EDGE} ${-EDGE} ${VIEW_WIDTH} ${VIEW_HEIGHT}`;\n\n/** A route bows away from its chord by this share of its length, within these bounds, in map units. */\nconst BOW_SHARE = 0.15;\n\nconst BOW_MIN = 1;\n\nconst BOW_MAX = 5;\n\nexport type MapPoint = {\n  x: number;\n  y: number;\n};\n\nexport type Share = {\n  left: number;\n  top: number;\n};\n\nfunction clamp(value: number, min: number, max: number) {\n  const atLeast = Math.max(value, min);\n  return Math.min(atLeast, max);\n}\n\nfunction scaled(point: MapPoint, factor: number): MapPoint {\n  const x = point.x * factor;\n  const y = point.y * factor;\n  return { x, y };\n}\n\nfunction added(first: MapPoint, second: MapPoint): MapPoint {\n  const x = first.x + second.x;\n  const y = first.y + second.y;\n  return { x, y };\n}\n\nexport function pointOf(latitude: number, longitude: number): MapPoint {\n  const fromWest = longitude - LONGITUDE_MIN;\n  const fromNorth = LATITUDE_MAX - latitude;\n  const westShare = fromWest / LONGITUDE_SPAN;\n  const northShare = fromNorth / LATITUDE_SPAN;\n  const x = westShare * MAP_WIDTH;\n  const y = northShare * MAP_HEIGHT;\n  return { x, y };\n}\n\n/** Where a point sits in the box of the map, from 0 to 1 on each side. */\nexport function shareOf(point: MapPoint): Share {\n  const fromLeft = point.x + EDGE;\n  const fromTop = point.y + EDGE;\n  const left = fromLeft / VIEW_WIDTH;\n  const top = fromTop / VIEW_HEIGHT;\n  return { left, top };\n}\n\nfunction midpointOf(from: MapPoint, to: MapPoint): MapPoint {\n  const sum = added(from, to);\n  return scaled(sum, 0.5);\n}\n\n/** Of the two directions square to a chord, the one that points up the map, so routes bow north. */\nfunction bowDirectionOf(from: MapPoint, to: MapPoint): MapPoint {\n  const dx = to.x - from.x;\n  const dy = to.y - from.y;\n  const length = Math.hypot(dx, dy);\n  const across = { x: dy, y: -dx };\n  const first = scaled(across, 1 / length);\n  const second = scaled(first, -1);\n  if (second.y < first.y) {\n    return second;\n  }\n  return first;\n}\n\n/**\n * How far the middle of a route stands from its chord. A quadratic curve reaches half the distance\n * to its control point, so the control point stands twice as far. A light that travels the route\n * either way uses the bend of the route as it is listed, so it follows the drawn curve.\n */\nexport function bendOf(from: MapPoint, to: MapPoint): MapPoint {\n  const dx = to.x - from.x;\n  const dy = to.y - from.y;\n  const length = Math.hypot(dx, dy);\n  const share = length * BOW_SHARE;\n  const bow = clamp(share, BOW_MIN, BOW_MAX);\n  const direction = bowDirectionOf(from, to);\n  return scaled(direction, bow);\n}\n\nexport function arcPathOf(from: MapPoint, to: MapPoint) {\n  const middle = midpointOf(from, to);\n  const bend = bendOf(from, to);\n  const reach = scaled(bend, 2);\n  const control = added(middle, reach);\n  return `M ${from.x} ${from.y} Q ${control.x} ${control.y} ${to.x} ${to.y}`;\n}\n",
      "type": "registry:component",
      "target": "components/blocks/maps-02/projection.ts"
    },
    {
      "path": "registry/ndeko/blocks/maps/maps-02/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport {\n  AGENTS,\n  regionOf,\n  REGIONS,\n  RUNS,\n  type AgentId,\n  type RegionId,\n} from './data';\n\n/** A run on its way from one region to another, drawn as a light along their route. */\nexport type Flight = {\n  id: string;\n  agentId: AgentId;\n  from: RegionId;\n  to: RegionId;\n};\n\nexport type MapState = {\n  /** Runs live in each region. A run in flight belongs to none until it lands. */\n  runs: Record<RegionId, number>;\n  flights: Flight[];\n  /** The last flight that landed in each region: a ring answers it there. */\n  landings: Partial<Record<RegionId, string>>;\n  /** The marker pinned open, with its routes lit. */\n  selectedId: RegionId | null;\n  /** The last change, said to screen readers. */\n  notice: string;\n};\n\nexport type MapAction =\n  | { type: 'departed'; flight: Flight }\n  | { type: 'landed'; id: string }\n  | { type: 'started'; region: RegionId }\n  | { type: 'finished'; region: RegionId }\n  | { type: 'toggled'; id: RegionId }\n  | { type: 'cleared' };\n\ntype Step = SessionStep<MapState, MapAction>;\n\n/** How long a light takes along its route. The run lands when it arrives. */\nexport const FLIGHT_MS = 1400;\n\nexport const INITIAL: MapState = {\n  runs: RUNS,\n  flights: [],\n  landings: {},\n  selectedId: null,\n  notice: '',\n};\n\nexport function runsWordOf(count: number) {\n  if (count === 1) {\n    return '1 run';\n  }\n  return `${count} runs`;\n}\n\n/** Europe, Frankfurt: 12 runs now. */\nexport function pinnedLineOf(id: RegionId, runs: number) {\n  const region = regionOf(id);\n  const count = runsWordOf(runs);\n  return `${region.name}, ${region.place}: ${count} now`;\n}\n\nexport function handoffLineOf(flight: Flight) {\n  const agent = AGENTS[flight.agentId].name;\n  const from = regionOf(flight.from).name;\n  const to = regionOf(flight.to).name;\n  return `${agent} handed a run from ${from} to ${to}`;\n}\n\nfunction withRuns(\n  runs: Record<RegionId, number>,\n  id: RegionId,\n  change: number\n): Record<RegionId, number> {\n  const shifted = runs[id] + change;\n  const count = Math.max(0, shifted);\n  return { ...runs, [id]: count };\n}\n\nfunction withRegionRuns(\n  state: MapState,\n  id: RegionId,\n  change: number\n): MapState {\n  const runs = withRuns(state.runs, id, change);\n  return { ...state, runs };\n}\n\nfunction departed(state: MapState, flight: Flight): MapState {\n  const isFlying = state.flights.some(\n    (candidate) => candidate.id === flight.id\n  );\n  if (isFlying) {\n    return state;\n  }\n  const runs = withRuns(state.runs, flight.from, -1);\n  return { ...state, runs, flights: [...state.flights, flight] };\n}\n\nfunction landed(state: MapState, id: string): MapState {\n  const flight = state.flights.find((candidate) => candidate.id === id);\n  if (!flight) {\n    return state;\n  }\n  const runs = withRuns(state.runs, flight.to, 1);\n  const flights = state.flights.filter((candidate) => candidate.id !== id);\n  const landings = { ...state.landings, [flight.to]: flight.id };\n  const notice = handoffLineOf(flight);\n  return { ...state, runs, flights, landings, notice };\n}\n\nfunction toggled(state: MapState, id: RegionId): MapState {\n  if (state.selectedId === id) {\n    return { ...state, selectedId: null, notice: '' };\n  }\n  const notice = pinnedLineOf(id, state.runs[id]);\n  return { ...state, selectedId: id, notice };\n}\n\nexport function reducer(state: MapState, action: MapAction): MapState {\n  switch (action.type) {\n    case 'departed':\n      return departed(state, action.flight);\n    case 'landed':\n      return landed(state, action.id);\n    case 'started':\n      return withRegionRuns(state, action.region, 1);\n    case 'finished':\n      return withRegionRuns(state, action.region, -1);\n    case 'toggled':\n      return toggled(state, action.id);\n    case 'cleared':\n      return { ...state, selectedId: null, notice: '' };\n  }\n}\n\n/** Every live run, those in flight included: a hand-off moves a run, it does not end it. */\nexport function totalRunsOf(state: MapState) {\n  let total = state.flights.length;\n  for (const region of REGIONS) {\n    total += state.runs[region.id];\n  }\n  return total;\n}\n\nfunction flightOf(\n  id: string,\n  agentId: AgentId,\n  from: RegionId,\n  to: RegionId\n): Flight {\n  return { id, agentId, from, to };\n}\n\nfunction departs(after: number, flight: Flight): Step {\n  return { after, action: { type: 'departed', flight } };\n}\n\nfunction lands(after: number, flight: Flight): Step {\n  return { after, action: { type: 'landed', id: flight.id } };\n}\n\n/** The demonstration pins a marker open, or closes the one it pinned. */\nfunction points(after: number, id: RegionId): Step {\n  return {\n    after,\n    by: 'demo',\n    press: `marker-${id}`,\n    action: { type: 'toggled', id },\n  };\n}\n\nconst EAST_TO_EUROPE = flightOf(\n  'east-europe',\n  'researcher',\n  'us-east',\n  'europe'\n);\n\nconst EUROPE_TO_INDIA = flightOf('europe-india', 'coder', 'europe', 'india');\n\nconst WEST_TO_EAST = flightOf('west-east', 'writer', 'us-west', 'us-east');\n\nconst INDIA_TO_ASIA = flightOf(\n  'india-asia',\n  'researcher',\n  'india',\n  'asia-pacific'\n);\n\nconst EAST_TO_SOUTH = flightOf(\n  'east-south',\n  'coder',\n  'us-east',\n  'south-america'\n);\n\nconst SOUTH_TO_EAST = flightOf(\n  'south-east',\n  'writer',\n  'south-america',\n  'us-east'\n);\n\n/**\n * Two flights overlap once, and every run that leaves a region is made up by one that arrives or\n * starts there, so the map ends the round as it began it.\n */\nexport const SCRIPT: Step[] = [\n  departs(1400, EAST_TO_EUROPE),\n  lands(FLIGHT_MS, EAST_TO_EUROPE),\n  points(600, 'europe'),\n  departs(1200, EUROPE_TO_INDIA),\n  departs(700, WEST_TO_EAST),\n  lands(700, EUROPE_TO_INDIA),\n  lands(700, WEST_TO_EAST),\n  points(900, 'india'),\n  departs(1100, INDIA_TO_ASIA),\n  lands(FLIGHT_MS, INDIA_TO_ASIA),\n  departs(800, EAST_TO_SOUTH),\n  lands(FLIGHT_MS, EAST_TO_SOUTH),\n  departs(700, SOUTH_TO_EAST),\n  lands(FLIGHT_MS, SOUTH_TO_EAST),\n  { after: 600, action: { type: 'finished', region: 'asia-pacific' } },\n  { after: 800, action: { type: 'started', region: 'us-west' } },\n  points(800, 'india'),\n];\n\n/** Under reduced motion every route is drawn and still, with Europe pinned open to show its routes. */\nexport const RESTING: MapState = { ...INITIAL, selectedId: 'europe' };\n\nexport const LOOP_AFTER_MS = 2000;\n",
      "type": "registry:component",
      "target": "components/blocks/maps-02/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/maps/maps-02/data.ts",
      "content": "import type { SeriesSlot } from '@/registry/ndeko/lib/agent-run';\n\nexport const MAP_TITLE = 'Live runs';\n\nexport type RegionId =\n  'us-west' | 'us-east' | 'south-america' | 'europe' | 'india' | 'asia-pacific';\n\nexport type Region = {\n  id: RegionId;\n  name: string;\n  place: string;\n  latitude: number;\n  longitude: number;\n};\n\n/** From west to east: the order Tab follows across the map. */\nexport const REGIONS: Region[] = [\n  {\n    id: 'us-west',\n    name: 'US West',\n    place: 'Oregon',\n    latitude: 45.6,\n    longitude: -121.18,\n  },\n  {\n    id: 'us-east',\n    name: 'US East',\n    place: 'Virginia',\n    latitude: 38.9,\n    longitude: -77.04,\n  },\n  {\n    id: 'south-america',\n    name: 'South America',\n    place: 'São Paulo',\n    latitude: -23.55,\n    longitude: -46.63,\n  },\n  {\n    id: 'europe',\n    name: 'Europe',\n    place: 'Frankfurt',\n    latitude: 50.11,\n    longitude: 8.68,\n  },\n  {\n    id: 'india',\n    name: 'India',\n    place: 'Mumbai',\n    latitude: 19.08,\n    longitude: 72.88,\n  },\n  {\n    id: 'asia-pacific',\n    name: 'Asia Pacific',\n    place: 'Singapore',\n    latitude: 1.35,\n    longitude: 103.82,\n  },\n];\n\nexport function regionOf(id: RegionId) {\n  const region = REGIONS.find((candidate) => candidate.id === id);\n  return region ?? REGIONS[0];\n}\n\nexport type Route = {\n  id: string;\n  from: RegionId;\n  to: RegionId;\n};\n\n/** The routes runs are handed along. None crosses the edge of the map. */\nexport const ROUTES: Route[] = [\n  { id: 'us-west:us-east', from: 'us-west', to: 'us-east' },\n  { id: 'us-east:europe', from: 'us-east', to: 'europe' },\n  { id: 'us-east:south-america', from: 'us-east', to: 'south-america' },\n  { id: 'europe:india', from: 'europe', to: 'india' },\n  { id: 'india:asia-pacific', from: 'india', to: 'asia-pacific' },\n];\n\nfunction joins(route: Route, first: RegionId, second: RegionId) {\n  const isSameWay = route.from === first && route.to === second;\n  const isOtherWay = route.from === second && route.to === first;\n  return isSameWay || isOtherWay;\n}\n\n/** The route between two regions, whichever way it is listed. */\nexport function routeBetween(first: RegionId, second: RegionId) {\n  const route = ROUTES.find((candidate) => joins(candidate, first, second));\n  return route ?? null;\n}\n\nexport function touchesRegion(route: Route, id: RegionId | null) {\n  return route.from === id || route.to === id;\n}\n\nexport type AgentId = 'researcher' | 'writer' | 'coder';\n\nexport type Agent = {\n  name: string;\n  series: SeriesSlot;\n};\n\nexport const AGENTS: Record<AgentId, Agent> = {\n  researcher: { name: 'Researcher', series: 2 },\n  writer: { name: 'Writer', series: 3 },\n  coder: { name: 'Coder', series: 5 },\n};\n\nexport const AGENT_IDS: AgentId[] = ['researcher', 'writer', 'coder'];\n\n/** Runs live in each region when the map opens. Invented, and marked as illustrative. */\nexport const RUNS: Record<RegionId, number> = {\n  'us-west': 7,\n  'us-east': 14,\n  'south-america': 5,\n  europe: 11,\n  india: 6,\n  'asia-pacific': 8,\n};\n",
      "type": "registry:component",
      "target": "components/blocks/maps-02/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "maps"
  ],
  "type": "registry:block"
}