From edf40cba410055063fe734c143f4730e81bd07e8 Mon Sep 17 00:00:00 2001 From: Taki Date: Mon, 16 Nov 2026 10:29:33 +0700 Subject: [PATCH 1/3] test(epub): verify spine reading order strictly follows itemrefs and linear attribute --- test/epub.test.mjs | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/epub.test.mjs b/test/epub.test.mjs index 9aa6301..e50f8d8 100644 --- a/test/epub.test.mjs +++ b/test/epub.test.mjs @@ -60,6 +60,57 @@ test('parseOpfXml extracts title, creator, manifest, and spine in sequence', asy assert.equal(parsed.spine[2].idref, 'ch2'); }); +test('parseOpfXml strictly respects spine itemref order and linear attribute over manifest declaration order', async () => { + const epub = await import('../dist/epub.js'); + const opfXml = ` + + + Unordered Spine Demo + + + + + + + + + + + + + +`; + + const mockOpfUri = { + path: '/project/OEBPS/content.opf', + with(change) { return { ...this, ...change }; } + }; + const mockRootUri = { + path: '/project', + with(change) { return { ...this, ...change }; } + }; + + const parsed = epub.parseOpfXml(opfXml, mockOpfUri, mockRootUri); + assert.equal(parsed.spine.length, 4); + + // Verify exact order in spine: cover (z_cover) -> prologue (m_prologue) -> ch2 (b_chapter2) -> ch1 (a_chapter1) + assert.equal(parsed.spine[0].idref, 'cover'); + assert.equal(parsed.spine[0].href, 'z_cover.xhtml'); + assert.equal(parsed.spine[0].linear, false); // linear="no" + + assert.equal(parsed.spine[1].idref, 'prologue'); + assert.equal(parsed.spine[1].href, 'm_prologue.xhtml'); + assert.equal(parsed.spine[1].linear, true); + + assert.equal(parsed.spine[2].idref, 'b-ch2'); + assert.equal(parsed.spine[2].href, 'b_chapter2.xhtml'); + assert.equal(parsed.spine[2].linear, true); + + assert.equal(parsed.spine[3].idref, 'a-ch1'); + assert.equal(parsed.spine[3].href, 'a_chapter1.xhtml'); + assert.equal(parsed.spine[3].linear, true); +}); + test('parseNavHtml extracts TOC items from EPUB 3 Navigation document', async () => { const epub = await import('../dist/epub.js'); const navHtml = ` From 48130fabd694ee9375d5d678215caeff2fd4a1fe Mon Sep 17 00:00:00 2001 From: Taki Date: Mon, 16 Nov 2026 10:30:25 +0700 Subject: [PATCH 2/3] test(fixtures): add unordered-spine test fixture for non-alphabetical reading order --- .../unordered-spine/META-INF/container.xml | 6 +++++ .../unordered-spine/OEBPS/a_chapter1.xhtml | 17 ++++++++++++++ .../unordered-spine/OEBPS/b_chapter2.xhtml | 17 ++++++++++++++ .../unordered-spine/OEBPS/content.opf | 22 +++++++++++++++++++ .../unordered-spine/OEBPS/m_prologue.xhtml | 17 ++++++++++++++ test/fixtures/unordered-spine/OEBPS/style.css | 17 ++++++++++++++ test/fixtures/unordered-spine/OEBPS/toc.xhtml | 19 ++++++++++++++++ .../unordered-spine/OEBPS/z_cover.xhtml | 15 +++++++++++++ 8 files changed, 130 insertions(+) create mode 100644 test/fixtures/unordered-spine/META-INF/container.xml create mode 100644 test/fixtures/unordered-spine/OEBPS/a_chapter1.xhtml create mode 100644 test/fixtures/unordered-spine/OEBPS/b_chapter2.xhtml create mode 100644 test/fixtures/unordered-spine/OEBPS/content.opf create mode 100644 test/fixtures/unordered-spine/OEBPS/m_prologue.xhtml create mode 100644 test/fixtures/unordered-spine/OEBPS/style.css create mode 100644 test/fixtures/unordered-spine/OEBPS/toc.xhtml create mode 100644 test/fixtures/unordered-spine/OEBPS/z_cover.xhtml diff --git a/test/fixtures/unordered-spine/META-INF/container.xml b/test/fixtures/unordered-spine/META-INF/container.xml new file mode 100644 index 0000000..0953a3e --- /dev/null +++ b/test/fixtures/unordered-spine/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/test/fixtures/unordered-spine/OEBPS/a_chapter1.xhtml b/test/fixtures/unordered-spine/OEBPS/a_chapter1.xhtml new file mode 100644 index 0000000..6eeaad7 --- /dev/null +++ b/test/fixtures/unordered-spine/OEBPS/a_chapter1.xhtml @@ -0,0 +1,17 @@ + + + + + Bab 1: Kilas Balik Memori + + + +

Bab 1: Kilas Balik Memori (a_chapter1.xhtml)

+

+ Ini adalah Spine Item urutan ke-4 (Spine 4/4) sekaligus bab terakhir dalam buku ini. +

+

+ Meskipun nama berkasnya berawalan a_ (yang biasanya paling atas di folder explorer), urutan baca canonical di spine menempatkannya di paling akhir. +

+ + \ No newline at end of file diff --git a/test/fixtures/unordered-spine/OEBPS/b_chapter2.xhtml b/test/fixtures/unordered-spine/OEBPS/b_chapter2.xhtml new file mode 100644 index 0000000..47e1584 --- /dev/null +++ b/test/fixtures/unordered-spine/OEBPS/b_chapter2.xhtml @@ -0,0 +1,17 @@ + + + + + Bab 2: Loncatan Waktu + + + +

Bab 2: Loncatan Waktu (b_chapter2.xhtml)

+

+ Ini adalah Spine Item urutan ke-3 (Spine 3/4). Bab 2 sengaja diletakkan sebelum Bab 1 di urutan spine untuk menguji alur cerita non-kronologis. +

+

+ Jika tombol Next Chapter (→) ditekan berikutnya, reader WAJIB membuka a_chapter1.xhtml. +

+ + \ No newline at end of file diff --git a/test/fixtures/unordered-spine/OEBPS/content.opf b/test/fixtures/unordered-spine/OEBPS/content.opf new file mode 100644 index 0000000..fba4e1c --- /dev/null +++ b/test/fixtures/unordered-spine/OEBPS/content.opf @@ -0,0 +1,22 @@ + + + + Unordered Spine Test Fixture + XHTML Reader Previewer + id + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/unordered-spine/OEBPS/m_prologue.xhtml b/test/fixtures/unordered-spine/OEBPS/m_prologue.xhtml new file mode 100644 index 0000000..ff6beee --- /dev/null +++ b/test/fixtures/unordered-spine/OEBPS/m_prologue.xhtml @@ -0,0 +1,17 @@ + + + + + Prolog: Awal Mula + + + +

Prolog: Awal Mula (m_prologue.xhtml)

+

+ Ini adalah Spine Item urutan ke-2 (Spine 2/4). Secara alfabetis nama berkas, huruf 'm' berada di tengah, namun pembaca resmi membaca dokumen ini tepat setelah cover. +

+

+ Jika tombol Next Chapter (→) ditekan, reader WAJIB membuka b_chapter2.xhtml sesuai urutan spine OPF, bukan z_cover.xhtml. +

+ + \ No newline at end of file diff --git a/test/fixtures/unordered-spine/OEBPS/style.css b/test/fixtures/unordered-spine/OEBPS/style.css new file mode 100644 index 0000000..266eb65 --- /dev/null +++ b/test/fixtures/unordered-spine/OEBPS/style.css @@ -0,0 +1,17 @@ +body { + font-family: system-ui, -apple-system, sans-serif; + line-height: 1.8; + padding: 1.5rem; +} + +h1 { + border-bottom: 2px solid #3b82f6; + padding-bottom: 0.5rem; + margin-bottom: 1.5rem; +} + +code { + background: rgba(156, 163, 175, 0.2); + padding: 0.2rem 0.4rem; + border-radius: 4px; +} diff --git a/test/fixtures/unordered-spine/OEBPS/toc.xhtml b/test/fixtures/unordered-spine/OEBPS/toc.xhtml new file mode 100644 index 0000000..c6d2834 --- /dev/null +++ b/test/fixtures/unordered-spine/OEBPS/toc.xhtml @@ -0,0 +1,19 @@ + + + + + Table of Contents + + + + + + \ No newline at end of file diff --git a/test/fixtures/unordered-spine/OEBPS/z_cover.xhtml b/test/fixtures/unordered-spine/OEBPS/z_cover.xhtml new file mode 100644 index 0000000..54f053a --- /dev/null +++ b/test/fixtures/unordered-spine/OEBPS/z_cover.xhtml @@ -0,0 +1,15 @@ + + + + + Cover Page + + + +
+

Cover Page (z_cover.xhtml)

+

Item ini memiliki atribut linear="no" di spine.

+

Urutan spine sesungguhnya adalah Spine 1 dari 4, meskipun secara alfabetis file ini berawalan 'z'.

+
+ + \ No newline at end of file From f48ce02c910fc1bbb0cedd017d3bc1fcf63f0e28 Mon Sep 17 00:00:00 2001 From: Taki Date: Mon, 16 Nov 2026 10:35:57 +0700 Subject: [PATCH 3/3] feat(reader): add spine order inspector tab and toolbar spine metadata --- src/extension.ts | 27 +++- src/reader-shell.ts | 281 +++++++++++++++++++++++++++++++++++-- test/reader-shell.test.mjs | 28 ++++ 3 files changed, 320 insertions(+), 16 deletions(-) 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 - ? `