UNPKG

@triabin/vue-book-reader

Version:

Forked from jinhuan138/vue-book-reader, add some features

43 lines (42 loc) 1.96 kB
const j = async ({ entries: d, loadBlob: l, getSize: g, getComment: u }, c) => { const r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), m = async (e) => { if (r.has(e)) return r.get(e); const t = URL.createObjectURL(await l(e)), n = URL.createObjectURL( new Blob([`<body style="margin: 0"><img src="${t}">`], { type: "text/html" }) ); return a.set(e, [t, n]), r.set(e, n), n; }, f = (e) => { var t, n; (n = (t = a.get(e)) == null ? void 0 : t.forEach) == null || n.call(t, (s) => URL.revokeObjectURL(s)), a.delete(e), r.delete(e); }, h = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp", ".svg", ".jxl", ".avif"], i = d.map((e) => e.filename).filter((e) => h.some((t) => e.endsWith(t))).sort(); if (!i.length) throw new Error("No supported image files in archive"); const o = {}; try { const t = JSON.parse(await u() || "")["ComicBookInfo/1.0"]; if (t) { const n = t.publicationYear, s = t.publicationMonth, b = s && s >= 1 && s <= 12 ? String(s).padStart(2, "0") : null; o.metadata = { title: t.title || c.name, publisher: t.publisher, language: t.language || t.lang, author: t.credits ? t.credits.map((p) => `${p.person} (${p.role})`).join(", ") : "", published: n && s ? `${n}-${b}` : void 0 }; } else o.metadata = { title: c.name }; } catch { o.metadata = { title: c.name }; } return o.getCover = () => l(i[0]), o.sections = i.map((e) => ({ id: e, load: () => m(e), unload: () => f(e), size: g(e) })), o.toc = i.map((e) => ({ label: e, href: e })), o.rendition = { layout: "pre-paginated" }, o.resolveHref = (e) => ({ index: o.sections.findIndex((t) => t.id === e) }), o.splitTOCHref = (e) => [e, null], o.getTOCFragment = (e) => e.documentElement, o.destroy = () => { for (const e of a.values()) for (const t of e) URL.revokeObjectURL(t); }, o; }; export { j as makeComicBook };