I don't understand why you can't just use closestPrev in the first place. It seems to me that you're iterating all the way to closestPrev in any case, but are just doing it in two steps.  Or are some of the parent elements being omitted somehow?

Maybe it is different in the offscreen case where an onscreen element may have offscreen children, but can't you do something simpler in this case?

This is what I said I was confused above in my comment on your long code comment.  Maybe you need to explain with a concrete example showing an element hierarchy that needs this treatment.

If it would simplify things or speed them up, I'd be fine with simplifying this so it only called the onscreen and offscreen callbacks for elements at the specified depth and never invoked them for their parents.  (I'm assuming that the client code that wants this library uses a consistent depth.)

I haven't looked at the other cases below, but I assume they're pretty much parallel to this one and I won't understand them either :-)  I can do another review pass once you've explained the need for the cousin stuff.