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.
- package/CHANGELOG.md +60 -0
- package/README.md +178 -20
- package/lib/EpubReader.d.ts +66 -15
- package/lib/EpubReader.js +168 -30
- package/lib/EpubReaderView.d.ts +37 -5
- package/lib/EpubReaderView.js +194 -93
- package/lib/cfiOrder.d.ts +2 -0
- package/lib/cfiOrder.js +34 -0
- package/lib/engine/html.js +1 -1
- package/lib/index.d.ts +5 -2
- package/lib/index.js +5 -1
- package/lib/strings.d.ts +94 -0
- package/lib/strings.js +96 -0
- package/lib/themes.d.ts +28 -6
- package/lib/themes.js +80 -20
- package/lib/types.d.ts +82 -1
- package/lib/ui/AppearanceSheet.d.ts +4 -2
- package/lib/ui/AppearanceSheet.js +40 -26
- package/lib/ui/ContentsSheet.d.ts +2 -0
- package/lib/ui/ContentsSheet.js +32 -22
- package/lib/ui/CustomizeSheet.d.ts +4 -2
- package/lib/ui/CustomizeSheet.js +31 -27
- package/lib/ui/HighlightMenu.d.ts +4 -2
- package/lib/ui/HighlightMenu.js +13 -11
- package/lib/ui/NoteEditor.js +12 -9
- package/lib/ui/SearchSheet.js +19 -6
- package/lib/ui/Sheet.js +7 -4
- package/lib/ui/Text.d.ts +9 -0
- package/lib/ui/Text.js +62 -0
- package/package.json +81 -76
- package/src/EpubReader.tsx +239 -43
- package/src/EpubReaderView.tsx +287 -99
- package/src/cfiOrder.ts +28 -0
- package/src/engine/epubcfi.js +527 -0
- package/src/engine/html.ts +1 -1
- package/src/engine/reader.js +1273 -157
- package/src/index.ts +5 -2
- package/src/strings.ts +187 -0
- package/src/themes.ts +97 -21
- package/src/types.ts +88 -2
- package/src/ui/AppearanceSheet.tsx +47 -29
- package/src/ui/ContentsSheet.tsx +34 -22
- package/src/ui/CustomizeSheet.tsx +27 -21
- package/src/ui/HighlightMenu.tsx +17 -13
- package/src/ui/NoteEditor.tsx +12 -9
- package/src/ui/SearchSheet.tsx +22 -5
- package/src/ui/Sheet.tsx +8 -5
- package/src/ui/Text.tsx +27 -0
package/src/index.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/src/strings.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Every text the reader shows. Pass a partial object as the `labels` prop of EpubReaderView to translate
|
|
5
|
+
* (for example into Pashto, Dari or Arabic); anything you leave out stays English.
|
|
6
|
+
*/
|
|
7
|
+
export interface ReaderLabels {
|
|
8
|
+
contents: string;
|
|
9
|
+
chapters: string;
|
|
10
|
+
font: string;
|
|
11
|
+
lineSpacing: string;
|
|
12
|
+
characterSpacing: string;
|
|
13
|
+
wordSpacing: string;
|
|
14
|
+
margins: string;
|
|
15
|
+
columns: string;
|
|
16
|
+
columnsAuto: string;
|
|
17
|
+
columnsOne: string;
|
|
18
|
+
columnsTwo: string;
|
|
19
|
+
slide: string;
|
|
20
|
+
curl: string;
|
|
21
|
+
fastFade: string;
|
|
22
|
+
scrollMode: string;
|
|
23
|
+
light: string;
|
|
24
|
+
dark: string;
|
|
25
|
+
matchDevice: string;
|
|
26
|
+
matchSurroundings: string;
|
|
27
|
+
appearance: string;
|
|
28
|
+
pageTurnStyle: string;
|
|
29
|
+
delete: string;
|
|
30
|
+
deleteBookmark: string;
|
|
31
|
+
deleteHighlight: string;
|
|
32
|
+
search: string;
|
|
33
|
+
searchBook: string;
|
|
34
|
+
searchInBook: string;
|
|
35
|
+
searching: string;
|
|
36
|
+
noResults: string;
|
|
37
|
+
themesSettings: string;
|
|
38
|
+
customizeTheme: string;
|
|
39
|
+
customize: string;
|
|
40
|
+
resetTheme: string;
|
|
41
|
+
boldText: string;
|
|
42
|
+
justifyText: string;
|
|
43
|
+
pageTurnSound: string;
|
|
44
|
+
accessibilityLayout: string;
|
|
45
|
+
smallerText: string;
|
|
46
|
+
largerText: string;
|
|
47
|
+
readerMenu: string;
|
|
48
|
+
closeBook: string;
|
|
49
|
+
share: string;
|
|
50
|
+
rotationLock: string;
|
|
51
|
+
rotationLockNeedsPackage: string;
|
|
52
|
+
lineGuide: string;
|
|
53
|
+
turnOffLineGuide: string;
|
|
54
|
+
backgroundDimming: string;
|
|
55
|
+
dimHigh: string;
|
|
56
|
+
dimMedium: string;
|
|
57
|
+
dimLow: string;
|
|
58
|
+
dimNone: string;
|
|
59
|
+
bookmarkPage: string;
|
|
60
|
+
highlight: string;
|
|
61
|
+
note: string;
|
|
62
|
+
addNote: string;
|
|
63
|
+
addANote: string;
|
|
64
|
+
underline: string;
|
|
65
|
+
removeHighlight: string;
|
|
66
|
+
dismiss: string;
|
|
67
|
+
done: string;
|
|
68
|
+
close: string;
|
|
69
|
+
cancel: string;
|
|
70
|
+
save: string;
|
|
71
|
+
ok: string;
|
|
72
|
+
noToc: string;
|
|
73
|
+
noBookmarks: string;
|
|
74
|
+
noHighlights: string;
|
|
75
|
+
bookmarks: string;
|
|
76
|
+
highlights: string;
|
|
77
|
+
loading: string;
|
|
78
|
+
couldNotOpen: string;
|
|
79
|
+
tryAgain: string;
|
|
80
|
+
openLink: string;
|
|
81
|
+
open: string;
|
|
82
|
+
lastPageInChapter: string;
|
|
83
|
+
/** "N pages left in chapter" */
|
|
84
|
+
pagesLeft: (n: number) => string;
|
|
85
|
+
/** "3 of 120" */
|
|
86
|
+
pageOfTotal: (page: number, total: number) => string;
|
|
87
|
+
/** "Page 3 of 120" */
|
|
88
|
+
pageOfTotalLong: (page: number, total: number) => string;
|
|
89
|
+
returnToPage: (page: number) => string;
|
|
90
|
+
/** how numbers are written (e.g. Arabic-Indic digits for an Arabic UI) */
|
|
91
|
+
formatNumber: (n: number) => string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const DEFAULT_LABELS: ReaderLabels = {
|
|
95
|
+
contents: 'Contents',
|
|
96
|
+
chapters: 'Chapters',
|
|
97
|
+
font: 'Font',
|
|
98
|
+
lineSpacing: 'LINE SPACING',
|
|
99
|
+
characterSpacing: 'CHARACTER SPACING',
|
|
100
|
+
wordSpacing: 'WORD SPACING',
|
|
101
|
+
margins: 'MARGINS',
|
|
102
|
+
columns: 'Columns',
|
|
103
|
+
columnsAuto: 'Auto Set',
|
|
104
|
+
columnsOne: 'One',
|
|
105
|
+
columnsTwo: 'Two',
|
|
106
|
+
slide: 'Slide',
|
|
107
|
+
curl: 'Curl',
|
|
108
|
+
fastFade: 'Fast Fade',
|
|
109
|
+
scrollMode: 'Scroll',
|
|
110
|
+
light: 'Light',
|
|
111
|
+
dark: 'Dark',
|
|
112
|
+
matchDevice: 'Match Device',
|
|
113
|
+
matchSurroundings: 'Match Surroundings',
|
|
114
|
+
appearance: 'Appearance',
|
|
115
|
+
pageTurnStyle: 'Page turn style',
|
|
116
|
+
delete: 'Delete',
|
|
117
|
+
deleteBookmark: 'Delete bookmark?',
|
|
118
|
+
deleteHighlight: 'Delete highlight?',
|
|
119
|
+
search: 'Search',
|
|
120
|
+
searchBook: 'Search Book',
|
|
121
|
+
searchInBook: 'Search in book',
|
|
122
|
+
searching: 'Searching…',
|
|
123
|
+
noResults: 'No results',
|
|
124
|
+
themesSettings: 'Themes & Settings',
|
|
125
|
+
customizeTheme: 'Customize Theme',
|
|
126
|
+
customize: 'Customize',
|
|
127
|
+
resetTheme: 'Reset Theme',
|
|
128
|
+
boldText: 'Bold Text',
|
|
129
|
+
justifyText: 'Justify Text',
|
|
130
|
+
pageTurnSound: 'Page Turn Sound',
|
|
131
|
+
accessibilityLayout: 'Accessibility & Layout Options',
|
|
132
|
+
smallerText: 'Smaller text',
|
|
133
|
+
largerText: 'Larger text',
|
|
134
|
+
readerMenu: 'Reader menu',
|
|
135
|
+
closeBook: 'Close book',
|
|
136
|
+
share: 'Share',
|
|
137
|
+
rotationLock: 'Rotation lock',
|
|
138
|
+
rotationLockNeedsPackage: 'Install expo-screen-orientation to enable the rotation lock.',
|
|
139
|
+
lineGuide: 'Line guide',
|
|
140
|
+
turnOffLineGuide: 'Turn Off Line Guide',
|
|
141
|
+
backgroundDimming: 'Background Dimming',
|
|
142
|
+
dimHigh: 'High',
|
|
143
|
+
dimMedium: 'Medium',
|
|
144
|
+
dimLow: 'Low',
|
|
145
|
+
dimNone: 'None',
|
|
146
|
+
bookmarkPage: 'Bookmark this page',
|
|
147
|
+
highlight: 'Highlight',
|
|
148
|
+
note: 'Note',
|
|
149
|
+
addNote: 'Add note',
|
|
150
|
+
addANote: 'Add a note',
|
|
151
|
+
underline: 'Underline',
|
|
152
|
+
removeHighlight: 'Remove highlight',
|
|
153
|
+
dismiss: 'Dismiss',
|
|
154
|
+
done: 'Done',
|
|
155
|
+
close: 'Close',
|
|
156
|
+
cancel: 'Cancel',
|
|
157
|
+
save: 'Save',
|
|
158
|
+
ok: 'OK',
|
|
159
|
+
noToc: 'No table of contents',
|
|
160
|
+
noBookmarks: 'No bookmarks yet. Tap the bookmark button while reading.',
|
|
161
|
+
noHighlights: 'No highlights or notes yet. Select text to add one.',
|
|
162
|
+
bookmarks: 'Bookmarks',
|
|
163
|
+
highlights: 'Highlights',
|
|
164
|
+
loading: 'Opening book…',
|
|
165
|
+
couldNotOpen: 'This book could not be opened',
|
|
166
|
+
tryAgain: 'Try again',
|
|
167
|
+
openLink: 'Open this link?',
|
|
168
|
+
open: 'Open',
|
|
169
|
+
lastPageInChapter: 'Last page in chapter',
|
|
170
|
+
pagesLeft: (n) => `${n} page${n === 1 ? '' : 's'} left in chapter`,
|
|
171
|
+
pageOfTotal: (p, t) => `${p} of ${t}`,
|
|
172
|
+
pageOfTotalLong: (p, t) => `Page ${p} of ${t}`,
|
|
173
|
+
returnToPage: (p) => `Return to page ${p}`,
|
|
174
|
+
formatNumber: (n) => String(n)
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const LabelsContext = createContext<ReaderLabels>(DEFAULT_LABELS);
|
|
178
|
+
|
|
179
|
+
export const LabelsProvider = LabelsContext.Provider;
|
|
180
|
+
export function useLabels(): ReaderLabels {
|
|
181
|
+
return useContext(LabelsContext);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function mergeLabels(partial?: Partial<ReaderLabels>): ReaderLabels {
|
|
185
|
+
return partial ? { ...DEFAULT_LABELS, ...partial } : DEFAULT_LABELS;
|
|
186
|
+
}
|
|
187
|
+
|
package/src/themes.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
-
import type { HighlightColor, ReaderFont, ReaderSettings, ReaderTheme, ThemeColors } from './types';
|
|
2
|
+
import type { CustomFont, HighlightColor, ReaderFont, ReaderSettings, ReaderTheme, ThemeColors } from './types';
|
|
3
3
|
|
|
4
4
|
export const THEMES: ReaderTheme[] = [
|
|
5
5
|
{
|
|
@@ -85,32 +85,55 @@ export const DEFAULT_SETTINGS: ReaderSettings = {
|
|
|
85
85
|
direction: 'auto'
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
export const
|
|
88
|
+
/** `themes`: the host's own list (see the `themes` prop), or the built-in one. Unknown ids get the first theme. */
|
|
89
|
+
export const getTheme = (id: string, themes: ReaderTheme[] = THEMES): ReaderTheme =>
|
|
90
|
+
themes.find((t) => t.id === id) || themes[0] || THEMES[0];
|
|
91
|
+
/** The built-in fonts plus the app's own (the CustomFont entries that have an id). */
|
|
92
|
+
export function fontChoices(custom?: CustomFont[]): ReaderFont[] {
|
|
93
|
+
// one entry per id: a family shipped as several files (regular, bold ...) shares one id
|
|
94
|
+
const seen = new Set<string>();
|
|
95
|
+
const extra = (custom || [])
|
|
96
|
+
.filter((f) => f.id && !seen.has(f.id) && !!seen.add(f.id))
|
|
97
|
+
.map((f) => ({ id: f.id as string, name: f.name || f.family, css: `"${f.family}"` }));
|
|
98
|
+
return extra.length ? FONTS.concat(extra) : FONTS;
|
|
99
|
+
}
|
|
100
|
+
export const getFont = (id: string, custom?: CustomFont[]): ReaderFont => {
|
|
101
|
+
const list = fontChoices(custom);
|
|
102
|
+
return list.find((f) => f.id === id) || list[0];
|
|
103
|
+
};
|
|
90
104
|
export const serifFont = SERIF;
|
|
91
105
|
|
|
92
106
|
export function isDark(settings: ReaderSettings, systemDark: boolean): boolean {
|
|
93
107
|
return settings.appearance === 'device' ? systemDark : settings.appearance === 'dark';
|
|
94
108
|
}
|
|
95
109
|
|
|
96
|
-
export function themeColors(settings: ReaderSettings, systemDark: boolean): ThemeColors {
|
|
97
|
-
const t = getTheme(settings.themeId);
|
|
110
|
+
export function themeColors(settings: ReaderSettings, systemDark: boolean, themes?: ReaderTheme[]): ThemeColors {
|
|
111
|
+
const t = getTheme(settings.themeId, themes);
|
|
98
112
|
return isDark(settings, systemDark) ? t.dark : t.light;
|
|
99
113
|
}
|
|
100
114
|
|
|
101
115
|
const BASE_MARGIN = 28;
|
|
102
116
|
|
|
103
117
|
/** Settings object understood by the WebView engine. */
|
|
104
|
-
export function toEngineSettings(
|
|
105
|
-
|
|
106
|
-
|
|
118
|
+
export function toEngineSettings(
|
|
119
|
+
settings: ReaderSettings,
|
|
120
|
+
systemDark: boolean,
|
|
121
|
+
insets: { top: number; bottom: number; left?: number; right?: number },
|
|
122
|
+
fonts?: CustomFont[],
|
|
123
|
+
themes?: ReaderTheme[],
|
|
124
|
+
/** false: no running header / footer, and no space kept for them */
|
|
125
|
+
runningLabels = true
|
|
126
|
+
) {
|
|
127
|
+
const theme = getTheme(settings.themeId, themes);
|
|
128
|
+
const labelSpace = runningLabels ? 40 : 0;
|
|
129
|
+
const c = themeColors(settings, systemDark, themes);
|
|
107
130
|
const custom = settings.customize;
|
|
108
131
|
return {
|
|
109
132
|
bg: c.bg,
|
|
110
133
|
fg: c.fg,
|
|
111
134
|
link: c.link,
|
|
112
135
|
bold: !!theme.bold || settings.bold,
|
|
113
|
-
fontFamily: getFont(settings.fontId).css,
|
|
136
|
+
fontFamily: getFont(settings.fontId, fonts).css,
|
|
114
137
|
fontSize: settings.fontSize,
|
|
115
138
|
lineHeight: custom ? settings.lineHeight : 1.5,
|
|
116
139
|
letterSpacing: custom ? (settings.letterSpacing / 100) * 0.25 : 0,
|
|
@@ -120,7 +143,9 @@ export function toEngineSettings(settings: ReaderSettings, systemDark: boolean,
|
|
|
120
143
|
justify: settings.justify,
|
|
121
144
|
mode: settings.pageTurn,
|
|
122
145
|
direction: settings.direction,
|
|
123
|
-
insets: { top: insets.top +
|
|
146
|
+
insets: { top: insets.top + labelSpace, bottom: insets.bottom + labelSpace, left: insets.left || 0, right: insets.right || 0 },
|
|
147
|
+
showHeader: runningLabels,
|
|
148
|
+
showFooter: runningLabels
|
|
124
149
|
};
|
|
125
150
|
}
|
|
126
151
|
|
|
@@ -138,19 +163,44 @@ export interface ChromeColors {
|
|
|
138
163
|
separator: string;
|
|
139
164
|
/** highlight for the current chapter / selected items */
|
|
140
165
|
accent: string;
|
|
166
|
+
/** solid buttons and fills (Done, the progress pill, switches). Default: black / white per control */
|
|
167
|
+
strong?: string;
|
|
168
|
+
/** text and icons on `strong` */
|
|
169
|
+
onStrong?: string;
|
|
141
170
|
dark: boolean;
|
|
142
171
|
}
|
|
143
172
|
|
|
173
|
+
const NAMED: Record<string, string> = { white: '#ffffff', black: '#000000' };
|
|
174
|
+
|
|
175
|
+
/** [r, g, b] of '#rgb', '#rgba', '#rrggbb', '#rrggbbaa', 'rgb(...)', 'rgba(...)', 'white' or 'black'. null for anything else. */
|
|
176
|
+
function rgbOf(color: string): number[] | null {
|
|
177
|
+
const c = (NAMED[color.trim().toLowerCase()] || color).trim();
|
|
178
|
+
let m = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(c);
|
|
179
|
+
if (m) {
|
|
180
|
+
const h = m[1].length <= 4 ? m[1].replace(/./g, '$&$&') : m[1];
|
|
181
|
+
return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
|
|
182
|
+
}
|
|
183
|
+
m = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(c);
|
|
184
|
+
if (m) return [m[1], m[2], m[3]].map((v) => Math.min(255, Math.round(+v)));
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// a theme colour the chrome cannot read falls back to plain white / black
|
|
189
|
+
function hexOf(color: string, dark: boolean): string {
|
|
190
|
+
const v = rgbOf(color) || (dark ? [0, 0, 0] : [255, 255, 255]);
|
|
191
|
+
return '#' + v.map((n) => n.toString(16).padStart(2, '0')).join('');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// both colours are '#rrggbb' here (see hexOf)
|
|
144
195
|
function mix(hex: string, other: string, amount: number): string {
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
const b = p(other);
|
|
196
|
+
const a = rgbOf(hex)!;
|
|
197
|
+
const b = rgbOf(other)!;
|
|
148
198
|
const m = a.map((v, i) => Math.round(v + (b[i] - v) * amount));
|
|
149
199
|
return '#' + m.map((v) => v.toString(16).padStart(2, '0')).join('');
|
|
150
200
|
}
|
|
151
201
|
|
|
152
202
|
function rgba(hex: string, alpha: number): string {
|
|
153
|
-
const v =
|
|
203
|
+
const v = rgbOf(hex)!;
|
|
154
204
|
return `rgba(${v[0]},${v[1]},${v[2]},${alpha})`;
|
|
155
205
|
}
|
|
156
206
|
|
|
@@ -158,13 +208,39 @@ function rgba(hex: string, alpha: number): string {
|
|
|
158
208
|
* Chrome (buttons, menus, sheets) is frosted glass tinted with the page colour, so a Calm page gets warm glass and a
|
|
159
209
|
* black page gets dark glass. Text and icons use the neutral text colour of the light / dark variant.
|
|
160
210
|
*/
|
|
161
|
-
export function chromeColors(colors: ThemeColors, dark: boolean): ChromeColors {
|
|
211
|
+
export function chromeColors(colors: ThemeColors, dark: boolean, chrome?: ChromeOverrides): ChromeColors {
|
|
212
|
+
const own = chrome && (dark ? chrome.dark : chrome.light);
|
|
213
|
+
const base = defaultChrome(colors, dark);
|
|
214
|
+
if (!own) return base;
|
|
215
|
+
// a key set to undefined keeps the default
|
|
216
|
+
const set = Object.fromEntries(Object.entries(own).filter(([, v]) => v !== undefined)) as Partial<ChromeColors>;
|
|
217
|
+
const out = { ...base, ...set, dark };
|
|
218
|
+
// a host `strong` without `onStrong`: black or white, whichever reads on it
|
|
219
|
+
if (set.strong && !set.onStrong) out.onStrong = textOn(set.strong);
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** '#000000' on a light colour, '#ffffff' on a dark one (or one that cannot be read). */
|
|
224
|
+
export function textOn(color: string): string {
|
|
225
|
+
const v = rgbOf(color);
|
|
226
|
+
if (!v) return '#ffffff';
|
|
227
|
+
return (0.299 * v[0] + 0.587 * v[1] + 0.114 * v[2]) / 255 > 0.6 ? '#000000' : '#ffffff';
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** The host's chrome colours for light and dark pages (see the `chrome` prop). Missing ones keep the default. */
|
|
231
|
+
export interface ChromeOverrides {
|
|
232
|
+
light?: Partial<Omit<ChromeColors, 'dark'>>;
|
|
233
|
+
dark?: Partial<Omit<ChromeColors, 'dark'>>;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function defaultChrome(colors: ThemeColors, dark: boolean): ChromeColors {
|
|
237
|
+
const bg = hexOf(colors.bg, dark);
|
|
162
238
|
if (dark) {
|
|
163
239
|
return {
|
|
164
|
-
glass: rgba(mix(
|
|
240
|
+
glass: rgba(mix(bg, '#ffffff', 0.22), 0.4),
|
|
165
241
|
glassBorder: 'rgba(255,255,255,0.16)',
|
|
166
|
-
sheet: mix(
|
|
167
|
-
sheetGlass: rgba(mix(
|
|
242
|
+
sheet: mix(bg, '#ffffff', 0.1),
|
|
243
|
+
sheetGlass: rgba(mix(bg, '#ffffff', 0.1), 0.84),
|
|
168
244
|
card: 'rgba(255,255,255,0.1)',
|
|
169
245
|
text: '#ffffff',
|
|
170
246
|
subtext: '#a09d96',
|
|
@@ -174,10 +250,10 @@ export function chromeColors(colors: ThemeColors, dark: boolean): ChromeColors {
|
|
|
174
250
|
};
|
|
175
251
|
}
|
|
176
252
|
return {
|
|
177
|
-
glass: rgba(mix(
|
|
253
|
+
glass: rgba(mix(bg, '#ffffff', 0.55), 0.5),
|
|
178
254
|
glassBorder: 'rgba(0,0,0,0.1)',
|
|
179
|
-
sheet: mix(
|
|
180
|
-
sheetGlass: rgba(mix(
|
|
255
|
+
sheet: mix(bg, '#ffffff', 0.5),
|
|
256
|
+
sheetGlass: rgba(mix(bg, '#ffffff', 0.5), 0.86),
|
|
181
257
|
card: 'rgba(0,0,0,0.06)',
|
|
182
258
|
text: '#000000',
|
|
183
259
|
subtext: '#6c6c70',
|
package/src/types.ts
CHANGED
|
@@ -13,17 +13,30 @@ export interface Highlight {
|
|
|
13
13
|
start: number;
|
|
14
14
|
end: number;
|
|
15
15
|
text: string;
|
|
16
|
-
|
|
16
|
+
/** a built-in colour name, or a key of the `highlightColors` prop, or a CSS colour such as '#ffff00' */
|
|
17
|
+
color: HighlightColor | (string & {});
|
|
18
|
+
/** epub.js range CFI. When set, it decides where the highlight is (spine/start/end are ignored). */
|
|
19
|
+
cfi?: string;
|
|
17
20
|
style?: HighlightStyle;
|
|
18
21
|
note?: string;
|
|
19
22
|
chapter?: string;
|
|
20
23
|
createdAt: number;
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
/** A highlight known only by its epub.js CFI (for example one saved by an epub.js reader). The engine finds the text. */
|
|
27
|
+
export interface CfiHighlight {
|
|
28
|
+
id: string;
|
|
29
|
+
cfi: string;
|
|
30
|
+
color: Highlight['color'];
|
|
31
|
+
style?: HighlightStyle;
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
export interface Bookmark {
|
|
24
35
|
id: string;
|
|
25
36
|
spine: number;
|
|
26
37
|
offset: number;
|
|
38
|
+
/** epub.js point CFI of the same spot */
|
|
39
|
+
cfi?: string;
|
|
27
40
|
chapter: string;
|
|
28
41
|
excerpt: string;
|
|
29
42
|
progress: number;
|
|
@@ -32,9 +45,12 @@ export interface Bookmark {
|
|
|
32
45
|
|
|
33
46
|
export interface TocItem {
|
|
34
47
|
label: string;
|
|
48
|
+
/** -1 when the entry's file is not in the book (only in the `all` list of onToc) */
|
|
35
49
|
spine: number;
|
|
36
50
|
fragment: string;
|
|
37
51
|
level: number;
|
|
52
|
+
/** path relative to the package (.opf) file, with '#fragment' when there is one, e.g. 'text/ch1.xhtml#s2' */
|
|
53
|
+
href: string;
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
export interface BookMetadata {
|
|
@@ -60,6 +76,28 @@ export interface RelocateEvent {
|
|
|
60
76
|
chapter: string;
|
|
61
77
|
excerpt: string;
|
|
62
78
|
indexed: boolean;
|
|
79
|
+
/** href of the spine item, relative to the package (.opf) file (epub.js location.start.href) */
|
|
80
|
+
href: string;
|
|
81
|
+
/** index in the TOC list (onToc) of the entry this page belongs to, -1 before the first entry */
|
|
82
|
+
tocIndex: number;
|
|
83
|
+
/** epub.js point CFI of the first character on the page */
|
|
84
|
+
startCfi?: string;
|
|
85
|
+
/** epub.js point CFI just after the last character on the page */
|
|
86
|
+
endCfi?: string;
|
|
87
|
+
/** epub.js locations ("chunks") of this page, once they are counted (see onLocations) */
|
|
88
|
+
locations?: LocationsInfo;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The page's place in the epub.js locations of the book. Same numbers as epub.js gives for the same CFIs. */
|
|
92
|
+
export interface LocationsInfo {
|
|
93
|
+
/** location index of startCfi (epub.js locationFromCfi) */
|
|
94
|
+
start: number;
|
|
95
|
+
/** location index of endCfi */
|
|
96
|
+
end: number;
|
|
97
|
+
/** number of locations in the book (epub.js locations.total + 1) */
|
|
98
|
+
count: number;
|
|
99
|
+
/** 0..1, epub.js percentageFromCfi(startCfi) */
|
|
100
|
+
progress: number;
|
|
63
101
|
}
|
|
64
102
|
|
|
65
103
|
export interface SelectionEvent {
|
|
@@ -68,6 +106,8 @@ export interface SelectionEvent {
|
|
|
68
106
|
end: number;
|
|
69
107
|
text: string;
|
|
70
108
|
rect: { x: number; y: number; width: number; height: number };
|
|
109
|
+
/** epub.js range CFI of the selection */
|
|
110
|
+
cfi?: string;
|
|
71
111
|
}
|
|
72
112
|
|
|
73
113
|
export interface SearchResult {
|
|
@@ -135,4 +175,50 @@ export interface ReaderSettings {
|
|
|
135
175
|
direction: 'auto' | 'ltr' | 'rtl';
|
|
136
176
|
}
|
|
137
177
|
|
|
138
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Where the book comes from.
|
|
180
|
+
* - uri: file://, content:// (Android), https://, or an asset/bundle URI that fetch() can read. `headers` are sent with the request.
|
|
181
|
+
* - base64: the EPUB bytes as base64 (a data: prefix is accepted).
|
|
182
|
+
* `key` identifies the book: when it changes the reader opens the new source. Defaults to the uri, or to a fingerprint of the data.
|
|
183
|
+
*/
|
|
184
|
+
export type EpubSource =
|
|
185
|
+
| { uri: string; headers?: Record<string, string>; key?: string }
|
|
186
|
+
| { base64: string; key?: string };
|
|
187
|
+
|
|
188
|
+
/** Safe-area space around the page, in points. Left/right matter in landscape on notched phones. */
|
|
189
|
+
export interface SafeInsets {
|
|
190
|
+
top: number;
|
|
191
|
+
bottom: number;
|
|
192
|
+
left?: number;
|
|
193
|
+
right?: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A font shipped by the app and loaded into every chapter with @font-face. Use `family` in a ReaderFont's css. */
|
|
197
|
+
export interface CustomFont {
|
|
198
|
+
/** set it to make the font a choice for settings.fontId (and in the font list of EpubReaderView) */
|
|
199
|
+
id?: string;
|
|
200
|
+
/** name in the font list (default: family) */
|
|
201
|
+
name?: string;
|
|
202
|
+
family: string;
|
|
203
|
+
/** the font file as base64 (a data: prefix is accepted) */
|
|
204
|
+
base64: string;
|
|
205
|
+
/** e.g. 'font/ttf', 'font/otf', 'font/woff2' */
|
|
206
|
+
mime: string;
|
|
207
|
+
weight?: 'normal' | 'bold' | number;
|
|
208
|
+
style?: 'normal' | 'italic';
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Fonts for the reader's own interface (buttons, sheets, menus), e.g. the app's brand font. Not the book text.
|
|
213
|
+
* Text that asks for weight 500 uses `medium`, 600 and up uses `bold`, when given.
|
|
214
|
+
* Give `bold`: without it, iOS draws bold text (titles, search matches) in the regular font, not bold.
|
|
215
|
+
* Text fields (search, notes) use `regular`.
|
|
216
|
+
*/
|
|
217
|
+
export interface UiFonts {
|
|
218
|
+
regular: string;
|
|
219
|
+
medium?: string;
|
|
220
|
+
bold?: string;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** 'theme': every text in the theme colour. 'keep': the book's own colours stay, made readable on the theme. */
|
|
224
|
+
export type BookColors = 'theme' | 'keep';
|