aksos-react-native-epub-reader 0.0.0-stage → 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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +351 -2
  3. package/lib/EpubReader.d.ts +76 -0
  4. package/lib/EpubReader.js +284 -0
  5. package/lib/EpubReaderView.d.ts +31 -0
  6. package/lib/EpubReaderView.js +599 -0
  7. package/lib/assets/page-turn-1.wav +0 -0
  8. package/lib/assets/page-turn-2.wav +0 -0
  9. package/lib/assets/page-turn-3.wav +0 -0
  10. package/lib/assets/page-turn-4.wav +0 -0
  11. package/lib/engine/html.d.ts +1 -0
  12. package/lib/engine/html.js +5 -0
  13. package/lib/index.d.ts +9 -0
  14. package/lib/index.js +34 -0
  15. package/lib/sound.d.ts +1 -0
  16. package/lib/sound.js +71 -0
  17. package/lib/strings.d.ts +94 -0
  18. package/lib/strings.js +96 -0
  19. package/lib/themes.d.ts +60 -0
  20. package/lib/themes.js +166 -0
  21. package/lib/types.d.ts +149 -0
  22. package/lib/types.js +2 -0
  23. package/lib/ui/AppearanceSheet.d.ts +15 -0
  24. package/lib/ui/AppearanceSheet.js +134 -0
  25. package/lib/ui/ContentsSheet.d.ts +27 -0
  26. package/lib/ui/ContentsSheet.js +89 -0
  27. package/lib/ui/CustomizeSheet.d.ts +16 -0
  28. package/lib/ui/CustomizeSheet.js +141 -0
  29. package/lib/ui/Glass.d.ts +15 -0
  30. package/lib/ui/Glass.js +27 -0
  31. package/lib/ui/HighlightMenu.d.ts +25 -0
  32. package/lib/ui/HighlightMenu.js +45 -0
  33. package/lib/ui/Icons.d.ts +17 -0
  34. package/lib/ui/Icons.js +193 -0
  35. package/lib/ui/LineGuide.d.ts +21 -0
  36. package/lib/ui/LineGuide.js +92 -0
  37. package/lib/ui/NoteEditor.d.ts +12 -0
  38. package/lib/ui/NoteEditor.js +63 -0
  39. package/lib/ui/Scrubber.d.ts +15 -0
  40. package/lib/ui/Scrubber.js +86 -0
  41. package/lib/ui/SearchSheet.d.ts +14 -0
  42. package/lib/ui/SearchSheet.js +79 -0
  43. package/lib/ui/Sheet.d.ts +19 -0
  44. package/lib/ui/Sheet.js +40 -0
  45. package/lib/ui/Slider.d.ts +14 -0
  46. package/lib/ui/Slider.js +53 -0
  47. package/package.json +76 -6
  48. package/src/EpubReader.tsx +356 -0
  49. package/src/EpubReaderView.tsx +865 -0
  50. package/src/assets/page-turn-1.wav +0 -0
  51. package/src/assets/page-turn-2.wav +0 -0
  52. package/src/assets/page-turn-3.wav +0 -0
  53. package/src/assets/page-turn-4.wav +0 -0
  54. package/src/engine/html.ts +2 -0
  55. package/src/engine/reader.js +2047 -0
  56. package/src/index.ts +9 -0
  57. package/src/sound.ts +66 -0
  58. package/src/strings.ts +187 -0
  59. package/src/themes.ts +188 -0
  60. package/src/types.ts +154 -0
  61. package/src/ui/AppearanceSheet.tsx +176 -0
  62. package/src/ui/ContentsSheet.tsx +146 -0
  63. package/src/ui/CustomizeSheet.tsx +191 -0
  64. package/src/ui/Glass.tsx +37 -0
  65. package/src/ui/HighlightMenu.tsx +66 -0
  66. package/src/ui/Icons.tsx +246 -0
  67. package/src/ui/LineGuide.tsx +87 -0
  68. package/src/ui/NoteEditor.tsx +57 -0
  69. package/src/ui/Scrubber.tsx +78 -0
  70. package/src/ui/SearchSheet.tsx +95 -0
  71. package/src/ui/Sheet.tsx +71 -0
  72. package/src/ui/Slider.tsx +30 -0
@@ -0,0 +1,176 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Pressable, StyleSheet, Text, View } from 'react-native';
3
+ import { isDark, serifFont, THEMES } from '../themes';
4
+ import type { ChromeColors } from '../themes';
5
+ import type { Appearance, PageTurn, ReaderSettings } from '../types';
6
+ import { useLabels } from '../strings';
7
+ import type { ReaderLabels } from '../strings';
8
+ import { Icon } from './Icons';
9
+ import type { IconName } from './Icons';
10
+ import { Sheet } from './Sheet';
11
+ import { Slider } from './Slider';
12
+
13
+ interface Props {
14
+ visible: boolean;
15
+ colors: ChromeColors;
16
+ settings: ReaderSettings;
17
+ systemDark: boolean;
18
+ onChange: (patch: Partial<ReaderSettings>) => void;
19
+ onCustomize: () => void;
20
+ onClose: () => void;
21
+ }
22
+
23
+ const SIZE = { min: 12, max: 40, step: 2 };
24
+
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' }
30
+ ];
31
+
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' }
37
+ ];
38
+
39
+ /** Icon of the current appearance choice: the button always shows the state it is in. */
40
+ const appearanceIcon = (a: Appearance): IconName => (a === 'light' ? 'sun' : a === 'dark' ? 'moon' : 'contrast');
41
+
42
+ /** "Themes & Settings" sheet. */
43
+ export function AppearanceSheet({ visible, colors, settings: s, systemDark, onChange, onCustomize, onClose }: Props) {
44
+ const L = useLabels();
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]);
50
+ const dark = isDark(s, systemDark);
51
+ const turn = TURNS.find((t) => t.id === s.pageTurn) || TURNS[0];
52
+
53
+ const menuView = menu && (
54
+ <>
55
+ <Pressable style={StyleSheet.absoluteFill} onPress={() => setMenu(null)} />
56
+ <View style={[styles.menu, { backgroundColor: colors.dark ? '#4a4742' : '#ffffff', borderColor: colors.glassBorder }]}>
57
+ {menu === 'turn'
58
+ ? TURNS.map((t) => (
59
+ <Pressable
60
+ key={t.id}
61
+ style={styles.menuItem}
62
+ onPress={() => {
63
+ onChange({ pageTurn: t.id });
64
+ setMenu(null);
65
+ }}
66
+ >
67
+ <View style={styles.check}>{s.pageTurn === t.id && <Icon name="check" color={colors.text} size={20} />}</View>
68
+ <Icon name={t.icon} color={colors.text} size={24} />
69
+ <Text style={[styles.menuText, { color: colors.text }]}>{L[t.label] as string}</Text>
70
+ </Pressable>
71
+ ))
72
+ : APPEARANCES.map((a) => (
73
+ <Pressable
74
+ key={a.key}
75
+ style={styles.menuItem}
76
+ onPress={() => {
77
+ onChange({ appearance: a.id });
78
+ setMenu(null);
79
+ }}
80
+ >
81
+ <View style={styles.check}>{s.appearance === a.id && a.key !== 'surroundings' && <Icon name="check" color={colors.text} size={20} />}</View>
82
+ <Icon name={a.icon} color={colors.text} size={24} />
83
+ <Text style={[styles.menuText, { color: colors.text }]}>{L[a.label] as string}</Text>
84
+ </Pressable>
85
+ ))}
86
+ </View>
87
+ </>
88
+ );
89
+
90
+ return (
91
+ <Sheet visible={visible} colors={colors} onClose={onClose} title={L.themesSettings} height="auto" overlay={menuView || undefined}>
92
+ <View style={styles.body}>
93
+ <View style={styles.row}>
94
+ <View style={[styles.pill, { flex: 1, backgroundColor: colors.card }]}>
95
+ <Pressable
96
+ style={styles.half}
97
+ onPress={() => onChange({ fontSize: Math.max(SIZE.min, s.fontSize - SIZE.step) })}
98
+ accessibilityRole="button"
99
+ accessibilityLabel={L.smallerText}
100
+ >
101
+ <Text style={{ color: colors.text, fontSize: 15, fontWeight: '500' }}>A</Text>
102
+ </Pressable>
103
+ <View style={[styles.divider, { backgroundColor: colors.separator }]} />
104
+ <Pressable
105
+ style={styles.half}
106
+ onPress={() => onChange({ fontSize: Math.min(SIZE.max, s.fontSize + SIZE.step) })}
107
+ accessibilityRole="button"
108
+ accessibilityLabel={L.largerText}
109
+ >
110
+ <Text style={{ color: colors.text, fontSize: 26, fontWeight: '500' }}>A</Text>
111
+ </Pressable>
112
+ </View>
113
+ <View style={[styles.pill, { width: 150, backgroundColor: colors.card }]}>
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}`}>
115
+ <Icon name={turn.icon} color={colors.text} size={26} />
116
+ </Pressable>
117
+ <Pressable style={[styles.half, menu === 'appearance' && { backgroundColor: colors.separator }]} onPress={() => setMenu(menu === 'appearance' ? null : 'appearance')} accessibilityRole="button" accessibilityLabel={L.appearance}>
118
+ <Icon name={appearanceIcon(s.appearance)} color={colors.text} size={26} />
119
+ </Pressable>
120
+ </View>
121
+ </View>
122
+
123
+ <View style={styles.brightness}>
124
+ <Icon name="sunLow" color={colors.subtext} size={20} />
125
+ <View style={{ flex: 1, marginHorizontal: 10 }}>
126
+ <Slider value={s.brightness} min={0.3} max={1} step={0.01} onChange={(v) => onChange({ brightness: v })} color={colors.text} track={colors.separator} thumbColor="#ffffff" />
127
+ </View>
128
+ <Icon name="sun" color={colors.subtext} size={26} />
129
+ </View>
130
+
131
+ <View style={styles.grid}>
132
+ {THEMES.map((t) => {
133
+ const c = dark ? t.dark : t.light;
134
+ const on = t.id === s.themeId;
135
+ return (
136
+ <Pressable
137
+ key={t.id}
138
+ onPress={() => onChange({ themeId: t.id })}
139
+ style={[styles.tile, { backgroundColor: c.bg, borderColor: on ? colors.text : colors.separator, borderWidth: on ? 3 : StyleSheet.hairlineWidth }]}
140
+ accessibilityRole="radio"
141
+ accessibilityState={{ selected: on }}
142
+ >
143
+ <Text style={{ color: c.fg, fontSize: 30, fontFamily: serifFont, fontWeight: t.bold ? '800' : '400' }}>Aa</Text>
144
+ <Text style={{ color: c.fg, fontSize: 15, fontFamily: serifFont, fontWeight: t.bold ? '700' : '400' }}>{t.name}</Text>
145
+ </Pressable>
146
+ );
147
+ })}
148
+ </View>
149
+
150
+ <Pressable onPress={onCustomize} style={[styles.customize, { backgroundColor: colors.card }]} accessibilityRole="button">
151
+ <Icon name="sliders" color={colors.text} size={22} />
152
+ <Text style={{ color: colors.text, fontSize: 18, fontWeight: '600', marginStart: 10 }}>{L.customize}</Text>
153
+ </Pressable>
154
+ </View>
155
+ </Sheet>
156
+ );
157
+ }
158
+
159
+ const styles = StyleSheet.create({
160
+ body: { paddingHorizontal: 16, paddingBottom: 28 },
161
+ row: { flexDirection: 'row', gap: 10 },
162
+ pill: { height: 58, borderRadius: 29, flexDirection: 'row', alignItems: 'center', overflow: 'hidden' },
163
+ half: { flex: 1, height: '100%', alignItems: 'center', justifyContent: 'center' },
164
+ divider: { width: StyleSheet.hairlineWidth, height: 24 },
165
+ brightness: { flexDirection: 'row', alignItems: 'center', marginTop: 14, marginBottom: 8, paddingHorizontal: 4 },
166
+ grid: { flexDirection: 'row', flexWrap: 'wrap', gap: 10, marginTop: 6 },
167
+ tile: { width: '31.6%', height: 92, borderRadius: 22, alignItems: 'center', justifyContent: 'center' },
168
+ customize: { marginTop: 12, height: 58, borderRadius: 29, flexDirection: 'row', alignItems: 'center', justifyContent: 'center' },
169
+ menu: {
170
+ position: 'absolute', top: 80, right: 16, width: 250, borderRadius: 24, paddingVertical: 8, borderWidth: StyleSheet.hairlineWidth,
171
+ shadowColor: '#000', shadowOpacity: 0.3, shadowRadius: 16, shadowOffset: { width: 0, height: 6 }, elevation: 12
172
+ },
173
+ menuItem: { flexDirection: 'row', alignItems: 'center', paddingVertical: 12, paddingHorizontal: 14 },
174
+ check: { width: 26, alignItems: 'center' },
175
+ menuText: { fontSize: 18, marginStart: 14, flexShrink: 1 }
176
+ });
@@ -0,0 +1,146 @@
1
+ import React, { useState } from 'react';
2
+ import { Alert, FlatList, Pressable, StyleSheet, Text, View } from 'react-native';
3
+ import { HIGHLIGHT_COLORS } from '../themes';
4
+ import type { ChromeColors } from '../themes';
5
+ import type { Bookmark, Highlight, TocItem } from '../types';
6
+ import { useLabels } from '../strings';
7
+ import { Sheet } from './Sheet';
8
+
9
+ export type ContentsTab = 'contents' | 'bookmarks' | 'notes';
10
+
11
+ interface Props {
12
+ visible: boolean;
13
+ colors: ChromeColors;
14
+ title: string;
15
+ /** e.g. "Page 100 of 219" */
16
+ subtitle: string;
17
+ toc: TocItem[];
18
+ currentSpine: number;
19
+ /** estimated page number in the whole book for a spine item + character offset */
20
+ pageOf: (spine: number, offset: number) => number;
21
+ bookmarks: Bookmark[];
22
+ highlights: Highlight[];
23
+ initialTab?: ContentsTab;
24
+ onClose: () => void;
25
+ onGoToc: (item: TocItem) => void;
26
+ onGoBookmark: (b: Bookmark) => void;
27
+ onGoHighlight: (h: Highlight) => void;
28
+ onDeleteBookmark: (id: string) => void;
29
+ onDeleteHighlight: (id: string) => void;
30
+ }
31
+
32
+ const TABS: { id: ContentsTab; label: 'chapters' | 'bookmarks' | 'highlights' }[] = [
33
+ { id: 'contents', label: 'chapters' },
34
+ { id: 'bookmarks', label: 'bookmarks' },
35
+ { id: 'notes', label: 'highlights' }
36
+ ];
37
+
38
+ /** Contents sheet: Chapters | Bookmarks | Highlights, each row with its page number. */
39
+ export function ContentsSheet(p: Props) {
40
+ const { colors } = p;
41
+ const L = useLabels();
42
+ const [tab, setTab] = useState<ContentsTab>(p.initialTab || 'contents');
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 }
47
+ ]);
48
+ const empty = (text: string) => <Text style={[styles.empty, { color: colors.subtext }]}>{text}</Text>;
49
+ const rowBorder = { borderColor: colors.separator };
50
+
51
+ return (
52
+ <Sheet visible={p.visible} colors={colors} onClose={p.onClose} closeIcon="check" title={p.title} subtitle={p.subtitle} height="90%">
53
+ <View style={[styles.segment, { backgroundColor: colors.card }]}>
54
+ {TABS.map((t) => (
55
+ <Pressable
56
+ key={t.id}
57
+ onPress={() => setTab(t.id)}
58
+ style={[styles.segItem, tab === t.id && { backgroundColor: colors.dark ? 'rgba(255,255,255,0.22)' : '#ffffff' }]}
59
+ accessibilityRole="tab"
60
+ accessibilityState={{ selected: tab === t.id }}
61
+ >
62
+ <Text style={{ color: colors.text, fontWeight: tab === t.id ? '600' : '400', fontSize: 16 }} maxFontSizeMultiplier={1.3}>{L[t.label]}</Text>
63
+ </Pressable>
64
+ ))}
65
+ </View>
66
+
67
+ {tab === 'contents' && (
68
+ <FlatList
69
+ data={p.toc}
70
+ keyExtractor={(_, i) => String(i)}
71
+ ListEmptyComponent={empty(L.noToc)}
72
+ renderItem={({ item }) => {
73
+ const active = item.spine === p.currentSpine && !item.fragment;
74
+ return (
75
+ <Pressable onPress={() => p.onGoToc(item)} accessibilityRole="button" style={[styles.row, rowBorder, { paddingStart: 20 + item.level * 18 }]}>
76
+ <Text style={[styles.rowText, { color: active ? colors.accent : colors.text, flex: 1 }]} numberOfLines={2}>
77
+ {item.label}
78
+ </Text>
79
+ <Text style={[styles.page, { color: colors.subtext }]}>{L.formatNumber(p.pageOf(item.spine, 0))}</Text>
80
+ </Pressable>
81
+ );
82
+ }}
83
+ />
84
+ )}
85
+
86
+ {tab === 'bookmarks' && (
87
+ <FlatList
88
+ data={p.bookmarks.slice().sort((a, b) => a.progress - b.progress)}
89
+ keyExtractor={(b) => b.id}
90
+ ListEmptyComponent={empty(L.noBookmarks)}
91
+ renderItem={({ item }) => (
92
+ <Pressable
93
+ onPress={() => p.onGoBookmark(item)}
94
+ onLongPress={() => confirmDelete(L.deleteBookmark, () => p.onDeleteBookmark(item.id))}
95
+ style={[styles.row, rowBorder]}
96
+ >
97
+ <View style={{ flex: 1 }}>
98
+ <Text style={[styles.meta, { color: colors.accent }]}>{item.chapter}</Text>
99
+ <Text style={[styles.rowText, { color: colors.text }]} numberOfLines={2}>
100
+ {item.excerpt}
101
+ </Text>
102
+ </View>
103
+ <Text style={[styles.page, { color: colors.subtext }]}>{L.formatNumber(p.pageOf(item.spine, item.offset))}</Text>
104
+ </Pressable>
105
+ )}
106
+ />
107
+ )}
108
+
109
+ {tab === 'notes' && (
110
+ <FlatList
111
+ data={p.highlights.slice().sort((a, b) => a.spine - b.spine || a.start - b.start)}
112
+ keyExtractor={(h) => h.id}
113
+ ListEmptyComponent={empty(L.noHighlights)}
114
+ renderItem={({ item }) => (
115
+ <Pressable
116
+ onPress={() => p.onGoHighlight(item)}
117
+ onLongPress={() => confirmDelete(L.deleteHighlight, () => p.onDeleteHighlight(item.id))}
118
+ style={[styles.row, rowBorder]}
119
+ >
120
+ <View style={[styles.bar, { backgroundColor: HIGHLIGHT_COLORS[item.color] }]} />
121
+ <View style={{ flex: 1 }}>
122
+ {!!item.note && <Text style={[styles.rowText, { color: colors.text, fontWeight: '600' }]}>{item.note}</Text>}
123
+ <Text style={[styles.rowText, { color: item.note ? colors.subtext : colors.text }]} numberOfLines={3}>
124
+ {item.text}
125
+ </Text>
126
+ {!!item.chapter && <Text style={[styles.meta, { color: colors.subtext }]}>{item.chapter}</Text>}
127
+ </View>
128
+ <Text style={[styles.page, { color: colors.subtext }]}>{L.formatNumber(p.pageOf(item.spine, item.start))}</Text>
129
+ </Pressable>
130
+ )}
131
+ />
132
+ )}
133
+ </Sheet>
134
+ );
135
+ }
136
+
137
+ const styles = StyleSheet.create({
138
+ segment: { flexDirection: 'row', marginHorizontal: 16, marginTop: 34, marginBottom: 6, borderRadius: 18, padding: 3 },
139
+ segItem: { flex: 1, alignItems: 'center', paddingVertical: 8, borderRadius: 15 },
140
+ row: { flexDirection: 'row', alignItems: 'center', paddingVertical: 17, paddingHorizontal: 20, marginHorizontal: 0, borderBottomWidth: StyleSheet.hairlineWidth },
141
+ rowText: { fontSize: 18, lineHeight: 24 },
142
+ page: { fontSize: 18, marginStart: 12, minWidth: 34, textAlign: 'right' },
143
+ meta: { fontSize: 13, marginBottom: 2, fontWeight: '600' },
144
+ bar: { width: 3, alignSelf: 'stretch', borderRadius: 2, marginEnd: 12 },
145
+ empty: { textAlign: 'center', padding: 32, fontSize: 16 }
146
+ });
@@ -0,0 +1,191 @@
1
+ import React, { useState } from 'react';
2
+ import { Pressable, ScrollView, StyleSheet, Switch, Text, View } from 'react-native';
3
+ import { FONTS, getFont, serifFont } from '../themes';
4
+ import type { ChromeColors } from '../themes';
5
+ import type { ColumnsSetting, ReaderSettings, ThemeColors } from '../types';
6
+ import { useLabels } from '../strings';
7
+ import { Icon } from './Icons';
8
+ import type { IconName } from './Icons';
9
+ import { Sheet } from './Sheet';
10
+ import { Slider } from './Slider';
11
+
12
+ interface Props {
13
+ visible: boolean;
14
+ colors: ChromeColors;
15
+ page: ThemeColors;
16
+ settings: ReaderSettings;
17
+ sample: string;
18
+ onChange: (patch: Partial<ReaderSettings>) => void;
19
+ onReset: () => void;
20
+ onClose: () => void;
21
+ }
22
+
23
+ const GREEN = { true: '#34c759' };
24
+
25
+ function Toggle(props: React.ComponentProps<typeof Switch>) {
26
+ return (
27
+ <View style={styles.toggleBox}>
28
+ <Switch {...props} />
29
+ </View>
30
+ );
31
+ }
32
+
33
+ /** "Customize Theme" sheet: font, bold, spacing, margins, columns, justify, sound. */
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 };
37
+ const [fonts, setFonts] = useState(false);
38
+ const [columnsMenu, setColumnsMenu] = useState(false);
39
+ const off = !s.customize;
40
+ const font = getFont(s.fontId);
41
+ const previewFont = s.fontId === 'system' ? undefined : serifFont;
42
+ const border = { borderTopWidth: StyleSheet.hairlineWidth, borderColor: colors.separator };
43
+
44
+ const sliderRow = (label: string, icon: IconName, value: number, min: number, max: number, step: number, show: string, key: keyof ReaderSettings) => (
45
+ <View style={[styles.sliderBlock, border, off && styles.dim]} pointerEvents={off ? 'none' : 'auto'}>
46
+ <Text style={[styles.caption, { color: colors.subtext }]}>{label}</Text>
47
+ <View style={styles.sliderRow}>
48
+ <Icon name={icon} color={colors.text} size={24} />
49
+ <View style={{ flex: 1, marginHorizontal: 12 }}>
50
+ <Slider value={value} min={min} max={max} step={step} onChange={(v) => onChange({ [key]: v } as Partial<ReaderSettings>)} color={colors.text} track={colors.separator} thumbColor="#ffffff" />
51
+ </View>
52
+ <Text style={[styles.value, { color: colors.subtext }]}>{show}</Text>
53
+ </View>
54
+ </View>
55
+ );
56
+
57
+ const row = (icon: IconName, label: string, right: React.ReactNode, onPress?: () => void, top = true, iconActive = false) => {
58
+ const content = (
59
+ <>
60
+ <View style={styles.rowIcon}>
61
+ <Icon name={icon} color={colors.text} size={22} active={iconActive} />
62
+ </View>
63
+ <Text style={[styles.label, { color: colors.text }]}>{label}</Text>
64
+ {right}
65
+ </>
66
+ );
67
+ return onPress ? (
68
+ <Pressable style={[styles.line, top && border]} onPress={onPress}>
69
+ {content}
70
+ </Pressable>
71
+ ) : (
72
+ <View style={[styles.line, top && border]}>{content}</View>
73
+ );
74
+ };
75
+
76
+ const close = () => {
77
+ setFonts(false);
78
+ setColumnsMenu(false);
79
+ onClose();
80
+ };
81
+
82
+ return (
83
+ <Sheet visible={visible} colors={colors} onClose={close} closeIcon="check" title={L.customizeTheme} height="92%">
84
+ <View style={[styles.preview, { backgroundColor: page.bg }]}>
85
+ <Text style={[styles.aa, { color: page.fg, fontFamily: previewFont }]}>Aa</Text>
86
+ <Text
87
+ numberOfLines={4}
88
+ style={{
89
+ color: page.fg, fontFamily: previewFont, fontSize: Math.min(s.fontSize, 22),
90
+ lineHeight: Math.min(s.fontSize, 22) * (s.customize ? s.lineHeight : 1.5),
91
+ fontWeight: s.bold ? '700' : '400', textAlign: s.justify ? 'justify' : 'auto'
92
+ }}
93
+ >
94
+ {sample}
95
+ </Text>
96
+ </View>
97
+
98
+ <ScrollView contentContainerStyle={styles.pad}>
99
+ <View style={[styles.group, { backgroundColor: colors.card }]}>
100
+ {row(
101
+ 'textSize',
102
+ L.font,
103
+ <View style={styles.value2}>
104
+ <Text style={{ color: colors.subtext, fontSize: 17 }}>{font.name}</Text>
105
+ <Icon name={fonts ? 'chevronUp' : 'chevronRight'} color={colors.subtext} size={18} />
106
+ </View>,
107
+ () => setFonts((v) => !v),
108
+ false
109
+ )}
110
+ {fonts &&
111
+ FONTS.map((f) => (
112
+ <Pressable
113
+ key={f.id}
114
+ onPress={() => {
115
+ onChange({ fontId: f.id });
116
+ setFonts(false);
117
+ }}
118
+ style={[styles.line, border]}
119
+ >
120
+ <View style={styles.check}>{s.fontId === f.id && <Icon name="check" color={colors.text} size={20} />}</View>
121
+ <Text style={[styles.label, { color: colors.text }]}>{f.name}</Text>
122
+ </Pressable>
123
+ ))}
124
+ {row('bold', L.boldText, <Toggle value={s.bold} onValueChange={(v) => onChange({ bold: v })} trackColor={GREEN} />)}
125
+ </View>
126
+
127
+ <Text style={[styles.heading, { color: colors.text }]}>{L.accessibilityLayout}</Text>
128
+ <View style={[styles.group, { backgroundColor: colors.card }]}>
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')}
134
+ </View>
135
+
136
+ <View style={[styles.group, { backgroundColor: colors.card, marginTop: 16 }]}>
137
+ {row(
138
+ 'columns',
139
+ L.columns,
140
+ <View style={styles.value2}>
141
+ <Text style={{ color: colors.subtext, fontSize: 17 }}>{COLUMN_LABEL[String(s.columns)]}</Text>
142
+ <Icon name={columnsMenu ? 'chevronUp' : 'chevronDown'} color={colors.subtext} size={18} />
143
+ </View>,
144
+ () => setColumnsMenu((v) => !v),
145
+ false
146
+ )}
147
+ {columnsMenu &&
148
+ (['auto', 1, 2] as ColumnsSetting[]).map((c) => (
149
+ <Pressable
150
+ key={String(c)}
151
+ style={[styles.line, border]}
152
+ onPress={() => {
153
+ onChange({ columns: c });
154
+ setColumnsMenu(false);
155
+ }}
156
+ >
157
+ <View style={styles.check}>{s.columns === c && <Icon name="check" color={colors.text} size={20} />}</View>
158
+ <Text style={[styles.label, { color: colors.text }]}>{COLUMN_LABEL[String(c)]}</Text>
159
+ </Pressable>
160
+ ))}
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} />)}
163
+ </View>
164
+
165
+ <Pressable onPress={onReset} style={[styles.reset, { backgroundColor: colors.card }]} accessibilityRole="button">
166
+ <Text style={{ color: '#ff3b30', fontSize: 18, fontWeight: '600' }}>{L.resetTheme}</Text>
167
+ </Pressable>
168
+ </ScrollView>
169
+ </Sheet>
170
+ );
171
+ }
172
+
173
+ const styles = StyleSheet.create({
174
+ preview: { paddingHorizontal: 22, paddingTop: 12, paddingBottom: 18, marginBottom: 10 },
175
+ aa: { fontSize: 34, textAlign: 'right', marginBottom: 6 },
176
+ pad: { paddingHorizontal: 16, paddingBottom: 40 },
177
+ group: { borderRadius: 24, overflow: 'hidden' },
178
+ line: { flexDirection: 'row', alignItems: 'center', minHeight: 56, paddingHorizontal: 18 },
179
+ rowIcon: { width: 34, height: 28, alignItems: 'flex-start', justifyContent: 'center' },
180
+ toggleBox: { height: 31, minWidth: 51, alignItems: 'center', justifyContent: 'center' },
181
+ label: { flex: 1, fontSize: 18, lineHeight: 24 },
182
+ check: { width: 34, height: 24, justifyContent: 'center' },
183
+ value2: { flexDirection: 'row', alignItems: 'center', gap: 4 },
184
+ heading: { fontSize: 22, fontWeight: '700', marginTop: 26, marginBottom: 10, marginStart: 4 },
185
+ sliderBlock: { paddingHorizontal: 18, paddingTop: 10, paddingBottom: 6 },
186
+ dim: { opacity: 0.45 },
187
+ caption: { fontSize: 14, marginBottom: 2 },
188
+ sliderRow: { flexDirection: 'row', alignItems: 'center' },
189
+ value: { width: 50, textAlign: 'right', fontSize: 17, lineHeight: 22 },
190
+ reset: { marginTop: 18, height: 58, borderRadius: 29, alignItems: 'center', justifyContent: 'center' }
191
+ });
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { StyleSheet, View } from 'react-native';
3
+ import type { StyleProp, ViewStyle } from 'react-native';
4
+
5
+ // expo-blur is optional: with it the controls are frosted glass, without it they are plain translucent.
6
+ let BlurView: React.ComponentType<any> | null = null;
7
+ try {
8
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
9
+ BlurView = require('expo-blur').BlurView;
10
+ } catch {
11
+ BlurView = null;
12
+ }
13
+
14
+ interface Props {
15
+ style?: StyleProp<ViewStyle>;
16
+ /** translucent tint drawn over the blur (use ChromeColors.glass or .sheetGlass) */
17
+ background: string;
18
+ border?: string;
19
+ dark: boolean;
20
+ /** blur strength 0..100 */
21
+ intensity?: number;
22
+ children?: React.ReactNode;
23
+ }
24
+
25
+ /** Frosted glass surface: blurs the book behind it so reading is not interrupted. */
26
+ export function Glass({ style, background, border, dark, intensity = 38, children }: Props) {
27
+ const base: ViewStyle = { overflow: 'hidden', borderWidth: border ? StyleSheet.hairlineWidth : 0, borderColor: border };
28
+ if (BlurView) {
29
+ return (
30
+ <BlurView intensity={intensity} tint={dark ? 'dark' : 'light'} style={[base, style]}>
31
+ <View style={[StyleSheet.absoluteFill, { backgroundColor: background }]} pointerEvents="none" />
32
+ {children}
33
+ </BlurView>
34
+ );
35
+ }
36
+ return <View style={[base, { backgroundColor: background }, style]}>{children}</View>;
37
+ }
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+ import { Pressable, StyleSheet, View } from 'react-native';
3
+ import { HIGHLIGHT_COLORS } from '../themes';
4
+ import type { ChromeColors } from '../themes';
5
+ import type { Highlight, HighlightColor } from '../types';
6
+ import { useLabels } from '../strings';
7
+ import { Glass } from './Glass';
8
+ import { Icon } from './Icons';
9
+
10
+ interface Props {
11
+ highlight: Highlight;
12
+ rect: { x: number; y: number; width: number; height: number };
13
+ screen: { width: number; height: number };
14
+ colors: ChromeColors;
15
+ onColor: (c: HighlightColor) => void;
16
+ onToggleUnderline: () => void;
17
+ onNote: () => void;
18
+ onDelete: () => void;
19
+ onDismiss: () => void;
20
+ }
21
+
22
+ const MAX_W = 316;
23
+ const H = 50;
24
+
25
+ /** Floating glass palette shown over a highlight, like Apple Books. */
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)
29
+ const left = Math.max(8, Math.min(screen.width - W - 8, rect.x + rect.width / 2 - W / 2));
30
+ const above = rect.y - H - 10;
31
+ const top = above > 60 ? above : rect.y + rect.height + 10;
32
+ return (
33
+ <>
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 }]}>
36
+ {(Object.keys(HIGHLIGHT_COLORS) as HighlightColor[]).map((c) => (
37
+ <Pressable key={c} onPress={() => onColor(c)} hitSlop={8} accessibilityRole="button" accessibilityLabel={`${c} ${L.highlight}`} accessibilityState={{ selected: highlight.color === c }}>
38
+ <View style={[styles.dot, { backgroundColor: HIGHLIGHT_COLORS[c], borderWidth: highlight.color === c ? 2 : 0, borderColor: colors.text }]} />
39
+ </Pressable>
40
+ ))}
41
+ <Pressable onPress={onToggleUnderline} hitSlop={11} accessibilityRole="button" accessibilityLabel={L.underline} accessibilityState={{ selected: highlight.style === 'underline' }}>
42
+ <Icon name="underline" color={colors.text} size={22} active={highlight.style === 'underline'} strokeWidth={highlight.style === 'underline' ? 2.4 : 1.8} />
43
+ </Pressable>
44
+ <Pressable onPress={onNote} hitSlop={11} accessibilityRole="button" accessibilityLabel={L.note}>
45
+ <Icon name="pencil" color={colors.text} size={22} />
46
+ </Pressable>
47
+ <Pressable onPress={onDelete} hitSlop={11} accessibilityRole="button" accessibilityLabel={L.removeHighlight}>
48
+ <Icon name="trash" color="#ff3b30" size={22} />
49
+ </Pressable>
50
+ </Glass>
51
+ </>
52
+ );
53
+ }
54
+
55
+ const styles = StyleSheet.create({
56
+ menu: {
57
+ position: 'absolute',
58
+ height: H,
59
+ borderRadius: 25,
60
+ flexDirection: 'row',
61
+ alignItems: 'center',
62
+ justifyContent: 'space-around',
63
+ paddingHorizontal: 12
64
+ },
65
+ dot: { width: 28, height: 28, borderRadius: 14 }
66
+ });