aksos-react-native-epub-reader 0.1.1 → 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 (44) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +158 -13
  3. package/lib/EpubReader.d.ts +47 -9
  4. package/lib/EpubReader.js +69 -16
  5. package/lib/EpubReaderView.d.ts +27 -2
  6. package/lib/EpubReaderView.js +38 -32
  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 +1 -1
  11. package/lib/themes.d.ts +24 -6
  12. package/lib/themes.js +80 -20
  13. package/lib/types.d.ts +66 -1
  14. package/lib/ui/AppearanceSheet.d.ts +4 -2
  15. package/lib/ui/AppearanceSheet.js +20 -13
  16. package/lib/ui/ContentsSheet.d.ts +2 -0
  17. package/lib/ui/ContentsSheet.js +21 -13
  18. package/lib/ui/CustomizeSheet.d.ts +4 -2
  19. package/lib/ui/CustomizeSheet.js +20 -18
  20. package/lib/ui/HighlightMenu.d.ts +4 -2
  21. package/lib/ui/HighlightMenu.js +3 -3
  22. package/lib/ui/NoteEditor.js +6 -5
  23. package/lib/ui/SearchSheet.js +6 -5
  24. package/lib/ui/Sheet.js +5 -4
  25. package/lib/ui/Text.d.ts +9 -0
  26. package/lib/ui/Text.js +62 -0
  27. package/package.json +81 -76
  28. package/src/EpubReader.tsx +121 -25
  29. package/src/EpubReaderView.tsx +61 -17
  30. package/src/cfiOrder.ts +28 -0
  31. package/src/engine/epubcfi.js +527 -0
  32. package/src/engine/html.ts +1 -1
  33. package/src/engine/reader.js +830 -65
  34. package/src/index.ts +1 -1
  35. package/src/themes.ts +97 -21
  36. package/src/types.ts +71 -1
  37. package/src/ui/AppearanceSheet.tsx +19 -10
  38. package/src/ui/ContentsSheet.tsx +14 -4
  39. package/src/ui/CustomizeSheet.tsx +14 -10
  40. package/src/ui/HighlightMenu.tsx +6 -4
  41. package/src/ui/NoteEditor.tsx +2 -1
  42. package/src/ui/SearchSheet.tsx +2 -1
  43. package/src/ui/Sheet.tsx +4 -3
  44. package/src/ui/Text.tsx +27 -0
package/lib/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export type { EpubReaderViewProps } from './EpubReaderView';
3
3
  export { EpubReader } from './EpubReader';
4
4
  export type { EpubReaderProps, EpubReaderHandle, ReaderErrorInfo } from './EpubReader';
5
5
  export { THEMES, FONTS, HIGHLIGHT_COLORS, DEFAULT_SETTINGS, getTheme, getFont, chromeColors, themeColors, isDark } from './themes';
6
- export type { ChromeColors } from './themes';
6
+ export type { ChromeColors, ChromeOverrides } from './themes';
7
7
  export { DEFAULT_LABELS } from './strings';
8
8
  export type { ReaderLabels } from './strings';
9
9
  export * from './types';
package/lib/themes.d.ts CHANGED
@@ -1,21 +1,26 @@
1
- import type { HighlightColor, ReaderFont, ReaderSettings, ReaderTheme, ThemeColors } from './types';
1
+ import type { CustomFont, HighlightColor, ReaderFont, ReaderSettings, ReaderTheme, ThemeColors } from './types';
2
2
  export declare const THEMES: ReaderTheme[];
3
3
  /** Font stacks. iOS ships most of these, on Android the stacks fall back to the system serif / sans. */
4
4
  export declare const FONTS: ReaderFont[];
5
5
  export declare const HIGHLIGHT_COLORS: Record<HighlightColor, string>;
6
6
  export declare const DEFAULT_SETTINGS: ReaderSettings;
7
- export declare const getTheme: (id: string) => ReaderTheme;
8
- export declare const getFont: (id: string) => ReaderFont;
7
+ /** `themes`: the host's own list (see the `themes` prop), or the built-in one. Unknown ids get the first theme. */
8
+ export declare const getTheme: (id: string, themes?: ReaderTheme[]) => ReaderTheme;
9
+ /** The built-in fonts plus the app's own (the CustomFont entries that have an id). */
10
+ export declare function fontChoices(custom?: CustomFont[]): ReaderFont[];
11
+ export declare const getFont: (id: string, custom?: CustomFont[]) => ReaderFont;
9
12
  export declare const serifFont: string;
10
13
  export declare function isDark(settings: ReaderSettings, systemDark: boolean): boolean;
11
- export declare function themeColors(settings: ReaderSettings, systemDark: boolean): ThemeColors;
14
+ export declare function themeColors(settings: ReaderSettings, systemDark: boolean, themes?: ReaderTheme[]): ThemeColors;
12
15
  /** Settings object understood by the WebView engine. */
13
16
  export declare function toEngineSettings(settings: ReaderSettings, systemDark: boolean, insets: {
14
17
  top: number;
15
18
  bottom: number;
16
19
  left?: number;
17
20
  right?: number;
18
- }): {
21
+ }, fonts?: CustomFont[], themes?: ReaderTheme[],
22
+ /** false: no running header / footer, and no space kept for them */
23
+ runningLabels?: boolean): {
19
24
  bg: string;
20
25
  fg: string;
21
26
  link: string;
@@ -36,6 +41,8 @@ export declare function toEngineSettings(settings: ReaderSettings, systemDark: b
36
41
  left: number;
37
42
  right: number;
38
43
  };
44
+ showHeader: boolean;
45
+ showFooter: boolean;
39
46
  };
40
47
  export interface ChromeColors {
41
48
  /** translucent control background (pills, circles), tinted with the page colour */
@@ -51,10 +58,21 @@ export interface ChromeColors {
51
58
  separator: string;
52
59
  /** highlight for the current chapter / selected items */
53
60
  accent: string;
61
+ /** solid buttons and fills (Done, the progress pill, switches). Default: black / white per control */
62
+ strong?: string;
63
+ /** text and icons on `strong` */
64
+ onStrong?: string;
54
65
  dark: boolean;
55
66
  }
56
67
  /**
57
68
  * Chrome (buttons, menus, sheets) is frosted glass tinted with the page colour, so a Calm page gets warm glass and a
58
69
  * black page gets dark glass. Text and icons use the neutral text colour of the light / dark variant.
59
70
  */
60
- export declare function chromeColors(colors: ThemeColors, dark: boolean): ChromeColors;
71
+ export declare function chromeColors(colors: ThemeColors, dark: boolean, chrome?: ChromeOverrides): ChromeColors;
72
+ /** '#000000' on a light colour, '#ffffff' on a dark one (or one that cannot be read). */
73
+ export declare function textOn(color: string): string;
74
+ /** The host's chrome colours for light and dark pages (see the `chrome` prop). Missing ones keep the default. */
75
+ export interface ChromeOverrides {
76
+ light?: Partial<Omit<ChromeColors, 'dark'>>;
77
+ dark?: Partial<Omit<ChromeColors, 'dark'>>;
78
+ }
package/lib/themes.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serifFont = exports.getFont = exports.getTheme = exports.DEFAULT_SETTINGS = exports.HIGHLIGHT_COLORS = exports.FONTS = exports.THEMES = void 0;
4
+ exports.fontChoices = fontChoices;
4
5
  exports.isDark = isDark;
5
6
  exports.themeColors = themeColors;
6
7
  exports.toEngineSettings = toEngineSettings;
7
8
  exports.chromeColors = chromeColors;
9
+ exports.textOn = textOn;
8
10
  const react_native_1 = require("react-native");
9
11
  exports.THEMES = [
10
12
  {
@@ -85,30 +87,46 @@ exports.DEFAULT_SETTINGS = {
85
87
  brightness: 1,
86
88
  direction: 'auto'
87
89
  };
88
- const getTheme = (id) => exports.THEMES.find((t) => t.id === id) || exports.THEMES[0];
90
+ /** `themes`: the host's own list (see the `themes` prop), or the built-in one. Unknown ids get the first theme. */
91
+ const getTheme = (id, themes = exports.THEMES) => themes.find((t) => t.id === id) || themes[0] || exports.THEMES[0];
89
92
  exports.getTheme = getTheme;
90
- const getFont = (id) => exports.FONTS.find((f) => f.id === id) || exports.FONTS[0];
93
+ /** The built-in fonts plus the app's own (the CustomFont entries that have an id). */
94
+ function fontChoices(custom) {
95
+ // one entry per id: a family shipped as several files (regular, bold ...) shares one id
96
+ const seen = new Set();
97
+ const extra = (custom || [])
98
+ .filter((f) => f.id && !seen.has(f.id) && !!seen.add(f.id))
99
+ .map((f) => ({ id: f.id, name: f.name || f.family, css: `"${f.family}"` }));
100
+ return extra.length ? exports.FONTS.concat(extra) : exports.FONTS;
101
+ }
102
+ const getFont = (id, custom) => {
103
+ const list = fontChoices(custom);
104
+ return list.find((f) => f.id === id) || list[0];
105
+ };
91
106
  exports.getFont = getFont;
92
107
  exports.serifFont = SERIF;
93
108
  function isDark(settings, systemDark) {
94
109
  return settings.appearance === 'device' ? systemDark : settings.appearance === 'dark';
95
110
  }
96
- function themeColors(settings, systemDark) {
97
- const t = (0, exports.getTheme)(settings.themeId);
111
+ function themeColors(settings, systemDark, themes) {
112
+ const t = (0, exports.getTheme)(settings.themeId, themes);
98
113
  return isDark(settings, systemDark) ? t.dark : t.light;
99
114
  }
100
115
  const BASE_MARGIN = 28;
101
116
  /** Settings object understood by the WebView engine. */
102
- function toEngineSettings(settings, systemDark, insets) {
103
- const theme = (0, exports.getTheme)(settings.themeId);
104
- const c = themeColors(settings, systemDark);
117
+ function toEngineSettings(settings, systemDark, insets, fonts, themes,
118
+ /** false: no running header / footer, and no space kept for them */
119
+ runningLabels = true) {
120
+ const theme = (0, exports.getTheme)(settings.themeId, themes);
121
+ const labelSpace = runningLabels ? 40 : 0;
122
+ const c = themeColors(settings, systemDark, themes);
105
123
  const custom = settings.customize;
106
124
  return {
107
125
  bg: c.bg,
108
126
  fg: c.fg,
109
127
  link: c.link,
110
128
  bold: !!theme.bold || settings.bold,
111
- fontFamily: (0, exports.getFont)(settings.fontId).css,
129
+ fontFamily: (0, exports.getFont)(settings.fontId, fonts).css,
112
130
  fontSize: settings.fontSize,
113
131
  lineHeight: custom ? settings.lineHeight : 1.5,
114
132
  letterSpacing: custom ? (settings.letterSpacing / 100) * 0.25 : 0,
@@ -118,31 +136,73 @@ function toEngineSettings(settings, systemDark, insets) {
118
136
  justify: settings.justify,
119
137
  mode: settings.pageTurn,
120
138
  direction: settings.direction,
121
- insets: { top: insets.top + 40, bottom: insets.bottom + 40, left: insets.left || 0, right: insets.right || 0 }
139
+ insets: { top: insets.top + labelSpace, bottom: insets.bottom + labelSpace, left: insets.left || 0, right: insets.right || 0 },
140
+ showHeader: runningLabels,
141
+ showFooter: runningLabels
122
142
  };
123
143
  }
144
+ const NAMED = { white: '#ffffff', black: '#000000' };
145
+ /** [r, g, b] of '#rgb', '#rgba', '#rrggbb', '#rrggbbaa', 'rgb(...)', 'rgba(...)', 'white' or 'black'. null for anything else. */
146
+ function rgbOf(color) {
147
+ const c = (NAMED[color.trim().toLowerCase()] || color).trim();
148
+ let m = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(c);
149
+ if (m) {
150
+ const h = m[1].length <= 4 ? m[1].replace(/./g, '$&$&') : m[1];
151
+ return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
152
+ }
153
+ m = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(c);
154
+ if (m)
155
+ return [m[1], m[2], m[3]].map((v) => Math.min(255, Math.round(+v)));
156
+ return null;
157
+ }
158
+ // a theme colour the chrome cannot read falls back to plain white / black
159
+ function hexOf(color, dark) {
160
+ const v = rgbOf(color) || (dark ? [0, 0, 0] : [255, 255, 255]);
161
+ return '#' + v.map((n) => n.toString(16).padStart(2, '0')).join('');
162
+ }
163
+ // both colours are '#rrggbb' here (see hexOf)
124
164
  function mix(hex, other, amount) {
125
- const p = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
126
- const a = p(hex);
127
- const b = p(other);
165
+ const a = rgbOf(hex);
166
+ const b = rgbOf(other);
128
167
  const m = a.map((v, i) => Math.round(v + (b[i] - v) * amount));
129
168
  return '#' + m.map((v) => v.toString(16).padStart(2, '0')).join('');
130
169
  }
131
170
  function rgba(hex, alpha) {
132
- const v = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
171
+ const v = rgbOf(hex);
133
172
  return `rgba(${v[0]},${v[1]},${v[2]},${alpha})`;
134
173
  }
135
174
  /**
136
175
  * Chrome (buttons, menus, sheets) is frosted glass tinted with the page colour, so a Calm page gets warm glass and a
137
176
  * black page gets dark glass. Text and icons use the neutral text colour of the light / dark variant.
138
177
  */
139
- function chromeColors(colors, dark) {
178
+ function chromeColors(colors, dark, chrome) {
179
+ const own = chrome && (dark ? chrome.dark : chrome.light);
180
+ const base = defaultChrome(colors, dark);
181
+ if (!own)
182
+ return base;
183
+ // a key set to undefined keeps the default
184
+ const set = Object.fromEntries(Object.entries(own).filter(([, v]) => v !== undefined));
185
+ const out = { ...base, ...set, dark };
186
+ // a host `strong` without `onStrong`: black or white, whichever reads on it
187
+ if (set.strong && !set.onStrong)
188
+ out.onStrong = textOn(set.strong);
189
+ return out;
190
+ }
191
+ /** '#000000' on a light colour, '#ffffff' on a dark one (or one that cannot be read). */
192
+ function textOn(color) {
193
+ const v = rgbOf(color);
194
+ if (!v)
195
+ return '#ffffff';
196
+ return (0.299 * v[0] + 0.587 * v[1] + 0.114 * v[2]) / 255 > 0.6 ? '#000000' : '#ffffff';
197
+ }
198
+ function defaultChrome(colors, dark) {
199
+ const bg = hexOf(colors.bg, dark);
140
200
  if (dark) {
141
201
  return {
142
- glass: rgba(mix(colors.bg, '#ffffff', 0.22), 0.4),
202
+ glass: rgba(mix(bg, '#ffffff', 0.22), 0.4),
143
203
  glassBorder: 'rgba(255,255,255,0.16)',
144
- sheet: mix(colors.bg, '#ffffff', 0.1),
145
- sheetGlass: rgba(mix(colors.bg, '#ffffff', 0.1), 0.84),
204
+ sheet: mix(bg, '#ffffff', 0.1),
205
+ sheetGlass: rgba(mix(bg, '#ffffff', 0.1), 0.84),
146
206
  card: 'rgba(255,255,255,0.1)',
147
207
  text: '#ffffff',
148
208
  subtext: '#a09d96',
@@ -152,10 +212,10 @@ function chromeColors(colors, dark) {
152
212
  };
153
213
  }
154
214
  return {
155
- glass: rgba(mix(colors.bg, '#ffffff', 0.55), 0.5),
215
+ glass: rgba(mix(bg, '#ffffff', 0.55), 0.5),
156
216
  glassBorder: 'rgba(0,0,0,0.1)',
157
- sheet: mix(colors.bg, '#ffffff', 0.5),
158
- sheetGlass: rgba(mix(colors.bg, '#ffffff', 0.5), 0.86),
217
+ sheet: mix(bg, '#ffffff', 0.5),
218
+ sheetGlass: rgba(mix(bg, '#ffffff', 0.5), 0.86),
159
219
  card: 'rgba(0,0,0,0.06)',
160
220
  text: '#000000',
161
221
  subtext: '#6c6c70',
package/lib/types.d.ts CHANGED
@@ -11,16 +11,28 @@ export interface Highlight {
11
11
  start: number;
12
12
  end: number;
13
13
  text: string;
14
- color: HighlightColor;
14
+ /** a built-in colour name, or a key of the `highlightColors` prop, or a CSS colour such as '#ffff00' */
15
+ color: HighlightColor | (string & {});
16
+ /** epub.js range CFI. When set, it decides where the highlight is (spine/start/end are ignored). */
17
+ cfi?: string;
15
18
  style?: HighlightStyle;
16
19
  note?: string;
17
20
  chapter?: string;
18
21
  createdAt: number;
19
22
  }
23
+ /** A highlight known only by its epub.js CFI (for example one saved by an epub.js reader). The engine finds the text. */
24
+ export interface CfiHighlight {
25
+ id: string;
26
+ cfi: string;
27
+ color: Highlight['color'];
28
+ style?: HighlightStyle;
29
+ }
20
30
  export interface Bookmark {
21
31
  id: string;
22
32
  spine: number;
23
33
  offset: number;
34
+ /** epub.js point CFI of the same spot */
35
+ cfi?: string;
24
36
  chapter: string;
25
37
  excerpt: string;
26
38
  progress: number;
@@ -28,9 +40,12 @@ export interface Bookmark {
28
40
  }
29
41
  export interface TocItem {
30
42
  label: string;
43
+ /** -1 when the entry's file is not in the book (only in the `all` list of onToc) */
31
44
  spine: number;
32
45
  fragment: string;
33
46
  level: number;
47
+ /** path relative to the package (.opf) file, with '#fragment' when there is one, e.g. 'text/ch1.xhtml#s2' */
48
+ href: string;
34
49
  }
35
50
  export interface BookMetadata {
36
51
  title: string;
@@ -54,6 +69,27 @@ export interface RelocateEvent {
54
69
  chapter: string;
55
70
  excerpt: string;
56
71
  indexed: boolean;
72
+ /** href of the spine item, relative to the package (.opf) file (epub.js location.start.href) */
73
+ href: string;
74
+ /** index in the TOC list (onToc) of the entry this page belongs to, -1 before the first entry */
75
+ tocIndex: number;
76
+ /** epub.js point CFI of the first character on the page */
77
+ startCfi?: string;
78
+ /** epub.js point CFI just after the last character on the page */
79
+ endCfi?: string;
80
+ /** epub.js locations ("chunks") of this page, once they are counted (see onLocations) */
81
+ locations?: LocationsInfo;
82
+ }
83
+ /** The page's place in the epub.js locations of the book. Same numbers as epub.js gives for the same CFIs. */
84
+ export interface LocationsInfo {
85
+ /** location index of startCfi (epub.js locationFromCfi) */
86
+ start: number;
87
+ /** location index of endCfi */
88
+ end: number;
89
+ /** number of locations in the book (epub.js locations.total + 1) */
90
+ count: number;
91
+ /** 0..1, epub.js percentageFromCfi(startCfi) */
92
+ progress: number;
57
93
  }
58
94
  export interface SelectionEvent {
59
95
  spine: number;
@@ -66,6 +102,8 @@ export interface SelectionEvent {
66
102
  width: number;
67
103
  height: number;
68
104
  };
105
+ /** epub.js range CFI of the selection */
106
+ cfi?: string;
69
107
  }
70
108
  export interface SearchResult {
71
109
  spine: number;
@@ -147,3 +185,30 @@ export interface SafeInsets {
147
185
  left?: number;
148
186
  right?: number;
149
187
  }
188
+ /** A font shipped by the app and loaded into every chapter with @font-face. Use `family` in a ReaderFont's css. */
189
+ export interface CustomFont {
190
+ /** set it to make the font a choice for settings.fontId (and in the font list of EpubReaderView) */
191
+ id?: string;
192
+ /** name in the font list (default: family) */
193
+ name?: string;
194
+ family: string;
195
+ /** the font file as base64 (a data: prefix is accepted) */
196
+ base64: string;
197
+ /** e.g. 'font/ttf', 'font/otf', 'font/woff2' */
198
+ mime: string;
199
+ weight?: 'normal' | 'bold' | number;
200
+ style?: 'normal' | 'italic';
201
+ }
202
+ /**
203
+ * Fonts for the reader's own interface (buttons, sheets, menus), e.g. the app's brand font. Not the book text.
204
+ * Text that asks for weight 500 uses `medium`, 600 and up uses `bold`, when given.
205
+ * Give `bold`: without it, iOS draws bold text (titles, search matches) in the regular font, not bold.
206
+ * Text fields (search, notes) use `regular`.
207
+ */
208
+ export interface UiFonts {
209
+ regular: string;
210
+ medium?: string;
211
+ bold?: string;
212
+ }
213
+ /** 'theme': every text in the theme colour. 'keep': the book's own colours stay, made readable on the theme. */
214
+ export type BookColors = 'theme' | 'keep';
@@ -1,15 +1,17 @@
1
1
  import React from 'react';
2
2
  import type { ChromeColors } from '../themes';
3
- import type { ReaderSettings } from '../types';
3
+ import type { ReaderSettings, ReaderTheme } from '../types';
4
4
  interface Props {
5
5
  visible: boolean;
6
6
  colors: ChromeColors;
7
7
  settings: ReaderSettings;
8
8
  systemDark: boolean;
9
+ /** the host's themes (default: the built-in ones) */
10
+ themes?: ReaderTheme[];
9
11
  onChange: (patch: Partial<ReaderSettings>) => void;
10
12
  onCustomize: () => void;
11
13
  onClose: () => void;
12
14
  }
13
15
  /** "Themes & Settings" sheet. */
14
- export declare function AppearanceSheet({ visible, colors, settings: s, systemDark, onChange, onCustomize, onClose }: Props): React.JSX.Element;
16
+ export declare function AppearanceSheet({ visible, colors, settings: s, systemDark, themes, onChange, onCustomize, onClose }: Props): React.JSX.Element;
15
17
  export {};
@@ -36,12 +36,14 @@ 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");
40
41
  const strings_1 = require("../strings");
41
42
  const Icons_1 = require("./Icons");
42
43
  const Sheet_1 = require("./Sheet");
43
44
  const Slider_1 = require("./Slider");
44
45
  const SIZE = { min: 12, max: 40, step: 2 };
46
+ const GRID_GAP = 10;
45
47
  const TURNS = [
46
48
  { id: 'slide', label: 'slide', icon: 'pageSlide' },
47
49
  { id: 'curl', label: 'curl', icon: 'pageCurl' },
@@ -57,9 +59,12 @@ const APPEARANCES = [
57
59
  /** Icon of the current appearance choice: the button always shows the state it is in. */
58
60
  const appearanceIcon = (a) => (a === 'light' ? 'sun' : a === 'dark' ? 'moon' : 'contrast');
59
61
  /** "Themes & Settings" sheet. */
60
- function AppearanceSheet({ visible, colors, settings: s, systemDark, onChange, onCustomize, onClose }) {
62
+ function AppearanceSheet({ visible, colors, settings: s, systemDark, themes, onChange, onCustomize, onClose }) {
61
63
  const L = (0, strings_1.useLabels)();
62
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%';
63
68
  // a popup left open must not reappear the next time the sheet is shown
64
69
  (0, react_1.useEffect)(() => {
65
70
  if (!visible)
@@ -76,23 +81,23 @@ function AppearanceSheet({ visible, colors, settings: s, systemDark, onChange, o
76
81
  } },
77
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 })),
78
83
  react_1.default.createElement(Icons_1.Icon, { name: t.icon, color: colors.text, size: 24 }),
79
- react_1.default.createElement(react_native_1.Text, { style: [styles.menuText, { color: colors.text }] }, L[t.label]))))
84
+ react_1.default.createElement(Text_1.Text, { style: [styles.menuText, { color: colors.text }] }, L[t.label]))))
80
85
  : APPEARANCES.map((a) => (react_1.default.createElement(react_native_1.Pressable, { key: a.key, style: styles.menuItem, onPress: () => {
81
86
  onChange({ appearance: a.id });
82
87
  setMenu(null);
83
88
  } },
84
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 })),
85
90
  react_1.default.createElement(Icons_1.Icon, { name: a.icon, color: colors.text, size: 24 }),
86
- react_1.default.createElement(react_native_1.Text, { style: [styles.menuText, { color: colors.text }] }, L[a.label])))))));
91
+ react_1.default.createElement(Text_1.Text, { style: [styles.menuText, { color: colors.text }] }, L[a.label])))))));
87
92
  return (react_1.default.createElement(Sheet_1.Sheet, { visible: visible, colors: colors, onClose: onClose, title: L.themesSettings, height: "auto", overlay: menuView || undefined },
88
93
  react_1.default.createElement(react_native_1.View, { style: styles.body },
89
94
  react_1.default.createElement(react_native_1.View, { style: styles.row },
90
95
  react_1.default.createElement(react_native_1.View, { style: [styles.pill, { flex: 1, backgroundColor: colors.card }] },
91
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 },
92
- react_1.default.createElement(react_native_1.Text, { style: { color: colors.text, fontSize: 15, fontWeight: '500' } }, "A")),
97
+ react_1.default.createElement(Text_1.Text, { style: { color: colors.text, fontSize: 15, fontWeight: '500' } }, "A")),
93
98
  react_1.default.createElement(react_native_1.View, { style: [styles.divider, { backgroundColor: colors.separator }] }),
94
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 },
95
- react_1.default.createElement(react_native_1.Text, { style: { color: colors.text, fontSize: 26, fontWeight: '500' } }, "A"))),
100
+ react_1.default.createElement(Text_1.Text, { style: { color: colors.text, fontSize: 26, fontWeight: '500' } }, "A"))),
96
101
  react_1.default.createElement(react_native_1.View, { style: [styles.pill, { width: 150, backgroundColor: colors.card }] },
97
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]}` },
98
103
  react_1.default.createElement(Icons_1.Icon, { name: turn.icon, color: colors.text, size: 26 })),
@@ -103,16 +108,17 @@ function AppearanceSheet({ visible, colors, settings: s, systemDark, onChange, o
103
108
  react_1.default.createElement(react_native_1.View, { style: { flex: 1, marginHorizontal: 10 } },
104
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" })),
105
110
  react_1.default.createElement(Icons_1.Icon, { name: "sun", color: colors.subtext, size: 26 })),
106
- 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) => {
107
112
  const c = dark ? t.dark : t.light;
108
- const on = t.id === s.themeId;
109
- 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 } },
110
- react_1.default.createElement(react_native_1.Text, { style: { color: c.fg, fontSize: 30, fontFamily: themes_1.serifFont, fontWeight: t.bold ? '800' : '400' } }, "Aa"),
111
- 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)));
112
118
  })),
113
119
  react_1.default.createElement(react_native_1.Pressable, { onPress: onCustomize, style: [styles.customize, { backgroundColor: colors.card }], accessibilityRole: "button" },
114
120
  react_1.default.createElement(Icons_1.Icon, { name: "sliders", color: colors.text, size: 22 }),
115
- react_1.default.createElement(react_native_1.Text, { style: { color: colors.text, fontSize: 18, fontWeight: '600', marginStart: 10 } }, L.customize)))));
121
+ react_1.default.createElement(Text_1.Text, { style: { color: colors.text, fontSize: 18, fontWeight: '600', marginStart: 10 } }, L.customize)))));
116
122
  }
117
123
  const styles = react_native_1.StyleSheet.create({
118
124
  body: { paddingHorizontal: 16, paddingBottom: 28 },
@@ -121,8 +127,9 @@ const styles = react_native_1.StyleSheet.create({
121
127
  half: { flex: 1, height: '100%', alignItems: 'center', justifyContent: 'center' },
122
128
  divider: { width: react_native_1.StyleSheet.hairlineWidth, height: 24 },
123
129
  brightness: { flexDirection: 'row', alignItems: 'center', marginTop: 14, marginBottom: 8, paddingHorizontal: 4 },
124
- grid: { flexDirection: 'row', flexWrap: 'wrap', gap: 10, marginTop: 6 },
125
- 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' },
126
133
  customize: { marginTop: 12, height: 58, borderRadius: 29, flexDirection: 'row', alignItems: 'center', justifyContent: 'center' },
127
134
  menu: {
128
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,9 +36,17 @@ 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");
40
41
  const strings_1 = require("../strings");
41
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
+ }
42
50
  const TABS = [
43
51
  { id: 'contents', label: 'chapters' },
44
52
  { id: 'bookmarks', label: 'bookmarks' },
@@ -53,29 +61,29 @@ function ContentsSheet(p) {
53
61
  { text: L.cancel, style: 'cancel' },
54
62
  { text: L.delete, style: 'destructive', onPress: fn }
55
63
  ]);
56
- 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);
57
65
  const rowBorder = { borderColor: colors.separator };
58
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%" },
59
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 } },
60
- react_1.default.createElement(react_native_1.Text, { style: { color: colors.text, fontWeight: tab === t.id ? '600' : '400', fontSize: 16 }, maxFontSizeMultiplier: 1.3 }, L[t.label]))))),
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]))))),
61
69
  tab === 'contents' && (react_1.default.createElement(react_native_1.FlatList, { data: p.toc, keyExtractor: (_, i) => String(i), ListEmptyComponent: empty(L.noToc), renderItem: ({ item }) => {
62
70
  const active = item.spine === p.currentSpine && !item.fragment;
63
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 }] },
64
- react_1.default.createElement(react_native_1.Text, { style: [styles.rowText, { color: active ? colors.accent : colors.text, flex: 1 }], numberOfLines: 2 }, item.label),
65
- react_1.default.createElement(react_native_1.Text, { style: [styles.page, { color: colors.subtext }] }, L.formatNumber(p.pageOf(item.spine, 0)))));
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)))));
66
74
  } })),
67
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] },
68
76
  react_1.default.createElement(react_native_1.View, { style: { flex: 1 } },
69
- react_1.default.createElement(react_native_1.Text, { style: [styles.meta, { color: colors.accent }] }, item.chapter),
70
- react_1.default.createElement(react_native_1.Text, { style: [styles.rowText, { color: colors.text }], numberOfLines: 2 }, item.excerpt)),
71
- react_1.default.createElement(react_native_1.Text, { style: [styles.page, { color: colors.subtext }] }, L.formatNumber(p.pageOf(item.spine, item.offset))))) })),
72
- 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(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] },
73
- 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 }] }),
74
82
  react_1.default.createElement(react_native_1.View, { style: { flex: 1 } },
75
- !!item.note && react_1.default.createElement(react_native_1.Text, { style: [styles.rowText, { color: colors.text, fontWeight: '600' }] }, item.note),
76
- react_1.default.createElement(react_native_1.Text, { style: [styles.rowText, { color: item.note ? colors.subtext : colors.text }], numberOfLines: 3 }, item.text),
77
- !!item.chapter && react_1.default.createElement(react_native_1.Text, { style: [styles.meta, { color: colors.subtext }] }, item.chapter)),
78
- react_1.default.createElement(react_native_1.Text, { style: [styles.page, { color: colors.subtext }] }, L.formatNumber(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))))) }))));
79
87
  }
80
88
  const styles = react_native_1.StyleSheet.create({
81
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 {};