{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"gradual-blur","type":"registry:ui","title":"Gradual Blur","description":"A scroll area whose edge melts into a progressive blur that clears when you reach the end.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/gradual-blur.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { motion } from \"motion/react\";\nimport { useEffect, useRef, useState, type CSSProperties, type ReactNode } from \"react\";\n\ntype Edge = \"top\" | \"bottom\" | \"left\" | \"right\";\n\ntype GradualBlurProps = {\n  children: ReactNode;\n  /** Edge of the scroll area that gets blurred. */\n  position?: Edge;\n  /** Blur at the very edge, in pixels. */\n  strength?: number;\n  /** Depth of the blurred band in pixels: its height, or its width on the left and right. */\n  height?: number;\n  /** Number of stacked blur layers. More layers give a smoother ramp. */\n  layers?: number;\n  /** Fade the blur out once the scroll reaches that edge. */\n  fadeAtEnd?: boolean;\n  /** Optional color laid over the band, fading toward the edge. */\n  tint?: string;\n  /** Accessible name of the scroll area. */\n  label?: string;\n  /** Classes for the outer frame. Give it a height or width so it can scroll. */\n  className?: string;\n  /** Classes for the scrolling content, such as a flex row for horizontal scrolling. */\n  contentClassName?: string;\n};\n\nconst DIRECTION: Record<Edge, string> = { top: \"to top\", bottom: \"to bottom\", left: \"to left\", right: \"to right\" };\n\nfunction reachedEdge(el: HTMLElement, edge: Edge) {\n  switch (edge) {\n    case \"top\":\n      return el.scrollTop <= 1;\n    case \"bottom\":\n      return el.scrollTop + el.clientHeight >= el.scrollHeight - 1;\n    case \"left\":\n      return el.scrollLeft <= 1;\n    case \"right\":\n      return el.scrollLeft + el.clientWidth >= el.scrollWidth - 1;\n  }\n}\n\nfunction bandStyle(edge: Edge, depth: number): CSSProperties {\n  switch (edge) {\n    case \"top\":\n      return { top: 0, left: 0, right: 0, height: depth };\n    case \"bottom\":\n      return { bottom: 0, left: 0, right: 0, height: depth };\n    case \"left\":\n      return { top: 0, bottom: 0, left: 0, width: depth };\n    case \"right\":\n      return { top: 0, bottom: 0, right: 0, width: depth };\n  }\n}\n\n/** A scroll area whose edge melts into a progressive blur, which clears once you reach that edge. */\nexport function GradualBlur({\n  children,\n  position = \"bottom\",\n  strength = 8,\n  height = 96,\n  layers = 5,\n  fadeAtEnd = true,\n  tint,\n  label,\n  className = \"\",\n  contentClassName = \"\",\n}: GradualBlurProps) {\n  const scrollRef = useRef<HTMLDivElement>(null);\n  const contentRef = useRef<HTMLDivElement>(null);\n  const [atEdge, setAtEdge] = useState(false);\n\n  useEffect(() => {\n    const el = scrollRef.current;\n    const content = contentRef.current;\n    if (!el || !content) return;\n    const check = () => setAtEdge(reachedEdge(el, position));\n    const observer = new ResizeObserver(check);\n    observer.observe(el);\n    observer.observe(content);\n    el.addEventListener(\"scroll\", check, { passive: true });\n    return () => {\n      observer.disconnect();\n      el.removeEventListener(\"scroll\", check);\n    };\n  }, [position]);\n\n  const count = Math.max(1, Math.min(12, Math.round(layers)));\n  const direction = DIRECTION[position];\n\n  return (\n    <div className={`relative overflow-hidden ${className}`}>\n      <div\n        ref={scrollRef}\n        role={label ? \"region\" : undefined}\n        aria-label={label}\n        tabIndex={0}\n        className=\"thin-scroll size-full overflow-auto rounded-[inherit]\"\n      >\n        <div ref={contentRef} className={contentClassName}>\n          {children}\n        </div>\n      </div>\n\n      <motion.div\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute z-10\"\n        style={bandStyle(position, height)}\n        initial={false}\n        animate={{ opacity: fadeAtEnd && atEdge ? 0 : 1 }}\n        transition={{ duration: 0.3, ease: \"easeOut\" }}\n      >\n        {Array.from({ length: count }, (_, i) => {\n          // Each layer doubles the blur of the one before and starts a step closer to the edge,\n          // so the blur builds up smoothly instead of in bands.\n          const blur = `blur(${(strength * 2 ** (i + 1 - count)).toFixed(2)}px)`;\n          const mask = `linear-gradient(${direction}, transparent ${(i / count) * 100}%, #000 ${((i + 1) / count) * 100}%)`;\n          return (\n            <div\n              key={i}\n              className=\"absolute inset-0\"\n              style={{ backdropFilter: blur, WebkitBackdropFilter: blur, maskImage: mask, WebkitMaskImage: mask }}\n            />\n          );\n        })}\n        {tint ? <div className=\"absolute inset-0\" style={{ background: `linear-gradient(${direction}, transparent, ${tint})` }} /> : null}\n      </motion.div>\n    </div>\n  );\n}\n"}]}