mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 23:16:17 -05:00
Adding epub.js to allow reading of ebooks in browser.
This commit is contained in:
parent
6dd1119eb0
commit
4286d2414a
5 changed files with 23319 additions and 9 deletions
|
|
@ -11,6 +11,7 @@
|
|||
"react-dropzone": "^11.4.2",
|
||||
"react-keyed-file-browser": "^1.14.0",
|
||||
"react-qr-code": "^2.0.7",
|
||||
"react-reader": "^0.19.0",
|
||||
"react-router-dom": "^6.3.0",
|
||||
"react-scripts": "^3.4.1",
|
||||
"react-semantic-toasts": "^0.6.5",
|
||||
|
|
|
|||
307
app/public/epub.html
Normal file
307
app/public/epub.html
Normal file
|
|
@ -0,0 +1,307 @@
|
|||
<!DOCTYPE html>
|
||||
<!--Copyright (c) 2013, FuturePress
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project. -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
|
||||
<script src="/jszip.min.js"></script>
|
||||
<script src="/epub.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
background: #fafafa;
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
color: #333;
|
||||
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#title {
|
||||
width: 900px;
|
||||
min-height: 18px;
|
||||
margin: 10px auto;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
color: #E2E2E2;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
#title:hover {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
#viewer {
|
||||
width: 80%;
|
||||
height: 90%;
|
||||
box-shadow: 0 0 4px #ccc;
|
||||
padding: 10px 10px 0px 10px;
|
||||
margin: 5px auto;
|
||||
background: white;
|
||||
}
|
||||
|
||||
#prev {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
#next {
|
||||
right: 0;
|
||||
}
|
||||
|
||||
#toc {
|
||||
display: block;
|
||||
margin: 10px auto;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
margin-top: -32px;
|
||||
font-size: 64px;
|
||||
color: #E2E2E2;
|
||||
font-family: arial, sans-serif;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.arrow:hover {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.arrow:active {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#book-viewer iframe {
|
||||
padding: 40px 40px;
|
||||
}
|
||||
|
||||
#controls > input[type=range] {
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
#navigation h1 {
|
||||
width: 200px;
|
||||
font-size: 16px;
|
||||
font-weight: normal;
|
||||
color: #fff;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#navigation h2 {
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
color: #B0B0B0;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#navigation ul {
|
||||
padding-left: 36px;
|
||||
margin-left: 0;
|
||||
margin-top: 12px;
|
||||
margin-bottom: 12px;
|
||||
width: 340px;
|
||||
}
|
||||
|
||||
#navigation ul li {
|
||||
list-style: decimal;
|
||||
margin-bottom: 10px;
|
||||
color: #cccddd;
|
||||
font-size: 12px;
|
||||
padding-left: 0;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
#navigation ul li a {
|
||||
color: #ccc;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#navigation ul li a:hover {
|
||||
color: #fff;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#navigation ul li {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
svg {
|
||||
display: block;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<select id="toc"></select>
|
||||
<div id="viewer"></div>
|
||||
<a id="prev" href="#prev" class="arrow">‹</a>
|
||||
<a id="next" href="#next" class="arrow">›</a>
|
||||
|
||||
<script>
|
||||
let params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
|
||||
let url = params && params.get("url") && decodeURIComponent(params.get("url"));
|
||||
let currentSectionIndex = (params && params.get("loc")) ? params.get("loc") : undefined;
|
||||
|
||||
let book = ePub(url);
|
||||
let rendition = book.renderTo("viewer", {
|
||||
flow: "paginated",
|
||||
width: "100%",
|
||||
height: "100%"
|
||||
});
|
||||
|
||||
rendition.display(currentSectionIndex);
|
||||
|
||||
book.ready.then(() => {
|
||||
|
||||
let next = document.getElementById("next");
|
||||
|
||||
next.addEventListener("click", function (e) {
|
||||
book.package.metadata.direction === "rtl" ? rendition.prev() : rendition.next();
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
|
||||
let prev = document.getElementById("prev");
|
||||
prev.addEventListener("click", function (e) {
|
||||
book.package.metadata.direction === "rtl" ? rendition.next() : rendition.prev();
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
|
||||
let keyListener = function (e) {
|
||||
|
||||
// Left Key
|
||||
if ((e.keyCode || e.which) === 37) {
|
||||
book.package.metadata.direction === "rtl" ? rendition.next() : rendition.prev();
|
||||
}
|
||||
|
||||
// Right Key
|
||||
if ((e.keyCode || e.which) === 39) {
|
||||
book.package.metadata.direction === "rtl" ? rendition.prev() : rendition.next();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
rendition.on("keyup", keyListener);
|
||||
document.addEventListener("keyup", keyListener, false);
|
||||
|
||||
})
|
||||
|
||||
let title = document.getElementById("title");
|
||||
|
||||
rendition.on("rendered", function (section) {
|
||||
let current = book.navigation && book.navigation.get(section.href);
|
||||
|
||||
if (current) {
|
||||
let $select = document.getElementById("toc");
|
||||
let $selected = $select.querySelector("option[selected]");
|
||||
if ($selected) {
|
||||
$selected.removeAttribute("selected");
|
||||
}
|
||||
|
||||
let $options = $select.querySelectorAll("option");
|
||||
for (let i = 0; i < $options.length; ++i) {
|
||||
let selected = $options[i].getAttribute("ref") === current.href;
|
||||
if (selected) {
|
||||
$options[i].setAttribute("selected", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
rendition.on("relocated", function (location) {
|
||||
console.log(location);
|
||||
|
||||
let next = book.package.metadata.direction === "rtl" ? document.getElementById("prev") : document.getElementById("next");
|
||||
let prev = book.package.metadata.direction === "rtl" ? document.getElementById("next") : document.getElementById("prev");
|
||||
|
||||
if (location.atEnd) {
|
||||
next.style.visibility = "hidden";
|
||||
} else {
|
||||
next.style.visibility = "visible";
|
||||
}
|
||||
|
||||
if (location.atStart) {
|
||||
prev.style.visibility = "hidden";
|
||||
} else {
|
||||
prev.style.visibility = "visible";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
rendition.on("layout", function (layout) {
|
||||
let viewer = document.getElementById("viewer");
|
||||
|
||||
if (layout.spread) {
|
||||
viewer.classList.remove('single');
|
||||
} else {
|
||||
viewer.classList.add('single');
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("unload", function () {
|
||||
console.log("unloading");
|
||||
this.book.destroy();
|
||||
});
|
||||
|
||||
book.loaded.navigation.then(function (toc) {
|
||||
let $select = document.getElementById("toc"),
|
||||
docfrag = document.createDocumentFragment();
|
||||
|
||||
toc.forEach(function (chapter) {
|
||||
let option = document.createElement("option");
|
||||
option.textContent = chapter.label;
|
||||
option.setAttribute("ref", chapter.href);
|
||||
|
||||
docfrag.appendChild(option);
|
||||
});
|
||||
|
||||
$select.appendChild(docfrag);
|
||||
|
||||
$select.onchange = function () {
|
||||
let index = $select.selectedIndex,
|
||||
url = $select.options[index].getAttribute("ref");
|
||||
rendition.display(url);
|
||||
return false;
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
22989
app/public/epub.js
Normal file
22989
app/public/epub.js
Normal file
File diff suppressed because it is too large
Load diff
15
app/public/jszip.min.js
vendored
Normal file
15
app/public/jszip.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -147,12 +147,15 @@ export function Files() {
|
|||
|
||||
function EbookCard({file}) {
|
||||
const {s} = useContext(ThemeContext);
|
||||
const downloadUrl = `/download/${encodeURIComponent(file.path)}`;
|
||||
let {ebook, suffix} = file;
|
||||
const coverSrc = ebook && ebook.cover_path ? `/media/${encodeURIComponent(ebook.cover_path)}` : null;
|
||||
|
||||
const downloadUrl = `/download/${encodeURIComponent(file.path)}`;
|
||||
const viewerUrl = `/epub.html?url=${downloadUrl}`;
|
||||
const isEpub = file['mimetype'].startsWith('application/epub');
|
||||
|
||||
let cover = <CardIcon><FileIcon file={file}/></CardIcon>;
|
||||
if (coverSrc) {
|
||||
if (ebook && ebook.cover_path) {
|
||||
const coverSrc = `/media/${encodeURIComponent(ebook.cover_path)}`;
|
||||
cover = <CardPosterLink to={downloadUrl} poster_url={coverSrc} external={true}/>;
|
||||
}
|
||||
|
||||
|
|
@ -167,14 +170,9 @@ function EbookCard({file}) {
|
|||
<ExternalCardLink to={downloadUrl}>{ebook ? ebook.title : file.title}</ExternalCardLink>
|
||||
</Container>
|
||||
</CardHeader>
|
||||
<CardDescription>
|
||||
<Container textAlign='left'>
|
||||
<b {...s}>{ebook ? ebook.creator : null}</b>
|
||||
</Container>
|
||||
</CardDescription>
|
||||
<CardMeta>
|
||||
<p {...s}>{ebook ? humanFileSize(ebook.size) : null}</p>
|
||||
<pre {...s}>{suffix}</pre>
|
||||
{isEpub && <ExternalCardLink to={viewerUrl}><Button content='View'/></ExternalCardLink>}
|
||||
</CardMeta>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue