@jaak.ai/stamps 2.0.0-dev.24 → 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.
Files changed (36) hide show
  1. package/README.md +50 -12
  2. package/dist/cjs/{index-DGM9-FNg.js → index-BfhtOB0D.js} +5 -2
  3. package/dist/cjs/index-BfhtOB0D.js.map +1 -0
  4. package/dist/cjs/jaak-stamps-webcomponent.cjs.js +2 -2
  5. package/dist/cjs/jaak-stamps.cjs.entry.js +385 -25
  6. package/dist/cjs/jaak-stamps.cjs.entry.js.map +1 -1
  7. package/dist/cjs/jaak-stamps.entry.cjs.js.map +1 -1
  8. package/dist/cjs/loader.cjs.js +2 -2
  9. package/dist/collection/components/my-component/my-component.css +227 -0
  10. package/dist/collection/components/my-component/my-component.js +467 -24
  11. package/dist/collection/components/my-component/my-component.js.map +1 -1
  12. package/dist/components/index.js +3 -0
  13. package/dist/components/index.js.map +1 -1
  14. package/dist/components/jaak-stamps.js +393 -25
  15. package/dist/components/jaak-stamps.js.map +1 -1
  16. package/dist/esm/{index-DqoVMnc7.js → index-BP1Q4KOg.js} +5 -2
  17. package/dist/esm/index-BP1Q4KOg.js.map +1 -0
  18. package/dist/esm/jaak-stamps-webcomponent.js +3 -3
  19. package/dist/esm/jaak-stamps.entry.js +385 -25
  20. package/dist/esm/jaak-stamps.entry.js.map +1 -1
  21. package/dist/esm/loader.js +3 -3
  22. package/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js +1 -1
  23. package/dist/jaak-stamps-webcomponent/jaak-stamps.entry.esm.js.map +1 -1
  24. package/dist/jaak-stamps-webcomponent/p-14eb13d8.entry.js +2 -0
  25. package/dist/jaak-stamps-webcomponent/p-14eb13d8.entry.js.map +1 -0
  26. package/dist/jaak-stamps-webcomponent/p-BP1Q4KOg.js +3 -0
  27. package/dist/jaak-stamps-webcomponent/p-BP1Q4KOg.js.map +1 -0
  28. package/dist/types/components/my-component/my-component.d.ts +37 -0
  29. package/dist/types/components.d.ts +18 -0
  30. package/package.json +1 -1
  31. package/dist/cjs/index-DGM9-FNg.js.map +0 -1
  32. package/dist/esm/index-DqoVMnc7.js.map +0 -1
  33. package/dist/jaak-stamps-webcomponent/p-0521d8f5.entry.js +0 -2
  34. package/dist/jaak-stamps-webcomponent/p-0521d8f5.entry.js.map +0 -1
  35. package/dist/jaak-stamps-webcomponent/p-DqoVMnc7.js +0 -3
  36. package/dist/jaak-stamps-webcomponent/p-DqoVMnc7.js.map +0 -1
@@ -5,6 +5,8 @@ export class JaakStamps {
5
5
  alignmentTolerance = 10; // Tolerancia en píxeles para considerar un lado alineado (escalado para 320x320)
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
+ 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)
8
10
  captureCompleted;
9
11
  isReady;
10
12
  isVideoActive = false;
@@ -30,6 +32,10 @@ export class JaakStamps {
30
32
  isLoading = false;
31
33
  isModelPreloaded = false;
32
34
  isMaskReady = false;
35
+ availableCameras = [];
36
+ selectedCameraId = null;
37
+ showCameraSelector = false;
38
+ isMultipleCamerasAvailable = false;
33
39
  videoRef;
34
40
  canvasRef;
35
41
  session;
@@ -40,6 +46,9 @@ export class JaakStamps {
40
46
  lastDetectedBox;
41
47
  mobileNetSession;
42
48
  mobileNetClassMap;
49
+ // Camera management properties
50
+ deviceType = 'desktop';
51
+ preferredCameraFacing = null;
43
52
  // Performance optimization properties
44
53
  frameSkipCounter = 0;
45
54
  FRAME_SKIP = 2; // Process every 3rd frame (reduces CPU by ~66%)
@@ -76,6 +85,13 @@ export class JaakStamps {
76
85
  this.cropMargin = 0;
77
86
  }
78
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
+ }
79
95
  emitReadyEvent() {
80
96
  const isDocumentReady = !!window.ort && this.isModelPreloaded;
81
97
  this.isReady.emit(isDocumentReady);
@@ -88,9 +104,267 @@ export class JaakStamps {
88
104
  const settings = videoTrack.getSettings();
89
105
  return settings.facingMode === 'environment';
90
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
+ }
91
363
  async componentDidLoad() {
92
364
  this.validateMaskSize();
93
365
  this.validateCropMargin();
366
+ this.validatePreferredCamera();
367
+ await this.detectDeviceTypeAndCameras();
94
368
  if (!window.ort) {
95
369
  const script = document.createElement('script');
96
370
  script.src = 'https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.min.js';
@@ -267,8 +541,10 @@ export class JaakStamps {
267
541
  // Configure ONNX Runtime with device-specific optimizations
268
542
  const sessionOptions = this.getSessionOptions();
269
543
  this.session = await window.ort.InferenceSession.create(modelPath, sessionOptions);
270
- // Preload MobileNet model and classes
271
- await this.loadMobileNetModel();
544
+ // Preload MobileNet model and classes only if classification is enabled
545
+ if (this.useDocumentClassification) {
546
+ await this.loadMobileNetModel();
547
+ }
272
548
  this.isModelPreloaded = true;
273
549
  this.isLoading = false;
274
550
  this.statusMessage = "Modelos precargados. Listo para comenzar detección";
@@ -290,6 +566,35 @@ export class JaakStamps {
290
566
  this.completeProcess(true);
291
567
  }
292
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
+ }
293
598
  async loadMobileNetModel() {
294
599
  try {
295
600
  this.debugLog('🤖 Loading MobileNet model...');
@@ -406,18 +711,38 @@ export class JaakStamps {
406
711
  }
407
712
  async getMaxResolution() {
408
713
  try {
409
- // Primero obtén un stream básico para acceder a las capacidades
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
410
726
  const tempStream = await navigator.mediaDevices.getUserMedia({
411
- video: { facingMode: "environment" }
727
+ video: videoConstraints
412
728
  });
413
729
  const videoTrack = tempStream.getVideoTracks()[0];
414
730
  const capabilities = videoTrack.getCapabilities();
415
731
  // Detener el stream temporal
416
732
  tempStream.getTracks().forEach(track => track.stop());
417
- // Construir restricciones con resolución optimizada para tablets
418
- const constraints = {
419
- facingMode: "environment"
420
- };
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
+ ;
421
746
  if (capabilities.width && capabilities.height) {
422
747
  // Limitar resolución máxima para tablets para evitar problemas de rendimiento
423
748
  const maxWidth = Math.min(capabilities.width.max, 1920);
@@ -444,13 +769,23 @@ export class JaakStamps {
444
769
  }
445
770
  catch (err) {
446
771
  this.debugLog('⚠️ Could not get capabilities, using fallback');
447
- // Fallback optimizado para tablets
772
+ // Optimized fallback for tablets
448
773
  const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
449
- return {
450
- facingMode: "environment",
774
+ const fallbackConstraints = {
451
775
  width: { ideal: isTablet ? 1280 : 1920 },
452
776
  height: { ideal: isTablet ? 720 : 1080 }
453
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;
454
789
  }
455
790
  }
456
791
  async setupCamera() {
@@ -485,8 +820,7 @@ export class JaakStamps {
485
820
  }
486
821
  catch (err) {
487
822
  this.debugLog("❌ No se pudo acceder a la cámara:", err);
488
- this.statusMessage = "Error: No se pudo acceder a la cámara.";
489
- this.statusColor = "#ff6b6b";
823
+ this.handleCameraPermissionError(err);
490
824
  }
491
825
  }
492
826
  preprocess(video) {
@@ -537,8 +871,8 @@ export class JaakStamps {
537
871
  this.debugLog('🤖 Loading detection model:', modelPath);
538
872
  const sessionOptions = this.getSessionOptions();
539
873
  this.session = await window.ort.InferenceSession.create(modelPath, sessionOptions);
540
- // Load MobileNet model if not already loaded
541
- if (!this.mobileNetSession) {
874
+ // Load MobileNet model if classification is enabled and not already loaded
875
+ if (this.useDocumentClassification && !this.mobileNetSession) {
542
876
  await this.loadMobileNetModel();
543
877
  }
544
878
  this.isModelPreloaded = true;
@@ -884,13 +1218,27 @@ export class JaakStamps {
884
1218
  // Captura del frente usando canvas reutilizado
885
1219
  this.capturedFullFrame = this.captureCanvas.toDataURL('image/png');
886
1220
  this.capturedCroppedId = croppedCanvas.toDataURL('image/png');
887
- // Classify the cropped document
888
- const classification = await this.classifyDocument(croppedCanvas);
889
- if (classification && classification.class === 'passport') {
890
- // If it's a passport, skip back capture since passports don't have a back side
891
- this.debugLog('📄 Passport detected - skipping back capture');
892
- this.completeProcess(true);
893
- return;
1221
+ // Check if document classification is enabled
1222
+ if (this.useDocumentClassification) {
1223
+ // Load MobileNet model if not loaded yet (lazy loading)
1224
+ if (!this.mobileNetSession) {
1225
+ try {
1226
+ await this.loadMobileNetModel();
1227
+ }
1228
+ catch (error) {
1229
+ this.debugLog('⚠️ Failed to load classification model, continuing without classification:', error);
1230
+ }
1231
+ }
1232
+ // Classify the cropped document if model is available
1233
+ if (this.mobileNetSession) {
1234
+ const classification = await this.classifyDocument(croppedCanvas);
1235
+ if (classification && classification.class === 'passport') {
1236
+ // If it's a passport, skip back capture since passports don't have a back side
1237
+ this.debugLog('📄 Passport detected - skipping back capture');
1238
+ this.completeProcess(true);
1239
+ return;
1240
+ }
1241
+ }
894
1242
  }
895
1243
  // For other IDs, continue with normal flow (back capture)
896
1244
  this.captureStep = 'back';
@@ -1022,7 +1370,20 @@ export class JaakStamps {
1022
1370
  this.cleanup();
1023
1371
  }
1024
1372
  render() {
1025
- return (h("div", { key: 'd6cd4225500c44e5c7fb4f2b3dc453a055467066', class: "detector-container" }, h("div", { key: '6bd49b0bcd686648aeffb8fb95203dc0779f1d8a', class: "video-container" }, h("video", { key: 'd2666ce9d1f5b84703ac86fd4eb901f4298ed7d5', ref: el => this.videoRef = el, autoplay: true, muted: true, playsinline: true, class: this.shouldMirrorVideo ? 'mirror' : '', style: { display: this.isVideoActive ? 'block' : 'none' } }), h("canvas", { key: 'e997f063450d81d2a15398f0761c9d06c28a85c9', ref: el => this.canvasRef = el, class: this.shouldMirrorVideo ? 'mirror' : '' }), this.isMaskReady && (h("div", { key: '4ccb8bf05091a7173255181eae1a8699fe512b56', class: "overlay-mask" }, h("div", { key: 'b35defa8c207b05e41d64c8e1eefc905d31fad55', class: "card-outline" }, h("div", { key: '6ed8dad63d6d79c1bb4a64f0b28467f5b29d778a', class: "side side-top" }), h("div", { key: '403d4a5ba681a58ad1870a4339e19b4f037a8795', class: "side side-right" }), h("div", { key: '3cb3276bb184a4b76419b4cb0b4fcb151a4df631', class: "side side-bottom" }), h("div", { key: 'ed7c9bec0e708ab282ba8b24a08d21b8126af27e', class: "side side-left" }), h("div", { key: '157be211355bf9260dc7a73d03831dbb1a2945e3', class: "corner corner-tl" }), h("div", { key: 'b19af5f319333ff05f981063af939d2c4cfc9b5f', class: "corner corner-tr" }), h("div", { key: '6fcd3e2c8842261dcd32c36e6df5b2f3dd0c8fc8', class: "corner corner-bl" }), h("div", { key: '7caab5eaee62f3f9039075b3748083c89c8127e0', class: "corner corner-br" }), !this.showFlipAnimation && !this.showSuccessAnimation && (h("div", { key: 'e3dd42ddb75b22aeef438d8651955f3dc039f00c', class: "guide-text" }, this.statusMessage))), this.captureStep === 'back' && !this.showFlipAnimation && !this.showSuccessAnimation && (h("button", { key: '54b8651817cd52bad2f34ac1413a4b1e21166cee', class: "skip-button", onClick: () => this.skipBackCapture(), type: "button" }, "Saltar reverso")))), this.isCapturing && (h("div", { key: '853707a4fa71eeacbee7985e619fca80d6522cbd', class: "capture-animation" })), this.showFlipAnimation && (h("div", { key: '246ed3f5dc57ee57345105cdebe5f950d5ff4c90', class: "flip-animation" }, h("div", { key: 'f03c6c87c8f5e98a32176cca061d369a521da2e8', class: "id-card-icon" }), h("div", { key: 'e357785b076a9e41ea4f9b3d9c14e847bacc9604', class: "flip-text" }, "\u00A1Voltea tu identificaci\u00F3n!"))), this.showSuccessAnimation && (h("div", { key: 'df3adaaecd3d547938638c58ccc0e89f8325fc23', class: "success-animation" }, h("div", { key: 'a023985b8afd6ed72f9e1c2ee63e2c7ba9fb960b', class: "check-icon" }), h("div", { key: '739ff7f329f2131061a6860529c07c8819800aab', class: "success-text" }, "\u00A1Proceso completado!"))), this.isLoading && (h("div", { key: '9b02df640528a19cb15e5dbabf9ecb43afbceffa', class: "loading-overlay" }, h("div", { key: '3652c8e355ea7fe623c478229bf548bdf30e399a', class: "loading-spinner" }), h("div", { key: '334f4469b5672f6af78b8679c15ed8c59ecefa85', class: "loading-text" }, this.statusMessage))), h("div", { key: 'a0b7c9b92771cff96e97bd67da2fd3090b080f8a', class: "watermark" }, h("img", { key: 'b5c8f0de1d8138d4a0c80526fd33b2daefa86b16', src: "https://storage.googleapis.com/jaak-static/commons/powered-by-jaak.png", alt: "Powered by Jaak" })))));
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" })))));
1026
1387
  }
1027
1388
  static get is() { return "jaak-stamps"; }
1028
1389
  static get encapsulation() { return "shadow"; }
@@ -1117,6 +1478,46 @@ export class JaakStamps {
1117
1478
  "setter": false,
1118
1479
  "reflect": false,
1119
1480
  "defaultValue": "0"
1481
+ },
1482
+ "useDocumentClassification": {
1483
+ "type": "boolean",
1484
+ "attribute": "use-document-classification",
1485
+ "mutable": false,
1486
+ "complexType": {
1487
+ "original": "boolean",
1488
+ "resolved": "boolean",
1489
+ "references": {}
1490
+ },
1491
+ "required": false,
1492
+ "optional": false,
1493
+ "docs": {
1494
+ "tags": [],
1495
+ "text": ""
1496
+ },
1497
+ "getter": false,
1498
+ "setter": false,
1499
+ "reflect": false,
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'"
1120
1521
  }
1121
1522
  };
1122
1523
  }
@@ -1139,7 +1540,11 @@ export class JaakStamps {
1139
1540
  "isDetectionPaused": {},
1140
1541
  "isLoading": {},
1141
1542
  "isModelPreloaded": {},
1142
- "isMaskReady": {}
1543
+ "isMaskReady": {},
1544
+ "availableCameras": {},
1545
+ "selectedCameraId": {},
1546
+ "showCameraSelector": {},
1547
+ "isMultipleCamerasAvailable": {}
1143
1548
  };
1144
1549
  }
1145
1550
  static get events() {
@@ -1312,6 +1717,44 @@ export class JaakStamps {
1312
1717
  "text": "",
1313
1718
  "tags": []
1314
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
+ }
1315
1758
  }
1316
1759
  };
1317
1760
  }