UNPKG

@scandit/web-datacapture-barcode

Version:

Scandit Data Capture SDK for the Web

1 lines • 2.87 kB
import"./BarcodeArAnnotation.js";import{updatePosition as e}from"./private/updatePosition.js";import{BarcodeArInfoAnnotation as t}from"./BarcodeArInfoAnnotation.js";import{Logger as n,ScanditHTMLElement as r}from"@scandit/web-datacapture-core";import{clamp as i}from"@scandit/web-datacapture-core/build/js/private/utils/clamp.js";import{defineCustomElements as a}from"@scandit/web-datacapture-core/build/js/private/utils/defineCustomElements.js";var o=class o extends r{constructor(...e){super(...e),this._annotationsWithThreshold=[],this._currentAnnotation=null}static register(){a({[o.tag]:o})}static create(e,n,r){let i=document.createElement(o.tag);i._barcode=e;let a=n===null||n instanceof t?{[o.threshold]:r??null,1:n}:n;i._annotationsWithThreshold=o.dropOutOfBoundThresholds(a);let s=i._annotationsWithThreshold.length-1,c=i._annotationsWithThreshold[s];i._currentAnnotation=c?c.annotation:null;for(let e of i.getChildAnnotations())e.hidden=!0;return i}static isValidThreshold(e){return Number.isFinite(e)&&e>0&&e<=1}static dropOutOfBoundThresholds(e){let t=[],r=[];for(let n of Object.keys(e)){let i=Number(n);o.isValidThreshold(i)?r.push({threshold:i,annotation:e[i]}):t.push(i)}if(t.length>0&&n.warn(`BarcodeArResponsiveAnnotation: ignoring thresholds outside (0, 1]: ${t.join(`, `)}.`),r.sort((e,t)=>e.threshold-t.threshold),r.length>0){let e=r.length-1;r[e].threshold=1}return r}get barcode(){return this._barcode}get annotationTrigger(){var e;return((e=this._currentAnnotation)==null?void 0:e.annotationTrigger)??`highlightTapAndBarcodeScan`}set annotationTrigger(e){for(let t of this.getChildAnnotations())t.annotationTrigger=e}set anchor(e){for(let t of this.getChildAnnotations())t.anchor=e}get anchor(){var e;return((e=this._currentAnnotation)==null?void 0:e.anchor)??void 0}updatePosition(t,n,r){this.updateAnnotationVisibility(),e(this,t,n)}updateForAreaRatio(e){if(!Number.isFinite(e))return;let t=i(e,0,1),n=this.selectAnnotation(t);n!==this._currentAnnotation&&(this._currentAnnotation=n,this.updateAnnotationVisibility())}selectAnnotation(e){for(let t of this._annotationsWithThreshold)if(t.threshold>=e)return t.annotation;let t=this._annotationsWithThreshold.length-1,n=this._annotationsWithThreshold[t];return n?n.annotation:null}getChildAnnotations(){let e=new Set;for(let t of this._annotationsWithThreshold)t.annotation!=null&&e.add(t.annotation);return Array.from(e)}updateAnnotationVisibility(){for(let e of this.getChildAnnotations())e.hidden=e!==this._currentAnnotation}static get threshold(){return o._threshold}static set threshold(e){o._threshold=e}connectedCallback(){this.append(...this.getChildAnnotations()),this.updateAnnotationVisibility()}disconnectedCallback(){for(let e of this.getChildAnnotations())e.remove()}};o.tag=`scandit-barcode-ar-responsive-annotation`,o._threshold=.1;export{o as BarcodeArResponsiveAnnotation};