{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"hairline-coords","type":"registry:ui","title":"Hairline Coords","description":"Full-bleed crosshair lines with live coordinates that tear and glitch when you hover a link.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/hairline-coords.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useId, useRef, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface HairlineCoordsProps {\n  children?: ReactNode;\n  color?: string;\n  /** Line width in px. */\n  thickness?: number;\n  /** Show live x/y readouts on the lines. */\n  showCoords?: boolean;\n  /** Distort the lines briefly when the pointer enters a target. */\n  glitch?: boolean;\n  /** Elements that trigger the glitch. */\n  targetSelector?: string;\n  /** Hide the native cursor inside the container. */\n  hideCursor?: boolean;\n  className?: string;\n}\n\nconst pad = (n: number) => String(Math.round(n)).padStart(4, \"0\");\n\nexport function HairlineCoords({\n  children,\n  color = \"#ffffff\",\n  thickness = 1,\n  showCoords = true,\n  glitch = true,\n  targetSelector = \"a, button\",\n  hideCursor = true,\n  className,\n}: HairlineCoordsProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const svgRef = useRef<SVGSVGElement>(null);\n  const filterId = \"crosshair-\" + useId().replace(/[^\\w-]/g, \"\");\n\n  useEffect(() => {\n    const root = rootRef.current!;\n    const svg = svgRef.current!;\n    const q = <T extends Element>(s: string) => svg.querySelector(s) as T;\n    const hLine = q<SVGLineElement>(\"[data-h]\");\n    const vLine = q<SVGLineElement>(\"[data-v]\");\n    const ring = q<SVGCircleElement>(\"[data-ring]\");\n    const xLabel = q<SVGTextElement>(\"[data-x]\");\n    const yLabel = q<SVGTextElement>(\"[data-y]\");\n    const turb = q<SVGFETurbulenceElement>(\"feTurbulence\");\n    const disp = q<SVGFEDisplacementMapElement>(\"feDisplacementMap\");\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let x = 0;\n    let y = 0;\n    let raf = 0;\n    let glitchAt = -1;\n    let target: Element | null = null;\n\n    const render = (now: number) => {\n      raf = 0;\n      hLine.setAttribute(\"y1\", String(y));\n      hLine.setAttribute(\"y2\", String(y));\n      vLine.setAttribute(\"x1\", String(x));\n      vLine.setAttribute(\"x2\", String(x));\n      ring.setAttribute(\"cx\", String(x));\n      ring.setAttribute(\"cy\", String(y));\n      xLabel.setAttribute(\"x\", String(x + 8));\n      xLabel.textContent = `X ${pad(x)}`;\n      yLabel.setAttribute(\"y\", String(y - 8));\n      yLabel.textContent = `Y ${pad(y)}`;\n      if (glitchAt >= 0) {\n        const p = (now - glitchAt) / 520;\n        if (p >= 1) {\n          glitchAt = -1;\n          disp.setAttribute(\"scale\", \"0\");\n        } else {\n          // Random frequency + seed per frame reads as a torn, flickering signal.\n          const burst = Math.random() > 0.25 ? 1 : 0.15;\n          disp.setAttribute(\"scale\", String(36 * (1 - p) * burst));\n          turb.setAttribute(\"seed\", String((Math.random() * 1000) | 0));\n          turb.setAttribute(\"baseFrequency\", `${0.002 + Math.random() * 0.01} ${0.04 + Math.random() * 0.3}`);\n          raf = requestAnimationFrame(render);\n        }\n      }\n    };\n    const schedule = () => {\n      if (!raf) raf = requestAnimationFrame(render);\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      x = e.clientX - r.left;\n      y = e.clientY - r.top;\n      svg.style.opacity = \"1\";\n      const hit = (e.target as Element).closest?.(targetSelector);\n      const next = hit && root.contains(hit) ? hit : null;\n      if (next !== target) {\n        target = next;\n        ring.setAttribute(\"r\", target ? \"14\" : \"5\");\n        if (target && glitch && !reduced) glitchAt = performance.now();\n      }\n      schedule();\n    };\n    const onLeave = () => {\n      svg.style.opacity = \"0\";\n      target = null;\n    };\n\n    root.addEventListener(\"pointermove\", onMove, { passive: true });\n    root.addEventListener(\"pointerleave\", onLeave);\n    return () => {\n      cancelAnimationFrame(raf);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, [glitch, targetSelector]);\n\n  const text = { fill: color, fontSize: 10, fontFamily: \"ui-monospace, monospace\", letterSpacing: \"0.08em\", opacity: 0.7 };\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"relative overflow-hidden\", className)}\n      data-crosshair-hide={hideCursor ? \"\" : undefined}\n    >\n      <style href=\"crosshair\" precedence=\"default\">\n        {`[data-crosshair-hide],[data-crosshair-hide] *{cursor:none!important}`}\n      </style>\n      {children}\n      <svg\n        ref={svgRef}\n        aria-hidden\n        width=\"100%\"\n        height=\"100%\"\n        style={{ position: \"absolute\", inset: 0, pointerEvents: \"none\", opacity: 0, transition: \"opacity .25s\" }}\n      >\n        <filter id={filterId} filterUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width=\"100%\" height=\"100%\">\n          <feTurbulence type=\"fractalNoise\" baseFrequency=\"0.01 0.2\" numOctaves=\"1\" result=\"noise\" />\n          <feDisplacementMap in=\"SourceGraphic\" in2=\"noise\" scale=\"0\" xChannelSelector=\"R\" yChannelSelector=\"G\" />\n        </filter>\n        <g filter={`url(#${filterId})`} stroke={color} strokeWidth={thickness}>\n          <line data-h x1=\"0\" x2=\"100%\" opacity={0.55} />\n          <line data-v y1=\"0\" y2=\"100%\" opacity={0.55} />\n          <circle data-ring r=\"5\" fill=\"none\" style={{ transition: \"r .25s cubic-bezier(.3,1.6,.5,1)\" }} />\n        </g>\n        <g style={{ display: showCoords ? undefined : \"none\" }}>\n          <text data-x y=\"18\" style={text} />\n          <text data-y x=\"10\" style={text} />\n        </g>\n      </svg>\n    </div>\n  );\n}\n"}]}