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