import React from 'react'; /** * Manifold XYPad — square control surface. Drag the glowing cyan dot; emits * normalized (x, y) in [0,1] with y-up. Uncontrolled by default; pass * `position` + `onMove` to control it. */ export function XYPad({ size = 240, showGrid = true, position, onMove, onGrab, onRelease, disabled = false, ariaLabel = 'XY pad', style }) { const [internal, setInternal] = React.useState([0.5, 0.5]); const [dragging, setDragging] = React.useState(false); const ref = React.useRef(null); const pos = position || internal; const update = (e) => { const el = ref.current; if (!el) return; const r = el.getBoundingClientRect(); const x = Math.max(0, Math.min(1, (e.clientX - r.left) / r.width)); const y = Math.max(0, Math.min(1, 1 - (e.clientY - r.top) / r.height)); if (!position) setInternal([x, y]); onMove && onMove(x, y); }; const down = (e) => { if (disabled) return; e.currentTarget.setPointerCapture?.(e.pointerId); setDragging(true); onGrab && onGrab(); update(e); }; const move = (e) => { if (dragging) update(e); }; const up = (e) => { if (!dragging) return; e.currentTarget.releasePointerCapture?.(e.pointerId); setDragging(false); onRelease && onRelease(); }; const [x, y] = pos; return (
{showGrid && (