@gullabs/react-flipbook

中文文档
3.2.2发布于 2026/10/01MITTypeScriptESM + CJS构建来源已验证近 30 天下载 5779

React 18/19 binding for @gullabs/flipbook-core. Maintained fork of react-pageflip.

原始使用文档
文档目录4 节
  1. Quickstart
  2. First-hour rules
  3. Common props and events
  4. License

@gullabs/react-flipbook

React 18/19 binding for @gullabs/flipbook-core. Maintained fork of react-pageflip. License: MIT (engine dependency is MPL-2.0).

Full monorepo docs:

npm i @gullabs/react-flipbook
# pulls @gullabs/flipbook-core; react is a peer (>=18)

Quickstart

import { useState } from 'react';
import HTMLFlipBook, { type BookSnapshot } from '@gullabs/react-flipbook';

export function Book() {
  // Seed from onLoaded. onPageChange fires only for real turns, never on mount.
  const [book, setBook] = useState<{ page: number; pageCount: number } | null>(null);
  const sync = (s: BookSnapshot) => setBook({ page: s.page, pageCount: s.pageCount });

  return (
    <>
      <p>{book ? `Page ${book.page + 1} of ${book.pageCount}` : 'Loading…'}</p>
      <HTMLFlipBook width={300} height={500} onLoaded={sync} onPageChange={sync}>
        {/* Host element required. Style content on an INNER wrapper — the
            engine owns layout + paper on the leaf root. */}
        <div>
          <div style={{ height: '100%', padding: 16 }}>Page 1</div>
        </div>
        <div>
          <div style={{ height: '100%', padding: 16 }}>Page 2</div>
        </div>
      </HTMLFlipBook>
    </>
  );
}

First-hour rules

  1. onLoaded for the initial counter — onPageChange / core flip do not fire on mount (only when the page index actually changes).
  2. Style an inner wrapper, not the leaf root. The engine writes position, size, clip, and paper onto the root every draw.
  3. Controlled page needs onPageChange — otherwise the engine turns and your prop snaps it back (a locked book).
  4. Do not drive initialPage from live URL state — it is a remount key. Freeze the deep link at mount, or use controlled page.
  5. Keep page-child identity stable across onTurnProgress. Memoize the page elements. A parent that rebuilds them on every progress tick tears the book down mid-curl. Put the scrubber thumb in a sibling, not in the page children.

Common props and events

Prop / eventRole
width / heightRequired page size
page + onPageChangeControlled page (optional pageTransition: 'animate' | 'instant')
onLoaded / onReadyInitial / once-per-engine snapshot (page, pageCount, visiblePages, …)
onTurnProgressFold progress 0…1 while animating or dragging. Silent on instant / reduced-motion turns and on hover peel. Settle with onPageChange / onChangeState.
lazyRadiusReact-only window. Core PageFlip ignores it; a vanilla host must window the DOM itself.
onTurnRejectedTurn did not start (reason, direction, targetPage, landedOn)
controls'auto' | 'visible' | 'none'
hardCoversCover leaves shown alone, hard density
pageBackgroundPaper color (any CSS color; opacity is structural)
injectStylesDefault true; set false under strict CSP and import core style.css
Page mediaPortrait curl freezes each <video> as a canvas and strips <audio>. video[controls], audio[controls], iframe, embed, and object do not start a fold. Play and pause stay the host's job — see core README.

Handle methods (ref → FlipBookHandle):

MethodRole
flipNext / flipPrevAnimate relative turn (boolean)
flipToPage(n)Animate to page (boolean)
turnToPage(n)Instant jump (boolean)
cancelTurn()Abandon in-flight turn without committing. read fires after the portrait clone is removed, on a completed turn and on cancel.
destroy()Tear down the engine and retire the React shell
pageFlip()Escape hatch → core PageFlip | null

Queries such as getPageCount / getVisiblePages live on the engine (pageFlip()?.getPageCount()) or on usePageFlip() state — not on the handle. Prefer destroy() on the handle over pageFlip()?.destroy(): the latter tears the engine down but does not retire the React shell until the next render.

License

MIT for this package. The engine (@gullabs/flipbook-core) is MPL-2.0 — see https://github.com/gul-labs/flipbook/blob/main/packages/core/LICENSE.

Copyright (c) 2026 Gul Labs.

版本与发布记录

@gullabs/react-flipbook 共发布 5 个版本,首次发布于 2026/08/31;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.2.2latest2026/10/011 个月前
3.2.12026/09/092 个月前
3.2.02026/09/092 个月前
3.1.02026/09/012 个月前
3.0.02026/08/312 个月前

关于 @gullabs/react-flipbook 的常见问题

@gullabs/react-flipbook 是什么?

React 18/19 binding for @gullabs/flipbook-core. Maintained fork of react-pageflip.

如何安装 @gullabs/react-flipbook?

在项目目录运行 npm install @gullabs/react-flipbook,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18)、react-dom(>=18)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gullabs/react-flipbook 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gullabs/react-flipbook 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gullabs/react-flipbook 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.18.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@gullabs/react-flipbook 可以商用吗?

@gullabs/react-flipbook 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gullabs/react-flipbook 的下载量有多少?

根据 npm 官方下载统计,@gullabs/react-flipbook 在 2026/10/17 – 2026/11/15 这 30 天内被下载 5,779 次,日均约 193 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gullabs/react-flipbook 还在维护吗?

最新版本 3.2.2 发布于 2026/10/01(1 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/08/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。