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

dom-inplace-paginator

v0.2.0

Published

Dependency-free DOM paginator for in-place page previews, print-ready page breaks, and HTML, Vue, and React integrations.

Readme

dom-inplace-paginator

一个零运行时依赖的原地 DOM 分页器,用于分页预览、打印分页,以及 HTML、Vue 3 和 React 项目集成。

当前版本为 0.2.0,仍处于实验阶段。分页器会直接修改目标 DOM;用于生产环境前,请根据实际文档内容完成浏览器兼容性测试。

特性

  • 根据页面尺寸、页眉、页脚和版心计算分页位置
  • 支持纯文本拆分、普通表格按行拆分和重复表头
  • 图片、视频、公式和自定义原子区域整体换页
  • 支持强制分页、忽略区域和自定义候选元素
  • 支持页眉、页脚、页码和可配置版心线
  • 自动注入打印分页规则和自定义分页类名
  • 提供原生 HTML、Vue 3 和 React 入口
  • 无运行时依赖

安装

npm install dom-inplace-paginator

快速开始

import { createPaginator } from "dom-inplace-paginator"

const paginator = createPaginator({
  page: {
    width: 800,
    height: 1080,
    gap: 16,
    padding: { top: 30, right: 48, bottom: 30, left: 48 },
  },
  header: {
    height: 40,
    render: () => "示例文档",
  },
  footer: {
    height: 30,
    render: ({ pageNumber, totalPages }) =>
      `第 ${pageNumber} / ${totalPages} 页`,
  },
  contentFrame: {
    visible: true,
    color: "#0089ff",
    width: 1,
    style: "solid",
    left: 48,
    right: 48,
  },
  print: {
    breakClass: "page_print",
    injectStyles: true,
  },
})

const result = await paginator.paginate(document.querySelector("#content"))
console.log(`共 ${result.pageCount} 页`)

contentFrame.left 和 contentFrame.right 同时控制版心线与正文左右边界,内容会始终位于版心线内部。未设置时,它们跟随 page.padding.left/right。

HTML

通过普通 <script> 引入 src/index.js 后,使用全局对象调用:

const paginator = DomPaginator.createPaginator(options)
await paginator.paginate(document.querySelector("#content"))

dom-inplace-paginator/html 还导出 paginateAll(options, scope),可自动处理带有 data-page-break 的容器。

Vue 3

<script setup>
import { vPageBreak } from "dom-inplace-paginator/vue"

const options = {
  page: { height: 700 },
  footer: {
    height: 30,
    render: ({ pageNumber, totalPages }) => `${pageNumber} / ${totalPages}`,
  },
}
</script>

<template>
  <main v-page-break="{ ready: true, options }">
    <h1>需要分页的内容</h1>
  </main>
</template>

也可以从 dom-inplace-paginator/vue 导入默认插件,并通过 app.use(plugin) 全局注册。

React

import { PageBreak } from "dom-inplace-paginator/react"

export default function Document() {
  return (
    <PageBreak options={{ page: { height: 700 } }}>
      <h1>需要分页的内容</h1>
    </PageBreak>
  )
}

分页后如需更新内容,请修改外层 key,完整卸载并重新创建分页区域。

DOM 标记

| 标记 | 作用 | | --- | --- | | data-page-atomic | 元素整体换页,不从内部拆分 | | data-page-break-inside="avoid" | 避免元素内部换页 | | data-page-break-before | 元素前强制换页 | | data-page-break-after | 元素后强制换页 | | data-page-ignore | 排除当前区域及其后代 | | data-page-candidate | 将元素加入分页候选 |

主要配置

  • page: width、height、gap、padding
  • header / footer: height、render({ pageNumber, totalPages })
  • contentFrame: visible、color、width、style、left、right
  • print: breakClass、injectStyles
  • candidates: minWidthRatio、minHeight
  • maxPages: 最大页数,默认 300
  • assetTimeout: 字体和图片等待超时
  • onError(error): 分页错误回调

在线 Demo

无需安装或克隆仓库,直接打开 在线分页 Demo 即可体验。页面右侧工具栏可调整页面、页眉、页脚、打印类名和版心线。

已知限制

  • 复杂合并单元格表格需要标记为 data-page-atomic
  • flex、grid、绝对定位和横向并列候选暂不保证自动拆分正确
  • 超过一页可用高度的单个元素会中止分页
  • 分页会直接修改 DOM,Vue/React 内容变化后需要完整重新挂载
  • 当前尚未提供 TypeScript 声明和自动化真实浏览器测试

开发

npm test
npm run check
npm pack --dry-run

License

MIT