ngx-image-cropper 4.0.1 → 6.0.1

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