@acanthis-dec/epub 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 ConstasJ
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,111 @@
1
- # Temporary Holding Version
1
+ # @acanthis-dec/epub
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [中文文档](./README.zh-CN.md) | [Workspace README](../../README.md)
4
+
5
+ Platform-independent, zero-Node in-memory EPUB 3.0 builder for Acanthis. It converts light novel metadata, sanitized chapter HTML, covers, and deduplicated illustrations into standard EPUB 3.0 archives (with EPUB 2 NCX and cover metadata compatibility) as pure `Uint8Array` buffers suitable for Node.js, Bun, browsers, and Web Workers.
6
+
7
+ ## Runtime Compatibility Guarantee
8
+
9
+ - **Zero Node.js APIs**: No `node:*` imports and no global `Buffer` usage anywhere in the package.
10
+ - **Compile-time & Bundle Guards**: Built with `tsdown` (`platform: "neutral"`) and compiled with TypeScript `"types": []` (without `@types/node`), making it safe for browser Web Workers without Node polyfills.
11
+ - **EPUB 3.0 Archive Standards**: Always places uncompressed `mimetype` (`application/epub+zip`, `{ level: 0 }`) as the first ZIP entry, decodes HTML named entities to UTF-8, normalizes leading chapter headings, strips dangerous tags/attributes, deduplicates illustrations by `sourceUrl`, and replaces missing images with `<p class="image-placeholder">[插图未包含]</p>`.
12
+
13
+ ## Installation
14
+
15
+ Workspace usage:
16
+
17
+ ```powershell
18
+ pnpm install --frozen-lockfile
19
+ pnpm --filter=@acanthis-dec/epub run check-types
20
+ pnpm --filter=@acanthis-dec/epub run build
21
+ ```
22
+
23
+ Import from workspace source or the published ESM package:
24
+
25
+ ```ts
26
+ import {
27
+ buildNovelEpub,
28
+ buildVolumeEpub,
29
+ type EpubChapterData,
30
+ type EpubImageAsset,
31
+ type EpubVolumeData,
32
+ type NovelEpubInput,
33
+ type VolumeEpubInput,
34
+ } from "@acanthis-dec/epub";
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ### Single-Volume EPUB (`buildVolumeEpub`)
40
+
41
+ ```ts
42
+ import { buildVolumeEpub } from "@acanthis-dec/epub";
43
+
44
+ const epubBytes = buildVolumeEpub({
45
+ identifier: "urn:acanthis:linovelib:3590:vol:101",
46
+ novelTitle: "Example Novel",
47
+ volumeTitle: "Volume 1",
48
+ author: "Example Author",
49
+ language: "zh-CN",
50
+ cover: {
51
+ sourceUrl: "https://example.invalid/cover.jpg",
52
+ data: coverUint8Array,
53
+ mimeType: "image/jpeg",
54
+ },
55
+ chapters: [
56
+ {
57
+ id: "1001",
58
+ title: "Chapter 1",
59
+ html: "<p>Hello&nbsp;World</p>",
60
+ },
61
+ ],
62
+ illustrations: [],
63
+ });
64
+ ```
65
+
66
+ ### Multi-Volume Novel EPUB (`buildNovelEpub`)
67
+
68
+ ```ts
69
+ import { buildNovelEpub } from "@acanthis-dec/epub";
70
+
71
+ const epubBytes = buildNovelEpub({
72
+ identifier: "urn:acanthis:linovelib:3590",
73
+ title: "Example Novel",
74
+ author: "Example Author",
75
+ volumes: [
76
+ {
77
+ id: "101",
78
+ title: "Volume 1",
79
+ chapters: [
80
+ {
81
+ id: "1001",
82
+ title: "Chapter 1",
83
+ html: '<p>Scene</p><img src="https://example.invalid/img-1.png" />',
84
+ },
85
+ ],
86
+ },
87
+ ],
88
+ illustrations: [
89
+ {
90
+ sourceUrl: "https://example.invalid/img-1.png",
91
+ data: imageUint8Array,
92
+ mimeType: "image/png",
93
+ },
94
+ ],
95
+ });
96
+ ```
97
+
98
+ ## API
99
+
100
+ ### Functions
101
+
102
+ - `buildVolumeEpub(input: VolumeEpubInput): Uint8Array` — Builds a single-volume EPUB 3.0 archive with a 1-level navigation tree (`nav.xhtml` + `toc.ncx`).
103
+ - `buildNovelEpub(input: NovelEpubInput): Uint8Array` — Builds a multi-volume EPUB 3.0 archive with volume title pages (`OEBPS/text/vol-XXX.xhtml`), deduplicated volume covers, and a 2-level nested navigation tree.
104
+
105
+ ### Types
106
+
107
+ - `EpubImageAsset` — `{ sourceUrl: string; data: Uint8Array; mimeType: string }` representing a cover or illustration binary keyed by its HTML `src` / source URL.
108
+ - `EpubChapterData` — `{ id: string; title: string; html: string }` representing a single chapter's metadata and HTML content.
109
+ - `EpubVolumeData` — `{ id: string; title: string; cover?: EpubImageAsset | undefined; chapters: EpubChapterData[] }` representing a volume within a multi-volume EPUB.
110
+ - `VolumeEpubInput` — Input payload for `buildVolumeEpub` (`identifier`, `novelTitle`, `volumeTitle`, `author`, optional `language`, `summary`, `genres`, `modifiedAt`, `cover`, plus `chapters` and `illustrations`).
111
+ - `NovelEpubInput` — Input payload for `buildNovelEpub` (`identifier`, `title`, `author`, optional `language`, `summary`, `genres`, `modifiedAt`, `cover`, plus `volumes` and `illustrations`).
@@ -0,0 +1,111 @@
1
+ # @acanthis-dec/epub
2
+
3
+ [English README](./README.md) | [工作区 README](../../README.zh-CN.md)
4
+
5
+ Acanthis 的平台无关、零 Node 耦合纯内存 EPUB 3.0 组装引擎。它将轻小说元数据、清洗后的章节 HTML、封面及去重后的插图打包为标准 EPUB 3.0 归档(同时兼容 EPUB 2 NCX 目录与封面元数据),输出纯 `Uint8Array` 二进制数据,可直接运行于 Node.js、Bun、浏览器与 Web Worker 环境。
6
+
7
+ ## 运行环境与兼容性保证
8
+
9
+ - **零 Node.js API 依赖**:包内不使用任何 `node:*` 模块或全局 `Buffer`。
10
+ - **编译期与打包期门禁**:`tsdown` 配置 `platform: "neutral"`,且 TypeScript 显式覆盖 `"types": []`(不引入 `@types/node`),确保浏览器端 Web Worker 无需任何 Node polyfill 即可直接打包运行。
11
+ - **EPUB 3.0 归档规范**:ZIP 首条目固定为无压缩 `mimetype`(`application/epub+zip`,`{ level: 0 }`),自动将 HTML 命名实体解码为 UTF-8、归一化章节首标题、清理危险标签与事件属性、按 `sourceUrl` 对插图去重注册,并将缺失插图替换为 `<p class="image-placeholder">[插图未包含]</p>`。
12
+
13
+ ## 安装
14
+
15
+ 工作区内使用:
16
+
17
+ ```powershell
18
+ pnpm install --frozen-lockfile
19
+ pnpm --filter=@acanthis-dec/epub run check-types
20
+ pnpm --filter=@acanthis-dec/epub run build
21
+ ```
22
+
23
+ 从 workspace 源码或发布后的 ESM 包导入:
24
+
25
+ ```ts
26
+ import {
27
+ buildNovelEpub,
28
+ buildVolumeEpub,
29
+ type EpubChapterData,
30
+ type EpubImageAsset,
31
+ type EpubVolumeData,
32
+ type NovelEpubInput,
33
+ type VolumeEpubInput,
34
+ } from "@acanthis-dec/epub";
35
+ ```
36
+
37
+ ## 用法
38
+
39
+ ### 单卷导出(`buildVolumeEpub`)
40
+
41
+ ```ts
42
+ import { buildVolumeEpub } from "@acanthis-dec/epub";
43
+
44
+ const epubBytes = buildVolumeEpub({
45
+ identifier: "urn:acanthis:linovelib:3590:vol:101",
46
+ novelTitle: "示例作品",
47
+ volumeTitle: "第一卷",
48
+ author: "示例作者",
49
+ language: "zh-CN",
50
+ cover: {
51
+ sourceUrl: "https://example.invalid/cover.jpg",
52
+ data: coverUint8Array,
53
+ mimeType: "image/jpeg",
54
+ },
55
+ chapters: [
56
+ {
57
+ id: "1001",
58
+ title: "第一章",
59
+ html: "<p>你好&nbsp;世界</p>",
60
+ },
61
+ ],
62
+ illustrations: [],
63
+ });
64
+ ```
65
+
66
+ ### 整书多卷合集导出(`buildNovelEpub`)
67
+
68
+ ```ts
69
+ import { buildNovelEpub } from "@acanthis-dec/epub";
70
+
71
+ const epubBytes = buildNovelEpub({
72
+ identifier: "urn:acanthis:linovelib:3590",
73
+ title: "示例作品",
74
+ author: "示例作者",
75
+ volumes: [
76
+ {
77
+ id: "101",
78
+ title: "第一卷",
79
+ chapters: [
80
+ {
81
+ id: "1001",
82
+ title: "第一章",
83
+ html: '<p>正文</p><img src="https://example.invalid/img-1.png" />',
84
+ },
85
+ ],
86
+ },
87
+ ],
88
+ illustrations: [
89
+ {
90
+ sourceUrl: "https://example.invalid/img-1.png",
91
+ data: imageUint8Array,
92
+ mimeType: "image/png",
93
+ },
94
+ ],
95
+ });
96
+ ```
97
+
98
+ ## API
99
+
100
+ ### 函数
101
+
102
+ - `buildVolumeEpub(input: VolumeEpubInput): Uint8Array` — 生成包含一维章节目录(`nav.xhtml` + `toc.ncx`)的单卷 EPUB 3.0 归档。
103
+ - `buildNovelEpub(input: NovelEpubInput): Uint8Array` — 生成包含分卷扉页(`OEBPS/text/vol-XXX.xhtml`)、去重分卷封面与二级嵌套目录树的多卷合集 EPUB 3.0 归档。
104
+
105
+ ### 公开类型
106
+
107
+ - `EpubImageAsset` — `{ sourceUrl: string; data: Uint8Array; mimeType: string }`,表示按 HTML `<img src>` / 来源 URL 索引的封面或插图二进制资产。
108
+ - `EpubChapterData` — `{ id: string; title: string; html: string }`,表示单章元数据与 HTML 正文。
109
+ - `EpubVolumeData` — `{ id: string; title: string; cover?: EpubImageAsset | undefined; chapters: EpubChapterData[] }`,表示整书合集中的单个分卷。
110
+ - `VolumeEpubInput` — `buildVolumeEpub` 的输入参数(`identifier`、`novelTitle`、`volumeTitle`、`author`,可选 `language`、`summary`、`genres`、`modifiedAt`、`cover`,以及 `chapters` 和 `illustrations`)。
111
+ - `NovelEpubInput` — `buildNovelEpub` 的输入参数(`identifier`、`title`、`author`,可选 `language`、`summary`、`genres`、`modifiedAt`、`cover`,以及 `volumes` 和 `illustrations`)。
@@ -0,0 +1,45 @@
1
+ interface EpubImageAsset {
2
+ /** 原始或服务端重写后的匹配键 URL(与章节 HTML 中 <img src> 一致) */
3
+ sourceUrl: string;
4
+ data: Uint8Array;
5
+ mimeType: string;
6
+ }
7
+ interface EpubChapterData {
8
+ id: string;
9
+ title: string;
10
+ html: string;
11
+ }
12
+ interface EpubVolumeData {
13
+ id: string;
14
+ title: string;
15
+ cover?: EpubImageAsset | undefined;
16
+ chapters: EpubChapterData[];
17
+ }
18
+ interface VolumeEpubInput {
19
+ identifier: string;
20
+ novelTitle: string;
21
+ volumeTitle: string;
22
+ author: string;
23
+ language?: string | undefined;
24
+ summary?: string | undefined;
25
+ genres?: string[] | undefined;
26
+ modifiedAt?: Date | undefined;
27
+ cover?: EpubImageAsset | undefined;
28
+ chapters: EpubChapterData[];
29
+ illustrations: EpubImageAsset[];
30
+ }
31
+ interface NovelEpubInput {
32
+ identifier: string;
33
+ title: string;
34
+ author: string;
35
+ language?: string | undefined;
36
+ summary?: string | undefined;
37
+ genres?: string[] | undefined;
38
+ modifiedAt?: Date | undefined;
39
+ cover?: EpubImageAsset | undefined;
40
+ volumes: EpubVolumeData[];
41
+ illustrations: EpubImageAsset[];
42
+ }
43
+ export declare function buildVolumeEpub(input: VolumeEpubInput): Uint8Array;
44
+ export declare function buildNovelEpub(input: NovelEpubInput): Uint8Array;
45
+ export type { EpubChapterData, EpubImageAsset, EpubVolumeData, NovelEpubInput, VolumeEpubInput };
package/dist/index.mjs ADDED
@@ -0,0 +1,877 @@
1
+ import { strToU8, zipSync } from "fflate";
2
+ import render from "dom-serializer";
3
+ import { Element, Text, isComment, isDirective, isTag, isText } from "domhandler";
4
+ import { parseDocument } from "htmlparser2";
5
+ // src/xhtml.ts
6
+ const DEFAULT_LANGUAGE$1 = "zh-CN";
7
+ const MIME_TO_EXTENSION = {
8
+ "image/jpeg": "jpg",
9
+ "image/jpg": "jpg",
10
+ "image/png": "png",
11
+ "image/webp": "webp",
12
+ "image/gif": "gif",
13
+ "image/svg+xml": "svg",
14
+ "image/avif": "avif"
15
+ };
16
+ const KNOWN_IMAGE_EXTENSIONS = {
17
+ jpg: "jpg",
18
+ jpeg: "jpg",
19
+ png: "png",
20
+ webp: "webp",
21
+ gif: "gif",
22
+ svg: "svg",
23
+ avif: "avif"
24
+ };
25
+ const REMOVED_TAG_NAMES = /* @__PURE__ */ new Set([
26
+ "script",
27
+ "iframe",
28
+ "style",
29
+ "noscript",
30
+ "object",
31
+ "embed"
32
+ ]);
33
+ const HEADING_TAG_NAMES = /* @__PURE__ */ new Set([
34
+ "h1",
35
+ "h2",
36
+ "h3"
37
+ ]);
38
+ const URI_ATTRIBUTE_NAMES = /* @__PURE__ */ new Set([
39
+ "href",
40
+ "src",
41
+ "xlink:href",
42
+ "action",
43
+ "formaction",
44
+ "poster",
45
+ "data",
46
+ "cite",
47
+ "background",
48
+ "srcset"
49
+ ]);
50
+ const VALID_XML_NCNAME = /^[A-Za-z_][A-Za-z0-9._-]*$/;
51
+ const ALLOWED_ATTR_NAMESPACE_PREFIXES = /* @__PURE__ */ new Set(["xml", "epub"]);
52
+ function isAllowedXmlAttributeName(name) {
53
+ const colonIndex = name.indexOf(":");
54
+ if (colonIndex === -1) return VALID_XML_NCNAME.test(name);
55
+ if (name.indexOf(":", colonIndex + 1) !== -1) return false;
56
+ const prefix = name.slice(0, colonIndex);
57
+ const localName = name.slice(colonIndex + 1);
58
+ if (!VALID_XML_NCNAME.test(prefix) || !VALID_XML_NCNAME.test(localName)) return false;
59
+ if (name === "xmlns:epub") return true;
60
+ return ALLOWED_ATTR_NAMESPACE_PREFIXES.has(prefix);
61
+ }
62
+ const XML_ESCAPE_MAP = {
63
+ "&": "&amp;",
64
+ "<": "&lt;",
65
+ ">": "&gt;",
66
+ "\"": "&quot;",
67
+ "'": "&apos;"
68
+ };
69
+ function escapeXml(text) {
70
+ return stripInvalidXmlControlChars(text).replace(/[&<>"']/g, (char) => XML_ESCAPE_MAP[char] ?? char);
71
+ }
72
+ function extractExtensionFromUrl(sourceUrl) {
73
+ if (!sourceUrl) return;
74
+ const trimmed = sourceUrl.trim();
75
+ if (!trimmed) return;
76
+ let pathname = trimmed;
77
+ try {
78
+ pathname = new URL(trimmed, "https://example.invalid").pathname;
79
+ } catch {
80
+ const withoutHash = trimmed.split("#")[0] ?? trimmed;
81
+ pathname = withoutHash.split("?")[0] ?? withoutHash;
82
+ }
83
+ const lastSegment = pathname.split("/").pop() ?? "";
84
+ const match = /\.([a-z0-9]+)$/i.exec(lastSegment);
85
+ if (!match?.[1]) return;
86
+ return KNOWN_IMAGE_EXTENSIONS[match[1].toLowerCase()];
87
+ }
88
+ function resolveImageExtension(mimeType, sourceUrl) {
89
+ const normalizedMime = mimeType.split(";")[0]?.trim().toLowerCase() ?? "";
90
+ const mapped = MIME_TO_EXTENSION[normalizedMime];
91
+ if (mapped) return mapped;
92
+ return extractExtensionFromUrl(sourceUrl) ?? "jpg";
93
+ }
94
+ function stripWhitespaceAndControl(value) {
95
+ const withoutWhitespace = value.replace(/\s+/g, "");
96
+ let result = "";
97
+ for (let i = 0; i < withoutWhitespace.length; i += 1) {
98
+ const code = withoutWhitespace.charCodeAt(i);
99
+ if (code <= 32 || code === 127) continue;
100
+ result += withoutWhitespace[i] ?? "";
101
+ }
102
+ return result;
103
+ }
104
+ function isUnsafeUri(value) {
105
+ const normalized = stripWhitespaceAndControl(value).toLowerCase();
106
+ return normalized.startsWith("javascript:") || normalized.startsWith("vbscript:") || normalized.startsWith("data:text/html");
107
+ }
108
+ function sanitizeElementAttributes(element) {
109
+ const cleaned = {};
110
+ for (const [rawKey, rawValue] of Object.entries(element.attribs)) {
111
+ const key = rawKey.trim();
112
+ if (!key || !isAllowedXmlAttributeName(key)) continue;
113
+ const lowerKey = key.toLowerCase();
114
+ if (lowerKey.startsWith("on") || lowerKey === "srcdoc") continue;
115
+ if (URI_ATTRIBUTE_NAMES.has(lowerKey) && isUnsafeUri(rawValue)) continue;
116
+ cleaned[key] = rawValue;
117
+ }
118
+ element.attribs = cleaned;
119
+ }
120
+ function sanitizeNodeList(nodes, imageHrefBySourceUrl) {
121
+ const result = [];
122
+ for (const node of nodes) {
123
+ if (isComment(node) || isDirective(node)) continue;
124
+ if (!isTag(node)) {
125
+ result.push(node);
126
+ continue;
127
+ }
128
+ const tagName = node.name.toLowerCase();
129
+ if (REMOVED_TAG_NAMES.has(tagName)) continue;
130
+ if (tagName.includes(":")) {
131
+ const unwrappedChildren = sanitizeNodeList(node.children, imageHrefBySourceUrl);
132
+ for (const child of unwrappedChildren) {
133
+ child.parent = node.parent;
134
+ result.push(child);
135
+ }
136
+ continue;
137
+ }
138
+ node.name = tagName;
139
+ if (tagName === "img") {
140
+ const rawSrc = node.attribs.src;
141
+ const mappedHref = rawSrc !== void 0 ? imageHrefBySourceUrl.get(rawSrc) ?? imageHrefBySourceUrl.get(rawSrc.trim()) : void 0;
142
+ if (mappedHref !== void 0) {
143
+ node.attribs = {
144
+ src: mappedHref,
145
+ alt: node.attribs.alt?.trim() || "插图"
146
+ };
147
+ node.children = [];
148
+ result.push(node);
149
+ } else {
150
+ const placeholder = new Element("p", { class: "image-placeholder" }, [new Text("[插图未包含]")]);
151
+ placeholder.parent = node.parent;
152
+ result.push(placeholder);
153
+ }
154
+ continue;
155
+ }
156
+ sanitizeElementAttributes(node);
157
+ node.children = sanitizeNodeList(node.children, imageHrefBySourceUrl);
158
+ result.push(node);
159
+ }
160
+ return result;
161
+ }
162
+ function collectTextContent(node) {
163
+ if (isText(node)) return node.data;
164
+ if (isTag(node)) {
165
+ let text = "";
166
+ for (const child of node.children) text += collectTextContent(child);
167
+ return text;
168
+ }
169
+ return "";
170
+ }
171
+ function normalizeLeadingHeading(nodes, chapterTitle) {
172
+ const firstSignificant = nodes.find((node) => {
173
+ if (isComment(node)) return false;
174
+ if (isText(node)) return node.data.trim().length > 0;
175
+ return true;
176
+ });
177
+ if (firstSignificant && isTag(firstSignificant) && HEADING_TAG_NAMES.has(firstSignificant.name.toLowerCase())) {
178
+ firstSignificant.name = "h1";
179
+ firstSignificant.attribs = {
180
+ ...firstSignificant.attribs,
181
+ class: "chapter-title"
182
+ };
183
+ if (collectTextContent(firstSignificant).trim().length === 0) firstSignificant.children = [new Text(chapterTitle)];
184
+ return nodes;
185
+ }
186
+ return [new Element("h1", { class: "chapter-title" }, [new Text(chapterTitle)]), ...nodes];
187
+ }
188
+ function wrapXhtmlDocument(options) {
189
+ const escapedLang = escapeXml(options.language?.trim() || DEFAULT_LANGUAGE$1);
190
+ const escapedTitle = escapeXml(options.title);
191
+ const bodyAttrs = options.bodyAttributes ? ` ${options.bodyAttributes}` : "";
192
+ return [
193
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
194
+ "<!DOCTYPE html>",
195
+ `<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="${escapedLang}" lang="${escapedLang}">`,
196
+ "<head>",
197
+ " <meta charset=\"UTF-8\" />",
198
+ `\t<title>${escapedTitle}</title>`,
199
+ " <link rel=\"stylesheet\" type=\"text/css\" href=\"../styles/main.css\" />",
200
+ "</head>",
201
+ `<body${bodyAttrs}>`,
202
+ options.bodyHtml,
203
+ "</body>",
204
+ "</html>",
205
+ ""
206
+ ].join("\n");
207
+ }
208
+ function buildCoverPageXhtml(title, imageHref, language) {
209
+ const escapedTitle = escapeXml(title);
210
+ return wrapXhtmlDocument({
211
+ title,
212
+ language,
213
+ bodyHtml: `\t<div class="cover-page"><img src="${escapeXml(imageHref)}" alt="${escapedTitle}" /></div>`,
214
+ bodyAttributes: "epub:type=\"cover\""
215
+ });
216
+ }
217
+ function buildVolumeTitlePageXhtml(options) {
218
+ const escapedTitle = escapeXml(options.title);
219
+ const parts = [" <div class=\"volume-title-page\">"];
220
+ if (options.coverHref) parts.push(`\t\t<img src="${escapeXml(options.coverHref)}" alt="${escapedTitle}" />`);
221
+ parts.push(`\t\t<h1 class="volume-title">${escapedTitle}</h1>`);
222
+ parts.push(" </div>");
223
+ return wrapXhtmlDocument({
224
+ title: options.title,
225
+ language: options.language,
226
+ bodyHtml: parts.join("\n")
227
+ });
228
+ }
229
+ function stripInvalidXmlControlChars(text) {
230
+ let hasInvalid = false;
231
+ for (let i = 0; i < text.length; i += 1) {
232
+ const code = text.charCodeAt(i);
233
+ if (code <= 8 || code === 11 || code === 12 || code >= 14 && code <= 31) {
234
+ hasInvalid = true;
235
+ break;
236
+ }
237
+ }
238
+ if (!hasInvalid) return text;
239
+ let result = "";
240
+ for (let i = 0; i < text.length; i += 1) {
241
+ const code = text.charCodeAt(i);
242
+ if (code <= 8 || code === 11 || code === 12 || code >= 14 && code <= 31) continue;
243
+ result += text[i] ?? "";
244
+ }
245
+ return result;
246
+ }
247
+ function escapeXmlFragmentChars(text) {
248
+ return stripInvalidXmlControlChars(text).replace(/[&<>]/g, (char) => XML_ESCAPE_MAP[char] ?? char);
249
+ }
250
+ function escapeNodesForXmlSerialization(nodes) {
251
+ for (const node of nodes) {
252
+ if (isText(node)) {
253
+ node.data = escapeXmlFragmentChars(node.data);
254
+ continue;
255
+ }
256
+ if (isTag(node)) {
257
+ const escapedAttribs = {};
258
+ for (const [key, value] of Object.entries(node.attribs)) escapedAttribs[key] = escapeXmlFragmentChars(value);
259
+ node.attribs = escapedAttribs;
260
+ escapeNodesForXmlSerialization(node.children);
261
+ }
262
+ }
263
+ }
264
+ function sanitizeChapterHtmlToXhtml(options) {
265
+ const normalizedChildren = normalizeLeadingHeading(sanitizeNodeList(parseDocument(options.chapter.html, { decodeEntities: true }).children, options.imageHrefBySourceUrl), options.chapter.title);
266
+ escapeNodesForXmlSerialization(normalizedChildren);
267
+ const bodyHtml = render(normalizedChildren, {
268
+ xmlMode: true,
269
+ encodeEntities: false
270
+ });
271
+ return wrapXhtmlDocument({
272
+ title: options.chapter.title,
273
+ language: options.language,
274
+ bodyHtml
275
+ });
276
+ }
277
+ // src/nav.ts
278
+ function renderNavList(entries, indentLevel) {
279
+ const indent = " ".repeat(indentLevel);
280
+ const itemIndent = " ".repeat(indentLevel + 1);
281
+ if (entries.length === 0) return `${indent}<ol></ol>`;
282
+ const lines = [`${indent}<ol>`];
283
+ for (const entry of entries) {
284
+ const href = escapeXml(entry.href);
285
+ const title = escapeXml(entry.title);
286
+ const children = entry.children;
287
+ if (children && children.length > 0) {
288
+ lines.push(`${itemIndent}<li>`);
289
+ lines.push(`${itemIndent}\t<a href="${href}">${title}</a>`);
290
+ lines.push(renderNavList(children, indentLevel + 2));
291
+ lines.push(`${itemIndent}</li>`);
292
+ } else lines.push(`${itemIndent}<li><a href="${href}">${title}</a></li>`);
293
+ }
294
+ lines.push(`${indent}</ol>`);
295
+ return lines.join("\n");
296
+ }
297
+ function buildNavXhtml(options) {
298
+ const escapedLang = escapeXml(options.language.trim() || "zh-CN");
299
+ const escapedTitle = escapeXml(options.title);
300
+ return [
301
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
302
+ "<!DOCTYPE html>",
303
+ `<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="${escapedLang}" lang="${escapedLang}">`,
304
+ "<head>",
305
+ " <meta charset=\"UTF-8\" />",
306
+ `\t<title>${escapedTitle}</title>`,
307
+ " <link rel=\"stylesheet\" type=\"text/css\" href=\"styles/main.css\" />",
308
+ "</head>",
309
+ "<body>",
310
+ " <nav epub:type=\"toc\" id=\"toc\">",
311
+ `\t\t<h1>${escapedTitle}</h1>`,
312
+ renderNavList(options.entries, 2),
313
+ " </nav>",
314
+ "</body>",
315
+ "</html>",
316
+ ""
317
+ ].join("\n");
318
+ }
319
+ // src/ncx.ts
320
+ function computeDepth(entries) {
321
+ if (entries.length === 0) return 1;
322
+ let maxDepth = 1;
323
+ for (const entry of entries) if (entry.children && entry.children.length > 0) {
324
+ const childDepth = 1 + computeDepth(entry.children);
325
+ if (childDepth > maxDepth) maxDepth = childDepth;
326
+ }
327
+ return maxDepth;
328
+ }
329
+ function renderNavPoints(entries, indentLevel, counter) {
330
+ const indent = " ".repeat(indentLevel);
331
+ const lines = [];
332
+ for (const entry of entries) {
333
+ counter.value += 1;
334
+ const order = counter.value;
335
+ lines.push(`${indent}<navPoint id="navPoint-${order}" playOrder="${order}">`);
336
+ lines.push(`${indent}\t<navLabel>`);
337
+ lines.push(`${indent}\t\t<text>${escapeXml(entry.title)}</text>`);
338
+ lines.push(`${indent}\t</navLabel>`);
339
+ lines.push(`${indent}\t<content src="${escapeXml(entry.href)}" />`);
340
+ if (entry.children && entry.children.length > 0) lines.push(...renderNavPoints(entry.children, indentLevel + 1, counter));
341
+ lines.push(`${indent}</navPoint>`);
342
+ }
343
+ return lines;
344
+ }
345
+ function buildTocNcx(options) {
346
+ const depth = computeDepth(options.entries);
347
+ const navPointLines = renderNavPoints(options.entries, 2, { value: 0 });
348
+ return [
349
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
350
+ "<ncx xmlns=\"http://www.daisy.org/z3986/2005/ncx/\" version=\"2005-1\">",
351
+ " <head>",
352
+ `\t\t<meta name="dtb:uid" content="${escapeXml(options.identifier)}" />`,
353
+ `\t\t<meta name="dtb:depth" content="${depth}" />`,
354
+ " <meta name=\"dtb:totalPageCount\" content=\"0\" />",
355
+ " <meta name=\"dtb:maxPageNumber\" content=\"0\" />",
356
+ " </head>",
357
+ " <docTitle>",
358
+ `\t\t<text>${escapeXml(options.title)}</text>`,
359
+ " </docTitle>",
360
+ " <docAuthor>",
361
+ `\t\t<text>${escapeXml(options.author)}</text>`,
362
+ " </docAuthor>",
363
+ " <navMap>",
364
+ ...navPointLines,
365
+ " </navMap>",
366
+ "</ncx>",
367
+ ""
368
+ ].join("\n");
369
+ }
370
+ // src/opf.ts
371
+ function buildContainerXml() {
372
+ return [
373
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
374
+ "<container version=\"1.0\" xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\">",
375
+ " <rootfiles>",
376
+ " <rootfile full-path=\"OEBPS/content.opf\" media-type=\"application/oebps-package+xml\" />",
377
+ " </rootfiles>",
378
+ "</container>",
379
+ ""
380
+ ].join("\n");
381
+ }
382
+ function buildContentOpf(options) {
383
+ const modifiedTimestamp = `${options.modifiedAt.toISOString().slice(0, 19)}Z`;
384
+ const lines = [
385
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
386
+ "<package xmlns=\"http://www.idpf.org/2007/opf\" version=\"3.0\" unique-identifier=\"bookid\">",
387
+ " <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\">",
388
+ `\t\t<dc:identifier id="bookid">${escapeXml(options.identifier)}</dc:identifier>`,
389
+ `\t\t<dc:title>${escapeXml(options.title)}</dc:title>`,
390
+ `\t\t<dc:creator>${escapeXml(options.author)}</dc:creator>`,
391
+ `\t\t<dc:language>${escapeXml(options.language)}</dc:language>`
392
+ ];
393
+ const summary = options.summary?.trim();
394
+ if (summary) lines.push(`\t\t<dc:description>${escapeXml(summary)}</dc:description>`);
395
+ for (const genre of options.genres ?? []) {
396
+ const trimmed = genre.trim();
397
+ if (trimmed) lines.push(`\t\t<dc:subject>${escapeXml(trimmed)}</dc:subject>`);
398
+ }
399
+ lines.push(`\t\t<meta property="dcterms:modified">${modifiedTimestamp}</meta>`);
400
+ const coverImageId = options.coverImageId?.trim();
401
+ if (coverImageId) lines.push(`\t\t<meta name="cover" content="${escapeXml(coverImageId)}" />`);
402
+ lines.push(" </metadata>");
403
+ lines.push(" <manifest>");
404
+ for (const item of options.manifest) {
405
+ const propertiesAttr = item.properties ? ` properties="${escapeXml(item.properties)}"` : "";
406
+ lines.push(`\t\t<item id="${escapeXml(item.id)}" href="${escapeXml(item.href)}" media-type="${escapeXml(item.mediaType)}"${propertiesAttr} />`);
407
+ }
408
+ lines.push(" </manifest>");
409
+ lines.push(" <spine toc=\"ncx\">");
410
+ for (const spineItem of options.spine) {
411
+ const linearAttr = spineItem.linear === false ? " linear=\"no\"" : "";
412
+ lines.push(`\t\t<itemref idref="${escapeXml(spineItem.idref)}"${linearAttr} />`);
413
+ }
414
+ lines.push(" </spine>");
415
+ lines.push("</package>");
416
+ lines.push("");
417
+ return lines.join("\n");
418
+ }
419
+ // src/styles.ts
420
+ const DEFAULT_EPUB_CSS = `html,
421
+ body {
422
+ margin: 0;
423
+ padding: 0;
424
+ font-family: "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "SimSun", Georgia, serif;
425
+ font-size: 1em;
426
+ line-height: 1.85;
427
+ color: #1f2328;
428
+ text-align: justify;
429
+ word-break: break-word;
430
+ }
431
+
432
+ body {
433
+ padding: 0.5em 0.8em;
434
+ }
435
+
436
+ p {
437
+ margin: 0.45em 0;
438
+ text-indent: 2em;
439
+ }
440
+
441
+ h1.chapter-title {
442
+ margin: 1.4em 0 1.6em;
443
+ font-size: 1.45em;
444
+ font-weight: 700;
445
+ line-height: 1.4;
446
+ text-align: center;
447
+ text-indent: 0;
448
+ break-after: avoid;
449
+ page-break-after: avoid;
450
+ }
451
+
452
+ .volume-title-page {
453
+ display: flex;
454
+ flex-direction: column;
455
+ align-items: center;
456
+ justify-content: center;
457
+ min-height: 88vh;
458
+ text-align: center;
459
+ padding: 2em 1em;
460
+ break-inside: avoid;
461
+ page-break-inside: avoid;
462
+ }
463
+
464
+ h1.volume-title {
465
+ margin: 1em 0;
466
+ font-size: 1.75em;
467
+ font-weight: 700;
468
+ line-height: 1.4;
469
+ text-align: center;
470
+ text-indent: 0;
471
+ }
472
+
473
+ .cover-page {
474
+ margin: 0;
475
+ padding: 0;
476
+ text-align: center;
477
+ break-inside: avoid;
478
+ page-break-inside: avoid;
479
+ }
480
+
481
+ img {
482
+ display: block;
483
+ margin: 1em auto;
484
+ max-width: 100%;
485
+ max-height: 100vh;
486
+ width: auto;
487
+ height: auto;
488
+ object-fit: contain;
489
+ break-inside: avoid;
490
+ page-break-inside: avoid;
491
+ }
492
+
493
+ .cover-page img {
494
+ margin: 0 auto;
495
+ }
496
+
497
+ ruby {
498
+ ruby-align: center;
499
+ ruby-position: over;
500
+ }
501
+
502
+ rt {
503
+ font-size: 0.55em;
504
+ line-height: 1.1;
505
+ text-align: center;
506
+ }
507
+
508
+ hr {
509
+ border: 0;
510
+ border-top: 1px solid #d0d7de;
511
+ margin: 1.5em auto;
512
+ width: 40%;
513
+ }
514
+
515
+ .image-placeholder {
516
+ margin: 1em auto;
517
+ padding: 0.75em 1em;
518
+ border: 1px dashed #9ca3af;
519
+ color: #6b7280;
520
+ background-color: #f9fafb;
521
+ font-size: 0.9em;
522
+ text-align: center;
523
+ text-indent: 0;
524
+ break-inside: avoid;
525
+ page-break-inside: avoid;
526
+ }
527
+ `;
528
+ // src/archive.ts
529
+ const DEFAULT_LANGUAGE = "zh-CN";
530
+ const EPUB_MIMETYPE = "application/epub+zip";
531
+ const CANONICAL_IMAGE_MEDIA_TYPES = {
532
+ "image/jpeg": "image/jpeg",
533
+ "image/jpg": "image/jpeg",
534
+ "image/png": "image/png",
535
+ "image/webp": "image/webp",
536
+ "image/gif": "image/gif",
537
+ "image/svg+xml": "image/svg+xml",
538
+ "image/avif": "image/avif"
539
+ };
540
+ const EXTENSION_TO_MEDIA_TYPE = {
541
+ jpg: "image/jpeg",
542
+ jpeg: "image/jpeg",
543
+ png: "image/png",
544
+ webp: "image/webp",
545
+ gif: "image/gif",
546
+ svg: "image/svg+xml",
547
+ avif: "image/avif"
548
+ };
549
+ function resolveImageMediaType(mimeType, ext) {
550
+ const base = mimeType.split(";")[0]?.trim().toLowerCase() ?? "";
551
+ const canonical = CANONICAL_IMAGE_MEDIA_TYPES[base];
552
+ if (canonical) return canonical;
553
+ return EXTENSION_TO_MEDIA_TYPE[ext.toLowerCase()] ?? "image/jpeg";
554
+ }
555
+ function resolveVolumeBookTitle(novelTitle, volumeTitle) {
556
+ const novel = novelTitle.trim();
557
+ const volume = volumeTitle.trim();
558
+ if (!novel) return volume || "Untitled";
559
+ if (!volume || novel === volume) return novel;
560
+ return `${novel} - ${volume}`;
561
+ }
562
+ function registerIllustrations(illustrations) {
563
+ const registry = /* @__PURE__ */ new Map();
564
+ const imageHrefBySourceUrl = /* @__PURE__ */ new Map();
565
+ const registeredImages = [];
566
+ let index = 0;
567
+ for (const asset of illustrations) {
568
+ if (registry.has(asset.sourceUrl)) continue;
569
+ index += 1;
570
+ const paddedIndex = String(index).padStart(4, "0");
571
+ const ext = resolveImageExtension(asset.mimeType, asset.sourceUrl);
572
+ const fileName = `img-${paddedIndex}.${ext}`;
573
+ const entry = {
574
+ manifestId: `img-${paddedIndex}`,
575
+ zipPath: `OEBPS/images/${fileName}`,
576
+ manifestHref: `images/${fileName}`,
577
+ relativeHref: `../images/${fileName}`,
578
+ mediaType: resolveImageMediaType(asset.mimeType, ext),
579
+ data: asset.data
580
+ };
581
+ registry.set(asset.sourceUrl, entry);
582
+ imageHrefBySourceUrl.set(asset.sourceUrl, entry.relativeHref);
583
+ registeredImages.push(entry);
584
+ }
585
+ return {
586
+ imageHrefBySourceUrl,
587
+ registeredImages
588
+ };
589
+ }
590
+ function packEpubArchive(options) {
591
+ const contentOpf = buildContentOpf({
592
+ identifier: options.identifier,
593
+ title: options.title,
594
+ author: options.author,
595
+ language: options.language,
596
+ summary: options.summary,
597
+ genres: options.genres,
598
+ modifiedAt: options.modifiedAt,
599
+ coverImageId: options.coverImageId,
600
+ manifest: options.manifest,
601
+ spine: options.spine
602
+ });
603
+ const navXhtml = buildNavXhtml({
604
+ title: options.title,
605
+ language: options.language,
606
+ entries: options.navEntries
607
+ });
608
+ const tocNcx = buildTocNcx({
609
+ identifier: options.identifier,
610
+ title: options.title,
611
+ author: options.author,
612
+ entries: options.navEntries
613
+ });
614
+ const zippable = {
615
+ mimetype: [strToU8(EPUB_MIMETYPE), { level: 0 }],
616
+ "META-INF/container.xml": strToU8(buildContainerXml()),
617
+ "OEBPS/styles/main.css": strToU8(DEFAULT_EPUB_CSS),
618
+ "OEBPS/content.opf": strToU8(contentOpf),
619
+ "OEBPS/nav.xhtml": strToU8(navXhtml),
620
+ "OEBPS/toc.ncx": strToU8(tocNcx)
621
+ };
622
+ for (const textEntry of options.textEntries) zippable[textEntry.zipPath] = strToU8(textEntry.content);
623
+ for (const binaryEntry of options.binaryEntries) zippable[binaryEntry.zipPath] = [binaryEntry.data, { level: 0 }];
624
+ return zipSync(zippable);
625
+ }
626
+ function createBaseManifest() {
627
+ return [
628
+ {
629
+ id: "ncx",
630
+ href: "toc.ncx",
631
+ mediaType: "application/x-dtbncx+xml"
632
+ },
633
+ {
634
+ id: "nav",
635
+ href: "nav.xhtml",
636
+ mediaType: "application/xhtml+xml",
637
+ properties: "nav"
638
+ },
639
+ {
640
+ id: "main-css",
641
+ href: "styles/main.css",
642
+ mediaType: "text/css"
643
+ }
644
+ ];
645
+ }
646
+ function appendCoverAssets(options) {
647
+ const coverExt = resolveImageExtension(options.cover.mimeType, options.cover.sourceUrl);
648
+ const coverFileName = `cover.${coverExt}`;
649
+ const coverRelativeHref = `../images/${coverFileName}`;
650
+ const coverImageId = "cover-image";
651
+ options.manifest.push({
652
+ id: coverImageId,
653
+ href: `images/${coverFileName}`,
654
+ mediaType: resolveImageMediaType(options.cover.mimeType, coverExt),
655
+ properties: "cover-image"
656
+ }, {
657
+ id: "cover",
658
+ href: "text/cover.xhtml",
659
+ mediaType: "application/xhtml+xml"
660
+ });
661
+ options.spine.push({ idref: "cover" });
662
+ options.binaryEntries.push({
663
+ zipPath: `OEBPS/images/${coverFileName}`,
664
+ data: options.cover.data
665
+ });
666
+ options.textEntries.push({
667
+ zipPath: "OEBPS/text/cover.xhtml",
668
+ content: buildCoverPageXhtml(options.bookTitle, coverRelativeHref, options.language)
669
+ });
670
+ return {
671
+ coverImageId,
672
+ coverRelativeHref
673
+ };
674
+ }
675
+ function appendChapterEntry(options) {
676
+ const paddedIndex = String(options.chapterIndex).padStart(4, "0");
677
+ const manifestId = `ch-${paddedIndex}`;
678
+ const manifestHref = `text/ch-${paddedIndex}.xhtml`;
679
+ const zipPath = `OEBPS/${manifestHref}`;
680
+ const xhtml = sanitizeChapterHtmlToXhtml({
681
+ chapter: options.chapter,
682
+ imageHrefBySourceUrl: options.imageHrefBySourceUrl,
683
+ language: options.language
684
+ });
685
+ options.manifest.push({
686
+ id: manifestId,
687
+ href: manifestHref,
688
+ mediaType: "application/xhtml+xml"
689
+ });
690
+ options.spine.push({ idref: manifestId });
691
+ options.textEntries.push({
692
+ zipPath,
693
+ content: xhtml
694
+ });
695
+ return {
696
+ title: options.chapter.title,
697
+ href: manifestHref
698
+ };
699
+ }
700
+ function buildVolumeEpub(input) {
701
+ const language = input.language?.trim() || DEFAULT_LANGUAGE;
702
+ const modifiedAt = input.modifiedAt ?? /* @__PURE__ */ new Date();
703
+ const bookTitle = resolveVolumeBookTitle(input.novelTitle, input.volumeTitle);
704
+ const manifest = createBaseManifest();
705
+ const spine = [];
706
+ const textEntries = [];
707
+ const binaryEntries = [];
708
+ const navEntries = [];
709
+ let coverImageId;
710
+ if (input.cover) coverImageId = appendCoverAssets({
711
+ cover: input.cover,
712
+ bookTitle,
713
+ language,
714
+ manifest,
715
+ spine,
716
+ textEntries,
717
+ binaryEntries
718
+ }).coverImageId;
719
+ const { imageHrefBySourceUrl, registeredImages } = registerIllustrations(input.illustrations);
720
+ let chapterCounter = 0;
721
+ for (const chapter of input.chapters) {
722
+ chapterCounter += 1;
723
+ const navEntry = appendChapterEntry({
724
+ chapter,
725
+ chapterIndex: chapterCounter,
726
+ language,
727
+ imageHrefBySourceUrl,
728
+ manifest,
729
+ spine,
730
+ textEntries
731
+ });
732
+ navEntries.push(navEntry);
733
+ }
734
+ for (const image of registeredImages) {
735
+ manifest.push({
736
+ id: image.manifestId,
737
+ href: image.manifestHref,
738
+ mediaType: image.mediaType
739
+ });
740
+ binaryEntries.push({
741
+ zipPath: image.zipPath,
742
+ data: image.data
743
+ });
744
+ }
745
+ return packEpubArchive({
746
+ identifier: input.identifier,
747
+ title: bookTitle,
748
+ author: input.author,
749
+ language,
750
+ summary: input.summary,
751
+ genres: input.genres,
752
+ modifiedAt,
753
+ coverImageId,
754
+ manifest,
755
+ spine,
756
+ navEntries,
757
+ textEntries,
758
+ binaryEntries
759
+ });
760
+ }
761
+ function buildNovelEpub(input) {
762
+ const language = input.language?.trim() || DEFAULT_LANGUAGE;
763
+ const modifiedAt = input.modifiedAt ?? /* @__PURE__ */ new Date();
764
+ const bookTitle = input.title.trim() || "Untitled";
765
+ const manifest = createBaseManifest();
766
+ const spine = [];
767
+ const textEntries = [];
768
+ const binaryEntries = [];
769
+ const navEntries = [];
770
+ const coverHrefBySourceUrl = /* @__PURE__ */ new Map();
771
+ let coverImageId;
772
+ if (input.cover) {
773
+ const coverResult = appendCoverAssets({
774
+ cover: input.cover,
775
+ bookTitle,
776
+ language,
777
+ manifest,
778
+ spine,
779
+ textEntries,
780
+ binaryEntries
781
+ });
782
+ coverImageId = coverResult.coverImageId;
783
+ if (input.cover.sourceUrl) coverHrefBySourceUrl.set(input.cover.sourceUrl, coverResult.coverRelativeHref);
784
+ }
785
+ const { imageHrefBySourceUrl, registeredImages } = registerIllustrations(input.illustrations);
786
+ let volumeCounter = 0;
787
+ let chapterCounter = 0;
788
+ for (const volume of input.volumes) {
789
+ volumeCounter += 1;
790
+ const volPadded = String(volumeCounter).padStart(3, "0");
791
+ let volumeCoverHref;
792
+ if (volume.cover) {
793
+ const existingCoverHref = volume.cover.sourceUrl ? coverHrefBySourceUrl.get(volume.cover.sourceUrl) : void 0;
794
+ if (existingCoverHref !== void 0) volumeCoverHref = existingCoverHref;
795
+ else {
796
+ const ext = resolveImageExtension(volume.cover.mimeType, volume.cover.sourceUrl);
797
+ const fileName = `vol-cover-${volPadded}.${ext}`;
798
+ const relHref = `../images/${fileName}`;
799
+ manifest.push({
800
+ id: `vol-cover-${volPadded}`,
801
+ href: `images/${fileName}`,
802
+ mediaType: resolveImageMediaType(volume.cover.mimeType, ext)
803
+ });
804
+ binaryEntries.push({
805
+ zipPath: `OEBPS/images/${fileName}`,
806
+ data: volume.cover.data
807
+ });
808
+ if (volume.cover.sourceUrl) coverHrefBySourceUrl.set(volume.cover.sourceUrl, relHref);
809
+ volumeCoverHref = relHref;
810
+ }
811
+ }
812
+ const volManifestId = `vol-${volPadded}`;
813
+ const volManifestHref = `text/vol-${volPadded}.xhtml`;
814
+ manifest.push({
815
+ id: volManifestId,
816
+ href: volManifestHref,
817
+ mediaType: "application/xhtml+xml"
818
+ });
819
+ spine.push({ idref: volManifestId });
820
+ textEntries.push({
821
+ zipPath: `OEBPS/${volManifestHref}`,
822
+ content: buildVolumeTitlePageXhtml({
823
+ title: volume.title,
824
+ language,
825
+ coverHref: volumeCoverHref
826
+ })
827
+ });
828
+ const volumeNavChildren = [];
829
+ for (const chapter of volume.chapters) {
830
+ chapterCounter += 1;
831
+ const chapterNavEntry = appendChapterEntry({
832
+ chapter,
833
+ chapterIndex: chapterCounter,
834
+ language,
835
+ imageHrefBySourceUrl,
836
+ manifest,
837
+ spine,
838
+ textEntries
839
+ });
840
+ volumeNavChildren.push(chapterNavEntry);
841
+ }
842
+ navEntries.push({
843
+ title: volume.title,
844
+ href: volManifestHref,
845
+ children: volumeNavChildren
846
+ });
847
+ }
848
+ for (const image of registeredImages) {
849
+ manifest.push({
850
+ id: image.manifestId,
851
+ href: image.manifestHref,
852
+ mediaType: image.mediaType
853
+ });
854
+ binaryEntries.push({
855
+ zipPath: image.zipPath,
856
+ data: image.data
857
+ });
858
+ }
859
+ return packEpubArchive({
860
+ identifier: input.identifier,
861
+ title: bookTitle,
862
+ author: input.author,
863
+ language,
864
+ summary: input.summary,
865
+ genres: input.genres,
866
+ modifiedAt,
867
+ coverImageId,
868
+ manifest,
869
+ spine,
870
+ navEntries,
871
+ textEntries,
872
+ binaryEntries
873
+ });
874
+ }
875
+ export { buildNovelEpub, buildVolumeEpub };
876
+
877
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["DEFAULT_LANGUAGE"],"sources":["../src/xhtml.ts","../src/nav.ts","../src/ncx.ts","../src/opf.ts","../src/styles.ts","../src/archive.ts"],"sourcesContent":["import render from \"dom-serializer\";\nimport {\n\ttype ChildNode,\n\tElement,\n\tisComment,\n\tisDirective,\n\tisTag,\n\tisText,\n\tText,\n} from \"domhandler\";\nimport { parseDocument } from \"htmlparser2\";\nimport type { EpubChapterData } from \"./types\";\n\nconst DEFAULT_LANGUAGE = \"zh-CN\";\n\nconst MIME_TO_EXTENSION: Readonly<Record<string, string>> = {\n\t\"image/jpeg\": \"jpg\",\n\t\"image/jpg\": \"jpg\",\n\t\"image/png\": \"png\",\n\t\"image/webp\": \"webp\",\n\t\"image/gif\": \"gif\",\n\t\"image/svg+xml\": \"svg\",\n\t\"image/avif\": \"avif\",\n};\n\nconst KNOWN_IMAGE_EXTENSIONS: Readonly<Record<string, string>> = {\n\tjpg: \"jpg\",\n\tjpeg: \"jpg\",\n\tpng: \"png\",\n\twebp: \"webp\",\n\tgif: \"gif\",\n\tsvg: \"svg\",\n\tavif: \"avif\",\n};\n\nconst REMOVED_TAG_NAMES = new Set([\n\t\"script\",\n\t\"iframe\",\n\t\"style\",\n\t\"noscript\",\n\t\"object\",\n\t\"embed\",\n]);\n\nconst HEADING_TAG_NAMES = new Set([\"h1\", \"h2\", \"h3\"]);\n\nconst URI_ATTRIBUTE_NAMES = new Set([\n\t\"href\",\n\t\"src\",\n\t\"xlink:href\",\n\t\"action\",\n\t\"formaction\",\n\t\"poster\",\n\t\"data\",\n\t\"cite\",\n\t\"background\",\n\t\"srcset\",\n]);\n\nconst VALID_XML_NCNAME = /^[A-Za-z_][A-Za-z0-9._-]*$/;\n\nconst ALLOWED_ATTR_NAMESPACE_PREFIXES = new Set([\"xml\", \"epub\"]);\n\nfunction isAllowedXmlAttributeName(name: string): boolean {\n\tconst colonIndex = name.indexOf(\":\");\n\tif (colonIndex === -1) {\n\t\treturn VALID_XML_NCNAME.test(name);\n\t}\n\tif (name.indexOf(\":\", colonIndex + 1) !== -1) {\n\t\treturn false;\n\t}\n\tconst prefix = name.slice(0, colonIndex);\n\tconst localName = name.slice(colonIndex + 1);\n\tif (!VALID_XML_NCNAME.test(prefix) || !VALID_XML_NCNAME.test(localName)) {\n\t\treturn false;\n\t}\n\tif (name === \"xmlns:epub\") {\n\t\treturn true;\n\t}\n\treturn ALLOWED_ATTR_NAMESPACE_PREFIXES.has(prefix);\n}\n\nconst XML_ESCAPE_MAP: Readonly<Record<string, string>> = {\n\t\"&\": \"&amp;\",\n\t\"<\": \"&lt;\",\n\t\">\": \"&gt;\",\n\t'\"': \"&quot;\",\n\t\"'\": \"&apos;\",\n};\n\nexport function escapeXml(text: string): string {\n\treturn stripInvalidXmlControlChars(text).replace(\n\t\t/[&<>\"']/g,\n\t\t(char) => XML_ESCAPE_MAP[char] ?? char,\n\t);\n}\n\nfunction extractExtensionFromUrl(sourceUrl?: string): string | undefined {\n\tif (!sourceUrl) {\n\t\treturn undefined;\n\t}\n\tconst trimmed = sourceUrl.trim();\n\tif (!trimmed) {\n\t\treturn undefined;\n\t}\n\n\tlet pathname = trimmed;\n\ttry {\n\t\tpathname = new URL(trimmed, \"https://example.invalid\").pathname;\n\t} catch {\n\t\tconst withoutHash = trimmed.split(\"#\")[0] ?? trimmed;\n\t\tpathname = withoutHash.split(\"?\")[0] ?? withoutHash;\n\t}\n\n\tconst lastSegment = pathname.split(\"/\").pop() ?? \"\";\n\tconst match = /\\.([a-z0-9]+)$/i.exec(lastSegment);\n\tif (!match?.[1]) {\n\t\treturn undefined;\n\t}\n\treturn KNOWN_IMAGE_EXTENSIONS[match[1].toLowerCase()];\n}\n\nexport function resolveImageExtension(\n\tmimeType: string,\n\tsourceUrl?: string,\n): string {\n\tconst normalizedMime = mimeType.split(\";\")[0]?.trim().toLowerCase() ?? \"\";\n\tconst mapped = MIME_TO_EXTENSION[normalizedMime];\n\tif (mapped) {\n\t\treturn mapped;\n\t}\n\treturn extractExtensionFromUrl(sourceUrl) ?? \"jpg\";\n}\n\nfunction stripWhitespaceAndControl(value: string): string {\n\tconst withoutWhitespace = value.replace(/\\s+/g, \"\");\n\tlet result = \"\";\n\tfor (let i = 0; i < withoutWhitespace.length; i += 1) {\n\t\tconst code = withoutWhitespace.charCodeAt(i);\n\t\tif (code <= 0x20 || code === 0x7f) {\n\t\t\tcontinue;\n\t\t}\n\t\tresult += withoutWhitespace[i] ?? \"\";\n\t}\n\treturn result;\n}\n\nfunction isUnsafeUri(value: string): boolean {\n\t// Strip Unicode whitespace and ASCII control characters before checking URI scheme\n\tconst normalized = stripWhitespaceAndControl(value).toLowerCase();\n\treturn (\n\t\tnormalized.startsWith(\"javascript:\") ||\n\t\tnormalized.startsWith(\"vbscript:\") ||\n\t\tnormalized.startsWith(\"data:text/html\")\n\t);\n}\n\nfunction sanitizeElementAttributes(element: Element): void {\n\tconst cleaned: Record<string, string> = {};\n\tfor (const [rawKey, rawValue] of Object.entries(element.attribs)) {\n\t\tconst key = rawKey.trim();\n\t\tif (!key || !isAllowedXmlAttributeName(key)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst lowerKey = key.toLowerCase();\n\t\tif (lowerKey.startsWith(\"on\") || lowerKey === \"srcdoc\") {\n\t\t\tcontinue;\n\t\t}\n\t\tif (URI_ATTRIBUTE_NAMES.has(lowerKey) && isUnsafeUri(rawValue)) {\n\t\t\tcontinue;\n\t\t}\n\t\tcleaned[key] = rawValue;\n\t}\n\telement.attribs = cleaned;\n}\n\nfunction sanitizeNodeList(\n\tnodes: ChildNode[],\n\timageHrefBySourceUrl: ReadonlyMap<string, string>,\n): ChildNode[] {\n\tconst result: ChildNode[] = [];\n\n\tfor (const node of nodes) {\n\t\tif (isComment(node) || isDirective(node)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!isTag(node)) {\n\t\t\tresult.push(node);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst tagName = node.name.toLowerCase();\n\t\tif (REMOVED_TAG_NAMES.has(tagName)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (tagName.includes(\":\")) {\n\t\t\tconst unwrappedChildren = sanitizeNodeList(\n\t\t\t\tnode.children,\n\t\t\t\timageHrefBySourceUrl,\n\t\t\t);\n\t\t\tfor (const child of unwrappedChildren) {\n\t\t\t\tchild.parent = node.parent;\n\t\t\t\tresult.push(child);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tnode.name = tagName;\n\n\t\tif (tagName === \"img\") {\n\t\t\tconst rawSrc = node.attribs.src;\n\t\t\tconst mappedHref =\n\t\t\t\trawSrc !== undefined\n\t\t\t\t\t? (imageHrefBySourceUrl.get(rawSrc) ??\n\t\t\t\t\t\timageHrefBySourceUrl.get(rawSrc.trim()))\n\t\t\t\t\t: undefined;\n\n\t\t\tif (mappedHref !== undefined) {\n\t\t\t\tconst alt = node.attribs.alt?.trim() || \"插图\";\n\t\t\t\tnode.attribs = {\n\t\t\t\t\tsrc: mappedHref,\n\t\t\t\t\talt,\n\t\t\t\t};\n\t\t\t\tnode.children = [];\n\t\t\t\tresult.push(node);\n\t\t\t} else {\n\t\t\t\tconst placeholder = new Element(\"p\", { class: \"image-placeholder\" }, [\n\t\t\t\t\tnew Text(\"[插图未包含]\"),\n\t\t\t\t]);\n\t\t\t\tplaceholder.parent = node.parent;\n\t\t\t\tresult.push(placeholder);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tsanitizeElementAttributes(node);\n\t\tnode.children = sanitizeNodeList(node.children, imageHrefBySourceUrl);\n\t\tresult.push(node);\n\t}\n\n\treturn result;\n}\n\nfunction collectTextContent(node: ChildNode): string {\n\tif (isText(node)) {\n\t\treturn node.data;\n\t}\n\tif (isTag(node)) {\n\t\tlet text = \"\";\n\t\tfor (const child of node.children) {\n\t\t\ttext += collectTextContent(child);\n\t\t}\n\t\treturn text;\n\t}\n\treturn \"\";\n}\n\nfunction normalizeLeadingHeading(\n\tnodes: ChildNode[],\n\tchapterTitle: string,\n): ChildNode[] {\n\tconst firstSignificant = nodes.find((node) => {\n\t\tif (isComment(node)) {\n\t\t\treturn false;\n\t\t}\n\t\tif (isText(node)) {\n\t\t\treturn node.data.trim().length > 0;\n\t\t}\n\t\treturn true;\n\t});\n\n\tif (\n\t\tfirstSignificant &&\n\t\tisTag(firstSignificant) &&\n\t\tHEADING_TAG_NAMES.has(firstSignificant.name.toLowerCase())\n\t) {\n\t\tfirstSignificant.name = \"h1\";\n\t\tfirstSignificant.attribs = {\n\t\t\t...firstSignificant.attribs,\n\t\t\tclass: \"chapter-title\",\n\t\t};\n\t\tif (collectTextContent(firstSignificant).trim().length === 0) {\n\t\t\tfirstSignificant.children = [new Text(chapterTitle)];\n\t\t}\n\t\treturn nodes;\n\t}\n\n\tconst heading = new Element(\"h1\", { class: \"chapter-title\" }, [\n\t\tnew Text(chapterTitle),\n\t]);\n\treturn [heading, ...nodes];\n}\n\nfunction wrapXhtmlDocument(options: {\n\ttitle: string;\n\tlanguage?: string | undefined;\n\tbodyHtml: string;\n\tbodyAttributes?: string | undefined;\n}): string {\n\tconst lang = options.language?.trim() || DEFAULT_LANGUAGE;\n\tconst escapedLang = escapeXml(lang);\n\tconst escapedTitle = escapeXml(options.title);\n\tconst bodyAttrs = options.bodyAttributes ? ` ${options.bodyAttributes}` : \"\";\n\n\treturn [\n\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>',\n\t\t\"<!DOCTYPE html>\",\n\t\t`<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" xml:lang=\"${escapedLang}\" lang=\"${escapedLang}\">`,\n\t\t\"<head>\",\n\t\t'\\t<meta charset=\"UTF-8\" />',\n\t\t`\\t<title>${escapedTitle}</title>`,\n\t\t'\\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../styles/main.css\" />',\n\t\t\"</head>\",\n\t\t`<body${bodyAttrs}>`,\n\t\toptions.bodyHtml,\n\t\t\"</body>\",\n\t\t\"</html>\",\n\t\t\"\",\n\t].join(\"\\n\");\n}\n\nexport function buildCoverPageXhtml(\n\ttitle: string,\n\timageHref: string,\n\tlanguage?: string,\n): string {\n\tconst escapedTitle = escapeXml(title);\n\tconst escapedHref = escapeXml(imageHref);\n\tconst bodyHtml = `\\t<div class=\"cover-page\"><img src=\"${escapedHref}\" alt=\"${escapedTitle}\" /></div>`;\n\treturn wrapXhtmlDocument({\n\t\ttitle,\n\t\tlanguage,\n\t\tbodyHtml,\n\t\tbodyAttributes: 'epub:type=\"cover\"',\n\t});\n}\n\nexport function buildVolumeTitlePageXhtml(options: {\n\ttitle: string;\n\tlanguage?: string | undefined;\n\tcoverHref?: string | undefined;\n}): string {\n\tconst escapedTitle = escapeXml(options.title);\n\tconst parts: string[] = ['\\t<div class=\"volume-title-page\">'];\n\tif (options.coverHref) {\n\t\tparts.push(\n\t\t\t`\\t\\t<img src=\"${escapeXml(options.coverHref)}\" alt=\"${escapedTitle}\" />`,\n\t\t);\n\t}\n\tparts.push(`\\t\\t<h1 class=\"volume-title\">${escapedTitle}</h1>`);\n\tparts.push(\"\\t</div>\");\n\n\treturn wrapXhtmlDocument({\n\t\ttitle: options.title,\n\t\tlanguage: options.language,\n\t\tbodyHtml: parts.join(\"\\n\"),\n\t});\n}\n\nfunction stripInvalidXmlControlChars(text: string): string {\n\tlet hasInvalid = false;\n\tfor (let i = 0; i < text.length; i += 1) {\n\t\tconst code = text.charCodeAt(i);\n\t\tif (\n\t\t\tcode <= 0x08 ||\n\t\t\tcode === 0x0b ||\n\t\t\tcode === 0x0c ||\n\t\t\t(code >= 0x0e && code <= 0x1f)\n\t\t) {\n\t\t\thasInvalid = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (!hasInvalid) {\n\t\treturn text;\n\t}\n\tlet result = \"\";\n\tfor (let i = 0; i < text.length; i += 1) {\n\t\tconst code = text.charCodeAt(i);\n\t\tif (\n\t\t\tcode <= 0x08 ||\n\t\t\tcode === 0x0b ||\n\t\t\tcode === 0x0c ||\n\t\t\t(code >= 0x0e && code <= 0x1f)\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tresult += text[i] ?? \"\";\n\t}\n\treturn result;\n}\n\nfunction escapeXmlFragmentChars(text: string): string {\n\treturn stripInvalidXmlControlChars(text).replace(\n\t\t/[&<>]/g,\n\t\t(char) => XML_ESCAPE_MAP[char] ?? char,\n\t);\n}\n\nfunction escapeNodesForXmlSerialization(nodes: ChildNode[]): void {\n\tfor (const node of nodes) {\n\t\tif (isText(node)) {\n\t\t\tnode.data = escapeXmlFragmentChars(node.data);\n\t\t\tcontinue;\n\t\t}\n\t\tif (isTag(node)) {\n\t\t\tconst escapedAttribs: Record<string, string> = {};\n\t\t\tfor (const [key, value] of Object.entries(node.attribs)) {\n\t\t\t\tescapedAttribs[key] = escapeXmlFragmentChars(value);\n\t\t\t}\n\t\t\tnode.attribs = escapedAttribs;\n\t\t\tescapeNodesForXmlSerialization(node.children);\n\t\t}\n\t}\n}\n\nexport function sanitizeChapterHtmlToXhtml(options: {\n\tchapter: EpubChapterData;\n\timageHrefBySourceUrl: ReadonlyMap<string, string>;\n\tlanguage?: string | undefined;\n}): string {\n\tconst document = parseDocument(options.chapter.html, {\n\t\tdecodeEntities: true,\n\t});\n\tconst sanitizedChildren = sanitizeNodeList(\n\t\tdocument.children,\n\t\toptions.imageHrefBySourceUrl,\n\t);\n\tconst normalizedChildren = normalizeLeadingHeading(\n\t\tsanitizedChildren,\n\t\toptions.chapter.title,\n\t);\n\tescapeNodesForXmlSerialization(normalizedChildren);\n\tconst bodyHtml = render(normalizedChildren, {\n\t\txmlMode: true,\n\t\tencodeEntities: false,\n\t});\n\n\treturn wrapXhtmlDocument({\n\t\ttitle: options.chapter.title,\n\t\tlanguage: options.language,\n\t\tbodyHtml,\n\t});\n}\n","import { escapeXml } from \"./xhtml\";\n\nexport interface NavEntry {\n\ttitle: string;\n\thref: string;\n\tchildren?: NavEntry[] | undefined;\n}\n\nfunction renderNavList(\n\tentries: readonly NavEntry[],\n\tindentLevel: number,\n): string {\n\tconst indent = \"\\t\".repeat(indentLevel);\n\tconst itemIndent = \"\\t\".repeat(indentLevel + 1);\n\tif (entries.length === 0) {\n\t\treturn `${indent}<ol></ol>`;\n\t}\n\n\tconst lines: string[] = [`${indent}<ol>`];\n\tfor (const entry of entries) {\n\t\tconst href = escapeXml(entry.href);\n\t\tconst title = escapeXml(entry.title);\n\t\tconst children = entry.children;\n\t\tif (children && children.length > 0) {\n\t\t\tlines.push(`${itemIndent}<li>`);\n\t\t\tlines.push(`${itemIndent}\\t<a href=\"${href}\">${title}</a>`);\n\t\t\tlines.push(renderNavList(children, indentLevel + 2));\n\t\t\tlines.push(`${itemIndent}</li>`);\n\t\t} else {\n\t\t\tlines.push(`${itemIndent}<li><a href=\"${href}\">${title}</a></li>`);\n\t\t}\n\t}\n\tlines.push(`${indent}</ol>`);\n\treturn lines.join(\"\\n\");\n}\n\nexport function buildNavXhtml(options: {\n\ttitle: string;\n\tlanguage: string;\n\tentries: NavEntry[];\n}): string {\n\tconst lang = options.language.trim() || \"zh-CN\";\n\tconst escapedLang = escapeXml(lang);\n\tconst escapedTitle = escapeXml(options.title);\n\n\treturn [\n\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>',\n\t\t\"<!DOCTYPE html>\",\n\t\t`<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" xml:lang=\"${escapedLang}\" lang=\"${escapedLang}\">`,\n\t\t\"<head>\",\n\t\t'\\t<meta charset=\"UTF-8\" />',\n\t\t`\\t<title>${escapedTitle}</title>`,\n\t\t'\\t<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/main.css\" />',\n\t\t\"</head>\",\n\t\t\"<body>\",\n\t\t'\\t<nav epub:type=\"toc\" id=\"toc\">',\n\t\t`\\t\\t<h1>${escapedTitle}</h1>`,\n\t\trenderNavList(options.entries, 2),\n\t\t\"\\t</nav>\",\n\t\t\"</body>\",\n\t\t\"</html>\",\n\t\t\"\",\n\t].join(\"\\n\");\n}\n","import type { NavEntry } from \"./nav\";\nimport { escapeXml } from \"./xhtml\";\n\nfunction computeDepth(entries: readonly NavEntry[]): number {\n\tif (entries.length === 0) {\n\t\treturn 1;\n\t}\n\tlet maxDepth = 1;\n\tfor (const entry of entries) {\n\t\tif (entry.children && entry.children.length > 0) {\n\t\t\tconst childDepth = 1 + computeDepth(entry.children);\n\t\t\tif (childDepth > maxDepth) {\n\t\t\t\tmaxDepth = childDepth;\n\t\t\t}\n\t\t}\n\t}\n\treturn maxDepth;\n}\n\nfunction renderNavPoints(\n\tentries: readonly NavEntry[],\n\tindentLevel: number,\n\tcounter: { value: number },\n): string[] {\n\tconst indent = \"\\t\".repeat(indentLevel);\n\tconst lines: string[] = [];\n\n\tfor (const entry of entries) {\n\t\tcounter.value += 1;\n\t\tconst order = counter.value;\n\t\tlines.push(\n\t\t\t`${indent}<navPoint id=\"navPoint-${order}\" playOrder=\"${order}\">`,\n\t\t);\n\t\tlines.push(`${indent}\\t<navLabel>`);\n\t\tlines.push(`${indent}\\t\\t<text>${escapeXml(entry.title)}</text>`);\n\t\tlines.push(`${indent}\\t</navLabel>`);\n\t\tlines.push(`${indent}\\t<content src=\"${escapeXml(entry.href)}\" />`);\n\t\tif (entry.children && entry.children.length > 0) {\n\t\t\tlines.push(...renderNavPoints(entry.children, indentLevel + 1, counter));\n\t\t}\n\t\tlines.push(`${indent}</navPoint>`);\n\t}\n\n\treturn lines;\n}\n\nexport function buildTocNcx(options: {\n\tidentifier: string;\n\ttitle: string;\n\tauthor: string;\n\tentries: NavEntry[];\n}): string {\n\tconst depth = computeDepth(options.entries);\n\tconst counter = { value: 0 };\n\tconst navPointLines = renderNavPoints(options.entries, 2, counter);\n\n\treturn [\n\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>',\n\t\t'<ncx xmlns=\"http://www.daisy.org/z3986/2005/ncx/\" version=\"2005-1\">',\n\t\t\"\\t<head>\",\n\t\t`\\t\\t<meta name=\"dtb:uid\" content=\"${escapeXml(options.identifier)}\" />`,\n\t\t`\\t\\t<meta name=\"dtb:depth\" content=\"${depth}\" />`,\n\t\t'\\t\\t<meta name=\"dtb:totalPageCount\" content=\"0\" />',\n\t\t'\\t\\t<meta name=\"dtb:maxPageNumber\" content=\"0\" />',\n\t\t\"\\t</head>\",\n\t\t\"\\t<docTitle>\",\n\t\t`\\t\\t<text>${escapeXml(options.title)}</text>`,\n\t\t\"\\t</docTitle>\",\n\t\t\"\\t<docAuthor>\",\n\t\t`\\t\\t<text>${escapeXml(options.author)}</text>`,\n\t\t\"\\t</docAuthor>\",\n\t\t\"\\t<navMap>\",\n\t\t...navPointLines,\n\t\t\"\\t</navMap>\",\n\t\t\"</ncx>\",\n\t\t\"\",\n\t].join(\"\\n\");\n}\n","import { escapeXml } from \"./xhtml\";\n\nexport interface OpfManifestItem {\n\tid: string;\n\thref: string;\n\tmediaType: string;\n\tproperties?: string | undefined;\n}\n\nexport interface OpfSpineItem {\n\tidref: string;\n\tlinear?: boolean | undefined;\n}\n\nexport function buildContainerXml(): string {\n\treturn [\n\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>',\n\t\t'<container version=\"1.0\" xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\">',\n\t\t\"\\t<rootfiles>\",\n\t\t'\\t\\t<rootfile full-path=\"OEBPS/content.opf\" media-type=\"application/oebps-package+xml\" />',\n\t\t\"\\t</rootfiles>\",\n\t\t\"</container>\",\n\t\t\"\",\n\t].join(\"\\n\");\n}\n\nexport function buildContentOpf(options: {\n\tidentifier: string;\n\ttitle: string;\n\tauthor: string;\n\tlanguage: string;\n\tsummary?: string | undefined;\n\tgenres?: string[] | undefined;\n\tmodifiedAt: Date;\n\tcoverImageId?: string | undefined;\n\tmanifest: OpfManifestItem[];\n\tspine: OpfSpineItem[];\n}): string {\n\tconst modifiedTimestamp = `${options.modifiedAt.toISOString().slice(0, 19)}Z`;\n\tconst lines: string[] = [\n\t\t'<?xml version=\"1.0\" encoding=\"UTF-8\"?>',\n\t\t'<package xmlns=\"http://www.idpf.org/2007/opf\" version=\"3.0\" unique-identifier=\"bookid\">',\n\t\t'\\t<metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\">',\n\t\t`\\t\\t<dc:identifier id=\"bookid\">${escapeXml(options.identifier)}</dc:identifier>`,\n\t\t`\\t\\t<dc:title>${escapeXml(options.title)}</dc:title>`,\n\t\t`\\t\\t<dc:creator>${escapeXml(options.author)}</dc:creator>`,\n\t\t`\\t\\t<dc:language>${escapeXml(options.language)}</dc:language>`,\n\t];\n\n\tconst summary = options.summary?.trim();\n\tif (summary) {\n\t\tlines.push(`\\t\\t<dc:description>${escapeXml(summary)}</dc:description>`);\n\t}\n\n\tfor (const genre of options.genres ?? []) {\n\t\tconst trimmed = genre.trim();\n\t\tif (trimmed) {\n\t\t\tlines.push(`\\t\\t<dc:subject>${escapeXml(trimmed)}</dc:subject>`);\n\t\t}\n\t}\n\n\tlines.push(\n\t\t`\\t\\t<meta property=\"dcterms:modified\">${modifiedTimestamp}</meta>`,\n\t);\n\n\tconst coverImageId = options.coverImageId?.trim();\n\tif (coverImageId) {\n\t\tlines.push(\n\t\t\t`\\t\\t<meta name=\"cover\" content=\"${escapeXml(coverImageId)}\" />`,\n\t\t);\n\t}\n\n\tlines.push(\"\\t</metadata>\");\n\tlines.push(\"\\t<manifest>\");\n\n\tfor (const item of options.manifest) {\n\t\tconst propertiesAttr = item.properties\n\t\t\t? ` properties=\"${escapeXml(item.properties)}\"`\n\t\t\t: \"\";\n\t\tlines.push(\n\t\t\t`\\t\\t<item id=\"${escapeXml(item.id)}\" href=\"${escapeXml(item.href)}\" media-type=\"${escapeXml(item.mediaType)}\"${propertiesAttr} />`,\n\t\t);\n\t}\n\n\tlines.push(\"\\t</manifest>\");\n\tlines.push('\\t<spine toc=\"ncx\">');\n\n\tfor (const spineItem of options.spine) {\n\t\tconst linearAttr = spineItem.linear === false ? ' linear=\"no\"' : \"\";\n\t\tlines.push(\n\t\t\t`\\t\\t<itemref idref=\"${escapeXml(spineItem.idref)}\"${linearAttr} />`,\n\t\t);\n\t}\n\n\tlines.push(\"\\t</spine>\");\n\tlines.push(\"</package>\");\n\tlines.push(\"\");\n\n\treturn lines.join(\"\\n\");\n}\n","export const DEFAULT_EPUB_CSS = `html,\nbody {\n\tmargin: 0;\n\tpadding: 0;\n\tfont-family: \"Noto Serif CJK SC\", \"Source Han Serif SC\", \"Songti SC\", \"SimSun\", Georgia, serif;\n\tfont-size: 1em;\n\tline-height: 1.85;\n\tcolor: #1f2328;\n\ttext-align: justify;\n\tword-break: break-word;\n}\n\nbody {\n\tpadding: 0.5em 0.8em;\n}\n\np {\n\tmargin: 0.45em 0;\n\ttext-indent: 2em;\n}\n\nh1.chapter-title {\n\tmargin: 1.4em 0 1.6em;\n\tfont-size: 1.45em;\n\tfont-weight: 700;\n\tline-height: 1.4;\n\ttext-align: center;\n\ttext-indent: 0;\n\tbreak-after: avoid;\n\tpage-break-after: avoid;\n}\n\n.volume-title-page {\n\tdisplay: flex;\n\tflex-direction: column;\n\talign-items: center;\n\tjustify-content: center;\n\tmin-height: 88vh;\n\ttext-align: center;\n\tpadding: 2em 1em;\n\tbreak-inside: avoid;\n\tpage-break-inside: avoid;\n}\n\nh1.volume-title {\n\tmargin: 1em 0;\n\tfont-size: 1.75em;\n\tfont-weight: 700;\n\tline-height: 1.4;\n\ttext-align: center;\n\ttext-indent: 0;\n}\n\n.cover-page {\n\tmargin: 0;\n\tpadding: 0;\n\ttext-align: center;\n\tbreak-inside: avoid;\n\tpage-break-inside: avoid;\n}\n\nimg {\n\tdisplay: block;\n\tmargin: 1em auto;\n\tmax-width: 100%;\n\tmax-height: 100vh;\n\twidth: auto;\n\theight: auto;\n\tobject-fit: contain;\n\tbreak-inside: avoid;\n\tpage-break-inside: avoid;\n}\n\n.cover-page img {\n\tmargin: 0 auto;\n}\n\nruby {\n\truby-align: center;\n\truby-position: over;\n}\n\nrt {\n\tfont-size: 0.55em;\n\tline-height: 1.1;\n\ttext-align: center;\n}\n\nhr {\n\tborder: 0;\n\tborder-top: 1px solid #d0d7de;\n\tmargin: 1.5em auto;\n\twidth: 40%;\n}\n\n.image-placeholder {\n\tmargin: 1em auto;\n\tpadding: 0.75em 1em;\n\tborder: 1px dashed #9ca3af;\n\tcolor: #6b7280;\n\tbackground-color: #f9fafb;\n\tfont-size: 0.9em;\n\ttext-align: center;\n\ttext-indent: 0;\n\tbreak-inside: avoid;\n\tpage-break-inside: avoid;\n}\n`;\n","import { strToU8, type Zippable, zipSync } from \"fflate\";\nimport { buildNavXhtml, type NavEntry } from \"./nav\";\nimport { buildTocNcx } from \"./ncx\";\nimport {\n\tbuildContainerXml,\n\tbuildContentOpf,\n\ttype OpfManifestItem,\n\ttype OpfSpineItem,\n} from \"./opf\";\nimport { DEFAULT_EPUB_CSS } from \"./styles\";\nimport type {\n\tEpubChapterData,\n\tEpubImageAsset,\n\tNovelEpubInput,\n\tVolumeEpubInput,\n} from \"./types\";\nimport {\n\tbuildCoverPageXhtml,\n\tbuildVolumeTitlePageXhtml,\n\tresolveImageExtension,\n\tsanitizeChapterHtmlToXhtml,\n} from \"./xhtml\";\n\nconst DEFAULT_LANGUAGE = \"zh-CN\";\nconst EPUB_MIMETYPE = \"application/epub+zip\";\n\ninterface RegisteredIllustration {\n\tmanifestId: string;\n\tzipPath: string;\n\tmanifestHref: string;\n\trelativeHref: string;\n\tmediaType: string;\n\tdata: Uint8Array;\n}\n\ninterface ArchiveTextEntry {\n\tzipPath: string;\n\tcontent: string;\n}\n\ninterface ArchiveBinaryEntry {\n\tzipPath: string;\n\tdata: Uint8Array;\n}\n\nconst CANONICAL_IMAGE_MEDIA_TYPES: Readonly<Record<string, string>> = {\n\t\"image/jpeg\": \"image/jpeg\",\n\t\"image/jpg\": \"image/jpeg\",\n\t\"image/png\": \"image/png\",\n\t\"image/webp\": \"image/webp\",\n\t\"image/gif\": \"image/gif\",\n\t\"image/svg+xml\": \"image/svg+xml\",\n\t\"image/avif\": \"image/avif\",\n};\n\nconst EXTENSION_TO_MEDIA_TYPE: Readonly<Record<string, string>> = {\n\tjpg: \"image/jpeg\",\n\tjpeg: \"image/jpeg\",\n\tpng: \"image/png\",\n\twebp: \"image/webp\",\n\tgif: \"image/gif\",\n\tsvg: \"image/svg+xml\",\n\tavif: \"image/avif\",\n};\n\nfunction resolveImageMediaType(mimeType: string, ext: string): string {\n\tconst base = mimeType.split(\";\")[0]?.trim().toLowerCase() ?? \"\";\n\tconst canonical = CANONICAL_IMAGE_MEDIA_TYPES[base];\n\tif (canonical) {\n\t\treturn canonical;\n\t}\n\treturn EXTENSION_TO_MEDIA_TYPE[ext.toLowerCase()] ?? \"image/jpeg\";\n}\n\nfunction resolveVolumeBookTitle(\n\tnovelTitle: string,\n\tvolumeTitle: string,\n): string {\n\tconst novel = novelTitle.trim();\n\tconst volume = volumeTitle.trim();\n\tif (!novel) {\n\t\treturn volume || \"Untitled\";\n\t}\n\tif (!volume || novel === volume) {\n\t\treturn novel;\n\t}\n\treturn `${novel} - ${volume}`;\n}\n\nfunction registerIllustrations(illustrations: readonly EpubImageAsset[]): {\n\timageHrefBySourceUrl: Map<string, string>;\n\tregisteredImages: RegisteredIllustration[];\n} {\n\tconst registry = new Map<string, RegisteredIllustration>();\n\tconst imageHrefBySourceUrl = new Map<string, string>();\n\tconst registeredImages: RegisteredIllustration[] = [];\n\tlet index = 0;\n\n\tfor (const asset of illustrations) {\n\t\tif (registry.has(asset.sourceUrl)) {\n\t\t\tcontinue;\n\t\t}\n\t\tindex += 1;\n\t\tconst paddedIndex = String(index).padStart(4, \"0\");\n\t\tconst ext = resolveImageExtension(asset.mimeType, asset.sourceUrl);\n\t\tconst fileName = `img-${paddedIndex}.${ext}`;\n\t\tconst entry: RegisteredIllustration = {\n\t\t\tmanifestId: `img-${paddedIndex}`,\n\t\t\tzipPath: `OEBPS/images/${fileName}`,\n\t\t\tmanifestHref: `images/${fileName}`,\n\t\t\trelativeHref: `../images/${fileName}`,\n\t\t\tmediaType: resolveImageMediaType(asset.mimeType, ext),\n\t\t\tdata: asset.data,\n\t\t};\n\t\tregistry.set(asset.sourceUrl, entry);\n\t\timageHrefBySourceUrl.set(asset.sourceUrl, entry.relativeHref);\n\t\tregisteredImages.push(entry);\n\t}\n\n\treturn { imageHrefBySourceUrl, registeredImages };\n}\n\nfunction packEpubArchive(options: {\n\tidentifier: string;\n\ttitle: string;\n\tauthor: string;\n\tlanguage: string;\n\tsummary?: string | undefined;\n\tgenres?: string[] | undefined;\n\tmodifiedAt: Date;\n\tcoverImageId?: string | undefined;\n\tmanifest: OpfManifestItem[];\n\tspine: OpfSpineItem[];\n\tnavEntries: NavEntry[];\n\ttextEntries: readonly ArchiveTextEntry[];\n\tbinaryEntries: readonly ArchiveBinaryEntry[];\n}): Uint8Array {\n\tconst contentOpf = buildContentOpf({\n\t\tidentifier: options.identifier,\n\t\ttitle: options.title,\n\t\tauthor: options.author,\n\t\tlanguage: options.language,\n\t\tsummary: options.summary,\n\t\tgenres: options.genres,\n\t\tmodifiedAt: options.modifiedAt,\n\t\tcoverImageId: options.coverImageId,\n\t\tmanifest: options.manifest,\n\t\tspine: options.spine,\n\t});\n\n\tconst navXhtml = buildNavXhtml({\n\t\ttitle: options.title,\n\t\tlanguage: options.language,\n\t\tentries: options.navEntries,\n\t});\n\n\tconst tocNcx = buildTocNcx({\n\t\tidentifier: options.identifier,\n\t\ttitle: options.title,\n\t\tauthor: options.author,\n\t\tentries: options.navEntries,\n\t});\n\n\tconst zippable: Zippable = {\n\t\tmimetype: [strToU8(EPUB_MIMETYPE), { level: 0 }],\n\t\t\"META-INF/container.xml\": strToU8(buildContainerXml()),\n\t\t\"OEBPS/styles/main.css\": strToU8(DEFAULT_EPUB_CSS),\n\t\t\"OEBPS/content.opf\": strToU8(contentOpf),\n\t\t\"OEBPS/nav.xhtml\": strToU8(navXhtml),\n\t\t\"OEBPS/toc.ncx\": strToU8(tocNcx),\n\t};\n\n\tfor (const textEntry of options.textEntries) {\n\t\tzippable[textEntry.zipPath] = strToU8(textEntry.content);\n\t}\n\n\tfor (const binaryEntry of options.binaryEntries) {\n\t\tzippable[binaryEntry.zipPath] = [binaryEntry.data, { level: 0 }];\n\t}\n\n\treturn zipSync(zippable);\n}\n\nfunction createBaseManifest(): OpfManifestItem[] {\n\treturn [\n\t\t{\n\t\t\tid: \"ncx\",\n\t\t\thref: \"toc.ncx\",\n\t\t\tmediaType: \"application/x-dtbncx+xml\",\n\t\t},\n\t\t{\n\t\t\tid: \"nav\",\n\t\t\thref: \"nav.xhtml\",\n\t\t\tmediaType: \"application/xhtml+xml\",\n\t\t\tproperties: \"nav\",\n\t\t},\n\t\t{\n\t\t\tid: \"main-css\",\n\t\t\thref: \"styles/main.css\",\n\t\t\tmediaType: \"text/css\",\n\t\t},\n\t];\n}\n\nfunction appendCoverAssets(options: {\n\tcover: EpubImageAsset;\n\tbookTitle: string;\n\tlanguage: string;\n\tmanifest: OpfManifestItem[];\n\tspine: OpfSpineItem[];\n\ttextEntries: ArchiveTextEntry[];\n\tbinaryEntries: ArchiveBinaryEntry[];\n}): { coverImageId: string; coverRelativeHref: string } {\n\tconst coverExt = resolveImageExtension(\n\t\toptions.cover.mimeType,\n\t\toptions.cover.sourceUrl,\n\t);\n\tconst coverFileName = `cover.${coverExt}`;\n\tconst coverRelativeHref = `../images/${coverFileName}`;\n\tconst coverImageId = \"cover-image\";\n\n\toptions.manifest.push(\n\t\t{\n\t\t\tid: coverImageId,\n\t\t\thref: `images/${coverFileName}`,\n\t\t\tmediaType: resolveImageMediaType(options.cover.mimeType, coverExt),\n\t\t\tproperties: \"cover-image\",\n\t\t},\n\t\t{\n\t\t\tid: \"cover\",\n\t\t\thref: \"text/cover.xhtml\",\n\t\t\tmediaType: \"application/xhtml+xml\",\n\t\t},\n\t);\n\n\toptions.spine.push({ idref: \"cover\" });\n\n\toptions.binaryEntries.push({\n\t\tzipPath: `OEBPS/images/${coverFileName}`,\n\t\tdata: options.cover.data,\n\t});\n\n\toptions.textEntries.push({\n\t\tzipPath: \"OEBPS/text/cover.xhtml\",\n\t\tcontent: buildCoverPageXhtml(\n\t\t\toptions.bookTitle,\n\t\t\tcoverRelativeHref,\n\t\t\toptions.language,\n\t\t),\n\t});\n\n\treturn { coverImageId, coverRelativeHref };\n}\n\nfunction appendChapterEntry(options: {\n\tchapter: EpubChapterData;\n\tchapterIndex: number;\n\tlanguage: string;\n\timageHrefBySourceUrl: ReadonlyMap<string, string>;\n\tmanifest: OpfManifestItem[];\n\tspine: OpfSpineItem[];\n\ttextEntries: ArchiveTextEntry[];\n}): NavEntry {\n\tconst paddedIndex = String(options.chapterIndex).padStart(4, \"0\");\n\tconst manifestId = `ch-${paddedIndex}`;\n\tconst manifestHref = `text/ch-${paddedIndex}.xhtml`;\n\tconst zipPath = `OEBPS/${manifestHref}`;\n\n\tconst xhtml = sanitizeChapterHtmlToXhtml({\n\t\tchapter: options.chapter,\n\t\timageHrefBySourceUrl: options.imageHrefBySourceUrl,\n\t\tlanguage: options.language,\n\t});\n\n\toptions.manifest.push({\n\t\tid: manifestId,\n\t\thref: manifestHref,\n\t\tmediaType: \"application/xhtml+xml\",\n\t});\n\toptions.spine.push({ idref: manifestId });\n\toptions.textEntries.push({\n\t\tzipPath,\n\t\tcontent: xhtml,\n\t});\n\n\treturn {\n\t\ttitle: options.chapter.title,\n\t\thref: manifestHref,\n\t};\n}\n\nexport function buildVolumeEpub(input: VolumeEpubInput): Uint8Array {\n\tconst language = input.language?.trim() || DEFAULT_LANGUAGE;\n\tconst modifiedAt = input.modifiedAt ?? new Date();\n\tconst bookTitle = resolveVolumeBookTitle(input.novelTitle, input.volumeTitle);\n\n\tconst manifest = createBaseManifest();\n\tconst spine: OpfSpineItem[] = [];\n\tconst textEntries: ArchiveTextEntry[] = [];\n\tconst binaryEntries: ArchiveBinaryEntry[] = [];\n\tconst navEntries: NavEntry[] = [];\n\n\tlet coverImageId: string | undefined;\n\tif (input.cover) {\n\t\tconst coverResult = appendCoverAssets({\n\t\t\tcover: input.cover,\n\t\t\tbookTitle,\n\t\t\tlanguage,\n\t\t\tmanifest,\n\t\t\tspine,\n\t\t\ttextEntries,\n\t\t\tbinaryEntries,\n\t\t});\n\t\tcoverImageId = coverResult.coverImageId;\n\t}\n\n\tconst { imageHrefBySourceUrl, registeredImages } = registerIllustrations(\n\t\tinput.illustrations,\n\t);\n\n\tlet chapterCounter = 0;\n\tfor (const chapter of input.chapters) {\n\t\tchapterCounter += 1;\n\t\tconst navEntry = appendChapterEntry({\n\t\t\tchapter,\n\t\t\tchapterIndex: chapterCounter,\n\t\t\tlanguage,\n\t\t\timageHrefBySourceUrl,\n\t\t\tmanifest,\n\t\t\tspine,\n\t\t\ttextEntries,\n\t\t});\n\t\tnavEntries.push(navEntry);\n\t}\n\n\tfor (const image of registeredImages) {\n\t\tmanifest.push({\n\t\t\tid: image.manifestId,\n\t\t\thref: image.manifestHref,\n\t\t\tmediaType: image.mediaType,\n\t\t});\n\t\tbinaryEntries.push({\n\t\t\tzipPath: image.zipPath,\n\t\t\tdata: image.data,\n\t\t});\n\t}\n\n\treturn packEpubArchive({\n\t\tidentifier: input.identifier,\n\t\ttitle: bookTitle,\n\t\tauthor: input.author,\n\t\tlanguage,\n\t\tsummary: input.summary,\n\t\tgenres: input.genres,\n\t\tmodifiedAt,\n\t\tcoverImageId,\n\t\tmanifest,\n\t\tspine,\n\t\tnavEntries,\n\t\ttextEntries,\n\t\tbinaryEntries,\n\t});\n}\n\nexport function buildNovelEpub(input: NovelEpubInput): Uint8Array {\n\tconst language = input.language?.trim() || DEFAULT_LANGUAGE;\n\tconst modifiedAt = input.modifiedAt ?? new Date();\n\tconst bookTitle = input.title.trim() || \"Untitled\";\n\n\tconst manifest = createBaseManifest();\n\tconst spine: OpfSpineItem[] = [];\n\tconst textEntries: ArchiveTextEntry[] = [];\n\tconst binaryEntries: ArchiveBinaryEntry[] = [];\n\tconst navEntries: NavEntry[] = [];\n\tconst coverHrefBySourceUrl = new Map<string, string>();\n\n\tlet coverImageId: string | undefined;\n\tif (input.cover) {\n\t\tconst coverResult = appendCoverAssets({\n\t\t\tcover: input.cover,\n\t\t\tbookTitle,\n\t\t\tlanguage,\n\t\t\tmanifest,\n\t\t\tspine,\n\t\t\ttextEntries,\n\t\t\tbinaryEntries,\n\t\t});\n\t\tcoverImageId = coverResult.coverImageId;\n\t\tif (input.cover.sourceUrl) {\n\t\t\tcoverHrefBySourceUrl.set(\n\t\t\t\tinput.cover.sourceUrl,\n\t\t\t\tcoverResult.coverRelativeHref,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst { imageHrefBySourceUrl, registeredImages } = registerIllustrations(\n\t\tinput.illustrations,\n\t);\n\n\tlet volumeCounter = 0;\n\tlet chapterCounter = 0;\n\n\tfor (const volume of input.volumes) {\n\t\tvolumeCounter += 1;\n\t\tconst volPadded = String(volumeCounter).padStart(3, \"0\");\n\n\t\tlet volumeCoverHref: string | undefined;\n\t\tif (volume.cover) {\n\t\t\tconst existingCoverHref = volume.cover.sourceUrl\n\t\t\t\t? coverHrefBySourceUrl.get(volume.cover.sourceUrl)\n\t\t\t\t: undefined;\n\t\t\tif (existingCoverHref !== undefined) {\n\t\t\t\tvolumeCoverHref = existingCoverHref;\n\t\t\t} else {\n\t\t\t\tconst ext = resolveImageExtension(\n\t\t\t\t\tvolume.cover.mimeType,\n\t\t\t\t\tvolume.cover.sourceUrl,\n\t\t\t\t);\n\t\t\t\tconst fileName = `vol-cover-${volPadded}.${ext}`;\n\t\t\t\tconst relHref = `../images/${fileName}`;\n\t\t\t\tmanifest.push({\n\t\t\t\t\tid: `vol-cover-${volPadded}`,\n\t\t\t\t\thref: `images/${fileName}`,\n\t\t\t\t\tmediaType: resolveImageMediaType(volume.cover.mimeType, ext),\n\t\t\t\t});\n\t\t\t\tbinaryEntries.push({\n\t\t\t\t\tzipPath: `OEBPS/images/${fileName}`,\n\t\t\t\t\tdata: volume.cover.data,\n\t\t\t\t});\n\t\t\t\tif (volume.cover.sourceUrl) {\n\t\t\t\t\tcoverHrefBySourceUrl.set(volume.cover.sourceUrl, relHref);\n\t\t\t\t}\n\t\t\t\tvolumeCoverHref = relHref;\n\t\t\t}\n\t\t}\n\n\t\tconst volManifestId = `vol-${volPadded}`;\n\t\tconst volManifestHref = `text/vol-${volPadded}.xhtml`;\n\t\tmanifest.push({\n\t\t\tid: volManifestId,\n\t\t\thref: volManifestHref,\n\t\t\tmediaType: \"application/xhtml+xml\",\n\t\t});\n\t\tspine.push({ idref: volManifestId });\n\t\ttextEntries.push({\n\t\t\tzipPath: `OEBPS/${volManifestHref}`,\n\t\t\tcontent: buildVolumeTitlePageXhtml({\n\t\t\t\ttitle: volume.title,\n\t\t\t\tlanguage,\n\t\t\t\tcoverHref: volumeCoverHref,\n\t\t\t}),\n\t\t});\n\n\t\tconst volumeNavChildren: NavEntry[] = [];\n\t\tfor (const chapter of volume.chapters) {\n\t\t\tchapterCounter += 1;\n\t\t\tconst chapterNavEntry = appendChapterEntry({\n\t\t\t\tchapter,\n\t\t\t\tchapterIndex: chapterCounter,\n\t\t\t\tlanguage,\n\t\t\t\timageHrefBySourceUrl,\n\t\t\t\tmanifest,\n\t\t\t\tspine,\n\t\t\t\ttextEntries,\n\t\t\t});\n\t\t\tvolumeNavChildren.push(chapterNavEntry);\n\t\t}\n\n\t\tnavEntries.push({\n\t\t\ttitle: volume.title,\n\t\t\thref: volManifestHref,\n\t\t\tchildren: volumeNavChildren,\n\t\t});\n\t}\n\n\tfor (const image of registeredImages) {\n\t\tmanifest.push({\n\t\t\tid: image.manifestId,\n\t\t\thref: image.manifestHref,\n\t\t\tmediaType: image.mediaType,\n\t\t});\n\t\tbinaryEntries.push({\n\t\t\tzipPath: image.zipPath,\n\t\t\tdata: image.data,\n\t\t});\n\t}\n\n\treturn packEpubArchive({\n\t\tidentifier: input.identifier,\n\t\ttitle: bookTitle,\n\t\tauthor: input.author,\n\t\tlanguage,\n\t\tsummary: input.summary,\n\t\tgenres: input.genres,\n\t\tmodifiedAt,\n\t\tcoverImageId,\n\t\tmanifest,\n\t\tspine,\n\t\tnavEntries,\n\t\ttextEntries,\n\t\tbinaryEntries,\n\t});\n}\n"],"mappings":";;;;;AAaA,MAAMA,qBAAmB;AAEzB,MAAM,oBAAsD;CAC3D,cAAc;CACd,aAAa;CACb,aAAa;CACb,cAAc;CACd,aAAa;CACb,iBAAiB;CACjB,cAAc;AACf;AAEA,MAAM,yBAA2D;CAChE,KAAK;CACL,MAAM;CACN,KAAK;CACL,MAAM;CACN,KAAK;CACL,KAAK;CACL,MAAM;AACP;AAEA,MAAM,oCAAoB,IAAI,IAAI;CACjC;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;AAED,MAAM,oCAAoB,IAAI,IAAI;CAAC;CAAM;CAAM;AAAI,CAAC;AAEpD,MAAM,sCAAsB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;AAED,MAAM,mBAAmB;AAEzB,MAAM,kDAAkC,IAAI,IAAI,CAAC,OAAO,MAAM,CAAC;AAE/D,SAAS,0BAA0B,MAAuB;CACzD,MAAM,aAAa,KAAK,QAAQ,GAAG;CACnC,IAAI,eAAe,IAClB,OAAO,iBAAiB,KAAK,IAAI;CAElC,IAAI,KAAK,QAAQ,KAAK,aAAa,CAAC,MAAM,IACzC,OAAO;CAER,MAAM,SAAS,KAAK,MAAM,GAAG,UAAU;CACvC,MAAM,YAAY,KAAK,MAAM,aAAa,CAAC;CAC3C,IAAI,CAAC,iBAAiB,KAAK,MAAM,KAAK,CAAC,iBAAiB,KAAK,SAAS,GACrE,OAAO;CAER,IAAI,SAAS,cACZ,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eAAe;EACvC;EAEA,WAAW,KAAK;GACf,OAAO,OAAO;GACd,MAAM;GACN,UAAU;EACX,CAAC;CACF;CAEA,KAAK,MAAM,SAAS,kBAAkB;EACrC,SAAS,KAAK;GACb,IAAI,MAAM;GACV,MAAM,MAAM;GACZ,WAAW,MAAM;EAClB,CAAC;EACD,cAAc,KAAK;GAClB,SAAS,MAAM;GACf,MAAM,MAAM;EACb,CAAC;CACF;CAEA,OAAO,gBAAgB;EACtB,YAAY,MAAM;EAClB,OAAO;EACP,QAAQ,MAAM;EACd;EACA,SAAS,MAAM;EACf,QAAQ,MAAM;EACd;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC;AACF"}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@acanthis-dec/epub",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Platform-independent in-memory EPUB 3.0 builder for Acanthis.",
5
+ "author": "ConstasJ <constasj@qq.com>",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "types": "./dist/index.d.mts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "package.json",
17
+ "README.md",
18
+ "README.zh-CN.md"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/ConstasJ/Acanthis.git"
23
+ },
24
+ "homepage": "https://github.com/ConstasJ/Acanthis#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/ConstasJ/Acanthis/issues"
27
+ },
28
+ "dependencies": {
29
+ "dom-serializer": "^2.0.0",
30
+ "domhandler": "^6.0.1",
31
+ "fflate": "^0.8.3",
32
+ "htmlparser2": "^10.1.0"
33
+ },
34
+ "devDependencies": {
35
+ "@acanthis-dec/config-tsdown": "1.0.0",
36
+ "@acanthis-dec/config-typescript": "1.0.0",
37
+ "tsdown": "0.23.7",
38
+ "tsx": "4.23.15",
39
+ "typescript": "7.0.2"
40
+ },
41
+ "scripts": {
42
+ "build": "tsdown",
43
+ "check-types": "tsc --noEmit"
44
+ },
45
+ "types": "./dist/index.d.mts"
6
46
  }