ngx-image-cropper 5.0.0 → 6.0.2

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 (64) 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} +251 -1035
  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 +12 -9
  29. package/lib/image-cropper.module.d.ts +6 -0
  30. package/lib/interfaces/cropper.settings.d.ts +1 -1
  31. package/lib/services/crop.service.d.ts +3 -0
  32. package/lib/services/cropper-position.service.d.ts +3 -0
  33. package/lib/services/load-image.service.d.ts +3 -0
  34. package/lib/utils/hammer.utils.d.ts +1 -1
  35. package/ngx-image-cropper.d.ts +1 -3
  36. package/package.json +24 -13
  37. package/bundles/ngx-image-cropper.umd.js +0 -2418
  38. package/bundles/ngx-image-cropper.umd.js.map +0 -1
  39. package/bundles/ngx-image-cropper.umd.min.js +0 -16
  40. package/bundles/ngx-image-cropper.umd.min.js.map +0 -1
  41. package/esm2015/lib/component/image-cropper.component.js +0 -827
  42. package/esm2015/lib/image-cropper.module.js +0 -24
  43. package/esm2015/lib/interfaces/cropper-options.interface.js +0 -56
  44. package/esm2015/lib/interfaces/cropper-position.interface.js +0 -20
  45. package/esm2015/lib/interfaces/cropper.settings.js +0 -140
  46. package/esm2015/lib/interfaces/dimensions.interface.js +0 -16
  47. package/esm2015/lib/interfaces/exif-transform.interface.js +0 -16
  48. package/esm2015/lib/interfaces/image-cropped-event.interface.js +0 -24
  49. package/esm2015/lib/interfaces/image-transform.interface.js +0 -20
  50. package/esm2015/lib/interfaces/index.js +0 -6
  51. package/esm2015/lib/interfaces/loaded-image.interface.js +0 -18
  52. package/esm2015/lib/interfaces/move-start.interface.js +0 -37
  53. package/esm2015/lib/services/crop.service.js +0 -176
  54. package/esm2015/lib/services/cropper-position.service.js +0 -259
  55. package/esm2015/lib/services/load-image.service.js +0 -304
  56. package/esm2015/lib/utils/blob.utils.js +0 -26
  57. package/esm2015/lib/utils/exif.utils.js +0 -128
  58. package/esm2015/lib/utils/hammer.utils.js +0 -29
  59. package/esm2015/lib/utils/keyboard.utils.js +0 -58
  60. package/esm2015/lib/utils/resize.utils.js +0 -116
  61. package/esm2015/ngx-image-cropper.js +0 -13
  62. package/esm2015/public-api.js +0 -11
  63. package/fesm2015/ngx-image-cropper.js.map +0 -1
  64. package/ngx-image-cropper.metadata.json +0 -1
@@ -0,0 +1,1315 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable, EventEmitter, isDevMode, Component, ChangeDetectionStrategy, ViewChild, Input, HostBinding, Output, HostListener, NgModule } from '@angular/core';
3
+ import * as i4 from '@angular/platform-browser';
4
+ import * as i5 from '@angular/common';
5
+ import { CommonModule } from '@angular/common';
6
+
7
+ class CropperSettings {
8
+ constructor() {
9
+ // From options
10
+ this.format = 'png';
11
+ this.maintainAspectRatio = true;
12
+ this.transform = {};
13
+ this.aspectRatio = 1;
14
+ this.resizeToWidth = 0;
15
+ this.resizeToHeight = 0;
16
+ this.cropperMinWidth = 0;
17
+ this.cropperMinHeight = 0;
18
+ this.cropperMaxHeight = 0;
19
+ this.cropperMaxWidth = 0;
20
+ this.cropperStaticWidth = 0;
21
+ this.cropperStaticHeight = 0;
22
+ this.canvasRotation = 0;
23
+ this.initialStepSize = 3;
24
+ this.roundCropper = false;
25
+ this.onlyScaleDown = false;
26
+ this.imageQuality = 92;
27
+ this.autoCrop = true;
28
+ this.containWithinAspectRatio = false;
29
+ this.hideResizeSquares = false;
30
+ this.alignImage = 'center';
31
+ // Internal
32
+ this.cropperScaledMinWidth = 20;
33
+ this.cropperScaledMinHeight = 20;
34
+ this.cropperScaledMaxWidth = 20;
35
+ this.cropperScaledMaxHeight = 20;
36
+ this.stepSize = this.initialStepSize;
37
+ }
38
+ setOptions(options) {
39
+ Object.keys(options)
40
+ .filter((k) => k in this)
41
+ .forEach((k) => this[k] = options[k]);
42
+ this.validateOptions();
43
+ }
44
+ setOptionsFromChanges(changes) {
45
+ Object.keys(changes)
46
+ .filter((k) => k in this)
47
+ .forEach((k) => this[k] = changes[k].currentValue);
48
+ this.validateOptions();
49
+ }
50
+ validateOptions() {
51
+ if (this.maintainAspectRatio && !this.aspectRatio) {
52
+ throw new Error('`aspectRatio` should > 0 when `maintainAspectRatio` is enabled');
53
+ }
54
+ }
55
+ }
56
+
57
+ var MoveTypes;
58
+ (function (MoveTypes) {
59
+ MoveTypes["Move"] = "move";
60
+ MoveTypes["Resize"] = "resize";
61
+ MoveTypes["Pinch"] = "pinch";
62
+ })(MoveTypes || (MoveTypes = {}));
63
+
64
+ function getPositionForKey(key) {
65
+ switch (key) {
66
+ case 'ArrowUp':
67
+ return 'top';
68
+ case 'ArrowRight':
69
+ return 'right';
70
+ case 'ArrowDown':
71
+ return 'bottom';
72
+ case 'ArrowLeft':
73
+ default:
74
+ return 'left';
75
+ }
76
+ }
77
+ function getInvertedPositionForKey(key) {
78
+ switch (key) {
79
+ case 'ArrowUp':
80
+ return 'bottom';
81
+ case 'ArrowRight':
82
+ return 'left';
83
+ case 'ArrowDown':
84
+ return 'top';
85
+ case 'ArrowLeft':
86
+ default:
87
+ return 'right';
88
+ }
89
+ }
90
+ function getEventForKey(key, stepSize) {
91
+ switch (key) {
92
+ case 'ArrowUp':
93
+ return { clientX: 0, clientY: stepSize * -1 };
94
+ case 'ArrowRight':
95
+ return { clientX: stepSize, clientY: 0 };
96
+ case 'ArrowDown':
97
+ return { clientX: 0, clientY: stepSize };
98
+ case 'ArrowLeft':
99
+ default:
100
+ return { clientX: stepSize * -1, clientY: 0 };
101
+ }
102
+ }
103
+
104
+ /*
105
+ * Hermite resize - fast image resize/resample using Hermite filter.
106
+ * https://github.com/viliusle/Hermite-resize
107
+ */
108
+ function resizeCanvas(canvas, width, height) {
109
+ const width_source = canvas.width;
110
+ const height_source = canvas.height;
111
+ width = Math.round(width);
112
+ height = Math.round(height);
113
+ const ratio_w = width_source / width;
114
+ const ratio_h = height_source / height;
115
+ const ratio_w_half = Math.ceil(ratio_w / 2);
116
+ const ratio_h_half = Math.ceil(ratio_h / 2);
117
+ const ctx = canvas.getContext('2d');
118
+ if (ctx) {
119
+ const img = ctx.getImageData(0, 0, width_source, height_source);
120
+ const img2 = ctx.createImageData(width, height);
121
+ const data = img.data;
122
+ const data2 = img2.data;
123
+ for (let j = 0; j < height; j++) {
124
+ for (let i = 0; i < width; i++) {
125
+ const x2 = (i + j * width) * 4;
126
+ const center_y = j * ratio_h;
127
+ let weight = 0;
128
+ let weights = 0;
129
+ let weights_alpha = 0;
130
+ let gx_r = 0;
131
+ let gx_g = 0;
132
+ let gx_b = 0;
133
+ let gx_a = 0;
134
+ const xx_start = Math.floor(i * ratio_w);
135
+ const yy_start = Math.floor(j * ratio_h);
136
+ let xx_stop = Math.ceil((i + 1) * ratio_w);
137
+ let yy_stop = Math.ceil((j + 1) * ratio_h);
138
+ xx_stop = Math.min(xx_stop, width_source);
139
+ yy_stop = Math.min(yy_stop, height_source);
140
+ for (let yy = yy_start; yy < yy_stop; yy++) {
141
+ const dy = Math.abs(center_y - yy) / ratio_h_half;
142
+ const center_x = i * ratio_w;
143
+ const w0 = dy * dy; //pre-calc part of w
144
+ for (let xx = xx_start; xx < xx_stop; xx++) {
145
+ const dx = Math.abs(center_x - xx) / ratio_w_half;
146
+ const w = Math.sqrt(w0 + dx * dx);
147
+ if (w >= 1) {
148
+ //pixel too far
149
+ continue;
150
+ }
151
+ //hermite filter
152
+ weight = 2 * w * w * w - 3 * w * w + 1;
153
+ const pos_x = 4 * (xx + yy * width_source);
154
+ //alpha
155
+ gx_a += weight * data[pos_x + 3];
156
+ weights_alpha += weight;
157
+ //colors
158
+ if (data[pos_x + 3] < 255)
159
+ weight = weight * data[pos_x + 3] / 250;
160
+ gx_r += weight * data[pos_x];
161
+ gx_g += weight * data[pos_x + 1];
162
+ gx_b += weight * data[pos_x + 2];
163
+ weights += weight;
164
+ }
165
+ }
166
+ data2[x2] = gx_r / weights;
167
+ data2[x2 + 1] = gx_g / weights;
168
+ data2[x2 + 2] = gx_b / weights;
169
+ data2[x2 + 3] = gx_a / weights_alpha;
170
+ }
171
+ }
172
+ canvas.width = width;
173
+ canvas.height = height;
174
+ //draw
175
+ ctx.putImageData(img2, 0, 0);
176
+ }
177
+ }
178
+
179
+ class CropService {
180
+ crop(sourceImage, loadedImage, cropper, settings) {
181
+ const imagePosition = this.getImagePosition(sourceImage, loadedImage, cropper, settings);
182
+ const width = imagePosition.x2 - imagePosition.x1;
183
+ const height = imagePosition.y2 - imagePosition.y1;
184
+ const cropCanvas = document.createElement('canvas');
185
+ cropCanvas.width = width;
186
+ cropCanvas.height = height;
187
+ const ctx = cropCanvas.getContext('2d');
188
+ if (!ctx) {
189
+ return null;
190
+ }
191
+ if (settings.backgroundColor != null) {
192
+ ctx.fillStyle = settings.backgroundColor;
193
+ ctx.fillRect(0, 0, width, height);
194
+ }
195
+ const scaleX = (settings.transform.scale || 1) * (settings.transform.flipH ? -1 : 1);
196
+ const scaleY = (settings.transform.scale || 1) * (settings.transform.flipV ? -1 : 1);
197
+ const transformedImage = loadedImage.transformed;
198
+ ctx.setTransform(scaleX, 0, 0, scaleY, transformedImage.size.width / 2, transformedImage.size.height / 2);
199
+ ctx.translate(-imagePosition.x1 / scaleX, -imagePosition.y1 / scaleY);
200
+ ctx.rotate((settings.transform.rotate || 0) * Math.PI / 180);
201
+ ctx.drawImage(transformedImage.image, -transformedImage.size.width / 2, -transformedImage.size.height / 2);
202
+ const output = {
203
+ width, height,
204
+ imagePosition,
205
+ cropperPosition: { ...cropper }
206
+ };
207
+ if (settings.containWithinAspectRatio) {
208
+ output.offsetImagePosition = this.getOffsetImagePosition(sourceImage, loadedImage, cropper, settings);
209
+ }
210
+ const resizeRatio = this.getResizeRatio(width, height, settings);
211
+ if (resizeRatio !== 1) {
212
+ output.width = Math.round(width * resizeRatio);
213
+ output.height = settings.maintainAspectRatio
214
+ ? Math.round(output.width / settings.aspectRatio)
215
+ : Math.round(height * resizeRatio);
216
+ resizeCanvas(cropCanvas, output.width, output.height);
217
+ }
218
+ output.base64 = cropCanvas.toDataURL('image/' + settings.format, this.getQuality(settings));
219
+ return output;
220
+ }
221
+ getImagePosition(sourceImage, loadedImage, cropper, settings) {
222
+ const sourceImageElement = sourceImage.nativeElement;
223
+ const ratio = loadedImage.transformed.size.width / sourceImageElement.offsetWidth;
224
+ const out = {
225
+ x1: Math.round(cropper.x1 * ratio),
226
+ y1: Math.round(cropper.y1 * ratio),
227
+ x2: Math.round(cropper.x2 * ratio),
228
+ y2: Math.round(cropper.y2 * ratio)
229
+ };
230
+ if (!settings.containWithinAspectRatio) {
231
+ out.x1 = Math.max(out.x1, 0);
232
+ out.y1 = Math.max(out.y1, 0);
233
+ out.x2 = Math.min(out.x2, loadedImage.transformed.size.width);
234
+ out.y2 = Math.min(out.y2, loadedImage.transformed.size.height);
235
+ }
236
+ return out;
237
+ }
238
+ getOffsetImagePosition(sourceImage, loadedImage, cropper, settings) {
239
+ const canvasRotation = settings.canvasRotation + loadedImage.exifTransform.rotate;
240
+ const sourceImageElement = sourceImage.nativeElement;
241
+ const ratio = loadedImage.transformed.size.width / sourceImageElement.offsetWidth;
242
+ let offsetX;
243
+ let offsetY;
244
+ if (canvasRotation % 2) {
245
+ offsetX = (loadedImage.transformed.size.width - loadedImage.original.size.height) / 2;
246
+ offsetY = (loadedImage.transformed.size.height - loadedImage.original.size.width) / 2;
247
+ }
248
+ else {
249
+ offsetX = (loadedImage.transformed.size.width - loadedImage.original.size.width) / 2;
250
+ offsetY = (loadedImage.transformed.size.height - loadedImage.original.size.height) / 2;
251
+ }
252
+ const out = {
253
+ x1: Math.round(cropper.x1 * ratio) - offsetX,
254
+ y1: Math.round(cropper.y1 * ratio) - offsetY,
255
+ x2: Math.round(cropper.x2 * ratio) - offsetX,
256
+ y2: Math.round(cropper.y2 * ratio) - offsetY
257
+ };
258
+ if (!settings.containWithinAspectRatio) {
259
+ out.x1 = Math.max(out.x1, 0);
260
+ out.y1 = Math.max(out.y1, 0);
261
+ out.x2 = Math.min(out.x2, loadedImage.transformed.size.width);
262
+ out.y2 = Math.min(out.y2, loadedImage.transformed.size.height);
263
+ }
264
+ return out;
265
+ }
266
+ getResizeRatio(width, height, settings) {
267
+ const ratioWidth = settings.resizeToWidth / width;
268
+ const ratioHeight = settings.resizeToHeight / height;
269
+ const ratios = new Array();
270
+ if (settings.resizeToWidth > 0) {
271
+ ratios.push(ratioWidth);
272
+ }
273
+ if (settings.resizeToHeight > 0) {
274
+ ratios.push(ratioHeight);
275
+ }
276
+ const result = ratios.length === 0 ? 1 : Math.min(...ratios);
277
+ if (result > 1 && !settings.onlyScaleDown) {
278
+ return result;
279
+ }
280
+ return Math.min(result, 1);
281
+ }
282
+ getQuality(settings) {
283
+ return Math.min(1, Math.max(0, settings.imageQuality / 100));
284
+ }
285
+ }
286
+ CropService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: CropService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
287
+ CropService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: CropService, providedIn: 'root' });
288
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: CropService, decorators: [{
289
+ type: Injectable,
290
+ args: [{ providedIn: 'root' }]
291
+ }] });
292
+
293
+ class CropperPositionService {
294
+ resetCropperPosition(sourceImage, cropperPosition, settings) {
295
+ if (!sourceImage?.nativeElement) {
296
+ return;
297
+ }
298
+ const sourceImageElement = sourceImage.nativeElement;
299
+ if (settings.cropperStaticHeight && settings.cropperStaticWidth) {
300
+ cropperPosition.x1 = 0;
301
+ cropperPosition.x2 = sourceImageElement.offsetWidth > settings.cropperStaticWidth ?
302
+ settings.cropperStaticWidth : sourceImageElement.offsetWidth;
303
+ cropperPosition.y1 = 0;
304
+ cropperPosition.y2 = sourceImageElement.offsetHeight > settings.cropperStaticHeight ?
305
+ settings.cropperStaticHeight : sourceImageElement.offsetHeight;
306
+ }
307
+ else {
308
+ const cropperWidth = Math.min(settings.cropperScaledMaxWidth, sourceImageElement.offsetWidth);
309
+ const cropperHeight = Math.min(settings.cropperScaledMaxHeight, sourceImageElement.offsetHeight);
310
+ if (!settings.maintainAspectRatio) {
311
+ cropperPosition.x1 = 0;
312
+ cropperPosition.x2 = cropperWidth;
313
+ cropperPosition.y1 = 0;
314
+ cropperPosition.y2 = cropperHeight;
315
+ }
316
+ else if (sourceImageElement.offsetWidth / settings.aspectRatio < sourceImageElement.offsetHeight) {
317
+ cropperPosition.x1 = 0;
318
+ cropperPosition.x2 = cropperWidth;
319
+ const cropperHeightWithAspectRatio = cropperWidth / settings.aspectRatio;
320
+ cropperPosition.y1 = (sourceImageElement.offsetHeight - cropperHeightWithAspectRatio) / 2;
321
+ cropperPosition.y2 = cropperPosition.y1 + cropperHeightWithAspectRatio;
322
+ }
323
+ else {
324
+ cropperPosition.y1 = 0;
325
+ cropperPosition.y2 = cropperHeight;
326
+ const cropperWidthWithAspectRatio = cropperHeight * settings.aspectRatio;
327
+ cropperPosition.x1 = (sourceImageElement.offsetWidth - cropperWidthWithAspectRatio) / 2;
328
+ cropperPosition.x2 = cropperPosition.x1 + cropperWidthWithAspectRatio;
329
+ }
330
+ }
331
+ }
332
+ move(event, moveStart, cropperPosition) {
333
+ const diffX = this.getClientX(event) - moveStart.clientX;
334
+ const diffY = this.getClientY(event) - moveStart.clientY;
335
+ cropperPosition.x1 = moveStart.x1 + diffX;
336
+ cropperPosition.y1 = moveStart.y1 + diffY;
337
+ cropperPosition.x2 = moveStart.x2 + diffX;
338
+ cropperPosition.y2 = moveStart.y2 + diffY;
339
+ }
340
+ resize(event, moveStart, cropperPosition, maxSize, settings) {
341
+ const moveX = this.getClientX(event) - moveStart.clientX;
342
+ const moveY = this.getClientY(event) - moveStart.clientY;
343
+ switch (moveStart.position) {
344
+ case 'left':
345
+ cropperPosition.x1 = Math.min(Math.max(moveStart.x1 + moveX, cropperPosition.x2 - settings.cropperScaledMaxWidth), cropperPosition.x2 - settings.cropperScaledMinWidth);
346
+ break;
347
+ case 'topleft':
348
+ cropperPosition.x1 = Math.min(Math.max(moveStart.x1 + moveX, cropperPosition.x2 - settings.cropperScaledMaxWidth), cropperPosition.x2 - settings.cropperScaledMinWidth);
349
+ cropperPosition.y1 = Math.min(Math.max(moveStart.y1 + moveY, cropperPosition.y2 - settings.cropperScaledMaxHeight), cropperPosition.y2 - settings.cropperScaledMinHeight);
350
+ break;
351
+ case 'top':
352
+ cropperPosition.y1 = Math.min(Math.max(moveStart.y1 + moveY, cropperPosition.y2 - settings.cropperScaledMaxHeight), cropperPosition.y2 - settings.cropperScaledMinHeight);
353
+ break;
354
+ case 'topright':
355
+ cropperPosition.x2 = Math.max(Math.min(moveStart.x2 + moveX, cropperPosition.x1 + settings.cropperScaledMaxWidth), cropperPosition.x1 + settings.cropperScaledMinWidth);
356
+ cropperPosition.y1 = Math.min(Math.max(moveStart.y1 + moveY, cropperPosition.y2 - settings.cropperScaledMaxHeight), cropperPosition.y2 - settings.cropperScaledMinHeight);
357
+ break;
358
+ case 'right':
359
+ cropperPosition.x2 = Math.max(Math.min(moveStart.x2 + moveX, cropperPosition.x1 + settings.cropperScaledMaxWidth), cropperPosition.x1 + settings.cropperScaledMinWidth);
360
+ break;
361
+ case 'bottomright':
362
+ cropperPosition.x2 = Math.max(Math.min(moveStart.x2 + moveX, cropperPosition.x1 + settings.cropperScaledMaxWidth), cropperPosition.x1 + settings.cropperScaledMinWidth);
363
+ cropperPosition.y2 = Math.max(Math.min(moveStart.y2 + moveY, cropperPosition.y1 + settings.cropperScaledMaxHeight), cropperPosition.y1 + settings.cropperScaledMinHeight);
364
+ break;
365
+ case 'bottom':
366
+ cropperPosition.y2 = Math.max(Math.min(moveStart.y2 + moveY, cropperPosition.y1 + settings.cropperScaledMaxHeight), cropperPosition.y1 + settings.cropperScaledMinHeight);
367
+ break;
368
+ case 'bottomleft':
369
+ cropperPosition.x1 = Math.min(Math.max(moveStart.x1 + moveX, cropperPosition.x2 - settings.cropperScaledMaxWidth), cropperPosition.x2 - settings.cropperScaledMinWidth);
370
+ cropperPosition.y2 = Math.max(Math.min(moveStart.y2 + moveY, cropperPosition.y1 + settings.cropperScaledMaxHeight), cropperPosition.y1 + settings.cropperScaledMinHeight);
371
+ break;
372
+ case 'center':
373
+ const scale = event.scale;
374
+ const newWidth = Math.min(Math.max(settings.cropperScaledMinWidth, (Math.abs(moveStart.x2 - moveStart.x1)) * scale), settings.cropperScaledMaxWidth);
375
+ const newHeight = Math.min(Math.max(settings.cropperScaledMinHeight, (Math.abs(moveStart.y2 - moveStart.y1)) * scale), settings.cropperScaledMaxHeight);
376
+ cropperPosition.x1 = moveStart.clientX - newWidth / 2;
377
+ cropperPosition.x2 = moveStart.clientX + newWidth / 2;
378
+ cropperPosition.y1 = moveStart.clientY - newHeight / 2;
379
+ cropperPosition.y2 = moveStart.clientY + newHeight / 2;
380
+ if (cropperPosition.x1 < 0) {
381
+ cropperPosition.x2 -= cropperPosition.x1;
382
+ cropperPosition.x1 = 0;
383
+ }
384
+ else if (cropperPosition.x2 > maxSize.width) {
385
+ cropperPosition.x1 -= (cropperPosition.x2 - maxSize.width);
386
+ cropperPosition.x2 = maxSize.width;
387
+ }
388
+ if (cropperPosition.y1 < 0) {
389
+ cropperPosition.y2 -= cropperPosition.y1;
390
+ cropperPosition.y1 = 0;
391
+ }
392
+ else if (cropperPosition.y2 > maxSize.height) {
393
+ cropperPosition.y1 -= (cropperPosition.y2 - maxSize.height);
394
+ cropperPosition.y2 = maxSize.height;
395
+ }
396
+ break;
397
+ }
398
+ if (settings.maintainAspectRatio) {
399
+ this.checkAspectRatio(moveStart.position, cropperPosition, maxSize, settings);
400
+ }
401
+ }
402
+ checkAspectRatio(position, cropperPosition, maxSize, settings) {
403
+ let overflowX = 0;
404
+ let overflowY = 0;
405
+ switch (position) {
406
+ case 'top':
407
+ cropperPosition.x2 = cropperPosition.x1 + (cropperPosition.y2 - cropperPosition.y1) * settings.aspectRatio;
408
+ overflowX = Math.max(cropperPosition.x2 - maxSize.width, 0);
409
+ overflowY = Math.max(0 - cropperPosition.y1, 0);
410
+ if (overflowX > 0 || overflowY > 0) {
411
+ cropperPosition.x2 -= (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
412
+ cropperPosition.y1 += (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
413
+ }
414
+ break;
415
+ case 'bottom':
416
+ cropperPosition.x2 = cropperPosition.x1 + (cropperPosition.y2 - cropperPosition.y1) * settings.aspectRatio;
417
+ overflowX = Math.max(cropperPosition.x2 - maxSize.width, 0);
418
+ overflowY = Math.max(cropperPosition.y2 - maxSize.height, 0);
419
+ if (overflowX > 0 || overflowY > 0) {
420
+ cropperPosition.x2 -= (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
421
+ cropperPosition.y2 -= (overflowY * settings.aspectRatio) > overflowX ? overflowY : (overflowX / settings.aspectRatio);
422
+ }
423
+ break;
424
+ case 'topleft':
425
+ cropperPosition.y1 = cropperPosition.y2 - (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
426
+ overflowX = Math.max(0 - cropperPosition.x1, 0);
427
+ overflowY = Math.max(0 - cropperPosition.y1, 0);
428
+ if (overflowX > 0 || overflowY > 0) {
429
+ cropperPosition.x1 += (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
430
+ cropperPosition.y1 += (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
431
+ }
432
+ break;
433
+ case 'topright':
434
+ cropperPosition.y1 = cropperPosition.y2 - (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
435
+ overflowX = Math.max(cropperPosition.x2 - maxSize.width, 0);
436
+ overflowY = Math.max(0 - cropperPosition.y1, 0);
437
+ if (overflowX > 0 || overflowY > 0) {
438
+ cropperPosition.x2 -= (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
439
+ cropperPosition.y1 += (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
440
+ }
441
+ break;
442
+ case 'right':
443
+ case 'bottomright':
444
+ cropperPosition.y2 = cropperPosition.y1 + (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
445
+ overflowX = Math.max(cropperPosition.x2 - maxSize.width, 0);
446
+ overflowY = Math.max(cropperPosition.y2 - maxSize.height, 0);
447
+ if (overflowX > 0 || overflowY > 0) {
448
+ cropperPosition.x2 -= (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
449
+ cropperPosition.y2 -= (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
450
+ }
451
+ break;
452
+ case 'left':
453
+ case 'bottomleft':
454
+ cropperPosition.y2 = cropperPosition.y1 + (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
455
+ overflowX = Math.max(0 - cropperPosition.x1, 0);
456
+ overflowY = Math.max(cropperPosition.y2 - maxSize.height, 0);
457
+ if (overflowX > 0 || overflowY > 0) {
458
+ cropperPosition.x1 += (overflowY * settings.aspectRatio) > overflowX ? (overflowY * settings.aspectRatio) : overflowX;
459
+ cropperPosition.y2 -= (overflowY * settings.aspectRatio) > overflowX ? overflowY : overflowX / settings.aspectRatio;
460
+ }
461
+ break;
462
+ case 'center':
463
+ cropperPosition.x2 = cropperPosition.x1 + (cropperPosition.y2 - cropperPosition.y1) * settings.aspectRatio;
464
+ cropperPosition.y2 = cropperPosition.y1 + (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
465
+ const overflowX1 = Math.max(0 - cropperPosition.x1, 0);
466
+ const overflowX2 = Math.max(cropperPosition.x2 - maxSize.width, 0);
467
+ const overflowY1 = Math.max(cropperPosition.y2 - maxSize.height, 0);
468
+ const overflowY2 = Math.max(0 - cropperPosition.y1, 0);
469
+ if (overflowX1 > 0 || overflowX2 > 0 || overflowY1 > 0 || overflowY2 > 0) {
470
+ cropperPosition.x1 += (overflowY1 * settings.aspectRatio) > overflowX1 ? (overflowY1 * settings.aspectRatio) : overflowX1;
471
+ cropperPosition.x2 -= (overflowY2 * settings.aspectRatio) > overflowX2 ? (overflowY2 * settings.aspectRatio) : overflowX2;
472
+ cropperPosition.y1 += (overflowY2 * settings.aspectRatio) > overflowX2 ? overflowY2 : overflowX2 / settings.aspectRatio;
473
+ cropperPosition.y2 -= (overflowY1 * settings.aspectRatio) > overflowX1 ? overflowY1 : overflowX1 / settings.aspectRatio;
474
+ }
475
+ break;
476
+ }
477
+ }
478
+ getClientX(event) {
479
+ return event.touches?.[0].clientX || event.clientX || 0;
480
+ }
481
+ getClientY(event) {
482
+ return event.touches?.[0].clientY || event.clientY || 0;
483
+ }
484
+ }
485
+ CropperPositionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: CropperPositionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
486
+ CropperPositionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: CropperPositionService, providedIn: 'root' });
487
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: CropperPositionService, decorators: [{
488
+ type: Injectable,
489
+ args: [{ providedIn: 'root' }]
490
+ }] });
491
+
492
+ // Black 2x1 JPEG, with the following meta information set:
493
+ // - EXIF Orientation: 6 (Rotated 90° CCW)
494
+ // Source: https://github.com/blueimp/JavaScript-Load-Image
495
+ const testAutoOrientationImageURL = 'data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAA' +
496
+ 'AAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA' +
497
+ 'QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE' +
498
+ 'BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/x' +
499
+ 'ABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAA' +
500
+ 'AAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==';
501
+ function supportsAutomaticRotation() {
502
+ return new Promise((resolve) => {
503
+ const img = new Image();
504
+ img.onload = () => {
505
+ // Check if browser supports automatic image orientation:
506
+ const supported = img.width === 1 && img.height === 2;
507
+ resolve(supported);
508
+ };
509
+ img.src = testAutoOrientationImageURL;
510
+ });
511
+ }
512
+ function getTransformationsFromExifData(exifRotationOrBase64Image) {
513
+ if (typeof exifRotationOrBase64Image === 'string') {
514
+ exifRotationOrBase64Image = getExifRotation(exifRotationOrBase64Image);
515
+ }
516
+ switch (exifRotationOrBase64Image) {
517
+ case 2:
518
+ return { rotate: 0, flip: true };
519
+ case 3:
520
+ return { rotate: 2, flip: false };
521
+ case 4:
522
+ return { rotate: 2, flip: true };
523
+ case 5:
524
+ return { rotate: 1, flip: true };
525
+ case 6:
526
+ return { rotate: 1, flip: false };
527
+ case 7:
528
+ return { rotate: 3, flip: true };
529
+ case 8:
530
+ return { rotate: 3, flip: false };
531
+ default:
532
+ return { rotate: 0, flip: false };
533
+ }
534
+ }
535
+ function getExifRotation(imageBase64) {
536
+ const view = new DataView(base64ToArrayBuffer(imageBase64));
537
+ if (view.getUint16(0, false) !== 0xFFD8) {
538
+ return -2;
539
+ }
540
+ const length = view.byteLength;
541
+ let offset = 2;
542
+ while (offset < length) {
543
+ if (view.getUint16(offset + 2, false) <= 8)
544
+ return -1;
545
+ const marker = view.getUint16(offset, false);
546
+ offset += 2;
547
+ if (marker == 0xFFE1) {
548
+ if (view.getUint32(offset += 2, false) !== 0x45786966) {
549
+ return -1;
550
+ }
551
+ const little = view.getUint16(offset += 6, false) == 0x4949;
552
+ offset += view.getUint32(offset + 4, little);
553
+ const tags = view.getUint16(offset, little);
554
+ offset += 2;
555
+ for (let i = 0; i < tags; i++) {
556
+ if (view.getUint16(offset + (i * 12), little) == 0x0112) {
557
+ return view.getUint16(offset + (i * 12) + 8, little);
558
+ }
559
+ }
560
+ }
561
+ else if ((marker & 0xFF00) !== 0xFF00) {
562
+ break;
563
+ }
564
+ else {
565
+ offset += view.getUint16(offset, false);
566
+ }
567
+ }
568
+ return -1;
569
+ }
570
+ function base64ToArrayBuffer(imageBase64) {
571
+ imageBase64 = imageBase64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
572
+ const binaryString = atob(imageBase64);
573
+ const len = binaryString.length;
574
+ const bytes = new Uint8Array(len);
575
+ for (let i = 0; i < len; i++) {
576
+ bytes[i] = binaryString.charCodeAt(i);
577
+ }
578
+ return bytes.buffer;
579
+ }
580
+
581
+ class LoadImageService {
582
+ constructor() {
583
+ this.autoRotateSupported = supportsAutomaticRotation();
584
+ }
585
+ loadImageFile(file, cropperSettings) {
586
+ return new Promise((resolve, reject) => {
587
+ const fileReader = new FileReader();
588
+ fileReader.onload = (event) => {
589
+ this.loadImage(event.target.result, file.type, cropperSettings)
590
+ .then(resolve)
591
+ .catch(reject);
592
+ };
593
+ fileReader.readAsDataURL(file);
594
+ });
595
+ }
596
+ loadImage(imageBase64, imageType, cropperSettings) {
597
+ if (!this.isValidImageType(imageType)) {
598
+ return Promise.reject(new Error('Invalid image type'));
599
+ }
600
+ return this.loadBase64Image(imageBase64, cropperSettings);
601
+ }
602
+ isValidImageType(type) {
603
+ return /image\/(png|jpg|jpeg|bmp|gif|tiff|webp|x-icon|vnd.microsoft.icon)/.test(type);
604
+ }
605
+ loadImageFromURL(url, cropperSettings) {
606
+ return new Promise((resolve, reject) => {
607
+ const img = new Image();
608
+ img.onerror = () => reject;
609
+ img.onload = () => {
610
+ const canvas = document.createElement('canvas');
611
+ const context = canvas.getContext('2d');
612
+ canvas.width = img.width;
613
+ canvas.height = img.height;
614
+ context?.drawImage(img, 0, 0);
615
+ this.loadBase64Image(canvas.toDataURL(), cropperSettings).then(resolve);
616
+ };
617
+ img.crossOrigin = 'anonymous';
618
+ img.src = url;
619
+ });
620
+ }
621
+ loadBase64Image(imageBase64, cropperSettings) {
622
+ return new Promise((resolve, reject) => {
623
+ const originalImage = new Image();
624
+ originalImage.onload = () => resolve({
625
+ originalImage,
626
+ originalBase64: imageBase64
627
+ });
628
+ originalImage.onerror = reject;
629
+ originalImage.src = imageBase64;
630
+ }).then((res) => this.transformImageBase64(res, cropperSettings));
631
+ }
632
+ async transformImageBase64(res, cropperSettings) {
633
+ const autoRotate = await this.autoRotateSupported;
634
+ const exifTransform = await getTransformationsFromExifData(autoRotate ? -1 : res.originalBase64);
635
+ if (!res.originalImage || !res.originalImage.complete) {
636
+ return Promise.reject(new Error('No image loaded'));
637
+ }
638
+ const loadedImage = {
639
+ original: {
640
+ base64: res.originalBase64,
641
+ image: res.originalImage,
642
+ size: {
643
+ width: res.originalImage.naturalWidth,
644
+ height: res.originalImage.naturalHeight
645
+ }
646
+ },
647
+ exifTransform
648
+ };
649
+ return this.transformLoadedImage(loadedImage, cropperSettings);
650
+ }
651
+ async transformLoadedImage(loadedImage, cropperSettings) {
652
+ const canvasRotation = cropperSettings.canvasRotation + loadedImage.exifTransform.rotate;
653
+ const originalSize = {
654
+ width: loadedImage.original.image.naturalWidth,
655
+ height: loadedImage.original.image.naturalHeight
656
+ };
657
+ if (canvasRotation === 0 && !loadedImage.exifTransform.flip && !cropperSettings.containWithinAspectRatio) {
658
+ return {
659
+ original: {
660
+ base64: loadedImage.original.base64,
661
+ image: loadedImage.original.image,
662
+ size: { ...originalSize }
663
+ },
664
+ transformed: {
665
+ base64: loadedImage.original.base64,
666
+ image: loadedImage.original.image,
667
+ size: { ...originalSize }
668
+ },
669
+ exifTransform: loadedImage.exifTransform
670
+ };
671
+ }
672
+ const transformedSize = this.getTransformedSize(originalSize, loadedImage.exifTransform, cropperSettings);
673
+ const canvas = document.createElement('canvas');
674
+ canvas.width = transformedSize.width;
675
+ canvas.height = transformedSize.height;
676
+ const ctx = canvas.getContext('2d');
677
+ ctx?.setTransform(loadedImage.exifTransform.flip ? -1 : 1, 0, 0, 1, canvas.width / 2, canvas.height / 2);
678
+ ctx?.rotate(Math.PI * (canvasRotation / 2));
679
+ ctx?.drawImage(loadedImage.original.image, -originalSize.width / 2, -originalSize.height / 2);
680
+ const transformedBase64 = canvas.toDataURL();
681
+ const transformedImage = await this.loadImageFromBase64(transformedBase64);
682
+ return {
683
+ original: {
684
+ base64: loadedImage.original.base64,
685
+ image: loadedImage.original.image,
686
+ size: { ...originalSize }
687
+ },
688
+ transformed: {
689
+ base64: transformedBase64,
690
+ image: transformedImage,
691
+ size: {
692
+ width: transformedImage.width,
693
+ height: transformedImage.height
694
+ }
695
+ },
696
+ exifTransform: loadedImage.exifTransform
697
+ };
698
+ }
699
+ loadImageFromBase64(imageBase64) {
700
+ return new Promise(((resolve, reject) => {
701
+ const image = new Image();
702
+ image.onload = () => resolve(image);
703
+ image.onerror = reject;
704
+ image.src = imageBase64;
705
+ }));
706
+ }
707
+ getTransformedSize(originalSize, exifTransform, cropperSettings) {
708
+ const canvasRotation = cropperSettings.canvasRotation + exifTransform.rotate;
709
+ if (cropperSettings.containWithinAspectRatio) {
710
+ if (canvasRotation % 2) {
711
+ const minWidthToContain = originalSize.width * cropperSettings.aspectRatio;
712
+ const minHeightToContain = originalSize.height / cropperSettings.aspectRatio;
713
+ return {
714
+ width: Math.max(originalSize.height, minWidthToContain),
715
+ height: Math.max(originalSize.width, minHeightToContain)
716
+ };
717
+ }
718
+ else {
719
+ const minWidthToContain = originalSize.height * cropperSettings.aspectRatio;
720
+ const minHeightToContain = originalSize.width / cropperSettings.aspectRatio;
721
+ return {
722
+ width: Math.max(originalSize.width, minWidthToContain),
723
+ height: Math.max(originalSize.height, minHeightToContain)
724
+ };
725
+ }
726
+ }
727
+ if (canvasRotation % 2) {
728
+ return {
729
+ height: originalSize.width,
730
+ width: originalSize.height
731
+ };
732
+ }
733
+ return {
734
+ width: originalSize.width,
735
+ height: originalSize.height
736
+ };
737
+ }
738
+ }
739
+ LoadImageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: LoadImageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
740
+ LoadImageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: LoadImageService, providedIn: 'root' });
741
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: LoadImageService, decorators: [{
742
+ type: Injectable,
743
+ args: [{ providedIn: 'root' }]
744
+ }] });
745
+
746
+ class ImageCropperComponent {
747
+ constructor(cropService, cropperPositionService, loadImageService, sanitizer, cd) {
748
+ this.cropService = cropService;
749
+ this.cropperPositionService = cropperPositionService;
750
+ this.loadImageService = loadImageService;
751
+ this.sanitizer = sanitizer;
752
+ this.cd = cd;
753
+ this.Hammer = window?.['Hammer'] || null;
754
+ this.settings = new CropperSettings();
755
+ this.setImageMaxSizeRetries = 0;
756
+ this.marginLeft = '0px';
757
+ this.maxSize = {
758
+ width: 0,
759
+ height: 0
760
+ };
761
+ this.moveTypes = MoveTypes;
762
+ this.imageVisible = false;
763
+ this.format = this.settings.format;
764
+ this.transform = {};
765
+ this.maintainAspectRatio = this.settings.maintainAspectRatio;
766
+ this.aspectRatio = this.settings.aspectRatio;
767
+ this.resizeToWidth = this.settings.resizeToWidth;
768
+ this.resizeToHeight = this.settings.resizeToHeight;
769
+ this.cropperMinWidth = this.settings.cropperMinWidth;
770
+ this.cropperMinHeight = this.settings.cropperMinHeight;
771
+ this.cropperMaxHeight = this.settings.cropperMaxHeight;
772
+ this.cropperMaxWidth = this.settings.cropperMaxWidth;
773
+ this.cropperStaticWidth = this.settings.cropperStaticWidth;
774
+ this.cropperStaticHeight = this.settings.cropperStaticHeight;
775
+ this.canvasRotation = this.settings.canvasRotation;
776
+ this.initialStepSize = this.settings.initialStepSize;
777
+ this.roundCropper = this.settings.roundCropper;
778
+ this.onlyScaleDown = this.settings.onlyScaleDown;
779
+ this.imageQuality = this.settings.imageQuality;
780
+ this.autoCrop = this.settings.autoCrop;
781
+ this.backgroundColor = this.settings.backgroundColor;
782
+ this.containWithinAspectRatio = this.settings.containWithinAspectRatio;
783
+ this.hideResizeSquares = this.settings.hideResizeSquares;
784
+ this.cropper = {
785
+ x1: -100,
786
+ y1: -100,
787
+ x2: 10000,
788
+ y2: 10000
789
+ };
790
+ this.alignImage = this.settings.alignImage;
791
+ this.disabled = false;
792
+ this.imageCropped = new EventEmitter();
793
+ this.startCropImage = new EventEmitter();
794
+ this.imageLoaded = new EventEmitter();
795
+ this.cropperReady = new EventEmitter();
796
+ this.loadImageFailed = new EventEmitter();
797
+ this.reset();
798
+ }
799
+ ngOnChanges(changes) {
800
+ this.onChangesUpdateSettings(changes);
801
+ this.onChangesInputImage(changes);
802
+ if (this.loadedImage?.original.image.complete && (changes['containWithinAspectRatio'] || changes['canvasRotation'])) {
803
+ this.loadImageService
804
+ .transformLoadedImage(this.loadedImage, this.settings)
805
+ .then((res) => this.setLoadedImage(res))
806
+ .catch((err) => this.loadImageError(err));
807
+ }
808
+ if (changes['cropper'] || changes['maintainAspectRatio'] || changes['aspectRatio']) {
809
+ this.setMaxSize();
810
+ this.setCropperScaledMinSize();
811
+ this.setCropperScaledMaxSize();
812
+ if (this.maintainAspectRatio && (changes['maintainAspectRatio'] || changes['aspectRatio'])) {
813
+ this.resetCropperPosition();
814
+ }
815
+ else if (changes['cropper']) {
816
+ this.checkCropperPosition(false);
817
+ this.doAutoCrop();
818
+ }
819
+ this.cd.markForCheck();
820
+ }
821
+ if (changes['transform']) {
822
+ this.transform = this.transform || {};
823
+ this.setCssTransform();
824
+ this.doAutoCrop();
825
+ }
826
+ }
827
+ onChangesUpdateSettings(changes) {
828
+ this.settings.setOptionsFromChanges(changes);
829
+ if (this.settings.cropperStaticHeight && this.settings.cropperStaticWidth) {
830
+ this.settings.setOptions({
831
+ hideResizeSquares: true,
832
+ cropperMinWidth: this.settings.cropperStaticWidth,
833
+ cropperMinHeight: this.settings.cropperStaticHeight,
834
+ cropperMaxHeight: this.settings.cropperStaticHeight,
835
+ cropperMaxWidth: this.settings.cropperStaticWidth,
836
+ maintainAspectRatio: false
837
+ });
838
+ }
839
+ }
840
+ onChangesInputImage(changes) {
841
+ if (changes['imageChangedEvent'] || changes['imageURL'] || changes['imageBase64'] || changes['imageFile']) {
842
+ this.reset();
843
+ }
844
+ if (changes['imageChangedEvent'] && this.isValidImageChangedEvent()) {
845
+ this.loadImageFile(this.imageChangedEvent.target.files[0]);
846
+ }
847
+ if (changes['imageURL'] && this.imageURL) {
848
+ this.loadImageFromURL(this.imageURL);
849
+ }
850
+ if (changes['imageBase64'] && this.imageBase64) {
851
+ this.loadBase64Image(this.imageBase64);
852
+ }
853
+ if (changes['imageFile'] && this.imageFile) {
854
+ this.loadImageFile(this.imageFile);
855
+ }
856
+ }
857
+ isValidImageChangedEvent() {
858
+ return this.imageChangedEvent?.target?.files?.length > 0;
859
+ }
860
+ setCssTransform() {
861
+ this.safeTransformStyle = this.sanitizer.bypassSecurityTrustStyle('scaleX(' + (this.transform.scale || 1) * (this.transform.flipH ? -1 : 1) + ')' +
862
+ 'scaleY(' + (this.transform.scale || 1) * (this.transform.flipV ? -1 : 1) + ')' +
863
+ 'rotate(' + (this.transform.rotate || 0) + 'deg)');
864
+ }
865
+ ngOnInit() {
866
+ this.settings.stepSize = this.initialStepSize;
867
+ this.activatePinchGesture();
868
+ }
869
+ reset() {
870
+ this.imageVisible = false;
871
+ this.loadedImage = undefined;
872
+ this.safeImgDataUrl = 'data:image/png;base64,iVBORw0KGg'
873
+ + 'oAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAU'
874
+ + 'AAarVyFEAAAAASUVORK5CYII=';
875
+ this.moveStart = {
876
+ active: false,
877
+ type: null,
878
+ position: null,
879
+ x1: 0,
880
+ y1: 0,
881
+ x2: 0,
882
+ y2: 0,
883
+ clientX: 0,
884
+ clientY: 0
885
+ };
886
+ this.maxSize = {
887
+ width: 0,
888
+ height: 0
889
+ };
890
+ this.cropper.x1 = -100;
891
+ this.cropper.y1 = -100;
892
+ this.cropper.x2 = 10000;
893
+ this.cropper.y2 = 10000;
894
+ }
895
+ loadImageFile(file) {
896
+ this.loadImageService
897
+ .loadImageFile(file, this.settings)
898
+ .then((res) => this.setLoadedImage(res))
899
+ .catch((err) => this.loadImageError(err));
900
+ }
901
+ loadBase64Image(imageBase64) {
902
+ this.loadImageService
903
+ .loadBase64Image(imageBase64, this.settings)
904
+ .then((res) => this.setLoadedImage(res))
905
+ .catch((err) => this.loadImageError(err));
906
+ }
907
+ loadImageFromURL(url) {
908
+ this.loadImageService
909
+ .loadImageFromURL(url, this.settings)
910
+ .then((res) => this.setLoadedImage(res))
911
+ .catch((err) => this.loadImageError(err));
912
+ }
913
+ setLoadedImage(loadedImage) {
914
+ this.loadedImage = loadedImage;
915
+ this.safeImgDataUrl = this.sanitizer.bypassSecurityTrustResourceUrl(loadedImage.transformed.base64);
916
+ this.cd.markForCheck();
917
+ }
918
+ loadImageError(error) {
919
+ console.error(error);
920
+ this.loadImageFailed.emit();
921
+ }
922
+ imageLoadedInView() {
923
+ if (this.loadedImage != null) {
924
+ this.imageLoaded.emit(this.loadedImage);
925
+ this.setImageMaxSizeRetries = 0;
926
+ setTimeout(() => this.checkImageMaxSizeRecursively());
927
+ }
928
+ }
929
+ checkImageMaxSizeRecursively() {
930
+ if (this.setImageMaxSizeRetries > 40) {
931
+ this.loadImageFailed.emit();
932
+ }
933
+ else if (this.sourceImageLoaded()) {
934
+ this.setMaxSize();
935
+ this.setCropperScaledMinSize();
936
+ this.setCropperScaledMaxSize();
937
+ this.resetCropperPosition();
938
+ this.cropperReady.emit({ ...this.maxSize });
939
+ this.cd.markForCheck();
940
+ }
941
+ else {
942
+ this.setImageMaxSizeRetries++;
943
+ setTimeout(() => this.checkImageMaxSizeRecursively(), 50);
944
+ }
945
+ }
946
+ sourceImageLoaded() {
947
+ return this.sourceImage?.nativeElement?.offsetWidth > 0;
948
+ }
949
+ onResize() {
950
+ if (!this.loadedImage) {
951
+ return;
952
+ }
953
+ this.resizeCropperPosition();
954
+ this.setMaxSize();
955
+ this.setCropperScaledMinSize();
956
+ this.setCropperScaledMaxSize();
957
+ }
958
+ activatePinchGesture() {
959
+ if (this.Hammer) {
960
+ const hammer = new this.Hammer(this.wrapper.nativeElement);
961
+ hammer.get('pinch').set({ enable: true });
962
+ hammer.on('pinchmove', this.onPinch.bind(this));
963
+ hammer.on('pinchend', this.pinchStop.bind(this));
964
+ hammer.on('pinchstart', this.startPinch.bind(this));
965
+ }
966
+ else if (isDevMode()) {
967
+ console.warn('[NgxImageCropper] Could not find HammerJS - Pinch Gesture won\'t work');
968
+ }
969
+ }
970
+ resizeCropperPosition() {
971
+ const sourceImageElement = this.sourceImage.nativeElement;
972
+ if (this.maxSize.width !== sourceImageElement.offsetWidth || this.maxSize.height !== sourceImageElement.offsetHeight) {
973
+ this.cropper.x1 = this.cropper.x1 * sourceImageElement.offsetWidth / this.maxSize.width;
974
+ this.cropper.x2 = this.cropper.x2 * sourceImageElement.offsetWidth / this.maxSize.width;
975
+ this.cropper.y1 = this.cropper.y1 * sourceImageElement.offsetHeight / this.maxSize.height;
976
+ this.cropper.y2 = this.cropper.y2 * sourceImageElement.offsetHeight / this.maxSize.height;
977
+ }
978
+ }
979
+ resetCropperPosition() {
980
+ this.cropperPositionService.resetCropperPosition(this.sourceImage, this.cropper, this.settings);
981
+ this.doAutoCrop();
982
+ this.imageVisible = true;
983
+ }
984
+ keyboardAccess(event) {
985
+ this.changeKeyboardStepSize(event);
986
+ this.keyboardMoveCropper(event);
987
+ }
988
+ changeKeyboardStepSize(event) {
989
+ const key = +event.key;
990
+ if (key >= 1 && key <= 9) {
991
+ this.settings.stepSize = key;
992
+ }
993
+ }
994
+ keyboardMoveCropper(event) {
995
+ const keyboardWhiteList = ['ArrowUp', 'ArrowDown', 'ArrowRight', 'ArrowLeft'];
996
+ if (!(keyboardWhiteList.includes(event.key))) {
997
+ return;
998
+ }
999
+ const moveType = event.shiftKey ? MoveTypes.Resize : MoveTypes.Move;
1000
+ const position = event.altKey ? getInvertedPositionForKey(event.key) : getPositionForKey(event.key);
1001
+ const moveEvent = getEventForKey(event.key, this.settings.stepSize);
1002
+ event.preventDefault();
1003
+ event.stopPropagation();
1004
+ this.startMove({ clientX: 0, clientY: 0 }, moveType, position);
1005
+ this.moveImg(moveEvent);
1006
+ this.moveStop();
1007
+ }
1008
+ startMove(event, moveType, position = null) {
1009
+ if (this.moveStart?.active && this.moveStart?.type === MoveTypes.Pinch) {
1010
+ return;
1011
+ }
1012
+ if (event.preventDefault) {
1013
+ event.preventDefault();
1014
+ }
1015
+ this.moveStart = {
1016
+ active: true,
1017
+ type: moveType,
1018
+ position,
1019
+ clientX: this.cropperPositionService.getClientX(event),
1020
+ clientY: this.cropperPositionService.getClientY(event),
1021
+ ...this.cropper
1022
+ };
1023
+ }
1024
+ startPinch(event) {
1025
+ if (!this.safeImgDataUrl) {
1026
+ return;
1027
+ }
1028
+ if (event.preventDefault) {
1029
+ event.preventDefault();
1030
+ }
1031
+ this.moveStart = {
1032
+ active: true,
1033
+ type: MoveTypes.Pinch,
1034
+ position: 'center',
1035
+ clientX: this.cropper.x1 + (this.cropper.x2 - this.cropper.x1) / 2,
1036
+ clientY: this.cropper.y1 + (this.cropper.y2 - this.cropper.y1) / 2,
1037
+ ...this.cropper
1038
+ };
1039
+ }
1040
+ moveImg(event) {
1041
+ if (this.moveStart.active) {
1042
+ if (event.stopPropagation) {
1043
+ event.stopPropagation();
1044
+ }
1045
+ if (event.preventDefault) {
1046
+ event.preventDefault();
1047
+ }
1048
+ if (this.moveStart.type === MoveTypes.Move) {
1049
+ this.cropperPositionService.move(event, this.moveStart, this.cropper);
1050
+ this.checkCropperPosition(true);
1051
+ }
1052
+ else if (this.moveStart.type === MoveTypes.Resize) {
1053
+ if (!this.cropperStaticWidth && !this.cropperStaticHeight) {
1054
+ this.cropperPositionService.resize(event, this.moveStart, this.cropper, this.maxSize, this.settings);
1055
+ }
1056
+ this.checkCropperPosition(false);
1057
+ }
1058
+ this.cd.detectChanges();
1059
+ }
1060
+ }
1061
+ onPinch(event) {
1062
+ if (this.moveStart.active) {
1063
+ if (event.stopPropagation) {
1064
+ event.stopPropagation();
1065
+ }
1066
+ if (event.preventDefault) {
1067
+ event.preventDefault();
1068
+ }
1069
+ if (this.moveStart.type === MoveTypes.Pinch) {
1070
+ this.cropperPositionService.resize(event, this.moveStart, this.cropper, this.maxSize, this.settings);
1071
+ this.checkCropperPosition(false);
1072
+ }
1073
+ this.cd.detectChanges();
1074
+ }
1075
+ }
1076
+ setMaxSize() {
1077
+ if (this.sourceImage) {
1078
+ const sourceImageElement = this.sourceImage.nativeElement;
1079
+ this.maxSize.width = sourceImageElement.offsetWidth;
1080
+ this.maxSize.height = sourceImageElement.offsetHeight;
1081
+ this.marginLeft = this.sanitizer.bypassSecurityTrustStyle('calc(50% - ' + this.maxSize.width / 2 + 'px)');
1082
+ }
1083
+ }
1084
+ setCropperScaledMinSize() {
1085
+ if (this.loadedImage?.transformed?.image) {
1086
+ this.setCropperScaledMinWidth();
1087
+ this.setCropperScaledMinHeight();
1088
+ }
1089
+ else {
1090
+ this.settings.cropperScaledMinWidth = 20;
1091
+ this.settings.cropperScaledMinHeight = 20;
1092
+ }
1093
+ }
1094
+ setCropperScaledMinWidth() {
1095
+ this.settings.cropperScaledMinWidth = this.cropperMinWidth > 0
1096
+ ? Math.max(20, this.cropperMinWidth / this.loadedImage.transformed.image.width * this.maxSize.width)
1097
+ : 20;
1098
+ }
1099
+ setCropperScaledMinHeight() {
1100
+ if (this.maintainAspectRatio) {
1101
+ this.settings.cropperScaledMinHeight = Math.max(20, this.settings.cropperScaledMinWidth / this.aspectRatio);
1102
+ }
1103
+ else if (this.cropperMinHeight > 0) {
1104
+ this.settings.cropperScaledMinHeight = Math.max(20, this.cropperMinHeight / this.loadedImage.transformed.image.height * this.maxSize.height);
1105
+ }
1106
+ else {
1107
+ this.settings.cropperScaledMinHeight = 20;
1108
+ }
1109
+ }
1110
+ setCropperScaledMaxSize() {
1111
+ if (this.loadedImage?.transformed?.image) {
1112
+ const ratio = this.loadedImage.transformed.size.width / this.maxSize.width;
1113
+ this.settings.cropperScaledMaxWidth = this.cropperMaxWidth > 20 ? this.cropperMaxWidth / ratio : this.maxSize.width;
1114
+ this.settings.cropperScaledMaxHeight = this.cropperMaxHeight > 20 ? this.cropperMaxHeight / ratio : this.maxSize.height;
1115
+ if (this.maintainAspectRatio) {
1116
+ if (this.settings.cropperScaledMaxWidth > this.settings.cropperScaledMaxHeight * this.aspectRatio) {
1117
+ this.settings.cropperScaledMaxWidth = this.settings.cropperScaledMaxHeight * this.aspectRatio;
1118
+ }
1119
+ else if (this.settings.cropperScaledMaxWidth < this.settings.cropperScaledMaxHeight * this.aspectRatio) {
1120
+ this.settings.cropperScaledMaxHeight = this.settings.cropperScaledMaxWidth / this.aspectRatio;
1121
+ }
1122
+ }
1123
+ }
1124
+ else {
1125
+ this.settings.cropperScaledMaxWidth = this.maxSize.width;
1126
+ this.settings.cropperScaledMaxHeight = this.maxSize.height;
1127
+ }
1128
+ }
1129
+ checkCropperPosition(maintainSize = false) {
1130
+ if (this.cropper.x1 < 0) {
1131
+ this.cropper.x2 -= maintainSize ? this.cropper.x1 : 0;
1132
+ this.cropper.x1 = 0;
1133
+ }
1134
+ if (this.cropper.y1 < 0) {
1135
+ this.cropper.y2 -= maintainSize ? this.cropper.y1 : 0;
1136
+ this.cropper.y1 = 0;
1137
+ }
1138
+ if (this.cropper.x2 > this.maxSize.width) {
1139
+ this.cropper.x1 -= maintainSize ? (this.cropper.x2 - this.maxSize.width) : 0;
1140
+ this.cropper.x2 = this.maxSize.width;
1141
+ }
1142
+ if (this.cropper.y2 > this.maxSize.height) {
1143
+ this.cropper.y1 -= maintainSize ? (this.cropper.y2 - this.maxSize.height) : 0;
1144
+ this.cropper.y2 = this.maxSize.height;
1145
+ }
1146
+ }
1147
+ moveStop() {
1148
+ if (this.moveStart.active) {
1149
+ this.moveStart.active = false;
1150
+ this.doAutoCrop();
1151
+ }
1152
+ }
1153
+ pinchStop() {
1154
+ if (this.moveStart.active) {
1155
+ this.moveStart.active = false;
1156
+ this.doAutoCrop();
1157
+ }
1158
+ }
1159
+ doAutoCrop() {
1160
+ if (this.autoCrop) {
1161
+ this.crop();
1162
+ }
1163
+ }
1164
+ crop() {
1165
+ if (this.loadedImage?.transformed?.image != null) {
1166
+ this.startCropImage.emit();
1167
+ const output = this.cropService.crop(this.sourceImage, this.loadedImage, this.cropper, this.settings);
1168
+ if (output != null) {
1169
+ this.imageCropped.emit(output);
1170
+ }
1171
+ return output;
1172
+ }
1173
+ return null;
1174
+ }
1175
+ }
1176
+ ImageCropperComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ImageCropperComponent, deps: [{ token: CropService }, { token: CropperPositionService }, { token: LoadImageService }, { token: i4.DomSanitizer }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
1177
+ ImageCropperComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.1.1", type: ImageCropperComponent, selector: "image-cropper", inputs: { imageChangedEvent: "imageChangedEvent", imageURL: "imageURL", imageBase64: "imageBase64", imageFile: "imageFile", format: "format", transform: "transform", maintainAspectRatio: "maintainAspectRatio", aspectRatio: "aspectRatio", resizeToWidth: "resizeToWidth", resizeToHeight: "resizeToHeight", cropperMinWidth: "cropperMinWidth", cropperMinHeight: "cropperMinHeight", cropperMaxHeight: "cropperMaxHeight", cropperMaxWidth: "cropperMaxWidth", cropperStaticWidth: "cropperStaticWidth", cropperStaticHeight: "cropperStaticHeight", canvasRotation: "canvasRotation", initialStepSize: "initialStepSize", roundCropper: "roundCropper", onlyScaleDown: "onlyScaleDown", imageQuality: "imageQuality", autoCrop: "autoCrop", backgroundColor: "backgroundColor", containWithinAspectRatio: "containWithinAspectRatio", hideResizeSquares: "hideResizeSquares", cropper: "cropper", alignImage: "alignImage", disabled: "disabled" }, outputs: { imageCropped: "imageCropped", startCropImage: "startCropImage", imageLoaded: "imageLoaded", cropperReady: "cropperReady", loadImageFailed: "loadImageFailed" }, host: { listeners: { "window:resize": "onResize()", "document:mousemove": "moveImg($event)", "document:touchmove": "moveImg($event)", "document:mouseup": "moveStop()", "document:touchend": "moveStop()" }, properties: { "style.text-align": "this.alignImage", "class.disabled": "this.disabled" } }, viewQueries: [{ propertyName: "wrapper", first: true, predicate: ["wrapper"], descendants: true, static: true }, { propertyName: "sourceImage", first: true, predicate: ["sourceImage"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<div [style.background]=\"imageVisible && backgroundColor\"\n #wrapper\n>\n <img\n #sourceImage\n class=\"ngx-ic-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=\"ngx-ic-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=\"ngx-ic-cropper\"\n *ngIf=\"imageVisible\"\n [class.ngx-ic-round]=\"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=\"ngx-ic-move\">\n </div>\n <ng-container *ngIf=\"!hideResizeSquares\">\n <span class=\"ngx-ic-resize ngx-ic-topleft\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'topleft')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'topleft')\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-top\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-topright\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'topright')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'topright')\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-right\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-bottomright\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'bottomright')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'bottomright')\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-bottom\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-bottomleft\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'bottomleft')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'bottomleft')\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-left\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize-bar ngx-ic-top\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'top')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'top')\">\n </span>\n <span class=\"ngx-ic-resize-bar ngx-ic-right\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'right')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'right')\">\n </span>\n <span class=\"ngx-ic-resize-bar ngx-ic-bottom\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'bottom')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'bottom')\">\n </span>\n <span class=\"ngx-ic-resize-bar ngx-ic-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", 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.ngx-ic-source-image{max-width:100%;max-height:100%;transform-origin:center}:host .ngx-ic-overlay{position:absolute;pointer-events:none;touch-action:none;outline:var(--cropper-overlay-color, white) solid 100vw;top:0;left:0}:host .ngx-ic-cropper{position:absolute;display:flex;color:#53535c;background:transparent;outline:rgba(255,255,255,.3) solid 100vw;outline:var(--cropper-outline-color, rgba(255, 255, 255, .3)) solid 100vw;touch-action:none}@media (orientation: portrait){:host .ngx-ic-cropper{outline-width:100vh}}:host .ngx-ic-cropper:after{position:absolute;content:\"\";top:0;bottom:0;left:0;right:0;pointer-events:none;border:dashed 1px;opacity:.75;color:inherit;z-index:1}:host .ngx-ic-cropper .ngx-ic-move{width:100%;cursor:move;border:1px solid rgba(255,255,255,.5)}:host .ngx-ic-cropper:focus .ngx-ic-move{border-color:#1e90ff;border-width:2px}:host .ngx-ic-cropper .ngx-ic-resize{position:absolute;display:inline-block;line-height:6px;padding:8px;opacity:.85;z-index:1}:host .ngx-ic-cropper .ngx-ic-resize .ngx-ic-square{display:inline-block;background:#53535C;width:6px;height:6px;border:1px solid rgba(255,255,255,.5);box-sizing:content-box}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-topleft{top:-12px;left:-12px;cursor:nwse-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-top{top:-12px;left:calc(50% - 12px);cursor:ns-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-topright{top:-12px;right:-12px;cursor:nesw-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-right{top:calc(50% - 12px);right:-12px;cursor:ew-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-bottomright{bottom:-12px;right:-12px;cursor:nwse-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-bottom{bottom:-12px;left:calc(50% - 12px);cursor:ns-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-bottomleft{bottom:-12px;left:-12px;cursor:nesw-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-left{top:calc(50% - 12px);left:-12px;cursor:ew-resize}:host .ngx-ic-cropper .ngx-ic-resize-bar{position:absolute;z-index:1}:host .ngx-ic-cropper .ngx-ic-resize-bar.ngx-ic-top{top:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:ns-resize}:host .ngx-ic-cropper .ngx-ic-resize-bar.ngx-ic-right{top:11px;right:-11px;height:calc(100% - 22px);width:22px;cursor:ew-resize}:host .ngx-ic-cropper .ngx-ic-resize-bar.ngx-ic-bottom{bottom:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:ns-resize}:host .ngx-ic-cropper .ngx-ic-resize-bar.ngx-ic-left{top:11px;left:-11px;height:calc(100% - 22px);width:22px;cursor:ew-resize}:host .ngx-ic-cropper.ngx-ic-round{outline-color:transparent}:host .ngx-ic-cropper.ngx-ic-round:after{border-radius:100%;box-shadow:0 0 0 100vw #ffffff4d;box-shadow:0 0 0 100vw var(--cropper-outline-color, rgba(255, 255, 255, .3))}@media (orientation: portrait){:host .ngx-ic-cropper.ngx-ic-round:after{box-shadow:0 0 0 100vh #ffffff4d;box-shadow:0 0 0 100vh var(--cropper-outline-color, rgba(255, 255, 255, .3))}}:host .ngx-ic-cropper.ngx-ic-round .ngx-ic-move{border-radius:100%}:host.disabled .ngx-ic-cropper .ngx-ic-resize,:host.disabled .ngx-ic-cropper .ngx-ic-resize-bar,:host.disabled .ngx-ic-cropper .ngx-ic-move{display:none}\n"], directives: [{ type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1178
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ImageCropperComponent, decorators: [{
1179
+ type: Component,
1180
+ args: [{ selector: 'image-cropper', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [style.background]=\"imageVisible && backgroundColor\"\n #wrapper\n>\n <img\n #sourceImage\n class=\"ngx-ic-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=\"ngx-ic-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=\"ngx-ic-cropper\"\n *ngIf=\"imageVisible\"\n [class.ngx-ic-round]=\"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=\"ngx-ic-move\">\n </div>\n <ng-container *ngIf=\"!hideResizeSquares\">\n <span class=\"ngx-ic-resize ngx-ic-topleft\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'topleft')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'topleft')\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-top\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-topright\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'topright')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'topright')\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-right\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-bottomright\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'bottomright')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'bottomright')\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-bottom\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-bottomleft\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'bottomleft')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'bottomleft')\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize ngx-ic-left\">\n <span class=\"ngx-ic-square\"></span>\n </span>\n <span class=\"ngx-ic-resize-bar ngx-ic-top\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'top')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'top')\">\n </span>\n <span class=\"ngx-ic-resize-bar ngx-ic-right\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'right')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'right')\">\n </span>\n <span class=\"ngx-ic-resize-bar ngx-ic-bottom\"\n (mousedown)=\"startMove($event, moveTypes.Resize, 'bottom')\"\n (touchstart)=\"startMove($event, moveTypes.Resize, 'bottom')\">\n </span>\n <span class=\"ngx-ic-resize-bar ngx-ic-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", 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.ngx-ic-source-image{max-width:100%;max-height:100%;transform-origin:center}:host .ngx-ic-overlay{position:absolute;pointer-events:none;touch-action:none;outline:var(--cropper-overlay-color, white) solid 100vw;top:0;left:0}:host .ngx-ic-cropper{position:absolute;display:flex;color:#53535c;background:transparent;outline:rgba(255,255,255,.3) solid 100vw;outline:var(--cropper-outline-color, rgba(255, 255, 255, .3)) solid 100vw;touch-action:none}@media (orientation: portrait){:host .ngx-ic-cropper{outline-width:100vh}}:host .ngx-ic-cropper:after{position:absolute;content:\"\";top:0;bottom:0;left:0;right:0;pointer-events:none;border:dashed 1px;opacity:.75;color:inherit;z-index:1}:host .ngx-ic-cropper .ngx-ic-move{width:100%;cursor:move;border:1px solid rgba(255,255,255,.5)}:host .ngx-ic-cropper:focus .ngx-ic-move{border-color:#1e90ff;border-width:2px}:host .ngx-ic-cropper .ngx-ic-resize{position:absolute;display:inline-block;line-height:6px;padding:8px;opacity:.85;z-index:1}:host .ngx-ic-cropper .ngx-ic-resize .ngx-ic-square{display:inline-block;background:#53535C;width:6px;height:6px;border:1px solid rgba(255,255,255,.5);box-sizing:content-box}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-topleft{top:-12px;left:-12px;cursor:nwse-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-top{top:-12px;left:calc(50% - 12px);cursor:ns-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-topright{top:-12px;right:-12px;cursor:nesw-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-right{top:calc(50% - 12px);right:-12px;cursor:ew-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-bottomright{bottom:-12px;right:-12px;cursor:nwse-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-bottom{bottom:-12px;left:calc(50% - 12px);cursor:ns-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-bottomleft{bottom:-12px;left:-12px;cursor:nesw-resize}:host .ngx-ic-cropper .ngx-ic-resize.ngx-ic-left{top:calc(50% - 12px);left:-12px;cursor:ew-resize}:host .ngx-ic-cropper .ngx-ic-resize-bar{position:absolute;z-index:1}:host .ngx-ic-cropper .ngx-ic-resize-bar.ngx-ic-top{top:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:ns-resize}:host .ngx-ic-cropper .ngx-ic-resize-bar.ngx-ic-right{top:11px;right:-11px;height:calc(100% - 22px);width:22px;cursor:ew-resize}:host .ngx-ic-cropper .ngx-ic-resize-bar.ngx-ic-bottom{bottom:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:ns-resize}:host .ngx-ic-cropper .ngx-ic-resize-bar.ngx-ic-left{top:11px;left:-11px;height:calc(100% - 22px);width:22px;cursor:ew-resize}:host .ngx-ic-cropper.ngx-ic-round{outline-color:transparent}:host .ngx-ic-cropper.ngx-ic-round:after{border-radius:100%;box-shadow:0 0 0 100vw #ffffff4d;box-shadow:0 0 0 100vw var(--cropper-outline-color, rgba(255, 255, 255, .3))}@media (orientation: portrait){:host .ngx-ic-cropper.ngx-ic-round:after{box-shadow:0 0 0 100vh #ffffff4d;box-shadow:0 0 0 100vh var(--cropper-outline-color, rgba(255, 255, 255, .3))}}:host .ngx-ic-cropper.ngx-ic-round .ngx-ic-move{border-radius:100%}:host.disabled .ngx-ic-cropper .ngx-ic-resize,:host.disabled .ngx-ic-cropper .ngx-ic-resize-bar,:host.disabled .ngx-ic-cropper .ngx-ic-move{display:none}\n"] }]
1181
+ }], ctorParameters: function () { return [{ type: CropService }, { type: CropperPositionService }, { type: LoadImageService }, { type: i4.DomSanitizer }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { wrapper: [{
1182
+ type: ViewChild,
1183
+ args: ['wrapper', { static: true }]
1184
+ }], sourceImage: [{
1185
+ type: ViewChild,
1186
+ args: ['sourceImage', { static: false }]
1187
+ }], imageChangedEvent: [{
1188
+ type: Input
1189
+ }], imageURL: [{
1190
+ type: Input
1191
+ }], imageBase64: [{
1192
+ type: Input
1193
+ }], imageFile: [{
1194
+ type: Input
1195
+ }], format: [{
1196
+ type: Input
1197
+ }], transform: [{
1198
+ type: Input
1199
+ }], maintainAspectRatio: [{
1200
+ type: Input
1201
+ }], aspectRatio: [{
1202
+ type: Input
1203
+ }], resizeToWidth: [{
1204
+ type: Input
1205
+ }], resizeToHeight: [{
1206
+ type: Input
1207
+ }], cropperMinWidth: [{
1208
+ type: Input
1209
+ }], cropperMinHeight: [{
1210
+ type: Input
1211
+ }], cropperMaxHeight: [{
1212
+ type: Input
1213
+ }], cropperMaxWidth: [{
1214
+ type: Input
1215
+ }], cropperStaticWidth: [{
1216
+ type: Input
1217
+ }], cropperStaticHeight: [{
1218
+ type: Input
1219
+ }], canvasRotation: [{
1220
+ type: Input
1221
+ }], initialStepSize: [{
1222
+ type: Input
1223
+ }], roundCropper: [{
1224
+ type: Input
1225
+ }], onlyScaleDown: [{
1226
+ type: Input
1227
+ }], imageQuality: [{
1228
+ type: Input
1229
+ }], autoCrop: [{
1230
+ type: Input
1231
+ }], backgroundColor: [{
1232
+ type: Input
1233
+ }], containWithinAspectRatio: [{
1234
+ type: Input
1235
+ }], hideResizeSquares: [{
1236
+ type: Input
1237
+ }], cropper: [{
1238
+ type: Input
1239
+ }], alignImage: [{
1240
+ type: HostBinding,
1241
+ args: ['style.text-align']
1242
+ }, {
1243
+ type: Input
1244
+ }], disabled: [{
1245
+ type: HostBinding,
1246
+ args: ['class.disabled']
1247
+ }, {
1248
+ type: Input
1249
+ }], imageCropped: [{
1250
+ type: Output
1251
+ }], startCropImage: [{
1252
+ type: Output
1253
+ }], imageLoaded: [{
1254
+ type: Output
1255
+ }], cropperReady: [{
1256
+ type: Output
1257
+ }], loadImageFailed: [{
1258
+ type: Output
1259
+ }], onResize: [{
1260
+ type: HostListener,
1261
+ args: ['window:resize']
1262
+ }], moveImg: [{
1263
+ type: HostListener,
1264
+ args: ['document:mousemove', ['$event']]
1265
+ }, {
1266
+ type: HostListener,
1267
+ args: ['document:touchmove', ['$event']]
1268
+ }], moveStop: [{
1269
+ type: HostListener,
1270
+ args: ['document:mouseup']
1271
+ }, {
1272
+ type: HostListener,
1273
+ args: ['document:touchend']
1274
+ }] } });
1275
+
1276
+ class ImageCropperModule {
1277
+ }
1278
+ ImageCropperModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ImageCropperModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1279
+ ImageCropperModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ImageCropperModule, declarations: [ImageCropperComponent], imports: [CommonModule], exports: [ImageCropperComponent] });
1280
+ ImageCropperModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ImageCropperModule, imports: [[
1281
+ CommonModule
1282
+ ]] });
1283
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ImageCropperModule, decorators: [{
1284
+ type: NgModule,
1285
+ args: [{
1286
+ imports: [
1287
+ CommonModule
1288
+ ],
1289
+ declarations: [
1290
+ ImageCropperComponent
1291
+ ],
1292
+ exports: [
1293
+ ImageCropperComponent
1294
+ ]
1295
+ }]
1296
+ }] });
1297
+
1298
+ function base64ToFile(base64Image) {
1299
+ const split = base64Image.split(',');
1300
+ const type = split[0].replace('data:', '').replace(';base64', '');
1301
+ const byteString = atob(split[1]);
1302
+ const ab = new ArrayBuffer(byteString.length);
1303
+ const ia = new Uint8Array(ab);
1304
+ for (let i = 0; i < byteString.length; i += 1) {
1305
+ ia[i] = byteString.charCodeAt(i);
1306
+ }
1307
+ return new Blob([ab], { type });
1308
+ }
1309
+
1310
+ /**
1311
+ * Generated bundle index. Do not edit.
1312
+ */
1313
+
1314
+ export { ImageCropperComponent, ImageCropperModule, base64ToFile, resizeCanvas };
1315
+ //# sourceMappingURL=ngx-image-cropper.mjs.map