@storyteller-platform/epub 0.8.1 → 0.8.2
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 +1044 -154
- package/dist/index.d.ts +7 -2
- package/dist/index.js +37 -10
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export type ParsedXml = Array<XmlNode>;
|
|
|
36
36
|
export type ManifestItem = {
|
|
37
37
|
id: string;
|
|
38
38
|
href: string;
|
|
39
|
+
title?: string | undefined;
|
|
39
40
|
mediaType?: string | undefined;
|
|
40
41
|
fallback?: string | undefined;
|
|
41
42
|
mediaOverlay?: string | undefined;
|
|
@@ -116,7 +117,7 @@ export interface Navigation {
|
|
|
116
117
|
role: string;
|
|
117
118
|
children: NavigationList;
|
|
118
119
|
}
|
|
119
|
-
interface GuideItem {
|
|
120
|
+
export interface GuideItem {
|
|
120
121
|
href: string;
|
|
121
122
|
title: string;
|
|
122
123
|
type: string;
|
|
@@ -314,6 +315,7 @@ export declare class Epub {
|
|
|
314
315
|
*/
|
|
315
316
|
getItemArchiveLength(id: string): Promise<number>;
|
|
316
317
|
getRootfile(): Promise<string>;
|
|
318
|
+
getPackageDocumentSource(): Promise<string>;
|
|
317
319
|
private getPackageDocument;
|
|
318
320
|
getPackageElement(): Promise<XmlElement<"package">>;
|
|
319
321
|
/**
|
|
@@ -836,7 +838,9 @@ export declare class Epub {
|
|
|
836
838
|
*
|
|
837
839
|
* @link https://www.w3.org/TR/epub-33/#sec-spine-elem
|
|
838
840
|
*/
|
|
839
|
-
getSpineItems(): Promise<ManifestItem
|
|
841
|
+
getSpineItems(): Promise<(ManifestItem & {
|
|
842
|
+
linear: boolean;
|
|
843
|
+
})[]>;
|
|
840
844
|
/**
|
|
841
845
|
* Add an item to the spine of the EPUB.
|
|
842
846
|
*
|
|
@@ -1131,6 +1135,7 @@ export declare class EpubFactory<A extends EpubStorageAdapterClass> {
|
|
|
1131
1135
|
from(source: string | Uint8Array, options?: FromOptions & AdapterOptions<A>): Promise<EpubInstanceFor<A> & {
|
|
1132
1136
|
storage: A["kind"];
|
|
1133
1137
|
}>;
|
|
1138
|
+
readPackageDocumentSource(source: string | Uint8Array, options?: AdapterOptions<A>): Promise<string>;
|
|
1134
1139
|
/**
|
|
1135
1140
|
* Construct a new EPUB on this factory's adapter, optionally seeded
|
|
1136
1141
|
* with the provided metadata. Requires a writable adapter that
|
package/dist/index.js
CHANGED
|
@@ -440,12 +440,15 @@ export class Epub {
|
|
|
440
440
|
this.rootfile = await this.resolveEntry("", fullPath);
|
|
441
441
|
return this.rootfile;
|
|
442
442
|
}
|
|
443
|
-
async
|
|
443
|
+
async getPackageDocumentSource() {
|
|
444
444
|
const rootfile = await this.getRootfile();
|
|
445
445
|
const packageDocumentString = await this.adapter.read(rootfile, "utf-8");
|
|
446
446
|
if (!packageDocumentString)
|
|
447
447
|
throw new Error(`Failed to parse EPUB: could not find package document at ${rootfile}`);
|
|
448
|
-
|
|
448
|
+
return packageDocumentString;
|
|
449
|
+
}
|
|
450
|
+
async getPackageDocument() {
|
|
451
|
+
const packageDocument = Epub.xmlParser.parse(await this.getPackageDocumentSource());
|
|
449
452
|
return normalizeOpfNamespacePrefixes(packageDocument);
|
|
450
453
|
}
|
|
451
454
|
async getPackageElement() {
|
|
@@ -1824,8 +1827,15 @@ export class Epub {
|
|
|
1824
1827
|
throw new Error("Failed to parse EPUB: Found no spine element in package document");
|
|
1825
1828
|
this.spine = spine["spine"]
|
|
1826
1829
|
.filter((node) => !Epub.isXmlTextNode(node))
|
|
1827
|
-
.map((itemref) =>
|
|
1828
|
-
|
|
1830
|
+
.map((itemref) => {
|
|
1831
|
+
const idRef = itemref[":@"]?.["@_idref"];
|
|
1832
|
+
const linear = itemref[":@"]?.["@_linear"];
|
|
1833
|
+
return {
|
|
1834
|
+
itemRef: idRef,
|
|
1835
|
+
linear: linear === "no" ? false : true,
|
|
1836
|
+
};
|
|
1837
|
+
})
|
|
1838
|
+
.filter((itemref) => !!itemref.itemRef);
|
|
1829
1839
|
return this.spine;
|
|
1830
1840
|
}
|
|
1831
1841
|
/**
|
|
@@ -1839,7 +1849,14 @@ export class Epub {
|
|
|
1839
1849
|
async getSpineItems() {
|
|
1840
1850
|
const spine = await this.getSpine();
|
|
1841
1851
|
const manifest = await this.getManifest();
|
|
1842
|
-
|
|
1852
|
+
const spineItems = [];
|
|
1853
|
+
for (const itemref of spine) {
|
|
1854
|
+
const item = manifest[itemref.itemRef];
|
|
1855
|
+
if (!item)
|
|
1856
|
+
continue;
|
|
1857
|
+
spineItems.push({ ...item, linear: itemref.linear });
|
|
1858
|
+
}
|
|
1859
|
+
return spineItems;
|
|
1843
1860
|
}
|
|
1844
1861
|
/**
|
|
1845
1862
|
* Add an item to the spine of the EPUB.
|
|
@@ -1903,16 +1920,16 @@ export class Epub {
|
|
|
1903
1920
|
(!secondChild || Epub.getXmlElementName(secondChild) !== "ol")) {
|
|
1904
1921
|
continue;
|
|
1905
1922
|
}
|
|
1923
|
+
const role = firstChild[":@"]?.["@_epub:type"]?.trim();
|
|
1906
1924
|
children.push({
|
|
1907
1925
|
title: Epub.getXhtmlTextContent(Epub.getXmlChildren(firstChild)),
|
|
1908
1926
|
...(Epub.getXmlElementName(firstChild) === "a" &&
|
|
1909
1927
|
firstChild[":@"]?.["@_href"] && {
|
|
1910
|
-
href: await this.resolveHref(firstChild[":@"]["@_href"],
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
firstChild[":@"]?.["@_epub:type"] && {
|
|
1914
|
-
role: await this.resolveHref(firstChild[":@"]["@_epub:type"], undefined, { toRoot: resolveToRoot }),
|
|
1928
|
+
href: await this.resolveHref(firstChild[":@"]["@_href"], navHref, {
|
|
1929
|
+
toRoot: resolveToRoot,
|
|
1930
|
+
}),
|
|
1915
1931
|
}),
|
|
1932
|
+
...(role && { role }),
|
|
1916
1933
|
...(secondChild &&
|
|
1917
1934
|
Epub.getXmlElementName(secondChild) === "ol" && {
|
|
1918
1935
|
children: await this.getNavigationChildren(secondChild, navHref, {
|
|
@@ -2496,6 +2513,16 @@ export class EpubFactory {
|
|
|
2496
2513
|
}
|
|
2497
2514
|
return epub;
|
|
2498
2515
|
}
|
|
2516
|
+
async readPackageDocumentSource(source, options = {}) {
|
|
2517
|
+
const adapter = await this.adapterClass.init(source, options);
|
|
2518
|
+
const epub = new Epub(this.adapterClass, adapter, typeof source === "string" ? source : undefined, true);
|
|
2519
|
+
try {
|
|
2520
|
+
return await epub.getPackageDocumentSource();
|
|
2521
|
+
}
|
|
2522
|
+
finally {
|
|
2523
|
+
epub.discardAndClose();
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2499
2526
|
/**
|
|
2500
2527
|
* Construct a new EPUB on this factory's adapter, optionally seeded
|
|
2501
2528
|
* with the provided metadata. Requires a writable adapter that
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyteller-platform/epub",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"vitest": "^5.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@readium/shared": "^2.
|
|
41
|
+
"@readium/shared": "^2.5.0",
|
|
42
42
|
"@storyteller-platform/fs": "^0.3.0",
|
|
43
43
|
"@storyteller-platform/media-types": "^0.2.1",
|
|
44
44
|
"@storyteller-platform/path": "^0.3.1",
|