react-native-simple-epub-reader 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,16 +25,18 @@ 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=") no-repeat;
28
+ [ref='epubjs-mk-balloon'] {
29
+ background: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPScxLjEnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZycgeG1sbnM6eGxpbms9J2h0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsnIHg9JzBweCcgeT0nMHB4JyB2aWV3Qm94PScwIDAgNzUgNzUnPjxnIGZpbGw9JyNCREJEQkQnIGlkPSdidWJibGUnPjxwYXRoIGNsYXNzPSdzdDAnIGQ9J00zNy41LDkuNEMxOS42LDkuNCw1LDIwLjUsNSwzNC4zYzAsNS45LDIuNywxMS4zLDcuMSwxNS42TDkuNiw2NS42bDE5LTcuM2MyLjgsMC42LDUuOCwwLjksOC45LDAuOSBDNTUuNSw1OS4yLDcwLDQ4LjEsNzAsMzQuM0M3MCwyMC41LDU1LjQsOS40LDM3LjUsOS40eicvPjwvZz48L3N2Zz4=')
30
+ no-repeat;
30
31
  width: 20px;
31
32
  height: 20px;
32
33
  cursor: pointer;
33
34
  margin-left: 0;
34
35
  }
35
36
 
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;
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;
38
40
  width: 20px;
39
41
  height: 20px;
40
42
  cursor: pointer;
@@ -43,7 +45,7 @@ export default `
43
45
  </style>
44
46
  </head>
45
47
 
46
- <body oncopy='return false' oncut='return false'>
48
+ <body oncopy="return false;" oncut="return false;">
47
49
  <div id="viewer"></div>
48
50
 
49
51
  <script>
@@ -59,114 +61,151 @@ export default `
59
61
  const allowPopups = window.allowPopups || false;
60
62
 
61
63
  if (!file) {
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
- }));
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
+ );
67
75
  }
68
76
 
69
77
  if (type === 'epub' || type === 'opf' || type === 'binary') {
70
78
  book = ePub(file);
71
79
  } else if (type === 'base64') {
72
- book = ePub(file, { encoding: "base64" });
80
+ book = ePub(file, { encoding: 'base64' });
73
81
  } else {
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
- }));
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
+ );
79
93
  }
80
94
 
81
- rendition = book.renderTo("viewer", {
82
- width: "100%",
83
- height: "100%",
84
- manager: "default",
85
- flow: "auto",
95
+ rendition = book.renderTo('viewer', {
96
+ width: '100%',
97
+ height: '100%',
98
+ manager: 'default',
99
+ flow: 'auto',
86
100
  snap: undefined,
87
101
  spread: undefined,
88
102
  fullsize: undefined,
89
103
  allowPopups: allowPopups,
90
- allowScriptedContent: allowScriptedContent
104
+ allowScriptedContent: allowScriptedContent,
91
105
  });
92
-
93
- const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView!== null ? window.ReactNativeWebView: window;
94
- reactNativeWebview.postMessage(JSON.stringify({ type: "onStarted" }));
106
+
107
+ const reactNativeWebview =
108
+ window.ReactNativeWebView !== undefined &&
109
+ window.ReactNativeWebView !== null
110
+ ? window.ReactNativeWebView
111
+ : window;
112
+ reactNativeWebview.postMessage(JSON.stringify({ type: 'onStarted' }));
95
113
 
96
114
  function flatten(chapters) {
97
- return [].concat.apply([], chapters.map((chapter) => [].concat.apply([chapter], flatten(chapter.subitems))));
115
+ return [].concat.apply(
116
+ [],
117
+ chapters.map((chapter) =>
118
+ [].concat.apply([chapter], flatten(chapter.subitems))
119
+ )
120
+ );
98
121
  }
99
122
 
100
123
  function getCfiFromHref(book, href) {
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)
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);
106
134
  }
107
135
 
108
136
  function getChapter(location) {
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
- };
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
+ }
122
154
 
123
155
  const makeRangeCfi = (a, b) => {
124
- const CFI = new ePub.CFI()
125
- const start = CFI.parse(a), end = CFI.parse(b)
156
+ const CFI = new ePub.CFI();
157
+ const start = CFI.parse(a),
158
+ end = CFI.parse(b);
126
159
  const cfi = {
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
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;
137
170
  for (let i = 0; i < len; i++) {
138
171
  if (CFI.equalStep(cfi.start.steps[i], cfi.end.steps[i])) {
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
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;
149
182
  }
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
- }
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
+ };
159
198
 
160
199
  if (!enableSelection) {
161
200
  rendition.themes.default({
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
- }
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
+ },
170
209
  });
171
210
  }
172
211
 
@@ -180,62 +219,94 @@ export default `
180
219
  .then(function () {
181
220
  var currentLocation = rendition.currentLocation();
182
221
 
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,
222
+ reactNativeWebview.postMessage(
223
+ JSON.stringify({
224
+ type: 'onReady',
197
225
  totalLocations: book.locations.total,
198
226
  currentLocation: currentLocation,
199
227
  progress: currentLocation?.start?.cfi
200
228
  ? book.locations.percentageFromCfi(currentLocation.start.cfi)
201
229
  : 0,
202
- }));
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
+ );
203
246
  return Promise.resolve();
204
247
  }
205
248
 
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
- });
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
+ });
228
281
 
229
282
  book
230
- .coverUrl()
231
- .then(async (url) => {
232
- var reader = new FileReader();
233
- reader.onload = (res) => {
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(() => {
234
305
  reactNativeWebview.postMessage(
235
306
  JSON.stringify({
236
- type: "meta",
307
+ type: 'meta',
237
308
  metadata: {
238
- cover: reader.result,
309
+ cover: undefined,
239
310
  author: book.package.metadata.creator,
240
311
  title: book.package.metadata.title,
241
312
  description: book.package.metadata.description,
@@ -245,53 +316,39 @@ export default `
245
316
  },
246
317
  })
247
318
  );
248
- };
249
- reader.readAsDataURL(await fetch(url).then((res) => res.blob()));
250
- })
251
- .catch(() => {
319
+ });
320
+
321
+ book.loaded.navigation.then(function (item) {
252
322
  reactNativeWebview.postMessage(
253
323
  JSON.stringify({
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
- },
324
+ type: 'onNavigationLoaded',
325
+ toc: item.toc,
326
+ landmarks: item.landmarks,
264
327
  })
265
328
  );
266
329
  });
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
- });
275
330
  })
276
331
  .catch(function (err) {
277
- reactNativeWebview.postMessage(JSON.stringify({
278
- type: "onDisplayError",
279
- reason: err.message || err.toString()
280
- }));
281
- });
332
+ reactNativeWebview.postMessage(
333
+ JSON.stringify({
334
+ type: 'onDisplayError',
335
+ reason: err.message || err.toString(),
336
+ })
337
+ );
338
+ });
282
339
 
283
340
  let isAnimating = false;
284
341
  const originalNext = rendition.next.bind(rendition);
285
342
  const originalPrev = rendition.prev.bind(rendition);
286
343
 
287
- rendition.next = function() {
344
+ rendition.next = function () {
288
345
  if (isAnimating) return;
289
346
  isAnimating = true;
290
-
347
+
291
348
  const container = rendition.manager.container;
292
349
  container.style.transition = 'opacity 0.2s ease-out';
293
350
  container.style.opacity = '0.4';
294
-
351
+
295
352
  setTimeout(() => {
296
353
  originalNext();
297
354
  setTimeout(() => {
@@ -304,14 +361,14 @@ export default `
304
361
  }, 100);
305
362
  };
306
363
 
307
- rendition.prev = function() {
364
+ rendition.prev = function () {
308
365
  if (isAnimating) return;
309
366
  isAnimating = true;
310
-
367
+
311
368
  const container = rendition.manager.container;
312
369
  container.style.transition = 'opacity 0.2s ease-out';
313
370
  container.style.opacity = '0.4';
314
-
371
+
315
372
  setTimeout(() => {
316
373
  originalPrev();
317
374
  setTimeout(() => {
@@ -329,71 +386,55 @@ export default `
329
386
  rendition.themes.select('theme');
330
387
  });
331
388
 
332
- rendition.on("relocated", function (location) {
389
+ rendition.on('relocated', function (location) {
333
390
  var percent = book.locations.percentageFromCfi(location.start.cfi);
334
391
  var percentage = Math.floor(percent * 100);
335
392
  var chapter = getChapter(location);
336
393
 
337
- reactNativeWebview.postMessage(JSON.stringify({
338
- type: "onLocationChange",
339
- totalLocations: book.locations.total,
340
- currentLocation: location,
341
- progress: percentage,
342
- currentSection: chapter,
343
- }));
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
+ );
344
403
 
345
404
  if (location.atStart) {
346
- reactNativeWebview.postMessage(JSON.stringify({
347
- type: "onBeginning",
348
- }));
405
+ reactNativeWebview.postMessage(
406
+ JSON.stringify({
407
+ type: 'onBeginning',
408
+ })
409
+ );
349
410
  }
350
411
 
351
412
  if (location.atEnd) {
352
- reactNativeWebview.postMessage(JSON.stringify({
353
- type: "onFinish",
354
- }));
413
+ reactNativeWebview.postMessage(
414
+ JSON.stringify({
415
+ type: 'onFinish',
416
+ })
417
+ );
355
418
  }
356
419
  });
357
420
 
358
- rendition.on("orientationchange", function (orientation) {
359
- reactNativeWebview.postMessage(JSON.stringify({
360
- type: 'onOrientationChange',
361
- orientation: orientation
362
- }));
363
- });
364
-
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
- });
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
+ );
390
429
  });
391
430
 
392
- rendition.on("resized", function (layout) {
393
- reactNativeWebview.postMessage(JSON.stringify({
394
- type: 'onResized',
395
- layout: layout,
396
- }));
431
+ rendition.on('layout', function (layout) {
432
+ reactNativeWebview.postMessage(
433
+ JSON.stringify({
434
+ type: 'onLayout',
435
+ layout: layout,
436
+ })
437
+ );
397
438
  });
398
439
  </script>
399
440
  </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,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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,4 +1,4 @@
1
1
  import { type ReaderProps } from '../types';
2
- declare const Reader: ({ src, onTap, onSwipeLeft, onSwipeRight, initialLocation, onLocationsReady, onLocationChange, onFinish, onBeginning, onPinch, LoaderComponent, }: ReaderProps) => import("react/jsx-runtime").JSX.Element;
2
+ declare const Reader: ({ src, onTap, onSwipeLeft, onSwipeRight, initialLocation, onLocationsReady, onLocationChange, onFinish, onBeginning, onPinch, LoaderComponent, onWebViewMessage, }: ReaderProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default Reader;
4
4
  //# sourceMappingURL=Reader.d.ts.map
@@ -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;AAuBxD,QAAA,MAAM,MAAM,GAAI,kJAYb,WAAW,4CAoNb,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,4CAyNb,CAAC;AAaF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const INTERNAL_EVENTS: string[];
2
+ export default INTERNAL_EVENTS;
3
+ //# sourceMappingURL=internalEvents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internalEvents.d.ts","sourceRoot":"","sources":["../../../../src/constants/internalEvents.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe,UAwBpB,CAAC;AAEF,eAAe,eAAe,CAAC"}