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.
- package/CHANGELOG.md +60 -0
- package/README.md +158 -13
- package/lib/EpubReader.d.ts +47 -9
- package/lib/EpubReader.js +69 -16
- package/lib/EpubReaderView.d.ts +27 -2
- package/lib/EpubReaderView.js +38 -32
- 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 +1 -1
- package/lib/themes.d.ts +24 -6
- package/lib/themes.js +80 -20
- package/lib/types.d.ts +66 -1
- package/lib/ui/AppearanceSheet.d.ts +4 -2
- package/lib/ui/AppearanceSheet.js +20 -13
- package/lib/ui/ContentsSheet.d.ts +2 -0
- package/lib/ui/ContentsSheet.js +21 -13
- package/lib/ui/CustomizeSheet.d.ts +4 -2
- package/lib/ui/CustomizeSheet.js +20 -18
- package/lib/ui/HighlightMenu.d.ts +4 -2
- package/lib/ui/HighlightMenu.js +3 -3
- package/lib/ui/NoteEditor.js +6 -5
- package/lib/ui/SearchSheet.js +6 -5
- package/lib/ui/Sheet.js +5 -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 +121 -25
- package/src/EpubReaderView.tsx +61 -17
- 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 +830 -65
- package/src/index.ts +1 -1
- package/src/themes.ts +97 -21
- package/src/types.ts +71 -1
- package/src/ui/AppearanceSheet.tsx +19 -10
- package/src/ui/ContentsSheet.tsx +14 -4
- package/src/ui/CustomizeSheet.tsx +14 -10
- package/src/ui/HighlightMenu.tsx +6 -4
- package/src/ui/NoteEditor.tsx +2 -1
- package/src/ui/SearchSheet.tsx +2 -1
- package/src/ui/Sheet.tsx +4 -3
- package/src/ui/Text.tsx +27 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- The 20-second start timer only counts while the app is in front. Before, leaving the app while a book opened
|
|
7
|
+
could show "The reader could not be started" on return.
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### New
|
|
12
|
+
- epub.js CFIs on highlights, bookmarks, selections and `onRelocate` (`startCfi`, `endCfi`).
|
|
13
|
+
- epub.js locations: `onLocations`, and `locations` on `onRelocate`. Same numbers as epub.js.
|
|
14
|
+
- `goTo({ cfi })` and `initialLocation={{ cfi }}`.
|
|
15
|
+
- Highlights can use any CSS colour, or a key of the new `highlightColors` prop.
|
|
16
|
+
- Custom book fonts (`fonts`), fonts for the reader's own buttons and sheets (`uiFonts`), and `chrome` colour overrides.
|
|
17
|
+
- `bookColors`: `'theme'` or `'keep'`.
|
|
18
|
+
- `themes` prop for your own reading themes.
|
|
19
|
+
|
|
20
|
+
### Breaking
|
|
21
|
+
- `menuItems` and `onMenuAction` are removed from `EpubReader`. They added items to the system selection menu,
|
|
22
|
+
which is now off. Use `onSelection` and your own UI instead.
|
|
23
|
+
- `TocItem.href` is new and required.
|
|
24
|
+
- `RelocateEvent.href` and `RelocateEvent.tocIndex` are new and required.
|
|
25
|
+
- `Highlight.color` is now any string, not only `HighlightColor`. Code like `MAP[h.color]` needs a check or a cast.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
- The system text selection is off. The reader's own long press and menu replace it.
|
|
29
|
+
- A highlight whose CFI is not found is drawn from its `spine` / `start` / `end` offsets.
|
|
30
|
+
- `goTo({ cfi })` with a CFI that is not found goes to the given `spine` / `offset`, or else the nearest chapter. It
|
|
31
|
+
no longer jumps to the start of the book.
|
|
32
|
+
- A book with no text (only images) has no `locations` on `onRelocate`.
|
|
33
|
+
- `.html` chapters are read like epub.js reads them (as HTML). A newline right after `<pre>` no longer counts, so
|
|
34
|
+
offsets saved after one in an `.html` chapter move by one. CFIs are not affected.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
- Dragging a selection to a paragraph's full stop, or just below it, no longer takes the first word of the next
|
|
38
|
+
paragraph. A dragged selection also takes the punctuation touching its ends, so it can end on the full stop.
|
|
39
|
+
- An `.html` chapter written as XHTML (for example with `<title/>`) is no longer blank.
|
|
40
|
+
- Changing `fonts` twice while a book opens no longer loses the fonts.
|
|
41
|
+
- Font data that is not base64 is skipped with a non-fatal `onError`, instead of going into the page script.
|
|
42
|
+
- Theme `bg` colours other than `#rrggbb` no longer break the reader's buttons and sheets.
|
|
43
|
+
- Tapping a bookmark or highlight goes to its CFI. The notes list is sorted by CFI.
|
|
44
|
+
- Host highlight colours (names like `tomato`, `hsl()`, 8-digit hex) are plain `rgba()`, so they show on iOS 15.
|
|
45
|
+
- `bookColors: 'keep'`: a theme `bg` in any CSS form is read correctly. Plain links follow a theme change.
|
|
46
|
+
- TOC `href` is the manifest href as written (`chapter%201.xhtml`), so it equals `relocate.href`, like epub.js.
|
|
47
|
+
- A page with only a picture has `endCfi` equal to `startCfi`.
|
|
48
|
+
- `selection.cfi` is always set. It is no longer `undefined` when the chapter's CFI data was dropped from the cache.
|
|
49
|
+
- A chapter is shown before its CFI data is built, so it opens faster.
|
|
50
|
+
- Fonts that share an `id` (regular and bold files) show once in the font list.
|
|
51
|
+
- A `chrome` key set to `undefined` keeps the default. A host `strong` without `onStrong` gets black or white text,
|
|
52
|
+
whichever reads on it. The progress pill uses `strong` on dark pages too.
|
|
53
|
+
- The search and note fields use the `uiFonts` regular font.
|
|
54
|
+
|
|
55
|
+
### Tests
|
|
56
|
+
- epub.js 0.3.93 is now a pinned devDependency. The compare test no longer needs another repo.
|
|
57
|
+
- New test books: nested TOC with a missing file, a file name with a space, special ids, `<img>`, vertical text,
|
|
58
|
+
XHTML saved as `.html`, a missing spine file, a picture-only book. A small test font is built in code.
|
|
59
|
+
- Old books are deleted before each run. Checks that cannot run are shown as skipped, not as passed.
|
|
60
|
+
- A missing Chrome gives a clear message (set `CHROME_PATH`).
|
package/README.md
CHANGED
|
@@ -19,13 +19,14 @@ It is one component with a full reading UI (`EpubReaderView`), plus a headless e
|
|
|
19
19
|
3. [Saving and restoring](#saving-and-restoring)
|
|
20
20
|
4. [`EpubReaderView` props](#epubreaderview-props)
|
|
21
21
|
5. [Headless `EpubReader`](#headless-epubreader)
|
|
22
|
-
6. [
|
|
23
|
-
7. [
|
|
24
|
-
8. [
|
|
25
|
-
9. [
|
|
26
|
-
10. [
|
|
27
|
-
11. [
|
|
28
|
-
12. [
|
|
22
|
+
6. [epub.js compatibility](#epubjs-compatibility)
|
|
23
|
+
7. [Data types](#data-types)
|
|
24
|
+
8. [Settings reference](#settings-reference)
|
|
25
|
+
9. [Right-to-left books](#right-to-left-books)
|
|
26
|
+
10. [What the user can do](#what-the-user-can-do)
|
|
27
|
+
11. [Troubleshooting](#troubleshooting)
|
|
28
|
+
12. [Limitations](#limitations)
|
|
29
|
+
13. [Credits and license](#credits-and-license)
|
|
29
30
|
|
|
30
31
|
---
|
|
31
32
|
|
|
@@ -159,7 +160,7 @@ changes font size, theme or rotates the device.
|
|
|
159
160
|
| `safeInsets` | `{ top; bottom; left?; right? }` | Status-bar, home-indicator and (landscape) notch space. Use `useSafeAreaInsets()` from `react-native-safe-area-context`. Without it a guess from the screen size is used. |
|
|
160
161
|
| `labels` | `Partial<ReaderLabels>` | Every text of the interface, for translation (Pashto, Dari, Arabic ...). `formatNumber` lets you show Arabic-Indic digits. See `DEFAULT_LABELS`. |
|
|
161
162
|
| `maxFileSize` | `number` | Largest EPUB in bytes (default 150 MB, `0` = no limit). Bigger files raise an error instead of crashing low-memory phones. |
|
|
162
|
-
| `initialLocation` | `{ spine
|
|
163
|
+
| `initialLocation` | `{ spine; offset } \| { cfi }` | Where to open: an offset, or an epub.js CFI. Defaults to the start. |
|
|
163
164
|
| `initialSettings` | `Partial<ReaderSettings>` | Theme, font, size, spacing ... |
|
|
164
165
|
| `initialHighlights` | `Highlight[]` | |
|
|
165
166
|
| `initialBookmarks` | `Bookmark[]` | |
|
|
@@ -171,6 +172,18 @@ changes font size, theme or rotates the device.
|
|
|
171
172
|
| `onMetadata` | `(m: BookMetadata) => void` | `title`, `author`, `language`, `publisher`. |
|
|
172
173
|
| `onCover` | `(dataUri: string) => void` | The cover image, if the book has one. |
|
|
173
174
|
| `onError` | `(message: string) => void` | Unreadable file, DRM, ... The reader itself shows an error screen with **Try again** and **Close**, so the user is never stuck. |
|
|
175
|
+
| `onLocations` | `(info: { count }) => void` | epub.js locations are counted. From now on `onLocationChange` has `locations`. |
|
|
176
|
+
| `highlightColors` | `Record<string, string>` | Colours of the highlight menu by name, e.g. `{ yellow: '#ffff00' }`. Default: the built-in five. |
|
|
177
|
+
| `highlightOpacity` | `number` | Fill opacity of `highlightColors`. Default `0.3`. |
|
|
178
|
+
| `fonts` | `CustomFont[]` | App fonts as base64. The ones with an `id` are added to the font list. |
|
|
179
|
+
| `bookColors` | `'theme' \| 'keep'` | Default `'theme'`. See the headless table below. |
|
|
180
|
+
| `maxZoom` | `number` | Largest pinch zoom. Default `3`, `1` turns it off. |
|
|
181
|
+
| `locationChars` | `number` | Characters per epub.js location. Default `150`, `0` turns them off. Read when the book opens. |
|
|
182
|
+
| `repairZeroWidth` | `boolean` | Default `true`. See [hidden zero-width runs](#epubjs-compatibility). Read when the book opens. |
|
|
183
|
+
| `themes` | `ReaderTheme[]` | Your own page themes, instead of the built-in six. |
|
|
184
|
+
| `chrome` | `ChromeOverrides` | Colours of buttons, sheets and menus: `{ light?: {...}, dark?: {...} }`. Missing keys keep the default. |
|
|
185
|
+
| `uiFonts` | `UiFonts` | Fonts of the interface (not the book): `{ regular, medium?, bold? }`. Give `bold`, or iOS draws bold text in the regular font. |
|
|
186
|
+
| `colorScheme` | `'light' \| 'dark'` | Light or dark for the "device" appearance. Default: the phone's setting. |
|
|
174
187
|
|
|
175
188
|
---
|
|
176
189
|
|
|
@@ -202,13 +215,129 @@ ref.current?.prev();
|
|
|
202
215
|
ref.current?.goTo({ spine: 3 });
|
|
203
216
|
ref.current?.goTo({ spine: 3, fragment: 'section-2' });
|
|
204
217
|
ref.current?.goTo({ progress: 0.5 }); // 0..1 across the whole book
|
|
218
|
+
ref.current?.goTo({ cfi, spine, offset }); // epub.js CFI; spine / offset are used if it is not found
|
|
205
219
|
ref.current?.search('word', 1); // results arrive in onSearchResults(1, results, done)
|
|
206
220
|
ref.current?.showSearchResult(result);
|
|
207
221
|
ref.current?.clearSelection();
|
|
208
222
|
ref.current?.setLabels('Chapter 3', '42 of 300'); // running header / footer drawn on the page
|
|
209
223
|
```
|
|
210
224
|
|
|
211
|
-
Extra callbacks: `onReady`, `onCover`, `onIndexed`, `
|
|
225
|
+
Extra callbacks: `onReady`, `onCover`, `onIndexed`, `onLocations`, `onHighlightTap`, `onLink`, `onLinkJump`,
|
|
226
|
+
`onDirectionChange`, `onSearchResults`, `onEndReached`, `onPageTurn`, `onZoom`, and `onError(message, { fatal })`.
|
|
227
|
+
A non-fatal error (a font that was skipped, a CFI that was not found) leaves the book open.
|
|
228
|
+
|
|
229
|
+
More props:
|
|
230
|
+
|
|
231
|
+
| Prop | Default | What it does |
|
|
232
|
+
|---|---|---|
|
|
233
|
+
| `highlightColors` | built-in five | Colours by name, e.g. `{ yellow: '#ffff00', blue: '#add8e6' }`. A highlight's `color` can also be a CSS colour itself. |
|
|
234
|
+
| `highlightOpacity` | `0.3` | Fill opacity for `highlightColors` (same as epub.js). |
|
|
235
|
+
| `fonts` | none | App fonts as base64, loaded with `@font-face` in every chapter. A font with an `id` can be picked with `settings.fontId`. |
|
|
236
|
+
| `bookColors` | `'theme'` | `'keep'`: the book's own colours stay (coloured headings, links). Grey and black text gets the theme colour. Colours that are hard to read are made lighter or darker. |
|
|
237
|
+
| `maxZoom` | `3` | Two-finger pinch zoom. `1` turns it off. While zoomed, one finger moves the page, and taps and swipes never turn it. Double tap resets. Paged modes only. |
|
|
238
|
+
| `locationChars` | `150` | Characters per epub.js location (see below). `0` turns locations off. Read when the book opens: change `source.key` to apply a new value. |
|
|
239
|
+
| `repairZeroWidth` | `true` | Shows runs of 3+ zero-width characters as U+2060, one for one (see below). Read when the book opens. |
|
|
240
|
+
| `themes` | built-in six | Your own page themes. `settings.themeId` picks one; an unknown id gets the first. `bg` must be `#rgb`, `#rrggbb` (with or without alpha), `rgb()`, `white` or `black`. |
|
|
241
|
+
| `runningLabels` | `true` | The chapter header and page footer drawn on the page. `false`: none, and no space is kept for them. |
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
<EpubReader
|
|
245
|
+
fonts={[{ id: 'nazanin', name: 'Bahij Nazanin', family: 'BahijNazanin', base64: NAZANIN_B64, mime: 'font/ttf' }]}
|
|
246
|
+
settings={{ ...settings, fontId: 'nazanin' }}
|
|
247
|
+
...
|
|
248
|
+
/>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
What the events give your own interface:
|
|
252
|
+
|
|
253
|
+
| Need | Where |
|
|
254
|
+
|---|---|
|
|
255
|
+
| Selection and its place on screen | `onSelection(sel)`: `sel.text`, `sel.rect`, `sel.cfi` |
|
|
256
|
+
| Tap on a highlight | `onHighlightTap(id, rect)` |
|
|
257
|
+
| Table of contents | `onToc(items)`: `label`, `level`, `href`, `spine`, `fragment` |
|
|
258
|
+
| Current chapter | `onRelocate(e)`: `e.chapter`, `e.tocIndex` (index in the TOC list), `e.href` |
|
|
259
|
+
| Position to save | `onRelocate(e)`: `e.startCfi` (or `e.spine` + `e.offset`) |
|
|
260
|
+
| Chunk range of the page | `onRelocate(e)`: `e.locations.start` .. `e.locations.end`, of `e.locations.count` |
|
|
261
|
+
| Search | `search(query, id)` then `onSearchResults(id, results, done)` |
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## epub.js compatibility
|
|
266
|
+
|
|
267
|
+
Use this when your app or server already stores epub.js data, or when another app still uses epub.js.
|
|
268
|
+
|
|
269
|
+
**CFIs.** The reader reads and writes epub.js CFIs. They are the same strings epub.js makes for the same spot.
|
|
270
|
+
|
|
271
|
+
- In: `initialLocation={{ cfi }}`, `goTo({ cfi })`, and highlights with a `cfi`. A highlight can be only
|
|
272
|
+
`{ id, cfi, color, style }`; the reader finds the text itself.
|
|
273
|
+
- Out: `onRelocate` gives `startCfi` and `endCfi`. `onSelection` gives `cfi` (a range CFI). `EpubReaderView` also
|
|
274
|
+
stores `cfi` on new highlights and bookmarks.
|
|
275
|
+
- A CFI you pass in is never rewritten. It is only read.
|
|
276
|
+
- When a CFI is not found in the book:
|
|
277
|
+
- A highlight that also has `spine`, `start` and `end` is drawn from those offsets.
|
|
278
|
+
- `goTo({ cfi, spine, offset })` goes to `spine` / `offset`. Without them, it goes to the nearest chapter. If there
|
|
279
|
+
is none, it stays on the page and `onError` gets a non-fatal error.
|
|
280
|
+
|
|
281
|
+
The conversion runs inside the reader, not as plain functions. It needs the chapter's DOM, and only the reader has it.
|
|
282
|
+
|
|
283
|
+
**Locations ("chunks").** The reader counts locations exactly like epub.js `book.locations.generate(150)`. The list
|
|
284
|
+
is the same, string by string. Once it is ready, `onLocations({ count })` fires, and every `onRelocate` has:
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
e.locations = {
|
|
288
|
+
start, // epub.js locationFromCfi(startCfi)
|
|
289
|
+
end, // epub.js locationFromCfi(endCfi)
|
|
290
|
+
count, // number of locations (epub.js locations.total + 1)
|
|
291
|
+
progress // 0..1, epub.js percentageFromCfi(startCfi)
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
`count` is epub.js `locations.total + 1`. So it is 1 more than `totalLocations` in `@epubjs-react-native/core`.
|
|
296
|
+
A book with no text (only images) has no locations. Then `e.locations` is not set.
|
|
297
|
+
|
|
298
|
+
Keep `locationChars` the same for a book forever if you store location numbers.
|
|
299
|
+
|
|
300
|
+
**What stays different.** Which text fits on one page depends on the layout. So the start and end of a page can
|
|
301
|
+
differ from epub.js on the same screen. For the same CFI, the location number and progress are always the same.
|
|
302
|
+
|
|
303
|
+
The chunk list can also differ from epub.js in these books. Each case shifts every chunk number after that chapter:
|
|
304
|
+
|
|
305
|
+
- A chapter that is not UTF-8 (UTF-16, or a declared charset like windows-1252). The reader decodes it; epub.js reads
|
|
306
|
+
it as UTF-8.
|
|
307
|
+
- A broken `.xhtml` chapter. The reader reads it again as HTML; epub.js counts its error page.
|
|
308
|
+
- A chapter file that is damaged. The reader counts its short "could not be read" text. A missing file counts as
|
|
309
|
+
empty.
|
|
310
|
+
|
|
311
|
+
**Limits copied from epub.js.** These CFIs work the same as in epub.js, so they also fail the same way:
|
|
312
|
+
|
|
313
|
+
- An `[id]` with `,`, `'` or `:` in it. epub.js cannot find its own CFI for those, and neither can this reader. A
|
|
314
|
+
highlight with such a CFI is not drawn from the CFI.
|
|
315
|
+
- `^` escapes (`^[`, `^]`, `^,`) are not decoded.
|
|
316
|
+
- Spatial (`@x:y`) and temporal (`~t`) parts are ignored.
|
|
317
|
+
|
|
318
|
+
A highlight that also has offsets is then drawn from its offsets.
|
|
319
|
+
|
|
320
|
+
**Hidden zero-width runs (watermarks).** Some servers hide data in the text as long runs of zero-width characters.
|
|
321
|
+
The reader never deletes them: that would move every offset and CFI after them. Instead, a run of 3 or more of
|
|
322
|
+
U+200B, U+200C, U+200D, U+FEFF is shown as U+2060 WORD JOINER, one for one. Arabic-script letters on both sides
|
|
323
|
+
still join, and the run never breaks a line. A single U+200C is real Pashto and Persian spelling and is kept.
|
|
324
|
+
Search ignores these characters. Text the reader sends to the app (excerpts, selection, TOC labels) leaves the runs out.
|
|
325
|
+
|
|
326
|
+
**Tests.** `npm run test:compat` loads the same books in epub.js and in this reader, in headless Chrome, and compares
|
|
327
|
+
chunk lists, CFIs in both directions, location numbers and progress. Set `EPUBJS_BUNDLE` to the epub.js build you
|
|
328
|
+
use, and `EPUB_DIR` to a folder of your own books.
|
|
329
|
+
|
|
330
|
+
### The book stays in memory
|
|
331
|
+
|
|
332
|
+
A `{ base64 }` source is never written to disk:
|
|
333
|
+
|
|
334
|
+
- The base64 string is sent into the WebView in pieces, with `injectJavaScript`.
|
|
335
|
+
- It is unzipped in memory (JSZip). Images and fonts become `data:` URIs.
|
|
336
|
+
- The WebView page is an inline HTML string. File access, DOM storage and the cache are turned off.
|
|
337
|
+
- No file system, storage or network API is used for it, on iOS or Android.
|
|
338
|
+
|
|
339
|
+
A `{ uri }` source is read with `fetch`. Over `https`, the system HTTP cache may keep a copy; send
|
|
340
|
+
`Cache-Control: no-store` from your server, or pass `{ base64 }` instead.
|
|
212
341
|
|
|
213
342
|
---
|
|
214
343
|
|
|
@@ -217,17 +346,23 @@ Extra callbacks: `onReady`, `onCover`, `onIndexed`, `onHighlightTap`, `onLink`,
|
|
|
217
346
|
```ts
|
|
218
347
|
interface Highlight {
|
|
219
348
|
id: string; spine: number; start: number; end: number; // character offsets in that chapter
|
|
220
|
-
text: string; color:
|
|
349
|
+
text: string; color: string; // a colour name or a CSS colour
|
|
350
|
+
cfi?: string; // epub.js range CFI; wins over the offsets,
|
|
351
|
+
// which are the fallback when it is not found
|
|
221
352
|
style?: 'highlight' | 'underline'; note?: string; chapter?: string; createdAt: number;
|
|
222
353
|
}
|
|
223
354
|
|
|
355
|
+
interface CfiHighlight { id: string; cfi: string; color: string; style?: 'highlight' | 'underline' }
|
|
356
|
+
|
|
224
357
|
interface Bookmark {
|
|
225
|
-
id: string; spine: number; offset: number; chapter: string; excerpt: string; progress: number; createdAt: number;
|
|
358
|
+
id: string; spine: number; offset: number; cfi?: string; chapter: string; excerpt: string; progress: number; createdAt: number;
|
|
226
359
|
}
|
|
227
360
|
|
|
228
361
|
interface RelocateEvent {
|
|
229
362
|
spine: number; offset: number; end: number; page: number; pageCount: number; spineCount: number;
|
|
230
363
|
textLength: number; progress: number; chapter: string; excerpt: string; indexed: boolean;
|
|
364
|
+
href: string; tocIndex: number; startCfi?: string; endCfi?: string;
|
|
365
|
+
locations?: { start: number; end: number; count: number; progress: number };
|
|
231
366
|
}
|
|
232
367
|
```
|
|
233
368
|
|
|
@@ -312,13 +447,18 @@ a second; a 50 MB illustrated book will be slow, and files above `maxFileSize` a
|
|
|
312
447
|
## Limitations
|
|
313
448
|
|
|
314
449
|
- Reflowable EPUBs only. Fixed-layout EPUBs and media overlays are not supported.
|
|
315
|
-
-
|
|
450
|
+
- Theme `bg` colours must be `#rgb`, `#rrggbb` (with or without alpha), `rgb()`, `white` or `black`. The reader's
|
|
451
|
+
buttons and sheets are tinted from it; any other colour gives them a plain white or black tint.
|
|
316
452
|
- Vertical writing modes (Japanese `writing-mode: vertical-rl`) are laid out horizontally.
|
|
317
453
|
- Character spacing is ignored in right-to-left books: it would break the joins of Arabic-script letters.
|
|
318
454
|
- Audio and video elements in a book are removed.
|
|
455
|
+
- The system text selection is turned off, because it does not work well on iPhone. The reader has its own: a long
|
|
456
|
+
press picks a word, a drag extends it, and the reader's menu (Highlight, Underline, Note) replaces the
|
|
457
|
+
system menu. So the system Copy, Look Up and Translate items are not offered.
|
|
319
458
|
- Text selection and highlights work in the chapter that is on screen; in Scroll mode a neighbouring chapter becomes
|
|
320
459
|
selectable once it scrolls into the middle of the screen.
|
|
321
|
-
-
|
|
460
|
+
- Pinch zoom works in the paged modes, not in Scroll mode.
|
|
461
|
+
- Search ignores case, diacritics (tashkeel), tatweel, ZWNJ and other zero-width characters, unifies Arabic / Persian letter variants (for example ي and ی) and all digit systems.
|
|
322
462
|
- The page curl is a geometric corner fold, not a physical simulation of paper.
|
|
323
463
|
|
|
324
464
|
---
|
|
@@ -332,6 +472,9 @@ The page-turn sounds (`src/assets/page-turn-*.wav`) are trimmed and softened rec
|
|
|
332
472
|
|
|
333
473
|
EPUB parsing uses [JSZip](https://stuk.github.io/jszip/).
|
|
334
474
|
|
|
475
|
+
The epub.js compatibility code (`src/engine/epubcfi.js`) is ported from [epub.js](https://github.com/futurepress/epub.js),
|
|
476
|
+
Copyright (c) 2013 FuturePress, BSD 2-Clause licence (the full notice is in that file).
|
|
477
|
+
|
|
335
478
|
### Security
|
|
336
479
|
|
|
337
480
|
Books are untrusted input. Chapter HTML is sanitized (scripts, event handlers, `javascript:` URLs, forms, `<base>`, remote images and
|
|
@@ -346,6 +489,8 @@ npm install
|
|
|
346
489
|
npm run build:engine # rebuilds src/engine/html.ts from src/engine/reader.js
|
|
347
490
|
npm run build:lib # compiles src/ to lib/
|
|
348
491
|
npm run typecheck
|
|
492
|
+
npm run test:compat # compares with epub.js in headless Chrome (needs Chrome and an epub.js build)
|
|
493
|
+
npm run test:features # watermark, search, CFI in/out, colours, fonts, book colours, zoom
|
|
349
494
|
```
|
|
350
495
|
|
|
351
496
|
The reading engine is plain JavaScript in `src/engine/reader.js`, bundled with JSZip into a single HTML page for the WebView.
|
package/lib/EpubReader.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { BookLocation, BookMetadata, EpubSource, Highlight, ReaderSettings, RelocateEvent, SafeInsets, SearchResult, SelectionEvent, TocItem } from './types';
|
|
2
|
+
import type { BookColors, BookLocation, BookMetadata, CfiHighlight, CustomFont, EpubSource, Highlight, ReaderSettings, ReaderTheme, RelocateEvent, SafeInsets, SearchResult, SelectionEvent, TocItem } from './types';
|
|
3
3
|
export interface ReaderErrorInfo {
|
|
4
4
|
/** true when the book cannot be shown (failed to open, reader engine stopped); false for a problem on one page */
|
|
5
5
|
fatal: boolean;
|
|
@@ -11,26 +11,52 @@ export interface EpubReaderProps {
|
|
|
11
11
|
systemDark?: boolean;
|
|
12
12
|
/** Space reserved for status bar / home indicator (and the notch in landscape). The engine adds room for the running header and footer. */
|
|
13
13
|
safeInsets?: SafeInsets;
|
|
14
|
+
/** Running header (chapter) and footer (page) on the page. false: none, and no space is kept for them. Default true. */
|
|
15
|
+
runningLabels?: boolean;
|
|
16
|
+
/** where to open: an offset, a share of the book, or an epub.js CFI ({ cfi: 'epubcfi(...)' }) */
|
|
14
17
|
initialLocation?: BookLocation | {
|
|
15
18
|
progress: number;
|
|
19
|
+
} | {
|
|
20
|
+
cfi: string;
|
|
16
21
|
};
|
|
17
|
-
highlights
|
|
22
|
+
/** highlights as offsets, or as epub.js CFIs only (CfiHighlight). A `cfi` always wins over offsets. */
|
|
23
|
+
highlights?: (Highlight | CfiHighlight)[];
|
|
24
|
+
/**
|
|
25
|
+
* Characters per epub.js location ("chunk"), as in epub.js book.locations.generate(n). Default 150 (the epub.js
|
|
26
|
+
* default). Keep it the same for a book forever if you store or pay by location numbers. 0 turns locations off.
|
|
27
|
+
*/
|
|
28
|
+
locationChars?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Show runs of 3+ zero-width characters (U+200B/C/D, U+FEFF), such as a hidden watermark, as U+2060 WORD JOINER,
|
|
31
|
+
* one for one, so they do not break words. Nothing is deleted, so offsets and CFIs do not change. Default true.
|
|
32
|
+
*/
|
|
33
|
+
repairZeroWidth?: boolean;
|
|
34
|
+
/** Highlight colours by name, e.g. { yellow: '#ffff00' }. A Highlight's `color` may also be a CSS colour itself. */
|
|
35
|
+
highlightColors?: Record<string, string>;
|
|
36
|
+
/** Fill opacity for highlightColors (default 0.3, like epub.js). */
|
|
37
|
+
highlightOpacity?: number;
|
|
38
|
+
/** Fonts loaded into every chapter with @font-face. A font with an `id` can be chosen with settings.fontId. */
|
|
39
|
+
fonts?: CustomFont[];
|
|
40
|
+
/** 'theme' (default): all text in the theme colour. 'keep': the book's own colours stay, made readable. */
|
|
41
|
+
bookColors?: BookColors;
|
|
42
|
+
/** Largest pinch zoom (default 3). 1 turns pinch zoom off. Paged modes only. */
|
|
43
|
+
maxZoom?: number;
|
|
44
|
+
/** Page themes to use instead of the built-in ones. settings.themeId picks one; an unknown id gets the first. */
|
|
45
|
+
themes?: ReaderTheme[];
|
|
18
46
|
/**
|
|
19
47
|
* Largest EPUB (bytes) that will be loaded. The whole book is held in memory while it is opened, so very large
|
|
20
48
|
* files can crash low-memory phones. Default 150 MB, 0 disables the check.
|
|
21
49
|
*/
|
|
22
50
|
maxFileSize?: number;
|
|
23
|
-
/** Items added to the native text-selection menu. `onMenuAction` fires with the item key. */
|
|
24
|
-
menuItems?: {
|
|
25
|
-
label: string;
|
|
26
|
-
key: string;
|
|
27
|
-
}[];
|
|
28
|
-
onMenuAction?: (key: string, selection: SelectionEvent | null) => void;
|
|
29
51
|
onReady?: (info: {
|
|
30
52
|
metadata: BookMetadata;
|
|
31
53
|
rtl: boolean;
|
|
32
54
|
}) => void;
|
|
33
|
-
|
|
55
|
+
/**
|
|
56
|
+
* items: the entries whose file is in the book. all: every entry, in the same order, with spine -1 for an entry
|
|
57
|
+
* whose file is missing (for example the chapters a preview leaves out). tocIndex points into items.
|
|
58
|
+
*/
|
|
59
|
+
onToc?: (items: TocItem[], all: TocItem[]) => void;
|
|
34
60
|
onCover?: (dataUri: string) => void;
|
|
35
61
|
onRelocate?: (e: RelocateEvent) => void;
|
|
36
62
|
/** fired once the whole book has been indexed: cumulative character offset of every spine item */
|
|
@@ -50,6 +76,12 @@ export interface EpubReaderProps {
|
|
|
50
76
|
/** the reading direction changed (the user overrode it in the settings) */
|
|
51
77
|
onDirectionChange?: (rtl: boolean) => void;
|
|
52
78
|
onSearchResults?: (searchId: number, results: SearchResult[], done: boolean) => void;
|
|
79
|
+
/** epub.js locations are counted (after the book is indexed). From now on onRelocate carries `locations`. */
|
|
80
|
+
onLocations?: (info: {
|
|
81
|
+
count: number;
|
|
82
|
+
}) => void;
|
|
83
|
+
/** the page was zoomed with two fingers (scale 1 = back to normal) */
|
|
84
|
+
onZoom?: (scale: number) => void;
|
|
53
85
|
onEndReached?: (edge: 'start' | 'end') => void;
|
|
54
86
|
onError?: (message: string, info: ReaderErrorInfo) => void;
|
|
55
87
|
}
|
|
@@ -62,6 +94,12 @@ export interface EpubReaderHandle {
|
|
|
62
94
|
fragment?: string;
|
|
63
95
|
} | {
|
|
64
96
|
progress: number;
|
|
97
|
+
}
|
|
98
|
+
/** spine / offset: where to go when the CFI is not found in this book */
|
|
99
|
+
| {
|
|
100
|
+
cfi: string;
|
|
101
|
+
spine?: number;
|
|
102
|
+
offset?: number;
|
|
65
103
|
}): void;
|
|
66
104
|
search(query: string, searchId: number): void;
|
|
67
105
|
cancelSearch(searchId?: number): void;
|
package/lib/EpubReader.js
CHANGED
|
@@ -43,6 +43,18 @@ const themes_1 = require("./themes");
|
|
|
43
43
|
const DEFAULT_MAX_FILE = 150 * 1024 * 1024;
|
|
44
44
|
const ENGINE_START_TIMEOUT = 20000;
|
|
45
45
|
const CHUNK = 256 * 1024;
|
|
46
|
+
function stripDataPrefix(b64) {
|
|
47
|
+
return b64.startsWith('data:') ? b64.slice(b64.indexOf(',') + 1) : b64;
|
|
48
|
+
}
|
|
49
|
+
// Font data as plain base64, or '' when it is not base64. Only these characters may go into the injected script.
|
|
50
|
+
function cleanFontBase64(b64) {
|
|
51
|
+
const data = stripDataPrefix(b64 || '').replace(/\s+/g, '').replace(/-/g, '+').replace(/_/g, '/');
|
|
52
|
+
return /^[A-Za-z0-9+/]+=*$/.test(data) ? data : '';
|
|
53
|
+
}
|
|
54
|
+
// identity of a font list: changes when a font is added, removed or replaced
|
|
55
|
+
function fontsKeyOf(fonts) {
|
|
56
|
+
return (fonts || []).map((f) => [f.id, f.family, f.weight, f.style, f.mime, sourceKeyOf({ base64: f.base64 })].join('|')).join(';');
|
|
57
|
+
}
|
|
46
58
|
/** Identity of a source: the explicit `key`, the uri, or a fingerprint sampled across the base64 data. */
|
|
47
59
|
function sourceKeyOf(source) {
|
|
48
60
|
if (source.key)
|
|
@@ -99,7 +111,7 @@ function toScript(cmd) {
|
|
|
99
111
|
return `window.__cmd(${json});true;`;
|
|
100
112
|
}
|
|
101
113
|
exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
102
|
-
const { source, settings, systemDark = false, safeInsets = { top: 0, bottom: 0 }, highlights,
|
|
114
|
+
const { source, settings, systemDark = false, safeInsets = { top: 0, bottom: 0 }, highlights, fonts } = props;
|
|
103
115
|
const web = (0, react_1.useRef)(null);
|
|
104
116
|
const cb = (0, react_1.useRef)(props);
|
|
105
117
|
cb.current = props;
|
|
@@ -107,13 +119,22 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
107
119
|
// bumping this remounts the WebView (after the system killed its process)
|
|
108
120
|
const [webKey, setWebKey] = (0, react_1.useState)(0);
|
|
109
121
|
const opened = (0, react_1.useRef)(false);
|
|
110
|
-
const selection = (0, react_1.useRef)(null);
|
|
111
122
|
const metaRef = (0, react_1.useRef)({ title: '', author: '', language: '', publisher: '' });
|
|
112
123
|
const lastLoc = (0, react_1.useRef)(null);
|
|
113
124
|
const lastKey = (0, react_1.useRef)('');
|
|
114
|
-
const
|
|
125
|
+
const fontGen = (0, react_1.useRef)(0);
|
|
126
|
+
const fontsKey = fontsKeyOf(fonts);
|
|
127
|
+
const hlColorsJson = JSON.stringify(props.highlightColors || null);
|
|
128
|
+
const themesJson = JSON.stringify(props.themes || null);
|
|
129
|
+
const engineSettings = (0, react_1.useMemo)(() => ({
|
|
130
|
+
...(0, themes_1.toEngineSettings)(settings, systemDark, safeInsets, fonts, props.themes, props.runningLabels !== false),
|
|
131
|
+
highlightColors: props.highlightColors || {},
|
|
132
|
+
highlightOpacity: props.highlightOpacity ?? 0.3,
|
|
133
|
+
bookColors: props.bookColors || 'theme',
|
|
134
|
+
maxZoom: props.maxZoom ?? 3
|
|
135
|
+
}),
|
|
115
136
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
|
-
[settings, systemDark, safeInsets.top, safeInsets.bottom, safeInsets.left, safeInsets.right]);
|
|
137
|
+
[settings, systemDark, safeInsets.top, safeInsets.bottom, safeInsets.left, safeInsets.right, fontsKey, hlColorsJson, themesJson, props.highlightOpacity, props.bookColors, props.maxZoom, props.runningLabels]);
|
|
117
138
|
// only what the engine actually uses decides about re-layout (the brightness slider, the page sound ... must not)
|
|
118
139
|
const engineJson = JSON.stringify(engineSettings);
|
|
119
140
|
const latest = (0, react_1.useRef)({ engineSettings, highlights });
|
|
@@ -121,13 +142,40 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
121
142
|
const send = (0, react_1.useCallback)((cmd) => {
|
|
122
143
|
web.current?.injectJavaScript(toScript(cmd));
|
|
123
144
|
}, []);
|
|
145
|
+
// iOS pauses the WebView in the background, so the start timer only counts while the app is in front
|
|
146
|
+
const [inFront, setInFront] = (0, react_1.useState)(react_native_1.AppState.currentState !== 'background');
|
|
147
|
+
(0, react_1.useEffect)(() => {
|
|
148
|
+
const sub = react_native_1.AppState.addEventListener('change', (state) => setInFront(state !== 'background'));
|
|
149
|
+
return () => sub.remove();
|
|
150
|
+
}, []);
|
|
124
151
|
// the engine never started (blocked WebView, out of memory ...)
|
|
125
152
|
(0, react_1.useEffect)(() => {
|
|
126
|
-
if (engineReady)
|
|
153
|
+
if (engineReady || !inFront)
|
|
127
154
|
return;
|
|
128
155
|
const t = setTimeout(() => cb.current.onError?.('The reader could not be started.', { fatal: true }), ENGINE_START_TIMEOUT);
|
|
129
156
|
return () => clearTimeout(t);
|
|
130
|
-
}, [engineReady, webKey]);
|
|
157
|
+
}, [engineReady, webKey, inFront]);
|
|
158
|
+
// Fonts go before the book (so the first page already uses them), in pieces like the book. Only when they change.
|
|
159
|
+
(0, react_1.useEffect)(() => {
|
|
160
|
+
if (!engineReady)
|
|
161
|
+
return;
|
|
162
|
+
// new keys for every update, so a later update cannot overwrite the data of one still waiting in the queue
|
|
163
|
+
const gen = ++fontGen.current;
|
|
164
|
+
const list = [];
|
|
165
|
+
(cb.current.fonts || []).forEach((f, i) => {
|
|
166
|
+
const data = cleanFontBase64(f.base64);
|
|
167
|
+
if (!data) {
|
|
168
|
+
cb.current.onError?.(`The font "${f.family}" was skipped: its data is not valid base64.`, { fatal: false });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const key = `f${gen}_${i}`;
|
|
172
|
+
for (let k = 0; k < data.length; k += CHUNK) {
|
|
173
|
+
web.current?.injectJavaScript(`window.__blob("${key}",${k === 0 ? 1 : 0},"${data.slice(k, k + CHUNK)}");true;`);
|
|
174
|
+
}
|
|
175
|
+
list.push({ key, family: f.family, mime: f.mime, weight: f.weight, style: f.style });
|
|
176
|
+
});
|
|
177
|
+
send({ cmd: 'fonts', list });
|
|
178
|
+
}, [engineReady, fontsKey, send]);
|
|
131
179
|
// open (or re-open) the book once the engine is up
|
|
132
180
|
const sourceKey = sourceKeyOf(source);
|
|
133
181
|
(0, react_1.useEffect)(() => {
|
|
@@ -157,7 +205,9 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
157
205
|
cmd: 'open',
|
|
158
206
|
settings: latest.current.engineSettings,
|
|
159
207
|
highlights: latest.current.highlights || [],
|
|
160
|
-
location: lastLoc.current || cb.current.initialLocation
|
|
208
|
+
location: lastLoc.current || cb.current.initialLocation,
|
|
209
|
+
locationChars: cb.current.locationChars ?? 150,
|
|
210
|
+
repairZeroWidth: cb.current.repairZeroWidth !== false
|
|
161
211
|
});
|
|
162
212
|
opened.current = true;
|
|
163
213
|
}
|
|
@@ -195,7 +245,6 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
195
245
|
send({ cmd: 'showHit', offset: r.offset, length: r.length });
|
|
196
246
|
},
|
|
197
247
|
clearSelection: () => {
|
|
198
|
-
selection.current = null;
|
|
199
248
|
send({ cmd: 'clearSelection' });
|
|
200
249
|
},
|
|
201
250
|
setLabels: (header, footer) => send({ cmd: 'labels', header, footer })
|
|
@@ -221,7 +270,10 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
221
270
|
break;
|
|
222
271
|
case 'toc':
|
|
223
272
|
p.onReady?.({ metadata: metaRef.current, rtl: !!d.rtl });
|
|
224
|
-
|
|
273
|
+
{
|
|
274
|
+
const items = Array.isArray(d.items) ? d.items : [];
|
|
275
|
+
p.onToc?.(items, Array.isArray(d.all) ? d.all : items);
|
|
276
|
+
}
|
|
225
277
|
break;
|
|
226
278
|
case 'cover':
|
|
227
279
|
if (typeof d.uri === 'string')
|
|
@@ -235,11 +287,9 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
235
287
|
p.onIndexed?.(d);
|
|
236
288
|
break;
|
|
237
289
|
case 'selection':
|
|
238
|
-
selection.current = d;
|
|
239
290
|
p.onSelection?.(d);
|
|
240
291
|
break;
|
|
241
292
|
case 'selectionClear':
|
|
242
|
-
selection.current = null;
|
|
243
293
|
p.onSelection?.(null);
|
|
244
294
|
break;
|
|
245
295
|
case 'highlightTap':
|
|
@@ -267,18 +317,21 @@ exports.EpubReader = (0, react_1.forwardRef)(function EpubReader(props, ref) {
|
|
|
267
317
|
case 'end':
|
|
268
318
|
p.onEndReached?.(d.edge);
|
|
269
319
|
break;
|
|
320
|
+
case 'locations':
|
|
321
|
+
p.onLocations?.({ count: d.count });
|
|
322
|
+
break;
|
|
323
|
+
case 'zoom':
|
|
324
|
+
p.onZoom?.(typeof d.scale === 'number' ? d.scale : 1);
|
|
325
|
+
break;
|
|
270
326
|
case 'error':
|
|
271
327
|
p.onError?.(String(d.message || 'Unknown error'), { fatal: !!d.fatal });
|
|
272
328
|
break;
|
|
273
329
|
}
|
|
274
330
|
}, []);
|
|
275
|
-
const bg = (0, themes_1.themeColors)(settings, systemDark).bg;
|
|
331
|
+
const bg = (0, themes_1.themeColors)(settings, systemDark, props.themes).bg;
|
|
276
332
|
return (react_1.default.createElement(react_native_1.View, { style: [styles.fill, { backgroundColor: bg }] },
|
|
277
333
|
react_1.default.createElement(react_native_webview_1.WebView, { key: webKey, ref: web, style: [styles.fill, { backgroundColor: bg }], originWhitelist: ['*'], source: { html: html_1.READER_HTML }, onMessage: onMessage, javaScriptEnabled: true, domStorageEnabled: false, scrollEnabled: false, bounces: false, overScrollMode: "never", showsHorizontalScrollIndicator: false, showsVerticalScrollIndicator: false, automaticallyAdjustContentInsets: false, contentInsetAdjustmentBehavior: "never", allowsInlineMediaPlayback: true, hideKeyboardAccessoryView: true, setSupportMultipleWindows: false,
|
|
278
334
|
// the page is generated here and never needs the file system, the network or the system font scale
|
|
279
|
-
allowFileAccess: false, allowFileAccessFromFileURLs: false, allowUniversalAccessFromFileURLs: false, mixedContentMode: "never", cacheEnabled: false, textZoom: 100,
|
|
280
|
-
const key = e.nativeEvent.key;
|
|
281
|
-
cb.current.onMenuAction?.(key, selection.current);
|
|
282
|
-
}, onShouldStartLoadWithRequest: (req) => req.url === 'about:blank' || req.url.startsWith('data:') || req.url.startsWith('about:'), onRenderProcessGone: recover, onContentProcessDidTerminate: recover, onError: (e) => cb.current.onError?.(e.nativeEvent.description || 'The reader failed to load.', { fatal: true }) })));
|
|
335
|
+
allowFileAccess: false, allowFileAccessFromFileURLs: false, allowUniversalAccessFromFileURLs: false, mixedContentMode: "never", cacheEnabled: false, textZoom: 100, onShouldStartLoadWithRequest: (req) => req.url === 'about:blank' || req.url.startsWith('data:') || req.url.startsWith('about:'), onRenderProcessGone: recover, onContentProcessDidTerminate: recover, onError: (e) => cb.current.onError?.(e.nativeEvent.description || 'The reader failed to load.', { fatal: true }) })));
|
|
283
336
|
});
|
|
284
337
|
const styles = react_native_1.StyleSheet.create({ fill: { flex: 1 } });
|
package/lib/EpubReaderView.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ChromeOverrides } from './themes';
|
|
3
|
+
import type { Bookmark, BookColors, BookLocation, BookMetadata, CustomFont, EpubSource, Highlight, ReaderSettings, ReaderTheme, RelocateEvent, SafeInsets, UiFonts } from './types';
|
|
3
4
|
import type { ReaderLabels } from './strings';
|
|
4
5
|
export interface EpubReaderViewProps {
|
|
5
6
|
source: EpubSource;
|
|
@@ -7,7 +8,10 @@ export interface EpubReaderViewProps {
|
|
|
7
8
|
title?: string;
|
|
8
9
|
/** Space for the status bar / home indicator (and notch in landscape). Use useSafeAreaInsets() from react-native-safe-area-context. */
|
|
9
10
|
safeInsets?: SafeInsets;
|
|
10
|
-
|
|
11
|
+
/** where to open: an offset or an epub.js CFI ({ cfi: 'epubcfi(...)' }) */
|
|
12
|
+
initialLocation?: BookLocation | {
|
|
13
|
+
cfi: string;
|
|
14
|
+
};
|
|
11
15
|
initialSettings?: Partial<ReaderSettings>;
|
|
12
16
|
initialHighlights?: Highlight[];
|
|
13
17
|
initialBookmarks?: Bookmark[];
|
|
@@ -23,6 +27,27 @@ export interface EpubReaderViewProps {
|
|
|
23
27
|
labels?: Partial<ReaderLabels>;
|
|
24
28
|
/** Largest EPUB in bytes that will be opened (default 150 MB, 0 = no limit). */
|
|
25
29
|
maxFileSize?: number;
|
|
30
|
+
/** Highlight colours by name, shown in the highlight menu (default: the built-in five). See EpubReader. */
|
|
31
|
+
highlightColors?: Record<string, string>;
|
|
32
|
+
highlightOpacity?: number;
|
|
33
|
+
/** App fonts; the ones with an `id` are added to the font list. See EpubReader. */
|
|
34
|
+
fonts?: CustomFont[];
|
|
35
|
+
bookColors?: BookColors;
|
|
36
|
+
maxZoom?: number;
|
|
37
|
+
/** characters per epub.js location (default 150, 0 = off). See EpubReader. */
|
|
38
|
+
locationChars?: number;
|
|
39
|
+
repairZeroWidth?: boolean;
|
|
40
|
+
onLocations?: (info: {
|
|
41
|
+
count: number;
|
|
42
|
+
}) => void;
|
|
43
|
+
/** Page themes instead of the built-in six (Themes sheet and page colours). */
|
|
44
|
+
themes?: ReaderTheme[];
|
|
45
|
+
/** Colours of buttons, sheets and menus, for light and dark pages. Missing ones keep the default. */
|
|
46
|
+
chrome?: ChromeOverrides;
|
|
47
|
+
/** Fonts of the interface (not the book), e.g. the app's own font. */
|
|
48
|
+
uiFonts?: UiFonts;
|
|
49
|
+
/** Light or dark for the 'device' appearance. Default: the phone's setting. Pass the app's own when it has one. */
|
|
50
|
+
colorScheme?: 'light' | 'dark';
|
|
26
51
|
}
|
|
27
52
|
/**
|
|
28
53
|
* Full reader screen. A different `source` (or Try again after an error) starts a fresh screen, so highlights,
|