Feature #42: Foliate-js Unified Reader Engine
Priority: High | Status: PLANNED
Summary
Replace VReader's custom EPUB WKWebView bridge with Foliate-js — a battle-tested JS library that natively parses both EPUB and MOBI/AZW3 via a <foliate-view> web component. AZW3/MOBI support comes for free. PDF stays on PDFKit, TXT stays on UITextView.
Architecture
ReaderContainerView
├── FoliateReaderHost (EPUB, AZW3, MOBI) ← NEW
│ └── WKWebView + <foliate-view>
│ ├── epub.js (EPUB parser)
│ ├── mobi.js (AZW3/MOBI parser)
│ ├── paginator.js + overlayer.js + search.js + tts.js
│ └── foliate-host.js (Swift↔JS bridge)
├── PDFReaderHost (unchanged — PDFKit)
└── TXTReaderHost (unchanged — UITextView)
Why Foliate-js Instead of Native Swift Parser
- One engine for two formats (epub.js + mobi.js share same interface)
- Battle-tested (used by Foliate GNOME reader)
- Built-in features (pagination, highlights, search, TTS, progress)
- Less code (delete ~2100 LOC, add ~1700 LOC, net -400)
- No external dependencies (pure JS, vendored)
Work Items (13)
Phase 1 — Foundation:
Phase 2 — Core Rendering:
Phase 3 — Container + Integration:
Phase 4 — Features:
Phase 5 — Cleanup:
Key Technical Decision
WKURLSchemeHandler (vreader-resource://) serves both JS modules (from app bundle) and book files (from sandbox), solving the dual-directory access problem for ES modules in WKWebView.
Formats Supported
| Extension |
Format |
Renderer |
.epub |
EPUB |
Foliate-js (replaces current bridge) |
.azw3 |
KF8 |
Foliate-js (NEW) |
.azw |
KF8/MOBI |
Foliate-js (NEW, DRM-free only) |
.mobi |
KF7/KF8 |
Foliate-js (NEW) |
.pdf |
PDF |
PDFKit (unchanged) |
.txt |
TXT |
UITextView (unchanged) |
Plans
- Full plan:
.claude/plans/snug-painting-barto.md
- Summary:
docs/2026-03-24-azw3-support-plan.md
Refs #6
Feature #42: Foliate-js Unified Reader Engine
Priority: High | Status: PLANNED
Summary
Replace VReader's custom EPUB WKWebView bridge with Foliate-js — a battle-tested JS library that natively parses both EPUB and MOBI/AZW3 via a
<foliate-view>web component. AZW3/MOBI support comes for free. PDF stays on PDFKit, TXT stays on UITextView.Architecture
Why Foliate-js Instead of Native Swift Parser
Work Items (13)
Phase 1 — Foundation:
.azw3+ AZW3MetadataExtractorPhase 2 — Core Rendering:
Phase 3 — Container + Integration:
Phase 4 — Features:
Phase 5 — Cleanup:
Key Technical Decision
WKURLSchemeHandler (
vreader-resource://) serves both JS modules (from app bundle) and book files (from sandbox), solving the dual-directory access problem for ES modules in WKWebView.Formats Supported
.epub.azw3.azw.mobi.pdf.txtPlans
.claude/plans/snug-painting-barto.mddocs/2026-03-24-azw3-support-plan.mdRefs #6