react-design-editor 0.0.54 → 0.0.55

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.
@@ -10,6 +10,10 @@ declare class AlignmentHandler {
10
10
  * Align center at selection
11
11
  */
12
12
  center: () => void;
13
+ /**
14
+ * Align center at selection
15
+ */
16
+ middle: () => void;
13
17
  /**
14
18
  * Align right at selection
15
19
  */
@@ -28,7 +28,23 @@ class AlignmentHandler {
28
28
  const activeSelection = activeObject;
29
29
  activeSelection.forEachObject(obj => {
30
30
  obj.set({
31
- left: 0 - ((obj.width * obj.scaleX) / 2),
31
+ left: 0 - (obj.width * obj.scaleX) / 2,
32
+ });
33
+ obj.setCoords();
34
+ this.handler.canvas.renderAll();
35
+ });
36
+ }
37
+ };
38
+ /**
39
+ * Align center at selection
40
+ */
41
+ this.middle = () => {
42
+ const activeObject = this.handler.canvas.getActiveObject();
43
+ if (activeObject && activeObject.type === 'activeSelection') {
44
+ const activeSelection = activeObject;
45
+ activeSelection.forEachObject(obj => {
46
+ obj.set({
47
+ top: 0 - (obj.width * obj.scaleX) / 2,
32
48
  });
33
49
  obj.setCoords();
34
50
  this.handler.canvas.renderAll();
@@ -42,10 +58,10 @@ class AlignmentHandler {
42
58
  const activeObject = this.handler.canvas.getActiveObject();
43
59
  if (activeObject && activeObject.type === 'activeSelection') {
44
60
  const activeSelection = activeObject;
45
- const activeObjectLeft = (activeObject.width / 2);
61
+ const activeObjectLeft = activeObject.width / 2;
46
62
  activeSelection.forEachObject(obj => {
47
63
  obj.set({
48
- left: activeObjectLeft - (obj.width * obj.scaleX),
64
+ left: activeObjectLeft - obj.width * obj.scaleX,
49
65
  });
50
66
  obj.setCoords();
51
67
  this.handler.canvas.renderAll();
@@ -358,6 +358,7 @@ class Handler {
358
358
  obj.set('src', source);
359
359
  resolve(obj.setSrc(source, () => this.canvas.renderAll(), {
360
360
  dirty: true,
361
+ crossOrigin: "anonymous"
361
362
  }));
362
363
  }
363
364
  });
@@ -1476,8 +1477,13 @@ class Handler {
1476
1477
  this.saveCanvasImage = (option = { name: 'New Image', format: 'png', quality: 1 }) => {
1477
1478
  // If it's zoomed out/in, the container will also include in the image
1478
1479
  // hence need to reset the zoom level.
1479
- this.zoomHandler.zoomOneToOne();
1480
- const { left, top, width, height } = this.workarea;
1480
+ let { left, top, width, height, scaleX, scaleY } = this.workarea;
1481
+ width = Math.ceil(width * scaleX);
1482
+ height = Math.ceil(height * scaleY);
1483
+ // cachedVT is used to reset the viewportTransform after the image is saved.
1484
+ const cachedVT = this.canvas.viewportTransform;
1485
+ // reset the viewportTransform to default (no zoom)
1486
+ this.canvas.viewportTransform = [1, 0, 0, 1, 0, 0];
1481
1487
  const dataUrl = this.canvas.toDataURL({
1482
1488
  ...option,
1483
1489
  left,
@@ -1494,6 +1500,8 @@ class Handler {
1494
1500
  anchorEl.click();
1495
1501
  anchorEl.remove();
1496
1502
  }
1503
+ // reset the viewportTransform to previous value.
1504
+ this.canvas.viewportTransform = cachedVT;
1497
1505
  };
1498
1506
  /**
1499
1507
  * Sets "angle" of an instance with centered rotation
@@ -274,7 +274,7 @@ class WorkareaHandler {
274
274
  this.handler.zoomHandler.zoomToPoint(new fabric_1.fabric.Point(center.left, center.top), zoom);
275
275
  canvas.renderAll();
276
276
  resolve(workarea);
277
- });
277
+ }, { crossOrigin: 'anonymous' });
278
278
  });
279
279
  };
280
280
  if (!source) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-design-editor",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "description": "Design Editor Tools with React.js + ant.design + fabric.js",
5
5
  "main": "dist/react-design-editor.min.js",
6
6
  "typings": "lib/index.d.ts",