react-design-editor 0.0.50 → 0.0.52

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 (100) hide show
  1. package/dist/react-design-editor.js +7739 -7114
  2. package/dist/react-design-editor.min.js +1 -1
  3. package/dist/react-design-editor.min.js.LICENSE.txt +2 -0
  4. package/lib/Canvas.d.ts +18 -18
  5. package/lib/Canvas.js +172 -172
  6. package/lib/CanvasObject.d.ts +10 -10
  7. package/lib/CanvasObject.js +96 -96
  8. package/lib/constants/code.d.ts +19 -19
  9. package/lib/constants/code.js +22 -22
  10. package/lib/constants/defaults.d.ts +38 -38
  11. package/lib/constants/defaults.js +69 -69
  12. package/lib/constants/index.d.ts +3 -3
  13. package/lib/constants/index.js +26 -26
  14. package/lib/handlers/AlignmentHandler.d.ts +18 -18
  15. package/lib/handlers/AlignmentHandler.js +58 -58
  16. package/lib/handlers/AnimationHandler.d.ts +50 -50
  17. package/lib/handlers/AnimationHandler.js +346 -346
  18. package/lib/handlers/ChartHandler.d.ts +8 -8
  19. package/lib/handlers/ChartHandler.js +8 -8
  20. package/lib/handlers/ContextmenuHandler.d.ts +28 -28
  21. package/lib/handlers/ContextmenuHandler.js +65 -65
  22. package/lib/handlers/CropHandler.d.ts +43 -43
  23. package/lib/handlers/CropHandler.js +261 -261
  24. package/lib/handlers/CustomHandler.d.ts +7 -7
  25. package/lib/handlers/CustomHandler.js +10 -10
  26. package/lib/handlers/DrawingHandler.d.ts +28 -28
  27. package/lib/handlers/DrawingHandler.js +318 -318
  28. package/lib/handlers/ElementHandler.d.ts +80 -80
  29. package/lib/handlers/ElementHandler.js +154 -154
  30. package/lib/handlers/EventHandler.d.ts +170 -170
  31. package/lib/handlers/EventHandler.js +880 -880
  32. package/lib/handlers/FiberHandler.d.ts +6 -6
  33. package/lib/handlers/FiberHandler.js +23 -23
  34. package/lib/handlers/GridHandler.d.ts +19 -19
  35. package/lib/handlers/GridHandler.js +77 -77
  36. package/lib/handlers/GuidelineHandler.d.ts +61 -61
  37. package/lib/handlers/GuidelineHandler.js +315 -315
  38. package/lib/handlers/Handler.d.ts +618 -618
  39. package/lib/handlers/Handler.js +1645 -1645
  40. package/lib/handlers/ImageHandler.d.ts +307 -307
  41. package/lib/handlers/ImageHandler.js +528 -528
  42. package/lib/handlers/InteractionHandler.d.ts +45 -45
  43. package/lib/handlers/InteractionHandler.js +168 -164
  44. package/lib/handlers/LinkHandler.d.ts +115 -115
  45. package/lib/handlers/LinkHandler.js +247 -247
  46. package/lib/handlers/NodeHandler.d.ts +50 -50
  47. package/lib/handlers/NodeHandler.js +274 -274
  48. package/lib/handlers/PortHandler.d.ts +22 -22
  49. package/lib/handlers/PortHandler.js +179 -179
  50. package/lib/handlers/ShortcutHandler.d.ts +119 -119
  51. package/lib/handlers/ShortcutHandler.js +151 -151
  52. package/lib/handlers/TooltipHandler.d.ts +33 -33
  53. package/lib/handlers/TooltipHandler.js +91 -91
  54. package/lib/handlers/TransactionHandler.d.ts +59 -59
  55. package/lib/handlers/TransactionHandler.js +137 -137
  56. package/lib/handlers/WorkareaHandler.d.ts +43 -43
  57. package/lib/handlers/WorkareaHandler.js +354 -354
  58. package/lib/handlers/ZoomHandler.d.ts +48 -48
  59. package/lib/handlers/ZoomHandler.js +143 -143
  60. package/lib/handlers/index.d.ts +23 -23
  61. package/lib/handlers/index.js +48 -48
  62. package/lib/index.d.ts +6 -6
  63. package/lib/index.js +20 -20
  64. package/lib/objects/Arrow.d.ts +2 -2
  65. package/lib/objects/Arrow.js +40 -40
  66. package/lib/objects/Chart.d.ts +10 -10
  67. package/lib/objects/Chart.js +117 -117
  68. package/lib/objects/CirclePort.d.ts +2 -2
  69. package/lib/objects/CirclePort.js +28 -28
  70. package/lib/objects/Cube.d.ts +5 -5
  71. package/lib/objects/Cube.js +71 -71
  72. package/lib/objects/CurvedLink.d.ts +2 -2
  73. package/lib/objects/CurvedLink.js +51 -51
  74. package/lib/objects/Element.d.ts +13 -13
  75. package/lib/objects/Element.js +77 -77
  76. package/lib/objects/Gif.d.ts +3 -3
  77. package/lib/objects/Gif.js +41 -41
  78. package/lib/objects/Iframe.d.ts +9 -9
  79. package/lib/objects/Iframe.js +63 -63
  80. package/lib/objects/Line.d.ts +2 -2
  81. package/lib/objects/Line.js +24 -24
  82. package/lib/objects/Link.d.ts +15 -15
  83. package/lib/objects/Link.js +107 -107
  84. package/lib/objects/Node.d.ts +59 -59
  85. package/lib/objects/Node.js +271 -271
  86. package/lib/objects/OrthogonalLink.d.ts +2 -2
  87. package/lib/objects/OrthogonalLink.js +54 -54
  88. package/lib/objects/Port.d.ts +12 -12
  89. package/lib/objects/Port.js +28 -28
  90. package/lib/objects/Svg.d.ts +12 -12
  91. package/lib/objects/Svg.js +93 -93
  92. package/lib/objects/Video.d.ts +14 -14
  93. package/lib/objects/Video.js +113 -113
  94. package/lib/objects/index.d.ts +15 -15
  95. package/lib/objects/index.js +32 -32
  96. package/lib/utils/ObjectUtil.d.ts +408 -408
  97. package/lib/utils/ObjectUtil.js +13 -13
  98. package/lib/utils/index.d.ts +1 -1
  99. package/lib/utils/index.js +13 -13
  100. package/package.json +1 -1
@@ -1,261 +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;
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,7 +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;
1
+ import { Handler } from '.';
2
+ declare class CustomHandler {
3
+ handler: Handler;
4
+ constructor(handler: Handler);
5
+ protected initialze(): void;
6
+ }
7
+ export default CustomHandler;
@@ -1,10 +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
+ "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 { 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;
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;