{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"parallax-cards","type":"registry:ui","title":"Parallax Cards","description":"A draggable, snapping row of photo cards whose images drift inside their frames as the row scrolls and tilt toward the pointer.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/parallax-cards.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef, type CSSProperties, type PointerEvent } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ParallaxCardItem {\n  image: string;\n  title: string;\n  subtitle?: string;\n  /** Small chip in the top-left corner. */\n  tag?: string;\n}\n\nexport interface ParallaxCardsProps {\n  items: ParallaxCardItem[];\n  /** Card width in px. */\n  cardWidth?: number;\n  /** Card height in px. */\n  cardHeight?: number;\n  /** Px between cards. */\n  gap?: number;\n  /** How far the photo drifts inside its card while scrolling, as a fraction of the card width. */\n  intensity?: number;\n  /** Max pointer tilt in degrees. */\n  tilt?: number;\n  /** Fade the row out at both edges. */\n  fadeEdges?: boolean;\n  className?: string;\n}\n\nconst clamp = (v: number) => Math.max(-1, Math.min(1, v));\n\nexport function ParallaxCards({\n  items,\n  cardWidth = 280,\n  cardHeight = 380,\n  gap = 20,\n  intensity = 0.2,\n  tilt = 6,\n  fadeEdges = true,\n  className,\n}: ParallaxCardsProps) {\n  const scroller = useRef<HTMLDivElement>(null);\n  const reduced = useRef(false);\n  const drag = useRef<{ x: number; left: number; moved: boolean } | null>(null);\n\n  // Horizontal scroll parallax: each card gets --px in [-1, 1] by its distance from the center.\n  useEffect(() => {\n    const el = scroller.current;\n    if (!el) return;\n    reduced.current = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const cards = Array.from(el.querySelectorAll<HTMLElement>(\"[data-pc-card]\"));\n    let raf = 0;\n    const update = () => {\n      raf = 0;\n      const half = el.clientWidth / 2;\n      const center = el.scrollLeft + half;\n      const max = el.scrollWidth - el.clientWidth;\n      el.parentElement?.style.setProperty(\"--pc-progress\", String(max > 0 ? el.scrollLeft / max : 0));\n      if (reduced.current) return;\n      for (const c of cards) {\n        c.style.setProperty(\"--px\", clamp((c.offsetLeft + c.offsetWidth / 2 - center) / (half + c.offsetWidth / 2)).toFixed(4));\n      }\n    };\n    const onScroll = () => {\n      if (!raf) raf = requestAnimationFrame(update);\n    };\n    // Start in the middle of the row so both sides are filled.\n    el.scrollLeft = (el.scrollWidth - el.clientWidth) / 2;\n    update();\n    el.addEventListener(\"scroll\", onScroll, { passive: true });\n    const ro = new ResizeObserver(onScroll);\n    ro.observe(el);\n    return () => {\n      el.removeEventListener(\"scroll\", onScroll);\n      ro.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [items.length, cardWidth, gap]);\n\n  const onCardMove = (e: PointerEvent<HTMLElement>) => {\n    if (reduced.current || drag.current?.moved) return;\n    const r = e.currentTarget.getBoundingClientRect();\n    const x = ((e.clientX - r.left) / r.width) * 2 - 1;\n    const y = ((e.clientY - r.top) / r.height) * 2 - 1;\n    const s = e.currentTarget.style;\n    s.setProperty(\"--mx\", x.toFixed(3));\n    s.setProperty(\"--my\", y.toFixed(3));\n    s.setProperty(\"--hover\", \"1\");\n  };\n  const onCardLeave = (e: PointerEvent<HTMLElement>) => {\n    const s = e.currentTarget.style;\n    s.setProperty(\"--mx\", \"0\");\n    s.setProperty(\"--my\", \"0\");\n    s.setProperty(\"--hover\", \"0\");\n  };\n\n  // Mouse drag-to-scroll (touch and trackpads scroll natively).\n  const onDown = (e: PointerEvent<HTMLDivElement>) => {\n    if (e.pointerType !== \"mouse\" || e.button !== 0) return;\n    drag.current = { x: e.clientX, left: e.currentTarget.scrollLeft, moved: false };\n  };\n  const onMove = (e: PointerEvent<HTMLDivElement>) => {\n    const d = drag.current;\n    if (!d) return;\n    const dx = e.clientX - d.x;\n    if (!d.moved && Math.abs(dx) > 4) {\n      d.moved = true;\n      e.currentTarget.setPointerCapture(e.pointerId);\n      e.currentTarget.style.scrollSnapType = \"none\";\n      e.currentTarget.style.cursor = \"grabbing\";\n    }\n    if (d.moved) e.currentTarget.scrollLeft = d.left - dx;\n  };\n  const onUp = (e: PointerEvent<HTMLDivElement>) => {\n    const el = e.currentTarget;\n    if (drag.current?.moved) {\n      el.style.cursor = \"\";\n      // Re-enabling snap makes the browser glide to the nearest card.\n      el.style.scrollSnapType = \"\";\n    }\n    drag.current = null;\n  };\n\n  const pad = cardWidth * intensity;\n  const mask = \"linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent)\";\n\n  return (\n    <div className={cn(\"relative w-full contain-inline-size\", className)}>\n      <div\n        ref={scroller}\n        role=\"region\"\n        aria-label=\"Cards\"\n        tabIndex={0}\n        onPointerDown={onDown}\n        onPointerMove={onMove}\n        onPointerUp={onUp}\n        onPointerCancel={onUp}\n        className=\"flex cursor-grab snap-x snap-mandatory overflow-x-auto overscroll-x-contain py-8 outline-none [scrollbar-width:none] focus-visible:ring-2 focus-visible:ring-ring [&::-webkit-scrollbar]:hidden\"\n        style={{\n          gap,\n          paddingInline: `calc(50% - ${cardWidth / 2}px)`,\n          maskImage: fadeEdges ? mask : undefined,\n          WebkitMaskImage: fadeEdges ? mask : undefined,\n        }}\n      >\n        {items.map((it, i) => (\n          <figure\n            key={it.image + i}\n            data-pc-card\n            onPointerMove={onCardMove}\n            onPointerLeave={onCardLeave}\n            className=\"group relative m-0 shrink-0 snap-center [perspective:900px]\"\n            style={{ width: cardWidth, height: cardHeight, [\"--px\" as string]: 0, [\"--mx\" as string]: 0, [\"--my\" as string]: 0, [\"--hover\" as string]: 0 } as CSSProperties}\n          >\n            <div\n              className=\"relative h-full w-full overflow-hidden rounded-[22px] border border-border bg-muted shadow-[0_30px_60px_-30px_rgba(0,0,0,.7)] transition-[transform,box-shadow] duration-500 ease-out will-change-transform group-hover:shadow-[0_40px_80px_-30px_rgba(0,0,0,.85)] motion-reduce:transition-none\"\n              style={{\n                transform: `rotateX(calc(var(--my) * ${-tilt}deg)) rotateY(calc(var(--mx) * ${tilt}deg)) scale(calc(1 + var(--hover) * .02))`,\n              }}\n            >\n              {/* Scroll layer: moves against the card, no transition so it tracks scroll 1:1. */}\n              <div\n                aria-hidden\n                className=\"absolute inset-y-[-24px] will-change-transform\"\n                style={{ left: -pad - 16, right: -pad - 16, transform: `translate3d(calc(var(--px) * ${-pad}px), 0, 0)` }}\n              >\n                {/* eslint-disable-next-line @next/next/no-img-element */}\n                <img\n                  src={it.image}\n                  alt=\"\"\n                  draggable={false}\n                  className=\"h-full w-full select-none object-cover transition-transform duration-700 ease-out motion-reduce:transition-none\"\n                  style={{ transform: `translate3d(calc(var(--mx) * -14px), calc(var(--my) * -14px), 0)` }}\n                />\n              </div>\n\n              <div aria-hidden className=\"absolute inset-0 bg-gradient-to-t from-black/85 via-black/10 to-black/20\" />\n              {/* Soft glare that follows the pointer. */}\n              <div\n                aria-hidden\n                className=\"pointer-events-none absolute inset-0 opacity-0 transition-opacity duration-500 group-hover:opacity-100\"\n                style={{\n                  background:\n                    \"radial-gradient(420px circle at calc(50% + var(--mx) * 50%) calc(50% + var(--my) * 50%), rgba(255,255,255,.16), transparent 45%)\",\n                }}\n              />\n\n              <div\n                className=\"absolute inset-0 flex flex-col justify-between p-5 text-white transition-transform duration-500 ease-out motion-reduce:transition-none\"\n                style={{ transform: `translate3d(calc(var(--mx) * 6px), calc(var(--my) * 6px), 0)` }}\n              >\n                <div className=\"flex items-start justify-between\">\n                  {it.tag ? (\n                    <span className=\"rounded-full border border-white/20 bg-white/10 px-2.5 py-1 text-[11px] font-medium uppercase tracking-wider backdrop-blur-md\">\n                      {it.tag}\n                    </span>\n                  ) : (\n                    <span />\n                  )}\n                  <span className=\"font-mono text-xs text-white/70\">\n                    {String(i + 1).padStart(2, \"0\")}/{String(items.length).padStart(2, \"0\")}\n                  </span>\n                </div>\n                <figcaption>\n                  <p className=\"text-2xl font-semibold leading-tight tracking-tight\">{it.title}</p>\n                  {it.subtitle && <p className=\"mt-1 text-sm text-white/75\">{it.subtitle}</p>}\n                </figcaption>\n              </div>\n            </div>\n          </figure>\n        ))}\n      </div>\n      <div aria-hidden className=\"mx-auto h-0.5 w-40 overflow-hidden rounded-full bg-foreground/10\">\n        <div\n          className=\"h-full w-1/4 rounded-full bg-foreground/70\"\n          style={{ transform: \"translateX(calc(var(--pc-progress, 0) * 300%))\" }}\n        />\n      </div>\n    </div>\n  );\n}\n"}]}