{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"melt-card","type":"registry:ui","title":"Melt Card","description":"An image card that leans toward the cursor and melts into noisy SVG displacement the faster you move.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/melt-card.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useId, useRef, type ReactNode } from \"react\";\n\nexport interface MeltCardProps {\n  image: string;\n  /** Card width in px. */\n  width?: number;\n  /** Card height in px. */\n  height?: number;\n  /** Strength of the displacement. 0 disables it. */\n  intensity?: number;\n  /** Noise frequency: lower = bigger, smoother blobs. */\n  frequency?: number;\n  /** How far the card drifts towards the cursor, in px. */\n  drift?: number;\n  /** Alt text for the image. */\n  alt?: string;\n  /** Overlay content, e.g. a caption. */\n  children?: ReactNode;\n  className?: string;\n}\n\nexport function MeltCard({\n  image,\n  width = 300,\n  height = 400,\n  intensity = 1,\n  frequency = 0.012,\n  drift = 18,\n  alt = \"\",\n  children,\n  className,\n}: MeltCardProps) {\n  const id = useId();\n  const root = useRef<HTMLDivElement>(null);\n  const card = useRef<HTMLDivElement>(null);\n  const disp = useRef<SVGFEDisplacementMapElement>(null);\n  const turb = useRef<SVGFETurbulenceElement>(null);\n\n  useEffect(() => {\n    const el = root.current!;\n    if (matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const s = { tx: 0, ty: 0, x: 0, y: 0, energy: 0, amount: 0, lastX: 0, lastY: 0, has: false, t: 0 };\n    let raf = 0;\n\n    const tick = () => {\n      if (!card.current || !disp.current || !turb.current) return void (raf = 0); // unmounted\n      s.x += (s.tx - s.x) * 0.08;\n      s.y += (s.ty - s.y) * 0.08;\n      s.energy *= 0.9; // cursor speed decays when the pointer rests\n      s.amount += (Math.min(1, s.energy) - s.amount) * 0.12;\n      s.t += 0.01 + s.amount * 0.03;\n      const nx = s.x / (width / 2);\n      const ny = s.y / (height / 2);\n      card.current!.style.transform = `translate3d(${nx * drift}px, ${ny * drift}px, 0) rotateX(${-ny * 6}deg) rotateY(${nx * 6}deg)`;\n      disp.current!.setAttribute(\"scale\", String(s.amount * 200 * intensity));\n      turb.current!.setAttribute(\"baseFrequency\", `${frequency} ${frequency * (1.2 + Math.sin(s.t) * 0.3)}`);\n      const moving = Math.abs(s.tx - s.x) + Math.abs(s.ty - s.y) > 0.2 || s.amount > 0.002 || s.energy > 0.002;\n      raf = moving ? requestAnimationFrame(tick) : 0;\n    };\n    const start = () => {\n      if (!raf) raf = requestAnimationFrame(tick);\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const r = el.getBoundingClientRect();\n      const px = e.clientX - r.left - r.width / 2;\n      const py = e.clientY - r.top - r.height / 2;\n      if (s.has) s.energy += Math.hypot(px - s.lastX, py - s.lastY) / 90;\n      s.energy = Math.min(s.energy, 1.6);\n      s.lastX = px;\n      s.lastY = py;\n      s.has = true;\n      s.tx = Math.max(-width / 2, Math.min(width / 2, px));\n      s.ty = Math.max(-height / 2, Math.min(height / 2, py));\n      start();\n    };\n    const onLeave = () => {\n      s.tx = s.ty = 0;\n      s.has = false;\n      start();\n    };\n    el.addEventListener(\"pointermove\", onMove);\n    el.addEventListener(\"pointerleave\", onLeave);\n    return () => {\n      cancelAnimationFrame(raf);\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, [width, height, intensity, frequency, drift]);\n\n  return (\n    <div ref={root} className={`p-10 ${className ?? \"\"}`} style={{ perspective: 900 }}>\n      <div\n        ref={card}\n        role=\"img\"\n        aria-label={alt || undefined}\n        className=\"relative overflow-hidden rounded-2xl bg-card shadow-[0_40px_80px_-30px_rgba(0,0,0,.8)] will-change-transform\"\n        style={{ width, height }}\n      >\n        <svg aria-hidden width={width} height={height} className=\"absolute inset-0 block\">\n          <defs>\n            <filter id={`${id}-f`} x=\"-10%\" y=\"-10%\" width=\"120%\" height=\"120%\" colorInterpolationFilters=\"sRGB\">\n              <feTurbulence ref={turb} type=\"fractalNoise\" baseFrequency={frequency} numOctaves={4} seed={7} result=\"noise\" />\n              <feDisplacementMap ref={disp} in=\"SourceGraphic\" in2=\"noise\" scale={0} xChannelSelector=\"R\" yChannelSelector=\"B\" />\n            </filter>\n          </defs>\n          <g filter={`url(#${id}-f)`}>\n            <image href={image} crossOrigin=\"anonymous\" x={0} y={0} width={width} height={height} preserveAspectRatio=\"xMidYMid slice\" />\n          </g>\n        </svg>\n        <div className=\"pointer-events-none absolute inset-0 bg-gradient-to-t from-black/70 via-transparent to-transparent\" />\n        {children && <div className=\"absolute inset-x-0 bottom-0 p-6 text-white\">{children}</div>}\n      </div>\n    </div>\n  );\n}\n"}]}