react-design-editor 0.0.31 → 0.0.35

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 (101) hide show
  1. package/README.md +1 -1
  2. package/dist/react-design-editor.js +37380 -16467
  3. package/dist/react-design-editor.min.js +1 -1
  4. package/dist/react-design-editor.min.js.LICENSE.txt +13 -2
  5. package/lib/Canvas.d.ts +18 -29
  6. package/lib/Canvas.js +172 -208
  7. package/lib/CanvasObject.d.ts +10 -10
  8. package/lib/CanvasObject.js +96 -89
  9. package/lib/constants/code.d.ts +19 -0
  10. package/lib/constants/code.js +22 -0
  11. package/lib/constants/defaults.d.ts +38 -0
  12. package/lib/constants/defaults.js +69 -0
  13. package/lib/constants/index.d.ts +3 -0
  14. package/lib/constants/index.js +26 -0
  15. package/lib/handlers/AlignmentHandler.d.ts +18 -18
  16. package/lib/handlers/AlignmentHandler.js +58 -58
  17. package/lib/handlers/AnimationHandler.d.ts +50 -48
  18. package/lib/handlers/AnimationHandler.js +323 -298
  19. package/lib/handlers/ChartHandler.d.ts +8 -8
  20. package/lib/handlers/ChartHandler.js +8 -8
  21. package/lib/handlers/ContextmenuHandler.d.ts +28 -23
  22. package/lib/handlers/ContextmenuHandler.js +65 -56
  23. package/lib/handlers/CropHandler.d.ts +43 -37
  24. package/lib/handlers/CropHandler.js +261 -243
  25. package/lib/handlers/CustomHandler.d.ts +7 -0
  26. package/lib/handlers/CustomHandler.js +10 -0
  27. package/lib/handlers/DrawingHandler.d.ts +28 -28
  28. package/lib/handlers/DrawingHandler.js +318 -318
  29. package/lib/handlers/ElementHandler.d.ts +80 -80
  30. package/lib/handlers/ElementHandler.js +154 -154
  31. package/lib/handlers/EventHandler.d.ts +170 -182
  32. package/lib/handlers/EventHandler.js +880 -914
  33. package/lib/handlers/FiberHandler.d.ts +6 -0
  34. package/lib/handlers/FiberHandler.js +23 -0
  35. package/lib/handlers/GridHandler.d.ts +19 -18
  36. package/lib/handlers/GridHandler.js +77 -75
  37. package/lib/handlers/GuidelineHandler.d.ts +61 -39
  38. package/lib/handlers/GuidelineHandler.js +315 -263
  39. package/lib/handlers/Handler.d.ts +622 -543
  40. package/lib/handlers/Handler.js +1638 -1514
  41. package/lib/handlers/ImageHandler.d.ts +307 -307
  42. package/lib/handlers/ImageHandler.js +529 -484
  43. package/lib/handlers/InteractionHandler.d.ts +45 -45
  44. package/lib/handlers/InteractionHandler.js +164 -156
  45. package/lib/handlers/LinkHandler.d.ts +115 -116
  46. package/lib/handlers/LinkHandler.js +247 -246
  47. package/lib/handlers/NodeHandler.d.ts +50 -50
  48. package/lib/handlers/NodeHandler.js +274 -274
  49. package/lib/handlers/PortHandler.d.ts +22 -22
  50. package/lib/handlers/PortHandler.js +179 -179
  51. package/lib/handlers/ShortcutHandler.d.ts +119 -119
  52. package/lib/handlers/ShortcutHandler.js +151 -150
  53. package/lib/handlers/TooltipHandler.d.ts +33 -24
  54. package/lib/handlers/TooltipHandler.js +91 -78
  55. package/lib/handlers/TransactionHandler.d.ts +59 -54
  56. package/lib/handlers/TransactionHandler.js +137 -129
  57. package/lib/handlers/WorkareaHandler.d.ts +43 -31
  58. package/lib/handlers/WorkareaHandler.js +354 -355
  59. package/lib/handlers/ZoomHandler.d.ts +48 -48
  60. package/lib/handlers/ZoomHandler.js +143 -145
  61. package/lib/handlers/index.d.ts +23 -21
  62. package/lib/handlers/index.js +48 -44
  63. package/lib/index.d.ts +5 -5
  64. package/lib/index.js +19 -19
  65. package/lib/objects/Arrow.d.ts +2 -2
  66. package/lib/objects/Arrow.js +40 -39
  67. package/lib/objects/Chart.d.ts +10 -10
  68. package/lib/objects/Chart.js +117 -116
  69. package/lib/objects/CirclePort.d.ts +2 -2
  70. package/lib/objects/CirclePort.js +28 -28
  71. package/lib/objects/Cube.d.ts +5 -5
  72. package/lib/objects/Cube.js +71 -71
  73. package/lib/objects/CurvedLink.d.ts +2 -2
  74. package/lib/objects/CurvedLink.js +51 -49
  75. package/lib/objects/Element.d.ts +13 -13
  76. package/lib/objects/Element.js +77 -76
  77. package/lib/objects/Gif.d.ts +3 -3
  78. package/lib/objects/Gif.js +41 -38
  79. package/lib/objects/Iframe.d.ts +9 -9
  80. package/lib/objects/Iframe.js +63 -62
  81. package/lib/objects/Line.d.ts +2 -2
  82. package/lib/objects/Line.js +24 -24
  83. package/lib/objects/Link.d.ts +15 -15
  84. package/lib/objects/Link.js +106 -104
  85. package/lib/objects/Node.d.ts +59 -59
  86. package/lib/objects/Node.js +271 -268
  87. package/lib/objects/OrthogonalLink.d.ts +2 -2
  88. package/lib/objects/OrthogonalLink.js +54 -52
  89. package/lib/objects/Port.d.ts +12 -12
  90. package/lib/objects/Port.js +28 -28
  91. package/lib/objects/Svg.d.ts +8 -0
  92. package/lib/objects/Svg.js +59 -0
  93. package/lib/objects/Video.d.ts +14 -14
  94. package/lib/objects/Video.js +113 -112
  95. package/lib/objects/index.d.ts +15 -14
  96. package/lib/objects/index.js +32 -30
  97. package/lib/utils/ObjectUtil.d.ts +407 -412
  98. package/lib/utils/ObjectUtil.js +13 -13
  99. package/lib/utils/index.d.ts +1 -1
  100. package/lib/utils/index.js +13 -13
  101. package/package.json +7 -6
@@ -1,243 +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
- * @returns
9
- */
10
- this.validType = () => {
11
- const activeObject = this.handler.canvas.getActiveObject();
12
- if (!activeObject) {
13
- return false;
14
- }
15
- if (activeObject.type === 'image') {
16
- return true;
17
- }
18
- return false;
19
- };
20
- /**
21
- * Start crop image
22
- */
23
- this.start = () => {
24
- if (this.validType()) {
25
- this.handler.interactionMode = 'crop';
26
- this.cropObject = this.handler.canvas.getActiveObject();
27
- const { left, top } = this.cropObject;
28
- this.cropRect = new fabric_1.fabric.Rect({
29
- width: this.cropObject.width,
30
- height: this.cropObject.height,
31
- scaleX: this.cropObject.scaleX,
32
- scaleY: this.cropObject.scaleY,
33
- originX: 'left',
34
- originY: 'top',
35
- left,
36
- top,
37
- hasRotatingPoint: false,
38
- fill: 'rgba(0, 0, 0, 0.2)',
39
- });
40
- this.handler.canvas.add(this.cropRect);
41
- this.handler.canvas.setActiveObject(this.cropRect);
42
- this.cropObject.selectable = false;
43
- this.cropObject.evented = false;
44
- this.handler.canvas.renderAll();
45
- }
46
- };
47
- /**
48
- * Finish crop image
49
- */
50
- this.finish = () => {
51
- const { left, top, width, height, scaleX, scaleY } = this.cropRect;
52
- const croppedImg = this.cropObject.toDataURL({
53
- left: left - this.cropObject.left,
54
- top: top - this.cropObject.top,
55
- width: width * scaleX,
56
- height: height * scaleY,
57
- });
58
- this.handler.setImage(this.cropObject, croppedImg);
59
- this.cancel();
60
- };
61
- /**
62
- * Cancel crop
63
- */
64
- this.cancel = () => {
65
- this.handler.interactionMode = 'selection';
66
- this.cropObject.selectable = true;
67
- this.cropObject.evented = true;
68
- this.handler.canvas.setActiveObject(this.cropObject);
69
- this.handler.canvas.remove(this.cropRect);
70
- this.cropRect = null;
71
- this.cropObject = null;
72
- this.handler.canvas.renderAll();
73
- };
74
- /**
75
- * Resize crop
76
- * @param {FabricEvent} opt
77
- */
78
- this.resize = (opt) => {
79
- const { target, transform: { original, corner } } = opt;
80
- const { left, top, width, height, scaleX, scaleY } = target;
81
- const { left: cropLeft, top: cropTop, width: cropWidth, height: cropHeight, scaleX: cropScaleX, scaleY: cropScaleY } = this.cropObject;
82
- if (corner === 'tl') {
83
- if (Math.round(cropLeft) > Math.round(left)) { // left
84
- const originRight = Math.round(cropLeft + cropWidth);
85
- const targetRight = Math.round(target.getBoundingRect().left + target.getBoundingRect().width);
86
- const diffRightRatio = 1 - ((originRight - targetRight) / cropWidth);
87
- target.set({
88
- left: cropLeft,
89
- scaleX: diffRightRatio > 1 ? 1 : diffRightRatio,
90
- });
91
- }
92
- if (Math.round(cropTop) > Math.round(top)) { // top
93
- const originBottom = Math.round(cropTop + cropHeight);
94
- const targetBottom = Math.round(target.getBoundingRect().top + target.getBoundingRect().height);
95
- const diffBottomRatio = 1 - ((originBottom - targetBottom) / cropHeight);
96
- target.set({
97
- top: cropTop,
98
- scaleY: diffBottomRatio > 1 ? 1 : diffBottomRatio,
99
- });
100
- }
101
- }
102
- else if (corner === 'bl') {
103
- if (Math.round(cropLeft) > Math.round(left)) { // left
104
- const originRight = Math.round(cropLeft + cropWidth);
105
- const targetRight = Math.round(target.getBoundingRect().left + target.getBoundingRect().width);
106
- const diffRightRatio = 1 - ((originRight - targetRight) / cropWidth);
107
- target.set({
108
- left: cropLeft,
109
- scaleX: diffRightRatio > 1 ? 1 : diffRightRatio,
110
- });
111
- }
112
- if (Math.round(cropTop + (cropHeight * cropScaleY)) < Math.round(top + (height * scaleY))) { // bottom
113
- const diffTopRatio = 1 - ((original.top - cropTop) / cropHeight);
114
- target.set({
115
- top: original.top,
116
- scaleY: diffTopRatio > 1 ? 1 : diffTopRatio,
117
- });
118
- }
119
- }
120
- else if (corner === 'tr') {
121
- if (Math.round(cropLeft + (cropWidth * cropScaleX)) < Math.round(left + (width * scaleX))) { // right
122
- const diffLeftRatio = 1 - ((original.left - cropLeft) / cropWidth);
123
- target.set({
124
- left: original.left,
125
- scaleX: diffLeftRatio > 1 ? 1 : diffLeftRatio,
126
- });
127
- }
128
- if (Math.round(cropTop) > Math.round(top)) { // top
129
- const originBottom = Math.round(cropTop + cropHeight);
130
- const targetBottom = Math.round(target.getBoundingRect().top + target.getBoundingRect().height);
131
- const diffBottomRatio = 1 - ((originBottom - targetBottom) / cropHeight);
132
- target.set({
133
- top: cropTop,
134
- scaleY: diffBottomRatio > 1 ? 1 : diffBottomRatio,
135
- });
136
- }
137
- }
138
- else if (corner === 'br') {
139
- if (Math.round(cropLeft + (cropWidth * cropScaleX)) < Math.round(left + (width * scaleX))) { // right
140
- const diffLeftRatio = 1 - ((original.left - cropLeft) / cropWidth);
141
- target.set({
142
- left: original.left,
143
- scaleX: diffLeftRatio > 1 ? 1 : diffLeftRatio,
144
- });
145
- }
146
- if (Math.round(cropTop + (cropHeight * cropScaleY)) < Math.round(top + (height * scaleY))) { // bottom
147
- const diffTopRatio = 1 - ((original.top - cropTop) / cropHeight);
148
- target.set({
149
- top: original.top,
150
- scaleY: diffTopRatio > 1 ? 1 : diffTopRatio,
151
- });
152
- }
153
- }
154
- else if (corner === 'ml') {
155
- if (Math.round(cropLeft) > Math.round(left)) { // left
156
- const originRight = Math.round(cropLeft + cropWidth);
157
- const targetRight = Math.round(target.getBoundingRect().left + target.getBoundingRect().width);
158
- const diffRightRatio = 1 - ((originRight - targetRight) / cropWidth);
159
- target.set({
160
- left: cropLeft,
161
- scaleX: diffRightRatio > 1 ? 1 : diffRightRatio,
162
- });
163
- }
164
- }
165
- else if (corner === 'mt') {
166
- if (Math.round(cropTop) > Math.round(top)) { // top
167
- const originBottom = Math.round(cropTop + cropHeight);
168
- const targetBottom = Math.round(target.getBoundingRect().top + target.getBoundingRect().height);
169
- const diffBottomRatio = 1 - ((originBottom - targetBottom) / cropHeight);
170
- target.set({
171
- top: cropTop,
172
- scaleY: diffBottomRatio > 1 ? 1 : diffBottomRatio,
173
- });
174
- }
175
- }
176
- else if (corner === 'mb') {
177
- if (Math.round(cropTop + (cropHeight * cropScaleY)) < Math.round(top + (height * scaleY))) { // bottom
178
- const diffTopRatio = 1 - ((original.top - cropTop) / cropHeight);
179
- target.set({
180
- top: original.top,
181
- scaleY: diffTopRatio > 1 ? 1 : diffTopRatio,
182
- });
183
- }
184
- }
185
- else if (corner === 'mr') {
186
- if (Math.round(cropLeft + (cropWidth * cropScaleX)) < Math.round(left + (width * scaleX))) { // right
187
- const diffLeftRatio = 1 - ((original.left - cropLeft) / cropWidth);
188
- target.set({
189
- left: original.left,
190
- scaleX: diffLeftRatio > 1 ? 1 : diffLeftRatio,
191
- });
192
- }
193
- }
194
- };
195
- /**
196
- * Resize crop
197
- * @param {FabricEvent} opt
198
- */
199
- this.moving = (opt) => {
200
- const { target } = opt;
201
- const { left, top, width, height, scaleX, scaleY } = target;
202
- const { left: cropLeft, top: cropTop, width: cropWidth, height: cropHeight } = this.cropObject.getBoundingRect();
203
- const movedTop = () => {
204
- if (Math.round(cropTop) >= Math.round(top)) {
205
- target.set({
206
- top: cropTop,
207
- });
208
- }
209
- else if (Math.round(cropTop + cropHeight) <= Math.round(top + (height * scaleY))) {
210
- target.set({
211
- top: cropTop + cropHeight - (height * scaleY),
212
- });
213
- }
214
- };
215
- if (Math.round(cropLeft) >= Math.round(left)) {
216
- target.set({
217
- left: Math.max(left, cropLeft),
218
- });
219
- movedTop();
220
- }
221
- else if (Math.round(cropLeft + cropWidth) <= Math.round(left + (width * scaleX))) {
222
- target.set({
223
- left: cropLeft + cropWidth - (width * scaleX),
224
- });
225
- movedTop();
226
- }
227
- else if (Math.round(cropTop) >= Math.round(top)) {
228
- target.set({
229
- top: cropTop,
230
- });
231
- }
232
- else if (Math.round(cropTop + cropHeight) <= Math.round(top + (height * scaleY))) {
233
- target.set({
234
- top: cropTop + cropHeight - (height * scaleY),
235
- });
236
- }
237
- };
238
- this.handler = handler;
239
- this.cropRect = null;
240
- this.cropObject = null;
241
- }
242
- }
243
- exports.default = CropHandler;
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;
@@ -1,28 +1,28 @@
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
+ 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;