{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "crosshair",
  "type": "registry:component",
  "title": "Crosshair",
  "description": "A precision crosshair: edge-to-edge lines with a center gap, rulers with tick marks along the edges and live monospace coordinates.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Cursors"
  ],
  "docs": "Installed in components/furin/crosshair/. Docs, live controls and props table: https://furin.dev/components/crosshair/",
  "files": [
    {
      "path": "registry/crosshair/Crosshair.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport \"./Crosshair.css\";\n\nexport interface CrosshairProps {\n  /** Color de las líneas y la mira. */\n  color?: string;\n  /** Hueco central alrededor del cursor, en px. */\n  gap?: number;\n  /** Muestra las coordenadas en vivo junto al cursor. */\n  showCoords?: boolean;\n  /** Muestra las reglas con marcas en los bordes. */\n  ruler?: boolean;\n  /** Coordenadas en porcentaje del contenedor en vez de píxeles. */\n  percent?: boolean;\n  /** Oculta el cursor del sistema dentro del contenedor. */\n  hideCursor?: boolean;\n  /** Se pasea solo cuando nadie mueve el cursor. */\n  autoplay?: boolean;\n  /** Texto de pista que se muestra cuando no hay children. */\n  hint?: string;\n  /** Contenido que queda debajo de la mira. */\n  children?: ReactNode;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nconst pad = (n: number, d = 4) => String(Math.max(0, Math.round(n))).padStart(d, \"0\");\n\n/** Mira de precisión: líneas de borde a borde con hueco central, reglas con marcas y coordenadas en vivo en mono. */\nexport function Crosshair({\n  color = \"#7DD3FC\",\n  gap = 18,\n  showCoords = true,\n  ruler = true,\n  percent = false,\n  hideCursor = true,\n  autoplay = false,\n  hint = \"Aim with your cursor\",\n  children,\n  className = \"\",\n  style,\n}: CrosshairProps) {\n  const host = useRef<HTMLDivElement>(null);\n  const capa = useRef<HTMLDivElement>(null);\n  const etiqueta = useRef<HTMLDivElement>(null);\n  const ex = useRef<HTMLSpanElement>(null);\n  const ey = useRef<HTMLSpanElement>(null);\n  const [activo, setActivo] = useState(true);\n  const live = useRef({ percent, autoplay });\n  live.current = { percent, autoplay };\n\n  useEffect(() => {\n    const el = host.current;\n    const cap = capa.current;\n    if (!el || !cap) return;\n    // En reduced motion la mira no se muestra: el cursor del sistema se queda como está.\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) { setActivo(false); return; }\n    let W = 1, H = 1, raf = 0, visible = true, inside = false, lastReal = -1e9, shown = false;\n    let px = 0, py = 0, pending = false;\n\n    const render = () => {\n      pending = false;\n      cap.style.setProperty(\"--furin-crosshair-x\", `${px.toFixed(1)}px`);\n      cap.style.setProperty(\"--furin-crosshair-y\", `${py.toFixed(1)}px`);\n      const eti = etiqueta.current;\n      if (ex.current && ey.current) {\n        if (live.current.percent) {\n          ex.current.textContent = `${((px / W) * 100).toFixed(1).padStart(5, \"0\")}%`;\n          ey.current.textContent = `${((py / H) * 100).toFixed(1).padStart(5, \"0\")}%`;\n        } else {\n          ex.current.textContent = pad(px);\n          ey.current.textContent = pad(py);\n        }\n      }\n      if (eti) {\n        // La etiqueta cambia de lado cerca de los bordes para no salirse.\n        const w = eti.offsetWidth || 120, h = eti.offsetHeight || 32;\n        const flipX = px + 22 + w > W - 6, flipY = py + 22 + h > H - 6;\n        eti.style.transform = `translate(${(flipX ? px - 22 - w : px + 22).toFixed(1)}px, ${(flipY ? py - 22 - h : py + 22).toFixed(1)}px)`;\n      }\n    };\n    const schedule = () => { if (!pending) { pending = true; requestAnimationFrame(render); } };\n    const show = (v: boolean) => { if (v !== shown) { shown = v; cap.classList.toggle(\"is-on\", v); } };\n\n    const setPos = (x: number, y: number) => { px = Math.min(Math.max(x, 0), W); py = Math.min(Math.max(y, 0), H); schedule(); };\n    const measure = () => { const b = el.getBoundingClientRect(); W = Math.max(1, b.width); H = Math.max(1, b.height); };\n\n    const onMove = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\") return;\n      const b = el.getBoundingClientRect();\n      W = b.width; H = b.height;\n      inside = true;\n      lastReal = performance.now();\n      setPos(e.clientX - b.left, e.clientY - b.top);\n      show(true);\n    };\n    const onLeave = () => { inside = false; if (!live.current.autoplay) show(false); };\n    const onDown = () => cap.classList.add(\"is-press\");\n    const onUp = () => cap.classList.remove(\"is-press\");\n    el.addEventListener(\"pointermove\", onMove);\n    el.addEventListener(\"pointerleave\", onLeave);\n    el.addEventListener(\"pointerdown\", onDown);\n    el.addEventListener(\"pointerup\", onUp);\n\n    // Paseo automático para la demo: una trayectoria en ocho, sin tocar el estado real.\n    const loop = (nowMs: number) => {\n      raf = 0;\n      if (!visible) return;\n      const auto = live.current.autoplay && (!inside || nowMs - lastReal > 2500);\n      if (auto) {\n        const t = nowMs / 1000;\n        setPos(W * (0.5 + 0.3 * Math.sin(t * 0.8)), H * (0.5 + 0.28 * Math.sin(t * 1.3 + 0.7)));\n        show(true);\n        raf = requestAnimationFrame(loop);\n      } else {\n        // Al volver el control a la persona, se apaga o se queda donde estaba.\n        if (live.current.autoplay) raf = requestAnimationFrame(loop);\n      }\n    };\n    const kick = () => { if (!raf && visible && live.current.autoplay) raf = requestAnimationFrame(loop); };\n    const io = new IntersectionObserver(([en]) => { visible = en.isIntersecting; if (visible) kick(); else if (raf) { cancelAnimationFrame(raf); raf = 0; } });\n    io.observe(el);\n    const ro = new ResizeObserver(measure);\n    ro.observe(el);\n    measure();\n    const poll = window.setInterval(kick, 600);\n    kick();\n    return () => {\n      cancelAnimationFrame(raf);\n      window.clearInterval(poll);\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerleave\", onLeave);\n      el.removeEventListener(\"pointerdown\", onDown);\n      el.removeEventListener(\"pointerup\", onUp);\n      io.disconnect();\n      ro.disconnect();\n    };\n  }, []);\n\n  const vars = { \"--furin-crosshair-color\": color, \"--furin-crosshair-gap\": `${gap}px` } as CSSProperties;\n  return (\n    <div ref={host} className={`furin-crosshair${hideCursor && activo ? \" furin-crosshair--sin-cursor\" : \"\"} ${className}`} style={{ ...vars, ...style }}>\n      <div className=\"furin-crosshair__contenido\">\n        {children ?? <span className=\"furin-crosshair__pista\">{hint}</span>}\n      </div>\n      {activo ? (\n        <div ref={capa} className=\"furin-crosshair__capa\" aria-hidden=\"true\">\n          {ruler ? (\n            <>\n              <i className=\"furin-crosshair__regla furin-crosshair__regla--x\" />\n              <i className=\"furin-crosshair__regla furin-crosshair__regla--y\" />\n              <i className=\"furin-crosshair__marca furin-crosshair__marca--x\" />\n              <i className=\"furin-crosshair__marca furin-crosshair__marca--y\" />\n            </>\n          ) : null}\n          <i className=\"furin-crosshair__linea furin-crosshair__linea--h\" />\n          <i className=\"furin-crosshair__linea furin-crosshair__linea--v\" />\n          <span className=\"furin-crosshair__mira\">\n            <svg viewBox=\"-16 -16 32 32\" width=\"32\" height=\"32\">\n              <path d=\"M-9 -4V-9H-4M4 -9H9V-4M9 4V9H4M-4 9H-9V4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeLinecap=\"square\" />\n              <circle r=\"1.6\" fill=\"currentColor\" />\n            </svg>\n          </span>\n          {showCoords ? (\n            <div ref={etiqueta} className=\"furin-crosshair__etq\">\n              <span><b>X</b><span ref={ex}>0000</span></span>\n              <span><b>Y</b><span ref={ey}>0000</span></span>\n            </div>\n          ) : (\n            <div ref={etiqueta} hidden />\n          )}\n        </div>\n      ) : null}\n    </div>\n  );\n}\n\nexport default Crosshair;\n",
      "type": "registry:component",
      "target": "components/furin/crosshair/Crosshair.tsx"
    },
    {
      "path": "registry/crosshair/Crosshair.css",
      "content": ".furin-crosshair {\n  --furin-crosshair-color: #7dd3fc;\n  --furin-crosshair-gap: 18px;\n  position: relative;\n  width: 100%;\n  height: 100%;\n  min-height: 200px;\n  overflow: hidden;\n  touch-action: pan-y;\n  font-family: Geist, system-ui, -apple-system, sans-serif;\n  color: rgba(255, 255, 255, 0.5);\n  user-select: none;\n}\n@media (hover: hover) and (pointer: fine) {\n  .furin-crosshair--sin-cursor, .furin-crosshair--sin-cursor * { cursor: none; }\n}\n.furin-crosshair__contenido { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }\n.furin-crosshair__pista {\n  font: 500 12px/1 \"JetBrains Mono\", ui-monospace, \"SF Mono\", Menlo, monospace;\n  letter-spacing: 0.14em;\n  text-transform: uppercase;\n  color: rgba(255, 255, 255, 0.34);\n}\n\n.furin-crosshair__capa {\n  --furin-crosshair-x: 50%;\n  --furin-crosshair-y: 50%;\n  position: absolute;\n  inset: 0;\n  z-index: 2;\n  pointer-events: none;\n  opacity: 0;\n  color: var(--furin-crosshair-color);\n  transition: opacity 0.22s ease;\n}\n.furin-crosshair__capa.is-on { opacity: 1; }\n\n/* Líneas de borde a borde: se desvanecen hacia los extremos y se abren alrededor del cursor. */\n.furin-crosshair__linea { position: absolute; display: block; }\n.furin-crosshair__linea--h {\n  left: 0; right: 0; top: 0; height: 1px;\n  transform: translateY(var(--furin-crosshair-y));\n  background: linear-gradient(90deg, transparent, currentColor 14%, currentColor 86%, transparent);\n  opacity: 0.55;\n  -webkit-mask-image: linear-gradient(90deg, #000 calc(var(--furin-crosshair-x) - var(--furin-crosshair-gap)), transparent calc(var(--furin-crosshair-x) - var(--furin-crosshair-gap)), transparent calc(var(--furin-crosshair-x) + var(--furin-crosshair-gap)), #000 calc(var(--furin-crosshair-x) + var(--furin-crosshair-gap)));\n  mask-image: linear-gradient(90deg, #000 calc(var(--furin-crosshair-x) - var(--furin-crosshair-gap)), transparent calc(var(--furin-crosshair-x) - var(--furin-crosshair-gap)), transparent calc(var(--furin-crosshair-x) + var(--furin-crosshair-gap)), #000 calc(var(--furin-crosshair-x) + var(--furin-crosshair-gap)));\n}\n.furin-crosshair__linea--v {\n  top: 0; bottom: 0; left: 0; width: 1px;\n  transform: translateX(var(--furin-crosshair-x));\n  background: linear-gradient(180deg, transparent, currentColor 14%, currentColor 86%, transparent);\n  opacity: 0.55;\n  -webkit-mask-image: linear-gradient(180deg, #000 calc(var(--furin-crosshair-y) - var(--furin-crosshair-gap)), transparent calc(var(--furin-crosshair-y) - var(--furin-crosshair-gap)), transparent calc(var(--furin-crosshair-y) + var(--furin-crosshair-gap)), #000 calc(var(--furin-crosshair-y) + var(--furin-crosshair-gap)));\n  mask-image: linear-gradient(180deg, #000 calc(var(--furin-crosshair-y) - var(--furin-crosshair-gap)), transparent calc(var(--furin-crosshair-y) - var(--furin-crosshair-gap)), transparent calc(var(--furin-crosshair-y) + var(--furin-crosshair-gap)), #000 calc(var(--furin-crosshair-y) + var(--furin-crosshair-gap)));\n}\n\n/* Mira central: cuatro esquinas y un punto; se cierra un poco al pulsar. */\n.furin-crosshair__mira {\n  position: absolute;\n  left: 0; top: 0;\n  width: 32px; height: 32px;\n  margin: -16px 0 0 -16px;\n  transform: translate(var(--furin-crosshair-x), var(--furin-crosshair-y));\n  display: block;\n}\n.furin-crosshair__mira svg { display: block; transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1); filter: drop-shadow(0 0 6px color-mix(in srgb, currentColor 60%, transparent)); }\n.furin-crosshair__capa.is-press .furin-crosshair__mira svg { transform: scale(0.62); }\n\n/* Reglas con marcas cada 8 px y una más larga cada 40 px. */\n.furin-crosshair__regla { position: absolute; display: block; opacity: 0.4; }\n.furin-crosshair__regla--x {\n  left: 0; right: 0; top: 0; height: 9px;\n  background:\n    repeating-linear-gradient(90deg, currentColor 0 1px, transparent 1px 40px) 0 0 / 100% 9px no-repeat,\n    repeating-linear-gradient(90deg, currentColor 0 1px, transparent 1px 8px) 0 0 / 100% 4px no-repeat;\n}\n.furin-crosshair__regla--y {\n  top: 0; bottom: 0; left: 0; width: 9px;\n  background:\n    repeating-linear-gradient(180deg, currentColor 0 1px, transparent 1px 40px) 0 0 / 9px 100% no-repeat,\n    repeating-linear-gradient(180deg, currentColor 0 1px, transparent 1px 8px) 0 0 / 4px 100% no-repeat;\n}\n.furin-crosshair__marca { position: absolute; display: block; background: currentColor; box-shadow: 0 0 8px currentColor; }\n.furin-crosshair__marca--x { top: 0; left: 0; width: 1px; height: 14px; transform: translateX(var(--furin-crosshair-x)); }\n.furin-crosshair__marca--y { top: 0; left: 0; height: 1px; width: 14px; transform: translateY(var(--furin-crosshair-y)); }\n\n/* Etiqueta de coordenadas: vidrio oscuro, mono, cifras tabulares. */\n.furin-crosshair__etq {\n  position: absolute;\n  left: 0; top: 0;\n  display: flex;\n  gap: 12px;\n  padding: 6px 10px;\n  border-radius: 8px;\n  border: 1px solid color-mix(in srgb, var(--furin-crosshair-color) 38%, transparent);\n  background: rgba(8, 11, 16, 0.72);\n  -webkit-backdrop-filter: blur(8px);\n  backdrop-filter: blur(8px);\n  box-shadow: 0 8px 20px -8px rgba(0, 0, 0, 0.7);\n  font: 500 11.5px/1 \"JetBrains Mono\", ui-monospace, \"SF Mono\", Menlo, monospace;\n  font-variant-numeric: tabular-nums;\n  letter-spacing: 0.02em;\n  color: #e9f6ff;\n  white-space: nowrap;\n}\n.furin-crosshair__etq > span { display: inline-flex; gap: 6px; }\n.furin-crosshair__etq b { font-weight: 500; color: var(--furin-crosshair-color); opacity: 0.85; }\n",
      "type": "registry:file",
      "target": "components/furin/crosshair/Crosshair.css"
    }
  ]
}
