@d-i-t-a/reader 3.0.0-alpha.13 → 3.0.0-alpha.15
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/esm/index.js +4521 -879
- package/dist/esm/index.js.map +4 -4
- package/dist/reader.js +71 -69
- package/dist/reader.js.map +4 -4
- package/dist/types/fetcher/BlobUrlManager.d.ts +91 -0
- package/dist/types/fetcher/CacheFetcher.d.ts +36 -0
- package/dist/types/fetcher/Container.d.ts +21 -0
- package/dist/types/fetcher/ContentFetcher.d.ts +32 -0
- package/dist/types/fetcher/EpubParser.d.ts +48 -0
- package/dist/types/fetcher/Fetcher.d.ts +111 -0
- package/dist/types/fetcher/FontDeobfuscator.d.ts +65 -0
- package/dist/types/fetcher/HttpFetcher.d.ts +31 -0
- package/dist/types/fetcher/ReadError.d.ts +35 -0
- package/dist/types/fetcher/TransformingFetcher.d.ts +38 -0
- package/dist/types/fetcher/ZipContainer.d.ts +16 -0
- package/dist/types/fetcher/ZipFetcher.d.ts +51 -0
- package/dist/types/fetcher/mediaType.d.ts +5 -0
- package/dist/types/fetcher/types.d.ts +27 -0
- package/dist/types/index.d.ts +20 -1
- package/dist/types/model/v3/Publication.d.ts +4 -4
- package/dist/types/modules/ModuleHost.d.ts +1 -0
- package/dist/types/modules/epub/search/SearchModule.d.ts +0 -1
- package/dist/types/navigator/EpubNavigator.d.ts +83 -9
- package/dist/types/navigator/PDFNavigator.d.ts +2 -4
- package/dist/types/navigator/VisualNavigator.d.ts +1 -1
- package/dist/types/types/pdfjs-workarounds.d.ts +1 -13
- package/dist/types/utils/Events.d.ts +10 -0
- package/package.json +2 -1
|
@@ -17,6 +17,7 @@ export interface ModuleHost {
|
|
|
17
17
|
readonly settings: UserSettings;
|
|
18
18
|
readonly rights: Partial<ReaderRights>;
|
|
19
19
|
readonly api?: Partial<NavigatorAPI>;
|
|
20
|
+
readonly fetcher: import("../fetcher/Fetcher").Fetcher;
|
|
20
21
|
readonly mainElement: HTMLElement;
|
|
21
22
|
readonly headerMenu?: HTMLElement | null;
|
|
22
23
|
goTo(locator: Locator): void | Promise<void>;
|
|
@@ -50,7 +50,6 @@ export declare class SearchModule implements ReaderModule<EpubModuleHost>, ISear
|
|
|
50
50
|
goToSearchIndex(href: string, index: number, current: boolean): Promise<void>;
|
|
51
51
|
private handleSearchBook;
|
|
52
52
|
searchBook(term: string): Promise<any>;
|
|
53
|
-
decodeBase64(base64: any): string;
|
|
54
53
|
searchChapter(term: string): Promise<any>;
|
|
55
54
|
drawSearch(): void;
|
|
56
55
|
handleResize(): Promise<void>;
|
|
@@ -22,11 +22,8 @@ import { DefinitionsModuleConfig } from "../modules/epub/search/DefinitionsModul
|
|
|
22
22
|
import { LineFocusModuleConfig } from "../modules/epub/LineFocusModule";
|
|
23
23
|
import { CitationModuleConfig } from "../modules/epub/CitationModule";
|
|
24
24
|
import { ConsumptionModuleConfig } from "../modules/epub/ConsumptionModule";
|
|
25
|
-
|
|
26
|
-
export type
|
|
27
|
-
export interface RequestConfig extends RequestInit {
|
|
28
|
-
encoded?: boolean;
|
|
29
|
-
}
|
|
25
|
+
import type { GetContent, GetContentBytesLength, RequestConfig } from "../fetcher/types";
|
|
26
|
+
export type { GetContent, GetContentBytesLength, RequestConfig };
|
|
30
27
|
export interface NavigatorAPI {
|
|
31
28
|
updateSettings?: (settings: Record<string, unknown>) => Promise<void>;
|
|
32
29
|
getContent: GetContent;
|
|
@@ -70,6 +67,19 @@ export interface EpubNavigatorConfig {
|
|
|
70
67
|
services?: PublicationServices;
|
|
71
68
|
sample?: SampleRead;
|
|
72
69
|
requestConfig?: RequestConfig;
|
|
70
|
+
/**
|
|
71
|
+
* Pre-built Fetcher to use for content loading. If provided, the
|
|
72
|
+
* navigator uses this instead of constructing its own HttpFetcher
|
|
73
|
+
* from requestConfig. Used when opening .epub files (ZipFetcher)
|
|
74
|
+
* or when the integrator wants full control over the content pipeline.
|
|
75
|
+
*/
|
|
76
|
+
fetcher?: import("../fetcher/Fetcher").Fetcher;
|
|
77
|
+
/**
|
|
78
|
+
* Blob URL manager for ZIP-based content. Rewrites resource references
|
|
79
|
+
* (images, CSS, fonts) to blob URLs so document.write() iframes can
|
|
80
|
+
* load them. Only needed when opening .epub files directly.
|
|
81
|
+
*/
|
|
82
|
+
blobUrlManager?: import("../fetcher/BlobUrlManager").BlobUrlManager;
|
|
73
83
|
modules: Array<ReaderModule<any> | undefined>;
|
|
74
84
|
highlighter: TextHighlighter;
|
|
75
85
|
}
|
|
@@ -83,15 +93,60 @@ export interface SampleRead {
|
|
|
83
93
|
popup?: string;
|
|
84
94
|
minimum?: number;
|
|
85
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Self-contained CSS or JS injected into every chapter iframe.
|
|
98
|
+
*
|
|
99
|
+
* Injectables are the integrator's additions — NOT content from the EPUB.
|
|
100
|
+
* They're loaded via `<link>` / `<script>` elements in the iframe head,
|
|
101
|
+
* independently of the Fetcher pipeline and the module system.
|
|
102
|
+
*
|
|
103
|
+
* Use injectables for:
|
|
104
|
+
* - **ReadiumCSS** — reading system stylesheets (r2before, r2default, r2after)
|
|
105
|
+
* - **Custom fonts** — `@font-face` stylesheets or system font declarations
|
|
106
|
+
* - **Custom styles** — integrator branding, popup/popover CSS, icon fonts
|
|
107
|
+
* - **Scripts** — self-contained libraries (MathJax, KaTeX, analytics)
|
|
108
|
+
*
|
|
109
|
+
* Use modules instead when you need the reader's API (fetcher, publication,
|
|
110
|
+
* navigation state, events, settings).
|
|
111
|
+
*
|
|
112
|
+
* Categories:
|
|
113
|
+
*
|
|
114
|
+
* ReadiumCSS (order matters):
|
|
115
|
+
* `{ type: "style", url: "...ReadiumCSS-before.css", r2before: true }`
|
|
116
|
+
* `{ type: "style", url: "...ReadiumCSS-default.css", r2default: true }`
|
|
117
|
+
* `{ type: "style", url: "...ReadiumCSS-after.css", r2after: true }`
|
|
118
|
+
*
|
|
119
|
+
* Custom font (file):
|
|
120
|
+
* `{ type: "style", url: ".../opendyslexic.css", fontFamily: "opendyslexic" }`
|
|
121
|
+
*
|
|
122
|
+
* Custom font (system):
|
|
123
|
+
* `{ type: "style", fontFamily: "Courier", systemFont: true }`
|
|
124
|
+
*
|
|
125
|
+
* Custom style:
|
|
126
|
+
* `{ type: "style", url: ".../style.css" }`
|
|
127
|
+
*
|
|
128
|
+
* Script:
|
|
129
|
+
* `{ type: "script", url: "https://cdn.../MathJax.js" }`
|
|
130
|
+
* `{ type: "script", url: ".../analytics.js", async: true }`
|
|
131
|
+
*/
|
|
86
132
|
export interface Injectable {
|
|
87
|
-
|
|
133
|
+
/** `"style"` for CSS, `"script"` for JS. */
|
|
134
|
+
type: "style" | "script";
|
|
135
|
+
/** URL to the CSS or JS file. Required unless `systemFont` is true. */
|
|
88
136
|
url?: string;
|
|
89
|
-
|
|
137
|
+
/** ReadiumCSS: inject before all other styles (first in head). */
|
|
90
138
|
r2before?: boolean;
|
|
139
|
+
/** ReadiumCSS: inject as the default stylesheet (second in head). */
|
|
91
140
|
r2default?: boolean;
|
|
141
|
+
/** ReadiumCSS: inject after all other styles (last in head). */
|
|
142
|
+
r2after?: boolean;
|
|
143
|
+
/** Font family name — registers this font in the reader's font selector. */
|
|
92
144
|
fontFamily?: string;
|
|
145
|
+
/** System font — no URL needed, the font is available on the user's OS. */
|
|
93
146
|
systemFont?: boolean;
|
|
147
|
+
/** Appearance name — registers a custom appearance with the r2after stylesheet. */
|
|
94
148
|
appearance?: string;
|
|
149
|
+
/** Load script asynchronously (only applies to `type: "script"`). */
|
|
95
150
|
async?: boolean;
|
|
96
151
|
}
|
|
97
152
|
export interface ReaderRights {
|
|
@@ -125,7 +180,23 @@ export interface InitialAnnotations {
|
|
|
125
180
|
export interface ReaderConfig {
|
|
126
181
|
/** Pre-parsed publication manifest JSON — if omitted the manifest is fetched from `url`. */
|
|
127
182
|
publication?: Record<string, unknown>;
|
|
128
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Manifest URL (webpub from server). Required unless `epub` is provided.
|
|
185
|
+
*/
|
|
186
|
+
url?: URL;
|
|
187
|
+
/**
|
|
188
|
+
* Open an .epub file directly — no server/streamer needed.
|
|
189
|
+
* The reader parses the EPUB client-side (container.xml → OPF → manifest)
|
|
190
|
+
* and serves content from the ZIP via ZipFetcher.
|
|
191
|
+
*
|
|
192
|
+
* Accepts:
|
|
193
|
+
* - `File` or `Blob` — local file from drag-drop, file picker, IndexedDB
|
|
194
|
+
* - `ArrayBuffer` — raw bytes already in memory
|
|
195
|
+
* - `URL` or `string` — URL to a hosted .epub file (fetched automatically)
|
|
196
|
+
*
|
|
197
|
+
* Mutually exclusive with `url` (webpub manifest) — provide one or the other.
|
|
198
|
+
*/
|
|
199
|
+
epub?: File | Blob | ArrayBuffer | URL | string;
|
|
129
200
|
userSettings?: Partial<import("../model/user-settings/UserSettings").InitialUserSettings>;
|
|
130
201
|
initialAnnotations?: InitialAnnotations;
|
|
131
202
|
lastReadingPosition?: import("../model/Locator").ReadingPosition;
|
|
@@ -171,6 +242,9 @@ export declare class EpubNavigator extends VisualNavigator implements EpubModule
|
|
|
171
242
|
mainElement: HTMLElement;
|
|
172
243
|
publication: Publication;
|
|
173
244
|
highlighter?: TextHighlighter;
|
|
245
|
+
private _fetcher;
|
|
246
|
+
private _blobUrlManager?;
|
|
247
|
+
get fetcher(): import("../fetcher/Fetcher").Fetcher;
|
|
174
248
|
supports(feature: NavigatorFeatureName): boolean;
|
|
175
249
|
private fxlZoomKeyHandler;
|
|
176
250
|
private getFxlCurrentScale;
|
|
@@ -240,7 +314,7 @@ export declare class EpubNavigator extends VisualNavigator implements EpubModule
|
|
|
240
314
|
requestConfig?: RequestConfig;
|
|
241
315
|
private didInitKeyboardEventHandler;
|
|
242
316
|
static create(config: EpubNavigatorConfig): Promise<EpubNavigator>;
|
|
243
|
-
protected constructor(settings: UserSettings, annotator: Annotator | undefined, initialLastReadingPosition: ReadingPosition | undefined, publication: Publication, api?: Partial<NavigatorAPI>, rights?: Partial<ReaderRights>, tts?: Partial<TTSModuleConfig>, injectables?: Array<Injectable>, attributes?: IFrameAttributes, services?: PublicationServices, sample?: SampleRead, requestConfig?: RequestConfig, highlighter?: TextHighlighter, modules?: Array<ReaderModule<any> | undefined
|
|
317
|
+
protected constructor(settings: UserSettings, annotator: Annotator | undefined, initialLastReadingPosition: ReadingPosition | undefined, publication: Publication, api?: Partial<NavigatorAPI>, rights?: Partial<ReaderRights>, tts?: Partial<TTSModuleConfig>, injectables?: Array<Injectable>, attributes?: IFrameAttributes, services?: PublicationServices, sample?: SampleRead, requestConfig?: RequestConfig, highlighter?: TextHighlighter, modules?: Array<ReaderModule<any> | undefined>, fetcher?: import("../fetcher/Fetcher").Fetcher, blobUrlManager?: import("../fetcher/BlobUrlManager").BlobUrlManager);
|
|
244
318
|
stop(): void;
|
|
245
319
|
spreads: HTMLDivElement;
|
|
246
320
|
firstSpread: HTMLDivElement;
|
|
@@ -41,10 +41,6 @@ export interface PDFNavigatorConfig {
|
|
|
41
41
|
*/
|
|
42
42
|
modules?: Array<import("../modules/ReaderModule").ReaderModule<any> | undefined>;
|
|
43
43
|
}
|
|
44
|
-
export declare enum ScaleType {
|
|
45
|
-
Page = 0,
|
|
46
|
-
Width = 1
|
|
47
|
-
}
|
|
48
44
|
export declare class PDFNavigator extends VisualNavigator implements PDFModuleHost {
|
|
49
45
|
readonly isPDF = true;
|
|
50
46
|
settings: UserSettings;
|
|
@@ -84,6 +80,8 @@ export declare class PDFNavigator extends VisualNavigator implements PDFModuleHo
|
|
|
84
80
|
get viewStore(): Store | undefined;
|
|
85
81
|
get annotator(): Annotator | undefined;
|
|
86
82
|
get currentResourceLink(): import("../model/v3").Link | undefined;
|
|
83
|
+
private _fetcher;
|
|
84
|
+
get fetcher(): import("../fetcher/Fetcher").Fetcher;
|
|
87
85
|
private resizeTimeout;
|
|
88
86
|
static create(config: PDFNavigatorConfig): Promise<PDFNavigator>;
|
|
89
87
|
protected constructor(settings: UserSettings, publication: Publication, api?: Partial<NavigatorAPI>, workerSrc?: string, annotator?: Annotator, initialLastReadingPosition?: ReadingPosition, viewStore?: Store, rights?: Partial<ReaderRights>, modules?: Array<import("../modules/ReaderModule").ReaderModule<any> | undefined>);
|
|
@@ -43,7 +43,7 @@ export declare abstract class VisualNavigator extends EventEmitter implements Na
|
|
|
43
43
|
abstract publication: Publication;
|
|
44
44
|
abstract rights: Partial<ReaderRights>;
|
|
45
45
|
readonly registry: ModuleRegistry;
|
|
46
|
-
readonly modules: ModuleAccessors<import("
|
|
46
|
+
readonly modules: ModuleAccessors<import("..").IBookmarkModule<import("..").ModuleHost>, import("..").IAnnotationModule<import("..").ModuleHost>, import("..").ISearchModule<import("..").ModuleHost>, import("..").IHistoryModule<import("..").ModuleHost>>;
|
|
47
47
|
abstract currentLocator(): Locator;
|
|
48
48
|
abstract positions(): Locator[];
|
|
49
49
|
abstract currentResource(): number | undefined;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* on pdfjs APIs anywhere else in the project.
|
|
12
12
|
*/
|
|
13
13
|
import type { PDFDocumentProxy } from "pdfjs-dist";
|
|
14
|
-
import type {
|
|
14
|
+
import type { PDFLinkService, PDFViewer } from "pdfjs-dist/web/pdf_viewer.mjs";
|
|
15
15
|
type AnnotationStorage = PDFDocumentProxy["annotationStorage"];
|
|
16
16
|
/**
|
|
17
17
|
* Serializable shape exposed by `AnnotationStorage.serializable`.
|
|
@@ -44,16 +44,4 @@ export declare function releasePdfViewerDocument(viewer: PDFViewer): void;
|
|
|
44
44
|
* Release the current document from a PDFLinkService (accepts null at runtime).
|
|
45
45
|
*/
|
|
46
46
|
export declare function releasePdfLinkServiceDocument(linkService: PDFLinkService): void;
|
|
47
|
-
interface FindControllerState {
|
|
48
|
-
query?: string;
|
|
49
|
-
caseSensitive?: boolean;
|
|
50
|
-
entireWord?: boolean;
|
|
51
|
-
highlightAll?: boolean;
|
|
52
|
-
findPrevious?: boolean;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Read the current search state from a PDFFindController.
|
|
56
|
-
* Returns null if no search has been performed yet.
|
|
57
|
-
*/
|
|
58
|
-
export declare function getFindControllerState(controller: PDFFindController): FindControllerState | null;
|
|
59
47
|
export {};
|
|
@@ -50,6 +50,8 @@ export declare const ReaderEvent: {
|
|
|
50
50
|
readonly InspectDetected: "inspect.detected";
|
|
51
51
|
readonly ActionTracked: "consumption.action";
|
|
52
52
|
readonly IdleSince: "consumption.idle";
|
|
53
|
+
readonly PageChanged: "page.changed";
|
|
54
|
+
readonly PdfMatchesUpdated: "pdf.matches.updated";
|
|
53
55
|
};
|
|
54
56
|
export type ReaderEventName = (typeof ReaderEvent)[keyof typeof ReaderEvent];
|
|
55
57
|
export interface ReaderEventMap {
|
|
@@ -105,4 +107,12 @@ export interface ReaderEventMap {
|
|
|
105
107
|
action: any;
|
|
106
108
|
};
|
|
107
109
|
[ReaderEvent.IdleSince]: number;
|
|
110
|
+
[ReaderEvent.PageChanged]: {
|
|
111
|
+
page: number;
|
|
112
|
+
totalPages: number;
|
|
113
|
+
};
|
|
114
|
+
[ReaderEvent.PdfMatchesUpdated]: {
|
|
115
|
+
current: number;
|
|
116
|
+
total: number;
|
|
117
|
+
};
|
|
108
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-i-t-a/reader",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.15",
|
|
4
4
|
"description": "A viewer application for EPUB files.",
|
|
5
5
|
"repository": "https://github.com/d-i-t-a/R2D2BC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"debounce": "^2.0.0",
|
|
46
46
|
"devtools-detector": "^2.0.14",
|
|
47
47
|
"eventemitter3": "^5.0.1",
|
|
48
|
+
"fflate": "^0.8.2",
|
|
48
49
|
"jscrypto": "^1.0.3",
|
|
49
50
|
"lodash": "^4.17.21",
|
|
50
51
|
"loglevel": "^1.8.0",
|