{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rail-nav",
  "title": "Side Navigation",
  "description": "A sidebar on a dashed rail: a solid line hooks into the current page and a quieter one reaches out to the row under your pointer.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "components/ui/rail-nav.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useMotionValue, useReducedMotion, useSpring, useTransform } from \"motion/react\"\n\nimport { useRailRows } from \"@/components/ui/rail-path\"\nimport { iconGestures, iconRest, springs } from \"@/lib/afterglow\"\nimport { cn } from \"@/lib/utils\"\n\ntype RailNavItem = {\n  id: string\n  label: string\n  icon?: React.ReactNode\n  /** a small trailing note, like a count */\n  badge?: string\n  /** makes the row a real link */\n  href?: string\n}\n\n/** a small label that starts a new group of rows */\ntype RailNavHeading = { heading: string }\n\ntype RailNavProps = Omit<React.ComponentProps<\"nav\">, \"onChange\" | \"defaultValue\"> & {\n  items: (RailNavItem | RailNavHeading)[]\n  value?: string\n  defaultValue?: string\n  onValueChange?: (id: string) => void\n}\n\nconst RAIL_X = 7\nconst RADIUS = 6\nconst HOOK = 8\nconst TAIL = 14\n\n// a sidebar on a dashed rail. a solid line runs down the rail and hooks into the page you are on,\n// and a quieter one reaches out from it to the row under your pointer or focus\nfunction RailNav({ items, value, defaultValue, onValueChange, className, \"aria-label\": label = \"Sidebar\", ...props }: RailNavProps) {\n  const reduceMotion = useReducedMotion()\n  const uid = React.useId()\n  const list = React.useRef<HTMLUListElement>(null)\n  const buttons = React.useRef(new Map<string, HTMLElement>())\n  const rows = items.filter((entry): entry is RailNavItem => \"id\" in entry)\n  const [internal, setInternal] = React.useState(defaultValue ?? rows[0]?.id)\n  const [hovered, setHovered] = React.useState<string | null>(null)\n  const active = value ?? internal\n\n  const measured = useRailRows(list, RAIL_X, 0, items)\n  const ys = React.useMemo(() => {\n    const map = new Map<string, number>()\n    rows.forEach((row, index) => {\n      const spot = measured?.[index]\n      if (spot) map.set(row.id, spot.y)\n    })\n    return map\n    // rows is derived from items\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [measured, items])\n\n  const top = (measured?.[0]?.y ?? 0) - TAIL\n  const bottom = measured?.[measured.length - 1]?.y ?? 0\n  const activeTarget = (active ? ys.get(active) : undefined) ?? top\n  const hoverTarget = (hovered ? ys.get(hovered) : undefined) ?? activeTarget\n\n  const motionConfig = reduceMotion ? { duration: 0 } : { stiffness: 320, damping: 30, mass: 0.7 }\n  const activeY = useSpring(top, motionConfig)\n  const hoverY = useSpring(top, { stiffness: 380, damping: 34, mass: 0.6 })\n  const startY = useMotionValue(top)\n\n  React.useEffect(() => {\n    startY.set(top)\n    if (reduceMotion) {\n      activeY.jump(activeTarget)\n      hoverY.jump(hoverTarget)\n    } else {\n      activeY.set(activeTarget)\n      hoverY.set(hoverTarget)\n    }\n  }, [activeTarget, activeY, hoverTarget, hoverY, reduceMotion, startY, top])\n\n  // the solid line: down the rail, then a rounded hook into the row\n  const activeD = useTransform([activeY, startY], ([y, from]: number[]) => {\n    const r = Math.max(Math.min(RADIUS, y - from), 0)\n    return `M ${RAIL_X} ${from} V ${y - r} A ${r} ${r} 0 0 0 ${RAIL_X + r} ${y} h ${HOOK}`\n  })\n  // the quiet line: from the end of the solid one to the hovered row, hooking the same way\n  const hoverD = useTransform([activeY, hoverY], ([from, y]: number[]) => {\n    const down = y >= from\n    const r = Math.min(RADIUS, Math.abs(y - from))\n    if (r < 0.5) return `M ${RAIL_X} ${from} h 0`\n    return `M ${RAIL_X} ${from} V ${down ? y - r : y + r} A ${r} ${r} 0 0 ${down ? 0 : 1} ${RAIL_X + r} ${y} h ${HOOK}`\n  })\n\n  function choose(id: string) {\n    if (value === undefined) setInternal(id)\n    onValueChange?.(id)\n  }\n\n  function onKeyDown(event: React.KeyboardEvent, id: string) {\n    const index = rows.findIndex((row) => row.id === id)\n    const next =\n      event.key === \"ArrowDown\" ? rows[Math.min(index + 1, rows.length - 1)]\n      : event.key === \"ArrowUp\" ? rows[Math.max(index - 1, 0)]\n      : event.key === \"Home\" ? rows[0]\n      : event.key === \"End\" ? rows[rows.length - 1]\n      : null\n    if (!next) return\n    event.preventDefault()\n    buttons.current.get(next.id)?.focus()\n  }\n\n  const slide = reduceMotion ? { duration: 0 } : springs.snappy\n\n  return (\n    <nav data-slot=\"rail-nav\" aria-label={label} className={cn(\"relative\", className)} {...props}>\n      <ul ref={list} className=\"relative flex flex-col\" onPointerLeave={() => setHovered(null)}>\n        {measured && (\n          <svg aria-hidden className=\"pointer-events-none absolute top-0 left-0 h-full w-8 overflow-visible\">\n            <path d={`M ${RAIL_X} ${top} V ${bottom}`} fill=\"none\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeDasharray=\"0.1 5\" className=\"stroke-foreground/35\" />\n            <motion.path d={hoverD} fill=\"none\" strokeWidth=\"1.5\" strokeLinecap=\"round\" className=\"stroke-foreground/30\" />\n            <motion.path d={activeD} fill=\"none\" strokeWidth=\"1.75\" strokeLinecap=\"round\" className=\"stroke-glow\" />\n            <motion.circle cx={RAIL_X + RADIUS + HOOK} cy={activeY} r=\"2.75\" className=\"fill-glow\" />\n          </svg>\n        )}\n        {items.map((entry, index) => {\n          if (\"heading\" in entry) {\n            return (\n              <li key={`heading-${index}`} className={cn(\"pl-8 pb-1.5 text-[11px] font-medium tracking-[0.08em] text-foreground/45 uppercase\", index > 0 && \"pt-6\")}>\n                {entry.heading}\n              </li>\n            )\n          }\n          const selected = entry.id === active\n          const Tag = entry.href ? \"a\" : \"button\"\n          return (\n            <li key={entry.id} data-rail-row className=\"relative\">\n              {hovered === entry.id && !selected && (\n                <motion.span\n                  layoutId={`${uid}-hover`}\n                  aria-hidden\n                  className=\"absolute inset-y-0.5 right-0 left-6 rounded-[10px] bg-foreground/[0.045]\"\n                  transition={slide}\n                />\n              )}\n              {selected && (\n                <motion.span\n                  layoutId={`${uid}-active`}\n                  aria-hidden\n                  className=\"absolute inset-y-0.5 right-0 left-6 rounded-[10px] bg-foreground/[0.08] shadow-[inset_0_1px_0_oklch(1_0_0/8%),inset_0_0_0_1px_oklch(1_0_0/4%)]\"\n                  transition={slide}\n                />\n              )}\n              <Tag\n                ref={(node: HTMLElement | null) => {\n                  if (node) buttons.current.set(entry.id, node)\n                  else buttons.current.delete(entry.id)\n                }}\n                {...(entry.href ? { href: entry.href } : { type: \"button\" as const })}\n                aria-current={selected ? \"page\" : undefined}\n                onClick={() => choose(entry.id)}\n                onPointerEnter={() => setHovered(entry.id)}\n                onFocus={() => setHovered(entry.id)}\n                onBlur={() => setHovered(null)}\n                onKeyDown={(event: React.KeyboardEvent) => onKeyDown(event, entry.id)}\n                className={cn(\n                  \"relative flex h-9 w-full cursor-pointer items-center gap-2.5 rounded-[10px] pr-3 pl-8 text-left text-sm outline-none transition-colors duration-150 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring [&_svg]:size-4 [&_svg]:shrink-0\",\n                  selected ? \"font-medium text-foreground\" : \"text-foreground/60 hover:text-foreground\"\n                )}\n              >\n                {entry.icon && (\n                  <motion.span\n                    aria-hidden\n                    className={cn(\"grid place-items-center transition-colors duration-200\", selected && \"text-glow\")}\n                    initial={false}\n                    animate={selected ? iconGestures.pop : iconRest}\n                    transition={reduceMotion ? { duration: 0 } : { duration: 0.24, ease: [0.2, 0.8, 0.2, 1] }}\n                  >\n                    {entry.icon}\n                  </motion.span>\n                )}\n                <span className=\"min-w-0 flex-1 truncate\">{entry.label}</span>\n                {entry.badge && (\n                  <span className=\"rounded-full bg-glow/15 px-1.5 py-px text-[11px] font-medium text-glow\">{entry.badge}</span>\n                )}\n              </Tag>\n            </li>\n          )\n        })}\n      </ul>\n    </nav>\n  )\n}\n\nexport { RailNav, type RailNavItem, type RailNavHeading, type RailNavProps }\n",
      "type": "registry:ui"
    },
    {
      "path": "components/ui/rail-path.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\n// the geometry that the rail components share: a path drawn through the centre of every row,\n// stepping sideways with rounded elbows where a row is indented, and a short curved hook that\n// turns off the rail into a row\n\ntype RailRow = { x: number; y: number }\n\ntype RailTrack = {\n  /** the full path, from the first row to the last */\n  d: string\n  /** how far along the path each row sits, in px */\n  at: number[]\n  total: number\n}\n\n/** a path through every row. rows that sit at a different x get a rounded jog halfway between them */\nfunction buildTrack(rows: RailRow[], radius = 7, bend: \"rounded\" | \"diagonal\" = \"rounded\"): RailTrack {\n  if (!rows.length) return { d: \"\", at: [], total: 0 }\n  let d = `M ${rows[0].x} ${rows[0].y}`\n  let length = 0\n  const at = [0]\n  for (let i = 1; i < rows.length; i++) {\n    const a = rows[i - 1]\n    const b = rows[i]\n    if (a.x === b.x) {\n      d += ` V ${b.y}`\n      length += b.y - a.y\n    } else {\n      if (bend === \"diagonal\") {\n        const mid = (a.y + b.y) / 2\n        const half = Math.min(Math.abs(b.x - a.x) / 2, (b.y - a.y) / 4)\n        d += ` V ${mid - half} L ${b.x} ${mid + half} V ${b.y}`\n        length += b.y - a.y - 2 * half + Math.hypot(b.x - a.x, 2 * half)\n        at.push(length)\n        continue\n      }\n      const dir = b.x > a.x ? 1 : -1\n      const dx = Math.abs(b.x - a.x)\n      const r = Math.min(radius, dx / 2, (b.y - a.y) / 4)\n      const mid = (a.y + b.y) / 2\n      d += ` V ${mid - r} A ${r} ${r} 0 0 ${dir === 1 ? 0 : 1} ${a.x + dir * r} ${mid} H ${b.x - dir * r}`\n      d += ` A ${r} ${r} 0 0 ${dir === 1 ? 1 : 0} ${b.x} ${mid + r} V ${b.y}`\n      length += mid - r - a.y + (Math.PI * r) / 2 + (dx - 2 * r) + (Math.PI * r) / 2 + (b.y - mid - r)\n    }\n    at.push(length)\n  }\n  return { d, at, total: length }\n}\n\n/** how far along the track a position is, where 1.5 means halfway between the second and third row */\nfunction lengthAt(track: RailTrack, position: number) {\n  if (!track.at.length) return 0\n  const clamped = Math.min(Math.max(position, 0), track.at.length - 1)\n  const index = Math.min(Math.floor(clamped), track.at.length - 2)\n  if (index < 0) return 0\n  const t = clamped - index\n  return track.at[index] + (track.at[index + 1] - track.at[index]) * t\n}\n\n/**\n * measures the centre of each `[data-rail-row]` inside the list. a row's `data-depth` shifts it\n * sideways by `step` px. returns null until the first measure, so nothing is drawn on the server\n */\nfunction useRailRows(list: React.RefObject<HTMLElement | null>, x: number, step: number, watch: unknown) {\n  const [rows, setRows] = React.useState<RailRow[] | null>(null)\n\n  React.useEffect(() => {\n    const node = list.current\n    if (!node) return\n    let frame = 0\n    const measure = () => {\n      frame = 0\n      const found = Array.from(node.querySelectorAll<HTMLElement>(\"[data-rail-row]\"))\n      setRows(\n        found.map((row) => ({\n          x: x + Number(row.dataset.depth ?? 0) * step,\n          y: row.offsetTop + row.offsetHeight / 2,\n        }))\n      )\n    }\n    const schedule = () => {\n      if (!frame) frame = requestAnimationFrame(measure)\n    }\n    schedule()\n    const observer = new ResizeObserver(schedule)\n    observer.observe(node)\n    node.querySelectorAll(\"[data-rail-row]\").forEach((row) => observer.observe(row))\n    return () => {\n      cancelAnimationFrame(frame)\n      observer.disconnect()\n    }\n  }, [list, x, step, watch])\n\n  return rows\n}\n\nexport { buildTrack, lengthAt, useRailRows, type RailRow, type RailTrack }\n",
      "type": "registry:ui"
    },
    {
      "path": "lib/afterglow.ts",
      "content": "import type { CSSProperties } from \"react\"\nimport type { TargetAndTransition, Transition } from \"motion/react\"\n\n// shared spring presets, every component picks from these\nexport const springs = {\n  snappy: { stiffness: 520, damping: 34, mass: 0.6 },\n  soft: { stiffness: 260, damping: 26, mass: 0.8 },\n  glide: { stiffness: 120, damping: 20, mass: 1 },\n} as const\n\nexport type SpringName = keyof typeof springs\n\nexport function spring(name: SpringName): Transition {\n  return { type: \"spring\", ...springs[name] }\n}\n\n// how a glow fades once its source moves away: slow, with a long tail\nexport const afterglow = {\n  linger: 0.9,\n  ease: [0.22, 1, 0.36, 1],\n} as const satisfies { linger: number; ease: Transition[\"ease\"] }\n\n// paints only the padding ring of an element, used for glowing borders\nexport const ringMask: CSSProperties = {\n  WebkitMask:\n    \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  WebkitMaskComposite: \"xor\",\n  mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  maskComposite: \"exclude\",\n}\n\n// small icon gestures, played when a control is pressed or selected\nexport const iconGestures = {\n  pop: { scale: [1, 1.2, 1] },\n  ring: { rotate: [0, -18, 14, -9, 4, 0], scale: [1, 1.12, 1] },\n  // a gear looks the same after half a turn, so it can rest there and snap back unseen\n  turn: { rotate: [0, 180], scale: [1, 1.12, 1] },\n  hop: { y: [0, -3, 0], scale: [1, 1.1, 1] },\n  nudge: { x: [0, 2.5, 0], scale: [1, 1.1, 1] },\n} satisfies Record<string, TargetAndTransition>\n\nexport type IconGesture = keyof typeof iconGestures\n\n// leaving a gesture is instant: every gesture already ends at, or looks like, its resting pose\nexport const iconRest: TargetAndTransition = { scale: 1, rotate: 0, x: 0, y: 0, transition: { duration: 0 } }\n",
      "type": "registry:lib"
    }
  ],
  "cssVars": {
    "theme": {
      "color-glow": "var(--glow)",
      "color-glow-foreground": "var(--glow-foreground)",
      "color-glow-2": "var(--glow-2)",
      "color-glow-3": "var(--glow-3)",
      "color-glass": "var(--glass)",
      "color-gloss-highlight": "var(--gloss-highlight)",
      "shadow-gloss": "inset 0 1px 0 0 var(--gloss-highlight), inset 0 -1px 0 0 var(--gloss-shade), 0 0 0 1px var(--gloss-edge), 0 1px 2px 0 var(--gloss-depth), 0 4px 12px -4px var(--gloss-depth)",
      "shadow-glass": "inset 0 1px 0 0 var(--gloss-highlight), inset 0 -10px 24px -18px var(--gloss-shade), inset 0 0 0 1px var(--gloss-edge), 0 2px 6px -1px var(--gloss-depth), 0 18px 40px -12px var(--gloss-depth)",
      "shadow-well": "inset 0 1px 3px 0 var(--gloss-depth), inset 0 0 0 1px var(--gloss-edge), 0 1px 0 0 var(--gloss-highlight)"
    },
    "light": {
      "glow": "oklch(0.7 0.19 45)",
      "glow-foreground": "oklch(0.22 0.05 40)",
      "glow-2": "oklch(0.64 0.22 12)",
      "glow-3": "oklch(0.56 0.21 300)",
      "glass": "oklch(1 0 0 / 55%)",
      "gloss-highlight": "oklch(1 0 0 / 95%)",
      "gloss-shade": "oklch(0.3 0.03 285 / 10%)",
      "gloss-depth": "oklch(0.32 0.03 285 / 20%)",
      "gloss-edge": "oklch(0.22 0.02 285 / 10%)",
      "liquid-tint": "oklch(1 0 0 / 18%)",
      "liquid-fallback": "oklch(1 0 0 / 55%)",
      "liquid-rim": "oklch(1 0 0 / 95%)",
      "liquid-edge": "oklch(0.2 0.02 285 / 10%)",
      "liquid-shadow": "oklch(0.22 0.02 285 / 26%)",
      "liquid-glow": "oklch(1 0 0 / 55%)",
      "liquid-shade": "oklch(0.25 0.03 285 / 14%)"
    },
    "dark": {
      "glow": "oklch(0.8 0.16 55)",
      "glow-foreground": "oklch(0.22 0.05 40)",
      "glow-2": "oklch(0.7 0.2 15)",
      "glow-3": "oklch(0.65 0.2 300)",
      "glass": "oklch(0.19 0 0 / 55%)",
      "gloss-highlight": "oklch(1 0 0 / 16%)",
      "gloss-shade": "oklch(0 0 0 / 30%)",
      "gloss-depth": "oklch(0.04 0 0 / 60%)",
      "gloss-edge": "oklch(1 0 0 / 9%)",
      "liquid-tint": "oklch(0.2 0 0 / 22%)",
      "liquid-fallback": "oklch(0.2 0 0 / 45%)",
      "liquid-rim": "oklch(1 0 0 / 60%)",
      "liquid-edge": "oklch(1 0 0 / 10%)",
      "liquid-shadow": "oklch(0 0 0 / 50%)",
      "liquid-glow": "oklch(1 0 0 / 24%)",
      "liquid-shade": "oklch(0 0 0 / 28%)"
    }
  },
  "type": "registry:ui"
}