Re #1256 - changed logic to detect the topmost/bottom-most visible nodes so it no longer depends on document.elementFromPoint (which only works for on-screen elements)