@d-i-t-a/reader 3.0.0-alpha.14 → 3.0.0-alpha.16
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 +4730 -947
- package/dist/esm/index.js.map +4 -4
- package/dist/reader.js +72 -69
- package/dist/reader.js.map +4 -4
- package/dist/types/fetcher/Base64DecodingFetcher.d.ts +19 -0
- 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 +29 -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 +18 -1
- package/dist/types/model/user-settings/UserSettings.d.ts +2 -1
- package/dist/types/model/v3/Publication.d.ts +4 -4
- package/dist/types/modules/ModuleHost.d.ts +3 -1
- package/dist/types/modules/ModuleRegistry.d.ts +1 -1
- package/dist/types/modules/ReaderModule.d.ts +1 -1
- package/dist/types/modules/epub/search/SearchModule.d.ts +0 -1
- package/dist/types/navigator/EpubNavigator.d.ts +44 -54
- package/dist/types/navigator/InjectableManager.d.ts +32 -0
- package/dist/types/navigator/PDFNavigator.d.ts +3 -1
- package/dist/types/navigator/VisualNavigator.d.ts +1 -1
- package/dist/types/navigator/types.d.ts +166 -0
- package/package.json +2 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Store from "../../store/Store";
|
|
2
2
|
import { UserProperties, UserProperty, UserSettingsIncrementable } from "./UserProperties";
|
|
3
|
-
import { Injectable
|
|
3
|
+
import { Injectable } from "../../navigator/EpubNavigator";
|
|
4
|
+
import type { NavigatorAPI } from "../../navigator/types";
|
|
4
5
|
import BookView from "../../views/BookView";
|
|
5
6
|
export interface UserSettingsConfig {
|
|
6
7
|
/** Store to save the user's selections in. */
|
|
@@ -25,7 +25,7 @@ export declare class Publication {
|
|
|
25
25
|
* Returns null if the JSON cannot be parsed.
|
|
26
26
|
*/
|
|
27
27
|
static fromJSON(json: any, url: URL): Publication | null;
|
|
28
|
-
static fromUrl(url: URL, requestConfig
|
|
28
|
+
static fromUrl(url: URL, requestConfig: RequestConfig | undefined, fetcher: import("../../fetcher/Fetcher").Fetcher): Promise<Publication>;
|
|
29
29
|
get metadata(): import("@readium/shared").Metadata;
|
|
30
30
|
get readingOrder(): Link[];
|
|
31
31
|
get resources(): Link[];
|
|
@@ -50,8 +50,8 @@ export declare class Publication {
|
|
|
50
50
|
getTOCItemAbsolute(href: string): Link | undefined;
|
|
51
51
|
getTOCItem(href: string): Link | undefined;
|
|
52
52
|
positionsByHref(href: string): Locator[];
|
|
53
|
-
autoGeneratePositions(requestConfig
|
|
54
|
-
fetchPositionsFromService(href: string,
|
|
55
|
-
fetchWeightsFromService(href: string,
|
|
53
|
+
autoGeneratePositions(requestConfig: RequestConfig | undefined, getContentBytesLength: GetContentBytesLength): Promise<void>;
|
|
54
|
+
fetchPositionsFromService(href: string, fetcher: import("../../fetcher/Fetcher").Fetcher): Promise<void>;
|
|
55
|
+
fetchWeightsFromService(href: string, fetcher: import("../../fetcher/Fetcher").Fetcher): Promise<void>;
|
|
56
56
|
private limitedTOC;
|
|
57
57
|
}
|
|
@@ -5,7 +5,8 @@ import { Publication } from "../model/v3";
|
|
|
5
5
|
import { ReaderModule } from "./ReaderModule";
|
|
6
6
|
import type { ReaderEventMap } from "../utils/Events";
|
|
7
7
|
import type { NavigatorFeatureKey, NavigatorFeatureMap } from "./NavigatorFeatureMap";
|
|
8
|
-
import { IFrameAttributes,
|
|
8
|
+
import { IFrameAttributes, RequestConfig, SampleRead } from "../navigator/EpubNavigator";
|
|
9
|
+
import type { NavigatorAPI, ReaderRights } from "../navigator/types";
|
|
9
10
|
import { UserSettings } from "../model/user-settings/UserSettings";
|
|
10
11
|
import { TextHighlighter } from "./highlight/TextHighlighter";
|
|
11
12
|
/**
|
|
@@ -17,6 +18,7 @@ export interface ModuleHost {
|
|
|
17
18
|
readonly settings: UserSettings;
|
|
18
19
|
readonly rights: Partial<ReaderRights>;
|
|
19
20
|
readonly api?: Partial<NavigatorAPI>;
|
|
21
|
+
readonly fetcher: import("../fetcher/Fetcher").Fetcher;
|
|
20
22
|
readonly mainElement: HTMLElement;
|
|
21
23
|
readonly headerMenu?: HTMLElement | null;
|
|
22
24
|
goTo(locator: Locator): void | Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReaderModule } from "./ReaderModule";
|
|
2
2
|
import type { ModuleHost } from "./ModuleHost";
|
|
3
3
|
import type { NavigatorFeatureKey, NavigatorFeatureMap } from "./NavigatorFeatureMap";
|
|
4
|
-
import type { ReaderRights } from "../navigator/
|
|
4
|
+
import type { ReaderRights } from "../navigator/types";
|
|
5
5
|
/**
|
|
6
6
|
* Registry for reader feature modules.
|
|
7
7
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModuleHost } from "./ModuleHost";
|
|
2
|
-
import type { ReaderRights } from "../navigator/
|
|
2
|
+
import type { ReaderRights } from "../navigator/types";
|
|
3
3
|
import type { NavigatorFeatureKey } from "./NavigatorFeatureMap";
|
|
4
4
|
/**
|
|
5
5
|
* Enum-like constant for navigator host types.
|
|
@@ -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,27 +22,10 @@ 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
|
-
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
export interface NavigatorAPI {
|
|
31
|
-
updateSettings?: (settings: Record<string, unknown>) => Promise<void>;
|
|
32
|
-
getContent: GetContent;
|
|
33
|
-
getContentBytesLength: GetContentBytesLength;
|
|
34
|
-
resourceReady?: () => void;
|
|
35
|
-
resourceAtStart?: () => void;
|
|
36
|
-
resourceAtEnd?: () => void;
|
|
37
|
-
resourceFitsScreen?: () => void;
|
|
38
|
-
updateCurrentLocation?: (locator: import("../model/Locator").ReadingPosition) => Promise<void>;
|
|
39
|
-
positionInfo?: (locator: import("../model/Locator").Locator) => void;
|
|
40
|
-
chapterInfo?: (title: string | undefined) => void;
|
|
41
|
-
keydownFallthrough?: (event: KeyboardEvent | undefined) => void;
|
|
42
|
-
clickThrough?: (event: MouseEvent | TouchEvent) => void;
|
|
43
|
-
direction?: (dir: string) => void;
|
|
44
|
-
onError?: (e: Error) => void;
|
|
45
|
-
}
|
|
25
|
+
import type { GetContent, GetContentBytesLength, RequestConfig } from "../fetcher/types";
|
|
26
|
+
import type { NavigatorAPI, ReaderRights, Injectable } from "./types";
|
|
27
|
+
export type { GetContent, GetContentBytesLength, RequestConfig };
|
|
28
|
+
export type { NavigatorAPI, ReaderRights, Injectable, InjectableContext, StyleInjectable, ScriptInjectable, InlineStyleInjectable, InlineScriptInjectable, } from "./types";
|
|
46
29
|
export interface IFrameAttributes {
|
|
47
30
|
margin: number;
|
|
48
31
|
navHeight?: number;
|
|
@@ -70,6 +53,19 @@ export interface EpubNavigatorConfig {
|
|
|
70
53
|
services?: PublicationServices;
|
|
71
54
|
sample?: SampleRead;
|
|
72
55
|
requestConfig?: RequestConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Pre-built Fetcher to use for content loading. If provided, the
|
|
58
|
+
* navigator uses this instead of constructing its own HttpFetcher
|
|
59
|
+
* from requestConfig. Used when opening .epub files (ZipFetcher)
|
|
60
|
+
* or when the integrator wants full control over the content pipeline.
|
|
61
|
+
*/
|
|
62
|
+
fetcher?: import("../fetcher/Fetcher").Fetcher;
|
|
63
|
+
/**
|
|
64
|
+
* Blob URL manager for ZIP-based content. Rewrites resource references
|
|
65
|
+
* (images, CSS, fonts) to blob URLs so document.write() iframes can
|
|
66
|
+
* load them. Only needed when opening .epub files directly.
|
|
67
|
+
*/
|
|
68
|
+
blobUrlManager?: import("../fetcher/BlobUrlManager").BlobUrlManager;
|
|
73
69
|
modules: Array<ReaderModule<any> | undefined>;
|
|
74
70
|
highlighter: TextHighlighter;
|
|
75
71
|
}
|
|
@@ -83,34 +79,6 @@ export interface SampleRead {
|
|
|
83
79
|
popup?: string;
|
|
84
80
|
minimum?: number;
|
|
85
81
|
}
|
|
86
|
-
export interface Injectable {
|
|
87
|
-
type: string;
|
|
88
|
-
url?: string;
|
|
89
|
-
r2after?: boolean;
|
|
90
|
-
r2before?: boolean;
|
|
91
|
-
r2default?: boolean;
|
|
92
|
-
fontFamily?: string;
|
|
93
|
-
systemFont?: boolean;
|
|
94
|
-
appearance?: string;
|
|
95
|
-
async?: boolean;
|
|
96
|
-
}
|
|
97
|
-
export interface ReaderRights {
|
|
98
|
-
enableBookmarks: boolean;
|
|
99
|
-
enableAnnotations: boolean;
|
|
100
|
-
enableTTS: boolean;
|
|
101
|
-
enableSearch: boolean;
|
|
102
|
-
enableDefinitions: boolean;
|
|
103
|
-
enableContentProtection: boolean;
|
|
104
|
-
enableTimeline: boolean;
|
|
105
|
-
autoGeneratePositions: boolean;
|
|
106
|
-
enableMediaOverlays: boolean;
|
|
107
|
-
enablePageBreaks: boolean;
|
|
108
|
-
enableLineFocus: boolean;
|
|
109
|
-
customKeyboardEvents: boolean;
|
|
110
|
-
enableHistory: boolean;
|
|
111
|
-
enableCitations: boolean;
|
|
112
|
-
enableConsumption: boolean;
|
|
113
|
-
}
|
|
114
82
|
export interface ReaderUI {
|
|
115
83
|
settings: UserSettingsUIConfig;
|
|
116
84
|
}
|
|
@@ -125,7 +93,23 @@ export interface InitialAnnotations {
|
|
|
125
93
|
export interface ReaderConfig {
|
|
126
94
|
/** Pre-parsed publication manifest JSON — if omitted the manifest is fetched from `url`. */
|
|
127
95
|
publication?: Record<string, unknown>;
|
|
128
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Manifest URL (webpub from server). Required unless `epub` is provided.
|
|
98
|
+
*/
|
|
99
|
+
url?: URL;
|
|
100
|
+
/**
|
|
101
|
+
* Open an .epub file directly — no server/streamer needed.
|
|
102
|
+
* The reader parses the EPUB client-side (container.xml → OPF → manifest)
|
|
103
|
+
* and serves content from the ZIP via ZipFetcher.
|
|
104
|
+
*
|
|
105
|
+
* Accepts:
|
|
106
|
+
* - `File` or `Blob` — local file from drag-drop, file picker, IndexedDB
|
|
107
|
+
* - `ArrayBuffer` — raw bytes already in memory
|
|
108
|
+
* - `URL` or `string` — URL to a hosted .epub file (fetched automatically)
|
|
109
|
+
*
|
|
110
|
+
* Mutually exclusive with `url` (webpub manifest) — provide one or the other.
|
|
111
|
+
*/
|
|
112
|
+
epub?: File | Blob | ArrayBuffer | URL | string;
|
|
129
113
|
userSettings?: Partial<import("../model/user-settings/UserSettings").InitialUserSettings>;
|
|
130
114
|
initialAnnotations?: InitialAnnotations;
|
|
131
115
|
lastReadingPosition?: import("../model/Locator").ReadingPosition;
|
|
@@ -171,6 +155,9 @@ export declare class EpubNavigator extends VisualNavigator implements EpubModule
|
|
|
171
155
|
mainElement: HTMLElement;
|
|
172
156
|
publication: Publication;
|
|
173
157
|
highlighter?: TextHighlighter;
|
|
158
|
+
private _fetcher;
|
|
159
|
+
private _blobUrlManager?;
|
|
160
|
+
get fetcher(): import("../fetcher/Fetcher").Fetcher;
|
|
174
161
|
supports(feature: NavigatorFeatureName): boolean;
|
|
175
162
|
private fxlZoomKeyHandler;
|
|
176
163
|
private getFxlCurrentScale;
|
|
@@ -239,8 +226,10 @@ export declare class EpubNavigator extends VisualNavigator implements EpubModule
|
|
|
239
226
|
sample?: SampleRead;
|
|
240
227
|
requestConfig?: RequestConfig;
|
|
241
228
|
private didInitKeyboardEventHandler;
|
|
229
|
+
/** Owns the lifecycle of `Injectable` items across iframe loads. */
|
|
230
|
+
private injectableManager;
|
|
242
231
|
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
|
|
232
|
+
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
233
|
stop(): void;
|
|
245
234
|
spreads: HTMLDivElement;
|
|
246
235
|
firstSpread: HTMLDivElement;
|
|
@@ -258,7 +247,6 @@ export declare class EpubNavigator extends VisualNavigator implements EpubModule
|
|
|
258
247
|
private updateBookView;
|
|
259
248
|
private loadManifest;
|
|
260
249
|
private handleIFrameLoad;
|
|
261
|
-
private injectInjectablesIntoIframeHead;
|
|
262
250
|
/**
|
|
263
251
|
* Displays standard error UI.
|
|
264
252
|
*/
|
|
@@ -317,9 +305,11 @@ export declare class EpubNavigator extends VisualNavigator implements EpubModule
|
|
|
317
305
|
private hideIframeContents;
|
|
318
306
|
private hideLoadingMessage;
|
|
319
307
|
private saveCurrentReadingPosition;
|
|
308
|
+
/**
|
|
309
|
+
* Create a `<base>` element for the iframe's document. Used by `prepareDoc`
|
|
310
|
+
* to anchor relative URLs in chapter content to the resource's href.
|
|
311
|
+
*/
|
|
320
312
|
private static createBase;
|
|
321
|
-
private static createCssLink;
|
|
322
|
-
private static createJavascriptLink;
|
|
323
313
|
activateMarker(id: any, position: any): void;
|
|
324
314
|
deactivateMarker(): void;
|
|
325
315
|
showLayer(layer: any): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Publication } from "../model/v3";
|
|
2
|
+
import type { UserSettings } from "../model/user-settings/UserSettings";
|
|
3
|
+
import type { Injectable } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Owns `Injectable` insertion into chapter iframes.
|
|
6
|
+
*
|
|
7
|
+
* All variants are injected into the parsed chapter HTML's `<head>` *before*
|
|
8
|
+
* `document.write()` — they end up in the iframe as if they were part of the
|
|
9
|
+
* original document, so the browser loads them in parallel with the body. No
|
|
10
|
+
* flash of unstyled content, no post-load round trip; the iframe's own `load`
|
|
11
|
+
* event covers readiness.
|
|
12
|
+
*
|
|
13
|
+
* Blob content is converted to a runtime object URL and revoked when the
|
|
14
|
+
* iframe navigates to the next chapter or the reader stops.
|
|
15
|
+
*/
|
|
16
|
+
export declare class InjectableManager {
|
|
17
|
+
private readonly publication;
|
|
18
|
+
private readonly settings;
|
|
19
|
+
/** Per-iframe object URLs created from `Blob` content. Revoked on cleanup. */
|
|
20
|
+
private objectUrlRegistry;
|
|
21
|
+
constructor(publication: Publication, settings: UserSettings);
|
|
22
|
+
/**
|
|
23
|
+
* Inject into the parsed chapter HTML's head. Mutates `doc` in place.
|
|
24
|
+
*/
|
|
25
|
+
injectStaticIntoDoc(doc: Document, iframe: HTMLIFrameElement, injectables: Injectable[] | undefined, resourceHref: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Revoke any object URLs allocated for `iframe` during injection. Called
|
|
28
|
+
* on chapter navigation (before the iframe loads new content) and on
|
|
29
|
+
* reader stop. Safe to call when the iframe has no registrations.
|
|
30
|
+
*/
|
|
31
|
+
cleanupForIframe(iframe: HTMLIFrameElement): void;
|
|
32
|
+
}
|
|
@@ -7,7 +7,7 @@ import Annotator from "../store/Annotator";
|
|
|
7
7
|
import Store from "../store/Store";
|
|
8
8
|
import { PDFDocumentProxy, AnnotationEditorType } from "pdfjs-dist";
|
|
9
9
|
import { EventBus, PDFFindController, PDFLinkService, PDFViewer, ScrollMode, SpreadMode } from "pdfjs-dist/web/pdf_viewer.mjs";
|
|
10
|
-
import { NavigatorAPI, ReaderRights } from "./
|
|
10
|
+
import type { NavigatorAPI, ReaderRights } from "./types";
|
|
11
11
|
export { SpreadMode, ScrollMode, AnnotationEditorType };
|
|
12
12
|
export interface PDFNavigatorConfig {
|
|
13
13
|
mainElement: HTMLElement;
|
|
@@ -80,6 +80,8 @@ export declare class PDFNavigator extends VisualNavigator implements PDFModuleHo
|
|
|
80
80
|
get viewStore(): Store | undefined;
|
|
81
81
|
get annotator(): Annotator | undefined;
|
|
82
82
|
get currentResourceLink(): import("../model/v3").Link | undefined;
|
|
83
|
+
private _fetcher;
|
|
84
|
+
get fetcher(): import("../fetcher/Fetcher").Fetcher;
|
|
83
85
|
private resizeTimeout;
|
|
84
86
|
static create(config: PDFNavigatorConfig): Promise<PDFNavigator>;
|
|
85
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>);
|
|
@@ -8,7 +8,7 @@ import { ReaderModule } from "../modules/ReaderModule";
|
|
|
8
8
|
import { ModuleRegistry } from "../modules/ModuleRegistry";
|
|
9
9
|
import { ModuleAccessors } from "../modules/ModuleAccessors";
|
|
10
10
|
import type { NavigatorFeatureKey, NavigatorFeatureMap } from "../modules/NavigatorFeatureMap";
|
|
11
|
-
import type { ReaderRights } from "./
|
|
11
|
+
import type { ReaderRights } from "./types";
|
|
12
12
|
/**
|
|
13
13
|
* Typed feature names for navigator capability queries.
|
|
14
14
|
*/
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { GetContent, GetContentBytesLength } from "../fetcher/types";
|
|
2
|
+
import type { Publication } from "../model/v3";
|
|
3
|
+
/**
|
|
4
|
+
* Callbacks the integrator can supply for the reader to emit state changes
|
|
5
|
+
* and delegate resource loading. Shared by EpubNavigator and PDFNavigator.
|
|
6
|
+
*/
|
|
7
|
+
export interface NavigatorAPI {
|
|
8
|
+
updateSettings?: (settings: Record<string, unknown>) => Promise<void>;
|
|
9
|
+
getContent: GetContent;
|
|
10
|
+
getContentBytesLength: GetContentBytesLength;
|
|
11
|
+
resourceReady?: () => void;
|
|
12
|
+
resourceAtStart?: () => void;
|
|
13
|
+
resourceAtEnd?: () => void;
|
|
14
|
+
resourceFitsScreen?: () => void;
|
|
15
|
+
updateCurrentLocation?: (locator: import("../model/Locator").ReadingPosition) => Promise<void>;
|
|
16
|
+
positionInfo?: (locator: import("../model/Locator").Locator) => void;
|
|
17
|
+
chapterInfo?: (title: string | undefined) => void;
|
|
18
|
+
keydownFallthrough?: (event: KeyboardEvent | undefined) => void;
|
|
19
|
+
clickThrough?: (event: MouseEvent | TouchEvent) => void;
|
|
20
|
+
direction?: (dir: string) => void;
|
|
21
|
+
onError?: (e: Error) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Context passed to an injectable's `when` predicate. Lets integrators gate
|
|
25
|
+
* per-resource / per-publication without us pre-computing a lot of metadata.
|
|
26
|
+
*
|
|
27
|
+
* `doc` is the parsed chapter XHTML document, provided for content inspection
|
|
28
|
+
* (detect math, language, tables, publisher classes, etc.). Treat it as
|
|
29
|
+
* read-only: mutations land in the written iframe and bypass the Injectable
|
|
30
|
+
* API contract. Use injectables for injection, not `when`.
|
|
31
|
+
*/
|
|
32
|
+
export interface InjectableContext {
|
|
33
|
+
publication: Publication;
|
|
34
|
+
/** href of the resource about to be loaded into the iframe */
|
|
35
|
+
resourceHref: string;
|
|
36
|
+
/** Parsed XHTML document of the chapter. Read-only by convention. */
|
|
37
|
+
doc: Document;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Shared optional fields on every Injectable variant.
|
|
41
|
+
*/
|
|
42
|
+
interface BaseInjectable {
|
|
43
|
+
/**
|
|
44
|
+
* If provided, the injectable is skipped when this returns false.
|
|
45
|
+
* Evaluated once per iframe load. Useful for per-resource or per-publication
|
|
46
|
+
* gating that the `injectables` / `injectablesFixed` array split can't express.
|
|
47
|
+
*/
|
|
48
|
+
when?: (ctx: InjectableContext) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Extra HTML attributes to set on the injected `<link>` / `<script>` /
|
|
51
|
+
* `<style>` element. Useful for CSP `nonce`, SRI `integrity`, `crossorigin`,
|
|
52
|
+
* `media` queries on link tags, `data-*` attributes, etc.
|
|
53
|
+
*/
|
|
54
|
+
attributes?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Inject a stylesheet as a `<link rel="stylesheet">` pointing at a URL, or
|
|
58
|
+
* as a Blob converted to an object URL at runtime.
|
|
59
|
+
*
|
|
60
|
+
* One of `url` or `blob` is required.
|
|
61
|
+
*/
|
|
62
|
+
export interface StyleInjectable extends BaseInjectable {
|
|
63
|
+
type: "style";
|
|
64
|
+
url?: string;
|
|
65
|
+
blob?: Blob;
|
|
66
|
+
/** ReadiumCSS: inject before all other styles (first in head). */
|
|
67
|
+
r2before?: boolean;
|
|
68
|
+
/** ReadiumCSS: inject as the default stylesheet (second in head). */
|
|
69
|
+
r2default?: boolean;
|
|
70
|
+
/** ReadiumCSS: inject after all other styles (last in head). */
|
|
71
|
+
r2after?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Registers the font family with the reader's font picker. `UserSettings`
|
|
74
|
+
* calls `addFont(fontFamily)` at init to extend the selectable list; the
|
|
75
|
+
* navigator calls `initAddedFont()` after this stylesheet loads to refresh
|
|
76
|
+
* the UI. The stylesheet should declare `@font-face` for this family.
|
|
77
|
+
*/
|
|
78
|
+
fontFamily?: string;
|
|
79
|
+
/**
|
|
80
|
+
* System font declaration — no URL needed, the font is available on the
|
|
81
|
+
* user's OS. Registers the family in the picker without loading a stylesheet.
|
|
82
|
+
*/
|
|
83
|
+
systemFont?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Registers an appearance name with the reader's appearance selector.
|
|
86
|
+
* `UserSettings` calls `addAppearance(appearance)` at init; the navigator
|
|
87
|
+
* calls `initAddedAppearance()` after this stylesheet loads. Typically set
|
|
88
|
+
* on an `r2after` stylesheet that declares the appearance's custom properties.
|
|
89
|
+
*/
|
|
90
|
+
appearance?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Inject a JS file as a `<script>` element pointing at a URL, or as a Blob
|
|
94
|
+
* converted to an object URL at runtime.
|
|
95
|
+
*
|
|
96
|
+
* One of `url` or `blob` is required.
|
|
97
|
+
*/
|
|
98
|
+
export interface ScriptInjectable extends BaseInjectable {
|
|
99
|
+
type: "script";
|
|
100
|
+
url?: string;
|
|
101
|
+
blob?: Blob;
|
|
102
|
+
/** Load script asynchronously. */
|
|
103
|
+
async?: boolean;
|
|
104
|
+
/** Render as `<script type="module">`. */
|
|
105
|
+
module?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Inject inline CSS — no HTTP round-trip. Rendered as a `<style>` element with
|
|
109
|
+
* `source` as its text content.
|
|
110
|
+
*/
|
|
111
|
+
export interface InlineStyleInjectable extends BaseInjectable {
|
|
112
|
+
type: "style-inline";
|
|
113
|
+
source: string;
|
|
114
|
+
/** ReadiumCSS: inject before all other styles (first in head). */
|
|
115
|
+
r2before?: boolean;
|
|
116
|
+
/** ReadiumCSS: inject as the default stylesheet (second in head). */
|
|
117
|
+
r2default?: boolean;
|
|
118
|
+
/** ReadiumCSS: inject after all other styles (last in head). */
|
|
119
|
+
r2after?: boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Inject inline JS — no HTTP round-trip. Rendered as a `<script>` element with
|
|
123
|
+
* `source` as its text content.
|
|
124
|
+
*/
|
|
125
|
+
export interface InlineScriptInjectable extends BaseInjectable {
|
|
126
|
+
type: "script-inline";
|
|
127
|
+
source: string;
|
|
128
|
+
/** Load script asynchronously. */
|
|
129
|
+
async?: boolean;
|
|
130
|
+
/** Render as `<script type="module">`. */
|
|
131
|
+
module?: boolean;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Injectable — discriminated union keyed on `type`. Passed to the navigator
|
|
135
|
+
* via `ReaderConfig.injectables` (and `injectablesFixed` for fixed-layout
|
|
136
|
+
* publications). Every item in the chosen array is evaluated per iframe load.
|
|
137
|
+
*
|
|
138
|
+
* All variants inject into the iframe `<head>`. Integrators needing DOM
|
|
139
|
+
* behaviour (click listeners, popup UI, glossary, analytics) write a normal
|
|
140
|
+
* `type: "script"` injectable whose content attaches its own handlers inside
|
|
141
|
+
* the iframe — the v2.5 pattern used by `injectables/click/click.ts` and
|
|
142
|
+
* `injectables/mui/script.js`, unchanged.
|
|
143
|
+
*/
|
|
144
|
+
export type Injectable = StyleInjectable | ScriptInjectable | InlineStyleInjectable | InlineScriptInjectable;
|
|
145
|
+
/**
|
|
146
|
+
* Feature toggles gating which modules are loaded and which reader
|
|
147
|
+
* capabilities are exposed. Shared by EpubNavigator and PDFNavigator.
|
|
148
|
+
*/
|
|
149
|
+
export interface ReaderRights {
|
|
150
|
+
enableBookmarks: boolean;
|
|
151
|
+
enableAnnotations: boolean;
|
|
152
|
+
enableTTS: boolean;
|
|
153
|
+
enableSearch: boolean;
|
|
154
|
+
enableDefinitions: boolean;
|
|
155
|
+
enableContentProtection: boolean;
|
|
156
|
+
enableTimeline: boolean;
|
|
157
|
+
autoGeneratePositions: boolean;
|
|
158
|
+
enableMediaOverlays: boolean;
|
|
159
|
+
enablePageBreaks: boolean;
|
|
160
|
+
enableLineFocus: boolean;
|
|
161
|
+
customKeyboardEvents: boolean;
|
|
162
|
+
enableHistory: boolean;
|
|
163
|
+
enableCitations: boolean;
|
|
164
|
+
enableConsumption: boolean;
|
|
165
|
+
}
|
|
166
|
+
export {};
|
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.16",
|
|
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",
|