"use strict";var y=Object.defineProperty;var w=(n,r,o)=>r in n?y(n,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[r]=o;var p=(n,r,o)=>w(n,typeof r!="symbol"?r+"":r,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("vue"),g=require("echarts"),v=require("nanoid"),b=require("../../commons/core/datasource/index.js");function C(n){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const o in n)if(o!=="default"){const c=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(r,o,c.get?c:{enumerable:!0,get:()=>n[o]})}}return r.default=n,Object.freeze(r)}const E=C(g),D=(n,r,o)=>{const c=d.ref(),s=d.ref(!1);class f{constructor(){p(this,"_iframe");this._iframe=c.value}fastEval(i){const t=this._iframe.contentWindow.document.getElementsByTagName("head")[0],e=this._iframe.contentWindow.document.createElement("script");e.setAttribute("type","text/javascript");const a=this._iframe.contentWindow.document.createElement("style");a.innerHTML=`
            *{
                margin:0;
                padding:0;
            }
            body, html {
                height:100%;
                overflow: hidden;
                background-color: transparent;
            }
            #renderDom {
                width:100%;
                height:100%;
                background-color: transparent;
                outline: none !important;
            }
        `,e.innerHTML=`
        try {
            ${i};
        } catch(e) {
            handleException(e);
        }`,t.innerHTML="",t.appendChild(a),t.appendChild(e)}async loadScriptAsync(i){return new Promise(t=>{const e=document.createElement("script");e.src=i,e.onload=()=>{t()},document.head.appendChild(e)})}async compileAndRunAsync(i){try{if(i.includes("window.")||i.includes("parent.")||i.includes("top."))return;let t="";s.value=!0;const e=this._iframe.contentWindow;if(e.myChart){try{e.myChart.dispose()}catch{}e.myChart=null,e.option=null}delete e.myChart,delete e.option,delete e.renderDom,delete e.initFunction;let a=e.document.getElementById("renderDom");if(a||(a=e.document.createElement("div"),a.id="renderDom",e.document.body.appendChild(a)),e.echarts=E,!a||(e.renderDom=a,!i))return;t+=`
                        window.initFunction = async function() {
                        window.myChart  = echarts.init(renderDom, null, {
                          renderer: 'svg'
                        });
                        window.option;
                    `,t+=i,t+=`

                            option && myChart.setOption(option);`,t+=`

                        }`;try{this.fastEval(t)}catch{}try{await e.initFunction()}catch{}if(!e.option)return;s.value=!1}catch{s.value=!1}}}const u=m=>{b.SHJDatasourceV2.parse({tId:v.nanoid(),sources:r,callback:({data:i})=>{try{window.SHJParseEvent(o,"dataListener",i);const t=`var echartsData = ${JSON.stringify(i[0].data[0].echartsData)};`;l.value.compileAndRunAsync(t+`
`+m)}catch{window.SHJParseEvent(o,"dataListener",null)}}})},l=d.ref();return d.onMounted(()=>{l.value=new f,u(n.code)}),{iframeRef:c,loadingStatus:s,renderingComponent:l,initEcharts:u}};exports.useEcharts=D;
