@storyteller-platform/epub 0.2.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/dist/node.cjs ADDED
@@ -0,0 +1,66 @@
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 node_exports = {};
20
+ __export(node_exports, {
21
+ Epub: () => Epub
22
+ });
23
+ module.exports = __toCommonJS(node_exports);
24
+ var import_promises = require("node:fs/promises");
25
+ var import_node_path = require("node:path");
26
+ var import_fs = require("@storyteller-platform/fs");
27
+ var import_index = require("./index.cjs");
28
+ class Epub extends import_index.Epub {
29
+ static create(...args) {
30
+ return super.create(...args);
31
+ }
32
+ static async from(...args) {
33
+ const pathOrData = args[0];
34
+ const fileData = typeof pathOrData === "string" ? await (0, import_fs.streamFile)(pathOrData) : pathOrData;
35
+ return super.from(fileData);
36
+ }
37
+ /**
38
+ * Write the current contents of the Epub to a new
39
+ * EPUB archive on disk.
40
+ *
41
+ * This _does not_ close the Epub. It can continue to
42
+ * be modified after it has been written to disk. Use
43
+ * `epub.close()` to close the Epub.
44
+ *
45
+ * When this method is called, the "dcterms:modified"
46
+ * meta tag is automatically updated to the current UTC
47
+ * timestamp.
48
+ *
49
+ * @param path The file path to write the new archive to. The
50
+ * parent directory does not need te exist -- the path will be
51
+ * recursively created.
52
+ */
53
+ async writeToFile(path) {
54
+ const data = await this.writeToArray();
55
+ if (!data.length)
56
+ throw new Error(
57
+ "Failed to write zip archive to file; writer returned no data"
58
+ );
59
+ await (0, import_promises.mkdir)((0, import_node_path.dirname)(path), { recursive: true });
60
+ await (0, import_promises.writeFile)(path, data);
61
+ }
62
+ }
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ Epub
66
+ });
@@ -0,0 +1,28 @@
1
+ import { Epub as Epub$1 } from './index.cjs';
2
+ export { AlternateScript, Collection, DcCreator, DcSubject, DublinCore, ElementName, EpubMetadata, ManifestItem, MetadataEntry, ParsedXml, XmlElement, XmlNode, XmlTextNode } from './index.cjs';
3
+ import '@zip.js/zip.js';
4
+ import 'fast-xml-parser';
5
+
6
+ declare class Epub extends Epub$1 {
7
+ static create(...args: Parameters<typeof Epub$1.create>): Promise<Epub>;
8
+ static from(...args: Parameters<typeof Epub$1.from>): Promise<Epub>;
9
+ /**
10
+ * Write the current contents of the Epub to a new
11
+ * EPUB archive on disk.
12
+ *
13
+ * This _does not_ close the Epub. It can continue to
14
+ * be modified after it has been written to disk. Use
15
+ * `epub.close()` to close the Epub.
16
+ *
17
+ * When this method is called, the "dcterms:modified"
18
+ * meta tag is automatically updated to the current UTC
19
+ * timestamp.
20
+ *
21
+ * @param path The file path to write the new archive to. The
22
+ * parent directory does not need te exist -- the path will be
23
+ * recursively created.
24
+ */
25
+ writeToFile(path: string): Promise<void>;
26
+ }
27
+
28
+ export { Epub };
package/dist/node.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { Epub as Epub$1 } from './index.js';
2
+ export { AlternateScript, Collection, DcCreator, DcSubject, DublinCore, ElementName, EpubMetadata, ManifestItem, MetadataEntry, ParsedXml, XmlElement, XmlNode, XmlTextNode } from './index.js';
3
+ import '@zip.js/zip.js';
4
+ import 'fast-xml-parser';
5
+
6
+ declare class Epub extends Epub$1 {
7
+ static create(...args: Parameters<typeof Epub$1.create>): Promise<Epub>;
8
+ static from(...args: Parameters<typeof Epub$1.from>): Promise<Epub>;
9
+ /**
10
+ * Write the current contents of the Epub to a new
11
+ * EPUB archive on disk.
12
+ *
13
+ * This _does not_ close the Epub. It can continue to
14
+ * be modified after it has been written to disk. Use
15
+ * `epub.close()` to close the Epub.
16
+ *
17
+ * When this method is called, the "dcterms:modified"
18
+ * meta tag is automatically updated to the current UTC
19
+ * timestamp.
20
+ *
21
+ * @param path The file path to write the new archive to. The
22
+ * parent directory does not need te exist -- the path will be
23
+ * recursively created.
24
+ */
25
+ writeToFile(path: string): Promise<void>;
26
+ }
27
+
28
+ export { Epub };
package/dist/node.js ADDED
@@ -0,0 +1,42 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ import { streamFile } from "@storyteller-platform/fs";
4
+ import { Epub as BaseEpub } from "./index.js";
5
+ class Epub extends BaseEpub {
6
+ static create(...args) {
7
+ return super.create(...args);
8
+ }
9
+ static async from(...args) {
10
+ const pathOrData = args[0];
11
+ const fileData = typeof pathOrData === "string" ? await streamFile(pathOrData) : pathOrData;
12
+ return super.from(fileData);
13
+ }
14
+ /**
15
+ * Write the current contents of the Epub to a new
16
+ * EPUB archive on disk.
17
+ *
18
+ * This _does not_ close the Epub. It can continue to
19
+ * be modified after it has been written to disk. Use
20
+ * `epub.close()` to close the Epub.
21
+ *
22
+ * When this method is called, the "dcterms:modified"
23
+ * meta tag is automatically updated to the current UTC
24
+ * timestamp.
25
+ *
26
+ * @param path The file path to write the new archive to. The
27
+ * parent directory does not need te exist -- the path will be
28
+ * recursively created.
29
+ */
30
+ async writeToFile(path) {
31
+ const data = await this.writeToArray();
32
+ if (!data.length)
33
+ throw new Error(
34
+ "Failed to write zip archive to file; writer returned no data"
35
+ );
36
+ await mkdir(dirname(path), { recursive: true });
37
+ await writeFile(path, data);
38
+ }
39
+ }
40
+ export {
41
+ Epub
42
+ };
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@storyteller-platform/epub",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "module": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "license": "MIT",
8
+ "exports": {
9
+ ".": {
10
+ "@storyteller": "./index.ts",
11
+ "@storyteller-node": "./node.ts",
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ },
21
+ "./node": {
22
+ "@storyteller": "./node.ts",
23
+ "@storyteller-node": "./node.ts",
24
+ "import": {
25
+ "types": "./dist/node.d.ts",
26
+ "default": "./dist/node.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/node.d.cts",
30
+ "default": "./dist/node.cjs"
31
+ }
32
+ }
33
+ },
34
+ "files": [
35
+ "dist/"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsup",
39
+ "readme:toc": "markdown-toc --maxdepth=5 --append='\n- [API Docs](#api-docs)' --bullets='-' -i readme-stub.md",
40
+ "readme:api": "typedoc",
41
+ "readme": "yarn readme:api && yarn readme:toc && cat readme-stub.md > README.md && tail -n +2 gen/README.md >> README.md",
42
+ "test": "tsx -C @storyteller --test index.test.ts",
43
+ "test:watch": "tsx -C @storyteller --test --watch index.test.ts",
44
+ "prepack": "yarn build"
45
+ },
46
+ "devDependencies": {
47
+ "@storyteller-platform/tsup": "^0.1.0",
48
+ "@tsconfig/strictest": "^2.0.5",
49
+ "@types/mime-types": "^2",
50
+ "@types/node": "^22.10.1",
51
+ "markdown-toc": "^1.2.0",
52
+ "remark-toc": "^9.0.0",
53
+ "tsup": "^8.5.0",
54
+ "tsx": "^4.19.2",
55
+ "typedoc": "^0.28.4",
56
+ "typedoc-plugin-markdown": "^4.6.3",
57
+ "typedoc-plugin-remark": "^1.2.0",
58
+ "typescript": "^5.8.3"
59
+ },
60
+ "dependencies": {
61
+ "@storyteller-platform/fs": "^0.1.2",
62
+ "@storyteller-platform/path": "^0.1.0",
63
+ "@zip.js/zip.js": "^2.0.0",
64
+ "async-mutex": "^0.5.0",
65
+ "fast-xml-parser": "^4.0.0",
66
+ "mem": "^8.0.0",
67
+ "mime-types": "^3.0.1",
68
+ "nanoid": "^5.1.5"
69
+ },
70
+ "publishConfig": {
71
+ "access": "public"
72
+ }
73
+ }