UNPKG

@scandit/web-datacapture-barcode

Version:

Scandit Data Capture SDK for the Web

1 lines • 7.78 kB
import"./BarcodeArAnnotation.js";import{getSlotted as e,setSlotted as t,slotSelector as n}from"../private/slots.js";import{BarcodeArInfoAnnotationBodyComponent as r}from"../atoms/BarcodeArInfoAnnotationBodyComponent.js";import{BarcodeArInfoAnnotationFooter as i}from"../atoms/BarcodeArInfoAnnotationFooter.js";import{BarcodeArInfoAnnotationHeader as a}from"../atoms/BarcodeArInfoAnnotationHeader.js";import{cssArrows as o}from"../atoms/private/CssArrows.js";import{updatePosition as s}from"./private/updatePosition.js";import{Color as c,ScanditIcon as l}from"@scandit/web-datacapture-core";import{ScanditHTMLElement as u,css as d,defineCustomElements as f,html as p}from"@scandit/web-datacapture-core/build/js/private/utils/index.js";let m=function(e){return e[e.Top=`top-center`]=`Top`,e[e.Bottom=`bottom-center`]=`Bottom`,e[e.Left=`left-center`]=`Left`,e[e.Right=`right-center`]=`Right`,e}({}),h=function(e){return e.Small=`small`,e.Medium=`medium`,e.Large=`large`,e}({}),g=function(e){return e.InfoAnnotationTap=`BarcodeArInfoAnnotationEventTap`,e}({});const _=`header`,v=`footer`,y=n(_),b=n(v),x=`--arrow-background-color`,S=`--background-color`,C=c.fromRGBA(255,255,255,1);var w=class n extends u{get barcode(){return this._barcode}set barcode(e){this._barcode=e}constructor(){super(),this.isEntireAnnotationTappable=!1,this.annotationTrigger=`highlightTapAndBarcodeScan`,this._widthPreset=`small`,this.onPointerUpListener=this.onPointerUp.bind(this),this.onSlotChangeListener=this.onSlotChange.bind(this),this.highlightableElementListenerMap=new Map;let e=this.attachShadow({mode:`open`});e.innerHTML=p`<div class="container arw-${m.Bottom} ${`small`}"><slot name="${_}"></slot><div class="body-container"><slot></slot></div><slot name="${v}"></slot></div>`,this.containerElement=e.querySelector(`.container`),e.append(n.createStyleElement().cloneNode(!0)),e.append(o())}updatePosition(e,t,n){s(this,e,t,0)}set anchor(e){for(let e of Object.values(m))this.containerElement.classList.remove(`arw-${e}`);this.containerElement.classList.add(`arw-${e}`),this.updateArrowColor()}get anchor(){for(let e of Object.values(m))if(this.containerElement.classList.contains(`arw-${e}`))return e;return m.Bottom}set widthPreset(e){this._widthPreset=e,this.containerElement.classList.remove(`small`,`medium`,`large`),this.containerElement.classList.add(e)}get widthPreset(){switch(!0){case this.containerElement.classList.contains(`small`):return`small`;case this.containerElement.classList.contains(`medium`):return`medium`;case this.containerElement.classList.contains(`large`):return`large`;default:return`small`}}get backgroundColor(){let e=this.containerElement.style.getPropertyValue(S);return e===``?C:c.fromHex(e)}set backgroundColor(e){this.containerElement.style.setProperty(S,`#${e.toJSON()}`),this.updateArrowColor()}set body(e){for(let e of this.body)e.remove();this.append(...e),this.updateArrowColor()}get body(){var e;let t=(e=this.shadowRoot)==null?void 0:e.querySelector(`slot:not([name])`);return(t==null?void 0:t.assignedElements())??[]}set header(e){t(this,_,e)}get header(){return e(this,_)}set footer(e){t(this,v,e)}get footer(){return e(this,v)}set hasTip(e){this.containerElement.classList.toggle(`arw-${this.anchor}`,e)}get hasTip(){return this.containerElement.classList.contains(`arw-${this.anchor}`)}static create(e){n.register();let t=document.createElement(n.tag);return t.barcode=e,t}static register(){f({[r.tag]:r,[a.tag]:a,[i.tag]:i,[n.tag]:n})}static createStyleElement(){return d`:host{--background-color:#${C.toJSON()};--arrow-size:7px;--arrow-background-color:var(--background-color);--arrow-offset:10px;font-family:SF Pro Display,sans-serif}.container{background-color:var(--background-color);border-radius:16px;display:flex;flex-direction:column;min-width:100px;position:relative;transition:opacity .3s ease;width:100%}.container.highlighted{opacity:.75}.container.${`small`}{width:180px}.container.${`medium`}{width:210px}.container.${`large`}{width:240px}.body-container{padding-bottom:1rem}`}connectedCallback(){var e,t;this.widthPreset=this._widthPreset,this.addEventListener(`pointerup`,this.onPointerUpListener);let n=(e=this.shadowRoot)==null?void 0:e.querySelector(y),r=(t=this.shadowRoot)==null?void 0:t.querySelector(b);n==null||n.addEventListener(`slotchange`,this.onSlotChangeListener),r==null||r.addEventListener(`slotchange`,this.onSlotChangeListener),this.onSlotChange(),this.isEntireAnnotationTappable&&this.makeHighlightable(this.containerElement)}disconnectedCallback(){var e,t;let n=(e=this.shadowRoot)==null?void 0:e.querySelector(y),r=(t=this.shadowRoot)==null?void 0:t.querySelector(b);n==null||n.removeEventListener(`slotchange`,this.onSlotChangeListener),r==null||r.removeEventListener(`slotchange`,this.onSlotChangeListener),this.removeEventListener(`pointerup`,this.onPointerUpListener);for(let[e,t]of this.highlightableElementListenerMap)e.removeEventListener(`pointerdown`,t.pointerdown),e.removeEventListener(`pointerup`,t.pointerup)}onSlotChange(){var e,t;let n=(e=this.shadowRoot)==null?void 0:e.querySelector(y),r=(t=this.shadowRoot)==null?void 0:t.querySelector(b),i=(n==null?void 0:n.assignedElements())??[],a=(r==null?void 0:r.assignedElements())??[];for(let e of i)e.style.setProperty(`--top-left-corner-radius`,`16px`),e.style.setProperty(`--top-right-corner-radius`,`16px`),this.isEntireAnnotationTappable||this.makeHighlightable(e);for(let e of a)e.style.setProperty(`--bottom-left-corner-radius`,`16px`),e.style.setProperty(`--bottom-right-corner-radius`,`16px`),this.isEntireAnnotationTappable||this.makeHighlightable(e);this.updateArrowColor()}updateArrowColor(){this.style.removeProperty(x),this.header||this.footer?this.header&&this.anchor.startsWith(`top`)?this.style.setProperty(x,`#${this.header.backgroundColor.toJSON()}`):this.footer&&this.anchor.startsWith(`bottom`)&&this.style.setProperty(x,`#${this.footer.backgroundColor.toJSON()}`):this.body.length>0&&!this.header&&!this.footer&&this.style.setProperty(x,`#${this.backgroundColor.toJSON()}`)}makeHighlightable(e){var t;let n=e.classList.contains(`container`)?e:(t=e.shadowRoot)==null?void 0:t.querySelector(`.container`);if(!n||this.highlightableElementListenerMap.has(n))return;let r=()=>{n.classList.add(`highlighted`)},i=()=>{n.classList.remove(`highlighted`)};n.addEventListener(`pointerdown`,r),n.addEventListener(`pointerup`,i),this.highlightableElementListenerMap.set(n,{pointerdown:r,pointerup:i})}onPointerUp(e){var t,n,o;let s=(t=e.target)==null?void 0:t.closest(a.tag),c=(n=e.target)==null?void 0:n.closest(i.tag),u=(o=e.target)==null?void 0:o.closest(`${r.tag} ${l.tag}`),d=new CustomEvent(`BarcodeArInfoAnnotationEventTap`,{bubbles:!0});if(s){var f,p;(f=this.listener)==null||(p=f.onInfoAnnotationHeaderTapped)==null||p.call(f,this),this.dispatchEvent(d)}if(c){var m,h;(m=this.listener)==null||(h=m.onInfoAnnotationFooterTapped)==null||h.call(m,this),this.dispatchEvent(d)}if((u==null?void 0:u.slot)===`left-barcode-icon`){let e=this.body.findIndex(e=>e.contains(u));if(this.body[e].isLeftIconTappable){var g,_;(g=this.listener)==null||(_=g.onInfoAnnotationLeftIconTapped)==null||_.call(g,this,this.body[e],e),this.dispatchEvent(d)}}if((u==null?void 0:u.slot)===`right-barcode-icon`){let e=this.body.findIndex(e=>e.contains(u));if(this.body[e].isRightIconTappable){var v,y;(v=this.listener)==null||(y=v.onInfoAnnotationRightIconTapped)==null||y.call(v,this,this.body[e],e),this.dispatchEvent(d)}}if(this.isEntireAnnotationTappable){var b,x;(b=this.listener)==null||(x=b.onInfoAnnotationTapped)==null||x.call(b,this),this.dispatchEvent(d)}}};w.tag=`scandit-barcode-ar-info-annotation`;export{w as BarcodeArInfoAnnotation,m as BarcodeArInfoAnnotationAnchor,g as BarcodeArInfoAnnotationEvent,h as BarcodeArInfoAnnotationWidthPreset};