import"../../es-global-bridge/es-global-bridge.js";class QRCodeElement extends HTMLElement{constructor(){super(),this.windowControllers=new AbortController,this._defineProperty=this._defineProperty.bind(this),this.attachShadow({mode:"open"}),Object.keys(QRCodeElement.defaultAttributes).map(this._defineProperty);const t=new URL("./qr.js",import.meta.url).href;globalThis.addEventListener("es-bridge-qr-loaded",this._qrLoaded.bind(this),{signal:this.windowControllers.signal}),globalThis.ESGlobalBridge.requestAvailability().load("qr",t)}disconnectedCallback(){this.windowControllers.abort(),super.disconnectedCallback&&super.disconnectedCallback()}static get tag(){return"qr-code"}_qrLoaded(){this.generate()}static get defaultAttributes(){return{data:null,format:"png",modulesize:5,margin:4}}static get observedAttributes(){return Object.keys(QRCodeElement.defaultAttributes)}attributeChangedCallback(t,e,i){let s=this[t+"Changed"];s&&"function"==typeof s&&s.call(this,e,i),!0===globalThis.ESGlobalBridge.requestAvailability().imports.qr&&this.generate()}_defineProperty(t){Object.defineProperty(this,t,{get:()=>{let e=this.getAttribute(t);return null===e?QRCodeElement.defaultAttributes[t]:e},set:e=>{this.setAttribute(t,e)}})}getOptions(){let{modulesize:t,margin:e}=this;return{modulesize:null!==t?parseInt(t):t,margin:null!==e?parseInt(e):e}}generate(){null!==this.data?"png"===this.format?this.generatePNG():"html"===this.format?this.generateHTML():"svg"===this.format?this.generateSVG():this.shadowRoot.innerHTML="<div>qr-code: "+this.format+" not supported!</div>":this.shadowRoot.innerHTML="<div>qr-code: no data!</div>"}generatePNG(){try{let t=globalThis.document.createElement("img");t.src=globalThis.QRCode.generatePNG(this.data,this.getOptions()),this.clear(),this.shadowRoot.appendChild(t)}catch(t){this.shadowRoot.innerHTML="<div>qr-code: no canvas support!</div>"}}generateHTML(){let t=globalThis.QRCode.generateHTML(this.data,this.getOptions());this.clear(),this.shadowRoot.appendChild(t)}generateSVG(){let t=globalThis.QRCode.generateSVG(this.data,this.getOptions());this.clear(),this.shadowRoot.appendChild(t)}clear(){for(;this.shadowRoot.lastChild;)this.shadowRoot.removeChild(this.shadowRoot.lastChild)}}customElements.define(QRCodeElement.tag,QRCodeElement);export{QRCodeElement};