diff --git a/package-lock.json b/package-lock.json index bd424b5d..edf50c9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24307,6 +24307,7 @@ "license": "MIT", "dependencies": { "@vitejs/plugin-react": "^4.3.3", + "pdfjs-dist": "^4.7.76", "react": "^18.3.1", "react-dom": "^18.3.1" }, diff --git a/packages/tests/package.json b/packages/tests/package.json index b3eb93f1..360f3583 100644 --- a/packages/tests/package.json +++ b/packages/tests/package.json @@ -25,6 +25,7 @@ "dependencies": { "@vitejs/plugin-react": "^4.3.3", "react": "^18.3.1", - "react-dom": "^18.3.1" + "react-dom": "^18.3.1", + "pdfjs-dist": "^4.7.76" } } diff --git a/packages/tests/tests/bookmarks/index.tsx b/packages/tests/tests/bookmarks/index.tsx index e1dcf1fe..412cfafb 100644 --- a/packages/tests/tests/bookmarks/index.tsx +++ b/packages/tests/tests/bookmarks/index.tsx @@ -4,10 +4,11 @@ import { bookmarksEnhancer, RuntimeBookmark } from "@prose-reader/enhancer-bookm import { createArchiveFromPdf, pdfEnhancer } from "@prose-reader/enhancer-pdf" import * as pdfjsLib from "pdfjs-dist" import pdfWorkerUrl from "pdfjs-dist/build/pdf.worker.min.mjs?url" -import { of } from "rxjs" +import { of, switchMap } from "rxjs" import { createRoot } from "react-dom/client" import { useEffect, useState } from "react" import { gesturesEnhancer } from "@prose-reader/enhancer-gestures" +import pdfjsViewerInlineCss from "pdfjs-dist/web/pdf_viewer.css?inline" pdfjsLib.GlobalWorkerOptions.workerSrc = new URL(pdfWorkerUrl, import.meta.url).toString() @@ -15,7 +16,6 @@ async function run() { const response = await fetch("http://localhost:3333/epubs/sample-3.pdf") const pdfBlob = await response.blob() const archive = await createArchiveFromPdf(pdfBlob) - const manifest = await generateManifestFromArchive(archive) const createReaderWithEnhancers = gesturesEnhancer(pdfEnhancer(bookmarksEnhancer(createReader))) @@ -23,6 +23,7 @@ async function run() { const reader = createReaderWithEnhancers({ pageTurnAnimation: "none", pdf: { + pdfjsViewerInlineCss, getArchiveForItem: () => { return of(archive) }, @@ -30,7 +31,7 @@ async function run() { }) const Bookmarks = () => { - const [bookmarks, setBookmarks] = useState([]) + const [bookmarks, setBookmarks] = useState<{ meta?: { absolutePageIndex?: number | undefined } }[]>([]) const [pagination, setPagination] = useState<{ beginAbsolutePageIndex?: number }>({ beginAbsolutePageIndex: 0 }) useEffect(() => { @@ -40,12 +41,12 @@ async function run() { }, []) useEffect(() => { - reader.bookmarks.bookmarks$.subscribe((bookmarks) => { - setBookmarks(bookmarks) + reader.bookmarks.bookmarks$.pipe(switchMap((bookmarks) => reader.pagination.locate(bookmarks))).subscribe(({ data }) => { + setBookmarks(data) }) - }, []) + }, [reader]) - const bookmarkForPage = bookmarks?.find((bookmark) => bookmark.absolutePageIndex === pagination.beginAbsolutePageIndex) + const bookmarkForPage = bookmarks?.find((bookmark) => bookmark.meta?.absolutePageIndex === pagination.beginAbsolutePageIndex) return (