This is exactly the use case I ran into most often, and I have designed a small library precisely to do these computations without touching the DOM. If you want to have a look, it is on <a href="https:&#x2F;&#x2F;www.github.com&#x2F;andreaferretti&#x2F;paths-js" rel="nofollow">https:&#x2F;&#x2F;www.github.com&#x2F;andreaferretti&#x2F;paths-js</a>