@treinetic/treinetic-epub-reader 1.3.2 → 2.0.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 +126 -155
- package/dist/ExternalControls.d.ts +40 -0
- package/dist/Keyboard.d.ts +14 -0
- package/dist/ModuleConfig.d.ts +14 -0
- package/dist/Settings.d.ts +6 -0
- package/dist/TOCJsonCreator.d.ts +11 -0
- package/dist/ThemeManager.d.ts +20 -0
- package/dist/TreineticEpubReader.d.ts +38 -0
- package/dist/TreineticHelpers.d.ts +19 -0
- package/dist/model/Metadata.d.ts +13 -0
- package/dist/model/Package.d.ts +21 -0
- package/dist/model/Spine.d.ts +19 -0
- package/dist/model/SpineItem.d.ts +34 -0
- package/dist/parser/EpubParser.d.ts +6 -0
- package/dist/style.css +1 -0
- package/dist/treinetic-epub-reader.es.js +3286 -0
- package/dist/treinetic-epub-reader.umd.js +38 -0
- package/dist/view/ReaderView.d.ts +42 -0
- package/license.txt +25 -0
- package/package.json +56 -153
- package/dist/TreineticEpubReader.css +0 -1324
- package/dist/TreineticEpubReader.js +0 -58314
- package/dist/TreineticEpubReader.min.css +0 -1
- package/dist/TreineticEpubReader.min.js +0 -2
- package/dist/TreineticEpubReader.min.js.map +0 -1
- package/dist/sample/assets/epub/epub_1.epub +0 -0
- package/dist/sample/assets/epub/epub_2/META-INF/container.xml +0 -6
- package/dist/sample/assets/epub/epub_2/OEBPS/0.css +0 -101
- package/dist/sample/assets/epub/epub_2/OEBPS/1.css +0 -12
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-0.htm.html +0 -26
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-1.htm.html +0 -27
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-10.htm.html +0 -49
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-11.htm.html +0 -152
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-12.htm.html +0 -111
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-13.htm.html +0 -136
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-14.htm.html +0 -177
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-15.htm.html +0 -144
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-16.htm.html +0 -105
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-17.htm.html +0 -52
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-2.htm.html +0 -83
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-3.htm.html +0 -84
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-4.htm.html +0 -69
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-5.htm.html +0 -158
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-6.htm.html +0 -154
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-7.htm.html +0 -163
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-8.htm.html +0 -94
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@2852-h-9.htm.html +0 -154
- package/dist/sample/assets/epub/epub_2/OEBPS/@public@vhost@g@gutenberg@html@files@2852@2852-h@images@cover.jpg +0 -0
- package/dist/sample/assets/epub/epub_2/OEBPS/content.opf +0 -91
- package/dist/sample/assets/epub/epub_2/OEBPS/pgepub.css +0 -30
- package/dist/sample/assets/epub/epub_2/OEBPS/toc.ncx +0 -125
- package/dist/sample/assets/epub/epub_2/OEBPS/wrap0000.html +0 -16
- package/dist/sample/assets/epub/epub_2/mimetype +0 -1
- package/dist/sample/assets/images/horizontal.png +0 -0
- package/dist/sample/assets/images/horizontal@2x.png +0 -0
- package/dist/sample/assets/images/vertical.png +0 -0
- package/dist/sample/assets/images/vertical@2x.png +0 -0
- package/dist/sample/assets/workers/deflate.js +0 -2
- package/dist/sample/assets/workers/inflate.js +0 -2
- package/dist/sample/assets/workers/z-worker.js +0 -2
- package/dist/sample/css/TreineticEpubReader.css +0 -1324
- package/dist/sample/css/style.css +0 -248
- package/dist/sample/index.html +0 -63
- package/dist/sample/js/TreineticEpubReader.js +0 -58314
- package/dist/sample/js/main.js +0 -218
- package/dist/workers/deflate.js +0 -2
- package/dist/workers/inflate.js +0 -2
- package/dist/workers/z-worker.js +0 -2
package/README.md
CHANGED
|
@@ -1,191 +1,162 @@
|
|
|
1
|
-
# Treinetic
|
|
1
|
+
# Treinetic Epub Reader 2.0.0
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A modern, lightweight, and framework-agnostic EPUB reader for the web, built with TypeScript.
|
|
4
|
+
This project is an initiative of Treinetic (Pvt) Ltd, Sri Lanka.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+

|
|
7
|
+
[](LICENSE)
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
1. Install the library
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm install @treinetic/treinetic-epub-reader --save
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
2. refer `css` and `js` lib in your html ( jquery is a must )
|
|
16
|
-
|
|
17
|
-
```html
|
|
18
|
-
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
|
19
|
-
<link rel="stylesheet" type="text/css" href="../node_modules/@treinetic/treinetic-epub-reader/dist/TreineticEpubReader.min.css">
|
|
20
|
-
<script type="text/javascript" src="../node_modules/@treinetic/treinetic-epub-reader/dist/TreineticEpubReader.min.js"></script>
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
3. create placeholder divs for the reader.
|
|
24
|
-
|
|
25
|
-
```html
|
|
26
|
-
<div id="epub-reader-frame"></div>
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
4. Javascript
|
|
30
|
-
```javascript
|
|
31
|
-
|
|
32
|
-
//Register the reader events and get reader controller object ( note that these are just callbacks you can't treat them as events though )
|
|
33
|
-
|
|
34
|
-
var exControls = TreineticEpubReader.handler();
|
|
35
|
-
exControls.registerEvent("onEpubLoadSuccess", function () {
|
|
12
|
+
This library allows you to easily embed an EPUB reader into any web application. It handles parsing, rendering, pagination, and navigation, while leaving the UI (buttons, sidebars, menus) completely up to you.
|
|
36
13
|
|
|
37
|
-
|
|
14
|
+
---
|
|
38
15
|
|
|
39
|
-
|
|
16
|
+
## Features
|
|
40
17
|
|
|
41
|
-
|
|
18
|
+
| Feature | Description |
|
|
19
|
+
| :--- | :--- |
|
|
20
|
+
| **Framework Agnostic** | Works seamlessly with React, Vue, Angular, or Vanilla JS. |
|
|
21
|
+
| **Lightweight** | Zero heavy dependencies. Uses native Iframe isolation for security and style encapsulation. |
|
|
22
|
+
| **Fully Responsive** | **New:** Automatically adapts padding and font sizes using internal container logic (Internal Wrapper Pattern). |
|
|
23
|
+
| **Themable** | Inject custom CSS, change fonts, and toggle dark mode easily. |
|
|
24
|
+
| **TypeScript** | Fully typed for a great developer experience. |
|
|
25
|
+
| **Modern Build** | ESM and UMD support via Vite for modern bundlers. |
|
|
26
|
+
| **Continuous Scroll** | Support for both Paginated (Kindle-style) and Vertical Scrolling modes. |
|
|
42
27
|
|
|
43
|
-
|
|
44
|
-
if (!hasTOC) {
|
|
45
|
-
let toc = exControls.getTOCJson();
|
|
46
|
-
}
|
|
47
|
-
// you can use following api calls after this
|
|
48
|
-
/**
|
|
49
|
-
exControls.hasNextPage()
|
|
50
|
-
exControls.nextPage();
|
|
51
|
-
exControls.hasPrevPage()
|
|
52
|
-
exControls.prevPage();
|
|
53
|
-
exControls.makeBookMark();
|
|
54
|
-
exControls.changeFontSize(int);
|
|
55
|
-
exControls.changeColumnMaxWidth(int);
|
|
56
|
-
exControls.setTheme("theme-id-goes-here");
|
|
57
|
-
exControls.setScrollMode("scroll-type-id-goes-here");
|
|
58
|
-
exControls.setDisplayFormat("display-format-id-goes-here");
|
|
59
|
-
|
|
60
|
-
extcontrols.getRecommendedFontSizeRange()
|
|
61
|
-
extcontrols.getRecommendedColumnWidthRange()
|
|
62
|
-
var list = extcontrols.getAvailableThemes();
|
|
63
|
-
var list = extcontrols.getAvailableScrollModes();
|
|
64
|
-
var list = extcontrols.getAvailableDisplayFormats();
|
|
65
|
-
var settings = extcontrols.getCurrentReaderSettings();
|
|
66
|
-
**/
|
|
67
|
-
});
|
|
28
|
+
## Requirements
|
|
68
29
|
|
|
30
|
+
- NodeJS 16+ (for development)
|
|
31
|
+
- Modern Browser (ES6 Support)
|
|
69
32
|
|
|
70
|
-
|
|
71
|
-
// if you are planning to use epub file directly make sure that worker js files inside `ZIPJS` the `dist` is copied outside to a accessible location.
|
|
72
|
-
// and set the root folder path of those files to 'jsLibRoot'
|
|
73
|
-
var config = TreineticEpubReader.config();
|
|
74
|
-
config.jsLibRoot = "src/ZIPJS/";
|
|
33
|
+
## Installation
|
|
75
34
|
|
|
76
|
-
|
|
77
|
-
|
|
35
|
+
### 1. NPM
|
|
36
|
+
Install the package via npm:
|
|
78
37
|
|
|
79
|
-
|
|
38
|
+
```bash
|
|
39
|
+
npm install @treinetic/treinetic-epub-reader
|
|
80
40
|
```
|
|
81
41
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
**BSD-3-Clause** ( http://opensource.org/licenses/BSD-3-Clause )
|
|
85
|
-
|
|
86
|
-
See [license.txt](./license.txt).
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## Development
|
|
90
|
-
|
|
91
|
-
### Git initialisation
|
|
92
|
-
|
|
93
|
-
* `git clone --recursive -b BRANCH_NAME https://github.com/Treinetic/TreineticEpubReader.git TreineticEpubReader` (replace "BRANCH_NAME" with e.g. "development")
|
|
94
|
-
* `cd TreineticEpubReader`
|
|
95
|
-
* `git submodule update --init --recursive` to ensure that the TreineticEpubReader chain of dependencies is initialised (readium-js, readium-shared-js)
|
|
96
|
-
* `git checkout BRANCH_NAME && git submodule foreach --recursive "git checkout BRANCH_NAME"` (or simply `cd` inside each repository / submodule, and manually enter the desired branch name: `git checkout BRANCH_NAME`) Git should automatically track the corresponding branch in the 'origin' remote.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Advanced usage (e.g. TravisCI) - the commands below automate the remote/origin tracking process (this requires a Bash-like shell):
|
|
100
|
-
|
|
101
|
-
* ``for remote in `git branch -r | grep -v \> | grep -v master`; do git branch --track ${remote#origin/} $remote; done`` to ensure that all Git 'origin' remotes are tracked by local branches.
|
|
102
|
-
* ``git checkout `git for-each-ref --format="%(refname:short) %(objectname)" 'refs/heads/' | grep $(git rev-parse HEAD) | cut -d " " -f 1` `` to ensure that Git checks-out actual branch names (as by default Git initializes submodules to match their registered Git SHA1 commit, but in detached HEAD state)
|
|
42
|
+
### 2. Manual
|
|
43
|
+
Alternatively, you can include the `dist/treinetic-epub-reader.umd.js` and `dist/style.css` manually in your project.
|
|
103
44
|
|
|
104
|
-
|
|
45
|
+
## Running the Demo
|
|
105
46
|
|
|
47
|
+
To see the reader in action with a sample UI:
|
|
106
48
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Note that the above command executes the following:
|
|
115
|
-
|
|
116
|
-
* `npm install` (to download dependencies defined in `package.json` ... note that the `--production` option can be used to avoid downloading development dependencies, for example when testing only the pre-built `build-output` folder contents)
|
|
117
|
-
* `npm update` (to make sure that the dependency tree is up to date)
|
|
118
|
-
* + some additional HTTP requests to the GitHub API in order to check for upstream library updates (wherever Readium uses a forked codebase)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
### Typical workflow
|
|
122
|
-
|
|
123
|
-
No RequireJS optimization:
|
|
124
|
-
|
|
125
|
-
* `npm run http` (to launch an http server. This automatically opens a web browser instance to the HTML files in the `dev` folder, choose `dev-sample.html` which do include only the reader view)
|
|
126
|
-
* Hack away! (e.g. source code in the `src/js` folder)
|
|
127
|
-
* Press F5 (refresh / reload) in the web browser
|
|
128
|
-
|
|
129
|
-
Or to use optimized Javascript bundles (single or multiple):
|
|
130
|
-
|
|
131
|
-
* `npm run build` (to update the RequireJS bundles in the build output folder)
|
|
132
|
-
* `npm run http:watch` (to launch an http server. This automatically opens a web browser instance to the HTML files in the `dev` folder, choose `index_RequireJS_single-bundle.html` or `index_RequireJS_multiple-bundles.html`, or the `*LITE.html` variants which do include only the reader view, not the ebook library view)
|
|
133
|
-
* `npm run http` (same as above, but without watching for file changes (no automatic rebuild))
|
|
134
|
-
|
|
135
|
-
And finally to update the distribution package.
|
|
136
|
-
|
|
137
|
-
* `npm run tr_build`
|
|
138
|
-
|
|
139
|
-
Also note that the built-in local HTTP server functionality (`npm run http`) is primarily designed to serve the Readium application at development time in its "exploded" form (`dev`, `src`, `node_modules`, etc. folders). It is also possible to use any arbitrary HTTP server as long as the root folder is `readium-js-viewer` (so that the application assets ; CSS, images, fonts ; can be loaded relative to this base URL). Example with the built-in NodeJS server: `node node_modules/http-server/bin/http-server -a 127.0.0.1 -p 8080 -c-1 .`. Also note that the `127.0.0.1` IP address which is used by default when invoking the `npm run http` command can be set to `0.0.0.0` in order to automatically bind the HTTP server to the local LAN IP, making it possible to open the Readium app in a web browser from another machine on the network. Simply set the `RJS_HTTP_IP` environment variable to `0.0.0.0` (e.g. using `export RJS_HTTP_IP="0.0.0.0"` from the command line), or for a less permanent setting: `RJS_HTTP_IP="0.0.0.0" npm run http` (the environment variable only "lasts" for the lifespan of the NPM command).
|
|
140
|
-
|
|
141
|
-
Remark: a log of HTTP requests is preserved in `http_app-ebooks.log`. This file contains ANSI color escape codes, so although it can be read using a regular text editor, it can be rendered in its original format using the shell command: `cat http_app.log` (on OSX / Linux), or `sed "s,x,x,g" http_app-ebooks.log` (on Windows).
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
### HTTP CORS (separate domains / origins, app vs. ebooks)
|
|
145
|
-
|
|
146
|
-
By default, a single HTTP server is launched when using the `npm run http` task, or its "watch" and "nowatch" variants (usage described in the above "Typical workflow" section).
|
|
147
|
-
To launch separate local HTTP servers on two different domains (in order to test HTTP CORS cross-origin app vs. ebooks deployment architecture), simply invoke the equivalent tasks named with `http2` instead of `http`. For example: `npm run http2`. More information about real-world HTTP CORS is given in the "Cloud reader deployment" section below.
|
|
148
|
-
|
|
149
|
-
Remark: logs of HTTP requests are preserved in two separate files `http_app.log` and `http_ebooks.log`. They contains ANSI color escape codes, so although they can be read using a regular text editor, they can be rendered in their original format using the shell command: `cat http_app.log` (on OSX / Linux), or `sed "s,x,x,g" http_app.log` (on Windows).
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/Treinetic/TreineticEpubReader.git
|
|
51
|
+
cd TreineticEpubReader
|
|
52
|
+
npm install
|
|
53
|
+
npm run demo
|
|
54
|
+
```
|
|
55
|
+
This will start a local server at `http://localhost:3001` with hot-reloading.
|
|
150
56
|
|
|
57
|
+
## Usage
|
|
151
58
|
|
|
152
|
-
###
|
|
59
|
+
### Basic Usage
|
|
153
60
|
|
|
154
|
-
|
|
61
|
+
First, import the necessary classes and CSS.
|
|
155
62
|
|
|
63
|
+
```typescript
|
|
64
|
+
import TreineticEpubReader from '@treinetic/treinetic-epub-reader';
|
|
65
|
+
import '@treinetic/treinetic-epub-reader/dist/style.css';
|
|
156
66
|
|
|
157
|
-
|
|
67
|
+
// Create the reader instance targeting your container
|
|
68
|
+
const reader = TreineticEpubReader.create("#epub-reader-frame");
|
|
158
69
|
|
|
159
|
-
|
|
70
|
+
// Load an EPUB file (url or base64)
|
|
71
|
+
reader.open("path/to/book.epub");
|
|
72
|
+
```
|
|
160
73
|
|
|
161
|
-
|
|
162
|
-
|
|
74
|
+
### HTML Structure
|
|
75
|
+
Create a container for the reader. The library will inject an internal wrapper and iframe into this div.
|
|
163
76
|
|
|
77
|
+
```html
|
|
78
|
+
<div id="epub-reader-frame" style="width: 100%; height: 600px;"></div>
|
|
79
|
+
```
|
|
80
|
+
> [!TIP]
|
|
81
|
+
> You can resize this container at will. The reader monitors its own size and adjusts layouts (padding, columns) automatically.
|
|
164
82
|
|
|
165
|
-
|
|
83
|
+
### Controlling the Reader
|
|
166
84
|
|
|
167
|
-
|
|
85
|
+
```typescript
|
|
86
|
+
// Navigation
|
|
87
|
+
document.getElementById('next-btn').onclick = () => reader.nextPage();
|
|
88
|
+
document.getElementById('prev-btn').onclick = () => reader.prevPage();
|
|
168
89
|
|
|
169
|
-
|
|
90
|
+
// Settings
|
|
91
|
+
reader.setTheme('night'); // 'day', 'night', 'sepia'
|
|
92
|
+
reader.setFontSize(120); // Percentage
|
|
93
|
+
```
|
|
170
94
|
|
|
171
|
-
|
|
95
|
+
### API Reference
|
|
96
|
+
|
|
97
|
+
| Method | Signature | Description |
|
|
98
|
+
| :--- | :--- | :--- |
|
|
99
|
+
| `open` | `(url: string) => void` | Loads and renders an EPUB file. |
|
|
100
|
+
| `nextPage` | `() => void` | Navigates to the next page or chapter. |
|
|
101
|
+
| `prevPage` | `() => void` | Navigates to the previous page or chapter. |
|
|
102
|
+
| `goToPage` | `(href: string) => void` | Navigates to a specific spine item (chapter). |
|
|
103
|
+
| `getTOC` | `() => TOCItem[]` | Returns the Table of Contents as a JSON tree. |
|
|
104
|
+
| `setTheme` | `(id: string) => void` | Switches themes (e.g. 'night', 'sepia', 'day'). |
|
|
105
|
+
| `registerTheme` | `(theme: ReaderTheme) => void` | Registers a new custom theme. |
|
|
106
|
+
| `setFontSize` | `(size: number) => void` | Sets font size (percentage, e.g. 120). |
|
|
107
|
+
| `setScrollOption`| `(mode: 'auto' \| 'scroll-continuous')` | Toggle between Paginated and Vertical Scroll. |
|
|
108
|
+
| `clearSettings` | `() => void` | Resets all user preferences (font, theme, location). |
|
|
109
|
+
|
|
110
|
+
### Keyboard Shortcuts
|
|
111
|
+
| Key | Action |
|
|
112
|
+
| :--- | :--- |
|
|
113
|
+
| `ArrowRight` | Next Page |
|
|
114
|
+
| `ArrowLeft` | Prev Page |
|
|
115
|
+
|
|
116
|
+
## 🎨 Advanced Customization
|
|
117
|
+
|
|
118
|
+
### Creating Custom Themes
|
|
119
|
+
You are not limited to the default themes. You can register your own:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
reader.registerTheme({
|
|
123
|
+
id: 'matrix-theme',
|
|
124
|
+
name: 'Matrix Mode',
|
|
125
|
+
style: {
|
|
126
|
+
'body': {
|
|
127
|
+
'background-color': '#000000',
|
|
128
|
+
'color': '#00FF00'
|
|
129
|
+
},
|
|
130
|
+
'p': {
|
|
131
|
+
'font-family': 'monospace'
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
172
135
|
|
|
173
|
-
|
|
136
|
+
reader.setTheme('matrix-theme');
|
|
137
|
+
```
|
|
174
138
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
139
|
+
## 🗺️ Project Roadmap
|
|
140
|
+
We have an ambitious vision to make this the de facto standard for open-source EPUB rendering.
|
|
141
|
+
Please see our detailed [ROADMAP](roadmap.md) for upcoming features like Full-Text Search, Offline support, and Mobile gestures.
|
|
178
142
|
|
|
179
|
-
|
|
143
|
+
## Project Structure
|
|
180
144
|
|
|
181
|
-
|
|
145
|
+
This project has been modernized (v2.0.0) to separate the **Core Library** from the **Demo Application**.
|
|
182
146
|
|
|
183
|
-
|
|
147
|
+
* `src/lib/`: **The Library**. Contains the core logic (`TreineticEpubReader.ts`, `ReaderView.ts`).
|
|
148
|
+
* `src/css/`: **Library CSS**. `main.css` (layout) and `responsive.css` (adaptive padding).
|
|
149
|
+
* `demo/`: **The Demo App**. Contains the UI (`index.html`, `demo.css`, `demo.js`).
|
|
150
|
+
* `dist/`: **Build Output**. The compiled files published to NPM.
|
|
184
151
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
* `npm run test:sauce:chromeApp`
|
|
152
|
+
## Contributing
|
|
153
|
+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
|
|
188
154
|
|
|
189
|
-
|
|
155
|
+
## Credits
|
|
156
|
+
- [Imal Hasaranga Perera](https://github.com/imalhasaranga)
|
|
157
|
+
- [Nuril Ahemad](https://github.com/nurilahemad)
|
|
158
|
+
- [All Contributors](../../contributors)
|
|
190
159
|
|
|
191
|
-
|
|
160
|
+
## License
|
|
161
|
+
The MIT License (MIT). Please see [License File](LICENSE) for more information.
|
|
162
|
+
(Portions based on the original ReadiumJS viewer, BSD-3-Clause).
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare class ExternalControls {
|
|
2
|
+
private static instance;
|
|
3
|
+
metadata: any;
|
|
4
|
+
reader: any;
|
|
5
|
+
channel: any;
|
|
6
|
+
auto_bookmark: boolean;
|
|
7
|
+
TocJsonObject: any;
|
|
8
|
+
currentPackageDocument: any;
|
|
9
|
+
readerSettings: any;
|
|
10
|
+
callbackFunctions: {
|
|
11
|
+
[key: string]: Function;
|
|
12
|
+
};
|
|
13
|
+
private constructor();
|
|
14
|
+
static getInstance(): ExternalControls;
|
|
15
|
+
static createInstance(): void;
|
|
16
|
+
epubLoaded(metadata: any, currentPackageDocument: any, reader: any): void;
|
|
17
|
+
registerEvent(eventName: string, func: Function): void;
|
|
18
|
+
epubFailed(error: any): void;
|
|
19
|
+
registerChannel(func: Function): void;
|
|
20
|
+
onTOCLoad(tocJson: any): void;
|
|
21
|
+
getReaderHeight(): number | null;
|
|
22
|
+
nextPage(): void;
|
|
23
|
+
prevPage(): void;
|
|
24
|
+
hasNextPage(): boolean;
|
|
25
|
+
hasPrevPage(): boolean;
|
|
26
|
+
makeBookMark(): void;
|
|
27
|
+
setAutoBookmark(val: boolean): void;
|
|
28
|
+
isAutoBookmark(): boolean;
|
|
29
|
+
getTOCJson(): string;
|
|
30
|
+
hasTOC(): boolean;
|
|
31
|
+
goToPage(href: string): void;
|
|
32
|
+
changeFontSize(size: number): void;
|
|
33
|
+
getRecommendedFontSizeRange(): {
|
|
34
|
+
min: number;
|
|
35
|
+
max: number;
|
|
36
|
+
};
|
|
37
|
+
setTheme(theme_id: string): void;
|
|
38
|
+
setScrollOption(type: 'auto' | 'scroll-continuous'): void;
|
|
39
|
+
private cloneUpdate;
|
|
40
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const Keyboard: {
|
|
2
|
+
scope: string;
|
|
3
|
+
handlers: {
|
|
4
|
+
[key: string]: Function[];
|
|
5
|
+
};
|
|
6
|
+
init: () => void;
|
|
7
|
+
on: (keyName: string, scope: string, callback: Function) => void;
|
|
8
|
+
handleKey: (e: KeyboardEvent) => void;
|
|
9
|
+
dispatch: (action: string) => void;
|
|
10
|
+
PagePrevious: string;
|
|
11
|
+
PageNext: string;
|
|
12
|
+
NightTheme: string;
|
|
13
|
+
applySettings: (_json: any) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const ModuleConfig: {
|
|
2
|
+
imagePathPrefix: string;
|
|
3
|
+
epubLibraryPath: string;
|
|
4
|
+
canHandleUrl: boolean;
|
|
5
|
+
canHandleDirectory: boolean;
|
|
6
|
+
epubReadingSystemUrl: string;
|
|
7
|
+
workerUrl: string;
|
|
8
|
+
annotationCSSUrl: string;
|
|
9
|
+
mathJaxUrl: string;
|
|
10
|
+
jsLibRoot: string;
|
|
11
|
+
fonts: never[];
|
|
12
|
+
useSimpleLoader: boolean;
|
|
13
|
+
loader: null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const Settings: {
|
|
2
|
+
put: (key: string, val: any, callback?: () => void) => void;
|
|
3
|
+
clear: (key: string, callback?: () => void) => void;
|
|
4
|
+
get: (key: string, callback?: (val: any) => void) => any;
|
|
5
|
+
getMultiple: (keys: string[], callback?: (val: any) => void) => any;
|
|
6
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const TOCJsonCreator: {
|
|
2
|
+
createTOCJson: (tocDom: HTMLElement) => any[];
|
|
3
|
+
getRootOL: (dom: HTMLElement) => HTMLElement;
|
|
4
|
+
findRecursively: (ol: HTMLElement) => any[];
|
|
5
|
+
createTOCItem: (a: HTMLAnchorElement) => {
|
|
6
|
+
Id_link: string | null;
|
|
7
|
+
name: string;
|
|
8
|
+
sub: any[];
|
|
9
|
+
};
|
|
10
|
+
getFixedTocElement: (dom: Document | HTMLElement) => HTMLElement;
|
|
11
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ReaderTheme {
|
|
2
|
+
name: string;
|
|
3
|
+
properties: {
|
|
4
|
+
"background-color": string;
|
|
5
|
+
"color": string;
|
|
6
|
+
"font-family"?: string;
|
|
7
|
+
[key: string]: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
css?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class ThemeManager {
|
|
12
|
+
private static instance;
|
|
13
|
+
private themes;
|
|
14
|
+
private constructor();
|
|
15
|
+
static getInstance(): ThemeManager;
|
|
16
|
+
registerTheme(theme: ReaderTheme): void;
|
|
17
|
+
getTheme(name: string): ReaderTheme | undefined;
|
|
18
|
+
private resolveThemeAlias;
|
|
19
|
+
private registerDefaultThemes;
|
|
20
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ExternalControls } from './ExternalControls';
|
|
2
|
+
import { ReaderView } from './view/ReaderView';
|
|
3
|
+
import { ReaderTheme } from './ThemeManager';
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
READIUM: any;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
declare const TreineticEpubReader: {
|
|
10
|
+
readium: any;
|
|
11
|
+
readerView: ReaderView | null;
|
|
12
|
+
currentPackageDocument: any;
|
|
13
|
+
ebookURL_filepath: string | null;
|
|
14
|
+
embeded: boolean;
|
|
15
|
+
init: (selectorOrElement: string | HTMLElement) => ExternalControls | null;
|
|
16
|
+
/**
|
|
17
|
+
* Alias for init() to align with standard library patterns.
|
|
18
|
+
*/
|
|
19
|
+
create: (selectorOrElement: string | HTMLElement) => ExternalControls | null;
|
|
20
|
+
open: (epubUrlOrFolder: string) => void;
|
|
21
|
+
initReader: (element: HTMLElement) => void;
|
|
22
|
+
handleReaderEvents: () => void;
|
|
23
|
+
loadEpub: (_readerSettings: any, ebookURL: string, _openPageRequest: any) => Promise<void>;
|
|
24
|
+
setReaderPreferences: () => {
|
|
25
|
+
reader: any;
|
|
26
|
+
};
|
|
27
|
+
getOpenPageRequest: (_settings: any, _ebookURL: string) => null;
|
|
28
|
+
savePlace: () => void;
|
|
29
|
+
nextPage: () => void;
|
|
30
|
+
prevPage: () => void;
|
|
31
|
+
goToPage: (href: string) => void;
|
|
32
|
+
setTheme: (theme: string) => void;
|
|
33
|
+
registerTheme: (theme: ReaderTheme) => void;
|
|
34
|
+
setFontSize: (size: number) => void;
|
|
35
|
+
setScrollOption: (type: "auto" | "scroll-continuous") => void;
|
|
36
|
+
clearSettings: () => void;
|
|
37
|
+
};
|
|
38
|
+
export default TreineticEpubReader;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const TreineticHelpers: {
|
|
2
|
+
updateReader: (reader: any, readerSettings: any) => void;
|
|
3
|
+
getBookStyles: (theme: string) => ({
|
|
4
|
+
selector: string;
|
|
5
|
+
declarations: {
|
|
6
|
+
backgroundColor: string | null | undefined;
|
|
7
|
+
color: string | null | undefined;
|
|
8
|
+
fontFamily: string;
|
|
9
|
+
};
|
|
10
|
+
} | {
|
|
11
|
+
selector: string;
|
|
12
|
+
declarations: {
|
|
13
|
+
backgroundColor: string | null | undefined;
|
|
14
|
+
color: string | null | undefined;
|
|
15
|
+
fontFamily?: undefined;
|
|
16
|
+
};
|
|
17
|
+
})[];
|
|
18
|
+
getPropertyFromThemeClass: (classOrId: string, property: string) => string | null | undefined;
|
|
19
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class Metadata {
|
|
2
|
+
identifier?: string;
|
|
3
|
+
title?: string;
|
|
4
|
+
author?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
publisher?: string;
|
|
7
|
+
language?: string;
|
|
8
|
+
rights?: string;
|
|
9
|
+
modifiedDate?: string;
|
|
10
|
+
publishedDate?: string;
|
|
11
|
+
epubVersion?: string;
|
|
12
|
+
constructor(packageMetadata?: any);
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { default as JSZip } from 'jszip';
|
|
2
|
+
import { Spine } from './Spine';
|
|
3
|
+
import { Metadata } from './Metadata';
|
|
4
|
+
export declare class Package {
|
|
5
|
+
rootUrl: string;
|
|
6
|
+
rootUrlMO?: string;
|
|
7
|
+
spine: Spine;
|
|
8
|
+
metadata: Metadata;
|
|
9
|
+
zip: JSZip | null;
|
|
10
|
+
rendition_viewport?: string;
|
|
11
|
+
rendition_layout?: string;
|
|
12
|
+
rendition_flow?: string;
|
|
13
|
+
rendition_orientation?: string;
|
|
14
|
+
rendition_spread?: string;
|
|
15
|
+
toc?: any;
|
|
16
|
+
constructor(packageData: any);
|
|
17
|
+
resolveRelativeUrl(relativeUrl: string): string;
|
|
18
|
+
isFixedLayout(): boolean;
|
|
19
|
+
loadFile(relativePath: string): Promise<string | null>;
|
|
20
|
+
loadBlob(relativePath: string): Promise<Blob | null>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Package } from './Package';
|
|
2
|
+
import { SpineItem } from './SpineItem';
|
|
3
|
+
export declare class Spine {
|
|
4
|
+
package: Package;
|
|
5
|
+
items: SpineItem[];
|
|
6
|
+
direction: string;
|
|
7
|
+
private handleLinear;
|
|
8
|
+
constructor(epubPackage: Package, spineDTO?: any);
|
|
9
|
+
isValidLinearItem(index: number): boolean;
|
|
10
|
+
item(index: number): SpineItem | undefined;
|
|
11
|
+
getItemByHref(href: string): SpineItem | undefined;
|
|
12
|
+
first(): SpineItem | undefined;
|
|
13
|
+
firstLinear(): SpineItem | undefined;
|
|
14
|
+
nextItem(item: SpineItem): SpineItem | undefined;
|
|
15
|
+
prevItem(item: SpineItem): SpineItem | undefined;
|
|
16
|
+
nextLinear(item: SpineItem): SpineItem | undefined;
|
|
17
|
+
prevLinear(item: SpineItem): SpineItem | undefined;
|
|
18
|
+
last(): SpineItem | undefined;
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Spine } from './Spine';
|
|
2
|
+
export declare class SpineItem {
|
|
3
|
+
idref: string;
|
|
4
|
+
href: string;
|
|
5
|
+
cfi: string;
|
|
6
|
+
linear: string;
|
|
7
|
+
page_spread: string;
|
|
8
|
+
rendition_viewport?: string;
|
|
9
|
+
rendition_spread?: string;
|
|
10
|
+
rendition_orientation?: string;
|
|
11
|
+
rendition_layout?: string;
|
|
12
|
+
rendition_flow?: string;
|
|
13
|
+
media_overlay_id?: string;
|
|
14
|
+
media_type?: string;
|
|
15
|
+
index: number;
|
|
16
|
+
spine: Spine;
|
|
17
|
+
static readonlyRENDITION_LAYOUT_REFLOWABLE: string;
|
|
18
|
+
static readonly RENDITION_LAYOUT_PREPAGINATED = "pre-paginated";
|
|
19
|
+
static readonly SPREAD_LEFT = "page-spread-left";
|
|
20
|
+
static readonly SPREAD_RIGHT = "page-spread-right";
|
|
21
|
+
static readonly SPREAD_CENTER = "page-spread-center";
|
|
22
|
+
static readonly SPREAD_NONE = "none";
|
|
23
|
+
static readonly SPREAD_AUTO = "auto";
|
|
24
|
+
static readonly FLOW_PAGINATED = "paginated";
|
|
25
|
+
static readonly FLOW_SCROLLED_CONTINUOUS = "scrolled-continuous";
|
|
26
|
+
static readonly FLOW_SCROLLED_DOC = "scrolled-doc";
|
|
27
|
+
static readonly FLOW_AUTO = "auto";
|
|
28
|
+
constructor(itemData: any, index: number, spine: Spine);
|
|
29
|
+
private validateSpread;
|
|
30
|
+
isReflowable(): boolean;
|
|
31
|
+
isFixedLayout(): boolean;
|
|
32
|
+
getRenditionLayout(): string | undefined;
|
|
33
|
+
static alternateSpread(spread: string): string;
|
|
34
|
+
}
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#epub-reader-frame{display:block;height:100%;width:100%;position:relative;border:none;box-sizing:border-box}.tr-epub-reader-element{container-type:inline-size;width:100%;height:100%;position:relative;padding:0;scrollbar-width:none;-ms-overflow-style:none}.tr-internal-wrapper{display:grid;width:100%;min-height:100%;box-sizing:border-box;padding:20px}.tr-epub-reader-element::-webkit-scrollbar{display:none}@container (max-width: 800px){.tr-internal-wrapper{padding:14px!important}}@container (max-width: 500px){.tr-internal-wrapper{padding:5px!important}}
|