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
|
@@ -112,8 +112,11 @@ function ReaderProvider({
|
|
|
112
112
|
const getMeta = useCallback(() => state.meta, [state.meta]);
|
|
113
113
|
const changeFontFamily = useCallback(fontFamily => {
|
|
114
114
|
book.current?.injectJavaScript(`
|
|
115
|
-
rendition
|
|
116
|
-
|
|
115
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
116
|
+
rendition.themes.font('${fontFamily}');
|
|
117
|
+
rendition.views().forEach(view => view.pane ? view.pane.render() : null);
|
|
118
|
+
}
|
|
119
|
+
true;
|
|
117
120
|
`);
|
|
118
121
|
dispatch({
|
|
119
122
|
type: Actions.CHANGE_FONT_FAMILY,
|
|
@@ -123,24 +126,14 @@ function ReaderProvider({
|
|
|
123
126
|
const injectJavascript = useCallback(script => {
|
|
124
127
|
book.current?.injectJavaScript(script);
|
|
125
128
|
}, []);
|
|
126
|
-
const changeFlow = useCallback(flow => {
|
|
127
|
-
webViewInjectFunctions.injectJavaScript(book, `rendition.flow(${JSON.stringify(flow)}); true`);
|
|
128
|
-
dispatch({
|
|
129
|
-
type: Actions.SET_FLOW,
|
|
130
|
-
payload: flow
|
|
131
|
-
});
|
|
132
|
-
}, []);
|
|
133
|
-
const setFlow = useCallback(flow => {
|
|
134
|
-
dispatch({
|
|
135
|
-
type: Actions.SET_FLOW,
|
|
136
|
-
payload: flow
|
|
137
|
-
});
|
|
138
|
-
}, []);
|
|
139
129
|
const changeTheme = useCallback(theme => {
|
|
140
130
|
book.current?.injectJavaScript(`
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
131
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
132
|
+
rendition.themes.register({ theme: ${JSON.stringify(theme)} });
|
|
133
|
+
rendition.themes.select('theme');
|
|
134
|
+
rendition.views().forEach(view => view.pane ? view.pane.render() : null);
|
|
135
|
+
}
|
|
136
|
+
true;
|
|
144
137
|
`);
|
|
145
138
|
dispatch({
|
|
146
139
|
type: Actions.CHANGE_THEME,
|
|
@@ -149,21 +142,33 @@ function ReaderProvider({
|
|
|
149
142
|
}, []);
|
|
150
143
|
const goNext = useCallback(() => {
|
|
151
144
|
webViewInjectFunctions.injectJavaScript(book, `
|
|
152
|
-
rendition
|
|
145
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
146
|
+
rendition.next();
|
|
147
|
+
}
|
|
153
148
|
`);
|
|
154
149
|
}, []);
|
|
155
150
|
const goPrevious = useCallback(() => {
|
|
156
151
|
webViewInjectFunctions.injectJavaScript(book, `
|
|
157
|
-
rendition
|
|
152
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
153
|
+
rendition.prev();
|
|
154
|
+
}
|
|
158
155
|
`);
|
|
159
156
|
}, []);
|
|
160
157
|
const goToLocation = useCallback(targetCfi => {
|
|
161
|
-
book.current?.injectJavaScript(`
|
|
158
|
+
book.current?.injectJavaScript(`
|
|
159
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
160
|
+
rendition.display('${targetCfi}');
|
|
161
|
+
}
|
|
162
|
+
true;
|
|
163
|
+
`);
|
|
162
164
|
}, []);
|
|
163
165
|
const changeFontSize = useCallback(size => {
|
|
164
166
|
book.current?.injectJavaScript(`
|
|
165
|
-
rendition
|
|
166
|
-
|
|
167
|
+
if (typeof rendition !== 'undefined' && rendition) {
|
|
168
|
+
rendition.themes.fontSize('${size}');
|
|
169
|
+
rendition.views().forEach(view => view.pane ? view.pane.render() : null);
|
|
170
|
+
}
|
|
171
|
+
true;
|
|
167
172
|
`);
|
|
168
173
|
dispatch({
|
|
169
174
|
type: Actions.CHANGE_FONT_SIZE,
|
|
@@ -188,8 +193,6 @@ function ReaderProvider({
|
|
|
188
193
|
setLocations,
|
|
189
194
|
changeFontFamily,
|
|
190
195
|
injectJavascript,
|
|
191
|
-
changeFlow,
|
|
192
|
-
setFlow,
|
|
193
196
|
changeFontSize,
|
|
194
197
|
theme: state.theme,
|
|
195
198
|
flow: state.flow,
|
|
@@ -203,7 +206,7 @@ function ReaderProvider({
|
|
|
203
206
|
locations: state.locations,
|
|
204
207
|
isLoading: loading,
|
|
205
208
|
setIsLoading: setLoading
|
|
206
|
-
}), [registerBook, goNext, goPrevious, goToLocation, setAtStart, setAtEnd, setTotalLocations, setCurrentLocation, changeTheme, getLocations, getCurrentLocation, getMeta, setMeta, setProgress, setLocations, changeFontFamily, injectJavascript,
|
|
209
|
+
}), [registerBook, goNext, goPrevious, goToLocation, setAtStart, setAtEnd, setTotalLocations, setCurrentLocation, changeTheme, getLocations, getCurrentLocation, getMeta, setMeta, setProgress, setLocations, changeFontFamily, injectJavascript, changeFontSize, state.theme, state.flow, state.fontSize, state.atStart, state.atEnd, state.totalLocations, state.currentLocation, state.meta, state.progress, state.locations, loading, setLoading]);
|
|
207
210
|
return /*#__PURE__*/_jsx(ReaderContext.Provider, {
|
|
208
211
|
value: contextValue,
|
|
209
212
|
children: children
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useCallback","useMemo","useReducer","useRef","useState","defaultTheme","webViewInjectFunctions","useReaderState","Actions","jsx","_jsx","ReaderContext","registerBook","setAtStart","setAtEnd","setTotalLocations","setCurrentLocation","setMeta","setProgress","setLocations","goToLocation","goPrevious","goNext","getLocations","getCurrentLocation","getMeta","cover","author","title","description","language","publisher","rights","atStart","atEnd","totalLocations","currentLocation","meta","progress","locations","theme","injectJavascript","changeFontSize","changeTheme","fontSize","isLoading","setIsLoading","ReaderProvider","children","bookReducer","initialState","state","dispatch","loading","setLoading","book","bookRef","current","type","SET_AT_START","payload","SET_AT_END","SET_TOTAL_LOCATIONS","location","SET_CURRENT_LOCATION","SET_META","SET_PROGRESS","SET_LOCATIONS","changeFontFamily","fontFamily","injectJavaScript","CHANGE_FONT_FAMILY","script","
|
|
1
|
+
{"version":3,"names":["createContext","useCallback","useMemo","useReducer","useRef","useState","defaultTheme","webViewInjectFunctions","useReaderState","Actions","jsx","_jsx","ReaderContext","registerBook","setAtStart","setAtEnd","setTotalLocations","setCurrentLocation","setMeta","setProgress","setLocations","goToLocation","goPrevious","goNext","getLocations","getCurrentLocation","getMeta","cover","author","title","description","language","publisher","rights","atStart","atEnd","totalLocations","currentLocation","meta","progress","locations","theme","injectJavascript","changeFontSize","changeTheme","fontSize","isLoading","setIsLoading","ReaderProvider","children","bookReducer","initialState","state","dispatch","loading","setLoading","book","bookRef","current","type","SET_AT_START","payload","SET_AT_END","SET_TOTAL_LOCATIONS","location","SET_CURRENT_LOCATION","SET_META","SET_PROGRESS","SET_LOCATIONS","changeFontFamily","fontFamily","injectJavaScript","CHANGE_FONT_FAMILY","script","JSON","stringify","CHANGE_THEME","targetCfi","size","CHANGE_FONT_SIZE","contextValue","flow","Provider","value"],"sourceRoot":"../../../src","sources":["context/ReaderContext.tsx"],"mappings":";;AAAA,SACEA,aAAa,EACbC,WAAW,EACXC,OAAO,EACPC,UAAU,EACVC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SAASC,YAAY,QAAQ,uBAAoB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kB,EAClB2B,WAAW,EACXpB,YAAY,EACZC,kBAAkB,EAClBC,OAAO,EACPR,OAAO,EACPC,WAAW,EACXC,YAAY,EACZiD,gBAAgB,EAChB3B,gBAAgB,EAChBC,cAAc,EACdS,KAAK,CAACX,KAAK,EACXW,KAAK,CAAC6B,IAAI,EACV7B,KAAK,CAACP,QAAQ,EACdO,KAAK,CAAClB,OAAO,EACbkB,KAAK,CAACjB,KAAK,EACXiB,KAAK,CAAChB,cAAc,EACpBgB,KAAK,CAACf,eAAe,EACrBe,KAAK,CAACd,IAAI,EACVc,KAAK,CAACb,QAAQ,EACda,KAAK,CAACZ,SAAS,EACfc,OAAO,EACPC,UAAU,CAEd,CAAC;EAED,oBACE5C,IAAA,CAACC,aAAa,CAACsE,QAAQ;IAACC,KAAK,EAAEH,YAAa;IAAA/B,QAAA,EACzCA;EAAQ,CACa,CAAC;AAE7B;AAEA,SAASrC,aAAa,EAAEoC,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
|
|
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","
|
|
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,
|
|
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"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const _default: "\n<!doctype html>\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>EPUB.js</title>\n <script id=\"jszip\"></script>\n <script id=\"epubjs\"></script>\n\n <style type=\"text/css\">\n body {\n margin: 0;\n background-color: #211f26;\n }\n\n #viewer {\n height: 100vh;\n width: 100vw;\n overflow: hidden !important;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n\n [ref='epubjs-mk-balloon'] {\n background: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPScxLjEnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZycgeG1sbnM6eGxpbms9J2h0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsnIHg9JzBweCcgeT0nMHB4JyB2aWV3Qm94PScwIDAgNzUgNzUnPjxnIGZpbGw9JyNCREJEQkQnIGlkPSdidWJibGUnPjxwYXRoIGNsYXNzPSdzdDAnIGQ9J00zNy41LDkuNEMxOS42LDkuNCw1LDIwLjUsNSwzNC4zYzAsNS45LDIuNywxMS4zLDcuMSwxNS42TDkuNiw2NS42bDE5LTcuM2MyLjgsMC42LDUuOCwwLjksOC45LDAuOSBDNTUuNSw1OS4yLDcwLDQ4LjEsNzAsMzQuM0M3MCwyMC41LDU1LjQsOS40LDM3LjUsOS40eicvPjwvZz48L3N2Zz4=')\n no-repeat;\n width: 20px;\n height: 20px;\n cursor: pointer;\n margin-left: 0;\n }\n\n [ref='epubjs-mk-heart'] {\n 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=')\n no-repeat;\n width: 20px;\n height: 20px;\n cursor: pointer;\n margin-left: 0;\n }\n </style>\n </head>\n\n <body oncopy=\"return false;\" oncut=\"return false;\">\n <div id=\"viewer\"></div>\n\n <script>\n let book;\n let rendition;\n\n const type = window.type;\n const file = window.book;\n const theme = window.theme;\n const initialLocations = window.locations;\n const enableSelection = window.enable_selection;\n const allowScriptedContent = window.allowScriptedContent || false;\n const allowPopups = window.allowPopups || false;\n\n if (!file) {\n const reactNativeWebview =\n window.ReactNativeWebView !== undefined &&\n window.ReactNativeWebView !== null\n ? window.ReactNativeWebView\n : window;\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onDisplayError',\n reason: 'Book file is missing',\n })\n );\n }\n\n if (type === 'epub' || type === 'opf' || type === 'binary') {\n book = ePub(file);\n } else if (type === 'base64') {\n book = ePub(file, { encoding: 'base64' });\n } else {\n const reactNativeWebview =\n window.ReactNativeWebView !== undefined &&\n window.ReactNativeWebView !== null\n ? window.ReactNativeWebView\n : window;\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onDisplayError',\n reason: 'Missing or invalid file type',\n })\n );\n }\n\n rendition = book.renderTo('viewer', {\n width: '100%',\n height: '100%',\n manager: 'default',\n flow: 'auto',\n snap: undefined,\n spread: undefined,\n fullsize: undefined,\n allowPopups: allowPopups,\n allowScriptedContent: allowScriptedContent,\n });\n\n const reactNativeWebview =\n window.ReactNativeWebView !== undefined &&\n window.ReactNativeWebView !== null\n ? window.ReactNativeWebView\n : window;\n reactNativeWebview.postMessage(JSON.stringify({ type: 'onStarted' }));\n\n function flatten(chapters) {\n return [].concat.apply(\n [],\n chapters.map((chapter) =>\n [].concat.apply([chapter], flatten(chapter.subitems))\n )\n );\n }\n\n function getCfiFromHref(book, href) {\n const [_, id] = href.split('#');\n let section =\n book.spine.get(href.split('/')[1]) ||\n book.spine.get(href) ||\n book.spine.get(href.split('/').slice(1).join('/'));\n\n const el = id\n ? section.document.getElementById(id)\n : section.document.body;\n return section.cfiFromElement(el);\n }\n\n function getChapter(location) {\n const locationHref = location.start.href;\n\n let match = flatten(book.navigation.toc)\n .filter((chapter) => {\n return book.canonical(chapter.href).includes(locationHref);\n }, null)\n .reduce((result, chapter) => {\n const locationAfterChapter =\n ePub.CFI.prototype.compare(\n location.start.cfi,\n getCfiFromHref(book, chapter.href)\n ) > 0;\n return locationAfterChapter ? chapter : result;\n }, null);\n\n return match;\n }\n\n const makeRangeCfi = (a, b) => {\n const CFI = new ePub.CFI();\n const start = CFI.parse(a),\n end = CFI.parse(b);\n const cfi = {\n range: true,\n base: start.base,\n path: {\n steps: [],\n terminal: null,\n },\n start: start.path,\n end: end.path,\n };\n const len = cfi.start.steps.length;\n for (let i = 0; i < len; i++) {\n if (CFI.equalStep(cfi.start.steps[i], cfi.end.steps[i])) {\n if (i == len - 1) {\n // Last step is equal, check terminals\n if (cfi.start.terminal === cfi.end.terminal) {\n // CFI's are equal\n cfi.path.steps.push(cfi.start.steps[i]);\n // Not a range\n cfi.range = false;\n }\n } else cfi.path.steps.push(cfi.start.steps[i]);\n } else break;\n }\n cfi.start.steps = cfi.start.steps.slice(cfi.path.steps.length);\n cfi.end.steps = cfi.end.steps.slice(cfi.path.steps.length);\n\n return (\n 'epubcfi(' +\n CFI.segmentString(cfi.base) +\n '!' +\n CFI.segmentString(cfi.path) +\n ',' +\n CFI.segmentString(cfi.start) +\n ',' +\n CFI.segmentString(cfi.end) +\n ')'\n );\n };\n\n if (!enableSelection) {\n rendition.themes.default({\n body: {\n '-webkit-touch-callout': 'none' /* iOS Safari */,\n '-webkit-user-select': 'none' /* Safari */,\n '-khtml-user-select': 'none' /* Konqueror HTML */,\n '-moz-user-select': 'none' /* Firefox */,\n '-ms-user-select': 'none' /* Internet Explorer/Edge */,\n 'user-select': 'none',\n },\n });\n }\n\n book.ready\n .then(function () {\n if (initialLocations) {\n book.locations.load(initialLocations);\n }\n return rendition.display();\n })\n .then(function () {\n var currentLocation = rendition.currentLocation();\n\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onReady',\n totalLocations: book.locations.total,\n currentLocation: currentLocation,\n progress: currentLocation?.start?.cfi\n ? book.locations.percentageFromCfi(currentLocation.start.cfi)\n : 0,\n })\n );\n\n if (initialLocations) {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onLocationsReady',\n epubKey: book.key(),\n locations: initialLocations,\n totalLocations: book.locations.total,\n currentLocation: currentLocation,\n progress: currentLocation?.start?.cfi\n ? book.locations.percentageFromCfi(currentLocation.start.cfi)\n : 0,\n })\n );\n return Promise.resolve();\n }\n\n return book.locations\n .generate(1600)\n .then(function () {\n var generatedLocation =\n rendition.currentLocation() || currentLocation;\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onLocationsReady',\n epubKey: book.key(),\n locations: book.locations.save(),\n totalLocations: book.locations.total,\n currentLocation: generatedLocation,\n progress: generatedLocation?.start?.cfi\n ? book.locations.percentageFromCfi(\n generatedLocation.start.cfi\n )\n : 0,\n })\n );\n })\n .catch(function () {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onLocationsReady',\n epubKey: book.key(),\n locations: [],\n totalLocations: book.locations.total,\n currentLocation: currentLocation,\n progress: 0,\n })\n );\n });\n\n book\n .coverUrl()\n .then(async (url) => {\n var reader = new FileReader();\n reader.onload = (res) => {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'meta',\n metadata: {\n cover: reader.result,\n author: book.package.metadata.creator,\n title: book.package.metadata.title,\n description: book.package.metadata.description,\n language: book.package.metadata.language,\n publisher: book.package.metadata.publisher,\n rights: book.package.metadata.rights,\n },\n })\n );\n };\n reader.readAsDataURL(await fetch(url).then((res) => res.blob()));\n })\n .catch(() => {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'meta',\n metadata: {\n cover: undefined,\n author: book.package.metadata.creator,\n title: book.package.metadata.title,\n description: book.package.metadata.description,\n language: book.package.metadata.language,\n publisher: book.package.metadata.publisher,\n rights: book.package.metadata.rights,\n },\n })\n );\n });\n\n book.loaded.navigation.then(function (item) {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onNavigationLoaded',\n toc: item.toc,\n landmarks: item.landmarks,\n })\n );\n });\n })\n .catch(function (err) {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onDisplayError',\n reason: err.message || err.toString(),\n })\n );\n });\n\n let isAnimating = false;\n const originalNext = rendition.next.bind(rendition);\n const originalPrev = rendition.prev.bind(rendition);\n\n rendition.next = function () {\n if (isAnimating) return;\n isAnimating = true;\n\n const container = rendition.manager.container;\n container.style.transition = 'opacity 0.2s ease-out';\n container.style.opacity = '0.4';\n\n setTimeout(() => {\n originalNext();\n setTimeout(() => {\n container.style.opacity = '1';\n setTimeout(() => {\n container.style.transition = '';\n isAnimating = false;\n }, 200);\n }, 50);\n }, 100);\n };\n\n rendition.prev = function () {\n if (isAnimating) return;\n isAnimating = true;\n\n const container = rendition.manager.container;\n container.style.transition = 'opacity 0.2s ease-out';\n container.style.opacity = '0.4';\n\n setTimeout(() => {\n originalPrev();\n setTimeout(() => {\n container.style.opacity = '1';\n setTimeout(() => {\n container.style.transition = '';\n isAnimating = false;\n }, 200);\n }, 50);\n }, 100);\n };\n\n rendition.on('started', () => {\n rendition.themes.register({ theme: theme });\n rendition.themes.select('theme');\n });\n\n rendition.on('relocated', function (location) {\n var percent = book.locations.percentageFromCfi(location.start.cfi);\n var percentage = Math.floor(percent * 100);\n var chapter = getChapter(location);\n\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onLocationChange',\n totalLocations: book.locations.total,\n currentLocation: location,\n progress: percentage,\n currentSection: chapter,\n })\n );\n\n if (location.atStart) {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onBeginning',\n })\n );\n }\n\n if (location.atEnd) {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onFinish',\n })\n );\n }\n });\n\n rendition.on('rendered', function (section) {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onRendered',\n section: section,\n currentSection: book.navigation.get(section.href),\n })\n );\n });\n\n rendition.on('layout', function (layout) {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: 'onLayout',\n layout: layout,\n })\n );\n });\n </script>\n </body>\n</html>\n";
|
|
1
|
+
declare const _default: "\n<!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>EPUB.js</title>\n <script id=\"jszip\"></script>\n <script id=\"epubjs\"></script>\n\n <style type=\"text/css\">\n body {\n margin: 0;\n background-color: #211F26;\n }\n\n #viewer {\n height: 100vh;\n width: 100vw;\n overflow: hidden !important;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n\n [ref=\"epubjs-mk-balloon\"] {\n background: url(\"data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPScxLjEnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZycgeG1sbnM6eGxpbms9J2h0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsnIHg9JzBweCcgeT0nMHB4JyB2aWV3Qm94PScwIDAgNzUgNzUnPjxnIGZpbGw9JyNCREJEQkQnIGlkPSdidWJibGUnPjxwYXRoIGNsYXNzPSdzdDAnIGQ9J00zNy41LDkuNEMxOS42LDkuNCw1LDIwLjUsNSwzNC4zYzAsNS45LDIuNywxMS4zLDcuMSwxNS42TDkuNiw2NS42bDE5LTcuM2MyLjgsMC42LDUuOCwwLjksOC45LDAuOSBDNTUuNSw1OS4yLDcwLDQ4LjEsNzAsMzQuM0M3MCwyMC41LDU1LjQsOS40LDM3LjUsOS40eicvPjwvZz48L3N2Zz4=\") no-repeat;\n width: 20px;\n height: 20px;\n cursor: pointer;\n margin-left: 0;\n }\n\n [ref=\"epubjs-mk-heart\"] {\n 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;\n width: 20px;\n height: 20px;\n cursor: pointer;\n margin-left: 0;\n }\n </style>\n </head>\n\n <body oncopy='return false' oncut='return false'>\n <div id=\"viewer\"></div>\n\n <script>\n let book;\n let rendition;\n\n const type = window.type;\n const file = window.book;\n const theme = window.theme;\n const initialLocations = window.locations;\n const enableSelection = window.enable_selection;\n const allowScriptedContent = window.allowScriptedContent || false;\n const allowPopups = window.allowPopups || false;\n\n if (!file) {\n const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView !== null ? window.ReactNativeWebView : window;\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onDisplayError\",\n reason: \"Book file is missing\"\n }));\n }\n\n if (type === 'epub' || type === 'opf' || type === 'binary') {\n book = ePub(file);\n } else if (type === 'base64') {\n book = ePub(file, { encoding: \"base64\" });\n } else {\n const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView !== null ? window.ReactNativeWebView : window;\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onDisplayError\",\n reason: \"Missing or invalid file type\"\n }));\n }\n\n rendition = book.renderTo(\"viewer\", {\n width: \"100%\",\n height: \"100%\",\n manager: \"default\",\n flow: \"auto\",\n snap: undefined,\n spread: undefined,\n fullsize: undefined,\n allowPopups: allowPopups,\n allowScriptedContent: allowScriptedContent\n });\n \n const reactNativeWebview = window.ReactNativeWebView !== undefined && window.ReactNativeWebView!== null ? window.ReactNativeWebView: window;\n reactNativeWebview.postMessage(JSON.stringify({ type: \"onStarted\" }));\n\n function flatten(chapters) {\n return [].concat.apply([], chapters.map((chapter) => [].concat.apply([chapter], flatten(chapter.subitems))));\n }\n\n function getCfiFromHref(book, href) {\n const [_, id] = href.split('#')\n let section = book.spine.get(href.split('/')[1]) || book.spine.get(href) || book.spine.get(href.split('/').slice(1).join('/'))\n\n const el = (id ? section.document.getElementById(id) : section.document.body)\n return section.cfiFromElement(el)\n }\n\n function getChapter(location) {\n const locationHref = location.start.href\n\n let match = flatten(book.navigation.toc)\n .filter((chapter) => {\n return book.canonical(chapter.href).includes(locationHref)\n }, null)\n .reduce((result, chapter) => {\n const locationAfterChapter = ePub.CFI.prototype.compare(location.start.cfi, getCfiFromHref(book, chapter.href)) > 0\n return locationAfterChapter ? chapter : result\n }, null);\n\n return match;\n };\n\n const makeRangeCfi = (a, b) => {\n const CFI = new ePub.CFI()\n const start = CFI.parse(a), end = CFI.parse(b)\n const cfi = {\n range: true,\n base: start.base,\n path: {\n steps: [],\n terminal: null\n },\n start: start.path,\n end: end.path\n }\n const len = cfi.start.steps.length\n for (let i = 0; i < len; i++) {\n if (CFI.equalStep(cfi.start.steps[i], cfi.end.steps[i])) {\n if (i == len - 1) {\n // Last step is equal, check terminals\n if (cfi.start.terminal === cfi.end.terminal) {\n // CFI's are equal\n cfi.path.steps.push(cfi.start.steps[i])\n // Not a range\n cfi.range = false\n }\n } else cfi.path.steps.push(cfi.start.steps[i])\n } else break\n }\n cfi.start.steps = cfi.start.steps.slice(cfi.path.steps.length)\n cfi.end.steps = cfi.end.steps.slice(cfi.path.steps.length)\n\n return 'epubcfi(' + CFI.segmentString(cfi.base)\n + '!' + CFI.segmentString(cfi.path)\n + ',' + CFI.segmentString(cfi.start)\n + ',' + CFI.segmentString(cfi.end)\n + ')'\n }\n\n if (!enableSelection) {\n rendition.themes.default({\n 'body': {\n '-webkit-touch-callout': 'none', /* iOS Safari */\n '-webkit-user-select': 'none', /* Safari */\n '-khtml-user-select': 'none', /* Konqueror HTML */\n '-moz-user-select': 'none', /* Firefox */\n '-ms-user-select': 'none', /* Internet Explorer/Edge */\n 'user-select': 'none'\n }\n });\n }\n\n book.ready\n .then(function () {\n if (initialLocations) {\n book.locations.load(initialLocations);\n }\n return rendition.display();\n })\n .then(function () {\n var currentLocation = rendition.currentLocation();\n\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onReady\",\n totalLocations: book.locations.total,\n currentLocation: currentLocation,\n progress: currentLocation?.start?.cfi\n ? book.locations.percentageFromCfi(currentLocation.start.cfi)\n : 0,\n }));\n\n if (initialLocations) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onLocationsReady\",\n epubKey: book.key(),\n locations: initialLocations,\n totalLocations: book.locations.total,\n currentLocation: currentLocation,\n progress: currentLocation?.start?.cfi\n ? book.locations.percentageFromCfi(currentLocation.start.cfi)\n : 0,\n }));\n return Promise.resolve();\n }\n\n return book.locations.generate(1600).then(function () {\n var generatedLocation = rendition.currentLocation() || currentLocation;\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onLocationsReady\",\n epubKey: book.key(),\n locations: book.locations.save(),\n totalLocations: book.locations.total,\n currentLocation: generatedLocation,\n progress: generatedLocation?.start?.cfi\n ? book.locations.percentageFromCfi(generatedLocation.start.cfi)\n : 0,\n }));\n }).catch(function () {\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onLocationsReady\",\n epubKey: book.key(),\n locations: [],\n totalLocations: book.locations.total,\n currentLocation: currentLocation,\n progress: 0,\n }));\n });\n\n book\n .coverUrl()\n .then(async (url) => {\n var reader = new FileReader();\n reader.onload = (res) => {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: \"meta\",\n metadata: {\n cover: reader.result,\n author: book.package.metadata.creator,\n title: book.package.metadata.title,\n description: book.package.metadata.description,\n language: book.package.metadata.language,\n publisher: book.package.metadata.publisher,\n rights: book.package.metadata.rights,\n },\n })\n );\n };\n reader.readAsDataURL(await fetch(url).then((res) => res.blob()));\n })\n .catch(() => {\n reactNativeWebview.postMessage(\n JSON.stringify({\n type: \"meta\",\n metadata: {\n cover: undefined,\n author: book.package.metadata.creator,\n title: book.package.metadata.title,\n description: book.package.metadata.description,\n language: book.package.metadata.language,\n publisher: book.package.metadata.publisher,\n rights: book.package.metadata.rights,\n },\n })\n );\n });\n\n book.loaded.navigation.then(function (item) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: 'onNavigationLoaded',\n toc: item.toc,\n landmarks: item.landmarks\n }));\n });\n })\n .catch(function (err) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onDisplayError\",\n reason: err.message || err.toString()\n }));\n });\n\n let isAnimating = false;\n const originalNext = rendition.next.bind(rendition);\n const originalPrev = rendition.prev.bind(rendition);\n\n rendition.next = function() {\n if (isAnimating) return;\n isAnimating = true;\n \n const container = rendition.manager.container;\n container.style.transition = 'opacity 0.2s ease-out';\n container.style.opacity = '0.4';\n \n setTimeout(() => {\n originalNext();\n setTimeout(() => {\n container.style.opacity = '1';\n setTimeout(() => {\n container.style.transition = '';\n isAnimating = false;\n }, 200);\n }, 50);\n }, 100);\n };\n\n rendition.prev = function() {\n if (isAnimating) return;\n isAnimating = true;\n \n const container = rendition.manager.container;\n container.style.transition = 'opacity 0.2s ease-out';\n container.style.opacity = '0.4';\n \n setTimeout(() => {\n originalPrev();\n setTimeout(() => {\n container.style.opacity = '1';\n setTimeout(() => {\n container.style.transition = '';\n isAnimating = false;\n }, 200);\n }, 50);\n }, 100);\n };\n\n rendition.on('started', () => {\n rendition.themes.register({ theme: theme });\n rendition.themes.select('theme');\n });\n\n rendition.on(\"relocated\", function (location) {\n var percent = book.locations.percentageFromCfi(location.start.cfi);\n var percentage = Math.floor(percent * 100);\n var chapter = getChapter(location);\n\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onLocationChange\",\n totalLocations: book.locations.total,\n currentLocation: location,\n progress: percentage,\n currentSection: chapter,\n }));\n\n if (location.atStart) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onBeginning\",\n }));\n }\n\n if (location.atEnd) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: \"onFinish\",\n }));\n }\n });\n\n rendition.on(\"orientationchange\", function (orientation) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: 'onOrientationChange',\n orientation: orientation\n }));\n });\n\n rendition.on(\"rendered\", function (section) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: 'onRendered',\n section: section,\n currentSection: book.navigation.get(section.href),\n }));\n });\n\n rendition.on(\"layout\", function (layout) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: 'onLayout',\n layout: layout,\n }));\n });\n\n rendition.on(\"selected\", function (cfiRange, contents) {\n book.getRange(cfiRange).then(function (range) {\n if (range) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: 'onSelected',\n cfiRange: cfiRange,\n text: range.toString(),\n }));\n }\n });\n });\n\n rendition.on(\"resized\", function (layout) {\n reactNativeWebview.postMessage(JSON.stringify({\n type: 'onResized',\n layout: layout,\n }));\n });\n </script>\n </body>\n</html>\n";
|
|
2
2
|
export default _default;
|
|
3
3
|
//# sourceMappingURL=template.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../../src/constants/template.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../../src/constants/template.ts"],"names":[],"mappings":";AAAA,wBA8YE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReaderContext.d.ts","sourceRoot":"","sources":["../../../../src/context/ReaderContext.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAQlD,QAAA,MAAM,aAAa,6CAiDjB,CAAC;AAEH,iBAAS,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"ReaderContext.d.ts","sourceRoot":"","sources":["../../../../src/context/ReaderContext.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAQlD,QAAA,MAAM,aAAa,6CAiDjB,CAAC;AAEH,iBAAS,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,2CAqMlE;AAED,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadEpub.d.ts","sourceRoot":"","sources":["../../../../src/helpers/downloadEpub.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,GACvB,KAAK,MAAM,EACX,UAAU,MAAM,KACf,OAAO,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"downloadEpub.d.ts","sourceRoot":"","sources":["../../../../src/helpers/downloadEpub.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,GACvB,KAAK,MAAM,EACX,UAAU,MAAM,KACf,OAAO,CAAC,MAAM,CAuBhB,CAAC"}
|
package/package.json
CHANGED
|
@@ -38,6 +38,7 @@ const Reader = ({
|
|
|
38
38
|
onWebViewMessage,
|
|
39
39
|
}: ReaderProps) => {
|
|
40
40
|
const [templateUri, setTemplateUri] = useState<string>('');
|
|
41
|
+
// const [isReaderReady, setIsReaderReady] = useState(false);
|
|
41
42
|
|
|
42
43
|
const {
|
|
43
44
|
registerBook,
|
|
@@ -61,7 +62,14 @@ const Reader = ({
|
|
|
61
62
|
const bookRef = useRef<WebView | null>(null);
|
|
62
63
|
|
|
63
64
|
const onMessage = (event: any) => {
|
|
64
|
-
|
|
65
|
+
let parsedEvent;
|
|
66
|
+
try {
|
|
67
|
+
parsedEvent = JSON.parse(event.nativeEvent.data);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.warn('Failed to parse WebView message:', error);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
console.log(parsedEvent.type);
|
|
66
74
|
|
|
67
75
|
if (!INTERNAL_EVENTS.includes(parsedEvent?.type) && onWebViewMessage) {
|
|
@@ -100,10 +108,16 @@ const Reader = ({
|
|
|
100
108
|
|
|
101
109
|
return onLocationsReady(props.epubKey, parsedEvent.locations);
|
|
102
110
|
case 'onReady':
|
|
111
|
+
// setIsReaderReady(true);
|
|
112
|
+
setIsLoading(false);
|
|
103
113
|
if (initialLocation) {
|
|
104
114
|
goToLocation(initialLocation);
|
|
105
115
|
}
|
|
106
116
|
break;
|
|
117
|
+
case 'onDisplayError':
|
|
118
|
+
setIsLoading(false);
|
|
119
|
+
console.error('Reader display error:', parsedEvent.reason);
|
|
120
|
+
break;
|
|
107
121
|
|
|
108
122
|
case 'onBeginning':
|
|
109
123
|
setAtStart(true);
|
|
@@ -125,11 +139,13 @@ const Reader = ({
|
|
|
125
139
|
};
|
|
126
140
|
|
|
127
141
|
const handleOnSwipeLeft = () => {
|
|
142
|
+
// if (!isReaderReady) return;
|
|
128
143
|
onSwipeLeft?.();
|
|
129
144
|
goNext();
|
|
130
145
|
};
|
|
131
146
|
|
|
132
147
|
const handleOnSwipeRight = () => {
|
|
148
|
+
// if (!isReaderReady) return;
|
|
133
149
|
onSwipeRight?.();
|
|
134
150
|
goPrevious();
|
|
135
151
|
};
|
|
@@ -137,6 +153,8 @@ const Reader = ({
|
|
|
137
153
|
const handleOnPinch = (
|
|
138
154
|
e: GestureUpdateEvent<PinchGestureHandlerEventPayload>
|
|
139
155
|
) => {
|
|
156
|
+
// if (!isReaderReady) return;
|
|
157
|
+
|
|
140
158
|
const fontSizeValue = parseInt(fontSize.replace('pt', ''), 10);
|
|
141
159
|
|
|
142
160
|
const scaleValue = e.scale > 1 ? e.scale * 0.5 : e.scale;
|
|
@@ -148,14 +166,23 @@ const Reader = ({
|
|
|
148
166
|
onPinch?.(e);
|
|
149
167
|
};
|
|
150
168
|
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
[
|
|
154
|
-
|
|
169
|
+
const epubFileName = useMemo(() => {
|
|
170
|
+
const splited = src.split('/').pop() || 'book.epub';
|
|
171
|
+
const cleanName = splited.split('?')[0] || 'book.epub';
|
|
172
|
+
const decoded = decodeURIComponent(cleanName)
|
|
173
|
+
.replace(' ', '_')
|
|
174
|
+
.replace(',', '_')
|
|
175
|
+
.replace(/[^a-zA-Z0-9._-]/g, '');
|
|
176
|
+
|
|
177
|
+
return decoded;
|
|
178
|
+
}, [src]);
|
|
155
179
|
|
|
156
|
-
const
|
|
157
|
-
() =>
|
|
158
|
-
|
|
180
|
+
const htmlTemplateName = useMemo(
|
|
181
|
+
() =>
|
|
182
|
+
epubFileName
|
|
183
|
+
.replace('.epub', '-template.html')
|
|
184
|
+
.replace('.zip', '-template.html'),
|
|
185
|
+
[epubFileName]
|
|
159
186
|
);
|
|
160
187
|
|
|
161
188
|
const handleBookRef = useCallback(
|
|
@@ -174,6 +201,8 @@ const Reader = ({
|
|
|
174
201
|
const prepareReader = async () => {
|
|
175
202
|
try {
|
|
176
203
|
setIsLoading(true);
|
|
204
|
+
// setIsReaderReady(false);
|
|
205
|
+
setTemplateUri('');
|
|
177
206
|
|
|
178
207
|
const [, jszip, epubjs] = await loadScripts();
|
|
179
208
|
|
|
@@ -197,8 +226,9 @@ const Reader = ({
|
|
|
197
226
|
}
|
|
198
227
|
} catch (error) {
|
|
199
228
|
console.error('Reader Error:', error);
|
|
200
|
-
|
|
201
|
-
|
|
229
|
+
if (isMounted) {
|
|
230
|
+
setIsLoading(false);
|
|
231
|
+
}
|
|
202
232
|
}
|
|
203
233
|
};
|
|
204
234
|
|
|
@@ -214,7 +244,7 @@ const Reader = ({
|
|
|
214
244
|
setIsLoading,
|
|
215
245
|
]);
|
|
216
246
|
|
|
217
|
-
if (
|
|
247
|
+
if (!templateUri) {
|
|
218
248
|
return LoaderComponent ? (
|
|
219
249
|
<LoaderComponent />
|
|
220
250
|
) : (
|
|
@@ -226,7 +256,7 @@ const Reader = ({
|
|
|
226
256
|
}
|
|
227
257
|
|
|
228
258
|
return (
|
|
229
|
-
|
|
259
|
+
<View style={styles.container}>
|
|
230
260
|
<GestureHandler
|
|
231
261
|
onSwipeLeft={handleOnSwipeLeft}
|
|
232
262
|
onSwipeRight={handleOnSwipeRight}
|
|
@@ -251,7 +281,19 @@ const Reader = ({
|
|
|
251
281
|
style={styles.container}
|
|
252
282
|
/>
|
|
253
283
|
</GestureHandler>
|
|
254
|
-
|
|
284
|
+
|
|
285
|
+
{isLoading &&
|
|
286
|
+
(LoaderComponent ? (
|
|
287
|
+
<View style={styles.loaderOverlay}>
|
|
288
|
+
<LoaderComponent />
|
|
289
|
+
</View>
|
|
290
|
+
) : (
|
|
291
|
+
<View style={styles.loaderOverlay}>
|
|
292
|
+
<ActivityIndicator size="large" />
|
|
293
|
+
<Text>Przygotowuję książkę...</Text>
|
|
294
|
+
</View>
|
|
295
|
+
))}
|
|
296
|
+
</View>
|
|
255
297
|
);
|
|
256
298
|
};
|
|
257
299
|
|
|
@@ -264,6 +306,11 @@ const styles = StyleSheet.create({
|
|
|
264
306
|
justifyContent: 'center',
|
|
265
307
|
alignItems: 'center',
|
|
266
308
|
},
|
|
309
|
+
loaderOverlay: {
|
|
310
|
+
...StyleSheet.absoluteFillObject,
|
|
311
|
+
justifyContent: 'center',
|
|
312
|
+
alignItems: 'center',
|
|
313
|
+
},
|
|
267
314
|
});
|
|
268
315
|
|
|
269
316
|
export default Reader;
|