{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pin-pile","type":"registry:ui","title":"Pin Pile","description":"Cards pin to the top of a scroll container and pile onto each other, with covered cards shrinking and dimming underneath.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/pin-pile.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { Children, useEffect, useRef, type ReactNode, type RefObject } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface PinPileProps {\n  /** One child per card. */\n  children: ReactNode;\n  /** The scrolling element. Defaults to the window. */\n  scrollContainerRef?: RefObject<HTMLElement | null>;\n  /** Distance from the top of the scroller where the first card pins, in px. */\n  stackOffset?: number;\n  /** Visible sliver of each earlier card peeking above the next, in px. */\n  stackGap?: number;\n  /** Vertical space between cards before they stack, in px. */\n  itemGap?: number;\n  /** How much each covered card shrinks per card on top of it. */\n  scaleStep?: number;\n  /** How dark a fully covered card gets, 0 to 1. */\n  dim?: number;\n  /** Blur for covered cards, in px per card on top. */\n  blur?: number;\n  className?: string;\n  /** Classes for every card wrapper. */\n  itemClassName?: string;\n}\n\nexport function PinPile({\n  children,\n  scrollContainerRef,\n  stackOffset = 32,\n  stackGap = 18,\n  itemGap = 96,\n  scaleStep = 0.05,\n  dim = 0.45,\n  blur = 0,\n  className,\n  itemClassName,\n}: PinPileProps) {\n  const items = Children.toArray(children);\n  const cards = useRef<(HTMLDivElement | null)[]>([]);\n  const shades = useRef<(HTMLDivElement | null)[]>([]);\n\n  useEffect(() => {\n    const scroller = scrollContainerRef?.current ?? null;\n    const target: HTMLElement | Window = scroller ?? window;\n    const reduce = matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let raf = 0;\n\n    const paint = () => {\n      raf = 0;\n      const top = scroller ? scroller.getBoundingClientRect().top : 0;\n      const els = cards.current.filter(Boolean) as HTMLDivElement[];\n      // p[j]: 0 while card j is still a full card-height away from its pin line, 1 once pinned.\n      const p = els.map((el, j) => {\n        const pin = top + stackOffset + j * stackGap;\n        const dist = el.getBoundingClientRect().top - pin;\n        return Math.min(1, Math.max(0, 1 - dist / (el.offsetHeight + itemGap)));\n      });\n      els.forEach((el, i) => {\n        let covered = 0;\n        for (let j = i + 1; j < els.length; j++) covered += p[j];\n        const inner = el.firstElementChild as HTMLElement | null;\n        if (!inner) return;\n        inner.style.transform = reduce ? \"\" : `scale(${Math.max(0.5, 1 - covered * scaleStep)})`;\n        inner.style.filter = blur && !reduce && covered > 0.01 ? `blur(${(covered * blur).toFixed(2)}px)` : \"\";\n        const shade = shades.current[i];\n        if (shade) shade.style.opacity = String(Math.min(1, covered) * dim);\n      });\n    };\n    const onScroll = () => {\n      if (!raf) raf = requestAnimationFrame(paint);\n    };\n\n    paint();\n    target.addEventListener(\"scroll\", onScroll, { passive: true });\n    window.addEventListener(\"resize\", onScroll);\n    return () => {\n      cancelAnimationFrame(raf);\n      target.removeEventListener(\"scroll\", onScroll);\n      window.removeEventListener(\"resize\", onScroll);\n    };\n  }, [scrollContainerRef, stackOffset, stackGap, itemGap, scaleStep, dim, blur, items.length]);\n\n  return (\n    <div className={cn(\"relative\", className)} style={{ paddingBottom: stackGap * items.length + itemGap }}>\n      {items.map((child, i) => (\n        <div\n          key={i}\n          ref={(el) => {\n            cards.current[i] = el;\n          }}\n          className=\"sticky\"\n          style={{ top: stackOffset + i * stackGap, marginTop: i ? itemGap : 0 }}\n        >\n          <div className={cn(\"relative origin-top overflow-hidden rounded-3xl will-change-transform\", itemClassName)}>\n            {child}\n            <div\n              aria-hidden\n              ref={(el) => {\n                shades.current[i] = el;\n              }}\n              className=\"pointer-events-none absolute inset-0 bg-black opacity-0\"\n            />\n          </div>\n        </div>\n      ))}\n    </div>\n  );\n}\n"}]}