{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cursor-crosshair",
  "type": "registry:component",
  "title": "Cursor Crosshair",
  "description": "Full-width dashed guide lines follow the pointer with X and Y readout chips and a dot that snaps to a grid, like a design tool ruler.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "cursor",
    "crosshair",
    "guides",
    "coordinates",
    "grid",
    "technical"
  ],
  "docs": "https://hyperblur.dev/effects/cursor-crosshair",
  "files": [
    {
      "path": "registry/hyperblur/cursor-crosshair.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cursor-crosshair.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CursorCrosshairProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  snap?: number;\n  showGrid?: boolean;\n  showReadout?: boolean;\n  idle?: boolean;\n}\n\nconst css = `\n.hb-qi9 { position: relative; width: 100%; height: 100%; overflow: hidden; box-sizing: border-box; isolation: isolate; font-family: inherit; --hb-qi9-color: #2f7bff; --hb-qi9-snap: 20px; }\n.hb-qi9 *, .hb-qi9 *::before, .hb-qi9 *::after { box-sizing: border-box; }\n.hb-qi9-grid { position: absolute; inset: 0; z-index: 0; pointer-events: none; background-image: linear-gradient(to right, rgba(255, 255, 255, 0.045) 1px, transparent 1px), linear-gradient(to bottom, rgba(255, 255, 255, 0.045) 1px, transparent 1px); background-size: var(--hb-qi9-snap) var(--hb-qi9-snap); }\n.hb-qi9-content { position: relative; z-index: 1; width: 100%; height: 100%; }\n.hb-qi9-layer { position: absolute; inset: 0; z-index: 2; pointer-events: none; opacity: 0; transition: opacity 0.3s ease; }\n.hb-qi9-layer[data-on=\"true\"] { opacity: 1; }\n.hb-qi9-h { position: absolute; left: 0; right: 0; top: 0; height: 1px; background-image: repeating-linear-gradient(to right, var(--hb-qi9-color) 0 4px, transparent 4px 8px); opacity: 0.7; will-change: transform; }\n.hb-qi9-v { position: absolute; top: 0; bottom: 0; left: 0; width: 1px; background-image: repeating-linear-gradient(to bottom, var(--hb-qi9-color) 0 4px, transparent 4px 8px); opacity: 0.7; will-change: transform; }\n.hb-qi9-dot { position: absolute; left: 0; top: 0; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; background: #0a0a0a; border: 2px solid var(--hb-qi9-color); box-shadow: 0 0 0 4px color-mix(in srgb, var(--hb-qi9-color) 22%, transparent); transition: transform 0.14s cubic-bezier(.2,.8,.2,1); }\n.hb-qi9-chip { position: absolute; left: 0; top: 0; white-space: nowrap; font: 500 10px/1 var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; color: #ededed; padding: 4px 6px; border-radius: 4px; background: color-mix(in srgb, var(--hb-qi9-color) 88%, #000); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45); }\n.hb-qi9-chip-x { top: 6px; }\n.hb-qi9-chip-y { left: 6px; }\n.hb-qi9-chip-xy { background: rgba(10, 10, 10, 0.86); border: 1px solid rgba(255, 255, 255, 0.12); color: #a1a1a1; transition: transform 0.14s cubic-bezier(.2,.8,.2,1); }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qi9-dot, .hb-qi9-chip-xy, .hb-qi9-layer { transition: none; }\n}\n`;\n\nconst pad3 = (n: number) => String(Math.max(0, Math.round(n))).padStart(3, \"0\");\n\nexport function CursorCrosshair({\n  color = \"#2f7bff\",\n  snap = 20,\n  showGrid = true,\n  showReadout = true,\n  idle = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: CursorCrosshairProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const layerRef = React.useRef<HTMLDivElement>(null);\n  const hRef = React.useRef<HTMLSpanElement>(null);\n  const vRef = React.useRef<HTMLSpanElement>(null);\n  const dotRef = React.useRef<HTMLSpanElement>(null);\n  const xRef = React.useRef<HTMLSpanElement>(null);\n  const yRef = React.useRef<HTMLSpanElement>(null);\n  const xyRef = React.useRef<HTMLSpanElement>(null);\n  const grid = Math.max(1, snap);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const layer = layerRef.current;\n    const hl = hRef.current;\n    const vl = vRef.current;\n    const dot = dotRef.current;\n    if (!root || !layer || !hl || !vl || !dot) 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 active = false;\n    let mix = 0;\n    let raf = 0;\n    let last = 0;\n    let t = 0;\n    let visible = true;\n    let lastText = \"\";\n    let lastSnap = \"\";\n\n    const render = () => {\n      const sxv = Math.min(w, Math.max(0, Math.round(cx / grid) * grid));\n      const syv = Math.min(h, Math.max(0, Math.round(cy / grid) * grid));\n      hl.style.transform = `translate3d(0, ${cy.toFixed(1)}px, 0)`;\n      vl.style.transform = `translate3d(${cx.toFixed(1)}px, 0, 0)`;\n      const key = `${sxv},${syv}`;\n      if (key !== lastSnap) {\n        lastSnap = key;\n        dot.style.transform = `translate3d(${sxv}px, ${syv}px, 0)`;\n        const xy = xyRef.current;\n        if (xy) {\n          const right = sxv + 92 > w;\n          const below = syv - 26 < 0;\n          xy.style.transform = `translate3d(${(right ? sxv - 10 : sxv + 10).toFixed(0)}px, ${(below ? syv + 10 : syv - 26).toFixed(0)}px, 0) translateX(${right ? \"-100%\" : \"0\"})`;\n          xy.textContent = `${pad3(sxv)}, ${pad3(syv)}`;\n        }\n      }\n      const xc = xRef.current;\n      const yc = yRef.current;\n      if (xc) xc.style.transform = `translate3d(${Math.min(w - 30, Math.max(30, cx)).toFixed(1)}px, 0, 0) translateX(-50%)`;\n      if (yc) yc.style.transform = `translate3d(0, ${Math.min(h - 16, Math.max(36, cy)).toFixed(1)}px, 0) translateY(-50%)`;\n      const text = `${Math.round(cx)}|${Math.round(cy)}`;\n      if (text !== lastText) {\n        lastText = text;\n        if (xc) xc.textContent = `X ${pad3(cx)}`;\n        if (yc) yc.textContent = `Y ${pad3(cy)}`;\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 * 4));\n      const ix = idle ? w * (0.5 + 0.3 * Math.sin(t * 0.38) + 0.06 * Math.sin(t * 1.21)) : px;\n      const iy = idle ? h * (0.5 + 0.26 * Math.sin(t * 0.59 + 0.9)) : py;\n      const tx = ix + (px - ix) * mix;\n      const ty = iy + (py - iy) * mix;\n      const k = 1 - Math.exp(-dt * 16);\n      cx += (tx - cx) * k;\n      cy += (ty - cy) * k;\n      layer.dataset.on = idle || active ? \"true\" : \"false\";\n      render();\n      raf = requestAnimationFrame(frame);\n    };\n\n    const start = () => {\n      if (raf || reduced || !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 r = root.getBoundingClientRect();\n      w = root.clientWidth;\n      h = root.clientHeight;\n      const s = r.width ? w / r.width : 1;\n      px = (e.clientX - r.left) * s;\n      py = (e.clientY - r.top) * s;\n      active = true;\n      if (reduced) {\n        cx = px;\n        cy = py;\n        layer.dataset.on = \"true\";\n        render();\n      }\n    };\n    const onLeave = () => {\n      active = false;\n      if (reduced && !idle) layer.dataset.on = \"false\";\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\") onLeave();\n    };\n\n    if (reduced) {\n      cx = w * 0.62;\n      cy = h * 0.4;\n      layer.dataset.on = idle ? \"true\" : \"false\";\n      render();\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    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    };\n  }, [grid, idle, showReadout]);\n\n  const vars = {\n    \"--hb-qi9-color\": color,\n    \"--hb-qi9-snap\": `${grid}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div ref={rootRef} className={`hb-qi9 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-cursor-crosshair\" precedence=\"default\">{css}</style>\n      {showGrid ? <div className=\"hb-qi9-grid\" aria-hidden=\"true\" /> : null}\n      <div className=\"hb-qi9-content\">{children}</div>\n      <div ref={layerRef} className=\"hb-qi9-layer\" aria-hidden=\"true\">\n        <span ref={hRef} className=\"hb-qi9-h\" />\n        <span ref={vRef} className=\"hb-qi9-v\" />\n        <span ref={dotRef} className=\"hb-qi9-dot\" />\n        {showReadout ? (\n          <>\n            <span ref={xRef} className=\"hb-qi9-chip hb-qi9-chip-x\" />\n            <span ref={yRef} className=\"hb-qi9-chip hb-qi9-chip-y\" />\n            <span ref={xyRef} className=\"hb-qi9-chip hb-qi9-chip-xy\" />\n          </>\n        ) : null}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}