@sam-senior/photo 1.2.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/lib/photo.component.mjs +233 -0
- package/esm2022/lib/photo.model.mjs +2 -0
- package/esm2022/lib/photo.module.mjs +57 -0
- package/esm2022/public_api.mjs +7 -0
- package/esm2022/sam-senior-photo.mjs +5 -0
- package/fesm2022/sam-senior-photo.mjs +296 -0
- package/fesm2022/sam-senior-photo.mjs.map +1 -0
- package/{sam-senior-photo.d.ts → index.d.ts} +5 -4
- package/lib/photo.component.d.ts +62 -59
- package/lib/photo.model.d.ts +4 -4
- package/lib/photo.module.d.ts +17 -2
- package/package.json +26 -29
- package/public_api.d.ts +3 -3
- package/bundles/sam-senior-photo.umd.js +0 -435
- package/bundles/sam-senior-photo.umd.js.map +0 -1
- package/bundles/sam-senior-photo.umd.min.js +0 -2
- package/bundles/sam-senior-photo.umd.min.js.map +0 -1
- package/esm2015/lib/photo.component.js +0 -374
- package/esm2015/lib/photo.model.js +0 -15
- package/esm2015/lib/photo.module.js +0 -33
- package/esm2015/public_api.js +0 -11
- package/esm2015/sam-senior-photo.js +0 -9
- package/esm5/lib/photo.component.js +0 -441
- package/esm5/lib/photo.model.js +0 -15
- package/esm5/lib/photo.module.js +0 -37
- package/esm5/public_api.js +0 -11
- package/esm5/sam-senior-photo.js +0 -9
- package/fesm2015/sam-senior-photo.js +0 -338
- package/fesm2015/sam-senior-photo.js.map +0 -1
- package/fesm5/sam-senior-photo.js +0 -407
- package/fesm5/sam-senior-photo.js.map +0 -1
- package/sam-senior-photo.metadata.json +0 -1
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
2
|
-
import { Component, ViewChild, EventEmitter, ViewEncapsulation, Input, Output, NgModule } from '@angular/core';
|
|
3
|
-
import { ConfirmDialogModule } from 'primeng/confirmdialog';
|
|
4
|
-
import { PanelModule } from 'primeng/panel';
|
|
5
|
-
import { ImageCropperService, ImageCropperModule, StepsModule, ObjectCardModule, ButtonModule, TileModule, LoadingStateModule } from '@seniorsistemas/angular-components';
|
|
6
|
-
import { DialogModule } from 'primeng/dialog';
|
|
7
|
-
import { PhotoCaptureService, PhotoCaptureModule } from '@sam-senior/photo-capture';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @fileoverview added by tsickle
|
|
11
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @fileoverview added by tsickle
|
|
16
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
17
|
-
*/
|
|
18
|
-
class PhotoComponent {
|
|
19
|
-
/**
|
|
20
|
-
* @param {?} imageCropperService
|
|
21
|
-
* @param {?} photoCaptureService
|
|
22
|
-
*/
|
|
23
|
-
constructor(imageCropperService, photoCaptureService) {
|
|
24
|
-
this.imageCropperService = imageCropperService;
|
|
25
|
-
this.photoCaptureService = photoCaptureService;
|
|
26
|
-
this.key = 'key';
|
|
27
|
-
this.actionIconClass = 'fa fa-camera';
|
|
28
|
-
this.photoSize = 'medium';
|
|
29
|
-
this.maxPhotoSize = 1;
|
|
30
|
-
this.photoWidth = 670;
|
|
31
|
-
this.photoHeight = 400;
|
|
32
|
-
this.canPhotoUpload = true;
|
|
33
|
-
this.canPhotoCapture = true;
|
|
34
|
-
this.cropperTitle = `Recortar`;
|
|
35
|
-
this.cropperActionCancel = `Cancelar`;
|
|
36
|
-
this.cropperActionCrop = `Recortar`;
|
|
37
|
-
this.cameraDialogLabel = `Captura`;
|
|
38
|
-
this.cameraDialogCaptureLabel = `Capturar`;
|
|
39
|
-
this.selectPhotoTypeLabel = `Selecionar imagem`;
|
|
40
|
-
this.selectUploadTypeLabel = `Upload`;
|
|
41
|
-
this.selectUploadTypeDescription = `Selecione uma imagem do seu computador`;
|
|
42
|
-
this.selectCaptureTypeLabel = `Capturar`;
|
|
43
|
-
this.selectCaptureTypeLabelDescription = `Capture uma imagem do seu dispositivo`;
|
|
44
|
-
this.dialogCancelLabel = `Cancelar`;
|
|
45
|
-
this.photoCrop = new EventEmitter();
|
|
46
|
-
this.openCamera = new EventEmitter();
|
|
47
|
-
this.closeCamera = new EventEmitter();
|
|
48
|
-
this.cameraError = new EventEmitter();
|
|
49
|
-
this.invalidPhotoSize = new EventEmitter();
|
|
50
|
-
this.isLoading = new EventEmitter();
|
|
51
|
-
this.cameraDialog = false;
|
|
52
|
-
this.selectPhotoType = false;
|
|
53
|
-
this.onChange = (/**
|
|
54
|
-
* @param {?} _
|
|
55
|
-
* @return {?}
|
|
56
|
-
*/
|
|
57
|
-
(_) => { });
|
|
58
|
-
this.onTouched = (/**
|
|
59
|
-
* @return {?}
|
|
60
|
-
*/
|
|
61
|
-
() => { });
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @return {?}
|
|
65
|
-
*/
|
|
66
|
-
changePhoto() {
|
|
67
|
-
if (this.canPhotoCapture && this.canPhotoUpload) {
|
|
68
|
-
this.selectPhotoType = true;
|
|
69
|
-
}
|
|
70
|
-
else if (this.canPhotoCapture) {
|
|
71
|
-
this.onOpenCamera();
|
|
72
|
-
}
|
|
73
|
-
else if (this.canPhotoUpload) {
|
|
74
|
-
this.onOpenUpload();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* @param {?} fn
|
|
79
|
-
* @return {?}
|
|
80
|
-
*/
|
|
81
|
-
registerOnChange(fn) {
|
|
82
|
-
this.onChange = fn;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* @param {?} fn
|
|
86
|
-
* @return {?}
|
|
87
|
-
*/
|
|
88
|
-
registerOnTouched(fn) {
|
|
89
|
-
this.onTouched = fn;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* @param {?} value
|
|
93
|
-
* @return {?}
|
|
94
|
-
*/
|
|
95
|
-
writeValue(value) {
|
|
96
|
-
this.photo = value;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* @return {?}
|
|
100
|
-
*/
|
|
101
|
-
onOpenCamera() {
|
|
102
|
-
this.closeSelectPhotoType();
|
|
103
|
-
this.cameraDialog = true;
|
|
104
|
-
this.photoCaptureService.setKey(this.key);
|
|
105
|
-
this.photoCaptureService.start();
|
|
106
|
-
this.openCamera.emit();
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* @return {?}
|
|
110
|
-
*/
|
|
111
|
-
closeSelectPhotoType() {
|
|
112
|
-
this.selectPhotoType = false;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* @return {?}
|
|
116
|
-
*/
|
|
117
|
-
onOpenUpload() {
|
|
118
|
-
this.closeSelectPhotoType();
|
|
119
|
-
((/** @type {?} */ (this.imageInput.nativeElement))).value = null;
|
|
120
|
-
((/** @type {?} */ (this.imageInput.nativeElement))).click();
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* @param {?} event
|
|
124
|
-
* @return {?}
|
|
125
|
-
*/
|
|
126
|
-
photoSelected(event) {
|
|
127
|
-
const [file] = event.srcElement.files;
|
|
128
|
-
this.photoRender(file);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* @return {?}
|
|
132
|
-
*/
|
|
133
|
-
onCloseCamera() {
|
|
134
|
-
this.cameraDialog = false;
|
|
135
|
-
this.photoCaptureService.stop();
|
|
136
|
-
this.closeCamera.emit();
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* @return {?}
|
|
140
|
-
*/
|
|
141
|
-
onPhotoCapture() {
|
|
142
|
-
this.isLoading.emit(true);
|
|
143
|
-
this.photoCaptureService.setKey(this.key);
|
|
144
|
-
this.photoCaptureService.takePhoto();
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* @param {?} photo
|
|
148
|
-
* @return {?}
|
|
149
|
-
*/
|
|
150
|
-
onPhotoTake(photo) {
|
|
151
|
-
if (this.photoCaptureService.getKey() === this.key) {
|
|
152
|
-
this.photoRender(photo.blob);
|
|
153
|
-
this.onCloseCamera();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* @param {?} error
|
|
158
|
-
* @return {?}
|
|
159
|
-
*/
|
|
160
|
-
onCameraError(error) {
|
|
161
|
-
if (this.photoCaptureService.getKey() === this.key) {
|
|
162
|
-
this.onCloseCamera();
|
|
163
|
-
this.cameraError.emit(error);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* @private
|
|
168
|
-
* @param {?} file
|
|
169
|
-
* @return {?}
|
|
170
|
-
*/
|
|
171
|
-
photoRender(file) {
|
|
172
|
-
if (file) {
|
|
173
|
-
/** @type {?} */
|
|
174
|
-
const fileReader = new FileReader();
|
|
175
|
-
fileReader.onloadend =
|
|
176
|
-
(/**
|
|
177
|
-
* @param {?} photoRender
|
|
178
|
-
* @return {?}
|
|
179
|
-
*/
|
|
180
|
-
photoRender => this.photoChopper(photoRender));
|
|
181
|
-
fileReader.readAsDataURL(file);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* @private
|
|
186
|
-
* @param {?} photoRender
|
|
187
|
-
* @return {?}
|
|
188
|
-
*/
|
|
189
|
-
photoChopper(photoRender) {
|
|
190
|
-
this.imageCropperService.show({
|
|
191
|
-
imageSource: photoRender.target.result,
|
|
192
|
-
croppedCanvas: (/**
|
|
193
|
-
* @param {?} imageCanvas
|
|
194
|
-
* @return {?}
|
|
195
|
-
*/
|
|
196
|
-
imageCanvas => {
|
|
197
|
-
imageCanvas.toBlob((/**
|
|
198
|
-
* @param {?} blob
|
|
199
|
-
* @return {?}
|
|
200
|
-
*/
|
|
201
|
-
blob => {
|
|
202
|
-
this.setPhotoContent(imageCanvas.toDataURL(), blob);
|
|
203
|
-
this.onCreateBlob();
|
|
204
|
-
}));
|
|
205
|
-
}),
|
|
206
|
-
header: this.cropperTitle,
|
|
207
|
-
emptyStateActionLabel: this.cropperActionCancel,
|
|
208
|
-
allowSelectAnother: false,
|
|
209
|
-
allowRemove: false,
|
|
210
|
-
cropLabel: this.cropperActionCrop,
|
|
211
|
-
rounded: true,
|
|
212
|
-
aspectRatio: 3 / 4
|
|
213
|
-
});
|
|
214
|
-
this.isLoading.emit(false);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* @private
|
|
218
|
-
* @return {?}
|
|
219
|
-
*/
|
|
220
|
-
onCreateBlob() {
|
|
221
|
-
if (this.getMaxSizeInBites() > this.photoContent.blob.size) {
|
|
222
|
-
this.photoCrop.emit(this.photoContent);
|
|
223
|
-
this.photo = this.photoContent.image;
|
|
224
|
-
this.onChange(this.photo);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
this.invalidPhotoSize.emit();
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* @private
|
|
232
|
-
* @return {?}
|
|
233
|
-
*/
|
|
234
|
-
getMaxSizeInBites() {
|
|
235
|
-
return (this.maxPhotoSize * 1000) * 1000;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* @private
|
|
239
|
-
* @param {?} imageUri
|
|
240
|
-
* @param {?} imageBlob
|
|
241
|
-
* @return {?}
|
|
242
|
-
*/
|
|
243
|
-
setPhotoContent(imageUri, imageBlob) {
|
|
244
|
-
this.photoContent = {
|
|
245
|
-
image: imageUri,
|
|
246
|
-
blob: imageBlob
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
PhotoComponent.decorators = [
|
|
251
|
-
{ type: Component, args: [{
|
|
252
|
-
selector: 'sam-photo',
|
|
253
|
-
template: "<input #imageInput type=\"file\" class=\"photo__input-file--hidden\" (change)=\"photoSelected($event)\" accept=\"image/*\">\r\n<s-thumbnail [size]=\"photoSize\" iconClass=\"fa fa-user\" (click)=\"changePhoto()\"\r\n [hasAction]=\"canPhotoUpload || canPhotoCapture\" [imageSource]=\"photo\" [actionIconClass]=\"actionIconClass\">\r\n</s-thumbnail>\r\n\r\n<p-dialog styleClass=\"photo-capture-custom\" [(visible)]=\"cameraDialog\" [header]=\"cameraDialogLabel\"\r\n [style]=\"{width: '700px'}\" appendTo='body' [modal]=\"true\">\r\n <sam-photo-capture [width]=\"photoWidth\" [height]=\"photoHeight\" (photoTake)=\"onPhotoTake($event)\"\r\n (error)=\"onCameraError($event)\"></sam-photo-capture>\r\n <p-footer>\r\n <s-button id=\"takePhotoBtn\" priority=\"primary\" [label]=\"cameraDialogCaptureLabel\" (click)=\"onPhotoCapture()\">\r\n </s-button>\r\n <s-button id=\"cancelBtn\" priority=\"link\" [label]=\"dialogCancelLabel\" (click)=\"onCloseCamera()\"></s-button>\r\n </p-footer>\r\n</p-dialog>\r\n\r\n<p-dialog [(visible)]=\"selectPhotoType\" [header]=\"selectPhotoTypeLabel\" [style]=\"{width: '400px'}\" appendTo='body' [modal]=\"true\"\r\n [closable]=\"false\">\r\n <s-tile [label]=\"selectUploadTypeLabel\" [description]=\"selectUploadTypeDescription\" iconClass=\"fa fa-upload\"\r\n (click)=\"onOpenUpload()\"></s-tile>\r\n <br>\r\n <s-tile [label]=\"selectCaptureTypeLabel\" [description]=\"selectCaptureTypeLabelDescription\" iconClass=\"fa fa-camera\"\r\n (click)=\"onOpenCamera()\"></s-tile>\r\n <p-footer>\r\n <s-button id=\"cancelBtn\" priority=\"link\" [label]=\"dialogCancelLabel\" (click)=\"closeSelectPhotoType()\"></s-button>\r\n </p-footer>\r\n</p-dialog>\r\n",
|
|
254
|
-
providers: [
|
|
255
|
-
{
|
|
256
|
-
provide: NG_VALUE_ACCESSOR,
|
|
257
|
-
useExisting: PhotoComponent,
|
|
258
|
-
multi: true
|
|
259
|
-
}
|
|
260
|
-
],
|
|
261
|
-
encapsulation: ViewEncapsulation.None,
|
|
262
|
-
styles: [".photo__input-file--hidden{position:fixed;top:-100em}.select-photo-type-container{display:flex;flex-direction:row;align-items:center;justify-content:center}.select-photo-type-item{color:gray;cursor:pointer;display:flex;flex-direction:column;align-items:center;justify-content:center}.select-photo-type-item:nth-child(1){border-right:1px solid #ccc}.select-photo-type-item i{font-size:80px;margin-left:40px;margin-right:40px}.select-photo-type-item span{margin-top:10px}"]
|
|
263
|
-
}] }
|
|
264
|
-
];
|
|
265
|
-
/** @nocollapse */
|
|
266
|
-
PhotoComponent.ctorParameters = () => [
|
|
267
|
-
{ type: ImageCropperService },
|
|
268
|
-
{ type: PhotoCaptureService }
|
|
269
|
-
];
|
|
270
|
-
PhotoComponent.propDecorators = {
|
|
271
|
-
imageInput: [{ type: ViewChild, args: [`imageInput`,] }],
|
|
272
|
-
key: [{ type: Input }],
|
|
273
|
-
photo: [{ type: Input }],
|
|
274
|
-
actionIconClass: [{ type: Input }],
|
|
275
|
-
photoSize: [{ type: Input }],
|
|
276
|
-
maxPhotoSize: [{ type: Input }],
|
|
277
|
-
photoWidth: [{ type: Input }],
|
|
278
|
-
photoHeight: [{ type: Input }],
|
|
279
|
-
canPhotoUpload: [{ type: Input }],
|
|
280
|
-
canPhotoCapture: [{ type: Input }],
|
|
281
|
-
cropperTitle: [{ type: Input }],
|
|
282
|
-
cropperActionCancel: [{ type: Input }],
|
|
283
|
-
cropperActionCrop: [{ type: Input }],
|
|
284
|
-
cameraDialogLabel: [{ type: Input }],
|
|
285
|
-
cameraDialogCaptureLabel: [{ type: Input }],
|
|
286
|
-
selectPhotoTypeLabel: [{ type: Input }],
|
|
287
|
-
selectUploadTypeLabel: [{ type: Input }],
|
|
288
|
-
selectUploadTypeDescription: [{ type: Input }],
|
|
289
|
-
selectCaptureTypeLabel: [{ type: Input }],
|
|
290
|
-
selectCaptureTypeLabelDescription: [{ type: Input }],
|
|
291
|
-
dialogCancelLabel: [{ type: Input }],
|
|
292
|
-
photoCrop: [{ type: Output }],
|
|
293
|
-
openCamera: [{ type: Output }],
|
|
294
|
-
closeCamera: [{ type: Output }],
|
|
295
|
-
cameraError: [{ type: Output }],
|
|
296
|
-
invalidPhotoSize: [{ type: Output }],
|
|
297
|
-
isLoading: [{ type: Output }]
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* @fileoverview added by tsickle
|
|
302
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
303
|
-
*/
|
|
304
|
-
class PhotoModule {
|
|
305
|
-
}
|
|
306
|
-
PhotoModule.decorators = [
|
|
307
|
-
{ type: NgModule, args: [{
|
|
308
|
-
declarations: [PhotoComponent],
|
|
309
|
-
imports: [
|
|
310
|
-
PanelModule,
|
|
311
|
-
DialogModule,
|
|
312
|
-
StepsModule,
|
|
313
|
-
ObjectCardModule,
|
|
314
|
-
ImageCropperModule,
|
|
315
|
-
ConfirmDialogModule,
|
|
316
|
-
PhotoCaptureModule,
|
|
317
|
-
ButtonModule,
|
|
318
|
-
TileModule,
|
|
319
|
-
LoadingStateModule
|
|
320
|
-
],
|
|
321
|
-
providers: [ImageCropperService],
|
|
322
|
-
exports: [PhotoComponent]
|
|
323
|
-
},] }
|
|
324
|
-
];
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* @fileoverview added by tsickle
|
|
328
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
329
|
-
*/
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* @fileoverview added by tsickle
|
|
333
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
334
|
-
*/
|
|
335
|
-
|
|
336
|
-
export { PhotoComponent, PhotoModule };
|
|
337
|
-
|
|
338
|
-
//# sourceMappingURL=sam-senior-photo.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sam-senior-photo.js.map","sources":["ng://@sam-senior/photo/lib/photo.component.ts","ng://@sam-senior/photo/lib/photo.module.ts"],"sourcesContent":["import { Component, ViewChild, EventEmitter, ElementRef, ViewEncapsulation, OnInit } from '@angular/core';\r\nimport { Input } from '@angular/core';\r\nimport { Output } from '@angular/core';\r\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\r\nimport { ImageCropperService } from '@seniorsistemas/angular-components';\r\nimport { PhotoCaptureService } from '@sam-senior/photo-capture';\r\n\r\nimport { PhotoModel } from './photo.model';\r\n\r\n@Component({\r\n selector: 'sam-photo',\r\n templateUrl: './photo.component.html',\r\n styleUrls: ['./photo.component.css'],\r\n providers: [\r\n {\r\n provide: NG_VALUE_ACCESSOR,\r\n useExisting: PhotoComponent,\r\n multi: true\r\n }\r\n ],\r\n encapsulation: ViewEncapsulation.None\r\n})\r\nexport class PhotoComponent implements ControlValueAccessor {\r\n @ViewChild(`imageInput`) imageInput: ElementRef;\r\n\r\n @Input() key = 'key';\r\n @Input() photo: string;\r\n @Input() actionIconClass = 'fa fa-camera';\r\n @Input() photoSize = 'medium';\r\n @Input() maxPhotoSize = 1;\r\n @Input() photoWidth = 670;\r\n @Input() photoHeight = 400;\r\n @Input() canPhotoUpload = true;\r\n @Input() canPhotoCapture = true;\r\n\r\n @Input() cropperTitle = `Recortar`;\r\n @Input() cropperActionCancel = `Cancelar`;\r\n @Input() cropperActionCrop = `Recortar`;\r\n\r\n @Input() cameraDialogLabel = `Captura`;\r\n @Input() cameraDialogCaptureLabel = `Capturar`;\r\n @Input() selectPhotoTypeLabel = `Selecionar imagem`;\r\n @Input() selectUploadTypeLabel = `Upload`;\r\n @Input() selectUploadTypeDescription = `Selecione uma imagem do seu computador`;\r\n @Input() selectCaptureTypeLabel = `Capturar`;\r\n @Input() selectCaptureTypeLabelDescription = `Capture uma imagem do seu dispositivo`;\r\n @Input() dialogCancelLabel = `Cancelar`;\r\n\r\n @Output() photoCrop = new EventEmitter();\r\n @Output() openCamera = new EventEmitter();\r\n @Output() closeCamera = new EventEmitter();\r\n @Output() cameraError = new EventEmitter();\r\n @Output() invalidPhotoSize = new EventEmitter();\r\n @Output() isLoading = new EventEmitter();\r\n\r\n public photoContent: PhotoModel;\r\n public cameraDialog = false;\r\n public selectPhotoType = false;\r\n\r\n private onChange = (_: any) => { };\r\n private onTouched = () => { };\r\n\r\n constructor(\r\n private imageCropperService: ImageCropperService,\r\n private photoCaptureService: PhotoCaptureService\r\n ) { }\r\n\r\n public changePhoto() {\r\n if (this.canPhotoCapture && this.canPhotoUpload) {\r\n this.selectPhotoType = true;\r\n } else if (this.canPhotoCapture) {\r\n this.onOpenCamera();\r\n } else if (this.canPhotoUpload) {\r\n this.onOpenUpload();\r\n }\r\n }\r\n\r\n public registerOnChange(fn: (_: any) => void): void {\r\n this.onChange = fn;\r\n }\r\n\r\n public registerOnTouched(fn: () => void): void {\r\n this.onTouched = fn;\r\n }\r\n\r\n public writeValue(value: any) {\r\n this.photo = value;\r\n }\r\n\r\n public onOpenCamera() {\r\n this.closeSelectPhotoType();\r\n this.cameraDialog = true;\r\n this.photoCaptureService.setKey(this.key);\r\n this.photoCaptureService.start();\r\n this.openCamera.emit();\r\n }\r\n\r\n public closeSelectPhotoType() {\r\n this.selectPhotoType = false;\r\n }\r\n\r\n public onOpenUpload() {\r\n this.closeSelectPhotoType();\r\n (this.imageInput.nativeElement as HTMLInputElement).value = null;\r\n (this.imageInput.nativeElement as HTMLInputElement).click();\r\n }\r\n\r\n public photoSelected(event: any) {\r\n const [file] = event.srcElement.files;\r\n this.photoRender(file);\r\n }\r\n\r\n public onCloseCamera() {\r\n this.cameraDialog = false;\r\n this.photoCaptureService.stop();\r\n this.closeCamera.emit();\r\n }\r\n\r\n public onPhotoCapture() {\r\n this.isLoading.emit(true);\r\n this.photoCaptureService.setKey(this.key);\r\n this.photoCaptureService.takePhoto();\r\n }\r\n\r\n public onPhotoTake(photo) {\r\n if (this.photoCaptureService.getKey() === this.key) {\r\n this.photoRender(photo.blob);\r\n this.onCloseCamera();\r\n }\r\n }\r\n\r\n public onCameraError(error) {\r\n if (this.photoCaptureService.getKey() === this.key) {\r\n this.onCloseCamera();\r\n this.cameraError.emit(error);\r\n }\r\n }\r\n\r\n private photoRender(file) {\r\n if (file) {\r\n const fileReader = new FileReader();\r\n fileReader.onloadend =\r\n photoRender => this.photoChopper(photoRender);\r\n fileReader.readAsDataURL(file);\r\n }\r\n }\r\n\r\n private photoChopper(photoRender) {\r\n this.imageCropperService.show({\r\n imageSource: photoRender.target.result,\r\n croppedCanvas: imageCanvas => {\r\n imageCanvas.toBlob(blob => {\r\n this.setPhotoContent(imageCanvas.toDataURL(), blob);\r\n this.onCreateBlob();\r\n });\r\n },\r\n header: this.cropperTitle,\r\n emptyStateActionLabel: this.cropperActionCancel,\r\n allowSelectAnother: false,\r\n allowRemove: false,\r\n cropLabel: this.cropperActionCrop,\r\n rounded: true,\r\n aspectRatio: 3 / 4\r\n });\r\n this.isLoading.emit(false);\r\n }\r\n\r\n private onCreateBlob() {\r\n if (this.getMaxSizeInBites() > this.photoContent.blob.size) {\r\n this.photoCrop.emit(this.photoContent);\r\n this.photo = this.photoContent.image;\r\n this.onChange(this.photo);\r\n } else {\r\n this.invalidPhotoSize.emit();\r\n }\r\n }\r\n\r\n private getMaxSizeInBites() {\r\n return (this.maxPhotoSize * 1000) * 1000;\r\n }\r\n\r\n private setPhotoContent(imageUri, imageBlob) {\r\n this.photoContent = {\r\n image: imageUri,\r\n blob: imageBlob\r\n };\r\n }\r\n\r\n}\r\n","import { NgModule } from '@angular/core';\r\nimport { ConfirmDialogModule } from 'primeng/confirmdialog';\r\nimport { PanelModule } from 'primeng/panel';\r\nimport {\r\n ImageCropperModule,\r\n StepsModule,\r\n ObjectCardModule,\r\n ButtonModule,\r\n TileModule,\r\n ImageCropperService,\r\n LoadingStateModule\r\n} from '@seniorsistemas/angular-components';\r\nimport { DialogModule } from 'primeng/dialog';\r\nimport { PhotoCaptureModule } from '@sam-senior/photo-capture';\r\n\r\nimport { PhotoComponent } from './photo.component';\r\n\r\n@NgModule({\r\n declarations: [PhotoComponent],\r\n imports: [\r\n PanelModule,\r\n DialogModule,\r\n StepsModule,\r\n ObjectCardModule,\r\n ImageCropperModule,\r\n ConfirmDialogModule,\r\n PhotoCaptureModule,\r\n ButtonModule,\r\n TileModule,\r\n LoadingStateModule\r\n ],\r\n providers: [ImageCropperService],\r\n exports: [PhotoComponent]\r\n})\r\nexport class PhotoModule { }\r\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,MAsBa,cAAc;;;;;IAwCzB,YACU,mBAAwC,EACxC,mBAAwC;QADxC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,wBAAmB,GAAnB,mBAAmB,CAAqB;QAvCzC,QAAG,GAAG,KAAK,CAAC;QAEZ,oBAAe,GAAG,cAAc,CAAC;QACjC,cAAS,GAAG,QAAQ,CAAC;QACrB,iBAAY,GAAG,CAAC,CAAC;QACjB,eAAU,GAAG,GAAG,CAAC;QACjB,gBAAW,GAAG,GAAG,CAAC;QAClB,mBAAc,GAAG,IAAI,CAAC;QACtB,oBAAe,GAAG,IAAI,CAAC;QAEvB,iBAAY,GAAG,UAAU,CAAC;QAC1B,wBAAmB,GAAG,UAAU,CAAC;QACjC,sBAAiB,GAAG,UAAU,CAAC;QAE/B,sBAAiB,GAAG,SAAS,CAAC;QAC9B,6BAAwB,GAAG,UAAU,CAAC;QACtC,yBAAoB,GAAG,mBAAmB,CAAC;QAC3C,0BAAqB,GAAG,QAAQ,CAAC;QACjC,gCAA2B,GAAG,wCAAwC,CAAC;QACvE,2BAAsB,GAAG,UAAU,CAAC;QACpC,sCAAiC,GAAG,uCAAuC,CAAC;QAC5E,sBAAiB,GAAG,UAAU,CAAC;QAE9B,cAAS,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,eAAU,GAAG,IAAI,YAAY,EAAE,CAAC;QAChC,gBAAW,GAAG,IAAI,YAAY,E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