@anu3ev/fabric-image-editor 0.8.29 → 0.9.1
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/README.md +102 -0
- package/dist/main.js +1845 -1002
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ A modern, powerful browser-based image editor built with [FabricJS](https://fabr
|
|
|
10
10
|
|
|
11
11
|
### Core Editing
|
|
12
12
|
- **Montage Area** - Dedicated workspace with clipping region for precise cropping
|
|
13
|
+
- **Canvas & Image Cropping** - Interactive crop mode for montage resizing and raster image cropping
|
|
13
14
|
- **Multi-layer Support** - Layer management with ordering, visibility, and locking
|
|
14
15
|
- **History System** - Full undo/redo with state management
|
|
15
16
|
- **Rich Text Editing** - Text manager with typography controls, uppercase transforms, and history-aware updates
|
|
@@ -255,6 +256,76 @@ await editor.shapeManager.update({
|
|
|
255
256
|
|
|
256
257
|
All mutating `ShapeManager` methods save to history by default. Pass `withoutSave: true` for internal or batched updates.
|
|
257
258
|
|
|
259
|
+
### Cropping Canvas and Images
|
|
260
|
+
|
|
261
|
+
`CropManager` provides a transient crop mode for the montage area and raster images. The crop frame can be moved and resized with Fabric controls, constrained by editor size limits, and optionally allowed to extend beyond the source object.
|
|
262
|
+
|
|
263
|
+
```javascript
|
|
264
|
+
// Start crop mode for the montage area
|
|
265
|
+
editor.cropManager.startCanvasCrop({
|
|
266
|
+
aspectRatio: {
|
|
267
|
+
width: 1,
|
|
268
|
+
height: 1
|
|
269
|
+
},
|
|
270
|
+
allowFrameOverflow: true,
|
|
271
|
+
showGrid: true,
|
|
272
|
+
cancelOnSelectionClear: true
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
// Or start with an explicit crop frame size
|
|
276
|
+
editor.cropManager.startCanvasCrop({
|
|
277
|
+
size: {
|
|
278
|
+
width: 800,
|
|
279
|
+
height: 600
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
// Start crop mode for a raster image.
|
|
284
|
+
// If target is omitted, CropManager uses the active object.
|
|
285
|
+
editor.cropManager.startImageCrop({
|
|
286
|
+
target: imageObject,
|
|
287
|
+
aspectRatio: {
|
|
288
|
+
width: 16,
|
|
289
|
+
height: 9
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
// Update active crop mode from UI controls
|
|
294
|
+
editor.cropManager.setAspectRatio({
|
|
295
|
+
aspectRatio: {
|
|
296
|
+
width: 4,
|
|
297
|
+
height: 3
|
|
298
|
+
}
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
editor.cropManager.setSize({
|
|
302
|
+
size: {
|
|
303
|
+
width: 512,
|
|
304
|
+
height: 512
|
|
305
|
+
}
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
// Apply or cancel the active crop mode
|
|
309
|
+
const cropResult = editor.cropManager.apply()
|
|
310
|
+
editor.cropManager.cancel()
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
`startCanvasCrop()` resizes the montage area when applied. `startImageCrop()` updates the selected image so the visible content inside the crop frame stays visually in place. Crop mode is runtime-only: it is not serialized into history until `apply()` commits the result.
|
|
314
|
+
|
|
315
|
+
Crop behavior options:
|
|
316
|
+
- `allowFrameOverflow` defaults to `true` and lets the crop frame become larger than the source object.
|
|
317
|
+
- `showGrid` defaults to `true` and draws a composition grid inside the crop frame.
|
|
318
|
+
- `cancelOnSelectionClear` defaults to `true` and cancels crop mode when the crop frame loses focus.
|
|
319
|
+
|
|
320
|
+
`CropManager` public methods:
|
|
321
|
+
- `startCanvasCrop()` enters crop mode for the montage area.
|
|
322
|
+
- `startImageCrop()` enters crop mode for a `FabricImage` target or the active image object.
|
|
323
|
+
- `setAspectRatio()` updates the active crop frame by width/height ratio.
|
|
324
|
+
- `setSize()` updates the active crop frame by explicit dimensions.
|
|
325
|
+
- `getState()` returns the active crop state, including mode, frame, target, options, and result rect.
|
|
326
|
+
- `apply()` commits the active crop and saves the new state to history.
|
|
327
|
+
- `cancel()` exits crop mode without changing the montage area or image.
|
|
328
|
+
|
|
258
329
|
### Configuring Fonts
|
|
259
330
|
|
|
260
331
|
By default the editor ships with a curated Google Fonts collection (Latin + Cyrillic coverage).
|
|
@@ -314,6 +385,7 @@ The editor follows a modular architecture with specialized managers:
|
|
|
314
385
|
- **`TextManager`** - Text object creation, styling, uppercase handling, and history integration
|
|
315
386
|
- **`LayerManager`** - Object layering, z-index management, send to back/front
|
|
316
387
|
- **`BackgroundManager`** - Background colors, gradients, and images
|
|
388
|
+
- **`CropManager`** - Runtime crop mode for montage resizing and raster image cropping
|
|
317
389
|
- **`TransformManager`** - Object transformations, fitting, and scaling
|
|
318
390
|
- **`ZoomManager`** - Zoom limits, fit calculations, and smooth viewport centering
|
|
319
391
|
|
|
@@ -496,6 +568,35 @@ editor.shapeManager.remove({ target: shape })
|
|
|
496
568
|
- `setTextAlign()` changes horizontal (`left`, `center`, `right`, `justify`) and vertical alignment inside the shape bounds.
|
|
497
569
|
- `setRounding()` enables or updates corner rounding for roundable presets.
|
|
498
570
|
|
|
571
|
+
#### Crop Operations
|
|
572
|
+
```javascript
|
|
573
|
+
// Start montage crop mode
|
|
574
|
+
editor.cropManager.startCanvasCrop({
|
|
575
|
+
aspectRatio: {
|
|
576
|
+
width: 1,
|
|
577
|
+
height: 1
|
|
578
|
+
}
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
// Start image crop mode for an explicit target
|
|
582
|
+
editor.cropManager.startImageCrop({
|
|
583
|
+
target: imageObject,
|
|
584
|
+
size: {
|
|
585
|
+
width: 512,
|
|
586
|
+
height: 512
|
|
587
|
+
}
|
|
588
|
+
})
|
|
589
|
+
|
|
590
|
+
// Read the active crop state
|
|
591
|
+
const cropState = editor.cropManager.getState()
|
|
592
|
+
|
|
593
|
+
// Commit or discard the active crop mode
|
|
594
|
+
editor.cropManager.apply()
|
|
595
|
+
editor.cropManager.cancel()
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
Crop frame dimensions are clamped to editor limits. Pass `allowFrameOverflow: false` when the frame must stay inside the montage area or image bounds.
|
|
599
|
+
|
|
499
600
|
#### Alignment & Guides
|
|
500
601
|
- Objects snap to montage area edges/centers and nearby objects while dragging, with guides for matches and equal spacing.
|
|
501
602
|
- Hold `Ctrl` during drag to temporarily disable snapping (movement still follows the configured move step).
|
|
@@ -578,6 +679,7 @@ src/
|
|
|
578
679
|
│ ├── background-manager/ # Background functionality
|
|
579
680
|
│ ├── canvas-manager/ # Canvas operations
|
|
580
681
|
│ ├── clipboard-manager/ # Copy/paste operations
|
|
682
|
+
│ ├── crop-manager/ # Montage and image crop mode
|
|
581
683
|
│ ├── customized-controls/ # Custom FabricJS controls
|
|
582
684
|
│ ├── deletion-manager/ # Object deletion
|
|
583
685
|
│ ├── error-manager/ # Error handling
|