/*! Built with http://stenciljs.com */
const{h:t}=window.webcomponents;import"./chunk-8cffe313.js";import"./chunk-e405d082.js";import"./chunk-3bf53888.js";import"./chunk-7fb7349a.js";import{b as e,c as s}from"./chunk-541bf05a.js";var i=function(t,e,s,i){return new(s||(s=Promise))(function(l,r){function n(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){t.done?l(t.value):new s(function(e){e(t.value)}).then(n,a)}c((i=i.apply(t,e||[])).next())})};class l{constructor(){this.type="template"}componentDidLoad(){}componentDidUpdate(){}loadSvg(){return i(this,void 0,void 0,function*(){this.loading=!0;const t=yield fetch(`${this.src}`).then(t=>t.text()).catch(t=>console.error("Error:",t));return this.loading=!1,t})}parseSvg(t){let e=s;this._svg=t,t=t.replace("]>",""),t=e.replaceAll(t,"{{ ","{{"),t=e.replaceAll(t,"{{  ","{{"),t=e.replaceAll(t," }}","}}"),t=e.replaceAll(t,"  }}","}}"),this.data&&Object.keys(this.data).forEach(s=>{t=e.replaceAll(t,"{{"+s+"}}",this.data[s])}),this.svgResult=t,setTimeout(e=>{this.el.querySelector(".embedded").innerHTML=t,setTimeout(t=>{this.el.querySelector("svg")&&(this._svgElement=this.el.querySelector("svg"),this.renderSvg())},40),this.getElements()},20)}getElements(){this.elements=[];let t=["Shape","Oval","Rectangle","Line","Group"],s=this.el.querySelectorAll("*");return Array.prototype.forEach.call(s,s=>{if(e.getAttributes(s).id){let i=e.getAttributes(s).id,l=!1;t.forEach(t=>{i.match(t)&&(l=!0)}),l||(i.match("btn-")&&(s.style.cursor="pointer",s.style.opacity="0"),this.elements.push({id:i,el:s}))}}),this.setClickHandlers(),this.elements}svgElementClickHandler(t){let e;t.stopPropagation(),this.elements.forEach(s=>{s.el===t.target&&(e=s)}),e&&this.svgElementClick.emit(e)}setClickHandlers(){this.elements.forEach(t=>{document.getElementById(t.id).addEventListener("click",t=>{this.svgElementClickHandler(t)}),t.id.match("btn-")})}renderSvg(){const t=this._svgElement,e=!(-1===this.el.className.indexOf("img-responsive"));let s,i,l;if(t.getAttribute("viewBox")&&(s=t.getAttribute("viewBox")),s&&(i=s.split(" ")[2],l=s.split(" ")[3],!1===e)){let e;this.el.style.width=i+"px",this.el.style.maxWidth=i+"px",this.el.style.height=l+"px",this.el.style.maxHeight=l+"px",t.style.width=i+"px",t.style.maxWidth=i+"px",t.style.height=l+"px",t.style.maxHeight=l+"px",(e=document.createAttribute("width")).value=i,t.setAttributeNode(e),(e=document.createAttribute("height")).value=l,t.setAttributeNode(e)}}render(){return this.dataJson&&(this.data=JSON.parse(this.dataJson)),this.src&&this.loadSvg().then(t=>{this.parseSvg(t)}),t("div",null,t("div",{class:"svg-container embedded"}))}static get is(){return"ema-svg"}static get properties(){return{data:{state:!0},dataJson:{type:"Any",attr:"data-json"},el:{elementRef:!0},getElements:{method:!0},src:{type:String,attr:"src"},svgResult:{state:!0},type:{type:String,attr:"type"}}}static get events(){return[{name:"svgElementClick",method:"svgElementClick",bubbles:!0,cancelable:!0,composed:!0}]}}export{l as EmaSvg};