import{MicroFrontendRegistry as t}from"../micro-frontend-registry/micro-frontend-registry.js";import{enableCoreServices as e}from"../micro-frontend-registry/lib/microServices.js";export class SimpleImg extends HTMLElement{static get tag(){return"simple-img"}constructor(){super(),e(),this.rendering=!1;var t=this.querySelector("img");t||(t=this.querySelector("template")&&this.querySelector("template").content.children[0]&&"IMG"===this.querySelector("template").content.children[0].tagName?this.querySelector("template").content.children[0]:{}),this.alt=t.alt||this.alt||"",this.src=t.src||this.src||"",this.loading=t.loading||this.loading||"lazy",this.decoding=t.decoding||this.decoding||"async",this.fetchpriority=t.fetchpriority||this.fetchpriority||"high",this.width=parseInt(t.width||this.width||300),this.height=parseInt(t.height||this.height||200),this.style.display="inline-block",this.style.width=this.width+"px",this.style.height=this.height+"px",this.innerHTML=null,this.quality=this.quality||80}static get haxProperties(){return new URL(`./lib/${this.tag}.haxProperties.json`,import.meta.url).href}static get observedAttributes(){return["srcconverted","src","loading","fetchpriority","decoding","alt","quality","height","width","rotate","fit","watermark","wmspot","format"]}updateconvertedurl(){if(this.src){const e={height:this.height,width:this.width,quality:this.quality,src:this.src,rotate:this.rotate,fit:this.fit,watermark:this.watermark,wmspot:this.wmspot,format:this.format};this.srcconverted=t.url("@core/imgManipulate",e)}}attributeChangedCallback(t,e,i){if(["width","height","quality","src","rotate","fit","format","watermark","wmspot"].includes(t)&&this.updateconvertedurl(),"srcconverted"===t&&""!=this.src&&!this.rendering){this.rendering=!0;let t=new Image;t.onload=()=>{this.render(this.srcconverted)},t.onerror=()=>{this.render(this.src)},t.src=this.srcconverted}}connectedCallback(){super.connectedCallback&&super.connectedCallback(),this.updateconvertedurl()}render(t){this.innerHTML=null,this.innerHTML=`\n    <img \n      src="${t}" \n      height="${this.height}" \n      width="${this.width}" \n      alt="${this.alt}" \n      fetchpriority="${this.fetchpriority}"\n      decoding="${this.decoding}"\n      loading="${this.loading}"\n    />`,this.rendering=!1}get rotate(){return this.getAttribute("rotate")}set rotate(t){this.setAttribute("rotate",t)}get fit(){return this.getAttribute("fit")}set fit(t){this.setAttribute("fit",t)}get watermark(){return this.getAttribute("watermark")}set watermark(t){this.setAttribute("watermark",t)}get wmspot(){return this.getAttribute("wmspot")}set wmspot(t){this.setAttribute("wmspot",t)}get format(){return this.getAttribute("format")}set format(t){this.setAttribute("format",t)}get height(){return this.getAttribute("height")}set height(t){this.setAttribute("height",t)}get width(){return this.getAttribute("width")}set width(t){this.setAttribute("width",t)}get src(){return this.getAttribute("src")}set src(t){this.setAttribute("src",t)}set srcconverted(t){this.setAttribute("srcconverted",t)}get srcconverted(){return this.getAttribute("srcconverted")}set loading(t){this.setAttribute("loading",t)}get loading(){return this.getAttribute("loading")}set fetchpriority(t){this.setAttribute("fetchpriority",t)}get fetchpriority(){return this.getAttribute("fetchpriority")}get quality(){return this.getAttribute("quality")}set quality(t){this.setAttribute("quality",t)}get alt(){return this.getAttribute("alt")}set alt(t){this.setAttribute("alt",t)}get baseurl(){return this.getAttribute("baseurl")}set baseurl(t){this.setAttribute("baseurl",t)}get decoding(){return this.getAttribute("decoding")}set decoding(t){this.setAttribute("decoding",t)}}customElements.define(SimpleImg.tag,SimpleImg);