@scandit/web-datacapture-barcode
Version:
Scandit Data Capture SDK for the Web
1 lines • 4.29 kB
JavaScript
import{PrivateBarcodeBatchAdvancedOverlayListener as e}from"./PrivateBarcodeBatchAdvancedOverlayListener.js";import{Anchor as t,MeasureUnit as n,NumberWithUnit as r,PointWithUnit as i}from"@scandit/web-datacapture-core";const a=new r(0,n.Pixel),o=new i(a,a),s=t.Center;var c=class t{constructor(){this.listener=null,this.type=`barcodeTrackingAdvanced`,this._shouldShowScanAreaGuides=!1,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(e){this._shouldShowScanAreaGuides=e,this.barcodeBatch.notifyContext()}static async withBarcodeBatchForView(n,r){let i=new t;return i.barcodeBatch=n,r&&(await r.addOverlay(i),i.view=r,i.privateListener=new e(i),n.addPrivateListener(i.privateListener),i.view.setDidTapCustomLocationsViewListener({didTapView:e=>{let t=i.getTrackedBarcodeForIdentifier(e);if(t){var n,r;(n=i.listener)==null||(r=n.didTapViewForTrackedBarcode)==null||r.call(n,i,t)}}})),i}async setViewForTrackedBarcode(e,t){if(e==null){this._viewForBarcode.set(t.identifier,null);return}let n=await e;n!=null&&this._viewForBarcode.set(t.identifier,n),this.barcodeBatch.isEnabled()||this.update()}setAnchorForTrackedBarcode(e,t){this._anchorForBarcode.set(t.identifier,e),this.barcodeBatch.isEnabled()||this.update()}setOffsetForTrackedBarcode(e,t){this._offsetForBarcode.set(t.identifier,e),this.barcodeBatch.isEnabled()||this.update()}clearTrackedBarcodeViews(){this._viewForBarcode.clear(),this.barcodeBatch.isEnabled()||this.update()}toJSONObject(){return{type:this.type,shouldShowScanAreaGuides:this._shouldShowScanAreaGuides}}getTrackedBarcodeForIdentifier(e){return this._barcodeForId.get(e)}async setViewForTrackedBarcodeFromListener(e,t){if(e==null){this._viewForBarcodeFromListener.set(t.identifier,null);return}let n=await e;n!=null&&this._viewForBarcodeFromListener.set(t.identifier,n)}processRemovedBarcodes(e){for(let t of e){let e=Number.parseInt(t,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(e){for(let s of e){if(this._anchorPositions.set(s.identifier,s.anchorPositions),this._barcodeForId.set(s.identifier,s),!this._viewForBarcodeFromListener.has(s.identifier)){var t,n;let e=((t=this.listener)==null||(n=t.viewForTrackedBarcode)==null?void 0:n.call(t,this,s))??Promise.resolve(null);this.setViewForTrackedBarcodeFromListener(e,s)}if(!this._offsetForBarcodeFromListener.has(s.identifier)){var r,i;let e=(r=this.listener)==null||(i=r.offsetForTrackedBarcode)==null?void 0:i.call(r,this,s);e!=null&&this._offsetForBarcodeFromListener.set(s.identifier,e)}if(!this._anchorForBarcodeFromListener.has(s.identifier)){var a,o;let e=(a=this.listener)==null||(o=a.anchorForTrackedBarcode)==null?void 0:o.call(a,this,s);e!=null&&this._anchorForBarcodeFromListener.set(s.identifier,e)}}}processUpdatedTrackedBarcodes(e){for(let t of e)this._anchorPositions.set(t.identifier,t.anchorPositions),this._barcodeForId.set(t.identifier,t)}update(e){e!=null&&(this.lastSession=e);let t=this.view;if(t===null)return;this.processRemovedBarcodes(this.lastSession.removedTrackedBarcodes),this.processAddedBarcodes(this.lastSession.addedTrackedBarcodes),this.processUpdatedTrackedBarcodes(this.lastSession.updatedTrackedBarcodes);let n={removedIds:this.lastSession.removedTrackedBarcodes,elements:[]};for(let e of Object.keys(this.lastSession.trackedBarcodes)){var r;let t=Number.parseInt(e,10),i=(r=this._viewForBarcode.get(t)??this._viewForBarcodeFromListener.get(t))==null?void 0:r.toJSONObject();i!=null&&n.elements.push({view:i,identifier:t,anchor:this._anchorForBarcode.get(t)??this._anchorForBarcodeFromListener.get(t)??s,offset:this._offsetForBarcode.get(t)??this._offsetForBarcodeFromListener.get(t)??o,anchorPositions:this._anchorPositions.get(t)})}t.renderCustomLocationsView(n)}};export{c as BarcodeBatchAdvancedOverlay};