I want to know if two text nodes are visually sequential, regardless of the HTML structure, that is, that there is no empty line or any other element between them.
I use Ranges to get rectangles (size and position), but there is a gap between the text nodes (the bottom of the first rectangle does not match the top of the second).
I tried to calculate this distance based on line-height and font-size but could not get the same value.
Here is the JsFiddle with my attempt: https://jsfiddle.net/3behsxxq/5/
Is there any way to calculate this distance?
EDIT: In the first case of jsFiddle code, there are four lines ("first text", "block", "second", "text block") that are visually sequential, that is, visually the distance between them is the same, but the number I get has difference 7 (in this first case). If I try to drop this space based on the difference between the line height / font size and the range values, they do not match, so I cannot counteract this.
EDITING 2. Context: in the image below, 6 lines have the same distance between them. I am looking for a way to determine that they are part of the same paragraph, regardless of the html structure (because html can have a <p> element or any other element to represent the paragraph).

javascript css form-control
jcbp
source share