@jaak.ai/stamps 2.0.0-beta.3 → 2.0.0-dev.18

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 +19 -104
  2. package/dist/cjs/{index-BfhtOB0D.js → index-DGM9-FNg.js} +2 -5
  3. package/dist/cjs/index-DGM9-FNg.js.map +1 -0
  4. package/dist/cjs/jaak-stamps-webcomponent.cjs.js +2 -2
  5. package/dist/cjs/jaak-stamps.cjs.entry.js +39 -732
  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 +7 -237
  10. package/dist/collection/components/my-component/my-component.js +38 -855
  11. package/dist/collection/components/my-component/my-component.js.map +1 -1
  12. package/dist/components/index.js +0 -3
  13. package/dist/components/index.js.map +1 -1
  14. package/dist/components/jaak-stamps.js +39 -743
  15. package/dist/components/jaak-stamps.js.map +1 -1
  16. package/dist/esm/{index-BP1Q4KOg.js → index-DqoVMnc7.js} +2 -5
  17. package/dist/esm/index-DqoVMnc7.js.map +1 -0
  18. package/dist/esm/jaak-stamps-webcomponent.js +3 -3
  19. package/dist/esm/jaak-stamps.entry.js +39 -732
  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-4688150a.entry.js +2 -0
  25. package/dist/jaak-stamps-webcomponent/p-4688150a.entry.js.map +1 -0
  26. package/dist/jaak-stamps-webcomponent/p-DqoVMnc7.js +3 -0
  27. package/dist/jaak-stamps-webcomponent/p-DqoVMnc7.js.map +1 -0
  28. package/dist/types/components/my-component/my-component.d.ts +2 -54
  29. package/dist/types/components.d.ts +0 -34
  30. package/package.json +1 -1
  31. package/dist/cjs/index-BfhtOB0D.js.map +0 -1
  32. package/dist/esm/index-BP1Q4KOg.js.map +0 -1
  33. package/dist/jaak-stamps-webcomponent/p-14eb13d8.entry.js +0 -2
  34. package/dist/jaak-stamps-webcomponent/p-14eb13d8.entry.js.map +0 -1
  35. package/dist/jaak-stamps-webcomponent/p-BP1Q4KOg.js +0 -3
  36. package/dist/jaak-stamps-webcomponent/p-BP1Q4KOg.js.map +0 -1
@@ -3,10 +3,6 @@ export class JaakStamps {
3
3
  el;
4
4
  debug = false;
5
5
  alignmentTolerance = 10; // Tolerancia en píxeles para considerar un lado alineado (escalado para 320x320)
6
- maskSize = 90; // Porcentaje del video que ocupará la máscara (default 90%)
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)
10
6
  captureCompleted;
11
7
  isReady;
12
8
  isVideoActive = false;
@@ -31,11 +27,6 @@ export class JaakStamps {
31
27
  isDetectionPaused = false;
32
28
  isLoading = false;
33
29
  isModelPreloaded = false;
34
- isMaskReady = false;
35
- availableCameras = [];
36
- selectedCameraId = null;
37
- showCameraSelector = false;
38
- isMultipleCamerasAvailable = false;
39
30
  videoRef;
40
31
  canvasRef;
41
32
  session;
@@ -44,11 +35,6 @@ export class JaakStamps {
44
35
  animationId;
45
36
  hasScreenshotTaken = false;
46
37
  lastDetectedBox;
47
- mobileNetSession;
48
- mobileNetClassMap;
49
- // Camera management properties
50
- deviceType = 'desktop';
51
- preferredCameraFacing = null;
52
38
  // Performance optimization properties
53
39
  frameSkipCounter = 0;
54
40
  FRAME_SKIP = 2; // Process every 3rd frame (reduces CPU by ~66%)
@@ -61,37 +47,16 @@ export class JaakStamps {
61
47
  preprocessCtx;
62
48
  captureCanvas;
63
49
  captureCtx;
64
- MODEL_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/ddmyp-v1.onnx";
65
- MOBILENET_MODEL_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/cdmmp-v1.onnx";
66
- MOBILENET_CLASSES_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/cdmmp-v1.json";
50
+ MODEL_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/detector-nano.onnx";
67
51
  INPUT_SIZE = 320;
68
52
  CONFIDENCE_THRESHOLD = 0.6;
69
- // ISO/IEC 7810 ID-1 standard dimensions (85.60mm x 53.98mm)
70
- ID1_ASPECT_RATIO = 85.60 / 53.98; // 1.5863320574...
53
+ MASK_WIDTH = 280;
54
+ MASK_HEIGHT = 176;
71
55
  debugLog(...args) {
72
56
  if (this.debug) {
73
57
  console.log(...args);
74
58
  }
75
59
  }
76
- validateMaskSize() {
77
- if (this.maskSize < 50 || this.maskSize > 100) {
78
- console.warn(`maskSize debe estar entre 50 y 100. Valor actual: ${this.maskSize}. Usando valor por defecto: 90`);
79
- this.maskSize = 90;
80
- }
81
- }
82
- validateCropMargin() {
83
- if (this.cropMargin < 0 || this.cropMargin > 100) {
84
- console.warn(`cropMargin debe estar entre 0 y 100. Valor actual: ${this.cropMargin}. Usando valor por defecto: 0`);
85
- this.cropMargin = 0;
86
- }
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
- }
95
60
  emitReadyEvent() {
96
61
  const isDocumentReady = !!window.ort && this.isModelPreloaded;
97
62
  this.isReady.emit(isDocumentReady);
@@ -104,267 +69,7 @@ export class JaakStamps {
104
69
  const settings = videoTrack.getSettings();
105
70
  return settings.facingMode === 'environment';
106
71
  }
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
- }
363
72
  async componentDidLoad() {
364
- this.validateMaskSize();
365
- this.validateCropMargin();
366
- this.validatePreferredCamera();
367
- await this.detectDeviceTypeAndCameras();
368
73
  if (!window.ort) {
369
74
  const script = document.createElement('script');
370
75
  script.src = 'https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.min.js';
@@ -380,92 +85,6 @@ export class JaakStamps {
380
85
  }
381
86
  // Initialize canvas pool for better performance
382
87
  this.initializeCanvasPool();
383
- this.setupResizeObserver();
384
- }
385
- setupResizeObserver() {
386
- if ('ResizeObserver' in window && this.canvasRef) {
387
- const resizeObserver = new ResizeObserver(() => {
388
- this.handleResize();
389
- });
390
- resizeObserver.observe(this.canvasRef.parentElement);
391
- }
392
- }
393
- handleResize() {
394
- if (this.canvasRef) {
395
- const container = this.canvasRef.parentElement;
396
- const rect = container.getBoundingClientRect();
397
- // Set canvas size to match container
398
- this.canvasRef.width = rect.width;
399
- this.canvasRef.height = rect.height;
400
- // Update mask positioning based on container and video dimensions
401
- this.updateMaskDimensions(rect);
402
- this.debugLog('📐 Canvas resized:', { width: rect.width, height: rect.height });
403
- }
404
- }
405
- updateMaskDimensions(containerRect) {
406
- if (!this.videoRef)
407
- return;
408
- const videoWidth = this.videoRef.videoWidth;
409
- const videoHeight = this.videoRef.videoHeight;
410
- if (videoWidth === 0 || videoHeight === 0)
411
- return;
412
- // Calculate video aspect ratio and container aspect ratio
413
- const videoAspectRatio = videoWidth / videoHeight;
414
- const containerAspectRatio = containerRect.width / containerRect.height;
415
- // Determine how video fits in container (letterboxed or pillarboxed)
416
- let displayedVideoWidth, displayedVideoHeight;
417
- let videoOffsetX = 0, videoOffsetY = 0;
418
- if (videoAspectRatio > containerAspectRatio) {
419
- // Video is wider - letterboxed (black bars top/bottom)
420
- displayedVideoWidth = containerRect.width;
421
- displayedVideoHeight = containerRect.width / videoAspectRatio;
422
- videoOffsetY = (containerRect.height - displayedVideoHeight) / 2;
423
- }
424
- else {
425
- // Video is taller - pillarboxed (black bars left/right)
426
- displayedVideoHeight = containerRect.height;
427
- displayedVideoWidth = containerRect.height * videoAspectRatio;
428
- videoOffsetX = (containerRect.width - displayedVideoWidth) / 2;
429
- }
430
- // Calculate maximum possible mask size while preserving exact ID-1 aspect ratio
431
- // Determine the limiting dimension based on video orientation and ID-1 proportions
432
- // Calculate what would be the max width if limited by video height
433
- const maxWidthByHeight = displayedVideoHeight * this.ID1_ASPECT_RATIO;
434
- let maskWidthInVideo, maskHeightInVideo;
435
- const sizeRatio = this.maskSize / 100;
436
- if (maxWidthByHeight <= displayedVideoWidth) {
437
- // Video height is the limiting factor
438
- maskHeightInVideo = displayedVideoHeight * sizeRatio;
439
- maskWidthInVideo = maskHeightInVideo * this.ID1_ASPECT_RATIO;
440
- }
441
- else {
442
- // Video width is the limiting factor
443
- maskWidthInVideo = displayedVideoWidth * sizeRatio;
444
- maskHeightInVideo = maskWidthInVideo / this.ID1_ASPECT_RATIO;
445
- }
446
- // Convert to percentages of the container
447
- const maskWidthPercent = (maskWidthInVideo / containerRect.width) * 100;
448
- const maskHeightPercent = (maskHeightInVideo / containerRect.height) * 100;
449
- // Calculate the center position of the displayed video area
450
- const videoCenterX = videoOffsetX + (displayedVideoWidth / 2);
451
- const videoCenterY = videoOffsetY + (displayedVideoHeight / 2);
452
- // Convert to percentages of the container
453
- const videoCenterXPercent = (videoCenterX / containerRect.width) * 100;
454
- const videoCenterYPercent = (videoCenterY / containerRect.height) * 100;
455
- // Update CSS custom properties for mask sizing and positioning
456
- this.el.style.setProperty('--mask-width', `${maskWidthPercent}%`);
457
- this.el.style.setProperty('--mask-height', `${maskHeightPercent}%`);
458
- this.el.style.setProperty('--mask-center-x', `${videoCenterXPercent}%`);
459
- this.el.style.setProperty('--mask-center-y', `${videoCenterYPercent}%`);
460
- // Mark mask as ready now that dimensions are calculated
461
- this.isMaskReady = true;
462
- this.debugLog('🎯 Mask dimensions updated:', {
463
- video: { width: videoWidth, height: videoHeight },
464
- displayed: { width: displayedVideoWidth, height: displayedVideoHeight },
465
- mask: { widthPercent: maskWidthPercent, heightPercent: maskHeightPercent },
466
- center: { x: videoCenterXPercent, y: videoCenterYPercent },
467
- offset: { x: videoOffsetX, y: videoOffsetY }
468
- });
469
88
  }
470
89
  initializeCanvasPool() {
471
90
  // Preprocess canvas - reused for every inference
@@ -534,29 +153,25 @@ export class JaakStamps {
534
153
  }
535
154
  try {
536
155
  this.isLoading = true;
537
- this.statusMessage = "Precargando modelos...";
156
+ this.statusMessage = "Precargando modelo de detección...";
538
157
  this.statusColor = "#007bff";
539
158
  const modelPath = this.MODEL_PATH;
540
- this.debugLog('🤖 Preloading detection model:', modelPath);
159
+ this.debugLog('🤖 Preloading model:', modelPath);
541
160
  // Configure ONNX Runtime with device-specific optimizations
542
161
  const sessionOptions = this.getSessionOptions();
543
162
  this.session = await window.ort.InferenceSession.create(modelPath, sessionOptions);
544
- // Preload MobileNet model and classes only if classification is enabled
545
- if (this.useDocumentClassification) {
546
- await this.loadMobileNetModel();
547
- }
548
163
  this.isModelPreloaded = true;
549
164
  this.isLoading = false;
550
- this.statusMessage = "Modelos precargados. Listo para comenzar detección";
165
+ this.statusMessage = "Modelo precargado. Listo para comenzar detección";
551
166
  this.statusColor = "#28a745";
552
167
  this.emitReadyEvent();
553
- this.debugLog('✅ Models preloaded successfully');
554
- return { success: true, message: 'Models preloaded successfully' };
168
+ this.debugLog('✅ Model preloaded successfully');
169
+ return { success: true, message: 'Model preloaded successfully' };
555
170
  }
556
171
  catch (error) {
557
- this.debugLog('❌ Error preloading models:', error);
172
+ this.debugLog('❌ Error preloading model:', error);
558
173
  this.isLoading = false;
559
- this.statusMessage = "Error al precargar los modelos";
174
+ this.statusMessage = "Error al precargar el modelo";
560
175
  this.statusColor = "#ff6b6b";
561
176
  return { success: false, error: error.message };
562
177
  }
@@ -566,109 +181,6 @@ export class JaakStamps {
566
181
  this.completeProcess(true);
567
182
  }
568
183
  }
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
- }
598
- async loadMobileNetModel() {
599
- try {
600
- this.debugLog('🤖 Loading MobileNet model...');
601
- // Load class map
602
- const classResponse = await fetch(this.MOBILENET_CLASSES_PATH);
603
- if (!classResponse.ok) {
604
- throw new Error(`Failed to load class map: ${this.MOBILENET_CLASSES_PATH}`);
605
- }
606
- this.mobileNetClassMap = await classResponse.json();
607
- this.debugLog('📋 MobileNet classes loaded:', this.mobileNetClassMap);
608
- // Load model
609
- const sessionOptions = this.getSessionOptions();
610
- this.mobileNetSession = await window.ort.InferenceSession.create(this.MOBILENET_MODEL_PATH, sessionOptions);
611
- this.debugLog('✅ MobileNet model loaded successfully');
612
- }
613
- catch (error) {
614
- this.debugLog('❌ Error loading MobileNet model:', error);
615
- throw error;
616
- }
617
- }
618
- preprocessMobileNet(canvas) {
619
- // Create a temporary canvas for MobileNet preprocessing (224x224)
620
- const tempCanvas = document.createElement('canvas');
621
- tempCanvas.width = 224;
622
- tempCanvas.height = 224;
623
- const tempCtx = tempCanvas.getContext('2d');
624
- // Draw the cropped image onto the 224x224 canvas
625
- tempCtx.drawImage(canvas, 0, 0, 224, 224);
626
- // Get image data and preprocess for MobileNet
627
- const imageData = tempCtx.getImageData(0, 0, 224, 224);
628
- const data = imageData.data;
629
- const hw = 224 * 224;
630
- const arr = new Float32Array(3 * hw);
631
- // Normalize pixels: (pixel/255 - 0.5) / 0.5 = (pixel - 127.5) / 127.5
632
- for (let i = 0; i < hw; i++) {
633
- arr[i] = (data[i * 4 + 0] / 255 - 0.5) / 0.5; // R
634
- arr[hw + i] = (data[i * 4 + 1] / 255 - 0.5) / 0.5; // G
635
- arr[2 * hw + i] = (data[i * 4 + 2] / 255 - 0.5) / 0.5; // B
636
- }
637
- return new window.ort.Tensor('float32', arr, [1, 3, 224, 224]);
638
- }
639
- async classifyDocument(canvas) {
640
- if (!this.mobileNetSession || !this.mobileNetClassMap) {
641
- this.debugLog('⚠️ MobileNet model not loaded');
642
- return null;
643
- }
644
- try {
645
- this.debugLog('🔍 Classifying document...');
646
- // Preprocess image for MobileNet
647
- const inputTensor = this.preprocessMobileNet(canvas);
648
- // Run inference
649
- const feeds = { input: inputTensor };
650
- const results = await this.mobileNetSession.run(feeds);
651
- const output = results[Object.keys(results)[0]].data;
652
- // Find the class with highest confidence
653
- const maxIdx = output.reduce((bestIdx, val, idx, arr) => val > arr[bestIdx] ? idx : bestIdx, 0);
654
- const confidence = output[maxIdx];
655
- const className = this.mobileNetClassMap[maxIdx.toString()] || "unknown";
656
- this.debugLog('📄 Document classification result:', {
657
- class: className,
658
- confidence: confidence.toFixed(3),
659
- classIndex: maxIdx
660
- });
661
- return {
662
- class: className,
663
- confidence: confidence,
664
- classIndex: maxIdx
665
- };
666
- }
667
- catch (error) {
668
- this.debugLog('❌ Error classifying document:', error);
669
- return null;
670
- }
671
- }
672
184
  cleanup() {
673
185
  if (this.animationId) {
674
186
  cancelAnimationFrame(this.animationId);
@@ -696,103 +208,22 @@ export class JaakStamps {
696
208
  this.captureCtx = undefined;
697
209
  this.captureCanvas = undefined;
698
210
  }
699
- // Disposed ONNX sessions
211
+ // Disposed ONNX session
700
212
  if (this.session) {
701
213
  this.session.release?.();
702
214
  this.session = undefined;
703
215
  }
704
- if (this.mobileNetSession) {
705
- this.mobileNetSession.release?.();
706
- this.mobileNetSession = undefined;
707
- }
708
- this.mobileNetClassMap = undefined;
709
216
  this.isModelPreloaded = false;
710
217
  this.debugLog('🧹 Canvas pool cleaned up');
711
218
  }
712
- async getMaxResolution() {
713
- try {
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
726
- const tempStream = await navigator.mediaDevices.getUserMedia({
727
- video: videoConstraints
728
- });
729
- const videoTrack = tempStream.getVideoTracks()[0];
730
- const capabilities = videoTrack.getCapabilities();
731
- // Detener el stream temporal
732
- tempStream.getTracks().forEach(track => track.stop());
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
- ;
746
- if (capabilities.width && capabilities.height) {
747
- // Limitar resolución máxima para tablets para evitar problemas de rendimiento
748
- const maxWidth = Math.min(capabilities.width.max, 1920);
749
- const maxHeight = Math.min(capabilities.height.max, 1080);
750
- // Para tablets, usar resolución moderada en lugar de máxima
751
- const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
752
- if (isTablet) {
753
- constraints.width = { ideal: Math.min(maxWidth, 1280) };
754
- constraints.height = { ideal: Math.min(maxHeight, 720) };
755
- }
756
- else {
757
- constraints.width = { ideal: maxWidth };
758
- constraints.height = { ideal: maxHeight };
759
- }
760
- this.debugLog('📐 Resolution capabilities:', {
761
- maxWidth: capabilities.width.max,
762
- maxHeight: capabilities.height.max,
763
- selectedWidth: constraints.width.ideal,
764
- selectedHeight: constraints.height.ideal,
765
- isTablet
766
- });
767
- }
768
- return constraints;
769
- }
770
- catch (err) {
771
- this.debugLog('⚠️ Could not get capabilities, using fallback');
772
- // Optimized fallback for tablets
773
- const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
774
- const fallbackConstraints = {
775
- width: { ideal: isTablet ? 1280 : 1920 },
776
- height: { ideal: isTablet ? 720 : 1080 }
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;
789
- }
790
- }
791
219
  async setupCamera() {
792
220
  try {
793
- const constraints = await this.getMaxResolution();
794
221
  const stream = await navigator.mediaDevices.getUserMedia({
795
- video: constraints,
222
+ video: {
223
+ width: { exact: 640 },
224
+ height: { exact: 640 },
225
+ facingMode: "environment"
226
+ },
796
227
  audio: false
797
228
  });
798
229
  if (this.videoRef) {
@@ -807,12 +238,6 @@ export class JaakStamps {
807
238
  this.videoRef.onloadedmetadata = async () => {
808
239
  await this.videoRef.play();
809
240
  this.isVideoActive = true;
810
- // Update mask dimensions once video is loaded
811
- if (this.canvasRef) {
812
- const container = this.canvasRef.parentElement;
813
- const rect = container.getBoundingClientRect();
814
- this.updateMaskDimensions(rect);
815
- }
816
241
  resolve();
817
242
  };
818
243
  });
@@ -820,7 +245,8 @@ export class JaakStamps {
820
245
  }
821
246
  catch (err) {
822
247
  this.debugLog("❌ No se pudo acceder a la cámara:", err);
823
- this.handleCameraPermissionError(err);
248
+ this.statusMessage = "Error: No se pudo acceder a la cámara.";
249
+ this.statusColor = "#ff6b6b";
824
250
  }
825
251
  }
826
252
  preprocess(video) {
@@ -865,22 +291,18 @@ export class JaakStamps {
865
291
  // Check if model is already preloaded
866
292
  if (!this.session) {
867
293
  this.isLoading = true;
868
- this.statusMessage = "Cargando modelos...";
294
+ this.statusMessage = "Cargando modelo de detección...";
869
295
  this.statusColor = "#007bff";
870
296
  const modelPath = this.MODEL_PATH;
871
- this.debugLog('🤖 Loading detection model:', modelPath);
297
+ this.debugLog('🤖 Loading model:', modelPath);
872
298
  const sessionOptions = this.getSessionOptions();
873
299
  this.session = await window.ort.InferenceSession.create(modelPath, sessionOptions);
874
- // Load MobileNet model if classification is enabled and not already loaded
875
- if (this.useDocumentClassification && !this.mobileNetSession) {
876
- await this.loadMobileNetModel();
877
- }
878
300
  this.isModelPreloaded = true;
879
301
  this.emitReadyEvent();
880
302
  }
881
303
  else {
882
- this.debugLog('🚀 Using preloaded models');
883
- this.statusMessage = "Usando modelos precargados...";
304
+ this.debugLog('🚀 Using preloaded model');
305
+ this.statusMessage = "Usando modelo precargado...";
884
306
  this.statusColor = "#007bff";
885
307
  }
886
308
  this.statusMessage = "Configurando cámara...";
@@ -993,58 +415,13 @@ export class JaakStamps {
993
415
  return isCentered && isGoodSize;
994
416
  }
995
417
  checkSideAlignment(box) {
996
- if (!this.videoRef)
997
- return { top: false, right: false, bottom: false, left: false };
998
- // Get video dimensions to calculate actual mask boundaries in model space
999
- const videoWidth = this.videoRef.videoWidth;
1000
- const videoHeight = this.videoRef.videoHeight;
1001
- if (videoWidth === 0 || videoHeight === 0) {
1002
- return { top: false, right: false, bottom: false, left: false };
1003
- }
1004
- // Calculate video aspect ratio
1005
- const videoAspectRatio = videoWidth / videoHeight;
1006
- // The model sees video stretched to 320x320, but we need to calculate where
1007
- // the mask should be in this distorted space to match the visual mask
1008
- // In the visual display, we calculate mask size based on the limiting dimension
1009
- // We need to replicate this logic but account for the distortion in model space
1010
- // Calculate the "display" dimensions (what the visual mask calculations use)
1011
- const containerAspectRatio = 1; // Assume square container for simplicity
1012
- let displayedVideoWidth, displayedVideoHeight;
1013
- if (videoAspectRatio > containerAspectRatio) {
1014
- // Video is wider - letterboxed in display
1015
- displayedVideoWidth = this.INPUT_SIZE;
1016
- displayedVideoHeight = this.INPUT_SIZE / videoAspectRatio;
1017
- }
1018
- else {
1019
- // Video is taller - pillarboxed in display
1020
- displayedVideoHeight = this.INPUT_SIZE;
1021
- displayedVideoWidth = this.INPUT_SIZE * videoAspectRatio;
1022
- }
1023
- // Calculate mask dimensions using the same logic as updateMaskDimensions
1024
- const maxWidthByHeight = displayedVideoHeight * this.ID1_ASPECT_RATIO;
1025
- let visualMaskWidth, visualMaskHeight;
1026
- const sizeRatio = this.maskSize / 100;
1027
- if (maxWidthByHeight <= displayedVideoWidth) {
1028
- // Video height is the limiting factor
1029
- visualMaskHeight = displayedVideoHeight * sizeRatio;
1030
- visualMaskWidth = visualMaskHeight * this.ID1_ASPECT_RATIO;
1031
- }
1032
- else {
1033
- // Video width is the limiting factor
1034
- visualMaskWidth = displayedVideoWidth * sizeRatio;
1035
- visualMaskHeight = visualMaskWidth / this.ID1_ASPECT_RATIO;
1036
- }
1037
- // Now map these visual mask dimensions to the distorted model space
1038
- // The model stretches video to 320x320, so we need to apply the inverse transformation
1039
- const modelMaskWidth = visualMaskWidth * (this.INPUT_SIZE / displayedVideoWidth);
1040
- const modelMaskHeight = visualMaskHeight * (this.INPUT_SIZE / displayedVideoHeight);
1041
- // Calculate mask boundaries in model coordinate system (always centered in 320x320)
418
+ // Obtener las coordenadas del marco de referencia (máscara)
1042
419
  const maskCenterX = this.INPUT_SIZE / 2;
1043
420
  const maskCenterY = this.INPUT_SIZE / 2;
1044
- const maskLeft = maskCenterX - (modelMaskWidth / 2);
1045
- const maskRight = maskCenterX + (modelMaskWidth / 2);
1046
- const maskTop = maskCenterY - (modelMaskHeight / 2);
1047
- const maskBottom = maskCenterY + (modelMaskHeight / 2);
421
+ const maskLeft = maskCenterX - (this.MASK_WIDTH / 2);
422
+ const maskRight = maskCenterX + (this.MASK_WIDTH / 2);
423
+ const maskTop = maskCenterY - (this.MASK_HEIGHT / 2);
424
+ const maskBottom = maskCenterY + (this.MASK_HEIGHT / 2);
1048
425
  // Obtener las coordenadas del documento detectado
1049
426
  let docLeft = box.x;
1050
427
  let docRight = box.x + box.w;
@@ -1099,9 +476,7 @@ export class JaakStamps {
1099
476
  corners?.forEach(corner => corner.classList.add('perfect-match'));
1100
477
  if (!this.hasScreenshotTaken) {
1101
478
  this.lastDetectedBox = bestBox;
1102
- this.takeScreenshot().catch(error => {
1103
- this.debugLog('❌ Error taking screenshot:', error);
1104
- });
479
+ this.takeScreenshot();
1105
480
  this.hasScreenshotTaken = true;
1106
481
  // Reset para permitir segunda captura
1107
482
  setTimeout(() => {
@@ -1143,48 +518,15 @@ export class JaakStamps {
1143
518
  }
1144
519
  }
1145
520
  drawDetections(ctx, boxes) {
1146
- if (!this.videoRef)
1147
- return;
1148
- // Get video and container dimensions
1149
- const videoWidth = this.videoRef.videoWidth;
1150
- const videoHeight = this.videoRef.videoHeight;
1151
- const containerWidth = this.canvasRef.width;
1152
- const containerHeight = this.canvasRef.height;
1153
- if (videoWidth === 0 || videoHeight === 0)
1154
- return;
1155
- // Calculate video aspect ratio and container aspect ratio
1156
- const videoAspectRatio = videoWidth / videoHeight;
1157
- const containerAspectRatio = containerWidth / containerHeight;
1158
- // Determine how video fits in container (same logic as updateMaskDimensions)
1159
- let displayedVideoWidth, displayedVideoHeight;
1160
- let videoOffsetX = 0, videoOffsetY = 0;
1161
- if (videoAspectRatio > containerAspectRatio) {
1162
- // Video is wider - letterboxed (black bars top/bottom)
1163
- displayedVideoWidth = containerWidth;
1164
- displayedVideoHeight = containerWidth / videoAspectRatio;
1165
- videoOffsetY = (containerHeight - displayedVideoHeight) / 2;
1166
- }
1167
- else {
1168
- // Video is taller - pillarboxed (black bars left/right)
1169
- displayedVideoHeight = containerHeight;
1170
- displayedVideoWidth = containerHeight * videoAspectRatio;
1171
- videoOffsetX = (containerWidth - displayedVideoWidth) / 2;
1172
- }
1173
- // Scale factor from model coordinates (320x320) to displayed video area
1174
- const scaleX = displayedVideoWidth / this.INPUT_SIZE;
1175
- const scaleY = displayedVideoHeight / this.INPUT_SIZE;
521
+ // Scale factor to convert from model coordinates (320x320) to canvas coordinates (640x640)
522
+ const scale = this.canvasRef.width / this.INPUT_SIZE;
1176
523
  boxes.forEach(det => {
1177
- // Convert model coordinates to displayed video coordinates
1178
- const x = det.x * scaleX + videoOffsetX;
1179
- const y = det.y * scaleY + videoOffsetY;
1180
- const w = det.w * scaleX;
1181
- const h = det.h * scaleY;
1182
524
  ctx.strokeStyle = "#32406C";
1183
525
  ctx.lineWidth = 2;
1184
- ctx.strokeRect(x, y, w, h);
526
+ ctx.strokeRect(det.x * scale, det.y * scale, det.w * scale, det.h * scale);
1185
527
  });
1186
528
  }
1187
- async takeScreenshot() {
529
+ takeScreenshot() {
1188
530
  if (!this.videoRef || !this.lastDetectedBox)
1189
531
  return;
1190
532
  // Activar animación
@@ -1200,10 +542,10 @@ export class JaakStamps {
1200
542
  // Calcular las coordenadas de recorte basadas en la detección
1201
543
  const scaleX = this.videoRef.videoWidth / this.INPUT_SIZE;
1202
544
  const scaleY = this.videoRef.videoHeight / this.INPUT_SIZE;
1203
- const cropX = Math.max(0, (this.lastDetectedBox.x * scaleX) - this.cropMargin);
1204
- const cropY = Math.max(0, (this.lastDetectedBox.y * scaleY) - this.cropMargin);
1205
- const cropWidth = Math.min((this.lastDetectedBox.w * scaleX) + (2 * this.cropMargin), this.videoRef.videoWidth - cropX);
1206
- const cropHeight = Math.min((this.lastDetectedBox.h * scaleY) + (2 * this.cropMargin), this.videoRef.videoHeight - cropY);
545
+ const cropX = Math.max(0, this.lastDetectedBox.x * scaleX);
546
+ const cropY = Math.max(0, this.lastDetectedBox.y * scaleY);
547
+ const cropWidth = Math.min(this.lastDetectedBox.w * scaleX, this.videoRef.videoWidth - cropX);
548
+ const cropHeight = Math.min(this.lastDetectedBox.h * scaleY, this.videoRef.videoHeight - cropY);
1207
549
  // OPTIMIZATION: Create temporary canvas only for cropped version
1208
550
  // (We reuse main capture canvas for full frame)
1209
551
  const croppedCanvas = document.createElement('canvas');
@@ -1218,29 +560,6 @@ export class JaakStamps {
1218
560
  // Captura del frente usando canvas reutilizado
1219
561
  this.capturedFullFrame = this.captureCanvas.toDataURL('image/png');
1220
562
  this.capturedCroppedId = croppedCanvas.toDataURL('image/png');
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
- }
1242
- }
1243
- // For other IDs, continue with normal flow (back capture)
1244
563
  this.captureStep = 'back';
1245
564
  this.statusMessage = "Voltee la identificación y muestre la parte trasera";
1246
565
  this.statusColor = "#007bff";
@@ -1370,20 +689,7 @@ export class JaakStamps {
1370
689
  this.cleanup();
1371
690
  }
1372
691
  render() {
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" })))));
692
+ return (h("div", { key: '788a458497c2303875f8accea1e0cc579379ff94', class: "detector-container" }, h("div", { key: 'ed491d2fb8399f7236ab492a100932518455be79', class: "video-container" }, h("video", { key: '8187f838c75776432dc48db4cd9bfe4ee350830d', ref: el => this.videoRef = el, width: "640", height: "640", autoplay: true, muted: true, playsinline: true, class: this.shouldMirrorVideo ? 'mirror' : '', style: { display: this.isVideoActive ? 'block' : 'none' } }), h("canvas", { key: '8cc31c45881d4f23c56c5ed246c9e59e30e0a782', ref: el => this.canvasRef = el, width: "640", height: "640", class: this.shouldMirrorVideo ? 'mirror' : '' }), h("div", { key: '54441a535098860601a7ef4f1b31a0d2a40a911b', class: "overlay-mask" }, h("div", { key: 'f9272bcb85c849e3b3170a0062c43e64359f112d', class: "card-outline" }, h("div", { key: '8a260667206ce2fecac262f2b5e81d0ebdccbb3c', class: "side side-top" }), h("div", { key: 'c9c0d25087aa8332027815829fc7bbd937f0596b', class: "side side-right" }), h("div", { key: '39394f06936ff01a525c83343ec05e6161611899', class: "side side-bottom" }), h("div", { key: '11799336a4b6f72d6042c02206626d947422ef0f', class: "side side-left" }), h("div", { key: '93d5636f85514d3fff76415ed806e6845c6e7fe3', class: "corner corner-tl" }), h("div", { key: '3bfc09f919744d1d04dcb0c08fb923879dc217c9', class: "corner corner-tr" }), h("div", { key: '6d9fa1395a606960597bed65301679dcd12fc8bb', class: "corner corner-bl" }), h("div", { key: '4819402bd891c4a8d581e1e10449850b3a580e96', class: "corner corner-br" }), !this.showFlipAnimation && !this.showSuccessAnimation && (h("div", { key: '26a57343cfccea003c3edc65c5c53ac97b16de53', class: "guide-text" }, this.statusMessage))), this.captureStep === 'back' && !this.showFlipAnimation && !this.showSuccessAnimation && (h("button", { key: '641d63e9f9e76fa81b2f770a1036b337f54a2c23', class: "skip-button", onClick: () => this.skipBackCapture(), type: "button" }, "Saltar reverso"))), this.isCapturing && (h("div", { key: 'e7ab12f7ad092d233e19de5bc7a3e424b6bc70c3', class: "capture-animation" })), this.showFlipAnimation && (h("div", { key: 'dddbe58a92172e9ab1e7002a3b4310d8e552926f', class: "flip-animation" }, h("div", { key: 'c2f49ee888573d873d67e8d4871bb6b1d8f2bc8d', class: "id-card-icon" }), h("div", { key: '6e71e7a9a3a85bb4f9252955ea220e64a25ae479', class: "flip-text" }, "\u00A1Voltea tu identificaci\u00F3n!"))), this.showSuccessAnimation && (h("div", { key: 'c9d8fd42711764ea197c7d13ef3d90e34b559e64', class: "success-animation" }, h("div", { key: '50dd978c2c501b53591346d75dac018006f42992', class: "check-icon" }), h("div", { key: 'ad25bc5811d435ceb7a1e9791cd3fc5dbd5c5227', class: "success-text" }, "\u00A1Proceso completado!"))), this.isLoading && (h("div", { key: '9ac52c0754d165f8141989b17398a89b21790976', class: "loading-overlay" }, h("div", { key: 'ccffac3b53db3ac4beddbf43ee8cff693e29fd73', class: "loading-spinner" }), h("div", { key: '708c4aad55e18be3fc77fe3f169430475dce7ee1', class: "loading-text" }, this.statusMessage))), h("div", { key: 'e0addbcea4b176772de10a608c6de4242da2a7f3', class: "watermark" }, h("img", { key: 'd3d2a989a01e2a64a100ccdc43a027f969d4b8b1', src: "https://storage.googleapis.com/jaak-static/commons/powered-by-jaak.png", alt: "Powered by Jaak" })))));
1387
693
  }
1388
694
  static get is() { return "jaak-stamps"; }
1389
695
  static get encapsulation() { return "shadow"; }
@@ -1438,86 +744,6 @@ export class JaakStamps {
1438
744
  "setter": false,
1439
745
  "reflect": false,
1440
746
  "defaultValue": "10"
1441
- },
1442
- "maskSize": {
1443
- "type": "number",
1444
- "attribute": "mask-size",
1445
- "mutable": false,
1446
- "complexType": {
1447
- "original": "number",
1448
- "resolved": "number",
1449
- "references": {}
1450
- },
1451
- "required": false,
1452
- "optional": false,
1453
- "docs": {
1454
- "tags": [],
1455
- "text": ""
1456
- },
1457
- "getter": false,
1458
- "setter": false,
1459
- "reflect": false,
1460
- "defaultValue": "90"
1461
- },
1462
- "cropMargin": {
1463
- "type": "number",
1464
- "attribute": "crop-margin",
1465
- "mutable": false,
1466
- "complexType": {
1467
- "original": "number",
1468
- "resolved": "number",
1469
- "references": {}
1470
- },
1471
- "required": false,
1472
- "optional": false,
1473
- "docs": {
1474
- "tags": [],
1475
- "text": ""
1476
- },
1477
- "getter": false,
1478
- "setter": false,
1479
- "reflect": false,
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'"
1521
747
  }
1522
748
  };
1523
749
  }
@@ -1539,12 +765,7 @@ export class JaakStamps {
1539
765
  "sideAlignment": {},
1540
766
  "isDetectionPaused": {},
1541
767
  "isLoading": {},
1542
- "isModelPreloaded": {},
1543
- "isMaskReady": {},
1544
- "availableCameras": {},
1545
- "selectedCameraId": {},
1546
- "showCameraSelector": {},
1547
- "isMultipleCamerasAvailable": {}
768
+ "isModelPreloaded": {}
1548
769
  };
1549
770
  }
1550
771
  static get events() {
@@ -1717,44 +938,6 @@ export class JaakStamps {
1717
938
  "text": "",
1718
939
  "tags": []
1719
940
  }
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
- }
1758
941
  }
1759
942
  };
1760
943
  }