react-native-simple-epub-reader 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/components/Reader.js +52 -10
- package/lib/module/components/Reader.js.map +1 -1
- package/lib/module/constants/template.js +214 -255
- package/lib/module/constants/template.js.map +1 -1
- package/lib/module/context/ReaderContext.js +29 -26
- package/lib/module/context/ReaderContext.js.map +1 -1
- package/lib/module/helpers/downloadEpub.js +8 -1
- package/lib/module/helpers/downloadEpub.js.map +1 -1
- package/lib/typescript/src/components/Reader.d.ts.map +1 -1
- package/lib/typescript/src/constants/template.d.ts +1 -1
- package/lib/typescript/src/constants/template.d.ts.map +1 -1
- package/lib/typescript/src/context/ReaderContext.d.ts.map +1 -1
- package/lib/typescript/src/helpers/downloadEpub.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Reader.tsx +60 -13
- package/src/constants/template.ts +214 -255
- package/src/context/ReaderContext.tsx +29 -27
- package/src/helpers/downloadEpub.ts +9 -1
|
@@ -10,7 +10,7 @@ import type { ReaderContextProps } from './types';
|
|
|
10
10
|
import { defaultTheme } from '../constants/theme';
|
|
11
11
|
import type WebView from 'react-native-webview';
|
|
12
12
|
import * as webViewInjectFunctions from '../helpers/webViewInjectFunctions';
|
|
13
|
-
import type { ePubCfi,
|
|
13
|
+
import type { ePubCfi, Location, Theme } from '../types';
|
|
14
14
|
import { useReaderState } from '../hooks/useReaderState';
|
|
15
15
|
import { Actions } from '../types/state.types';
|
|
16
16
|
|
|
@@ -123,8 +123,11 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
|
|
|
123
123
|
const getMeta = useCallback(() => state.meta, [state.meta]);
|
|
124
124
|
const changeFontFamily = useCallback((fontFamily: string) => {
|
|
125
125
|
book.current?.injectJavaScript(`
|
|
126
|
-
rendition
|
|
127
|
-
|
|
126
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
127
|
+
rendition.themes.font('${fontFamily}');
|
|
128
|
+
rendition.views().forEach(view => view.pane ? view.pane.render() : null);
|
|
129
|
+
}
|
|
130
|
+
true;
|
|
128
131
|
`);
|
|
129
132
|
dispatch({ type: Actions.CHANGE_FONT_FAMILY, payload: fontFamily });
|
|
130
133
|
}, []);
|
|
@@ -133,23 +136,14 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
|
|
|
133
136
|
book.current?.injectJavaScript(script);
|
|
134
137
|
}, []);
|
|
135
138
|
|
|
136
|
-
const changeFlow = useCallback((flow: Flow) => {
|
|
137
|
-
webViewInjectFunctions.injectJavaScript(
|
|
138
|
-
book,
|
|
139
|
-
`rendition.flow(${JSON.stringify(flow)}); true`
|
|
140
|
-
);
|
|
141
|
-
dispatch({ type: Actions.SET_FLOW, payload: flow });
|
|
142
|
-
}, []);
|
|
143
|
-
|
|
144
|
-
const setFlow = useCallback((flow: Flow) => {
|
|
145
|
-
dispatch({ type: Actions.SET_FLOW, payload: flow });
|
|
146
|
-
}, []);
|
|
147
|
-
|
|
148
139
|
const changeTheme = useCallback((theme: Theme) => {
|
|
149
140
|
book.current?.injectJavaScript(`
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
141
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
142
|
+
rendition.themes.register({ theme: ${JSON.stringify(theme)} });
|
|
143
|
+
rendition.themes.select('theme');
|
|
144
|
+
rendition.views().forEach(view => view.pane ? view.pane.render() : null);
|
|
145
|
+
}
|
|
146
|
+
true;
|
|
153
147
|
`);
|
|
154
148
|
dispatch({ type: Actions.CHANGE_THEME, payload: theme });
|
|
155
149
|
}, []);
|
|
@@ -158,7 +152,9 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
|
|
|
158
152
|
webViewInjectFunctions.injectJavaScript(
|
|
159
153
|
book,
|
|
160
154
|
`
|
|
161
|
-
rendition
|
|
155
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
156
|
+
rendition.next();
|
|
157
|
+
}
|
|
162
158
|
`
|
|
163
159
|
);
|
|
164
160
|
}, []);
|
|
@@ -167,19 +163,29 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
|
|
|
167
163
|
webViewInjectFunctions.injectJavaScript(
|
|
168
164
|
book,
|
|
169
165
|
`
|
|
170
|
-
rendition
|
|
166
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
167
|
+
rendition.prev();
|
|
168
|
+
}
|
|
171
169
|
`
|
|
172
170
|
);
|
|
173
171
|
}, []);
|
|
174
172
|
|
|
175
173
|
const goToLocation = useCallback((targetCfi: ePubCfi) => {
|
|
176
|
-
book.current?.injectJavaScript(`
|
|
174
|
+
book.current?.injectJavaScript(`
|
|
175
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
176
|
+
rendition.display('${targetCfi}');
|
|
177
|
+
}
|
|
178
|
+
true;
|
|
179
|
+
`);
|
|
177
180
|
}, []);
|
|
178
181
|
|
|
179
182
|
const changeFontSize = useCallback((size: string) => {
|
|
180
183
|
book.current?.injectJavaScript(`
|
|
181
|
-
rendition
|
|
182
|
-
|
|
184
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
185
|
+
rendition.themes.fontSize('${size}');
|
|
186
|
+
rendition.views().forEach(view => view.pane ? view.pane.render() : null);
|
|
187
|
+
}
|
|
188
|
+
true;
|
|
183
189
|
`);
|
|
184
190
|
dispatch({ type: Actions.CHANGE_FONT_SIZE, payload: size });
|
|
185
191
|
}, []);
|
|
@@ -203,8 +209,6 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
|
|
|
203
209
|
setLocations,
|
|
204
210
|
changeFontFamily,
|
|
205
211
|
injectJavascript,
|
|
206
|
-
changeFlow,
|
|
207
|
-
setFlow,
|
|
208
212
|
changeFontSize,
|
|
209
213
|
theme: state.theme,
|
|
210
214
|
flow: state.flow,
|
|
@@ -237,8 +241,6 @@ function ReaderProvider({ children }: { children: React.ReactNode }) {
|
|
|
237
241
|
setLocations,
|
|
238
242
|
changeFontFamily,
|
|
239
243
|
injectJavascript,
|
|
240
|
-
changeFlow,
|
|
241
|
-
setFlow,
|
|
242
244
|
changeFontSize,
|
|
243
245
|
state.theme,
|
|
244
246
|
state.flow,
|
|
@@ -11,7 +11,15 @@ export const downloadEpub = async (
|
|
|
11
11
|
return file.uri;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const normalized = url.split('?X-Goog-Algorithm')[0];
|
|
15
|
+
|
|
16
|
+
if (!normalized) {
|
|
17
|
+
throw new Error('Invalid URL provided for EPUB download.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
console.log({ url });
|
|
21
|
+
|
|
22
|
+
const downloadedFile = await File.downloadFileAsync(normalized, file);
|
|
15
23
|
|
|
16
24
|
return downloadedFile.uri;
|
|
17
25
|
} catch (error) {
|