@storyteller-platform/epub 0.7.0 → 0.8.0

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