@jaak.ai/stamps 2.0.0-beta.2 → 2.0.0-beta.4

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 (84) hide show
  1. package/README.md +216 -212
  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 +1860 -783
  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 +629 -72
  10. package/dist/collection/components/my-component/my-component.js +896 -781
  11. package/dist/collection/components/my-component/my-component.js.map +1 -1
  12. package/dist/collection/services/CameraService.js +453 -0
  13. package/dist/collection/services/CameraService.js.map +1 -0
  14. package/dist/collection/services/DetectionService.js +369 -0
  15. package/dist/collection/services/DetectionService.js.map +1 -0
  16. package/dist/collection/services/EventBusService.js +42 -0
  17. package/dist/collection/services/EventBusService.js.map +1 -0
  18. package/dist/collection/services/LoggerService.js +40 -0
  19. package/dist/collection/services/LoggerService.js.map +1 -0
  20. package/dist/collection/services/ServiceContainer.js +66 -0
  21. package/dist/collection/services/ServiceContainer.js.map +1 -0
  22. package/dist/collection/services/StateManagerService.js +109 -0
  23. package/dist/collection/services/StateManagerService.js.map +1 -0
  24. package/dist/collection/services/factories/DeviceStrategyFactory.js +16 -0
  25. package/dist/collection/services/factories/DeviceStrategyFactory.js.map +1 -0
  26. package/dist/collection/services/interfaces/ICameraService.js +2 -0
  27. package/dist/collection/services/interfaces/ICameraService.js.map +1 -0
  28. package/dist/collection/services/interfaces/IDetectionService.js +2 -0
  29. package/dist/collection/services/interfaces/IDetectionService.js.map +1 -0
  30. package/dist/collection/services/interfaces/IEventBus.js +2 -0
  31. package/dist/collection/services/interfaces/IEventBus.js.map +1 -0
  32. package/dist/collection/services/interfaces/ILogger.js +2 -0
  33. package/dist/collection/services/interfaces/ILogger.js.map +1 -0
  34. package/dist/collection/services/interfaces/IStateManager.js +2 -0
  35. package/dist/collection/services/interfaces/IStateManager.js.map +1 -0
  36. package/dist/collection/services/strategies/HighPerformanceDeviceStrategy.js +30 -0
  37. package/dist/collection/services/strategies/HighPerformanceDeviceStrategy.js.map +1 -0
  38. package/dist/collection/services/strategies/IDeviceStrategy.js +2 -0
  39. package/dist/collection/services/strategies/IDeviceStrategy.js.map +1 -0
  40. package/dist/collection/services/strategies/LowMemoryDeviceStrategy.js +30 -0
  41. package/dist/collection/services/strategies/LowMemoryDeviceStrategy.js.map +1 -0
  42. package/dist/collection/types/component-types.js +2 -0
  43. package/dist/collection/types/component-types.js.map +1 -0
  44. package/dist/components/index.js +3 -0
  45. package/dist/components/index.js.map +1 -1
  46. package/dist/components/jaak-stamps.js +1873 -797
  47. package/dist/components/jaak-stamps.js.map +1 -1
  48. package/dist/esm/{index-DqoVMnc7.js → index-BP1Q4KOg.js} +5 -2
  49. package/dist/esm/index-BP1Q4KOg.js.map +1 -0
  50. package/dist/esm/jaak-stamps-webcomponent.js +3 -3
  51. package/dist/esm/jaak-stamps.entry.js +1860 -783
  52. package/dist/esm/jaak-stamps.entry.js.map +1 -1
  53. package/dist/esm/loader.js +3 -3
  54. package/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js +1 -1
  55. package/dist/jaak-stamps-webcomponent/jaak-stamps.entry.esm.js.map +1 -1
  56. package/dist/jaak-stamps-webcomponent/p-10ee2dab.entry.js +2 -0
  57. package/dist/jaak-stamps-webcomponent/p-10ee2dab.entry.js.map +1 -0
  58. package/dist/jaak-stamps-webcomponent/p-BP1Q4KOg.js +3 -0
  59. package/dist/jaak-stamps-webcomponent/p-BP1Q4KOg.js.map +1 -0
  60. package/dist/types/components/my-component/my-component.d.ts +90 -79
  61. package/dist/types/components.d.ts +32 -8
  62. package/dist/types/services/CameraService.d.ts +46 -0
  63. package/dist/types/services/DetectionService.d.ts +35 -0
  64. package/dist/types/services/EventBusService.d.ts +9 -0
  65. package/dist/types/services/LoggerService.d.ts +12 -0
  66. package/dist/types/services/ServiceContainer.d.ts +27 -0
  67. package/dist/types/services/StateManagerService.d.ts +15 -0
  68. package/dist/types/services/factories/DeviceStrategyFactory.d.ts +4 -0
  69. package/dist/types/services/interfaces/ICameraService.d.ts +34 -0
  70. package/dist/types/services/interfaces/IDetectionService.d.ts +31 -0
  71. package/dist/types/services/interfaces/IEventBus.d.ts +16 -0
  72. package/dist/types/services/interfaces/ILogger.d.ts +8 -0
  73. package/dist/types/services/interfaces/IStateManager.d.ts +35 -0
  74. package/dist/types/services/strategies/HighPerformanceDeviceStrategy.d.ts +6 -0
  75. package/dist/types/services/strategies/IDeviceStrategy.d.ts +21 -0
  76. package/dist/types/services/strategies/LowMemoryDeviceStrategy.d.ts +6 -0
  77. package/dist/types/types/component-types.d.ts +36 -0
  78. package/package.json +3 -3
  79. package/dist/cjs/index-DGM9-FNg.js.map +0 -1
  80. package/dist/esm/index-DqoVMnc7.js.map +0 -1
  81. package/dist/jaak-stamps-webcomponent/p-DqoVMnc7.js +0 -3
  82. package/dist/jaak-stamps-webcomponent/p-DqoVMnc7.js.map +0 -1
  83. package/dist/jaak-stamps-webcomponent/p-f1172b06.entry.js +0 -2
  84. package/dist/jaak-stamps-webcomponent/p-f1172b06.entry.js.map +0 -1
package/README.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # Jaak Stamps - Document Detector Web Component
2
2
 
3
- Un componente web para la detección y captura automática de documentos de identificación usando visión artificial y redes neuronales.
3
+ A web component for automatic detection and capture of identification documents using computer vision.
4
4
 
5
- ## Características
5
+ ## Features
6
6
 
7
- - 📷 **Detección automática** de documentos de identificación en tiempo real
8
- - 🎯 **Guía visual** para posicionamiento óptimo del documento
9
- - 🤖 **Clasificación inteligente** de documentos para determinar si requieren reverso
10
- - 📋 **Captura adaptativa** - automáticamente detecta si el documento tiene reverso
11
- - 🖼 **Doble salida** para cada lado: imagen completa y recorte del documento
12
- - ✂️ **Recorte configurable** con margen personalizable alrededor del documento
13
- - 🔧 **API programática** para control total del proceso
14
- - 📱 **Responsive** y compatible con dispositivos móviles
15
- - **Optimización automática** para mejor rendimiento
7
+ - Real-time automatic document detection
8
+ - Visual guide for optimal document positioning
9
+ - Intelligent document classification to determine if back capture is required
10
+ - Adaptive capture - automatically detects if document requires back side
11
+ - Dual output for each side: full frame and cropped document
12
+ - Configurable cropping with customizable margin around document
13
+ - Programmatic API for complete process control
14
+ - Responsive and mobile device compatible
15
+ - Automatic optimization for better performance
16
16
 
17
- ## Instalación
17
+ ## Installation
18
18
 
19
19
  ### NPM
20
20
  ```bash
@@ -31,7 +31,7 @@ yarn add @jaak.ai/stamps
31
31
  <script type="module" src="https://unpkg.com/@jaak.ai/stamps/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js"></script>
32
32
  ```
33
33
 
34
- ## Uso Básico
34
+ ## Basic Usage
35
35
 
36
36
  ### HTML Vanilla
37
37
 
@@ -43,25 +43,25 @@ yarn add @jaak.ai/stamps
43
43
  <script type="module" src="https://unpkg.com/@jaak.ai/stamps/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js"></script>
44
44
  </head>
45
45
  <body>
46
- <jaak-stamps id="detector" debug="false" mask-size="90" crop-margin="10" use-document-classification="false"></jaak-stamps>
46
+ <jaak-stamps id="detector" debug="false" mask-size="80" crop-margin="20" capture-delay="1000" use-document-classification="false"></jaak-stamps>
47
47
 
48
- <button onclick="startCapture()">Iniciar Captura</button>
49
- <button onclick="stopCapture()">Detener</button>
50
- <button onclick="resetCapture()">Reiniciar</button>
48
+ <button onclick="startCapture()">Start Capture</button>
49
+ <button onclick="stopCapture()">Stop</button>
50
+ <button onclick="resetCapture()">Reset</button>
51
51
 
52
52
  <script>
53
53
  const detector = document.getElementById('detector');
54
54
 
55
- // Escuchar evento de captura completada
55
+ // Listen for capture completed event
56
56
  detector.addEventListener('captureCompleted', (event) => {
57
- console.log('Captura completada:', event.detail);
58
- // event.detail contiene las imágenes capturadas
57
+ console.log('Capture completed:', event.detail);
58
+ // event.detail contains the captured images
59
59
  });
60
60
 
61
- // Escuchar evento de componente listo
61
+ // Listen for component ready event
62
62
  detector.addEventListener('isReady', (event) => {
63
- console.log('Componente listo:', event.detail);
64
- // event.detail indica si el componente está listo (true/false)
63
+ console.log('Component ready:', event.detail);
64
+ // event.detail indicates if the component is ready (true/false)
65
65
  });
66
66
 
67
67
  function startCapture() {
@@ -76,21 +76,21 @@ yarn add @jaak.ai/stamps
76
76
  detector.resetCapture();
77
77
  }
78
78
 
79
- // Precargar el modelo (opcional - mejora el rendimiento)
79
+ // Preload model (optional - improves performance)
80
80
  async function preloadModel() {
81
81
  try {
82
82
  const result = await detector.preloadModel();
83
- console.log('Modelo precargado:', result);
83
+ console.log('Model preloaded:', result);
84
84
  } catch (error) {
85
- console.error('Error al precargar:', error);
85
+ console.error('Error preloading:', error);
86
86
  }
87
87
  }
88
88
 
89
- // Obtener imágenes después de la captura
89
+ // Get images after capture
90
90
  async function getImages() {
91
91
  try {
92
92
  const images = await detector.getCapturedImages();
93
- console.log('Imágenes capturadas:', images);
93
+ console.log('Captured images:', images);
94
94
  } catch (error) {
95
95
  console.error('Error:', error.message);
96
96
  }
@@ -102,18 +102,18 @@ yarn add @jaak.ai/stamps
102
102
 
103
103
  ### Angular
104
104
 
105
- #### 1. Instalar el componente
105
+ #### 1. Install the component
106
106
  ```bash
107
107
  npm install @jaak.ai/stamps
108
108
  ```
109
109
 
110
- #### 2. Configurar el módulo (app.module.ts)
110
+ #### 2. Configure the module (app.module.ts)
111
111
  ```typescript
112
112
  import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
113
113
  import { BrowserModule } from '@angular/platform-browser';
114
114
  import { AppComponent } from './app.component';
115
115
 
116
- // Importar el componente web
116
+ // Import the web component
117
117
  import '@jaak.ai/stamps/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js';
118
118
 
119
119
  @NgModule({
@@ -121,12 +121,12 @@ import '@jaak.ai/stamps/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.e
121
121
  imports: [BrowserModule],
122
122
  providers: [],
123
123
  bootstrap: [AppComponent],
124
- schemas: [CUSTOM_ELEMENTS_SCHEMA] // Permitir elementos personalizados
124
+ schemas: [CUSTOM_ELEMENTS_SCHEMA] // Allow custom elements
125
125
  })
126
126
  export class AppModule { }
127
127
  ```
128
128
 
129
- #### 3. Usar en el componente
129
+ #### 3. Use in the component
130
130
  ```typescript
131
131
  // app.component.ts
132
132
  import { Component, ElementRef, ViewChild, OnInit } from '@angular/core';
@@ -135,31 +135,31 @@ import { Component, ElementRef, ViewChild, OnInit } from '@angular/core';
135
135
  selector: 'app-root',
136
136
  template: `
137
137
  <div class="container">
138
- <h1>Detector de Documentos</h1>
138
+ <h1>Document Detector</h1>
139
139
 
140
140
  <jaak-stamps
141
141
  #detector
142
142
  [debug]="false"
143
- [maskSize]="90"
144
- [cropMargin]="10"
143
+ [maskSize]="80"
144
+ [cropMargin]="20"
145
145
  [useDocumentClassification]="false"
146
146
  (captureCompleted)="onCaptureCompleted($event)"
147
147
  (isReady)="onComponentReady($event)">
148
148
  </jaak-stamps>
149
149
 
150
150
  <div class="controls">
151
- <button (click)="preloadModel()">Precargar Modelo</button>
152
- <button (click)="startCapture()">Iniciar Captura</button>
153
- <button (click)="stopCapture()">Detener</button>
154
- <button (click)="resetCapture()">Reiniciar</button>
155
- <button (click)="getImages()" [disabled]="!isCompleted">Obtener Imágenes</button>
151
+ <button (click)="preloadModel()">Preload Model</button>
152
+ <button (click)="startCapture()">Start Capture</button>
153
+ <button (click)="stopCapture()">Stop</button>
154
+ <button (click)="resetCapture()">Reset</button>
155
+ <button (click)="getImages()" [disabled]="!isCompleted">Get Images</button>
156
156
  </div>
157
157
 
158
158
  <div *ngIf="capturedData" class="results">
159
- <h3>Imágenes Capturadas:</h3>
160
- <p>Total de imágenes: {{ capturedData.metadata.totalImages }}</p>
161
- <img *ngIf="capturedData.front.cropped" [src]="capturedData.front.cropped" alt="Frente">
162
- <img *ngIf="capturedData.back.cropped" [src]="capturedData.back.cropped" alt="Reverso">
159
+ <h3>Captured Images:</h3>
160
+ <p>Total images: {{ capturedData.metadata.totalImages }}</p>
161
+ <img *ngIf="capturedData.front.cropped" [src]="capturedData.front.cropped" alt="Front">
162
+ <img *ngIf="capturedData.back.cropped" [src]="capturedData.back.cropped" alt="Back">
163
163
  </div>
164
164
  </div>
165
165
  `,
@@ -177,15 +177,15 @@ export class AppComponent implements OnInit {
177
177
  isCompleted = false;
178
178
 
179
179
  ngOnInit() {
180
- // El elemento ya está disponible después de la vista
180
+ // The element is already available after the view
181
181
  }
182
182
 
183
183
  async preloadModel() {
184
184
  try {
185
185
  const result = await this.detectorRef.nativeElement.preloadModel();
186
- console.log('Modelo precargado:', result);
186
+ console.log('Model preloaded:', result);
187
187
  } catch (error) {
188
- console.error('Error al precargar modelo:', error);
188
+ console.error('Error preloading model:', error);
189
189
  }
190
190
  }
191
191
 
@@ -193,7 +193,7 @@ export class AppComponent implements OnInit {
193
193
  try {
194
194
  await this.detectorRef.nativeElement.startCapture();
195
195
  } catch (error) {
196
- console.error('Error al iniciar captura:', error);
196
+ console.error('Error starting capture:', error);
197
197
  }
198
198
  }
199
199
 
@@ -210,41 +210,41 @@ export class AppComponent implements OnInit {
210
210
  async getImages() {
211
211
  try {
212
212
  const images = await this.detectorRef.nativeElement.getCapturedImages();
213
- console.log('Imágenes obtenidas:', images);
213
+ console.log('Images obtained:', images);
214
214
  } catch (error) {
215
- console.error('Error al obtener imágenes:', error);
215
+ console.error('Error getting images:', error);
216
216
  }
217
217
  }
218
218
 
219
219
  onCaptureCompleted(event: any) {
220
- console.log('Captura completada en Angular:', event.detail);
220
+ console.log('Capture completed in Angular:', event.detail);
221
221
  this.capturedData = event.detail;
222
222
  this.isCompleted = true;
223
223
  }
224
224
 
225
225
  onComponentReady(event: any) {
226
- console.log('Componente listo en Angular:', event.detail);
227
- // El componente está listo para iniciar detección
226
+ console.log('Component ready in Angular:', event.detail);
227
+ // The component is ready to start detection
228
228
  }
229
229
  }
230
230
  ```
231
231
 
232
232
  ### React
233
233
 
234
- #### 1. Instalar el componente
234
+ #### 1. Install the component
235
235
  ```bash
236
236
  npm install @jaak.ai/stamps
237
237
  ```
238
238
 
239
- #### 2. Crear componente wrapper (opcional pero recomendado)
239
+ #### 2. Create wrapper component (optional but recommended)
240
240
  ```jsx
241
241
  // JaakStampsWrapper.jsx
242
242
  import React, { useRef, useEffect, useImperativeHandle, forwardRef } from 'react';
243
243
 
244
- // Importar el web component
244
+ // Import the web component
245
245
  import '@jaak.ai/stamps/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js';
246
246
 
247
- const JaakStampsWrapper = forwardRef(({ debug = false, maskSize = 90, cropMargin = 0, useDocumentClassification = false, onCaptureCompleted, onIsReady }, ref) => {
247
+ const JaakStampsWrapper = forwardRef(({ debug = false, maskSize = 80, cropMargin = 20, useDocumentClassification = false, onCaptureCompleted, onIsReady }, ref) => {
248
248
  const elementRef = useRef(null);
249
249
 
250
250
  useImperativeHandle(ref, () => ({
@@ -298,7 +298,7 @@ const JaakStampsWrapper = forwardRef(({ debug = false, maskSize = 90, cropMargin
298
298
  export default JaakStampsWrapper;
299
299
  ```
300
300
 
301
- #### 3. Usar en tu aplicación React
301
+ #### 3. Use in your React application
302
302
  ```jsx
303
303
  // App.jsx
304
304
  import React, { useRef, useState } from 'react';
@@ -311,22 +311,22 @@ function App() {
311
311
  const [status, setStatus] = useState(null);
312
312
 
313
313
  const handleCaptureCompleted = (data) => {
314
- console.log('Captura completada:', data);
314
+ console.log('Capture completed:', data);
315
315
  setCapturedData(data);
316
316
  setIsCompleted(true);
317
317
  };
318
318
 
319
319
  const handleIsReady = (isReady) => {
320
- console.log('Componente listo:', isReady);
321
- // El componente está listo para iniciar detección
320
+ console.log('Component ready:', isReady);
321
+ // The component is ready to start detection
322
322
  };
323
323
 
324
324
  const preloadModel = async () => {
325
325
  try {
326
326
  const result = await detectorRef.current?.preloadModel();
327
- console.log('Modelo precargado:', result);
327
+ console.log('Model preloaded:', result);
328
328
  } catch (error) {
329
- console.error('Error al precargar modelo:', error);
329
+ console.error('Error preloading model:', error);
330
330
  }
331
331
  };
332
332
 
@@ -334,7 +334,7 @@ function App() {
334
334
  try {
335
335
  await detectorRef.current?.startCapture();
336
336
  } catch (error) {
337
- console.error('Error al iniciar captura:', error);
337
+ console.error('Error starting capture:', error);
338
338
  }
339
339
  };
340
340
 
@@ -351,9 +351,9 @@ function App() {
351
351
  const getImages = async () => {
352
352
  try {
353
353
  const images = await detectorRef.current?.getCapturedImages();
354
- console.log('Imágenes obtenidas:', images);
354
+ console.log('Images obtained:', images);
355
355
  } catch (error) {
356
- console.error('Error al obtener imágenes:', error);
356
+ console.error('Error getting images:', error);
357
357
  }
358
358
  };
359
359
 
@@ -365,52 +365,51 @@ function App() {
365
365
  return (
366
366
  <div className="App">
367
367
  <header className="App-header">
368
- <h1>Detector de Documentos - React</h1>
368
+ <h1>Document Detector - React</h1>
369
369
 
370
370
  <JaakStampsWrapper
371
371
  ref={detectorRef}
372
372
  debug={false}
373
- maskSize={90}
374
- cropMargin={10}
373
+ maskSize={80}
374
+ cropMargin={20}
375
375
  useDocumentClassification={false}
376
376
  onCaptureCompleted={handleCaptureCompleted}
377
377
  onIsReady={handleIsReady}
378
378
  />
379
379
 
380
380
  <div className="controls">
381
- <button onClick={preloadModel}>Precargar Modelo</button>
382
- <button onClick={startCapture}>Iniciar Captura</button>
383
- <button onClick={stopCapture}>Detener</button>
384
- <button onClick={resetCapture}>Reiniciar</button>
381
+ <button onClick={preloadModel}>Preload Model</button>
382
+ <button onClick={startCapture}>Start Capture</button>
383
+ <button onClick={stopCapture}>Stop</button>
384
+ <button onClick={resetCapture}>Reset</button>
385
385
  <button onClick={getImages} disabled={!isCompleted}>
386
- Obtener Imágenes
386
+ Get Images
387
387
  </button>
388
- <button onClick={checkStatus}>Verificar Estado</button>
388
+ <button onClick={checkStatus}>Check Status</button>
389
389
  </div>
390
390
 
391
391
  {status && (
392
392
  <div className="status">
393
- <h3>Estado Actual:</h3>
394
- <p>Video activo: {status.isVideoActive ? '' : 'No'}</p>
395
- <p>Paso: {status.captureStep}</p>
396
- <p>Mensaje: {status.statusMessage}</p>
397
- <p>Proceso completado: {status.isProcessCompleted ? '' : 'No'}</p>
398
- <p>Modelo precargado: {status.isModelPreloaded ? 'Sí' : 'No'}</p>
393
+ <h3>Current Status:</h3>
394
+ <p>Video active: {status.isVideoActive ? 'Yes' : 'No'}</p>
395
+ <p>Step: {status.captureStep}</p>
396
+ <p>Process completed: {status.isProcessCompleted ? 'Yes' : 'No'}</p>
397
+ <p>Model preloaded: {status.isModelPreloaded ? 'Yes' : 'No'}</p>
399
398
  </div>
400
399
  )}
401
400
 
402
401
  {capturedData && (
403
402
  <div className="results">
404
- <h3>Resultados de la Captura:</h3>
405
- <p>Total de imágenes: {capturedData.metadata.totalImages}</p>
403
+ <h3>Capture Results:</h3>
404
+ <p>Total images: {capturedData.metadata.totalImages}</p>
406
405
  <p>Timestamp: {capturedData.timestamp}</p>
407
406
 
408
407
  {capturedData.front.cropped && (
409
408
  <div>
410
- <h4>Frente del Documento:</h4>
409
+ <h4>Document Front:</h4>
411
410
  <img
412
411
  src={capturedData.front.cropped}
413
- alt="Frente del documento"
412
+ alt="Document front"
414
413
  style={{ maxWidth: '300px', border: '1px solid #ccc', margin: '10px' }}
415
414
  />
416
415
  </div>
@@ -418,10 +417,10 @@ function App() {
418
417
 
419
418
  {capturedData.back.cropped && (
420
419
  <div>
421
- <h4>Reverso del Documento:</h4>
420
+ <h4>Document Back:</h4>
422
421
  <img
423
422
  src={capturedData.back.cropped}
424
- alt="Reverso del documento"
423
+ alt="Document back"
425
424
  style={{ maxWidth: '300px', border: '1px solid #ccc', margin: '10px' }}
426
425
  />
427
426
  </div>
@@ -438,170 +437,175 @@ export default App;
438
437
 
439
438
  ## API Reference
440
439
 
441
- ### Props/Atributos
440
+ ### Properties/Attributes
442
441
 
443
- | Propiedad | Tipo | Predeterminado | Descripción |
444
- |-----------|------|---------------|-------------|
445
- | `debug` | `boolean` | `false` | Activa el modo debug para mostrar información de depuración |
446
- | `alignmentTolerance` | `number` | `10` | Tolerancia en píxeles para considerar un lado alineado |
447
- | `maskSize` | `number` | `90` | Porcentaje del video que ocupará la máscara de detección (50-100) |
448
- | `cropMargin` | `number` | `0` | Margen en píxeles agregado al recorte del documento (0-100) |
449
- | `useDocumentClassification` | `boolean` | `false` | Habilita la clasificación automática de documentos para determinar si solicitar reverso. Solo carga el modelo de clasificación cuando está habilitada. |
442
+ | Property | Type | Default | Description |
443
+ |----------|------|---------|-------------|
444
+ | `debug` | `boolean` | `false` | Enables debug mode to show debugging information |
445
+ | `alignmentTolerance` | `number` | `15` | Tolerance in pixels to consider a side aligned |
446
+ | `maskSize` | `number` | `80` | Percentage of video that the detection mask will occupy (50-100) |
447
+ | `cropMargin` | `number` | `20` | Margin in pixels added to the document crop (0-100) |
448
+ | `captureDelay` | `number` | `1500` | Time in milliseconds the document must remain in position before automatically capturing (0-10000) |
449
+ | `useDocumentClassification` | `boolean` | `false` | Enables automatic document classification to determine if back capture is required. Only loads the classification model when enabled. |
450
+ | `preferredCamera` | `'auto' \| 'front' \| 'back'` | `'auto'` | Defines which camera to use: `'auto'` (automatic based on device), `'front'` (front camera), `'back'` (back camera) |
450
451
 
451
- ### Métodos Públicos
452
+ ### Public Methods
452
453
 
453
- | Método | Retorna | Descripción |
454
+ | Method | Returns | Description |
454
455
  |--------|---------|-------------|
455
- | `startCapture()` | `Promise<void>` | Inicia el proceso de detección y captura |
456
- | `stopCapture()` | `Promise<void>` | Detiene el proceso y libera la cámara |
457
- | `resetCapture()` | `Promise<void>` | Reinicia el proceso de captura |
458
- | `preloadModel()` | `Promise<{success: boolean, message?: string, error?: string}>` | Precarga el modelo de detección |
459
- | `getCapturedImages()` | `Promise<CapturedImages>` | Obtiene las imágenes capturadas (solo después de completar) |
460
- | `isProcessCompleted()` | `Promise<boolean>` | Verifica si el proceso ha sido completado |
461
- | `getStatus()` | `Promise<Status>` | Obtiene el estado actual del detector |
462
- | `skipBackCapture()` | `Promise<void>` | Omite la captura del reverso (solo disponible en paso 'back') |
463
-
464
- ### Eventos
465
-
466
- | Evento | Payload | Descripción |
467
- |--------|---------|-------------|
468
- | `captureCompleted` | `CapturedImages` | Se emite cuando se completa el proceso de captura |
469
- | `isReady` | `boolean` | Se emite cuando el componente está listo para comenzar la detección (modelos cargados) |
470
-
471
- ### Tipos de Datos
456
+ | `startCapture()` | `Promise<void>` | Starts the detection and capture process |
457
+ | `stopCapture()` | `Promise<void>` | Stops the process and releases the camera |
458
+ | `resetCapture()` | `Promise<void>` | Resets the capture process |
459
+ | `preloadModel()` | `Promise<{success: boolean, message?: string, error?: string}>` | Preloads the detection model |
460
+ | `getCapturedImages()` | `Promise<CapturedImages>` | Gets the captured images (only after completion) |
461
+ | `isProcessCompleted()` | `Promise<boolean>` | Checks if the process has been completed |
462
+ | `getStatus()` | `Promise<Status>` | Gets the current detector status |
463
+ | `skipBackCapture()` | `Promise<void>` | Skips back capture (only available in 'back' step) |
464
+ | `getCameraInfo()` | `Promise<CameraInfo>` | Gets detailed information about available cameras |
465
+ | `setPreferredCamera(camera)` | `Promise<{success: boolean, selectedCamera: string, availableCameras: number}>` | Sets the preferred camera ('auto', 'front', 'back') |
466
+ | `setCaptureDelay(delay)` | `Promise<{success: boolean, captureDelay: number}>` | Sets the wait time before automatically capturing (0-10000ms) |
467
+ | `getCaptureDelay()` | `Promise<number>` | Gets the current wait time configured for automatic capture |
468
+ | `setTorchEnabled(enabled)` | `Promise<{success: boolean, enabled: boolean}>` | Enables or disables the camera torch/flash |
469
+ | `focusAtPoint(x, y)` | `Promise<{success: boolean, coordinates: {x: number, y: number}}>` | Focuses the camera at specific coordinates |
470
+
471
+ ### Events
472
+
473
+ | Event | Payload | Description |
474
+ |-------|---------|-------------|
475
+ | `captureCompleted` | `CapturedImages` | Emitted when the capture process is completed |
476
+ | `isReady` | `boolean` | Emitted when the component is ready to start detection (models loaded) |
477
+
478
+ ### Data Types
472
479
 
473
480
  ```typescript
474
481
  interface CapturedImages {
475
482
  front: {
476
- fullFrame: string | null; // Base64 de la imagen completa del frente
477
- cropped: string | null; // Base64 del documento recortado del frente
483
+ fullFrame: string | null; // Base64 of the complete front image
484
+ cropped: string | null; // Base64 of the cropped front document
478
485
  };
479
486
  back: {
480
- fullFrame: string | null; // Base64 de la imagen completa del reverso
481
- cropped: string | null; // Base64 del documento recortado del reverso
487
+ fullFrame: string | null; // Base64 of the complete back image
488
+ cropped: string | null; // Base64 of the cropped back document
482
489
  };
483
- timestamp: string; // ISO timestamp de la captura
490
+ timestamp: string; // ISO timestamp of capture
484
491
  metadata: {
485
- totalImages: number; // Número total de imágenes capturadas
486
- processCompleted: boolean; // Si el proceso fue completado
487
- backCaptureSkipped?: boolean; // Si se omitió la captura del reverso
492
+ totalImages: number; // Total number of captured images
493
+ processCompleted: boolean; // If the process was completed
494
+ backCaptureSkipped?: boolean; // If back capture was skipped
488
495
  };
489
496
  }
490
497
 
491
498
  interface Status {
492
- isVideoActive: boolean; // Si la cámara está activa
493
- captureStep: 'front' | 'back' | 'completed'; // Paso actual del proceso
494
- statusMessage: string; // Mensaje de estado actual
495
- hasImages: boolean; // Si hay imágenes capturadas
496
- isProcessCompleted: boolean; // Si el proceso está completado
497
- isModelPreloaded: boolean; // Si el modelo está precargado
499
+ isVideoActive: boolean; // If the camera is active
500
+ captureStep: 'front' | 'back' | 'completed'; // Current process step
501
+ hasImages: boolean; // If there are captured images
502
+ isProcessCompleted: boolean; // If the process is completed
503
+ isModelPreloaded: boolean; // If the model is preloaded
498
504
  }
499
505
  ```
500
506
 
501
- ## Flujo de Trabajo
502
-
503
- ### Flujo Estándar (useDocumentClassification = false)
504
- 1. **Inicialización**: El componente se prepara para la detección
505
- 2. **Inicio de captura**: Se carga automáticamente el modelo de detección
506
- 3. **Captura del frente**: El usuario posiciona el documento y se captura automáticamente
507
- 4. **Solicitud de reverso**: Siempre se solicita voltear el documento para capturar el reverso
508
- 5. **Botón "Saltar reverso"**: Disponible para omitir manualmente la captura del reverso
509
- 6. **Completado**: Se emite el evento `captureCompleted` con las imágenes correspondientes
510
-
511
- ### Flujo con Clasificación Inteligente (useDocumentClassification = true)
512
- 1. **Inicialización**: El componente se prepara para la detección
513
- 2. **Inicio de captura**: Se cargan automáticamente los modelos de detección y clasificación
514
- 3. **Captura del frente**: El usuario posiciona el documento y se captura automáticamente
515
- 4. **Clasificación automática**: El sistema determina si el documento requiere captura de reverso
516
- 5. **Flujo adaptativo**:
517
- - **Si es pasaporte**: Se completa automáticamente el proceso (sin reverso)
518
- - **Si es otro documento**: Se solicita voltear el documento para capturar el reverso
519
- 6. **Completado**: Se emite el evento `captureCompleted` con las imágenes correspondientes
520
-
521
- ### Flujo con Precarga (Recomendado)
522
- 1. **Precarga de modelos**: Se llama a `preloadModel()` para cargar ambos modelos en memoria
523
- 2. **Inicio optimizado**: Al iniciar la captura, se usan los modelos ya cargados
524
- 3. **Captura del frente**: Detección y clasificación más rápidas con modelos precargados
525
- 4. **Flujo inteligente**:
526
- - **Documento sin reverso**: Proceso completado inmediatamente
527
- - **Documento con reverso**: Se solicita captura del reverso
528
- 5. **Completado**: Se emite el evento `captureCompleted` con todas las imágenes
529
-
530
- ### Clasificación de Documentos
531
-
532
- #### Modo con Clasificación Habilitada (`useDocumentClassification = true`)
533
- Cuando la propiedad está habilitada, el sistema utiliza un modelo de inteligencia artificial especializado para determinar automáticamente si el documento requiere captura de reverso:
534
- - **Pasaportes**: Se omite automáticamente la captura del reverso
535
- - **Otros documentos**: Requieren captura de ambos lados (frente y reverso)
536
- - **Botón "Saltar reverso"**: Siempre disponible para permitir flexibilidad manual
537
- - **Carga optimizada**: El modelo de clasificación se descarga solo cuando es necesario
538
-
539
- #### Modo Estándar (`useDocumentClassification = false`, por defecto)
540
- Cuando está deshabilitada, el comportamiento es más liviano y directo:
541
- - **Todos los documentos**: Siempre se solicita captura del reverso
542
- - **Botón "Saltar reverso"**: Disponible para omitir manualmente la captura
543
- - **Sin clasificación**: NO se carga el modelo de clasificación, solo el de detección
544
- - **Menor uso de ancho de banda**: Solo descarga el modelo de detección (~5MB menos)
545
-
546
- #### Consideraciones de Rendimiento
547
- - **Con clasificación deshabilitada**: Carga más rápida y menor uso de datos
548
- - **Con clasificación habilitada**: Experiencia más inteligente pero requiere descargar modelo adicional
549
- - **Carga bajo demanda**: El modelo de clasificación se carga solo cuando se captura el primer documento
550
-
551
- ## Requisitos del Sistema
552
-
553
- - **Navegadores**: Chrome/Edge 88+, Firefox 85+, Safari 14+
554
- - **Cámara**: Acceso a cámara trasera (móvil) o webcam (escritorio)
555
- - **Conexión**: Conexión a internet para cargar los modelos de IA
556
-
557
- ## Consideraciones de Privacidad y Rendimiento
558
-
559
- ### Privacidad
560
- - Las imágenes se procesan localmente en el navegador
561
- - No se envían datos a servidores externos
562
- - Los modelos de IA (detección y clasificación) se ejecutan completamente en el cliente
563
- - La clasificación de documentos se realiza de forma privada y local
564
- - Las imágenes capturadas solo están disponibles en el contexto de tu aplicación
565
-
566
- ### Optimización de Recursos
567
- - **Carga condicional**: Solo descarga modelos necesarios según configuración
568
- - **Modelo de detección**: ~15MB (siempre requerido)
569
- - **Modelo de clasificación**: ~5MB (solo si `useDocumentClassification = true`)
570
- - **Lazy loading**: Los modelos se cargan cuando realmente se necesitan
571
- - **Cache del navegador**: Los modelos se almacenan localmente después de la primera descarga
572
-
573
- ## Desarrollo
574
-
575
- ### Clonar el repositorio
507
+ ## Workflow
508
+
509
+ ### Standard Flow (useDocumentClassification = false)
510
+ 1. **Initialization**: Component prepares for detection
511
+ 2. **Start capture**: Detection model loads automatically
512
+ 3. **Front capture**: User positions document and it captures automatically
513
+ 4. **Back request**: Always requests to flip document for back capture
514
+ 5. **Skip back button**: Available to manually skip back capture
515
+ 6. **Completed**: Emits `captureCompleted` event with corresponding images
516
+
517
+ ### Smart Classification Flow (useDocumentClassification = true)
518
+ 1. **Initialization**: Component prepares for detection
519
+ 2. **Start capture**: Detection and classification models load automatically
520
+ 3. **Front capture**: User positions document and it captures automatically
521
+ 4. **Automatic classification**: System determines if document requires back capture
522
+ 5. **Adaptive flow**:
523
+ - **If passport**: Process completes automatically (no back side)
524
+ - **If other document**: Requests to flip document for back capture
525
+ 6. **Completed**: Emits `captureCompleted` event with corresponding images
526
+
527
+ ### Preload Flow (Recommended)
528
+ 1. **Model preload**: Call `preloadModel()` to load models in memory
529
+ 2. **Optimized start**: When starting capture, uses already loaded models
530
+ 3. **Front capture**: Faster detection and classification with preloaded models
531
+ 4. **Smart flow**:
532
+ - **Document without back**: Process completed immediately
533
+ - **Document with back**: Requests back capture
534
+ 5. **Completed**: Emits `captureCompleted` event with all images
535
+
536
+ ### Document Classification
537
+
538
+ #### Classification Enabled Mode (`useDocumentClassification = true`)
539
+ When enabled, the system automatically determines if the document requires back capture:
540
+ - **Passports**: Automatically skips back capture
541
+ - **Other documents**: Require capture of both sides (front and back)
542
+ - **Skip back button**: Always available for manual flexibility
543
+ - **Optimized loading**: Classification model downloads only when needed
544
+
545
+ #### Standard Mode (`useDocumentClassification = false`, default)
546
+ When disabled, behavior is lighter and more direct:
547
+ - **All documents**: Always requests back capture
548
+ - **Skip back button**: Available to manually skip capture
549
+ - **No classification**: Only loads detection model
550
+ - **Lower bandwidth usage**: Downloads only detection model
551
+
552
+ #### Performance Considerations
553
+ - **Classification disabled**: Faster loading and lower data usage
554
+ - **Classification enabled**: Smarter experience but requires additional model download
555
+ - **On-demand loading**: Classification model loads only when first document is captured
556
+
557
+ ## System Requirements
558
+
559
+ - **Browsers**: Chrome/Edge 88+, Firefox 85+, Safari 14+
560
+ - **Camera**: Access to rear camera (mobile) or webcam (desktop)
561
+ - **Connection**: Internet connection to load detection models
562
+
563
+ ## Privacy and Performance Considerations
564
+
565
+ ### Privacy
566
+ - Images are processed locally in the browser
567
+ - No data is sent to external servers
568
+ - All processing runs completely on the client side
569
+ - Document classification is performed privately and locally
570
+ - Captured images are only available within your application context
571
+
572
+ ### Resource Optimization
573
+ - **Conditional loading**: Only downloads necessary models based on configuration
574
+ - **Lazy loading**: Models load when actually needed
575
+ - **Browser cache**: Models are stored locally after first download
576
+
577
+ ## Development
578
+
579
+ ### Clone the repository
576
580
  ```bash
577
581
  git clone [repository-url]
578
582
  cd jaak-stamps-webcomponent
579
583
  ```
580
584
 
581
- ### Instalar dependencias
585
+ ### Install dependencies
582
586
  ```bash
583
587
  npm install
584
588
  ```
585
589
 
586
- ### Desarrollo local
590
+ ### Local development
587
591
  ```bash
588
592
  npm start
589
593
  ```
590
594
 
591
- ### Construir para producción
595
+ ### Build for production
592
596
  ```bash
593
597
  npm run build
594
598
  ```
595
599
 
596
- ### Ejecutar tests
600
+ ### Run tests
597
601
  ```bash
598
602
  npm test
599
603
  ```
600
604
 
601
- ## Soporte
605
+ ## Support
602
606
 
603
- Para reportar bugs o solicitar características, por favor crea un issue en el repositorio del proyecto.
607
+ To report bugs or request features, please create an issue in the project repository.
604
608
 
605
- ## Licencia
609
+ ## License
606
610
 
607
- MIT License - ver archivo LICENSE para detalles.
611
+ MIT License - see LICENSE file for details.