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

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,45 @@ 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 la resolución máxima
324
+ const constraints = {
325
+ facingMode: "environment"
326
+ };
327
+ if (capabilities.width && capabilities.height) {
328
+ constraints.width = { ideal: capabilities.width.max };
329
+ constraints.height = { ideal: capabilities.height.max };
330
+ this.debugLog('📐 Max resolution capabilities:', {
331
+ width: capabilities.width.max,
332
+ height: capabilities.height.max
333
+ });
334
+ }
335
+ return constraints;
336
+ }
337
+ catch (err) {
338
+ this.debugLog('⚠️ Could not get capabilities, using fallback');
339
+ // Fallback para dispositivos que no soportan getCapabilities
340
+ return {
341
+ facingMode: "environment",
342
+ width: { ideal: 1920 },
343
+ height: { ideal: 1080 }
344
+ };
345
+ }
346
+ }
227
347
  async setupCamera() {
228
348
  try {
349
+ const constraints = await this.getMaxResolution();
229
350
  const stream = await navigator.mediaDevices.getUserMedia({
230
- video: {
231
- width: { exact: 640 },
232
- height: { exact: 640 },
233
- facingMode: "environment"
234
- },
351
+ video: constraints,
235
352
  audio: false
236
353
  });
237
354
  if (this.videoRef) {
@@ -246,6 +363,12 @@ const JaakStamps = class {
246
363
  this.videoRef.onloadedmetadata = async () => {
247
364
  await this.videoRef.play();
248
365
  this.isVideoActive = true;
366
+ // Update mask dimensions once video is loaded
367
+ if (this.canvasRef) {
368
+ const container = this.canvasRef.parentElement;
369
+ const rect = container.getBoundingClientRect();
370
+ this.updateMaskDimensions(rect);
371
+ }
249
372
  resolve();
250
373
  };
251
374
  });
@@ -423,13 +546,57 @@ const JaakStamps = class {
423
546
  return isCentered && isGoodSize;
424
547
  }
425
548
  checkSideAlignment(box) {
426
- // Obtener las coordenadas del marco de referencia (máscara)
549
+ if (!this.videoRef)
550
+ return { top: false, right: false, bottom: false, left: false };
551
+ // Get video dimensions to calculate actual mask boundaries in model space
552
+ const videoWidth = this.videoRef.videoWidth;
553
+ const videoHeight = this.videoRef.videoHeight;
554
+ if (videoWidth === 0 || videoHeight === 0) {
555
+ return { top: false, right: false, bottom: false, left: false };
556
+ }
557
+ // Calculate video aspect ratio
558
+ const videoAspectRatio = videoWidth / videoHeight;
559
+ // The model sees video stretched to 320x320, but we need to calculate where
560
+ // the mask should be in this distorted space to match the visual mask
561
+ // In the visual display, we calculate mask size based on the limiting dimension
562
+ // We need to replicate this logic but account for the distortion in model space
563
+ // Calculate the "display" dimensions (what the visual mask calculations use)
564
+ const containerAspectRatio = 1; // Assume square container for simplicity
565
+ let displayedVideoWidth, displayedVideoHeight;
566
+ if (videoAspectRatio > containerAspectRatio) {
567
+ // Video is wider - letterboxed in display
568
+ displayedVideoWidth = this.INPUT_SIZE;
569
+ displayedVideoHeight = this.INPUT_SIZE / videoAspectRatio;
570
+ }
571
+ else {
572
+ // Video is taller - pillarboxed in display
573
+ displayedVideoHeight = this.INPUT_SIZE;
574
+ displayedVideoWidth = this.INPUT_SIZE * videoAspectRatio;
575
+ }
576
+ // Calculate mask dimensions using the same logic as updateMaskDimensions
577
+ const maxWidthByHeight = displayedVideoHeight * this.ID1_ASPECT_RATIO;
578
+ let visualMaskWidth, visualMaskHeight;
579
+ if (maxWidthByHeight <= displayedVideoWidth) {
580
+ // Video height is the limiting factor
581
+ visualMaskHeight = displayedVideoHeight * 0.9;
582
+ visualMaskWidth = visualMaskHeight * this.ID1_ASPECT_RATIO;
583
+ }
584
+ else {
585
+ // Video width is the limiting factor
586
+ visualMaskWidth = displayedVideoWidth * 0.9;
587
+ visualMaskHeight = visualMaskWidth / this.ID1_ASPECT_RATIO;
588
+ }
589
+ // Now map these visual mask dimensions to the distorted model space
590
+ // The model stretches video to 320x320, so we need to apply the inverse transformation
591
+ const modelMaskWidth = visualMaskWidth * (this.INPUT_SIZE / displayedVideoWidth);
592
+ const modelMaskHeight = visualMaskHeight * (this.INPUT_SIZE / displayedVideoHeight);
593
+ // Calculate mask boundaries in model coordinate system (always centered in 320x320)
427
594
  const maskCenterX = this.INPUT_SIZE / 2;
428
595
  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);
596
+ const maskLeft = maskCenterX - (modelMaskWidth / 2);
597
+ const maskRight = maskCenterX + (modelMaskWidth / 2);
598
+ const maskTop = maskCenterY - (modelMaskHeight / 2);
599
+ const maskBottom = maskCenterY + (modelMaskHeight / 2);
433
600
  // Obtener las coordenadas del documento detectado
434
601
  let docLeft = box.x;
435
602
  let docRight = box.x + box.w;
@@ -526,12 +693,45 @@ const JaakStamps = class {
526
693
  }
527
694
  }
528
695
  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;
696
+ if (!this.videoRef)
697
+ return;
698
+ // Get video and container dimensions
699
+ const videoWidth = this.videoRef.videoWidth;
700
+ const videoHeight = this.videoRef.videoHeight;
701
+ const containerWidth = this.canvasRef.width;
702
+ const containerHeight = this.canvasRef.height;
703
+ if (videoWidth === 0 || videoHeight === 0)
704
+ return;
705
+ // Calculate video aspect ratio and container aspect ratio
706
+ const videoAspectRatio = videoWidth / videoHeight;
707
+ const containerAspectRatio = containerWidth / containerHeight;
708
+ // Determine how video fits in container (same logic as updateMaskDimensions)
709
+ let displayedVideoWidth, displayedVideoHeight;
710
+ let videoOffsetX = 0, videoOffsetY = 0;
711
+ if (videoAspectRatio > containerAspectRatio) {
712
+ // Video is wider - letterboxed (black bars top/bottom)
713
+ displayedVideoWidth = containerWidth;
714
+ displayedVideoHeight = containerWidth / videoAspectRatio;
715
+ videoOffsetY = (containerHeight - displayedVideoHeight) / 2;
716
+ }
717
+ else {
718
+ // Video is taller - pillarboxed (black bars left/right)
719
+ displayedVideoHeight = containerHeight;
720
+ displayedVideoWidth = containerHeight * videoAspectRatio;
721
+ videoOffsetX = (containerWidth - displayedVideoWidth) / 2;
722
+ }
723
+ // Scale factor from model coordinates (320x320) to displayed video area
724
+ const scaleX = displayedVideoWidth / this.INPUT_SIZE;
725
+ const scaleY = displayedVideoHeight / this.INPUT_SIZE;
531
726
  boxes.forEach(det => {
727
+ // Convert model coordinates to displayed video coordinates
728
+ const x = det.x * scaleX + videoOffsetX;
729
+ const y = det.y * scaleY + videoOffsetY;
730
+ const w = det.w * scaleX;
731
+ const h = det.h * scaleY;
532
732
  ctx.strokeStyle = "#32406C";
533
733
  ctx.lineWidth = 2;
534
- ctx.strokeRect(det.x * scale, det.y * scale, det.w * scale, det.h * scale);
734
+ ctx.strokeRect(x, y, w, h);
535
735
  });
536
736
  }
537
737
  takeScreenshot() {
@@ -697,7 +897,7 @@ const JaakStamps = class {
697
897
  this.cleanup();
698
898
  }
699
899
  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" })))));
900
+ return (h("div", { key: 'c95e9dee4b79561384fe1777b99a4cc4fa92bdbe', class: "detector-container" }, h("div", { key: 'a002fed79f5fd475a636818535a4a65324ec3fbf', class: "video-container" }, h("video", { key: '1a2a79193aac789c53b899da06e24bc4fe71891e', ref: el => this.videoRef = el, autoplay: true, muted: true, playsinline: true, class: this.shouldMirrorVideo ? 'mirror' : '', style: { display: this.isVideoActive ? 'block' : 'none' } }), h("canvas", { key: '1771841686ff849a70d3b8e23034a44880494c7e', ref: el => this.canvasRef = el, class: this.shouldMirrorVideo ? 'mirror' : '' }), this.isMaskReady && (h("div", { key: '29563822f3ec6c0d00ef20fb2da346b2d9c24175', class: "overlay-mask" }, h("div", { key: 'e70ec55cfc25697e62981ffbfb5c78dc32821daa', class: "card-outline" }, h("div", { key: '1ae7dae4facd6971a3031cec4992f657192855da', class: "side side-top" }), h("div", { key: 'efec73ad8e754a279443a93f05c7e416476540c3', class: "side side-right" }), h("div", { key: '42dca6ffed2ac93bffd48877b3ef05e11aa16bac', class: "side side-bottom" }), h("div", { key: 'e872078e654987be4d02600b866f39767bff6c91', class: "side side-left" }), h("div", { key: '71dc7e353e6a11ddc6e300ddd6a96c483dc8e43d', class: "corner corner-tl" }), h("div", { key: 'e380c3c0526f8c6c5f6caefc2ea1feabc17b0b4a', class: "corner corner-tr" }), h("div", { key: 'de4720a6418ec86931c24a0542cffdbba8211b22', class: "corner corner-bl" }), h("div", { key: '338a487a89c9c4d1662428fdc73cdb355766149c', class: "corner corner-br" }), !this.showFlipAnimation && !this.showSuccessAnimation && (h("div", { key: '34190a47c348dd00d48467c4edfd80efaf0494cd', class: "guide-text" }, this.statusMessage))), this.captureStep === 'back' && !this.showFlipAnimation && !this.showSuccessAnimation && (h("button", { key: 'c585163a9db511b461d575594b2c8f5a79cbc1d2', class: "skip-button", onClick: () => this.skipBackCapture(), type: "button" }, "Saltar reverso")))), this.isCapturing && (h("div", { key: 'bc56a29c90d7177cad35c930ed54304bb20f700e', class: "capture-animation" })), this.showFlipAnimation && (h("div", { key: '1d636a6dde80ec90f6db7868a0abd163af8a8836', class: "flip-animation" }, h("div", { key: '95a78fbba1f340d8a56b24a9dda4a4c888cc2d44', class: "id-card-icon" }), h("div", { key: 'bb8e11d34b31cb0d28c2b1f2d02a1cc85b8dd1b3', class: "flip-text" }, "\u00A1Voltea tu identificaci\u00F3n!"))), this.showSuccessAnimation && (h("div", { key: 'ae2ce6604dccccb27995cbcc0ba0635c36125e9f', class: "success-animation" }, h("div", { key: '713cdfca5618225281106ed9da9c30c7f00d2f96', class: "check-icon" }), h("div", { key: '9ac255f66474d6a0d546c4f28dd1464dc1db199c', class: "success-text" }, "\u00A1Proceso completado!"))), this.isLoading && (h("div", { key: 'f3d08c1ba7596c70b3184b6023e4c330cadf395e', class: "loading-overlay" }, h("div", { key: '989ebafd27b84d6e86483569fb28a2df3dc587d5', class: "loading-spinner" }), h("div", { key: 'b14a356fde939b9bd52733bafaba762e5c5b2503', class: "loading-text" }, this.statusMessage))), h("div", { key: '3ff6690dc129f0981eb21de785c631c1221dbd5b', class: "watermark" }, h("img", { key: '67ad3a5d54c9dd1b36fae6f5857695b8dd1a2447', src: "https://storage.googleapis.com/jaak-static/commons/powered-by-jaak.png", alt: "Powered by Jaak" })))));
701
901
  }
702
902
  };
703
903
  JaakStamps.style = myComponentCss;