@anu3ev/fabric-image-editor

中文文档
0.14.1发布于 2026/11/04MITTypeScriptES Module构建来源已验证近 30 天下载 1900

TypeScript image editor library built on FabricJS, allowing you to create instances with an integrated montage area and providing an API to modify and manage state.

原始使用文档
文档目录28 节
  1. Why this project matters
  2. Built with this library
  3. See it in action
  4. Crop flow
  5. Layers and history
  6. Text styling
  7. For hiring managers
  8. Integration services
  9. ✨ Features
  10. Core Editing
  11. Advanced Capabilities
  12. Developer Features
  13. 📦 Installation
  14. 🚀 Quick Start
  15. Library language
  16. 🎮 Demo Application
  17. 🏗️ Architecture
  18. Core Managers
  19. Utility Managers
  20. UI Components
  21. How the parts work together
  22. 🛠️ Development
  23. Project Structure
  24. 🎯 Planned Features
  25. 🤝 Contributing
  26. 🔧 Browser Support
  27. 📄 License
  28. 🙏 Acknowledgments

Fabric Image Editor

Unit Coverage npm version Tests License: MIT

An image editor you can build into your web application.

Let users crop images, add text and shapes, work with layers, reuse compositions, and export the result. Built with TypeScript and Fabric.js, the library provides editing tools, undo/redo, and state restoration through an API you can connect to your own interface.

🚀 Live Demo · Integration guide

Why this project matters

Users can prepare and revise images without leaving your application.

Examples of where an integrated editor can fit:

Your applicationWhat users can do with an integrated editor
E-commerce administrationPrepare product images with captions, promotional labels, and a consistent layout.
CMS or publishing toolsCrop and compose an illustration while preparing an article or page.
Marketing toolsReuse a saved composition and change its text, images, or background.
Applications with AI image generationEdit the generated image before saving it. The application supplies the AI service.

Built with this library

Production inSales Vue image editor with reusable templates and a product composition

I built this TypeScript/FabricJS library and integrated it into the production Vue image editor at inSales. I owned the frontend architecture and implementation, working from prepared Figma designs and defining API contracts with the backend engineer.

The library provides canvas editing, history, and serialization. The product-specific Vue interface, backend, and AI features shown in the case belong to the host application and are not included in the npm package.

More project details on LinkedIn

See it in action

The live demo exercises the same workflows exposed through the public API.

Crop flow

Crop an image with a fixed ratio and a dimmed area outside the crop frame

Layers and history

Watch the layers and history demo

Text styling

Watch the text styling demo

For hiring managers

This repository demonstrates practical work with:

  • stateful browser interactions built on top of a canvas runtime;
  • editing with undo/redo, serialization, template restore, and export;
  • modular TypeScript architecture with explicit manager ownership;
  • public APIs and events designed for host-application integration;
  • regression coverage for interaction-heavy scenarios such as crop, selection, scaling, snapping, and text editing.

Integration services

I can integrate this editor into your application and adapt it to your workflow.

This can include image loading and saving, custom tools, editor open/close lifecycle, and error handling in your application.

I also provide support during integration and after launch, including troubleshooting, maintenance, and further development. We can agree on the scope and support arrangements around your product's needs.

Contact me on LinkedIn to discuss your integration.

✨ Features

Core Editing

  • Montage Area - Dedicated workspace with clipping region for precise cropping
  • Canvas & Image Cropping - Interactive crop mode for montage resizing and raster image cropping
  • Multi-layer Support - Layer management with ordering, visibility, and locking
  • History System - Full undo/redo with state management
  • Rich Text Editing - Text manager with typography controls, uppercase transforms, and history-aware updates
  • Object Transformations - Zoom, rotate, flip, fit, and scale operations
  • Professional Tools - Copy/paste, grouping, selection, and alignment

Advanced Capabilities

  • Background Management - Color, multi-stop gradient, and image backgrounds
  • Image Import/Export - Import PNG, JPEG, WebP, and SVG; export PNG, JPEG, WebP, SVG, and PDF
  • Precision Alignment - Snapping to montage edges/centers and nearby objects with visual guides and spacing detection
  • Live Measurements - Hold Alt with a selection to display distance guides to the hovered object or montage area
  • Web Worker Integration - Heavy operations run in background threads
  • Font Loader - FontManager handles Google Fonts + custom sources with automatic @font-face registration
  • Configurable Toolbar - Dynamic toolbar with context-sensitive actions
  • Clipboard Integration - Native copy/paste support with system clipboard
  • Deletion Guards - Application-defined rules can prevent user deletion for protected objects
  • Clone Preparation - Applications can sanitize object clones before copy, paste, duplicate, or cut

Developer Features

  • TypeScript Support - Full type definitions included
  • Modular Architecture - Clean separation of concerns with manager classes
  • Event System - Rich event handling for integration
  • Responsive Design - Adapts to different screen sizes and containers
  • Testing Infrastructure - Jest test suite with 80%+ coverage

📦 Installation

npm install @anu3ev/fabric-image-editor

Requirements:

  • Node.js ≥ 20.0.0
  • NPM ≥ 9.0.0
  • Browser with ES2022 support and the APIs listed in Browser Support

🚀 Quick Start

Add a container to your page:

<div id="editor"></div>

Initialize the editor after the container is mounted:

import initEditor from '@anu3ev/fabric-image-editor'

/** Editor instance owned by this page or component. */
const editor = await initEditor('editor', {
  montageAreaWidth: 512,
  montageAreaHeight: 512,
  editorContainerWidth: '100%',
  editorContainerHeight: '600px',
  fonts: []
})

fonts: [] skips the default font downloads. Call editor.destroy() when the owning page or component is removed.

See the integration guide for configuration, image import/export, text, shapes, cropping, and other editing operations.

Library language

English (en) and Russian (ru) are bundled. English is the default.

const editor = await initEditor('editor', { language: 'ru' })

Add a language or override selected translations with customLanguages:

import initEditor, { type EditorLocale } from '@anu3ev/fabric-image-editor'

const portuguese = {
  ui: { toolbar: { delete: 'Excluir', duplicate: 'Duplicar' } }
} satisfies EditorLocale

const editor = await initEditor('editor', {
  language: 'pt',
  customLanguages: { pt: portuguese }
})

See Language and translations for available keys, fallback rules, partial overrides, and notifications.

🎮 Demo Application

The repository includes a development demo for trying library operations. See Run the demo from source for local setup.

Visit the demo at: https://anu3ev.github.io/image-editor/**

🏗️ Architecture

The editor follows a modular architecture with specialized managers:

Core Managers

  • ImageManager - Image import/export, format handling, PDF generation
  • CanvasManager - Canvas sizing, scaling, and viewport management
  • HistoryManager - Undo/redo functionality with state persistence
  • TextManager - Text object creation, styling, uppercase handling, and history integration
  • LayerManager - Object layering, z-index management, send to back/front
  • BackgroundManager - Background colors, gradients, and images
  • CropManager - Runtime crop mode for montage resizing and raster image cropping
  • TransformManager - Object transformations, fitting, and scaling
  • ZoomManager - Zoom limits, fit calculations, and smooth viewport centering

Utility Managers

  • SelectionManager - Object selection and multi-selection handling
  • ClipboardManager - Copy/paste, cut, duplicate, clone preparation, and system clipboard integration
  • GroupingManager - Object grouping and ungrouping operations
  • DeletionManager - Object deletion, delete guards, skipped-delete events, and group handling
  • ShapeManager - Preset-based shape groups with inner text, layout, scaling, and style controls
  • ObjectLockManager - Object locking and unlocking functionality
  • SnappingManager - Alignment guides and equal-spacing snaps while moving objects
  • MeasurementManager - ALT-triggered distance guides to hovered objects or the montage area
  • PanConstraintManager - Constrains canvas panning relative to zoom and montage bounds
  • WorkerManager - Web Worker integration for heavy operations
  • FontManager - Font loading via FontFace API or fallback @font-face injection
  • ModuleLoader - Dynamic module loading (jsPDF, etc.)
  • ErrorManager - Error and warning events for the application to handle
  • TemplateManager (src/editor/template-manager/index.ts) - Serializes and reapplies object/group templates with optional background preservation

UI Components

  • ToolbarManager - Dynamic toolbar with configurable actions
  • CustomizedControls - Custom FabricJS controls and interactions
  • InteractionBlocker - UI blocking during operations
  • AngleIndicatorManager - Rotation angle badge shown while rotating selected objects (toggle via showRotationAngle)
  • ObjectSizeIndicatorManager - Size feedback while scaling (toggle via showObjectSizeOnScale)
  • ViewportScrollbarManager - Viewport scrollbars for panning (toggle via showViewportScrollbars)
  • CursorIndicator - Shared indicator for values shown next to the pointer

How the parts work together

  1. Initialization creates the managers, loads fonts and initial content, and establishes the starting history state. initEditor() waits for editor.ready before returning.
  2. A UI action calls the relevant manager. That manager coordinates geometry, rendering, editor events, and history where the operation requires them.
  3. Undo/redo and template application restore objects and their editor-specific behavior. Text and shapes need their layout and interaction state restored alongside their serialized properties.
  4. Crop frames, guides, and interaction overlays are temporary runtime state. They are kept separate from the composition that is saved or exported.
  5. destroy() releases the instance's listeners, workers, managed image URLs, and UI resources. The application owns its surrounding components, API requests, and persistent storage.

See Find the right part of the code for source entry points and manager-specific documentation.

Jest covers library behavior; Playwright exercises browser interactions. The coverage badge links to the unit-test workflow.

🛠️ Development

See CONTRIBUTING.md for local setup, build commands, type checking, linting, and unit and browser tests.

Project Structure

src/
├── main.ts                         # Public initialization function and exported types
├── editor/
│   ├── index.ts                    # ImageEditor and manager ownership
│   ├── defaults.ts                 # Default editor options
│   ├── constants.ts                # Shared values and limits
│   ├── default-fonts.ts            # Default font definitions
│   ├── listeners.ts                # Browser and canvas event handling
│   ├── object-serialization.ts      # Shared object serialization properties
│   ├── background-manager/
│   ├── canvas-manager/
│   ├── clipboard-manager/
│   ├── crop-manager/
│   ├── customized-controls/
│   ├── deletion-manager/
│   ├── error-manager/
│   ├── font-manager/
│   ├── grouping-manager/
│   ├── history-manager/
│   ├── image-manager/
│   ├── interaction-blocker/
│   ├── layer-manager/
│   ├── measurement-manager/
│   ├── module-loader/
│   ├── object-lock-manager/
│   ├── pan-constraint-manager/
│   ├── selection-manager/
│   ├── shape-manager/              # Creation, layout, editing, scaling, and restoration
│   ├── snapping-manager/           # Guide rendering and interaction-specific snapping
│   ├── template-manager/
│   ├── text-manager/
│   ├── transform-manager/
│   ├── worker-manager/
│   ├── zoom-manager/
│   ├── types/                      # Options, events, fonts, and Fabric/browser types
│   ├── utils/                      # Shared geometry and browser utilities
│   └── ui/
│       ├── angle-indicator/
│       ├── cursor-indicator/
│       ├── object-size-indicator/
│       ├── toolbar-manager/
│       └── viewport-scrollbar-manager/
└── demo/                           # Development interface for exercising the API
    ├── index.html
    ├── style.css
    ├── js/                         # Demo initialization, controls, and listeners
    └── vendor/                     # Demo CSS dependencies
specs/
├── src/editor/                     # Jest unit tests
├── test-utils/                     # Shared test fixtures, mocks, and assertions
├── __mocks__/
└── setupTests.ts
e2e/
├── tests/                          # Playwright interaction scenarios
├── models/                         # Editor and manager-specific browser models
├── fixtures/                       # Test setup and scenario data
├── helpers/                        # Shared browser test support
├── types/                          # Shared browser test contracts
└── assets/                         # Local assets used by browser tests
guides/integration.md               # API usage and integration examples
CONTRIBUTING.md                     # Setup, builds, checks, and contribution workflow
assets/                            # README screenshots and GIFs
badges/                            # Checked-in coverage badge
scripts/build-declarations.mjs      # Package declaration assembly
.github/workflows/                  # Quality checks, publishing, and demo deployment
vite.config.*.js                    # Development, library, and demo builds
jest.config.ts
playwright.config.ts
tsconfig*.json
dist/                              # Generated npm library build
dev-build/                         # Generated development library build
docs/                              # Generated GitHub Pages demo

The manager responsibilities are described above; their source directories contain the implementation and, where available, more detailed READMEs. docs/ is build output, while written documentation lives in the root Markdown files and guides/.

🎯 Planned Features

The following features are planned for future releases:

  • Drawing Mode - Freehand drawing tools and brushes
  • Filters & Effects - Image filters and visual effects
  • Extended Shape Library - Additional shapes beyond the existing preset library
  • Multi-language - Internationalization support

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

See CONTRIBUTING.md for setup instructions and contribution guidelines.

🔧 Browser Support

The library runs in the browser and is built as ES modules targeting ES2022. Worker-based image processing uses Web Workers, createImageBitmap, and OffscreenCanvas. Remote images and fonts must allow the required cross-origin requests.

Browser tests are configured for Chromium.

For applications with server rendering, load and initialize the editor on the client after its container exists.

📄 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments

  • Built with FabricJS - Powerful HTML5 canvas library
  • Vite - Lightning fast build tool
  • TypeScript - Type safety and developer experience
  • Jest - Comprehensive testing framework

Repository: github.com/Anu3ev/image-editor

NPM Package: @anu3ev/fabric-image-editor

Live Demo: anu3ev.github.io/image-editor

版本与发布记录

@anu3ev/fabric-image-editor 共发布 245 个版本,首次发布于 2025/05/23;过去 12 个月发布了 166 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.14.1latest2026/11/044 天前
0.13.12026/10/2415 天前
0.13.02026/10/1029 天前
0.12.12026/10/081 个月前
0.12.02026/10/071 个月前
0.11.02026/10/051 个月前

关于 @anu3ev/fabric-image-editor 的常见问题

@anu3ev/fabric-image-editor 是什么?

TypeScript image editor library built on FabricJS, allowing you to create instances with an integrated montage area and providing an API to modify and manage state.

如何安装 @anu3ev/fabric-image-editor?

在项目目录运行 npm install @anu3ev/fabric-image-editor,或使用 pnpm add / yarn add / bun add。

@anu3ev/fabric-image-editor 支持 TypeScript 吗?

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

@anu3ev/fabric-image-editor 支持 ESM 还是 CommonJS?

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

@anu3ev/fabric-image-editor 需要什么版本的 Node.js?

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

@anu3ev/fabric-image-editor 可以商用吗?

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

@anu3ev/fabric-image-editor 的下载量有多少?

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

@anu3ev/fabric-image-editor 还在维护吗?

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