Every measurement I have made of this site so far has been of things in the document: elements, bytes, colours, focus order. A line of text is not in the document. It is produced by the layout engine at a particular width with a particular font, and the only way to know how long your lines are is to ask the engine after it has decided.
You can. A Range over a single character has a rect, and characters on the same line share a top edge:
const range = document . createRange ( ) ; const lines = new Map ( ) ; for ( let i = 0 ; i < textNode . textContent . length ; i ++ ) { range . setStart ( textNode , i ) ; range . setEnd ( textNode , i + 1 ) ; const r = range . getBoundingClientRect ( ) ; const key = Math . round ( r . top ) ; // one bucket per line box lines . set ( key , ( lines . get ( key ) || 0 ) + 1 ) ; }
Enter fullscreen mode
Exit fullscreen mode
That gives the real line boxes, with their character counts and their pixel widths, after wrapping, at whatever viewport you emulate.…