{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "target-lock-cursor",
  "title": "Target Lock Cursor",
  "description": "A custom cursor of four corner brackets that roams freely, then snaps around whatever you point at — links, buttons or anything marked data-lock — resizing to its exact bounds with a quick focus squeeze and a label tag, like a camera locking on.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/target-lock-cursor/target-lock-cursor.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface TargetLockCursorProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  /** CSS selector for elements the cursor locks onto. Elements with data-lock always count. */\n  targets?: string;\n  color?: string;\n  /** Size of the free-roaming reticle, in px. */\n  size?: number;\n  /** Gap between a locked target and the brackets, in px. */\n  padding?: number;\n  /** Length of each corner bracket, in px. */\n  corner?: number;\n  /** Show the target's data-lock text in a tag above it. */\n  showLabel?: boolean;\n  /** Keep the system cursor visible as well. */\n  keepCursor?: boolean;\n}\n\ntype Box = { x: number; y: number; w: number; h: number };\n\nexport function TargetLockCursor({ targets = \"a, button, [data-lock]\", color = \"#d4ff3f\", size = 26, padding = 8, corner = 12, showLabel = true, keepCursor = false, className, style, children, ...props }: TargetLockCursorProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const reticleRef = React.useRef<HTMLDivElement>(null);\n  const dotRef = React.useRef<HTMLSpanElement>(null);\n  const labelRef = React.useRef<HTMLSpanElement>(null);\n  const [active, setActive] = React.useState(false);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const reticle = reticleRef.current;\n    if (!root || !reticle) return;\n    const now: Box = { x: 0, y: 0, w: size, h: size };\n    const goal: Box = { x: 0, y: 0, w: size, h: size };\n    const mouse = { x: 0, y: 0, dx: 0, dy: 0 };\n    let target: HTMLElement | null = null;\n    let lockedAt = 0;\n    let raf = 0;\n    let running = false;\n    let shown = false;\n\n    const local = (rect: DOMRect) => {\n      const r = root.getBoundingClientRect();\n      // Map from screen px to the root's CSS px, in case a parent is scaled.\n      const scale = r.width / root.offsetWidth || 1;\n      return { x: (rect.left - r.left) / scale, y: (rect.top - r.top) / scale, w: rect.width / scale, h: rect.height / scale };\n    };\n    const aim = () => {\n      if (target && target.isConnected) {\n        const b = local(target.getBoundingClientRect());\n        goal.x = b.x - padding;\n        goal.y = b.y - padding;\n        goal.w = b.w + padding * 2;\n        goal.h = b.h + padding * 2;\n      } else {\n        goal.x = mouse.x - size / 2;\n        goal.y = mouse.y - size / 2;\n        goal.w = size;\n        goal.h = size;\n      }\n    };\n    const tick = (t: number) => {\n      aim();\n      // Locking on is quick and snappy; drifting free is a touch softer.\n      const k = target ? 0.26 : 0.32;\n      now.x += (goal.x - now.x) * k;\n      now.y += (goal.y - now.y) * k;\n      now.w += (goal.w - now.w) * k;\n      now.h += (goal.h - now.h) * k;\n      // A brief squeeze right after locking on, like a camera confirming focus.\n      const since = (t - lockedAt) / 1000;\n      const pulse = target && since < 0.45 ? Math.sin((since / 0.45) * Math.PI) * 5 : 0;\n      reticle.style.transform = `translate3d(${(now.x + pulse).toFixed(2)}px, ${(now.y + pulse).toFixed(2)}px, 0)`;\n      reticle.style.width = `${Math.max(4, now.w - pulse * 2).toFixed(2)}px`;\n      reticle.style.height = `${Math.max(4, now.h - pulse * 2).toFixed(2)}px`;\n      if (dotRef.current) {\n        dotRef.current.style.transform = `translate3d(${mouse.x.toFixed(1)}px, ${mouse.y.toFixed(1)}px, 0) translate(-50%, -50%)`;\n      }\n      const moving = Math.abs(goal.x - now.x) + Math.abs(goal.y - now.y) + Math.abs(goal.w - now.w) + Math.abs(goal.h - now.h) > 0.1 || pulse !== 0;\n      if (moving) raf = requestAnimationFrame(tick);\n      else running = false;\n    };\n    const kick = () => {\n      if (!running) {\n        running = true;\n        raf = requestAnimationFrame(tick);\n      }\n    };\n    const onMove = (event: PointerEvent) => {\n      if (event.pointerType !== \"mouse\") return;\n      const r = root.getBoundingClientRect();\n      const scale = r.width / root.offsetWidth || 1;\n      mouse.x = (event.clientX - r.left) / scale;\n      mouse.y = (event.clientY - r.top) / scale;\n      const hit = (event.target as Element | null)?.closest?.<HTMLElement>(`${targets}, [data-lock]`) ?? null;\n      const next = hit && root.contains(hit) && hit !== root ? hit : null;\n      if (next !== target) {\n        target = next;\n        lockedAt = performance.now();\n        if (labelRef.current) {\n          labelRef.current.textContent = target ? target.dataset.lock || target.getAttribute(\"aria-label\") || target.textContent?.trim().slice(0, 24) || \"\" : \"\";\n          labelRef.current.style.opacity = target && showLabel ? \"1\" : \"0\";\n        }\n        reticle.dataset.locked = target ? \"true\" : \"false\";\n      }\n      if (!shown) {\n        shown = true;\n        setActive(true);\n        // Appear right at the pointer instead of flying in from the corner.\n        aim();\n        Object.assign(now, goal);\n      }\n      kick();\n    };\n    const onLeave = () => {\n      shown = false;\n      target = null;\n      setActive(false);\n    };\n    const onScroll = () => target && kick();\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    window.addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n    return () => {\n      cancelAnimationFrame(raf);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      window.removeEventListener(\"scroll\", onScroll, { capture: true });\n    };\n  }, [targets, size, padding, showLabel]);\n\n  const bracket = (pos: string) => (\n    <span\n      className={cn(\"absolute\", pos)}\n      style={{\n        width: corner,\n        height: corner,\n        borderColor: color,\n        borderStyle: \"solid\",\n        borderWidth: 0,\n        ...(pos.includes(\"top-0\") ? { borderTopWidth: 2 } : { borderBottomWidth: 2 }),\n        ...(pos.includes(\"left-0\") ? { borderLeftWidth: 2 } : { borderRightWidth: 2 }),\n      }}\n    />\n  );\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"relative\", !keepCursor && \"[@media(pointer:fine)]:cursor-none [@media(pointer:fine)]:[&_*]:cursor-none\", className)}\n      style={style}\n      {...props}\n    >\n      {children}\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 z-50 overflow-visible transition-opacity duration-200\" style={{ opacity: active ? 1 : 0 }}>\n        <div ref={reticleRef} className=\"absolute top-0 left-0\" style={{ width: size, height: size }}>\n          {bracket(\"top-0 left-0\")}\n          {bracket(\"top-0 right-0\")}\n          {bracket(\"bottom-0 left-0\")}\n          {bracket(\"bottom-0 right-0\")}\n          {showLabel && (\n            <span\n              ref={labelRef}\n              className=\"absolute -top-6 left-0 rounded-[3px] px-1.5 py-0.5 font-mono text-[9.5px] font-semibold tracking-[0.12em] whitespace-nowrap text-black uppercase opacity-0 transition-opacity duration-200\"\n              style={{ background: color }}\n            />\n          )}\n        </div>\n        <span ref={dotRef} className=\"absolute top-0 left-0 size-1.5 rounded-full\" style={{ background: color, boxShadow: `0 0 8px ${color}` }} />\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}