@storyteller-platform/epub 0.7.0 → 0.8.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.
@@ -1,236 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
7
- var __typeError = (msg) => {
8
- throw TypeError(msg);
9
- };
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") {
16
- for (let key of __getOwnPropNames(from))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
- var __using = (stack, value, async) => {
24
- if (value != null) {
25
- if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
26
- var dispose, inner;
27
- if (async) dispose = value[__knownSymbol("asyncDispose")];
28
- if (dispose === void 0) {
29
- dispose = value[__knownSymbol("dispose")];
30
- if (async) inner = dispose;
31
- }
32
- if (typeof dispose !== "function") __typeError("Object not disposable");
33
- if (inner) dispose = function() {
34
- try {
35
- inner.call(this);
36
- } catch (e) {
37
- return Promise.reject(e);
38
- }
39
- };
40
- stack.push([async, dispose, value]);
41
- } else if (async) {
42
- stack.push([async]);
43
- }
44
- return value;
45
- };
46
- var __callDispose = (stack, error, hasError) => {
47
- var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
48
- return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
49
- };
50
- var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
51
- var next = (it) => {
52
- while (it = stack.pop()) {
53
- try {
54
- var result = it[1] && it[1].call(it[2]);
55
- if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
56
- } catch (e) {
57
- fail(e);
58
- }
59
- }
60
- if (hasError) throw error;
61
- };
62
- return next();
63
- };
64
- var tmpfs_exports = {};
65
- __export(tmpfs_exports, {
66
- TmpFsAdapter: () => TmpFsAdapter
67
- });
68
- module.exports = __toCommonJS(tmpfs_exports);
69
- var import_node_crypto = require("node:crypto");
70
- var import_node_fs = require("node:fs");
71
- var import_promises = require("node:fs/promises");
72
- var import_node_os = require("node:os");
73
- var import_promises2 = require("node:stream/promises");
74
- var import_yauzl_promise = require("yauzl-promise");
75
- var import_yazl = require("yazl");
76
- var import_path = require("@storyteller-platform/path");
77
- const MP3_FILE_EXTENSIONS = [".mp3"];
78
- const MPEG4_FILE_EXTENSIONS = [".mp4", ".m4a", ".m4b"];
79
- const AAC_FILE_EXTENSIONS = [".aac"];
80
- const OGG_FILE_EXTENSIONS = [".ogg", ".oga", ".mogg"];
81
- const OPUS_FILE_EXTENSIONS = [".opus"];
82
- const WAVE_FILE_EXTENSIONS = [".wav"];
83
- const AIFF_FILE_EXTENSIONS = [".aiff"];
84
- const FLAC_FILE_EXTENSIONS = [".flac"];
85
- const ALAC_FILE_EXTENSIONS = [".alac"];
86
- const WEBM_FILE_EXTENSIONS = [".weba"];
87
- const AUDIO_FILE_EXTENSIONS = [
88
- ...MP3_FILE_EXTENSIONS,
89
- ...AAC_FILE_EXTENSIONS,
90
- ...MPEG4_FILE_EXTENSIONS,
91
- ...OPUS_FILE_EXTENSIONS,
92
- ...OGG_FILE_EXTENSIONS,
93
- ...WAVE_FILE_EXTENSIONS,
94
- ...AIFF_FILE_EXTENSIONS,
95
- ...FLAC_FILE_EXTENSIONS,
96
- ...ALAC_FILE_EXTENSIONS,
97
- ...WEBM_FILE_EXTENSIONS
98
- ];
99
- function isAudioFile(filenameOrExt) {
100
- const lowered = filenameOrExt.toLowerCase();
101
- return AUDIO_FILE_EXTENSIONS.some((ext) => lowered.endsWith(ext));
102
- }
103
- function mintRootPath() {
104
- return (0, import_path.join)((0, import_node_os.tmpdir)(), `storyteller-platform-epub-${(0, import_node_crypto.randomUUID)()}`);
105
- }
106
- class TmpFsAdapter {
107
- constructor(rootPath) {
108
- this.rootPath = rootPath;
109
- }
110
- static kind = "extracted-dir";
111
- static capabilities = { writable: true };
112
- static async init(source) {
113
- const rootPath = mintRootPath();
114
- try {
115
- var _stack = [];
116
- try {
117
- const zipfile = typeof source === "string" ? await (0, import_yauzl_promise.open)(source) : await (0, import_yauzl_promise.fromBuffer)(Buffer.from(source));
118
- const stack = __using(_stack, new AsyncDisposableStack(), true);
119
- stack.defer(async () => {
120
- await zipfile.close();
121
- });
122
- for await (const entry of zipfile) {
123
- if (entry.filename.endsWith("/")) {
124
- continue;
125
- }
126
- const writePath = (0, import_path.join)(rootPath, entry.filename);
127
- const readStream = await entry.openReadStream();
128
- await (0, import_promises.mkdir)((0, import_path.dirname)(writePath), { recursive: true });
129
- const writeStream = (0, import_node_fs.createWriteStream)(writePath);
130
- await (0, import_promises2.pipeline)(readStream, writeStream);
131
- }
132
- } catch (_) {
133
- var _error = _, _hasError = true;
134
- } finally {
135
- var _promise = __callDispose(_stack, _error, _hasError);
136
- _promise && await _promise;
137
- }
138
- } catch (error) {
139
- (0, import_node_fs.rmSync)(rootPath, { force: true, recursive: true });
140
- throw error;
141
- }
142
- return new TmpFsAdapter(rootPath);
143
- }
144
- static async initEmpty() {
145
- const rootPath = mintRootPath();
146
- await (0, import_promises.mkdir)(rootPath, { recursive: true });
147
- return new TmpFsAdapter(rootPath);
148
- }
149
- async read(path, encoding) {
150
- return await (0, import_promises.readFile)(path, encoding);
151
- }
152
- async write(path, data, encoding) {
153
- await (0, import_promises.mkdir)((0, import_path.dirname)(path), { recursive: true });
154
- await (0, import_promises.writeFile)(path, data, encoding);
155
- }
156
- async remove(path) {
157
- await (0, import_promises.rm)(path);
158
- }
159
- async archiveLength(path) {
160
- try {
161
- const st = await (0, import_promises.stat)(path);
162
- return st.size;
163
- } catch {
164
- return 0;
165
- }
166
- }
167
- async *list() {
168
- const entries = await (0, import_promises.readdir)(this.rootPath, {
169
- recursive: true,
170
- withFileTypes: true
171
- });
172
- for (const entry of entries) {
173
- if (entry.isDirectory()) continue;
174
- const absolutePath = (0, import_path.join)(entry.parentPath, entry.name);
175
- yield {
176
- absolutePath,
177
- relativePath: absolutePath.replace(`${this.rootPath}${import_path.sep}`, "")
178
- };
179
- }
180
- }
181
- async duplicate() {
182
- const newRoot = mintRootPath();
183
- try {
184
- await (0, import_promises.cp)(this.rootPath, newRoot, { recursive: true });
185
- } catch (error) {
186
- (0, import_node_fs.rmSync)(newRoot, { force: true, recursive: true });
187
- throw error;
188
- }
189
- return new TmpFsAdapter(newRoot);
190
- }
191
- async serialize(targetPath) {
192
- var _stack = [];
193
- try {
194
- const tmpArchivePath = (0, import_path.join)(
195
- (0, import_node_os.tmpdir)(),
196
- `storyteller-platform-epub-${(0, import_node_crypto.randomUUID)()}`
197
- );
198
- const { promise, resolve } = Promise.withResolvers();
199
- const zipfile = new import_yazl.ZipFile();
200
- const writeStream = (0, import_node_fs.createWriteStream)(tmpArchivePath);
201
- writeStream.on("close", () => {
202
- resolve();
203
- });
204
- const stack = __using(_stack, new AsyncDisposableStack(), true);
205
- stack.defer(async () => {
206
- writeStream.close();
207
- await (0, import_promises.rm)(tmpArchivePath, { force: true });
208
- });
209
- zipfile.outputStream.pipe(writeStream);
210
- zipfile.addBuffer(Buffer.from("application/epub+zip"), "mimetype", {
211
- compress: false
212
- });
213
- for await (const entry of this.list()) {
214
- if (entry.relativePath === "mimetype") continue;
215
- zipfile.addFile(entry.absolutePath, entry.relativePath, {
216
- compress: !isAudioFile(entry.absolutePath)
217
- });
218
- }
219
- zipfile.end();
220
- await promise;
221
- await (0, import_promises.cp)(tmpArchivePath, targetPath);
222
- } catch (_) {
223
- var _error = _, _hasError = true;
224
- } finally {
225
- var _promise = __callDispose(_stack, _error, _hasError);
226
- _promise && await _promise;
227
- }
228
- }
229
- dispose() {
230
- (0, import_node_fs.rmSync)(this.rootPath, { recursive: true, force: true });
231
- }
232
- }
233
- // Annotate the CommonJS export names for ESM import in node:
234
- 0 && (module.exports = {
235
- TmpFsAdapter
236
- });
@@ -1,29 +0,0 @@
1
- import { EpubStorageAdapter, EpubListEntry } from './interface.cjs';
2
-
3
- /**
4
- * Extracts an EPUB archive to a temp directory and serves all I/O off
5
- * the real filesystem.
6
- * `Epub.using(TmpFsAdapter).from(...)` returns a writable {@link Epub}.
7
- */
8
- declare class TmpFsAdapter implements EpubStorageAdapter {
9
- readonly rootPath: string;
10
- static readonly kind: "extracted-dir";
11
- static readonly capabilities: {
12
- readonly writable: true;
13
- };
14
- static init(source: string | Uint8Array): Promise<TmpFsAdapter>;
15
- static initEmpty(): Promise<TmpFsAdapter>;
16
- private constructor();
17
- read(path: string): Promise<Uint8Array>;
18
- read(path: string, encoding: "utf-8"): Promise<string>;
19
- write(path: string, data: Uint8Array): Promise<void>;
20
- write(path: string, data: string, encoding: "utf-8"): Promise<void>;
21
- remove(path: string): Promise<void>;
22
- archiveLength(path: string): Promise<number>;
23
- list(): AsyncIterable<EpubListEntry>;
24
- duplicate(): Promise<TmpFsAdapter>;
25
- serialize(targetPath: string): Promise<void>;
26
- dispose(): void;
27
- }
28
-
29
- export { TmpFsAdapter };
@@ -1,50 +0,0 @@
1
- var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
2
- var __typeError = (msg) => {
3
- throw TypeError(msg);
4
- };
5
- var __using = (stack, value, async) => {
6
- if (value != null) {
7
- if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
8
- var dispose, inner;
9
- if (async) dispose = value[__knownSymbol("asyncDispose")];
10
- if (dispose === void 0) {
11
- dispose = value[__knownSymbol("dispose")];
12
- if (async) inner = dispose;
13
- }
14
- if (typeof dispose !== "function") __typeError("Object not disposable");
15
- if (inner) dispose = function() {
16
- try {
17
- inner.call(this);
18
- } catch (e) {
19
- return Promise.reject(e);
20
- }
21
- };
22
- stack.push([async, dispose, value]);
23
- } else if (async) {
24
- stack.push([async]);
25
- }
26
- return value;
27
- };
28
- var __callDispose = (stack, error, hasError) => {
29
- var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
30
- return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
31
- };
32
- var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
33
- var next = (it) => {
34
- while (it = stack.pop()) {
35
- try {
36
- var result = it[1] && it[1].call(it[2]);
37
- if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
38
- } catch (e) {
39
- fail(e);
40
- }
41
- }
42
- if (hasError) throw error;
43
- };
44
- return next();
45
- };
46
-
47
- export {
48
- __using,
49
- __callDispose
50
- };
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var epubcheck_exports = {};
20
- __export(epubcheck_exports, {
21
- epubcheck: () => epubcheck
22
- });
23
- module.exports = __toCommonJS(epubcheck_exports);
24
- var import_node_child_process = require("node:child_process");
25
- var import_node_crypto = require("node:crypto");
26
- var import_promises = require("node:fs/promises");
27
- var import_node_os = require("node:os");
28
- var import_node_path = require("node:path");
29
- var import_node_url = require("node:url");
30
- var import_node_util = require("node:util");
31
- const import_meta = {};
32
- const here = (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
33
- const JAR = (0, import_node_path.join)(here, "vendors", "epubcheck-5.3.0", "epubcheck.jar");
34
- async function epubcheck(epubFile) {
35
- const output = (0, import_node_path.join)((0, import_node_os.tmpdir)(), `epubcheck-${(0, import_node_crypto.randomUUID)()}.json`);
36
- const execFilePromise = (0, import_node_util.promisify)(import_node_child_process.execFile);
37
- try {
38
- await execFilePromise("java", [
39
- "-jar",
40
- JAR,
41
- "--json",
42
- output,
43
- epubFile
44
- ]).catch((error) => {
45
- if (error instanceof Error && error.message.includes("Check finished with errors")) {
46
- return;
47
- }
48
- throw error;
49
- });
50
- const json = await (0, import_promises.readFile)(output, "utf8");
51
- return JSON.parse(json);
52
- } finally {
53
- await (0, import_promises.unlink)(output).catch(() => {
54
- });
55
- }
56
- }
57
- // Annotate the CommonJS export names for ESM import in node:
58
- 0 && (module.exports = {
59
- epubcheck
60
- });
@@ -1,23 +0,0 @@
1
- interface Location {
2
- url: {
3
- hierachical: boolean;
4
- opaque: boolean;
5
- };
6
- path: string;
7
- line: number;
8
- column: number;
9
- context: string | null;
10
- }
11
- interface Message {
12
- ID: string;
13
- severity: "FATAL" | "ERROR" | "WARNING" | "INFO" | "USAGE";
14
- message: string;
15
- additionalLocations: number;
16
- locations: Location[];
17
- }
18
- interface Report {
19
- messages: Message[];
20
- }
21
- declare function epubcheck(epubFile: string): Promise<Report>;
22
-
23
- export { type Location, type Message, type Report, epubcheck };