canvas-editor

Hufe921MIT活跃维护

基于 Canvas/SVG 实现的富文本编辑器,支持 LaTeX 公式、日期选择、PDF 导出等能力,适合在浏览器里搭建电子病历、报表等复杂排版编辑场景。

A Canvas/SVG-based rich text editor

暂无版本5,262star +2 / 7 天876fork同步于 2026-11-10 11:36 UTC

怎么上手

由 README 提炼,执行前请确认
npm install @hufe921/canvas-editor
import Editor from '@hufe921/canvas-editor'
const editor = new Editor(container, { main: [{ value: 'Hello, Canvas Editor!' }] })
硬件要求按 README 说明

README 未说明,纯浏览器端渲染,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

基于 Canvas/SVG 渲染的所见即所得富文本编辑器,适合需要像素级排版与分页的文档场景

基于 Canvas/SVG 实现的富文本编辑器,支持 LaTeX 公式、日期选择、PDF 导出等能力,适合在浏览器里搭建电子病历、报表等复杂排版编辑场景。

核心能力

  • 用 Canvas 自绘渲染管线,跨浏览器排版一致
  • 支持表格、图片、LaTeX 公式、分页与页眉页脚
  • 内置表单控件与目录、批注等文档结构能力
  • 通过 instance.use 插件系统扩展 Word/Excel 导入导出等
  • 可切换 backend: 'svg' 使用内置 SVG 渲染后端

容易踩的坑

开发源码需要 Node.js >= 24.13.1 并推荐使用 pnpm;Word/Excel 导入导出、公式、拼写检查等能力需额外安装 canvas-editor-plugin 官方插件;PDF 导出在单独的 feature/pdf 分支而非主包

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Overview

    Canvas Editor is a feature-rich, WYSIWYG document editor rendered with HTML <canvas> (with an optional SVG backend). It is designed for use cases that demand pixel-perfect rendering, advanced typography, complex layouts, and Word-like document experiences in the browser — including EMR (Electronic Medical Records), legal contracts, reports, and other document-centric applications.

    Unlike traditional contenteditable-based editors, Canvas Editor takes full control of the rendering pipeline, providing consistent typography across browsers, precise pagination, and a uniform export experience.

    Features

    • Rich Text — Undo / Redo, Font, Size, Bold, Italic, Underline, Strikeout, Superscript, Alignment, Headings, Lists, and more
    • Insertable Elements — Tables, Images, Hyperlinks, Code Blocks, Page Breaks, Math Formulas (LaTeX), Date Pickers, Block elements
    • Form Controls — Select, Text, Date, Radio, Checkbox controls
    • Pagination — Native pagination with headers, footers, and page numbers
    • Page Layout — Configurable page margins, watermarks, backgrounds
    • Document Structure — Catalog (TOC) generation, comments, group annotations
    • Print & Export — Print-ready output via canvas-to-image / PDF rendering
    • Interaction — Custom context menus, customizable shortcut keys, drag-and-drop for text, elements, and controls
    • Extensibility — Plugin system (instance.use); official plugins cover Word/Excel import-export, formulas, code blocks, comments, spell checking, and more
    • Large Documents — Responsive rendering and editing of very large documents through incremental layout, position and history reuse, visible-page rendering, and optimized zooming
    • Performance — Web Workers for word counting, catalog generation, and async value retrieval

    Why Canvas Editor?

    Canvas Editorcontenteditable Editors
    Cross-browser renderingPixel-perfect, identicalVaries by browser
    PaginationNative, document-styleManual / unsupported
    Print fidelityMatches on-screen outputOften diverges
    Typography controlFull controlLimited by the browser
    Document featuresTOC, headers/footers, watermarksRequires heavy custom logic

    Installation

    # npm
    npm install @hufe921/canvas-editor
    
    # pnpm
    pnpm add @hufe921/canvas-editor
    
    # yarn
    yarn add @hufe921/canvas-editor
    

    Quick Start

    <div class="canvas-editor"></div>
    
    import Editor from '@hufe921/canvas-editor'
    
    const container = document.querySelector('.canvas-editor')
    
    const editor = new Editor(container, {
      main: [
        {
          value: 'Hello, Canvas Editor!'
        }
      ]
    })
    

    For complete API documentation, see the official docs.

    Ecosystem

    ProjectDescription
    canvas-editor-pluginOfficial plugins: Word/Excel import-export, formula, comment, spellcheck & 20+ more
    SVG render layerBuilt-in SVG rendering backend — enable via the backend: 'svg' editor option (supersedes the old feature/svg branch)
    feature/pdfPDF export — live demo
    feature/aiAI-powered text processing demo
    feature/CRDTCRDT-based collaboration (experimental)

    Development

    Prerequisites

    • Node.js >= 24.13.1
    • pnpm (recommended)

    Setup

    # Install dependencies
    pnpm install
    
    # Start the development server
    npm run dev
    

    Build

    # Build the application (demo)
    npm run build
    
    # Build the library (publishable package)
    npm run lib
    

    Quality Checks

    # Lint
    npm run lint
    
    # Type check
    npm run type:check
    
    # Unit tests (Vitest)
    npm run test:unit
    
    # E2E tests (Cypress)
    npm run cypress:open    # interactive
    npm run cypress:run     # headless
    

    Documentation

    npm run docs:dev        # Start VitePress docs locally
    npm run docs:build      # Build the documentation site
    

    Project Structure

    src/editor/
    ├── core/
    │   ├── draw/           # Rendering engine (canvas drawing)
    │   ├── render/         # Pluggable render backends (canvas / SVG)
    │   │   ├── particle/   # Element renderers (text, image, table, latex, ...)
    │   │   ├── control/    # Form control rendering
    │   │   ├── frame/      # Frame elements (margin, background, borders)
    │   │   ├── richtext/   # Decorations (underline, highlight)
    │   │   └── interactive/# Interactive features (search, graffiti)
    │   ├── command/        # Command pattern (executeBold, executeUndo, ...)
    │   ├── event/          # Canvas and global event handling
    │   ├── observer/       # Mouse, selection, image observers
    │   ├── worker/         # Web Workers for async operations
    │   └── plugin/         # Plugin system
    ├── interface/          # TypeScript interfaces
    ├── dataset/            # Enums and constants
    └── utils/              # Utility helpers
    

    Contributing

    Contributions are what make the open-source community such an amazing place. Any contributions you make are greatly appreciated — bug reports, feature requests, documentation improvements, or pull requests.

    1. Fork the repository
    2. Create your feature branch (git checkout -b feat/amazing-feature)
    3. Commit your changes following Conventional Commits (git commit -m 'feat: add amazing feature')
    4. Push to the branch (git push origin feat/amazing-feature)
    5. Open a Pull Request

    Pre-commit hooks automatically run lint and type:check. Commit messages must follow Conventional Commits format (feat:, fix:, docs:, refactor:, ...).

    Contributors

    Thanks to all the people who have contributed to Canvas Editor!

    Community & Support

    Sponsors

    If you find this project useful, please consider sponsoring to support its continued development.

    License

    This project is licensed under the MIT License.

    Copyright © 2022–present, Hufe921.