@likecoin/epub-ts 0.3.96 → 0.4.0

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
@@ -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
- 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.
5
+ [![CI](https://github.com/likecoin/epub.ts/actions/workflows/ci.yml/badge.svg)](https://github.com/likecoin/epub.ts/actions/workflows/ci.yml)
6
+ [![npm](https://img.shields.io/npm/v/%40likecoin%2Fepub-ts)](https://www.npmjs.com/package/@likecoin/epub-ts)
7
+ [![License](https://img.shields.io/npm/l/%40likecoin%2Fepub-ts)](./LICENSE)
6
8
 
7
- ## Install
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** — only 1 runtime dependency (`jszip`); removed `core-js`, `lodash`, `path-webpack`, `event-emitter`, `localforage`, `@xmldom/xmldom`
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
- ```js
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
- This is a drop-in replacement. Change your import:
54
+ Drop-in replacement. Change your import:
27
55
 
28
56
  ```diff
29
57
  - import ePub from "epubjs";
@@ -35,30 +63,110 @@ All APIs remain the same.
35
63
  ## Named Exports
36
64
 
37
65
  ```js
38
- import { Book, EpubCFI, Rendition, Contents, Layout } from "@likecoin/epub-ts";
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
- ## What's Changed
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 | 1 (`jszip`) | 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 (incremental conversion)
46
- - Removed dependencies: `core-js`, `lodash`, `path-webpack`
116
+ - Source: JavaScript → TypeScript (full strict mode)
117
+ - Removed dependencies: `core-js`, `lodash`, `path-webpack`, `localforage`, `@xmldom/xmldom`
47
118
  - Replaced `event-emitter` with inline typed emitter
119
+ - Replaced `localforage` with native IndexedDB wrapper
120
+ - Replaced `@xmldom/xmldom` with native DOMParser/XMLSerializer
121
+ - Dropped IE8–IE11 support
48
122
 
49
123
  ## Development
50
124
 
125
+ ### Prerequisites
126
+
127
+ - Node.js 18+
128
+ - npm 9+
129
+
130
+ ### Setup
131
+
51
132
  ```bash
133
+ git clone https://github.com/likecoin/epub.ts.git
134
+ cd epub.ts
52
135
  npm install
53
- npm run build # Vite library build → dist/
54
- npm test # Vitest
55
- npm run typecheck # tsc --noEmit
56
136
  ```
57
137
 
138
+ ### Scripts
139
+
140
+ | Script | Description |
141
+ |--------|-------------|
142
+ | `npm run build` | Vite library build → `dist/` |
143
+ | `npm test` | Run tests (Vitest) |
144
+ | `npm run test:watch` | Run tests in watch mode |
145
+ | `npm run typecheck` | TypeScript type checking (`tsc --noEmit`) |
146
+ | `npm run lint` | ESLint |
147
+ | `npm run lint:fix` | ESLint with auto-fix |
148
+ | `npm run docs` | Generate API docs (HTML + Markdown) |
149
+
58
150
  ## Contributing
59
151
 
60
152
  See [PROJECT_STATUS.md](./PROJECT_STATUS.md) for current conversion progress and what to work on.
61
153
 
154
+ For AI agents contributing to this project, see [AGENTS.md](./AGENTS.md).
155
+
62
156
  ## License
63
157
 
64
- BSD-2-Clause (same as epubjs)
158
+ [BSD-2-Clause](./LICENSE) (same as epubjs)
159
+
160
+ ## Acknowledgments
161
+
162
+ - [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
163
+ - [jszip](https://github.com/Stuk/jszip) — ZIP file handling
164
+
165
+ ## Built by 3ook.com
166
+
167
+ 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.
168
+
169
+ ## Related Projects
170
+
171
+ - [epubjs](https://github.com/futurepress/epub.js) — Original EPUB reader library
172
+ - [epubcheck-ts](https://github.com/likecoin/epubcheck-ts) — TypeScript EPUB validator (also by 3ook.com)
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 {string} url
55
- * @param {string} [encoding]
56
- * @return {string}
54
+ * @param url
55
+ * @param _encoding
56
+ * @return text content
57
57
  */
58
58
  getText(url: string, _encoding?: string): Promise<string> | undefined;
59
59
  /**
@@ -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
  /**
@@ -36,13 +37,18 @@ declare class Contents implements IEventEmitter {
36
37
  _resizeCheck: (() => void) | undefined;
37
38
  _triggerEvent: ((e: Event) => void) | undefined;
38
39
  _onSelectionChange: ((e: Event) => void) | undefined;
40
+ _onVisibilityChange: (() => void) | undefined;
41
+ _mediaQueryHandlers: {
42
+ mql: MediaQueryList;
43
+ handler: (e: MediaQueryListEvent) => void;
44
+ }[];
39
45
  selectionEndTimeout: ReturnType<typeof setTimeout> | undefined;
40
46
  _layoutStyle: string;
41
47
  constructor(doc: Document, content?: HTMLElement, cfiBase?: string, sectionIndex?: number);
42
48
  /**
43
49
  * Get DOM events that are listened for and passed along
44
50
  */
45
- static get listenedEvents(): readonly ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "mousemove", "click", "touchend", "touchstart", "touchmove"];
51
+ static get listenedEvents(): typeof DOM_EVENTS;
46
52
  /**
47
53
  * Get or Set width
48
54
  * @param {number} [w]
@@ -230,7 +236,7 @@ declare class Contents implements IEventEmitter {
230
236
  addClass(className: string): void;
231
237
  /**
232
238
  * Remove a class from the contents container
233
- * @param {string} removeClass
239
+ * @param className - class name to remove
234
240
  */
235
241
  removeClass(className: string): void;
236
242
  /**
@@ -289,7 +295,6 @@ declare class Contents implements IEventEmitter {
289
295
  * @returns {EpubCFI} cfi
290
296
  */
291
297
  cfiFromNode(node: Node, ignoreClass?: string): string;
292
- map(layout: LayoutProps): EpubCFIPair[];
293
298
  /**
294
299
  * Size the contents to a given width and height
295
300
  * @param {number} [width]