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 🙏

© 2026 – Pkg Stats / Ryan Hefner

rebook

v0.8.0

Published

A modular e-book parsing and rendering library

Readme

rebook

English | API 参考 | 架构设计 | 经验总结

rebook 是一个 TypeScript 电子书工具库,用来构建高性能阅读器和电子书处理流程,支持浏览器、微信小程序、Node.js 和 worker 类运行环境。

它把 EPUB、MOBI/AZW3、FB2、CBZ 解析成统一的 Book 契约。浏览器和微信小程序渲染器、导出、搜索、插件以及 AI 文档处理工作流都基于同一套契约。

主要特性

  • 高性能翻页:rebook 先把章节排成 Pretext line ranges,再只渲染当前可见行。普通翻页只更新 page index 和一小段 DOM/snapshot,不需要重排整章 DOM 或 iframe。
  • 跨平台渲染:浏览器端渲染轻量 DOM 行;微信小程序端输出可序列化 snapshot,适合 WXML 渲染。
  • 多格式解析:支持 EPUB 2/3、MOBI/AZW/AZW3、FictionBook 2、CBZ。
  • 环境无关解析器:通过 parser adapters,让同一套解析器运行在浏览器、Node.js、小程序和 worker 中。
  • 模块化架构:解析器、渲染器、导出器、插件、适配器相互独立。
  • AI 友好内容模型:章节可暴露结构块、样式片段、可搜索文本和可修改文档树。
  • 内置工作流能力:搜索、前 N 个 section 导出、试读限制、TTS 播放钩子、专业翻译流水线、MCP server。

安装

npm install rebook

浏览器阅读器

import { registry, createReader } from 'rebook'
import { epub } from 'rebook/parsers/epub'
import { mobi } from 'rebook/parsers/mobi'
import { fb2 } from 'rebook/parsers/fb2'
import { cbz } from 'rebook/parsers/cbz'

registry.register('epub', epub)
registry.register('mobi', mobi)
registry.register('fb2', fb2)
registry.register('cbz', cbz)

const reader = createReader({
    container: document.getElementById('viewer')!,
    layout: 'paginated',
    maxColumnCount: 2,
    styles: {
        fontSize: '18px',
        lineHeight: 1.7,
        minColumnWidth: '320px',
        maxColumnWidth: '720px',
        margin: '32px',
    },
})

const book = await reader.open(file)
await reader.next()
await reader.goTo('chapter.xhtml#section')

微信小程序阅读器

没有 DOM 的小程序环境使用平台 reader。它默认安装小程序 parser adapters,并可通过 wx.createOffscreenCanvas 做文本测量。

import { registry } from 'rebook'
import { epub } from 'rebook/parsers/epub'
import { createWechatMiniProgramReader } from 'rebook/renderers/wechat-miniprogram'

registry.register('epub', epub)

const fs = wx.getFileSystemManager()
const arrayBuffer = fs.readFileSync(filePath) as ArrayBuffer
const unitlessStyles = new Set(['fontWeight', 'opacity', 'zIndex'])
const toStyleText = (style: Record<string, string | number> = {}) =>
    Object.entries(style)
        .map(([key, value]) => {
            const cssKey = key.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`)
            const cssValue = typeof value === 'number' && !unitlessStyles.has(key)
                ? `${value}px`
                : String(value)
            return `${cssKey}:${cssValue}`
        })
        .join(';')

const reader = createWechatMiniProgramReader({
    width: 375,
    height: 667,
    wx,
    layout: 'paginated',
    styles: { fontSize: '18px', lineHeight: 1.7 },
    setData: snapshot => this.setData({
        reader: {
            ...snapshot,
            lines: snapshot.lines.map(line => ({
                ...line,
                styleText: toStyleText(line.style),
                fragments: 'fragments' in line
                    ? line.fragments.map(fragment => ({
                        ...fragment,
                        styleText: toStyleText(fragment.style),
                    }))
                    : undefined,
            })),
        },
    }),
})

await reader.open(arrayBuffer)
await reader.next()

在 WXML 中渲染 snapshot 里的 reader.lines。每个 line node 都包含布局 style 以及文本、图片或表格数据。传给 WXML 前需要把 style object 转成 CSS 字符串。更完整的接入方式见 API 参考:微信小程序 Reader

MCP Server

rebook-mcp 可以通过 Model Context Protocol 把本地书籍暴露给 AI 助手。支持 EPUB、MOBI/AZW3、FB2 和 CBZ。

{
  "mcpServers": {
    "book": {
      "command": "npx",
      "args": ["-y", "--package", "rebook", "rebook-mcp", "/absolute/path/book.epub"]
    }
  }
}

内置工具包括章节列表、章节正文读取、元数据读取、整本书或单章节搜索。嵌入式 API 见 MCP Tools

支持格式

| 格式 | 扩展名 | |------|--------| | EPUB 2/3 | .epub | | Mobipocket / Kindle | .mobi.azw.azw3 | | FictionBook 2 | .fb2.fbz.fb2.zip | | Comic Book Zip | .cbz |

更多 API

  • 试读限制withTrialLimit({ maxPages })、试读感知目录、受限导航。见 Plugins
  • 导出exportFirstSections()exportBook() 支持 EPUB、CBZ、TXT、HTML 输出。见 First Sections Export
  • 搜索searchBook()searchChapters()reader.search()reader.searchChapters()。见 Search
  • 文档模型:查询和修改章节文档树,用于 AI 工作流、标注、转换和序列化。见 Document Model
  • Pretext 排版:直接使用 prepareBlocks()layout()getVisibleLines() 构建自定义渲染器。见 Pretext Layout

文档

  • API 参考 - readers、parsers、renderers、plugins、exporters、adapters、search、MCP 和文档 API。
  • 架构设计 - 解析器/渲染器分离、adapter 设计、渲染管线和项目结构。
  • 经验总结 - 设计取舍、性能说明、AI 工作流想法和实现经验。

开发

npm install
npm run dev
npm run typecheck
npm run build
npm test

许可证

MIT

致谢

基于 John Factotum 优秀的 foliate-js