@d-i-t-a/reader 3.0.0-alpha.14 → 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.
@@ -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
- export type GetContent = (href: string) => Promise<string>;
26
- export type GetContentBytesLength = (href: string, requestConfig?: RequestConfig) => Promise<number>;
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
- type: string;
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
- r2after?: boolean;
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
- url: URL;
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;
@@ -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>);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-i-t-a/reader",
3
- "version": "3.0.0-alpha.14",
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",