/*! Built with http://stenciljs.com */
var __generator=this&&this.__generator||function(t,e){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=r[2&o[0]?"return":o[0]?"throw":"next"])&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[0,i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};import{h}from"./webcomponents.core.js";import"./chunk-c1dbd7c7.js";import{c as DomUtil,d as StringUtil}from"./chunk-67be3191.js";import"./chunk-7fb7349a.js";import"./chunk-25ecf4a4.js";import"./chunk-ccff1a1c.js";var __awaiter=function(t,e,n,r){return new(n||(n=Promise))(function(i,o){function a(t){try{s(r.next(t))}catch(t){o(t)}}function l(t){try{s(r.throw(t))}catch(t){o(t)}}function s(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(a,l)}s((r=r.apply(t,e||[])).next())})},Svg=function(){function t(){this.type="template"}return t.prototype.componentDidLoad=function(){},t.prototype.componentDidUpdate=function(){},t.prototype.loadSvg=function(){return __awaiter(this,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return this.loading=!0,[4,fetch(""+this.src).then(function(t){return t.text()}).catch(function(t){return console.error("Error:",t)})];case 1:return t=e.sent(),this.loading=!1,[2,t]}})})},t.prototype.parseSvg=function(t){var e=this,n=StringUtil;this._svg=t,t=t.replace("]>",""),t=n.replaceAll(t,"{{ ","{{"),t=n.replaceAll(t,"{{  ","{{"),t=n.replaceAll(t," }}","}}"),t=n.replaceAll(t,"  }}","}}"),this.data&&Object.keys(this.data).forEach(function(r){t=n.replaceAll(t,"{{"+r+"}}",e.data[r])}),this.svgResult=t,setTimeout(function(n){e.el.querySelector(".embedded").innerHTML=t,setTimeout(function(t){e.el.querySelector("svg")&&(e._svgElement=e.el.querySelector("svg"),e.renderSvg())},40),e.getElements()},20)},t.prototype.getElements=function(){var t=this;this.elements=[];var e=["Shape","Oval","Rectangle","Line","Group"],n=this.el.querySelectorAll("*");return Array.prototype.forEach.call(n,function(n){if(DomUtil.getAttributes(n).id){var r=DomUtil.getAttributes(n).id,i=!1;e.forEach(function(t){r.match(t)&&(i=!0)}),i||(r.match("btn-")&&(n.style.cursor="pointer",n.style.opacity="0"),t.elements.push({id:r,el:n}))}}),this.setClickHandlers(),this.elements},t.prototype.svgElementClickHandler=function(t){var e;t.stopPropagation(),this.elements.forEach(function(n){n.el===t.target&&(e=n)}),e&&this.svgElementClick.emit(e)},t.prototype.setClickHandlers=function(){var t=this;this.elements.forEach(function(e){document.getElementById(e.id).addEventListener("click",function(e){t.svgElementClickHandler(e)}),e.id.match("btn-")})},t.prototype.renderSvg=function(){var t,e,n,r=this._svgElement,i=!(-1===this.el.className.indexOf("img-responsive"));if(r.getAttribute("viewBox")&&(t=r.getAttribute("viewBox")),t&&(e=t.split(" ")[2],n=t.split(" ")[3],!1===i)){this.el.style.width=e+"px",this.el.style.maxWidth=e+"px",this.el.style.height=n+"px",this.el.style.maxHeight=n+"px",r.style.width=e+"px",r.style.maxWidth=e+"px",r.style.height=n+"px",r.style.maxHeight=n+"px";var o=void 0;(o=document.createAttribute("width")).value=e,r.setAttributeNode(o),(o=document.createAttribute("height")).value=n,r.setAttributeNode(o)}},t.prototype.render=function(){var t=this;return this.dataJson&&(this.data=JSON.parse(this.dataJson)),this.src&&this.loadSvg().then(function(e){t.parseSvg(e)}),h("div",null,h("div",{class:"svg-container embedded"}))},Object.defineProperty(t,"is",{get:function(){return"ema-svg"},enumerable:!0,configurable:!0}),Object.defineProperty(t,"properties",{get:function(){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"}}},enumerable:!0,configurable:!0}),Object.defineProperty(t,"events",{get:function(){return[{name:"svgElementClick",method:"svgElementClick",bubbles:!0,cancelable:!0,composed:!0}]},enumerable:!0,configurable:!0}),t}();export{Svg as EmaSvg};