scandoc-ai-components 0.0.55 → 0.0.57

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.
Files changed (2) hide show
  1. package/dist/index.js +4 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11169,8 +11169,8 @@ const fullImage=(0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video,c
11169
11169
  if("DetectedBlurValue"in response){this.pastBlurValues.push(response["DetectedBlurValue"]);}else{this.pastBlurValues=[];}//
11170
11170
  if(response["InfoCode"]==="1007"){const imageId=response["Index"];const imageSide=response["Side"];//
11171
11171
  if(this.extractionImages[imageSide]===undefined){this.extractionImages[imageSide]=images[imageId]["fullImg"];}const extractionImages={...this.extractionImages};//
11172
- if(Object.keys(extractionImages).length===1){this.scanStartTime=Date.now();this.showMessage("Turn to the other side");}if(Object.keys(extractionImages).length===2){this.showMessage("Validation successful");const[isExtractionOk,extractionData]=await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(extractionImages["FRONT"],extractionImages["BACK"],{IgnoreBackImage:false});this.onExtraction(isExtractionOk,extractionData);return;}}else if(response["InfoCode"]==="1000"){this.showMessage("Validation successful");this.showMessage("Extracting data");const imageId=response["Index"];const image=images[imageId]["fullImg"];const[isExtractionOk,extractionData]=await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(image,undefined,{IgnoreBackImage:true});this.onExtraction(isExtractionOk,extractionData);return;}}this.candidateImages=[];}}}).finally(()=>{setTimeout(()=>this.analyzeVideoStream(),ExtractorVideo.FREQUENCY_MS);});}onExtraction(isExtractionOk,extractionData){this.candidateImages=[];this.extractionImages={};this.stopVideo();if(isExtractionOk){this.showMessage("Success - data extracted","success");const shouldStop=this.onExtractedResults({success:true,code:"001",info:"Document extracted successfully.",data:extractionData});if(shouldStop===true){setTimeout(()=>this.analyzeVideoStream(),ExtractorVideo.FREQUENCY_MS);}}else{this.onExtractedResults({success:false,code:"005",info:"Document validation passed but extraction failed."});setTimeout(()=>this.analyzeVideoStream(),ExtractorVideo.FREQUENCY_MS);}}async startVideo(){try{const serviceConfig=(0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();await serviceConfig.getAccessToken(true);// this will throw if 401
11173
- const videoElem=document.getElementById("ScanDocAIVideoElement");if(!videoElem){throw new Error("Video element not found.");}this.video=videoElem;this.isRunning=true;this.scanStartTime=Date.now();const devices=await navigator.mediaDevices.enumerateDevices();const environmentCameras=devices.filter(device=>device.kind==="videoinput"&&device.label.toLowerCase().includes("back"));const cameras=await checkAutofocusSupport(environmentCameras);let deviceId;if(cameras.length>0){deviceId=cameras[0].deviceId;}const userMediaConstraints={...ExtractorVideo.VIDEO_SETTINGS};if(deviceId){userMediaConstraints.deviceId=deviceId;}const stream=await navigator.mediaDevices.getUserMedia({video:userMediaConstraints});this.video.srcObject=stream;await this.video.play().catch(e=>{console.warn(`Error on video play: ${e}`);});this.scanStartTime=Date.now();// Reset timer
11172
+ if(Object.keys(extractionImages).length===1){this.scanStartTime=Date.now();this.showMessage("Turn to the other side");}if(Object.keys(extractionImages).length===2){this.showMessage("Validation successful");const[isExtractionOk,extractionData]=await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(extractionImages["FRONT"],extractionImages["BACK"],{IgnoreBackImage:false});this.onExtraction(isExtractionOk,extractionData);return;}}else if(response["InfoCode"]==="1000"){this.showMessage("Validation successful");this.showMessage("Extracting data");const imageId=response["Index"];const image=images[imageId]["fullImg"];const[isExtractionOk,extractionData]=await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(image,undefined,{IgnoreBackImage:true});this.onExtraction(isExtractionOk,extractionData);return;}}this.candidateImages=[];}}}).finally(()=>{setTimeout(()=>this.analyzeVideoStream(),ExtractorVideo.FREQUENCY_MS);});}onExtraction(isExtractionOk,extractionData){this.candidateImages=[];this.extractionImages={};this.stopVideo();if(isExtractionOk){this.showMessage("Success - data extracted","success");const shouldStop=this.onExtractedResults({success:true,code:"001",info:"Document extracted successfully.",data:extractionData});if(shouldStop===true){setTimeout(()=>this.analyzeVideoStream(),ExtractorVideo.FREQUENCY_MS);}}else{this.onExtractedResults({success:false,code:"005",info:"Document validation passed but extraction failed."});setTimeout(()=>this.analyzeVideoStream(),ExtractorVideo.FREQUENCY_MS);}}async getCameraMargins(){const video=document.getElementById('ScanDocAIVideoElement');const canvas=document.createElement('canvas');const ctx=canvas.getContext('2d');canvas.width=video.videoWidth;canvas.height=video.videoHeight;ctx.drawImage(video,0,0,canvas.width,canvas.height);const imageData=ctx.getImageData(0,0,canvas.width,canvas.height).data;const isColumnBlack=x=>{const threshold=16;for(let y=0;y<canvas.height;y++){const i=(y*canvas.width+x)*4;const[r,g,b]=[imageData[i],imageData[i+1],imageData[i+2]];if(r>threshold||g>threshold||b>threshold)return false;}return true;};const isRowBlack=y=>{const threshold=16;for(let x=0;x<canvas.width;x++){const i=(y*canvas.width+x)*4;const[r,g,b]=[imageData[i],imageData[i+1],imageData[i+2]];if(r>threshold||g>threshold||b>threshold)return false;}return true;};let left=0,right=0,top=0,bottom=0;while(left<canvas.width&&isColumnBlack(left))left++;while(right<canvas.width&&isColumnBlack(canvas.width-1-right))right++;while(top<canvas.height&&isRowBlack(top))top++;while(bottom<canvas.height&&isRowBlack(canvas.height-1-bottom))bottom++;return{leftPct:left/canvas.width,rightPct:right/canvas.width,topPct:top/canvas.height,bottomPct:bottom/canvas.height};}async startVideo(){try{const serviceConfig=(0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();await serviceConfig.getAccessToken(true);// this will throw if 401
11173
+ const videoElem=document.getElementById("ScanDocAIVideoElement");if(!videoElem){throw new Error("Video element not found.");}this.video=videoElem;this.isRunning=true;this.scanStartTime=Date.now();const devices=await navigator.mediaDevices.enumerateDevices();const environmentCameras=devices.filter(device=>device.kind==="videoinput"&&device.label.toLowerCase().includes("back"));const cameras=await checkAutofocusSupport(environmentCameras);let deviceId;if(cameras.length>0){deviceId=cameras[0].deviceId;}const userMediaConstraints={...ExtractorVideo.VIDEO_SETTINGS};if(deviceId){userMediaConstraints.deviceId=deviceId;}const stream=await navigator.mediaDevices.getUserMedia({video:userMediaConstraints});this.video.srcObject=stream;await this.video.play().catch(e=>{console.warn(`Error on video play: ${e}`);});setTimeout(async()=>{const margins=await this.getCameraMargins();console.log("Margins:",margins);const rectangle=document.querySelector('.desktopRectangle');if(rectangle){const clamp=(pct,max=0.2)=>Math.min(pct,max)*100;rectangle.style.top=`${clamp(margins.topPct)}%`;rectangle.style.bottom=`${clamp(margins.bottomPct)}%`;rectangle.style.left=`${clamp(margins.leftPct)}%`;rectangle.style.right=`${clamp(margins.rightPct)}%`;}},500);this.scanStartTime=Date.now();// Reset timer
11174
11174
  setTimeout(()=>this.analyzeVideoStream(),ExtractorVideo.FREQUENCY_MS);this.showMessage("Starting scanning");return true;}catch(error){console.error("startVideo failed:",error);this.isRunning=false;this.stopVideo();this.onExtractedResults({success:false,code:error.status===401||error.status===403?"004":"005",info:error.status===401||error.status===403?"Authentication failed: Invalid API key.":"Startup failed: "+(error.message||"Unknown error")});return false;}}stopVideo(){this.isRunning=false;if(this.video){this.video.pause();if(this.video.srcObject!==undefined&&this.video.srcObject!==null){this.video.srcObject.getTracks().forEach(t=>t.stop());}this.video.srcObject=null;}}showMessage(message){const messageElement=document.getElementById("ScanDocAIMessage");if(messageElement){messageElement.innerText=message;}}getHTML(){return`
11175
11175
  <div class="desktopFeedback" id="ScanDocAIMessage"></div>
11176
11176
  <div class="desktopVideoArea">
@@ -11215,14 +11215,12 @@ setTimeout(()=>this.analyzeVideoStream(),ExtractorVideo.FREQUENCY_MS);this.showM
11215
11215
 
11216
11216
  .desktopRectangle {
11217
11217
  position: absolute;
11218
- top: 32px;
11219
- right: 32px;
11220
- bottom: 32px;
11221
- left: 28px;
11222
11218
  border-radius: 30px;
11223
11219
  display: flex;
11224
11220
  justify-content: center;
11225
11221
  align-items: center;
11222
+ transition: all 0.3s ease;
11223
+ background-color: rgba(80, 120, 187, 0.1);
11226
11224
  }
11227
11225
 
11228
11226
  .dashedRectangle {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "scandoc-ai-components",
3
3
  "author": "ScanDoc-AI",
4
- "version": "0.0.55",
4
+ "version": "0.0.57",
5
5
  "private": false,
6
6
  "description": "Pure JavaScript package for integrating ScanDoc-AI services.",
7
7
  "keywords": [