@likecoin/epub-ts 0.3.95 → 0.3.97
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 +118 -12
- package/dist/annotations.d.ts +1 -1
- package/dist/archive.d.ts +3 -3
- package/dist/book.d.ts +12 -11
- package/dist/contents.d.ts +4 -3
- package/dist/epub.cjs +5 -5
- package/dist/epub.cjs.map +1 -1
- package/dist/epub.d.ts +3 -1
- package/dist/epub.js +1878 -1878
- package/dist/epub.js.map +1 -1
- package/dist/epub.umd.js +5 -5
- package/dist/epub.umd.js.map +1 -1
- package/dist/epubcfi.d.ts +5 -5
- package/dist/index.d.ts +13 -1
- package/dist/locations.d.ts +10 -4
- package/dist/managers/continuous/index.d.ts +2 -2
- package/dist/managers/default/index.d.ts +5 -5
- package/dist/managers/helpers/views.d.ts +1 -1
- package/dist/mapping.d.ts +5 -3
- package/dist/packaging.d.ts +2 -4
- package/dist/rendition.d.ts +8 -8
- package/dist/resources.d.ts +1 -1
- package/dist/section.d.ts +2 -2
- package/dist/spine.d.ts +1 -1
- package/dist/store.d.ts +3 -3
- package/dist/themes.d.ts +1 -2
- package/dist/types.d.ts +4 -7
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/core.d.ts +0 -1
- package/package.json +15 -3
package/README.md
CHANGED
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
A TypeScript fork of [epubjs](https://github.com/futurepress/epub.js) v0.3.93 by [Fred Chasen](https://github.com/fchasen) / [FuturePress](https://github.com/futurepress) — parse and render EPUB documents in the browser.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://github.com/likecoin/epub.ts/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/@likecoin/epub-ts)
|
|
7
|
+
[](./LICENSE)
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
> **Note**: This library is primarily developed for internal use at [3ook.com](https://3ook.com) and is provided as-is. It was mainly built with AI-assisted development. For the original library, see [epubjs](https://github.com/futurepress/epub.js).
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Drop-in replacement** for epubjs v0.3.93 — same API, just change the import
|
|
14
|
+
- **TypeScript first** — full strict mode, typed emitter, generated `.d.ts` declarations
|
|
15
|
+
- **Modern build** — Vite library build, ESM + CJS output
|
|
16
|
+
- **Fewer dependencies** — removed `core-js`, `lodash`, `path-webpack`, `event-emitter`
|
|
17
|
+
- **Named exports** — import individual classes like `Book`, `EpubCFI`, `Rendition`, etc.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
8
20
|
|
|
9
21
|
```bash
|
|
10
22
|
npm install @likecoin/epub-ts
|
|
@@ -12,18 +24,34 @@ npm install @likecoin/epub-ts
|
|
|
12
24
|
|
|
13
25
|
## Quick Start
|
|
14
26
|
|
|
15
|
-
|
|
27
|
+
### ES Modules (recommended)
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
16
30
|
import ePub from "@likecoin/epub-ts";
|
|
17
31
|
|
|
18
|
-
// Same API as epubjs
|
|
19
32
|
const book = ePub("/path/to/book.epub");
|
|
20
33
|
const rendition = book.renderTo("viewer", { width: 600, height: 400 });
|
|
21
34
|
rendition.display();
|
|
22
35
|
```
|
|
23
36
|
|
|
37
|
+
### Browser (from ArrayBuffer)
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import ePub from "@likecoin/epub-ts";
|
|
41
|
+
|
|
42
|
+
const fileInput = document.querySelector('input[type="file"]');
|
|
43
|
+
fileInput.addEventListener("change", async (event) => {
|
|
44
|
+
const file = event.target.files[0];
|
|
45
|
+
const data = await file.arrayBuffer();
|
|
46
|
+
const book = ePub(data);
|
|
47
|
+
const rendition = book.renderTo("viewer", { width: 600, height: 400 });
|
|
48
|
+
rendition.display();
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
24
52
|
## Migration from epubjs
|
|
25
53
|
|
|
26
|
-
|
|
54
|
+
Drop-in replacement. Change your import:
|
|
27
55
|
|
|
28
56
|
```diff
|
|
29
57
|
- import ePub from "epubjs";
|
|
@@ -35,30 +63,108 @@ All APIs remain the same.
|
|
|
35
63
|
## Named Exports
|
|
36
64
|
|
|
37
65
|
```js
|
|
38
|
-
import {
|
|
66
|
+
import {
|
|
67
|
+
Book, EpubCFI, Rendition, Contents, Layout,
|
|
68
|
+
Section, Spine, Locations, Navigation, PageList,
|
|
69
|
+
Resources, Packaging, Archive, Store,
|
|
70
|
+
Annotations, Themes, Mapping,
|
|
71
|
+
} from "@likecoin/epub-ts";
|
|
39
72
|
```
|
|
40
73
|
|
|
41
|
-
##
|
|
74
|
+
## API
|
|
75
|
+
|
|
76
|
+
See the full [API documentation](https://likecoin.github.io/epub.ts/) for details on all classes, interfaces, and methods.
|
|
77
|
+
|
|
78
|
+
Key classes:
|
|
79
|
+
|
|
80
|
+
| Class | Description |
|
|
81
|
+
|-------|-------------|
|
|
82
|
+
| `Book` | Main EPUB representation — loading, parsing, manipulation |
|
|
83
|
+
| `Rendition` | Renders a book to a DOM element |
|
|
84
|
+
| `Contents` | Manages content within an iframe |
|
|
85
|
+
| `EpubCFI` | EPUB Canonical Fragment Identifier parser |
|
|
86
|
+
| `Locations` | Generates and manages reading locations |
|
|
87
|
+
| `Navigation` | Table of contents and landmarks |
|
|
88
|
+
| `Annotations` | Highlights, underlines, and marks |
|
|
89
|
+
|
|
90
|
+
## Comparison with epubjs
|
|
91
|
+
|
|
92
|
+
| Aspect | epub.ts | epubjs |
|
|
93
|
+
|--------|---------|--------|
|
|
94
|
+
| Language | TypeScript (strict mode) | JavaScript |
|
|
95
|
+
| Build | Vite | webpack + Babel |
|
|
96
|
+
| Tests | Vitest | Karma + Mocha |
|
|
97
|
+
| Type definitions | Generated from source | Hand-written `.d.ts` |
|
|
98
|
+
| Dependencies | 3 (`jszip`, `localforage`, `@xmldom/xmldom`) | 7+ (`core-js`, `lodash`, `event-emitter`, etc.) |
|
|
99
|
+
| API compatibility | 100% (drop-in replacement) | — |
|
|
100
|
+
| Bundle format | ESM + CJS | UMD |
|
|
101
|
+
| Maintenance | Active | Inactive since 2022 |
|
|
102
|
+
|
|
103
|
+
## Supported Environments
|
|
104
|
+
|
|
105
|
+
| Environment | Notes |
|
|
106
|
+
|-------------|-------|
|
|
107
|
+
| Modern browsers | Chrome, Firefox, Safari, Edge (requires DOM) |
|
|
108
|
+
| Vite / webpack | ESM or CJS imports |
|
|
109
|
+
|
|
110
|
+
> **Note**: This library requires a DOM environment. Node.js support (parsing-only, no rendering) is planned but not yet available.
|
|
111
|
+
|
|
112
|
+
## What's Changed from epubjs
|
|
42
113
|
|
|
43
114
|
- Build: webpack + Babel → Vite
|
|
44
115
|
- Tests: Karma + Mocha → Vitest
|
|
45
|
-
- Source: JavaScript → TypeScript (
|
|
116
|
+
- Source: JavaScript → TypeScript (full strict mode)
|
|
46
117
|
- Removed dependencies: `core-js`, `lodash`, `path-webpack`
|
|
47
118
|
- Replaced `event-emitter` with inline typed emitter
|
|
48
119
|
|
|
49
120
|
## Development
|
|
50
121
|
|
|
122
|
+
### Prerequisites
|
|
123
|
+
|
|
124
|
+
- Node.js 18+
|
|
125
|
+
- npm 9+
|
|
126
|
+
|
|
127
|
+
### Setup
|
|
128
|
+
|
|
51
129
|
```bash
|
|
130
|
+
git clone https://github.com/likecoin/epub.ts.git
|
|
131
|
+
cd epub.ts
|
|
52
132
|
npm install
|
|
53
|
-
npm run build # Vite library build → dist/
|
|
54
|
-
npm test # Vitest
|
|
55
|
-
npm run typecheck # tsc --noEmit
|
|
56
133
|
```
|
|
57
134
|
|
|
135
|
+
### Scripts
|
|
136
|
+
|
|
137
|
+
| Script | Description |
|
|
138
|
+
|--------|-------------|
|
|
139
|
+
| `npm run build` | Vite library build → `dist/` |
|
|
140
|
+
| `npm test` | Run tests (Vitest) |
|
|
141
|
+
| `npm run test:watch` | Run tests in watch mode |
|
|
142
|
+
| `npm run typecheck` | TypeScript type checking (`tsc --noEmit`) |
|
|
143
|
+
| `npm run lint` | ESLint |
|
|
144
|
+
| `npm run lint:fix` | ESLint with auto-fix |
|
|
145
|
+
| `npm run docs` | Generate API docs (HTML + Markdown) |
|
|
146
|
+
|
|
58
147
|
## Contributing
|
|
59
148
|
|
|
60
149
|
See [PROJECT_STATUS.md](./PROJECT_STATUS.md) for current conversion progress and what to work on.
|
|
61
150
|
|
|
151
|
+
For AI agents contributing to this project, see [AGENTS.md](./AGENTS.md).
|
|
152
|
+
|
|
62
153
|
## License
|
|
63
154
|
|
|
64
|
-
BSD-2-Clause (same as epubjs)
|
|
155
|
+
[BSD-2-Clause](./LICENSE) (same as epubjs)
|
|
156
|
+
|
|
157
|
+
## Acknowledgments
|
|
158
|
+
|
|
159
|
+
- [epubjs](https://github.com/futurepress/epub.js) by [Fred Chasen](https://github.com/fchasen) / [FuturePress](https://github.com/futurepress) — the original library this is forked from
|
|
160
|
+
- [jszip](https://github.com/Stuk/jszip) — ZIP file handling
|
|
161
|
+
- [@xmldom/xmldom](https://github.com/xmldom/xmldom) — XML parsing
|
|
162
|
+
|
|
163
|
+
## Built by 3ook.com
|
|
164
|
+
|
|
165
|
+
This project is built and maintained by the [3ook.com](https://3ook.com) team. 3ook is a Web3 eBook platform where authors can publish EPUB ebooks and readers can collect them as digital assets.
|
|
166
|
+
|
|
167
|
+
## Related Projects
|
|
168
|
+
|
|
169
|
+
- [epubjs](https://github.com/futurepress/epub.js) — Original EPUB reader library
|
|
170
|
+
- [epubcheck-ts](https://github.com/likecoin/epubcheck-ts) — TypeScript EPUB validator (also by 3ook.com)
|
package/dist/annotations.d.ts
CHANGED
package/dist/archive.d.ts
CHANGED
|
@@ -51,9 +51,9 @@ declare class Archive {
|
|
|
51
51
|
getBlob(url: string, mimeType?: string): Promise<Blob> | undefined;
|
|
52
52
|
/**
|
|
53
53
|
* Get Text from Archive by Url
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @return
|
|
54
|
+
* @param url
|
|
55
|
+
* @param _encoding
|
|
56
|
+
* @return text content
|
|
57
57
|
*/
|
|
58
58
|
getText(url: string, _encoding?: string): Promise<string> | undefined;
|
|
59
59
|
/**
|
package/dist/book.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ import { default as Rendition } from './rendition';
|
|
|
12
12
|
import { default as Archive } from './archive';
|
|
13
13
|
import { default as Store } from './store';
|
|
14
14
|
import { default as DisplayOptions } from './displayoptions';
|
|
15
|
-
import {
|
|
15
|
+
import { default as JSZip } from 'jszip';
|
|
16
|
+
import { IEventEmitter, BookOptions, RenditionOptions, RequestFunction, PackagingManifestObject, PackagingMetadataObject } from './types';
|
|
16
17
|
import { default as Section } from './section';
|
|
17
18
|
interface BookLoadingState {
|
|
18
19
|
manifest: defer;
|
|
@@ -25,14 +26,14 @@ interface BookLoadingState {
|
|
|
25
26
|
displayOptions: defer;
|
|
26
27
|
}
|
|
27
28
|
interface BookLoadedState {
|
|
28
|
-
manifest: Promise<
|
|
29
|
-
spine: Promise<
|
|
30
|
-
metadata: Promise<
|
|
31
|
-
cover: Promise<
|
|
32
|
-
navigation: Promise<
|
|
33
|
-
pageList: Promise<
|
|
34
|
-
resources: Promise<
|
|
35
|
-
displayOptions: Promise<
|
|
29
|
+
manifest: Promise<PackagingManifestObject>;
|
|
30
|
+
spine: Promise<Spine>;
|
|
31
|
+
metadata: Promise<PackagingMetadataObject>;
|
|
32
|
+
cover: Promise<string>;
|
|
33
|
+
navigation: Promise<Navigation>;
|
|
34
|
+
pageList: Promise<PageList>;
|
|
35
|
+
resources: Promise<Resources>;
|
|
36
|
+
displayOptions: Promise<DisplayOptions>;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* An Epub representation with methods for the loading, parsing and manipulation
|
|
@@ -59,7 +60,7 @@ declare class Book implements IEventEmitter {
|
|
|
59
60
|
isOpen: boolean;
|
|
60
61
|
loading: BookLoadingState | undefined;
|
|
61
62
|
loaded: BookLoadedState | undefined;
|
|
62
|
-
ready: Promise<
|
|
63
|
+
ready: Promise<[PackagingManifestObject, Spine, PackagingMetadataObject, string, Navigation, Resources, DisplayOptions]> | undefined;
|
|
63
64
|
isRendered: boolean;
|
|
64
65
|
request: RequestFunction;
|
|
65
66
|
spine: Spine | undefined;
|
|
@@ -188,7 +189,7 @@ declare class Book implements IEventEmitter {
|
|
|
188
189
|
* @param {string} [encoding]
|
|
189
190
|
* @return {Archive}
|
|
190
191
|
*/
|
|
191
|
-
unarchive(input: string | ArrayBuffer | Blob, encoding?: string): Promise<
|
|
192
|
+
unarchive(input: string | ArrayBuffer | Blob, encoding?: string): Promise<JSZip>;
|
|
192
193
|
/**
|
|
193
194
|
* Store the epubs contents
|
|
194
195
|
* @private
|
package/dist/contents.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { default as EpubCFI } from './epubcfi';
|
|
2
|
+
import { DOM_EVENTS } from './utils/constants';
|
|
2
3
|
import { ViewportSettings, LayoutProps, EpubCFIPair, IEventEmitter } from './types';
|
|
3
4
|
import { default as Section } from './section';
|
|
4
5
|
/**
|
|
@@ -42,7 +43,7 @@ declare class Contents implements IEventEmitter {
|
|
|
42
43
|
/**
|
|
43
44
|
* Get DOM events that are listened for and passed along
|
|
44
45
|
*/
|
|
45
|
-
static get listenedEvents():
|
|
46
|
+
static get listenedEvents(): typeof DOM_EVENTS;
|
|
46
47
|
/**
|
|
47
48
|
* Get or Set width
|
|
48
49
|
* @param {number} [w]
|
|
@@ -216,7 +217,7 @@ declare class Contents implements IEventEmitter {
|
|
|
216
217
|
* @param {array | object} rules
|
|
217
218
|
* @param {string} key If the key is the same, the CSS will be replaced instead of inserted
|
|
218
219
|
*/
|
|
219
|
-
addStylesheetRules(rules:
|
|
220
|
+
addStylesheetRules(rules: Record<string, Record<string, string> | Array<Record<string, string>>> | Array<Array<string | string[]>>, key?: string): void;
|
|
220
221
|
/**
|
|
221
222
|
* Append a script tag to the document head
|
|
222
223
|
* @param {string} src url
|
|
@@ -230,7 +231,7 @@ declare class Contents implements IEventEmitter {
|
|
|
230
231
|
addClass(className: string): void;
|
|
231
232
|
/**
|
|
232
233
|
* Remove a class from the contents container
|
|
233
|
-
* @param
|
|
234
|
+
* @param className - class name to remove
|
|
234
235
|
*/
|
|
235
236
|
removeClass(className: string): void;
|
|
236
237
|
/**
|