@storyteller-platform/epub 0.4.10 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,743 +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">;
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 getPackageDocument;
194
- private getPackageElement;
195
- /**
196
- * Safely modify the package document, without race conditions.
197
- *
198
- * Since the reading the package document is an async process,
199
- * multiple simultaneously dispatched function calls that all
200
- * attempt to modify it can clobber each other's changes. This
201
- * method uses a mutex to ensure that each update runs exclusively.
202
- *
203
- * @param producer The function to update the package document. If
204
- * it returns a new package document, that will be persisted, otherwise
205
- * it will be assumed that the package document was modified in place.
206
- */
207
- private withPackage;
208
- /**
209
- * Retrieve the manifest for the Epub.
210
- *
211
- * This is represented as a map from each manifest items'
212
- * id to the rest of its properties.
213
- *
214
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
215
- */
216
- getManifest(): Promise<Record<string, ManifestItem>>;
217
- /**
218
- * Returns the first index in the metadata element's children array
219
- * that matches the provided predicate.
220
- *
221
- * Note: This may technically be different than the index in the
222
- * getMetadata() array, as it includes non-metadata nodes, like
223
- * text nodes. These are technically not allowed, but may exist,
224
- * nonetheless. As consumers only ever see the getMetadata()
225
- * array, this method is only meant to be used internally.
226
- */
227
- private findMetadataIndex;
228
- /**
229
- * Returns the item in the metadata element's children array
230
- * that matches the provided predicate.
231
- */
232
- findMetadataItem(predicate: (entry: MetadataEntry) => boolean): Promise<{
233
- id: string | undefined;
234
- 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}`;
235
- properties: {
236
- [k: string]: string;
237
- };
238
- value: string | undefined;
239
- } | null>;
240
- /**
241
- * Returns the item in the metadata element's children array
242
- * that matches the provided predicate.
243
- */
244
- findAllMetadataItems(predicate: (entry: MetadataEntry) => boolean): Promise<{
245
- id: string | undefined;
246
- 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}`;
247
- properties: {
248
- [k: string]: string;
249
- };
250
- value: string | undefined;
251
- }[]>;
252
- private static parseMetadataItem;
253
- /**
254
- * Retrieve the metadata entries for the Epub.
255
- *
256
- * This is represented as an array of metadata entries,
257
- * in the order that they're presented in the Epub package document.
258
- *
259
- * For more useful semantic representations of metadata, use
260
- * specific methods such as `getTitle()` and `getAuthors()`.
261
- *
262
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
263
- */
264
- getMetadata(): Promise<EpubMetadata>;
265
- /**
266
- * Retrieve the identifier from the dc:identifier element
267
- * in the EPUB metadata.
268
- *
269
- * If there is no dc:identifier element, returns null.
270
- *
271
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
272
- */
273
- getIdentifier(): Promise<string | null>;
274
- /**
275
- * Set the dc:identifier metadata element with the provided string.
276
- *
277
- * Updates the existing dc:identifier element if one exists.
278
- * Otherwise creates a new element
279
- *
280
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
281
- */
282
- setIdentifier(identifier: string): Promise<void>;
283
- /**
284
- * Even "EPUB 3" publications sometimes still only use the
285
- * EPUB 2 specification for identifying the cover image.
286
- * This is a private method that is used as a fallback if
287
- * we fail to find the cover image according to the EPUB 3
288
- * spec.
289
- */
290
- private getEpub2CoverImage;
291
- /**
292
- * Retrieve the cover image manifest item.
293
- *
294
- * This does not return the actual image data. To
295
- * retrieve the image data, pass this item's id to
296
- * epub.readItemContents, or use epub.getCoverImage()
297
- * instead.
298
- *
299
- * @link https://www.w3.org/TR/epub-33/#sec-cover-image
300
- */
301
- getCoverImageItem(): Promise<ManifestItem | null>;
302
- /**
303
- * Retrieve the cover image data as a byte array.
304
- *
305
- * This does not include, for example, the cover image's
306
- * filename or mime type. To retrieve the image manifest
307
- * item, use epub.getCoverImageItem().
308
- *
309
- * @link https://www.w3.org/TR/epub-33/#sec-cover-image
310
- */
311
- getCoverImage(): Promise<Uint8Array<ArrayBufferLike> | null>;
312
- /**
313
- * Set the cover image for the EPUB.
314
- *
315
- * Adds a manifest item with the `cover-image` property, per
316
- * the EPUB 3 spec, and then writes the provided image data to
317
- * the provided href within the publication.
318
- */
319
- setCoverImage(href: string, data: Uint8Array): Promise<void>;
320
- /**
321
- * Retrieve the publication date from the dc:date element
322
- * in the EPUB metadata as a Date object.
323
- *
324
- * If there is no dc:date element, returns null.
325
- *
326
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcdate
327
- */
328
- getPublicationDate(): Promise<Date | null>;
329
- /**
330
- * Set the dc:date metadata element with the provided date.
331
- *
332
- * Updates the existing dc:date element if one exists.
333
- * Otherwise creates a new element
334
- *
335
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcdate
336
- */
337
- setPublicationDate(date: Date): Promise<void>;
338
- /**
339
- * Set the dc:type metadata element.
340
- *
341
- * Updates the existing dc:type element if one exists.
342
- * Otherwise creates a new element.
343
- *
344
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctype
345
- */
346
- setType(type: string): Promise<void>;
347
- /**
348
- * Retrieve the publication type from the dc:type element
349
- * in the EPUB metadata.
350
- *
351
- * If there is no dc:type element, returns null.
352
- *
353
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctype
354
- */
355
- getType(): Promise<MetadataEntry | null>;
356
- /**
357
- * Add a subject to the EPUB metadata.
358
- *
359
- * @param subject May be a string representing just a schema-less
360
- * subject name, or a DcSubject object
361
- *
362
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
363
- */
364
- addSubject(subject: string | DcSubject): Promise<void>;
365
- /**
366
- * Remove a subject from the EPUB metadata.
367
- *
368
- * Removes the subject at the provided index. This index
369
- * refers to the array returned by `epub.getSubjects()`.
370
- *
371
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
372
- */
373
- removeSubject(index: number): Promise<void>;
374
- /**
375
- * Retrieve the list of subjects for this EPUB.
376
- *
377
- * Subjects without associated authority and term metadata
378
- * will be returned as strings. Otherwise, they will
379
- * be represented as DcSubject objects, with a value,
380
- * authority, and term.
381
- *
382
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
383
- */
384
- getSubjects(): Promise<(string | DcSubject)[]>;
385
- /**
386
- * Retrieve the Epub's language as specified in its
387
- * package document metadata.
388
- *
389
- * If no language metadata is specified, returns null.
390
- * Returns the language as an Intl.Locale instance.
391
- *
392
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
393
- */
394
- getLanguage(): Promise<Intl.Locale | null>;
395
- /**
396
- * Update the Epub's language metadata entry.
397
- *
398
- * Updates the existing dc:language element if one exists.
399
- * Otherwise creates a new element
400
- *
401
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
402
- */
403
- setLanguage(locale: Intl.Locale): Promise<void>;
404
- /**
405
- * Retrieve the title of the Epub.
406
- *
407
- * @param main Optional - whether to return only the first title segment
408
- * if multiple are found. Otherwise, will follow the spec to combine title
409
- * segments
410
- *
411
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
412
- */
413
- getTitle(expanded?: boolean): Promise<string | null>;
414
- /**
415
- * Retrieve the subtitle of the Epub, if it exists.
416
- *
417
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
418
- */
419
- getSubtitle(): Promise<string | null>;
420
- /**
421
- * Retrieve all title entries of the Epub.
422
- *
423
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
424
- */
425
- getTitles(): Promise<{
426
- title: string;
427
- type: string | null;
428
- }[]>;
429
- /**
430
- * Update the Epub's description metadata entry.
431
- *
432
- * Updates the existing dc:description element if one exists.
433
- * Otherwise creates a new element. Any non-ASCII symbols,
434
- * `&`, `<`, `>`, `"`, `'`, and `\``` will be encoded as HTML entities.
435
- */
436
- setDescription(description: string): Promise<void>;
437
- /**
438
- * Retrieve the Epub's description as specified in its
439
- * package document metadata.
440
- *
441
- * If no description metadata is specified, returns null.
442
- * Returns the description as a string. Descriptions may
443
- * include HTML markup.
444
- */
445
- getDescription(): Promise<string | null>;
446
- /**
447
- * Return the set of custom vocabulary prefixes set on this publication's
448
- * root package element.
449
- *
450
- * Returns a map from prefix to URI
451
- *
452
- * @link https://www.w3.org/TR/epub-33/#sec-prefix-attr
453
- */
454
- getPackageVocabularyPrefixes(): Promise<Record<string, string>>;
455
- /**
456
- * Set a custom vocabulary prefix on the root package element.
457
- *
458
- * @link https://www.w3.org/TR/epub-33/#sec-prefix-attr
459
- */
460
- setPackageVocabularyPrefix(prefix: string, uri: string): Promise<void>;
461
- /**
462
- * Set the title of the Epub.
463
- *
464
- * This will replace all existing dc:title elements with
465
- * this title. It will be given title-type "main".
466
- *
467
- * To set specific titles and their types, use epub.setTitles().
468
- *
469
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dctitle
470
- */
471
- setTitle(title: string): Promise<void>;
472
- setTitles(entries: {
473
- title: string;
474
- type: string | null;
475
- }[]): Promise<void>;
476
- /**
477
- * Retrieve the list of collections.
478
- */
479
- getCollections(): Promise<Collection[]>;
480
- /**
481
- * Add a collection to the EPUB metadata.
482
- *
483
- * If index is provided, the collection will be placed at
484
- * that index in the list of collections. Otherwise, it
485
- * will be added to the end of the list.
486
- */
487
- addCollection(collection: Collection, index?: number): Promise<void>;
488
- /**
489
- * Remove a collection from the EPUB metadata.
490
- *
491
- * Removes the collection at the provided index. This index
492
- * refers to the array returned by `epub.getCollections()`.
493
- */
494
- removeCollection(index: number): Promise<void>;
495
- /**
496
- * Retrieve the list of creators.
497
- *
498
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
499
- */
500
- getCreators(type?: "creator" | "contributor"): Promise<DcCreator[]>;
501
- /**
502
- * Retrieve the list of contributors.
503
- *
504
- * This is a convenience method for
505
- * `epub.getCreators('contributor')`.
506
- *
507
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccontributor
508
- */
509
- getContributors(): Promise<DcCreator[]>;
510
- /**
511
- * Add a creator to the EPUB metadata.
512
- *
513
- * If index is provided, the creator will be placed at
514
- * that index in the list of creators. Otherwise, it
515
- * will be added to the end of the list.
516
- *
517
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
518
- */
519
- addCreator(creator: DcCreator, index?: number, type?: "creator" | "contributor"): Promise<void>;
520
- /**
521
- * Remove a creator from the EPUB metadata.
522
- *
523
- * Removes the creator at the provided index. This index
524
- * refers to the array returned by `epub.getCreators()`.
525
- *
526
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
527
- */
528
- removeCreator(index: number, type?: "creator" | "contributor"): Promise<void>;
529
- /**
530
- * Remove a contributor from the EPUB metadata.
531
- *
532
- * Removes the contributor at the provided index. This index
533
- * refers to the array returned by `epub.getContributors()`.
534
- *
535
- * This is a convenience method for
536
- * `epub.removeCreator(index, 'contributor')`.
537
- *
538
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
539
- */
540
- removeContributor(index: number): Promise<void>;
541
- /**
542
- * Add a contributor to the EPUB metadata.
543
- *
544
- * If index is provided, the creator will be placed at
545
- * that index in the list of creators. Otherwise, it
546
- * will be added to the end of the list.
547
- *
548
- * This is a convenience method for
549
- * `epub.addCreator(contributor, index, 'contributor')`.
550
- *
551
- * @link https://www.w3.org/TR/epub-33/#sec-opf-dccreator
552
- */
553
- addContributor(contributor: DcCreator, index?: number): Promise<void>;
554
- private getSpine;
555
- /**
556
- * Retrieve the manifest items that make up the Epub's spine.
557
- *
558
- * The spine specifies the order that the contents of the Epub
559
- * should be displayed to users by default.
560
- *
561
- * @link https://www.w3.org/TR/epub-33/#sec-spine-elem
562
- */
563
- getSpineItems(): Promise<ManifestItem[]>;
564
- /**
565
- * Add an item to the spine of the EPUB.
566
- *
567
- * If `index` is undefined, the item will be added
568
- * to the end of the spine. Otherwise it will be
569
- * inserted at the specified index.
570
- *
571
- * If the manifestId does not correspond to an item
572
- * in the manifest, this will throw an error.
573
- *
574
- * @link https://www.w3.org/TR/epub-33/#sec-spine-elem
575
- */
576
- addSpineItem(manifestId: string, index?: number): Promise<void>;
577
- /**
578
- * Remove the spine item at the specified index.
579
- *
580
- * @link https://www.w3.org/TR/epub-33/#sec-spine-elem
581
- */
582
- removeSpineItem(index: number): Promise<void>;
583
- /**
584
- * Returns a Zip Entry path for an HREF
585
- */
586
- private resolveHref;
587
- /**
588
- * Retrieve the contents of a file, given its href.
589
- *
590
- * Optionally takes the href that this href should be resolved relative to,
591
- * and an encoding parameter.
592
- *
593
- * @param href The href of the file to retrieve
594
- * @param [relitaveTo] Optional - The href to resolve this href relative to.
595
- * Use if resolving a relative href from a file other than the package document.
596
- * @param [encoding] Optional - Must be the string "utf-8". If provided,
597
- * the function will encode the data into a unicode string.
598
- * Otherwise, the data will be returned as a byte array.
599
- */
600
- readFileContents(href: string, relativeTo?: string): Promise<Uint8Array>;
601
- readFileContents(href: string, relativeTo: string | undefined, encoding: "utf-8"): Promise<string>;
602
- /**
603
- * Retrieve the contents of a manifest item, given its id.
604
- *
605
- * @param id The id of the manifest item to retrieve
606
- * @param [encoding] Optional - must be the string "utf-8". If
607
- * provided, the function will encode the data into a unicode string.
608
- * Otherwise, the data will be returned as a byte array.
609
- *
610
- * @link https://www.w3.org/TR/epub-33/#sec-contentdocs
611
- */
612
- readItemContents(id: string): Promise<Uint8Array>;
613
- readItemContents(id: string, encoding: "utf-8"): Promise<string>;
614
- /**
615
- * Create a new XHTML document with the given body
616
- * and head.
617
- *
618
- * @param body The XML nodes to place in the body of the document
619
- * @param head Optional - the XMl nodes to place in the head
620
- * @param language Optional - defaults to the EPUB's language
621
- */
622
- createXhtmlDocument(body: ParsedXml, head?: ParsedXml, language?: Intl.Locale): Promise<(XmlElement<"html"> | XmlElement<"?xml">)[]>;
623
- /**
624
- * Retrieves the contents of an XHTML item, given its manifest id.
625
- *
626
- * @param id The id of the manifest item to retrieve
627
- * @param [as] Optional - whether to return the parsed XML document tree,
628
- * or the concatenated text of the document. Defaults to the parsed XML tree.
629
- *
630
- * @link https://www.w3.org/TR/epub-33/#sec-xhtml
631
- */
632
- readXhtmlItemContents(id: string, as?: "xhtml"): Promise<ParsedXml>;
633
- readXhtmlItemContents(id: string, as: "text"): Promise<string>;
634
- private writeEntryContents;
635
- /**
636
- * Write new contents for an existing manifest item,
637
- * specified by its id.
638
- *
639
- * The id must reference an existing manifest item. If
640
- * creating a new item, use `epub.addManifestItem()` instead.
641
- *
642
- * @param id The id of the manifest item to write new contents for
643
- * @param contents The new contents. May be either a utf-8 encoded string
644
- * or a byte array, as determined by the encoding
645
- * @param [encoding] Optional - must be the string "utf-8". If provided,
646
- * the contents will be interpreted as a unicode string. Otherwise, the
647
- * contents must be a byte array.
648
- *
649
- * @link https://www.w3.org/TR/epub-33/#sec-contentdocs
650
- */
651
- writeItemContents(id: string, contents: Uint8Array): Promise<void>;
652
- writeItemContents(id: string, contents: string, encoding: "utf-8"): Promise<void>;
653
- /**
654
- * Write new contents for an existing XHTML item,
655
- * specified by its id.
656
- *
657
- * The id must reference an existing manifest item. If
658
- * creating a new item, use `epub.addManifestItem()` instead.
659
- *
660
- * @param id The id of the manifest item to write new contents for
661
- * @param contents The new contents. Must be a parsed XML tree.
662
- *
663
- * @link https://www.w3.org/TR/epub-33/#sec-xhtml
664
- */
665
- writeXhtmlItemContents(id: string, contents: ParsedXml): Promise<void>;
666
- removeManifestItem(id: string): Promise<void>;
667
- /**
668
- * Create a new manifest item and write its contents to a
669
- * new entry.
670
- *
671
- * @param id The id of the manifest item to write new contents for
672
- * @param contents The new contents. May be either a parsed XML tree
673
- * or a unicode string, as determined by the `as` argument.
674
- * @param encoding Optional - whether to interpret contents as a parsed
675
- * XML tree, a unicode string, or a byte array. Defaults to a byte array.
676
- *
677
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
678
- * @link https://www.w3.org/TR/epub-33/#sec-contentdocs
679
- */
680
- addManifestItem(item: ManifestItem, contents: ParsedXml, encoding: "xml"): Promise<void>;
681
- addManifestItem(item: ManifestItem, contents: string, encoding: "utf-8"): Promise<void>;
682
- addManifestItem(item: ManifestItem, contents: Uint8Array): Promise<void>;
683
- /**
684
- * Update the manifest entry for an existing item.
685
- *
686
- * To update the contents of an entry, use `epub.writeItemContents()`
687
- * or `epub.writeXhtmlItemContents()`
688
- *
689
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
690
- */
691
- updateManifestItem(id: string, newItem: Omit<ManifestItem, "id">): Promise<void>;
692
- /**
693
- * Add a new metadata entry to the Epub.
694
- *
695
- * This method, like `epub.getMetadata()`, operates on
696
- * metadata entries. For more useful semantic representations
697
- * of metadata, use specific methods such as `setTitle()` and
698
- * `setLanguage()`.
699
- *
700
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
701
- */
702
- addMetadata(entry: MetadataEntry): Promise<void>;
703
- /**
704
- * Replace a metadata entry with a new one.
705
- *
706
- * The `predicate` argument will be used to determine which entry
707
- * to replace. The first metadata entry that matches the
708
- * predicate will be replaced.
709
- *
710
- * @param predicate Calls predicate once for each metadata entry,
711
- * until it finds one where predicate returns true
712
- * @param entry The new entry to replace the found entry with
713
- *
714
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
715
- */
716
- replaceMetadata(predicate: (entry: MetadataEntry) => boolean, entry: MetadataEntry): Promise<void>;
717
- /**
718
- * Remove one or more metadata entries.
719
- *
720
- * The `predicate` argument will be used to determine which entries
721
- * to remove. The all metadata entries that match the
722
- * predicate will be removed.
723
- *
724
- * @param predicate Calls predicate once for each metadata entry,
725
- * removing any for which it returns true
726
- *
727
- * @link https://www.w3.org/TR/epub-33/#sec-pkg-metadata
728
- */
729
- removeMetadata(predicate: (entry: MetadataEntry) => boolean): Promise<void>;
730
- discardAndClose(): void;
731
- /**
732
- * Write the current contents of the Epub to a new
733
- * EPUB archive on disk.
734
- *
735
- * When this method is called, the "dcterms:modified"
736
- * meta tag is automatically updated to the current UTC
737
- * timestamp.
738
- */
739
- saveAndClose(): Promise<void>;
740
- [Symbol.dispose](): void;
741
- }
742
-
743
- 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';