@jaak.ai/stamps 2.0.0-dev.19 → 2.0.0-dev.21

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.
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, c as createEvent, a as getElement, h } from './index-DqoVMnc7.js';
2
2
 
3
- const myComponentCss = ":host{display:block;font-family:system-ui, -apple-system, sans-serif;color:#1a1a1a}.detector-container{display:flex;flex-direction:column;align-items:center}h1{font-size:24px;font-weight:500;color:#333;margin:0 0 24px 0}.video-container{position:relative;width:100%;max-width:640px;aspect-ratio:1;background:#fff;border:1px solid #e0e0e0;border-radius:8px;overflow:hidden}video,canvas{position:absolute;width:100%;height:100%;border-radius:8px}video.mirror,canvas.mirror{transform:rotateY(180deg)}canvas{z-index:1}video{z-index:0}.status{margin-top:16px;font-size:12px;color:#666}.overlay-mask{position:absolute;top:0;left:0;width:100%;height:100%;z-index:10;display:block;pointer-events:none}.card-outline{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);width:88%;height:55%;border:none;border-radius:4px;background:transparent;box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7);opacity:0.8}.card-outline.perfect-match{box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7)}.side{position:absolute;background:#999;transition:background-color 0.3s ease}.side.aligned{background:#28a745}.side-top{top:0;left:0;width:100%;height:3px}.side-right{top:0;right:0;width:3px;height:100%}.side-bottom{bottom:0;left:0;width:100%;height:3px}.side-left{top:0;left:0;width:3px;height:100%}.corner{position:absolute;width:20px;height:20px;border:2px solid #999;z-index:12}.corner-tl{top:-10px;left:-10px;border-right:none;border-bottom:none}.corner-tr{top:-10px;right:-10px;border-left:none;border-bottom:none}.corner-bl{bottom:-10px;left:-10px;border-right:none;border-top:none}.corner-br{bottom:-10px;right:-10px;border-left:none;border-top:none}.corner.perfect-match{border-color:#28a745}.guide-text{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);color:#fff;font-size:14px;font-weight:600;text-align:center;white-space:normal;background:rgba(128, 128, 128, 0.8);padding:12px 20px;border-radius:20px;max-width:300px;z-index:20}.capture-animation{position:absolute;top:0;left:0;width:100%;height:100%;background:#fff;opacity:0;z-index:30;pointer-events:none;animation:captureFlash 0.6s ease-out}@keyframes captureFlash{0%{opacity:0}15%{opacity:0.8}30%{opacity:0}45%{opacity:0.4}60%{opacity:0}100%{opacity:0}}.card-outline.capturing{animation:pulseGreen 0.6s ease-out}@keyframes pulseGreen{0%{border-color:#28a745;box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 0 4px rgba(40, 167, 69, 0)}50%{border-color:#28a745;box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 0 8px rgba(40, 167, 69, 0.6)}100%{border-color:#28a745;box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 0 4px rgba(40, 167, 69, 0)}}.flip-animation{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);z-index:35;pointer-events:none;opacity:0;animation:showFlipInstruction 3s ease-in-out;display:flex;flex-direction:column;align-items:center;justify-content:center}.id-card-icon{width:80px;height:50px;background:linear-gradient(135deg, #6c757d 0%, #495057 100%);border-radius:8px;position:relative;animation:flipCard 2s ease-in-out infinite;box-shadow:0 4px 12px rgba(0, 0, 0, 0.3)}.id-card-icon::before{content:'';position:absolute;top:8px;left:8px;width:16px;height:12px;background:rgba(255, 255, 255, 0.9);border-radius:2px}.id-card-icon::after{content:'';position:absolute;top:25px;left:8px;width:64px;height:3px;background:rgba(255, 255, 255, 0.7);border-radius:1px;box-shadow:0 6px 0 rgba(255, 255, 255, 0.7), 0 12px 0 rgba(255, 255, 255, 0.7)}.flip-text{margin-top:12px;color:#fff;font-size:14px;font-weight:600;text-align:center;background:rgba(128, 128, 128, 0.8);padding:12px 20px;border-radius:20px;max-width:300px}@keyframes showFlipInstruction{0%{opacity:0;transform:translate(-50%, -50%) scale(0.8)}15%{opacity:1;transform:translate(-50%, -50%) scale(1)}85%{opacity:1;transform:translate(-50%, -50%) scale(1)}100%{opacity:0;transform:translate(-50%, -50%) scale(0.8)}}@keyframes flipCard{0%{transform:rotateY(0deg)}50%{transform:rotateY(180deg)}100%{transform:rotateY(360deg)}}.success-animation{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);z-index:35;pointer-events:none;opacity:0;animation:showSuccessMessage 3s ease-in-out;display:flex;flex-direction:column;align-items:center;justify-content:center}.check-icon{width:80px;height:80px;background:linear-gradient(135deg, #6c757d 0%, #495057 100%);border-radius:50%;position:relative;animation:bounceSuccess 0.6s ease-out;box-shadow:0 4px 16px rgba(108, 117, 125, 0.4);display:flex;align-items:center;justify-content:center}.check-icon::before{content:'';position:absolute;width:20px;height:35px;border:4px solid #fff;border-top:none;border-left:none;transform:rotate(45deg);animation:drawCheck 0.4s ease-out 0.2s both}.success-text{margin-top:16px;color:#fff;font-size:14px;font-weight:600;text-align:center;background:rgba(128, 128, 128, 0.8);padding:12px 20px;border-radius:20px;max-width:300px;animation:fadeInUp 0.5s ease-out 0.4s both}@keyframes showSuccessMessage{0%{opacity:0;transform:translate(-50%, -50%) scale(0.5)}15%{opacity:1;transform:translate(-50%, -50%) scale(1)}85%{opacity:1;transform:translate(-50%, -50%) scale(1)}100%{opacity:0;transform:translate(-50%, -50%) scale(0.9)}}@keyframes bounceSuccess{0%{transform:scale(0)}50%{transform:scale(1.1)}100%{transform:scale(1)}}@keyframes drawCheck{0%{width:0;height:0}50%{width:20px;height:0}100%{width:20px;height:35px}}@keyframes fadeInUp{0%{opacity:0;transform:translateY(20px)}100%{opacity:1;transform:translateY(0)}}.skip-button{position:absolute;bottom:20px;left:50%;transform:translateX(-50%);z-index:25;pointer-events:auto;background:#fff;color:#333;border:none;border-radius:25px;padding:12px 24px;font-size:14px;font-weight:600;cursor:pointer;transition:all 0.3s ease}.skip-button:hover{background:#f8f9fa}.skip-button:active{background:#e9ecef;transform:translateX(-50%) translateY(0)}.watermark{position:absolute;bottom:12px;right:12px;z-index:15;pointer-events:none;opacity:0.7}.watermark img{height:24px;width:auto;filter:drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3))}.loading-overlay{position:absolute;top:0;left:0;width:100%;height:100%;background:rgba(0, 0, 0, 0.8);display:flex;flex-direction:column;align-items:center;justify-content:center;z-index:30;border-radius:20px}.loading-spinner{width:60px;height:60px;border:4px solid rgba(255, 255, 255, 0.2);border-top:4px solid #007bff;border-radius:50%;animation:spin 1s linear infinite;margin-bottom:20px}.loading-text{color:white;font-size:16px;font-weight:500;text-align:center;opacity:0.9}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}";
3
+ const myComponentCss = ":host{display:block;width:100%;height:100%;font-family:system-ui, -apple-system, sans-serif;color:#1a1a1a}.detector-container{display:flex;flex-direction:column;align-items:center;width:100%;height:100%}h1{font-size:24px;font-weight:500;color:#333;margin:0 0 24px 0}.video-container{position:relative;width:100%;height:100%;background:#333;border:1px solid #e0e0e0;border-radius:8px;overflow:hidden}video,canvas{position:absolute;width:100%;height:100%;border-radius:8px}video.mirror,canvas.mirror{transform:rotateY(180deg)}canvas{z-index:1}video{z-index:0}.status{margin-top:16px;font-size:12px;color:#666}.overlay-mask{position:absolute;top:0;left:0;width:100%;height:100%;z-index:10;display:block;pointer-events:none}.card-outline{position:absolute;top:var(--mask-center-y, 50%);left:var(--mask-center-x, 50%);transform:translate(-50%, -50%);width:var(--mask-width, 88%);height:var(--mask-height, 55%);border:none;border-radius:4px;background:transparent;box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7);opacity:0.8}.card-outline.perfect-match{box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7)}.side{position:absolute;background:#999;transition:background-color 0.3s ease}.side.aligned{background:#28a745}.side-top{top:0;left:0;width:100%;height:3px}.side-right{top:0;right:0;width:3px;height:100%}.side-bottom{bottom:0;left:0;width:100%;height:3px}.side-left{top:0;left:0;width:3px;height:100%}.corner{position:absolute;width:20px;height:20px;border:2px solid #999;z-index:12}.corner-tl{top:-10px;left:-10px;border-right:none;border-bottom:none}.corner-tr{top:-10px;right:-10px;border-left:none;border-bottom:none}.corner-bl{bottom:-10px;left:-10px;border-right:none;border-top:none}.corner-br{bottom:-10px;right:-10px;border-left:none;border-top:none}.corner.perfect-match{border-color:#28a745}.guide-text{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);color:#fff;font-size:14px;font-weight:600;text-align:center;white-space:normal;background:rgba(128, 128, 128, 0.8);padding:12px 20px;border-radius:20px;max-width:300px;z-index:20}.capture-animation{position:absolute;top:0;left:0;width:100%;height:100%;background:#fff;opacity:0;z-index:30;pointer-events:none;animation:captureFlash 0.6s ease-out}@keyframes captureFlash{0%{opacity:0}15%{opacity:0.8}30%{opacity:0}45%{opacity:0.4}60%{opacity:0}100%{opacity:0}}.card-outline.capturing{animation:pulseGreen 0.6s ease-out}@keyframes pulseGreen{0%{border-color:#28a745;box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 0 4px rgba(40, 167, 69, 0)}50%{border-color:#28a745;box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 0 8px rgba(40, 167, 69, 0.6)}100%{border-color:#28a745;box-shadow:0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 0 4px rgba(40, 167, 69, 0)}}.flip-animation{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);z-index:35;pointer-events:none;opacity:0;animation:showFlipInstruction 3s ease-in-out;display:flex;flex-direction:column;align-items:center;justify-content:center}.id-card-icon{width:80px;height:50px;background:linear-gradient(135deg, #6c757d 0%, #495057 100%);border-radius:8px;position:relative;animation:flipCard 2s ease-in-out infinite;box-shadow:0 4px 12px rgba(0, 0, 0, 0.3)}.id-card-icon::before{content:'';position:absolute;top:8px;left:8px;width:16px;height:12px;background:rgba(255, 255, 255, 0.9);border-radius:2px}.id-card-icon::after{content:'';position:absolute;top:25px;left:8px;width:64px;height:3px;background:rgba(255, 255, 255, 0.7);border-radius:1px;box-shadow:0 6px 0 rgba(255, 255, 255, 0.7), 0 12px 0 rgba(255, 255, 255, 0.7)}.flip-text{margin-top:12px;color:#fff;font-size:14px;font-weight:600;text-align:center;background:rgba(128, 128, 128, 0.8);padding:12px 20px;border-radius:20px;max-width:300px}@keyframes showFlipInstruction{0%{opacity:0;transform:translate(-50%, -50%) scale(0.8)}15%{opacity:1;transform:translate(-50%, -50%) scale(1)}85%{opacity:1;transform:translate(-50%, -50%) scale(1)}100%{opacity:0;transform:translate(-50%, -50%) scale(0.8)}}@keyframes flipCard{0%{transform:rotateY(0deg)}50%{transform:rotateY(180deg)}100%{transform:rotateY(360deg)}}.success-animation{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);z-index:35;pointer-events:none;opacity:0;animation:showSuccessMessage 3s ease-in-out;display:flex;flex-direction:column;align-items:center;justify-content:center}.check-icon{width:80px;height:80px;background:linear-gradient(135deg, #6c757d 0%, #495057 100%);border-radius:50%;position:relative;animation:bounceSuccess 0.6s ease-out;box-shadow:0 4px 16px rgba(108, 117, 125, 0.4);display:flex;align-items:center;justify-content:center}.check-icon::before{content:'';position:absolute;width:20px;height:35px;border:4px solid #fff;border-top:none;border-left:none;transform:rotate(45deg);animation:drawCheck 0.4s ease-out 0.2s both}.success-text{margin-top:16px;color:#fff;font-size:14px;font-weight:600;text-align:center;background:rgba(128, 128, 128, 0.8);padding:12px 20px;border-radius:20px;max-width:300px;animation:fadeInUp 0.5s ease-out 0.4s both}@keyframes showSuccessMessage{0%{opacity:0;transform:translate(-50%, -50%) scale(0.5)}15%{opacity:1;transform:translate(-50%, -50%) scale(1)}85%{opacity:1;transform:translate(-50%, -50%) scale(1)}100%{opacity:0;transform:translate(-50%, -50%) scale(0.9)}}@keyframes bounceSuccess{0%{transform:scale(0)}50%{transform:scale(1.1)}100%{transform:scale(1)}}@keyframes drawCheck{0%{width:0;height:0}50%{width:20px;height:0}100%{width:20px;height:35px}}@keyframes fadeInUp{0%{opacity:0;transform:translateY(20px)}100%{opacity:1;transform:translateY(0)}}.skip-button{position:absolute;bottom:20px;left:50%;transform:translateX(-50%);z-index:25;pointer-events:auto;background:#fff;color:#333;border:none;border-radius:25px;padding:12px 24px;font-size:14px;font-weight:600;cursor:pointer;transition:all 0.3s ease}.skip-button:hover{background:#f8f9fa}.skip-button:active{background:#e9ecef;transform:translateX(-50%) translateY(0)}.watermark{position:absolute;bottom:12px;right:12px;z-index:15;pointer-events:none;opacity:0.7}.watermark img{height:24px;width:auto;filter:drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3))}.loading-overlay{position:absolute;top:0;left:0;width:100%;height:100%;background:rgba(0, 0, 0, 0.8);display:flex;flex-direction:column;align-items:center;justify-content:center;z-index:30;border-radius:20px}.loading-spinner{width:60px;height:60px;border:4px solid rgba(255, 255, 255, 0.2);border-top:4px solid #007bff;border-radius:50%;animation:spin 1s linear infinite;margin-bottom:20px}.loading-text{color:white;font-size:16px;font-weight:500;text-align:center;opacity:0.9}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}";
4
4
 
5
5
  const JaakStamps = class {
6
6
  constructor(hostRef) {
@@ -35,6 +35,7 @@ const JaakStamps = class {
35
35
  isDetectionPaused = false;
36
36
  isLoading = false;
37
37
  isModelPreloaded = false;
38
+ isMaskReady = false;
38
39
  videoRef;
39
40
  canvasRef;
40
41
  session;
@@ -58,8 +59,8 @@ const JaakStamps = class {
58
59
  MODEL_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/detector-nano.onnx";
59
60
  INPUT_SIZE = 320;
60
61
  CONFIDENCE_THRESHOLD = 0.6;
61
- MASK_WIDTH = 280;
62
- MASK_HEIGHT = 176;
62
+ // ISO/IEC 7810 ID-1 standard dimensions (85.60mm x 53.98mm)
63
+ ID1_ASPECT_RATIO = 85.60 / 53.98; // 1.5863320574...
63
64
  debugLog(...args) {
64
65
  if (this.debug) {
65
66
  console.log(...args);
@@ -93,6 +94,91 @@ const JaakStamps = class {
93
94
  }
94
95
  // Initialize canvas pool for better performance
95
96
  this.initializeCanvasPool();
97
+ this.setupResizeObserver();
98
+ }
99
+ setupResizeObserver() {
100
+ if ('ResizeObserver' in window && this.canvasRef) {
101
+ const resizeObserver = new ResizeObserver(() => {
102
+ this.handleResize();
103
+ });
104
+ resizeObserver.observe(this.canvasRef.parentElement);
105
+ }
106
+ }
107
+ handleResize() {
108
+ if (this.canvasRef) {
109
+ const container = this.canvasRef.parentElement;
110
+ const rect = container.getBoundingClientRect();
111
+ // Set canvas size to match container
112
+ this.canvasRef.width = rect.width;
113
+ this.canvasRef.height = rect.height;
114
+ // Update mask positioning based on container and video dimensions
115
+ this.updateMaskDimensions(rect);
116
+ this.debugLog('📐 Canvas resized:', { width: rect.width, height: rect.height });
117
+ }
118
+ }
119
+ updateMaskDimensions(containerRect) {
120
+ if (!this.videoRef)
121
+ return;
122
+ const videoWidth = this.videoRef.videoWidth;
123
+ const videoHeight = this.videoRef.videoHeight;
124
+ if (videoWidth === 0 || videoHeight === 0)
125
+ return;
126
+ // Calculate video aspect ratio and container aspect ratio
127
+ const videoAspectRatio = videoWidth / videoHeight;
128
+ const containerAspectRatio = containerRect.width / containerRect.height;
129
+ // Determine how video fits in container (letterboxed or pillarboxed)
130
+ let displayedVideoWidth, displayedVideoHeight;
131
+ let videoOffsetX = 0, videoOffsetY = 0;
132
+ if (videoAspectRatio > containerAspectRatio) {
133
+ // Video is wider - letterboxed (black bars top/bottom)
134
+ displayedVideoWidth = containerRect.width;
135
+ displayedVideoHeight = containerRect.width / videoAspectRatio;
136
+ videoOffsetY = (containerRect.height - displayedVideoHeight) / 2;
137
+ }
138
+ else {
139
+ // Video is taller - pillarboxed (black bars left/right)
140
+ displayedVideoHeight = containerRect.height;
141
+ displayedVideoWidth = containerRect.height * videoAspectRatio;
142
+ videoOffsetX = (containerRect.width - displayedVideoWidth) / 2;
143
+ }
144
+ // Calculate maximum possible mask size while preserving exact ID-1 aspect ratio
145
+ // Determine the limiting dimension based on video orientation and ID-1 proportions
146
+ // Calculate what would be the max width if limited by video height
147
+ const maxWidthByHeight = displayedVideoHeight * this.ID1_ASPECT_RATIO;
148
+ let maskWidthInVideo, maskHeightInVideo;
149
+ if (maxWidthByHeight <= displayedVideoWidth) {
150
+ // Video height is the limiting factor
151
+ maskHeightInVideo = displayedVideoHeight * 0.9; // Use 90% of available height
152
+ maskWidthInVideo = maskHeightInVideo * this.ID1_ASPECT_RATIO;
153
+ }
154
+ else {
155
+ // Video width is the limiting factor
156
+ maskWidthInVideo = displayedVideoWidth * 0.9; // Use 90% of available width
157
+ maskHeightInVideo = maskWidthInVideo / this.ID1_ASPECT_RATIO;
158
+ }
159
+ // Convert to percentages of the container
160
+ const maskWidthPercent = (maskWidthInVideo / containerRect.width) * 100;
161
+ const maskHeightPercent = (maskHeightInVideo / containerRect.height) * 100;
162
+ // Calculate the center position of the displayed video area
163
+ const videoCenterX = videoOffsetX + (displayedVideoWidth / 2);
164
+ const videoCenterY = videoOffsetY + (displayedVideoHeight / 2);
165
+ // Convert to percentages of the container
166
+ const videoCenterXPercent = (videoCenterX / containerRect.width) * 100;
167
+ const videoCenterYPercent = (videoCenterY / containerRect.height) * 100;
168
+ // Update CSS custom properties for mask sizing and positioning
169
+ this.el.style.setProperty('--mask-width', `${maskWidthPercent}%`);
170
+ this.el.style.setProperty('--mask-height', `${maskHeightPercent}%`);
171
+ this.el.style.setProperty('--mask-center-x', `${videoCenterXPercent}%`);
172
+ this.el.style.setProperty('--mask-center-y', `${videoCenterYPercent}%`);
173
+ // Mark mask as ready now that dimensions are calculated
174
+ this.isMaskReady = true;
175
+ this.debugLog('🎯 Mask dimensions updated:', {
176
+ video: { width: videoWidth, height: videoHeight },
177
+ displayed: { width: displayedVideoWidth, height: displayedVideoHeight },
178
+ mask: { widthPercent: maskWidthPercent, heightPercent: maskHeightPercent },
179
+ center: { x: videoCenterXPercent, y: videoCenterYPercent },
180
+ offset: { x: videoOffsetX, y: videoOffsetY }
181
+ });
96
182
  }
97
183
  initializeCanvasPool() {
98
184
  // Preprocess canvas - reused for every inference
@@ -224,14 +310,60 @@ const JaakStamps = class {
224
310
  this.isModelPreloaded = false;
225
311
  this.debugLog('🧹 Canvas pool cleaned up');
226
312
  }
313
+ async getMaxResolution() {
314
+ try {
315
+ // Primero obtén un stream básico para acceder a las capacidades
316
+ const tempStream = await navigator.mediaDevices.getUserMedia({
317
+ video: { facingMode: "environment" }
318
+ });
319
+ const videoTrack = tempStream.getVideoTracks()[0];
320
+ const capabilities = videoTrack.getCapabilities();
321
+ // Detener el stream temporal
322
+ tempStream.getTracks().forEach(track => track.stop());
323
+ // Construir restricciones con resolución optimizada para tablets
324
+ const constraints = {
325
+ facingMode: "environment"
326
+ };
327
+ if (capabilities.width && capabilities.height) {
328
+ // Limitar resolución máxima para tablets para evitar problemas de rendimiento
329
+ const maxWidth = Math.min(capabilities.width.max, 1920);
330
+ const maxHeight = Math.min(capabilities.height.max, 1080);
331
+ // Para tablets, usar resolución moderada en lugar de máxima
332
+ const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
333
+ if (isTablet) {
334
+ constraints.width = { ideal: Math.min(maxWidth, 1280) };
335
+ constraints.height = { ideal: Math.min(maxHeight, 720) };
336
+ }
337
+ else {
338
+ constraints.width = { ideal: maxWidth };
339
+ constraints.height = { ideal: maxHeight };
340
+ }
341
+ this.debugLog('📐 Resolution capabilities:', {
342
+ maxWidth: capabilities.width.max,
343
+ maxHeight: capabilities.height.max,
344
+ selectedWidth: constraints.width.ideal,
345
+ selectedHeight: constraints.height.ideal,
346
+ isTablet
347
+ });
348
+ }
349
+ return constraints;
350
+ }
351
+ catch (err) {
352
+ this.debugLog('⚠️ Could not get capabilities, using fallback');
353
+ // Fallback optimizado para tablets
354
+ const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
355
+ return {
356
+ facingMode: "environment",
357
+ width: { ideal: isTablet ? 1280 : 1920 },
358
+ height: { ideal: isTablet ? 720 : 1080 }
359
+ };
360
+ }
361
+ }
227
362
  async setupCamera() {
228
363
  try {
364
+ const constraints = await this.getMaxResolution();
229
365
  const stream = await navigator.mediaDevices.getUserMedia({
230
- video: {
231
- width: { exact: 640 },
232
- height: { exact: 640 },
233
- facingMode: "environment"
234
- },
366
+ video: constraints,
235
367
  audio: false
236
368
  });
237
369
  if (this.videoRef) {
@@ -246,6 +378,12 @@ const JaakStamps = class {
246
378
  this.videoRef.onloadedmetadata = async () => {
247
379
  await this.videoRef.play();
248
380
  this.isVideoActive = true;
381
+ // Update mask dimensions once video is loaded
382
+ if (this.canvasRef) {
383
+ const container = this.canvasRef.parentElement;
384
+ const rect = container.getBoundingClientRect();
385
+ this.updateMaskDimensions(rect);
386
+ }
249
387
  resolve();
250
388
  };
251
389
  });
@@ -423,13 +561,57 @@ const JaakStamps = class {
423
561
  return isCentered && isGoodSize;
424
562
  }
425
563
  checkSideAlignment(box) {
426
- // Obtener las coordenadas del marco de referencia (máscara)
564
+ if (!this.videoRef)
565
+ return { top: false, right: false, bottom: false, left: false };
566
+ // Get video dimensions to calculate actual mask boundaries in model space
567
+ const videoWidth = this.videoRef.videoWidth;
568
+ const videoHeight = this.videoRef.videoHeight;
569
+ if (videoWidth === 0 || videoHeight === 0) {
570
+ return { top: false, right: false, bottom: false, left: false };
571
+ }
572
+ // Calculate video aspect ratio
573
+ const videoAspectRatio = videoWidth / videoHeight;
574
+ // The model sees video stretched to 320x320, but we need to calculate where
575
+ // the mask should be in this distorted space to match the visual mask
576
+ // In the visual display, we calculate mask size based on the limiting dimension
577
+ // We need to replicate this logic but account for the distortion in model space
578
+ // Calculate the "display" dimensions (what the visual mask calculations use)
579
+ const containerAspectRatio = 1; // Assume square container for simplicity
580
+ let displayedVideoWidth, displayedVideoHeight;
581
+ if (videoAspectRatio > containerAspectRatio) {
582
+ // Video is wider - letterboxed in display
583
+ displayedVideoWidth = this.INPUT_SIZE;
584
+ displayedVideoHeight = this.INPUT_SIZE / videoAspectRatio;
585
+ }
586
+ else {
587
+ // Video is taller - pillarboxed in display
588
+ displayedVideoHeight = this.INPUT_SIZE;
589
+ displayedVideoWidth = this.INPUT_SIZE * videoAspectRatio;
590
+ }
591
+ // Calculate mask dimensions using the same logic as updateMaskDimensions
592
+ const maxWidthByHeight = displayedVideoHeight * this.ID1_ASPECT_RATIO;
593
+ let visualMaskWidth, visualMaskHeight;
594
+ if (maxWidthByHeight <= displayedVideoWidth) {
595
+ // Video height is the limiting factor
596
+ visualMaskHeight = displayedVideoHeight * 0.9;
597
+ visualMaskWidth = visualMaskHeight * this.ID1_ASPECT_RATIO;
598
+ }
599
+ else {
600
+ // Video width is the limiting factor
601
+ visualMaskWidth = displayedVideoWidth * 0.9;
602
+ visualMaskHeight = visualMaskWidth / this.ID1_ASPECT_RATIO;
603
+ }
604
+ // Now map these visual mask dimensions to the distorted model space
605
+ // The model stretches video to 320x320, so we need to apply the inverse transformation
606
+ const modelMaskWidth = visualMaskWidth * (this.INPUT_SIZE / displayedVideoWidth);
607
+ const modelMaskHeight = visualMaskHeight * (this.INPUT_SIZE / displayedVideoHeight);
608
+ // Calculate mask boundaries in model coordinate system (always centered in 320x320)
427
609
  const maskCenterX = this.INPUT_SIZE / 2;
428
610
  const maskCenterY = this.INPUT_SIZE / 2;
429
- const maskLeft = maskCenterX - (this.MASK_WIDTH / 2);
430
- const maskRight = maskCenterX + (this.MASK_WIDTH / 2);
431
- const maskTop = maskCenterY - (this.MASK_HEIGHT / 2);
432
- const maskBottom = maskCenterY + (this.MASK_HEIGHT / 2);
611
+ const maskLeft = maskCenterX - (modelMaskWidth / 2);
612
+ const maskRight = maskCenterX + (modelMaskWidth / 2);
613
+ const maskTop = maskCenterY - (modelMaskHeight / 2);
614
+ const maskBottom = maskCenterY + (modelMaskHeight / 2);
433
615
  // Obtener las coordenadas del documento detectado
434
616
  let docLeft = box.x;
435
617
  let docRight = box.x + box.w;
@@ -526,12 +708,45 @@ const JaakStamps = class {
526
708
  }
527
709
  }
528
710
  drawDetections(ctx, boxes) {
529
- // Scale factor to convert from model coordinates (320x320) to canvas coordinates (640x640)
530
- const scale = this.canvasRef.width / this.INPUT_SIZE;
711
+ if (!this.videoRef)
712
+ return;
713
+ // Get video and container dimensions
714
+ const videoWidth = this.videoRef.videoWidth;
715
+ const videoHeight = this.videoRef.videoHeight;
716
+ const containerWidth = this.canvasRef.width;
717
+ const containerHeight = this.canvasRef.height;
718
+ if (videoWidth === 0 || videoHeight === 0)
719
+ return;
720
+ // Calculate video aspect ratio and container aspect ratio
721
+ const videoAspectRatio = videoWidth / videoHeight;
722
+ const containerAspectRatio = containerWidth / containerHeight;
723
+ // Determine how video fits in container (same logic as updateMaskDimensions)
724
+ let displayedVideoWidth, displayedVideoHeight;
725
+ let videoOffsetX = 0, videoOffsetY = 0;
726
+ if (videoAspectRatio > containerAspectRatio) {
727
+ // Video is wider - letterboxed (black bars top/bottom)
728
+ displayedVideoWidth = containerWidth;
729
+ displayedVideoHeight = containerWidth / videoAspectRatio;
730
+ videoOffsetY = (containerHeight - displayedVideoHeight) / 2;
731
+ }
732
+ else {
733
+ // Video is taller - pillarboxed (black bars left/right)
734
+ displayedVideoHeight = containerHeight;
735
+ displayedVideoWidth = containerHeight * videoAspectRatio;
736
+ videoOffsetX = (containerWidth - displayedVideoWidth) / 2;
737
+ }
738
+ // Scale factor from model coordinates (320x320) to displayed video area
739
+ const scaleX = displayedVideoWidth / this.INPUT_SIZE;
740
+ const scaleY = displayedVideoHeight / this.INPUT_SIZE;
531
741
  boxes.forEach(det => {
742
+ // Convert model coordinates to displayed video coordinates
743
+ const x = det.x * scaleX + videoOffsetX;
744
+ const y = det.y * scaleY + videoOffsetY;
745
+ const w = det.w * scaleX;
746
+ const h = det.h * scaleY;
532
747
  ctx.strokeStyle = "#32406C";
533
748
  ctx.lineWidth = 2;
534
- ctx.strokeRect(det.x * scale, det.y * scale, det.w * scale, det.h * scale);
749
+ ctx.strokeRect(x, y, w, h);
535
750
  });
536
751
  }
537
752
  takeScreenshot() {
@@ -697,7 +912,7 @@ const JaakStamps = class {
697
912
  this.cleanup();
698
913
  }
699
914
  render() {
700
- 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" })))));
915
+ return (h("div", { key: 'b63a5966ee08d4de7b5d8a10dbf248150e8620ec', class: "detector-container" }, h("div", { key: '1c62d540a1802a758b90a543edfdc364123ae950', class: "video-container" }, h("video", { key: '18e066e0005c3b287983ebb29c9e4aa147eaaf8d', ref: el => this.videoRef = el, autoplay: true, muted: true, playsinline: true, class: this.shouldMirrorVideo ? 'mirror' : '', style: { display: this.isVideoActive ? 'block' : 'none' } }), h("canvas", { key: '43cd238e38a5a2ff9c140800ac686580a7ca33b9', ref: el => this.canvasRef = el, class: this.shouldMirrorVideo ? 'mirror' : '' }), this.isMaskReady && (h("div", { key: 'f43db67b9d1ef47264092694c3ab8afa9925e258', class: "overlay-mask" }, h("div", { key: 'ac60d94edc4cfa6ccf91ba6e04d2be6e4368be97', class: "card-outline" }, h("div", { key: 'de6aca9bbfe778890adf4c69e8525a114c37f6d4', class: "side side-top" }), h("div", { key: '7ce7b1e2215b01ea5d714b8ecc988361e384b6f7', class: "side side-right" }), h("div", { key: 'b79a68f68facb42ca139d6a2bc8e1e6d7133872d', class: "side side-bottom" }), h("div", { key: '81d90c4a08cfc2267cec195a3b342c87bb1d07d0', class: "side side-left" }), h("div", { key: 'c93c83abb8e17a5cb9c1bd53b2e1239ef50c7bf4', class: "corner corner-tl" }), h("div", { key: '81ca7cf2aab7026e851bd226843a6db5807315d5', class: "corner corner-tr" }), h("div", { key: 'c451fe226ac15023ee9799443060f1da620cb3b3', class: "corner corner-bl" }), h("div", { key: '7c3e2b2a21bd37144fe6b4d5df67df625dc12103', class: "corner corner-br" }), !this.showFlipAnimation && !this.showSuccessAnimation && (h("div", { key: '74ab171b64bdf0e1269845b4fcd9bf8e2caf891d', class: "guide-text" }, this.statusMessage))), this.captureStep === 'back' && !this.showFlipAnimation && !this.showSuccessAnimation && (h("button", { key: '2b2b9387ce8b023acf0d65c7f7b3480211f7cb2d', class: "skip-button", onClick: () => this.skipBackCapture(), type: "button" }, "Saltar reverso")))), this.isCapturing && (h("div", { key: 'eabd88499f52098f79e434afcce73acb2727c411', class: "capture-animation" })), this.showFlipAnimation && (h("div", { key: '9affe6040a39260747db98db2b68a103fb719fbb', class: "flip-animation" }, h("div", { key: '8b25f3688a16f4b070664237a093122a6720edfb', class: "id-card-icon" }), h("div", { key: '805b11cfb4d06a25e02370b06f6cf15f0f0cf6b5', class: "flip-text" }, "\u00A1Voltea tu identificaci\u00F3n!"))), this.showSuccessAnimation && (h("div", { key: 'cba337b6fef8b919425566c0c9c5de797d42c4c8', class: "success-animation" }, h("div", { key: '4a88df3f9285757b489b030ba985d720a8a3badf', class: "check-icon" }), h("div", { key: 'a0bdd89c2c6274330ba66a6b6bba86ab6c725979', class: "success-text" }, "\u00A1Proceso completado!"))), this.isLoading && (h("div", { key: '564fc1333b0fb69102e26ac1da4e77786a9bc7a3', class: "loading-overlay" }, h("div", { key: '283e4a6315a39b26203e19a13f35389bc1870a0f', class: "loading-spinner" }), h("div", { key: '7e4f00a1fcee1bbf29d74c8be35a72aba2c1041a', class: "loading-text" }, this.statusMessage))), h("div", { key: '6cbe1fea1c4a7d3cb25cd34ee04becb5fa538dfd', class: "watermark" }, h("img", { key: '1bd4157b7f74753570ddf48682acf419a6de03ea', src: "https://storage.googleapis.com/jaak-static/commons/powered-by-jaak.png", alt: "Powered by Jaak" })))));
701
916
  }
702
917
  };
703
918
  JaakStamps.style = myComponentCss;