@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.
- package/dist/cjs/jaak-stamps-webcomponent.cjs.js +1 -1
- package/dist/cjs/jaak-stamps.cjs.entry.js +232 -17
- package/dist/cjs/jaak-stamps.cjs.entry.js.map +1 -1
- package/dist/cjs/jaak-stamps.entry.cjs.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/my-component/my-component.css +10 -7
- package/dist/collection/components/my-component/my-component.js +233 -17
- package/dist/collection/components/my-component/my-component.js.map +1 -1
- package/dist/components/jaak-stamps.js +233 -17
- package/dist/components/jaak-stamps.js.map +1 -1
- package/dist/esm/jaak-stamps-webcomponent.js +1 -1
- package/dist/esm/jaak-stamps.entry.js +232 -17
- package/dist/esm/jaak-stamps.entry.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js +1 -1
- package/dist/jaak-stamps-webcomponent/jaak-stamps.entry.esm.js.map +1 -1
- package/dist/jaak-stamps-webcomponent/p-dd6cc14e.entry.js +2 -0
- package/dist/jaak-stamps-webcomponent/p-dd6cc14e.entry.js.map +1 -0
- package/dist/types/components/my-component/my-component.d.ts +6 -2
- package/package.json +1 -1
- package/dist/jaak-stamps-webcomponent/p-4688150a.entry.js +0 -2
- package/dist/jaak-stamps-webcomponent/p-4688150a.entry.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { p as proxyCustomElement, H, c as createEvent, h } from './index.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%;
|
|
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$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H {
|
|
6
6
|
constructor() {
|
|
@@ -37,6 +37,7 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
37
37
|
isDetectionPaused = false;
|
|
38
38
|
isLoading = false;
|
|
39
39
|
isModelPreloaded = false;
|
|
40
|
+
isMaskReady = false;
|
|
40
41
|
videoRef;
|
|
41
42
|
canvasRef;
|
|
42
43
|
session;
|
|
@@ -60,8 +61,8 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
60
61
|
MODEL_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/detector-nano.onnx";
|
|
61
62
|
INPUT_SIZE = 320;
|
|
62
63
|
CONFIDENCE_THRESHOLD = 0.6;
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
// ISO/IEC 7810 ID-1 standard dimensions (85.60mm x 53.98mm)
|
|
65
|
+
ID1_ASPECT_RATIO = 85.60 / 53.98; // 1.5863320574...
|
|
65
66
|
debugLog(...args) {
|
|
66
67
|
if (this.debug) {
|
|
67
68
|
console.log(...args);
|
|
@@ -95,6 +96,91 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
95
96
|
}
|
|
96
97
|
// Initialize canvas pool for better performance
|
|
97
98
|
this.initializeCanvasPool();
|
|
99
|
+
this.setupResizeObserver();
|
|
100
|
+
}
|
|
101
|
+
setupResizeObserver() {
|
|
102
|
+
if ('ResizeObserver' in window && this.canvasRef) {
|
|
103
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
104
|
+
this.handleResize();
|
|
105
|
+
});
|
|
106
|
+
resizeObserver.observe(this.canvasRef.parentElement);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
handleResize() {
|
|
110
|
+
if (this.canvasRef) {
|
|
111
|
+
const container = this.canvasRef.parentElement;
|
|
112
|
+
const rect = container.getBoundingClientRect();
|
|
113
|
+
// Set canvas size to match container
|
|
114
|
+
this.canvasRef.width = rect.width;
|
|
115
|
+
this.canvasRef.height = rect.height;
|
|
116
|
+
// Update mask positioning based on container and video dimensions
|
|
117
|
+
this.updateMaskDimensions(rect);
|
|
118
|
+
this.debugLog('📐 Canvas resized:', { width: rect.width, height: rect.height });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
updateMaskDimensions(containerRect) {
|
|
122
|
+
if (!this.videoRef)
|
|
123
|
+
return;
|
|
124
|
+
const videoWidth = this.videoRef.videoWidth;
|
|
125
|
+
const videoHeight = this.videoRef.videoHeight;
|
|
126
|
+
if (videoWidth === 0 || videoHeight === 0)
|
|
127
|
+
return;
|
|
128
|
+
// Calculate video aspect ratio and container aspect ratio
|
|
129
|
+
const videoAspectRatio = videoWidth / videoHeight;
|
|
130
|
+
const containerAspectRatio = containerRect.width / containerRect.height;
|
|
131
|
+
// Determine how video fits in container (letterboxed or pillarboxed)
|
|
132
|
+
let displayedVideoWidth, displayedVideoHeight;
|
|
133
|
+
let videoOffsetX = 0, videoOffsetY = 0;
|
|
134
|
+
if (videoAspectRatio > containerAspectRatio) {
|
|
135
|
+
// Video is wider - letterboxed (black bars top/bottom)
|
|
136
|
+
displayedVideoWidth = containerRect.width;
|
|
137
|
+
displayedVideoHeight = containerRect.width / videoAspectRatio;
|
|
138
|
+
videoOffsetY = (containerRect.height - displayedVideoHeight) / 2;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// Video is taller - pillarboxed (black bars left/right)
|
|
142
|
+
displayedVideoHeight = containerRect.height;
|
|
143
|
+
displayedVideoWidth = containerRect.height * videoAspectRatio;
|
|
144
|
+
videoOffsetX = (containerRect.width - displayedVideoWidth) / 2;
|
|
145
|
+
}
|
|
146
|
+
// Calculate maximum possible mask size while preserving exact ID-1 aspect ratio
|
|
147
|
+
// Determine the limiting dimension based on video orientation and ID-1 proportions
|
|
148
|
+
// Calculate what would be the max width if limited by video height
|
|
149
|
+
const maxWidthByHeight = displayedVideoHeight * this.ID1_ASPECT_RATIO;
|
|
150
|
+
let maskWidthInVideo, maskHeightInVideo;
|
|
151
|
+
if (maxWidthByHeight <= displayedVideoWidth) {
|
|
152
|
+
// Video height is the limiting factor
|
|
153
|
+
maskHeightInVideo = displayedVideoHeight * 0.9; // Use 90% of available height
|
|
154
|
+
maskWidthInVideo = maskHeightInVideo * this.ID1_ASPECT_RATIO;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// Video width is the limiting factor
|
|
158
|
+
maskWidthInVideo = displayedVideoWidth * 0.9; // Use 90% of available width
|
|
159
|
+
maskHeightInVideo = maskWidthInVideo / this.ID1_ASPECT_RATIO;
|
|
160
|
+
}
|
|
161
|
+
// Convert to percentages of the container
|
|
162
|
+
const maskWidthPercent = (maskWidthInVideo / containerRect.width) * 100;
|
|
163
|
+
const maskHeightPercent = (maskHeightInVideo / containerRect.height) * 100;
|
|
164
|
+
// Calculate the center position of the displayed video area
|
|
165
|
+
const videoCenterX = videoOffsetX + (displayedVideoWidth / 2);
|
|
166
|
+
const videoCenterY = videoOffsetY + (displayedVideoHeight / 2);
|
|
167
|
+
// Convert to percentages of the container
|
|
168
|
+
const videoCenterXPercent = (videoCenterX / containerRect.width) * 100;
|
|
169
|
+
const videoCenterYPercent = (videoCenterY / containerRect.height) * 100;
|
|
170
|
+
// Update CSS custom properties for mask sizing and positioning
|
|
171
|
+
this.el.style.setProperty('--mask-width', `${maskWidthPercent}%`);
|
|
172
|
+
this.el.style.setProperty('--mask-height', `${maskHeightPercent}%`);
|
|
173
|
+
this.el.style.setProperty('--mask-center-x', `${videoCenterXPercent}%`);
|
|
174
|
+
this.el.style.setProperty('--mask-center-y', `${videoCenterYPercent}%`);
|
|
175
|
+
// Mark mask as ready now that dimensions are calculated
|
|
176
|
+
this.isMaskReady = true;
|
|
177
|
+
this.debugLog('🎯 Mask dimensions updated:', {
|
|
178
|
+
video: { width: videoWidth, height: videoHeight },
|
|
179
|
+
displayed: { width: displayedVideoWidth, height: displayedVideoHeight },
|
|
180
|
+
mask: { widthPercent: maskWidthPercent, heightPercent: maskHeightPercent },
|
|
181
|
+
center: { x: videoCenterXPercent, y: videoCenterYPercent },
|
|
182
|
+
offset: { x: videoOffsetX, y: videoOffsetY }
|
|
183
|
+
});
|
|
98
184
|
}
|
|
99
185
|
initializeCanvasPool() {
|
|
100
186
|
// Preprocess canvas - reused for every inference
|
|
@@ -226,14 +312,60 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
226
312
|
this.isModelPreloaded = false;
|
|
227
313
|
this.debugLog('🧹 Canvas pool cleaned up');
|
|
228
314
|
}
|
|
315
|
+
async getMaxResolution() {
|
|
316
|
+
try {
|
|
317
|
+
// Primero obtén un stream básico para acceder a las capacidades
|
|
318
|
+
const tempStream = await navigator.mediaDevices.getUserMedia({
|
|
319
|
+
video: { facingMode: "environment" }
|
|
320
|
+
});
|
|
321
|
+
const videoTrack = tempStream.getVideoTracks()[0];
|
|
322
|
+
const capabilities = videoTrack.getCapabilities();
|
|
323
|
+
// Detener el stream temporal
|
|
324
|
+
tempStream.getTracks().forEach(track => track.stop());
|
|
325
|
+
// Construir restricciones con resolución optimizada para tablets
|
|
326
|
+
const constraints = {
|
|
327
|
+
facingMode: "environment"
|
|
328
|
+
};
|
|
329
|
+
if (capabilities.width && capabilities.height) {
|
|
330
|
+
// Limitar resolución máxima para tablets para evitar problemas de rendimiento
|
|
331
|
+
const maxWidth = Math.min(capabilities.width.max, 1920);
|
|
332
|
+
const maxHeight = Math.min(capabilities.height.max, 1080);
|
|
333
|
+
// Para tablets, usar resolución moderada en lugar de máxima
|
|
334
|
+
const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
|
|
335
|
+
if (isTablet) {
|
|
336
|
+
constraints.width = { ideal: Math.min(maxWidth, 1280) };
|
|
337
|
+
constraints.height = { ideal: Math.min(maxHeight, 720) };
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
constraints.width = { ideal: maxWidth };
|
|
341
|
+
constraints.height = { ideal: maxHeight };
|
|
342
|
+
}
|
|
343
|
+
this.debugLog('📐 Resolution capabilities:', {
|
|
344
|
+
maxWidth: capabilities.width.max,
|
|
345
|
+
maxHeight: capabilities.height.max,
|
|
346
|
+
selectedWidth: constraints.width.ideal,
|
|
347
|
+
selectedHeight: constraints.height.ideal,
|
|
348
|
+
isTablet
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
return constraints;
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
this.debugLog('⚠️ Could not get capabilities, using fallback');
|
|
355
|
+
// Fallback optimizado para tablets
|
|
356
|
+
const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth >= 768;
|
|
357
|
+
return {
|
|
358
|
+
facingMode: "environment",
|
|
359
|
+
width: { ideal: isTablet ? 1280 : 1920 },
|
|
360
|
+
height: { ideal: isTablet ? 720 : 1080 }
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
229
364
|
async setupCamera() {
|
|
230
365
|
try {
|
|
366
|
+
const constraints = await this.getMaxResolution();
|
|
231
367
|
const stream = await navigator.mediaDevices.getUserMedia({
|
|
232
|
-
video:
|
|
233
|
-
width: { exact: 640 },
|
|
234
|
-
height: { exact: 640 },
|
|
235
|
-
facingMode: "environment"
|
|
236
|
-
},
|
|
368
|
+
video: constraints,
|
|
237
369
|
audio: false
|
|
238
370
|
});
|
|
239
371
|
if (this.videoRef) {
|
|
@@ -248,6 +380,12 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
248
380
|
this.videoRef.onloadedmetadata = async () => {
|
|
249
381
|
await this.videoRef.play();
|
|
250
382
|
this.isVideoActive = true;
|
|
383
|
+
// Update mask dimensions once video is loaded
|
|
384
|
+
if (this.canvasRef) {
|
|
385
|
+
const container = this.canvasRef.parentElement;
|
|
386
|
+
const rect = container.getBoundingClientRect();
|
|
387
|
+
this.updateMaskDimensions(rect);
|
|
388
|
+
}
|
|
251
389
|
resolve();
|
|
252
390
|
};
|
|
253
391
|
});
|
|
@@ -425,13 +563,57 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
425
563
|
return isCentered && isGoodSize;
|
|
426
564
|
}
|
|
427
565
|
checkSideAlignment(box) {
|
|
428
|
-
|
|
566
|
+
if (!this.videoRef)
|
|
567
|
+
return { top: false, right: false, bottom: false, left: false };
|
|
568
|
+
// Get video dimensions to calculate actual mask boundaries in model space
|
|
569
|
+
const videoWidth = this.videoRef.videoWidth;
|
|
570
|
+
const videoHeight = this.videoRef.videoHeight;
|
|
571
|
+
if (videoWidth === 0 || videoHeight === 0) {
|
|
572
|
+
return { top: false, right: false, bottom: false, left: false };
|
|
573
|
+
}
|
|
574
|
+
// Calculate video aspect ratio
|
|
575
|
+
const videoAspectRatio = videoWidth / videoHeight;
|
|
576
|
+
// The model sees video stretched to 320x320, but we need to calculate where
|
|
577
|
+
// the mask should be in this distorted space to match the visual mask
|
|
578
|
+
// In the visual display, we calculate mask size based on the limiting dimension
|
|
579
|
+
// We need to replicate this logic but account for the distortion in model space
|
|
580
|
+
// Calculate the "display" dimensions (what the visual mask calculations use)
|
|
581
|
+
const containerAspectRatio = 1; // Assume square container for simplicity
|
|
582
|
+
let displayedVideoWidth, displayedVideoHeight;
|
|
583
|
+
if (videoAspectRatio > containerAspectRatio) {
|
|
584
|
+
// Video is wider - letterboxed in display
|
|
585
|
+
displayedVideoWidth = this.INPUT_SIZE;
|
|
586
|
+
displayedVideoHeight = this.INPUT_SIZE / videoAspectRatio;
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
// Video is taller - pillarboxed in display
|
|
590
|
+
displayedVideoHeight = this.INPUT_SIZE;
|
|
591
|
+
displayedVideoWidth = this.INPUT_SIZE * videoAspectRatio;
|
|
592
|
+
}
|
|
593
|
+
// Calculate mask dimensions using the same logic as updateMaskDimensions
|
|
594
|
+
const maxWidthByHeight = displayedVideoHeight * this.ID1_ASPECT_RATIO;
|
|
595
|
+
let visualMaskWidth, visualMaskHeight;
|
|
596
|
+
if (maxWidthByHeight <= displayedVideoWidth) {
|
|
597
|
+
// Video height is the limiting factor
|
|
598
|
+
visualMaskHeight = displayedVideoHeight * 0.9;
|
|
599
|
+
visualMaskWidth = visualMaskHeight * this.ID1_ASPECT_RATIO;
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
// Video width is the limiting factor
|
|
603
|
+
visualMaskWidth = displayedVideoWidth * 0.9;
|
|
604
|
+
visualMaskHeight = visualMaskWidth / this.ID1_ASPECT_RATIO;
|
|
605
|
+
}
|
|
606
|
+
// Now map these visual mask dimensions to the distorted model space
|
|
607
|
+
// The model stretches video to 320x320, so we need to apply the inverse transformation
|
|
608
|
+
const modelMaskWidth = visualMaskWidth * (this.INPUT_SIZE / displayedVideoWidth);
|
|
609
|
+
const modelMaskHeight = visualMaskHeight * (this.INPUT_SIZE / displayedVideoHeight);
|
|
610
|
+
// Calculate mask boundaries in model coordinate system (always centered in 320x320)
|
|
429
611
|
const maskCenterX = this.INPUT_SIZE / 2;
|
|
430
612
|
const maskCenterY = this.INPUT_SIZE / 2;
|
|
431
|
-
const maskLeft = maskCenterX - (
|
|
432
|
-
const maskRight = maskCenterX + (
|
|
433
|
-
const maskTop = maskCenterY - (
|
|
434
|
-
const maskBottom = maskCenterY + (
|
|
613
|
+
const maskLeft = maskCenterX - (modelMaskWidth / 2);
|
|
614
|
+
const maskRight = maskCenterX + (modelMaskWidth / 2);
|
|
615
|
+
const maskTop = maskCenterY - (modelMaskHeight / 2);
|
|
616
|
+
const maskBottom = maskCenterY + (modelMaskHeight / 2);
|
|
435
617
|
// Obtener las coordenadas del documento detectado
|
|
436
618
|
let docLeft = box.x;
|
|
437
619
|
let docRight = box.x + box.w;
|
|
@@ -528,12 +710,45 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
528
710
|
}
|
|
529
711
|
}
|
|
530
712
|
drawDetections(ctx, boxes) {
|
|
531
|
-
|
|
532
|
-
|
|
713
|
+
if (!this.videoRef)
|
|
714
|
+
return;
|
|
715
|
+
// Get video and container dimensions
|
|
716
|
+
const videoWidth = this.videoRef.videoWidth;
|
|
717
|
+
const videoHeight = this.videoRef.videoHeight;
|
|
718
|
+
const containerWidth = this.canvasRef.width;
|
|
719
|
+
const containerHeight = this.canvasRef.height;
|
|
720
|
+
if (videoWidth === 0 || videoHeight === 0)
|
|
721
|
+
return;
|
|
722
|
+
// Calculate video aspect ratio and container aspect ratio
|
|
723
|
+
const videoAspectRatio = videoWidth / videoHeight;
|
|
724
|
+
const containerAspectRatio = containerWidth / containerHeight;
|
|
725
|
+
// Determine how video fits in container (same logic as updateMaskDimensions)
|
|
726
|
+
let displayedVideoWidth, displayedVideoHeight;
|
|
727
|
+
let videoOffsetX = 0, videoOffsetY = 0;
|
|
728
|
+
if (videoAspectRatio > containerAspectRatio) {
|
|
729
|
+
// Video is wider - letterboxed (black bars top/bottom)
|
|
730
|
+
displayedVideoWidth = containerWidth;
|
|
731
|
+
displayedVideoHeight = containerWidth / videoAspectRatio;
|
|
732
|
+
videoOffsetY = (containerHeight - displayedVideoHeight) / 2;
|
|
733
|
+
}
|
|
734
|
+
else {
|
|
735
|
+
// Video is taller - pillarboxed (black bars left/right)
|
|
736
|
+
displayedVideoHeight = containerHeight;
|
|
737
|
+
displayedVideoWidth = containerHeight * videoAspectRatio;
|
|
738
|
+
videoOffsetX = (containerWidth - displayedVideoWidth) / 2;
|
|
739
|
+
}
|
|
740
|
+
// Scale factor from model coordinates (320x320) to displayed video area
|
|
741
|
+
const scaleX = displayedVideoWidth / this.INPUT_SIZE;
|
|
742
|
+
const scaleY = displayedVideoHeight / this.INPUT_SIZE;
|
|
533
743
|
boxes.forEach(det => {
|
|
744
|
+
// Convert model coordinates to displayed video coordinates
|
|
745
|
+
const x = det.x * scaleX + videoOffsetX;
|
|
746
|
+
const y = det.y * scaleY + videoOffsetY;
|
|
747
|
+
const w = det.w * scaleX;
|
|
748
|
+
const h = det.h * scaleY;
|
|
534
749
|
ctx.strokeStyle = "#32406C";
|
|
535
750
|
ctx.lineWidth = 2;
|
|
536
|
-
ctx.strokeRect(
|
|
751
|
+
ctx.strokeRect(x, y, w, h);
|
|
537
752
|
});
|
|
538
753
|
}
|
|
539
754
|
takeScreenshot() {
|
|
@@ -699,7 +914,7 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
699
914
|
this.cleanup();
|
|
700
915
|
}
|
|
701
916
|
render() {
|
|
702
|
-
return (h("div", { key: '
|
|
917
|
+
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" })))));
|
|
703
918
|
}
|
|
704
919
|
static get style() { return myComponentCss; }
|
|
705
920
|
}, [1, "jaak-stamps", {
|
|
@@ -722,6 +937,7 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
722
937
|
"isDetectionPaused": [32],
|
|
723
938
|
"isLoading": [32],
|
|
724
939
|
"isModelPreloaded": [32],
|
|
940
|
+
"isMaskReady": [32],
|
|
725
941
|
"getCapturedImages": [64],
|
|
726
942
|
"isProcessCompleted": [64],
|
|
727
943
|
"startCapture": [64],
|