
A CSS column-based pagination engine for rendering book chapter HTML in web environments. Built with TypeScript, ships as ESM and CJS with full type declarations.
| Feature |
Description |
| π HTML Pagination |
CSS column layout engine that splits chapter HTML into discrete pages |
| π Scroll Mode |
Alternative continuous scroll reading mode with progress tracking |
| π€ Typography Settings |
Configurable font size, family, line height, letter/word spacing, paragraph spacing, text alignment, and hyphenation |
| π¨ Theme System |
Four built-in themes β Light, Sepia, Dark, and Ultra Dark |
| π§ Chapter Navigation |
Chapter manager with ordered traversal, jump-to-chapter, and boundary detection |
| π Reading Progress |
Combined chapter + page progress calculation (0 to 1) |
| π Content Security |
DOMPurify-based HTML sanitization before rendering |
| βοΈ React Wrapper |
Provider, View component, and hooks for React integration |
| π¦ Dual Format |
Ships as ESM and CJS with full TypeScript declarations |
npm install @readmigo/reader-engine
For React integration:
npm install @readmigo/reader-engine react react-dom
import { ReaderEngine } from '@readmigo/reader-engine';
const engine = new ReaderEngine({
apiBaseUrl: 'https://api.readmigo.com',
settings: { theme: 'sepia', fontSize: 20 },
});
// Mount to a DOM container
engine.mount(document.getElementById('reader')!);
// Load a book and its first chapter
const book = await engine.loadBook('book-123');
await engine.loadChapter(0);
// Navigate pages
engine.nextPage();
engine.prevPage();
// Listen for state changes
engine.callbacks.onStateChange = (state) => {
console.log(`Page ${state.currentPage + 1}/${state.totalPages}`);
};
import React, { useEffect } from 'react';
import { ReaderProvider, ReaderView, useReader } from '@readmigo/reader-engine/react';
function App() {
return (
<ReaderProvider apiBaseUrl="https://api.readmigo.com">
<ReaderPage bookId="book-123" />
</ReaderProvider>
);
}
function ReaderPage({ bookId }: { bookId: string }) {
const { state, loadBook, loadChapter, nextPage, prevPage } = useReader();
useEffect(() => {
loadBook(bookId).then(() => loadChapter(0));
}, [bookId, loadBook, loadChapter]);
return (
<div>
<ReaderView style={{ height: '80vh' }} />
<p>Progress: {(state.overallProgress * 100).toFixed(1)}%</p>
</div>
);
}
@readmigo/reader-engine
βββ types/ # Data models, settings, themes
βββ api/ # HTTP client + content loader
βββ renderer/ # CSS generation + DOMPurify HTML rendering
βββ core/ # Paginator (CSS columns) + scroll mode
βββ navigation/ # Chapter traversal + progress calculation
βββ engine.ts # ReaderEngine facade
βββ react/ # Provider, View component, hooks
The engine uses CSS multi-column layout to split content into pages, then translates the content horizontally to display one page at a time. See docs/ARCHITECTURE.md for detailed module diagrams and data flow.
| Theme |
Background |
Text |
Best For |
| Light |
#FFFFFF |
#1A1A1A |
Daytime reading |
| Sepia |
#F4ECD8 |
#5B4636 |
Reduced eye strain |
| Dark |
#1C1C1E |
#E5E5E7 |
Low-light environments |
| Ultra Dark |
#000000 |
#E5E5E7 |
OLED screens / night |
| Document |
Description |
| Architecture |
Module diagrams, data flow, CSS column pagination |
| Design |
Architecture decisions, core mechanisms, data flow, security, and extensibility |
| API Reference |
Complete type and method documentation |
| Getting Started |
Setup, integration guides, and customization |
| Command |
Description |
npm install |
Install dependencies |
npm run build |
Build with tsup (ESM + CJS + DTS) |
npm run dev |
Watch mode build |
npm test |
Run tests with Vitest |
npm run test:watch |
Watch mode tests |
npm run lint |
Type check with tsc --noEmit |
reader-engine/
βββ src/
β βββ types/ # Book, Chapter, Settings, Theme types
β βββ api/ # ApiClient, ContentLoader
β βββ renderer/ # ChapterRenderer, generateReaderCSS
β βββ core/ # Paginator, ScrollMode
β βββ navigation/ # ChapterManager, calculateOverallProgress
β βββ react/ # ReaderProvider, ReaderView, hooks
β βββ engine.ts # ReaderEngine facade
β βββ index.ts # Public exports
βββ docs/ # Architecture, API, Getting Started
βββ examples/ # Usage examples
βββ tsconfig.json # TypeScript config
βββ tsup.config.ts # Build config (ESM + CJS + DTS)
βββ vitest.config.ts # Test config (happy-dom)
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature)
- Make your changes and add tests
- Ensure all checks pass:
npm run lint && npm run build && npm test
- Commit your changes (
git commit -m 'feat: add my feature')
- Push to the branch (
git push origin feature/my-feature)
- Open a Pull Request
MIT