@anu3ev/fabric-image-editor 0.1.47 → 0.1.49
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/dist/main.js +616 -726
- package/dist/{worker.js → worker.ts} +13 -3
- package/package.json +1 -1
- package/readme.md +33 -32
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-globals */
|
|
2
2
|
|
|
3
|
-
self.onmessage = async(e) => {
|
|
3
|
+
self.onmessage = async(e: MessageEvent): Promise<void> => {
|
|
4
4
|
const { action, payload, requestId } = e.data
|
|
5
5
|
|
|
6
6
|
try {
|
|
@@ -23,9 +23,14 @@ self.onmessage = async(e) => {
|
|
|
23
23
|
// рисуем изображение в offscreen
|
|
24
24
|
const offscreen = new OffscreenCanvas(width, height)
|
|
25
25
|
const ctx = offscreen.getContext('2d')
|
|
26
|
+
|
|
27
|
+
if (!ctx) {
|
|
28
|
+
throw new Error('Failed to get 2D context from OffscreenCanvas')
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
ctx.drawImage(imgBitmap, 0, 0, width, height)
|
|
27
32
|
|
|
28
|
-
// конвертим
|
|
33
|
+
// конвертим в blob
|
|
29
34
|
const resizedBlob = await offscreen.convertToBlob()
|
|
30
35
|
|
|
31
36
|
self.postMessage({ requestId, action, success: true, data: resizedBlob })
|
|
@@ -39,6 +44,11 @@ self.onmessage = async(e) => {
|
|
|
39
44
|
// рисуем изображение в offscreen
|
|
40
45
|
const off = new OffscreenCanvas(bitmap.width, bitmap.height)
|
|
41
46
|
const ctx = off.getContext('2d')
|
|
47
|
+
|
|
48
|
+
if (!ctx) {
|
|
49
|
+
throw new Error('Failed to get 2D context from OffscreenCanvas')
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
ctx.drawImage(bitmap, 0, 0, width, height)
|
|
43
53
|
|
|
44
54
|
// конвертируем в blob, а затем в dataURL
|
|
@@ -63,6 +73,6 @@ self.onmessage = async(e) => {
|
|
|
63
73
|
throw new Error(`Unknown action ${action}`)
|
|
64
74
|
}
|
|
65
75
|
} catch (err) {
|
|
66
|
-
self.postMessage({ requestId, action, success: false, error: err.message })
|
|
76
|
+
self.postMessage({ requestId, action, success: false, error: (err as Error).message })
|
|
67
77
|
}
|
|
68
78
|
}
|
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.49",
|
|
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,24 +1,25 @@
|
|
|
1
1
|
# Fabric Image Editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Fabric Image Editor is a browser-based image editor powered by [FabricJS](https://fabricjs.com/). It is published as the library `@anu3ev/fabric-image-editor` and can be embedded into any web page. The repository also contains a small demo application that showcases the library's capabilities.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- Layer, history and selection
|
|
9
|
-
- Object transformation (zoom,
|
|
10
|
-
-
|
|
11
|
-
-
|
|
7
|
+
- Montage area and clipping region for easy cropping
|
|
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
|
|
12
13
|
|
|
13
14
|
## Installation
|
|
14
15
|
|
|
15
|
-
```
|
|
16
|
+
```bash
|
|
16
17
|
npm install @anu3ev/fabric-image-editor
|
|
17
|
-
|
|
18
|
+
````
|
|
18
19
|
|
|
19
|
-
##
|
|
20
|
+
## Quick Start
|
|
20
21
|
|
|
21
|
-
Create a
|
|
22
|
+
Create a container in your HTML and initialize the editor:
|
|
22
23
|
|
|
23
24
|
```html
|
|
24
25
|
<div id="editor"></div>
|
|
@@ -29,49 +30,49 @@ import initEditor from '@anu3ev/fabric-image-editor'
|
|
|
29
30
|
|
|
30
31
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
31
32
|
const editor = await initEditor('editor', {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
montageAreaWidth: 512,
|
|
34
|
+
montageAreaHeight: 512,
|
|
35
|
+
editorContainerWidth: '100%',
|
|
36
|
+
editorContainerHeight: '100vh'
|
|
36
37
|
})
|
|
37
38
|
|
|
38
|
-
//
|
|
39
|
+
// work with the `editor` instance...
|
|
39
40
|
})
|
|
40
41
|
```
|
|
41
42
|
|
|
42
|
-
## Running the
|
|
43
|
+
## Running the Demo
|
|
43
44
|
|
|
44
|
-
Clone this repository and install
|
|
45
|
+
Clone this repository and install dependencies:
|
|
45
46
|
|
|
46
|
-
```
|
|
47
|
+
```bash
|
|
47
48
|
npm install
|
|
48
49
|
npm run dev
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
A Vite dev server will start and open the demo page from `index.html`.
|
|
52
53
|
|
|
53
|
-
## Building the
|
|
54
|
+
## Building the Library
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
Use `npm run build` to create the library build in the `dist/` directory. The output is an ES module that can be published to npm or used directly in other projects.
|
|
56
57
|
|
|
57
|
-
##
|
|
58
|
+
## Project Structure
|
|
58
59
|
|
|
59
60
|
```
|
|
60
61
|
src/
|
|
61
|
-
main.ts
|
|
62
|
-
demo/
|
|
63
|
-
editor/
|
|
64
|
-
index.html
|
|
65
|
-
vite.config.js
|
|
62
|
+
main.ts – entry point exporting `initEditor`
|
|
63
|
+
demo/ – demo scripts and styles
|
|
64
|
+
editor/ – ImageEditor class and feature managers
|
|
65
|
+
index.html – demo page
|
|
66
|
+
vite.config.js – Vite configuration
|
|
66
67
|
```
|
|
67
68
|
|
|
68
|
-
The `editor` directory
|
|
69
|
+
The `editor` directory is divided into managers for canvas manipulation, image handling, history, layers, shapes, clipboard and more. Look inside these files to understand how each feature works.
|
|
69
70
|
|
|
70
|
-
## Further
|
|
71
|
+
## Further Reading
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
* Explore the manager classes under `src/editor` for implementation details
|
|
74
|
+
* Check TODO comments in the code for planned features and improvements
|
|
75
|
+
* Familiarize yourself with FabricJS to extend the editor
|
|
75
76
|
|
|
76
77
|
## License
|
|
77
78
|
|