react-design-editor 0.0.33 → 0.0.37

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 (95) hide show
  1. package/README.md +37 -33
  2. package/dist/react-design-editor.js +20849 -11309
  3. package/dist/react-design-editor.min.js +1 -1
  4. package/dist/react-design-editor.min.js.LICENSE.txt +3 -10
  5. package/package.json +35 -31
  6. package/lib/Canvas.d.ts +0 -32
  7. package/lib/Canvas.js +0 -162
  8. package/lib/CanvasObject.d.ts +0 -10
  9. package/lib/CanvasObject.js +0 -96
  10. package/lib/constants/defaults.d.ts +0 -37
  11. package/lib/constants/defaults.js +0 -68
  12. package/lib/constants/index.d.ts +0 -2
  13. package/lib/constants/index.js +0 -24
  14. package/lib/handlers/AlignmentHandler.d.ts +0 -18
  15. package/lib/handlers/AlignmentHandler.js +0 -58
  16. package/lib/handlers/AnimationHandler.d.ts +0 -50
  17. package/lib/handlers/AnimationHandler.js +0 -320
  18. package/lib/handlers/ChartHandler.d.ts +0 -8
  19. package/lib/handlers/ChartHandler.js +0 -8
  20. package/lib/handlers/ContextmenuHandler.d.ts +0 -28
  21. package/lib/handlers/ContextmenuHandler.js +0 -65
  22. package/lib/handlers/CropHandler.d.ts +0 -43
  23. package/lib/handlers/CropHandler.js +0 -261
  24. package/lib/handlers/DrawingHandler.d.ts +0 -28
  25. package/lib/handlers/DrawingHandler.js +0 -318
  26. package/lib/handlers/ElementHandler.d.ts +0 -80
  27. package/lib/handlers/ElementHandler.js +0 -154
  28. package/lib/handlers/EventHandler.d.ts +0 -170
  29. package/lib/handlers/EventHandler.js +0 -877
  30. package/lib/handlers/GridHandler.d.ts +0 -19
  31. package/lib/handlers/GridHandler.js +0 -77
  32. package/lib/handlers/GuidelineHandler.d.ts +0 -61
  33. package/lib/handlers/GuidelineHandler.js +0 -314
  34. package/lib/handlers/Handler.d.ts +0 -603
  35. package/lib/handlers/Handler.js +0 -1612
  36. package/lib/handlers/ImageHandler.d.ts +0 -307
  37. package/lib/handlers/ImageHandler.js +0 -529
  38. package/lib/handlers/InteractionHandler.d.ts +0 -45
  39. package/lib/handlers/InteractionHandler.js +0 -159
  40. package/lib/handlers/LinkHandler.d.ts +0 -115
  41. package/lib/handlers/LinkHandler.js +0 -247
  42. package/lib/handlers/NodeHandler.d.ts +0 -50
  43. package/lib/handlers/NodeHandler.js +0 -274
  44. package/lib/handlers/PortHandler.d.ts +0 -22
  45. package/lib/handlers/PortHandler.js +0 -179
  46. package/lib/handlers/ShortcutHandler.d.ts +0 -119
  47. package/lib/handlers/ShortcutHandler.js +0 -150
  48. package/lib/handlers/TooltipHandler.d.ts +0 -33
  49. package/lib/handlers/TooltipHandler.js +0 -91
  50. package/lib/handlers/TransactionHandler.d.ts +0 -59
  51. package/lib/handlers/TransactionHandler.js +0 -139
  52. package/lib/handlers/WorkareaHandler.d.ts +0 -43
  53. package/lib/handlers/WorkareaHandler.js +0 -354
  54. package/lib/handlers/ZoomHandler.d.ts +0 -48
  55. package/lib/handlers/ZoomHandler.js +0 -143
  56. package/lib/handlers/index.d.ts +0 -21
  57. package/lib/handlers/index.js +0 -44
  58. package/lib/index.d.ts +0 -5
  59. package/lib/index.js +0 -19
  60. package/lib/objects/Arrow.d.ts +0 -2
  61. package/lib/objects/Arrow.js +0 -39
  62. package/lib/objects/Chart.d.ts +0 -10
  63. package/lib/objects/Chart.js +0 -123
  64. package/lib/objects/CirclePort.d.ts +0 -2
  65. package/lib/objects/CirclePort.js +0 -28
  66. package/lib/objects/Cube.d.ts +0 -5
  67. package/lib/objects/Cube.js +0 -71
  68. package/lib/objects/CurvedLink.d.ts +0 -2
  69. package/lib/objects/CurvedLink.js +0 -49
  70. package/lib/objects/Element.d.ts +0 -13
  71. package/lib/objects/Element.js +0 -83
  72. package/lib/objects/Gif.d.ts +0 -3
  73. package/lib/objects/Gif.js +0 -38
  74. package/lib/objects/Iframe.d.ts +0 -9
  75. package/lib/objects/Iframe.js +0 -69
  76. package/lib/objects/Line.d.ts +0 -2
  77. package/lib/objects/Line.js +0 -24
  78. package/lib/objects/Link.d.ts +0 -15
  79. package/lib/objects/Link.js +0 -104
  80. package/lib/objects/Node.d.ts +0 -59
  81. package/lib/objects/Node.js +0 -271
  82. package/lib/objects/OrthogonalLink.d.ts +0 -2
  83. package/lib/objects/OrthogonalLink.js +0 -52
  84. package/lib/objects/Port.d.ts +0 -12
  85. package/lib/objects/Port.js +0 -28
  86. package/lib/objects/Svg.d.ts +0 -8
  87. package/lib/objects/Svg.js +0 -59
  88. package/lib/objects/Video.d.ts +0 -14
  89. package/lib/objects/Video.js +0 -119
  90. package/lib/objects/index.d.ts +0 -15
  91. package/lib/objects/index.js +0 -32
  92. package/lib/utils/ObjectUtil.d.ts +0 -400
  93. package/lib/utils/ObjectUtil.js +0 -13
  94. package/lib/utils/index.d.ts +0 -1
  95. package/lib/utils/index.js +0 -13
@@ -1,261 +0,0 @@
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;
@@ -1,28 +0,0 @@
1
- import { fabric } from 'fabric';
2
- import Handler from './Handler';
3
- import { FabricEvent, FabricObject } from '../utils';
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;
@@ -1,318 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fabric_1 = require("fabric");
4
- const uuid_1 = require("uuid");
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: 3,
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: uuid_1.v4(),
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: 2,
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 = uuid_1.v4();
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: 3,
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 = uuid_1.v4();
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: uuid_1.v4(),
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;
@@ -1,80 +0,0 @@
1
- import { fabric } from 'fabric';
2
- import Handler from './Handler';
3
- import { VideoObject } from '../objects/Video';
4
- import { ChartObject } from '../objects/Chart';
5
- import { IframeObject } from '../objects/Iframe';
6
- import { ElementObject } from '../objects/Element';
7
- export declare type ElementType = 'container' | 'script' | 'style';
8
- export declare type ElementObjectType = VideoObject | ChartObject | IframeObject | ElementObject;
9
- export interface ElementCode {
10
- html?: string;
11
- css?: string;
12
- js?: string;
13
- }
14
- declare class ElementHandler {
15
- handler?: Handler;
16
- constructor(handler: Handler);
17
- /**
18
- * Set element by id
19
- * @param {string} id
20
- * @param {*} source
21
- * @returns {void}
22
- */
23
- setById: (id: string, source: any) => void;
24
- /**
25
- * Set element
26
- * @param {ElementObjectType} obj
27
- * @param {*} source
28
- */
29
- set: (obj: ElementObjectType, source: any) => void;
30
- /**
31
- * Find element by id with type
32
- * @param {string} id
33
- * @param {ElementType} [type='container']
34
- * @returns
35
- */
36
- findById: (id: string, type?: ElementType) => HTMLElement;
37
- /**
38
- * Remove element
39
- * @param {HTMLElement} el
40
- * @returns
41
- */
42
- remove: (el: HTMLElement) => void;
43
- /**
44
- * Remove element by id
45
- * @param {string} id
46
- */
47
- removeById: (id: string) => void;
48
- /**
49
- * Remove element by ids
50
- * @param {string[]} ids
51
- */
52
- removeByIds: (ids: string[]) => void;
53
- /**
54
- * Set position
55
- * @param {HTMLElement} el
56
- * @param {number} left
57
- * @param {number} top
58
- * @returns
59
- */
60
- setPosition: (el: HTMLElement, obj: fabric.Object) => void;
61
- setPositionByOrigin: (el: HTMLElement, obj: fabric.Object, left: number, top: number) => void;
62
- /**
63
- * Set size
64
- * @param {HTMLElement} el
65
- * @param {number} width
66
- * @param {number} height
67
- * @returns
68
- */
69
- setSize: (el: HTMLElement, obj: fabric.Object) => void;
70
- /**
71
- * Set scale or angle
72
- * @param {HTMLElement} el
73
- * @param {number} scaleX
74
- * @param {number} scaleY
75
- * @param {number} angle
76
- * @returns
77
- */
78
- setScaleOrAngle: (el: HTMLElement, obj: fabric.Object) => void;
79
- }
80
- export default ElementHandler;