UNPKG

@scandit/web-datacapture-barcode

Version:

Scandit Data Capture SDK for the Web

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