type MouseDragDocumentLike = {
  addEventListener: (type: "mousemove" | "mouseup", listener: (event: MouseEvent) => void) => void;
  removeEventListener: (type: "mousemove" | "mouseup", listener: (event: MouseEvent) => void) => void;
};

export function attachDocumentMouseDrag(
  doc: MouseDragDocumentLike,
  onMove: (event: MouseEvent) => void,
  onUp: (event: MouseEvent) => void,
): () => void {
  function cleanup() {
    doc.removeEventListener("mousemove", onMove);
    doc.removeEventListener("mouseup", onUp);
  }

  doc.addEventListener("mousemove", onMove);
  doc.addEventListener("mouseup", onUp);
  return cleanup;
}
