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