@guajiritos/image-picker 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,630 +1,593 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Pipe, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, ViewChild, Output, NgModule } from '@angular/core';
2
+ import { Pipe, NgModule, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, ViewChild, Output } from '@angular/core';
3
3
  import { ResizeObserver } from 'resize-observer';
4
- import * as i1 from '@angular/common';
5
- import { CommonModule } from '@angular/common';
6
- import * as i2 from '@angular/material/icon';
4
+ import { NgIf, NgStyle, NgForOf } from '@angular/common';
5
+ import * as i1 from '@angular/material/button';
6
+ import { MatButtonModule } from '@angular/material/button';
7
+ import * as i2 from '@angular/material/tooltip';
8
+ import { MatTooltipModule } from '@angular/material/tooltip';
9
+ import * as i3 from '@angular/material/icon';
7
10
  import { MatIconModule } from '@angular/material/icon';
8
- import * as i3 from '@angular/material/legacy-button';
9
- import { MatLegacyButtonModule } from '@angular/material/legacy-button';
10
- import * as i4 from '@angular/material/legacy-tooltip';
11
- import { MatLegacyTooltipModule } from '@angular/material/legacy-tooltip';
12
- import * as i5 from '@angular/material/legacy-slider';
13
- import { MatLegacySliderModule } from '@angular/material/legacy-slider';
14
- import * as i6 from '@angular/forms';
15
- import { FormsModule, ReactiveFormsModule } from '@angular/forms';
16
- import * as i7 from '@angular/material/legacy-form-field';
17
- import { MatLegacyFormFieldModule } from '@angular/material/legacy-form-field';
18
- import * as i8 from '@angular/material/legacy-select';
19
- import { MatLegacySelectModule } from '@angular/material/legacy-select';
20
- import * as i9 from '@angular/material/legacy-core';
21
- import * as i10 from '@angular/material/legacy-input';
22
- import { MatLegacyInputModule } from '@angular/material/legacy-input';
23
- import * as i11 from '@angular/material/legacy-checkbox';
24
- import { MatLegacyCheckboxModule } from '@angular/material/legacy-checkbox';
11
+ import * as i5 from '@angular/material/slider';
12
+ import { MatSliderModule } from '@angular/material/slider';
13
+ import * as i6 from '@angular/material/checkbox';
14
+ import { MatCheckboxModule } from '@angular/material/checkbox';
15
+ import * as i7 from '@angular/material/form-field';
16
+ import { MatFormFieldModule } from '@angular/material/form-field';
17
+ import * as i8 from '@angular/material/input';
18
+ import { MatInputModule } from '@angular/material/input';
19
+ import * as i9 from '@angular/material/select';
20
+ import { MatSelectModule } from '@angular/material/select';
21
+ import * as i11 from '@angular/forms';
22
+ import { FormsModule } from '@angular/forms';
23
+ import { Subject } from 'rxjs';
24
+ import * as i10 from '@angular/material/core';
25
25
 
26
- class CalculateSizePipe {
27
- transform(imageLength) {
28
- if (!imageLength) {
29
- return;
30
- }
31
- if (imageLength) {
32
- return Math.ceil(((3 / 4) * imageLength) / 1024);
33
- }
34
- else {
35
- return;
36
- }
37
- }
38
- }
39
- CalculateSizePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: CalculateSizePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
40
- CalculateSizePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.1.4", ngImport: i0, type: CalculateSizePipe, name: "calculateSize" });
41
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: CalculateSizePipe, decorators: [{
42
- type: Pipe,
43
- args: [{
44
- name: 'calculateSize'
45
- }]
26
+ class CalculateSizePipe {
27
+ transform(imageLength) {
28
+ if (!imageLength) {
29
+ return 0;
30
+ }
31
+ if (imageLength) {
32
+ return Math.ceil(((3 / 4) * imageLength) / 1024);
33
+ }
34
+ else {
35
+ return 0;
36
+ }
37
+ }
38
+ }
39
+ CalculateSizePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.3", ngImport: i0, type: CalculateSizePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
40
+ CalculateSizePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.3", ngImport: i0, type: CalculateSizePipe, name: "calculateSize" });
41
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.3", ngImport: i0, type: CalculateSizePipe, decorators: [{
42
+ type: Pipe,
43
+ args: [{
44
+ name: 'calculateSize'
45
+ }]
46
46
  }] });
47
47
 
48
- class GuajiritosImagePickerComponent {
49
- constructor(_cdRef) {
50
- this._cdRef = _cdRef;
51
- this.observer = null;
52
- this.labelEn = {
53
- 'Upload a image': 'Upload a image',
54
- 'You must edit the image in order to resize it': 'You must edit the image in order to resize it',
55
- 'too large': 'too large',
56
- 'Open the editor panel': 'Open the editor panel',
57
- 'Download the image': 'Download the image',
58
- 'Control Panel': 'Control Panel',
59
- Quality: 'Quality',
60
- 'Max dimensions': 'Max dimensions',
61
- 'aspect-ratio': 'aspect-ratio',
62
- 'max-width(px)': 'max-width(px)',
63
- 'max-height(px)': 'max-height(px)',
64
- Format: 'Format',
65
- Crop: 'Crop',
66
- 'width(px)': 'width(px)',
67
- 'height(px)': 'height(px)',
68
- Remove: 'Remove',
69
- };
70
- this.labelEs = {
71
- 'Upload a image': 'Suba una imagen',
72
- 'You must edit the image in order to resize it': 'Debe editar la imagen para disminuir su tamaño',
73
- 'too large': 'muy grande',
74
- 'Open the editor panel': 'Abra el panel de edición',
75
- 'Download the image': 'Descarge la imagen',
76
- 'Control Panel': 'Panel de control',
77
- Remove: 'Quitar',
78
- Quality: 'Calidad',
79
- 'Max dimensions': 'Dimensiones',
80
- 'aspect-ratio': 'relación-aspecto',
81
- 'max-width(px)': 'max. ancho',
82
- 'max-height(px)': 'max. alto',
83
- Format: 'Formato',
84
- Crop: 'Recortar',
85
- 'width(px)': 'ancho(px)',
86
- 'height(px)': 'altura(px)',
87
- };
88
- this.labelFr = {
89
- 'Upload a image': 'Charger une image',
90
- 'You must edit the image in order to resize it': 'Vous devez éditer l\'image pour changer sa taille',
91
- 'too large': 'Trop grande',
92
- 'Open the editor panel': 'Ouvrir le panneau d\'édition',
93
- 'Download the image': 'Télécharger l\'image',
94
- 'Control Panel': 'Panneau de commande',
95
- Remove: 'Supprimer',
96
- Quality: 'Qualité',
97
- 'Max dimensions': 'Dimensions maximales',
98
- 'aspect-ratio': 'rapport de forme',
99
- 'max-width(px)': 'largeur max.',
100
- 'max-height(px)': 'hauteur max',
101
- Format: 'Format',
102
- Crop: 'Recadrer',
103
- 'width(px)': 'largeur(px)',
104
- 'height(px)': 'hauteur(px)',
105
- };
106
- this.arrayCopiedImages = [];
107
- this.config = {
108
- height: '240px',
109
- width: '320px',
110
- borderRadius: '16px',
111
- compressInitial: true,
112
- language: 'en',
113
- hideDeleteBtn: false,
114
- hideDownloadBtn: false,
115
- hideEditBtn: false,
116
- hideAddBtn: false,
117
- };
118
- this.showCrop = false;
119
- this.loadImage = false;
120
- this.uuidFilePicker = Date.now().toString(20);
121
- this.showEditPanel = false;
122
- this.quality = 92;
123
- this.format = 'jpeg';
124
- this.allFormats = ['webp', 'jpeg', 'png'];
125
- this.maxHeight = 2000;
126
- this.maxWidth = 2000;
127
- this.cropHeight = 150;
128
- this.cropWidth = 150;
129
- this.maintainAspectRatio = true;
130
- this.imageName = 'download';
131
- this.appearance = 'outline';
132
- this.color = 'primary';
133
- this.imagesAllowed = 'image/*';
134
- this.$imageChanged = new EventEmitter();
135
- this.$imageOriginal = new EventEmitter();
136
- this.labels = this.labelEn;
137
- }
138
- set _imageSrc(value) {
139
- if (value) {
140
- this.parseToBase64(value).then((dataUri) => {
141
- this.imageSrc = dataUri;
142
- this.arrayCopiedImages = [];
143
- this.arrayCopiedImages.push(this.imageSrc);
144
- this.originImageSrc = value;
145
- this.lastOriginSrc = value;
146
- this.$imageOriginal.next(this.originImageSrc);
147
- this.loadImage = true;
148
- this._cdRef.markForCheck();
149
- });
150
- }
151
- else {
152
- this.imageSrc = null;
153
- this.originImageSrc = null;
154
- this.loadImage = false;
155
- this.arrayCopiedImages = [];
156
- this.lastOriginSrc = null;
157
- this.$imageOriginal.next(null);
158
- this.format = 'jpeg';
159
- this.maxHeight = 2000;
160
- this.maxWidth = 2000;
161
- this.cropHeight = 150;
162
- this.cropWidth = 150;
163
- this.maintainAspectRatio = true;
164
- this.showEditPanel = false;
165
- this._cdRef.markForCheck();
166
- }
167
- }
168
- set _config(value) {
169
- if (value && value.constructor == Object) {
170
- this.config = { ...this.config, ...value };
171
- if (value?.language !== undefined) {
172
- if (value.language === 'en') {
173
- this.labels = { ...this.labelEn };
174
- }
175
- if (value.language === 'es') {
176
- this.labels = { ...this.labelEs };
177
- }
178
- if (value.language === 'fr') {
179
- this.labels = { ...this.labelFr };
180
- }
181
- }
182
- }
183
- }
184
- async handleReaderLoaded(readerEvt) {
185
- const binaryString = readerEvt.target.result;
186
- const base64textString = btoa(binaryString);
187
- this.originImageSrc = this.urlImage + base64textString;
188
- this.lastOriginSrc = this.urlImage + base64textString;
189
- if (this.config?.compressInitial) {
190
- this.quality = 92;
191
- const input = {
192
- dataType: this.format,
193
- quality: 0.92,
194
- maintainRatio: true,
195
- };
196
- this.imageSrc = await this.resizeDataURL(this.urlImage + base64textString, input);
197
- }
198
- else {
199
- this.imageSrc = this.urlImage + base64textString;
200
- this.arrayCopiedImages = [];
201
- this.arrayCopiedImages.push({
202
- lastImage: this.imageSrc,
203
- width: this.maxWidth,
204
- height: this.maxHeight,
205
- quality: this.quality,
206
- });
207
- this.$imageOriginal.next(this.imageSrc);
208
- }
209
- this.$imageChanged.next(this.imageSrc);
210
- this.loadImage = true;
211
- }
212
- parseToBase64(imageUrl) {
213
- let types = imageUrl.split('.');
214
- let type = types[types.length - 1];
215
- if (!type || (type !== 'png' && type !== 'jpeg' && type !== 'webp')) {
216
- type = 'jpeg';
217
- }
218
- this.format = type;
219
- return new Promise((resolve) => {
220
- let img = document.createElement('img');
221
- img.crossOrigin = 'Anonymous';
222
- img.src = imageUrl;
223
- this.maxHeight = img?.height;
224
- this.maxWidth = img?.width;
225
- img.onload = function () {
226
- let canvas = document.createElement('canvas');
227
- let ctx = canvas.getContext('2d');
228
- let ratio = 1.0;
229
- canvas.width = img?.width * ratio;
230
- canvas.height = img?.height * ratio;
231
- ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
232
- let dataURI = canvas.toDataURL(`image/${type}`, 0.92);
233
- return resolve({
234
- dataUri: dataURI,
235
- width: canvas.width,
236
- height: canvas.height,
237
- });
238
- };
239
- }).then((data) => {
240
- this.maxHeight = data?.height;
241
- this.maxWidth = data?.width;
242
- return data?.dataUri;
243
- });
244
- }
245
- async resizeDataURL(datas, input) {
246
- return await new Promise(async function (resolve) {
247
- let img = document.createElement('img');
248
- img.src = datas + '';
249
- img.crossOrigin = 'Anonymous';
250
- let quality = input.quality ? input.quality : 1.0;
251
- let maintainRatio = input.maintainRatio != undefined ? input.maintainRatio : true;
252
- img.onload = function () {
253
- const canvas = document.createElement('canvas');
254
- const ctx = canvas.getContext('2d');
255
- let ratio = img.width / img.height;
256
- let width = input.width ? input.width : img.width;
257
- let height = input.height ? input.height : img.height;
258
- if (maintainRatio) {
259
- if (input.changeHeight) {
260
- canvas.width = height * ratio;
261
- canvas.height = height;
262
- }
263
- else {
264
- canvas.width = width;
265
- canvas.height = width / ratio;
266
- }
267
- }
268
- else {
269
- canvas.width = width;
270
- canvas.height = height;
271
- }
272
- ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
273
- let type = input.dataType ? input.dataType : 'webp';
274
- const dataURI = canvas.toDataURL(`image/${type}`, quality);
275
- resolve({
276
- dataUri: dataURI,
277
- width: canvas.width,
278
- height: canvas.height,
279
- });
280
- };
281
- }).then((data) => {
282
- this.maxHeight = data?.height;
283
- this.maxWidth = data?.width;
284
- if (this.arrayCopiedImages?.length <= 20) {
285
- this.arrayCopiedImages.push({
286
- lastImage: data?.dataUri,
287
- width: this.maxWidth,
288
- height: this.maxHeight,
289
- quality: this.quality,
290
- });
291
- }
292
- return data.dataUri;
293
- });
294
- }
295
- wait(ms) {
296
- ms = ms ? ms : 1000;
297
- return new Promise((resolve) => {
298
- setTimeout(() => {
299
- return resolve(true);
300
- }, ms);
301
- });
302
- }
303
- dragElement(element) {
304
- let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
305
- if (document.getElementById(element.id + '-header')) {
306
- document.getElementById(element.id + '-header').onmousedown = dragMouseDown;
307
- document.getElementById(element.id + '-header').ontouchstart = dragMouseDown;
308
- }
309
- else {
310
- element.onmousedown = dragMouseDown;
311
- element.ontouchstart = dragMouseDown;
312
- }
313
- function dragMouseDown(e) {
314
- e = e || window.event;
315
- e.preventDefault();
316
- pos3 = e.clientX;
317
- pos4 = e.clientY;
318
- document.onmouseup = closeDragElement;
319
- document.ontouchend = closeDragElement;
320
- document.onmousemove = elementDrag;
321
- document.ontouchmove = elementDrag;
322
- }
323
- function elementDrag(e) {
324
- let holderImage = document.getElementById('image-full');
325
- e = e || window.event;
326
- e.preventDefault();
327
- pos1 = pos3 - e.clientX;
328
- pos2 = pos4 - e.clientY;
329
- pos3 = e.clientX;
330
- pos4 = e.clientY;
331
- const newTop = element.offsetTop - pos2;
332
- const newLeft = element.offsetLeft - pos1;
333
- const rectHolder = holderImage.getBoundingClientRect();
334
- const rectElement = element.getBoundingClientRect();
335
- if (newTop >= rectHolder.y + 8) {
336
- element.style.top = Math.min(newTop, rectHolder.y + rectHolder.height - rectElement.height - 4) + 'px';
337
- }
338
- if (newLeft > rectHolder.x + 4 && rectHolder.x + rectHolder.width > rectElement.x + rectElement.width + 2) {
339
- element.style.left = Math.min(newLeft, rectHolder.x + rectHolder.width - rectElement.width - 4) + 'px';
340
- }
341
- }
342
- function closeDragElement() {
343
- document.onmouseup = null;
344
- document.onmousemove = null;
345
- document.ontouchend = null;
346
- document.ontouchmove = null;
347
- }
348
- }
349
- onUpload(event) {
350
- event.preventDefault();
351
- this.imagePicker.nativeElement.click();
352
- }
353
- handleFileSelect(evt) {
354
- const files = evt.target?.files;
355
- if (files) {
356
- const file = files[0];
357
- this.imageName = file.name.split('.')[0];
358
- this.fileType = file.type;
359
- this.urlImage = `data:${file.type};base64,`;
360
- if (files && file) {
361
- const reader = new FileReader();
362
- reader.onload = this.handleReaderLoaded.bind(this);
363
- reader.readAsBinaryString(file);
364
- }
365
- }
366
- }
367
- onCloseEditPanel() {
368
- if (this.observer instanceof ResizeObserver) {
369
- this.observer.unobserve(document.getElementById('image-cropper'));
370
- this.observer.unobserve(document.getElementById('image-full'));
371
- }
372
- this.showCrop = false;
373
- this.showEditPanel = false;
374
- }
375
- async onChangeQuality() {
376
- const qualityItem = this.quality / 100;
377
- this.maxHeight = this.maxHeight && +this.maxHeight ? this.maxHeight : 2000;
378
- this.maxWidth = this.maxWidth && +this.maxWidth ? this.maxWidth : 2000;
379
- await this.wait(250);
380
- try {
381
- const input = {
382
- height: this.maxHeight,
383
- width: this.maxWidth,
384
- dataType: this.format,
385
- quality: qualityItem,
386
- maintainRatio: this.maintainAspectRatio,
387
- };
388
- this.imageSrc = await this.resizeDataURL(this.originImageSrc, input);
389
- this.$imageChanged.next(this.imageSrc);
390
- this.loadImage = true;
391
- }
392
- catch (error) {
393
- this.loadImage = true;
394
- }
395
- }
396
- async onChangeFormat() {
397
- let qualityItem = this.quality / 100;
398
- this.maxHeight = this.maxHeight && +this.maxHeight ? this.maxHeight : 2000;
399
- this.maxWidth = this.maxWidth && +this.maxWidth ? this.maxWidth : 2000;
400
- await this.wait(250);
401
- try {
402
- let input = {
403
- height: this.maxHeight,
404
- width: this.maxWidth,
405
- dataType: this.format,
406
- quality: qualityItem,
407
- maintainRatio: this.maintainAspectRatio,
408
- };
409
- this.imageSrc = await this.resizeDataURL(this.originImageSrc, input);
410
- this.$imageChanged.next(this.imageSrc);
411
- this.loadImage = true;
412
- }
413
- catch (error) {
414
- this.loadImage = true;
415
- }
416
- }
417
- async onChangeSize(changeWidth, changeHeight) {
418
- let qualityItem = this.quality / 100;
419
- this.maxHeight = this.maxHeight && +this.maxHeight ? this.maxHeight : 2000;
420
- this.maxWidth = this.maxWidth && +this.maxWidth ? this.maxWidth : 2000;
421
- await this.wait(500);
422
- try {
423
- let input = {
424
- height: this.maxHeight,
425
- width: this.maxWidth,
426
- dataType: this.format,
427
- quality: qualityItem,
428
- maintainRatio: this.maintainAspectRatio,
429
- changeHeight: changeHeight,
430
- changeWidth: changeWidth,
431
- };
432
- this.imageSrc = await this.resizeDataURL(this.originImageSrc, input);
433
- this.$imageChanged.next(this.imageSrc);
434
- this.loadImage = true;
435
- }
436
- catch (error) {
437
- this.loadImage = true;
438
- }
439
- }
440
- onChangeCrop() {
441
- const cropper = document.getElementById('image-cropper');
442
- cropper.style.width = this.cropWidth + 'px';
443
- cropper.style.height = this.cropHeight + 'px';
444
- }
445
- onCropStateChange() {
446
- const cropper = document.getElementById('image-cropper');
447
- if (this.showCrop) {
448
- cropper.style.opacity = '1.0';
449
- this.dragElement(cropper);
450
- this.observer = new ResizeObserver((entries) => {
451
- entries.forEach((entry) => {
452
- if (this.showEditPanel) {
453
- const elementCropper = document.getElementById('image-cropper');
454
- const rectHolder = document.getElementById('image-full').getBoundingClientRect();
455
- const rectElemnt = elementCropper.getBoundingClientRect();
456
- const maxWidth = rectHolder.x + rectHolder.width - rectElemnt.x - 4;
457
- const maxHeight = rectHolder.y + rectHolder.height - rectElemnt.y - 4;
458
- elementCropper.style.maxWidth = maxWidth + 'px';
459
- elementCropper.style.maxHeight = maxHeight + 'px';
460
- this.cropWidth = rectElemnt.width;
461
- this.cropHeight = rectElemnt.height;
462
- if (entry.target.id == 'image-full') {
463
- if (rectHolder.top > 0) {
464
- elementCropper.style.top = rectHolder.top + 4 + 'px';
465
- }
466
- elementCropper.style.left = rectHolder.left + 4 + 'px';
467
- }
468
- }
469
- });
470
- });
471
- this.observer.observe(document.getElementById('image-cropper'));
472
- this.observer.observe(document.getElementById('image-full'));
473
- }
474
- else {
475
- cropper.style.opacity = '0.0';
476
- if (this.observer instanceof ResizeObserver) {
477
- this.observer.unobserve(document.getElementById('image-cropper'));
478
- this.observer.unobserve(document.getElementById('image-full'));
479
- }
480
- }
481
- }
482
- onCrop(type) {
483
- type = type ? type : this.format;
484
- const cropper = document.getElementById('image-cropper');
485
- const rectCropper = cropper.getBoundingClientRect();
486
- const dataHolderRect = document.getElementById('image-full').getBoundingClientRect();
487
- const canvas = document.createElement('canvas');
488
- new Promise((resolve, reject) => {
489
- let ctx = canvas.getContext('2d');
490
- let image = new Image();
491
- image.src = this.imageSrc;
492
- image.onload = () => {
493
- let ratio = image.height / dataHolderRect.height;
494
- let newWidth = rectCropper.width * ratio;
495
- let newHeight = rectCropper.height * ratio;
496
- canvas.height = newHeight;
497
- canvas.width = newWidth;
498
- ctx.drawImage(image, Math.abs(rectCropper.x * ratio) - Math.abs(dataHolderRect.x * ratio), Math.abs(rectCropper.y * ratio) - Math.abs(dataHolderRect.y * ratio), newWidth, newHeight, 0, 0, newWidth, newHeight);
499
- // ctx.drawImage(image, 90, 130, 50, 60, 10, 10, 50, 60);
500
- resolve(canvas.toDataURL(`image/${type}`, 0.98));
501
- };
502
- image.onerror = (e) => {
503
- reject(e);
504
- };
505
- })
506
- .then((dataUri) => {
507
- this.imageSrc = dataUri;
508
- this.showCrop = false;
509
- this.onCropStateChange();
510
- this.maxWidth = canvas.width;
511
- this.maxHeight = canvas.height;
512
- this.lastOriginSrc = this.originImageSrc + '';
513
- this.originImageSrc = dataUri;
514
- this.$imageChanged.next(this.imageSrc);
515
- })
516
- .catch((e) => {
517
- console.log(e);
518
- });
519
- }
520
- onRestore() {
521
- if (this.arrayCopiedImages.length) {
522
- let lastState = this.arrayCopiedImages.pop();
523
- this.imageSrc = lastState.lastImage;
524
- this.maxWidth = lastState.width;
525
- this.maxHeight = lastState.height;
526
- this.originImageSrc = this.lastOriginSrc + '';
527
- }
528
- else {
529
- this.imageSrc = this.lastOriginSrc;
530
- this.originImageSrc = this.lastOriginSrc + '';
531
- }
532
- this.$imageChanged.next(this.imageSrc);
533
- }
534
- onRemove() {
535
- this.imageSrc = null;
536
- this.originImageSrc = null;
537
- this.loadImage = false;
538
- this.arrayCopiedImages = [];
539
- this.lastOriginSrc = null;
540
- this.$imageOriginal.next(null);
541
- this.$imageChanged.next(null);
542
- this.format = 'jpeg';
543
- this.maxHeight = 2000;
544
- this.maxWidth = 2000;
545
- this.cropHeight = 150;
546
- this.cropWidth = 150;
547
- this.maintainAspectRatio = true;
548
- this.showEditPanel = false;
549
- }
550
- }
551
- GuajiritosImagePickerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: GuajiritosImagePickerComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
552
- GuajiritosImagePickerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.4", type: GuajiritosImagePickerComponent, selector: "guajiritos-image-picker", inputs: { appearance: "appearance", color: "color", imagesAllowed: "imagesAllowed", _imageSrc: "_imageSrc", _config: "_config" }, outputs: { $imageChanged: "$imageChanged", $imageOriginal: "$imageOriginal" }, viewQueries: [{ propertyName: "imagePicker", first: true, predicate: ["imagePicker"], descendants: true }], ngImport: i0, template: "<div *ngIf='!loadImage' class='place-image'>\r\n <div class='image-holder'\r\n [ngStyle]='{ width: config?.width,height: config?.height,borderRadius: config?.borderRadius}'>\r\n <button [matTooltip]=\"labels['Upload a image']\" class='image-upload-btn' mat-icon-button (click)='onUpload($event)'>\r\n <mat-icon class='mat-18'>add_a_photo</mat-icon>\r\n </button>\r\n <input #imagePicker type='file' style='display: none' [id]=\"'filePicker-' + uuidFilePicker\"\r\n (change)='handleFileSelect($event)' [accept]='imagesAllowed'>\r\n </div>\r\n</div>\r\n<div *ngIf='loadImage' class='place-image'>\r\n <div class='image-holder-loaded'\r\n [ngStyle]='{width: config?.width,height: config?.height,borderRadius: config?.borderRadius}'>\r\n <img [src]='imageSrc' alt='image-loaded' [ngStyle]='{ borderRadius: config.borderRadius }'>\r\n <input #imagePicker type='file' style='display: none' [id]=\"'filePicker-' + uuidFilePicker\"\r\n (change)='handleFileSelect($event)' [accept]='imagesAllowed'>\r\n </div>\r\n <p *ngIf='imageSrc?.length' class='mat-caption image-caption'\r\n [ngStyle]=\"{color: (imageSrc?.length | calculateSize) > 120 ? '#f44336' : 'unset',fontWeight: (imageSrc?.length | calculateSize) > 120 ? '500' : 'unset'}\">\r\n size: {{ (imageSrc?.length | calculateSize) }}Kb &nbsp; {{ format }}\r\n </p>\r\n\r\n <div class='editing-bar-btn'\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <button id='upload-img' *ngIf='!config.hideAddBtn' mat-icon-button [matTooltip]=\"labels['Upload a image']\"\r\n (click)='onUpload($event)'>\r\n <mat-icon class='mat-18'>add_a_photo</mat-icon>\r\n </button>\r\n <button id='edit-img' *ngIf='!config.hideEditBtn' mat-icon-button [matTooltip]=\"labels['Open the editor panel']\"\r\n (click)='showEditPanel = true'>\r\n <mat-icon class='mat-18'>edit</mat-icon>\r\n </button>\r\n <a id='download-img' *ngIf='!config.hideDownloadBtn' [matTooltip]=\"labels['Download the image']\"\r\n [href]='imageSrc' mat-icon-button [download]='imageName'>\r\n <mat-icon class='mat-18'>cloud_download</mat-icon>\r\n </a>\r\n <button id='delete-img' *ngIf='!config.hideDeleteBtn' mat-icon-button [matTooltip]=\"labels['Remove']\"\r\n (click)='onRemove()'>\r\n <mat-icon class='mat-18'>delete</mat-icon>\r\n </button>\r\n </div>\r\n</div>\r\n\r\n<div *ngIf='showEditPanel' id='popup' class='popup'>\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: center flex-end; align-items: center'>\r\n <button mat-icon-button (click)='onCloseEditPanel()'>\r\n <mat-icon class='mat-18'>clear</mat-icon>\r\n </button>\r\n </div>\r\n\r\n <div class='image-container'>\r\n <div class='image-holder-full'>\r\n <img id='image-full' [src]='imageSrc' alt=''>\r\n <div id='image-cropper' class='image-cropper'>\r\n <div id='image-cropper-header'>\r\n <mat-icon>drag_indicator</mat-icon>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <div class='control-panel'>\r\n <p class='title-panel'>{{ labels['Control Panel'] }}</p>\r\n\r\n <p class='item-panel'>{{ labels['Quality'] }}</p>\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <mat-slider [color]='color' style='max-width: 100%; width: 100%' (change)='onChangeQuality()'\r\n [(ngModel)]='quality' [min]='0' [max]='100' [step]='1' [thumbLabel]='true'>\r\n </mat-slider>\r\n </div>\r\n\r\n <p class='item-panel'>\r\n {{ labels['Max dimensions'] }}\r\n <mat-checkbox style='float: right' [(ngModel)]='maintainAspectRatio' [color]='color'>\r\n <span class='mat-caption'>{{ labels['aspect-ratio'] }}</span>\r\n </mat-checkbox>\r\n </p>\r\n <div\r\n style='margin-top: 8px !important; flex-flow: row wrap; box-sizing: border-box; display: flex; place-content: flex-start space-between; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['max-width(px)'] }}</mat-label>\r\n <input (change)='onChangeSize(true, false)' matInput [placeholder]=\"labels['max-width(px)']\"\r\n [(ngModel)]='maxWidth' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['max-height(px)'] }}</mat-label>\r\n <input (change)='onChangeSize(false, true)' matInput [placeholder]=\"labels['max-height(px)']\"\r\n [(ngModel)]='maxHeight' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n </div>\r\n\r\n <p class='item-panel'>{{ labels['Format'] }}</p>\r\n <div\r\n style='margin-top: 8px !important; flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 100%; width: 100%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-select [(ngModel)]='format' (selectionChange)='onChangeFormat()'>\r\n <mat-option *ngFor='let format of allFormats' [value]='format'>\r\n {{ format }}\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n\r\n <div>\r\n <mat-checkbox (change)='onCropStateChange()' [(ngModel)]='showCrop' [color]='color'>\r\n <p class='item-panel'>{{ labels['Crop'] }}</p>\r\n </mat-checkbox>\r\n <button style='float: right' mat-icon-button [color]='color' (click)='onRestore()'>\r\n <mat-icon>refresh</mat-icon>\r\n </button>\r\n </div>\r\n\r\n <ng-container *ngIf='showCrop'>\r\n <div\r\n style='margin-top: 8px !important; flex-flow: row wrap; box-sizing: border-box; display: flex; place-content: flex-start space-between; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['width(px)'] }}</mat-label>\r\n <input (change)='onChangeCrop()' matInput [placeholder]=\"labels['width(px)']\"\r\n [(ngModel)]='cropWidth' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['height(px)'] }}</mat-label>\r\n <input (change)='onChangeCrop()' matInput\r\n [placeholder]=\"labels['height(px)']\" [(ngModel)]='cropHeight' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n </div>\r\n\r\n <p style='margin-bottom: 4px !important'>\r\n <button mat-icon-button [color]='color' (click)='onCrop()'>\r\n <mat-icon> crop</mat-icon>\r\n </button>\r\n </p>\r\n </ng-container>\r\n\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: center space-between; align-items: center'>\r\n <button mat-flat-button (click)='onCloseEditPanel()' [color]='color'\r\n style='padding: 0 8px; height: 34px; box-sizing: border-box;'>\r\n Guardar\r\n </button>\r\n\r\n <p *ngIf='imageSrc?.length' class='mat-caption image-caption'\r\n [ngStyle]=\"{color: (imageSrc?.length | calculateSize) > 120 ? '#f44336' : 'unset',fontWeight: (imageSrc?.length | calculateSize) > 120 ? '500' : 'unset'}\">\r\n size: {{ (imageSrc?.length | calculateSize) }}Kb &nbsp; {{ format }}\r\n </p>\r\n </div>\r\n </div>\r\n </div>\r\n</div>\r\n", styles: ["guachos-image-picker p{margin:0!important;padding:0!important}guachos-image-picker .place-image{flex-direction:column;box-sizing:border-box;display:flex;place-content:flex-start;align-items:center}guachos-image-picker .place-image .image-holder{flex-direction:column;box-sizing:border-box;display:flex;place-content:center;align-items:center;position:relative;width:320px;height:240px;border-radius:16px;max-width:100%!important;border:2px rgba(0,0,0,.3) solid;background-color:#fcfcfc}@media (max-width: 599px){guachos-image-picker .place-image .image-holder{max-width:100%!important;max-height:250px!important}}guachos-image-picker .place-image .image-holder .image-upload-btn{transition:all .5s ease;position:relative;opacity:.85;width:50px;height:50px;color:#424242}guachos-image-picker .place-image .image-holder .image-upload-btn mat-icon{font-size:50px;width:50px;height:50px;line-height:50px;color:#424242}@media (max-width: 599px){guachos-image-picker .place-image .image-holder .image-upload-btn{opacity:1;width:30px;height:30px}guachos-image-picker .place-image .image-holder .image-upload-btn mat-icon{font-size:30px;width:30px;height:30px;line-height:30px}}guachos-image-picker .place-image .image-holder:hover .image-upload-btn{opacity:1;transition:all .5s ease}guachos-image-picker .place-image .image-holder-loaded{flex-direction:column;box-sizing:border-box;display:flex;place-content:center;align-items:center;position:relative;max-width:100%!important;width:320px;height:240px;border-radius:4px;padding:2px}guachos-image-picker .place-image .image-holder-loaded .image-caption{position:absolute;right:0;bottom:-22px}guachos-image-picker .place-image .image-holder-loaded img{height:100%;max-height:100%;width:100%;max-width:100%;object-fit:cover;object-position:center}@media (max-width: 599px){guachos-image-picker .place-image .image-holder-loaded{max-height:195px!important}}guachos-image-picker .place-image .image-holder-loaded .image-upload-btn{transition:all .5s ease;position:relative;opacity:.85;width:50px;height:50px;color:#424242}guachos-image-picker .place-image .image-holder-loaded .image-upload-btn mat-icon{font-size:50px;width:50px;height:50px;line-height:50px;color:#424242}@media (max-width: 599px){guachos-image-picker .place-image .image-holder-loaded .image-upload-btn{opacity:1;width:30px;height:30px}guachos-image-picker .place-image .image-holder-loaded .image-upload-btn mat-icon{font-size:30px;width:30px;height:30px;line-height:30px}}guachos-image-picker .place-image .image-holder-loaded:hover .image-upload-btn{opacity:1;transition:all .5s ease}guachos-image-picker .place-image .editing-bar-btn{margin-top:2px}guachos-image-picker .place-image .editing-bar-btn .mat-icon-button{height:20px;line-height:20px;width:24px}guachos-image-picker .place-image .editing-bar-btn mat-icon{line-height:20px!important;font-size:20px!important;width:20px!important;height:20px!important}guachos-image-picker .place-image .editing-bar-btn button{margin:4px;color:#424242;transition:all .5s ease}guachos-image-picker .place-image .editing-bar-btn button:hover{transform:scale(1.25);margin:4px 8px;transition:all .25s ease-in}guachos-image-picker .place-image .editing-bar-btn a{margin:4px;color:#424242;transition:all .5s ease}guachos-image-picker .place-image .editing-bar-btn a:hover{transform:scale(1.25);margin:4px 8px;transition:all .25s ease-in}guachos-image-picker .popup{width:100vw;max-height:100%;height:100%;overflow:auto;position:fixed;top:0;left:0;background-color:#000c;z-index:1000;padding:24px;color:#fff;box-sizing:border-box;animation-name:show;animation-duration:.4s}guachos-image-picker .popup .image-container{margin-top:50px;margin-bottom:50px;height:100%;min-height:100%;min-width:100%;width:100%;flex-flow:row wrap;box-sizing:border-box;display:flex;place-content:flex-start center;align-items:flex-start}guachos-image-picker .popup .image-container .image-holder-full{height:auto;width:auto;position:relative;display:contents}guachos-image-picker .popup img{max-height:600px;max-width:100%;object-fit:cover;object-position:center;margin:8px;transition:all .5s ease}@media (max-width: 1024px){guachos-image-picker .popup{background-color:#000000d9;padding:8px}guachos-image-picker .popup img{max-height:100%;max-width:100%}}@media (max-width: 599px){guachos-image-picker .popup img{margin:0}}guachos-image-picker .popup .control-panel{color:#fff;background-color:#000000eb;margin:8px;padding:16px;max-width:100%;width:18rem;border-radius:8px;flex-direction:column;box-sizing:border-box;display:flex;place-content:stretch flex-start;align-items:stretch}@media (max-width: 599px){guachos-image-picker .popup .control-panel{margin:8px 0;width:100%}}guachos-image-picker .popup .control-panel .title-panel{padding:0 4px;font-size:17px;font-weight:500;margin-bottom:16px!important}guachos-image-picker .popup .control-panel .item-panel{padding:0 4px;font-size:14px;font-weight:500}@keyframes show{0%{top:-100vh;opacity:0}to{top:0;opacity:1}}guachos-image-picker .mat-form-field-appearance-fill .mat-form-field-flex{background-color:#fafafa!important}guachos-image-picker .mat-select-panel{background:#fafafa!important}guachos-image-picker input.mat-input-element{color:#000000d9}guachos-image-picker .mat-checkbox-background{background-color:#fff}guachos-image-picker .image-cropper{position:absolute;width:150px;height:150px;border:2.5px solid #fafafa;box-sizing:border-box;resize:both;overflow:auto;opacity:0}guachos-image-picker .image-cropper #image-cropper-header{padding:10px;cursor:move;z-index:10;background-color:transparent;height:85%}guachos-image-picker .image-cropper #image-cropper-header mat-icon{color:#fff}guachos-image-picker .btn{padding:4px 8px;border-radius:4px;cursor:pointer}guachos-image-picker .btn mat-icon{color:#000000d1}\n"], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i3.MatLegacyButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "component", type: i3.MatLegacyAnchor, selector: "a[mat-button], a[mat-raised-button], a[mat-icon-button], a[mat-fab], a[mat-mini-fab], a[mat-stroked-button], a[mat-flat-button]", inputs: ["disabled", "disableRipple", "color", "tabIndex"], exportAs: ["matButton", "matAnchor"] }, { kind: "directive", type: i4.MatLegacyTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { kind: "component", type: i5.MatLegacySlider, selector: "mat-slider", inputs: ["disabled", "color", "tabIndex", "invert", "max", "min", "step", "thumbLabel", "tickInterval", "value", "displayWith", "valueText", "vertical"], outputs: ["change", "input", "valueChange"], exportAs: ["matSlider"] }, { kind: "directive", type: i6.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i6.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i6.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i6.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i6.MaxValidator, selector: "input[type=number][max][formControlName],input[type=number][max][formControl],input[type=number][max][ngModel]", inputs: ["max"] }, { kind: "directive", type: i6.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i7.MatLegacyFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i7.MatLegacyLabel, selector: "mat-label" }, { kind: "component", type: i8.MatLegacySelect, selector: "mat-select", inputs: ["disabled", "disableRipple", "tabIndex"], exportAs: ["matSelect"] }, { kind: "component", type: i9.MatLegacyOption, selector: "mat-option", exportAs: ["matOption"] }, { kind: "directive", type: i10.MatLegacyInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", exportAs: ["matInput"] }, { kind: "component", type: i11.MatLegacyCheckbox, selector: "mat-checkbox", inputs: ["disableRipple", "color", "tabIndex"], exportAs: ["matCheckbox"] }, { kind: "pipe", type: CalculateSizePipe, name: "calculateSize" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
553
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: GuajiritosImagePickerComponent, decorators: [{
554
- type: Component,
555
- args: [{ selector: 'guajiritos-image-picker', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "<div *ngIf='!loadImage' class='place-image'>\r\n <div class='image-holder'\r\n [ngStyle]='{ width: config?.width,height: config?.height,borderRadius: config?.borderRadius}'>\r\n <button [matTooltip]=\"labels['Upload a image']\" class='image-upload-btn' mat-icon-button (click)='onUpload($event)'>\r\n <mat-icon class='mat-18'>add_a_photo</mat-icon>\r\n </button>\r\n <input #imagePicker type='file' style='display: none' [id]=\"'filePicker-' + uuidFilePicker\"\r\n (change)='handleFileSelect($event)' [accept]='imagesAllowed'>\r\n </div>\r\n</div>\r\n<div *ngIf='loadImage' class='place-image'>\r\n <div class='image-holder-loaded'\r\n [ngStyle]='{width: config?.width,height: config?.height,borderRadius: config?.borderRadius}'>\r\n <img [src]='imageSrc' alt='image-loaded' [ngStyle]='{ borderRadius: config.borderRadius }'>\r\n <input #imagePicker type='file' style='display: none' [id]=\"'filePicker-' + uuidFilePicker\"\r\n (change)='handleFileSelect($event)' [accept]='imagesAllowed'>\r\n </div>\r\n <p *ngIf='imageSrc?.length' class='mat-caption image-caption'\r\n [ngStyle]=\"{color: (imageSrc?.length | calculateSize) > 120 ? '#f44336' : 'unset',fontWeight: (imageSrc?.length | calculateSize) > 120 ? '500' : 'unset'}\">\r\n size: {{ (imageSrc?.length | calculateSize) }}Kb &nbsp; {{ format }}\r\n </p>\r\n\r\n <div class='editing-bar-btn'\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <button id='upload-img' *ngIf='!config.hideAddBtn' mat-icon-button [matTooltip]=\"labels['Upload a image']\"\r\n (click)='onUpload($event)'>\r\n <mat-icon class='mat-18'>add_a_photo</mat-icon>\r\n </button>\r\n <button id='edit-img' *ngIf='!config.hideEditBtn' mat-icon-button [matTooltip]=\"labels['Open the editor panel']\"\r\n (click)='showEditPanel = true'>\r\n <mat-icon class='mat-18'>edit</mat-icon>\r\n </button>\r\n <a id='download-img' *ngIf='!config.hideDownloadBtn' [matTooltip]=\"labels['Download the image']\"\r\n [href]='imageSrc' mat-icon-button [download]='imageName'>\r\n <mat-icon class='mat-18'>cloud_download</mat-icon>\r\n </a>\r\n <button id='delete-img' *ngIf='!config.hideDeleteBtn' mat-icon-button [matTooltip]=\"labels['Remove']\"\r\n (click)='onRemove()'>\r\n <mat-icon class='mat-18'>delete</mat-icon>\r\n </button>\r\n </div>\r\n</div>\r\n\r\n<div *ngIf='showEditPanel' id='popup' class='popup'>\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: center flex-end; align-items: center'>\r\n <button mat-icon-button (click)='onCloseEditPanel()'>\r\n <mat-icon class='mat-18'>clear</mat-icon>\r\n </button>\r\n </div>\r\n\r\n <div class='image-container'>\r\n <div class='image-holder-full'>\r\n <img id='image-full' [src]='imageSrc' alt=''>\r\n <div id='image-cropper' class='image-cropper'>\r\n <div id='image-cropper-header'>\r\n <mat-icon>drag_indicator</mat-icon>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <div class='control-panel'>\r\n <p class='title-panel'>{{ labels['Control Panel'] }}</p>\r\n\r\n <p class='item-panel'>{{ labels['Quality'] }}</p>\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <mat-slider [color]='color' style='max-width: 100%; width: 100%' (change)='onChangeQuality()'\r\n [(ngModel)]='quality' [min]='0' [max]='100' [step]='1' [thumbLabel]='true'>\r\n </mat-slider>\r\n </div>\r\n\r\n <p class='item-panel'>\r\n {{ labels['Max dimensions'] }}\r\n <mat-checkbox style='float: right' [(ngModel)]='maintainAspectRatio' [color]='color'>\r\n <span class='mat-caption'>{{ labels['aspect-ratio'] }}</span>\r\n </mat-checkbox>\r\n </p>\r\n <div\r\n style='margin-top: 8px !important; flex-flow: row wrap; box-sizing: border-box; display: flex; place-content: flex-start space-between; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['max-width(px)'] }}</mat-label>\r\n <input (change)='onChangeSize(true, false)' matInput [placeholder]=\"labels['max-width(px)']\"\r\n [(ngModel)]='maxWidth' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['max-height(px)'] }}</mat-label>\r\n <input (change)='onChangeSize(false, true)' matInput [placeholder]=\"labels['max-height(px)']\"\r\n [(ngModel)]='maxHeight' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n </div>\r\n\r\n <p class='item-panel'>{{ labels['Format'] }}</p>\r\n <div\r\n style='margin-top: 8px !important; flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 100%; width: 100%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-select [(ngModel)]='format' (selectionChange)='onChangeFormat()'>\r\n <mat-option *ngFor='let format of allFormats' [value]='format'>\r\n {{ format }}\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n\r\n <div>\r\n <mat-checkbox (change)='onCropStateChange()' [(ngModel)]='showCrop' [color]='color'>\r\n <p class='item-panel'>{{ labels['Crop'] }}</p>\r\n </mat-checkbox>\r\n <button style='float: right' mat-icon-button [color]='color' (click)='onRestore()'>\r\n <mat-icon>refresh</mat-icon>\r\n </button>\r\n </div>\r\n\r\n <ng-container *ngIf='showCrop'>\r\n <div\r\n style='margin-top: 8px !important; flex-flow: row wrap; box-sizing: border-box; display: flex; place-content: flex-start space-between; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['width(px)'] }}</mat-label>\r\n <input (change)='onChangeCrop()' matInput [placeholder]=\"labels['width(px)']\"\r\n [(ngModel)]='cropWidth' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['height(px)'] }}</mat-label>\r\n <input (change)='onChangeCrop()' matInput\r\n [placeholder]=\"labels['height(px)']\" [(ngModel)]='cropHeight' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n </div>\r\n\r\n <p style='margin-bottom: 4px !important'>\r\n <button mat-icon-button [color]='color' (click)='onCrop()'>\r\n <mat-icon> crop</mat-icon>\r\n </button>\r\n </p>\r\n </ng-container>\r\n\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: center space-between; align-items: center'>\r\n <button mat-flat-button (click)='onCloseEditPanel()' [color]='color'\r\n style='padding: 0 8px; height: 34px; box-sizing: border-box;'>\r\n Guardar\r\n </button>\r\n\r\n <p *ngIf='imageSrc?.length' class='mat-caption image-caption'\r\n [ngStyle]=\"{color: (imageSrc?.length | calculateSize) > 120 ? '#f44336' : 'unset',fontWeight: (imageSrc?.length | calculateSize) > 120 ? '500' : 'unset'}\">\r\n size: {{ (imageSrc?.length | calculateSize) }}Kb &nbsp; {{ format }}\r\n </p>\r\n </div>\r\n </div>\r\n </div>\r\n</div>\r\n", styles: ["guachos-image-picker p{margin:0!important;padding:0!important}guachos-image-picker .place-image{flex-direction:column;box-sizing:border-box;display:flex;place-content:flex-start;align-items:center}guachos-image-picker .place-image .image-holder{flex-direction:column;box-sizing:border-box;display:flex;place-content:center;align-items:center;position:relative;width:320px;height:240px;border-radius:16px;max-width:100%!important;border:2px rgba(0,0,0,.3) solid;background-color:#fcfcfc}@media (max-width: 599px){guachos-image-picker .place-image .image-holder{max-width:100%!important;max-height:250px!important}}guachos-image-picker .place-image .image-holder .image-upload-btn{transition:all .5s ease;position:relative;opacity:.85;width:50px;height:50px;color:#424242}guachos-image-picker .place-image .image-holder .image-upload-btn mat-icon{font-size:50px;width:50px;height:50px;line-height:50px;color:#424242}@media (max-width: 599px){guachos-image-picker .place-image .image-holder .image-upload-btn{opacity:1;width:30px;height:30px}guachos-image-picker .place-image .image-holder .image-upload-btn mat-icon{font-size:30px;width:30px;height:30px;line-height:30px}}guachos-image-picker .place-image .image-holder:hover .image-upload-btn{opacity:1;transition:all .5s ease}guachos-image-picker .place-image .image-holder-loaded{flex-direction:column;box-sizing:border-box;display:flex;place-content:center;align-items:center;position:relative;max-width:100%!important;width:320px;height:240px;border-radius:4px;padding:2px}guachos-image-picker .place-image .image-holder-loaded .image-caption{position:absolute;right:0;bottom:-22px}guachos-image-picker .place-image .image-holder-loaded img{height:100%;max-height:100%;width:100%;max-width:100%;object-fit:cover;object-position:center}@media (max-width: 599px){guachos-image-picker .place-image .image-holder-loaded{max-height:195px!important}}guachos-image-picker .place-image .image-holder-loaded .image-upload-btn{transition:all .5s ease;position:relative;opacity:.85;width:50px;height:50px;color:#424242}guachos-image-picker .place-image .image-holder-loaded .image-upload-btn mat-icon{font-size:50px;width:50px;height:50px;line-height:50px;color:#424242}@media (max-width: 599px){guachos-image-picker .place-image .image-holder-loaded .image-upload-btn{opacity:1;width:30px;height:30px}guachos-image-picker .place-image .image-holder-loaded .image-upload-btn mat-icon{font-size:30px;width:30px;height:30px;line-height:30px}}guachos-image-picker .place-image .image-holder-loaded:hover .image-upload-btn{opacity:1;transition:all .5s ease}guachos-image-picker .place-image .editing-bar-btn{margin-top:2px}guachos-image-picker .place-image .editing-bar-btn .mat-icon-button{height:20px;line-height:20px;width:24px}guachos-image-picker .place-image .editing-bar-btn mat-icon{line-height:20px!important;font-size:20px!important;width:20px!important;height:20px!important}guachos-image-picker .place-image .editing-bar-btn button{margin:4px;color:#424242;transition:all .5s ease}guachos-image-picker .place-image .editing-bar-btn button:hover{transform:scale(1.25);margin:4px 8px;transition:all .25s ease-in}guachos-image-picker .place-image .editing-bar-btn a{margin:4px;color:#424242;transition:all .5s ease}guachos-image-picker .place-image .editing-bar-btn a:hover{transform:scale(1.25);margin:4px 8px;transition:all .25s ease-in}guachos-image-picker .popup{width:100vw;max-height:100%;height:100%;overflow:auto;position:fixed;top:0;left:0;background-color:#000c;z-index:1000;padding:24px;color:#fff;box-sizing:border-box;animation-name:show;animation-duration:.4s}guachos-image-picker .popup .image-container{margin-top:50px;margin-bottom:50px;height:100%;min-height:100%;min-width:100%;width:100%;flex-flow:row wrap;box-sizing:border-box;display:flex;place-content:flex-start center;align-items:flex-start}guachos-image-picker .popup .image-container .image-holder-full{height:auto;width:auto;position:relative;display:contents}guachos-image-picker .popup img{max-height:600px;max-width:100%;object-fit:cover;object-position:center;margin:8px;transition:all .5s ease}@media (max-width: 1024px){guachos-image-picker .popup{background-color:#000000d9;padding:8px}guachos-image-picker .popup img{max-height:100%;max-width:100%}}@media (max-width: 599px){guachos-image-picker .popup img{margin:0}}guachos-image-picker .popup .control-panel{color:#fff;background-color:#000000eb;margin:8px;padding:16px;max-width:100%;width:18rem;border-radius:8px;flex-direction:column;box-sizing:border-box;display:flex;place-content:stretch flex-start;align-items:stretch}@media (max-width: 599px){guachos-image-picker .popup .control-panel{margin:8px 0;width:100%}}guachos-image-picker .popup .control-panel .title-panel{padding:0 4px;font-size:17px;font-weight:500;margin-bottom:16px!important}guachos-image-picker .popup .control-panel .item-panel{padding:0 4px;font-size:14px;font-weight:500}@keyframes show{0%{top:-100vh;opacity:0}to{top:0;opacity:1}}guachos-image-picker .mat-form-field-appearance-fill .mat-form-field-flex{background-color:#fafafa!important}guachos-image-picker .mat-select-panel{background:#fafafa!important}guachos-image-picker input.mat-input-element{color:#000000d9}guachos-image-picker .mat-checkbox-background{background-color:#fff}guachos-image-picker .image-cropper{position:absolute;width:150px;height:150px;border:2.5px solid #fafafa;box-sizing:border-box;resize:both;overflow:auto;opacity:0}guachos-image-picker .image-cropper #image-cropper-header{padding:10px;cursor:move;z-index:10;background-color:transparent;height:85%}guachos-image-picker .image-cropper #image-cropper-header mat-icon{color:#fff}guachos-image-picker .btn{padding:4px 8px;border-radius:4px;cursor:pointer}guachos-image-picker .btn mat-icon{color:#000000d1}\n"] }]
556
- }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { appearance: [{
557
- type: Input
558
- }], color: [{
559
- type: Input
560
- }], imagesAllowed: [{
561
- type: Input
562
- }], imagePicker: [{
563
- type: ViewChild,
564
- args: ['imagePicker', { static: false }]
565
- }], $imageChanged: [{
566
- type: Output
567
- }], $imageOriginal: [{
568
- type: Output
569
- }], _imageSrc: [{
570
- type: Input
571
- }], _config: [{
572
- type: Input
573
- }] } });
574
-
575
- class GuajiritosImagePickerModule {
576
- }
577
- GuajiritosImagePickerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: GuajiritosImagePickerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
578
- GuajiritosImagePickerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.4", ngImport: i0, type: GuajiritosImagePickerModule, declarations: [GuajiritosImagePickerComponent, CalculateSizePipe], imports: [CommonModule,
579
- MatIconModule,
580
- MatLegacyButtonModule,
581
- MatLegacyTooltipModule,
582
- MatLegacySliderModule,
583
- FormsModule,
584
- ReactiveFormsModule,
585
- MatLegacyFormFieldModule,
586
- MatLegacySelectModule,
587
- MatLegacyInputModule,
588
- MatLegacyCheckboxModule], exports: [GuajiritosImagePickerComponent] });
589
- GuajiritosImagePickerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: GuajiritosImagePickerModule, imports: [CommonModule,
590
- MatIconModule,
591
- MatLegacyButtonModule,
592
- MatLegacyTooltipModule,
593
- MatLegacySliderModule,
594
- FormsModule,
595
- ReactiveFormsModule,
596
- MatLegacyFormFieldModule,
597
- MatLegacySelectModule,
598
- MatLegacyInputModule,
599
- MatLegacyCheckboxModule] });
600
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: GuajiritosImagePickerModule, decorators: [{
601
- type: NgModule,
602
- args: [{
603
- declarations: [GuajiritosImagePickerComponent, CalculateSizePipe],
604
- imports: [
605
- CommonModule,
606
- MatIconModule,
607
- MatLegacyButtonModule,
608
- MatLegacyTooltipModule,
609
- MatLegacySliderModule,
610
- FormsModule,
611
- ReactiveFormsModule,
612
- MatLegacyFormFieldModule,
613
- MatLegacySelectModule,
614
- MatLegacyInputModule,
615
- MatLegacyCheckboxModule,
616
- ],
617
- exports: [GuajiritosImagePickerComponent],
618
- }]
48
+ class CalculateSizeModule {
49
+ }
50
+ CalculateSizeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.3", ngImport: i0, type: CalculateSizeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
51
+ CalculateSizeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.3", ngImport: i0, type: CalculateSizeModule, declarations: [CalculateSizePipe], exports: [CalculateSizePipe] });
52
+ CalculateSizeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.3", ngImport: i0, type: CalculateSizeModule });
53
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.3", ngImport: i0, type: CalculateSizeModule, decorators: [{
54
+ type: NgModule,
55
+ args: [{
56
+ declarations: [CalculateSizePipe],
57
+ exports: [CalculateSizePipe],
58
+ }]
619
59
  }] });
620
60
 
621
- /*
622
- * Public API Surface of guachos-image-picker
61
+ class GuajiritosImagePicker {
62
+ constructor(_cdRef) {
63
+ this._cdRef = _cdRef;
64
+ this.unsubscribeAll$ = new Subject();
65
+ this.observer = null;
66
+ this.labelEn = {
67
+ 'Upload a image': 'Upload a image',
68
+ 'You must edit the image in order to resize it': 'You must edit the image in order to resize it',
69
+ 'too large': 'too large',
70
+ 'Open the editor panel': 'Open the editor panel',
71
+ 'Download the image': 'Download the image',
72
+ 'Control Panel': 'Control Panel',
73
+ Quality: 'Quality',
74
+ 'Max dimensions': 'Max dimensions',
75
+ 'aspect-ratio': 'aspect-ratio',
76
+ 'max-width(px)': 'max-width(px)',
77
+ 'max-height(px)': 'max-height(px)',
78
+ Format: 'Format',
79
+ Crop: 'Crop',
80
+ 'width(px)': 'width(px)',
81
+ 'height(px)': 'height(px)',
82
+ Remove: 'Remove',
83
+ };
84
+ this.labelEs = {
85
+ 'Upload a image': 'Suba una imagen',
86
+ 'You must edit the image in order to resize it': 'Debe editar la imagen para disminuir su tamaño',
87
+ 'too large': 'muy grande',
88
+ 'Open the editor panel': 'Abra el panel de edición',
89
+ 'Download the image': 'Descargue la imagen',
90
+ 'Control Panel': 'Panel de control',
91
+ Remove: 'Quitar',
92
+ Quality: 'Calidad',
93
+ 'Max dimensions': 'Dimensiones',
94
+ 'aspect-ratio': 'relación-aspecto',
95
+ 'max-width(px)': 'max. ancho',
96
+ 'max-height(px)': 'max. alto',
97
+ Format: 'Formato',
98
+ Crop: 'Recortar',
99
+ 'width(px)': 'ancho(px)',
100
+ 'height(px)': 'altura(px)',
101
+ };
102
+ this.labelFr = {
103
+ 'Upload a image': 'Charger une image',
104
+ 'You must edit the image in order to resize it': 'Vous devez éditer l\'image pour changer sa taille',
105
+ 'too large': 'Trop grande',
106
+ 'Open the editor panel': 'Ouvrir le panneau d\'édition',
107
+ 'Download the image': 'Télécharger l\'image',
108
+ 'Control Panel': 'Panneau de commande',
109
+ Remove: 'Supprimer',
110
+ Quality: 'Qualité',
111
+ 'Max dimensions': 'Dimensions maximales',
112
+ 'aspect-ratio': 'rapport de forme',
113
+ 'max-width(px)': 'largeur max.',
114
+ 'max-height(px)': 'hauteur max',
115
+ Format: 'Format',
116
+ Crop: 'Recadrer',
117
+ 'width(px)': 'largeur(px)',
118
+ 'height(px)': 'hauteur(px)',
119
+ };
120
+ this.arrayCopiedImages = [];
121
+ this.config = {
122
+ height: '240px',
123
+ width: '320px',
124
+ borderRadius: '16px',
125
+ compressInitial: true,
126
+ language: 'en',
127
+ hideDeleteBtn: false,
128
+ hideDownloadBtn: false,
129
+ hideEditBtn: false,
130
+ hideAddBtn: false,
131
+ };
132
+ this.showCrop = false;
133
+ this.loadImage = false;
134
+ this.uuidFilePicker = Date.now().toString(20);
135
+ this.showEditPanel = false;
136
+ this.quality = 92;
137
+ this.format = 'jpeg';
138
+ this.allFormats = ['webp', 'jpeg', 'png'];
139
+ this.maxHeight = 2000;
140
+ this.maxWidth = 2000;
141
+ this.cropHeight = 150;
142
+ this.cropWidth = 150;
143
+ this.maintainAspectRatio = true;
144
+ this.imageName = 'download';
145
+ this.appearance = 'outline';
146
+ this.color = 'primary';
147
+ this.imagesAllowed = 'image/*';
148
+ this.$imageChanged = new EventEmitter();
149
+ this.$imageOriginal = new EventEmitter();
150
+ this.labels = this.labelEn;
151
+ }
152
+ set _imageSrc(image) {
153
+ if (image) {
154
+ let types = image.split('.');
155
+ this.format = types[types.length - 1];
156
+ if (!this.format || (this.format !== 'png' && this.format !== 'jpeg' && this.format !== 'webp')) {
157
+ this.format = 'jpeg';
158
+ }
159
+ this.imageSrc = image;
160
+ this.arrayCopiedImages = [];
161
+ this.arrayCopiedImages.push(this.imageSrc);
162
+ this.originImageSrc = image;
163
+ this.lastOriginSrc = image;
164
+ this.$imageOriginal.next(this.originImageSrc);
165
+ this.loadImage = true;
166
+ this._cdRef.markForCheck();
167
+ }
168
+ else {
169
+ this.imageSrc = null;
170
+ this.originImageSrc = null;
171
+ this.loadImage = false;
172
+ this.arrayCopiedImages = [];
173
+ this.lastOriginSrc = null;
174
+ this.$imageOriginal.next(null);
175
+ this.format = 'jpeg';
176
+ this.maxHeight = 2000;
177
+ this.maxWidth = 2000;
178
+ this.cropHeight = 150;
179
+ this.cropWidth = 150;
180
+ this.maintainAspectRatio = true;
181
+ this.showEditPanel = false;
182
+ this._cdRef.markForCheck();
183
+ }
184
+ }
185
+ set _config(value) {
186
+ if (value && value.constructor == Object) {
187
+ this.config = { ...this.config, ...value };
188
+ if (value?.language !== undefined) {
189
+ if (value.language === 'en') {
190
+ this.labels = { ...this.labelEn };
191
+ }
192
+ if (value.language === 'es') {
193
+ this.labels = { ...this.labelEs };
194
+ }
195
+ if (value.language === 'fr') {
196
+ this.labels = { ...this.labelFr };
197
+ }
198
+ }
199
+ }
200
+ }
201
+ async handleReaderLoaded(readerEvt) {
202
+ const binaryString = readerEvt.target.result;
203
+ const base64textString = btoa(binaryString);
204
+ this.originImageSrc = this.urlImage + base64textString;
205
+ this.lastOriginSrc = this.urlImage + base64textString;
206
+ if (this.config?.compressInitial) {
207
+ this.quality = 92;
208
+ const input = {
209
+ dataType: this.format,
210
+ quality: 0.92,
211
+ maintainRatio: true,
212
+ };
213
+ this.imageSrc = await this.resizeDataURL(this.urlImage + base64textString, input);
214
+ }
215
+ else {
216
+ this.imageSrc = this.urlImage + base64textString;
217
+ this.arrayCopiedImages = [];
218
+ this.arrayCopiedImages.push({
219
+ lastImage: this.imageSrc,
220
+ width: this.maxWidth,
221
+ height: this.maxHeight,
222
+ quality: this.quality,
223
+ });
224
+ this.$imageOriginal.next(this.imageSrc);
225
+ }
226
+ this.$imageChanged.next(this.imageSrc);
227
+ this.loadImage = true;
228
+ }
229
+ async resizeDataURL(datas, input) {
230
+ return await new Promise(async function (resolve) {
231
+ let img = document.createElement('img');
232
+ img.src = datas + '';
233
+ img.crossOrigin = 'Anonymous';
234
+ let quality = input.quality ? input.quality : 1.0;
235
+ let maintainRatio = input.maintainRatio != undefined ? input.maintainRatio : true;
236
+ img.onload = function () {
237
+ const canvas = document.createElement('canvas');
238
+ const ctx = canvas.getContext('2d');
239
+ let ratio = img.width / img.height;
240
+ let width = input.width ? input.width : img.width;
241
+ let height = input.height ? input.height : img.height;
242
+ if (maintainRatio) {
243
+ if (input.changeHeight) {
244
+ canvas.width = height * ratio;
245
+ canvas.height = height;
246
+ }
247
+ else {
248
+ canvas.width = width;
249
+ canvas.height = width / ratio;
250
+ }
251
+ }
252
+ else {
253
+ canvas.width = width;
254
+ canvas.height = height;
255
+ }
256
+ ctx?.drawImage(img, 0, 0, canvas.width, canvas.height);
257
+ let type = input.dataType ? input.dataType : 'webp';
258
+ const dataURI = canvas.toDataURL(`image/${type}`, quality);
259
+ resolve({
260
+ dataUri: dataURI,
261
+ width: canvas.width,
262
+ height: canvas.height,
263
+ });
264
+ };
265
+ }).then((data) => {
266
+ this.maxHeight = data?.height;
267
+ this.maxWidth = data?.width;
268
+ if (this.arrayCopiedImages?.length <= 20) {
269
+ this.arrayCopiedImages.push({
270
+ lastImage: data?.dataUri,
271
+ width: this.maxWidth,
272
+ height: this.maxHeight,
273
+ quality: this.quality,
274
+ });
275
+ }
276
+ return data.dataUri;
277
+ });
278
+ }
279
+ wait(ms) {
280
+ ms = ms ? ms : 1000;
281
+ return new Promise((resolve) => {
282
+ setTimeout(() => {
283
+ return resolve(true);
284
+ }, ms);
285
+ });
286
+ }
287
+ dragElement(element) {
288
+ let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
289
+ let el = document.getElementById(element.id + '-header');
290
+ if (el) {
291
+ el.onmousedown = dragMouseDown;
292
+ el.ontouchstart = dragMouseDown;
293
+ }
294
+ else {
295
+ element.onmousedown = dragMouseDown;
296
+ element.ontouchstart = dragMouseDown;
297
+ }
298
+ function dragMouseDown(e) {
299
+ e = e || window.event;
300
+ e?.preventDefault();
301
+ pos3 = e?.clientX;
302
+ pos4 = e?.clientY;
303
+ document.onmouseup = closeDragElement;
304
+ document.ontouchend = closeDragElement;
305
+ document.onmousemove = elementDrag;
306
+ document.ontouchmove = elementDrag;
307
+ }
308
+ function elementDrag(e) {
309
+ let holderImage = document.getElementById('image-full');
310
+ e = e || window.event;
311
+ e?.preventDefault();
312
+ pos1 = pos3 - e?.clientX;
313
+ pos2 = pos4 - e?.clientY;
314
+ pos3 = e?.clientX;
315
+ pos4 = e?.clientY;
316
+ const newTop = element.offsetTop - pos2;
317
+ const newLeft = element.offsetLeft - pos1;
318
+ const rectHolder = holderImage.getBoundingClientRect();
319
+ const rectElement = element.getBoundingClientRect();
320
+ if (newTop >= rectHolder.y + 8) {
321
+ element.style.top = Math.min(newTop, rectHolder.y + rectHolder.height - rectElement.height - 4) + 'px';
322
+ }
323
+ if (newLeft > rectHolder.x + 4 && rectHolder.x + rectHolder.width > rectElement.x + rectElement.width + 2) {
324
+ element.style.left = Math.min(newLeft, rectHolder.x + rectHolder.width - rectElement.width - 4) + 'px';
325
+ }
326
+ }
327
+ function closeDragElement() {
328
+ document.onmouseup = null;
329
+ document.onmousemove = null;
330
+ document.ontouchend = null;
331
+ document.ontouchmove = null;
332
+ }
333
+ }
334
+ onUpload(event) {
335
+ event.preventDefault();
336
+ this.imagePicker?.nativeElement.click();
337
+ }
338
+ handleFileSelect(evt) {
339
+ const files = evt.target?.files;
340
+ if (files) {
341
+ const file = files[0];
342
+ this.imageName = file.name.split('.')[0];
343
+ this.fileType = file.type;
344
+ this.urlImage = `data:${file.type};base64,`;
345
+ if (files && file) {
346
+ const reader = new FileReader();
347
+ reader.onload = this.handleReaderLoaded.bind(this);
348
+ reader.readAsBinaryString(file);
349
+ }
350
+ }
351
+ }
352
+ onCloseEditPanel() {
353
+ if (this.observer instanceof ResizeObserver) {
354
+ let imageCropper = document.getElementById('image-cropper');
355
+ let imageFull = document.getElementById('image-full');
356
+ this.observer.unobserve(imageCropper);
357
+ this.observer.unobserve(imageFull);
358
+ }
359
+ this.showCrop = false;
360
+ this.showEditPanel = false;
361
+ }
362
+ async onChangeQuality() {
363
+ const qualityItem = this.quality / 100;
364
+ this.maxHeight = this.maxHeight && +this.maxHeight ? this.maxHeight : 2000;
365
+ this.maxWidth = this.maxWidth && +this.maxWidth ? this.maxWidth : 2000;
366
+ await this.wait(250);
367
+ try {
368
+ const input = {
369
+ height: this.maxHeight,
370
+ width: this.maxWidth,
371
+ dataType: this.format,
372
+ quality: qualityItem,
373
+ maintainRatio: this.maintainAspectRatio,
374
+ };
375
+ this.imageSrc = await this.resizeDataURL(this.originImageSrc, input);
376
+ this.$imageChanged.next(this.imageSrc);
377
+ this.loadImage = true;
378
+ }
379
+ catch (error) {
380
+ this.loadImage = true;
381
+ }
382
+ }
383
+ async onChangeFormat() {
384
+ let qualityItem = this.quality / 100;
385
+ this.maxHeight = this.maxHeight && +this.maxHeight ? this.maxHeight : 2000;
386
+ this.maxWidth = this.maxWidth && +this.maxWidth ? this.maxWidth : 2000;
387
+ await this.wait(250);
388
+ try {
389
+ let input = {
390
+ height: this.maxHeight,
391
+ width: this.maxWidth,
392
+ dataType: this.format,
393
+ quality: qualityItem,
394
+ maintainRatio: this.maintainAspectRatio,
395
+ };
396
+ this.imageSrc = await this.resizeDataURL(this.originImageSrc, input);
397
+ this.$imageChanged.next(this.imageSrc);
398
+ this.loadImage = true;
399
+ }
400
+ catch (error) {
401
+ this.loadImage = true;
402
+ }
403
+ }
404
+ async onChangeSize(changeWidth, changeHeight) {
405
+ let qualityItem = this.quality / 100;
406
+ this.maxHeight = this.maxHeight && +this.maxHeight ? this.maxHeight : 2000;
407
+ this.maxWidth = this.maxWidth && +this.maxWidth ? this.maxWidth : 2000;
408
+ await this.wait(500);
409
+ try {
410
+ let input = {
411
+ height: this.maxHeight,
412
+ width: this.maxWidth,
413
+ dataType: this.format,
414
+ quality: qualityItem,
415
+ maintainRatio: this.maintainAspectRatio,
416
+ changeHeight: changeHeight,
417
+ changeWidth: changeWidth,
418
+ };
419
+ this.imageSrc = await this.resizeDataURL(this.originImageSrc, input);
420
+ this.$imageChanged.next(this.imageSrc);
421
+ this.loadImage = true;
422
+ }
423
+ catch (error) {
424
+ this.loadImage = true;
425
+ }
426
+ }
427
+ onChangeCrop() {
428
+ const cropper = document.getElementById('image-cropper');
429
+ cropper.style.width = this.cropWidth + 'px';
430
+ cropper.style.height = this.cropHeight + 'px';
431
+ }
432
+ onCropStateChange() {
433
+ const cropper = document.getElementById('image-cropper');
434
+ if (this.showCrop) {
435
+ cropper.style.opacity = '1.0';
436
+ this.dragElement(cropper);
437
+ this.observer = new ResizeObserver((entries) => {
438
+ entries.forEach((entry) => {
439
+ if (this.showEditPanel) {
440
+ const elementCropper = document.getElementById('image-cropper');
441
+ const elementFull = document.getElementById('image-full');
442
+ const rectHolder = elementFull.getBoundingClientRect();
443
+ const rectElement = elementCropper.getBoundingClientRect();
444
+ const maxWidth = rectHolder.x + rectHolder.width - rectElement.x - 4;
445
+ const maxHeight = rectHolder.y + rectHolder.height - rectElement.y - 4;
446
+ elementCropper.style.maxWidth = maxWidth + 'px';
447
+ elementCropper.style.maxHeight = maxHeight + 'px';
448
+ this.cropWidth = rectElement.width;
449
+ this.cropHeight = rectElement.height;
450
+ if (entry.target.id == 'image-full') {
451
+ if (rectHolder.top > 0) {
452
+ elementCropper.style.top = rectHolder.top + 4 + 'px';
453
+ }
454
+ elementCropper.style.left = rectHolder.left + 4 + 'px';
455
+ }
456
+ }
457
+ });
458
+ });
459
+ this.observer.observe(document.getElementById('image-cropper'));
460
+ this.observer.observe(document.getElementById('image-full'));
461
+ }
462
+ else {
463
+ cropper.style.opacity = '0.0';
464
+ if (this.observer instanceof ResizeObserver) {
465
+ const elementCropper = document.getElementById('image-cropper');
466
+ const elementFull = document.getElementById('image-full');
467
+ this.observer.unobserve(elementCropper);
468
+ this.observer.unobserve(elementFull);
469
+ }
470
+ }
471
+ }
472
+ onCrop(type) {
473
+ type = type ? type : this.format;
474
+ const cropper = document.getElementById('image-cropper');
475
+ const elementFull = document.getElementById('image-full');
476
+ const rectCropper = cropper.getBoundingClientRect();
477
+ const dataHolderRect = elementFull.getBoundingClientRect();
478
+ const canvas = document.createElement('canvas');
479
+ new Promise((resolve, reject) => {
480
+ let ctx = canvas.getContext('2d');
481
+ let image = new Image();
482
+ image.src = this.imageSrc;
483
+ image.onload = () => {
484
+ let ratio = image.height / dataHolderRect.height;
485
+ let newWidth = rectCropper.width * ratio;
486
+ let newHeight = rectCropper.height * ratio;
487
+ canvas.height = newHeight;
488
+ canvas.width = newWidth;
489
+ ctx?.drawImage(image, Math.abs(rectCropper.x * ratio) - Math.abs(dataHolderRect.x * ratio), Math.abs(rectCropper.y * ratio) - Math.abs(dataHolderRect.y * ratio), newWidth, newHeight, 0, 0, newWidth, newHeight);
490
+ // ctx.drawImage(image, 90, 130, 50, 60, 10, 10, 50, 60);
491
+ resolve(canvas.toDataURL(`image/${type}`, 0.98));
492
+ };
493
+ image.onerror = (e) => {
494
+ reject(e);
495
+ };
496
+ })
497
+ .then((dataUri) => {
498
+ this.imageSrc = dataUri;
499
+ this.showCrop = false;
500
+ this.onCropStateChange();
501
+ this.maxWidth = canvas.width;
502
+ this.maxHeight = canvas.height;
503
+ this.lastOriginSrc = this.originImageSrc + '';
504
+ this.originImageSrc = dataUri;
505
+ this.$imageChanged.next(this.imageSrc);
506
+ })
507
+ .catch((e) => {
508
+ console.log(e);
509
+ });
510
+ }
511
+ onRestore() {
512
+ if (this.arrayCopiedImages.length) {
513
+ let lastState = this.arrayCopiedImages.pop();
514
+ this.imageSrc = lastState.lastImage;
515
+ this.maxWidth = lastState.width;
516
+ this.maxHeight = lastState.height;
517
+ this.originImageSrc = this.lastOriginSrc + '';
518
+ }
519
+ else {
520
+ this.imageSrc = this.lastOriginSrc;
521
+ this.originImageSrc = this.lastOriginSrc + '';
522
+ }
523
+ this.$imageChanged.next(this.imageSrc);
524
+ }
525
+ onRemove() {
526
+ this.imageSrc = null;
527
+ this.originImageSrc = null;
528
+ this.loadImage = false;
529
+ this.arrayCopiedImages = [];
530
+ this.lastOriginSrc = null;
531
+ this.$imageOriginal.next(null);
532
+ this.$imageChanged.next(null);
533
+ this.format = 'jpeg';
534
+ this.maxHeight = 2000;
535
+ this.maxWidth = 2000;
536
+ this.cropHeight = 150;
537
+ this.cropWidth = 150;
538
+ this.maintainAspectRatio = true;
539
+ this.showEditPanel = false;
540
+ }
541
+ ngOnDestroy() {
542
+ this.unsubscribeAll$.next();
543
+ this.unsubscribeAll$.complete();
544
+ }
545
+ }
546
+ GuajiritosImagePicker.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.3", ngImport: i0, type: GuajiritosImagePicker, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
547
+ GuajiritosImagePicker.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.3", type: GuajiritosImagePicker, isStandalone: true, selector: "guajiritos-image-picker", inputs: { appearance: "appearance", color: "color", imagesAllowed: "imagesAllowed", _imageSrc: "_imageSrc", _config: "_config" }, outputs: { $imageChanged: "$imageChanged", $imageOriginal: "$imageOriginal" }, viewQueries: [{ propertyName: "imagePicker", first: true, predicate: ["imagePicker"], descendants: true }], ngImport: i0, template: "<div *ngIf='!loadImage' class='place-image'>\r\n <div class='image-holder'\r\n [ngStyle]='{ width: config?.width,height: config?.height,borderRadius: config?.borderRadius}'>\r\n <button [matTooltip]=\"labels['Upload a image']\" class='image-upload-btn' mat-icon-button (click)='onUpload($event)'>\r\n <mat-icon class='mat-18'>add_a_photo</mat-icon>\r\n </button>\r\n <input #imagePicker type='file' style='display: none' [id]=\"'filePicker-' + uuidFilePicker\"\r\n (change)='handleFileSelect($event)' [accept]='imagesAllowed'>\r\n </div>\r\n</div>\r\n<div *ngIf='loadImage' class='place-image'>\r\n <div class='image-holder-loaded'\r\n [ngStyle]='{width: config?.width,height: config?.height,borderRadius: config?.borderRadius}'>\r\n <img [src]='imageSrc' alt='image-loaded' [ngStyle]='{ borderRadius: config.borderRadius }'>\r\n <input #imagePicker type='file' style='display: none' [id]=\"'filePicker-' + uuidFilePicker\"\r\n (change)='handleFileSelect($event)' [accept]='imagesAllowed'>\r\n </div>\r\n <p *ngIf='imageSrc?.length' class='mat-caption image-caption'\r\n [ngStyle]=\"{color: (imageSrc?.length | calculateSize) > 120 ? '#f44336' : 'unset',fontWeight: (imageSrc?.length | calculateSize) > 120 ? '500' : 'unset'}\">\r\n size: {{ (imageSrc?.length | calculateSize) }}Kb &nbsp; {{ format }}\r\n </p>\r\n\r\n <div class='editing-bar-btn'\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <button id='upload-img' *ngIf='!config.hideAddBtn' mat-icon-button [matTooltip]=\"labels['Upload a image']\"\r\n (click)='onUpload($event)'>\r\n <mat-icon class='mat-18'>add_a_photo</mat-icon>\r\n </button>\r\n <button id='edit-img' *ngIf='!config.hideEditBtn' mat-icon-button [matTooltip]=\"labels['Open the editor panel']\"\r\n (click)='showEditPanel = true'>\r\n <mat-icon class='mat-18'>edit</mat-icon>\r\n </button>\r\n <a id='download-img' *ngIf='!config.hideDownloadBtn' [matTooltip]=\"labels['Download the image']\"\r\n [href]='imageSrc' mat-icon-button [download]='imageName'>\r\n <mat-icon class='mat-18'>cloud_download</mat-icon>\r\n </a>\r\n <button id='delete-img' *ngIf='!config.hideDeleteBtn' mat-icon-button [matTooltip]=\"labels['Remove']\"\r\n (click)='onRemove()'>\r\n <mat-icon class='mat-18'>delete</mat-icon>\r\n </button>\r\n </div>\r\n</div>\r\n\r\n<div *ngIf='showEditPanel' id='popup' class='popup'>\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: center flex-end; align-items: center'>\r\n <button mat-icon-button (click)='onCloseEditPanel()'>\r\n <mat-icon class='mat-18'>clear</mat-icon>\r\n </button>\r\n </div>\r\n\r\n <div class='image-container'>\r\n <div class='image-holder-full'>\r\n <img id='image-full' [src]='imageSrc' alt=''>\r\n <div id='image-cropper' class='image-cropper'>\r\n <div id='image-cropper-header'>\r\n <mat-icon>drag_indicator</mat-icon>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <div class='control-panel'>\r\n <p class='title-panel'>{{ labels['Control Panel'] }}</p>\r\n\r\n <p class='item-panel'>{{ labels['Quality'] }}</p>\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <mat-slider [color]='color' style='max-width: 100%; width: 100%' (change)='onChangeQuality()'\r\n [(ngModel)]='quality' [min]='0' [max]='100' [step]='1'>\r\n </mat-slider>\r\n </div>\r\n\r\n <p class='item-panel'>\r\n {{ labels['Max dimensions'] }}\r\n <mat-checkbox style='float: right' [(ngModel)]='maintainAspectRatio' [color]='color'>\r\n <span class='mat-caption'>{{ labels['aspect-ratio'] }}</span>\r\n </mat-checkbox>\r\n </p>\r\n <div\r\n style='margin-top: 8px !important; flex-flow: row wrap; box-sizing: border-box; display: flex; place-content: flex-start space-between; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['max-width(px)'] }}</mat-label>\r\n <input (change)='onChangeSize(true, false)' matInput [placeholder]=\"labels['max-width(px)']\"\r\n [(ngModel)]='maxWidth' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['max-height(px)'] }}</mat-label>\r\n <input (change)='onChangeSize(false, true)' matInput [placeholder]=\"labels['max-height(px)']\"\r\n [(ngModel)]='maxHeight' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n </div>\r\n\r\n <p class='item-panel'>{{ labels['Format'] }}</p>\r\n <div\r\n style='margin-top: 8px !important; flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 100%; width: 100%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-select [(ngModel)]='format' (selectionChange)='onChangeFormat()'>\r\n <mat-option *ngFor='let format of allFormats' [value]='format'>\r\n {{ format }}\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n\r\n <div>\r\n <mat-checkbox (change)='onCropStateChange()' [(ngModel)]='showCrop' [color]='color'>\r\n <p class='item-panel'>{{ labels['Crop'] }}</p>\r\n </mat-checkbox>\r\n <button style='float: right' mat-icon-button [color]='color' (click)='onRestore()'>\r\n <mat-icon>refresh</mat-icon>\r\n </button>\r\n </div>\r\n\r\n <ng-container *ngIf='showCrop'>\r\n <div\r\n style='margin-top: 8px !important; flex-flow: row wrap; box-sizing: border-box; display: flex; place-content: flex-start space-between; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['width(px)'] }}</mat-label>\r\n <input (change)='onChangeCrop()' matInput [placeholder]=\"labels['width(px)']\"\r\n [(ngModel)]='cropWidth' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['height(px)'] }}</mat-label>\r\n <input (change)='onChangeCrop()' matInput\r\n [placeholder]=\"labels['height(px)']\" [(ngModel)]='cropHeight' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n </div>\r\n\r\n <p style='margin-bottom: 4px !important'>\r\n <button mat-icon-button [color]='color' (click)='onCrop()'>\r\n <mat-icon> crop</mat-icon>\r\n </button>\r\n </p>\r\n </ng-container>\r\n\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: center space-between; align-items: center'>\r\n <button mat-flat-button (click)='onCloseEditPanel()' [color]='color'\r\n style='padding: 0 8px; height: 34px; box-sizing: border-box;'>\r\n Guardar\r\n </button>\r\n\r\n <p *ngIf='imageSrc?.length' class='mat-caption image-caption'\r\n [ngStyle]=\"{color: (imageSrc?.length | calculateSize) > 120 ? '#f44336' : 'unset',fontWeight: (imageSrc?.length | calculateSize) > 120 ? '500' : 'unset'}\">\r\n size: {{ (imageSrc?.length | calculateSize) }}Kb &nbsp; {{ format }}\r\n </p>\r\n </div>\r\n </div>\r\n </div>\r\n</div>\r\n", styles: ["guajiritos-image-picker p{margin:0!important;padding:0!important}guajiritos-image-picker .place-image{flex-direction:column;box-sizing:border-box;display:flex;place-content:flex-start;align-items:center}guajiritos-image-picker .place-image .image-holder{flex-direction:column;box-sizing:border-box;display:flex;place-content:center;align-items:center;position:relative;width:320px;height:240px;border-radius:16px;max-width:100%!important;border:2px rgba(0,0,0,.3) solid;background-color:#fcfcfc}@media (max-width: 599px){guajiritos-image-picker .place-image .image-holder{max-width:100%!important;max-height:250px!important}}guajiritos-image-picker .place-image .image-holder .image-upload-btn{transition:all .5s ease;position:relative;opacity:.85;width:50px;height:50px;color:#424242}guajiritos-image-picker .place-image .image-holder .image-upload-btn mat-icon{font-size:50px;width:50px;height:50px;line-height:50px;color:#424242}@media (max-width: 599px){guajiritos-image-picker .place-image .image-holder .image-upload-btn{opacity:1;width:30px;height:30px}guajiritos-image-picker .place-image .image-holder .image-upload-btn mat-icon{font-size:30px;width:30px;height:30px;line-height:30px}}guajiritos-image-picker .place-image .image-holder:hover .image-upload-btn{opacity:1;transition:all .5s ease}guajiritos-image-picker .place-image .image-holder-loaded{flex-direction:column;box-sizing:border-box;display:flex;place-content:center;align-items:center;position:relative;max-width:100%!important;width:320px;height:240px;border-radius:4px;padding:2px}guajiritos-image-picker .place-image .image-holder-loaded .image-caption{position:absolute;right:0;bottom:-22px}guajiritos-image-picker .place-image .image-holder-loaded img{height:100%;max-height:100%;width:100%;max-width:100%;object-fit:cover;object-position:center}@media (max-width: 599px){guajiritos-image-picker .place-image .image-holder-loaded{max-height:195px!important}}guajiritos-image-picker .place-image .image-holder-loaded .image-upload-btn{transition:all .5s ease;position:relative;opacity:.85;width:50px;height:50px;color:#424242}guajiritos-image-picker .place-image .image-holder-loaded .image-upload-btn mat-icon{font-size:50px;width:50px;height:50px;line-height:50px;color:#424242}@media (max-width: 599px){guajiritos-image-picker .place-image .image-holder-loaded .image-upload-btn{opacity:1;width:30px;height:30px}guajiritos-image-picker .place-image .image-holder-loaded .image-upload-btn mat-icon{font-size:30px;width:30px;height:30px;line-height:30px}}guajiritos-image-picker .place-image .image-holder-loaded:hover .image-upload-btn{opacity:1;transition:all .5s ease}guajiritos-image-picker .place-image .editing-bar-btn{margin-top:2px}guajiritos-image-picker .place-image .editing-bar-btn .mat-icon-button{height:20px;line-height:20px;width:24px}guajiritos-image-picker .place-image .editing-bar-btn mat-icon{line-height:20px!important;font-size:20px!important;width:20px!important;height:20px!important}guajiritos-image-picker .place-image .editing-bar-btn button{margin:4px;color:#424242;transition:all .5s ease}guajiritos-image-picker .place-image .editing-bar-btn button:hover{transform:scale(1.25);margin:4px 8px;transition:all .25s ease-in}guajiritos-image-picker .place-image .editing-bar-btn a{margin:4px;color:#424242;transition:all .5s ease}guajiritos-image-picker .place-image .editing-bar-btn a:hover{transform:scale(1.25);margin:4px 8px;transition:all .25s ease-in}guajiritos-image-picker .popup{width:100vw;max-height:100%;height:100%;overflow:auto;position:fixed;top:0;left:0;background-color:#000c;z-index:1000;padding:24px;color:#fff;box-sizing:border-box;animation-name:show;animation-duration:.4s}guajiritos-image-picker .popup .image-container{margin-top:50px;margin-bottom:50px;height:100%;min-height:100%;min-width:100%;width:100%;flex-flow:row wrap;box-sizing:border-box;display:flex;place-content:flex-start center;align-items:flex-start}guajiritos-image-picker .popup .image-container .image-holder-full{height:auto;width:auto;position:relative;display:contents}guajiritos-image-picker .popup img{max-height:600px;max-width:100%;object-fit:cover;object-position:center;margin:8px;transition:all .5s ease}@media (max-width: 1024px){guajiritos-image-picker .popup{background-color:#000000d9;padding:8px}guajiritos-image-picker .popup img{max-height:100%;max-width:100%}}@media (max-width: 599px){guajiritos-image-picker .popup img{margin:0}}guajiritos-image-picker .popup .control-panel{color:#fff;background-color:#000000eb;margin:8px;padding:16px;max-width:100%;width:18rem;border-radius:8px;flex-direction:column;box-sizing:border-box;display:flex;place-content:stretch flex-start;align-items:stretch}@media (max-width: 599px){guajiritos-image-picker .popup .control-panel{margin:8px 0;width:100%}}guajiritos-image-picker .popup .control-panel .title-panel{padding:0 4px;font-size:17px;font-weight:500;margin-bottom:16px!important}guajiritos-image-picker .popup .control-panel .item-panel{padding:0 4px;font-size:14px;font-weight:500}@keyframes show{0%{top:-100vh;opacity:0}to{top:0;opacity:1}}guajiritos-image-picker .mat-form-field-appearance-fill .mat-form-field-flex{background-color:#fafafa!important}guajiritos-image-picker .mat-select-panel{background:#fafafa!important}guajiritos-image-picker input.mat-input-element{color:#000000d9}guajiritos-image-picker .mat-checkbox-background{background-color:#fff}guajiritos-image-picker .image-cropper{position:absolute;width:150px;height:150px;border:2.5px solid #fafafa;box-sizing:border-box;resize:both;overflow:auto;opacity:0}guajiritos-image-picker .image-cropper #image-cropper-header{padding:10px;cursor:move;z-index:10;background-color:transparent;height:85%}guajiritos-image-picker .image-cropper #image-cropper-header mat-icon{color:#fff}guajiritos-image-picker .btn{padding:4px 8px;border-radius:4px;cursor:pointer}guajiritos-image-picker .btn mat-icon{color:#000000d1}\n"], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i1.MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "component", type: i1.MatIconAnchor, selector: "a[mat-icon-button]", inputs: ["disabled", "disableRipple", "color", "tabIndex"], exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: i1.MatIconButton, selector: "button[mat-icon-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "ngmodule", type: MatTooltipModule }, { kind: "directive", type: i2.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i3.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: CalculateSizeModule }, { kind: "pipe", type: CalculateSizePipe, name: "calculateSize" }, { kind: "ngmodule", type: MatSliderModule }, { kind: "component", type: i5.MatSlider, selector: "mat-slider", inputs: ["color", "disableRipple", "disabled", "discrete", "showTickMarks", "min", "max", "step", "displayWith"], exportAs: ["matSlider"] }, { kind: "ngmodule", type: MatCheckboxModule }, { kind: "component", type: i6.MatCheckbox, selector: "mat-checkbox", inputs: ["disableRipple", "color", "tabIndex"], exportAs: ["matCheckbox"] }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "component", type: i7.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i7.MatLabel, selector: "mat-label" }, { kind: "ngmodule", type: MatInputModule }, { kind: "directive", type: i8.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "ngmodule", type: MatSelectModule }, { kind: "component", type: i9.MatSelect, selector: "mat-select", inputs: ["disabled", "disableRipple", "tabIndex", "hideSingleSelectionIndicator"], exportAs: ["matSelect"] }, { kind: "component", type: i10.MatOption, selector: "mat-option", exportAs: ["matOption"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i11.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i11.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i11.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i11.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i11.MaxValidator, selector: "input[type=number][max][formControlName],input[type=number][max][formControl],input[type=number][max][ngModel]", inputs: ["max"] }, { kind: "directive", type: i11.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
548
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.3", ngImport: i0, type: GuajiritosImagePicker, decorators: [{
549
+ type: Component,
550
+ args: [{ selector: 'guajiritos-image-picker', standalone: true, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [
551
+ NgIf,
552
+ NgStyle,
553
+ MatButtonModule,
554
+ MatTooltipModule,
555
+ MatIconModule,
556
+ CalculateSizeModule,
557
+ MatSliderModule,
558
+ MatCheckboxModule,
559
+ MatFormFieldModule,
560
+ MatInputModule,
561
+ MatSelectModule,
562
+ FormsModule,
563
+ NgForOf,
564
+ ], template: "<div *ngIf='!loadImage' class='place-image'>\r\n <div class='image-holder'\r\n [ngStyle]='{ width: config?.width,height: config?.height,borderRadius: config?.borderRadius}'>\r\n <button [matTooltip]=\"labels['Upload a image']\" class='image-upload-btn' mat-icon-button (click)='onUpload($event)'>\r\n <mat-icon class='mat-18'>add_a_photo</mat-icon>\r\n </button>\r\n <input #imagePicker type='file' style='display: none' [id]=\"'filePicker-' + uuidFilePicker\"\r\n (change)='handleFileSelect($event)' [accept]='imagesAllowed'>\r\n </div>\r\n</div>\r\n<div *ngIf='loadImage' class='place-image'>\r\n <div class='image-holder-loaded'\r\n [ngStyle]='{width: config?.width,height: config?.height,borderRadius: config?.borderRadius}'>\r\n <img [src]='imageSrc' alt='image-loaded' [ngStyle]='{ borderRadius: config.borderRadius }'>\r\n <input #imagePicker type='file' style='display: none' [id]=\"'filePicker-' + uuidFilePicker\"\r\n (change)='handleFileSelect($event)' [accept]='imagesAllowed'>\r\n </div>\r\n <p *ngIf='imageSrc?.length' class='mat-caption image-caption'\r\n [ngStyle]=\"{color: (imageSrc?.length | calculateSize) > 120 ? '#f44336' : 'unset',fontWeight: (imageSrc?.length | calculateSize) > 120 ? '500' : 'unset'}\">\r\n size: {{ (imageSrc?.length | calculateSize) }}Kb &nbsp; {{ format }}\r\n </p>\r\n\r\n <div class='editing-bar-btn'\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <button id='upload-img' *ngIf='!config.hideAddBtn' mat-icon-button [matTooltip]=\"labels['Upload a image']\"\r\n (click)='onUpload($event)'>\r\n <mat-icon class='mat-18'>add_a_photo</mat-icon>\r\n </button>\r\n <button id='edit-img' *ngIf='!config.hideEditBtn' mat-icon-button [matTooltip]=\"labels['Open the editor panel']\"\r\n (click)='showEditPanel = true'>\r\n <mat-icon class='mat-18'>edit</mat-icon>\r\n </button>\r\n <a id='download-img' *ngIf='!config.hideDownloadBtn' [matTooltip]=\"labels['Download the image']\"\r\n [href]='imageSrc' mat-icon-button [download]='imageName'>\r\n <mat-icon class='mat-18'>cloud_download</mat-icon>\r\n </a>\r\n <button id='delete-img' *ngIf='!config.hideDeleteBtn' mat-icon-button [matTooltip]=\"labels['Remove']\"\r\n (click)='onRemove()'>\r\n <mat-icon class='mat-18'>delete</mat-icon>\r\n </button>\r\n </div>\r\n</div>\r\n\r\n<div *ngIf='showEditPanel' id='popup' class='popup'>\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: center flex-end; align-items: center'>\r\n <button mat-icon-button (click)='onCloseEditPanel()'>\r\n <mat-icon class='mat-18'>clear</mat-icon>\r\n </button>\r\n </div>\r\n\r\n <div class='image-container'>\r\n <div class='image-holder-full'>\r\n <img id='image-full' [src]='imageSrc' alt=''>\r\n <div id='image-cropper' class='image-cropper'>\r\n <div id='image-cropper-header'>\r\n <mat-icon>drag_indicator</mat-icon>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <div class='control-panel'>\r\n <p class='title-panel'>{{ labels['Control Panel'] }}</p>\r\n\r\n <p class='item-panel'>{{ labels['Quality'] }}</p>\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <mat-slider [color]='color' style='max-width: 100%; width: 100%' (change)='onChangeQuality()'\r\n [(ngModel)]='quality' [min]='0' [max]='100' [step]='1'>\r\n </mat-slider>\r\n </div>\r\n\r\n <p class='item-panel'>\r\n {{ labels['Max dimensions'] }}\r\n <mat-checkbox style='float: right' [(ngModel)]='maintainAspectRatio' [color]='color'>\r\n <span class='mat-caption'>{{ labels['aspect-ratio'] }}</span>\r\n </mat-checkbox>\r\n </p>\r\n <div\r\n style='margin-top: 8px !important; flex-flow: row wrap; box-sizing: border-box; display: flex; place-content: flex-start space-between; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['max-width(px)'] }}</mat-label>\r\n <input (change)='onChangeSize(true, false)' matInput [placeholder]=\"labels['max-width(px)']\"\r\n [(ngModel)]='maxWidth' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['max-height(px)'] }}</mat-label>\r\n <input (change)='onChangeSize(false, true)' matInput [placeholder]=\"labels['max-height(px)']\"\r\n [(ngModel)]='maxHeight' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n </div>\r\n\r\n <p class='item-panel'>{{ labels['Format'] }}</p>\r\n <div\r\n style='margin-top: 8px !important; flex-direction: row; box-sizing: border-box; display: flex; place-content: flex-start; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 100%; width: 100%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-select [(ngModel)]='format' (selectionChange)='onChangeFormat()'>\r\n <mat-option *ngFor='let format of allFormats' [value]='format'>\r\n {{ format }}\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n\r\n <div>\r\n <mat-checkbox (change)='onCropStateChange()' [(ngModel)]='showCrop' [color]='color'>\r\n <p class='item-panel'>{{ labels['Crop'] }}</p>\r\n </mat-checkbox>\r\n <button style='float: right' mat-icon-button [color]='color' (click)='onRestore()'>\r\n <mat-icon>refresh</mat-icon>\r\n </button>\r\n </div>\r\n\r\n <ng-container *ngIf='showCrop'>\r\n <div\r\n style='margin-top: 8px !important; flex-flow: row wrap; box-sizing: border-box; display: flex; place-content: flex-start space-between; align-items: flex-start'>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['width(px)'] }}</mat-label>\r\n <input (change)='onChangeCrop()' matInput [placeholder]=\"labels['width(px)']\"\r\n [(ngModel)]='cropWidth' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n <mat-form-field class='no-input-style' style='max-width: 48%; width: 48%' [appearance]='appearance'\r\n [color]='color'>\r\n <mat-label>{{ labels['height(px)'] }}</mat-label>\r\n <input (change)='onChangeCrop()' matInput\r\n [placeholder]=\"labels['height(px)']\" [(ngModel)]='cropHeight' type='number' [min]='0' [max]='2000'>\r\n </mat-form-field>\r\n </div>\r\n\r\n <p style='margin-bottom: 4px !important'>\r\n <button mat-icon-button [color]='color' (click)='onCrop()'>\r\n <mat-icon> crop</mat-icon>\r\n </button>\r\n </p>\r\n </ng-container>\r\n\r\n <div\r\n style='flex-direction: row; box-sizing: border-box; display: flex; place-content: center space-between; align-items: center'>\r\n <button mat-flat-button (click)='onCloseEditPanel()' [color]='color'\r\n style='padding: 0 8px; height: 34px; box-sizing: border-box;'>\r\n Guardar\r\n </button>\r\n\r\n <p *ngIf='imageSrc?.length' class='mat-caption image-caption'\r\n [ngStyle]=\"{color: (imageSrc?.length | calculateSize) > 120 ? '#f44336' : 'unset',fontWeight: (imageSrc?.length | calculateSize) > 120 ? '500' : 'unset'}\">\r\n size: {{ (imageSrc?.length | calculateSize) }}Kb &nbsp; {{ format }}\r\n </p>\r\n </div>\r\n </div>\r\n </div>\r\n</div>\r\n", styles: ["guajiritos-image-picker p{margin:0!important;padding:0!important}guajiritos-image-picker .place-image{flex-direction:column;box-sizing:border-box;display:flex;place-content:flex-start;align-items:center}guajiritos-image-picker .place-image .image-holder{flex-direction:column;box-sizing:border-box;display:flex;place-content:center;align-items:center;position:relative;width:320px;height:240px;border-radius:16px;max-width:100%!important;border:2px rgba(0,0,0,.3) solid;background-color:#fcfcfc}@media (max-width: 599px){guajiritos-image-picker .place-image .image-holder{max-width:100%!important;max-height:250px!important}}guajiritos-image-picker .place-image .image-holder .image-upload-btn{transition:all .5s ease;position:relative;opacity:.85;width:50px;height:50px;color:#424242}guajiritos-image-picker .place-image .image-holder .image-upload-btn mat-icon{font-size:50px;width:50px;height:50px;line-height:50px;color:#424242}@media (max-width: 599px){guajiritos-image-picker .place-image .image-holder .image-upload-btn{opacity:1;width:30px;height:30px}guajiritos-image-picker .place-image .image-holder .image-upload-btn mat-icon{font-size:30px;width:30px;height:30px;line-height:30px}}guajiritos-image-picker .place-image .image-holder:hover .image-upload-btn{opacity:1;transition:all .5s ease}guajiritos-image-picker .place-image .image-holder-loaded{flex-direction:column;box-sizing:border-box;display:flex;place-content:center;align-items:center;position:relative;max-width:100%!important;width:320px;height:240px;border-radius:4px;padding:2px}guajiritos-image-picker .place-image .image-holder-loaded .image-caption{position:absolute;right:0;bottom:-22px}guajiritos-image-picker .place-image .image-holder-loaded img{height:100%;max-height:100%;width:100%;max-width:100%;object-fit:cover;object-position:center}@media (max-width: 599px){guajiritos-image-picker .place-image .image-holder-loaded{max-height:195px!important}}guajiritos-image-picker .place-image .image-holder-loaded .image-upload-btn{transition:all .5s ease;position:relative;opacity:.85;width:50px;height:50px;color:#424242}guajiritos-image-picker .place-image .image-holder-loaded .image-upload-btn mat-icon{font-size:50px;width:50px;height:50px;line-height:50px;color:#424242}@media (max-width: 599px){guajiritos-image-picker .place-image .image-holder-loaded .image-upload-btn{opacity:1;width:30px;height:30px}guajiritos-image-picker .place-image .image-holder-loaded .image-upload-btn mat-icon{font-size:30px;width:30px;height:30px;line-height:30px}}guajiritos-image-picker .place-image .image-holder-loaded:hover .image-upload-btn{opacity:1;transition:all .5s ease}guajiritos-image-picker .place-image .editing-bar-btn{margin-top:2px}guajiritos-image-picker .place-image .editing-bar-btn .mat-icon-button{height:20px;line-height:20px;width:24px}guajiritos-image-picker .place-image .editing-bar-btn mat-icon{line-height:20px!important;font-size:20px!important;width:20px!important;height:20px!important}guajiritos-image-picker .place-image .editing-bar-btn button{margin:4px;color:#424242;transition:all .5s ease}guajiritos-image-picker .place-image .editing-bar-btn button:hover{transform:scale(1.25);margin:4px 8px;transition:all .25s ease-in}guajiritos-image-picker .place-image .editing-bar-btn a{margin:4px;color:#424242;transition:all .5s ease}guajiritos-image-picker .place-image .editing-bar-btn a:hover{transform:scale(1.25);margin:4px 8px;transition:all .25s ease-in}guajiritos-image-picker .popup{width:100vw;max-height:100%;height:100%;overflow:auto;position:fixed;top:0;left:0;background-color:#000c;z-index:1000;padding:24px;color:#fff;box-sizing:border-box;animation-name:show;animation-duration:.4s}guajiritos-image-picker .popup .image-container{margin-top:50px;margin-bottom:50px;height:100%;min-height:100%;min-width:100%;width:100%;flex-flow:row wrap;box-sizing:border-box;display:flex;place-content:flex-start center;align-items:flex-start}guajiritos-image-picker .popup .image-container .image-holder-full{height:auto;width:auto;position:relative;display:contents}guajiritos-image-picker .popup img{max-height:600px;max-width:100%;object-fit:cover;object-position:center;margin:8px;transition:all .5s ease}@media (max-width: 1024px){guajiritos-image-picker .popup{background-color:#000000d9;padding:8px}guajiritos-image-picker .popup img{max-height:100%;max-width:100%}}@media (max-width: 599px){guajiritos-image-picker .popup img{margin:0}}guajiritos-image-picker .popup .control-panel{color:#fff;background-color:#000000eb;margin:8px;padding:16px;max-width:100%;width:18rem;border-radius:8px;flex-direction:column;box-sizing:border-box;display:flex;place-content:stretch flex-start;align-items:stretch}@media (max-width: 599px){guajiritos-image-picker .popup .control-panel{margin:8px 0;width:100%}}guajiritos-image-picker .popup .control-panel .title-panel{padding:0 4px;font-size:17px;font-weight:500;margin-bottom:16px!important}guajiritos-image-picker .popup .control-panel .item-panel{padding:0 4px;font-size:14px;font-weight:500}@keyframes show{0%{top:-100vh;opacity:0}to{top:0;opacity:1}}guajiritos-image-picker .mat-form-field-appearance-fill .mat-form-field-flex{background-color:#fafafa!important}guajiritos-image-picker .mat-select-panel{background:#fafafa!important}guajiritos-image-picker input.mat-input-element{color:#000000d9}guajiritos-image-picker .mat-checkbox-background{background-color:#fff}guajiritos-image-picker .image-cropper{position:absolute;width:150px;height:150px;border:2.5px solid #fafafa;box-sizing:border-box;resize:both;overflow:auto;opacity:0}guajiritos-image-picker .image-cropper #image-cropper-header{padding:10px;cursor:move;z-index:10;background-color:transparent;height:85%}guajiritos-image-picker .image-cropper #image-cropper-header mat-icon{color:#fff}guajiritos-image-picker .btn{padding:4px 8px;border-radius:4px;cursor:pointer}guajiritos-image-picker .btn mat-icon{color:#000000d1}\n"] }]
565
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { appearance: [{
566
+ type: Input
567
+ }], color: [{
568
+ type: Input
569
+ }], imagesAllowed: [{
570
+ type: Input
571
+ }], imagePicker: [{
572
+ type: ViewChild,
573
+ args: ['imagePicker', { static: false }]
574
+ }], $imageChanged: [{
575
+ type: Output
576
+ }], $imageOriginal: [{
577
+ type: Output
578
+ }], _imageSrc: [{
579
+ type: Input
580
+ }], _config: [{
581
+ type: Input
582
+ }] } });
583
+
584
+ /*
585
+ * Public API Surface of guachos-image-picker
623
586
  */
624
587
 
625
- /**
626
- * Generated bundle index. Do not edit.
588
+ /**
589
+ * Generated bundle index. Do not edit.
627
590
  */
628
591
 
629
- export { GuajiritosImagePickerComponent, GuajiritosImagePickerModule };
592
+ export { GuajiritosImagePicker };
630
593
  //# sourceMappingURL=guajiritos-image-picker.mjs.map