aksos-react-native-epub-reader 0.1.0 → 0.2.1
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/CHANGELOG.md +60 -0
- package/README.md +178 -20
- package/lib/EpubReader.d.ts +66 -15
- package/lib/EpubReader.js +168 -30
- package/lib/EpubReaderView.d.ts +37 -5
- package/lib/EpubReaderView.js +194 -93
- package/lib/cfiOrder.d.ts +2 -0
- package/lib/cfiOrder.js +34 -0
- package/lib/engine/html.js +1 -1
- package/lib/index.d.ts +5 -2
- package/lib/index.js +5 -1
- package/lib/strings.d.ts +94 -0
- package/lib/strings.js +96 -0
- package/lib/themes.d.ts +28 -6
- package/lib/themes.js +80 -20
- package/lib/types.d.ts +82 -1
- package/lib/ui/AppearanceSheet.d.ts +4 -2
- package/lib/ui/AppearanceSheet.js +40 -26
- package/lib/ui/ContentsSheet.d.ts +2 -0
- package/lib/ui/ContentsSheet.js +32 -22
- package/lib/ui/CustomizeSheet.d.ts +4 -2
- package/lib/ui/CustomizeSheet.js +31 -27
- package/lib/ui/HighlightMenu.d.ts +4 -2
- package/lib/ui/HighlightMenu.js +13 -11
- package/lib/ui/NoteEditor.js +12 -9
- package/lib/ui/SearchSheet.js +19 -6
- package/lib/ui/Sheet.js +7 -4
- package/lib/ui/Text.d.ts +9 -0
- package/lib/ui/Text.js +62 -0
- package/package.json +81 -76
- package/src/EpubReader.tsx +239 -43
- package/src/EpubReaderView.tsx +287 -99
- package/src/cfiOrder.ts +28 -0
- package/src/engine/epubcfi.js +527 -0
- package/src/engine/html.ts +1 -1
- package/src/engine/reader.js +1273 -157
- package/src/index.ts +5 -2
- package/src/strings.ts +187 -0
- package/src/themes.ts +97 -21
- package/src/types.ts +88 -2
- package/src/ui/AppearanceSheet.tsx +47 -29
- package/src/ui/ContentsSheet.tsx +34 -22
- package/src/ui/CustomizeSheet.tsx +27 -21
- package/src/ui/HighlightMenu.tsx +17 -13
- package/src/ui/NoteEditor.tsx +12 -9
- package/src/ui/SearchSheet.tsx +22 -5
- package/src/ui/Sheet.tsx +8 -5
- package/src/ui/Text.tsx +27 -0
package/lib/EpubReader.js
CHANGED
|
@@ -34,17 +34,60 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.EpubReader = void 0;
|
|
37
|
+
exports.sourceKeyOf = sourceKeyOf;
|
|
37
38
|
const react_1 = __importStar(require("react"));
|
|
38
39
|
const react_native_1 = require("react-native");
|
|
39
40
|
const react_native_webview_1 = require("react-native-webview");
|
|
40
41
|
const html_1 = require("./engine/html");
|
|
41
42
|
const themes_1 = require("./themes");
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
const DEFAULT_MAX_FILE = 150 * 1024 * 1024;
|
|
44
|
+
const ENGINE_START_TIMEOUT = 20000;
|
|
45
|
+
const CHUNK = 256 * 1024;
|
|
46
|
+
function stripDataPrefix(b64) {
|
|
47
|
+
return b64.startsWith('data:') ? b64.slice(b64.indexOf(',') + 1) : b64;
|
|
48
|
+
}
|
|
49
|
+
// Font data as plain base64, or '' when it is not base64. Only these characters may go into the injected script.
|
|
50
|
+
function cleanFontBase64(b64) {
|
|
51
|
+
const data = stripDataPrefix(b64 || '').replace(/\s+/g, '').replace(/-/g, '+').replace(/_/g, '/');
|
|
52
|
+
return /^[A-Za-z0-9+/]+=*$/.test(data) ? data : '';
|
|
53
|
+
}
|
|
54
|
+
// identity of a font list: changes when a font is added, removed or replaced
|
|
55
|
+
function fontsKeyOf(fonts) {
|
|
56
|
+
return (fonts || []).map((f) => [f.id, f.family, f.weight, f.style, f.mime, sourceKeyOf({ base64: f.base64 })].join('|')).join(';');
|
|
57
|
+
}
|
|
58
|
+
/** Identity of a source: the explicit `key`, the uri, or a fingerprint sampled across the base64 data. */
|
|
59
|
+
function sourceKeyOf(source) {
|
|
60
|
+
if (source.key)
|
|
61
|
+
return source.key;
|
|
62
|
+
if ('uri' in source)
|
|
63
|
+
return source.uri;
|
|
64
|
+
const b = source.base64;
|
|
65
|
+
let h = 5381;
|
|
66
|
+
const step = Math.max(1, Math.floor(b.length / 512));
|
|
67
|
+
for (let i = 0; i < b.length; i += step)
|
|
68
|
+
h = ((h << 5) + h + b.charCodeAt(i)) | 0;
|
|
69
|
+
return `b64:${b.length}:${h >>> 0}`;
|
|
70
|
+
}
|
|
71
|
+
async function uriToBase64(source, maxBytes) {
|
|
72
|
+
let res;
|
|
73
|
+
try {
|
|
74
|
+
res = await fetch(source.uri, source.headers ? { headers: source.headers } : undefined);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw new Error('The book file could not be opened (it may have been moved or deleted, or there is no connection).');
|
|
78
|
+
}
|
|
79
|
+
// file:// responses report status 0 on some platforms, so only real HTTP errors count
|
|
80
|
+
if (res.status >= 400)
|
|
81
|
+
throw new Error(`The book could not be downloaded (error ${res.status}).`);
|
|
44
82
|
const blob = await res.blob();
|
|
83
|
+
if (maxBytes > 0 && blob.size > maxBytes) {
|
|
84
|
+
throw new Error(`This book is too large to open (${Math.round(blob.size / 1048576)} MB).`);
|
|
85
|
+
}
|
|
86
|
+
if (blob.size === 0)
|
|
87
|
+
throw new Error('The book file is empty.');
|
|
45
88
|
return new Promise((resolve, reject) => {
|
|
46
89
|
const fr = new FileReader();
|
|
47
|
-
fr.onerror = () => reject(
|
|
90
|
+
fr.onerror = () => reject(new Error('The book file could not be read.'));
|
|
48
91
|
fr.onloadend = () => {
|
|
49
92
|
const s = String(fr.result);
|
|
50
93
|
resolve(s.slice(s.indexOf(',') + 1));
|
|
@@ -52,6 +95,14 @@ async function uriToBase64(uri) {
|
|
|
52
95
|
fr.readAsDataURL(blob);
|
|
53
96
|
});
|
|
54
97
|
}
|
|
98
|
+
function cleanBase64(data) {
|
|
99
|
+
let s = data;
|
|
100
|
+
if (s.startsWith('data:'))
|
|
101
|
+
s = s.slice(s.indexOf(',') + 1);
|
|
102
|
+
if (/\s/.test(s.slice(0, 4096)) || s.indexOf('\n') >= 0)
|
|
103
|
+
s = s.replace(/\s+/g, '');
|
|
104
|
+
return s;
|
|
105
|
+
}
|
|
55
106
|
const LS = String.fromCharCode(0x2028);
|
|
56
107
|
const PS = String.fromCharCode(0x2029);
|
|
57
108
|
// U+2028/2029 are legal in JSON but terminate a JS string literal, so escape them.
|
|
@@ -60,43 +111,108 @@ function toScript(cmd) {
|
|
|
60
111
|
return `window.__cmd(${json});true;`;
|
|
61
112
|
}
|
|
62
113
|
exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
63
|
-
const { source, settings, systemDark = false, safeInsets = { top: 0, bottom: 0 }, highlights,
|
|
114
|
+
const { source, settings, systemDark = false, safeInsets = { top: 0, bottom: 0 }, highlights, fonts } = props;
|
|
64
115
|
const web = (0, react_1.useRef)(null);
|
|
65
116
|
const cb = (0, react_1.useRef)(props);
|
|
66
117
|
cb.current = props;
|
|
67
118
|
const [engineReady, setEngineReady] = (0, react_1.useState)(false);
|
|
119
|
+
// bumping this remounts the WebView (after the system killed its process)
|
|
120
|
+
const [webKey, setWebKey] = (0, react_1.useState)(0);
|
|
68
121
|
const opened = (0, react_1.useRef)(false);
|
|
69
|
-
const selection = (0, react_1.useRef)(null);
|
|
70
122
|
const metaRef = (0, react_1.useRef)({ title: '', author: '', language: '', publisher: '' });
|
|
71
|
-
const
|
|
123
|
+
const lastLoc = (0, react_1.useRef)(null);
|
|
124
|
+
const lastKey = (0, react_1.useRef)('');
|
|
125
|
+
const fontGen = (0, react_1.useRef)(0);
|
|
126
|
+
const fontsKey = fontsKeyOf(fonts);
|
|
127
|
+
const hlColorsJson = JSON.stringify(props.highlightColors || null);
|
|
128
|
+
const themesJson = JSON.stringify(props.themes || null);
|
|
129
|
+
const engineSettings = (0, react_1.useMemo)(() => ({
|
|
130
|
+
...(0, themes_1.toEngineSettings)(settings, systemDark, safeInsets, fonts, props.themes, props.runningLabels !== false),
|
|
131
|
+
highlightColors: props.highlightColors || {},
|
|
132
|
+
highlightOpacity: props.highlightOpacity ?? 0.3,
|
|
133
|
+
bookColors: props.bookColors || 'theme',
|
|
134
|
+
maxZoom: props.maxZoom ?? 3
|
|
135
|
+
}),
|
|
72
136
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
-
[settings, systemDark, safeInsets.top, safeInsets.bottom]);
|
|
137
|
+
[settings, systemDark, safeInsets.top, safeInsets.bottom, safeInsets.left, safeInsets.right, fontsKey, hlColorsJson, themesJson, props.highlightOpacity, props.bookColors, props.maxZoom, props.runningLabels]);
|
|
138
|
+
// only what the engine actually uses decides about re-layout (the brightness slider, the page sound ... must not)
|
|
139
|
+
const engineJson = JSON.stringify(engineSettings);
|
|
140
|
+
const latest = (0, react_1.useRef)({ engineSettings, highlights });
|
|
141
|
+
latest.current = { engineSettings, highlights };
|
|
74
142
|
const send = (0, react_1.useCallback)((cmd) => {
|
|
75
143
|
web.current?.injectJavaScript(toScript(cmd));
|
|
76
144
|
}, []);
|
|
145
|
+
// iOS pauses the WebView in the background, so the start timer only counts while the app is in front
|
|
146
|
+
const [inFront, setInFront] = (0, react_1.useState)(react_native_1.AppState.currentState !== 'background');
|
|
147
|
+
(0, react_1.useEffect)(() => {
|
|
148
|
+
const sub = react_native_1.AppState.addEventListener('change', (state) => setInFront(state !== 'background'));
|
|
149
|
+
return () => sub.remove();
|
|
150
|
+
}, []);
|
|
151
|
+
// the engine never started (blocked WebView, out of memory ...)
|
|
152
|
+
(0, react_1.useEffect)(() => {
|
|
153
|
+
if (engineReady || !inFront)
|
|
154
|
+
return;
|
|
155
|
+
const t = setTimeout(() => cb.current.onError?.('The reader could not be started.', { fatal: true }), ENGINE_START_TIMEOUT);
|
|
156
|
+
return () => clearTimeout(t);
|
|
157
|
+
}, [engineReady, webKey, inFront]);
|
|
158
|
+
// Fonts go before the book (so the first page already uses them), in pieces like the book. Only when they change.
|
|
159
|
+
(0, react_1.useEffect)(() => {
|
|
160
|
+
if (!engineReady)
|
|
161
|
+
return;
|
|
162
|
+
// new keys for every update, so a later update cannot overwrite the data of one still waiting in the queue
|
|
163
|
+
const gen = ++fontGen.current;
|
|
164
|
+
const list = [];
|
|
165
|
+
(cb.current.fonts || []).forEach((f, i) => {
|
|
166
|
+
const data = cleanFontBase64(f.base64);
|
|
167
|
+
if (!data) {
|
|
168
|
+
cb.current.onError?.(`The font "${f.family}" was skipped: its data is not valid base64.`, { fatal: false });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const key = `f${gen}_${i}`;
|
|
172
|
+
for (let k = 0; k < data.length; k += CHUNK) {
|
|
173
|
+
web.current?.injectJavaScript(`window.__blob("${key}",${k === 0 ? 1 : 0},"${data.slice(k, k + CHUNK)}");true;`);
|
|
174
|
+
}
|
|
175
|
+
list.push({ key, family: f.family, mime: f.mime, weight: f.weight, style: f.style });
|
|
176
|
+
});
|
|
177
|
+
send({ cmd: 'fonts', list });
|
|
178
|
+
}, [engineReady, fontsKey, send]);
|
|
77
179
|
// open (or re-open) the book once the engine is up
|
|
78
|
-
const sourceKey =
|
|
180
|
+
const sourceKey = sourceKeyOf(source);
|
|
79
181
|
(0, react_1.useEffect)(() => {
|
|
80
182
|
if (!engineReady)
|
|
81
183
|
return;
|
|
82
184
|
let cancelled = false;
|
|
83
185
|
opened.current = false;
|
|
186
|
+
if (lastKey.current !== sourceKey) {
|
|
187
|
+
lastKey.current = sourceKey;
|
|
188
|
+
lastLoc.current = null;
|
|
189
|
+
}
|
|
84
190
|
(async () => {
|
|
85
191
|
try {
|
|
86
|
-
const
|
|
192
|
+
const limit = cb.current.maxFileSize ?? DEFAULT_MAX_FILE;
|
|
193
|
+
let data = 'uri' in source ? await uriToBase64(source, limit) : cleanBase64(source.base64);
|
|
87
194
|
if (cancelled)
|
|
88
195
|
return;
|
|
196
|
+
if (!data)
|
|
197
|
+
throw new Error('The book file is empty.');
|
|
198
|
+
// the book travels in pieces: one huge string would exist several times over (JSON, bridge, page)
|
|
199
|
+
for (let i = 0; i < data.length; i += CHUNK) {
|
|
200
|
+
web.current?.injectJavaScript(`window.__chunk(${i === 0 ? 1 : 0},"${data.slice(i, i + CHUNK)}");true;`);
|
|
201
|
+
}
|
|
202
|
+
data = '';
|
|
203
|
+
// settings, highlights and position are read now, not when loading started
|
|
89
204
|
send({
|
|
90
205
|
cmd: 'open',
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
206
|
+
settings: latest.current.engineSettings,
|
|
207
|
+
highlights: latest.current.highlights || [],
|
|
208
|
+
location: lastLoc.current || cb.current.initialLocation,
|
|
209
|
+
locationChars: cb.current.locationChars ?? 150,
|
|
210
|
+
repairZeroWidth: cb.current.repairZeroWidth !== false
|
|
95
211
|
});
|
|
96
212
|
opened.current = true;
|
|
97
213
|
}
|
|
98
214
|
catch (e) {
|
|
99
|
-
cb.current.onError?.(String(e?.message || e));
|
|
215
|
+
cb.current.onError?.(String(e?.message || e), { fatal: true });
|
|
100
216
|
}
|
|
101
217
|
})();
|
|
102
218
|
return () => {
|
|
@@ -106,12 +222,18 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
106
222
|
}, [engineReady, sourceKey]);
|
|
107
223
|
(0, react_1.useEffect)(() => {
|
|
108
224
|
if (opened.current)
|
|
109
|
-
send({ cmd: 'settings', settings: engineSettings });
|
|
110
|
-
}, [
|
|
225
|
+
send({ cmd: 'settings', settings: latest.current.engineSettings });
|
|
226
|
+
}, [engineJson, send]);
|
|
111
227
|
(0, react_1.useEffect)(() => {
|
|
112
228
|
if (opened.current)
|
|
113
229
|
send({ cmd: 'highlights', list: highlights || [] });
|
|
114
230
|
}, [highlights, send]);
|
|
231
|
+
// Android killed the renderer / iOS terminated the web content process: start over at the last position
|
|
232
|
+
const recover = (0, react_1.useCallback)(() => {
|
|
233
|
+
opened.current = false;
|
|
234
|
+
setEngineReady(false);
|
|
235
|
+
setWebKey((k) => k + 1);
|
|
236
|
+
}, []);
|
|
115
237
|
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
116
238
|
next: () => send({ cmd: 'next' }),
|
|
117
239
|
prev: () => send({ cmd: 'prev' }),
|
|
@@ -123,7 +245,6 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
123
245
|
send({ cmd: 'showHit', offset: r.offset, length: r.length });
|
|
124
246
|
},
|
|
125
247
|
clearSelection: () => {
|
|
126
|
-
selection.current = null;
|
|
127
248
|
send({ cmd: 'clearSelection' });
|
|
128
249
|
},
|
|
129
250
|
setLabels: (header, footer) => send({ cmd: 'labels', header, footer })
|
|
@@ -136,8 +257,10 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
136
257
|
catch {
|
|
137
258
|
return;
|
|
138
259
|
}
|
|
260
|
+
if (!msg || typeof msg !== 'object' || typeof msg.type !== 'string')
|
|
261
|
+
return;
|
|
139
262
|
const p = cb.current;
|
|
140
|
-
const d = msg.data;
|
|
263
|
+
const d = msg.data && typeof msg.data === 'object' ? msg.data : {};
|
|
141
264
|
switch (msg.type) {
|
|
142
265
|
case 'ready':
|
|
143
266
|
setEngineReady(true);
|
|
@@ -147,23 +270,26 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
147
270
|
break;
|
|
148
271
|
case 'toc':
|
|
149
272
|
p.onReady?.({ metadata: metaRef.current, rtl: !!d.rtl });
|
|
150
|
-
|
|
273
|
+
{
|
|
274
|
+
const items = Array.isArray(d.items) ? d.items : [];
|
|
275
|
+
p.onToc?.(items, Array.isArray(d.all) ? d.all : items);
|
|
276
|
+
}
|
|
151
277
|
break;
|
|
152
278
|
case 'cover':
|
|
153
|
-
|
|
279
|
+
if (typeof d.uri === 'string')
|
|
280
|
+
p.onCover?.(d.uri);
|
|
154
281
|
break;
|
|
155
282
|
case 'relocate':
|
|
283
|
+
lastLoc.current = { spine: d.spine, offset: d.offset };
|
|
156
284
|
p.onRelocate?.(d);
|
|
157
285
|
break;
|
|
158
286
|
case 'indexed':
|
|
159
287
|
p.onIndexed?.(d);
|
|
160
288
|
break;
|
|
161
289
|
case 'selection':
|
|
162
|
-
selection.current = d;
|
|
163
290
|
p.onSelection?.(d);
|
|
164
291
|
break;
|
|
165
292
|
case 'selectionClear':
|
|
166
|
-
selection.current = null;
|
|
167
293
|
p.onSelection?.(null);
|
|
168
294
|
break;
|
|
169
295
|
case 'highlightTap':
|
|
@@ -176,24 +302,36 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
176
302
|
p.onPageTurn?.();
|
|
177
303
|
break;
|
|
178
304
|
case 'link':
|
|
179
|
-
|
|
305
|
+
if (typeof d.href === 'string' && /^(https?|mailto):/i.test(d.href))
|
|
306
|
+
p.onLink?.(d.href);
|
|
307
|
+
break;
|
|
308
|
+
case 'linkJump':
|
|
309
|
+
p.onLinkJump?.({ spine: d.spine, offset: d.offset });
|
|
310
|
+
break;
|
|
311
|
+
case 'direction':
|
|
312
|
+
p.onDirectionChange?.(!!d.rtl);
|
|
180
313
|
break;
|
|
181
314
|
case 'searchResults':
|
|
182
|
-
p.onSearchResults?.(d.id, d.results, d.done);
|
|
315
|
+
p.onSearchResults?.(d.id, Array.isArray(d.results) ? d.results : [], !!d.done);
|
|
183
316
|
break;
|
|
184
317
|
case 'end':
|
|
185
318
|
p.onEndReached?.(d.edge);
|
|
186
319
|
break;
|
|
320
|
+
case 'locations':
|
|
321
|
+
p.onLocations?.({ count: d.count });
|
|
322
|
+
break;
|
|
323
|
+
case 'zoom':
|
|
324
|
+
p.onZoom?.(typeof d.scale === 'number' ? d.scale : 1);
|
|
325
|
+
break;
|
|
187
326
|
case 'error':
|
|
188
|
-
p.onError?.(d.message);
|
|
327
|
+
p.onError?.(String(d.message || 'Unknown error'), { fatal: !!d.fatal });
|
|
189
328
|
break;
|
|
190
329
|
}
|
|
191
330
|
}, []);
|
|
192
|
-
const bg = (0, themes_1.themeColors)(settings, systemDark).bg;
|
|
331
|
+
const bg = (0, themes_1.themeColors)(settings, systemDark, props.themes).bg;
|
|
193
332
|
return (react_1.default.createElement(react_native_1.View, { style: [styles.fill, { backgroundColor: bg }] },
|
|
194
|
-
react_1.default.createElement(react_native_webview_1.WebView, { ref: web, style: [styles.fill, { backgroundColor: bg }], originWhitelist: ['*'], source: { html: html_1.READER_HTML }, onMessage: onMessage, javaScriptEnabled: true, domStorageEnabled: false, scrollEnabled: false, bounces: false, overScrollMode: "never", showsHorizontalScrollIndicator: false, showsVerticalScrollIndicator: false, automaticallyAdjustContentInsets: false, contentInsetAdjustmentBehavior: "never", allowsInlineMediaPlayback: true, hideKeyboardAccessoryView: true, setSupportMultipleWindows: false,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}, onShouldStartLoadWithRequest: (req) => req.url === 'about:blank' || req.url.startsWith('data:') || req.url.startsWith('about:'), onError: (e) => cb.current.onError?.(e.nativeEvent.description) })));
|
|
333
|
+
react_1.default.createElement(react_native_webview_1.WebView, { key: webKey, ref: web, style: [styles.fill, { backgroundColor: bg }], originWhitelist: ['*'], source: { html: html_1.READER_HTML }, onMessage: onMessage, javaScriptEnabled: true, domStorageEnabled: false, scrollEnabled: false, bounces: false, overScrollMode: "never", showsHorizontalScrollIndicator: false, showsVerticalScrollIndicator: false, automaticallyAdjustContentInsets: false, contentInsetAdjustmentBehavior: "never", allowsInlineMediaPlayback: true, hideKeyboardAccessoryView: true, setSupportMultipleWindows: false,
|
|
334
|
+
// the page is generated here and never needs the file system, the network or the system font scale
|
|
335
|
+
allowFileAccess: false, allowFileAccessFromFileURLs: false, allowUniversalAccessFromFileURLs: false, mixedContentMode: "never", cacheEnabled: false, textZoom: 100, onShouldStartLoadWithRequest: (req) => req.url === 'about:blank' || req.url.startsWith('data:') || req.url.startsWith('about:'), onRenderProcessGone: recover, onContentProcessDidTerminate: recover, onError: (e) => cb.current.onError?.(e.nativeEvent.description || 'The reader failed to load.', { fatal: true }) })));
|
|
198
336
|
});
|
|
199
337
|
const styles = react_native_1.StyleSheet.create({ fill: { flex: 1 } });
|
package/lib/EpubReaderView.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ChromeOverrides } from './themes';
|
|
3
|
+
import type { Bookmark, BookColors, BookLocation, BookMetadata, CustomFont, EpubSource, Highlight, ReaderSettings, ReaderTheme, RelocateEvent, SafeInsets, UiFonts } from './types';
|
|
4
|
+
import type { ReaderLabels } from './strings';
|
|
3
5
|
export interface EpubReaderViewProps {
|
|
4
6
|
source: EpubSource;
|
|
5
7
|
/** shown in the Contents sheet until the book's own title is read */
|
|
6
8
|
title?: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/** Space for the status bar / home indicator (and notch in landscape). Use useSafeAreaInsets() from react-native-safe-area-context. */
|
|
10
|
+
safeInsets?: SafeInsets;
|
|
11
|
+
/** where to open: an offset or an epub.js CFI ({ cfi: 'epubcfi(...)' }) */
|
|
12
|
+
initialLocation?: BookLocation | {
|
|
13
|
+
cfi: string;
|
|
10
14
|
};
|
|
11
|
-
initialLocation?: BookLocation;
|
|
12
15
|
initialSettings?: Partial<ReaderSettings>;
|
|
13
16
|
initialHighlights?: Highlight[];
|
|
14
17
|
initialBookmarks?: Bookmark[];
|
|
@@ -20,5 +23,34 @@ export interface EpubReaderViewProps {
|
|
|
20
23
|
onMetadata?: (m: BookMetadata) => void;
|
|
21
24
|
onCover?: (dataUri: string) => void;
|
|
22
25
|
onError?: (message: string) => void;
|
|
26
|
+
/** Texts of the interface; leave out what you do not translate (see ReaderLabels). */
|
|
27
|
+
labels?: Partial<ReaderLabels>;
|
|
28
|
+
/** Largest EPUB in bytes that will be opened (default 150 MB, 0 = no limit). */
|
|
29
|
+
maxFileSize?: number;
|
|
30
|
+
/** Highlight colours by name, shown in the highlight menu (default: the built-in five). See EpubReader. */
|
|
31
|
+
highlightColors?: Record<string, string>;
|
|
32
|
+
highlightOpacity?: number;
|
|
33
|
+
/** App fonts; the ones with an `id` are added to the font list. See EpubReader. */
|
|
34
|
+
fonts?: CustomFont[];
|
|
35
|
+
bookColors?: BookColors;
|
|
36
|
+
maxZoom?: number;
|
|
37
|
+
/** characters per epub.js location (default 150, 0 = off). See EpubReader. */
|
|
38
|
+
locationChars?: number;
|
|
39
|
+
repairZeroWidth?: boolean;
|
|
40
|
+
onLocations?: (info: {
|
|
41
|
+
count: number;
|
|
42
|
+
}) => void;
|
|
43
|
+
/** Page themes instead of the built-in six (Themes sheet and page colours). */
|
|
44
|
+
themes?: ReaderTheme[];
|
|
45
|
+
/** Colours of buttons, sheets and menus, for light and dark pages. Missing ones keep the default. */
|
|
46
|
+
chrome?: ChromeOverrides;
|
|
47
|
+
/** Fonts of the interface (not the book), e.g. the app's own font. */
|
|
48
|
+
uiFonts?: UiFonts;
|
|
49
|
+
/** Light or dark for the 'device' appearance. Default: the phone's setting. Pass the app's own when it has one. */
|
|
50
|
+
colorScheme?: 'light' | 'dark';
|
|
23
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Full reader screen. A different `source` (or Try again after an error) starts a fresh screen, so highlights,
|
|
54
|
+
* bookmarks and position of one book can never leak into another.
|
|
55
|
+
*/
|
|
24
56
|
export declare function EpubReaderView(props: EpubReaderViewProps): React.JSX.Element;
|