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,246 @@
1
+ import React from 'react';
2
+ import Svg, { Circle, G, Line, Path, Rect } from 'react-native-svg';
3
+
4
+ /**
5
+ * Vector icon set (24 x 24 grid, rounded strokes). Every icon takes the colour it is drawn in, so it follows the
6
+ * theme (light / dark / any page colour). Some icons carry state: `active` fills or closes them
7
+ * (bookmark, rotation lock, line guide).
8
+ */
9
+ export type IconName =
10
+ | 'close' | 'check' | 'chevronRight' | 'chevronUp' | 'chevronDown'
11
+ | 'list' | 'search' | 'textSize' | 'share' | 'bookmark' | 'rotationLock' | 'lineGuide' | 'undo'
12
+ | 'sun' | 'sunLow' | 'moon' | 'contrast'
13
+ | 'pageSlide' | 'pageCurl' | 'pageFade' | 'pageScroll'
14
+ | 'sliders' | 'lineSpacing' | 'charSpacing' | 'wordSpacing' | 'margins' | 'columns' | 'bold' | 'justify'
15
+ | 'trash' | 'pencil' | 'underline' | 'highlighter' | 'sound' | 'soundOff';
16
+
17
+ interface Props {
18
+ name: IconName;
19
+ color: string;
20
+ size?: number;
21
+ /** filled / closed state for bookmark, rotation lock, line guide */
22
+ active?: boolean;
23
+ strokeWidth?: number;
24
+ }
25
+
26
+ const RAYS = [0, 45, 90, 135, 180, 225, 270, 315].map((deg) => {
27
+ const a = (deg * Math.PI) / 180;
28
+ return { x1: 12 + 6.6 * Math.cos(a), y1: 12 + 6.6 * Math.sin(a), x2: 12 + 9.2 * Math.cos(a), y2: 12 + 9.2 * Math.sin(a) };
29
+ });
30
+
31
+ export function Icon({ name, color, size = 24, active = false, strokeWidth = 1.8 }: Props) {
32
+ const p = { stroke: color, strokeWidth, strokeLinecap: 'round' as const, strokeLinejoin: 'round' as const, fill: 'none' };
33
+ let body: React.ReactNode = null;
34
+
35
+ switch (name) {
36
+ case 'close':
37
+ body = <Path d="M6 6 L18 18 M18 6 L6 18" {...p} />;
38
+ break;
39
+ case 'check':
40
+ body = <Path d="M5 12.5 L10 17.5 L19 7" {...p} />;
41
+ break;
42
+ case 'chevronRight':
43
+ body = <Path d="M9 5.5 L15.5 12 L9 18.5" {...p} />;
44
+ break;
45
+ case 'chevronUp':
46
+ body = <Path d="M5.5 15 L12 8.5 L18.5 15" {...p} />;
47
+ break;
48
+ case 'chevronDown':
49
+ body = <Path d="M5.5 9 L12 15.5 L18.5 9" {...p} />;
50
+ break;
51
+ case 'list':
52
+ body = (
53
+ <G>
54
+ {[7, 12, 17].map((y) => (
55
+ <G key={y}>
56
+ <Circle cx={4.8} cy={y} r={1.25} fill={color} />
57
+ <Path d={`M9 ${y} H20`} {...p} />
58
+ </G>
59
+ ))}
60
+ </G>
61
+ );
62
+ break;
63
+ case 'search':
64
+ body = (
65
+ <G>
66
+ <Circle cx={10.8} cy={10.8} r={6.3} {...p} />
67
+ <Path d="M15.6 15.6 L20.5 20.5" {...p} />
68
+ </G>
69
+ );
70
+ break;
71
+ case 'textSize':
72
+ body = (
73
+ <G>
74
+ <Path d="M2.8 18 L6.3 9.2 L9.8 18 M4.1 14.9 H8.5" {...p} />
75
+ <Path d="M11.6 18 L16.6 5.6 L21.6 18 M13.5 13.6 H19.7" {...p} />
76
+ </G>
77
+ );
78
+ break;
79
+ case 'share':
80
+ body = (
81
+ <G>
82
+ <Path d="M8.5 10 H7 A1.7 1.7 0 0 0 5.3 11.7 V19 A1.7 1.7 0 0 0 7 20.7 H17 A1.7 1.7 0 0 0 18.7 19 V11.7 A1.7 1.7 0 0 0 17 10 H15.5" {...p} />
83
+ <Path d="M12 14.5 V3.5 M8.2 7.3 L12 3.5 L15.8 7.3" {...p} />
84
+ </G>
85
+ );
86
+ break;
87
+ case 'bookmark':
88
+ body = (
89
+ <Path
90
+ d="M7.2 3.8 H16.8 A1.2 1.2 0 0 1 18 5 V20.2 L12 16.2 L6 20.2 V5 A1.2 1.2 0 0 1 7.2 3.8 Z"
91
+ {...p}
92
+ fill={active ? color : 'none'}
93
+ />
94
+ );
95
+ break;
96
+ case 'rotationLock':
97
+ body = (
98
+ <G>
99
+ <Path d="M20.2 13 A8.2 8.2 0 1 1 17 5.9" {...p} />
100
+ <Path d="M17.2 2.8 V6.2 H13.8" {...p} />
101
+ <Rect x={9} y={11.2} width={6} height={5} rx={1.2} {...p} fill={active ? color : 'none'} />
102
+ <Path d={active ? 'M10.4 11.2 V10 A1.6 1.6 0 0 1 13.6 10 V11.2' : 'M10.4 11.2 V9.9 A1.6 1.6 0 0 1 13.6 9.9'} {...p} />
103
+ </G>
104
+ );
105
+ break;
106
+ case 'lineGuide':
107
+ body = (
108
+ <G>
109
+ <Path d="M4 6.2 H20 M4 17.8 H20" {...p} opacity={0.5} />
110
+ <Rect x={2.8} y={9.2} width={18.4} height={5.6} rx={2.8} {...p} fill={active ? color : 'none'} fillOpacity={active ? 0.28 : 0} />
111
+ </G>
112
+ );
113
+ break;
114
+ case 'undo':
115
+ body = <Path d="M8.5 6 L4 10.5 L8.5 15 M4.5 10.5 H14.5 A5 5 0 0 1 14.5 20.5 H11" {...p} />;
116
+ break;
117
+ case 'sun':
118
+ body = (
119
+ <G>
120
+ <Circle cx={12} cy={12} r={3.9} {...p} />
121
+ {RAYS.map((r, i) => (
122
+ <Line key={i} x1={r.x1} y1={r.y1} x2={r.x2} y2={r.y2} {...p} />
123
+ ))}
124
+ </G>
125
+ );
126
+ break;
127
+ case 'sunLow':
128
+ body = (
129
+ <G>
130
+ <Circle cx={12} cy={12} r={2.4} {...p} />
131
+ {RAYS.map((r, i) => (
132
+ <Line key={i} x1={12 + (r.x1 - 12) * 0.8} y1={12 + (r.y1 - 12) * 0.8} x2={12 + (r.x2 - 12) * 0.62} y2={12 + (r.y2 - 12) * 0.62} {...p} />
133
+ ))}
134
+ </G>
135
+ );
136
+ break;
137
+ case 'moon':
138
+ body = <Path d="M20 14.2 A8.4 8.4 0 1 1 9.8 4 A6.6 6.6 0 0 0 20 14.2 Z" {...p} />;
139
+ break;
140
+ case 'contrast':
141
+ body = (
142
+ <G>
143
+ <Circle cx={12} cy={12} r={8.2} {...p} />
144
+ <Path d="M12 3.8 A8.2 8.2 0 0 1 12 20.2 Z" fill={color} stroke={color} strokeWidth={1} />
145
+ </G>
146
+ );
147
+ break;
148
+ case 'pageSlide':
149
+ body = (
150
+ <G>
151
+ <Path d="M9 5.2 H5.2 A1.9 1.9 0 0 0 3.3 7.1 V17.9 A1.9 1.9 0 0 0 5.2 19.8 H9" {...p} opacity={0.55} />
152
+ <Rect x={8} y={3.2} width={12.7} height={16.6} rx={2.4} {...p} />
153
+ </G>
154
+ );
155
+ break;
156
+ case 'pageCurl':
157
+ body = (
158
+ <G>
159
+ <Path d="M6.7 3.5 H14.5 L20 9 V18.6 A1.9 1.9 0 0 1 18.1 20.5 H6.7 A1.9 1.9 0 0 1 4.8 18.6 V5.4 A1.9 1.9 0 0 1 6.7 3.5 Z" {...p} />
160
+ <Path d="M14.5 3.5 V7.4 A1.6 1.6 0 0 0 16.1 9 H20" {...p} />
161
+ </G>
162
+ );
163
+ break;
164
+ case 'pageFade':
165
+ body = <Path d="M13.2 2.8 L5.2 13.2 H11 L10.2 21.2 L18.8 10.4 H13 Z" {...p} />;
166
+ break;
167
+ case 'pageScroll':
168
+ body = (
169
+ <G>
170
+ <Rect x={5} y={3} width={14} height={18} rx={2.4} {...p} />
171
+ <Path d="M9.4 9.6 L12 7 L14.6 9.6 M9.4 14.4 L12 17 L14.6 14.4" {...p} />
172
+ </G>
173
+ );
174
+ break;
175
+ case 'sliders':
176
+ body = (
177
+ <G>
178
+ <Path d="M3.5 8 H9.2 M14.8 8 H20.5 M3.5 16 H14.2 M19.8 16 H20.5" {...p} />
179
+ <Circle cx={12} cy={8} r={2.8} {...p} />
180
+ <Circle cx={17} cy={16} r={2.8} {...p} />
181
+ </G>
182
+ );
183
+ break;
184
+ case 'lineSpacing':
185
+ body = <Path d="M10.5 6.5 H20.5 M10.5 12 H20.5 M10.5 17.5 H20.5 M5 4.5 V19.5 M2.9 6.6 L5 4.5 L7.1 6.6 M2.9 17.4 L5 19.5 L7.1 17.4" {...p} />;
186
+ break;
187
+ case 'charSpacing':
188
+ body = <Path d="M7.6 13.6 L12 3.8 L16.4 13.6 M9.2 10.4 H14.8 M3.8 19.2 H20.2 M6.2 16.9 L3.8 19.2 L6.2 21.5 M17.8 16.9 L20.2 19.2 L17.8 21.5" {...p} />;
189
+ break;
190
+ case 'wordSpacing':
191
+ body = (
192
+ <G>
193
+ <Rect x={2.8} y={4.5} width={7} height={4.2} rx={1.2} {...p} />
194
+ <Rect x={14.2} y={4.5} width={7} height={4.2} rx={1.2} {...p} />
195
+ <Path d="M3.8 15.2 H20.2 M6.2 12.9 L3.8 15.2 L6.2 17.5 M17.8 12.9 L20.2 15.2 L17.8 17.5" {...p} />
196
+ </G>
197
+ );
198
+ break;
199
+ case 'margins':
200
+ body = (
201
+ <G>
202
+ <Rect x={3.8} y={3} width={16.4} height={18} rx={2.4} {...p} />
203
+ <Path d="M8 7 V17 M16 7 V17" {...p} />
204
+ </G>
205
+ );
206
+ break;
207
+ case 'columns':
208
+ body = (
209
+ <G>
210
+ <Rect x={3.5} y={4} width={7.6} height={16} rx={1.8} {...p} />
211
+ <Rect x={12.9} y={4} width={7.6} height={16} rx={1.8} {...p} />
212
+ </G>
213
+ );
214
+ break;
215
+ case 'bold':
216
+ body = <Path d="M8 4.6 V19.4 M8 4.6 H13 A3.6 3.6 0 0 1 13 11.8 H8 M8 11.8 H14 A3.8 3.8 0 0 1 14 19.4 H8" {...p} strokeWidth={strokeWidth + 0.5} />;
217
+ break;
218
+ case 'justify':
219
+ body = <Path d="M4 6 H20 M4 10 H20 M4 14 H20 M4 18 H20" {...p} />;
220
+ break;
221
+ case 'trash':
222
+ body = <Path d="M4.5 7 H19.5 M9.3 7 V4.6 H14.7 V7 M6.6 7 L7.6 19.6 A1.2 1.2 0 0 0 8.8 20.7 H15.2 A1.2 1.2 0 0 0 16.4 19.6 L17.4 7 M10.2 10.8 V16.4 M13.8 10.8 V16.4" {...p} />;
223
+ break;
224
+ case 'pencil':
225
+ body = <Path d="M4 20 L5.2 15.2 L16.2 4.2 A2.2 2.2 0 0 1 19.4 7.4 L8.4 18.4 Z M14 6.4 L17.2 9.6" {...p} />;
226
+ break;
227
+ case 'highlighter':
228
+ body = <Path d="M14.2 4.6 L19.4 9.8 L10.6 18.6 L5.4 13.4 Z M5.4 13.4 L4.2 17.6 L7.6 18.6 M3.5 21 H12.5" {...p} />;
229
+ break;
230
+ case 'underline':
231
+ body = <Path d="M7.4 4.4 V11 A4.6 4.6 0 0 0 16.6 11 V4.4 M5 20 H19" {...p} />;
232
+ break;
233
+ case 'sound':
234
+ body = <Path d="M4 9.5 H7.5 L12.5 5.2 V18.8 L7.5 14.5 H4 Z M16 9 A4.2 4.2 0 0 1 16 15 M18.6 6.6 A7.6 7.6 0 0 1 18.6 17.4" {...p} />;
235
+ break;
236
+ case 'soundOff':
237
+ body = <Path d="M4 9.5 H7.5 L12.5 5.2 V18.8 L7.5 14.5 H4 Z M16.2 9.4 L21 14.6 M21 9.4 L16.2 14.6" {...p} />;
238
+ break;
239
+ }
240
+
241
+ return (
242
+ <Svg width={size} height={size} viewBox="0 0 24 24">
243
+ {body}
244
+ </Svg>
245
+ );
246
+ }
@@ -0,0 +1,87 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { PanResponder, StyleSheet, View } from 'react-native';
3
+
4
+ export type DimLevel = 'high' | 'medium' | 'low' | 'none';
5
+
6
+ /** Opacity of the page-coloured veil over everything except the guide line. */
7
+ export const DIM_ALPHA: Record<DimLevel, number> = { high: 0.86, medium: 0.62, low: 0.36, none: 0 };
8
+
9
+ function rgba(hex: string, a: number): string {
10
+ const v = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
11
+ return `rgba(${v[0]},${v[1]},${v[2]},${a})`;
12
+ }
13
+
14
+ interface Props {
15
+ /** page background colour (#rrggbb) */
16
+ bg: string;
17
+ dark: boolean;
18
+ dim: DimLevel;
19
+ /** height of one line of text */
20
+ lineHeight: number;
21
+ /** vertical range the guide may move in */
22
+ minY: number;
23
+ maxY: number;
24
+ }
25
+
26
+ /**
27
+ * Line Guide: dims the page except for one line that can be dragged up and down.
28
+ * The veil ignores touches, so page turns and taps still reach the book.
29
+ */
30
+ export function LineGuide({ bg, dark, dim, lineHeight, minY, maxY }: Props) {
31
+ const h = Math.round(lineHeight) + 14;
32
+ const [y, setY] = useState(minY + 40);
33
+ const state = useRef({ start: 0, minY, maxY, h });
34
+ state.current.minY = minY;
35
+ state.current.maxY = maxY;
36
+ state.current.h = h;
37
+ const yRef = useRef(y);
38
+ yRef.current = y;
39
+
40
+ const pan = useRef(
41
+ PanResponder.create({
42
+ onStartShouldSetPanResponder: () => true,
43
+ onMoveShouldSetPanResponder: () => true,
44
+ onPanResponderGrant: () => {
45
+ state.current.start = yRef.current;
46
+ },
47
+ onPanResponderMove: (_e, g) => {
48
+ const s = state.current;
49
+ setY(Math.max(s.minY, Math.min(s.maxY - s.h, s.start + g.dy)));
50
+ }
51
+ })
52
+ ).current;
53
+
54
+ const veil = rgba(bg, DIM_ALPHA[dim]);
55
+ return (
56
+ <View style={StyleSheet.absoluteFill} pointerEvents="box-none">
57
+ {dim !== 'none' && (
58
+ <>
59
+ <View pointerEvents="none" style={[styles.veil, { top: 0, height: y, backgroundColor: veil }]} />
60
+ <View pointerEvents="none" style={[styles.veil, { top: y + h, bottom: 0, backgroundColor: veil }]} />
61
+ </>
62
+ )}
63
+ <View
64
+ {...pan.panHandlers}
65
+ style={[
66
+ styles.band,
67
+ {
68
+ top: y,
69
+ height: h,
70
+ borderRadius: h / 2,
71
+ borderColor: dark ? 'rgba(255,255,255,0.35)' : 'rgba(0,0,0,0.22)',
72
+ backgroundColor: dark ? 'rgba(255,255,255,0.05)' : 'rgba(0,0,0,0.03)'
73
+ }
74
+ ]}
75
+ accessibilityLabel="Line guide"
76
+ />
77
+ </View>
78
+ );
79
+ }
80
+
81
+ const styles = StyleSheet.create({
82
+ veil: { position: 'absolute', left: 0, right: 0 },
83
+ band: {
84
+ position: 'absolute', left: 10, right: 10, borderWidth: StyleSheet.hairlineWidth * 2,
85
+ shadowColor: '#000', shadowOpacity: 0.35, shadowRadius: 8, shadowOffset: { width: 0, height: 3 }, elevation: 6
86
+ }
87
+ });
@@ -0,0 +1,57 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { KeyboardAvoidingView, Modal, Platform, Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
3
+ import type { ChromeColors } from '../themes';
4
+ import { useLabels } from '../strings';
5
+
6
+ interface Props {
7
+ visible: boolean;
8
+ quote: string;
9
+ initial: string;
10
+ colors: ChromeColors;
11
+ onSave: (note: string) => void;
12
+ onCancel: () => void;
13
+ }
14
+
15
+ export function NoteEditor({ visible, quote, initial, colors, onSave, onCancel }: Props) {
16
+ const L = useLabels();
17
+ const [text, setText] = useState(initial);
18
+ useEffect(() => setText(initial), [initial, visible]);
19
+ return (
20
+ <Modal visible={visible} animationType="slide" transparent onRequestClose={onCancel} statusBarTranslucent>
21
+ <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={styles.wrap}>
22
+ <Pressable style={StyleSheet.absoluteFill} onPress={onCancel} />
23
+ <View style={[styles.card, { backgroundColor: colors.sheet }]}>
24
+ <View style={styles.head}>
25
+ <Pressable onPress={onCancel} hitSlop={12} accessibilityRole="button">
26
+ <Text style={{ color: colors.accent, fontSize: 17 }} maxFontSizeMultiplier={1.4}>{L.cancel}</Text>
27
+ </Pressable>
28
+ <Text style={{ color: colors.text, fontSize: 17, fontWeight: '600' }} maxFontSizeMultiplier={1.4}>{L.note}</Text>
29
+ <Pressable onPress={() => onSave(text.trim())} hitSlop={12} accessibilityRole="button">
30
+ <Text style={{ color: colors.accent, fontSize: 17, fontWeight: '600' }} maxFontSizeMultiplier={1.4}>{L.save}</Text>
31
+ </Pressable>
32
+ </View>
33
+ <Text numberOfLines={3} style={[styles.quote, { color: colors.subtext, borderColor: colors.accent }]}>
34
+ {quote}
35
+ </Text>
36
+ <TextInput
37
+ autoFocus
38
+ multiline
39
+ value={text}
40
+ onChangeText={setText}
41
+ placeholder={L.addANote}
42
+ placeholderTextColor={colors.subtext}
43
+ style={[styles.input, { color: colors.text, backgroundColor: colors.card }]}
44
+ />
45
+ </View>
46
+ </KeyboardAvoidingView>
47
+ </Modal>
48
+ );
49
+ }
50
+
51
+ const styles = StyleSheet.create({
52
+ wrap: { flex: 1, justifyContent: 'flex-end', backgroundColor: 'rgba(0,0,0,0.35)' },
53
+ card: { borderTopLeftRadius: 14, borderTopRightRadius: 14, padding: 16 },
54
+ head: { flexDirection: 'row', justifyContent: 'space-between', marginBottom: 12 },
55
+ quote: { fontSize: 14, borderStartWidth: 3, paddingStart: 10, marginBottom: 12, fontStyle: 'italic' },
56
+ input: { minHeight: 110, maxHeight: 220, borderRadius: 10, padding: 12, fontSize: 16, textAlignVertical: 'top' }
57
+ });
@@ -0,0 +1,78 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { PanResponder, StyleSheet, View } from 'react-native';
3
+
4
+ interface Props {
5
+ value: number; // 0..1
6
+ onScrub?: (v: number) => void;
7
+ onComplete: (v: number) => void;
8
+ color: string;
9
+ track: string;
10
+ thumbColor?: string;
11
+ /** hide the thumb for a flat progress bar */
12
+ noThumb?: boolean;
13
+ rtl?: boolean;
14
+ }
15
+
16
+ /** Minimal horizontal slider (no native dependency). */
17
+ export function Scrubber({ value, onScrub, onComplete, color, track, thumbColor, noThumb, rtl }: Props) {
18
+ const [width, setWidth] = useState(1);
19
+ const [drag, setDrag] = useState<number | null>(null);
20
+ const latest = useRef({ width: 1, onScrub, onComplete, rtl });
21
+ latest.current = { width, onScrub, onComplete, rtl };
22
+ const startX = useRef(0);
23
+
24
+ const toValue = (x: number) => {
25
+ const { width: w, rtl: r } = latest.current;
26
+ const v = Math.max(0, Math.min(1, x / w));
27
+ return r ? 1 - v : v;
28
+ };
29
+
30
+ const pan = useRef(
31
+ PanResponder.create({
32
+ onStartShouldSetPanResponder: () => true,
33
+ onMoveShouldSetPanResponder: () => true,
34
+ onPanResponderTerminationRequest: () => false,
35
+ onPanResponderGrant: (e) => {
36
+ startX.current = e.nativeEvent.locationX;
37
+ const v = toValue(startX.current);
38
+ setDrag(v);
39
+ latest.current.onScrub?.(v);
40
+ },
41
+ onPanResponderMove: (_e, g) => {
42
+ const v = toValue(startX.current + g.dx);
43
+ setDrag(v);
44
+ latest.current.onScrub?.(v);
45
+ },
46
+ onPanResponderRelease: (_e, g) => {
47
+ const v = toValue(startX.current + g.dx);
48
+ setDrag(null);
49
+ latest.current.onComplete(v);
50
+ }
51
+ })
52
+ ).current;
53
+
54
+ const shown = drag ?? value;
55
+ const frac = rtl ? 1 - shown : shown;
56
+ return (
57
+ <View style={styles.hit} onLayout={(e) => setWidth(e.nativeEvent.layout.width)} {...pan.panHandlers}>
58
+ <View style={[styles.track, { backgroundColor: track }]} pointerEvents="none">
59
+ <View style={{ height: 4, backgroundColor: color, width: `${frac * 100}%` }} />
60
+ </View>
61
+ {!noThumb && (
62
+ <View
63
+ pointerEvents="none"
64
+ style={[styles.thumb, { backgroundColor: thumbColor || color, left: Math.max(0, Math.min(width - 28, frac * (width - 28))) }]}
65
+ />
66
+ )}
67
+ </View>
68
+ );
69
+ }
70
+
71
+ const styles = StyleSheet.create({
72
+ hit: { height: 40, justifyContent: 'center' },
73
+ track: { height: 4, borderRadius: 2, overflow: 'hidden', flexDirection: 'row' },
74
+ thumb: {
75
+ position: 'absolute', width: 28, height: 28, borderRadius: 14, top: 6,
76
+ shadowColor: '#000', shadowOpacity: 0.3, shadowRadius: 3, shadowOffset: { width: 0, height: 1 }, elevation: 3
77
+ }
78
+ });
@@ -0,0 +1,95 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { FlatList, Keyboard, Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
3
+ import type { ChromeColors } from '../themes';
4
+ import type { SearchResult } from '../types';
5
+ import { useLabels } from '../strings';
6
+ import { Icon } from './Icons';
7
+ import { Sheet } from './Sheet';
8
+
9
+ interface Props {
10
+ visible: boolean;
11
+ colors: ChromeColors;
12
+ results: SearchResult[];
13
+ searching: boolean;
14
+ onClose: () => void;
15
+ onSearch: (query: string) => void;
16
+ onPick: (r: SearchResult) => void;
17
+ }
18
+
19
+ export function SearchSheet({ visible, colors, results, searching, onClose, onSearch, onPick }: Props) {
20
+ const L = useLabels();
21
+ const [q, setQ] = useState('');
22
+ const [kb, setKb] = useState(0);
23
+
24
+ // the sheet sits at the bottom, so the keyboard would cover the lower results
25
+ useEffect(() => {
26
+ const show = Keyboard.addListener('keyboardDidShow', (e) => setKb(e.endCoordinates?.height || 0));
27
+ const hide = Keyboard.addListener('keyboardDidHide', () => setKb(0));
28
+ return () => {
29
+ show.remove();
30
+ hide.remove();
31
+ };
32
+ }, []);
33
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
34
+
35
+ useEffect(() => {
36
+ clearTimeout(timer.current);
37
+ timer.current = setTimeout(() => onSearch(q), 350);
38
+ return () => clearTimeout(timer.current);
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, [q]);
41
+
42
+ return (
43
+ <Sheet visible={visible} colors={colors} onClose={onClose} height="85%" title={L.search}>
44
+ <View style={[styles.field, { backgroundColor: colors.card }]}>
45
+ <Icon name="search" color={colors.subtext} size={20} />
46
+ <TextInput
47
+ value={q}
48
+ onChangeText={setQ}
49
+ placeholder={L.searchInBook}
50
+ accessibilityLabel={L.searchInBook}
51
+ placeholderTextColor={colors.subtext}
52
+ style={[styles.input, { color: colors.text }]}
53
+ autoCorrect={false}
54
+ returnKeyType="search"
55
+ onSubmitEditing={() => onSearch(q)}
56
+ clearButtonMode="while-editing"
57
+ />
58
+ </View>
59
+ <FlatList
60
+ data={results}
61
+ keyboardShouldPersistTaps="handled"
62
+ keyboardDismissMode="on-drag"
63
+ contentContainerStyle={{ paddingBottom: kb }}
64
+ keyExtractor={(_, i) => String(i)}
65
+ ListHeaderComponent={
66
+ q.trim().length >= 2 ? (
67
+ <Text style={[styles.count, { color: colors.subtext }]}>
68
+ {searching ? L.searching : results.length === 0 ? L.noResults : `${L.formatNumber(results.length)}${results.length >= 500 ? '+' : ''}`}
69
+ </Text>
70
+ ) : null
71
+ }
72
+ renderItem={({ item }) => (
73
+ <Pressable onPress={() => onPick(item)} style={[styles.row, { borderColor: colors.separator }]} accessibilityRole="button">
74
+ <Text style={[styles.chapter, { color: colors.accent }]} numberOfLines={1}>
75
+ {item.chapter}
76
+ </Text>
77
+ <Text style={{ color: colors.text, fontSize: 15, lineHeight: 21 }} numberOfLines={3}>
78
+ {item.before}
79
+ <Text style={{ fontWeight: '700', backgroundColor: 'rgba(255,214,10,0.45)' }}>{item.match}</Text>
80
+ {item.after}
81
+ </Text>
82
+ </Pressable>
83
+ )}
84
+ />
85
+ </Sheet>
86
+ );
87
+ }
88
+
89
+ const styles = StyleSheet.create({
90
+ field: { flexDirection: 'row', alignItems: 'center', marginHorizontal: 16, marginBottom: 8, paddingHorizontal: 10, borderRadius: 10, height: 38 },
91
+ input: { flex: 1, marginStart: 6, fontSize: 16, paddingVertical: 0 },
92
+ count: { paddingHorizontal: 20, paddingVertical: 8, fontSize: 13 },
93
+ row: { paddingVertical: 12, paddingHorizontal: 20, borderBottomWidth: StyleSheet.hairlineWidth },
94
+ chapter: { fontSize: 12, fontWeight: '600', marginBottom: 3 }
95
+ });
@@ -0,0 +1,71 @@
1
+ import React from 'react';
2
+ import { Modal, Pressable, StyleSheet, Text, View } from 'react-native';
3
+ import type { ViewStyle } from 'react-native';
4
+ import type { ChromeColors } from '../themes';
5
+ import { Glass } from './Glass';
6
+ import { useLabels } from '../strings';
7
+ import { Icon } from './Icons';
8
+
9
+ interface Props {
10
+ visible: boolean;
11
+ title?: string;
12
+ subtitle?: string;
13
+ colors: ChromeColors;
14
+ height?: ViewStyle['height'];
15
+ /** 'x' puts a glass close button on the left (Themes, Search); 'check' puts a solid check on the right (Contents, Customize) */
16
+ closeIcon?: 'x' | 'check';
17
+ onClose: () => void;
18
+ children: React.ReactNode;
19
+ /** rendered above the content, e.g. popup menus */
20
+ overlay?: React.ReactNode;
21
+ }
22
+
23
+ /** Rounded frosted-glass sheet: the book stays faintly visible behind it. */
24
+ export function Sheet({ visible, title, subtitle, colors, height = '70%', closeIcon = 'x', onClose, children, overlay }: Props) {
25
+ const L = useLabels();
26
+ const button =
27
+ closeIcon === 'check' ? (
28
+ <Pressable onPress={onClose} hitSlop={10} style={[styles.circle, { backgroundColor: colors.dark ? '#ffffff' : '#000000' }]} accessibilityRole="button" accessibilityLabel={L.done}>
29
+ <Icon name="check" color={colors.dark ? '#000000' : '#ffffff'} size={24} strokeWidth={2.2} />
30
+ </Pressable>
31
+ ) : (
32
+ <Pressable onPress={onClose} hitSlop={10} accessibilityRole="button" accessibilityLabel={L.close}>
33
+ <Glass dark={colors.dark} background={colors.glass} border={colors.glassBorder} style={styles.circle}>
34
+ <Icon name="close" color={colors.text} size={22} />
35
+ </Glass>
36
+ </Pressable>
37
+ );
38
+
39
+ return (
40
+ <Modal visible={visible} transparent animationType="slide" onRequestClose={onClose} statusBarTranslucent>
41
+ <Pressable style={styles.backdrop} onPress={onClose} />
42
+ <Glass dark={colors.dark} background={colors.sheetGlass} border={colors.glassBorder} intensity={70} style={[styles.sheet, { height }]}>
43
+ <View style={styles.header}>
44
+ {closeIcon === 'x' && button}
45
+ <View style={styles.titleBox} pointerEvents="none">
46
+ {!!title && (
47
+ <Text style={[styles.title, { color: colors.text }]} numberOfLines={1} maxFontSizeMultiplier={1.3} accessibilityRole="header">
48
+ {title}
49
+ </Text>
50
+ )}
51
+ {!!subtitle && <Text style={[styles.subtitle, { color: colors.text }]}>{subtitle}</Text>}
52
+ </View>
53
+ <View style={{ flex: 1 }} />
54
+ {closeIcon === 'check' && button}
55
+ </View>
56
+ {children}
57
+ {overlay}
58
+ </Glass>
59
+ </Modal>
60
+ );
61
+ }
62
+
63
+ const styles = StyleSheet.create({
64
+ backdrop: { flex: 1, backgroundColor: 'rgba(0,0,0,0.18)' },
65
+ sheet: { borderTopLeftRadius: 34, borderTopRightRadius: 34, paddingTop: 12 },
66
+ header: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16, minHeight: 52, marginBottom: 6 },
67
+ circle: { width: 44, height: 44, borderRadius: 22, alignItems: 'center', justifyContent: 'center' },
68
+ titleBox: { position: 'absolute', left: 70, right: 70, alignItems: 'center' },
69
+ title: { fontSize: 17, fontWeight: '600' },
70
+ subtitle: { fontSize: 17, marginTop: 14 }
71
+ });
@@ -0,0 +1,30 @@
1
+ import React, { useRef } from 'react';
2
+ import { Scrubber } from './Scrubber';
3
+
4
+ interface Props {
5
+ value: number;
6
+ min: number;
7
+ max: number;
8
+ step: number;
9
+ onChange: (v: number) => void;
10
+ color: string;
11
+ track: string;
12
+ thumbColor?: string;
13
+ }
14
+
15
+ const round = (v: number, step: number) => Math.round(v / step) * step;
16
+
17
+ /** Value slider on top of Scrubber; emits only when the stepped value changes. */
18
+ export function Slider({ value, min, max, step, onChange, color, track, thumbColor }: Props) {
19
+ const last = useRef(value);
20
+ const toValue = (f: number) => +(round(min + f * (max - min), step)).toFixed(4);
21
+ const emit = (f: number) => {
22
+ const v = toValue(f);
23
+ if (v !== last.current) {
24
+ last.current = v;
25
+ onChange(v);
26
+ }
27
+ };
28
+ last.current = value;
29
+ return <Scrubber value={(value - min) / (max - min)} color={color} track={track} thumbColor={thumbColor} onScrub={emit} onComplete={emit} />;
30
+ }