{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-decay",
  "type": "registry:component",
  "title": "Card Decay",
  "description": "A card whose image follows the pointer on a spring and swings with its speed, while a large title and an outlined echo trail behind it.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "card",
    "spring",
    "inertia",
    "parallax",
    "title",
    "pointer"
  ],
  "docs": "https://hyperblur.dev/effects/card-decay",
  "files": [
    {
      "path": "registry/hyperblur/card-decay.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/card-decay.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CardDecayProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  title?: string;\n  kicker?: string;\n  caption?: string;\n  src?: string;\n  accent?: string;\n  strength?: number;\n  ratio?: number;\n  idle?: boolean;\n}\n\nconst css = `\n.hb-qk4 {\n  --hb-qk4-ix: 0px;\n  --hb-qk4-iy: 0px;\n  --hb-qk4-ir: 0deg;\n  --hb-qk4-tx: 0px;\n  --hb-qk4-ty: 0px;\n  --hb-qk4-gx: 0px;\n  --hb-qk4-gy: 0px;\n  position: relative;\n  display: block;\n  width: 100%;\n  aspect-ratio: var(--hb-qk4-r);\n  container-type: inline-size;\n  font-family: inherit;\n  box-sizing: border-box;\n  touch-action: pan-y;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-qk4 *, .hb-qk4 *::before, .hb-qk4 *::after { box-sizing: border-box; }\n.hb-qk4-frame {\n  position: absolute;\n  inset: 0;\n  overflow: hidden;\n  border-radius: 18px;\n  border: 1px solid #262626;\n  background: #0a0a0a;\n  color: #ededed;\n}\n.hb-qk4-img {\n  position: absolute;\n  inset: -14%;\n  background-size: cover;\n  background-position: center;\n  transform: translate3d(var(--hb-qk4-ix), var(--hb-qk4-iy), 0) rotate(var(--hb-qk4-ir));\n  will-change: transform;\n}\n.hb-qk4-scene {\n  background:\n    radial-gradient(circle at 74% 34%, #ffffff 0, color-mix(in srgb, var(--hb-qk4-c) 40%, #ffffff) 7%, transparent 8.5%),\n    radial-gradient(circle at 74% 34%, color-mix(in srgb, var(--hb-qk4-c) 75%, transparent) 0, transparent 34%),\n    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.07) 0 1px, transparent 1px 9px),\n    linear-gradient(180deg, color-mix(in srgb, var(--hb-qk4-c) 62%, #0a0a18) 0%, color-mix(in srgb, var(--hb-qk4-c) 20%, #050509) 100%);\n}\n.hb-qk4-skyline {\n  position: absolute;\n  inset: 0;\n  background: #06060b;\n  clip-path: polygon(0 78%, 6% 78%, 6% 62%, 12% 62%, 12% 70%, 18% 70%, 18% 54%, 25% 54%, 25% 72%, 32% 72%, 32% 60%, 38% 60%, 38% 76%, 46% 76%, 46% 58%, 53% 58%, 53% 68%, 60% 68%, 60% 50%, 68% 50%, 68% 74%, 75% 74%, 75% 64%, 83% 64%, 83% 72%, 90% 72%, 90% 56%, 96% 56%, 96% 78%, 100% 78%, 100% 100%, 0 100%);\n}\n.hb-qk4-shade {\n  position: absolute;\n  inset: 0;\n  pointer-events: none;\n  background: linear-gradient(180deg, rgba(5, 5, 8, 0.1) 30%, rgba(5, 5, 8, 0.78) 100%);\n}\n.hb-qk4-kick {\n  position: absolute;\n  left: 5cqw;\n  top: 5cqw;\n  padding: 1.6cqw 3.2cqw;\n  border-radius: 999px;\n  border: 1px solid rgba(255, 255, 255, 0.2);\n  background: rgba(10, 10, 12, 0.5);\n  font-size: max(10px, 3.4cqw);\n  font-weight: 500;\n  line-height: 1;\n  letter-spacing: 0.12em;\n  text-transform: uppercase;\n  color: #ededed;\n  transform: translate3d(calc(var(--hb-qk4-tx) * 0.5), calc(var(--hb-qk4-ty) * 0.5), 0);\n  will-change: transform;\n}\n.hb-qk4-head {\n  position: absolute;\n  left: 5cqw;\n  right: 5cqw;\n  bottom: 4.6cqw;\n}\n.hb-qk4-title, .hb-qk4-ghost {\n  display: block;\n  margin: 0;\n  font-size: 14cqw;\n  font-weight: 700;\n  line-height: 0.95;\n  letter-spacing: -0.02em;\n  white-space: nowrap;\n}\n.hb-qk4-title {\n  position: relative;\n  color: #ffffff;\n  transform: translate3d(var(--hb-qk4-tx), var(--hb-qk4-ty), 0);\n  will-change: transform;\n}\n.hb-qk4-ghost {\n  position: absolute;\n  left: 0;\n  top: 0;\n  color: transparent;\n  -webkit-text-stroke: 1px rgba(255, 255, 255, 0.4);\n  transform: translate3d(var(--hb-qk4-gx), var(--hb-qk4-gy), 0);\n  will-change: transform;\n  pointer-events: none;\n}\n.hb-qk4-cap {\n  margin: 2.4cqw 0 0;\n  font-size: max(11px, 3.6cqw);\n  line-height: 1.3;\n  color: #bdbdbd;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qk4-img, .hb-qk4-kick, .hb-qk4-title, .hb-qk4-ghost { transform: none; will-change: auto; }\n}\n`;\n\ninterface Spring {\n  x: number;\n  y: number;\n  vx: number;\n  vy: number;\n}\n\nfunction clampN(n: number) {\n  return Math.min(1, Math.max(-1, n));\n}\n\nfunction advance(p: Spring, tx: number, ty: number, k: number, c: number, dt: number) {\n  const steps = 2;\n  const h = dt / steps;\n  for (let i = 0; i < steps; i += 1) {\n    p.vx += (k * (tx - p.x) - c * p.vx) * h;\n    p.vy += (k * (ty - p.y) - c * p.vy) * h;\n    p.x += p.vx * h;\n    p.y += p.vy * h;\n  }\n}\n\nexport function CardDecay({\n  title = \"Neon Harbor\",\n  kicker = \"Night shift 03\",\n  caption = \"Container cranes, rain and 4 a.m. light\",\n  src,\n  accent = \"#2f7bff\",\n  strength = 22,\n  ratio = 1.7,\n  idle = true,\n  className = \"\",\n  style,\n  onPointerMove,\n  onPointerLeave,\n  onPointerCancel,\n  ...rest\n}: CardDecayProps) {\n  const root = React.useRef<HTMLDivElement>(null);\n  const st = React.useRef({ tx: 0, ty: 0, hover: false });\n\n  React.useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const s = st.current;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    if (reduce) return;\n    const img: Spring = { x: 0, y: 0, vx: 0, vy: 0 };\n    const tit: Spring = { x: 0, y: 0, vx: 0, vy: 0 };\n    const gho: Spring = { x: 0, y: 0, vx: 0, vy: 0 };\n    let raf = 0;\n    let last = 0;\n    const frame = (ms: number) => {\n      const t = ms / 1000;\n      const dt = Math.min(0.04, last ? t - last : 0.016);\n      last = t;\n      if (!s.hover) {\n        if (idle) {\n          s.tx = 0.9 * Math.sin(t * 0.9);\n          s.ty = 0.6 * Math.sin(t * 0.7 + 1.1);\n        } else {\n          s.tx = 0;\n          s.ty = 0;\n        }\n      }\n      advance(img, s.tx * strength, s.ty * strength, 140, 15, dt);\n      advance(tit, s.tx * strength * 1.3, s.ty * strength * 0.9, 52, 7, dt);\n      advance(gho, s.tx * strength * 1.9, s.ty * strength * 1.3, 28, 5, dt);\n      const rot = Math.max(-9, Math.min(9, img.vx * 0.014));\n      el.style.setProperty(\"--hb-qk4-ix\", `${img.x.toFixed(2)}px`);\n      el.style.setProperty(\"--hb-qk4-iy\", `${img.y.toFixed(2)}px`);\n      el.style.setProperty(\"--hb-qk4-ir\", `${rot.toFixed(2)}deg`);\n      el.style.setProperty(\"--hb-qk4-tx\", `${tit.x.toFixed(2)}px`);\n      el.style.setProperty(\"--hb-qk4-ty\", `${tit.y.toFixed(2)}px`);\n      el.style.setProperty(\"--hb-qk4-gx\", `${gho.x.toFixed(2)}px`);\n      el.style.setProperty(\"--hb-qk4-gy\", `${gho.y.toFixed(2)}px`);\n      raf = requestAnimationFrame(frame);\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      cancelAnimationFrame(raf);\n      last = 0;\n      if (entry.isIntersecting) raf = requestAnimationFrame(frame);\n    });\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [strength, idle]);\n\n  const move = (e: React.PointerEvent<HTMLDivElement>) => {\n    onPointerMove?.(e);\n    const r = e.currentTarget.getBoundingClientRect();\n    if (!r.width || !r.height) return;\n    const s = st.current;\n    s.hover = true;\n    s.tx = clampN(((e.clientX - r.left) / r.width - 0.5) * 2);\n    s.ty = clampN(((e.clientY - r.top) / r.height - 0.5) * 2);\n  };\n\n  const leave = (e: React.PointerEvent<HTMLDivElement>) => {\n    onPointerLeave?.(e);\n    st.current.hover = false;\n  };\n\n  const cancel = (e: React.PointerEvent<HTMLDivElement>) => {\n    onPointerCancel?.(e);\n    st.current.hover = false;\n  };\n\n  return (\n    <div\n      ref={root}\n      className={`hb-qk4 ${className}`}\n      style={{ \"--hb-qk4-r\": ratio, \"--hb-qk4-c\": accent, ...style } as React.CSSProperties}\n      onPointerMove={move}\n      onPointerLeave={leave}\n      onPointerCancel={cancel}\n      {...rest}\n    >\n      <style href=\"hb-card-decay\" precedence=\"default\">{css}</style>\n      <div className=\"hb-qk4-frame\">\n        {src ? (\n          <div className=\"hb-qk4-img\" style={{ backgroundImage: `url(${JSON.stringify(src)})` }} aria-hidden=\"true\" />\n        ) : (\n          <div className=\"hb-qk4-img hb-qk4-scene\" aria-hidden=\"true\">\n            <span className=\"hb-qk4-skyline\" />\n          </div>\n        )}\n        <div className=\"hb-qk4-shade\" aria-hidden=\"true\" />\n        {kicker ? <span className=\"hb-qk4-kick\">{kicker}</span> : null}\n        <div className=\"hb-qk4-head\">\n          <span className=\"hb-qk4-ghost\" aria-hidden=\"true\">{title}</span>\n          <h3 className=\"hb-qk4-title\">{title}</h3>\n          {caption ? <p className=\"hb-qk4-cap\">{caption}</p> : null}\n        </div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}