@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.
@@ -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
- this.session = await window.ort.InferenceSession.create(modelPath, sessionOptions);
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
- this.mobileNetSession = await window.ort.InferenceSession.create(this.MOBILENET_MODEL_PATH, sessionOptions);
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', // Maximum optimization
900
- logSeverityLevel: this.debug ? 2 : 4, // Reduce logging overhead in production
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
- this.session = await window.ort.InferenceSession.create(modelPath, sessionOptions);
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: '86ff6966e69804bea4faef5a9201480bd7ef5b9a', class: "detector-container" }, h("div", { key: 'aaed4a078d4eff98674f2163a56a1596782612bd', class: "video-container" }, h("video", { key: '6ae6a7c626c9b2b6e6915c826517d1365205b3a0', ref: el => this.videoRef = el, autoplay: true, muted: true, playsinline: true, class: this.shouldMirrorVideo ? 'mirror' : '', style: { display: this.isVideoActive ? 'block' : 'none' } }), h("canvas", { key: 'c8666e4b4814e633155be738e23ada098fb3be93', ref: el => this.canvasRef = el, class: this.shouldMirrorVideo ? 'mirror' : '' }), this.isMaskReady && (h("div", { key: '968bcd21315afcf054f881647723299e7e57c29b', class: "overlay-mask" }, h("div", { key: '77f8a331f3d9e19b35c11b6c23b06420cbab9fd5', class: "card-outline" }, h("div", { key: '9d0164e7b2dcf6392471151c236127cd57507512', class: "side side-top" }), h("div", { key: '05a003eb49d25c72644aea2511b6519c5241ffb4', class: "side side-right" }), h("div", { key: 'a561ae9a94eb78aacfc24bac717164b3e22f41e5', class: "side side-bottom" }), h("div", { key: '81d64e5b58032c14062fc8efdee417db7f8a9f12', class: "side side-left" }), h("div", { key: '03c02e2c4c73c525965e34c7c47bb74f769d577f', class: "corner corner-tl" }), h("div", { key: '84780aec021ec4e0c7d38f6a659be765c4604ed5', class: "corner corner-tr" }), h("div", { key: '1ea67789c5a38cbc790f911f8f06b55c866d3927', class: "corner corner-bl" }), h("div", { key: 'e0e1999b0c5c37451850203eed4dbc2ff5834261', class: "corner corner-br" }), !this.showFlipAnimation && !this.showSuccessAnimation && (h("div", { key: '4909eb28d62b1674436c148ef46cd05a35ff8ec8', class: "guide-text" }, this.statusMessage))), this.captureStep === 'back' && !this.showFlipAnimation && !this.showSuccessAnimation && (h("button", { key: '5a971c2121cf9962719ad89fc45530b8acccb550', class: "skip-button", onClick: () => this.skipBackCapture(), type: "button" }, "Saltar reverso")), this.isVideoActive && (h("div", { key: '109e5885c49212f89d5678d9c9716ebd48614126', class: "camera-controls" }, this.isMultipleCamerasAvailable && (h("button", { key: '7c8ce2cd775c0646c80378cd0ad1f70243443ddf', class: "flip-camera-button", onClick: () => this.flipCamera(), type: "button", title: "Cambiar c\u00E1mara" }, "Girar c\u00E1mara")), h("button", { key: '5d3d066ba7e317fdc33878eeb9f2f7d28c6f65dc', class: "camera-selector-button", onClick: () => this.toggleCameraSelector(), type: "button", title: "Seleccionar c\u00E1mara" }, "C\u00E1maras"), this.debug && (h("div", { key: '4cbc284f2efbcb90ef91ea2e064bf0aa1e7980af', style: {
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: 'df214515289add2cc73f989bfacb59069334a0e6' }), "M\u00FAltiples: ", this.isMultipleCamerasAvailable ? 'Sí' : 'No', h("br", { key: 'aa2b1784781b5b45d24139e2b6cc4865d9f3a00c' }), "Selector: ", this.showCameraSelector ? 'Visible' : 'Oculto', h("br", { key: 'fb95b2b58c9fb89f632d85a9271b7788d45a66c0' }), "Video: ", this.isVideoActive ? 'Activo' : 'Inactivo')))), this.showCameraSelector && this.availableCameras.length > 0 && (h("div", { key: 'ec1c90c5a6c84e3ef75724e7e600a60714545608', class: "camera-selector-dropdown" }, h("div", { key: 'ea118817b6563c78b7fbf5ee66af2e38a441a8b7', class: "camera-selector-header" }, h("span", { key: '52603259d50ffb7aa6ea5753762f0f0d018b39ff' }, "Seleccionar C\u00E1mara"), h("button", { key: '422ae0643f5d1451cf539b3a77becbf44904a484', class: "close-selector", onClick: () => this.toggleCameraSelector(), type: "button" }, "\u00D7")), h("div", { key: 'd5acef7ba0b1645c52fb3ea7b3c64e70fa187a5f', class: "camera-list" }, this.availableCameras.map((camera) => (h("button", { key: camera.deviceId, class: `camera-option ${this.selectedCameraId === camera.deviceId ? 'selected' : ''}`, onClick: () => {
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: 'b670e7bf441559bf156874dbe3bbf83dbff2fa0d', class: "device-info" }, h("small", { key: '4d333925c1ff4197b6009414ed694b0a0eb06159' }, "Dispositivo: ", this.deviceType)))))), this.isCapturing && (h("div", { key: '21f7ea0e50575226daba8607ab4bccc5029aa179', class: "capture-animation" })), this.showFlipAnimation && (h("div", { key: 'c2350cc43d3a119391f62f2cf771ed5afcdb3558', class: "flip-animation" }, h("div", { key: 'a91de9e8662a4750555bce2a879b89f9216b8156', class: "id-card-icon" }), h("div", { key: 'def1c2534e1aae27e262deb6fd26a73ff0c8cb9b', class: "flip-text" }, "\u00A1Voltea tu identificaci\u00F3n!"))), this.showSuccessAnimation && (h("div", { key: 'acbbfb6d07e4f6bf343ff18af2d55979e76db3d4', class: "success-animation" }, h("div", { key: 'f5acd84325226e6b1ede1180335d7495a6b2d95e', class: "check-icon" }), h("div", { key: '393fd8300ce48e59bd3ef94f0e895abc3a938c1f', class: "success-text" }, "\u00A1Proceso completado!"))), this.isLoading && (h("div", { key: 'ce0d1baebab8bf0e18531a26b549f38e349a0d72', class: "loading-overlay" }, h("div", { key: '14c76fa00ddd814f37bd9c6dc57f761119886566', class: "loading-spinner" }), h("div", { key: '87ccb288f927e61ec126d83f44061699810c9e06', class: "loading-text" }, this.statusMessage))), this.debug && (h("div", { key: '943dff6e2772f2595a95116e8943866f97cada6e', class: "status-bar" }, h("div", { key: '00fe53b71ef94d51636259f106e4518df910848d', class: "status-message", style: { 'color': this.statusColor } }, this.statusMessage))), h("div", { key: '4c3bd150006473d9540fb1418f11f45fb96d1e56', class: "watermark" }, h("img", { key: 'c634701f52a4422c7be5b4007bf34ba4aeb4ebcc', src: "https://storage.googleapis.com/jaak-static/commons/powered-by-jaak.png", alt: "Powered by Jaak" })))));
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;