@storyteller-platform/epub 0.7.1 → 0.8.1

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
@@ -1,5 +1,1163 @@
1
- import 'fast-xml-parser';
2
- export { AdapterOptions, EpubListEntry, EpubStorageAdapter, EpubStorageAdapterClass, EpubStorageCapabilities, EpubStorageKind } from './adapters/interface.js';
3
- export { A as AlternateScript, C as Collection, g as DcCreator, D as DcSubject, h as DublinCore, E as ElementName, o as Epub, Epub2UpgradeOptions, q as EpubFactory, e as EpubIdentifier, p as EpubInstanceFor, d as EpubMetadata, n as EpubReadOnlyError, l as EpubReader, f as EpubSource, m as EpubVersionError, F as FromOptions, I as InMemoryEpubReader, Landmark, M as ManifestItem, c as MetadataEntry, j as Navigation, N as NavigationItem, i as NavigationList, k as PackageElement, P as ParsedXml, X as XmlElement, b as XmlNode, a as XmlTextNode } from './upgrade.js';
4
- export { MemoryAdapter, MemoryAdapterOptions } from './adapters/memory.js';
5
- export { TmpFsAdapter } from './adapters/tmpfs.js';
1
+ import { XMLParser } from "fast-xml-parser";
2
+ import type { AdapterOptions, EpubStorageAdapter, EpubStorageAdapterClass, EpubStorageKind } from "./adapters/interface.ts";
3
+ import * as Upgrade from "./upgrade.ts";
4
+ export type { EpubStorageKind } from "./adapters/interface.ts";
5
+ export { type AdapterOptions, type EpubListEntry, type EpubStorageAdapter, type EpubStorageAdapterClass, type EpubStorageCapabilities, } from "./adapters/interface.ts";
6
+ export { MemoryAdapter, type MemoryAdapterOptions } from "./adapters/memory.ts";
7
+ export { TmpFsAdapter } from "./adapters/tmpfs.ts";
8
+ declare global {
9
+ namespace Intl {
10
+ interface Locale {
11
+ textInfo: {
12
+ direction: "rtl" | "ltr";
13
+ };
14
+ }
15
+ }
16
+ }
17
+ type Letter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
18
+ type QuestionMark = "?";
19
+ /** A valid name for an XML element (must start with a letter) */
20
+ export type ElementName = `${Letter | Uppercase<Letter> | QuestionMark}${string}`;
21
+ type PropertyPrefix = "@_";
22
+ /** An XML element */
23
+ export type XmlElement<Name extends ElementName = ElementName> = {
24
+ ":@"?: Record<`${PropertyPrefix}${string}`, string>;
25
+ } & {
26
+ [key in Name]: ParsedXml;
27
+ };
28
+ /** A text node in an XML document */
29
+ export type XmlTextNode = {
30
+ "#text": string;
31
+ };
32
+ /** A valid XML node. May be either an element or a text node. */
33
+ export type XmlNode = XmlElement | XmlTextNode;
34
+ /** An XML structure */
35
+ export type ParsedXml = Array<XmlNode>;
36
+ export type ManifestItem = {
37
+ id: string;
38
+ href: string;
39
+ mediaType?: string | undefined;
40
+ fallback?: string | undefined;
41
+ mediaOverlay?: string | undefined;
42
+ properties?: string[] | undefined;
43
+ };
44
+ export type MetadataEntry = {
45
+ id?: string | undefined;
46
+ type: ElementName;
47
+ properties: Record<string, string>;
48
+ value: string | undefined;
49
+ };
50
+ export type EpubMetadata = MetadataEntry[];
51
+ export interface DcSubject {
52
+ value: string;
53
+ authority: string;
54
+ term: string;
55
+ }
56
+ export interface EpubIdentifier {
57
+ value: string;
58
+ id?: string | undefined;
59
+ /** the value of a refining `identifier-type` meta, if present */
60
+ identifierType?: string | undefined;
61
+ /** the `scheme` of a refining `identifier-type` meta, or a legacy `opf:scheme` attribute */
62
+ scheme?: string | undefined;
63
+ }
64
+ export interface EpubSource {
65
+ value: string;
66
+ id?: string | undefined;
67
+ /** the value of a refining `identifier-type` meta, if present */
68
+ identifierType?: string | undefined;
69
+ /** the `scheme` of a refining `identifier-type` meta, or a legacy `opf:scheme` attribute */
70
+ scheme?: string | undefined;
71
+ /**
72
+ * whether this source has a `source-of="pagination"` refinement
73
+ * or of a `<meta property="pageBreakSource">` element
74
+ *
75
+ * as of EPUB 3.4 `source-of` is advised-deprecated in favour of the
76
+ * publication-level `pageBreakSource` property. if you want to
77
+ * be sure to get the source of pagination, use {@link Epub.getPageBreakSource}
78
+ */
79
+ isPageBreakSource?: boolean | undefined;
80
+ }
81
+ export interface AlternateScript {
82
+ name: string;
83
+ locale: Intl.Locale;
84
+ }
85
+ export interface DcCreator {
86
+ name: string;
87
+ role?: string;
88
+ roleScheme?: string;
89
+ fileAs?: string;
90
+ alternateScripts?: AlternateScript[];
91
+ }
92
+ export interface DublinCore {
93
+ title: string;
94
+ language: Intl.Locale;
95
+ identifier: string;
96
+ date?: Date;
97
+ subjects?: Array<string | DcSubject>;
98
+ creators?: DcCreator[];
99
+ contributors?: DcCreator[];
100
+ type?: string;
101
+ }
102
+ export interface Collection {
103
+ name: string;
104
+ type?: string;
105
+ position?: string;
106
+ }
107
+ export interface NavigationItem {
108
+ title: string;
109
+ href?: string;
110
+ role?: string;
111
+ children?: NavigationList;
112
+ }
113
+ export type NavigationList = NavigationItem[];
114
+ export interface Navigation {
115
+ title?: string;
116
+ role: string;
117
+ children: NavigationList;
118
+ }
119
+ interface GuideItem {
120
+ href: string;
121
+ title: string;
122
+ type: string;
123
+ }
124
+ export type PackageElement = XmlElement<"package">;
125
+ export interface FromOptions {
126
+ /**
127
+ * when true, mutation methods throw {@link EpubReadOnlyError} at runtime
128
+ * @default false
129
+ */
130
+ readonly?: boolean;
131
+ }
132
+ /**
133
+ * Read-only view of an EPUB
134
+ * Returned by Epub.using(MemoryAdapter).from(...) and by Epub.from(path, { readonly: true })
135
+ */
136
+ export type EpubReader = Pick<Epub, "storage" | "findMetadataItem" | "findAllMetadataItems" | "resolveHref" | "readFileContents" | "readItemContents" | "readXhtmlItemContents" | "discardAndClose" | Extract<keyof Epub, `get${string}`>> & Disposable;
137
+ /**
138
+ * Readonly Epub-instance backed by an in-memory zip handle
139
+ * Returned by `Epub.using(MemoryAdapter).from(...)`
140
+ */
141
+ export type InMemoryEpubReader = EpubReader & {
142
+ readonly storage: "in-memory";
143
+ };
144
+ export declare class EpubVersionError extends Error {
145
+ }
146
+ export declare class EpubReadOnlyError extends Error {
147
+ }
148
+ /**
149
+ * A single EPUB instance.
150
+ *
151
+ * The entire EPUB contents will be read into memory.
152
+ *
153
+ * Example usage:
154
+ *
155
+ * ```ts
156
+ * import { Epub, getBody, findByName, textContent } from '@storyteller-platform/epub';
157
+ *
158
+ * const epub = await Epub.from('./path/to/book.epub');
159
+ * const title = await epub.getTitle();
160
+ * const spineItems = await epub.getSpineItems();
161
+ * const chptOne = spineItems[0];
162
+ * const chptOneXml = await epub.readXhtmlItemContents(chptOne.id);
163
+ *
164
+ * const body = getBody(chptOneXml);
165
+ * const h1 = Epub.findXmlChildByName('h1', body);
166
+ * const headingText = textContent(h1);
167
+ *
168
+ * await epub.setTitle(headingText);
169
+ * await epub.writeToFile('./path/to/updated.epub');
170
+ * await epub.close();
171
+ * ```
172
+ *
173
+ * @link https://www.w3.org/TR/epub-33/
174
+ */
175
+ export declare class Epub {
176
+ protected adapterClass: EpubStorageAdapterClass;
177
+ protected adapter: EpubStorageAdapter;
178
+ protected inputPath: string | undefined;
179
+ protected readonlyOverride: boolean;
180
+ static xmlParser: XMLParser;
181
+ static xhtmlParser: XMLParser;
182
+ static xmlBuilder: import("fast-xml-builder").XMLBuilder;
183
+ static xhtmlBuilder: import("fast-xml-builder").XMLBuilder;
184
+ /**
185
+ * Format a duration, provided as a number of seconds, as
186
+ * a SMIL clock value, to be used for Media Overlays.
187
+ *
188
+ * @link https://www.w3.org/TR/epub-33/#sec-duration
189
+ */
190
+ static formatSmilDuration(duration: number): string;
191
+ /**
192
+ * Given an XML structure representing a complete XHTML document,
193
+ * add a `link` element to the `head` of the document.
194
+ *
195
+ * This method modifies the provided XML structure.
196
+ */
197
+ static addLinkToXhtmlHead(xml: ParsedXml, link: {
198
+ rel: string;
199
+ href: string;
200
+ type: string;
201
+ }): void;
202
+ /**
203
+ * Given an XML structure representing a complete XHTML document,
204
+ * return the sub-structure representing the children of the
205
+ * document's body element.
206
+ */
207
+ static getXhtmlBody(xml: ParsedXml): ParsedXml;
208
+ static createXmlElement<Name extends ElementName>(name: Name, properties: Record<string, string>, children?: XmlNode[]): XmlElement<Name>;
209
+ static createXmlTextNode(text: string): XmlTextNode;
210
+ /**
211
+ * Given an XML structure representing a complete XHTML document,
212
+ * return a string representing the concatenation of all text nodes
213
+ * in the document.
214
+ */
215
+ static getXhtmlTextContent(xml: ParsedXml): string;
216
+ /**
217
+ * Given an XMLElement, return its attributes.
218
+ */
219
+ static getXmlAttributes(element: XmlElement): Record<string, string>;
220
+ /**
221
+ * Given an XMLElement, return its tag name.
222
+ */
223
+ static getXmlElementName<Name extends ElementName>(element: XmlElement<Name>): Name;
224
+ /**
225
+ * Given an XMLElement, return a list of its children
226
+ */
227
+ static getXmlChildren<Name extends ElementName>(element: XmlElement<Name>): ParsedXml;
228
+ static replaceXmlChildren<Name extends ElementName>(element: XmlElement<Name>, children: XmlNode[]): void;
229
+ /**
230
+ * Given an XML structure, find the first child matching
231
+ * the provided name and optional filter.
232
+ */
233
+ static findXmlChildByName<Name extends ElementName>(name: Name, xml: ParsedXml, filter?: (node: XmlElement<Name>) => boolean): XmlElement<Name> | undefined;
234
+ /**
235
+ * Given an XML structure, find the first descendant matching
236
+ * the provided name and optional filter.
237
+ *
238
+ * Will perform a breadth first search for the element, returning
239
+ * the highest element in the tree matching the name and filter.
240
+ */
241
+ static findXmlDescendantByName<Name extends ElementName>(name: Name, xml: ParsedXml, filter?: (node: XmlElement<Name>) => boolean): XmlElement<Name> | undefined;
242
+ /**
243
+ * Given an XMLNode, determine whether it represents
244
+ * a text node or an XML element.
245
+ */
246
+ static isXmlTextNode(node: XmlNode): node is XmlTextNode;
247
+ private rootfile;
248
+ private manifest;
249
+ private spine;
250
+ private packageMutex;
251
+ /**
252
+ * Storage backend kind in use for this instance
253
+ *
254
+ * Public so callers can declare type-level requirements via {@link InMemoryEpubReader}
255
+ * Orthogonal to the read-only / writable axis (controlled by `readonlyOverride`
256
+ * and the adapter's capability bag)
257
+ */
258
+ readonly storage: EpubStorageKind;
259
+ /**
260
+ * Prefer the static factories ({@link Epub.using}, {@link Epub.from},
261
+ * {@link Epub.create}, {@link Epub.upgrade}) over calling this constructor
262
+ * directly. It's public so {@link EpubFactory} can construct instances; nothing
263
+ * else should need to.
264
+ */
265
+ constructor(adapterClass: EpubStorageAdapterClass, adapter: EpubStorageAdapter, inputPath: string | undefined, readonlyOverride?: boolean);
266
+ /**
267
+ * Runtime guard for mutation methods
268
+ */
269
+ private assertWritable;
270
+ /**
271
+ * Construct a new EPUB on a writable backend, optionally seeded
272
+ * with the provided metadata. Equivalent to
273
+ * `Epub.using(TmpFsAdapter).create(...)`.
274
+ *
275
+ * @param dublinCore Core metadata terms
276
+ * @param additionalMetadata An array of additional metadata entries
277
+ */
278
+ static create(path: string, dublinCore: DublinCore, additionalMetadata?: EpubMetadata): Promise<Epub>;
279
+ /**
280
+ * Specify the storage backend to use for the EPUB
281
+ *
282
+ * The returned factory exposes `from`, `create`, and `upgrade`,
283
+ * which route through the supplied adapter.
284
+ *
285
+ * @example
286
+ * ```ts
287
+ * using epub = await Epub.using(TmpFsAdapter).from(path)
288
+ * using reader = await Epub.using(MemoryAdapter).from(buffer, { cache: false })
289
+ * ```
290
+ */
291
+ static using<A extends EpubStorageAdapterClass>(adapterClass: A): EpubFactory<A>;
292
+ /**
293
+ * Open an existing EPUB publication, extracting it to a temp directory
294
+ * so writes can mutate the unpacked tree and rezip with `saveAndClose`.
295
+ *
296
+ * Pass `{ readonly: true }` to gate mutations at runtime.
297
+ *
298
+ * prefer `Epub.using(TmpFsAdapter).from(path)` (or
299
+ * `Epub.using(MemoryAdapter).from(path)` for read-only, in-memory access)
300
+ * @throws {EpubVersionError} when the archive is not a valid EPUB 3
301
+ */
302
+ static from(pathOrData: string | Uint8Array): Promise<Epub>;
303
+ static from(pathOrData: string | Uint8Array, options: FromOptions & {
304
+ readonly: true;
305
+ }): Promise<EpubReader>;
306
+ static from(pathOrData: string | Uint8Array, options?: FromOptions): Promise<Epub | EpubReader>;
307
+ static assertEpub3(epub: Epub): Promise<void>;
308
+ copy(path?: string): Promise<Epub>;
309
+ private removeEntry;
310
+ /**
311
+ * Length of the underlying archive entry for a manifest item, in bytes
312
+ * Necessary to compute the readium page count which is for COMPRESSED content
313
+ * @see {@link https://github.com/readium/architecture/issues/123}
314
+ */
315
+ getItemArchiveLength(id: string): Promise<number>;
316
+ getRootfile(): Promise<string>;
317
+ private getPackageDocument;
318
+ getPackageElement(): Promise<XmlElement<"package">>;
319
+ /**
320
+ * Safely modify the package document, without race conditions.
321
+ *
322
+ * Since the reading the package document is an async process,
323
+ * multiple simultaneously dispatched function calls that all
324
+ * attempt to modify it can clobber each other's changes. This
325
+ * method uses a mutex to ensure that each update runs exclusively.
326
+ *
327
+ * @param producer The function to update the package document. If
328
+ * it returns a new package document, that will be persisted, otherwise
329
+ * it will be assumed that the package document was modified in place.
330
+ */
331
+ withPackage(producer: ((packageElement: PackageElement) => void) | ((packageElement: PackageElement) => PackageElement) | ((packageElement: PackageElement) => Promise<PackageElement>) | ((packageElement: PackageElement) => Promise<void>)): Promise<void>;
332
+ /**
333
+ * Retrieve the manifest for the Epub.
334
+ *
335
+ * This is represented as a map from each manifest items'
336
+ * id to the rest of its properties.
337
+ *
338
+ * @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
339
+ */
340
+ getManifest(): Promise<Record<string, ManifestItem>>;
341
+ /**
342
+ * Returns the first index in the metadata element's children array
343
+ * that matches the provided predicate.
344
+ *
345
+ * Note: This may technically be different than the index in the
346
+ * getMetadata() array, as it includes non-metadata nodes, like
347
+ * text nodes. These are technically not allowed, but may exist,
348
+ * nonetheless. As consumers only ever see the getMetadata()
349
+ * array, this method is only meant to be used internally.
350
+ */
351
+ private findMetadataIndex;
352
+ /**
353
+ * Returns the item in the metadata element's children array
354
+ * that matches the provided predicate.
355
+ */
356
+ findMetadataItem(predicate: (entry: MetadataEntry) => boolean): Promise<{
357
+ id: string | undefined;
358
+ type: `?${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}`;
359
+ properties: {
360
+ [k: string]: string;
361
+ };
362
+ value: string | undefined;
363
+ } | null>;
364
+ /**
365
+ * Returns the item in the metadata element's children array
366
+ * that matches the provided predicate.
367
+ */
368
+ findAllMetadataItems(predicate: (entry: MetadataEntry) => boolean): Promise<{
369
+ id: string | undefined;
370
+ type: `?${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}`;
371
+ properties: {
372
+ [k: string]: string;
373
+ };
374
+ value: string | undefined;
375
+ }[]>;
376
+ private static parseMetadataItem;
377
+ /**
378
+ * Retrieve the metadata entries for the Epub.
379
+ *
380
+ * This is represented as an array of metadata entries,
381
+ * in the order that they're presented in the Epub package document.
382
+ *
383
+ * For more useful semantic representations of metadata, use
384
+ * specific methods such as `getTitle()` and `getAuthors()`.
385
+ *
386
+ * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
387
+ */
388
+ getMetadata(): Promise<EpubMetadata>;
389
+ /**
390
+ * Retrieve the first identifier from the dc:identifier element
391
+ * in the EPUB metadata.
392
+ *
393
+ * If there is no dc:identifier element, returns null.
394
+ *
395
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
396
+ *
397
+ * @deprecated Use {@link getUniqueIdentifier} instead to get the unique identifier,
398
+ * or {@link getIdentifiers} to get all identifiers.
399
+ */
400
+ getIdentifier(): Promise<string | null>;
401
+ /**
402
+ * Set the dc:identifier metadata element with the provided string.
403
+ *
404
+ * Updates the existing dc:identifier element if one exists.
405
+ * Otherwise creates a new element
406
+ *
407
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
408
+ *
409
+ * @deprecated Use {@link setUniqueIdentifier} instead.
410
+ */
411
+ setIdentifier(identifier: string): Promise<void>;
412
+ /**
413
+ * Retrieve the identifier with the unique identifier id
414
+ * in the EPUB metadata.
415
+ *
416
+ * If there is no unique identifier id, returns the first dc:identifier element.
417
+ *
418
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
419
+ */
420
+ getUniqueIdentifier(): Promise<string | null>;
421
+ /**
422
+ * Set the unique identifier id for the EPUB.
423
+ *
424
+ * Updates the existing dc:identifier element referenced by the unique identifier id if one exists.
425
+ * Otherwise creates a new element with the provided identifier, and sets the unique identifier id to the new element's id.
426
+ *
427
+ * Note: you likely shouldn't change the unique identifier id unless you are producing a new EPUB.
428
+ *
429
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
430
+ */
431
+ setUniqueIdentifier(identifier: string): Promise<void>;
432
+ /**
433
+ * Retrieve the id of the publication's unique identifier, as declared by the
434
+ * package element's `unique-identifier` attribute.
435
+ *
436
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
437
+ */
438
+ getUniqueIdentifierId(): Promise<string | null>;
439
+ /**
440
+ * Collect `dc:identifier` or `dc:source` entries, attaching the value and
441
+ * scheme of any refining `identifier-type` meta (spec D.3.8) and a legacy
442
+ * `opf:scheme` attribute. Values are not interpreted.
443
+ *
444
+ * `onRefinement` is invoked for every other meta refining a collected entry,
445
+ * so callers can surface element-specific refinements (e.g. `source-of` on a
446
+ * `dc:source`).
447
+ */
448
+ private static collectDcEntries;
449
+ /**
450
+ * Retrieve every `dc:identifier` entry, returned as found.
451
+ *
452
+ * Values are not interpreted. Any refining `identifier-type` meta (spec
453
+ * D.3.8) or legacy `opf:scheme` attribute is surfaced on the entry, but no
454
+ * parsing of the value itself is attempted. To read `dc:source` entries, use
455
+ * {@link getSources}.
456
+ *
457
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
458
+ */
459
+ getIdentifiers(): Promise<EpubIdentifier[]>;
460
+ /**
461
+ * Retrieve every `dc:source` entry, returned as found.
462
+ *
463
+ * Like {@link getIdentifiers}, values are not interpreted. In addition to a
464
+ * refining `identifier-type`, a refining `source-of` meta (spec D.3.11) is
465
+ * surfaced as `sourceOf`.
466
+ *
467
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcsource
468
+ */
469
+ getSources(): Promise<EpubSource[]>;
470
+ /**
471
+ * Retrieve the `pageBreakSource` property (EPUB 3.4, spec D.2.9), the
472
+ * publication-level source for the source of its page break markers.
473
+ *
474
+ * This property replaces the refining `source-of="pagination"` meta (spec
475
+ * D.3.11), see {@link EpubSource.sourceOf}. If no `pageBreakSource` property is found,
476
+ * we fall back to finding a `dc:source` with a `source-of="pagination"` refinement.
477
+ *
478
+ * @link https://www.w3.org/TR/epub/#pageBreakSource
479
+ */
480
+ getPageBreakSource(): Promise<EpubSource | null>;
481
+ /**
482
+ * Set the `pageBreakSource` property (EPUB 3.4, spec D.2.9), or remove it when
483
+ * passed null. Replaces an existing `pageBreakSource` meta if present.
484
+ *
485
+ * Pass `none` to indicate the pagination is unique to this publication.
486
+ *
487
+ * @link https://www.w3.org/TR/epub/#pageBreakSource
488
+ */
489
+ setPageBreakSource(value: string | null): Promise<void>;
490
+ /**
491
+ * Replace the publication's `dc:identifier` entries.
492
+ *
493
+ * This replaces ALL existing `dc:identifier` elements except the publication's
494
+ * unique identifier (the one referenced by the package element's
495
+ * `unique-identifier` attribute), which is always preserved and must not be
496
+ * included in the provided list. If included anyway, it is ignored. See
497
+ * {@link setUniqueIdentifier} to change it.
498
+ *
499
+ * Identifiers are placed in the order they are provided.
500
+ *
501
+ * `dc:source` entries are not touched, use {@link setSources} for those.
502
+ *
503
+ * When an entry has an `identifierType`, it is written in the refining form
504
+ * (a `meta` with `property="identifier-type"`, carrying the `scheme`
505
+ * attribute when provided). An entry with only a `scheme` is written using
506
+ * the legacy `opf:scheme` attribute.
507
+ *
508
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
509
+ */
510
+ setIdentifiers(identifiers: EpubIdentifier[]): Promise<void>;
511
+ /**
512
+ * Remove `meta` refinements pointing at any of the given ids,
513
+ * restricted to the given `property` values as a cleanup step
514
+ * Mutates `children` in place.
515
+ */
516
+ private static removeRefiningMetas;
517
+ /**
518
+ * Replace the publication's `dc:source` entries.
519
+ *
520
+ * This replaces ALL existing `dc:source` elements (and their refining
521
+ * `identifier-type` / `source-of` metas). `dc:identifier` entries are not
522
+ * touched; use {@link setIdentifiers} for those. Pass an empty array to
523
+ * remove all sources.
524
+ *
525
+ * When an entry has an `identifierType`, it is written in the refining form.
526
+ * A `sourceOf` value is written as a refining `source-of` meta (spec D.3.11).
527
+ * An entry with only a `scheme` uses the legacy `opf:scheme` attribute.
528
+ *
529
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcsource
530
+ */
531
+ setSources(sources: EpubSource[]): Promise<void>;
532
+ /**
533
+ * Even "EPUB 3" publications sometimes still only use the
534
+ * EPUB 2 specification for identifying the cover image.
535
+ * This is a private method that is used as a fallback if
536
+ * we fail to find the cover image according to the EPUB 3
537
+ * spec.
538
+ */
539
+ private getEpub2CoverImage;
540
+ /**
541
+ * Retrieve the cover image manifest item.
542
+ *
543
+ * This does not return the actual image data. To
544
+ * retrieve the image data, pass this item's id to
545
+ * epub.readItemContents, or use epub.getCoverImage()
546
+ * instead.
547
+ *
548
+ * @link https://www.w3.org/TR/epub-33/#sec-cover-image
549
+ */
550
+ getCoverImageItem(): Promise<ManifestItem | null>;
551
+ /**
552
+ * Retrieve the cover image data as a byte array.
553
+ *
554
+ * This does not include, for example, the cover image's
555
+ * filename or mime type. To retrieve the image manifest
556
+ * item, use epub.getCoverImageItem().
557
+ *
558
+ * @link https://www.w3.org/TR/epub-33/#sec-cover-image
559
+ */
560
+ getCoverImage(): Promise<Uint8Array<ArrayBufferLike> | null>;
561
+ /**
562
+ * Set the cover image for the EPUB.
563
+ *
564
+ * Adds a manifest item with the `cover-image` property, per
565
+ * the EPUB 3 spec, and then writes the provided image data to
566
+ * the provided href within the publication.
567
+ */
568
+ setCoverImage(href: string, data: Uint8Array): Promise<void>;
569
+ /**
570
+ * Retrieve the publication date from the dc:date element
571
+ * in the EPUB metadata as a Date object.
572
+ *
573
+ * If there is no dc:date element, returns null.
574
+ *
575
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcdate
576
+ */
577
+ getPublicationDate(): Promise<Date | null>;
578
+ /**
579
+ * Set the dc:date metadata element with the provided date.
580
+ *
581
+ * Updates the existing dc:date element if one exists.
582
+ * Otherwise creates a new element
583
+ *
584
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcdate
585
+ */
586
+ setPublicationDate(date: Date): Promise<void>;
587
+ /**
588
+ * Retrieve the modified date from the dcterms:modified metadata
589
+ * in the EPUB metadata as a Date object.
590
+ *
591
+ * If there is no meta element with dcterms:modified, returns null.
592
+ *
593
+ * @link https://www.w3.org/TR/epub-33/#sec-metadata-last-modified
594
+ */
595
+ getModifiedDate(): Promise<Date | null>;
596
+ /**
597
+ * Retrieve the layout from the rendition:layout meta element
598
+ * in the EPUB metadata.
599
+ *
600
+ * If there is no meta element, returns 'reflowable'.
601
+ *
602
+ * @link https://www.w3.org/TR/epub-33/#layout
603
+ */
604
+ getLayout(): Promise<"reflowable" | "pre-paginated">;
605
+ /**
606
+ * Retrieve the base direction from the package element.
607
+ *
608
+ * If there is no `dir` attribute on the package element,
609
+ * returns 'auto'.
610
+ *
611
+ * @link https://www.w3.org/TR/epub-33/#attrdef-dir
612
+ */
613
+ getBaseDirection(): Promise<"ltr" | "rtl" | "auto">;
614
+ /**
615
+ * Set the dc:type metadata element.
616
+ *
617
+ * Updates the existing dc:type element if one exists.
618
+ * Otherwise creates a new element.
619
+ *
620
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dctype
621
+ */
622
+ setType(type: string): Promise<void>;
623
+ /**
624
+ * Retrieve the publication type from the dc:type element
625
+ * in the EPUB metadata.
626
+ *
627
+ * If there is no dc:type element, returns null.
628
+ *
629
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dctype
630
+ */
631
+ getType(): Promise<MetadataEntry | null>;
632
+ /**
633
+ * Add a subject to the EPUB metadata.
634
+ *
635
+ * @param subject May be a string representing just a schema-less
636
+ * subject name, or a DcSubject object
637
+ *
638
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
639
+ */
640
+ addSubject(subject: string | DcSubject): Promise<void>;
641
+ /**
642
+ * Remove a subject from the EPUB metadata.
643
+ *
644
+ * Removes the subject at the provided index. This index
645
+ * refers to the array returned by `epub.getSubjects()`.
646
+ *
647
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
648
+ */
649
+ removeSubject(index: number): Promise<void>;
650
+ /**
651
+ * Retrieve the list of subjects for this EPUB.
652
+ *
653
+ * Subjects without associated authority and term metadata
654
+ * will be returned as strings. Otherwise, they will
655
+ * be represented as DcSubject objects, with a value,
656
+ * authority, and term.
657
+ *
658
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
659
+ */
660
+ getSubjects(): Promise<(string | DcSubject)[]>;
661
+ /**
662
+ * Retrieve the Epub's language as specified in its
663
+ * package document metadata.
664
+ *
665
+ * If no language metadata is specified, returns null.
666
+ * Returns the language as an Intl.Locale instance.
667
+ *
668
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
669
+ */
670
+ getLanguage(): Promise<Intl.Locale | null>;
671
+ /**
672
+ * Update the Epub's language metadata entry.
673
+ *
674
+ * Updates the existing dc:language element if one exists.
675
+ * Otherwise creates a new element
676
+ *
677
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
678
+ */
679
+ setLanguage(locale: Intl.Locale): Promise<void>;
680
+ /**
681
+ * Retrieve the title of the Epub.
682
+ *
683
+ * @param main Optional - whether to return only the first title segment
684
+ * if multiple are found. Otherwise, will follow the spec to combine title
685
+ * segments
686
+ *
687
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
688
+ */
689
+ getTitle(expanded?: boolean): Promise<string | null>;
690
+ /**
691
+ * Retrieve the subtitle of the Epub, if it exists.
692
+ *
693
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
694
+ */
695
+ getSubtitle(): Promise<string | null>;
696
+ /**
697
+ * Retrieve all title entries of the Epub.
698
+ *
699
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
700
+ */
701
+ getTitles(): Promise<{
702
+ title: string;
703
+ type: string | null;
704
+ }[]>;
705
+ /**
706
+ * Update the Epub's description metadata entry.
707
+ *
708
+ * Updates the existing dc:description element if one exists.
709
+ * Otherwise creates a new element. Any non-ASCII symbols,
710
+ * `&`, `<`, `>`, `"`, `'`, and `\``` will be encoded as HTML entities.
711
+ */
712
+ setDescription(description: string): Promise<void>;
713
+ /**
714
+ * Retrieve the Epub's description as specified in its
715
+ * package document metadata.
716
+ *
717
+ * If no description metadata is specified, returns null.
718
+ * Returns the description as a string. Descriptions may
719
+ * include HTML markup.
720
+ */
721
+ getDescription(): Promise<string | null>;
722
+ /**
723
+ * Return the set of custom vocabulary prefixes set on this publication's
724
+ * root package element.
725
+ *
726
+ * Returns a map from prefix to URI
727
+ *
728
+ * @link https://www.w3.org/TR/epub-33/#sec-prefix-attr
729
+ */
730
+ getPackageVocabularyPrefixes(): Promise<Record<string, string>>;
731
+ /**
732
+ * Set a custom vocabulary prefix on the root package element.
733
+ *
734
+ * @link https://www.w3.org/TR/epub-33/#sec-prefix-attr
735
+ */
736
+ setPackageVocabularyPrefix(prefix: string, uri: string): Promise<void>;
737
+ /**
738
+ * Set the title of the Epub.
739
+ *
740
+ * This will replace all existing dc:title elements with
741
+ * this title. It will be given title-type "main".
742
+ *
743
+ * To set specific titles and their types, use epub.setTitles().
744
+ *
745
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
746
+ */
747
+ setTitle(title: string): Promise<void>;
748
+ setTitles(entries: {
749
+ title: string;
750
+ type: string | null;
751
+ }[]): Promise<void>;
752
+ /**
753
+ * Retrieve the list of collections.
754
+ */
755
+ getCollections(): Promise<Collection[]>;
756
+ /**
757
+ * Add a collection to the EPUB metadata.
758
+ *
759
+ * If index is provided, the collection will be placed at
760
+ * that index in the list of collections. Otherwise, it
761
+ * will be added to the end of the list.
762
+ */
763
+ addCollection(collection: Collection, index?: number): Promise<void>;
764
+ /**
765
+ * Remove a collection from the EPUB metadata.
766
+ *
767
+ * Removes the collection at the provided index. This index
768
+ * refers to the array returned by `epub.getCollections()`.
769
+ */
770
+ removeCollection(index: number): Promise<void>;
771
+ /**
772
+ * Retrieve the list of creators.
773
+ *
774
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
775
+ */
776
+ getCreators(type?: "creator" | "contributor"): Promise<DcCreator[]>;
777
+ /**
778
+ * Retrieve the list of contributors.
779
+ *
780
+ * This is a convenience method for
781
+ * `epub.getCreators('contributor')`.
782
+ *
783
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dccontributor
784
+ */
785
+ getContributors(): Promise<DcCreator[]>;
786
+ /**
787
+ * Add a creator to the EPUB metadata.
788
+ *
789
+ * If index is provided, the creator will be placed at
790
+ * that index in the list of creators. Otherwise, it
791
+ * will be added to the end of the list.
792
+ *
793
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
794
+ */
795
+ addCreator(creator: DcCreator, index?: number, type?: "creator" | "contributor"): Promise<void>;
796
+ /**
797
+ * Remove a creator from the EPUB metadata.
798
+ *
799
+ * Removes the creator at the provided index. This index
800
+ * refers to the array returned by `epub.getCreators()`.
801
+ *
802
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
803
+ */
804
+ removeCreator(index: number, type?: "creator" | "contributor"): Promise<void>;
805
+ /**
806
+ * Remove a contributor from the EPUB metadata.
807
+ *
808
+ * Removes the contributor at the provided index. This index
809
+ * refers to the array returned by `epub.getContributors()`.
810
+ *
811
+ * This is a convenience method for
812
+ * `epub.removeCreator(index, 'contributor')`.
813
+ *
814
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
815
+ */
816
+ removeContributor(index: number): Promise<void>;
817
+ /**
818
+ * Add a contributor to the EPUB metadata.
819
+ *
820
+ * If index is provided, the creator will be placed at
821
+ * that index in the list of creators. Otherwise, it
822
+ * will be added to the end of the list.
823
+ *
824
+ * This is a convenience method for
825
+ * `epub.addCreator(contributor, index, 'contributor')`.
826
+ *
827
+ * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
828
+ */
829
+ addContributor(contributor: DcCreator, index?: number): Promise<void>;
830
+ private getSpine;
831
+ /**
832
+ * Retrieve the manifest items that make up the Epub's spine.
833
+ *
834
+ * The spine specifies the order that the contents of the Epub
835
+ * should be displayed to users by default.
836
+ *
837
+ * @link https://www.w3.org/TR/epub-33/#sec-spine-elem
838
+ */
839
+ getSpineItems(): Promise<ManifestItem[]>;
840
+ /**
841
+ * Add an item to the spine of the EPUB.
842
+ *
843
+ * If `index` is undefined, the item will be added
844
+ * to the end of the spine. Otherwise it will be
845
+ * inserted at the specified index.
846
+ *
847
+ * If the manifestId does not correspond to an item
848
+ * in the manifest, this will throw an error.
849
+ *
850
+ * @link https://www.w3.org/TR/epub-33/#sec-spine-elem
851
+ */
852
+ addSpineItem(manifestId: string, index?: number): Promise<void>;
853
+ /**
854
+ * Remove the spine item at the specified index.
855
+ *
856
+ * @link https://www.w3.org/TR/epub-33/#sec-spine-elem
857
+ */
858
+ removeSpineItem(index: number): Promise<void>;
859
+ private getNavigationChildren;
860
+ private getNavigation;
861
+ /**
862
+ * Returns the structured table of contents navigation document
863
+ * as a Navigation object.
864
+ *
865
+ * @link https://www.w3.org/TR/epub-33/#sec-nav-toc
866
+ */
867
+ getTableOfContents({ resolveToRoot, }?: {
868
+ resolveToRoot?: boolean;
869
+ }): Promise<Navigation | null>;
870
+ /**
871
+ * Returns the structured landmarks navigation document
872
+ * as a Navigation object
873
+ *
874
+ * @link https://www.w3.org/TR/epub-33/#sec-nav-landmarks
875
+ */
876
+ getLandmarks({ resolveToRoot, }?: {
877
+ resolveToRoot?: boolean;
878
+ }): Promise<Navigation | null>;
879
+ /**
880
+ * Returns the structured page list navigation document
881
+ * as a Navigation object
882
+ *
883
+ * @link https://www.w3.org/TR/epub-33/#sec-nav-landmarks
884
+ */
885
+ getPageList({ resolveToRoot, }?: {
886
+ resolveToRoot?: boolean;
887
+ }): Promise<Navigation | null>;
888
+ /**
889
+ * Name the entry a resolved URL addresses.
890
+ *
891
+ * A correctly authored publication percent-encodes its hrefs, so the
892
+ * decoded reading is the one the spec calls for and the one we prefer.
893
+ * Some publications instead write the entry name verbatim, so when the two
894
+ * readings differ we ask the archive which one it holds. A verbatim name
895
+ * carrying a bare `%`, as `100%.xhtml` does, is not a valid encoding at all
896
+ * and can only be its own answer.
897
+ */
898
+ private entryForUrl;
899
+ /**
900
+ * Resolve an href to the name of the archive entry it addresses.
901
+ *
902
+ * @param from The entry the href appears in; it resolves against that
903
+ * entry's directory
904
+ * @throws when the href addresses something outside the publication
905
+ */
906
+ private resolveEntry;
907
+ /**
908
+ * Returns a path-relative-scheme-less URL, relative to the
909
+ * container root.
910
+ *
911
+ * An href that points outside the publication, such as an external link in
912
+ * a navigation document, is handed back unchanged.
913
+ *
914
+ * @param href The href to resolve
915
+ * @param [relativeTo] Optional - The href to resolve this href relative to.
916
+ Use if resolving a relative href from a file other than the package document.
917
+ */
918
+ resolveHref(href: string, relativeTo?: string, { toRoot }?: {
919
+ toRoot?: boolean | undefined;
920
+ }): Promise<string>;
921
+ /**
922
+ * Retrieve the contents of a file, given its href.
923
+ *
924
+ * Optionally takes the href that this href should be resolved relative to,
925
+ * and an encoding parameter.
926
+ *
927
+ * @param href The href of the file to retrieve
928
+ * @param [relitaveTo] Optional - The href to resolve this href relative to.
929
+ * Use if resolving a relative href from a file other than the package document.
930
+ * @param [encoding] Optional - Must be the string "utf-8". If provided,
931
+ * the function will encode the data into a unicode string.
932
+ * Otherwise, the data will be returned as a byte array.
933
+ */
934
+ readFileContents(href: string, relativeTo?: string): Promise<Uint8Array>;
935
+ readFileContents(href: string, relativeTo: string | undefined, encoding: "utf-8"): Promise<string>;
936
+ /**
937
+ * Retrieve the contents of a manifest item, given its id.
938
+ *
939
+ * @param id The id of the manifest item to retrieve
940
+ * @param [encoding] Optional - must be the string "utf-8". If
941
+ * provided, the function will encode the data into a unicode string.
942
+ * Otherwise, the data will be returned as a byte array.
943
+ *
944
+ * @link https://www.w3.org/TR/epub-33/#sec-contentdocs
945
+ */
946
+ readItemContents(id: string): Promise<Uint8Array>;
947
+ readItemContents(id: string, encoding: "utf-8"): Promise<string>;
948
+ /**
949
+ * Create a new XHTML document with the given body
950
+ * and head.
951
+ *
952
+ * @param body The XML nodes to place in the body of the document
953
+ * @param head Optional - the XMl nodes to place in the head
954
+ * @param language Optional - defaults to the EPUB's language
955
+ */
956
+ createXhtmlDocument(body: ParsedXml, head?: ParsedXml, language?: Intl.Locale): Promise<(XmlElement<"?xml"> | XmlElement<"html">)[]>;
957
+ /**
958
+ * Retrieves the contents of an XHTML item, given its manifest id.
959
+ *
960
+ * @param id The id of the manifest item to retrieve
961
+ * @param [as] Optional - whether to return the parsed XML document tree,
962
+ * or the concatenated text of the document. Defaults to the parsed XML tree.
963
+ *
964
+ * @link https://www.w3.org/TR/epub-33/#sec-xhtml
965
+ */
966
+ readXhtmlItemContents(id: string, as?: "xhtml"): Promise<ParsedXml>;
967
+ readXhtmlItemContents(id: string, as: "text"): Promise<string>;
968
+ private writeEntryContents;
969
+ /**
970
+ * Write new contents for an existing manifest item,
971
+ * specified by its id.
972
+ *
973
+ * The id must reference an existing manifest item. If
974
+ * creating a new item, use `epub.addManifestItem()` instead.
975
+ *
976
+ * @param id The id of the manifest item to write new contents for
977
+ * @param contents The new contents. May be either a utf-8 encoded string
978
+ * or a byte array, as determined by the encoding
979
+ * @param [encoding] Optional - must be the string "utf-8". If provided,
980
+ * the contents will be interpreted as a unicode string. Otherwise, the
981
+ * contents must be a byte array.
982
+ *
983
+ * @link https://www.w3.org/TR/epub-33/#sec-contentdocs
984
+ */
985
+ writeItemContents(id: string, contents: Uint8Array): Promise<void>;
986
+ writeItemContents(id: string, contents: string, encoding: "utf-8"): Promise<void>;
987
+ /**
988
+ * Write new contents for an existing XHTML item,
989
+ * specified by its id.
990
+ *
991
+ * The id must reference an existing manifest item. If
992
+ * creating a new item, use `epub.addManifestItem()` instead.
993
+ *
994
+ * @param id The id of the manifest item to write new contents for
995
+ * @param contents The new contents. Must be a parsed XML tree.
996
+ *
997
+ * @link https://www.w3.org/TR/epub-33/#sec-xhtml
998
+ */
999
+ writeXhtmlItemContents(id: string, contents: ParsedXml): Promise<void>;
1000
+ removeManifestItem(id: string): Promise<void>;
1001
+ /**
1002
+ * Create a new manifest item and write its contents to a
1003
+ * new entry.
1004
+ *
1005
+ * @param id The id of the manifest item to write new contents for
1006
+ * @param contents The new contents. May be either a parsed XML tree
1007
+ * or a unicode string, as determined by the `as` argument.
1008
+ * @param encoding Optional - whether to interpret contents as a parsed
1009
+ * XML tree, a unicode string, or a byte array. Defaults to a byte array.
1010
+ *
1011
+ * @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
1012
+ * @link https://www.w3.org/TR/epub-33/#sec-contentdocs
1013
+ */
1014
+ addManifestItem(item: ManifestItem, contents: ParsedXml, encoding: "xml"): Promise<void>;
1015
+ addManifestItem(item: ManifestItem, contents: string, encoding: "utf-8"): Promise<void>;
1016
+ addManifestItem(item: ManifestItem, contents: Uint8Array): Promise<void>;
1017
+ /**
1018
+ * Update the manifest entry for an existing item.
1019
+ *
1020
+ * To update the contents of an entry, use `epub.writeItemContents()`
1021
+ * or `epub.writeXhtmlItemContents()`
1022
+ *
1023
+ * @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
1024
+ */
1025
+ updateManifestItem(id: string, newItem: Omit<ManifestItem, "id">): Promise<void>;
1026
+ /**
1027
+ * Add a new metadata entry to the Epub.
1028
+ *
1029
+ * This method, like `epub.getMetadata()`, operates on
1030
+ * metadata entries. For more useful semantic representations
1031
+ * of metadata, use specific methods such as `setTitle()` and
1032
+ * `setLanguage()`.
1033
+ *
1034
+ * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
1035
+ */
1036
+ addMetadata(entry: MetadataEntry): Promise<void>;
1037
+ /**
1038
+ * Replace a metadata entry with a new one.
1039
+ *
1040
+ * The `predicate` argument will be used to determine which entry
1041
+ * to replace. The first metadata entry that matches the
1042
+ * predicate will be replaced.
1043
+ *
1044
+ * @param predicate Calls predicate once for each metadata entry,
1045
+ * until it finds one where predicate returns true
1046
+ * @param entry The new entry to replace the found entry with
1047
+ *
1048
+ * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
1049
+ */
1050
+ replaceMetadata(predicate: (entry: MetadataEntry) => boolean, entry: MetadataEntry): Promise<void>;
1051
+ /**
1052
+ * Remove one or more metadata entries.
1053
+ *
1054
+ * The `predicate` argument will be used to determine which entries
1055
+ * to remove. The all metadata entries that match the
1056
+ * predicate will be removed.
1057
+ *
1058
+ * @param predicate Calls predicate once for each metadata entry,
1059
+ * removing any for which it returns true
1060
+ *
1061
+ * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
1062
+ */
1063
+ removeMetadata(predicate: (entry: MetadataEntry) => boolean): Promise<void>;
1064
+ /**
1065
+ * Returns the EPUB version declared on the package element.
1066
+ */
1067
+ getVersion(): Promise<string>;
1068
+ /**
1069
+ * Parse the NCX table of contents, if one exists, and return
1070
+ * a tree of TocEntry nodes.
1071
+ *
1072
+ * Useful for both EPUB 2 publications (where the NCX is the
1073
+ * primary navigation) and EPUB 3 publications that retain an
1074
+ * NCX for backwards compatibility.
1075
+ */
1076
+ getNcxTableOfContents(): Promise<NavigationList>;
1077
+ private parseNavPoints;
1078
+ /**
1079
+ * Retrieve the guide entries from the package document.
1080
+ *
1081
+ * The guide element is deprecated in EPUB 3 in favor of
1082
+ * the landmarks nav, but many publications still include it.
1083
+ */
1084
+ getGuideEntries(): Promise<GuideItem[]>;
1085
+ discardAndClose(): void;
1086
+ /**
1087
+ * Write the current contents of the Epub to a new
1088
+ * EPUB archive on disk.
1089
+ *
1090
+ * When this method is called, the "dcterms:modified"
1091
+ * meta tag is automatically updated to the current UTC
1092
+ * timestamp.
1093
+ */
1094
+ saveAndClose(): Promise<void>;
1095
+ /**
1096
+ * Upgrade an EPUB 2 publication to EPUB 3 in place, returning a new,
1097
+ * valid Epub 3 instance. Equivalent to
1098
+ * `Epub.using(TmpFsAdapter).upgrade(...)`.
1099
+ */
1100
+ static upgrade(path: string, options?: Upgrade.Epub2UpgradeOptions): Promise<Epub>;
1101
+ [Symbol.dispose](): void;
1102
+ }
1103
+ /**
1104
+ * Resolves to {@link Epub} for writable adapters, {@link EpubReader} for read-only ones.
1105
+ *
1106
+ * The conditional pivots on `capabilities.writable`, which must be a literal
1107
+ * `true`/`false` on the adapter class (use `as const`) for inference to work.
1108
+ */
1109
+ export type EpubInstanceFor<A extends EpubStorageAdapterClass> = A["capabilities"]["writable"] extends true ? Epub : EpubReader;
1110
+ /**
1111
+ * Adapter-bound factory returned by {@link Epub.using}.
1112
+ *
1113
+ * Mirrors the static factory surface (`from`, `create`, `upgrade`) but routes
1114
+ * all I/O through the supplied adapter. Each method's signature degrades
1115
+ * gracefully when the adapter doesn't support the operation: `create` and
1116
+ * `upgrade` throw at runtime if the adapter is read-only or lacks `initEmpty`.
1117
+ */
1118
+ export declare class EpubFactory<A extends EpubStorageAdapterClass> {
1119
+ readonly adapterClass: A;
1120
+ constructor(adapterClass: A);
1121
+ /**
1122
+ * Open an existing EPUB through this factory's adapter
1123
+ *
1124
+ * @throws {EpubVersionError} when the archive is not a valid EPUB 3
1125
+ */
1126
+ from(source: string | Uint8Array, options: FromOptions & {
1127
+ readonly: true;
1128
+ } & AdapterOptions<A>): Promise<EpubReader & {
1129
+ storage: A["kind"];
1130
+ }>;
1131
+ from(source: string | Uint8Array, options?: FromOptions & AdapterOptions<A>): Promise<EpubInstanceFor<A> & {
1132
+ storage: A["kind"];
1133
+ }>;
1134
+ /**
1135
+ * Construct a new EPUB on this factory's adapter, optionally seeded
1136
+ * with the provided metadata. Requires a writable adapter that
1137
+ * implements `initEmpty` (today: {@link TmpFsAdapter}).
1138
+ *
1139
+ * @throws when the adapter is read-only or does not implement initEmpty
1140
+ */
1141
+ create(path: string, { title, language, identifier, date, subjects, type, creators, contributors, }: DublinCore, additionalMetadata?: EpubMetadata): Promise<EpubInstanceFor<A>>;
1142
+ /**
1143
+ * Upgrade an EPUB 2 publication to EPUB 3 in place using this
1144
+ * factory's adapter, returning a new, valid Epub 3 instance.
1145
+ *
1146
+ * Performs the following transformations:
1147
+ * - upgrades OPF metadata to EPUB 3 conventions
1148
+ * - scans XHTML documents and adds manifest item properties
1149
+ * - parses the NCX into a TOC tree and generates a nav.xhtml
1150
+ * - removes the NCX file and the guide element (configurable)
1151
+ * - fixes common font MIME types
1152
+ * - bumps the package version to 3.0
1153
+ * - goes over each xhtml item and rewrites it using XMLParser to make sure the output is valid XHTML
1154
+ *
1155
+ * Requires a writable adapter. When {@link Upgrade.Epub2UpgradeOptions.outputPath}
1156
+ * is set, the source file is copied to that path on disk first; this
1157
+ * only makes sense for adapters whose `source` is a real fs path.
1158
+ *
1159
+ * @throws when the adapter is read-only
1160
+ */
1161
+ upgrade(path: string, options?: Upgrade.Epub2UpgradeOptions): Promise<EpubInstanceFor<A>>;
1162
+ }
1163
+ export type { Epub2UpgradeOptions, Landmark } from "./upgrade.ts";