npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@treinetic/treinetic-epub-reader

v2.0.4

Published

A modern, lightweight, and framework-agnostic EPUB reader for the web, built with TypeScript.

Readme

Treinetic Epub Reader 2.0.3

A modern, lightweight, and framework-agnostic EPUB reader for the web, built with TypeScript. This project is an initiative of Treinetic (Pvt) Ltd, Sri Lanka.

Issues Software License Forks Stars Twitter

This library allows you to easily embed an EPUB reader into any web application. It handles parsing, rendering, pagination, and navigation, while leaving the UI (buttons, sidebars, menus) completely up to you.


Features

| Feature | Description | | :--- | :--- | | Framework Agnostic | Works seamlessly with React, Vue, Angular, or Vanilla JS. | | Lightweight | Zero heavy dependencies. Uses native Iframe isolation for security and style encapsulation. | | Fully Responsive | New: Automatically adapts padding and font sizes using internal container logic (Internal Wrapper Pattern). | | Themable | Inject custom CSS, change fonts, and toggle dark mode easily. | | TypeScript | Fully typed for a great developer experience. | | Modern Build | ESM and UMD support via Vite for modern bundlers. | | Continuous Scroll | Support for both Paginated (Kindle-style) and Vertical Scrolling modes. |

Requirements

  • NodeJS 16+ (for development)
  • Modern Browser (ES6 Support)

Installation

1. NPM

Install the package via npm:

npm install @treinetic/treinetic-epub-reader

2. Manual

Alternatively, you can include the dist/treinetic-epub-reader.umd.js and dist/style.css manually in your project.

Running the Demo

To see the reader in action with a sample UI:

git clone https://github.com/Treinetic/TreineticEpubReader.git
cd TreineticEpubReader
npm install
npm run demo

This will start a local server at http://localhost:3001 with hot-reloading.

Usage

Basic Usage

First, import the necessary methods and CSS.

[!NOTE] v2.0.3 Update: You can now use Named Exports for better compatibility with Vite and modern bundlers.

import { create } from '@treinetic/treinetic-epub-reader';
import '@treinetic/treinetic-epub-reader/dist/style.css'; 

// Create the reader instance targeting your container
const reader = create("#epub-reader-frame");

// Load an EPUB file (url or base64)
// Note: Must be a valid .epub file, not a PDF.
// For correct path resolution in Vite, ensure files are in 'public/' or imported as assets.
import { open } from '@treinetic/treinetic-epub-reader';
open("path/to/book.epub");

HTML Structure

Create a container for the reader. The library will inject an internal wrapper and iframe into this div.

<div id="epub-reader-frame" style="width: 100%; height: 600px;"></div>

[!TIP] You can resize this container at will. The reader monitors its own size and adjusts layouts (padding, columns) automatically.

Controlling the Reader

// Navigation
document.getElementById('next-btn').onclick = () => reader.nextPage();
document.getElementById('prev-btn').onclick = () => reader.prevPage();

// Settings
reader.setTheme('night'); // 'day', 'night', 'sepia'
reader.setFontSize(120);  // Percentage

API Reference

| Method | Signature | Description | | :--- | :--- | :--- | | open | (url: string) => void | Loads and renders an EPUB file. | | nextPage | () => void | Navigates to the next page or chapter. | | prevPage | () => void | Navigates to the previous page or chapter. | | goToPage | (href: string) => void | Navigates to a specific spine item (chapter). | | getTOC | () => TOCItem[] | Returns the Table of Contents as a JSON tree. | | setTheme | (id: string) => void | Switches themes (e.g. 'night', 'sepia', 'day'). | | registerTheme | (theme: ReaderTheme) => void | Registers a new custom theme. | | setFontSize | (size: number) => void | Sets font size (percentage, e.g. 120). | | setScrollOption| (mode: 'auto' \| 'scroll-continuous') | Toggle between Paginated and Vertical Scroll. | | clearSettings | () => void | Resets all user preferences (font, theme, location). |

Keyboard Shortcuts

| Key | Action | | :--- | :--- | | ArrowRight | Next Page | | ArrowLeft | Prev Page |

🎨 Advanced Customization

Creating Custom Themes

You are not limited to the default themes. You can register your own:

reader.registerTheme({
    id: 'matrix-theme',
    name: 'Matrix Mode',
    style: {
        'body': {
            'background-color': '#000000',
            'color': '#00FF00'
        },
        'p': {
            'font-family': 'monospace'
        }
    }
});

reader.setTheme('matrix-theme');

🗺️ Project Roadmap

We have an ambitious vision to make this the de facto standard for open-source EPUB rendering. Please see our detailed ROADMAP for upcoming features like Full-Text Search, Offline support, and Mobile gestures.

Project Structure

This project has been modernized (v2.0.0) to separate the Core Library from the Demo Application.

  • src/lib/: The Library. Contains the core logic (TreineticEpubReader.ts, ReaderView.ts).
  • src/css/: Library CSS. main.css (layout) and responsive.css (adaptive padding).
  • demo/: The Demo App. Contains the UI (index.html, demo.css, demo.js).
  • dist/: Build Output. The compiled files published to NPM.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information. (Portions based on the original ReadiumJS viewer, BSD-3-Clause).