@qfo/qfchart 0.6.3 → 0.6.4

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.
package/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@ interface IndicatorPoint {
28
28
  bordercolor?: string;
29
29
  };
30
30
  }
31
- type IndicatorStyle = 'line' | 'step' | 'columns' | 'histogram' | 'circles' | 'cross' | 'background' | 'shape' | 'char' | 'bar' | 'candle' | 'barcolor';
31
+ type IndicatorStyle = 'line' | 'step' | 'columns' | 'histogram' | 'circles' | 'cross' | 'background' | 'shape' | 'char' | 'bar' | 'candle' | 'barcolor' | 'fill';
32
32
  interface IndicatorOptions {
33
33
  style: IndicatorStyle;
34
34
  color: string;
@@ -47,8 +47,10 @@ interface IndicatorOptions {
47
47
  bordercolor?: string;
48
48
  }
49
49
  interface IndicatorPlot {
50
- data: IndicatorPoint[];
50
+ data?: IndicatorPoint[];
51
51
  options: IndicatorOptions;
52
+ plot1?: string;
53
+ plot2?: string;
52
54
  }
53
55
  interface Indicator$1 {
54
56
  id: string;
@@ -14,25 +14,25 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- (function(et,lt){typeof exports=="object"&&typeof module<"u"?lt(exports,require("echarts")):typeof define=="function"&&define.amd?define(["exports","echarts"],lt):(et=typeof globalThis<"u"?globalThis:et||self,lt(et.QFChart={},et.echarts))})(this,function(et,lt){"use strict";function yt(r){var e=Object.create(null);return r&&Object.keys(r).forEach(function(t){if(t!=="default"){var i=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:function(){return r[t]}})}}),e.default=r,Object.freeze(e)}var j=yt(lt),xt=Object.defineProperty,mt=(r,e,t)=>e in r?xt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,at=(r,e,t)=>(mt(r,typeof e!="symbol"?e+"":e,t),t);class bt{constructor(e,t,i,s={}){at(this,"id"),at(this,"plots"),at(this,"paneIndex"),at(this,"height"),at(this,"collapsed"),at(this,"titleColor"),at(this,"controls"),this.id=e,this.plots=t,this.paneIndex=i,this.height=s.height,this.collapsed=s.collapsed||!1,this.titleColor=s.titleColor,this.controls=s.controls}toggleCollapse(){this.collapsed=!this.collapsed}isVisible(){return!this.collapsed}updateData(e){Object.keys(e).forEach(t=>{if(!this.plots[t])this.plots[t]=e[t];else{const i=this.plots[t],s=e[t];s.options&&(i.options={...i.options,...s.options});const o=new Map;i.data.forEach(n=>{o.set(n.time,n)}),s.data.forEach(n=>{o.set(n.time,n)}),i.data=Array.from(o.values()).sort((n,p)=>n.time-p.time)}})}}class ft{static calculate(e,t,i,s=!1,o=null,n){let p=0;e>0&&(p=1/e*100);const d=i.yAxisPadding!==void 0?i.yAxisPadding:5,l=h=>C=>{const M=(C.max-C.min)*(h/100);return C.min-M},k=h=>C=>{const M=(C.max-C.min)*(h/100);return C.max+M},y=Array.from(t.values()).map(h=>h.paneIndex).filter(h=>h>0).sort((h,C)=>h-C).filter((h,C,M)=>M.indexOf(h)===C),m=y.length>0,I=i.dataZoom?.visible??!0,u=i.dataZoom?.position??"top",f=i.dataZoom?.height??6,v=i.dataZoom?.start??0,E=i.dataZoom?.end??100;let V=8,Z=92,x=-1;if(o)if(o==="main")x=0;else{const h=t.get(o);h&&(x=h.paneIndex)}if(x!==-1){const h=[],C=[],M=[],$=[],R=i.dataZoom?.start??50,D=i.dataZoom?.end??100;(i.dataZoom?.zoomOnTouch??!0)&&$.push({type:"inside",xAxisIndex:"all",start:R,end:D});const W=m?Math.max(...y):0,q=[];for(let O=0;O<=W;O++){const B=O===x;h.push({left:"10%",right:"10%",top:B?"5%":"0%",height:B?"90%":"0%",show:B,containLabel:!1}),C.push({type:"category",gridIndex:O,data:[],show:B,axisLabel:{show:B,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:B,lineStyle:{color:"#334155"}},splitLine:{show:B,lineStyle:{color:"#334155",opacity:.5}}});let tt,st;if(O===0&&x===0?(tt=i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?i.yAxisMin:l(d),st=i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?i.yAxisMax:k(d)):(tt=l(d),st=k(d)),M.push({position:"right",gridIndex:O,show:B,scale:!0,min:tt,max:st,axisLabel:{show:B,color:"#94a3b8",fontFamily:i.fontFamily,formatter:J=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(J);const ot=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:2;return typeof J=="number"?J.toFixed(ot):String(J)}},splitLine:{show:B,lineStyle:{color:"#334155",opacity:.5}}}),O>0){const J=Array.from(t.values()).find(ot=>ot.paneIndex===O);J&&q.push({index:O,height:B?90:0,top:B?5:0,isCollapsed:!1,indicatorId:J.id,titleColor:J.titleColor,controls:J.controls})}}return{grid:h,xAxis:C,yAxis:M,dataZoom:$,paneLayout:q,mainPaneHeight:x===0?90:0,mainPaneTop:x===0?5:0,pixelToPercent:p,overlayYAxisMap:new Map,separatePaneYAxisOffset:1}}I?u==="top"?(V=f+4,Z=95):(Z=100-f-2,V=8):(V=5,Z=95);let A=5;e>0&&(A=20/e*100);let w=75,T=[];if(m){const h=y.map(D=>{const W=Array.from(t.values()).find(q=>q.paneIndex===D);return{index:D,requestedHeight:W?.height,isCollapsed:W?.collapsed??!1,indicatorId:W?.id,titleColor:W?.titleColor,controls:W?.controls}}).map(D=>({...D,height:D.isCollapsed?3:D.requestedHeight!==void 0?D.requestedHeight:15})),C=h.reduce((D,W)=>D+W.height,0),M=h.length*A,$=C+M;w=Z-V-$,s?w=3:w<20&&(w=Math.max(w,10));let R=V+w+A;T=h.map(D=>{const W={index:D.index,height:D.height,top:R,isCollapsed:D.isCollapsed,indicatorId:D.indicatorId,titleColor:D.titleColor,controls:D.controls};return R+=D.height+A,W})}else w=Z-V,s&&(w=3);const S=[];S.push({left:"10%",right:"10%",top:V+"%",height:w+"%",containLabel:!1}),T.forEach(h=>{S.push({left:"10%",right:"10%",top:h.top+"%",height:h.height+"%",containLabel:!1})});const c=[0,...T.map((h,C)=>C+1)],a=[],g=T.length===0;a.push({type:"category",data:[],gridIndex:0,scale:!0,axisLine:{onZero:!1,show:!s,lineStyle:{color:"#334155"}},splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:h=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(h);const C=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:2;return typeof h=="number"?h.toFixed(C):String(h)}},axisTick:{show:!s},axisPointer:{label:{show:g,fontSize:11,backgroundColor:"#475569"}}}),T.forEach((h,C)=>{const M=C===T.length-1;a.push({type:"category",gridIndex:C+1,data:[],axisLabel:{show:!1},axisLine:{show:!h.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:M,fontSize:11,backgroundColor:"#475569"}}})});const b=[];let P,F;i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?P=i.yAxisMin:P=l(d),i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?F=i.yAxisMax:F=k(d),b.push({position:"right",scale:!0,min:P,max:F,gridIndex:0,splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLine:{show:!s,lineStyle:{color:"#334155"}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:h=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(h);const C=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:2;return typeof h=="number"?h.toFixed(C):String(h)}}});let z=1,G=-1/0,N=1/0;n&&n.length>0&&(G=Math.min(...n.map(h=>h.low)),N=Math.max(...n.map(h=>h.high)));const H=new Map;t.forEach((h,C)=>{h.paneIndex===0&&!h.collapsed&&n&&n.length>0&&Object.entries(h.plots).forEach(([M,$])=>{const R=`${C}::${M}`,D=["background","barcolor","char"],W=$.options.style==="shape"&&($.options.location==="abovebar"||$.options.location==="belowbar");if(D.includes($.options.style)){H.has(R)||(H.set(R,z),z++);return}if($.options.style==="shape"&&!W){H.has(R)||(H.set(R,z),z++);return}const q=[];if(Object.values($.data).forEach(O=>{typeof O=="number"&&!isNaN(O)&&isFinite(O)&&q.push(O)}),q.length>0){const O=Math.min(...q),B=Math.max(...q),tt=B-O,st=N-G,J=O>=G*.5&&B<=N*1.5,ot=tt>st*.01;J&&ot||H.has(R)||(H.set(R,z),z++)}})});const X=H.size>0?z-1:0;for(let h=0;h<X;h++)b.push({position:"left",scale:!0,min:l(d),max:k(d),gridIndex:0,show:!1,splitLine:{show:!1},axisLine:{show:!1},axisLabel:{show:!1}});const K=z;T.forEach((h,C)=>{b.push({position:"right",scale:!0,min:l(d),max:k(d),gridIndex:C+1,splitLine:{show:!h.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!h.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10,formatter:M=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(M);const $=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:2;return typeof M=="number"?M.toFixed($):String(M)}},axisLine:{show:!h.isCollapsed,lineStyle:{color:"#334155"}}})});const Y=[];return I&&((i.dataZoom?.zoomOnTouch??!0)&&Y.push({type:"inside",xAxisIndex:c,start:v,end:E}),u==="top"?Y.push({type:"slider",xAxisIndex:c,top:"1%",height:f+"%",start:v,end:E,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1}):Y.push({type:"slider",xAxisIndex:c,bottom:"1%",height:f+"%",start:v,end:E,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1})),{grid:S,xAxis:a,yAxis:b,dataZoom:Y,paneLayout:T,mainPaneHeight:w,mainPaneTop:V,pixelToPercent:p,overlayYAxisMap:H,separatePaneYAxisOffset:K}}static calculateMaximized(e,t,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}const pt=new Map;function vt(r,e="#00da3c",t="64px"){if(typeof document>"u")return"";const i=`${r}-${e}-${t}`;if(pt.has(i))return pt.get(i);const s=document.createElement("canvas"),o=s.getContext("2d");if(s.width=32,s.height=32,o){o.font="bold "+t+" Arial",o.fillStyle=e,o.textAlign="center",o.textBaseline="middle",o.fillText(r,16,16);const n=s.toDataURL("image/png");return pt.set(i,n),n}return""}class it{static buildCandlestickSeries(e,t,i){const s=t.upColor||"#00da3c",o=t.downColor||"#ec0000",n=e.map(d=>[d.open,d.close,d.low,d.high]);if(i&&i>n.length){const d=i-n.length;for(let l=0;l<d;l++)n.push(null)}let p;if(t.lastPriceLine?.visible!==!1&&e.length>0){const d=e[e.length-1],l=d.close,k=d.close>=d.open,y=t.lastPriceLine?.color||(k?s:o);let m=t.lastPriceLine?.lineStyle||"dashed";m.startsWith("linestyle_")&&(m=m.replace("linestyle_","")),p={symbol:["none","none"],data:[{yAxis:l,label:{show:!0,position:"end",formatter:I=>{if(t.yAxisLabelFormatter)return t.yAxisLabelFormatter(I.value);const u=t.yAxisDecimalPlaces!==void 0?t.yAxisDecimalPlaces:2;return typeof I.value=="number"?I.value.toFixed(u):I.value},color:"#fff",backgroundColor:y,padding:[2,4],borderRadius:2,fontSize:11,fontWeight:"bold"},lineStyle:{color:y,type:m,width:1,opacity:.8}}],animation:!1,silent:!0}}return{type:"candlestick",name:t.title||"Market",data:n,itemStyle:{color:s,color0:o,borderColor:s,borderColor0:o},markLine:p,xAxisIndex:0,yAxisIndex:0,z:5}}static getShapeSymbol(e){switch(e){case"arrowdown":return"path://M12 24l-12-12h8v-12h8v12h8z";case"arrowup":return"path://M12 0l12 12h-8v12h-8v-12h-8z";case"circle":return"circle";case"cross":return"path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z";case"diamond":return"diamond";case"flag":return"path://M6 2v20h2v-8h12l-2-6 2-6h-12z";case"labeldown":return"path://M4 2h16a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-6l-2 4l-2 -4h-6a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2z";case"labelup":return"path://M12 2l2 4h6a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-16a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h6z";case"square":return"rect";case"triangledown":return"path://M12 21l-10-18h20z";case"triangleup":return"triangle";case"xcross":return"path://M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z";default:return"circle"}}static getShapeRotation(e){return 0}static getShapeSize(e,t,i){if(t!==void 0&&i!==void 0)return[t,i];let s;switch(e){case"tiny":s=8;break;case"small":s=12;break;case"normal":case"auto":s=16;break;case"large":s=24;break;case"huge":s=32;break;default:s=16}return t!==void 0?[t,t]:i!==void 0?[i,i]:s}static getLabelConfig(e,t){switch(t){case"abovebar":return{position:"top",distance:5};case"belowbar":return{position:"bottom",distance:5};case"top":return{position:"bottom",distance:5};case"bottom":return{position:"top",distance:5};case"absolute":default:return e==="labelup"||e==="labeldown"?{position:"inside",distance:0}:{position:"top",distance:5}}}static buildIndicatorSeries(e,t,i,s,o=0,n,p,d=1){const l=[],k=new Array(s).fill(null);return e.forEach((y,m)=>{y.collapsed||Object.keys(y.plots).forEach(I=>{const u=y.plots[I],f=`${m}::${I}`;let v=0,E=0;const V=u.options.overlay;if(V!==void 0?V:y.paneIndex===0)v=0,p&&p.has(f)?E=p.get(f):E=0;else{const w=i.findIndex(T=>T.index===y.paneIndex);w!==-1&&(v=w+1,E=d+w)}const Z=new Array(s).fill(null),x=new Array(s).fill(null),A=new Array(s).fill(null);switch(u.data.forEach(w=>{const T=t.get(w.time);if(T!==void 0){const S=w.options?.offset??u.options.offset??0,c=T+o+S;if(c>=0&&c<s){let a=w.value;const g=w.options?.color;(g===null||g==="na"||g==="NaN"||typeof g=="number"&&isNaN(g))&&(a=null),Z[c]=a,x[c]=g||u.options.color,A[c]=w.options||{}}}}),u.options?.style?.startsWith("style_")&&(u.options.style=u.options.style.replace("style_","")),u.options.style){case"histogram":case"columns":l.push({name:f,type:"bar",xAxisIndex:v,yAxisIndex:E,data:Z.map((c,a)=>({value:c,itemStyle:x[a]?{color:x[a]}:void 0})),itemStyle:{color:u.options.color}});break;case"circles":case"cross":const w=Z.map((c,a)=>{if(c===null)return null;const g=x[a]||u.options.color,b={value:[a,c],itemStyle:{color:g}};return u.options.style==="cross"?(b.symbol=`image://${vt("+",g,"24px")}`,b.symbolSize=16):(b.symbol="circle",b.symbolSize=6),b}).filter(c=>c!==null);l.push({name:f,type:"scatter",xAxisIndex:v,yAxisIndex:E,data:w});break;case"bar":case"candle":const T=Z.map((c,a)=>{if(c===null||!Array.isArray(c)||c.length!==4)return null;const[g,b,P,F]=c,z=A[a]||{},G=z.color||x[a]||u.options.color,N=z.wickcolor||u.options.wickcolor||G,H=z.bordercolor||u.options.bordercolor||N;return[a,g,F,P,b,G,N,H]}).filter(c=>c!==null);l.push({name:f,type:"custom",xAxisIndex:v,yAxisIndex:E,renderItem:(c,a)=>{const g=a.value(0),b=a.value(1),P=a.value(2),F=a.value(3),z=a.value(4),G=a.value(5),N=a.value(6),H=a.value(7);if(isNaN(b)||isNaN(P)||isNaN(F)||isNaN(z))return null;const X=a.coord([g,0])[0],K=a.coord([g,b])[1],Y=a.coord([g,P])[1],h=a.coord([g,F])[1],C=a.coord([g,z])[1],M=a.size([1,0])[0]*.6;if(u.options.style==="candle"){const $=Math.min(K,Y),R=Math.max(K,Y),D=Math.abs(Y-K);return{type:"group",children:[{type:"line",shape:{x1:X,y1:C,x2:X,y2:$},style:{stroke:N,lineWidth:1}},{type:"line",shape:{x1:X,y1:R,x2:X,y2:h},style:{stroke:N,lineWidth:1}},{type:"rect",shape:{x:X-M/2,y:$,width:M,height:D||1},style:{fill:G,stroke:H,lineWidth:1}}]}}else{const $=M*.5;return{type:"group",children:[{type:"line",shape:{x1:X,y1:h,x2:X,y2:C},style:{stroke:G,lineWidth:1}},{type:"line",shape:{x1:X-$,y1:K,x2:X,y2:K},style:{stroke:G,lineWidth:1}},{type:"line",shape:{x1:X,y1:Y,x2:X+$,y2:Y},style:{stroke:G,lineWidth:1}}]}}},data:T});break;case"shape":const S=Z.map((c,a)=>{const g=A[a]||{},b=u.options,P=g.location||b.location||"absolute";if(P!=="absolute"&&!c||c==null)return null;const F=g.color||b.color||"blue",z=g.shape||b.shape||"circle",G=g.size||b.size||"normal",N=g.text||b.text,H=g.textcolor||b.textcolor||"white",X=g.width||b.width,K=g.height||b.height;let Y=c,h=[0,0];P==="abovebar"?(n&&n[a]&&(Y=n[a].high),h=[0,"-150%"]):P==="belowbar"?(n&&n[a]&&(Y=n[a].low),h=[0,"150%"]):P==="top"?(Y=c,h=[0,0]):P==="bottom"&&(Y=c,h=[0,0]);const C=it.getShapeSymbol(z),M=it.getShapeSize(G,X,K),$=it.getShapeRotation(z);let R=M;z.includes("label")&&(Array.isArray(M)?R=[M[0]*2.5,M[1]*2.5]:R=M*2.5);const D=it.getLabelConfig(z,P);return{value:[a,Y],symbol:C,symbolSize:R,symbolRotate:$,symbolOffset:h,itemStyle:{color:F},label:{show:!!N,position:D.position,distance:D.distance,formatter:N,color:H,fontSize:10,fontWeight:"bold"}}}).filter(c=>c!==null);l.push({name:f,type:"scatter",xAxisIndex:v,yAxisIndex:E,data:S});break;case"background":l.push({name:f,type:"custom",xAxisIndex:v,yAxisIndex:E,z:-10,renderItem:(c,a)=>{const g=a.value(0);if(isNaN(g))return;const b=a.coord([g,0]),P=a.size([1,0])[0],F=c.coordSys,z=b[0]-P/2,G=x[c.dataIndex],N=a.value(1);if(!(!G||N===null||N===void 0||isNaN(N)))return{type:"rect",shape:{x:z,y:F.y,width:P,height:F.height},style:{fill:G,opacity:.3},silent:!0}},data:Z.map((c,a)=>[a,c])});break;case"step":l.push({name:f,type:"custom",xAxisIndex:v,yAxisIndex:E,renderItem:(c,a)=>{const g=a.value(0),b=a.value(1);if(isNaN(b)||b===null)return;const P=a.coord([g,b]),F=a.size([1,0])[0];return{type:"line",shape:{x1:P[0]-F/2,y1:P[1],x2:P[0]+F/2,y2:P[1]},style:{stroke:x[c.dataIndex]||u.options.color,lineWidth:u.options.linewidth||1},silent:!0}},data:Z.map((c,a)=>[a,c])});break;case"barcolor":u.data.forEach(c=>{const a=t.get(c.time);if(a!==void 0){const g=c.options?.offset??u.options.offset??0,b=a+o+g;if(b>=0&&b<s){const P=c.options?.color||u.options.color;!(P===null||P==="na"||P==="NaN"||typeof P=="number"&&isNaN(P))&&c.value!==null&&c.value!==void 0&&(k[b]=P)}}});break;case"char":l.push({name:f,type:"scatter",xAxisIndex:v,yAxisIndex:E,symbolSize:0,data:Z.map((c,a)=>({value:[a,c],itemStyle:{opacity:0}})),silent:!0});break;case"line":default:l.push({name:f,type:"custom",xAxisIndex:v,yAxisIndex:E,renderItem:(c,a)=>{const g=c.dataIndex;if(g===0)return;const b=a.value(1),P=a.value(2);if(b===null||isNaN(b)||P===null||isNaN(P))return;const F=a.coord([g-1,P]),z=a.coord([g,b]);return{type:"line",shape:{x1:F[0],y1:F[1],x2:z[0],y2:z[1]},style:{stroke:x[g]||u.options.color,lineWidth:u.options.linewidth||1},silent:!0}},data:Z.map((c,a)=>[a,c,a>0?Z[a-1]:null])});break}})}),{series:l,barColors:k}}}class wt{static build(e,t,i,s=!1,o=null){const n=[],p=e.pixelToPercent,d=e.mainPaneTop;if(!o||o==="main"){const l=10*p;if(n.push({type:"text",left:"8.5%",top:d+l+"%",z:10,style:{text:t.title||"Market",fill:t.titleColor||"#fff",font:`bold 16px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),t.watermark!==!1){const y=e.mainPaneTop+e.mainPaneHeight;n.push({type:"text",right:"11%",top:y-3+"%",z:10,style:{text:"QFChart",fill:t.fontColor||"#cbd5e1",font:"bold 16px sans-serif",opacity:.1},cursor:"pointer",onclick:()=>{window.open("https://quantforge.org","_blank")}})}const k=[];if(t.controls?.collapse&&k.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","collapse")},{type:"text",style:{text:s?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),t.controls?.maximize){const y=o==="main",m=t.controls?.collapse?25:0;k.push({type:"group",x:m,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","maximize")},{type:"text",style:{text:y?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(t.controls?.fullscreen){let y=0;t.controls?.collapse&&(y+=25),t.controls?.maximize&&(y+=25),k.push({type:"group",x:y,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","fullscreen")},{type:"text",style:{text:"\u26F6",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}k.length>0&&n.push({type:"group",right:"10.5%",top:d+"%",children:k})}return e.paneLayout.forEach(l=>{if(o&&l.indicatorId!==o)return;n.push({type:"text",left:"8.5%",top:l.top+10*p+"%",z:10,style:{text:l.indicatorId||"",fill:l.titleColor||"#fff",font:`bold 12px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const k=[];if(l.controls?.collapse&&k.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>l.indicatorId&&i(l.indicatorId,"collapse")},{type:"text",style:{text:l.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),l.controls?.maximize){const y=o===l.indicatorId,m=l.controls?.collapse?25:0;k.push({type:"group",x:m,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>l.indicatorId&&i(l.indicatorId,"maximize")},{type:"text",style:{text:y?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}k.length>0&&n.push({type:"group",right:"10.5%",top:l.top+"%",children:k})}),n}}class Ct{static format(e,t){if(!e||e.length===0)return"";const i=t.title||"Market",s=t.upColor||"#00da3c",o=t.downColor||"#ec0000",n=t.fontFamily||"sans-serif",p=e[0].axisValue;let d=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${n};">${p}</div>`;const l=e.find(y=>y.seriesType==="candlestick"),k=e.filter(y=>y.seriesType!=="candlestick");if(l){const[y,m,I,u,f]=l.value,v=I>=m?s:o;d+=`
17
+ (function(ot,lt){typeof exports=="object"&&typeof module<"u"?lt(exports,require("echarts")):typeof define=="function"&&define.amd?define(["exports","echarts"],lt):(ot=typeof globalThis<"u"?globalThis:ot||self,lt(ot.QFChart={},ot.echarts))})(this,function(ot,lt){"use strict";function mt(r){var e=Object.create(null);return r&&Object.keys(r).forEach(function(t){if(t!=="default"){var i=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:function(){return r[t]}})}}),e.default=r,Object.freeze(e)}var j=mt(lt),bt=Object.defineProperty,vt=(r,e,t)=>e in r?bt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,at=(r,e,t)=>(vt(r,typeof e!="symbol"?e+"":e,t),t);class wt{constructor(e,t,i,s={}){at(this,"id"),at(this,"plots"),at(this,"paneIndex"),at(this,"height"),at(this,"collapsed"),at(this,"titleColor"),at(this,"controls"),this.id=e,this.plots=t,this.paneIndex=i,this.height=s.height,this.collapsed=s.collapsed||!1,this.titleColor=s.titleColor,this.controls=s.controls}toggleCollapse(){this.collapsed=!this.collapsed}isVisible(){return!this.collapsed}updateData(e){Object.keys(e).forEach(t=>{if(!this.plots[t])this.plots[t]=e[t];else{const i=this.plots[t],s=e[t];if(!i.data)return;s.options&&(i.options={...i.options,...s.options});const o=new Map;i.data?.forEach(n=>{o.set(n.time,n)}),s.data?.forEach(n=>{o.set(n.time,n)}),i.data=Array.from(o.values()).sort((n,u)=>n.time-u.time)}})}}class gt{static calculate(e,t,i,s=!1,o=null,n){let u=0;e>0&&(u=1/e*100);const p=i.yAxisPadding!==void 0?i.yAxisPadding:5,h=l=>f=>{const P=(f.max-f.min)*(l/100);return f.min-P},S=l=>f=>{const P=(f.max-f.min)*(l/100);return f.max+P},x=Array.from(t.values()).map(l=>l.paneIndex).filter(l=>l>0).sort((l,f)=>l-f).filter((l,f,P)=>P.indexOf(l)===f),y=x.length>0,A=i.dataZoom?.visible??!0,v=i.dataZoom?.position??"top",d=i.dataZoom?.height??6,m=i.dataZoom?.start??0,M=i.dataZoom?.end??100;let $=8,q=92,g=-1;if(o)if(o==="main")g=0;else{const l=t.get(o);l&&(g=l.paneIndex)}if(g!==-1){const l=[],f=[],P=[],T=[],H=i.dataZoom?.start??50,C=i.dataZoom?.end??100;(i.dataZoom?.zoomOnTouch??!0)&&T.push({type:"inside",xAxisIndex:"all",start:H,end:C});const N=y?Math.max(...x):0,L=[];for(let F=0;F<=N;F++){const G=F===g;l.push({left:"10%",right:"10%",top:G?"5%":"0%",height:G?"90%":"0%",show:G,containLabel:!1}),f.push({type:"category",gridIndex:F,data:[],show:G,axisLabel:{show:G,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:G,lineStyle:{color:"#334155"}},splitLine:{show:G,lineStyle:{color:"#334155",opacity:.5}}});let R,V;if(F===0&&g===0?(R=i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?i.yAxisMin:h(p),V=i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?i.yAxisMax:S(p)):(R=h(p),V=S(p)),P.push({position:"right",gridIndex:F,show:G,scale:!0,min:R,max:V,axisLabel:{show:G,color:"#94a3b8",fontFamily:i.fontFamily,formatter:Y=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(Y);const K=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:2;return typeof Y=="number"?Y.toFixed(K):String(Y)}},splitLine:{show:G,lineStyle:{color:"#334155",opacity:.5}}}),F>0){const Y=Array.from(t.values()).find(K=>K.paneIndex===F);Y&&L.push({index:F,height:G?90:0,top:G?5:0,isCollapsed:!1,indicatorId:Y.id,titleColor:Y.titleColor,controls:Y.controls})}}return{grid:l,xAxis:f,yAxis:P,dataZoom:T,paneLayout:L,mainPaneHeight:g===0?90:0,mainPaneTop:g===0?5:0,pixelToPercent:u,overlayYAxisMap:new Map,separatePaneYAxisOffset:1}}A?v==="top"?($=d+4,q=95):(q=100-d-2,$=8):($=5,q=95);let I=5;e>0&&(I=20/e*100);let E=75,z=[];if(y){const l=x.map(C=>{const N=Array.from(t.values()).find(L=>L.paneIndex===C);return{index:C,requestedHeight:N?.height,isCollapsed:N?.collapsed??!1,indicatorId:N?.id,titleColor:N?.titleColor,controls:N?.controls}}).map(C=>({...C,height:C.isCollapsed?3:C.requestedHeight!==void 0?C.requestedHeight:15})),f=l.reduce((C,N)=>C+N.height,0),P=l.length*I,T=f+P;E=q-$-T,s?E=3:E<20&&(E=Math.max(E,10));let H=$+E+I;z=l.map(C=>{const N={index:C.index,height:C.height,top:H,isCollapsed:C.isCollapsed,indicatorId:C.indicatorId,titleColor:C.titleColor,controls:C.controls};return H+=C.height+I,N})}else E=q-$,s&&(E=3);const D=[];D.push({left:"10%",right:"10%",top:$+"%",height:E+"%",containLabel:!1}),z.forEach(l=>{D.push({left:"10%",right:"10%",top:l.top+"%",height:l.height+"%",containLabel:!1})});const B=[0,...z.map((l,f)=>f+1)],W=[],X=z.length===0;W.push({type:"category",data:[],gridIndex:0,scale:!0,axisLine:{onZero:!1,show:!s,lineStyle:{color:"#334155"}},splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:l=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(l);const f=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:2;return typeof l=="number"?l.toFixed(f):String(l)}},axisTick:{show:!s},axisPointer:{label:{show:X,fontSize:11,backgroundColor:"#475569"}}}),z.forEach((l,f)=>{const P=f===z.length-1;W.push({type:"category",gridIndex:f+1,data:[],axisLabel:{show:!1},axisLine:{show:!l.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:P,fontSize:11,backgroundColor:"#475569"}}})});const Z=[];let _,st;i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?_=i.yAxisMin:_=h(p),i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?st=i.yAxisMax:st=S(p),Z.push({position:"right",scale:!0,min:_,max:st,gridIndex:0,splitLine:{show:!s,lineStyle:{color:"#334155",opacity:.5}},axisLine:{show:!s,lineStyle:{color:"#334155"}},axisLabel:{show:!s,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",formatter:l=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(l);const f=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:2;return typeof l=="number"?l.toFixed(f):String(l)}}});let Q=1,it=-1/0,c=1/0;n&&n.length>0&&(it=Math.min(...n.map(l=>l.low)),c=Math.max(...n.map(l=>l.high)));const a=new Map;t.forEach((l,f)=>{l.paneIndex===0&&!l.collapsed&&n&&n.length>0&&Object.entries(l.plots).forEach(([P,T])=>{const H=`${f}::${P}`,C=["background","barcolor","char"],N=T.options.style==="shape"&&(T.options.location==="abovebar"||T.options.location==="belowbar");if(C.includes(T.options.style)){a.has(H)||(a.set(H,Q),Q++);return}if(T.options.style==="shape"&&!N){a.has(H)||(a.set(H,Q),Q++);return}const L=[];if(T.data&&Object.values(T.data).forEach(F=>{typeof F=="number"&&!isNaN(F)&&isFinite(F)&&L.push(F)}),L.length>0){const F=Math.min(...L),G=Math.max(...L),R=G-F,V=c-it,Y=F>=it*.5&&G<=c*1.5,K=R>V*.01;Y&&K||a.has(H)||(a.set(H,Q),Q++)}})});const w=a.size>0?Q-1:0;for(let l=0;l<w;l++)Z.push({position:"left",scale:!0,min:h(p),max:S(p),gridIndex:0,show:!1,splitLine:{show:!1},axisLine:{show:!1},axisLabel:{show:!1}});const k=Q;z.forEach((l,f)=>{Z.push({position:"right",scale:!0,min:h(p),max:S(p),gridIndex:f+1,splitLine:{show:!l.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!l.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10,formatter:P=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(P);const T=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:2;return typeof P=="number"?P.toFixed(T):String(P)}},axisLine:{show:!l.isCollapsed,lineStyle:{color:"#334155"}}})});const b=[];return A&&((i.dataZoom?.zoomOnTouch??!0)&&b.push({type:"inside",xAxisIndex:B,start:m,end:M}),v==="top"?b.push({type:"slider",xAxisIndex:B,top:"1%",height:d+"%",start:m,end:M,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1}):b.push({type:"slider",xAxisIndex:B,bottom:"1%",height:d+"%",start:m,end:M,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1})),{grid:D,xAxis:W,yAxis:Z,dataZoom:b,paneLayout:z,mainPaneHeight:E,mainPaneTop:$,pixelToPercent:u,overlayYAxisMap:a,separatePaneYAxisOffset:k}}static calculateMaximized(e,t,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}const ut=new Map;function Ct(r,e="#00da3c",t="64px"){if(typeof document>"u")return"";const i=`${r}-${e}-${t}`;if(ut.has(i))return ut.get(i);const s=document.createElement("canvas"),o=s.getContext("2d");if(s.width=32,s.height=32,o){o.font="bold "+t+" Arial",o.fillStyle=e,o.textAlign="center",o.textBaseline="middle",o.fillText(r,16,16);const n=s.toDataURL("image/png");return ut.set(i,n),n}return""}var kt=Object.defineProperty,St=(r,e,t)=>e in r?kt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,It=(r,e,t)=>(St(r,typeof e!="symbol"?e+"":e,t),t);const xt=class tt{static parseColor(e){if(!e)return{color:"#888888",opacity:.2};const t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(t){const i=t[1],s=t[2],o=t[3],n=t[4]?parseFloat(t[4]):1;return{color:`rgb(${i},${s},${o})`,opacity:n}}return{color:e,opacity:.3}}static buildCandlestickSeries(e,t,i){const s=t.upColor||"#00da3c",o=t.downColor||"#ec0000",n=e.map(p=>[p.open,p.close,p.low,p.high]);if(i&&i>n.length){const p=i-n.length;for(let h=0;h<p;h++)n.push(null)}let u;if(t.lastPriceLine?.visible!==!1&&e.length>0){const p=e[e.length-1],h=p.close,S=p.close>=p.open,x=t.lastPriceLine?.color||(S?s:o);let y=t.lastPriceLine?.lineStyle||"dashed";y.startsWith("linestyle_")&&(y=y.replace("linestyle_","")),u={symbol:["none","none"],data:[{yAxis:h,label:{show:!0,position:"end",formatter:A=>{if(t.yAxisLabelFormatter)return t.yAxisLabelFormatter(A.value);const v=t.yAxisDecimalPlaces!==void 0?t.yAxisDecimalPlaces:2;return typeof A.value=="number"?A.value.toFixed(v):A.value},color:"#fff",backgroundColor:x,padding:[2,4],borderRadius:2,fontSize:11,fontWeight:"bold"},lineStyle:{color:x,type:y,width:1,opacity:.8}}],animation:!1,silent:!0}}return{type:"candlestick",name:t.title||"Market",data:n,itemStyle:{color:s,color0:o,borderColor:s,borderColor0:o},markLine:u,xAxisIndex:0,yAxisIndex:0,z:5}}static getShapeSymbol(e){switch(e){case"arrowdown":return"path://M12 24l-12-12h8v-12h8v12h8z";case"arrowup":return"path://M12 0l12 12h-8v12h-8v-12h-8z";case"circle":return"circle";case"cross":return"path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z";case"diamond":return"diamond";case"flag":return"path://M6 2v20h2v-8h12l-2-6 2-6h-12z";case"labeldown":return"path://M4 2h16a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-6l-2 4l-2 -4h-6a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2z";case"labelup":return"path://M12 2l2 4h6a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-16a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h6z";case"square":return"rect";case"triangledown":return"path://M12 21l-10-18h20z";case"triangleup":return"triangle";case"xcross":return"path://M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z";default:return"circle"}}static getShapeRotation(e){return 0}static getShapeSize(e,t,i){if(t!==void 0&&i!==void 0)return[t,i];let s;switch(e){case"tiny":s=8;break;case"small":s=12;break;case"normal":case"auto":s=16;break;case"large":s=24;break;case"huge":s=32;break;default:s=16}return t!==void 0?[t,t]:i!==void 0?[i,i]:s}static getLabelConfig(e,t){switch(t){case"abovebar":return{position:"top",distance:5};case"belowbar":return{position:"bottom",distance:5};case"top":return{position:"bottom",distance:5};case"bottom":return{position:"top",distance:5};case"absolute":default:return e==="labelup"||e==="labeldown"?{position:"inside",distance:0}:{position:"top",distance:5}}}static buildIndicatorSeries(e,t,i,s,o=0,n,u,p=1){const h=[],S=new Array(s).fill(null),x=new Map;return e.forEach((y,A)=>{y.collapsed||Object.keys(y.plots).sort((v,d)=>{const m=y.plots[v],M=y.plots[d],$=m.options.style==="fill",q=M.options.style==="fill";return $&&!q?1:!$&&q?-1:0}).forEach(v=>{const d=y.plots[v],m=`${A}::${v}`;let M=0,$=0;const q=d.options.overlay;if(q!==void 0?q:y.paneIndex===0)M=0,u&&u.has(m)?$=u.get(m):$=0;else{const z=i.findIndex(D=>D.index===y.paneIndex);z!==-1&&(M=z+1,$=p+z)}const g=new Array(s).fill(null),I=new Array(s).fill(null),E=new Array(s).fill(null);switch(d.data?.forEach(z=>{const D=t.get(z.time);if(D!==void 0){const B=z.options?.offset??d.options.offset??0,W=D+o+B;if(W>=0&&W<s){let X=z.value;const Z=z.options?.color;(Z===null||Z==="na"||Z==="NaN"||typeof Z=="number"&&isNaN(Z))&&(X=null),g[W]=X,I[W]=Z||d.options.color||tt.DEFAULT_COLOR,E[W]=z.options||{}}}}),x.set(`${A}::${v}`,g),d.options?.style?.startsWith("style_")&&(d.options.style=d.options.style.replace("style_","")),d.options.style){case"histogram":case"columns":h.push({name:m,type:"bar",xAxisIndex:M,yAxisIndex:$,data:g.map((c,a)=>({value:c,itemStyle:I[a]?{color:I[a]}:void 0})),itemStyle:{color:d.options.color||tt.DEFAULT_COLOR}});break;case"circles":case"cross":const z=g.map((c,a)=>{if(c===null)return null;const w=I[a]||d.options.color||tt.DEFAULT_COLOR,k={value:[a,c],itemStyle:{color:w}};return d.options.style==="cross"?(k.symbol=`image://${Ct("+",w,"24px")}`,k.symbolSize=16):(k.symbol="circle",k.symbolSize=6),k}).filter(c=>c!==null);h.push({name:m,type:"scatter",xAxisIndex:M,yAxisIndex:$,data:z});break;case"bar":case"candle":const D=g.map((c,a)=>{if(c===null||!Array.isArray(c)||c.length!==4)return null;const[w,k,b,l]=c,f=E[a]||{},P=f.color||I[a]||d.options.color||tt.DEFAULT_COLOR,T=f.wickcolor||d.options.wickcolor||P,H=f.bordercolor||d.options.bordercolor||T;return[a,w,l,b,k,P,T,H]}).filter(c=>c!==null);h.push({name:m,type:"custom",xAxisIndex:M,yAxisIndex:$,renderItem:(c,a)=>{const w=a.value(0),k=a.value(1),b=a.value(2),l=a.value(3),f=a.value(4),P=a.value(5),T=a.value(6),H=a.value(7);if(isNaN(k)||isNaN(b)||isNaN(l)||isNaN(f))return null;const C=a.coord([w,0])[0],N=a.coord([w,k])[1],L=a.coord([w,b])[1],F=a.coord([w,l])[1],G=a.coord([w,f])[1],R=a.size([1,0])[0]*.6;if(d.options.style==="candle"){const V=Math.min(N,L),Y=Math.max(N,L),K=Math.abs(L-N);return{type:"group",children:[{type:"line",shape:{x1:C,y1:G,x2:C,y2:V},style:{stroke:T,lineWidth:1}},{type:"line",shape:{x1:C,y1:Y,x2:C,y2:F},style:{stroke:T,lineWidth:1}},{type:"rect",shape:{x:C-R/2,y:V,width:R,height:K||1},style:{fill:P,stroke:H,lineWidth:1}}]}}else{const V=R*.5;return{type:"group",children:[{type:"line",shape:{x1:C,y1:F,x2:C,y2:G},style:{stroke:P,lineWidth:1}},{type:"line",shape:{x1:C-V,y1:N,x2:C,y2:N},style:{stroke:P,lineWidth:1}},{type:"line",shape:{x1:C,y1:L,x2:C+V,y2:L},style:{stroke:P,lineWidth:1}}]}}},data:D});break;case"shape":const B=g.map((c,a)=>{const w=E[a]||{},k=d.options,b=w.location||k.location||"absolute";if(b!=="absolute"&&!c||c==null)return null;const l=w.color||k.color||tt.DEFAULT_COLOR,f=w.shape||k.shape||"circle",P=w.size||k.size||"normal",T=w.text||k.text,H=w.textcolor||k.textcolor||"white",C=w.width||k.width,N=w.height||k.height;let L=c,F=[0,0];b==="abovebar"?(n&&n[a]&&(L=n[a].high),F=[0,"-150%"]):b==="belowbar"?(n&&n[a]&&(L=n[a].low),F=[0,"150%"]):b==="top"?(L=c,F=[0,0]):b==="bottom"&&(L=c,F=[0,0]);const G=tt.getShapeSymbol(f),R=tt.getShapeSize(P,C,N),V=tt.getShapeRotation(f);let Y=R;f.includes("label")&&(Array.isArray(R)?Y=[R[0]*2.5,R[1]*2.5]:Y=R*2.5);const K=tt.getLabelConfig(f,b);return{value:[a,L],symbol:G,symbolSize:Y,symbolRotate:V,symbolOffset:F,itemStyle:{color:l},label:{show:!!T,position:K.position,distance:K.distance,formatter:T,color:H,fontSize:10,fontWeight:"bold"}}}).filter(c=>c!==null);h.push({name:m,type:"scatter",xAxisIndex:M,yAxisIndex:$,data:B});break;case"background":h.push({name:m,type:"custom",xAxisIndex:M,yAxisIndex:$,z:-10,renderItem:(c,a)=>{const w=a.value(0);if(isNaN(w))return;const k=a.coord([w,0]),b=a.size([1,0])[0],l=c.coordSys,f=k[0]-b/2,P=I[c.dataIndex],T=a.value(1);if(!(!P||T===null||T===void 0||isNaN(T)))return{type:"rect",shape:{x:f,y:l.y,width:b,height:l.height},style:{fill:P,opacity:.3},silent:!0}},data:g.map((c,a)=>[a,c])});break;case"step":h.push({name:m,type:"custom",xAxisIndex:M,yAxisIndex:$,renderItem:(c,a)=>{const w=a.value(0),k=a.value(1);if(isNaN(k)||k===null)return;const b=a.coord([w,k]),l=a.size([1,0])[0];return{type:"line",shape:{x1:b[0]-l/2,y1:b[1],x2:b[0]+l/2,y2:b[1]},style:{stroke:I[c.dataIndex]||d.options.color||tt.DEFAULT_COLOR,lineWidth:d.options.linewidth||1},silent:!0}},data:g.map((c,a)=>[a,c])});break;case"barcolor":d.data?.forEach(c=>{const a=t.get(c.time);if(a!==void 0){const w=c.options?.offset??d.options.offset??0,k=a+o+w;if(k>=0&&k<s){const b=c.options?.color||d.options.color||tt.DEFAULT_COLOR;!(b===null||b==="na"||b==="NaN"||typeof b=="number"&&isNaN(b))&&c.value!==null&&c.value!==void 0&&(S[k]=b)}}});break;case"char":h.push({name:m,type:"scatter",xAxisIndex:M,yAxisIndex:$,symbolSize:0,data:g.map((c,a)=>({value:[a,c],itemStyle:{opacity:0}})),silent:!0});break;case"fill":const W=d.plot1?`${A}::${d.plot1}`:null,X=d.plot2?`${A}::${d.plot2}`:null;if(!W||!X){console.warn(`Fill plot "${v}" missing plot1 or plot2 reference`);break}const Z=x.get(W),_=x.get(X);if(!Z||!_){console.warn(`Fill plot "${v}" references non-existent plots: ${d.plot1}, ${d.plot2}`);break}const{color:st,opacity:Q}=tt.parseColor(d.options.color||"rgba(128, 128, 128, 0.2)"),it=[];for(let c=0;c<s;c++){const a=Z[c],w=_[c],k=c>0?Z[c-1]:null,b=c>0?_[c-1]:null;it.push([c,a,w,k,b])}h.push({name:m,type:"custom",xAxisIndex:M,yAxisIndex:$,z:-5,renderItem:(c,a)=>{const w=c.dataIndex;if(w===0)return null;const k=a.value(1),b=a.value(2),l=a.value(3),f=a.value(4);if(k===null||b===null||l===null||f===null||isNaN(k)||isNaN(b)||isNaN(l)||isNaN(f))return null;const P=a.coord([w-1,l]),T=a.coord([w,k]),H=a.coord([w,b]),C=a.coord([w-1,f]);return{type:"polygon",shape:{points:[P,T,H,C]},style:{fill:st,opacity:Q},silent:!0}},data:it});break;case"line":default:h.push({name:m,type:"custom",xAxisIndex:M,yAxisIndex:$,renderItem:(c,a)=>{const w=c.dataIndex;if(w===0)return;const k=a.value(1),b=a.value(2);if(k===null||isNaN(k)||b===null||isNaN(b))return;const l=a.coord([w-1,b]),f=a.coord([w,k]);return{type:"line",shape:{x1:l[0],y1:l[1],x2:f[0],y2:f[1]},style:{stroke:I[w]||d.options.color||tt.DEFAULT_COLOR,lineWidth:d.options.linewidth||1},silent:!0}},data:g.map((c,a)=>[a,c,a>0?g[a-1]:null])});break}})}),{series:h,barColors:S}}};It(xt,"DEFAULT_COLOR","#2962ff");let ct=xt;class Pt{static build(e,t,i,s=!1,o=null){const n=[],u=e.pixelToPercent,p=e.mainPaneTop;if(!o||o==="main"){const h=10*u;if(n.push({type:"text",left:"8.5%",top:p+h+"%",z:10,style:{text:t.title||"Market",fill:t.titleColor||"#fff",font:`bold 16px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),t.watermark!==!1){const x=e.mainPaneTop+e.mainPaneHeight;n.push({type:"text",right:"11%",top:x-3+"%",z:10,style:{text:"QFChart",fill:t.fontColor||"#cbd5e1",font:"bold 16px sans-serif",opacity:.1},cursor:"pointer",onclick:()=>{window.open("https://quantforge.org","_blank")}})}const S=[];if(t.controls?.collapse&&S.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","collapse")},{type:"text",style:{text:s?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),t.controls?.maximize){const x=o==="main",y=t.controls?.collapse?25:0;S.push({type:"group",x:y,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","maximize")},{type:"text",style:{text:x?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(t.controls?.fullscreen){let x=0;t.controls?.collapse&&(x+=25),t.controls?.maximize&&(x+=25),S.push({type:"group",x,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>i("main","fullscreen")},{type:"text",style:{text:"\u26F6",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}S.length>0&&n.push({type:"group",right:"10.5%",top:p+"%",children:S})}return e.paneLayout.forEach(h=>{if(o&&h.indicatorId!==o)return;n.push({type:"text",left:"8.5%",top:h.top+10*u+"%",z:10,style:{text:h.indicatorId||"",fill:h.titleColor||"#fff",font:`bold 12px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const S=[];if(h.controls?.collapse&&S.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>h.indicatorId&&i(h.indicatorId,"collapse")},{type:"text",style:{text:h.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),h.controls?.maximize){const x=o===h.indicatorId,y=h.controls?.collapse?25:0;S.push({type:"group",x:y,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>h.indicatorId&&i(h.indicatorId,"maximize")},{type:"text",style:{text:x?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}S.length>0&&n.push({type:"group",right:"10.5%",top:h.top+"%",children:S})}),n}}class Dt{static format(e,t){if(!e||e.length===0)return"";const i=t.title||"Market",s=t.upColor||"#00da3c",o=t.downColor||"#ec0000",n=t.fontFamily||"sans-serif",u=e[0].axisValue;let p=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${n};">${u}</div>`;const h=e.find(x=>x.seriesType==="candlestick"),S=e.filter(x=>x.seriesType!=="candlestick");if(h){const[x,y,A,v,d]=h.value,m=A>=y?s:o;p+=`
18
18
  <div style="margin-bottom: 8px; font-family: ${n};">
19
- <div style="display:flex; justify-content:space-between; color:${v}; font-weight:bold;">
19
+ <div style="display:flex; justify-content:space-between; color:${m}; font-weight:bold;">
20
20
  <span>${i}</span>
21
21
  </div>
22
22
  <div style="display: grid; grid-template-columns: auto auto; gap: 2px 15px; font-size: 0.9em; color: #cbd5e1;">
23
- <span>Open:</span> <span style="text-align: right; color: ${I>=m?s:o}">${m}</span>
24
- <span>High:</span> <span style="text-align: right; color: ${s}">${f}</span>
25
- <span>Low:</span> <span style="text-align: right; color: ${o}">${u}</span>
26
- <span>Close:</span> <span style="text-align: right; color: ${I>=m?s:o}">${I}</span>
23
+ <span>Open:</span> <span style="text-align: right; color: ${A>=y?s:o}">${y}</span>
24
+ <span>High:</span> <span style="text-align: right; color: ${s}">${d}</span>
25
+ <span>Low:</span> <span style="text-align: right; color: ${o}">${v}</span>
26
+ <span>Close:</span> <span style="text-align: right; color: ${A>=y?s:o}">${A}</span>
27
27
  </div>
28
28
  </div>
29
- `}if(k.length>0){d+='<div style="border-top: 1px solid #334155; margin: 5px 0; padding-top: 5px;"></div>';const y={};k.forEach(m=>{const I=m.seriesName.split("::"),u=I.length>1?I[0]:"Unknown",f=I.length>1?I[1]:m.seriesName;y[u]||(y[u]=[]),y[u].push({...m,displayName:f})}),Object.keys(y).forEach(m=>{d+=`
29
+ `}if(S.length>0){p+='<div style="border-top: 1px solid #334155; margin: 5px 0; padding-top: 5px;"></div>';const x={};S.forEach(y=>{const A=y.seriesName.split("::"),v=A.length>1?A[0]:"Unknown",d=A.length>1?A[1]:y.seriesName;x[v]||(x[v]=[]),x[v].push({...y,displayName:d})}),Object.keys(x).forEach(y=>{p+=`
30
30
  <div style="margin-top: 8px; font-family: ${n};">
31
- <div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${m}</div>
32
- `,y[m].forEach(I=>{let u=I.value;if(Array.isArray(u)&&(u=u[1]),u==null)return;const f=typeof u=="number"?u.toLocaleString(void 0,{maximumFractionDigits:4}):u;d+=`
31
+ <div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${y}</div>
32
+ `,x[y].forEach(A=>{let v=A.value;if(Array.isArray(v)&&(v=v[1]),v==null)return;const d=typeof v=="number"?v.toLocaleString(void 0,{maximumFractionDigits:4}):v;p+=`
33
33
  <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; padding-left: 8px;">
34
- <div>${I.marker} <span style="color: #cbd5e1;">${I.displayName}</span></div>
35
- <div style="font-size: 10px; color: #fff;padding-left:10px;">${f}</div>
36
- </div>`}),d+="</div>"})}return d}}var kt=Object.defineProperty,Pt=(r,e,t)=>e in r?kt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,rt=(r,e,t)=>(Pt(r,typeof e!="symbol"?e+"":e,t),t);class It{constructor(e,t){rt(this,"plugins",new Map),rt(this,"activePluginId",null),rt(this,"context"),rt(this,"toolbarContainer"),rt(this,"tooltipElement",null),rt(this,"hideTimeout",null),this.context=e,this.toolbarContainer=t,this.createTooltip(),this.renderToolbar()}createTooltip(){this.tooltipElement=document.createElement("div"),Object.assign(this.tooltipElement.style,{position:"fixed",display:"none",backgroundColor:"#1e293b",color:"#e2e8f0",padding:"6px 10px",borderRadius:"6px",fontSize:"13px",lineHeight:"1.4",fontWeight:"500",border:"1px solid #334155",zIndex:"9999",pointerEvents:"none",whiteSpace:"nowrap",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.15)",fontFamily:this.context.getOptions().fontFamily||"sans-serif",transition:"opacity 0.15s ease-in-out, transform 0.15s ease-in-out",opacity:"0",transform:"translateX(-5px)"}),document.body.appendChild(this.tooltipElement)}destroy(){this.tooltipElement&&this.tooltipElement.parentNode&&this.tooltipElement.parentNode.removeChild(this.tooltipElement),this.tooltipElement=null}showTooltip(e,t){if(!this.tooltipElement)return;this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null);const i=e.getBoundingClientRect();this.tooltipElement.textContent=t,this.tooltipElement.style.display="block";const s=this.tooltipElement.getBoundingClientRect(),o=i.top+(i.height-s.height)/2,n=i.right+10;this.tooltipElement.style.top=`${o}px`,this.tooltipElement.style.left=`${n}px`,requestAnimationFrame(()=>{this.tooltipElement&&(this.tooltipElement.style.opacity="1",this.tooltipElement.style.transform="translateX(0)")})}hideTooltip(){this.tooltipElement&&(this.tooltipElement.style.opacity="0",this.tooltipElement.style.transform="translateX(-5px)",this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(()=>{this.tooltipElement&&(this.tooltipElement.style.display="none"),this.hideTimeout=null},150))}register(e){if(this.plugins.has(e.id)){console.warn(`Plugin with id ${e.id} is already registered.`);return}this.plugins.set(e.id,e),e.init(this.context),this.addButton(e)}unregister(e){const t=this.plugins.get(e);t&&(this.activePluginId===e&&this.deactivatePlugin(),t.destroy?.(),this.plugins.delete(e),this.removeButton(e))}activatePlugin(e){if(this.activePluginId===e){this.deactivatePlugin();return}this.activePluginId&&this.deactivatePlugin();const t=this.plugins.get(e);t&&(this.activePluginId=e,this.setButtonActive(e,!0),t.activate?.())}deactivatePlugin(){this.activePluginId&&(this.plugins.get(this.activePluginId)?.deactivate?.(),this.setButtonActive(this.activePluginId,!1),this.activePluginId=null)}renderToolbar(){this.toolbarContainer.innerHTML="",this.toolbarContainer.classList.add("qfchart-toolbar"),this.toolbarContainer.style.display="flex",this.toolbarContainer.style.flexDirection="column",this.toolbarContainer.style.width="40px",this.toolbarContainer.style.backgroundColor=this.context.getOptions().backgroundColor||"#1e293b",this.toolbarContainer.style.borderRight="1px solid #334155",this.toolbarContainer.style.padding="5px",this.toolbarContainer.style.boxSizing="border-box",this.toolbarContainer.style.gap="5px",this.toolbarContainer.style.flexShrink="0"}addButton(e){const t=document.createElement("button");t.id=`qfchart-plugin-btn-${e.id}`,t.style.width="30px",t.style.height="30px",t.style.padding="4px",t.style.border="1px solid transparent",t.style.borderRadius="4px",t.style.backgroundColor="transparent",t.style.cursor="pointer",t.style.color=this.context.getOptions().fontColor||"#cbd5e1",t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",e.icon?t.innerHTML=e.icon:t.innerText=(e.name||e.id).substring(0,2).toUpperCase(),t.addEventListener("mouseenter",()=>{this.activePluginId!==e.id&&(t.style.backgroundColor="rgba(255, 255, 255, 0.1)"),this.showTooltip(t,e.name||e.id)}),t.addEventListener("mouseleave",()=>{this.activePluginId!==e.id&&(t.style.backgroundColor="transparent"),this.hideTooltip()}),t.onclick=()=>this.activatePlugin(e.id),this.toolbarContainer.appendChild(t)}removeButton(e){const t=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${e}`);t&&t.remove()}setButtonActive(e,t){const i=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${e}`);i&&(t?(i.style.backgroundColor="#2563eb",i.style.color="#ffffff"):(i.style.backgroundColor="transparent",i.style.color=this.context.getOptions().fontColor||"#cbd5e1"))}}var St=Object.defineProperty,At=(r,e,t)=>e in r?St(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,U=(r,e,t)=>(At(r,typeof e!="symbol"?e+"":e,t),t);class Mt{constructor(e){U(this,"context"),U(this,"isEditing",!1),U(this,"currentDrawing",null),U(this,"editingPointIndex",null),U(this,"zr"),U(this,"editGroup",null),U(this,"editLine",null),U(this,"editStartPoint",null),U(this,"editEndPoint",null),U(this,"isMovingShape",!1),U(this,"dragStart",null),U(this,"initialPixelPoints",[]),U(this,"onDrawingMouseDown",t=>{if(this.isEditing)return;const i=this.context.getDrawing(t.id);i&&(this.isEditing=!0,this.isMovingShape=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.dragStart={x:t.x,y:t.y},this.initialPixelPoints=i.points.map(s=>{const o=this.context.coordinateConversion.dataToPixel(s);return o?{x:o.x,y:o.y}:{x:0,y:0}}),this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),U(this,"onPointMouseDown",t=>{if(this.isEditing)return;const i=this.context.getDrawing(t.id);i&&(this.isEditing=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.editingPointIndex=t.pointIndex,this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),U(this,"onMouseMove",t=>{if(!this.isEditing||!this.currentDrawing)return;const i=t.offsetX,s=t.offsetY;if(this.isMovingShape&&this.dragStart){const o=i-this.dragStart.x,n=s-this.dragStart.y,p={x:this.initialPixelPoints[0].x+o,y:this.initialPixelPoints[0].y+n},d={x:this.initialPixelPoints[1].x+o,y:this.initialPixelPoints[1].y+n};this.editLine.setShape({x1:p.x,y1:p.y,x2:d.x,y2:d.y}),this.editStartPoint.setShape({cx:p.x,cy:p.y}),this.editEndPoint.setShape({cx:d.x,cy:d.y})}else this.editingPointIndex!==null&&(this.editingPointIndex===0?(this.editLine.setShape({x1:i,y1:s}),this.editStartPoint.setShape({cx:i,cy:s})):(this.editLine.setShape({x2:i,y2:s}),this.editEndPoint.setShape({cx:i,cy:s})))}),U(this,"onMouseUp",t=>{this.isEditing&&this.finishEditing(t.offsetX,t.offsetY)}),this.context=e,this.zr=this.context.getChart().getZr(),this.bindEvents()}bindEvents(){this.context.events.on("drawing:point:mousedown",this.onPointMouseDown),this.context.events.on("drawing:mousedown",this.onDrawingMouseDown)}createEditGraphic(){if(!this.currentDrawing)return;this.editGroup=new j.graphic.Group;const e=this.currentDrawing.points[0],t=this.currentDrawing.points[1],i=this.context.coordinateConversion.dataToPixel(e),s=this.context.coordinateConversion.dataToPixel(t);!i||!s||(this.editLine=new j.graphic.Line({shape:{x1:i.x,y1:i.y,x2:s.x,y2:s.y},style:{stroke:this.currentDrawing.style?.color||"#3b82f6",lineWidth:this.currentDrawing.style?.lineWidth||2,lineDash:[4,4]},silent:!0}),this.editStartPoint=new j.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new j.graphic.Circle({shape:{cx:s.x,cy:s.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editGroup.add(this.editLine),this.editGroup.add(this.editStartPoint),this.editGroup.add(this.editEndPoint),this.zr.add(this.editGroup))}finishEditing(e,t){if(this.currentDrawing){if(this.isMovingShape&&this.dragStart){const i=e-this.dragStart.x,s=t-this.dragStart.y,o=this.initialPixelPoints.map((n,p)=>{const d=n.x+i,l=n.y+s;return this.context.coordinateConversion.pixelToData({x:d,y:l})});o.every(n=>n!==null)&&o[0]&&o[1]&&(this.currentDrawing.points[0]=o[0],this.currentDrawing.points[1]=o[1],o[0].paneIndex!==void 0&&(this.currentDrawing.paneIndex=o[0].paneIndex),this.context.updateDrawing(this.currentDrawing))}else if(this.editingPointIndex!==null){const i=this.context.coordinateConversion.pixelToData({x:e,y:t});i&&(this.currentDrawing.points[this.editingPointIndex]=i,this.editingPointIndex===0&&i.paneIndex!==void 0&&(this.currentDrawing.paneIndex=i.paneIndex),this.context.updateDrawing(this.currentDrawing))}this.isEditing=!1,this.isMovingShape=!1,this.dragStart=null,this.initialPixelPoints=[],this.currentDrawing=null,this.editingPointIndex=null,this.editGroup&&(this.zr.remove(this.editGroup),this.editGroup=null),this.zr.off("mousemove",this.onMouseMove),this.zr.off("mouseup",this.onMouseUp),this.context.unlockChart()}}}var Dt=Object.defineProperty,Et=(r,e,t)=>e in r?Dt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,zt=(r,e,t)=>(Et(r,typeof e!="symbol"?e+"":e,t),t);class Lt{constructor(){zt(this,"handlers",new Map)}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t)}off(e,t){const i=this.handlers.get(e);i&&i.delete(t)}emit(e,t){const i=this.handlers.get(e);i&&i.forEach(s=>{try{s(t)}catch(o){console.error(`Error in EventBus handler for ${e}:`,o)}})}clear(){this.handlers.clear()}}var Tt=Object.defineProperty,Ft=(r,e,t)=>e in r?Tt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,L=(r,e,t)=>(Ft(r,typeof e!="symbol"?e+"":e,t),t);class Nt{constructor(e,t={}){L(this,"chart"),L(this,"options"),L(this,"marketData",[]),L(this,"indicators",new Map),L(this,"timeToIndex",new Map),L(this,"pluginManager"),L(this,"drawingEditor"),L(this,"events",new Lt),L(this,"isMainCollapsed",!1),L(this,"maximizedPaneId",null),L(this,"countdownInterval",null),L(this,"selectedDrawingId",null),L(this,"drawings",[]),L(this,"coordinateConversion",{pixelToData:o=>{const n=this.chart.getOption();if(!n||!n.grid)return null;const p=n.grid.length;for(let d=0;d<p;d++)if(this.chart.containPixel({gridIndex:d},[o.x,o.y])){this.chart.convertFromPixel({seriesIndex:d},[o.x,o.y]);const l=this.chart.convertFromPixel({gridIndex:d},[o.x,o.y]);if(l)return{timeIndex:Math.round(l[0]),value:l[1],paneIndex:d}}return null},dataToPixel:o=>{const n=o.paneIndex||0,p=this.chart.convertToPixel({gridIndex:n},[o.timeIndex,o.value]);return p?{x:p[0],y:p[1]}:null}}),L(this,"upColor","#00da3c"),L(this,"downColor","#ec0000"),L(this,"defaultPadding",0),L(this,"padding"),L(this,"dataIndexOffset",0),L(this,"rootContainer"),L(this,"layoutContainer"),L(this,"toolbarContainer"),L(this,"leftSidebar"),L(this,"rightSidebar"),L(this,"chartContainer"),L(this,"onKeyDown",o=>{(o.key==="Delete"||o.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),L(this,"onFullscreenChange",()=>{this.render()}),L(this,"isLocked",!1),L(this,"lockedState",null),this.rootContainer=e,this.options={title:"Market",height:"600px",backgroundColor:"#1e293b",upColor:"#00da3c",downColor:"#ec0000",fontColor:"#cbd5e1",fontFamily:"sans-serif",padding:.01,dataZoom:{visible:!0,position:"top",height:6},layout:{mainPaneHeight:"50%",gap:13},watermark:!0,...t},this.options.upColor&&(this.upColor=this.options.upColor),this.options.downColor&&(this.downColor=this.options.downColor),this.padding=this.options.padding!==void 0?this.options.padding:this.defaultPadding,this.options.height&&(typeof this.options.height=="number"?this.rootContainer.style.height=`${this.options.height}px`:this.rootContainer.style.height=this.options.height),this.rootContainer.innerHTML="",this.layoutContainer=document.createElement("div"),this.layoutContainer.style.display="flex",this.layoutContainer.style.width="100%",this.layoutContainer.style.height="100%",this.layoutContainer.style.overflow="hidden",this.rootContainer.appendChild(this.layoutContainer),this.leftSidebar=document.createElement("div"),this.leftSidebar.style.display="none",this.leftSidebar.style.width="250px",this.leftSidebar.style.flexShrink="0",this.leftSidebar.style.overflowY="auto",this.leftSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.leftSidebar.style.borderRight="1px solid #334155",this.leftSidebar.style.padding="10px",this.leftSidebar.style.boxSizing="border-box",this.leftSidebar.style.color="#cbd5e1",this.leftSidebar.style.fontSize="12px",this.leftSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.leftSidebar),this.toolbarContainer=document.createElement("div"),this.layoutContainer.appendChild(this.toolbarContainer),this.chartContainer=document.createElement("div"),this.chartContainer.style.flexGrow="1",this.chartContainer.style.height="100%",this.chartContainer.style.overflow="hidden",this.layoutContainer.appendChild(this.chartContainer),this.rightSidebar=document.createElement("div"),this.rightSidebar.style.display="none",this.rightSidebar.style.width="250px",this.rightSidebar.style.flexShrink="0",this.rightSidebar.style.overflowY="auto",this.rightSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.rightSidebar.style.borderLeft="1px solid #334155",this.rightSidebar.style.padding="10px",this.rightSidebar.style.boxSizing="border-box",this.rightSidebar.style.color="#cbd5e1",this.rightSidebar.style.fontSize="12px",this.rightSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.rightSidebar),this.chart=j.init(this.chartContainer),this.pluginManager=new It(this,this.toolbarContainer),this.drawingEditor=new Mt(this),this.chart.on("dataZoom",o=>{this.events.emit("chart:dataZoom",o);const n=this.options.databox?.triggerOn,p=this.options.databox?.position;n==="click"&&p==="floating"&&this.chart.dispatchAction({type:"hideTip"})}),this.chart.on("finished",o=>this.events.emit("chart:updated",o)),this.chart.getZr().on("mousedown",o=>this.events.emit("mouse:down",o)),this.chart.getZr().on("mousemove",o=>this.events.emit("mouse:move",o)),this.chart.getZr().on("mouseup",o=>this.events.emit("mouse:up",o)),this.chart.getZr().on("click",o=>this.events.emit("mouse:click",o));const i=this.chart.getZr(),s=i.setCursorStyle;i.setCursorStyle=function(o){o==="grab"&&(o="crosshair"),s.call(this,o)},this.bindDrawingEvents(),window.addEventListener("resize",this.resize.bind(this)),document.addEventListener("fullscreenchange",this.onFullscreenChange),document.addEventListener("keydown",this.onKeyDown)}bindDrawingEvents(){let e=null;const t=i=>{if(!i||i.componentType!=="series"||!i.seriesName?.startsWith("drawings"))return null;i.seriesIndex;const s=i.seriesName.match(/drawings-pane-(\d+)/);if(!s)return null;const o=parseInt(s[1]),n=this.drawings.filter(d=>(d.paneIndex||0)===o)[i.dataIndex];if(!n)return null;const p=i.event?.target?.name;return{drawing:n,targetName:p,paneIdx:o}};this.chart.on("mouseover",i=>{const s=t(i);if(!s)return;const o=i.event?.target?.parent;if(o){const n=s.drawing.id===this.selectedDrawingId;e&&(clearTimeout(e),e=null),n||o.children().forEach(p=>{p.name&&p.name.startsWith("point")&&p.attr("style",{opacity:1})})}if(s.targetName==="line")this.events.emit("drawing:hover",{id:s.drawing.id,type:s.drawing.type}),this.chart.getZr().setCursorStyle("move");else if(s.targetName?.startsWith("point")){const n=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:n}),this.chart.getZr().setCursorStyle("pointer")}}),this.chart.on("mouseout",i=>{const s=t(i);if(!s)return;const o=i.event?.target?.parent;if(s.drawing.id!==this.selectedDrawingId){if(e=setTimeout(()=>{if(o){if(this.selectedDrawingId===s.drawing.id)return;o.children().forEach(n=>{n.name&&n.name.startsWith("point")&&n.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const n=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:n})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=t(i);if(!s)return;const o=i.event?.event||i.event,n=o?.offsetX,p=o?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:n,y:p});else if(s.targetName?.startsWith("point")){const d=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:d,x:n,y:p})}}),this.chart.on("click",i=>{const s=t(i);if(s){if(this.selectedDrawingId!==s.drawing.id&&(this.selectedDrawingId=s.drawing.id,this.events.emit("drawing:selected",{id:s.drawing.id}),this.render()),s.targetName==="line")this.events.emit("drawing:click",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:click",{id:s.drawing.id,pointIndex:o})}}}),this.chart.getZr().on("click",i=>{i.target||this.selectedDrawingId&&(this.events.emit("drawing:deselected",{id:this.selectedDrawingId}),this.selectedDrawingId=null,this.render())})}getChart(){return this.chart}getMarketData(){return this.marketData}getTimeToIndex(){return this.timeToIndex}getOptions(){return this.options}disableTools(){this.pluginManager.deactivatePlugin()}registerPlugin(e){this.pluginManager.register(e)}addDrawing(e){this.drawings.push(e),this.render()}removeDrawing(e){const t=this.drawings.findIndex(i=>i.id===e);if(t!==-1){const i=this.drawings[t];this.drawings.splice(t,1),this.events.emit("drawing:deleted",{id:i.id}),this.render()}}getDrawing(e){return this.drawings.find(t=>t.id===e)}updateDrawing(e){const t=this.drawings.findIndex(i=>i.id===e.id);t!==-1&&(this.drawings[t]=e,this.render())}lockChart(){if(this.isLocked)return;this.isLocked=!0;const e=this.chart.getOption();this.chart.setOption({dataZoom:e.dataZoom.map(t=>({...t,disabled:!0})),tooltip:{show:!1}})}unlockChart(){if(!this.isLocked)return;this.isLocked=!1;const e=this.chart.getOption();(this.options.dataZoom||{}).visible,e.dataZoom&&this.chart.setOption({dataZoom:e.dataZoom.map(t=>({...t,disabled:!1})),tooltip:{show:!0}})}setZoom(e,t){this.chart.dispatchAction({type:"dataZoom",start:e,end:t})}setMarketData(e){this.marketData=e,this.rebuildTimeIndex(),this.render()}updateData(e){if(e.length===0)return;const t=new Map;this.marketData.forEach(f=>{t.set(f.time,f)}),e.forEach(f=>{t.has(f.time),t.set(f.time,f)}),this.marketData=Array.from(t.values()).sort((f,v)=>f.time-v.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=it.buildCandlestickSeries(this.marketData,this.options),o={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},n=[...Array(i).fill(o),...s.data,...Array(i).fill(o)],p=[...Array(i).fill(""),...this.marketData.map(f=>new Date(f.time).toLocaleString()),...Array(i).fill("")],d=this.chart.getOption(),l=ft.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData),k=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:y,barColors:m}=it.buildIndicatorSeries(this.indicators,this.timeToIndex,l.paneLayout,p.length,i,k,l.overlayYAxisMap,l.separatePaneYAxisOffset),I=n.map((f,v)=>m[v]?{value:f.value||f,itemStyle:{color:m[v],color0:m[v],borderColor:m[v],borderColor0:m[v]}}:f),u={xAxis:d.xAxis.map((f,v)=>({data:p})),series:[{data:I,markLine:s.markLine},...y.map(f=>{const v={data:f.data};return f.renderItem&&(v.renderItem=f.renderItem),v})]};this.chart.setOption(u,{notMerge:!1}),this.startCountdown()}startCountdown(){if(this.stopCountdown(),!this.options.lastPriceLine?.showCountdown||!this.options.interval||this.marketData.length===0)return;const e=()=>{if(this.marketData.length===0)return;const t=this.marketData[this.marketData.length-1].time+(this.options.interval||0),i=Date.now(),s=t-i;if(s<=0)return;const o=Math.abs(s),n=Math.floor(o/36e5),p=Math.floor(o%36e5/6e4),d=Math.floor(o%6e4/1e3),l=`${n>0?n.toString().padStart(2,"0")+":":""}${p.toString().padStart(2,"0")}:${d.toString().padStart(2,"0")}`,k=this.chart.getOption();if(!k||!k.series)return;const y=k.series.findIndex(E=>E.type==="candlestick");if(y===-1)return;const m=k.series[y];if(!m.markLine||!m.markLine.data||!m.markLine.data[0])return;const I=m.markLine.data[0];I.label.formatter;const u=I.yAxis;let f="";if(this.options.yAxisLabelFormatter)f=this.options.yAxisLabelFormatter(u);else{const E=this.options.yAxisDecimalPlaces!==void 0?this.options.yAxisDecimalPlaces:2;f=typeof u=="number"?u.toFixed(E):u}const v=`${f}
37
- ${l}`;this.chart.setOption({series:[{name:this.options.title||"Market",markLine:{data:[{...I,label:{...I.label,formatter:v}}]}}]})};e(),this.countdownInterval=setInterval(e,1e3)}stopCountdown(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null)}addIndicator(e,t,i={}){const s=i.overlay!==void 0?i.overlay:i.isOverlay??!1;let o=0;if(!s){let p=0;this.indicators.forEach(d=>{d.paneIndex>p&&(p=d.paneIndex)}),o=p+1}const n=new bt(e,t,o,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(e,n),this.render(),n}setIndicator(e,t,i=!1){this.addIndicator(e,{[e]:t},{overlay:i})}removeIndicator(e){this.indicators.delete(e),this.render()}toggleIndicator(e,t="collapse"){if(t==="fullscreen"){document.fullscreenElement?document.exitFullscreen():this.rootContainer.requestFullscreen();return}if(t==="maximize"){this.maximizedPaneId===e?this.maximizedPaneId=null:this.maximizedPaneId=e,this.render();return}if(e==="main"){this.isMainCollapsed=!this.isMainCollapsed,this.render();return}const i=this.indicators.get(e);i&&(i.toggleCollapse(),this.render())}resize(){this.chart.resize()}destroy(){this.stopCountdown(),window.removeEventListener("resize",this.resize.bind(this)),document.removeEventListener("fullscreenchange",this.onFullscreenChange),document.removeEventListener("keydown",this.onKeyDown),this.pluginManager.deactivatePlugin(),this.pluginManager.destroy(),this.chart.dispose()}rebuildTimeIndex(){this.timeToIndex.clear(),this.marketData.forEach((i,s)=>{this.timeToIndex.set(i.time,s)});const e=this.marketData.length,t=Math.ceil(e*this.padding);this.dataIndexOffset=t}render(){if(this.marketData.length===0)return;let e=null;try{const x=this.chart.getOption();if(x&&x.dataZoom&&x.dataZoom.length>0){const A=x.dataZoom.find(w=>w.type==="slider"||w.type==="inside");A&&(e={start:A.start,end:A.end})}}catch{}const t=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,o=t==="left"?"block":"none",n=t==="right"?"block":"none";(i!==o||s!==n)&&(this.leftSidebar.style.display=o,this.rightSidebar.style.display=n,this.chart.resize());const p=this.dataIndexOffset,d=[...Array(p).fill(""),...this.marketData.map(x=>new Date(x.time).toLocaleString()),...Array(p).fill("")],l=ft.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData);if(!e&&l.dataZoom&&this.marketData.length>0){const x=this.marketData.length,A=d.length,w=p/A,T=x/A;l.dataZoom.forEach(S=>{if(S.start!==void 0){const c=S.start/100,a=w+c*T;S.start=a*100}if(S.end!==void 0){const c=S.end/100,a=w+c*T;S.end=a*100}})}e&&l.dataZoom&&l.dataZoom.forEach(x=>{x.start=e.start,x.end=e.end}),l.xAxis.forEach(x=>{x.data=d,x.boundaryGap=!1});const k=it.buildCandlestickSeries(this.marketData,this.options),y={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};k.data=[...Array(p).fill(y),...k.data,...Array(p).fill(y)];const m=[...Array(p).fill(null),...this.marketData,...Array(p).fill(null)],{series:I,barColors:u}=it.buildIndicatorSeries(this.indicators,this.timeToIndex,l.paneLayout,d.length,p,m,l.overlayYAxisMap,l.separatePaneYAxisOffset);k.data=k.data.map((x,A)=>u[A]?{value:x.value||x,itemStyle:{color:u[A],color0:u[A],borderColor:u[A],borderColor0:u[A]}}:x);const f=wt.build(l,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),v=new Map;this.drawings.forEach(x=>{const A=x.paneIndex||0;v.has(A)||v.set(A,[]),v.get(A).push(x)});const E=[];v.forEach((x,A)=>{E.push({type:"custom",name:`drawings-pane-${A}`,xAxisIndex:A,yAxisIndex:A,clip:!0,renderItem:(w,T)=>{const S=x[w.dataIndex];if(!S)return;const c=S.points[0],a=S.points[1];if(!c||!a)return;const g=T.coord([c.timeIndex,c.value]),b=T.coord([a.timeIndex,a.value]),P=S.id===this.selectedDrawingId;if(S.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:g[0],y1:g[1],x2:b[0],y2:b[1]},style:{stroke:S.style?.color||"#3b82f6",lineWidth:S.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:g[0],cy:g[1],r:4},style:{fill:"#fff",stroke:S.style?.color||"#3b82f6",lineWidth:1,opacity:P?1:0}},{type:"circle",name:"point-end",shape:{cx:b[0],cy:b[1],r:4},style:{fill:"#fff",stroke:S.style?.color||"#3b82f6",lineWidth:1,opacity:P?1:0}}]};if(S.type==="fibonacci"){const F=g[0],z=g[1],G=b[0],N=b[1],H=Math.min(F,G),X=Math.max(F,G),K=X-H,Y=N-z,h=[0,.236,.382,.5,.618,.786,1],C=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],M=[];M.push({type:"line",name:"line",shape:{x1:F,y1:z,x2:G,y2:N},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),M.push({type:"circle",name:"point-start",shape:{cx:F,cy:z,r:4},style:{fill:"#fff",stroke:S.style?.color||"#3b82f6",lineWidth:1,opacity:P?1:0},z:100}),M.push({type:"circle",name:"point-end",shape:{cx:G,cy:N,r:4},style:{fill:"#fff",stroke:S.style?.color||"#3b82f6",lineWidth:1,opacity:P?1:0},z:100}),h.forEach((D,W)=>{const q=N-Y*D,O=C[W%C.length];M.push({type:"line",name:"fib-line",shape:{x1:H,y1:q,x2:X,y2:q},style:{stroke:O,lineWidth:1},silent:!0});const B=S.points[0].value,tt=S.points[1].value,st=tt-B,J=tt-st*D;if(M.push({type:"text",style:{text:`${D} (${J.toFixed(2)})`,x:H+5,y:q-10,fill:O,fontSize:10},silent:!0}),W<h.length-1){const ot=h[W+1],dt=N-Y*ot,ut=Math.abs(dt-q),gt=Math.min(q,dt);M.push({type:"rect",shape:{x:H,y:gt,width:K,height:ut},style:{fill:C[(W+1)%C.length],opacity:.1},silent:!0})}});const $=[],R=[];return h.forEach((D,W)=>{const q=N-Y*D,O=C[W%C.length];R.push({type:"line",shape:{x1:H,y1:q,x2:X,y2:q},style:{stroke:O,lineWidth:1},silent:!0});const B=S.points[0].value,tt=S.points[1].value,st=tt-B,J=tt-st*D;if(R.push({type:"text",style:{text:`${D} (${J.toFixed(2)})`,x:H+5,y:q-10,fill:O,fontSize:10},silent:!0}),W<h.length-1){const ot=h[W+1],dt=N-Y*ot,ut=Math.abs(dt-q),gt=Math.min(q,dt);$.push({type:"rect",name:"line",shape:{x:H,y:gt,width:K,height:ut},style:{fill:C[(W+1)%C.length],opacity:.1}})}}),{type:"group",children:[...$,...R,{type:"line",name:"line",shape:{x1:F,y1:z,x2:G,y2:N},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:F,cy:z,r:4},style:{fill:"#fff",stroke:S.style?.color||"#3b82f6",lineWidth:1,opacity:P?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:G,cy:N,r:4},style:{fill:"#fff",stroke:S.style?.color||"#3b82f6",lineWidth:1,opacity:P?1:0},z:100}]}}},data:x.map(w=>[w.points[0].timeIndex,w.points[0].value,w.points[1].timeIndex,w.points[1].value]),z:100,silent:!1})});const V=x=>{const A=Ct.format(x,this.options),w=this.options.databox?.position;return w==="left"?(this.leftSidebar.innerHTML=A,""):w==="right"?(this.rightSidebar.innerHTML=A,""):this.options.databox?`<div style="min-width: 200px;">${A}</div>`:""},Z={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",triggerOn:this.options.databox?.triggerOn??"mousemove",axisPointer:{type:"cross",label:{backgroundColor:"#475569"}},backgroundColor:"rgba(30, 41, 59, 0.9)",borderWidth:1,borderColor:"#334155",padding:10,textStyle:{color:"#fff",fontFamily:this.options.fontFamily||"sans-serif"},formatter:V,extraCssText:t!=="floating"&&t!==void 0?"display: none !important;":void 0,position:(x,A,w,T,S)=>{if(this.options.databox?.position==="floating"){const c={top:10};return c[["left","right"][+(x[0]<S.viewSize[0]/2)]]=30,c}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:f,grid:l.grid,xAxis:l.xAxis,yAxis:l.yAxis,dataZoom:l.dataZoom,series:[k,...I,...E]};this.chart.setOption(Z,!0)}}var Zt=Object.defineProperty,$t=(r,e,t)=>e in r?Zt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ht=(r,e,t)=>($t(r,typeof e!="symbol"?e+"":e,t),t);class ct{constructor(e){ht(this,"id"),ht(this,"name"),ht(this,"icon"),ht(this,"context"),ht(this,"eventListeners",[]),this.id=e.id,this.name=e.name,this.icon=e.icon}init(e){this.context=e,this.onInit()}onInit(){}activate(){this.onActivate(),this.context.events.emit("plugin:activated",this.id)}onActivate(){}deactivate(){this.onDeactivate(),this.context.events.emit("plugin:deactivated",this.id)}onDeactivate(){}destroy(){this.removeAllListeners(),this.onDestroy()}onDestroy(){}on(e,t){this.context.events.on(e,t),this.eventListeners.push({event:e,handler:t})}off(e,t){this.context.events.off(e,t),this.eventListeners=this.eventListeners.filter(i=>i.event!==e||i.handler!==t)}removeAllListeners(){this.eventListeners.forEach(({event:e,handler:t})=>{this.context.events.off(e,t)}),this.eventListeners=[]}get chart(){return this.context.getChart()}get marketData(){return this.context.getMarketData()}}var Gt=Object.defineProperty,Wt=(r,e,t)=>e in r?Gt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Q=(r,e,t)=>(Wt(r,typeof e!="symbol"?e+"":e,t),t);class Ot extends ct{constructor(e){super({id:"measure",name:e?.name||"Measure",icon:e?.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-240q-33 0-56.5-23.5T80-320v-320q0-33 23.5-56.5T160-720h640q33 0 56.5 23.5T880-640v320q0 33-23.5 56.5T800-240H160Zm0-80h640v-320H680v160h-80v-160h-80v160h-80v-160h-80v160h-80v-160H160v320Zm120-160h80-80Zm160 0h80-80Zm160 0h80-80Zm-120 0Z"/></svg>'}),Q(this,"zr"),Q(this,"state","idle"),Q(this,"startPoint",null),Q(this,"endPoint",null),Q(this,"group",null),Q(this,"rect",null),Q(this,"labelRect",null),Q(this,"labelText",null),Q(this,"lineV",null),Q(this,"lineH",null),Q(this,"arrowStart",null),Q(this,"arrowEnd",null),Q(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),Q(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),Q(this,"onClick",t=>{this.state==="idle"?(this.state="drawing",this.startPoint=[t.offsetX,t.offsetY],this.endPoint=[t.offsetX,t.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic(),this.context.disableTools(),this.enableClearListeners())}),Q(this,"clearHandlers",{}),Q(this,"onMouseMove",t=>{this.state==="drawing"&&(this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}enableClearListeners(){const e=()=>{this.removeGraphic()};setTimeout(()=>{this.zr.on("click",e)},10),this.zr.on("mousedown",this.onMouseDown),this.context.events.on("chart:dataZoom",this.onChartInteraction),this.clearHandlers={click:e,mousedown:this.onMouseDown,dataZoom:this.onChartInteraction}}disableClearListeners(){this.clearHandlers.click&&this.zr.off("click",this.clearHandlers.click),this.clearHandlers.mousedown&&this.zr.off("mousedown",this.clearHandlers.mousedown),this.clearHandlers.dataZoom&&this.context.events.off("chart:dataZoom",this.clearHandlers.dataZoom),this.clearHandlers={}}initGraphic(){this.group||(this.group=new j.graphic.Group,this.rect=new j.graphic.Rect({shape:{x:0,y:0,width:0,height:0},style:{fill:"rgba(0,0,0,0)",stroke:"transparent",lineWidth:0},z:100}),this.lineV=new j.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new j.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new j.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new j.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new j.graphic.Rect({shape:{x:0,y:0,width:0,height:0,r:4},style:{fill:"transparent",stroke:"transparent",lineWidth:0,shadowBlur:5,shadowColor:"rgba(0,0,0,0.3)"},z:102}),this.labelText=new j.graphic.Text({style:{x:0,y:0,text:"",fill:"#fff",font:"12px sans-serif",align:"center",verticalAlign:"middle"},z:103}),this.group.add(this.rect),this.group.add(this.lineV),this.group.add(this.lineH),this.group.add(this.arrowStart),this.group.add(this.arrowEnd),this.group.add(this.labelRect),this.group.add(this.labelText),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[e,t]=this.startPoint,[i,s]=this.endPoint,o=this.context.coordinateConversion.pixelToData({x:e,y:t}),n=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!o||!n)return;const p=Math.round(o.timeIndex),d=Math.round(n.timeIndex),l=o.value,k=n.value,y=d-p,m=k-l,I=m/l*100,u=m>=0,f=u?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",v=u?"#2196F3":"#ec0000";this.rect.setShape({x:Math.min(e,i),y:Math.min(t,s),width:Math.abs(i-e),height:Math.abs(s-t)}),this.rect.setStyle({fill:f});const E=(e+i)/2,V=(t+s)/2;this.lineV.setShape({x1:E,y1:t,x2:E,y2:s}),this.lineV.setStyle({stroke:v}),this.lineH.setShape({x1:e,y1:V,x2:i,y2:V}),this.lineH.setStyle({stroke:v});const Z=Math.min(t,s),x=Math.max(t,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),u?(this.arrowStart.setShape({points:[[E,Z],[E-4,Z+6],[E+4,Z+6]]}),this.arrowStart.setStyle({fill:v})):(this.arrowEnd.setShape({points:[[E,x],[E-4,x-6],[E+4,x-6]]}),this.arrowEnd.setStyle({fill:v}));const A=[`${m.toFixed(2)} (${I.toFixed(2)}%)`,`${y} bars, ${(y*0).toFixed(0)}d`].join(`
38
- `),w=140,T=40,S=Math.max(t,s),c=Math.min(t,s);let a=(e+i)/2-w/2,g=S+10;const b=this.chart.getHeight();g+T>b&&(g=c-T-10),this.labelRect.setShape({x:a,y:g,width:w,height:T}),this.labelRect.setStyle({fill:"#1e293b",stroke:v,lineWidth:1}),this.labelText.setStyle({x:a+w/2,y:g+T/2,text:A,fill:"#fff"})}}var Ht=Object.defineProperty,jt=(r,e,t)=>e in r?Ht(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_=(r,e,t)=>(jt(r,typeof e!="symbol"?e+"":e,t),t);class Yt extends ct{constructor(e){super({id:"trend-line",name:e?.name||"Trend Line",icon:e?.icon||'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="2" y1="22" x2="22" y2="2" /></svg>'}),_(this,"zr"),_(this,"state","idle"),_(this,"startPoint",null),_(this,"endPoint",null),_(this,"group",null),_(this,"line",null),_(this,"startCircle",null),_(this,"endCircle",null),_(this,"onMouseDown",()=>{}),_(this,"onChartInteraction",()=>{}),_(this,"onClick",t=>{if(this.state==="idle")this.state="drawing",this.startPoint=[t.offsetX,t.offsetY],this.endPoint=[t.offsetX,t.offsetY],this.initGraphic(),this.updateGraphic();else if(this.state==="drawing"){if(this.state="finished",this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic(),this.startPoint&&this.endPoint){const i=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),s=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(i&&s){const o=i.paneIndex||0;this.context.addDrawing({id:`line-${Date.now()}`,type:"line",points:[i,s],paneIndex:o,style:{color:"#3b82f6",lineWidth:2}})}}this.removeGraphic(),this.context.disableTools()}}),_(this,"clearHandlers",{}),_(this,"onMouseMove",t=>{this.state==="drawing"&&(this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}saveDataCoordinates(){}updateGraphicFromData(){}enableClearListeners(){}disableClearListeners(){}initGraphic(){this.group||(this.group=new j.graphic.Group,this.line=new j.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#3b82f6",lineWidth:2},z:100}),this.startCircle=new j.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.endCircle=new j.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.group.add(this.line),this.group.add(this.startCircle),this.group.add(this.endCircle),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[e,t]=this.startPoint,[i,s]=this.endPoint;this.line.setShape({x1:e,y1:t,x2:i,y2:s}),this.startCircle.setShape({cx:e,cy:t}),this.endCircle.setShape({cx:i,cy:s})}}var Rt=Object.defineProperty,qt=(r,e,t)=>e in r?Rt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,nt=(r,e,t)=>(qt(r,typeof e!="symbol"?e+"":e,t),t);class Xt extends ct{constructor(e={}){super({id:"fibonacci-tool",name:e.name||"Fibonacci Retracement",icon:e.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M120-80v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Z"/></svg>'}),nt(this,"startPoint",null),nt(this,"endPoint",null),nt(this,"state","idle"),nt(this,"graphicGroup",null),nt(this,"levels",[0,.236,.382,.5,.618,.786,1]),nt(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),nt(this,"onClick",t=>{this.state==="idle"?(this.state="drawing",this.startPoint=[t.offsetX,t.offsetY],this.endPoint=[t.offsetX,t.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic(),this.saveDrawing(),this.removeGraphic(),this.context.disableTools())}),nt(this,"onMouseMove",t=>{this.state==="drawing"&&(this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic())})}onActivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.context.getChart().getZr().setCursorStyle("crosshair"),this.bindEvents()}onDeactivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.removeGraphic(),this.unbindEvents(),this.context.getChart().getZr().setCursorStyle("default")}bindEvents(){const e=this.context.getChart().getZr();e.on("click",this.onClick),e.on("mousemove",this.onMouseMove)}unbindEvents(){const e=this.context.getChart().getZr();e.off("click",this.onClick),e.off("mousemove",this.onMouseMove)}initGraphic(){this.graphicGroup=new j.graphic.Group,this.context.getChart().getZr().add(this.graphicGroup)}removeGraphic(){this.graphicGroup&&(this.context.getChart().getZr().remove(this.graphicGroup),this.graphicGroup=null)}updateGraphic(){if(!this.graphicGroup||!this.startPoint||!this.endPoint)return;this.graphicGroup.removeAll();const e=this.startPoint[0],t=this.startPoint[1],i=this.endPoint[0],s=this.endPoint[1],o=new j.graphic.Line({shape:{x1:e,y1:t,x2:i,y2:s},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]},silent:!0});this.graphicGroup.add(o);const n=Math.min(e,i),p=Math.max(e,i),d=p-n,l=s-t;this.levels.forEach((k,y)=>{const m=s-l*k,I=this.colors[y%this.colors.length],u=new j.graphic.Line({shape:{x1:n,y1:m,x2:p,y2:m},style:{stroke:I,lineWidth:1},silent:!0});if(this.graphicGroup.add(u),y<this.levels.length-1){const f=this.levels[y+1],v=s-l*f,E=Math.abs(v-m),V=Math.min(m,v),Z=new j.graphic.Rect({shape:{x:n,y:V,width:d,height:E},style:{fill:this.colors[(y+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(Z)}})}saveDrawing(){if(!this.startPoint||!this.endPoint)return;const e=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),t=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(e&&t){const i=e.paneIndex||0;this.context.addDrawing({id:`fib-${Date.now()}`,type:"fibonacci",points:[e,t],paneIndex:i,style:{color:"#3b82f6",lineWidth:1}})}}}et.AbstractPlugin=ct,et.FibonacciTool=Xt,et.LineTool=Yt,et.MeasureTool=Ot,et.QFChart=Nt});
34
+ <div>${A.marker} <span style="color: #cbd5e1;">${A.displayName}</span></div>
35
+ <div style="font-size: 10px; color: #fff;padding-left:10px;">${d}</div>
36
+ </div>`}),p+="</div>"})}return p}}var At=Object.defineProperty,Mt=(r,e,t)=>e in r?At(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,rt=(r,e,t)=>(Mt(r,typeof e!="symbol"?e+"":e,t),t);class Et{constructor(e,t){rt(this,"plugins",new Map),rt(this,"activePluginId",null),rt(this,"context"),rt(this,"toolbarContainer"),rt(this,"tooltipElement",null),rt(this,"hideTimeout",null),this.context=e,this.toolbarContainer=t,this.createTooltip(),this.renderToolbar()}createTooltip(){this.tooltipElement=document.createElement("div"),Object.assign(this.tooltipElement.style,{position:"fixed",display:"none",backgroundColor:"#1e293b",color:"#e2e8f0",padding:"6px 10px",borderRadius:"6px",fontSize:"13px",lineHeight:"1.4",fontWeight:"500",border:"1px solid #334155",zIndex:"9999",pointerEvents:"none",whiteSpace:"nowrap",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.15)",fontFamily:this.context.getOptions().fontFamily||"sans-serif",transition:"opacity 0.15s ease-in-out, transform 0.15s ease-in-out",opacity:"0",transform:"translateX(-5px)"}),document.body.appendChild(this.tooltipElement)}destroy(){this.tooltipElement&&this.tooltipElement.parentNode&&this.tooltipElement.parentNode.removeChild(this.tooltipElement),this.tooltipElement=null}showTooltip(e,t){if(!this.tooltipElement)return;this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null);const i=e.getBoundingClientRect();this.tooltipElement.textContent=t,this.tooltipElement.style.display="block";const s=this.tooltipElement.getBoundingClientRect(),o=i.top+(i.height-s.height)/2,n=i.right+10;this.tooltipElement.style.top=`${o}px`,this.tooltipElement.style.left=`${n}px`,requestAnimationFrame(()=>{this.tooltipElement&&(this.tooltipElement.style.opacity="1",this.tooltipElement.style.transform="translateX(0)")})}hideTooltip(){this.tooltipElement&&(this.tooltipElement.style.opacity="0",this.tooltipElement.style.transform="translateX(-5px)",this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout(()=>{this.tooltipElement&&(this.tooltipElement.style.display="none"),this.hideTimeout=null},150))}register(e){if(this.plugins.has(e.id)){console.warn(`Plugin with id ${e.id} is already registered.`);return}this.plugins.set(e.id,e),e.init(this.context),this.addButton(e)}unregister(e){const t=this.plugins.get(e);t&&(this.activePluginId===e&&this.deactivatePlugin(),t.destroy?.(),this.plugins.delete(e),this.removeButton(e))}activatePlugin(e){if(this.activePluginId===e){this.deactivatePlugin();return}this.activePluginId&&this.deactivatePlugin();const t=this.plugins.get(e);t&&(this.activePluginId=e,this.setButtonActive(e,!0),t.activate?.())}deactivatePlugin(){this.activePluginId&&(this.plugins.get(this.activePluginId)?.deactivate?.(),this.setButtonActive(this.activePluginId,!1),this.activePluginId=null)}renderToolbar(){this.toolbarContainer.innerHTML="",this.toolbarContainer.classList.add("qfchart-toolbar"),this.toolbarContainer.style.display="flex",this.toolbarContainer.style.flexDirection="column",this.toolbarContainer.style.width="40px",this.toolbarContainer.style.backgroundColor=this.context.getOptions().backgroundColor||"#1e293b",this.toolbarContainer.style.borderRight="1px solid #334155",this.toolbarContainer.style.padding="5px",this.toolbarContainer.style.boxSizing="border-box",this.toolbarContainer.style.gap="5px",this.toolbarContainer.style.flexShrink="0"}addButton(e){const t=document.createElement("button");t.id=`qfchart-plugin-btn-${e.id}`,t.style.width="30px",t.style.height="30px",t.style.padding="4px",t.style.border="1px solid transparent",t.style.borderRadius="4px",t.style.backgroundColor="transparent",t.style.cursor="pointer",t.style.color=this.context.getOptions().fontColor||"#cbd5e1",t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",e.icon?t.innerHTML=e.icon:t.innerText=(e.name||e.id).substring(0,2).toUpperCase(),t.addEventListener("mouseenter",()=>{this.activePluginId!==e.id&&(t.style.backgroundColor="rgba(255, 255, 255, 0.1)"),this.showTooltip(t,e.name||e.id)}),t.addEventListener("mouseleave",()=>{this.activePluginId!==e.id&&(t.style.backgroundColor="transparent"),this.hideTooltip()}),t.onclick=()=>this.activatePlugin(e.id),this.toolbarContainer.appendChild(t)}removeButton(e){const t=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${e}`);t&&t.remove()}setButtonActive(e,t){const i=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${e}`);i&&(t?(i.style.backgroundColor="#2563eb",i.style.color="#ffffff"):(i.style.backgroundColor="transparent",i.style.color=this.context.getOptions().fontColor||"#cbd5e1"))}}var Lt=Object.defineProperty,zt=(r,e,t)=>e in r?Lt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,J=(r,e,t)=>(zt(r,typeof e!="symbol"?e+"":e,t),t);class Tt{constructor(e){J(this,"context"),J(this,"isEditing",!1),J(this,"currentDrawing",null),J(this,"editingPointIndex",null),J(this,"zr"),J(this,"editGroup",null),J(this,"editLine",null),J(this,"editStartPoint",null),J(this,"editEndPoint",null),J(this,"isMovingShape",!1),J(this,"dragStart",null),J(this,"initialPixelPoints",[]),J(this,"onDrawingMouseDown",t=>{if(this.isEditing)return;const i=this.context.getDrawing(t.id);i&&(this.isEditing=!0,this.isMovingShape=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.dragStart={x:t.x,y:t.y},this.initialPixelPoints=i.points.map(s=>{const o=this.context.coordinateConversion.dataToPixel(s);return o?{x:o.x,y:o.y}:{x:0,y:0}}),this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),J(this,"onPointMouseDown",t=>{if(this.isEditing)return;const i=this.context.getDrawing(t.id);i&&(this.isEditing=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.editingPointIndex=t.pointIndex,this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),J(this,"onMouseMove",t=>{if(!this.isEditing||!this.currentDrawing)return;const i=t.offsetX,s=t.offsetY;if(this.isMovingShape&&this.dragStart){const o=i-this.dragStart.x,n=s-this.dragStart.y,u={x:this.initialPixelPoints[0].x+o,y:this.initialPixelPoints[0].y+n},p={x:this.initialPixelPoints[1].x+o,y:this.initialPixelPoints[1].y+n};this.editLine.setShape({x1:u.x,y1:u.y,x2:p.x,y2:p.y}),this.editStartPoint.setShape({cx:u.x,cy:u.y}),this.editEndPoint.setShape({cx:p.x,cy:p.y})}else this.editingPointIndex!==null&&(this.editingPointIndex===0?(this.editLine.setShape({x1:i,y1:s}),this.editStartPoint.setShape({cx:i,cy:s})):(this.editLine.setShape({x2:i,y2:s}),this.editEndPoint.setShape({cx:i,cy:s})))}),J(this,"onMouseUp",t=>{this.isEditing&&this.finishEditing(t.offsetX,t.offsetY)}),this.context=e,this.zr=this.context.getChart().getZr(),this.bindEvents()}bindEvents(){this.context.events.on("drawing:point:mousedown",this.onPointMouseDown),this.context.events.on("drawing:mousedown",this.onDrawingMouseDown)}createEditGraphic(){if(!this.currentDrawing)return;this.editGroup=new j.graphic.Group;const e=this.currentDrawing.points[0],t=this.currentDrawing.points[1],i=this.context.coordinateConversion.dataToPixel(e),s=this.context.coordinateConversion.dataToPixel(t);!i||!s||(this.editLine=new j.graphic.Line({shape:{x1:i.x,y1:i.y,x2:s.x,y2:s.y},style:{stroke:this.currentDrawing.style?.color||"#3b82f6",lineWidth:this.currentDrawing.style?.lineWidth||2,lineDash:[4,4]},silent:!0}),this.editStartPoint=new j.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new j.graphic.Circle({shape:{cx:s.x,cy:s.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editGroup.add(this.editLine),this.editGroup.add(this.editStartPoint),this.editGroup.add(this.editEndPoint),this.zr.add(this.editGroup))}finishEditing(e,t){if(this.currentDrawing){if(this.isMovingShape&&this.dragStart){const i=e-this.dragStart.x,s=t-this.dragStart.y,o=this.initialPixelPoints.map((n,u)=>{const p=n.x+i,h=n.y+s;return this.context.coordinateConversion.pixelToData({x:p,y:h})});o.every(n=>n!==null)&&o[0]&&o[1]&&(this.currentDrawing.points[0]=o[0],this.currentDrawing.points[1]=o[1],o[0].paneIndex!==void 0&&(this.currentDrawing.paneIndex=o[0].paneIndex),this.context.updateDrawing(this.currentDrawing))}else if(this.editingPointIndex!==null){const i=this.context.coordinateConversion.pixelToData({x:e,y:t});i&&(this.currentDrawing.points[this.editingPointIndex]=i,this.editingPointIndex===0&&i.paneIndex!==void 0&&(this.currentDrawing.paneIndex=i.paneIndex),this.context.updateDrawing(this.currentDrawing))}this.isEditing=!1,this.isMovingShape=!1,this.dragStart=null,this.initialPixelPoints=[],this.currentDrawing=null,this.editingPointIndex=null,this.editGroup&&(this.zr.remove(this.editGroup),this.editGroup=null),this.zr.off("mousemove",this.onMouseMove),this.zr.off("mouseup",this.onMouseUp),this.context.unlockChart()}}}var Ft=Object.defineProperty,$t=(r,e,t)=>e in r?Ft(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Nt=(r,e,t)=>($t(r,typeof e!="symbol"?e+"":e,t),t);class Ot{constructor(){Nt(this,"handlers",new Map)}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t)}off(e,t){const i=this.handlers.get(e);i&&i.delete(t)}emit(e,t){const i=this.handlers.get(e);i&&i.forEach(s=>{try{s(t)}catch(o){console.error(`Error in EventBus handler for ${e}:`,o)}})}clear(){this.handlers.clear()}}var Zt=Object.defineProperty,Gt=(r,e,t)=>e in r?Zt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,O=(r,e,t)=>(Gt(r,typeof e!="symbol"?e+"":e,t),t);class Wt{constructor(e,t={}){O(this,"chart"),O(this,"options"),O(this,"marketData",[]),O(this,"indicators",new Map),O(this,"timeToIndex",new Map),O(this,"pluginManager"),O(this,"drawingEditor"),O(this,"events",new Ot),O(this,"isMainCollapsed",!1),O(this,"maximizedPaneId",null),O(this,"countdownInterval",null),O(this,"selectedDrawingId",null),O(this,"drawings",[]),O(this,"coordinateConversion",{pixelToData:o=>{const n=this.chart.getOption();if(!n||!n.grid)return null;const u=n.grid.length;for(let p=0;p<u;p++)if(this.chart.containPixel({gridIndex:p},[o.x,o.y])){this.chart.convertFromPixel({seriesIndex:p},[o.x,o.y]);const h=this.chart.convertFromPixel({gridIndex:p},[o.x,o.y]);if(h)return{timeIndex:Math.round(h[0]),value:h[1],paneIndex:p}}return null},dataToPixel:o=>{const n=o.paneIndex||0,u=this.chart.convertToPixel({gridIndex:n},[o.timeIndex,o.value]);return u?{x:u[0],y:u[1]}:null}}),O(this,"upColor","#00da3c"),O(this,"downColor","#ec0000"),O(this,"defaultPadding",0),O(this,"padding"),O(this,"dataIndexOffset",0),O(this,"rootContainer"),O(this,"layoutContainer"),O(this,"toolbarContainer"),O(this,"leftSidebar"),O(this,"rightSidebar"),O(this,"chartContainer"),O(this,"onKeyDown",o=>{(o.key==="Delete"||o.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),O(this,"onFullscreenChange",()=>{this.render()}),O(this,"isLocked",!1),O(this,"lockedState",null),this.rootContainer=e,this.options={title:"Market",height:"600px",backgroundColor:"#1e293b",upColor:"#00da3c",downColor:"#ec0000",fontColor:"#cbd5e1",fontFamily:"sans-serif",padding:.01,dataZoom:{visible:!0,position:"top",height:6},layout:{mainPaneHeight:"50%",gap:13},watermark:!0,...t},this.options.upColor&&(this.upColor=this.options.upColor),this.options.downColor&&(this.downColor=this.options.downColor),this.padding=this.options.padding!==void 0?this.options.padding:this.defaultPadding,this.options.height&&(typeof this.options.height=="number"?this.rootContainer.style.height=`${this.options.height}px`:this.rootContainer.style.height=this.options.height),this.rootContainer.innerHTML="",this.layoutContainer=document.createElement("div"),this.layoutContainer.style.display="flex",this.layoutContainer.style.width="100%",this.layoutContainer.style.height="100%",this.layoutContainer.style.overflow="hidden",this.rootContainer.appendChild(this.layoutContainer),this.leftSidebar=document.createElement("div"),this.leftSidebar.style.display="none",this.leftSidebar.style.width="250px",this.leftSidebar.style.flexShrink="0",this.leftSidebar.style.overflowY="auto",this.leftSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.leftSidebar.style.borderRight="1px solid #334155",this.leftSidebar.style.padding="10px",this.leftSidebar.style.boxSizing="border-box",this.leftSidebar.style.color="#cbd5e1",this.leftSidebar.style.fontSize="12px",this.leftSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.leftSidebar),this.toolbarContainer=document.createElement("div"),this.layoutContainer.appendChild(this.toolbarContainer),this.chartContainer=document.createElement("div"),this.chartContainer.style.flexGrow="1",this.chartContainer.style.height="100%",this.chartContainer.style.overflow="hidden",this.layoutContainer.appendChild(this.chartContainer),this.rightSidebar=document.createElement("div"),this.rightSidebar.style.display="none",this.rightSidebar.style.width="250px",this.rightSidebar.style.flexShrink="0",this.rightSidebar.style.overflowY="auto",this.rightSidebar.style.backgroundColor=this.options.backgroundColor||"#1e293b",this.rightSidebar.style.borderLeft="1px solid #334155",this.rightSidebar.style.padding="10px",this.rightSidebar.style.boxSizing="border-box",this.rightSidebar.style.color="#cbd5e1",this.rightSidebar.style.fontSize="12px",this.rightSidebar.style.fontFamily=this.options.fontFamily||"sans-serif",this.layoutContainer.appendChild(this.rightSidebar),this.chart=j.init(this.chartContainer),this.pluginManager=new Et(this,this.toolbarContainer),this.drawingEditor=new Tt(this),this.chart.on("dataZoom",o=>{this.events.emit("chart:dataZoom",o);const n=this.options.databox?.triggerOn,u=this.options.databox?.position;n==="click"&&u==="floating"&&this.chart.dispatchAction({type:"hideTip"})}),this.chart.on("finished",o=>this.events.emit("chart:updated",o)),this.chart.getZr().on("mousedown",o=>this.events.emit("mouse:down",o)),this.chart.getZr().on("mousemove",o=>this.events.emit("mouse:move",o)),this.chart.getZr().on("mouseup",o=>this.events.emit("mouse:up",o)),this.chart.getZr().on("click",o=>this.events.emit("mouse:click",o));const i=this.chart.getZr(),s=i.setCursorStyle;i.setCursorStyle=function(o){o==="grab"&&(o="crosshair"),s.call(this,o)},this.bindDrawingEvents(),window.addEventListener("resize",this.resize.bind(this)),document.addEventListener("fullscreenchange",this.onFullscreenChange),document.addEventListener("keydown",this.onKeyDown)}bindDrawingEvents(){let e=null;const t=i=>{if(!i||i.componentType!=="series"||!i.seriesName?.startsWith("drawings"))return null;i.seriesIndex;const s=i.seriesName.match(/drawings-pane-(\d+)/);if(!s)return null;const o=parseInt(s[1]),n=this.drawings.filter(p=>(p.paneIndex||0)===o)[i.dataIndex];if(!n)return null;const u=i.event?.target?.name;return{drawing:n,targetName:u,paneIdx:o}};this.chart.on("mouseover",i=>{const s=t(i);if(!s)return;const o=i.event?.target?.parent;if(o){const n=s.drawing.id===this.selectedDrawingId;e&&(clearTimeout(e),e=null),n||o.children().forEach(u=>{u.name&&u.name.startsWith("point")&&u.attr("style",{opacity:1})})}if(s.targetName==="line")this.events.emit("drawing:hover",{id:s.drawing.id,type:s.drawing.type}),this.chart.getZr().setCursorStyle("move");else if(s.targetName?.startsWith("point")){const n=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:n}),this.chart.getZr().setCursorStyle("pointer")}}),this.chart.on("mouseout",i=>{const s=t(i);if(!s)return;const o=i.event?.target?.parent;if(s.drawing.id!==this.selectedDrawingId){if(e=setTimeout(()=>{if(o){if(this.selectedDrawingId===s.drawing.id)return;o.children().forEach(n=>{n.name&&n.name.startsWith("point")&&n.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const n=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:n})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=t(i);if(!s)return;const o=i.event?.event||i.event,n=o?.offsetX,u=o?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:n,y:u});else if(s.targetName?.startsWith("point")){const p=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:p,x:n,y:u})}}),this.chart.on("click",i=>{const s=t(i);if(s){if(this.selectedDrawingId!==s.drawing.id&&(this.selectedDrawingId=s.drawing.id,this.events.emit("drawing:selected",{id:s.drawing.id}),this.render()),s.targetName==="line")this.events.emit("drawing:click",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:click",{id:s.drawing.id,pointIndex:o})}}}),this.chart.getZr().on("click",i=>{i.target||this.selectedDrawingId&&(this.events.emit("drawing:deselected",{id:this.selectedDrawingId}),this.selectedDrawingId=null,this.render())})}getChart(){return this.chart}getMarketData(){return this.marketData}getTimeToIndex(){return this.timeToIndex}getOptions(){return this.options}disableTools(){this.pluginManager.deactivatePlugin()}registerPlugin(e){this.pluginManager.register(e)}addDrawing(e){this.drawings.push(e),this.render()}removeDrawing(e){const t=this.drawings.findIndex(i=>i.id===e);if(t!==-1){const i=this.drawings[t];this.drawings.splice(t,1),this.events.emit("drawing:deleted",{id:i.id}),this.render()}}getDrawing(e){return this.drawings.find(t=>t.id===e)}updateDrawing(e){const t=this.drawings.findIndex(i=>i.id===e.id);t!==-1&&(this.drawings[t]=e,this.render())}lockChart(){if(this.isLocked)return;this.isLocked=!0;const e=this.chart.getOption();this.chart.setOption({dataZoom:e.dataZoom.map(t=>({...t,disabled:!0})),tooltip:{show:!1}})}unlockChart(){if(!this.isLocked)return;this.isLocked=!1;const e=this.chart.getOption();(this.options.dataZoom||{}).visible,e.dataZoom&&this.chart.setOption({dataZoom:e.dataZoom.map(t=>({...t,disabled:!1})),tooltip:{show:!0}})}setZoom(e,t){this.chart.dispatchAction({type:"dataZoom",start:e,end:t})}setMarketData(e){this.marketData=e,this.rebuildTimeIndex(),this.render()}updateData(e){if(e.length===0)return;const t=new Map;this.marketData.forEach(d=>{t.set(d.time,d)}),e.forEach(d=>{t.has(d.time),t.set(d.time,d)}),this.marketData=Array.from(t.values()).sort((d,m)=>d.time-m.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=ct.buildCandlestickSeries(this.marketData,this.options),o={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},n=[...Array(i).fill(o),...s.data,...Array(i).fill(o)],u=[...Array(i).fill(""),...this.marketData.map(d=>new Date(d.time).toLocaleString()),...Array(i).fill("")],p=this.chart.getOption(),h=gt.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData),S=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:x,barColors:y}=ct.buildIndicatorSeries(this.indicators,this.timeToIndex,h.paneLayout,u.length,i,S,h.overlayYAxisMap,h.separatePaneYAxisOffset),A=n.map((d,m)=>y[m]?{value:d.value||d,itemStyle:{color:y[m],color0:y[m],borderColor:y[m],borderColor0:y[m]}}:d),v={xAxis:p.xAxis.map((d,m)=>({data:u})),series:[{data:A,markLine:s.markLine},...x.map(d=>{const m={data:d.data};return d.renderItem&&(m.renderItem=d.renderItem),m})]};this.chart.setOption(v,{notMerge:!1}),this.startCountdown()}startCountdown(){if(this.stopCountdown(),!this.options.lastPriceLine?.showCountdown||!this.options.interval||this.marketData.length===0)return;const e=()=>{if(this.marketData.length===0)return;const t=this.marketData[this.marketData.length-1].time+(this.options.interval||0),i=Date.now(),s=t-i;if(s<=0)return;const o=Math.abs(s),n=Math.floor(o/36e5),u=Math.floor(o%36e5/6e4),p=Math.floor(o%6e4/1e3),h=`${n>0?n.toString().padStart(2,"0")+":":""}${u.toString().padStart(2,"0")}:${p.toString().padStart(2,"0")}`,S=this.chart.getOption();if(!S||!S.series)return;const x=S.series.findIndex(M=>M.type==="candlestick");if(x===-1)return;const y=S.series[x];if(!y.markLine||!y.markLine.data||!y.markLine.data[0])return;const A=y.markLine.data[0];A.label.formatter;const v=A.yAxis;let d="";if(this.options.yAxisLabelFormatter)d=this.options.yAxisLabelFormatter(v);else{const M=this.options.yAxisDecimalPlaces!==void 0?this.options.yAxisDecimalPlaces:2;d=typeof v=="number"?v.toFixed(M):v}const m=`${d}
37
+ ${h}`;this.chart.setOption({series:[{name:this.options.title||"Market",markLine:{data:[{...A,label:{...A.label,formatter:m}}]}}]})};e(),this.countdownInterval=setInterval(e,1e3)}stopCountdown(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null)}addIndicator(e,t,i={}){const s=i.overlay!==void 0?i.overlay:i.isOverlay??!1;let o=0;if(!s){let u=0;this.indicators.forEach(p=>{p.paneIndex>u&&(u=p.paneIndex)}),o=u+1}const n=new wt(e,t,o,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(e,n),this.render(),n}setIndicator(e,t,i=!1){this.addIndicator(e,{[e]:t},{overlay:i})}removeIndicator(e){this.indicators.delete(e),this.render()}toggleIndicator(e,t="collapse"){if(t==="fullscreen"){document.fullscreenElement?document.exitFullscreen():this.rootContainer.requestFullscreen();return}if(t==="maximize"){this.maximizedPaneId===e?this.maximizedPaneId=null:this.maximizedPaneId=e,this.render();return}if(e==="main"){this.isMainCollapsed=!this.isMainCollapsed,this.render();return}const i=this.indicators.get(e);i&&(i.toggleCollapse(),this.render())}resize(){this.chart.resize()}destroy(){this.stopCountdown(),window.removeEventListener("resize",this.resize.bind(this)),document.removeEventListener("fullscreenchange",this.onFullscreenChange),document.removeEventListener("keydown",this.onKeyDown),this.pluginManager.deactivatePlugin(),this.pluginManager.destroy(),this.chart.dispose()}rebuildTimeIndex(){this.timeToIndex.clear(),this.marketData.forEach((i,s)=>{this.timeToIndex.set(i.time,s)});const e=this.marketData.length,t=Math.ceil(e*this.padding);this.dataIndexOffset=t}render(){if(this.marketData.length===0)return;let e=null;try{const g=this.chart.getOption();if(g&&g.dataZoom&&g.dataZoom.length>0){const I=g.dataZoom.find(E=>E.type==="slider"||E.type==="inside");I&&(e={start:I.start,end:I.end})}}catch{}const t=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,o=t==="left"?"block":"none",n=t==="right"?"block":"none";(i!==o||s!==n)&&(this.leftSidebar.style.display=o,this.rightSidebar.style.display=n,this.chart.resize());const u=this.dataIndexOffset,p=[...Array(u).fill(""),...this.marketData.map(g=>new Date(g.time).toLocaleString()),...Array(u).fill("")],h=gt.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData);if(!e&&h.dataZoom&&this.marketData.length>0){const g=this.marketData.length,I=p.length,E=u/I,z=g/I;h.dataZoom.forEach(D=>{if(D.start!==void 0){const B=D.start/100,W=E+B*z;D.start=W*100}if(D.end!==void 0){const B=D.end/100,W=E+B*z;D.end=W*100}})}e&&h.dataZoom&&h.dataZoom.forEach(g=>{g.start=e.start,g.end=e.end}),h.xAxis.forEach(g=>{g.data=p,g.boundaryGap=!1});const S=ct.buildCandlestickSeries(this.marketData,this.options),x={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};S.data=[...Array(u).fill(x),...S.data,...Array(u).fill(x)];const y=[...Array(u).fill(null),...this.marketData,...Array(u).fill(null)],{series:A,barColors:v}=ct.buildIndicatorSeries(this.indicators,this.timeToIndex,h.paneLayout,p.length,u,y,h.overlayYAxisMap,h.separatePaneYAxisOffset);S.data=S.data.map((g,I)=>v[I]?{value:g.value||g,itemStyle:{color:v[I],color0:v[I],borderColor:v[I],borderColor0:v[I]}}:g);const d=Pt.build(h,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),m=new Map;this.drawings.forEach(g=>{const I=g.paneIndex||0;m.has(I)||m.set(I,[]),m.get(I).push(g)});const M=[];m.forEach((g,I)=>{M.push({type:"custom",name:`drawings-pane-${I}`,xAxisIndex:I,yAxisIndex:I,clip:!0,renderItem:(E,z)=>{const D=g[E.dataIndex];if(!D)return;const B=D.points[0],W=D.points[1];if(!B||!W)return;const X=z.coord([B.timeIndex,B.value]),Z=z.coord([W.timeIndex,W.value]),_=D.id===this.selectedDrawingId;if(D.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:X[0],y1:X[1],x2:Z[0],y2:Z[1]},style:{stroke:D.style?.color||"#3b82f6",lineWidth:D.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:X[0],cy:X[1],r:4},style:{fill:"#fff",stroke:D.style?.color||"#3b82f6",lineWidth:1,opacity:_?1:0}},{type:"circle",name:"point-end",shape:{cx:Z[0],cy:Z[1],r:4},style:{fill:"#fff",stroke:D.style?.color||"#3b82f6",lineWidth:1,opacity:_?1:0}}]};if(D.type==="fibonacci"){const st=X[0],Q=X[1],it=Z[0],c=Z[1],a=Math.min(st,it),w=Math.max(st,it),k=w-a,b=c-Q,l=[0,.236,.382,.5,.618,.786,1],f=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],P=[];P.push({type:"line",name:"line",shape:{x1:st,y1:Q,x2:it,y2:c},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),P.push({type:"circle",name:"point-start",shape:{cx:st,cy:Q,r:4},style:{fill:"#fff",stroke:D.style?.color||"#3b82f6",lineWidth:1,opacity:_?1:0},z:100}),P.push({type:"circle",name:"point-end",shape:{cx:it,cy:c,r:4},style:{fill:"#fff",stroke:D.style?.color||"#3b82f6",lineWidth:1,opacity:_?1:0},z:100}),l.forEach((C,N)=>{const L=c-b*C,F=f[N%f.length];P.push({type:"line",name:"fib-line",shape:{x1:a,y1:L,x2:w,y2:L},style:{stroke:F,lineWidth:1},silent:!0});const G=D.points[0].value,R=D.points[1].value,V=R-G,Y=R-V*C;if(P.push({type:"text",style:{text:`${C} (${Y.toFixed(2)})`,x:a+5,y:L-10,fill:F,fontSize:10},silent:!0}),N<l.length-1){const K=l[N+1],dt=c-b*K,ft=Math.abs(dt-L),yt=Math.min(L,dt);P.push({type:"rect",shape:{x:a,y:yt,width:k,height:ft},style:{fill:f[(N+1)%f.length],opacity:.1},silent:!0})}});const T=[],H=[];return l.forEach((C,N)=>{const L=c-b*C,F=f[N%f.length];H.push({type:"line",shape:{x1:a,y1:L,x2:w,y2:L},style:{stroke:F,lineWidth:1},silent:!0});const G=D.points[0].value,R=D.points[1].value,V=R-G,Y=R-V*C;if(H.push({type:"text",style:{text:`${C} (${Y.toFixed(2)})`,x:a+5,y:L-10,fill:F,fontSize:10},silent:!0}),N<l.length-1){const K=l[N+1],dt=c-b*K,ft=Math.abs(dt-L),yt=Math.min(L,dt);T.push({type:"rect",name:"line",shape:{x:a,y:yt,width:k,height:ft},style:{fill:f[(N+1)%f.length],opacity:.1}})}}),{type:"group",children:[...T,...H,{type:"line",name:"line",shape:{x1:st,y1:Q,x2:it,y2:c},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:st,cy:Q,r:4},style:{fill:"#fff",stroke:D.style?.color||"#3b82f6",lineWidth:1,opacity:_?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:it,cy:c,r:4},style:{fill:"#fff",stroke:D.style?.color||"#3b82f6",lineWidth:1,opacity:_?1:0},z:100}]}}},data:g.map(E=>[E.points[0].timeIndex,E.points[0].value,E.points[1].timeIndex,E.points[1].value]),z:100,silent:!1})});const $=g=>{const I=Dt.format(g,this.options),E=this.options.databox?.position;return E==="left"?(this.leftSidebar.innerHTML=I,""):E==="right"?(this.rightSidebar.innerHTML=I,""):this.options.databox?`<div style="min-width: 200px;">${I}</div>`:""},q={backgroundColor:this.options.backgroundColor,animation:!1,legend:{show:!1},tooltip:{show:!0,showContent:!!this.options.databox,trigger:"axis",triggerOn:this.options.databox?.triggerOn??"mousemove",axisPointer:{type:"cross",label:{backgroundColor:"#475569"}},backgroundColor:"rgba(30, 41, 59, 0.9)",borderWidth:1,borderColor:"#334155",padding:10,textStyle:{color:"#fff",fontFamily:this.options.fontFamily||"sans-serif"},formatter:$,extraCssText:t!=="floating"&&t!==void 0?"display: none !important;":void 0,position:(g,I,E,z,D)=>{if(this.options.databox?.position==="floating"){const B={top:10};return B[["left","right"][+(g[0]<D.viewSize[0]/2)]]=30,B}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:d,grid:h.grid,xAxis:h.xAxis,yAxis:h.yAxis,dataZoom:h.dataZoom,series:[S,...A,...M]};this.chart.setOption(q,!0)}}var Ht=Object.defineProperty,jt=(r,e,t)=>e in r?Ht(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ht=(r,e,t)=>(jt(r,typeof e!="symbol"?e+"":e,t),t);class pt{constructor(e){ht(this,"id"),ht(this,"name"),ht(this,"icon"),ht(this,"context"),ht(this,"eventListeners",[]),this.id=e.id,this.name=e.name,this.icon=e.icon}init(e){this.context=e,this.onInit()}onInit(){}activate(){this.onActivate(),this.context.events.emit("plugin:activated",this.id)}onActivate(){}deactivate(){this.onDeactivate(),this.context.events.emit("plugin:deactivated",this.id)}onDeactivate(){}destroy(){this.removeAllListeners(),this.onDestroy()}onDestroy(){}on(e,t){this.context.events.on(e,t),this.eventListeners.push({event:e,handler:t})}off(e,t){this.context.events.off(e,t),this.eventListeners=this.eventListeners.filter(i=>i.event!==e||i.handler!==t)}removeAllListeners(){this.eventListeners.forEach(({event:e,handler:t})=>{this.context.events.off(e,t)}),this.eventListeners=[]}get chart(){return this.context.getChart()}get marketData(){return this.context.getMarketData()}}var Rt=Object.defineProperty,Yt=(r,e,t)=>e in r?Rt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,U=(r,e,t)=>(Yt(r,typeof e!="symbol"?e+"":e,t),t);class Bt extends pt{constructor(e){super({id:"measure",name:e?.name||"Measure",icon:e?.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-240q-33 0-56.5-23.5T80-320v-320q0-33 23.5-56.5T160-720h640q33 0 56.5 23.5T880-640v320q0 33-23.5 56.5T800-240H160Zm0-80h640v-320H680v160h-80v-160h-80v160h-80v-160h-80v160h-80v-160H160v320Zm120-160h80-80Zm160 0h80-80Zm160 0h80-80Zm-120 0Z"/></svg>'}),U(this,"zr"),U(this,"state","idle"),U(this,"startPoint",null),U(this,"endPoint",null),U(this,"group",null),U(this,"rect",null),U(this,"labelRect",null),U(this,"labelText",null),U(this,"lineV",null),U(this,"lineH",null),U(this,"arrowStart",null),U(this,"arrowEnd",null),U(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),U(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),U(this,"onClick",t=>{this.state==="idle"?(this.state="drawing",this.startPoint=[t.offsetX,t.offsetY],this.endPoint=[t.offsetX,t.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic(),this.context.disableTools(),this.enableClearListeners())}),U(this,"clearHandlers",{}),U(this,"onMouseMove",t=>{this.state==="drawing"&&(this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}enableClearListeners(){const e=()=>{this.removeGraphic()};setTimeout(()=>{this.zr.on("click",e)},10),this.zr.on("mousedown",this.onMouseDown),this.context.events.on("chart:dataZoom",this.onChartInteraction),this.clearHandlers={click:e,mousedown:this.onMouseDown,dataZoom:this.onChartInteraction}}disableClearListeners(){this.clearHandlers.click&&this.zr.off("click",this.clearHandlers.click),this.clearHandlers.mousedown&&this.zr.off("mousedown",this.clearHandlers.mousedown),this.clearHandlers.dataZoom&&this.context.events.off("chart:dataZoom",this.clearHandlers.dataZoom),this.clearHandlers={}}initGraphic(){this.group||(this.group=new j.graphic.Group,this.rect=new j.graphic.Rect({shape:{x:0,y:0,width:0,height:0},style:{fill:"rgba(0,0,0,0)",stroke:"transparent",lineWidth:0},z:100}),this.lineV=new j.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new j.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new j.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new j.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new j.graphic.Rect({shape:{x:0,y:0,width:0,height:0,r:4},style:{fill:"transparent",stroke:"transparent",lineWidth:0,shadowBlur:5,shadowColor:"rgba(0,0,0,0.3)"},z:102}),this.labelText=new j.graphic.Text({style:{x:0,y:0,text:"",fill:"#fff",font:"12px sans-serif",align:"center",verticalAlign:"middle"},z:103}),this.group.add(this.rect),this.group.add(this.lineV),this.group.add(this.lineH),this.group.add(this.arrowStart),this.group.add(this.arrowEnd),this.group.add(this.labelRect),this.group.add(this.labelText),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[e,t]=this.startPoint,[i,s]=this.endPoint,o=this.context.coordinateConversion.pixelToData({x:e,y:t}),n=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!o||!n)return;const u=Math.round(o.timeIndex),p=Math.round(n.timeIndex),h=o.value,S=n.value,x=p-u,y=S-h,A=y/h*100,v=y>=0,d=v?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",m=v?"#2196F3":"#ec0000";this.rect.setShape({x:Math.min(e,i),y:Math.min(t,s),width:Math.abs(i-e),height:Math.abs(s-t)}),this.rect.setStyle({fill:d});const M=(e+i)/2,$=(t+s)/2;this.lineV.setShape({x1:M,y1:t,x2:M,y2:s}),this.lineV.setStyle({stroke:m}),this.lineH.setShape({x1:e,y1:$,x2:i,y2:$}),this.lineH.setStyle({stroke:m});const q=Math.min(t,s),g=Math.max(t,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),v?(this.arrowStart.setShape({points:[[M,q],[M-4,q+6],[M+4,q+6]]}),this.arrowStart.setStyle({fill:m})):(this.arrowEnd.setShape({points:[[M,g],[M-4,g-6],[M+4,g-6]]}),this.arrowEnd.setStyle({fill:m}));const I=[`${y.toFixed(2)} (${A.toFixed(2)}%)`,`${x} bars, ${(x*0).toFixed(0)}d`].join(`
38
+ `),E=140,z=40,D=Math.max(t,s),B=Math.min(t,s);let W=(e+i)/2-E/2,X=D+10;const Z=this.chart.getHeight();X+z>Z&&(X=B-z-10),this.labelRect.setShape({x:W,y:X,width:E,height:z}),this.labelRect.setStyle({fill:"#1e293b",stroke:m,lineWidth:1}),this.labelText.setStyle({x:W+E/2,y:X+z/2,text:I,fill:"#fff"})}}var qt=Object.defineProperty,Xt=(r,e,t)=>e in r?qt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,et=(r,e,t)=>(Xt(r,typeof e!="symbol"?e+"":e,t),t);class Ut extends pt{constructor(e){super({id:"trend-line",name:e?.name||"Trend Line",icon:e?.icon||'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="2" y1="22" x2="22" y2="2" /></svg>'}),et(this,"zr"),et(this,"state","idle"),et(this,"startPoint",null),et(this,"endPoint",null),et(this,"group",null),et(this,"line",null),et(this,"startCircle",null),et(this,"endCircle",null),et(this,"onMouseDown",()=>{}),et(this,"onChartInteraction",()=>{}),et(this,"onClick",t=>{if(this.state==="idle")this.state="drawing",this.startPoint=[t.offsetX,t.offsetY],this.endPoint=[t.offsetX,t.offsetY],this.initGraphic(),this.updateGraphic();else if(this.state==="drawing"){if(this.state="finished",this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic(),this.startPoint&&this.endPoint){const i=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),s=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(i&&s){const o=i.paneIndex||0;this.context.addDrawing({id:`line-${Date.now()}`,type:"line",points:[i,s],paneIndex:o,style:{color:"#3b82f6",lineWidth:2}})}}this.removeGraphic(),this.context.disableTools()}}),et(this,"clearHandlers",{}),et(this,"onMouseMove",t=>{this.state==="drawing"&&(this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic())})}onInit(){this.zr=this.chart.getZr()}onActivate(){this.state="idle",this.chart.getZr().setCursorStyle("crosshair"),this.zr.on("click",this.onClick),this.zr.on("mousemove",this.onMouseMove)}onDeactivate(){this.state="idle",this.chart.getZr().setCursorStyle("default"),this.zr.off("click",this.onClick),this.zr.off("mousemove",this.onMouseMove),this.disableClearListeners(),this.state==="drawing"&&this.removeGraphic()}onDestroy(){this.removeGraphic()}saveDataCoordinates(){}updateGraphicFromData(){}enableClearListeners(){}disableClearListeners(){}initGraphic(){this.group||(this.group=new j.graphic.Group,this.line=new j.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#3b82f6",lineWidth:2},z:100}),this.startCircle=new j.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.endCircle=new j.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.group.add(this.line),this.group.add(this.startCircle),this.group.add(this.endCircle),this.zr.add(this.group))}removeGraphic(){this.group&&(this.zr.remove(this.group),this.group=null,this.disableClearListeners())}updateGraphic(){if(!this.startPoint||!this.endPoint||!this.group)return;const[e,t]=this.startPoint,[i,s]=this.endPoint;this.line.setShape({x1:e,y1:t,x2:i,y2:s}),this.startCircle.setShape({cx:e,cy:t}),this.endCircle.setShape({cx:i,cy:s})}}var Vt=Object.defineProperty,Jt=(r,e,t)=>e in r?Vt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,nt=(r,e,t)=>(Jt(r,typeof e!="symbol"?e+"":e,t),t);class Qt extends pt{constructor(e={}){super({id:"fibonacci-tool",name:e.name||"Fibonacci Retracement",icon:e.icon||'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M120-80v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Zm0-240v-80h720v80H120Z"/></svg>'}),nt(this,"startPoint",null),nt(this,"endPoint",null),nt(this,"state","idle"),nt(this,"graphicGroup",null),nt(this,"levels",[0,.236,.382,.5,.618,.786,1]),nt(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),nt(this,"onClick",t=>{this.state==="idle"?(this.state="drawing",this.startPoint=[t.offsetX,t.offsetY],this.endPoint=[t.offsetX,t.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic(),this.saveDrawing(),this.removeGraphic(),this.context.disableTools())}),nt(this,"onMouseMove",t=>{this.state==="drawing"&&(this.endPoint=[t.offsetX,t.offsetY],this.updateGraphic())})}onActivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.context.getChart().getZr().setCursorStyle("crosshair"),this.bindEvents()}onDeactivate(){this.state="idle",this.startPoint=null,this.endPoint=null,this.removeGraphic(),this.unbindEvents(),this.context.getChart().getZr().setCursorStyle("default")}bindEvents(){const e=this.context.getChart().getZr();e.on("click",this.onClick),e.on("mousemove",this.onMouseMove)}unbindEvents(){const e=this.context.getChart().getZr();e.off("click",this.onClick),e.off("mousemove",this.onMouseMove)}initGraphic(){this.graphicGroup=new j.graphic.Group,this.context.getChart().getZr().add(this.graphicGroup)}removeGraphic(){this.graphicGroup&&(this.context.getChart().getZr().remove(this.graphicGroup),this.graphicGroup=null)}updateGraphic(){if(!this.graphicGroup||!this.startPoint||!this.endPoint)return;this.graphicGroup.removeAll();const e=this.startPoint[0],t=this.startPoint[1],i=this.endPoint[0],s=this.endPoint[1],o=new j.graphic.Line({shape:{x1:e,y1:t,x2:i,y2:s},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]},silent:!0});this.graphicGroup.add(o);const n=Math.min(e,i),u=Math.max(e,i),p=u-n,h=s-t;this.levels.forEach((S,x)=>{const y=s-h*S,A=this.colors[x%this.colors.length],v=new j.graphic.Line({shape:{x1:n,y1:y,x2:u,y2:y},style:{stroke:A,lineWidth:1},silent:!0});if(this.graphicGroup.add(v),x<this.levels.length-1){const d=this.levels[x+1],m=s-h*d,M=Math.abs(m-y),$=Math.min(y,m),q=new j.graphic.Rect({shape:{x:n,y:$,width:p,height:M},style:{fill:this.colors[(x+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(q)}})}saveDrawing(){if(!this.startPoint||!this.endPoint)return;const e=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),t=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(e&&t){const i=e.paneIndex||0;this.context.addDrawing({id:`fib-${Date.now()}`,type:"fibonacci",points:[e,t],paneIndex:i,style:{color:"#3b82f6",lineWidth:1}})}}}ot.AbstractPlugin=pt,ot.FibonacciTool=Qt,ot.LineTool=Ut,ot.MeasureTool=Bt,ot.QFChart=Wt});