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

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.
@@ -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>
@@ -61,151 +59,114 @@ export default `
61
59
  const allowPopups = window.allowPopups || false;
62
60
 
63
61
  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
- );
62
+ const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView !== null ? window.ReactNativeWebView : window;
63
+ reactNativeWebview.postMessage(JSON.stringify({
64
+ type: "onDisplayError",
65
+ reason: "Book file is missing"
66
+ }));
75
67
  }
76
68
 
77
69
  if (type === 'epub' || type === 'opf' || type === 'binary') {
78
70
  book = ePub(file);
79
71
  } else if (type === 'base64') {
80
- book = ePub(file, { encoding: 'base64' });
72
+ book = ePub(file, { encoding: "base64" });
81
73
  } 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
- );
74
+ const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView !== null ? window.ReactNativeWebView : window;
75
+ reactNativeWebview.postMessage(JSON.stringify({
76
+ type: "onDisplayError",
77
+ reason: "Missing or invalid file type"
78
+ }));
93
79
  }
94
80
 
95
- rendition = book.renderTo('viewer', {
96
- width: '100%',
97
- height: '100%',
98
- manager: 'default',
99
- flow: 'auto',
81
+ rendition = book.renderTo("viewer", {
82
+ width: "100%",
83
+ height: "100%",
84
+ manager: "default",
85
+ flow: "auto",
100
86
  snap: undefined,
101
87
  spread: undefined,
102
88
  fullsize: undefined,
103
89
  allowPopups: allowPopups,
104
- allowScriptedContent: allowScriptedContent,
90
+ allowScriptedContent: allowScriptedContent
105
91
  });
106
-
107
- const reactNativeWebview =
108
- window.ReactNativeWebView !== undefined &&
109
- window.ReactNativeWebView !== null
110
- ? window.ReactNativeWebView
111
- : window;
112
- reactNativeWebview.postMessage(JSON.stringify({ type: 'onStarted' }));
92
+
93
+ const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView!== null ? window.ReactNativeWebView: window;
94
+ reactNativeWebview.postMessage(JSON.stringify({ type: "onStarted" }));
113
95
 
114
96
  function flatten(chapters) {
115
- return [].concat.apply(
116
- [],
117
- chapters.map((chapter) =>
118
- [].concat.apply([chapter], flatten(chapter.subitems))
119
- )
120
- );
97
+ return [].concat.apply([], chapters.map((chapter) => [].concat.apply([chapter], flatten(chapter.subitems))));
121
98
  }
122
99
 
123
100
  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);
101
+ const [_, id] = href.split('#')
102
+ let section = book.spine.get(href.split('/')[1]) || book.spine.get(href) || book.spine.get(href.split('/').slice(1).join('/'))
103
+
104
+ const el = (id ? section.document.getElementById(id) : section.document.body)
105
+ return section.cfiFromElement(el)
134
106
  }
135
107
 
136
108
  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
- }
109
+ const locationHref = location.start.href
110
+
111
+ let match = flatten(book.navigation.toc)
112
+ .filter((chapter) => {
113
+ return book.canonical(chapter.href).includes(locationHref)
114
+ }, null)
115
+ .reduce((result, chapter) => {
116
+ const locationAfterChapter = ePub.CFI.prototype.compare(location.start.cfi, getCfiFromHref(book, chapter.href)) > 0
117
+ return locationAfterChapter ? chapter : result
118
+ }, null);
119
+
120
+ return match;
121
+ };
154
122
 
155
123
  const makeRangeCfi = (a, b) => {
156
- const CFI = new ePub.CFI();
157
- const start = CFI.parse(a),
158
- end = CFI.parse(b);
124
+ const CFI = new ePub.CFI()
125
+ const start = CFI.parse(a), end = CFI.parse(b)
159
126
  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;
127
+ range: true,
128
+ base: start.base,
129
+ path: {
130
+ steps: [],
131
+ terminal: null
132
+ },
133
+ start: start.path,
134
+ end: end.path
135
+ }
136
+ const len = cfi.start.steps.length
170
137
  for (let i = 0; i < len; i++) {
171
138
  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;
139
+ if (i == len - 1) {
140
+ // Last step is equal, check terminals
141
+ if (cfi.start.terminal === cfi.end.terminal) {
142
+ // CFI's are equal
143
+ cfi.path.steps.push(cfi.start.steps[i])
144
+ // Not a range
145
+ cfi.range = false
146
+ }
147
+ } else cfi.path.steps.push(cfi.start.steps[i])
148
+ } else break
182
149
  }
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
- };
150
+ cfi.start.steps = cfi.start.steps.slice(cfi.path.steps.length)
151
+ cfi.end.steps = cfi.end.steps.slice(cfi.path.steps.length)
152
+
153
+ return 'epubcfi(' + CFI.segmentString(cfi.base)
154
+ + '!' + CFI.segmentString(cfi.path)
155
+ + ',' + CFI.segmentString(cfi.start)
156
+ + ',' + CFI.segmentString(cfi.end)
157
+ + ')'
158
+ }
198
159
 
199
160
  if (!enableSelection) {
200
161
  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
- },
162
+ 'body': {
163
+ '-webkit-touch-callout': 'none', /* iOS Safari */
164
+ '-webkit-user-select': 'none', /* Safari */
165
+ '-khtml-user-select': 'none', /* Konqueror HTML */
166
+ '-moz-user-select': 'none', /* Firefox */
167
+ '-ms-user-select': 'none', /* Internet Explorer/Edge */
168
+ 'user-select': 'none'
169
+ }
209
170
  });
210
171
  }
211
172
 
@@ -219,94 +180,62 @@ export default `
219
180
  .then(function () {
220
181
  var currentLocation = rendition.currentLocation();
221
182
 
222
- reactNativeWebview.postMessage(
223
- JSON.stringify({
224
- type: 'onReady',
183
+ reactNativeWebview.postMessage(JSON.stringify({
184
+ type: "onReady",
185
+ totalLocations: book.locations.total,
186
+ currentLocation: currentLocation,
187
+ progress: currentLocation?.start?.cfi
188
+ ? book.locations.percentageFromCfi(currentLocation.start.cfi)
189
+ : 0,
190
+ }));
191
+
192
+ if (initialLocations) {
193
+ reactNativeWebview.postMessage(JSON.stringify({
194
+ type: "onLocationsReady",
195
+ epubKey: book.key(),
196
+ locations: initialLocations,
225
197
  totalLocations: book.locations.total,
226
198
  currentLocation: currentLocation,
227
199
  progress: currentLocation?.start?.cfi
228
200
  ? book.locations.percentageFromCfi(currentLocation.start.cfi)
229
201
  : 0,
230
- })
231
- );
232
-
233
- if (initialLocations) {
234
- reactNativeWebview.postMessage(
235
- JSON.stringify({
236
- type: 'onLocationsReady',
237
- epubKey: book.key(),
238
- locations: initialLocations,
239
- totalLocations: book.locations.total,
240
- currentLocation: currentLocation,
241
- progress: currentLocation?.start?.cfi
242
- ? book.locations.percentageFromCfi(currentLocation.start.cfi)
243
- : 0,
244
- })
245
- );
202
+ }));
246
203
  return Promise.resolve();
247
204
  }
248
205
 
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',
257
- epubKey: book.key(),
258
- locations: book.locations.save(),
259
- totalLocations: book.locations.total,
260
- currentLocation: generatedLocation,
261
- progress: generatedLocation?.start?.cfi
262
- ? book.locations.percentageFromCfi(
263
- generatedLocation.start.cfi
264
- )
265
- : 0,
266
- })
267
- );
268
- })
269
- .catch(function () {
270
- reactNativeWebview.postMessage(
271
- JSON.stringify({
272
- type: 'onLocationsReady',
273
- epubKey: book.key(),
274
- locations: [],
275
- totalLocations: book.locations.total,
276
- currentLocation: currentLocation,
277
- progress: 0,
278
- })
279
- );
280
- });
206
+ return book.locations.generate(1600).then(function () {
207
+ var generatedLocation = rendition.currentLocation() || currentLocation;
208
+ reactNativeWebview.postMessage(JSON.stringify({
209
+ type: "onLocationsReady",
210
+ epubKey: book.key(),
211
+ locations: book.locations.save(),
212
+ totalLocations: book.locations.total,
213
+ currentLocation: generatedLocation,
214
+ progress: generatedLocation?.start?.cfi
215
+ ? book.locations.percentageFromCfi(generatedLocation.start.cfi)
216
+ : 0,
217
+ }));
218
+ }).catch(function () {
219
+ reactNativeWebview.postMessage(JSON.stringify({
220
+ type: "onLocationsReady",
221
+ epubKey: book.key(),
222
+ locations: [],
223
+ totalLocations: book.locations.total,
224
+ currentLocation: currentLocation,
225
+ progress: 0,
226
+ }));
227
+ });
281
228
 
282
229
  book
283
- .coverUrl()
284
- .then(async (url) => {
285
- var reader = new FileReader();
286
- reader.onload = (res) => {
287
- reactNativeWebview.postMessage(
288
- JSON.stringify({
289
- type: 'meta',
290
- metadata: {
291
- cover: reader.result,
292
- author: book.package.metadata.creator,
293
- title: book.package.metadata.title,
294
- description: book.package.metadata.description,
295
- language: book.package.metadata.language,
296
- publisher: book.package.metadata.publisher,
297
- rights: book.package.metadata.rights,
298
- },
299
- })
300
- );
301
- };
302
- reader.readAsDataURL(await fetch(url).then((res) => res.blob()));
303
- })
304
- .catch(() => {
230
+ .coverUrl()
231
+ .then(async (url) => {
232
+ var reader = new FileReader();
233
+ reader.onload = (res) => {
305
234
  reactNativeWebview.postMessage(
306
235
  JSON.stringify({
307
- type: 'meta',
236
+ type: "meta",
308
237
  metadata: {
309
- cover: undefined,
238
+ cover: reader.result,
310
239
  author: book.package.metadata.creator,
311
240
  title: book.package.metadata.title,
312
241
  description: book.package.metadata.description,
@@ -316,39 +245,53 @@ export default `
316
245
  },
317
246
  })
318
247
  );
319
- });
320
-
321
- book.loaded.navigation.then(function (item) {
248
+ };
249
+ reader.readAsDataURL(await fetch(url).then((res) => res.blob()));
250
+ })
251
+ .catch(() => {
322
252
  reactNativeWebview.postMessage(
323
253
  JSON.stringify({
324
- type: 'onNavigationLoaded',
325
- toc: item.toc,
326
- landmarks: item.landmarks,
254
+ type: "meta",
255
+ metadata: {
256
+ cover: undefined,
257
+ author: book.package.metadata.creator,
258
+ title: book.package.metadata.title,
259
+ description: book.package.metadata.description,
260
+ language: book.package.metadata.language,
261
+ publisher: book.package.metadata.publisher,
262
+ rights: book.package.metadata.rights,
263
+ },
327
264
  })
328
265
  );
329
266
  });
267
+
268
+ book.loaded.navigation.then(function (item) {
269
+ reactNativeWebview.postMessage(JSON.stringify({
270
+ type: 'onNavigationLoaded',
271
+ toc: item.toc,
272
+ landmarks: item.landmarks
273
+ }));
274
+ });
330
275
  })
331
276
  .catch(function (err) {
332
- reactNativeWebview.postMessage(
333
- JSON.stringify({
334
- type: 'onDisplayError',
335
- reason: err.message || err.toString(),
336
- })
337
- );
338
- });
277
+ reactNativeWebview.postMessage(JSON.stringify({
278
+ type: "onDisplayError",
279
+ reason: err.message || err.toString()
280
+ }));
281
+ });
339
282
 
340
283
  let isAnimating = false;
341
284
  const originalNext = rendition.next.bind(rendition);
342
285
  const originalPrev = rendition.prev.bind(rendition);
343
286
 
344
- rendition.next = function () {
287
+ rendition.next = function() {
345
288
  if (isAnimating) return;
346
289
  isAnimating = true;
347
-
290
+
348
291
  const container = rendition.manager.container;
349
292
  container.style.transition = 'opacity 0.2s ease-out';
350
293
  container.style.opacity = '0.4';
351
-
294
+
352
295
  setTimeout(() => {
353
296
  originalNext();
354
297
  setTimeout(() => {
@@ -361,14 +304,14 @@ export default `
361
304
  }, 100);
362
305
  };
363
306
 
364
- rendition.prev = function () {
307
+ rendition.prev = function() {
365
308
  if (isAnimating) return;
366
309
  isAnimating = true;
367
-
310
+
368
311
  const container = rendition.manager.container;
369
312
  container.style.transition = 'opacity 0.2s ease-out';
370
313
  container.style.opacity = '0.4';
371
-
314
+
372
315
  setTimeout(() => {
373
316
  originalPrev();
374
317
  setTimeout(() => {
@@ -386,55 +329,71 @@ export default `
386
329
  rendition.themes.select('theme');
387
330
  });
388
331
 
389
- rendition.on('relocated', function (location) {
332
+ rendition.on("relocated", function (location) {
390
333
  var percent = book.locations.percentageFromCfi(location.start.cfi);
391
334
  var percentage = Math.floor(percent * 100);
392
335
  var chapter = getChapter(location);
393
336
 
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
- );
337
+ reactNativeWebview.postMessage(JSON.stringify({
338
+ type: "onLocationChange",
339
+ totalLocations: book.locations.total,
340
+ currentLocation: location,
341
+ progress: percentage,
342
+ currentSection: chapter,
343
+ }));
403
344
 
404
345
  if (location.atStart) {
405
- reactNativeWebview.postMessage(
406
- JSON.stringify({
407
- type: 'onBeginning',
408
- })
409
- );
346
+ reactNativeWebview.postMessage(JSON.stringify({
347
+ type: "onBeginning",
348
+ }));
410
349
  }
411
350
 
412
351
  if (location.atEnd) {
413
- reactNativeWebview.postMessage(
414
- JSON.stringify({
415
- type: 'onFinish',
416
- })
417
- );
352
+ reactNativeWebview.postMessage(JSON.stringify({
353
+ type: "onFinish",
354
+ }));
418
355
  }
419
356
  });
420
357
 
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
- );
358
+ rendition.on("orientationchange", function (orientation) {
359
+ reactNativeWebview.postMessage(JSON.stringify({
360
+ type: 'onOrientationChange',
361
+ orientation: orientation
362
+ }));
429
363
  });
430
364
 
431
- rendition.on('layout', function (layout) {
432
- reactNativeWebview.postMessage(
433
- JSON.stringify({
434
- type: 'onLayout',
435
- layout: layout,
436
- })
437
- );
365
+ rendition.on("rendered", function (section) {
366
+ reactNativeWebview.postMessage(JSON.stringify({
367
+ type: 'onRendered',
368
+ section: section,
369
+ currentSection: book.navigation.get(section.href),
370
+ }));
371
+ });
372
+
373
+ rendition.on("layout", function (layout) {
374
+ reactNativeWebview.postMessage(JSON.stringify({
375
+ type: 'onLayout',
376
+ layout: layout,
377
+ }));
378
+ });
379
+
380
+ rendition.on("selected", function (cfiRange, contents) {
381
+ book.getRange(cfiRange).then(function (range) {
382
+ if (range) {
383
+ reactNativeWebview.postMessage(JSON.stringify({
384
+ type: 'onSelected',
385
+ cfiRange: cfiRange,
386
+ text: range.toString(),
387
+ }));
388
+ }
389
+ });
390
+ });
391
+
392
+ rendition.on("resized", function (layout) {
393
+ reactNativeWebview.postMessage(JSON.stringify({
394
+ type: 'onResized',
395
+ layout: layout,
396
+ }));
438
397
  });
439
398
  </script>
440
399
  </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,CAAC","ignoreList":[]}
@@ -7,7 +7,14 @@ export const downloadEpub = async (url, fileName) => {
7
7
  if (file.exists) {
8
8
  return file.uri;
9
9
  }
10
- const downloadedFile = await File.downloadFileAsync(url, file);
10
+ const normalized = url.split('?X-Goog-Algorithm')[0];
11
+ if (!normalized) {
12
+ throw new Error('Invalid URL provided for EPUB download.');
13
+ }
14
+ console.log({
15
+ url
16
+ });
17
+ const downloadedFile = await File.downloadFileAsync(normalized, file);
11
18
  return downloadedFile.uri;
12
19
  } catch (error) {
13
20
  console.error('Download Error:', error);
@@ -1 +1 @@
1
- {"version":3,"names":["File","Paths","downloadEpub","url","fileName","file","document","exists","uri","downloadedFile","downloadFileAsync","error","console"],"sourceRoot":"../../../src","sources":["helpers/downloadEpub.ts"],"mappings":";;AAAA,SAASA,IAAI,EAAEC,KAAK,QAAQ,kBAAkB;AAE9C,OAAO,MAAMC,YAAY,GAAG,MAAAA,CAC1BC,GAAW,EACXC,QAAgB,KACI;EACpB,IAAI;IACF,MAAMC,IAAI,GAAG,IAAIL,IAAI,CAACC,KAAK,CAACK,QAAQ,EAAEF,QAAQ,CAAC;IAE/C,IAAIC,IAAI,CAACE,MAAM,EAAE;MACf,OAAOF,IAAI,CAACG,GAAG;IACjB;IAEA,MAAMC,cAAc,GAAG,MAAMT,IAAI,CAACU,iBAAiB,CAACP,GAAG,EAAEE,IAAI,CAAC;IAE9D,OAAOI,cAAc,CAACD,GAAG;EAC3B,CAAC,CAAC,OAAOG,KAAK,EAAE;IACdC,OAAO,CAACD,KAAK,CAAC,iBAAiB,EAAEA,KAAK,CAAC;IACvC,MAAMA,KAAK;EACb;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["File","Paths","downloadEpub","url","fileName","file","document","exists","uri","normalized","split","Error","console","log","downloadedFile","downloadFileAsync","error"],"sourceRoot":"../../../src","sources":["helpers/downloadEpub.ts"],"mappings":";;AAAA,SAASA,IAAI,EAAEC,KAAK,QAAQ,kBAAkB;AAE9C,OAAO,MAAMC,YAAY,GAAG,MAAAA,CAC1BC,GAAW,EACXC,QAAgB,KACI;EACpB,IAAI;IACF,MAAMC,IAAI,GAAG,IAAIL,IAAI,CAACC,KAAK,CAACK,QAAQ,EAAEF,QAAQ,CAAC;IAE/C,IAAIC,IAAI,CAACE,MAAM,EAAE;MACf,OAAOF,IAAI,CAACG,GAAG;IACjB;IAEA,MAAMC,UAAU,GAAGN,GAAG,CAACO,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAEpD,IAAI,CAACD,UAAU,EAAE;MACf,MAAM,IAAIE,KAAK,CAAC,yCAAyC,CAAC;IAC5D;IAEAC,OAAO,CAACC,GAAG,CAAC;MAAEV;IAAI,CAAC,CAAC;IAEpB,MAAMW,cAAc,GAAG,MAAMd,IAAI,CAACe,iBAAiB,CAACN,UAAU,EAAEJ,IAAI,CAAC;IAErE,OAAOS,cAAc,CAACN,GAAG;EAC3B,CAAC,CAAC,OAAOQ,KAAK,EAAE;IACdJ,OAAO,CAACI,KAAK,CAAC,iBAAiB,EAAEA,KAAK,CAAC;IACvC,MAAMA,KAAK;EACb;AACF,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"Reader.d.ts","sourceRoot":"","sources":["../../../../src/components/Reader.tsx"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAwBxD,QAAA,MAAM,MAAM,GAAI,oKAab,WAAW,4CA8Ob,CAAC;AAaF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Reader.d.ts","sourceRoot":"","sources":["../../../../src/components/Reader.tsx"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAwBxD,QAAA,MAAM,MAAM,GAAI,oKAab,WAAW,4CAmQb,CAAC;AAkBF,eAAe,MAAM,CAAC"}