@likecoin/epub-ts 0.4.5 → 0.4.7

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/dist/index.d.ts CHANGED
@@ -20,3 +20,13 @@ import { default as ePub } from './epub';
20
20
  export default ePub;
21
21
  export { Book, EpubCFI, Rendition, Contents, Layout, Section, Spine, Locations, Navigation, PageList, Resources, Packaging, Archive, Store, DisplayOptions, Annotations, Themes, Mapping, };
22
22
  export * from './types';
23
+ export type { BookEvents } from './book';
24
+ export type { RenditionEvents } from './rendition';
25
+ export type { AnnotationEvents } from './annotations';
26
+ export type { LocationsEvents } from './locations';
27
+ export type { LayoutEvents } from './layout';
28
+ export type { ContentsEvents } from './contents';
29
+ export type { StoreEvents } from './store';
30
+ export type { DefaultManagerEvents } from './managers/default/index';
31
+ export type { IframeViewEvents } from './managers/views/iframe';
32
+ export type { InlineViewEvents } from './managers/views/inline';
package/dist/layout.d.ts CHANGED
@@ -10,10 +10,13 @@ import { default as Section } from './section';
10
10
  * @param {number} [settings.minSpreadWidth=800]
11
11
  * @param {boolean} [settings.evenSpreads=false]
12
12
  */
13
- declare class Layout implements IEventEmitter {
14
- on: (type: string, fn: (...args: any[]) => void) => this;
15
- off: (type: string, fn?: (...args: any[]) => void) => this;
16
- emit: (type: string, ...args: unknown[]) => void;
13
+ export interface LayoutEvents extends Record<string, any[]> {
14
+ "updated": [LayoutProps, Partial<LayoutProps>];
15
+ }
16
+ declare class Layout implements IEventEmitter<LayoutEvents> {
17
+ on: IEventEmitter<LayoutEvents>["on"];
18
+ off: IEventEmitter<LayoutEvents>["off"];
19
+ emit: IEventEmitter<LayoutEvents>["emit"];
17
20
  settings: LayoutSettings;
18
21
  name: string;
19
22
  _spread: boolean;
@@ -9,10 +9,15 @@ import { default as Section } from './section';
9
9
  * @param {request} request
10
10
  * @param {number} [pause=100]
11
11
  */
12
- declare class Locations implements IEventEmitter {
13
- on: (type: string, fn: (...args: any[]) => void) => this;
14
- off: (type: string, fn?: (...args: any[]) => void) => this;
15
- emit: (type: string, ...args: unknown[]) => void;
12
+ export interface LocationsEvents extends Record<string, any[]> {
13
+ "changed": [{
14
+ percentage: number;
15
+ }];
16
+ }
17
+ declare class Locations implements IEventEmitter<LocationsEvents> {
18
+ on: IEventEmitter<LocationsEvents>["on"];
19
+ off: IEventEmitter<LocationsEvents>["off"];
20
+ emit: IEventEmitter<LocationsEvents>["emit"];
16
21
  spine: Spine | undefined;
17
22
  request: RequestFunction | undefined;
18
23
  pause: number | undefined;
@@ -7,7 +7,25 @@ import { default as Section } from '../../section';
7
7
  import { default as Contents } from '../../contents';
8
8
  import { default as IframeView } from '../views/iframe';
9
9
  import { IEventEmitter, ManagerOptions, ViewSettings, ViewLocation, RequestFunction, SizeObject, ReframeBounds, LayoutProps } from '../../types';
10
- declare class DefaultViewManager implements IEventEmitter {
10
+ export interface DefaultManagerEvents extends Record<string, any[]> {
11
+ "resize": [Section];
12
+ "resized": [{
13
+ width: number;
14
+ height: number;
15
+ }, string?];
16
+ "orientationchange": [number];
17
+ "added": [IframeView];
18
+ "scroll": [{
19
+ top: number;
20
+ left: number;
21
+ }];
22
+ "scrolled": [{
23
+ top: number;
24
+ left: number;
25
+ }];
26
+ "removed": [IframeView];
27
+ }
28
+ declare class DefaultViewManager implements IEventEmitter<DefaultManagerEvents> {
11
29
  name: string;
12
30
  optsSettings: ManagerOptions["settings"];
13
31
  View: new (section: Section, options?: ViewSettings) => IframeView;
@@ -54,10 +72,10 @@ declare class DefaultViewManager implements IEventEmitter {
54
72
  width: number;
55
73
  height: number;
56
74
  };
57
- on: IEventEmitter["on"];
58
- off: IEventEmitter["off"];
59
- emit: IEventEmitter["emit"];
60
- __listeners: IEventEmitter["__listeners"];
75
+ on: IEventEmitter<DefaultManagerEvents>["on"];
76
+ off: IEventEmitter<DefaultManagerEvents>["off"];
77
+ emit: IEventEmitter<DefaultManagerEvents>["emit"];
78
+ __listeners: IEventEmitter<DefaultManagerEvents>["__listeners"];
61
79
  constructor(options: ManagerOptions);
62
80
  render(element: HTMLElement, size: SizeObject): void;
63
81
  addEventListeners(): void;
@@ -2,7 +2,8 @@ import { IEventEmitter } from '../../types';
2
2
  import { default as DefaultViewManager } from '../default/index';
3
3
  import { default as Contents } from '../../contents';
4
4
  import { default as Layout } from '../../layout';
5
- declare class Snap implements IEventEmitter {
5
+ import { default as IframeView } from '../views/iframe';
6
+ declare class Snap implements IEventEmitter<Record<string, any[]>> {
6
7
  settings: {
7
8
  duration: number;
8
9
  minVelocity: number;
@@ -32,12 +33,10 @@ declare class Snap implements IEventEmitter {
32
33
  _onTouchStart: ((e: TouchEvent) => void) | undefined;
33
34
  _onTouchMove: ((e: TouchEvent) => void) | undefined;
34
35
  _onTouchEnd: ((e?: TouchEvent) => void) | undefined;
35
- _afterDisplayed: ((view: {
36
- contents: Contents;
37
- }) => void) | undefined;
38
- on: IEventEmitter["on"];
39
- off: IEventEmitter["off"];
40
- emit: IEventEmitter["emit"];
36
+ _afterDisplayed: ((view: IframeView) => void) | undefined;
37
+ on: IEventEmitter<Record<string, any[]>>["on"];
38
+ off: IEventEmitter<Record<string, any[]>>["off"];
39
+ emit: IEventEmitter<Record<string, any[]>>["emit"];
41
40
  constructor(manager: DefaultViewManager, options?: Record<string, unknown>);
42
41
  setup(manager: DefaultViewManager): void;
43
42
  supportsTouch(): boolean;
@@ -45,9 +44,7 @@ declare class Snap implements IEventEmitter {
45
44
  enableScroll(): void;
46
45
  addListeners(): void;
47
46
  removeListeners(): void;
48
- afterDisplayed(view: {
49
- contents: Contents;
50
- }): void;
47
+ afterDisplayed(view: IframeView): void;
51
48
  triggerViewEvent(e: TouchEvent, contents: Contents): void;
52
49
  onScroll(_e?: Event): void;
53
50
  onResize(_e?: Event): void;
@@ -4,7 +4,18 @@ import { Pane, Mark } from '../../marks-pane';
4
4
  import { IEventEmitter, ViewSettings, ReframeBounds, RequestFunction } from '../../types';
5
5
  import { default as Section } from '../../section';
6
6
  import { default as Layout } from '../../layout';
7
- declare class IframeView implements IEventEmitter {
7
+ export interface IframeViewEvents extends Record<string, any[]> {
8
+ "axis": [string];
9
+ "writingMode": [string];
10
+ "loaderror": [unknown];
11
+ "rendered": [Section];
12
+ "resized": [ReframeBounds];
13
+ "displayed": [IframeView];
14
+ "shown": [IframeView];
15
+ "hidden": [IframeView];
16
+ "markClicked": [string, object | undefined];
17
+ }
18
+ declare class IframeView implements IEventEmitter<IframeViewEvents> {
8
19
  settings: ViewSettings;
9
20
  id: string;
10
21
  section: Section;
@@ -61,10 +72,10 @@ declare class IframeView implements IEventEmitter {
61
72
  stopExpanding: boolean;
62
73
  axis: string;
63
74
  expanded?: boolean;
64
- on: IEventEmitter["on"];
65
- off: IEventEmitter["off"];
66
- emit: IEventEmitter["emit"];
67
- __listeners: IEventEmitter["__listeners"];
75
+ on: IEventEmitter<IframeViewEvents>["on"];
76
+ off: IEventEmitter<IframeViewEvents>["off"];
77
+ emit: IEventEmitter<IframeViewEvents>["emit"];
78
+ __listeners: IEventEmitter<IframeViewEvents>["__listeners"];
68
79
  constructor(section: Section, options?: ViewSettings);
69
80
  container(axis?: string): HTMLElement;
70
81
  create(): HTMLIFrameElement;
@@ -3,7 +3,18 @@ import { default as Contents } from '../../contents';
3
3
  import { default as Section } from '../../section';
4
4
  import { default as Layout } from '../../layout';
5
5
  import { IEventEmitter, ViewSettings, RequestFunction, SizeObject, ReframeBounds } from '../../types';
6
- declare class InlineView implements IEventEmitter {
6
+ export interface InlineViewEvents extends Record<string, any[]> {
7
+ "loaderror": [unknown];
8
+ "rendered": [Section];
9
+ "resized": [{
10
+ width: number;
11
+ height: number;
12
+ }];
13
+ "displayed": [InlineView];
14
+ "shown": [InlineView];
15
+ "hidden": [InlineView];
16
+ }
17
+ declare class InlineView implements IEventEmitter<InlineViewEvents> {
7
18
  settings: ViewSettings & {
8
19
  layout: Layout;
9
20
  };
@@ -37,9 +48,9 @@ declare class InlineView implements IEventEmitter {
37
48
  contents: Contents | undefined;
38
49
  rendering: boolean;
39
50
  stopExpanding: boolean;
40
- on: IEventEmitter["on"];
41
- off: IEventEmitter["off"];
42
- emit: IEventEmitter["emit"];
51
+ on: IEventEmitter<InlineViewEvents>["on"];
52
+ off: IEventEmitter<InlineViewEvents>["off"];
53
+ emit: IEventEmitter<InlineViewEvents>["emit"];
43
54
  constructor(section: Section, options?: ViewSettings);
44
55
  container(axis?: string): HTMLElement;
45
56
  create(): HTMLDivElement;
package/dist/node.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Node.js parsing-only entry point for epub.ts.
3
+ *
4
+ * Requires `linkedom` as a peer dependency to provide DOMParser
5
+ * and document globals that the parsing chain needs.
6
+ *
7
+ * Usage:
8
+ * import { Book } from "@likecoin/epub-ts/node";
9
+ * const book = new Book(buffer);
10
+ * await book.opened;
11
+ */
12
+ export { default as Book } from './book';
13
+ export { default as EpubCFI } from './epubcfi';
14
+ export { default as Container } from './container';
15
+ export { default as Packaging } from './packaging';
16
+ export { default as Navigation } from './navigation';
17
+ export { default as Spine } from './spine';
18
+ export { default as Locations } from './locations';
19
+ export { default as Section } from './section';
20
+ export { default as Archive } from './archive';
21
+ export { default as PageList } from './pagelist';
22
+ export { default as Resources } from './resources';
23
+ export { default as DisplayOptions } from './displayoptions';
24
+ export { default as Layout } from './layout';
25
+ export * from './types';
@@ -6,7 +6,7 @@ import { default as Layout } from './layout';
6
6
  import { default as Themes } from './themes';
7
7
  import { default as Contents } from './contents';
8
8
  import { default as Annotations } from './annotations';
9
- import { IEventEmitter, RenditionOptions, Location, GlobalLayout, ViewLocation, SizeObject, PackagingMetadataObject, ViewManagerConstructor, ViewConstructor } from './types';
9
+ import { IEventEmitter, RenditionOptions, Location, GlobalLayout, ViewLocation, SizeObject, PackagingMetadataObject, LayoutProps, ViewManagerConstructor, ViewConstructor } from './types';
10
10
  import { default as Book } from './book';
11
11
  import { default as Section } from './section';
12
12
  import { default as IframeView } from './managers/views/iframe';
@@ -35,6 +35,30 @@ import { default as DefaultViewManager } from './managers/default/index';
35
35
  * @param {boolean} [options.allowScriptedContent=false] enable running scripts in content
36
36
  * @param {boolean} [options.allowPopups=false] enable opening popup in content
37
37
  */
38
+ export interface RenditionEvents extends Record<string, any[]> {
39
+ "started": [];
40
+ "attached": [];
41
+ "displayed": [Section | undefined];
42
+ "displayerror": [Error];
43
+ "rendered": [Section, IframeView];
44
+ "removed": [Section, IframeView];
45
+ "resized": [{
46
+ width: number;
47
+ height: number;
48
+ }, string?];
49
+ "orientationchange": [number];
50
+ "locationChanged": [{
51
+ index: number;
52
+ href: string;
53
+ start: string;
54
+ end: string;
55
+ percentage: number | undefined;
56
+ }];
57
+ "relocated": [Location];
58
+ "markClicked": [string, object | undefined, Contents];
59
+ "selected": [string, Contents];
60
+ "layout": [LayoutProps, Partial<LayoutProps>];
61
+ }
38
62
  interface RenditionHooks {
39
63
  display: Hook;
40
64
  serialize: Hook;
@@ -44,7 +68,7 @@ interface RenditionHooks {
44
68
  render: Hook;
45
69
  show: Hook;
46
70
  }
47
- declare class Rendition implements IEventEmitter {
71
+ declare class Rendition implements IEventEmitter<RenditionEvents> {
48
72
  settings: RenditionOptions;
49
73
  book: Book;
50
74
  hooks: RenditionHooks;
@@ -55,14 +79,14 @@ declare class Rendition implements IEventEmitter {
55
79
  location: Location | undefined;
56
80
  starting: defer<void>;
57
81
  started: Promise<void>;
58
- manager: DefaultViewManager | undefined;
82
+ manager: DefaultViewManager;
59
83
  ViewManager: ViewManagerConstructor;
60
84
  View: ViewConstructor;
61
85
  _layout: Layout | undefined;
62
86
  displaying: defer<Section | undefined> | undefined;
63
- on: IEventEmitter["on"];
64
- off: IEventEmitter["off"];
65
- emit: IEventEmitter["emit"];
87
+ on: IEventEmitter<RenditionEvents>["on"];
88
+ off: IEventEmitter<RenditionEvents>["off"];
89
+ emit: IEventEmitter<RenditionEvents>["emit"];
66
90
  constructor(book: Book, options?: RenditionOptions);
67
91
  /**
68
92
  * Set the manager function
@@ -130,7 +154,7 @@ declare class Rendition implements IEventEmitter {
130
154
  * Report orientation events and display the last seen location
131
155
  * @private
132
156
  */
133
- onOrientationChange(orientation: string): void;
157
+ onOrientationChange(orientation: number): void;
134
158
  /**
135
159
  * Move the Rendition to a specific offset
136
160
  * Usually you would be better off calling display()
@@ -234,7 +258,7 @@ declare class Rendition implements IEventEmitter {
234
258
  * @private
235
259
  * @param {EpubCFI} cfirange
236
260
  */
237
- triggerMarkEvent(cfiRange: string, data: object, contents: Contents): void;
261
+ triggerMarkEvent(cfiRange: string, data: object | undefined, contents: Contents): void;
238
262
  /**
239
263
  * Get a Range from a Visible CFI
240
264
  * @param {string} cfi EpubCfi String
@@ -15,15 +15,15 @@ declare class Resources {
15
15
  archive: Archive;
16
16
  resolver: (href: string, absolute?: boolean) => string;
17
17
  request: RequestFunction;
18
- } | undefined;
19
- manifest: PackagingManifestObject | undefined;
20
- resources: PackagingManifestItem[] | undefined;
21
- replacementUrls: string[] | undefined;
22
- html: PackagingManifestItem[] | undefined;
23
- assets: PackagingManifestItem[] | undefined;
24
- css: PackagingManifestItem[] | undefined;
25
- urls: string[] | undefined;
26
- cssUrls: string[] | undefined;
18
+ };
19
+ manifest: PackagingManifestObject;
20
+ resources: PackagingManifestItem[];
21
+ replacementUrls: string[];
22
+ html: PackagingManifestItem[];
23
+ assets: PackagingManifestItem[];
24
+ css: PackagingManifestItem[];
25
+ urls: string[];
26
+ cssUrls: string[];
27
27
  constructor(manifest: PackagingManifestObject, options?: {
28
28
  replacements?: string;
29
29
  archive?: Archive;
package/dist/store.d.ts CHANGED
@@ -10,10 +10,14 @@ interface SimpleStorage {
10
10
  * @param {function} [requester]
11
11
  * @param {function} [resolver]
12
12
  */
13
- declare class Store implements IEventEmitter {
14
- on: (type: string, fn: (...args: any[]) => void) => this;
15
- off: (type: string, fn?: (...args: any[]) => void) => this;
16
- emit: (type: string, ...args: unknown[]) => void;
13
+ export interface StoreEvents extends Record<string, any[]> {
14
+ "online": [Store];
15
+ "offline": [Store];
16
+ }
17
+ declare class Store implements IEventEmitter<StoreEvents> {
18
+ on: IEventEmitter<StoreEvents>["on"];
19
+ off: IEventEmitter<StoreEvents>["off"];
20
+ emit: IEventEmitter<StoreEvents>["emit"];
17
21
  urlCache: Record<string, string>;
18
22
  storage: SimpleStorage;
19
23
  name: string;
package/dist/types.d.ts CHANGED
@@ -6,10 +6,11 @@ export interface Deferred<T = unknown> {
6
6
  reject: (reason?: unknown) => void;
7
7
  promise: Promise<T>;
8
8
  }
9
- export interface IEventEmitter {
10
- on(type: string, fn: (...args: any[]) => void): unknown;
11
- off(type: string, fn?: (...args: any[]) => void): unknown;
12
- emit(type: string, ...args: unknown[]): void;
9
+ export type EventMap = Record<string, any[]>;
10
+ export interface IEventEmitter<E extends EventMap = Record<string, any[]>> {
11
+ on<K extends keyof E & string>(type: K, fn: (...args: E[K]) => void): void;
12
+ off<K extends keyof E & string>(type: K, fn?: (...args: E[K]) => void): void;
13
+ emit<K extends keyof E & string>(type: K, ...args: E[K]): void;
13
14
  __listeners?: Record<string, Array<(...args: any[]) => void>>;
14
15
  }
15
16
  export interface PackagingMetadataObject {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likecoin/epub-ts",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "TypeScript EPUB parser and renderer, forked from epubjs",
5
5
  "keywords": [
6
6
  "epub",
@@ -20,15 +20,23 @@
20
20
  "types": "./dist/index.d.ts",
21
21
  "import": "./dist/epub.js",
22
22
  "require": "./dist/epub.cjs"
23
+ },
24
+ "./node": {
25
+ "types": "./dist/node.d.ts",
26
+ "import": "./dist/epub.node.js",
27
+ "require": "./dist/epub.node.cjs"
23
28
  }
24
29
  },
25
- "sideEffects": false,
30
+ "sideEffects": [
31
+ "dist/epub.node.js",
32
+ "dist/epub.node.cjs"
33
+ ],
26
34
  "files": [
27
35
  "dist"
28
36
  ],
29
37
  "repository": "https://github.com/likecoin/epub.ts",
30
38
  "scripts": {
31
- "build": "vite build",
39
+ "build": "vite build && vite build --config vite.config.node.ts",
32
40
  "test": "vitest run",
33
41
  "test:watch": "vitest",
34
42
  "typecheck": "tsc --noEmit",
@@ -49,7 +57,9 @@
49
57
  "devDependencies": {
50
58
  "@eslint/js": "^9.39.2",
51
59
  "eslint": "^9.39.2",
60
+ "fake-indexeddb": "^6.2.5",
52
61
  "jsdom": "^28.0.0",
62
+ "linkedom": "^0.18.0",
53
63
  "typedoc": "^0.28.16",
54
64
  "typedoc-plugin-markdown": "^4.10.0",
55
65
  "typescript": "^5.7.3",
@@ -58,6 +68,14 @@
58
68
  "vite-plugin-dts": "^4.5.4",
59
69
  "vitest": "^3.0.5"
60
70
  },
71
+ "peerDependencies": {
72
+ "linkedom": ">=0.16.0"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "linkedom": {
76
+ "optional": true
77
+ }
78
+ },
61
79
  "dependencies": {
62
80
  "jszip": "^3.10.1"
63
81
  }