/*! Built with http://stenciljs.com */
const{h:e}=window.webcomponents;import{f as t,i as s}from"./chunk-d76c3657.js";var i=function(e,t,s,i){return new(s||(s=Promise))(function(l,n){function r(e){try{o(i.next(e))}catch(e){n(e)}}function a(e){try{o(i.throw(e))}catch(e){n(e)}}function o(e){e.done?l(e.value):new s(function(t){t(e.value)}).then(r,a)}o((i=i.apply(e,t||[])).next())})};class l{constructor(){this.type="template"}componentDidLoad(){}componentDidUpdate(){}loadSvg(){return i(this,void 0,void 0,function*(){this.loading=!0;const e=yield fetch(`${this.src}`).then(e=>e.text()).catch(e=>console.error("Error:",e));return this.loading=!1,e})}parseSvg(e){let t=s;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(t=>{this.el.querySelector(".embedded").innerHTML=e,setTimeout(e=>{this.el.querySelector("svg")&&(this._svgElement=this.el.querySelector("svg"),this.renderSvg())},40),this.getElements()},20)}getElements(){this.elements=[];let e=["Shape","Oval","Rectangle","Line","Group"],s=this.el.querySelectorAll("*");return Array.prototype.forEach.call(s,s=>{if(t.getAttributes(s).id){let i=t.getAttributes(s).id,l=!1;e.forEach(e=>{i.match(e)&&(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(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).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")),console.log("--------------"),console.log("svg: type="+this.type),console.log("responsive="+t),console.log("viewBox="+s),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)}),e("div",null,e("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};