UNPKG

@scandit/web-datacapture-barcode

Version:

Scandit Data Capture SDK for the Web

1 lines 3.46 kB
import {a as a$1}from'./chunk-KEN6J62X.js';import {a}from'./chunk-HDODW33D.js';import {a as a$2}from'./chunk-74KP5NGF.js';import {CameraSettings,convertToPublicFrameData,Logger,DataCaptureContext}from'@scandit/web-datacapture-core';var c=class p{constructor(){this.type="sparkScan";this._synchronousFrameFlow=false;this._isEnabled=true;this._isSuppressed=null;this._context=null;this.listeners=new Set;this.allowedRemainingWorkerMessages=new Set;this.workerMessageListener=this.onWorkerMessage.bind(this);}static get recommendedCameraSettings(){return CameraSettings.fromJSON(a.CameraSettings.settings)}get context(){return this._context}static forSettings(e){let a=new p;return a.settings=e,a}isEnabled(){return this._isEnabled}async setEnabled(e){this._isSuppressed=null,this._isEnabled=e,await this.notifyContext();}isSuppressed(){return this._isSuppressed===true}async setResultSuppressionEnabled(e){this._isSuppressed=e,await this.notifyContext();}async applySettings(e){return this.settings=e,this.notifyContext()}addListener(e){this.listeners.add(e);}removeListener(e){this.listeners.delete(e);}toJSONObject(){let e={type:this.type,enabled:this._isEnabled,settings:this.settings.toJSONObject()};return this._isSuppressed!==null&&(e.isSuppressed=this._isSuppressed),e}async selectItemWithSmartScanSelection(){await this.workerCommand("sparkScanSelectItemWithSmartScanSelection",{});}setDelegate(e){this.delegate=e;}async workerCommand(e,a){this.context&&await this.context.workerCommand(e,a);}attachedToContext(e){this._context=e,this._context.subscribeToWorkerMessages(this.workerMessageListener);}async detachedFromContext(){var e;await this.workerCommand("sparkScanModeRemove",{}),(e=this._context)==null||e.unsubscribeToWorkerMessages(this.workerMessageListener),this._context=null;}sendClearFrameDataRequest(e){queueMicrotask(()=>{var a;(a=this.context)==null||a.workerCommand("deleteFrameData",{frameId:e});});}async onDidScan(e){if(this.context==null)return;let{frameData:a}=e.payload;if(this._isSuppressed){this.sendClearFrameDataRequest(a.frameId),this.allowedRemainingWorkerMessages.clear();return}if(!this._isEnabled){this.sendClearFrameDataRequest(a.frameId),this.allowedRemainingWorkerMessages.clear();return}this.allowedRemainingWorkerMessages.add("successFeedback");let t=[],s=a$1.fromJSON(e.payload.session);for(let r of this.listeners)if(r.didScan)try{let i=r.didScan(this,s,convertToPublicFrameData(a,this.context));i instanceof Promise&&await i;}catch(i){t.push(i);}this.sendClearFrameDataRequest(a.frameId),this.allowedRemainingWorkerMessages.add("sparkScanDidUpdateSession");for(let r of t)Logger.error(r);}onDidUpdateSession(e){var t;if(!this._isEnabled&&!this.allowedRemainingWorkerMessages.has(e.type))return;this.allowedRemainingWorkerMessages.delete(e.type);let a=a$1.fromJSON(e.payload);for(let s of this.listeners)(t=s.didUpdateSession)==null||t.call(s,this,a);}async onWorkerMessage(e){var a,t;switch(e.type){case "sparkScanDidScan":{await this.onDidScan(e);break}case "sparkScanDidUpdateSession":{this.onDidUpdateSession(e);break}case "sparkScanSwitchedToSmartScanSelection":{(a=this.delegate)==null||a.onSwitchedToSmartScanSelection();break}case "sparkScanSwitchedAwayFromSmartScanSelection":{(t=this.delegate)==null||t.onSwitchedAwayFromSmartScanSelection();break}}}async notifyContext(){this.context&&(this.settings=a$2(this.settings,DataCaptureContext.capabilityInfo),await this.context.update());}};export{c as a};