react-native-simple-epub-reader 0.1.2 → 0.1.4

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 (36) hide show
  1. package/lib/module/components/GestureHandler/index.js +8 -2
  2. package/lib/module/components/GestureHandler/index.js.map +1 -1
  3. package/lib/module/components/Reader.js +125 -22
  4. package/lib/module/components/Reader.js.map +1 -1
  5. package/lib/module/constants/template.js +189 -226
  6. package/lib/module/constants/template.js.map +1 -1
  7. package/lib/module/constants/theme.js +28 -11
  8. package/lib/module/constants/theme.js.map +1 -1
  9. package/lib/module/helpers/downloadEpub.js +5 -1
  10. package/lib/module/helpers/downloadEpub.js.map +1 -1
  11. package/lib/module/helpers/saveTemplateToFile.js +4 -0
  12. package/lib/module/helpers/saveTemplateToFile.js.map +1 -1
  13. package/lib/module/hooks/useInjectWebviewVariables.js +4 -2
  14. package/lib/module/hooks/useInjectWebviewVariables.js.map +1 -1
  15. package/lib/typescript/src/components/GestureHandler/index.d.ts.map +1 -1
  16. package/lib/typescript/src/components/Reader.d.ts +1 -1
  17. package/lib/typescript/src/components/Reader.d.ts.map +1 -1
  18. package/lib/typescript/src/constants/template.d.ts +1 -1
  19. package/lib/typescript/src/constants/template.d.ts.map +1 -1
  20. package/lib/typescript/src/constants/theme.d.ts.map +1 -1
  21. package/lib/typescript/src/helpers/downloadEpub.d.ts.map +1 -1
  22. package/lib/typescript/src/helpers/saveTemplateToFile.d.ts +1 -0
  23. package/lib/typescript/src/helpers/saveTemplateToFile.d.ts.map +1 -1
  24. package/lib/typescript/src/hooks/useInjectWebviewVariables.d.ts +2 -1
  25. package/lib/typescript/src/hooks/useInjectWebviewVariables.d.ts.map +1 -1
  26. package/lib/typescript/src/types/index.d.ts +4 -0
  27. package/lib/typescript/src/types/index.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/src/components/GestureHandler/index.tsx +8 -0
  30. package/src/components/Reader.tsx +161 -27
  31. package/src/constants/template.ts +189 -226
  32. package/src/constants/theme.ts +28 -11
  33. package/src/helpers/downloadEpub.ts +7 -1
  34. package/src/helpers/saveTemplateToFile.ts +5 -0
  35. package/src/hooks/useInjectWebviewVariables.ts +9 -0
  36. package/src/types/index.ts +4 -0
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  export default `
4
- <!doctype html>
5
- <html>
4
+ <!DOCTYPE html>
5
+ <html>
6
6
  <head>
7
- <meta charset="utf-8" />
7
+ <meta charset="utf-8">
8
8
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
9
  <title>EPUB.js</title>
10
10
  <script id="jszip"></script>
@@ -13,7 +13,7 @@ export default `
13
13
  <style type="text/css">
14
14
  body {
15
15
  margin: 0;
16
- background-color: #211f26;
16
+ background-color: #211F26;
17
17
  }
18
18
 
19
19
  #viewer {
@@ -25,18 +25,16 @@ export default `
25
25
  align-items: center;
26
26
  }
27
27
 
28
- [ref='epubjs-mk-balloon'] {
29
- background: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPScxLjEnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZycgeG1sbnM6eGxpbms9J2h0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsnIHg9JzBweCcgeT0nMHB4JyB2aWV3Qm94PScwIDAgNzUgNzUnPjxnIGZpbGw9JyNCREJEQkQnIGlkPSdidWJibGUnPjxwYXRoIGNsYXNzPSdzdDAnIGQ9J00zNy41LDkuNEMxOS42LDkuNCw1LDIwLjUsNSwzNC4zYzAsNS45LDIuNywxMS4zLDcuMSwxNS42TDkuNiw2NS42bDE5LTcuM2MyLjgsMC42LDUuOCwwLjksOC45LDAuOSBDNTUuNSw1OS4yLDcwLDQ4LjEsNzAsMzQuM0M3MCwyMC41LDU1LjQsOS40LDM3LjUsOS40eicvPjwvZz48L3N2Zz4=')
30
- no-repeat;
28
+ [ref="epubjs-mk-balloon"] {
29
+ background: url("data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPScxLjEnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZycgeG1sbnM6eGxpbms9J2h0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsnIHg9JzBweCcgeT0nMHB4JyB2aWV3Qm94PScwIDAgNzUgNzUnPjxnIGZpbGw9JyNCREJEQkQnIGlkPSdidWJibGUnPjxwYXRoIGNsYXNzPSdzdDAnIGQ9J00zNy41LDkuNEMxOS42LDkuNCw1LDIwLjUsNSwzNC4zYzAsNS45LDIuNywxMS4zLDcuMSwxNS42TDkuNiw2NS42bDE5LTcuM2MyLjgsMC42LDUuOCwwLjksOC45LDAuOSBDNTUuNSw1OS4yLDcwLDQ4LjEsNzAsMzQuM0M3MCwyMC41LDU1LjQsOS40LDM3LjUsOS40eicvPjwvZz48L3N2Zz4=") no-repeat;
31
30
  width: 20px;
32
31
  height: 20px;
33
32
  cursor: pointer;
34
33
  margin-left: 0;
35
34
  }
36
35
 
37
- [ref='epubjs-mk-heart'] {
38
- background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAACOUlEQVR4nLWUTWgTURDH14Oe9JiPNqFNujvvzdsm3bdvPxKMFUEPag/iwdaD3j1JDymlCMXiqUeRHvWgFRQUxKPirUU8eFARvCnUj7QXP7DiJtk8easJjRjzIQ784bEz82Pe7MzTtP9tpmnu8UbNpOM4uzvFKF+3GM1BHHIAbwjA7xyY5AaGPuCarZtHmzGcsGM+YevKp2JUrAN4XeW2wSxKMy6wrSkKtbsiJZ96SfnAGZbl8bG6DawhdLwqAK9xYI25XLaufCrmjkjJKQpVF3DLzrDRFtAHXJ9hUNsoxOTH8hn5afGcrBRjkR66w3I/0GoJaPWRO9T63tRGISanmVHzgK1FMBvGmSr/iZeUn5fL8svlRbl5aKQt6bGXjPQ7bKefA5MOIahZOpsuAQmUY3t1pWNSN5WABtwwT2kW4Mki0OqgoMov+YA1rrMTmk3IhCr3hd/5St303EtEV54Yw5xq4y4PcHOFt/etH12xRqQHWFGsn/MFuHAQaPCmGO8b9roQl5OEBpaB862xoZTuc4F+uJDLhv0CF/LZ0DPoe9M097YNNwd2hAMLb9rpnmGrdlr1LrQJO/zH9bMMnBWA4X0n1RV2T6TU6oUc2Pm/vQ0aN/CSAKzfFp0rvWWnI5gNbEnrxWwD59UOL+UzjXc7ftTbYlxezGca0X4Dm+sJ1jQO7LgA/Hoa9eCln5Cv/IQ8i3ogAL+pZdAGMYcQdAGfHSAkmCQkUOc8pXQgWNPUgysAl5XU+Z9gg9gPaBjV+CGbZVoAAAAASUVORK5CYII=')
39
- no-repeat;
36
+ [ref="epubjs-mk-heart"] {
37
+ background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAACOUlEQVR4nLWUTWgTURDH14Oe9JiPNqFNujvvzdsm3bdvPxKMFUEPag/iwdaD3j1JDymlCMXiqUeRHvWgFRQUxKPirUU8eFARvCnUj7QXP7DiJtk8easJjRjzIQ784bEz82Pe7MzTtP9tpmnu8UbNpOM4uzvFKF+3GM1BHHIAbwjA7xyY5AaGPuCarZtHmzGcsGM+YevKp2JUrAN4XeW2wSxKMy6wrSkKtbsiJZ96SfnAGZbl8bG6DawhdLwqAK9xYI25XLaufCrmjkjJKQpVF3DLzrDRFtAHXJ9hUNsoxOTH8hn5afGcrBRjkR66w3I/0GoJaPWRO9T63tRGISanmVHzgK1FMBvGmSr/iZeUn5fL8svlRbl5aKQt6bGXjPQ7bKefA5MOIahZOpsuAQmUY3t1pWNSN5WABtwwT2kW4Mki0OqgoMov+YA1rrMTmk3IhCr3hd/5St303EtEV54Yw5xq4y4PcHOFt/etH12xRqQHWFGsn/MFuHAQaPCmGO8b9roQl5OEBpaB862xoZTuc4F+uJDLhv0CF/LZ0DPoe9M097YNNwd2hAMLb9rpnmGrdlr1LrQJO/zH9bMMnBWA4X0n1RV2T6TU6oUc2Pm/vQ0aN/CSAKzfFp0rvWWnI5gNbEnrxWwD59UOL+UzjXc7ftTbYlxezGca0X4Dm+sJ1jQO7LgA/Hoa9eCln5Cv/IQ8i3ogAL+pZdAGMYcQdAGfHSAkmCQkUOc8pXQgWNPUgysAl5XU+Z9gg9gPaBjV+CGbZVoAAAAASUVORK5CYII=") no-repeat;
40
38
  width: 20px;
41
39
  height: 20px;
42
40
  cursor: pointer;
@@ -45,7 +43,7 @@ export default `
45
43
  </style>
46
44
  </head>
47
45
 
48
- <body oncopy="return false;" oncut="return false;">
46
+ <body oncopy='return false' oncut='return false'>
49
47
  <div id="viewer"></div>
50
48
 
51
49
  <script>
@@ -59,153 +57,117 @@ export default `
59
57
  const enableSelection = window.enable_selection;
60
58
  const allowScriptedContent = window.allowScriptedContent || false;
61
59
  const allowPopups = window.allowPopups || false;
60
+ const LOCATION_GENERATION_CHARS = 2800;
62
61
 
63
62
  if (!file) {
64
- const reactNativeWebview =
65
- window.ReactNativeWebView !== undefined &&
66
- window.ReactNativeWebView !== null
67
- ? window.ReactNativeWebView
68
- : window;
69
- reactNativeWebview.postMessage(
70
- JSON.stringify({
71
- type: 'onDisplayError',
72
- reason: 'Book file is missing',
73
- })
74
- );
63
+ const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView !== null ? window.ReactNativeWebView : window;
64
+ reactNativeWebview.postMessage(JSON.stringify({
65
+ type: "onDisplayError",
66
+ reason: "Book file is missing"
67
+ }));
75
68
  }
76
69
 
77
70
  if (type === 'epub' || type === 'opf' || type === 'binary') {
78
71
  book = ePub(file);
79
72
  } else if (type === 'base64') {
80
- book = ePub(file, { encoding: 'base64' });
73
+ book = ePub(file, { encoding: "base64" });
81
74
  } else {
82
- const reactNativeWebview =
83
- window.ReactNativeWebView !== undefined &&
84
- window.ReactNativeWebView !== null
85
- ? window.ReactNativeWebView
86
- : window;
87
- reactNativeWebview.postMessage(
88
- JSON.stringify({
89
- type: 'onDisplayError',
90
- reason: 'Missing or invalid file type',
91
- })
92
- );
75
+ const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView !== null ? window.ReactNativeWebView : window;
76
+ reactNativeWebview.postMessage(JSON.stringify({
77
+ type: "onDisplayError",
78
+ reason: "Missing or invalid file type"
79
+ }));
93
80
  }
94
81
 
95
- rendition = book.renderTo('viewer', {
96
- width: '100%',
97
- height: '100%',
98
- manager: 'default',
99
- flow: 'auto',
82
+ rendition = book.renderTo("viewer", {
83
+ width: "100%",
84
+ height: "100%",
85
+ manager: "default",
86
+ flow: "auto",
100
87
  snap: undefined,
101
88
  spread: undefined,
102
89
  fullsize: undefined,
103
90
  allowPopups: allowPopups,
104
- allowScriptedContent: allowScriptedContent,
91
+ allowScriptedContent: allowScriptedContent
105
92
  });
106
-
107
- const reactNativeWebview =
108
- window.ReactNativeWebView !== undefined &&
109
- window.ReactNativeWebView !== null
110
- ? window.ReactNativeWebView
111
- : window;
112
- reactNativeWebview.postMessage(JSON.stringify({ type: 'onStarted' }));
93
+
94
+ const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView!== null ? window.ReactNativeWebView: window;
95
+ reactNativeWebview.postMessage(JSON.stringify({ type: "onStarted" }));
113
96
 
114
97
  function flatten(chapters) {
115
- return [].concat.apply(
116
- [],
117
- chapters.map((chapter) =>
118
- [].concat.apply([chapter], flatten(chapter.subitems))
119
- )
120
- );
98
+ return [].concat.apply([], chapters.map((chapter) => [].concat.apply([chapter], flatten(chapter.subitems))));
121
99
  }
122
100
 
123
101
  function getCfiFromHref(book, href) {
124
- const [_, id] = href.split('#');
125
- let section =
126
- book.spine.get(href.split('/')[1]) ||
127
- book.spine.get(href) ||
128
- book.spine.get(href.split('/').slice(1).join('/'));
129
-
130
- const el = id
131
- ? section.document.getElementById(id)
132
- : section.document.body;
133
- return section.cfiFromElement(el);
102
+ const [_, id] = href.split('#')
103
+ let section = book.spine.get(href.split('/')[1]) || book.spine.get(href) || book.spine.get(href.split('/').slice(1).join('/'))
104
+
105
+ const el = (id ? section.document.getElementById(id) : section.document.body)
106
+ return section.cfiFromElement(el)
134
107
  }
135
108
 
136
109
  function getChapter(location) {
137
- const locationHref = location.start.href;
138
-
139
- let match = flatten(book.navigation.toc)
140
- .filter((chapter) => {
141
- return book.canonical(chapter.href).includes(locationHref);
142
- }, null)
143
- .reduce((result, chapter) => {
144
- const locationAfterChapter =
145
- ePub.CFI.prototype.compare(
146
- location.start.cfi,
147
- getCfiFromHref(book, chapter.href)
148
- ) > 0;
149
- return locationAfterChapter ? chapter : result;
150
- }, null);
151
-
152
- return match;
153
- }
110
+ const locationHref = location.start.href
111
+
112
+ let match = flatten(book.navigation.toc)
113
+ .filter((chapter) => {
114
+ return book.canonical(chapter.href).includes(locationHref)
115
+ }, null)
116
+ .reduce((result, chapter) => {
117
+ const locationAfterChapter = ePub.CFI.prototype.compare(location.start.cfi, getCfiFromHref(book, chapter.href)) > 0
118
+ return locationAfterChapter ? chapter : result
119
+ }, null);
120
+
121
+ return match;
122
+ };
154
123
 
155
124
  const makeRangeCfi = (a, b) => {
156
- const CFI = new ePub.CFI();
157
- const start = CFI.parse(a),
158
- end = CFI.parse(b);
125
+ const CFI = new ePub.CFI()
126
+ const start = CFI.parse(a), end = CFI.parse(b)
159
127
  const cfi = {
160
- range: true,
161
- base: start.base,
162
- path: {
163
- steps: [],
164
- terminal: null,
165
- },
166
- start: start.path,
167
- end: end.path,
168
- };
169
- const len = cfi.start.steps.length;
128
+ range: true,
129
+ base: start.base,
130
+ path: {
131
+ steps: [],
132
+ terminal: null
133
+ },
134
+ start: start.path,
135
+ end: end.path
136
+ }
137
+ const len = cfi.start.steps.length
170
138
  for (let i = 0; i < len; i++) {
171
139
  if (CFI.equalStep(cfi.start.steps[i], cfi.end.steps[i])) {
172
- if (i == len - 1) {
173
- // Last step is equal, check terminals
174
- if (cfi.start.terminal === cfi.end.terminal) {
175
- // CFI's are equal
176
- cfi.path.steps.push(cfi.start.steps[i]);
177
- // Not a range
178
- cfi.range = false;
179
- }
180
- } else cfi.path.steps.push(cfi.start.steps[i]);
181
- } else break;
140
+ if (i == len - 1) {
141
+ // Last step is equal, check terminals
142
+ if (cfi.start.terminal === cfi.end.terminal) {
143
+ // CFI's are equal
144
+ cfi.path.steps.push(cfi.start.steps[i])
145
+ // Not a range
146
+ cfi.range = false
147
+ }
148
+ } else cfi.path.steps.push(cfi.start.steps[i])
149
+ } else break
182
150
  }
183
- cfi.start.steps = cfi.start.steps.slice(cfi.path.steps.length);
184
- cfi.end.steps = cfi.end.steps.slice(cfi.path.steps.length);
185
-
186
- return (
187
- 'epubcfi(' +
188
- CFI.segmentString(cfi.base) +
189
- '!' +
190
- CFI.segmentString(cfi.path) +
191
- ',' +
192
- CFI.segmentString(cfi.start) +
193
- ',' +
194
- CFI.segmentString(cfi.end) +
195
- ')'
196
- );
197
- };
151
+ cfi.start.steps = cfi.start.steps.slice(cfi.path.steps.length)
152
+ cfi.end.steps = cfi.end.steps.slice(cfi.path.steps.length)
153
+
154
+ return 'epubcfi(' + CFI.segmentString(cfi.base)
155
+ + '!' + CFI.segmentString(cfi.path)
156
+ + ',' + CFI.segmentString(cfi.start)
157
+ + ',' + CFI.segmentString(cfi.end)
158
+ + ')'
159
+ }
198
160
 
199
161
  if (!enableSelection) {
200
162
  rendition.themes.default({
201
- body: {
202
- '-webkit-touch-callout': 'none' /* iOS Safari */,
203
- '-webkit-user-select': 'none' /* Safari */,
204
- '-khtml-user-select': 'none' /* Konqueror HTML */,
205
- '-moz-user-select': 'none' /* Firefox */,
206
- '-ms-user-select': 'none' /* Internet Explorer/Edge */,
207
- 'user-select': 'none',
208
- },
163
+ 'body': {
164
+ '-webkit-touch-callout': 'none', /* iOS Safari */
165
+ '-webkit-user-select': 'none', /* Safari */
166
+ '-khtml-user-select': 'none', /* Konqueror HTML */
167
+ '-moz-user-select': 'none', /* Firefox */
168
+ '-ms-user-select': 'none', /* Internet Explorer/Edge */
169
+ 'user-select': 'none'
170
+ }
209
171
  });
210
172
  }
211
173
 
@@ -219,21 +181,20 @@ export default `
219
181
  .then(function () {
220
182
  var currentLocation = rendition.currentLocation();
221
183
 
222
- reactNativeWebview.postMessage(
223
- JSON.stringify({
224
- type: 'onReady',
225
- totalLocations: book.locations.total,
226
- currentLocation: currentLocation,
227
- progress: currentLocation?.start?.cfi
228
- ? book.locations.percentageFromCfi(currentLocation.start.cfi)
229
- : 0,
230
- })
231
- );
232
-
233
- if (initialLocations) {
234
- reactNativeWebview.postMessage(
235
- JSON.stringify({
236
- type: 'onLocationsReady',
184
+ reactNativeWebview.postMessage(JSON.stringify({
185
+ type: "onReady",
186
+ totalLocations: book.locations.total,
187
+ currentLocation: currentLocation,
188
+ progress: currentLocation?.start?.cfi
189
+ ? book.locations.percentageFromCfi(currentLocation.start.cfi)
190
+ : 0,
191
+ }));
192
+
193
+ // Defer heavier work to let the onReady bridge message be delivered first.
194
+ setTimeout(function () {
195
+ if (initialLocations && initialLocations.length) {
196
+ reactNativeWebview.postMessage(JSON.stringify({
197
+ type: "onLocationsReady",
237
198
  epubKey: book.key(),
238
199
  locations: initialLocations,
239
200
  totalLocations: book.locations.total,
@@ -241,52 +202,41 @@ export default `
241
202
  progress: currentLocation?.start?.cfi
242
203
  ? book.locations.percentageFromCfi(currentLocation.start.cfi)
243
204
  : 0,
244
- })
245
- );
246
- return Promise.resolve();
247
- }
248
-
249
- return book.locations
250
- .generate(1600)
251
- .then(function () {
252
- var generatedLocation =
253
- rendition.currentLocation() || currentLocation;
254
- reactNativeWebview.postMessage(
255
- JSON.stringify({
256
- type: 'onLocationsReady',
205
+ }));
206
+ } else {
207
+ // Larger chunk size reduces startup cost for the first locations map.
208
+ book.locations.generate(LOCATION_GENERATION_CHARS).then(function () {
209
+ var generatedLocation = rendition.currentLocation() || currentLocation;
210
+ reactNativeWebview.postMessage(JSON.stringify({
211
+ type: "onLocationsReady",
257
212
  epubKey: book.key(),
258
213
  locations: book.locations.save(),
259
214
  totalLocations: book.locations.total,
260
215
  currentLocation: generatedLocation,
261
216
  progress: generatedLocation?.start?.cfi
262
- ? book.locations.percentageFromCfi(
263
- generatedLocation.start.cfi
264
- )
217
+ ? book.locations.percentageFromCfi(generatedLocation.start.cfi)
265
218
  : 0,
266
- })
267
- );
268
- })
269
- .catch(function () {
270
- reactNativeWebview.postMessage(
271
- JSON.stringify({
272
- type: 'onLocationsReady',
219
+ }));
220
+ }).catch(function () {
221
+ reactNativeWebview.postMessage(JSON.stringify({
222
+ type: "onLocationsReady",
273
223
  epubKey: book.key(),
274
224
  locations: [],
275
225
  totalLocations: book.locations.total,
276
226
  currentLocation: currentLocation,
277
227
  progress: 0,
278
- })
279
- );
280
- });
228
+ }));
229
+ });
230
+ }
281
231
 
282
- book
232
+ book
283
233
  .coverUrl()
284
234
  .then(async (url) => {
285
235
  var reader = new FileReader();
286
- reader.onload = (res) => {
236
+ reader.onload = () => {
287
237
  reactNativeWebview.postMessage(
288
238
  JSON.stringify({
289
- type: 'meta',
239
+ type: "meta",
290
240
  metadata: {
291
241
  cover: reader.result,
292
242
  author: book.package.metadata.creator,
@@ -304,7 +254,7 @@ export default `
304
254
  .catch(() => {
305
255
  reactNativeWebview.postMessage(
306
256
  JSON.stringify({
307
- type: 'meta',
257
+ type: "meta",
308
258
  metadata: {
309
259
  cover: undefined,
310
260
  author: book.package.metadata.creator,
@@ -318,37 +268,34 @@ export default `
318
268
  );
319
269
  });
320
270
 
321
- book.loaded.navigation.then(function (item) {
322
- reactNativeWebview.postMessage(
323
- JSON.stringify({
271
+ book.loaded.navigation.then(function (item) {
272
+ reactNativeWebview.postMessage(JSON.stringify({
324
273
  type: 'onNavigationLoaded',
325
274
  toc: item.toc,
326
- landmarks: item.landmarks,
327
- })
328
- );
329
- });
275
+ landmarks: item.landmarks
276
+ }));
277
+ });
278
+ }, 0);
330
279
  })
331
280
  .catch(function (err) {
332
- reactNativeWebview.postMessage(
333
- JSON.stringify({
334
- type: 'onDisplayError',
335
- reason: err.message || err.toString(),
336
- })
337
- );
338
- });
281
+ reactNativeWebview.postMessage(JSON.stringify({
282
+ type: "onDisplayError",
283
+ reason: err.message || err.toString()
284
+ }));
285
+ });
339
286
 
340
287
  let isAnimating = false;
341
288
  const originalNext = rendition.next.bind(rendition);
342
289
  const originalPrev = rendition.prev.bind(rendition);
343
290
 
344
- rendition.next = function () {
291
+ rendition.next = function() {
345
292
  if (isAnimating) return;
346
293
  isAnimating = true;
347
-
294
+
348
295
  const container = rendition.manager.container;
349
296
  container.style.transition = 'opacity 0.2s ease-out';
350
297
  container.style.opacity = '0.4';
351
-
298
+
352
299
  setTimeout(() => {
353
300
  originalNext();
354
301
  setTimeout(() => {
@@ -361,14 +308,14 @@ export default `
361
308
  }, 100);
362
309
  };
363
310
 
364
- rendition.prev = function () {
311
+ rendition.prev = function() {
365
312
  if (isAnimating) return;
366
313
  isAnimating = true;
367
-
314
+
368
315
  const container = rendition.manager.container;
369
316
  container.style.transition = 'opacity 0.2s ease-out';
370
317
  container.style.opacity = '0.4';
371
-
318
+
372
319
  setTimeout(() => {
373
320
  originalPrev();
374
321
  setTimeout(() => {
@@ -386,55 +333,71 @@ export default `
386
333
  rendition.themes.select('theme');
387
334
  });
388
335
 
389
- rendition.on('relocated', function (location) {
336
+ rendition.on("relocated", function (location) {
390
337
  var percent = book.locations.percentageFromCfi(location.start.cfi);
391
338
  var percentage = Math.floor(percent * 100);
392
339
  var chapter = getChapter(location);
393
340
 
394
- reactNativeWebview.postMessage(
395
- JSON.stringify({
396
- type: 'onLocationChange',
397
- totalLocations: book.locations.total,
398
- currentLocation: location,
399
- progress: percentage,
400
- currentSection: chapter,
401
- })
402
- );
341
+ reactNativeWebview.postMessage(JSON.stringify({
342
+ type: "onLocationChange",
343
+ totalLocations: book.locations.total,
344
+ currentLocation: location,
345
+ progress: percentage,
346
+ currentSection: chapter,
347
+ }));
403
348
 
404
349
  if (location.atStart) {
405
- reactNativeWebview.postMessage(
406
- JSON.stringify({
407
- type: 'onBeginning',
408
- })
409
- );
350
+ reactNativeWebview.postMessage(JSON.stringify({
351
+ type: "onBeginning",
352
+ }));
410
353
  }
411
354
 
412
355
  if (location.atEnd) {
413
- reactNativeWebview.postMessage(
414
- JSON.stringify({
415
- type: 'onFinish',
416
- })
417
- );
356
+ reactNativeWebview.postMessage(JSON.stringify({
357
+ type: "onFinish",
358
+ }));
418
359
  }
419
360
  });
420
361
 
421
- rendition.on('rendered', function (section) {
422
- reactNativeWebview.postMessage(
423
- JSON.stringify({
424
- type: 'onRendered',
425
- section: section,
426
- currentSection: book.navigation.get(section.href),
427
- })
428
- );
362
+ rendition.on("orientationchange", function (orientation) {
363
+ reactNativeWebview.postMessage(JSON.stringify({
364
+ type: 'onOrientationChange',
365
+ orientation: orientation
366
+ }));
367
+ });
368
+
369
+ rendition.on("rendered", function (section) {
370
+ reactNativeWebview.postMessage(JSON.stringify({
371
+ type: 'onRendered',
372
+ section: section,
373
+ currentSection: book.navigation.get(section.href),
374
+ }));
375
+ });
376
+
377
+ rendition.on("layout", function (layout) {
378
+ reactNativeWebview.postMessage(JSON.stringify({
379
+ type: 'onLayout',
380
+ layout: layout,
381
+ }));
382
+ });
383
+
384
+ rendition.on("selected", function (cfiRange, contents) {
385
+ book.getRange(cfiRange).then(function (range) {
386
+ if (range) {
387
+ reactNativeWebview.postMessage(JSON.stringify({
388
+ type: 'onSelected',
389
+ cfiRange: cfiRange,
390
+ text: range.toString(),
391
+ }));
392
+ }
393
+ });
429
394
  });
430
395
 
431
- rendition.on('layout', function (layout) {
432
- reactNativeWebview.postMessage(
433
- JSON.stringify({
434
- type: 'onLayout',
435
- layout: layout,
436
- })
437
- );
396
+ rendition.on("resized", function (layout) {
397
+ reactNativeWebview.postMessage(JSON.stringify({
398
+ type: 'onResized',
399
+ layout: layout,
400
+ }));
438
401
  });
439
402
  </script>
440
403
  </body>
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["constants/template.ts"],"mappings":";;AAAA,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["constants/template.ts"],"mappings":";;AAAA,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
@@ -2,42 +2,59 @@
2
2
 
3
3
  export const defaultTheme = {
4
4
  'body': {
5
- background: '#FFF'
5
+ background: '#211F26'
6
6
  },
7
7
  'span': {
8
- color: '#000'
8
+ color: '#ffffff !important',
9
+ backgroundColor: '#211F26'
9
10
  },
10
11
  'p': {
11
- color: '#000'
12
+ color: '#ffffff !important',
13
+ backgroundColor: '#211F26'
12
14
  },
13
15
  'li': {
14
- color: '#000'
16
+ color: '#ffffff !important',
17
+ backgroundColor: '#211F26'
15
18
  },
16
19
  'h1': {
17
- color: '#000'
20
+ color: '#ffffff !important',
21
+ backgroundColor: '#211F26'
18
22
  },
19
23
  'h2': {
20
- color: '#000'
24
+ color: '#ffffff !important',
25
+ backgroundColor: '#211F26'
21
26
  },
22
27
  'h3': {
23
- color: '#000'
28
+ color: '#ffffff !important',
29
+ backgroundColor: '#211F26'
24
30
  },
25
31
  'h4': {
26
- color: '#000'
32
+ color: '#ffffff !important',
33
+ backgroundColor: '#211F26'
27
34
  },
28
35
  'h5': {
29
- color: '#000'
36
+ color: '#ffffff !important',
37
+ backgroundColor: '#211F26'
30
38
  },
31
39
  'h6': {
32
- color: '#000'
40
+ color: '#ffffff !important',
41
+ backgroundColor: '#211F26'
33
42
  },
34
43
  'a': {
35
- 'color': '#000',
44
+ 'color': '#ffffff !important',
45
+ 'backgroundColor': '#211F26',
36
46
  'pointer-events': 'auto',
37
47
  'cursor': 'pointer'
38
48
  },
49
+ '*': {
50
+ color: '#ffffff !important',
51
+ backgroundColor: '#211F26'
52
+ },
39
53
  '::selection': {
40
54
  background: 'lightskyblue'
55
+ },
56
+ '::marker': {
57
+ color: '#ffffff !important'
41
58
  }
42
59
  };
43
60
  //# sourceMappingURL=theme.js.map