{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cursor-target",
  "type": "registry:component",
  "title": "Cursor Target",
  "description": "A lock-on reticle with four corner brackets and a rotating dashed ring. It follows the pointer and shrinks onto buttons and links when you hover or tab to them.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "cursor",
    "reticle",
    "lock-on",
    "hover",
    "focus",
    "pointer"
  ],
  "docs": "https://hyperblur.dev/effects/cursor-target",
  "files": [
    {
      "path": "registry/hyperblur/cursor-target.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cursor-target.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CursorTargetProps extends React.HTMLAttributes<HTMLDivElement> {\n  accent?: string;\n  size?: number;\n  padding?: number;\n  thickness?: number;\n  selector?: string;\n  showLabel?: boolean;\n  idle?: boolean;\n}\n\nconst css = `\n.hb-qi1 { position: relative; width: 100%; height: 100%; overflow: hidden; box-sizing: border-box; isolation: isolate; font-family: inherit; }\n.hb-qi1 *, .hb-qi1 *::before, .hb-qi1 *::after { box-sizing: border-box; }\n.hb-qi1-content { position: relative; z-index: 1; width: 100%; height: 100%; }\n.hb-qi1-reticle { position: absolute; left: 0; top: 0; z-index: 2; width: 44px; height: 44px; pointer-events: none; color: rgba(237, 237, 237, 0.88); opacity: 0; transition: color 0.2s ease, opacity 0.3s ease; will-change: transform, width, height; }\n.hb-qi1-reticle[data-ready=\"true\"] { opacity: 1; }\n.hb-qi1-reticle[data-locked=\"true\"] { color: var(--hb-qi1-accent); }\n.hb-qi1-corner { position: absolute; width: 10px; height: 10px; border: 0 solid currentColor; }\n.hb-qi1-tl { left: 0; top: 0; border-left-width: var(--hb-qi1-t); border-top-width: var(--hb-qi1-t); border-top-left-radius: 2px; }\n.hb-qi1-tr { right: 0; top: 0; border-right-width: var(--hb-qi1-t); border-top-width: var(--hb-qi1-t); border-top-right-radius: 2px; }\n.hb-qi1-bl { left: 0; bottom: 0; border-left-width: var(--hb-qi1-t); border-bottom-width: var(--hb-qi1-t); border-bottom-left-radius: 2px; }\n.hb-qi1-br { right: 0; bottom: 0; border-right-width: var(--hb-qi1-t); border-bottom-width: var(--hb-qi1-t); border-bottom-right-radius: 2px; }\n.hb-qi1-ring { position: absolute; left: 50%; top: 50%; width: var(--hb-qi1-ring); height: var(--hb-qi1-ring); margin: calc(var(--hb-qi1-ring) / -2) 0 0 calc(var(--hb-qi1-ring) / -2); border-radius: 50%; border: 1px dashed currentColor; opacity: 0.6; animation: hb-qi1-spin 7s linear infinite; transition: opacity 0.25s ease; }\n.hb-qi1-dot { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; background: currentColor; transition: opacity 0.2s ease; }\n.hb-qi1-reticle[data-locked=\"true\"] .hb-qi1-ring, .hb-qi1-reticle[data-locked=\"true\"] .hb-qi1-dot { opacity: 0; }\n.hb-qi1-chip { position: absolute; left: 0; top: calc(100% + 6px); white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; font: 500 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px 6px; border-radius: 4px; background: rgba(10, 10, 10, 0.82); border: 1px solid rgba(255, 255, 255, 0.12); color: currentColor; }\n.hb-qi1-reticle[data-flip=\"true\"] .hb-qi1-chip { top: auto; bottom: calc(100% + 6px); }\n@keyframes hb-qi1-spin { to { transform: rotate(360deg); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qi1-ring { animation: none; }\n  .hb-qi1-reticle, .hb-qi1-ring, .hb-qi1-dot { transition: none; }\n}\n`;\n\nfunction labelOf(el: HTMLElement) {\n  const text = el.getAttribute(\"data-hb-label\") || el.getAttribute(\"aria-label\") || el.textContent || \"\";\n  return text.trim().replace(/\\s+/g, \" \").slice(0, 24) || \"Target\";\n}\n\nexport function CursorTarget({\n  accent = \"#2f7bff\",\n  size = 44,\n  padding = 6,\n  thickness = 2,\n  selector = \"a, button, [data-hb-target]\",\n  showLabel = true,\n  idle = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: CursorTargetProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const contentRef = React.useRef<HTMLDivElement>(null);\n  const reticleRef = React.useRef<HTMLDivElement>(null);\n  const chipRef = React.useRef<HTMLSpanElement>(null);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const content = contentRef.current;\n    const reticle = reticleRef.current;\n    if (!root || !content || !reticle) return;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let w = root.clientWidth;\n    let h = root.clientHeight;\n    let px = w / 2;\n    let py = h / 2;\n    let cx = w / 2;\n    let cy = h / 2;\n    let cw = size;\n    let ch = size;\n    let active = false;\n    let mix = 0;\n    let hoverEl: HTMLElement | null = null;\n    let focusEl: HTMLElement | null = null;\n    let lastLabel = \"\";\n    let raf = 0;\n    let last = 0;\n    let t = 0;\n    let visible = true;\n\n    const toLocal = (rect: DOMRect) => {\n      const r0 = root.getBoundingClientRect();\n      const s = r0.width ? w / r0.width : 1;\n      return {\n        x: (rect.left - r0.left + rect.width / 2) * s,\n        y: (rect.top - r0.top + rect.height / 2) * s,\n        w: rect.width * s,\n        h: rect.height * s,\n      };\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      t += dt;\n      w = root.clientWidth;\n      h = root.clientHeight;\n      mix += ((active ? 1 : 0) - mix) * (1 - Math.exp(-dt * 5));\n      const items = Array.from(content.querySelectorAll<HTMLElement>(selector));\n      let lock: HTMLElement | null = focusEl ?? (active ? hoverEl : null);\n      let freeX = px;\n      let freeY = py;\n      let show = true;\n      if (!lock && !active) {\n        if (idle && !reduced) {\n          const slot = Math.floor(t / 2.2);\n          const n = items.length;\n          if (n && slot % (n + 1) < n) lock = items[slot % (n + 1)];\n          const ix = w * (0.5 + 0.34 * Math.sin(t * 0.55) + 0.05 * Math.sin(t * 1.9));\n          const iy = h * (0.5 + 0.3 * Math.sin(t * 0.83 + 0.7));\n          freeX = ix + (px - ix) * mix;\n          freeY = iy + (py - iy) * mix;\n        } else if (!idle) {\n          show = false;\n        }\n      }\n      let tx = freeX;\n      let ty = freeY;\n      let tw = size;\n      let th = size;\n      if (lock) {\n        const r = toLocal(lock.getBoundingClientRect());\n        tx = r.x;\n        ty = r.y;\n        tw = r.w + padding * 2;\n        th = r.h + padding * 2;\n      }\n      const kp = reduced ? 1 : 1 - Math.exp(-dt * 13);\n      const ks = reduced ? 1 : 1 - Math.exp(-dt * 11);\n      cx += (tx - cx) * kp;\n      cy += (ty - cy) * kp;\n      cw += (tw - cw) * ks;\n      ch += (th - ch) * ks;\n      reticle.style.transform = `translate3d(${(cx - cw / 2).toFixed(2)}px, ${(cy - ch / 2).toFixed(2)}px, 0)`;\n      reticle.style.width = `${cw.toFixed(2)}px`;\n      reticle.style.height = `${ch.toFixed(2)}px`;\n      reticle.dataset.ready = show ? \"true\" : \"false\";\n      reticle.dataset.locked = lock ? \"true\" : \"false\";\n      reticle.dataset.flip = cy + ch / 2 + 26 > h ? \"true\" : \"false\";\n      const chip = chipRef.current;\n      if (chip) {\n        const label = lock ? labelOf(lock) : `x ${Math.round(cx)} y ${Math.round(cy)}`;\n        if (label !== lastLabel) {\n          chip.textContent = label;\n          lastLabel = label;\n        }\n      }\n      raf = requestAnimationFrame(frame);\n    };\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\n    const onMove = (e: PointerEvent) => {\n      const r0 = root.getBoundingClientRect();\n      const s = r0.width ? w / r0.width : 1;\n      px = (e.clientX - r0.left) * s;\n      py = (e.clientY - r0.top) * s;\n      active = true;\n      const target = e.target instanceof Element ? e.target.closest<HTMLElement>(selector) : null;\n      hoverEl = target && content.contains(target) ? target : null;\n    };\n    const onLeave = () => {\n      active = false;\n      hoverEl = null;\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\") onLeave();\n    };\n    const onFocusIn = (e: FocusEvent) => {\n      const el = e.target instanceof HTMLElement ? e.target.closest<HTMLElement>(selector) : null;\n      let keyboard = false;\n      try {\n        keyboard = !!el && el.matches(\":focus-visible\");\n      } catch {\n        keyboard = !!el;\n      }\n      focusEl = el && keyboard && content.contains(el) ? el : null;\n    };\n    const onFocusOut = () => {\n      focusEl = null;\n    };\n\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointercancel\", 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\n    return () => {\n      stop();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointercancel\", onLeave);\n      root.removeEventListener(\"pointerup\", onUp);\n      root.removeEventListener(\"focusin\", onFocusIn);\n      root.removeEventListener(\"focusout\", onFocusOut);\n    };\n  }, [size, padding, selector, idle]);\n\n  const vars = {\n    \"--hb-qi1-accent\": accent,\n    \"--hb-qi1-t\": `${thickness}px`,\n    \"--hb-qi1-ring\": `${size + 16}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div ref={rootRef} className={`hb-qi1 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-cursor-target\" precedence=\"default\">{css}</style>\n      <div ref={contentRef} className=\"hb-qi1-content\">{children}</div>\n      <div ref={reticleRef} className=\"hb-qi1-reticle\" aria-hidden=\"true\">\n        <span className=\"hb-qi1-ring\" />\n        <span className=\"hb-qi1-corner hb-qi1-tl\" />\n        <span className=\"hb-qi1-corner hb-qi1-tr\" />\n        <span className=\"hb-qi1-corner hb-qi1-bl\" />\n        <span className=\"hb-qi1-corner hb-qi1-br\" />\n        <span className=\"hb-qi1-dot\" />\n        {showLabel ? <span ref={chipRef} className=\"hb-qi1-chip\" /> : null}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}