import { useState } from "react"; const COORD_RE = /\[(-?\d+),\s*(-?\d+)\]/g; export function TextWithCoords({ text, style }: { text: string; style?: React.CSSProperties }) { const parts: React.ReactNode[] = []; let last = 0; let match: RegExpExecArray | null; COORD_RE.lastIndex = 0; while ((match = COORD_RE.exec(text)) !== null) { if (match.index > last) parts.push(text.slice(last, match.index)); parts.push(); last = match.index + match[0].length; } if (last < text.length) parts.push(text.slice(last)); return {parts}; } function CoordBadge({ x, y, raw }: { x: string; y: string; raw: string }) { const [copied, setCopied] = useState(false); async function handleClick(e: React.MouseEvent) { e.stopPropagation(); await navigator.clipboard.writeText(`/travel ${x},${y}`); setCopied(true); setTimeout(() => setCopied(false), 1500); } return ( {copied ? "✓ copié" : raw} ); }