@storyteller-platform/epub 0.4.6 → 0.4.8

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/README.md CHANGED
@@ -262,7 +262,7 @@ https://www.w3.org/TR/epub-33/
262
262
  > `protected` **new Epub**(`extractPath`, `inputPath`): [`Epub`](#epub)
263
263
 
264
264
  Defined in:
265
- [epub/index.ts:379](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L379)
265
+ [epub/index.ts:391](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L391)
266
266
 
267
267
  ##### Parameters
268
268
 
@@ -282,14 +282,14 @@ Defined in:
282
282
  > `protected` **extractPath**: `string`
283
283
 
284
284
  Defined in:
285
- [epub/index.ts:380](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L380)
285
+ [epub/index.ts:392](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L392)
286
286
 
287
287
  #### inputPath
288
288
 
289
289
  > `protected` **inputPath**: `undefined` \| `string`
290
290
 
291
291
  Defined in:
292
- [epub/index.ts:381](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L381)
292
+ [epub/index.ts:393](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L393)
293
293
 
294
294
  #### xhtmlBuilder
295
295
 
@@ -326,7 +326,7 @@ Defined in:
326
326
  > **\[dispose\]**(): `void`
327
327
 
328
328
  Defined in:
329
- [epub/index.ts:2493](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2493)
329
+ [epub/index.ts:2541](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2541)
330
330
 
331
331
  ##### Returns
332
332
 
@@ -337,7 +337,7 @@ Defined in:
337
337
  > **addCollection**(`collection`, `index?`): `Promise`\<`void`\>
338
338
 
339
339
  Defined in:
340
- [epub/index.ts:1520](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1520)
340
+ [epub/index.ts:1532](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1532)
341
341
 
342
342
  Add a collection to the EPUB metadata.
343
343
 
@@ -360,7 +360,7 @@ collections. Otherwise, it will be added to the end of the list.
360
360
  > **addContributor**(`contributor`, `index?`): `Promise`\<`void`\>
361
361
 
362
362
  Defined in:
363
- [epub/index.ts:1862](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1862)
363
+ [epub/index.ts:1874](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1874)
364
364
 
365
365
  Add a contributor to the EPUB metadata.
366
366
 
@@ -390,7 +390,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dccreator
390
390
  > **addCreator**(`creator`, `index?`, `type?`): `Promise`\<`void`\>
391
391
 
392
392
  Defined in:
393
- [epub/index.ts:1707](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1707)
393
+ [epub/index.ts:1719](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1719)
394
394
 
395
395
  Add a creator to the EPUB metadata.
396
396
 
@@ -420,7 +420,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dccreator
420
420
  > **addManifestItem**(`item`, `contents`, `encoding`): `Promise`\<`void`\>
421
421
 
422
422
  Defined in:
423
- [epub/index.ts:2189](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2189)
423
+ [epub/index.ts:2237](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2237)
424
424
 
425
425
  Create a new manifest item and write its contents to a new entry.
426
426
 
@@ -449,7 +449,7 @@ https://www.w3.org/TR/epub-33/#sec-contentdocs
449
449
  > **addManifestItem**(`item`, `contents`, `encoding`): `Promise`\<`void`\>
450
450
 
451
451
  Defined in:
452
- [epub/index.ts:2194](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2194)
452
+ [epub/index.ts:2242](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2242)
453
453
 
454
454
  Create a new manifest item and write its contents to a new entry.
455
455
 
@@ -478,7 +478,7 @@ https://www.w3.org/TR/epub-33/#sec-contentdocs
478
478
  > **addManifestItem**(`item`, `contents`): `Promise`\<`void`\>
479
479
 
480
480
  Defined in:
481
- [epub/index.ts:2199](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2199)
481
+ [epub/index.ts:2247](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2247)
482
482
 
483
483
  Create a new manifest item and write its contents to a new entry.
484
484
 
@@ -506,7 +506,7 @@ https://www.w3.org/TR/epub-33/#sec-contentdocs
506
506
  > **addMetadata**(`entry`): `Promise`\<`void`\>
507
507
 
508
508
  Defined in:
509
- [epub/index.ts:2311](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2311)
509
+ [epub/index.ts:2359](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2359)
510
510
 
511
511
  Add a new metadata entry to the Epub.
512
512
 
@@ -533,7 +533,7 @@ https://www.w3.org/TR/epub-33/#sec-pkg-metadata
533
533
  > **addSpineItem**(`manifestId`, `index?`): `Promise`\<`void`\>
534
534
 
535
535
  Defined in:
536
- [epub/index.ts:1916](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1916)
536
+ [epub/index.ts:1928](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1928)
537
537
 
538
538
  Add an item to the spine of the EPUB.
539
539
 
@@ -563,7 +563,7 @@ https://www.w3.org/TR/epub-33/#sec-spine-elem
563
563
  > **addSubject**(`subject`): `Promise`\<`void`\>
564
564
 
565
565
  Defined in:
566
- [epub/index.ts:1049](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1049)
566
+ [epub/index.ts:1061](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1061)
567
567
 
568
568
  Add a subject to the EPUB metadata.
569
569
 
@@ -588,7 +588,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
588
588
  > [`XmlElement`](#xmlelement)\<`"?xml"`\>)[]\>
589
589
 
590
590
  Defined in:
591
- [epub/index.ts:2017](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2017)
591
+ [epub/index.ts:2063](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2063)
592
592
 
593
593
  Create a new XHTML document with the given body and head.
594
594
 
@@ -610,7 +610,7 @@ Create a new XHTML document with the given body and head.
610
610
  > **discardAndClose**(): `void`
611
611
 
612
612
  Defined in:
613
- [epub/index.ts:2420](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2420)
613
+ [epub/index.ts:2468](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2468)
614
614
 
615
615
  ##### Returns
616
616
 
@@ -621,7 +621,7 @@ Defined in:
621
621
  > **findAllMetadataItems**(`predicate`): `Promise`\<`object`[]\>
622
622
 
623
623
  Defined in:
624
- [epub/index.ts:772](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L772)
624
+ [epub/index.ts:784](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L784)
625
625
 
626
626
  Returns the item in the metadata element's children array that matches the
627
627
  provided predicate.
@@ -661,7 +661,7 @@ provided predicate.
661
661
  > \}\>
662
662
 
663
663
  Defined in:
664
- [epub/index.ts:763](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L763)
664
+ [epub/index.ts:775](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L775)
665
665
 
666
666
  Returns the item in the metadata element's children array that matches the
667
667
  provided predicate.
@@ -700,7 +700,7 @@ provided predicate.
700
700
  > **getCollections**(): `Promise`\<[`Collection`](#collection)[]\>
701
701
 
702
702
  Defined in:
703
- [epub/index.ts:1480](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1480)
703
+ [epub/index.ts:1492](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1492)
704
704
 
705
705
  Retrieve the list of collections.
706
706
 
@@ -713,7 +713,7 @@ Retrieve the list of collections.
713
713
  > **getContributors**(): `Promise`\<[`DcCreator`](#dccreator)[]\>
714
714
 
715
715
  Defined in:
716
- [epub/index.ts:1694](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1694)
716
+ [epub/index.ts:1706](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1706)
717
717
 
718
718
  Retrieve the list of contributors.
719
719
 
@@ -732,7 +732,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dccontributor
732
732
  > **getCoverImage**(): `Promise`\<`null` \| `Uint8Array`\<`ArrayBufferLike`\>\>
733
733
 
734
734
  Defined in:
735
- [epub/index.ts:952](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L952)
735
+ [epub/index.ts:964](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L964)
736
736
 
737
737
  Retrieve the cover image data as a byte array.
738
738
 
@@ -753,7 +753,7 @@ https://www.w3.org/TR/epub-33/#sec-cover-image
753
753
  > [`ManifestItem`](#manifestitem)\>
754
754
 
755
755
  Defined in:
756
- [epub/index.ts:933](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L933)
756
+ [epub/index.ts:945](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L945)
757
757
 
758
758
  Retrieve the cover image manifest item.
759
759
 
@@ -773,7 +773,7 @@ https://www.w3.org/TR/epub-33/#sec-cover-image
773
773
  > **getCreators**(`type`): `Promise`\<[`DcCreator`](#dccreator)[]\>
774
774
 
775
775
  Defined in:
776
- [epub/index.ts:1633](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1633)
776
+ [epub/index.ts:1645](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1645)
777
777
 
778
778
  Retrieve the list of creators.
779
779
 
@@ -796,7 +796,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dccreator
796
796
  > **getDescription**(): `Promise`\<`null` \| `string`\>
797
797
 
798
798
  Defined in:
799
- [epub/index.ts:1331](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1331)
799
+ [epub/index.ts:1343](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1343)
800
800
 
801
801
  Retrieve the Epub's description as specified in its package document metadata.
802
802
 
@@ -812,7 +812,7 @@ as a string. Descriptions may include HTML markup.
812
812
  > **getIdentifier**(): `Promise`\<`null` \| `string`\>
813
813
 
814
814
  Defined in:
815
- [epub/index.ts:867](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L867)
815
+ [epub/index.ts:879](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L879)
816
816
 
817
817
  Retrieve the identifier from the dc:identifier element in the EPUB metadata.
818
818
 
@@ -831,7 +831,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
831
831
  > **getLanguage**(): `Promise`\<`null` \| `Locale`\>
832
832
 
833
833
  Defined in:
834
- [epub/index.ts:1168](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1168)
834
+ [epub/index.ts:1180](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1180)
835
835
 
836
836
  Retrieve the Epub's language as specified in its package document metadata.
837
837
 
@@ -852,7 +852,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
852
852
  > [`ManifestItem`](#manifestitem)\>\>
853
853
 
854
854
  Defined in:
855
- [epub/index.ts:688](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L688)
855
+ [epub/index.ts:700](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L700)
856
856
 
857
857
  Retrieve the manifest for the Epub.
858
858
 
@@ -872,7 +872,7 @@ https://www.w3.org/TR/epub-33/#sec-pkg-manifest
872
872
  > **getMetadata**(): `Promise`\<[`EpubMetadata`](#epubmetadata)\>
873
873
 
874
874
  Defined in:
875
- [epub/index.ts:839](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L839)
875
+ [epub/index.ts:851](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L851)
876
876
 
877
877
  Retrieve the metadata entries for the Epub.
878
878
 
@@ -896,7 +896,7 @@ https://www.w3.org/TR/epub-33/#sec-pkg-metadata
896
896
  > `string`\>\>
897
897
 
898
898
  Defined in:
899
- [epub/index.ts:1348](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1348)
899
+ [epub/index.ts:1360](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1360)
900
900
 
901
901
  Return the set of custom vocabulary prefixes set on this publication's root
902
902
  package element.
@@ -916,7 +916,7 @@ https://www.w3.org/TR/epub-33/#sec-prefix-attr
916
916
  > **getPublicationDate**(): `Promise`\<`null` \| `Date`\>
917
917
 
918
918
  Defined in:
919
- [epub/index.ts:989](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L989)
919
+ [epub/index.ts:1001](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1001)
920
920
 
921
921
  Retrieve the publication date from the dc:date element in the EPUB metadata as a
922
922
  Date object.
@@ -931,12 +931,23 @@ If there is no dc:date element, returns null.
931
931
 
932
932
  https://www.w3.org/TR/epub-33/#sec-opf-dcdate
933
933
 
934
+ #### getRootfile()
935
+
936
+ > **getRootfile**(): `Promise`\<`string`\>
937
+
938
+ Defined in:
939
+ [epub/index.ts:552](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L552)
940
+
941
+ ##### Returns
942
+
943
+ `Promise`\<`string`\>
944
+
934
945
  #### getSpineItems()
935
946
 
936
947
  > **getSpineItems**(): `Promise`\<[`ManifestItem`](#manifestitem)[]\>
937
948
 
938
949
  Defined in:
939
- [epub/index.ts:1897](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1897)
950
+ [epub/index.ts:1909](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1909)
940
951
 
941
952
  Retrieve the manifest items that make up the Epub's spine.
942
953
 
@@ -956,7 +967,7 @@ https://www.w3.org/TR/epub-33/#sec-spine-elem
956
967
  > **getSubjects**(): `Promise`\<(`string` \| [`DcSubject`](#dcsubject))[]\>
957
968
 
958
969
  Defined in:
959
- [epub/index.ts:1123](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1123)
970
+ [epub/index.ts:1135](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1135)
960
971
 
961
972
  Retrieve the list of subjects for this EPUB.
962
973
 
@@ -977,7 +988,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
977
988
  > **getSubtitle**(): `Promise`\<`null` \| `string`\>
978
989
 
979
990
  Defined in:
980
- [epub/index.ts:1238](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1238)
991
+ [epub/index.ts:1250](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1250)
981
992
 
982
993
  Retrieve the subtitle of the Epub, if it exists.
983
994
 
@@ -994,7 +1005,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dctitle
994
1005
  > **getTitle**(`expanded`): `Promise`\<`null` \| `string`\>
995
1006
 
996
1007
  Defined in:
997
- [epub/index.ts:1214](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1214)
1008
+ [epub/index.ts:1226](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1226)
998
1009
 
999
1010
  Retrieve the title of the Epub.
1000
1011
 
@@ -1017,7 +1028,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dctitle
1017
1028
  > **getTitles**(): `Promise`\<`object`[]\>
1018
1029
 
1019
1030
  Defined in:
1020
- [epub/index.ts:1250](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1250)
1031
+ [epub/index.ts:1262](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1262)
1021
1032
 
1022
1033
  Retrieve all title entries of the Epub.
1023
1034
 
@@ -1034,7 +1045,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dctitle
1034
1045
  > **getType**(): `Promise`\<`null` \| [`MetadataEntry`](#metadataentry)\>
1035
1046
 
1036
1047
  Defined in:
1037
- [epub/index.ts:1036](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1036)
1048
+ [epub/index.ts:1048](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1048)
1038
1049
 
1039
1050
  Retrieve the publication type from the dc:type element in the EPUB metadata.
1040
1051
 
@@ -1048,6 +1059,56 @@ If there is no dc:type element, returns null.
1048
1059
 
1049
1060
  https://www.w3.org/TR/epub-33/#sec-opf-dctype
1050
1061
 
1062
+ #### readFileContents()
1063
+
1064
+ ##### Call Signature
1065
+
1066
+ > **readFileContents**(`href`, `relativeTo?`):
1067
+ > `Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>
1068
+
1069
+ Defined in:
1070
+ [epub/index.ts:2004](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2004)
1071
+
1072
+ Retrieve the contents of a file, given its href.
1073
+
1074
+ Optionally takes the href that this href should be resolved relative to, and an
1075
+ encoding parameter.
1076
+
1077
+ ###### Parameters
1078
+
1079
+ | Parameter | Type | Description |
1080
+ | ------------- | -------- | -------------------------------- |
1081
+ | `href` | `string` | The href of the file to retrieve |
1082
+ | `relativeTo?` | `string` | - |
1083
+
1084
+ ###### Returns
1085
+
1086
+ `Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>
1087
+
1088
+ ##### Call Signature
1089
+
1090
+ > **readFileContents**(`href`, `relativeTo`, `encoding`): `Promise`\<`string`\>
1091
+
1092
+ Defined in:
1093
+ [epub/index.ts:2005](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2005)
1094
+
1095
+ Retrieve the contents of a file, given its href.
1096
+
1097
+ Optionally takes the href that this href should be resolved relative to, and an
1098
+ encoding parameter.
1099
+
1100
+ ###### Parameters
1101
+
1102
+ | Parameter | Type | Description |
1103
+ | ------------ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1104
+ | `href` | `string` | The href of the file to retrieve |
1105
+ | `relativeTo` | `undefined` \| `string` | - |
1106
+ | `encoding` | `"utf-8"` | Optional - Must be the string "utf-8". If provided, the function will encode the data into a unicode string. Otherwise, the data will be returned as a byte array. |
1107
+
1108
+ ###### Returns
1109
+
1110
+ `Promise`\<`string`\>
1111
+
1051
1112
  #### readItemContents()
1052
1113
 
1053
1114
  ##### Call Signature
@@ -1055,7 +1116,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dctype
1055
1116
  > **readItemContents**(`id`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>
1056
1117
 
1057
1118
  Defined in:
1058
- [epub/index.ts:1989](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1989)
1119
+ [epub/index.ts:2035](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2035)
1059
1120
 
1060
1121
  Retrieve the contents of a manifest item, given its id.
1061
1122
 
@@ -1078,7 +1139,7 @@ https://www.w3.org/TR/epub-33/#sec-contentdocs
1078
1139
  > **readItemContents**(`id`, `encoding`): `Promise`\<`string`\>
1079
1140
 
1080
1141
  Defined in:
1081
- [epub/index.ts:1990](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1990)
1142
+ [epub/index.ts:2036](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2036)
1082
1143
 
1083
1144
  Retrieve the contents of a manifest item, given its id.
1084
1145
 
@@ -1104,7 +1165,7 @@ https://www.w3.org/TR/epub-33/#sec-contentdocs
1104
1165
  > **readXhtmlItemContents**(`id`, `as?`): `Promise`\<[`ParsedXml`](#parsedxml)\>
1105
1166
 
1106
1167
  Defined in:
1107
- [epub/index.ts:2050](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2050)
1168
+ [epub/index.ts:2098](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2098)
1108
1169
 
1109
1170
  Retrieves the contents of an XHTML item, given its manifest id.
1110
1171
 
@@ -1128,7 +1189,7 @@ https://www.w3.org/TR/epub-33/#sec-xhtml
1128
1189
  > **readXhtmlItemContents**(`id`, `as`): `Promise`\<`string`\>
1129
1190
 
1130
1191
  Defined in:
1131
- [epub/index.ts:2051](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2051)
1192
+ [epub/index.ts:2099](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2099)
1132
1193
 
1133
1194
  Retrieves the contents of an XHTML item, given its manifest id.
1134
1195
 
@@ -1152,7 +1213,7 @@ https://www.w3.org/TR/epub-33/#sec-xhtml
1152
1213
  > **removeCollection**(`index`): `Promise`\<`void`\>
1153
1214
 
1154
1215
  Defined in:
1155
- [epub/index.ts:1589](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1589)
1216
+ [epub/index.ts:1601](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1601)
1156
1217
 
1157
1218
  Remove a collection from the EPUB metadata.
1158
1219
 
@@ -1174,7 +1235,7 @@ returned by `epub.getCollections()`.
1174
1235
  > **removeContributor**(`index`): `Promise`\<`void`\>
1175
1236
 
1176
1237
  Defined in:
1177
- [epub/index.ts:1846](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1846)
1238
+ [epub/index.ts:1858](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1858)
1178
1239
 
1179
1240
  Remove a contributor from the EPUB metadata.
1180
1241
 
@@ -1202,7 +1263,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dccreator
1202
1263
  > **removeCreator**(`index`, `type`): `Promise`\<`void`\>
1203
1264
 
1204
1265
  Defined in:
1205
- [epub/index.ts:1794](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1794)
1266
+ [epub/index.ts:1806](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1806)
1206
1267
 
1207
1268
  Remove a creator from the EPUB metadata.
1208
1269
 
@@ -1229,7 +1290,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dccreator
1229
1290
  > **removeManifestItem**(`id`): `Promise`\<`void`\>
1230
1291
 
1231
1292
  Defined in:
1232
- [epub/index.ts:2146](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2146)
1293
+ [epub/index.ts:2194](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2194)
1233
1294
 
1234
1295
  ##### Parameters
1235
1296
 
@@ -1246,7 +1307,7 @@ Defined in:
1246
1307
  > **removeMetadata**(`predicate`): `Promise`\<`void`\>
1247
1308
 
1248
1309
  Defined in:
1249
- [epub/index.ts:2395](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2395)
1310
+ [epub/index.ts:2443](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2443)
1250
1311
 
1251
1312
  Remove one or more metadata entries.
1252
1313
 
@@ -1272,7 +1333,7 @@ https://www.w3.org/TR/epub-33/#sec-pkg-metadata
1272
1333
  > **removeSpineItem**(`index`): `Promise`\<`void`\>
1273
1334
 
1274
1335
  Defined in:
1275
- [epub/index.ts:1952](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1952)
1336
+ [epub/index.ts:1964](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1964)
1276
1337
 
1277
1338
  Remove the spine item at the specified index.
1278
1339
 
@@ -1295,7 +1356,7 @@ https://www.w3.org/TR/epub-33/#sec-spine-elem
1295
1356
  > **removeSubject**(`index`): `Promise`\<`void`\>
1296
1357
 
1297
1358
  Defined in:
1298
- [epub/index.ts:1086](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1086)
1359
+ [epub/index.ts:1098](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1098)
1299
1360
 
1300
1361
  Remove a subject from the EPUB metadata.
1301
1362
 
@@ -1321,7 +1382,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dccreator
1321
1382
  > **replaceMetadata**(`predicate`, `entry`): `Promise`\<`void`\>
1322
1383
 
1323
1384
  Defined in:
1324
- [epub/index.ts:2350](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2350)
1385
+ [epub/index.ts:2398](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2398)
1325
1386
 
1326
1387
  Replace a metadata entry with a new one.
1327
1388
 
@@ -1348,7 +1409,7 @@ https://www.w3.org/TR/epub-33/#sec-pkg-metadata
1348
1409
  > **saveAndClose**(): `Promise`\<`void`\>
1349
1410
 
1350
1411
  Defined in:
1351
- [epub/index.ts:2436](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2436)
1412
+ [epub/index.ts:2484](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2484)
1352
1413
 
1353
1414
  Write the current contents of the Epub to a new EPUB archive on disk.
1354
1415
 
@@ -1364,7 +1425,7 @@ updated to the current UTC timestamp.
1364
1425
  > **setCoverImage**(`href`, `data`): `Promise`\<`void`\>
1365
1426
 
1366
1427
  Defined in:
1367
- [epub/index.ts:966](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L966)
1428
+ [epub/index.ts:978](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L978)
1368
1429
 
1369
1430
  Set the cover image for the EPUB.
1370
1431
 
@@ -1387,7 +1448,7 @@ then writes the provided image data to the provided href within the publication.
1387
1448
  > **setDescription**(`description`): `Promise`\<`void`\>
1388
1449
 
1389
1450
  Defined in:
1390
- [epub/index.ts:1315](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1315)
1451
+ [epub/index.ts:1327](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1327)
1391
1452
 
1392
1453
  Update the Epub's description metadata entry.
1393
1454
 
@@ -1410,7 +1471,7 @@ encoded as HTML entities.
1410
1471
  > **setIdentifier**(`identifier`): `Promise`\<`void`\>
1411
1472
 
1412
1473
  Defined in:
1413
- [epub/index.ts:881](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L881)
1474
+ [epub/index.ts:893](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L893)
1414
1475
 
1415
1476
  Set the dc:identifier metadata element with the provided string.
1416
1477
 
@@ -1436,7 +1497,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
1436
1497
  > **setLanguage**(`locale`): `Promise`\<`void`\>
1437
1498
 
1438
1499
  Defined in:
1439
- [epub/index.ts:1197](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1197)
1500
+ [epub/index.ts:1209](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1209)
1440
1501
 
1441
1502
  Update the Epub's language metadata entry.
1442
1503
 
@@ -1462,7 +1523,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
1462
1523
  > **setPackageVocabularyPrefix**(`prefix`, `uri`): `Promise`\<`void`\>
1463
1524
 
1464
1525
  Defined in:
1465
- [epub/index.ts:1366](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1366)
1526
+ [epub/index.ts:1378](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1378)
1466
1527
 
1467
1528
  Set a custom vocabulary prefix on the root package element.
1468
1529
 
@@ -1486,7 +1547,7 @@ https://www.w3.org/TR/epub-33/#sec-prefix-attr
1486
1547
  > **setPublicationDate**(`date`): `Promise`\<`void`\>
1487
1548
 
1488
1549
  Defined in:
1489
- [epub/index.ts:1004](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1004)
1550
+ [epub/index.ts:1016](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1016)
1490
1551
 
1491
1552
  Set the dc:date metadata element with the provided date.
1492
1553
 
@@ -1512,7 +1573,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dcdate
1512
1573
  > **setTitle**(`title`): `Promise`\<`void`\>
1513
1574
 
1514
1575
  Defined in:
1515
- [epub/index.ts:1390](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1390)
1576
+ [epub/index.ts:1402](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1402)
1516
1577
 
1517
1578
  Set the title of the Epub.
1518
1579
 
@@ -1540,7 +1601,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dctitle
1540
1601
  > **setTitles**(`entries`): `Promise`\<`void`\>
1541
1602
 
1542
1603
  Defined in:
1543
- [epub/index.ts:1418](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1418)
1604
+ [epub/index.ts:1430](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1430)
1544
1605
 
1545
1606
  ##### Parameters
1546
1607
 
@@ -1557,7 +1618,7 @@ Defined in:
1557
1618
  > **setType**(`type`): `Promise`\<`void`\>
1558
1619
 
1559
1620
  Defined in:
1560
- [epub/index.ts:1020](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1020)
1621
+ [epub/index.ts:1032](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L1032)
1561
1622
 
1562
1623
  Set the dc:type metadata element.
1563
1624
 
@@ -1583,7 +1644,7 @@ https://www.w3.org/TR/epub-33/#sec-opf-dctype
1583
1644
  > **updateManifestItem**(`id`, `newItem`): `Promise`\<`void`\>
1584
1645
 
1585
1646
  Defined in:
1586
- [epub/index.ts:2262](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2262)
1647
+ [epub/index.ts:2310](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2310)
1587
1648
 
1588
1649
  Update the manifest entry for an existing item.
1589
1650
 
@@ -1612,7 +1673,7 @@ https://www.w3.org/TR/epub-33/#sec-pkg-manifest
1612
1673
  > **writeItemContents**(`id`, `contents`): `Promise`\<`void`\>
1613
1674
 
1614
1675
  Defined in:
1615
- [epub/index.ts:2098](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2098)
1676
+ [epub/index.ts:2146](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2146)
1616
1677
 
1617
1678
  Write new contents for an existing manifest item, specified by its id.
1618
1679
 
@@ -1639,7 +1700,7 @@ https://www.w3.org/TR/epub-33/#sec-contentdocs
1639
1700
  > **writeItemContents**(`id`, `contents`, `encoding`): `Promise`\<`void`\>
1640
1701
 
1641
1702
  Defined in:
1642
- [epub/index.ts:2099](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2099)
1703
+ [epub/index.ts:2147](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2147)
1643
1704
 
1644
1705
  Write new contents for an existing manifest item, specified by its id.
1645
1706
 
@@ -1667,7 +1728,7 @@ https://www.w3.org/TR/epub-33/#sec-contentdocs
1667
1728
  > **writeXhtmlItemContents**(`id`, `contents`): `Promise`\<`void`\>
1668
1729
 
1669
1730
  Defined in:
1670
- [epub/index.ts:2138](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2138)
1731
+ [epub/index.ts:2186](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L2186)
1671
1732
 
1672
1733
  Write new contents for an existing XHTML item, specified by its id.
1673
1734
 
@@ -1721,7 +1782,7 @@ This method modifies the provided XML structure.
1721
1782
  > `Promise`\<[`Epub`](#epub)\>
1722
1783
 
1723
1784
  Defined in:
1724
- [epub/index.ts:399](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L399)
1785
+ [epub/index.ts:411](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L411)
1725
1786
 
1726
1787
  Construct an Epub instance, optionally beginning with the provided metadata.
1727
1788
 
@@ -1786,7 +1847,7 @@ Defined in:
1786
1847
  > `undefined` \| [`XmlElement`](#xmlelement)\<`Name`\>
1787
1848
 
1788
1849
  Defined in:
1789
- [epub/index.ts:354](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L354)
1850
+ [epub/index.ts:366](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L366)
1790
1851
 
1791
1852
  Given an XML structure, find the first child matching the provided name and
1792
1853
  optional filter.
@@ -1838,7 +1899,7 @@ https://www.w3.org/TR/epub-33/#sec-duration
1838
1899
  > `static` **from**(`pathOrData`): `Promise`\<[`Epub`](#epub)\>
1839
1900
 
1840
1901
  Defined in:
1841
- [epub/index.ts:483](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L483)
1902
+ [epub/index.ts:495](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L495)
1842
1903
 
1843
1904
  Construct an Epub instance by reading an existing EPUB publication.
1844
1905
 
@@ -1892,12 +1953,31 @@ representing the concatenation of all text nodes in the document.
1892
1953
 
1893
1954
  `string`
1894
1955
 
1956
+ #### getXmlAttributes()
1957
+
1958
+ > `static` **getXmlAttributes**(`element`): `Record`\<`string`, `string`\>
1959
+
1960
+ Defined in:
1961
+ [epub/index.ts:319](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L319)
1962
+
1963
+ Given an XMLElement, return its attributes.
1964
+
1965
+ ##### Parameters
1966
+
1967
+ | Parameter | Type |
1968
+ | --------- | --------------------------- |
1969
+ | `element` | [`XmlElement`](#xmlelement) |
1970
+
1971
+ ##### Returns
1972
+
1973
+ `Record`\<`string`, `string`\>
1974
+
1895
1975
  #### getXmlChildren()
1896
1976
 
1897
1977
  > `static` **getXmlChildren**\<`Name`\>(`element`): [`ParsedXml`](#parsedxml)
1898
1978
 
1899
1979
  Defined in:
1900
- [epub/index.ts:334](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L334)
1980
+ [epub/index.ts:346](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L346)
1901
1981
 
1902
1982
  Given an XMLElement, return a list of its children
1903
1983
 
@@ -1922,7 +2002,7 @@ Given an XMLElement, return a list of its children
1922
2002
  > `static` **getXmlElementName**\<`Name`\>(`element`): `Name`
1923
2003
 
1924
2004
  Defined in:
1925
- [epub/index.ts:319](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L319)
2005
+ [epub/index.ts:331](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L331)
1926
2006
 
1927
2007
  Given an XMLElement, return its tag name.
1928
2008
 
@@ -1947,7 +2027,7 @@ Given an XMLElement, return its tag name.
1947
2027
  > `static` **isXmlTextNode**(`node`): `node is XmlTextNode`
1948
2028
 
1949
2029
  Defined in:
1950
- [epub/index.ts:367](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L367)
2030
+ [epub/index.ts:379](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L379)
1951
2031
 
1952
2032
  Given an XMLNode, determine whether it represents a text node or an XML element.
1953
2033
 
@@ -1966,7 +2046,7 @@ Given an XMLNode, determine whether it represents a text node or an XML element.
1966
2046
  > `static` **replaceXmlChildren**\<`Name`\>(`element`, `children`): `void`
1967
2047
 
1968
2048
  Defined in:
1969
- [epub/index.ts:342](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L342)
2049
+ [epub/index.ts:354](https://gitlab.com/storyteller-platform/storyteller/-/blob/main/epub/index.ts#L354)
1970
2050
 
1971
2051
  ##### Type Parameters
1972
2052
 
package/dist/index.cjs CHANGED
@@ -213,6 +213,17 @@ class Epub {
213
213
  }
214
214
  return text;
215
215
  }
216
+ /**
217
+ * Given an XMLElement, return its attributes.
218
+ */
219
+ static getXmlAttributes(element) {
220
+ return Object.fromEntries(
221
+ Object.entries(element[":@"] ?? {}).map(([key, value]) => [
222
+ key.slice(2),
223
+ value
224
+ ])
225
+ );
226
+ }
216
227
  /**
217
228
  * Given an XMLElement, return its tag name.
218
229
  */
@@ -1548,6 +1559,13 @@ ${JSON.stringify(element, null, 2)}`
1548
1559
  const startPath = (0, import_path.dirname)(from);
1549
1560
  return (0, import_path.resolve)(this.extractPath, startPath, href);
1550
1561
  }
1562
+ async readFileContents(href, relativeTo, encoding) {
1563
+ const rootfile = await this.getRootfile();
1564
+ const from = relativeTo ? this.resolveHref(rootfile, relativeTo) : rootfile;
1565
+ const path = this.resolveHref(from, href);
1566
+ const itemEntry = encoding ? await this.getFileData(path, encoding) : await this.getFileData(path);
1567
+ return itemEntry;
1568
+ }
1551
1569
  async readItemContents(id, encoding) {
1552
1570
  const rootfile = await this.getRootfile();
1553
1571
  const manifest = await this.getManifest();
package/dist/index.d.cts CHANGED
@@ -141,6 +141,10 @@ declare class Epub {
141
141
  * in the document.
142
142
  */
143
143
  static getXhtmlTextContent(xml: ParsedXml): string;
144
+ /**
145
+ * Given an XMLElement, return its attributes.
146
+ */
147
+ static getXmlAttributes(element: XmlElement): Record<string, string>;
144
148
  /**
145
149
  * Given an XMLElement, return its tag name.
146
150
  */
@@ -184,7 +188,7 @@ declare class Epub {
184
188
  static from(pathOrData: string | Uint8Array): Promise<Epub>;
185
189
  private removeEntry;
186
190
  private getFileData;
187
- private getRootfile;
191
+ getRootfile(): Promise<string>;
188
192
  private migratePackageDocument;
189
193
  private getPackageDocument;
190
194
  private getPackageElement;
@@ -580,6 +584,21 @@ declare class Epub {
580
584
  * Returns a Zip Entry path for an HREF
581
585
  */
582
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>;
583
602
  /**
584
603
  * Retrieve the contents of a manifest item, given its id.
585
604
  *
package/dist/index.d.ts CHANGED
@@ -141,6 +141,10 @@ declare class Epub {
141
141
  * in the document.
142
142
  */
143
143
  static getXhtmlTextContent(xml: ParsedXml): string;
144
+ /**
145
+ * Given an XMLElement, return its attributes.
146
+ */
147
+ static getXmlAttributes(element: XmlElement): Record<string, string>;
144
148
  /**
145
149
  * Given an XMLElement, return its tag name.
146
150
  */
@@ -184,7 +188,7 @@ declare class Epub {
184
188
  static from(pathOrData: string | Uint8Array): Promise<Epub>;
185
189
  private removeEntry;
186
190
  private getFileData;
187
- private getRootfile;
191
+ getRootfile(): Promise<string>;
188
192
  private migratePackageDocument;
189
193
  private getPackageDocument;
190
194
  private getPackageElement;
@@ -580,6 +584,21 @@ declare class Epub {
580
584
  * Returns a Zip Entry path for an HREF
581
585
  */
582
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>;
583
602
  /**
584
603
  * Retrieve the contents of a manifest item, given its id.
585
604
  *
package/dist/index.js CHANGED
@@ -180,6 +180,17 @@ class Epub {
180
180
  }
181
181
  return text;
182
182
  }
183
+ /**
184
+ * Given an XMLElement, return its attributes.
185
+ */
186
+ static getXmlAttributes(element) {
187
+ return Object.fromEntries(
188
+ Object.entries(element[":@"] ?? {}).map(([key, value]) => [
189
+ key.slice(2),
190
+ value
191
+ ])
192
+ );
193
+ }
183
194
  /**
184
195
  * Given an XMLElement, return its tag name.
185
196
  */
@@ -1515,6 +1526,13 @@ ${JSON.stringify(element, null, 2)}`
1515
1526
  const startPath = dirname(from);
1516
1527
  return resolve(this.extractPath, startPath, href);
1517
1528
  }
1529
+ async readFileContents(href, relativeTo, encoding) {
1530
+ const rootfile = await this.getRootfile();
1531
+ const from = relativeTo ? this.resolveHref(rootfile, relativeTo) : rootfile;
1532
+ const path = this.resolveHref(from, href);
1533
+ const itemEntry = encoding ? await this.getFileData(path, encoding) : await this.getFileData(path);
1534
+ return itemEntry;
1535
+ }
1518
1536
  async readItemContents(id, encoding) {
1519
1537
  const rootfile = await this.getRootfile();
1520
1538
  const manifest = await this.getManifest();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyteller-platform/epub",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",