UNPKG

@scandit/web-datacapture-barcode

Version:

Scandit Data Capture SDK for the Web

1 lines 3.45 kB
import{BarcodeFindFeedback as e}from"./BarcodeFindFeedback.js";import{Camera as t,FrameSourceState as n,TorchState as r,isCameraFrameSource as i}from"@scandit/web-datacapture-core";let a=function(e){return e.Started=`started`,e.Paused=`paused`,e.Stopped=`stopped`,e}({});var o=class{constructor(t,n,i,a,o){this.viewState=`paused`,this.barcodeFindViewUiListener=null,this.torchState=r.Off,this.sessionState=null,this.barcodeFindView=t,this.barcodeFind=i,this.context=n,this.viewSettings=a,this.cameraSettings=o,i.feedback=e.createWithOptions(this.viewSettings.soundEnabled,this.viewSettings.hapticEnabled)}async prepare(){await this.barcodeFind.setEnabled(!1),this.barcodeFind.addPrivateListener(this);let e=await t.getAll(!1,i(this.context.frameSource)),n=i(this.context.frameSource)?this.context.frameSource:e[0]??t.pickBestGuess();await this.context.setFrameSource(n),await this.context.frameSource.applySettings(this.cameraSettings),this.isTorchAvailable=await n.isTorchAvailable(),this.barcodeFindView.setTorchAvailable(this.isTorchAvailable)}async dispose(){await this.context.removeMode(this.barcodeFind),this.barcodeFind.removePrivateListener(this)}async didPauseSearch(e){this.barcodeFindView.switchToPaused(Object.values(this.customerItemsListState),e)}async didStartSearch(){this.barcodeFindView.switchToStarted()}async didStopSearch(e){var t;(t=this.barcodeFindViewUiListener)==null||t.didTapFinishButton(e)}async onSetItemList(e){this.customerItemsListState=e.reduce((e,t)=>(e[t.searchOptions.barcodeData]=t,e),{}),this.barcodeFind.feedback.itemListUpdated.emit(),this.barcodeFindView.updateProgressBar(0,Object.values(this.customerItemsListState).length)}onDidUpdateSession(e,t,n){this.sessionState=t,this.barcodeFindView.updateProgressBar(this.sessionState.allFoundItems.length),this.barcodeFindView.renderDots(this.sessionState,this.customerItemsListState)}async onShutterButtonClicked(){this.viewState===`paused`||this.viewState===`stopped`?await this.startSearching():await this.pauseSearching()}async onTorchButtonClicked(){this.isTorchAvailable&&(await this.context.frameSource.setDesiredTorchState(this.torchState===r.Off?r.On:r.Off),this.torchState=this.torchState===r.Off?r.On:r.Off,this.barcodeFindView.toggleTorchIcon(this.torchState))}onDotClick(e){var t;let n=(t=this.sessionState)==null?void 0:t.trackedBarcodes[e];if(n!=null){let e=this.customerItemsListState[n.barcode.data??``];this.barcodeFindView.moveCardOnTheFront(e)}}onFinishButtonClicked(){this.stopSearching()}onFindListUpdatedFeedback(){this.barcodeFind.feedback.itemListUpdated.emit()}onFeedback(){this.barcodeFind.feedback.found.emit(),this.barcodeFindView.setShutterButtonPulse(!0)}async pauseSearching(){var e;this.viewState=`paused`,await((e=this.context.frameSource)==null?void 0:e.switchToDesiredState(n.Standby)),await this.barcodeFind.setEnabled(!1),await this.barcodeFind.pause(),this.barcodeFindView.setShutterButtonPulse(!1)}async startSearching(){var e;this.viewState=`started`,await((e=this.context.frameSource)==null?void 0:e.switchToDesiredState(n.On)),await this.barcodeFind.setEnabled(!0),await this.barcodeFind.start()}async stopSearching(){var e;this.viewState=`stopped`,await this.barcodeFind.setEnabled(!1),await((e=this.context.frameSource)==null?void 0:e.switchToDesiredState(n.Off)),await this.barcodeFind.stop(),this.barcodeFindView.setShutterButtonPulse(!1),this.sessionState=null}};export{o as BarcodeFindPresenter,a as ViewState};