ding-image-editor 3.15.3 → 3.15.4
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/tui-image-editor.js +963 -18
- package/dist/tui-image-editor.min.js +3 -3
- package/package.json +1 -1
- package/src/js/component/freeDrawing.js +29 -10
- package/src/js/imageEditor.js +7 -0
package/package.json
CHANGED
@@ -27,8 +27,13 @@ class FreeDrawing extends Component {
|
|
27
27
|
this._handlers = {
|
28
28
|
mousedown: this._onFabricMouseDown.bind(this),
|
29
29
|
mousemove: this._onFabricMouseMove.bind(this),
|
30
|
-
mouseup: this.
|
30
|
+
mouseup: this._onMasikMouseUp.bind(this),
|
31
31
|
};
|
32
|
+
|
33
|
+
/**
|
34
|
+
* imageEditor instance
|
35
|
+
*/
|
36
|
+
this.imageEditor = null;
|
32
37
|
}
|
33
38
|
|
34
39
|
/**
|
@@ -37,10 +42,11 @@ class FreeDrawing extends Component {
|
|
37
42
|
*/
|
38
43
|
start(setting) {
|
39
44
|
console.log(setting);
|
40
|
-
if (setting?.
|
41
|
-
this.
|
45
|
+
if (setting?.mosaic) {
|
46
|
+
this.setMosaic(setting);
|
42
47
|
} else {
|
43
48
|
const canvas = this.getCanvas();
|
49
|
+
console.log(canvas);
|
44
50
|
canvas.isDrawingMode = true;
|
45
51
|
this.setBrush(setting);
|
46
52
|
}
|
@@ -73,9 +79,11 @@ class FreeDrawing extends Component {
|
|
73
79
|
}
|
74
80
|
|
75
81
|
/**
|
76
|
-
* Set
|
82
|
+
* Set mosaic
|
77
83
|
*/
|
78
|
-
|
84
|
+
setMosaic(setting) {
|
85
|
+
this.imageEditor = setting.imageEditor;
|
86
|
+
this.width = setting.width;
|
79
87
|
const canvas = this.getCanvas();
|
80
88
|
canvas.selection = false;
|
81
89
|
canvas.on('mouse:down', this._handlers.mousedown);
|
@@ -101,11 +109,15 @@ class FreeDrawing extends Component {
|
|
101
109
|
*/
|
102
110
|
_onFabricMouseMove(fEvent) {
|
103
111
|
const canvas = this.getCanvas();
|
104
|
-
const blockSize =
|
112
|
+
const blockSize = this.width;
|
113
|
+
const halfSize = this.width / 2;
|
114
|
+
// 直接获取e中的x,y有问题
|
105
115
|
const startPoints = canvas.getPointer(fEvent.e);
|
106
|
-
|
107
|
-
const
|
108
|
-
|
116
|
+
console.log(startPoints);
|
117
|
+
const startX = startPoints.x - halfSize;
|
118
|
+
console.log(startX);
|
119
|
+
const startY = startPoints.y - halfSize;
|
120
|
+
const ctx = canvas.contextContainer;
|
109
121
|
const imageData = ctx.getImageData(startX, startY, blockSize, blockSize);
|
110
122
|
const { data } = imageData;
|
111
123
|
let r = 0;
|
@@ -132,7 +144,14 @@ class FreeDrawing extends Component {
|
|
132
144
|
* MouseUp event handler on canvas
|
133
145
|
* @private
|
134
146
|
*/
|
135
|
-
|
147
|
+
async _onMasikMouseUp() {
|
148
|
+
const doms = document.getElementsByClassName('lower-canvas');
|
149
|
+
const [domCanvas] = doms;
|
150
|
+
const dataURL = domCanvas.toDataURL();
|
151
|
+
const response = await fetch(dataURL);
|
152
|
+
const blob = await response.blob();
|
153
|
+
const imgUrl = URL.createObjectURL(blob);
|
154
|
+
this.imageEditor.invoke('addImageObject', imgUrl);
|
136
155
|
const canvas = this.getCanvas();
|
137
156
|
canvas.off({
|
138
157
|
'mouse:move': this._handlers.mousemove,
|
package/src/js/imageEditor.js
CHANGED
@@ -734,6 +734,13 @@ class ImageEditor {
|
|
734
734
|
}
|
735
735
|
}
|
736
736
|
|
737
|
+
/**
|
738
|
+
* get canvas image center
|
739
|
+
*/
|
740
|
+
getCenterPoint() {
|
741
|
+
return this._graphics.canvasImage.getCenterPoint();
|
742
|
+
}
|
743
|
+
|
737
744
|
/**
|
738
745
|
* Load image from file
|
739
746
|
* @param {File} imgFile - Image file
|