Add optional highlight function when initializing TTS (#82)

This commit is contained in:
Huang Xin
2025-06-16 17:28:18 +00:00
committed by GitHub
parent b26cde2527
commit 0d4a92ae75
+3 -3
View File
@@ -577,12 +577,12 @@ export class View extends HTMLElement {
for (const item of list) this.deleteAnnotation(item) for (const item of list) this.deleteAnnotation(item)
this.#searchResults.clear() this.#searchResults.clear()
} }
async initTTS(granularity = 'word') { async initTTS(granularity = 'word', highlight) {
const doc = this.renderer.getContents()[0].doc const doc = this.renderer.getContents()[0].doc
if (this.tts && this.tts.doc === doc) return if (this.tts && this.tts.doc === doc) return
const { TTS } = await import('./tts.js') const { TTS } = await import('./tts.js')
this.tts = new TTS(doc, textWalker, range => this.tts = new TTS(doc, textWalker, highlight || (range =>
this.renderer.scrollToAnchor(range, true), granularity) this.renderer.scrollToAnchor(range, true)), granularity)
} }
startMediaOverlay() { startMediaOverlay() {
const { index } = this.renderer.getContents()[0] const { index } = this.renderer.getContents()[0]