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/src/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { EpubReaderView } from './EpubReaderView';
|
|
2
2
|
export type { EpubReaderViewProps } from './EpubReaderView';
|
|
3
3
|
export { EpubReader } from './EpubReader';
|
|
4
|
-
export type { EpubReaderProps, EpubReaderHandle } from './EpubReader';
|
|
5
|
-
export { THEMES, FONTS, HIGHLIGHT_COLORS, DEFAULT_SETTINGS, getTheme, getFont, chromeColors } from './themes';
|
|
4
|
+
export type { EpubReaderProps, EpubReaderHandle, ReaderErrorInfo } from './EpubReader';
|
|
5
|
+
export { THEMES, FONTS, HIGHLIGHT_COLORS, DEFAULT_SETTINGS, getTheme, getFont, chromeColors, themeColors, isDark } from './themes';
|
|
6
|
+
export type { ChromeColors } from './themes';
|
|
7
|
+
export { DEFAULT_LABELS } from './strings';
|
|
8
|
+
export type { ReaderLabels } from './strings';
|
|
6
9
|
export * from './types';
|
package/src/strings.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Every text the reader shows. Pass a partial object as the `labels` prop of EpubReaderView to translate
|
|
5
|
+
* (for example into Pashto, Dari or Arabic); anything you leave out stays English.
|
|
6
|
+
*/
|
|
7
|
+
export interface ReaderLabels {
|
|
8
|
+
contents: string;
|
|
9
|
+
chapters: string;
|
|
10
|
+
font: string;
|
|
11
|
+
lineSpacing: string;
|
|
12
|
+
characterSpacing: string;
|
|
13
|
+
wordSpacing: string;
|
|
14
|
+
margins: string;
|
|
15
|
+
columns: string;
|
|
16
|
+
columnsAuto: string;
|
|
17
|
+
columnsOne: string;
|
|
18
|
+
columnsTwo: string;
|
|
19
|
+
slide: string;
|
|
20
|
+
curl: string;
|
|
21
|
+
fastFade: string;
|
|
22
|
+
scrollMode: string;
|
|
23
|
+
light: string;
|
|
24
|
+
dark: string;
|
|
25
|
+
matchDevice: string;
|
|
26
|
+
matchSurroundings: string;
|
|
27
|
+
appearance: string;
|
|
28
|
+
pageTurnStyle: string;
|
|
29
|
+
delete: string;
|
|
30
|
+
deleteBookmark: string;
|
|
31
|
+
deleteHighlight: string;
|
|
32
|
+
search: string;
|
|
33
|
+
searchBook: string;
|
|
34
|
+
searchInBook: string;
|
|
35
|
+
searching: string;
|
|
36
|
+
noResults: string;
|
|
37
|
+
themesSettings: string;
|
|
38
|
+
customizeTheme: string;
|
|
39
|
+
customize: string;
|
|
40
|
+
resetTheme: string;
|
|
41
|
+
boldText: string;
|
|
42
|
+
justifyText: string;
|
|
43
|
+
pageTurnSound: string;
|
|
44
|
+
accessibilityLayout: string;
|
|
45
|
+
smallerText: string;
|
|
46
|
+
largerText: string;
|
|
47
|
+
readerMenu: string;
|
|
48
|
+
closeBook: string;
|
|
49
|
+
share: string;
|
|
50
|
+
rotationLock: string;
|
|
51
|
+
rotationLockNeedsPackage: string;
|
|
52
|
+
lineGuide: string;
|
|
53
|
+
turnOffLineGuide: string;
|
|
54
|
+
backgroundDimming: string;
|
|
55
|
+
dimHigh: string;
|
|
56
|
+
dimMedium: string;
|
|
57
|
+
dimLow: string;
|
|
58
|
+
dimNone: string;
|
|
59
|
+
bookmarkPage: string;
|
|
60
|
+
highlight: string;
|
|
61
|
+
note: string;
|
|
62
|
+
addNote: string;
|
|
63
|
+
addANote: string;
|
|
64
|
+
underline: string;
|
|
65
|
+
removeHighlight: string;
|
|
66
|
+
dismiss: string;
|
|
67
|
+
done: string;
|
|
68
|
+
close: string;
|
|
69
|
+
cancel: string;
|
|
70
|
+
save: string;
|
|
71
|
+
ok: string;
|
|
72
|
+
noToc: string;
|
|
73
|
+
noBookmarks: string;
|
|
74
|
+
noHighlights: string;
|
|
75
|
+
bookmarks: string;
|
|
76
|
+
highlights: string;
|
|
77
|
+
loading: string;
|
|
78
|
+
couldNotOpen: string;
|
|
79
|
+
tryAgain: string;
|
|
80
|
+
openLink: string;
|
|
81
|
+
open: string;
|
|
82
|
+
lastPageInChapter: string;
|
|
83
|
+
/** "N pages left in chapter" */
|
|
84
|
+
pagesLeft: (n: number) => string;
|
|
85
|
+
/** "3 of 120" */
|
|
86
|
+
pageOfTotal: (page: number, total: number) => string;
|
|
87
|
+
/** "Page 3 of 120" */
|
|
88
|
+
pageOfTotalLong: (page: number, total: number) => string;
|
|
89
|
+
returnToPage: (page: number) => string;
|
|
90
|
+
/** how numbers are written (e.g. Arabic-Indic digits for an Arabic UI) */
|
|
91
|
+
formatNumber: (n: number) => string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const DEFAULT_LABELS: ReaderLabels = {
|
|
95
|
+
contents: 'Contents',
|
|
96
|
+
chapters: 'Chapters',
|
|
97
|
+
font: 'Font',
|
|
98
|
+
lineSpacing: 'LINE SPACING',
|
|
99
|
+
characterSpacing: 'CHARACTER SPACING',
|
|
100
|
+
wordSpacing: 'WORD SPACING',
|
|
101
|
+
margins: 'MARGINS',
|
|
102
|
+
columns: 'Columns',
|
|
103
|
+
columnsAuto: 'Auto Set',
|
|
104
|
+
columnsOne: 'One',
|
|
105
|
+
columnsTwo: 'Two',
|
|
106
|
+
slide: 'Slide',
|
|
107
|
+
curl: 'Curl',
|
|
108
|
+
fastFade: 'Fast Fade',
|
|
109
|
+
scrollMode: 'Scroll',
|
|
110
|
+
light: 'Light',
|
|
111
|
+
dark: 'Dark',
|
|
112
|
+
matchDevice: 'Match Device',
|
|
113
|
+
matchSurroundings: 'Match Surroundings',
|
|
114
|
+
appearance: 'Appearance',
|
|
115
|
+
pageTurnStyle: 'Page turn style',
|
|
116
|
+
delete: 'Delete',
|
|
117
|
+
deleteBookmark: 'Delete bookmark?',
|
|
118
|
+
deleteHighlight: 'Delete highlight?',
|
|
119
|
+
search: 'Search',
|
|
120
|
+
searchBook: 'Search Book',
|
|
121
|
+
searchInBook: 'Search in book',
|
|
122
|
+
searching: 'Searching…',
|
|
123
|
+
noResults: 'No results',
|
|
124
|
+
themesSettings: 'Themes & Settings',
|
|
125
|
+
customizeTheme: 'Customize Theme',
|
|
126
|
+
customize: 'Customize',
|
|
127
|
+
resetTheme: 'Reset Theme',
|
|
128
|
+
boldText: 'Bold Text',
|
|
129
|
+
justifyText: 'Justify Text',
|
|
130
|
+
pageTurnSound: 'Page Turn Sound',
|
|
131
|
+
accessibilityLayout: 'Accessibility & Layout Options',
|
|
132
|
+
smallerText: 'Smaller text',
|
|
133
|
+
largerText: 'Larger text',
|
|
134
|
+
readerMenu: 'Reader menu',
|
|
135
|
+
closeBook: 'Close book',
|
|
136
|
+
share: 'Share',
|
|
137
|
+
rotationLock: 'Rotation lock',
|
|
138
|
+
rotationLockNeedsPackage: 'Install expo-screen-orientation to enable the rotation lock.',
|
|
139
|
+
lineGuide: 'Line guide',
|
|
140
|
+
turnOffLineGuide: 'Turn Off Line Guide',
|
|
141
|
+
backgroundDimming: 'Background Dimming',
|
|
142
|
+
dimHigh: 'High',
|
|
143
|
+
dimMedium: 'Medium',
|
|
144
|
+
dimLow: 'Low',
|
|
145
|
+
dimNone: 'None',
|
|
146
|
+
bookmarkPage: 'Bookmark this page',
|
|
147
|
+
highlight: 'Highlight',
|
|
148
|
+
note: 'Note',
|
|
149
|
+
addNote: 'Add note',
|
|
150
|
+
addANote: 'Add a note',
|
|
151
|
+
underline: 'Underline',
|
|
152
|
+
removeHighlight: 'Remove highlight',
|
|
153
|
+
dismiss: 'Dismiss',
|
|
154
|
+
done: 'Done',
|
|
155
|
+
close: 'Close',
|
|
156
|
+
cancel: 'Cancel',
|
|
157
|
+
save: 'Save',
|
|
158
|
+
ok: 'OK',
|
|
159
|
+
noToc: 'No table of contents',
|
|
160
|
+
noBookmarks: 'No bookmarks yet. Tap the bookmark button while reading.',
|
|
161
|
+
noHighlights: 'No highlights or notes yet. Select text to add one.',
|
|
162
|
+
bookmarks: 'Bookmarks',
|
|
163
|
+
highlights: 'Highlights',
|
|
164
|
+
loading: 'Opening book…',
|
|
165
|
+
couldNotOpen: 'This book could not be opened',
|
|
166
|
+
tryAgain: 'Try again',
|
|
167
|
+
openLink: 'Open this link?',
|
|
168
|
+
open: 'Open',
|
|
169
|
+
lastPageInChapter: 'Last page in chapter',
|
|
170
|
+
pagesLeft: (n) => `${n} page${n === 1 ? '' : 's'} left in chapter`,
|
|
171
|
+
pageOfTotal: (p, t) => `${p} of ${t}`,
|
|
172
|
+
pageOfTotalLong: (p, t) => `Page ${p} of ${t}`,
|
|
173
|
+
returnToPage: (p) => `Return to page ${p}`,
|
|
174
|
+
formatNumber: (n) => String(n)
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const LabelsContext = createContext<ReaderLabels>(DEFAULT_LABELS);
|
|
178
|
+
|
|
179
|
+
export const LabelsProvider = LabelsContext.Provider;
|
|
180
|
+
export function useLabels(): ReaderLabels {
|
|
181
|
+
return useContext(LabelsContext);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function mergeLabels(partial?: Partial<ReaderLabels>): ReaderLabels {
|
|
185
|
+
return partial ? { ...DEFAULT_LABELS, ...partial } : DEFAULT_LABELS;
|
|
186
|
+
}
|
|
187
|
+
|
package/src/themes.ts
CHANGED
|
@@ -101,7 +101,7 @@ export function themeColors(settings: ReaderSettings, systemDark: boolean): Them
|
|
|
101
101
|
const BASE_MARGIN = 28;
|
|
102
102
|
|
|
103
103
|
/** Settings object understood by the WebView engine. */
|
|
104
|
-
export function toEngineSettings(settings: ReaderSettings, systemDark: boolean, insets: { top: number; bottom: number }) {
|
|
104
|
+
export function toEngineSettings(settings: ReaderSettings, systemDark: boolean, insets: { top: number; bottom: number; left?: number; right?: number }) {
|
|
105
105
|
const theme = getTheme(settings.themeId);
|
|
106
106
|
const c = themeColors(settings, systemDark);
|
|
107
107
|
const custom = settings.customize;
|
|
@@ -120,7 +120,7 @@ export function toEngineSettings(settings: ReaderSettings, systemDark: boolean,
|
|
|
120
120
|
justify: settings.justify,
|
|
121
121
|
mode: settings.pageTurn,
|
|
122
122
|
direction: settings.direction,
|
|
123
|
-
insets: { top: insets.top + 40, bottom: insets.bottom + 40 }
|
|
123
|
+
insets: { top: insets.top + 40, bottom: insets.bottom + 40, left: insets.left || 0, right: insets.right || 0 }
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
126
|
|
package/src/types.ts
CHANGED
|
@@ -135,4 +135,20 @@ export interface ReaderSettings {
|
|
|
135
135
|
direction: 'auto' | 'ltr' | 'rtl';
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Where the book comes from.
|
|
140
|
+
* - uri: file://, content:// (Android), https://, or an asset/bundle URI that fetch() can read. `headers` are sent with the request.
|
|
141
|
+
* - base64: the EPUB bytes as base64 (a data: prefix is accepted).
|
|
142
|
+
* `key` identifies the book: when it changes the reader opens the new source. Defaults to the uri, or to a fingerprint of the data.
|
|
143
|
+
*/
|
|
144
|
+
export type EpubSource =
|
|
145
|
+
| { uri: string; headers?: Record<string, string>; key?: string }
|
|
146
|
+
| { base64: string; key?: string };
|
|
147
|
+
|
|
148
|
+
/** Safe-area space around the page, in points. Left/right matter in landscape on notched phones. */
|
|
149
|
+
export interface SafeInsets {
|
|
150
|
+
top: number;
|
|
151
|
+
bottom: number;
|
|
152
|
+
left?: number;
|
|
153
|
+
right?: number;
|
|
154
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
3
3
|
import { isDark, serifFont, THEMES } from '../themes';
|
|
4
4
|
import type { ChromeColors } from '../themes';
|
|
5
5
|
import type { Appearance, PageTurn, ReaderSettings } from '../types';
|
|
6
|
+
import { useLabels } from '../strings';
|
|
7
|
+
import type { ReaderLabels } from '../strings';
|
|
6
8
|
import { Icon } from './Icons';
|
|
7
9
|
import type { IconName } from './Icons';
|
|
8
10
|
import { Sheet } from './Sheet';
|
|
@@ -20,18 +22,18 @@ interface Props {
|
|
|
20
22
|
|
|
21
23
|
const SIZE = { min: 12, max: 40, step: 2 };
|
|
22
24
|
|
|
23
|
-
const TURNS: { id: PageTurn; label:
|
|
24
|
-
{ id: 'slide', label: '
|
|
25
|
-
{ id: 'curl', label: '
|
|
26
|
-
{ id: 'fade', label: '
|
|
27
|
-
{ id: 'scroll', label: '
|
|
25
|
+
const TURNS: { id: PageTurn; label: keyof ReaderLabels; icon: IconName }[] = [
|
|
26
|
+
{ id: 'slide', label: 'slide', icon: 'pageSlide' },
|
|
27
|
+
{ id: 'curl', label: 'curl', icon: 'pageCurl' },
|
|
28
|
+
{ id: 'fade', label: 'fastFade', icon: 'pageFade' },
|
|
29
|
+
{ id: 'scroll', label: 'scrollMode', icon: 'pageScroll' }
|
|
28
30
|
];
|
|
29
31
|
|
|
30
|
-
const APPEARANCES: { id: Appearance; label:
|
|
31
|
-
{ id: 'light', label: '
|
|
32
|
-
{ id: 'dark', label: '
|
|
33
|
-
{ id: 'device', label: '
|
|
34
|
-
{ id: 'device', label: '
|
|
32
|
+
const APPEARANCES: { id: Appearance; label: keyof ReaderLabels; icon: IconName; key: string }[] = [
|
|
33
|
+
{ id: 'light', label: 'light', icon: 'sun', key: 'light' },
|
|
34
|
+
{ id: 'dark', label: 'dark', icon: 'moon', key: 'dark' },
|
|
35
|
+
{ id: 'device', label: 'matchDevice', icon: 'contrast', key: 'device' },
|
|
36
|
+
{ id: 'device', label: 'matchSurroundings', icon: 'sunLow', key: 'surroundings' }
|
|
35
37
|
];
|
|
36
38
|
|
|
37
39
|
/** Icon of the current appearance choice: the button always shows the state it is in. */
|
|
@@ -39,7 +41,12 @@ const appearanceIcon = (a: Appearance): IconName => (a === 'light' ? 'sun' : a =
|
|
|
39
41
|
|
|
40
42
|
/** "Themes & Settings" sheet. */
|
|
41
43
|
export function AppearanceSheet({ visible, colors, settings: s, systemDark, onChange, onCustomize, onClose }: Props) {
|
|
44
|
+
const L = useLabels();
|
|
42
45
|
const [menu, setMenu] = useState<null | 'turn' | 'appearance'>(null);
|
|
46
|
+
// a popup left open must not reappear the next time the sheet is shown
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!visible) setMenu(null);
|
|
49
|
+
}, [visible]);
|
|
43
50
|
const dark = isDark(s, systemDark);
|
|
44
51
|
const turn = TURNS.find((t) => t.id === s.pageTurn) || TURNS[0];
|
|
45
52
|
|
|
@@ -59,7 +66,7 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
|
|
|
59
66
|
>
|
|
60
67
|
<View style={styles.check}>{s.pageTurn === t.id && <Icon name="check" color={colors.text} size={20} />}</View>
|
|
61
68
|
<Icon name={t.icon} color={colors.text} size={24} />
|
|
62
|
-
<Text style={[styles.menuText, { color: colors.text }]}>{t.label}</Text>
|
|
69
|
+
<Text style={[styles.menuText, { color: colors.text }]}>{L[t.label] as string}</Text>
|
|
63
70
|
</Pressable>
|
|
64
71
|
))
|
|
65
72
|
: APPEARANCES.map((a) => (
|
|
@@ -73,7 +80,7 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
|
|
|
73
80
|
>
|
|
74
81
|
<View style={styles.check}>{s.appearance === a.id && a.key !== 'surroundings' && <Icon name="check" color={colors.text} size={20} />}</View>
|
|
75
82
|
<Icon name={a.icon} color={colors.text} size={24} />
|
|
76
|
-
<Text style={[styles.menuText, { color: colors.text }]}>{a.label}</Text>
|
|
83
|
+
<Text style={[styles.menuText, { color: colors.text }]}>{L[a.label] as string}</Text>
|
|
77
84
|
</Pressable>
|
|
78
85
|
))}
|
|
79
86
|
</View>
|
|
@@ -81,14 +88,15 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
|
|
|
81
88
|
);
|
|
82
89
|
|
|
83
90
|
return (
|
|
84
|
-
<Sheet visible={visible} colors={colors} onClose={onClose} title=
|
|
91
|
+
<Sheet visible={visible} colors={colors} onClose={onClose} title={L.themesSettings} height="auto" overlay={menuView || undefined}>
|
|
85
92
|
<View style={styles.body}>
|
|
86
93
|
<View style={styles.row}>
|
|
87
94
|
<View style={[styles.pill, { flex: 1, backgroundColor: colors.card }]}>
|
|
88
95
|
<Pressable
|
|
89
96
|
style={styles.half}
|
|
90
97
|
onPress={() => onChange({ fontSize: Math.max(SIZE.min, s.fontSize - SIZE.step) })}
|
|
91
|
-
|
|
98
|
+
accessibilityRole="button"
|
|
99
|
+
accessibilityLabel={L.smallerText}
|
|
92
100
|
>
|
|
93
101
|
<Text style={{ color: colors.text, fontSize: 15, fontWeight: '500' }}>A</Text>
|
|
94
102
|
</Pressable>
|
|
@@ -96,16 +104,17 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
|
|
|
96
104
|
<Pressable
|
|
97
105
|
style={styles.half}
|
|
98
106
|
onPress={() => onChange({ fontSize: Math.min(SIZE.max, s.fontSize + SIZE.step) })}
|
|
99
|
-
|
|
107
|
+
accessibilityRole="button"
|
|
108
|
+
accessibilityLabel={L.largerText}
|
|
100
109
|
>
|
|
101
110
|
<Text style={{ color: colors.text, fontSize: 26, fontWeight: '500' }}>A</Text>
|
|
102
111
|
</Pressable>
|
|
103
112
|
</View>
|
|
104
113
|
<View style={[styles.pill, { width: 150, backgroundColor: colors.card }]}>
|
|
105
|
-
<Pressable style={[styles.half, menu === 'turn' && { backgroundColor: colors.separator }]} onPress={() => setMenu(menu === 'turn' ? null : 'turn')} accessibilityLabel={
|
|
114
|
+
<Pressable style={[styles.half, menu === 'turn' && { backgroundColor: colors.separator }]} onPress={() => setMenu(menu === 'turn' ? null : 'turn')} accessibilityRole="button" accessibilityLabel={`${L.pageTurnStyle}: ${L[turn.label] as string}`}>
|
|
106
115
|
<Icon name={turn.icon} color={colors.text} size={26} />
|
|
107
116
|
</Pressable>
|
|
108
|
-
<Pressable style={[styles.half, menu === 'appearance' && { backgroundColor: colors.separator }]} onPress={() => setMenu(menu === 'appearance' ? null : 'appearance')}
|
|
117
|
+
<Pressable style={[styles.half, menu === 'appearance' && { backgroundColor: colors.separator }]} onPress={() => setMenu(menu === 'appearance' ? null : 'appearance')} accessibilityRole="button" accessibilityLabel={L.appearance}>
|
|
109
118
|
<Icon name={appearanceIcon(s.appearance)} color={colors.text} size={26} />
|
|
110
119
|
</Pressable>
|
|
111
120
|
</View>
|
|
@@ -140,7 +149,7 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
|
|
|
140
149
|
|
|
141
150
|
<Pressable onPress={onCustomize} style={[styles.customize, { backgroundColor: colors.card }]} accessibilityRole="button">
|
|
142
151
|
<Icon name="sliders" color={colors.text} size={22} />
|
|
143
|
-
<Text style={{ color: colors.text, fontSize: 18, fontWeight: '600', marginStart: 10 }}>
|
|
152
|
+
<Text style={{ color: colors.text, fontSize: 18, fontWeight: '600', marginStart: 10 }}>{L.customize}</Text>
|
|
144
153
|
</Pressable>
|
|
145
154
|
</View>
|
|
146
155
|
</Sheet>
|
package/src/ui/ContentsSheet.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { Alert, FlatList, Pressable, StyleSheet, Text, View } from 'react-native
|
|
|
3
3
|
import { HIGHLIGHT_COLORS } from '../themes';
|
|
4
4
|
import type { ChromeColors } from '../themes';
|
|
5
5
|
import type { Bookmark, Highlight, TocItem } from '../types';
|
|
6
|
+
import { useLabels } from '../strings';
|
|
6
7
|
import { Sheet } from './Sheet';
|
|
7
8
|
|
|
8
9
|
export type ContentsTab = 'contents' | 'bookmarks' | 'notes';
|
|
@@ -28,20 +29,21 @@ interface Props {
|
|
|
28
29
|
onDeleteHighlight: (id: string) => void;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
const TABS: { id: ContentsTab; label:
|
|
32
|
-
{ id: 'contents', label: '
|
|
33
|
-
{ id: 'bookmarks', label: '
|
|
34
|
-
{ id: 'notes', label: '
|
|
32
|
+
const TABS: { id: ContentsTab; label: 'chapters' | 'bookmarks' | 'highlights' }[] = [
|
|
33
|
+
{ id: 'contents', label: 'chapters' },
|
|
34
|
+
{ id: 'bookmarks', label: 'bookmarks' },
|
|
35
|
+
{ id: 'notes', label: 'highlights' }
|
|
35
36
|
];
|
|
36
37
|
|
|
37
38
|
/** Contents sheet: Chapters | Bookmarks | Highlights, each row with its page number. */
|
|
38
39
|
export function ContentsSheet(p: Props) {
|
|
39
40
|
const { colors } = p;
|
|
41
|
+
const L = useLabels();
|
|
40
42
|
const [tab, setTab] = useState<ContentsTab>(p.initialTab || 'contents');
|
|
41
|
-
const confirmDelete = (
|
|
42
|
-
Alert.alert(
|
|
43
|
-
{ text:
|
|
44
|
-
{ text:
|
|
43
|
+
const confirmDelete = (title: string, fn: () => void) =>
|
|
44
|
+
Alert.alert(title, undefined, [
|
|
45
|
+
{ text: L.cancel, style: 'cancel' },
|
|
46
|
+
{ text: L.delete, style: 'destructive', onPress: fn }
|
|
45
47
|
]);
|
|
46
48
|
const empty = (text: string) => <Text style={[styles.empty, { color: colors.subtext }]}>{text}</Text>;
|
|
47
49
|
const rowBorder = { borderColor: colors.separator };
|
|
@@ -57,7 +59,7 @@ export function ContentsSheet(p: Props) {
|
|
|
57
59
|
accessibilityRole="tab"
|
|
58
60
|
accessibilityState={{ selected: tab === t.id }}
|
|
59
61
|
>
|
|
60
|
-
<Text style={{ color: colors.text, fontWeight: tab === t.id ? '600' : '400', fontSize: 16 }}>{t.label}</Text>
|
|
62
|
+
<Text style={{ color: colors.text, fontWeight: tab === t.id ? '600' : '400', fontSize: 16 }} maxFontSizeMultiplier={1.3}>{L[t.label]}</Text>
|
|
61
63
|
</Pressable>
|
|
62
64
|
))}
|
|
63
65
|
</View>
|
|
@@ -66,15 +68,15 @@ export function ContentsSheet(p: Props) {
|
|
|
66
68
|
<FlatList
|
|
67
69
|
data={p.toc}
|
|
68
70
|
keyExtractor={(_, i) => String(i)}
|
|
69
|
-
ListEmptyComponent={empty(
|
|
71
|
+
ListEmptyComponent={empty(L.noToc)}
|
|
70
72
|
renderItem={({ item }) => {
|
|
71
73
|
const active = item.spine === p.currentSpine && !item.fragment;
|
|
72
74
|
return (
|
|
73
|
-
<Pressable onPress={() => p.onGoToc(item)} style={[styles.row, rowBorder, { paddingStart: 20 + item.level * 18 }]}>
|
|
75
|
+
<Pressable onPress={() => p.onGoToc(item)} accessibilityRole="button" style={[styles.row, rowBorder, { paddingStart: 20 + item.level * 18 }]}>
|
|
74
76
|
<Text style={[styles.rowText, { color: active ? colors.accent : colors.text, flex: 1 }]} numberOfLines={2}>
|
|
75
77
|
{item.label}
|
|
76
78
|
</Text>
|
|
77
|
-
<Text style={[styles.page, { color: colors.subtext }]}>{p.pageOf(item.spine, 0)}</Text>
|
|
79
|
+
<Text style={[styles.page, { color: colors.subtext }]}>{L.formatNumber(p.pageOf(item.spine, 0))}</Text>
|
|
78
80
|
</Pressable>
|
|
79
81
|
);
|
|
80
82
|
}}
|
|
@@ -85,11 +87,11 @@ export function ContentsSheet(p: Props) {
|
|
|
85
87
|
<FlatList
|
|
86
88
|
data={p.bookmarks.slice().sort((a, b) => a.progress - b.progress)}
|
|
87
89
|
keyExtractor={(b) => b.id}
|
|
88
|
-
ListEmptyComponent={empty(
|
|
90
|
+
ListEmptyComponent={empty(L.noBookmarks)}
|
|
89
91
|
renderItem={({ item }) => (
|
|
90
92
|
<Pressable
|
|
91
93
|
onPress={() => p.onGoBookmark(item)}
|
|
92
|
-
onLongPress={() => confirmDelete(
|
|
94
|
+
onLongPress={() => confirmDelete(L.deleteBookmark, () => p.onDeleteBookmark(item.id))}
|
|
93
95
|
style={[styles.row, rowBorder]}
|
|
94
96
|
>
|
|
95
97
|
<View style={{ flex: 1 }}>
|
|
@@ -98,7 +100,7 @@ export function ContentsSheet(p: Props) {
|
|
|
98
100
|
{item.excerpt}
|
|
99
101
|
</Text>
|
|
100
102
|
</View>
|
|
101
|
-
<Text style={[styles.page, { color: colors.subtext }]}>{p.pageOf(item.spine, item.offset)}</Text>
|
|
103
|
+
<Text style={[styles.page, { color: colors.subtext }]}>{L.formatNumber(p.pageOf(item.spine, item.offset))}</Text>
|
|
102
104
|
</Pressable>
|
|
103
105
|
)}
|
|
104
106
|
/>
|
|
@@ -108,11 +110,11 @@ export function ContentsSheet(p: Props) {
|
|
|
108
110
|
<FlatList
|
|
109
111
|
data={p.highlights.slice().sort((a, b) => a.spine - b.spine || a.start - b.start)}
|
|
110
112
|
keyExtractor={(h) => h.id}
|
|
111
|
-
ListEmptyComponent={empty(
|
|
113
|
+
ListEmptyComponent={empty(L.noHighlights)}
|
|
112
114
|
renderItem={({ item }) => (
|
|
113
115
|
<Pressable
|
|
114
116
|
onPress={() => p.onGoHighlight(item)}
|
|
115
|
-
onLongPress={() => confirmDelete(
|
|
117
|
+
onLongPress={() => confirmDelete(L.deleteHighlight, () => p.onDeleteHighlight(item.id))}
|
|
116
118
|
style={[styles.row, rowBorder]}
|
|
117
119
|
>
|
|
118
120
|
<View style={[styles.bar, { backgroundColor: HIGHLIGHT_COLORS[item.color] }]} />
|
|
@@ -123,7 +125,7 @@ export function ContentsSheet(p: Props) {
|
|
|
123
125
|
</Text>
|
|
124
126
|
{!!item.chapter && <Text style={[styles.meta, { color: colors.subtext }]}>{item.chapter}</Text>}
|
|
125
127
|
</View>
|
|
126
|
-
<Text style={[styles.page, { color: colors.subtext }]}>{p.pageOf(item.spine, item.start)}</Text>
|
|
128
|
+
<Text style={[styles.page, { color: colors.subtext }]}>{L.formatNumber(p.pageOf(item.spine, item.start))}</Text>
|
|
127
129
|
</Pressable>
|
|
128
130
|
)}
|
|
129
131
|
/>
|
|
@@ -3,6 +3,7 @@ import { Pressable, ScrollView, StyleSheet, Switch, Text, View } from 'react-nat
|
|
|
3
3
|
import { FONTS, getFont, serifFont } from '../themes';
|
|
4
4
|
import type { ChromeColors } from '../themes';
|
|
5
5
|
import type { ColumnsSetting, ReaderSettings, ThemeColors } from '../types';
|
|
6
|
+
import { useLabels } from '../strings';
|
|
6
7
|
import { Icon } from './Icons';
|
|
7
8
|
import type { IconName } from './Icons';
|
|
8
9
|
import { Sheet } from './Sheet';
|
|
@@ -19,7 +20,6 @@ interface Props {
|
|
|
19
20
|
onClose: () => void;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
const COLUMN_LABEL: Record<string, string> = { auto: 'Auto Set', '1': 'One', '2': 'Two' };
|
|
23
23
|
const GREEN = { true: '#34c759' };
|
|
24
24
|
|
|
25
25
|
function Toggle(props: React.ComponentProps<typeof Switch>) {
|
|
@@ -32,6 +32,8 @@ function Toggle(props: React.ComponentProps<typeof Switch>) {
|
|
|
32
32
|
|
|
33
33
|
/** "Customize Theme" sheet: font, bold, spacing, margins, columns, justify, sound. */
|
|
34
34
|
export function CustomizeSheet({ visible, colors, page, settings: s, sample, onChange, onReset, onClose }: Props) {
|
|
35
|
+
const L = useLabels();
|
|
36
|
+
const COLUMN_LABEL: Record<string, string> = { auto: L.columnsAuto, '1': L.columnsOne, '2': L.columnsTwo };
|
|
35
37
|
const [fonts, setFonts] = useState(false);
|
|
36
38
|
const [columnsMenu, setColumnsMenu] = useState(false);
|
|
37
39
|
const off = !s.customize;
|
|
@@ -78,7 +80,7 @@ export function CustomizeSheet({ visible, colors, page, settings: s, sample, onC
|
|
|
78
80
|
};
|
|
79
81
|
|
|
80
82
|
return (
|
|
81
|
-
<Sheet visible={visible} colors={colors} onClose={close} closeIcon="check" title=
|
|
83
|
+
<Sheet visible={visible} colors={colors} onClose={close} closeIcon="check" title={L.customizeTheme} height="92%">
|
|
82
84
|
<View style={[styles.preview, { backgroundColor: page.bg }]}>
|
|
83
85
|
<Text style={[styles.aa, { color: page.fg, fontFamily: previewFont }]}>Aa</Text>
|
|
84
86
|
<Text
|
|
@@ -97,7 +99,7 @@ export function CustomizeSheet({ visible, colors, page, settings: s, sample, onC
|
|
|
97
99
|
<View style={[styles.group, { backgroundColor: colors.card }]}>
|
|
98
100
|
{row(
|
|
99
101
|
'textSize',
|
|
100
|
-
|
|
102
|
+
L.font,
|
|
101
103
|
<View style={styles.value2}>
|
|
102
104
|
<Text style={{ color: colors.subtext, fontSize: 17 }}>{font.name}</Text>
|
|
103
105
|
<Icon name={fonts ? 'chevronUp' : 'chevronRight'} color={colors.subtext} size={18} />
|
|
@@ -119,22 +121,22 @@ export function CustomizeSheet({ visible, colors, page, settings: s, sample, onC
|
|
|
119
121
|
<Text style={[styles.label, { color: colors.text }]}>{f.name}</Text>
|
|
120
122
|
</Pressable>
|
|
121
123
|
))}
|
|
122
|
-
{row('bold',
|
|
124
|
+
{row('bold', L.boldText, <Toggle value={s.bold} onValueChange={(v) => onChange({ bold: v })} trackColor={GREEN} />)}
|
|
123
125
|
</View>
|
|
124
126
|
|
|
125
|
-
<Text style={[styles.heading, { color: colors.text }]}>
|
|
127
|
+
<Text style={[styles.heading, { color: colors.text }]}>{L.accessibilityLayout}</Text>
|
|
126
128
|
<View style={[styles.group, { backgroundColor: colors.card }]}>
|
|
127
|
-
{row('sliders',
|
|
128
|
-
{sliderRow(
|
|
129
|
-
{sliderRow(
|
|
130
|
-
{sliderRow(
|
|
131
|
-
{sliderRow(
|
|
129
|
+
{row('sliders', L.customize, <Toggle value={s.customize} onValueChange={(v) => onChange({ customize: v })} trackColor={GREEN} />, undefined, false)}
|
|
130
|
+
{sliderRow(L.lineSpacing, 'lineSpacing', s.lineHeight, 1.1, 2.2, 0.05, s.lineHeight.toFixed(2), 'lineHeight')}
|
|
131
|
+
{sliderRow(L.characterSpacing, 'charSpacing', s.letterSpacing, -50, 100, 5, `${s.letterSpacing}%`, 'letterSpacing')}
|
|
132
|
+
{sliderRow(L.wordSpacing, 'wordSpacing', s.wordSpacing, -50, 100, 5, `${s.wordSpacing}%`, 'wordSpacing')}
|
|
133
|
+
{sliderRow(L.margins, 'margins', s.margins, -50, 100, 5, `${s.margins}%`, 'margins')}
|
|
132
134
|
</View>
|
|
133
135
|
|
|
134
136
|
<View style={[styles.group, { backgroundColor: colors.card, marginTop: 16 }]}>
|
|
135
137
|
{row(
|
|
136
138
|
'columns',
|
|
137
|
-
|
|
139
|
+
L.columns,
|
|
138
140
|
<View style={styles.value2}>
|
|
139
141
|
<Text style={{ color: colors.subtext, fontSize: 17 }}>{COLUMN_LABEL[String(s.columns)]}</Text>
|
|
140
142
|
<Icon name={columnsMenu ? 'chevronUp' : 'chevronDown'} color={colors.subtext} size={18} />
|
|
@@ -156,12 +158,12 @@ export function CustomizeSheet({ visible, colors, page, settings: s, sample, onC
|
|
|
156
158
|
<Text style={[styles.label, { color: colors.text }]}>{COLUMN_LABEL[String(c)]}</Text>
|
|
157
159
|
</Pressable>
|
|
158
160
|
))}
|
|
159
|
-
{row('justify',
|
|
160
|
-
{row(s.pageSound ? 'sound' : 'soundOff',
|
|
161
|
+
{row('justify', L.justifyText, <Toggle value={s.justify} onValueChange={(v) => onChange({ justify: v })} trackColor={GREEN} />)}
|
|
162
|
+
{row(s.pageSound ? 'sound' : 'soundOff', L.pageTurnSound, <Toggle value={s.pageSound} onValueChange={(v) => onChange({ pageSound: v })} trackColor={GREEN} />)}
|
|
161
163
|
</View>
|
|
162
164
|
|
|
163
|
-
<Pressable onPress={onReset} style={[styles.reset, { backgroundColor: colors.card }]}>
|
|
164
|
-
<Text style={{ color: '#ff3b30', fontSize: 18, fontWeight: '600' }}>
|
|
165
|
+
<Pressable onPress={onReset} style={[styles.reset, { backgroundColor: colors.card }]} accessibilityRole="button">
|
|
166
|
+
<Text style={{ color: '#ff3b30', fontSize: 18, fontWeight: '600' }}>{L.resetTheme}</Text>
|
|
165
167
|
</Pressable>
|
|
166
168
|
</ScrollView>
|
|
167
169
|
</Sheet>
|
package/src/ui/HighlightMenu.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { Pressable, StyleSheet, View } from 'react-native';
|
|
|
3
3
|
import { HIGHLIGHT_COLORS } from '../themes';
|
|
4
4
|
import type { ChromeColors } from '../themes';
|
|
5
5
|
import type { Highlight, HighlightColor } from '../types';
|
|
6
|
+
import { useLabels } from '../strings';
|
|
6
7
|
import { Glass } from './Glass';
|
|
7
8
|
import { Icon } from './Icons';
|
|
8
9
|
|
|
@@ -18,30 +19,32 @@ interface Props {
|
|
|
18
19
|
onDismiss: () => void;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
const
|
|
22
|
+
const MAX_W = 316;
|
|
22
23
|
const H = 50;
|
|
23
24
|
|
|
24
25
|
/** Floating glass palette shown over a highlight, like Apple Books. */
|
|
25
26
|
export function HighlightMenu({ highlight, rect, screen, colors, onColor, onToggleUnderline, onNote, onDelete, onDismiss }: Props) {
|
|
27
|
+
const L = useLabels();
|
|
28
|
+
const W = Math.min(MAX_W, screen.width - 16); // narrow windows (split screen, foldable cover screens)
|
|
26
29
|
const left = Math.max(8, Math.min(screen.width - W - 8, rect.x + rect.width / 2 - W / 2));
|
|
27
30
|
const above = rect.y - H - 10;
|
|
28
31
|
const top = above > 60 ? above : rect.y + rect.height + 10;
|
|
29
32
|
return (
|
|
30
33
|
<>
|
|
31
|
-
<Pressable style={StyleSheet.absoluteFill} onPress={onDismiss} accessibilityLabel=
|
|
32
|
-
<Glass dark={colors.dark} background={colors.sheetGlass} border={colors.glassBorder} intensity={55} style={[styles.menu, { left, top }]}>
|
|
34
|
+
<Pressable style={StyleSheet.absoluteFill} onPress={onDismiss} accessibilityLabel={L.dismiss} />
|
|
35
|
+
<Glass dark={colors.dark} background={colors.sheetGlass} border={colors.glassBorder} intensity={55} style={[styles.menu, { left, top, width: W }]}>
|
|
33
36
|
{(Object.keys(HIGHLIGHT_COLORS) as HighlightColor[]).map((c) => (
|
|
34
|
-
<Pressable key={c} onPress={() => onColor(c)} hitSlop={
|
|
37
|
+
<Pressable key={c} onPress={() => onColor(c)} hitSlop={8} accessibilityRole="button" accessibilityLabel={`${c} ${L.highlight}`} accessibilityState={{ selected: highlight.color === c }}>
|
|
35
38
|
<View style={[styles.dot, { backgroundColor: HIGHLIGHT_COLORS[c], borderWidth: highlight.color === c ? 2 : 0, borderColor: colors.text }]} />
|
|
36
39
|
</Pressable>
|
|
37
40
|
))}
|
|
38
|
-
<Pressable onPress={onToggleUnderline} hitSlop={
|
|
41
|
+
<Pressable onPress={onToggleUnderline} hitSlop={11} accessibilityRole="button" accessibilityLabel={L.underline} accessibilityState={{ selected: highlight.style === 'underline' }}>
|
|
39
42
|
<Icon name="underline" color={colors.text} size={22} active={highlight.style === 'underline'} strokeWidth={highlight.style === 'underline' ? 2.4 : 1.8} />
|
|
40
43
|
</Pressable>
|
|
41
|
-
<Pressable onPress={onNote} hitSlop={
|
|
44
|
+
<Pressable onPress={onNote} hitSlop={11} accessibilityRole="button" accessibilityLabel={L.note}>
|
|
42
45
|
<Icon name="pencil" color={colors.text} size={22} />
|
|
43
46
|
</Pressable>
|
|
44
|
-
<Pressable onPress={onDelete} hitSlop={
|
|
47
|
+
<Pressable onPress={onDelete} hitSlop={11} accessibilityRole="button" accessibilityLabel={L.removeHighlight}>
|
|
45
48
|
<Icon name="trash" color="#ff3b30" size={22} />
|
|
46
49
|
</Pressable>
|
|
47
50
|
</Glass>
|
|
@@ -52,7 +55,6 @@ export function HighlightMenu({ highlight, rect, screen, colors, onColor, onTogg
|
|
|
52
55
|
const styles = StyleSheet.create({
|
|
53
56
|
menu: {
|
|
54
57
|
position: 'absolute',
|
|
55
|
-
width: W,
|
|
56
58
|
height: H,
|
|
57
59
|
borderRadius: 25,
|
|
58
60
|
flexDirection: 'row',
|
|
@@ -60,5 +62,5 @@ const styles = StyleSheet.create({
|
|
|
60
62
|
justifyContent: 'space-around',
|
|
61
63
|
paddingHorizontal: 12
|
|
62
64
|
},
|
|
63
|
-
dot: { width:
|
|
65
|
+
dot: { width: 28, height: 28, borderRadius: 14 }
|
|
64
66
|
});
|