@storyteller-platform/epub 0.8.1 → 1.0.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/README.md +8243 -572
- package/dist/adapters/interface.d.ts +20 -1
- package/dist/adapters/memory.d.ts +2 -2
- package/dist/adapters/memory.js +16 -30
- package/dist/adapters/tmpfs.browser.d.ts +11 -0
- package/dist/adapters/tmpfs.browser.js +9 -0
- package/dist/adapters/tmpfs.d.ts +2 -2
- package/dist/adapters/tmpfs.js +22 -35
- package/dist/files.browser.d.ts +2 -0
- package/dist/files.browser.js +7 -0
- package/dist/files.node.d.ts +2 -0
- package/dist/files.node.js +10 -0
- package/dist/index.d.ts +48 -120
- package/dist/index.js +401 -646
- package/dist/jsx-dev-runtime.d.ts +9 -0
- package/dist/jsx-dev-runtime.js +9 -0
- package/dist/jsx-runtime.d.ts +42 -0
- package/dist/jsx-runtime.js +69 -0
- package/dist/upgrade.d.ts +26 -17
- package/dist/upgrade.js +117 -157
- package/dist/xml.d.ts +103 -0
- package/dist/xml.js +248 -0
- package/dist/zip.browser.d.ts +2 -0
- package/dist/zip.browser.js +33 -0
- package/dist/zip.node.d.ts +9 -0
- package/dist/zip.node.js +246 -0
- package/package.json +92 -10
- package/dist/epubcheck.d.ts +0 -21
- package/dist/epubcheck.js +0 -34
- package/dist/zip.d.ts +0 -2
- package/dist/zip.js +0 -137
|
@@ -8,6 +8,25 @@
|
|
|
8
8
|
* reads only
|
|
9
9
|
*/
|
|
10
10
|
export type EpubStorageKind = "tmp-dir" | "in-memory" | (string & {});
|
|
11
|
+
export type ArchiveSource = string | Uint8Array | Blob;
|
|
12
|
+
/**
|
|
13
|
+
* A file in an opened zip archive. Directory entries are left out.
|
|
14
|
+
*/
|
|
15
|
+
export interface ZipEntry {
|
|
16
|
+
readonly filename: string;
|
|
17
|
+
readonly compressedSize: number;
|
|
18
|
+
readonly uncompressedSize: number;
|
|
19
|
+
/** rejects when the data doesn't match the CRC32 or size in the central directory */
|
|
20
|
+
read(): Promise<Uint8Array>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* An opened zip archive. The `#zip` import picks the reader:
|
|
24
|
+
* yauzl-promise in Node, zip.js everywhere else.
|
|
25
|
+
*/
|
|
26
|
+
export interface ZipArchive {
|
|
27
|
+
readonly entries: readonly ZipEntry[];
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
}
|
|
11
30
|
export interface EpubStorageCapabilities {
|
|
12
31
|
/** when false, the Epub class refuses every mutation method at runtime */
|
|
13
32
|
readonly writable: boolean;
|
|
@@ -63,7 +82,7 @@ export interface EpubStorageAdapterClass<Opts extends object = object> {
|
|
|
63
82
|
* Open an archive from a path or buffer.
|
|
64
83
|
* Will throw if the archive is not a valid EPUB 3
|
|
65
84
|
*/
|
|
66
|
-
init(source:
|
|
85
|
+
init(source: ArchiveSource, opts?: Opts): Promise<EpubStorageAdapter>;
|
|
67
86
|
/**
|
|
68
87
|
* Initialize an empty extract root for {@link Epub.create}.
|
|
69
88
|
* Only necessary for adapters that can write
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EpubStorageAdapter } from "./interface.ts";
|
|
1
|
+
import type { ArchiveSource, EpubStorageAdapter } from "./interface.ts";
|
|
2
2
|
export interface MemoryAdapterOptions {
|
|
3
3
|
/**
|
|
4
4
|
* per-entry decompressed buffer cache
|
|
@@ -23,7 +23,7 @@ export declare class MemoryAdapter implements EpubStorageAdapter {
|
|
|
23
23
|
static readonly capabilities: {
|
|
24
24
|
readonly writable: false;
|
|
25
25
|
};
|
|
26
|
-
static init(source:
|
|
26
|
+
static init(source: ArchiveSource, opts?: MemoryAdapterOptions): Promise<MemoryAdapter>;
|
|
27
27
|
private constructor();
|
|
28
28
|
read(entry: string): Promise<Uint8Array>;
|
|
29
29
|
read(entry: string, encoding: "utf-8"): Promise<string>;
|
package/dist/adapters/memory.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { openZip } from "
|
|
1
|
+
import { openZip } from "#zip";
|
|
2
|
+
const utf8 = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
2
3
|
/**
|
|
3
4
|
* Loads an EPUB archive into memory and serves all I/O off the in-memory zip handle.
|
|
4
5
|
*
|
|
@@ -15,20 +16,11 @@ export class MemoryAdapter {
|
|
|
15
16
|
const { cache = true, signal } = opts;
|
|
16
17
|
signal?.throwIfAborted();
|
|
17
18
|
const zip = await openZip(source);
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
for await (const entry of zip) {
|
|
21
|
-
signal?.throwIfAborted();
|
|
22
|
-
if (entry.filename.endsWith("/"))
|
|
23
|
-
continue;
|
|
24
|
-
entries.set(entry.filename, entry);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
19
|
+
if (signal?.aborted) {
|
|
28
20
|
await zip.close();
|
|
29
|
-
|
|
21
|
+
signal.throwIfAborted();
|
|
30
22
|
}
|
|
31
|
-
return new MemoryAdapter(zip, entries, cache ? new Map() : null);
|
|
23
|
+
return new MemoryAdapter(zip, new Map(zip.entries.map((entry) => [entry.filename, entry])), cache ? new Map() : null);
|
|
32
24
|
}
|
|
33
25
|
constructor(zip, entries, cache) {
|
|
34
26
|
this.zip = zip;
|
|
@@ -36,24 +28,18 @@ export class MemoryAdapter {
|
|
|
36
28
|
this.cache = cache;
|
|
37
29
|
}
|
|
38
30
|
async read(entry, encoding) {
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const stream = await zipEntry.openReadStream();
|
|
50
|
-
const chunks = [];
|
|
51
|
-
for await (const chunk of stream) {
|
|
52
|
-
chunks.push(chunk);
|
|
31
|
+
let data = this.cache?.get(entry);
|
|
32
|
+
if (!data) {
|
|
33
|
+
const zipEntry = this.entries.get(entry);
|
|
34
|
+
if (!zipEntry) {
|
|
35
|
+
const err = new Error(`ENOENT: zip entry not found in EPUB archive: ${entry}`);
|
|
36
|
+
err.code = "ENOENT";
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
data = await zipEntry.read();
|
|
40
|
+
this.cache?.set(entry, data);
|
|
53
41
|
}
|
|
54
|
-
|
|
55
|
-
this.cache?.set(entry, buf);
|
|
56
|
-
return encoding ? buf.toString(encoding) : new Uint8Array(buf);
|
|
42
|
+
return encoding ? utf8.decode(data) : new Uint8Array(data);
|
|
57
43
|
}
|
|
58
44
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
59
45
|
async exists(entry) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EpubStorageAdapter } from "./interface.ts";
|
|
2
|
+
declare function unavailable(): Promise<EpubStorageAdapter>;
|
|
3
|
+
export declare const TmpFsAdapter: {
|
|
4
|
+
readonly kind: "extracted-dir";
|
|
5
|
+
readonly capabilities: {
|
|
6
|
+
readonly writable: true;
|
|
7
|
+
};
|
|
8
|
+
readonly init: typeof unavailable;
|
|
9
|
+
readonly initEmpty: typeof unavailable;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function unavailable() {
|
|
2
|
+
return Promise.reject(new Error("TmpFsAdapter extracts EPUBs to a temp directory and only works in Node.js. Use Epub.using(MemoryAdapter) instead."));
|
|
3
|
+
}
|
|
4
|
+
export const TmpFsAdapter = {
|
|
5
|
+
kind: "extracted-dir",
|
|
6
|
+
capabilities: { writable: true },
|
|
7
|
+
init: unavailable,
|
|
8
|
+
initEmpty: unavailable,
|
|
9
|
+
};
|
package/dist/adapters/tmpfs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EpubListEntry, EpubStorageAdapter } from "./interface.ts";
|
|
1
|
+
import type { ArchiveSource, EpubListEntry, EpubStorageAdapter } from "./interface.ts";
|
|
2
2
|
/**
|
|
3
3
|
* Extracts an EPUB archive to a temp directory and serves all I/O off
|
|
4
4
|
* the real filesystem.
|
|
@@ -10,7 +10,7 @@ export declare class TmpFsAdapter implements EpubStorageAdapter {
|
|
|
10
10
|
static readonly capabilities: {
|
|
11
11
|
readonly writable: true;
|
|
12
12
|
};
|
|
13
|
-
static init(source:
|
|
13
|
+
static init(source: ArchiveSource): Promise<TmpFsAdapter>;
|
|
14
14
|
static initEmpty(): Promise<TmpFsAdapter>;
|
|
15
15
|
private constructor();
|
|
16
16
|
private diskPath;
|
package/dist/adapters/tmpfs.js
CHANGED
|
@@ -58,7 +58,7 @@ import { ZipFile } from "yazl";
|
|
|
58
58
|
import { scratchPath } from "@storyteller-platform/fs";
|
|
59
59
|
import { MediaType } from "@storyteller-platform/media-types";
|
|
60
60
|
import { dirname, join, sep } from "@storyteller-platform/path";
|
|
61
|
-
import { openZip } from "../zip.js";
|
|
61
|
+
import { openZip } from "../zip.node.js";
|
|
62
62
|
const PRECOMPRESSED_KINDS = new Set([
|
|
63
63
|
"audio",
|
|
64
64
|
"image",
|
|
@@ -90,44 +90,31 @@ export class TmpFsAdapter {
|
|
|
90
90
|
static kind = "extracted-dir";
|
|
91
91
|
static capabilities = { writable: true };
|
|
92
92
|
static async init(source) {
|
|
93
|
-
const
|
|
93
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
94
94
|
try {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (!isStorableEntryName(entry.filename))
|
|
108
|
-
continue;
|
|
109
|
-
const writePath = join(rootPath, ...entry.filename.split("/"));
|
|
110
|
-
const readStream = await entry.openReadStream();
|
|
111
|
-
await mkdir(dirname(writePath), { recursive: true });
|
|
112
|
-
const writeStream = createWriteStream(writePath);
|
|
113
|
-
await pipeline(readStream, writeStream);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
catch (e_1) {
|
|
117
|
-
env_1.error = e_1;
|
|
118
|
-
env_1.hasError = true;
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
const result_1 = __disposeResources(env_1);
|
|
122
|
-
if (result_1)
|
|
123
|
-
await result_1;
|
|
95
|
+
const cleanup = __addDisposableResource(env_1, new AsyncDisposableStack(), true);
|
|
96
|
+
const rootPath = mintRootPath();
|
|
97
|
+
cleanup.defer(() => rm(rootPath, { force: true, recursive: true }));
|
|
98
|
+
const zip = __addDisposableResource(env_1, await openZip(source), true);
|
|
99
|
+
for (const entry of zip.entries) {
|
|
100
|
+
if (!isStorableEntryName(entry.filename))
|
|
101
|
+
continue;
|
|
102
|
+
const writePath = join(rootPath, ...entry.filename.split("/"));
|
|
103
|
+
await mkdir(dirname(writePath), { recursive: true });
|
|
104
|
+
await pipeline(await entry.openReadStream(), createWriteStream(writePath));
|
|
124
105
|
}
|
|
106
|
+
cleanup.move();
|
|
107
|
+
return new TmpFsAdapter(rootPath);
|
|
125
108
|
}
|
|
126
|
-
catch (
|
|
127
|
-
|
|
128
|
-
|
|
109
|
+
catch (e_1) {
|
|
110
|
+
env_1.error = e_1;
|
|
111
|
+
env_1.hasError = true;
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
const result_1 = __disposeResources(env_1);
|
|
115
|
+
if (result_1)
|
|
116
|
+
await result_1;
|
|
129
117
|
}
|
|
130
|
-
return new TmpFsAdapter(rootPath);
|
|
131
118
|
}
|
|
132
119
|
static async initEmpty() {
|
|
133
120
|
const rootPath = mintRootPath();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const PATHS_NEED_NODE = "File paths only work in Node.js. Pass the EPUB as a Blob, File or Uint8Array instead.";
|
|
2
|
+
export function openFile(path) {
|
|
3
|
+
return Promise.reject(new Error(`Cannot open "${path}". ${PATHS_NEED_NODE}`));
|
|
4
|
+
}
|
|
5
|
+
export function copyFile(from, to) {
|
|
6
|
+
return Promise.reject(new Error(`Cannot copy "${from}" to "${to}". ${PATHS_NEED_NODE}`));
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { openAsBlob } from "node:fs";
|
|
2
|
+
import { cp, mkdir } from "node:fs/promises";
|
|
3
|
+
import { dirname } from "@storyteller-platform/path";
|
|
4
|
+
export async function openFile(path) {
|
|
5
|
+
return await openAsBlob(path);
|
|
6
|
+
}
|
|
7
|
+
export async function copyFile(from, to) {
|
|
8
|
+
await mkdir(dirname(to), { recursive: true });
|
|
9
|
+
await cp(from, to, { force: true });
|
|
10
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,41 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
export {
|
|
1
|
+
/** @jsxImportSource @storyteller-platform/epub */
|
|
2
|
+
import type { Document, Element, Node } from "@xmldom/xmldom";
|
|
3
|
+
import type { AdapterOptions, ArchiveSource, EpubStorageAdapter, EpubStorageAdapterClass, EpubStorageKind } from "./adapters/interface.ts";
|
|
4
|
+
import * as Upgrade from "./upgrade.tsx";
|
|
5
|
+
export { TmpFsAdapter } from "#tmpfs";
|
|
6
|
+
export type { AdapterOptions, ArchiveSource, EpubListEntry, EpubStorageAdapter, EpubStorageAdapterClass, EpubStorageCapabilities, EpubStorageKind, } from "./adapters/interface.ts";
|
|
6
7
|
export { MemoryAdapter, type MemoryAdapterOptions } from "./adapters/memory.ts";
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The XML surface. Publication-level operations live on {@link Epub}; for
|
|
10
|
+
* building and inspecting XML trees directly, use these.
|
|
11
|
+
*
|
|
12
|
+
* The DOM node types are re-exported so that callers do not need to depend on
|
|
13
|
+
* `@xmldom/xmldom` themselves.
|
|
14
|
+
*/
|
|
15
|
+
export { addLinkToXhtmlHead, adoptNamespaces, createDocument, createDocumentType, declareDefaultNamespace, findXmlChildByName, findXmlChildByNameNS, findXmlDescendantByName, findXmlDescendantByNameNS, getXhtmlBody, insert, isCdata, isComment, isElement, isText, NS, parse, replace, serialize, text, x, XMLSerializer, } from "./xml.ts";
|
|
16
|
+
export type { XmlDiagnostic } from "./xml.ts";
|
|
17
|
+
export type { Attr, Document, DocumentType, Element, Node, Text, } from "@xmldom/xmldom";
|
|
8
18
|
declare global {
|
|
9
19
|
namespace Intl {
|
|
10
20
|
interface Locale {
|
|
11
|
-
textInfo
|
|
21
|
+
textInfo?: {
|
|
12
22
|
direction: "rtl" | "ltr";
|
|
13
23
|
};
|
|
14
24
|
}
|
|
15
25
|
}
|
|
16
26
|
}
|
|
17
|
-
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";
|
|
18
|
-
type QuestionMark = "?";
|
|
19
|
-
/** A valid name for an XML element (must start with a letter) */
|
|
20
|
-
export type ElementName = `${Letter | Uppercase<Letter> | QuestionMark}${string}`;
|
|
21
|
-
type PropertyPrefix = "@_";
|
|
22
|
-
/** An XML element */
|
|
23
|
-
export type XmlElement<Name extends ElementName = ElementName> = {
|
|
24
|
-
":@"?: Record<`${PropertyPrefix}${string}`, string>;
|
|
25
|
-
} & {
|
|
26
|
-
[key in Name]: ParsedXml;
|
|
27
|
-
};
|
|
28
|
-
/** A text node in an XML document */
|
|
29
|
-
export type XmlTextNode = {
|
|
30
|
-
"#text": string;
|
|
31
|
-
};
|
|
32
|
-
/** A valid XML node. May be either an element or a text node. */
|
|
33
|
-
export type XmlNode = XmlElement | XmlTextNode;
|
|
34
|
-
/** An XML structure */
|
|
35
|
-
export type ParsedXml = Array<XmlNode>;
|
|
36
27
|
export type ManifestItem = {
|
|
37
28
|
id: string;
|
|
38
29
|
href: string;
|
|
30
|
+
title?: string | undefined;
|
|
39
31
|
mediaType?: string | undefined;
|
|
40
32
|
fallback?: string | undefined;
|
|
41
33
|
mediaOverlay?: string | undefined;
|
|
@@ -43,7 +35,7 @@ export type ManifestItem = {
|
|
|
43
35
|
};
|
|
44
36
|
export type MetadataEntry = {
|
|
45
37
|
id?: string | undefined;
|
|
46
|
-
type:
|
|
38
|
+
type: string;
|
|
47
39
|
properties: Record<string, string>;
|
|
48
40
|
value: string | undefined;
|
|
49
41
|
};
|
|
@@ -116,12 +108,11 @@ export interface Navigation {
|
|
|
116
108
|
role: string;
|
|
117
109
|
children: NavigationList;
|
|
118
110
|
}
|
|
119
|
-
interface GuideItem {
|
|
111
|
+
export interface GuideItem {
|
|
120
112
|
href: string;
|
|
121
113
|
title: string;
|
|
122
114
|
type: string;
|
|
123
115
|
}
|
|
124
|
-
export type PackageElement = XmlElement<"package">;
|
|
125
116
|
export interface FromOptions {
|
|
126
117
|
/**
|
|
127
118
|
* when true, mutation methods throw {@link EpubReadOnlyError} at runtime
|
|
@@ -162,7 +153,7 @@ export declare class EpubReadOnlyError extends Error {
|
|
|
162
153
|
* const chptOneXml = await epub.readXhtmlItemContents(chptOne.id);
|
|
163
154
|
*
|
|
164
155
|
* const body = getBody(chptOneXml);
|
|
165
|
-
* const h1 =
|
|
156
|
+
* const h1 = findXmlChildByName('h1', body);
|
|
166
157
|
* const headingText = textContent(h1);
|
|
167
158
|
*
|
|
168
159
|
* await epub.setTitle(headingText);
|
|
@@ -177,10 +168,6 @@ export declare class Epub {
|
|
|
177
168
|
protected adapter: EpubStorageAdapter;
|
|
178
169
|
protected inputPath: string | undefined;
|
|
179
170
|
protected readonlyOverride: boolean;
|
|
180
|
-
static xmlParser: XMLParser;
|
|
181
|
-
static xhtmlParser: XMLParser;
|
|
182
|
-
static xmlBuilder: import("fast-xml-builder").XMLBuilder;
|
|
183
|
-
static xhtmlBuilder: import("fast-xml-builder").XMLBuilder;
|
|
184
171
|
/**
|
|
185
172
|
* Format a duration, provided as a number of seconds, as
|
|
186
173
|
* a SMIL clock value, to be used for Media Overlays.
|
|
@@ -188,62 +175,6 @@ export declare class Epub {
|
|
|
188
175
|
* @link https://www.w3.org/TR/epub-33/#sec-duration
|
|
189
176
|
*/
|
|
190
177
|
static formatSmilDuration(duration: number): string;
|
|
191
|
-
/**
|
|
192
|
-
* Given an XML structure representing a complete XHTML document,
|
|
193
|
-
* add a `link` element to the `head` of the document.
|
|
194
|
-
*
|
|
195
|
-
* This method modifies the provided XML structure.
|
|
196
|
-
*/
|
|
197
|
-
static addLinkToXhtmlHead(xml: ParsedXml, link: {
|
|
198
|
-
rel: string;
|
|
199
|
-
href: string;
|
|
200
|
-
type: string;
|
|
201
|
-
}): void;
|
|
202
|
-
/**
|
|
203
|
-
* Given an XML structure representing a complete XHTML document,
|
|
204
|
-
* return the sub-structure representing the children of the
|
|
205
|
-
* document's body element.
|
|
206
|
-
*/
|
|
207
|
-
static getXhtmlBody(xml: ParsedXml): ParsedXml;
|
|
208
|
-
static createXmlElement<Name extends ElementName>(name: Name, properties: Record<string, string>, children?: XmlNode[]): XmlElement<Name>;
|
|
209
|
-
static createXmlTextNode(text: string): XmlTextNode;
|
|
210
|
-
/**
|
|
211
|
-
* Given an XML structure representing a complete XHTML document,
|
|
212
|
-
* return a string representing the concatenation of all text nodes
|
|
213
|
-
* in the document.
|
|
214
|
-
*/
|
|
215
|
-
static getXhtmlTextContent(xml: ParsedXml): string;
|
|
216
|
-
/**
|
|
217
|
-
* Given an XMLElement, return its attributes.
|
|
218
|
-
*/
|
|
219
|
-
static getXmlAttributes(element: XmlElement): Record<string, string>;
|
|
220
|
-
/**
|
|
221
|
-
* Given an XMLElement, return its tag name.
|
|
222
|
-
*/
|
|
223
|
-
static getXmlElementName<Name extends ElementName>(element: XmlElement<Name>): Name;
|
|
224
|
-
/**
|
|
225
|
-
* Given an XMLElement, return a list of its children
|
|
226
|
-
*/
|
|
227
|
-
static getXmlChildren<Name extends ElementName>(element: XmlElement<Name>): ParsedXml;
|
|
228
|
-
static replaceXmlChildren<Name extends ElementName>(element: XmlElement<Name>, children: XmlNode[]): void;
|
|
229
|
-
/**
|
|
230
|
-
* Given an XML structure, find the first child matching
|
|
231
|
-
* the provided name and optional filter.
|
|
232
|
-
*/
|
|
233
|
-
static findXmlChildByName<Name extends ElementName>(name: Name, xml: ParsedXml, filter?: (node: XmlElement<Name>) => boolean): XmlElement<Name> | undefined;
|
|
234
|
-
/**
|
|
235
|
-
* Given an XML structure, find the first descendant matching
|
|
236
|
-
* the provided name and optional filter.
|
|
237
|
-
*
|
|
238
|
-
* Will perform a breadth first search for the element, returning
|
|
239
|
-
* the highest element in the tree matching the name and filter.
|
|
240
|
-
*/
|
|
241
|
-
static findXmlDescendantByName<Name extends ElementName>(name: Name, xml: ParsedXml, filter?: (node: XmlElement<Name>) => boolean): XmlElement<Name> | undefined;
|
|
242
|
-
/**
|
|
243
|
-
* Given an XMLNode, determine whether it represents
|
|
244
|
-
* a text node or an XML element.
|
|
245
|
-
*/
|
|
246
|
-
static isXmlTextNode(node: XmlNode): node is XmlTextNode;
|
|
247
178
|
private rootfile;
|
|
248
179
|
private manifest;
|
|
249
180
|
private spine;
|
|
@@ -299,11 +230,11 @@ export declare class Epub {
|
|
|
299
230
|
* `Epub.using(MemoryAdapter).from(path)` for read-only, in-memory access)
|
|
300
231
|
* @throws {EpubVersionError} when the archive is not a valid EPUB 3
|
|
301
232
|
*/
|
|
302
|
-
static from(pathOrData:
|
|
303
|
-
static from(pathOrData:
|
|
233
|
+
static from(pathOrData: ArchiveSource): Promise<Epub>;
|
|
234
|
+
static from(pathOrData: ArchiveSource, options: FromOptions & {
|
|
304
235
|
readonly: true;
|
|
305
236
|
}): Promise<EpubReader>;
|
|
306
|
-
static from(pathOrData:
|
|
237
|
+
static from(pathOrData: ArchiveSource, options?: FromOptions): Promise<Epub | EpubReader>;
|
|
307
238
|
static assertEpub3(epub: Epub): Promise<void>;
|
|
308
239
|
copy(path?: string): Promise<Epub>;
|
|
309
240
|
private removeEntry;
|
|
@@ -314,8 +245,9 @@ export declare class Epub {
|
|
|
314
245
|
*/
|
|
315
246
|
getItemArchiveLength(id: string): Promise<number>;
|
|
316
247
|
getRootfile(): Promise<string>;
|
|
248
|
+
getPackageDocumentSource(): Promise<string>;
|
|
317
249
|
private getPackageDocument;
|
|
318
|
-
getPackageElement(): Promise<
|
|
250
|
+
getPackageElement(): Promise<Element>;
|
|
319
251
|
/**
|
|
320
252
|
* Safely modify the package document, without race conditions.
|
|
321
253
|
*
|
|
@@ -328,7 +260,7 @@ export declare class Epub {
|
|
|
328
260
|
* it returns a new package document, that will be persisted, otherwise
|
|
329
261
|
* it will be assumed that the package document was modified in place.
|
|
330
262
|
*/
|
|
331
|
-
withPackage(producer: ((packageElement:
|
|
263
|
+
withPackage(producer: ((packageElement: Element) => void) | ((packageElement: Element) => Element) | ((packageElement: Element) => Promise<Element>) | ((packageElement: Element) => Promise<void>)): Promise<void>;
|
|
332
264
|
/**
|
|
333
265
|
* Retrieve the manifest for the Epub.
|
|
334
266
|
*
|
|
@@ -353,26 +285,12 @@ export declare class Epub {
|
|
|
353
285
|
* Returns the item in the metadata element's children array
|
|
354
286
|
* that matches the provided predicate.
|
|
355
287
|
*/
|
|
356
|
-
findMetadataItem(predicate: (entry: MetadataEntry) => boolean): Promise<
|
|
357
|
-
id: string | undefined;
|
|
358
|
-
type: `?${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}`;
|
|
359
|
-
properties: {
|
|
360
|
-
[k: string]: string;
|
|
361
|
-
};
|
|
362
|
-
value: string | undefined;
|
|
363
|
-
} | null>;
|
|
288
|
+
findMetadataItem(predicate: (entry: MetadataEntry) => boolean): Promise<MetadataEntry | null>;
|
|
364
289
|
/**
|
|
365
290
|
* Returns the item in the metadata element's children array
|
|
366
291
|
* that matches the provided predicate.
|
|
367
292
|
*/
|
|
368
|
-
findAllMetadataItems(predicate: (entry: MetadataEntry) => boolean): Promise<
|
|
369
|
-
id: string | undefined;
|
|
370
|
-
type: `?${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}`;
|
|
371
|
-
properties: {
|
|
372
|
-
[k: string]: string;
|
|
373
|
-
};
|
|
374
|
-
value: string | undefined;
|
|
375
|
-
}[]>;
|
|
293
|
+
findAllMetadataItems(predicate: (entry: MetadataEntry) => boolean): Promise<MetadataEntry[]>;
|
|
376
294
|
private static parseMetadataItem;
|
|
377
295
|
/**
|
|
378
296
|
* Retrieve the metadata entries for the Epub.
|
|
@@ -511,7 +429,7 @@ export declare class Epub {
|
|
|
511
429
|
/**
|
|
512
430
|
* Remove `meta` refinements pointing at any of the given ids,
|
|
513
431
|
* restricted to the given `property` values as a cleanup step
|
|
514
|
-
* Mutates `
|
|
432
|
+
* Mutates `metadata` in place.
|
|
515
433
|
*/
|
|
516
434
|
private static removeRefiningMetas;
|
|
517
435
|
/**
|
|
@@ -836,7 +754,9 @@ export declare class Epub {
|
|
|
836
754
|
*
|
|
837
755
|
* @link https://www.w3.org/TR/epub-33/#sec-spine-elem
|
|
838
756
|
*/
|
|
839
|
-
getSpineItems(): Promise<ManifestItem
|
|
757
|
+
getSpineItems(): Promise<(ManifestItem & {
|
|
758
|
+
linear: boolean;
|
|
759
|
+
})[]>;
|
|
840
760
|
/**
|
|
841
761
|
* Add an item to the spine of the EPUB.
|
|
842
762
|
*
|
|
@@ -945,6 +865,13 @@ export declare class Epub {
|
|
|
945
865
|
*/
|
|
946
866
|
readItemContents(id: string): Promise<Uint8Array>;
|
|
947
867
|
readItemContents(id: string, encoding: "utf-8"): Promise<string>;
|
|
868
|
+
/**
|
|
869
|
+
* Create a new XML document with the given root node.
|
|
870
|
+
*
|
|
871
|
+
* @param root The XML node to use as the document element
|
|
872
|
+
* @param language Optional - defaults to the EPUB's language
|
|
873
|
+
*/
|
|
874
|
+
createXmlDocument(root: Element): Document;
|
|
948
875
|
/**
|
|
949
876
|
* Create a new XHTML document with the given body
|
|
950
877
|
* and head.
|
|
@@ -953,7 +880,7 @@ export declare class Epub {
|
|
|
953
880
|
* @param head Optional - the XMl nodes to place in the head
|
|
954
881
|
* @param language Optional - defaults to the EPUB's language
|
|
955
882
|
*/
|
|
956
|
-
createXhtmlDocument(body:
|
|
883
|
+
createXhtmlDocument(body: Node[], head?: Node[], language?: Intl.Locale): Promise<Document>;
|
|
957
884
|
/**
|
|
958
885
|
* Retrieves the contents of an XHTML item, given its manifest id.
|
|
959
886
|
*
|
|
@@ -963,7 +890,7 @@ export declare class Epub {
|
|
|
963
890
|
*
|
|
964
891
|
* @link https://www.w3.org/TR/epub-33/#sec-xhtml
|
|
965
892
|
*/
|
|
966
|
-
readXhtmlItemContents(id: string, as?: "xhtml"): Promise<
|
|
893
|
+
readXhtmlItemContents(id: string, as?: "xhtml"): Promise<Document>;
|
|
967
894
|
readXhtmlItemContents(id: string, as: "text"): Promise<string>;
|
|
968
895
|
private writeEntryContents;
|
|
969
896
|
/**
|
|
@@ -996,7 +923,7 @@ export declare class Epub {
|
|
|
996
923
|
*
|
|
997
924
|
* @link https://www.w3.org/TR/epub-33/#sec-xhtml
|
|
998
925
|
*/
|
|
999
|
-
writeXhtmlItemContents(id: string, contents:
|
|
926
|
+
writeXhtmlItemContents(id: string, contents: Document): Promise<void>;
|
|
1000
927
|
removeManifestItem(id: string): Promise<void>;
|
|
1001
928
|
/**
|
|
1002
929
|
* Create a new manifest item and write its contents to a
|
|
@@ -1011,7 +938,7 @@ export declare class Epub {
|
|
|
1011
938
|
* @link https://www.w3.org/TR/epub-33/#sec-pkg-manifest
|
|
1012
939
|
* @link https://www.w3.org/TR/epub-33/#sec-contentdocs
|
|
1013
940
|
*/
|
|
1014
|
-
addManifestItem(item: ManifestItem, contents:
|
|
941
|
+
addManifestItem(item: ManifestItem, contents: Document, encoding: "xml"): Promise<void>;
|
|
1015
942
|
addManifestItem(item: ManifestItem, contents: string, encoding: "utf-8"): Promise<void>;
|
|
1016
943
|
addManifestItem(item: ManifestItem, contents: Uint8Array): Promise<void>;
|
|
1017
944
|
/**
|
|
@@ -1123,14 +1050,15 @@ export declare class EpubFactory<A extends EpubStorageAdapterClass> {
|
|
|
1123
1050
|
*
|
|
1124
1051
|
* @throws {EpubVersionError} when the archive is not a valid EPUB 3
|
|
1125
1052
|
*/
|
|
1126
|
-
from(source:
|
|
1053
|
+
from(source: ArchiveSource, options: FromOptions & {
|
|
1127
1054
|
readonly: true;
|
|
1128
1055
|
} & AdapterOptions<A>): Promise<EpubReader & {
|
|
1129
1056
|
storage: A["kind"];
|
|
1130
1057
|
}>;
|
|
1131
|
-
from(source:
|
|
1058
|
+
from(source: ArchiveSource, options?: FromOptions & AdapterOptions<A>): Promise<EpubInstanceFor<A> & {
|
|
1132
1059
|
storage: A["kind"];
|
|
1133
1060
|
}>;
|
|
1061
|
+
readPackageDocumentSource(source: ArchiveSource, options?: AdapterOptions<A>): Promise<string>;
|
|
1134
1062
|
/**
|
|
1135
1063
|
* Construct a new EPUB on this factory's adapter, optionally seeded
|
|
1136
1064
|
* with the provided metadata. Requires a writable adapter that
|
|
@@ -1160,4 +1088,4 @@ export declare class EpubFactory<A extends EpubStorageAdapterClass> {
|
|
|
1160
1088
|
*/
|
|
1161
1089
|
upgrade(path: string, options?: Upgrade.Epub2UpgradeOptions): Promise<EpubInstanceFor<A>>;
|
|
1162
1090
|
}
|
|
1163
|
-
export type { Epub2UpgradeOptions, Landmark } from "./upgrade.
|
|
1091
|
+
export type { Epub2UpgradeOptions, Landmark } from "./upgrade.tsx";
|