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,528 +1,528 @@
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
- return 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
- };
162
- /**
163
- * Apply filter by type
164
- * @param {string} type
165
- * @param {*} [value]
166
- * @param {fabric.Image} [imageObj]
167
- */
168
- this.applyFilterByType = (type, apply = true, value, imageObj) => {
169
- const obj = imageObj || this.handler.canvas.getActiveObject();
170
- const findIndex = exports.FILTER_TYPES.findIndex(ft => ft === type);
171
- if (obj.filters && findIndex > -1) {
172
- if (apply) {
173
- obj.filters[findIndex] = this.createFilter({
174
- type,
175
- ...value,
176
- });
177
- obj.applyFilters();
178
- }
179
- else {
180
- obj.filters[findIndex] = false;
181
- obj.applyFilters();
182
- }
183
- this.handler.canvas.requestRenderAll();
184
- }
185
- };
186
- /**
187
- * Apply filter in image
188
- * @param {fabric.Image} [imageObj]
189
- * @param {number} index
190
- * @param {fabric.IBaseFilter} filter
191
- */
192
- this.applyFilter = (index, filter, imageObj) => {
193
- const obj = imageObj || this.handler.canvas.getActiveObject();
194
- if (obj.filters) {
195
- obj.filters[index] = filter;
196
- obj.applyFilters();
197
- this.handler.canvas.requestRenderAll();
198
- }
199
- };
200
- /**
201
- * Apply filter value in image
202
- * @param {fabric.Image} [imageObj]
203
- * @param {number} index
204
- * @param {string} prop
205
- * @param {any} value
206
- */
207
- this.applyFilterValue = (index, prop, value, imageObj) => {
208
- const obj = imageObj || this.handler.canvas.getActiveObject();
209
- if (obj.filters) {
210
- const filter = obj.filters[index];
211
- if (filter) {
212
- filter.setOptions({
213
- [prop]: value,
214
- });
215
- obj.applyFilters();
216
- this.handler.canvas.requestRenderAll();
217
- }
218
- }
219
- };
220
- /**
221
- * Apply grayscale in image
222
- * @param {fabric.Image} [imageObj]
223
- * @param {boolean} [grayscale=false]
224
- * @param {GrayscaleModeType} [value]
225
- */
226
- this.applyGrayscale = (grayscale = false, value, imageObj) => {
227
- this.applyFilter(0, grayscale &&
228
- new fabric_1.fabric.Image.filters.Grayscale(value
229
- ? {
230
- mode: value,
231
- }
232
- : undefined), imageObj);
233
- };
234
- /**
235
- * Apply invert in image
236
- * @param {fabric.Image} [imageObj]
237
- * @param {boolean} [invert=false]
238
- */
239
- this.applyInvert = (invert = false, imageObj) => {
240
- this.applyFilter(1, invert && new fabric_1.fabric.Image.filters.Invert(), imageObj);
241
- };
242
- /**
243
- * Apply remove color in image
244
- * @param {fabric.Image} [imageObj]
245
- * @param {boolean} [removeColor=false]
246
- * @param {RemoveColorFilter} [value]
247
- */
248
- // public applyRemoveColor = (removeColor = false, value?: RemoveColorFilter, imageObj?: fabric.Image): void => {
249
- // this.applyFilter(2, removeColor && new fabric.Image.filters.RemoveColor(value), imageObj);
250
- // }
251
- /**
252
- * Apply sepia in image
253
- * @param {fabric.Image} [imageObj]
254
- * @param {boolean} [sepia=false]
255
- */
256
- this.applySepia = (sepia = false, imageObj) => {
257
- this.applyFilter(3, sepia && new fabric_1.fabric.Image.filters.Sepia(), imageObj);
258
- };
259
- /**
260
- * Apply brownie in image
261
- * @param {boolean} [brownie=false]
262
- * @param {fabric.Image} [imageObj]
263
- */
264
- // public applyBrownie = (brownie = false, imageObj?: fabric.Image): void => {
265
- // this.applyFilter(4, brownie && new fabric.Image.filters.Brownie(), imageObj);
266
- // }
267
- /**
268
- * Apply brightness in image
269
- * @param {boolean} [brightness=false]
270
- * @param {number} [value]
271
- * @param {fabric.Image} [imageObj]
272
- */
273
- this.applyBrightness = (brightness = false, value, imageObj) => {
274
- this.applyFilter(5, brightness &&
275
- new fabric_1.fabric.Image.filters.Brightness(value
276
- ? {
277
- brightness: value,
278
- }
279
- : undefined), imageObj);
280
- };
281
- /**
282
- * Apply contrast in image
283
- * @param {boolean} [contrast=false]
284
- * @param {number} [value]
285
- * @param {fabric.Image} [imageObj]
286
- */
287
- this.applyContrast = (contrast = false, value, imageObj) => {
288
- this.applyFilter(6, contrast &&
289
- new fabric_1.fabric.Image.filters.Contrast(value
290
- ? {
291
- contrast: value,
292
- }
293
- : undefined), imageObj);
294
- };
295
- /**
296
- * Apply saturation in image
297
- * @param {boolean} [saturation=false]
298
- * @param {number} [value]
299
- * @param {fabric.Image} [imageObj]
300
- */
301
- this.applySaturation = (saturation = false, value, imageObj) => {
302
- this.applyFilter(7, saturation &&
303
- new fabric_1.fabric.Image.filters.Saturation(value
304
- ? {
305
- saturation: value,
306
- }
307
- : undefined), imageObj);
308
- };
309
- /**
310
- * Apply noise in image
311
- * @param {boolean} [noise=false]
312
- * @param {number} [value]
313
- * @param {fabric.Image} [imageObj]
314
- */
315
- this.applyNoise = (noise = false, value, imageObj) => {
316
- this.applyFilter(8, noise &&
317
- new fabric_1.fabric.Image.filters.Noise(value
318
- ? {
319
- noise: value,
320
- }
321
- : undefined), imageObj);
322
- };
323
- /**
324
- * Apply vintage in image
325
- * @param {boolean} [vintage=false]
326
- * @param {fabric.Image} [imageObj]
327
- */
328
- // public applyVintage = (vintage = false, imageObj?: fabric.Image): void => {
329
- // this.applyFilter(9, vintage && new fabric.Image.filters.Vintage(), imageObj);
330
- // }
331
- /**
332
- * Apply pixelate in image
333
- * @param {boolean} [pixelate=false]
334
- * @param {number} [value]
335
- * @param {fabric.Image} [imageObj]
336
- */
337
- this.applyPixelate = (pixelate = false, value, imageObj) => {
338
- this.applyFilter(10, pixelate &&
339
- new fabric_1.fabric.Image.filters.Pixelate(value
340
- ? {
341
- blocksize: value,
342
- }
343
- : undefined), imageObj);
344
- };
345
- /**
346
- * Apply blur in image
347
- * @param {boolean} [blur=false]
348
- * @param {number} [value]
349
- * @param {fabric.Image} imageObj
350
- */
351
- // public applyBlur = (blur = false, value?: number, imageObj?: fabric.Image): void => {
352
- // this.applyFilter(11, blur && new fabric.Image.filters.Blur(value ? {
353
- // value,
354
- // } : undefined), imageObj);
355
- // }
356
- /**
357
- * Apply sharpen in image
358
- * @param {boolean} [sharpen=false]
359
- * @param {number[]} [value=[0, -1, 0, -1, 5, -1, 0, -1, 0]]
360
- * @param {fabric.Image} [imageObj]
361
- */
362
- this.applySharpen = (sharpen = false, value = SHARPEN_MATRIX, imageObj) => {
363
- this.applyFilter(12, sharpen &&
364
- new fabric_1.fabric.Image.filters.Convolute(value
365
- ? {
366
- matrix: value,
367
- }
368
- : undefined), imageObj);
369
- };
370
- /**
371
- * Apply emboss in image
372
- * @param {boolean} [emboss=false]
373
- * @param {number[]} [value=[1, 1, 1, 1, 0.7, -1, -1, -1, -1]]
374
- * @param {fabric.Image} [imageObj]
375
- */
376
- this.applyEmboss = (emboss = false, value = EMBOSS_MATRIX, imageObj) => {
377
- this.applyFilter(13, emboss &&
378
- new fabric_1.fabric.Image.filters.Convolute(value
379
- ? {
380
- matrix: value,
381
- }
382
- : undefined), imageObj);
383
- };
384
- /**
385
- * Apply technicolor in image
386
- * @param {boolean} [technicolor=false]
387
- * @param {fabric.Image} [imageObj]
388
- */
389
- // public applyTechnicolor = (technicolor = false, imageObj?: fabric.Image): void => {
390
- // this.applyFilter(14, technicolor && new fabric.Image.filters.Technicolor(), imageObj);
391
- // }
392
- /**
393
- * Apply polaroid in image
394
- * @param {boolean} [polaroid=false]
395
- * @param {fabric.Image} [imageObj]
396
- */
397
- // public applyPolaroid = (polaroid = false, imageObj?: fabric.Image): void => {
398
- // this.applyFilter(15, polaroid && new fabric.Image.filters.Polaroid(), imageObj);
399
- // }
400
- /**
401
- * Apply blend color in image
402
- * @param {boolean} [blend=false]
403
- * @param {BlendColorFilter} [value]
404
- * @param {fabric.Image} [imageObj]
405
- */
406
- this.applyBlendColor = (blend = false, value, imageObj) => {
407
- this.applyFilter(16, blend && new fabric_1.fabric.Image.filters.BlendColor(value), imageObj);
408
- };
409
- /**
410
- * Apply gamma in image
411
- * @param {boolean} [gamma=false]
412
- * @param {GammaFilter} [value]
413
- * @param {fabric.Image} [imageObj]
414
- */
415
- // public applyGamma = (gamma = false, value?: GammaFilter, imageObj?: fabric.Image): void => {
416
- // this.applyFilter(17, gamma && new fabric.Image.filters.Gamma(value), imageObj);
417
- // }
418
- /**
419
- * Apply kodachrome in image
420
- * @param {boolean} [kodachrome=false]
421
- * @param {fabric.Image} [imageObj]
422
- */
423
- // public applyKodachrome = (kodachrome = false, imageObj?: fabric.Image): void => {
424
- // this.applyFilter(18, kodachrome && new fabric.Image.filters.Kodachrome(), imageObj);
425
- // }
426
- /**
427
- * Apply black white in image
428
- * @param {boolean} [blackWhite=false]
429
- * @param {fabric.Image} [imageObj]
430
- */
431
- // public applyBlackWhite = (blackWhite = false, imageObj?: fabric.Image): void => {
432
- // this.applyFilter(19, blackWhite && new fabric.Image.filters.BlackWhite(), imageObj);
433
- // }
434
- /**
435
- * Apply blend image in image
436
- * @param {boolean} [blendImage=false]
437
- * @param {BlendImageFilter} value
438
- * @param {fabric.Image} [imageObj]
439
- */
440
- this.applyBlendImage = (blendImage = false, value, imageObj) => {
441
- this.applyFilter(20, blendImage && new fabric_1.fabric.Image.filters.BlendImage(value), imageObj);
442
- };
443
- /**
444
- * Apply hue rotation in image
445
- * @param {boolean} [hue=false]
446
- * @param {HueRotationFilter} [value]
447
- * @param {fabric.Image} [imageObj]
448
- */
449
- // public applyHue = (hue = false, value?: HueRotationFilter, imageObj?: fabric.Image): void => {
450
- // this.applyFilter(21, hue && new fabric.Image.filters.HueRotation(value ? {
451
- // rotation: value,
452
- // } : undefined), imageObj);
453
- // }
454
- /**
455
- * Apply resize in image
456
- * @param {boolean} [resize=false]
457
- * @param {ResizeFilter} [value]
458
- * @param {fabric.Image} [imageObj]
459
- */
460
- this.applyResize = (resize = false, value, imageObj) => {
461
- this.applyFilter(22, resize && new fabric_1.fabric.Image.filters.Resize(value), imageObj);
462
- };
463
- /**
464
- * Apply tint in image
465
- * @param {boolean} [tint=false]
466
- * @param {TintFilter} [value]
467
- * @param {fabric.Image} [imageObj]
468
- */
469
- this.applyTint = (tint = false, value, imageObj) => {
470
- this.applyFilter(23, tint && new fabric_1.fabric.Image.filters.Tint(value), imageObj);
471
- };
472
- /**
473
- * Apply mask in image
474
- * @param {boolean} [mask=false]
475
- * @param {MaskFilter} [value]
476
- * @param {fabric.Image} [imageObj]
477
- */
478
- this.applyMask = (mask = false, value, imageObj) => {
479
- this.applyFilter(24, mask && new fabric_1.fabric.Image.filters.Mask(value), imageObj);
480
- };
481
- /**
482
- * Apply multiply in image
483
- * @param {boolean} [multiply=false]
484
- * @param {MultiplyFilter} [value]
485
- * @param {fabric.Image} [imageObj]
486
- */
487
- this.applyMultiply = (multiply = false, value, imageObj) => {
488
- this.applyFilter(25, multiply && new fabric_1.fabric.Image.filters.Multiply(value), imageObj);
489
- };
490
- /**
491
- * Apply sepia2 in image
492
- * @param {boolean} [sepia2=false]
493
- * @param {fabric.Image} [imageObj]
494
- */
495
- this.applySepia2 = (sepia2 = false, imageObj) => {
496
- this.applyFilter(26, sepia2 && new fabric_1.fabric.Image.filters.Sepia2(), imageObj);
497
- };
498
- /**
499
- * Apply gradient transparency in image
500
- * @param {boolean} [gradientTransparency=false]
501
- * @param {GradientTransparencyFilter} [value]
502
- * @param {fabric.Image} [imageObj]
503
- */
504
- this.applyGradientTransparency = (gradientTransparency = false, value, imageObj) => {
505
- this.applyFilter(27, gradientTransparency && new fabric_1.fabric.Image.filters.GradientTransparency(value), imageObj);
506
- };
507
- /**
508
- * Apply color matrix in image
509
- * @param {boolean} [colorMatrix=false]
510
- * @param {ColorMatrixFilter} [value]
511
- * @param {fabric.Image} [imageObj]
512
- */
513
- this.applyColorMatrix = (colorMatrix = false, value, imageObj) => {
514
- this.applyFilter(28, colorMatrix && new fabric_1.fabric.Image.filters.ColorMatrix(value), imageObj);
515
- };
516
- /**
517
- * Apply remove white in image
518
- * @param {boolean} [removeWhite=false]
519
- * @param {RemoveWhiteFilter} [value]
520
- * @param {fabric.Image} [imageObj]
521
- */
522
- this.applyRemoveWhite = (removeWhite = false, value, imageObj) => {
523
- this.applyFilter(29, removeWhite && new fabric_1.fabric.Image.filters.RemoveWhite(value), imageObj);
524
- };
525
- this.handler = handler;
526
- }
527
- }
528
- exports.default = ImageHandler;
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
+ return 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
+ };
162
+ /**
163
+ * Apply filter by type
164
+ * @param {string} type
165
+ * @param {*} [value]
166
+ * @param {fabric.Image} [imageObj]
167
+ */
168
+ this.applyFilterByType = (type, apply = true, value, imageObj) => {
169
+ const obj = imageObj || this.handler.canvas.getActiveObject();
170
+ const findIndex = exports.FILTER_TYPES.findIndex(ft => ft === type);
171
+ if (obj.filters && findIndex > -1) {
172
+ if (apply) {
173
+ obj.filters[findIndex] = this.createFilter({
174
+ type,
175
+ ...value,
176
+ });
177
+ obj.applyFilters();
178
+ }
179
+ else {
180
+ obj.filters[findIndex] = false;
181
+ obj.applyFilters();
182
+ }
183
+ this.handler.canvas.requestRenderAll();
184
+ }
185
+ };
186
+ /**
187
+ * Apply filter in image
188
+ * @param {fabric.Image} [imageObj]
189
+ * @param {number} index
190
+ * @param {fabric.IBaseFilter} filter
191
+ */
192
+ this.applyFilter = (index, filter, imageObj) => {
193
+ const obj = imageObj || this.handler.canvas.getActiveObject();
194
+ if (obj.filters) {
195
+ obj.filters[index] = filter;
196
+ obj.applyFilters();
197
+ this.handler.canvas.requestRenderAll();
198
+ }
199
+ };
200
+ /**
201
+ * Apply filter value in image
202
+ * @param {fabric.Image} [imageObj]
203
+ * @param {number} index
204
+ * @param {string} prop
205
+ * @param {any} value
206
+ */
207
+ this.applyFilterValue = (index, prop, value, imageObj) => {
208
+ const obj = imageObj || this.handler.canvas.getActiveObject();
209
+ if (obj.filters) {
210
+ const filter = obj.filters[index];
211
+ if (filter) {
212
+ filter.setOptions({
213
+ [prop]: value,
214
+ });
215
+ obj.applyFilters();
216
+ this.handler.canvas.requestRenderAll();
217
+ }
218
+ }
219
+ };
220
+ /**
221
+ * Apply grayscale in image
222
+ * @param {fabric.Image} [imageObj]
223
+ * @param {boolean} [grayscale=false]
224
+ * @param {GrayscaleModeType} [value]
225
+ */
226
+ this.applyGrayscale = (grayscale = false, value, imageObj) => {
227
+ this.applyFilter(0, grayscale &&
228
+ new fabric_1.fabric.Image.filters.Grayscale(value
229
+ ? {
230
+ mode: value,
231
+ }
232
+ : undefined), imageObj);
233
+ };
234
+ /**
235
+ * Apply invert in image
236
+ * @param {fabric.Image} [imageObj]
237
+ * @param {boolean} [invert=false]
238
+ */
239
+ this.applyInvert = (invert = false, imageObj) => {
240
+ this.applyFilter(1, invert && new fabric_1.fabric.Image.filters.Invert(), imageObj);
241
+ };
242
+ /**
243
+ * Apply remove color in image
244
+ * @param {fabric.Image} [imageObj]
245
+ * @param {boolean} [removeColor=false]
246
+ * @param {RemoveColorFilter} [value]
247
+ */
248
+ // public applyRemoveColor = (removeColor = false, value?: RemoveColorFilter, imageObj?: fabric.Image): void => {
249
+ // this.applyFilter(2, removeColor && new fabric.Image.filters.RemoveColor(value), imageObj);
250
+ // }
251
+ /**
252
+ * Apply sepia in image
253
+ * @param {fabric.Image} [imageObj]
254
+ * @param {boolean} [sepia=false]
255
+ */
256
+ this.applySepia = (sepia = false, imageObj) => {
257
+ this.applyFilter(3, sepia && new fabric_1.fabric.Image.filters.Sepia(), imageObj);
258
+ };
259
+ /**
260
+ * Apply brownie in image
261
+ * @param {boolean} [brownie=false]
262
+ * @param {fabric.Image} [imageObj]
263
+ */
264
+ // public applyBrownie = (brownie = false, imageObj?: fabric.Image): void => {
265
+ // this.applyFilter(4, brownie && new fabric.Image.filters.Brownie(), imageObj);
266
+ // }
267
+ /**
268
+ * Apply brightness in image
269
+ * @param {boolean} [brightness=false]
270
+ * @param {number} [value]
271
+ * @param {fabric.Image} [imageObj]
272
+ */
273
+ this.applyBrightness = (brightness = false, value, imageObj) => {
274
+ this.applyFilter(5, brightness &&
275
+ new fabric_1.fabric.Image.filters.Brightness(value
276
+ ? {
277
+ brightness: value,
278
+ }
279
+ : undefined), imageObj);
280
+ };
281
+ /**
282
+ * Apply contrast in image
283
+ * @param {boolean} [contrast=false]
284
+ * @param {number} [value]
285
+ * @param {fabric.Image} [imageObj]
286
+ */
287
+ this.applyContrast = (contrast = false, value, imageObj) => {
288
+ this.applyFilter(6, contrast &&
289
+ new fabric_1.fabric.Image.filters.Contrast(value
290
+ ? {
291
+ contrast: value,
292
+ }
293
+ : undefined), imageObj);
294
+ };
295
+ /**
296
+ * Apply saturation in image
297
+ * @param {boolean} [saturation=false]
298
+ * @param {number} [value]
299
+ * @param {fabric.Image} [imageObj]
300
+ */
301
+ this.applySaturation = (saturation = false, value, imageObj) => {
302
+ this.applyFilter(7, saturation &&
303
+ new fabric_1.fabric.Image.filters.Saturation(value
304
+ ? {
305
+ saturation: value,
306
+ }
307
+ : undefined), imageObj);
308
+ };
309
+ /**
310
+ * Apply noise in image
311
+ * @param {boolean} [noise=false]
312
+ * @param {number} [value]
313
+ * @param {fabric.Image} [imageObj]
314
+ */
315
+ this.applyNoise = (noise = false, value, imageObj) => {
316
+ this.applyFilter(8, noise &&
317
+ new fabric_1.fabric.Image.filters.Noise(value
318
+ ? {
319
+ noise: value,
320
+ }
321
+ : undefined), imageObj);
322
+ };
323
+ /**
324
+ * Apply vintage in image
325
+ * @param {boolean} [vintage=false]
326
+ * @param {fabric.Image} [imageObj]
327
+ */
328
+ // public applyVintage = (vintage = false, imageObj?: fabric.Image): void => {
329
+ // this.applyFilter(9, vintage && new fabric.Image.filters.Vintage(), imageObj);
330
+ // }
331
+ /**
332
+ * Apply pixelate in image
333
+ * @param {boolean} [pixelate=false]
334
+ * @param {number} [value]
335
+ * @param {fabric.Image} [imageObj]
336
+ */
337
+ this.applyPixelate = (pixelate = false, value, imageObj) => {
338
+ this.applyFilter(10, pixelate &&
339
+ new fabric_1.fabric.Image.filters.Pixelate(value
340
+ ? {
341
+ blocksize: value,
342
+ }
343
+ : undefined), imageObj);
344
+ };
345
+ /**
346
+ * Apply blur in image
347
+ * @param {boolean} [blur=false]
348
+ * @param {number} [value]
349
+ * @param {fabric.Image} imageObj
350
+ */
351
+ // public applyBlur = (blur = false, value?: number, imageObj?: fabric.Image): void => {
352
+ // this.applyFilter(11, blur && new fabric.Image.filters.Blur(value ? {
353
+ // value,
354
+ // } : undefined), imageObj);
355
+ // }
356
+ /**
357
+ * Apply sharpen in image
358
+ * @param {boolean} [sharpen=false]
359
+ * @param {number[]} [value=[0, -1, 0, -1, 5, -1, 0, -1, 0]]
360
+ * @param {fabric.Image} [imageObj]
361
+ */
362
+ this.applySharpen = (sharpen = false, value = SHARPEN_MATRIX, imageObj) => {
363
+ this.applyFilter(12, sharpen &&
364
+ new fabric_1.fabric.Image.filters.Convolute(value
365
+ ? {
366
+ matrix: value,
367
+ }
368
+ : undefined), imageObj);
369
+ };
370
+ /**
371
+ * Apply emboss in image
372
+ * @param {boolean} [emboss=false]
373
+ * @param {number[]} [value=[1, 1, 1, 1, 0.7, -1, -1, -1, -1]]
374
+ * @param {fabric.Image} [imageObj]
375
+ */
376
+ this.applyEmboss = (emboss = false, value = EMBOSS_MATRIX, imageObj) => {
377
+ this.applyFilter(13, emboss &&
378
+ new fabric_1.fabric.Image.filters.Convolute(value
379
+ ? {
380
+ matrix: value,
381
+ }
382
+ : undefined), imageObj);
383
+ };
384
+ /**
385
+ * Apply technicolor in image
386
+ * @param {boolean} [technicolor=false]
387
+ * @param {fabric.Image} [imageObj]
388
+ */
389
+ // public applyTechnicolor = (technicolor = false, imageObj?: fabric.Image): void => {
390
+ // this.applyFilter(14, technicolor && new fabric.Image.filters.Technicolor(), imageObj);
391
+ // }
392
+ /**
393
+ * Apply polaroid in image
394
+ * @param {boolean} [polaroid=false]
395
+ * @param {fabric.Image} [imageObj]
396
+ */
397
+ // public applyPolaroid = (polaroid = false, imageObj?: fabric.Image): void => {
398
+ // this.applyFilter(15, polaroid && new fabric.Image.filters.Polaroid(), imageObj);
399
+ // }
400
+ /**
401
+ * Apply blend color in image
402
+ * @param {boolean} [blend=false]
403
+ * @param {BlendColorFilter} [value]
404
+ * @param {fabric.Image} [imageObj]
405
+ */
406
+ this.applyBlendColor = (blend = false, value, imageObj) => {
407
+ this.applyFilter(16, blend && new fabric_1.fabric.Image.filters.BlendColor(value), imageObj);
408
+ };
409
+ /**
410
+ * Apply gamma in image
411
+ * @param {boolean} [gamma=false]
412
+ * @param {GammaFilter} [value]
413
+ * @param {fabric.Image} [imageObj]
414
+ */
415
+ // public applyGamma = (gamma = false, value?: GammaFilter, imageObj?: fabric.Image): void => {
416
+ // this.applyFilter(17, gamma && new fabric.Image.filters.Gamma(value), imageObj);
417
+ // }
418
+ /**
419
+ * Apply kodachrome in image
420
+ * @param {boolean} [kodachrome=false]
421
+ * @param {fabric.Image} [imageObj]
422
+ */
423
+ // public applyKodachrome = (kodachrome = false, imageObj?: fabric.Image): void => {
424
+ // this.applyFilter(18, kodachrome && new fabric.Image.filters.Kodachrome(), imageObj);
425
+ // }
426
+ /**
427
+ * Apply black white in image
428
+ * @param {boolean} [blackWhite=false]
429
+ * @param {fabric.Image} [imageObj]
430
+ */
431
+ // public applyBlackWhite = (blackWhite = false, imageObj?: fabric.Image): void => {
432
+ // this.applyFilter(19, blackWhite && new fabric.Image.filters.BlackWhite(), imageObj);
433
+ // }
434
+ /**
435
+ * Apply blend image in image
436
+ * @param {boolean} [blendImage=false]
437
+ * @param {BlendImageFilter} value
438
+ * @param {fabric.Image} [imageObj]
439
+ */
440
+ this.applyBlendImage = (blendImage = false, value, imageObj) => {
441
+ this.applyFilter(20, blendImage && new fabric_1.fabric.Image.filters.BlendImage(value), imageObj);
442
+ };
443
+ /**
444
+ * Apply hue rotation in image
445
+ * @param {boolean} [hue=false]
446
+ * @param {HueRotationFilter} [value]
447
+ * @param {fabric.Image} [imageObj]
448
+ */
449
+ // public applyHue = (hue = false, value?: HueRotationFilter, imageObj?: fabric.Image): void => {
450
+ // this.applyFilter(21, hue && new fabric.Image.filters.HueRotation(value ? {
451
+ // rotation: value,
452
+ // } : undefined), imageObj);
453
+ // }
454
+ /**
455
+ * Apply resize in image
456
+ * @param {boolean} [resize=false]
457
+ * @param {ResizeFilter} [value]
458
+ * @param {fabric.Image} [imageObj]
459
+ */
460
+ this.applyResize = (resize = false, value, imageObj) => {
461
+ this.applyFilter(22, resize && new fabric_1.fabric.Image.filters.Resize(value), imageObj);
462
+ };
463
+ /**
464
+ * Apply tint in image
465
+ * @param {boolean} [tint=false]
466
+ * @param {TintFilter} [value]
467
+ * @param {fabric.Image} [imageObj]
468
+ */
469
+ this.applyTint = (tint = false, value, imageObj) => {
470
+ this.applyFilter(23, tint && new fabric_1.fabric.Image.filters.Tint(value), imageObj);
471
+ };
472
+ /**
473
+ * Apply mask in image
474
+ * @param {boolean} [mask=false]
475
+ * @param {MaskFilter} [value]
476
+ * @param {fabric.Image} [imageObj]
477
+ */
478
+ this.applyMask = (mask = false, value, imageObj) => {
479
+ this.applyFilter(24, mask && new fabric_1.fabric.Image.filters.Mask(value), imageObj);
480
+ };
481
+ /**
482
+ * Apply multiply in image
483
+ * @param {boolean} [multiply=false]
484
+ * @param {MultiplyFilter} [value]
485
+ * @param {fabric.Image} [imageObj]
486
+ */
487
+ this.applyMultiply = (multiply = false, value, imageObj) => {
488
+ this.applyFilter(25, multiply && new fabric_1.fabric.Image.filters.Multiply(value), imageObj);
489
+ };
490
+ /**
491
+ * Apply sepia2 in image
492
+ * @param {boolean} [sepia2=false]
493
+ * @param {fabric.Image} [imageObj]
494
+ */
495
+ this.applySepia2 = (sepia2 = false, imageObj) => {
496
+ this.applyFilter(26, sepia2 && new fabric_1.fabric.Image.filters.Sepia2(), imageObj);
497
+ };
498
+ /**
499
+ * Apply gradient transparency in image
500
+ * @param {boolean} [gradientTransparency=false]
501
+ * @param {GradientTransparencyFilter} [value]
502
+ * @param {fabric.Image} [imageObj]
503
+ */
504
+ this.applyGradientTransparency = (gradientTransparency = false, value, imageObj) => {
505
+ this.applyFilter(27, gradientTransparency && new fabric_1.fabric.Image.filters.GradientTransparency(value), imageObj);
506
+ };
507
+ /**
508
+ * Apply color matrix in image
509
+ * @param {boolean} [colorMatrix=false]
510
+ * @param {ColorMatrixFilter} [value]
511
+ * @param {fabric.Image} [imageObj]
512
+ */
513
+ this.applyColorMatrix = (colorMatrix = false, value, imageObj) => {
514
+ this.applyFilter(28, colorMatrix && new fabric_1.fabric.Image.filters.ColorMatrix(value), imageObj);
515
+ };
516
+ /**
517
+ * Apply remove white in image
518
+ * @param {boolean} [removeWhite=false]
519
+ * @param {RemoveWhiteFilter} [value]
520
+ * @param {fabric.Image} [imageObj]
521
+ */
522
+ this.applyRemoveWhite = (removeWhite = false, value, imageObj) => {
523
+ this.applyFilter(29, removeWhite && new fabric_1.fabric.Image.filters.RemoveWhite(value), imageObj);
524
+ };
525
+ this.handler = handler;
526
+ }
527
+ }
528
+ exports.default = ImageHandler;