{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-distort-image",
  "type": "registry:component",
  "title": "Velocity Distort Image",
  "description": "An image that warps like heat haze in proportion to how fast the pointer moves over it, with the red and blue channels pulled apart along the direction of travel. It settles back to sharp when the pointer slows.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "image",
    "distortion",
    "svg filter",
    "chromatic",
    "velocity",
    "hover"
  ],
  "docs": "https://hyperblur.dev/effects/hover-distort-image",
  "files": [
    {
      "path": "registry/hyperblur/hover-distort-image.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hover-distort-image.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HoverDistortImageProps extends React.HTMLAttributes<HTMLDivElement> {\n  src?: string;\n  title?: string;\n  caption?: string;\n  intensity?: number;\n  split?: number;\n  autoPlay?: boolean;\n  ratio?: number;\n}\n\nconst css = `\n.hb-wg5 { position: relative; box-sizing: border-box; width: 100%; border-radius: 14px; overflow: hidden; font-family: inherit; color: #ededed; background: #0d0d0d; box-shadow: 0 0 0 1px #262626, 0 22px 40px -24px rgba(0,0,0,.9); isolation: isolate; touch-action: pan-y; cursor: crosshair; }\n.hb-wg5 *, .hb-wg5 *::before, .hb-wg5 *::after { box-sizing: border-box; }\n.hb-wg5-svg { display: block; width: 100%; height: 100%; }\n.hb-wg5-img { transform-origin: 50% 50%; transition: transform 1.1s cubic-bezier(.16,1,.3,1); }\n.hb-wg5[data-live=\"true\"] .hb-wg5-img { transform: scale(1.04); }\n.hb-wg5-meta { position: absolute; left: 12px; right: 12px; bottom: 11px; display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; pointer-events: none; }\n.hb-wg5-title { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.015em; line-height: 1.1; text-shadow: 0 1px 10px rgba(0,0,0,.5); }\n.hb-wg5-cap { margin: 3px 0 0; font-family: var(--font-mono, ui-monospace, monospace); font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; color: rgba(237,237,237,.7); }\n.hb-wg5-gauge { display: flex; align-items: flex-end; gap: 2px; height: 16px; }\n.hb-wg5-bar { width: 3px; border-radius: 1px; background: rgba(255,255,255,.22); height: 30%; transition: height .18s ease-out, background .2s ease; }\n.hb-wg5-bar[data-on=\"true\"] { background: #ededed; }\n.hb-wg5::after { content: \"\"; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, transparent 50%, rgba(0,0,0,.55)); }\n.hb-wg5-meta { z-index: 1; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wg5-img, .hb-wg5-bar { transition: none; }\n  .hb-wg5[data-live=\"true\"] .hb-wg5-img { transform: none; }\n}\n`;\n\nfunction Scene() {\n  return (\n    <>\n      <defs>\n        <linearGradient id=\"hb-wg5-sky\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n          <stop offset=\"0\" stopColor=\"#1b1446\" />\n          <stop offset=\".45\" stopColor=\"#c2417a\" />\n          <stop offset=\".72\" stopColor=\"#ff9a5a\" />\n          <stop offset=\"1\" stopColor=\"#ffd59a\" />\n        </linearGradient>\n        <linearGradient id=\"hb-wg5-sea\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n          <stop offset=\"0\" stopColor=\"#3a1f55\" />\n          <stop offset=\"1\" stopColor=\"#0a0b1e\" />\n        </linearGradient>\n        <radialGradient id=\"hb-wg5-sun\" cx=\".5\" cy=\".5\" r=\".5\">\n          <stop offset=\"0\" stopColor=\"#fff4d6\" />\n          <stop offset=\".7\" stopColor=\"#ffd08a\" />\n          <stop offset=\"1\" stopColor=\"#ff9a5a\" stopOpacity=\"0\" />\n        </radialGradient>\n      </defs>\n      <rect width=\"400\" height=\"260\" fill=\"url(#hb-wg5-sky)\" />\n      <circle cx=\"200\" cy=\"150\" r=\"64\" fill=\"url(#hb-wg5-sun)\" />\n      {[0, 1, 2, 3, 4].map((i) => (\n        <rect key={i} x=\"120\" y={(122 + i * 8.5).toFixed(1)} width=\"160\" height={(1.2 + i * 0.9).toFixed(1)} fill=\"#c2417a\" opacity=\".85\" />\n      ))}\n      <path d=\"M0 160 L46 128 L84 146 L132 112 L170 150 L0 160Z\" fill=\"#2a1847\" />\n      <path d=\"M230 160 L270 120 L300 138 L344 104 L400 140 L400 160Z\" fill=\"#251540\" />\n      <rect y=\"158\" width=\"400\" height=\"102\" fill=\"url(#hb-wg5-sea)\" />\n      {Array.from({ length: 14 }, (_, i) => {\n        const y = 164 + i * 7;\n        const w = 30 + i * 9;\n        return <rect key={i} x={(200 - w / 2).toFixed(1)} y={y} width={w.toFixed(1)} height=\"1.6\" rx=\".8\" fill=\"#ffc38a\" opacity={(0.75 - i * 0.045).toFixed(3)} />;\n      })}\n    </>\n  );\n}\n\nexport function HoverDistortImage({\n  src,\n  title = \"Low tide, Algarve\",\n  caption = \"Frame 0412 · 35mm\",\n  intensity = 34,\n  split = 5,\n  autoPlay = true,\n  ratio = 0.62,\n  className = \"\",\n  style,\n  ...rest\n}: HoverDistortImageProps) {\n  const rawId = React.useId();\n  const id = `hb-wg5-f${rawId.replace(/[^a-zA-Z0-9]/g, \"\")}`;\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const turbRef = React.useRef<SVGFETurbulenceElement>(null);\n  const dispRef = React.useRef<SVGFEDisplacementMapElement>(null);\n  const rRef = React.useRef<SVGFEOffsetElement>(null);\n  const bRef = React.useRef<SVGFEOffsetElement>(null);\n  const gaugeRef = React.useRef<HTMLDivElement>(null);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const turb = turbRef.current;\n    const disp = dispRef.current;\n    const ro = rRef.current;\n    const bo = bRef.current;\n    const gauge = gaugeRef.current;\n    if (!root || !turb || !disp || !ro || !bo || !gauge) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const bars = Array.from(gauge.children) as HTMLElement[];\n    let lx = 0;\n    let ly = 0;\n    let has = false;\n    let energy = 0;\n    let dirX = 1;\n    let dirY = 0;\n    let inside = false;\n    let t = 0;\n    let raf = 0;\n    let last = performance.now();\n    let visible = true;\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      t += dt;\n      if (!inside && autoPlay) {\n        const pulse = Math.pow(Math.max(0, Math.sin(t * 1.1)), 6);\n        energy = Math.max(energy, pulse * 0.75);\n      }\n      energy *= Math.exp(-dt * 2.4);\n      const e = Math.min(1, energy);\n      const scale = intensity * e;\n      const f1 = 0.012 + 0.01 * e + 0.002 * Math.sin(t * 3.1);\n      const f2 = 0.03 + 0.05 * e;\n      turb.setAttribute(\"baseFrequency\", `${f1.toFixed(4)} ${f2.toFixed(4)}`);\n      disp.setAttribute(\"scale\", scale.toFixed(2));\n      const off = split * e;\n      ro.setAttribute(\"dx\", (off * dirX).toFixed(2));\n      ro.setAttribute(\"dy\", (off * dirY).toFixed(2));\n      bo.setAttribute(\"dx\", (-off * dirX).toFixed(2));\n      bo.setAttribute(\"dy\", (-off * dirY).toFixed(2));\n      root.dataset.live = inside || e > 0.15 ? \"true\" : \"false\";\n      bars.forEach((b, i) => {\n        const on = e > (i + 0.5) / bars.length;\n        b.dataset.on = on ? \"true\" : \"false\";\n        b.style.height = `${(30 + 70 * Math.min(1, e * bars.length / (i + 1))).toFixed(0)}%`;\n      });\n      raf = requestAnimationFrame(frame);\n    };\n    const start = () => {\n      if (raf || !visible) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    };\n    const stop = () => {\n      if (raf) cancelAnimationFrame(raf);\n      raf = 0;\n    };\n    const onMove = (e: PointerEvent) => {\n      inside = true;\n      if (has) {\n        const dx = e.clientX - lx;\n        const dy = e.clientY - ly;\n        const d = Math.hypot(dx, dy);\n        if (d > 0.5) {\n          dirX = dirX * 0.7 + (dx / d) * 0.3;\n          dirY = dirY * 0.7 + (dy / d) * 0.3;\n          const m = Math.hypot(dirX, dirY) || 1;\n          dirX /= m;\n          dirY /= m;\n        }\n        energy = Math.min(1.2, energy + d * 0.012);\n      }\n      lx = e.clientX;\n      ly = e.clientY;\n      has = true;\n    };\n    const onDown = (e: PointerEvent) => {\n      onMove(e);\n      energy = Math.min(1.2, energy + 0.6);\n    };\n    const onLeave = () => {\n      inside = false;\n      has = false;\n    };\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onDown);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointercancel\", onLeave);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n      else stop();\n    });\n    io.observe(root);\n    start();\n    return () => {\n      stop();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onDown);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointercancel\", onLeave);\n    };\n  }, [intensity, split, autoPlay]);\n\n  const h = Math.round(400 * ratio);\n\n  return (\n    <div ref={rootRef} className={`hb-wg5 ${className}`} style={{ aspectRatio: `400 / ${h}`, ...style }} data-live=\"false\" role=\"img\" aria-label={title} {...rest}>\n      <style href=\"hb-hover-distort-image\" precedence=\"default\">{css}</style>\n      <svg className=\"hb-wg5-svg\" viewBox={`0 0 400 ${h}`} preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n        <defs>\n          <filter id={id} x=\"-5%\" y=\"-5%\" width=\"110%\" height=\"110%\" colorInterpolationFilters=\"sRGB\">\n            <feTurbulence ref={turbRef} type=\"fractalNoise\" baseFrequency=\"0.012 0.03\" numOctaves={2} seed={3} result=\"noise\" />\n            <feDisplacementMap ref={dispRef} in=\"SourceGraphic\" in2=\"noise\" scale={0} xChannelSelector=\"R\" yChannelSelector=\"G\" result=\"warp\" />\n            <feColorMatrix in=\"warp\" type=\"matrix\" values=\"1 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 1 0\" result=\"red\" />\n            <feOffset ref={rRef} in=\"red\" dx={0} dy={0} result=\"red2\" />\n            <feColorMatrix in=\"warp\" type=\"matrix\" values=\"0 0 0 0 0  0 1 0 0 0  0 0 0 0 0  0 0 0 1 0\" result=\"green\" />\n            <feColorMatrix in=\"warp\" type=\"matrix\" values=\"0 0 0 0 0  0 0 0 0 0  0 0 1 0 0  0 0 0 1 0\" result=\"blue\" />\n            <feOffset ref={bRef} in=\"blue\" dx={0} dy={0} result=\"blue2\" />\n            <feBlend in=\"red2\" in2=\"green\" mode=\"screen\" result=\"rg\" />\n            <feBlend in=\"rg\" in2=\"blue2\" mode=\"screen\" />\n          </filter>\n        </defs>\n        <g className=\"hb-wg5-img\" filter={`url(#${id})`}>\n          {src ? <image href={src} width=\"400\" height={h} preserveAspectRatio=\"xMidYMid slice\" /> : <Scene />}\n        </g>\n      </svg>\n      <div className=\"hb-wg5-meta\">\n        <div>\n          <p className=\"hb-wg5-title\">{title}</p>\n          <p className=\"hb-wg5-cap\">{caption}</p>\n        </div>\n        <div ref={gaugeRef} className=\"hb-wg5-gauge\" aria-hidden=\"true\">\n          {[0, 1, 2, 3, 4].map((i) => (\n            <span key={i} className=\"hb-wg5-bar\" data-on=\"false\" />\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}