UNPKG

@scandit/web-datacapture-barcode

Version:

Scandit Data Capture SDK for the Web

1 lines 4.32 kB
import {a}from'./chunk-C52THG7K.js';import {NumberWithUnit,MeasureUnit,PointWithUnit,Anchor}from'@scandit/web-datacapture-core';var f=new NumberWithUnit(0,MeasureUnit.Pixel),F=new PointWithUnit(f,f),m=Anchor.Center,p=class v{constructor(){this.listener=null;this.type="barcodeTrackingAdvanced";this._shouldShowScanAreaGuides=false;this._viewForBarcode=new Map;this._anchorForBarcode=new Map;this._offsetForBarcode=new Map;this._viewForBarcodeFromListener=new Map;this._anchorForBarcodeFromListener=new Map;this._offsetForBarcodeFromListener=new Map;this._anchorPositions=new Map;this._barcodeForId=new Map;}get shouldShowScanAreaGuides(){return this._shouldShowScanAreaGuides}set shouldShowScanAreaGuides(a){this._shouldShowScanAreaGuides=a,this.barcodeBatch.notifyContext();}static async withBarcodeBatchForView(a$1,r){let e=new v;return e.barcodeBatch=a$1,r&&(await r.addOverlay(e),e.view=r,e.privateListener=new a(e),a$1.addPrivateListener(e.privateListener),e.view.setDidTapCustomLocationsViewListener({didTapView:n=>{var t,d;let o=e.getTrackedBarcodeForIdentifier(n);o&&((d=(t=e.listener)==null?void 0:t.didTapViewForTrackedBarcode)==null||d.call(t,e,o));}})),e}async setViewForTrackedBarcode(a,r){if(a==null){this._viewForBarcode.set(r.identifier,null);return}let e=await a;e!=null&&this._viewForBarcode.set(r.identifier,e),this.barcodeBatch.isEnabled()||this.update();}setAnchorForTrackedBarcode(a,r){this._anchorForBarcode.set(r.identifier,a),this.barcodeBatch.isEnabled()||this.update();}setOffsetForTrackedBarcode(a,r){this._offsetForBarcode.set(r.identifier,a),this.barcodeBatch.isEnabled()||this.update();}clearTrackedBarcodeViews(){this._viewForBarcode.clear(),this.barcodeBatch.isEnabled()||this.update();}toJSONObject(){return {type:this.type,shouldShowScanAreaGuides:this._shouldShowScanAreaGuides}}getTrackedBarcodeForIdentifier(a){return this._barcodeForId.get(a)}async setViewForTrackedBarcodeFromListener(a,r){if(a==null){this._viewForBarcodeFromListener.set(r.identifier,null);return}let e=await a;e!=null&&this._viewForBarcodeFromListener.set(r.identifier,e);}processRemovedBarcodes(a){for(let r of a){let e=Number.parseInt(r,10);this._viewForBarcode.delete(e),this._anchorForBarcode.delete(e),this._offsetForBarcode.delete(e),this._anchorPositions.delete(e),this._viewForBarcodeFromListener.delete(e),this._anchorForBarcodeFromListener.delete(e),this._offsetForBarcodeFromListener.delete(e);}}processAddedBarcodes(a){var r,e,n,o,t,d,h;for(let i of a){if(this._anchorPositions.set(i.identifier,i.anchorPositions),this._barcodeForId.set(i.identifier,i),!this._viewForBarcodeFromListener.has(i.identifier)){let c=(n=(e=(r=this.listener)==null?void 0:r.viewForTrackedBarcode)==null?void 0:e.call(r,this,i))!=null?n:Promise.resolve(null);this.setViewForTrackedBarcodeFromListener(c,i);}if(!this._offsetForBarcodeFromListener.has(i.identifier)){let c=(t=(o=this.listener)==null?void 0:o.offsetForTrackedBarcode)==null?void 0:t.call(o,this,i);c!=null&&this._offsetForBarcodeFromListener.set(i.identifier,c);}if(!this._anchorForBarcodeFromListener.has(i.identifier)){let c=(h=(d=this.listener)==null?void 0:d.anchorForTrackedBarcode)==null?void 0:h.call(d,this,i);c!=null&&this._anchorForBarcodeFromListener.set(i.identifier,c);}}}processUpdatedTrackedBarcodes(a){for(let r of a)this._anchorPositions.set(r.identifier,r.anchorPositions),this._barcodeForId.set(r.identifier,r);}update(a){var n,o,t,d,h,i;a!=null&&(this.lastSession=a);let r=this.view;if(r===null)return;this.processRemovedBarcodes(this.lastSession.removedTrackedBarcodes),this.processAddedBarcodes(this.lastSession.addedTrackedBarcodes),this.processUpdatedTrackedBarcodes(this.lastSession.updatedTrackedBarcodes);let e={removedIds:this.lastSession.removedTrackedBarcodes,elements:[]};for(let c of Object.keys(this.lastSession.trackedBarcodes)){let s=Number.parseInt(c,10),B=(o=(n=this._viewForBarcode.get(s))!=null?n:this._viewForBarcodeFromListener.get(s))==null?void 0:o.toJSONObject();B!=null&&e.elements.push({view:B,identifier:s,anchor:(d=(t=this._anchorForBarcode.get(s))!=null?t:this._anchorForBarcodeFromListener.get(s))!=null?d:m,offset:(i=(h=this._offsetForBarcode.get(s))!=null?h:this._offsetForBarcodeFromListener.get(s))!=null?i:F,anchorPositions:this._anchorPositions.get(s)});}r.renderCustomLocationsView(e);}};export{p as a};