How can I get the page number for a specific TOC item
For example my TOC (nav file) contains href's to s1.xhtml, s2.xhtml etc. How can I get the page number of each href?
I don't think this is possible. Page size is relative. A page on an iPhone is smaller than a page on a 27" desktop monitor, so you can't properly tell how many pages a book or a section is without rendering the entire book first.
You can use percentageFromCfi to roughly know what percentage a CFI (or section) is through a book:
https://github.com/futurepress/epub.js/blob/master/documentation/md/API.md#percentagefromcfi
When epub.js starts it calculates 'locations' I am using this as pages (since there is no exact page as each screen is different) I would like to know the location number from the TOC href.
Get a CFI for your href first,
const id = href.split('#')[1]
const section = book.spine.get(href)
await section.load(book.load.bind(book))
const el = id ? section.document.getElementById(id) : section.document.body
const cfi = section.cfiFromElement(el)
section.unload()
Then use percentageFromCfi.