@likecoin/epub-ts 0.4.3 → 0.4.4

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/layout.d.ts CHANGED
@@ -13,7 +13,7 @@ import { default as Section } from './section';
13
13
  declare class Layout implements IEventEmitter {
14
14
  on: (type: string, fn: (...args: any[]) => void) => this;
15
15
  off: (type: string, fn?: (...args: any[]) => void) => this;
16
- emit: (type: string, ...args: any[]) => void;
16
+ emit: (type: string, ...args: unknown[]) => void;
17
17
  settings: LayoutSettings;
18
18
  name: string;
19
19
  _spread: boolean;
@@ -12,7 +12,7 @@ import { default as Section } from './section';
12
12
  declare class Locations implements IEventEmitter {
13
13
  on: (type: string, fn: (...args: any[]) => void) => this;
14
14
  off: (type: string, fn?: (...args: any[]) => void) => this;
15
- emit: (type: string, ...args: any[]) => void;
15
+ emit: (type: string, ...args: unknown[]) => void;
16
16
  spine: Spine | undefined;
17
17
  request: RequestFunction | undefined;
18
18
  pause: number | undefined;
@@ -18,7 +18,7 @@ declare class ContinuousViewManager extends DefaultViewManager {
18
18
  trimTimeout: ReturnType<typeof setTimeout>;
19
19
  constructor(options: ManagerOptions);
20
20
  display(section: Section, target?: string): Promise<any>;
21
- fill(_full?: InstanceType<typeof defer>): Promise<any>;
21
+ fill(_full?: defer<void>): Promise<void>;
22
22
  moveTo(offset: {
23
23
  left: number;
24
24
  top: number;
@@ -9,7 +9,7 @@ import { default as IframeView } from '../views/iframe';
9
9
  import { IEventEmitter, ManagerOptions, ViewSettings, ViewLocation, RequestFunction, SizeObject, ReframeBounds, LayoutProps } from '../../types';
10
10
  declare class DefaultViewManager implements IEventEmitter {
11
11
  name: string;
12
- optsSettings: ManagerOptions;
12
+ optsSettings: ManagerOptions["settings"];
13
13
  View: new (section: Section, options?: ViewSettings) => IframeView;
14
14
  request: RequestFunction;
15
15
  renditionQueue: Queue;
@@ -75,8 +75,8 @@ declare class IframeView implements IEventEmitter {
75
75
  reframe(width: number, height: number): void;
76
76
  load(contents: string): Promise<Contents>;
77
77
  onLoad(event: Event, promise: {
78
- resolve: (value?: any) => void;
79
- reject: (reason?: any) => void;
78
+ resolve: (value: Contents | PromiseLike<Contents>) => void;
79
+ reject: (reason?: unknown) => void;
80
80
  }): void;
81
81
  setLayout(layout: Layout): void;
82
82
  setAxis(axis: string): void;
@@ -1,8 +1,14 @@
1
- import { IEventEmitter, ViewSettings } from '../../types';
1
+ import { default as EpubCFI } from '../../epubcfi';
2
+ import { default as Contents } from '../../contents';
3
+ import { default as Section } from '../../section';
4
+ import { default as Layout } from '../../layout';
5
+ import { IEventEmitter, ViewSettings, RequestFunction, SizeObject, ReframeBounds } from '../../types';
2
6
  declare class InlineView implements IEventEmitter {
3
- settings: any;
7
+ settings: ViewSettings & {
8
+ layout: Layout;
9
+ };
4
10
  id: string;
5
- section: any;
11
+ section: Section;
6
12
  index: number;
7
13
  element: HTMLElement;
8
14
  added: boolean;
@@ -12,8 +18,8 @@ declare class InlineView implements IEventEmitter {
12
18
  height: number;
13
19
  fixedWidth: number;
14
20
  fixedHeight: number;
15
- epubcfi: any;
16
- layout: any;
21
+ epubcfi: EpubCFI;
22
+ layout: Layout;
17
23
  frame: HTMLDivElement | undefined;
18
24
  resizing: boolean;
19
25
  _width: number | undefined;
@@ -22,44 +28,44 @@ declare class InlineView implements IEventEmitter {
22
28
  _textHeight: number | undefined;
23
29
  _needsReframe: boolean;
24
30
  _expanding: boolean;
25
- elementBounds: any;
26
- prevBounds: any;
31
+ elementBounds: SizeObject | undefined;
32
+ prevBounds: SizeObject | undefined;
27
33
  lockedWidth: number;
28
34
  lockedHeight: number;
29
35
  document: Document;
30
36
  window: Window;
31
- contents: any;
37
+ contents: Contents | undefined;
32
38
  rendering: boolean;
33
39
  stopExpanding: boolean;
34
40
  on: IEventEmitter["on"];
35
41
  off: IEventEmitter["off"];
36
42
  emit: IEventEmitter["emit"];
37
- constructor(section: any, options?: ViewSettings);
43
+ constructor(section: Section, options?: ViewSettings);
38
44
  container(axis?: string): HTMLElement;
39
45
  create(): HTMLDivElement;
40
- render(request: any, show?: boolean): Promise<any>;
46
+ render(request: RequestFunction, show?: boolean): Promise<void>;
41
47
  size(_width?: number, _height?: number): void;
42
48
  lock(what: string, width: number, height: number): void;
43
49
  expand(_force?: boolean): void;
44
50
  contentWidth(_min?: number): number;
45
51
  contentHeight(_min?: number): number;
46
- resize(width: any, height: any): void;
47
- load(contents: string): Promise<any>;
48
- setLayout(layout: any): void;
52
+ resize(width: number | false, height: number | false): void;
53
+ load(contents: string): Promise<Contents>;
54
+ setLayout(layout: Layout): void;
49
55
  resizeListenters(): void;
50
56
  addListeners(): void;
51
- removeListeners(_layoutFunc?: any): void;
52
- display(request: any): Promise<any>;
57
+ removeListeners(): void;
58
+ display(request: RequestFunction): Promise<InlineView>;
53
59
  show(): void;
54
60
  hide(): void;
55
61
  position(): DOMRect;
56
- locationOf(target: any): {
62
+ locationOf(target: string): {
57
63
  left: number;
58
64
  top: number;
59
65
  };
60
- onDisplayed(_view: any): void;
61
- onResize(_view: any, _e?: any): void;
62
- bounds(): any;
66
+ onDisplayed(_view: InlineView): void;
67
+ onResize(_view: InlineView, _e?: ReframeBounds): void;
68
+ bounds(): SizeObject;
63
69
  destroy(): void;
64
70
  }
65
71
  export default InlineView;
@@ -46,7 +46,7 @@ interface RenditionHooks {
46
46
  show: Hook;
47
47
  }
48
48
  declare class Rendition implements IEventEmitter {
49
- settings: RenditionOptions & Record<string, any>;
49
+ settings: RenditionOptions;
50
50
  book: Book | undefined;
51
51
  hooks: RenditionHooks;
52
52
  themes: Themes;
@@ -54,13 +54,13 @@ declare class Rendition implements IEventEmitter {
54
54
  epubcfi: EpubCFI;
55
55
  q: Queue;
56
56
  location: Location | undefined;
57
- starting: defer;
57
+ starting: defer<void>;
58
58
  started: Promise<void>;
59
59
  manager: DefaultViewManager | undefined;
60
60
  ViewManager: typeof DefaultViewManager | typeof ContinuousViewManager | Function;
61
61
  View: typeof IframeView | Function;
62
62
  _layout: Layout | undefined;
63
- displaying: defer | undefined;
63
+ displaying: defer<Section | undefined> | undefined;
64
64
  on: IEventEmitter["on"];
65
65
  off: IEventEmitter["off"];
66
66
  emit: IEventEmitter["emit"];
@@ -109,7 +109,7 @@ declare class Rendition implements IEventEmitter {
109
109
  * @param {string} target Url or EpubCFI
110
110
  * @return {Promise}
111
111
  */
112
- _display(target?: string | number): Promise<Section> | undefined;
112
+ _display(target?: string | number): Promise<Section | undefined> | undefined;
113
113
  /**
114
114
  * Report what section has been displayed
115
115
  * @private
@@ -168,7 +168,7 @@ declare class Rendition implements IEventEmitter {
168
168
  * @param {object} metadata
169
169
  * @return {object} properties
170
170
  */
171
- determineLayoutProperties(metadata: PackagingMetadataObject & Record<string, any>): GlobalLayout;
171
+ determineLayoutProperties(metadata: PackagingMetadataObject): GlobalLayout;
172
172
  /**
173
173
  * Adjust the flow of the rendition to paginated or scrolled
174
174
  * (scrolled-continuous vs scrolled-doc are handled by different view managers)
package/dist/spine.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { default as EpubCFI } from './epubcfi';
2
2
  import { default as Hook } from './utils/hook';
3
3
  import { default as Section } from './section';
4
- import { PackagingManifestObject, PackagingObject, SpineItem } from './types';
4
+ import { default as Packaging } from './packaging';
5
+ import { PackagingManifestObject, SpineItem } from './types';
5
6
  /**
6
7
  * A collection of Spine Items
7
8
  */
@@ -27,7 +28,7 @@ declare class Spine {
27
28
  * @param {method} resolver URL resolver
28
29
  * @param {method} canonical Resolve canonical url
29
30
  */
30
- unpack(_package: PackagingObject & {
31
+ unpack(_package: Packaging & {
31
32
  baseUrl?: string;
32
33
  basePath?: string;
33
34
  }, resolver: (href: string, absolute?: boolean) => string, canonical: (href: string) => string): void;
package/dist/store.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IEventEmitter, RequestFunction } from './types';
2
2
  interface SimpleStorage {
3
- getItem(key: string): Promise<any>;
4
- setItem(key: string, value: any): Promise<any>;
3
+ getItem(key: string): Promise<Uint8Array | null>;
4
+ setItem(key: string, value: Uint8Array): Promise<Uint8Array>;
5
5
  }
6
6
  /**
7
7
  * Handles saving and requesting files from local storage
@@ -13,7 +13,7 @@ interface SimpleStorage {
13
13
  declare class Store implements IEventEmitter {
14
14
  on: (type: string, fn: (...args: any[]) => void) => this;
15
15
  off: (type: string, fn?: (...args: any[]) => void) => this;
16
- emit: (type: string, ...args: any[]) => void;
16
+ emit: (type: string, ...args: unknown[]) => void;
17
17
  urlCache: Record<string, string>;
18
18
  storage: SimpleStorage;
19
19
  name: string;
@@ -52,7 +52,7 @@ declare class Store implements IEventEmitter {
52
52
  resources: Array<{
53
53
  href: string;
54
54
  }>;
55
- }, force?: boolean): Promise<any[]>;
55
+ }, force?: boolean): Promise<(Uint8Array | null)[]>;
56
56
  /**
57
57
  * Put binary data from a url to storage
58
58
  * @param {string} url a url to request from storage
@@ -60,7 +60,7 @@ declare class Store implements IEventEmitter {
60
60
  * @param {object} [headers]
61
61
  * @return {Promise<Blob>}
62
62
  */
63
- put(url: string, withCredentials?: boolean, headers?: Record<string, string>): Promise<any>;
63
+ put(url: string, withCredentials?: boolean, headers?: Record<string, string>): Promise<Uint8Array | null>;
64
64
  /**
65
65
  * Request a url
66
66
  * @param {string} url a url to request from storage
@@ -69,22 +69,22 @@ declare class Store implements IEventEmitter {
69
69
  * @param {object} [headers]
70
70
  * @return {Promise<Blob | string | JSON | Document | XMLDocument>}
71
71
  */
72
- request(url: string, type?: string, withCredentials?: boolean, headers?: Record<string, string>): Promise<any>;
72
+ request(url: string, type?: string, withCredentials?: boolean, headers?: Record<string, string>): Promise<unknown>;
73
73
  /**
74
74
  * Request a url from storage
75
75
  * @param {string} url a url to request from storage
76
76
  * @param {string} [type] specify the type of the returned result
77
77
  * @return {Promise<Blob | string | JSON | Document | XMLDocument>}
78
78
  */
79
- retrieve(url: string, type?: string): Promise<any>;
79
+ retrieve(url: string, type?: string): Promise<unknown>;
80
80
  /**
81
81
  * Handle the response from request
82
82
  * @private
83
- * @param {any} response
83
+ * @param {string | Blob} response
84
84
  * @param {string} [type]
85
- * @return {any} the parsed result
85
+ * @return {string | Document | Blob | object} the parsed result
86
86
  */
87
- handleResponse(response: any, type?: string): any;
87
+ handleResponse(response: string | Blob, type?: string): string | Document | Blob | object;
88
88
  /**
89
89
  * Get a Blob from Storage by Url
90
90
  * @param {string} url
package/dist/types.d.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import { default as Section } from './section';
2
- export interface Deferred<T = any> {
2
+ import { default as Queue } from './utils/queue';
3
+ export interface Deferred<T = unknown> {
3
4
  id: string;
4
- resolve: (value?: T | PromiseLike<T>) => void;
5
- reject: (reason?: any) => void;
5
+ resolve: (value: T | PromiseLike<T>) => void;
6
+ reject: (reason?: unknown) => void;
6
7
  promise: Promise<T>;
7
8
  }
8
9
  export interface IEventEmitter {
9
- on(type: string, fn: (...args: any[]) => void): any;
10
- off(type: string, fn?: (...args: any[]) => void): any;
11
- emit(type: string, ...args: any[]): void;
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;
12
13
  __listeners?: Record<string, Array<(...args: any[]) => void>>;
13
14
  }
14
15
  export interface PackagingMetadataObject {
@@ -28,6 +29,7 @@ export interface PackagingMetadataObject {
28
29
  media_active_class: string;
29
30
  spread: string;
30
31
  direction: string;
32
+ minSpreadWidth?: number;
31
33
  }
32
34
  export interface PackagingSpineItem {
33
35
  id?: string;
@@ -115,6 +117,10 @@ export interface RenditionOptions {
115
117
  defaultDirection?: string;
116
118
  allowScriptedContent?: boolean;
117
119
  allowPopups?: boolean;
120
+ globalLayoutProperties?: GlobalLayout;
121
+ direction?: string;
122
+ orientation?: string;
123
+ gap?: number;
118
124
  }
119
125
  export interface DisplayedLocation {
120
126
  index: number;
@@ -184,7 +190,7 @@ export interface EpubCFIComponent {
184
190
  assertion: string | null;
185
191
  };
186
192
  }
187
- export type RequestFunction = (url: string, type?: string, withCredentials?: boolean, headers?: Record<string, string>) => Promise<any>;
193
+ export type RequestFunction = (url: string, type?: string, withCredentials?: boolean, headers?: Record<string, string>) => Promise<unknown>;
188
194
  export interface SizeObject {
189
195
  width: number;
190
196
  height: number;
@@ -229,10 +235,18 @@ export interface ManagerOptions extends ViewSettings {
229
235
  snap?: boolean | object;
230
236
  view?: string | Function | object;
231
237
  request?: RequestFunction;
232
- [key: string]: any;
238
+ size?: SizeObject;
239
+ rtlScrollType?: string;
240
+ offset?: number;
241
+ afterScrolledTimeout?: number;
242
+ gap?: number;
243
+ offsetDelta?: number;
244
+ resizeOnOrientationChange?: boolean;
245
+ queue?: Queue;
246
+ settings?: RenditionOptions;
233
247
  }
234
248
  export interface HooksObject {
235
- [key: string]: any;
249
+ [key: string]: unknown;
236
250
  }
237
251
  export interface StageOptions {
238
252
  width?: number | string;
@@ -265,3 +279,9 @@ export interface ParsedPath {
265
279
  ext: string;
266
280
  name: string;
267
281
  }
282
+ declare global {
283
+ interface Window {
284
+ webkitURL?: typeof URL;
285
+ mozURL?: typeof URL;
286
+ }
287
+ }
@@ -52,14 +52,14 @@ export declare function prefixed(unprefixed: string): string;
52
52
  * @returns {object}
53
53
  * @memberof Core
54
54
  */
55
- export declare function defaults(obj: any, ...sources: any[]): any;
55
+ export declare function defaults<T extends object>(obj: T, ...sources: object[]): T;
56
56
  /**
57
57
  * Extend properties of an object
58
58
  * @param {object} target
59
59
  * @returns {object}
60
60
  * @memberof Core
61
61
  */
62
- export declare function extend(target: any, ...sources: any[]): any;
62
+ export declare function extend<T extends object>(target: T, ...sources: (object | null | undefined)[]): T;
63
63
  /**
64
64
  * Fast quicksort insert for sorted array -- based on:
65
65
  * http://stackoverflow.com/questions/1344500/efficient-way-to-insert-a-number-into-a-sorted-array-of-numbers
@@ -69,7 +69,7 @@ export declare function extend(target: any, ...sources: any[]): any;
69
69
  * @returns {number} location (in array)
70
70
  * @memberof Core
71
71
  */
72
- export declare function insert(item: any, array: any[], compareFunction?: (a: any, b: any) => number): number;
72
+ export declare function insert<T>(item: T, array: T[], compareFunction?: (a: T, b: T) => number): number;
73
73
  /**
74
74
  * Finds where something would fit into a sorted array
75
75
  * @param {any} item
@@ -80,7 +80,7 @@ export declare function insert(item: any, array: any[], compareFunction?: (a: an
80
80
  * @returns {number} location (in array)
81
81
  * @memberof Core
82
82
  */
83
- export declare function locationOf(item: any, array: any[], compareFunction?: (a: any, b: any) => number, _start?: number, _end?: number): number;
83
+ export declare function locationOf<T>(item: T, array: T[], compareFunction?: (a: T, b: T) => number, _start?: number, _end?: number): number;
84
84
  /**
85
85
  * Finds index of something in a sorted array
86
86
  * Returns -1 if not found
@@ -92,7 +92,7 @@ export declare function locationOf(item: any, array: any[], compareFunction?: (a
92
92
  * @returns {number} index (in array) or -1
93
93
  * @memberof Core
94
94
  */
95
- export declare function indexOfSorted(item: any, array: any[], compareFunction?: (a: any, b: any) => number, _start?: number, _end?: number): number;
95
+ export declare function indexOfSorted<T>(item: T, array: T[], compareFunction?: (a: T, b: T) => number, _start?: number, _end?: number): number;
96
96
  /**
97
97
  * Find the bounds of an element
98
98
  * taking padding and margin into account
@@ -217,7 +217,7 @@ export declare function parse(markup: string, mime: string): Document;
217
217
  * @returns {element} element
218
218
  * @memberof Core
219
219
  */
220
- export declare function qs(el: Document | Element, sel: string): Element | undefined;
220
+ export declare function qs(el: Document | Element, sel: string): Element | null;
221
221
  /**
222
222
  * querySelectorAll wrapper
223
223
  * @param {element} el
@@ -267,11 +267,11 @@ export declare function blob2base64(blob: Blob): Promise<string | ArrayBuffer>;
267
267
  * Creates a new pending promise and provides methods to resolve or reject it.
268
268
  * From: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm/Deferred#backwards_forwards_compatible
269
269
  */
270
- export declare class defer {
270
+ export declare class defer<T = unknown> {
271
271
  id: string;
272
- resolve: (value?: any) => void;
273
- reject: (reason?: any) => void;
274
- promise: Promise<any>;
272
+ resolve: (value: T | PromiseLike<T>) => void;
273
+ reject: (reason?: unknown) => void;
274
+ promise: Promise<T>;
275
275
  constructor();
276
276
  }
277
277
  /**
@@ -3,4 +3,4 @@
3
3
  * Drop-in replacement for the "event-emitter" npm package.
4
4
  * Supports on(type, fn), off(type, fn), emit(type, ...args).
5
5
  */
6
- export default function EventEmitter(target: any): any;
6
+ export default function EventEmitter(target: object): object;
@@ -1,37 +1,45 @@
1
+ import { defer } from './core';
2
+ interface QueueItem {
3
+ task?: (...args: unknown[]) => unknown;
4
+ args: unknown[];
5
+ deferred?: defer<unknown>;
6
+ promise: Promise<unknown>;
7
+ }
1
8
  /**
2
9
  * Queue for handling tasks one at a time
3
10
  * @class
4
11
  * @param {scope} context what this will resolve to in the tasks
5
12
  */
6
13
  declare class Queue {
7
- _q: any[];
8
- context: any;
9
- tick: any;
10
- running: any;
14
+ _q: QueueItem[];
15
+ context: object | undefined;
16
+ tick: ((cb: FrameRequestCallback) => number) | false;
17
+ running: boolean | Promise<void> | undefined;
11
18
  paused: boolean;
12
- defered: any;
13
- constructor(context: any);
19
+ defered: defer<void> | undefined;
20
+ constructor(context?: object);
14
21
  /**
15
22
  * Add an item to the queue
16
23
  * @return {Promise}
17
24
  */
18
- enqueue(..._args: any[]): Promise<any>;
25
+ enqueue<R>(promise: Promise<R>): Promise<R>;
26
+ enqueue<A extends unknown[], R>(task: (...args: A) => R, ...args: A): Promise<Awaited<R>>;
19
27
  /**
20
28
  * Run one item
21
29
  * @return {Promise}
22
30
  */
23
- dequeue(): any;
31
+ dequeue(): Promise<unknown> | undefined;
24
32
  dump(): void;
25
33
  /**
26
34
  * Run all tasks sequentially, at convince
27
35
  * @return {Promise}
28
36
  */
29
- run(): Promise<any>;
37
+ run(): Promise<void>;
30
38
  /**
31
39
  * Flush all, as quickly as possible
32
40
  * @return {Promise}
33
41
  */
34
- flush(): any;
42
+ flush(): Promise<void> | undefined;
35
43
  /**
36
44
  * Clear all items in wait
37
45
  */
@@ -60,7 +68,7 @@ declare class Queue {
60
68
  * @return {function} task
61
69
  */
62
70
  declare class Task {
63
- constructor(task: Function, args: any[], context: any);
71
+ constructor(task: (...args: unknown[]) => void, args: unknown[], context?: object);
64
72
  }
65
73
  export default Queue;
66
74
  export { Task };
@@ -1,2 +1,2 @@
1
- declare function request(url: string, type?: string, withCredentials?: boolean, headers?: Record<string, string>): Promise<any>;
1
+ declare function request(url: string, type?: string, withCredentials?: boolean, headers?: Record<string, string>): Promise<unknown>;
2
2
  export default request;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likecoin/epub-ts",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "TypeScript EPUB parser and renderer, forked from epubjs",
5
5
  "keywords": [
6
6
  "epub",