react-book-reader 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,23 +1,45 @@
1
- # an easy way to embed a reader into your webapp
1
+ <div align="center">
2
+ <img width=250 src="https://raw.githubusercontent.com/jinhuan138/react-book-reader/master/docs/public/logo.png" />
3
+ <h1>ReactBookReader</h1>
4
+ </div>
5
+
6
+ <p>
7
+ <a href="https://www.npmjs.com/package/react-book-reader" target="_blank">
8
+ <img src="https://img.shields.io/npm/v/react-book-reader?style=flat-square" />
9
+ </a>
10
+ <a href="https://www.npmjs.com/package/react-book-reader" target="_blank" >
11
+ <img src="https://img.shields.io/npm/dw/react-book-reader?style=flat-square" />
12
+ </a>
13
+ <a href="./LICENSE">
14
+ <img src="https://img.shields.io/npm/l/react-book-reader?style=flat-square" />
15
+ </a>
16
+ </p>
17
+
18
+ <div align="center">
19
+ <h2><a href="https://jinhuan138.github.io/react-book-reader/">📖Documentation</a></h2>
20
+ </div>
21
+
22
+ # Introduction
23
+
24
+ react-book-reader is a react wrapper for [foliate-js](https://github.com/johnfactotum/foliate-js) - library for rendering e-books in the browser.
25
+ Supports EPUB, MOBI, KF8 (AZW3), FB2, CBZ, PDF (experimental; requires PDF.js), or add support for other formats yourself by implementing the book interface
26
+
27
+ ## Basic usage
2
28
 
3
29
  ```bash
4
30
  npm install react-book-reader --save
5
31
  ```
6
32
 
7
- And in your vue-component...
33
+ And in your react-component...
8
34
 
9
- ```react
35
+ ```jsx
10
36
  import { ReactReader } from 'react-book-reader'
11
37
 
12
- const App = () => {
13
- return (
14
- <div style={{ height: '100vh' }}>
15
- {/* Supports EPUB, MOBI, KF8 (AZW3), FB2, CBZ, PDF */}
16
- <ReactReader url="/files/啼笑因缘.azw3" />
17
- </div>
18
- )
19
- }
20
-
21
- export default App
38
+ export default () => (
39
+ <div style={{ height: '100vh' }}>
40
+ {/* Supports EPUB, MOBI, KF8 (AZW3), FB2, CBZ, PDF */}
41
+ <ReactReader url="files/啼笑因缘.epub" />
42
+ </div>
43
+ );
22
44
  ```
23
45
 
@@ -0,0 +1,25 @@
1
+ const h = ({ entries: i, loadBlob: a, getSize: l }, d) => {
2
+ const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), f = async (e) => {
3
+ if (r.has(e)) return r.get(e);
4
+ const o = URL.createObjectURL(await a(e)), n = URL.createObjectURL(
5
+ new Blob([`<!DOCTYPE html><html><head><meta charset="utf-8"></head><body style="margin: 0"><img src="${o}"></body></html>`], { type: "text/html" })
6
+ );
7
+ return s.set(e, [o, n]), r.set(e, n), n;
8
+ }, p = (e) => {
9
+ s.get(e)?.forEach?.((o) => URL.revokeObjectURL(o)), s.delete(e), r.delete(e);
10
+ }, g = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp", ".svg", ".jxl", ".avif"], c = i.map((e) => e.filename).filter((e) => g.some((o) => e.endsWith(o))).sort();
11
+ if (!c.length) throw new Error("No supported image files in archive");
12
+ const t = {};
13
+ return t.getCover = () => a(c[0]), t.metadata = { title: d.name }, t.sections = c.map((e) => ({
14
+ id: e,
15
+ load: () => f(e),
16
+ unload: () => p(e),
17
+ size: l(e)
18
+ })), t.toc = c.map((e) => ({ label: e, href: e })), t.rendition = { layout: "pre-paginated" }, t.resolveHref = (e) => ({ index: t.sections.findIndex((o) => o.id === e) }), t.splitTOCHref = (e) => [e, null], t.getTOCFragment = (e) => e.documentElement, t.destroy = () => {
19
+ for (const e of s.values())
20
+ for (const o of e) URL.revokeObjectURL(o);
21
+ }, t;
22
+ };
23
+ export {
24
+ h as makeComicBook
25
+ };