@anu3ev/fabric-image-editor 0.1.73 → 0.1.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/main.js +419 -320
- package/package.json +1 -1
- package/readme.md +338 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anu3ev/fabric-image-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.74",
|
|
4
4
|
"description": "JavaScript image editor built on FabricJS, allowing you to create instances with an integrated montage area and providing an API to modify and manage state.",
|
|
5
5
|
"module": "dist/main.js",
|
|
6
6
|
"files": [
|
package/readme.md
CHANGED
|
@@ -1,23 +1,46 @@
|
|
|
1
1
|
# Fabric Image Editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A modern, powerful browser-based image editor built with [FabricJS](https://fabricjs.com/) and TypeScript. This library provides a complete image editing solution with professional features for web applications.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
🚀 **[Live Demo](https://anu3ev.github.io/image-editor/)**
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- Layer, history and selection managers
|
|
9
|
-
- Object transformation helpers (zoom, rotate, flip, fit)
|
|
10
|
-
- Copy/paste and grouping tools
|
|
11
|
-
- Heavy operations are executed in a Web Worker to keep the UI responsive
|
|
12
|
-
- Configurable toolbar with actions for selected objects
|
|
7
|
+
## ✨ Features
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
### Core Editing
|
|
10
|
+
- **Montage Area** - Dedicated workspace with clipping region for precise cropping
|
|
11
|
+
- **Multi-layer Support** - Layer management with ordering, visibility, and locking
|
|
12
|
+
- **History System** - Full undo/redo with state management
|
|
13
|
+
- **Object Transformations** - Zoom, rotate, flip, fit, and scale operations
|
|
14
|
+
- **Professional Tools** - Copy/paste, grouping, selection, and alignment
|
|
15
|
+
|
|
16
|
+
### Advanced Capabilities
|
|
17
|
+
- **Background Management** - Color, gradient, and image backgrounds
|
|
18
|
+
- **Image Import/Export** - Support for PNG, JPG, SVG, and PDF formats
|
|
19
|
+
- **Web Worker Integration** - Heavy operations run in background threads
|
|
20
|
+
- **Configurable Toolbar** - Dynamic toolbar with context-sensitive actions
|
|
21
|
+
- **Clipboard Integration** - Native copy/paste support with system clipboard
|
|
22
|
+
|
|
23
|
+
### Developer Features
|
|
24
|
+
- **TypeScript Support** - Full type definitions included
|
|
25
|
+
- **Modular Architecture** - Clean separation of concerns with manager classes
|
|
26
|
+
- **Event System** - Rich event handling for integration
|
|
27
|
+
- **Responsive Design** - Adapts to different screen sizes and containers
|
|
28
|
+
- **Comprehensive Testing** - Jest test suite with 85%+ coverage
|
|
29
|
+
|
|
30
|
+
## 📦 Installation
|
|
15
31
|
|
|
16
32
|
```bash
|
|
17
33
|
npm install @anu3ev/fabric-image-editor
|
|
18
|
-
|
|
34
|
+
```
|
|
19
35
|
|
|
20
|
-
|
|
36
|
+
**Requirements:**
|
|
37
|
+
- Node.js ≥ 20.0.0
|
|
38
|
+
- NPM ≥ 9.0.0
|
|
39
|
+
- Modern browser with ES2016+ support
|
|
40
|
+
|
|
41
|
+
## 🚀 Quick Start
|
|
42
|
+
|
|
43
|
+
### Basic Setup
|
|
21
44
|
|
|
22
45
|
Create a container in your HTML and initialize the editor:
|
|
23
46
|
|
|
@@ -36,44 +59,329 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
36
59
|
editorContainerHeight: '100vh'
|
|
37
60
|
})
|
|
38
61
|
|
|
39
|
-
//
|
|
62
|
+
// The editor is now ready to use!
|
|
63
|
+
console.log('Editor initialized:', editor)
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Working with Images
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
// Import an image
|
|
71
|
+
await editor.imageManager.importImage({
|
|
72
|
+
source: 'path/to/image.jpg',
|
|
73
|
+
scale: 'image-contain' // 'image-contain', 'image-cover', 'scale-montage'
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// Export the canvas
|
|
77
|
+
const result = await editor.imageManager.exportCanvasAsImageFile({
|
|
78
|
+
fileName: 'edited-image.png',
|
|
79
|
+
contentType: 'image/png'
|
|
40
80
|
})
|
|
81
|
+
|
|
82
|
+
// Handle the exported file
|
|
83
|
+
const url = URL.createObjectURL(result.image)
|
|
84
|
+
// Use the URL for download or display
|
|
41
85
|
```
|
|
42
86
|
|
|
43
|
-
|
|
87
|
+
### Managing Backgrounds
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
// Set a color background
|
|
91
|
+
editor.backgroundManager.setColorBackground({ color: '#ff0000' })
|
|
92
|
+
|
|
93
|
+
// Set a gradient background
|
|
94
|
+
editor.backgroundManager.setGradientBackground({
|
|
95
|
+
startColor: '#ff0000',
|
|
96
|
+
endColor: '#0000ff',
|
|
97
|
+
angle: 45
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
// Set an image background
|
|
101
|
+
await editor.backgroundManager.setImageBackground({ source: 'bg-image.jpg' })
|
|
102
|
+
```
|
|
44
103
|
|
|
45
|
-
|
|
104
|
+
## 🎮 Demo Application
|
|
105
|
+
|
|
106
|
+
The repository includes a comprehensive demo showcasing all features:
|
|
46
107
|
|
|
47
108
|
```bash
|
|
109
|
+
git clone https://github.com/Anu3ev/image-editor.git
|
|
110
|
+
cd image-editor
|
|
48
111
|
npm install
|
|
49
112
|
npm run dev
|
|
50
113
|
```
|
|
51
114
|
|
|
52
|
-
|
|
115
|
+
Visit the demo at: **https://anu3ev.github.io/image-editor/**
|
|
116
|
+
|
|
117
|
+
## 🏗️ Architecture
|
|
118
|
+
|
|
119
|
+
The editor follows a modular architecture with specialized managers:
|
|
120
|
+
|
|
121
|
+
### Core Managers
|
|
122
|
+
- **`ImageManager`** - Image import/export, format handling, PDF generation
|
|
123
|
+
- **`CanvasManager`** - Canvas sizing, scaling, and viewport management
|
|
124
|
+
- **`HistoryManager`** - Undo/redo functionality with state persistence
|
|
125
|
+
- **`LayerManager`** - Object layering, z-index management, send to back/front
|
|
126
|
+
- **`BackgroundManager`** - Background colors, gradients, and images
|
|
127
|
+
- **`TransformManager`** - Object transformations, fitting, and scaling
|
|
128
|
+
|
|
129
|
+
### Utility Managers
|
|
130
|
+
- **`SelectionManager`** - Object selection and multi-selection handling
|
|
131
|
+
- **`ClipboardManager`** - Copy/paste with system clipboard integration
|
|
132
|
+
- **`GroupingManager`** - Object grouping and ungrouping operations
|
|
133
|
+
- **`ShapeManager`** - Shape creation (rectangles, circles, etc.)
|
|
134
|
+
- **`WorkerManager`** - Web Worker integration for heavy operations
|
|
135
|
+
- **`ErrorManager`** - Error handling and user notifications
|
|
136
|
+
|
|
137
|
+
### UI Components
|
|
138
|
+
- **`ToolbarManager`** - Dynamic toolbar with configurable actions
|
|
139
|
+
- **`CustomizedControls`** - Custom FabricJS controls and interactions
|
|
140
|
+
- **`InteractionBlocker`** - UI blocking during operations
|
|
141
|
+
|
|
142
|
+
## 📚 API Reference
|
|
143
|
+
|
|
144
|
+
### Editor Initialization
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
initEditor(containerId, options): Promise<ImageEditor>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Parameters:**
|
|
151
|
+
- `containerId` (string) - HTML container element ID
|
|
152
|
+
- `options` (CanvasOptions) - Configuration object
|
|
153
|
+
|
|
154
|
+
**Common Options:**
|
|
155
|
+
```javascript
|
|
156
|
+
{
|
|
157
|
+
// Canvas dimensions (internal resolution)
|
|
158
|
+
montageAreaWidth: 512,
|
|
159
|
+
montageAreaHeight: 512,
|
|
160
|
+
|
|
161
|
+
// Container dimensions (display size)
|
|
162
|
+
editorContainerWidth: '800px',
|
|
163
|
+
editorContainerHeight: '600px',
|
|
164
|
+
|
|
165
|
+
// Initial image
|
|
166
|
+
initialImage: {
|
|
167
|
+
source: 'path/to/image.jpg',
|
|
168
|
+
scale: 'image-contain'
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
// Content types for import
|
|
172
|
+
acceptContentTypes: ['image/png', 'image/jpeg', 'image/svg+xml'],
|
|
173
|
+
|
|
174
|
+
// Callback when ready
|
|
175
|
+
_onReadyCallback: (editor) => console.log('Ready!')
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Core Methods
|
|
53
180
|
|
|
54
|
-
|
|
181
|
+
#### Image Operations
|
|
182
|
+
```javascript
|
|
183
|
+
// Import image from file or URL
|
|
184
|
+
await editor.imageManager.importImage({
|
|
185
|
+
source: File | string,
|
|
186
|
+
scale?: 'image-contain' | 'image-cover' | 'scale-montage',
|
|
187
|
+
withoutSave?: boolean
|
|
188
|
+
})
|
|
55
189
|
|
|
56
|
-
|
|
190
|
+
// Export canvas as image
|
|
191
|
+
await editor.imageManager.exportCanvasAsImageFile({
|
|
192
|
+
fileName?: string,
|
|
193
|
+
contentType?: 'image/png' | 'image/jpeg' | 'image/svg+xml' | 'application/pdf',
|
|
194
|
+
exportAsBase64?: boolean,
|
|
195
|
+
exportAsBlob?: boolean
|
|
196
|
+
})
|
|
197
|
+
```
|
|
57
198
|
|
|
58
|
-
|
|
199
|
+
#### Background Management
|
|
200
|
+
```javascript
|
|
201
|
+
// Color background
|
|
202
|
+
editor.backgroundManager.setColorBackground({ color: '#ff0000' })
|
|
203
|
+
|
|
204
|
+
// Gradient background
|
|
205
|
+
editor.backgroundManager.setGradientBackground({
|
|
206
|
+
startColor: '#ff0000',
|
|
207
|
+
endColor: '#0000ff',
|
|
208
|
+
angle: 45,
|
|
209
|
+
startPosition?: 0,
|
|
210
|
+
endPosition?: 100
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
// Image background
|
|
214
|
+
await editor.backgroundManager.setImageBackground({ source: 'image.jpg' })
|
|
215
|
+
|
|
216
|
+
// Remove background
|
|
217
|
+
editor.backgroundManager.removeBackground()
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### Canvas Control
|
|
221
|
+
```javascript
|
|
222
|
+
// Scale montage area to fit image
|
|
223
|
+
editor.canvasManager.scaleMontageAreaToImage()
|
|
224
|
+
|
|
225
|
+
// Set canvas dimensions
|
|
226
|
+
editor.canvasManager.setCanvasBackstoreWidth(800)
|
|
227
|
+
editor.canvasManager.setCanvasBackstoreHeight(600)
|
|
228
|
+
|
|
229
|
+
// Zoom operations
|
|
230
|
+
editor.canvas.zoomToPoint(point, zoomLevel)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### Object Transformations
|
|
234
|
+
```javascript
|
|
235
|
+
// Fit object to montage area
|
|
236
|
+
editor.transformManager.fitObject({
|
|
237
|
+
type: 'contain' | 'cover',
|
|
238
|
+
fitAsOneObject?: boolean
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
// Reset object transformations
|
|
242
|
+
editor.transformManager.resetObject()
|
|
243
|
+
|
|
244
|
+
// Flip operations
|
|
245
|
+
editor.transformManager.flipObjectHorizontally()
|
|
246
|
+
editor.transformManager.flipObjectVertically()
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Layer Management
|
|
250
|
+
```javascript
|
|
251
|
+
// Layer operations
|
|
252
|
+
editor.layerManager.sendObjectToBack(object)
|
|
253
|
+
editor.layerManager.bringObjectToFront(object)
|
|
254
|
+
editor.layerManager.moveLayerUp(object)
|
|
255
|
+
editor.layerManager.moveLayerDown(object)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
#### History Control
|
|
259
|
+
```javascript
|
|
260
|
+
// Undo/Redo
|
|
261
|
+
editor.historyManager.undo()
|
|
262
|
+
editor.historyManager.redo()
|
|
263
|
+
|
|
264
|
+
// Save state
|
|
265
|
+
editor.historyManager.saveState()
|
|
266
|
+
|
|
267
|
+
// Load from JSON
|
|
268
|
+
editor.historyManager.loadStateFromFullState(jsonState)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## 🛠️ Development
|
|
272
|
+
|
|
273
|
+
### Building the Library
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
# Development mode with demo app and watch
|
|
277
|
+
npm run dev
|
|
278
|
+
|
|
279
|
+
# Development build to dev-build folder
|
|
280
|
+
npm run dev:build
|
|
281
|
+
|
|
282
|
+
# Production build
|
|
283
|
+
npm run build
|
|
284
|
+
|
|
285
|
+
# Build documentation
|
|
286
|
+
npm run build:docs
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Testing
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
# Run all tests
|
|
293
|
+
npm test
|
|
294
|
+
|
|
295
|
+
# Watch mode for development
|
|
296
|
+
npm run test:watch
|
|
297
|
+
|
|
298
|
+
# Coverage report
|
|
299
|
+
npm run test:coverage
|
|
300
|
+
|
|
301
|
+
# CI mode
|
|
302
|
+
npm run test:ci
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Project Structure
|
|
59
306
|
|
|
60
307
|
```
|
|
61
308
|
src/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
309
|
+
├── main.ts # Entry point, exports initEditor()
|
|
310
|
+
├── editor/
|
|
311
|
+
│ ├── index.ts # ImageEditor class
|
|
312
|
+
│ ├── defaults.ts # Default configuration
|
|
313
|
+
│ ├── constants.ts # Constants and limits
|
|
314
|
+
│ ├── listeners.ts # Event handling
|
|
315
|
+
│ ├── background-manager/ # Background functionality
|
|
316
|
+
│ ├── canvas-manager/ # Canvas operations
|
|
317
|
+
│ ├── clipboard-manager/ # Copy/paste operations
|
|
318
|
+
│ ├── error-manager/ # Error handling
|
|
319
|
+
│ ├── history-manager/ # Undo/redo system
|
|
320
|
+
│ ├── image-manager/ # Image import/export
|
|
321
|
+
│ ├── layer-manager/ # Layer management
|
|
322
|
+
│ ├── shape-manager/ # Shape creation
|
|
323
|
+
│ ├── transform-manager/ # Object transformations
|
|
324
|
+
│ ├── ui/ # UI components
|
|
325
|
+
│ └── types/ # TypeScript definitions
|
|
326
|
+
├── demo/ # Demo application
|
|
327
|
+
specs/ # Test specifications
|
|
328
|
+
docs/ # Documentation build
|
|
329
|
+
vite.config.*.js # Vite configurations
|
|
330
|
+
jest.config.ts # Jest test configuration
|
|
67
331
|
```
|
|
68
332
|
|
|
69
|
-
|
|
333
|
+
## 🎯 Planned Features
|
|
334
|
+
|
|
335
|
+
The following features are planned for future releases:
|
|
336
|
+
|
|
337
|
+
- **Drawing Mode** - Freehand drawing tools and brushes
|
|
338
|
+
- **Text Support** - Text layers with formatting options
|
|
339
|
+
- **Snap/Alignment** - Snap to edges, centers, and guides
|
|
340
|
+
- **Filters & Effects** - Image filters and visual effects
|
|
341
|
+
- **Shape Library** - Extended shape collection
|
|
342
|
+
- **Multi-language** - Internationalization support
|
|
343
|
+
|
|
344
|
+
## 🤝 Contributing
|
|
345
|
+
|
|
346
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
347
|
+
|
|
348
|
+
### Development Setup
|
|
349
|
+
```bash
|
|
350
|
+
git clone https://github.com/Anu3ev/image-editor.git
|
|
351
|
+
cd image-editor
|
|
352
|
+
npm install
|
|
353
|
+
npm run dev
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Running Tests
|
|
357
|
+
```bash
|
|
358
|
+
npm test # Run all tests
|
|
359
|
+
npm run test:watch # Development mode
|
|
360
|
+
npm run test:coverage # Coverage report
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## 🔧 Browser Support
|
|
364
|
+
|
|
365
|
+
- **Chrome** ≥ 88
|
|
366
|
+
- **Firefox** ≥ 85
|
|
367
|
+
- **Safari** ≥ 14
|
|
368
|
+
- **Edge** ≥ 88
|
|
369
|
+
|
|
370
|
+
All modern browsers with ES2016+ and Web Workers support.
|
|
371
|
+
|
|
372
|
+
## 📄 License
|
|
373
|
+
|
|
374
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
70
375
|
|
|
71
|
-
##
|
|
376
|
+
## 🙏 Acknowledgments
|
|
72
377
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
378
|
+
- Built with [FabricJS](https://fabricjs.com/) - Powerful HTML5 canvas library
|
|
379
|
+
- [Vite](https://vitejs.dev/) - Lightning fast build tool
|
|
380
|
+
- [TypeScript](https://www.typescriptlang.org/) - Type safety and developer experience
|
|
381
|
+
- [Jest](https://jestjs.io/) - Comprehensive testing framework
|
|
76
382
|
|
|
77
|
-
|
|
383
|
+
---
|
|
78
384
|
|
|
79
|
-
|
|
385
|
+
**Repository:** [github.com/Anu3ev/image-editor](https://github.com/Anu3ev/image-editor)
|
|
386
|
+
**NPM Package:** [@anu3ev/fabric-image-editor](https://www.npmjs.com/package/@anu3ev/fabric-image-editor)
|
|
387
|
+
**Live Demo:** [anu3ev.github.io/image-editor](https://anu3ev.github.io/image-editor/)
|