aksos-react-native-epub-reader 0.1.0 → 0.1.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/README.md +21 -8
- package/lib/EpubReader.d.ts +20 -7
- package/lib/EpubReader.js +106 -21
- package/lib/EpubReaderView.d.ts +12 -5
- package/lib/EpubReaderView.js +175 -80
- 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 +4 -0
- package/lib/themes.js +1 -1
- package/lib/types.d.ts +16 -0
- package/lib/ui/AppearanceSheet.js +23 -16
- package/lib/ui/ContentsSheet.js +16 -14
- package/lib/ui/CustomizeSheet.js +17 -15
- package/lib/ui/HighlightMenu.js +11 -9
- package/lib/ui/NoteEditor.js +10 -8
- package/lib/ui/SearchSheet.js +15 -3
- package/lib/ui/Sheet.js +5 -3
- package/package.json +75 -75
- package/src/EpubReader.tsx +123 -23
- package/src/EpubReaderView.tsx +229 -85
- package/src/engine/html.ts +1 -1
- package/src/engine/reader.js +455 -104
- package/src/index.ts +5 -2
- package/src/strings.ts +187 -0
- package/src/themes.ts +2 -2
- package/src/types.ts +17 -1
- package/src/ui/AppearanceSheet.tsx +28 -19
- package/src/ui/ContentsSheet.tsx +20 -18
- package/src/ui/CustomizeSheet.tsx +17 -15
- package/src/ui/HighlightMenu.tsx +11 -9
- package/src/ui/NoteEditor.tsx +10 -8
- package/src/ui/SearchSheet.tsx +21 -5
- package/src/ui/Sheet.tsx +5 -3
package/lib/EpubReaderView.js
CHANGED
|
@@ -42,6 +42,7 @@ const AppearanceSheet_1 = require("./ui/AppearanceSheet");
|
|
|
42
42
|
const ContentsSheet_1 = require("./ui/ContentsSheet");
|
|
43
43
|
const CustomizeSheet_1 = require("./ui/CustomizeSheet");
|
|
44
44
|
const sound_1 = require("./sound");
|
|
45
|
+
const strings_1 = require("./strings");
|
|
45
46
|
const Glass_1 = require("./ui/Glass");
|
|
46
47
|
const HighlightMenu_1 = require("./ui/HighlightMenu");
|
|
47
48
|
const Icons_1 = require("./ui/Icons");
|
|
@@ -68,20 +69,43 @@ try {
|
|
|
68
69
|
catch {
|
|
69
70
|
ScreenOrientation = null;
|
|
70
71
|
}
|
|
71
|
-
const
|
|
72
|
-
{ id: 'high', label: '
|
|
73
|
-
{ id: 'medium', label: '
|
|
74
|
-
{ id: 'low', label: '
|
|
75
|
-
{ id: 'none', label: '
|
|
72
|
+
const DIM_IDS = [
|
|
73
|
+
{ id: 'high', label: 'dimHigh' },
|
|
74
|
+
{ id: 'medium', label: 'dimMedium' },
|
|
75
|
+
{ id: 'low', label: 'dimLow' },
|
|
76
|
+
{ id: 'none', label: 'dimNone' }
|
|
76
77
|
];
|
|
77
78
|
const SAMPLE = 'The reader turned the page slowly, listening to the wind move across the empty hills.';
|
|
78
79
|
const uid = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
// Used when the host passes no safeInsets. A guess from the screen size; the exact values come from react-native-safe-area-context.
|
|
81
|
+
function defaultInsets(width, height) {
|
|
82
|
+
if (react_native_1.Platform.OS !== 'ios')
|
|
83
|
+
return { top: react_native_1.StatusBar.currentHeight || 24, bottom: 0 };
|
|
84
|
+
const long = Math.max(width, height);
|
|
85
|
+
const landscape = width > height;
|
|
86
|
+
const notch = long >= 812; // iPhone X and later (iPads are larger but have no notch: they are caught by the short side)
|
|
87
|
+
const phone = Math.min(width, height) < 600;
|
|
88
|
+
if (!phone)
|
|
89
|
+
return { top: 24, bottom: 20 };
|
|
90
|
+
if (!notch)
|
|
91
|
+
return { top: 20, bottom: 0 };
|
|
92
|
+
const top = long >= 852 ? 59 : 47;
|
|
93
|
+
return landscape ? { top: 0, bottom: 21, left: top, right: top } : { top, bottom: 34 };
|
|
81
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Full reader screen. A different `source` (or Try again after an error) starts a fresh screen, so highlights,
|
|
97
|
+
* bookmarks and position of one book can never leak into another.
|
|
98
|
+
*/
|
|
82
99
|
function EpubReaderView(props) {
|
|
83
|
-
const
|
|
100
|
+
const [attempt, setAttempt] = (0, react_1.useState)(0);
|
|
101
|
+
const labels = (0, react_1.useMemo)(() => (0, strings_1.mergeLabels)(props.labels), [props.labels]);
|
|
102
|
+
return (react_1.default.createElement(strings_1.LabelsProvider, { value: labels },
|
|
103
|
+
react_1.default.createElement(ReaderScreen, { key: `${(0, EpubReader_1.sourceKeyOf)(props.source)}#${attempt}`, ...props, onRetry: () => setAttempt((a) => a + 1) })));
|
|
104
|
+
}
|
|
105
|
+
function ReaderScreen(props) {
|
|
106
|
+
const L = (0, strings_1.useLabels)();
|
|
84
107
|
const screen = (0, react_native_1.useWindowDimensions)();
|
|
108
|
+
const safe = props.safeInsets || defaultInsets(screen.width, screen.height);
|
|
85
109
|
const systemDark = (0, react_native_1.useColorScheme)() === 'dark';
|
|
86
110
|
const reader = (0, react_1.useRef)(null);
|
|
87
111
|
const [settings, setSettings] = (0, react_1.useState)({ ...themes_1.DEFAULT_SETTINGS, ...props.initialSettings });
|
|
@@ -109,9 +133,30 @@ function EpubReaderView(props) {
|
|
|
109
133
|
const [results, setResults] = (0, react_1.useState)([]);
|
|
110
134
|
const [searching, setSearching] = (0, react_1.useState)(false);
|
|
111
135
|
const [error, setError] = (0, react_1.useState)(null);
|
|
136
|
+
// the book could not be opened (or the reader engine stopped): a full screen with a way out
|
|
137
|
+
const [fatal, setFatal] = (0, react_1.useState)(null);
|
|
138
|
+
const [loaded, setLoaded] = (0, react_1.useState)(false);
|
|
139
|
+
const [reduceMotion, setReduceMotion] = (0, react_1.useState)(false);
|
|
112
140
|
const searchId = (0, react_1.useRef)(0);
|
|
141
|
+
const latestProps = (0, react_1.useRef)(props);
|
|
142
|
+
latestProps.current = props;
|
|
143
|
+
const settingsRef = (0, react_1.useRef)(settings);
|
|
144
|
+
const highlightsRef = (0, react_1.useRef)(highlights);
|
|
145
|
+
const bookmarksRef = (0, react_1.useRef)(bookmarks);
|
|
146
|
+
const lockedByUs = (0, react_1.useRef)(false);
|
|
113
147
|
const seen = (0, react_1.useRef)({});
|
|
114
148
|
const layoutKey = (0, react_1.useRef)('');
|
|
149
|
+
(0, react_1.useEffect)(() => {
|
|
150
|
+
let on = true;
|
|
151
|
+
react_native_1.AccessibilityInfo.isReduceMotionEnabled?.().then((v) => on && setReduceMotion(!!v)).catch(() => undefined);
|
|
152
|
+
const sub = react_native_1.AccessibilityInfo.addEventListener?.('reduceMotionChanged', (v) => setReduceMotion(!!v));
|
|
153
|
+
return () => {
|
|
154
|
+
on = false;
|
|
155
|
+
sub?.remove?.();
|
|
156
|
+
};
|
|
157
|
+
}, []);
|
|
158
|
+
// people who asked for less motion get the fade instead of the curl or slide
|
|
159
|
+
const readerSettings = (0, react_1.useMemo)(() => (reduceMotion && (settings.pageTurn === 'curl' || settings.pageTurn === 'slide') ? { ...settings, pageTurn: 'fade' } : settings), [settings, reduceMotion]);
|
|
115
160
|
const dark = (0, themes_1.isDark)(settings, systemDark);
|
|
116
161
|
const page = (0, themes_1.themeColors)(settings, systemDark);
|
|
117
162
|
const colors = (0, react_1.useMemo)(() => (0, themes_1.chromeColors)(page, dark), [page, dark]);
|
|
@@ -130,29 +175,26 @@ function EpubReaderView(props) {
|
|
|
130
175
|
setMenuOpen(false);
|
|
131
176
|
}, [chrome]);
|
|
132
177
|
// ----- persistence helpers
|
|
178
|
+
// The next list is computed from a ref and the host is told outside of any state updater, so a callback
|
|
179
|
+
// never runs during render (StrictMode runs updaters twice) and quick successive edits never lose each other.
|
|
133
180
|
const updateHighlights = (0, react_1.useCallback)((fn) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
},
|
|
140
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
141
|
-
[props.onHighlightsChange]);
|
|
181
|
+
const next = fn(highlightsRef.current);
|
|
182
|
+
highlightsRef.current = next;
|
|
183
|
+
setHighlights(next);
|
|
184
|
+
latestProps.current.onHighlightsChange?.(next);
|
|
185
|
+
}, []);
|
|
142
186
|
const updateBookmarks = (0, react_1.useCallback)((fn) => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const changeSettings = (patch) => {
|
|
152
|
-
const next = { ...settings, ...patch };
|
|
187
|
+
const next = fn(bookmarksRef.current);
|
|
188
|
+
bookmarksRef.current = next;
|
|
189
|
+
setBookmarks(next);
|
|
190
|
+
latestProps.current.onBookmarksChange?.(next);
|
|
191
|
+
}, []);
|
|
192
|
+
const changeSettings = (0, react_1.useCallback)((patch) => {
|
|
193
|
+
const next = { ...settingsRef.current, ...patch };
|
|
194
|
+
settingsRef.current = next;
|
|
153
195
|
setSettings(next);
|
|
154
|
-
|
|
155
|
-
};
|
|
196
|
+
latestProps.current.onSettingsChange?.(next);
|
|
197
|
+
}, []);
|
|
156
198
|
// ----- book page numbers (estimated from characters per page)
|
|
157
199
|
const onRelocate = (e) => {
|
|
158
200
|
const key = [settings.fontSize, settings.fontId, settings.lineHeight, settings.letterSpacing, settings.wordSpacing, settings.margins, settings.customize, settings.columns, settings.bold, settings.pageTurn === 'scroll'].join('|');
|
|
@@ -170,6 +212,7 @@ function EpubReaderView(props) {
|
|
|
170
212
|
const next = pc > 0 && len > 0 ? len / pc : 1200;
|
|
171
213
|
setCpp((old) => (Math.abs(old - next) / next > 0.01 ? next : old));
|
|
172
214
|
setLoc(e);
|
|
215
|
+
setLoaded(true);
|
|
173
216
|
setActive(null);
|
|
174
217
|
props.onLocationChange?.(e);
|
|
175
218
|
};
|
|
@@ -186,10 +229,10 @@ function EpubReaderView(props) {
|
|
|
186
229
|
(0, react_1.useEffect)(() => {
|
|
187
230
|
if (!loc)
|
|
188
231
|
return;
|
|
189
|
-
const header = chrome ? (pagesLeft === 0 ?
|
|
190
|
-
const footer = chrome ?
|
|
232
|
+
const header = chrome ? (pagesLeft === 0 ? L.lastPageInChapter : L.pagesLeft(pagesLeft)) : loc.chapter;
|
|
233
|
+
const footer = chrome ? L.pageOfTotal(curPage, totalPages) : L.formatNumber(curPage);
|
|
191
234
|
reader.current?.setLabels(header, footer);
|
|
192
|
-
}, [chrome, loc, curPage, totalPages, pagesLeft]);
|
|
235
|
+
}, [chrome, loc, curPage, totalPages, pagesLeft, L]);
|
|
193
236
|
// ----- bookmarks
|
|
194
237
|
const bookmarkHere = (0, react_1.useMemo)(() => (loc ? bookmarks.filter((b) => b.spine === loc.spine && b.offset >= loc.offset && b.offset < Math.max(loc.end, loc.offset + 1)) : []), [bookmarks, loc]);
|
|
195
238
|
const toggleBookmark = () => {
|
|
@@ -260,12 +303,13 @@ function EpubReaderView(props) {
|
|
|
260
303
|
};
|
|
261
304
|
const toggleRotationLock = async () => {
|
|
262
305
|
if (!ScreenOrientation) {
|
|
263
|
-
react_native_1.Alert.alert(
|
|
306
|
+
react_native_1.Alert.alert(L.rotationLock, L.rotationLockNeedsPackage);
|
|
264
307
|
return;
|
|
265
308
|
}
|
|
266
309
|
try {
|
|
267
310
|
if (rotLocked) {
|
|
268
311
|
await ScreenOrientation.unlockAsync();
|
|
312
|
+
lockedByUs.current = false;
|
|
269
313
|
setRotLocked(false);
|
|
270
314
|
}
|
|
271
315
|
else {
|
|
@@ -273,6 +317,7 @@ function EpubReaderView(props) {
|
|
|
273
317
|
const O = ScreenOrientation.Orientation;
|
|
274
318
|
const L = ScreenOrientation.OrientationLock;
|
|
275
319
|
await ScreenOrientation.lockAsync(o === O.LANDSCAPE_LEFT ? L.LANDSCAPE_LEFT : o === O.LANDSCAPE_RIGHT ? L.LANDSCAPE_RIGHT : L.PORTRAIT_UP);
|
|
320
|
+
lockedByUs.current = true;
|
|
276
321
|
setRotLocked(true);
|
|
277
322
|
}
|
|
278
323
|
}
|
|
@@ -281,7 +326,8 @@ function EpubReaderView(props) {
|
|
|
281
326
|
}
|
|
282
327
|
};
|
|
283
328
|
(0, react_1.useEffect)(() => () => {
|
|
284
|
-
|
|
329
|
+
// only release a lock this reader set: the host app may have its own orientation policy
|
|
330
|
+
if (ScreenOrientation && lockedByUs.current)
|
|
285
331
|
ScreenOrientation.unlockAsync().catch(() => undefined);
|
|
286
332
|
}, []);
|
|
287
333
|
const onLineGuideButton = () => {
|
|
@@ -293,6 +339,14 @@ function EpubReaderView(props) {
|
|
|
293
339
|
else
|
|
294
340
|
setLineMenu(true);
|
|
295
341
|
};
|
|
342
|
+
const openLink = (href) => {
|
|
343
|
+
if (!/^(https?|mailto):/i.test(href))
|
|
344
|
+
return;
|
|
345
|
+
react_native_1.Alert.alert(L.openLink, href, [
|
|
346
|
+
{ text: L.cancel, style: 'cancel' },
|
|
347
|
+
{ text: L.open, onPress: () => react_native_1.Linking.openURL(href).catch(() => undefined) }
|
|
348
|
+
]);
|
|
349
|
+
};
|
|
296
350
|
const share = () => {
|
|
297
351
|
const text = [loc?.excerpt, meta?.title && `— ${meta.title}`].filter(Boolean).join(' ');
|
|
298
352
|
react_native_1.Share.share({ message: text || meta?.title || '' }).catch(() => undefined);
|
|
@@ -300,7 +354,7 @@ function EpubReaderView(props) {
|
|
|
300
354
|
const progressFill = Math.max(0, Math.min(1, loc?.progress ?? 0));
|
|
301
355
|
const tx = colors.text;
|
|
302
356
|
return (react_1.default.createElement(react_native_1.View, { style: [styles.root, { backgroundColor: page.bg }] },
|
|
303
|
-
react_1.default.createElement(EpubReader_1.EpubReader, { ref: reader, source: props.source, settings:
|
|
357
|
+
react_1.default.createElement(EpubReader_1.EpubReader, { ref: reader, source: props.source, settings: readerSettings, systemDark: systemDark, safeInsets: safe, initialLocation: props.initialLocation, highlights: highlights, maxFileSize: props.maxFileSize, onReady: ({ metadata, rtl: isRtl }) => {
|
|
304
358
|
setMeta(metadata);
|
|
305
359
|
setRtl(isRtl);
|
|
306
360
|
props.onMetadata?.(metadata);
|
|
@@ -320,127 +374,159 @@ function EpubReaderView(props) {
|
|
|
320
374
|
setChrome(false);
|
|
321
375
|
setActive(null);
|
|
322
376
|
}
|
|
323
|
-
}, onLink: (
|
|
377
|
+
}, onLink: openLink, onLinkJump: (from) => setReturnTo({ spine: from.spine, offset: from.offset, page: pageOf(from.spine, from.offset) }), onDirectionChange: setRtl, onSearchResults: (id, found, done) => {
|
|
324
378
|
if (id !== searchId.current)
|
|
325
379
|
return;
|
|
326
380
|
setResults((prev) => prev.concat(found));
|
|
327
381
|
if (done)
|
|
328
382
|
setSearching(false);
|
|
329
|
-
}, onError: (m) => {
|
|
330
|
-
|
|
383
|
+
}, onError: (m, info) => {
|
|
384
|
+
if (info.fatal || !loaded)
|
|
385
|
+
setFatal(m);
|
|
386
|
+
else
|
|
387
|
+
setError(m);
|
|
331
388
|
props.onError?.(m);
|
|
332
389
|
} }),
|
|
390
|
+
!chrome && (react_1.default.createElement(react_native_1.View, { pointerEvents: "none", accessible: true, accessibilityRole: "button", accessibilityLabel: L.readerMenu, accessibilityActions: [
|
|
391
|
+
{ name: 'activate', label: L.readerMenu },
|
|
392
|
+
{ name: 'increment', label: 'Next page' },
|
|
393
|
+
{ name: 'decrement', label: 'Previous page' }
|
|
394
|
+
], onAccessibilityAction: (e) => {
|
|
395
|
+
const a = e.nativeEvent.actionName;
|
|
396
|
+
if (a === 'increment')
|
|
397
|
+
reader.current?.next();
|
|
398
|
+
else if (a === 'decrement')
|
|
399
|
+
reader.current?.prev();
|
|
400
|
+
else
|
|
401
|
+
setChrome(true);
|
|
402
|
+
}, style: [styles.a11yHandle, { bottom: safe.bottom, left: safe.left || 0 }] })),
|
|
333
403
|
react_1.default.createElement(react_native_1.View, { pointerEvents: "none", style: [react_native_1.StyleSheet.absoluteFill, { backgroundColor: '#000000', opacity: (1 - settings.brightness) * 0.75 }] }),
|
|
334
404
|
lineGuide && (react_1.default.createElement(LineGuide_1.LineGuide, { bg: page.bg, dark: dark, dim: dimLevel, lineHeight: settings.fontSize * (settings.customize ? settings.lineHeight : 1.5), minY: safe.top + 30, maxY: screen.height - safe.bottom - 30 })),
|
|
335
405
|
bookmarkHere.length > 0 && (react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: "none", style: [styles.ribbon, { right: 22, opacity: fadeOut }] },
|
|
336
406
|
react_1.default.createElement(react_native_1.View, { style: styles.ribbonBody }),
|
|
337
407
|
react_1.default.createElement(react_native_1.View, { style: styles.ribbonNotch }))),
|
|
338
|
-
react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: chrome ? 'auto' : 'none', style: [styles.closeWrap, { top: safe.top + 2, opacity: fade }] },
|
|
339
|
-
react_1.default.createElement(react_native_1.Pressable, { onPress: props.onClose, hitSlop: 10, accessibilityRole: "button", accessibilityLabel:
|
|
408
|
+
react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: chrome ? 'auto' : 'none', ...hiddenA11y(!chrome), style: [styles.closeWrap, { top: safe.top + 2, right: 16 + (safe.right || 0), opacity: fade }] },
|
|
409
|
+
react_1.default.createElement(react_native_1.Pressable, { onPress: props.onClose, hitSlop: 10, accessibilityRole: "button", accessibilityLabel: L.closeBook },
|
|
340
410
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.circle },
|
|
341
411
|
react_1.default.createElement(Icons_1.Icon, { name: "close", color: tx, size: 22 })))),
|
|
342
|
-
returnTo && (react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: chrome ? 'auto' : 'none', style: [styles.returnWrap, { top: safe.top + 2, opacity: fade }] },
|
|
412
|
+
returnTo && (react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: chrome ? 'auto' : 'none', ...hiddenA11y(!chrome), style: [styles.returnWrap, { top: safe.top + 2, left: 16 + (safe.left || 0), opacity: fade }] },
|
|
343
413
|
react_1.default.createElement(react_native_1.Pressable, { onPress: () => {
|
|
344
414
|
reader.current?.goTo({ spine: returnTo.spine, offset: returnTo.offset });
|
|
345
415
|
setReturnTo(null);
|
|
346
|
-
}, hitSlop: 8, accessibilityRole: "button", accessibilityLabel:
|
|
416
|
+
}, hitSlop: 8, accessibilityRole: "button", accessibilityLabel: L.returnToPage(returnTo.page) },
|
|
347
417
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.returnPill },
|
|
348
418
|
react_1.default.createElement(Icons_1.Icon, { name: "undo", color: tx, size: 22 }),
|
|
349
|
-
react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 20, marginStart: 8 } }, returnTo.page))))),
|
|
350
|
-
react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: chrome && !menuOpen ? 'auto' : 'none', style: [styles.menuBtnWrap, { bottom: safe.bottom + 14, opacity: react_native_1.Animated.multiply(fade, react_native_1.Animated.subtract(1, menuFade)) }] },
|
|
351
|
-
react_1.default.createElement(react_native_1.Pressable, { onPress: () => setMenuOpen(true), accessibilityRole: "button", accessibilityLabel:
|
|
419
|
+
react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 20, marginStart: 8 }, maxFontSizeMultiplier: 1.3 }, L.formatNumber(returnTo.page)))))),
|
|
420
|
+
react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: chrome && !menuOpen ? 'auto' : 'none', ...hiddenA11y(!(chrome && !menuOpen)), style: [styles.menuBtnWrap, { bottom: safe.bottom + 14, right: 16 + (safe.right || 0), opacity: react_native_1.Animated.multiply(fade, react_native_1.Animated.subtract(1, menuFade)) }] },
|
|
421
|
+
react_1.default.createElement(react_native_1.Pressable, { onPress: () => setMenuOpen(true), accessibilityRole: "button", accessibilityLabel: L.readerMenu },
|
|
352
422
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.menuBtn },
|
|
353
423
|
react_1.default.createElement(Icons_1.Icon, { name: "list", color: tx, size: 24 })))),
|
|
354
|
-
react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: chrome && menuOpen ? 'box-none' : 'none', style: [styles.controls, { bottom: safe.bottom + 44, opacity: menuFade }] },
|
|
424
|
+
react_1.default.createElement(react_native_1.Animated.View, { pointerEvents: chrome && menuOpen ? 'box-none' : 'none', ...hiddenA11y(!(chrome && menuOpen)), style: [styles.controls, { bottom: safe.bottom + 44, right: 16 + (safe.right || 0), opacity: menuFade }] },
|
|
355
425
|
react_1.default.createElement(react_native_1.Pressable, { onPress: () => {
|
|
356
426
|
setMenuOpen(false);
|
|
357
427
|
setSheet('contents');
|
|
358
|
-
}, accessibilityRole: "button", accessibilityLabel:
|
|
428
|
+
}, accessibilityRole: "button", accessibilityLabel: L.contents, style: styles.pillWrap },
|
|
359
429
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.pill },
|
|
360
430
|
react_1.default.createElement(react_native_1.View, { style: styles.pillRow, onLayout: (e) => setPillW(e.nativeEvent.layout.width) },
|
|
361
|
-
react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: tx }] },
|
|
362
|
-
|
|
363
|
-
|
|
431
|
+
react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: tx }], maxFontSizeMultiplier: 1.3 },
|
|
432
|
+
L.contents,
|
|
433
|
+
" \u2022 ",
|
|
434
|
+
L.formatNumber(percent),
|
|
364
435
|
"%"),
|
|
365
436
|
react_1.default.createElement(Icons_1.Icon, { name: "list", color: tx, size: 24 })),
|
|
366
437
|
react_1.default.createElement(react_native_1.View, { pointerEvents: "none", style: [styles.fill, { width: progressFill * pillW, backgroundColor: dark ? 'rgba(255,255,255,0.35)' : '#1c1408', [rtl ? 'right' : 'left']: 0 }] },
|
|
367
438
|
react_1.default.createElement(react_native_1.View, { style: [styles.pillRow, { position: 'absolute', top: 0, width: pillW, [rtl ? 'right' : 'left']: 0 }] },
|
|
368
|
-
react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: dark ? tx : '#ffffff' }] },
|
|
369
|
-
|
|
370
|
-
|
|
439
|
+
react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: dark ? tx : '#ffffff' }], maxFontSizeMultiplier: 1.3 },
|
|
440
|
+
L.contents,
|
|
441
|
+
" \u2022 ",
|
|
442
|
+
L.formatNumber(percent),
|
|
371
443
|
"%"),
|
|
372
444
|
react_1.default.createElement(Icons_1.Icon, { name: "list", color: dark ? tx : '#ffffff', size: 24 }))))),
|
|
373
445
|
react_1.default.createElement(react_native_1.Pressable, { onPress: () => {
|
|
374
446
|
setMenuOpen(false);
|
|
375
447
|
setSheet('search');
|
|
376
|
-
}, accessibilityRole: "button", accessibilityLabel:
|
|
448
|
+
}, accessibilityRole: "button", accessibilityLabel: L.searchBook, style: styles.pillWrap },
|
|
377
449
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.pill },
|
|
378
450
|
react_1.default.createElement(react_native_1.View, { style: styles.pillRow },
|
|
379
|
-
react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: tx }] },
|
|
451
|
+
react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: tx }], maxFontSizeMultiplier: 1.3 }, L.searchBook),
|
|
380
452
|
react_1.default.createElement(Icons_1.Icon, { name: "search", color: tx, size: 24 })))),
|
|
381
453
|
react_1.default.createElement(react_native_1.Pressable, { onPress: () => {
|
|
382
454
|
setMenuOpen(false);
|
|
383
455
|
setSheet('appearance');
|
|
384
|
-
}, accessibilityRole: "button", accessibilityLabel:
|
|
456
|
+
}, accessibilityRole: "button", accessibilityLabel: L.themesSettings, style: styles.pillWrap },
|
|
385
457
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.pill },
|
|
386
458
|
react_1.default.createElement(react_native_1.View, { style: styles.pillRow },
|
|
387
|
-
react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: tx }] },
|
|
459
|
+
react_1.default.createElement(react_native_1.Text, { style: [styles.pillText, { color: tx }], maxFontSizeMultiplier: 1.3 }, L.themesSettings),
|
|
388
460
|
react_1.default.createElement(Icons_1.Icon, { name: "textSize", color: tx, size: 26 })))),
|
|
389
461
|
react_1.default.createElement(react_native_1.View, { style: styles.roundRow },
|
|
390
|
-
react_1.default.createElement(react_native_1.Pressable, { onPress: share, style: styles.roundWrap, accessibilityRole: "button", accessibilityLabel:
|
|
462
|
+
react_1.default.createElement(react_native_1.Pressable, { onPress: share, style: styles.roundWrap, accessibilityRole: "button", accessibilityLabel: L.share },
|
|
391
463
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.round },
|
|
392
464
|
react_1.default.createElement(Icons_1.Icon, { name: "share", color: tx, size: 24 }))),
|
|
393
|
-
react_1.default.createElement(react_native_1.Pressable, { onPress: toggleRotationLock, style: styles.roundWrap, accessibilityRole: "button", accessibilityLabel:
|
|
465
|
+
react_1.default.createElement(react_native_1.Pressable, { onPress: toggleRotationLock, style: styles.roundWrap, accessibilityRole: "button", accessibilityLabel: L.rotationLock, accessibilityState: { selected: rotLocked } },
|
|
394
466
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: rotLocked ? (dark ? 'rgba(255,255,255,0.35)' : 'rgba(0,0,0,0.18)') : colors.glass, border: colors.glassBorder, style: styles.round },
|
|
395
467
|
react_1.default.createElement(Icons_1.Icon, { name: "rotationLock", color: tx, size: 26, active: rotLocked }))),
|
|
396
|
-
react_1.default.createElement(react_native_1.Pressable, { onPress: onLineGuideButton, style: styles.roundWrap, accessibilityRole: "button", accessibilityLabel:
|
|
468
|
+
react_1.default.createElement(react_native_1.Pressable, { onPress: onLineGuideButton, style: styles.roundWrap, accessibilityRole: "button", accessibilityLabel: L.lineGuide, accessibilityState: { selected: lineGuide } },
|
|
397
469
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: lineGuide ? (dark ? 'rgba(255,255,255,0.35)' : 'rgba(0,0,0,0.18)') : colors.glass, border: colors.glassBorder, style: styles.round },
|
|
398
470
|
react_1.default.createElement(Icons_1.Icon, { name: "lineGuide", color: tx, size: 26, active: lineGuide }))),
|
|
399
|
-
react_1.default.createElement(react_native_1.Pressable, { onPress: toggleBookmark, style: styles.roundWrap, accessibilityRole: "button", accessibilityLabel:
|
|
471
|
+
react_1.default.createElement(react_native_1.Pressable, { onPress: toggleBookmark, style: styles.roundWrap, accessibilityRole: "button", accessibilityLabel: L.bookmarkPage, accessibilityState: { selected: bookmarkHere.length > 0 } },
|
|
400
472
|
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.round },
|
|
401
473
|
react_1.default.createElement(Icons_1.Icon, { name: "bookmark", color: tx, size: 24, active: bookmarkHere.length > 0 }))))),
|
|
402
474
|
selection && !active && !noteFor && (() => {
|
|
403
|
-
const w = 214;
|
|
475
|
+
const w = Math.min(Math.max(214, screen.width * 0.5), screen.width - 16);
|
|
404
476
|
const r = selection.rect;
|
|
405
477
|
const left = Math.max(8, Math.min(screen.width - w - 8, r.x + r.width / 2 - w / 2));
|
|
406
478
|
// the system callout (Copy / Look Up) sits above the selection, so ours goes below it
|
|
407
479
|
const below = r.y + r.height + 16;
|
|
408
480
|
const top = below + 54 > screen.height - safe.bottom ? Math.max(safe.top + 8, r.y - 120) : below;
|
|
409
481
|
return (react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.sheetGlass, border: colors.glassBorder, intensity: 55, style: [styles.selBar, { left, top, width: w }] },
|
|
410
|
-
react_1.default.createElement(react_native_1.Pressable, { style: styles.selBtn, onPress: () => createHighlight(selection, false), accessibilityRole: "button", accessibilityLabel:
|
|
482
|
+
react_1.default.createElement(react_native_1.Pressable, { style: styles.selBtn, onPress: () => createHighlight(selection, false), accessibilityRole: "button", accessibilityLabel: L.highlight },
|
|
411
483
|
react_1.default.createElement(Icons_1.Icon, { name: "highlighter", color: tx, size: 22 }),
|
|
412
|
-
react_1.default.createElement(react_native_1.Text, { style: [styles.selText, { color: tx }] },
|
|
484
|
+
react_1.default.createElement(react_native_1.Text, { style: [styles.selText, { color: tx }], numberOfLines: 1, maxFontSizeMultiplier: 1.2 }, L.highlight)),
|
|
413
485
|
react_1.default.createElement(react_native_1.View, { style: [styles.selSep, { backgroundColor: colors.separator }] }),
|
|
414
|
-
react_1.default.createElement(react_native_1.Pressable, { style: styles.selBtn, onPress: () => createHighlight(selection, true), accessibilityRole: "button", accessibilityLabel:
|
|
486
|
+
react_1.default.createElement(react_native_1.Pressable, { style: styles.selBtn, onPress: () => createHighlight(selection, true), accessibilityRole: "button", accessibilityLabel: L.addNote },
|
|
415
487
|
react_1.default.createElement(Icons_1.Icon, { name: "pencil", color: tx, size: 22 }),
|
|
416
|
-
react_1.default.createElement(react_native_1.Text, { style: [styles.selText, { color: tx }] },
|
|
488
|
+
react_1.default.createElement(react_native_1.Text, { style: [styles.selText, { color: tx }], numberOfLines: 1, maxFontSizeMultiplier: 1.2 }, L.note))));
|
|
417
489
|
})(),
|
|
418
490
|
activeHighlight && active && (react_1.default.createElement(HighlightMenu_1.HighlightMenu, { highlight: activeHighlight, rect: active.rect, screen: screen, colors: colors, onColor: (c) => patchHighlight(activeHighlight.id, { color: c }), onToggleUnderline: () => patchHighlight(activeHighlight.id, { style: activeHighlight.style === 'underline' ? 'highlight' : 'underline' }), onNote: () => {
|
|
419
491
|
setNoteFor(activeHighlight.id);
|
|
420
492
|
setActive(null);
|
|
421
493
|
}, onDelete: () => removeHighlight(activeHighlight.id), onDismiss: () => setActive(null) })),
|
|
422
|
-
|
|
494
|
+
!loaded && !fatal && (react_1.default.createElement(react_native_1.View, { style: [react_native_1.StyleSheet.absoluteFill, styles.splash, { backgroundColor: page.bg }], pointerEvents: "box-none" },
|
|
495
|
+
react_1.default.createElement(react_native_1.ActivityIndicator, { color: page.fg }),
|
|
496
|
+
react_1.default.createElement(react_native_1.Text, { style: { color: page.fg, opacity: 0.6, marginTop: 12, fontSize: 15 }, maxFontSizeMultiplier: 1.3 }, L.loading),
|
|
497
|
+
react_1.default.createElement(react_native_1.Pressable, { onPress: props.onClose, hitSlop: 10, accessibilityRole: "button", accessibilityLabel: L.closeBook, style: [styles.splashClose, { top: safe.top + 2, right: 16 + (safe.right || 0) }] },
|
|
498
|
+
react_1.default.createElement(Glass_1.Glass, { dark: dark, background: colors.glass, border: colors.glassBorder, style: styles.circle },
|
|
499
|
+
react_1.default.createElement(Icons_1.Icon, { name: "close", color: tx, size: 22 }))))),
|
|
500
|
+
!!fatal && (react_1.default.createElement(react_native_1.View, { style: [react_native_1.StyleSheet.absoluteFill, styles.splash, { backgroundColor: page.bg }], accessibilityViewIsModal: true },
|
|
501
|
+
react_1.default.createElement(react_native_1.Text, { style: { color: page.fg, fontSize: 18, fontWeight: '600', textAlign: 'center' }, accessibilityRole: "header" }, L.couldNotOpen),
|
|
502
|
+
react_1.default.createElement(react_native_1.Text, { style: { color: page.fg, opacity: 0.7, fontSize: 15, textAlign: 'center', marginTop: 10 }, accessibilityRole: "alert" }, fatal),
|
|
503
|
+
react_1.default.createElement(react_native_1.View, { style: styles.fatalButtons },
|
|
504
|
+
react_1.default.createElement(react_native_1.Pressable, { onPress: props.onRetry, style: [styles.fatalBtn, { backgroundColor: colors.accent }], accessibilityRole: "button" },
|
|
505
|
+
react_1.default.createElement(react_native_1.Text, { style: { color: '#ffffff', fontSize: 16, fontWeight: '600' } }, L.tryAgain)),
|
|
506
|
+
!!props.onClose && (react_1.default.createElement(react_native_1.Pressable, { onPress: props.onClose, style: [styles.fatalBtn, { backgroundColor: colors.card }], accessibilityRole: "button" },
|
|
507
|
+
react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 16, fontWeight: '600' } }, L.close)))))),
|
|
508
|
+
error && !fatal && (react_1.default.createElement(react_native_1.View, { style: [styles.error, { backgroundColor: colors.sheet }], accessibilityRole: "alert" },
|
|
423
509
|
react_1.default.createElement(react_native_1.Text, { style: { color: colors.text, fontSize: 15, textAlign: 'center' } }, error),
|
|
424
|
-
react_1.default.createElement(react_native_1.Pressable, { onPress: () => setError(null), style: { marginTop: 12 } },
|
|
425
|
-
react_1.default.createElement(react_native_1.Text, { style: { color: colors.accent, fontSize: 16 } },
|
|
510
|
+
react_1.default.createElement(react_native_1.Pressable, { onPress: () => setError(null), style: { marginTop: 12, padding: 8 }, accessibilityRole: "button" },
|
|
511
|
+
react_1.default.createElement(react_native_1.Text, { style: { color: colors.accent, fontSize: 16 } }, L.ok)))),
|
|
426
512
|
lineMenu && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
427
|
-
react_1.default.createElement(react_native_1.Pressable, { style: react_native_1.StyleSheet.absoluteFill, onPress: () => setLineMenu(false), accessibilityLabel:
|
|
513
|
+
react_1.default.createElement(react_native_1.Pressable, { style: react_native_1.StyleSheet.absoluteFill, onPress: () => setLineMenu(false), accessibilityLabel: L.dismiss }),
|
|
428
514
|
react_1.default.createElement(react_native_1.View, { style: [styles.lineMenu, { bottom: safe.bottom + 20, backgroundColor: colors.dark ? '#4a4742' : '#ffffff', borderColor: colors.glassBorder }] },
|
|
429
|
-
react_1.default.createElement(react_native_1.Text, { style: [styles.lineMenuHead, { color: colors.subtext }] },
|
|
430
|
-
|
|
515
|
+
react_1.default.createElement(react_native_1.Text, { style: [styles.lineMenuHead, { color: colors.subtext }] }, L.backgroundDimming),
|
|
516
|
+
DIM_IDS.map((d) => (react_1.default.createElement(react_native_1.Pressable, { key: d.id, style: styles.lineItem, accessibilityRole: "button", accessibilityState: { selected: dimLevel === d.id }, onPress: () => {
|
|
431
517
|
setDimLevel(d.id);
|
|
432
518
|
setLineMenu(false);
|
|
433
519
|
} },
|
|
434
520
|
react_1.default.createElement(react_native_1.View, { style: styles.lineCheck }, dimLevel === d.id && react_1.default.createElement(Icons_1.Icon, { name: "check", color: tx, size: 20 })),
|
|
435
|
-
react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 19 } }, d.label)))),
|
|
521
|
+
react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 19 } }, L[d.label])))),
|
|
436
522
|
react_1.default.createElement(react_native_1.View, { style: [styles.lineSep, { backgroundColor: colors.separator }] }),
|
|
437
|
-
react_1.default.createElement(react_native_1.Pressable, { style: styles.lineItem, onPress: () => {
|
|
523
|
+
react_1.default.createElement(react_native_1.Pressable, { style: styles.lineItem, accessibilityRole: "button", onPress: () => {
|
|
438
524
|
setLineGuide(false);
|
|
439
525
|
setLineMenu(false);
|
|
440
526
|
} },
|
|
441
527
|
react_1.default.createElement(react_native_1.View, { style: styles.lineCheck }),
|
|
442
|
-
react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 19 } },
|
|
443
|
-
react_1.default.createElement(ContentsSheet_1.ContentsSheet, { visible: sheet === 'contents', colors: colors, title: meta?.title || props.title || '', subtitle:
|
|
528
|
+
react_1.default.createElement(react_native_1.Text, { style: { color: tx, fontSize: 19 } }, L.turnOffLineGuide))))),
|
|
529
|
+
react_1.default.createElement(ContentsSheet_1.ContentsSheet, { visible: sheet === 'contents', colors: colors, title: meta?.title || props.title || '', subtitle: L.pageOfTotalLong(curPage, totalPages), toc: toc, currentSpine: loc?.spine ?? 0, pageOf: pageOf, bookmarks: bookmarks, highlights: highlights, onClose: closeSheet, onGoToc: (item) => {
|
|
444
530
|
closeSheet();
|
|
445
531
|
jump({ spine: item.spine, fragment: item.fragment });
|
|
446
532
|
}, onGoBookmark: (b) => {
|
|
@@ -467,9 +553,9 @@ function EpubReaderView(props) {
|
|
|
467
553
|
}
|
|
468
554
|
const styles = react_native_1.StyleSheet.create({
|
|
469
555
|
root: { flex: 1 },
|
|
470
|
-
closeWrap: { position: 'absolute'
|
|
556
|
+
closeWrap: { position: 'absolute' },
|
|
471
557
|
circle: { width: 42, height: 42, borderRadius: 21, alignItems: 'center', justifyContent: 'center' },
|
|
472
|
-
controls: { position: 'absolute',
|
|
558
|
+
controls: { position: 'absolute', width: '68%', minWidth: 260, maxWidth: 420 },
|
|
473
559
|
selBar: { position: 'absolute', height: 48, borderRadius: 24, flexDirection: 'row', alignItems: 'center' },
|
|
474
560
|
selBtn: { flex: 1, height: '100%', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6 },
|
|
475
561
|
selText: { fontSize: 15, fontWeight: '600' },
|
|
@@ -482,9 +568,9 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
482
568
|
lineItem: { flexDirection: 'row', alignItems: 'center', paddingVertical: 12, paddingHorizontal: 18 },
|
|
483
569
|
lineCheck: { width: 34 },
|
|
484
570
|
lineSep: { height: react_native_1.StyleSheet.hairlineWidth, marginVertical: 6, marginHorizontal: 18 },
|
|
485
|
-
menuBtnWrap: { position: 'absolute'
|
|
571
|
+
menuBtnWrap: { position: 'absolute' },
|
|
486
572
|
menuBtn: { width: 54, height: 54, borderRadius: 27, alignItems: 'center', justifyContent: 'center' },
|
|
487
|
-
returnWrap: { position: 'absolute'
|
|
573
|
+
returnWrap: { position: 'absolute' },
|
|
488
574
|
returnPill: { height: 46, borderRadius: 23, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16 },
|
|
489
575
|
pillRow: { height: 50, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 22 },
|
|
490
576
|
pillWrap: { marginBottom: 8 },
|
|
@@ -500,5 +586,14 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
500
586
|
width: 0, height: 0, borderLeftWidth: 8, borderRightWidth: 8, borderBottomWidth: 7,
|
|
501
587
|
borderLeftColor: '#ff3b30', borderRightColor: '#ff3b30', borderBottomColor: 'transparent'
|
|
502
588
|
},
|
|
503
|
-
error: { position: 'absolute', left: 24, right: 24, top: '40%', padding: 20, borderRadius: 14, alignItems: 'center', elevation: 10 }
|
|
589
|
+
error: { position: 'absolute', left: 24, right: 24, top: '40%', padding: 20, borderRadius: 14, alignItems: 'center', elevation: 10 },
|
|
590
|
+
splash: { alignItems: 'center', justifyContent: 'center', paddingHorizontal: 32 },
|
|
591
|
+
splashClose: { position: 'absolute' },
|
|
592
|
+
fatalButtons: { flexDirection: 'row', gap: 12, marginTop: 24 },
|
|
593
|
+
fatalBtn: { minWidth: 110, height: 46, borderRadius: 23, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 20 },
|
|
594
|
+
a11yHandle: { position: 'absolute', width: 48, height: 48, backgroundColor: 'transparent' }
|
|
504
595
|
});
|
|
596
|
+
// controls that are faded out must not stay reachable for VoiceOver / TalkBack
|
|
597
|
+
function hiddenA11y(hidden) {
|
|
598
|
+
return { accessibilityElementsHidden: hidden, importantForAccessibility: (hidden ? 'no-hide-descendants' : 'auto') };
|
|
599
|
+
}
|