feat: floating bookmarks

add floating bookmarks
This commit is contained in:
2026-06-03 22:19:19 -05:00
parent 6b4c0c43f8
commit 054e7689bd
10 changed files with 263 additions and 12 deletions
+17
View File
@@ -55,6 +55,23 @@ export function isEpubCfi(location: string | number): boolean {
return typeof location === "string" && location.startsWith("epubcfi(");
}
/** Book progress 0100 from an EPUB CFI (requires locations.generate). */
export function percentageFromCfi(rendition: EpubRendition, cfi: string): number | null {
if (!rendition.book?.locations || !isEpubCfi(cfi)) return null;
try {
const pct = rendition.book.locations.percentageFromCfi(cfi);
if (pct === null || pct === undefined) return null;
return Math.min(100, Math.max(0, Math.round(pct * 100)));
} catch {
return null;
}
}
export function spineLength(rendition: EpubRendition): number {
const items = rendition.book?.spine?.spineItems;
return items?.length ?? 0;
}
/** Map nav/TOC href to a spine href epub.js can display. */
export function resolveSpineHref(book: EpubBookForNav, href: string): string {
const hashIndex = href.indexOf("#");