@@ -17,14 +17,6 @@ const ReactReader = dynamic(() => import('react-reader').then(mod => mod.ReactRe
1717 loading : ( ) => < DocumentSkeleton />
1818} ) ;
1919
20- const colors = {
21- background : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--background' ) ,
22- foreground : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--foreground' ) ,
23- base : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--base' ) ,
24- offbase : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--offbase' ) ,
25- muted : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--muted' ) ,
26- } ;
27-
2820const getThemeStyles = ( ) : IReactReaderStyle => {
2921 const baseStyle = {
3022 ...ReactReaderStyle ,
@@ -34,6 +26,14 @@ const getThemeStyles = (): IReactReaderStyle => {
3426 }
3527 } ;
3628
29+ const colors = {
30+ background : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--background' ) ,
31+ foreground : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--foreground' ) ,
32+ base : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--base' ) ,
33+ offbase : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--offbase' ) ,
34+ muted : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--muted' ) ,
35+ } ;
36+
3737 return {
3838 ...baseStyle ,
3939 arrow : {
@@ -124,15 +124,16 @@ export function EPUBViewer({ className = '' }: EPUBViewerProps) {
124124 setLastDocumentLocation ( id as string , location . toString ( ) ) ;
125125 }
126126 }
127-
128- locationRef . current = location ;
129127
130128 setEPUBPageInChapter ( displayed . page , displayed . total , chapter ?. label || '' ) ;
131129
132130 // Add a small delay for initial load to ensure rendition is ready
133131 if ( initial ) {
134- setInitialPrevLocLoad ( true ) ;
132+ rendition . current . display ( location . toString ( ) ) . then ( ( ) => {
133+ setInitialPrevLocLoad ( true ) ;
134+ } ) ;
135135 } else {
136+ locationRef . current = location ;
136137 extractPageText ( bookRef . current , rendition . current ) ;
137138 }
138139 }
@@ -147,6 +148,11 @@ export function EPUBViewer({ className = '' }: EPUBViewerProps) {
147148
148149 const updateTheme = useCallback ( ( rendition : Rendition ) => {
149150 if ( ! epubTheme ) return ; // Only apply theme if enabled
151+
152+ const colors = {
153+ foreground : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--foreground' ) ,
154+ base : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--base' ) ,
155+ } ;
150156
151157 rendition . themes . override ( 'color' , colors . foreground ) ;
152158 rendition . themes . override ( 'background' , colors . base ) ;
0 commit comments