@@ -113,7 +113,7 @@ const TTS_HIGHLIGHT_LENGTH = 4
113113const TTS_GEOMETRY_LINE_BUFFER = 0.9
114114const TTS_NEW_PAGE_AUTO_FOLLOW_GUARD = 36
115115const TTS_PAGE_END_FIXED_LEAD = 8
116- const DEBUG_TTS_FOLLOW = true
116+ const DEBUG_TTS_FOLLOW = false
117117
118118type TextIndex = { nodes : Text [ ] ; starts : number [ ] ; total : number ; text : string }
119119type TTSRangeViewportState = {
@@ -2014,7 +2014,9 @@ const Reader = ({ bookPath, bookId, bookRecord, getCoverDataUrl, onBack, darkMod
20142014 return
20152015 }
20162016
2017- const geometry = getTTSRangeViewportState ( doc , range )
2017+ const geometry = ( DEBUG_TTS_FOLLOW || pageEndOffset === null )
2018+ ? getTTSRangeViewportState ( doc , range )
2019+ : null
20182020 const pageSpan = pageStartOffset !== null && pageEndOffset !== null
20192021 ? Math . max ( 1 , pageEndOffset - pageStartOffset )
20202022 : null
@@ -2031,7 +2033,7 @@ const Reader = ({ bookPath, bookId, bookRecord, getCoverDataUrl, onBack, darkMod
20312033 const progressShouldAdvance =
20322034 ! beforeCurrentPageGuard &&
20332035 ! insideNewPageGuard &&
2034- ! geometry . hasUsableRect && pageEndOffset === null && (
2036+ ! ( geometry ? .hasUsableRect ?? true ) && pageEndOffset === null && (
20352037 ( source === 'boundary' && continuousPage >= currentPage + 1.05 ) ||
20362038 ( continuousPage >= currentPage + 1.12 )
20372039 )
@@ -2064,21 +2066,21 @@ const Reader = ({ bookPath, bookId, bookRecord, getCoverDataUrl, onBack, darkMod
20642066 continuousPage : Number ( continuousPage . toFixed ( 2 ) ) ,
20652067 currentPage,
20662068 totalPages,
2067- rect : geometry . rect ? {
2069+ rect : geometry ? .rect ? {
20682070 left : Math . round ( geometry . rect . left ) ,
20692071 right : Math . round ( geometry . rect . right ) ,
20702072 top : Math . round ( geometry . rect . top ) ,
20712073 bottom : Math . round ( geometry . rect . bottom ) ,
20722074 width : Math . round ( geometry . rect . width ) ,
20732075 height : Math . round ( geometry . rect . height ) ,
20742076 } : null ,
2075- viewport : geometry . viewport ,
2076- lineHeight : Math . round ( geometry . lineHeight ) ,
2077- bottomGap : geometry . bottomGap === null ? null : Math . round ( geometry . bottomGap ) ,
2078- leftGap : geometry . leftGap === null ? null : Math . round ( geometry . leftGap ) ,
2079- rightGap : geometry . rightGap === null ? null : Math . round ( geometry . rightGap ) ,
2080- hasUsableRect : geometry . hasUsableRect ,
2081- geometryReason : geometry . reason ,
2077+ viewport : geometry ? .viewport ?? null ,
2078+ lineHeight : geometry ? Math . round ( geometry . lineHeight ) : null ,
2079+ bottomGap : geometry ? .bottomGap === null || geometry ?. bottomGap === undefined ? null : Math . round ( geometry . bottomGap ) ,
2080+ leftGap : geometry ? .leftGap === null || geometry ?. leftGap === undefined ? null : Math . round ( geometry . leftGap ) ,
2081+ rightGap : geometry ? .rightGap === null || geometry ?. rightGap === undefined ? null : Math . round ( geometry . rightGap ) ,
2082+ hasUsableRect : geometry ? .hasUsableRect ?? null ,
2083+ geometryReason : geometry ? .reason ?? null ,
20822084 pageBoundaryShouldAdvance,
20832085 pageEntryGuard,
20842086 beforeCurrentPageGuard,
@@ -2102,13 +2104,13 @@ const Reader = ({ bookPath, bookId, bookRecord, getCoverDataUrl, onBack, darkMod
21022104 pageEndLead : TTS_PAGE_END_FIXED_LEAD ,
21032105 distanceToPageEnd,
21042106 trigger : pageBoundaryShouldAdvance ? 'page-end-cfi' : 'progress-fallback' ,
2105- geometryReason : geometry . reason ,
2107+ geometryReason : geometry ? .reason ?? null ,
21062108 pageEntryGuard,
21072109 beforeCurrentPageGuard,
2108- bottomGap : geometry . bottomGap === null ? null : Math . round ( geometry . bottomGap ) ,
2109- leftGap : geometry . leftGap === null ? null : Math . round ( geometry . leftGap ) ,
2110- rightGap : geometry . rightGap === null ? null : Math . round ( geometry . rightGap ) ,
2111- lineHeight : Math . round ( geometry . lineHeight ) ,
2110+ bottomGap : geometry ? .bottomGap === null || geometry ?. bottomGap === undefined ? null : Math . round ( geometry . bottomGap ) ,
2111+ leftGap : geometry ? .leftGap === null || geometry ?. leftGap === undefined ? null : Math . round ( geometry . leftGap ) ,
2112+ rightGap : geometry ? .rightGap === null || geometry ?. rightGap === undefined ? null : Math . round ( geometry . rightGap ) ,
2113+ lineHeight : geometry ? Math . round ( geometry . lineHeight ) : null ,
21122114 } )
21132115 requestTTSAutoNextPage ( displayed , absoluteOffset , pageStartOffset , pageEndOffset )
21142116 }
0 commit comments