ding-image-editor 3.15.3 → 3.15.5

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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for TOAST UI Image Editor v3.15.3
1
+ // Type definitions for TOAST UI Image Editor v3.15.5
2
2
  // TypeScript Version: 3.2.2
3
3
 
4
4
  declare namespace tuiImageEditor {
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.5",
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,
@@ -488,6 +488,7 @@ class Text extends Component {
488
488
  * @private
489
489
  */
490
490
  _onFabricSelect(fEvent) {
491
+ console.log('ssssssss')
491
492
  this.isPrevEditing = true;
492
493
 
493
494
  this.setSelectedInfo(fEvent.target, true);
@@ -505,11 +506,11 @@ class Text extends Component {
505
506
  return;
506
507
  }
507
508
 
508
- if (this.isPrevEditing) {
509
- this.isPrevEditing = false;
509
+ // if (this.isPrevEditing) {
510
+ // this.isPrevEditing = false;
510
511
 
511
- return;
512
- }
512
+ // return;
513
+ // }
513
514
 
514
515
  this._fireAddText(fEvent);
515
516
  }
@@ -666,8 +666,8 @@ class Zoom extends Component {
666
666
  _addScrollBar() {
667
667
  const canvas = this.getCanvas();
668
668
 
669
- canvas.add(this._horizontalScroll);
670
- canvas.add(this._verticalScroll);
669
+ // canvas.add(this._horizontalScroll);
670
+ // canvas.add(this._verticalScroll);
671
671
 
672
672
  if (this.scrollBarTid) {
673
673
  clearTimeout(this.scrollBarTid);
@@ -132,6 +132,8 @@ class Graphics {
132
132
  */
133
133
  this._componentMap = {};
134
134
 
135
+ this._zoomLevel = 1;
136
+
135
137
  /**
136
138
  * fabric event handlers
137
139
  * @type {Object.<string, function>}
@@ -462,6 +464,7 @@ class Graphics {
462
464
  const zoom = this.getComponent(components.ZOOM);
463
465
 
464
466
  zoom.zoom({ x, y }, zoomLevel);
467
+ this._zoomLevel = zoomLevel
465
468
  }
466
469
 
467
470
  /**
@@ -584,9 +587,21 @@ class Graphics {
584
587
  canvasImage = this.canvasImage;
585
588
  }
586
589
 
587
- const { width, height } = canvasImage.getBoundingRect();
590
+ let { width, height } = canvasImage.getBoundingRect();
591
+
592
+ if(this._zoomLevel!==1){
593
+ width= width/this._zoomLevel
594
+ height= height/this._zoomLevel
595
+ }
596
+
597
+ console.log('adjustimage',width,height)
598
+
599
+ console.log('adjustmax',this.cssMaxWidth,this.cssMaxHeight)
600
+
601
+ // 修改了 _calcMaxDimension
588
602
  const maxDimension = this._calcMaxDimension(width, height);
589
603
 
604
+ console.log('maxDimension',maxDimension)
590
605
  this.setCanvasCssDimension({
591
606
  width: '100%',
592
607
  height: '100%', // Set height '' for IE9
@@ -1046,8 +1061,10 @@ class Graphics {
1046
1061
  _calcMaxDimension(width, height) {
1047
1062
  const wScaleFactor = this.cssMaxWidth / width;
1048
1063
  const hScaleFactor = this.cssMaxHeight / height;
1049
- let cssMaxWidth = Math.min(width, this.cssMaxWidth);
1050
- let cssMaxHeight = Math.min(height, this.cssMaxHeight);
1064
+ // let cssMaxWidth = Math.min(width, this.cssMaxWidth);
1065
+ // let cssMaxHeight = Math.min(height, this.cssMaxHeight);
1066
+ let cssMaxWidth = this.cssMaxWidth;
1067
+ let cssMaxHeight = this.cssMaxHeight;
1051
1068
 
1052
1069
  if (wScaleFactor < 1 && wScaleFactor < hScaleFactor) {
1053
1070
  cssMaxWidth = width * wScaleFactor;
@@ -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
@@ -965,6 +972,7 @@ class ImageEditor {
965
972
  * });
966
973
  */
967
974
  rotate(angle, isSilent) {
975
+ console.log('isSilent',isSilent)
968
976
  return this._rotate('rotate', angle, isSilent);
969
977
  }
970
978