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.
- package/README.md +1 -1
- package/dist/react-design-editor.js +37380 -16467
- package/dist/react-design-editor.min.js +1 -1
- package/dist/react-design-editor.min.js.LICENSE.txt +13 -2
- package/lib/Canvas.d.ts +18 -29
- package/lib/Canvas.js +172 -208
- package/lib/CanvasObject.d.ts +10 -10
- package/lib/CanvasObject.js +96 -89
- package/lib/constants/code.d.ts +19 -0
- package/lib/constants/code.js +22 -0
- package/lib/constants/defaults.d.ts +38 -0
- package/lib/constants/defaults.js +69 -0
- package/lib/constants/index.d.ts +3 -0
- package/lib/constants/index.js +26 -0
- package/lib/handlers/AlignmentHandler.d.ts +18 -18
- package/lib/handlers/AlignmentHandler.js +58 -58
- package/lib/handlers/AnimationHandler.d.ts +50 -48
- package/lib/handlers/AnimationHandler.js +323 -298
- package/lib/handlers/ChartHandler.d.ts +8 -8
- package/lib/handlers/ChartHandler.js +8 -8
- package/lib/handlers/ContextmenuHandler.d.ts +28 -23
- package/lib/handlers/ContextmenuHandler.js +65 -56
- package/lib/handlers/CropHandler.d.ts +43 -37
- package/lib/handlers/CropHandler.js +261 -243
- package/lib/handlers/CustomHandler.d.ts +7 -0
- package/lib/handlers/CustomHandler.js +10 -0
- package/lib/handlers/DrawingHandler.d.ts +28 -28
- package/lib/handlers/DrawingHandler.js +318 -318
- package/lib/handlers/ElementHandler.d.ts +80 -80
- package/lib/handlers/ElementHandler.js +154 -154
- package/lib/handlers/EventHandler.d.ts +170 -182
- package/lib/handlers/EventHandler.js +880 -914
- package/lib/handlers/FiberHandler.d.ts +6 -0
- package/lib/handlers/FiberHandler.js +23 -0
- package/lib/handlers/GridHandler.d.ts +19 -18
- package/lib/handlers/GridHandler.js +77 -75
- package/lib/handlers/GuidelineHandler.d.ts +61 -39
- package/lib/handlers/GuidelineHandler.js +315 -263
- package/lib/handlers/Handler.d.ts +622 -543
- package/lib/handlers/Handler.js +1638 -1514
- package/lib/handlers/ImageHandler.d.ts +307 -307
- package/lib/handlers/ImageHandler.js +529 -484
- package/lib/handlers/InteractionHandler.d.ts +45 -45
- package/lib/handlers/InteractionHandler.js +164 -156
- package/lib/handlers/LinkHandler.d.ts +115 -116
- package/lib/handlers/LinkHandler.js +247 -246
- package/lib/handlers/NodeHandler.d.ts +50 -50
- package/lib/handlers/NodeHandler.js +274 -274
- package/lib/handlers/PortHandler.d.ts +22 -22
- package/lib/handlers/PortHandler.js +179 -179
- package/lib/handlers/ShortcutHandler.d.ts +119 -119
- package/lib/handlers/ShortcutHandler.js +151 -150
- package/lib/handlers/TooltipHandler.d.ts +33 -24
- package/lib/handlers/TooltipHandler.js +91 -78
- package/lib/handlers/TransactionHandler.d.ts +59 -54
- package/lib/handlers/TransactionHandler.js +137 -129
- package/lib/handlers/WorkareaHandler.d.ts +43 -31
- package/lib/handlers/WorkareaHandler.js +354 -355
- package/lib/handlers/ZoomHandler.d.ts +48 -48
- package/lib/handlers/ZoomHandler.js +143 -145
- package/lib/handlers/index.d.ts +23 -21
- package/lib/handlers/index.js +48 -44
- package/lib/index.d.ts +5 -5
- package/lib/index.js +19 -19
- package/lib/objects/Arrow.d.ts +2 -2
- package/lib/objects/Arrow.js +40 -39
- package/lib/objects/Chart.d.ts +10 -10
- package/lib/objects/Chart.js +117 -116
- package/lib/objects/CirclePort.d.ts +2 -2
- package/lib/objects/CirclePort.js +28 -28
- package/lib/objects/Cube.d.ts +5 -5
- package/lib/objects/Cube.js +71 -71
- package/lib/objects/CurvedLink.d.ts +2 -2
- package/lib/objects/CurvedLink.js +51 -49
- package/lib/objects/Element.d.ts +13 -13
- package/lib/objects/Element.js +77 -76
- package/lib/objects/Gif.d.ts +3 -3
- package/lib/objects/Gif.js +41 -38
- package/lib/objects/Iframe.d.ts +9 -9
- package/lib/objects/Iframe.js +63 -62
- package/lib/objects/Line.d.ts +2 -2
- package/lib/objects/Line.js +24 -24
- package/lib/objects/Link.d.ts +15 -15
- package/lib/objects/Link.js +106 -104
- package/lib/objects/Node.d.ts +59 -59
- package/lib/objects/Node.js +271 -268
- package/lib/objects/OrthogonalLink.d.ts +2 -2
- package/lib/objects/OrthogonalLink.js +54 -52
- package/lib/objects/Port.d.ts +12 -12
- package/lib/objects/Port.js +28 -28
- package/lib/objects/Svg.d.ts +8 -0
- package/lib/objects/Svg.js +59 -0
- package/lib/objects/Video.d.ts +14 -14
- package/lib/objects/Video.js +113 -112
- package/lib/objects/index.d.ts +15 -14
- package/lib/objects/index.js +32 -30
- package/lib/utils/ObjectUtil.d.ts +407 -412
- package/lib/utils/ObjectUtil.js +13 -13
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +13 -13
- package/package.json +7 -6
|
@@ -1,484 +1,529 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.capitalize = exports.FILTER_TYPES = void 0;
|
|
7
|
-
const fabric_1 = require("fabric");
|
|
8
|
-
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
9
|
-
exports.FILTER_TYPES = [
|
|
10
|
-
'grayscale',
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
else if (type === '
|
|
74
|
-
return new fabric_1.fabric.Image.filters.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// } else if (type === '
|
|
87
|
-
// return new fabric.Image.filters.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
...
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
*
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
*
|
|
203
|
-
* @param {
|
|
204
|
-
* @param {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
*
|
|
223
|
-
* @param {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
*
|
|
238
|
-
* @param {boolean} [
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
*
|
|
246
|
-
* @param {boolean} [
|
|
247
|
-
* @param {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
this.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
*
|
|
270
|
-
* @param {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Apply
|
|
298
|
-
* @param {boolean} [
|
|
299
|
-
* @param {number} [value]
|
|
300
|
-
* @param {fabric.Image} [imageObj]
|
|
301
|
-
*/
|
|
302
|
-
this.
|
|
303
|
-
this.applyFilter(
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
*
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
*
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
*
|
|
350
|
-
* @param {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
//
|
|
354
|
-
//
|
|
355
|
-
//
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
*
|
|
359
|
-
* @param {
|
|
360
|
-
* @param {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
*
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
*
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
*
|
|
403
|
-
* @param {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Apply
|
|
412
|
-
* @param {boolean} [
|
|
413
|
-
* @param {
|
|
414
|
-
* @param {fabric.Image} [imageObj]
|
|
415
|
-
*/
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Apply
|
|
421
|
-
* @param {boolean} [
|
|
422
|
-
* @param {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
this.
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
*
|
|
430
|
-
* @param {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
*
|
|
439
|
-
* @param {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
*
|
|
448
|
-
* @param {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
this.
|
|
452
|
-
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
*
|
|
457
|
-
* @param {
|
|
458
|
-
* @param {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
*
|
|
466
|
-
* @param {
|
|
467
|
-
* @param {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
*
|
|
475
|
-
* @param {
|
|
476
|
-
* @param {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.capitalize = exports.FILTER_TYPES = void 0;
|
|
7
|
+
const fabric_1 = require("fabric");
|
|
8
|
+
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
9
|
+
exports.FILTER_TYPES = [
|
|
10
|
+
'grayscale',
|
|
11
|
+
'invert',
|
|
12
|
+
'remove-color',
|
|
13
|
+
'sepia',
|
|
14
|
+
'brownie',
|
|
15
|
+
'brightness',
|
|
16
|
+
'contrast',
|
|
17
|
+
'saturation',
|
|
18
|
+
'noise',
|
|
19
|
+
'vintage',
|
|
20
|
+
'pixelate',
|
|
21
|
+
'blur',
|
|
22
|
+
'sharpen',
|
|
23
|
+
'emboss',
|
|
24
|
+
'technicolor',
|
|
25
|
+
'polaroid',
|
|
26
|
+
'blend-color',
|
|
27
|
+
'gamma',
|
|
28
|
+
'kodachrome',
|
|
29
|
+
'blackwhite',
|
|
30
|
+
'blend-image',
|
|
31
|
+
'hue',
|
|
32
|
+
'resize',
|
|
33
|
+
'tint',
|
|
34
|
+
'mask',
|
|
35
|
+
'multiply',
|
|
36
|
+
'sepia2',
|
|
37
|
+
];
|
|
38
|
+
exports.capitalize = (str) => (str ? str.charAt(0).toUpperCase() + str.slice(1) : false);
|
|
39
|
+
const SHARPEN_MATRIX = [0, -1, 0, -1, 5, -1, 0, -1, 0];
|
|
40
|
+
const EMBOSS_MATRIX = [1, 1, 1, 1, 0.7, -1, -1, -1, -1];
|
|
41
|
+
/**
|
|
42
|
+
* Image Handler
|
|
43
|
+
* @author salgum1114
|
|
44
|
+
* @date 2019-09-01
|
|
45
|
+
* @class ImageHandler
|
|
46
|
+
* @implements {IBaseHandler}
|
|
47
|
+
*/
|
|
48
|
+
class ImageHandler {
|
|
49
|
+
constructor(handler) {
|
|
50
|
+
/**
|
|
51
|
+
* Create filter by type
|
|
52
|
+
* @param {IFilter} filter
|
|
53
|
+
*/
|
|
54
|
+
this.createFilter = (filter) => {
|
|
55
|
+
const { type: filterType, ...other } = filter;
|
|
56
|
+
const type = filterType.toLowerCase();
|
|
57
|
+
if (type === 'grayscale') {
|
|
58
|
+
return new fabric_1.fabric.Image.filters.Grayscale(other);
|
|
59
|
+
}
|
|
60
|
+
else if (type === 'invert') {
|
|
61
|
+
return new fabric_1.fabric.Image.filters.Invert();
|
|
62
|
+
// } else if (type === 'remove-color') {
|
|
63
|
+
// return new fabric.Image.filters.RemoveColor(other);
|
|
64
|
+
}
|
|
65
|
+
else if (type === 'sepia') {
|
|
66
|
+
return new fabric_1.fabric.Image.filters.Sepia();
|
|
67
|
+
// } else if (type === 'brownie') {
|
|
68
|
+
// return new fabric.Image.filters.Brownie();
|
|
69
|
+
}
|
|
70
|
+
else if (type === 'brightness') {
|
|
71
|
+
return new fabric_1.fabric.Image.filters.Brightness({ brightness: other.brightness });
|
|
72
|
+
}
|
|
73
|
+
else if (type === 'contrast') {
|
|
74
|
+
return new fabric_1.fabric.Image.filters.Contrast(other);
|
|
75
|
+
}
|
|
76
|
+
else if (type === 'saturation') {
|
|
77
|
+
return new fabric_1.fabric.Image.filters.Saturation(other);
|
|
78
|
+
}
|
|
79
|
+
else if (type === 'noise') {
|
|
80
|
+
return new fabric_1.fabric.Image.filters.Noise({ noise: other.noise });
|
|
81
|
+
// } else if (type === 'vintage') {
|
|
82
|
+
// return new fabric.Image.filters.Vintage();
|
|
83
|
+
}
|
|
84
|
+
else if (type === 'pixelate') {
|
|
85
|
+
return new fabric_1.fabric.Image.filters.Pixelate(other);
|
|
86
|
+
// } else if (type === 'blur') {
|
|
87
|
+
// return new fabric.Image.filters.Blur(other);
|
|
88
|
+
}
|
|
89
|
+
else if (type === 'sharpen') {
|
|
90
|
+
return new fabric_1.fabric.Image.filters.Convolute({
|
|
91
|
+
matrix: SHARPEN_MATRIX,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else if (type === 'emboss') {
|
|
95
|
+
return new fabric_1.fabric.Image.filters.Convolute({
|
|
96
|
+
matrix: EMBOSS_MATRIX,
|
|
97
|
+
});
|
|
98
|
+
// } else if (type === 'technicolor') {
|
|
99
|
+
// return new fabric.Image.filters.Technicolor();
|
|
100
|
+
// } else if (type === 'polaroid') {
|
|
101
|
+
// return new fabric.Image.filters.Polaroid();
|
|
102
|
+
}
|
|
103
|
+
else if (type === 'blend-color') {
|
|
104
|
+
return new fabric_1.fabric.Image.filters.BlendColor(other);
|
|
105
|
+
// } else if (type === 'gamma') {
|
|
106
|
+
// return new fabric.Image.filters.Gamma(other);
|
|
107
|
+
// } else if (type === 'kodachrome') {
|
|
108
|
+
// return new fabric.Image.filters.Kodachrome();
|
|
109
|
+
// } else if (type === 'blackwhite') {
|
|
110
|
+
// return new fabric.Image.filters.BlackWhite();
|
|
111
|
+
}
|
|
112
|
+
else if (type === 'blend-image') {
|
|
113
|
+
return new fabric_1.fabric.Image.filters.BlendImage(other);
|
|
114
|
+
// } else if (type === 'hue') {
|
|
115
|
+
// return new fabric.Image.filters.HueRotation(other);
|
|
116
|
+
}
|
|
117
|
+
else if (type === 'resize') {
|
|
118
|
+
return new fabric_1.fabric.Image.filters.Resize(other);
|
|
119
|
+
}
|
|
120
|
+
else if (type === 'tint') {
|
|
121
|
+
return new fabric_1.fabric.Image.filters.Tint(other);
|
|
122
|
+
}
|
|
123
|
+
else if (type === 'mask') {
|
|
124
|
+
return new fabric_1.fabric.Image.filters.Mask({
|
|
125
|
+
channel: other.channel,
|
|
126
|
+
mask: other.mask,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else if (type === 'multiply') {
|
|
130
|
+
return new fabric_1.fabric.Image.filters.Multiply({
|
|
131
|
+
color: other.color,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else if (type === 'sepia2') {
|
|
135
|
+
return new fabric_1.fabric.Image.filters.Sepia2(other);
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Create filter by types
|
|
141
|
+
* @param {IFilter[]} filters
|
|
142
|
+
*/
|
|
143
|
+
this.createFilters = (filters) => {
|
|
144
|
+
const createdFilters = filters.reduce((prev, filter) => {
|
|
145
|
+
let type = filter.type;
|
|
146
|
+
if (type.toLowerCase() === 'convolute' && isEqual_1.default(filter.matrix, SHARPEN_MATRIX)) {
|
|
147
|
+
type = 'sharpen';
|
|
148
|
+
}
|
|
149
|
+
else if (type.toLowerCase() === 'convolute' && isEqual_1.default(filter.matrix, EMBOSS_MATRIX)) {
|
|
150
|
+
type = 'emboss';
|
|
151
|
+
}
|
|
152
|
+
const findIndex = exports.FILTER_TYPES.findIndex(filterType => type.toLowerCase() === filterType);
|
|
153
|
+
if (findIndex > -1) {
|
|
154
|
+
prev[findIndex] = this.createFilter({
|
|
155
|
+
...filter,
|
|
156
|
+
type,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return prev;
|
|
160
|
+
}, []);
|
|
161
|
+
return createdFilters;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Apply filter by type
|
|
165
|
+
* @param {string} type
|
|
166
|
+
* @param {*} [value]
|
|
167
|
+
* @param {fabric.Image} [imageObj]
|
|
168
|
+
*/
|
|
169
|
+
this.applyFilterByType = (type, apply = true, value, imageObj) => {
|
|
170
|
+
const obj = imageObj || this.handler.canvas.getActiveObject();
|
|
171
|
+
const findIndex = exports.FILTER_TYPES.findIndex(ft => ft === type);
|
|
172
|
+
if (obj.filters && findIndex > -1) {
|
|
173
|
+
if (apply) {
|
|
174
|
+
obj.filters[findIndex] = this.createFilter({
|
|
175
|
+
type,
|
|
176
|
+
...value,
|
|
177
|
+
});
|
|
178
|
+
obj.applyFilters();
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
obj.filters[findIndex] = false;
|
|
182
|
+
obj.applyFilters();
|
|
183
|
+
}
|
|
184
|
+
this.handler.canvas.requestRenderAll();
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Apply filter in image
|
|
189
|
+
* @param {fabric.Image} [imageObj]
|
|
190
|
+
* @param {number} index
|
|
191
|
+
* @param {fabric.IBaseFilter} filter
|
|
192
|
+
*/
|
|
193
|
+
this.applyFilter = (index, filter, imageObj) => {
|
|
194
|
+
const obj = imageObj || this.handler.canvas.getActiveObject();
|
|
195
|
+
if (obj.filters) {
|
|
196
|
+
obj.filters[index] = filter;
|
|
197
|
+
obj.applyFilters();
|
|
198
|
+
this.handler.canvas.requestRenderAll();
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Apply filter value in image
|
|
203
|
+
* @param {fabric.Image} [imageObj]
|
|
204
|
+
* @param {number} index
|
|
205
|
+
* @param {string} prop
|
|
206
|
+
* @param {any} value
|
|
207
|
+
*/
|
|
208
|
+
this.applyFilterValue = (index, prop, value, imageObj) => {
|
|
209
|
+
const obj = imageObj || this.handler.canvas.getActiveObject();
|
|
210
|
+
if (obj.filters) {
|
|
211
|
+
const filter = obj.filters[index];
|
|
212
|
+
if (filter) {
|
|
213
|
+
filter.setOptions({
|
|
214
|
+
[prop]: value,
|
|
215
|
+
});
|
|
216
|
+
obj.applyFilters();
|
|
217
|
+
this.handler.canvas.requestRenderAll();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Apply grayscale in image
|
|
223
|
+
* @param {fabric.Image} [imageObj]
|
|
224
|
+
* @param {boolean} [grayscale=false]
|
|
225
|
+
* @param {GrayscaleModeType} [value]
|
|
226
|
+
*/
|
|
227
|
+
this.applyGrayscale = (grayscale = false, value, imageObj) => {
|
|
228
|
+
this.applyFilter(0, grayscale &&
|
|
229
|
+
new fabric_1.fabric.Image.filters.Grayscale(value
|
|
230
|
+
? {
|
|
231
|
+
mode: value,
|
|
232
|
+
}
|
|
233
|
+
: undefined), imageObj);
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Apply invert in image
|
|
237
|
+
* @param {fabric.Image} [imageObj]
|
|
238
|
+
* @param {boolean} [invert=false]
|
|
239
|
+
*/
|
|
240
|
+
this.applyInvert = (invert = false, imageObj) => {
|
|
241
|
+
this.applyFilter(1, invert && new fabric_1.fabric.Image.filters.Invert(), imageObj);
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Apply remove color in image
|
|
245
|
+
* @param {fabric.Image} [imageObj]
|
|
246
|
+
* @param {boolean} [removeColor=false]
|
|
247
|
+
* @param {RemoveColorFilter} [value]
|
|
248
|
+
*/
|
|
249
|
+
// public applyRemoveColor = (removeColor = false, value?: RemoveColorFilter, imageObj?: fabric.Image): void => {
|
|
250
|
+
// this.applyFilter(2, removeColor && new fabric.Image.filters.RemoveColor(value), imageObj);
|
|
251
|
+
// }
|
|
252
|
+
/**
|
|
253
|
+
* Apply sepia in image
|
|
254
|
+
* @param {fabric.Image} [imageObj]
|
|
255
|
+
* @param {boolean} [sepia=false]
|
|
256
|
+
*/
|
|
257
|
+
this.applySepia = (sepia = false, imageObj) => {
|
|
258
|
+
this.applyFilter(3, sepia && new fabric_1.fabric.Image.filters.Sepia(), imageObj);
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Apply brownie in image
|
|
262
|
+
* @param {boolean} [brownie=false]
|
|
263
|
+
* @param {fabric.Image} [imageObj]
|
|
264
|
+
*/
|
|
265
|
+
// public applyBrownie = (brownie = false, imageObj?: fabric.Image): void => {
|
|
266
|
+
// this.applyFilter(4, brownie && new fabric.Image.filters.Brownie(), imageObj);
|
|
267
|
+
// }
|
|
268
|
+
/**
|
|
269
|
+
* Apply brightness in image
|
|
270
|
+
* @param {boolean} [brightness=false]
|
|
271
|
+
* @param {number} [value]
|
|
272
|
+
* @param {fabric.Image} [imageObj]
|
|
273
|
+
*/
|
|
274
|
+
this.applyBrightness = (brightness = false, value, imageObj) => {
|
|
275
|
+
this.applyFilter(5, brightness &&
|
|
276
|
+
new fabric_1.fabric.Image.filters.Brightness(value
|
|
277
|
+
? {
|
|
278
|
+
brightness: value,
|
|
279
|
+
}
|
|
280
|
+
: undefined), imageObj);
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Apply contrast in image
|
|
284
|
+
* @param {boolean} [contrast=false]
|
|
285
|
+
* @param {number} [value]
|
|
286
|
+
* @param {fabric.Image} [imageObj]
|
|
287
|
+
*/
|
|
288
|
+
this.applyContrast = (contrast = false, value, imageObj) => {
|
|
289
|
+
this.applyFilter(6, contrast &&
|
|
290
|
+
new fabric_1.fabric.Image.filters.Contrast(value
|
|
291
|
+
? {
|
|
292
|
+
contrast: value,
|
|
293
|
+
}
|
|
294
|
+
: undefined), imageObj);
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* Apply saturation in image
|
|
298
|
+
* @param {boolean} [saturation=false]
|
|
299
|
+
* @param {number} [value]
|
|
300
|
+
* @param {fabric.Image} [imageObj]
|
|
301
|
+
*/
|
|
302
|
+
this.applySaturation = (saturation = false, value, imageObj) => {
|
|
303
|
+
this.applyFilter(7, saturation &&
|
|
304
|
+
new fabric_1.fabric.Image.filters.Saturation(value
|
|
305
|
+
? {
|
|
306
|
+
saturation: value,
|
|
307
|
+
}
|
|
308
|
+
: undefined), imageObj);
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Apply noise in image
|
|
312
|
+
* @param {boolean} [noise=false]
|
|
313
|
+
* @param {number} [value]
|
|
314
|
+
* @param {fabric.Image} [imageObj]
|
|
315
|
+
*/
|
|
316
|
+
this.applyNoise = (noise = false, value, imageObj) => {
|
|
317
|
+
this.applyFilter(8, noise &&
|
|
318
|
+
new fabric_1.fabric.Image.filters.Noise(value
|
|
319
|
+
? {
|
|
320
|
+
noise: value,
|
|
321
|
+
}
|
|
322
|
+
: undefined), imageObj);
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* Apply vintage in image
|
|
326
|
+
* @param {boolean} [vintage=false]
|
|
327
|
+
* @param {fabric.Image} [imageObj]
|
|
328
|
+
*/
|
|
329
|
+
// public applyVintage = (vintage = false, imageObj?: fabric.Image): void => {
|
|
330
|
+
// this.applyFilter(9, vintage && new fabric.Image.filters.Vintage(), imageObj);
|
|
331
|
+
// }
|
|
332
|
+
/**
|
|
333
|
+
* Apply pixelate in image
|
|
334
|
+
* @param {boolean} [pixelate=false]
|
|
335
|
+
* @param {number} [value]
|
|
336
|
+
* @param {fabric.Image} [imageObj]
|
|
337
|
+
*/
|
|
338
|
+
this.applyPixelate = (pixelate = false, value, imageObj) => {
|
|
339
|
+
this.applyFilter(10, pixelate &&
|
|
340
|
+
new fabric_1.fabric.Image.filters.Pixelate(value
|
|
341
|
+
? {
|
|
342
|
+
blocksize: value,
|
|
343
|
+
}
|
|
344
|
+
: undefined), imageObj);
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* Apply blur in image
|
|
348
|
+
* @param {boolean} [blur=false]
|
|
349
|
+
* @param {number} [value]
|
|
350
|
+
* @param {fabric.Image} imageObj
|
|
351
|
+
*/
|
|
352
|
+
// public applyBlur = (blur = false, value?: number, imageObj?: fabric.Image): void => {
|
|
353
|
+
// this.applyFilter(11, blur && new fabric.Image.filters.Blur(value ? {
|
|
354
|
+
// value,
|
|
355
|
+
// } : undefined), imageObj);
|
|
356
|
+
// }
|
|
357
|
+
/**
|
|
358
|
+
* Apply sharpen in image
|
|
359
|
+
* @param {boolean} [sharpen=false]
|
|
360
|
+
* @param {number[]} [value=[0, -1, 0, -1, 5, -1, 0, -1, 0]]
|
|
361
|
+
* @param {fabric.Image} [imageObj]
|
|
362
|
+
*/
|
|
363
|
+
this.applySharpen = (sharpen = false, value = SHARPEN_MATRIX, imageObj) => {
|
|
364
|
+
this.applyFilter(12, sharpen &&
|
|
365
|
+
new fabric_1.fabric.Image.filters.Convolute(value
|
|
366
|
+
? {
|
|
367
|
+
matrix: value,
|
|
368
|
+
}
|
|
369
|
+
: undefined), imageObj);
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* Apply emboss in image
|
|
373
|
+
* @param {boolean} [emboss=false]
|
|
374
|
+
* @param {number[]} [value=[1, 1, 1, 1, 0.7, -1, -1, -1, -1]]
|
|
375
|
+
* @param {fabric.Image} [imageObj]
|
|
376
|
+
*/
|
|
377
|
+
this.applyEmboss = (emboss = false, value = EMBOSS_MATRIX, imageObj) => {
|
|
378
|
+
this.applyFilter(13, emboss &&
|
|
379
|
+
new fabric_1.fabric.Image.filters.Convolute(value
|
|
380
|
+
? {
|
|
381
|
+
matrix: value,
|
|
382
|
+
}
|
|
383
|
+
: undefined), imageObj);
|
|
384
|
+
};
|
|
385
|
+
/**
|
|
386
|
+
* Apply technicolor in image
|
|
387
|
+
* @param {boolean} [technicolor=false]
|
|
388
|
+
* @param {fabric.Image} [imageObj]
|
|
389
|
+
*/
|
|
390
|
+
// public applyTechnicolor = (technicolor = false, imageObj?: fabric.Image): void => {
|
|
391
|
+
// this.applyFilter(14, technicolor && new fabric.Image.filters.Technicolor(), imageObj);
|
|
392
|
+
// }
|
|
393
|
+
/**
|
|
394
|
+
* Apply polaroid in image
|
|
395
|
+
* @param {boolean} [polaroid=false]
|
|
396
|
+
* @param {fabric.Image} [imageObj]
|
|
397
|
+
*/
|
|
398
|
+
// public applyPolaroid = (polaroid = false, imageObj?: fabric.Image): void => {
|
|
399
|
+
// this.applyFilter(15, polaroid && new fabric.Image.filters.Polaroid(), imageObj);
|
|
400
|
+
// }
|
|
401
|
+
/**
|
|
402
|
+
* Apply blend color in image
|
|
403
|
+
* @param {boolean} [blend=false]
|
|
404
|
+
* @param {BlendColorFilter} [value]
|
|
405
|
+
* @param {fabric.Image} [imageObj]
|
|
406
|
+
*/
|
|
407
|
+
this.applyBlendColor = (blend = false, value, imageObj) => {
|
|
408
|
+
this.applyFilter(16, blend && new fabric_1.fabric.Image.filters.BlendColor(value), imageObj);
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* Apply gamma in image
|
|
412
|
+
* @param {boolean} [gamma=false]
|
|
413
|
+
* @param {GammaFilter} [value]
|
|
414
|
+
* @param {fabric.Image} [imageObj]
|
|
415
|
+
*/
|
|
416
|
+
// public applyGamma = (gamma = false, value?: GammaFilter, imageObj?: fabric.Image): void => {
|
|
417
|
+
// this.applyFilter(17, gamma && new fabric.Image.filters.Gamma(value), imageObj);
|
|
418
|
+
// }
|
|
419
|
+
/**
|
|
420
|
+
* Apply kodachrome in image
|
|
421
|
+
* @param {boolean} [kodachrome=false]
|
|
422
|
+
* @param {fabric.Image} [imageObj]
|
|
423
|
+
*/
|
|
424
|
+
// public applyKodachrome = (kodachrome = false, imageObj?: fabric.Image): void => {
|
|
425
|
+
// this.applyFilter(18, kodachrome && new fabric.Image.filters.Kodachrome(), imageObj);
|
|
426
|
+
// }
|
|
427
|
+
/**
|
|
428
|
+
* Apply black white in image
|
|
429
|
+
* @param {boolean} [blackWhite=false]
|
|
430
|
+
* @param {fabric.Image} [imageObj]
|
|
431
|
+
*/
|
|
432
|
+
// public applyBlackWhite = (blackWhite = false, imageObj?: fabric.Image): void => {
|
|
433
|
+
// this.applyFilter(19, blackWhite && new fabric.Image.filters.BlackWhite(), imageObj);
|
|
434
|
+
// }
|
|
435
|
+
/**
|
|
436
|
+
* Apply blend image in image
|
|
437
|
+
* @param {boolean} [blendImage=false]
|
|
438
|
+
* @param {BlendImageFilter} value
|
|
439
|
+
* @param {fabric.Image} [imageObj]
|
|
440
|
+
*/
|
|
441
|
+
this.applyBlendImage = (blendImage = false, value, imageObj) => {
|
|
442
|
+
this.applyFilter(20, blendImage && new fabric_1.fabric.Image.filters.BlendImage(value), imageObj);
|
|
443
|
+
};
|
|
444
|
+
/**
|
|
445
|
+
* Apply hue rotation in image
|
|
446
|
+
* @param {boolean} [hue=false]
|
|
447
|
+
* @param {HueRotationFilter} [value]
|
|
448
|
+
* @param {fabric.Image} [imageObj]
|
|
449
|
+
*/
|
|
450
|
+
// public applyHue = (hue = false, value?: HueRotationFilter, imageObj?: fabric.Image): void => {
|
|
451
|
+
// this.applyFilter(21, hue && new fabric.Image.filters.HueRotation(value ? {
|
|
452
|
+
// rotation: value,
|
|
453
|
+
// } : undefined), imageObj);
|
|
454
|
+
// }
|
|
455
|
+
/**
|
|
456
|
+
* Apply resize in image
|
|
457
|
+
* @param {boolean} [resize=false]
|
|
458
|
+
* @param {ResizeFilter} [value]
|
|
459
|
+
* @param {fabric.Image} [imageObj]
|
|
460
|
+
*/
|
|
461
|
+
this.applyResize = (resize = false, value, imageObj) => {
|
|
462
|
+
this.applyFilter(22, resize && new fabric_1.fabric.Image.filters.Resize(value), imageObj);
|
|
463
|
+
};
|
|
464
|
+
/**
|
|
465
|
+
* Apply tint in image
|
|
466
|
+
* @param {boolean} [tint=false]
|
|
467
|
+
* @param {TintFilter} [value]
|
|
468
|
+
* @param {fabric.Image} [imageObj]
|
|
469
|
+
*/
|
|
470
|
+
this.applyTint = (tint = false, value, imageObj) => {
|
|
471
|
+
this.applyFilter(23, tint && new fabric_1.fabric.Image.filters.Tint(value), imageObj);
|
|
472
|
+
};
|
|
473
|
+
/**
|
|
474
|
+
* Apply mask in image
|
|
475
|
+
* @param {boolean} [mask=false]
|
|
476
|
+
* @param {MaskFilter} [value]
|
|
477
|
+
* @param {fabric.Image} [imageObj]
|
|
478
|
+
*/
|
|
479
|
+
this.applyMask = (mask = false, value, imageObj) => {
|
|
480
|
+
this.applyFilter(24, mask && new fabric_1.fabric.Image.filters.Mask(value), imageObj);
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Apply multiply in image
|
|
484
|
+
* @param {boolean} [multiply=false]
|
|
485
|
+
* @param {MultiplyFilter} [value]
|
|
486
|
+
* @param {fabric.Image} [imageObj]
|
|
487
|
+
*/
|
|
488
|
+
this.applyMultiply = (multiply = false, value, imageObj) => {
|
|
489
|
+
this.applyFilter(25, multiply && new fabric_1.fabric.Image.filters.Multiply(value), imageObj);
|
|
490
|
+
};
|
|
491
|
+
/**
|
|
492
|
+
* Apply sepia2 in image
|
|
493
|
+
* @param {boolean} [sepia2=false]
|
|
494
|
+
* @param {fabric.Image} [imageObj]
|
|
495
|
+
*/
|
|
496
|
+
this.applySepia2 = (sepia2 = false, imageObj) => {
|
|
497
|
+
this.applyFilter(26, sepia2 && new fabric_1.fabric.Image.filters.Sepia2(), imageObj);
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* Apply gradient transparency in image
|
|
501
|
+
* @param {boolean} [gradientTransparency=false]
|
|
502
|
+
* @param {GradientTransparencyFilter} [value]
|
|
503
|
+
* @param {fabric.Image} [imageObj]
|
|
504
|
+
*/
|
|
505
|
+
this.applyGradientTransparency = (gradientTransparency = false, value, imageObj) => {
|
|
506
|
+
this.applyFilter(27, gradientTransparency && new fabric_1.fabric.Image.filters.GradientTransparency(value), imageObj);
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* Apply color matrix in image
|
|
510
|
+
* @param {boolean} [colorMatrix=false]
|
|
511
|
+
* @param {ColorMatrixFilter} [value]
|
|
512
|
+
* @param {fabric.Image} [imageObj]
|
|
513
|
+
*/
|
|
514
|
+
this.applyColorMatrix = (colorMatrix = false, value, imageObj) => {
|
|
515
|
+
this.applyFilter(28, colorMatrix && new fabric_1.fabric.Image.filters.ColorMatrix(value), imageObj);
|
|
516
|
+
};
|
|
517
|
+
/**
|
|
518
|
+
* Apply remove white in image
|
|
519
|
+
* @param {boolean} [removeWhite=false]
|
|
520
|
+
* @param {RemoveWhiteFilter} [value]
|
|
521
|
+
* @param {fabric.Image} [imageObj]
|
|
522
|
+
*/
|
|
523
|
+
this.applyRemoveWhite = (removeWhite = false, value, imageObj) => {
|
|
524
|
+
this.applyFilter(29, removeWhite && new fabric_1.fabric.Image.filters.RemoveWhite(value), imageObj);
|
|
525
|
+
};
|
|
526
|
+
this.handler = handler;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
exports.default = ImageHandler;
|