@likecoin/epub-ts 0.4.4 → 0.4.6
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 +30 -6
- package/dist/annotations.d.ts +23 -19
- package/dist/book.d.ts +18 -15
- package/dist/contents.d.ts +16 -5
- package/dist/epub.cjs +3 -3
- package/dist/epub.cjs.map +1 -1
- package/dist/epub.js +176 -164
- package/dist/epub.js.map +1 -1
- package/dist/epub.node.cjs +4 -0
- package/dist/epub.node.cjs.map +1 -0
- package/dist/epub.node.js +6294 -0
- package/dist/epub.node.js.map +1 -0
- package/dist/epub.umd.js +3 -3
- package/dist/epub.umd.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/layout.d.ts +7 -4
- package/dist/locations.d.ts +9 -4
- package/dist/managers/continuous/index.d.ts +8 -8
- package/dist/managers/default/index.d.ts +28 -10
- package/dist/managers/helpers/snap.d.ts +13 -15
- package/dist/managers/views/iframe.d.ts +28 -12
- package/dist/managers/views/inline.d.ts +15 -4
- package/dist/navigation.d.ts +1 -1
- package/dist/node.d.ts +25 -0
- package/dist/packaging.d.ts +20 -9
- package/dist/rendition.d.ts +37 -14
- package/dist/resources.d.ts +9 -9
- package/dist/spine.d.ts +10 -10
- package/dist/store.d.ts +8 -4
- package/dist/themes.d.ts +1 -1
- package/dist/types.d.ts +22 -7
- package/dist/utils/hook.d.ts +6 -5
- package/dist/utils/path.d.ts +0 -1
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -49,6 +49,30 @@ fileInput.addEventListener("change", async (event) => {
|
|
|
49
49
|
});
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
### Node.js (parsing only)
|
|
53
|
+
|
|
54
|
+
Parse EPUB metadata, spine, navigation, and section content without a browser. Requires [`linkedom`](https://github.com/WebReflection/linkedom) as a peer dependency.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install linkedom
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { Book } from "@likecoin/epub-ts/node";
|
|
62
|
+
import { readFileSync } from "node:fs";
|
|
63
|
+
|
|
64
|
+
const data = readFileSync("book.epub");
|
|
65
|
+
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
66
|
+
const book = new Book(arrayBuffer);
|
|
67
|
+
await book.opened;
|
|
68
|
+
|
|
69
|
+
console.log(book.packaging.metadata.title);
|
|
70
|
+
console.log(book.navigation.toc.map(item => item.label));
|
|
71
|
+
|
|
72
|
+
const section = book.spine.first();
|
|
73
|
+
const html = await section.render(book.archive.request.bind(book.archive));
|
|
74
|
+
```
|
|
75
|
+
|
|
52
76
|
## Migration from epubjs
|
|
53
77
|
|
|
54
78
|
Drop-in replacement. Change your import:
|
|
@@ -102,12 +126,11 @@ Key classes:
|
|
|
102
126
|
|
|
103
127
|
## Supported Environments
|
|
104
128
|
|
|
105
|
-
| Environment | Notes |
|
|
106
|
-
|
|
107
|
-
| Modern browsers | Chrome, Firefox, Safari, Edge
|
|
108
|
-
| Vite / webpack | ESM or CJS
|
|
109
|
-
|
|
110
|
-
> **Note**: This library requires a DOM environment. Node.js support (parsing-only, no rendering) is planned but not yet available.
|
|
129
|
+
| Environment | Import | Notes |
|
|
130
|
+
|-------------|--------|-------|
|
|
131
|
+
| Modern browsers | `@likecoin/epub-ts` | Chrome, Firefox, Safari, Edge |
|
|
132
|
+
| Vite / webpack | `@likecoin/epub-ts` | ESM or CJS |
|
|
133
|
+
| Node.js 18+ | `@likecoin/epub-ts/node` | Parsing only (no rendering); requires `linkedom` peer dep |
|
|
111
134
|
|
|
112
135
|
## What's Changed from epubjs
|
|
113
136
|
|
|
@@ -118,6 +141,7 @@ Key classes:
|
|
|
118
141
|
- Replaced `event-emitter` with inline typed emitter
|
|
119
142
|
- Replaced `localforage` with native IndexedDB wrapper
|
|
120
143
|
- Replaced `@xmldom/xmldom` with native DOMParser/XMLSerializer
|
|
144
|
+
- Added Node.js parsing-only entry point (`@likecoin/epub-ts/node`) with `linkedom`
|
|
121
145
|
- Dropped IE8–IE11 support
|
|
122
146
|
|
|
123
147
|
## Development
|
package/dist/annotations.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { IEventEmitter } from './types';
|
|
|
2
2
|
import { default as Rendition } from './rendition';
|
|
3
3
|
interface AnnotationView {
|
|
4
4
|
index: number;
|
|
5
|
-
highlight:
|
|
6
|
-
underline:
|
|
7
|
-
mark:
|
|
8
|
-
unhighlight:
|
|
9
|
-
ununderline:
|
|
10
|
-
unmark:
|
|
5
|
+
highlight: (cfiRange: string, data?: Record<string, string>, cb?: EventListener, className?: string, styles?: Record<string, string>) => object | undefined;
|
|
6
|
+
underline: (cfiRange: string, data?: Record<string, string>, cb?: EventListener, className?: string, styles?: Record<string, string>) => object | undefined;
|
|
7
|
+
mark: (cfiRange: string, data?: Record<string, string>, cb?: EventListener) => object | null | undefined;
|
|
8
|
+
unhighlight: (cfiRange: string) => void;
|
|
9
|
+
ununderline: (cfiRange: string) => void;
|
|
10
|
+
unmark: (cfiRange: string) => void;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Handles managing adding & removing Annotations
|
|
@@ -32,7 +32,7 @@ declare class Annotations {
|
|
|
32
32
|
* @param {object} styles CSS styles to assign to annotation
|
|
33
33
|
* @returns {Annotation} annotation
|
|
34
34
|
*/
|
|
35
|
-
add(type: string, cfiRange: string, data?: Record<string, any>, cb?:
|
|
35
|
+
add(type: string, cfiRange: string, data?: Record<string, any>, cb?: EventListener, className?: string, styles?: Record<string, string>): Annotation;
|
|
36
36
|
/**
|
|
37
37
|
* Remove an annotation from store
|
|
38
38
|
* @param {EpubCFI} cfiRange EpubCFI range the annotation is attached to
|
|
@@ -57,7 +57,7 @@ declare class Annotations {
|
|
|
57
57
|
* @param {string} className CSS class to assign to annotation
|
|
58
58
|
* @param {object} styles CSS styles to assign to annotation
|
|
59
59
|
*/
|
|
60
|
-
highlight(cfiRange: string, data?: Record<string, any>, cb?:
|
|
60
|
+
highlight(cfiRange: string, data?: Record<string, any>, cb?: EventListener, className?: string, styles?: Record<string, string>): Annotation;
|
|
61
61
|
/**
|
|
62
62
|
* Add a underline to the store
|
|
63
63
|
* @param {EpubCFI} cfiRange EpubCFI range to attach annotation to
|
|
@@ -66,14 +66,14 @@ declare class Annotations {
|
|
|
66
66
|
* @param {string} className CSS class to assign to annotation
|
|
67
67
|
* @param {object} styles CSS styles to assign to annotation
|
|
68
68
|
*/
|
|
69
|
-
underline(cfiRange: string, data?: Record<string, any>, cb?:
|
|
69
|
+
underline(cfiRange: string, data?: Record<string, any>, cb?: EventListener, className?: string, styles?: Record<string, string>): Annotation;
|
|
70
70
|
/**
|
|
71
71
|
* Add a mark to the store
|
|
72
72
|
* @param {EpubCFI} cfiRange EpubCFI range to attach annotation to
|
|
73
73
|
* @param {object} data Data to assign to annotation
|
|
74
74
|
* @param {function} cb Callback after annotation is clicked
|
|
75
75
|
*/
|
|
76
|
-
mark(cfiRange: string, data?: Record<string, any>, cb?:
|
|
76
|
+
mark(cfiRange: string, data?: Record<string, any>, cb?: EventListener): Annotation;
|
|
77
77
|
/**
|
|
78
78
|
* iterate over annotations in the store
|
|
79
79
|
*/
|
|
@@ -114,24 +114,28 @@ declare class Annotations {
|
|
|
114
114
|
* @param {object} styles CSS styles to assign to annotation
|
|
115
115
|
* @returns {Annotation} annotation
|
|
116
116
|
*/
|
|
117
|
-
|
|
117
|
+
export interface AnnotationEvents extends Record<string, any[]> {
|
|
118
|
+
"attach": [object | null | undefined];
|
|
119
|
+
"detach": [];
|
|
120
|
+
}
|
|
121
|
+
declare class Annotation implements IEventEmitter<AnnotationEvents> {
|
|
118
122
|
type: string;
|
|
119
123
|
cfiRange: string;
|
|
120
124
|
data: Record<string, any>;
|
|
121
125
|
sectionIndex: number;
|
|
122
|
-
mark: object | undefined;
|
|
123
|
-
cb:
|
|
126
|
+
mark: object | null | undefined;
|
|
127
|
+
cb: EventListener;
|
|
124
128
|
className: string;
|
|
125
129
|
styles: Record<string, string>;
|
|
126
|
-
on: IEventEmitter["on"];
|
|
127
|
-
off: IEventEmitter["off"];
|
|
128
|
-
emit: IEventEmitter["emit"];
|
|
130
|
+
on: IEventEmitter<AnnotationEvents>["on"];
|
|
131
|
+
off: IEventEmitter<AnnotationEvents>["off"];
|
|
132
|
+
emit: IEventEmitter<AnnotationEvents>["emit"];
|
|
129
133
|
constructor({ type, cfiRange, data, sectionIndex, cb, className, styles }: {
|
|
130
134
|
type: string;
|
|
131
135
|
cfiRange: string;
|
|
132
136
|
data?: Record<string, any>;
|
|
133
137
|
sectionIndex?: number;
|
|
134
|
-
cb?:
|
|
138
|
+
cb?: EventListener;
|
|
135
139
|
className?: string;
|
|
136
140
|
styles?: Record<string, string>;
|
|
137
141
|
});
|
|
@@ -144,12 +148,12 @@ declare class Annotation implements IEventEmitter {
|
|
|
144
148
|
* Add to a view
|
|
145
149
|
* @param {View} view
|
|
146
150
|
*/
|
|
147
|
-
attach(view: AnnotationView): object | undefined;
|
|
151
|
+
attach(view: AnnotationView): object | null | undefined;
|
|
148
152
|
/**
|
|
149
153
|
* Remove from a view
|
|
150
154
|
* @param {View} view
|
|
151
155
|
*/
|
|
152
|
-
detach(view: AnnotationView):
|
|
156
|
+
detach(view: AnnotationView): void;
|
|
153
157
|
/**
|
|
154
158
|
* [Not Implemented] Get text of an annotation
|
|
155
159
|
* @TODO: needs implementation in contents
|
package/dist/book.d.ts
CHANGED
|
@@ -35,6 +35,9 @@ interface BookLoadedState {
|
|
|
35
35
|
resources: Promise<Resources>;
|
|
36
36
|
displayOptions: Promise<DisplayOptions>;
|
|
37
37
|
}
|
|
38
|
+
export interface BookEvents extends Record<string, any[]> {
|
|
39
|
+
"openFailed": [Error];
|
|
40
|
+
}
|
|
38
41
|
/**
|
|
39
42
|
* An Epub representation with methods for the loading, parsing and manipulation
|
|
40
43
|
* of its contents.
|
|
@@ -53,35 +56,35 @@ interface BookLoadedState {
|
|
|
53
56
|
* @example new Book("/path/to/book.epub", {})
|
|
54
57
|
* @example new Book({ replacements: "blobUrl" })
|
|
55
58
|
*/
|
|
56
|
-
declare class Book implements IEventEmitter {
|
|
59
|
+
declare class Book implements IEventEmitter<BookEvents> {
|
|
57
60
|
settings: BookOptions;
|
|
58
61
|
opening: defer<Book>;
|
|
59
|
-
opened: Promise<Book
|
|
62
|
+
opened: Promise<Book>;
|
|
60
63
|
isOpen: boolean;
|
|
61
|
-
loading: BookLoadingState
|
|
62
|
-
loaded: BookLoadedState
|
|
63
|
-
ready: Promise<[PackagingManifestObject, Spine, PackagingMetadataObject, string, Navigation, Resources, DisplayOptions]
|
|
64
|
+
loading: BookLoadingState;
|
|
65
|
+
loaded: BookLoadedState;
|
|
66
|
+
ready: Promise<[PackagingManifestObject, Spine, PackagingMetadataObject, string, Navigation, Resources, DisplayOptions]>;
|
|
64
67
|
isRendered: boolean;
|
|
65
68
|
request: RequestFunction;
|
|
66
|
-
spine: Spine
|
|
67
|
-
locations: Locations
|
|
68
|
-
navigation: Navigation
|
|
69
|
-
pageList: PageList
|
|
70
|
-
url: Url
|
|
69
|
+
spine: Spine;
|
|
70
|
+
locations: Locations;
|
|
71
|
+
navigation: Navigation;
|
|
72
|
+
pageList: PageList;
|
|
73
|
+
url: Url;
|
|
71
74
|
path: Path | undefined;
|
|
72
75
|
archived: boolean;
|
|
73
76
|
archive: Archive | undefined;
|
|
74
77
|
storage: Store | undefined;
|
|
75
|
-
resources: Resources
|
|
78
|
+
resources: Resources;
|
|
76
79
|
rendition: Rendition | undefined;
|
|
77
80
|
container: Container | undefined;
|
|
78
|
-
packaging: Packaging
|
|
81
|
+
packaging: Packaging;
|
|
79
82
|
displayOptions: DisplayOptions | undefined;
|
|
80
83
|
package: Packaging | undefined;
|
|
81
84
|
cover: string;
|
|
82
|
-
on: IEventEmitter["on"];
|
|
83
|
-
off: IEventEmitter["off"];
|
|
84
|
-
emit: IEventEmitter["emit"];
|
|
85
|
+
on: IEventEmitter<BookEvents>["on"];
|
|
86
|
+
off: IEventEmitter<BookEvents>["off"];
|
|
87
|
+
emit: IEventEmitter<BookEvents>["emit"];
|
|
85
88
|
constructor(url?: string | ArrayBuffer | Blob | BookOptions, options?: BookOptions);
|
|
86
89
|
/**
|
|
87
90
|
* Open a epub or url
|
package/dist/contents.d.ts
CHANGED
|
@@ -10,11 +10,22 @@ import { default as Section } from './section';
|
|
|
10
10
|
* @param {string} cfiBase Section component of CFIs
|
|
11
11
|
* @param {number} sectionIndex Index in Spine of Conntent's Section
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
export interface ContentsEvents {
|
|
14
|
+
"expand": [];
|
|
15
|
+
"resize": [{
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}];
|
|
19
|
+
"selected": [string];
|
|
20
|
+
"selectedRange": [Range];
|
|
21
|
+
"linkClicked": [string];
|
|
22
|
+
[event: string]: any[];
|
|
23
|
+
}
|
|
24
|
+
declare class Contents implements IEventEmitter<ContentsEvents> {
|
|
25
|
+
on: IEventEmitter<ContentsEvents>["on"];
|
|
26
|
+
off: IEventEmitter<ContentsEvents>["off"];
|
|
27
|
+
emit: IEventEmitter<ContentsEvents>["emit"];
|
|
28
|
+
__listeners: IEventEmitter<ContentsEvents>["__listeners"];
|
|
18
29
|
epubcfi: EpubCFI;
|
|
19
30
|
document: Document;
|
|
20
31
|
documentElement: HTMLElement;
|