@storyteller-platform/epub 0.4.9 → 0.5.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.cts CHANGED
@@ -1,744 +1,2 @@
1
- import { XMLParser, XMLBuilder } from 'fast-xml-parser';
2
-
3
- declare global {
4
- namespace Intl {
5
- interface Locale {
6
- textInfo: {
7
- direction: "rtl" | "ltr";
8
- };
9
- }
10
- }
11
- }
12
- 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";
13
- type QuestionMark = "?";
14
- /** A valid name for an XML element (must start with a letter) */
15
- type ElementName = `${Letter | Uppercase<Letter> | QuestionMark}${string}`;
16
- type PropertyPrefix = "@_";
17
- /** An XML element */
18
- type XmlElement<Name extends ElementName = ElementName> = {
19
- ":@"?: Record<`${PropertyPrefix}${string}`, string>;
20
- } & {
21
- [key in Name]: ParsedXml;
22
- };
23
- /** A text node in an XML document */
24
- type XmlTextNode = {
25
- "#text": string;
26
- };
27
- /** A valid XML node. May be either an element or a text node. */
28
- type XmlNode = XmlElement | XmlTextNode;
29
- /** An XML structure */
30
- type ParsedXml = Array<XmlNode>;
31
- type ManifestItem = {
32
- id: string;
33
- href: string;
34
- mediaType?: string | undefined;
35
- fallback?: string | undefined;
36
- mediaOverlay?: string | undefined;
37
- properties?: string[] | undefined;
38
- };
39
- type MetadataEntry = {
40
- id?: string | undefined;
41
- type: ElementName;
42
- properties: Record<string, string>;
43
- value: string | undefined;
44
- };
45
- type EpubMetadata = MetadataEntry[];
46
- interface DcSubject {
47
- value: string;
48
- authority: string;
49
- term: string;
50
- }
51
- interface AlternateScript {
52
- name: string;
53
- locale: Intl.Locale;
54
- }
55
- interface DcCreator {
56
- name: string;
57
- role?: string;
58
- roleScheme?: string;
59
- fileAs?: string;
60
- alternateScripts?: AlternateScript[];
61
- }
62
- interface DublinCore {
63
- title: string;
64
- language: Intl.Locale;
65
- identifier: string;
66
- date?: Date;
67
- subjects?: Array<string | DcSubject>;
68
- creators?: DcCreator[];
69
- contributors?: DcCreator[];
70
- type?: string;
71
- }
72
- interface Collection {
73
- name: string;
74
- type?: string;
75
- position?: string;
76
- }
77
- type PackageElement = XmlElement<"package"> | XmlElement<"opf:package">;
78
- /**
79
- * A single EPUB instance.
80
- *
81
- * The entire EPUB contents will be read into memory.
82
- *
83
- * Example usage:
84
- *
85
- * ```ts
86
- * import { Epub, getBody, findByName, textContent } from '@storyteller-platform/epub';
87
- *
88
- * const epub = await Epub.from('./path/to/book.epub');
89
- * const title = await epub.getTitle();
90
- * const spineItems = await epub.getSpineItems();
91
- * const chptOne = spineItems[0];
92
- * const chptOneXml = await epub.readXhtmlItemContents(chptOne.id);
93
- *
94
- * const body = getBody(chptOneXml);
95
- * const h1 = Epub.findXmlChildByName('h1', body);
96
- * const headingText = textContent(h1);
97
- *
98
- * await epub.setTitle(headingText);
99
- * await epub.writeToFile('./path/to/updated.epub');
100
- * await epub.close();
101
- * ```
102
- *
103
- * @link https://www.w3.org/TR/epub-33/
104
- */
105
- declare class Epub {
106
- protected extractPath: string;
107
- protected inputPath: string | undefined;
108
- static xmlParser: XMLParser;
109
- static xhtmlParser: XMLParser;
110
- static xmlBuilder: XMLBuilder;
111
- static xhtmlBuilder: XMLBuilder;
112
- /**
113
- * Format a duration, provided as a number of seconds, as
114
- * a SMIL clock value, to be used for Media Overlays.
115
- *
116
- * @link https://www.w3.org/TR/epub-33/#sec-duration
117
- */
118
- static formatSmilDuration(duration: number): string;
119
- /**
120
- * Given an XML structure representing a complete XHTML document,
121
- * add a `link` element to the `head` of the document.
122
- *
123
- * This method modifies the provided XML structure.
124
- */
125
- static addLinkToXhtmlHead(xml: ParsedXml, link: {
126
- rel: string;
127
- href: string;
128
- type: string;
129
- }): void;
130
- /**
131
- * Given an XML structure representing a complete XHTML document,
132
- * return the sub-structure representing the children of the
133
- * document's body element.
134
- */
135
- static getXhtmlBody(xml: ParsedXml): ParsedXml;
136
- static createXmlElement<Name extends ElementName>(name: Name, properties: Record<string, string>, children?: XmlNode[]): XmlElement<Name>;
137
- static createXmlTextNode(text: string): XmlTextNode;
138
- /**
139
- * Given an XML structure representing a complete XHTML document,
140
- * return a string representing the concatenation of all text nodes
141
- * in the document.
142
- */
143
- static getXhtmlTextContent(xml: ParsedXml): string;
144
- /**
145
- * Given an XMLElement, return its attributes.
146
- */
147
- static getXmlAttributes(element: XmlElement): Record<string, string>;
148
- /**
149
- * Given an XMLElement, return its tag name.
150
- */
151
- static getXmlElementName<Name extends ElementName>(element: XmlElement<Name>): Name;
152
- /**
153
- * Given an XMLElement, return a list of its children
154
- */
155
- static getXmlChildren<Name extends ElementName>(element: XmlElement<Name>): ParsedXml;
156
- static replaceXmlChildren<Name extends ElementName>(element: XmlElement<Name>, children: XmlNode[]): void;
157
- /**
158
- * Given an XML structure, find the first child matching
159
- * the provided name and optional filter.
160
- */
161
- static findXmlChildByName<Name extends ElementName>(name: Name, xml: ParsedXml, filter?: (node: XmlNode) => boolean): XmlElement<Name> | undefined;
162
- /**
163
- * Given an XMLNode, determine whether it represents
164
- * a text node or an XML element.
165
- */
166
- static isXmlTextNode(node: XmlNode): node is XmlTextNode;
167
- private rootfile;
168
- private manifest;
169
- private spine;
170
- private packageMutex;
171
- protected constructor(extractPath: string, inputPath: string | undefined);
172
- /**
173
- * Construct an Epub instance, optionally beginning
174
- * with the provided metadata.
175
- *
176
- * @param dublinCore Core metadata terms
177
- * @param additionalMetadata An array of additional metadata entries
178
- */
179
- static create(path: string, { title, language, identifier, date, subjects, type, creators, contributors, }: DublinCore, additionalMetadata?: EpubMetadata): Promise<Epub>;
180
- /**
181
- * Construct an Epub instance by reading an existing EPUB
182
- * publication.
183
- *
184
- * @param pathOrData Must be either a string representing the
185
- * path to an EPUB file on disk, or a Uint8Array representing
186
- * the data of the EPUB publication.
187
- */
188
- static from(pathOrData: string | Uint8Array): Promise<Epub>;
189
- copy(path?: string): Promise<Epub>;
190
- private removeEntry;
191
- private getFileData;
192
- getRootfile(): Promise<string>;
193
- private migratePackageDocument;
194
- private getPackageDocument;
195
- private getPackageElement;
196
- /**
197
- * Safely modify the package document, without race conditions.
198
- *
199
- * Since the reading the package document is an async process,
200
- * multiple simultaneously dispatched function calls that all
201
- * attempt to modify it can clobber each other's changes. This
202
- * method uses a mutex to ensure that each update runs exclusively.
203
- *
204
- * @param producer The function to update the package document. If
205
- * it returns a new package document, that will be persisted, otherwise
206
- * it will be assumed that the package document was modified in place.
207
- */
208
- private withPackage;
209
- /**
210
- * Retrieve the manifest for the Epub.
211
- *
212
- * This is represented as a map from each manifest items'
213
- * id to the rest of its properties.
214
- *
215
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
216
- */
217
- getManifest(): Promise<Record<string, ManifestItem>>;
218
- /**
219
- * Returns the first index in the metadata element's children array
220
- * that matches the provided predicate.
221
- *
222
- * Note: This may technically be different than the index in the
223
- * getMetadata() array, as it includes non-metadata nodes, like
224
- * text nodes. These are technically not allowed, but may exist,
225
- * nonetheless. As consumers only ever see the getMetadata()
226
- * array, this method is only meant to be used internally.
227
- */
228
- private findMetadataIndex;
229
- /**
230
- * Returns the item in the metadata element's children array
231
- * that matches the provided predicate.
232
- */
233
- findMetadataItem(predicate: (entry: MetadataEntry) => boolean): Promise<{
234
- id: string | undefined;
235
- type: `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}` | `?${string}`;
236
- properties: {
237
- [k: string]: string;
238
- };
239
- value: string | undefined;
240
- } | null>;
241
- /**
242
- * Returns the item in the metadata element's children array
243
- * that matches the provided predicate.
244
- */
245
- findAllMetadataItems(predicate: (entry: MetadataEntry) => boolean): Promise<{
246
- id: string | undefined;
247
- type: `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}` | `?${string}`;
248
- properties: {
249
- [k: string]: string;
250
- };
251
- value: string | undefined;
252
- }[]>;
253
- private static parseMetadataItem;
254
- /**
255
- * Retrieve the metadata entries for the Epub.
256
- *
257
- * This is represented as an array of metadata entries,
258
- * in the order that they're presented in the Epub package document.
259
- *
260
- * For more useful semantic representations of metadata, use
261
- * specific methods such as `getTitle()` and `getAuthors()`.
262
- *
263
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
264
- */
265
- getMetadata(): Promise<EpubMetadata>;
266
- /**
267
- * Retrieve the identifier from the dc:identifier element
268
- * in the EPUB metadata.
269
- *
270
- * If there is no dc:identifier element, returns null.
271
- *
272
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
273
- */
274
- getIdentifier(): Promise<string | null>;
275
- /**
276
- * Set the dc:identifier metadata element with the provided string.
277
- *
278
- * Updates the existing dc:identifier element if one exists.
279
- * Otherwise creates a new element
280
- *
281
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
282
- */
283
- setIdentifier(identifier: string): Promise<void>;
284
- /**
285
- * Even "EPUB 3" publications sometimes still only use the
286
- * EPUB 2 specification for identifying the cover image.
287
- * This is a private method that is used as a fallback if
288
- * we fail to find the cover image according to the EPUB 3
289
- * spec.
290
- */
291
- private getEpub2CoverImage;
292
- /**
293
- * Retrieve the cover image manifest item.
294
- *
295
- * This does not return the actual image data. To
296
- * retrieve the image data, pass this item's id to
297
- * epub.readItemContents, or use epub.getCoverImage()
298
- * instead.
299
- *
300
- * @link https://www.w3.org/TR/epub-33/#sec-cover-image
301
- */
302
- getCoverImageItem(): Promise<ManifestItem | null>;
303
- /**
304
- * Retrieve the cover image data as a byte array.
305
- *
306
- * This does not include, for example, the cover image's
307
- * filename or mime type. To retrieve the image manifest
308
- * item, use epub.getCoverImageItem().
309
- *
310
- * @link https://www.w3.org/TR/epub-33/#sec-cover-image
311
- */
312
- getCoverImage(): Promise<Uint8Array<ArrayBufferLike> | null>;
313
- /**
314
- * Set the cover image for the EPUB.
315
- *
316
- * Adds a manifest item with the `cover-image` property, per
317
- * the EPUB 3 spec, and then writes the provided image data to
318
- * the provided href within the publication.
319
- */
320
- setCoverImage(href: string, data: Uint8Array): Promise<void>;
321
- /**
322
- * Retrieve the publication date from the dc:date element
323
- * in the EPUB metadata as a Date object.
324
- *
325
- * If there is no dc:date element, returns null.
326
- *
327
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcdate
328
- */
329
- getPublicationDate(): Promise<Date | null>;
330
- /**
331
- * Set the dc:date metadata element with the provided date.
332
- *
333
- * Updates the existing dc:date element if one exists.
334
- * Otherwise creates a new element
335
- *
336
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcdate
337
- */
338
- setPublicationDate(date: Date): Promise<void>;
339
- /**
340
- * Set the dc:type metadata element.
341
- *
342
- * Updates the existing dc:type element if one exists.
343
- * Otherwise creates a new element.
344
- *
345
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctype
346
- */
347
- setType(type: string): Promise<void>;
348
- /**
349
- * Retrieve the publication type from the dc:type element
350
- * in the EPUB metadata.
351
- *
352
- * If there is no dc:type element, returns null.
353
- *
354
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctype
355
- */
356
- getType(): Promise<MetadataEntry | null>;
357
- /**
358
- * Add a subject to the EPUB metadata.
359
- *
360
- * @param subject May be a string representing just a schema-less
361
- * subject name, or a DcSubject object
362
- *
363
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
364
- */
365
- addSubject(subject: string | DcSubject): Promise<void>;
366
- /**
367
- * Remove a subject from the EPUB metadata.
368
- *
369
- * Removes the subject at the provided index. This index
370
- * refers to the array returned by `epub.getSubjects()`.
371
- *
372
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
373
- */
374
- removeSubject(index: number): Promise<void>;
375
- /**
376
- * Retrieve the list of subjects for this EPUB.
377
- *
378
- * Subjects without associated authority and term metadata
379
- * will be returned as strings. Otherwise, they will
380
- * be represented as DcSubject objects, with a value,
381
- * authority, and term.
382
- *
383
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
384
- */
385
- getSubjects(): Promise<(string | DcSubject)[]>;
386
- /**
387
- * Retrieve the Epub's language as specified in its
388
- * package document metadata.
389
- *
390
- * If no language metadata is specified, returns null.
391
- * Returns the language as an Intl.Locale instance.
392
- *
393
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
394
- */
395
- getLanguage(): Promise<Intl.Locale | null>;
396
- /**
397
- * Update the Epub's language metadata entry.
398
- *
399
- * Updates the existing dc:language element if one exists.
400
- * Otherwise creates a new element
401
- *
402
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
403
- */
404
- setLanguage(locale: Intl.Locale): Promise<void>;
405
- /**
406
- * Retrieve the title of the Epub.
407
- *
408
- * @param main Optional - whether to return only the first title segment
409
- * if multiple are found. Otherwise, will follow the spec to combine title
410
- * segments
411
- *
412
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
413
- */
414
- getTitle(expanded?: boolean): Promise<string | null>;
415
- /**
416
- * Retrieve the subtitle of the Epub, if it exists.
417
- *
418
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
419
- */
420
- getSubtitle(): Promise<string | null>;
421
- /**
422
- * Retrieve all title entries of the Epub.
423
- *
424
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
425
- */
426
- getTitles(): Promise<{
427
- title: string;
428
- type: string | null;
429
- }[]>;
430
- /**
431
- * Update the Epub's description metadata entry.
432
- *
433
- * Updates the existing dc:description element if one exists.
434
- * Otherwise creates a new element. Any non-ASCII symbols,
435
- * `&`, `<`, `>`, `"`, `'`, and `\``` will be encoded as HTML entities.
436
- */
437
- setDescription(description: string): Promise<void>;
438
- /**
439
- * Retrieve the Epub's description as specified in its
440
- * package document metadata.
441
- *
442
- * If no description metadata is specified, returns null.
443
- * Returns the description as a string. Descriptions may
444
- * include HTML markup.
445
- */
446
- getDescription(): Promise<string | null>;
447
- /**
448
- * Return the set of custom vocabulary prefixes set on this publication's
449
- * root package element.
450
- *
451
- * Returns a map from prefix to URI
452
- *
453
- * @link https://www.w3.org/TR/epub-33/#sec-prefix-attr
454
- */
455
- getPackageVocabularyPrefixes(): Promise<Record<string, string>>;
456
- /**
457
- * Set a custom vocabulary prefix on the root package element.
458
- *
459
- * @link https://www.w3.org/TR/epub-33/#sec-prefix-attr
460
- */
461
- setPackageVocabularyPrefix(prefix: string, uri: string): Promise<void>;
462
- /**
463
- * Set the title of the Epub.
464
- *
465
- * This will replace all existing dc:title elements with
466
- * this title. It will be given title-type "main".
467
- *
468
- * To set specific titles and their types, use epub.setTitles().
469
- *
470
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
471
- */
472
- setTitle(title: string): Promise<void>;
473
- setTitles(entries: {
474
- title: string;
475
- type: string | null;
476
- }[]): Promise<void>;
477
- /**
478
- * Retrieve the list of collections.
479
- */
480
- getCollections(): Promise<Collection[]>;
481
- /**
482
- * Add a collection to the EPUB metadata.
483
- *
484
- * If index is provided, the collection will be placed at
485
- * that index in the list of collections. Otherwise, it
486
- * will be added to the end of the list.
487
- */
488
- addCollection(collection: Collection, index?: number): Promise<void>;
489
- /**
490
- * Remove a collection from the EPUB metadata.
491
- *
492
- * Removes the collection at the provided index. This index
493
- * refers to the array returned by `epub.getCollections()`.
494
- */
495
- removeCollection(index: number): Promise<void>;
496
- /**
497
- * Retrieve the list of creators.
498
- *
499
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
500
- */
501
- getCreators(type?: "creator" | "contributor"): Promise<DcCreator[]>;
502
- /**
503
- * Retrieve the list of contributors.
504
- *
505
- * This is a convenience method for
506
- * `epub.getCreators('contributor')`.
507
- *
508
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccontributor
509
- */
510
- getContributors(): Promise<DcCreator[]>;
511
- /**
512
- * Add a creator to the EPUB metadata.
513
- *
514
- * If index is provided, the creator will be placed at
515
- * that index in the list of creators. Otherwise, it
516
- * will be added to the end of the list.
517
- *
518
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
519
- */
520
- addCreator(creator: DcCreator, index?: number, type?: "creator" | "contributor"): Promise<void>;
521
- /**
522
- * Remove a creator from the EPUB metadata.
523
- *
524
- * Removes the creator at the provided index. This index
525
- * refers to the array returned by `epub.getCreators()`.
526
- *
527
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
528
- */
529
- removeCreator(index: number, type?: "creator" | "contributor"): Promise<void>;
530
- /**
531
- * Remove a contributor from the EPUB metadata.
532
- *
533
- * Removes the contributor at the provided index. This index
534
- * refers to the array returned by `epub.getContributors()`.
535
- *
536
- * This is a convenience method for
537
- * `epub.removeCreator(index, 'contributor')`.
538
- *
539
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
540
- */
541
- removeContributor(index: number): Promise<void>;
542
- /**
543
- * Add a contributor to the EPUB metadata.
544
- *
545
- * If index is provided, the creator will be placed at
546
- * that index in the list of creators. Otherwise, it
547
- * will be added to the end of the list.
548
- *
549
- * This is a convenience method for
550
- * `epub.addCreator(contributor, index, 'contributor')`.
551
- *
552
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
553
- */
554
- addContributor(contributor: DcCreator, index?: number): Promise<void>;
555
- private getSpine;
556
- /**
557
- * Retrieve the manifest items that make up the Epub's spine.
558
- *
559
- * The spine specifies the order that the contents of the Epub
560
- * should be displayed to users by default.
561
- *
562
- * @link https://www.w3.org/TR/epub-33/#sec-spine-elem
563
- */
564
- getSpineItems(): Promise<ManifestItem[]>;
565
- /**
566
- * Add an item to the spine of the EPUB.
567
- *
568
- * If `index` is undefined, the item will be added
569
- * to the end of the spine. Otherwise it will be
570
- * inserted at the specified index.
571
- *
572
- * If the manifestId does not correspond to an item
573
- * in the manifest, this will throw an error.
574
- *
575
- * @link https://www.w3.org/TR/epub-33/#sec-spine-elem
576
- */
577
- addSpineItem(manifestId: string, index?: number): Promise<void>;
578
- /**
579
- * Remove the spine item at the specified index.
580
- *
581
- * @link https://www.w3.org/TR/epub-33/#sec-spine-elem
582
- */
583
- removeSpineItem(index: number): Promise<void>;
584
- /**
585
- * Returns a Zip Entry path for an HREF
586
- */
587
- private resolveHref;
588
- /**
589
- * Retrieve the contents of a file, given its href.
590
- *
591
- * Optionally takes the href that this href should be resolved relative to,
592
- * and an encoding parameter.
593
- *
594
- * @param href The href of the file to retrieve
595
- * @param [relitaveTo] Optional - The href to resolve this href relative to.
596
- * Use if resolving a relative href from a file other than the package document.
597
- * @param [encoding] Optional - Must be the string "utf-8". If provided,
598
- * the function will encode the data into a unicode string.
599
- * Otherwise, the data will be returned as a byte array.
600
- */
601
- readFileContents(href: string, relativeTo?: string): Promise<Uint8Array>;
602
- readFileContents(href: string, relativeTo: string | undefined, encoding: "utf-8"): Promise<string>;
603
- /**
604
- * Retrieve the contents of a manifest item, given its id.
605
- *
606
- * @param id The id of the manifest item to retrieve
607
- * @param [encoding] Optional - must be the string "utf-8". If
608
- * provided, the function will encode the data into a unicode string.
609
- * Otherwise, the data will be returned as a byte array.
610
- *
611
- * @link https://www.w3.org/TR/epub-33/#sec-contentdocs
612
- */
613
- readItemContents(id: string): Promise<Uint8Array>;
614
- readItemContents(id: string, encoding: "utf-8"): Promise<string>;
615
- /**
616
- * Create a new XHTML document with the given body
617
- * and head.
618
- *
619
- * @param body The XML nodes to place in the body of the document
620
- * @param head Optional - the XMl nodes to place in the head
621
- * @param language Optional - defaults to the EPUB's language
622
- */
623
- createXhtmlDocument(body: ParsedXml, head?: ParsedXml, language?: Intl.Locale): Promise<(XmlElement<"html"> | XmlElement<"?xml">)[]>;
624
- /**
625
- * Retrieves the contents of an XHTML item, given its manifest id.
626
- *
627
- * @param id The id of the manifest item to retrieve
628
- * @param [as] Optional - whether to return the parsed XML document tree,
629
- * or the concatenated text of the document. Defaults to the parsed XML tree.
630
- *
631
- * @link https://www.w3.org/TR/epub-33/#sec-xhtml
632
- */
633
- readXhtmlItemContents(id: string, as?: "xhtml"): Promise<ParsedXml>;
634
- readXhtmlItemContents(id: string, as: "text"): Promise<string>;
635
- private writeEntryContents;
636
- /**
637
- * Write new contents for an existing manifest item,
638
- * specified by its id.
639
- *
640
- * The id must reference an existing manifest item. If
641
- * creating a new item, use `epub.addManifestItem()` instead.
642
- *
643
- * @param id The id of the manifest item to write new contents for
644
- * @param contents The new contents. May be either a utf-8 encoded string
645
- * or a byte array, as determined by the encoding
646
- * @param [encoding] Optional - must be the string "utf-8". If provided,
647
- * the contents will be interpreted as a unicode string. Otherwise, the
648
- * contents must be a byte array.
649
- *
650
- * @link https://www.w3.org/TR/epub-33/#sec-contentdocs
651
- */
652
- writeItemContents(id: string, contents: Uint8Array): Promise<void>;
653
- writeItemContents(id: string, contents: string, encoding: "utf-8"): Promise<void>;
654
- /**
655
- * Write new contents for an existing XHTML item,
656
- * specified by its id.
657
- *
658
- * The id must reference an existing manifest item. If
659
- * creating a new item, use `epub.addManifestItem()` instead.
660
- *
661
- * @param id The id of the manifest item to write new contents for
662
- * @param contents The new contents. Must be a parsed XML tree.
663
- *
664
- * @link https://www.w3.org/TR/epub-33/#sec-xhtml
665
- */
666
- writeXhtmlItemContents(id: string, contents: ParsedXml): Promise<void>;
667
- removeManifestItem(id: string): Promise<void>;
668
- /**
669
- * Create a new manifest item and write its contents to a
670
- * new entry.
671
- *
672
- * @param id The id of the manifest item to write new contents for
673
- * @param contents The new contents. May be either a parsed XML tree
674
- * or a unicode string, as determined by the `as` argument.
675
- * @param encoding Optional - whether to interpret contents as a parsed
676
- * XML tree, a unicode string, or a byte array. Defaults to a byte array.
677
- *
678
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
679
- * @link https://www.w3.org/TR/epub-33/#sec-contentdocs
680
- */
681
- addManifestItem(item: ManifestItem, contents: ParsedXml, encoding: "xml"): Promise<void>;
682
- addManifestItem(item: ManifestItem, contents: string, encoding: "utf-8"): Promise<void>;
683
- addManifestItem(item: ManifestItem, contents: Uint8Array): Promise<void>;
684
- /**
685
- * Update the manifest entry for an existing item.
686
- *
687
- * To update the contents of an entry, use `epub.writeItemContents()`
688
- * or `epub.writeXhtmlItemContents()`
689
- *
690
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
691
- */
692
- updateManifestItem(id: string, newItem: Omit<ManifestItem, "id">): Promise<void>;
693
- /**
694
- * Add a new metadata entry to the Epub.
695
- *
696
- * This method, like `epub.getMetadata()`, operates on
697
- * metadata entries. For more useful semantic representations
698
- * of metadata, use specific methods such as `setTitle()` and
699
- * `setLanguage()`.
700
- *
701
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
702
- */
703
- addMetadata(entry: MetadataEntry): Promise<void>;
704
- /**
705
- * Replace a metadata entry with a new one.
706
- *
707
- * The `predicate` argument will be used to determine which entry
708
- * to replace. The first metadata entry that matches the
709
- * predicate will be replaced.
710
- *
711
- * @param predicate Calls predicate once for each metadata entry,
712
- * until it finds one where predicate returns true
713
- * @param entry The new entry to replace the found entry with
714
- *
715
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
716
- */
717
- replaceMetadata(predicate: (entry: MetadataEntry) => boolean, entry: MetadataEntry): Promise<void>;
718
- /**
719
- * Remove one or more metadata entries.
720
- *
721
- * The `predicate` argument will be used to determine which entries
722
- * to remove. The all metadata entries that match the
723
- * predicate will be removed.
724
- *
725
- * @param predicate Calls predicate once for each metadata entry,
726
- * removing any for which it returns true
727
- *
728
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
729
- */
730
- removeMetadata(predicate: (entry: MetadataEntry) => boolean): Promise<void>;
731
- discardAndClose(): void;
732
- /**
733
- * Write the current contents of the Epub to a new
734
- * EPUB archive on disk.
735
- *
736
- * When this method is called, the "dcterms:modified"
737
- * meta tag is automatically updated to the current UTC
738
- * timestamp.
739
- */
740
- saveAndClose(): Promise<void>;
741
- [Symbol.dispose](): void;
742
- }
743
-
744
- export { type AlternateScript, type Collection, type DcCreator, type DcSubject, type DublinCore, type ElementName, Epub, type EpubMetadata, type ManifestItem, type MetadataEntry, type PackageElement, type ParsedXml, type XmlElement, type XmlNode, type XmlTextNode };
1
+ import 'fast-xml-parser';
2
+ export { A as AlternateScript, C as Collection, e as DcCreator, D as DcSubject, f as DublinCore, E as ElementName, k as Epub, Epub2UpgradeOptions, d as EpubMetadata, j as EpubVersionError, Landmark, M as ManifestItem, c as MetadataEntry, h as Navigation, N as NavigationItem, g as NavigationList, i as PackageElement, P as ParsedXml, X as XmlElement, b as XmlNode, a as XmlTextNode } from './upgrade.cjs';