Allow getting page/TOC item for ranges

This commit is contained in:
John Factotum
2023-09-24 02:37:33 +08:00
parent 495aef0064
commit 0a9c418711
+7 -2
View File
@@ -241,7 +241,7 @@ export class View extends HTMLElement {
doc.addEventListener('click', e => { doc.addEventListener('click', e => {
const [value, range] = overlayer.hitTest(e) const [value, range] = overlayer.hitTest(e)
if (value && !value.startsWith(SEARCH_PREFIX)) { if (value && !value.startsWith(SEARCH_PREFIX)) {
this.#emit('show-annotation', { value, range }) this.#emit('show-annotation', { value, index, range })
} }
}, false) }, false)
@@ -258,7 +258,7 @@ export class View extends HTMLElement {
const { index, anchor } = resolved const { index, anchor } = resolved
const { doc } = this.#getOverlayer(index) const { doc } = this.#getOverlayer(index)
const range = anchor(doc) const range = anchor(doc)
this.#emit('show-annotation', { value, range }) this.#emit('show-annotation', { value, index, range })
} }
} }
getCFI(index, range) { getCFI(index, range) {
@@ -320,6 +320,11 @@ export class View extends HTMLElement {
for (const { doc } of this.renderer.getContents()) for (const { doc } of this.renderer.getContents())
doc.defaultView.getSelection().removeAllRanges() doc.defaultView.getSelection().removeAllRanges()
} }
getProgressOf(index, range) {
const tocItem = this.#tocProgress?.getProgress(index, range)
const pageItem = this.#pageProgress?.getProgress(index, range)
return { tocItem, pageItem }
}
async getTOCItemOf(target) { async getTOCItemOf(target) {
try { try {
const { index, anchor } = await this.resolveNavigation(target) const { index, anchor } = await this.resolveNavigation(target)