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
package/lib/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export { EpubReaderView } from './EpubReaderView';
2
2
  export type { EpubReaderViewProps } from './EpubReaderView';
3
3
  export { EpubReader } from './EpubReader';
4
- export type { EpubReaderProps, EpubReaderHandle } from './EpubReader';
5
- export { THEMES, FONTS, HIGHLIGHT_COLORS, DEFAULT_SETTINGS, getTheme, getFont, chromeColors } from './themes';
4
+ export type { EpubReaderProps, EpubReaderHandle, ReaderErrorInfo } from './EpubReader';
5
+ export { THEMES, FONTS, HIGHLIGHT_COLORS, DEFAULT_SETTINGS, getTheme, getFont, chromeColors, themeColors, isDark } from './themes';
6
+ export type { ChromeColors, ChromeOverrides } from './themes';
7
+ export { DEFAULT_LABELS } from './strings';
8
+ export type { ReaderLabels } from './strings';
6
9
  export * from './types';
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.chromeColors = exports.getFont = exports.getTheme = exports.DEFAULT_SETTINGS = exports.HIGHLIGHT_COLORS = exports.FONTS = exports.THEMES = exports.EpubReader = exports.EpubReaderView = void 0;
17
+ exports.DEFAULT_LABELS = exports.isDark = exports.themeColors = exports.chromeColors = exports.getFont = exports.getTheme = exports.DEFAULT_SETTINGS = exports.HIGHLIGHT_COLORS = exports.FONTS = exports.THEMES = exports.EpubReader = exports.EpubReaderView = void 0;
18
18
  var EpubReaderView_1 = require("./EpubReaderView");
19
19
  Object.defineProperty(exports, "EpubReaderView", { enumerable: true, get: function () { return EpubReaderView_1.EpubReaderView; } });
20
20
  var EpubReader_1 = require("./EpubReader");
@@ -27,4 +27,8 @@ Object.defineProperty(exports, "DEFAULT_SETTINGS", { enumerable: true, get: func
27
27
  Object.defineProperty(exports, "getTheme", { enumerable: true, get: function () { return themes_1.getTheme; } });
28
28
  Object.defineProperty(exports, "getFont", { enumerable: true, get: function () { return themes_1.getFont; } });
29
29
  Object.defineProperty(exports, "chromeColors", { enumerable: true, get: function () { return themes_1.chromeColors; } });
30
+ Object.defineProperty(exports, "themeColors", { enumerable: true, get: function () { return themes_1.themeColors; } });
31
+ Object.defineProperty(exports, "isDark", { enumerable: true, get: function () { return themes_1.isDark; } });
32
+ var strings_1 = require("./strings");
33
+ Object.defineProperty(exports, "DEFAULT_LABELS", { enumerable: true, get: function () { return strings_1.DEFAULT_LABELS; } });
30
34
  __exportStar(require("./types"), exports);
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Every text the reader shows. Pass a partial object as the `labels` prop of EpubReaderView to translate
3
+ * (for example into Pashto, Dari or Arabic); anything you leave out stays English.
4
+ */
5
+ export interface ReaderLabels {
6
+ contents: string;
7
+ chapters: string;
8
+ font: string;
9
+ lineSpacing: string;
10
+ characterSpacing: string;
11
+ wordSpacing: string;
12
+ margins: string;
13
+ columns: string;
14
+ columnsAuto: string;
15
+ columnsOne: string;
16
+ columnsTwo: string;
17
+ slide: string;
18
+ curl: string;
19
+ fastFade: string;
20
+ scrollMode: string;
21
+ light: string;
22
+ dark: string;
23
+ matchDevice: string;
24
+ matchSurroundings: string;
25
+ appearance: string;
26
+ pageTurnStyle: string;
27
+ delete: string;
28
+ deleteBookmark: string;
29
+ deleteHighlight: string;
30
+ search: string;
31
+ searchBook: string;
32
+ searchInBook: string;
33
+ searching: string;
34
+ noResults: string;
35
+ themesSettings: string;
36
+ customizeTheme: string;
37
+ customize: string;
38
+ resetTheme: string;
39
+ boldText: string;
40
+ justifyText: string;
41
+ pageTurnSound: string;
42
+ accessibilityLayout: string;
43
+ smallerText: string;
44
+ largerText: string;
45
+ readerMenu: string;
46
+ closeBook: string;
47
+ share: string;
48
+ rotationLock: string;
49
+ rotationLockNeedsPackage: string;
50
+ lineGuide: string;
51
+ turnOffLineGuide: string;
52
+ backgroundDimming: string;
53
+ dimHigh: string;
54
+ dimMedium: string;
55
+ dimLow: string;
56
+ dimNone: string;
57
+ bookmarkPage: string;
58
+ highlight: string;
59
+ note: string;
60
+ addNote: string;
61
+ addANote: string;
62
+ underline: string;
63
+ removeHighlight: string;
64
+ dismiss: string;
65
+ done: string;
66
+ close: string;
67
+ cancel: string;
68
+ save: string;
69
+ ok: string;
70
+ noToc: string;
71
+ noBookmarks: string;
72
+ noHighlights: string;
73
+ bookmarks: string;
74
+ highlights: string;
75
+ loading: string;
76
+ couldNotOpen: string;
77
+ tryAgain: string;
78
+ openLink: string;
79
+ open: string;
80
+ lastPageInChapter: string;
81
+ /** "N pages left in chapter" */
82
+ pagesLeft: (n: number) => string;
83
+ /** "3 of 120" */
84
+ pageOfTotal: (page: number, total: number) => string;
85
+ /** "Page 3 of 120" */
86
+ pageOfTotalLong: (page: number, total: number) => string;
87
+ returnToPage: (page: number) => string;
88
+ /** how numbers are written (e.g. Arabic-Indic digits for an Arabic UI) */
89
+ formatNumber: (n: number) => string;
90
+ }
91
+ export declare const DEFAULT_LABELS: ReaderLabels;
92
+ export declare const LabelsProvider: import("react").Provider<ReaderLabels>;
93
+ export declare function useLabels(): ReaderLabels;
94
+ export declare function mergeLabels(partial?: Partial<ReaderLabels>): ReaderLabels;
package/lib/strings.js ADDED
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LabelsProvider = exports.DEFAULT_LABELS = void 0;
4
+ exports.useLabels = useLabels;
5
+ exports.mergeLabels = mergeLabels;
6
+ const react_1 = require("react");
7
+ exports.DEFAULT_LABELS = {
8
+ contents: 'Contents',
9
+ chapters: 'Chapters',
10
+ font: 'Font',
11
+ lineSpacing: 'LINE SPACING',
12
+ characterSpacing: 'CHARACTER SPACING',
13
+ wordSpacing: 'WORD SPACING',
14
+ margins: 'MARGINS',
15
+ columns: 'Columns',
16
+ columnsAuto: 'Auto Set',
17
+ columnsOne: 'One',
18
+ columnsTwo: 'Two',
19
+ slide: 'Slide',
20
+ curl: 'Curl',
21
+ fastFade: 'Fast Fade',
22
+ scrollMode: 'Scroll',
23
+ light: 'Light',
24
+ dark: 'Dark',
25
+ matchDevice: 'Match Device',
26
+ matchSurroundings: 'Match Surroundings',
27
+ appearance: 'Appearance',
28
+ pageTurnStyle: 'Page turn style',
29
+ delete: 'Delete',
30
+ deleteBookmark: 'Delete bookmark?',
31
+ deleteHighlight: 'Delete highlight?',
32
+ search: 'Search',
33
+ searchBook: 'Search Book',
34
+ searchInBook: 'Search in book',
35
+ searching: 'Searching…',
36
+ noResults: 'No results',
37
+ themesSettings: 'Themes & Settings',
38
+ customizeTheme: 'Customize Theme',
39
+ customize: 'Customize',
40
+ resetTheme: 'Reset Theme',
41
+ boldText: 'Bold Text',
42
+ justifyText: 'Justify Text',
43
+ pageTurnSound: 'Page Turn Sound',
44
+ accessibilityLayout: 'Accessibility & Layout Options',
45
+ smallerText: 'Smaller text',
46
+ largerText: 'Larger text',
47
+ readerMenu: 'Reader menu',
48
+ closeBook: 'Close book',
49
+ share: 'Share',
50
+ rotationLock: 'Rotation lock',
51
+ rotationLockNeedsPackage: 'Install expo-screen-orientation to enable the rotation lock.',
52
+ lineGuide: 'Line guide',
53
+ turnOffLineGuide: 'Turn Off Line Guide',
54
+ backgroundDimming: 'Background Dimming',
55
+ dimHigh: 'High',
56
+ dimMedium: 'Medium',
57
+ dimLow: 'Low',
58
+ dimNone: 'None',
59
+ bookmarkPage: 'Bookmark this page',
60
+ highlight: 'Highlight',
61
+ note: 'Note',
62
+ addNote: 'Add note',
63
+ addANote: 'Add a note',
64
+ underline: 'Underline',
65
+ removeHighlight: 'Remove highlight',
66
+ dismiss: 'Dismiss',
67
+ done: 'Done',
68
+ close: 'Close',
69
+ cancel: 'Cancel',
70
+ save: 'Save',
71
+ ok: 'OK',
72
+ noToc: 'No table of contents',
73
+ noBookmarks: 'No bookmarks yet. Tap the bookmark button while reading.',
74
+ noHighlights: 'No highlights or notes yet. Select text to add one.',
75
+ bookmarks: 'Bookmarks',
76
+ highlights: 'Highlights',
77
+ loading: 'Opening book…',
78
+ couldNotOpen: 'This book could not be opened',
79
+ tryAgain: 'Try again',
80
+ openLink: 'Open this link?',
81
+ open: 'Open',
82
+ lastPageInChapter: 'Last page in chapter',
83
+ pagesLeft: (n) => `${n} page${n === 1 ? '' : 's'} left in chapter`,
84
+ pageOfTotal: (p, t) => `${p} of ${t}`,
85
+ pageOfTotalLong: (p, t) => `Page ${p} of ${t}`,
86
+ returnToPage: (p) => `Return to page ${p}`,
87
+ formatNumber: (n) => String(n)
88
+ };
89
+ const LabelsContext = (0, react_1.createContext)(exports.DEFAULT_LABELS);
90
+ exports.LabelsProvider = LabelsContext.Provider;
91
+ function useLabels() {
92
+ return (0, react_1.useContext)(LabelsContext);
93
+ }
94
+ function mergeLabels(partial) {
95
+ return partial ? { ...exports.DEFAULT_LABELS, ...partial } : exports.DEFAULT_LABELS;
96
+ }
package/lib/themes.d.ts CHANGED
@@ -1,19 +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;
20
+ right?: number;
21
+ }, fonts?: CustomFont[], themes?: ReaderTheme[],
22
+ /** false: no running header / footer, and no space kept for them */
23
+ runningLabels?: boolean): {
17
24
  bg: string;
18
25
  fg: string;
19
26
  link: string;
@@ -31,7 +38,11 @@ export declare function toEngineSettings(settings: ReaderSettings, systemDark: b
31
38
  insets: {
32
39
  top: number;
33
40
  bottom: number;
41
+ left: number;
42
+ right: number;
34
43
  };
44
+ showHeader: boolean;
45
+ showFooter: boolean;
35
46
  };
36
47
  export interface ChromeColors {
37
48
  /** translucent control background (pills, circles), tinted with the page colour */
@@ -47,10 +58,21 @@ export interface ChromeColors {
47
58
  separator: string;
48
59
  /** highlight for the current chapter / selected items */
49
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;
50
65
  dark: boolean;
51
66
  }
52
67
  /**
53
68
  * Chrome (buttons, menus, sheets) is frosted glass tinted with the page colour, so a Calm page gets warm glass and a
54
69
  * black page gets dark glass. Text and icons use the neutral text colour of the light / dark variant.
55
70
  */
56
- 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 }
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;
@@ -126,8 +164,51 @@ export interface ReaderSettings {
126
164
  /** 'auto' follows the book's page-progression-direction / language */
127
165
  direction: 'auto' | 'ltr' | 'rtl';
128
166
  }
167
+ /**
168
+ * Where the book comes from.
169
+ * - uri: file://, content:// (Android), https://, or an asset/bundle URI that fetch() can read. `headers` are sent with the request.
170
+ * - base64: the EPUB bytes as base64 (a data: prefix is accepted).
171
+ * `key` identifies the book: when it changes the reader opens the new source. Defaults to the uri, or to a fingerprint of the data.
172
+ */
129
173
  export type EpubSource = {
130
174
  uri: string;
175
+ headers?: Record<string, string>;
176
+ key?: string;
131
177
  } | {
132
178
  base64: string;
179
+ key?: string;
133
180
  };
181
+ /** Safe-area space around the page, in points. Left/right matter in landscape on notched phones. */
182
+ export interface SafeInsets {
183
+ top: number;
184
+ bottom: number;
185
+ left?: number;
186
+ right?: number;
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 {};