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