UNPKG

@scandit/web-datacapture-barcode

Version:

Scandit Data Capture SDK for the Web

10 lines (7 loc) 3.51 kB
import { a as a$2 } from './chunk-W7TZ36EI.js'; import { a as a$1, b as b$1 } from './chunk-HTKUJZG2.js'; import { a } from './chunk-IILNTCMF.js'; import { b } from './chunk-XCZGCZ5K.js'; import { CameraSettings, convertToPublicFrameData } from '@scandit/web-datacapture-core'; var l=class b$2{constructor(){this.feedback=a.createDefaultFeedback();this.skipSerialization=!0;this.type="barcodeFind";this._isEnabled=!0;this._context=null;this.listeners=new Set;this.privateListeners=new Set;this.workerMessageListener=this.onWorkerMessage.bind(this);this._transformer=null;}static get recommendedCameraSettings(){let e=new CameraSettings(b.BarcodeFind.CameraSettings.settings);for(let[r,a]of Object.entries(b.BarcodeFind.CameraSettings.hiddenProperties))e.setProperty(r,a);return e}get context(){return this._context}get allListeners(){return [...this.privateListeners,...this.listeners]}static async forSettings(e){let r=new b$2;return r.settings=e,r}isEnabled(){return this._isEnabled}async setEnabled(e){this._isEnabled=e,await this.workerCommand("barcodeFindSetEnabled",{enabled:e});}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 r;for(let a of this.privateListeners)(r=a.onSetItemList)==null||r.call(a,e);return this.workerCommand("barcodeFindSetItemList",{itemList:e.map(a=>a.toJSONObject())})}async setBarcodeTransformer(e){var r;return this._transformer=e,this.workerCommand("barcodeFindSetTransformerFunction",{functionAsString:(r=this._transformer)==null?void 0:r.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,r){this.context!=null&&await this.context.workerCommand(e,r);}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 r,a,c;switch(e.type){case"barcodeFindDidUpdateSession":{if(this._context==null)return;for(let t of this.allListeners)(r=t.onDidUpdateSession)==null||r.call(t,this,a$2.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$1(new b$1(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$1(new b$1(o),null));t.didStopSearch(i);}break}case"barcodeFindListUpdatedFeedback":{for(let t of this.allListeners)(a=t.onFindListUpdatedFeedback)==null||a.call(t);break}case"barcodeFindFeedback":{for(let t of this.allListeners)(c=t.onFeedback)==null||c.call(t);break}}}addPrivateListener(e){this.privateListeners.add(e);}removePrivateListener(e){this.privateListeners.delete(e);}}; export { l as a };