{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"cursor-crosshair-readout","type":"registry:component","title":"Crosshair Cursor Readout","description":"A drafting-tool crosshair for any surface: hairline guides with live X/Y tags on ticked rulers, snapping to element corners, edges and centres with their dimensions drawn, click-to-pin distance measuring, keyboard nudging and a touch handle. Patrols the snap targets on its own at rest. No dependencies.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/cursor-crosshair-readout.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useRef } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\n\ntype Box = { l: number; t: number; r: number; b: number; name: string };\ntype Cfg = { snap: boolean; measure: boolean; snapRadius: number; snapSelector: string; idlePatrol: boolean };\ntype Pt = [number, number];\n\n// fx, fy (0..1 across the box), short code, spoken name\nconst SPOTS: ReadonlyArray<readonly [number, number, string, string]> = [\n  [0, 0, \"NW\", \"top left corner\"],\n  [0.5, 0, \"N\", \"top edge\"],\n  [1, 0, \"NE\", \"top right corner\"],\n  [0, 0.5, \"W\", \"left edge\"],\n  [0.5, 0.5, \"C\", \"center\"],\n  [1, 0.5, \"E\", \"right edge\"],\n  [0, 1, \"SW\", \"bottom left corner\"],\n  [0.5, 1, \"S\", \"bottom edge\"],\n  [1, 1, \"SE\", \"bottom right corner\"],\n];\n\nconst HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;\nconst INTERACTIVE = \"a,button,input,select,textarea,label,summary,[role=button],[role=link],[contenteditable]\";\nconst MONO = 'ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, Consolas, monospace';\nconst clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));\nconst pad = (n: number) => String(Math.round(n)).padStart(3, \"0\");\nconst sgn = (n: number) => (n < 0 ? \"−\" : \"+\") + Math.abs(Math.round(n));\n\nconst TAG: CSSProperties = {\n  position: \"absolute\",\n  font: \"600 9.5px/14px \" + MONO,\n  letterSpacing: \"0.04em\",\n  fontVariantNumeric: \"tabular-nums\",\n  color: \"#fff\",\n  background: \"#0a0b0e\",\n  boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.16)\",\n  borderRadius: 3,\n  padding: \"0 4px\",\n  whiteSpace: \"nowrap\",\n};\nconst DIM: CSSProperties = {\n  position: \"absolute\",\n  font: \"600 9.5px/15px \" + MONO,\n  fontVariantNumeric: \"tabular-nums\",\n  color: \"#fff\",\n  background: \"var(--ccr-a)\",\n  borderRadius: 3,\n  padding: \"0 5px\",\n  whiteSpace: \"nowrap\",\n};\nconst PILL: CSSProperties = {\n  font: \"500 10px/1 \" + MONO,\n  letterSpacing: \"0.12em\",\n  textTransform: \"uppercase\",\n  color: \"rgba(255,255,255,0.78)\",\n  background: \"rgba(8,9,11,0.82)\",\n  boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.14)\",\n  borderRadius: 999,\n  padding: \"6px 10px\",\n};\n\n/**\n * A drafting-table cursor for a bounded surface. Mark elements with data-snap\n * (or pass snapSelector) and the crosshair snaps to their corners, edges and\n * centre while their dimensions are drawn. Click (or press Enter / the Pin\n * button) to drop an origin and read the offset and distance from it. With no\n * pointer it patrols the snap targets by itself.\n */\nexport function CursorCrosshairReadout({\n  children,\n  showReadout = true,\n  showRings = true,\n  lineStyle = \"dashed\",\n  showRulers = true,\n  snap = true,\n  measure = false,\n  idlePatrol = false,\n  snapRadius = 14,\n  snapSelector = \"[data-snap]\",\n  accent = \"#3b82f6\",\n  className,\n}: {\n  children?: ReactNode;\n  showReadout?: boolean;\n  /** The centre reticle and its dot. Off leaves only the two guides. */\n  showRings?: boolean;\n  lineStyle?: \"dashed\" | \"solid\";\n  /** Ticked rulers on the top and left edges, with the live X / Y tags. */\n  showRulers?: boolean;\n  /** Snap to the corners, edge midpoints and centre of snap targets. */\n  snap?: boolean;\n  /** Click, Enter or the Pin button drops an origin and measures from it. */\n  measure?: boolean;\n  /** With no pointer, patrol the snap targets by itself. Off parks the crosshair. */\n  idlePatrol?: boolean;\n  /** Pointer distance (px) at which the crosshair snaps. */\n  snapRadius?: number;\n  /** CSS selector for snap targets, matched inside the surface. */\n  snapSelector?: string;\n  /** Hex colour for the centre dot, snap boxes and dimension tags. */\n  accent?: string;\n  className?: string;\n}) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const ovRef = useRef<HTMLDivElement>(null);\n  const cfg = useRef<Cfg>({ snap, measure, snapRadius, snapSelector, idlePatrol });\n  const redraw = useRef<() => void>(() => {});\n  const descId = \"ccr\" + useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const acc = HEX.test(accent) ? accent : \"#3b82f6\";\n  const line = lineStyle === \"solid\" ? \"solid\" : \"dashed\";\n\n  useEffect(() => {\n    cfg.current = { snap, measure, snapRadius, snapSelector, idlePatrol };\n    redraw.current();\n  }, [snap, measure, snapRadius, snapSelector, idlePatrol]);\n\n  useEffect(() => {\n    const root = rootRef.current;\n    const ov = ovRef.current;\n    if (!root || !ov) return;\n    const q = (k: string) => ov.querySelector<HTMLElement>('[data-ccr=\"' + k + '\"]');\n    const eX = q(\"x\");\n    const eY = q(\"y\");\n    const chip = q(\"chip\");\n    const rowB = q(\"rb\");\n    const rowC = q(\"rc\");\n    const xTag = q(\"xtag\");\n    const yTag = q(\"ytag\");\n    const bx = q(\"box\");\n    const bw = q(\"bw\");\n    const bh = q(\"bh\");\n    const bn = q(\"bn\");\n    const mid = q(\"mid\");\n    const size = q(\"size\");\n    const pinBtn = q(\"pin\");\n    const grip = q(\"grip\");\n    const svg = ov.querySelector<SVGSVGElement>(\"svg\");\n    const sLine = ov.querySelector<SVGLineElement>(\"line\");\n    const sMark = ov.querySelector<SVGRectElement>(\"rect\");\n    const live = root.querySelector<HTMLElement>(\"[data-ccr-live]\");\n\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let reduced = mq.matches;\n    let visible = true;\n    let docHidden = document.hidden;\n    let handle = 0;\n    let lastT = 0;\n\n    let W = 0;\n    let H = 0;\n    let boxes: Box[] = [];\n    // raw target / smoothed pointer / displayed (snapped) position\n    let tx = 0;\n    let ty = 0;\n    let px = -1;\n    let py = -1;\n    let dx = -1;\n    let dy = -1;\n    let hovering = false;\n    let focused = false;\n    let dragging = false;\n    let pressed = false;\n    let kb = false;\n    let kbIdx = -1;\n    let lastInput = -Infinity;\n    let settle = 0;\n    let wasEngaged = false;\n    let idleSince = -1;\n    let lastIdle = -1;\n    let anchor: Pt | null = null;\n    let pType = \"mouse\";\n    let grab: Pt | null = null;\n    let say = false;\n    let shown = false;\n    const HOLD = 4000;\n    const DWELL = 2100;\n\n    const engagedAt = (ts: number) =>\n      hovering || focused || dragging || ts - lastInput < (reduced ? Infinity : HOLD);\n\n    const measureBoxes = () => {\n      const rr = root.getBoundingClientRect();\n      W = root.offsetWidth;\n      H = root.offsetHeight;\n      const sx = rr.width > 0 ? W / rr.width : 1;\n      const sy = rr.height > 0 ? H / rr.height : 1;\n      boxes = [];\n      let list: NodeListOf<Element> | null = null;\n      try {\n        list = root.querySelectorAll(cfg.current.snapSelector);\n      } catch {\n        list = null;\n      }\n      if (!list) return;\n      list.forEach((el) => {\n        if (ov.contains(el)) return;\n        const r = el.getBoundingClientRect();\n        const l = (r.left - rr.left) * sx;\n        const t = (r.top - rr.top) * sy;\n        const rt = (r.right - rr.left) * sx;\n        const b = (r.bottom - rr.top) * sy;\n        if (rt - l < 4 || b - t < 4) return;\n        boxes.push({ l, t, r: rt, b, name: (el.getAttribute(\"data-snap\") || el.tagName.toLowerCase()).slice(0, 24) });\n      });\n    };\n\n    const put = (el: HTMLElement | null, s: string) => {\n      if (el && el.textContent !== s) el.textContent = s;\n    };\n\n    const draw = (): boolean => {\n      const c = cfg.current;\n      const chipW = chip ? chip.offsetWidth : 0;\n      const chipH = chip ? chip.offsetHeight : 0;\n      let x = clamp(px, 0, W);\n      let y = clamp(py, 0, H);\n      let hit: Box | null = null;\n      let spot = -1;\n      if (c.snap) {\n        const R = kb ? 3 : Math.max(0, c.snapRadius);\n        let best = R + 0.001;\n        for (const b of boxes) {\n          for (let i = 0; i < SPOTS.length; i++) {\n            const s = SPOTS[i];\n            if (!s) continue;\n            const sx = b.l + (b.r - b.l) * s[0];\n            const sy = b.t + (b.b - b.t) * s[1];\n            const d = Math.hypot(sx - x, sy - y);\n            if (d < best) {\n              best = d;\n              hit = b;\n              spot = i;\n            }\n          }\n        }\n        if (hit && spot >= 0) {\n          const s = SPOTS[spot];\n          if (s) {\n            x = hit.l + (hit.r - hit.l) * s[0];\n            y = hit.t + (hit.b - hit.t) * s[1];\n          }\n        }\n      }\n      if (!hit) {\n        let area = Infinity;\n        for (const b of boxes) {\n          const a = (b.r - b.l) * (b.b - b.t);\n          if (x >= b.l && x <= b.r && y >= b.t && y <= b.b && a < area) {\n            area = a;\n            hit = b;\n          }\n        }\n      }\n      // ease only into a snap; free tracking stays instant\n      let pending = false;\n      if (dx < 0) {\n        dx = x;\n        dy = y;\n      } else {\n        const k = spot >= 0 && !reduced ? 0.55 : 1;\n        dx += (x - dx) * k;\n        dy += (y - dy) * k;\n        if (Math.abs(x - dx) > 0.3 || Math.abs(y - dy) > 0.3) pending = true;\n        else {\n          dx = x;\n          dy = y;\n        }\n      }\n      const rx = Math.round(dx);\n      const ry = Math.round(dy);\n      ov.style.opacity = shown ? \"1\" : \"0\";\n      if (pinBtn) {\n        pinBtn.style.pointerEvents = shown ? \"\" : \"none\";\n        pinBtn.tabIndex = shown ? 0 : -1;\n      }\n      ov.style.setProperty(\"--cx\", rx + \"px\");\n      ov.style.setProperty(\"--cy\", ry + \"px\");\n      ov.style.setProperty(\"--p\", pressed ? \"1\" : \"0\");\n      ov.style.setProperty(\"--s\", spot >= 0 ? \"1\" : \"0\");\n\n      // readout chip\n      put(eX, pad(rx));\n      put(eY, pad(ry));\n      const a = c.measure ? anchor : null;\n      let rowBText = \"\";\n      if (hit) rowBText = spot >= 0 ? \"SNAP \" + (SPOTS[spot]?.[2] ?? \"\") + \" · \" + hit.name : hit.name;\n      let rowCText = \"\";\n      let dist = 0;\n      if (a) {\n        dist = Math.hypot(rx - a[0], ry - a[1]);\n        rowCText = \"Δ \" + sgn(rx - a[0]) + \" \" + sgn(ry - a[1]) + \" · L \" + dist.toFixed(1);\n      }\n      if (rowB) {\n        put(rowB, rowBText);\n        rowB.hidden = !rowBText;\n      }\n      if (rowC) {\n        put(rowC, rowCText);\n        rowC.hidden = !rowCText;\n      }\n      if (chip) {\n        const cl = rx + 16 + chipW > W - 4 ? rx - 16 - chipW : rx + 16;\n        const ct = ry + 16 + chipH > H - 4 ? ry - 16 - chipH : ry + 16;\n        chip.style.left = Math.max(2, cl) + \"px\";\n        chip.style.top = Math.max(2, ct) + \"px\";\n      }\n      // edge tags\n      if (xTag) {\n        put(xTag, pad(rx));\n        xTag.style.left = clamp(rx, 16, Math.max(16, W - 16)) + \"px\";\n      }\n      if (yTag) {\n        put(yTag, pad(ry));\n        yTag.style.top = clamp(ry, 14, Math.max(14, H - 14)) + \"px\";\n      }\n      put(size, Math.round(W) + \" × \" + Math.round(H));\n\n      // snap box and dimensions\n      if (bx) {\n        if (hit) {\n          bx.style.opacity = \"1\";\n          bx.style.left = hit.l + \"px\";\n          bx.style.top = hit.t + \"px\";\n          bx.style.width = hit.r - hit.l + \"px\";\n          bx.style.height = hit.b - hit.t + \"px\";\n          put(bw, String(Math.round(hit.r - hit.l)));\n          put(bh, String(Math.round(hit.b - hit.t)));\n          put(bn, hit.name);\n          if (bw) bw.style.top = hit.t < 26 ? \"3px\" : \"-19px\";\n          if (bh) {\n            const inside = hit.l < 42;\n            bh.style.left = inside ? \"3px\" : \"auto\";\n            bh.style.right = inside ? \"auto\" : \"calc(100% + 4px)\";\n          }\n          if (bn) {\n            const inside = hit.b > H - 28;\n            bn.style.top = inside ? \"auto\" : \"calc(100% + 4px)\";\n            bn.style.bottom = inside ? \"3px\" : \"auto\";\n          }\n        } else bx.style.opacity = \"0\";\n      }\n\n      // measuring line\n      if (svg && sLine && sMark) {\n        svg.style.display = a ? \"block\" : \"none\";\n        if (a) {\n          sLine.setAttribute(\"x1\", String(a[0]));\n          sLine.setAttribute(\"y1\", String(a[1]));\n          sLine.setAttribute(\"x2\", String(rx));\n          sLine.setAttribute(\"y2\", String(ry));\n          sMark.setAttribute(\"x\", String(a[0] - 3.5));\n          sMark.setAttribute(\"y\", String(a[1] - 3.5));\n        }\n      }\n      if (mid) {\n        mid.hidden = !a || dist < 28;\n        if (a) {\n          mid.style.left = (a[0] + rx) / 2 + \"px\";\n          mid.style.top = (a[1] + ry) / 2 + \"px\";\n          put(mid, dist.toFixed(1));\n        }\n      }\n      if (pinBtn) {\n        const t = a ? \"Clear\" : \"Pin\";\n        put(pinBtn, t);\n        pinBtn.setAttribute(\"aria-pressed\", a ? \"true\" : \"false\");\n        pinBtn.setAttribute(\"aria-label\", a ? \"Clear the measurement origin\" : \"Pin a measurement origin at the crosshair\");\n      }\n      if (say && live) {\n        say = false;\n        let s = \"X \" + rx + \", Y \" + ry;\n        if (hit) s += spot >= 0 ? \", snapped to \" + hit.name + \" \" + (SPOTS[spot]?.[3] ?? \"\") : \", over \" + hit.name;\n        if (a) s += \". Offset \" + sgn(rx - a[0]) + \", \" + sgn(ry - a[1]) + \", distance \" + dist.toFixed(1);\n        live.textContent = s;\n      }\n      return pending;\n    };\n\n    const frame = (ts: number) => {\n      handle = 0;\n      if (!visible || docHidden) return;\n      const dt = lastT ? Math.min(0.05, (ts - lastT) / 1000) : 0.016;\n      lastT = ts;\n      measureBoxes();\n      const eng = engagedAt(ts);\n      let moving = false;\n      if (!eng) {\n        if (wasEngaged || idleSince < 0) {\n          idleSince = ts;\n          lastIdle = -1;\n          wasEngaged = false;\n          anchor = null;\n          kb = false;\n        }\n        const still = reduced || !cfg.current.idlePatrol;\n        const pts: Pt[] = [];\n        // patrol the biggest targets first; slivers would drown in their own tags\n        const big = boxes.filter((b) => b.r - b.l >= 40 && b.b - b.t >= 24);\n        const tour = (big.length ? big : boxes).slice().sort((a, b) => (b.r - b.l) * (b.b - b.t) - (a.r - a.l) * (a.b - a.t));\n        for (const b of tour) {\n          pts.push([b.l, b.t], [(b.l + b.r) / 2, (b.t + b.b) / 2]);\n        }\n        if (pts.length) {\n          let k = 1 % pts.length;\n          if (!still) {\n            const i = Math.floor((ts - idleSince) / DWELL);\n            k = i % pts.length;\n            if (i !== lastIdle) {\n              lastIdle = i;\n              const prev = pts[k - 1];\n              anchor = cfg.current.measure && k % 2 === 1 && prev ? prev : null;\n            }\n          }\n          const p = pts[k];\n          if (p) {\n            tx = clamp(p[0], 0, W);\n            ty = clamp(p[1], 0, H);\n          }\n        } else if (still) {\n          tx = W * 0.62;\n          ty = H * 0.44;\n        } else {\n          tx = W * (0.5 + 0.26 * Math.sin(ts * 0.0004));\n          ty = H * (0.5 + 0.2 * Math.sin(ts * 0.00053 + 1.3));\n        }\n        if (px < 0 || still) {\n          px = tx;\n          py = ty;\n        } else {\n          const k = 1 - Math.exp(-dt * 6.5);\n          px += (tx - px) * k;\n          py += (ty - py) * k;\n        }\n      } else {\n        wasEngaged = true;\n        if (px < 0 || reduced) {\n          px = tx;\n          py = ty;\n        } else if (settle > 0) {\n          px += (tx - px) * 0.42;\n          py += (ty - py) * 0.42;\n          settle--;\n          if (Math.abs(tx - px) < 0.3 && Math.abs(ty - py) < 0.3) settle = 0;\n          moving = settle > 0;\n        } else {\n          px = tx;\n          py = ty;\n        }\n      }\n      shown = eng || cfg.current.idlePatrol;\n      const pending = draw();\n      if (visible && !docHidden && ((!reduced && (eng || cfg.current.idlePatrol)) || moving || pending)) handle = requestAnimationFrame(frame);\n    };\n    const kick = () => {\n      if (!handle && visible && !docHidden) handle = requestAnimationFrame(frame);\n    };\n    redraw.current = kick;\n\n    // wake: remember where the crosshair is so it eases to the pointer\n    const wake = (ts: number) => {\n      if (!engagedAt(ts)) {\n        settle = 7;\n        tx = px;\n        ty = py;\n      }\n    };\n    const inPin = (e: Event) => !!pinBtn && pinBtn.contains(e.target as Node);\n    const local = (e: PointerEvent): Pt => {\n      const rr = root.getBoundingClientRect();\n      const w = root.offsetWidth;\n      const h = root.offsetHeight;\n      return [\n        clamp((e.clientX - rr.left) * (rr.width > 0 ? w / rr.width : 1), 0, w),\n        clamp((e.clientY - rr.top) * (rr.height > 0 ? h / rr.height : 1), 0, h),\n      ];\n    };\n    const aim = (e: PointerEvent) => {\n      const p = local(e);\n      tx = clamp(p[0] + (grab ? grab[0] : 0), 0, root.offsetWidth);\n      ty = clamp(p[1] + (grab ? grab[1] : 0), 0, root.offsetHeight);\n      lastInput = e.timeStamp;\n      kb = false;\n      kick();\n    };\n    const toggleAnchor = () => {\n      anchor = anchor ? null : [Math.round(dx), Math.round(dy)];\n      say = true;\n      kick();\n    };\n\n    const onEnter = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\" || inPin(e)) return;\n      wake(e.timeStamp);\n      hovering = true;\n      pType = e.pointerType;\n      aim(e);\n    };\n    const onMove = (e: PointerEvent) => {\n      if (inPin(e)) return;\n      if (e.pointerType === \"touch\" && !dragging) return;\n      if (e.pointerType !== \"touch\" && !hovering) wake(e.timeStamp);\n      if (e.pointerType !== \"touch\") hovering = true;\n      pType = e.pointerType;\n      aim(e);\n    };\n    const onDown = (e: PointerEvent) => {\n      if (inPin(e) || (e.pointerType === \"mouse\" && e.button !== 0)) return;\n      wake(e.timeStamp);\n      pType = e.pointerType;\n      pressed = true;\n      if (e.pointerType === \"touch\") dragging = true;\n      else hovering = true;\n      if (grip && grip.contains(e.target as Node)) {\n        const p = local(e);\n        grab = [dx - p[0], dy - p[1]];\n        try {\n          grip.setPointerCapture(e.pointerId);\n        } catch {\n          /* capture is a nicety */\n        }\n      } else grab = null;\n      aim(e);\n    };\n    const onUp = (e: PointerEvent) => {\n      pressed = false;\n      dragging = false;\n      grab = null;\n      lastInput = e.timeStamp;\n      kick();\n    };\n    const onLeave = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\" || inPin(e)) return;\n      hovering = false;\n      pressed = false;\n      lastInput = -Infinity;\n      kick();\n    };\n    const onClick = (e: MouseEvent) => {\n      if (!cfg.current.measure || pType === \"touch\" || inPin(e)) return;\n      const t = e.target as Element | null;\n      if (t && t.closest && t.closest(INTERACTIVE)) return;\n      toggleAnchor();\n    };\n    const onPin = (e: Event) => {\n      e.stopPropagation();\n      toggleAnchor();\n    };\n    const onFocus = (e: FocusEvent) => {\n      let vis = false;\n      try {\n        vis = root.matches(\":focus-visible\");\n      } catch {\n        vis = false;\n      }\n      if (!vis) return;\n      wake(e.timeStamp);\n      focused = true;\n      kb = true;\n      if (dx >= 0) {\n        tx = dx;\n        ty = dy;\n        px = dx;\n        py = dy;\n      }\n      lastInput = e.timeStamp;\n      say = true;\n      kick();\n    };\n    const onBlur = () => {\n      focused = false;\n      kb = false;\n      kick();\n    };\n    const onKey = (e: KeyboardEvent) => {\n      if (e.target !== root || e.ctrlKey || e.metaKey || e.altKey) return;\n      const k = e.key;\n      const step = e.shiftKey ? 10 : 1;\n      const nudge = (ax: number, ay: number) => {\n        wake(e.timeStamp);\n        const bx0 = dx >= 0 ? dx : px;\n        const by0 = dy >= 0 ? dy : py;\n        tx = clamp(bx0 + ax * step, 0, root.offsetWidth);\n        ty = clamp(by0 + ay * step, 0, root.offsetHeight);\n        px = tx;\n        py = ty;\n      };\n      let handled = true;\n      if (k === \"ArrowLeft\") nudge(-1, 0);\n      else if (k === \"ArrowRight\") nudge(1, 0);\n      else if (k === \"ArrowUp\") nudge(0, -1);\n      else if (k === \"ArrowDown\") nudge(0, 1);\n      else if (k === \"Home\") {\n        wake(e.timeStamp);\n        tx = root.offsetWidth / 2;\n        ty = root.offsetHeight / 2;\n        px = tx;\n        py = ty;\n      } else if ((k === \"n\" || k === \"N\" || k === \"p\" || k === \"P\")) {\n        measureBoxes();\n        if (boxes.length) {\n          wake(e.timeStamp);\n          const dir = k === \"n\" || k === \"N\" ? 1 : -1;\n          kbIdx = (kbIdx + dir + boxes.length) % boxes.length;\n          const b = boxes[kbIdx];\n          if (b) {\n            tx = (b.l + b.r) / 2;\n            ty = (b.t + b.b) / 2;\n            px = tx;\n            py = ty;\n          }\n        } else handled = false;\n      } else if (k === \"Enter\" || k === \" \") {\n        if (cfg.current.measure) toggleAnchor();\n        else handled = false;\n      } else if (k === \"Escape\") {\n        if (anchor) anchor = null;\n        else handled = false;\n      } else handled = false;\n      if (!handled) return;\n      e.preventDefault();\n      kb = true;\n      lastInput = e.timeStamp;\n      say = true;\n      kick();\n    };\n\n    const onMq = () => {\n      reduced = mq.matches;\n      kick();\n    };\n    const onVis = () => {\n      docHidden = document.hidden;\n      if (!docHidden) kick();\n    };\n    const io = new IntersectionObserver(\n      (en) => {\n        visible = !!en[0]?.isIntersecting;\n        if (visible) kick();\n      },\n      { rootMargin: \"200px\" },\n    );\n    const ro = new ResizeObserver(() => kick());\n\n    root.addEventListener(\"pointerenter\", onEnter);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onDown);\n    root.addEventListener(\"pointerup\", onUp);\n    root.addEventListener(\"pointercancel\", onUp);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"click\", onClick);\n    root.addEventListener(\"focus\", onFocus);\n    root.addEventListener(\"blur\", onBlur);\n    root.addEventListener(\"keydown\", onKey);\n    pinBtn?.addEventListener(\"click\", onPin);\n    mq.addEventListener(\"change\", onMq);\n    document.addEventListener(\"visibilitychange\", onVis);\n    io.observe(root);\n    ro.observe(root);\n    kick();\n\n    return () => {\n      root.removeEventListener(\"pointerenter\", onEnter);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onDown);\n      root.removeEventListener(\"pointerup\", onUp);\n      root.removeEventListener(\"pointercancel\", onUp);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"click\", onClick);\n      root.removeEventListener(\"focus\", onFocus);\n      root.removeEventListener(\"blur\", onBlur);\n      root.removeEventListener(\"keydown\", onKey);\n      pinBtn?.removeEventListener(\"click\", onPin);\n      mq.removeEventListener(\"change\", onMq);\n      document.removeEventListener(\"visibilitychange\", onVis);\n      io.disconnect();\n      ro.disconnect();\n      if (handle) cancelAnimationFrame(handle);\n      handle = 0;\n      redraw.current = () => {};\n    };\n  }, []);\n\n  const guide = \"rgba(255,255,255,0.62)\";\n  const maskX = \"linear-gradient(90deg, rgba(0,0,0,0.22), #000 var(--cx), rgba(0,0,0,0.22))\";\n  const maskY = \"linear-gradient(180deg, rgba(0,0,0,0.22), #000 var(--cy), rgba(0,0,0,0.22))\";\n  const ease = \"cubic-bezier(0.2, 0.8, 0.2, 1)\";\n\n  return (\n    <div\n      ref={rootRef}\n      role=\"group\"\n      aria-label=\"Crosshair measuring surface\"\n      aria-describedby={descId}\n      tabIndex={0}\n      className={\n        \"relative min-h-[12rem] cursor-none touch-pan-y overflow-hidden focus-visible:!rounded-[inherit] focus-visible:!outline-2 focus-visible:!outline-offset-[-2px] focus-visible:!outline-[#60a5fa]\" +\n        (className ? \" \" + className : \"\")\n      }\n    >\n      {children}\n\n      <span id={descId} className=\"sr-only\">\n        Arrow keys move the crosshair by one pixel, Shift by ten. N and P jump between snap targets. Enter pins a\n        measurement origin, Escape clears it, Home centres the crosshair.\n      </span>\n      <span data-ccr-live=\"\" role=\"status\" aria-live=\"polite\" className=\"sr-only\" />\n\n      <div\n        ref={ovRef}\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 overflow-hidden motion-reduce:!transition-none\"\n        style={{ opacity: idlePatrol ? 1 : 0, transition: \"opacity .22s ease\", \"--cx\": \"62%\", \"--cy\": \"44%\", \"--p\": \"0\", \"--s\": \"0\", \"--ccr-a\": acc } as CSSProperties}\n      >\n        {/* guides: bright at the crosshair, fading toward the edges; difference blend reads on any ground */}\n        <div\n          className=\"absolute inset-x-0\"\n          style={{\n            top: \"calc(var(--cy) - 0.5px)\",\n            height: 0,\n            borderTop: \"1px \" + line + \" \" + guide,\n            mixBlendMode: \"difference\",\n            maskImage: maskX,\n            WebkitMaskImage: maskX,\n          }}\n        />\n        <div\n          className=\"absolute inset-y-0\"\n          style={{\n            left: \"calc(var(--cx) - 0.5px)\",\n            width: 0,\n            borderLeft: \"1px \" + line + \" \" + guide,\n            mixBlendMode: \"difference\",\n            maskImage: maskY,\n            WebkitMaskImage: maskY,\n          }}\n        />\n\n        {/* measuring line from the pinned origin */}\n        <svg width=\"100%\" height=\"100%\" className=\"absolute inset-0 overflow-visible\" style={{ display: \"none\" }}>\n          <line stroke={acc} strokeWidth=\"1.25\" strokeDasharray=\"4 3\" />\n          <rect width=\"7\" height=\"7\" fill=\"#0a0b0e\" stroke={acc} strokeWidth=\"1.25\" />\n        </svg>\n        <div\n          data-ccr=\"mid\"\n          hidden\n          style={{ ...TAG, transform: \"translate(-50%, -50%)\", color: acc, boxShadow: \"inset 0 0 0 1px \" + acc }}\n        />\n\n        {/* snap box with dimension tags */}\n        <div\n          data-ccr=\"box\"\n          className=\"absolute motion-reduce:!transition-none\"\n          style={{\n            opacity: 0,\n            left: 0,\n            top: 0,\n            width: 0,\n            height: 0,\n            boxShadow: \"inset 0 0 0 1px \" + acc,\n            background: \"color-mix(in srgb, \" + acc + \" 9%, transparent)\",\n            transition: \"left .12s \" + ease + \", top .12s \" + ease + \", width .12s \" + ease + \", height .12s \" + ease + \", opacity .12s\",\n          }}\n        >\n          <span data-ccr=\"bw\" style={{ ...DIM, left: \"50%\", transform: \"translateX(-50%)\" }}>\n            0\n          </span>\n          <span data-ccr=\"bh\" style={{ ...DIM, top: \"50%\", transform: \"translateY(-50%)\" }}>\n            0\n          </span>\n          <span data-ccr=\"bn\" style={{ ...DIM, left: 0, background: \"#0a0b0e\", boxShadow: \"inset 0 0 0 1px \" + acc }} />\n        </div>\n\n        {/* rulers */}\n        <div\n          className=\"absolute inset-x-0 top-0\"\n          style={{\n            display: showRulers ? \"block\" : \"none\",\n            height: 14,\n            background:\n              \"linear-gradient(90deg, rgba(255,255,255,0.6) 1px, transparent 1px) 0 100% / 50px 8px repeat-x, linear-gradient(90deg, rgba(255,255,255,0.3) 1px, transparent 1px) 0 100% / 10px 4px repeat-x, rgba(8,9,11,0.58)\",\n            boxShadow: \"inset 0 -1px 0 rgba(255,255,255,0.14)\",\n          }}\n        >\n          <span data-ccr=\"xtag\" style={{ ...TAG, top: 0, transform: \"translateX(-50%)\", left: \"var(--cx)\" }}>\n            000\n          </span>\n        </div>\n        <div\n          className=\"absolute inset-y-0 left-0\"\n          style={{\n            display: showRulers ? \"block\" : \"none\",\n            width: 14,\n            background:\n              \"linear-gradient(180deg, rgba(255,255,255,0.6) 1px, transparent 1px) 100% 0 / 8px 50px repeat-y, linear-gradient(180deg, rgba(255,255,255,0.3) 1px, transparent 1px) 100% 0 / 4px 10px repeat-y, rgba(8,9,11,0.58)\",\n            boxShadow: \"inset -1px 0 0 rgba(255,255,255,0.14)\",\n          }}\n        >\n          <span data-ccr=\"ytag\" style={{ ...TAG, left: 0, transform: \"translateY(-50%)\", top: \"var(--cy)\", padding: \"0 2px\", fontSize: 9 }}>\n            000\n          </span>\n        </div>\n\n        {/* reticle and dot */}\n        <div style={{ display: showRings ? \"block\" : \"none\" }}>\n          <div\n            className=\"absolute motion-reduce:!transition-none\"\n            style={{\n              left: \"var(--cx)\",\n              top: \"var(--cy)\",\n              width: 52,\n              height: 52,\n              mixBlendMode: \"difference\",\n              backgroundImage:\n                \"linear-gradient(#fff,#fff), linear-gradient(#fff,#fff), linear-gradient(#fff,#fff), linear-gradient(#fff,#fff)\",\n              backgroundPosition: \"50% 0, 50% 100%, 0 50%, 100% 50%\",\n              backgroundSize: \"1px 7px, 1px 7px, 7px 1px, 7px 1px\",\n              backgroundRepeat: \"no-repeat\",\n              transform: \"translate(-50%, -50%) scale(calc(1 - var(--p) * 0.2))\",\n              opacity: \"calc(1 - var(--s) * 0.85)\",\n              transition: \"transform .16s \" + ease + \", opacity .14s\",\n            }}\n          >\n            <span\n              className=\"absolute rounded-full\"\n              style={{ inset: 6, boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.8)\" }}\n            />\n          </div>\n          <div\n            className=\"absolute motion-reduce:!transition-none\"\n            style={{\n              left: \"var(--cx)\",\n              top: \"var(--cy)\",\n              width: 20,\n              height: 20,\n              boxShadow: \"inset 0 0 0 1.5px \" + acc,\n              transform: \"translate(-50%, -50%) rotate(calc(45deg - var(--s) * 45deg)) scale(calc(0.7 + var(--s) * 0.3))\",\n              opacity: \"var(--s)\",\n              transition: \"transform .18s \" + ease + \", opacity .14s\",\n            }}\n          />\n          <div\n            className=\"absolute rounded-full\"\n            style={{\n              left: \"var(--cx)\",\n              top: \"var(--cy)\",\n              width: 6,\n              height: 6,\n              transform: \"translate(-50%, -50%)\",\n              background: acc,\n              boxShadow: \"0 0 0 3px color-mix(in srgb, \" + acc + \" 28%, transparent), 0 0 14px \" + acc,\n            }}\n          />\n          {/* touch handle: drag the crosshair with a finger, offset kept so it stays visible */}\n          <div\n            data-ccr=\"grip\"\n            className=\"absolute touch-none rounded-full [@media(pointer:coarse)]:pointer-events-auto\"\n            style={{ left: \"var(--cx)\", top: \"var(--cy)\", width: 48, height: 48, transform: \"translate(-50%, -50%)\" }}\n          />\n        </div>\n\n        {/* readout chip */}\n        <div\n          data-ccr=\"chip\"\n          className=\"absolute motion-reduce:!transition-none\"\n          style={{\n            display: showReadout ? \"block\" : \"none\",\n            left: 0,\n            top: 0,\n            font: \"500 10px/1.5 \" + MONO,\n            fontVariantNumeric: \"tabular-nums\",\n            color: \"#fff\",\n            background: \"rgba(8,9,11,0.92)\",\n            boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.16), 0 8px 24px -6px rgba(0,0,0,0.5)\",\n            borderRadius: 6,\n            padding: \"5px 8px\",\n            whiteSpace: \"nowrap\",\n          }}\n        >\n          <div>\n            <span style={{ color: \"rgba(255,255,255,0.5)\" }}>X </span>\n            <span data-ccr=\"x\">000</span>\n            <span style={{ color: \"rgba(255,255,255,0.5)\" }}> {\"·\"} Y </span>\n            <span data-ccr=\"y\">000</span>\n          </div>\n          <div data-ccr=\"rb\" hidden style={{ color: \"rgba(255,255,255,0.66)\" }} />\n          <div data-ccr=\"rc\" hidden style={{ color: \"#93c5fd\" }} />\n        </div>\n\n        {/* status strip */}\n        <div\n          className=\"absolute bottom-2 left-[22px] right-2 flex items-end justify-between\"\n          style={{ display: showReadout ? \"flex\" : \"none\" }}\n        >\n          <span data-ccr=\"size\" style={{ ...PILL, letterSpacing: \"0.06em\", padding: \"5px 8px\", color: \"rgba(255,255,255,0.6)\" }}>\n            0 {\"×\"} 0\n          </span>\n          <button\n            type=\"button\"\n            data-ccr=\"pin\"\n            className=\"pointer-events-auto cursor-pointer transition-colors hover:!bg-white/15 focus-visible:!rounded-full focus-visible:!outline-2 focus-visible:!outline-offset-2 focus-visible:!outline-[#60a5fa] motion-reduce:transition-none [@media(pointer:coarse)]:!h-10 [@media(pointer:coarse)]:!px-5\"\n            style={{ ...PILL, display: measure ? \"inline-block\" : \"none\", border: 0 }}\n          >\n            Pin\n          </button>\n        </div>\n      </div>\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/cursor-crosshair-readout.tsx"}],"meta":{"tier":"free","tags":["cursor","crosshair","readout","technical","measure","snap","rulers","design-tool"],"href":"https://viberdy.dev/library/cursor-crosshair-readout","aiPrompt":"Create a single-file React + Tailwind component named CursorCrosshairReadout (a \"use client\" file, React only). It wraps children in a bounded surface and overlays a precision, drafting-software cursor.\n\nProps (all optional): children; showReadout true (the chip and bottom status strip); showRings true (centre reticle, snap square and dot; off leaves only the guides); lineStyle \"dashed\" | \"solid\" (default \"dashed\"); showRulers true; snap true; measure false (opt-in); idlePatrol false (opt-in); snapRadius 14 (px); snapSelector \"[data-snap]\"; accent \"#3b82f6\" (validated against a hex regex); className (appended to the root). Root: relative, min-h 12rem, cursor-none, overflow-hidden, touch-action pan-y, tabIndex 0, role=\"group\", aria-label, aria-describedby pointing to an sr-only instruction span, plus an sr-only role=\"status\" aria-live=\"polite\" region.\n\nOverlay (absolute inset-0, pointer-events none, aria-hidden) driven by CSS variables --cx/--cy (px), --p (pressed 0/1), --s (snapped 0/1), --ccr-a (accent), written imperatively from one rAF loop; never setState on move.\n- Guides: 1px dashed/solid rgba(255,255,255,0.62) lines, mix-blend-mode difference, mask-image gradient from alpha 0.22 at the edges to 1 at the crosshair.\n- Reticle: 52px box with four 7px ticks at N/E/S/W and a 40px ring (inset 6px, 1px white 0.8), difference blend; scales to 0.8 while pressed and fades out when snapped. Snap square: 20px, 1.5px accent inset border, rotates from 45deg to 0 and scales 0.7 to 1 when snapped (.18s cubic-bezier(.2,.8,.2,1)). Dot: 6px accent with a 3px 28% halo and a 14px glow.\n- Rulers: 14px strips on top and left, rgba(8,9,11,0.58), ticks every 10px (4px) and 50px (8px), with 14px-tall mono tags showing the live X (top) and Y (left), clamped to the edges.\n- Chip: mono 10px, near-black 0.92 with a hairline, offset 16px from the crosshair and flipped near the right/bottom edge. Row 1 \"X 312 · Y 148\" (3-digit padded, tabular nums), row 2 the snap target (\"SNAP NE · button\" or the element name), row 3 when measuring \"Δ +120 −34 · L 124.7\".\n- Snap: elements matching snapSelector are measured every frame in layout pixels ((client - rect) * offsetWidth / rect.width, so scaled previews work). Candidate points are the 9 points of each box (corners, edge mids, centre); the nearest within snapRadius wins (3px for keyboard). The displayed crosshair eases into a snap at k 0.55 per frame and leaves it instantly. The hovered/snapped element gets an inset accent outline with 9% accent fill, and accent tags: width on the top edge, height on the left edge, name at the bottom (tags flip inside the box near the surface edges); the box glides between elements (.12s).\n- Measuring: click (mouse/pen, ignoring a,button,input,select,textarea,label,summary,[role=button],[role=link],[contenteditable]), Enter/Space or the Pin button (aria-pressed, 40px tall on coarse pointers) drops an origin; an SVG dashed accent line with a square marker connects it to the crosshair and a mid-label shows the distance. Escape clears it.\n- Bottom strip: pill with the surface size \"960 × 600\" and the Pin/Clear button.\n\nInput: pointer events. Mouse: instant tracking; entering from idle eases in over 7 frames at 0.42. Touch: tap places the crosshair, drag moves it horizontally (vertical pans the page); a 48px grip over the dot (pointer-events only on coarse pointers, touch-action none, pointer capture) drags with the finger offset preserved. After touch input it holds 4s. Keyboard (only when the root itself is focused and :focus-visible): arrows 1px, Shift 10px, Home centres, N/P cycle snap targets, Enter/Space pin, Escape clear; each action updates the live region (\"X 312, Y 148, snapped to button top left corner. Offset +12, -4, distance 12.6\"). Focus ring: 2px #60a5fa inset, important utilities.\n\nIdle: with idlePatrol on and no pointer or focus the crosshair patrols (off: the whole overlay is hidden, opacity 0 with a .22s fade, until the pointer or keyboard focus engages; hidden, the Pin button is inert): waypoints are each snap box's top-left corner then centre, 2.1s dwell each, eased with k = 1 - exp(-dt*6.5); on every centre waypoint the previous corner is the measuring origin. No snap targets: a slow Lissajous (0.26W, 0.2H, 0.0004 / 0.00053 rad per ms). Leaving with a mouse returns to patrol immediately.\n\nLoop: one rAF started in a mount effect, IntersectionObserver (rootMargin 200px) and visibilitychange pause it, ResizeObserver kicks it, handle 0 when idle (StrictMode safe). prefers-reduced-motion: no patrol (parks at the first target centre, or 62%/44%), no easing, no transitions, frames only on input.","license":"https://viberdy.dev/license"}}