{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-morph-cursor",
  "type": "registry:component",
  "title": "Morph Cursor",
  "description": "A custom cursor that melts into the exact shape of whatever you hover, pill, circle or rounded rectangle, and inverts what is under it. Between targets it stretches along its path like a drop of liquid.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "cursor",
    "morph",
    "blend",
    "toolbar",
    "pointer",
    "spring"
  ],
  "docs": "https://hyperblur.dev/effects/hover-morph-cursor",
  "files": [
    {
      "path": "registry/hyperblur/hover-morph-cursor.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hover-morph-cursor.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HoverMorphCursorProps extends React.HTMLAttributes<HTMLDivElement> {\n  selector?: string;\n  size?: number;\n  padding?: number;\n  color?: string;\n  blend?: boolean;\n  autoPlay?: boolean;\n}\n\nconst css = `\n.hb-wg6 { position: relative; box-sizing: border-box; width: 100%; height: 100%; font-family: inherit; isolation: isolate; touch-action: pan-y; }\n.hb-wg6 *, .hb-wg6 *::before, .hb-wg6 *::after { box-sizing: border-box; }\n@media (hover: hover) and (pointer: fine) {\n  .hb-wg6[data-inside=\"true\"], .hb-wg6[data-inside=\"true\"] * { cursor: none !important; }\n}\n.hb-wg6-blob { position: absolute; left: 0; top: 0; z-index: 5; pointer-events: none; width: 1px; height: 1px; background: var(--hb-wg6-color, #ededed); opacity: 0; transform-origin: 0 0; will-change: transform, width, height, border-radius; transition: opacity .35s ease; }\n.hb-wg6[data-blend=\"true\"] .hb-wg6-blob { mix-blend-mode: difference; }\n.hb-wg6[data-show=\"true\"] .hb-wg6-blob { opacity: 1; }\n.hb-wg6-blob::after { content: \"\"; position: absolute; inset: -6px; border-radius: inherit; border: 1px solid var(--hb-wg6-color, #ededed); opacity: 0; transform: scale(.9); transition: opacity .3s ease, transform .45s cubic-bezier(.2,.9,.25,1); }\n.hb-wg6[data-locked=\"true\"] .hb-wg6-blob::after { opacity: .28; transform: none; }\n.hb-wg6-default { display: flex; height: 100%; align-items: center; justify-content: center; padding: 16px; }\n.hb-wg6-bar { display: flex; align-items: center; gap: 4px; padding: 6px; border-radius: 14px; background: #111; box-shadow: 0 0 0 1px #262626, inset 0 1px 0 rgba(255,255,255,.04), 0 14px 30px -18px rgba(0,0,0,.9); color: #ededed; }\n.hb-wg6-icon, .hb-wg6-pill, .hb-wg6-seg { appearance: none; border: 0; background: none; color: inherit; font: inherit; margin: 0; display: inline-grid; place-items: center; outline: none; }\n.hb-wg6-icon { width: 32px; height: 32px; border-radius: 50%; color: #a1a1a1; }\n.hb-wg6-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }\n.hb-wg6-sep { width: 1px; height: 20px; background: #262626; margin: 0 4px; }\n.hb-wg6-seg { height: 32px; padding: 0 11px; border-radius: 8px; font-size: 12px; color: #a1a1a1; }\n.hb-wg6-pill { height: 32px; padding: 0 14px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #ededed; color: #0a0a0a; margin-left: 4px; }\n.hb-wg6-icon:focus-visible, .hb-wg6-seg:focus-visible, .hb-wg6-pill:focus-visible { box-shadow: 0 0 0 2px #2f7bff; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wg6-blob { display: none; }\n  .hb-wg6[data-inside=\"true\"], .hb-wg6[data-inside=\"true\"] * { cursor: auto !important; }\n}\n`;\n\nfunction DefaultBar() {\n  const path = (d: string) => (\n    <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n      <path d={d} />\n    </svg>\n  );\n  return (\n    <div className=\"hb-wg6-default\">\n      <div className=\"hb-wg6-bar\" role=\"toolbar\" aria-label=\"Editor\">\n        <button type=\"button\" className=\"hb-wg6-icon\" aria-label=\"Undo\">{path(\"M9 7L4.5 11.5 9 16M5 11.5h9a5 5 0 0 1 0 10h-2\")}</button>\n        <button type=\"button\" className=\"hb-wg6-icon\" aria-label=\"Comment\">{path(\"M5 6h14v9h-8l-4 3.5V15H5z\")}</button>\n        <span className=\"hb-wg6-sep\" aria-hidden=\"true\" />\n        <button type=\"button\" className=\"hb-wg6-seg\">Design</button>\n        <button type=\"button\" className=\"hb-wg6-seg\">Prototype</button>\n        <button type=\"button\" className=\"hb-wg6-pill\">Share</button>\n      </div>\n    </div>\n  );\n}\n\nexport function HoverMorphCursor({\n  selector = \"button, a, [data-morph]\",\n  size = 14,\n  padding = 0,\n  color = \"#ededed\",\n  blend = true,\n  autoPlay = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: HoverMorphCursorProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const blobRef = React.useRef<HTMLSpanElement>(null);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const blob = blobRef.current;\n    if (!root || !blob) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const cur = { x: root.offsetWidth / 2, y: root.offsetHeight / 2, w: size, h: size, r: size / 2 };\n    const vel = { x: 0, y: 0, w: 0, h: 0, r: 0 };\n    let px = cur.x;\n    let py = cur.y;\n    let inside = false;\n    let target: HTMLElement | null = null;\n    let autoIdx = 0;\n    let autoT = 0;\n    let raf = 0;\n    let last = performance.now();\n    let visible = true;\n    let pressed = 0;\n    let lastPx = px;\n    let lastPy = py;\n\n    const scale = () => {\n      const r = root.getBoundingClientRect();\n      return { r, s: r.width ? root.offsetWidth / r.width : 1 };\n    };\n    const rectOf = (el: HTMLElement) => {\n      const { r, s } = scale();\n      const b = el.getBoundingClientRect();\n      const rad = parseFloat(getComputedStyle(el).borderTopLeftRadius) || 6;\n      return {\n        x: (b.left - r.left) * s - padding,\n        y: (b.top - r.top) * s - padding,\n        w: b.width * s + padding * 2,\n        h: b.height * s + padding * 2,\n        r: Math.min(rad + padding, (b.height * s + padding * 2) / 2),\n      };\n    };\n    const targets = () =>\n      (Array.from(root.querySelectorAll(selector)) as HTMLElement[]).filter((el) => !blob.contains(el) && el.offsetParent !== null);\n\n    const spring = (key: keyof typeof cur, goal: number, dt: number, k: number, d: number) => {\n      const a = (goal - cur[key]) * k - vel[key] * d;\n      vel[key] += a * dt;\n      cur[key] += vel[key] * dt;\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.032, (now - last) / 1000);\n      last = now;\n      let goal: { x: number; y: number; w: number; h: number; r: number };\n      let el: HTMLElement | null = inside ? target : null;\n      if (!inside && autoPlay) {\n        autoT += dt;\n        const list = targets();\n        if (autoT > 1.35 && list.length) {\n          autoT = 0;\n          autoIdx = (autoIdx + 1) % list.length;\n        }\n        el = list[autoIdx % Math.max(1, list.length)] ?? null;\n      }\n      if (el) {\n        goal = rectOf(el);\n        root.dataset.locked = \"true\";\n      } else {\n        const sz = size * (1 - pressed * 0.35);\n        goal = { x: px - sz / 2, y: py - sz / 2, w: sz, h: sz, r: sz / 2 };\n        root.dataset.locked = \"false\";\n      }\n      pressed *= Math.exp(-dt * 8);\n      const k = el ? 420 : 900;\n      const d = el ? 30 : 46;\n      spring(\"x\", goal.x, dt, k, d);\n      spring(\"y\", goal.y, dt, k, d);\n      spring(\"w\", goal.w, dt, k * 0.8, d);\n      spring(\"h\", goal.h, dt, k * 0.8, d);\n      spring(\"r\", goal.r, dt, k, d);\n      const speed = Math.hypot(vel.x, vel.y);\n      const stretch = Math.min(0.45, speed / 2600);\n      const ang = Math.atan2(vel.y, vel.x);\n      const w = Math.max(2, cur.w);\n      const h = Math.max(2, cur.h);\n      blob.style.width = `${w.toFixed(1)}px`;\n      blob.style.height = `${h.toFixed(1)}px`;\n      blob.style.borderRadius = `${Math.max(0, Math.min(cur.r, h / 2, w / 2)).toFixed(1)}px`;\n      const cx = cur.x + w / 2;\n      const cy = cur.y + h / 2;\n      blob.style.transform = `translate3d(${cx.toFixed(1)}px, ${cy.toFixed(1)}px, 0) rotate(${ang.toFixed(3)}rad) scale(${(1 + stretch).toFixed(3)}, ${(1 - stretch * 0.6).toFixed(3)}) rotate(${(-ang).toFixed(3)}rad) translate(${(-w / 2).toFixed(1)}px, ${(-h / 2).toFixed(1)}px)`;\n      lastPx = px;\n      lastPy = py;\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 pick = (node: EventTarget | null) => {\n      const elNode = node instanceof Element ? node.closest(selector) : null;\n      return elNode instanceof HTMLElement && root.contains(elNode) ? elNode : null;\n    };\n    const onMove = (e: PointerEvent) => {\n      const { r, s } = scale();\n      px = (e.clientX - r.left) * s;\n      py = (e.clientY - r.top) * s;\n      if (!inside && Math.hypot(px - lastPx, py - lastPy) > 200 && !target) {\n        cur.x = px - size / 2;\n        cur.y = py - size / 2;\n      }\n      inside = true;\n      target = pick(e.target);\n      root.dataset.inside = e.pointerType === \"mouse\" ? \"true\" : \"false\";\n      root.dataset.show = \"true\";\n    };\n    const onDown = (e: PointerEvent) => {\n      onMove(e);\n      pressed = 1;\n    };\n    const onLeave = () => {\n      inside = false;\n      target = null;\n      root.dataset.inside = \"false\";\n      root.dataset.show = autoPlay ? \"true\" : \"false\";\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\") window.setTimeout(onLeave, 1500);\n    };\n    const onFocusIn = (e: FocusEvent) => {\n      const el = pick(e.target);\n      if (!el) return;\n      inside = true;\n      target = el;\n      root.dataset.show = \"true\";\n    };\n    const onFocusOut = (e: FocusEvent) => {\n      if (!root.contains(e.relatedTarget as Node | null)) onLeave();\n    };\n    root.dataset.show = autoPlay ? \"true\" : \"false\";\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onDown);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointerup\", onUp);\n    root.addEventListener(\"focusin\", onFocusIn);\n    root.addEventListener(\"focusout\", onFocusOut);\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(\"pointerup\", onUp);\n      root.removeEventListener(\"focusin\", onFocusIn);\n      root.removeEventListener(\"focusout\", onFocusOut);\n    };\n  }, [selector, size, padding, autoPlay]);\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-wg6 ${className}`}\n      style={{ \"--hb-wg6-color\": color, ...style } as React.CSSProperties}\n      data-blend={blend ? \"true\" : \"false\"}\n      data-inside=\"false\"\n      data-show=\"false\"\n      data-locked=\"false\"\n      {...rest}\n    >\n      <style href=\"hb-hover-morph-cursor\" precedence=\"default\">{css}</style>\n      {children ?? <DefaultBar />}\n      <span ref={blobRef} className=\"hb-wg6-blob\" aria-hidden=\"true\" />\n    </div>\n  );\n}\n"
    }
  ]
}