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