@scandit/web-datacapture-barcode
Version:
Scandit Data Capture SDK for the Web
1 lines • 3.63 kB
JavaScript
import {a as a$2,b}from'./chunk-HTKUJZG2.js';import {a}from'./chunk-M4AENTE5.js';import {a as a$3}from'./chunk-55SHUUX6.js';import {a as a$1}from'./chunk-DHKABHFE.js';import {CameraSettings,convertToPublicFrameData}from'@scandit/web-datacapture-core';import {warnMultithreadingUnavailable}from'@scandit/web-datacapture-core/build/js/private/utils/warnMultithreadingUnavailable.js';var l=class u{constructor(){this.feedback=a.createDefaultFeedback();this.skipSerialization=true;this.type="barcodeFind";this._isEnabled=true;this._context=null;this.listeners=new Set;this.privateListeners=new Set;this.workerMessageListener=this.onWorkerMessage.bind(this);this._transformer=null;}static get recommendedCameraSettings(){return new CameraSettings(a$1.CameraSettings.settings)}get context(){return this._context}get allListeners(){return [...this.privateListeners,...this.listeners]}static async forSettings(e){warnMultithreadingUnavailable();let a=new u;return a.settings=e,a}isEnabled(){return this._isEnabled}async setEnabled(e){var a;this._isEnabled=e,await this.workerCommand("barcodeFindSetEnabled",{enabled:e}),await((a=this.context)==null?void 0:a.update([{type:"modeEnabled",newValue:e}],{updateContext:false}));}async applySettings(e){this.settings=e,await this.workerCommand("barcodeFindApplySettings",{settings:e.toJSONObject()});}addListener(e){this.listeners.add(e);}removeListener(e){this.listeners.delete(e);}async setItemList(e){var a;for(let r of this.privateListeners)(a=r.onSetItemList)==null||a.call(r,e);return this.workerCommand("barcodeFindSetItemList",{itemList:e.map(r=>r.toJSONObject())})}async setBarcodeTransformer(e){var a;return this._transformer=e,this.workerCommand("barcodeFindSetTransformerFunction",{functionAsString:(a=this._transformer)==null?void 0:a.transformBarcodeData.toString()})}async start(){return this.workerCommand("barcodeFindSearchStart",{})}async stop(){return this.workerCommand("barcodeFindSearchStop",{})}async pause(){return this.workerCommand("barcodeFindSearchPause",{})}toJSONObject(){return {type:this.type,enabled:this.isEnabled(),settings:this.settings.toJSONObject()}}async workerCommand(e,a){this.context!=null&&await this.context.workerCommand(e,a);}async attachedToContext(e){this._context=e,this._context.subscribeToWorkerMessages(this.workerMessageListener),await this.workerCommand("barcodeFindForSettings",{settings:this.settings.toJSONObject()});}async detachedFromContext(){var e;await this.workerCommand("barcodeFindModeRemove",{}),(e=this._context)==null||e.unsubscribeToWorkerMessages(this.workerMessageListener),this._context=null;}async onWorkerMessage(e){var a,r,d;switch(e.type){case "barcodeFindDidUpdateSession":{if(this._context==null)return;for(let t of this.allListeners)(a=t.onDidUpdateSession)==null||a.call(t,this,a$3.fromJSON(e.payload.session),convertToPublicFrameData(e.payload.frameData,this._context));break}case "barcodeFindSearchPaused":{for(let t of this.allListeners){let i=e.payload.foundItems.map(o=>new a$2(new b(o),null));t.didPauseSearch(i);}break}case "barcodeFindSearchStarted":{for(let t of this.allListeners)t.didStartSearch();break}case "barcodeFindSearchStopped":{for(let t of this.allListeners){let i=e.payload.foundItems.map(o=>new a$2(new b(o),null));t.didStopSearch(i);}break}case "barcodeFindListUpdatedFeedback":{for(let t of this.allListeners)(r=t.onFindListUpdatedFeedback)==null||r.call(t);break}case "barcodeFindFeedback":{for(let t of this.allListeners)(d=t.onFeedback)==null||d.call(t);break}}}addPrivateListener(e){this.privateListeners.add(e);}removePrivateListener(e){this.privateListeners.delete(e);}};export{l as a};