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.
Files changed (48) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +178 -20
  3. package/lib/EpubReader.d.ts +66 -15
  4. package/lib/EpubReader.js +168 -30
  5. package/lib/EpubReaderView.d.ts +37 -5
  6. package/lib/EpubReaderView.js +194 -93
  7. package/lib/cfiOrder.d.ts +2 -0
  8. package/lib/cfiOrder.js +34 -0
  9. package/lib/engine/html.js +1 -1
  10. package/lib/index.d.ts +5 -2
  11. package/lib/index.js +5 -1
  12. package/lib/strings.d.ts +94 -0
  13. package/lib/strings.js +96 -0
  14. package/lib/themes.d.ts +28 -6
  15. package/lib/themes.js +80 -20
  16. package/lib/types.d.ts +82 -1
  17. package/lib/ui/AppearanceSheet.d.ts +4 -2
  18. package/lib/ui/AppearanceSheet.js +40 -26
  19. package/lib/ui/ContentsSheet.d.ts +2 -0
  20. package/lib/ui/ContentsSheet.js +32 -22
  21. package/lib/ui/CustomizeSheet.d.ts +4 -2
  22. package/lib/ui/CustomizeSheet.js +31 -27
  23. package/lib/ui/HighlightMenu.d.ts +4 -2
  24. package/lib/ui/HighlightMenu.js +13 -11
  25. package/lib/ui/NoteEditor.js +12 -9
  26. package/lib/ui/SearchSheet.js +19 -6
  27. package/lib/ui/Sheet.js +7 -4
  28. package/lib/ui/Text.d.ts +9 -0
  29. package/lib/ui/Text.js +62 -0
  30. package/package.json +81 -76
  31. package/src/EpubReader.tsx +239 -43
  32. package/src/EpubReaderView.tsx +287 -99
  33. package/src/cfiOrder.ts +28 -0
  34. package/src/engine/epubcfi.js +527 -0
  35. package/src/engine/html.ts +1 -1
  36. package/src/engine/reader.js +1273 -157
  37. package/src/index.ts +5 -2
  38. package/src/strings.ts +187 -0
  39. package/src/themes.ts +97 -21
  40. package/src/types.ts +88 -2
  41. package/src/ui/AppearanceSheet.tsx +47 -29
  42. package/src/ui/ContentsSheet.tsx +34 -22
  43. package/src/ui/CustomizeSheet.tsx +27 -21
  44. package/src/ui/HighlightMenu.tsx +17 -13
  45. package/src/ui/NoteEditor.tsx +12 -9
  46. package/src/ui/SearchSheet.tsx +22 -5
  47. package/src/ui/Sheet.tsx +8 -5
  48. package/src/ui/Text.tsx +27 -0
@@ -1,8 +1,11 @@
1
- import React, { useState } from 'react';
2
- import { Pressable, StyleSheet, Text, View } from 'react-native';
3
- import { isDark, serifFont, THEMES } from '../themes';
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Pressable, StyleSheet, View } from 'react-native';
3
+ import { Text } from './Text';
4
+ import { getTheme, isDark, serifFont, THEMES } from '../themes';
4
5
  import type { ChromeColors } from '../themes';
5
- import type { Appearance, PageTurn, ReaderSettings } from '../types';
6
+ import type { Appearance, PageTurn, ReaderSettings, ReaderTheme } from '../types';
7
+ import { useLabels } from '../strings';
8
+ import type { ReaderLabels } from '../strings';
6
9
  import { Icon } from './Icons';
7
10
  import type { IconName } from './Icons';
8
11
  import { Sheet } from './Sheet';
@@ -13,33 +16,44 @@ interface Props {
13
16
  colors: ChromeColors;
14
17
  settings: ReaderSettings;
15
18
  systemDark: boolean;
19
+ /** the host's themes (default: the built-in ones) */
20
+ themes?: ReaderTheme[];
16
21
  onChange: (patch: Partial<ReaderSettings>) => void;
17
22
  onCustomize: () => void;
18
23
  onClose: () => void;
19
24
  }
20
25
 
21
26
  const SIZE = { min: 12, max: 40, step: 2 };
27
+ const GRID_GAP = 10;
22
28
 
23
- const TURNS: { id: PageTurn; label: string; icon: IconName }[] = [
24
- { id: 'slide', label: 'Slide', icon: 'pageSlide' },
25
- { id: 'curl', label: 'Curl', icon: 'pageCurl' },
26
- { id: 'fade', label: 'Fast Fade', icon: 'pageFade' },
27
- { id: 'scroll', label: 'Scroll', icon: 'pageScroll' }
29
+ const TURNS: { id: PageTurn; label: keyof ReaderLabels; icon: IconName }[] = [
30
+ { id: 'slide', label: 'slide', icon: 'pageSlide' },
31
+ { id: 'curl', label: 'curl', icon: 'pageCurl' },
32
+ { id: 'fade', label: 'fastFade', icon: 'pageFade' },
33
+ { id: 'scroll', label: 'scrollMode', icon: 'pageScroll' }
28
34
  ];
29
35
 
30
- const APPEARANCES: { id: Appearance; label: string; icon: IconName; key: string }[] = [
31
- { id: 'light', label: 'Light', icon: 'sun', key: 'light' },
32
- { id: 'dark', label: 'Dark', icon: 'moon', key: 'dark' },
33
- { id: 'device', label: 'Match Device', icon: 'contrast', key: 'device' },
34
- { id: 'device', label: 'Match Surroundings', icon: 'sunLow', key: 'surroundings' }
36
+ const APPEARANCES: { id: Appearance; label: keyof ReaderLabels; icon: IconName; key: string }[] = [
37
+ { id: 'light', label: 'light', icon: 'sun', key: 'light' },
38
+ { id: 'dark', label: 'dark', icon: 'moon', key: 'dark' },
39
+ { id: 'device', label: 'matchDevice', icon: 'contrast', key: 'device' },
40
+ { id: 'device', label: 'matchSurroundings', icon: 'sunLow', key: 'surroundings' }
35
41
  ];
36
42
 
37
43
  /** Icon of the current appearance choice: the button always shows the state it is in. */
38
44
  const appearanceIcon = (a: Appearance): IconName => (a === 'light' ? 'sun' : a === 'dark' ? 'moon' : 'contrast');
39
45
 
40
46
  /** "Themes & Settings" sheet. */
41
- export function AppearanceSheet({ visible, colors, settings: s, systemDark, onChange, onCustomize, onClose }: Props) {
47
+ export function AppearanceSheet({ visible, colors, settings: s, systemDark, themes, onChange, onCustomize, onClose }: Props) {
48
+ const L = useLabels();
42
49
  const [menu, setMenu] = useState<null | 'turn' | 'appearance'>(null);
50
+ // Three tiles a row. Measured, because a percentage width does not count the gaps and wrapped to two.
51
+ const [gridW, setGridW] = useState(0);
52
+ const tileW = gridW ? Math.floor((gridW - GRID_GAP * 2) / 3) : '30%';
53
+ // a popup left open must not reappear the next time the sheet is shown
54
+ useEffect(() => {
55
+ if (!visible) setMenu(null);
56
+ }, [visible]);
43
57
  const dark = isDark(s, systemDark);
44
58
  const turn = TURNS.find((t) => t.id === s.pageTurn) || TURNS[0];
45
59
 
@@ -59,7 +73,7 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
59
73
  >
60
74
  <View style={styles.check}>{s.pageTurn === t.id && <Icon name="check" color={colors.text} size={20} />}</View>
61
75
  <Icon name={t.icon} color={colors.text} size={24} />
62
- <Text style={[styles.menuText, { color: colors.text }]}>{t.label}</Text>
76
+ <Text style={[styles.menuText, { color: colors.text }]}>{L[t.label] as string}</Text>
63
77
  </Pressable>
64
78
  ))
65
79
  : APPEARANCES.map((a) => (
@@ -73,7 +87,7 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
73
87
  >
74
88
  <View style={styles.check}>{s.appearance === a.id && a.key !== 'surroundings' && <Icon name="check" color={colors.text} size={20} />}</View>
75
89
  <Icon name={a.icon} color={colors.text} size={24} />
76
- <Text style={[styles.menuText, { color: colors.text }]}>{a.label}</Text>
90
+ <Text style={[styles.menuText, { color: colors.text }]}>{L[a.label] as string}</Text>
77
91
  </Pressable>
78
92
  ))}
79
93
  </View>
@@ -81,14 +95,15 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
81
95
  );
82
96
 
83
97
  return (
84
- <Sheet visible={visible} colors={colors} onClose={onClose} title="Themes & Settings" height="auto" overlay={menuView || undefined}>
98
+ <Sheet visible={visible} colors={colors} onClose={onClose} title={L.themesSettings} height="auto" overlay={menuView || undefined}>
85
99
  <View style={styles.body}>
86
100
  <View style={styles.row}>
87
101
  <View style={[styles.pill, { flex: 1, backgroundColor: colors.card }]}>
88
102
  <Pressable
89
103
  style={styles.half}
90
104
  onPress={() => onChange({ fontSize: Math.max(SIZE.min, s.fontSize - SIZE.step) })}
91
- accessibilityLabel="Smaller text"
105
+ accessibilityRole="button"
106
+ accessibilityLabel={L.smallerText}
92
107
  >
93
108
  <Text style={{ color: colors.text, fontSize: 15, fontWeight: '500' }}>A</Text>
94
109
  </Pressable>
@@ -96,16 +111,17 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
96
111
  <Pressable
97
112
  style={styles.half}
98
113
  onPress={() => onChange({ fontSize: Math.min(SIZE.max, s.fontSize + SIZE.step) })}
99
- accessibilityLabel="Larger text"
114
+ accessibilityRole="button"
115
+ accessibilityLabel={L.largerText}
100
116
  >
101
117
  <Text style={{ color: colors.text, fontSize: 26, fontWeight: '500' }}>A</Text>
102
118
  </Pressable>
103
119
  </View>
104
120
  <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={`Page turn style: ${turn.label}`}>
121
+ <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
122
  <Icon name={turn.icon} color={colors.text} size={26} />
107
123
  </Pressable>
108
- <Pressable style={[styles.half, menu === 'appearance' && { backgroundColor: colors.separator }]} onPress={() => setMenu(menu === 'appearance' ? null : 'appearance')} accessibilityLabel="Appearance">
124
+ <Pressable style={[styles.half, menu === 'appearance' && { backgroundColor: colors.separator }]} onPress={() => setMenu(menu === 'appearance' ? null : 'appearance')} accessibilityRole="button" accessibilityLabel={L.appearance}>
109
125
  <Icon name={appearanceIcon(s.appearance)} color={colors.text} size={26} />
110
126
  </Pressable>
111
127
  </View>
@@ -119,15 +135,16 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
119
135
  <Icon name="sun" color={colors.subtext} size={26} />
120
136
  </View>
121
137
 
122
- <View style={styles.grid}>
123
- {THEMES.map((t) => {
138
+ <View style={styles.grid} onLayout={(e) => setGridW(e.nativeEvent.layout.width)}>
139
+ {(themes || THEMES).map((t) => {
124
140
  const c = dark ? t.dark : t.light;
125
- const on = t.id === s.themeId;
141
+ // an id the list does not have shows as its first theme, like the page does
142
+ const on = t.id === getTheme(s.themeId, themes).id;
126
143
  return (
127
144
  <Pressable
128
145
  key={t.id}
129
146
  onPress={() => onChange({ themeId: t.id })}
130
- style={[styles.tile, { backgroundColor: c.bg, borderColor: on ? colors.text : colors.separator, borderWidth: on ? 3 : StyleSheet.hairlineWidth }]}
147
+ style={[styles.tile, { width: tileW, backgroundColor: c.bg, borderColor: on ? colors.text : colors.separator, borderWidth: on ? 3 : StyleSheet.hairlineWidth }]}
131
148
  accessibilityRole="radio"
132
149
  accessibilityState={{ selected: on }}
133
150
  >
@@ -140,7 +157,7 @@ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onCh
140
157
 
141
158
  <Pressable onPress={onCustomize} style={[styles.customize, { backgroundColor: colors.card }]} accessibilityRole="button">
142
159
  <Icon name="sliders" color={colors.text} size={22} />
143
- <Text style={{ color: colors.text, fontSize: 18, fontWeight: '600', marginStart: 10 }}>Customize</Text>
160
+ <Text style={{ color: colors.text, fontSize: 18, fontWeight: '600', marginStart: 10 }}>{L.customize}</Text>
144
161
  </Pressable>
145
162
  </View>
146
163
  </Sheet>
@@ -154,8 +171,9 @@ const styles = StyleSheet.create({
154
171
  half: { flex: 1, height: '100%', alignItems: 'center', justifyContent: 'center' },
155
172
  divider: { width: StyleSheet.hairlineWidth, height: 24 },
156
173
  brightness: { flexDirection: 'row', alignItems: 'center', marginTop: 14, marginBottom: 8, paddingHorizontal: 4 },
157
- grid: { flexDirection: 'row', flexWrap: 'wrap', gap: 10, marginTop: 6 },
158
- tile: { width: '31.6%', height: 92, borderRadius: 22, alignItems: 'center', justifyContent: 'center' },
174
+ // centred, so a last row that is not full sits in the middle
175
+ grid: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'center', gap: GRID_GAP, marginTop: 6 },
176
+ tile: { height: 92, borderRadius: 22, alignItems: 'center', justifyContent: 'center' },
159
177
  customize: { marginTop: 12, height: 58, borderRadius: 29, flexDirection: 'row', alignItems: 'center', justifyContent: 'center' },
160
178
  menu: {
161
179
  position: 'absolute', top: 80, right: 16, width: 250, borderRadius: 24, paddingVertical: 8, borderWidth: StyleSheet.hairlineWidth,
@@ -1,9 +1,18 @@
1
1
  import React, { useState } from 'react';
2
- import { Alert, FlatList, Pressable, StyleSheet, Text, View } from 'react-native';
2
+ import { Alert, FlatList, Pressable, StyleSheet, View } from 'react-native';
3
+ import { Text } from './Text';
3
4
  import { HIGHLIGHT_COLORS } from '../themes';
4
5
  import type { ChromeColors } from '../themes';
5
- import type { Bookmark, Highlight, TocItem } from '../types';
6
+ import type { Bookmark, Highlight, HighlightColor, TocItem } from '../types';
7
+ import { useLabels } from '../strings';
6
8
  import { Sheet } from './Sheet';
9
+ import { compareCfi } from '../cfiOrder';
10
+
11
+ // book order: by CFI when both have one (their offsets may be placeholders), else by offsets
12
+ function byPosition(a: Highlight, b: Highlight): number {
13
+ if (a.cfi && b.cfi) return compareCfi(a.cfi, b.cfi) || a.createdAt - b.createdAt;
14
+ return a.spine - b.spine || a.start - b.start;
15
+ }
7
16
 
8
17
  export type ContentsTab = 'contents' | 'bookmarks' | 'notes';
9
18
 
@@ -19,6 +28,8 @@ interface Props {
19
28
  pageOf: (spine: number, offset: number) => number;
20
29
  bookmarks: Bookmark[];
21
30
  highlights: Highlight[];
31
+ /** host highlight colours (name -> CSS colour) */
32
+ palette?: Record<string, string>;
22
33
  initialTab?: ContentsTab;
23
34
  onClose: () => void;
24
35
  onGoToc: (item: TocItem) => void;
@@ -28,20 +39,21 @@ interface Props {
28
39
  onDeleteHighlight: (id: string) => void;
29
40
  }
30
41
 
31
- const TABS: { id: ContentsTab; label: string }[] = [
32
- { id: 'contents', label: 'Chapters' },
33
- { id: 'bookmarks', label: 'Bookmarks' },
34
- { id: 'notes', label: 'Highlights' }
42
+ const TABS: { id: ContentsTab; label: 'chapters' | 'bookmarks' | 'highlights' }[] = [
43
+ { id: 'contents', label: 'chapters' },
44
+ { id: 'bookmarks', label: 'bookmarks' },
45
+ { id: 'notes', label: 'highlights' }
35
46
  ];
36
47
 
37
48
  /** Contents sheet: Chapters | Bookmarks | Highlights, each row with its page number. */
38
49
  export function ContentsSheet(p: Props) {
39
50
  const { colors } = p;
51
+ const L = useLabels();
40
52
  const [tab, setTab] = useState<ContentsTab>(p.initialTab || 'contents');
41
- const confirmDelete = (what: string, fn: () => void) =>
42
- Alert.alert(`Delete ${what}?`, undefined, [
43
- { text: 'Cancel', style: 'cancel' },
44
- { text: 'Delete', style: 'destructive', onPress: fn }
53
+ const confirmDelete = (title: string, fn: () => void) =>
54
+ Alert.alert(title, undefined, [
55
+ { text: L.cancel, style: 'cancel' },
56
+ { text: L.delete, style: 'destructive', onPress: fn }
45
57
  ]);
46
58
  const empty = (text: string) => <Text style={[styles.empty, { color: colors.subtext }]}>{text}</Text>;
47
59
  const rowBorder = { borderColor: colors.separator };
@@ -57,7 +69,7 @@ export function ContentsSheet(p: Props) {
57
69
  accessibilityRole="tab"
58
70
  accessibilityState={{ selected: tab === t.id }}
59
71
  >
60
- <Text style={{ color: colors.text, fontWeight: tab === t.id ? '600' : '400', fontSize: 16 }}>{t.label}</Text>
72
+ <Text style={{ color: colors.text, fontWeight: tab === t.id ? '600' : '400', fontSize: 16 }} maxFontSizeMultiplier={1.3}>{L[t.label]}</Text>
61
73
  </Pressable>
62
74
  ))}
63
75
  </View>
@@ -66,15 +78,15 @@ export function ContentsSheet(p: Props) {
66
78
  <FlatList
67
79
  data={p.toc}
68
80
  keyExtractor={(_, i) => String(i)}
69
- ListEmptyComponent={empty('No table of contents')}
81
+ ListEmptyComponent={empty(L.noToc)}
70
82
  renderItem={({ item }) => {
71
83
  const active = item.spine === p.currentSpine && !item.fragment;
72
84
  return (
73
- <Pressable onPress={() => p.onGoToc(item)} style={[styles.row, rowBorder, { paddingStart: 20 + item.level * 18 }]}>
85
+ <Pressable onPress={() => p.onGoToc(item)} accessibilityRole="button" style={[styles.row, rowBorder, { paddingStart: 20 + item.level * 18 }]}>
74
86
  <Text style={[styles.rowText, { color: active ? colors.accent : colors.text, flex: 1 }]} numberOfLines={2}>
75
87
  {item.label}
76
88
  </Text>
77
- <Text style={[styles.page, { color: colors.subtext }]}>{p.pageOf(item.spine, 0)}</Text>
89
+ <Text style={[styles.page, { color: colors.subtext }]}>{L.formatNumber(p.pageOf(item.spine, 0))}</Text>
78
90
  </Pressable>
79
91
  );
80
92
  }}
@@ -85,11 +97,11 @@ export function ContentsSheet(p: Props) {
85
97
  <FlatList
86
98
  data={p.bookmarks.slice().sort((a, b) => a.progress - b.progress)}
87
99
  keyExtractor={(b) => b.id}
88
- ListEmptyComponent={empty('No bookmarks yet. Tap the bookmark button while reading.')}
100
+ ListEmptyComponent={empty(L.noBookmarks)}
89
101
  renderItem={({ item }) => (
90
102
  <Pressable
91
103
  onPress={() => p.onGoBookmark(item)}
92
- onLongPress={() => confirmDelete('bookmark', () => p.onDeleteBookmark(item.id))}
104
+ onLongPress={() => confirmDelete(L.deleteBookmark, () => p.onDeleteBookmark(item.id))}
93
105
  style={[styles.row, rowBorder]}
94
106
  >
95
107
  <View style={{ flex: 1 }}>
@@ -98,7 +110,7 @@ export function ContentsSheet(p: Props) {
98
110
  {item.excerpt}
99
111
  </Text>
100
112
  </View>
101
- <Text style={[styles.page, { color: colors.subtext }]}>{p.pageOf(item.spine, item.offset)}</Text>
113
+ <Text style={[styles.page, { color: colors.subtext }]}>{L.formatNumber(p.pageOf(item.spine, item.offset))}</Text>
102
114
  </Pressable>
103
115
  )}
104
116
  />
@@ -106,16 +118,16 @@ export function ContentsSheet(p: Props) {
106
118
 
107
119
  {tab === 'notes' && (
108
120
  <FlatList
109
- data={p.highlights.slice().sort((a, b) => a.spine - b.spine || a.start - b.start)}
121
+ data={p.highlights.slice().sort(byPosition)}
110
122
  keyExtractor={(h) => h.id}
111
- ListEmptyComponent={empty('No highlights or notes yet. Select text to add one.')}
123
+ ListEmptyComponent={empty(L.noHighlights)}
112
124
  renderItem={({ item }) => (
113
125
  <Pressable
114
126
  onPress={() => p.onGoHighlight(item)}
115
- onLongPress={() => confirmDelete('highlight', () => p.onDeleteHighlight(item.id))}
127
+ onLongPress={() => confirmDelete(L.deleteHighlight, () => p.onDeleteHighlight(item.id))}
116
128
  style={[styles.row, rowBorder]}
117
129
  >
118
- <View style={[styles.bar, { backgroundColor: HIGHLIGHT_COLORS[item.color] }]} />
130
+ <View style={[styles.bar, { backgroundColor: p.palette?.[item.color] || HIGHLIGHT_COLORS[item.color as HighlightColor] || item.color }]} />
119
131
  <View style={{ flex: 1 }}>
120
132
  {!!item.note && <Text style={[styles.rowText, { color: colors.text, fontWeight: '600' }]}>{item.note}</Text>}
121
133
  <Text style={[styles.rowText, { color: item.note ? colors.subtext : colors.text }]} numberOfLines={3}>
@@ -123,7 +135,7 @@ export function ContentsSheet(p: Props) {
123
135
  </Text>
124
136
  {!!item.chapter && <Text style={[styles.meta, { color: colors.subtext }]}>{item.chapter}</Text>}
125
137
  </View>
126
- <Text style={[styles.page, { color: colors.subtext }]}>{p.pageOf(item.spine, item.start)}</Text>
138
+ <Text style={[styles.page, { color: colors.subtext }]}>{L.formatNumber(p.pageOf(item.spine, item.start))}</Text>
127
139
  </Pressable>
128
140
  )}
129
141
  />
@@ -1,8 +1,10 @@
1
1
  import React, { useState } from 'react';
2
- import { Pressable, ScrollView, StyleSheet, Switch, Text, View } from 'react-native';
3
- import { FONTS, getFont, serifFont } from '../themes';
2
+ import { Pressable, ScrollView, StyleSheet, Switch, View } from 'react-native';
3
+ import { Text } from './Text';
4
+ import { FONTS, serifFont } from '../themes';
4
5
  import type { ChromeColors } from '../themes';
5
- import type { ColumnsSetting, ReaderSettings, ThemeColors } from '../types';
6
+ import type { ColumnsSetting, ReaderFont, ReaderSettings, ThemeColors } from '../types';
7
+ import { useLabels } from '../strings';
6
8
  import { Icon } from './Icons';
7
9
  import type { IconName } from './Icons';
8
10
  import { Sheet } from './Sheet';
@@ -14,12 +16,13 @@ interface Props {
14
16
  page: ThemeColors;
15
17
  settings: ReaderSettings;
16
18
  sample: string;
19
+ /** fonts to choose from (default: the built-in FONTS) */
20
+ fontList?: ReaderFont[];
17
21
  onChange: (patch: Partial<ReaderSettings>) => void;
18
22
  onReset: () => void;
19
23
  onClose: () => void;
20
24
  }
21
25
 
22
- const COLUMN_LABEL: Record<string, string> = { auto: 'Auto Set', '1': 'One', '2': 'Two' };
23
26
  const GREEN = { true: '#34c759' };
24
27
 
25
28
  function Toggle(props: React.ComponentProps<typeof Switch>) {
@@ -31,11 +34,14 @@ function Toggle(props: React.ComponentProps<typeof Switch>) {
31
34
  }
32
35
 
33
36
  /** "Customize Theme" sheet: font, bold, spacing, margins, columns, justify, sound. */
34
- export function CustomizeSheet({ visible, colors, page, settings: s, sample, onChange, onReset, onClose }: Props) {
37
+ export function CustomizeSheet({ visible, colors, page, settings: s, sample, fontList = FONTS, onChange, onReset, onClose }: Props) {
38
+ const track = colors.strong ? { true: colors.strong } : GREEN;
39
+ const L = useLabels();
40
+ const COLUMN_LABEL: Record<string, string> = { auto: L.columnsAuto, '1': L.columnsOne, '2': L.columnsTwo };
35
41
  const [fonts, setFonts] = useState(false);
36
42
  const [columnsMenu, setColumnsMenu] = useState(false);
37
43
  const off = !s.customize;
38
- const font = getFont(s.fontId);
44
+ const font = fontList.find((f) => f.id === s.fontId) || fontList[0];
39
45
  const previewFont = s.fontId === 'system' ? undefined : serifFont;
40
46
  const border = { borderTopWidth: StyleSheet.hairlineWidth, borderColor: colors.separator };
41
47
 
@@ -78,7 +84,7 @@ export function CustomizeSheet({ visible, colors, page, settings: s, sample, onC
78
84
  };
79
85
 
80
86
  return (
81
- <Sheet visible={visible} colors={colors} onClose={close} closeIcon="check" title="Customize Theme" height="92%">
87
+ <Sheet visible={visible} colors={colors} onClose={close} closeIcon="check" title={L.customizeTheme} height="92%">
82
88
  <View style={[styles.preview, { backgroundColor: page.bg }]}>
83
89
  <Text style={[styles.aa, { color: page.fg, fontFamily: previewFont }]}>Aa</Text>
84
90
  <Text
@@ -97,7 +103,7 @@ export function CustomizeSheet({ visible, colors, page, settings: s, sample, onC
97
103
  <View style={[styles.group, { backgroundColor: colors.card }]}>
98
104
  {row(
99
105
  'textSize',
100
- 'Font',
106
+ L.font,
101
107
  <View style={styles.value2}>
102
108
  <Text style={{ color: colors.subtext, fontSize: 17 }}>{font.name}</Text>
103
109
  <Icon name={fonts ? 'chevronUp' : 'chevronRight'} color={colors.subtext} size={18} />
@@ -106,7 +112,7 @@ export function CustomizeSheet({ visible, colors, page, settings: s, sample, onC
106
112
  false
107
113
  )}
108
114
  {fonts &&
109
- FONTS.map((f) => (
115
+ fontList.map((f) => (
110
116
  <Pressable
111
117
  key={f.id}
112
118
  onPress={() => {
@@ -119,22 +125,22 @@ export function CustomizeSheet({ visible, colors, page, settings: s, sample, onC
119
125
  <Text style={[styles.label, { color: colors.text }]}>{f.name}</Text>
120
126
  </Pressable>
121
127
  ))}
122
- {row('bold', 'Bold Text', <Toggle value={s.bold} onValueChange={(v) => onChange({ bold: v })} trackColor={GREEN} />)}
128
+ {row('bold', L.boldText, <Toggle value={s.bold} onValueChange={(v) => onChange({ bold: v })} trackColor={track} />)}
123
129
  </View>
124
130
 
125
- <Text style={[styles.heading, { color: colors.text }]}>Accessibility & Layout Options</Text>
131
+ <Text style={[styles.heading, { color: colors.text }]}>{L.accessibilityLayout}</Text>
126
132
  <View style={[styles.group, { backgroundColor: colors.card }]}>
127
- {row('sliders', 'Customize', <Toggle value={s.customize} onValueChange={(v) => onChange({ customize: v })} trackColor={GREEN} />, undefined, false)}
128
- {sliderRow('LINE SPACING', 'lineSpacing', s.lineHeight, 1.1, 2.2, 0.05, s.lineHeight.toFixed(2), 'lineHeight')}
129
- {sliderRow('CHARACTER SPACING', 'charSpacing', s.letterSpacing, -50, 100, 5, `${s.letterSpacing}%`, 'letterSpacing')}
130
- {sliderRow('WORD SPACING', 'wordSpacing', s.wordSpacing, -50, 100, 5, `${s.wordSpacing}%`, 'wordSpacing')}
131
- {sliderRow('MARGINS', 'margins', s.margins, -50, 100, 5, `${s.margins}%`, 'margins')}
133
+ {row('sliders', L.customize, <Toggle value={s.customize} onValueChange={(v) => onChange({ customize: v })} trackColor={track} />, undefined, false)}
134
+ {sliderRow(L.lineSpacing, 'lineSpacing', s.lineHeight, 1.1, 2.2, 0.05, s.lineHeight.toFixed(2), 'lineHeight')}
135
+ {sliderRow(L.characterSpacing, 'charSpacing', s.letterSpacing, -50, 100, 5, `${s.letterSpacing}%`, 'letterSpacing')}
136
+ {sliderRow(L.wordSpacing, 'wordSpacing', s.wordSpacing, -50, 100, 5, `${s.wordSpacing}%`, 'wordSpacing')}
137
+ {sliderRow(L.margins, 'margins', s.margins, -50, 100, 5, `${s.margins}%`, 'margins')}
132
138
  </View>
133
139
 
134
140
  <View style={[styles.group, { backgroundColor: colors.card, marginTop: 16 }]}>
135
141
  {row(
136
142
  'columns',
137
- 'Columns',
143
+ L.columns,
138
144
  <View style={styles.value2}>
139
145
  <Text style={{ color: colors.subtext, fontSize: 17 }}>{COLUMN_LABEL[String(s.columns)]}</Text>
140
146
  <Icon name={columnsMenu ? 'chevronUp' : 'chevronDown'} color={colors.subtext} size={18} />
@@ -156,12 +162,12 @@ export function CustomizeSheet({ visible, colors, page, settings: s, sample, onC
156
162
  <Text style={[styles.label, { color: colors.text }]}>{COLUMN_LABEL[String(c)]}</Text>
157
163
  </Pressable>
158
164
  ))}
159
- {row('justify', 'Justify Text', <Toggle value={s.justify} onValueChange={(v) => onChange({ justify: v })} trackColor={GREEN} />)}
160
- {row(s.pageSound ? 'sound' : 'soundOff', 'Page Turn Sound', <Toggle value={s.pageSound} onValueChange={(v) => onChange({ pageSound: v })} trackColor={GREEN} />)}
165
+ {row('justify', L.justifyText, <Toggle value={s.justify} onValueChange={(v) => onChange({ justify: v })} trackColor={track} />)}
166
+ {row(s.pageSound ? 'sound' : 'soundOff', L.pageTurnSound, <Toggle value={s.pageSound} onValueChange={(v) => onChange({ pageSound: v })} trackColor={track} />)}
161
167
  </View>
162
168
 
163
- <Pressable onPress={onReset} style={[styles.reset, { backgroundColor: colors.card }]}>
164
- <Text style={{ color: '#ff3b30', fontSize: 18, fontWeight: '600' }}>Reset Theme</Text>
169
+ <Pressable onPress={onReset} style={[styles.reset, { backgroundColor: colors.card }]} accessibilityRole="button">
170
+ <Text style={{ color: '#ff3b30', fontSize: 18, fontWeight: '600' }}>{L.resetTheme}</Text>
165
171
  </Pressable>
166
172
  </ScrollView>
167
173
  </Sheet>
@@ -3,45 +3,50 @@ 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
 
9
10
  interface Props {
10
11
  highlight: Highlight;
12
+ /** colour name -> CSS colour shown as a dot (default: the built-in HIGHLIGHT_COLORS) */
13
+ palette?: Record<string, string>;
11
14
  rect: { x: number; y: number; width: number; height: number };
12
15
  screen: { width: number; height: number };
13
16
  colors: ChromeColors;
14
- onColor: (c: HighlightColor) => void;
17
+ onColor: (c: HighlightColor | (string & {})) => void;
15
18
  onToggleUnderline: () => void;
16
19
  onNote: () => void;
17
20
  onDelete: () => void;
18
21
  onDismiss: () => void;
19
22
  }
20
23
 
21
- const W = 316;
24
+ const MAX_W = 316;
22
25
  const H = 50;
23
26
 
24
27
  /** Floating glass palette shown over a highlight, like Apple Books. */
25
- export function HighlightMenu({ highlight, rect, screen, colors, onColor, onToggleUnderline, onNote, onDelete, onDismiss }: Props) {
28
+ export function HighlightMenu({ highlight, palette = HIGHLIGHT_COLORS, rect, screen, colors, onColor, onToggleUnderline, onNote, onDelete, onDismiss }: Props) {
29
+ const L = useLabels();
30
+ const W = Math.min(MAX_W, screen.width - 16); // narrow windows (split screen, foldable cover screens)
26
31
  const left = Math.max(8, Math.min(screen.width - W - 8, rect.x + rect.width / 2 - W / 2));
27
32
  const above = rect.y - H - 10;
28
33
  const top = above > 60 ? above : rect.y + rect.height + 10;
29
34
  return (
30
35
  <>
31
- <Pressable style={StyleSheet.absoluteFill} onPress={onDismiss} accessibilityLabel="Dismiss" />
32
- <Glass dark={colors.dark} background={colors.sheetGlass} border={colors.glassBorder} intensity={55} style={[styles.menu, { left, top }]}>
33
- {(Object.keys(HIGHLIGHT_COLORS) as HighlightColor[]).map((c) => (
34
- <Pressable key={c} onPress={() => onColor(c)} hitSlop={4} accessibilityLabel={`${c} highlight`}>
35
- <View style={[styles.dot, { backgroundColor: HIGHLIGHT_COLORS[c], borderWidth: highlight.color === c ? 2 : 0, borderColor: colors.text }]} />
36
+ <Pressable style={StyleSheet.absoluteFill} onPress={onDismiss} accessibilityLabel={L.dismiss} />
37
+ <Glass dark={colors.dark} background={colors.sheetGlass} border={colors.glassBorder} intensity={55} style={[styles.menu, { left, top, width: W }]}>
38
+ {Object.keys(palette).map((c) => (
39
+ <Pressable key={c} onPress={() => onColor(c)} hitSlop={8} accessibilityRole="button" accessibilityLabel={`${c} ${L.highlight}`} accessibilityState={{ selected: highlight.color === c }}>
40
+ <View style={[styles.dot, { backgroundColor: palette[c], borderWidth: highlight.color === c ? 2 : 0, borderColor: colors.text }]} />
36
41
  </Pressable>
37
42
  ))}
38
- <Pressable onPress={onToggleUnderline} hitSlop={6} accessibilityLabel="Underline">
43
+ <Pressable onPress={onToggleUnderline} hitSlop={11} accessibilityRole="button" accessibilityLabel={L.underline} accessibilityState={{ selected: highlight.style === 'underline' }}>
39
44
  <Icon name="underline" color={colors.text} size={22} active={highlight.style === 'underline'} strokeWidth={highlight.style === 'underline' ? 2.4 : 1.8} />
40
45
  </Pressable>
41
- <Pressable onPress={onNote} hitSlop={6} accessibilityLabel="Note">
46
+ <Pressable onPress={onNote} hitSlop={11} accessibilityRole="button" accessibilityLabel={L.note}>
42
47
  <Icon name="pencil" color={colors.text} size={22} />
43
48
  </Pressable>
44
- <Pressable onPress={onDelete} hitSlop={6} accessibilityLabel="Remove highlight">
49
+ <Pressable onPress={onDelete} hitSlop={11} accessibilityRole="button" accessibilityLabel={L.removeHighlight}>
45
50
  <Icon name="trash" color="#ff3b30" size={22} />
46
51
  </Pressable>
47
52
  </Glass>
@@ -52,7 +57,6 @@ export function HighlightMenu({ highlight, rect, screen, colors, onColor, onTogg
52
57
  const styles = StyleSheet.create({
53
58
  menu: {
54
59
  position: 'absolute',
55
- width: W,
56
60
  height: H,
57
61
  borderRadius: 25,
58
62
  flexDirection: 'row',
@@ -60,5 +64,5 @@ const styles = StyleSheet.create({
60
64
  justifyContent: 'space-around',
61
65
  paddingHorizontal: 12
62
66
  },
63
- dot: { width: 26, height: 26, borderRadius: 13 }
67
+ dot: { width: 28, height: 28, borderRadius: 14 }
64
68
  });
@@ -1,6 +1,8 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { KeyboardAvoidingView, Modal, Platform, Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
2
+ import { KeyboardAvoidingView, Modal, Platform, Pressable, StyleSheet, View } from 'react-native';
3
+ import { Text, TextInput } from './Text';
3
4
  import type { ChromeColors } from '../themes';
5
+ import { useLabels } from '../strings';
4
6
 
5
7
  interface Props {
6
8
  visible: boolean;
@@ -12,20 +14,21 @@ interface Props {
12
14
  }
13
15
 
14
16
  export function NoteEditor({ visible, quote, initial, colors, onSave, onCancel }: Props) {
17
+ const L = useLabels();
15
18
  const [text, setText] = useState(initial);
16
19
  useEffect(() => setText(initial), [initial, visible]);
17
20
  return (
18
- <Modal visible={visible} animationType="slide" transparent onRequestClose={onCancel}>
19
- <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={styles.wrap}>
21
+ <Modal visible={visible} animationType="slide" transparent onRequestClose={onCancel} statusBarTranslucent>
22
+ <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={styles.wrap}>
20
23
  <Pressable style={StyleSheet.absoluteFill} onPress={onCancel} />
21
24
  <View style={[styles.card, { backgroundColor: colors.sheet }]}>
22
25
  <View style={styles.head}>
23
- <Pressable onPress={onCancel} hitSlop={10}>
24
- <Text style={{ color: colors.accent, fontSize: 17 }}>Cancel</Text>
26
+ <Pressable onPress={onCancel} hitSlop={12} accessibilityRole="button">
27
+ <Text style={{ color: colors.accent, fontSize: 17 }} maxFontSizeMultiplier={1.4}>{L.cancel}</Text>
25
28
  </Pressable>
26
- <Text style={{ color: colors.text, fontSize: 17, fontWeight: '600' }}>Note</Text>
27
- <Pressable onPress={() => onSave(text.trim())} hitSlop={10}>
28
- <Text style={{ color: colors.accent, fontSize: 17, fontWeight: '600' }}>Save</Text>
29
+ <Text style={{ color: colors.text, fontSize: 17, fontWeight: '600' }} maxFontSizeMultiplier={1.4}>{L.note}</Text>
30
+ <Pressable onPress={() => onSave(text.trim())} hitSlop={12} accessibilityRole="button">
31
+ <Text style={{ color: colors.accent, fontSize: 17, fontWeight: '600' }} maxFontSizeMultiplier={1.4}>{L.save}</Text>
29
32
  </Pressable>
30
33
  </View>
31
34
  <Text numberOfLines={3} style={[styles.quote, { color: colors.subtext, borderColor: colors.accent }]}>
@@ -36,7 +39,7 @@ export function NoteEditor({ visible, quote, initial, colors, onSave, onCancel }
36
39
  multiline
37
40
  value={text}
38
41
  onChangeText={setText}
39
- placeholder="Add a note"
42
+ placeholder={L.addANote}
40
43
  placeholderTextColor={colors.subtext}
41
44
  style={[styles.input, { color: colors.text, backgroundColor: colors.card }]}
42
45
  />
@@ -1,7 +1,9 @@
1
1
  import React, { useEffect, useRef, useState } from 'react';
2
- import { FlatList, Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
2
+ import { FlatList, Keyboard, Pressable, StyleSheet, View } from 'react-native';
3
+ import { Text, TextInput } from './Text';
3
4
  import type { ChromeColors } from '../themes';
4
5
  import type { SearchResult } from '../types';
6
+ import { useLabels } from '../strings';
5
7
  import { Icon } from './Icons';
6
8
  import { Sheet } from './Sheet';
7
9
 
@@ -16,7 +18,19 @@ interface Props {
16
18
  }
17
19
 
18
20
  export function SearchSheet({ visible, colors, results, searching, onClose, onSearch, onPick }: Props) {
21
+ const L = useLabels();
19
22
  const [q, setQ] = useState('');
23
+ const [kb, setKb] = useState(0);
24
+
25
+ // the sheet sits at the bottom, so the keyboard would cover the lower results
26
+ useEffect(() => {
27
+ const show = Keyboard.addListener('keyboardDidShow', (e) => setKb(e.endCoordinates?.height || 0));
28
+ const hide = Keyboard.addListener('keyboardDidHide', () => setKb(0));
29
+ return () => {
30
+ show.remove();
31
+ hide.remove();
32
+ };
33
+ }, []);
20
34
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
21
35
 
22
36
  useEffect(() => {
@@ -27,13 +41,14 @@ export function SearchSheet({ visible, colors, results, searching, onClose, onSe
27
41
  }, [q]);
28
42
 
29
43
  return (
30
- <Sheet visible={visible} colors={colors} onClose={onClose} height="85%" title="Search">
44
+ <Sheet visible={visible} colors={colors} onClose={onClose} height="85%" title={L.search}>
31
45
  <View style={[styles.field, { backgroundColor: colors.card }]}>
32
46
  <Icon name="search" color={colors.subtext} size={20} />
33
47
  <TextInput
34
48
  value={q}
35
49
  onChangeText={setQ}
36
- placeholder="Search in book"
50
+ placeholder={L.searchInBook}
51
+ accessibilityLabel={L.searchInBook}
37
52
  placeholderTextColor={colors.subtext}
38
53
  style={[styles.input, { color: colors.text }]}
39
54
  autoCorrect={false}
@@ -45,16 +60,18 @@ export function SearchSheet({ visible, colors, results, searching, onClose, onSe
45
60
  <FlatList
46
61
  data={results}
47
62
  keyboardShouldPersistTaps="handled"
63
+ keyboardDismissMode="on-drag"
64
+ contentContainerStyle={{ paddingBottom: kb }}
48
65
  keyExtractor={(_, i) => String(i)}
49
66
  ListHeaderComponent={
50
67
  q.trim().length >= 2 ? (
51
68
  <Text style={[styles.count, { color: colors.subtext }]}>
52
- {searching ? 'Searching...' : `${results.length}${results.length >= 500 ? '+' : ''} results`}
69
+ {searching ? L.searching : results.length === 0 ? L.noResults : `${L.formatNumber(results.length)}${results.length >= 500 ? '+' : ''}`}
53
70
  </Text>
54
71
  ) : null
55
72
  }
56
73
  renderItem={({ item }) => (
57
- <Pressable onPress={() => onPick(item)} style={[styles.row, { borderColor: colors.separator }]}>
74
+ <Pressable onPress={() => onPick(item)} style={[styles.row, { borderColor: colors.separator }]} accessibilityRole="button">
58
75
  <Text style={[styles.chapter, { color: colors.accent }]} numberOfLines={1}>
59
76
  {item.chapter}
60
77
  </Text>