@acanthis-dec/epub 0.1.0 → 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/index.d.mts CHANGED
@@ -15,6 +15,31 @@ interface EpubVolumeData {
15
15
  cover?: EpubImageAsset | undefined;
16
16
  chapters: EpubChapterData[];
17
17
  }
18
+ interface VolumeEpubSyncMetadata {
19
+ platform: string;
20
+ novelId: string;
21
+ volumeId: string;
22
+ profile: "original" | "eink";
23
+ contentFingerprint: string;
24
+ }
25
+ interface AcanthisEpubManifestChapter {
26
+ index: number;
27
+ href: string;
28
+ chapterId: string;
29
+ title: string;
30
+ totalParagraphs: number;
31
+ }
32
+ interface AcanthisEpubManifest {
33
+ schemaVersion: 1;
34
+ platform: string;
35
+ novelId: string;
36
+ volumeId: string;
37
+ volumeTitle: string;
38
+ profile: "original" | "eink";
39
+ contentFingerprint: string;
40
+ generatedAt: string;
41
+ chapters: AcanthisEpubManifestChapter[];
42
+ }
18
43
  interface VolumeEpubInput {
19
44
  identifier: string;
20
45
  novelTitle: string;
@@ -27,6 +52,7 @@ interface VolumeEpubInput {
27
52
  cover?: EpubImageAsset | undefined;
28
53
  chapters: EpubChapterData[];
29
54
  illustrations: EpubImageAsset[];
55
+ syncMetadata?: VolumeEpubSyncMetadata | undefined;
30
56
  }
31
57
  interface NovelEpubInput {
32
58
  identifier: string;
@@ -42,4 +68,4 @@ interface NovelEpubInput {
42
68
  }
43
69
  export declare function buildVolumeEpub(input: VolumeEpubInput): Uint8Array;
44
70
  export declare function buildNovelEpub(input: NovelEpubInput): Uint8Array;
45
- export type { EpubChapterData, EpubImageAsset, EpubVolumeData, NovelEpubInput, VolumeEpubInput };
71
+ export type { AcanthisEpubManifest, AcanthisEpubManifestChapter, EpubChapterData, EpubImageAsset, EpubVolumeData, NovelEpubInput, VolumeEpubInput, VolumeEpubSyncMetadata };
package/dist/index.mjs CHANGED
@@ -35,6 +35,14 @@ const HEADING_TAG_NAMES = /* @__PURE__ */ new Set([
35
35
  "h2",
36
36
  "h3"
37
37
  ]);
38
+ const ALL_HEADING_TAG_NAMES = /* @__PURE__ */ new Set([
39
+ "h1",
40
+ "h2",
41
+ "h3",
42
+ "h4",
43
+ "h5",
44
+ "h6"
45
+ ]);
38
46
  const URI_ATTRIBUTE_NAMES = /* @__PURE__ */ new Set([
39
47
  "href",
40
48
  "src",
@@ -261,18 +269,122 @@ function escapeNodesForXmlSerialization(nodes) {
261
269
  }
262
270
  }
263
271
  }
264
- function sanitizeChapterHtmlToXhtml(options) {
265
- const normalizedChildren = normalizeLeadingHeading(sanitizeNodeList(parseDocument(options.chapter.html, { decodeEntities: true }).children, options.imageHrefBySourceUrl), options.chapter.title);
272
+ function hasSingleImageChild(element) {
273
+ let foundImg = false;
274
+ for (const child of element.children) {
275
+ if (isText(child)) {
276
+ if (child.data.trim().length > 0) return false;
277
+ continue;
278
+ }
279
+ if (isTag(child)) {
280
+ if (child.name.toLowerCase() === "img" && !foundImg) {
281
+ foundImg = true;
282
+ continue;
283
+ }
284
+ return false;
285
+ }
286
+ if (!isComment(child)) return false;
287
+ }
288
+ return foundImg;
289
+ }
290
+ function annotateChapterBlocks(nodes) {
291
+ const result = [];
292
+ let blockIndex = 0;
293
+ for (const node of nodes) {
294
+ if (isText(node)) {
295
+ const trimmed = node.data.trim();
296
+ if (!trimmed) {
297
+ result.push(node);
298
+ continue;
299
+ }
300
+ const wrapped = new Element("p", { id: `b${blockIndex}` }, [new Text(trimmed)]);
301
+ wrapped.parent = node.parent;
302
+ result.push(wrapped);
303
+ blockIndex += 1;
304
+ continue;
305
+ }
306
+ if (!isTag(node)) {
307
+ result.push(node);
308
+ continue;
309
+ }
310
+ const tag = node.name.toLowerCase();
311
+ if (tag === "img") {
312
+ node.attribs = {
313
+ ...node.attribs,
314
+ id: `b${blockIndex}`
315
+ };
316
+ result.push(node);
317
+ blockIndex += 1;
318
+ continue;
319
+ }
320
+ if (tag === "p") {
321
+ if (hasSingleImageChild(node)) {
322
+ node.attribs = {
323
+ ...node.attribs,
324
+ id: `b${blockIndex}`
325
+ };
326
+ result.push(node);
327
+ blockIndex += 1;
328
+ continue;
329
+ }
330
+ const hasText = collectTextContent(node).trim().length > 0;
331
+ const hasElementChild = node.children.some((child) => isTag(child));
332
+ if (!hasText && !hasElementChild) {
333
+ result.push(node);
334
+ continue;
335
+ }
336
+ node.attribs = {
337
+ ...node.attribs,
338
+ id: `b${blockIndex}`
339
+ };
340
+ result.push(node);
341
+ blockIndex += 1;
342
+ continue;
343
+ }
344
+ if (ALL_HEADING_TAG_NAMES.has(tag)) {
345
+ node.attribs = {
346
+ ...node.attribs,
347
+ id: `b${blockIndex}`
348
+ };
349
+ result.push(node);
350
+ blockIndex += 1;
351
+ continue;
352
+ }
353
+ node.attribs = {
354
+ ...node.attribs,
355
+ id: `b${blockIndex}`
356
+ };
357
+ result.push(node);
358
+ blockIndex += 1;
359
+ }
360
+ return {
361
+ nodes: result,
362
+ totalParagraphs: blockIndex
363
+ };
364
+ }
365
+ function sanitizeChapterHtmlToXhtmlWithStats(options) {
366
+ const sanitizedChildren = sanitizeNodeList(parseDocument(options.chapter.html, { decodeEntities: true }).children, options.imageHrefBySourceUrl);
367
+ let childrenForHeading = sanitizedChildren;
368
+ let totalParagraphs = 0;
369
+ if (options.enableBlockAnchors) {
370
+ const annotated = annotateChapterBlocks(sanitizedChildren);
371
+ childrenForHeading = annotated.nodes;
372
+ totalParagraphs = annotated.totalParagraphs;
373
+ }
374
+ const normalizedChildren = normalizeLeadingHeading(childrenForHeading, options.chapter.title);
266
375
  escapeNodesForXmlSerialization(normalizedChildren);
267
376
  const bodyHtml = render(normalizedChildren, {
268
377
  xmlMode: true,
269
378
  encodeEntities: false
270
379
  });
271
- return wrapXhtmlDocument({
272
- title: options.chapter.title,
273
- language: options.language,
274
- bodyHtml
275
- });
380
+ return {
381
+ xhtml: wrapXhtmlDocument({
382
+ title: options.chapter.title,
383
+ language: options.language,
384
+ bodyHtml
385
+ }),
386
+ totalParagraphs
387
+ };
276
388
  }
277
389
  // src/nav.ts
278
390
  function renderNavList(entries, indentLevel) {
@@ -677,10 +789,11 @@ function appendChapterEntry(options) {
677
789
  const manifestId = `ch-${paddedIndex}`;
678
790
  const manifestHref = `text/ch-${paddedIndex}.xhtml`;
679
791
  const zipPath = `OEBPS/${manifestHref}`;
680
- const xhtml = sanitizeChapterHtmlToXhtml({
792
+ const { xhtml, totalParagraphs } = sanitizeChapterHtmlToXhtmlWithStats({
681
793
  chapter: options.chapter,
682
794
  imageHrefBySourceUrl: options.imageHrefBySourceUrl,
683
- language: options.language
795
+ language: options.language,
796
+ enableBlockAnchors: options.enableBlockAnchors
684
797
  });
685
798
  options.manifest.push({
686
799
  id: manifestId,
@@ -693,8 +806,11 @@ function appendChapterEntry(options) {
693
806
  content: xhtml
694
807
  });
695
808
  return {
696
- title: options.chapter.title,
697
- href: manifestHref
809
+ navEntry: {
810
+ title: options.chapter.title,
811
+ href: manifestHref
812
+ },
813
+ totalParagraphs
698
814
  };
699
815
  }
700
816
  function buildVolumeEpub(input) {
@@ -717,19 +833,46 @@ function buildVolumeEpub(input) {
717
833
  binaryEntries
718
834
  }).coverImageId;
719
835
  const { imageHrefBySourceUrl, registeredImages } = registerIllustrations(input.illustrations);
836
+ const enableBlockAnchors = input.syncMetadata !== void 0;
837
+ const manifestChapters = [];
720
838
  let chapterCounter = 0;
721
839
  for (const chapter of input.chapters) {
722
840
  chapterCounter += 1;
723
- const navEntry = appendChapterEntry({
841
+ const { navEntry, totalParagraphs } = appendChapterEntry({
724
842
  chapter,
725
843
  chapterIndex: chapterCounter,
726
844
  language,
727
845
  imageHrefBySourceUrl,
728
846
  manifest,
729
847
  spine,
730
- textEntries
848
+ textEntries,
849
+ enableBlockAnchors
731
850
  });
732
851
  navEntries.push(navEntry);
852
+ if (enableBlockAnchors) manifestChapters.push({
853
+ index: chapterCounter,
854
+ href: navEntry.href,
855
+ chapterId: chapter.id,
856
+ title: chapter.title,
857
+ totalParagraphs
858
+ });
859
+ }
860
+ if (input.syncMetadata) {
861
+ const acanthisManifest = {
862
+ schemaVersion: 1,
863
+ platform: input.syncMetadata.platform,
864
+ novelId: input.syncMetadata.novelId,
865
+ volumeId: input.syncMetadata.volumeId,
866
+ volumeTitle: input.volumeTitle,
867
+ profile: input.syncMetadata.profile,
868
+ contentFingerprint: input.syncMetadata.contentFingerprint,
869
+ generatedAt: modifiedAt.toISOString(),
870
+ chapters: manifestChapters
871
+ };
872
+ textEntries.push({
873
+ zipPath: "OEBPS/acanthis-manifest.json",
874
+ content: `${JSON.stringify(acanthisManifest, null, 2)}\n`
875
+ });
733
876
  }
734
877
  for (const image of registeredImages) {
735
878
  manifest.push({
@@ -828,7 +971,7 @@ function buildNovelEpub(input) {
828
971
  const volumeNavChildren = [];
829
972
  for (const chapter of volume.chapters) {
830
973
  chapterCounter += 1;
831
- const chapterNavEntry = appendChapterEntry({
974
+ const { navEntry: chapterNavEntry } = appendChapterEntry({
832
975
  chapter,
833
976
  chapterIndex: chapterCounter,
834
977
  language,
@@ -1 +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,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AAI,OAAO,MAAM,WAAW,OAAO;IAEzD,kBAAkB;GACnB;EACD;EAEA,MAAM,gBAAgB,OAAO;EAC7B,MAAM,kBAAkB,YAAY,UAAU;EAC9C,SAAS,KAAK;GACb,IAAI;GACJ,MAAM;GACN,WAAW;EACZ,CAAC;EACD,MAAM,KAAK,EAAE,OAAO,cAAc,CAAC;EACnC,YAAY,KAAK;GAChB,SAAS,SAAS;GAClB,SAAS,0BAA0B;IAClC,OAAO,OAAO;IACd;IACA,WAAW;GACZ,CAAC;EACF,CAAC;EAED,MAAM,oBAAgC,CAAC;EACvC,KAAK,MAAM,WAAW,OAAO,UAAU;GACtC,kBAAkB;GAClB,MAAM,kBAAkB,mBAAmB;IAC1C;IACA,cAAc;IACd;IACA;IACA;IACA;IACA;GACD,CAAC;GACD,kBAAkB,KAAK,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"}
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\"]);\nconst ALL_HEADING_TAG_NAMES = new Set([\"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\"]);\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\nfunction hasSingleImageChild(element: Element): boolean {\n\tlet foundImg = false;\n\tfor (const child of element.children) {\n\t\tif (isText(child)) {\n\t\t\tif (child.data.trim().length > 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (isTag(child)) {\n\t\t\tif (child.name.toLowerCase() === \"img\" && !foundImg) {\n\t\t\t\tfoundImg = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (!isComment(child)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn foundImg;\n}\n\nfunction annotateChapterBlocks(nodes: ChildNode[]): {\n\tnodes: ChildNode[];\n\ttotalParagraphs: number;\n} {\n\tconst result: ChildNode[] = [];\n\tlet blockIndex = 0;\n\n\tfor (const node of nodes) {\n\t\tif (isText(node)) {\n\t\t\tconst trimmed = node.data.trim();\n\t\t\tif (!trimmed) {\n\t\t\t\tresult.push(node);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst wrapped = new Element(\"p\", { id: `b${blockIndex}` }, [\n\t\t\t\tnew Text(trimmed),\n\t\t\t]);\n\t\t\twrapped.parent = node.parent;\n\t\t\tresult.push(wrapped);\n\t\t\tblockIndex += 1;\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 tag = node.name.toLowerCase();\n\n\t\tif (tag === \"img\") {\n\t\t\tnode.attribs = {\n\t\t\t\t...node.attribs,\n\t\t\t\tid: `b${blockIndex}`,\n\t\t\t};\n\t\t\tresult.push(node);\n\t\t\tblockIndex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (tag === \"p\") {\n\t\t\tif (hasSingleImageChild(node)) {\n\t\t\t\tnode.attribs = {\n\t\t\t\t\t...node.attribs,\n\t\t\t\t\tid: `b${blockIndex}`,\n\t\t\t\t};\n\t\t\t\tresult.push(node);\n\t\t\t\tblockIndex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst hasText = collectTextContent(node).trim().length > 0;\n\t\t\tconst hasElementChild = node.children.some((child) => isTag(child));\n\t\t\tif (!hasText && !hasElementChild) {\n\t\t\t\tresult.push(node);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tnode.attribs = {\n\t\t\t\t...node.attribs,\n\t\t\t\tid: `b${blockIndex}`,\n\t\t\t};\n\t\t\tresult.push(node);\n\t\t\tblockIndex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (ALL_HEADING_TAG_NAMES.has(tag)) {\n\t\t\tnode.attribs = {\n\t\t\t\t...node.attribs,\n\t\t\t\tid: `b${blockIndex}`,\n\t\t\t};\n\t\t\tresult.push(node);\n\t\t\tblockIndex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tnode.attribs = {\n\t\t\t...node.attribs,\n\t\t\tid: `b${blockIndex}`,\n\t\t};\n\t\tresult.push(node);\n\t\tblockIndex += 1;\n\t}\n\n\treturn {\n\t\tnodes: result,\n\t\ttotalParagraphs: blockIndex,\n\t};\n}\n\nexport interface SanitizeChapterHtmlOptions {\n\tchapter: EpubChapterData;\n\timageHrefBySourceUrl: ReadonlyMap<string, string>;\n\tlanguage?: string | undefined;\n\tenableBlockAnchors?: boolean | undefined;\n}\n\nexport interface SanitizedChapterXhtmlResult {\n\txhtml: string;\n\ttotalParagraphs: number;\n}\n\nexport function sanitizeChapterHtmlToXhtmlWithStats(\n\toptions: SanitizeChapterHtmlOptions,\n): SanitizedChapterXhtmlResult {\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\tlet childrenForHeading = sanitizedChildren;\n\tlet totalParagraphs = 0;\n\n\tif (options.enableBlockAnchors) {\n\t\tconst annotated = annotateChapterBlocks(sanitizedChildren);\n\t\tchildrenForHeading = annotated.nodes;\n\t\ttotalParagraphs = annotated.totalParagraphs;\n\t}\n\n\tconst normalizedChildren = normalizeLeadingHeading(\n\t\tchildrenForHeading,\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 {\n\t\txhtml: wrapXhtmlDocument({\n\t\t\ttitle: options.chapter.title,\n\t\t\tlanguage: options.language,\n\t\t\tbodyHtml,\n\t\t}),\n\t\ttotalParagraphs,\n\t};\n}\n\nexport function sanitizeChapterHtmlToXhtml(\n\toptions: SanitizeChapterHtmlOptions,\n): string {\n\treturn sanitizeChapterHtmlToXhtmlWithStats(options).xhtml;\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\tAcanthisEpubManifest,\n\tAcanthisEpubManifestChapter,\n\tEpubChapterData,\n\tEpubImageAsset,\n\tNovelEpubInput,\n\tVolumeEpubInput,\n} from \"./types\";\nimport {\n\tbuildCoverPageXhtml,\n\tbuildVolumeTitlePageXhtml,\n\tresolveImageExtension,\n\tsanitizeChapterHtmlToXhtmlWithStats,\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\tenableBlockAnchors?: boolean | undefined;\n}): { navEntry: NavEntry; totalParagraphs: number } {\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, totalParagraphs } = sanitizeChapterHtmlToXhtmlWithStats({\n\t\tchapter: options.chapter,\n\t\timageHrefBySourceUrl: options.imageHrefBySourceUrl,\n\t\tlanguage: options.language,\n\t\tenableBlockAnchors: options.enableBlockAnchors,\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\tnavEntry: {\n\t\t\ttitle: options.chapter.title,\n\t\t\thref: manifestHref,\n\t\t},\n\t\ttotalParagraphs,\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\tconst enableBlockAnchors = input.syncMetadata !== undefined;\n\tconst manifestChapters: AcanthisEpubManifestChapter[] = [];\n\n\tlet chapterCounter = 0;\n\tfor (const chapter of input.chapters) {\n\t\tchapterCounter += 1;\n\t\tconst { navEntry, totalParagraphs } = 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\tenableBlockAnchors,\n\t\t});\n\t\tnavEntries.push(navEntry);\n\t\tif (enableBlockAnchors) {\n\t\t\tmanifestChapters.push({\n\t\t\t\tindex: chapterCounter,\n\t\t\t\thref: navEntry.href,\n\t\t\t\tchapterId: chapter.id,\n\t\t\t\ttitle: chapter.title,\n\t\t\t\ttotalParagraphs,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (input.syncMetadata) {\n\t\tconst acanthisManifest: AcanthisEpubManifest = {\n\t\t\tschemaVersion: 1,\n\t\t\tplatform: input.syncMetadata.platform,\n\t\t\tnovelId: input.syncMetadata.novelId,\n\t\t\tvolumeId: input.syncMetadata.volumeId,\n\t\t\tvolumeTitle: input.volumeTitle,\n\t\t\tprofile: input.syncMetadata.profile,\n\t\t\tcontentFingerprint: input.syncMetadata.contentFingerprint,\n\t\t\tgeneratedAt: modifiedAt.toISOString(),\n\t\t\tchapters: manifestChapters,\n\t\t};\n\t\ttextEntries.push({\n\t\t\tzipPath: \"OEBPS/acanthis-manifest.json\",\n\t\t\tcontent: `${JSON.stringify(acanthisManifest, null, 2)}\\n`,\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\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 { navEntry: 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;AACpD,M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MAAM,UAAU;KAChB,WAAW,sBAAsB,OAAO,MAAM,UAAU,GAAG;IAC5D,CAAC;IACD,cAAc,KAAK;KAClB,SAAS,gBAAgB;KACzB,MAAM,OAAO,MAAM;IACpB,CAAC;IACD,IAAI,OAAO,MAAM,WAChB,qBAAqB,IAAI,OAAO,MAAM,WAAW,OAAO;IAEzD,kBAAkB;GACnB;EACD;EAEA,MAAM,gBAAgB,OAAO;EAC7B,MAAM,kBAAkB,YAAY,UAAU;EAC9C,SAAS,KAAK;GACb,IAAI;GACJ,MAAM;GACN,WAAW;EACZ,CAAC;EACD,MAAM,KAAK,EAAE,OAAO,cAAc,CAAC;EACnC,YAAY,KAAK;GAChB,SAAS,SAAS;GAClB,SAAS,0BAA0B;IAClC,OAAO,OAAO;IACd;IACA,WAAW;GACZ,CAAC;EACF,CAAC;EAED,MAAM,oBAAgC,CAAC;EACvC,KAAK,MAAM,WAAW,OAAO,UAAU;GACtC,kBAAkB;GAClB,MAAM,EAAE,UAAU,oBAAoB,mBAAmB;IACxD;IACA,cAAc;IACd;IACA;IACA;IACA;IACA;GACD,CAAC;GACD,kBAAkB,KAAK,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,6 @@
1
1
  {
2
2
  "name": "@acanthis-dec/epub",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Platform-independent in-memory EPUB 3.0 builder for Acanthis.",
5
5
  "author": "ConstasJ <constasj@qq.com>",
6
6
  "license": "MIT",