|
| 1 | +import { createReader } from "@prose-reader/core" |
| 2 | +import { Streamer, createArchiveFromJszip } from "@prose-reader/streamer" |
| 3 | +import { loadAsync } from "jszip" |
| 4 | +import { from } from "rxjs" |
| 5 | + |
| 6 | +async function createStreamer() { |
| 7 | + const streamer = new Streamer({ |
| 8 | + getArchive: async () => { |
| 9 | + const epubResponse = await fetch( |
| 10 | + "http://localhost:3333/epubs/haruko-html-jpeg.epub", |
| 11 | + ) |
| 12 | + const epubBlob = await epubResponse.blob() |
| 13 | + const epubJszip = await loadAsync(epubBlob) |
| 14 | + const archive = await createArchiveFromJszip(epubJszip) |
| 15 | + |
| 16 | + return archive |
| 17 | + }, |
| 18 | + }) |
| 19 | + |
| 20 | + return streamer |
| 21 | +} |
| 22 | + |
| 23 | +async function run() { |
| 24 | + const streamer = await createStreamer() |
| 25 | + const manifestResponse = await streamer.fetchManifest({ |
| 26 | + key: `_`, |
| 27 | + }) |
| 28 | + const manifest = await manifestResponse.json() |
| 29 | + |
| 30 | + const reader = createReader({ |
| 31 | + pageTurnAnimation: "none", |
| 32 | + layoutLayerTransition: false, |
| 33 | + getResource: (item) => { |
| 34 | + return from(streamer.fetchResource({ key: `_`, resourcePath: item.href })) |
| 35 | + }, |
| 36 | + }) |
| 37 | + |
| 38 | + const query = new URLSearchParams(window.location.search) |
| 39 | + const cfi = query.get("cfi") || undefined |
| 40 | + |
| 41 | + reader.load({ |
| 42 | + // biome-ignore lint/style/noNonNullAssertion: <explanation> |
| 43 | + containerElement: document.getElementById(`app`)!, |
| 44 | + manifest, |
| 45 | + cfi, |
| 46 | + }) |
| 47 | + |
| 48 | + // @ts-expect-error export for debug |
| 49 | + window.reader = reader |
| 50 | +} |
| 51 | + |
| 52 | +run() |
0 commit comments