|
| 1 | +# PWA TTS Auto-Follow Stabilization Notes |
| 2 | + |
| 3 | +Date: 2026-04-30 |
| 4 | + |
| 5 | +## Problem |
| 6 | + |
| 7 | +PWA TTS auto-follow page turning went through several unstable states: |
| 8 | + |
| 9 | +- Fixed character buffers turned too early or too late depending on layout. |
| 10 | +- Geometry-based triggers using `Range.getClientRects()` were unreliable with epub.js column pagination. |
| 11 | +- Auto-follow and manual navigation state could overlap. |
| 12 | +- `end.cfi` sometimes mapped later than the visual page boundary. |
| 13 | +- A global learned ratio over-corrected and caused early page turns. |
| 14 | + |
| 15 | +## Final PWA Approach |
| 16 | + |
| 17 | +- TTS `absoluteOffset` is the single progress source. |
| 18 | +- Highlight display and page-turn decisions are separated. |
| 19 | +- Current page boundaries are derived from epub.js `currentLocation()` CFIs. |
| 20 | +- Page turn uses the current page's measured end boundary with a tiny fixed lead: |
| 21 | + - `pageTurnOffset = pageEndOffset - 8` |
| 22 | +- Auto page turns are routed through a sequence-tracked request path: |
| 23 | + - `requestTTSAutoNextPage(...)` |
| 24 | + - `ttsAutoFollowPendingRef` |
| 25 | + - `ttsAutoFollowSequenceRef` |
| 26 | +- Relocated unlock only applies to the matching auto-follow sequence. |
| 27 | +- Guards prevent repeated page turns: |
| 28 | + - Do not auto-turn if `absoluteOffset < pageStartOffset`. |
| 29 | + - Do not auto-turn immediately after entering a new page. |
| 30 | + - Manual page turns still apply a temporary auto-follow cooldown. |
| 31 | + |
| 32 | +## Lessons |
| 33 | + |
| 34 | +- Do not use CSS Highlight geometry as the source of truth for page turning in this epub.js setup. |
| 35 | +- Do not apply cross-page learned ratios globally; a correction learned on one page can be wrong for another. |
| 36 | +- Keep auto-follow state explicit and separate from manual navigation state. |
| 37 | +- Use geometry logs only as debugging context for highlight placement. |
| 38 | + |
| 39 | +## Renderer Follow-Up |
| 40 | + |
| 41 | +Do not port intermediate experiments. Port only the final state-machine approach after PWA local/formal/iOS testing is confirmed. |
0 commit comments