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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ding-image-editor",
3
- "version": "3.15.3",
3
+ "version": "3.15.4",
4
4
  "description": "TOAST UI ImageEditor",
5
5
  "keywords": [
6
6
  "nhn",
@@ -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._onFabricMouseUp.bind(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?.masik) {
41
- this.startMasik();
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 masik
82
+ * Set mosaic
77
83
  */
78
- startMasik() {
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 = 20;
112
+ const blockSize = this.width;
113
+ const halfSize = this.width / 2;
114
+ // 直接获取e中的x,y有问题
105
115
  const startPoints = canvas.getPointer(fEvent.e);
106
- const startX = startPoints.x;
107
- const startY = startPoints.y;
108
- const ctx = canvas.getContext('2d');
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
- _onFabricMouseUp() {
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,
@@ -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