diff --git a/src/extension.ts b/src/extension.ts index 15e47b2..d355d34 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -214,11 +214,31 @@ async function attachReaderToWebview( (item) => item.uri.path.toLowerCase() === currentSource.path.toLowerCase() ) ?? -1; - const currentFileName = currentSource.path.slice(currentSource.path.lastIndexOf('/') + 1).toLowerCase(); + const currentFileName = currentSource.path.slice(currentSource.path.lastIndexOf('/') + 1); + const isLinear = spineIndex >= 0 ? (epubPackage?.spine[spineIndex]?.linear !== false) : true; + + const spineItems = epubPackage?.spine.map((item, idx) => { + const itemFileName = item.uri.path.slice(item.uri.path.lastIndexOf('/') + 1); + const isActive = item.uri.path.toLowerCase() === currentSource.path.toLowerCase(); + const tocMatch = epubPackage.toc.find( + (t) => t.uri.path.toLowerCase() === item.uri.path.toLowerCase() + ); + return { + index: idx + 1, + idref: item.idref, + href: item.href, + fileName: itemFileName, + linear: item.linear !== false, + active: isActive, + label: tocMatch?.label + }; + }); + + const currentFileNameLower = currentFileName.toLowerCase(); const tocWithActive = epubPackage?.toc.map((item) => { const itemFileName = item.href.split(/[?#]/, 1)[0].split('/').pop()?.toLowerCase(); const isActive = item.uri.path.toLowerCase() === currentSource.path.toLowerCase() - || (itemFileName && itemFileName === currentFileName); + || (itemFileName && itemFileName === currentFileNameLower); return { label: item.label, href: item.href, @@ -240,6 +260,9 @@ async function attachReaderToWebview( creator: epubPackage?.creator, chapterIndex: spineIndex >= 0 ? spineIndex + 1 : undefined, totalChapters: epubPackage?.spine.length, + currentFileName, + isLinear, + spineItems, toc: tocWithActive, historyBackInfo }; diff --git a/src/reader-shell.ts b/src/reader-shell.ts index a27d78c..b9a8b0c 100644 --- a/src/reader-shell.ts +++ b/src/reader-shell.ts @@ -14,6 +14,16 @@ export interface HistoryBackInfo { scrollRatio?: number; } +export interface ReaderSpineNavInfo { + index: number; + idref: string; + href: string; + fileName: string; + linear: boolean; + active: boolean; + label?: string; +} + export interface ReaderNavInfo { hasPrev?: boolean; hasNext?: boolean; @@ -21,6 +31,9 @@ export interface ReaderNavInfo { creator?: string; chapterIndex?: number; totalChapters?: number; + currentFileName?: string; + isLinear?: boolean; + spineItems?: ReaderSpineNavInfo[]; toc?: ReaderTocItem[]; historyBackInfo?: HistoryBackInfo; } @@ -70,6 +83,7 @@ const PHOSPHOR = { arrowsOutLineVertical: ``, slidersHorizontal: ``, dotsThree: ``, + listNumbers: ``, bookmarkSimple: ``, arrowUUpLeft: ``, x: `` @@ -112,16 +126,17 @@ export function readerShell( const hasNav = navInfo && typeof navInfo.totalChapters === 'number' && navInfo.totalChapters > 0; const hasToc = navInfo && Array.isArray(navInfo.toc) && navInfo.toc.length > 0; + const hasSpine = navInfo && Array.isArray(navInfo.spineItems) && navInfo.spineItems.length > 0; - const tocBtnHtml = hasToc - ? `` + const tocBtnHtml = (hasToc || hasSpine) + ? `` : ''; const navHtml = hasNav ? `
` : ''; @@ -135,22 +150,59 @@ export function readerShell( }) .join(''); - const sidebarHtml = hasToc - ? `