I just wanted to chime in to say the Foliate code is really beautifully written too.
I was able to hack together an epub audiobook reader by running a custom version of foliatejs in Microsoft Edge (which has an amazing and free text to speech engine called "read aloud"). It's VERT hacky but you can try it here:
https://nathansherburn.github.io/foliate-js/
I've recently written an article about the dangers of ebooks. Maybe it's of interest to some: https://gebir.ge/blog/every-trick-in-the-book/