@guajiritos/image-picker 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -0
- package/esm2020/guajiritos-image-picker.mjs +5 -0
- package/esm2020/lib/guachos-image-picker.component.mjs +542 -0
- package/esm2020/lib/guachos-image-picker.module.mjs +60 -0
- package/esm2020/public-api.mjs +6 -0
- package/esm2020/utils/calculate-size.pipe.mjs +24 -0
- package/fesm2015/guajiritos-image-picker.mjs +646 -0
- package/fesm2015/guajiritos-image-picker.mjs.map +1 -0
- package/fesm2020/guajiritos-image-picker.mjs +630 -0
- package/fesm2020/guajiritos-image-picker.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/guachos-image-picker.component.d.ts +79 -0
- package/lib/guachos-image-picker.module.d.ts +18 -0
- package/package.json +57 -0
- package/public-api.d.ts +2 -0
- package/utils/calculate-size.pipe.d.ts +7 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Pipe, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, ViewChild, Output, NgModule } from '@angular/core';
|
|
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';
|
|
7
|
+
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';
|
|
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
|
+
}]
|
|
46
|
+
}] });
|
|
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 {{ 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 {{ 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 {{ 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 {{ 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
|
+
}]
|
|
619
|
+
}] });
|
|
620
|
+
|
|
621
|
+
/*
|
|
622
|
+
* Public API Surface of guachos-image-picker
|
|
623
|
+
*/
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Generated bundle index. Do not edit.
|
|
627
|
+
*/
|
|
628
|
+
|
|
629
|
+
export { GuajiritosImagePickerComponent, GuajiritosImagePickerModule };
|
|
630
|
+
//# sourceMappingURL=guajiritos-image-picker.mjs.map
|