A function which can return closest element based on a cursor x, y value from the domNodes

I am using react-dnd package in Next.js for my dnd project. In the canDrop function I want a javascript function which can return me some value based on some parameter. Here is the problem:

Inputs: function will have 3 parameters. dragX, dragY and childrenArray. dragX and dragY are the co-ordinates of x and y position of the mouse when an element is being dragged and childrenArray I am making it from domNodes, which can be very deeply nested.

Outputs : I want 3 outputs.

  1. If cursor is on a childNode return that node or if not return null.
  2. closestNode according to the cursor position from left or right or bottom or top
  3. closestCorner of the colosestNode ( corners are left, right , bottom and top )