react-design-editor 0.0.37 → 0.0.41

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.
Files changed (99) hide show
  1. package/dist/react-design-editor.js +773 -726
  2. package/dist/react-design-editor.min.js +1 -1
  3. package/lib/Canvas.d.ts +18 -0
  4. package/lib/Canvas.js +172 -0
  5. package/lib/CanvasObject.d.ts +10 -0
  6. package/lib/CanvasObject.js +96 -0
  7. package/lib/constants/code.d.ts +19 -0
  8. package/lib/constants/code.js +22 -0
  9. package/lib/constants/defaults.d.ts +38 -0
  10. package/lib/constants/defaults.js +69 -0
  11. package/lib/constants/index.d.ts +3 -0
  12. package/lib/constants/index.js +26 -0
  13. package/lib/handlers/AlignmentHandler.d.ts +18 -0
  14. package/lib/handlers/AlignmentHandler.js +58 -0
  15. package/lib/handlers/AnimationHandler.d.ts +50 -0
  16. package/lib/handlers/AnimationHandler.js +323 -0
  17. package/lib/handlers/ChartHandler.d.ts +8 -0
  18. package/lib/handlers/ChartHandler.js +8 -0
  19. package/lib/handlers/ContextmenuHandler.d.ts +28 -0
  20. package/lib/handlers/ContextmenuHandler.js +65 -0
  21. package/lib/handlers/CropHandler.d.ts +43 -0
  22. package/lib/handlers/CropHandler.js +261 -0
  23. package/lib/handlers/CustomHandler.d.ts +7 -0
  24. package/lib/handlers/CustomHandler.js +10 -0
  25. package/lib/handlers/DrawingHandler.d.ts +28 -0
  26. package/lib/handlers/DrawingHandler.js +318 -0
  27. package/lib/handlers/ElementHandler.d.ts +80 -0
  28. package/lib/handlers/ElementHandler.js +154 -0
  29. package/lib/handlers/EventHandler.d.ts +170 -0
  30. package/lib/handlers/EventHandler.js +880 -0
  31. package/lib/handlers/FiberHandler.d.ts +6 -0
  32. package/lib/handlers/FiberHandler.js +23 -0
  33. package/lib/handlers/GridHandler.d.ts +19 -0
  34. package/lib/handlers/GridHandler.js +77 -0
  35. package/lib/handlers/GuidelineHandler.d.ts +61 -0
  36. package/lib/handlers/GuidelineHandler.js +315 -0
  37. package/lib/handlers/Handler.d.ts +622 -0
  38. package/lib/handlers/Handler.js +1640 -0
  39. package/lib/handlers/ImageHandler.d.ts +307 -0
  40. package/lib/handlers/ImageHandler.js +529 -0
  41. package/lib/handlers/InteractionHandler.d.ts +45 -0
  42. package/lib/handlers/InteractionHandler.js +164 -0
  43. package/lib/handlers/LinkHandler.d.ts +115 -0
  44. package/lib/handlers/LinkHandler.js +247 -0
  45. package/lib/handlers/NodeHandler.d.ts +50 -0
  46. package/lib/handlers/NodeHandler.js +274 -0
  47. package/lib/handlers/PortHandler.d.ts +22 -0
  48. package/lib/handlers/PortHandler.js +179 -0
  49. package/lib/handlers/ShortcutHandler.d.ts +119 -0
  50. package/lib/handlers/ShortcutHandler.js +151 -0
  51. package/lib/handlers/TooltipHandler.d.ts +33 -0
  52. package/lib/handlers/TooltipHandler.js +91 -0
  53. package/lib/handlers/TransactionHandler.d.ts +59 -0
  54. package/lib/handlers/TransactionHandler.js +137 -0
  55. package/lib/handlers/WorkareaHandler.d.ts +43 -0
  56. package/lib/handlers/WorkareaHandler.js +354 -0
  57. package/lib/handlers/ZoomHandler.d.ts +48 -0
  58. package/lib/handlers/ZoomHandler.js +143 -0
  59. package/lib/handlers/index.d.ts +23 -0
  60. package/lib/handlers/index.js +48 -0
  61. package/lib/index.d.ts +6 -0
  62. package/lib/index.js +20 -0
  63. package/lib/objects/Arrow.d.ts +2 -0
  64. package/lib/objects/Arrow.js +40 -0
  65. package/lib/objects/Chart.d.ts +10 -0
  66. package/lib/objects/Chart.js +124 -0
  67. package/lib/objects/CirclePort.d.ts +2 -0
  68. package/lib/objects/CirclePort.js +28 -0
  69. package/lib/objects/Cube.d.ts +5 -0
  70. package/lib/objects/Cube.js +71 -0
  71. package/lib/objects/CurvedLink.d.ts +2 -0
  72. package/lib/objects/CurvedLink.js +51 -0
  73. package/lib/objects/Element.d.ts +13 -0
  74. package/lib/objects/Element.js +84 -0
  75. package/lib/objects/Gif.d.ts +3 -0
  76. package/lib/objects/Gif.js +41 -0
  77. package/lib/objects/Iframe.d.ts +9 -0
  78. package/lib/objects/Iframe.js +70 -0
  79. package/lib/objects/Line.d.ts +2 -0
  80. package/lib/objects/Line.js +24 -0
  81. package/lib/objects/Link.d.ts +15 -0
  82. package/lib/objects/Link.js +106 -0
  83. package/lib/objects/Node.d.ts +59 -0
  84. package/lib/objects/Node.js +271 -0
  85. package/lib/objects/OrthogonalLink.d.ts +2 -0
  86. package/lib/objects/OrthogonalLink.js +54 -0
  87. package/lib/objects/Port.d.ts +12 -0
  88. package/lib/objects/Port.js +28 -0
  89. package/lib/objects/Svg.d.ts +8 -0
  90. package/lib/objects/Svg.js +77 -0
  91. package/lib/objects/Video.d.ts +14 -0
  92. package/lib/objects/Video.js +120 -0
  93. package/lib/objects/index.d.ts +15 -0
  94. package/lib/objects/index.js +32 -0
  95. package/lib/utils/ObjectUtil.d.ts +407 -0
  96. package/lib/utils/ObjectUtil.js +13 -0
  97. package/lib/utils/index.d.ts +1 -0
  98. package/lib/utils/index.js +13 -0
  99. package/package.json +1 -1
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fabric_1 = require("fabric");
4
+ class CropHandler {
5
+ constructor(handler) {
6
+ /**
7
+ * Validate crop type
8
+ *
9
+ * @returns
10
+ */
11
+ this.validType = () => {
12
+ const activeObject = this.handler.canvas.getActiveObject();
13
+ if (!activeObject) {
14
+ return false;
15
+ }
16
+ if (activeObject.type === 'image') {
17
+ return true;
18
+ }
19
+ return false;
20
+ };
21
+ /**
22
+ * Start crop image
23
+ *
24
+ */
25
+ this.start = () => {
26
+ if (this.validType()) {
27
+ this.handler.interactionMode = 'crop';
28
+ this.cropObject = this.handler.canvas.getActiveObject();
29
+ const { left, top } = this.cropObject;
30
+ this.cropRect = new fabric_1.fabric.Rect({
31
+ width: this.cropObject.width,
32
+ height: this.cropObject.height,
33
+ scaleX: this.cropObject.scaleX,
34
+ scaleY: this.cropObject.scaleY,
35
+ originX: 'left',
36
+ originY: 'top',
37
+ left,
38
+ top,
39
+ hasRotatingPoint: false,
40
+ fill: 'rgba(0, 0, 0, 0.2)',
41
+ });
42
+ this.handler.canvas.add(this.cropRect);
43
+ this.handler.canvas.setActiveObject(this.cropRect);
44
+ this.cropObject.selectable = false;
45
+ this.cropObject.evented = false;
46
+ this.handler.canvas.renderAll();
47
+ }
48
+ };
49
+ /**
50
+ * Finish crop image
51
+ *
52
+ */
53
+ this.finish = () => {
54
+ const { left, top, width, height, scaleX, scaleY } = this.cropRect;
55
+ const croppedImg = this.cropObject.toDataURL({
56
+ left: left - this.cropObject.left,
57
+ top: top - this.cropObject.top,
58
+ width: width * scaleX,
59
+ height: height * scaleY,
60
+ });
61
+ this.handler.setImage(this.cropObject, croppedImg);
62
+ this.cancel();
63
+ };
64
+ /**
65
+ * Cancel crop
66
+ *
67
+ */
68
+ this.cancel = () => {
69
+ this.handler.interactionMode = 'selection';
70
+ this.cropObject.selectable = true;
71
+ this.cropObject.evented = true;
72
+ this.handler.canvas.setActiveObject(this.cropObject);
73
+ this.handler.canvas.remove(this.cropRect);
74
+ this.cropRect = null;
75
+ this.cropObject = null;
76
+ this.handler.canvas.renderAll();
77
+ };
78
+ /**
79
+ * Resize crop
80
+ *
81
+ * @param {FabricEvent} opt
82
+ */
83
+ this.resize = (opt) => {
84
+ const { target, transform: { original, corner }, } = opt;
85
+ const { left, top, width, height, scaleX, scaleY } = target;
86
+ const { left: cropLeft, top: cropTop, width: cropWidth, height: cropHeight, scaleX: cropScaleX, scaleY: cropScaleY, } = this.cropObject;
87
+ if (corner === 'tl') {
88
+ if (Math.round(cropLeft) > Math.round(left)) {
89
+ // left
90
+ const originRight = Math.round(cropLeft + cropWidth);
91
+ const targetRight = Math.round(target.getBoundingRect().left + target.getBoundingRect().width);
92
+ const diffRightRatio = 1 - (originRight - targetRight) / cropWidth;
93
+ target.set({
94
+ left: cropLeft,
95
+ scaleX: diffRightRatio > 1 ? 1 : diffRightRatio,
96
+ });
97
+ }
98
+ if (Math.round(cropTop) > Math.round(top)) {
99
+ // top
100
+ const originBottom = Math.round(cropTop + cropHeight);
101
+ const targetBottom = Math.round(target.getBoundingRect().top + target.getBoundingRect().height);
102
+ const diffBottomRatio = 1 - (originBottom - targetBottom) / cropHeight;
103
+ target.set({
104
+ top: cropTop,
105
+ scaleY: diffBottomRatio > 1 ? 1 : diffBottomRatio,
106
+ });
107
+ }
108
+ }
109
+ else if (corner === 'bl') {
110
+ if (Math.round(cropLeft) > Math.round(left)) {
111
+ // left
112
+ const originRight = Math.round(cropLeft + cropWidth);
113
+ const targetRight = Math.round(target.getBoundingRect().left + target.getBoundingRect().width);
114
+ const diffRightRatio = 1 - (originRight - targetRight) / cropWidth;
115
+ target.set({
116
+ left: cropLeft,
117
+ scaleX: diffRightRatio > 1 ? 1 : diffRightRatio,
118
+ });
119
+ }
120
+ if (Math.round(cropTop + cropHeight * cropScaleY) < Math.round(top + height * scaleY)) {
121
+ // bottom
122
+ const diffTopRatio = 1 - (original.top - cropTop) / cropHeight;
123
+ target.set({
124
+ top: original.top,
125
+ scaleY: diffTopRatio > 1 ? 1 : diffTopRatio,
126
+ });
127
+ }
128
+ }
129
+ else if (corner === 'tr') {
130
+ if (Math.round(cropLeft + cropWidth * cropScaleX) < Math.round(left + width * scaleX)) {
131
+ // right
132
+ const diffLeftRatio = 1 - (original.left - cropLeft) / cropWidth;
133
+ target.set({
134
+ left: original.left,
135
+ scaleX: diffLeftRatio > 1 ? 1 : diffLeftRatio,
136
+ });
137
+ }
138
+ if (Math.round(cropTop) > Math.round(top)) {
139
+ // top
140
+ const originBottom = Math.round(cropTop + cropHeight);
141
+ const targetBottom = Math.round(target.getBoundingRect().top + target.getBoundingRect().height);
142
+ const diffBottomRatio = 1 - (originBottom - targetBottom) / cropHeight;
143
+ target.set({
144
+ top: cropTop,
145
+ scaleY: diffBottomRatio > 1 ? 1 : diffBottomRatio,
146
+ });
147
+ }
148
+ }
149
+ else if (corner === 'br') {
150
+ if (Math.round(cropLeft + cropWidth * cropScaleX) < Math.round(left + width * scaleX)) {
151
+ // right
152
+ const diffLeftRatio = 1 - (original.left - cropLeft) / cropWidth;
153
+ target.set({
154
+ left: original.left,
155
+ scaleX: diffLeftRatio > 1 ? 1 : diffLeftRatio,
156
+ });
157
+ }
158
+ if (Math.round(cropTop + cropHeight * cropScaleY) < Math.round(top + height * scaleY)) {
159
+ // bottom
160
+ const diffTopRatio = 1 - (original.top - cropTop) / cropHeight;
161
+ target.set({
162
+ top: original.top,
163
+ scaleY: diffTopRatio > 1 ? 1 : diffTopRatio,
164
+ });
165
+ }
166
+ }
167
+ else if (corner === 'ml') {
168
+ if (Math.round(cropLeft) > Math.round(left)) {
169
+ // left
170
+ const originRight = Math.round(cropLeft + cropWidth);
171
+ const targetRight = Math.round(target.getBoundingRect().left + target.getBoundingRect().width);
172
+ const diffRightRatio = 1 - (originRight - targetRight) / cropWidth;
173
+ target.set({
174
+ left: cropLeft,
175
+ scaleX: diffRightRatio > 1 ? 1 : diffRightRatio,
176
+ });
177
+ }
178
+ }
179
+ else if (corner === 'mt') {
180
+ if (Math.round(cropTop) > Math.round(top)) {
181
+ // top
182
+ const originBottom = Math.round(cropTop + cropHeight);
183
+ const targetBottom = Math.round(target.getBoundingRect().top + target.getBoundingRect().height);
184
+ const diffBottomRatio = 1 - (originBottom - targetBottom) / cropHeight;
185
+ target.set({
186
+ top: cropTop,
187
+ scaleY: diffBottomRatio > 1 ? 1 : diffBottomRatio,
188
+ });
189
+ }
190
+ }
191
+ else if (corner === 'mb') {
192
+ if (Math.round(cropTop + cropHeight * cropScaleY) < Math.round(top + height * scaleY)) {
193
+ // bottom
194
+ const diffTopRatio = 1 - (original.top - cropTop) / cropHeight;
195
+ target.set({
196
+ top: original.top,
197
+ scaleY: diffTopRatio > 1 ? 1 : diffTopRatio,
198
+ });
199
+ }
200
+ }
201
+ else if (corner === 'mr') {
202
+ if (Math.round(cropLeft + cropWidth * cropScaleX) < Math.round(left + width * scaleX)) {
203
+ // right
204
+ const diffLeftRatio = 1 - (original.left - cropLeft) / cropWidth;
205
+ target.set({
206
+ left: original.left,
207
+ scaleX: diffLeftRatio > 1 ? 1 : diffLeftRatio,
208
+ });
209
+ }
210
+ }
211
+ };
212
+ /**
213
+ * Resize crop
214
+ *
215
+ * @param {FabricEvent} opt
216
+ */
217
+ this.moving = (opt) => {
218
+ const { target } = opt;
219
+ const { left, top, width, height, scaleX, scaleY } = target;
220
+ const { left: cropLeft, top: cropTop, width: cropWidth, height: cropHeight, } = this.cropObject.getBoundingRect();
221
+ const movedTop = () => {
222
+ if (Math.round(cropTop) >= Math.round(top)) {
223
+ target.set({
224
+ top: cropTop,
225
+ });
226
+ }
227
+ else if (Math.round(cropTop + cropHeight) <= Math.round(top + height * scaleY)) {
228
+ target.set({
229
+ top: cropTop + cropHeight - height * scaleY,
230
+ });
231
+ }
232
+ };
233
+ if (Math.round(cropLeft) >= Math.round(left)) {
234
+ target.set({
235
+ left: Math.max(left, cropLeft),
236
+ });
237
+ movedTop();
238
+ }
239
+ else if (Math.round(cropLeft + cropWidth) <= Math.round(left + width * scaleX)) {
240
+ target.set({
241
+ left: cropLeft + cropWidth - width * scaleX,
242
+ });
243
+ movedTop();
244
+ }
245
+ else if (Math.round(cropTop) >= Math.round(top)) {
246
+ target.set({
247
+ top: cropTop,
248
+ });
249
+ }
250
+ else if (Math.round(cropTop + cropHeight) <= Math.round(top + height * scaleY)) {
251
+ target.set({
252
+ top: cropTop + cropHeight - height * scaleY,
253
+ });
254
+ }
255
+ };
256
+ this.handler = handler;
257
+ this.cropRect = null;
258
+ this.cropObject = null;
259
+ }
260
+ }
261
+ exports.default = CropHandler;
@@ -0,0 +1,7 @@
1
+ import { Handler } from '.';
2
+ declare class CustomHandler {
3
+ handler: Handler;
4
+ constructor(handler: Handler);
5
+ protected initialze(): void;
6
+ }
7
+ export default CustomHandler;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CustomHandler {
4
+ constructor(handler) {
5
+ this.handler = handler;
6
+ this.initialze();
7
+ }
8
+ initialze() { }
9
+ }
10
+ exports.default = CustomHandler;
@@ -0,0 +1,28 @@
1
+ import { fabric } from 'fabric';
2
+ import { FabricEvent, FabricObject } from '../utils';
3
+ import Handler from './Handler';
4
+ declare class DrawingHandler {
5
+ handler: Handler;
6
+ constructor(handler: Handler);
7
+ polygon: {
8
+ init: () => void;
9
+ finish: () => void;
10
+ addPoint: (opt: FabricEvent) => void;
11
+ generate: (pointArray: FabricObject<fabric.Circle>[]) => void;
12
+ };
13
+ line: {
14
+ init: () => void;
15
+ finish: () => void;
16
+ addPoint: (opt: FabricEvent) => void;
17
+ generate: (opt: FabricEvent) => void;
18
+ };
19
+ arrow: {
20
+ init: () => void;
21
+ finish: () => void;
22
+ addPoint: (opt: FabricEvent) => void;
23
+ generate: (opt: FabricEvent) => void;
24
+ };
25
+ orthogonal: {};
26
+ curve: {};
27
+ }
28
+ export default DrawingHandler;
@@ -0,0 +1,318 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fabric_1 = require("fabric");
4
+ const uuidv4_1 = require("uuidv4");
5
+ const objects_1 = require("../objects");
6
+ class DrawingHandler {
7
+ constructor(handler) {
8
+ this.polygon = {
9
+ init: () => {
10
+ this.handler.interactionHandler.drawing('polygon');
11
+ this.handler.pointArray = [];
12
+ this.handler.lineArray = [];
13
+ this.handler.activeLine = null;
14
+ this.handler.activeShape = null;
15
+ },
16
+ finish: () => {
17
+ this.handler.pointArray.forEach(point => {
18
+ this.handler.canvas.remove(point);
19
+ });
20
+ this.handler.lineArray.forEach(line => {
21
+ this.handler.canvas.remove(line);
22
+ });
23
+ this.handler.canvas.remove(this.handler.activeLine);
24
+ this.handler.canvas.remove(this.handler.activeShape);
25
+ this.handler.pointArray = [];
26
+ this.handler.lineArray = [];
27
+ this.handler.activeLine = null;
28
+ this.handler.activeShape = null;
29
+ this.handler.canvas.renderAll();
30
+ this.handler.interactionHandler.selection();
31
+ },
32
+ addPoint: (opt) => {
33
+ const { e, absolutePointer } = opt;
34
+ const { x, y } = absolutePointer;
35
+ const circle = new fabric_1.fabric.Circle({
36
+ radius: 1,
37
+ fill: '#ffffff',
38
+ stroke: '#333333',
39
+ strokeWidth: 0.5,
40
+ left: x,
41
+ top: y,
42
+ selectable: false,
43
+ hasBorders: false,
44
+ hasControls: false,
45
+ originX: 'center',
46
+ originY: 'center',
47
+ hoverCursor: 'pointer',
48
+ });
49
+ circle.set({
50
+ id: uuidv4_1.uuid(),
51
+ });
52
+ if (!this.handler.pointArray.length) {
53
+ circle.set({
54
+ fill: 'red',
55
+ });
56
+ }
57
+ const points = [x, y, x, y];
58
+ const line = new fabric_1.fabric.Line(points, {
59
+ strokeWidth: 1,
60
+ fill: '#999999',
61
+ stroke: '#999999',
62
+ originX: 'center',
63
+ originY: 'center',
64
+ selectable: false,
65
+ hasBorders: false,
66
+ hasControls: false,
67
+ evented: false,
68
+ });
69
+ line.set({
70
+ class: 'line',
71
+ });
72
+ if (this.handler.activeShape) {
73
+ const position = this.handler.canvas.getPointer(e);
74
+ const activeShapePoints = this.handler.activeShape.get('points');
75
+ activeShapePoints.push({
76
+ x: position.x,
77
+ y: position.y,
78
+ });
79
+ const polygon = new fabric_1.fabric.Polygon(activeShapePoints, {
80
+ stroke: '#333333',
81
+ strokeWidth: 1,
82
+ fill: '#cccccc',
83
+ opacity: 0.1,
84
+ selectable: false,
85
+ hasBorders: false,
86
+ hasControls: false,
87
+ evented: false,
88
+ });
89
+ this.handler.canvas.remove(this.handler.activeShape);
90
+ this.handler.canvas.add(polygon);
91
+ this.handler.activeShape = polygon;
92
+ this.handler.canvas.renderAll();
93
+ }
94
+ else {
95
+ const polyPoint = [{ x, y }];
96
+ const polygon = new fabric_1.fabric.Polygon(polyPoint, {
97
+ stroke: '#333333',
98
+ strokeWidth: 1,
99
+ fill: '#cccccc',
100
+ opacity: 0.1,
101
+ selectable: false,
102
+ hasBorders: false,
103
+ hasControls: false,
104
+ evented: false,
105
+ });
106
+ this.handler.activeShape = polygon;
107
+ this.handler.canvas.add(polygon);
108
+ }
109
+ this.handler.activeLine = line;
110
+ this.handler.pointArray.push(circle);
111
+ this.handler.lineArray.push(line);
112
+ this.handler.canvas.add(line);
113
+ this.handler.canvas.add(circle);
114
+ },
115
+ generate: (pointArray) => {
116
+ const points = [];
117
+ const id = uuidv4_1.uuid();
118
+ pointArray.forEach(point => {
119
+ points.push({
120
+ x: point.left,
121
+ y: point.top,
122
+ });
123
+ this.handler.canvas.remove(point);
124
+ });
125
+ this.handler.lineArray.forEach(line => {
126
+ this.handler.canvas.remove(line);
127
+ });
128
+ this.handler.canvas.remove(this.handler.activeShape).remove(this.handler.activeLine);
129
+ const option = {
130
+ id,
131
+ points,
132
+ type: 'polygon',
133
+ stroke: 'rgba(0, 0, 0, 1)',
134
+ strokeWidth: 1,
135
+ fill: 'rgba(0, 0, 0, 0.25)',
136
+ opacity: 1,
137
+ objectCaching: !this.handler.editable,
138
+ name: 'New polygon',
139
+ superType: 'drawing',
140
+ };
141
+ this.handler.add(option, false);
142
+ this.handler.pointArray = [];
143
+ this.handler.activeLine = null;
144
+ this.handler.activeShape = null;
145
+ this.handler.interactionHandler.selection();
146
+ },
147
+ };
148
+ this.line = {
149
+ init: () => {
150
+ this.handler.interactionHandler.drawing('line');
151
+ this.handler.pointArray = [];
152
+ this.handler.activeLine = null;
153
+ },
154
+ finish: () => {
155
+ this.handler.pointArray.forEach(point => {
156
+ this.handler.canvas.remove(point);
157
+ });
158
+ this.handler.canvas.remove(this.handler.activeLine);
159
+ this.handler.pointArray = [];
160
+ this.handler.activeLine = null;
161
+ this.handler.canvas.renderAll();
162
+ this.handler.interactionHandler.selection();
163
+ },
164
+ addPoint: (opt) => {
165
+ const { absolutePointer } = opt;
166
+ const { x, y } = absolutePointer;
167
+ const circle = new fabric_1.fabric.Circle({
168
+ radius: 3,
169
+ fill: '#ffffff',
170
+ stroke: '#333333',
171
+ strokeWidth: 0.5,
172
+ left: x,
173
+ top: y,
174
+ selectable: false,
175
+ hasBorders: false,
176
+ hasControls: false,
177
+ originX: 'center',
178
+ originY: 'center',
179
+ hoverCursor: 'pointer',
180
+ });
181
+ if (!this.handler.pointArray.length) {
182
+ circle.set({
183
+ fill: 'red',
184
+ });
185
+ }
186
+ const points = [x, y, x, y];
187
+ this.handler.activeLine = new objects_1.Line(points, {
188
+ strokeWidth: 2,
189
+ fill: '#999999',
190
+ stroke: '#999999',
191
+ originX: 'center',
192
+ originY: 'center',
193
+ selectable: false,
194
+ hasBorders: false,
195
+ hasControls: false,
196
+ evented: false,
197
+ });
198
+ this.handler.activeLine.set({
199
+ class: 'line',
200
+ });
201
+ this.handler.pointArray.push(circle);
202
+ this.handler.canvas.add(this.handler.activeLine);
203
+ this.handler.canvas.add(circle);
204
+ },
205
+ generate: (opt) => {
206
+ const { absolutePointer } = opt;
207
+ const { x, y } = absolutePointer;
208
+ let points = [];
209
+ const id = uuidv4_1.uuid();
210
+ this.handler.pointArray.forEach(point => {
211
+ points = points.concat(point.left, point.top, x, y);
212
+ this.handler.canvas.remove(point);
213
+ });
214
+ this.handler.canvas.remove(this.handler.activeLine);
215
+ const option = {
216
+ id,
217
+ points,
218
+ type: 'line',
219
+ stroke: 'rgba(0, 0, 0, 1)',
220
+ strokeWidth: 3,
221
+ opacity: 1,
222
+ objectCaching: !this.handler.editable,
223
+ name: 'New line',
224
+ superType: 'drawing',
225
+ };
226
+ this.handler.add(option, false);
227
+ this.handler.pointArray = [];
228
+ this.handler.activeLine = null;
229
+ this.handler.interactionHandler.selection();
230
+ },
231
+ };
232
+ this.arrow = {
233
+ init: () => {
234
+ this.handler.interactionHandler.drawing('arrow');
235
+ this.handler.pointArray = [];
236
+ this.handler.activeLine = null;
237
+ },
238
+ finish: () => {
239
+ this.handler.pointArray.forEach(point => {
240
+ this.handler.canvas.remove(point);
241
+ });
242
+ this.handler.canvas.remove(this.handler.activeLine);
243
+ this.handler.pointArray = [];
244
+ this.handler.activeLine = null;
245
+ this.handler.canvas.renderAll();
246
+ this.handler.interactionHandler.selection();
247
+ },
248
+ addPoint: (opt) => {
249
+ const { absolutePointer } = opt;
250
+ const { x, y } = absolutePointer;
251
+ const circle = new fabric_1.fabric.Circle({
252
+ radius: 3,
253
+ fill: '#ffffff',
254
+ stroke: '#333333',
255
+ strokeWidth: 0.5,
256
+ left: x,
257
+ top: y,
258
+ selectable: false,
259
+ hasBorders: false,
260
+ hasControls: false,
261
+ originX: 'center',
262
+ originY: 'center',
263
+ hoverCursor: 'pointer',
264
+ });
265
+ if (!this.handler.pointArray.length) {
266
+ circle.set({
267
+ fill: 'red',
268
+ });
269
+ }
270
+ const points = [x, y, x, y];
271
+ this.handler.activeLine = new objects_1.Arrow(points, {
272
+ strokeWidth: 2,
273
+ fill: '#999999',
274
+ stroke: '#999999',
275
+ class: 'line',
276
+ originX: 'center',
277
+ originY: 'center',
278
+ selectable: false,
279
+ hasBorders: false,
280
+ hasControls: false,
281
+ evented: false,
282
+ });
283
+ this.handler.pointArray.push(circle);
284
+ this.handler.canvas.add(this.handler.activeLine);
285
+ this.handler.canvas.add(circle);
286
+ },
287
+ generate: (opt) => {
288
+ const { absolutePointer } = opt;
289
+ const { x, y } = absolutePointer;
290
+ let points = [];
291
+ this.handler.pointArray.forEach(point => {
292
+ points = points.concat(point.left, point.top, x, y);
293
+ this.handler.canvas.remove(point);
294
+ });
295
+ this.handler.canvas.remove(this.handler.activeLine);
296
+ const option = {
297
+ id: uuidv4_1.uuid(),
298
+ points,
299
+ type: 'arrow',
300
+ stroke: 'rgba(0, 0, 0, 1)',
301
+ strokeWidth: 3,
302
+ opacity: 1,
303
+ objectCaching: !this.handler.editable,
304
+ name: 'New line',
305
+ superType: 'drawing',
306
+ };
307
+ this.handler.add(option, false);
308
+ this.handler.pointArray = [];
309
+ this.handler.activeLine = null;
310
+ this.handler.interactionHandler.selection();
311
+ },
312
+ };
313
+ this.orthogonal = {};
314
+ this.curve = {};
315
+ this.handler = handler;
316
+ }
317
+ }
318
+ exports.default = DrawingHandler;