{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-area",
  "title": "Scroll Area",
  "description": "A scrollable container with a thin, draggable, auto-hiding custom scrollbar (vertical, horizontal or both) and edge fade masks, replacing the native browser scrollbar.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/scroll-area/scroll-area.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion } 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\nexport type ScrollAreaDirection = \"vertical\" | \"horizontal\" | \"both\";\nexport type ScrollAreaSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface ScrollAreaProps {\n  children: React.ReactNode;\n  direction?: ScrollAreaDirection;\n  height?: number | string;\n  width?: number | string;\n  /** Keep the scrollbar visible at all times instead of fading it out when idle. */\n  alwaysVisible?: boolean;\n  showFadeMask?: boolean;\n  theme?: \"dark\" | \"light\";\n  accentColor?: string;\n  size?: ScrollAreaSize;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { thumb: \"rgba(255,255,255,0.28)\", thumbHover: \"rgba(255,255,255,0.45)\", track: \"rgba(255,255,255,0.05)\", fadeTo: \"#080808\" },\n  light: { thumb: \"rgba(10,10,10,0.22)\", thumbHover: \"rgba(10,10,10,0.4)\", track: \"rgba(10,10,10,0.04)\", fadeTo: \"#FFFFFF\" },\n};\n\nconst SIZES: Record<ScrollAreaSize, { thickness: number; margin: number }> = {\n  sm: { thickness: 6, margin: 2 },\n  md: { thickness: 8, margin: 3 },\n  lg: { thickness: 10, margin: 3 },\n};\n\ninterface Metrics {\n  scrollTop: number;\n  scrollLeft: number;\n  scrollHeight: number;\n  scrollWidth: number;\n  clientHeight: number;\n  clientWidth: number;\n}\n\nconst emptyMetrics: Metrics = { scrollTop: 0, scrollLeft: 0, scrollHeight: 0, scrollWidth: 0, clientHeight: 0, clientWidth: 0 };\n\nexport function ScrollArea({\n  children,\n  direction = \"vertical\",\n  height = 320,\n  width,\n  alwaysVisible = false,\n  showFadeMask = true,\n  theme = \"dark\",\n  accentColor,\n  size = \"md\",\n  className,\n}: ScrollAreaProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const showV = direction === \"vertical\" || direction === \"both\";\n  const showH = direction === \"horizontal\" || direction === \"both\";\n\n  const viewportRef = React.useRef<HTMLDivElement>(null);\n  const [m, setM] = React.useState<Metrics>(emptyMetrics);\n  const [active, setActive] = React.useState(alwaysVisible);\n  const [dragging, setDragging] = React.useState<\"v\" | \"h\" | null>(null);\n  const hideTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const dragStart = React.useRef({ pos: 0, scroll: 0 });\n\n  const readMetrics = React.useCallback(() => {\n    const el = viewportRef.current;\n    if (!el) return;\n    setM({ scrollTop: el.scrollTop, scrollLeft: el.scrollLeft, scrollHeight: el.scrollHeight, scrollWidth: el.scrollWidth, clientHeight: el.clientHeight, clientWidth: el.clientWidth });\n  }, []);\n\n  const wake = React.useCallback(() => {\n    if (alwaysVisible) return;\n    setActive(true);\n    if (hideTimer.current) clearTimeout(hideTimer.current);\n    hideTimer.current = setTimeout(() => setActive(false), 900);\n  }, [alwaysVisible]);\n\n  React.useEffect(() => {\n    const el = viewportRef.current;\n    if (!el) return;\n    readMetrics();\n    const onScroll = () => {\n      readMetrics();\n      wake();\n    };\n    el.addEventListener(\"scroll\", onScroll, { passive: true });\n    const ro = new ResizeObserver(readMetrics);\n    ro.observe(el);\n    const mo = new MutationObserver(readMetrics);\n    mo.observe(el, { childList: true, subtree: true });\n    return () => {\n      el.removeEventListener(\"scroll\", onScroll);\n      ro.disconnect();\n      mo.disconnect();\n    };\n  }, [readMetrics, wake]);\n\n  React.useEffect(() => () => {\n    if (hideTimer.current) clearTimeout(hideTimer.current);\n  }, []);\n\n  const trackH = m.clientHeight - s.margin * 2;\n  const trackW = m.clientWidth - s.margin * 2;\n  const maxScrollTop = Math.max(0, m.scrollHeight - m.clientHeight);\n  const maxScrollLeft = Math.max(0, m.scrollWidth - m.clientWidth);\n  const thumbH = maxScrollTop > 0 ? Math.max(24, (m.clientHeight / m.scrollHeight) * trackH) : 0;\n  const thumbW = maxScrollLeft > 0 ? Math.max(24, (m.clientWidth / m.scrollWidth) * trackW) : 0;\n  const thumbTop = maxScrollTop > 0 ? (m.scrollTop / maxScrollTop) * (trackH - thumbH) : 0;\n  const thumbLeft = maxScrollLeft > 0 ? (m.scrollLeft / maxScrollLeft) * (trackW - thumbW) : 0;\n\n  // Two plain handlers rather than a (axis) => (e) => {...} factory: the\n  // lint rule that flags ref writes during render can't see through a\n  // curried function to confirm the *returned* closure only ever runs from\n  // an event (which it does — startDrag(\"v\") itself runs at render time\n  // just to produce the handler, but the handler itself doesn't), so it\n  // conservatively flags the ref write anyway.\n  const onVPointerDown = (e: React.PointerEvent) => {\n    e.preventDefault();\n    (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n    dragStart.current = { pos: e.clientY, scroll: m.scrollTop };\n    setDragging(\"v\");\n    setActive(true);\n  };\n  const onHPointerDown = (e: React.PointerEvent) => {\n    e.preventDefault();\n    (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n    dragStart.current = { pos: e.clientX, scroll: m.scrollLeft };\n    setDragging(\"h\");\n    setActive(true);\n  };\n\n  const onDragMove = (e: React.PointerEvent) => {\n    if (!dragging || !viewportRef.current) return;\n    if (dragging === \"v\") {\n      const deltaPx = e.clientY - dragStart.current.pos;\n      const range = trackH - thumbH;\n      const scrollDelta = range > 0 ? (deltaPx / range) * maxScrollTop : 0;\n      viewportRef.current.scrollTop = Math.min(maxScrollTop, Math.max(0, dragStart.current.scroll + scrollDelta));\n    } else {\n      const deltaPx = e.clientX - dragStart.current.pos;\n      const range = trackW - thumbW;\n      const scrollDelta = range > 0 ? (deltaPx / range) * maxScrollLeft : 0;\n      viewportRef.current.scrollLeft = Math.min(maxScrollLeft, Math.max(0, dragStart.current.scroll + scrollDelta));\n    }\n  };\n\n  const endDrag = () => {\n    setDragging(null);\n    wake();\n  };\n\n  const visible = alwaysVisible || active || dragging !== null;\n  const atTop = m.scrollTop <= 1;\n  const atBottom = m.scrollTop >= maxScrollTop - 1;\n  const atLeft = m.scrollLeft <= 1;\n  const atRight = m.scrollLeft >= maxScrollLeft - 1;\n\n  return (\n    // The fade mask is a gradient into a solid color, which only reads as a\n    // seamless fade — rather than a visible hard-edged rectangle — when\n    // that color actually matches whatever's behind it. Since this\n    // component has no way to know an arbitrary parent's background, it\n    // owns its own (p.fadeTo) and uses that same value for both, so the\n    // two can never drift apart regardless of where it's dropped in.\n    <div className={cn(\"relative\", className)} style={{ width, maxWidth: \"100%\", height, background: p.fadeTo }} onMouseEnter={wake} onMouseMove={wake}>\n      <div\n        ref={viewportRef}\n        tabIndex={0}\n        // The native scrollbar is hidden two ways at once because no single\n        // property covers every engine: scrollbarWidth is the (standard)\n        // Firefox property, and Chrome/Safari only respect the vendor\n        // ::-webkit-scrollbar pseudo-element, reached here through\n        // Tailwind's arbitrary-variant syntax rather than an injected\n        // <style> tag (which would need its own generated class to target\n        // safely instead of leaking a shared selector across instances).\n        className=\"h-full w-full outline-none [&::-webkit-scrollbar]:hidden\"\n        style={{\n          overflowY: showV ? \"auto\" : \"hidden\",\n          overflowX: showH ? \"auto\" : \"hidden\",\n          scrollbarWidth: \"none\",\n          msOverflowStyle: \"none\",\n        }}\n      >\n        {children}\n      </div>\n\n      {showFadeMask && showV && !atTop && <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-0 top-0\" style={{ height: 24, background: `linear-gradient(to bottom, ${p.fadeTo}, transparent)` }} />}\n      {showFadeMask && showV && !atBottom && <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-0 bottom-0\" style={{ height: 24, background: `linear-gradient(to top, ${p.fadeTo}, transparent)` }} />}\n      {showFadeMask && showH && !atLeft && <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-y-0 left-0\" style={{ width: 24, background: `linear-gradient(to right, ${p.fadeTo}, transparent)` }} />}\n      {showFadeMask && showH && !atRight && <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-y-0 right-0\" style={{ width: 24, background: `linear-gradient(to left, ${p.fadeTo}, transparent)` }} />}\n\n      {showV && thumbH > 0 && (\n        <div className=\"absolute\" style={{ top: s.margin, bottom: s.margin, right: 1, width: s.thickness, borderRadius: s.thickness }}>\n          <motion.div\n            role=\"scrollbar\"\n            aria-orientation=\"vertical\"\n            aria-valuenow={maxScrollTop > 0 ? Math.round((m.scrollTop / maxScrollTop) * 100) : 0}\n            onPointerDown={onVPointerDown}\n            onPointerMove={onDragMove}\n            onPointerUp={endDrag}\n            onPointerCancel={endDrag}\n            className=\"absolute cursor-pointer touch-none\"\n            style={{ top: thumbTop, height: thumbH, width: s.thickness, borderRadius: s.thickness, background: dragging === \"v\" ? (accentColor ?? p.thumbHover) : p.thumb }}\n            animate={{ opacity: visible ? 1 : 0 }}\n            transition={{ duration: 0.15 }}\n          />\n        </div>\n      )}\n      {showH && thumbW > 0 && (\n        <div className=\"absolute\" style={{ left: s.margin, right: s.margin, bottom: 1, height: s.thickness, borderRadius: s.thickness }}>\n          <motion.div\n            role=\"scrollbar\"\n            aria-orientation=\"horizontal\"\n            aria-valuenow={maxScrollLeft > 0 ? Math.round((m.scrollLeft / maxScrollLeft) * 100) : 0}\n            onPointerDown={onHPointerDown}\n            onPointerMove={onDragMove}\n            onPointerUp={endDrag}\n            onPointerCancel={endDrag}\n            className=\"absolute cursor-pointer touch-none\"\n            style={{ left: thumbLeft, width: thumbW, height: s.thickness, borderRadius: s.thickness, background: dragging === \"h\" ? (accentColor ?? p.thumbHover) : p.thumb }}\n            animate={{ opacity: visible ? 1 : 0 }}\n            transition={{ duration: 0.15 }}\n          />\n        </div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}