{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-rail",
  "title": "Scroll Rail",
  "description": "A quiet document minimap with equal short dashes that expand near the pointer and follow the active content block.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "components/ui/scroll-rail.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useMotionValue, useReducedMotion, useSpring, type MotionValue } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype ScrollRailItem = {\n  /** matches a `data-rail-id` on the element it points to */\n  id: string\n  title: string\n  excerpt?: string\n  /** optional group label shown in the hover preview */\n  group?: string\n}\n\ntype ScrollRailProps = Omit<React.ComponentProps<\"nav\">, \"children\"> & {\n  items: ScrollRailItem[]\n  /** the element that scrolls; leave it out to follow the page */\n  container?: HTMLElement | null\n  /** which edge of its content the rail sits on; the preview opens toward the content */\n  side?: \"left\" | \"right\"\n}\n\nconst TICK = 9\nconst REST = 8\nconst REACH = 56\nconst SWELL = 18\nconst RAIL_SPRING = { type: \"spring\" as const, stiffness: 300, damping: 34, mass: 0.8 }\n\n// a quiet document minimap: every mark rests at the same short length, nearby marks swell toward\n// the pointer, and the active mark brightens without changing size\nfunction ScrollRail({ items, container = null, side = \"right\", className, onPointerMove, onPointerLeave, ...props }: ScrollRailProps) {\n  const reduceMotion = useReducedMotion()\n  const [active, setActive] = React.useState(0)\n  const [hover, setHover] = React.useState<{ index: number; y: number } | null>(null)\n  const pointerY = useMotionValue(Infinity)\n  const buttons = React.useRef<(HTMLButtonElement | null)[]>([])\n  const hideTimer = React.useRef(0)\n  // the tick you clicked stays lit even if the content ends before that part can reach the top;\n  // it lets go as soon as you scroll yourself\n  const pinned = React.useRef<number | null>(null)\n\n  const find = React.useCallback(\n    (id: string) => (container ?? document).querySelector<HTMLElement>(`[data-rail-id=\"${CSS.escape(id)}\"]`),\n    [container]\n  )\n\n  // the current part is the last one whose top has passed a line near the top of the view, so the part\n  // you just jumped to is the one that lights up\n  React.useEffect(() => {\n    let frame = 0\n    pinned.current = null\n    const measure = () => {\n      frame = 0\n      if (pinned.current !== null) {\n        setActive(pinned.current)\n        return\n      }\n      const top = container ? container.getBoundingClientRect().top : 0\n      const height = container ? container.clientHeight : window.innerHeight\n      const line = top + height * 0.15\n      let next = 0\n      items.forEach((item, index) => {\n        const node = find(item.id)\n        if (node && node.getBoundingClientRect().top <= line) next = index\n      })\n      const atEnd = container\n        ? container.scrollTop + container.clientHeight >= container.scrollHeight - Math.max(24, height * 0.02)\n        : window.scrollY + window.innerHeight >= document.documentElement.scrollHeight - Math.max(24, height * 0.02)\n      const atStart = container ? container.scrollTop <= 2 : window.scrollY <= 2\n      setActive(atStart ? 0 : atEnd ? items.length - 1 : next)\n    }\n    const schedule = () => {\n      if (!frame) frame = requestAnimationFrame(measure)\n    }\n    schedule()\n    const scroller: HTMLElement | Window = container ?? window\n    const release = () => {\n      pinned.current = null\n      schedule()\n    }\n    scroller.addEventListener(\"scroll\", schedule, { passive: true })\n    scroller.addEventListener(\"wheel\", release, { passive: true })\n    scroller.addEventListener(\"touchmove\", release, { passive: true })\n    scroller.addEventListener(\"pointerdown\", release)\n    window.addEventListener(\"keydown\", release)\n    window.addEventListener(\"resize\", schedule)\n    return () => {\n      cancelAnimationFrame(frame)\n      scroller.removeEventListener(\"scroll\", schedule)\n      scroller.removeEventListener(\"wheel\", release)\n      scroller.removeEventListener(\"touchmove\", release)\n      scroller.removeEventListener(\"pointerdown\", release)\n      window.removeEventListener(\"keydown\", release)\n      window.removeEventListener(\"resize\", schedule)\n    }\n  }, [container, find, items])\n\n  React.useEffect(() => () => window.clearTimeout(hideTimer.current), [])\n\n  function show(index: number) {\n    window.clearTimeout(hideTimer.current)\n    const node = buttons.current[index]\n    if (node) setHover({ index, y: node.offsetTop + node.offsetHeight / 2 })\n  }\n\n  function hideSoon() {\n    window.clearTimeout(hideTimer.current)\n    hideTimer.current = window.setTimeout(() => setHover(null), 120)\n  }\n\n  function go(index: number) {\n    pinned.current = index\n    setActive(index)\n    const target = find(items[index].id)\n    if (!target) return\n    const behavior = reduceMotion ? \"auto\" : \"smooth\"\n    if (container) {\n      const delta = target.getBoundingClientRect().top - (container.getBoundingClientRect().top + 20)\n      container.scrollTo({ top: container.scrollTop + delta, behavior })\n    } else {\n      target.scrollIntoView({ behavior, block: \"start\" })\n    }\n  }\n\n  function onKeyDown(event: React.KeyboardEvent, index: number) {\n    const to =\n      event.key === \"ArrowDown\" || event.key === \"ArrowRight\"\n        ? Math.min(index + 1, items.length - 1)\n        : event.key === \"ArrowUp\" || event.key === \"ArrowLeft\"\n          ? Math.max(index - 1, 0)\n          : event.key === \"Home\"\n            ? 0\n            : event.key === \"End\"\n              ? items.length - 1\n              : null\n    if (to === null) return\n    event.preventDefault()\n    buttons.current[to]?.focus()\n  }\n\n  const item = hover ? items[hover.index] : null\n\n  return (\n    <nav\n      data-slot=\"scroll-rail\"\n      aria-label=\"Jump to\"\n      className={cn(\"relative w-10\", className)}\n      onPointerMove={(event) => {\n        onPointerMove?.(event)\n        pointerY.set(event.clientY)\n      }}\n      onPointerLeave={(event) => {\n        onPointerLeave?.(event)\n        pointerY.set(Infinity)\n        hideSoon()\n      }}\n      {...props}\n    >\n      <div className=\"relative flex flex-col\" onPointerLeave={hideSoon}>\n        {items.map((entry, index) => (\n          <Tick\n            key={entry.id}\n            ref={(node) => {\n              buttons.current[index] = node\n            }}\n            label={entry.title}\n            side={side}\n            active={index === active}\n            pointerY={pointerY}\n            onClick={() => go(index)}\n            onPointerEnter={() => show(index)}\n            onFocus={() => show(index)}\n            onBlur={hideSoon}\n            onKeyDown={(event) => onKeyDown(event, index)}\n            tabIndex={index === active ? 0 : -1}\n          />\n        ))}\n\n        <AnimatePresence>\n          {hover && item && (\n            <motion.div\n              key=\"preview\"\n              aria-hidden\n              className={cn(\"pointer-events-none absolute top-0 z-10 w-72\", side === \"right\" ? \"right-full mr-3\" : \"left-full ml-3\")}\n              style={{ transformOrigin: side === \"right\" ? \"right center\" : \"left center\" }}\n              initial={{ opacity: 0, scale: 0.96, y: hover.y }}\n              animate={{ opacity: 1, scale: 1, y: hover.y }}\n              exit={{ opacity: 0, scale: 0.96, transition: { duration: 0.1 } }}\n              transition={{\n                opacity: { duration: 0.15 },\n                scale: { type: \"spring\", duration: 0.25, bounce: 0 },\n                y: reduceMotion ? { duration: 0 } : RAIL_SPRING,\n              }}\n            >\n              <div className=\"-translate-y-1/2 rounded-[20px] bg-glass p-3.5 shadow-glass backdrop-blur-2xl backdrop-saturate-150\">\n                <div className=\"relative\">\n                  <AnimatePresence mode=\"popLayout\" initial={false}>\n                    <motion.div\n                      key={hover.index}\n                      initial={{ opacity: 0, y: reduceMotion ? 0 : 4 }}\n                      animate={{ opacity: 1, y: 0 }}\n                      exit={{ opacity: 0, transition: { duration: 0.08 } }}\n                      transition={{ duration: 0.15, ease: [0.2, 0.8, 0.2, 1] }}\n                    >\n                      <p className=\"text-[11px] text-foreground/50 tabular-nums\">\n                        {item.group ? `${item.group} · ` : \"\"}\n                        {hover.index + 1} of {items.length}\n                      </p>\n                      <p className=\"mt-0.5 truncate text-sm font-medium text-foreground\">{item.title}</p>\n                      {item.excerpt && (\n                        <p className=\"mt-1 line-clamp-2 text-[13px] leading-snug text-foreground/60\">{item.excerpt}</p>\n                      )}\n                    </motion.div>\n                  </AnimatePresence>\n                </div>\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </nav>\n  )\n}\n\ntype TickProps = Omit<React.ComponentProps<\"button\">, \"children\"> & {\n  label: string\n  side: \"left\" | \"right\"\n  active: boolean\n  pointerY: MotionValue<number>\n}\n\nfunction Tick({ ref, label, side, active, pointerY, className, ...props }: TickProps) {\n  const reduceMotion = useReducedMotion()\n  const node = React.useRef<HTMLButtonElement | null>(null)\n  const width = useSpring(REST, RAIL_SPRING)\n  const opacity = useSpring(0.3, RAIL_SPRING)\n\n  // swell with how near the pointer is, on top of the resting length\n  React.useEffect(() => {\n    const update = () => {\n      const y = pointerY.get()\n      let near = 0\n      if (Number.isFinite(y) && node.current) {\n        const rect = node.current.getBoundingClientRect()\n        const proximity = Math.max(0, 1 - Math.abs(y - (rect.top + rect.height / 2)) / REACH)\n        near = proximity * proximity * (3 - 2 * proximity)\n      }\n      const nextWidth = REST + SWELL * near\n      const nextOpacity = active ? 0.78 : 0.22 + 0.48 * near\n      if (reduceMotion) {\n        width.jump(nextWidth)\n        opacity.jump(nextOpacity)\n      } else {\n        width.set(nextWidth)\n        opacity.set(nextOpacity)\n      }\n    }\n    update()\n    return pointerY.on(\"change\", update)\n  }, [active, opacity, pointerY, reduceMotion, width])\n\n  return (\n    <button\n      ref={(element) => {\n        node.current = element\n        if (typeof ref === \"function\") ref(element)\n        else if (ref) ref.current = element\n      }}\n      type=\"button\"\n      aria-label={label}\n      aria-current={active ? \"true\" : undefined}\n      className={cn(\n        \"group flex w-10 cursor-pointer items-center rounded-sm outline-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring\",\n        side === \"right\" ? \"justify-end\" : \"justify-start\",\n        className\n      )}\n      style={{ height: TICK }}\n      {...props}\n    >\n      <motion.span aria-hidden className=\"h-[2px] rounded-full bg-foreground\" style={{ width, opacity }} />\n    </button>\n  )\n}\n\nexport { ScrollRail, type ScrollRailItem, type ScrollRailProps }\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"
}