@jaak.ai/stamps 2.0.0-dev.27 → 2.0.0-dev.28
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.cjs.entry.js +102 -9
- package/dist/cjs/jaak-stamps.cjs.entry.js.map +1 -1
- package/dist/cjs/jaak-stamps.entry.cjs.js.map +1 -1
- package/dist/collection/components/my-component/my-component.js +102 -9
- package/dist/collection/components/my-component/my-component.js.map +1 -1
- package/dist/components/jaak-stamps.js +102 -9
- package/dist/components/jaak-stamps.js.map +1 -1
- package/dist/esm/jaak-stamps.entry.js +102 -9
- package/dist/esm/jaak-stamps.entry.js.map +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-67b8e4cf.entry.js +2 -0
- package/dist/jaak-stamps-webcomponent/p-67b8e4cf.entry.js.map +1 -0
- package/dist/types/components/my-component/my-component.d.ts +1 -0
- package/package.json +1 -1
- package/dist/jaak-stamps-webcomponent/p-eb318f43.entry.js +0 -2
- package/dist/jaak-stamps-webcomponent/p-eb318f43.entry.js.map +0 -1
|
@@ -587,9 +587,36 @@ const JaakStamps = class {
|
|
|
587
587
|
this.debugLog('🤖 Preloading detection model:', modelPath);
|
|
588
588
|
// Configure ONNX Runtime with device-specific optimizations
|
|
589
589
|
const sessionOptions = this.getSessionOptions();
|
|
590
|
-
|
|
590
|
+
const deviceInfo = this.getDeviceMemoryInfo();
|
|
591
|
+
try {
|
|
592
|
+
this.session = await window.ort.InferenceSession.create(modelPath, sessionOptions);
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
if (error.message.includes('failed to allocate a buffer')) {
|
|
596
|
+
this.debugLog('❌ Buffer allocation failed during preload, trying with minimal settings');
|
|
597
|
+
const fallbackOptions = {
|
|
598
|
+
executionProviders: ['wasm'],
|
|
599
|
+
graphOptimizationLevel: 'disabled',
|
|
600
|
+
logSeverityLevel: 4,
|
|
601
|
+
enableCpuMemArena: false,
|
|
602
|
+
enableMemPattern: false,
|
|
603
|
+
executionMode: 'sequential',
|
|
604
|
+
interOpNumThreads: 1,
|
|
605
|
+
intraOpNumThreads: 1,
|
|
606
|
+
};
|
|
607
|
+
this.session = await window.ort.InferenceSession.create(modelPath, fallbackOptions);
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
throw error;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
591
613
|
// Preload MobileNet model and classes only if classification is enabled
|
|
614
|
+
// For low memory devices, load sequentially to avoid memory pressure
|
|
592
615
|
if (this.useDocumentClassification) {
|
|
616
|
+
if (deviceInfo.isLowMemory) {
|
|
617
|
+
this.debugLog('🔄 Sequential model loading for low memory device');
|
|
618
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
619
|
+
}
|
|
593
620
|
await this.loadMobileNetModel();
|
|
594
621
|
}
|
|
595
622
|
this.isModelPreloaded = true;
|
|
@@ -654,7 +681,28 @@ const JaakStamps = class {
|
|
|
654
681
|
this.debugLog('📋 MobileNet classes loaded:', this.mobileNetClassMap);
|
|
655
682
|
// Load model
|
|
656
683
|
const sessionOptions = this.getSessionOptions();
|
|
657
|
-
|
|
684
|
+
try {
|
|
685
|
+
this.mobileNetSession = await window.ort.InferenceSession.create(this.MOBILENET_MODEL_PATH, sessionOptions);
|
|
686
|
+
}
|
|
687
|
+
catch (error) {
|
|
688
|
+
if (error.message.includes('failed to allocate a buffer')) {
|
|
689
|
+
this.debugLog('❌ MobileNet buffer allocation failed, trying with minimal settings');
|
|
690
|
+
const fallbackOptions = {
|
|
691
|
+
executionProviders: ['wasm'],
|
|
692
|
+
graphOptimizationLevel: 'disabled',
|
|
693
|
+
logSeverityLevel: 4,
|
|
694
|
+
enableCpuMemArena: false,
|
|
695
|
+
enableMemPattern: false,
|
|
696
|
+
executionMode: 'sequential',
|
|
697
|
+
interOpNumThreads: 1,
|
|
698
|
+
intraOpNumThreads: 1,
|
|
699
|
+
};
|
|
700
|
+
this.mobileNetSession = await window.ort.InferenceSession.create(this.MOBILENET_MODEL_PATH, fallbackOptions);
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
throw error;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
658
706
|
this.debugLog('✅ MobileNet model loaded successfully');
|
|
659
707
|
}
|
|
660
708
|
catch (error) {
|
|
@@ -889,15 +937,39 @@ const JaakStamps = class {
|
|
|
889
937
|
const transposedData = new Float32Array(R.concat(G, B));
|
|
890
938
|
return new window.ort.Tensor("float32", transposedData, [1, 3, this.INPUT_SIZE, this.INPUT_SIZE]);
|
|
891
939
|
}
|
|
940
|
+
getDeviceMemoryInfo() {
|
|
941
|
+
const nav = navigator;
|
|
942
|
+
const memory = nav.deviceMemory || nav.hardwareConcurrency || 4;
|
|
943
|
+
const connection = nav.connection || nav.mozConnection || nav.webkitConnection;
|
|
944
|
+
const isSlowConnection = connection && (connection.effectiveType === 'slow-2g' || connection.effectiveType === '2g');
|
|
945
|
+
return {
|
|
946
|
+
estimatedRAM: memory,
|
|
947
|
+
isLowMemory: memory <= 4,
|
|
948
|
+
isSlowConnection: isSlowConnection
|
|
949
|
+
};
|
|
950
|
+
}
|
|
892
951
|
getSessionOptions() {
|
|
952
|
+
const deviceInfo = this.getDeviceMemoryInfo();
|
|
953
|
+
if (deviceInfo.isLowMemory) {
|
|
954
|
+
return {
|
|
955
|
+
executionProviders: ['wasm'],
|
|
956
|
+
graphOptimizationLevel: 'basic',
|
|
957
|
+
logSeverityLevel: 4,
|
|
958
|
+
logVerbosityLevel: 0,
|
|
959
|
+
enableCpuMemArena: false,
|
|
960
|
+
enableMemPattern: false,
|
|
961
|
+
executionMode: 'sequential',
|
|
962
|
+
interOpNumThreads: 1,
|
|
963
|
+
intraOpNumThreads: 1,
|
|
964
|
+
};
|
|
965
|
+
}
|
|
893
966
|
return {
|
|
894
967
|
executionProviders: [
|
|
895
|
-
// Try WebGL first for GPU acceleration, fallback to WASM
|
|
896
968
|
'webgl',
|
|
897
969
|
'wasm'
|
|
898
970
|
],
|
|
899
|
-
graphOptimizationLevel: 'all',
|
|
900
|
-
logSeverityLevel: this.debug ? 2 : 4,
|
|
971
|
+
graphOptimizationLevel: 'all',
|
|
972
|
+
logSeverityLevel: this.debug ? 2 : 4,
|
|
901
973
|
logVerbosityLevel: 0,
|
|
902
974
|
enableCpuMemArena: true,
|
|
903
975
|
enableMemPattern: true,
|
|
@@ -922,7 +994,28 @@ const JaakStamps = class {
|
|
|
922
994
|
const modelPath = this.MODEL_PATH;
|
|
923
995
|
this.debugLog('🤖 Loading detection model:', modelPath);
|
|
924
996
|
const sessionOptions = this.getSessionOptions();
|
|
925
|
-
|
|
997
|
+
try {
|
|
998
|
+
this.session = await window.ort.InferenceSession.create(modelPath, sessionOptions);
|
|
999
|
+
}
|
|
1000
|
+
catch (error) {
|
|
1001
|
+
if (error.message.includes('failed to allocate a buffer')) {
|
|
1002
|
+
this.debugLog('❌ Buffer allocation failed, trying with minimal settings');
|
|
1003
|
+
const fallbackOptions = {
|
|
1004
|
+
executionProviders: ['wasm'],
|
|
1005
|
+
graphOptimizationLevel: 'disabled',
|
|
1006
|
+
logSeverityLevel: 4,
|
|
1007
|
+
enableCpuMemArena: false,
|
|
1008
|
+
enableMemPattern: false,
|
|
1009
|
+
executionMode: 'sequential',
|
|
1010
|
+
interOpNumThreads: 1,
|
|
1011
|
+
intraOpNumThreads: 1,
|
|
1012
|
+
};
|
|
1013
|
+
this.session = await window.ort.InferenceSession.create(modelPath, fallbackOptions);
|
|
1014
|
+
}
|
|
1015
|
+
else {
|
|
1016
|
+
throw error;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
926
1019
|
// Load MobileNet model if classification is enabled and not already loaded
|
|
927
1020
|
if (this.useDocumentClassification && !this.mobileNetSession) {
|
|
928
1021
|
if (this.debug) {
|
|
@@ -1442,7 +1535,7 @@ const JaakStamps = class {
|
|
|
1442
1535
|
this.cleanup();
|
|
1443
1536
|
}
|
|
1444
1537
|
render() {
|
|
1445
|
-
return (h("div", { key: '
|
|
1538
|
+
return (h("div", { key: 'bacf8b2ded1c5015d01dd4240dda6a93fbfb629e', class: "detector-container" }, h("div", { key: '235aefbd8916d6b53ab191c654ed00f303ca73b7', class: "video-container" }, h("video", { key: '9b641c7092c5ecfa601b1f80d6bf8c310539c436', ref: el => this.videoRef = el, autoplay: true, muted: true, playsinline: true, class: this.shouldMirrorVideo ? 'mirror' : '', style: { display: this.isVideoActive ? 'block' : 'none' } }), h("canvas", { key: '2c3c384436b7dd91084dbdd27a34ac9192fa3f22', ref: el => this.canvasRef = el, class: this.shouldMirrorVideo ? 'mirror' : '' }), this.isMaskReady && (h("div", { key: '9e2ca398482ebae4da984854483af3159d908d2b', class: "overlay-mask" }, h("div", { key: 'ee14fd65d752351644a281fc4cbd7d8cf8765eec', class: "card-outline" }, h("div", { key: 'c5a924145ac54e7f545b0b6571f1d7d259fc1145', class: "side side-top" }), h("div", { key: 'a88e9ab5f1a4f7041edb44008697b619bf52a85b', class: "side side-right" }), h("div", { key: '08fbf94000951ea31d029469d8158b8bd3349bf8', class: "side side-bottom" }), h("div", { key: '3b9ead8e1d2c0f7fea2878a248241681c07bd0f6', class: "side side-left" }), h("div", { key: 'f96b9a5a0f00f016b11486a63ca984b368d18c8b', class: "corner corner-tl" }), h("div", { key: '30210f2ec60913466665dea50a1e8bc6cba34b41', class: "corner corner-tr" }), h("div", { key: 'cc4644c99957a9ddf68901ddd368037e01c56899', class: "corner corner-bl" }), h("div", { key: '95b08e9b36f880dda1d614f929ceb71259f5ec38', class: "corner corner-br" }), !this.showFlipAnimation && !this.showSuccessAnimation && (h("div", { key: '9bb545a793764b258381b0e3d665472c67d65b5b', class: "guide-text" }, this.statusMessage))), this.captureStep === 'back' && !this.showFlipAnimation && !this.showSuccessAnimation && (h("button", { key: '3b78e394067ea610021fd915215fca30ed0d654b', class: "skip-button", onClick: () => this.skipBackCapture(), type: "button" }, "Saltar reverso")), this.isVideoActive && (h("div", { key: '85fbcf97d151fbf1f37a2f6f90bbd93ef77afdba', class: "camera-controls" }, this.isMultipleCamerasAvailable && (h("button", { key: '56bab78e6ea660e42057b5e6bc322f6990116119', class: "flip-camera-button", onClick: () => this.flipCamera(), type: "button", title: "Cambiar c\u00E1mara" }, "Girar c\u00E1mara")), h("button", { key: 'c149303ed671d326efada743393e52b5a3710710', class: "camera-selector-button", onClick: () => this.toggleCameraSelector(), type: "button", title: "Seleccionar c\u00E1mara" }, "C\u00E1maras"), this.debug && (h("div", { key: 'ce7c0c1dbc2ba267dbd0181dd7268e2d9f7209c0', style: {
|
|
1446
1539
|
position: 'absolute',
|
|
1447
1540
|
top: '50px',
|
|
1448
1541
|
right: '0',
|
|
@@ -1452,10 +1545,10 @@ const JaakStamps = class {
|
|
|
1452
1545
|
fontSize: '10px',
|
|
1453
1546
|
borderRadius: '4px',
|
|
1454
1547
|
whiteSpace: 'nowrap'
|
|
1455
|
-
} }, "C\u00E1maras: ", this.availableCameras.length, h("br", { key: '
|
|
1548
|
+
} }, "C\u00E1maras: ", this.availableCameras.length, h("br", { key: 'd62a6ddde7160f41075b3b1d00340515019a48ca' }), "M\u00FAltiples: ", this.isMultipleCamerasAvailable ? 'Sí' : 'No', h("br", { key: 'fe8c322421809a58f49150ef877ae0502d34d002' }), "Selector: ", this.showCameraSelector ? 'Visible' : 'Oculto', h("br", { key: '084d8c5c6c0193edcaf3bd7d64d0bce8e0bb6964' }), "Video: ", this.isVideoActive ? 'Activo' : 'Inactivo')))), this.showCameraSelector && this.availableCameras.length > 0 && (h("div", { key: '03b1a66188e65f1843c50aec096db840d60bb703', class: "camera-selector-dropdown" }, h("div", { key: 'fe7e08d25dd394d893a7f6269c80a2aaa4732134', class: "camera-selector-header" }, h("span", { key: '1b8f4892c3eef6dac8c682e152abb35e2331496c' }, "Seleccionar C\u00E1mara"), h("button", { key: '396c78a3753c707619e27ef7e5f3a412ba8480c6', class: "close-selector", onClick: () => this.toggleCameraSelector(), type: "button" }, "\u00D7")), h("div", { key: '6d56d67efe54719f21978cc6cc44cf2f421469bb', class: "camera-list" }, this.availableCameras.map((camera) => (h("button", { key: camera.deviceId, class: `camera-option ${this.selectedCameraId === camera.deviceId ? 'selected' : ''}`, onClick: () => {
|
|
1456
1549
|
this.switchCamera(camera.deviceId);
|
|
1457
1550
|
this.toggleCameraSelector();
|
|
1458
|
-
}, type: "button" }, h("span", { class: "camera-label" }, camera.label || `Cámara ${this.availableCameras.indexOf(camera) + 1}`), this.selectedCameraId === camera.deviceId && (h("span", { class: "selected-indicator" }, "\u2713")))))), h("div", { key: '
|
|
1551
|
+
}, type: "button" }, h("span", { class: "camera-label" }, camera.label || `Cámara ${this.availableCameras.indexOf(camera) + 1}`), this.selectedCameraId === camera.deviceId && (h("span", { class: "selected-indicator" }, "\u2713")))))), h("div", { key: '7f5dda6214695d50c08d2ba4ccec236f3bd158cf', class: "device-info" }, h("small", { key: '50d2768f82b9b7f0a9c1729a5167493f731fb4f6' }, "Dispositivo: ", this.deviceType)))))), this.isCapturing && (h("div", { key: '7ed246b862639b2c6df54dbd32ebb883776bfbd7', class: "capture-animation" })), this.showFlipAnimation && (h("div", { key: 'f2d3a97dfcb9fd757b2f39ec184bce3f5dcb3595', class: "flip-animation" }, h("div", { key: '89a98223c60317d2b9449029ba393c75bec154b3', class: "id-card-icon" }), h("div", { key: '507f6f1b7f38082772bbac2fc28046618161c69b', class: "flip-text" }, "\u00A1Voltea tu identificaci\u00F3n!"))), this.showSuccessAnimation && (h("div", { key: '9010d5be6684759b5d99c58ee65b0a7ebe82b9cb', class: "success-animation" }, h("div", { key: '454c39a5c0d457418b8abdc6e63b1c8a249a118f', class: "check-icon" }), h("div", { key: '502e55f1496f7d8cde9178c416bd9db4cf0491eb', class: "success-text" }, "\u00A1Proceso completado!"))), this.isLoading && (h("div", { key: 'e4d6b7c5ebc8da42689150195dd837e77e152ea3', class: "loading-overlay" }, h("div", { key: '7cc39dbbe94e0730c47829291b83717476517f7f', class: "loading-spinner" }), h("div", { key: '4c1afe04fc7a627c9a57c2f7b851ce62f9305676', class: "loading-text" }, this.statusMessage))), this.debug && (h("div", { key: '8745c4603b35003bff859657c86c713b7f58e204', class: "status-bar" }, h("div", { key: 'e098f2402d58d1808052e3d213f851e66db69ee4', class: "status-message", style: { 'color': this.statusColor } }, this.statusMessage))), h("div", { key: 'af4e07b405af5b1786009b0e9ecf72551753de28', class: "watermark" }, h("img", { key: '25f4b80f13528617007aad160c855c4fff0c8af5', src: "https://storage.googleapis.com/jaak-static/commons/powered-by-jaak.png", alt: "Powered by Jaak" })))));
|
|
1459
1552
|
}
|
|
1460
1553
|
};
|
|
1461
1554
|
JaakStamps.style = myComponentCss;
|