react-native-simple-epub-reader 0.1.1 → 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.
- package/lib/module/components/Reader.js +52 -10
- package/lib/module/components/Reader.js.map +1 -1
- package/lib/module/constants/template.js +214 -255
- 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/module/helpers/downloadEpub.js +8 -1
- package/lib/module/helpers/downloadEpub.js.map +1 -1
- package/lib/typescript/src/components/Reader.d.ts.map +1 -1
- 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/helpers/downloadEpub.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Reader.tsx +60 -13
- package/src/constants/template.ts +214 -255
- package/src/context/ReaderContext.tsx +29 -27
- package/src/helpers/downloadEpub.ts +9 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
export default `
|
|
4
|
-
<!
|
|
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: #
|
|
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=
|
|
29
|
-
background: url(
|
|
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=
|
|
38
|
-
background: url(
|
|
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=
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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:
|
|
72
|
+
book = ePub(file, { encoding: "base64" });
|
|
81
73
|
} else {
|
|
82
|
-
const reactNativeWebview =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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(
|
|
96
|
-
width:
|
|
97
|
-
height:
|
|
98
|
-
manager:
|
|
99
|
-
flow:
|
|
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
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
224
|
-
|
|
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
|
-
.
|
|
251
|
-
.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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:
|
|
236
|
+
type: "meta",
|
|
308
237
|
metadata: {
|
|
309
|
-
cover:
|
|
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
|
-
|
|
248
|
+
};
|
|
249
|
+
reader.readAsDataURL(await fetch(url).then((res) => res.blob()));
|
|
250
|
+
})
|
|
251
|
+
.catch(() => {
|
|
322
252
|
reactNativeWebview.postMessage(
|
|
323
253
|
JSON.stringify({
|
|
324
|
-
type:
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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(
|
|
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
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
})
|
|
409
|
-
);
|
|
346
|
+
reactNativeWebview.postMessage(JSON.stringify({
|
|
347
|
+
type: "onBeginning",
|
|
348
|
+
}));
|
|
410
349
|
}
|
|
411
350
|
|
|
412
351
|
if (location.atEnd) {
|
|
413
|
-
reactNativeWebview.postMessage(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
})
|
|
417
|
-
);
|
|
352
|
+
reactNativeWebview.postMessage(JSON.stringify({
|
|
353
|
+
type: "onFinish",
|
|
354
|
+
}));
|
|
418
355
|
}
|
|
419
356
|
});
|
|
420
357
|
|
|
421
|
-
rendition.on(
|
|
422
|
-
reactNativeWebview.postMessage(
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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(
|
|
432
|
-
reactNativeWebview.postMessage(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|
|
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":[]}
|