@bendyline/squisq-react

中文文档
2.12.26发布于 2026/11/08MITTypeScriptES Module构建来源已验证近 30 天下载 7657

React component library for doc playback, block rendering, and media layers

原始使用文档
文档目录12 节
  1. Install
  2. Quick Start
  3. Components
  4. Fenced-code copy control
  5. Layers
  6. Hooks
  7. Standalone Player
  8. Diagram Pictures
  9. Styles
  10. Full API Reference
  11. Related Packages
  12. License

@bendyline/squisq-react

React component library for playing, rendering, and interacting with Squisq documents. Includes a full-featured doc player, SVG-based block renderer, media layers, and playback hooks.

Part of the Squisq monorepo.

npm MIT License

Install

npm install @bendyline/squisq-react @bendyline/squisq

Peer dependencies: react and react-dom (v18 or v19).

Quick Start

import { DocPlayer } from '@bendyline/squisq-react';
import '@bendyline/squisq-react/styles';

function App() {
  return <DocPlayer markdown={'# Hello\n\nWelcome to Squisq.'} />;
}

DocPlayer accepts either raw markdown (parsed and converted internally) or a parsed doc; if you already have a Doc, pass <DocPlayer doc={doc} />. basePath is optional (default '.') and is the base URL for resolving relative media paths. With neither markdown nor doc, the player renders a themed empty state rather than crashing.

v1.5 breaking changes: the old script prop is now doc, and the audioProvider prop is now audioController (its type AudioProvider was renamed to AudioController). LinearDocView gained the same markdown prop.

Components

ComponentDescription
DocPlayerMain document player with timed playback, audio sync, and controls
LinearDocViewScroll-based linear rendering of all blocks
BlockRendererSVG-based renderer for a single block
MarkdownRendererRenders Squisq markdown as a visual document
DocPlayerWithSidebarDocPlayer with a sidebar navigation panel
CaptionOverlayTimed caption/subtitle overlay
DocProgressBarPlayback progress indicator
DocControlsOverlayFloating playback controls
DocControlsBottomBottom-bar playback controls
DocControlsSidebarSidebar navigation controls
DocControlsSlideshowSlideshow-style navigation controls
SocialCaptionOverlayLarge centered word-by-word (TikTok/Reels-style) captions
InlineVideoPlayerNative <video> wrapper resolving src/poster via MediaContext
InlineAudioPlayerNative <audio> wrapper resolving src via MediaContext
AnimatedImageControlsPlay/pause controls over an animated GIF/WebP/APNG image
MediaClipLayerHidden <audio>/<video> elements for timed media clips
JsonViewRead-only viewer for JSON values bound to a Squisq-annotated schema

Fenced-code copy control

MarkdownRenderer and the linear document surfaces keep code-copy UI off by default. Opt in with showCodeCopyButton. Web hosts can rely on navigator.clipboard; Electron or native embeddings can provide their own clipboard bridge:

<LinearDocView
  markdown={'```\n$ node packages/tooling/dist/cli.mjs components\n```'}
  showCodeCopyButton
  onCopyCode={(code, { language }) => hostClipboard.writeText(code)}
/>

The same two props are available on DocPlayer (for linear mode), and on the standalone static mount() options. The callback receives the exact fence contents, without the backtick delimiters.

Layers

Blocks are composed of typed layers rendered as SVG:

LayerDescription
ImageLayerBackground and foreground images
TextLayerStyled text with positioning and animation
ShapeLayerSVG shapes (rectangles, circles, lines)
PathLayerFreeform SVG path drawing
VideoLayerEmbedded video with playback sync
TableLayerHTML table embedded via SVG <foreignObject>
MapLayerTile-based map rendering
TreeLayerInteractive filesystem/outline tree

Hooks

HookDescription
useDocPlaybackCore playback state machine — timing, block transitions, scripting
useAudioSyncSynchronizes audio playback with doc timeline
useMediaScheduleResolves which timed media clips are active at the current time
useViewportOrientationTracks viewport orientation for responsive layouts
useAutoSurfaceLive light/dark surface detection via prefers-color-scheme
useMediaProvider / useMediaUrlMedia URL resolution via MediaContext

useDocPlayback takes configuration as an options object:

useDocPlayback(doc, currentTime, { viewport, theme, onSeek });

Standalone Player

A global build is available for non-React environments. It exposes a SquisqPlayer global with mount, getHandle, unmount, and version. mount returns an instance handle. Load the package stylesheet alongside the raw global build so authored Font Awesome icons can use the shared webfonts.

The default build is the light player and omits Mermaid's multi-megabyte parser and layout engines. Documents that contain Mermaid fences should use the full variant at dist/squisq-player.full.global.js (also exported as @bendyline/squisq-react/standalone/full). Other diagrams are supported by both variants.

The former mountStatic() shortcut was removed; pass mode: 'static' to mount(). Render methods are instance-scoped and are no longer copied to top-level window.seekTo / window.getDuration properties.

Interactive mount:

<link rel="stylesheet" href="https://unpkg.com/@bendyline/squisq-react/dist/styles/index.css" />
<script src="https://unpkg.com/@bendyline/squisq-react/dist/squisq-player.global.js"></script>
<div id="player"></div>
<script>
  // docJson is a Doc (e.g. produced by markdownToDoc and serialized)
  const root = document.getElementById('player');
  const handle = SquisqPlayer.mount(root, docJson, {
    mode: 'slideshow', // or 'static' for a scrollable document view
    basePath: '/',
  });

  // In render mode: const api = await handle.renderAPI;
  // The same handle is available later as SquisqPlayer.getHandle(root).
</script>

For headless capture, add renderMode: true, then await handle.renderAPI before calling seekTo() or reading render metadata. seekTo() resolves only after React has committed the requested visual time, CSS animations have been positioned, active video has produced its sought frame, and one final paint opportunity has completed. getRenderedTime() returns the timeline time represented by the committed DOM. TypeScript hosts can import MountOptions and SquisqPlayerHandle from the package root.

Set animationsEnabled: false on DocPlayer, BlockRenderer, or standalone mount() to render authored layer animations and block transitions as static content. Embedded video, timed media, captions, audio, and document timing stay active; this makes the option suitable for compact MP4 and animated-GIF export.

For build-time embedding, @bendyline/squisq-react/standalone-source exports the player as a self-contained string constant (PLAYER_BUNDLE) with the shared icon styles composed once. It is used by @bendyline/squisq-formats and the CLI to produce single-file HTML and rendered video exports.

Diagram Pictures

@bendyline/squisq-react/diagram-pictures draws diagrams as PNG for document exports (browser only): renderMermaidPicture, renderSquisqDiagramPicture (ASCII diagrams and timelines, drawing, layout and diagram blocks, cropped to their content without slide chrome), renderTreePicture, and createDiagramPictureRenderer, the renderer rasterizeDiagrams in @bendyline/squisq-formats/diagrams takes. Pictures are plain SVG drawn to a canvas — Mermaid with SVG-text labels, no <foreignObject> — so the read-back works in every browser, and text uses system fonts because a picture cannot load the page's web fonts.

Styles

Import the package CSS for block transitions and Font Awesome inline icons:

import '@bendyline/squisq-react/styles';

Full API Reference

See docs/API.md for the complete prop tables, hook signatures, and types.

PackageDescription
@bendyline/squisqHeadless core — schemas, templates, spatial, markdown, storage
@bendyline/squisq-formatsDOCX, PDF, HTML import/export
@bendyline/squisq-editor-reactReact editor with raw/WYSIWYG/preview modes

License

MIT

版本与发布记录

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

版本发布日期距今
2.12.26latest2026/11/08今天
2.12.252026/11/07今天
2.12.242026/11/052 天前
2.12.232026/11/053 天前
2.12.222026/11/017 天前
2.12.212026/10/308 天前

关于 @bendyline/squisq-react 的常见问题

@bendyline/squisq-react 是什么?

React component library for doc playback, block rendering, and media layers

如何安装 @bendyline/squisq-react?

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

@bendyline/squisq-react 支持 TypeScript 吗?

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

@bendyline/squisq-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bendyline/squisq-react 需要什么版本的 Node.js?

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

@bendyline/squisq-react 可以商用吗?

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

@bendyline/squisq-react 的下载量有多少?

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

@bendyline/squisq-react 还在维护吗?

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