@yoyaflow/yoya-ui 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import{Mi as e,Tt as t,g as n,h as r,v as i,vi as a}from"./yoya.core.chunk.min.js";var o=class extends t{constructor(e=null){super(`div`,null),this._autoResize=!0,this._chartInstance=null,this._devicePixelRatio=null,this._echartsLib=null,this._height=`400px`,this._loading=!1,this._loadingText=`加载中...`,this._onReadyCallbacks=[],this._onResizeCallbacks=[],this._option=null,this._renderer=`canvas`,this._resizeObserver=null,this._theme=null,this._width=`100%`,this.className(r,`yoya-vechart`),this.styles({height:this._height,overflow:`hidden`,position:`relative`,width:this._width}),this._setupEchart(e)}echartsLib(e){return e?this._echartsLib=e:typeof window<`u`&&window.echarts&&(this._echartsLib=window.echarts),this}option(e){return e===void 0?this._option:(this._option=e||null,this._chartInstance&&this._echartsLib&&this._chartInstance.setOption(this._option,!0),this)}width(e){return e===void 0?this._width:(this._width=e,this.style(`width`,e),this)}height(e){return e===void 0?this._height:(this._height=e,this.style(`height`,e),this)}theme(e){return e===void 0?this._theme:(this._theme=e,this)}renderer(e){return e===void 0?this._renderer:(this._renderer=e===`svg`?`svg`:`canvas`,this)}devicePixelRatio(e){return e===void 0?this._devicePixelRatio:(this._devicePixelRatio=e,this)}autoResize(e){return e===void 0?this._autoResize:(this._autoResize=!!e,this)}loading(e,t=`加载中...`){return this._loading=!!e,this._loadingText=t,this._chartInstance&&(this._loading?this._chartInstance.showLoading({color:`var(--yoya-color-primary, #2563eb)`,lineWidth:2,maskColor:`rgba(255, 255, 255, 0.8)`,text:t,textColor:`var(--yoya-color-text, #172033)`}):this._chartInstance.hideLoading()),this}onChartReady(e){return typeof e==`function`&&(this._chartInstance?e(this._chartInstance):this._onReadyCallbacks.push(e)),this}onChartResize(e){return typeof e==`function`&&this._onResizeCallbacks.push(e),this}getChartInstance(){return this._chartInstance}resize(e={}){return this._chartInstance&&this._chartInstance.resize(e),this}clear(){return this._chartInstance&&this._chartInstance.clear(),this}dispose(){return this._disposeChart(),this}destroy(){return this._disposeChart(),super.destroy()}renderDom(){let e=super.renderDom();return e&&!this._chartInstance&&requestAnimationFrame(()=>this._initChart()),e}_setupEchart(e){if(e!=null){if(typeof e==`function`){e(this);return}if(i(e)){let{autoResize:t,devicePixelRatio:n,echartsLib:r,height:i,loading:a,loadingText:o,onChartReady:s,onChartResize:c,option:l,renderer:u,theme:d,width:f,...p}=e;Object.keys(p).length>0&&this.setup(p),r!==void 0&&this.echartsLib(r),f!==void 0&&this.width(f),i!==void 0&&this.height(i),d!==void 0&&this.theme(d),u!==void 0&&this.renderer(u),n!==void 0&&this.devicePixelRatio(n),t!==void 0&&this.autoResize(t),o!==void 0&&(this._loadingText=o),s!==void 0&&this.onChartReady(s),c!==void 0&&this.onChartResize(c),l!==void 0&&this.option(l),a!==void 0&&this.loading(a,this._loadingText);return}this.child(e)}}_initChart(){if(!this._deleted){if(this._echartsLib||this.echartsLib(),!this._echartsLib){console.warn(`[VEchart] ECharts library not provided. Call echartsLib() first.`);return}if(!(this._chartInstance||!this._el))try{this._chartInstance=this._echartsLib.init(this._el,this._theme,{devicePixelRatio:this._devicePixelRatio,renderer:this._renderer}),this._option&&this._chartInstance.setOption(this._option,!0),this._loading&&this.loading(!0,this._loadingText),setTimeout(()=>{this._chartInstance&&!this._chartInstance.isDisposed()&&this._chartInstance.resize()},100),this._executeReadyCallbacks(),this._autoResize&&this._initResizeObserver()}catch(e){console.error(`[VEchart] Failed to initialize chart:`,e)}}}_executeReadyCallbacks(){this._chartInstance&&(this._onReadyCallbacks.forEach(e=>{try{e(this._chartInstance)}catch(e){console.error(`[VEchart] Error in onChartReady callback:`,e)}}),this._onReadyCallbacks=[])}_initResizeObserver(){if(typeof ResizeObserver<`u`){this._resizeObserver=new ResizeObserver(e=>{for(let t of e){let{height:e,width:n}=t.contentRect;this._handleResize(n,e)}}),this._el&&this._resizeObserver.observe(this._el);return}this._resizeHandler=()=>this._handleResize(),this._resizeUnbind=a(`resize`,this._resizeHandler)}_handleResize(e,t){this._chartInstance&&(this._chartInstance.resize(),this._onResizeCallbacks.forEach(n=>{try{n({height:t,width:e})}catch(e){console.error(`[VEchart] Error in onChartResize callback:`,e)}}))}_disposeChart(){this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._resizeHandler&&(this._resizeUnbind?.(),this._resizeHandler=null,this._resizeUnbind=null),this._chartInstance&&=(this._chartInstance.dispose(),null)}};function s(e=null,t=null,r=null){return n(o,e,t,r)}e(t,{vEchart:s});export{o as VEchart,s as vEchart};