@jaak.ai/stamps 2.0.0-dev.25 → 2.0.0-dev.26
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 +3 -0
- package/dist/cjs/{index-DGM9-FNg.js → index-BfhtOB0D.js} +5 -2
- package/dist/cjs/index-BfhtOB0D.js.map +1 -0
- package/dist/cjs/jaak-stamps-webcomponent.cjs.js +2 -2
- package/dist/cjs/jaak-stamps.cjs.entry.js +357 -14
- package/dist/cjs/jaak-stamps.cjs.entry.js.map +1 -1
- package/dist/cjs/jaak-stamps.entry.cjs.js.map +1 -1
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/collection/components/my-component/my-component.css +227 -0
- package/dist/collection/components/my-component/my-component.js +419 -13
- package/dist/collection/components/my-component/my-component.js.map +1 -1
- package/dist/components/index.js +3 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/jaak-stamps.js +364 -14
- package/dist/components/jaak-stamps.js.map +1 -1
- package/dist/esm/{index-DqoVMnc7.js → index-BP1Q4KOg.js} +5 -2
- package/dist/esm/index-BP1Q4KOg.js.map +1 -0
- package/dist/esm/jaak-stamps-webcomponent.js +3 -3
- package/dist/esm/jaak-stamps.entry.js +357 -14
- package/dist/esm/jaak-stamps.entry.js.map +1 -1
- package/dist/esm/loader.js +3 -3
- package/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js +1 -1
- package/dist/jaak-stamps-webcomponent/jaak-stamps.entry.esm.js.map +1 -1
- package/dist/jaak-stamps-webcomponent/p-14eb13d8.entry.js +2 -0
- package/dist/jaak-stamps-webcomponent/p-14eb13d8.entry.js.map +1 -0
- package/dist/jaak-stamps-webcomponent/p-BP1Q4KOg.js +3 -0
- package/dist/jaak-stamps-webcomponent/p-BP1Q4KOg.js.map +1 -0
- package/dist/types/components/my-component/my-component.d.ts +36 -0
- package/dist/types/components.d.ts +10 -0
- package/package.json +1 -1
- package/dist/cjs/index-DGM9-FNg.js.map +0 -1
- package/dist/esm/index-DqoVMnc7.js.map +0 -1
- package/dist/jaak-stamps-webcomponent/p-DqoVMnc7.js +0 -3
- package/dist/jaak-stamps-webcomponent/p-DqoVMnc7.js.map +0 -1
- package/dist/jaak-stamps-webcomponent/p-f1172b06.entry.js +0 -2
- package/dist/jaak-stamps-webcomponent/p-f1172b06.entry.js.map +0 -1
|
@@ -6,6 +6,7 @@ export class JaakStamps {
|
|
|
6
6
|
maskSize = 90; // Porcentaje del video que ocupará la máscara (default 90%)
|
|
7
7
|
cropMargin = 0; // Margen en píxeles para el recorte del documento (default 0)
|
|
8
8
|
useDocumentClassification = false; // Habilita la clasificación automática de documentos para determinar si solicitar reverso
|
|
9
|
+
preferredCamera = 'auto'; // Define qué cámara usar: 'auto' (automático según dispositivo), 'front' (frontal), 'back' (trasera)
|
|
9
10
|
captureCompleted;
|
|
10
11
|
isReady;
|
|
11
12
|
isVideoActive = false;
|
|
@@ -31,6 +32,10 @@ export class JaakStamps {
|
|
|
31
32
|
isLoading = false;
|
|
32
33
|
isModelPreloaded = false;
|
|
33
34
|
isMaskReady = false;
|
|
35
|
+
availableCameras = [];
|
|
36
|
+
selectedCameraId = null;
|
|
37
|
+
showCameraSelector = false;
|
|
38
|
+
isMultipleCamerasAvailable = false;
|
|
34
39
|
videoRef;
|
|
35
40
|
canvasRef;
|
|
36
41
|
session;
|
|
@@ -41,6 +46,9 @@ export class JaakStamps {
|
|
|
41
46
|
lastDetectedBox;
|
|
42
47
|
mobileNetSession;
|
|
43
48
|
mobileNetClassMap;
|
|
49
|
+
// Camera management properties
|
|
50
|
+
deviceType = 'desktop';
|
|
51
|
+
preferredCameraFacing = null;
|
|
44
52
|
// Performance optimization properties
|
|
45
53
|
frameSkipCounter = 0;
|
|
46
54
|
FRAME_SKIP = 2; // Process every 3rd frame (reduces CPU by ~66%)
|
|
@@ -77,6 +85,13 @@ export class JaakStamps {
|
|
|
77
85
|
this.cropMargin = 0;
|
|
78
86
|
}
|
|
79
87
|
}
|
|
88
|
+
validatePreferredCamera() {
|
|
89
|
+
const validOptions = ['auto', 'front', 'back'];
|
|
90
|
+
if (!validOptions.includes(this.preferredCamera)) {
|
|
91
|
+
console.warn(`preferredCamera debe ser uno de: ${validOptions.join(', ')}. Valor actual: ${this.preferredCamera}. Usando valor por defecto: 'auto'`);
|
|
92
|
+
this.preferredCamera = 'auto';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
80
95
|
emitReadyEvent() {
|
|
81
96
|
const isDocumentReady = !!window.ort && this.isModelPreloaded;
|
|
82
97
|
this.isReady.emit(isDocumentReady);
|
|
@@ -89,9 +104,267 @@ export class JaakStamps {
|
|
|
89
104
|
const settings = videoTrack.getSettings();
|
|
90
105
|
return settings.facingMode === 'environment';
|
|
91
106
|
}
|
|
107
|
+
async detectDeviceTypeAndCameras() {
|
|
108
|
+
// Detect device type
|
|
109
|
+
const userAgent = navigator.userAgent;
|
|
110
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);
|
|
111
|
+
const isTablet = /iPad|Android/i.test(userAgent) && window.innerWidth >= 768;
|
|
112
|
+
if (isTablet) {
|
|
113
|
+
this.deviceType = 'tablet';
|
|
114
|
+
}
|
|
115
|
+
else if (isMobile) {
|
|
116
|
+
this.deviceType = 'mobile';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this.deviceType = 'desktop';
|
|
120
|
+
}
|
|
121
|
+
this.debugLog('📱 Device type detected:', this.deviceType);
|
|
122
|
+
// Enumerate available cameras
|
|
123
|
+
await this.enumerateAndDetectCameras();
|
|
124
|
+
// Load user preference
|
|
125
|
+
this.loadCameraPreference();
|
|
126
|
+
}
|
|
127
|
+
async enumerateAndDetectCameras() {
|
|
128
|
+
try {
|
|
129
|
+
// First, check if we have permission to enumerate devices
|
|
130
|
+
const permissionStatus = await this.checkCameraPermission();
|
|
131
|
+
if (permissionStatus === 'denied') {
|
|
132
|
+
this.debugLog('❌ Camera permission denied');
|
|
133
|
+
this.statusMessage = "Permiso de cámara denegado";
|
|
134
|
+
this.statusColor = "#ff6b6b";
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// Request minimal permission to get device labels
|
|
138
|
+
if (permissionStatus === 'prompt') {
|
|
139
|
+
const tempStream = await navigator.mediaDevices.getUserMedia({ video: true });
|
|
140
|
+
tempStream.getTracks().forEach(track => track.stop());
|
|
141
|
+
}
|
|
142
|
+
// Now enumerate devices with labels
|
|
143
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
144
|
+
this.availableCameras = devices.filter(device => device.kind === 'videoinput');
|
|
145
|
+
this.isMultipleCamerasAvailable = this.availableCameras.length > 1;
|
|
146
|
+
this.debugLog('📹 Available cameras:', {
|
|
147
|
+
count: this.availableCameras.length,
|
|
148
|
+
isMultipleCamerasAvailable: this.isMultipleCamerasAvailable,
|
|
149
|
+
cameras: this.availableCameras.map(cam => ({
|
|
150
|
+
id: cam.deviceId,
|
|
151
|
+
label: cam.label || 'Unknown Camera'
|
|
152
|
+
}))
|
|
153
|
+
});
|
|
154
|
+
// Set initial camera preference based on device type
|
|
155
|
+
this.setInitialCameraPreference();
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
this.debugLog('❌ Error enumerating cameras:', error);
|
|
159
|
+
this.handleCameraPermissionError(error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async checkCameraPermission() {
|
|
163
|
+
try {
|
|
164
|
+
if (!navigator.permissions) {
|
|
165
|
+
return 'prompt'; // Assume we need to prompt on older browsers
|
|
166
|
+
}
|
|
167
|
+
const permission = await navigator.permissions.query({ name: 'camera' });
|
|
168
|
+
return permission.state;
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
this.debugLog('⚠️ Could not check camera permission:', error);
|
|
172
|
+
return 'prompt';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
handleCameraPermissionError(error) {
|
|
176
|
+
if (error.name === 'NotAllowedError') {
|
|
177
|
+
this.statusMessage = "Permiso de cámara denegado. Active el permiso en configuración.";
|
|
178
|
+
this.statusColor = "#ff6b6b";
|
|
179
|
+
this.availableCameras = [];
|
|
180
|
+
this.isMultipleCamerasAvailable = false;
|
|
181
|
+
}
|
|
182
|
+
else if (error.name === 'NotFoundError') {
|
|
183
|
+
this.statusMessage = "No se encontraron cámaras disponibles.";
|
|
184
|
+
this.statusColor = "#ff6b6b";
|
|
185
|
+
this.availableCameras = [];
|
|
186
|
+
this.isMultipleCamerasAvailable = false;
|
|
187
|
+
}
|
|
188
|
+
else if (error.name === 'NotReadableError') {
|
|
189
|
+
this.statusMessage = "Cámara en uso por otra aplicación.";
|
|
190
|
+
this.statusColor = "#ff6b6b";
|
|
191
|
+
this.availableCameras = [];
|
|
192
|
+
this.isMultipleCamerasAvailable = false;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
this.statusMessage = "Error al acceder a las cámaras.";
|
|
196
|
+
this.statusColor = "#ff6b6b";
|
|
197
|
+
this.availableCameras = [];
|
|
198
|
+
this.isMultipleCamerasAvailable = false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
setInitialCameraPreference() {
|
|
202
|
+
if (this.availableCameras.length === 0)
|
|
203
|
+
return;
|
|
204
|
+
// Apply user preference for camera selection
|
|
205
|
+
if (this.preferredCamera === 'front') {
|
|
206
|
+
// User explicitly wants front camera
|
|
207
|
+
this.preferredCameraFacing = 'user';
|
|
208
|
+
const frontCamera = this.availableCameras.find(camera => camera.label.toLowerCase().includes('front') ||
|
|
209
|
+
camera.label.toLowerCase().includes('user') ||
|
|
210
|
+
camera.label.toLowerCase().includes('selfie') ||
|
|
211
|
+
!camera.label.toLowerCase().includes('back') && !camera.label.toLowerCase().includes('rear'));
|
|
212
|
+
if (frontCamera) {
|
|
213
|
+
this.selectedCameraId = frontCamera.deviceId;
|
|
214
|
+
this.debugLog('👤 User selected front camera:', frontCamera.label);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
this.selectedCameraId = this.availableCameras[0].deviceId;
|
|
218
|
+
this.debugLog('⚠️ Front camera not found, using first available:', this.availableCameras[0].label);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else if (this.preferredCamera === 'back') {
|
|
222
|
+
// User explicitly wants back camera
|
|
223
|
+
this.preferredCameraFacing = 'environment';
|
|
224
|
+
const backCamera = this.availableCameras.find(camera => camera.label.toLowerCase().includes('back') ||
|
|
225
|
+
camera.label.toLowerCase().includes('rear') ||
|
|
226
|
+
camera.label.toLowerCase().includes('environment'));
|
|
227
|
+
if (backCamera) {
|
|
228
|
+
this.selectedCameraId = backCamera.deviceId;
|
|
229
|
+
this.debugLog('📷 User selected back camera:', backCamera.label);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
this.selectedCameraId = this.availableCameras[0].deviceId;
|
|
233
|
+
this.debugLog('⚠️ Back camera not found, using first available:', this.availableCameras[0].label);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
// Auto mode - use device type to determine best camera
|
|
238
|
+
if (this.deviceType === 'mobile' || this.deviceType === 'tablet') {
|
|
239
|
+
// For mobile/tablet, prefer rear camera for document scanning
|
|
240
|
+
this.preferredCameraFacing = 'environment';
|
|
241
|
+
const rearCamera = this.availableCameras.find(camera => camera.label.toLowerCase().includes('back') ||
|
|
242
|
+
camera.label.toLowerCase().includes('rear') ||
|
|
243
|
+
camera.label.toLowerCase().includes('environment'));
|
|
244
|
+
if (rearCamera) {
|
|
245
|
+
this.selectedCameraId = rearCamera.deviceId;
|
|
246
|
+
this.debugLog('📱 Auto-selected rear camera for mobile:', rearCamera.label);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
this.selectedCameraId = this.availableCameras[0].deviceId;
|
|
250
|
+
this.debugLog('📱 Rear camera not found, using first available:', this.availableCameras[0].label);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
// For desktop, use first available camera (usually the only one)
|
|
255
|
+
this.selectedCameraId = this.availableCameras[0].deviceId;
|
|
256
|
+
this.debugLog('💻 Auto-selected desktop camera:', this.availableCameras[0].label);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
loadCameraPreference() {
|
|
261
|
+
try {
|
|
262
|
+
const saved = localStorage.getItem('jaak-stamps-camera-preference');
|
|
263
|
+
if (saved) {
|
|
264
|
+
const preference = JSON.parse(saved);
|
|
265
|
+
// Validate that the saved camera is still available
|
|
266
|
+
const isStillAvailable = this.availableCameras.some(camera => camera.deviceId === preference.cameraId);
|
|
267
|
+
if (isStillAvailable) {
|
|
268
|
+
this.selectedCameraId = preference.cameraId;
|
|
269
|
+
this.preferredCameraFacing = preference.facing;
|
|
270
|
+
this.debugLog('💾 Loaded camera preference:', preference);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
this.debugLog('⚠️ Error loading camera preference:', error);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
saveCameraPreference() {
|
|
279
|
+
try {
|
|
280
|
+
const preference = {
|
|
281
|
+
cameraId: this.selectedCameraId,
|
|
282
|
+
facing: this.preferredCameraFacing,
|
|
283
|
+
timestamp: Date.now()
|
|
284
|
+
};
|
|
285
|
+
localStorage.setItem('jaak-stamps-camera-preference', JSON.stringify(preference));
|
|
286
|
+
this.debugLog('💾 Saved camera preference:', preference);
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
this.debugLog('⚠️ Error saving camera preference:', error);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
async switchCamera(cameraId) {
|
|
293
|
+
if (!this.isVideoActive || this.selectedCameraId === cameraId)
|
|
294
|
+
return;
|
|
295
|
+
try {
|
|
296
|
+
// Check if the selected camera is still available
|
|
297
|
+
const selectedCamera = this.availableCameras.find(cam => cam.deviceId === cameraId);
|
|
298
|
+
if (!selectedCamera) {
|
|
299
|
+
this.debugLog('❌ Selected camera not found, re-enumerating...');
|
|
300
|
+
await this.enumerateAndDetectCameras();
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
// Show loading state
|
|
304
|
+
this.statusMessage = "Cambiando cámara...";
|
|
305
|
+
this.statusColor = "#007bff";
|
|
306
|
+
// Stop current stream
|
|
307
|
+
if (this.videoStream) {
|
|
308
|
+
this.videoStream.getTracks().forEach(track => track.stop());
|
|
309
|
+
}
|
|
310
|
+
// Update selected camera
|
|
311
|
+
this.selectedCameraId = cameraId;
|
|
312
|
+
// Update facing mode preference
|
|
313
|
+
const isRearCamera = selectedCamera.label.toLowerCase().includes('back') ||
|
|
314
|
+
selectedCamera.label.toLowerCase().includes('rear') ||
|
|
315
|
+
selectedCamera.label.toLowerCase().includes('environment');
|
|
316
|
+
this.preferredCameraFacing = isRearCamera ? 'environment' : 'user';
|
|
317
|
+
// Save preference
|
|
318
|
+
this.saveCameraPreference();
|
|
319
|
+
// Setup new camera with error handling
|
|
320
|
+
await this.setupCameraWithRetry();
|
|
321
|
+
this.debugLog('🔄 Switched to camera:', selectedCamera.label);
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
this.debugLog('❌ Error switching camera:', error);
|
|
325
|
+
this.handleCameraPermissionError(error);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
async setupCameraWithRetry(maxRetries = 3) {
|
|
329
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
330
|
+
try {
|
|
331
|
+
await this.setupCamera();
|
|
332
|
+
return; // Success
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
this.debugLog(`❌ Camera setup attempt ${attempt} failed:`, error);
|
|
336
|
+
if (attempt === maxRetries) {
|
|
337
|
+
// Last attempt failed, handle the error
|
|
338
|
+
this.handleCameraPermissionError(error);
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
// Wait before retrying
|
|
342
|
+
await new Promise(resolve => setTimeout(resolve, 500 * attempt));
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
toggleCameraSelector() {
|
|
347
|
+
this.showCameraSelector = !this.showCameraSelector;
|
|
348
|
+
this.debugLog('📹 Camera selector toggled:', {
|
|
349
|
+
showCameraSelector: this.showCameraSelector,
|
|
350
|
+
isMultipleCamerasAvailable: this.isMultipleCamerasAvailable,
|
|
351
|
+
availableCameras: this.availableCameras.length,
|
|
352
|
+
isVideoActive: this.isVideoActive
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
async flipCamera() {
|
|
356
|
+
if (!this.isMultipleCamerasAvailable)
|
|
357
|
+
return;
|
|
358
|
+
const currentIndex = this.availableCameras.findIndex(camera => camera.deviceId === this.selectedCameraId);
|
|
359
|
+
const nextIndex = (currentIndex + 1) % this.availableCameras.length;
|
|
360
|
+
const nextCamera = this.availableCameras[nextIndex];
|
|
361
|
+
await this.switchCamera(nextCamera.deviceId);
|
|
362
|
+
}
|
|
92
363
|
async componentDidLoad() {
|
|
93
364
|
this.validateMaskSize();
|
|
94
365
|
this.validateCropMargin();
|
|
366
|
+
this.validatePreferredCamera();
|
|
367
|
+
await this.detectDeviceTypeAndCameras();
|
|
95
368
|
if (!window.ort) {
|
|
96
369
|
const script = document.createElement('script');
|
|
97
370
|
script.src = 'https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.min.js';
|
|
@@ -293,6 +566,35 @@ export class JaakStamps {
|
|
|
293
566
|
this.completeProcess(true);
|
|
294
567
|
}
|
|
295
568
|
}
|
|
569
|
+
async getCameraInfo() {
|
|
570
|
+
return {
|
|
571
|
+
availableCameras: this.availableCameras.map(camera => ({
|
|
572
|
+
id: camera.deviceId,
|
|
573
|
+
label: camera.label || 'Unknown Camera',
|
|
574
|
+
selected: camera.deviceId === this.selectedCameraId
|
|
575
|
+
})),
|
|
576
|
+
selectedCameraId: this.selectedCameraId,
|
|
577
|
+
deviceType: this.deviceType,
|
|
578
|
+
isMultipleCamerasAvailable: this.isMultipleCamerasAvailable,
|
|
579
|
+
preferredFacing: this.preferredCameraFacing,
|
|
580
|
+
userPreferredCamera: this.preferredCamera
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
async setPreferredCamera(camera) {
|
|
584
|
+
this.preferredCamera = camera;
|
|
585
|
+
this.debugLog('🎯 Camera preference changed to:', camera);
|
|
586
|
+
// Re-detect and apply new camera preference
|
|
587
|
+
await this.enumerateAndDetectCameras();
|
|
588
|
+
// If video is active, switch to the new preferred camera
|
|
589
|
+
if (this.isVideoActive && this.selectedCameraId) {
|
|
590
|
+
await this.switchCamera(this.selectedCameraId);
|
|
591
|
+
}
|
|
592
|
+
return {
|
|
593
|
+
success: true,
|
|
594
|
+
selectedCamera: this.selectedCameraId,
|
|
595
|
+
availableCameras: this.availableCameras.length
|
|
596
|
+
};
|
|
597
|
+
}
|
|
296
598
|
async loadMobileNetModel() {
|
|
297
599
|
try {
|
|
298
600
|
this.debugLog('🤖 Loading MobileNet model...');
|
|
@@ -409,18 +711,38 @@ export class JaakStamps {
|
|
|
409
711
|
}
|
|
410
712
|
async getMaxResolution() {
|
|
411
713
|
try {
|
|
412
|
-
//
|
|
714
|
+
// Build constraints with selected camera if available
|
|
715
|
+
const videoConstraints = {};
|
|
716
|
+
if (this.selectedCameraId) {
|
|
717
|
+
videoConstraints.deviceId = { exact: this.selectedCameraId };
|
|
718
|
+
}
|
|
719
|
+
else if (this.preferredCameraFacing) {
|
|
720
|
+
videoConstraints.facingMode = this.preferredCameraFacing;
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
videoConstraints.facingMode = "environment";
|
|
724
|
+
}
|
|
725
|
+
// Get temporary stream to access capabilities
|
|
413
726
|
const tempStream = await navigator.mediaDevices.getUserMedia({
|
|
414
|
-
video:
|
|
727
|
+
video: videoConstraints
|
|
415
728
|
});
|
|
416
729
|
const videoTrack = tempStream.getVideoTracks()[0];
|
|
417
730
|
const capabilities = videoTrack.getCapabilities();
|
|
418
731
|
// Detener el stream temporal
|
|
419
732
|
tempStream.getTracks().forEach(track => track.stop());
|
|
420
|
-
//
|
|
421
|
-
const constraints = {
|
|
422
|
-
|
|
423
|
-
|
|
733
|
+
// Build constraints with resolution optimized for tablets
|
|
734
|
+
const constraints = {};
|
|
735
|
+
// Set camera selection constraints
|
|
736
|
+
if (this.selectedCameraId) {
|
|
737
|
+
constraints.deviceId = { exact: this.selectedCameraId };
|
|
738
|
+
}
|
|
739
|
+
else if (this.preferredCameraFacing) {
|
|
740
|
+
constraints.facingMode = this.preferredCameraFacing;
|
|
741
|
+
}
|
|
742
|
+
else {
|
|
743
|
+
constraints.facingMode = "environment";
|
|
744
|
+
}
|
|
745
|
+
;
|
|
424
746
|
if (capabilities.width && capabilities.height) {
|
|
425
747
|
// Limitar resolución máxima para tablets para evitar problemas de rendimiento
|
|
426
748
|
const maxWidth = Math.min(capabilities.width.max, 1920);
|
|
@@ -447,13 +769,23 @@ export class JaakStamps {
|
|
|
447
769
|
}
|
|
448
770
|
catch (err) {
|
|
449
771
|
this.debugLog('⚠️ Could not get capabilities, using fallback');
|
|
450
|
-
//
|
|
772
|
+
// Optimized fallback for tablets
|
|
451
773
|
const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
|
|
452
|
-
|
|
453
|
-
facingMode: "environment",
|
|
774
|
+
const fallbackConstraints = {
|
|
454
775
|
width: { ideal: isTablet ? 1280 : 1920 },
|
|
455
776
|
height: { ideal: isTablet ? 720 : 1080 }
|
|
456
777
|
};
|
|
778
|
+
// Add camera selection to fallback
|
|
779
|
+
if (this.selectedCameraId) {
|
|
780
|
+
fallbackConstraints.deviceId = { exact: this.selectedCameraId };
|
|
781
|
+
}
|
|
782
|
+
else if (this.preferredCameraFacing) {
|
|
783
|
+
fallbackConstraints.facingMode = this.preferredCameraFacing;
|
|
784
|
+
}
|
|
785
|
+
else {
|
|
786
|
+
fallbackConstraints.facingMode = "environment";
|
|
787
|
+
}
|
|
788
|
+
return fallbackConstraints;
|
|
457
789
|
}
|
|
458
790
|
}
|
|
459
791
|
async setupCamera() {
|
|
@@ -488,8 +820,7 @@ export class JaakStamps {
|
|
|
488
820
|
}
|
|
489
821
|
catch (err) {
|
|
490
822
|
this.debugLog("❌ No se pudo acceder a la cámara:", err);
|
|
491
|
-
this.
|
|
492
|
-
this.statusColor = "#ff6b6b";
|
|
823
|
+
this.handleCameraPermissionError(err);
|
|
493
824
|
}
|
|
494
825
|
}
|
|
495
826
|
preprocess(video) {
|
|
@@ -1039,7 +1370,20 @@ export class JaakStamps {
|
|
|
1039
1370
|
this.cleanup();
|
|
1040
1371
|
}
|
|
1041
1372
|
render() {
|
|
1042
|
-
return (h("div", { key: '
|
|
1373
|
+
return (h("div", { key: 'b90673f523dbf112786eb7184f56415055765c0c', class: "detector-container" }, h("div", { key: '925c5c886e9af53b460281244958e722de670a70', class: "video-container" }, h("video", { key: '4a0074e33a81b4694c6c99e3ece256c1ac8fe1d5', ref: el => this.videoRef = el, autoplay: true, muted: true, playsinline: true, class: this.shouldMirrorVideo ? 'mirror' : '', style: { display: this.isVideoActive ? 'block' : 'none' } }), h("canvas", { key: 'a7b7f3b35c0535c11f6a4a155502dbe016f590b7', ref: el => this.canvasRef = el, class: this.shouldMirrorVideo ? 'mirror' : '' }), this.isMaskReady && (h("div", { key: '695b6a2f97e29b0b9c5b9d43682a951caff376a1', class: "overlay-mask" }, h("div", { key: '768875c39d5917c6a04306037d03d9e1aed114bd', class: "card-outline" }, h("div", { key: 'a56536deb7b8c99145d1bef6fee84e5801798644', class: "side side-top" }), h("div", { key: 'df413058c7e787f9c8a95a429a4f7186de07f5f6', class: "side side-right" }), h("div", { key: '37e074e3d4c914457f97720f9ab1f1ac2c70c4f1', class: "side side-bottom" }), h("div", { key: '772d3d40925c75ba5d39e2e7dd6405f7cc88d292', class: "side side-left" }), h("div", { key: 'd4e624782b3f4b4b8dbb8286b3acf003e433928c', class: "corner corner-tl" }), h("div", { key: '63f0ccfbbe3c1d413ca6912f36cab4afa6334bb2', class: "corner corner-tr" }), h("div", { key: '20012a50fe3d98ddfa669f5283a871c757522797', class: "corner corner-bl" }), h("div", { key: '9d82646bd08a6ca2b8c5782629fc68fd93cf1287', class: "corner corner-br" }), !this.showFlipAnimation && !this.showSuccessAnimation && (h("div", { key: '79fcbdb52e434a45aa6f2748d6d84500beb2e844', class: "guide-text" }, this.statusMessage))), this.captureStep === 'back' && !this.showFlipAnimation && !this.showSuccessAnimation && (h("button", { key: '16e587d645e2489a3410fe80bfc014738f08f02f', class: "skip-button", onClick: () => this.skipBackCapture(), type: "button" }, "Saltar reverso")), this.isVideoActive && (h("div", { key: 'd46d6881a9e1b63bdd849f5a8c6e96a2caefdefb', class: "camera-controls" }, this.isMultipleCamerasAvailable && (h("button", { key: 'afb4b44d691471f8af6e894e061aecb6c82259da', class: "flip-camera-button", onClick: () => this.flipCamera(), type: "button", title: "Cambiar c\u00E1mara" }, "Girar c\u00E1mara")), h("button", { key: '4e0680c2da9e6cc70b5880e8f5db9830c080acf9', class: "camera-selector-button", onClick: () => this.toggleCameraSelector(), type: "button", title: "Seleccionar c\u00E1mara" }, "C\u00E1maras"), this.debug && (h("div", { key: 'fc59922452a216273f742d3158559f6b2a1da43e', style: {
|
|
1374
|
+
position: 'absolute',
|
|
1375
|
+
top: '50px',
|
|
1376
|
+
right: '0',
|
|
1377
|
+
background: 'rgba(0,0,0,0.8)',
|
|
1378
|
+
color: 'white',
|
|
1379
|
+
padding: '8px',
|
|
1380
|
+
fontSize: '10px',
|
|
1381
|
+
borderRadius: '4px',
|
|
1382
|
+
whiteSpace: 'nowrap'
|
|
1383
|
+
} }, "C\u00E1maras: ", this.availableCameras.length, h("br", { key: '8f112283d1e0518a395dc6d94e1caa46fee0a86b' }), "M\u00FAltiples: ", this.isMultipleCamerasAvailable ? 'Sí' : 'No', h("br", { key: 'aacfd3ee868ee5d0819ce5ef693e3ef384867332' }), "Selector: ", this.showCameraSelector ? 'Visible' : 'Oculto', h("br", { key: '9927df7f56583c7388cee25e13526efc7e032eb1' }), "Video: ", this.isVideoActive ? 'Activo' : 'Inactivo')))), this.showCameraSelector && this.availableCameras.length > 0 && (h("div", { key: 'c2914bf7f3175b8f0ddab977abbdefe3022d7d29', class: "camera-selector-dropdown" }, h("div", { key: '0b5397e77ff33944f3620d78b1ab41275dffd7ac', class: "camera-selector-header" }, h("span", { key: '78f0fb8e34a0cf2d16138522a98cbdb9eefd671f' }, "Seleccionar C\u00E1mara"), h("button", { key: '0d4ea7b191d61d1d9b9c35462ce336148be73fcb', class: "close-selector", onClick: () => this.toggleCameraSelector(), type: "button" }, "\u00D7")), h("div", { key: 'c16c7a106493ef7633a4cd35b06a4f45327a2e23', class: "camera-list" }, this.availableCameras.map((camera) => (h("button", { key: camera.deviceId, class: `camera-option ${this.selectedCameraId === camera.deviceId ? 'selected' : ''}`, onClick: () => {
|
|
1384
|
+
this.switchCamera(camera.deviceId);
|
|
1385
|
+
this.toggleCameraSelector();
|
|
1386
|
+
}, type: "button" }, h("span", { class: "camera-label" }, camera.label || `Cámara ${this.availableCameras.indexOf(camera) + 1}`), this.selectedCameraId === camera.deviceId && (h("span", { class: "selected-indicator" }, "\u2713")))))), h("div", { key: '11d6f980c3995a8414da5f7e6921f963ca72aed4', class: "device-info" }, h("small", { key: '78f5ff030f9e6e5021234a246599eb459b05d9f7' }, "Dispositivo: ", this.deviceType)))))), this.isCapturing && (h("div", { key: 'ef7d32491d8bdb94b2d6456420c2ddbc80f03d81', class: "capture-animation" })), this.showFlipAnimation && (h("div", { key: 'cfb5868ee75a9d1d1604c52f6fce1241090e4ac2', class: "flip-animation" }, h("div", { key: '1b41035e63f88434aba6699d4e68e06bea2c1529', class: "id-card-icon" }), h("div", { key: '4e83af9d0d39ce37b7448c4a0783b60b42b858e2', class: "flip-text" }, "\u00A1Voltea tu identificaci\u00F3n!"))), this.showSuccessAnimation && (h("div", { key: 'c7911e8be74b0fc7d7d18d7dcb52374645ca5f12', class: "success-animation" }, h("div", { key: '18e5ea5cfa3eb35fe3b99c12e6fab8e27e09e85e', class: "check-icon" }), h("div", { key: '490d8fcd6540c3b4fdc95f7fb5e6f6697722c9ac', class: "success-text" }, "\u00A1Proceso completado!"))), this.isLoading && (h("div", { key: 'f7fbfec6be2d8e0dc4e522b85b7d67897575cf0e', class: "loading-overlay" }, h("div", { key: '8282b92f19da6a9c7d22a64a0929b2b4d67c46be', class: "loading-spinner" }), h("div", { key: '7880b689297eb9d80a9b0023ba7933148fd8710a', class: "loading-text" }, this.statusMessage))), h("div", { key: '887c951fb03097171d9bd466fe24e36d11a49954', class: "watermark" }, h("img", { key: '314c9c172a4c6795c825741ea6f02b0e1186e93d', src: "https://storage.googleapis.com/jaak-static/commons/powered-by-jaak.png", alt: "Powered by Jaak" })))));
|
|
1043
1387
|
}
|
|
1044
1388
|
static get is() { return "jaak-stamps"; }
|
|
1045
1389
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1154,6 +1498,26 @@ export class JaakStamps {
|
|
|
1154
1498
|
"setter": false,
|
|
1155
1499
|
"reflect": false,
|
|
1156
1500
|
"defaultValue": "false"
|
|
1501
|
+
},
|
|
1502
|
+
"preferredCamera": {
|
|
1503
|
+
"type": "string",
|
|
1504
|
+
"attribute": "preferred-camera",
|
|
1505
|
+
"mutable": false,
|
|
1506
|
+
"complexType": {
|
|
1507
|
+
"original": "'auto' | 'front' | 'back'",
|
|
1508
|
+
"resolved": "\"auto\" | \"back\" | \"front\"",
|
|
1509
|
+
"references": {}
|
|
1510
|
+
},
|
|
1511
|
+
"required": false,
|
|
1512
|
+
"optional": false,
|
|
1513
|
+
"docs": {
|
|
1514
|
+
"tags": [],
|
|
1515
|
+
"text": ""
|
|
1516
|
+
},
|
|
1517
|
+
"getter": false,
|
|
1518
|
+
"setter": false,
|
|
1519
|
+
"reflect": false,
|
|
1520
|
+
"defaultValue": "'auto'"
|
|
1157
1521
|
}
|
|
1158
1522
|
};
|
|
1159
1523
|
}
|
|
@@ -1176,7 +1540,11 @@ export class JaakStamps {
|
|
|
1176
1540
|
"isDetectionPaused": {},
|
|
1177
1541
|
"isLoading": {},
|
|
1178
1542
|
"isModelPreloaded": {},
|
|
1179
|
-
"isMaskReady": {}
|
|
1543
|
+
"isMaskReady": {},
|
|
1544
|
+
"availableCameras": {},
|
|
1545
|
+
"selectedCameraId": {},
|
|
1546
|
+
"showCameraSelector": {},
|
|
1547
|
+
"isMultipleCamerasAvailable": {}
|
|
1180
1548
|
};
|
|
1181
1549
|
}
|
|
1182
1550
|
static get events() {
|
|
@@ -1349,6 +1717,44 @@ export class JaakStamps {
|
|
|
1349
1717
|
"text": "",
|
|
1350
1718
|
"tags": []
|
|
1351
1719
|
}
|
|
1720
|
+
},
|
|
1721
|
+
"getCameraInfo": {
|
|
1722
|
+
"complexType": {
|
|
1723
|
+
"signature": "() => Promise<{ availableCameras: { id: string; label: string; selected: boolean; }[]; selectedCameraId: string; deviceType: \"mobile\" | \"desktop\" | \"tablet\"; isMultipleCamerasAvailable: boolean; preferredFacing: \"environment\" | \"user\"; userPreferredCamera: \"auto\" | \"front\" | \"back\"; }>",
|
|
1724
|
+
"parameters": [],
|
|
1725
|
+
"references": {
|
|
1726
|
+
"Promise": {
|
|
1727
|
+
"location": "global",
|
|
1728
|
+
"id": "global::Promise"
|
|
1729
|
+
}
|
|
1730
|
+
},
|
|
1731
|
+
"return": "Promise<{ availableCameras: { id: string; label: string; selected: boolean; }[]; selectedCameraId: string; deviceType: \"mobile\" | \"desktop\" | \"tablet\"; isMultipleCamerasAvailable: boolean; preferredFacing: \"environment\" | \"user\"; userPreferredCamera: \"auto\" | \"front\" | \"back\"; }>"
|
|
1732
|
+
},
|
|
1733
|
+
"docs": {
|
|
1734
|
+
"text": "",
|
|
1735
|
+
"tags": []
|
|
1736
|
+
}
|
|
1737
|
+
},
|
|
1738
|
+
"setPreferredCamera": {
|
|
1739
|
+
"complexType": {
|
|
1740
|
+
"signature": "(camera: \"auto\" | \"front\" | \"back\") => Promise<{ success: boolean; selectedCamera: string; availableCameras: number; }>",
|
|
1741
|
+
"parameters": [{
|
|
1742
|
+
"name": "camera",
|
|
1743
|
+
"type": "\"auto\" | \"front\" | \"back\"",
|
|
1744
|
+
"docs": ""
|
|
1745
|
+
}],
|
|
1746
|
+
"references": {
|
|
1747
|
+
"Promise": {
|
|
1748
|
+
"location": "global",
|
|
1749
|
+
"id": "global::Promise"
|
|
1750
|
+
}
|
|
1751
|
+
},
|
|
1752
|
+
"return": "Promise<{ success: boolean; selectedCamera: string; availableCameras: number; }>"
|
|
1753
|
+
},
|
|
1754
|
+
"docs": {
|
|
1755
|
+
"text": "",
|
|
1756
|
+
"tags": []
|
|
1757
|
+
}
|
|
1352
1758
|
}
|
|
1353
1759
|
};
|
|
1354
1760
|
}
|