Repository navigation
fix(web): add reading position to TTS locators, align with native - #376
Open
ddfreiling wants to merge 8 commits into
Open
ddfreiling wants to merge 8 commits into
ddfreiling wants to merge 8 commits into
Conversation
Upstream's HTML content iterator builds element locators with only an href and a cssSelector, and web TTS sent them to Dart as they were. Apps that track the reading position from timebased states skip locators without a position, so on web they lost the position and chapter skip during read-aloud. iOS and Android emit positions. Every TTS state now carries the first position of the spoken resource, the matching totalProgression, and tocHref (which only the playing state had). WebPub has no positions list, so its reading-order index is used, as its text locators do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TTS locators carried the first position of the spoken resource, so the reported progress only moved once per resource and had no chapter title. The TTS content iterator now sets each text element's progression to its index over the resource's element count, as kotlin-toolkit's HtmlResourceContentIterator does. The position is the last one in the resource that starts at or before that progression, and the locator takes its title when it has none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
enrichWithPosition listed every Locator field to add a position and a title. Spreading the locator does the same and keeps future fields. A test now checks that the TTS text locator matches the playing state's locator, position included, as native text locators always carry one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Web TTS sent a text locator for every spoken paragraph, on top of the one the visual navigator sends when TTS moves it. With synchronization off, the text locator moved while the page stayed put. Native TTS reports progress through player states only, and the text-locator stream follows the visual reader, as the streams docs describe. Web now does the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The EPUB, DiViNa and TTS navigators each built one position per reading-order item when a publication has no positions list. They now share readingOrderPositions(), which also gives WebPub TTS states the chapter title the TTS copy left out. A test now checks that upstream's HTMLResourceContentIterator still has the private fields ProgressionHTMLResourceContentIterator reads, so an upstream rename fails CI instead of silently dropping progression. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
totalProgression was (position - 1 + progression) / total, adding the resource progression to the current position. In a resource spanning several positions it ran up to almost one position ahead, then jumped at each boundary, so it could fall outside the reported position. EPUB text locators and TTS states both used it. enrichWithTotalProgression now takes the positions list and computes (firstPosition - 1 + progression * positionsInResource) / total, which matches kotlin-toolkit's interpolation over the resource's range. It falls back to the old formula when the locator has no progression or its resource is missing from the list. WebPub and DiViNa have one position per resource, so their values do not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Backward traversal past a resource’s first element emits negative progression and assigns the wrong position to its last paragraph, requiring a boundary guard and a real-iterator regression test.
1 open issue
What changed in this PR
This PR aligns web text-to-speech (TTS) progress reporting with the plugin’s native implementations, adding reading-position metadata while keeping text-locator events tied to the visual reader.
Changes:
- Enriches TTS player-state locators with position, progression, title, and chapter metadata.
- Removes TTS-generated text-locator events and corrects total progression across multi-position resources.
- Shares reading-order fallback logic and adds regression tests and migration notes.
| File | Description |
|---|---|
flutter_readium/web/src/ReadiumReader.ts |
Passes publication positions to TTS. |
flutter_readium/web/src/navigators/locatorEnrich.ts |
Adds position enrichment and resource-span interpolation. |
flutter_readium/web/src/navigators/FlutterWebPubNavigator.ts |
Uses shared reading-order positions for progress. |
flutter_readium/web/src/navigators/FlutterTTSNavigator.ts |
Enriches player states and removes TTS text-locator events. |
flutter_readium/web/src/navigators/FlutterEpubNavigator.ts |
Adopts corrected progression and shared fallback logic. |
flutter_readium/web/src/navigators/FlutterDivinaNavigator.ts |
Reuses shared position and progression helpers. |
flutter_readium/web/src/__tests__/locatorEnrich.test.ts |
Tests position selection and multi-position interpolation. |
flutter_readium/web/src/__tests__/FlutterTTSNavigator.test.ts |
Tests TTS metadata, event separation, and iterator progression. |
flutter_readium/changelog.d/+web-tts-no-text-locator.changed.md |
Documents the TTS event migration. |
flutter_readium/changelog.d/+web-tts-locator-position.fixed.md |
Documents enriched TTS reading positions. |
flutter_readium/changelog.d/+web-total-progression-span.fixed.md |
Documents corrected progress within long chapters. |
Review effort: Balanced
Upstream's HTMLResourceContentIterator.hasPrevious() reads elements.at(index), which wraps index -1 to the last element. Going back from a resource's first paragraph therefore returned the same resource's last paragraph instead of moving to the previous resource, and with the progression subclass it carried a negative progression. ProgressionHTMLResourceContentIterator now returns false at the first element, so the publication iterator moves to the previous resource. Tests drive the subclass over a real parsed resource, which also covers the upstream private fields it reads; they replace the mock-based tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Web TTS states and EPUB text locators took their title from the positions list, whose entries have none in practice, so apps got no chapter title. iOS and Android set it from the ToC entry, as does swift-toolkit's EPUB navigator. enrichWithTocHref becomes enrichWithToc, built on a shared withTocLink(locator, link) that sets both tocHref and the entry's title, keeping the locator's own title when the entry has none. The positions title stays a fallback for TTS. The audiobook ToC lookup in Notalib#368 can reuse withTocLink. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Dec 1, 2026
ddfreiling
added a commit
that referenced
this pull request
Dec 5, 2026
A ToC entry's title is optional in RWPM. The plugin assigned it to the locator unconditionally, so an untitled entry replaced the title that the toolkit had already set with nil/null. Keep the existing title in that case. tocHref handling is unchanged. Native counterpart of #368 and #376. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
During web read-aloud,
onTimebasedPlayerStateChangedlocators had noposition,progression,totalProgressionortitle, and only the playing state hadtocHref. Apps could not track or restore the TTS position, show progress, or skip chapters reliably. Upstream's TSHTMLResourceContentIteratoremits locators with none of these, unlike the Kotlin and Swift iterators.Web TTS also sent
onTextLocatorChangedfor every paragraph, which native TTS never does. With sync off, the text locator moved while the page stayed put.Change
ProgressionHTMLResourceContentIteratorsubclass sets each element'sprogressionto its index over the resource's element count, as kotlin-toolkit does. Every TTS state (playing, paused, ended, failure, word boundary) then getspositionfrom the positions list, plustocHref,titleandtotalProgression.onTextLocatorChangedfollows the visual reader, asdocs/api-reference/streams-events.mdalready says.totalProgression: now(firstPositionOfResource - 1 + progression * positionsInResource) / total, matching kotlin-toolkit's interpolation. The old formula added resource progression to the current position, so inside chapters spanning several positions it ran up to almost one position ahead. This also applies to EPUB text locators. WebPub and DiViNa have one position per resource, so their values do not change.withTocLink(locator, link)setstocHrefand the ToC entry'stitle, as iOS, Android and swift-toolkit's EPUB navigator do. TTS states and EPUB text locators use it; before, their title came from the positions list, which has none in practice.hasPrevious()wraps index -1 to the resource's last element, so TTS jumped to the same chapter's last paragraph (also onmain). The subclass now stops at the first element, so TTS moves to the previous chapter.readingOrderPositions()fallback replaces three copies (EPUB, DiViNa, TTS).Review notes
currentIndex,currentElement,parsedElementRecipesandelements(). jsdom tests drive it over a real parsed resource, so a rename in an@readium/sharedupgrade fails CI.enrichWithTocHrefis renamedenrichWithToc. fix(web): complete audiobook locator fields after go() #368 rewrites the same function for audiobooks; whichever merges second should build onwithTocLink.totalProgressionfor positions partway into long chapters, and bookmarks saved with the old formula can sort just after newer ones in the same chapter.onTextLocatorChangedmust switch toonTimebasedPlayerStateChanged.currentLocator, as documented indocs/guides/saving-progress.md.Verification
bin/typecheck, jest (575 tests) andbin/changelog checkpass after rebasing ontomain.totalProgressionstayed inside each position and only grew.Not covered
tocHrefand title are coarser.