ngx-image-cropper 4.0.0 → 6.0.0

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 (89) hide show
  1. package/README.md +1 -0
  2. package/esm2020/lib/component/image-cropper.component.mjs +540 -0
  3. package/esm2020/lib/image-cropper.module.mjs +26 -0
  4. package/esm2020/lib/interfaces/cropper-options.interface.mjs +2 -0
  5. package/esm2020/lib/interfaces/cropper-position.interface.mjs +2 -0
  6. package/esm2020/lib/interfaces/cropper.settings.mjs +50 -0
  7. package/esm2020/lib/interfaces/dimensions.interface.mjs +2 -0
  8. package/esm2020/lib/interfaces/exif-transform.interface.mjs +2 -0
  9. package/esm2020/lib/interfaces/image-cropped-event.interface.mjs +2 -0
  10. package/esm2020/lib/interfaces/image-transform.interface.mjs +2 -0
  11. package/esm2020/lib/interfaces/index.mjs +2 -0
  12. package/esm2020/lib/interfaces/loaded-image.interface.mjs +2 -0
  13. package/esm2020/lib/interfaces/move-start.interface.mjs +7 -0
  14. package/esm2020/lib/services/crop.service.mjs +117 -0
  15. package/esm2020/lib/services/cropper-position.service.mjs +201 -0
  16. package/esm2020/lib/services/load-image.service.mjs +168 -0
  17. package/esm2020/lib/utils/blob.utils.mjs +12 -0
  18. package/esm2020/lib/utils/exif.utils.mjs +89 -0
  19. package/esm2020/lib/utils/hammer.utils.mjs +2 -0
  20. package/esm2020/lib/utils/keyboard.utils.mjs +40 -0
  21. package/esm2020/lib/utils/resize.utils.mjs +75 -0
  22. package/esm2020/ngx-image-cropper.mjs +5 -0
  23. package/esm2020/public-api.mjs +6 -0
  24. package/fesm2015/{ngx-image-cropper.js → ngx-image-cropper.mjs} +547 -1324
  25. package/fesm2015/ngx-image-cropper.mjs.map +1 -0
  26. package/fesm2020/ngx-image-cropper.mjs +1315 -0
  27. package/fesm2020/ngx-image-cropper.mjs.map +1 -0
  28. package/lib/component/image-cropper.component.d.ts +15 -12
  29. package/lib/image-cropper.module.d.ts +6 -0
  30. package/lib/interfaces/cropper.settings.d.ts +1 -1
  31. package/lib/interfaces/index.d.ts +1 -0
  32. package/lib/services/crop.service.d.ts +4 -1
  33. package/lib/services/cropper-position.service.d.ts +3 -0
  34. package/lib/services/load-image.service.d.ts +3 -0
  35. package/lib/utils/hammer.utils.d.ts +1 -1
  36. package/ngx-image-cropper.d.ts +1 -3
  37. package/package.json +25 -15
  38. package/bundles/ngx-image-cropper.umd.js +0 -2614
  39. package/bundles/ngx-image-cropper.umd.js.map +0 -1
  40. package/bundles/ngx-image-cropper.umd.min.js +0 -16
  41. package/bundles/ngx-image-cropper.umd.min.js.map +0 -1
  42. package/esm2015/lib/component/image-cropper.component.js +0 -825
  43. package/esm2015/lib/image-cropper.module.js +0 -24
  44. package/esm2015/lib/interfaces/cropper-options.interface.js +0 -56
  45. package/esm2015/lib/interfaces/cropper-position.interface.js +0 -20
  46. package/esm2015/lib/interfaces/cropper.settings.js +0 -140
  47. package/esm2015/lib/interfaces/dimensions.interface.js +0 -16
  48. package/esm2015/lib/interfaces/exif-transform.interface.js +0 -16
  49. package/esm2015/lib/interfaces/image-cropped-event.interface.js +0 -24
  50. package/esm2015/lib/interfaces/image-transform.interface.js +0 -20
  51. package/esm2015/lib/interfaces/index.js +0 -6
  52. package/esm2015/lib/interfaces/loaded-image.interface.js +0 -18
  53. package/esm2015/lib/interfaces/move-start.interface.js +0 -37
  54. package/esm2015/lib/services/crop.service.js +0 -176
  55. package/esm2015/lib/services/cropper-position.service.js +0 -254
  56. package/esm2015/lib/services/load-image.service.js +0 -304
  57. package/esm2015/lib/utils/blob.utils.js +0 -26
  58. package/esm2015/lib/utils/exif.utils.js +0 -128
  59. package/esm2015/lib/utils/hammer.utils.js +0 -29
  60. package/esm2015/lib/utils/keyboard.utils.js +0 -58
  61. package/esm2015/lib/utils/resize.utils.js +0 -116
  62. package/esm2015/ngx-image-cropper.js +0 -13
  63. package/esm2015/public-api.js +0 -11
  64. package/esm5/lib/component/image-cropper.component.js +0 -978
  65. package/esm5/lib/image-cropper.module.js +0 -28
  66. package/esm5/lib/interfaces/cropper-options.interface.js +0 -56
  67. package/esm5/lib/interfaces/cropper-position.interface.js +0 -20
  68. package/esm5/lib/interfaces/cropper.settings.js +0 -156
  69. package/esm5/lib/interfaces/dimensions.interface.js +0 -16
  70. package/esm5/lib/interfaces/exif-transform.interface.js +0 -16
  71. package/esm5/lib/interfaces/image-cropped-event.interface.js +0 -24
  72. package/esm5/lib/interfaces/image-transform.interface.js +0 -20
  73. package/esm5/lib/interfaces/index.js +0 -6
  74. package/esm5/lib/interfaces/loaded-image.interface.js +0 -18
  75. package/esm5/lib/interfaces/move-start.interface.js +0 -37
  76. package/esm5/lib/services/crop.service.js +0 -214
  77. package/esm5/lib/services/cropper-position.service.js +0 -293
  78. package/esm5/lib/services/load-image.service.js +0 -366
  79. package/esm5/lib/utils/blob.utils.js +0 -26
  80. package/esm5/lib/utils/exif.utils.js +0 -128
  81. package/esm5/lib/utils/hammer.utils.js +0 -29
  82. package/esm5/lib/utils/keyboard.utils.js +0 -58
  83. package/esm5/lib/utils/resize.utils.js +0 -116
  84. package/esm5/ngx-image-cropper.js +0 -13
  85. package/esm5/public-api.js +0 -11
  86. package/fesm2015/ngx-image-cropper.js.map +0 -1
  87. package/fesm5/ngx-image-cropper.js +0 -2396
  88. package/fesm5/ngx-image-cropper.js.map +0 -1
  89. package/ngx-image-cropper.metadata.json +0 -1
@@ -1,2396 +0,0 @@
1
- import { __assign, __spread, __awaiter, __generator } from 'tslib';
2
- import { Injectable, ɵɵdefineInjectable, EventEmitter, isDevMode, Component, ChangeDetectionStrategy, ChangeDetectorRef, ViewChild, Input, HostBinding, Output, HostListener, NgModule } from '@angular/core';
3
- import { DomSanitizer } from '@angular/platform-browser';
4
- import { CommonModule } from '@angular/common';
5
-
6
- /**
7
- * @fileoverview added by tsickle
8
- * Generated from: lib/interfaces/move-start.interface.ts
9
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
10
- */
11
- /**
12
- * @record
13
- */
14
- function MoveStart() { }
15
- if (false) {
16
- /** @type {?} */
17
- MoveStart.prototype.active;
18
- /** @type {?} */
19
- MoveStart.prototype.type;
20
- /** @type {?} */
21
- MoveStart.prototype.position;
22
- /** @type {?} */
23
- MoveStart.prototype.x1;
24
- /** @type {?} */
25
- MoveStart.prototype.y1;
26
- /** @type {?} */
27
- MoveStart.prototype.x2;
28
- /** @type {?} */
29
- MoveStart.prototype.y2;
30
- /** @type {?} */
31
- MoveStart.prototype.clientX;
32
- /** @type {?} */
33
- MoveStart.prototype.clientY;
34
- }
35
- /** @enum {string} */
36
- var MoveTypes = {
37
- Move: "move",
38
- Resize: "resize",
39
- Pinch: "pinch",
40
- };
41
-
42
- /**
43
- * @fileoverview added by tsickle
44
- * Generated from: lib/utils/resize.utils.ts
45
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
46
- */
47
- /*
48
- * Hermite resize - fast image resize/resample using Hermite filter.
49
- * https://github.com/viliusle/Hermite-resize
50
- */
51
- /**
52
- * @param {?} canvas
53
- * @param {?} width
54
- * @param {?} height
55
- * @return {?}
56
- */
57
- function resizeCanvas(canvas, width, height) {
58
- /** @type {?} */
59
- var width_source = canvas.width;
60
- /** @type {?} */
61
- var height_source = canvas.height;
62
- width = Math.round(width);
63
- height = Math.round(height);
64
- /** @type {?} */
65
- var ratio_w = width_source / width;
66
- /** @type {?} */
67
- var ratio_h = height_source / height;
68
- /** @type {?} */
69
- var ratio_w_half = Math.ceil(ratio_w / 2);
70
- /** @type {?} */
71
- var ratio_h_half = Math.ceil(ratio_h / 2);
72
- /** @type {?} */
73
- var ctx = canvas.getContext('2d');
74
- if (ctx) {
75
- /** @type {?} */
76
- var img = ctx.getImageData(0, 0, width_source, height_source);
77
- /** @type {?} */
78
- var img2 = ctx.createImageData(width, height);
79
- /** @type {?} */
80
- var data = img.data;
81
- /** @type {?} */
82
- var data2 = img2.data;
83
- for (var j = 0; j < height; j++) {
84
- for (var i = 0; i < width; i++) {
85
- /** @type {?} */
86
- var x2 = (i + j * width) * 4;
87
- /** @type {?} */
88
- var center_y = j * ratio_h;
89
- /** @type {?} */
90
- var weight = 0;
91
- /** @type {?} */
92
- var weights = 0;
93
- /** @type {?} */
94
- var weights_alpha = 0;
95
- /** @type {?} */
96
- var gx_r = 0;
97
- /** @type {?} */
98
- var gx_g = 0;
99
- /** @type {?} */
100
- var gx_b = 0;
101
- /** @type {?} */
102
- var gx_a = 0;
103
- /** @type {?} */
104
- var xx_start = Math.floor(i * ratio_w);
105
- /** @type {?} */
106
- var yy_start = Math.floor(j * ratio_h);
107
- /** @type {?} */
108
- var xx_stop = Math.ceil((i + 1) * ratio_w);
109
- /** @type {?} */
110
- var yy_stop = Math.ceil((j + 1) * ratio_h);
111
- xx_stop = Math.min(xx_stop, width_source);
112
- yy_stop = Math.min(yy_stop, height_source);
113
- for (var yy = yy_start; yy < yy_stop; yy++) {
114
- /** @type {?} */
115
- var dy = Math.abs(center_y - yy) / ratio_h_half;
116
- /** @type {?} */
117
- var center_x = i * ratio_w;
118
- /** @type {?} */
119
- var w0 = dy * dy;
120
- for (var xx = xx_start; xx < xx_stop; xx++) {
121
- /** @type {?} */
122
- var dx = Math.abs(center_x - xx) / ratio_w_half;
123
- /** @type {?} */
124
- var w = Math.sqrt(w0 + dx * dx);
125
- if (w >= 1) {
126
- //pixel too far
127
- continue;
128
- }
129
- //hermite filter
130
- weight = 2 * w * w * w - 3 * w * w + 1;
131
- /** @type {?} */
132
- var pos_x = 4 * (xx + yy * width_source);
133
- //alpha
134
- gx_a += weight * data[pos_x + 3];
135
- weights_alpha += weight;
136
- //colors
137
- if (data[pos_x + 3] < 255)
138
- weight = weight * data[pos_x + 3] / 250;
139
- gx_r += weight * data[pos_x];
140
- gx_g += weight * data[pos_x + 1];
141
- gx_b += weight * data[pos_x + 2];
142
- weights += weight;
143
- }
144
- }
145
- data2[x2] = gx_r / weights;
146
- data2[x2 + 1] = gx_g / weights;
147
- data2[x2 + 2] = gx_b / weights;
148
- data2[x2 + 3] = gx_a / weights_alpha;
149
- }
150
- }
151
- canvas.width = width;
152
- canvas.height = height;
153
- //draw
154
- ctx.putImageData(img2, 0, 0);
155
- }
156
- }
157
-
158
- /**
159
- * @fileoverview added by tsickle
160
- * Generated from: lib/services/crop.service.ts
161
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
162
- */
163
- var CropService = /** @class */ (function () {
164
- function CropService() {
165
- }
166
- /**
167
- * @param {?} sourceImage
168
- * @param {?} loadedImage
169
- * @param {?} cropper
170
- * @param {?} settings
171
- * @return {?}
172
- */
173
- CropService.prototype.crop = /**
174
- * @param {?} sourceImage
175
- * @param {?} loadedImage
176
- * @param {?} cropper
177
- * @param {?} settings
178
- * @return {?}
179
- */
180
- function (sourceImage, loadedImage, cropper, settings) {
181
- /** @type {?} */
182
- var imagePosition = this.getImagePosition(sourceImage, loadedImage, cropper, settings);
183
- /** @type {?} */
184
- var width = imagePosition.x2 - imagePosition.x1;
185
- /** @type {?} */
186
- var height = imagePosition.y2 - imagePosition.y1;
187
- /** @type {?} */
188
- var cropCanvas = (/** @type {?} */ (document.createElement('canvas')));
189
- cropCanvas.width = width;
190
- cropCanvas.height = height;
191
- /** @type {?} */
192
- var ctx = cropCanvas.getContext('2d');
193
- if (!ctx) {
194
- return;
195
- }
196
- if (settings.backgroundColor != null) {
197
- ctx.fillStyle = settings.backgroundColor;
198
- ctx.fillRect(0, 0, width, height);
199
- }
200
- /** @type {?} */
201
- var scaleX = (settings.transform.scale || 1) * (settings.transform.flipH ? -1 : 1);
202
- /** @type {?} */
203
- var scaleY = (settings.transform.scale || 1) * (settings.transform.flipV ? -1 : 1);
204
- /** @type {?} */
205
- var transformedImage = loadedImage.transformed;
206
- ctx.setTransform(scaleX, 0, 0, scaleY, transformedImage.size.width / 2, transformedImage.size.height / 2);
207
- ctx.translate(-imagePosition.x1 / scaleX, -imagePosition.y1 / scaleY);
208
- ctx.rotate((settings.transform.rotate || 0) * Math.PI / 180);
209
- ctx.drawImage(transformedImage.image, -transformedImage.size.width / 2, -transformedImage.size.height / 2);
210
- /** @type {?} */
211
- var output = {
212
- width: width, height: height,
213
- imagePosition: imagePosition,
214
- cropperPosition: __assign({}, cropper)
215
- };
216
- if (settings.containWithinAspectRatio) {
217
- output.offsetImagePosition = this.getOffsetImagePosition(sourceImage, loadedImage, cropper, settings);
218
- }
219
- /** @type {?} */
220
- var resizeRatio = this.getResizeRatio(width, height, settings);
221
- if (resizeRatio !== 1) {
222
- output.width = Math.round(width * resizeRatio);
223
- output.height = settings.maintainAspectRatio
224
- ? Math.round(output.width / settings.aspectRatio)
225
- : Math.round(height * resizeRatio);
226
- resizeCanvas(cropCanvas, output.width, output.height);
227
- }
228
- output.base64 = cropCanvas.toDataURL('image/' + settings.format, this.getQuality(settings));
229
- return output;
230
- };
231
- /**
232
- * @private
233
- * @param {?} sourceImage
234
- * @param {?} loadedImage
235
- * @param {?} cropper
236
- * @param {?} settings
237
- * @return {?}
238
- */
239
- CropService.prototype.getImagePosition = /**
240
- * @private
241
- * @param {?} sourceImage
242
- * @param {?} loadedImage
243
- * @param {?} cropper
244
- * @param {?} settings
245
- * @return {?}
246
- */
247
- function (sourceImage, loadedImage, cropper, settings) {
248
- /** @type {?} */
249
- var sourceImageElement = sourceImage.nativeElement;
250
- /** @type {?} */
251
- var ratio = loadedImage.transformed.size.width / sourceImageElement.offsetWidth;
252
- /** @type {?} */
253
- var out = {
254
- x1: Math.round(cropper.x1 * ratio),
255
- y1: Math.round(cropper.y1 * ratio),
256
- x2: Math.round(cropper.x2 * ratio),
257
- y2: Math.round(cropper.y2 * ratio)
258
- };
259
- if (!settings.containWithinAspectRatio) {
260
- out.x1 = Math.max(out.x1, 0);
261
- out.y1 = Math.max(out.y1, 0);
262
- out.x2 = Math.min(out.x2, loadedImage.transformed.size.width);
263
- out.y2 = Math.min(out.y2, loadedImage.transformed.size.height);
264
- }
265
- return out;
266
- };
267
- /**
268
- * @private
269
- * @param {?} sourceImage
270
- * @param {?} loadedImage
271
- * @param {?} cropper
272
- * @param {?} settings
273
- * @return {?}
274
- */
275
- CropService.prototype.getOffsetImagePosition = /**
276
- * @private
277
- * @param {?} sourceImage
278
- * @param {?} loadedImage
279
- * @param {?} cropper
280
- * @param {?} settings
281
- * @return {?}
282
- */
283
- function (sourceImage, loadedImage, cropper, settings) {
284
- /** @type {?} */
285
- var canvasRotation = settings.canvasRotation + loadedImage.exifTransform.rotate;
286
- /** @type {?} */
287
- var sourceImageElement = sourceImage.nativeElement;
288
- /** @type {?} */
289
- var ratio = loadedImage.transformed.size.width / sourceImageElement.offsetWidth;
290
- /** @type {?} */
291
- var offsetX;
292
- /** @type {?} */
293
- var offsetY;
294
- if (canvasRotation % 2) {
295
- offsetX = (loadedImage.transformed.size.width - loadedImage.original.size.height) / 2;
296
- offsetY = (loadedImage.transformed.size.height - loadedImage.original.size.width) / 2;
297
- }
298
- else {
299
- offsetX = (loadedImage.transformed.size.width - loadedImage.original.size.width) / 2;
300
- offsetY = (loadedImage.transformed.size.height - loadedImage.original.size.height) / 2;
301
- }
302
- /** @type {?} */
303
- var out = {
304
- x1: Math.round(cropper.x1 * ratio) - offsetX,
305
- y1: Math.round(cropper.y1 * ratio) - offsetY,
306
- x2: Math.round(cropper.x2 * ratio) - offsetX,
307
- y2: Math.round(cropper.y2 * ratio) - offsetY
308
- };
309
- if (!settings.containWithinAspectRatio) {
310
- out.x1 = Math.max(out.x1, 0);
311
- out.y1 = Math.max(out.y1, 0);
312
- out.x2 = Math.min(out.x2, loadedImage.transformed.size.width);
313
- out.y2 = Math.min(out.y2, loadedImage.transformed.size.height);
314
- }
315
- return out;
316
- };
317
- /**
318
- * @param {?} width
319
- * @param {?} height
320
- * @param {?} settings
321
- * @return {?}
322
- */
323
- CropService.prototype.getResizeRatio = /**
324
- * @param {?} width
325
- * @param {?} height
326
- * @param {?} settings
327
- * @return {?}
328
- */
329
- function (width, height, settings) {
330
- /** @type {?} */
331
- var ratioWidth = settings.resizeToWidth / width;
332
- /** @type {?} */
333
- var ratioHeight = settings.resizeToHeight / height;
334
- /** @type {?} */
335
- var ratios = new Array();
336
- if (settings.resizeToWidth > 0) {
337
- ratios.push(ratioWidth);
338
- }
339
- if (settings.resizeToHeight > 0) {
340
- ratios.push(ratioHeight);
341
- }
342
- /** @type {?} */
343
- var result = ratios.length === 0 ? 1 : Math.min.apply(Math, __spread(ratios));
344
- if (result > 1 && !settings.onlyScaleDown) {
345
- return result;
346
- }
347
- return Math.min(result, 1);
348
- };
349
- /**
350
- * @param {?} settings
351
- * @return {?}
352
- */
353
- CropService.prototype.getQuality = /**
354
- * @param {?} settings
355
- * @return {?}
356
- */
357
- function (settings) {
358
- return Math.min(1, Math.max(0, settings.imageQuality / 100));
359
- };
360
- CropService.decorators = [
361
- { type: Injectable, args: [{ providedIn: 'root' },] }
362
- ];
363
- /** @nocollapse */ CropService.ɵprov = ɵɵdefineInjectable({ factory: function CropService_Factory() { return new CropService(); }, token: CropService, providedIn: "root" });
364
- return CropService;
365
- }());
366
-
367
- /**
368
- * @fileoverview added by tsickle
369
- * Generated from: lib/interfaces/cropper.settings.ts
370
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
371
- */
372
- var CropperSettings = /** @class */ (function () {
373
- function CropperSettings() {
374
- // From options
375
- this.format = 'png';
376
- this.maintainAspectRatio = true;
377
- this.transform = {};
378
- this.aspectRatio = 1;
379
- this.resizeToWidth = 0;
380
- this.resizeToHeight = 0;
381
- this.cropperMinWidth = 0;
382
- this.cropperMinHeight = 0;
383
- this.cropperMaxHeight = 0;
384
- this.cropperMaxWidth = 0;
385
- this.cropperStaticWidth = 0;
386
- this.cropperStaticHeight = 0;
387
- this.canvasRotation = 0;
388
- this.initialStepSize = 3;
389
- this.roundCropper = false;
390
- this.onlyScaleDown = false;
391
- this.imageQuality = 92;
392
- this.autoCrop = true;
393
- this.backgroundColor = undefined;
394
- this.containWithinAspectRatio = false;
395
- this.hideResizeSquares = false;
396
- this.alignImage = 'center';
397
- // Internal
398
- this.cropperScaledMinWidth = 20;
399
- this.cropperScaledMinHeight = 20;
400
- this.cropperScaledMaxWidth = 20;
401
- this.cropperScaledMaxHeight = 20;
402
- this.stepSize = this.initialStepSize;
403
- }
404
- /**
405
- * @param {?} options
406
- * @return {?}
407
- */
408
- CropperSettings.prototype.setOptions = /**
409
- * @param {?} options
410
- * @return {?}
411
- */
412
- function (options) {
413
- var _this = this;
414
- Object.keys(options)
415
- .filter((/**
416
- * @param {?} k
417
- * @return {?}
418
- */
419
- function (k) { return k in _this; }))
420
- .forEach((/**
421
- * @param {?} k
422
- * @return {?}
423
- */
424
- function (k) { return _this[k] = options[k]; }));
425
- this.validateOptions();
426
- };
427
- /**
428
- * @param {?} changes
429
- * @return {?}
430
- */
431
- CropperSettings.prototype.setOptionsFromChanges = /**
432
- * @param {?} changes
433
- * @return {?}
434
- */
435
- function (changes) {
436
- var _this = this;
437
- Object.keys(changes)
438
- .filter((/**
439
- * @param {?} k
440
- * @return {?}
441
- */
442
- function (k) { return k in _this; }))
443
- .forEach((/**
444
- * @param {?} k
445
- * @return {?}
446
- */
447
- function (k) { return _this[k] = changes[k].currentValue; }));
448
- this.validateOptions();
449
- };
450
- /**
451
- * @private
452
- * @return {?}
453
- */
454
- CropperSettings.prototype.validateOptions = /**
455
- * @private
456
- * @return {?}
457
- */
458
- function () {
459
- if (this.maintainAspectRatio && !this.aspectRatio) {
460
- throw new Error('`aspectRatio` should > 0 when `maintainAspectRatio` is enabled');
461
- }
462
- };
463
- return CropperSettings;
464
- }());
465
- if (false) {
466
- /** @type {?} */
467
- CropperSettings.prototype.format;
468
- /** @type {?} */
469
- CropperSettings.prototype.maintainAspectRatio;
470
- /** @type {?} */
471
- CropperSettings.prototype.transform;
472
- /** @type {?} */
473
- CropperSettings.prototype.aspectRatio;
474
- /** @type {?} */
475
- CropperSettings.prototype.resizeToWidth;
476
- /** @type {?} */
477
- CropperSettings.prototype.resizeToHeight;
478
- /** @type {?} */
479
- CropperSettings.prototype.cropperMinWidth;
480
- /** @type {?} */
481
- CropperSettings.prototype.cropperMinHeight;
482
- /** @type {?} */
483
- CropperSettings.prototype.cropperMaxHeight;
484
- /** @type {?} */
485
- CropperSettings.prototype.cropperMaxWidth;
486
- /** @type {?} */
487
- CropperSettings.prototype.cropperStaticWidth;
488
- /** @type {?} */
489
- CropperSettings.prototype.cropperStaticHeight;
490
- /** @type {?} */
491
- CropperSettings.prototype.canvasRotation;
492
- /** @type {?} */
493
- CropperSettings.prototype.initialStepSize;
494
- /** @type {?} */
495
- CropperSettings.prototype.roundCropper;
496
- /** @type {?} */
497
- CropperSettings.prototype.onlyScaleDown;
498
- /** @type {?} */
499
- CropperSettings.prototype.imageQuality;
500
- /** @type {?} */
501
- CropperSettings.prototype.autoCrop;
502
- /** @type {?} */
503
- CropperSettings.prototype.backgroundColor;
504
- /** @type {?} */
505
- CropperSettings.prototype.containWithinAspectRatio;
506
- /** @type {?} */
507
- CropperSettings.prototype.hideResizeSquares;
508
- /** @type {?} */
509
- CropperSettings.prototype.alignImage;
510
- /** @type {?} */
511
- CropperSettings.prototype.cropperScaledMinWidth;
512
- /** @type {?} */
513
- CropperSettings.prototype.cropperScaledMinHeight;
514
- /** @type {?} */
515
- CropperSettings.prototype.cropperScaledMaxWidth;
516
- /** @type {?} */
517
- CropperSettings.prototype.cropperScaledMaxHeight;
518
- /** @type {?} */
519
- CropperSettings.prototype.stepSize;
520
- }
521
-
522
- /**
523
- * @fileoverview added by tsickle
524
- * Generated from: lib/utils/exif.utils.ts
525
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
526
- */
527
- // Black 2x1 JPEG, with the following meta information set:
528
- // - EXIF Orientation: 6 (Rotated 90° CCW)
529
- // Source: https://github.com/blueimp/JavaScript-Load-Image
530
- /** @type {?} */
531
- var testAutoOrientationImageURL = 'data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAA' +
532
- 'AAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA' +
533
- 'QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE' +
534
- 'BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/x' +
535
- 'ABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAA' +
536
- 'AAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==';
537
- /**
538
- * @return {?}
539
- */
540
- function supportsAutomaticRotation() {
541
- return new Promise((/**
542
- * @param {?} resolve
543
- * @return {?}
544
- */
545
- function (resolve) {
546
- /** @type {?} */
547
- var img = new Image();
548
- img.onload = (/**
549
- * @return {?}
550
- */
551
- function () {
552
- // Check if browser supports automatic image orientation:
553
- /** @type {?} */
554
- var supported = img.width === 1 && img.height === 2;
555
- resolve(supported);
556
- });
557
- img.src = testAutoOrientationImageURL;
558
- }));
559
- }
560
- /**
561
- * @param {?} exifRotationOrBase64Image
562
- * @return {?}
563
- */
564
- function getTransformationsFromExifData(exifRotationOrBase64Image) {
565
- if (typeof exifRotationOrBase64Image === 'string') {
566
- exifRotationOrBase64Image = getExifRotation(exifRotationOrBase64Image);
567
- }
568
- switch (exifRotationOrBase64Image) {
569
- case 2:
570
- return { rotate: 0, flip: true };
571
- case 3:
572
- return { rotate: 2, flip: false };
573
- case 4:
574
- return { rotate: 2, flip: true };
575
- case 5:
576
- return { rotate: 1, flip: true };
577
- case 6:
578
- return { rotate: 1, flip: false };
579
- case 7:
580
- return { rotate: 3, flip: true };
581
- case 8:
582
- return { rotate: 3, flip: false };
583
- default:
584
- return { rotate: 0, flip: false };
585
- }
586
- }
587
- /**
588
- * @param {?} imageBase64
589
- * @return {?}
590
- */
591
- function getExifRotation(imageBase64) {
592
- /** @type {?} */
593
- var view = new DataView(base64ToArrayBuffer(imageBase64));
594
- if (view.getUint16(0, false) != 0xFFD8) {
595
- return -2;
596
- }
597
- /** @type {?} */
598
- var length = view.byteLength;
599
- /** @type {?} */
600
- var offset = 2;
601
- while (offset < length) {
602
- if (view.getUint16(offset + 2, false) <= 8)
603
- return -1;
604
- /** @type {?} */
605
- var marker = view.getUint16(offset, false);
606
- offset += 2;
607
- if (marker == 0xFFE1) {
608
- if (view.getUint32(offset += 2, false) != 0x45786966) {
609
- return -1;
610
- }
611
- /** @type {?} */
612
- var little = view.getUint16(offset += 6, false) == 0x4949;
613
- offset += view.getUint32(offset + 4, little);
614
- /** @type {?} */
615
- var tags = view.getUint16(offset, little);
616
- offset += 2;
617
- for (var i = 0; i < tags; i++) {
618
- if (view.getUint16(offset + (i * 12), little) == 0x0112) {
619
- return view.getUint16(offset + (i * 12) + 8, little);
620
- }
621
- }
622
- }
623
- else if ((marker & 0xFF00) != 0xFF00) {
624
- break;
625
- }
626
- else {
627
- offset += view.getUint16(offset, false);
628
- }
629
- }
630
- return -1;
631
- }
632
- /**
633
- * @param {?} imageBase64
634
- * @return {?}
635
- */
636
- function base64ToArrayBuffer(imageBase64) {
637
- imageBase64 = imageBase64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
638
- /** @type {?} */
639
- var binaryString = atob(imageBase64);
640
- /** @type {?} */
641
- var len = binaryString.length;
642
- /** @type {?} */
643
- var bytes = new Uint8Array(len);
644
- for (var i = 0; i < len; i++) {
645
- bytes[i] = binaryString.charCodeAt(i);
646
- }
647
- return bytes.buffer;
648
- }
649
-
650
- /**
651
- * @fileoverview added by tsickle
652
- * Generated from: lib/services/load-image.service.ts
653
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
654
- */
655
- /**
656
- * @record
657
- */
658
- function LoadImageBase64() { }
659
- if (false) {
660
- /** @type {?} */
661
- LoadImageBase64.prototype.originalImage;
662
- /** @type {?} */
663
- LoadImageBase64.prototype.originalBase64;
664
- }
665
- var LoadImageService = /** @class */ (function () {
666
- function LoadImageService() {
667
- this.autoRotateSupported = supportsAutomaticRotation();
668
- }
669
- /**
670
- * @param {?} file
671
- * @param {?} cropperSettings
672
- * @return {?}
673
- */
674
- LoadImageService.prototype.loadImageFile = /**
675
- * @param {?} file
676
- * @param {?} cropperSettings
677
- * @return {?}
678
- */
679
- function (file, cropperSettings) {
680
- var _this = this;
681
- return new Promise((/**
682
- * @param {?} resolve
683
- * @param {?} reject
684
- * @return {?}
685
- */
686
- function (resolve, reject) {
687
- /** @type {?} */
688
- var fileReader = new FileReader();
689
- fileReader.onload = (/**
690
- * @param {?} event
691
- * @return {?}
692
- */
693
- function (event) {
694
- _this.loadImage(event.target.result, file.type, cropperSettings)
695
- .then(resolve)
696
- .catch(reject);
697
- });
698
- fileReader.readAsDataURL(file);
699
- }));
700
- };
701
- /**
702
- * @private
703
- * @param {?} imageBase64
704
- * @param {?} imageType
705
- * @param {?} cropperSettings
706
- * @return {?}
707
- */
708
- LoadImageService.prototype.loadImage = /**
709
- * @private
710
- * @param {?} imageBase64
711
- * @param {?} imageType
712
- * @param {?} cropperSettings
713
- * @return {?}
714
- */
715
- function (imageBase64, imageType, cropperSettings) {
716
- if (!this.isValidImageType(imageType)) {
717
- return Promise.reject(new Error('Invalid image type'));
718
- }
719
- return this.loadBase64Image(imageBase64, cropperSettings);
720
- };
721
- /**
722
- * @private
723
- * @param {?} type
724
- * @return {?}
725
- */
726
- LoadImageService.prototype.isValidImageType = /**
727
- * @private
728
- * @param {?} type
729
- * @return {?}
730
- */
731
- function (type) {
732
- return /image\/(png|jpg|jpeg|bmp|gif|tiff|webp)/.test(type);
733
- };
734
- /**
735
- * @param {?} url
736
- * @param {?} cropperSettings
737
- * @return {?}
738
- */
739
- LoadImageService.prototype.loadImageFromURL = /**
740
- * @param {?} url
741
- * @param {?} cropperSettings
742
- * @return {?}
743
- */
744
- function (url, cropperSettings) {
745
- var _this = this;
746
- return new Promise((/**
747
- * @param {?} resolve
748
- * @param {?} reject
749
- * @return {?}
750
- */
751
- function (resolve, reject) {
752
- /** @type {?} */
753
- var img = new Image();
754
- img.onerror = (/**
755
- * @return {?}
756
- */
757
- function () { return reject; });
758
- img.onload = (/**
759
- * @return {?}
760
- */
761
- function () {
762
- /** @type {?} */
763
- var canvas = document.createElement('canvas');
764
- /** @type {?} */
765
- var context = canvas.getContext('2d');
766
- canvas.width = img.width;
767
- canvas.height = img.height;
768
- context.drawImage(img, 0, 0);
769
- _this.loadBase64Image(canvas.toDataURL(), cropperSettings).then(resolve);
770
- });
771
- img.crossOrigin = 'anonymous';
772
- img.src = url;
773
- }));
774
- };
775
- /**
776
- * @param {?} imageBase64
777
- * @param {?} cropperSettings
778
- * @return {?}
779
- */
780
- LoadImageService.prototype.loadBase64Image = /**
781
- * @param {?} imageBase64
782
- * @param {?} cropperSettings
783
- * @return {?}
784
- */
785
- function (imageBase64, cropperSettings) {
786
- var _this = this;
787
- return new Promise((/**
788
- * @param {?} resolve
789
- * @param {?} reject
790
- * @return {?}
791
- */
792
- function (resolve, reject) {
793
- /** @type {?} */
794
- var originalImage = new Image();
795
- originalImage.onload = (/**
796
- * @return {?}
797
- */
798
- function () { return resolve({
799
- originalImage: originalImage,
800
- originalBase64: imageBase64
801
- }); });
802
- originalImage.onerror = reject;
803
- originalImage.src = imageBase64;
804
- })).then((/**
805
- * @param {?} res
806
- * @return {?}
807
- */
808
- function (res) { return _this.transformImageBase64(res, cropperSettings); }));
809
- };
810
- /**
811
- * @private
812
- * @param {?} res
813
- * @param {?} cropperSettings
814
- * @return {?}
815
- */
816
- LoadImageService.prototype.transformImageBase64 = /**
817
- * @private
818
- * @param {?} res
819
- * @param {?} cropperSettings
820
- * @return {?}
821
- */
822
- function (res, cropperSettings) {
823
- return __awaiter(this, void 0, void 0, function () {
824
- var autoRotate, exifTransform, loadedImage;
825
- return __generator(this, function (_a) {
826
- switch (_a.label) {
827
- case 0: return [4 /*yield*/, this.autoRotateSupported];
828
- case 1:
829
- autoRotate = _a.sent();
830
- return [4 /*yield*/, getTransformationsFromExifData(autoRotate ? -1 : res.originalBase64)];
831
- case 2:
832
- exifTransform = _a.sent();
833
- if (!res.originalImage || !res.originalImage.complete) {
834
- return [2 /*return*/, Promise.reject(new Error('No image loaded'))];
835
- }
836
- loadedImage = {
837
- original: {
838
- base64: res.originalBase64,
839
- image: res.originalImage,
840
- size: {
841
- width: res.originalImage.naturalWidth,
842
- height: res.originalImage.naturalHeight
843
- }
844
- },
845
- exifTransform: exifTransform
846
- };
847
- return [2 /*return*/, this.transformLoadedImage(loadedImage, cropperSettings)];
848
- }
849
- });
850
- });
851
- };
852
- /**
853
- * @param {?} loadedImage
854
- * @param {?} cropperSettings
855
- * @return {?}
856
- */
857
- LoadImageService.prototype.transformLoadedImage = /**
858
- * @param {?} loadedImage
859
- * @param {?} cropperSettings
860
- * @return {?}
861
- */
862
- function (loadedImage, cropperSettings) {
863
- return __awaiter(this, void 0, void 0, function () {
864
- var canvasRotation, originalSize, transformedSize, canvas, ctx, transformedBase64, transformedImage;
865
- return __generator(this, function (_a) {
866
- switch (_a.label) {
867
- case 0:
868
- canvasRotation = cropperSettings.canvasRotation + loadedImage.exifTransform.rotate;
869
- originalSize = {
870
- width: loadedImage.original.image.naturalWidth,
871
- height: loadedImage.original.image.naturalHeight
872
- };
873
- if (canvasRotation === 0 && !loadedImage.exifTransform.flip && !cropperSettings.containWithinAspectRatio) {
874
- return [2 /*return*/, {
875
- original: {
876
- base64: loadedImage.original.base64,
877
- image: loadedImage.original.image,
878
- size: __assign({}, originalSize)
879
- },
880
- transformed: {
881
- base64: loadedImage.original.base64,
882
- image: loadedImage.original.image,
883
- size: __assign({}, originalSize)
884
- },
885
- exifTransform: loadedImage.exifTransform
886
- }];
887
- }
888
- transformedSize = this.getTransformedSize(originalSize, loadedImage.exifTransform, cropperSettings);
889
- canvas = document.createElement('canvas');
890
- canvas.width = transformedSize.width;
891
- canvas.height = transformedSize.height;
892
- ctx = canvas.getContext('2d');
893
- ctx.setTransform(loadedImage.exifTransform.flip ? -1 : 1, 0, 0, 1, canvas.width / 2, canvas.height / 2);
894
- ctx.rotate(Math.PI * (canvasRotation / 2));
895
- ctx.drawImage(loadedImage.original.image, -originalSize.width / 2, -originalSize.height / 2);
896
- transformedBase64 = canvas.toDataURL();
897
- return [4 /*yield*/, this.loadImageFromBase64(transformedBase64)];
898
- case 1:
899
- transformedImage = _a.sent();
900
- return [2 /*return*/, {
901
- original: {
902
- base64: loadedImage.original.base64,
903
- image: loadedImage.original.image,
904
- size: __assign({}, originalSize)
905
- },
906
- transformed: {
907
- base64: transformedBase64,
908
- image: transformedImage,
909
- size: {
910
- width: transformedImage.width,
911
- height: transformedImage.height
912
- }
913
- },
914
- exifTransform: loadedImage.exifTransform
915
- }];
916
- }
917
- });
918
- });
919
- };
920
- /**
921
- * @private
922
- * @param {?} imageBase64
923
- * @return {?}
924
- */
925
- LoadImageService.prototype.loadImageFromBase64 = /**
926
- * @private
927
- * @param {?} imageBase64
928
- * @return {?}
929
- */
930
- function (imageBase64) {
931
- return new Promise(((/**
932
- * @param {?} resolve
933
- * @param {?} reject
934
- * @return {?}
935
- */
936
- function (resolve, reject) {
937
- /** @type {?} */
938
- var image = new Image();
939
- image.onload = (/**
940
- * @return {?}
941
- */
942
- function () { return resolve(image); });
943
- image.onerror = reject;
944
- image.src = imageBase64;
945
- })));
946
- };
947
- /**
948
- * @private
949
- * @param {?} originalSize
950
- * @param {?} exifTransform
951
- * @param {?} cropperSettings
952
- * @return {?}
953
- */
954
- LoadImageService.prototype.getTransformedSize = /**
955
- * @private
956
- * @param {?} originalSize
957
- * @param {?} exifTransform
958
- * @param {?} cropperSettings
959
- * @return {?}
960
- */
961
- function (originalSize, exifTransform, cropperSettings) {
962
- /** @type {?} */
963
- var canvasRotation = cropperSettings.canvasRotation + exifTransform.rotate;
964
- if (cropperSettings.containWithinAspectRatio) {
965
- if (canvasRotation % 2) {
966
- /** @type {?} */
967
- var minWidthToContain = originalSize.width * cropperSettings.aspectRatio;
968
- /** @type {?} */
969
- var minHeightToContain = originalSize.height / cropperSettings.aspectRatio;
970
- return {
971
- width: Math.max(originalSize.height, minWidthToContain),
972
- height: Math.max(originalSize.width, minHeightToContain)
973
- };
974
- }
975
- else {
976
- /** @type {?} */
977
- var minWidthToContain = originalSize.height * cropperSettings.aspectRatio;
978
- /** @type {?} */
979
- var minHeightToContain = originalSize.width / cropperSettings.aspectRatio;
980
- return {
981
- width: Math.max(originalSize.width, minWidthToContain),
982
- height: Math.max(originalSize.height, minHeightToContain)
983
- };
984
- }
985
- }
986
- if (canvasRotation % 2) {
987
- return {
988
- height: originalSize.width,
989
- width: originalSize.height
990
- };
991
- }
992
- return {
993
- width: originalSize.width,
994
- height: originalSize.height
995
- };
996
- };
997
- LoadImageService.decorators = [
998
- { type: Injectable, args: [{ providedIn: 'root' },] }
999
- ];
1000
- /** @nocollapse */ LoadImageService.ɵprov = ɵɵdefineInjectable({ factory: function LoadImageService_Factory() { return new LoadImageService(); }, token: LoadImageService, providedIn: "root" });
1001
- return LoadImageService;
1002
- }());
1003
- if (false) {
1004
- /**
1005
- * @type {?}
1006
- * @private
1007
- */
1008
- LoadImageService.prototype.autoRotateSupported;
1009
- }
1010
-
1011
- /**
1012
- * @fileoverview added by tsickle
1013
- * Generated from: lib/services/cropper-position.service.ts
1014
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1015
- */
1016
- var CropperPositionService = /** @class */ (function () {
1017
- function CropperPositionService() {
1018
- }
1019
- /**
1020
- * @param {?} sourceImage
1021
- * @param {?} cropperPosition
1022
- * @param {?} settings
1023
- * @return {?}
1024
- */
1025
- CropperPositionService.prototype.resetCropperPosition = /**
1026
- * @param {?} sourceImage
1027
- * @param {?} cropperPosition
1028
- * @param {?} settings
1029
- * @return {?}
1030
- */
1031
- function (sourceImage, cropperPosition, settings) {
1032
- /** @type {?} */
1033
- var sourceImageElement = sourceImage.nativeElement;
1034
- if (settings.cropperStaticHeight && settings.cropperStaticWidth) {
1035
- cropperPosition.x1 = 0;
1036
- cropperPosition.x2 = sourceImageElement.offsetWidth > settings.cropperStaticWidth ?
1037
- settings.cropperStaticWidth : sourceImageElement.offsetWidth;
1038
- cropperPosition.y1 = 0;
1039
- cropperPosition.y2 = sourceImageElement.offsetHeight > settings.cropperStaticHeight ?
1040
- settings.cropperStaticHeight : sourceImageElement.offsetHeight;
1041
- }
1042
- else {
1043
- /** @type {?} */
1044
- var cropperWidth = Math.min(settings.cropperScaledMaxWidth, sourceImageElement.offsetWidth);
1045
- /** @type {?} */
1046
- var cropperHeight = Math.min(settings.cropperScaledMaxHeight, sourceImageElement.offsetHeight);
1047
- if (!settings.maintainAspectRatio) {
1048
- cropperPosition.x1 = 0;
1049
- cropperPosition.x2 = cropperWidth;
1050
- cropperPosition.y1 = 0;
1051
- cropperPosition.y2 = cropperHeight;
1052
- }
1053
- else if (cropperWidth / settings.aspectRatio < cropperHeight) {
1054
- cropperPosition.x1 = 0;
1055
- cropperPosition.x2 = cropperWidth;
1056
- /** @type {?} */
1057
- var cropperHeightWithAspectRatio = cropperWidth / settings.aspectRatio;
1058
- cropperPosition.y1 = (sourceImageElement.offsetHeight - cropperHeightWithAspectRatio) / 2;
1059
- cropperPosition.y2 = cropperPosition.y1 + cropperHeightWithAspectRatio;
1060
- }
1061
- else {
1062
- cropperPosition.y1 = 0;
1063
- cropperPosition.y2 = cropperHeight;
1064
- /** @type {?} */
1065
- var cropperWidthWithAspectRatio = cropperHeight * settings.aspectRatio;
1066
- cropperPosition.x1 = (sourceImageElement.offsetWidth - cropperWidthWithAspectRatio) / 2;
1067
- cropperPosition.x2 = cropperPosition.x1 + cropperWidthWithAspectRatio;
1068
- }
1069
- }
1070
- };
1071
- /**
1072
- * @param {?} event
1073
- * @param {?} moveStart
1074
- * @param {?} cropperPosition
1075
- * @return {?}
1076
- */
1077
- CropperPositionService.prototype.move = /**
1078
- * @param {?} event
1079
- * @param {?} moveStart
1080
- * @param {?} cropperPosition
1081
- * @return {?}
1082
- */
1083
- function (event, moveStart, cropperPosition) {
1084
- /** @type {?} */
1085
- var diffX = this.getClientX(event) - moveStart.clientX;
1086
- /** @type {?} */
1087
- var diffY = this.getClientY(event) - moveStart.clientY;
1088
- cropperPosition.x1 = moveStart.x1 + diffX;
1089
- cropperPosition.y1 = moveStart.y1 + diffY;
1090
- cropperPosition.x2 = moveStart.x2 + diffX;
1091
- cropperPosition.y2 = moveStart.y2 + diffY;
1092
- };
1093
- /**
1094
- * @param {?} event
1095
- * @param {?} moveStart
1096
- * @param {?} cropperPosition
1097
- * @param {?} maxSize
1098
- * @param {?} settings
1099
- * @return {?}
1100
- */
1101
- CropperPositionService.prototype.resize = /**
1102
- * @param {?} event
1103
- * @param {?} moveStart
1104
- * @param {?} cropperPosition
1105
- * @param {?} maxSize
1106
- * @param {?} settings
1107
- * @return {?}
1108
- */
1109
- function (event, moveStart, cropperPosition, maxSize, settings) {
1110
- /** @type {?} */
1111
- var moveX = this.getClientX(event) - moveStart.clientX;
1112
- /** @type {?} */
1113
- var moveY = this.getClientY(event) - moveStart.clientY;
1114
- switch (moveStart.position) {
1115
- case 'left':
1116
- cropperPosition.x1 = Math.min(Math.max(moveStart.x1 + moveX, cropperPosition.x2 - settings.cropperScaledMaxWidth), cropperPosition.x2 - settings.cropperScaledMinWidth);
1117
- break;
1118
- case 'topleft':
1119
- cropperPosition.x1 = Math.min(Math.max(moveStart.x1 + moveX, cropperPosition.x2 - settings.cropperScaledMaxWidth), cropperPosition.x2 - settings.cropperScaledMinWidth);
1120
- cropperPosition.y1 = Math.min(Math.max(moveStart.y1 + moveY, cropperPosition.y2 - settings.cropperScaledMaxHeight), cropperPosition.y2 - settings.cropperScaledMinHeight);
1121
- break;
1122
- case 'top':
1123
- cropperPosition.y1 = Math.min(Math.max(moveStart.y1 + moveY, cropperPosition.y2 - settings.cropperScaledMaxHeight), cropperPosition.y2 - settings.cropperScaledMinHeight);
1124
- break;
1125
- case 'topright':
1126
- cropperPosition.x2 = Math.max(Math.min(moveStart.x2 + moveX, cropperPosition.x1 + settings.cropperScaledMaxWidth), cropperPosition.x1 + settings.cropperScaledMinWidth);
1127
- cropperPosition.y1 = Math.min(Math.max(moveStart.y1 + moveY, cropperPosition.y2 - settings.cropperScaledMaxHeight), cropperPosition.y2 - settings.cropperScaledMinHeight);
1128
- break;
1129
- case 'right':
1130
- cropperPosition.x2 = Math.max(Math.min(moveStart.x2 + moveX, cropperPosition.x1 + settings.cropperScaledMaxWidth), cropperPosition.x1 + settings.cropperScaledMinWidth);
1131
- break;
1132
- case 'bottomright':
1133
- cropperPosition.x2 = Math.max(Math.min(moveStart.x2 + moveX, cropperPosition.x1 + settings.cropperScaledMaxWidth), cropperPosition.x1 + settings.cropperScaledMinWidth);
1134
- cropperPosition.y2 = Math.max(Math.min(moveStart.y2 + moveY, cropperPosition.y1 + settings.cropperScaledMaxHeight), cropperPosition.y1 + settings.cropperScaledMinHeight);
1135
- break;
1136
- case 'bottom':
1137
- cropperPosition.y2 = Math.max(Math.min(moveStart.y2 + moveY, cropperPosition.y1 + settings.cropperScaledMaxHeight), cropperPosition.y1 + settings.cropperScaledMinHeight);
1138
- break;
1139
- case 'bottomleft':
1140
- cropperPosition.x1 = Math.min(Math.max(moveStart.x1 + moveX, cropperPosition.x2 - settings.cropperScaledMaxWidth), cropperPosition.x2 - settings.cropperScaledMinWidth);
1141
- cropperPosition.y2 = Math.max(Math.min(moveStart.y2 + moveY, cropperPosition.y1 + settings.cropperScaledMaxHeight), cropperPosition.y1 + settings.cropperScaledMinHeight);
1142
- break;
1143
- case 'center':
1144
- /** @type {?} */
1145
- var scale = event.scale;
1146
- /** @type {?} */
1147
- var newWidth = Math.min(Math.max(settings.cropperScaledMinWidth, (Math.abs(moveStart.x2 - moveStart.x1)) * scale), settings.cropperScaledMaxWidth);
1148
- /** @type {?} */
1149
- var newHeight = Math.min(Math.max(settings.cropperScaledMinHeight, (Math.abs(moveStart.y2 - moveStart.y1)) * scale), settings.cropperScaledMaxHeight);
1150
- cropperPosition.x1 = moveStart.clientX - newWidth / 2;
1151
- cropperPosition.x2 = moveStart.clientX + newWidth / 2;
1152
- cropperPosition.y1 = moveStart.clientY - newHeight / 2;
1153
- cropperPosition.y2 = moveStart.clientY + newHeight / 2;
1154
- if (cropperPosition.x1 < 0) {
1155
- cropperPosition.x2 -= cropperPosition.x1;
1156
- cropperPosition.x1 = 0;
1157
- }
1158
- else if (cropperPosition.x2 > maxSize.width) {
1159
- cropperPosition.x1 -= (cropperPosition.x2 - maxSize.width);
1160
- cropperPosition.x2 = maxSize.width;
1161
- }
1162
- if (cropperPosition.y1 < 0) {
1163
- cropperPosition.y2 -= cropperPosition.y1;
1164
- cropperPosition.y1 = 0;
1165
- }
1166
- else if (cropperPosition.y2 > maxSize.height) {
1167
- cropperPosition.y1 -= (cropperPosition.y2 - maxSize.height);
1168
- cropperPosition.y2 = maxSize.height;
1169
- }
1170
- break;
1171
- }
1172
- if (settings.maintainAspectRatio) {
1173
- this.checkAspectRatio(moveStart.position, cropperPosition, maxSize, settings);
1174
- }
1175
- };
1176
- /**
1177
- * @param {?} position
1178
- * @param {?} cropperPosition
1179
- * @param {?} maxSize
1180
- * @param {?} settings
1181
- * @return {?}
1182
- */
1183
- CropperPositionService.prototype.checkAspectRatio = /**
1184
- * @param {?} position
1185
- * @param {?} cropperPosition
1186
- * @param {?} maxSize
1187
- * @param {?} settings
1188
- * @return {?}
1189
- */
1190
- function (position, cropperPosition, maxSize, settings) {
1191
- /** @type {?} */
1192
- var overflowX = 0;
1193
- /** @type {?} */
1194
- var overflowY = 0;
1195
- switch (position) {
1196
- case 'top':
1197
- cropperPosition.x2 = cropperPosition.x1 + (cropperPosition.y2 - cropperPosition.y1) * settings.aspectRatio;
1198
- overflowX = Math.max(cropperPosition.x2 - maxSize.width, 0);
1199
- overflowY = Math.max(0 - cropperPosition.y1, 0);
1200
- if (overflowX > 0 || overflowY > 0) {
1201
- cropperPosition.x2 -= (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
1202
- cropperPosition.y1 += (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
1203
- }
1204
- break;
1205
- case 'bottom':
1206
- cropperPosition.x2 = cropperPosition.x1 + (cropperPosition.y2 - cropperPosition.y1) * settings.aspectRatio;
1207
- overflowX = Math.max(cropperPosition.x2 - maxSize.width, 0);
1208
- overflowY = Math.max(cropperPosition.y2 - maxSize.height, 0);
1209
- if (overflowX > 0 || overflowY > 0) {
1210
- cropperPosition.x2 -= (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
1211
- cropperPosition.y2 -= (overflowY * settings.aspectRatio) > overflowX ? overflowY : (overflowX / settings.aspectRatio);
1212
- }
1213
- break;
1214
- case 'topleft':
1215
- cropperPosition.y1 = cropperPosition.y2 - (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
1216
- overflowX = Math.max(0 - cropperPosition.x1, 0);
1217
- overflowY = Math.max(0 - cropperPosition.y1, 0);
1218
- if (overflowX > 0 || overflowY > 0) {
1219
- cropperPosition.x1 += (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
1220
- cropperPosition.y1 += (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
1221
- }
1222
- break;
1223
- case 'topright':
1224
- cropperPosition.y1 = cropperPosition.y2 - (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
1225
- overflowX = Math.max(cropperPosition.x2 - maxSize.width, 0);
1226
- overflowY = Math.max(0 - cropperPosition.y1, 0);
1227
- if (overflowX > 0 || overflowY > 0) {
1228
- cropperPosition.x2 -= (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
1229
- cropperPosition.y1 += (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
1230
- }
1231
- break;
1232
- case 'right':
1233
- case 'bottomright':
1234
- cropperPosition.y2 = cropperPosition.y1 + (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
1235
- overflowX = Math.max(cropperPosition.x2 - maxSize.width, 0);
1236
- overflowY = Math.max(cropperPosition.y2 - maxSize.height, 0);
1237
- if (overflowX > 0 || overflowY > 0) {
1238
- cropperPosition.x2 -= (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
1239
- cropperPosition.y2 -= (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
1240
- }
1241
- break;
1242
- case 'left':
1243
- case 'bottomleft':
1244
- cropperPosition.y2 = cropperPosition.y1 + (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
1245
- overflowX = Math.max(0 - cropperPosition.x1, 0);
1246
- overflowY = Math.max(cropperPosition.y2 - maxSize.height, 0);
1247
- if (overflowX > 0 || overflowY > 0) {
1248
- cropperPosition.x1 += (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
1249
- cropperPosition.y2 -= (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
1250
- }
1251
- break;
1252
- case 'center':
1253
- cropperPosition.x2 = cropperPosition.x1 + (cropperPosition.y2 - cropperPosition.y1) * settings.aspectRatio;
1254
- cropperPosition.y2 = cropperPosition.y1 + (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
1255
- /** @type {?} */
1256
- var overflowX1 = Math.max(0 - cropperPosition.x1, 0);
1257
- /** @type {?} */
1258
- var overflowX2 = Math.max(cropperPosition.x2 - maxSize.width, 0);
1259
- /** @type {?} */
1260
- var overflowY1 = Math.max(cropperPosition.y2 - maxSize.height, 0);
1261
- /** @type {?} */
1262
- var overflowY2 = Math.max(0 - cropperPosition.y1, 0);
1263
- if (overflowX1 > 0 || overflowX2 > 0 || overflowY1 > 0 || overflowY2 > 0) {
1264
- cropperPosition.x1 += (overflowY1 * settings.aspectRatio) > overflowX1 ? (overflowY1 * settings.aspectRatio) : overflowX1;
1265
- cropperPosition.x2 -= (overflowY2 * settings.aspectRatio) > overflowX2 ? (overflowY2 * settings.aspectRatio) : overflowX2;
1266
- cropperPosition.y1 += (overflowY2 * settings.aspectRatio) > overflowX2 ? overflowY2 : overflowX2 / settings.aspectRatio;
1267
- cropperPosition.y2 -= (overflowY1 * settings.aspectRatio) > overflowX1 ? overflowY1 : overflowX1 / settings.aspectRatio;
1268
- }
1269
- break;
1270
- }
1271
- };
1272
- /**
1273
- * @param {?} event
1274
- * @return {?}
1275
- */
1276
- CropperPositionService.prototype.getClientX = /**
1277
- * @param {?} event
1278
- * @return {?}
1279
- */
1280
- function (event) {
1281
- return (event.touches && event.touches[0] ? event.touches[0].clientX : event.clientX) || 0;
1282
- };
1283
- /**
1284
- * @param {?} event
1285
- * @return {?}
1286
- */
1287
- CropperPositionService.prototype.getClientY = /**
1288
- * @param {?} event
1289
- * @return {?}
1290
- */
1291
- function (event) {
1292
- return (event.touches && event.touches[0] ? event.touches[0].clientY : event.clientY) || 0;
1293
- };
1294
- CropperPositionService.decorators = [
1295
- { type: Injectable, args: [{ providedIn: 'root' },] }
1296
- ];
1297
- /** @nocollapse */ CropperPositionService.ɵprov = ɵɵdefineInjectable({ factory: function CropperPositionService_Factory() { return new CropperPositionService(); }, token: CropperPositionService, providedIn: "root" });
1298
- return CropperPositionService;
1299
- }());
1300
-
1301
- /**
1302
- * @fileoverview added by tsickle
1303
- * Generated from: lib/utils/keyboard.utils.ts
1304
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1305
- */
1306
- /**
1307
- * @param {?} key
1308
- * @return {?}
1309
- */
1310
- function getPositionForKey(key) {
1311
- switch (key) {
1312
- case 'ArrowUp':
1313
- return 'top';
1314
- case 'ArrowRight':
1315
- return 'right';
1316
- case 'ArrowDown':
1317
- return 'bottom';
1318
- case 'ArrowLeft':
1319
- default:
1320
- return 'left';
1321
- }
1322
- }
1323
- /**
1324
- * @param {?} key
1325
- * @return {?}
1326
- */
1327
- function getInvertedPositionForKey(key) {
1328
- switch (key) {
1329
- case 'ArrowUp':
1330
- return 'bottom';
1331
- case 'ArrowRight':
1332
- return 'left';
1333
- case 'ArrowDown':
1334
- return 'top';
1335
- case 'ArrowLeft':
1336
- default:
1337
- return 'right';
1338
- }
1339
- }
1340
- /**
1341
- * @param {?} key
1342
- * @param {?} stepSize
1343
- * @return {?}
1344
- */
1345
- function getEventForKey(key, stepSize) {
1346
- switch (key) {
1347
- case 'ArrowUp':
1348
- return { clientX: 0, clientY: stepSize * -1 };
1349
- case 'ArrowRight':
1350
- return { clientX: stepSize, clientY: 0 };
1351
- case 'ArrowDown':
1352
- return { clientX: 0, clientY: stepSize };
1353
- case 'ArrowLeft':
1354
- default:
1355
- return { clientX: stepSize * -1, clientY: 0 };
1356
- }
1357
- }
1358
-
1359
- /**
1360
- * @fileoverview added by tsickle
1361
- * Generated from: lib/component/image-cropper.component.ts
1362
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1363
- */
1364
- var ImageCropperComponent = /** @class */ (function () {
1365
- function ImageCropperComponent(cropService, cropperPositionService, loadImageService, sanitizer, cd) {
1366
- this.cropService = cropService;
1367
- this.cropperPositionService = cropperPositionService;
1368
- this.loadImageService = loadImageService;
1369
- this.sanitizer = sanitizer;
1370
- this.cd = cd;
1371
- this.Hammer = typeof window !== 'undefined'
1372
- ? (/** @type {?} */ (((/** @type {?} */ (window))).Hammer))
1373
- : null;
1374
- this.settings = new CropperSettings();
1375
- this.setImageMaxSizeRetries = 0;
1376
- this.marginLeft = '0px';
1377
- this.moveTypes = MoveTypes;
1378
- this.imageVisible = false;
1379
- this.format = this.settings.format;
1380
- this.transform = {};
1381
- this.maintainAspectRatio = this.settings.maintainAspectRatio;
1382
- this.aspectRatio = this.settings.aspectRatio;
1383
- this.resizeToWidth = this.settings.resizeToWidth;
1384
- this.resizeToHeight = this.settings.resizeToHeight;
1385
- this.cropperMinWidth = this.settings.cropperMinWidth;
1386
- this.cropperMinHeight = this.settings.cropperMinHeight;
1387
- this.cropperMaxHeight = this.settings.cropperMaxHeight;
1388
- this.cropperMaxWidth = this.settings.cropperMaxWidth;
1389
- this.cropperStaticWidth = this.settings.cropperStaticWidth;
1390
- this.cropperStaticHeight = this.settings.cropperStaticHeight;
1391
- this.canvasRotation = this.settings.canvasRotation;
1392
- this.initialStepSize = this.settings.initialStepSize;
1393
- this.roundCropper = this.settings.roundCropper;
1394
- this.onlyScaleDown = this.settings.onlyScaleDown;
1395
- this.imageQuality = this.settings.imageQuality;
1396
- this.autoCrop = this.settings.autoCrop;
1397
- this.backgroundColor = this.settings.backgroundColor;
1398
- this.containWithinAspectRatio = this.settings.containWithinAspectRatio;
1399
- this.hideResizeSquares = this.settings.hideResizeSquares;
1400
- this.cropper = {
1401
- x1: -100,
1402
- y1: -100,
1403
- x2: 10000,
1404
- y2: 10000
1405
- };
1406
- this.alignImage = this.settings.alignImage;
1407
- this.disabled = false;
1408
- this.imageCropped = new EventEmitter();
1409
- this.startCropImage = new EventEmitter();
1410
- this.imageLoaded = new EventEmitter();
1411
- this.cropperReady = new EventEmitter();
1412
- this.loadImageFailed = new EventEmitter();
1413
- this.reset();
1414
- }
1415
- /**
1416
- * @param {?} changes
1417
- * @return {?}
1418
- */
1419
- ImageCropperComponent.prototype.ngOnChanges = /**
1420
- * @param {?} changes
1421
- * @return {?}
1422
- */
1423
- function (changes) {
1424
- var _this = this;
1425
- this.onChangesUpdateSettings(changes);
1426
- this.onChangesInputImage(changes);
1427
- if (this.loadedImage && this.loadedImage.original.image.complete
1428
- && (changes.containWithinAspectRatio || changes.canvasRotation)) {
1429
- this.loadImageService
1430
- .transformLoadedImage(this.loadedImage, this.settings)
1431
- .then((/**
1432
- * @param {?} res
1433
- * @return {?}
1434
- */
1435
- function (res) { return _this.setLoadedImage(res); }))
1436
- .catch((/**
1437
- * @param {?} err
1438
- * @return {?}
1439
- */
1440
- function (err) { return _this.loadImageError(err); }));
1441
- }
1442
- if (changes.cropper || changes.maintainAspectRatio || changes.aspectRatio) {
1443
- this.setMaxSize();
1444
- this.setCropperScaledMinSize();
1445
- this.setCropperScaledMaxSize();
1446
- if (this.maintainAspectRatio && (changes.maintainAspectRatio || changes.aspectRatio)) {
1447
- this.resetCropperPosition();
1448
- }
1449
- else if (changes.cropper) {
1450
- this.checkCropperPosition(false);
1451
- this.doAutoCrop();
1452
- }
1453
- this.cd.markForCheck();
1454
- }
1455
- if (changes.transform) {
1456
- this.transform = this.transform || {};
1457
- this.setCssTransform();
1458
- this.doAutoCrop();
1459
- }
1460
- };
1461
- /**
1462
- * @private
1463
- * @param {?} changes
1464
- * @return {?}
1465
- */
1466
- ImageCropperComponent.prototype.onChangesUpdateSettings = /**
1467
- * @private
1468
- * @param {?} changes
1469
- * @return {?}
1470
- */
1471
- function (changes) {
1472
- this.settings.setOptionsFromChanges(changes);
1473
- if (this.settings.cropperStaticHeight && this.settings.cropperStaticWidth) {
1474
- this.settings.setOptions({
1475
- hideResizeSquares: true,
1476
- cropperMinWidth: this.settings.cropperStaticWidth,
1477
- cropperMinHeight: this.settings.cropperStaticHeight,
1478
- cropperMaxHeight: this.settings.cropperStaticHeight,
1479
- cropperMaxWidth: this.settings.cropperStaticWidth,
1480
- maintainAspectRatio: false
1481
- });
1482
- }
1483
- };
1484
- /**
1485
- * @private
1486
- * @param {?} changes
1487
- * @return {?}
1488
- */
1489
- ImageCropperComponent.prototype.onChangesInputImage = /**
1490
- * @private
1491
- * @param {?} changes
1492
- * @return {?}
1493
- */
1494
- function (changes) {
1495
- if (changes.imageChangedEvent || changes.imageURL || changes.imageBase64 || changes.imageFile) {
1496
- this.reset();
1497
- }
1498
- if (changes.imageChangedEvent && this.isValidImageChangedEvent()) {
1499
- this.loadImageFile(this.imageChangedEvent.target.files[0]);
1500
- }
1501
- if (changes.imageURL && this.imageURL) {
1502
- this.loadImageFromURL(this.imageURL);
1503
- }
1504
- if (changes.imageBase64 && this.imageBase64) {
1505
- this.loadBase64Image(this.imageBase64);
1506
- }
1507
- if (changes.imageFile && this.imageFile) {
1508
- this.loadImageFile(this.imageFile);
1509
- }
1510
- };
1511
- /**
1512
- * @private
1513
- * @return {?}
1514
- */
1515
- ImageCropperComponent.prototype.isValidImageChangedEvent = /**
1516
- * @private
1517
- * @return {?}
1518
- */
1519
- function () {
1520
- return this.imageChangedEvent
1521
- && this.imageChangedEvent.target
1522
- && this.imageChangedEvent.target.files
1523
- && this.imageChangedEvent.target.files.length > 0;
1524
- };
1525
- /**
1526
- * @private
1527
- * @return {?}
1528
- */
1529
- ImageCropperComponent.prototype.setCssTransform = /**
1530
- * @private
1531
- * @return {?}
1532
- */
1533
- function () {
1534
- this.safeTransformStyle = this.sanitizer.bypassSecurityTrustStyle('scaleX(' + (this.transform.scale || 1) * (this.transform.flipH ? -1 : 1) + ')' +
1535
- 'scaleY(' + (this.transform.scale || 1) * (this.transform.flipV ? -1 : 1) + ')' +
1536
- 'rotate(' + (this.transform.rotate || 0) + 'deg)');
1537
- };
1538
- /**
1539
- * @return {?}
1540
- */
1541
- ImageCropperComponent.prototype.ngOnInit = /**
1542
- * @return {?}
1543
- */
1544
- function () {
1545
- this.settings.stepSize = this.initialStepSize;
1546
- this.activatePinchGesture();
1547
- };
1548
- /**
1549
- * @private
1550
- * @return {?}
1551
- */
1552
- ImageCropperComponent.prototype.reset = /**
1553
- * @private
1554
- * @return {?}
1555
- */
1556
- function () {
1557
- this.imageVisible = false;
1558
- this.loadedImage = null;
1559
- this.safeImgDataUrl = 'data:image/png;base64,iVBORw0KGg'
1560
- + 'oAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAU'
1561
- + 'AAarVyFEAAAAASUVORK5CYII=';
1562
- this.moveStart = {
1563
- active: false,
1564
- type: null,
1565
- position: null,
1566
- x1: 0,
1567
- y1: 0,
1568
- x2: 0,
1569
- y2: 0,
1570
- clientX: 0,
1571
- clientY: 0
1572
- };
1573
- this.maxSize = {
1574
- width: 0,
1575
- height: 0
1576
- };
1577
- this.cropper.x1 = -100;
1578
- this.cropper.y1 = -100;
1579
- this.cropper.x2 = 10000;
1580
- this.cropper.y2 = 10000;
1581
- };
1582
- /**
1583
- * @private
1584
- * @param {?} file
1585
- * @return {?}
1586
- */
1587
- ImageCropperComponent.prototype.loadImageFile = /**
1588
- * @private
1589
- * @param {?} file
1590
- * @return {?}
1591
- */
1592
- function (file) {
1593
- var _this = this;
1594
- this.loadImageService
1595
- .loadImageFile(file, this.settings)
1596
- .then((/**
1597
- * @param {?} res
1598
- * @return {?}
1599
- */
1600
- function (res) { return _this.setLoadedImage(res); }))
1601
- .catch((/**
1602
- * @param {?} err
1603
- * @return {?}
1604
- */
1605
- function (err) { return _this.loadImageError(err); }));
1606
- };
1607
- /**
1608
- * @private
1609
- * @param {?} imageBase64
1610
- * @return {?}
1611
- */
1612
- ImageCropperComponent.prototype.loadBase64Image = /**
1613
- * @private
1614
- * @param {?} imageBase64
1615
- * @return {?}
1616
- */
1617
- function (imageBase64) {
1618
- var _this = this;
1619
- this.loadImageService
1620
- .loadBase64Image(imageBase64, this.settings)
1621
- .then((/**
1622
- * @param {?} res
1623
- * @return {?}
1624
- */
1625
- function (res) { return _this.setLoadedImage(res); }))
1626
- .catch((/**
1627
- * @param {?} err
1628
- * @return {?}
1629
- */
1630
- function (err) { return _this.loadImageError(err); }));
1631
- };
1632
- /**
1633
- * @private
1634
- * @param {?} url
1635
- * @return {?}
1636
- */
1637
- ImageCropperComponent.prototype.loadImageFromURL = /**
1638
- * @private
1639
- * @param {?} url
1640
- * @return {?}
1641
- */
1642
- function (url) {
1643
- var _this = this;
1644
- this.loadImageService
1645
- .loadImageFromURL(url, this.settings)
1646
- .then((/**
1647
- * @param {?} res
1648
- * @return {?}
1649
- */
1650
- function (res) { return _this.setLoadedImage(res); }))
1651
- .catch((/**
1652
- * @param {?} err
1653
- * @return {?}
1654
- */
1655
- function (err) { return _this.loadImageError(err); }));
1656
- };
1657
- /**
1658
- * @private
1659
- * @param {?} loadedImage
1660
- * @return {?}
1661
- */
1662
- ImageCropperComponent.prototype.setLoadedImage = /**
1663
- * @private
1664
- * @param {?} loadedImage
1665
- * @return {?}
1666
- */
1667
- function (loadedImage) {
1668
- this.loadedImage = loadedImage;
1669
- this.safeImgDataUrl = this.sanitizer.bypassSecurityTrustResourceUrl(loadedImage.transformed.base64);
1670
- this.cd.markForCheck();
1671
- };
1672
- /**
1673
- * @private
1674
- * @param {?} error
1675
- * @return {?}
1676
- */
1677
- ImageCropperComponent.prototype.loadImageError = /**
1678
- * @private
1679
- * @param {?} error
1680
- * @return {?}
1681
- */
1682
- function (error) {
1683
- console.error(error);
1684
- this.loadImageFailed.emit();
1685
- };
1686
- /**
1687
- * @return {?}
1688
- */
1689
- ImageCropperComponent.prototype.imageLoadedInView = /**
1690
- * @return {?}
1691
- */
1692
- function () {
1693
- var _this = this;
1694
- if (this.loadedImage != null) {
1695
- this.imageLoaded.emit(this.loadedImage);
1696
- this.setImageMaxSizeRetries = 0;
1697
- setTimeout((/**
1698
- * @return {?}
1699
- */
1700
- function () { return _this.checkImageMaxSizeRecursively(); }));
1701
- }
1702
- };
1703
- /**
1704
- * @private
1705
- * @return {?}
1706
- */
1707
- ImageCropperComponent.prototype.checkImageMaxSizeRecursively = /**
1708
- * @private
1709
- * @return {?}
1710
- */
1711
- function () {
1712
- var _this = this;
1713
- if (this.setImageMaxSizeRetries > 40) {
1714
- this.loadImageFailed.emit();
1715
- }
1716
- else if (this.sourceImageLoaded()) {
1717
- this.setMaxSize();
1718
- this.setCropperScaledMinSize();
1719
- this.setCropperScaledMaxSize();
1720
- this.resetCropperPosition();
1721
- this.cropperReady.emit(__assign({}, this.maxSize));
1722
- this.cd.markForCheck();
1723
- }
1724
- else {
1725
- this.setImageMaxSizeRetries++;
1726
- setTimeout((/**
1727
- * @return {?}
1728
- */
1729
- function () { return _this.checkImageMaxSizeRecursively(); }), 50);
1730
- }
1731
- };
1732
- /**
1733
- * @private
1734
- * @return {?}
1735
- */
1736
- ImageCropperComponent.prototype.sourceImageLoaded = /**
1737
- * @private
1738
- * @return {?}
1739
- */
1740
- function () {
1741
- return this.sourceImage && this.sourceImage.nativeElement && this.sourceImage.nativeElement.offsetWidth > 0;
1742
- };
1743
- /**
1744
- * @return {?}
1745
- */
1746
- ImageCropperComponent.prototype.onResize = /**
1747
- * @return {?}
1748
- */
1749
- function () {
1750
- if (!this.loadedImage) {
1751
- return;
1752
- }
1753
- this.resizeCropperPosition();
1754
- this.setMaxSize();
1755
- this.setCropperScaledMinSize();
1756
- this.setCropperScaledMaxSize();
1757
- };
1758
- /**
1759
- * @private
1760
- * @return {?}
1761
- */
1762
- ImageCropperComponent.prototype.activatePinchGesture = /**
1763
- * @private
1764
- * @return {?}
1765
- */
1766
- function () {
1767
- if (this.Hammer) {
1768
- /** @type {?} */
1769
- var hammer = new this.Hammer(this.wrapper.nativeElement);
1770
- hammer.get('pinch').set({ enable: true });
1771
- hammer.on('pinchmove', this.onPinch.bind(this));
1772
- hammer.on('pinchend', this.pinchStop.bind(this));
1773
- hammer.on('pinchstart', this.startPinch.bind(this));
1774
- }
1775
- else if (isDevMode()) {
1776
- console.warn('[NgxImageCropper] Could not find HammerJS - Pinch Gesture won\'t work');
1777
- }
1778
- };
1779
- /**
1780
- * @private
1781
- * @return {?}
1782
- */
1783
- ImageCropperComponent.prototype.resizeCropperPosition = /**
1784
- * @private
1785
- * @return {?}
1786
- */
1787
- function () {
1788
- /** @type {?} */
1789
- var sourceImageElement = this.sourceImage.nativeElement;
1790
- if (this.maxSize.width !== sourceImageElement.offsetWidth || this.maxSize.height !== sourceImageElement.offsetHeight) {
1791
- this.cropper.x1 = this.cropper.x1 * sourceImageElement.offsetWidth / this.maxSize.width;
1792
- this.cropper.x2 = this.cropper.x2 * sourceImageElement.offsetWidth / this.maxSize.width;
1793
- this.cropper.y1 = this.cropper.y1 * sourceImageElement.offsetHeight / this.maxSize.height;
1794
- this.cropper.y2 = this.cropper.y2 * sourceImageElement.offsetHeight / this.maxSize.height;
1795
- }
1796
- };
1797
- /**
1798
- * @return {?}
1799
- */
1800
- ImageCropperComponent.prototype.resetCropperPosition = /**
1801
- * @return {?}
1802
- */
1803
- function () {
1804
- this.cropperPositionService.resetCropperPosition(this.sourceImage, this.cropper, this.settings);
1805
- this.doAutoCrop();
1806
- this.imageVisible = true;
1807
- };
1808
- /**
1809
- * @param {?} event
1810
- * @return {?}
1811
- */
1812
- ImageCropperComponent.prototype.keyboardAccess = /**
1813
- * @param {?} event
1814
- * @return {?}
1815
- */
1816
- function (event) {
1817
- this.changeKeyboardStepSize(event);
1818
- this.keyboardMoveCropper(event);
1819
- };
1820
- /**
1821
- * @private
1822
- * @param {?} event
1823
- * @return {?}
1824
- */
1825
- ImageCropperComponent.prototype.changeKeyboardStepSize = /**
1826
- * @private
1827
- * @param {?} event
1828
- * @return {?}
1829
- */
1830
- function (event) {
1831
- if (event.key >= '1' && event.key <= '9') {
1832
- this.settings.stepSize = +event.key;
1833
- return;
1834
- }
1835
- };
1836
- /**
1837
- * @private
1838
- * @param {?} event
1839
- * @return {?}
1840
- */
1841
- ImageCropperComponent.prototype.keyboardMoveCropper = /**
1842
- * @private
1843
- * @param {?} event
1844
- * @return {?}
1845
- */
1846
- function (event) {
1847
- /** @type {?} */
1848
- var keyboardWhiteList = ['ArrowUp', 'ArrowDown', 'ArrowRight', 'ArrowLeft'];
1849
- if (!(keyboardWhiteList.includes(event.key))) {
1850
- return;
1851
- }
1852
- /** @type {?} */
1853
- var moveType = event.shiftKey ? MoveTypes.Resize : MoveTypes.Move;
1854
- /** @type {?} */
1855
- var position = event.altKey ? getInvertedPositionForKey(event.key) : getPositionForKey(event.key);
1856
- /** @type {?} */
1857
- var moveEvent = getEventForKey(event.key, this.settings.stepSize);
1858
- event.preventDefault();
1859
- event.stopPropagation();
1860
- this.startMove({ clientX: 0, clientY: 0 }, moveType, position);
1861
- this.moveImg(moveEvent);
1862
- this.moveStop();
1863
- };
1864
- /**
1865
- * @param {?} event
1866
- * @param {?} moveType
1867
- * @param {?=} position
1868
- * @return {?}
1869
- */
1870
- ImageCropperComponent.prototype.startMove = /**
1871
- * @param {?} event
1872
- * @param {?} moveType
1873
- * @param {?=} position
1874
- * @return {?}
1875
- */
1876
- function (event, moveType, position) {
1877
- if (position === void 0) { position = null; }
1878
- if (this.moveStart && this.moveStart.active && this.moveStart.type === MoveTypes.Pinch) {
1879
- return;
1880
- }
1881
- if (event.preventDefault) {
1882
- event.preventDefault();
1883
- }
1884
- this.moveStart = __assign({ active: true, type: moveType, position: position, clientX: this.cropperPositionService.getClientX(event), clientY: this.cropperPositionService.getClientY(event) }, this.cropper);
1885
- };
1886
- /**
1887
- * @param {?} event
1888
- * @return {?}
1889
- */
1890
- ImageCropperComponent.prototype.startPinch = /**
1891
- * @param {?} event
1892
- * @return {?}
1893
- */
1894
- function (event) {
1895
- if (!this.safeImgDataUrl) {
1896
- return;
1897
- }
1898
- if (event.preventDefault) {
1899
- event.preventDefault();
1900
- }
1901
- this.moveStart = __assign({ active: true, type: MoveTypes.Pinch, position: 'center', clientX: this.cropper.x1 + (this.cropper.x2 - this.cropper.x1) / 2, clientY: this.cropper.y1 + (this.cropper.y2 - this.cropper.y1) / 2 }, this.cropper);
1902
- };
1903
- /**
1904
- * @param {?} event
1905
- * @return {?}
1906
- */
1907
- ImageCropperComponent.prototype.moveImg = /**
1908
- * @param {?} event
1909
- * @return {?}
1910
- */
1911
- function (event) {
1912
- if (this.moveStart.active) {
1913
- if (event.stopPropagation) {
1914
- event.stopPropagation();
1915
- }
1916
- if (event.preventDefault) {
1917
- event.preventDefault();
1918
- }
1919
- if (this.moveStart.type === MoveTypes.Move) {
1920
- this.cropperPositionService.move(event, this.moveStart, this.cropper);
1921
- this.checkCropperPosition(true);
1922
- }
1923
- else if (this.moveStart.type === MoveTypes.Resize) {
1924
- if (!this.cropperStaticWidth && !this.cropperStaticHeight) {
1925
- this.cropperPositionService.resize(event, this.moveStart, this.cropper, this.maxSize, this.settings);
1926
- }
1927
- this.checkCropperPosition(false);
1928
- }
1929
- this.cd.detectChanges();
1930
- }
1931
- };
1932
- /**
1933
- * @param {?} event
1934
- * @return {?}
1935
- */
1936
- ImageCropperComponent.prototype.onPinch = /**
1937
- * @param {?} event
1938
- * @return {?}
1939
- */
1940
- function (event) {
1941
- if (this.moveStart.active) {
1942
- if (event.stopPropagation) {
1943
- event.stopPropagation();
1944
- }
1945
- if (event.preventDefault) {
1946
- event.preventDefault();
1947
- }
1948
- if (this.moveStart.type === MoveTypes.Pinch) {
1949
- this.cropperPositionService.resize(event, this.moveStart, this.cropper, this.maxSize, this.settings);
1950
- this.checkCropperPosition(false);
1951
- }
1952
- this.cd.detectChanges();
1953
- }
1954
- };
1955
- /**
1956
- * @private
1957
- * @return {?}
1958
- */
1959
- ImageCropperComponent.prototype.setMaxSize = /**
1960
- * @private
1961
- * @return {?}
1962
- */
1963
- function () {
1964
- if (this.sourceImage) {
1965
- /** @type {?} */
1966
- var sourceImageElement = this.sourceImage.nativeElement;
1967
- this.maxSize.width = sourceImageElement.offsetWidth;
1968
- this.maxSize.height = sourceImageElement.offsetHeight;
1969
- this.marginLeft = this.sanitizer.bypassSecurityTrustStyle('calc(50% - ' + this.maxSize.width / 2 + 'px)');
1970
- }
1971
- };
1972
- /**
1973
- * @private
1974
- * @return {?}
1975
- */
1976
- ImageCropperComponent.prototype.setCropperScaledMinSize = /**
1977
- * @private
1978
- * @return {?}
1979
- */
1980
- function () {
1981
- if (this.loadedImage && this.loadedImage.transformed && this.loadedImage.transformed.image) {
1982
- this.setCropperScaledMinWidth();
1983
- this.setCropperScaledMinHeight();
1984
- }
1985
- else {
1986
- this.settings.cropperScaledMinWidth = 20;
1987
- this.settings.cropperScaledMinHeight = 20;
1988
- }
1989
- };
1990
- /**
1991
- * @private
1992
- * @return {?}
1993
- */
1994
- ImageCropperComponent.prototype.setCropperScaledMinWidth = /**
1995
- * @private
1996
- * @return {?}
1997
- */
1998
- function () {
1999
- this.settings.cropperScaledMinWidth = this.cropperMinWidth > 0
2000
- ? Math.max(20, this.cropperMinWidth / this.loadedImage.transformed.image.width * this.maxSize.width)
2001
- : 20;
2002
- };
2003
- /**
2004
- * @private
2005
- * @return {?}
2006
- */
2007
- ImageCropperComponent.prototype.setCropperScaledMinHeight = /**
2008
- * @private
2009
- * @return {?}
2010
- */
2011
- function () {
2012
- if (this.maintainAspectRatio) {
2013
- this.settings.cropperScaledMinHeight = Math.max(20, this.settings.cropperScaledMinWidth / this.aspectRatio);
2014
- }
2015
- else if (this.cropperMinHeight > 0) {
2016
- this.settings.cropperScaledMinHeight = Math.max(20, this.cropperMinHeight / this.loadedImage.transformed.image.height * this.maxSize.height);
2017
- }
2018
- else {
2019
- this.settings.cropperScaledMinHeight = 20;
2020
- }
2021
- };
2022
- /**
2023
- * @private
2024
- * @return {?}
2025
- */
2026
- ImageCropperComponent.prototype.setCropperScaledMaxSize = /**
2027
- * @private
2028
- * @return {?}
2029
- */
2030
- function () {
2031
- if (this.loadedImage && this.loadedImage.transformed && this.loadedImage.transformed.image) {
2032
- /** @type {?} */
2033
- var ratio = this.loadedImage.transformed.size.width / this.maxSize.width;
2034
- this.settings.cropperScaledMaxWidth = this.cropperMaxWidth > 20 ? this.cropperMaxWidth / ratio : this.maxSize.width;
2035
- this.settings.cropperScaledMaxHeight = this.cropperMaxHeight > 20 ? this.cropperMaxHeight / ratio : this.maxSize.height;
2036
- if (this.maintainAspectRatio) {
2037
- if (this.settings.cropperScaledMaxWidth > this.settings.cropperScaledMaxHeight * this.aspectRatio) {
2038
- this.settings.cropperScaledMaxWidth = this.settings.cropperScaledMaxHeight * this.aspectRatio;
2039
- }
2040
- else if (this.settings.cropperScaledMaxWidth < this.settings.cropperScaledMaxHeight * this.aspectRatio) {
2041
- this.settings.cropperScaledMaxHeight = this.settings.cropperScaledMaxWidth / this.aspectRatio;
2042
- }
2043
- }
2044
- }
2045
- else {
2046
- this.settings.cropperScaledMaxWidth = this.maxSize.width;
2047
- this.settings.cropperScaledMaxHeight = this.maxSize.height;
2048
- }
2049
- };
2050
- /**
2051
- * @private
2052
- * @param {?=} maintainSize
2053
- * @return {?}
2054
- */
2055
- ImageCropperComponent.prototype.checkCropperPosition = /**
2056
- * @private
2057
- * @param {?=} maintainSize
2058
- * @return {?}
2059
- */
2060
- function (maintainSize) {
2061
- if (maintainSize === void 0) { maintainSize = false; }
2062
- if (this.cropper.x1 < 0) {
2063
- this.cropper.x2 -= maintainSize ? this.cropper.x1 : 0;
2064
- this.cropper.x1 = 0;
2065
- }
2066
- if (this.cropper.y1 < 0) {
2067
- this.cropper.y2 -= maintainSize ? this.cropper.y1 : 0;
2068
- this.cropper.y1 = 0;
2069
- }
2070
- if (this.cropper.x2 > this.maxSize.width) {
2071
- this.cropper.x1 -= maintainSize ? (this.cropper.x2 - this.maxSize.width) : 0;
2072
- this.cropper.x2 = this.maxSize.width;
2073
- }
2074
- if (this.cropper.y2 > this.maxSize.height) {
2075
- this.cropper.y1 -= maintainSize ? (this.cropper.y2 - this.maxSize.height) : 0;
2076
- this.cropper.y2 = this.maxSize.height;
2077
- }
2078
- };
2079
- /**
2080
- * @return {?}
2081
- */
2082
- ImageCropperComponent.prototype.moveStop = /**
2083
- * @return {?}
2084
- */
2085
- function () {
2086
- if (this.moveStart.active) {
2087
- this.moveStart.active = false;
2088
- this.doAutoCrop();
2089
- }
2090
- };
2091
- /**
2092
- * @return {?}
2093
- */
2094
- ImageCropperComponent.prototype.pinchStop = /**
2095
- * @return {?}
2096
- */
2097
- function () {
2098
- if (this.moveStart.active) {
2099
- this.moveStart.active = false;
2100
- this.doAutoCrop();
2101
- }
2102
- };
2103
- /**
2104
- * @private
2105
- * @return {?}
2106
- */
2107
- ImageCropperComponent.prototype.doAutoCrop = /**
2108
- * @private
2109
- * @return {?}
2110
- */
2111
- function () {
2112
- if (this.autoCrop) {
2113
- this.crop();
2114
- }
2115
- };
2116
- /**
2117
- * @return {?}
2118
- */
2119
- ImageCropperComponent.prototype.crop = /**
2120
- * @return {?}
2121
- */
2122
- function () {
2123
- if (this.sourceImage && this.sourceImage.nativeElement && this.loadedImage.transformed.image != null) {
2124
- this.startCropImage.emit();
2125
- /** @type {?} */
2126
- var output = this.cropService.crop(this.sourceImage, this.loadedImage, this.cropper, this.settings);
2127
- if (output != null) {
2128
- this.imageCropped.emit(output);
2129
- }
2130
- return output;
2131
- }
2132
- return null;
2133
- };
2134
- ImageCropperComponent.decorators = [
2135
- { type: Component, args: [{
2136
- selector: 'image-cropper',
2137
- template: "<div [style.background]=\"imageVisible && backgroundColor\"\n #wrapper\n>\n <img\n #sourceImage\n class=\"source-image\"\n *ngIf=\"safeImgDataUrl\"\n [src]=\"safeImgDataUrl\"\n [style.visibility]=\"imageVisible ? 'visible' : 'hidden'\"\n [style.transform]=\"safeTransformStyle\"\n (load)=\"imageLoadedInView()\"\n />\n <div\n class=\"overlay\"\n [style.width.px]=\"maxSize.width\"\n [style.height.px]=\"maxSize.height\"\n [style.margin-left]=\"alignImage === 'center' ? marginLeft : null\"\n ></div>\n <div class=\"cropper\"\n *ngIf=\"imageVisible\"\n [class.rounded]=\"roundCropper\"\n [style.top.px]=\"cropper.y1\"\n [style.left.px]=\"cropper.x1\"\n [style.width.px]=\"cropper.x2 - cropper.x1\"\n [style.height.px]=\"cropper.y2 - cropper.y1\"\n [style.margin-left]=\"alignImage === 'center' ? marginLeft : null\"\n [style.visibility]=\"imageVisible ? 'visible' : 'hidden'\"\n (keydown)=\"keyboardAccess($event)\"\n tabindex=\"0\"\n >\n <div\n (mousedown)=\"startMove($event, moveTypes.Move)\"\n (touchstart)=\"startMove($event, moveTypes.Move)\"\n class=\"move\">\n </div>\n <ng-container *ngIf=\"!hideResizeSquares\">\n <span class=\"resize topleft\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'topleft')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'topleft')\">\n <span class=\"square\"></span>\n </span>\n <span class=\"resize top\">\n <span class=\"square\"></span>\n </span>\n <span class=\"resize topright\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'topright')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'topright')\">\n <span class=\"square\"></span>\n </span>\n <span class=\"resize right\">\n <span class=\"square\"></span>\n </span>\n <span class=\"resize bottomright\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'bottomright')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'bottomright')\">\n <span class=\"square\"></span>\n </span>\n <span class=\"resize bottom\">\n <span class=\"square\"></span>\n </span>\n <span class=\"resize bottomleft\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'bottomleft')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'bottomleft')\">\n <span class=\"square\"></span>\n </span>\n <span class=\"resize left\">\n <span class=\"square\"></span>\n </span>\n <span class=\"resize-bar top\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'top')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'top')\">\n </span>\n <span class=\"resize-bar right\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'right')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'right')\">\n </span>\n <span class=\"resize-bar bottom\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'bottom')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'bottom')\">\n </span>\n <span class=\"resize-bar left\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'left')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'left')\">\n </span>\n </ng-container>\n </div>\n</div>\n",
2138
- changeDetection: ChangeDetectionStrategy.OnPush,
2139
- styles: [":host{display:flex;position:relative;width:100%;max-width:100%;max-height:100%;overflow:hidden;padding:5px;text-align:center}:host>div{width:100%;position:relative}:host>div img.source-image{max-width:100%;max-height:100%;transform-origin:center}:host .overlay{position:absolute;pointer-events:none;touch-action:none;outline:var(--cropper-overlay-color,#fff) solid 100vw;top:0;left:0}:host .cropper{position:absolute;display:flex;color:#53535c;background:0 0;outline:rgba(255,255,255,.3) solid 100vw;outline:var(--cropper-outline-color,rgba(255,255,255,.3)) solid 100vw;touch-action:none}:host .cropper:after{position:absolute;content:\"\";top:0;bottom:0;left:0;right:0;pointer-events:none;border:1px dashed;opacity:.75;color:inherit;z-index:1}:host .cropper .move{width:100%;cursor:move;border:1px solid rgba(255,255,255,.5)}:host .cropper:focus .move{border-color:#1e90ff;border-width:2px}:host .cropper .resize{position:absolute;display:inline-block;line-height:6px;padding:8px;opacity:.85;z-index:1}:host .cropper .resize .square{display:inline-block;background:#53535c;width:6px;height:6px;border:1px solid rgba(255,255,255,.5);box-sizing:content-box}:host .cropper .resize.topleft{top:-12px;left:-12px;cursor:nwse-resize}:host .cropper .resize.top{top:-12px;left:calc(50% - 12px);cursor:ns-resize}:host .cropper .resize.topright{top:-12px;right:-12px;cursor:nesw-resize}:host .cropper .resize.right{top:calc(50% - 12px);right:-12px;cursor:ew-resize}:host .cropper .resize.bottomright{bottom:-12px;right:-12px;cursor:nwse-resize}:host .cropper .resize.bottom{bottom:-12px;left:calc(50% - 12px);cursor:ns-resize}:host .cropper .resize.bottomleft{bottom:-12px;left:-12px;cursor:nesw-resize}:host .cropper .resize.left{top:calc(50% - 12px);left:-12px;cursor:ew-resize}:host .cropper .resize-bar{position:absolute;z-index:1}:host .cropper .resize-bar.top{top:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:ns-resize}:host .cropper .resize-bar.right{top:11px;right:-11px;height:calc(100% - 22px);width:22px;cursor:ew-resize}:host .cropper .resize-bar.bottom{bottom:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:ns-resize}:host .cropper .resize-bar.left{top:11px;left:-11px;height:calc(100% - 22px);width:22px;cursor:ew-resize}:host .cropper.rounded{outline-color:transparent}:host .cropper.rounded:after{border-radius:100%;box-shadow:0 0 0 100vw rgba(255,255,255,.3);box-shadow:0 0 0 100vw var(--cropper-outline-color,rgba(255,255,255,.3))}@media (orientation:portrait){:host .cropper{outline-width:100vh}:host .cropper.rounded:after{box-shadow:0 0 0 100vh rgba(255,255,255,.3);box-shadow:0 0 0 100vh var(--cropper-outline-color,rgba(255,255,255,.3))}}:host .cropper.rounded .move{border-radius:100%}:host.disabled .cropper .move,:host.disabled .cropper .resize,:host.disabled .cropper .resize-bar{display:none}"]
2140
- }] }
2141
- ];
2142
- /** @nocollapse */
2143
- ImageCropperComponent.ctorParameters = function () { return [
2144
- { type: CropService },
2145
- { type: CropperPositionService },
2146
- { type: LoadImageService },
2147
- { type: DomSanitizer },
2148
- { type: ChangeDetectorRef }
2149
- ]; };
2150
- ImageCropperComponent.propDecorators = {
2151
- wrapper: [{ type: ViewChild, args: ['wrapper', { static: true },] }],
2152
- sourceImage: [{ type: ViewChild, args: ['sourceImage', { static: false },] }],
2153
- imageChangedEvent: [{ type: Input }],
2154
- imageURL: [{ type: Input }],
2155
- imageBase64: [{ type: Input }],
2156
- imageFile: [{ type: Input }],
2157
- format: [{ type: Input }],
2158
- transform: [{ type: Input }],
2159
- maintainAspectRatio: [{ type: Input }],
2160
- aspectRatio: [{ type: Input }],
2161
- resizeToWidth: [{ type: Input }],
2162
- resizeToHeight: [{ type: Input }],
2163
- cropperMinWidth: [{ type: Input }],
2164
- cropperMinHeight: [{ type: Input }],
2165
- cropperMaxHeight: [{ type: Input }],
2166
- cropperMaxWidth: [{ type: Input }],
2167
- cropperStaticWidth: [{ type: Input }],
2168
- cropperStaticHeight: [{ type: Input }],
2169
- canvasRotation: [{ type: Input }],
2170
- initialStepSize: [{ type: Input }],
2171
- roundCropper: [{ type: Input }],
2172
- onlyScaleDown: [{ type: Input }],
2173
- imageQuality: [{ type: Input }],
2174
- autoCrop: [{ type: Input }],
2175
- backgroundColor: [{ type: Input }],
2176
- containWithinAspectRatio: [{ type: Input }],
2177
- hideResizeSquares: [{ type: Input }],
2178
- cropper: [{ type: Input }],
2179
- alignImage: [{ type: HostBinding, args: ['style.text-align',] }, { type: Input }],
2180
- disabled: [{ type: HostBinding, args: ['class.disabled',] }, { type: Input }],
2181
- imageCropped: [{ type: Output }],
2182
- startCropImage: [{ type: Output }],
2183
- imageLoaded: [{ type: Output }],
2184
- cropperReady: [{ type: Output }],
2185
- loadImageFailed: [{ type: Output }],
2186
- onResize: [{ type: HostListener, args: ['window:resize',] }],
2187
- moveImg: [{ type: HostListener, args: ['document:mousemove', ['$event'],] }, { type: HostListener, args: ['document:touchmove', ['$event'],] }],
2188
- moveStop: [{ type: HostListener, args: ['document:mouseup',] }, { type: HostListener, args: ['document:touchend',] }]
2189
- };
2190
- return ImageCropperComponent;
2191
- }());
2192
- if (false) {
2193
- /**
2194
- * @type {?}
2195
- * @private
2196
- */
2197
- ImageCropperComponent.prototype.Hammer;
2198
- /**
2199
- * @type {?}
2200
- * @private
2201
- */
2202
- ImageCropperComponent.prototype.settings;
2203
- /**
2204
- * @type {?}
2205
- * @private
2206
- */
2207
- ImageCropperComponent.prototype.setImageMaxSizeRetries;
2208
- /**
2209
- * @type {?}
2210
- * @private
2211
- */
2212
- ImageCropperComponent.prototype.moveStart;
2213
- /**
2214
- * @type {?}
2215
- * @private
2216
- */
2217
- ImageCropperComponent.prototype.loadedImage;
2218
- /** @type {?} */
2219
- ImageCropperComponent.prototype.safeImgDataUrl;
2220
- /** @type {?} */
2221
- ImageCropperComponent.prototype.safeTransformStyle;
2222
- /** @type {?} */
2223
- ImageCropperComponent.prototype.marginLeft;
2224
- /** @type {?} */
2225
- ImageCropperComponent.prototype.maxSize;
2226
- /** @type {?} */
2227
- ImageCropperComponent.prototype.moveTypes;
2228
- /** @type {?} */
2229
- ImageCropperComponent.prototype.imageVisible;
2230
- /** @type {?} */
2231
- ImageCropperComponent.prototype.wrapper;
2232
- /** @type {?} */
2233
- ImageCropperComponent.prototype.sourceImage;
2234
- /** @type {?} */
2235
- ImageCropperComponent.prototype.imageChangedEvent;
2236
- /** @type {?} */
2237
- ImageCropperComponent.prototype.imageURL;
2238
- /** @type {?} */
2239
- ImageCropperComponent.prototype.imageBase64;
2240
- /** @type {?} */
2241
- ImageCropperComponent.prototype.imageFile;
2242
- /** @type {?} */
2243
- ImageCropperComponent.prototype.format;
2244
- /** @type {?} */
2245
- ImageCropperComponent.prototype.transform;
2246
- /** @type {?} */
2247
- ImageCropperComponent.prototype.maintainAspectRatio;
2248
- /** @type {?} */
2249
- ImageCropperComponent.prototype.aspectRatio;
2250
- /** @type {?} */
2251
- ImageCropperComponent.prototype.resizeToWidth;
2252
- /** @type {?} */
2253
- ImageCropperComponent.prototype.resizeToHeight;
2254
- /** @type {?} */
2255
- ImageCropperComponent.prototype.cropperMinWidth;
2256
- /** @type {?} */
2257
- ImageCropperComponent.prototype.cropperMinHeight;
2258
- /** @type {?} */
2259
- ImageCropperComponent.prototype.cropperMaxHeight;
2260
- /** @type {?} */
2261
- ImageCropperComponent.prototype.cropperMaxWidth;
2262
- /** @type {?} */
2263
- ImageCropperComponent.prototype.cropperStaticWidth;
2264
- /** @type {?} */
2265
- ImageCropperComponent.prototype.cropperStaticHeight;
2266
- /** @type {?} */
2267
- ImageCropperComponent.prototype.canvasRotation;
2268
- /** @type {?} */
2269
- ImageCropperComponent.prototype.initialStepSize;
2270
- /** @type {?} */
2271
- ImageCropperComponent.prototype.roundCropper;
2272
- /** @type {?} */
2273
- ImageCropperComponent.prototype.onlyScaleDown;
2274
- /** @type {?} */
2275
- ImageCropperComponent.prototype.imageQuality;
2276
- /** @type {?} */
2277
- ImageCropperComponent.prototype.autoCrop;
2278
- /** @type {?} */
2279
- ImageCropperComponent.prototype.backgroundColor;
2280
- /** @type {?} */
2281
- ImageCropperComponent.prototype.containWithinAspectRatio;
2282
- /** @type {?} */
2283
- ImageCropperComponent.prototype.hideResizeSquares;
2284
- /** @type {?} */
2285
- ImageCropperComponent.prototype.cropper;
2286
- /** @type {?} */
2287
- ImageCropperComponent.prototype.alignImage;
2288
- /** @type {?} */
2289
- ImageCropperComponent.prototype.disabled;
2290
- /** @type {?} */
2291
- ImageCropperComponent.prototype.imageCropped;
2292
- /** @type {?} */
2293
- ImageCropperComponent.prototype.startCropImage;
2294
- /** @type {?} */
2295
- ImageCropperComponent.prototype.imageLoaded;
2296
- /** @type {?} */
2297
- ImageCropperComponent.prototype.cropperReady;
2298
- /** @type {?} */
2299
- ImageCropperComponent.prototype.loadImageFailed;
2300
- /**
2301
- * @type {?}
2302
- * @private
2303
- */
2304
- ImageCropperComponent.prototype.cropService;
2305
- /**
2306
- * @type {?}
2307
- * @private
2308
- */
2309
- ImageCropperComponent.prototype.cropperPositionService;
2310
- /**
2311
- * @type {?}
2312
- * @private
2313
- */
2314
- ImageCropperComponent.prototype.loadImageService;
2315
- /**
2316
- * @type {?}
2317
- * @private
2318
- */
2319
- ImageCropperComponent.prototype.sanitizer;
2320
- /**
2321
- * @type {?}
2322
- * @private
2323
- */
2324
- ImageCropperComponent.prototype.cd;
2325
- }
2326
-
2327
- /**
2328
- * @fileoverview added by tsickle
2329
- * Generated from: lib/image-cropper.module.ts
2330
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2331
- */
2332
- var ImageCropperModule = /** @class */ (function () {
2333
- function ImageCropperModule() {
2334
- }
2335
- ImageCropperModule.decorators = [
2336
- { type: NgModule, args: [{
2337
- imports: [
2338
- CommonModule
2339
- ],
2340
- declarations: [
2341
- ImageCropperComponent
2342
- ],
2343
- exports: [
2344
- ImageCropperComponent
2345
- ]
2346
- },] }
2347
- ];
2348
- return ImageCropperModule;
2349
- }());
2350
-
2351
- /**
2352
- * @fileoverview added by tsickle
2353
- * Generated from: lib/interfaces/index.ts
2354
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2355
- */
2356
-
2357
- /**
2358
- * @fileoverview added by tsickle
2359
- * Generated from: lib/utils/blob.utils.ts
2360
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2361
- */
2362
- /**
2363
- * @param {?} base64Image
2364
- * @return {?}
2365
- */
2366
- function base64ToFile(base64Image) {
2367
- /** @type {?} */
2368
- var split = base64Image.split(',');
2369
- /** @type {?} */
2370
- var type = split[0].replace('data:', '').replace(';base64', '');
2371
- /** @type {?} */
2372
- var byteString = atob(split[1]);
2373
- /** @type {?} */
2374
- var ab = new ArrayBuffer(byteString.length);
2375
- /** @type {?} */
2376
- var ia = new Uint8Array(ab);
2377
- for (var i = 0; i < byteString.length; i += 1) {
2378
- ia[i] = byteString.charCodeAt(i);
2379
- }
2380
- return new Blob([ab], { type: type });
2381
- }
2382
-
2383
- /**
2384
- * @fileoverview added by tsickle
2385
- * Generated from: public-api.ts
2386
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2387
- */
2388
-
2389
- /**
2390
- * @fileoverview added by tsickle
2391
- * Generated from: ngx-image-cropper.ts
2392
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2393
- */
2394
-
2395
- export { ImageCropperComponent, ImageCropperModule, base64ToFile, resizeCanvas, CropService as ɵa, CropperPositionService as ɵb, LoadImageService as ɵc };
2396
- //# sourceMappingURL=ngx-image-cropper.js.map