UNPKG

@scandit/web-datacapture-barcode

Version:

Scandit Data Capture SDK for the Web

1 lines 4.05 kB
import {a}from'./chunk-KHHN2PZL.js';import {TorchState,isCameraFrameSource,Camera,CameraPosition,FrameSourceState}from'@scandit/web-datacapture-core';var l=class{constructor(e,t,a,o,r){this.torchState=TorchState.Off;this.cameraSupportMap=new Map;this.zoomFactor=1;this.cameras=[];this.view=e,this.context=t,this.barcodeAr=a,this.viewSettings=o,this.cameraSettings=r;}get currentCamera(){if(isCameraFrameSource(this.context.frameSource))return this.context.frameSource;throw new Error("The current frame source is not a Camera")}isCameraMirrored(){return this.currentCamera.getMirrorImageEnabled()}async prepare(){var a$1,o,r;await this.barcodeAr.setEnabled(false),this.barcodeAr.feedback=await a.createWithOptions(true,true),this.barcodeAr.addPrivateListener(this),this.cameras=await Camera.getAll(false,isCameraFrameSource(this.context.frameSource));let e=isCameraFrameSource(this.context.frameSource)?this.context.frameSource:(r=(o=(a$1=this.cameras.find(s=>s.position===this.viewSettings.defaultCameraPosition))!=null?a$1:this.cameras.find(s=>s.position===(this.viewSettings.defaultCameraPosition===CameraPosition.WorldFacing?CameraPosition.UserFacing:CameraPosition.WorldFacing)))!=null?o:this.cameras[0])!=null?r:Camera.pickBestGuess();await this.context.setFrameSource(e),await this.currentCamera.applySettings(this.cameraSettings),await this.currentCamera.switchToDesiredState(FrameSourceState.Standby),this.zoomFactor=this.currentCamera.settings.zoomFactor,this.view.changeZoomButtonIcon(this.zoomFactor);let t=await this.isTorchAvailableForCurrentCamera();this.view.setTorchAvailable(t);}async dispose(){var e;this.view.deleteAllViews(),await this.context.removeMode(this.barcodeAr),this.barcodeAr.removePrivateListener(this),await((e=this.context.frameSource)==null?void 0:e.switchToDesiredState(FrameSourceState.Off));}async startSearching(){var e;this.view.deleteAllViews(),await((e=this.context.frameSource)==null?void 0:e.switchToDesiredState(FrameSourceState.On)),await this.barcodeAr.setEnabled(true),await this.barcodeAr.start();}async stopSearching(){var e;this.view.deleteAllViews(),await((e=this.context.frameSource)==null?void 0:e.switchToDesiredState(FrameSourceState.Off)),await this.barcodeAr.setEnabled(false),await this.barcodeAr.stop();}async pauseSearching(){var e;this.view.deletePendingViews(),await((e=this.context.frameSource)==null?void 0:e.switchToDesiredState(FrameSourceState.Standby)),await this.barcodeAr.setEnabled(false),await this.barcodeAr.pause();}emitTappedFeedback(){this.barcodeAr.feedback.tapped.emit();}didUpdateSession(e,t){Object.keys(t.addedTrackedBarcodes).length>0&&this.barcodeAr.feedback.scanned.emit(),this.view.render(t);}async isTorchAvailableForCurrentCamera(){let e=this.currentCamera.label,t=this.cameraSupportMap.get(e);if(t!==void 0)return t.torch;let a=await this.currentCamera.isTorchAvailable();return this.cameraSupportMap.set(e,{torch:a}),a}async onTorchButtonClicked(){let e=await this.isTorchAvailableForCurrentCamera();this.view.setTorchAvailable(e),e&&(await this.currentCamera.setDesiredTorchState(this.torchState===TorchState.Off?TorchState.On:TorchState.Off),this.torchState=this.torchState===TorchState.Off?TorchState.On:TorchState.Off,this.view.toggleTorchIcon(this.torchState));}async onZoomButtonClicked(){var t;if(!this.currentCamera.isZoomAvailable())return;let e=(t={1:2,2:1}[this.zoomFactor])!=null?t:1;this.currentCamera.settings.zoomFactor=e,await this.currentCamera.applySettings(this.currentCamera.settings),this.zoomFactor=e,this.view.changeZoomButtonIcon(e);}async onCameraSwitchButtonClicked(){var r,s;let e=this.currentCamera.getCurrentState(),t=this.currentCamera.position===CameraPosition.UserFacing?CameraPosition.WorldFacing:CameraPosition.UserFacing,a=(s=(r=this.cameras.find(u=>u.position===t))!=null?r:this.cameras[0])!=null?s:Camera.pickBestGuessForPosition(t);await this.context.setFrameSource(a),await this.currentCamera.switchToDesiredState(e);let o=await this.isTorchAvailableForCurrentCamera();this.view.setTorchAvailable(o);}};export{l as a};