expo-epub-reader 0.0.0-stage → 0.2.0

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 (193) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/LICENSE +21 -0
  3. package/README.md +289 -2
  4. package/THIRD_PARTY_NOTICES.md +35 -0
  5. package/build/content/cfiPath.d.ts +17 -0
  6. package/build/content/cfiPath.js +60 -0
  7. package/build/content/cfiPath.js.map +1 -0
  8. package/build/content/css.d.ts +97 -0
  9. package/build/content/css.js +507 -0
  10. package/build/content/css.js.map +1 -0
  11. package/build/content/htmlToBlocks.d.ts +124 -0
  12. package/build/content/htmlToBlocks.js +671 -0
  13. package/build/content/htmlToBlocks.js.map +1 -0
  14. package/build/content/notes.d.ts +12 -0
  15. package/build/content/notes.js +86 -0
  16. package/build/content/notes.js.map +1 -0
  17. package/build/content/parseWorker.d.ts +28 -0
  18. package/build/content/parseWorker.js +63 -0
  19. package/build/content/parseWorker.js.map +1 -0
  20. package/build/content/ranges.d.ts +30 -0
  21. package/build/content/ranges.js +100 -0
  22. package/build/content/ranges.js.map +1 -0
  23. package/build/content/search.d.ts +35 -0
  24. package/build/content/search.js +95 -0
  25. package/build/content/search.js.map +1 -0
  26. package/build/content/serialize.d.ts +12 -0
  27. package/build/content/serialize.js +122 -0
  28. package/build/content/serialize.js.map +1 -0
  29. package/build/content/stats.d.ts +19 -0
  30. package/build/content/stats.js +47 -0
  31. package/build/content/stats.js.map +1 -0
  32. package/build/content/styles.d.ts +56 -0
  33. package/build/content/styles.js +327 -0
  34. package/build/content/styles.js.map +1 -0
  35. package/build/core/archive.d.ts +51 -0
  36. package/build/core/archive.js +188 -0
  37. package/build/core/archive.js.map +1 -0
  38. package/build/core/book.d.ts +90 -0
  39. package/build/core/book.js +272 -0
  40. package/build/core/book.js.map +1 -0
  41. package/build/core/container.d.ts +9 -0
  42. package/build/core/container.js +31 -0
  43. package/build/core/container.js.map +1 -0
  44. package/build/core/displayoptions.d.ts +11 -0
  45. package/build/core/displayoptions.js +41 -0
  46. package/build/core/displayoptions.js.map +1 -0
  47. package/build/core/epubcfi.d.ts +92 -0
  48. package/build/core/epubcfi.js +354 -0
  49. package/build/core/epubcfi.js.map +1 -0
  50. package/build/core/errors.d.ts +25 -0
  51. package/build/core/errors.js +18 -0
  52. package/build/core/errors.js.map +1 -0
  53. package/build/core/fonts.d.ts +16 -0
  54. package/build/core/fonts.js +109 -0
  55. package/build/core/fonts.js.map +1 -0
  56. package/build/core/index.d.ts +21 -0
  57. package/build/core/index.js +68 -0
  58. package/build/core/index.js.map +1 -0
  59. package/build/core/navigation.d.ts +45 -0
  60. package/build/core/navigation.js +161 -0
  61. package/build/core/navigation.js.map +1 -0
  62. package/build/core/packaging.d.ts +76 -0
  63. package/build/core/packaging.js +203 -0
  64. package/build/core/packaging.js.map +1 -0
  65. package/build/core/pagelist.d.ts +28 -0
  66. package/build/core/pagelist.js +96 -0
  67. package/build/core/pagelist.js.map +1 -0
  68. package/build/core/section.d.ts +47 -0
  69. package/build/core/section.js +93 -0
  70. package/build/core/section.js.map +1 -0
  71. package/build/core/spine.d.ts +23 -0
  72. package/build/core/spine.js +106 -0
  73. package/build/core/spine.js.map +1 -0
  74. package/build/core/utils/mime.d.ts +3 -0
  75. package/build/core/utils/mime.js +42 -0
  76. package/build/core/utils/mime.js.map +1 -0
  77. package/build/core/utils/path.d.ts +35 -0
  78. package/build/core/utils/path.js +134 -0
  79. package/build/core/utils/path.js.map +1 -0
  80. package/build/core/utils/xml.d.ts +60 -0
  81. package/build/core/utils/xml.js +314 -0
  82. package/build/core/utils/xml.js.map +1 -0
  83. package/build/experiments.d.ts +71 -0
  84. package/build/experiments.js +53 -0
  85. package/build/experiments.js.map +1 -0
  86. package/build/index.d.ts +37 -0
  87. package/build/index.js +85 -0
  88. package/build/index.js.map +1 -0
  89. package/build/layout/dispose.d.ts +12 -0
  90. package/build/layout/dispose.js +27 -0
  91. package/build/layout/dispose.js.map +1 -0
  92. package/build/layout/flow.d.ts +25 -0
  93. package/build/layout/flow.js +101 -0
  94. package/build/layout/flow.js.map +1 -0
  95. package/build/layout/images.d.ts +18 -0
  96. package/build/layout/images.js +61 -0
  97. package/build/layout/images.js.map +1 -0
  98. package/build/layout/paginator.d.ts +86 -0
  99. package/build/layout/paginator.js +179 -0
  100. package/build/layout/paginator.js.map +1 -0
  101. package/build/layout/theme.d.ts +34 -0
  102. package/build/layout/theme.js +63 -0
  103. package/build/layout/theme.js.map +1 -0
  104. package/build/layout/typesetter.d.ts +217 -0
  105. package/build/layout/typesetter.js +978 -0
  106. package/build/layout/typesetter.js.map +1 -0
  107. package/build/loaders.d.ts +20 -0
  108. package/build/loaders.js +54 -0
  109. package/build/loaders.js.map +1 -0
  110. package/build/perf.d.ts +45 -0
  111. package/build/perf.js +9 -0
  112. package/build/perf.js.map +1 -0
  113. package/build/react/EpubReader.d.ts +124 -0
  114. package/build/react/EpubReader.js +308 -0
  115. package/build/react/EpubReader.js.map +1 -0
  116. package/build/react/PagedView.d.ts +7 -0
  117. package/build/react/PagedView.js +373 -0
  118. package/build/react/PagedView.js.map +1 -0
  119. package/build/react/PagedViewReanimated.d.ts +14 -0
  120. package/build/react/PagedViewReanimated.js +359 -0
  121. package/build/react/PagedViewReanimated.js.map +1 -0
  122. package/build/react/ScrolledView.d.ts +9 -0
  123. package/build/react/ScrolledView.js +440 -0
  124. package/build/react/ScrolledView.js.map +1 -0
  125. package/build/react/SelectionHandles.d.ts +19 -0
  126. package/build/react/SelectionHandles.js +63 -0
  127. package/build/react/SelectionHandles.js.map +1 -0
  128. package/build/react/a11y.d.ts +35 -0
  129. package/build/react/a11y.js +81 -0
  130. package/build/react/a11y.js.map +1 -0
  131. package/build/react/contentStore.d.ts +55 -0
  132. package/build/react/contentStore.js +167 -0
  133. package/build/react/contentStore.js.map +1 -0
  134. package/build/react/engine.d.ts +348 -0
  135. package/build/react/engine.js +1124 -0
  136. package/build/react/engine.js.map +1 -0
  137. package/build/react/parseRuntime.d.ts +9 -0
  138. package/build/react/parseRuntime.js +34 -0
  139. package/build/react/parseRuntime.js.map +1 -0
  140. package/build/react/useEpub.d.ts +12 -0
  141. package/build/react/useEpub.js +43 -0
  142. package/build/react/useEpub.js.map +1 -0
  143. package/build/react/viewTypes.d.ts +52 -0
  144. package/build/react/viewTypes.js +3 -0
  145. package/build/react/viewTypes.js.map +1 -0
  146. package/package.json +120 -4
  147. package/src/content/cfiPath.ts +55 -0
  148. package/src/content/css.ts +480 -0
  149. package/src/content/htmlToBlocks.ts +749 -0
  150. package/src/content/notes.ts +79 -0
  151. package/src/content/parseWorker.ts +71 -0
  152. package/src/content/ranges.ts +98 -0
  153. package/src/content/search.ts +104 -0
  154. package/src/content/serialize.ts +138 -0
  155. package/src/content/stats.ts +52 -0
  156. package/src/content/styles.ts +334 -0
  157. package/src/core/archive.ts +205 -0
  158. package/src/core/book.ts +290 -0
  159. package/src/core/container.ts +27 -0
  160. package/src/core/displayoptions.ts +38 -0
  161. package/src/core/epubcfi.ts +385 -0
  162. package/src/core/errors.ts +33 -0
  163. package/src/core/fonts.ts +104 -0
  164. package/src/core/index.ts +21 -0
  165. package/src/core/navigation.ts +188 -0
  166. package/src/core/packaging.ts +261 -0
  167. package/src/core/pagelist.ts +99 -0
  168. package/src/core/section.ts +128 -0
  169. package/src/core/spine.ts +99 -0
  170. package/src/core/utils/mime.ts +40 -0
  171. package/src/core/utils/path.ts +121 -0
  172. package/src/core/utils/xml.ts +295 -0
  173. package/src/experiments.ts +102 -0
  174. package/src/index.ts +44 -0
  175. package/src/layout/dispose.ts +31 -0
  176. package/src/layout/flow.ts +100 -0
  177. package/src/layout/images.ts +58 -0
  178. package/src/layout/paginator.ts +234 -0
  179. package/src/layout/theme.ts +92 -0
  180. package/src/layout/typesetter.ts +1155 -0
  181. package/src/loaders.ts +55 -0
  182. package/src/perf.ts +53 -0
  183. package/src/react/EpubReader.tsx +470 -0
  184. package/src/react/PagedView.tsx +439 -0
  185. package/src/react/PagedViewReanimated.tsx +414 -0
  186. package/src/react/ScrolledView.tsx +573 -0
  187. package/src/react/SelectionHandles.tsx +88 -0
  188. package/src/react/a11y.tsx +117 -0
  189. package/src/react/contentStore.ts +181 -0
  190. package/src/react/engine.ts +1284 -0
  191. package/src/react/parseRuntime.ts +33 -0
  192. package/src/react/useEpub.ts +54 -0
  193. package/src/react/viewTypes.ts +53 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,76 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 — 2026-12-06
4
+
5
+ First release published to npm. 0.1.0 was never published, so the upgrade notes below only matter if you used it from git.
6
+
7
+ ### Reading
8
+
9
+ - **Scrolled flow:** `flow="scrolled"` reads chapters as one continuous scroll; switching flows keeps the exact position.
10
+ - **Search:** `reader.search(query, { exact, wholeWords, signal })` streams hits for the whole book.
11
+ - Matching ignores case and accents by default.
12
+ - Each hit has a range CFI and an excerpt.
13
+ - `display()` accepts range CFIs.
14
+ - **Highlights:** the `highlights` prop (`{ cfiRange, color?, id? }[]`) draws ranges behind the text in both flows, and they follow relayouts.
15
+ - **Text selection:**
16
+ - Long-press selects a word. Drag to extend it (paginated flow), or use the handles in either flow; a tap clears it.
17
+ - `onSelectionChange`, `selectionColor`, `getSelection()` / `clearSelection()`.
18
+ - **Footnote popups:** `onFootnote({ text, label, href, sectionIndex })` is called for tapped note references.
19
+ - Recognised references: EPUB 3 `noteref`, `doc-noteref`, or a superscript / short-marker link.
20
+ - Backlinks are stripped from the note text.
21
+ - `<aside epub:type="footnote">` notes are hidden from the text.
22
+ - **Reading progress by text:**
23
+ - `progress` is measured in characters of the book's linear text, so it is stable across font size, screen and flow.
24
+ - New fields: `progressIsEstimate`, `chapterProgress`, `minutesLeftInChapter`, `minutesLeftInBook`.
25
+ - Props `bookProgress` and `wordsPerMinute`; `ref.progressOf(cfi)`.
26
+
27
+ ### Typography
28
+
29
+ - **Book stylesheets:** linked and embedded CSS is applied (a subset). Colours, font families and page margins follow the theme. Turn it off with `publisherStyles={false}`.
30
+ - **Hyphenation:** the `hyphenate` prop (e.g. `hyphenateSync` from the `hyphen` package) hyphenates at layout time without changing positions.
31
+ - **Publisher fonts:** `publisherFonts` uses the book's `@font-face` fonts, including IDPF/Adobe-obfuscated ones.
32
+ - **Superscripts and subscripts** are raised and lowered.
33
+ - **Small caps** are synthesized.
34
+
35
+ ### Accessibility
36
+
37
+ - **Screen readers:** while VoiceOver or TalkBack runs, invisible accessible elements cover the page text (paragraphs, headings, images, links).
38
+ - "Next page" / "Previous page" actions turn pages.
39
+ - Focus follows page turns.
40
+ - **Reduce motion:** pages change without the slide.
41
+ - **New props:** `accessibilityLayer`, `respectSystemFontScale`.
42
+
43
+ ### Performance
44
+
45
+ - **Time-sliced layout:** a page shows before its whole chapter is laid out.
46
+ - **Disk cache:** parsed chapters are cached on disk (with `expo-file-system`).
47
+ - Capped at 64 MB, least recently used first.
48
+ - `setContentCacheLimit()` / `clearContentCache()`.
49
+ - **Opt-in experiments:**
50
+ - UI-thread page turns: `experimental={{ pager: 'reanimated' }}`, with the optional Reanimated / Worklets / Gesture Handler peers.
51
+ - Off-thread parsing: `experimental={{ parseThread: 'worklet' }}`, which needs worklets bundle mode.
52
+ - Measurements: [`example/bench-results/README.md`](example/bench-results/README.md).
53
+
54
+ ### Fixes
55
+
56
+ - Forward page turns on Android no longer flash a blank page.
57
+ - Highlights and selections ending a paragraph no longer stretch to the right margin.
58
+ - A long-press right after a jump in the scrolled flow is no longer ignored.
59
+
60
+ ### Packaging
61
+
62
+ - **Typed errors:** `EpubError` has a `code` (`INVALID_ARCHIVE`, `INVALID_CONTAINER`, `INVALID_PACKAGE`, `RESOURCE_NOT_FOUND`, `DRM_PROTECTED`, `MISSING_DEPENDENCY`). DRM-encrypted books fail on open.
63
+ - **Parser-only entry:** `expo-epub-reader/core` has no React Native or Skia, for Node, servers and tests.
64
+ - **CommonJS build:** `build/` is now CommonJS, loadable by Node and any bundler. Apps keep using the TypeScript source via the `react-native` entry.
65
+ - **Notices:** the epub.js license notice is included in `THIRD_PARTY_NOTICES.md`.
66
+
67
+ ### Upgrading from 0.1.0
68
+
69
+ - **`progress` changed meaning:** chapter-weighted before, text-weighted now. Percentages stored by an app will differ.
70
+ - **Two location reports:** `onLocationChange` can fire twice for one position. It reports an estimated page total, or `progressIsEstimate: true`, first, then the exact values.
71
+ - **Error type:** `ResourceNotFoundError` is now an `EpubError` (code `RESOURCE_NOT_FOUND`).
72
+ - **Cached chapters:** cached chapters from earlier builds are parsed again once.
73
+
74
+ ## 0.1.0
75
+
76
+ - Initial version (not published): a TypeScript port of epub.js parsing (container, OPF, spine, nav/NCX, page-list, CFI), the XHTML → blocks content model, the Skia typesetter and paginator, `<EpubReader>` and `useEpub()`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026-present expo-epub-reader contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,290 @@
1
- # Temporary Holding Version
1
+ # expo-epub-reader
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ EPUB parsing and a paginated reader for Expo / React Native, rendered with
4
+ [React Native Skia](https://wcandillon.github.io/react-native-skia/).
5
+
6
+ - **`core/`** – a TypeScript port of [epub.js](https://github.com/futurepress/epub.js)'s
7
+ parsing layer (container → OPF → spine / manifest / metadata, EPUB3 nav + EPUB2 NCX
8
+ table of contents, page-list, EPUB CFI) with no DOM or browser dependencies
9
+ (`@xmldom/xmldom` + `htmlparser2` for markup, `fflate` for unzip).
10
+ - **`content/`** – converts chapter XHTML into styled text/image blocks (headings,
11
+ paragraphs, bold/italic, links, lists, blockquotes, tables, images) and applies the
12
+ book's stylesheets and inline CSS through a small CSS engine (`content/css.ts`).
13
+ - **`layout/`** – typesets blocks with Skia's Paragraph API and paginates them
14
+ (line-level page splits, widows/orphans, keep-headings-with-next, full-page images).
15
+ - **`react/`** – `<EpubReader>` with two reading modes: paginated (swipe / tap to
16
+ turn pages) and continuous vertical scrolling across chapters (`flow="scrolled"`).
17
+ Switching modes keeps the exact reading position. Plus internal links, themes, CFI
18
+ locations, and `useEpub()`.
19
+
20
+ ## Install
21
+
22
+ ```sh
23
+ npx expo install expo-epub-reader react-native-skia expo-file-system expo-build-properties
24
+ ```
25
+
26
+ `react-native-skia` v3 needs a development build (not Expo Go) and Android `minSdkVersion` 26:
27
+
28
+ ```json
29
+ { "expo": { "plugins": [["expo-build-properties", { "android": { "minSdkVersion": 26 } }]] } }
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```tsx
35
+ import { EpubReader, useEpub, sepiaTheme, type EpubReaderRef } from 'expo-epub-reader';
36
+
37
+ export function Reader({ uri }: { uri: string }) {
38
+ const source = useMemo(() => ({ uri }), [uri]); // or { url } / { bytes }
39
+ const { book, loading, error } = useEpub(source);
40
+ const reader = useRef<EpubReaderRef>(null);
41
+
42
+ if (!book) return loading ? <ActivityIndicator /> : <Text>{error?.message}</Text>;
43
+ return (
44
+ <EpubReader
45
+ ref={reader}
46
+ book={book}
47
+ flow={scrolled ? 'scrolled' : 'paginated'} // switch any time; position is kept
48
+ theme={{ ...sepiaTheme, fontSize: 20 }}
49
+ publisherStyles // book CSS on (default); false = reader styles only
50
+ initialLocation={savedCfi} // CFI, href#fragment or spine index
51
+ onLocationChange={(loc) => save(loc.cfi)} // { cfi, page, totalPagesInSection, progress, minutesLeftInChapter, … }
52
+ onLinkPress={(href) => Linking.openURL(href)} // external links only
53
+ onPress={toggleToolbar} // tap in the middle of the page
54
+ />
55
+ );
56
+ }
57
+
58
+ // Navigation (paginated: next page · scrolled: one screen down)
59
+ reader.current?.next();
60
+ reader.current?.display(book.navigation.toc[3].href);
61
+ ```
62
+
63
+ ### Reading progress
64
+
65
+ `onLocationChange` reports progress by the book's text, so it stays the same when the font size, theme, screen or flow changes:
66
+
67
+ | Field | Meaning |
68
+ | --- | --- |
69
+ | `progress` | 0..1 through the book's linear chapters, by characters |
70
+ | `progressIsEstimate` | true until the text index is ready (`progress` is then estimated from chapter positions) |
71
+ | `chapterProgress` | 0..1 through the current chapter |
72
+ | `minutesLeftInChapter` | reading time left in the chapter, at `wordsPerMinute` (default 230) |
73
+ | `minutesLeftInBook` | reading time left in the book; undefined until the text index is ready |
74
+
75
+ - **Text index:** after the first page, the reader counts the text of every chapter in the background, one chapter per idle moment.
76
+ - The counts are saved with the chapter cache, so the next open is instant.
77
+ - When the index is ready, the current location is reported again with exact values.
78
+ - Turn this off with `bookProgress={false}`.
79
+ - **`progressOf(cfi)`:** `reader.current.progressOf(cfi)` gives the percentage at any saved position, for example to label bookmarks or highlights.
80
+ - **Non-linear chapters:** chapters marked non-linear in the spine (notes, extras) don't count toward the total.
81
+
82
+ ### Search and highlights
83
+
84
+ `search()` walks the whole book chapter by chapter, ignoring case and accents ("cafe" finds "Café"). Each hit has a range CFI: pass it to `display()` to go there, or to the `highlights` prop to mark it.
85
+
86
+ ```tsx
87
+ const [hits, setHits] = useState<SearchHit[]>([]);
88
+
89
+ async function find(query: string, signal: AbortSignal) {
90
+ const found: SearchHit[] = [];
91
+ for await (const hit of reader.current!.search(query, { signal })) found.push(hit); // { cfi, excerpt, excerptMatch, sectionIndex, href }
92
+ setHits(found);
93
+ }
94
+
95
+ <EpubReader
96
+ ref={reader}
97
+ book={book}
98
+ highlights={useMemo(() => hits.map((h) => ({ cfiRange: h.cfi })), [hits])} // { cfiRange, color?, id? }
99
+ />;
100
+
101
+ reader.current?.display(hits[0].cfi); // opens the page with the hit
102
+ ```
103
+
104
+ - **Search options:** `{ exact, wholeWords, context, signal }`.
105
+ - **Highlights:** drawn behind the text, in paged and scrolled flows. They follow font, theme and size changes.
106
+ - **Colours:** any CSS colour; translucent ones work best on every theme. The default is `DEFAULT_HIGHLIGHT_COLOR`.
107
+ - **Saving highlights:** the app owns them. Store the `cfiRange` strings and pass them back in.
108
+ - **Without a reader:** `searchContent`, `cfiForRange` and `locateRange` work on a chapter's content model (`htmlToBlocks`).
109
+
110
+ ### Footnotes
111
+
112
+ Pass `onFootnote` and tapping a note reference shows the note in a popup (your UI) instead of jumping to it:
113
+
114
+ ```tsx
115
+ const [note, setNote] = useState<Footnote | null>(null); // { text, label, href, sectionIndex }
116
+
117
+ <EpubReader book={book} onFootnote={setNote} />;
118
+
119
+ // in your popup: note.label ("1"), note.text; "Go to note" → reader.current?.display(note.href)
120
+ ```
121
+
122
+ - **Recognised references:**
123
+ - links marked `epub:type="noteref"` or `role="doc-noteref"`
124
+ - in books without semantics, internal links whose text is a short marker ("1", "[2]", "*", "†") and that are superscript, have a note-like class, or point at a note-like id (`#fn3`, `#note12`)
125
+ - **Note text:**
126
+ - It comes from the target element, or the paragraph or list item around it.
127
+ - Links back to the reference are dropped: `epub:type="backlink"`, arrows such as ↩, and the note's own number.
128
+ - If no text is found, the link is followed as usual.
129
+ - **Hidden asides:** with `onFootnote`, `<aside epub:type="footnote">` notes (also endnote, rearnote and `role="doc-footnote"`) are left out of the text, as most reading apps do.
130
+ - **Without `onFootnote`:** nothing changes, and note references are followed like any other link.
131
+ - **Sample book:** the example app includes one with three note styles, `example/assets/samples/footnotes.epub`, built by `example/scripts/make-footnotes-sample.mjs`.
132
+
133
+ ### Typography
134
+
135
+ - **Hyphenation:** pass a function that inserts soft hyphens, e.g. from the [`hyphen`](https://www.npmjs.com/package/hyphen) package:
136
+
137
+ ```tsx
138
+ import { hyphenateSync } from 'hyphen/en-us'; // one import per language
139
+
140
+ <EpubReader book={book} hyphenate={hyphenateSync} />;
141
+ ```
142
+
143
+ - Body paragraphs are hyphenated at layout time, not headings or preformatted text. The book's text, CFIs, search, selection and progress don't change.
144
+ - A hyphen is drawn at each hyphenated line end; Skia versions that draw their own are detected.
145
+ - Keep the function identity stable, because changing it re-lays out the book.
146
+ - **Publisher fonts:** `publisherFonts` uses the fonts embedded in the book (`@font-face`) wherever its CSS asks for them; other text keeps the theme's fonts.
147
+ - Obfuscated fonts (IDPF and Adobe schemes) are decoded.
148
+ - With a `fontProvider`, the book's fonts are registered in it.
149
+ - Fonts load once per book, when the first chapter is laid out.
150
+ - **Superscript and subscript** are raised and lowered. Skia's paragraph API has no baseline shift, so the glyphs are drawn as an offset copy while the line keeps its normal metrics.
151
+ - **Small caps** (`font-variant: small-caps`) are synthesized as reduced capitals, which works with any font.
152
+
153
+ ### Accessibility
154
+
155
+ - **Screen readers:** pages are drawn on a canvas, so while VoiceOver or TalkBack is running the reader adds invisible accessible elements over the text.
156
+ - **What's included:** one element per paragraph or heading (only the lines visible on that page or screen), one per image (its alt text), and one per link. Footnote references are read as "Note 1" and open the note.
157
+ - **Page turns:** every element has "Next page" and "Previous page" actions (VoiceOver: swipe up or down with the Actions rotor; TalkBack: the actions menu).
158
+ - **Toolbar:** double-tapping a paragraph or a magic tap calls `onPress`, so the app can show its toolbar.
159
+ - **Focus:** after a turn, focus moves to the new page's first paragraph. At either end of the book the reader announces "Start of book" or "End of book".
160
+ - **Turning it on or off:** `accessibilityLayer="always"` adds the elements for other assistive tech too (Switch Control, Voice Control); `"off"` disables them.
161
+ - **Reduce motion:** with the system "reduce motion" setting on, pages change without the slide animation.
162
+ - **System text size:** with `respectSystemFontScale`, `theme.fontSize` follows the system text size setting (Dynamic Type, Android font size). It's off by default, because reading apps usually have their own font-size control.
163
+
164
+ ### Text selection
165
+
166
+ Long-press a word to select it. Keep the finger down and drag to extend the selection (paginated flow), or use the two handles in either flow. A tap or a page swipe clears it. The reader reports the selection; your app draws its own menu.
167
+
168
+ ```tsx
169
+ const [selection, setSelection] = useState<ReaderSelection | null>(null); // { cfiRange, text, sectionIndex }
170
+
171
+ <EpubReader
172
+ ref={reader}
173
+ book={book}
174
+ onSelectionChange={setSelection}
175
+ highlights={marks}
176
+ selectionColor="rgba(0, 122, 255, 0.26)" // optional
177
+ />;
178
+
179
+ // e.g. a "Highlight" button: keep the range, then dismiss the selection
180
+ setMarks((m) => [...m, { cfiRange: selection!.cfiRange }]);
181
+ reader.current?.clearSelection();
182
+ ```
183
+
184
+ - **Scope:** a selection stays within one chapter.
185
+ - **Clearing:** theme, size and flow changes clear the selection, and so do jumps.
186
+ - **Reanimated pager:** the opt-in UI-thread pager (`experimental={{ pager: 'reanimated' }}`) doesn't support selection yet.
187
+
188
+ ### Parsing only (Node, servers, no Skia)
189
+
190
+ The `expo-epub-reader/core` entry has the parser without React Native or Skia: use it in Node, on a server, or in tests. In an app, the main entry exports the same classes.
191
+
192
+ ```ts
193
+ import { Book } from 'expo-epub-reader/core';
194
+
195
+ const book = await Book.open(bytes); // Uint8Array | ArrayBuffer
196
+ book.metadata.title; // creators, language, publisher, …
197
+ book.navigation.toc; // NavItem[] (resolved hrefs, depth)
198
+ book.spine.get('#chapter1') ?? book.spine.get(2); // by idref / index / href / CFI
199
+ const doc = await book.spine.get(2)!.load(); // xmldom Document
200
+ await book.coverBytes();
201
+ await book.spine.get(2)!.find('rabbit'); // [{ cfi, excerpt }]
202
+ ```
203
+
204
+ ### Errors
205
+
206
+ Problems with the book itself reject with an `EpubError` whose `code` you can switch on:
207
+
208
+ ```ts
209
+ import { isEpubError } from 'expo-epub-reader';
210
+
211
+ const { error } = useEpub(source);
212
+ if (isEpubError(error, 'DRM_PROTECTED')) showMessage('This book is protected by DRM.');
213
+ ```
214
+
215
+ | `code` | Meaning |
216
+ | --- | --- |
217
+ | `INVALID_ARCHIVE` | not a zip file |
218
+ | `INVALID_CONTAINER` | no usable `META-INF/container.xml` (and no `.opf` to fall back to) |
219
+ | `INVALID_PACKAGE` | the OPF is missing, malformed, or lacks metadata/manifest/spine |
220
+ | `RESOURCE_NOT_FOUND` | a referenced file isn't in the archive (`ResourceNotFoundError`) |
221
+ | `DRM_PROTECTED` | content is encrypted (Adobe DRM, Readium LCP, …); font obfuscation alone is fine |
222
+ | `MISSING_DEPENDENCY` | opening a `uri`/`url` without `expo-file-system` installed |
223
+
224
+ ### epub.js → expo-epub-reader
225
+
226
+ | epub.js | here |
227
+ | --- | --- |
228
+ | `ePub(url)` + `book.loaded.*` | `await Book.open(bytes)` (everything parsed on open) |
229
+ | `book.packaging.metadata` | `book.metadata` (adds `creators[]`, `subjects[]`, `version`) |
230
+ | `book.navigation.toc` | same – hrefs are resolved archive paths |
231
+ | `book.spine.get(target)` | same (index, href, `#idref`, CFI) |
232
+ | `section.load()` | same – returns an xmldom `Document` |
233
+ | `new EpubCFI(str)`, `compare` | `new EpubCFI(str)`, `EpubCFI.compare`, `cfi.resolve(doc)` |
234
+ | `book.renderTo(el).display()` | `<EpubReader book={book} />` |
235
+
236
+ ## Development
237
+
238
+ ```sh
239
+ npm install
240
+ npm test # unit + real-book integration tests
241
+ npm run typecheck
242
+ cd example && npm install && npx expo run:ios # or run:android
243
+ ```
244
+
245
+ The example app bundles three public-domain books from Project Gutenberg (EPUB3 with
246
+ illustrations, EPUB3, EPUB2/NCX) in `example/assets/books/`.
247
+
248
+ ## Performance
249
+
250
+ - **Metrics:** `<EpubReader onMetric={…}>` and `ReaderEngine` report timing for each stage: open, read, parse, blocks, typeset, paginate, picture, commit, firstPage and resolve.
251
+ - **Benchmarks:** the example app includes an automated A/B benchmark (`example/bench/`, `example/scripts/bench.mjs`). Results and methodology are in [`example/bench-results/README.md`](example/bench-results/README.md).
252
+ - **Current defaults** (iOS Release, compared with the first version):
253
+ - whole-book layout about 25% faster
254
+ - typesetting about 44% faster
255
+ - relayouts 19–27% faster
256
+ - page turns about 16 ms beyond the slide animation
257
+
258
+ ## Performance features
259
+
260
+ - **Time-sliced layout (default):**
261
+ - Chapters are laid out in small slices, so a page can show before its whole chapter is laid out, and prefetching never blocks the JS thread for long.
262
+ - While a chapter is still being laid out, `onLocationChange` may report an estimated `totalPagesInSection` first and the exact total a moment later.
263
+ - **Chapter cache (default, when `expo-file-system` is installed):**
264
+ - Parsed chapters are stored in the app's cache directory, so reopening a book skips parsing (first page about 25–35% faster in the benchmarks).
265
+ - The OS may clear it at any time.
266
+ - It is capped at 64 MB (least recently used chapters are removed first); change the cap with `setContentCacheLimit(bytes)` and empty it with `clearContentCache()`.
267
+ - Disable with `experimental={{ contentCache: 'off' }}`.
268
+ - **UI-thread page turns (opt-in):** with `react-native-reanimated`, `react-native-worklets` and `react-native-gesture-handler` installed, `experimental={{ pager: 'reanimated' }}` runs the drag and turn animation on the UI thread.
269
+ - **Off-thread parsing (experimental, opt-in):** `experimental={{ parseThread: 'worklet' }}` parses chapters on a background worklet runtime.
270
+ - It needs react-native-worklets *bundle mode* in the app: see `example/babel.config.js` and `example/metro.config.js`.
271
+ - It frees the JS thread, but delays the first page slightly.
272
+
273
+ Measurements and methodology: [`example/bench-results/README.md`](example/bench-results/README.md).
274
+
275
+ ## Known limitations (v1)
276
+
277
+ - Book stylesheets are applied with a subset of CSS:
278
+ - **Selectors:** type, class, id, attribute, descendant/child/sibling combinators, `:first-child`, `:last-child` and `:link`. Rules using anything else (pseudo-elements, `:hover`, `:not()`, `:nth-child()`) are skipped.
279
+ - **Properties:** the ones the renderer understands: alignment, text-indent, vertical margins, left margin, font size/weight/style/variant, text-transform, text-decoration, line-height, page breaks and `display: none`/`block`.
280
+ - **Not supported:** floats, borders, backgrounds and widths. Floated figures render as full-width blocks.
281
+ - **Reader control:** colours, font families and page margins always follow the reader's theme. `text-align: justify` defers to `theme.textAlign`.
282
+ - **Opting out:** set `publisherStyles={false}` to ignore book CSS.
283
+ - Floats and drop caps (`float`, `::first-letter`) are not supported; floated content is laid out as a full-width block.
284
+ - Embedded fonts in WOFF2 format can't be loaded by Skia; other `src` formats (TTF, OTF, WOFF) are tried instead.
285
+ - Fixed-layout (pre-paginated) EPUBs, SVG images, MathML, audio/video and RTL page
286
+ progression are not rendered specially.
287
+
288
+ ## License
289
+
290
+ MIT. The EPUB parser in `src/core/` is a port of [epub.js](https://github.com/futurepress/epub.js) (BSD); see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
@@ -0,0 +1,35 @@
1
+ # Third-party notices
2
+
3
+ ## epub.js
4
+
5
+ The EPUB parsing code in `src/core/` is a TypeScript port of [epub.js](https://github.com/futurepress/epub.js).
6
+
7
+ ```
8
+ Copyright (c) 2013, FuturePress
9
+
10
+ All rights reserved.
11
+
12
+ Redistribution and use in source and binary forms, with or without
13
+ modification, are permitted provided that the following conditions are met:
14
+
15
+ 1. Redistributions of source code must retain the above copyright notice, this
16
+ list of conditions and the following disclaimer.
17
+ 2. Redistributions in binary form must reproduce the above copyright notice,
18
+ this list of conditions and the following disclaimer in the documentation
19
+ and/or other materials provided with the distribution.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+
32
+ The views and conclusions contained in the software and documentation are those
33
+ of the authors and should not be interpreted as representing official policies,
34
+ either expressed or implied, of the FreeBSD Project.
35
+ ```
@@ -0,0 +1,17 @@
1
+ /**
2
+ * CFI step paths computed once while walking a chapter, so positions can be turned into
3
+ * CFIs (and CFIs back into positions) without the DOM. Numbering matches
4
+ * `EpubCFI.pathTo`: element steps count element siblings, text steps count text/CDATA
5
+ * siblings, `<html>` is not a step, element steps carry their `id`.
6
+ */
7
+ import type { CfiStep } from '../core/epubcfi';
8
+ import { type Node } from '../core/utils/xml';
9
+ export declare class PathMemo {
10
+ private paths;
11
+ private indexes;
12
+ /** Steps from below `<html>` down to `node` (same as `EpubCFI.pathTo(node).steps`). */
13
+ path(node: Node): CfiStep[];
14
+ /** Position of `node` among its element siblings (elements) or text siblings (text). */
15
+ private indexOf;
16
+ }
17
+ export declare function sameSteps(a: CfiStep[], b: CfiStep[], length?: number): boolean;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PathMemo = void 0;
4
+ exports.sameSteps = sameSteps;
5
+ const xml_1 = require("../core/utils/xml");
6
+ class PathMemo {
7
+ constructor() {
8
+ this.paths = new Map();
9
+ this.indexes = new Map();
10
+ }
11
+ /** Steps from below `<html>` down to `node` (same as `EpubCFI.pathTo(node).steps`). */
12
+ path(node) {
13
+ const hit = this.paths.get(node);
14
+ if (hit)
15
+ return hit;
16
+ const parent = node.parentNode;
17
+ let steps;
18
+ if (!parent || parent.nodeType === xml_1.DOCUMENT_NODE)
19
+ steps = [];
20
+ else {
21
+ const text = (0, xml_1.isText)(node);
22
+ const step = { type: text ? 'text' : 'element', index: this.indexOf(parent, node) };
23
+ const id = text ? null : node.getAttribute?.('id');
24
+ if (id)
25
+ step.id = id;
26
+ steps = [...this.path(parent), step];
27
+ }
28
+ this.paths.set(node, steps);
29
+ return steps;
30
+ }
31
+ /** Position of `node` among its element siblings (elements) or text siblings (text). */
32
+ indexOf(parent, node) {
33
+ let map = this.indexes.get(parent);
34
+ if (!map) {
35
+ map = new Map();
36
+ let el = 0;
37
+ let tx = 0;
38
+ const kids = parent.childNodes;
39
+ for (let i = 0; i < kids.length; i++) {
40
+ const k = kids[i];
41
+ if (k.nodeType === xml_1.ELEMENT_NODE)
42
+ map.set(k, el++);
43
+ else if ((0, xml_1.isText)(k))
44
+ map.set(k, tx++);
45
+ }
46
+ this.indexes.set(parent, map);
47
+ }
48
+ return map.get(node) ?? -1;
49
+ }
50
+ }
51
+ exports.PathMemo = PathMemo;
52
+ function sameSteps(a, b, length = Math.max(a.length, b.length)) {
53
+ if (a.length < length || b.length < length)
54
+ return false;
55
+ for (let i = 0; i < length; i++)
56
+ if (a[i].type !== b[i].type || a[i].index !== b[i].index)
57
+ return false;
58
+ return true;
59
+ }
60
+ //# sourceMappingURL=cfiPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cfiPath.js","sourceRoot":"","sources":["../../src/content/cfiPath.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * A small CSS engine for EPUB stylesheets: parses rules and matches selectors against
3
+ * the chapter DOM, producing for each element the declarations that apply to it in
4
+ * cascade order (specificity, then source order). The declarations are then read by
5
+ * `parseInlineStyle`, exactly like a `style=""` attribute.
6
+ *
7
+ * Supported selectors: type, `*`, `.class`, `#id`, `[attr]`, `[attr=v]`, `[attr~=v]`,
8
+ * `[attr|=v]`, `[attr^=v]`, `[attr$=v]`, `[attr*=v]`, compounds, the descendant, child
9
+ * (`>`), adjacent (`+`) and sibling (`~`) combinators, `:first-child`, `:last-child`,
10
+ * `:link`/`:visited` (as `a[href]`), `:root`. A rule with anything else (pseudo-elements,
11
+ * `:hover`, `:not(...)`, …) is skipped: only that rule, not the stylesheet.
12
+ *
13
+ * At-rules: `@media` blocks apply when the query mentions `screen`/`all` or is empty
14
+ * (not `print`, not negated); `@font-face` rules are collected (`StyleSheet.fontFaces`);
15
+ * `@import`, `@page`, `@namespace`, … are ignored.
16
+ */
17
+ import { type Element } from '../core/utils/xml';
18
+ type AttrOp = '' | '=' | '~=' | '|=' | '^=' | '$=' | '*=';
19
+ interface Compound {
20
+ tag?: string;
21
+ id?: string;
22
+ classes: string[];
23
+ attrs: {
24
+ name: string;
25
+ op: AttrOp;
26
+ value: string;
27
+ }[];
28
+ firstChild?: boolean;
29
+ lastChild?: boolean;
30
+ root?: boolean;
31
+ }
32
+ type Combinator = ' ' | '>' | '+' | '~';
33
+ /** A selector as compounds from right (subject) to left, with the combinator to the next. */
34
+ interface Selector {
35
+ parts: {
36
+ compound: Compound;
37
+ combinator?: Combinator;
38
+ }[];
39
+ specificity: number;
40
+ }
41
+ export interface CssRule {
42
+ selector: Selector;
43
+ /** Raw declarations, `prop: value; …`. */
44
+ declarations: string;
45
+ order: number;
46
+ }
47
+ /** An `@font-face` rule: an embedded font for a family. */
48
+ export interface FontFace {
49
+ family: string;
50
+ /** `url(...)` values of `src`, as written (relative to the stylesheet). */
51
+ urls: string[];
52
+ /** CSS weight (400 normal, 700 bold). */
53
+ weight: number;
54
+ italic: boolean;
55
+ }
56
+ export interface StyleSheet {
57
+ rules: CssRule[];
58
+ fontFaces: FontFace[];
59
+ }
60
+ /** Parse one selector (no commas). Returns null when it uses something unsupported. */
61
+ export declare function parseSelector(text: string): Selector | null;
62
+ export declare function parseStyleSheet(css: string): StyleSheet;
63
+ /**
64
+ * Resolves the declarations that apply to an element from a set of stylesheets.
65
+ * Rules are indexed by the subject's id / class / tag so each element is only tested
66
+ * against rules that could match it.
67
+ */
68
+ export declare class StyleResolver {
69
+ private byId;
70
+ private byClass;
71
+ private byTag;
72
+ private universal;
73
+ readonly size: number;
74
+ /** Memo for consumers: most elements share the same declarations (e.g. every <p>). */
75
+ readonly memo: Map<string, unknown>;
76
+ constructor(sheets: StyleSheet[]);
77
+ /** Matched declarations in cascade order (lowest priority first), or '' if none. */
78
+ declarationsFor(el: Element): string;
79
+ }
80
+ /** Stylesheet references of a chapter document, in document order. */
81
+ export declare function stylesheetRefs(doc: {
82
+ getElementsByTagName(name: string): ArrayLike<Element>;
83
+ }): ({
84
+ href: string;
85
+ } | {
86
+ text: string;
87
+ })[];
88
+ /**
89
+ * Keep the parts of a book's CSS that describe the text, drop the parts the reader
90
+ * (and the person reading) control: colours and backgrounds (themes, dark mode),
91
+ * specific font families (the reader's font; generic `monospace` is kept for code, and
92
+ * the book's embedded fonts when `embeddedFonts` lists them),
93
+ * page-level margins/padding/line-height/absolute font size on `html`/`body`, and
94
+ * `text-align: justify` (the theme's `textAlign` decides; other alignments are kept).
95
+ */
96
+ export declare function readerDeclarations(declarations: string, tag: string, embeddedFonts?: ReadonlySet<string>): string;
97
+ export {};