import{r as e,c as t,h as s,g as i}from"./p-3b76effa.js";import"./p-d7ac2f15.js";import{D as l,S as r}from"./p-18ca1c85.js";class a{constructor(s){e(this,s),this.type="template",this.svgElementClick=t(this,"svgElementClick",7)}componentDidLoad(){}componentDidUpdate(){}async loadSvg(){this.loading=!0;const e=await fetch(`${this.src}`).then(e=>e.text()).catch(e=>console.error("Error:",e));return this.loading=!1,e}parseSvg(e){let t=r;this._svg=e,e=e.replace("]>",""),e=t.replaceAll(e,"{{ ","{{"),e=t.replaceAll(e,"{{  ","{{"),e=t.replaceAll(e," }}","}}"),e=t.replaceAll(e,"  }}","}}"),this.data&&Object.keys(this.data).forEach(s=>{e=t.replaceAll(e,"{{"+s+"}}",this.data[s])}),this.svgResult=e,setTimeout(()=>{this.el.querySelector(".embedded").innerHTML=e,this.getElements(),this.el.querySelector("svg")&&(this._svgElement=this.el.querySelector("svg"),this.renderSvg())},20)}async getElements(){this.elements=[];let e=["Shape","Oval","Rectangle","Line","Group"],t=this.el.querySelectorAll("*");return Array.prototype.forEach.call(t,t=>{if(l.getAttributes(t).id){let s=l.getAttributes(t).id,i=!1;e.forEach(e=>{s.match(e)&&(i=!0)}),i||(s.match("btn-")&&(t.style.cursor="pointer",t.style.opacity="0"),this.elements.push({id:s,el:t}))}}),this.setClickHandlers(),this.elements}svgElementClickHandler(e){let t;e.stopPropagation(),this.elements.forEach(s=>{s.el===e.target&&(t=s)}),t&&this.svgElementClick.emit(t)}setClickHandlers(){this.elements.forEach(e=>{document.getElementById(e.id)&&(document.getElementById(e.id).addEventListener("click",e=>{this.svgElementClickHandler(e)}),e.id.match("btn-"))})}renderSvg(){const e=this._svgElement,t=!(-1===this.el.className.indexOf("img-responsive"));let s,i,l;if(e.getAttribute("viewBox")&&(s=e.getAttribute("viewBox")),s&&(i=s.split(" ")[2],l=s.split(" ")[3],!1===t)){let t;this.el.style.width=i+"px",this.el.style.maxWidth=i+"px",this.el.style.height=l+"px",this.el.style.maxHeight=l+"px",e.style.width=i+"px",e.style.maxWidth=i+"px",e.style.height=l+"px",e.style.maxHeight=l+"px",(t=document.createAttribute("width")).value=i,e.setAttributeNode(t),(t=document.createAttribute("height")).value=l,e.setAttributeNode(t)}}render(){return this.dataJson&&(this.data=JSON.parse(this.dataJson)),this.src&&this.loadSvg().then(e=>{this.parseSvg(e)}),s("div",{class:"svg-container embedded"})}get el(){return i(this)}}export{a as ema_svg};