@qfo/qfchart 0.6.7 → 0.7.1

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' | 'fill' | 'label';
31
+ type IndicatorStyle = 'line' | 'step' | 'columns' | 'histogram' | 'circles' | 'cross' | 'background' | 'shape' | 'char' | 'bar' | 'candle' | 'barcolor' | 'fill' | 'label' | 'drawing_line';
32
32
  interface IndicatorOptions {
33
33
  style: IndicatorStyle;
34
34
  color: string;
@@ -273,6 +273,8 @@ declare class QFChart implements ChartContext {
273
273
  private leftSidebar;
274
274
  private rightSidebar;
275
275
  private chartContainer;
276
+ private overlayContainer;
277
+ private _lastTables;
276
278
  constructor(container: HTMLElement, options?: QFChartOptions);
277
279
  private onKeyDown;
278
280
  private onFullscreenChange;
@@ -356,6 +358,7 @@ declare class QFChart implements ChartContext {
356
358
  removeIndicator(id: string): void;
357
359
  toggleIndicator(id: string, action?: 'collapse' | 'maximize' | 'fullscreen'): void;
358
360
  resize(): void;
361
+ private _renderTableOverlays;
359
362
  destroy(): void;
360
363
  private rebuildTimeIndex;
361
364
  private render;
@@ -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(K,lt){typeof exports=="object"&&typeof module<"u"?lt(exports,require("echarts")):typeof define=="function"&&define.amd?define(["exports","echarts"],lt):(K=typeof globalThis<"u"?globalThis:K||self,lt(K.QFChart={},K.echarts))})(this,function(K,lt){"use strict";function St(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 Z=St(lt),At=Object.defineProperty,kt=(r,e,t)=>e in r?At(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,nt=(r,e,t)=>(kt(r,typeof e!="symbol"?e+"":e,t),t);class Pt{constructor(e,t,i,s={}){nt(this,"id"),nt(this,"plots"),nt(this,"paneIndex"),nt(this,"height"),nt(this,"collapsed"),nt(this,"titleColor"),nt(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 n=new Map;i.data?.forEach(o=>{n.set(o.time,o)}),s.data?.forEach(o=>{n.set(o.time,o)}),i.data=Array.from(n.values()).sort((o,c)=>o.time-c.time)}})}}class O{static createMinFunction(e){return t=>{const i=(t.max-t.min)*(e/100);return t.min-i}}static createMaxFunction(e){return t=>{const i=(t.max-t.min)*(e/100);return t.max+i}}static autoDetectDecimals(e){if(!e||e.length===0)return 2;const t=e[e.length-1].close;if(t===0||!isFinite(t)||isNaN(t))return 2;const i=Math.abs(t);if(i>=1)return 2;const s=Math.ceil(-Math.log10(i));return Math.min(s+4,10)}static formatValue(e,t){return typeof e=="number"?e.toFixed(t):String(e)}}class vt{static calculate(e,t,i,s=!1,n=null,o){let c=0;e>0&&(c=1/e*100);const a=i.yAxisPadding!==void 0?i.yAxisPadding:5,l=Array.from(t.values()).map(v=>v.paneIndex).filter(v=>v>0).sort((v,M)=>v-M).filter((v,M,T)=>T.indexOf(v)===M),f=l.length>0,g=i.dataZoom?.visible??!0,h=i.dataZoom?.position??"top",d=i.dataZoom?.height??6,p=i.dataZoom?.start??0,u=i.dataZoom?.end??100;let b=8,w=92,C=-1;if(n)if(n==="main")C=0;else{const v=t.get(n);v&&(C=v.paneIndex)}if(C!==-1){const v=[],M=[],T=[],$=[],B=i.dataZoom?.start??50,F=i.dataZoom?.end??100;(i.dataZoom?.zoomOnTouch??!0)&&$.push({type:"inside",xAxisIndex:"all",start:B,end:F});const G=f?Math.max(...l):0,H=[];for(let N=0;N<=G;N++){const W=N===C;v.push({left:"10%",right:"10%",top:W?"5%":"0%",height:W?"90%":"0%",show:W,containLabel:!1}),M.push({type:"category",gridIndex:N,data:[],show:W,axisLabel:{show:W,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:W,lineStyle:{color:"#334155"}},splitLine:{show:W,lineStyle:{color:"#334155",opacity:.5}}});let et,J;if(N===0&&C===0?(et=i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?i.yAxisMin:O.createMinFunction(a),J=i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?i.yAxisMax:O.createMaxFunction(a)):(et=O.createMinFunction(a),J=O.createMaxFunction(a)),T.push({position:"right",gridIndex:N,show:W,scale:!0,min:et,max:J,axisLabel:{show:W,color:"#94a3b8",fontFamily:i.fontFamily,formatter:X=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(X);const it=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:O.autoDetectDecimals(o);return O.formatValue(X,it)}},splitLine:{show:W,lineStyle:{color:"#334155",opacity:.5}}}),N>0){const X=Array.from(t.values()).find(it=>it.paneIndex===N);X&&H.push({index:N,height:W?90:0,top:W?5:0,isCollapsed:!1,indicatorId:X.id,titleColor:X.titleColor,controls:X.controls})}}return{grid:v,xAxis:M,yAxis:T,dataZoom:$,paneLayout:H,mainPaneHeight:C===0?90:0,mainPaneTop:C===0?5:0,pixelToPercent:c,overlayYAxisMap:new Map,separatePaneYAxisOffset:1}}g?h==="top"?(b=d+4,w=95):(w=100-d-2,b=8):(b=5,w=95);let S=5;e>0&&(S=20/e*100);let x=75,m=[];if(f){const v=l.map(F=>{const G=Array.from(t.values()).find(H=>H.paneIndex===F);return{index:F,requestedHeight:G?.height,isCollapsed:G?.collapsed??!1,indicatorId:G?.id,titleColor:G?.titleColor,controls:G?.controls}}).map(F=>({...F,height:F.isCollapsed?3:F.requestedHeight!==void 0?F.requestedHeight:15})),M=v.reduce((F,G)=>F+G.height,0),T=v.length*S,$=M+T;x=w-b-$,s?x=3:x<20&&(x=Math.max(x,10));let B=b+x+S;m=v.map(F=>{const G={index:F.index,height:F.height,top:B,isCollapsed:F.isCollapsed,indicatorId:F.indicatorId,titleColor:F.titleColor,controls:F.controls};return B+=F.height+S,G})}else x=w-b,s&&(x=3);const I=[];I.push({left:"10%",right:"10%",top:b+"%",height:x+"%",containLabel:!1}),m.forEach(v=>{I.push({left:"10%",right:"10%",top:v.top+"%",height:v.height+"%",containLabel:!1})});const P=[0,...m.map((v,M)=>M+1)],y=[],k=m.length===0;y.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:v=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(v);const M=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:O.autoDetectDecimals(o);return O.formatValue(v,M)}},axisTick:{show:!s},axisPointer:{label:{show:k,fontSize:11,backgroundColor:"#475569"}}}),m.forEach((v,M)=>{const T=M===m.length-1;y.push({type:"category",gridIndex:M+1,data:[],axisLabel:{show:!1},axisLine:{show:!v.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:T,fontSize:11,backgroundColor:"#475569"}}})});const L=[];let A,D;i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?A=i.yAxisMin:A=O.createMinFunction(a),i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?D=i.yAxisMax:D=O.createMaxFunction(a),L.push({position:"right",scale:!0,min:A,max:D,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:v=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(v);const M=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:O.autoDetectDecimals(o);return O.formatValue(v,M)}}});let z=1,j=-1/0,U=1/0;o&&o.length>0&&(j=Math.min(...o.map(v=>v.low)),U=Math.max(...o.map(v=>v.high)));const _=new Map;t.forEach((v,M)=>{v.paneIndex===0&&!v.collapsed&&o&&o.length>0&&Object.entries(v.plots).forEach(([T,$])=>{const B=`${M}::${T}`,F=["background","barcolor","char"],G=$.options.style==="shape"&&($.options.location==="abovebar"||$.options.location==="belowbar");if(F.includes($.options.style)){_.has(B)||(_.set(B,z),z++);return}if($.options.style==="shape"&&!G){_.has(B)||(_.set(B,z),z++);return}const H=[];if($.data&&Object.values($.data).forEach(N=>{typeof N=="number"&&!isNaN(N)&&isFinite(N)&&H.push(N)}),H.length>0){const N=Math.min(...H),W=Math.max(...H),et=W-N,J=U-j,X=N>=j*.5&&W<=U*1.5,it=et>J*.01;X&&it||_.has(B)||(_.set(B,z),z++)}})});const Q=_.size>0?z-1:0,tt=new Set;_.forEach((v,M)=>{t.forEach(T=>{Object.entries(T.plots).forEach(([$,B])=>{`${T.id}::${$}`===M&&["background","barcolor","char"].includes(B.options.style)&&tt.add(v)})})});for(let v=0;v<Q;v++){const M=v+1,T=tt.has(M);L.push({position:"left",scale:!T,min:T?0:O.createMinFunction(a),max:T?1:O.createMaxFunction(a),gridIndex:0,show:!1,splitLine:{show:!1},axisLine:{show:!1},axisLabel:{show:!1}})}const ct=z;m.forEach((v,M)=>{L.push({position:"right",scale:!0,min:O.createMinFunction(a),max:O.createMaxFunction(a),gridIndex:M+1,splitLine:{show:!v.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!v.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10,formatter:T=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(T);const $=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:O.autoDetectDecimals(o);return O.formatValue(T,$)}},axisLine:{show:!v.isCollapsed,lineStyle:{color:"#334155"}}})});const ot=[];return g&&((i.dataZoom?.zoomOnTouch??!0)&&ot.push({type:"inside",xAxisIndex:P,start:p,end:u}),h==="top"?ot.push({type:"slider",xAxisIndex:P,top:"1%",height:d+"%",start:p,end:u,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1}):ot.push({type:"slider",xAxisIndex:P,bottom:"1%",height:d+"%",start:p,end:u,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1})),{grid:I,xAxis:y,yAxis:L,dataZoom:ot,paneLayout:m,mainPaneHeight:x,mainPaneTop:b,pixelToPercent:c,overlayYAxisMap:_,separatePaneYAxisOffset:ct}}static calculateMaximized(e,t,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}class Dt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:o,plotOptions:c}=e,a="#2962ff";return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(l,f)=>{const g=l.dataIndex;if(g===0)return;const h=f.value(1),d=f.value(2);if(h===null||isNaN(h)||d===null||isNaN(d))return;const p=f.coord([g-1,d]),u=f.coord([g,h]);return{type:"line",shape:{x1:p[0],y1:p[1],x2:u[0],y2:u[1]},style:{stroke:o[g]||c.color||a,lineWidth:c.linewidth||1},silent:!0}},data:n.map((l,f)=>[f,l,f>0?n[f-1]:null])}}}class Mt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:o,plotOptions:c}=e,a="#2962ff";return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(l,f)=>{const g=f.value(0),h=f.value(1);if(isNaN(h)||h===null)return;const d=f.coord([g,h]),p=f.size([1,0])[0];return{type:"line",shape:{x1:d[0]-p/2,y1:d[1],x2:d[0]+p/2,y2:d[1]},style:{stroke:o[l.dataIndex]||c.color||a,lineWidth:c.linewidth||1},silent:!0}},data:n.map((l,f)=>[f,l])}}}class wt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:o,plotOptions:c}=e;return{name:t,type:"bar",xAxisIndex:i,yAxisIndex:s,data:n.map((a,l)=>({value:a,itemStyle:o[l]?{color:o[l]}:void 0})),itemStyle:{color:c.color||"#2962ff"}}}}const ft=new Map;function Lt(r,e="#00da3c",t="64px"){if(typeof document>"u")return"";const i=`${r}-${e}-${t}`;if(ft.has(i))return ft.get(i);const s=document.createElement("canvas"),n=s.getContext("2d");if(s.width=32,s.height=32,n){n.font="bold "+t+" Arial",n.fillStyle=e,n.textAlign="center",n.textBaseline="middle",n.fillText(r,16,16);const o=s.toDataURL("image/png");return ft.set(i,o),o}return""}class gt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:o,plotOptions:c}=e,a="#2962ff",l=c.style;if(l==="char")return{name:t,type:"scatter",xAxisIndex:i,yAxisIndex:s,symbolSize:0,data:n.map((g,h)=>({value:[h,g],itemStyle:{opacity:0}})),silent:!0};const f=n.map((g,h)=>{if(g===null)return null;const d=o[h]||c.color||a,p={value:[h,g],itemStyle:{color:d}};return l==="cross"?(p.symbol=`image://${Lt("+",d,"24px")}`,p.symbolSize=16):(p.symbol="circle",p.symbolSize=6),p}).filter(g=>g!==null);return{name:t,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:f}}}class Ct{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:o,optionsArray:c,plotOptions:a}=e,l="#2962ff",f=a.style==="candle",g=n.map((h,d)=>{if(h===null||!Array.isArray(h)||h.length!==4)return null;const[p,u,b,w]=h,C=c[d]||{},S=C.color||o[d]||a.color||l,x=C.wickcolor||a.wickcolor||S,m=C.bordercolor||a.bordercolor||x;return[d,p,w,b,u,S,x,m]}).filter(h=>h!==null);return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(h,d)=>{const p=d.value(0),u=d.value(1),b=d.value(2),w=d.value(3),C=d.value(4),S=d.value(5),x=d.value(6),m=d.value(7);if(isNaN(u)||isNaN(b)||isNaN(w)||isNaN(C))return null;const I=d.coord([p,0])[0],P=d.coord([p,u])[1],y=d.coord([p,b])[1],k=d.coord([p,w])[1],L=d.coord([p,C])[1],A=d.size([1,0])[0]*.6;if(f){const D=Math.min(P,y),z=Math.max(P,y),j=Math.abs(y-P);return{type:"group",children:[{type:"line",shape:{x1:I,y1:L,x2:I,y2:D},style:{stroke:x,lineWidth:1}},{type:"line",shape:{x1:I,y1:z,x2:I,y2:k},style:{stroke:x,lineWidth:1}},{type:"rect",shape:{x:I-A/2,y:D,width:A,height:j||1},style:{fill:S,stroke:m,lineWidth:1}}]}}else{const D=A*.5;return{type:"group",children:[{type:"line",shape:{x1:I,y1:k,x2:I,y2:L},style:{stroke:S,lineWidth:1}},{type:"line",shape:{x1:I-D,y1:P,x2:I,y2:P},style:{stroke:S,lineWidth:1}},{type:"line",shape:{x1:I,y1:y,x2:I+D,y2:y},style:{stroke:S,lineWidth:1}}]}}},data:g}}}class rt{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}}}}class zt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:o,optionsArray:c,plotOptions:a,candlestickData:l}=e,f="#2962ff",g=n.map((h,d)=>{const p=c[d]||{},u=a,b=p.location||u.location||"absolute";if(b!=="absolute"&&!h||h==null)return null;const w=p.color||u.color||f,C=p.shape||u.shape||"circle",S=p.size||u.size||"normal",x=p.text||u.text,m=p.textcolor||u.textcolor||"white",I=p.width||u.width,P=p.height||u.height;let y=h,k=[0,0];b==="abovebar"?(l&&l[d]&&(y=l[d].high),k=[0,"-150%"]):b==="belowbar"?(l&&l[d]&&(y=l[d].low),k=[0,"150%"]):b==="top"?(y=h,k=[0,0]):b==="bottom"&&(y=h,k=[0,0]);const L=rt.getShapeSymbol(C),A=rt.getShapeSize(S,I,P),D=rt.getShapeRotation(C);let z=A;C.includes("label")&&(Array.isArray(A)?z=[A[0]*2.5,A[1]*2.5]:z=A*2.5);const j=rt.getLabelConfig(C,b);return{value:[d,y],symbol:L,symbolSize:z,symbolRotate:D,symbolOffset:k,itemStyle:{color:w},label:{show:!!x,position:j.position,distance:j.distance,formatter:x,color:m,fontSize:10,fontWeight:"bold"}}}).filter(h=>h!==null);return{name:t,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:g}}}class Et{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:o}=e;return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,z:-10,renderItem:(c,a)=>{const l=a.value(0);if(isNaN(l))return;const f=a.coord([l,.5]),g=a.size([1,0])[0],h=c.coordSys,d=f[0]-g/2,p=o[c.dataIndex],u=a.value(1);if(!(!p||u===null||u===void 0||isNaN(u)))return{type:"rect",shape:{x:d,y:h.y,width:g,height:h.height},style:{fill:p,opacity:.3},silent:!0}},data:n.map((c,a)=>[a,c!=null&&!isNaN(c)?.5:null])}}}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],n=t[3],o=t[4]?parseFloat(t[4]):1;return{color:`rgb(${i},${s},${n})`,opacity:o}}return{color:e,opacity:.3}}}class Nt{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,plotOptions:n,plotDataArrays:o,indicatorId:c,plotName:a}=e,l=e.dataArray.length,f=n.plot1?`${c}::${n.plot1}`:null,g=n.plot2?`${c}::${n.plot2}`:null;if(!f||!g)return console.warn(`Fill plot "${a}" missing plot1 or plot2 reference`),null;const h=o?.get(f),d=o?.get(g);if(!h||!d)return console.warn(`Fill plot "${a}" references non-existent plots: ${n.plot1}, ${n.plot2}`),null;const{color:p,opacity:u}=Tt.parseColor(n.color||"rgba(128, 128, 128, 0.2)"),b=[];for(let w=0;w<l;w++){const C=h[w],S=d[w],x=w>0?h[w-1]:null,m=w>0?d[w-1]:null;b.push([w,C,S,x,m])}return{name:t,type:"custom",xAxisIndex:i,yAxisIndex:s,z:-5,renderItem:(w,C)=>{const S=w.dataIndex;if(S===0)return null;const x=C.value(1),m=C.value(2),I=C.value(3),P=C.value(4);if(x===null||m===null||I===null||P===null||isNaN(x)||isNaN(m)||isNaN(I)||isNaN(P))return null;const y=C.coord([S-1,I]),k=C.coord([S,x]),L=C.coord([S,m]),A=C.coord([S-1,P]);return{type:"polygon",shape:{points:[y,k,L,A]},style:{fill:p,opacity:u},silent:!0}},data:b}}}class Ft{render(e){const{seriesName:t,xAxisIndex:i,yAxisIndex:s,dataArray:n,candlestickData:o}=e,c=n.map((a,l)=>{if(a==null)return null;const f=typeof a=="object"?a:null;if(!f)return null;const g=f.text||"",h=f.color||"#2962ff",d=f.textcolor||"#ffffff",p=f.yloc||"price",u=f.style||"style_label_down",b=f.size||"normal",w=f.textalign||"align_center",C=f.tooltip||"",S=this.styleToShape(u);let x=f.y,m=[0,0];p==="abovebar"?(o&&o[l]&&(x=o[l].high),m=[0,"-150%"]):p==="belowbar"&&(o&&o[l]&&(x=o[l].low),m=[0,"150%"]);const I=rt.getShapeSymbol(S),P=rt.getShapeSize(b),y=this.getSizePx(b);let k;if(S==="labeldown"||S==="labelup"){const z=g.length*y*.65,j=y*2.5,U=Math.max(j,z+y*1.6),_=y*2.8;k=[U,_],S==="labeldown"?m=[m[0],typeof m[1]=="string"?m[1]:m[1]-_*.35]:m=[m[0],typeof m[1]=="string"?m[1]:m[1]+_*.35]}else S==="none"?k=0:Array.isArray(P)?k=[P[0]*1.5,P[1]*1.5]:k=P*1.5;const L=this.getLabelPosition(u,p),A=L==="inside"||L.startsWith("inside"),D={value:[l,x],symbol:I,symbolSize:k,symbolOffset:m,itemStyle:{color:h},label:{show:!!g,position:L,distance:A?0:5,formatter:g,color:d,fontSize:y,fontWeight:"bold",align:A?"center":w==="align_left"?"left":w==="align_right"?"right":"center",verticalAlign:"middle",padding:[2,6]}};return C&&(D.tooltip={formatter:C}),D}).filter(a=>a!==null);return{name:t,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:c,z:20}}styleToShape(e){switch(e.startsWith("style_")?e.substring(6):e){case"label_down":return"labeldown";case"label_up":return"labelup";case"label_left":return"labeldown";case"label_right":return"labeldown";case"label_lower_left":return"labeldown";case"label_lower_right":return"labeldown";case"label_upper_left":return"labelup";case"label_upper_right":return"labelup";case"label_center":return"labeldown";case"circle":return"circle";case"square":return"square";case"diamond":return"diamond";case"flag":return"flag";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"cross":return"cross";case"xcross":return"xcross";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"text_outline":return"none";case"none":return"none";default:return"labeldown"}}getLabelPosition(e,t){switch(e.startsWith("style_")?e.substring(6):e){case"label_down":return"inside";case"label_up":return"inside";case"label_left":return"left";case"label_right":return"right";case"label_lower_left":return"insideBottomLeft";case"label_lower_right":return"insideBottomRight";case"label_upper_left":return"insideTopLeft";case"label_upper_right":return"insideTopRight";case"label_center":return"inside";case"text_outline":case"none":return t==="abovebar"?"top":t==="belowbar"?"bottom":"top";default:return t==="belowbar"?"bottom":"top"}}getSizePx(e){switch(e){case"tiny":return 8;case"small":return 9;case"normal":case"auto":return 10;case"large":return 12;case"huge":return 14;default:return 10}}}var $t=Object.defineProperty,Ot=(r,e,t)=>e in r?$t(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Zt=(r,e,t)=>(Ot(r,typeof e!="symbol"?e+"":e,t),t);const V=class{static register(e,t){this.renderers.set(e,t)}static get(e){return this.renderers.get(e)||this.renderers.get("line")}};Zt(V,"renderers",new Map),V.register("line",new Dt),V.register("step",new Mt),V.register("histogram",new wt),V.register("columns",new wt),V.register("circles",new gt),V.register("cross",new gt),V.register("char",new gt),V.register("bar",new Ct),V.register("candle",new Ct),V.register("shape",new zt),V.register("background",new Et),V.register("fill",new Nt),V.register("label",new Ft);let Gt=V;var Wt=Object.defineProperty,_t=(r,e,t)=>e in r?Wt(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);const It=class bt{static buildCandlestickSeries(e,t,i){const s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",o=e.map(a=>[a.open,a.close,a.low,a.high]);if(i&&i>o.length){const a=i-o.length;for(let l=0;l<a;l++)o.push(null)}let c;if(t.lastPriceLine?.visible!==!1&&e.length>0){const a=e[e.length-1],l=a.close,f=a.close>=a.open,g=t.lastPriceLine?.color||(f?s:n);let h=t.lastPriceLine?.lineStyle||"dashed";h.startsWith("linestyle_")&&(h=h.replace("linestyle_",""));const d=t.yAxisDecimalPlaces!==void 0?t.yAxisDecimalPlaces:O.autoDetectDecimals(e);c={symbol:["none","none"],precision:d,data:[{yAxis:l,label:{show:!0,position:"end",formatter:p=>t.yAxisLabelFormatter?t.yAxisLabelFormatter(p.value):O.formatValue(p.value,d),color:"#fff",backgroundColor:g,padding:[2,4],borderRadius:2,fontSize:11,fontWeight:"bold"},lineStyle:{color:g,type:h,width:1,opacity:.8}}],animation:!1,silent:!0}}return{type:"candlestick",name:t.title||"Market",data:o,itemStyle:{color:s,color0:n,borderColor:s,borderColor0:n},markLine:c,xAxisIndex:0,yAxisIndex:0,z:5}}static buildIndicatorSeries(e,t,i,s,n=0,o,c,a=1){const l=[],f=new Array(s).fill(null),g=new Map;return e.forEach((h,d)=>{h.collapsed||Object.keys(h.plots).sort((p,u)=>{const b=h.plots[p],w=h.plots[u],C=b.options.style==="fill",S=w.options.style==="fill";return C&&!S?1:!C&&S?-1:0}).forEach(p=>{const u=h.plots[p],b=`${d}::${p}`;let w=0,C=0;const S=u.options.overlay;if(h.paneIndex===0||S===!0)w=0,c&&c.has(b)?C=c.get(b):C=0;else{const y=i.findIndex(k=>k.index===h.paneIndex);y!==-1&&(w=y+1,C=a+y)}const x=new Array(s).fill(null),m=new Array(s).fill(null),I=new Array(s).fill(null);if(u.data?.forEach(y=>{const k=t.get(y.time);if(k!==void 0){const L=y.options?.offset??u.options.offset??0,A=k+n+L;if(A>=0&&A<s){let D=y.value;const z=y.options?.color;(z===null||z==="na"||z==="NaN"||typeof z=="number"&&isNaN(z))&&(D=null),x[A]=D,m[A]=z||u.options.color||bt.DEFAULT_COLOR,I[A]=y.options||{}}}}),g.set(`${d}::${p}`,x),u.options?.style?.startsWith("style_")&&(u.options.style=u.options.style.replace("style_","")),u.options.style==="barcolor"){u.data?.forEach(y=>{const k=t.get(y.time);if(k!==void 0){const L=y.options?.offset??u.options.offset??0,A=k+n+L;if(A>=0&&A<s){const D=y.options?.color||u.options.color||bt.DEFAULT_COLOR;!(D===null||D==="na"||D==="NaN"||typeof D=="number"&&isNaN(D))&&y.value!==null&&y.value!==void 0&&(f[A]=D)}}});return}const P=Gt.get(u.options.style).render({seriesName:b,xAxisIndex:w,yAxisIndex:C,dataArray:x,colorArray:m,optionsArray:I,plotOptions:u.options,candlestickData:o,plotDataArrays:g,indicatorId:d,plotName:p});P&&l.push(P)})}),{series:l,barColors:f}}};Ht(It,"DEFAULT_COLOR","#2962ff");let pt=It;class Rt{static build(e,t,i,s=!1,n=null){const o=[],c=e.pixelToPercent,a=e.mainPaneTop;if(!n||n==="main"){const l=10*c;if(o.push({type:"text",left:"8.5%",top:a+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 g=e.mainPaneTop+e.mainPaneHeight;o.push({type:"text",right:"11%",top:g-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 f=[];if(t.controls?.collapse&&f.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 g=n==="main",h=t.controls?.collapse?25:0;f.push({type:"group",x:h,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:g?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(t.controls?.fullscreen){let g=0;t.controls?.collapse&&(g+=25),t.controls?.maximize&&(g+=25),f.push({type:"group",x:g,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}]})}f.length>0&&o.push({type:"group",right:"10.5%",top:a+"%",children:f})}return e.paneLayout.forEach(l=>{if(n&&l.indicatorId!==n)return;o.push({type:"text",left:"8.5%",top:l.top+10*c+"%",z:10,style:{text:l.indicatorId||"",fill:l.titleColor||"#fff",font:`bold 12px ${t.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const f=[];if(l.controls?.collapse&&f.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 g=n===l.indicatorId,h=l.controls?.collapse?25:0;f.push({type:"group",x:h,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:g?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${t.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}f.length>0&&o.push({type:"group",right:"10.5%",top:l.top+"%",children:f})}),o}}class jt{static format(e,t){if(!e||e.length===0)return"";const i=t.title||"Market",s=t.upColor||"#00da3c",n=t.downColor||"#ec0000",o=t.fontFamily||"sans-serif",c=e[0].axisValue;let a=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${o};">${c}</div>`;const l=e.find(g=>g.seriesType==="candlestick"),f=e.filter(g=>g.seriesType!=="candlestick");if(l){const[g,h,d,p,u]=l.value,b=d>=h?s:n;a+=`
18
- <div style="margin-bottom: 8px; font-family: ${o};">
19
- <div style="display:flex; justify-content:space-between; color:${b}; font-weight:bold;">
17
+ (function(st,ct){typeof exports=="object"&&typeof module<"u"?ct(exports,require("echarts")):typeof define=="function"&&define.amd?define(["exports","echarts"],ct):(st=typeof globalThis<"u"?globalThis:st||self,ct(st.QFChart={},st.echarts))})(this,function(st,ct){"use strict";function Mt(g){var t=Object.create(null);return g&&Object.keys(g).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(g,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return g[e]}})}}),t.default=g,Object.freeze(t)}var W=Mt(ct),_t=Object.defineProperty,Dt=(g,t,e)=>t in g?_t(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,rt=(g,t,e)=>(Dt(g,typeof t!="symbol"?t+"":t,e),e);class zt{constructor(t,e,i,s={}){rt(this,"id"),rt(this,"plots"),rt(this,"paneIndex"),rt(this,"height"),rt(this,"collapsed"),rt(this,"titleColor"),rt(this,"controls"),this.id=t,this.plots=e,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(t){Object.keys(t).forEach(e=>{if(!this.plots[e])this.plots[e]=t[e];else{const i=this.plots[e],s=t[e];if(!i.data)return;s.options&&(i.options={...i.options,...s.options});const n=new Map;i.data?.forEach(l=>{n.set(l.time,l)}),s.data?.forEach(l=>{n.set(l.time,l)}),i.data=Array.from(n.values()).sort((l,d)=>l.time-d.time)}})}}class Z{static createMinFunction(t){return e=>{const i=(e.max-e.min)*(t/100);return e.min-i}}static createMaxFunction(t){return e=>{const i=(e.max-e.min)*(t/100);return e.max+i}}static autoDetectDecimals(t){if(!t||t.length===0)return 2;const e=t[t.length-1].close;if(e===0||!isFinite(e)||isNaN(e))return 2;const i=Math.abs(e);if(i>=1)return 2;const s=Math.ceil(-Math.log10(i));return Math.min(s+4,10)}static formatValue(t,e){return typeof t=="number"?t.toFixed(e):String(t)}}class It{static calculate(t,e,i,s=!1,n=null,l){let d=0;t>0&&(d=1/t*100);const h=i.yAxisPadding!==void 0?i.yAxisPadding:5,c=Array.from(e.values()).map(k=>k.paneIndex).filter(k=>k>0).sort((k,z)=>k-z).filter((k,z,E)=>E.indexOf(k)===z),y=c.length>0,p=i.dataZoom?.visible??!0,f=i.dataZoom?.position??"top",r=i.dataZoom?.height??6,o=i.dataZoom?.start??0,u=i.dataZoom?.end??100;let a=8,x=92,m=-1;if(n)if(n==="main")m=0;else{const k=e.get(n);k&&(m=k.paneIndex)}if(m!==-1){const k=[],z=[],E=[],$=[],H=i.dataZoom?.start??50,O=i.dataZoom?.end??100;(i.dataZoom?.zoomOnTouch??!0)&&$.push({type:"inside",xAxisIndex:"all",start:H,end:O,filterMode:"weakFilter"});const Y=y?Math.max(...c):0,V=[];for(let T=0;T<=Y;T++){const N=T===m;k.push({left:"10%",right:"10%",top:N?"5%":"0%",height:N?"90%":"0%",show:N,containLabel:!1}),z.push({type:"category",gridIndex:T,data:[],show:N,axisLabel:{show:N,color:"#94a3b8",fontFamily:i.fontFamily},axisLine:{show:N,lineStyle:{color:"#334155"}},splitLine:{show:N,lineStyle:{color:"#334155",opacity:.5}}});let it,nt;if(T===0&&m===0?(it=i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?i.yAxisMin:Z.createMinFunction(h),nt=i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?i.yAxisMax:Z.createMaxFunction(h)):(it=Z.createMinFunction(h),nt=Z.createMaxFunction(h)),E.push({position:"right",gridIndex:T,show:N,scale:!0,min:it,max:nt,axisLabel:{show:N,color:"#94a3b8",fontFamily:i.fontFamily,formatter:X=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(X);const ot=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(l);return Z.formatValue(X,ot)}},splitLine:{show:N,lineStyle:{color:"#334155",opacity:.5}}}),T>0){const X=Array.from(e.values()).find(ot=>ot.paneIndex===T);X&&V.push({index:T,height:N?90:0,top:N?5:0,isCollapsed:!1,indicatorId:X.id,titleColor:X.titleColor,controls:X.controls})}}return{grid:k,xAxis:z,yAxis:E,dataZoom:$,paneLayout:V,mainPaneHeight:m===0?90:0,mainPaneTop:m===0?5:0,pixelToPercent:d,overlayYAxisMap:new Map,separatePaneYAxisOffset:1}}p?f==="top"?(a=r+4,x=95):(x=100-r-2,a=8):(a=5,x=95);let S=5;t>0&&(S=20/t*100);let I=75,A=[];if(y){const k=c.map(O=>{const Y=Array.from(e.values()).find(V=>V.paneIndex===O);return{index:O,requestedHeight:Y?.height,isCollapsed:Y?.collapsed??!1,indicatorId:Y?.id,titleColor:Y?.titleColor,controls:Y?.controls}}).map(O=>({...O,height:O.isCollapsed?3:O.requestedHeight!==void 0?O.requestedHeight:15})),z=k.reduce((O,Y)=>O+Y.height,0),E=k.length*S,$=z+E;I=x-a-$,s?I=3:I<20&&(I=Math.max(I,10));let H=a+I+S;A=k.map(O=>{const Y={index:O.index,height:O.height,top:H,isCollapsed:O.isCollapsed,indicatorId:O.indicatorId,titleColor:O.titleColor,controls:O.controls};return H+=O.height+S,Y})}else I=x-a,s&&(I=3);const v=[];v.push({left:"10%",right:"10%",top:a+"%",height:I+"%",containLabel:!1}),A.forEach(k=>{v.push({left:"10%",right:"10%",top:k.top+"%",height:k.height+"%",containLabel:!1})});const b=[0,...A.map((k,z)=>z+1)],C=[],w=A.length===0;C.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:k=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(k);const z=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(l);return Z.formatValue(k,z)}},axisTick:{show:!s},axisPointer:{label:{show:w,fontSize:11,backgroundColor:"#475569"}}}),A.forEach((k,z)=>{const E=z===A.length-1;C.push({type:"category",gridIndex:z+1,data:[],axisLabel:{show:!1},axisLine:{show:!k.isCollapsed,lineStyle:{color:"#334155"}},axisTick:{show:!1},splitLine:{show:!1},axisPointer:{label:{show:E,fontSize:11,backgroundColor:"#475569"}}})});const M=[];let P,D;i.yAxisMin!==void 0&&i.yAxisMin!=="auto"?P=i.yAxisMin:P=Z.createMinFunction(h),i.yAxisMax!==void 0&&i.yAxisMax!=="auto"?D=i.yAxisMax:D=Z.createMaxFunction(h),M.push({position:"right",scale:!0,min:P,max:D,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:k=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(k);const z=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(l);return Z.formatValue(k,z)}}});let _=1,F=-1/0,R=1/0;l&&l.length>0&&(F=Math.min(...l.map(k=>k.low)),R=Math.max(...l.map(k=>k.high)));const G=new Map;e.forEach((k,z)=>{k.paneIndex===0&&!k.collapsed&&l&&l.length>0&&Object.entries(k.plots).forEach(([E,$])=>{const H=`${z}::${E}`,O=["background","barcolor","char"],Y=$.options.style==="shape"&&($.options.location==="abovebar"||$.options.location==="AboveBar"||$.options.location==="belowbar"||$.options.location==="BelowBar");if(O.includes($.options.style)){G.has(H)||(G.set(H,_),_++);return}if($.options.style==="shape"&&!Y){G.has(H)||(G.set(H,_),_++);return}const V=[];if($.data&&Object.values($.data).forEach(T=>{typeof T=="number"&&!isNaN(T)&&isFinite(T)&&V.push(T)}),V.length>0){const T=Math.min(...V),N=Math.max(...V),it=N-T,nt=R-F,X=T>=F*.5&&N<=R*1.5,ot=it>nt*.01;X&&ot||G.has(H)||(G.set(H,_),_++)}})});const Q=G.size>0?_-1:0,U=new Set;G.forEach((k,z)=>{e.forEach(E=>{Object.entries(E.plots).forEach(([$,H])=>{`${E.id}::${$}`===z&&["background","barcolor","char"].includes(H.options.style)&&U.add(k)})})});for(let k=0;k<Q;k++){const z=k+1,E=U.has(z);M.push({position:"left",scale:!E,min:E?0:Z.createMinFunction(h),max:E?1:Z.createMaxFunction(h),gridIndex:0,show:!1,splitLine:{show:!1},axisLine:{show:!1},axisLabel:{show:!1}})}const tt=_;A.forEach((k,z)=>{M.push({position:"right",scale:!0,min:Z.createMinFunction(h),max:Z.createMaxFunction(h),gridIndex:z+1,splitLine:{show:!k.isCollapsed,lineStyle:{color:"#334155",opacity:.3}},axisLabel:{show:!k.isCollapsed,color:"#94a3b8",fontFamily:i.fontFamily||"sans-serif",fontSize:10,formatter:E=>{if(i.yAxisLabelFormatter)return i.yAxisLabelFormatter(E);const $=i.yAxisDecimalPlaces!==void 0?i.yAxisDecimalPlaces:Z.autoDetectDecimals(l);return Z.formatValue(E,$)}},axisLine:{show:!k.isCollapsed,lineStyle:{color:"#334155"}}})});const et=[];return p&&((i.dataZoom?.zoomOnTouch??!0)&&et.push({type:"inside",xAxisIndex:b,start:o,end:u,filterMode:"weakFilter"}),f==="top"?et.push({type:"slider",xAxisIndex:b,top:"1%",height:r+"%",start:o,end:u,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1,filterMode:"weakFilter"}):et.push({type:"slider",xAxisIndex:b,bottom:"1%",height:r+"%",start:o,end:u,borderColor:"#334155",textStyle:{color:"#cbd5e1"},brushSelect:!1,filterMode:"weakFilter"})),{grid:v,xAxis:C,yAxis:M,dataZoom:et,paneLayout:A,mainPaneHeight:I,mainPaneTop:a,pixelToPercent:d,overlayYAxisMap:G,separatePaneYAxisOffset:tt}}static calculateMaximized(t,e,i){return{grid:[],xAxis:[],yAxis:[],dataZoom:[],paneLayout:[],mainPaneHeight:0,mainPaneTop:0,pixelToPercent:0}}}class Lt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:l,plotOptions:d}=t,h="#2962ff";return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(c,y)=>{const p=c.dataIndex;if(p===0)return;const f=y.value(1),r=y.value(2);if(f===null||isNaN(f)||r===null||isNaN(r))return;const o=y.coord([p-1,r]),u=y.coord([p,f]);return{type:"line",shape:{x1:o[0],y1:o[1],x2:u[0],y2:u[1]},style:{stroke:l[p]||d.color||h,lineWidth:d.linewidth||1},silent:!0}},data:n.map((c,y)=>[y,c,y>0?n[y-1]:null])}}}class Et{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:l,plotOptions:d}=t,h="#2962ff";return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(c,y)=>{const p=y.value(0),f=y.value(1);if(isNaN(f)||f===null)return;const r=y.coord([p,f]),o=y.size([1,0])[0];return{type:"line",shape:{x1:r[0]-o/2,y1:r[1],x2:r[0]+o/2,y2:r[1]},style:{stroke:l[c.dataIndex]||d.color||h,lineWidth:d.linewidth||1},silent:!0}},data:n.map((c,y)=>[y,c])}}}class St{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:l,plotOptions:d}=t;return{name:e,type:"bar",xAxisIndex:i,yAxisIndex:s,data:n.map((h,c)=>({value:h,itemStyle:l[c]?{color:l[c]}:void 0})),itemStyle:{color:d.color||"#2962ff"}}}}const yt=new Map;function $t(g,t="#00da3c",e="64px"){if(typeof document>"u")return"";const i=`${g}-${t}-${e}`;if(yt.has(i))return yt.get(i);const s=document.createElement("canvas"),n=s.getContext("2d");if(s.width=32,s.height=32,n){n.font="bold "+e+" Arial",n.fillStyle=t,n.textAlign="center",n.textBaseline="middle",n.fillText(g,16,16);const l=s.toDataURL("image/png");return yt.set(i,l),l}return""}class gt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:l,plotOptions:d}=t,h="#2962ff",c=d.style;if(c==="char")return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,symbolSize:0,data:n.map((p,f)=>({value:[f,p],itemStyle:{opacity:0}})),silent:!0};const y=n.map((p,f)=>{if(p===null)return null;const r=l[f]||d.color||h,o={value:[f,p],itemStyle:{color:r}};return c==="cross"?(o.symbol=`image://${$t("+",r,"24px")}`,o.symbolSize=16):(o.symbol="circle",o.symbolSize=6),o}).filter(p=>p!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:y}}}class kt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:l,optionsArray:d,plotOptions:h}=t,c="#2962ff",y=h.style==="candle",p=n.map((f,r)=>{if(f===null||!Array.isArray(f)||f.length!==4)return null;const[o,u,a,x]=f,m=d[r]||{},S=m.color||l[r]||h.color||c,I=m.wickcolor||h.wickcolor||S,A=m.bordercolor||h.bordercolor||I;return[r,o,x,a,u,S,I,A]}).filter(f=>f!==null);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(f,r)=>{const o=r.value(0),u=r.value(1),a=r.value(2),x=r.value(3),m=r.value(4),S=r.value(5),I=r.value(6),A=r.value(7);if(isNaN(u)||isNaN(a)||isNaN(x)||isNaN(m))return null;const v=r.coord([o,0])[0],b=r.coord([o,u])[1],C=r.coord([o,a])[1],w=r.coord([o,x])[1],M=r.coord([o,m])[1],P=r.size([1,0])[0]*.6;if(y){const D=Math.min(b,C),_=Math.max(b,C),F=Math.abs(C-b);return{type:"group",children:[{type:"line",shape:{x1:v,y1:M,x2:v,y2:D},style:{stroke:I,lineWidth:1}},{type:"line",shape:{x1:v,y1:_,x2:v,y2:w},style:{stroke:I,lineWidth:1}},{type:"rect",shape:{x:v-P/2,y:D,width:P,height:F||1},style:{fill:S,stroke:A,lineWidth:1}}]}}else{const D=P*.5;return{type:"group",children:[{type:"line",shape:{x1:v,y1:w,x2:v,y2:M},style:{stroke:S,lineWidth:1}},{type:"line",shape:{x1:v-D,y1:b,x2:v,y2:b},style:{stroke:S,lineWidth:1}},{type:"line",shape:{x1:v,y1:C,x2:v+D,y2:C},style:{stroke:S,lineWidth:1}}]}}},data:p}}}class lt{static getShapeSymbol(t){switch(t){case"arrowdown":case"shape_arrow_down":return"path://M12 24l-12-12h8v-12h8v12h8z";case"arrowup":case"shape_arrow_up":return"path://M12 0l12 12h-8v12h-8v-12h-8z";case"circle":case"shape_circle":return"circle";case"cross":case"shape_cross":return"path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z";case"diamond":case"shape_diamond":return"diamond";case"flag":case"shape_flag":return"path://M6 2v20h2v-8h12l-2-6 2-6h-12z";case"labeldown":case"shape_label_down":return"path://M2 1h20a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-8l-2 3-2-3h-8a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1z";case"labelleft":case"shape_label_left":return"path://M0 10l3-3v-5a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-18a1 1 0 0 1-1-1v-5z";case"labelright":case"shape_label_right":return"path://M24 10l-3-3v-5a1 1 0 0 0-1-1h-18a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h18a1 1 0 0 0 1-1v-5z";case"labelup":case"shape_label_up":return"path://M12 1l2 3h8a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-20a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1h8z";case"square":case"shape_square":return"rect";case"triangledown":case"shape_triangle_down":return"path://M12 21l-10-18h20z";case"triangleup":case"shape_triangle_up":return"triangle";case"xcross":case"shape_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(t){return 0}static getShapeSize(t,e,i){if(e!==void 0&&i!==void 0)return[e,i];let s;switch(t){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 e!==void 0?[e,e]:i!==void 0?[i,i]:s}static getLabelConfig(t,e){switch(e){case"abovebar":case"AboveBar":return{position:"top",distance:5};case"belowbar":case"BelowBar":return{position:"bottom",distance:5};case"top":case"Top":return{position:"bottom",distance:5};case"bottom":case"Bottom":return{position:"top",distance:5};case"absolute":case"Absolute":default:return t==="labelup"||t==="labeldown"||t==="shape_label_up"||t==="shape_label_down"?{position:"inside",distance:0}:{position:"top",distance:5}}}}class Tt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:l,optionsArray:d,plotOptions:h,candlestickData:c}=t,y="#2962ff",p=n.map((f,r)=>{const o=d[r]||{},u=h,a=o.location||u.location||"absolute";if(a!=="absolute"&&a!=="Absolute"&&!f||f==null)return null;const x=o.color||u.color||y,m=o.shape||u.shape||"circle",S=o.size||u.size||"normal",I=o.text||u.text,A=o.textcolor||u.textcolor||"white",v=o.width||u.width,b=o.height||u.height;let C=f,w=[0,0];a==="abovebar"||a==="AboveBar"||a==="ab"?(c&&c[r]&&(C=c[r].high),w=[0,"-150%"]):a==="belowbar"||a==="BelowBar"||a==="bl"?(c&&c[r]&&(C=c[r].low),w=[0,"150%"]):a==="top"||a==="Top"?(C=f,w=[0,0]):(a==="bottom"||a==="Bottom")&&(C=f,w=[0,0]);const M=lt.getShapeSymbol(m),P=lt.getShapeSize(S,v,b),D=lt.getShapeRotation(m);let _=P;m.includes("label")&&(Array.isArray(P)?_=[P[0]*2.5,P[1]*2.5]:_=P*2.5);const F=lt.getLabelConfig(m,a);return{value:[r,C],symbol:M,symbolSize:_,symbolRotate:D,symbolOffset:w,itemStyle:{color:x},label:{show:!!I,position:F.position,distance:F.distance,formatter:I,color:A,fontSize:10,fontWeight:"bold"}}}).filter(f=>f!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:p}}}class Nt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,colorArray:l}=t;return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,z:-10,renderItem:(d,h)=>{const c=h.value(0);if(isNaN(c))return;const y=h.coord([c,.5]),p=h.size([1,0])[0],f=d.coordSys,r=y[0]-p/2,o=l[d.dataIndex],u=h.value(1);if(!(!o||u===null||u===void 0||isNaN(u)))return{type:"rect",shape:{x:r,y:f.y,width:p,height:f.height},style:{fill:o,opacity:.3},silent:!0}},data:n.map((d,h)=>[h,d!=null&&!isNaN(d)?.5:null])}}}class xt{static parseColor(t){if(!t)return{color:"#888888",opacity:.2};const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const i=e[1],s=e[2],n=e[3],l=e[4]?parseFloat(e[4]):1;return{color:`rgb(${i},${s},${n})`,opacity:l}}return{color:t,opacity:.3}}}class Ft{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,plotOptions:n,plotDataArrays:l,indicatorId:d,plotName:h}=t,c=t.dataArray.length,y=n.plot1?`${d}::${n.plot1}`:null,p=n.plot2?`${d}::${n.plot2}`:null;if(!y||!p)return console.warn(`Fill plot "${h}" missing plot1 or plot2 reference`),null;const f=l?.get(y),r=l?.get(p);if(!f||!r)return console.warn(`Fill plot "${h}" references non-existent plots: ${n.plot1}, ${n.plot2}`),null;const{color:o,opacity:u}=xt.parseColor(n.color||"rgba(128, 128, 128, 0.2)"),a=[];for(let x=0;x<c;x++){const m=f[x],S=r[x],I=x>0?f[x-1]:null,A=x>0?r[x-1]:null;a.push([x,m,S,I,A])}return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,z:1,renderItem:(x,m)=>{const S=x.dataIndex;if(S===0)return null;const I=m.value(1),A=m.value(2),v=m.value(3),b=m.value(4);if(I===null||A===null||v===null||b===null||isNaN(I)||isNaN(A)||isNaN(v)||isNaN(b))return null;const C=m.coord([S-1,v]),w=m.coord([S,I]),M=m.coord([S,A]),P=m.coord([S-1,b]);return{type:"polygon",shape:{points:[C,w,M,P]},style:{fill:o,opacity:u},silent:!0}},data:a}}}class Ot{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,candlestickData:l,dataIndexOffset:d}=t,h=d||0,c=[];for(let p=0;p<n.length;p++){const f=n[p];if(!f)continue;const r=Array.isArray(f)?f:[f];for(const o of r)o&&typeof o=="object"&&!o._deleted&&c.push(o)}const y=c.map(p=>{const f=p.text||"",r=p.color||"#2962ff",o=p.textcolor||"#ffffff",u=p.yloc||"price",a=p.style||"style_label_down",x=p.size||"normal",m=p.textalign||"align_center",S=p.tooltip||"",I=this.styleToShape(a),A=p.xloc==="bar_index"||p.xloc==="bi"?p.x+h:p.x;let v=p.y,b=[0,0];u==="abovebar"||u==="AboveBar"||u==="ab"?(l&&l[A]&&(v=l[A].high),b=[0,"-150%"]):(u==="belowbar"||u==="BelowBar"||u==="bl")&&(l&&l[A]&&(v=l[A].low),b=[0,"150%"]);const C=lt.getShapeSymbol(I),w=lt.getShapeSize(x),M=this.getSizePx(x);let P;const D=I==="labeldown"||I==="shape_label_down"||I==="labelup"||I==="shape_label_up"||I==="labelleft"||I==="labelright";let _=[0,0];if(D){const Q=f.length*M*.65,U=M*2.5,tt=Math.max(U,Q+M*1.6),et=M*2.8,k=3/24;if(I==="labelleft"||I==="labelright"){const z=tt/(1-k);P=[z,et];const E=typeof b[0]=="string"?0:b[0];I==="labelleft"?(b=[E+z*.42,b[1]],_=[z*k*.5,0]):(b=[E-z*.42,b[1]],_=[-z*k*.5,0])}else{const z=et/(1-k);P=[tt,z],I==="labeldown"?(b=[b[0],typeof b[1]=="string"?b[1]:b[1]-z*.42],_=[0,-z*k*.5]):(b=[b[0],typeof b[1]=="string"?b[1]:b[1]+z*.42],_=[0,z*k*.5])}}else I==="none"?P=0:Array.isArray(w)?P=[w[0]*1.5,w[1]*1.5]:P=w*1.5;const F=this.getLabelPosition(a,u),R=F==="inside"||F.startsWith("inside"),G={value:[A,v],symbol:C,symbolSize:P,symbolOffset:b,itemStyle:{color:r},label:{show:!!f,position:F,distance:R?0:5,offset:_,formatter:f,color:o,fontSize:M,fontWeight:"bold",align:R?"center":m==="align_left"||m==="left"?"left":m==="align_right"||m==="right"?"right":"center",verticalAlign:"middle",padding:[2,6]}};return S&&(G.tooltip={formatter:S}),G}).filter(p=>p!==null);return{name:e,type:"scatter",xAxisIndex:i,yAxisIndex:s,data:y,z:20}}styleToShape(t){switch(t.startsWith("style_")?t.substring(6):t){case"label_down":return"labeldown";case"label_up":return"labelup";case"label_left":return"labelleft";case"label_right":return"labelright";case"label_lower_left":return"labeldown";case"label_lower_right":return"labeldown";case"label_upper_left":return"labelup";case"label_upper_right":return"labelup";case"label_center":return"labeldown";case"circle":return"circle";case"square":return"square";case"diamond":return"diamond";case"flag":return"flag";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"cross":return"cross";case"xcross":return"xcross";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"text_outline":return"none";case"none":return"none";default:return"labeldown"}}getLabelPosition(t,e){switch(t.startsWith("style_")?t.substring(6):t){case"label_down":case"label_up":case"label_left":case"label_right":case"label_lower_left":case"label_lower_right":case"label_upper_left":case"label_upper_right":case"label_center":return"inside";case"text_outline":case"none":return e==="abovebar"||e==="AboveBar"||e==="ab"?"top":e==="belowbar"||e==="BelowBar"||e==="bl"?"bottom":"top";default:return e==="belowbar"||e==="BelowBar"||e==="bl"?"bottom":"top"}}getSizePx(t){switch(t){case"tiny":return 8;case"small":return 9;case"normal":case"auto":return 10;case"large":return 12;case"huge":return 14;default:return 10}}}class Zt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:l}=t,d=l||0,h="#2962ff",c=[];for(let o=0;o<n.length;o++){const u=n[o];if(!u)continue;const a=Array.isArray(u)?u:[u];for(const x of a)x&&typeof x=="object"&&!x._deleted&&c.push(x)}if(c.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};let y=1/0,p=-1/0;for(const o of c)o.y1<y&&(y=o.y1),o.y1>p&&(p=o.y1),o.y2<y&&(y=o.y2),o.y2>p&&(p=o.y2);const f=(t.candlestickData?.length||0)+d,r=Math.max(0,f-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(o,u)=>{const a=[];for(const x of c){if(x._deleted)continue;const m=x.xloc==="bar_index"||x.xloc==="bi"?d:0;let S=u.coord([x.x1+m,x.y1]),I=u.coord([x.x2+m,x.y2]);const A=x.extend||"none";if(A!=="none"){const w=o.coordSys;[S,I]=this.extendLine(S,I,A,w.x,w.x+w.width,w.y,w.y+w.height)}const v=x.color||h,b=x.width||1;a.push({type:"line",shape:{x1:S[0],y1:S[1],x2:I[0],y2:I[1]},style:{stroke:v,lineWidth:b,lineDash:this.getDashPattern(x.style)}});const C=x.style||"style_solid";if(C==="style_arrow_left"||C==="style_arrow_both"){const w=this.arrowHead(I,S,b,v);w&&a.push(w)}if(C==="style_arrow_right"||C==="style_arrow_both"){const w=this.arrowHead(S,I,b,v);w&&a.push(w)}}return{type:"group",children:a}},data:[[0,r,y,p]],clip:!0,encode:{x:[0,1],y:[2,3]},z:15,silent:!0,emphasis:{disabled:!0}}}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}extendLine(t,e,i,s,n,l,d){const h=e[0]-t[0],c=e[1]-t[1];if(h===0&&c===0)return[t,e];const y=(r,o)=>{let u=1/0;if(o[0]!==0){const a=o[0]>0?(n-r[0])/o[0]:(s-r[0])/o[0];u=Math.min(u,a)}if(o[1]!==0){const a=o[1]>0?(d-r[1])/o[1]:(l-r[1])/o[1];u=Math.min(u,a)}return isFinite(u)||(u=0),[r[0]+u*o[0],r[1]+u*o[1]]};let p=t,f=e;return(i==="right"||i==="both")&&(f=y(t,[h,c])),(i==="left"||i==="both")&&(p=y(e,[-h,-c])),[p,f]}arrowHead(t,e,i,s){const n=e[0]-t[0],l=e[1]-t[1],d=Math.sqrt(n*n+l*l);if(d<1)return null;const h=Math.max(8,i*4),c=n/d,y=l/d,p=e[0]-c*h,f=e[1]-y*h,r=-y*h*.4,o=c*h*.4;return{type:"polygon",shape:{points:[[e[0],e[1]],[p+r,f+o],[p-r,f-o]]},style:{fill:s}}}}class Wt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:l}=t,d=l||0,h=[];for(let r=0;r<n.length;r++){const o=n[r];if(!o)continue;const u=Array.isArray(o)?o:[o];for(const a of u){if(!a||typeof a!="object"||a._deleted)continue;const x=a.line1,m=a.line2;!x||!m||x._deleted||m._deleted||h.push(a)}}if(h.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};let c=1/0,y=-1/0;for(const r of h)for(const o of[r.line1.y1,r.line1.y2,r.line2.y1,r.line2.y2])o<c&&(c=o),o>y&&(y=o);const p=(t.candlestickData?.length||0)+d,f=Math.max(0,p-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(r,o)=>{const u=[];for(const a of h){if(a._deleted)continue;const x=a.line1,m=a.line2;if(!x||!m||x._deleted||m._deleted)continue;const S=x.xloc==="bar_index"||x.xloc==="bi"?d:0,I=m.xloc==="bar_index"||m.xloc==="bi"?d:0;let A=o.coord([x.x1+S,x.y1]),v=o.coord([x.x2+S,x.y2]),b=o.coord([m.x1+I,m.y1]),C=o.coord([m.x2+I,m.y2]);const w=x.extend||"none",M=m.extend||"none";if(w!=="none"||M!=="none"){const _=r.coordSys,F=_.x,R=_.x+_.width,G=_.y,Q=_.y+_.height;w!=="none"&&([A,v]=this.extendLine(A,v,w,F,R,G,Q)),M!=="none"&&([b,C]=this.extendLine(b,C,M,F,R,G,Q))}const{color:P,opacity:D}=xt.parseColor(a.color||"rgba(128, 128, 128, 0.2)");u.push({type:"polygon",shape:{points:[A,v,C,b]},style:{fill:P,opacity:D},silent:!0})}return{type:"group",children:u}},data:[[0,f,c,y]],clip:!0,encode:{x:[0,1],y:[2,3]},z:10,silent:!0,emphasis:{disabled:!0}}}extendLine(t,e,i,s,n,l,d){const h=e[0]-t[0],c=e[1]-t[1];if(h===0&&c===0)return[t,e];const y=(r,o)=>{let u=1/0;if(o[0]!==0){const a=o[0]>0?(n-r[0])/o[0]:(s-r[0])/o[0];u=Math.min(u,a)}if(o[1]!==0){const a=o[1]>0?(d-r[1])/o[1]:(l-r[1])/o[1];u=Math.min(u,a)}return isFinite(u)||(u=0),[r[0]+u*o[0],r[1]+u*o[1]]};let p=t,f=e;return(i==="right"||i==="both")&&(f=y(t,[h,c])),(i==="left"||i==="both")&&(p=y(e,[-h,-c])),[p,f]}}class Gt{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:l}=t,d=l||0,h=[];for(let r=0;r<n.length;r++){const o=n[r];if(!o)continue;const u=Array.isArray(o)?o:[o];for(const a of u)a&&typeof a=="object"&&!a._deleted&&a.points&&a.points.length>=2&&h.push(a)}if(h.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};let c=1/0,y=-1/0;for(const r of h)for(const o of r.points){const u=o.price??0;u<c&&(c=u),u>y&&(y=u)}const p=(t.candlestickData?.length||0)+d,f=Math.max(0,p-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(r,o)=>{const u=[];for(const a of h){if(a._deleted)continue;const x=a.points;if(!x||x.length<2)continue;const m=a.xloc==="bi"||a.xloc==="bar_index",S=m?d:0,I=[];for(const C of x){const w=m?(C.index??0)+S:C.time??0,M=C.price??0;I.push(o.coord([w,M]))}if(I.length<2)continue;const A=a.line_color||"#2962ff",v=a.line_width||1,b=this.getDashPattern(a.line_style);if(a.fill_color&&a.fill_color!==""&&a.fill_color!=="na"){const{color:C,opacity:w}=xt.parseColor(a.fill_color);if(a.curved){const M=this.buildCurvedPath(I,a.closed);u.push({type:"path",shape:{pathData:M+" Z"},style:{fill:C,opacity:w,stroke:"none"},silent:!0})}else u.push({type:"polygon",shape:{points:I},style:{fill:C,opacity:w,stroke:"none"},silent:!0})}if(a.curved){const C=this.buildCurvedPath(I,a.closed);u.push({type:"path",shape:{pathData:C},style:{fill:"none",stroke:A,lineWidth:v,lineDash:b},silent:!0})}else{const C=a.closed?[...I,I[0]]:I;u.push({type:"polyline",shape:{points:C},style:{fill:"none",stroke:A,lineWidth:v,lineDash:b},silent:!0})}}return{type:"group",children:u}},data:[[0,f,c,y]],clip:!0,encode:{x:[0,1],y:[2,3]},z:12,silent:!0,emphasis:{disabled:!0}}}buildCurvedPath(t,e){const i=t.length;if(i<2)return"";if(i===2)return`M ${t[0][0]} ${t[0][1]} L ${t[1][0]} ${t[1][1]}`;const s=.5;let n=`M ${t[0][0]} ${t[0][1]}`;const l=h=>e?t[(h%i+i)%i]:h<0?t[0]:h>=i?t[i-1]:t[h],d=e?i:i-1;for(let h=0;h<d;h++){const c=l(h-1),y=l(h),p=l(h+1),f=l(h+2),r=y[0]+(p[0]-c[0])*s/3,o=y[1]+(p[1]-c[1])*s/3,u=p[0]-(f[0]-y[0])*s/3,a=p[1]-(f[1]-y[1])*s/3;n+=` C ${r} ${o}, ${u} ${a}, ${p[0]} ${p[1]}`}return e&&(n+=" Z"),n}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}}function mt(g){if(!g||typeof g!="string")return g;if(g.startsWith("#")){const t=g.slice(1);if(t.length===8){const e=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16),n=parseInt(t.slice(6,8),16)/255;return`rgba(${e},${i},${s},${n.toFixed(3)})`}}return g}class Ht{render(t){const{seriesName:e,xAxisIndex:i,yAxisIndex:s,dataArray:n,dataIndexOffset:l}=t,d=l||0,h=[];for(let r=0;r<n.length;r++){const o=n[r];if(!o)continue;const u=Array.isArray(o)?o:[o];for(const a of u)a&&typeof a=="object"&&!a._deleted&&h.push(a)}if(h.length===0)return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,data:[],silent:!0};let c=1/0,y=-1/0;for(const r of h)r.top<c&&(c=r.top),r.top>y&&(y=r.top),r.bottom<c&&(c=r.bottom),r.bottom>y&&(y=r.bottom);const p=(t.candlestickData?.length||0)+d,f=Math.max(0,p-1);return{name:e,type:"custom",xAxisIndex:i,yAxisIndex:s,renderItem:(r,o)=>{const u=[];for(const a of h){if(a._deleted)continue;const x=a.xloc==="bar_index"||a.xloc==="bi"?d:0,m=o.coord([a.left+x,a.top]),S=o.coord([a.right+x,a.bottom]);let I=m[0],A=m[1],v=S[0]-m[0],b=S[1]-m[1];const C=a.extend||"none";if(C!=="none"){const D=r.coordSys;(C==="left"||C==="both")&&(I=D.x,v=C==="both"?D.width:S[0]-D.x),(C==="right"||C==="both")&&C==="right"&&(v=D.x+D.width-m[0])}const w=mt(a.bgcolor)||"#2962ff";u.push({type:"rect",shape:{x:I,y:A,width:v,height:b},style:{fill:w}});const M=mt(a.border_color)||"#2962ff",P=a.border_width??1;if(P>0&&u.push({type:"rect",shape:{x:I,y:A,width:v,height:b},style:{fill:"none",stroke:M,lineWidth:P,lineDash:this.getDashPattern(a.border_style)}}),a.text){const D=this.getTextX(I,v,a.text_halign),_=this.getTextY(A,b,a.text_valign);u.push({type:"text",style:{x:D,y:_,text:a.text,fill:mt(a.text_color)||"#000000",fontSize:this.getSizePixels(a.text_size),fontFamily:a.text_font_family==="monospace"?"monospace":"sans-serif",fontWeight:a.text_formatting==="format_bold"?"bold":"normal",fontStyle:a.text_formatting==="format_italic"?"italic":"normal",textAlign:this.mapHAlign(a.text_halign),textVerticalAlign:this.mapVAlign(a.text_valign)}})}}return{type:"group",children:u}},data:[[0,f,c,y]],clip:!0,encode:{x:[0,1],y:[2,3]},z:14,silent:!0,emphasis:{disabled:!0}}}getDashPattern(t){switch(t){case"style_dotted":return[2,2];case"style_dashed":return[6,4];default:return}}getSizePixels(t){if(typeof t=="number"&&t>0)return t;switch(t){case"auto":case"size.auto":return 12;case"tiny":case"size.tiny":return 8;case"small":case"size.small":return 10;case"normal":case"size.normal":return 14;case"large":case"size.large":return 20;case"huge":case"size.huge":return 36;default:return 12}}mapHAlign(t){switch(t){case"left":case"text.align_left":return"left";case"right":case"text.align_right":return"right";case"center":case"text.align_center":default:return"center"}}mapVAlign(t){switch(t){case"top":case"text.align_top":return"top";case"bottom":case"text.align_bottom":return"bottom";case"center":case"text.align_center":default:return"middle"}}getTextX(t,e,i){switch(i){case"left":case"text.align_left":return t+4;case"right":case"text.align_right":return t+e-4;case"center":case"text.align_center":default:return t+e/2}}getTextY(t,e,i){switch(i){case"top":case"text.align_top":return t+4;case"bottom":case"text.align_bottom":return t+e-4;case"center":case"text.align_center":default:return t+e/2}}}var Bt=Object.defineProperty,Rt=(g,t,e)=>t in g?Bt(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,jt=(g,t,e)=>(Rt(g,typeof t!="symbol"?t+"":t,e),e);const B=class{static register(t,e){this.renderers.set(t,e)}static get(t){return this.renderers.get(t)||this.renderers.get("line")}};jt(B,"renderers",new Map),B.register("line",new Lt),B.register("step",new Et),B.register("histogram",new St),B.register("columns",new St),B.register("circles",new gt),B.register("cross",new gt),B.register("char",new gt),B.register("bar",new kt),B.register("candle",new kt),B.register("shape",new Tt),B.register("background",new Nt),B.register("fill",new Ft),B.register("label",new Ot),B.register("drawing_line",new Zt),B.register("linefill",new Wt),B.register("drawing_polyline",new Gt),B.register("drawing_box",new Ht);let Yt=B;var Vt=Object.defineProperty,qt=(g,t,e)=>t in g?Vt(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,Xt=(g,t,e)=>(qt(g,typeof t!="symbol"?t+"":t,e),e);const Pt=class At{static buildCandlestickSeries(t,e,i){const s=e.upColor||"#00da3c",n=e.downColor||"#ec0000",l=t.map(h=>[h.open,h.close,h.low,h.high]);if(i&&i>l.length){const h=i-l.length;for(let c=0;c<h;c++)l.push(null)}let d;if(e.lastPriceLine?.visible!==!1&&t.length>0){const h=t[t.length-1],c=h.close,y=h.close>=h.open,p=e.lastPriceLine?.color||(y?s:n);let f=e.lastPriceLine?.lineStyle||"dashed";f.startsWith("linestyle_")&&(f=f.replace("linestyle_",""));const r=e.yAxisDecimalPlaces!==void 0?e.yAxisDecimalPlaces:Z.autoDetectDecimals(t);d={symbol:["none","none"],precision:r,data:[{yAxis:c,label:{show:!0,position:"end",formatter:o=>e.yAxisLabelFormatter?e.yAxisLabelFormatter(o.value):Z.formatValue(o.value,r),color:"#fff",backgroundColor:p,padding:[2,4],borderRadius:2,fontSize:11,fontWeight:"bold"},lineStyle:{color:p,type:f,width:1,opacity:.8}}],animation:!1,silent:!0}}return{type:"candlestick",name:e.title||"Market",data:l,itemStyle:{color:s,color0:n,borderColor:s,borderColor0:n},markLine:d,xAxisIndex:0,yAxisIndex:0,z:5}}static buildIndicatorSeries(t,e,i,s,n=0,l,d,h=1){const c=[],y=new Array(s).fill(null),p=new Map;return t.forEach((f,r)=>{f.collapsed||Object.keys(f.plots).sort((o,u)=>{const a=f.plots[o],x=f.plots[u],m=a.options.style==="fill",S=x.options.style==="fill";return m&&!S?1:!m&&S?-1:0}).forEach(o=>{const u=f.plots[o],a=`${r}::${o}`;let x=0,m=0;const S=u.options.overlay;if(f.paneIndex===0||S===!0)x=0,d&&d.has(a)?m=d.get(a):m=0;else{const C=i.findIndex(w=>w.index===f.paneIndex);C!==-1&&(x=C+1,m=h+C)}const I=new Array(s).fill(null),A=new Array(s).fill(null),v=new Array(s).fill(null);if(u.data?.forEach(C=>{const w=e.get(C.time);if(w!==void 0){const M=C.options?.offset??u.options.offset??0,P=w+n+M;if(P>=0&&P<s){let D=C.value;const _=C.options?.color,F=C.options!=null&&"color"in C.options,R=_===null||_==="na"||_==="NaN"||typeof _=="number"&&isNaN(_)||F&&_===void 0;R&&(D=null),I[P]=D,A[P]=R?null:_||u.options.color||At.DEFAULT_COLOR,v[P]=C.options||{}}}}),p.set(`${r}::${o}`,I),u.options?.style?.startsWith("style_")&&(u.options.style=u.options.style.replace("style_","")),u.options.style==="barcolor"){u.data?.forEach(C=>{const w=e.get(C.time);if(w!==void 0){const M=C.options?.offset??u.options.offset??0,P=w+n+M;if(P>=0&&P<s){const D=C.options?.color||u.options.color||At.DEFAULT_COLOR;!(D===null||D==="na"||D==="NaN"||typeof D=="number"&&isNaN(D))&&C.value!==null&&C.value!==void 0&&(y[P]=D)}}});return}if(u.options.style==="table")return;const b=Yt.get(u.options.style).render({seriesName:a,xAxisIndex:x,yAxisIndex:m,dataArray:I,colorArray:A,optionsArray:v,plotOptions:u.options,candlestickData:l,plotDataArrays:p,indicatorId:r,plotName:o,dataIndexOffset:n});b&&c.push(b)})}),{series:c,barColors:y}}};Xt(Pt,"DEFAULT_COLOR","#2962ff");let ut=Pt;class Ut{static build(t,e,i,s=!1,n=null){const l=[],d=t.pixelToPercent,h=t.mainPaneTop;if(!n||n==="main"){const c=10*d;if(l.push({type:"text",left:"8.5%",top:h+c+"%",z:10,style:{text:e.title||"Market",fill:e.titleColor||"#fff",font:`bold 16px ${e.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}}),e.watermark!==!1){const p=t.mainPaneTop+t.mainPaneHeight;l.push({type:"text",right:"11%",top:p-3+"%",z:10,style:{text:"QFChart",fill:e.fontColor||"#cbd5e1",font:"bold 16px sans-serif",opacity:.1},cursor:"pointer",onclick:()=>{window.open("https://quantforge.org","_blank")}})}const y=[];if(e.controls?.collapse&&y.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 ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),e.controls?.maximize){const p=n==="main",f=e.controls?.collapse?25:0;y.push({type:"group",x:f,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:p?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}if(e.controls?.fullscreen){let p=0;e.controls?.collapse&&(p+=25),e.controls?.maximize&&(p+=25),y.push({type:"group",x:p,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 ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}y.length>0&&l.push({type:"group",right:"10.5%",top:h+"%",children:y})}return t.paneLayout.forEach(c=>{if(n&&c.indicatorId!==n)return;l.push({type:"text",left:"8.5%",top:c.top+10*d+"%",z:10,style:{text:c.indicatorId||"",fill:c.titleColor||"#fff",font:`bold 12px ${e.fontFamily||"sans-serif"}`,textVerticalAlign:"top"}});const y=[];if(c.controls?.collapse&&y.push({type:"group",children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>c.indicatorId&&i(c.indicatorId,"collapse")},{type:"text",style:{text:c.isCollapsed?"+":"\u2212",fill:"#cbd5e1",font:`bold 14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]}),c.controls?.maximize){const p=n===c.indicatorId,f=c.controls?.collapse?25:0;y.push({type:"group",x:f,children:[{type:"rect",shape:{width:20,height:20,r:2},style:{fill:"#334155",stroke:"#475569",lineWidth:1},onclick:()=>c.indicatorId&&i(c.indicatorId,"maximize")},{type:"text",style:{text:p?"\u2750":"\u25A1",fill:"#cbd5e1",font:`14px ${e.fontFamily}`,x:10,y:10,textAlign:"center",textVerticalAlign:"middle"},silent:!0}]})}y.length>0&&l.push({type:"group",right:"10.5%",top:c.top+"%",children:y})}),l}}class Jt{static format(t,e){if(!t||t.length===0)return"";const i=e.title||"Market",s=e.upColor||"#00da3c",n=e.downColor||"#ec0000",l=e.fontFamily||"sans-serif",d=t[0].axisValue;let h=`<div style="font-weight: bold; margin-bottom: 5px; color: #cbd5e1; font-family: ${l};">${d}</div>`;const c=t.find(p=>p.seriesType==="candlestick"),y=t.filter(p=>p.seriesType!=="candlestick");if(c){const[p,f,r,o,u]=c.value,a=r>=f?s:n;h+=`
18
+ <div style="margin-bottom: 8px; font-family: ${l};">
19
+ <div style="display:flex; justify-content:space-between; color:${a}; 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: ${d>=h?s:n}">${h}</span>
23
+ <span>Open:</span> <span style="text-align: right; color: ${r>=f?s:n}">${f}</span>
24
24
  <span>High:</span> <span style="text-align: right; color: ${s}">${u}</span>
25
- <span>Low:</span> <span style="text-align: right; color: ${n}">${p}</span>
26
- <span>Close:</span> <span style="text-align: right; color: ${d>=h?s:n}">${d}</span>
25
+ <span>Low:</span> <span style="text-align: right; color: ${n}">${o}</span>
26
+ <span>Close:</span> <span style="text-align: right; color: ${r>=f?s:n}">${r}</span>
27
27
  </div>
28
28
  </div>
29
- `}if(f.length>0){a+='<div style="border-top: 1px solid #334155; margin: 5px 0; padding-top: 5px;"></div>';const g={};f.forEach(h=>{const d=h.seriesName.split("::"),p=d.length>1?d[0]:"Unknown",u=d.length>1?d[1]:h.seriesName;g[p]||(g[p]=[]),g[p].push({...h,displayName:u})}),Object.keys(g).forEach(h=>{a+=`
30
- <div style="margin-top: 8px; font-family: ${o};">
31
- <div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${h}</div>
32
- `,g[h].forEach(d=>{let p=d.value;if(Array.isArray(p)&&(p=p[1]),p==null)return;const u=typeof p=="number"?p.toLocaleString(void 0,{maximumFractionDigits:4}):p;a+=`
29
+ `}if(y.length>0){h+='<div style="border-top: 1px solid #334155; margin: 5px 0; padding-top: 5px;"></div>';const p={};y.forEach(f=>{const r=f.seriesName.split("::"),o=r.length>1?r[0]:"Unknown",u=r.length>1?r[1]:f.seriesName;p[o]||(p[o]=[]),p[o].push({...f,displayName:u})}),Object.keys(p).forEach(f=>{h+=`
30
+ <div style="margin-top: 8px; font-family: ${l};">
31
+ <div style="font-weight:bold; color: #fff; margin-bottom: 2px;">${f}</div>
32
+ `,p[f].forEach(r=>{let o=r.value;if(Array.isArray(o)&&(o=o[1]),o==null)return;const u=typeof o=="number"?o.toLocaleString(void 0,{maximumFractionDigits:4}):o;h+=`
33
33
  <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; padding-left: 8px;">
34
- <div>${d.marker} <span style="color: #cbd5e1;">${d.displayName}</span></div>
34
+ <div>${r.marker} <span style="color: #cbd5e1;">${r.displayName}</span></div>
35
35
  <div style="font-size: 10px; color: #fff;padding-left:10px;">${u}</div>
36
- </div>`}),a+="</div>"})}return a}}var Yt=Object.defineProperty,Bt=(r,e,t)=>e in r?Yt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,at=(r,e,t)=>(Bt(r,typeof e!="symbol"?e+"":e,t),t);class Vt{constructor(e,t){at(this,"plugins",new Map),at(this,"activePluginId",null),at(this,"context"),at(this,"toolbarContainer"),at(this,"tooltipElement",null),at(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(),n=i.top+(i.height-s.height)/2,o=i.right+10;this.tooltipElement.style.top=`${n}px`,this.tooltipElement.style.left=`${o}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 qt=Object.defineProperty,Xt=(r,e,t)=>e in r?qt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Y=(r,e,t)=>(Xt(r,typeof e!="symbol"?e+"":e,t),t);class Ut{constructor(e){Y(this,"context"),Y(this,"isEditing",!1),Y(this,"currentDrawing",null),Y(this,"editingPointIndex",null),Y(this,"zr"),Y(this,"editGroup",null),Y(this,"editLine",null),Y(this,"editStartPoint",null),Y(this,"editEndPoint",null),Y(this,"isMovingShape",!1),Y(this,"dragStart",null),Y(this,"initialPixelPoints",[]),Y(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 n=this.context.coordinateConversion.dataToPixel(s);return n?{x:n.x,y:n.y}:{x:0,y:0}}),this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),Y(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))}),Y(this,"onMouseMove",t=>{if(!this.isEditing||!this.currentDrawing)return;const i=t.offsetX,s=t.offsetY;if(this.isMovingShape&&this.dragStart){const n=i-this.dragStart.x,o=s-this.dragStart.y,c={x:this.initialPixelPoints[0].x+n,y:this.initialPixelPoints[0].y+o},a={x:this.initialPixelPoints[1].x+n,y:this.initialPixelPoints[1].y+o};this.editLine.setShape({x1:c.x,y1:c.y,x2:a.x,y2:a.y}),this.editStartPoint.setShape({cx:c.x,cy:c.y}),this.editEndPoint.setShape({cx:a.x,cy:a.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})))}),Y(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 Z.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 Z.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 Z.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new Z.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,n=this.initialPixelPoints.map((o,c)=>{const a=o.x+i,l=o.y+s;return this.context.coordinateConversion.pixelToData({x:a,y:l})});n.every(o=>o!==null)&&n[0]&&n[1]&&(this.currentDrawing.points[0]=n[0],this.currentDrawing.points[1]=n[1],n[0].paneIndex!==void 0&&(this.currentDrawing.paneIndex=n[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 Qt=Object.defineProperty,Jt=(r,e,t)=>e in r?Qt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Kt=(r,e,t)=>(Jt(r,typeof e!="symbol"?e+"":e,t),t);class te{constructor(){Kt(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(n){console.error(`Error in EventBus handler for ${e}:`,n)}})}clear(){this.handlers.clear()}}var ee=Object.defineProperty,ie=(r,e,t)=>e in r?ee(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,E=(r,e,t)=>(ie(r,typeof e!="symbol"?e+"":e,t),t);class se{constructor(e,t={}){E(this,"chart"),E(this,"options"),E(this,"marketData",[]),E(this,"indicators",new Map),E(this,"timeToIndex",new Map),E(this,"pluginManager"),E(this,"drawingEditor"),E(this,"events",new te),E(this,"isMainCollapsed",!1),E(this,"maximizedPaneId",null),E(this,"countdownInterval",null),E(this,"selectedDrawingId",null),E(this,"drawings",[]),E(this,"coordinateConversion",{pixelToData:n=>{const o=this.chart.getOption();if(!o||!o.grid)return null;const c=o.grid.length;for(let a=0;a<c;a++)if(this.chart.containPixel({gridIndex:a},[n.x,n.y])){this.chart.convertFromPixel({seriesIndex:a},[n.x,n.y]);const l=this.chart.convertFromPixel({gridIndex:a},[n.x,n.y]);if(l)return{timeIndex:Math.round(l[0]),value:l[1],paneIndex:a}}return null},dataToPixel:n=>{const o=n.paneIndex||0,c=this.chart.convertToPixel({gridIndex:o},[n.timeIndex,n.value]);return c?{x:c[0],y:c[1]}:null}}),E(this,"upColor","#00da3c"),E(this,"downColor","#ec0000"),E(this,"defaultPadding",0),E(this,"padding"),E(this,"dataIndexOffset",0),E(this,"rootContainer"),E(this,"layoutContainer"),E(this,"toolbarContainer"),E(this,"leftSidebar"),E(this,"rightSidebar"),E(this,"chartContainer"),E(this,"onKeyDown",n=>{(n.key==="Delete"||n.key==="Backspace")&&this.selectedDrawingId&&(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.render())}),E(this,"onFullscreenChange",()=>{this.render()}),E(this,"isLocked",!1),E(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=Z.init(this.chartContainer),this.pluginManager=new Vt(this,this.toolbarContainer),this.drawingEditor=new Ut(this),this.chart.on("dataZoom",n=>{this.events.emit("chart:dataZoom",n);const o=this.options.databox?.triggerOn,c=this.options.databox?.position;o==="click"&&c==="floating"&&this.chart.dispatchAction({type:"hideTip"})}),this.chart.on("finished",n=>this.events.emit("chart:updated",n)),this.chart.getZr().on("mousedown",n=>this.events.emit("mouse:down",n)),this.chart.getZr().on("mousemove",n=>this.events.emit("mouse:move",n)),this.chart.getZr().on("mouseup",n=>this.events.emit("mouse:up",n)),this.chart.getZr().on("click",n=>this.events.emit("mouse:click",n));const i=this.chart.getZr(),s=i.setCursorStyle;i.setCursorStyle=function(n){n==="grab"&&(n="crosshair"),s.call(this,n)},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 n=parseInt(s[1]),o=this.drawings.filter(a=>(a.paneIndex||0)===n)[i.dataIndex];if(!o)return null;const c=i.event?.target?.name;return{drawing:o,targetName:c,paneIdx:n}};this.chart.on("mouseover",i=>{const s=t(i);if(!s)return;const n=i.event?.target?.parent;if(n){const o=s.drawing.id===this.selectedDrawingId;e&&(clearTimeout(e),e=null),o||n.children().forEach(c=>{c.name&&c.name.startsWith("point")&&c.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 o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:o}),this.chart.getZr().setCursorStyle("pointer")}}),this.chart.on("mouseout",i=>{const s=t(i);if(!s)return;const n=i.event?.target?.parent;if(s.drawing.id!==this.selectedDrawingId){if(e=setTimeout(()=>{if(n){if(this.selectedDrawingId===s.drawing.id)return;n.children().forEach(o=>{o.name&&o.name.startsWith("point")&&o.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const o=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:o})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=t(i);if(!s)return;const n=i.event?.event||i.event,o=n?.offsetX,c=n?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:o,y:c});else if(s.targetName?.startsWith("point")){const a=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:a,x:o,y:c})}}),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 n=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:click",{id:s.drawing.id,pointIndex:n})}}}),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(u=>{t.set(u.time,u)}),e.forEach(u=>{t.has(u.time),t.set(u.time,u)}),this.marketData=Array.from(t.values()).sort((u,b)=>u.time-b.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=pt.buildCandlestickSeries(this.marketData,this.options),n={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},o=[...Array(i).fill(n),...s.data,...Array(i).fill(n)],c=[...Array(i).fill(""),...this.marketData.map(u=>new Date(u.time).toLocaleString()),...Array(i).fill("")],a=this.chart.getOption(),l=vt.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData),f=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:g,barColors:h}=pt.buildIndicatorSeries(this.indicators,this.timeToIndex,l.paneLayout,c.length,i,f,l.overlayYAxisMap,l.separatePaneYAxisOffset),d=o.map((u,b)=>h[b]?{value:u.value||u,itemStyle:{color:h[b],color0:h[b],borderColor:h[b],borderColor0:h[b]}}:u),p={xAxis:a.xAxis.map((u,b)=>({data:c})),series:[{data:d,markLine:s.markLine},...g.map(u=>{const b={data:u.data};return u.renderItem&&(b.renderItem=u.renderItem),b})]};this.chart.setOption(p,{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 n=Math.abs(s),o=Math.floor(n/36e5),c=Math.floor(n%36e5/6e4),a=Math.floor(n%6e4/1e3),l=`${o>0?o.toString().padStart(2,"0")+":":""}${c.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`,f=this.chart.getOption();if(!f||!f.series)return;const g=f.series.findIndex(w=>w.type==="candlestick");if(g===-1)return;const h=f.series[g];if(!h.markLine||!h.markLine.data||!h.markLine.data[0])return;const d=h.markLine.data[0];d.label.formatter;const p=d.yAxis;let u="";if(this.options.yAxisLabelFormatter)u=this.options.yAxisLabelFormatter(p);else{const w=this.options.yAxisDecimalPlaces!==void 0?this.options.yAxisDecimalPlaces:O.autoDetectDecimals(this.marketData);u=O.formatValue(p,w)}const b=`${u}
37
- ${l}`;this.chart.setOption({series:[{name:this.options.title||"Market",markLine:{data:[{...d,label:{...d.label,formatter:b}}]}}]})};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 n=0;if(!s){let c=0;this.indicators.forEach(a=>{a.paneIndex>c&&(c=a.paneIndex)}),n=c+1}const o=new Pt(e,t,n,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(e,o),this.render(),o}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 m=x.dataZoom.find(I=>I.type==="slider"||I.type==="inside");m&&(e={start:m.start,end:m.end})}}catch{}const t=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,n=t==="left"?"block":"none",o=t==="right"?"block":"none";(i!==n||s!==o)&&(this.leftSidebar.style.display=n,this.rightSidebar.style.display=o,this.chart.resize());const c=this.dataIndexOffset,a=[...Array(c).fill(""),...this.marketData.map(x=>new Date(x.time).toLocaleString()),...Array(c).fill("")],l=vt.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,m=a.length,I=c/m,P=x/m;l.dataZoom.forEach(y=>{if(y.start!==void 0){const k=y.start/100,L=I+k*P;y.start=L*100}if(y.end!==void 0){const k=y.end/100,L=I+k*P;y.end=L*100}})}e&&l.dataZoom&&l.dataZoom.forEach(x=>{x.start=e.start,x.end=e.end}),l.xAxis.forEach(x=>{x.data=a,x.boundaryGap=!1});const f=pt.buildCandlestickSeries(this.marketData,this.options),g={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};f.data=[...Array(c).fill(g),...f.data,...Array(c).fill(g)];const h=[...Array(c).fill(null),...this.marketData,...Array(c).fill(null)],{series:d,barColors:p}=pt.buildIndicatorSeries(this.indicators,this.timeToIndex,l.paneLayout,a.length,c,h,l.overlayYAxisMap,l.separatePaneYAxisOffset);f.data=f.data.map((x,m)=>p[m]?{value:x.value||x,itemStyle:{color:p[m],color0:p[m],borderColor:p[m],borderColor0:p[m]}}:x);const u=Rt.build(l,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),b=new Map;this.drawings.forEach(x=>{const m=x.paneIndex||0;b.has(m)||b.set(m,[]),b.get(m).push(x)});const w=[];b.forEach((x,m)=>{w.push({type:"custom",name:`drawings-pane-${m}`,xAxisIndex:m,yAxisIndex:m,clip:!0,renderItem:(I,P)=>{const y=x[I.dataIndex];if(!y)return;const k=y.points[0],L=y.points[1];if(!k||!L)return;const A=P.coord([k.timeIndex,k.value]),D=P.coord([L.timeIndex,L.value]),z=y.id===this.selectedDrawingId;if(y.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:A[0],y1:A[1],x2:D[0],y2:D[1]},style:{stroke:y.style?.color||"#3b82f6",lineWidth:y.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:A[0],cy:A[1],r:4},style:{fill:"#fff",stroke:y.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}},{type:"circle",name:"point-end",shape:{cx:D[0],cy:D[1],r:4},style:{fill:"#fff",stroke:y.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0}}]};if(y.type==="fibonacci"){const j=A[0],U=A[1],_=D[0],Q=D[1],tt=Math.min(j,_),ct=Math.max(j,_),ot=ct-tt,v=Q-U,M=[0,.236,.382,.5,.618,.786,1],T=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],$=[];$.push({type:"line",name:"line",shape:{x1:j,y1:U,x2:_,y2:Q},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),$.push({type:"circle",name:"point-start",shape:{cx:j,cy:U,r:4},style:{fill:"#fff",stroke:y.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),$.push({type:"circle",name:"point-end",shape:{cx:_,cy:Q,r:4},style:{fill:"#fff",stroke:y.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}),M.forEach((G,H)=>{const N=Q-v*G,W=T[H%T.length];$.push({type:"line",name:"fib-line",shape:{x1:tt,y1:N,x2:ct,y2:N},style:{stroke:W,lineWidth:1},silent:!0});const et=y.points[0].value,J=y.points[1].value,X=J-et,it=J-X*G;if($.push({type:"text",style:{text:`${G} (${it.toFixed(2)})`,x:tt+5,y:N-10,fill:W,fontSize:10},silent:!0}),H<M.length-1){const yt=M[H+1],dt=Q-v*yt,xt=Math.abs(dt-N),mt=Math.min(N,dt);$.push({type:"rect",shape:{x:tt,y:mt,width:ot,height:xt},style:{fill:T[(H+1)%T.length],opacity:.1},silent:!0})}});const B=[],F=[];return M.forEach((G,H)=>{const N=Q-v*G,W=T[H%T.length];F.push({type:"line",shape:{x1:tt,y1:N,x2:ct,y2:N},style:{stroke:W,lineWidth:1},silent:!0});const et=y.points[0].value,J=y.points[1].value,X=J-et,it=J-X*G;if(F.push({type:"text",style:{text:`${G} (${it.toFixed(2)})`,x:tt+5,y:N-10,fill:W,fontSize:10},silent:!0}),H<M.length-1){const yt=M[H+1],dt=Q-v*yt,xt=Math.abs(dt-N),mt=Math.min(N,dt);B.push({type:"rect",name:"line",shape:{x:tt,y:mt,width:ot,height:xt},style:{fill:T[(H+1)%T.length],opacity:.1}})}}),{type:"group",children:[...B,...F,{type:"line",name:"line",shape:{x1:j,y1:U,x2:_,y2:Q},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:j,cy:U,r:4},style:{fill:"#fff",stroke:y.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:_,cy:Q,r:4},style:{fill:"#fff",stroke:y.style?.color||"#3b82f6",lineWidth:1,opacity:z?1:0},z:100}]}}},data:x.map(I=>[I.points[0].timeIndex,I.points[0].value,I.points[1].timeIndex,I.points[1].value]),z:100,silent:!1})});const C=x=>{const m=jt.format(x,this.options),I=this.options.databox?.position;return I==="left"?(this.leftSidebar.innerHTML=m,""):I==="right"?(this.rightSidebar.innerHTML=m,""):this.options.databox?`<div style="min-width: 200px;">${m}</div>`:""},S={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:C,extraCssText:t!=="floating"&&t!==void 0?"display: none !important;":void 0,position:(x,m,I,P,y)=>{if(this.options.databox?.position==="floating"){const k={top:10};return k[["left","right"][+(x[0]<y.viewSize[0]/2)]]=30,k}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:u,grid:l.grid,xAxis:l.xAxis,yAxis:l.yAxis,dataZoom:l.dataZoom,series:[f,...d,...w]};this.chart.setOption(S,!0)}}var ne=Object.defineProperty,oe=(r,e,t)=>e in r?ne(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ht=(r,e,t)=>(oe(r,typeof e!="symbol"?e+"":e,t),t);class ut{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 re=Object.defineProperty,ae=(r,e,t)=>e in r?re(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,R=(r,e,t)=>(ae(r,typeof e!="symbol"?e+"":e,t),t);class le extends ut{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>'}),R(this,"zr"),R(this,"state","idle"),R(this,"startPoint",null),R(this,"endPoint",null),R(this,"group",null),R(this,"rect",null),R(this,"labelRect",null),R(this,"labelText",null),R(this,"lineV",null),R(this,"lineH",null),R(this,"arrowStart",null),R(this,"arrowEnd",null),R(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),R(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),R(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())}),R(this,"clearHandlers",{}),R(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 Z.graphic.Group,this.rect=new Z.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 Z.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new Z.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new Z.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new Z.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new Z.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 Z.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,n=this.context.coordinateConversion.pixelToData({x:e,y:t}),o=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!n||!o)return;const c=Math.round(n.timeIndex),a=Math.round(o.timeIndex),l=n.value,f=o.value,g=a-c,h=f-l,d=h/l*100,p=h>=0,u=p?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",b=p?"#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:u});const w=(e+i)/2,C=(t+s)/2;this.lineV.setShape({x1:w,y1:t,x2:w,y2:s}),this.lineV.setStyle({stroke:b}),this.lineH.setShape({x1:e,y1:C,x2:i,y2:C}),this.lineH.setStyle({stroke:b});const S=Math.min(t,s),x=Math.max(t,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),p?(this.arrowStart.setShape({points:[[w,S],[w-4,S+6],[w+4,S+6]]}),this.arrowStart.setStyle({fill:b})):(this.arrowEnd.setShape({points:[[w,x],[w-4,x-6],[w+4,x-6]]}),this.arrowEnd.setStyle({fill:b}));const m=[`${h.toFixed(2)} (${d.toFixed(2)}%)`,`${g} bars, ${(g*0).toFixed(0)}d`].join(`
38
- `),I=140,P=40,y=Math.max(t,s),k=Math.min(t,s);let L=(e+i)/2-I/2,A=y+10;const D=this.chart.getHeight();A+P>D&&(A=k-P-10),this.labelRect.setShape({x:L,y:A,width:I,height:P}),this.labelRect.setStyle({fill:"#1e293b",stroke:b,lineWidth:1}),this.labelText.setStyle({x:L+I/2,y:A+P/2,text:m,fill:"#fff"})}}var he=Object.defineProperty,ce=(r,e,t)=>e in r?he(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,q=(r,e,t)=>(ce(r,typeof e!="symbol"?e+"":e,t),t);class de extends ut{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>'}),q(this,"zr"),q(this,"state","idle"),q(this,"startPoint",null),q(this,"endPoint",null),q(this,"group",null),q(this,"line",null),q(this,"startCircle",null),q(this,"endCircle",null),q(this,"onMouseDown",()=>{}),q(this,"onChartInteraction",()=>{}),q(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 n=i.paneIndex||0;this.context.addDrawing({id:`line-${Date.now()}`,type:"line",points:[i,s],paneIndex:n,style:{color:"#3b82f6",lineWidth:2}})}}this.removeGraphic(),this.context.disableTools()}}),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()}saveDataCoordinates(){}updateGraphicFromData(){}enableClearListeners(){}disableClearListeners(){}initGraphic(){this.group||(this.group=new Z.graphic.Group,this.line=new Z.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#3b82f6",lineWidth:2},z:100}),this.startCircle=new Z.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.endCircle=new Z.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 pe=Object.defineProperty,ue=(r,e,t)=>e in r?pe(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,st=(r,e,t)=>(ue(r,typeof e!="symbol"?e+"":e,t),t);class fe extends ut{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>'}),st(this,"startPoint",null),st(this,"endPoint",null),st(this,"state","idle"),st(this,"graphicGroup",null),st(this,"levels",[0,.236,.382,.5,.618,.786,1]),st(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),st(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())}),st(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 Z.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],n=new Z.graphic.Line({shape:{x1:e,y1:t,x2:i,y2:s},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]},silent:!0});this.graphicGroup.add(n);const o=Math.min(e,i),c=Math.max(e,i),a=c-o,l=s-t;this.levels.forEach((f,g)=>{const h=s-l*f,d=this.colors[g%this.colors.length],p=new Z.graphic.Line({shape:{x1:o,y1:h,x2:c,y2:h},style:{stroke:d,lineWidth:1},silent:!0});if(this.graphicGroup.add(p),g<this.levels.length-1){const u=this.levels[g+1],b=s-l*u,w=Math.abs(b-h),C=Math.min(h,b),S=new Z.graphic.Rect({shape:{x:o,y:C,width:a,height:w},style:{fill:this.colors[(g+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(S)}})}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}})}}}K.AbstractPlugin=ut,K.FibonacciTool=fe,K.LineTool=de,K.MeasureTool=le,K.QFChart=se});
36
+ </div>`}),h+="</div>"})}return h}}var Kt=Object.defineProperty,Qt=(g,t,e)=>t in g?Kt(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,ht=(g,t,e)=>(Qt(g,typeof t!="symbol"?t+"":t,e),e);class te{constructor(t,e){ht(this,"plugins",new Map),ht(this,"activePluginId",null),ht(this,"context"),ht(this,"toolbarContainer"),ht(this,"tooltipElement",null),ht(this,"hideTimeout",null),this.context=t,this.toolbarContainer=e,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(t,e){if(!this.tooltipElement)return;this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null);const i=t.getBoundingClientRect();this.tooltipElement.textContent=e,this.tooltipElement.style.display="block";const s=this.tooltipElement.getBoundingClientRect(),n=i.top+(i.height-s.height)/2,l=i.right+10;this.tooltipElement.style.top=`${n}px`,this.tooltipElement.style.left=`${l}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(t){if(this.plugins.has(t.id)){console.warn(`Plugin with id ${t.id} is already registered.`);return}this.plugins.set(t.id,t),t.init(this.context),this.addButton(t)}unregister(t){const e=this.plugins.get(t);e&&(this.activePluginId===t&&this.deactivatePlugin(),e.destroy?.(),this.plugins.delete(t),this.removeButton(t))}activatePlugin(t){if(this.activePluginId===t){this.deactivatePlugin();return}this.activePluginId&&this.deactivatePlugin();const e=this.plugins.get(t);e&&(this.activePluginId=t,this.setButtonActive(t,!0),e.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(t){const e=document.createElement("button");e.id=`qfchart-plugin-btn-${t.id}`,e.style.width="30px",e.style.height="30px",e.style.padding="4px",e.style.border="1px solid transparent",e.style.borderRadius="4px",e.style.backgroundColor="transparent",e.style.cursor="pointer",e.style.color=this.context.getOptions().fontColor||"#cbd5e1",e.style.display="flex",e.style.alignItems="center",e.style.justifyContent="center",t.icon?e.innerHTML=t.icon:e.innerText=(t.name||t.id).substring(0,2).toUpperCase(),e.addEventListener("mouseenter",()=>{this.activePluginId!==t.id&&(e.style.backgroundColor="rgba(255, 255, 255, 0.1)"),this.showTooltip(e,t.name||t.id)}),e.addEventListener("mouseleave",()=>{this.activePluginId!==t.id&&(e.style.backgroundColor="transparent"),this.hideTooltip()}),e.onclick=()=>this.activatePlugin(t.id),this.toolbarContainer.appendChild(e)}removeButton(t){const e=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${t}`);e&&e.remove()}setButtonActive(t,e){const i=this.toolbarContainer.querySelector(`#qfchart-plugin-btn-${t}`);i&&(e?(i.style.backgroundColor="#2563eb",i.style.color="#ffffff"):(i.style.backgroundColor="transparent",i.style.color=this.context.getOptions().fontColor||"#cbd5e1"))}}var ee=Object.defineProperty,ie=(g,t,e)=>t in g?ee(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,q=(g,t,e)=>(ie(g,typeof t!="symbol"?t+"":t,e),e);class se{constructor(t){q(this,"context"),q(this,"isEditing",!1),q(this,"currentDrawing",null),q(this,"editingPointIndex",null),q(this,"zr"),q(this,"editGroup",null),q(this,"editLine",null),q(this,"editStartPoint",null),q(this,"editEndPoint",null),q(this,"isMovingShape",!1),q(this,"dragStart",null),q(this,"initialPixelPoints",[]),q(this,"onDrawingMouseDown",e=>{if(this.isEditing)return;const i=this.context.getDrawing(e.id);i&&(this.isEditing=!0,this.isMovingShape=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.dragStart={x:e.x,y:e.y},this.initialPixelPoints=i.points.map(s=>{const n=this.context.coordinateConversion.dataToPixel(s);return n?{x:n.x,y:n.y}:{x:0,y:0}}),this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),q(this,"onPointMouseDown",e=>{if(this.isEditing)return;const i=this.context.getDrawing(e.id);i&&(this.isEditing=!0,this.currentDrawing=JSON.parse(JSON.stringify(i)),this.editingPointIndex=e.pointIndex,this.context.lockChart(),this.createEditGraphic(),this.zr.on("mousemove",this.onMouseMove),this.zr.on("mouseup",this.onMouseUp))}),q(this,"onMouseMove",e=>{if(!this.isEditing||!this.currentDrawing)return;const i=e.offsetX,s=e.offsetY;if(this.isMovingShape&&this.dragStart){const n=i-this.dragStart.x,l=s-this.dragStart.y,d={x:this.initialPixelPoints[0].x+n,y:this.initialPixelPoints[0].y+l},h={x:this.initialPixelPoints[1].x+n,y:this.initialPixelPoints[1].y+l};this.editLine.setShape({x1:d.x,y1:d.y,x2:h.x,y2:h.y}),this.editStartPoint.setShape({cx:d.x,cy:d.y}),this.editEndPoint.setShape({cx:h.x,cy:h.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})))}),q(this,"onMouseUp",e=>{this.isEditing&&this.finishEditing(e.offsetX,e.offsetY)}),this.context=t,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 W.graphic.Group;const t=this.currentDrawing.points[0],e=this.currentDrawing.points[1],i=this.context.coordinateConversion.dataToPixel(t),s=this.context.coordinateConversion.dataToPixel(e);!i||!s||(this.editLine=new W.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 W.graphic.Circle({shape:{cx:i.x,cy:i.y,r:5},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:2},z:1e3}),this.editEndPoint=new W.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(t,e){if(this.currentDrawing){if(this.isMovingShape&&this.dragStart){const i=t-this.dragStart.x,s=e-this.dragStart.y,n=this.initialPixelPoints.map((l,d)=>{const h=l.x+i,c=l.y+s;return this.context.coordinateConversion.pixelToData({x:h,y:c})});n.every(l=>l!==null)&&n[0]&&n[1]&&(this.currentDrawing.points[0]=n[0],this.currentDrawing.points[1]=n[1],n[0].paneIndex!==void 0&&(this.currentDrawing.paneIndex=n[0].paneIndex),this.context.updateDrawing(this.currentDrawing))}else if(this.editingPointIndex!==null){const i=this.context.coordinateConversion.pixelToData({x:t,y:e});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 ne=Object.defineProperty,oe=(g,t,e)=>t in g?ne(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,ae=(g,t,e)=>(oe(g,typeof t!="symbol"?t+"":t,e),e);class re{constructor(){ae(this,"handlers",new Map)}on(t,e){this.handlers.has(t)||this.handlers.set(t,new Set),this.handlers.get(t).add(e)}off(t,e){const i=this.handlers.get(t);i&&i.delete(e)}emit(t,e){const i=this.handlers.get(t);i&&i.forEach(s=>{try{s(e)}catch(n){console.error(`Error in EventBus handler for ${t}:`,n)}})}clear(){this.handlers.clear()}}class J{static safeParseColor(t){if(!t||typeof t!="string")return{color:"#888888",opacity:1};const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const i=e[4]?parseFloat(e[4]):1;return{color:`rgb(${e[1]},${e[2]},${e[3]})`,opacity:i}}return{color:t,opacity:1}}static render(t,e,i){J.clearAll(t);const s=new Map;for(const n of e)n&&!n._deleted&&s.set(n.position,n);s.forEach(n=>{const l=J.buildTable(n);J.positionTable(l,n.position,i),t.appendChild(l)})}static clearAll(t){for(;t.firstChild;)t.removeChild(t.firstChild)}static buildTable(t){const e=document.createElement("table");if(e.style.borderCollapse="separate",e.style.borderSpacing="0",e.style.pointerEvents="auto",e.style.fontSize="14px",e.style.lineHeight="1.4",e.style.fontFamily="sans-serif",e.style.margin="4px",t.bgcolor){const{color:d,opacity:h}=J.safeParseColor(t.bgcolor);e.style.backgroundColor=d,h<1&&(e.style.opacity=String(h))}if(t.frame_width>0&&t.frame_color){const{color:d}=J.safeParseColor(t.frame_color);e.style.border=`${t.frame_width}px solid ${d}`}else t.frame_width>0&&(e.style.border=`${t.frame_width}px solid #999`);const i=new Map,s=new Set;if(t.merges)for(const d of t.merges){const h=`${d.startCol},${d.startRow}`;i.set(h,{colspan:d.endCol-d.startCol+1,rowspan:d.endRow-d.startRow+1});for(let c=d.startRow;c<=d.endRow;c++)for(let y=d.startCol;y<=d.endCol;y++)c===d.startRow&&y===d.startCol||s.add(`${y},${c}`)}const n=t.rows||0,l=t.columns||0;for(let d=0;d<n;d++){const h=document.createElement("tr");for(let c=0;c<l;c++){const y=`${c},${d}`;if(s.has(y))continue;const p=document.createElement("td"),f=i.get(y);if(f&&(f.colspan>1&&(p.colSpan=f.colspan),f.rowspan>1&&(p.rowSpan=f.rowspan)),t.border_width>0){const o=t.border_color?J.safeParseColor(t.border_color).color:"#999";p.style.border=`${t.border_width}px solid ${o}`}const r=t.cells?.[d]?.[c];if(r&&!r._merged){if(p.textContent=r.text||"",r.bgcolor){const{color:o,opacity:u}=J.safeParseColor(r.bgcolor);p.style.backgroundColor=o,u<1&&(p.style.backgroundColor=r.bgcolor)}if(r.text_color){const{color:o}=J.safeParseColor(r.text_color);p.style.color=o}p.style.fontSize=J.getSizePixels(r.text_size)+"px",p.style.textAlign=J.mapHAlign(r.text_halign),p.style.verticalAlign=J.mapVAlign(r.text_valign),r.text_font_family==="monospace"&&(p.style.fontFamily="monospace"),r.width>0&&(p.style.width=r.width+"%"),r.height>0&&(p.style.height=r.height+"%"),r.tooltip&&(p.title=r.tooltip)}p.style.padding="4px 6px",p.style.whiteSpace="nowrap",h.appendChild(p)}e.appendChild(h)}return e}static positionTable(t,e,i){t.style.position="absolute";const s=8,n=i?i.y+"px":"0",l=i?i.x+"px":"0",d=i?i.y+i.height-s+"px":"0",h=i?i.x+i.width-s+"px":"0",c=i?i.x+i.width/2+"px":"50%",y=i?i.y+i.height/2+"px":"50%";switch(e){case"top_left":t.style.top=n,t.style.left=l;break;case"top_center":t.style.top=n,t.style.left=c,t.style.transform="translateX(-50%)";break;case"top_right":t.style.top=n,t.style.left=h,t.style.transform="translateX(-100%)";break;case"middle_left":t.style.top=y,t.style.left=l,t.style.transform="translateY(-50%)";break;case"middle_center":t.style.top=y,t.style.left=c,t.style.transform="translate(-50%, -50%)";break;case"middle_right":t.style.top=y,t.style.left=h,t.style.transform="translate(-100%, -50%)";break;case"bottom_left":t.style.top=d,t.style.left=l,t.style.transform="translateY(-100%)";break;case"bottom_center":t.style.top=d,t.style.left=c,t.style.transform="translate(-50%, -100%)";break;case"bottom_right":t.style.top=d,t.style.left=h,t.style.transform="translate(-100%, -100%)";break;default:t.style.top=n,t.style.left=h,t.style.transform="translateX(-100%)";break}}static getSizePixels(t){if(typeof t=="number"&&t>0)return t;switch(t){case"auto":case"size.auto":return 12;case"tiny":case"size.tiny":return 8;case"small":case"size.small":return 10;case"normal":case"size.normal":return 14;case"large":case"size.large":return 20;case"huge":case"size.huge":return 36;default:return 14}}static mapHAlign(t){switch(t){case"left":case"text.align_left":return"left";case"right":case"text.align_right":return"right";case"center":case"text.align_center":default:return"center"}}static mapVAlign(t){switch(t){case"top":case"text.align_top":return"top";case"bottom":case"text.align_bottom":return"bottom";case"center":case"text.align_center":default:return"middle"}}}var le=Object.defineProperty,he=(g,t,e)=>t in g?le(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,L=(g,t,e)=>(he(g,typeof t!="symbol"?t+"":t,e),e);class ce{constructor(t,e={}){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 re),L(this,"isMainCollapsed",!1),L(this,"maximizedPaneId",null),L(this,"countdownInterval",null),L(this,"selectedDrawingId",null),L(this,"drawings",[]),L(this,"coordinateConversion",{pixelToData:n=>{const l=this.chart.getOption();if(!l||!l.grid)return null;const d=l.grid.length;for(let h=0;h<d;h++)if(this.chart.containPixel({gridIndex:h},[n.x,n.y])){this.chart.convertFromPixel({seriesIndex:h},[n.x,n.y]);const c=this.chart.convertFromPixel({gridIndex:h},[n.x,n.y]);if(c)return{timeIndex:Math.round(c[0]),value:c[1],paneIndex:h}}return null},dataToPixel:n=>{const l=n.paneIndex||0,d=this.chart.convertToPixel({gridIndex:l},[n.timeIndex,n.value]);return d?{x:d[0],y:d[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,"overlayContainer"),L(this,"_lastTables",[]),L(this,"onKeyDown",n=>{(n.key==="Delete"||n.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=t,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,...e},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=W.init(this.chartContainer),this.chartContainer.style.position="relative",this.overlayContainer=document.createElement("div"),this.overlayContainer.style.cssText="position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:100;overflow:hidden;",this.chartContainer.appendChild(this.overlayContainer),this.pluginManager=new te(this,this.toolbarContainer),this.drawingEditor=new se(this),this.chart.on("dataZoom",n=>{this.events.emit("chart:dataZoom",n);const l=this.options.databox?.triggerOn,d=this.options.databox?.position;l==="click"&&d==="floating"&&this.chart.dispatchAction({type:"hideTip"})}),this.chart.on("finished",n=>this.events.emit("chart:updated",n)),this.chart.getZr().on("mousedown",n=>this.events.emit("mouse:down",n)),this.chart.getZr().on("mousemove",n=>this.events.emit("mouse:move",n)),this.chart.getZr().on("mouseup",n=>this.events.emit("mouse:up",n)),this.chart.getZr().on("click",n=>this.events.emit("mouse:click",n));const i=this.chart.getZr(),s=i.setCursorStyle;i.setCursorStyle=function(n){n==="grab"&&(n="crosshair"),s.call(this,n)},this.bindDrawingEvents(),window.addEventListener("resize",this.resize.bind(this)),document.addEventListener("fullscreenchange",this.onFullscreenChange),document.addEventListener("keydown",this.onKeyDown)}bindDrawingEvents(){let t=null;const e=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 n=parseInt(s[1]),l=this.drawings.filter(h=>(h.paneIndex||0)===n)[i.dataIndex];if(!l)return null;const d=i.event?.target?.name;return{drawing:l,targetName:d,paneIdx:n}};this.chart.on("mouseover",i=>{const s=e(i);if(!s)return;const n=i.event?.target?.parent;if(n){const l=s.drawing.id===this.selectedDrawingId;t&&(clearTimeout(t),t=null),l||n.children().forEach(d=>{d.name&&d.name.startsWith("point")&&d.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 l=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:hover",{id:s.drawing.id,pointIndex:l}),this.chart.getZr().setCursorStyle("pointer")}}),this.chart.on("mouseout",i=>{const s=e(i);if(!s)return;const n=i.event?.target?.parent;if(s.drawing.id!==this.selectedDrawingId){if(t=setTimeout(()=>{if(n){if(this.selectedDrawingId===s.drawing.id)return;n.children().forEach(l=>{l.name&&l.name.startsWith("point")&&l.attr("style",{opacity:0})})}},50),s.targetName==="line")this.events.emit("drawing:mouseout",{id:s.drawing.id});else if(s.targetName?.startsWith("point")){const l=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mouseout",{id:s.drawing.id,pointIndex:l})}this.chart.getZr().setCursorStyle("default")}}),this.chart.on("mousedown",i=>{const s=e(i);if(!s)return;const n=i.event?.event||i.event,l=n?.offsetX,d=n?.offsetY;if(s.targetName==="line")this.events.emit("drawing:mousedown",{id:s.drawing.id,x:l,y:d});else if(s.targetName?.startsWith("point")){const h=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:mousedown",{id:s.drawing.id,pointIndex:h,x:l,y:d})}}),this.chart.on("click",i=>{const s=e(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 n=s.targetName==="point-start"?0:1;this.events.emit("drawing:point:click",{id:s.drawing.id,pointIndex:n})}}}),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(t){this.pluginManager.register(t)}addDrawing(t){this.drawings.push(t),this.render()}removeDrawing(t){const e=this.drawings.findIndex(i=>i.id===t);if(e!==-1){const i=this.drawings[e];this.drawings.splice(e,1),this.events.emit("drawing:deleted",{id:i.id}),this.render()}}getDrawing(t){return this.drawings.find(e=>e.id===t)}updateDrawing(t){const e=this.drawings.findIndex(i=>i.id===t.id);e!==-1&&(this.drawings[e]=t,this.render())}lockChart(){if(this.isLocked)return;this.isLocked=!0;const t=this.chart.getOption();this.chart.setOption({dataZoom:t.dataZoom.map(e=>({...e,disabled:!0})),tooltip:{show:!1}})}unlockChart(){if(!this.isLocked)return;this.isLocked=!1;const t=this.chart.getOption();(this.options.dataZoom||{}).visible,t.dataZoom&&this.chart.setOption({dataZoom:t.dataZoom.map(e=>({...e,disabled:!1})),tooltip:{show:!0}})}setZoom(t,e){this.chart.dispatchAction({type:"dataZoom",start:t,end:e})}setMarketData(t){this.marketData=t,this.rebuildTimeIndex(),this.render()}updateData(t){if(t.length===0)return;const e=new Map;this.marketData.forEach(a=>{e.set(a.time,a)}),t.forEach(a=>{e.has(a.time),e.set(a.time,a)}),this.marketData=Array.from(e.values()).sort((a,x)=>a.time-x.time),this.rebuildTimeIndex();const i=this.dataIndexOffset,s=ut.buildCandlestickSeries(this.marketData,this.options),n={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}},l=[...Array(i).fill(n),...s.data,...Array(i).fill(n)],d=[...Array(i).fill(""),...this.marketData.map(a=>new Date(a.time).toLocaleString()),...Array(i).fill("")],h=this.chart.getOption(),c=It.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData),y=[...Array(i).fill(null),...this.marketData,...Array(i).fill(null)],{series:p,barColors:f}=ut.buildIndicatorSeries(this.indicators,this.timeToIndex,c.paneLayout,d.length,i,y,c.overlayYAxisMap,c.separatePaneYAxisOffset),r=l.map((a,x)=>f[x]?{value:a.value||a,itemStyle:{color:f[x],color0:f[x],borderColor:f[x],borderColor0:f[x]}}:a),o={xAxis:h.xAxis.map((a,x)=>({data:d})),series:[{data:r,markLine:s.markLine},...p.map(a=>{const x={data:a.data};return a.renderItem&&(x.renderItem=a.renderItem),x})]};this.chart.setOption(o,{notMerge:!1});const u=[];this.indicators.forEach(a=>{Object.values(a.plots).forEach(x=>{x.options?.style==="table"&&x.data?.forEach(m=>{(Array.isArray(m.value)?m.value:[m.value]).forEach(S=>{S&&!S._deleted&&u.push(S)})})})}),this._lastTables=u,this._renderTableOverlays(),this.startCountdown()}startCountdown(){if(this.stopCountdown(),!this.options.lastPriceLine?.showCountdown||!this.options.interval||this.marketData.length===0)return;const t=()=>{if(this.marketData.length===0)return;const e=this.marketData[this.marketData.length-1].time+(this.options.interval||0),i=Date.now(),s=e-i;if(s<=0)return;const n=Math.abs(s),l=Math.floor(n/36e5),d=Math.floor(n%36e5/6e4),h=Math.floor(n%6e4/1e3),c=`${l>0?l.toString().padStart(2,"0")+":":""}${d.toString().padStart(2,"0")}:${h.toString().padStart(2,"0")}`,y=this.chart.getOption();if(!y||!y.series)return;const p=y.series.findIndex(x=>x.type==="candlestick");if(p===-1)return;const f=y.series[p];if(!f.markLine||!f.markLine.data||!f.markLine.data[0])return;const r=f.markLine.data[0];r.label.formatter;const o=r.yAxis;let u="";if(this.options.yAxisLabelFormatter)u=this.options.yAxisLabelFormatter(o);else{const x=this.options.yAxisDecimalPlaces!==void 0?this.options.yAxisDecimalPlaces:Z.autoDetectDecimals(this.marketData);u=Z.formatValue(o,x)}const a=`${u}
37
+ ${c}`;this.chart.setOption({series:[{name:this.options.title||"Market",markLine:{data:[{...r,label:{...r.label,formatter:a}}]}}]})};t(),this.countdownInterval=setInterval(t,1e3)}stopCountdown(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null)}addIndicator(t,e,i={}){const s=i.overlay!==void 0?i.overlay:i.isOverlay??!1;let n=0;if(!s){let d=0;this.indicators.forEach(h=>{h.paneIndex>d&&(d=h.paneIndex)}),n=d+1}const l=new zt(t,e,n,{height:i.height,collapsed:!1,titleColor:i.titleColor,controls:i.controls});return this.indicators.set(t,l),this.render(),l}setIndicator(t,e,i=!1){this.addIndicator(t,{[t]:e},{overlay:i})}removeIndicator(t){this.indicators.delete(t),this.render()}toggleIndicator(t,e="collapse"){if(e==="fullscreen"){document.fullscreenElement?document.exitFullscreen():this.rootContainer.requestFullscreen();return}if(e==="maximize"){this.maximizedPaneId===t?this.maximizedPaneId=null:this.maximizedPaneId=t,this.render();return}if(t==="main"){this.isMainCollapsed=!this.isMainCollapsed,this.render();return}const i=this.indicators.get(t);i&&(i.toggleCollapse(),this.render())}resize(){this.chart.resize(),this._renderTableOverlays()}_renderTableOverlays(){const t=this.chart.getModel().getComponent("grid",0)?.coordinateSystem?.getRect();J.render(this.overlayContainer,this._lastTables,t)}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 t=this.marketData.length,e=Math.ceil(t*this.padding);this.dataIndexOffset=e}render(){if(this.marketData.length===0)return;let t=null;try{const A=this.chart.getOption();if(A&&A.dataZoom&&A.dataZoom.length>0){const v=A.dataZoom.find(b=>b.type==="slider"||b.type==="inside");v&&(t={start:v.start,end:v.end})}}catch{}const e=this.options.databox?.position,i=this.leftSidebar.style.display,s=this.rightSidebar.style.display,n=e==="left"?"block":"none",l=e==="right"?"block":"none";(i!==n||s!==l)&&(this.leftSidebar.style.display=n,this.rightSidebar.style.display=l,this.chart.resize());const d=this.dataIndexOffset,h=[...Array(d).fill(""),...this.marketData.map(A=>new Date(A.time).toLocaleString()),...Array(d).fill("")],c=It.calculate(this.chart.getHeight(),this.indicators,this.options,this.isMainCollapsed,this.maximizedPaneId,this.marketData);if(!t&&c.dataZoom&&this.marketData.length>0){const A=this.marketData.length,v=h.length,b=d/v,C=A/v;c.dataZoom.forEach(w=>{if(w.start!==void 0){const M=w.start/100,P=b+M*C;w.start=P*100}if(w.end!==void 0){const M=w.end/100,P=b+M*C;w.end=P*100}})}t&&c.dataZoom&&c.dataZoom.forEach(A=>{A.start=t.start,A.end=t.end}),c.xAxis.forEach(A=>{A.data=h,A.boundaryGap=!1});const y=ut.buildCandlestickSeries(this.marketData,this.options),p={value:[NaN,NaN,NaN,NaN],itemStyle:{opacity:0}};y.data=[...Array(d).fill(p),...y.data,...Array(d).fill(p)];const f=[...Array(d).fill(null),...this.marketData,...Array(d).fill(null)],{series:r,barColors:o}=ut.buildIndicatorSeries(this.indicators,this.timeToIndex,c.paneLayout,h.length,d,f,c.overlayYAxisMap,c.separatePaneYAxisOffset);y.data=y.data.map((A,v)=>o[v]?{value:A.value||A,itemStyle:{color:o[v],color0:o[v],borderColor:o[v],borderColor0:o[v]}}:A);const u=Ut.build(c,this.options,this.toggleIndicator.bind(this),this.isMainCollapsed,this.maximizedPaneId),a=new Map;this.drawings.forEach(A=>{const v=A.paneIndex||0;a.has(v)||a.set(v,[]),a.get(v).push(A)});const x=[];a.forEach((A,v)=>{x.push({type:"custom",name:`drawings-pane-${v}`,xAxisIndex:v,yAxisIndex:v,clip:!0,renderItem:(b,C)=>{const w=A[b.dataIndex];if(!w)return;const M=w.points[0],P=w.points[1];if(!M||!P)return;const D=C.coord([M.timeIndex,M.value]),_=C.coord([P.timeIndex,P.value]),F=w.id===this.selectedDrawingId;if(w.type==="line")return{type:"group",children:[{type:"line",name:"line",shape:{x1:D[0],y1:D[1],x2:_[0],y2:_[1]},style:{stroke:w.style?.color||"#3b82f6",lineWidth:w.style?.lineWidth||2}},{type:"circle",name:"point-start",shape:{cx:D[0],cy:D[1],r:4},style:{fill:"#fff",stroke:w.style?.color||"#3b82f6",lineWidth:1,opacity:F?1:0}},{type:"circle",name:"point-end",shape:{cx:_[0],cy:_[1],r:4},style:{fill:"#fff",stroke:w.style?.color||"#3b82f6",lineWidth:1,opacity:F?1:0}}]};if(w.type==="fibonacci"){const R=D[0],G=D[1],Q=_[0],U=_[1],tt=Math.min(R,Q),et=Math.max(R,Q),k=et-tt,z=U-G,E=[0,.236,.382,.5,.618,.786,1],$=["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"],H=[];H.push({type:"line",name:"line",shape:{x1:R,y1:G,x2:Q,y2:U},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}}),H.push({type:"circle",name:"point-start",shape:{cx:R,cy:G,r:4},style:{fill:"#fff",stroke:w.style?.color||"#3b82f6",lineWidth:1,opacity:F?1:0},z:100}),H.push({type:"circle",name:"point-end",shape:{cx:Q,cy:U,r:4},style:{fill:"#fff",stroke:w.style?.color||"#3b82f6",lineWidth:1,opacity:F?1:0},z:100}),E.forEach((V,T)=>{const N=U-z*V,it=$[T%$.length];H.push({type:"line",name:"fib-line",shape:{x1:tt,y1:N,x2:et,y2:N},style:{stroke:it,lineWidth:1},silent:!0});const nt=w.points[0].value,X=w.points[1].value,ot=X-nt,bt=X-ot*V;if(H.push({type:"text",style:{text:`${V} (${bt.toFixed(2)})`,x:tt+5,y:N-10,fill:it,fontSize:10},silent:!0}),T<E.length-1){const wt=E[T+1],pt=U-z*wt,vt=Math.abs(pt-N),Ct=Math.min(N,pt);H.push({type:"rect",shape:{x:tt,y:Ct,width:k,height:vt},style:{fill:$[(T+1)%$.length],opacity:.1},silent:!0})}});const O=[],Y=[];return E.forEach((V,T)=>{const N=U-z*V,it=$[T%$.length];Y.push({type:"line",shape:{x1:tt,y1:N,x2:et,y2:N},style:{stroke:it,lineWidth:1},silent:!0});const nt=w.points[0].value,X=w.points[1].value,ot=X-nt,bt=X-ot*V;if(Y.push({type:"text",style:{text:`${V} (${bt.toFixed(2)})`,x:tt+5,y:N-10,fill:it,fontSize:10},silent:!0}),T<E.length-1){const wt=E[T+1],pt=U-z*wt,vt=Math.abs(pt-N),Ct=Math.min(N,pt);O.push({type:"rect",name:"line",shape:{x:tt,y:Ct,width:k,height:vt},style:{fill:$[(T+1)%$.length],opacity:.1}})}}),{type:"group",children:[...O,...Y,{type:"line",name:"line",shape:{x1:R,y1:G,x2:Q,y2:U},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]}},{type:"circle",name:"point-start",shape:{cx:R,cy:G,r:4},style:{fill:"#fff",stroke:w.style?.color||"#3b82f6",lineWidth:1,opacity:F?1:0},z:100},{type:"circle",name:"point-end",shape:{cx:Q,cy:U,r:4},style:{fill:"#fff",stroke:w.style?.color||"#3b82f6",lineWidth:1,opacity:F?1:0},z:100}]}}},data:A.map(b=>[b.points[0].timeIndex,b.points[0].value,b.points[1].timeIndex,b.points[1].value]),encode:{x:[0,2],y:[1,3]},z:100,silent:!1})});const m=A=>{const v=Jt.format(A,this.options),b=this.options.databox?.position;return b==="left"?(this.leftSidebar.innerHTML=v,""):b==="right"?(this.rightSidebar.innerHTML=v,""):this.options.databox?`<div style="min-width: 200px;">${v}</div>`:""},S=[];this.indicators.forEach(A=>{Object.values(A.plots).forEach(v=>{v.options?.style==="table"&&v.data?.forEach(b=>{(Array.isArray(b.value)?b.value:[b.value]).forEach(C=>{C&&!C._deleted&&S.push(C)})})})});const I={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:m,extraCssText:e!=="floating"&&e!==void 0?"display: none !important;":void 0,position:(A,v,b,C,w)=>{if(this.options.databox?.position==="floating"){const M={top:10};return M[["left","right"][+(A[0]<w.viewSize[0]/2)]]=30,M}return null}},axisPointer:{link:{xAxisIndex:"all"},label:{backgroundColor:"#475569"}},graphic:u,grid:c.grid,xAxis:c.xAxis,yAxis:c.yAxis,dataZoom:c.dataZoom,series:[y,...r,...x]};this.chart.setOption(I,!0),this._lastTables=S,this._renderTableOverlays()}}var de=Object.defineProperty,pe=(g,t,e)=>t in g?de(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,dt=(g,t,e)=>(pe(g,typeof t!="symbol"?t+"":t,e),e);class ft{constructor(t){dt(this,"id"),dt(this,"name"),dt(this,"icon"),dt(this,"context"),dt(this,"eventListeners",[]),this.id=t.id,this.name=t.name,this.icon=t.icon}init(t){this.context=t,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(t,e){this.context.events.on(t,e),this.eventListeners.push({event:t,handler:e})}off(t,e){this.context.events.off(t,e),this.eventListeners=this.eventListeners.filter(i=>i.event!==t||i.handler!==e)}removeAllListeners(){this.eventListeners.forEach(({event:t,handler:e})=>{this.context.events.off(t,e)}),this.eventListeners=[]}get chart(){return this.context.getChart()}get marketData(){return this.context.getMarketData()}}var ue=Object.defineProperty,fe=(g,t,e)=>t in g?ue(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,j=(g,t,e)=>(fe(g,typeof t!="symbol"?t+"":t,e),e);class ye extends ft{constructor(t){super({id:"measure",name:t?.name||"Measure",icon:t?.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>'}),j(this,"zr"),j(this,"state","idle"),j(this,"startPoint",null),j(this,"endPoint",null),j(this,"group",null),j(this,"rect",null),j(this,"labelRect",null),j(this,"labelText",null),j(this,"lineV",null),j(this,"lineH",null),j(this,"arrowStart",null),j(this,"arrowEnd",null),j(this,"onMouseDown",()=>{this.state==="finished"&&this.removeGraphic()}),j(this,"onChartInteraction",()=>{this.group&&this.removeGraphic()}),j(this,"onClick",e=>{this.state==="idle"?(this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.context.disableTools(),this.enableClearListeners())}),j(this,"clearHandlers",{}),j(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.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 t=()=>{this.removeGraphic()};setTimeout(()=>{this.zr.on("click",t)},10),this.zr.on("mousedown",this.onMouseDown),this.context.events.on("chart:dataZoom",this.onChartInteraction),this.clearHandlers={click:t,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 W.graphic.Group,this.rect=new W.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 W.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.lineH=new W.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#fff",lineWidth:1,lineDash:[4,4]},z:101}),this.arrowStart=new W.graphic.Polygon({shape:{points:[[0,0],[-5,10],[5,10]]},style:{fill:"#fff"},z:102}),this.arrowEnd=new W.graphic.Polygon({shape:{points:[[0,0],[-5,-10],[5,-10]]},style:{fill:"#fff"},z:102}),this.labelRect=new W.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 W.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[t,e]=this.startPoint,[i,s]=this.endPoint,n=this.context.coordinateConversion.pixelToData({x:t,y:e}),l=this.context.coordinateConversion.pixelToData({x:i,y:s});if(!n||!l)return;const d=Math.round(n.timeIndex),h=Math.round(l.timeIndex),c=n.value,y=l.value,p=h-d,f=y-c,r=f/c*100,o=f>=0,u=o?"rgba(33, 150, 243, 0.2)":"rgba(236, 0, 0, 0.2)",a=o?"#2196F3":"#ec0000";this.rect.setShape({x:Math.min(t,i),y:Math.min(e,s),width:Math.abs(i-t),height:Math.abs(s-e)}),this.rect.setStyle({fill:u});const x=(t+i)/2,m=(e+s)/2;this.lineV.setShape({x1:x,y1:e,x2:x,y2:s}),this.lineV.setStyle({stroke:a}),this.lineH.setShape({x1:t,y1:m,x2:i,y2:m}),this.lineH.setStyle({stroke:a});const S=Math.min(e,s),I=Math.max(e,s);this.arrowStart.setStyle({fill:"none"}),this.arrowEnd.setStyle({fill:"none"}),o?(this.arrowStart.setShape({points:[[x,S],[x-4,S+6],[x+4,S+6]]}),this.arrowStart.setStyle({fill:a})):(this.arrowEnd.setShape({points:[[x,I],[x-4,I-6],[x+4,I-6]]}),this.arrowEnd.setStyle({fill:a}));const A=[`${f.toFixed(2)} (${r.toFixed(2)}%)`,`${p} bars, ${(p*0).toFixed(0)}d`].join(`
38
+ `),v=140,b=40,C=Math.max(e,s),w=Math.min(e,s);let M=(t+i)/2-v/2,P=C+10;const D=this.chart.getHeight();P+b>D&&(P=w-b-10),this.labelRect.setShape({x:M,y:P,width:v,height:b}),this.labelRect.setStyle({fill:"#1e293b",stroke:a,lineWidth:1}),this.labelText.setStyle({x:M+v/2,y:P+b/2,text:A,fill:"#fff"})}}var ge=Object.defineProperty,xe=(g,t,e)=>t in g?ge(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,K=(g,t,e)=>(xe(g,typeof t!="symbol"?t+"":t,e),e);class me extends ft{constructor(t){super({id:"trend-line",name:t?.name||"Trend Line",icon:t?.icon||'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="2" y1="22" x2="22" y2="2" /></svg>'}),K(this,"zr"),K(this,"state","idle"),K(this,"startPoint",null),K(this,"endPoint",null),K(this,"group",null),K(this,"line",null),K(this,"startCircle",null),K(this,"endCircle",null),K(this,"onMouseDown",()=>{}),K(this,"onChartInteraction",()=>{}),K(this,"onClick",e=>{if(this.state==="idle")this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic();else if(this.state==="drawing"){if(this.state="finished",this.endPoint=[e.offsetX,e.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 n=i.paneIndex||0;this.context.addDrawing({id:`line-${Date.now()}`,type:"line",points:[i,s],paneIndex:n,style:{color:"#3b82f6",lineWidth:2}})}}this.removeGraphic(),this.context.disableTools()}}),K(this,"clearHandlers",{}),K(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.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 W.graphic.Group,this.line=new W.graphic.Line({shape:{x1:0,y1:0,x2:0,y2:0},style:{stroke:"#3b82f6",lineWidth:2},z:100}),this.startCircle=new W.graphic.Circle({shape:{cx:0,cy:0,r:4},style:{fill:"#fff",stroke:"#3b82f6",lineWidth:1},z:101}),this.endCircle=new W.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[t,e]=this.startPoint,[i,s]=this.endPoint;this.line.setShape({x1:t,y1:e,x2:i,y2:s}),this.startCircle.setShape({cx:t,cy:e}),this.endCircle.setShape({cx:i,cy:s})}}var be=Object.defineProperty,we=(g,t,e)=>t in g?be(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,at=(g,t,e)=>(we(g,typeof t!="symbol"?t+"":t,e),e);class ve extends ft{constructor(t={}){super({id:"fibonacci-tool",name:t.name||"Fibonacci Retracement",icon:t.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>'}),at(this,"startPoint",null),at(this,"endPoint",null),at(this,"state","idle"),at(this,"graphicGroup",null),at(this,"levels",[0,.236,.382,.5,.618,.786,1]),at(this,"colors",["#787b86","#f44336","#ff9800","#4caf50","#2196f3","#00bcd4","#787b86"]),at(this,"onClick",e=>{this.state==="idle"?(this.state="drawing",this.startPoint=[e.offsetX,e.offsetY],this.endPoint=[e.offsetX,e.offsetY],this.initGraphic(),this.updateGraphic()):this.state==="drawing"&&(this.state="finished",this.endPoint=[e.offsetX,e.offsetY],this.updateGraphic(),this.saveDrawing(),this.removeGraphic(),this.context.disableTools())}),at(this,"onMouseMove",e=>{this.state==="drawing"&&(this.endPoint=[e.offsetX,e.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 t=this.context.getChart().getZr();t.on("click",this.onClick),t.on("mousemove",this.onMouseMove)}unbindEvents(){const t=this.context.getChart().getZr();t.off("click",this.onClick),t.off("mousemove",this.onMouseMove)}initGraphic(){this.graphicGroup=new W.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 t=this.startPoint[0],e=this.startPoint[1],i=this.endPoint[0],s=this.endPoint[1],n=new W.graphic.Line({shape:{x1:t,y1:e,x2:i,y2:s},style:{stroke:"#999",lineWidth:1,lineDash:[4,4]},silent:!0});this.graphicGroup.add(n);const l=Math.min(t,i),d=Math.max(t,i),h=d-l,c=s-e;this.levels.forEach((y,p)=>{const f=s-c*y,r=this.colors[p%this.colors.length],o=new W.graphic.Line({shape:{x1:l,y1:f,x2:d,y2:f},style:{stroke:r,lineWidth:1},silent:!0});if(this.graphicGroup.add(o),p<this.levels.length-1){const u=this.levels[p+1],a=s-c*u,x=Math.abs(a-f),m=Math.min(f,a),S=new W.graphic.Rect({shape:{x:l,y:m,width:h,height:x},style:{fill:this.colors[(p+1)%this.colors.length],opacity:.1},silent:!0});this.graphicGroup.add(S)}})}saveDrawing(){if(!this.startPoint||!this.endPoint)return;const t=this.context.coordinateConversion.pixelToData({x:this.startPoint[0],y:this.startPoint[1]}),e=this.context.coordinateConversion.pixelToData({x:this.endPoint[0],y:this.endPoint[1]});if(t&&e){const i=t.paneIndex||0;this.context.addDrawing({id:`fib-${Date.now()}`,type:"fibonacci",points:[t,e],paneIndex:i,style:{color:"#3b82f6",lineWidth:1}})}}}st.AbstractPlugin=ft,st.FibonacciTool=ve,st.LineTool=me,st.MeasureTool=ye,st.QFChart=ce});