Add option to show start of main body text as defined in landmarks

This commit is contained in:
John Factotum
2023-05-16 16:21:56 +08:00
parent 3c4d309b52
commit edea003b2f
+10 -6
View File
@@ -78,12 +78,16 @@ export class View extends HTMLElement {
this.renderer.open(book)
this.#root.append(this.renderer)
}
async init({ lastLocation }) {
if (lastLocation) {
const resolved = this.resolveNavigation(lastLocation)
if (resolved) await this.renderer.goTo(resolved)
else await this.renderer.next()
} else await this.renderer.next()
goToTextStart() {
return this.goTo(this.book.landmarks
?.find(m => m.type.includes('bodymatter') || m.type.includes('text'))
?.href ?? this.book.sections.findIndex(s => s.linear !== 'no'))
}
async init({ lastLocation, showTextStart }) {
const resolved = lastLocation ? this.resolveNavigation(lastLocation) : null
if (resolved) await this.renderer.goTo(resolved)
else if (showTextStart) await this.goToTextStart()
else await this.renderer.next()
}
#emit(name, detail, cancelable) {
return this.dispatchEvent(new CustomEvent(name, { detail, cancelable }))