ngx-image-cropper 4.0.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +50 -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} +547 -1324
- package/fesm2015/ngx-image-cropper.mjs.map +1 -0
- package/fesm2020/ngx-image-cropper.mjs +1315 -0
- package/fesm2020/ngx-image-cropper.mjs.map +1 -0
- package/lib/component/image-cropper.component.d.ts +15 -12
- package/lib/image-cropper.module.d.ts +6 -0
- package/lib/interfaces/cropper.settings.d.ts +1 -1
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/services/crop.service.d.ts +4 -1
- 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 +25 -15
- package/bundles/ngx-image-cropper.umd.js +0 -2614
- 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 -825
- 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 -254
- 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/esm5/lib/component/image-cropper.component.js +0 -978
- package/esm5/lib/image-cropper.module.js +0 -28
- package/esm5/lib/interfaces/cropper-options.interface.js +0 -56
- package/esm5/lib/interfaces/cropper-position.interface.js +0 -20
- package/esm5/lib/interfaces/cropper.settings.js +0 -156
- package/esm5/lib/interfaces/dimensions.interface.js +0 -16
- package/esm5/lib/interfaces/exif-transform.interface.js +0 -16
- package/esm5/lib/interfaces/image-cropped-event.interface.js +0 -24
- package/esm5/lib/interfaces/image-transform.interface.js +0 -20
- package/esm5/lib/interfaces/index.js +0 -6
- package/esm5/lib/interfaces/loaded-image.interface.js +0 -18
- package/esm5/lib/interfaces/move-start.interface.js +0 -37
- package/esm5/lib/services/crop.service.js +0 -214
- package/esm5/lib/services/cropper-position.service.js +0 -293
- package/esm5/lib/services/load-image.service.js +0 -366
- package/esm5/lib/utils/blob.utils.js +0 -26
- package/esm5/lib/utils/exif.utils.js +0 -128
- package/esm5/lib/utils/hammer.utils.js +0 -29
- package/esm5/lib/utils/keyboard.utils.js +0 -58
- package/esm5/lib/utils/resize.utils.js +0 -116
- package/esm5/ngx-image-cropper.js +0 -13
- package/esm5/public-api.js +0 -11
- package/fesm2015/ngx-image-cropper.js.map +0 -1
- package/fesm5/ngx-image-cropper.js +0 -2396
- package/fesm5/ngx-image-cropper.js.map +0 -1
- package/ngx-image-cropper.metadata.json +0 -1
|
@@ -1,126 +1,149 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, EventEmitter, isDevMode, Component, ChangeDetectionStrategy, ViewChild, Input, HostBinding, Output, HostListener, NgModule } from '@angular/core';
|
|
3
3
|
import { __awaiter } from 'tslib';
|
|
4
|
+
import * as i4 from '@angular/platform-browser';
|
|
5
|
+
import * as i5 from '@angular/common';
|
|
4
6
|
import { CommonModule } from '@angular/common';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
8
|
+
class CropperSettings {
|
|
9
|
+
constructor() {
|
|
10
|
+
// From options
|
|
11
|
+
this.format = 'png';
|
|
12
|
+
this.maintainAspectRatio = true;
|
|
13
|
+
this.transform = {};
|
|
14
|
+
this.aspectRatio = 1;
|
|
15
|
+
this.resizeToWidth = 0;
|
|
16
|
+
this.resizeToHeight = 0;
|
|
17
|
+
this.cropperMinWidth = 0;
|
|
18
|
+
this.cropperMinHeight = 0;
|
|
19
|
+
this.cropperMaxHeight = 0;
|
|
20
|
+
this.cropperMaxWidth = 0;
|
|
21
|
+
this.cropperStaticWidth = 0;
|
|
22
|
+
this.cropperStaticHeight = 0;
|
|
23
|
+
this.canvasRotation = 0;
|
|
24
|
+
this.initialStepSize = 3;
|
|
25
|
+
this.roundCropper = false;
|
|
26
|
+
this.onlyScaleDown = false;
|
|
27
|
+
this.imageQuality = 92;
|
|
28
|
+
this.autoCrop = true;
|
|
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
|
+
}
|
|
34
103
|
}
|
|
35
|
-
/** @enum {string} */
|
|
36
|
-
const MoveTypes = {
|
|
37
|
-
Move: "move",
|
|
38
|
-
Resize: "resize",
|
|
39
|
-
Pinch: "pinch",
|
|
40
|
-
};
|
|
41
104
|
|
|
42
|
-
/**
|
|
43
|
-
* @fileoverview added by tsickle
|
|
44
|
-
* Generated from: lib/utils/resize.utils.ts
|
|
45
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
46
|
-
*/
|
|
47
105
|
/*
|
|
48
106
|
* Hermite resize - fast image resize/resample using Hermite filter.
|
|
49
107
|
* https://github.com/viliusle/Hermite-resize
|
|
50
108
|
*/
|
|
51
|
-
/**
|
|
52
|
-
* @param {?} canvas
|
|
53
|
-
* @param {?} width
|
|
54
|
-
* @param {?} height
|
|
55
|
-
* @return {?}
|
|
56
|
-
*/
|
|
57
109
|
function resizeCanvas(canvas, width, height) {
|
|
58
|
-
/** @type {?} */
|
|
59
110
|
const width_source = canvas.width;
|
|
60
|
-
/** @type {?} */
|
|
61
111
|
const height_source = canvas.height;
|
|
62
112
|
width = Math.round(width);
|
|
63
113
|
height = Math.round(height);
|
|
64
|
-
/** @type {?} */
|
|
65
114
|
const ratio_w = width_source / width;
|
|
66
|
-
/** @type {?} */
|
|
67
115
|
const ratio_h = height_source / height;
|
|
68
|
-
/** @type {?} */
|
|
69
116
|
const ratio_w_half = Math.ceil(ratio_w / 2);
|
|
70
|
-
/** @type {?} */
|
|
71
117
|
const ratio_h_half = Math.ceil(ratio_h / 2);
|
|
72
|
-
/** @type {?} */
|
|
73
118
|
const ctx = canvas.getContext('2d');
|
|
74
119
|
if (ctx) {
|
|
75
|
-
/** @type {?} */
|
|
76
120
|
const img = ctx.getImageData(0, 0, width_source, height_source);
|
|
77
|
-
/** @type {?} */
|
|
78
121
|
const img2 = ctx.createImageData(width, height);
|
|
79
|
-
/** @type {?} */
|
|
80
122
|
const data = img.data;
|
|
81
|
-
/** @type {?} */
|
|
82
123
|
const data2 = img2.data;
|
|
83
124
|
for (let j = 0; j < height; j++) {
|
|
84
125
|
for (let i = 0; i < width; i++) {
|
|
85
|
-
/** @type {?} */
|
|
86
126
|
const x2 = (i + j * width) * 4;
|
|
87
|
-
/** @type {?} */
|
|
88
127
|
const center_y = j * ratio_h;
|
|
89
|
-
/** @type {?} */
|
|
90
128
|
let weight = 0;
|
|
91
|
-
/** @type {?} */
|
|
92
129
|
let weights = 0;
|
|
93
|
-
/** @type {?} */
|
|
94
130
|
let weights_alpha = 0;
|
|
95
|
-
/** @type {?} */
|
|
96
131
|
let gx_r = 0;
|
|
97
|
-
/** @type {?} */
|
|
98
132
|
let gx_g = 0;
|
|
99
|
-
/** @type {?} */
|
|
100
133
|
let gx_b = 0;
|
|
101
|
-
/** @type {?} */
|
|
102
134
|
let gx_a = 0;
|
|
103
|
-
/** @type {?} */
|
|
104
135
|
const xx_start = Math.floor(i * ratio_w);
|
|
105
|
-
/** @type {?} */
|
|
106
136
|
const yy_start = Math.floor(j * ratio_h);
|
|
107
|
-
/** @type {?} */
|
|
108
137
|
let xx_stop = Math.ceil((i + 1) * ratio_w);
|
|
109
|
-
/** @type {?} */
|
|
110
138
|
let yy_stop = Math.ceil((j + 1) * ratio_h);
|
|
111
139
|
xx_stop = Math.min(xx_stop, width_source);
|
|
112
140
|
yy_stop = Math.min(yy_stop, height_source);
|
|
113
141
|
for (let yy = yy_start; yy < yy_stop; yy++) {
|
|
114
|
-
/** @type {?} */
|
|
115
142
|
const dy = Math.abs(center_y - yy) / ratio_h_half;
|
|
116
|
-
/** @type {?} */
|
|
117
143
|
const center_x = i * ratio_w;
|
|
118
|
-
|
|
119
|
-
const w0 = dy * dy;
|
|
144
|
+
const w0 = dy * dy; //pre-calc part of w
|
|
120
145
|
for (let xx = xx_start; xx < xx_stop; xx++) {
|
|
121
|
-
/** @type {?} */
|
|
122
146
|
const dx = Math.abs(center_x - xx) / ratio_w_half;
|
|
123
|
-
/** @type {?} */
|
|
124
147
|
const w = Math.sqrt(w0 + dx * dx);
|
|
125
148
|
if (w >= 1) {
|
|
126
149
|
//pixel too far
|
|
@@ -128,7 +151,6 @@ function resizeCanvas(canvas, width, height) {
|
|
|
128
151
|
}
|
|
129
152
|
//hermite filter
|
|
130
153
|
weight = 2 * w * w * w - 3 * w * w + 1;
|
|
131
|
-
/** @type {?} */
|
|
132
154
|
const pos_x = 4 * (xx + yy * width_source);
|
|
133
155
|
//alpha
|
|
134
156
|
gx_a += weight * data[pos_x + 3];
|
|
@@ -155,50 +177,29 @@ function resizeCanvas(canvas, width, height) {
|
|
|
155
177
|
}
|
|
156
178
|
}
|
|
157
179
|
|
|
158
|
-
/**
|
|
159
|
-
* @fileoverview added by tsickle
|
|
160
|
-
* Generated from: lib/services/crop.service.ts
|
|
161
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
162
|
-
*/
|
|
163
180
|
class CropService {
|
|
164
|
-
/**
|
|
165
|
-
* @param {?} sourceImage
|
|
166
|
-
* @param {?} loadedImage
|
|
167
|
-
* @param {?} cropper
|
|
168
|
-
* @param {?} settings
|
|
169
|
-
* @return {?}
|
|
170
|
-
*/
|
|
171
181
|
crop(sourceImage, loadedImage, cropper, settings) {
|
|
172
|
-
/** @type {?} */
|
|
173
182
|
const imagePosition = this.getImagePosition(sourceImage, loadedImage, cropper, settings);
|
|
174
|
-
/** @type {?} */
|
|
175
183
|
const width = imagePosition.x2 - imagePosition.x1;
|
|
176
|
-
/** @type {?} */
|
|
177
184
|
const height = imagePosition.y2 - imagePosition.y1;
|
|
178
|
-
|
|
179
|
-
const cropCanvas = (/** @type {?} */ (document.createElement('canvas')));
|
|
185
|
+
const cropCanvas = document.createElement('canvas');
|
|
180
186
|
cropCanvas.width = width;
|
|
181
187
|
cropCanvas.height = height;
|
|
182
|
-
/** @type {?} */
|
|
183
188
|
const ctx = cropCanvas.getContext('2d');
|
|
184
189
|
if (!ctx) {
|
|
185
|
-
return;
|
|
190
|
+
return null;
|
|
186
191
|
}
|
|
187
192
|
if (settings.backgroundColor != null) {
|
|
188
193
|
ctx.fillStyle = settings.backgroundColor;
|
|
189
194
|
ctx.fillRect(0, 0, width, height);
|
|
190
195
|
}
|
|
191
|
-
/** @type {?} */
|
|
192
196
|
const scaleX = (settings.transform.scale || 1) * (settings.transform.flipH ? -1 : 1);
|
|
193
|
-
/** @type {?} */
|
|
194
197
|
const scaleY = (settings.transform.scale || 1) * (settings.transform.flipV ? -1 : 1);
|
|
195
|
-
/** @type {?} */
|
|
196
198
|
const transformedImage = loadedImage.transformed;
|
|
197
199
|
ctx.setTransform(scaleX, 0, 0, scaleY, transformedImage.size.width / 2, transformedImage.size.height / 2);
|
|
198
200
|
ctx.translate(-imagePosition.x1 / scaleX, -imagePosition.y1 / scaleY);
|
|
199
201
|
ctx.rotate((settings.transform.rotate || 0) * Math.PI / 180);
|
|
200
202
|
ctx.drawImage(transformedImage.image, -transformedImage.size.width / 2, -transformedImage.size.height / 2);
|
|
201
|
-
/** @type {?} */
|
|
202
203
|
const output = {
|
|
203
204
|
width, height,
|
|
204
205
|
imagePosition,
|
|
@@ -207,7 +208,6 @@ class CropService {
|
|
|
207
208
|
if (settings.containWithinAspectRatio) {
|
|
208
209
|
output.offsetImagePosition = this.getOffsetImagePosition(sourceImage, loadedImage, cropper, settings);
|
|
209
210
|
}
|
|
210
|
-
/** @type {?} */
|
|
211
211
|
const resizeRatio = this.getResizeRatio(width, height, settings);
|
|
212
212
|
if (resizeRatio !== 1) {
|
|
213
213
|
output.width = Math.round(width * resizeRatio);
|
|
@@ -219,20 +219,9 @@ class CropService {
|
|
|
219
219
|
output.base64 = cropCanvas.toDataURL('image/' + settings.format, this.getQuality(settings));
|
|
220
220
|
return output;
|
|
221
221
|
}
|
|
222
|
-
/**
|
|
223
|
-
* @private
|
|
224
|
-
* @param {?} sourceImage
|
|
225
|
-
* @param {?} loadedImage
|
|
226
|
-
* @param {?} cropper
|
|
227
|
-
* @param {?} settings
|
|
228
|
-
* @return {?}
|
|
229
|
-
*/
|
|
230
222
|
getImagePosition(sourceImage, loadedImage, cropper, settings) {
|
|
231
|
-
/** @type {?} */
|
|
232
223
|
const sourceImageElement = sourceImage.nativeElement;
|
|
233
|
-
/** @type {?} */
|
|
234
224
|
const ratio = loadedImage.transformed.size.width / sourceImageElement.offsetWidth;
|
|
235
|
-
/** @type {?} */
|
|
236
225
|
const out = {
|
|
237
226
|
x1: Math.round(cropper.x1 * ratio),
|
|
238
227
|
y1: Math.round(cropper.y1 * ratio),
|
|
@@ -247,24 +236,11 @@ class CropService {
|
|
|
247
236
|
}
|
|
248
237
|
return out;
|
|
249
238
|
}
|
|
250
|
-
/**
|
|
251
|
-
* @private
|
|
252
|
-
* @param {?} sourceImage
|
|
253
|
-
* @param {?} loadedImage
|
|
254
|
-
* @param {?} cropper
|
|
255
|
-
* @param {?} settings
|
|
256
|
-
* @return {?}
|
|
257
|
-
*/
|
|
258
239
|
getOffsetImagePosition(sourceImage, loadedImage, cropper, settings) {
|
|
259
|
-
/** @type {?} */
|
|
260
240
|
const canvasRotation = settings.canvasRotation + loadedImage.exifTransform.rotate;
|
|
261
|
-
/** @type {?} */
|
|
262
241
|
const sourceImageElement = sourceImage.nativeElement;
|
|
263
|
-
/** @type {?} */
|
|
264
242
|
const ratio = loadedImage.transformed.size.width / sourceImageElement.offsetWidth;
|
|
265
|
-
/** @type {?} */
|
|
266
243
|
let offsetX;
|
|
267
|
-
/** @type {?} */
|
|
268
244
|
let offsetY;
|
|
269
245
|
if (canvasRotation % 2) {
|
|
270
246
|
offsetX = (loadedImage.transformed.size.width - loadedImage.original.size.height) / 2;
|
|
@@ -274,7 +250,6 @@ class CropService {
|
|
|
274
250
|
offsetX = (loadedImage.transformed.size.width - loadedImage.original.size.width) / 2;
|
|
275
251
|
offsetY = (loadedImage.transformed.size.height - loadedImage.original.size.height) / 2;
|
|
276
252
|
}
|
|
277
|
-
/** @type {?} */
|
|
278
253
|
const out = {
|
|
279
254
|
x1: Math.round(cropper.x1 * ratio) - offsetX,
|
|
280
255
|
y1: Math.round(cropper.y1 * ratio) - offsetY,
|
|
@@ -289,18 +264,9 @@ class CropService {
|
|
|
289
264
|
}
|
|
290
265
|
return out;
|
|
291
266
|
}
|
|
292
|
-
/**
|
|
293
|
-
* @param {?} width
|
|
294
|
-
* @param {?} height
|
|
295
|
-
* @param {?} settings
|
|
296
|
-
* @return {?}
|
|
297
|
-
*/
|
|
298
267
|
getResizeRatio(width, height, settings) {
|
|
299
|
-
/** @type {?} */
|
|
300
268
|
const ratioWidth = settings.resizeToWidth / width;
|
|
301
|
-
/** @type {?} */
|
|
302
269
|
const ratioHeight = settings.resizeToHeight / height;
|
|
303
|
-
/** @type {?} */
|
|
304
270
|
const ratios = new Array();
|
|
305
271
|
if (settings.resizeToWidth > 0) {
|
|
306
272
|
ratios.push(ratioWidth);
|
|
@@ -308,608 +274,28 @@ class CropService {
|
|
|
308
274
|
if (settings.resizeToHeight > 0) {
|
|
309
275
|
ratios.push(ratioHeight);
|
|
310
276
|
}
|
|
311
|
-
/** @type {?} */
|
|
312
277
|
const result = ratios.length === 0 ? 1 : Math.min(...ratios);
|
|
313
278
|
if (result > 1 && !settings.onlyScaleDown) {
|
|
314
279
|
return result;
|
|
315
280
|
}
|
|
316
281
|
return Math.min(result, 1);
|
|
317
282
|
}
|
|
318
|
-
/**
|
|
319
|
-
* @param {?} settings
|
|
320
|
-
* @return {?}
|
|
321
|
-
*/
|
|
322
283
|
getQuality(settings) {
|
|
323
284
|
return Math.min(1, Math.max(0, settings.imageQuality / 100));
|
|
324
285
|
}
|
|
325
286
|
}
|
|
326
|
-
CropService
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
* @fileoverview added by tsickle
|
|
333
|
-
* Generated from: lib/interfaces/cropper.settings.ts
|
|
334
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
335
|
-
*/
|
|
336
|
-
class CropperSettings {
|
|
337
|
-
constructor() {
|
|
338
|
-
// From options
|
|
339
|
-
this.format = 'png';
|
|
340
|
-
this.maintainAspectRatio = true;
|
|
341
|
-
this.transform = {};
|
|
342
|
-
this.aspectRatio = 1;
|
|
343
|
-
this.resizeToWidth = 0;
|
|
344
|
-
this.resizeToHeight = 0;
|
|
345
|
-
this.cropperMinWidth = 0;
|
|
346
|
-
this.cropperMinHeight = 0;
|
|
347
|
-
this.cropperMaxHeight = 0;
|
|
348
|
-
this.cropperMaxWidth = 0;
|
|
349
|
-
this.cropperStaticWidth = 0;
|
|
350
|
-
this.cropperStaticHeight = 0;
|
|
351
|
-
this.canvasRotation = 0;
|
|
352
|
-
this.initialStepSize = 3;
|
|
353
|
-
this.roundCropper = false;
|
|
354
|
-
this.onlyScaleDown = false;
|
|
355
|
-
this.imageQuality = 92;
|
|
356
|
-
this.autoCrop = true;
|
|
357
|
-
this.backgroundColor = undefined;
|
|
358
|
-
this.containWithinAspectRatio = false;
|
|
359
|
-
this.hideResizeSquares = false;
|
|
360
|
-
this.alignImage = 'center';
|
|
361
|
-
// Internal
|
|
362
|
-
this.cropperScaledMinWidth = 20;
|
|
363
|
-
this.cropperScaledMinHeight = 20;
|
|
364
|
-
this.cropperScaledMaxWidth = 20;
|
|
365
|
-
this.cropperScaledMaxHeight = 20;
|
|
366
|
-
this.stepSize = this.initialStepSize;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* @param {?} options
|
|
370
|
-
* @return {?}
|
|
371
|
-
*/
|
|
372
|
-
setOptions(options) {
|
|
373
|
-
Object.keys(options)
|
|
374
|
-
.filter((/**
|
|
375
|
-
* @param {?} k
|
|
376
|
-
* @return {?}
|
|
377
|
-
*/
|
|
378
|
-
(k) => k in this))
|
|
379
|
-
.forEach((/**
|
|
380
|
-
* @param {?} k
|
|
381
|
-
* @return {?}
|
|
382
|
-
*/
|
|
383
|
-
(k) => this[k] = options[k]));
|
|
384
|
-
this.validateOptions();
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* @param {?} changes
|
|
388
|
-
* @return {?}
|
|
389
|
-
*/
|
|
390
|
-
setOptionsFromChanges(changes) {
|
|
391
|
-
Object.keys(changes)
|
|
392
|
-
.filter((/**
|
|
393
|
-
* @param {?} k
|
|
394
|
-
* @return {?}
|
|
395
|
-
*/
|
|
396
|
-
(k) => k in this))
|
|
397
|
-
.forEach((/**
|
|
398
|
-
* @param {?} k
|
|
399
|
-
* @return {?}
|
|
400
|
-
*/
|
|
401
|
-
(k) => this[k] = changes[k].currentValue));
|
|
402
|
-
this.validateOptions();
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* @private
|
|
406
|
-
* @return {?}
|
|
407
|
-
*/
|
|
408
|
-
validateOptions() {
|
|
409
|
-
if (this.maintainAspectRatio && !this.aspectRatio) {
|
|
410
|
-
throw new Error('`aspectRatio` should > 0 when `maintainAspectRatio` is enabled');
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
if (false) {
|
|
415
|
-
/** @type {?} */
|
|
416
|
-
CropperSettings.prototype.format;
|
|
417
|
-
/** @type {?} */
|
|
418
|
-
CropperSettings.prototype.maintainAspectRatio;
|
|
419
|
-
/** @type {?} */
|
|
420
|
-
CropperSettings.prototype.transform;
|
|
421
|
-
/** @type {?} */
|
|
422
|
-
CropperSettings.prototype.aspectRatio;
|
|
423
|
-
/** @type {?} */
|
|
424
|
-
CropperSettings.prototype.resizeToWidth;
|
|
425
|
-
/** @type {?} */
|
|
426
|
-
CropperSettings.prototype.resizeToHeight;
|
|
427
|
-
/** @type {?} */
|
|
428
|
-
CropperSettings.prototype.cropperMinWidth;
|
|
429
|
-
/** @type {?} */
|
|
430
|
-
CropperSettings.prototype.cropperMinHeight;
|
|
431
|
-
/** @type {?} */
|
|
432
|
-
CropperSettings.prototype.cropperMaxHeight;
|
|
433
|
-
/** @type {?} */
|
|
434
|
-
CropperSettings.prototype.cropperMaxWidth;
|
|
435
|
-
/** @type {?} */
|
|
436
|
-
CropperSettings.prototype.cropperStaticWidth;
|
|
437
|
-
/** @type {?} */
|
|
438
|
-
CropperSettings.prototype.cropperStaticHeight;
|
|
439
|
-
/** @type {?} */
|
|
440
|
-
CropperSettings.prototype.canvasRotation;
|
|
441
|
-
/** @type {?} */
|
|
442
|
-
CropperSettings.prototype.initialStepSize;
|
|
443
|
-
/** @type {?} */
|
|
444
|
-
CropperSettings.prototype.roundCropper;
|
|
445
|
-
/** @type {?} */
|
|
446
|
-
CropperSettings.prototype.onlyScaleDown;
|
|
447
|
-
/** @type {?} */
|
|
448
|
-
CropperSettings.prototype.imageQuality;
|
|
449
|
-
/** @type {?} */
|
|
450
|
-
CropperSettings.prototype.autoCrop;
|
|
451
|
-
/** @type {?} */
|
|
452
|
-
CropperSettings.prototype.backgroundColor;
|
|
453
|
-
/** @type {?} */
|
|
454
|
-
CropperSettings.prototype.containWithinAspectRatio;
|
|
455
|
-
/** @type {?} */
|
|
456
|
-
CropperSettings.prototype.hideResizeSquares;
|
|
457
|
-
/** @type {?} */
|
|
458
|
-
CropperSettings.prototype.alignImage;
|
|
459
|
-
/** @type {?} */
|
|
460
|
-
CropperSettings.prototype.cropperScaledMinWidth;
|
|
461
|
-
/** @type {?} */
|
|
462
|
-
CropperSettings.prototype.cropperScaledMinHeight;
|
|
463
|
-
/** @type {?} */
|
|
464
|
-
CropperSettings.prototype.cropperScaledMaxWidth;
|
|
465
|
-
/** @type {?} */
|
|
466
|
-
CropperSettings.prototype.cropperScaledMaxHeight;
|
|
467
|
-
/** @type {?} */
|
|
468
|
-
CropperSettings.prototype.stepSize;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* @fileoverview added by tsickle
|
|
473
|
-
* Generated from: lib/utils/exif.utils.ts
|
|
474
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
475
|
-
*/
|
|
476
|
-
// Black 2x1 JPEG, with the following meta information set:
|
|
477
|
-
// - EXIF Orientation: 6 (Rotated 90° CCW)
|
|
478
|
-
// Source: https://github.com/blueimp/JavaScript-Load-Image
|
|
479
|
-
/** @type {?} */
|
|
480
|
-
const testAutoOrientationImageURL = 'data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAA' +
|
|
481
|
-
'AAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA' +
|
|
482
|
-
'QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE' +
|
|
483
|
-
'BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/x' +
|
|
484
|
-
'ABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAA' +
|
|
485
|
-
'AAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==';
|
|
486
|
-
/**
|
|
487
|
-
* @return {?}
|
|
488
|
-
*/
|
|
489
|
-
function supportsAutomaticRotation() {
|
|
490
|
-
return new Promise((/**
|
|
491
|
-
* @param {?} resolve
|
|
492
|
-
* @return {?}
|
|
493
|
-
*/
|
|
494
|
-
(resolve) => {
|
|
495
|
-
/** @type {?} */
|
|
496
|
-
const img = new Image();
|
|
497
|
-
img.onload = (/**
|
|
498
|
-
* @return {?}
|
|
499
|
-
*/
|
|
500
|
-
() => {
|
|
501
|
-
// Check if browser supports automatic image orientation:
|
|
502
|
-
/** @type {?} */
|
|
503
|
-
const supported = img.width === 1 && img.height === 2;
|
|
504
|
-
resolve(supported);
|
|
505
|
-
});
|
|
506
|
-
img.src = testAutoOrientationImageURL;
|
|
507
|
-
}));
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* @param {?} exifRotationOrBase64Image
|
|
511
|
-
* @return {?}
|
|
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
|
-
/**
|
|
537
|
-
* @param {?} imageBase64
|
|
538
|
-
* @return {?}
|
|
539
|
-
*/
|
|
540
|
-
function getExifRotation(imageBase64) {
|
|
541
|
-
/** @type {?} */
|
|
542
|
-
const view = new DataView(base64ToArrayBuffer(imageBase64));
|
|
543
|
-
if (view.getUint16(0, false) != 0xFFD8) {
|
|
544
|
-
return -2;
|
|
545
|
-
}
|
|
546
|
-
/** @type {?} */
|
|
547
|
-
const length = view.byteLength;
|
|
548
|
-
/** @type {?} */
|
|
549
|
-
let offset = 2;
|
|
550
|
-
while (offset < length) {
|
|
551
|
-
if (view.getUint16(offset + 2, false) <= 8)
|
|
552
|
-
return -1;
|
|
553
|
-
/** @type {?} */
|
|
554
|
-
const marker = view.getUint16(offset, false);
|
|
555
|
-
offset += 2;
|
|
556
|
-
if (marker == 0xFFE1) {
|
|
557
|
-
if (view.getUint32(offset += 2, false) != 0x45786966) {
|
|
558
|
-
return -1;
|
|
559
|
-
}
|
|
560
|
-
/** @type {?} */
|
|
561
|
-
const little = view.getUint16(offset += 6, false) == 0x4949;
|
|
562
|
-
offset += view.getUint32(offset + 4, little);
|
|
563
|
-
/** @type {?} */
|
|
564
|
-
const tags = view.getUint16(offset, little);
|
|
565
|
-
offset += 2;
|
|
566
|
-
for (let i = 0; i < tags; i++) {
|
|
567
|
-
if (view.getUint16(offset + (i * 12), little) == 0x0112) {
|
|
568
|
-
return view.getUint16(offset + (i * 12) + 8, little);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
else if ((marker & 0xFF00) != 0xFF00) {
|
|
573
|
-
break;
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
offset += view.getUint16(offset, false);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
return -1;
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* @param {?} imageBase64
|
|
583
|
-
* @return {?}
|
|
584
|
-
*/
|
|
585
|
-
function base64ToArrayBuffer(imageBase64) {
|
|
586
|
-
imageBase64 = imageBase64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
|
|
587
|
-
/** @type {?} */
|
|
588
|
-
const binaryString = atob(imageBase64);
|
|
589
|
-
/** @type {?} */
|
|
590
|
-
const len = binaryString.length;
|
|
591
|
-
/** @type {?} */
|
|
592
|
-
const bytes = new Uint8Array(len);
|
|
593
|
-
for (let i = 0; i < len; i++) {
|
|
594
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
595
|
-
}
|
|
596
|
-
return bytes.buffer;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
* @fileoverview added by tsickle
|
|
601
|
-
* Generated from: lib/services/load-image.service.ts
|
|
602
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
603
|
-
*/
|
|
604
|
-
/**
|
|
605
|
-
* @record
|
|
606
|
-
*/
|
|
607
|
-
function LoadImageBase64() { }
|
|
608
|
-
if (false) {
|
|
609
|
-
/** @type {?} */
|
|
610
|
-
LoadImageBase64.prototype.originalImage;
|
|
611
|
-
/** @type {?} */
|
|
612
|
-
LoadImageBase64.prototype.originalBase64;
|
|
613
|
-
}
|
|
614
|
-
class LoadImageService {
|
|
615
|
-
constructor() {
|
|
616
|
-
this.autoRotateSupported = supportsAutomaticRotation();
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* @param {?} file
|
|
620
|
-
* @param {?} cropperSettings
|
|
621
|
-
* @return {?}
|
|
622
|
-
*/
|
|
623
|
-
loadImageFile(file, cropperSettings) {
|
|
624
|
-
return new Promise((/**
|
|
625
|
-
* @param {?} resolve
|
|
626
|
-
* @param {?} reject
|
|
627
|
-
* @return {?}
|
|
628
|
-
*/
|
|
629
|
-
(resolve, reject) => {
|
|
630
|
-
/** @type {?} */
|
|
631
|
-
const fileReader = new FileReader();
|
|
632
|
-
fileReader.onload = (/**
|
|
633
|
-
* @param {?} event
|
|
634
|
-
* @return {?}
|
|
635
|
-
*/
|
|
636
|
-
(event) => {
|
|
637
|
-
this.loadImage(event.target.result, file.type, cropperSettings)
|
|
638
|
-
.then(resolve)
|
|
639
|
-
.catch(reject);
|
|
640
|
-
});
|
|
641
|
-
fileReader.readAsDataURL(file);
|
|
642
|
-
}));
|
|
643
|
-
}
|
|
644
|
-
/**
|
|
645
|
-
* @private
|
|
646
|
-
* @param {?} imageBase64
|
|
647
|
-
* @param {?} imageType
|
|
648
|
-
* @param {?} cropperSettings
|
|
649
|
-
* @return {?}
|
|
650
|
-
*/
|
|
651
|
-
loadImage(imageBase64, imageType, cropperSettings) {
|
|
652
|
-
if (!this.isValidImageType(imageType)) {
|
|
653
|
-
return Promise.reject(new Error('Invalid image type'));
|
|
654
|
-
}
|
|
655
|
-
return this.loadBase64Image(imageBase64, cropperSettings);
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* @private
|
|
659
|
-
* @param {?} type
|
|
660
|
-
* @return {?}
|
|
661
|
-
*/
|
|
662
|
-
isValidImageType(type) {
|
|
663
|
-
return /image\/(png|jpg|jpeg|bmp|gif|tiff|webp)/.test(type);
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* @param {?} url
|
|
667
|
-
* @param {?} cropperSettings
|
|
668
|
-
* @return {?}
|
|
669
|
-
*/
|
|
670
|
-
loadImageFromURL(url, cropperSettings) {
|
|
671
|
-
return new Promise((/**
|
|
672
|
-
* @param {?} resolve
|
|
673
|
-
* @param {?} reject
|
|
674
|
-
* @return {?}
|
|
675
|
-
*/
|
|
676
|
-
(resolve, reject) => {
|
|
677
|
-
/** @type {?} */
|
|
678
|
-
const img = new Image();
|
|
679
|
-
img.onerror = (/**
|
|
680
|
-
* @return {?}
|
|
681
|
-
*/
|
|
682
|
-
() => reject);
|
|
683
|
-
img.onload = (/**
|
|
684
|
-
* @return {?}
|
|
685
|
-
*/
|
|
686
|
-
() => {
|
|
687
|
-
/** @type {?} */
|
|
688
|
-
const canvas = document.createElement('canvas');
|
|
689
|
-
/** @type {?} */
|
|
690
|
-
const context = canvas.getContext('2d');
|
|
691
|
-
canvas.width = img.width;
|
|
692
|
-
canvas.height = img.height;
|
|
693
|
-
context.drawImage(img, 0, 0);
|
|
694
|
-
this.loadBase64Image(canvas.toDataURL(), cropperSettings).then(resolve);
|
|
695
|
-
});
|
|
696
|
-
img.crossOrigin = 'anonymous';
|
|
697
|
-
img.src = url;
|
|
698
|
-
}));
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* @param {?} imageBase64
|
|
702
|
-
* @param {?} cropperSettings
|
|
703
|
-
* @return {?}
|
|
704
|
-
*/
|
|
705
|
-
loadBase64Image(imageBase64, cropperSettings) {
|
|
706
|
-
return new Promise((/**
|
|
707
|
-
* @param {?} resolve
|
|
708
|
-
* @param {?} reject
|
|
709
|
-
* @return {?}
|
|
710
|
-
*/
|
|
711
|
-
(resolve, reject) => {
|
|
712
|
-
/** @type {?} */
|
|
713
|
-
const originalImage = new Image();
|
|
714
|
-
originalImage.onload = (/**
|
|
715
|
-
* @return {?}
|
|
716
|
-
*/
|
|
717
|
-
() => resolve({
|
|
718
|
-
originalImage,
|
|
719
|
-
originalBase64: imageBase64
|
|
720
|
-
}));
|
|
721
|
-
originalImage.onerror = reject;
|
|
722
|
-
originalImage.src = imageBase64;
|
|
723
|
-
})).then((/**
|
|
724
|
-
* @param {?} res
|
|
725
|
-
* @return {?}
|
|
726
|
-
*/
|
|
727
|
-
(res) => this.transformImageBase64(res, cropperSettings)));
|
|
728
|
-
}
|
|
729
|
-
/**
|
|
730
|
-
* @private
|
|
731
|
-
* @param {?} res
|
|
732
|
-
* @param {?} cropperSettings
|
|
733
|
-
* @return {?}
|
|
734
|
-
*/
|
|
735
|
-
transformImageBase64(res, cropperSettings) {
|
|
736
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
737
|
-
/** @type {?} */
|
|
738
|
-
const autoRotate = yield this.autoRotateSupported;
|
|
739
|
-
/** @type {?} */
|
|
740
|
-
const exifTransform = yield getTransformationsFromExifData(autoRotate ? -1 : res.originalBase64);
|
|
741
|
-
if (!res.originalImage || !res.originalImage.complete) {
|
|
742
|
-
return Promise.reject(new Error('No image loaded'));
|
|
743
|
-
}
|
|
744
|
-
/** @type {?} */
|
|
745
|
-
const loadedImage = {
|
|
746
|
-
original: {
|
|
747
|
-
base64: res.originalBase64,
|
|
748
|
-
image: res.originalImage,
|
|
749
|
-
size: {
|
|
750
|
-
width: res.originalImage.naturalWidth,
|
|
751
|
-
height: res.originalImage.naturalHeight
|
|
752
|
-
}
|
|
753
|
-
},
|
|
754
|
-
exifTransform
|
|
755
|
-
};
|
|
756
|
-
return this.transformLoadedImage(loadedImage, cropperSettings);
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
* @param {?} loadedImage
|
|
761
|
-
* @param {?} cropperSettings
|
|
762
|
-
* @return {?}
|
|
763
|
-
*/
|
|
764
|
-
transformLoadedImage(loadedImage, cropperSettings) {
|
|
765
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
766
|
-
/** @type {?} */
|
|
767
|
-
const canvasRotation = cropperSettings.canvasRotation + loadedImage.exifTransform.rotate;
|
|
768
|
-
/** @type {?} */
|
|
769
|
-
const originalSize = {
|
|
770
|
-
width: loadedImage.original.image.naturalWidth,
|
|
771
|
-
height: loadedImage.original.image.naturalHeight
|
|
772
|
-
};
|
|
773
|
-
if (canvasRotation === 0 && !loadedImage.exifTransform.flip && !cropperSettings.containWithinAspectRatio) {
|
|
774
|
-
return {
|
|
775
|
-
original: {
|
|
776
|
-
base64: loadedImage.original.base64,
|
|
777
|
-
image: loadedImage.original.image,
|
|
778
|
-
size: Object.assign({}, originalSize)
|
|
779
|
-
},
|
|
780
|
-
transformed: {
|
|
781
|
-
base64: loadedImage.original.base64,
|
|
782
|
-
image: loadedImage.original.image,
|
|
783
|
-
size: Object.assign({}, originalSize)
|
|
784
|
-
},
|
|
785
|
-
exifTransform: loadedImage.exifTransform
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
/** @type {?} */
|
|
789
|
-
const transformedSize = this.getTransformedSize(originalSize, loadedImage.exifTransform, cropperSettings);
|
|
790
|
-
/** @type {?} */
|
|
791
|
-
const canvas = document.createElement('canvas');
|
|
792
|
-
canvas.width = transformedSize.width;
|
|
793
|
-
canvas.height = transformedSize.height;
|
|
794
|
-
/** @type {?} */
|
|
795
|
-
const ctx = canvas.getContext('2d');
|
|
796
|
-
ctx.setTransform(loadedImage.exifTransform.flip ? -1 : 1, 0, 0, 1, canvas.width / 2, canvas.height / 2);
|
|
797
|
-
ctx.rotate(Math.PI * (canvasRotation / 2));
|
|
798
|
-
ctx.drawImage(loadedImage.original.image, -originalSize.width / 2, -originalSize.height / 2);
|
|
799
|
-
/** @type {?} */
|
|
800
|
-
const transformedBase64 = canvas.toDataURL();
|
|
801
|
-
/** @type {?} */
|
|
802
|
-
const transformedImage = yield this.loadImageFromBase64(transformedBase64);
|
|
803
|
-
return {
|
|
804
|
-
original: {
|
|
805
|
-
base64: loadedImage.original.base64,
|
|
806
|
-
image: loadedImage.original.image,
|
|
807
|
-
size: Object.assign({}, originalSize)
|
|
808
|
-
},
|
|
809
|
-
transformed: {
|
|
810
|
-
base64: transformedBase64,
|
|
811
|
-
image: transformedImage,
|
|
812
|
-
size: {
|
|
813
|
-
width: transformedImage.width,
|
|
814
|
-
height: transformedImage.height
|
|
815
|
-
}
|
|
816
|
-
},
|
|
817
|
-
exifTransform: loadedImage.exifTransform
|
|
818
|
-
};
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* @private
|
|
823
|
-
* @param {?} imageBase64
|
|
824
|
-
* @return {?}
|
|
825
|
-
*/
|
|
826
|
-
loadImageFromBase64(imageBase64) {
|
|
827
|
-
return new Promise(((/**
|
|
828
|
-
* @param {?} resolve
|
|
829
|
-
* @param {?} reject
|
|
830
|
-
* @return {?}
|
|
831
|
-
*/
|
|
832
|
-
(resolve, reject) => {
|
|
833
|
-
/** @type {?} */
|
|
834
|
-
const image = new Image();
|
|
835
|
-
image.onload = (/**
|
|
836
|
-
* @return {?}
|
|
837
|
-
*/
|
|
838
|
-
() => resolve(image));
|
|
839
|
-
image.onerror = reject;
|
|
840
|
-
image.src = imageBase64;
|
|
841
|
-
})));
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* @private
|
|
845
|
-
* @param {?} originalSize
|
|
846
|
-
* @param {?} exifTransform
|
|
847
|
-
* @param {?} cropperSettings
|
|
848
|
-
* @return {?}
|
|
849
|
-
*/
|
|
850
|
-
getTransformedSize(originalSize, exifTransform, cropperSettings) {
|
|
851
|
-
/** @type {?} */
|
|
852
|
-
const canvasRotation = cropperSettings.canvasRotation + exifTransform.rotate;
|
|
853
|
-
if (cropperSettings.containWithinAspectRatio) {
|
|
854
|
-
if (canvasRotation % 2) {
|
|
855
|
-
/** @type {?} */
|
|
856
|
-
const minWidthToContain = originalSize.width * cropperSettings.aspectRatio;
|
|
857
|
-
/** @type {?} */
|
|
858
|
-
const minHeightToContain = originalSize.height / cropperSettings.aspectRatio;
|
|
859
|
-
return {
|
|
860
|
-
width: Math.max(originalSize.height, minWidthToContain),
|
|
861
|
-
height: Math.max(originalSize.width, minHeightToContain)
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
else {
|
|
865
|
-
/** @type {?} */
|
|
866
|
-
const minWidthToContain = originalSize.height * cropperSettings.aspectRatio;
|
|
867
|
-
/** @type {?} */
|
|
868
|
-
const minHeightToContain = originalSize.width / cropperSettings.aspectRatio;
|
|
869
|
-
return {
|
|
870
|
-
width: Math.max(originalSize.width, minWidthToContain),
|
|
871
|
-
height: Math.max(originalSize.height, minHeightToContain)
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
if (canvasRotation % 2) {
|
|
876
|
-
return {
|
|
877
|
-
height: originalSize.width,
|
|
878
|
-
width: originalSize.height
|
|
879
|
-
};
|
|
880
|
-
}
|
|
881
|
-
return {
|
|
882
|
-
width: originalSize.width,
|
|
883
|
-
height: originalSize.height
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
LoadImageService.decorators = [
|
|
888
|
-
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
|
889
|
-
];
|
|
890
|
-
/** @nocollapse */ LoadImageService.ɵprov = ɵɵdefineInjectable({ factory: function LoadImageService_Factory() { return new LoadImageService(); }, token: LoadImageService, providedIn: "root" });
|
|
891
|
-
if (false) {
|
|
892
|
-
/**
|
|
893
|
-
* @type {?}
|
|
894
|
-
* @private
|
|
895
|
-
*/
|
|
896
|
-
LoadImageService.prototype.autoRotateSupported;
|
|
897
|
-
}
|
|
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
|
+
}] });
|
|
898
293
|
|
|
899
|
-
/**
|
|
900
|
-
* @fileoverview added by tsickle
|
|
901
|
-
* Generated from: lib/services/cropper-position.service.ts
|
|
902
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
903
|
-
*/
|
|
904
294
|
class CropperPositionService {
|
|
905
|
-
/**
|
|
906
|
-
* @param {?} sourceImage
|
|
907
|
-
* @param {?} cropperPosition
|
|
908
|
-
* @param {?} settings
|
|
909
|
-
* @return {?}
|
|
910
|
-
*/
|
|
911
295
|
resetCropperPosition(sourceImage, cropperPosition, settings) {
|
|
912
|
-
|
|
296
|
+
if (!(sourceImage === null || sourceImage === void 0 ? void 0 : sourceImage.nativeElement)) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
913
299
|
const sourceImageElement = sourceImage.nativeElement;
|
|
914
300
|
if (settings.cropperStaticHeight && settings.cropperStaticWidth) {
|
|
915
301
|
cropperPosition.x1 = 0;
|
|
@@ -920,9 +306,7 @@ class CropperPositionService {
|
|
|
920
306
|
settings.cropperStaticHeight : sourceImageElement.offsetHeight;
|
|
921
307
|
}
|
|
922
308
|
else {
|
|
923
|
-
/** @type {?} */
|
|
924
309
|
const cropperWidth = Math.min(settings.cropperScaledMaxWidth, sourceImageElement.offsetWidth);
|
|
925
|
-
/** @type {?} */
|
|
926
310
|
const cropperHeight = Math.min(settings.cropperScaledMaxHeight, sourceImageElement.offsetHeight);
|
|
927
311
|
if (!settings.maintainAspectRatio) {
|
|
928
312
|
cropperPosition.x1 = 0;
|
|
@@ -930,10 +314,9 @@ class CropperPositionService {
|
|
|
930
314
|
cropperPosition.y1 = 0;
|
|
931
315
|
cropperPosition.y2 = cropperHeight;
|
|
932
316
|
}
|
|
933
|
-
else if (
|
|
317
|
+
else if (sourceImageElement.offsetWidth / settings.aspectRatio < sourceImageElement.offsetHeight) {
|
|
934
318
|
cropperPosition.x1 = 0;
|
|
935
319
|
cropperPosition.x2 = cropperWidth;
|
|
936
|
-
/** @type {?} */
|
|
937
320
|
const cropperHeightWithAspectRatio = cropperWidth / settings.aspectRatio;
|
|
938
321
|
cropperPosition.y1 = (sourceImageElement.offsetHeight - cropperHeightWithAspectRatio) / 2;
|
|
939
322
|
cropperPosition.y2 = cropperPosition.y1 + cropperHeightWithAspectRatio;
|
|
@@ -941,41 +324,22 @@ class CropperPositionService {
|
|
|
941
324
|
else {
|
|
942
325
|
cropperPosition.y1 = 0;
|
|
943
326
|
cropperPosition.y2 = cropperHeight;
|
|
944
|
-
/** @type {?} */
|
|
945
327
|
const cropperWidthWithAspectRatio = cropperHeight * settings.aspectRatio;
|
|
946
328
|
cropperPosition.x1 = (sourceImageElement.offsetWidth - cropperWidthWithAspectRatio) / 2;
|
|
947
329
|
cropperPosition.x2 = cropperPosition.x1 + cropperWidthWithAspectRatio;
|
|
948
330
|
}
|
|
949
331
|
}
|
|
950
332
|
}
|
|
951
|
-
/**
|
|
952
|
-
* @param {?} event
|
|
953
|
-
* @param {?} moveStart
|
|
954
|
-
* @param {?} cropperPosition
|
|
955
|
-
* @return {?}
|
|
956
|
-
*/
|
|
957
333
|
move(event, moveStart, cropperPosition) {
|
|
958
|
-
/** @type {?} */
|
|
959
334
|
const diffX = this.getClientX(event) - moveStart.clientX;
|
|
960
|
-
/** @type {?} */
|
|
961
335
|
const diffY = this.getClientY(event) - moveStart.clientY;
|
|
962
336
|
cropperPosition.x1 = moveStart.x1 + diffX;
|
|
963
337
|
cropperPosition.y1 = moveStart.y1 + diffY;
|
|
964
338
|
cropperPosition.x2 = moveStart.x2 + diffX;
|
|
965
339
|
cropperPosition.y2 = moveStart.y2 + diffY;
|
|
966
340
|
}
|
|
967
|
-
/**
|
|
968
|
-
* @param {?} event
|
|
969
|
-
* @param {?} moveStart
|
|
970
|
-
* @param {?} cropperPosition
|
|
971
|
-
* @param {?} maxSize
|
|
972
|
-
* @param {?} settings
|
|
973
|
-
* @return {?}
|
|
974
|
-
*/
|
|
975
341
|
resize(event, moveStart, cropperPosition, maxSize, settings) {
|
|
976
|
-
/** @type {?} */
|
|
977
342
|
const moveX = this.getClientX(event) - moveStart.clientX;
|
|
978
|
-
/** @type {?} */
|
|
979
343
|
const moveY = this.getClientY(event) - moveStart.clientY;
|
|
980
344
|
switch (moveStart.position) {
|
|
981
345
|
case 'left':
|
|
@@ -1007,11 +371,8 @@ class CropperPositionService {
|
|
|
1007
371
|
cropperPosition.y2 = Math.max(Math.min(moveStart.y2 + moveY, cropperPosition.y1 + settings.cropperScaledMaxHeight), cropperPosition.y1 + settings.cropperScaledMinHeight);
|
|
1008
372
|
break;
|
|
1009
373
|
case 'center':
|
|
1010
|
-
/** @type {?} */
|
|
1011
374
|
const scale = event.scale;
|
|
1012
|
-
/** @type {?} */
|
|
1013
375
|
const newWidth = Math.min(Math.max(settings.cropperScaledMinWidth, (Math.abs(moveStart.x2 - moveStart.x1)) * scale), settings.cropperScaledMaxWidth);
|
|
1014
|
-
/** @type {?} */
|
|
1015
376
|
const newHeight = Math.min(Math.max(settings.cropperScaledMinHeight, (Math.abs(moveStart.y2 - moveStart.y1)) * scale), settings.cropperScaledMaxHeight);
|
|
1016
377
|
cropperPosition.x1 = moveStart.clientX - newWidth / 2;
|
|
1017
378
|
cropperPosition.x2 = moveStart.clientX + newWidth / 2;
|
|
@@ -1039,17 +400,8 @@ class CropperPositionService {
|
|
|
1039
400
|
this.checkAspectRatio(moveStart.position, cropperPosition, maxSize, settings);
|
|
1040
401
|
}
|
|
1041
402
|
}
|
|
1042
|
-
/**
|
|
1043
|
-
* @param {?} position
|
|
1044
|
-
* @param {?} cropperPosition
|
|
1045
|
-
* @param {?} maxSize
|
|
1046
|
-
* @param {?} settings
|
|
1047
|
-
* @return {?}
|
|
1048
|
-
*/
|
|
1049
403
|
checkAspectRatio(position, cropperPosition, maxSize, settings) {
|
|
1050
|
-
/** @type {?} */
|
|
1051
404
|
let overflowX = 0;
|
|
1052
|
-
/** @type {?} */
|
|
1053
405
|
let overflowY = 0;
|
|
1054
406
|
switch (position) {
|
|
1055
407
|
case 'top':
|
|
@@ -1111,13 +463,9 @@ class CropperPositionService {
|
|
|
1111
463
|
case 'center':
|
|
1112
464
|
cropperPosition.x2 = cropperPosition.x1 + (cropperPosition.y2 - cropperPosition.y1) * settings.aspectRatio;
|
|
1113
465
|
cropperPosition.y2 = cropperPosition.y1 + (cropperPosition.x2 - cropperPosition.x1) / settings.aspectRatio;
|
|
1114
|
-
/** @type {?} */
|
|
1115
466
|
const overflowX1 = Math.max(0 - cropperPosition.x1, 0);
|
|
1116
|
-
/** @type {?} */
|
|
1117
467
|
const overflowX2 = Math.max(cropperPosition.x2 - maxSize.width, 0);
|
|
1118
|
-
/** @type {?} */
|
|
1119
468
|
const overflowY1 = Math.max(cropperPosition.y2 - maxSize.height, 0);
|
|
1120
|
-
/** @type {?} */
|
|
1121
469
|
const overflowY2 = Math.max(0 - cropperPosition.y1, 0);
|
|
1122
470
|
if (overflowX1 > 0 || overflowX2 > 0 || overflowY1 > 0 || overflowY2 > 0) {
|
|
1123
471
|
cropperPosition.x1 += (overflowY1 * settings.aspectRatio) > overflowX1 ? (overflowY1 * settings.aspectRatio) : overflowX1;
|
|
@@ -1125,112 +473,298 @@ class CropperPositionService {
|
|
|
1125
473
|
cropperPosition.y1 += (overflowY2 * settings.aspectRatio) > overflowX2 ? overflowY2 : overflowX2 / settings.aspectRatio;
|
|
1126
474
|
cropperPosition.y2 -= (overflowY1 * settings.aspectRatio) > overflowX1 ? overflowY1 : overflowX1 / settings.aspectRatio;
|
|
1127
475
|
}
|
|
1128
|
-
break;
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
getClientX(event) {
|
|
480
|
+
var _a;
|
|
481
|
+
return ((_a = event.touches) === null || _a === void 0 ? void 0 : _a[0].clientX) || event.clientX || 0;
|
|
482
|
+
}
|
|
483
|
+
getClientY(event) {
|
|
484
|
+
var _a;
|
|
485
|
+
return ((_a = event.touches) === null || _a === void 0 ? void 0 : _a[0].clientY) || event.clientY || 0;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
CropperPositionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: CropperPositionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
489
|
+
CropperPositionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: CropperPositionService, providedIn: 'root' });
|
|
490
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: CropperPositionService, decorators: [{
|
|
491
|
+
type: Injectable,
|
|
492
|
+
args: [{ providedIn: 'root' }]
|
|
493
|
+
}] });
|
|
494
|
+
|
|
495
|
+
// Black 2x1 JPEG, with the following meta information set:
|
|
496
|
+
// - EXIF Orientation: 6 (Rotated 90° CCW)
|
|
497
|
+
// Source: https://github.com/blueimp/JavaScript-Load-Image
|
|
498
|
+
const testAutoOrientationImageURL = 'data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAA' +
|
|
499
|
+
'AAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA' +
|
|
500
|
+
'QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE' +
|
|
501
|
+
'BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/x' +
|
|
502
|
+
'ABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAA' +
|
|
503
|
+
'AAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==';
|
|
504
|
+
function supportsAutomaticRotation() {
|
|
505
|
+
return new Promise((resolve) => {
|
|
506
|
+
const img = new Image();
|
|
507
|
+
img.onload = () => {
|
|
508
|
+
// Check if browser supports automatic image orientation:
|
|
509
|
+
const supported = img.width === 1 && img.height === 2;
|
|
510
|
+
resolve(supported);
|
|
511
|
+
};
|
|
512
|
+
img.src = testAutoOrientationImageURL;
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
function getTransformationsFromExifData(exifRotationOrBase64Image) {
|
|
516
|
+
if (typeof exifRotationOrBase64Image === 'string') {
|
|
517
|
+
exifRotationOrBase64Image = getExifRotation(exifRotationOrBase64Image);
|
|
518
|
+
}
|
|
519
|
+
switch (exifRotationOrBase64Image) {
|
|
520
|
+
case 2:
|
|
521
|
+
return { rotate: 0, flip: true };
|
|
522
|
+
case 3:
|
|
523
|
+
return { rotate: 2, flip: false };
|
|
524
|
+
case 4:
|
|
525
|
+
return { rotate: 2, flip: true };
|
|
526
|
+
case 5:
|
|
527
|
+
return { rotate: 1, flip: true };
|
|
528
|
+
case 6:
|
|
529
|
+
return { rotate: 1, flip: false };
|
|
530
|
+
case 7:
|
|
531
|
+
return { rotate: 3, flip: true };
|
|
532
|
+
case 8:
|
|
533
|
+
return { rotate: 3, flip: false };
|
|
534
|
+
default:
|
|
535
|
+
return { rotate: 0, flip: false };
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
function getExifRotation(imageBase64) {
|
|
539
|
+
const view = new DataView(base64ToArrayBuffer(imageBase64));
|
|
540
|
+
if (view.getUint16(0, false) !== 0xFFD8) {
|
|
541
|
+
return -2;
|
|
542
|
+
}
|
|
543
|
+
const length = view.byteLength;
|
|
544
|
+
let offset = 2;
|
|
545
|
+
while (offset < length) {
|
|
546
|
+
if (view.getUint16(offset + 2, false) <= 8)
|
|
547
|
+
return -1;
|
|
548
|
+
const marker = view.getUint16(offset, false);
|
|
549
|
+
offset += 2;
|
|
550
|
+
if (marker == 0xFFE1) {
|
|
551
|
+
if (view.getUint32(offset += 2, false) !== 0x45786966) {
|
|
552
|
+
return -1;
|
|
553
|
+
}
|
|
554
|
+
const little = view.getUint16(offset += 6, false) == 0x4949;
|
|
555
|
+
offset += view.getUint32(offset + 4, little);
|
|
556
|
+
const tags = view.getUint16(offset, little);
|
|
557
|
+
offset += 2;
|
|
558
|
+
for (let i = 0; i < tags; i++) {
|
|
559
|
+
if (view.getUint16(offset + (i * 12), little) == 0x0112) {
|
|
560
|
+
return view.getUint16(offset + (i * 12) + 8, little);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
else if ((marker & 0xFF00) !== 0xFF00) {
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
offset += view.getUint16(offset, false);
|
|
1129
569
|
}
|
|
1130
570
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
* @return {?}
|
|
1141
|
-
*/
|
|
1142
|
-
getClientY(event) {
|
|
1143
|
-
return (event.touches && event.touches[0] ? event.touches[0].clientY : event.clientY) || 0;
|
|
571
|
+
return -1;
|
|
572
|
+
}
|
|
573
|
+
function base64ToArrayBuffer(imageBase64) {
|
|
574
|
+
imageBase64 = imageBase64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
|
|
575
|
+
const binaryString = atob(imageBase64);
|
|
576
|
+
const len = binaryString.length;
|
|
577
|
+
const bytes = new Uint8Array(len);
|
|
578
|
+
for (let i = 0; i < len; i++) {
|
|
579
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
1144
580
|
}
|
|
581
|
+
return bytes.buffer;
|
|
1145
582
|
}
|
|
1146
|
-
CropperPositionService.decorators = [
|
|
1147
|
-
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
|
1148
|
-
];
|
|
1149
|
-
/** @nocollapse */ CropperPositionService.ɵprov = ɵɵdefineInjectable({ factory: function CropperPositionService_Factory() { return new CropperPositionService(); }, token: CropperPositionService, providedIn: "root" });
|
|
1150
583
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
1155
|
-
*/
|
|
1156
|
-
/**
|
|
1157
|
-
* @param {?} key
|
|
1158
|
-
* @return {?}
|
|
1159
|
-
*/
|
|
1160
|
-
function getPositionForKey(key) {
|
|
1161
|
-
switch (key) {
|
|
1162
|
-
case 'ArrowUp':
|
|
1163
|
-
return 'top';
|
|
1164
|
-
case 'ArrowRight':
|
|
1165
|
-
return 'right';
|
|
1166
|
-
case 'ArrowDown':
|
|
1167
|
-
return 'bottom';
|
|
1168
|
-
case 'ArrowLeft':
|
|
1169
|
-
default:
|
|
1170
|
-
return 'left';
|
|
584
|
+
class LoadImageService {
|
|
585
|
+
constructor() {
|
|
586
|
+
this.autoRotateSupported = supportsAutomaticRotation();
|
|
1171
587
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
return 'left';
|
|
1183
|
-
case 'ArrowDown':
|
|
1184
|
-
return 'top';
|
|
1185
|
-
case 'ArrowLeft':
|
|
1186
|
-
default:
|
|
1187
|
-
return 'right';
|
|
588
|
+
loadImageFile(file, cropperSettings) {
|
|
589
|
+
return new Promise((resolve, reject) => {
|
|
590
|
+
const fileReader = new FileReader();
|
|
591
|
+
fileReader.onload = (event) => {
|
|
592
|
+
this.loadImage(event.target.result, file.type, cropperSettings)
|
|
593
|
+
.then(resolve)
|
|
594
|
+
.catch(reject);
|
|
595
|
+
};
|
|
596
|
+
fileReader.readAsDataURL(file);
|
|
597
|
+
});
|
|
1188
598
|
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
599
|
+
loadImage(imageBase64, imageType, cropperSettings) {
|
|
600
|
+
if (!this.isValidImageType(imageType)) {
|
|
601
|
+
return Promise.reject(new Error('Invalid image type'));
|
|
602
|
+
}
|
|
603
|
+
return this.loadBase64Image(imageBase64, cropperSettings);
|
|
604
|
+
}
|
|
605
|
+
isValidImageType(type) {
|
|
606
|
+
return /image\/(png|jpg|jpeg|bmp|gif|tiff|webp)/.test(type);
|
|
607
|
+
}
|
|
608
|
+
loadImageFromURL(url, cropperSettings) {
|
|
609
|
+
return new Promise((resolve, reject) => {
|
|
610
|
+
const img = new Image();
|
|
611
|
+
img.onerror = () => reject;
|
|
612
|
+
img.onload = () => {
|
|
613
|
+
const canvas = document.createElement('canvas');
|
|
614
|
+
const context = canvas.getContext('2d');
|
|
615
|
+
canvas.width = img.width;
|
|
616
|
+
canvas.height = img.height;
|
|
617
|
+
context === null || context === void 0 ? void 0 : context.drawImage(img, 0, 0);
|
|
618
|
+
this.loadBase64Image(canvas.toDataURL(), cropperSettings).then(resolve);
|
|
619
|
+
};
|
|
620
|
+
img.crossOrigin = 'anonymous';
|
|
621
|
+
img.src = url;
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
loadBase64Image(imageBase64, cropperSettings) {
|
|
625
|
+
return new Promise((resolve, reject) => {
|
|
626
|
+
const originalImage = new Image();
|
|
627
|
+
originalImage.onload = () => resolve({
|
|
628
|
+
originalImage,
|
|
629
|
+
originalBase64: imageBase64
|
|
630
|
+
});
|
|
631
|
+
originalImage.onerror = reject;
|
|
632
|
+
originalImage.src = imageBase64;
|
|
633
|
+
}).then((res) => this.transformImageBase64(res, cropperSettings));
|
|
634
|
+
}
|
|
635
|
+
transformImageBase64(res, cropperSettings) {
|
|
636
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
637
|
+
const autoRotate = yield this.autoRotateSupported;
|
|
638
|
+
const exifTransform = yield getTransformationsFromExifData(autoRotate ? -1 : res.originalBase64);
|
|
639
|
+
if (!res.originalImage || !res.originalImage.complete) {
|
|
640
|
+
return Promise.reject(new Error('No image loaded'));
|
|
641
|
+
}
|
|
642
|
+
const loadedImage = {
|
|
643
|
+
original: {
|
|
644
|
+
base64: res.originalBase64,
|
|
645
|
+
image: res.originalImage,
|
|
646
|
+
size: {
|
|
647
|
+
width: res.originalImage.naturalWidth,
|
|
648
|
+
height: res.originalImage.naturalHeight
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
exifTransform
|
|
652
|
+
};
|
|
653
|
+
return this.transformLoadedImage(loadedImage, cropperSettings);
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
transformLoadedImage(loadedImage, cropperSettings) {
|
|
657
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
658
|
+
const canvasRotation = cropperSettings.canvasRotation + loadedImage.exifTransform.rotate;
|
|
659
|
+
const originalSize = {
|
|
660
|
+
width: loadedImage.original.image.naturalWidth,
|
|
661
|
+
height: loadedImage.original.image.naturalHeight
|
|
662
|
+
};
|
|
663
|
+
if (canvasRotation === 0 && !loadedImage.exifTransform.flip && !cropperSettings.containWithinAspectRatio) {
|
|
664
|
+
return {
|
|
665
|
+
original: {
|
|
666
|
+
base64: loadedImage.original.base64,
|
|
667
|
+
image: loadedImage.original.image,
|
|
668
|
+
size: Object.assign({}, originalSize)
|
|
669
|
+
},
|
|
670
|
+
transformed: {
|
|
671
|
+
base64: loadedImage.original.base64,
|
|
672
|
+
image: loadedImage.original.image,
|
|
673
|
+
size: Object.assign({}, originalSize)
|
|
674
|
+
},
|
|
675
|
+
exifTransform: loadedImage.exifTransform
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
const transformedSize = this.getTransformedSize(originalSize, loadedImage.exifTransform, cropperSettings);
|
|
679
|
+
const canvas = document.createElement('canvas');
|
|
680
|
+
canvas.width = transformedSize.width;
|
|
681
|
+
canvas.height = transformedSize.height;
|
|
682
|
+
const ctx = canvas.getContext('2d');
|
|
683
|
+
ctx === null || ctx === void 0 ? void 0 : ctx.setTransform(loadedImage.exifTransform.flip ? -1 : 1, 0, 0, 1, canvas.width / 2, canvas.height / 2);
|
|
684
|
+
ctx === null || ctx === void 0 ? void 0 : ctx.rotate(Math.PI * (canvasRotation / 2));
|
|
685
|
+
ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(loadedImage.original.image, -originalSize.width / 2, -originalSize.height / 2);
|
|
686
|
+
const transformedBase64 = canvas.toDataURL();
|
|
687
|
+
const transformedImage = yield this.loadImageFromBase64(transformedBase64);
|
|
688
|
+
return {
|
|
689
|
+
original: {
|
|
690
|
+
base64: loadedImage.original.base64,
|
|
691
|
+
image: loadedImage.original.image,
|
|
692
|
+
size: Object.assign({}, originalSize)
|
|
693
|
+
},
|
|
694
|
+
transformed: {
|
|
695
|
+
base64: transformedBase64,
|
|
696
|
+
image: transformedImage,
|
|
697
|
+
size: {
|
|
698
|
+
width: transformedImage.width,
|
|
699
|
+
height: transformedImage.height
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
exifTransform: loadedImage.exifTransform
|
|
703
|
+
};
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
loadImageFromBase64(imageBase64) {
|
|
707
|
+
return new Promise(((resolve, reject) => {
|
|
708
|
+
const image = new Image();
|
|
709
|
+
image.onload = () => resolve(image);
|
|
710
|
+
image.onerror = reject;
|
|
711
|
+
image.src = imageBase64;
|
|
712
|
+
}));
|
|
713
|
+
}
|
|
714
|
+
getTransformedSize(originalSize, exifTransform, cropperSettings) {
|
|
715
|
+
const canvasRotation = cropperSettings.canvasRotation + exifTransform.rotate;
|
|
716
|
+
if (cropperSettings.containWithinAspectRatio) {
|
|
717
|
+
if (canvasRotation % 2) {
|
|
718
|
+
const minWidthToContain = originalSize.width * cropperSettings.aspectRatio;
|
|
719
|
+
const minHeightToContain = originalSize.height / cropperSettings.aspectRatio;
|
|
720
|
+
return {
|
|
721
|
+
width: Math.max(originalSize.height, minWidthToContain),
|
|
722
|
+
height: Math.max(originalSize.width, minHeightToContain)
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
else {
|
|
726
|
+
const minWidthToContain = originalSize.height * cropperSettings.aspectRatio;
|
|
727
|
+
const minHeightToContain = originalSize.width / cropperSettings.aspectRatio;
|
|
728
|
+
return {
|
|
729
|
+
width: Math.max(originalSize.width, minWidthToContain),
|
|
730
|
+
height: Math.max(originalSize.height, minHeightToContain)
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (canvasRotation % 2) {
|
|
735
|
+
return {
|
|
736
|
+
height: originalSize.width,
|
|
737
|
+
width: originalSize.height
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
return {
|
|
741
|
+
width: originalSize.width,
|
|
742
|
+
height: originalSize.height
|
|
743
|
+
};
|
|
1206
744
|
}
|
|
1207
745
|
}
|
|
746
|
+
LoadImageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: LoadImageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
747
|
+
LoadImageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: LoadImageService, providedIn: 'root' });
|
|
748
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: LoadImageService, decorators: [{
|
|
749
|
+
type: Injectable,
|
|
750
|
+
args: [{ providedIn: 'root' }]
|
|
751
|
+
}] });
|
|
1208
752
|
|
|
1209
|
-
/**
|
|
1210
|
-
* @fileoverview added by tsickle
|
|
1211
|
-
* Generated from: lib/component/image-cropper.component.ts
|
|
1212
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
1213
|
-
*/
|
|
1214
753
|
class ImageCropperComponent {
|
|
1215
|
-
/**
|
|
1216
|
-
* @param {?} cropService
|
|
1217
|
-
* @param {?} cropperPositionService
|
|
1218
|
-
* @param {?} loadImageService
|
|
1219
|
-
* @param {?} sanitizer
|
|
1220
|
-
* @param {?} cd
|
|
1221
|
-
*/
|
|
1222
754
|
constructor(cropService, cropperPositionService, loadImageService, sanitizer, cd) {
|
|
1223
755
|
this.cropService = cropService;
|
|
1224
756
|
this.cropperPositionService = cropperPositionService;
|
|
1225
757
|
this.loadImageService = loadImageService;
|
|
1226
758
|
this.sanitizer = sanitizer;
|
|
1227
759
|
this.cd = cd;
|
|
1228
|
-
this.Hammer =
|
|
1229
|
-
? (/** @type {?} */ (((/** @type {?} */ (window))).Hammer))
|
|
1230
|
-
: null;
|
|
760
|
+
this.Hammer = (window === null || window === void 0 ? void 0 : window['Hammer']) || null;
|
|
1231
761
|
this.settings = new CropperSettings();
|
|
1232
762
|
this.setImageMaxSizeRetries = 0;
|
|
1233
763
|
this.marginLeft = '0px';
|
|
764
|
+
this.maxSize = {
|
|
765
|
+
width: 0,
|
|
766
|
+
height: 0
|
|
767
|
+
};
|
|
1234
768
|
this.moveTypes = MoveTypes;
|
|
1235
769
|
this.imageVisible = false;
|
|
1236
770
|
this.format = this.settings.format;
|
|
@@ -1269,52 +803,35 @@ class ImageCropperComponent {
|
|
|
1269
803
|
this.loadImageFailed = new EventEmitter();
|
|
1270
804
|
this.reset();
|
|
1271
805
|
}
|
|
1272
|
-
/**
|
|
1273
|
-
* @param {?} changes
|
|
1274
|
-
* @return {?}
|
|
1275
|
-
*/
|
|
1276
806
|
ngOnChanges(changes) {
|
|
807
|
+
var _a;
|
|
1277
808
|
this.onChangesUpdateSettings(changes);
|
|
1278
809
|
this.onChangesInputImage(changes);
|
|
1279
|
-
if (this.loadedImage
|
|
1280
|
-
&& (changes.containWithinAspectRatio || changes.canvasRotation)) {
|
|
810
|
+
if (((_a = this.loadedImage) === null || _a === void 0 ? void 0 : _a.original.image.complete) && (changes['containWithinAspectRatio'] || changes['canvasRotation'])) {
|
|
1281
811
|
this.loadImageService
|
|
1282
812
|
.transformLoadedImage(this.loadedImage, this.settings)
|
|
1283
|
-
.then((
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
(res) => this.setLoadedImage(res)))
|
|
1288
|
-
.catch((/**
|
|
1289
|
-
* @param {?} err
|
|
1290
|
-
* @return {?}
|
|
1291
|
-
*/
|
|
1292
|
-
(err) => this.loadImageError(err)));
|
|
1293
|
-
}
|
|
1294
|
-
if (changes.cropper || changes.maintainAspectRatio || changes.aspectRatio) {
|
|
813
|
+
.then((res) => this.setLoadedImage(res))
|
|
814
|
+
.catch((err) => this.loadImageError(err));
|
|
815
|
+
}
|
|
816
|
+
if (changes['cropper'] || changes['maintainAspectRatio'] || changes['aspectRatio']) {
|
|
1295
817
|
this.setMaxSize();
|
|
1296
818
|
this.setCropperScaledMinSize();
|
|
1297
819
|
this.setCropperScaledMaxSize();
|
|
1298
|
-
if (this.maintainAspectRatio && (changes
|
|
820
|
+
if (this.maintainAspectRatio && (changes['maintainAspectRatio'] || changes['aspectRatio'])) {
|
|
1299
821
|
this.resetCropperPosition();
|
|
1300
822
|
}
|
|
1301
|
-
else if (changes
|
|
823
|
+
else if (changes['cropper']) {
|
|
1302
824
|
this.checkCropperPosition(false);
|
|
1303
825
|
this.doAutoCrop();
|
|
1304
826
|
}
|
|
1305
827
|
this.cd.markForCheck();
|
|
1306
828
|
}
|
|
1307
|
-
if (changes
|
|
829
|
+
if (changes['transform']) {
|
|
1308
830
|
this.transform = this.transform || {};
|
|
1309
831
|
this.setCssTransform();
|
|
1310
832
|
this.doAutoCrop();
|
|
1311
833
|
}
|
|
1312
834
|
}
|
|
1313
|
-
/**
|
|
1314
|
-
* @private
|
|
1315
|
-
* @param {?} changes
|
|
1316
|
-
* @return {?}
|
|
1317
|
-
*/
|
|
1318
835
|
onChangesUpdateSettings(changes) {
|
|
1319
836
|
this.settings.setOptionsFromChanges(changes);
|
|
1320
837
|
if (this.settings.cropperStaticHeight && this.settings.cropperStaticWidth) {
|
|
@@ -1328,61 +845,39 @@ class ImageCropperComponent {
|
|
|
1328
845
|
});
|
|
1329
846
|
}
|
|
1330
847
|
}
|
|
1331
|
-
/**
|
|
1332
|
-
* @private
|
|
1333
|
-
* @param {?} changes
|
|
1334
|
-
* @return {?}
|
|
1335
|
-
*/
|
|
1336
848
|
onChangesInputImage(changes) {
|
|
1337
|
-
if (changes
|
|
849
|
+
if (changes['imageChangedEvent'] || changes['imageURL'] || changes['imageBase64'] || changes['imageFile']) {
|
|
1338
850
|
this.reset();
|
|
1339
851
|
}
|
|
1340
|
-
if (changes
|
|
852
|
+
if (changes['imageChangedEvent'] && this.isValidImageChangedEvent()) {
|
|
1341
853
|
this.loadImageFile(this.imageChangedEvent.target.files[0]);
|
|
1342
854
|
}
|
|
1343
|
-
if (changes
|
|
855
|
+
if (changes['imageURL'] && this.imageURL) {
|
|
1344
856
|
this.loadImageFromURL(this.imageURL);
|
|
1345
857
|
}
|
|
1346
|
-
if (changes
|
|
858
|
+
if (changes['imageBase64'] && this.imageBase64) {
|
|
1347
859
|
this.loadBase64Image(this.imageBase64);
|
|
1348
860
|
}
|
|
1349
|
-
if (changes
|
|
861
|
+
if (changes['imageFile'] && this.imageFile) {
|
|
1350
862
|
this.loadImageFile(this.imageFile);
|
|
1351
863
|
}
|
|
1352
864
|
}
|
|
1353
|
-
/**
|
|
1354
|
-
* @private
|
|
1355
|
-
* @return {?}
|
|
1356
|
-
*/
|
|
1357
865
|
isValidImageChangedEvent() {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
&& this.imageChangedEvent.target.files.length > 0;
|
|
1362
|
-
}
|
|
1363
|
-
/**
|
|
1364
|
-
* @private
|
|
1365
|
-
* @return {?}
|
|
1366
|
-
*/
|
|
866
|
+
var _a, _b, _c;
|
|
867
|
+
return ((_c = (_b = (_a = this.imageChangedEvent) === null || _a === void 0 ? void 0 : _a.target) === null || _b === void 0 ? void 0 : _b.files) === null || _c === void 0 ? void 0 : _c.length) > 0;
|
|
868
|
+
}
|
|
1367
869
|
setCssTransform() {
|
|
1368
870
|
this.safeTransformStyle = this.sanitizer.bypassSecurityTrustStyle('scaleX(' + (this.transform.scale || 1) * (this.transform.flipH ? -1 : 1) + ')' +
|
|
1369
871
|
'scaleY(' + (this.transform.scale || 1) * (this.transform.flipV ? -1 : 1) + ')' +
|
|
1370
872
|
'rotate(' + (this.transform.rotate || 0) + 'deg)');
|
|
1371
873
|
}
|
|
1372
|
-
/**
|
|
1373
|
-
* @return {?}
|
|
1374
|
-
*/
|
|
1375
874
|
ngOnInit() {
|
|
1376
875
|
this.settings.stepSize = this.initialStepSize;
|
|
1377
876
|
this.activatePinchGesture();
|
|
1378
877
|
}
|
|
1379
|
-
/**
|
|
1380
|
-
* @private
|
|
1381
|
-
* @return {?}
|
|
1382
|
-
*/
|
|
1383
878
|
reset() {
|
|
1384
879
|
this.imageVisible = false;
|
|
1385
|
-
this.loadedImage =
|
|
880
|
+
this.loadedImage = undefined;
|
|
1386
881
|
this.safeImgDataUrl = 'data:image/png;base64,iVBORw0KGg'
|
|
1387
882
|
+ 'oAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAU'
|
|
1388
883
|
+ 'AAarVyFEAAAAASUVORK5CYII=';
|
|
@@ -1406,99 +901,40 @@ class ImageCropperComponent {
|
|
|
1406
901
|
this.cropper.x2 = 10000;
|
|
1407
902
|
this.cropper.y2 = 10000;
|
|
1408
903
|
}
|
|
1409
|
-
/**
|
|
1410
|
-
* @private
|
|
1411
|
-
* @param {?} file
|
|
1412
|
-
* @return {?}
|
|
1413
|
-
*/
|
|
1414
904
|
loadImageFile(file) {
|
|
1415
905
|
this.loadImageService
|
|
1416
906
|
.loadImageFile(file, this.settings)
|
|
1417
|
-
.then((
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
*/
|
|
1421
|
-
(res) => this.setLoadedImage(res)))
|
|
1422
|
-
.catch((/**
|
|
1423
|
-
* @param {?} err
|
|
1424
|
-
* @return {?}
|
|
1425
|
-
*/
|
|
1426
|
-
(err) => this.loadImageError(err)));
|
|
1427
|
-
}
|
|
1428
|
-
/**
|
|
1429
|
-
* @private
|
|
1430
|
-
* @param {?} imageBase64
|
|
1431
|
-
* @return {?}
|
|
1432
|
-
*/
|
|
907
|
+
.then((res) => this.setLoadedImage(res))
|
|
908
|
+
.catch((err) => this.loadImageError(err));
|
|
909
|
+
}
|
|
1433
910
|
loadBase64Image(imageBase64) {
|
|
1434
911
|
this.loadImageService
|
|
1435
912
|
.loadBase64Image(imageBase64, this.settings)
|
|
1436
|
-
.then((
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
*/
|
|
1440
|
-
(res) => this.setLoadedImage(res)))
|
|
1441
|
-
.catch((/**
|
|
1442
|
-
* @param {?} err
|
|
1443
|
-
* @return {?}
|
|
1444
|
-
*/
|
|
1445
|
-
(err) => this.loadImageError(err)));
|
|
1446
|
-
}
|
|
1447
|
-
/**
|
|
1448
|
-
* @private
|
|
1449
|
-
* @param {?} url
|
|
1450
|
-
* @return {?}
|
|
1451
|
-
*/
|
|
913
|
+
.then((res) => this.setLoadedImage(res))
|
|
914
|
+
.catch((err) => this.loadImageError(err));
|
|
915
|
+
}
|
|
1452
916
|
loadImageFromURL(url) {
|
|
1453
917
|
this.loadImageService
|
|
1454
918
|
.loadImageFromURL(url, this.settings)
|
|
1455
|
-
.then((
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
*/
|
|
1459
|
-
(res) => this.setLoadedImage(res)))
|
|
1460
|
-
.catch((/**
|
|
1461
|
-
* @param {?} err
|
|
1462
|
-
* @return {?}
|
|
1463
|
-
*/
|
|
1464
|
-
(err) => this.loadImageError(err)));
|
|
1465
|
-
}
|
|
1466
|
-
/**
|
|
1467
|
-
* @private
|
|
1468
|
-
* @param {?} loadedImage
|
|
1469
|
-
* @return {?}
|
|
1470
|
-
*/
|
|
919
|
+
.then((res) => this.setLoadedImage(res))
|
|
920
|
+
.catch((err) => this.loadImageError(err));
|
|
921
|
+
}
|
|
1471
922
|
setLoadedImage(loadedImage) {
|
|
1472
923
|
this.loadedImage = loadedImage;
|
|
1473
924
|
this.safeImgDataUrl = this.sanitizer.bypassSecurityTrustResourceUrl(loadedImage.transformed.base64);
|
|
1474
925
|
this.cd.markForCheck();
|
|
1475
926
|
}
|
|
1476
|
-
/**
|
|
1477
|
-
* @private
|
|
1478
|
-
* @param {?} error
|
|
1479
|
-
* @return {?}
|
|
1480
|
-
*/
|
|
1481
927
|
loadImageError(error) {
|
|
1482
928
|
console.error(error);
|
|
1483
929
|
this.loadImageFailed.emit();
|
|
1484
930
|
}
|
|
1485
|
-
/**
|
|
1486
|
-
* @return {?}
|
|
1487
|
-
*/
|
|
1488
931
|
imageLoadedInView() {
|
|
1489
932
|
if (this.loadedImage != null) {
|
|
1490
933
|
this.imageLoaded.emit(this.loadedImage);
|
|
1491
934
|
this.setImageMaxSizeRetries = 0;
|
|
1492
|
-
setTimeout((
|
|
1493
|
-
* @return {?}
|
|
1494
|
-
*/
|
|
1495
|
-
() => this.checkImageMaxSizeRecursively()));
|
|
935
|
+
setTimeout(() => this.checkImageMaxSizeRecursively());
|
|
1496
936
|
}
|
|
1497
937
|
}
|
|
1498
|
-
/**
|
|
1499
|
-
* @private
|
|
1500
|
-
* @return {?}
|
|
1501
|
-
*/
|
|
1502
938
|
checkImageMaxSizeRecursively() {
|
|
1503
939
|
if (this.setImageMaxSizeRetries > 40) {
|
|
1504
940
|
this.loadImageFailed.emit();
|
|
@@ -1513,22 +949,13 @@ class ImageCropperComponent {
|
|
|
1513
949
|
}
|
|
1514
950
|
else {
|
|
1515
951
|
this.setImageMaxSizeRetries++;
|
|
1516
|
-
setTimeout((
|
|
1517
|
-
* @return {?}
|
|
1518
|
-
*/
|
|
1519
|
-
() => this.checkImageMaxSizeRecursively()), 50);
|
|
952
|
+
setTimeout(() => this.checkImageMaxSizeRecursively(), 50);
|
|
1520
953
|
}
|
|
1521
954
|
}
|
|
1522
|
-
/**
|
|
1523
|
-
* @private
|
|
1524
|
-
* @return {?}
|
|
1525
|
-
*/
|
|
1526
955
|
sourceImageLoaded() {
|
|
1527
|
-
|
|
956
|
+
var _a, _b;
|
|
957
|
+
return ((_b = (_a = this.sourceImage) === null || _a === void 0 ? void 0 : _a.nativeElement) === null || _b === void 0 ? void 0 : _b.offsetWidth) > 0;
|
|
1528
958
|
}
|
|
1529
|
-
/**
|
|
1530
|
-
* @return {?}
|
|
1531
|
-
*/
|
|
1532
959
|
onResize() {
|
|
1533
960
|
if (!this.loadedImage) {
|
|
1534
961
|
return;
|
|
@@ -1538,13 +965,8 @@ class ImageCropperComponent {
|
|
|
1538
965
|
this.setCropperScaledMinSize();
|
|
1539
966
|
this.setCropperScaledMaxSize();
|
|
1540
967
|
}
|
|
1541
|
-
/**
|
|
1542
|
-
* @private
|
|
1543
|
-
* @return {?}
|
|
1544
|
-
*/
|
|
1545
968
|
activatePinchGesture() {
|
|
1546
969
|
if (this.Hammer) {
|
|
1547
|
-
/** @type {?} */
|
|
1548
970
|
const hammer = new this.Hammer(this.wrapper.nativeElement);
|
|
1549
971
|
hammer.get('pinch').set({ enable: true });
|
|
1550
972
|
hammer.on('pinchmove', this.onPinch.bind(this));
|
|
@@ -1555,12 +977,7 @@ class ImageCropperComponent {
|
|
|
1555
977
|
console.warn('[NgxImageCropper] Could not find HammerJS - Pinch Gesture won\'t work');
|
|
1556
978
|
}
|
|
1557
979
|
}
|
|
1558
|
-
/**
|
|
1559
|
-
* @private
|
|
1560
|
-
* @return {?}
|
|
1561
|
-
*/
|
|
1562
980
|
resizeCropperPosition() {
|
|
1563
|
-
/** @type {?} */
|
|
1564
981
|
const sourceImageElement = this.sourceImage.nativeElement;
|
|
1565
982
|
if (this.maxSize.width !== sourceImageElement.offsetWidth || this.maxSize.height !== sourceImageElement.offsetHeight) {
|
|
1566
983
|
this.cropper.x1 = this.cropper.x1 * sourceImageElement.offsetWidth / this.maxSize.width;
|
|
@@ -1569,49 +986,28 @@ class ImageCropperComponent {
|
|
|
1569
986
|
this.cropper.y2 = this.cropper.y2 * sourceImageElement.offsetHeight / this.maxSize.height;
|
|
1570
987
|
}
|
|
1571
988
|
}
|
|
1572
|
-
/**
|
|
1573
|
-
* @return {?}
|
|
1574
|
-
*/
|
|
1575
989
|
resetCropperPosition() {
|
|
1576
990
|
this.cropperPositionService.resetCropperPosition(this.sourceImage, this.cropper, this.settings);
|
|
1577
991
|
this.doAutoCrop();
|
|
1578
992
|
this.imageVisible = true;
|
|
1579
993
|
}
|
|
1580
|
-
/**
|
|
1581
|
-
* @param {?} event
|
|
1582
|
-
* @return {?}
|
|
1583
|
-
*/
|
|
1584
994
|
keyboardAccess(event) {
|
|
1585
995
|
this.changeKeyboardStepSize(event);
|
|
1586
996
|
this.keyboardMoveCropper(event);
|
|
1587
997
|
}
|
|
1588
|
-
/**
|
|
1589
|
-
* @private
|
|
1590
|
-
* @param {?} event
|
|
1591
|
-
* @return {?}
|
|
1592
|
-
*/
|
|
1593
998
|
changeKeyboardStepSize(event) {
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
999
|
+
const key = +event.key;
|
|
1000
|
+
if (key >= 1 && key <= 9) {
|
|
1001
|
+
this.settings.stepSize = key;
|
|
1597
1002
|
}
|
|
1598
1003
|
}
|
|
1599
|
-
/**
|
|
1600
|
-
* @private
|
|
1601
|
-
* @param {?} event
|
|
1602
|
-
* @return {?}
|
|
1603
|
-
*/
|
|
1604
1004
|
keyboardMoveCropper(event) {
|
|
1605
|
-
/** @type {?} */
|
|
1606
1005
|
const keyboardWhiteList = ['ArrowUp', 'ArrowDown', 'ArrowRight', 'ArrowLeft'];
|
|
1607
1006
|
if (!(keyboardWhiteList.includes(event.key))) {
|
|
1608
1007
|
return;
|
|
1609
1008
|
}
|
|
1610
|
-
/** @type {?} */
|
|
1611
1009
|
const moveType = event.shiftKey ? MoveTypes.Resize : MoveTypes.Move;
|
|
1612
|
-
/** @type {?} */
|
|
1613
1010
|
const position = event.altKey ? getInvertedPositionForKey(event.key) : getPositionForKey(event.key);
|
|
1614
|
-
/** @type {?} */
|
|
1615
1011
|
const moveEvent = getEventForKey(event.key, this.settings.stepSize);
|
|
1616
1012
|
event.preventDefault();
|
|
1617
1013
|
event.stopPropagation();
|
|
@@ -1619,14 +1015,9 @@ class ImageCropperComponent {
|
|
|
1619
1015
|
this.moveImg(moveEvent);
|
|
1620
1016
|
this.moveStop();
|
|
1621
1017
|
}
|
|
1622
|
-
/**
|
|
1623
|
-
* @param {?} event
|
|
1624
|
-
* @param {?} moveType
|
|
1625
|
-
* @param {?=} position
|
|
1626
|
-
* @return {?}
|
|
1627
|
-
*/
|
|
1628
1018
|
startMove(event, moveType, position = null) {
|
|
1629
|
-
|
|
1019
|
+
var _a, _b;
|
|
1020
|
+
if (((_a = this.moveStart) === null || _a === void 0 ? void 0 : _a.active) && ((_b = this.moveStart) === null || _b === void 0 ? void 0 : _b.type) === MoveTypes.Pinch) {
|
|
1630
1021
|
return;
|
|
1631
1022
|
}
|
|
1632
1023
|
if (event.preventDefault) {
|
|
@@ -1634,10 +1025,6 @@ class ImageCropperComponent {
|
|
|
1634
1025
|
}
|
|
1635
1026
|
this.moveStart = Object.assign({ active: true, type: moveType, position, clientX: this.cropperPositionService.getClientX(event), clientY: this.cropperPositionService.getClientY(event) }, this.cropper);
|
|
1636
1027
|
}
|
|
1637
|
-
/**
|
|
1638
|
-
* @param {?} event
|
|
1639
|
-
* @return {?}
|
|
1640
|
-
*/
|
|
1641
1028
|
startPinch(event) {
|
|
1642
1029
|
if (!this.safeImgDataUrl) {
|
|
1643
1030
|
return;
|
|
@@ -1647,10 +1034,6 @@ class ImageCropperComponent {
|
|
|
1647
1034
|
}
|
|
1648
1035
|
this.moveStart = Object.assign({ active: true, type: MoveTypes.Pinch, position: 'center', clientX: this.cropper.x1 + (this.cropper.x2 - this.cropper.x1) / 2, clientY: this.cropper.y1 + (this.cropper.y2 - this.cropper.y1) / 2 }, this.cropper);
|
|
1649
1036
|
}
|
|
1650
|
-
/**
|
|
1651
|
-
* @param {?} event
|
|
1652
|
-
* @return {?}
|
|
1653
|
-
*/
|
|
1654
1037
|
moveImg(event) {
|
|
1655
1038
|
if (this.moveStart.active) {
|
|
1656
1039
|
if (event.stopPropagation) {
|
|
@@ -1672,10 +1055,6 @@ class ImageCropperComponent {
|
|
|
1672
1055
|
this.cd.detectChanges();
|
|
1673
1056
|
}
|
|
1674
1057
|
}
|
|
1675
|
-
/**
|
|
1676
|
-
* @param {?} event
|
|
1677
|
-
* @return {?}
|
|
1678
|
-
*/
|
|
1679
1058
|
onPinch(event) {
|
|
1680
1059
|
if (this.moveStart.active) {
|
|
1681
1060
|
if (event.stopPropagation) {
|
|
@@ -1691,25 +1070,17 @@ class ImageCropperComponent {
|
|
|
1691
1070
|
this.cd.detectChanges();
|
|
1692
1071
|
}
|
|
1693
1072
|
}
|
|
1694
|
-
/**
|
|
1695
|
-
* @private
|
|
1696
|
-
* @return {?}
|
|
1697
|
-
*/
|
|
1698
1073
|
setMaxSize() {
|
|
1699
1074
|
if (this.sourceImage) {
|
|
1700
|
-
/** @type {?} */
|
|
1701
1075
|
const sourceImageElement = this.sourceImage.nativeElement;
|
|
1702
1076
|
this.maxSize.width = sourceImageElement.offsetWidth;
|
|
1703
1077
|
this.maxSize.height = sourceImageElement.offsetHeight;
|
|
1704
1078
|
this.marginLeft = this.sanitizer.bypassSecurityTrustStyle('calc(50% - ' + this.maxSize.width / 2 + 'px)');
|
|
1705
1079
|
}
|
|
1706
1080
|
}
|
|
1707
|
-
/**
|
|
1708
|
-
* @private
|
|
1709
|
-
* @return {?}
|
|
1710
|
-
*/
|
|
1711
1081
|
setCropperScaledMinSize() {
|
|
1712
|
-
|
|
1082
|
+
var _a, _b;
|
|
1083
|
+
if ((_b = (_a = this.loadedImage) === null || _a === void 0 ? void 0 : _a.transformed) === null || _b === void 0 ? void 0 : _b.image) {
|
|
1713
1084
|
this.setCropperScaledMinWidth();
|
|
1714
1085
|
this.setCropperScaledMinHeight();
|
|
1715
1086
|
}
|
|
@@ -1718,19 +1089,11 @@ class ImageCropperComponent {
|
|
|
1718
1089
|
this.settings.cropperScaledMinHeight = 20;
|
|
1719
1090
|
}
|
|
1720
1091
|
}
|
|
1721
|
-
/**
|
|
1722
|
-
* @private
|
|
1723
|
-
* @return {?}
|
|
1724
|
-
*/
|
|
1725
1092
|
setCropperScaledMinWidth() {
|
|
1726
1093
|
this.settings.cropperScaledMinWidth = this.cropperMinWidth > 0
|
|
1727
1094
|
? Math.max(20, this.cropperMinWidth / this.loadedImage.transformed.image.width * this.maxSize.width)
|
|
1728
1095
|
: 20;
|
|
1729
1096
|
}
|
|
1730
|
-
/**
|
|
1731
|
-
* @private
|
|
1732
|
-
* @return {?}
|
|
1733
|
-
*/
|
|
1734
1097
|
setCropperScaledMinHeight() {
|
|
1735
1098
|
if (this.maintainAspectRatio) {
|
|
1736
1099
|
this.settings.cropperScaledMinHeight = Math.max(20, this.settings.cropperScaledMinWidth / this.aspectRatio);
|
|
@@ -1742,13 +1105,9 @@ class ImageCropperComponent {
|
|
|
1742
1105
|
this.settings.cropperScaledMinHeight = 20;
|
|
1743
1106
|
}
|
|
1744
1107
|
}
|
|
1745
|
-
/**
|
|
1746
|
-
* @private
|
|
1747
|
-
* @return {?}
|
|
1748
|
-
*/
|
|
1749
1108
|
setCropperScaledMaxSize() {
|
|
1750
|
-
|
|
1751
|
-
|
|
1109
|
+
var _a, _b;
|
|
1110
|
+
if ((_b = (_a = this.loadedImage) === null || _a === void 0 ? void 0 : _a.transformed) === null || _b === void 0 ? void 0 : _b.image) {
|
|
1752
1111
|
const ratio = this.loadedImage.transformed.size.width / this.maxSize.width;
|
|
1753
1112
|
this.settings.cropperScaledMaxWidth = this.cropperMaxWidth > 20 ? this.cropperMaxWidth / ratio : this.maxSize.width;
|
|
1754
1113
|
this.settings.cropperScaledMaxHeight = this.cropperMaxHeight > 20 ? this.cropperMaxHeight / ratio : this.maxSize.height;
|
|
@@ -1766,11 +1125,6 @@ class ImageCropperComponent {
|
|
|
1766
1125
|
this.settings.cropperScaledMaxHeight = this.maxSize.height;
|
|
1767
1126
|
}
|
|
1768
1127
|
}
|
|
1769
|
-
/**
|
|
1770
|
-
* @private
|
|
1771
|
-
* @param {?=} maintainSize
|
|
1772
|
-
* @return {?}
|
|
1773
|
-
*/
|
|
1774
1128
|
checkCropperPosition(maintainSize = false) {
|
|
1775
1129
|
if (this.cropper.x1 < 0) {
|
|
1776
1130
|
this.cropper.x2 -= maintainSize ? this.cropper.x1 : 0;
|
|
@@ -1789,40 +1143,27 @@ class ImageCropperComponent {
|
|
|
1789
1143
|
this.cropper.y2 = this.maxSize.height;
|
|
1790
1144
|
}
|
|
1791
1145
|
}
|
|
1792
|
-
/**
|
|
1793
|
-
* @return {?}
|
|
1794
|
-
*/
|
|
1795
1146
|
moveStop() {
|
|
1796
1147
|
if (this.moveStart.active) {
|
|
1797
1148
|
this.moveStart.active = false;
|
|
1798
1149
|
this.doAutoCrop();
|
|
1799
1150
|
}
|
|
1800
1151
|
}
|
|
1801
|
-
/**
|
|
1802
|
-
* @return {?}
|
|
1803
|
-
*/
|
|
1804
1152
|
pinchStop() {
|
|
1805
1153
|
if (this.moveStart.active) {
|
|
1806
1154
|
this.moveStart.active = false;
|
|
1807
1155
|
this.doAutoCrop();
|
|
1808
1156
|
}
|
|
1809
1157
|
}
|
|
1810
|
-
/**
|
|
1811
|
-
* @private
|
|
1812
|
-
* @return {?}
|
|
1813
|
-
*/
|
|
1814
1158
|
doAutoCrop() {
|
|
1815
1159
|
if (this.autoCrop) {
|
|
1816
1160
|
this.crop();
|
|
1817
1161
|
}
|
|
1818
1162
|
}
|
|
1819
|
-
/**
|
|
1820
|
-
* @return {?}
|
|
1821
|
-
*/
|
|
1822
1163
|
crop() {
|
|
1823
|
-
|
|
1164
|
+
var _a, _b;
|
|
1165
|
+
if (((_b = (_a = this.loadedImage) === null || _a === void 0 ? void 0 : _a.transformed) === null || _b === void 0 ? void 0 : _b.image) != null) {
|
|
1824
1166
|
this.startCropImage.emit();
|
|
1825
|
-
/** @type {?} */
|
|
1826
1167
|
const output = this.cropService.crop(this.sourceImage, this.loadedImage, this.cropper, this.settings);
|
|
1827
1168
|
if (output != null) {
|
|
1828
1169
|
this.imageCropped.emit(output);
|
|
@@ -1832,243 +1173,133 @@ class ImageCropperComponent {
|
|
|
1832
1173
|
return null;
|
|
1833
1174
|
}
|
|
1834
1175
|
}
|
|
1835
|
-
ImageCropperComponent
|
|
1836
|
-
{ type:
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
]
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
]
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
ImageCropperComponent.prototype.imageChangedEvent;
|
|
1935
|
-
/** @type {?} */
|
|
1936
|
-
ImageCropperComponent.prototype.imageURL;
|
|
1937
|
-
/** @type {?} */
|
|
1938
|
-
ImageCropperComponent.prototype.imageBase64;
|
|
1939
|
-
/** @type {?} */
|
|
1940
|
-
ImageCropperComponent.prototype.imageFile;
|
|
1941
|
-
/** @type {?} */
|
|
1942
|
-
ImageCropperComponent.prototype.format;
|
|
1943
|
-
/** @type {?} */
|
|
1944
|
-
ImageCropperComponent.prototype.transform;
|
|
1945
|
-
/** @type {?} */
|
|
1946
|
-
ImageCropperComponent.prototype.maintainAspectRatio;
|
|
1947
|
-
/** @type {?} */
|
|
1948
|
-
ImageCropperComponent.prototype.aspectRatio;
|
|
1949
|
-
/** @type {?} */
|
|
1950
|
-
ImageCropperComponent.prototype.resizeToWidth;
|
|
1951
|
-
/** @type {?} */
|
|
1952
|
-
ImageCropperComponent.prototype.resizeToHeight;
|
|
1953
|
-
/** @type {?} */
|
|
1954
|
-
ImageCropperComponent.prototype.cropperMinWidth;
|
|
1955
|
-
/** @type {?} */
|
|
1956
|
-
ImageCropperComponent.prototype.cropperMinHeight;
|
|
1957
|
-
/** @type {?} */
|
|
1958
|
-
ImageCropperComponent.prototype.cropperMaxHeight;
|
|
1959
|
-
/** @type {?} */
|
|
1960
|
-
ImageCropperComponent.prototype.cropperMaxWidth;
|
|
1961
|
-
/** @type {?} */
|
|
1962
|
-
ImageCropperComponent.prototype.cropperStaticWidth;
|
|
1963
|
-
/** @type {?} */
|
|
1964
|
-
ImageCropperComponent.prototype.cropperStaticHeight;
|
|
1965
|
-
/** @type {?} */
|
|
1966
|
-
ImageCropperComponent.prototype.canvasRotation;
|
|
1967
|
-
/** @type {?} */
|
|
1968
|
-
ImageCropperComponent.prototype.initialStepSize;
|
|
1969
|
-
/** @type {?} */
|
|
1970
|
-
ImageCropperComponent.prototype.roundCropper;
|
|
1971
|
-
/** @type {?} */
|
|
1972
|
-
ImageCropperComponent.prototype.onlyScaleDown;
|
|
1973
|
-
/** @type {?} */
|
|
1974
|
-
ImageCropperComponent.prototype.imageQuality;
|
|
1975
|
-
/** @type {?} */
|
|
1976
|
-
ImageCropperComponent.prototype.autoCrop;
|
|
1977
|
-
/** @type {?} */
|
|
1978
|
-
ImageCropperComponent.prototype.backgroundColor;
|
|
1979
|
-
/** @type {?} */
|
|
1980
|
-
ImageCropperComponent.prototype.containWithinAspectRatio;
|
|
1981
|
-
/** @type {?} */
|
|
1982
|
-
ImageCropperComponent.prototype.hideResizeSquares;
|
|
1983
|
-
/** @type {?} */
|
|
1984
|
-
ImageCropperComponent.prototype.cropper;
|
|
1985
|
-
/** @type {?} */
|
|
1986
|
-
ImageCropperComponent.prototype.alignImage;
|
|
1987
|
-
/** @type {?} */
|
|
1988
|
-
ImageCropperComponent.prototype.disabled;
|
|
1989
|
-
/** @type {?} */
|
|
1990
|
-
ImageCropperComponent.prototype.imageCropped;
|
|
1991
|
-
/** @type {?} */
|
|
1992
|
-
ImageCropperComponent.prototype.startCropImage;
|
|
1993
|
-
/** @type {?} */
|
|
1994
|
-
ImageCropperComponent.prototype.imageLoaded;
|
|
1995
|
-
/** @type {?} */
|
|
1996
|
-
ImageCropperComponent.prototype.cropperReady;
|
|
1997
|
-
/** @type {?} */
|
|
1998
|
-
ImageCropperComponent.prototype.loadImageFailed;
|
|
1999
|
-
/**
|
|
2000
|
-
* @type {?}
|
|
2001
|
-
* @private
|
|
2002
|
-
*/
|
|
2003
|
-
ImageCropperComponent.prototype.cropService;
|
|
2004
|
-
/**
|
|
2005
|
-
* @type {?}
|
|
2006
|
-
* @private
|
|
2007
|
-
*/
|
|
2008
|
-
ImageCropperComponent.prototype.cropperPositionService;
|
|
2009
|
-
/**
|
|
2010
|
-
* @type {?}
|
|
2011
|
-
* @private
|
|
2012
|
-
*/
|
|
2013
|
-
ImageCropperComponent.prototype.loadImageService;
|
|
2014
|
-
/**
|
|
2015
|
-
* @type {?}
|
|
2016
|
-
* @private
|
|
2017
|
-
*/
|
|
2018
|
-
ImageCropperComponent.prototype.sanitizer;
|
|
2019
|
-
/**
|
|
2020
|
-
* @type {?}
|
|
2021
|
-
* @private
|
|
2022
|
-
*/
|
|
2023
|
-
ImageCropperComponent.prototype.cd;
|
|
2024
|
-
}
|
|
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
|
+
}] } });
|
|
2025
1275
|
|
|
2026
|
-
/**
|
|
2027
|
-
* @fileoverview added by tsickle
|
|
2028
|
-
* Generated from: lib/image-cropper.module.ts
|
|
2029
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
2030
|
-
*/
|
|
2031
1276
|
class ImageCropperModule {
|
|
2032
1277
|
}
|
|
2033
|
-
ImageCropperModule
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
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
|
+
}] });
|
|
2052
1297
|
|
|
2053
|
-
/**
|
|
2054
|
-
* @fileoverview added by tsickle
|
|
2055
|
-
* Generated from: lib/utils/blob.utils.ts
|
|
2056
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
2057
|
-
*/
|
|
2058
|
-
/**
|
|
2059
|
-
* @param {?} base64Image
|
|
2060
|
-
* @return {?}
|
|
2061
|
-
*/
|
|
2062
1298
|
function base64ToFile(base64Image) {
|
|
2063
|
-
/** @type {?} */
|
|
2064
1299
|
const split = base64Image.split(',');
|
|
2065
|
-
/** @type {?} */
|
|
2066
1300
|
const type = split[0].replace('data:', '').replace(';base64', '');
|
|
2067
|
-
/** @type {?} */
|
|
2068
1301
|
const byteString = atob(split[1]);
|
|
2069
|
-
/** @type {?} */
|
|
2070
1302
|
const ab = new ArrayBuffer(byteString.length);
|
|
2071
|
-
/** @type {?} */
|
|
2072
1303
|
const ia = new Uint8Array(ab);
|
|
2073
1304
|
for (let i = 0; i < byteString.length; i += 1) {
|
|
2074
1305
|
ia[i] = byteString.charCodeAt(i);
|
|
@@ -2077,16 +1308,8 @@ function base64ToFile(base64Image) {
|
|
|
2077
1308
|
}
|
|
2078
1309
|
|
|
2079
1310
|
/**
|
|
2080
|
-
*
|
|
2081
|
-
* Generated from: public-api.ts
|
|
2082
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
2083
|
-
*/
|
|
2084
|
-
|
|
2085
|
-
/**
|
|
2086
|
-
* @fileoverview added by tsickle
|
|
2087
|
-
* Generated from: ngx-image-cropper.ts
|
|
2088
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
1311
|
+
* Generated bundle index. Do not edit.
|
|
2089
1312
|
*/
|
|
2090
1313
|
|
|
2091
|
-
export { ImageCropperComponent, ImageCropperModule, base64ToFile, resizeCanvas
|
|
2092
|
-
//# sourceMappingURL=ngx-image-cropper.
|
|
1314
|
+
export { ImageCropperComponent, ImageCropperModule, base64ToFile, resizeCanvas };
|
|
1315
|
+
//# sourceMappingURL=ngx-image-cropper.mjs.map
|