@syncfusion/ej2-image-editor 21.2.6 → 22.1.34

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 (105) hide show
  1. package/.eslintrc.json +1 -0
  2. package/CHANGELOG.md +6 -24
  3. package/dist/ej2-image-editor.umd.min.js +2 -2
  4. package/dist/ej2-image-editor.umd.min.js.map +1 -1
  5. package/dist/es6/ej2-image-editor.es2015.js +19186 -12390
  6. package/dist/es6/ej2-image-editor.es2015.js.map +1 -1
  7. package/dist/es6/ej2-image-editor.es5.js +19217 -12390
  8. package/dist/es6/ej2-image-editor.es5.js.map +1 -1
  9. package/dist/global/ej2-image-editor.min.js +2 -2
  10. package/dist/global/ej2-image-editor.min.js.map +1 -1
  11. package/dist/global/index.d.ts +1 -1
  12. package/package.json +11 -11
  13. package/src/image-editor/action/crop.d.ts +35 -0
  14. package/src/image-editor/action/crop.js +818 -0
  15. package/src/image-editor/action/draw.d.ts +122 -0
  16. package/src/image-editor/action/draw.js +3253 -0
  17. package/src/image-editor/action/export.d.ts +23 -0
  18. package/src/image-editor/action/export.js +364 -0
  19. package/src/image-editor/action/filter.d.ts +35 -0
  20. package/src/image-editor/action/filter.js +699 -0
  21. package/src/image-editor/action/freehand-draw.d.ts +61 -0
  22. package/src/image-editor/action/freehand-draw.js +1015 -0
  23. package/src/image-editor/action/index.d.ts +9 -0
  24. package/src/image-editor/action/index.js +9 -0
  25. package/src/image-editor/action/selection.d.ts +140 -0
  26. package/src/image-editor/action/selection.js +4689 -0
  27. package/src/image-editor/action/shape.d.ts +93 -0
  28. package/src/image-editor/action/shape.js +2657 -0
  29. package/src/image-editor/action/transform.d.ts +67 -0
  30. package/src/image-editor/action/transform.js +1670 -0
  31. package/src/image-editor/action/undo-redo.d.ts +43 -0
  32. package/src/image-editor/action/undo-redo.js +800 -0
  33. package/src/image-editor/base/enum.d.ts +189 -0
  34. package/src/image-editor/base/enum.js +198 -0
  35. package/src/image-editor/{image-editor-model.d.ts → base/image-editor-model.d.ts} +131 -43
  36. package/src/image-editor/{image-editor.d.ts → base/image-editor.d.ts} +425 -1108
  37. package/src/image-editor/base/image-editor.js +2458 -0
  38. package/src/image-editor/base/index.d.ts +4 -0
  39. package/src/image-editor/base/index.js +2 -0
  40. package/src/image-editor/base/interface.d.ts +1120 -0
  41. package/src/image-editor/base/interface.js +1 -0
  42. package/src/image-editor/index.d.ts +3 -5
  43. package/src/image-editor/index.js +3 -4
  44. package/src/image-editor/renderer/index.d.ts +1 -0
  45. package/src/image-editor/renderer/index.js +1 -0
  46. package/src/image-editor/renderer/toolbar.d.ts +105 -0
  47. package/src/image-editor/renderer/toolbar.js +3019 -0
  48. package/styles/bootstrap-dark.css +69 -3
  49. package/styles/bootstrap.css +69 -3
  50. package/styles/bootstrap4.css +69 -3
  51. package/styles/bootstrap5-dark.css +69 -3
  52. package/styles/bootstrap5.css +69 -3
  53. package/styles/fabric-dark.css +69 -3
  54. package/styles/fabric.css +69 -3
  55. package/styles/fluent-dark.css +69 -3
  56. package/styles/fluent.css +69 -3
  57. package/styles/highcontrast-light.css +69 -3
  58. package/styles/highcontrast.css +69 -7
  59. package/styles/image-editor/_layout.scss +21 -7
  60. package/styles/image-editor/_material3-dark-definition.scss +1 -0
  61. package/styles/image-editor/_material3-definition.scss +11 -0
  62. package/styles/image-editor/_theme.scss +9 -2
  63. package/styles/image-editor/bootstrap-dark.css +69 -3
  64. package/styles/image-editor/bootstrap.css +69 -3
  65. package/styles/image-editor/bootstrap4.css +69 -3
  66. package/styles/image-editor/bootstrap5-dark.css +69 -3
  67. package/styles/image-editor/bootstrap5.css +69 -3
  68. package/styles/image-editor/fabric-dark.css +69 -3
  69. package/styles/image-editor/fabric.css +69 -3
  70. package/styles/image-editor/fluent-dark.css +69 -3
  71. package/styles/image-editor/fluent.css +69 -3
  72. package/styles/image-editor/highcontrast-light.css +69 -3
  73. package/styles/image-editor/highcontrast.css +69 -7
  74. package/styles/image-editor/icons/_bootstrap-dark.scss +132 -0
  75. package/styles/image-editor/icons/_bootstrap.scss +132 -0
  76. package/styles/image-editor/icons/_bootstrap4.scss +132 -0
  77. package/styles/image-editor/icons/_bootstrap5.scss +132 -0
  78. package/styles/image-editor/icons/_fabric-dark.scss +132 -0
  79. package/styles/image-editor/icons/_fabric.scss +132 -0
  80. package/styles/image-editor/icons/_fluent.scss +132 -0
  81. package/styles/image-editor/icons/_fusionnew.scss +132 -0
  82. package/styles/image-editor/icons/_highcontrast-light.scss +132 -0
  83. package/styles/image-editor/icons/_highcontrast.scss +132 -0
  84. package/styles/image-editor/icons/_material-dark.scss +132 -0
  85. package/styles/image-editor/icons/_material.scss +132 -0
  86. package/styles/image-editor/icons/_material3-dark.scss +1 -0
  87. package/styles/image-editor/icons/_material3.scss +133 -1
  88. package/styles/image-editor/icons/_tailwind.scss +132 -0
  89. package/styles/image-editor/material-dark.css +69 -3
  90. package/styles/image-editor/material.css +69 -3
  91. package/styles/image-editor/material3-dark.css +453 -0
  92. package/styles/image-editor/material3-dark.scss +14 -0
  93. package/styles/image-editor/material3.css +509 -0
  94. package/styles/image-editor/material3.scss +14 -0
  95. package/styles/image-editor/tailwind-dark.css +69 -3
  96. package/styles/image-editor/tailwind.css +69 -3
  97. package/styles/material-dark.css +69 -3
  98. package/styles/material.css +69 -3
  99. package/styles/material3-dark.css +453 -0
  100. package/styles/material3-dark.scss +3 -0
  101. package/styles/material3.css +509 -0
  102. package/styles/material3.scss +3 -0
  103. package/styles/tailwind-dark.css +69 -3
  104. package/styles/tailwind.css +69 -3
  105. package/src/image-editor/image-editor.js +0 -14784
@@ -0,0 +1,699 @@
1
+ import { isNullOrUndefined, extend } from '@syncfusion/ej2-base';
2
+ var Filter = /** @class */ (function () {
3
+ function Filter(parent) {
4
+ this.adjustmentLevel = { brightness: 0, contrast: 0, hue: 0, opacity: 100, saturation: 0, blur: 0,
5
+ exposure: 0, sharpen: false, bw: false }; // for toolbar slider value
6
+ this.tempAdjustmentLevel = { brightness: 0, contrast: 0, hue: 0, opacity: 100, saturation: 0, blur: 0,
7
+ exposure: 0, sharpen: false, bw: false }; // for temp toolbar slider value
8
+ this.adjustmentValue = ''; // for internal slider value
9
+ this.isBrightnessAdjusted = false;
10
+ this.appliedFilter = '';
11
+ this.parent = parent;
12
+ this.addEventListener();
13
+ }
14
+ Filter.prototype.destroy = function () {
15
+ if (this.parent.isDestroyed) {
16
+ return;
17
+ }
18
+ this.removeEventListener();
19
+ };
20
+ Filter.prototype.addEventListener = function () {
21
+ this.parent.on('filter', this.filter, this);
22
+ this.parent.on('destroyed', this.destroy, this);
23
+ };
24
+ Filter.prototype.removeEventListener = function () {
25
+ this.parent.off('filter', this.filter);
26
+ this.parent.off('destroyed', this.destroy);
27
+ };
28
+ Filter.prototype.filter = function (args) {
29
+ this.updatePrivateVariables();
30
+ switch (args.prop) {
31
+ case 'finetuneImage':
32
+ this.finetuneImage(args.value['option'], args.value['value']);
33
+ break;
34
+ case 'applyImageFilter':
35
+ this.setFilter(args.value['option']);
36
+ break;
37
+ case 'update-finetunes':
38
+ this.updateFinetunes();
39
+ break;
40
+ case 'updateBrightFilter':
41
+ this.updateBrightFilter();
42
+ break;
43
+ case 'set-adjustment':
44
+ this.setAdjustment(args.value['operation']);
45
+ break;
46
+ case 'update-filter':
47
+ this.updateFilter(args.value['operation'], args.value['filter']);
48
+ break;
49
+ case 'initFilter':
50
+ this.initFilter();
51
+ break;
52
+ case 'setCurrAdjValue':
53
+ this.setCurrAdjValue(args.value['type'], args.value['value']);
54
+ break;
55
+ case 'updateAdj':
56
+ this.updateAdj(args.value['type'], args.value['value'], args.value['isPreview'], args.value['ctx']);
57
+ break;
58
+ case 'getCurrentObj':
59
+ this.getCurrentObj(args.value['object']);
60
+ break;
61
+ case 'getAdjustmentLevel':
62
+ args.value['obj']['adjustmentLevel'] = this.adjustmentLevel;
63
+ break;
64
+ case 'setAdjustmentLevel':
65
+ this.adjustmentLevel = args.value['adjustmentLevel'];
66
+ break;
67
+ case 'getTempAdjustmentLevel':
68
+ args.value['obj']['tempAdjustmentLevel'] = this.tempAdjustmentLevel;
69
+ break;
70
+ case 'setTempAdjustmentLevel':
71
+ this.tempAdjustmentLevel = args.value['tempAdjustmentLevel'];
72
+ break;
73
+ case 'setAdjustmentValue':
74
+ this.adjustmentValue = args.value['adjustmentValue'];
75
+ break;
76
+ case 'getBrightnessAdjusted':
77
+ args.value['obj']['isBrightnessAdjusted'] = this.isBrightnessAdjusted;
78
+ break;
79
+ case 'setBrightnessAdjusted':
80
+ this.isBrightnessAdjusted = args.value['isBrightnessAdjusted'];
81
+ if (this.parent.currentFilter.split('_') && this.parent.currentFilter.split('_')[1] === 'cold') {
82
+ this.isBrightnessAdjusted = false;
83
+ }
84
+ break;
85
+ case 'reset':
86
+ this.reset();
87
+ break;
88
+ }
89
+ };
90
+ Filter.prototype.updatePrivateVariables = function () {
91
+ var parent = this.parent;
92
+ if (!isNullOrUndefined(parent.lowerCanvas)) {
93
+ this.lowerContext = parent.lowerCanvas.getContext('2d');
94
+ }
95
+ };
96
+ Filter.prototype.getModuleName = function () {
97
+ return 'filter';
98
+ };
99
+ Filter.prototype.updateBrightFilter = function () {
100
+ var splitWords = this.lowerContext.filter.split(' ');
101
+ if (this.isBrightnessAdjusted && splitWords.length > 0 && !isNullOrUndefined(splitWords[4])) {
102
+ var opacityValue = parseFloat(splitWords[4].split('(')[1]);
103
+ splitWords[4] = 'opacity(' + (opacityValue - 0.3) + ')';
104
+ this.lowerContext.filter = splitWords.join(' ');
105
+ }
106
+ };
107
+ Filter.prototype.reset = function () {
108
+ this.adjustmentLevel = { brightness: 0, contrast: 0, hue: 0, opacity: 100, saturation: 0,
109
+ blur: 0, exposure: 0, sharpen: false, bw: false };
110
+ this.tempAdjustmentLevel = { brightness: 0, contrast: 0, hue: 0, opacity: 100, saturation: 0,
111
+ blur: 0, exposure: 0, sharpen: false, bw: false };
112
+ this.adjustmentValue = this.parent.getDefaultFilter();
113
+ this.isBrightnessAdjusted = false;
114
+ this.appliedFilter = '';
115
+ };
116
+ Filter.prototype.updateFinetunes = function () {
117
+ var parent = this.parent;
118
+ var fs = parent.finetuneSettings;
119
+ if (fs) {
120
+ if (fs.brightness) {
121
+ this.adjustmentLevel.brightness = fs.brightness.defaultValue;
122
+ this.tempAdjustmentLevel.brightness = fs.brightness.defaultValue;
123
+ }
124
+ if (fs.contrast) {
125
+ this.adjustmentLevel.contrast = fs.contrast.defaultValue;
126
+ this.tempAdjustmentLevel.contrast = fs.contrast.defaultValue;
127
+ }
128
+ if (fs.hue) {
129
+ this.adjustmentLevel.hue = fs.hue.defaultValue;
130
+ this.tempAdjustmentLevel.hue = fs.hue.defaultValue;
131
+ }
132
+ if (fs.saturation) {
133
+ this.adjustmentLevel.saturation = fs.saturation.defaultValue;
134
+ this.tempAdjustmentLevel.saturation = fs.saturation.defaultValue;
135
+ }
136
+ if (fs.exposure) {
137
+ this.adjustmentLevel.exposure = fs.exposure.defaultValue;
138
+ this.tempAdjustmentLevel.exposure = fs.exposure.defaultValue;
139
+ }
140
+ if (fs.opacity) {
141
+ this.adjustmentLevel.opacity = fs.opacity.defaultValue;
142
+ this.tempAdjustmentLevel.opacity = fs.opacity.defaultValue;
143
+ }
144
+ if (fs.blur) {
145
+ this.adjustmentLevel.blur = fs.blur.defaultValue;
146
+ this.tempAdjustmentLevel.blur = fs.blur.defaultValue;
147
+ }
148
+ parent.notify('draw', { prop: 'isInitialLoading', onPropertyChange: false, value: { isInitialLoading: true } });
149
+ }
150
+ };
151
+ Filter.prototype.initFilter = function () {
152
+ this.setFilterAdj('brightness', this.adjustmentLevel.brightness);
153
+ this.setFilterAdj('contrast', this.adjustmentLevel.contrast);
154
+ this.setFilterAdj('hue', this.adjustmentLevel.hue);
155
+ this.setFilterAdj('saturation', this.adjustmentLevel.saturation);
156
+ this.setFilterAdj('exposure', this.adjustmentLevel.exposure);
157
+ this.setFilterAdj('opacity', this.adjustmentLevel.opacity);
158
+ this.setFilterAdj('blur', this.adjustmentLevel.blur);
159
+ };
160
+ Filter.prototype.updateAdj = function (type, value, isPreview, ctx) {
161
+ var parent = this.parent;
162
+ this.lowerContext.clearRect(0, 0, parent.lowerCanvas.width, parent.lowerCanvas.height);
163
+ var splitWords = this.lowerContext.filter.split(' ');
164
+ var values = [];
165
+ var opacityValue;
166
+ var brightnessValue;
167
+ if (splitWords[4]) {
168
+ opacityValue = parseFloat(splitWords[4].split('(')[1]);
169
+ }
170
+ if (splitWords[0]) {
171
+ brightnessValue = parseFloat(splitWords[0].split('(')[1]);
172
+ }
173
+ var brightness = this.getFilterValue(this.adjustmentLevel.brightness);
174
+ var saturation = this.getFilterValue(this.adjustmentLevel.saturation);
175
+ var excludedTypes = ['brightness', 'contrast', 'hue', 'saturation', 'exposure', 'opacity', 'blur'];
176
+ if (excludedTypes.indexOf(type) === -1) {
177
+ if (isNullOrUndefined(isPreview) && (this.adjustmentLevel.sharpen || this.adjustmentLevel.bw)) {
178
+ parent.isUndoRedo = true;
179
+ var temp = this.lowerContext.filter;
180
+ this.lowerContext.filter = 'none';
181
+ parent.notify('shape', { prop: 'iterateObjColl', onPropertyChange: false });
182
+ parent.notify('freehand-draw', { prop: 'freehandRedraw', onPropertyChange: false,
183
+ value: { context: this.lowerContext, points: null } });
184
+ this.lowerContext.filter = temp;
185
+ parent.isUndoRedo = false;
186
+ }
187
+ }
188
+ if (brightness !== 1) {
189
+ splitWords[4] = 'opacity(' + (opacityValue - 0.3) + ')';
190
+ }
191
+ var saturate;
192
+ var bright;
193
+ var saturatePercent;
194
+ var contrast;
195
+ var saturatePercentage;
196
+ switch (type) {
197
+ case 'brightness':
198
+ if (parseFloat(splitWords[3].split('(')[1]) !== 100) {
199
+ value += 0.1;
200
+ }
201
+ splitWords[0] = 'brightness(' + value + ')';
202
+ this.adjustmentValue = splitWords.join(' ');
203
+ break;
204
+ case 'contrast':
205
+ splitWords[1] = 'contrast(' + value + '%)';
206
+ this.adjustmentValue = splitWords.join(' ');
207
+ break;
208
+ case 'hue':
209
+ splitWords[2] = 'hue-rotate(' + value + 'deg)';
210
+ this.adjustmentValue = splitWords.join(' ');
211
+ break;
212
+ case 'saturation':
213
+ splitWords[3] = 'saturate(' + value + '%)';
214
+ if (saturation !== 1) {
215
+ splitWords[0] = 'brightness(' + (brightnessValue + 0.09) + ')';
216
+ }
217
+ this.adjustmentValue = splitWords.join(' ');
218
+ break;
219
+ case 'opacity':
220
+ if (parseFloat(splitWords[0].split('(')[1]) !== 1) {
221
+ value -= 0.2;
222
+ }
223
+ splitWords[4] = 'opacity(' + value + ')';
224
+ this.adjustmentValue = splitWords.join(' ');
225
+ break;
226
+ case 'blur':
227
+ splitWords[5] = 'blur(' + value + 'px)';
228
+ this.adjustmentValue = splitWords.join(' ');
229
+ break;
230
+ case 'exposure':
231
+ if (brightness !== 1) {
232
+ splitWords[4] = 'opacity(' + (opacityValue - 0.3) + ')';
233
+ }
234
+ if (value > 1) {
235
+ value -= 1;
236
+ value += brightness;
237
+ }
238
+ else if (value < 1) {
239
+ value = 1 - value;
240
+ value = brightness - value;
241
+ }
242
+ splitWords[0] = 'brightness(' + value + ')';
243
+ this.adjustmentValue = splitWords.join(' ');
244
+ break;
245
+ case 'chrome':
246
+ saturate = this.getSaturationFilterValue(this.adjustmentLevel.saturation);
247
+ saturate *= 100;
248
+ value = saturate + (saturate * 0.4);
249
+ splitWords[3] = 'saturate(' + value + '%)';
250
+ values = this.adjustmentValue.split(' ');
251
+ splitWords[0] = values[0];
252
+ splitWords[1] = values[1];
253
+ splitWords[2] = values[2];
254
+ splitWords[4] = values[4];
255
+ splitWords[5] = values[5];
256
+ splitWords[6] = 'sepia(0%)';
257
+ splitWords[7] = 'grayscale(0%)';
258
+ splitWords[8] = 'invert(0%)';
259
+ break;
260
+ case 'cold':
261
+ // Adjusting Brightness
262
+ bright = this.getFilterValue(this.adjustmentLevel.brightness);
263
+ bright *= 100;
264
+ value = bright * 0.9;
265
+ value *= 0.01;
266
+ splitWords[0] = 'brightness(' + value + ')';
267
+ // Adjusting Contrast
268
+ contrast = this.getFilterValue(this.adjustmentLevel.contrast);
269
+ contrast *= 100;
270
+ value = contrast + (contrast * 0.5);
271
+ splitWords[1] = 'contrast(' + value + '%)';
272
+ // Adjusting Saturation
273
+ saturatePercentage = this.getSaturationFilterValue(this.adjustmentLevel.saturation);
274
+ saturatePercentage *= 100;
275
+ value = saturatePercentage;
276
+ splitWords[3] = 'saturate(' + value + '%)';
277
+ values = this.adjustmentValue.split(' ');
278
+ splitWords[2] = values[2];
279
+ splitWords[4] = values[4];
280
+ splitWords[5] = values[5];
281
+ splitWords[6] = 'sepia(0%)';
282
+ splitWords[7] = 'grayscale(0%)';
283
+ splitWords[8] = 'invert(0%)';
284
+ break;
285
+ case 'warm':
286
+ saturatePercent = this.getSaturationFilterValue(this.adjustmentLevel.saturation);
287
+ saturatePercent *= 100;
288
+ value = saturatePercent + (saturatePercent * 0.4);
289
+ splitWords[3] = 'saturate(' + value + '%)';
290
+ splitWords[6] = 'sepia(25%)';
291
+ values = this.adjustmentValue.split(' ');
292
+ splitWords[0] = values[0];
293
+ splitWords[1] = values[1];
294
+ splitWords[2] = values[2];
295
+ splitWords[4] = values[4];
296
+ splitWords[5] = values[5];
297
+ splitWords[7] = 'grayscale(0%)';
298
+ splitWords[8] = 'invert(0%)';
299
+ break;
300
+ case 'grayscale':
301
+ splitWords[7] = 'grayscale(100%)';
302
+ values = this.adjustmentValue.split(' ');
303
+ splitWords[0] = values[0];
304
+ splitWords[1] = values[1];
305
+ splitWords[2] = values[2];
306
+ splitWords[3] = values[3];
307
+ splitWords[4] = values[4];
308
+ splitWords[5] = values[5];
309
+ splitWords[6] = 'sepia(0%)';
310
+ splitWords[8] = 'invert(0%)';
311
+ break;
312
+ case 'sepia':
313
+ splitWords[6] = 'sepia(100%)';
314
+ values = this.adjustmentValue.split(' ');
315
+ splitWords[0] = values[0];
316
+ splitWords[1] = values[1];
317
+ splitWords[2] = values[2];
318
+ splitWords[3] = values[3];
319
+ splitWords[4] = values[4];
320
+ splitWords[5] = values[5];
321
+ splitWords[7] = 'grayscale(0%)';
322
+ splitWords[8] = 'invert(0%)';
323
+ break;
324
+ case 'invert':
325
+ splitWords[8] = 'invert(100%)';
326
+ values = this.adjustmentValue.split(' ');
327
+ splitWords[0] = values[0];
328
+ splitWords[1] = values[1];
329
+ splitWords[2] = values[2];
330
+ splitWords[3] = values[3];
331
+ splitWords[4] = values[4];
332
+ splitWords[5] = values[5];
333
+ splitWords[6] = 'sepia(0%)';
334
+ splitWords[7] = 'grayscale(0%)';
335
+ break;
336
+ }
337
+ if (type !== 'sharpen' && type !== 'blackandwhite') {
338
+ if (isNullOrUndefined(isPreview)) {
339
+ if (type === 'default') {
340
+ splitWords = this.getDefaultCurrentFilter(splitWords);
341
+ }
342
+ this.lowerContext.filter = splitWords.join(' ');
343
+ }
344
+ splitWords = this.setTempFilterValue(brightness, isPreview, splitWords, type);
345
+ parent.notify('draw', { prop: 'setRotateZoom', onPropertyChange: false, value: { isRotateZoom: true } });
346
+ parent.notify('draw', { prop: 'updateCurrTransState', onPropertyChange: false,
347
+ value: { type: 'initial', isPreventDestination: null, isRotatePan: null } });
348
+ this.appliedFilter = this.lowerContext.filter;
349
+ this.lowerContext.drawImage(parent.baseImg, parent.img.srcLeft, parent.img.srcTop, parent.img.srcWidth, parent.img.srcHeight, parent.img.destLeft, parent.img.destTop, parent.img.destWidth, parent.img.destHeight);
350
+ parent.notify('draw', { prop: 'updateCurrTransState', onPropertyChange: false,
351
+ value: { type: 'reverse', isPreventDestination: null, isRotatePan: null } });
352
+ parent.notify('draw', { prop: 'setRotateZoom', onPropertyChange: false, value: { isRotateZoom: false } });
353
+ if (brightness !== 1) {
354
+ splitWords[4] = 'opacity(' + opacityValue + ')';
355
+ }
356
+ else if (saturation !== 1) {
357
+ splitWords[0] = 'brightness(' + brightnessValue + ')';
358
+ }
359
+ if ((type === 'exposure' && brightness !== 1) || (type === 'saturation' && saturation !== 1)) {
360
+ splitWords[0] = 'brightness(' + brightnessValue + ')';
361
+ }
362
+ splitWords = this.setTempFilterValue(brightness, isPreview, splitWords, type);
363
+ if (isNullOrUndefined(isPreview)) {
364
+ this.lowerContext.filter = splitWords.join(' ');
365
+ }
366
+ parent.initialAdjustmentValue = splitWords.join(' ');
367
+ var tempFilter = this.lowerContext.filter;
368
+ this.lowerContext.filter = 'brightness(' + 1 + ') ' + 'contrast(' + 100 + '%) ' + 'hue-rotate(' + 0 + 'deg) ' +
369
+ 'saturate(' + 100 + '%) ' + 'opacity(' + 1 + ') ' + 'blur(' + 0 + 'px) ' + 'sepia(0%) ' + 'grayscale(0%) ' + 'invert(0%)';
370
+ parent.notify('shape', { prop: 'iterateObjColl', onPropertyChange: false });
371
+ parent.notify('freehand-draw', { prop: 'freehandRedraw', onPropertyChange: false,
372
+ value: { context: this.lowerContext, points: null } });
373
+ this.lowerContext.filter = tempFilter;
374
+ parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.lowerContext } });
375
+ if ((parent.currSelectionPoint && parent.currSelectionPoint.shape === 'crop-circle') || parent.isCircleCrop) {
376
+ parent.notify('crop', { prop: 'cropCircle', onPropertyChange: false,
377
+ value: { context: this.lowerContext, isSave: null, isFlip: null } });
378
+ }
379
+ this.isBrightnessAdjusted = brightness !== 1;
380
+ }
381
+ var filter = splitWords.join(' ');
382
+ if (ctx) {
383
+ ctx.filter = filter;
384
+ }
385
+ };
386
+ Filter.prototype.setTempFilterValue = function (brightness, isPreview, splitWords, type) {
387
+ if (isPreview) {
388
+ if (type === 'default') {
389
+ splitWords = this.getDefaultCurrentFilter(splitWords);
390
+ }
391
+ else if (brightness !== 1) {
392
+ var tempSplitWords = this.lowerContext.filter.split(' ');
393
+ tempSplitWords[4] = splitWords[4];
394
+ this.lowerContext.filter = tempSplitWords.join(' ');
395
+ }
396
+ }
397
+ return splitWords;
398
+ };
399
+ Filter.prototype.getDefaultCurrentFilter = function (splitWords) {
400
+ var values = this.adjustmentValue.split(' ');
401
+ splitWords = [
402
+ values[0],
403
+ values[1],
404
+ values[2],
405
+ values[3],
406
+ values[4],
407
+ values[5],
408
+ 'sepia(0%)',
409
+ 'grayscale(0%)',
410
+ 'invert(0%)'
411
+ ];
412
+ return splitWords;
413
+ };
414
+ Filter.prototype.getFilterValue = function (value) {
415
+ return (value === 0) ? 1 : 1 + ((value * 0.5) / 100);
416
+ };
417
+ Filter.prototype.getSaturationFilterValue = function (value) {
418
+ return value === 0 ? 1 : 1 + (value / 100);
419
+ };
420
+ Filter.prototype.setFilterAdj = function (type, value) {
421
+ var parent = this.parent;
422
+ parent.notify('freehand-draw', { prop: 'apply-pen-draw', onPropertyChange: false });
423
+ this.adjustmentLevel["" + type] = value;
424
+ var valueMap;
425
+ switch (type) {
426
+ case 'brightness':
427
+ case 'contrast':
428
+ case 'exposure':
429
+ value = this.getFilterValue(value);
430
+ if (type === 'contrast') {
431
+ value *= 100;
432
+ }
433
+ break;
434
+ case 'hue':
435
+ value *= 3;
436
+ break;
437
+ case 'saturation':
438
+ value = this.getSaturationFilterValue(value) * 100;
439
+ break;
440
+ case 'opacity':
441
+ if (value >= 50) {
442
+ value /= 100;
443
+ }
444
+ else if (value === 40) {
445
+ value = 0.45;
446
+ }
447
+ else if (value === 30) {
448
+ value = 0.40;
449
+ }
450
+ else if (value === 20) {
451
+ value = 0.35;
452
+ }
453
+ else if (value === 10) {
454
+ value = 0.30;
455
+ }
456
+ else if (value === 0) {
457
+ value = 0.25;
458
+ }
459
+ break;
460
+ case 'blur':
461
+ if (value !== 0) {
462
+ value /= 20;
463
+ // Since 0.5 is not working in blur we consider from 1
464
+ value += 0.5;
465
+ }
466
+ break;
467
+ }
468
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
469
+ var prevObj = this.getCurrentObj();
470
+ prevObj.objColl = extend([], parent.objColl, [], true);
471
+ prevObj.pointColl = extend([], parent.pointColl, [], true);
472
+ prevObj.afterCropActions = extend([], parent.afterCropActions, [], true);
473
+ var selPointCollObj = { selPointColl: null };
474
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false, value: { obj: selPointCollObj } });
475
+ prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
476
+ this.updateAdj(type, value);
477
+ var filter = this.lowerContext.filter;
478
+ this.lowerContext.filter = this.appliedFilter;
479
+ parent.notify('undo-redo', {
480
+ prop: 'updateUndoRedoColl',
481
+ onPropertyChange: false,
482
+ value: {
483
+ operation: type,
484
+ previousObj: prevObj,
485
+ previousObjColl: prevObj.objColl,
486
+ previousPointColl: prevObj.pointColl,
487
+ previousSelPointColl: prevObj.selPointColl,
488
+ previousCropObj: prevCropObj,
489
+ previousText: null,
490
+ currentText: null,
491
+ previousFilter: null,
492
+ isCircleCrop: null
493
+ }
494
+ });
495
+ this.lowerContext.filter = filter;
496
+ };
497
+ Filter.prototype.setFilter = function (type) {
498
+ var parent = this.parent;
499
+ type = type.toLowerCase();
500
+ parent.notify('freehand-draw', { prop: 'apply-pen-draw', onPropertyChange: false });
501
+ var obj = { currentFilter: this.parent.currentFilter };
502
+ var prevFilter = obj['currentFilter'];
503
+ var prevCropObj = extend({}, parent.cropObj, {}, true);
504
+ var prevObj = this.getCurrentObj();
505
+ prevObj.objColl = extend([], parent.objColl, [], true);
506
+ prevObj.pointColl = extend([], parent.pointColl, [], true);
507
+ prevObj.afterCropActions = extend([], parent.afterCropActions, [], true);
508
+ var selPointCollObj = { selPointColl: null };
509
+ parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
510
+ value: { obj: selPointCollObj } });
511
+ prevObj.selPointColl = extend([], selPointCollObj['selPointColl'], [], true);
512
+ this.updateAdj(type, null);
513
+ var filter = this.lowerContext.filter;
514
+ this.lowerContext.filter = this.appliedFilter;
515
+ parent.notify('draw', { prop: 'setImageEdited', onPropertyChange: false });
516
+ parent.notify('undo-redo', { prop: 'updateUndoRedoColl', onPropertyChange: false,
517
+ value: { operation: type, previousObj: prevObj, previousObjColl: prevObj.objColl,
518
+ previousPointColl: prevObj.pointColl, previousSelPointColl: prevObj.selPointColl,
519
+ previousCropObj: prevCropObj, previousText: null,
520
+ currentText: null, previousFilter: prevFilter, isCircleCrop: null } });
521
+ this.lowerContext.filter = filter;
522
+ };
523
+ Filter.prototype.setAdjustment = function (type) {
524
+ var splitWords = this.lowerContext.filter.split(' ');
525
+ var value;
526
+ var valueArr;
527
+ switch (type) {
528
+ case 'brightness':
529
+ valueArr = splitWords[0].split('(');
530
+ value = parseFloat(valueArr[1].split(')')[0]);
531
+ this.adjustmentLevel.brightness = this.setFilterValue(value);
532
+ break;
533
+ case 'contrast':
534
+ valueArr = splitWords[1].split('(');
535
+ value = parseFloat(valueArr[1].split(')')[0]);
536
+ value /= 100;
537
+ this.adjustmentLevel.contrast = this.setFilterValue(value);
538
+ break;
539
+ case 'hue':
540
+ valueArr = splitWords[2].split('(');
541
+ value = parseFloat(valueArr[1].split(')')[0]);
542
+ value /= 3;
543
+ this.adjustmentLevel.hue = value;
544
+ break;
545
+ case 'saturation':
546
+ valueArr = splitWords[3].split('(');
547
+ value = parseFloat(valueArr[1].split(')')[0]);
548
+ value /= 100;
549
+ this.adjustmentLevel.saturation = this.setSaturationFilterValue(value);
550
+ break;
551
+ case 'opacity':
552
+ valueArr = splitWords[4].split('(');
553
+ value = parseFloat(valueArr[1].split(')')[0]);
554
+ if (value === 0.45) {
555
+ value = 40;
556
+ }
557
+ else if (value === 0.40) {
558
+ value = 30;
559
+ }
560
+ else if (value === 0.35) {
561
+ value = 20;
562
+ }
563
+ else if (value === 0.30) {
564
+ value = 10;
565
+ }
566
+ else if (value === 0.25) {
567
+ value = 0;
568
+ }
569
+ else {
570
+ value *= 100;
571
+ }
572
+ this.adjustmentLevel.opacity = value;
573
+ break;
574
+ case 'blur':
575
+ valueArr = splitWords[5].split('(');
576
+ value = parseFloat(valueArr[1].split(')')[0]);
577
+ value *= 20;
578
+ this.adjustmentLevel.blur = value;
579
+ break;
580
+ case 'exposure':
581
+ valueArr = splitWords[0].split('(');
582
+ value = parseFloat(valueArr[1].split(')')[0]);
583
+ this.adjustmentLevel.exposure = this.setFilterValue(value);
584
+ break;
585
+ }
586
+ };
587
+ Filter.prototype.setFilterValue = function (value) {
588
+ return Math.round((value === 1) ? 0 : ((value - 1) * 100) / 0.5);
589
+ };
590
+ Filter.prototype.setSaturationFilterValue = function (value) {
591
+ return Math.round((value === 1) ? 0 : (value - 1) * 100);
592
+ };
593
+ Filter.prototype.updateFilter = function (type, previousFilter) {
594
+ var parent = this.parent;
595
+ var validTypes = ['default', 'chrome', 'cold', 'warm', 'grayscale', 'blackandwhite', 'sepia', 'invert', 'sharpen'];
596
+ if (validTypes.indexOf(type) !== -1) {
597
+ var selEle = parent.element.querySelector('.e-contextual-toolbar-wrapper .e-toolbar-item.e-selected');
598
+ if (selEle) {
599
+ selEle.classList.remove('e-selected');
600
+ }
601
+ var filterCanvas = document.getElementById(parent.element.id + '_' + type + 'Canvas');
602
+ if (filterCanvas) {
603
+ filterCanvas.parentElement.classList.add('e-selected');
604
+ }
605
+ this.parent.currentFilter = previousFilter ? previousFilter : parent.element.id + '_' + type;
606
+ }
607
+ };
608
+ Filter.prototype.finetuneImage = function (finetuneOption, value) {
609
+ var parent = this.parent;
610
+ if (!parent.disabled && parent.isImageLoaded) {
611
+ switch (finetuneOption.toLowerCase()) {
612
+ case 'brightness':
613
+ this.setFilterAdj('brightness', value);
614
+ break;
615
+ case 'contrast':
616
+ this.setFilterAdj('contrast', value);
617
+ break;
618
+ case 'hue':
619
+ this.setFilterAdj('hue', value);
620
+ break;
621
+ case 'saturation':
622
+ this.setFilterAdj('saturation', value);
623
+ break;
624
+ case 'opacity':
625
+ this.setFilterAdj('opacity', value);
626
+ break;
627
+ case 'blur':
628
+ this.setFilterAdj('blur', value);
629
+ break;
630
+ case 'exposure':
631
+ this.setFilterAdj('exposure', value);
632
+ break;
633
+ }
634
+ this.parent.canvasFilter = this.lowerContext.filter;
635
+ parent.notify('undo-redo', { prop: 'updateCurrUrc', value: { type: 'ok' } });
636
+ }
637
+ };
638
+ Filter.prototype.setCurrAdjValue = function (type, value) {
639
+ this.parent.notify('draw', { prop: 'setImageEdited', onPropertyChange: false });
640
+ switch (type) {
641
+ case 'brightness':
642
+ this.setFilterAdj('brightness', value);
643
+ break;
644
+ case 'contrast':
645
+ this.setFilterAdj('contrast', value);
646
+ break;
647
+ case 'hue':
648
+ this.setFilterAdj('hue', value);
649
+ break;
650
+ case 'saturation':
651
+ this.setFilterAdj('saturation', value);
652
+ break;
653
+ case 'opacity':
654
+ this.setFilterAdj('opacity', value);
655
+ break;
656
+ case 'blur':
657
+ this.setFilterAdj('blur', value);
658
+ break;
659
+ case 'exposure':
660
+ this.setFilterAdj('exposure', value);
661
+ break;
662
+ }
663
+ };
664
+ Filter.prototype.getCurrentObj = function (dummyObj) {
665
+ var parent = this.parent;
666
+ var tempFlipPanPointObj = { point: null };
667
+ parent.notify('crop', { prop: 'getTempFlipPanPoint', value: { obj: tempFlipPanPointObj } });
668
+ var zoomObj = { previousZoomValue: null };
669
+ parent.notify('transform', { prop: 'getPreviousZoomValue', value: { obj: zoomObj } });
670
+ var obj = { cropZoom: 0, defaultZoom: 0, totalPannedPoint: { x: 0, y: 0 }, totalPannedClientPoint: { x: 0, y: 0 },
671
+ totalPannedInternalPoint: { x: 0, y: 0 }, tempFlipPanPoint: { x: 0, y: 0 }, activeObj: {},
672
+ rotateFlipColl: [], degree: 0, currFlipState: '', zoomFactor: 0, previousZoomValue: 0,
673
+ destPoints: { startX: 0, startY: 0, width: 0, height: 0 },
674
+ srcPoints: { startX: 0, startY: 0, width: 0, height: 0 }, filter: '' };
675
+ obj.cropZoom = parent.transform.cropZoomFactor;
676
+ obj.defaultZoom = parent.transform.defaultZoomFactor;
677
+ obj.zoomFactor = parent.zoomSettings.zoomFactor;
678
+ obj.previousZoomValue = zoomObj['previousZoomValue'];
679
+ obj.totalPannedPoint = extend({}, parent.panPoint.totalPannedPoint, {}, true);
680
+ obj.totalPannedClientPoint = extend({}, parent.panPoint.totalPannedClientPoint, {}, true);
681
+ obj.totalPannedInternalPoint = extend({}, parent.panPoint.totalPannedInternalPoint, {}, true);
682
+ obj.tempFlipPanPoint = extend({}, tempFlipPanPointObj['point'], {}, true);
683
+ obj.activeObj = extend({}, parent.activeObj, {}, true);
684
+ obj.rotateFlipColl = extend([], parent.rotateFlipColl, [], true);
685
+ obj.degree = parent.transform.degree;
686
+ obj.currFlipState = parent.transform.currFlipState;
687
+ obj.destPoints = { startX: parent.img.destLeft, startY: parent.img.destTop, endX: 0, endY: 0,
688
+ width: parent.img.destWidth, height: parent.img.destHeight };
689
+ obj.srcPoints = { startX: parent.img.srcLeft, startY: parent.img.srcTop, endX: 0, endY: 0,
690
+ width: parent.img.srcWidth, height: parent.img.srcHeight };
691
+ obj.filter = this.lowerContext.filter;
692
+ if (dummyObj) {
693
+ dummyObj['currObj'] = obj;
694
+ }
695
+ return obj;
696
+ };
697
+ return Filter;
698
+ }());
699
+ export { Filter };