@tony01/astroneum 0.4.1-beta.2
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/CHANGELOG.md +237 -0
- package/LICENSE +21 -0
- package/README.md +198 -0
- package/dist/Indicator-BBI3L_lx.d.ts +1181 -0
- package/dist/ar-SA-AEPUSRMF.js +2 -0
- package/dist/astroneum.css +1 -0
- package/dist/chunk-2SN3RH42.js +2 -0
- package/dist/chunk-2YYGUSVX.js +3 -0
- package/dist/chunk-3GJSZFLM.js +2 -0
- package/dist/chunk-4YOLQ5DC.js +2 -0
- package/dist/chunk-I4YQBP2M.js +3 -0
- package/dist/chunk-OOMZRONH.js +35 -0
- package/dist/chunk-PV2GAINM.js +2 -0
- package/dist/chunk-SDXH2WAI.js +3 -0
- package/dist/chunk-YFPXTHZX.js +2 -0
- package/dist/chunk-YW3STIPY.js +653 -0
- package/dist/de-DE-4PR3NRQ7.js +2 -0
- package/dist/entries/alerts.d.ts +93 -0
- package/dist/entries/alerts.js +2 -0
- package/dist/entries/datafeeds/crypto.d.ts +65 -0
- package/dist/entries/datafeeds/crypto.js +2 -0
- package/dist/entries/datafeeds/polygon.d.ts +113 -0
- package/dist/entries/datafeeds/polygon.js +2 -0
- package/dist/entries/multichart.d.ts +96 -0
- package/dist/entries/multichart.js +2 -0
- package/dist/entries/portfolio.d.ts +55 -0
- package/dist/entries/portfolio.js +2 -0
- package/dist/entries/replay.d.ts +141 -0
- package/dist/entries/replay.js +2 -0
- package/dist/entries/script.d.ts +68 -0
- package/dist/entries/script.js +2 -0
- package/dist/entries/watchlist.d.ts +43 -0
- package/dist/entries/watchlist.js +2 -0
- package/dist/es-ES-HNDVPSLW.js +2 -0
- package/dist/fr-FR-Y7XWRGF2.js +2 -0
- package/dist/hi-IN-KEGIKIMV.js +2 -0
- package/dist/id-ID-QXDIUQUZ.js +2 -0
- package/dist/index.d.ts +1434 -0
- package/dist/index.js +2 -0
- package/dist/it-IT-UDTDFSRB.js +2 -0
- package/dist/ja-JP-NIODTBW3.js +2 -0
- package/dist/ko-KR-DQHPXKBA.js +2 -0
- package/dist/nl-NL-BB3ZHCXS.js +2 -0
- package/dist/pl-PL-I5MZDLFD.js +2 -0
- package/dist/pt-BR-MAMRTOYR.js +2 -0
- package/dist/ru-RU-F43D6B7G.js +2 -0
- package/dist/th-TH-KTFIUAD6.js +2 -0
- package/dist/tr-TR-WFTKJ22Y.js +2 -0
- package/dist/vi-VN-CD3WI2FQ.js +2 -0
- package/dist/zh-CN-Y2C6RSOI.js +3 -0
- package/docs/STRUCTURE.md +231 -0
- package/docs/TODO-DESIGN.md +261 -0
- package/docs/TODO.md +222 -0
- package/docs/api.md +528 -0
- package/docs/datafeed-guide.md +311 -0
- package/docs/design-astroneum.md +479 -0
- package/docs/plugin-development.md +565 -0
- package/docs/tv-functions-skill.md +706 -0
- package/package.json +147 -0
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
function U(n,e){if(!(!ae(n)&&!ae(e))){for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)){let r=n[t],i=e[t];ae(i)&&ae(r)?U(r,i):n[t]=Ae(i);}}}function Ae(n){if(!ae(n))return n;let e=null;ne(n)?e=[]:e={};for(let t in n)if(Object.prototype.hasOwnProperty.call(n,t)){let r=n[t];ae(r)?e[t]=Ae(r):e[t]=r;}return e}function ne(n){return Object.prototype.toString.call(n)==="[object Array]"}function j(n){return typeof n=="function"}function ae(n){return typeof n=="object"&&_(n)}function w(n){return typeof n=="number"&&Number.isFinite(n)}function _(n){return n!=null}function Pe(n){return typeof n=="boolean"}function L(n){return typeof n=="string"}var oa=/\\(\\)?/g,na=RegExp(`[^.[\\]]+|\\[(?:([^"'][^[]*)|(["'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))`,"g");function K(n,e,t){if(_(n)){let r=[];e.replace(na,(s,...l)=>{let c=s;return _(l[1])?c=l[2].replace(oa,"$1"):_(l[0])&&(c=l[0].trim()),r.push(c),""});let i=n,o=0,a=r.length;for(;_(i)&&o<a;)i=i?.[r[o++]];return _(i)?i:t??"--"}return t??"--"}function aa(n,e){let t={};return n.formatToParts(new Date(e)).forEach(({type:r,value:i})=>{switch(r){case "year":{t.YYYY=i;break}case "month":{t.MM=i;break}case "day":{t.DD=i;break}case "hour":{t.HH=i==="24"?"00":i;break}case "minute":{t.mm=i;break}case "second":{t.ss=i;break}}}),t}function mr(n,e,t){let r=aa(n,e);return t.replace(/YYYY|MM|DD|HH|mm|ss/g,i=>r[i])}function ee(n,e){let t=+n;return w(t)?t.toFixed(e??2):`${n}`}function pr(n){let e=+n;if(w(e)){if(e>1e9)return `${+(e/1e9).toFixed(3)}B`;if(e>1e6)return `${+(e/1e6).toFixed(3)}M`;if(e>1e3)return `${+(e/1e3).toFixed(3)}K`}return `${n}`}function gr(n,e){let t=`${n}`;if(e.length===0)return t;if(t.includes(".")){let r=t.split(".");return `${r[0].replace(/(\d)(?=(\d{3})+$)/g,i=>`${i}${e}`)}.${r[1]}`}return t.replace(/(\d)(?=(\d{3})+$)/g,r=>`${r}${e}`)}function fr(n,e){let t=`${n}`;if(new RegExp("\\.0{"+e+",}[1-9][0-9]*$").test(t)){let i=t.split("."),o=i.length-1,a=i[o],s=/0*/.exec(a);if(_(s)){let l=s[0].length;return i[o]=a.replace(/0*/,`0{${l}}`),i.join(".")}}return t}function Yr(n,e){return n.replace(/\{(\w+)\}/g,(t,r)=>{let i=e[r];return _(i)?i:`{${r}}`})}function ct(n,e,t,r){let i=n.result,o=n.figures,a=n.styles,s=K(a,"circles",t.circles),l=s.length,c=K(a,"bars",t.bars),u=c.length,h=K(a,"lines",t.lines),d=h.length,m=0,p=0,g=0,f,v=0;o.forEach(y=>{switch(y.type){case "circle":{v=m;let b=s[m%l];f={...b,color:b.noChangeColor},m++;break}case "bar":{v=p;let b=c[p%u];f={...b,color:b.noChangeColor},p++;break}case "line":{v=g,f=h[g%d],g++;break}}if(_(y.type)){let b=y.styles?.({data:{prev:i[e-1],current:i[e],next:i[e+1]},indicator:n,defaultStyles:t});r(y,{...f,...b},v);}});}var lt=class n{id;paneId;name;shortName;precision=4;calcParams=[];shouldOhlc=false;shouldFormatBigNumber=false;visible=true;zLevel=0;extendData;series="normal";figures=[];minValue=null;maxValue=null;styles=null;shouldUpdate=(e,t)=>{let r=JSON.stringify(e.calcParams)!==JSON.stringify(t.calcParams)||e.figures!==t.figures||e.calc!==t.calc,i=r||e.shortName!==t.shortName||e.series!==t.series||e.minValue!==t.minValue||e.maxValue!==t.maxValue||e.precision!==t.precision||e.shouldOhlc!==t.shouldOhlc||e.shouldFormatBigNumber!==t.shouldFormatBigNumber||e.visible!==t.visible||e.zLevel!==t.zLevel||e.extendData!==t.extendData||e.regenerateFigures!==t.regenerateFigures||e.createTooltipDataSource!==t.createTooltipDataSource||e.draw!==t.draw;return {calc:r,draw:i}};calc=()=>[];regenerateFigures=null;createTooltipDataSource=null;draw=null;result=[];_prevIndicator;_lockSeriesPrecision=false;constructor(e){this.override(e),this._lockSeriesPrecision=false;}override(e){let{result:t,...r}=this;this._prevIndicator={...Ae(r),result:t};let{id:i,name:o,shortName:a,precision:s,styles:l,figures:c,calcParams:u,...h}=e;!L(this.id)&&L(i)&&(this.id=i),L(this.name)||(this.name=o??""),this.shortName=a??this.shortName??this.name,w(s)&&(this.precision=s,this._lockSeriesPrecision=true),_(l)&&(this.styles??={},U(this.styles,l)),U(this,h),_(u)&&(this.calcParams=u,j(this.regenerateFigures)&&(this.figures=this.regenerateFigures(this.calcParams))),this.figures=c??this.figures;}setSeriesPrecision(e){this._lockSeriesPrecision||(this.precision=e);}shouldUpdateImp(){let e=this._prevIndicator.zLevel!==this.zLevel,t=this.shouldUpdate(this._prevIndicator,this);return Pe(t)?{calc:t,draw:t,sort:e}:{...t,sort:e}}async calcImp(e,t="full"){try{let r=await this.calc(e,this);return this.result=r,!0}catch{return false}}static extend(e){class t extends n{constructor(){super(e);}}return t}};var sa={name:"A/D",shortName:"A/D",precision:2,shouldFormatBigNumber:true,figures:[{key:"ad",title:"A/D: ",type:"line"}],calc:n=>{let e=0;return n.map(t=>{let r={},i=t.high,o=t.low,a=t.close,s=t.volume??0;if(i!==o){let l=(a-o-(i-a))/(i-o);e+=l*s;}return r.ad=e,r})}},xi=sa;var la={name:"AMA",shortName:"AMA",series:"price",calcParams:[10],precision:2,shouldOhlc:true,figures:[{key:"ama",title:"AMA: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=2/3,o=2/31,a=0,s=[];return n.forEach((l,c)=>{let u={};if(c>=r-1){let h=Math.abs(l.close-n[c-(r-1)].close),d=0;for(let g=c-(r-2);g<=c;g++)d+=Math.abs(n[g].close-n[g-1].close);let p=((d!==0?h/d:0)*(i-o)+o)**2;if(c===r-1){let g=0;for(let f=0;f<r;f++)g+=n[f].close;a=g/r;}else a=a+p*(l.close-a);u.ama=a;}s.push(u);}),s}},Ci=la;var ca={name:"ADX",shortName:"ADX",calcParams:[14],precision:2,figures:[{key:"adx",title:"ADX: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=0,o=0,a=0,s=0,l=0,c=0,u=0,h=0;return n.map((d,m)=>{let p={},g=n[m-1]??d,f=d.high,v=d.low,y=f-v,b=Math.abs(f-g.close),S=Math.abs(g.close-v),x=f-g.high,C=g.low-v,T=Math.max(y,b,S),A=x>0&&x>C?x:0,P=C>0&&C>x?C:0;if(i+=T,o+=A,a+=P,m>=r-1){m>r-1?(s=s-s/r+T,l=l-l/r+A,c=c-c/r+P):(s=i,l=o,c=a);let R=0,D=0;s!==0&&(R=l*100/s,D=c*100/s);let E=0;D+R!==0&&(E=Math.abs(D-R)/(D+R)*100),u+=E,m>=r*2-2&&(m>r*2-2?h=(h*(r-1)+E)/r:h=u/r,p.adx=h);}return p})}},Ti=ca;var ua={name:"AVP",shortName:"AVP",series:"price",precision:2,figures:[{key:"avp",title:"AVP: ",type:"line"}],calc:n=>{let e=0,t=0;return n.map(r=>{let i={},o=r.turnover??0,a=r.volume??0;return e+=o,t+=a,t!==0&&(i.avp=e/t),i})}},Si=ua;var ha={name:"ATR",shortName:"ATR",calcParams:[14],precision:2,figures:[{key:"atr",title:"ATR: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=0,i=0;return n.map((o,a)=>{let s={},l=(n[a-1]??o).close,c=o.high,u=o.low,h=c-u,d=Math.abs(c-l),m=Math.abs(l-u),p=Math.max(h,d,m);return r+=p,a>=t[0]-1&&(a>t[0]-1?i=(i*(t[0]-1)+p)/t[0]:i=r/t[0],s.atr=i),s})}},Ai=ha;var da={name:"AO",shortName:"AO",calcParams:[5,34],figures:[{key:"ao",title:"AO: ",type:"bar",baseValue:0,styles:({data:n,indicator:e,defaultStyles:t})=>{let{prev:r,current:i}=n,o=r?.ao??Number.MIN_SAFE_INTEGER,a=i?.ao??Number.MIN_SAFE_INTEGER,s="";a>o?s=K(e.styles,"bars[0].upColor",t.bars[0].upColor):s=K(e.styles,"bars[0].downColor",t.bars[0].downColor);let l=a>o?"stroke":"fill";return {color:s,style:l,borderColor:s}}}],calc:(n,e)=>{let t=e.calcParams,r=Math.max(t[0],t[1]),i=0,o=0,a=0,s=0;return n.map((l,c)=>{let u={},h=(l.low+l.high)/2;if(i+=h,o+=h,c>=t[0]-1){a=i/t[0];let d=n[c-(t[0]-1)];i-=(d.low+d.high)/2;}if(c>=t[1]-1){s=o/t[1];let d=n[c-(t[1]-1)];o-=(d.low+d.high)/2;}return c>=r-1&&(u.ao=a-s),u})}},Pi=da;var ma={name:"BIAS",shortName:"BIAS",calcParams:[6,12,24],figures:[{key:"bias1",title:"BIAS6: ",type:"line"},{key:"bias2",title:"BIAS12: ",type:"line"},{key:"bias3",title:"BIAS24: ",type:"line"}],regenerateFigures:n=>n.map((e,t)=>({key:`bias${t+1}`,title:`BIAS${e}: `,type:"line"})),calc:(n,e)=>{let{calcParams:t,figures:r}=e,i=[];return n.map((o,a)=>{let s={},l=o.close;return t.forEach((c,u)=>{if(i[u]=(i[u]??0)+l,a>=c-1){let h=i[u]/t[u];s[r[u].key]=(l-h)/h*100,i[u]-=n[a-(c-1)].close;}}),s})}},wi=ma;function pa(n,e){let t=n.length,r=0;return n.forEach(i=>{let o=i.close-e;r+=o*o;}),r=Math.abs(r),Math.sqrt(r/t)}var ga={name:"BOLL",shortName:"BOLL",series:"price",calcParams:[20,2],precision:2,shouldOhlc:true,figures:[{key:"up",title:"UP: ",type:"line"},{key:"mid",title:"MID: ",type:"line"},{key:"dn",title:"DN: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=t[0]-1,i=0;return n.map((o,a)=>{let s=o.close,l={};if(i+=s,a>=r){l.mid=i/t[0];let c=pa(n.slice(a-r,a+1),l.mid);l.up=l.mid+t[1]*c,l.dn=l.mid-t[1]*c,i-=n[a-r].close;}return l})}},Ei=ga;var fa={name:"BRAR",shortName:"BRAR",calcParams:[26],figures:[{key:"br",title:"BR: ",type:"line"},{key:"ar",title:"AR: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=0,i=0,o=0,a=0;return n.map((s,l)=>{let c={},u=s.high,h=s.low,d=s.open,m=(n[l-1]??s).close;if(o+=u-d,a+=d-h,r+=u-m,i+=m-h,l>=t[0]-1){a!==0?c.ar=o/a*100:c.ar=0,i!==0?c.br=r/i*100:c.br=0;let p=n[l-(t[0]-1)],g=p.high,f=p.low,v=p.open,y=(n[l-t[0]]??n[l-(t[0]-1)]).close;r-=g-y,i-=y-f,o-=g-v,a-=v-f;}return c})}},Ii=fa;var ya={name:"BBI",shortName:"BBI",series:"price",precision:2,calcParams:[3,6,12,24],shouldOhlc:true,figures:[{key:"bbi",title:"BBI: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=Math.max(...t),i=[],o=[];return n.map((a,s)=>{let l={},c=a.close;if(t.forEach((u,h)=>{i[h]=(i[h]??0)+c,s>=u-1&&(o[h]=i[h]/u,i[h]-=n[s-(u-1)].close);}),s>=r-1){let u=0;o.forEach(h=>{u+=h;}),l.bbi=u/4;}return l})}},Ri=ya;var va={name:"CMF",shortName:"CMF",calcParams:[20],precision:4,figures:[{key:"cmf",title:"CMF: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=0,o=0,a=[];return n.forEach((s,l)=>{let c={},u=s.high,h=s.low,d=s.close,m=s.volume??0,p=0;if(u!==h&&(p=(d-h-(u-d))/(u-h)),i+=p*m,o+=m,l>=r-1){o!==0&&(c.cmf=i/o);let g=n[l-(r-1)],f=g.volume??0,v=0;g.high!==g.low&&(v=(g.close-g.low-(g.high-g.close))/(g.high-g.low)),i-=v*f,o-=f;}a.push(c);}),a}},Di=va;var _a={name:"CCI",shortName:"CCI",calcParams:[20],figures:[{key:"cci",title:"CCI: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=t[0]-1,i=0,o=[];return n.map((a,s)=>{let l={},c=(a.high+a.low+a.close)/3;if(i+=c,o.push(c),s>=r){let u=i/t[0],h=o.slice(s-r,s+1),d=0;h.forEach(g=>{d+=Math.abs(g-u);});let m=d/t[0];l.cci=m!==0?(c-u)/m/.015:0;let p=(n[s-r].high+n[s-r].low+n[s-r].close)/3;i-=p;}return l})}},ki=_a;var ba={name:"CORR",shortName:"CORR",calcParams:[20],precision:4,figures:[{key:"corr",title:"CORR: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0];return n.map((i,o)=>{let a={};if(o>=r-1){let s=0,l=0,c=0,u=0,h=0;for(let p=0;p<r;p++){let g=p+1,f=n[o-(r-1)+p].close;s+=g,l+=f,c+=g*f,u+=g*g,h+=f*f;}let d=r*c-s*l,m=Math.sqrt((r*u-s*s)*(r*h-l*l));a.corr=m!==0?d/m:0;}return a})}},Mi=ba;var xa={name:"CR",shortName:"CR",calcParams:[26,10,20,40,60],figures:[{key:"cr",title:"CR: ",type:"line"},{key:"ma1",title:"MA1: ",type:"line"},{key:"ma2",title:"MA2: ",type:"line"},{key:"ma3",title:"MA3: ",type:"line"},{key:"ma4",title:"MA4: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=Math.ceil(t[1]/2.5+1),i=Math.ceil(t[2]/2.5+1),o=Math.ceil(t[3]/2.5+1),a=Math.ceil(t[4]/2.5+1),s=0,l=[],c=0,u=[],h=0,d=[],m=0,p=[],g=[];return n.forEach((f,v)=>{let y={},b=n[v-1]??f,S=(b.high+b.close+b.low+b.open)/4,x=Math.max(0,f.high-S),C=Math.max(0,S-f.low);v>=t[0]-1&&(C!==0?y.cr=x/C*100:y.cr=0,s+=y.cr,c+=y.cr,h+=y.cr,m+=y.cr,v>=t[0]+t[1]-2&&(l.push(s/t[1]),v>=t[0]+t[1]+r-3&&(y.ma1=l[l.length-1-r]),s-=g[v-(t[1]-1)].cr??0),v>=t[0]+t[2]-2&&(u.push(c/t[2]),v>=t[0]+t[2]+i-3&&(y.ma2=u[u.length-1-i]),c-=g[v-(t[2]-1)].cr??0),v>=t[0]+t[3]-2&&(d.push(h/t[3]),v>=t[0]+t[3]+o-3&&(y.ma3=d[d.length-1-o]),h-=g[v-(t[3]-1)].cr??0),v>=t[0]+t[4]-2&&(p.push(m/t[4]),v>=t[0]+t[4]+a-3&&(y.ma4=p[p.length-1-a]),m-=g[v-(t[4]-1)].cr??0)),g.push(y);}),g}},Fi=xa;var Ca={name:"DMA",shortName:"DMA",calcParams:[10,50,10],figures:[{key:"dma",title:"DMA: ",type:"line"},{key:"ama",title:"AMA: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=Math.max(t[0],t[1]),i=0,o=0,a=0,s=[];return n.forEach((l,c)=>{let u={},h=l.close;i+=h,o+=h;let d=0,m=0;if(c>=t[0]-1&&(d=i/t[0],i-=n[c-(t[0]-1)].close),c>=t[1]-1&&(m=o/t[1],o-=n[c-(t[1]-1)].close),c>=r-1){let p=d-m;u.dma=p,a+=p,c>=r+t[2]-2&&(u.ama=a/t[2],a-=s[c-(t[2]-1)].dma??0);}s.push(u);}),s}},Li=Ca;var Ta={name:"DMI",shortName:"DMI",calcParams:[14,6],figures:[{key:"pdi",title:"PDI: ",type:"line"},{key:"mdi",title:"MDI: ",type:"line"},{key:"adx",title:"ADX: ",type:"line"},{key:"adxr",title:"ADXR: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=0,i=0,o=0,a=0,s=0,l=0,c=0,u=0,h=[];return n.forEach((d,m)=>{let p={},g=n[m-1]??d,f=g.close,v=d.high,y=d.low,b=v-y,S=Math.abs(v-f),x=Math.abs(f-y),C=v-g.high,T=g.low-y,A=Math.max(Math.max(b,S),x),P=C>0&&C>T?C:0,R=T>0&&T>C?T:0;if(r+=A,i+=P,o+=R,m>=t[0]-1){m>t[0]-1?(a=a-a/t[0]+A,s=s-s/t[0]+P,l=l-l/t[0]+R):(a=r,s=i,l=o);let D=0,E=0;a!==0&&(D=s*100/a,E=l*100/a),p.pdi=D,p.mdi=E;let I=0;E+D!==0&&(I=Math.abs(E-D)/(E+D)*100),c+=I,m>=t[0]*2-2&&(m>t[0]*2-2?u=(u*(t[0]-1)+I)/t[0]:u=c/t[0],p.adx=u,m>=t[0]*2+t[1]-3&&(p.adxr=((h[m-(t[1]-1)].adx??0)+u)/2));}h.push(p);}),h}},Bi=Ta;var Sa={name:"DC",shortName:"DC",series:"price",calcParams:[20],precision:2,shouldOhlc:true,figures:[{key:"up",title:"UP: ",type:"line"},{key:"mid",title:"MID: ",type:"line"},{key:"dn",title:"DN: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0];return n.map((i,o)=>{let a={};if(o>=r-1){let s=-1/0,l=1/0;for(let c=o-(r-1);c<=o;c++)s=Math.max(s,n[c].high),l=Math.min(l,n[c].low);a.up=s,a.dn=l,a.mid=(s+l)/2;}return a})}},Oi=Sa;var Aa={name:"DEMA",shortName:"DEMA",series:"price",calcParams:[20],precision:2,shouldOhlc:true,figures:[{key:"dema",title:"DEMA: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=0,o=0,a=0,s=[];return n.forEach((l,c)=>{let u={},h=l.close;if(i+=h,c>=r-1){if(c>r-1){let d=o;o=(2*h+(r-1)*o)/(r+1),a=(2*d+(r-1)*a)/(r+1);}else o=i/r,a=o;u.dema=2*o-a;}s.push(u);}),s}},Ni=Aa;var Pa={name:"EMV",shortName:"EMV",calcParams:[14,9],figures:[{key:"emv",title:"EMV: ",type:"line"},{key:"maEmv",title:"MAEMV: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=0,i=[];return n.map((o,a)=>{let s={};if(a>0){let l=n[a-1],c=o.high,u=o.low,h=o.volume??0,d=(c+u)/2-(l.high+l.low)/2;if(h===0||c-u===0)s.emv=0;else {let m=h/1e8/(c-u);s.emv=d/m;}r+=s.emv,i.push(s.emv),a>=t[0]&&(s.maEmv=r/t[0],r-=i[a-t[0]]);}return s})}},Vi=Pa;var wa={name:"EMA",shortName:"EMA",series:"price",calcParams:[6,12,20],precision:2,shouldOhlc:true,figures:[{key:"ema1",title:"EMA6: ",type:"line"},{key:"ema2",title:"EMA12: ",type:"line"},{key:"ema3",title:"EMA20: ",type:"line"}],regenerateFigures:n=>n.map((e,t)=>({key:`ema${t+1}`,title:`EMA${e}: `,type:"line"})),calc:(n,e)=>{let{calcParams:t,figures:r}=e,i=0,o=[];return n.map((a,s)=>{let l={},c=a.close;return i+=c,t.forEach((u,h)=>{s>=u-1&&(s>u-1?o[h]=(2*c+(u-1)*o[h])/(u+1):o[h]=i/u,l[r[h].key]=o[h]);}),l})}},Wi=wa;var Ea={name:"HV",shortName:"HV",calcParams:[20],precision:4,figures:[{key:"hv",title:"HV: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=[],o=[];return n.forEach((a,s)=>{let l={},c=n[s-1];if(c&&c.close!==0?o.push(Math.log(a.close/c.close)):o.push(0),s>=r){let u=o.slice(s-r+1,s+1),h=u.reduce((p,g)=>p+g,0)/r,d=0;for(let p=0;p<u.length;p++)d+=(u[p]-h)**2;let m=Math.sqrt(d/(r-1));l.hv=m*Math.sqrt(252);}i.push(l);}),i}},Yi=Ea;function Hr(n,e){if(n.length<e)return NaN;let t=0,r=0,i=n.length-e;for(let o=0;o<e;o++){let a=o+1;t+=n[i+o]*a,r+=a;}return t/r}var Ia={name:"HMA",shortName:"HMA",series:"price",calcParams:[20],precision:2,shouldOhlc:true,figures:[{key:"hma",title:"HMA: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=Math.max(Math.floor(r/2),1),o=Math.max(Math.round(Math.sqrt(r)),1),a=[],s=[];for(let l=0;l<n.length;l++){let c=n.slice(0,l+1).map(u=>u.close);if(c.length>=r){let u=Hr(c,r),h=Hr(c,i);s.push(2*h-u);}else s.push(NaN);}for(let l=0;l<n.length;l++){let c={};if(l>=r+o-2){let u=s.slice(l-(o-1),l+1);c.hma=Hr(u,o);}a.push(c);}return a}},Hi=Ia;var Ra={name:"Ichimoku",shortName:"Ichimoku",series:"price",calcParams:[9,26,52],precision:2,shouldOhlc:true,figures:[{key:"tenkan",title:"Tenkan: ",type:"line"},{key:"kijun",title:"Kijun: ",type:"line"},{key:"senkouA",title:"SenkouA: ",type:"line"},{key:"senkouB",title:"SenkouB: ",type:"line"},{key:"chikou",title:"Chikou: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,[r,i,o]=t,a=[];n.forEach((s,l)=>{let c={};if(l>=r-1){let u=-1/0,h=1/0;for(let d=l-(r-1);d<=l;d++)u=Math.max(u,n[d].high),h=Math.min(h,n[d].low);c.tenkan=(u+h)/2;}if(l>=i-1){let u=-1/0,h=1/0;for(let d=l-(i-1);d<=l;d++)u=Math.max(u,n[d].high),h=Math.min(h,n[d].low);c.kijun=(u+h)/2;}if(l>=o-1){let u=-1/0,h=1/0;for(let d=l-(o-1);d<=l;d++)u=Math.max(u,n[d].high),h=Math.min(h,n[d].low);c.senkouB=(u+h)/2;}a.push(c),l>=i&&(a[l-i].chikou=s.close);});for(let s=0;s<a.length;s++)if(a[s].tenkan!==void 0&&a[s].kijun!==void 0){let l=(a[s].tenkan+a[s].kijun)/2,c=s+i;c<a.length&&(a[c].senkouA=l);}return a}},zi=Ra;var Da={name:"KC",shortName:"KC",series:"price",calcParams:[20,1.5],precision:2,shouldOhlc:true,figures:[{key:"up",title:"UP: ",type:"line"},{key:"mid",title:"MID: ",type:"line"},{key:"dn",title:"DN: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=t[0],i=t[1],o=0,a=0,s=0,l=0;return n.map((c,u)=>{let h={},d=c.close,m=n[u-1]??c,p=Math.max(c.high-c.low,Math.abs(c.high-m.close),Math.abs(m.close-c.low));return o+=d,s+=p,u>=r-1&&(u>r-1?(a=(2*d+(r-1)*a)/(r+1),l=(l*(r-1)+p)/r):(a=o/r,l=s/r),h.mid=a,h.up=a+i*l,h.dn=a-i*l),h})}},Xi=Da;var ka={name:"LinReg",shortName:"LinReg",series:"price",calcParams:[20],precision:2,shouldOhlc:true,figures:[{key:"linreg",title:"LinReg: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0];return n.map((i,o)=>{let a={};if(o>=r-1){let s=0,l=0,c=0,u=0;for(let m=0;m<r;m++){let p=m+1,g=n[o-(r-1)+m].close;s+=p,l+=g,c+=p*g,u+=p*p;}let h=(r*c-s*l)/(r*u-s*s),d=(l-h*s)/r;a.linreg=h*r+d,a.slope=h;}return a})}},Ui=ka;var Ma={name:"MTM",shortName:"MTM",calcParams:[12,6],figures:[{key:"mtm",title:"MTM: ",type:"line"},{key:"maMtm",title:"MAMTM: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=0,i=[];return n.forEach((o,a)=>{let s={};if(a>=t[0]){let l=o.close,c=n[a-t[0]].close;s.mtm=l-c,r+=s.mtm,a>=t[0]+t[1]-1&&(s.maMtm=r/t[1],r-=i[a-(t[1]-1)].mtm??0);}i.push(s);}),i}},Gi=Ma;var Fa={name:"MFI",shortName:"MFI",calcParams:[14],precision:2,figures:[{key:"mfi",title:"MFI: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=0,o=0,a=[];return n.forEach((s,l)=>{let c={},u=n[l-1]??s,h=(s.high+s.low+s.close)/3,d=(u.high+u.low+u.close)/3,m=h*(s.volume??0);if(h>d?i+=m:h<d&&(o+=m),l>=r-1){if(o!==0&&i+o!==0){let b=i/o;c.mfi=100-100/(1+b);}else i===0&&o===0?c.mfi=50:i===0?c.mfi=0:c.mfi=100;let p=n[l-(r-1)],g=n[l-r]??p,f=(p.high+p.low+p.close)/3,v=(g.high+g.low+g.close)/3,y=f*(p.volume??0);f>v?i-=y:f<v&&(o-=y);}a.push(c);}),a}},$i=Fa;var La={name:"MA",shortName:"MA",series:"price",calcParams:[5,10,30,60],precision:2,shouldOhlc:true,figures:[{key:"ma1",title:"MA5: ",type:"line"},{key:"ma2",title:"MA10: ",type:"line"},{key:"ma3",title:"MA30: ",type:"line"},{key:"ma4",title:"MA60: ",type:"line"}],regenerateFigures:n=>n.map((e,t)=>({key:`ma${t+1}`,title:`MA${e}: `,type:"line"})),calc:(n,e)=>{let{calcParams:t,figures:r}=e,i=[];return n.map((o,a)=>{let s={},l=o.close;return t.forEach((c,u)=>{i[u]=(i[u]??0)+l,a>=c-1&&(s[r[u].key]=i[u]/c,i[u]-=n[a-(c-1)].close);}),s})}},ji=La;var Ba={name:"MACD",shortName:"MACD",calcParams:[12,26,9],figures:[{key:"dif",title:"DIF: ",type:"line"},{key:"dea",title:"DEA: ",type:"line"},{key:"macd",title:"MACD: ",type:"bar",baseValue:0,styles:({data:n,indicator:e,defaultStyles:t})=>{let{prev:r,current:i}=n,o=r?.macd??Number.MIN_SAFE_INTEGER,a=i?.macd??Number.MIN_SAFE_INTEGER,s="";return a>0?s=K(e.styles,"bars[0].upColor",t.bars[0].upColor):a<0?s=K(e.styles,"bars[0].downColor",t.bars[0].downColor):s=K(e.styles,"bars[0].noChangeColor",t.bars[0].noChangeColor),{style:o<a?"stroke":"fill",color:s,borderColor:s}}}],calc:(n,e)=>{let t=e.calcParams,r=0,i=0,o=0,a=0,s=0,l=0,c=Math.max(t[0],t[1]);return n.map((u,h)=>{let d={},m=u.close;return r+=m,h>=t[0]-1&&(h>t[0]-1?i=(2*m+(t[0]-1)*i)/(t[0]+1):i=r/t[0]),h>=t[1]-1&&(h>t[1]-1?o=(2*m+(t[1]-1)*o)/(t[1]+1):o=r/t[1]),h>=c-1&&(a=i-o,d.dif=a,s+=a,h>=c+t[2]-2&&(h>c+t[2]-2?l=(a*2+l*(t[2]-1))/(t[2]+1):l=s/t[2],d.macd=(a-l)*2,d.dea=l)),d})}},qi=Ba;var Oa={name:"OBV",shortName:"OBV",calcParams:[30],figures:[{key:"obv",title:"OBV: ",type:"line"},{key:"maObv",title:"MAOBV: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=0,i=0,o=[];return n.forEach((a,s)=>{let l=n[s-1]??a;a.close<l.close?i-=a.volume??0:a.close>l.close&&(i+=a.volume??0);let c={obv:i};r+=i,s>=t[0]-1&&(c.maObv=r/t[0],r-=o[s-(t[0]-1)].obv??0),o.push(c);}),o}},Zi=Oa;var Na={name:"PP",shortName:"PP",series:"price",precision:2,shouldOhlc:true,figures:[{key:"pp",title:"PP: ",type:"line"},{key:"r1",title:"R1: ",type:"line"},{key:"r2",title:"R2: ",type:"line"},{key:"r3",title:"R3: ",type:"line"},{key:"s1",title:"S1: ",type:"line"},{key:"s2",title:"S2: ",type:"line"},{key:"s3",title:"S3: ",type:"line"}],calc:n=>n.map((e,t)=>{let r={},i=n[t-1];if(i){let o=(i.high+i.low+i.close)/3;r.pp=o,r.r1=2*o-i.low,r.r2=o+(i.high-i.low),r.r3=i.high+2*(o-i.low),r.s1=2*o-i.high,r.s2=o-(i.high-i.low),r.s3=i.low-2*(i.high-o);}return r})},Qi=Na;var Va={name:"PVT",shortName:"PVT",figures:[{key:"pvt",title:"PVT: ",type:"line"}],calc:n=>{let e=0;return n.map((t,r)=>{let i={},o=t.close,a=t.volume??1,s=(n[r-1]??t).close,l=0,c=s*a;return c!==0&&(l=(o-s)/c),e+=l,i.pvt=e,i})}},Ki=Va;var Wa={name:"PSY",shortName:"PSY",calcParams:[12,6],figures:[{key:"psy",title:"PSY: ",type:"line"},{key:"maPsy",title:"MAPSY: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=0,i=0,o=[],a=[];return n.forEach((s,l)=>{let c={},u=(n[l-1]??s).close,h=s.close-u>0?1:0;o.push(h),r+=h,l>=t[0]-1&&(c.psy=r/t[0]*100,i+=c.psy,l>=t[0]+t[1]-2&&(c.maPsy=i/t[1],i-=a[l-(t[1]-1)].psy??0),r-=o[l-(t[0]-1)]),a.push(c);}),a}},Ji=Wa;var Ya={name:"ROC",shortName:"ROC",calcParams:[12,6],figures:[{key:"roc",title:"ROC: ",type:"line"},{key:"maRoc",title:"MAROC: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=[],i=0;return n.forEach((o,a)=>{let s={};if(a>=t[0]-1){let l=o.close,c=(n[a-t[0]]??n[a-(t[0]-1)]).close;c!==0?s.roc=(l-c)/c*100:s.roc=0,i+=s.roc,a>=t[0]-1+t[1]-1&&(s.maRoc=i/t[1],i-=r[a-(t[1]-1)].roc??0);}r.push(s);}),r}},eo=Ya;var Ha={name:"RSI",shortName:"RSI",calcParams:[6,12,24],figures:[{key:"rsi1",title:"RSI1: ",type:"line"},{key:"rsi2",title:"RSI2: ",type:"line"},{key:"rsi3",title:"RSI3: ",type:"line"}],regenerateFigures:n=>n.map((e,t)=>{let r=t+1;return {key:`rsi${r}`,title:`RSI${r}: `,type:"line"}}),calc:(n,e)=>{let{calcParams:t,figures:r}=e,i=[],o=[];return n.map((a,s)=>{let l={},c=(n[s-1]??a).close,u=a.close-c;return t.forEach((h,d)=>{if(u>0?i[d]=(i[d]??0)+u:o[d]=(o[d]??0)+Math.abs(u),s>=h-1){o[d]!==0?l[r[d].key]=100-100/(1+i[d]/o[d]):l[r[d].key]=0;let m=n[s-(h-1)],p=n[s-h]??m,g=m.close-p.close;g>0?i[d]-=g:o[d]-=Math.abs(g);}}),l})}},to=Ha;var za={name:"SMA",shortName:"SMA",series:"price",calcParams:[12,2],precision:2,figures:[{key:"sma",title:"SMA: ",type:"line"}],shouldOhlc:true,calc:(n,e)=>{let t=e.calcParams,r=0,i=0;return n.map((o,a)=>{let s={},l=o.close;return r+=l,a>=t[0]-1&&(a>t[0]-1?i=(l*t[1]+i*(t[0]-t[1]+1))/(t[0]+1):i=r/t[0],s.sma=i),s})}},ro=za;var Xa={name:"STDDEV",shortName:"STDDEV",calcParams:[20],precision:4,figures:[{key:"stddev",title:"STDDEV: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0];return n.map((i,o)=>{let a={};if(o>=r-1){let s=0;for(let u=o-(r-1);u<=o;u++)s+=n[u].close;let l=s/r,c=0;for(let u=o-(r-1);u<=o;u++)c+=(n[u].close-l)**2;a.stddev=Math.sqrt(c/r);}return a})}},io=Xa;function xt(n,e,t){let r=0,i=0;for(i=n.length-1;r!==i;){let o=Math.floor((i+r)/2),a=i-r,s=n[o][e];if(t===n[r][e])return r;if(t===n[i][e])return i;if(t===s)return o;if(t>s?r=o:i=o,a<=2)break}return r}function oo(n){let e=Math.floor(xe(n)),t=we(e),r=n/t,i=0;return r<1.5?i=1:r<2.5?i=2:r<3.5?i=3:r<4.5?i=4:r<5.5?i=5:r<6.5?i=6:i=8,n=i*t,+n.toFixed(Math.abs(e))}function zr(n,e){e=Math.max(0,e??0);let t=Math.pow(10,e);return Math.round(n*t)/t}function no(n){let e=n.toString(),t=e.indexOf("e");if(t>0){let i=+e.slice(t+1);return i<0?-i:0}let r=e.indexOf(".");return r<0?0:e.length-1-r}function yr(n,e,t){let r=[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],i=n.length,o=0;for(;o<i;){let a=n[o];r[0]=Math.max(a[e]??Number.MIN_SAFE_INTEGER,r[0]),r[1]=Math.min(a[t]??Number.MAX_SAFE_INTEGER,r[1]),++o;}return r}function xe(n){return n===0?0:Math.log10(n)}function we(n){return Math.pow(10,n)}var Ua={name:"KDJ",shortName:"KDJ",calcParams:[9,3,3],figures:[{key:"k",title:"K: ",type:"line"},{key:"d",title:"D: ",type:"line"},{key:"j",title:"J: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=[];return n.forEach((i,o)=>{let a={},s=i.close;if(o>=t[0]-1){let l=yr(n.slice(o-(t[0]-1),o+1),"high","low"),c=l[0],u=l[1],h=c-u,d=(s-u)/(h===0?1:h)*100;a.k=((t[1]-1)*(r[o-1]?.k??50)+d)/t[1],a.d=((t[2]-1)*(r[o-1]?.d??50)+a.k)/t[2],a.j=3*a.k-2*a.d;}r.push(a);}),r}},ao=Ua;var Ga={name:"SAR",shortName:"SAR",series:"price",calcParams:[2,2,20],precision:2,shouldOhlc:true,figures:[{key:"sar",title:"SAR: ",type:"circle",styles:({data:n,indicator:e,defaultStyles:t})=>{let{current:r}=n,i=r?.sar??Number.MIN_SAFE_INTEGER,o=((r?.high??0)+(r?.low??0))/2;return {color:i<o?K(e.styles,"circles[0].upColor",t.circles[0].upColor):K(e.styles,"circles[0].downColor",t.circles[0].downColor)}}}],calc:(n,e)=>{let t=e.calcParams,r=t[0]/100,i=t[1]/100,o=t[2]/100,a=r,s=-100,l=false,c=0;return n.map((u,h)=>{let d=c,m=u.high,p=u.low;if(l){(s===-100||s<m)&&(s=m,a=Math.min(a+i,o)),c=d+a*(s-d);let g=Math.min(n[Math.max(1,h)-1].low,p);c>u.low?(c=s,a=r,s=-100,l=!l):c>g&&(c=g);}else {(s===-100||s>p)&&(s=p,a=Math.min(a+i,o)),c=d+a*(s-d);let g=Math.max(n[Math.max(1,h)-1].high,m);c<u.high?(c=s,a=0,s=-100,l=!l):c<g&&(c=g);}return {high:m,low:p,sar:c}})}},so=Ga;var $a={name:"SuperTrend",shortName:"SuperTrend",series:"price",calcParams:[10,3],precision:2,shouldOhlc:true,figures:[{key:"superTrend",title:"SuperTrend: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=t[0],i=t[1],o=0,a=0,s=1,l=0,c=0,u=[];return n.forEach((h,d)=>{let m={},p=(h.high+h.low)/2,g=n[d-1]??h,f=Math.max(h.high-h.low,Math.abs(h.high-g.close),Math.abs(g.close-h.low));if(o+=f,d>=r-1){d>r-1?a=(a*(r-1)+f)/r:a=o/r;let v=p+i*a,y=p-i*a;d===r-1?(l=v,c=y,s=1):(l=v<l||g.close>l?v:l,c=y>c||g.close<c?y:c,s===1&&h.close<c?s=-1:s===-1&&h.close>l&&(s=1)),m.superTrend=s===1?c:l,m.direction=s;}u.push(m);}),u}},lo=$a;var ja={name:"TEMA",shortName:"TEMA",series:"price",calcParams:[20],precision:2,shouldOhlc:true,figures:[{key:"tema",title:"TEMA: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=0,o=0,a=0,s=0,l=[];return n.forEach((c,u)=>{let h={},d=c.close;if(i+=d,u>=r-1){if(u>r-1){let m=o,p=a;o=(2*d+(r-1)*o)/(r+1),a=(2*m+(r-1)*a)/(r+1),s=(2*p+(r-1)*s)/(r+1);}else o=i/r,a=o,s=o;h.tema=3*o-3*a+s;}l.push(h);}),l}},co=ja;var qa={name:"TRIX",shortName:"TRIX",calcParams:[12,9],figures:[{key:"trix",title:"TRIX: ",type:"line"},{key:"maTrix",title:"MATRIX: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=0,i=0,o=0,a=0,s=0,l=0,c=0,u=[];return n.forEach((h,d)=>{let m={},p=h.close;if(r+=p,d>=t[0]-1&&(d>t[0]-1?i=(2*p+(t[0]-1)*i)/(t[0]+1):i=r/t[0],s+=i,d>=t[0]*2-2&&(d>t[0]*2-2?o=(2*i+(t[0]-1)*o)/(t[0]+1):o=s/t[0],l+=o,d>=t[0]*3-3))){let g=0,f=0;d>t[0]*3-3?(g=(2*o+(t[0]-1)*a)/(t[0]+1),f=(g-a)/a*100):g=l/t[0],a=g,m.trix=f,c+=f,d>=t[0]*3+t[1]-4&&(m.maTrix=c/t[1],c-=u[d-(t[1]-1)].trix??0);}u.push(m);}),u}},uo=qa;function Za(n){let e=n.match(/^rgba\(([^)]+)\)$/i);if(e===null)return n;let t=e[1].split(",").map(r=>r.trim());return t.length<3?n:`rgba(${t[0]}, ${t[1]}, ${t[2]}, 1)`}function ho(){return {key:"volume",title:"VOLUME: ",type:"bar",baseValue:0,attrs:({coordinate:n,barSpace:e,yAxis:t})=>{let r=n.current.volume;if(!_(r))return null;let i=e.gapBar%2===0?1:0,o=t.convertToPixel(t.getRange().from),a=n.current.x-e.halfGapBar,s=e.gapBar+i,l=Math.min(r,o),c=Math.max(1,Math.abs(o-r));return {x:a,y:l,width:s,height:c}},styles:({data:n,indicator:e,defaultStyles:t})=>{let r=n.current,i=K(e.styles,"bars[0].noChangeColor",t.bars[0].noChangeColor);return _(r)&&(r.close>r.open?i=K(e.styles,"bars[0].upColor",t.bars[0].upColor):r.close<r.open&&(i=K(e.styles,"bars[0].downColor",t.bars[0].downColor))),{color:Za(i)}}}}var Qa={name:"VOL",shortName:"VOL",series:"volume",calcParams:[7,25,99],shouldFormatBigNumber:true,precision:0,minValue:0,figures:[{key:"ma1",title:"MA5: ",type:"line"},{key:"ma2",title:"MA10: ",type:"line"},{key:"ma3",title:"MA20: ",type:"line"},ho()],regenerateFigures:n=>{let e=n.map((t,r)=>({key:`ma${r+1}`,title:`MA${t}: `,type:"line"}));return e.push(ho()),e},calc:(n,e)=>{let{calcParams:t,figures:r}=e,i=[];return n.map((o,a)=>{let s=o.volume??0,l={volume:s,open:o.open,close:o.close};return t.forEach((c,u)=>{i[u]=(i[u]??0)+s,a>=c-1&&(l[r[u].key]=i[u]/c,i[u]-=n[a-(c-1)].volume??0);}),l})}},mo=Qa;var Ka={name:"VROC",shortName:"VROC",calcParams:[14],precision:2,figures:[{key:"vroc",title:"VROC: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0];return n.map((i,o)=>{let a={};if(o>=r){let s=n[o-r].volume??0,l=i.volume??0;s!==0&&(a.vroc=(l-s)/s*100);}return a})}},po=Ka;var Ja={name:"VR",shortName:"VR",calcParams:[26,6],figures:[{key:"vr",title:"VR: ",type:"line"},{key:"maVr",title:"MAVR: ",type:"line"}],calc:(n,e)=>{let t=e.calcParams,r=0,i=0,o=0,a=0,s=[];return n.forEach((l,c)=>{let u={},h=l.close,d=(n[c-1]??l).close,m=l.volume??0;if(h>d?r+=m:h<d?i+=m:o+=m,c>=t[0]-1){let p=o/2;i+p===0?u.vr=0:u.vr=(r+p)/(i+p)*100,a+=u.vr,c>=t[0]+t[1]-2&&(u.maVr=a/t[1],a-=s[c-(t[1]-1)].vr??0);let g=n[c-(t[0]-1)],f=n[c-t[0]]??g,v=g.close,y=g.volume??0;v>f.close?r-=y:v<f.close?i-=y:o-=y;}s.push(u);}),s}},go=Ja;var es={name:"VWAP",shortName:"VWAP",series:"price",precision:2,shouldOhlc:true,figures:[{key:"vwap",title:"VWAP: ",type:"line"}],calc:n=>{let e=0,t=0;return n.map(r=>{let i={},o=r.volume??0,a=(r.high+r.low+r.close)/3;return e+=a*o,t+=o,t!==0&&(i.vwap=e/t),i})}},fo=es;var ts={name:"VWMA",shortName:"VWMA",series:"price",calcParams:[20],precision:2,shouldOhlc:true,figures:[{key:"vwma",title:"VWMA: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=0,o=0,a=[];return n.forEach((s,l)=>{let c={},u=s.volume??0;if(i+=s.close*u,o+=u,l>=r-1){o!==0&&(c.vwma=i/o);let h=n[l-(r-1)],d=h.volume??0;i-=h.close*d,o-=d;}a.push(c);}),a}},yo=ts;var rs={name:"WMA",shortName:"WMA",series:"price",calcParams:[20],precision:2,shouldOhlc:true,figures:[{key:"wma",title:"WMA: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0],i=r*(r+1)/2;return n.map((o,a)=>{let s={};if(a>=r-1){let l=0;for(let c=0;c<r;c++){let u=c+1;l+=n[a-(r-1)+c].close*u;}s.wma=l/i;}return s})}},vo=rs;var is={name:"WR",shortName:"WR",calcParams:[6,10,14],figures:[{key:"wr1",title:"WR1: ",type:"line"},{key:"wr2",title:"WR2: ",type:"line"},{key:"wr3",title:"WR3: ",type:"line"}],regenerateFigures:n=>n.map((e,t)=>({key:`wr${t+1}`,title:`WR${t+1}: `,type:"line"})),calc:(n,e)=>{let{calcParams:t,figures:r}=e;return n.map((i,o)=>{let a={},s=i.close;return t.forEach((l,c)=>{let u=l-1;if(o>=u){let h=yr(n.slice(o-u,o+1),"high","low"),d=h[0],m=h[1],p=d-m;a[r[c].key]=p===0?0:(s-d)/p*100;}}),a})}},_o=is;var os={name:"ZZ",shortName:"ZZ",series:"price",calcParams:[5],precision:2,shouldOhlc:true,figures:[{key:"zigzag",title:"ZZ: ",type:"line"}],calc:(n,e)=>{let r=e.calcParams[0]/100,i=n.map(()=>({}));if(n.length<3)return i;let o=n[1].close>n[0].close?1:-1;o===1?n[0].low:n[0].high;let l=0,c=o===1?n[0].high:n[0].low;for(let u=1;u<n.length;u++)o===1?(n[u].high>=c&&(l=u,c=n[u].high),(c-n[u].low)/c>=r&&(i[l].zigzag=c,o=-1,l=u,c=n[u].low)):(n[u].low<=c&&(l=u,c=n[u].low),(n[u].high-c)/c>=r&&(i[l].zigzag=c,o=1,l=u,c=n[u].high));return i}},bo=os;var vr={},ns=[xi,Ci,Ti,Si,Ai,Pi,wi,Ei,Ii,Ri,Di,ki,Mi,Fi,Li,Bi,Oi,Ni,Vi,Wi,Yi,Hi,zi,Xi,Ui,Gi,$i,ji,qi,Zi,Qi,Ki,Ji,eo,to,ro,io,ao,so,lo,co,uo,mo,po,go,fo,yo,vo,_o,bo];ns.forEach(n=>{vr[n.name]=lt.extend(n);});function Xr(n){vr[n.name]=lt.extend(n);}function _r(n){return vr[n]??null}function as(){return Object.keys(vr)}function fe(n,e){let t=e?.ignoreEvent??false;return Pe(t)?!t:!t.includes(n)}var xo=1,Ct=-1,Co="overlay_",We="overlay_figure_",ut=class n{id;groupId="";paneId;name;totalStep=1;currentStep=xo;lock=false;visible=true;zLevel=0;needDefaultPointFigure=false;needDefaultXAxisFigure=false;needDefaultYAxisFigure=false;mode="normal";modeSensitivity=8;points=[];extendData;styles=null;createPointFigures=null;createXAxisFigures=null;createYAxisFigures=null;performEventPressedMove=null;performEventMoveForDrawing=null;onDrawStart=null;onDrawing=null;onDrawEnd=null;onClick=null;onDoubleClick=null;onRightClick=null;onPressedMoveStart=null;onPressedMoving=null;onPressedMoveEnd=null;onMouseMove=null;onMouseEnter=null;onMouseLeave=null;onRemoved=null;onSelected=null;onDeselected=null;_prevZLevel=0;_prevOverlay;_prevPressedPoint=null;_prevPressedPoints=[];constructor(e){this.override(e);}override(e){this._prevOverlay=Ae({...this,_prevOverlay:null});let{id:t,name:r,currentStep:i,points:o,styles:a,...s}=e;if(U(this,s),L(this.name)||(this.name=r??""),!L(this.id)&&L(t)&&(this.id=t),_(a)&&(this.styles??={},U(this.styles,a)),ne(o)&&o.length>0){let l=0;if(this.points=[...o],o.length>=this.totalStep-1?(this.currentStep=Ct,l=this.totalStep-1):(this.currentStep=o.length+1,l=o.length),j(this.performEventMoveForDrawing))for(let c=0;c<l;c++)this.performEventMoveForDrawing({currentStep:c+2,mode:this.mode,points:this.points,performPointIndex:c,performPoint:this.points[c]});this.currentStep===Ct&&this.performEventPressedMove?.({currentStep:this.currentStep,mode:this.mode,points:this.points,performPointIndex:this.points.length-1,performPoint:this.points[this.points.length-1]});}}getPrevZLevel(){return this._prevZLevel}setPrevZLevel(e){this._prevZLevel=e;}shouldUpdate(){let e=this._prevOverlay.zLevel!==this.zLevel,t=e||JSON.stringify(this._prevOverlay.points)!==JSON.stringify(this.points)||this._prevOverlay.visible!==this.visible||this._prevOverlay.extendData!==this.extendData||this._prevOverlay.styles!==this.styles;return {sort:e,draw:t}}nextStep(){this.currentStep===this.totalStep-1?this.currentStep=Ct:this.currentStep++;}forceComplete(){this.currentStep=Ct;}isDrawing(){return this.currentStep!==Ct}isStart(){return this.currentStep===xo}eventMoveForDrawing(e){let t=this.currentStep-1,r={};w(e.timestamp)&&(r.timestamp=e.timestamp),w(e.dataIndex)&&(r.dataIndex=e.dataIndex),w(e.value)&&(r.value=e.value),this.points[t]=r,this.performEventMoveForDrawing?.({currentStep:this.currentStep,mode:this.mode,points:this.points,performPointIndex:t,performPoint:r});}eventPressedPointMove(e,t){this.points[t].timestamp=e.timestamp,w(e.value)&&(this.points[t].value=e.value),this.performEventPressedMove?.({currentStep:this.currentStep,points:this.points,mode:this.mode,performPointIndex:t,performPoint:this.points[t]});}startPressedMove(e){this._prevPressedPoint={...e},this._prevPressedPoints=Ae(this.points);}eventPressedOtherMove(e,t){if(this._prevPressedPoint!==null){let r=null;w(e.dataIndex)&&w(this._prevPressedPoint.dataIndex)&&(r=e.dataIndex-this._prevPressedPoint.dataIndex);let i=null;w(e.value)&&w(this._prevPressedPoint.value)&&(i=e.value-this._prevPressedPoint.value),this.points=this._prevPressedPoints.map(o=>{w(o.timestamp)&&(o.dataIndex=t.timestampToDataIndex(o.timestamp));let a={...o};return w(r)&&w(o.dataIndex)&&(a.dataIndex=o.dataIndex+r,a.timestamp=t.dataIndexToTimestamp(a.dataIndex)??void 0),w(i)&&w(o.value)&&(a.value=o.value+i),a});}}static extend(e){class t extends n{constructor(){super(e);}}return t}};var q={PRICE:2,VOLUME:0};var ss={name:"fibonacciLine",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({chart:n,coordinates:e,bounding:t,overlay:r,yAxis:i})=>{let o=r.points;if(e.length>0){let a=0;i?.isInCandle()??true?a=n.getSymbol()?.pricePrecision??q.PRICE:n.getIndicators({paneId:r.paneId}).forEach(d=>{a=Math.max(a,d.precision);});let s=[],l=[],c=0,u=t.width;if(e.length>1&&w(o[0].value)&&w(o[1].value)){let h=[1,.786,.618,.5,.382,.236,0],d=e[0].y-e[1].y,m=o[0].value-o[1].value;h.forEach(p=>{let g=e[1].y+d*p,f=n.getDecimalFold().format(n.getThousandsSeparator().format(((o[1].value??0)+m*p).toFixed(a)));s.push({coordinates:[{x:c,y:g},{x:u,y:g}]}),l.push({x:c,y:g,text:`${f} (${(p*100).toFixed(1)}%)`,baseline:"bottom"});});}return [{type:"line",attrs:s},{type:"text",isCheckEvent:false,attrs:l}]}return []}},To=ss;var ls={name:"horizontalRayLine",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n,bounding:e})=>{let t={x:0,y:n[0].y};return _(n[1])&&n[0].x<n[1].x&&(t.x=e.width),[{type:"line",attrs:{coordinates:[n[0],t]}}]},performEventPressedMove:({points:n,performPoint:e})=>{n[0].value=e.value,n[1].value=e.value;},performEventMoveForDrawing:({currentStep:n,points:e,performPoint:t})=>{n===2&&(e[0].value=t.value);}},So=ls;var cs={name:"horizontalSegment",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n})=>{let e=[];return n.length===2&&e.push({coordinates:n}),[{type:"line",attrs:e}]},performEventPressedMove:({points:n,performPoint:e})=>{n[0].value=e.value,n[1].value=e.value;},performEventMoveForDrawing:({currentStep:n,points:e,performPoint:t})=>{n===2&&(e[0].value=t.value);}},Ao=cs;var us={name:"horizontalStraightLine",totalStep:2,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n,bounding:e})=>[{type:"line",attrs:{coordinates:[{x:0,y:n[0].y},{x:e.width,y:n[0].y}]}}]},Po=us;var Ee=class{_children=[];_callbacks=new Map;registerEvent(e,t){return this._callbacks.set(e,t),this}onEvent(e,t){let r=this._callbacks.get(e);return _(r)&&this.checkEventOn(t)?r(t):false}dispatchEventToChildren(e,t){let r=this._children.length-1;if(r>-1){for(let i=r;i>-1;i--)if(this._children[i].dispatchEvent(e,t))return true}return false}dispatchEvent(e,t){return this.dispatchEventToChildren(e,t)?true:this.onEvent(e,t)}addChild(e){return this._children.push(e),this}clear(){this._children=[];}};var re=2,Tt=class n extends Ee{attrs;styles;constructor(e){super(),this.attrs=e.attrs,this.styles=e.styles;}checkEventOn(e){return this.checkEventOnImp(e,this.attrs,this.styles)}setAttrs(e){return this.attrs=e,this}setStyles(e){return this.styles=e,this}draw(e){this.drawImp(e,this.attrs,this.styles);}static extend(e){class t extends n{checkEventOnImp(i,o,a){return e.checkEventOn(i,o,a)}drawImp(i,o,a){e.draw(i,o,a);}}return t}};function Ur(n,e){let t=[];t=t.concat(e);for(let r of t){let{coordinates:i}=r;if(i.length>1)for(let o=1;o<i.length;o++){let a=i[o-1],s=i[o];if(a.x===s.x){if(Math.abs(a.y-n.y)+Math.abs(s.y-n.y)-Math.abs(a.y-s.y)<re+re&&Math.abs(n.x-a.x)<re)return true}else {let l=ht(a,s),c=br(l,n),u=Math.abs(c-n.y);if(Math.abs(a.x-n.x)+Math.abs(s.x-n.x)-Math.abs(a.x-s.x)<re+re&&u*u/(l[0]*l[0]+1)<re*re)return true}}}return false}function br(n,e){return n!==null?e.x*n[0]+n[1]:e.y}function Be(n,e,t){let r=ht(n,e);return br(r,t)}function ht(n,e){let t=n.x-e.x;if(t!==0){let r=(n.y-e.y)/t,i=n.y-r*n.x;return [r,i]}return null}function Gr(n,e,t){let r=e.length,i=w(t)?t>0&&t<1?t:0:t?.5:0;if(i>0&&r>2){let o=e[0].x,a=e[0].y;for(let l=1;l<r-1;l++){let c=e[l-1],u=e[l],h=e[l+1],d=u.x-c.x,m=u.y-c.y,p=h.x-u.x,g=h.y-u.y,f=h.x-c.x,v=h.y-c.y,y=Math.sqrt(d*d+m*m),b=Math.sqrt(p*p+g*g),S=b/(b+y),x=u.x+f*i*S,C=u.y+v*i*S;x=Math.min(x,Math.max(h.x,u.x)),C=Math.min(C,Math.max(h.y,u.y)),x=Math.max(x,Math.min(h.x,u.x)),C=Math.max(C,Math.min(h.y,u.y)),f=x-u.x,v=C-u.y;let T=u.x-f*y/b,A=u.y-v*y/b;T=Math.min(T,Math.max(c.x,u.x)),A=Math.min(A,Math.max(c.y,u.y)),T=Math.max(T,Math.min(c.x,u.x)),A=Math.max(A,Math.min(c.y,u.y)),f=u.x-T,v=u.y-A,x=u.x+f*b/y,C=u.y+v*b/y,n.bezierCurveTo(o,a,T,A,u.x,u.y),o=x,a=C;}let s=e[r-1];n.bezierCurveTo(o,a,s.x,s.y,s.x,s.y);}else for(let o=1;o<r;o++)n.lineTo(e[o].x,e[o].y);}function hs(n,e,t){let r=[];r=r.concat(e);let{style:i="solid",smooth:o=false,size:a=1,color:s="currentColor",dashedValue:l=[2,2]}=t;n.lineWidth=a,n.strokeStyle=s,i==="dashed"?n.setLineDash(l):n.setLineDash([]);let c=a%2===1?.5:0;r.forEach(({coordinates:u})=>{u.length>1&&(u.length===2&&(u[0].x===u[1].x||u[0].y===u[1].y)?(n.beginPath(),u[0].x===u[1].x?(n.moveTo(u[0].x+c,u[0].y),n.lineTo(u[1].x+c,u[1].y)):(n.moveTo(u[0].x,u[0].y+c),n.lineTo(u[1].x,u[1].y+c)),n.stroke(),n.closePath()):(n.save(),a%2===1&&n.translate(.5,.5),n.beginPath(),n.moveTo(u[0].x,u[0].y),Gr(n,u,o),n.stroke(),n.closePath(),n.restore()));});}var ds={name:"line",checkEventOn:Ur,draw:(n,e,t)=>{hs(n,e,t);}},wo=ds;function $r(n,e,t){let r=t??0,i=[];if(n.length>1)if(n[0].x===n[1].x){let a=e.height;if(i.push({coordinates:[{x:n[0].x,y:0},{x:n[0].x,y:a}]}),n.length>2){i.push({coordinates:[{x:n[2].x,y:0},{x:n[2].x,y:a}]});let s=n[0].x-n[2].x;for(let l=0;l<r;l++){let c=s*(l+1);i.push({coordinates:[{x:n[0].x+c,y:0},{x:n[0].x+c,y:a}]});}}}else {let a=e.width,s=ht(n[0],n[1]),l=s[0],c=s[1];if(i.push({coordinates:[{x:0,y:0*l+c},{x:a,y:a*l+c}]}),n.length>2){let u=n[2].y-l*n[2].x;i.push({coordinates:[{x:0,y:0*l+u},{x:a,y:a*l+u}]});let h=c-u;for(let d=0;d<r;d++){let m=c+h*(d+1);i.push({coordinates:[{x:0,y:0*l+m},{x:a,y:a*l+m}]});}}}return i}var ms={name:"parallelStraightLine",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n,bounding:e})=>[{type:"line",attrs:$r(n,e)}]},Eo=ms;var ps={name:"priceChannelLine",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n,bounding:e})=>[{type:"line",attrs:$r(n,e,1)}]},Io=ps;var gs={name:"priceLine",totalStep:2,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({chart:n,coordinates:e,bounding:t,overlay:r,yAxis:i})=>{let o=0;i?.isInCandle()??true?o=n.getSymbol()?.pricePrecision??q.PRICE:n.getIndicators({paneId:r.paneId}).forEach(l=>{o=Math.max(o,l.precision);});let{value:a=0}=r.points[0];return [{type:"line",attrs:{coordinates:[e[0],{x:t.width,y:e[0].y}]}},{type:"text",ignoreEvent:true,attrs:{x:e[0].x,y:e[0].y,text:n.getDecimalFold().format(n.getThousandsSeparator().format(a.toFixed(o))),baseline:"bottom"}}]}},Ro=gs;function fs(n,e){if(n.length>1){let t={x:0,y:0};return n[0].x===n[1].x&&n[0].y!==n[1].y?n[0].y<n[1].y?t={x:n[0].x,y:e.height}:t={x:n[0].x,y:0}:n[0].x>n[1].x?t={x:0,y:Be(n[0],n[1],{x:0,y:n[0].y})}:t={x:e.width,y:Be(n[0],n[1],{x:e.width,y:n[0].y})},{coordinates:[n[0],t]}}return []}var ys={name:"rayLine",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n,bounding:e})=>[{type:"line",attrs:fs(n,e)}]},Do=ys;var vs={name:"segment",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n})=>n.length===2?[{type:"line",attrs:{coordinates:n}}]:[]},ko=vs;var _s={name:"straightLine",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n,bounding:e})=>n.length===2?n[0].x===n[1].x?[{type:"line",attrs:{coordinates:[{x:n[0].x,y:0},{x:n[0].x,y:e.height}]}}]:[{type:"line",attrs:{coordinates:[{x:0,y:Be(n[0],n[1],{x:0,y:n[0].y})},{x:e.width,y:Be(n[0],n[1],{x:e.width,y:n[0].y})}]}}]:[]},Mo=_s;var bs={name:"verticalRayLine",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n,bounding:e})=>{if(n.length===2){let t={x:n[0].x,y:0};return n[0].y<n[1].y&&(t.y=e.height),[{type:"line",attrs:{coordinates:[n[0],t]}}]}return []},performEventPressedMove:({points:n,performPoint:e})=>{n[0].timestamp=e.timestamp,n[0].dataIndex=e.dataIndex,n[1].timestamp=e.timestamp,n[1].dataIndex=e.dataIndex;},performEventMoveForDrawing:({currentStep:n,points:e,performPoint:t})=>{n===2&&(e[0].timestamp=t.timestamp,e[0].dataIndex=t.dataIndex);}},Fo=bs;var xs={name:"verticalSegment",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n})=>n.length===2?[{type:"line",attrs:{coordinates:n}}]:[],performEventPressedMove:({points:n,performPoint:e})=>{n[0].timestamp=e.timestamp,n[0].dataIndex=e.dataIndex,n[1].timestamp=e.timestamp,n[1].dataIndex=e.dataIndex;},performEventMoveForDrawing:({currentStep:n,points:e,performPoint:t})=>{n===2&&(e[0].timestamp=t.timestamp,e[0].dataIndex=t.dataIndex);}},Lo=xs;var Cs={name:"verticalStraightLine",totalStep:2,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:n,bounding:e})=>[{type:"line",attrs:{coordinates:[{x:n[0].x,y:0},{x:n[0].x,y:e.height}]}}]},Bo=Cs;var Ts={name:"simpleAnnotation",totalStep:2,styles:{line:{style:"dashed"}},createPointFigures:({overlay:n,coordinates:e})=>{let t="";_(n.extendData)&&(j(n.extendData)?t=n.extendData(n):t=n.extendData??"");let r=e[0].x,i=e[0].y-6,o=i-50,a=o-5;return [{type:"line",attrs:{coordinates:[{x:r,y:i},{x:r,y:o}]},ignoreEvent:true},{type:"polygon",attrs:{coordinates:[{x:r,y:o},{x:r-4,y:a},{x:r+4,y:a}]},ignoreEvent:true},{type:"text",attrs:{x:r,y:a,text:t,align:"center",baseline:"bottom"},ignoreEvent:true}]}},Oo=Ts;var Ss={name:"simpleTag",totalStep:2,styles:{line:{style:"dashed"}},createPointFigures:({bounding:n,coordinates:e})=>({type:"line",attrs:{coordinates:[{x:0,y:e[0].y},{x:n.width,y:e[0].y}]},ignoreEvent:true}),createYAxisFigures:({chart:n,overlay:e,coordinates:t,bounding:r,yAxis:i})=>{let o=i?.isFromZero()??false,a="left",s=0;o?(a="left",s=0):(a="right",s=r.width);let l="";return _(e.extendData)&&(j(e.extendData)?l=e.extendData(e):l=e.extendData??""),!_(l)&&w(e.points[0].value)&&(l=ee(e.points[0].value,n.getSymbol()?.pricePrecision??q.PRICE)),{type:"text",attrs:{x:s,y:t[0].y,text:l,align:a,baseline:"middle"}}}},No=Ss;var xr={},As=[To,So,Ao,Po,Eo,Io,Ro,Do,ko,Mo,Fo,Lo,Bo,Oo,No];As.forEach(n=>{xr[n.name]=ut.extend(n);});function Ps(n){xr[n.name]=ut.extend(n);}function Vo(n){return xr[n]??null}function ws(){return Object.keys(xr)}var Cr=-1;function Ce(n){return j(window.requestAnimationFrame)?window.requestAnimationFrame(n):window.setTimeout(n,20)}function jr(n){j(window.cancelAnimationFrame)?window.cancelAnimationFrame(n):window.clearTimeout(n);}var St=null;function z(n){return n.ownerDocument.defaultView?.devicePixelRatio??1}var Wo=new Map;function se(n,e,t){let r=`${n??12}:${e??"normal"}:${t??"Helvetica Neue"}`,i=Wo.get(r);return i===void 0&&(i=`${e??"normal"} ${n??12}px ${t??"Helvetica Neue"}`,Wo.set(r,i)),i}function ie(n,e,t,r){if(!_(St)){let i=document.createElement("canvas"),o=z(i);St=i.getContext("2d"),St.scale(o,o);}return St.font=se(e,t,r),Math.round(St.measureText(n).width)}var Yo=new Map;function Ie(n,e){let t=`${n.font}\0${e}`,r=Yo.get(t);return r===void 0&&(r=n.measureText(e).width,Yo.set(t,r)),r}function Ho(){return {from:0,to:0,range:0,realFrom:0,realTo:0,realRange:0,displayFrom:0,displayTo:0,displayRange:0}}var Ye=class{name;scrollZoomEnabled=true;createTicks;_parent;_range=Ho();_prevRange=Ho();_ticks=[];_autoCalcTickFlag=true;constructor(e){this._parent=e;}getParent(){return this._parent}buildTicks(e){return this._autoCalcTickFlag&&(this._range=this.createRangeImp()),this._prevRange.from!==this._range.from||this._prevRange.to!==this._range.to||e?(this._prevRange=this._range,this._ticks=this.createTicksImp(),true):false}getTicks(){return this._ticks}setRange(e){this._autoCalcTickFlag=false,this._range=e;}getRange(){return this._range}setAutoCalcTickFlag(e){this._autoCalcTickFlag=e;}getAutoCalcTickFlag(){return this._autoCalcTickFlag}};var B={CANDLE:"candle_pane",INDICATOR:"indicator_pane_",X_AXIS:"x_axis_pane"};var Tr=8,de=class n extends Ye{reverse=false;inside=false;position="right";gap={top:.2,bottom:.1};_animRealFrom=0;_animRealTo=0;_animVelocityFrom=0;_animVelocityTo=0;_animating=false;_prevRealFrom=null;_prevRealTo=null;_lastFrameTime=0;scaleSmoothTime=.56;scaleDeadbandPx=0;scaleDeadbandLeak=.28;_lastTickBuildHeight=-1;createRange=e=>e.defaultRange;minSpan=e=>we(-e);valueToRealValue=e=>e;realValueToDisplayValue=e=>e;displayValueToRealValue=e=>e;realValueToValue=e=>e;displayValueToText=(e,t)=>ee(e,t);constructor(e,t){super(e),this.override(t);}override(e){let{name:t,gap:r,...i}=e;L(this.name)||(this.name=t),U(this.gap,r),U(this,i);}createRangeImp(){let e=this.getParent(),t=e.getChart(),r=t.getChartStore(),i=e.getId(),o=Number.MAX_SAFE_INTEGER,a=Number.MIN_SAFE_INTEGER,s=false,l=Number.MAX_SAFE_INTEGER,c=Number.MIN_SAFE_INTEGER,u=Number.MAX_SAFE_INTEGER,h=r.getIndicatorsByPaneId(i);h.forEach(V=>{s||=V.shouldOhlc,u=Math.min(u,V.precision),w(V.minValue)&&(l=Math.min(l,V.minValue)),w(V.maxValue)&&(c=Math.max(c,V.maxValue));});let d=4,m=this.isInCandle();if(m){let V=r.getSymbol()?.pricePrecision??q.PRICE;u!==Number.MAX_SAFE_INTEGER?d=Math.min(u,V):d=V;}else u!==Number.MAX_SAFE_INTEGER&&(d=u);let p=r.getVisibleRangeDataList(),g=t.getStyles().candle,f=g.type==="area",v=g.area.value,y=m&&!f||!m&&s;p.forEach(V=>{let O=V.dataIndex,te=V.data.current;if(_(te)&&(y&&(o=Math.min(o,te.low),a=Math.max(a,te.high)),m&&f)){let G=te[v];w(G)&&(o=Math.min(o,G),a=Math.max(a,G));}h.forEach(({result:G,figures:$})=>{let H=G[O]??{};$.forEach(Q=>{let le=H[Q.key];w(le)&&(o=Math.min(o,le),a=Math.max(a,le));});});}),o!==Number.MAX_SAFE_INTEGER&&a!==Number.MIN_SAFE_INTEGER?(o=Math.min(l,o),a=Math.max(c,a)):(o=0,a=10);let b=a-o,S={from:o,to:a,range:b,realFrom:o,realTo:a,realRange:b,displayFrom:o,displayTo:a,displayRange:b},x=this.createRange({chart:t,paneId:i,defaultRange:S}),C=x.realFrom,T=x.realTo,A=x.realRange,P=this.minSpan(d);if(C===T||A<P){let V=l===C,O=c===T,te=Tr/2;C=V?C:O?C-Tr*P:C-te*P,T=O?T:V?T+Tr*P:T+te*P;}let R=this.getBounding().height,{top:D,bottom:E}=this.gap,I=D;I>=1&&(I=I/R);let k=E;if(k>=1&&(k=k/R),A=T-C,C=C-A*k,T=T+A*I,w(this._prevRealFrom)&&w(this._prevRealTo)){let V=Math.max(R,1),te=Math.max(Math.abs(this._prevRealTo-this._prevRealFrom),Number.EPSILON)/V,G=Math.max(this.scaleDeadbandPx,0)*te,$=Math.max(0,Math.min(this.scaleDeadbandLeak,1)),H=C-this._prevRealFrom,Q=T-this._prevRealTo;Math.abs(H)<G&&(C=this._prevRealFrom+H*$),Math.abs(Q)<G&&(T=this._prevRealTo+Q*$),A=T-C;}let F=this.realValueToValue(C,{range:x}),W=this.realValueToValue(T,{range:x}),X=this.realValueToDisplayValue(C,{range:x}),Y=this.realValueToDisplayValue(T,{range:x});return {from:F,to:W,range:W-F,realFrom:C,realTo:T,realRange:T-C,displayFrom:X,displayTo:Y,displayRange:Y-X}}isInCandle(){return this.getParent().getId()===B.CANDLE}isFromZero(){return this.position==="left"&&this.inside||this.position==="right"&&!this.inside}tickCoord(e){let t=this.getRange(),r=this.getParent().getYAxisWidget()?.getBounding().height??0,i=this.realValueToValue(this.displayValueToRealValue(+e.value,{range:t}),{range:t}),o=this.convertToPixel(i);return Number.isFinite(o)&&o>=-r&&o<=r*2?o:this._convertToPixelByRange(i,t,r)}createTicksImp(){let e=this.getRange(),{displayFrom:t,displayTo:r,displayRange:i}=e,o=[];if(i>=0){let b=oo(i/Tr),S=no(b),x=zr(Math.ceil(t/b)*b,S),C=zr(Math.floor(r/b)*b,S),T=0,A=x;if(b!==0)for(;A<=C;){let P=A.toFixed(S);o[T]={text:P,coord:0,value:P},++T,A+=b;}}let a=this.getParent(),s=a.getYAxisWidget()?.getBounding().height??0,l=a.getChart().getChartStore(),c=[],u=l.getIndicatorsByPaneId(a.getId()),h=l.getStyles(),d=0,m=false;this.isInCandle()?d=l.getSymbol()?.pricePrecision??q.PRICE:u.forEach(b=>{d=Math.max(d,b.precision),m||=b.shouldFormatBigNumber;});let p=l.getInnerFormatter(),g=l.getThousandsSeparator(),f=l.getDecimalFold(),v=h.yAxis.tickText.size,y=NaN;if(o.forEach(({value:b})=>{let S=this.displayValueToText(+b,d),x=this.realValueToValue(this.displayValueToRealValue(+b,{range:e}),{range:e}),C=this._convertToPixelByRange(x,e,s);m&&(S=p.formatBigNumber(b)),S=f.format(g.format(S));let T=w(y);C>v&&C<s-v&&(T&&Math.abs(y-C)>v*2||!T)&&(c.push({text:S,coord:C,value:b}),y=C);}),c.length===0&&o.length>0){let b=NaN;o.forEach(({value:S})=>{let x=this.displayValueToText(+S,d),C=this.realValueToValue(this.displayValueToRealValue(+S,{range:e}),{range:e}),T=this._convertToPixelByRange(C,e,s);if(!Number.isFinite(T)||T<0||T>s)return;m&&(x=p.formatBigNumber(S)),x=f.format(g.format(x)),(!w(b)||Math.abs(b-T)>v)&&(c.push({text:x,coord:T,value:S}),b=T);});}return j(this.createTicks)?this.createTicks({range:this.getRange(),bounding:this.getBounding(),defaultTicks:c}):c}getAutoSize(){let e=this.getParent(),r=e.getChart().getChartStore(),i=r.getStyles(),o=i.yAxis,a=o.size;if(a!=="auto")return a;let s=0;if(o.show&&(o.axisLine.show&&(s+=o.axisLine.size),o.tickLine.show&&(s+=o.tickLine.length),o.tickText.show)){let g=0;this.getTicks().forEach(f=>{g=Math.max(g,ie(f.text,o.tickText.size,o.tickText.weight,o.tickText.family));}),s+=o.tickText.marginStart+o.tickText.marginEnd+g;}let l=i.candle.priceMark,c=l.show&&l.last.show&&l.last.text.show,u=0,h=i.crosshair,d=h.show&&h.horizontal.show&&h.horizontal.text.show,m=0;if(c||d){let g=r.getSymbol()?.pricePrecision??q.PRICE,f=this.getRange().displayTo;if(c){let v=r.getDataList(),y=v[v.length-1];if(_(y)){let{paddingLeft:b,paddingRight:S,size:x,family:C,weight:T}=l.last.text;u=b+ie(ee(y.close,g),x,T,C)+S;let A=r.getInnerFormatter().formatExtendText;l.last.extendTexts.forEach((P,R)=>{let D=A({type:"last_price",data:y,index:R});D.length>0&&P.show&&(u=Math.max(u,P.paddingLeft+ie(D,P.size,P.weight,P.family)+P.paddingRight));});}}if(d){let v=r.getIndicatorsByPaneId(e.getId()),y=0,b=false;v.forEach(C=>{y=Math.max(C.precision,y),b||=C.shouldFormatBigNumber;});let S=2;if(this.isInCandle()){let C=i.indicator.lastValueMark;C.show&&C.text.show?S=Math.max(y,g):S=g;}else S=y;let x=ee(f,S);b&&(x=r.getInnerFormatter().formatBigNumber(x)),x=r.getDecimalFold().format(x),m+=h.horizontal.text.paddingLeft+h.horizontal.text.paddingRight+h.horizontal.text.borderSize*2+ie(x,h.horizontal.text.size,h.horizontal.text.weight,h.horizontal.text.family);}}let p=Math.max(s,u,m);return Math.ceil(p/4)*4}getBounding(){return this.getParent().getYAxisWidget().getBounding()}convertFromPixel(e){let t=this.getBounding().height,r=this.getRange(),{realFrom:i,realRange:o}=r,s=(this.reverse?e/t:1-e/t)*o+i;return this.realValueToValue(s,{range:r})}buildTicks(e){let t=this.getParent().getYAxisWidget()?.getBounding().height??0,r=t!==this._lastTickBuildHeight,i=this.getTicks().length===0,o=this.getAutoCalcTickFlag(),a=super.buildTicks(e||r||i);if(this._lastTickBuildHeight=t,o){let{realFrom:s,realTo:l}=this.getRange();this._prevRealFrom===null?(this._animRealFrom=s,this._animRealTo=l,this._animVelocityFrom=0,this._animVelocityTo=0):this._animating||(this._animating=true,this._lastFrameTime=performance.now(),this._driveSpring()),this._prevRealFrom=s,this._prevRealTo=l;}return a}_smoothDamp(e,t,r,i){let o=Number.isFinite(this.scaleSmoothTime)?this.scaleSmoothTime:.28,s=2/Math.max(.08,Math.min(o,1.2)),l=s*i,c=1/(1+l+.48*l*l+.235*l*l*l),u=e-t,h=(r+s*u)*i,d=(r-s*h)*c;return {value:t+(u+h)*c,velocity:d}}_driveSpring(){let e=this.getParent(),t=e.getChart(),r=e.getId(),i=()=>{if(!this._animating)return;let o=performance.now(),a=Math.min((o-this._lastFrameTime)/1e3,.12);this._lastFrameTime=o;let s=this._prevRealFrom??this._animRealFrom,l=this._prevRealTo??this._animRealTo,c=1/120;for(;a>0;){let p=Math.min(c,a),g=this._smoothDamp(this._animRealFrom,s,this._animVelocityFrom,p),f=this._smoothDamp(this._animRealTo,l,this._animVelocityTo,p);this._animRealFrom=g.value,this._animRealTo=f.value,this._animVelocityFrom=g.velocity,this._animVelocityTo=f.velocity,a-=p;}let u=Math.max(Math.abs(l-s),1),h=u*1e-5,d=u*1e-4;Math.abs(this._animRealFrom-s)<h&&Math.abs(this._animRealTo-l)<h&&Math.abs(this._animVelocityFrom)<d&&Math.abs(this._animVelocityTo)<d?(this._animRealFrom=s,this._animRealTo=l,this._animVelocityFrom=0,this._animVelocityTo=0,this._animating=false,t.updatePane(0,r)):(t.updatePane(0,r),Ce(i));};Ce(i);}getDisplayRange(){if(this._animating||this._prevRealFrom!==null)return {realFrom:this._animRealFrom,realTo:this._animRealTo};let e=this.getRange();return {realFrom:e.realFrom,realTo:e.realTo}}convertToPixel(e){let t=this.getRange(),r=this.valueToRealValue(e,{range:t}),i=this.getParent().getYAxisWidget()?.getBounding().height??0,{realFrom:o,realTo:a}=this.getDisplayRange(),s=a-o;if(s===0)return 0;let l=(r-o)/s;return this.reverse?l*i:(1-l)*i}convertToNicePixel(e){let t=this.getParent().getYAxisWidget()?.getBounding().height??0,r=this.convertToPixel(e);return Math.max(t*.05,Math.min(r,t*.98))}_convertToPixelByRange(e,t,r){let i=this.valueToRealValue(e,{range:t}),o=t.realRange;if(o===0)return 0;let a=(i-t.realFrom)/o;return this.reverse?a*r:(1-a)*r}static extend(e){class t extends n{constructor(i){super(i,e);}}return t}};var Es={name:"normal"},zo=Es;var Is={name:"percentage",minSpan:()=>Math.pow(10,-2),displayValueToText:n=>`${ee(n,2)}%`,valueToRealValue:(n,{range:e})=>(n-e.from)/e.range*e.realRange+e.realFrom,realValueToValue:(n,{range:e})=>(n-e.realFrom)/e.realRange*e.range+e.from,createRange:({chart:n,defaultRange:e})=>{let t=n.getDataList(),r=n.getVisibleRange(),i=t[r.from];if(_(i)){let{from:o,to:a,range:s}=e,l=(e.from-i.close)/i.close*100,c=(e.to-i.close)/i.close*100,u=c-l;return {from:o,to:a,range:s,realFrom:l,realTo:c,realRange:u,displayFrom:l,displayTo:c,displayRange:u}}return e}},Xo=Is;var Rs={name:"logarithm",minSpan:n=>.05*we(-n),valueToRealValue:n=>n<0?-xe(Math.abs(n)):xe(n),realValueToDisplayValue:n=>n<0?-we(Math.abs(n)):we(n),displayValueToRealValue:n=>n<0?-xe(Math.abs(n)):xe(n),realValueToValue:n=>n<0?-we(Math.abs(n)):we(n),createRange:({defaultRange:n})=>{let{from:e,to:t,range:r}=n,i=e<0?-xe(Math.abs(e)):xe(e),o=t<0?-xe(Math.abs(t)):xe(t);return {from:e,to:t,range:r,realFrom:i,realTo:o,realRange:o-i,displayFrom:e,displayTo:t,displayRange:r}}},Uo=Rs;var qr={normal:de.extend(zo),percentage:de.extend(Xo),logarithm:de.extend(Uo)};function Ds(n){qr[n.name]=de.extend(n);}function Go(n){return qr[n]??qr.normal}var Zr={second:"HH:mm:ss",minute:"HH:mm",hour:"MM-DD HH:mm",day:"YYYY-MM-DD",week:"YYYY-MM-DD",month:"YYYY-MM",year:"YYYY"},Sr={second:"DD/MM/YYYY, HH:mm:ss",minute:"DD/MM/YYYY, HH:mm",hour:"DD/MM/YYYY, HH:mm",day:"DD/MM/YYYY",week:"DD/MM/YYYY",month:"MM/YYYY",year:"YYYY"};var ks=[1e3,2e3,5e3,1e4,15e3,3e4,6e4,2*6e4,5*6e4,10*6e4,15*6e4,30*6e4,36e5,2*36e5,4*36e5,6*36e5,12*36e5,864e5];function Ms(n,e){switch(n){case "second":return e*1e3;case "minute":return e*6e4;case "hour":return e*36e5;default:return e*864e5}}function Fs(n){for(let e of ks)if(e>=n)return e;return 864e5}var dt=class n extends Ye{constructor(e,t){super(e),this.override(t);}override(e){let{name:t,scrollZoomEnabled:r,createTicks:i}=e;L(this.name)||(this.name=t),this.scrollZoomEnabled=r??this.scrollZoomEnabled,this.createTicks=i??this.createTicks;}createRangeImp(){let t=this.getParent().getChart().getChartStore().getVisibleRange(),{realFrom:r,realTo:i}=t,o=r,a=i,s=i-r+1;return {from:o,to:a,range:s,realFrom:o,realTo:a,realRange:s,displayFrom:o,displayTo:a,displayRange:s}}createTicksImp(){let{realFrom:e,realTo:t,from:r}=this.getRange(),i=this.getParent().getChart().getChartStore(),o=i.getInnerFormatter().formatDate,a=i.getPeriod(),s=[],l=i.getBarSpace().bar,c=i.getStyles().xAxis.tickText,u=Math.max(ie("YYYY-MM-DD HH:mm:ss",c.size,c.weight,c.family),this.getBounding().width/8),h=Math.ceil(u/l);h%2!==0&&(h+=1);let d=a?.timespan??"day",m=a?.multiplier??1;if(d==="second"||d==="minute"||d==="hour"){let p=Ms(d,m),g=h*p,f=Fs(g),v=-1/0;for(let y=Math.max(0,Math.floor(e));y<t;y++){if(y<r)continue;let b=i.dataIndexToTimestamp(y);if(!w(b)||b%f!==0)continue;let S=this.convertToPixel(y);S-v<u||(v=S,s.push({coord:S,value:b,text:o(b,Zr[d],"xAxis")}));}}else {let p=Math.max(0,Math.floor(e/h)*h);for(let g=p;g<t;g+=h)if(g>=r){let f=i.dataIndexToTimestamp(g);w(f)&&s.push({coord:this.convertToPixel(g),value:f,text:o(f,Zr[d],"xAxis")});}}return j(this.createTicks)?this.createTicks({range:this.getRange(),bounding:this.getBounding(),defaultTicks:s}):s}getAutoSize(){let e=this.getParent().getChart().getStyles(),t=e.xAxis,r=t.size;if(r!=="auto")return r;let i=e.crosshair,o=0;t.show&&(t.axisLine.show&&(o+=t.axisLine.size),t.tickLine.show&&(o+=t.tickLine.length),t.tickText.show&&(o+=t.tickText.marginStart+t.tickText.marginEnd+t.tickText.size));let a=0;return i.show&&i.vertical.show&&i.vertical.text.show&&(a+=i.vertical.text.paddingTop+i.vertical.text.paddingBottom+i.vertical.text.borderSize*2+i.vertical.text.size),Math.max(o,a)}getBounding(){return this.getParent().getMainWidget().getBounding()}convertTimestampFromPixel(e){let t=this.getParent().getChart().getChartStore(),r=t.coordinateToDataIndex(e);return t.dataIndexToTimestamp(r)}convertTimestampToPixel(e){let t=this.getParent().getChart().getChartStore(),r=t.timestampToDataIndex(e);return t.dataIndexToCoordinate(r)}convertFromPixel(e){return this.getParent().getChart().getChartStore().coordinateToDataIndex(e)}convertToPixel(e){return this.getParent().getChart().getChartStore().dataIndexToCoordinate(e)}static extend(e){class t extends n{constructor(i){super(i,e);}}return t}};var Ls={name:"normal"},$o=Ls;var Qr={normal:dt.extend($o)};function Bs(n){Qr[n.name]=dt.extend(n);}function jo(n){return Qr[n]??Qr.normal}var Os=typeof import.meta<"u"&&import.meta.env?.DEV===true;function Kr(n,e,t,r,i,o){if(Os){let a=r!==""?`Call api \`${r}\`${i!==""||o!==""?", ":"."}`:"",s=i!==""?`invalid parameter \`${i}\`${o!==""?", ":"."}`:"";console.log(n,e,t,a,s,o!==""?o:"");}}function me(n,e,t){Kr("%c\u{1F611} astroneum warning%c %s%s%s","padding:3px 4px;border-radius:2px;color:#ffffff;background-color:#FF9600","color:#FF9600",n,e,t??"");}function qo(n,e,t){Kr("%c\u{1F61F} astroneum error%c %s%s%s","padding:3px 4px;border-radius:2px;color:#ffffff;background-color:#F92855;","color:#F92855;",n,e,t);}function Zo(){Kr("%c\u2764\uFE0F Welcome to Astroneum. Version is __VERSION__","border-radius:4px;border:dashed 1px #1677FF;line-height:70px;padding:0 20px;margin:16px 0;font-size:14px;color:#1677FF;","","","","");}function He(n){let e={width:0,height:0,left:0,right:0,top:0,bottom:0};return _(n)&&U(e,n),e}var Oe=class{_options={duration:500,iterationCount:1};_doFrameCallback;_currentIterationCount=0;_running=false;_time=0;constructor(e){U(this._options,e);}_loop(){this._running=true;let e=()=>{if(this._running){let t=performance.now()-this._time;t<this._options.duration?(this._doFrameCallback?.(t),Ce(e)):(this.stop(),this._currentIterationCount++,this._currentIterationCount<this._options.iterationCount&&this.start());}};Ce(e);}doFrame(e){return this._doFrameCallback=e,this}setDuration(e){return this._options.duration=e,this}setIterationCount(e){return this._options.iterationCount=e,this}start(){this._running||(this._time=performance.now(),this._loop());}stop(){this._running&&this._doFrameCallback?.(this._options.duration),this._running=false;}};var Jr=1,Qo=new Date().getTime();function mt(n){let e=new Date().getTime();return e===Qo?++Jr:Jr=1,Qo=e,`${n??""}${e}_${Jr}`}function oe(n,e){let t=document.createElement(n),r=e??{};for(let i in r)t.style[i]=r[i]??"";return t}function ei(){return {from:0,to:0,realFrom:0,realTo:0}}var Ko={data:0,indicator:1,overlay:2},At=class{_holdingTasks=null;_running=false;_callback;constructor(e){this._callback=e;}add(e,t="indicator"){let r={priority:t,tasks:e};if(!this._running)this._runBatch(r);else if(_(this._holdingTasks)){let i=Ko[t],o=false;for(let a=0;a<this._holdingTasks.length;a++)if(Ko[this._holdingTasks[a].priority]>i){this._holdingTasks.splice(a,0,r),o=true;break}o||this._holdingTasks.push(r);}else this._holdingTasks=[r];}async _runBatch(e){this._running=true;try{await Promise.all(Object.values(e.tasks));}finally{if(this._running=false,this._callback?.(),_(this._holdingTasks)&&this._holdingTasks.length>0){let t=this._holdingTasks.shift();this._runBatch(t);}else this._holdingTasks=null;}}clear(){this._holdingTasks=null;}};var Pt=class{_callbacks=[];subscribe(e){this._callbacks.indexOf(e)<0&&this._callbacks.push(e);}unsubscribe(e){if(j(e)){let t=this._callbacks.indexOf(e);t>-1&&this._callbacks.splice(t,1);}else this._callbacks=[];}execute(e){this._callbacks.forEach(t=>{t(e);});}isEmpty(){return this._callbacks.length===0}};function Re(n){return n==="transparent"||n==="none"||/^[rR][gG][Bb][Aa]\(([\s]*(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)[\s]*,){3}[\s]*0[\s]*\)$/.test(n)||/^[hH][Ss][Ll][Aa]\(([\s]*(360|3[0-5][0-9]|[012]?[0-9][0-9]?)[\s]*,)([\s]*((100|[0-9][0-9]?)%|0)[\s]*,){2}([\s]*0[\s]*)\)$/.test(n)}function De(n,e){let t=n.replace(/^#/,""),r=parseInt(t,16),i=r>>16&255,o=r>>8&255,a=r&255;return `rgba(${i}, ${o}, ${a}, ${e??1})`}var M={RED:"#F92855",GREEN:"#2DC08E",WHITE:"#FFFFFF",GREY:"#76808F",BLUE:"#1677FF"};function Ns(){return {show:true,horizontal:{show:true,size:1,color:"#EDEDED",style:"dashed",dashedValue:[2,2]},vertical:{show:true,size:1,color:"#EDEDED",style:"dashed",dashedValue:[2,2]}}}function Vs(){let n={show:true,color:M.GREY,textOffset:5,textSize:12,textFamily:"Helvetica Neue",textWeight:"500"};return {type:"candle_solid",bar:{compareRule:"current_open",upColor:M.GREEN,downColor:M.RED,noChangeColor:M.GREY,upBorderColor:M.GREEN,downBorderColor:M.RED,noChangeBorderColor:M.GREY,upWickColor:M.GREEN,downWickColor:M.RED,noChangeWickColor:M.GREY},area:{lineSize:2,lineColor:M.BLUE,smooth:false,value:"close",backgroundColor:[{offset:0,color:De(M.BLUE,.01)},{offset:1,color:De(M.BLUE,.2)}],point:{show:true,color:M.BLUE,radius:4,rippleColor:De(M.BLUE,.3),rippleRadius:8,animation:true,animationDuration:1e3}},priceMark:{show:true,high:{...n},low:{...n},last:{show:true,compareRule:"current_open",upColor:M.GREEN,downColor:M.RED,noChangeColor:M.GREY,line:{show:true,style:"dashed",dashedValue:[4,4],size:1},text:{show:true,style:"fill",size:12,paddingLeft:4,paddingTop:4,paddingRight:4,paddingBottom:4,borderColor:"transparent",borderStyle:"solid",borderSize:0,borderDashedValue:[2,2],color:M.WHITE,family:"Helvetica Neue",weight:"normal",borderRadius:2},extendTexts:[]}},tooltip:{offsetLeft:4,offsetTop:6,offsetRight:4,offsetBottom:6,showRule:"always",showType:"standard",rect:{position:"fixed",paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,offsetLeft:4,offsetTop:4,offsetRight:4,offsetBottom:4,borderRadius:4,borderSize:1,borderColor:"#F2F3F5",color:"#FEFEFE"},title:{show:false,size:14,family:"Helvetica Neue",weight:"normal",color:M.GREY,marginLeft:8,marginTop:4,marginRight:8,marginBottom:4,template:"{ticker} \xB7 {period}"},legend:{size:12,family:"Helvetica Neue",weight:"normal",color:M.GREY,marginLeft:8,marginTop:4,marginRight:8,marginBottom:4,defaultValue:"n/a",template:[{title:"time",value:"{time}"},{title:"open",value:"{open}"},{title:"high",value:"{high}"},{title:"low",value:"{low}"},{title:"close",value:"{close}"},{title:"volume",value:"{volume}"}]},features:[]}}}function Ws(){let n=De(M.GREEN,.7),e=De(M.RED,.7);return {ohlc:{compareRule:"current_open",upColor:n,downColor:e,noChangeColor:M.GREY},bars:[{style:"fill",borderStyle:"solid",borderSize:1,borderDashedValue:[2,2],upColor:n,downColor:e,noChangeColor:M.GREY}],lines:["#FF9600","#935EBD",M.BLUE,"#E11D74","#01C5C4"].map(t=>({style:"solid",smooth:false,size:1,dashedValue:[2,2],color:t})),circles:[{style:"fill",borderStyle:"solid",borderSize:1,borderDashedValue:[2,2],upColor:n,downColor:e,noChangeColor:M.GREY}],lastValueMark:{show:false,text:{show:false,style:"fill",color:M.WHITE,size:12,family:"Helvetica Neue",weight:"normal",borderStyle:"solid",borderColor:"transparent",borderSize:0,borderDashedValue:[2,2],paddingLeft:4,paddingTop:4,paddingRight:4,paddingBottom:4,borderRadius:2}},tooltip:{offsetLeft:4,offsetTop:6,offsetRight:4,offsetBottom:6,showRule:"always",showType:"standard",title:{show:true,showName:true,showParams:true,size:12,family:"Helvetica Neue",weight:"normal",color:M.GREY,marginLeft:8,marginTop:4,marginRight:8,marginBottom:4},legend:{size:12,family:"Helvetica Neue",weight:"normal",color:M.GREY,marginLeft:8,marginTop:4,marginRight:8,marginBottom:4,defaultValue:"n/a"},features:[]}}}function Jo(){return {show:true,size:"auto",axisLine:{show:true,color:"#DDDDDD",size:1},tickText:{show:true,color:M.GREY,size:12,family:"Helvetica Neue",weight:"normal",marginStart:4,marginEnd:6},tickLine:{show:true,size:1,length:3,color:"#DDDDDD"}}}function Ys(){return {show:true,horizontal:{show:true,line:{show:true,style:"dashed",dashedValue:[4,2],size:1,color:M.GREY},text:{show:true,style:"fill",color:M.WHITE,size:12,family:"Helvetica Neue",weight:"normal",borderStyle:"solid",borderDashedValue:[2,2],borderSize:1,borderColor:M.GREY,borderRadius:2,paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,backgroundColor:M.GREY},features:[]},vertical:{show:true,line:{show:true,style:"dashed",dashedValue:[4,2],size:1,color:M.GREY},text:{show:true,style:"fill",color:M.WHITE,size:12,family:"Helvetica Neue",weight:"normal",borderStyle:"solid",borderDashedValue:[2,2],borderSize:1,borderColor:M.GREY,borderRadius:2,paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,backgroundColor:M.GREY}}}}function Hs(){let n=De(M.BLUE,.35),e=De(M.BLUE,.25);function t(){return {style:"fill",color:M.WHITE,size:12,family:"Helvetica Neue",weight:"normal",borderStyle:"solid",borderDashedValue:[2,2],borderSize:1,borderRadius:2,borderColor:M.BLUE,paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,backgroundColor:M.BLUE}}return {point:{color:M.BLUE,borderColor:n,borderSize:1,radius:5,activeColor:M.BLUE,activeBorderColor:n,activeBorderSize:3,activeRadius:5},line:{style:"solid",smooth:false,color:M.BLUE,size:1,dashedValue:[2,2]},rect:{style:"fill",color:e,borderColor:M.BLUE,borderSize:1,borderRadius:0,borderStyle:"solid",borderDashedValue:[2,2]},polygon:{style:"fill",color:e,borderColor:M.BLUE,borderSize:1,borderStyle:"solid",borderDashedValue:[2,2]},circle:{style:"fill",color:e,borderColor:M.BLUE,borderSize:1,borderStyle:"solid",borderDashedValue:[2,2]},arc:{style:"solid",color:M.BLUE,size:1,dashedValue:[2,2]},text:t()}}function zs(){return {size:1,color:"#DDDDDD",fill:true,activeBackgroundColor:De(M.BLUE,.08)}}function en(){return {grid:Ns(),candle:Vs(),indicator:Ws(),xAxis:Jo(),yAxis:Jo(),separator:zs(),crosshair:Ys(),overlay:Hs()}}var Xs={grid:{horizontal:{color:"#EDEDED"},vertical:{color:"#EDEDED"}},candle:{priceMark:{high:{color:"#76808F"},low:{color:"#76808F"}},tooltip:{rect:{color:"#FEFEFE",borderColor:"#F2F3F5"},title:{color:"#76808F"},legend:{color:"#76808F"}}},indicator:{tooltip:{title:{color:"#76808F"},legend:{color:"#76808F"}}},xAxis:{axisLine:{color:"#DDDDDD"},tickText:{color:"#76808F"},tickLine:{color:"#DDDDDD"}},yAxis:{axisLine:{color:"#DDDDDD"},tickText:{color:"#76808F"},tickLine:{color:"#DDDDDD"}},separator:{color:"#DDDDDD"},crosshair:{horizontal:{line:{color:"#76808F"},text:{borderColor:"#686D76",backgroundColor:"#686D76"}},vertical:{line:{color:"#76808F"},text:{borderColor:"#686D76",backgroundColor:"#686D76"}}}},tn=Xs;var Us={grid:{horizontal:{color:"#292929"},vertical:{color:"#292929"}},candle:{priceMark:{high:{color:"#C9D1D9"},low:{color:"#C9D1D9"}},tooltip:{rect:{color:"rgba(10, 10, 10, .6)",borderColor:"rgba(10, 10, 10, .6)"},title:{color:"#929AA5"},legend:{color:"#929AA5"}}},indicator:{tooltip:{title:{color:"#929AA5"},legend:{color:"#929AA5"}}},xAxis:{axisLine:{color:"#333333"},tickText:{color:"#929AA5"},tickLine:{color:"#333333"}},yAxis:{axisLine:{color:"#333333"},tickText:{color:"#929AA5"},tickLine:{color:"#333333"}},separator:{color:"#333333"},crosshair:{horizontal:{line:{color:"#929AA5"},text:{borderColor:"#373a40",backgroundColor:"#373a40"}},vertical:{line:{color:"#929AA5"},text:{borderColor:"#373a40",backgroundColor:"#373a40"}}}},rn=Us;var Gs={light:tn,dark:rn};function on(n){return Gs[n]??null}var nn={MIN:1,MAX:50},$s=10,js=80,qs=.2,Ar=10,wt=class n{_chart;_styles=en();_formatter={formatDate:({dateTimeFormat:e,timestamp:t,template:r})=>mr(e,t,r),formatBigNumber:pr,formatExtendText:e=>""};_innerFormatter={formatDate:(e,t,r)=>this._formatter.formatDate({dateTimeFormat:this._dateTimeFormat,timestamp:e,template:t,type:r}),formatBigNumber:e=>this._formatter.formatBigNumber(e),formatExtendText:e=>this._formatter.formatExtendText(e)};_locale="en-US";_thousandsSeparator={sign:",",format:e=>gr(e,this._thousandsSeparator.sign)};_decimalFold={threshold:3,format:e=>fr(e,this._decimalFold.threshold)};_symbol=null;_period=null;_dataList=[];_dataLoader=null;_loading=false;_dataLoadMore={forward:false,backward:false};_dateTimeFormat;_zoomEnabled=true;_zoomAnchor={main:"cursor",xAxis:"cursor"};_scrollEnabled=true;_totalBarSpace=0;_barSpace=$s;_gapBarSpace;_offsetRightDistance=js;_lastBarRightSideDiffBarCount;_startLastBarRightSideDiffBarCount=0;_scrollLimitRole="bar_count";_minVisibleBarCount={left:2,right:2};_maxOffsetDistance={left:50,right:50};_visibleRange=ei();_visibleRangeDataList=[];_visibleRangeHighLowPrice=[{x:0,price:Number.MIN_SAFE_INTEGER},{x:0,price:Number.MAX_SAFE_INTEGER}];_crosshair={};_actions=new Map;_indicators=new Map;_taskScheduler;_pendingCalcMap=new Map;_calcMicrotaskScheduled=false;static _IDLE_CALC_THRESHOLD=2e3;_fullLayoutNeeded=false;_didInitialForcedLayout=false;_overlays=new Map;_progressOverlayInfo=null;_lastPriceMarkExtendTextUpdateTimers=[];_pressedOverlayInfo={paneId:"",overlay:null,figureType:"none",figureIndex:-1,figure:null};_hoverOverlayInfo={paneId:"",overlay:null,figureType:"none",figureIndex:-1,figure:null};_clickOverlayInfo={paneId:"",overlay:null,figureType:"none",figureIndex:-1,figure:null};constructor(e,t){this._chart=e,this._calcOptimalBarSpace(),this._lastBarRightSideDiffBarCount=this._offsetRightDistance/this._barSpace;let{styles:r,locale:i,timezone:o,formatter:a,thousandsSeparator:s,decimalFold:l,zoomAnchor:c}=t??{};_(r)&&this.setStyles(r),L(i)&&this.setLocale(i),this.setTimezone(o??""),_(a)&&this.setFormatter(a),_(s)&&this.setThousandsSeparator(s),_(l)&&this.setDecimalFold(l),_(c)&&this.setZoomAnchor(c),this._taskScheduler=new At(()=>{if(!this._didInitialForcedLayout&&this._dataList.length>0){this._didInitialForcedLayout=true,this._chart.layout({measureHeight:true,measureWidth:true,update:true,buildYAxisTick:true,forceBuildYAxisTick:true});return}let u=this._fullLayoutNeeded;this._fullLayoutNeeded=false,u?this._chart.layout({measureHeight:true,measureWidth:true,update:true,buildYAxisTick:true,forceBuildYAxisTick:true}):this._chart.layout({buildYAxisTick:true,cacheYAxisWidth:true,update:true});});}setStyles(e){let t=null;if(L(e)?t=on(e):t=e,U(this._styles,t),ne(t?.candle?.tooltip?.legend?.template)&&(this._styles.candle.tooltip.legend.template=t.candle.tooltip.legend.template),_(t?.candle?.priceMark?.last?.extendTexts)){this._clearLastPriceMarkExtendTextUpdateTimer();let r=[];this._styles.candle.priceMark.last.extendTexts.forEach(i=>{let o=i.updateInterval;if(i.show&&o>0&&!r.includes(o)){r.push(o);let a=setInterval(()=>{this._chart.updatePane(0,B.CANDLE);},o);this._lastPriceMarkExtendTextUpdateTimers.push(a);}});}}getStyles(){return this._styles}setFormatter(e){U(this._formatter,e);}getFormatter(){return this._formatter}getInnerFormatter(){return this._innerFormatter}setLocale(e){this._locale=e;}getLocale(){return this._locale}setTimezone(e){if(!_(this._dateTimeFormat)||this.getTimezone()!==e){let t={hour12:false,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"};e.length>0&&(t.timeZone=e);let r=null;try{r=new Intl.DateTimeFormat("en",t);}catch{me("","","Timezone is error!!!");}r!==null&&(this._dateTimeFormat=r);}}getTimezone(){return this._dateTimeFormat.resolvedOptions().timeZone}getDateTimeFormat(){return this._dateTimeFormat}setThousandsSeparator(e){U(this._thousandsSeparator,e);}getThousandsSeparator(){return this._thousandsSeparator}setDecimalFold(e){U(this._decimalFold,e);}getDecimalFold(){return this._decimalFold}setSymbol(e){this.resetData(()=>{this._symbol={pricePrecision:q.PRICE,volumePrecision:q.VOLUME,...this._symbol,...e},this._synchronizeIndicatorSeriesPrecision();});}getSymbol(){return this._symbol}setPeriod(e){this.resetData(()=>{this._period=e;});}getPeriod(){return this._period}getDataList(){return this._dataList}getVisibleRangeDataList(){return this._visibleRangeDataList}getVisibleRangeHighLowPrice(){return this._visibleRangeHighLowPrice}_addData(e,t,r){let i=false,o=false,a=0;if(ne(e)){let s={backward:false,forward:false};switch(Pe(r)?(s.backward=r,s.forward=r):(s.backward=r?.backward??false,s.forward=r?.forward??false),a=e.length,t){case "init":{this._clearData(),this._dataList=e,this._dataLoadMore.backward=s.backward,this._dataLoadMore.forward=s.forward,this.setOffsetRightDistance(this._offsetRightDistance),o=true;break}case "backward":{this._dataList=this._dataList.concat(e),this._dataLoadMore.backward=s.backward,this._lastBarRightSideDiffBarCount-=a,o=a>0;break}case "forward":{this._dataList=e.concat(this._dataList),this._dataLoadMore.forward=s.forward,o=a>0;break}}i=true;}else {let s=this._dataList.length,l=()=>({timestamp:e.timestamp,open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume,turnover:e.turnover}),c=e.timestamp,u=K(this._dataList[s-1],"timestamp",0);if(c>u){this._dataList.push(l());let h=this.getLastBarRightSideDiffBarCount();h<0&&this.setLastBarRightSideDiffBarCount(--h),a=1,i=true,o=true;}else if(c===u){let h=this._dataList[s-1];_(h)?(h.open=e.open,h.high=e.high,h.low=e.low,h.close=e.close,h.volume=e.volume,h.turnover=e.turnover):this._dataList[s-1]=l(),i=true,o=true;}}if(i&&o){let s=t==="update"&&a===0;this._adjustVisibleRange(),this.setCrosshair(this._crosshair,{notInvalidate:true});let l=this.getIndicatorsByFilter({});l.length>0?(s||(this._fullLayoutNeeded=true),this._calcIndicator(l,s?"tail":"full")):s?this._chart.layout({buildYAxisTick:true,cacheYAxisWidth:true,update:true}):this._chart.layout({measureWidth:true,update:true,buildYAxisTick:true,cacheYAxisWidth:t!=="init"});}}setDataLoader(e){this.resetData(()=>{this._dataLoader=e;});}_calcOptimalBarSpace(){let t=1-qs*Math.atan(Math.max(4,this._barSpace)-4)/(Math.PI*.5),r=Math.min(Math.floor(this._barSpace*t),Math.floor(this._barSpace));r%2===0&&r+2>=this._barSpace&&--r,this._gapBarSpace=Math.max(1,r);}_adjustVisibleRange(){let e=this._dataList.length,t=this._totalBarSpace/this._barSpace,r=0,i=0;this._scrollLimitRole==="distance"?(r=(this._totalBarSpace-this._maxOffsetDistance.right)/this._barSpace,i=(this._totalBarSpace-this._maxOffsetDistance.left)/this._barSpace):(r=this._minVisibleBarCount.left,i=this._minVisibleBarCount.right),r=Math.max(0,r),i=Math.max(0,i);let o=t-Math.min(r,e);this._lastBarRightSideDiffBarCount>o&&(this._lastBarRightSideDiffBarCount=o);let a=-e+Math.min(i,e);this._lastBarRightSideDiffBarCount<a&&(this._lastBarRightSideDiffBarCount=a);let s=Math.round(this._lastBarRightSideDiffBarCount+e+.5),l=s;s>e&&(s=e);let c=Math.round(s-t)-1;c<0&&(c=0);let u=this._lastBarRightSideDiffBarCount>0?Math.round(e+this._lastBarRightSideDiffBarCount-t)-1:c;this._visibleRange={from:c,to:s,realFrom:u,realTo:l},this.executeAction("onVisibleRangeChange",this._visibleRange),this._visibleRangeDataList=[],this._visibleRangeHighLowPrice=[{x:0,price:Number.MIN_SAFE_INTEGER},{x:0,price:Number.MAX_SAFE_INTEGER}];for(let h=u;h<l;h++){let d=this._dataList[h],m=this.dataIndexToCoordinate(h);this._visibleRangeDataList.push({dataIndex:h,x:m,data:{prev:this._dataList[h-1]??d,current:d,next:this._dataList[h+1]??d}}),_(d)&&(this._visibleRangeHighLowPrice[0].price<d.high&&(this._visibleRangeHighLowPrice[0].price=d.high,this._visibleRangeHighLowPrice[0].x=m),this._visibleRangeHighLowPrice[1].price>d.low&&(this._visibleRangeHighLowPrice[1].price=d.low,this._visibleRangeHighLowPrice[1].x=m));}c===0?this._dataLoadMore.forward&&this._processDataLoad("forward"):s===e&&this._dataLoadMore.backward&&this._processDataLoad("backward");}_processDataLoad(e){if(!this._loading&&_(this._dataLoader)&&_(this._symbol)&&_(this._period)){this._loading=true;let t={type:e,symbol:this._symbol,period:this._period,timestamp:null,callback:(r,i)=>{this._loading=false,this._addData(r,e,i),e==="init"&&this._dataLoader?.subscribeBar?.({symbol:this._symbol,period:this._period,callback:o=>{this._addData(o,"update");}});}};switch(e){case "backward":{t.timestamp=this._dataList[this._dataList.length-1]?.timestamp??null;break}case "forward":{t.timestamp=this._dataList[0]?.timestamp??null;break}}this._dataLoader.getBars(t);}}_processDataUnsubscribe(){_(this._dataLoader)&&_(this._symbol)&&_(this._period)&&this._dataLoader.unsubscribeBar?.({symbol:this._symbol,period:this._period});}resetData(e){this._processDataUnsubscribe(),e?.(),this._loading=false,this._processDataLoad("init");}getBarSpace(){return {bar:this._barSpace,halfBar:this._barSpace/2,gapBar:this._gapBarSpace,halfGapBar:Math.floor(this._gapBarSpace/2)}}setBarSpace(e,t){e<nn.MIN||e>nn.MAX||this._barSpace===e||(this._barSpace=e,this._calcOptimalBarSpace(),t?.(),this._adjustVisibleRange(),this.setCrosshair(this._crosshair,{notInvalidate:true}),this._chart.layout({measureWidth:true,update:true,buildYAxisTick:true,cacheYAxisWidth:true}));}setTotalBarSpace(e){this._totalBarSpace!==e&&(this._totalBarSpace=e,this._adjustVisibleRange(),this.setCrosshair(this._crosshair,{notInvalidate:true}));}setOffsetRightDistance(e,t){return this._offsetRightDistance=this._scrollLimitRole==="distance"?Math.min(this._maxOffsetDistance.right,e):e,this._lastBarRightSideDiffBarCount=this._offsetRightDistance/this._barSpace,(t??false)&&(this._adjustVisibleRange(),this.setCrosshair(this._crosshair,{notInvalidate:true}),this._chart.layout({measureWidth:true,update:true,buildYAxisTick:true,cacheYAxisWidth:true})),this}getInitialOffsetRightDistance(){return this._offsetRightDistance}getOffsetRightDistance(){return Math.max(0,this._lastBarRightSideDiffBarCount*this._barSpace)}getLastBarRightSideDiffBarCount(){return this._lastBarRightSideDiffBarCount}setLastBarRightSideDiffBarCount(e){this._lastBarRightSideDiffBarCount=e;}setMaxOffsetLeftDistance(e){this._scrollLimitRole="distance",this._maxOffsetDistance.left=e;}setMaxOffsetRightDistance(e){this._scrollLimitRole="distance",this._maxOffsetDistance.right=e;}setLeftMinVisibleBarCount(e){this._scrollLimitRole="bar_count",this._minVisibleBarCount.left=e;}setRightMinVisibleBarCount(e){this._scrollLimitRole="bar_count",this._minVisibleBarCount.right=e;}getVisibleRange(){return this._visibleRange}startScroll(){this._startLastBarRightSideDiffBarCount=this._lastBarRightSideDiffBarCount;}scroll(e){if(!this._scrollEnabled)return;let t=e/this._barSpace,r=this._lastBarRightSideDiffBarCount*this._barSpace;this._lastBarRightSideDiffBarCount=this._startLastBarRightSideDiffBarCount-t,this._adjustVisibleRange(),this.setCrosshair(this._crosshair,{notInvalidate:true}),this._chart.layout({measureWidth:true,update:true,buildYAxisTick:true,cacheYAxisWidth:true});let i=Math.round(r-this._lastBarRightSideDiffBarCount*this._barSpace);i!==0&&this.executeAction("onScroll",{distance:i});}getDataByDataIndex(e){return this._dataList[e]??null}coordinateToFloatIndex(e){let t=this._dataList.length,r=(this._totalBarSpace-e)/this._barSpace,i=t+this._lastBarRightSideDiffBarCount-r;return Math.round(i*1e6)/1e6}dataIndexToTimestamp(e){let t=this._dataList.length;if(t===0)return null;let r=this.getDataByDataIndex(e);if(_(r))return r.timestamp;if(_(this._period)){let i=t-1,o=null,a=0;if(e>i?(o=this._dataList[i].timestamp,a=e-i):e<0&&(o=this._dataList[0].timestamp,a=e),w(o)){let{timespan:s,multiplier:l}=this._period;switch(s){case "second":return o+l*1e3*a;case "minute":return o+l*60*1e3*a;case "hour":return o+l*60*60*1e3*a;case "day":return o+l*24*60*60*1e3*a;case "week":return o+l*7*24*60*60*1e3*a;case "month":{let c=new Date(o),u=c.getDate();c.setDate(1),c.setMonth(c.getMonth()+l*a);let h=new Date(c.getFullYear(),c.getMonth()+1,0).getDate();return c.setDate(Math.min(u,h)),c.getTime()}case "year":{let c=new Date(o);return c.setFullYear(c.getFullYear()+l*a),c.getTime()}}}}return null}timestampToDataIndex(e){let t=this._dataList.length;if(t===0)return 0;if(_(this._period)){let r=null,i=0,o=t-1,a=this._dataList[o].timestamp;e>a&&(r=a,i=o);let s=this._dataList[0].timestamp;if(e<s&&(r=s,i=0),w(r)){let{timespan:l,multiplier:c}=this._period;switch(l){case "second":return i+Math.floor((e-r)/(c*1e3));case "minute":return i+Math.floor((e-r)/(c*60*1e3));case "hour":return i+Math.floor((e-r)/(c*60*60*1e3));case "day":return i+Math.floor((e-r)/(c*24*60*60*1e3));case "week":return i+Math.floor((e-r)/(c*7*24*60*60*1e3));case "month":{let u=new Date(r),h=new Date(e),d=u.getFullYear(),m=h.getFullYear(),p=u.getMonth(),g=h.getMonth();return i+Math.floor(((m-d)*12+(g-p))/c)}case "year":{let u=new Date(r).getFullYear(),h=new Date(e).getFullYear();return i+Math.floor((h-u)/c)}}}}return xt(this._dataList,"timestamp",e)}dataIndexToCoordinate(e){let r=this._dataList.length+this._lastBarRightSideDiffBarCount-e;return Math.floor(this._totalBarSpace-(r-.5)*this._barSpace+.5)}coordinateToDataIndex(e){return Math.ceil(this.coordinateToFloatIndex(e))-1}zoom(e,t,r){if(!this._zoomEnabled)return;let i=t??{x:this._crosshair.x??this._totalBarSpace/2};r==="xAxis"?this._zoomAnchor.xAxis==="last_bar"&&(i.x=this.dataIndexToCoordinate(this._dataList.length-1)):this._zoomAnchor.main==="last_bar"&&(i.x=this.dataIndexToCoordinate(this._dataList.length-1));let o=i.x,a=this.coordinateToFloatIndex(o),s=this._barSpace,l=this._barSpace+e*(this._barSpace/Ar);this.setBarSpace(l,()=>{this._lastBarRightSideDiffBarCount+=a-this.coordinateToFloatIndex(o);});let c=this._barSpace/s;c!==1&&this.executeAction("onZoom",{scale:c});}setZoomEnabled(e){this._zoomEnabled=e;}isZoomEnabled(){return this._zoomEnabled}setZoomAnchor(e){L(e)?(this._zoomAnchor.main=e,this._zoomAnchor.xAxis=e):(L(e.main)&&(this._zoomAnchor.main=e.main),L(e.xAxis)&&(this._zoomAnchor.xAxis=e.xAxis));}getZoomAnchor(){return {...this._zoomAnchor}}setScrollEnabled(e){this._scrollEnabled=e;}isScrollEnabled(){return this._scrollEnabled}setCrosshair(e,t){let{notInvalidate:r,notExecuteAction:i,forceInvalidate:o}=t??{},a=e??{},s=0,l=0;w(a.x)?(s=this.coordinateToDataIndex(a.x),s<0?l=0:s>this._dataList.length-1?l=this._dataList.length-1:l=s):(s=this._dataList.length-1,l=s);let c=this._dataList[l],u=this.dataIndexToCoordinate(s),h={x:this._crosshair.x,y:this._crosshair.y,paneId:this._crosshair.paneId};this._crosshair={...a,realX:u,candleData:c,realDataIndex:s,dataIndex:l,timestamp:this.dataIndexToTimestamp(s)??void 0},(h.x!==a.x||h.y!==a.y||h.paneId!==a.paneId||(o??false))&&(_(c)&&!(i??false)&&this.hasAction("onCrosshairChange")&&L(this._crosshair.paneId)&&this.executeAction("onCrosshairChange",e),(r??false)||this._chart.updatePane(1));}getCrosshair(){return this._crosshair}executeAction(e,t){this._actions.get(e)?.execute(t);}subscribeAction(e,t){this._actions.has(e)||this._actions.set(e,new Pt),this._actions.get(e)?.subscribe(t);}unsubscribeAction(e,t){let r=this._actions.get(e);_(r)&&(r.unsubscribe(t),r.isEmpty()&&this._actions.delete(e));}hasAction(e){let t=this._actions.get(e);return _(t)&&!t.isEmpty()}_sortIndicators(e){L(e)?this._indicators.get(e)?.sort((t,r)=>t.zLevel-r.zLevel):this._indicators.forEach(t=>{t.sort((r,i)=>r.zLevel-i.zLevel);});}_calcIndicator(e,t="full"){let r=[].concat(e);r.length!==0&&(r.forEach(i=>{(this._pendingCalcMap.get(i.id)===void 0||t==="full")&&this._pendingCalcMap.set(i.id,{ind:i,mode:t});}),!this._calcMicrotaskScheduled&&(this._calcMicrotaskScheduled=true,queueMicrotask(()=>{if(this._calcMicrotaskScheduled=false,this._pendingCalcMap.size===0)return;let i={};this._pendingCalcMap.forEach((s,l)=>{i[l]=s.ind.calcImp(this._dataList,s.mode);}),this._pendingCalcMap.clear();let o=globalThis.scheduler,a=()=>{this._taskScheduler.add(i);};o!==void 0?o.postTask(a,{priority:"background"}):this._dataList.length>=n._IDLE_CALC_THRESHOLD&&typeof requestIdleCallback=="function"?requestIdleCallback(a):this._dataList.length>=n._IDLE_CALC_THRESHOLD?setTimeout(a,0):a();})));}addIndicator(e,t,r){let{name:i}=e;if(this.getIndicatorsByFilter(e).length>0)return false;let a=this.getIndicatorsByPaneId(t),s=_r(i),l=new s;return this._synchronizeIndicatorSeriesPrecision(l),l.paneId=t,l.override(e),r||(this.removeIndicator({paneId:t}),a=[]),a.push(l),this._indicators.set(t,a),this._sortIndicators(t),this._calcIndicator(l),true}getIndicatorsByPaneId(e){return this._indicators.get(e)??[]}getIndicatorsByFilter(e){let{paneId:t,name:r,id:i}=e,o=s=>_(i)?s.id===i:!_(r)||s.name===r,a=[];return _(t)?a=a.concat(this.getIndicatorsByPaneId(t).filter(o)):this._indicators.forEach(s=>{a=a.concat(s.filter(o));}),a}removeIndicator(e){let t=false;return this.getIndicatorsByFilter(e).forEach(i=>{let o=this.getIndicatorsByPaneId(i.paneId),a=o.findIndex(s=>s.id===i.id);a>-1&&(o.splice(a,1),t=true),o.length===0&&this._indicators.delete(i.paneId);}),t}hasIndicators(e){return this._indicators.has(e)}_synchronizeIndicatorSeriesPrecision(e){if(_(this._symbol)){let{pricePrecision:t=q.PRICE,volumePrecision:r=q.VOLUME}=this._symbol,i=o=>{switch(o.series){case "price":{o.setSeriesPrecision(t);break}case "volume":{o.setSeriesPrecision(r);break}}};_(e)?i(e):this._indicators.forEach(o=>{o.forEach(a=>{i(a);});});}}overrideIndicator(e){let t=false,r=false;return this.getIndicatorsByFilter(e).forEach(o=>{o.override(e);let{calc:a,draw:s,sort:l}=o.shouldUpdateImp();l&&(r=true),a?this._calcIndicator(o):s&&(t=true);}),r&&this._sortIndicators(),t?(this._chart.layout({update:true}),true):false}getOverlaysByFilter(e){let{id:t,groupId:r,paneId:i,name:o}=e,a=c=>_(t)?c.id===t:_(r)?c.groupId===r&&(!_(o)||c.name===o):!_(o)||c.name===o,s=[];_(i)?s=s.concat(this.getOverlaysByPaneId(i).filter(a)):this._overlays.forEach(c=>{s=s.concat(c.filter(a));});let l=this._progressOverlayInfo?.overlay;return _(l)&&a(l)&&s.push(l),s}getOverlaysByPaneId(e){if(!L(e)){let t=[];return this._overlays.forEach(r=>{t=t.concat(r);}),t}return this._overlays.get(e)??[]}_sortOverlays(e){L(e)?this._overlays.get(e)?.sort((t,r)=>t.zLevel-r.zLevel):this._overlays.forEach(t=>{t.sort((r,i)=>r.zLevel-i.zLevel);});}addOverlays(e,t){let r=[],i=e.map((o,a)=>{if(_(o.id)){let l=null;for(let c of this._overlays){let h=c[1].find(d=>d.id===o.id);if(_(h)){l=h;break}}if(_(l))return o.id}let s=Vo(o.name);if(_(s)){let l=o.id??mt(Co),c=new s,u=o.paneId??B.CANDLE;o.id=l,o.groupId??=l;let h=this.getOverlaysByPaneId(u).length;return o.zLevel??=h,c.override(o),r.includes(u)||r.push(u),c.isDrawing()?this._progressOverlayInfo={paneId:u,overlay:c,appointPaneFlag:t[a]}:(this._overlays.has(u)||this._overlays.set(u,[]),this._overlays.get(u)?.push(c)),c.isStart()&&c.onDrawStart?.({overlay:c,chart:this._chart}),l}return null});return r.length>0&&(this._sortOverlays(),r.forEach(o=>{this._chart.updatePane(1,o);}),this._chart.updatePane(1,B.X_AXIS)),i}getProgressOverlayInfo(){return this._progressOverlayInfo}progressOverlayComplete(){if(this._progressOverlayInfo!==null){let{overlay:e,paneId:t}=this._progressOverlayInfo;e.isDrawing()||(this._overlays.has(t)||this._overlays.set(t,[]),this._overlays.get(t)?.push(e),this._sortOverlays(t),this._progressOverlayInfo=null);}}updateProgressOverlayInfo(e,t){this._progressOverlayInfo!==null&&(Pe(t)&&t&&(this._progressOverlayInfo.appointPaneFlag=t),this._progressOverlayInfo.paneId=e,this._progressOverlayInfo.overlay.override({paneId:e}));}overrideOverlay(e){let t=false,r=[];return this.getOverlaysByFilter(e).forEach(o=>{o.override(e);let{sort:a,draw:s}=o.shouldUpdate();a&&(t=true),(a||s)&&(r.includes(o.paneId)||r.push(o.paneId));}),t&&this._sortOverlays(),r.length>0?(r.forEach(o=>{this._chart.updatePane(1,o);}),this._chart.updatePane(1,B.X_AXIS),true):false}removeOverlay(e){let t=[];return this.getOverlaysByFilter(e).forEach(i=>{let o=i.paneId,a=this.getOverlaysByPaneId(i.paneId);if(i.onRemoved?.({overlay:i,chart:this._chart}),t.includes(o)||t.push(o),i.isDrawing())this._progressOverlayInfo=null;else {let s=a.findIndex(l=>l.id===i.id);s>-1&&a.splice(s,1);}a.length===0&&this._overlays.delete(o);}),t.length>0?(t.forEach(i=>{this._chart.updatePane(1,i);}),this._chart.updatePane(1,B.X_AXIS),true):false}setPressedOverlayInfo(e){this._pressedOverlayInfo=e;}getPressedOverlayInfo(){return this._pressedOverlayInfo}setHoverOverlayInfo(e,t,r){let{overlay:i,figureType:o,figureIndex:a,figure:s}=this._hoverOverlayInfo,l=e.overlay;if((i?.id!==l?.id||o!==e.figureType||a!==e.figureIndex)&&(this._hoverOverlayInfo=e,i?.id!==l?.id)){let c=false,u=false;i!==null&&(i.override({zLevel:i.getPrevZLevel()}),u=true,r(i,s)&&(c=true)),l!==null&&(l.setPrevZLevel(l.zLevel),l.override({zLevel:Number.MAX_SAFE_INTEGER}),u=true,t(l,e.figure)&&(c=true)),u&&this._sortOverlays(),c||this._chart.updatePane(1);}}getHoverOverlayInfo(){return this._hoverOverlayInfo}setClickOverlayInfo(e,t,r){let{paneId:i,overlay:o,figureType:a,figure:s,figureIndex:l}=this._clickOverlayInfo,c=e.overlay;(o?.id!==c?.id||a!==e.figureType||l!==e.figureIndex)&&(this._clickOverlayInfo=e,o?.id!==c?.id&&(_(o)&&r(o,s),_(c)&&t(c,e.figure),this._chart.updatePane(1,e.paneId),i!==e.paneId&&this._chart.updatePane(1,i),this._chart.updatePane(1,B.X_AXIS)));}getClickOverlayInfo(){return this._clickOverlayInfo}isOverlayEmpty(){return this._overlays.size===0&&this._progressOverlayInfo===null}isOverlayDrawing(){return this._progressOverlayInfo?.overlay.isDrawing()??false}_clearLastPriceMarkExtendTextUpdateTimer(){this._lastPriceMarkExtendTextUpdateTimers.forEach(e=>{clearInterval(e);}),this._lastPriceMarkExtendTextUpdateTimers=[];}_clearData(){this._dataLoadMore.backward=false,this._dataLoadMore.forward=false,this._loading=false,this._dataList=[],this._visibleRangeDataList=[],this._visibleRangeHighLowPrice=[{x:0,price:Number.MIN_SAFE_INTEGER},{x:0,price:Number.MAX_SAFE_INTEGER}],this._visibleRange=ei(),this._crosshair={};}getChart(){return this._chart}destroy(){this._clearData(),this._clearLastPriceMarkExtendTextUpdateTimer(),this._taskScheduler.clear(),this._overlays.clear(),this._indicators.clear(),this._actions.clear();}};var N={MAIN:"main",X_AXIS:"xAxis",Y_AXIS:"yAxis",SEPARATOR:"separator"},ze=7;async function Zs(){return await new Promise(n=>{let e=new ResizeObserver(t=>{n(t.every(r=>"devicePixelContentBoxSize"in r)),e.disconnect();});e.observe(document.body,{box:"device-pixel-content-box"});}).catch(()=>false)}var pt=class{_element;_resizeObserver;_mediaQueryList;_ctx;_listener;_supportedDevicePixelContentBox=false;_width=0;_height=0;_pixelWidth=0;_pixelHeight=0;_nextPixelWidth=0;_nextPixelHeight=0;_requestAnimationId=Cr;_mediaQueryListener=()=>{let e=z(this._element);this._nextPixelWidth=Math.round(this._element.clientWidth*e),this._nextPixelHeight=Math.round(this._element.clientHeight*e),this._resetPixelRatio();};constructor(e,t){this._listener=t,this._element=oe("canvas",e),this._ctx=this._element.getContext("2d"),Zs().then(r=>{this._supportedDevicePixelContentBox=r,r?(this._resizeObserver=new ResizeObserver(i=>{let a=i.find(s=>s.target===this._element)?.devicePixelContentBoxSize[0];_(a)&&(this._nextPixelWidth=a.inlineSize,this._nextPixelHeight=a.blockSize,(this._pixelWidth!==this._nextPixelWidth||this._pixelHeight!==this._nextPixelHeight)&&this._resetPixelRatio());}),this._resizeObserver.observe(this._element,{box:"device-pixel-content-box"})):(this._mediaQueryList=window.matchMedia(`(resolution: ${z(this._element)}dppx)`),this._mediaQueryList.addListener(this._mediaQueryListener));}).catch(r=>false);}_resetPixelRatio(){this._executeListener(()=>{let e=this._element.clientWidth,t=this._element.clientHeight;this._width=e,this._height=t,this._pixelWidth=this._nextPixelWidth,this._pixelHeight=this._nextPixelHeight,this._element.width=this._nextPixelWidth,this._element.height=this._nextPixelHeight;let r=this._nextPixelWidth/e,i=this._nextPixelHeight/t;this._ctx.scale(r,i);});}_executeListener(e){this._requestAnimationId===Cr&&(this._requestAnimationId=Ce(()=>{this._ctx.clearRect(0,0,this._width,this._height),e?.(),this._listener(),this._requestAnimationId=Cr;}));}update(e,t){if(this._width!==e||this._height!==t){if(this._element.style.width=`${e}px`,this._element.style.height=`${t}px`,!this._supportedDevicePixelContentBox){let r=z(this._element);this._nextPixelWidth=Math.round(e*r),this._nextPixelHeight=Math.round(t*r),this._resetPixelRatio();}}else this._executeListener();}getElement(){return this._element}getContext(){return this._ctx}destroy(){_(this._resizeObserver)&&this._resizeObserver.unobserve(this._element),_(this._mediaQueryList)&&this._mediaQueryList.removeListener(this._mediaQueryListener);}};var pe=class{_gl;_element;constructor(e){this._element=document.createElement("canvas"),e.appendChild(this._element);let t=this._element.getContext("webgl2",{antialias:false,premultipliedAlpha:false,preserveDrawingBuffer:false,powerPreference:"high-performance"});if(t===null)throw this._element.remove(),new Error("[astroneum] WebGL2 not supported \u2014 falling back to Canvas2D");this._gl=t;}get gl(){return this._gl}get element(){return this._element}resize(e,t,r){this._element.width=Math.round(e*r),this._element.height=Math.round(t*r),this._element.style.width=`${e}px`,this._element.style.height=`${t}px`,this._gl.viewport(0,0,this._element.width,this._element.height);}destroy(){this._gl.getExtension("WEBGL_lose_context")?.loseContext(),this._element.remove();}static isSupported(){return Qs}},Qs=(()=>{try{let e=document.createElement("canvas").getContext("webgl2");return e===null?!1:(e.getExtension("WEBGL_lose_context")?.loseContext(),!0)}catch{return false}})();var Ks="0123456789.,+-eEkKMBT%$ /()[]ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz:\u20AC\xA5\xA3\xA2";function Js(){return Math.max(Math.ceil(typeof window<"u"?window.devicePixelRatio??2:2),2)}var Pr=class{fontSize;fontFamily;_texture=null;_glyphs=new Map;constructor(e,t){this.fontSize=e,this.fontFamily=t;}build(e){if(this._texture!==null)return;let t=Js(),r=Array.from(new Set(Ks)),i=this.fontSize*t,o=document.createElement("canvas"),a=o.getContext("2d");a.font=`${i}px ${this.fontFamily}`;let s=Math.ceil(i*1.5),l=r.map(f=>a.measureText(f).width),c=0;for(let f=0;f<l.length;f++)l[f]>c&&(c=l[f]);let u=Math.ceil(c+i*.2),h=Math.ceil(Math.sqrt(r.length)),d=Math.ceil(r.length/h),m=h*u,p=d*s;o.width=m,o.height=p,a.font=`${i}px ${this.fontFamily}`,a.textBaseline="top",a.fillStyle="white",r.forEach((f,v)=>{let y=v%h,b=Math.floor(v/h),S=y*u,x=b*s;a.fillText(f,S,x),this._glyphs.set(f,{u0:S/m,v0:x/p,u1:(S+u)/m,v1:(x+s)/p,advance:l[v]/t,cellW:u/t,cellH:s/t});});let g=a.getImageData(0,0,m,p);this._texture=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this._texture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,m,p,0,e.RGBA,e.UNSIGNED_BYTE,g.data),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null);}getGlyph(e){return this._glyphs.get(e)??null}get texture(){return this._texture}destroy(e){this._texture!==null&&(e.deleteTexture(this._texture),this._texture=null);}};var el=`#version 300 es
|
|
3
|
+
in vec2 a_corner;
|
|
4
|
+
in vec4 a_rect;
|
|
5
|
+
in vec4 a_uv;
|
|
6
|
+
in vec4 a_color;
|
|
7
|
+
uniform vec2 u_res;
|
|
8
|
+
out vec2 v_uv;
|
|
9
|
+
out vec4 v_color;
|
|
10
|
+
void main() {
|
|
11
|
+
float px = a_rect.x + a_corner.x * a_rect.z;
|
|
12
|
+
float py = a_rect.y + a_corner.y * a_rect.w;
|
|
13
|
+
v_uv = vec2(a_uv.x + a_corner.x * (a_uv.z - a_uv.x),
|
|
14
|
+
a_uv.y + a_corner.y * (a_uv.w - a_uv.y));
|
|
15
|
+
v_color = a_color;
|
|
16
|
+
gl_Position = vec4(px / u_res.x * 2.0 - 1.0,
|
|
17
|
+
1.0 - py / u_res.y * 2.0, 0.0, 1.0);
|
|
18
|
+
}`,tl=`#version 300 es
|
|
19
|
+
precision mediump float;
|
|
20
|
+
uniform sampler2D u_atlas;
|
|
21
|
+
in vec2 v_uv;
|
|
22
|
+
in vec4 v_color;
|
|
23
|
+
out vec4 fragColor;
|
|
24
|
+
void main() {
|
|
25
|
+
float a = texture(u_atlas, v_uv).a;
|
|
26
|
+
fragColor = vec4(v_color.rgb, v_color.a * a);
|
|
27
|
+
}`;function rl(n){let e=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(n);return e!==null?[parseInt(e[1],16)/255,parseInt(e[2],16)/255,parseInt(e[3],16)/255,e[4]!==void 0?parseInt(e[4],16)/255:1]:(e=/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)/.exec(n),e!==null?[parseFloat(e[1])/255,parseFloat(e[2])/255,parseFloat(e[3])/255,e[4]!==void 0?parseFloat(e[4]):1]:[1,1,1,1])}var wr=12,an=8192,Et=class{_canvas;_gl;_program;_vao;_cornerVbo;_instanceVbo;_uRes;_uAtlas;_aCorner;_aRect;_aUv;_aColor;_mainItems=[];_overlayItems=[];_phase="main";_cssW=0;_cssH=0;_pixelRatio=1;_buf=new Float32Array(an*wr);_atlases=new Map;constructor(e){this._canvas=document.createElement("canvas"),this._canvas.style.cssText="position:absolute;top:0;left:0;pointer-events:none;z-index:3;box-sizing:border-box;",e.appendChild(this._canvas);let t=this._canvas.getContext("webgl2",{antialias:false,premultipliedAlpha:false,preserveDrawingBuffer:false,powerPreference:"high-performance"});this._gl=t,this._program=this._compileProgram(),this._uRes=t.getUniformLocation(this._program,"u_res"),this._uAtlas=t.getUniformLocation(this._program,"u_atlas"),this._aCorner=t.getAttribLocation(this._program,"a_corner"),this._aRect=t.getAttribLocation(this._program,"a_rect"),this._aUv=t.getAttribLocation(this._program,"a_uv"),this._aColor=t.getAttribLocation(this._program,"a_color"),this._vao=t.createVertexArray(),t.bindVertexArray(this._vao),this._cornerVbo=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._cornerVbo),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(this._aCorner),t.vertexAttribPointer(this._aCorner,2,t.FLOAT,false,0,0),this._instanceVbo=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._instanceVbo),t.bufferData(t.ARRAY_BUFFER,this._buf,t.DYNAMIC_DRAW);let r=wr*4;t.enableVertexAttribArray(this._aRect),t.vertexAttribPointer(this._aRect,4,t.FLOAT,false,r,0),t.vertexAttribDivisor(this._aRect,1),t.enableVertexAttribArray(this._aUv),t.vertexAttribPointer(this._aUv,4,t.FLOAT,false,r,16),t.vertexAttribDivisor(this._aUv,1),t.enableVertexAttribArray(this._aColor),t.vertexAttribPointer(this._aColor,4,t.FLOAT,false,r,32),t.vertexAttribDivisor(this._aColor,1),t.bindVertexArray(null),t.disable(t.DEPTH_TEST),t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA);}beginMainFrame(){this._phase="main",this._mainItems=[],this._overlayItems=[];}beginOverlayFrame(){this._phase="overlay",this._overlayItems=[];}queue(e){this._phase==="main"?this._mainItems.push(e):this._overlayItems.push(e);}flush(){let e=this._gl;if(this._cssW===0||this._cssH===0)return;e.viewport(0,0,this._canvas.width,this._canvas.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);let t=this._mainItems.concat(this._overlayItems);if(t.length===0)return;e.useProgram(this._program),e.uniform2f(this._uRes,this._cssW,this._cssH),e.uniform1i(this._uAtlas,0),e.bindVertexArray(this._vao),e.activeTexture(e.TEXTURE0);let r=new Map;for(let i of t){let o=`${i.fontSize}/${i.fontFamily}`,a=r.get(o);a===void 0&&(a={atlas:this._getAtlas(i.fontSize,i.fontFamily),items:[]},r.set(o,a)),a.items.push(i);}for(let{atlas:i,items:o}of r.values()){if(i.texture===null)continue;let a=this._packInstances(i,o);a!==0&&(e.bindTexture(e.TEXTURE_2D,i.texture),e.bindBuffer(e.ARRAY_BUFFER,this._instanceVbo),e.bufferSubData(e.ARRAY_BUFFER,0,this._buf.subarray(0,a*wr)),e.drawArraysInstanced(e.TRIANGLE_STRIP,0,4,a));}e.bindVertexArray(null);}_packInstances(e,t){let r=this._buf,i=0,o=a=>Math.round(a*this._pixelRatio)/this._pixelRatio;for(let a of t){let s=a.fontSize/e.fontSize,c=(e.getGlyph("0")?.cellH??a.fontSize)*s,u=a.paddingLeft??0,h=a.paddingTop??0,[d,m,p,g]=rl(a.color),f=0;for(let C of a.text){let T=e.getGlyph(C);f+=(T!==null?T.advance:a.fontSize*.5)*s;}let v=a.align??"left",y;v==="right"||v==="end"?y=a.x-f+u:v==="center"?y=a.x-f/2+u:y=a.x+u;let b=a.baseline??"top",S;b==="bottom"||b==="alphabetic"||b==="ideographic"?S=a.y-c+h:b==="middle"?S=a.y-c/2+h:S=a.y+h,y=o(y),S=o(S);let x=y;for(let C of a.text){if(i>=an)break;let T=e.getGlyph(C);if(T===null){x+=a.fontSize*.5*s;continue}let A=T.cellW*s,P=o(x),R=S,D=Math.max(1/this._pixelRatio,o(A)),E=Math.max(1/this._pixelRatio,o(c)),I=i*wr;r[I]=P,r[I+1]=R,r[I+2]=D,r[I+3]=E,r[I+4]=T.u0,r[I+5]=T.v0,r[I+6]=T.u1,r[I+7]=T.v1,r[I+8]=d,r[I+9]=m,r[I+10]=p,r[I+11]=g,x+=T.advance*s,i++;}}return i}_getAtlas(e,t){let r=`${e}/${t}`,i=this._atlases.get(r);return i===void 0&&(i=new Pr(e,t),i.build(this._gl),this._atlases.set(r,i)),i}resize(e,t){if(this._cssW===e&&this._cssH===t)return;this._cssW=e,this._cssH=t;let r=Math.max(Math.ceil(z(this._canvas)),1);this._pixelRatio=r,this._canvas.width=Math.round(e*this._pixelRatio),this._canvas.height=Math.round(t*this._pixelRatio),this._canvas.style.width=`${e}px`,this._canvas.style.height=`${t}px`,this._gl.viewport(0,0,this._canvas.width,this._canvas.height);}getElement(){return this._canvas}destroy(){let e=this._gl;for(let r of this._atlases.values())r.destroy(e);this._atlases.clear(),e.deleteBuffer(this._cornerVbo),e.deleteBuffer(this._instanceVbo),e.deleteVertexArray(this._vao),e.deleteProgram(this._program),e.getExtension("WEBGL_lose_context")?.loseContext(),this._canvas.remove();}static isSupported(){return pe.isSupported()}_compileProgram(){let e=this._gl,t=e.createShader(e.VERTEX_SHADER);e.shaderSource(t,el),e.compileShader(t);let r=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(r,tl),e.compileShader(r);let i=e.createProgram();return e.attachShader(i,t),e.attachShader(i,r),e.linkProgram(i),e.deleteShader(t),e.deleteShader(r),i}};var Xe=class extends Ee{_rootContainer;_pane;_container;_bounding=He();_cursor="crosshair";_forceCursor=null;constructor(e,t){super(),this._pane=t,this._rootContainer=e,this._container=this.createContainer(),e.appendChild(this._container);}setBounding(e){return U(this._bounding,e),this}getContainer(){return this._container}getBounding(){return this._bounding}getPane(){return this._pane}checkEventOn(e){return true}setCursor(e){L(this._forceCursor)||e!==this._cursor&&(this._cursor=e,this._container.style.cursor=this._cursor);}setForceCursor(e){e!==this._forceCursor&&(this._forceCursor=e,this._container.style.cursor=this._forceCursor??this._cursor);}getForceCursor(){return this._forceCursor}update(e){this.updateImp(this._container,this._bounding,e??3);}destroy(){this._rootContainer.removeChild(this._container);}};var ke=class extends Xe{_mainCanvas;_overlayCanvas;_textRenderer;constructor(e,t){super(e,t);let r=this.getContainer();this._textRenderer=Et.isSupported()?new Et(r):null,this._mainCanvas=new pt({position:"absolute",top:"0",left:"0",zIndex:"2",boxSizing:"border-box"},()=>{this._textRenderer?.beginMainFrame(),this.updateMain(this._mainCanvas.getContext()),this._textRenderer?.flush();}),this._overlayCanvas=new pt({position:"absolute",top:"0",left:"0",zIndex:"2",boxSizing:"border-box"},()=>{this._textRenderer?.beginOverlayFrame(),this.updateOverlay(this._overlayCanvas.getContext()),this._textRenderer?.flush();}),r.appendChild(this._mainCanvas.getElement()),r.appendChild(this._overlayCanvas.getElement());}createContainer(){return oe("div",{margin:"0",padding:"0",position:"absolute",top:"0",overflow:"hidden",boxSizing:"border-box",zIndex:"1",backgroundColor:"inherit"})}getTextRenderer(){return this._textRenderer}queueText(e){this._textRenderer?.queue(e);}updateImp(e,t,r){let{width:i,height:o,left:a}=t;e.style.left=`${a}px`;let s=r,l=e.clientWidth,c=e.clientHeight;switch((i!==l||o!==c)&&(e.style.width=`${i}px`,e.style.height=`${o}px`,this._textRenderer?.resize(i,o),s=3),s){case 0:{this._mainCanvas.update(i,o);break}case 1:{this._overlayCanvas.update(i,o);break}case 3:case 4:{this._mainCanvas.update(i,o),this._overlayCanvas.update(i,o);break}}}destroy(){this._mainCanvas.destroy(),this._overlayCanvas.destroy(),this._textRenderer?.destroy();}getImage(e){let{width:t,height:r}=this.getBounding(),i=oe("canvas",{width:`${t}px`,height:`${r}px`,boxSizing:"border-box"}),o=i.getContext("2d"),a=z(i);return i.width=t*a,i.height=r*a,o.scale(a,a),o.drawImage(this._mainCanvas.getElement(),0,0,t,r),e&&o.drawImage(this._overlayCanvas.getElement(),0,0,t,r),i}};function ti(n,e){let t=[];t=t.concat(e);for(let r of t){let{x:i,y:o,r:a}=r,s=n.x-i,l=n.y-o;if(!(s*s+l*l>a*a))return true}return false}function il(n,e,t){let r=[];r=r.concat(e);let{style:i="fill",color:o="currentColor",borderSize:a=1,borderColor:s="currentColor",borderStyle:l="solid",borderDashedValue:c=[2,2]}=t,u=(i==="fill"||t.style==="stroke_fill")&&(!L(o)||!Re(o));u&&(n.fillStyle=o,r.forEach(({x:h,y:d,r:m})=>{n.beginPath(),n.arc(h,d,m,0,Math.PI*2),n.closePath(),n.fill();})),(i==="stroke"||t.style==="stroke_fill")&&a>0&&!Re(s)&&(n.strokeStyle=s,n.lineWidth=a,l==="dashed"?n.setLineDash(c):n.setLineDash([]),r.forEach(({x:h,y:d,r:m})=>{(!u||m>a)&&(n.beginPath(),n.arc(h,d,m,0,Math.PI*2),n.closePath(),n.stroke());}));}var ol={name:"circle",checkEventOn:ti,draw:(n,e,t)=>{il(n,e,t);}},sn=ol;function ri(n,e){let t=[];t=t.concat(e);for(let r of t){let i=false,{coordinates:o}=r;for(let a=0,s=o.length-1;a<o.length;s=a++)o[a].y>n.y!=o[s].y>n.y&&n.x<(o[s].x-o[a].x)*(n.y-o[a].y)/(o[s].y-o[a].y)+o[a].x&&(i=!i);if(i)return true}return false}function nl(n,e,t){let r=[];r=r.concat(e);let{style:i="fill",color:o="currentColor",borderSize:a=1,borderColor:s="currentColor",borderStyle:l="solid",borderDashedValue:c=[2,2]}=t;(i==="fill"||t.style==="stroke_fill")&&(!L(o)||!Re(o))&&(n.fillStyle=o,r.forEach(({coordinates:u})=>{n.beginPath(),n.moveTo(u[0].x,u[0].y);for(let h=1;h<u.length;h++)n.lineTo(u[h].x,u[h].y);n.closePath(),n.fill();})),(i==="stroke"||t.style==="stroke_fill")&&a>0&&!Re(s)&&(n.strokeStyle=s,n.lineWidth=a,l==="dashed"?n.setLineDash(c):n.setLineDash([]),r.forEach(({coordinates:u})=>{n.beginPath(),n.moveTo(u[0].x,u[0].y);for(let h=1;h<u.length;h++)n.lineTo(u[h].x,u[h].y);n.closePath(),n.stroke();}));}var al={name:"polygon",checkEventOn:ri,draw:(n,e,t)=>{nl(n,e,t);}},ln=al;function It(n,e){let t=[];t=t.concat(e);for(let r of t){let i=r.x,o=r.width;o<re*2&&(i-=re,o=re*2);let a=r.y,s=r.height;if(s<re*2&&(a-=re,s=re*2),n.x>=i&&n.x<=i+o&&n.y>=a&&n.y<=a+s)return true}return false}function Ue(n,e,t){let r=[];r=r.concat(e);let{style:i="fill",color:o="transparent",borderSize:a=1,borderColor:s="transparent",borderStyle:l="solid",borderRadius:c=0,borderDashedValue:u=[2,2]}=t,h=n.roundRect??n.rect,d=(i==="fill"||t.style==="stroke_fill")&&(!L(o)||!Re(o));if(d&&(n.fillStyle=o,r.forEach(({x:m,y:p,width:g,height:f})=>{n.beginPath(),h.call(n,m,p,g,f,c),n.closePath(),n.fill();})),(i==="stroke"||t.style==="stroke_fill")&&a>0&&!Re(s)){n.strokeStyle=s,n.fillStyle=s,n.lineWidth=a,l==="dashed"?n.setLineDash(u):n.setLineDash([]);let m=a%2===1?.5:0,p=Math.round(m*2);r.forEach(({x:g,y:f,width:v,height:y})=>{v>a*2&&y>a*2?(n.beginPath(),h.call(n,g+m,f+m,v-p,y-p,c),n.closePath(),n.stroke()):d||n.fillRect(g,f,v,y);});}}var sl={name:"rect",checkEventOn:It,draw:(n,e,t)=>{Ue(n,e,t);}},cn=sl;function gt(n,e){let{size:t=12,paddingLeft:r=0,paddingTop:i=0,paddingRight:o=0,paddingBottom:a=0,weight:s="normal",family:l}=e,{x:c,y:u,text:h,align:d="left",baseline:m="top",width:p,height:g}=n,f=p??r+ie(h,t,s,l)+o,v=g??i+t+a,y=0;switch(d){case "left":case "start":{y=c;break}case "right":case "end":{y=c-f;break}default:{y=c-f/2;break}}let b=0;switch(m){case "top":case "hanging":{b=u;break}case "bottom":case "ideographic":case "alphabetic":{b=u-v;break}default:{b=u-v/2;break}}return {x:y,y:b,width:f,height:v}}function ii(n,e,t){let r=[];r=r.concat(e);for(let i of r){let{x:o,y:a,width:s,height:l}=gt(i,t);if(n.x>=o&&n.x<=o+s&&n.y>=a&&n.y<=a+l)return true}return false}function ll(n,e,t){let r=[];r=r.concat(e);let{color:i="currentColor",size:o=12,family:a,weight:s,paddingLeft:l=0,paddingTop:c=0,paddingRight:u=0}=t,h=r.map(p=>gt(p,t));Ue(n,h,{...t,color:t.backgroundColor}),n.textAlign="left",n.textBaseline="top",n.font=se(o,s,a),n.fillStyle=i;let d=Math.max(z(n.canvas),1),m=p=>Math.round(p*d)/d;r.forEach((p,g)=>{let f=h[g],v=m(f.x+l),y=m(f.y+c),b=Math.max(0,m(f.width-l-u));n.fillText(p.text,v,y,b);});}var cl={name:"text",checkEventOn:ii,draw:(n,e,t)=>{ll(n,e,t);}},un=cl;function hn(n,e){let t=n.x-e.x,r=n.y-e.y;return Math.sqrt(t*t+r*r)}function oi(n,e){let t=[];t=t.concat(e);for(let r of t)if(Math.abs(hn(n,r)-r.r)<re){let{r:i,startAngle:o,endAngle:a}=r,s=i*Math.cos(o)+r.x,l=i*Math.sin(o)+r.y,c=i*Math.cos(a)+r.x,u=i*Math.sin(a)+r.y;if(n.x<=Math.max(s,c)+re&&n.x>=Math.min(s,c)-re&&n.y<=Math.max(l,u)+re&&n.y>=Math.min(l,u)-re)return true}return false}function ul(n,e,t){let r=[];r=r.concat(e);let{style:i="solid",size:o=1,color:a="currentColor",dashedValue:s=[2,2]}=t;n.lineWidth=o,n.strokeStyle=a,i==="dashed"?n.setLineDash(s):n.setLineDash([]),r.forEach(({x:l,y:c,r:u,startAngle:h,endAngle:d})=>{n.beginPath(),n.arc(l,c,u,h,d),n.stroke(),n.closePath();});}var hl={name:"arc",checkEventOn:oi,draw:(n,e,t)=>{ul(n,e,t);}},dn=hl;function mn(n,e,t,r,i,o,a){let[s,l,c,u,h,d,m]=r,p=a?e+d:d+i,g=a?t+m:m+o;dl(e,t,s,l,c,u,h,p,g).forEach(v=>{n.bezierCurveTo(v[0],v[1],v[2],v[3],v[4],v[5]);});}function dl(n,e,t,r,i,o,a,s,l){let{cx:c,cy:u,startAngle:h,deltaAngle:d}=ml(n,e,t,r,i,o,a,s,l),m=[],p=Math.ceil(Math.abs(d)/(Math.PI/2));for(let g=0;g<p;g++){let f=h+g*d/p,v=h+(g+1)*d/p,y=pl(c,u,t,r,i,f,v);m.push(y);}return m}function ml(n,e,t,r,i,o,a,s,l){let c=i*Math.PI/180,u=(n-s)/2,h=(e-l)/2,d=Math.cos(c)*u+Math.sin(c)*h,m=-Math.sin(c)*u+Math.cos(c)*h,p=d**2/t**2+m**2/r**2;p>1&&(t*=Math.sqrt(p),r*=Math.sqrt(p));let g=o===a?-1:1,f=t**2*r**2-t**2*m**2-r**2*d**2,v=t**2*m**2+r**2*d**2,y=g*Math.sqrt(Math.abs(f/v))*(t*m/r),b=g*Math.sqrt(Math.abs(f/v))*(-r*d/t),S=Math.cos(c)*y-Math.sin(c)*b+(n+s)/2,x=Math.sin(c)*y+Math.cos(c)*b+(e+l)/2,C=Math.atan2((m-b)/r,(d-y)/t),T=Math.atan2((-m-b)/r,(-d-y)/t)-C;return T<0&&a===1?T+=2*Math.PI:T>0&&a===0&&(T-=2*Math.PI),{cx:S,cy:x,startAngle:C,deltaAngle:T}}function pl(n,e,t,r,i,o,a){let s=Math.sin(a-o)*(Math.sqrt(4+3*Math.tan((a-o)/2)**2)-1)/3,l=Math.cos(i),c=Math.sin(i),u=n+t*Math.cos(o)*l-r*Math.sin(o)*c,h=e+t*Math.cos(o)*c+r*Math.sin(o)*l,d=n+t*Math.cos(a)*l-r*Math.sin(a)*c,m=e+t*Math.cos(a)*c+r*Math.sin(a)*l,p=u+s*(-t*Math.sin(o)*l-r*Math.cos(o)*c),g=h+s*(-t*Math.sin(o)*c+r*Math.cos(o)*l),f=d-s*(-t*Math.sin(a)*l-r*Math.cos(a)*c),v=m-s*(-t*Math.sin(a)*c+r*Math.cos(a)*l);return [p,g,f,v,d,m]}function gl(n,e,t){let r=[];r=r.concat(e);let{lineWidth:i=1,color:o="currentColor"}=t;n.lineWidth=i,n.strokeStyle=o,n.setLineDash([]),r.forEach(({x:a,y:s,path:l})=>{let c=l.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi);if(_(c)){let u=a,h=s;n.beginPath(),c.forEach(d=>{let m=0,p=0,g=0,f=0,v=d[0],y=d.slice(1).trim().split(/[\s,]+/).map(Number);switch(v){case "M":m=y[0]+u,p=y[1]+h,n.moveTo(m,p),g=m,f=p;break;case "m":m+=y[0],p+=y[1],n.moveTo(m,p),g=m,f=p;break;case "L":m=y[0]+u,p=y[1]+h,n.lineTo(m,p);break;case "l":m+=y[0],p+=y[1],n.lineTo(m,p);break;case "H":m=y[0]+u,n.lineTo(m,p);break;case "h":m+=y[0],n.lineTo(m,p);break;case "V":p=y[0]+h,n.lineTo(m,p);break;case "v":p+=y[0],n.lineTo(m,p);break;case "C":n.bezierCurveTo(y[0]+u,y[1]+h,y[2]+u,y[3]+h,y[4]+u,y[5]+h),m=y[4]+u,p=y[5]+h;break;case "c":n.bezierCurveTo(m+y[0],p+y[1],m+y[2],p+y[3],m+y[4],p+y[5]),m+=y[4],p+=y[5];break;case "S":n.bezierCurveTo(m,p,y[0]+u,y[1]+h,y[2]+u,y[3]+h),m=y[2]+u,p=y[3]+h;break;case "s":n.bezierCurveTo(m,p,m+y[0],p+y[1],m+y[2],p+y[3]),m+=y[2],p+=y[3];break;case "Q":n.quadraticCurveTo(y[0]+u,y[1]+h,y[2]+u,y[3]+h),m=y[2]+u,p=y[3]+h;break;case "q":n.quadraticCurveTo(m+y[0],p+y[1],m+y[2],p+y[3]),m+=y[2],p+=y[3];break;case "T":n.quadraticCurveTo(m,p,y[0]+u,y[1]+h),m=y[0]+u,p=y[1]+h;break;case "t":n.quadraticCurveTo(m,p,m+y[0],p+y[1]),m+=y[0],p+=y[1];break;case "A":mn(n,m,p,y,u,h,false),m=y[5]+u,p=y[6]+h;break;case "a":mn(n,m,p,y,u,h,true),m+=y[5],p+=y[6];break;case "Z":case "z":n.closePath(),m=g,p=f;break;}}),t.style==="fill"?n.fill():n.stroke();}});}var fl={name:"path",checkEventOn:It,draw:(n,e,t)=>{gl(n,e,t);}},pn=fl;var gn={},yl=[sn,wo,ln,cn,un,dn,pn];yl.forEach(n=>{gn[n.name]=Tt.extend(n);});function fn(n){return gn[n]??null}var J=class extends Ee{_widget;constructor(e){super(),this._widget=e;}getWidget(){return this._widget}createFigure(e,t){let r=fn(e.name);if(r!==null){let i=new r(e);if(_(t)){for(let o in t)t.hasOwnProperty(o)&&i.registerEvent(o,t[o]);this.addChild(i);}return i}return null}draw(e,...t){this.clear(),this.drawImp(e,t);}checkEventOn(e){return true}};var Er=`#version 300 es
|
|
28
|
+
precision highp float;
|
|
29
|
+
|
|
30
|
+
// Per-instance attributes (divisor = 1)
|
|
31
|
+
in float a_centerX;
|
|
32
|
+
in float a_open;
|
|
33
|
+
in float a_high;
|
|
34
|
+
in float a_low;
|
|
35
|
+
in float a_close;
|
|
36
|
+
in vec4 a_wickColor;
|
|
37
|
+
in vec4 a_bodyColor;
|
|
38
|
+
in vec4 a_borderColor;
|
|
39
|
+
|
|
40
|
+
uniform float u_priceFrom; // realFrom of the visible Y range
|
|
41
|
+
uniform float u_priceRange; // realRange of the visible Y range
|
|
42
|
+
uniform vec2 u_resolution; // canvas physical pixel dimensions
|
|
43
|
+
uniform float u_pixelRatio; // CSS px \u2192 physical px
|
|
44
|
+
uniform float u_barHalfWidth; // half bar gapBar width, in CSS pixels
|
|
45
|
+
// Render mode: 0 = candle (solid/stroke), 1 = ohlc
|
|
46
|
+
uniform int u_renderMode;
|
|
47
|
+
// Half of ohlcSize in CSS pixels \u2014 only used when u_renderMode == 1
|
|
48
|
+
uniform float u_ohlcHalfSize;
|
|
49
|
+
// Pan-offset optimisation: CSS pixel delta added to every bar's a_centerX so
|
|
50
|
+
// pure-pan frames skip bufferSubData and update only this uniform (O(1)).
|
|
51
|
+
uniform float u_panOffset;
|
|
52
|
+
|
|
53
|
+
out vec4 v_color;
|
|
54
|
+
|
|
55
|
+
// Unit-quad positions shared by all three sub-quads
|
|
56
|
+
vec2 unitQuad(int id) {
|
|
57
|
+
if (id == 0) return vec2(0.0, 0.0);
|
|
58
|
+
if (id == 1) return vec2(1.0, 0.0);
|
|
59
|
+
if (id == 2) return vec2(0.0, 1.0);
|
|
60
|
+
if (id == 3) return vec2(0.0, 1.0);
|
|
61
|
+
if (id == 4) return vec2(1.0, 0.0);
|
|
62
|
+
return vec2(1.0, 1.0);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// GPU price \u2192 physical screen-Y pixel
|
|
66
|
+
float priceToPhysY(float price) {
|
|
67
|
+
float rate = (price - u_priceFrom) / u_priceRange;
|
|
68
|
+
return (1.0 - rate) * u_resolution.y;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
void main() {
|
|
72
|
+
bool isWick = gl_VertexID < 6;
|
|
73
|
+
bool isBodyOuter = gl_VertexID >= 6 && gl_VertexID < 12;
|
|
74
|
+
// isBodyInner = gl_VertexID >= 12
|
|
75
|
+
|
|
76
|
+
int localId = gl_VertexID < 6 ? gl_VertexID :
|
|
77
|
+
gl_VertexID < 12 ? gl_VertexID - 6 :
|
|
78
|
+
gl_VertexID - 12;
|
|
79
|
+
vec2 unit = unitQuad(localId);
|
|
80
|
+
|
|
81
|
+
float highY = priceToPhysY(a_high);
|
|
82
|
+
float lowY = priceToPhysY(a_low);
|
|
83
|
+
float openY = priceToPhysY(a_open);
|
|
84
|
+
float closeY = priceToPhysY(a_close);
|
|
85
|
+
|
|
86
|
+
float pr = u_pixelRatio;
|
|
87
|
+
float cx = (a_centerX + u_panOffset) * pr; // pan-offset + CSS px \u2192 physical px
|
|
88
|
+
float bhw = u_barHalfWidth * pr;
|
|
89
|
+
|
|
90
|
+
float screenX, screenY;
|
|
91
|
+
|
|
92
|
+
if (u_renderMode == 1) {
|
|
93
|
+
// \u2500\u2500 OHLC mode \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
94
|
+
// wick: center-aligned vertical bar, width = ohlcSize
|
|
95
|
+
// body-outer: open stub (left side: cx-bhw \u2192 cx-ohw)
|
|
96
|
+
// body-inner: close stub (right side: cx+ohw \u2192 cx+bhw)
|
|
97
|
+
float ohw = u_ohlcHalfSize * pr; // half ohlcSize in physical px
|
|
98
|
+
float tickH = ohw * 2.0; // tick height = ohlcSize
|
|
99
|
+
|
|
100
|
+
if (isWick) {
|
|
101
|
+
screenX = cx - ohw + unit.x * ohw * 2.0;
|
|
102
|
+
screenY = highY + (lowY - highY) * unit.y;
|
|
103
|
+
v_color = a_bodyColor;
|
|
104
|
+
} else if (isBodyOuter) {
|
|
105
|
+
float left = cx - bhw;
|
|
106
|
+
float right = cx - ohw;
|
|
107
|
+
screenX = left + unit.x * max(right - left, 0.0);
|
|
108
|
+
screenY = openY + unit.y * tickH;
|
|
109
|
+
v_color = a_bodyColor;
|
|
110
|
+
} else {
|
|
111
|
+
float left = cx + ohw;
|
|
112
|
+
float right = cx + bhw;
|
|
113
|
+
screenX = left + unit.x * max(right - left, 0.0);
|
|
114
|
+
screenY = closeY + unit.y * tickH;
|
|
115
|
+
v_color = a_bodyColor;
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
// \u2500\u2500 Candle mode (solid / stroke) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
119
|
+
float bodyTop = min(openY, closeY);
|
|
120
|
+
float bodyBottom = max(openY, closeY);
|
|
121
|
+
bodyBottom = max(bodyBottom, bodyTop + 1.0); // min 1px body
|
|
122
|
+
|
|
123
|
+
if (isWick) {
|
|
124
|
+
screenX = cx - 0.5 + unit.x;
|
|
125
|
+
screenY = highY + (lowY - highY) * unit.y;
|
|
126
|
+
v_color = a_wickColor;
|
|
127
|
+
} else if (isBodyOuter) {
|
|
128
|
+
screenX = cx - bhw + unit.x * bhw * 2.0;
|
|
129
|
+
screenY = bodyTop + (bodyBottom - bodyTop) * unit.y;
|
|
130
|
+
v_color = a_borderColor;
|
|
131
|
+
} else {
|
|
132
|
+
// body inner \u2014 1 physical pixel inset on each side.
|
|
133
|
+
// For stroke types, bodyColor alpha = 0 \u2192 body-inner is transparent,
|
|
134
|
+
// leaving only the body-outer border visible (hollow candle).
|
|
135
|
+
float inset = 1.0;
|
|
136
|
+
float innerHW = max(bhw - inset, 0.5);
|
|
137
|
+
screenX = cx - innerHW + unit.x * innerHW * 2.0;
|
|
138
|
+
float innerTop = bodyTop + inset;
|
|
139
|
+
float innerBottom = max(bodyBottom - inset, innerTop);
|
|
140
|
+
screenY = innerTop + (innerBottom - innerTop) * unit.y;
|
|
141
|
+
v_color = a_bodyColor;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Physical pixel \u2192 NDC (executes for both OHLC and Candle modes)
|
|
146
|
+
gl_Position = vec4(
|
|
147
|
+
screenX / u_resolution.x * 2.0 - 1.0,
|
|
148
|
+
1.0 - screenY / u_resolution.y * 2.0,
|
|
149
|
+
0.0, 1.0
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
`,Ir=`#version 300 es
|
|
153
|
+
precision mediump float;
|
|
154
|
+
in vec4 v_color;
|
|
155
|
+
out vec4 fragColor;
|
|
156
|
+
void main() { fragColor = v_color; }
|
|
157
|
+
`;function vl(n){let e=n.replace("#","");if(e.length===6||e.length===8){let t=parseInt(e.slice(0,2),16)/255,r=parseInt(e.slice(2,4),16)/255,i=parseInt(e.slice(4,6),16)/255,o=e.length===8?parseInt(e.slice(6,8),16)/255:1;return [t,r,i,o]}if(e.length===3){let t=parseInt(e[0]+e[0],16)/255,r=parseInt(e[1]+e[1],16)/255,i=parseInt(e[2]+e[2],16)/255;return [t,r,i,1]}return [0,0,0,1]}function _l(n){if(n.startsWith("#"))return vl(n);let e=n.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)/);return e!==null?[parseFloat(e[1])/255,parseFloat(e[2])/255,parseFloat(e[3])/255,e[4]!==void 0?parseFloat(e[4]):1]:[0,0,0,1]}function Te(n,e){let t=e.get(n);return t===void 0&&(t=_l(n),e.set(n,t)),t}function ft(n,e,t){e[t]=n[0]*255+.5|0,e[t+1]=n[1]*255+.5|0,e[t+2]=n[2]*255+.5|0,e[t+3]=n[3]*255+.5|0;}var ni=class{_canvas;_gl;_sizeVersion=0;constructor(e){let t=document.createElement("canvas");t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.zIndex="1",t.style.pointerEvents="none",e.appendChild(t),this._canvas=t;let r=t.getContext("webgl2",{antialias:false,premultipliedAlpha:false,preserveDrawingBuffer:false,powerPreference:"high-performance",alpha:true});if(r===null)throw t.remove(),new Error("[SharedIndicatorGLCanvas] WebGL2 unavailable");this._gl=r,r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),r.disable(r.DEPTH_TEST),r.enable(r.SCISSOR_TEST);}get gl(){return this._gl}get canvas(){return this._canvas}get sizeVersion(){return this._sizeVersion}resize(e,t){let r=z(this._canvas),i=Math.round(e*r),o=Math.round(t*r);this._canvas.width===i&&this._canvas.height===o||(this._canvas.style.width=`${e}px`,this._canvas.style.height=`${t}px`,this._canvas.width=i,this._canvas.height=o,this._sizeVersion++);}beginFrame(){let e=this._gl,t=this._canvas.width,r=this._canvas.height;e.viewport(0,0,t,r),e.scissor(0,0,t,r),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);}destroy(){this._gl.getExtension("WEBGL_lose_context")?.loseContext(),this._canvas.remove();}},Rt=new WeakMap,bl=new FinalizationRegistry(n=>{n.destroy();});function Dt(n){return Rt.get(n)??null}function ai(n,e){if(!pe.isSupported())return null;let t=Rt.get(n);if(t===void 0)try{t=new ni(e),Rt.set(n,t),bl.register(n,t,n);}catch{return null}return t}function yn(n){let e=Rt.get(n);e!==void 0&&(e.destroy(),Rt.delete(n));}var _e=24,Me=20,vn=6,xl=`#version 300 es
|
|
158
|
+
precision highp float;
|
|
159
|
+
|
|
160
|
+
// Per-segment attributes (divisor = 1)
|
|
161
|
+
in float a_x0;
|
|
162
|
+
in float a_y0;
|
|
163
|
+
in float a_x1;
|
|
164
|
+
in float a_y1;
|
|
165
|
+
in float a_halfWidth; // CSS pixels
|
|
166
|
+
in vec4 a_color; // RGBA, normalized
|
|
167
|
+
|
|
168
|
+
// Canvas dimensions in physical pixels; devicePixelRatio
|
|
169
|
+
uniform vec2 u_resolution;
|
|
170
|
+
uniform float u_pixelRatio;
|
|
171
|
+
|
|
172
|
+
out vec4 v_color;
|
|
173
|
+
out float v_normDist; // signed normalised perp distance: \xB11 at the line edges
|
|
174
|
+
|
|
175
|
+
void main() {
|
|
176
|
+
// Quad-expansion pattern for 6 vertices (two triangles):
|
|
177
|
+
// vi: 0 1 2 3 4 5
|
|
178
|
+
// t: 0 1 1 0 1 0 (0 = p0 endpoint, 1 = p1 endpoint)
|
|
179
|
+
// n: -1 -1 +1 -1 +1 +1 (\xB1normal extrusion)
|
|
180
|
+
int vi = gl_VertexID % 6;
|
|
181
|
+
float t = (vi == 1 || vi == 2 || vi == 4) ? 1.0 : 0.0;
|
|
182
|
+
float n = (vi == 2 || vi == 4 || vi == 5) ? 1.0 : -1.0;
|
|
183
|
+
|
|
184
|
+
// Convert endpoints to physical pixels
|
|
185
|
+
vec2 p0 = vec2(a_x0, a_y0) * u_pixelRatio;
|
|
186
|
+
vec2 p1 = vec2(a_x1, a_y1) * u_pixelRatio;
|
|
187
|
+
vec2 dir = p1 - p0;
|
|
188
|
+
float len = length(dir);
|
|
189
|
+
vec2 unitDir = len > 0.001 ? dir / len : vec2(1.0, 0.0);
|
|
190
|
+
vec2 normal = vec2(-unitDir.y, unitDir.x);
|
|
191
|
+
|
|
192
|
+
// Interpolate along segment then extrude perpendicular
|
|
193
|
+
vec2 pos = mix(p0, p1, t) + normal * (n * a_halfWidth * u_pixelRatio);
|
|
194
|
+
|
|
195
|
+
// Physical px \u2192 NDC (Y-flip: CSS Y=0 is top, NDC Y=+1 is top)
|
|
196
|
+
gl_Position = vec4(
|
|
197
|
+
(pos.x / u_resolution.x) * 2.0 - 1.0,
|
|
198
|
+
1.0 - (pos.y / u_resolution.y) * 2.0,
|
|
199
|
+
0.0, 1.0
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
v_color = a_color;
|
|
203
|
+
v_normDist = n; // \xB11 at the outer edges, interpolated across the quad
|
|
204
|
+
}
|
|
205
|
+
`,Cl=`#version 300 es
|
|
206
|
+
precision mediump float;
|
|
207
|
+
in vec4 v_color;
|
|
208
|
+
in float v_normDist;
|
|
209
|
+
out vec4 fragColor;
|
|
210
|
+
void main() {
|
|
211
|
+
// Anti-alias the line edge over ~1 physical pixel using the built-in
|
|
212
|
+
// fwidth() derivative (GLSL ES 3.0 \u2014 no extension needed).
|
|
213
|
+
// abs(v_normDist) \u2192 0 at the centreline, 1 at the hard edge.
|
|
214
|
+
// smoothstep fades the alpha from 1 \u2192 0 over one derivative-width.
|
|
215
|
+
float fw = fwidth(v_normDist);
|
|
216
|
+
float aa = 1.0 - smoothstep(1.0 - fw, 1.0 + fw, abs(v_normDist));
|
|
217
|
+
fragColor = vec4(v_color.rgb, v_color.a * aa);
|
|
218
|
+
}
|
|
219
|
+
`;function _n(n,e,t){let r=n.createShader(e);if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS))throw new Error(`[IndicatorLineWebGLRenderer] shader compile error: ${n.getShaderInfoLog(r)??"?"}`);return r}function Tl(n){let e=_n(n,n.VERTEX_SHADER,xl),t=_n(n,n.FRAGMENT_SHADER,Cl),r=n.createProgram();if(n.attachShader(r,e),n.attachShader(r,t),n.linkProgram(r),n.deleteShader(e),n.deleteShader(t),!n.getProgramParameter(r,n.LINK_STATUS))throw new Error(`[IndicatorLineWebGLRenderer] program link error: ${n.getProgramInfoLog(r)??"?"}`);return r}var si=class{_sharedCanvas;_gl;_program;_vao;_vbo;_uResolution;_uPixelRatio;_capacity=0;_segCount=0;_stagingBuf=new ArrayBuffer(512*_e);_stagingF32=new Float32Array(this._stagingBuf);_stagingU8=new Uint8Array(this._stagingBuf);_colorCache=new Map;_gridVao;_gridVbo;_gridCapacity=0;_gridSegCount=0;_gridStagingBuf=new ArrayBuffer(128*_e);_gridStagingF32=new Float32Array(this._gridStagingBuf);_gridStagingU8=new Uint8Array(this._gridStagingBuf);_gridVboVersion=0;_gridDrawnVersion=-1;_gridFingerprintCount=-1;_gridFingerprintFirstX=0;_gridFingerprintFirstY=0;_gridFingerprintLastX=0;_gridFingerprintLastY=0;_fingerprintSegmentCount=-1;_fingerprintFirstX=0;_fingerprintFirstY=0;_fingerprintLastX=0;_fingerprintLastY=0;_culledBuf=[];_vboVersion=0;_drawnVersion=-1;_lastSizeVersion=-1;constructor(e){this._sharedCanvas=e;let t=e.gl;this._gl=t,this._program=Tl(t),t.useProgram(this._program),this._uResolution=t.getUniformLocation(this._program,"u_resolution"),this._uPixelRatio=t.getUniformLocation(this._program,"u_pixelRatio"),this._vao=t.createVertexArray(),t.bindVertexArray(this._vao),this._vbo=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._vbo),this._setupAttribs(t),t.bindVertexArray(null),this._gridVao=t.createVertexArray(),t.bindVertexArray(this._gridVao),this._gridVbo=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._gridVbo),this._setupAttribs(t),t.bindVertexArray(null);}_setupAttribs(e){let t=this._program,r=_e,i=(a,s)=>{let l=e.getAttribLocation(t,a);l<0||(e.enableVertexAttribArray(l),e.vertexAttribPointer(l,1,e.FLOAT,false,r,s),e.vertexAttribDivisor(l,1));};i("a_x0",0),i("a_y0",4),i("a_x1",8),i("a_y1",12),i("a_halfWidth",16);let o=e.getAttribLocation(t,"a_color");o>=0&&(e.enableVertexAttribArray(o),e.vertexAttribPointer(o,4,e.UNSIGNED_BYTE,true,r,Me),e.vertexAttribDivisor(o,1));}isDirty(){return this._vboVersion!==this._drawnVersion||this._lastSizeVersion!==this._sharedCanvas.sizeVersion}resize(e,t){this._sharedCanvas.resize(e,t);}_ensureCapacity(e){if(e<=this._capacity)return;let t=Math.max(e,this._capacity*2,512);this._stagingBuf=new ArrayBuffer(t*_e),this._stagingF32=new Float32Array(this._stagingBuf),this._stagingU8=new Uint8Array(this._stagingBuf);let r=this._gl;r.bindBuffer(r.ARRAY_BUFFER,this._vbo),r.bufferData(r.ARRAY_BUFFER,t*_e,r.DYNAMIC_DRAW),this._capacity=t;}_parseColorCached(e){return Te(e,this._colorCache)}setData(e){let t=this._culledBuf,r=0;for(let u=0;u<e.length;u++){let h=e[u];Math.abs(h.x1-h.x0)<.5&&Math.abs(h.y1-h.y0)<.5||(r>=t.length?t.push(h):t[r]=h,r++);}let i=r;if(this._segCount=i,i===0){this._fingerprintSegmentCount!==0&&this._vboVersion++,this._fingerprintSegmentCount=0;return}let o=t[0],a=t[r-1];if(i===this._fingerprintSegmentCount&&o.x0===this._fingerprintFirstX&&o.y0===this._fingerprintFirstY&&a.x1===this._fingerprintLastX&&a.y1===this._fingerprintLastY)return;this._fingerprintSegmentCount=i,this._fingerprintFirstX=o.x0,this._fingerprintFirstY=o.y0,this._fingerprintLastX=a.x1,this._fingerprintLastY=a.y1,this._ensureCapacity(i);let s=this._stagingF32,l=this._stagingU8;for(let u=0;u<i;u++){let h=t[u],d=u*5,m=u*_e;s[d+0]=h.x0,s[d+1]=h.y0,s[d+2]=h.x1,s[d+3]=h.y1,s[d+4]=h.halfWidth;let p=this._parseColorCached(h.color);l[m+Me]=p[0]*255+.5|0,l[m+Me+1]=p[1]*255+.5|0,l[m+Me+2]=p[2]*255+.5|0,l[m+Me+3]=p[3]*255+.5|0;}let c=this._gl;c.bindBuffer(c.ARRAY_BUFFER,this._vbo),c.bufferSubData(c.ARRAY_BUFFER,0,this._stagingU8,0,i*_e),this._vboVersion++;}draw(){let e=this._sharedCanvas,t=e.canvas,r=this._gl,i=z(t),o=t.width,a=t.height;this._drawnVersion=this._vboVersion,this._lastSizeVersion=e.sizeVersion,this._segCount!==0&&(r.useProgram(this._program),r.uniform2f(this._uResolution,o,a),r.uniform1f(this._uPixelRatio,i),r.bindVertexArray(this._vao),r.drawArraysInstanced(r.TRIANGLES,0,vn,this._segCount),r.bindVertexArray(null));}isGridDirty(){return this._gridVboVersion!==this._gridDrawnVersion||this._lastSizeVersion!==this._sharedCanvas.sizeVersion}_ensureGridCapacity(e){if(e<=this._gridCapacity)return;let t=Math.max(e,this._gridCapacity*2,128);this._gridStagingBuf=new ArrayBuffer(t*_e),this._gridStagingF32=new Float32Array(this._gridStagingBuf),this._gridStagingU8=new Uint8Array(this._gridStagingBuf);let r=this._gl;r.bindBuffer(r.ARRAY_BUFFER,this._gridVbo),r.bufferData(r.ARRAY_BUFFER,t*_e,r.DYNAMIC_DRAW),this._gridCapacity=t;}setGridLines(e){let t=e.length;if(this._gridSegCount=t,t===0){this._gridFingerprintCount!==0&&this._gridVboVersion++,this._gridFingerprintCount=0;return}let r=e[0],i=e[t-1];if(t===this._gridFingerprintCount&&r.x0===this._gridFingerprintFirstX&&r.y0===this._gridFingerprintFirstY&&i.x1===this._gridFingerprintLastX&&i.y1===this._gridFingerprintLastY)return;this._gridFingerprintCount=t,this._gridFingerprintFirstX=r.x0,this._gridFingerprintFirstY=r.y0,this._gridFingerprintLastX=i.x1,this._gridFingerprintLastY=i.y1,this._ensureGridCapacity(t);let o=this._gridStagingF32,a=this._gridStagingU8;for(let l=0;l<t;l++){let c=e[l],u=l*5,h=l*_e;o[u+0]=c.x0,o[u+1]=c.y0,o[u+2]=c.x1,o[u+3]=c.y1,o[u+4]=c.halfWidth;let d=this._parseColorCached(c.color);a[h+Me]=d[0]*255+.5|0,a[h+Me+1]=d[1]*255+.5|0,a[h+Me+2]=d[2]*255+.5|0,a[h+Me+3]=d[3]*255+.5|0;}let s=this._gl;s.bindBuffer(s.ARRAY_BUFFER,this._gridVbo),s.bufferSubData(s.ARRAY_BUFFER,0,this._gridStagingU8,0,t*_e),this._gridVboVersion++;}drawGrid(){if(this._gridDrawnVersion=this._gridVboVersion,this._lastSizeVersion=this._sharedCanvas.sizeVersion,this._gridSegCount===0)return;let t=this._sharedCanvas.canvas,r=this._gl,i=z(t),o=t.width,a=t.height;r.useProgram(this._program),r.uniform2f(this._uResolution,o,a),r.uniform1f(this._uPixelRatio,i),r.bindVertexArray(this._gridVao),r.drawArraysInstanced(r.TRIANGLES,0,vn,this._gridSegCount),r.bindVertexArray(null);}destroy(){let e=this._gl;e.deleteVertexArray(this._gridVao),e.deleteBuffer(this._gridVbo),e.deleteVertexArray(this._vao),e.deleteBuffer(this._vbo),e.deleteProgram(this._program);}},kt=new WeakMap;function Rr(n){return kt.get(n)??null}function bn(n,e){let t=kt.get(n);return t===void 0&&(t=new si(e),kt.set(n,t)),t}function xn(n){let e=kt.get(n);e!==void 0&&(e.destroy(),kt.delete(n));}var Mt=class extends J{drawImp(e){let t=this.getWidget(),r=this.getWidget().getPane(),i=r.getChart(),o=t.getBounding(),a=i.getStyles().grid;if(!a.show)return;let c=Dt(t)!==null?Rr(t):null;if(c!==null){let p=[],g=a.horizontal;if(g.show!==false){let v=r.getAxisComponent(),y=(g.size??1)/2;for(let b of v.getTicks())p.push({x0:0,y0:b.coord,x1:o.width,y1:b.coord,halfWidth:y,color:g.color});}let f=a.vertical;if(f.show!==false){let v=i.getXAxisPane().getAxisComponent(),y=(f.size??1)/2;for(let b of v.getTicks())p.push({x0:b.coord,y0:0,x1:b.coord,y1:o.height,halfWidth:y,color:f.color});}c.setGridLines(p);return}let u=a.horizontal;if(u.show){let g=r.getAxisComponent().getTicks().map(f=>({coordinates:[{x:0,y:f.coord},{x:o.width,y:f.coord}]}));this.createFigure({name:"line",attrs:g,styles:u})?.draw(e);}let d=a.vertical;if(d.show){let g=i.getXAxisPane().getAxisComponent().getTicks().map(f=>({coordinates:[{x:f.coord,y:0},{x:f.coord,y:o.height}]}));this.createFigure({name:"line",attrs:g,styles:d})?.draw(e);}}};var Zp="drawing_tools",Cn="__astroneumPluginRuntime";var li=class{_canvas;_gl;_vboCache=new Map;constructor(e){let t=document.createElement("canvas");t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.zIndex="1",t.style.pointerEvents="none",e.appendChild(t),this._canvas=t;let r=t.getContext("webgl2",{antialias:false,premultipliedAlpha:false,preserveDrawingBuffer:false,powerPreference:"high-performance",alpha:true});if(r===null)throw new Error("[IndicatorPluginWebGLRenderer] WebGL2 unavailable");this._gl=r,r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),r.disable(r.DEPTH_TEST),r.enable(r.SCISSOR_TEST);}getContext(){return this._gl}getOrCreateVbo(e){let t=this._vboCache.get(e);if(t===void 0){if(t=this._gl.createBuffer()??void 0,t===void 0)throw new Error("[IndicatorPluginWebGLRenderer] Failed to create buffer");this._vboCache.set(e,t);}return t}resize(e,t){let r=z(this._canvas),i=Math.round(e*r),o=Math.round(t*r);this._canvas.width===i&&this._canvas.height===o||(this._canvas.style.width=`${e}px`,this._canvas.style.height=`${t}px`,this._canvas.width=i,this._canvas.height=o);}beginFrame(){let e=this._gl,t=this._canvas.width,r=this._canvas.height;e.viewport(0,0,t,r),e.scissor(0,0,t,r),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);}destroy(){this._vboCache.forEach(e=>{this._gl.deleteBuffer(e);}),this._vboCache.clear(),this._gl.getExtension("WEBGL_lose_context")?.loseContext(),this._canvas.remove();}},Ft=new WeakMap;function Tn(n){return Ft.get(n)??null}function Sn(n,e){if(!pe.isSupported())return null;let t=Ft.get(n);if(t===void 0)try{t=new li(e),Ft.set(n,t);}catch{return null}return t}function An(n){let e=Ft.get(n);e!==void 0&&(e.destroy(),Ft.delete(n));}var yt=20,Lt=16,Sl=6,Pn=2166136261,Al=16777619,Pl=1024,wl=`#version 300 es
|
|
220
|
+
precision highp float;
|
|
221
|
+
|
|
222
|
+
// Per-instance attributes (divisor = 1)
|
|
223
|
+
in float a_x;
|
|
224
|
+
in float a_y;
|
|
225
|
+
in float a_width;
|
|
226
|
+
in float a_height;
|
|
227
|
+
in vec4 a_color; // RGBA, normalized
|
|
228
|
+
|
|
229
|
+
// Canvas physical dimensions; devicePixelRatio
|
|
230
|
+
uniform vec2 u_resolution;
|
|
231
|
+
uniform float u_pixelRatio;
|
|
232
|
+
|
|
233
|
+
out vec4 v_color;
|
|
234
|
+
|
|
235
|
+
// Unit-quad positions for 6 vertices (two CCW triangles):
|
|
236
|
+
// vi: 0 1 2 3 4 5
|
|
237
|
+
// uv: (0,0) (1,0) (0,1) (0,1) (1,0) (1,1)
|
|
238
|
+
vec2 unitQuad(int id) {
|
|
239
|
+
if (id == 0) return vec2(0.0, 0.0);
|
|
240
|
+
if (id == 1) return vec2(1.0, 0.0);
|
|
241
|
+
if (id == 2) return vec2(0.0, 1.0);
|
|
242
|
+
if (id == 3) return vec2(0.0, 1.0);
|
|
243
|
+
if (id == 4) return vec2(1.0, 0.0);
|
|
244
|
+
return vec2(1.0, 1.0);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
void main() {
|
|
248
|
+
vec2 uv = unitQuad(gl_VertexID % 6);
|
|
249
|
+
|
|
250
|
+
// CSS-pixel position of this vertex corner
|
|
251
|
+
vec2 cssPx = vec2(a_x + uv.x * a_width,
|
|
252
|
+
a_y + uv.y * a_height);
|
|
253
|
+
|
|
254
|
+
// CSS px \u2192 physical px \u2192 NDC (Y-flip: CSS Y=0 is top, NDC Y=+1 is top)
|
|
255
|
+
vec2 physPx = cssPx * u_pixelRatio;
|
|
256
|
+
gl_Position = vec4(
|
|
257
|
+
(physPx.x / u_resolution.x) * 2.0 - 1.0,
|
|
258
|
+
1.0 - (physPx.y / u_resolution.y) * 2.0,
|
|
259
|
+
0.0, 1.0
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
v_color = a_color;
|
|
263
|
+
}
|
|
264
|
+
`,El=`#version 300 es
|
|
265
|
+
precision mediump float;
|
|
266
|
+
in vec4 v_color;
|
|
267
|
+
out vec4 fragColor;
|
|
268
|
+
void main() { fragColor = v_color; }
|
|
269
|
+
`;function wn(n,e,t){let r=n.createShader(e);if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS))throw new Error(`[IndicatorRectWebGLRenderer] shader compile error: ${n.getShaderInfoLog(r)??"?"}`);return r}function Il(n){let e=wn(n,n.VERTEX_SHADER,wl),t=wn(n,n.FRAGMENT_SHADER,El),r=n.createProgram();if(n.attachShader(r,e),n.attachShader(r,t),n.linkProgram(r),n.deleteShader(e),n.deleteShader(t),!n.getProgramParameter(r,n.LINK_STATUS))throw new Error(`[IndicatorRectWebGLRenderer] program link error: ${n.getProgramInfoLog(r)??"?"}`);return r}var ci=class{_sharedCanvas;_gl;_program;_vao;_vbo;_uResolution;_uPixelRatio;_capacity=0;_rectCount=0;_stagingBuf=new ArrayBuffer(512*yt);_stagingF32=new Float32Array(this._stagingBuf);_stagingU8=new Uint8Array(this._stagingBuf);_colorCache=new Map;_colorHashCache=new Map;_fingerprintRectCount=-1;_fingerprintHash=0;_culledBuf=[];_vboVersion=0;_drawnVersion=-1;_lastSizeVersion=-1;constructor(e){this._sharedCanvas=e;let t=e.gl;this._gl=t,this._program=Il(t),t.useProgram(this._program),this._uResolution=t.getUniformLocation(this._program,"u_resolution"),this._uPixelRatio=t.getUniformLocation(this._program,"u_pixelRatio"),this._vao=t.createVertexArray(),t.bindVertexArray(this._vao),this._vbo=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._vbo),this._setupAttribs(t),t.bindVertexArray(null);}_setupAttribs(e){let t=this._program,r=yt,i=(a,s)=>{let l=e.getAttribLocation(t,a);l<0||(e.enableVertexAttribArray(l),e.vertexAttribPointer(l,1,e.FLOAT,false,r,s),e.vertexAttribDivisor(l,1));};i("a_x",0),i("a_y",4),i("a_width",8),i("a_height",12);let o=e.getAttribLocation(t,"a_color");o>=0&&(e.enableVertexAttribArray(o),e.vertexAttribPointer(o,4,e.UNSIGNED_BYTE,true,r,Lt),e.vertexAttribDivisor(o,1));}isDirty(){return this._vboVersion!==this._drawnVersion||this._lastSizeVersion!==this._sharedCanvas.sizeVersion}resize(e,t){this._sharedCanvas.resize(e,t);}_ensureCapacity(e){if(e<=this._capacity)return;let t=Math.max(e,this._capacity*2,512);this._stagingBuf=new ArrayBuffer(t*yt),this._stagingF32=new Float32Array(this._stagingBuf),this._stagingU8=new Uint8Array(this._stagingBuf);let r=this._gl;r.bindBuffer(r.ARRAY_BUFFER,this._vbo),r.bufferData(r.ARRAY_BUFFER,t*yt,r.DYNAMIC_DRAW),this._capacity=t;}_parseColorCached(e){return Te(e,this._colorCache)}_mixHash(e,t){return Math.imul(e^t,Al)>>>0}_hashQuantized(e){return Math.round(e*Pl)|0}_hashColorCached(e){let t=this._colorHashCache.get(e);if(t===void 0){t=Pn;for(let r=0;r<e.length;r++)t=this._mixHash(t,e.charCodeAt(r));this._colorHashCache.set(e,t);}return t}setData(e){let t=this._culledBuf,r=0,i=Pn;for(let c=0;c<e.length;c++){let u=e[c];u.width<.5||u.height<.5||(r>=t.length?t.push(u):t[r]=u,i=this._mixHash(i,this._hashQuantized(u.x)),i=this._mixHash(i,this._hashQuantized(u.y)),i=this._mixHash(i,this._hashQuantized(u.width)),i=this._mixHash(i,this._hashQuantized(u.height)),i=this._mixHash(i,this._hashColorCached(u.color)),r++);}let o=r;if(this._rectCount=o,o===0){this._fingerprintRectCount!==0&&this._vboVersion++,this._fingerprintRectCount=0,this._fingerprintHash=0;return}if(o===this._fingerprintRectCount&&i===this._fingerprintHash)return;this._fingerprintRectCount=o,this._fingerprintHash=i,this._ensureCapacity(o);let a=this._stagingF32,s=this._stagingU8;for(let c=0;c<o;c++){let u=t[c],h=c*4,d=c*yt;a[h+0]=u.x,a[h+1]=u.y,a[h+2]=u.width,a[h+3]=u.height;let m=this._parseColorCached(u.color);s[d+Lt]=m[0]*255+.5|0,s[d+Lt+1]=m[1]*255+.5|0,s[d+Lt+2]=m[2]*255+.5|0,s[d+Lt+3]=m[3]*255+.5|0;}let l=this._gl;l.bindBuffer(l.ARRAY_BUFFER,this._vbo),l.bufferSubData(l.ARRAY_BUFFER,0,this._stagingU8,0,o*yt),this._vboVersion++;}draw(){let e=this._sharedCanvas,t=e.canvas,r=this._gl,i=z(t),o=t.width,a=t.height;this._drawnVersion=this._vboVersion,this._lastSizeVersion=e.sizeVersion,this._rectCount!==0&&(r.useProgram(this._program),r.uniform2f(this._uResolution,o,a),r.uniform1f(this._uPixelRatio,i),r.bindVertexArray(this._vao),r.drawArraysInstanced(r.TRIANGLES,0,Sl,this._rectCount),r.bindVertexArray(null));}destroy(){let e=this._gl;e.deleteVertexArray(this._vao),e.deleteBuffer(this._vbo),e.deleteProgram(this._program);}},Bt=new WeakMap;function En(n){return Bt.get(n)??null}function In(n,e){let t=Bt.get(n);return t===void 0&&(t=new ci(e),Bt.set(n,t)),t}function Rn(n){let e=Bt.get(n);e!==void 0&&(e.destroy(),Bt.delete(n));}function Dn(n){let{style:e,color:t,borderRadius:r,borderSize:i,borderColor:o}=n;return !(e!==void 0&&e!=="fill"||typeof t!="string"||t==="transparent"||t===""||r!==void 0&&r!==0||i!==void 0&&i>0&&typeof o=="string"&&o!=="transparent")}var Ge=class extends J{eachChildren(e){let r=this.getWidget().getPane().getChart().getChartStore(),i=r.getVisibleRangeDataList(),o=r.getBarSpace(),a=i.length,s=0;for(;s<a;)e(i[s],o,s),++s;}};function kn(n,e,t){let r=n.createShader(e);if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS)){let i=n.getShaderInfoLog(r)??"unknown";throw n.deleteShader(r),new Error(`[CandleWebGLRenderer] shader compile error: ${i}`)}return r}function Rl(n){let e=kn(n,n.VERTEX_SHADER,Er),t=kn(n,n.FRAGMENT_SHADER,Ir),r=n.createProgram();if(n.attachShader(r,e),n.attachShader(r,t),n.linkProgram(r),n.deleteShader(e),n.deleteShader(t),!n.getProgramParameter(r,n.LINK_STATUS))throw new Error(`[CandleWebGLRenderer] program link error: ${n.getProgramInfoLog(r)??"unknown"}`);return r}var ui=class{_gl;_canvas;_program;_vao;_vbo;_uPriceFrom;_uPriceRange;_uResolution;_uPixelRatio;_uBarHalfWidth;_uRenderMode;_uOhlcHalfSize;_uPanOffset;_capacity=0;_barCount=0;_stagingBuf=new ArrayBuffer(512*32);_stagingF32=new Float32Array(this._stagingBuf);_stagingU8=new Uint8Array(this._stagingBuf);_singleBarBuf=new ArrayBuffer(32);_singleBarF32=new Float32Array(this._singleBarBuf);_singleBarU8=new Uint8Array(this._singleBarBuf);_colorCache=new Map;_fingerprintBarCount=-1;_fingerprintFirstX=0;_fingerprintLastX=0;_fingerprintLastClose=0;_fingerprintLastBodyColor="";_fingerprintFirstOpen=NaN;_fingerprintFirstClose=NaN;_fingerprintBarStep=0;_panOffsetCss=0;_vboVersion=0;_drawnVersion=-1;_lastPriceFrom=NaN;_lastPriceRange=NaN;_lastBarHalfWidth=NaN;_lastRenderMode=-1;_lastOhlcHalfSize=NaN;_vboFirstDataIdx=-1;_vboLastDataIdx=-1;_vboBar0X=0;_vboBarStep=0;_drawStartOffset=0;_visibleBarCount=0;_lastDrawStartOffset=-1;_canvasWidthCss=0;_lodActive=false;_lodBuf=[];_timerExt=null;_timerQuery=null;_timerQueryActive=false;constructor(e){let t=document.createElement("canvas");t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.zIndex="1",t.style.pointerEvents="none",e.appendChild(t),this._canvas=t;let r=t.getContext("webgl2",{antialias:false,premultipliedAlpha:false,preserveDrawingBuffer:false,powerPreference:"high-performance",alpha:true});if(r===null)throw new Error("[CandleWebGLRenderer] WebGL2 unavailable");if(this._gl=r,r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),r.disable(r.DEPTH_TEST),r.enable(r.SCISSOR_TEST),this._program=Rl(r),r.useProgram(this._program),this._uPriceFrom=r.getUniformLocation(this._program,"u_priceFrom"),this._uPriceRange=r.getUniformLocation(this._program,"u_priceRange"),this._uResolution=r.getUniformLocation(this._program,"u_resolution"),this._uPixelRatio=r.getUniformLocation(this._program,"u_pixelRatio"),this._uRenderMode=r.getUniformLocation(this._program,"u_renderMode"),this._uOhlcHalfSize=r.getUniformLocation(this._program,"u_ohlcHalfSize"),this._uBarHalfWidth=r.getUniformLocation(this._program,"u_barHalfWidth"),this._uPanOffset=r.getUniformLocation(this._program,"u_panOffset"),this._vao=r.createVertexArray(),r.bindVertexArray(this._vao),this._vbo=r.createBuffer(),r.bindBuffer(r.ARRAY_BUFFER,this._vbo),this._setupAttribs(r),r.bindVertexArray(null),import.meta.env?.DEV){let i=r.getExtension("EXT_disjoint_timer_query_webgl2");i!==null&&(this._timerExt=i,this._timerQuery=r.createQuery());}}_parseColorCached(e){return Te(e,this._colorCache)}_packColor(e,t,r){ft(e,t,r);}_writeBarIntoViews(e,t,r,i,o){t[i+0]=e.centerX-this._panOffsetCss,t[i+1]=e.open,t[i+2]=e.high,t[i+3]=e.low,t[i+4]=e.close,this._packColor(this._parseColorCached(e.wickColor),r,o+20),this._packColor(this._parseColorCached(e.bodyColor),r,o+20+4),this._packColor(this._parseColorCached(e.borderColor),r,o+20+8);}_setupAttribs(e){this._rebindAttribsWithOffset(e,0);}_rebindAttribsWithOffset(e,t){let r=this._program,i=32,o=(s,l)=>{let c=e.getAttribLocation(r,s);c<0||(e.enableVertexAttribArray(c),e.vertexAttribPointer(c,1,e.FLOAT,false,i,t+l),e.vertexAttribDivisor(c,1));},a=(s,l)=>{let c=e.getAttribLocation(r,s);c<0||(e.enableVertexAttribArray(c),e.vertexAttribPointer(c,4,e.UNSIGNED_BYTE,true,i,t+l),e.vertexAttribDivisor(c,1));};o("a_centerX",0),o("a_open",4),o("a_high",8),o("a_low",12),o("a_close",16),a("a_wickColor",20),a("a_bodyColor",24),a("a_borderColor",28);}resize(e,t){this._canvasWidthCss=e;let r=z(this._canvas),i=Math.round(e*r),o=Math.round(t*r);this._canvas.width===i&&this._canvas.height===o||(this._canvas.style.width=`${e}px`,this._canvas.style.height=`${t}px`,this._canvas.width=i,this._canvas.height=o,this._vboVersion++);}_applyLod(e,t){for(;this._lodBuf.length<t;)this._lodBuf.push({centerX:0,open:0,high:0,low:0,close:0,wickColor:"",bodyColor:"",borderColor:""});let r=e.length,i=r/t;for(let o=0;o<t;o++){let a=Math.floor(o*i),s=Math.min(Math.floor((o+1)*i)-1,r-1),l=e[a],c=e[s],u=l.high,h=l.low;for(let m=a+1;m<=s;m++){let p=e[m];p.high>u&&(u=p.high),p.low<h&&(h=p.low);}let d=this._lodBuf[o];d.centerX=l.centerX,d.open=l.open,d.high=u,d.low=h,d.close=c.close,d.wickColor=c.wickColor,d.bodyColor=c.bodyColor,d.borderColor=c.borderColor;}}_ensureCapacity(e){if(e<=this._capacity)return;let t=Math.max(e,this._capacity*2,512);this._stagingBuf=new ArrayBuffer(t*32),this._stagingF32=new Float32Array(this._stagingBuf),this._stagingU8=new Uint8Array(this._stagingBuf);let r=this._gl;r.bindBuffer(r.ARRAY_BUFFER,this._vbo),r.bufferData(r.ARRAY_BUFFER,t*32,r.DYNAMIC_DRAW),this._capacity=t;}setData(e,t=0,r=e.length){if(!this._lodActive&&t>0&&r>0&&t+r<=e.length&&this._barCount>0&&this._vboFirstDataIdx>=0&&this._vboBarStep!==0){let f=e[t],v=e[t+r-1];if(f.dataIndex!==void 0&&v.dataIndex!==void 0&&f.dataIndex>=this._vboFirstDataIdx&&v.dataIndex<=this._vboLastDataIdx&&(r<2||e[t+1].centerX-f.centerX===this._vboBarStep)){let y=f.dataIndex-this._vboFirstDataIdx,b=this._vboBar0X+y*this._vboBarStep;this._panOffsetCss=f.centerX-b,this._drawStartOffset=y,this._visibleBarCount=r,this._fingerprintBarCount=r,this._fingerprintFirstX=f.centerX,this._fingerprintLastX=v.centerX,this._fingerprintLastClose=v.close,this._fingerprintLastBodyColor=v.bodyColor,this._fingerprintFirstOpen=f.open,this._fingerprintFirstClose=f.close,this._fingerprintBarStep=r>=2?e[t+1].centerX-f.centerX:this._fingerprintBarStep,this._vboVersion++;return}}let i=1.5,o,a=Math.min(r,e.length-t);if(this._canvasWidthCss>0&&a>this._canvasWidthCss*i){let f=Math.max(1,Math.floor(this._canvasWidthCss)),v=t===0&&a===e.length?e:e.slice(t,t+a);this._applyLod(v,f),o=this._lodBuf,this._lodActive=true;}else o=e,this._lodActive=false;let s=o.length;if(this._barCount=s,s===0){this._fingerprintBarCount=0;return}let l=this._lodActive?0:t,c=this._lodActive?s:Math.min(r,s-t);if(c===0){this._fingerprintBarCount=0;return}let u=o[l],h=o[l+c-1];if(c===this._fingerprintBarCount&&u.centerX===this._fingerprintFirstX&&h.centerX===this._fingerprintLastX&&h.close===this._fingerprintLastClose&&h.bodyColor===this._fingerprintLastBodyColor)return;let d=c>=2?o[l+1].centerX-u.centerX:this._fingerprintBarStep;if(c===this._fingerprintBarCount&&h.close===this._fingerprintLastClose&&h.bodyColor===this._fingerprintLastBodyColor&&u.open===this._fingerprintFirstOpen&&u.close===this._fingerprintFirstClose&&d===this._fingerprintBarStep){this._panOffsetCss+=u.centerX-this._fingerprintFirstX,this._fingerprintFirstX=u.centerX,this._fingerprintLastX=h.centerX,this._vboVersion++;return}this._panOffsetCss=0,this._fingerprintBarCount=c,this._fingerprintFirstX=u.centerX,this._fingerprintLastX=h.centerX,this._fingerprintLastClose=h.close,this._fingerprintLastBodyColor=h.bodyColor,this._fingerprintFirstOpen=u.open,this._fingerprintFirstClose=u.close,this._fingerprintBarStep=d,this._vboFirstDataIdx=o[0].dataIndex??-1,this._vboLastDataIdx=o[s-1].dataIndex??-1,this._vboBar0X=o[0].centerX,this._vboBarStep=d,this._drawStartOffset=this._lodActive?0:t,this._visibleBarCount=this._lodActive?s:c,this._ensureCapacity(s);let m=this._stagingF32,p=this._stagingU8;for(let f=0;f<s;f++)this._writeBarIntoViews(o[f],m,p,f<<3,f*32);let g=this._gl;g.bindBuffer(g.ARRAY_BUFFER,this._vbo),g.bufferSubData(g.ARRAY_BUFFER,0,this._stagingU8,0,s*32),this._vboVersion++;}updateLastBar(e){if(this._barCount===0||this._lodActive)return;this._fingerprintLastClose=e.close,this._writeBarIntoViews(e,this._singleBarF32,this._singleBarU8,0,0);let t=this._gl;t.bindBuffer(t.ARRAY_BUFFER,this._vbo);let r=this._visibleBarCount>0?this._drawStartOffset+this._visibleBarCount-1:this._barCount-1;t.bufferSubData(t.ARRAY_BUFFER,r*32,this._singleBarBuf),this._vboVersion++;}draw(e,t,r,i=0,o=0){if(this._barCount===0||this._vboVersion===this._drawnVersion&&e===this._lastPriceFrom&&t===this._lastPriceRange&&r===this._lastBarHalfWidth&&i===this._lastRenderMode&&o===this._lastOhlcHalfSize)return;this._drawnVersion=this._vboVersion,this._lastPriceFrom=e,this._lastPriceRange=t,this._lastBarHalfWidth=r,this._lastRenderMode=i,this._lastOhlcHalfSize=o;let a=this._gl,s=z(this._canvas),l=this._canvas.width,c=this._canvas.height;if(this._timerExt!==null&&this._timerQuery!==null){if(this._timerQueryActive&&!a.getParameter(this._timerExt.GPU_DISJOINT_EXT)&&a.getQueryParameter(this._timerQuery,a.QUERY_RESULT_AVAILABLE)){let g=a.getQueryParameter(this._timerQuery,a.QUERY_RESULT)/1e6;g>4&&console.warn(`[CandleWebGLRenderer] GPU frame ${g.toFixed(2)} ms (budget: 4 ms @ 60 fps)`);}a.beginQuery(this._timerExt.TIME_ELAPSED_EXT,this._timerQuery),this._timerQueryActive=true;}a.viewport(0,0,l,c),a.scissor(0,0,l,c),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT),a.useProgram(this._program),a.uniform1f(this._uPriceFrom,e),a.uniform1f(this._uPriceRange,t),a.uniform2f(this._uResolution,l,c),a.uniform1f(this._uPixelRatio,s),a.uniform1f(this._uBarHalfWidth,r),a.uniform1i(this._uRenderMode,i),a.uniform1f(this._uOhlcHalfSize,o),a.uniform1f(this._uPanOffset,this._panOffsetCss),a.bindVertexArray(this._vao);let u=this._drawStartOffset*32;this._drawStartOffset!==this._lastDrawStartOffset&&(a.bindBuffer(a.ARRAY_BUFFER,this._vbo),this._rebindAttribsWithOffset(a,u),this._lastDrawStartOffset=this._drawStartOffset);let h=this._visibleBarCount>0?this._visibleBarCount:this._barCount;a.drawArraysInstanced(a.TRIANGLES,0,18,h),a.bindVertexArray(null),this._timerExt!==null&&this._timerQuery!==null&&this._timerQueryActive&&a.endQuery(this._timerExt.TIME_ELAPSED_EXT);}destroy(){let e=this._gl;this._timerQuery!==null&&e.deleteQuery(this._timerQuery),e.deleteVertexArray(this._vao),e.deleteBuffer(this._vbo),e.deleteProgram(this._program),e.getExtension("WEBGL_lose_context")?.loseContext(),this._canvas.remove();}static isSupported(){return pe.isSupported()}},Dr=new WeakMap;function Mn(n,e){if(!pe.isSupported())return null;let t=Dr.get(n);if(t===void 0)try{t=new ui(e),Dr.set(n,t);}catch{return null}return t}function kr(n){let e=Dr.get(n);e!==void 0&&(e.destroy(),Dr.delete(n));}function Dl(){return `'use strict';
|
|
270
|
+
const BYTES_PER_BAR = ${32};
|
|
271
|
+
const COLOR_BYTE_OFF = ${20};
|
|
272
|
+
const VERTS_PER_BAR = ${18};
|
|
273
|
+
const VERT_SRC = ${JSON.stringify(Er)};
|
|
274
|
+
const FRAG_SRC = ${JSON.stringify(Ir)};
|
|
275
|
+
|
|
276
|
+
// P1-A: SharedArrayBuffer zero-copy VBO \u2014 set when main thread sends SAB at init
|
|
277
|
+
let sabU8 = null;
|
|
278
|
+
|
|
279
|
+
let gl, program, vao, vbo, capacity = 0;
|
|
280
|
+
let uPriceFrom, uPriceRange, uResolution, uPixelRatio,
|
|
281
|
+
uBarHalfWidth, uRenderMode, uOhlcHalfSize, uPanOffset;
|
|
282
|
+
|
|
283
|
+
function compile(type, src) {
|
|
284
|
+
const s = gl.createShader(type);
|
|
285
|
+
gl.shaderSource(s, src);
|
|
286
|
+
gl.compileShader(s);
|
|
287
|
+
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) {
|
|
288
|
+
const msg = gl.getShaderInfoLog(s) || 'unknown';
|
|
289
|
+
gl.deleteShader(s);
|
|
290
|
+
throw new Error('[CandleWorker] shader compile error: ' + msg);
|
|
291
|
+
}
|
|
292
|
+
return s;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function init(canvas, sab) {
|
|
296
|
+
if (sab) sabU8 = new Uint8Array(sab);
|
|
297
|
+
gl = canvas.getContext('webgl2', {
|
|
298
|
+
antialias: false,
|
|
299
|
+
premultipliedAlpha: false,
|
|
300
|
+
preserveDrawingBuffer: false,
|
|
301
|
+
powerPreference: 'high-performance',
|
|
302
|
+
alpha: true
|
|
303
|
+
});
|
|
304
|
+
if (!gl) {
|
|
305
|
+
self.postMessage({ type: 'error', msg: 'WebGL2 unavailable in worker' });
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
gl.enable(gl.BLEND);
|
|
310
|
+
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
311
|
+
gl.disable(gl.DEPTH_TEST);
|
|
312
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
313
|
+
|
|
314
|
+
const vert = compile(gl.VERTEX_SHADER, VERT_SRC);
|
|
315
|
+
const frag = compile(gl.FRAGMENT_SHADER, FRAG_SRC);
|
|
316
|
+
program = gl.createProgram();
|
|
317
|
+
gl.attachShader(program, vert);
|
|
318
|
+
gl.attachShader(program, frag);
|
|
319
|
+
gl.linkProgram(program);
|
|
320
|
+
gl.deleteShader(vert);
|
|
321
|
+
gl.deleteShader(frag);
|
|
322
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
323
|
+
self.postMessage({ type: 'error', msg: '[CandleWorker] link error: ' + (gl.getProgramInfoLog(program) || 'unknown') });
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
gl.useProgram(program);
|
|
327
|
+
|
|
328
|
+
uPriceFrom = gl.getUniformLocation(program, 'u_priceFrom');
|
|
329
|
+
uPriceRange = gl.getUniformLocation(program, 'u_priceRange');
|
|
330
|
+
uResolution = gl.getUniformLocation(program, 'u_resolution');
|
|
331
|
+
uPixelRatio = gl.getUniformLocation(program, 'u_pixelRatio');
|
|
332
|
+
uBarHalfWidth = gl.getUniformLocation(program, 'u_barHalfWidth');
|
|
333
|
+
uRenderMode = gl.getUniformLocation(program, 'u_renderMode');
|
|
334
|
+
uOhlcHalfSize = gl.getUniformLocation(program, 'u_ohlcHalfSize');
|
|
335
|
+
uPanOffset = gl.getUniformLocation(program, 'u_panOffset');
|
|
336
|
+
|
|
337
|
+
vao = gl.createVertexArray();
|
|
338
|
+
gl.bindVertexArray(vao);
|
|
339
|
+
vbo = gl.createBuffer();
|
|
340
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
341
|
+
|
|
342
|
+
const stride = BYTES_PER_BAR;
|
|
343
|
+
function bindF32(name, offset) {
|
|
344
|
+
const loc = gl.getAttribLocation(program, name);
|
|
345
|
+
if (loc < 0) return;
|
|
346
|
+
gl.enableVertexAttribArray(loc);
|
|
347
|
+
gl.vertexAttribPointer(loc, 1, gl.FLOAT, false, stride, offset);
|
|
348
|
+
gl.vertexAttribDivisor(loc, 1);
|
|
349
|
+
}
|
|
350
|
+
function bindU8Color(name, offset) {
|
|
351
|
+
const loc = gl.getAttribLocation(program, name);
|
|
352
|
+
if (loc < 0) return;
|
|
353
|
+
gl.enableVertexAttribArray(loc);
|
|
354
|
+
gl.vertexAttribPointer(loc, 4, gl.UNSIGNED_BYTE, true, stride, offset);
|
|
355
|
+
gl.vertexAttribDivisor(loc, 1);
|
|
356
|
+
}
|
|
357
|
+
bindF32 ('a_centerX', 0);
|
|
358
|
+
bindF32 ('a_open', 4);
|
|
359
|
+
bindF32 ('a_high', 8);
|
|
360
|
+
bindF32 ('a_low', 12);
|
|
361
|
+
bindF32 ('a_close', 16);
|
|
362
|
+
bindU8Color ('a_wickColor', 20);
|
|
363
|
+
bindU8Color ('a_bodyColor', 24);
|
|
364
|
+
bindU8Color ('a_borderColor', 28);
|
|
365
|
+
gl.bindVertexArray(null);
|
|
366
|
+
|
|
367
|
+
self.postMessage({ type: 'ready' });
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
self.onmessage = function(e) {
|
|
371
|
+
const msg = e.data;
|
|
372
|
+
switch (msg.type) {
|
|
373
|
+
case 'init':
|
|
374
|
+
try { init(msg.canvas, msg.sab); }
|
|
375
|
+
catch (err) { self.postMessage({ type: 'error', msg: String(err) }); }
|
|
376
|
+
break;
|
|
377
|
+
|
|
378
|
+
case 'upload': {
|
|
379
|
+
// Full VBO upload \u2014 bytes is a structured-clone of the staging Uint8Array.
|
|
380
|
+
const { bytes, count } = msg;
|
|
381
|
+
const byteLen = count * BYTES_PER_BAR;
|
|
382
|
+
if (count > capacity) {
|
|
383
|
+
const newCap = Math.max(count, capacity * 2, 512);
|
|
384
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
385
|
+
gl.bufferData(gl.ARRAY_BUFFER, newCap * BYTES_PER_BAR, gl.DYNAMIC_DRAW);
|
|
386
|
+
capacity = newCap;
|
|
387
|
+
}
|
|
388
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
389
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, bytes, 0, byteLen);
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
case 'uploadSAB': {
|
|
394
|
+
// P1-A: Zero-copy path \u2014 read directly from SharedArrayBuffer.
|
|
395
|
+
// Main thread already packed data into sabU8; we just upload it.
|
|
396
|
+
const { count } = msg;
|
|
397
|
+
if (!sabU8 || count === 0) break;
|
|
398
|
+
const byteLen = count * BYTES_PER_BAR;
|
|
399
|
+
if (count > capacity) {
|
|
400
|
+
const newCap = Math.max(count, capacity * 2, 512);
|
|
401
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
402
|
+
gl.bufferData(gl.ARRAY_BUFFER, newCap * BYTES_PER_BAR, gl.DYNAMIC_DRAW);
|
|
403
|
+
capacity = newCap;
|
|
404
|
+
}
|
|
405
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
406
|
+
// Create a view over the SAB slice \u2014 no copy
|
|
407
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, sabU8, 0, byteLen);
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
case 'uploadPartial': {
|
|
412
|
+
// Partial update for the last bar (live tick optimisation).
|
|
413
|
+
const { bytes, byteOffset } = msg;
|
|
414
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
415
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, byteOffset, bytes);
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
case 'draw': {
|
|
420
|
+
const {
|
|
421
|
+
barCount, priceFrom, priceRange, barHalfWidth,
|
|
422
|
+
renderMode, ohlcHalfSize, panOffset,
|
|
423
|
+
physW, physH, pixelRatio
|
|
424
|
+
} = msg;
|
|
425
|
+
if (barCount === 0) return;
|
|
426
|
+
gl.viewport(0, 0, physW, physH);
|
|
427
|
+
gl.scissor(0, 0, physW, physH);
|
|
428
|
+
gl.clearColor(0, 0, 0, 0);
|
|
429
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
430
|
+
gl.useProgram(program);
|
|
431
|
+
gl.uniform1f(uPriceFrom, priceFrom);
|
|
432
|
+
gl.uniform1f(uPriceRange, priceRange);
|
|
433
|
+
gl.uniform2f(uResolution, physW, physH);
|
|
434
|
+
gl.uniform1f(uPixelRatio, pixelRatio);
|
|
435
|
+
gl.uniform1f(uBarHalfWidth, barHalfWidth);
|
|
436
|
+
gl.uniform1i(uRenderMode, renderMode);
|
|
437
|
+
gl.uniform1f(uOhlcHalfSize, ohlcHalfSize);
|
|
438
|
+
gl.uniform1f(uPanOffset, panOffset);
|
|
439
|
+
gl.bindVertexArray(vao);
|
|
440
|
+
gl.drawArraysInstanced(gl.TRIANGLES, 0, VERTS_PER_BAR, barCount);
|
|
441
|
+
gl.bindVertexArray(null);
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
case 'resize': {
|
|
446
|
+
const { physW, physH } = msg;
|
|
447
|
+
const canvas = gl.canvas;
|
|
448
|
+
if (canvas.width !== physW || canvas.height !== physH) {
|
|
449
|
+
canvas.width = physW;
|
|
450
|
+
canvas.height = physH;
|
|
451
|
+
}
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
case 'destroy': {
|
|
456
|
+
gl.deleteVertexArray(vao);
|
|
457
|
+
gl.deleteBuffer(vbo);
|
|
458
|
+
gl.deleteProgram(program);
|
|
459
|
+
const ext = gl.getExtension('WEBGL_lose_context');
|
|
460
|
+
if (ext) ext.loseContext();
|
|
461
|
+
self.close();
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
`}var hi=null;function kl(){return hi===null&&(hi=Dl()),hi}var Mr=class{_canvas;_worker;_workerReady=false;_sab;_sabF32;_sabU8;_capacity=0;_stagingBuf=new ArrayBuffer(0);_stagingF32=new Float32Array(0);_stagingU8=new Uint8Array(0);_singleBarBuf=new ArrayBuffer(32);_singleBarF32=new Float32Array(this._singleBarBuf);_singleBarU8=new Uint8Array(this._singleBarBuf);_colorCache=new Map;_canvasWidthCss=0;_lodActive=false;_lodBuf=[];_fingerprintBarCount=-1;_fingerprintFirstX=0;_fingerprintLastX=0;_fingerprintLastClose=0;_fingerprintLastBodyColor="";_fingerprintFirstOpen=NaN;_fingerprintFirstClose=NaN;_fingerprintBarStep=0;_panOffsetCss=0;_barCount=0;_vboVersion=0;_drawnVersion=-1;_lastPriceFrom=NaN;_lastPriceRange=NaN;_lastBarHalfWidth=NaN;_lastRenderMode=-1;_lastOhlcHalfSize=NaN;_physW=0;_physH=0;_pixelRatio=1;constructor(e){let t=document.createElement("canvas");t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.zIndex="1",t.style.pointerEvents="none",e.appendChild(t),this._canvas=t;let r=65536;typeof SharedArrayBuffer<"u"&&globalThis.crossOriginIsolated===true?(this._sab=new SharedArrayBuffer(r*32),this._sabF32=new Float32Array(this._sab),this._sabU8=new Uint8Array(this._sab)):(this._sab=null,this._sabF32=null,this._sabU8=null);let i=new Blob([kl()],{type:"application/javascript"}),o=URL.createObjectURL(i),a=new Worker(o);URL.revokeObjectURL(o),this._worker=a,a.onerror=l=>{console.error("[CandleWorkerRenderer] worker error",l.message);},a.onmessage=l=>{l.data.type==="ready"&&(this._workerReady=true),l.data.type==="error"&&console.error("[CandleWorkerRenderer] worker reported error:",l.data.msg);};let s=t.transferControlToOffscreen();a.postMessage({type:"init",canvas:s,sab:this._sab},[s]);}_parseColorCached(e){return Te(e,this._colorCache)}_packColor(e,t,r){ft(e,t,r);}_writeBarIntoViews(e,t,r,i,o){t[i+0]=e.centerX-this._panOffsetCss,t[i+1]=e.open,t[i+2]=e.high,t[i+3]=e.low,t[i+4]=e.close,this._packColor(this._parseColorCached(e.wickColor),r,o+20),this._packColor(this._parseColorCached(e.bodyColor),r,o+20+4),this._packColor(this._parseColorCached(e.borderColor),r,o+20+8);}_applyLod(e,t){for(;this._lodBuf.length<t;)this._lodBuf.push({centerX:0,open:0,high:0,low:0,close:0,wickColor:"",bodyColor:"",borderColor:""});let r=e.length,i=r/t;for(let o=0;o<t;o++){let a=Math.floor(o*i),s=Math.min(Math.floor((o+1)*i)-1,r-1),l=e[a],c=e[s],u=l.high,h=l.low;for(let m=a+1;m<=s;m++){let p=e[m];p.high>u&&(u=p.high),p.low<h&&(h=p.low);}let d=this._lodBuf[o];d.centerX=l.centerX,d.open=l.open,d.high=u,d.low=h,d.close=c.close,d.wickColor=c.wickColor,d.bodyColor=c.bodyColor,d.borderColor=c.borderColor;}}_ensureCapacity(e){if(e<=this._capacity)return;let t=Math.max(e,this._capacity*2,512);this._stagingBuf=new ArrayBuffer(t*32),this._stagingF32=new Float32Array(this._stagingBuf),this._stagingU8=new Uint8Array(this._stagingBuf),this._capacity=t;}setData(e){if(!this._workerReady)return;let t=1.5,r;if(this._canvasWidthCss>0&&e.length>this._canvasWidthCss*t){let u=Math.max(1,Math.floor(this._canvasWidthCss));this._applyLod(e,u),r=this._lodBuf,this._lodActive=true;}else r=e,this._lodActive=false;let i=r.length;if(this._barCount=i,i===0){this._fingerprintBarCount=0;return}let o=r[0],a=r[i-1];if(i===this._fingerprintBarCount&&o.centerX===this._fingerprintFirstX&&a.centerX===this._fingerprintLastX&&a.close===this._fingerprintLastClose&&a.bodyColor===this._fingerprintLastBodyColor)return;let s=i>=2?r[1].centerX-o.centerX:this._fingerprintBarStep;if(i===this._fingerprintBarCount&&a.close===this._fingerprintLastClose&&a.bodyColor===this._fingerprintLastBodyColor&&o.open===this._fingerprintFirstOpen&&o.close===this._fingerprintFirstClose&&s===this._fingerprintBarStep){this._panOffsetCss+=o.centerX-this._fingerprintFirstX,this._fingerprintFirstX=o.centerX,this._fingerprintLastX=a.centerX,this._vboVersion++;return}this._panOffsetCss=0,this._fingerprintBarCount=i,this._fingerprintFirstX=o.centerX,this._fingerprintLastX=a.centerX,this._fingerprintLastClose=a.close,this._fingerprintLastBodyColor=a.bodyColor,this._fingerprintFirstOpen=o.open,this._fingerprintFirstClose=o.close,this._fingerprintBarStep=s,this._ensureCapacity(i);let l=this._stagingF32,c=this._stagingU8;for(let u=0;u<i;u++)this._writeBarIntoViews(r[u],l,c,u<<3,u*32);if(this._sabU8!==null&&i*32<=this._sab.byteLength)this._sabU8.set(c.subarray(0,i*32)),this._worker.postMessage({type:"uploadSAB",count:i});else {let u=i*32,h=this._stagingU8.slice(0,u);this._worker.postMessage({type:"upload",bytes:h,count:i});}this._vboVersion++;}updateLastBar(e){if(this._barCount===0||this._lodActive||!this._workerReady)return;this._fingerprintLastClose=e.close,this._writeBarIntoViews(e,this._singleBarF32,this._singleBarU8,0,0);let t=(this._barCount-1)*32,r=this._singleBarU8.slice();this._worker.postMessage({type:"uploadPartial",bytes:r,byteOffset:t}),this._vboVersion++;}resize(e,t){this._canvasWidthCss=e;let r=z(this._canvas),i=Math.round(e*r),o=Math.round(t*r);this._canvas.style.width=`${e}px`,this._canvas.style.height=`${t}px`,!(i===this._physW&&o===this._physH&&r===this._pixelRatio)&&(this._physW=i,this._physH=o,this._pixelRatio=r,this._workerReady&&this._worker.postMessage({type:"resize",physW:i,physH:o}),this._vboVersion++);}draw(e,t,r,i=0,o=0){this._barCount===0||!this._workerReady||this._vboVersion===this._drawnVersion&&e===this._lastPriceFrom&&t===this._lastPriceRange&&r===this._lastBarHalfWidth&&i===this._lastRenderMode&&o===this._lastOhlcHalfSize||(this._drawnVersion=this._vboVersion,this._lastPriceFrom=e,this._lastPriceRange=t,this._lastBarHalfWidth=r,this._lastRenderMode=i,this._lastOhlcHalfSize=o,this._worker.postMessage({type:"draw",barCount:this._barCount,priceFrom:e,priceRange:t,barHalfWidth:r,renderMode:i,ohlcHalfSize:o,panOffset:this._panOffsetCss,physW:this._physW,physH:this._physH,pixelRatio:this._pixelRatio}));}destroy(){this._workerReady?this._worker.postMessage({type:"destroy"}):this._worker.terminate(),this._canvas.remove();}static isSupported(){return pe.isSupported()&&typeof OffscreenCanvas<"u"&&typeof Worker<"u"}},Ot=new WeakMap;function Fn(n,e){if(!Mr.isSupported())return null;let t=Ot.get(n);if(t===void 0)try{t=new Mr(e),Ot.set(n,t);}catch{return null}return t}function Ln(n){return Ot.get(n)??null}function Fr(n){let e=Ot.get(n);e!==void 0&&(e.destroy(),Ot.delete(n));}var Nt=null,Vt=null;async function Ml(){return Nt!==null&&!Nt.lost?Nt:(Vt!==null||(Vt=(async()=>{let n=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(n===null)throw new Error("[CandleWebGPURenderer] No GPU adapter");let e=[];n.features.has("timestamp-query")&&e.push("timestamp-query");let t=await n.requestDevice({requiredFeatures:e});return t.lost.then(()=>{Nt=null,Vt=null;}).catch(()=>{}),Nt=t,t})()),Vt)}var Fl=`
|
|
467
|
+
struct Uniforms {
|
|
468
|
+
priceFrom : f32,
|
|
469
|
+
priceRange : f32,
|
|
470
|
+
resolutionX : f32,
|
|
471
|
+
resolutionY : f32,
|
|
472
|
+
pixelRatio : f32,
|
|
473
|
+
barHalfWidth : f32,
|
|
474
|
+
renderMode : u32, // 0 = candle, 1 = ohlc
|
|
475
|
+
ohlcHalfSize : f32,
|
|
476
|
+
panOffset : f32,
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
@group(0) @binding(0) var<uniform> u : Uniforms;
|
|
480
|
+
|
|
481
|
+
struct InstanceIn {
|
|
482
|
+
@location(0) centerX : f32,
|
|
483
|
+
@location(1) open : f32,
|
|
484
|
+
@location(2) high : f32,
|
|
485
|
+
@location(3) low : f32,
|
|
486
|
+
@location(4) close : f32,
|
|
487
|
+
@location(5) wickColor : vec4<f32>, // normalised [0,1]
|
|
488
|
+
@location(6) bodyColor : vec4<f32>,
|
|
489
|
+
@location(7) borderColor : vec4<f32>,
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
struct VertOut {
|
|
493
|
+
@builtin(position) pos : vec4<f32>,
|
|
494
|
+
@location(0) color : vec4<f32>,
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Unit-quad vertex for a 2-triangle (6-vert) quad.
|
|
498
|
+
fn unitQuad(id: u32) -> vec2<f32> {
|
|
499
|
+
switch id {
|
|
500
|
+
case 0u: { return vec2(0.0, 0.0); }
|
|
501
|
+
case 1u: { return vec2(1.0, 0.0); }
|
|
502
|
+
case 2u: { return vec2(0.0, 1.0); }
|
|
503
|
+
case 3u: { return vec2(0.0, 1.0); }
|
|
504
|
+
case 4u: { return vec2(1.0, 0.0); }
|
|
505
|
+
default: { return vec2(1.0, 1.0); }
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
fn priceToPhysY(price: f32) -> f32 {
|
|
510
|
+
let rate = (price - u.priceFrom) / u.priceRange;
|
|
511
|
+
return (1.0 - rate) * u.resolutionY;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
fn physToNdc(x: f32, y: f32) -> vec4<f32> {
|
|
515
|
+
return vec4(
|
|
516
|
+
x / u.resolutionX * 2.0 - 1.0,
|
|
517
|
+
1.0 - y / u.resolutionY * 2.0,
|
|
518
|
+
0.0, 1.0
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
@vertex
|
|
523
|
+
fn vs_main(inst: InstanceIn, @builtin(vertex_index) vid: u32) -> VertOut {
|
|
524
|
+
let isWick = vid < 6u;
|
|
525
|
+
let isBodyOuter = vid >= 6u && vid < 12u;
|
|
526
|
+
|
|
527
|
+
let localId = select(select(vid - 12u, vid - 6u, vid < 12u), vid, vid < 6u);
|
|
528
|
+
let unit = unitQuad(localId);
|
|
529
|
+
|
|
530
|
+
let highY = priceToPhysY(inst.high);
|
|
531
|
+
let lowY = priceToPhysY(inst.low);
|
|
532
|
+
let openY = priceToPhysY(inst.open);
|
|
533
|
+
let closeY = priceToPhysY(inst.close);
|
|
534
|
+
|
|
535
|
+
let pr = u.pixelRatio;
|
|
536
|
+
let cx = (inst.centerX + u.panOffset) * pr;
|
|
537
|
+
let bhw = u.barHalfWidth * pr;
|
|
538
|
+
|
|
539
|
+
var screenX : f32;
|
|
540
|
+
var screenY : f32;
|
|
541
|
+
var color : vec4<f32>;
|
|
542
|
+
|
|
543
|
+
if u.renderMode == 1u {
|
|
544
|
+
// OHLC mode
|
|
545
|
+
let ohw = u.ohlcHalfSize * pr;
|
|
546
|
+
let tickH = ohw * 2.0;
|
|
547
|
+
if isWick {
|
|
548
|
+
screenX = cx - ohw + unit.x * ohw * 2.0;
|
|
549
|
+
screenY = highY + (lowY - highY) * unit.y;
|
|
550
|
+
color = inst.bodyColor;
|
|
551
|
+
} else if isBodyOuter {
|
|
552
|
+
let left = cx - bhw;
|
|
553
|
+
let right = cx - ohw;
|
|
554
|
+
screenX = left + unit.x * max(right - left, 0.0);
|
|
555
|
+
screenY = openY + unit.y * tickH;
|
|
556
|
+
color = inst.bodyColor;
|
|
557
|
+
} else {
|
|
558
|
+
let left = cx + ohw;
|
|
559
|
+
let right = cx + bhw;
|
|
560
|
+
screenX = left + unit.x * max(right - left, 0.0);
|
|
561
|
+
screenY = closeY + unit.y * tickH;
|
|
562
|
+
color = inst.bodyColor;
|
|
563
|
+
}
|
|
564
|
+
} else {
|
|
565
|
+
// Candle mode (solid / stroke)
|
|
566
|
+
var bodyTop = min(openY, closeY);
|
|
567
|
+
var bodyBottom = max(openY, closeY);
|
|
568
|
+
bodyBottom = max(bodyBottom, bodyTop + 1.0);
|
|
569
|
+
|
|
570
|
+
if isWick {
|
|
571
|
+
screenX = cx - 0.5 + unit.x;
|
|
572
|
+
screenY = highY + (lowY - highY) * unit.y;
|
|
573
|
+
color = inst.wickColor;
|
|
574
|
+
} else if isBodyOuter {
|
|
575
|
+
screenX = cx - bhw + unit.x * bhw * 2.0;
|
|
576
|
+
screenY = bodyTop + (bodyBottom - bodyTop) * unit.y;
|
|
577
|
+
color = inst.borderColor;
|
|
578
|
+
} else {
|
|
579
|
+
let inset = 1.0;
|
|
580
|
+
let innerHW = max(bhw - inset, 0.5);
|
|
581
|
+
screenX = cx - innerHW + unit.x * innerHW * 2.0;
|
|
582
|
+
let innerTop = bodyTop + inset;
|
|
583
|
+
let innerBottom = max(bodyBottom - inset, innerTop);
|
|
584
|
+
screenY = innerTop + (innerBottom - innerTop) * unit.y;
|
|
585
|
+
color = inst.bodyColor;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return VertOut(physToNdc(screenX, screenY), color);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
@fragment
|
|
593
|
+
fn fs_main(@location(0) color: vec4<f32>) -> @location(0) vec4<f32> {
|
|
594
|
+
return color;
|
|
595
|
+
}
|
|
596
|
+
`,Bn=false,Lr=false,Br=null;async function Ll(){return Bn?Lr:(Br!==null||(Br=(async()=>{try{if(!("gpu"in navigator))return !1;Lr=await navigator.gpu.requestAdapter()!==null;}catch{Lr=false;}return Bn=true,Lr})()),Br)}var Wt=new WeakMap;function Nn(n){return Wt.get(n)??null}async function Vn(n,e){let t=Wt.get(n);if(t!==void 0)return t;try{let r=await di.create(e);return Wt.set(n,r),r}catch{return null}}function Wn(n){let e=Wt.get(n);e!==void 0&&(e.destroy(),Wt.delete(n));}var On=48,di=class n{_canvas;_context;_device;_pipeline;_uniformBuffer;_uniformBindGroup;_instanceBuffer=null;_instanceCapacity=0;_stagingBuf=new ArrayBuffer(512*32);_stagingF32=new Float32Array(this._stagingBuf);_stagingU8=new Uint8Array(this._stagingBuf);_singleBarBuf=new ArrayBuffer(32);_singleBarF32=new Float32Array(this._singleBarBuf);_singleBarU8=new Uint8Array(this._singleBarBuf);_uniformData=new Float32Array(On/4);_colorCache=new Map;_barCount=0;_fingerprintBarCount=-1;_fingerprintFirstX=0;_fingerprintLastX=0;_fingerprintLastClose=0;_fingerprintLastBodyColor="";_fingerprintFirstOpen=NaN;_fingerprintFirstClose=NaN;_fingerprintBarStep=0;_panOffsetCss=0;_vboVersion=0;_drawnVersion=-1;_lastPriceFrom=NaN;_lastPriceRange=NaN;_lastBarHalfWidth=NaN;_lastRenderMode=-1;_lastOhlcHalfSize=NaN;_canvasWidthCss=0;_lodActive=false;_lodBuf=[];_renderBundle=null;_bundleVboVersion=-1;_indirectBuffer=null;_tsQuerySet=null;_tsResolveBuffer=null;_tsReadbackBuffer=null;_tsSampleCount=0;_tsTotalNs=0;_tsCanQuery=false;constructor(e,t,r,i,o,a){this._canvas=e,this._context=t,this._device=r,this._pipeline=i,this._uniformBuffer=o,this._uniformBindGroup=a,this._indirectBuffer=r.createBuffer({size:16,usage:GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_DST});try{this._tsQuerySet=r.createQuerySet({type:"timestamp",count:2}),this._tsResolveBuffer=r.createBuffer({size:16,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this._tsReadbackBuffer=r.createBuffer({size:16,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),this._tsCanQuery=!0;}catch{}}static async create(e){if(!("gpu"in navigator))throw new Error("[CandleWebGPURenderer] WebGPU not supported");let t=await Ml(),r=document.createElement("canvas");r.style.cssText="position:absolute;top:0;left:0;z-index:1;pointer-events:none;",e.appendChild(r);let i=r.getContext("webgpu");if(i===null)throw new Error("[CandleWebGPURenderer] Cannot get WebGPU canvas context");let o=navigator.gpu.getPreferredCanvasFormat();i.configure({device:t,format:o,alphaMode:"premultiplied"});let a=t.createBuffer({size:On,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),s=t.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}}]}),l=t.createBindGroup({layout:s,entries:[{binding:0,resource:{buffer:a}}]}),c=t.createShaderModule({code:Fl}),u={arrayStride:32,stepMode:"instance",attributes:[{shaderLocation:0,offset:0,format:"float32"},{shaderLocation:1,offset:4,format:"float32"},{shaderLocation:2,offset:8,format:"float32"},{shaderLocation:3,offset:12,format:"float32"},{shaderLocation:4,offset:16,format:"float32"},{shaderLocation:5,offset:20,format:"unorm8x4"},{shaderLocation:6,offset:24,format:"unorm8x4"},{shaderLocation:7,offset:28,format:"unorm8x4"}]},h=t.createRenderPipeline({layout:t.createPipelineLayout({bindGroupLayouts:[s]}),vertex:{module:c,entryPoint:"vs_main",buffers:[u]},fragment:{module:c,entryPoint:"fs_main",targets:[{format:o,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list"}});return new n(r,i,t,h,a,l)}static async isSupported(){return Ll()}resize(e,t){if(this._canvasWidthCss===e&&this._canvas.style.width===`${e}px`)return;this._canvasWidthCss=e;let r=z(this._canvas),i=Math.round(e*r),o=Math.round(t*r);this._canvas.width===i&&this._canvas.height===o||(this._canvas.width=i,this._canvas.height=o,this._canvas.style.width=`${e}px`,this._canvas.style.height=`${t}px`,this._vboVersion++);}_parseColorCached(e){return Te(e,this._colorCache)}_packColor(e,t,r){ft(e,t,r);}_writeBarIntoViews(e,t,r,i,o){t[i+0]=e.centerX-this._panOffsetCss,t[i+1]=e.open,t[i+2]=e.high,t[i+3]=e.low,t[i+4]=e.close,this._packColor(this._parseColorCached(e.wickColor),r,o+20),this._packColor(this._parseColorCached(e.bodyColor),r,o+20+4),this._packColor(this._parseColorCached(e.borderColor),r,o+20+8);}_applyLod(e,t){for(;this._lodBuf.length<t;)this._lodBuf.push({centerX:0,open:0,high:0,low:0,close:0,wickColor:"",bodyColor:"",borderColor:""});let r=e.length,i=r/t;for(let o=0;o<t;o++){let a=Math.floor(o*i),s=Math.min(Math.floor((o+1)*i)-1,r-1),l=e[a],c=e[s],u=l.high,h=l.low;for(let m=a+1;m<=s;m++)e[m].high>u&&(u=e[m].high),e[m].low<h&&(h=e[m].low);let d=this._lodBuf[o];d.centerX=l.centerX,d.open=l.open,d.high=u,d.low=h,d.close=c.close,d.wickColor=c.wickColor,d.bodyColor=c.bodyColor,d.borderColor=c.borderColor;}}_ensureInstanceBuffer(e){if(this._instanceBuffer!==null&&e<=this._instanceCapacity)return this._instanceBuffer;let t=Math.max(e,this._instanceCapacity*2,512);this._instanceBuffer?.destroy();let r=t*32;return this._instanceBuffer=this._device.createBuffer({size:r+3&-4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),this._instanceCapacity=t,this._stagingBuf=new ArrayBuffer(t*32),this._stagingF32=new Float32Array(this._stagingBuf),this._stagingU8=new Uint8Array(this._stagingBuf),this._instanceBuffer}setData(e){let r;if(this._canvasWidthCss>0&&e.length>this._canvasWidthCss*1.5){let u=Math.max(1,Math.floor(this._canvasWidthCss));this._applyLod(e,u),r=this._lodBuf,this._lodActive=true;}else r=e,this._lodActive=false;let i=r.length;if(this._barCount=i,i===0){this._fingerprintBarCount=0;return}let o=r[0],a=r[i-1];if(i===this._fingerprintBarCount&&o.centerX===this._fingerprintFirstX&&a.centerX===this._fingerprintLastX&&a.close===this._fingerprintLastClose&&a.bodyColor===this._fingerprintLastBodyColor)return;let s=i>=2?r[1].centerX-o.centerX:this._fingerprintBarStep;if(i===this._fingerprintBarCount&&a.close===this._fingerprintLastClose&&a.bodyColor===this._fingerprintLastBodyColor&&o.open===this._fingerprintFirstOpen&&o.close===this._fingerprintFirstClose&&s===this._fingerprintBarStep){this._panOffsetCss+=o.centerX-this._fingerprintFirstX,this._fingerprintFirstX=o.centerX,this._fingerprintLastX=a.centerX,this._vboVersion++;return}this._panOffsetCss=0,this._fingerprintBarCount=i,this._fingerprintFirstX=o.centerX,this._fingerprintLastX=a.centerX,this._fingerprintLastClose=a.close,this._fingerprintLastBodyColor=a.bodyColor,this._fingerprintFirstOpen=o.open,this._fingerprintFirstClose=o.close,this._fingerprintBarStep=s,this._ensureInstanceBuffer(i);let l=this._stagingF32,c=this._stagingU8;for(let u=0;u<i;u++)this._writeBarIntoViews(r[u],l,c,u<<3,u*32);if(this._device.queue.writeBuffer(this._instanceBuffer,0,this._stagingBuf,0,i*32),this._indirectBuffer!==null){let u=new Uint32Array([18,i,0,0]);this._device.queue.writeBuffer(this._indirectBuffer,0,u);}this._renderBundle=null,this._vboVersion++;}updateLastBar(e){this._barCount===0||this._lodActive||this._instanceBuffer===null||(this._fingerprintLastClose=e.close,this._writeBarIntoViews(e,this._singleBarF32,this._singleBarU8,0,0),this._device.queue.writeBuffer(this._instanceBuffer,(this._barCount-1)*32,this._singleBarBuf),this._renderBundle=null,this._vboVersion++);}draw(e,t,r,i=0,o=0){if(this._barCount===0||this._instanceBuffer===null||this._vboVersion===this._drawnVersion&&e===this._lastPriceFrom&&t===this._lastPriceRange&&r===this._lastBarHalfWidth&&i===this._lastRenderMode&&o===this._lastOhlcHalfSize)return;this._drawnVersion=this._vboVersion,this._lastPriceFrom=e,this._lastPriceRange=t,this._lastBarHalfWidth=r,this._lastRenderMode=i,this._lastOhlcHalfSize=o;let a=z(this._canvas),s=this._canvas.width,l=this._canvas.height;if(this._uniformData[0]=e,this._uniformData[1]=t,this._uniformData[2]=s,this._uniformData[3]=l,this._uniformData[4]=a,this._uniformData[5]=r,this._uniformData[6]=i,this._uniformData[7]=o,this._uniformData[8]=this._panOffsetCss,this._device.queue.writeBuffer(this._uniformBuffer,0,this._uniformData),!(this._renderBundle!==null&&this._bundleVboVersion===this._vboVersion))try{let m=this._context.getCurrentTexture().format,p=this._device.createRenderBundleEncoder({colorFormats:[m]});p.setPipeline(this._pipeline),p.setBindGroup(0,this._uniformBindGroup),p.setVertexBuffer(0,this._instanceBuffer),this._indirectBuffer!==null?p.drawIndirect(this._indirectBuffer,0):p.draw(18,this._barCount,0,0),this._renderBundle=p.finish(),this._bundleVboVersion=this._vboVersion;}catch{this._renderBundle=null;}let u=this._device.createCommandEncoder(),h=this._tsCanQuery&&this._tsQuerySet!==null?{querySet:this._tsQuerySet,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}:void 0,d=u.beginRenderPass({colorAttachments:[{view:this._context.getCurrentTexture().createView(),loadOp:"clear",clearValue:{r:0,g:0,b:0,a:0},storeOp:"store"}],...h!==void 0?{timestampWrites:h}:{}});if(this._renderBundle!==null?d.executeBundles([this._renderBundle]):(d.setPipeline(this._pipeline),d.setBindGroup(0,this._uniformBindGroup),d.setVertexBuffer(0,this._instanceBuffer),this._indirectBuffer!==null?d.drawIndirect(this._indirectBuffer,0):d.draw(18,this._barCount,0,0)),d.end(),this._tsCanQuery&&this._tsQuerySet!==null&&this._tsResolveBuffer!==null&&this._tsReadbackBuffer!==null&&(u.resolveQuerySet(this._tsQuerySet,0,2,this._tsResolveBuffer,0),u.copyBufferToBuffer(this._tsResolveBuffer,0,this._tsReadbackBuffer,0,16)),this._device.queue.submit([u.finish()]),this._tsCanQuery&&this._tsReadbackBuffer!==null){let m=this._tsReadbackBuffer;m.mapAsync(GPUMapMode.READ).then(()=>{try{let p=new BigUint64Array(m.getMappedRange()),g=Number(p[1]-p[0]);this._tsTotalNs+=g,this._tsSampleCount++;}finally{m.unmap();}}).catch(()=>{});}}getAverageGpuMs(){return this._tsSampleCount===0?0:this._tsTotalNs/this._tsSampleCount/1e6}resetGpuMetrics(){this._tsTotalNs=0,this._tsSampleCount=0;}destroy(){this._instanceBuffer?.destroy(),this._uniformBuffer.destroy(),this._indirectBuffer?.destroy();try{this._tsQuerySet?.destroy();}catch{}try{this._tsResolveBuffer?.destroy();}catch{}try{this._tsReadbackBuffer?.destroy();}catch{}this._canvas.remove();}};var Bl=131072,mi=class{_pool;_cursor=0;constructor(){this._pool=[];for(let e=0;e<Bl;e++)this._pool.push({dataIndex:0,centerX:0,open:0,high:0,low:0,close:0,wickColor:"",bodyColor:"",borderColor:""});}reset(){this._cursor=0;}alloc(){return this._cursor>=this._pool.length&&this._pool.push({dataIndex:0,centerX:0,open:0,high:0,low:0,close:0,wickColor:"",bodyColor:"",borderColor:""}),this._pool[this._cursor++]}},je=class extends Ge{_boundCandleBarClickEvent=e=>()=>(this.getWidget().getPane().getChart().getChartStore().executeAction("onCandleBarClick",e),false);_barPool=new mi;_webGPUInitStarted=false;_webGPUActive=false;_drawWithWebGL(e){let{type:t,styles:r}=e,i=this.getWidget(),o=i.getPane(),a=o.getChart().getChartStore(),s=Nn(i);s===null&&!this._webGPUInitStarted&&(this._webGPUInitStarted=true,Vn(i,i.getContainer()).catch(()=>{}));let l=null,c=null;if(s!==null)l=s,this._webGPUActive||(this._webGPUActive=true,Fr(i),kr(i));else {let E=Ln(i);if(E===null&&(E=Fn(i,i.getContainer())),c=E===null?Mn(i,i.getContainer()):null,E===null&&c===null)return false;l=E??c;}let{width:u,height:h}=i.getBounding();l.resize(u,h);let d="rgba(0,0,0,0)",m=a.getVisibleRangeDataList(),p=a.getBarSpace(),g=this._barPool;g.reset();let f=[],v=(E,I,k,F)=>{let{open:W,high:X,low:Y,close:V}=k,O=r.compareRule==="current_open"?W:F??V,te,G,$;V>O?(te=r.upWickColor,G=r.upColor,$=r.upBorderColor):V<O?(te=r.downWickColor,G=r.downColor,$=r.downBorderColor):(te=r.noChangeWickColor,G=r.noChangeColor,$=r.noChangeBorderColor),(t==="candle_stroke"||t==="candle_up_stroke"&&V>W||t==="candle_down_stroke"&&W>V)&&(G=d);let Q=g.alloc();return Q.dataIndex=E,Q.centerX=I,Q.open=W,Q.high=X,Q.low=Y,Q.close=V,Q.wickColor=te,Q.bodyColor=G,Q.borderColor=$,Q},y=64,b=0;if(c!==null&&m.length>0){let E=a.getDataList(),I=m[0];m[m.length-1];let F=Math.min(y,I.dataIndex);for(let W=F;W>=1;W--){let X=I.dataIndex-W,Y=E[X];if(!_(Y))continue;let V=X>0?E[X-1]:null,O=I.x-W*p.gapBar;f.push(v(X,O,Y,V?.close));}b=f.length;}let S=f.length;for(let E of m){let{x:I,dataIndex:k,data:{current:F,prev:W}}=E;_(F)&&f.push(v(k,I,F,W?.close));}let x=f.length-S;if(c!==null&&m.length>0){let E=a.getDataList(),I=m[m.length-1],k=Math.min(y,E.length-1-I.dataIndex);for(let F=1;F<=k;F++){let W=I.dataIndex+F,X=E[W];if(!_(X))continue;let Y=E[W-1]??null,V=I.x+F*p.gapBar;f.push(v(W,V,X,Y?.close));}}let T=o.getAxisComponent().getDisplayRange(),A=T.realFrom,P=T.realTo-T.realFrom,R=0,D=0;if(t==="ohlc"){R=1;let{gapBar:E}=p,I=Math.min(Math.max(Math.round(E*.2),1),8);I>2&&I%2===1&&I--,D=Math.floor(I/2);}return c!==null?c.setData(f,b,x):l.setData(f),l.draw(A,P,p.halfGapBar,R,D),true}drawImp(e){let t=this.getWidget().getPane(),r=t.getId()===B.CANDLE,i=t.getChart().getChartStore(),o=this.getCandleBarOptions();if(o!==null){if(this._drawWithWebGL(o))return;let{type:a,styles:s}=o,l=0,c=0;if(o.type==="ohlc"){let{gapBar:h}=i.getBarSpace();l=Math.min(Math.max(Math.round(h*.2),1),8),l>2&&l%2===1&&l--,c=Math.floor(l/2);}let u=t.getAxisComponent();this.eachChildren((h,d)=>{let{x:m,data:{current:p,prev:g}}=h;if(_(p)){let{open:f,high:v,low:y,close:b}=p,S=s.compareRule==="current_open"?f:g?.close??b,x=[];b>S?(x[0]=s.upColor,x[1]=s.upBorderColor,x[2]=s.upWickColor):b<S?(x[0]=s.downColor,x[1]=s.downBorderColor,x[2]=s.downWickColor):(x[0]=s.noChangeColor,x[1]=s.noChangeBorderColor,x[2]=s.noChangeWickColor);let C=u.convertToPixel(f),T=u.convertToPixel(b),A=[C,T,u.convertToPixel(v),u.convertToPixel(y)];A.sort((D,E)=>D-E);let P=d.gapBar%2===0?1:0,R=[];switch(a){case "candle_solid":{R=this._createSolidBar(m,A,d,x,P);break}case "candle_stroke":{R=this._createStrokeBar(m,A,d,x,P);break}case "candle_up_stroke":{b>f?R=this._createStrokeBar(m,A,d,x,P):R=this._createSolidBar(m,A,d,x,P);break}case "candle_down_stroke":{f>b?R=this._createStrokeBar(m,A,d,x,P):R=this._createSolidBar(m,A,d,x,P);break}case "ohlc":{R=[{name:"rect",attrs:[{x:m-c,y:A[0],width:l,height:A[3]-A[0]},{x:m-d.halfGapBar,y:C+l>A[3]?A[3]-l:C,width:d.halfGapBar-c,height:l},{x:m+c,y:T+l>A[3]?A[3]-l:T,width:d.halfGapBar-c,height:l}],styles:{color:x[0]}}];break}}R.forEach(D=>{let E=null;r&&(E={mouseClickEvent:this._boundCandleBarClickEvent(h)}),this.createFigure(D,E??void 0)?.draw(e);});}});}}getCandleBarOptions(){let e=this.getWidget().getPane().getChart().getStyles().candle;return {type:e.type,styles:e.bar}}_createSolidBar(e,t,r,i,o){return [{name:"rect",attrs:{x:e,y:t[0],width:1,height:t[3]-t[0]},styles:{color:i[2]}},{name:"rect",attrs:{x:e-r.halfGapBar,y:t[1],width:r.gapBar+o,height:Math.max(1,t[2]-t[1])},styles:{style:"stroke_fill",color:i[0],borderColor:i[1]}}]}_createStrokeBar(e,t,r,i,o){return [{name:"rect",attrs:[{x:e,y:t[0],width:1,height:t[1]-t[0]},{x:e,y:t[2],width:1,height:t[3]-t[2]}],styles:{color:i[2]}},{name:"rect",attrs:{x:e-r.halfGapBar,y:t[1],width:r.gapBar+o,height:Math.max(1,t[2]-t[1])},styles:{style:"stroke",borderColor:i[1]}}]}};function Ol(n){if(n.extendData===null||typeof n.extendData!="object")return null;let e=n.extendData[Cn];return e===null||typeof e!="object"?null:e}function Nl(n,e,t){let r=n.getDataList(),i=n.getVisibleRange(),o=e.getRange(),a=Math.max(1,Math.floor(t.width)),s=Math.max(1,Math.floor(t.height)),l=Math.min(o.realFrom,o.realTo),c=Math.max(o.realFrom,o.realTo);if(r.length===0)return {priceMin:l,priceMax:c,timeMin:0,timeMax:0,resolution:[a,s]};let u=r.length-1,h=Math.min(u,Math.max(0,Math.floor(i.realFrom))),d=Math.min(r.length,Math.max(1,Math.ceil(i.realTo))),m=Math.min(u,Math.max(h,d-1)),p=Number(r[h]?.timestamp??0),g=Number(r[m]?.timestamp??p);return {priceMin:l,priceMax:c,timeMin:Math.min(p,g),timeMax:Math.max(p,g),resolution:[a,s]}}var Yt=class extends je{getCandleBarOptions(){let e=this.getWidget().getPane();if(!e.getAxisComponent().isInCandle()){let r=e.getChart().getChartStore(),i=r.getIndicatorsByPaneId(e.getId());for(let o of i)if(o.shouldOhlc&&o.visible){let a=o.styles,s=r.getStyles().indicator,l=K(a,"ohlc.compareRule",s.ohlc.compareRule),c=K(a,"ohlc.upColor",s.ohlc.upColor),u=K(a,"ohlc.downColor",s.ohlc.downColor),h=K(a,"ohlc.noChangeColor",s.ohlc.noChangeColor);return {type:"ohlc",styles:{compareRule:l,upColor:c,downColor:u,noChangeColor:h,upBorderColor:c,downBorderColor:u,noChangeBorderColor:h,upWickColor:c,downWickColor:u,noChangeWickColor:h}}}}return null}drawImp(e){super.drawImp(e);let t=this.getWidget(),r=t.getPane(),i=r.getChart(),o=t.getBounding(),a=i.getXAxisPane().getAxisComponent(),s=r.getAxisComponent(),l=i.getChartStore(),c=l.getIndicatorsByPaneId(r.getId()),u=l.getStyles().indicator;if(c.some(x=>x.visible&&x.series==="volume")){let x=e.createLinearGradient(0,o.height,0,0);x.addColorStop(0,"rgba(46, 116, 255, 0.24)"),x.addColorStop(.45,"rgba(46, 116, 255, 0.08)"),x.addColorStop(1,"rgba(46, 116, 255, 0)"),e.save(),e.fillStyle=x,e.fillRect(0,0,o.width,o.height),e.restore();}let d=[],m=[],p=[],g;e.save(),c.forEach(x=>{if(x.visible){x.zLevel<0?e.globalCompositeOperation="destination-over":e.globalCompositeOperation="source-over";let C=false,T=Ol(x),A=T?.renderGL;if(x.zLevel>=0&&j(A)&&(g===void 0&&(g=Sn(t,t.getContainer())),g!==null&&(p.push({indicatorId:x.id,indicator:x,output:Array.isArray(T.output)?T.output:[],runtimeData:T,renderGL:A}),C=true)),!C&&x.draw!==null&&(e.save(),C=x.draw({ctx:e,chart:i,indicator:x,bounding:o,xAxis:a,yAxis:s}),e.restore()),!C){let P=x.result,R=[];this.eachChildren((D,E)=>{let{halfGapBar:I}=E,{dataIndex:k,x:F}=D,W=a.convertToPixel(k-1),X=a.convertToPixel(k+1),Y=P[k-1]??null,V=P[k]??null,O=P[k+1]??null,te={x:W},G={x:F},$={x:X};x.figures.forEach(({key:H})=>{let Q=Y?.[H];w(Q)&&(te[H]=s.convertToPixel(Q));let le=V?.[H];w(le)&&(G[H]=s.convertToPixel(le));let be=O?.[H];w(be)&&($[H]=s.convertToPixel(be));}),ct(x,k,u,(H,Q,le)=>{if(_(V?.[H.key])){let be=G[H.key],ge=H.attrs?.({data:{prev:Y,current:V,next:O},coordinate:{prev:te,current:G,next:$},bounding:o,barSpace:E,xAxis:a,yAxis:s});if(!_(ge))switch(H.type){case "circle":{ge={x:F,y:be,r:Math.max(1,I)};break}case "rect":case "bar":{let ot=H.baseValue??s.getRange().from,Ne=s.convertToPixel(ot),nt=Math.abs(Ne-be);ot!==V?.[H.key]&&(nt=Math.max(1,nt));let ce=0;be>Ne?ce=Ne:ce=be,ge={x:F-I,y:ce,width:Math.max(1,I*2),height:nt};break}case "line":{_(R[le])||(R[le]=[]),Q.show!==false&&w(G[H.key])&&w($[H.key])&&R[le].push({coordinates:[{x:G.x,y:G[H.key]},{x:$.x,y:$[H.key]}],styles:Q});break}}let ve=H.type;_(ge)&&ve!=="line"&&(x.zLevel>=0&&x.series!=="volume"&&(ve==="rect"||ve==="bar")&&Dn(Q)?m.push({x:ge.x,y:ge.y,width:ge.width,height:ge.height,color:Q.color}):this.createFigure({name:ve==="bar"?"rect":ve,attrs:ge,styles:Q})?.draw(e));}});}),R.forEach(D=>{if(D.length>1){let E=[{coordinates:[D[0].coordinates[0],D[0].coordinates[1]],styles:D[0].styles}];for(let I=1;I<D.length;I++){let k=E[E.length-1],F=D[I],W=k.coordinates[k.coordinates.length-1];W.x===F.coordinates[0].x&&W.y===F.coordinates[0].y&&k.styles.style===F.styles.style&&k.styles.color===F.styles.color&&k.styles.size===F.styles.size&&k.styles.smooth===F.styles.smooth&&k.styles.dashedValue?.[0]===F.styles.dashedValue?.[0]&&k.styles.dashedValue?.[1]===F.styles.dashedValue?.[1]?k.coordinates.push(F.coordinates[1]):E.push({coordinates:[F.coordinates[0],F.coordinates[1]],styles:F.styles});}E.forEach(({coordinates:I,styles:k})=>{this.createFigure({name:"line",attrs:{coordinates:I},styles:k})?.draw(e);});}});}}}),e.restore();let f=g===void 0?Tn(t):g;if(f!==null){let{width:x,height:C}=o;if(f.resize(x,C),f.beginFrame(),p.length>0){let T=f.getContext(),A=Nl(i,s,o);p.forEach(({indicatorId:P,indicator:R,output:D,runtimeData:E,renderGL:I})=>{try{let k=f.getOrCreateVbo(P);I(T,D,A,k);}catch(k){E!==null&&(E.renderGL=null);let F=k instanceof Error?k.message:String(k);me("IndicatorView.drawImp","indicator.renderGL",`plugin \`${P}\` renderGL failed (${F}). Falling back to render2D when available.`);let W=R.draw;if(j(W))try{e.save(),e.globalCompositeOperation="source-over",W({ctx:e,chart:i,indicator:R,bounding:o,xAxis:a,yAxis:s}),e.restore();}catch(X){let Y=X instanceof Error?X.message:String(X);me("IndicatorView.drawImp","indicator.draw",`plugin \`${P}\` render2D fallback failed (${Y}).`);}}});}}let{width:v,height:y}=o,b=m.length>0||d.length>0,S=b?ai(t,t.getContainer()):Dt(t);if(S!==null){if(S.resize(v,y),!b){S.beginFrame();return}let x=m.length>0?In(t,S):En(t),C=d.length>0?bn(t,S):Rr(t);x?.setData(m),C?.setData(d),((x?.isDirty()??false)||(C?.isDirty()??false)||(C?.isGridDirty()??false))&&(S.beginFrame(),x?.draw(),C?.drawGrid(),C?.draw());}else if(b){e.save();for(let x of m)e.fillStyle=x.color,e.fillRect(x.x,x.y,x.width,x.height);for(let x of d)e.beginPath(),e.strokeStyle=x.color,e.lineWidth=x.halfWidth*2,e.moveTo(x.x0,x.y0),e.lineTo(x.x1,x.y1),e.stroke();e.restore();}}};var Ht=class extends J{drawImp(e){let t=this.getWidget(),r=t.getPane(),i=t.getBounding(),o=t.getPane().getChart().getChartStore(),a=o.getCrosshair(),s=o.getStyles().crosshair;if(L(a.paneId)&&s.show){if(a.paneId===r.getId()){let c=a.y;this._drawLine(e,[{x:0,y:c},{x:i.width,y:c}],s.horizontal);}let l=a.realX;this._drawLine(e,[{x:l,y:0},{x:l,y:i.height}],s.vertical);}}_drawLine(e,t,r){if(r.show){let i=r.line;i.show&&this.createFigure({name:"line",attrs:{coordinates:t},styles:i})?.draw(e);}}};var qe=class extends J{_activeFeatureInfo=null;_collapsed=new Set;_rowBounds=new Map;_hoveredIndicatorId=null;_featureClickEvent=(e,t)=>()=>(this.getWidget().getPane().getChart().getChartStore().executeAction(e,t),true);_featureMouseMoveEvent=e=>()=>(this._activeFeatureInfo=e,true);_toggleCollapseEvent=e=>()=>(this._collapsed.has(e)?this._collapsed.delete(e):this._collapsed.add(e),true);constructor(e){super(e),this.registerEvent("mouseMoveEvent",t=>{this._activeFeatureInfo=null,this._hoveredIndicatorId=null;for(let[r,i]of this._rowBounds)if(t.y>=i.top&&t.y<=i.bottom){this._hoveredIndicatorId=r;break}return false}),this.registerEvent("mouseLeaveEvent",()=>(this._activeFeatureInfo=null,this._hoveredIndicatorId=null,false));}drawImp(e){let t=this.getWidget(),i=t.getPane().getChart().getChartStore();if(i.getDataList().length===0)return;let o=t.getBounding(),{offsetLeft:a,offsetTop:s,offsetRight:l}=i.getStyles().indicator.tooltip;this.drawIndicatorTooltip(e,a,s,o.width-l);}drawIndicatorTooltip(e,t,r,i){let o=this.getWidget().getPane(),a=o.getChart().getChartStore(),l=a.getStyles().indicator.tooltip;if(this.isDrawTooltip(a.getCrosshair(),l)){let c=a.getIndicatorsByPaneId(o.getId()),u=l.title,h=l.legend;this._rowBounds.clear(),c.forEach(d=>{let m=r,p=0,g={x:t,y:r},{name:f,calcParamsText:v,legends:y,features:b}=this.getIndicatorTooltipData(d),S=f.length>0,x=y.length>0;if(S||x){let C=this._collapsed.has(d.id),T=d.id===this._hoveredIndicatorId,A=T?this.classifyTooltipFeatures(b):[[],[],[]];if(p=this.drawChevron(e,d.id,C,g,p,u),S){let P=f;v.length>0&&(P=`${P}${v}`);let R=u.color;p=this.drawStandardTooltipLegends(e,[{title:{text:"",color:R},value:{text:P,color:R}}],g,t,p,i,u);}if(!C&&x&&(p=this.drawStandardTooltipLegends(e,y,g,t,p,i,h)),T){let P=[...A[0],...A[1],...A[2]];p=this.drawStandardTooltipFeatures(e,P,g,d,t,p,i);}r=g.y+p,this._rowBounds.set(d.id,{top:m,bottom:r});}});}return r}drawChevron(e,t,r,i,o,a){let{marginLeft:s=0,marginTop:l=0,marginRight:c=0,marginBottom:u=0,size:h=12,family:d,weight:m,color:p}=a,g=r?"\u203A":"\u2228";e.font=se(h,m,d);let f=Ie(e,g),v=l+h+u;return o=Math.max(o,v),this.createFigure({name:"text",attrs:{text:g,x:i.x+s,y:i.y+l},styles:{color:p,size:h,family:d,weight:m,paddingLeft:2,paddingTop:0,paddingRight:4,paddingBottom:0}},{mouseDownEvent:this._toggleCollapseEvent(t)})?.draw(e),i.x+=s+f+8,o}drawStandardTooltipFeatures(e,t,r,i,o,a,s){if(t.length>0){let l=0,c=0;t.forEach(d=>{let{marginLeft:m=0,marginTop:p=0,marginRight:g=0,marginBottom:f=0,paddingLeft:v=0,paddingTop:y=0,paddingRight:b=0,paddingBottom:S=0,size:x=0,type:C,content:T}=d,A=0;if(C==="icon_font"){let P=T;e.font=se(x,"normal",P.family),A=Ie(e,P.code);}else A=x;l+=m+v+A+b+g,c=Math.max(c,p+y+x+S+f);}),r.x+l>s?(r.x=o,r.y+=a,a=c):a=Math.max(a,c);let h=this.getWidget().getPane().getId();t.forEach(d=>{let{marginLeft:m=0,marginTop:p=0,marginRight:g=0,paddingLeft:f=0,paddingTop:v=0,paddingRight:y=0,paddingBottom:b=0,backgroundColor:S,activeBackgroundColor:x,borderRadius:C,size:T=0,color:A,activeColor:P,type:R,content:D}=d,E=A,I=S;this._activeFeatureInfo?.paneId===h&&this._activeFeatureInfo.indicator?.id===i?.id&&this._activeFeatureInfo.feature.id===d.id&&(E=P??A,I=x??S);let k="onCandleTooltipFeatureClick",F={paneId:h,feature:d};_(i)&&(k="onIndicatorTooltipFeatureClick",F.indicator=i);let W={mouseDownEvent:this._featureClickEvent(k,F),mouseMoveEvent:this._featureMouseMoveEvent(F)},X=0;if(R==="icon_font"){let Y=D;this.createFigure({name:"text",attrs:{text:Y.code,x:r.x+m,y:r.y+p},styles:{paddingLeft:f,paddingTop:v,paddingRight:y,paddingBottom:b,borderRadius:C,size:T,family:Y.family,color:E,backgroundColor:I}},W)?.draw(e),X=Ie(e,Y.code);}else {this.createFigure({name:"rect",attrs:{x:r.x+m,y:r.y+p,width:T,height:T},styles:{paddingLeft:f,paddingTop:v,paddingRight:y,paddingBottom:b,color:I}},W)?.draw(e);let Y=D;this.createFigure({name:"path",attrs:{path:Y.path,x:r.x+m+f,y:r.y+p+v,width:T,height:T},styles:{style:Y.style,lineWidth:Y.lineWidth,color:E}})?.draw(e),X=T;}r.x+=m+f+X+y+g;});}return a}drawStandardTooltipLegends(e,t,r,i,o,a,s){if(t.length>0){let{marginLeft:l,marginTop:c,marginRight:u,marginBottom:h,size:d,family:m,weight:p}=s;e.font=se(d,p,m),t.forEach(g=>{let f=g.title,v=g.value,y=Ie(e,f.text),b=Ie(e,v.text),S=y+b,x=c+d+h;r.x+l+S+u>a?(r.x=i,r.y+=o,o=x):o=Math.max(o,x),f.text.length>0&&this.createFigure({name:"text",attrs:{x:r.x+l,y:r.y+c,text:f.text},styles:{color:f.color,size:d,family:m,weight:p}})?.draw(e),this.createFigure({name:"text",attrs:{x:r.x+l+y,y:r.y+c,text:v.text},styles:{color:v.color,size:d,family:m,weight:p}})?.draw(e),r.x+=l+S+u;});}return o}isDrawTooltip(e,t){let r=t.showRule;return r==="always"||r==="follow_cross"&&L(e.paneId)}getIndicatorTooltipData(e){let t=this.getWidget().getPane().getChart().getChartStore(),r=t.getStyles().indicator,i=r.tooltip,o=i.title,a="",s="";if(o.show&&(o.showName&&(a=e.shortName),o.showParams)){let g=e.calcParams;g.length>0&&(s=`(${g.join(",")})`);}let l={name:a,calcParamsText:s,legends:[],features:i.features},c=e.result,u=t.getCrosshair().dataIndex??Math.max(0,c.length-1),h=t.getInnerFormatter(),d=t.getDecimalFold(),m=t.getThousandsSeparator(),p=[];if(e.visible){let g=c[u]??{},f=i.legend.defaultValue;ct(e,u,r,(v,y)=>{if(L(v.title)){let b=y.color,S=g[v.key];w(S)&&(S=ee(S,e.precision),e.shouldFormatBigNumber&&(S=h.formatBigNumber(S)),S=d.format(m.format(S))),p.push({title:{text:v.title,color:b},value:{text:S??f,color:b}});}}),l.legends=p;}if(j(e.createTooltipDataSource)){let g=this.getWidget(),f=g.getPane(),v=f.getChart(),{name:y,calcParamsText:b,legends:S,features:x}=e.createTooltipDataSource({chart:v,indicator:e,crosshair:t.getCrosshair(),bounding:g.getBounding(),xAxis:f.getChart().getXAxisPane().getAxisComponent(),yAxis:f.getAxisComponent()});if(o.show&&(y!==void 0&&o.showName&&(l.name=y),b!==void 0&&o.showParams&&(l.calcParamsText=b)),_(x)&&(l.features=x),S!==void 0&&e.visible){let C=[],T=r.tooltip.legend.color;S.forEach(A=>{let P={text:"",color:T};ae(A.title)?P=A.title:P.text=A.title;let R={text:"",color:T};ae(A.value)?R=A.value:R.text=A.value,w(Number(R.text))&&(R.text=d.format(m.format(R.text))),C.push({title:P,value:R});}),l.legends=C;}}return l}classifyTooltipFeatures(e){let t=[],r=[],i=[];return e.forEach(o=>{switch(o.position){case "left":{t.push(o);break}case "middle":{r.push(o);break}case "right":{i.push(o);break}}}),[t,r,i]}};var Ze=class extends J{constructor(e){super(e),this._initEvent();}_initEvent(){let e=this.getWidget(),t=e.getPane(),r=t.getId(),i=t.getChart(),o=i.getChartStore();this.registerEvent("mouseMoveEvent",a=>{let s=o.getProgressOverlayInfo();if(s!==null){let l=s.overlay,c=s.paneId;l.isStart()&&(o.updateProgressOverlayInfo(r),c=r);let u=l.points.length-1;return l.isDrawing()&&c===r&&(l.eventMoveForDrawing(this._coordinateToPoint(l,a)),l.onDrawing?.({chart:i,overlay:l,...a})),this._figureMouseMoveEvent(l,"point",u,{key:`${We}point_${u}`,type:"circle",attrs:{}})(a)}return o.setHoverOverlayInfo({paneId:r,overlay:null,figureType:"none",figureIndex:-1,figure:null},(l,c)=>this._processOverlayMouseEnterEvent(l,c,a),(l,c)=>this._processOverlayMouseLeaveEvent(l,c,a)),e.setForceCursor(null),false}).registerEvent("mouseClickEvent",a=>{let s=o.getProgressOverlayInfo();if(s!==null){let l=s.overlay,c=s.paneId;l.isStart()&&(o.updateProgressOverlayInfo(r,true),c=r);let u=l.points.length-1;return l.isDrawing()&&c===r&&(l.eventMoveForDrawing(this._coordinateToPoint(l,a)),l.onDrawing?.({chart:i,overlay:l,...a}),l.nextStep(),l.isDrawing()||(o.progressOverlayComplete(),l.onDrawEnd?.({chart:i,overlay:l,...a}))),this._figureMouseClickEvent(l,"point",u,{key:`${We}point_${u}`,type:"circle",attrs:{}})(a)}return o.setClickOverlayInfo({paneId:r,overlay:null,figureType:"none",figureIndex:-1,figure:null},(l,c)=>this._processOverlaySelectedEvent(l,c,a),(l,c)=>this._processOverlayDeselectedEvent(l,c,a)),false}).registerEvent("mouseDoubleClickEvent",a=>{let s=o.getProgressOverlayInfo();if(s!==null){let l=s.overlay,c=s.paneId;l.isDrawing()&&c===r&&(l.forceComplete(),l.isDrawing()||(o.progressOverlayComplete(),l.onDrawEnd?.({chart:i,overlay:l,...a})));let u=l.points.length-1;return this._figureMouseClickEvent(l,"point",u,{key:`${We}point_${u}`,type:"circle",attrs:{}})(a)}return false}).registerEvent("mouseRightClickEvent",a=>{let s=o.getProgressOverlayInfo();if(s!==null){let l=s.overlay;if(l.isDrawing()){let c=l.points.length-1;return this._figureMouseRightClickEvent(l,"point",c,{key:`${We}point_${c}`,type:"circle",attrs:{}})(a)}}return false}).registerEvent("mouseUpEvent",a=>{let{overlay:s,figure:l}=o.getPressedOverlayInfo();return s!==null&&fe("onPressedMoveEnd",l)&&s.onPressedMoveEnd?.({chart:i,overlay:s,figure:l??void 0,...a}),o.setPressedOverlayInfo({paneId:r,overlay:null,figureType:"none",figureIndex:-1,figure:null}),false}).registerEvent("pressedMouseMoveEvent",a=>{let{overlay:s,figureType:l,figureIndex:c,figure:u}=o.getPressedOverlayInfo();if(s!==null&&fe("onPressedMoving",u)){if(!s.lock){let h=this._coordinateToPoint(s,a);l==="point"?s.eventPressedPointMove(h,c):s.eventPressedOtherMove(h,this.getWidget().getPane().getChart().getChartStore());let d=false;s.onPressedMoving?.({chart:i,overlay:s,figure:u??void 0,...a,preventDefault:()=>{d=true;}}),d?this.getWidget().setForceCursor(null):this.getWidget().setForceCursor("pointer");}return true}return this.getWidget().setForceCursor(null),false});}_createFigureEvents(e,t,r,i){return e.isDrawing()?null:{mouseMoveEvent:this._figureMouseMoveEvent(e,t,r,i),mouseDownEvent:this._figureMouseDownEvent(e,t,r,i),mouseClickEvent:this._figureMouseClickEvent(e,t,r,i),mouseRightClickEvent:this._figureMouseRightClickEvent(e,t,r,i),mouseDoubleClickEvent:this._figureMouseDoubleClickEvent(e,t,r,i)}}_processOverlayMouseEnterEvent(e,t,r){return j(e.onMouseEnter)&&fe("onMouseEnter",t)?(e.onMouseEnter({chart:this.getWidget().getPane().getChart(),overlay:e,figure:t??void 0,...r}),true):false}_processOverlayMouseLeaveEvent(e,t,r){return j(e.onMouseLeave)&&fe("onMouseLeave",t)?(e.onMouseLeave({chart:this.getWidget().getPane().getChart(),overlay:e,figure:t??void 0,...r}),true):false}_processOverlaySelectedEvent(e,t,r){return fe("onSelected",t)?(e.onSelected?.({chart:this.getWidget().getPane().getChart(),overlay:e,figure:t??void 0,...r}),true):false}_processOverlayDeselectedEvent(e,t,r){return fe("onDeselected",t)?(e.onDeselected?.({chart:this.getWidget().getPane().getChart(),overlay:e,figure:t??void 0,...r}),true):false}_figureMouseMoveEvent(e,t,r,i){return o=>{let a=this.getWidget().getPane(),s=!e.isDrawing()&&fe("onMouseMove",i);if(s){let l=false;e.onMouseMove?.({chart:a.getChart(),overlay:e,figure:i,...o,preventDefault:()=>{l=true;}}),l?this.getWidget().setForceCursor(null):this.getWidget().setForceCursor("pointer");}return a.getChart().getChartStore().setHoverOverlayInfo({paneId:a.getId(),overlay:e,figureType:t,figure:i,figureIndex:r},(l,c)=>this._processOverlayMouseEnterEvent(l,c,o),(l,c)=>this._processOverlayMouseLeaveEvent(l,c,o)),s}}_figureMouseDownEvent(e,t,r,i){return o=>{let a=this.getWidget().getPane(),s=a.getId();return e.startPressedMove(this._coordinateToPoint(e,o)),fe("onPressedMoveStart",i)?(e.onPressedMoveStart?.({chart:a.getChart(),overlay:e,figure:i,...o}),a.getChart().getChartStore().setPressedOverlayInfo({paneId:s,overlay:e,figureType:t,figureIndex:r,figure:i}),!e.isDrawing()):false}}_figureMouseClickEvent(e,t,r,i){return o=>{let a=this.getWidget().getPane(),s=a.getId(),l=!e.isDrawing()&&fe("onClick",i);return l&&e.onClick?.({chart:this.getWidget().getPane().getChart(),overlay:e,figure:i,...o}),a.getChart().getChartStore().setClickOverlayInfo({paneId:s,overlay:e,figureType:t,figureIndex:r,figure:i},(c,u)=>this._processOverlaySelectedEvent(c,u,o),(c,u)=>this._processOverlayDeselectedEvent(c,u,o)),l}}_figureMouseDoubleClickEvent(e,t,r,i){return o=>fe("onDoubleClick",i)?(e.onDoubleClick?.({...o,chart:this.getWidget().getPane().getChart(),figure:i,overlay:e}),!e.isDrawing()):false}_figureMouseRightClickEvent(e,t,r,i){return o=>{if(fe("onRightClick",i)){let a=false;return e.onRightClick?.({chart:this.getWidget().getPane().getChart(),overlay:e,figure:i,...o,preventDefault:()=>{a=true;}}),a||this.getWidget().getPane().getChart().getChartStore().removeOverlay(e),!e.isDrawing()}return false}}_coordinateToPoint(e,t){let r={},i=this.getWidget().getPane(),o=i.getChart(),a=i.getId(),s=o.getChartStore();if(this.coordinateToPointTimestampDataIndexFlag()){let c=o.getXAxisPane().getAxisComponent().convertFromPixel(t.x),u=s.dataIndexToTimestamp(c)??void 0;r.timestamp=u,r.dataIndex=c;}if(this.coordinateToPointValueFlag()){let l=i.getAxisComponent(),c=l.convertFromPixel(t.y);if(e.mode!=="normal"&&a===B.CANDLE&&w(r.dataIndex)){let u=s.getDataByDataIndex(r.dataIndex);if(u!==null){let h=e.modeSensitivity;if(c>u.high)if(e.mode==="weak_magnet"){let d=l.convertToPixel(u.high),m=l.convertFromPixel(d-h);c<m&&(c=u.high);}else c=u.high;else if(c<u.low)if(e.mode==="weak_magnet"){let d=l.convertToPixel(u.low),m=l.convertFromPixel(d-h);c>m&&(c=u.low);}else c=u.low;else {let d=Math.max(u.open,u.close),m=Math.min(u.open,u.close);c>d?c-d<u.high-c?c=d:c=u.high:c<m?c-u.low<m-c?c=u.low:c=m:d-c<c-m?c=d:c=m;}}}r.value=c;}return r}coordinateToPointValueFlag(){return true}coordinateToPointTimestampDataIndexFlag(){return true}dispatchEvent(e,t){return this.getWidget().getPane().getChart().getChartStore().isOverlayDrawing()?this.onEvent(e,t):super.dispatchEvent(e,t)}drawImp(e){this.getCompleteOverlays().forEach(i=>{i.visible&&this._drawOverlay(e,i);});let r=this.getProgressOverlay();_(r)&&r.visible&&this._drawOverlay(e,r);}_drawOverlay(e,t){let{points:r}=t,i=this.getWidget().getPane(),o=i.getChart(),a=o.getChartStore(),s=i.getAxisComponent(),l=o.getXAxisPane().getAxisComponent(),c=r.reduce((u,h)=>{let d=h.dataIndex??null;if(!w(d)&&w(h.timestamp)&&(d=a.timestampToDataIndex(h.timestamp)),!w(d)||!w(h.value))return u;let m=l.convertToPixel(d),p=s?.convertToPixel(h.value);return !w(m)||!w(p)||u.push({x:m,y:p}),u},[]);if(c.length>0){let u=[].concat(this.getFigures(t,c));this.drawFigures(e,t,u);}this.drawDefaultFigures(e,t,c);}drawFigures(e,t,r){let i=this.getWidget().getPane().getChart().getStyles().overlay;r.forEach((o,a)=>{let{type:s,styles:l,attrs:c}=o;[].concat(c).forEach(h=>{let d=this._createFigureEvents(t,"other",a,o),m={...i[s],...t.styles?.[s],...l};this.createFigure({name:s,attrs:h,styles:m},d??void 0)?.draw(e);});});}getCompleteOverlays(){let e=this.getWidget().getPane();return e.getChart().getChartStore().getOverlaysByPaneId(e.getId())}getProgressOverlay(){let e=this.getWidget().getPane(),t=e.getChart().getChartStore().getProgressOverlayInfo();return _(t)&&t.paneId===e.getId()?t.overlay:null}getFigures(e,t){let r=this.getWidget(),i=r.getPane(),o=i.getChart(),a=i.getAxisComponent(),s=o.getXAxisPane().getAxisComponent(),l=r.getBounding();return e.createPointFigures?.({chart:o,overlay:e,coordinates:t,bounding:l,xAxis:s,yAxis:a})??[]}drawDefaultFigures(e,t,r){if(t.needDefaultPointFigure){let i=this.getWidget().getPane().getChart().getChartStore(),o=i.getHoverOverlayInfo(),a=i.getClickOverlayInfo();if(o.overlay?.id===t.id&&o.figureType!=="none"||a.overlay?.id===t.id&&a.figureType!=="none"){let s=i.getStyles().overlay,l=t.styles,c={...s.point,...l?.point};r.forEach(({x:u,y:h},d)=>{let m=c.radius,p=c.color,g=c.borderColor,f=c.borderSize;o.overlay?.id===t.id&&o.figureType==="point"&&o.figure?.key===`${We}point_${d}`&&(m=c.activeRadius,p=c.activeColor,g=c.activeBorderColor,f=c.activeBorderSize),this.createFigure({name:"circle",attrs:{x:u,y:h,r:m+f},styles:{color:g}},this._createFigureEvents(t,"point",d,{key:`${We}point_${d}`,type:"circle",attrs:{x:u,y:h,r:m+f},styles:{color:g}})??void 0)?.draw(e),this.createFigure({name:"circle",attrs:{x:u,y:h,r:m},styles:{color:p}})?.draw(e);});}}}};var Qe=class extends ke{_gridView=new Mt(this);_indicatorView=new Yt(this);_crosshairLineView=new Ht(this);_tooltipView=this.createTooltipView();_overlayView=new Ze(this);constructor(e,t){super(e,t),this.addChild(this._tooltipView),this.addChild(this._overlayView);}getName(){return N.MAIN}updateMain(e){this.getPane().getOptions().state!=="minimize"&&(this.updateMainContent(e),this._gridView.draw(e),this._indicatorView.draw(e));}createTooltipView(){return new qe(this)}updateMainContent(e){}updateOverlayContent(e){}updateOverlay(e){this.getPane().getOptions().state!=="minimize"&&(this._overlayView.draw(e),this._crosshairLineView.draw(e),this.updateOverlayContent(e)),this._tooltipView.draw(e);}destroy(){xn(this),Rn(this),An(this),yn(this),super.destroy();}};var zt=class extends Ge{_ripplePoint=this.createFigure({name:"circle",attrs:{x:0,y:0,r:0},styles:{style:"fill"}});_animationFrameTime=0;_gradientCache=null;_animation=new Oe({iterationCount:1/0}).doFrame(e=>{this._animationFrameTime=e;let t=this.getWidget().getPane();t.getChart().updatePane(0,t.getId());});drawImp(e){let t=this.getWidget(),r=t.getPane(),i=r.getChart(),a=i.getDataList().length-1,s=t.getBounding(),l=r.getAxisComponent(),c=i.getStyles().candle.area,u=[],h=Number.MAX_SAFE_INTEGER,d=Number.MIN_SAFE_INTEGER,m=null;if(this.eachChildren(g=>{let f=g.x,{current:v}=g.data,y=v?.[c.value];if(w(y)){let b=l.convertToPixel(y);d===Number.MIN_SAFE_INTEGER&&(d=f),u.push({x:f,y:b}),h=Math.min(h,b),g.dataIndex===a&&(m={x:f,y:b});}}),u.length>0){this.createFigure({name:"line",attrs:{coordinates:u},styles:{color:c.lineColor,size:c.lineSize,smooth:c.smooth}})?.draw(e);let g=c.backgroundColor,f="";if(ne(g)){if(this._gradientCache===null||this._gradientCache.height!==s.height||this._gradientCache.minY!==h){let v=e.createLinearGradient(0,s.height,0,h);try{g.forEach(({offset:y,color:b})=>{v.addColorStop(y,b);});}catch{}this._gradientCache={gradient:v,height:s.height,minY:h};}f=this._gradientCache.gradient;}else f=g;e.fillStyle=f,e.beginPath(),e.moveTo(d,s.height),e.lineTo(u[0].x,u[0].y),Gr(e,u,c.smooth),e.lineTo(u[u.length-1].x,s.height),e.closePath(),e.fill();}let p=c.point;if(p.show&&_(m)){this.createFigure({name:"circle",attrs:{x:m.x,y:m.y,r:p.radius},styles:{style:"fill",color:p.color}})?.draw(e);let g=p.rippleRadius;p.animation&&(g=p.radius+this._animationFrameTime/p.animationDuration*(p.rippleRadius-p.radius),this._animation.setDuration(p.animationDuration).start()),this._ripplePoint?.setAttrs({x:m.x,y:m.y,r:g}).setStyles({style:"fill",color:p.rippleColor}).draw(e);}else this.stopAnimation();}stopAnimation(){this._animation.stop();}};var Xt=class extends J{drawImp(e){let r=this.getWidget().getPane(),i=r.getChart().getChartStore(),o=i.getStyles().candle.priceMark,a=o.high,s=o.low;if(o.show&&(a.show||s.show)){let l=i.getVisibleRangeHighLowPrice(),c=i.getSymbol()?.pricePrecision??q.PRICE,u=r.getAxisComponent(),{price:h,x:d}=l[0],{price:m,x:p}=l[1],g=u.convertToPixel(h),f=u.convertToPixel(m),v=i.getDecimalFold(),y=i.getThousandsSeparator();a.show&&h!==Number.MIN_SAFE_INTEGER&&this._drawMark(e,v.format(y.format(ee(h,c))),{x:d,y:g},g<f?[-2,-5]:[2,5],a),s.show&&m!==Number.MAX_SAFE_INTEGER&&this._drawMark(e,v.format(y.format(ee(m,c))),{x:p,y:f},g<f?[2,5]:[-2,-5],s);}}_drawMark(e,t,r,i,o){let a=r.x,s=r.y+i[0];this.createFigure({name:"line",attrs:{coordinates:[{x:a-2,y:s+i[0]},{x:a,y:s},{x:a+2,y:s+i[0]}]},styles:{color:o.color}})?.draw(e);let l=0,c=0,u="left",{width:h}=this.getWidget().getBounding();a>h/2?(l=a-5,c=l-o.textOffset,u="right"):(l=a+5,u="left",c=l+o.textOffset);let d=s+i[1];this.createFigure({name:"line",attrs:{coordinates:[{x:a,y:s},{x:a,y:d},{x:l,y:d}]},styles:{color:o.color}})?.draw(e);let m=Math.max(o.textSize,11);e.save(),e.font=se(m,"400",o.textFamily),e.textAlign=u,e.textBaseline="middle",e.shadowColor="rgba(0, 0, 0, 0.9)",e.shadowBlur=4,e.shadowOffsetX=0,e.shadowOffsetY=0,e.fillStyle=o.color,e.fillText(t,c,d),e.shadowBlur=0,e.fillText(t,c,d),e.restore();}};var Ut=class extends J{drawImp(e){let t=this.getWidget(),r=t.getPane(),i=t.getBounding(),o=r.getChart().getChartStore(),a=o.getStyles().candle.priceMark,s=a.last,l=s.line;if(a.show&&s.show&&l.show){let c=r.getAxisComponent(),u=o.getDataList(),h=u[u.length-1];if(_(h)){let{close:d,open:m}=h,p=s.compareRule==="current_open"?m:u[u.length-2]?.close??d,g=c.convertToNicePixel(d),f="";d>p?f=s.upColor:d<p?f=s.downColor:f=s.noChangeColor,this.createFigure({name:"line",attrs:{coordinates:[{x:0,y:g},{x:i.width,y:g}]},styles:{style:l.style,color:f,size:l.size,dashedValue:l.dashedValue}})?.draw(e);}}}};var Vl={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"\u6210\u4EA4\u989D\uFF1A",change:"\u6DA8\u5E45\uFF1A",second:"\u79D2",minute:"",hour:"\u5C0F\u65F6",day:"\u5929",week:"\u5468",month:"\u6708",year:"\u5E74"},Yn=Vl;var Wl={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"\u6210\u4EA4\u984D\uFF1A",change:"\u6F32\u5E45\uFF1A",second:"\u79D2",minute:"\u5206",hour:"\u5C0F\u6642",day:"\u5929",week:"\u9031",month:"\u6708",year:"\u5E74"},Hn=Wl;var Yl={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"Turnover: ",change:"Change: ",second:"S",minute:"",hour:"H",day:"D",week:"W",month:"M",year:"Y"},zn=Yl;var Hl={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"\u58F2\u8CB7\u4EE3\u91D1\uFF1A",change:"\u5909\u52D5\uFF1A",second:"\u79D2",minute:"\u5206",hour:"\u6642",day:"\u65E5",week:"\u9031",month:"\u6708",year:"\u5E74"},Xn=Hl;var zl={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"\u0E21\u0E39\u0E25\u0E04\u0E48\u0E32: ",change:"\u0E40\u0E1B\u0E25\u0E35\u0E48\u0E22\u0E19\u0E41\u0E1B\u0E25\u0E07: ",second:"\u0E27\u0E34",minute:"\u0E19",hour:"\u0E0A\u0E21",day:"\u0E27",week:"\u0E2A\u0E31\u0E1B\u0E14\u0E32\u0E2B\u0E4C",month:"\u0E40\u0E14\u0E37\u0E2D\u0E19",year:"\u0E1B\u0E35"},Un=zl;var Xl={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"\uAC70\uB798\uB300\uAE08: ",change:"\uBCC0\uB3D9: ",second:"\uCD08",minute:"\uBD84",hour:"\uC2DC",day:"\uC77C",week:"\uC8FC",month:"\uC6D4",year:"\uB144"},Gn=Xl;var Ul={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"Chiffre d'aff. : ",change:"Variation : ",second:"s",minute:"min",hour:"h",day:"j",week:"sem",month:"m",year:"a"},$n=Ul;var Gl={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"Umsatz: ",change:"\xC4nderung: ",second:"S",minute:"Min",hour:"H",day:"T",week:"W",month:"Mo",year:"J"},jn=Gl;var $l={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"Faturamento: ",change:"Varia\xE7\xE3o: ",second:"S",minute:"min",hour:"H",day:"D",week:"S",month:"M",year:"A"},qn=$l;var jl={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"Facturaci\xF3n: ",change:"Cambio: ",second:"S",minute:"min",hour:"H",day:"D",week:"S",month:"M",year:"A"},Zn=jl;var ql={time:"",open:"O ",high:"H ",low:"L ",close:"C ",volume:"Vol ",turnover:"Nilai: ",change:"Perubahan: ",second:"dtk",minute:"mnt",hour:"jam",day:"hr",week:"mg",month:"bln",year:"thn"},Qn=ql;var Zl={"zh-CN":Yn,"zh-TW":Hn,"en-US":zn,"ja-JP":Xn,"th-TH":Un,"ko-KR":Gn,"fr-FR":$n,"de-DE":jn,"pt-PT":qn,"es-ES":Zn,"id-ID":Qn};function pi(n,e){return Zl[e][n]??n}var Gt=class extends qe{drawImp(e){let t=this.getWidget(),r=t.getPane().getChart().getChartStore();if(r.getDataList().length===0)return;let i=r.getCrosshair(),o=t.getBounding(),a=r.getStyles(),s=a.candle,l=a.indicator;if(s.tooltip.showType==="rect"&&l.tooltip.showType==="rect"){let c=this.isDrawTooltip(i,s.tooltip),u=this.isDrawTooltip(i,l.tooltip);this._drawRectTooltip(e,c,u,s.tooltip.offsetTop);}else if(s.tooltip.showType==="standard"&&l.tooltip.showType==="standard"){let{offsetLeft:c,offsetTop:u,offsetRight:h}=s.tooltip,d=o.width-h,m=this._drawCandleStandardTooltip(e,c,u,d);this.drawIndicatorTooltip(e,c,m,d);}else if(s.tooltip.showType==="rect"&&l.tooltip.showType==="standard"){let{offsetLeft:c,offsetTop:u,offsetRight:h}=s.tooltip,d=o.width-h,m=this.drawIndicatorTooltip(e,c,u,d),p=this.isDrawTooltip(i,s.tooltip);this._drawRectTooltip(e,p,false,m);}else {let{offsetLeft:c,offsetTop:u,offsetRight:h}=s.tooltip,d=o.width-h,m=this._drawCandleStandardTooltip(e,c,u,d),p=this.isDrawTooltip(i,l.tooltip);this._drawRectTooltip(e,false,p,m);}}_drawCandleStandardTooltip(e,t,r,i){let o=this.getWidget().getPane().getChart().getChartStore(),s=o.getStyles().candle.tooltip,l=s.legend,c=0,u={x:t,y:r},h=o.getCrosshair();if(this.isDrawTooltip(h,s)){let d=s.title,m=this._getCandleTooltipLegends();if(d.show){let{type:g="",span:f=""}=o.getPeriod()??{},v=Yr(d.template,{...o.getSymbol(),period:`${f}${pi(g,o.getLocale())}`}),y=d.color;m.unshift({title:{text:"",color:y},value:{text:v,color:y}});}let p=this.classifyTooltipFeatures(s.features);c=this.drawStandardTooltipFeatures(e,p[0],u,null,t,c,i),c=this.drawStandardTooltipFeatures(e,p[1],u,null,t,c,i),m.length>0&&(c=this.drawStandardTooltipLegends(e,m,u,t,c,i,l)),c=this.drawStandardTooltipFeatures(e,p[2],u,null,t,c,i);}return u.y+c}_drawRectTooltip(e,t,r,i){let o=this.getWidget(),a=o.getPane(),s=a.getChart().getChartStore(),l=s.getStyles(),c=l.candle,u=l.indicator,h=c.tooltip,d=u.tooltip;if(t||r){let m=this._getCandleTooltipLegends(),{offsetLeft:p,offsetTop:g,offsetRight:f,offsetBottom:v}=h,{marginLeft:y,marginRight:b,marginTop:S,marginBottom:x,size:C,weight:T,family:A}=h.legend,{position:P,paddingLeft:R,paddingRight:D,paddingTop:E,paddingBottom:I,offsetLeft:k,offsetRight:F,offsetTop:W,offsetBottom:X,borderSize:Y,borderRadius:V,borderColor:O,color:te}=h.rect,G=0,$=0,H=0;t&&(e.font=se(C,T,A),m.forEach(ce=>{let Fe=ce.title,Ve=ce.value,at=`${Fe.text}${Ve.text}`,st=Ie(e,at)+y+b;G=Math.max(G,st);}),H+=(x+S+C)*m.length);let{marginLeft:Q,marginRight:le,marginTop:be,marginBottom:ge,size:ve,weight:ot,family:Ne}=d.legend,nt=[];if(r){let ce=s.getIndicatorsByPaneId(a.getId());e.font=se(ve,ot,Ne),ce.forEach(Fe=>{let Ve=this.getIndicatorTooltipData(Fe).legends;nt.push(Ve),Ve.forEach(at=>{let st=at.title,hr=at.value,ue=`${st.text}${hr.text}`,Se=Ie(e,ue)+Q+le;G=Math.max(G,Se),H+=be+ge+ve;});});}if($+=G,$!==0&&H!==0){let ce=s.getCrosshair(),Fe=o.getBounding(),Ve=a.getYAxisWidget().getBounding();$+=Y*2+R+D,H+=Y*2+E+I;let at=Fe.width/2,st=P==="pointer"&&ce.paneId===B.CANDLE,hr=(ce.realX??0)>at,ue=0;if(st){let he=ce.realX;hr?ue=he-F-$:ue=he+k;}else {let he=this.getWidget().getPane().getAxisComponent();hr?(ue=k+p,he.inside&&he.position==="left"&&(ue+=Ve.width)):(ue=Fe.width-F-$-f,he.inside&&he.position==="right"&&(ue-=Ve.width));}let Se=i+W;st&&(Se=ce.y-H/2,Se+H>Fe.height-X-v&&(Se=Fe.height-X-H-v),Se<i+W&&(Se=i+W+g)),this.createFigure({name:"rect",attrs:{x:ue,y:Se,width:$,height:H},styles:{style:"stroke_fill",color:te,borderColor:O,borderSize:Y,borderRadius:V}})?.draw(e);let ia=ue+Y+R+y,Le=Se+Y+E;if(t&&m.forEach(he=>{Le+=S;let dr=he.title;this.createFigure({name:"text",attrs:{x:ia,y:Le,text:dr.text},styles:{color:dr.color,size:C,family:A,weight:T}})?.draw(e);let bt=he.value;this.createFigure({name:"text",attrs:{x:ue+$-Y-b-D,y:Le,text:bt.text,align:"right"},styles:{color:bt.color,size:C,family:A,weight:T}})?.draw(e),Le+=C+x;}),r){let he=ue+Y+R+Q;nt.forEach(dr=>{dr.forEach(bt=>{Le+=be;let _i=bt.title,bi=bt.value;this.createFigure({name:"text",attrs:{x:he,y:Le,text:_i.text},styles:{color:_i.color,size:ve,family:Ne,weight:ot}})?.draw(e),this.createFigure({name:"text",attrs:{x:ue+$-Y-le-D,y:Le,text:bi.text,align:"right"},styles:{color:bi.color,size:ve,family:Ne,weight:ot}})?.draw(e),Le+=ve+ge;});});}}}}_getCandleTooltipLegends(){let e=this.getWidget().getPane().getChart().getChartStore(),t=e.getStyles().candle,r=e.getDataList(),i=e.getInnerFormatter(),o=e.getDecimalFold(),a=e.getThousandsSeparator(),s=e.getLocale(),{pricePrecision:l=q.PRICE,volumePrecision:c=q.VOLUME}=e.getSymbol()??{},u=e.getPeriod(),h=e.getCrosshair().dataIndex??r.length-1,d=t.tooltip,{color:m,defaultValue:p,template:g}=d.legend,f=r[h-1]??null,v=r[h],y=f?.close??v.close,b=v.close-y,S={...v,time:i.formatDate(v.timestamp,Sr[u?.timespan??"day"],"tooltip"),open:o.format(a.format(ee(v.open,l))),high:o.format(a.format(ee(v.high,l))),low:o.format(a.format(ee(v.low,l))),close:o.format(a.format(ee(v.close,l))),volume:o.format(a.format(i.formatBigNumber(ee(v.volume??p,c)))),turnover:o.format(a.format(ee(v.turnover??p,l))),change:y===0?p:`${a.format(ee(b/y*100))}%`};return (j(g)?g({prev:f,current:v,next:r[h+1]??null},t):g).map(({title:C,value:T})=>{let A={text:"",color:m};ae(C)?A={...C}:A.text=C,A.text=pi(A.text,s);let P={text:p,color:m};return ae(T)?P={...T}:P.text=T,_(/{change}/.exec(P.text))&&(P.color=b===0?t.priceMark.last.noChangeColor:b>0?t.priceMark.last.upColor:t.priceMark.last.downColor),P.text=Yr(P.text,S),{title:A,value:P}})}};var $t=class extends J{_activeFeatureInfo=null;_featureClickEvent=e=>()=>(this.getWidget().getPane().getChart().getChartStore().executeAction("onCrosshairFeatureClick",e),true);_featureMouseMoveEvent=e=>()=>(this._activeFeatureInfo=e,this.getWidget().setForceCursor("pointer"),true);constructor(e){super(e),this.registerEvent("mouseMoveEvent",t=>(this._activeFeatureInfo=null,this.getWidget().setForceCursor(null),false));}drawImp(e){let t=this.getWidget(),r=t.getPane(),i=t.getPane().getChart().getChartStore(),o=i.getCrosshair(),a=this.getWidget(),s=a.getPane().getAxisComponent();if(L(o.paneId)&&o.paneId===r.getId()&&s.isInCandle()){let l=i.getStyles().crosshair,c=l.horizontal.features;if(l.show&&l.horizontal.show&&c.length>0){let u=s.position==="right",h=a.getBounding(),d=0,m=l.horizontal.text;if(s.inside&&m.show){let f=s.convertFromPixel(o.y),v=s.getRange(),y=s.displayValueToText(s.realValueToDisplayValue(s.valueToRealValue(f,{range:v}),{range:v}),i.getSymbol()?.pricePrecision??q.PRICE);y=i.getDecimalFold().format(i.getThousandsSeparator().format(y)),d=m.paddingLeft+ie(y,m.size,m.weight,m.family)+m.paddingRight;}let p=d;u&&(p=h.width-d);let g=o.y;c.forEach(f=>{let{marginLeft:v=0,marginTop:y=0,marginRight:b=0,paddingLeft:S=0,paddingTop:x=0,paddingRight:C=0,paddingBottom:T=0,color:A,activeColor:P,backgroundColor:R,activeBackgroundColor:D,borderRadius:E,size:I=0,type:k,content:F}=f,W=I;if(k==="icon_font"){let O=F;W=S+ie(O.code,I,"normal",O.family)+C;}u?p-=W+b:p+=v;let X=A,Y=R;this._activeFeatureInfo?.feature.id===f.id&&(X=P??A,Y=D??R);let V={mouseDownEvent:this._featureClickEvent({crosshair:o,feature:f}),mouseMoveEvent:this._featureMouseMoveEvent({crosshair:o,feature:f})};if(k==="icon_font"){let O=F;this.createFigure({name:"text",attrs:{text:O.code,x:p,y:g+y,baseline:"middle"},styles:{paddingLeft:S,paddingTop:x,paddingRight:C,paddingBottom:T,borderRadius:E,size:I,family:O.family,color:X,backgroundColor:Y}},V)?.draw(e);}else {this.createFigure({name:"rect",attrs:{x:p,y:g+y-I/2,width:I,height:I},styles:{paddingLeft:S,paddingTop:x,paddingRight:C,paddingBottom:T,color:Y}},V)?.draw(e);let O=F;this.createFigure({name:"path",attrs:{path:O.path,x:p,y:g+y+x-I/2,width:I,height:I},styles:{style:O.style,lineWidth:O.lineWidth,color:X}})?.draw(e);}u?p-=v:p+=W+b;});}}}};var jt=class extends Qe{_candleBarView=new je(this);_candleAreaView=new zt(this);_candleHighLowPriceView=new Xt(this);_candleLastPriceLineView=new Ut(this);_crosshairFeatureView=new $t(this);constructor(e,t){super(e,t),this.addChild(this._candleBarView),this.addChild(this._crosshairFeatureView);}updateMainContent(e){this.getPane().getChart().getStyles().candle.type!=="area"?(this._candleBarView.draw(e),this._candleHighLowPriceView.draw(e),this._candleAreaView.stopAnimation()):this._candleAreaView.draw(e),this._candleLastPriceLineView.draw(e);}updateOverlayContent(e){this._crosshairFeatureView.draw(e);}createTooltipView(){return new Gt(this)}destroy(){Wn(this),Fr(this),kr(this),super.destroy();}};var Ke=class extends J{drawImp(e,t){let r=this.getWidget(),i=r.getPane(),o=r.getBounding(),a=i.getAxisComponent(),s=this.getAxisStyles(i.getChart().getStyles());if(s.show&&(s.axisLine.show&&this.createFigure({name:"line",attrs:this.createAxisLine(o,s),styles:s.axisLine})?.draw(e),!t[0])){let l=a.getTicks();if(s.tickLine.show&&this.createTickLines(l,o,s).forEach(u=>{this.createFigure({name:"line",attrs:u,styles:s.tickLine})?.draw(e);}),s.tickText.show){let c=this.createTickTexts(l,o,s),u=r.getTextRenderer();if(u!==null){let h=s.tickText,d=h.color??"#888888",m=h.size??12,p=h.family??"Helvetica Neue";for(let g of c)u.queue({text:g.text,x:g.x,y:g.y,fontSize:m,fontFamily:p,color:d,align:g.align,baseline:g.baseline});}else this.createFigure({name:"text",attrs:c,styles:s.tickText})?.draw(e);}}}};var qt=class extends Ke{getAxisStyles(e){return e.yAxis}createAxisLine(e,t){let r=this.getWidget().getPane().getAxisComponent(),i=t.axisLine.size,o=0;return r.isFromZero()?o=0:o=e.width-i,{coordinates:[{x:o,y:0},{x:o,y:e.height}]}}createTickLines(e,t,r){let i=this.getWidget().getPane().getAxisComponent(),o=r.axisLine,a=r.tickLine,s=0,l=0;return i.isFromZero()?(s=0,o.show&&(s+=o.size),l=s+a.length):(s=t.width,o.show&&(s-=o.size),l=s-a.length),e.map(c=>{let u=i instanceof de?i.tickCoord(c):c.coord;return {coordinates:[{x:s,y:u},{x:l,y:u}]}})}createTickTexts(e,t,r){let i=this.getWidget().getPane().getAxisComponent(),o=r.axisLine,a=r.tickLine,s=r.tickText,l=0;i.isFromZero()?(l=s.marginStart,o.show&&(l+=o.size),a.show&&(l+=a.length)):(l=t.width-s.marginEnd,o.show&&(l-=o.size),a.show&&(l-=a.length));let c=this.getWidget().getPane().getAxisComponent().isFromZero()?"left":"right";return e.map(u=>{let h=i instanceof de?i.tickCoord(u):u.coord;return {x:l,y:h,text:u.text,align:c,baseline:"middle"}})}};var Zt=class extends J{drawImp(e){let t=this.getWidget(),r=t.getPane(),i=t.getBounding(),o=r.getChart().getChartStore(),a=o.getStyles().candle.priceMark,s=a.last,l=s.text;if(a.show&&s.show&&l.show){let c=o.getSymbol()?.pricePrecision??q.PRICE,u=r.getAxisComponent(),h=o.getDataList(),d=h[h.length-1];if(_(d)){let{close:m,open:p}=d,g=s.compareRule==="current_open"?p:h[h.length-2]?.close??m,f=u.convertToNicePixel(m),v="";m>g?v=s.upColor:m<g?v=s.downColor:v=s.noChangeColor;let y=0,b="left";u.isFromZero()?(y=0,b="left"):(y=i.width,b="right");let S=[],x=u.getRange(),C=u.displayValueToText(u.realValueToDisplayValue(u.valueToRealValue(m,{range:x}),{range:x}),c);C=o.getDecimalFold().format(o.getThousandsSeparator().format(C));let{paddingLeft:T,paddingRight:A,paddingTop:P,paddingBottom:R,size:D,family:E,weight:I}=l,k=T+ie(C,D,I,E)+A,F=P+D+R;S.push({name:"text",attrs:{x:y,y:f,width:k,height:F,text:C,align:b,baseline:"middle"},styles:{...l,backgroundColor:v}});let W=o.getInnerFormatter().formatExtendText,X=D/2,Y=f-X-P,V=f+X+R;s.extendTexts.forEach((O,te)=>{let G=W({type:"last_price",data:d,index:te});if(G.length>0&&O.show){let $=O.size/2,H=0;O.position==="above_price"?(Y-=O.paddingBottom+$,H=Y,Y-=$+O.paddingTop):(V+=O.paddingTop+$,H=V,V+=$+O.paddingBottom),k=Math.max(k,O.paddingLeft+ie(G,O.size,O.weight,O.family)+O.paddingRight),S.push({name:"text",attrs:{x:y,y:H,width:k,height:O.paddingTop+O.size+O.paddingBottom,text:G,align:b,baseline:"middle"},styles:{...O,backgroundColor:v}});}}),S.forEach(O=>{O.attrs.width=k,this.createFigure(O)?.draw(e);});}}}};var Qt=class extends J{drawImp(e){let t=this.getWidget(),r=t.getPane(),i=t.getBounding(),o=r.getChart().getChartStore(),a=o.getStyles().indicator,s=a.lastValueMark,l=s.text;if(s.show){let c=r.getAxisComponent(),u=c.getRange(),d=o.getDataList().length-1,m=o.getIndicatorsByPaneId(r.getId()),p=o.getInnerFormatter(),g=o.getDecimalFold(),f=o.getThousandsSeparator();m.forEach(v=>{let b=v.result[d]??{};if(_(b)&&v.visible){let S=v.precision;ct(v,d,a,(x,C)=>{let T=b[x.key];if(w(T)){let A=c.convertToNicePixel(T),P=c.displayValueToText(c.realValueToDisplayValue(c.valueToRealValue(T,{range:u}),{range:u}),S);v.shouldFormatBigNumber&&(P=p.formatBigNumber(P)),P=g.format(f.format(P));let R=0,D="left";c.isFromZero()?(R=0,D="left"):(R=i.width,D="right");let E={...l,backgroundColor:C.color},I={x:R,y:A,text:P,align:D,baseline:"middle"},k=t.getTextRenderer();if(k!==null){let F=E.backgroundColor;if(F){let W=gt(I,E);Ue(e,[W],{...E,color:F});}k.queue({text:P,x:R,y:A,fontSize:E.size??12,fontFamily:E.family??"Helvetica Neue",color:E.color??"#ffffff",align:D,baseline:"middle",paddingLeft:E.paddingLeft,paddingTop:E.paddingTop});}else this.createFigure({name:"text",attrs:I,styles:E})?.draw(e);}});}});}}};var Je=class extends Ze{coordinateToPointTimestampDataIndexFlag(){return false}drawDefaultFigures(e,t,r){this.drawFigures(e,t,this.getDefaultFigures(t,r));}getDefaultFigures(e,t){let r=this.getWidget(),i=r.getPane(),o=i.getChart().getChartStore(),a=o.getClickOverlayInfo(),s=[];if(e.needDefaultYAxisFigure&&e.id===a.overlay?.id&&a.paneId===i.getId()){let l=i.getAxisComponent(),c=r.getBounding(),u=Number.MAX_SAFE_INTEGER,h=Number.MIN_SAFE_INTEGER,d=l.isFromZero(),m="left",p=0;d?(m="left",p=0):(m="right",p=c.width);let g=o.getDecimalFold(),f=o.getThousandsSeparator();t.forEach((v,y)=>{let b=e.points[y];if(w(b.value)){u=Math.min(u,v.y),h=Math.max(h,v.y);let S=g.format(f.format(ee(b.value,o.getSymbol()?.pricePrecision??q.PRICE)));s.push({type:"text",attrs:{x:p,y:v.y,text:S,align:m,baseline:"middle"},ignoreEvent:true});}}),t.length>1&&s.unshift({type:"rect",attrs:{x:0,y:u,width:c.width,height:h-u},ignoreEvent:true});}return s}getFigures(e,t){let r=this.getWidget(),i=r.getPane(),o=i.getChart(),a=i.getAxisComponent(),s=o.getXAxisPane().getAxisComponent(),l=r.getBounding();return e.createYAxisFigures?.({chart:o,overlay:e,coordinates:t,bounding:l,xAxis:s,yAxis:a})??[]}};var et=class extends J{drawImp(e){let t=this.getWidget(),r=t.getPane(),i=t.getPane().getChart().getChartStore(),o=i.getCrosshair();if(L(o.paneId)&&this.compare(o,r.getId())){let a=i.getStyles().crosshair;if(a.show){let s=this.getDirectionStyles(a),l=s.text;if(s.show&&l.show){let c=t.getBounding(),u=r.getAxisComponent(),h=this.getText(o,i,u);e.font=se(l.size,l.weight,l.family);let d=e.measureText(h).width,m=this.getTextAttrs(h,d,o,c,u,l),p=t.getTextRenderer();if(p!==null){if(l.backgroundColor){let g=gt(m,l);Ue(e,[g],{...l,color:l.backgroundColor});}p.queue({text:h,x:m.x,y:m.y,fontSize:l.size,fontFamily:l.family,color:l.color,align:m.align,baseline:m.baseline,paddingLeft:l.paddingLeft,paddingTop:l.paddingTop});}else this.createFigure({name:"text",attrs:m,styles:l})?.draw(e);}}}}compare(e,t){return e.paneId===t}getDirectionStyles(e){return e.horizontal}getText(e,t,r){let i=r,o=r.convertFromPixel(e.y),a=0,s=false;i.isInCandle()?a=t.getSymbol()?.pricePrecision??q.PRICE:t.getIndicatorsByPaneId(e.paneId).forEach(h=>{a=Math.max(h.precision,a),s||=h.shouldFormatBigNumber;});let l=i.getRange(),c=i.displayValueToText(i.realValueToDisplayValue(i.valueToRealValue(o,{range:l}),{range:l}),a);return s&&(c=t.getInnerFormatter().formatBigNumber(c)),t.getDecimalFold().format(t.getThousandsSeparator().format(c))}getTextAttrs(e,t,r,i,o,a){let s=o,l=0,c="left";return s.isFromZero()?(l=0,c="left"):(l=i.width,c="right"),{x:l,y:r.y,text:e,align:c,baseline:"middle"}}};var Kt=class extends ke{_yAxisView=new qt(this);_candleLastPriceLabelView=new Zt(this);_indicatorLastValueView=new Qt(this);_overlayYAxisView=new Je(this);_crosshairHorizontalLabelView=new et(this);constructor(e,t){super(e,t),this.setCursor("ns-resize"),this.addChild(this._overlayYAxisView);}getName(){return N.Y_AXIS}updateMain(e){let t=this.getPane().getOptions().state==="minimize";this._yAxisView.draw(e,t),t||(this.getPane().getAxisComponent().isInCandle()&&this._candleLastPriceLabelView.draw(e),this._indicatorLastValueView.draw(e));}updateOverlay(e){this.getPane().getOptions().state!=="minimize"&&(this._overlayYAxisView.draw(e),this._crosshairHorizontalLabelView.draw(e));}};var tt=class{_container;_id;_chart;_bounding=He();_originalBounding=He();_visible=true;constructor(e,t){this._chart=e,this._id=t,this._container=oe("div",{width:"100%",margin:"0",padding:"0",position:"relative",overflow:"hidden",boxSizing:"border-box",backgroundColor:"inherit"});}getContainer(){return this._container}setVisible(e){this._visible!==e&&(this._container.style.display=e?"block":"none",this._visible=e);}getVisible(){return this._visible}getId(){return this._id}getChart(){return this._chart}getBounding(){return this._bounding}setOriginalBounding(e){U(this._originalBounding,e);}getOriginalBounding(){return this._originalBounding}update(e){this._bounding.height!==this._container.clientHeight&&(this._container.style.height=`${this._bounding.height}px`),this.updateImp(e??3,this._container,this._bounding);}};var rt=class extends tt{_mainWidget;_yAxisWidget=null;_axis;_options={id:"",minHeight:30,dragEnabled:true,order:0,height:100,state:"normal",axis:{name:"normal",scrollZoomEnabled:true}};constructor(e,t,r){super(e,t);let i=this.getContainer();this._mainWidget=this.createMainWidget(i),this._yAxisWidget=this.createYAxisWidget(i),this.setOptions(r);}setOptions(e){let t=this.getId();if(t===B.CANDLE||t===B.X_AXIS){let o=e.axis?.name;(!_(this._axis)||_(o)&&this._options.axis.name!==o)&&(this._axis=this.createAxisComponent(o??"normal"));}else _(this._axis)||(this._axis=this.createAxisComponent("normal"));this._axis instanceof de&&this._axis.setAutoCalcTickFlag(true),U(this._options,e),this._axis.override({...this._options.axis,name:e.axis?.name??"normal"});let r=null,i="default";return this.getId()===B.X_AXIS?(r=this.getMainWidget().getContainer(),i="ew-resize"):(r=this.getYAxisWidget().getContainer(),i="ns-resize"),e.axis?.scrollZoomEnabled??true?r.style.cursor=i:r.style.cursor="default",this}getOptions(){return this._options}getAxisComponent(){return this._axis}setBounding(e,t,r,i){U(this.getBounding(),e);let o={};_(e.height)&&(o.height=e.height),_(e.top)&&(o.top=e.top),this._mainWidget.setBounding(o);let a=_(t);return a&&this._mainWidget.setBounding(t),_(this._yAxisWidget)&&(this._yAxisWidget.setBounding(o),this._axis.position==="left"?_(r)&&this._yAxisWidget.setBounding({...r,left:0}):_(i)&&(this._yAxisWidget.setBounding(i),a&&this._yAxisWidget.setBounding({left:(t.left??0)+(t.width??0)+(t.right??0)-(i.width??0)}))),this}getMainWidget(){return this._mainWidget}getYAxisWidget(){return this._yAxisWidget}updateImp(e){this._mainWidget.update(e),this._yAxisWidget?.update(e);}destroy(){this.getContainer().style.willChange="",this._mainWidget.destroy(),this._yAxisWidget?.destroy();}getImage(e){let{width:t,height:r}=this.getBounding(),i=oe("canvas",{width:`${t}px`,height:`${r}px`,boxSizing:"border-box"}),o=i.getContext("2d"),a=z(i);i.width=t*a,i.height=r*a,o.scale(a,a);let s=this._mainWidget.getBounding();if(o.drawImage(this._mainWidget.getImage(e),s.left,0,s.width,s.height),this._yAxisWidget!==null){let l=this._yAxisWidget.getBounding();o.drawImage(this._yAxisWidget.getImage(e),l.left,0,l.width,l.height);}return i}createYAxisWidget(e){return null}};var it=class extends rt{createAxisComponent(e){let t=Go(e??"default");return new t(this)}createMainWidget(e){return new Qe(e,this)}createYAxisWidget(e){return new Kt(e,this)}};var er=class extends it{createMainWidget(e){return new jt(e,this)}};var tr=class extends Ke{getAxisStyles(e){return e.xAxis}createAxisLine(e){return {coordinates:[{x:0,y:0},{x:e.width,y:0}]}}createTickLines(e,t,r){let i=r.tickLine,o=r.axisLine.size;return e.map(a=>({coordinates:[{x:a.coord,y:0},{x:a.coord,y:o+i.length}]}))}createTickTexts(e,t,r){let i=r.tickText,o=r.axisLine.size,a=r.tickLine.length;return e.map(s=>({x:s.coord,y:o+a+i.marginStart,text:s.text,align:"center",baseline:"top"}))}};var rr=class extends Je{coordinateToPointTimestampDataIndexFlag(){return true}coordinateToPointValueFlag(){return false}getCompleteOverlays(){return this.getWidget().getPane().getChart().getChartStore().getOverlaysByPaneId()}getProgressOverlay(){return this.getWidget().getPane().getChart().getChartStore().getProgressOverlayInfo()?.overlay??null}getDefaultFigures(e,t){let r=[],i=this.getWidget(),a=i.getPane().getChart().getChartStore(),s=a.getClickOverlayInfo();if(e.needDefaultXAxisFigure&&e.id===s.overlay?.id){let l=Number.MAX_SAFE_INTEGER,c=Number.MIN_SAFE_INTEGER;t.forEach((u,h)=>{l=Math.min(l,u.x),c=Math.max(c,u.x);let d=e.points[h];if(w(d.timestamp)){let m=a.getInnerFormatter().formatDate(d.timestamp,"YYYY-MM-DD HH:mm","crosshair");r.push({type:"text",attrs:{x:u.x,y:0,text:m,align:"center"},ignoreEvent:true});}}),t.length>1&&r.unshift({type:"rect",attrs:{x:l,y:0,width:c-l,height:i.getBounding().height},ignoreEvent:true});}return r}getFigures(e,t){let r=this.getWidget(),i=r.getPane(),o=i.getChart(),a=i.getAxisComponent(),s=o.getXAxisPane().getAxisComponent(),l=r.getBounding();return e.createXAxisFigures?.({chart:o,overlay:e,coordinates:t,bounding:l,xAxis:s,yAxis:a})??[]}};var ir=class extends et{compare(e){return _(e.timestamp)}getDirectionStyles(e){return e.vertical}getText(e,t){let r=e.timestamp;return t.getInnerFormatter().formatDate(r,Sr[t.getPeriod()?.timespan??"day"],"crosshair")}getTextAttrs(e,t,r,i,o,a){let s=r.realX,l=0,c="center";return s-t/2-a.paddingLeft<0?(l=0,c="left"):s+t/2+a.paddingRight>i.width?(l=i.width,c="right"):l=s,{x:l,y:0,text:e,align:c,baseline:"top"}}};var or=class extends ke{_xAxisView=new tr(this);_overlayXAxisView=new rr(this);_crosshairVerticalLabelView=new ir(this);constructor(e,t){super(e,t),this.setCursor("ew-resize"),this.addChild(this._overlayXAxisView);}getName(){return N.X_AXIS}updateMain(e){this._xAxisView.draw(e);}updateOverlay(e){this._overlayXAxisView.draw(e),this._crosshairVerticalLabelView.draw(e);}};var nr=class extends rt{createAxisComponent(e){let t=jo(e);return new t(this)}createMainWidget(e){return new or(e,this)}};function Kn(n,e){let t=0;return function(){let r=Date.now();r-t>(e)&&(n.apply(this,arguments),t=r);}}var ar=class extends Xe{_dragFlag=false;_dragStartY=0;_topPaneHeight=0;_bottomPaneHeight=0;_topPane=null;_bottomPane=null;constructor(e,t){super(e,t),this.registerEvent("touchStartEvent",this._mouseDownEvent.bind(this)).registerEvent("touchMoveEvent",this._pressedMouseMoveEvent.bind(this)).registerEvent("touchEndEvent",this._mouseUpEvent.bind(this)).registerEvent("mouseDownEvent",this._mouseDownEvent.bind(this)).registerEvent("mouseUpEvent",this._mouseUpEvent.bind(this)).registerEvent("pressedMouseMoveEvent",this._pressedMouseMoveEvent.bind(this)).registerEvent("mouseEnterEvent",this._mouseEnterEvent.bind(this)).registerEvent("mouseLeaveEvent",this._mouseLeaveEvent.bind(this));}getName(){return N.SEPARATOR}_mouseDownEvent(e){this._dragFlag=true,this._dragStartY=e.pageY;let t=this.getPane(),r=t.getChart();this._topPane=t.getTopPane(),this._bottomPane=t.getBottomPane();let i=r.getDrawPanes();if(this._topPane.getOptions().state==="minimize"){let o=i.findIndex(a=>a.getId()===this._topPane?.getId());for(let a=o-1;a>-1;a--){let s=i[a];if(s.getOptions().state!=="minimize"){this._topPane=s;break}}}if(this._bottomPane.getOptions().state==="minimize"){let o=i.findIndex(a=>a.getId()===this._bottomPane?.getId());for(let a=o+1;a<i.length;a++){let s=i[a];if(s.getOptions().state!=="minimize"){this._bottomPane=s;break}}}return this._topPaneHeight=this._topPane.getBounding().height,this._bottomPaneHeight=this._bottomPane.getBounding().height,true}_mouseUpEvent(){return this._dragFlag=false,this._topPane=null,this._bottomPane=null,this._topPaneHeight=0,this._bottomPaneHeight=0,this._mouseLeaveEvent()}_pressedMouseMoveEvent=Kn(this._pressedTouchMouseMoveEvent,20);_pressedTouchMouseMoveEvent(e){let t=e.pageY-this._dragStartY,r=t<0;if(_(this._topPane)&&_(this._bottomPane)){let i=this._bottomPane.getOptions();if(this._topPane.getOptions().state!=="minimize"&&i.state!=="minimize"&&i.dragEnabled){let o=null,a=null,s=0,l=0;r?(o=this._topPane,a=this._bottomPane,s=this._topPaneHeight,l=this._bottomPaneHeight):(o=this._bottomPane,a=this._topPane,s=this._bottomPaneHeight,l=this._topPaneHeight);let c=o.getOptions().minHeight;if(s>c){let u=Math.max(s-Math.abs(t),c),h=s-u;o.setBounding({height:u}),a.setBounding({height:l+h});let d=this.getPane(),m=d.getChart();m.getChartStore().executeAction("onPaneDrag",{paneId:d.getId()}),m.layout({measureHeight:true,measureWidth:true,update:true,buildYAxisTick:true,forceBuildYAxisTick:true});}}}return true}_mouseEnterEvent(){let e=this.getPane();if(e.getBottomPane().getOptions().dragEnabled){let i=e.getChart().getStyles().separator;return this.getContainer().style.background=i.activeBackgroundColor,true}return false}_mouseLeaveEvent(){return this._dragFlag?false:(this.getContainer().style.background="transparent",true)}createContainer(){return oe("div",{width:"100%",height:`${ze}px`,margin:"0",padding:"0",position:"absolute",top:"-3px",zIndex:"20",boxSizing:"border-box",cursor:"ns-resize"})}updateImp(e,t,r){if(r===4||r===2){let i=this.getPane().getChart().getStyles().separator;e.style.top=`${-Math.floor((ze-i.size)/2)}px`,e.style.height=`${ze}px`;}}};var sr=class extends tt{_topPane;_bottomPane;_separatorWidget;constructor(e,t,r,i){super(e,t),this.getContainer().style.overflow="",this._topPane=r,this._bottomPane=i,this._separatorWidget=new ar(this.getContainer(),this);}setBounding(e){return U(this.getBounding(),e),this}getTopPane(){return this._topPane}setTopPane(e){return this._topPane=e,this}getBottomPane(){return this._bottomPane}setBottomPane(e){return this._bottomPane=e,this}getWidget(){return this._separatorWidget}getImage(e){let{width:t,height:r}=this.getBounding(),i=this.getChart().getStyles().separator,o=oe("canvas",{width:`${t}px`,height:`${r}px`,boxSizing:"border-box"}),a=o.getContext("2d"),s=z(o);return o.width=t*s,o.height=r*s,a.scale(s,s),a.fillStyle=i.color,a.fillRect(0,0,t,r),o}updateImp(e,t,r){if(e===4||e===2){let i=this.getChart().getStyles().separator;t.style.backgroundColor=i.color,t.style.height=`${r.height}px`,t.style.marginLeft=`${r.left}px`,t.style.width=`${r.width}px`,this._separatorWidget.update(e);}}};function fi(){return typeof window>"u"?false:window.navigator.userAgent.toLowerCase().includes("firefox")}function Or(){return typeof window>"u"?false:/iPhone|iPad|iPod|iOS/.test(window.navigator.userAgent)}var Nr={ResetClick:500,LongTap:500,PreventFiresTouchEvents:500},vt={CancelClick:5,CancelTap:5,DoubleClick:5,DoubleTap:30},lr={Left:0,Middle:1,Right:2},Jn=10,cr=class{_target;_handler;_options;_clickCount=0;_clickTimeoutId=null;_clickCoordinate={x:Number.NEGATIVE_INFINITY,y:Number.POSITIVE_INFINITY};_tapCount=0;_tapTimeoutId=null;_tapCoordinate={x:Number.NEGATIVE_INFINITY,y:Number.POSITIVE_INFINITY};_longTapTimeoutId=null;_longTapActive=false;_mouseMoveStartCoordinate=null;_touchMoveStartCoordinate=null;_touchMoveExceededManhattanDistance=false;_cancelClick=false;_cancelTap=false;_unsubscribeOutsideMouseEvents=null;_unsubscribeOutsideTouchEvents=null;_unsubscribeMobileSafariEvents=null;_unsubscribeMousemove=null;_unsubscribeMouseWheel=null;_unsubscribeContextMenu=null;_unsubscribeRootMouseEvents=null;_unsubscribeRootTouchEvents=null;_startPinchMiddleCoordinate=null;_startPinchDistance=0;_pinchPrevented=false;_preventTouchDragProcess=false;_mousePressed=false;_lastTouchEventTimeStamp=0;_activeTouchId=null;_acceptMouseLeave=!Or();constructor(e,t,r){this._target=e,this._handler=t,this._options=r,this._init();}destroy(){this._unsubscribeOutsideMouseEvents!==null&&(this._unsubscribeOutsideMouseEvents(),this._unsubscribeOutsideMouseEvents=null),this._unsubscribeOutsideTouchEvents!==null&&(this._unsubscribeOutsideTouchEvents(),this._unsubscribeOutsideTouchEvents=null),this._unsubscribeMousemove!==null&&(this._unsubscribeMousemove(),this._unsubscribeMousemove=null),this._unsubscribeMouseWheel!==null&&(this._unsubscribeMouseWheel(),this._unsubscribeMouseWheel=null),this._unsubscribeContextMenu!==null&&(this._unsubscribeContextMenu(),this._unsubscribeContextMenu=null),this._unsubscribeRootMouseEvents!==null&&(this._unsubscribeRootMouseEvents(),this._unsubscribeRootMouseEvents=null),this._unsubscribeRootTouchEvents!==null&&(this._unsubscribeRootTouchEvents(),this._unsubscribeRootTouchEvents=null),this._unsubscribeMobileSafariEvents!==null&&(this._unsubscribeMobileSafariEvents(),this._unsubscribeMobileSafariEvents=null),this._clearLongTapTimeout(),this._resetClickTimeout();}_mouseEnterHandler(e){this._unsubscribeMousemove?.(),this._unsubscribeMouseWheel?.(),this._unsubscribeContextMenu?.();let t=this._mouseMoveHandler.bind(this);this._unsubscribeMousemove=()=>{this._target.removeEventListener("mousemove",t);},this._target.addEventListener("mousemove",t);let r=this._mouseWheelHandler.bind(this);this._unsubscribeMouseWheel=()=>{this._target.removeEventListener("wheel",r);},this._target.addEventListener("wheel",r,{passive:false});let i=this._contextMenuHandler.bind(this);this._unsubscribeContextMenu=()=>{this._target.removeEventListener("contextmenu",i);},this._target.addEventListener("contextmenu",i,{passive:false}),!this._firesTouchEvents(e)&&(this._processEvent(this._makeCompatEvent(e),this._handler.mouseEnterEvent),this._acceptMouseLeave=true);}_resetClickTimeout(){this._clickTimeoutId!==null&&clearTimeout(this._clickTimeoutId),this._clickCount=0,this._clickTimeoutId=null,this._clickCoordinate={x:Number.NEGATIVE_INFINITY,y:Number.POSITIVE_INFINITY};}_resetTapTimeout(){this._tapTimeoutId!==null&&clearTimeout(this._tapTimeoutId),this._tapCount=0,this._tapTimeoutId=null,this._tapCoordinate={x:Number.NEGATIVE_INFINITY,y:Number.POSITIVE_INFINITY};}_mouseMoveHandler(e){if(this._mousePressed||this._touchMoveStartCoordinate!==null||this._firesTouchEvents(e))return;let r=e.getCoalescedEvents?.(),i=r!==void 0&&r.length>0?r[r.length-1]:e;this._processEvent(this._makeCompatEvent(i),this._handler.mouseMoveEvent),this._acceptMouseLeave=true;}_mouseWheelHandler(e){if(Math.abs(e.deltaX)>Math.abs(e.deltaY)){if(!_(this._handler.mouseWheelHortEvent)||(this._preventDefault(e),Math.abs(e.deltaX)===0))return;this._handler.mouseWheelHortEvent(this._makeCompatEvent(e),-e.deltaX);}else {if(!_(this._handler.mouseWheelVertEvent))return;let t=-(e.deltaY/100);if(t===0)return;switch(this._preventDefault(e),e.deltaMode){case e.DOM_DELTA_PAGE:{t*=120;break}case e.DOM_DELTA_LINE:{t*=32;break}}if(t!==0){let r=Math.sign(t)*Math.min(1,Math.abs(t));this._handler.mouseWheelVertEvent(this._makeCompatEvent(e),r);}}}_contextMenuHandler(e){this._preventDefault(e);}_touchMoveHandler(e){let t=this._touchWithId(e.changedTouches,this._activeTouchId);if(t===null||(this._lastTouchEventTimeStamp=this._eventTimeStamp(e),this._startPinchMiddleCoordinate!==null)||this._preventTouchDragProcess)return;this._pinchPrevented=true;let r=this._mouseTouchMoveWithDownInfo(this._getCoordinate(t),this._touchMoveStartCoordinate),{xOffset:i,yOffset:o,manhattanDistance:a}=r;if(!(!this._touchMoveExceededManhattanDistance&&a<vt.CancelTap)){if(!this._touchMoveExceededManhattanDistance){let s=i*.5,l=o>=s&&!this._options.treatVertDragAsPageScroll(),c=s>o&&!this._options.treatHorzDragAsPageScroll();!l&&!c&&(this._preventTouchDragProcess=true),this._touchMoveExceededManhattanDistance=true,this._cancelTap=true,this._clearLongTapTimeout(),this._resetTapTimeout();}this._preventTouchDragProcess||this._processEvent(this._makeCompatEvent(e,t),this._handler.touchMoveEvent);}}_mouseMoveWithDownHandler(e){if(e.button!==lr.Left)return;let t=this._mouseTouchMoveWithDownInfo(this._getCoordinate(e),this._mouseMoveStartCoordinate),{manhattanDistance:r}=t;r>=vt.CancelClick&&(this._cancelClick=true,this._resetClickTimeout()),this._cancelClick&&this._processEvent(this._makeCompatEvent(e),this._handler.pressedMouseMoveEvent);}_mouseTouchMoveWithDownInfo(e,t){let r=Math.abs(t.x-e.x),i=Math.abs(t.y-e.y),o=r+i;return {xOffset:r,yOffset:i,manhattanDistance:o}}_onFirefoxOutsideMouseUp=e=>{this._mouseUpHandler(e);};_onMobileSafariDoubleClick=e=>{if(this._firesTouchEvents(e)){if(++this._tapCount,this._tapTimeoutId!==null&&this._tapCount>1){let{manhattanDistance:t}=this._mouseTouchMoveWithDownInfo(this._getCoordinate(e),this._tapCoordinate);t<vt.DoubleTap&&!this._cancelTap&&this._processEvent(this._makeCompatEvent(e),this._handler.doubleTapEvent),this._resetTapTimeout();}}else if(++this._clickCount,this._clickTimeoutId!==null&&this._clickCount>1){let{manhattanDistance:t}=this._mouseTouchMoveWithDownInfo(this._getCoordinate(e),this._clickCoordinate);t<vt.DoubleClick&&!this._cancelClick&&this._processEvent(this._makeCompatEvent(e),this._handler.mouseDoubleClickEvent),this._resetClickTimeout();}};_touchEndHandler(e){let t=this._touchWithId(e.changedTouches,this._activeTouchId);if(t===null&&e.touches.length===0&&(t=e.changedTouches[0]),t===null)return;this._activeTouchId=null,this._lastTouchEventTimeStamp=this._eventTimeStamp(e),this._clearLongTapTimeout(),this._touchMoveStartCoordinate=null,this._unsubscribeRootTouchEvents!==null&&(this._unsubscribeRootTouchEvents(),this._unsubscribeRootTouchEvents=null);let r=this._makeCompatEvent(e,t);if(this._processEvent(r,this._handler.touchEndEvent),++this._tapCount,this._tapTimeoutId!==null&&this._tapCount>1){let{manhattanDistance:i}=this._mouseTouchMoveWithDownInfo(this._getCoordinate(t),this._tapCoordinate);i<vt.DoubleTap&&!this._cancelTap&&this._processEvent(r,this._handler.doubleTapEvent),this._resetTapTimeout();}else this._cancelTap||(this._processEvent(r,this._handler.tapEvent),_(this._handler.tapEvent)&&this._preventDefault(e));this._tapCount===0&&this._preventDefault(e),e.touches.length===0&&this._longTapActive&&(this._longTapActive=false,this._preventDefault(e));}_mouseUpHandler(e){if(e.button!==lr.Left)return;let t=this._makeCompatEvent(e);if(this._mouseMoveStartCoordinate=null,this._mousePressed=false,this._unsubscribeRootMouseEvents!==null&&(this._unsubscribeRootMouseEvents(),this._unsubscribeRootMouseEvents=null),fi()&&this._target.ownerDocument.documentElement.removeEventListener("mouseleave",this._onFirefoxOutsideMouseUp),!this._firesTouchEvents(e))if(this._processEvent(t,this._handler.mouseUpEvent),++this._clickCount,this._clickTimeoutId!==null&&this._clickCount>1){let{manhattanDistance:r}=this._mouseTouchMoveWithDownInfo(this._getCoordinate(e),this._clickCoordinate);r<vt.DoubleClick&&!this._cancelClick&&this._processEvent(t,this._handler.mouseDoubleClickEvent),this._resetClickTimeout();}else this._cancelClick||this._processEvent(t,this._handler.mouseClickEvent);}_clearLongTapTimeout(){this._longTapTimeoutId!==null&&(clearTimeout(this._longTapTimeoutId),this._longTapTimeoutId=null);}_touchStartHandler(e){if(this._activeTouchId!==null)return;let t=e.changedTouches[0];this._activeTouchId=t.identifier,this._lastTouchEventTimeStamp=this._eventTimeStamp(e);let r=this._target.ownerDocument.documentElement;this._cancelTap=false,this._touchMoveExceededManhattanDistance=false,this._preventTouchDragProcess=false,this._touchMoveStartCoordinate=this._getCoordinate(t),this._unsubscribeRootTouchEvents!==null&&(this._unsubscribeRootTouchEvents(),this._unsubscribeRootTouchEvents=null);{let i=this._touchMoveHandler.bind(this),o=this._touchEndHandler.bind(this);this._unsubscribeRootTouchEvents=()=>{r.removeEventListener("touchmove",i),r.removeEventListener("touchend",o);},r.addEventListener("touchmove",i,{passive:false}),r.addEventListener("touchend",o,{passive:false}),this._clearLongTapTimeout(),this._longTapTimeoutId=setTimeout(this._longTapHandler.bind(this,e),Nr.LongTap);}this._processEvent(this._makeCompatEvent(e,t),this._handler.touchStartEvent),this._tapTimeoutId===null&&(this._tapCount=0,this._tapTimeoutId=setTimeout(this._resetTapTimeout.bind(this),Nr.ResetClick),this._tapCoordinate=this._getCoordinate(t));}_mouseDownHandler(e){if(e.button===lr.Right){this._preventDefault(e),this._processEvent(this._makeCompatEvent(e),this._handler.mouseRightClickEvent);return}if(e.button!==lr.Left)return;let t=this._target.ownerDocument.documentElement;fi()&&t.addEventListener("mouseleave",this._onFirefoxOutsideMouseUp),this._cancelClick=false,this._mouseMoveStartCoordinate=this._getCoordinate(e),this._unsubscribeRootMouseEvents!==null&&(this._unsubscribeRootMouseEvents(),this._unsubscribeRootMouseEvents=null);{let r=this._mouseMoveWithDownHandler.bind(this),i=this._mouseUpHandler.bind(this);this._unsubscribeRootMouseEvents=()=>{t.removeEventListener("mousemove",r),t.removeEventListener("mouseup",i);},t.addEventListener("mousemove",r),t.addEventListener("mouseup",i);}this._mousePressed=true,!this._firesTouchEvents(e)&&(this._processEvent(this._makeCompatEvent(e),this._handler.mouseDownEvent),this._clickTimeoutId===null&&(this._clickCount=0,this._clickTimeoutId=setTimeout(this._resetClickTimeout.bind(this),Nr.ResetClick),this._clickCoordinate=this._getCoordinate(e)));}_init(){this._target.addEventListener("mouseenter",this._mouseEnterHandler.bind(this)),this._target.addEventListener("touchcancel",this._clearLongTapTimeout.bind(this));{let e=this._target.ownerDocument,t=r=>{this._handler.mouseDownOutsideEvent!=null&&(r.composed&&this._target.contains(r.composedPath()[0])||r.target!==null&&this._target.contains(r.target)||this._handler.mouseDownOutsideEvent({x:0,y:0,pageX:0,pageY:0}));};this._unsubscribeOutsideTouchEvents=()=>{e.removeEventListener("touchstart",t);},this._unsubscribeOutsideMouseEvents=()=>{e.removeEventListener("mousedown",t);},e.addEventListener("mousedown",t),e.addEventListener("touchstart",t,{passive:true});}Or()&&(this._unsubscribeMobileSafariEvents=()=>{this._target.removeEventListener("dblclick",this._onMobileSafariDoubleClick);},this._target.addEventListener("dblclick",this._onMobileSafariDoubleClick)),this._target.addEventListener("mouseleave",this._mouseLeaveHandler.bind(this)),this._target.addEventListener("touchstart",this._touchStartHandler.bind(this),{passive:true}),this._target.addEventListener("mousedown",e=>{if(e.button===lr.Middle)return e.preventDefault(),false}),this._target.addEventListener("mousedown",this._mouseDownHandler.bind(this)),this._initPinch(),this._target.addEventListener("touchmove",()=>{},{passive:false});}_initPinch(){!_(this._handler.pinchStartEvent)&&!_(this._handler.pinchEvent)&&!_(this._handler.pinchEndEvent)||(this._target.addEventListener("touchstart",e=>{this._checkPinchState(e.touches);},{passive:true}),this._target.addEventListener("touchmove",e=>{if(!(e.touches.length!==2||this._startPinchMiddleCoordinate===null)&&_(this._handler.pinchEvent)){let r=this._getTouchDistance(e.touches[0],e.touches[1])/this._startPinchDistance;this._handler.pinchEvent({...this._startPinchMiddleCoordinate,pageX:0,pageY:0},r),this._preventDefault(e);}},{passive:false}),this._target.addEventListener("touchend",e=>{this._checkPinchState(e.touches);}));}_checkPinchState(e){e.length===1&&(this._pinchPrevented=false),e.length!==2||this._pinchPrevented||this._longTapActive?this._stopPinch():this._startPinch(e);}_startPinch(e){let t=this._target.getBoundingClientRect();this._startPinchMiddleCoordinate={x:(e[0].clientX-t.left+(e[1].clientX-t.left))/2,y:(e[0].clientY-t.top+(e[1].clientY-t.top))/2},this._startPinchDistance=this._getTouchDistance(e[0],e[1]),_(this._handler.pinchStartEvent)&&this._handler.pinchStartEvent({x:0,y:0,pageX:0,pageY:0}),this._clearLongTapTimeout();}_stopPinch(){this._startPinchMiddleCoordinate!==null&&(this._startPinchMiddleCoordinate=null,_(this._handler.pinchEndEvent)&&this._handler.pinchEndEvent({x:0,y:0,pageX:0,pageY:0}));}_mouseLeaveHandler(e){this._unsubscribeMousemove?.(),this._unsubscribeMouseWheel?.(),this._unsubscribeContextMenu?.(),!this._firesTouchEvents(e)&&this._acceptMouseLeave&&(this._processEvent(this._makeCompatEvent(e),this._handler.mouseLeaveEvent),this._acceptMouseLeave=!Or());}_longTapHandler(e){let t=this._touchWithId(e.touches,this._activeTouchId);t!==null&&(this._processEvent(this._makeCompatEvent(e,t),this._handler.longTapEvent),this._cancelTap=true,this._longTapActive=true);}_firesTouchEvents(e){return _(e.sourceCapabilities?.firesTouchEvents)?e.sourceCapabilities.firesTouchEvents:this._eventTimeStamp(e)<this._lastTouchEventTimeStamp+Nr.PreventFiresTouchEvents}_processEvent(e,t){t?.call(this._handler,e);}_makeCompatEvent(e,t){let r=t??e,i=this._target.getBoundingClientRect();return {x:r.clientX-i.left,y:r.clientY-i.top,pageX:r.pageX,pageY:r.pageY,isTouch:!e.type.startsWith("mouse")&&e.type!=="contextmenu"&&e.type!=="click"&&e.type!=="wheel",preventDefault:()=>{e.type!=="touchstart"&&this._preventDefault(e);}}}_getTouchDistance(e,t){let r=e.clientX-t.clientX,i=e.clientY-t.clientY;return Math.sqrt(r*r+i*i)}_preventDefault(e){e.cancelable&&e.preventDefault();}_getCoordinate(e){return {x:e.pageX,y:e.pageY}}_eventTimeStamp(e){return e.timeStamp??performance.now()}_touchWithId(e,t){for(let r=0;r<e.length;++r)if(e[r].identifier===t)return e[r];return null}};var ur=class{_container;_chart;_event;_flingStartTime=new Date().getTime();_flingScrollRequestId=null;_startScrollCoordinate=null;_touchCoordinate=null;_touchCancelCrosshair=false;_touchZoomed=false;_pinchScale=1;_mouseDownWidget=null;_prevYAxisRange=null;_xAxisStartScaleCoordinate=null;_xAxisStartScaleDistance=0;_xAxisScale=1;_yAxisStartScaleDistance=0;_mouseMoveTriggerWidgetInfo={pane:null,widget:null};_boundKeyBoardDownEvent=e=>{switch(e.code){case "Escape":{let t=this._chart.getChartStore(),r=t.getProgressOverlayInfo();r!==null&&t.removeOverlay({id:r.overlay.id});break}default:{if(e.shiftKey)switch(e.code){case "Equal":{this._chart.getChartStore().zoom(.5,null,"main");break}case "Minus":{this._chart.getChartStore().zoom(-0.5,null,"main");break}case "ArrowLeft":{let t=this._chart.getChartStore();t.startScroll(),t.scroll(-3*t.getBarSpace().bar);break}case "ArrowRight":{let t=this._chart.getChartStore();t.startScroll(),t.scroll(3*t.getBarSpace().bar);break}}break}}};constructor(e,t){this._container=e,this._chart=t,this._event=new cr(e,this,{treatVertDragAsPageScroll:()=>false,treatHorzDragAsPageScroll:()=>false}),e.addEventListener("keydown",this._boundKeyBoardDownEvent),window.addEventListener("keydown",this._boundKeyBoardDownEvent);}pinchStartEvent(){return this._touchZoomed=true,this._pinchScale=1,true}pinchEvent(e,t){let{pane:r,widget:i}=this._findWidgetByEvent(e);if(r?.getId()!==B.X_AXIS&&i?.getName()===N.MAIN){let o=this._makeWidgetEvent(e,i),a=(t-this._pinchScale)*5;return this._pinchScale=t,this._chart.getChartStore().zoom(a,{x:o.x,y:o.y},"main"),true}return false}mouseWheelHortEvent(e,t){let r=this._chart.getChartStore();return r.startScroll(),r.scroll(t),true}mouseWheelVertEvent(e,t){let{widget:r}=this._findWidgetByEvent(e),i=this._makeWidgetEvent(e,r);return r?.getName()===N.MAIN?(this._chart.getChartStore().zoom(t,{x:i.x,y:i.y},"main"),true):false}mouseDownEvent(e){let{pane:t,widget:r}=this._findWidgetByEvent(e);if(this._mouseDownWidget=r,r!==null){let i=this._makeWidgetEvent(e,r);switch(r.getName()){case N.SEPARATOR:return r.dispatchEvent("mouseDownEvent",i);case N.MAIN:{let a=t.getAxisComponent();if(!a.getAutoCalcTickFlag()){let s=a.getRange();this._prevYAxisRange={...s};}return this._startScrollCoordinate={x:i.x,y:i.y},this._chart.getChartStore().startScroll(),r.dispatchEvent("mouseDownEvent",i)}case N.X_AXIS:return this._processXAxisScrollStartEvent(r,i);case N.Y_AXIS:return this._processYAxisScaleStartEvent(r,i)}}return false}mouseMoveEvent(e){let{pane:t,widget:r}=this._findWidgetByEvent(e),i=this._makeWidgetEvent(e,r);if((this._mouseMoveTriggerWidgetInfo.pane?.getId()!==t?.getId()||this._mouseMoveTriggerWidgetInfo.widget?.getName()!==r?.getName())&&(r?.dispatchEvent("mouseEnterEvent",i),this._mouseMoveTriggerWidgetInfo.widget?.dispatchEvent("mouseLeaveEvent",i),this._mouseMoveTriggerWidgetInfo={pane:t,widget:r}),r!==null)switch(r.getName()){case N.MAIN:{let a=r.dispatchEvent("mouseMoveEvent",i),s={x:i.x,y:i.y,paneId:t?.getId()};return a?(r.getForceCursor()!=="pointer"&&(s=void 0),r.setCursor("pointer")):r.setCursor("crosshair"),this._chart.getChartStore().setCrosshair(s),a}case N.SEPARATOR:case N.X_AXIS:case N.Y_AXIS:{let a=r.dispatchEvent("mouseMoveEvent",i);return this._chart.getChartStore().setCrosshair(),a}}return false}pressedMouseMoveEvent(e){if(this._mouseDownWidget!==null&&this._mouseDownWidget.getName()===N.SEPARATOR)return this._mouseDownWidget.dispatchEvent("pressedMouseMoveEvent",e);let{pane:t,widget:r}=this._findWidgetByEvent(e);if(r!==null&&this._mouseDownWidget?.getPane().getId()===t?.getId()&&this._mouseDownWidget?.getName()===r.getName()){let i=this._makeWidgetEvent(e,r);switch(r.getName()){case N.MAIN:{let a,s=r.dispatchEvent("pressedMouseMoveEvent",i);return s||this._processMainScrollingEvent(r,i),(!s||r.getForceCursor()==="pointer")&&(a={x:i.x,y:i.y,paneId:t?.getId()}),this._chart.getChartStore().setCrosshair(a,{forceInvalidate:true}),s}case N.X_AXIS:return this._processXAxisScrollingEvent(r,i);case N.Y_AXIS:return this._processYAxisScalingEvent(r,i)}}return false}mouseUpEvent(e){let{widget:t}=this._findWidgetByEvent(e),r=false;if(t!==null){let i=this._makeWidgetEvent(e,t);switch(t.getName()){case N.MAIN:case N.SEPARATOR:case N.X_AXIS:case N.Y_AXIS:{r=t.dispatchEvent("mouseUpEvent",i);break}}r&&this._chart.updatePane(1);}return this._mouseDownWidget=null,this._startScrollCoordinate=null,this._prevYAxisRange=null,this._xAxisStartScaleCoordinate=null,this._xAxisStartScaleDistance=0,this._xAxisScale=1,this._yAxisStartScaleDistance=0,r}mouseClickEvent(e){let{widget:t}=this._findWidgetByEvent(e);if(t!==null){let r=this._makeWidgetEvent(e,t);return t.dispatchEvent("mouseClickEvent",r)}return false}mouseRightClickEvent(e){let{widget:t}=this._findWidgetByEvent(e),r=false;if(t!==null){let i=this._makeWidgetEvent(e,t);switch(t.getName()){case N.MAIN:case N.X_AXIS:case N.Y_AXIS:{r=t.dispatchEvent("mouseRightClickEvent",i);break}}r&&this._chart.updatePane(1);}return false}mouseDoubleClickEvent(e){let{pane:t,widget:r}=this._findWidgetByEvent(e);if(r!==null)switch(r.getName()){case N.MAIN:{let o=this._makeWidgetEvent(e,r);return r.dispatchEvent("mouseDoubleClickEvent",o)}case N.Y_AXIS:{let o=t.getAxisComponent();if(!o.getAutoCalcTickFlag())return o.setAutoCalcTickFlag(true),this._chart.layout({measureWidth:true,update:true,buildYAxisTick:true}),true;break}}return false}mouseLeaveEvent(){return this._chart.getChartStore().setCrosshair(),true}touchStartEvent(e){let{pane:t,widget:r}=this._findWidgetByEvent(e);if(r!==null){let i=this._makeWidgetEvent(e,r);switch(i.preventDefault?.(),r.getName()){case N.MAIN:{let a=this._chart.getChartStore();if(r.dispatchEvent("mouseDownEvent",i))return this._touchCancelCrosshair=true,this._touchCoordinate=null,a.setCrosshair(void 0,{notInvalidate:true}),this._chart.updatePane(1),true;this._flingScrollRequestId!==null&&(jr(this._flingScrollRequestId),this._flingScrollRequestId=null),this._flingStartTime=new Date().getTime();let s=t.getAxisComponent();if(!s.getAutoCalcTickFlag()){let l=s.getRange();this._prevYAxisRange={...l};}if(this._startScrollCoordinate={x:i.x,y:i.y},a.startScroll(),this._touchZoomed=false,this._touchCoordinate!==null){let l=i.x-this._touchCoordinate.x,c=i.y-this._touchCoordinate.y;Math.sqrt(l*l+c*c)<Jn?(this._touchCoordinate={x:i.x,y:i.y},a.setCrosshair({x:i.x,y:i.y,paneId:t?.getId()})):(this._touchCoordinate=null,this._touchCancelCrosshair=true,a.setCrosshair());}return true}case N.X_AXIS:return this._processXAxisScrollStartEvent(r,i);case N.Y_AXIS:return this._processYAxisScaleStartEvent(r,i)}}return false}touchMoveEvent(e){let{pane:t,widget:r}=this._findWidgetByEvent(e);if(r!==null){let i=this._makeWidgetEvent(e,r),o=r.getName(),a=this._chart.getChartStore();switch(o){case N.MAIN:return r.dispatchEvent("pressedMouseMoveEvent",i)?(i.preventDefault?.(),a.setCrosshair(void 0,{notInvalidate:true}),this._chart.updatePane(1),true):(this._touchCoordinate!==null?(i.preventDefault?.(),a.setCrosshair({x:i.x,y:i.y,paneId:t?.getId()})):this._processMainScrollingEvent(r,i),true);case N.X_AXIS:return i.preventDefault?.(),this._processXAxisScrollingEvent(r,i);case N.Y_AXIS:return this._processYAxisScalingEvent(r,i)}}return false}touchEndEvent(e){let{widget:t}=this._findWidgetByEvent(e);if(t!==null){let r=this._makeWidgetEvent(e,t);switch(t.getName()){case N.MAIN:{if(t.dispatchEvent("mouseUpEvent",r),this._startScrollCoordinate!==null){let o=new Date().getTime()-this._flingStartTime,s=(r.x-this._startScrollCoordinate.x)/(o>0?o:1)*20;if(o<200&&Math.abs(s)>0){let l=this._chart.getChartStore(),c=()=>{this._flingScrollRequestId=Ce(()=>{l.startScroll(),l.scroll(s),s=s*(1-.025),Math.abs(s)<1?this._flingScrollRequestId!==null&&(jr(this._flingScrollRequestId),this._flingScrollRequestId=null):c();});};c();}}return true}case N.X_AXIS:case N.Y_AXIS:t.dispatchEvent("mouseUpEvent",r)&&this._chart.updatePane(1);}this._startScrollCoordinate=null,this._prevYAxisRange=null,this._xAxisStartScaleCoordinate=null,this._xAxisStartScaleDistance=0,this._xAxisScale=1,this._yAxisStartScaleDistance=0;}return false}tapEvent(e){let{pane:t,widget:r}=this._findWidgetByEvent(e),i=false;if(r!==null){let o=this._makeWidgetEvent(e,r),a=r.dispatchEvent("mouseClickEvent",o);if(r.getName()===N.MAIN){let s=this._makeWidgetEvent(e,r),l=this._chart.getChartStore();a?(this._touchCancelCrosshair=true,this._touchCoordinate=null,l.setCrosshair(void 0,{notInvalidate:true}),i=true):(!this._touchCancelCrosshair&&!this._touchZoomed&&(this._touchCoordinate={x:s.x,y:s.y},l.setCrosshair({x:s.x,y:s.y,paneId:t?.getId()},{notInvalidate:true}),i=true),this._touchCancelCrosshair=false);}(i||a)&&this._chart.updatePane(1);}return i}doubleTapEvent(e){return this.mouseDoubleClickEvent(e)}longTapEvent(e){let{pane:t,widget:r}=this._findWidgetByEvent(e);if(r!==null&&r.getName()===N.MAIN){let i=this._makeWidgetEvent(e,r);return this._touchCoordinate={x:i.x,y:i.y},this._chart.getChartStore().setCrosshair({x:i.x,y:i.y,paneId:t?.getId()}),true}return false}_processMainScrollingEvent(e,t){if(this._startScrollCoordinate!==null){let r=e.getPane().getAxisComponent();if(this._prevYAxisRange!==null&&!r.getAutoCalcTickFlag()&&r.scrollZoomEnabled){t.preventDefault?.();let{from:o,to:a,range:s}=this._prevYAxisRange,l=0;r.reverse?l=this._startScrollCoordinate.y-t.y:l=t.y-this._startScrollCoordinate.y;let c=e.getBounding(),u=l/c.height,h=s*u,d=o+h,m=a+h,p=r.valueToRealValue(d,{range:this._prevYAxisRange}),g=r.valueToRealValue(m,{range:this._prevYAxisRange}),f=r.realValueToDisplayValue(p,{range:this._prevYAxisRange}),v=r.realValueToDisplayValue(g,{range:this._prevYAxisRange});r.setRange({from:d,to:m,range:m-d,realFrom:p,realTo:g,realRange:g-p,displayFrom:f,displayTo:v,displayRange:v-f});}let i=t.x-this._startScrollCoordinate.x;this._chart.getChartStore().scroll(i);}}_processXAxisScrollStartEvent(e,t){let r=e.dispatchEvent("mouseDownEvent",t);return r&&this._chart.updatePane(1),this._xAxisStartScaleCoordinate={x:t.x,y:t.y},this._xAxisStartScaleDistance=t.pageX,r}_processXAxisScrollingEvent(e,t){let r=e.dispatchEvent("pressedMouseMoveEvent",t);if(r)this._chart.updatePane(1);else if(e.getPane().getAxisComponent().scrollZoomEnabled&&this._xAxisStartScaleDistance!==0){let o=this._xAxisStartScaleDistance/t.pageX;if(Number.isFinite(o)){let a=(o-this._xAxisScale)*10;this._xAxisScale=o,this._chart.getChartStore().zoom(a,this._xAxisStartScaleCoordinate,"xAxis");}}return r}_processYAxisScaleStartEvent(e,t){let r=e.dispatchEvent("mouseDownEvent",t);r&&this._chart.updatePane(1);let i=e.getPane().getAxisComponent().getRange();return this._prevYAxisRange={...i},this._yAxisStartScaleDistance=t.pageY,r}_processYAxisScalingEvent(e,t){let r=e.dispatchEvent("pressedMouseMoveEvent",t);if(r)this._chart.updatePane(1);else {let i=e.getPane().getAxisComponent();if(this._prevYAxisRange!==null&&i.scrollZoomEnabled&&this._yAxisStartScaleDistance!==0){t.preventDefault?.();let{from:o,to:a,range:s}=this._prevYAxisRange,l=t.pageY/this._yAxisStartScaleDistance,c=s*l,u=(c-s)/2,h=o-u,d=a+u,m=i.valueToRealValue(h,{range:this._prevYAxisRange}),p=i.valueToRealValue(d,{range:this._prevYAxisRange}),g=i.realValueToDisplayValue(m,{range:this._prevYAxisRange}),f=i.realValueToDisplayValue(p,{range:this._prevYAxisRange});i.setRange({from:h,to:d,range:c,realFrom:m,realTo:p,realRange:p-m,displayFrom:g,displayTo:f,displayRange:f-g}),this._chart.layout({measureWidth:true,update:true,buildYAxisTick:true});}}return r}_findWidgetByEvent(e){let{x:t,y:r}=e,i=this._chart.getSeparatorPanes(),o=this._chart.getStyles().separator.size;for(let c of i){let u=c[1],h=u.getBounding(),d=h.top-Math.round((ze-o)/2);if(t>=h.left&&t<=h.left+h.width&&r>=d&&r<=d+ze)return {pane:u,widget:u.getWidget()}}let a=this._chart.getDrawPanes(),s=null;for(let c of a){let u=c.getBounding();if(t>=u.left&&t<=u.left+u.width&&r>=u.top&&r<=u.top+u.height){s=c;break}}let l=null;if(s!==null){if(!_(l)){let c=s.getMainWidget(),u=c.getBounding();t>=u.left&&t<=u.left+u.width&&r>=u.top&&r<=u.top+u.height&&(l=c);}if(!_(l)){let c=s.getYAxisWidget();if(c!==null){let u=c.getBounding();t>=u.left&&t<=u.left+u.width&&r>=u.top&&r<=u.top+u.height&&(l=c);}}}return {pane:s,widget:l}}_makeWidgetEvent(e,t){let r=t?.getBounding()??null;return {...e,x:e.x-(r?.left??0),y:e.y-(r?.top??0)}}destroy(){this._container.removeEventListener("keydown",this._boundKeyBoardDownEvent),window.removeEventListener("keydown",this._boundKeyBoardDownEvent),this._event.destroy();}};var _t=class{id;_container;_chartContainer;_chartBounding=He();_chartEvent;_chartStore;_drawPanes=[];_candlePane;_xAxisPane;_separatorPanes=new Map;_layoutOptions={sort:true,measureHeight:true,measureWidth:true,update:true,buildYAxisTick:false,cacheYAxisWidth:false,forceBuildYAxisTick:false};_layoutPending=false;_layoutRafId=0;_cacheYAxisWidth={left:0,right:0};_visible=true;_intersectionObserver=null;_qualityTier="high";_longTaskCount=0;_longTaskWindowStart=0;_perfObserver=null;_resizeTimer=null;_resizeObserver=null;_frameCount=0;_frameTotalMs=0;constructor(e,t){this._initContainer(e),this._chartEvent=new ur(this._chartContainer,this),this._chartStore=new wt(this,t),this._initPanes(t),this._layout(),this._initObservers();}_initObservers(){if(typeof IntersectionObserver<"u"&&(this._intersectionObserver=new IntersectionObserver(([e])=>{this._visible=e.isIntersecting;},{threshold:0}),this._intersectionObserver.observe(this._chartContainer)),typeof PerformanceObserver<"u")try{this._perfObserver=new PerformanceObserver(e=>{let t=performance.now();t-this._longTaskWindowStart>1e3&&(this._longTaskWindowStart=t,this._longTaskCount=0),this._longTaskCount+=e.getEntries().length,this._longTaskCount>=3?this._qualityTier="low":this._qualityTier==="low"&&this._longTaskCount===0&&(this._qualityTier="high");}),this._perfObserver.observe({entryTypes:["longtask"]});}catch{}typeof ResizeObserver<"u"&&(this._resizeObserver=new ResizeObserver(()=>{this._resizeTimer!==null&&clearTimeout(this._resizeTimer),this._resizeTimer=setTimeout(()=>{this._resizeTimer=null,this._applyResize();},150);}),this._resizeObserver.observe(this._chartContainer));}setQualityTier(e){this._qualityTier=e;}getQualityTier(){return this._qualityTier}getPerformanceMetrics(){let e=typeof performance<"u"?[...performance.getEntriesByName("astroneum:frame-start"),...performance.getEntriesByName("astroneum:frame-end")]:[],t=this._frameCount>0?this._frameTotalMs/this._frameCount:0;return {frameCount:this._frameCount,avgFrameMs:t,entries:e}}_initContainer(e){this._container=e,this._chartContainer=oe("div",{position:"relative",width:"100%",height:"100%",outline:"none",borderStyle:"none",cursor:"crosshair",boxSizing:"border-box",userSelect:"none",webkitUserSelect:"none",overflow:"hidden",backgroundColor:"inherit",msUserSelect:"none",MozUserSelect:"none",webkitTapHighlightColor:"transparent"}),this._chartContainer.tabIndex=1,e.appendChild(this._chartContainer),this._cacheChartBounding();}_cacheChartBounding(){this._chartBounding.width=Math.floor(this._chartContainer.clientWidth),this._chartBounding.height=Math.floor(this._chartContainer.clientHeight);}_initPanes(e){let t=e?.layout??[{type:"candle"}],r=o=>{if(!_(this._candlePane)){let a=o.options??{};U(a,{id:B.CANDLE}),this._candlePane=this._createPane(er,B.CANDLE,a),(o.content??[]).forEach(l=>{this.createIndicator(l,true,a);});}},i=o=>{if(!_(this._xAxisPane)){let a=this._createPane(nr,B.X_AXIS,o??{});this._xAxisPane=a;}};t.forEach(o=>{switch(o.type){case "candle":{r(o);break}case "indicator":{let a=o.content??[];if(a.length>0){let s=o.options?.id??null;_(s)&&(s=mt(B.INDICATOR));let l={...o.options,id:s};a.forEach(c=>{this.createIndicator(c,true,l);});}break}case "xAxis":{i(o.options);break}}}),r({}),i({order:Number.MAX_SAFE_INTEGER});}_createPane(e,t,r){let i=new e(this,t,r??{});return this._drawPanes.push(i),i}_recalculatePaneHeight(e,t,r){if(r===0)return false;let i=this._drawPanes.filter(a=>{let s=a.getId();return a.getOptions().state==="normal"&&s!==e.getId()&&s!==B.X_AXIS}),o=i.length;if(o===0)return false;if(e.getId()!==B.CANDLE&&_(this._candlePane)&&this._candlePane.getOptions().state==="normal"){let a=this._candlePane.getBounding().height;if(a>0){let s=this._candlePane.getOptions().minHeight,l=a+r;l<s&&(l=s,t-=a+r-l),this._candlePane.setBounding({height:l});}}else {let a=r,s=Math.floor(r/o);i.forEach((l,c)=>{let u=l.getBounding().height,h=0;c===o-1?h=u+a:h=u+s,h<l.getOptions().minHeight&&(h=l.getOptions().minHeight),l.setBounding({height:h}),a-=h-u;}),Math.abs(a)>0&&(t-=a);}return e.setBounding({height:t}),true}getDrawPaneById(e){return e===B.CANDLE?this._candlePane:e===B.X_AXIS?this._xAxisPane:this._drawPanes.find(r=>r.getId()===e)??null}getContainer(){return this._container}getChartStore(){return this._chartStore}getXAxisPane(){return this._xAxisPane}getDrawPanes(){return this._drawPanes}getSeparatorPanes(){return this._separatorPanes}layout(e){(e.sort??false)&&(this._layoutOptions.sort=e.sort),(e.measureHeight??false)&&(this._layoutOptions.measureHeight=e.measureHeight),(e.measureWidth??false)&&(this._layoutOptions.measureWidth=e.measureWidth),(e.update??false)&&(this._layoutOptions.update=e.update),(e.buildYAxisTick??false)&&(this._layoutOptions.buildYAxisTick=e.buildYAxisTick),(e.cacheYAxisWidth??false)&&(this._layoutOptions.cacheYAxisWidth=e.cacheYAxisWidth),(e.buildYAxisTick??false)&&(this._layoutOptions.forceBuildYAxisTick=e.forceBuildYAxisTick),this._layoutPending||(this._layoutPending=true,this._layoutRafId=requestAnimationFrame(()=>{this._layout(),this._layoutPending=false;}));}_layout(){if(!this._visible)return;let e=typeof performance<"u"?performance.now():0;typeof performance<"u"&&performance.mark("astroneum:frame-start");let{sort:t,measureHeight:r,measureWidth:i,update:o,buildYAxisTick:a,cacheYAxisWidth:s,forceBuildYAxisTick:l}=this._layoutOptions;if(t){for(;_(this._chartContainer.firstChild);)this._chartContainer.removeChild(this._chartContainer.firstChild);this._separatorPanes.clear(),this._drawPanes.sort((h,d)=>h.getOptions().order-d.getOptions().order);let u=null;this._drawPanes.forEach(h=>{if(h.getId()!==B.X_AXIS){if(_(u)){let d=new sr(this,"",u,h);this._chartContainer.appendChild(d.getContainer()),this._separatorPanes.set(h,d);}u=h;}this._chartContainer.appendChild(h.getContainer());});}if(r){let u=this._chartBounding.height,h=this.getStyles().separator.size,d=this._xAxisPane.getAxisComponent().getAutoSize(),m=u-d;m<0&&(m=0),this._drawPanes.forEach(g=>{let f=g.getId();if(_(this._separatorPanes.get(g))&&(m-=h),f!==B.X_AXIS&&f!==B.CANDLE&&g.getVisible()){let v=g.getBounding().height;v>m?(v=m,m=0):m-=v,g.setBounding({height:v});}}),this._candlePane.setBounding({height:Math.max(m,0)}),this._xAxisPane.setBounding({height:d});let p=0;this._drawPanes.forEach(g=>{let f=this._separatorPanes.get(g);_(f)&&(f.setBounding({height:h,top:p}),p+=h),g.setBounding({top:p}),p+=g.getBounding().height;});}let c=i;if((a||l)&&this._drawPanes.forEach(u=>{let h=u.getAxisComponent().buildTicks(l);c||=h;}),c){let u=this._chartBounding.width,h=this.getStyles(),d=0,m=true,p=0,g=true;this._drawPanes.forEach(P=>{if(P.getId()!==B.X_AXIS){let R=P.getAxisComponent(),D=R.inside,E=R.getAutoSize();R.position==="left"?(d=Math.max(d,E),D&&(m=false)):(p=Math.max(p,E),D&&(g=false));}}),s&&(d=Math.max(this._cacheYAxisWidth.left,d),p=Math.max(this._cacheYAxisWidth.right,p)),this._cacheYAxisWidth.left=d,this._cacheYAxisWidth.right=p;let f=u,v=0,y=0;m&&(f-=d,v=d),g&&(f-=p,y=p),this._chartStore.setTotalBarSpace(f);let b={width:u},S={width:f,left:v,right:y},x={width:d},C={width:p},T=h.separator.fill,A={};T?A=b:A=S,this._drawPanes.forEach(P=>{this._separatorPanes.get(P)?.setBounding(A),P.setBounding(b,S,x,C);});}o&&(this._xAxisPane.getAxisComponent().buildTicks(true),this.updatePane(4)),this._layoutOptions={sort:false,measureHeight:false,measureWidth:false,update:false,buildYAxisTick:false,cacheYAxisWidth:false,forceBuildYAxisTick:false},typeof performance<"u"&&(performance.mark("astroneum:frame-end"),this._frameTotalMs+=performance.now()-e,this._frameCount++);}updatePane(e,t){_(t)?this.getDrawPaneById(t)?.update(e):this._drawPanes.forEach(r=>{r.update(e),this._separatorPanes.get(r)?.update(e);});}getDom(e,t){if(_(e)){let r=this.getDrawPaneById(e);if(_(r))switch(t??"root"){case "root":return r.getContainer();case "main":return r.getMainWidget().getContainer();case "yAxis":return r.getYAxisWidget()?.getContainer()??null}}else return this._chartContainer;return null}getSize(e,t){if(_(e)){let r=this.getDrawPaneById(e);if(_(r))switch(t??"root"){case "root":return r.getBounding();case "main":return r.getMainWidget().getBounding();case "yAxis":return r.getYAxisWidget()?.getBounding()??null}}else return this._chartBounding;return null}_resetYAxisAutoCalcTickFlag(){this._drawPanes.forEach(e=>{e.getAxisComponent().setAutoCalcTickFlag(true);});}setSymbol(e){e!==this.getSymbol()&&(this._resetYAxisAutoCalcTickFlag(),this._chartStore.setSymbol(e));}getSymbol(){return this._chartStore.getSymbol()}setPeriod(e){e!==this.getPeriod()&&(this._resetYAxisAutoCalcTickFlag(),this._chartStore.setPeriod(e));}getPeriod(){return this._chartStore.getPeriod()}setStyles(e){this._setOptions(()=>{this._chartStore.setStyles(e);});}getStyles(){return this._chartStore.getStyles()}setFormatter(e){this._setOptions(()=>{this._chartStore.setFormatter(e);});}getFormatter(){return this._chartStore.getFormatter()}setLocale(e){this._setOptions(()=>{this._chartStore.setLocale(e);});}getLocale(){return this._chartStore.getLocale()}setTimezone(e){this._setOptions(()=>{this._chartStore.setTimezone(e);});}getTimezone(){return this._chartStore.getTimezone()}setThousandsSeparator(e){this._setOptions(()=>{this._chartStore.setThousandsSeparator(e);});}getThousandsSeparator(){return this._chartStore.getThousandsSeparator()}setDecimalFold(e){this._setOptions(()=>{this._chartStore.setDecimalFold(e);});}getDecimalFold(){return this._chartStore.getDecimalFold()}_setOptions(e){e(),this.layout({measureHeight:true,measureWidth:true,update:true,buildYAxisTick:true,forceBuildYAxisTick:true});}setOffsetRightDistance(e){this._chartStore.setOffsetRightDistance(e,true);}getOffsetRightDistance(){return this._chartStore.getOffsetRightDistance()}setMaxOffsetLeftDistance(e){if(e<0){me("setMaxOffsetLeftDistance","distance","distance must greater than zero!!!");return}this._chartStore.setMaxOffsetLeftDistance(e);}setMaxOffsetRightDistance(e){if(e<0){me("setMaxOffsetRightDistance","distance","distance must greater than zero!!!");return}this._chartStore.setMaxOffsetRightDistance(e);}setLeftMinVisibleBarCount(e){if(e<0){me("setLeftMinVisibleBarCount","barCount","barCount must greater than zero!!!");return}this._chartStore.setLeftMinVisibleBarCount(Math.ceil(e));}setRightMinVisibleBarCount(e){if(e<0){me("setRightMinVisibleBarCount","barCount","barCount must greater than zero!!!");return}this._chartStore.setRightMinVisibleBarCount(Math.ceil(e));}setBarSpace(e){this._chartStore.setBarSpace(e);}getBarSpace(){return this._chartStore.getBarSpace()}getVisibleRange(){return this._chartStore.getVisibleRange()}resetData(){this._chartStore.resetData();}getDataList(){return this._chartStore.getDataList()}setDataLoader(e){this._resetYAxisAutoCalcTickFlag(),this._chartStore.setDataLoader(e);}createIndicator(e,t,r){let i=L(e)?{name:e}:e;if(_r(i.name)===null)return me("createIndicator","value","indicator not supported, you may need to use registerIndicator to add one!!!"),null;let o=r??{};if(L(o.id)||(o.id=mt(B.INDICATOR)),L(i.id)||(i.id=mt(i.name)),this._chartStore.addIndicator(i,o.id,t??false)){let s=false;return _(this.getDrawPaneById(o.id))||(this._createPane(it,o.id,o),o.height??=100,s=true),this.setPaneOptions(o),this.layout({sort:s,measureHeight:true,measureWidth:true,update:true,buildYAxisTick:true,forceBuildYAxisTick:true}),i.id}return null}overrideIndicator(e){return this._chartStore.overrideIndicator(e)}getIndicators(e){return this._chartStore.getIndicatorsByFilter(e??{})}removeIndicator(e){let t=this._chartStore.removeIndicator(e??{});if(t){let r=false,i=[];this._drawPanes.forEach(o=>{let a=o.getId();a!==B.CANDLE&&a!==B.X_AXIS&&i.push(a);}),i.forEach(o=>{if(!this._chartStore.hasIndicators(o)){let a=this._drawPanes.findIndex(l=>l.getId()===o),s=this._drawPanes[a];_(s)&&(r=true,this._recalculatePaneHeight(s,0,s.getBounding().height),this._drawPanes.splice(a,1),s.destroy());}}),this._drawPanes.length===2&&(this._candlePane.setVisible(true),this._candlePane.setBounding({height:this._chartBounding.height-this._xAxisPane.getBounding().height})),this.layout({sort:r,measureHeight:r,measureWidth:true,update:true,buildYAxisTick:true,forceBuildYAxisTick:true});}return t}createOverlay(e){let t=[],r=[],i=a=>{!_(a.paneId)||this.getDrawPaneById(a.paneId)===null?(a.paneId=B.CANDLE,r.push(false)):r.push(true),t.push(a);};L(e)?i({name:e}):ne(e)?e.forEach(a=>{let s=null;L(a)?s={name:a}:s=a,i(s);}):i(e);let o=this._chartStore.addOverlays(t,r);return ne(e)?o:o[0]}getOverlays(e){return this._chartStore.getOverlaysByFilter(e??{})}overrideOverlay(e){return this._chartStore.overrideOverlay(e)}removeOverlay(e){return this._chartStore.removeOverlay(e??{})}setPaneOptions(e){let t=false,r=false,i=_(e.id);for(let o of this._drawPanes){let a=o.getId();if(i&&e.id===a||!i){if(a!==B.X_AXIS){if(w(e.height)&&e.height>0){let l=Math.max(e.minHeight??o.getOptions().minHeight,0),c=Math.max(l,e.height);r=true,t=true,o.setOriginalBounding({height:c}),this._recalculatePaneHeight(o,c,-c);}if(_(e.state)&&o.getOptions().state!==e.state){t=true,r=true;let l=e.state;switch(l){case "maximize":{let c=this._drawPanes.find(u=>{let h=u.getId();return u.getOptions().state==="maximize"&&h!==B.X_AXIS});if(!_(c)){o.getOptions().state==="normal"&&o.setOriginalBounding({height:o.getBounding().height}),o.setOptions({state:l});let u=this._chartBounding.height;o.setBounding({height:u-this._xAxisPane.getBounding().height}),this._drawPanes.forEach(h=>{h.getId()!==B.X_AXIS&&h.getId()!==a&&(h.setBounding({height:h.getOriginalBounding().height}),h.setVisible(false),this._separatorPanes.get(h)?.setVisible(false));});}break}case "minimize":{let c=o.getBounding().height,u=o.getOptions().state,h=c-30;u==="maximize"&&(h=o.getOriginalBounding().height-30),this._recalculatePaneHeight(o,30,h)&&(u==="normal"&&o.setOriginalBounding({height:c}),o.setOptions({state:l})),this._drawPanes.forEach(d=>{d.getId()!==B.X_AXIS&&(d.setVisible(true),this._separatorPanes.get(d)?.setVisible(true));});break}default:{let c=o.getOriginalBounding().height;this._recalculatePaneHeight(o,c,o.getBounding().height-c)&&o.setOptions({state:l}),this._drawPanes.forEach(u=>{u.getId()!==B.X_AXIS&&(u.setVisible(true),this._separatorPanes.get(u)?.setVisible(true));});break}}}}_(e.axis)&&(r=true);let s={...e};if(delete s.state,o.setOptions(s),a===e.id)break}}r&&this.layout({measureHeight:t,measureWidth:true,update:true,buildYAxisTick:true,forceBuildYAxisTick:true});}getPaneOptions(e){return _(e)?this.getDrawPaneById(e)?.getOptions()??null:this._drawPanes.map(t=>t.getOptions())}setZoomEnabled(e){this._chartStore.setZoomEnabled(e);}isZoomEnabled(){return this._chartStore.isZoomEnabled()}setZoomAnchor(e){this._chartStore.setZoomAnchor(e);}getZoomAnchor(){return this._chartStore.getZoomAnchor()}setScrollEnabled(e){this._chartStore.setScrollEnabled(e);}isScrollEnabled(){return this._chartStore.isScrollEnabled()}scrollByDistance(e,t){let r=w(t)&&t>0?t:0;if(this._chartStore.startScroll(),r>0){let i=new Oe({duration:r});i.doFrame(o=>{let a=e*(o/r);this._chartStore.scroll(a);}),i.start();}else this._chartStore.scroll(e);}scrollToRealTime(e){let{bar:t}=this._chartStore.getBarSpace(),i=(this._chartStore.getLastBarRightSideDiffBarCount()-this._chartStore.getInitialOffsetRightDistance()/t)*t;this.scrollByDistance(i,e);}scrollToDataIndex(e,t){let r=(this._chartStore.getLastBarRightSideDiffBarCount()+(this.getDataList().length-1-e))*this._chartStore.getBarSpace().bar;this.scrollByDistance(r,t);}scrollToTimestamp(e,t){let r=xt(this.getDataList(),"timestamp",e);this.scrollToDataIndex(r,t);}zoomAtCoordinate(e,t,r){let i=w(r)&&r>0?r:0,{bar:o}=this._chartStore.getBarSpace(),s=o*e-o;if(i>0){let l=0,c=new Oe({duration:i});c.doFrame(u=>{let h=s*(u/i),d=(h-l)/this._chartStore.getBarSpace().bar*Ar;this._chartStore.zoom(d,t??null,"main"),l=h;}),c.start();}else this._chartStore.zoom(s/o*Ar,t??null,"main");}zoomAtDataIndex(e,t,r){let i=this._chartStore.dataIndexToCoordinate(t);this.zoomAtCoordinate(e,{x:i,y:0},r);}zoomAtTimestamp(e,t,r){let i=xt(this.getDataList(),"timestamp",t);this.zoomAtDataIndex(e,i,r);}convertToPixel(e,t){let{paneId:r=B.CANDLE,absolute:i=false}=t??{},o=[];if(r!==B.X_AXIS){let a=this.getDrawPaneById(r);if(a!==null){let s=a.getBounding(),l=[].concat(e),c=this._xAxisPane.getAxisComponent(),u=a.getAxisComponent();o=l.map(h=>{let d={},m=h.dataIndex;if(w(h.timestamp)&&(m=this._chartStore.timestampToDataIndex(h.timestamp)),w(m)&&(d.x=c.convertToPixel(m)),w(h.value)){let p=u.convertToPixel(h.value);d.y=i?s.top+p:p;}return d});}}return ne(e)?o:o[0]??{}}convertFromPixel(e,t){let{paneId:r=B.CANDLE,absolute:i=false}=t??{},o=[];if(r!==B.X_AXIS){let a=this.getDrawPaneById(r);if(a!==null){let s=a.getBounding(),l=[].concat(e),c=this._xAxisPane.getAxisComponent(),u=a.getAxisComponent();o=l.map(h=>{let d={};if(w(h.x)){let m=c.convertFromPixel(h.x);d.dataIndex=m,d.timestamp=this._chartStore.dataIndexToTimestamp(m)??void 0;}if(w(h.y)){let m=i?h.y-s.top:h.y;d.value=u.convertFromPixel(m);}return d});}}return ne(e)?o:o[0]??{}}executeAction(e,t){if(e==="onCrosshairChange"){let r=null;_(t)&&(r={...t},r.paneId??=B.CANDLE),this._chartStore.setCrosshair(r,{notExecuteAction:true});}}subscribeAction(e,t){this._chartStore.subscribeAction(e,t);}unsubscribeAction(e,t){this._chartStore.unsubscribeAction(e,t);}getConvertPictureUrl(e,t,r){let{width:i,height:o}=this._chartBounding,a=oe("canvas",{width:`${i}px`,height:`${o}px`,boxSizing:"border-box"}),s=a.getContext("2d"),l=z(a);a.width=i*l,a.height=o*l,s.scale(l,l),s.fillStyle=r??"#FFFFFF",s.fillRect(0,0,i,o);let c=e??false;return this._drawPanes.forEach(u=>{let h=this._separatorPanes.get(u);if(_(h)){let m=h.getBounding();s.drawImage(h.getImage(c),m.left,m.top,m.width,m.height);}let d=u.getBounding();s.drawImage(u.getImage(c),0,d.top,i,d.height);}),a.toDataURL(`image/${t??"jpeg"}`)}_applyResize(){this._cacheChartBounding(),this.layout({measureHeight:true,measureWidth:true,update:true,buildYAxisTick:true,forceBuildYAxisTick:true});}resize(){this._applyResize();}destroy(){this._layoutRafId!==0&&(cancelAnimationFrame(this._layoutRafId),this._layoutRafId=0),this._resizeTimer!==null&&(clearTimeout(this._resizeTimer),this._resizeTimer=null),this._intersectionObserver?.disconnect(),this._perfObserver?.disconnect(),this._resizeObserver?.disconnect(),this._chartEvent.destroy(),this._drawPanes.forEach(e=>{e.destroy();}),this._drawPanes=[],this._separatorPanes.clear(),this._chartStore.destroy(),this._container.removeChild(this._chartContainer);}};var ea=false,Vr=new Map,Ql=1;function O_(n,e){ea||(ea=true,Zo());let t=null;if(L(n)?t=document.getElementById(n):t=n,t===null)return qo("","","The chart cannot be initialized correctly. Please check the parameters. The chart container cannot be null and child elements need to be added!!!"),null;let r=Vr.get(t.id);if(_(r))return me("","","The chart has been initialized on the dom\uFF01\uFF01\uFF01"),r;let i=`k_line_chart_${Ql++}`;return r=new _t(t,e),r.id=i,t.setAttribute("k-line-chart-id",i),Vr.set(i,r),r}function N_(n){let e=null;if(n instanceof _t)e=n.id;else {let t=null;L(n)?t=document.getElementById(n):t=n,e=t?.getAttribute("k-line-chart-id")??null;}e!==null&&(Vr.get(e)?.destroy(),Vr.delete(e));}var V_={clone:Ae,merge:U,isString:L,isNumber:w,isValid:_,isObject:ae,isArray:ne,isFunction:j,isBoolean:Pe,formatValue:K,formatPrecision:ee,formatBigNumber:pr,formatDate:mr,formatThousands:gr,formatFoldDecimal:fr,calcTextWidth:ie,getLinearSlopeIntercept:ht,getLinearYFromSlopeIntercept:br,getLinearYFromCoordinates:Be,checkCoordinateOnArc:oi,checkCoordinateOnCircle:ti,checkCoordinateOnLine:Ur,checkCoordinateOnPolygon:ri,checkCoordinateOnRect:It,checkCoordinateOnText:ii};function yi(n,e){let t=0;return n.map((r,i)=>(t+=isFinite(r)?r:0,i>=e&&(t-=isFinite(n[i-e])?n[i-e]:0),i<e-1?NaN:t/e))}function Wr(n,e){let t=2/(e+1),r=[],i=NaN;return n.forEach((o,a)=>{if(!isFinite(o)){r.push(NaN);return}if(!isFinite(i)){i=o,r.push(o);return}i=o*t+i*(1-t),r.push(i);}),r}function Kl(n,e){let t=1/e,r=[],i=NaN;return n.forEach(o=>{if(!isFinite(o)){r.push(NaN);return}i=isFinite(i)?o*t+i*(1-t):o,r.push(i);}),r}function Jl(n,e){return n.map((t,r)=>{if(r<e-1)return NaN;let i=0,o=0;for(let a=0;a<e;a++){let s=e-a;i+=s,o+=(n[r-a]??NaN)*s;}return o/i})}function ec(n,e){let t=0,r=0;return n.map((i,o)=>{if(o===0)return NaN;let a=i-n[o-1];if(t+=a>0?a:0,r+=a<0?-a:0,o<e)return NaN;if(o>e){let c=n[o-1]-n[o-2];t-=c>0?c:0,r-=c<0?-c:0;}let s=t/e,l=r/e;return l===0?100:100-100/(1+s/l)})}function tc(n,e){return n.map((t,r)=>{let i=n.slice(Math.max(0,r-e+1),r+1);return Math.max(...i.filter(isFinite))})}function rc(n,e){return n.map((t,r)=>{let i=n.slice(Math.max(0,r-e+1),r+1);return Math.min(...i.filter(isFinite))})}function ta(n,e){let t=yi(n,e);return n.map((r,i)=>{if(i<e-1)return NaN;let o=0;for(let a=0;a<e;a++)o+=(n[i-a]-t[i])**2;return Math.sqrt(o/e)})}function ic(n,e){return n.map((t,r)=>r>0&&(n[r-1]<=e[r-1]&&t>e[r]||n[r-1]>=e[r-1]&&t<e[r]))}function oc(n,e){return n.map((t,r)=>r>0&&n[r-1]<e[r-1]&&t>e[r])}function nc(n,e){return n.map((t,r)=>r>0&&n[r-1]>e[r-1]&&t<e[r])}var ra={sma:yi,ema:Wr,rma:Kl,wma:Jl,rsi:ec,highest:tc,lowest:rc,stdev:ta,cross:ic,crossover:oc,crossunder:nc,bbands(n,e,t=2){let r=yi(n,e),i=ta(n,e);return {upper:r.map((o,a)=>o+t*i[a]),middle:r,lower:r.map((o,a)=>o-t*i[a])}},macd(n,e=12,t=26,r=9){let i=Wr(n,e),o=Wr(n,t),a=i.map((l,c)=>l-o[c]),s=Wr(a.map(l=>isFinite(l)?l:0),r);return {macd:a,signal:s,histogram:a.map((l,c)=>l-s[c])}}},ac=["window","document","location","fetch","XMLHttpRequest","WebSocket","Function","setTimeout","setInterval","importScripts","require","process","__dirname","__filename","global","globalThis"];function sc(n){return `
|
|
597
|
+
"use strict";
|
|
598
|
+
${ac.map(t=>`const ${t} = undefined;`).join(" ")}
|
|
599
|
+
|
|
600
|
+
// Freeze Object/Array prototypes to prevent prototype-pollution attacks
|
|
601
|
+
// (adding properties that bleed across script invocations).
|
|
602
|
+
// Note: this does NOT block constructor-chain escapes such as
|
|
603
|
+
// (0).constructor.constructor('return globalThis')()
|
|
604
|
+
// because Number.prototype and Function.prototype are not frozen
|
|
605
|
+
// (Function.prototype must stay live for the factory itself).
|
|
606
|
+
Object.freeze(Object.prototype);
|
|
607
|
+
Object.freeze(Array.prototype);
|
|
608
|
+
|
|
609
|
+
// eval cannot be redeclared in strict mode (SyntaxError),
|
|
610
|
+
// but freezing Object.prototype blocks the indirect-eval
|
|
611
|
+
// bypass via this.constructor.constructor('return eval')().
|
|
612
|
+
|
|
613
|
+
let _name = 'Script';
|
|
614
|
+
let _shortName = 'Script';
|
|
615
|
+
let _overlay = false;
|
|
616
|
+
let _precision = 4;
|
|
617
|
+
const _figures = [];
|
|
618
|
+
const _inputs = {};
|
|
619
|
+
let _rows = null;
|
|
620
|
+
|
|
621
|
+
function study(name, opts) {
|
|
622
|
+
_name = name;
|
|
623
|
+
_shortName = (opts && opts.shortName) ? opts.shortName : name;
|
|
624
|
+
_overlay = (opts && opts.overlay) === true;
|
|
625
|
+
_precision = (opts && opts.precision != null) ? opts.precision : 4;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function input(title, defaultVal, opts) {
|
|
629
|
+
// Validate opts to prevent unexpected values from polluting the script context
|
|
630
|
+
_inputs[title] = defaultVal;
|
|
631
|
+
return defaultVal;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
function plot(values, opts) {
|
|
635
|
+
const key = 'plot' + (_figures.length + 1);
|
|
636
|
+
_figures.push({
|
|
637
|
+
key,
|
|
638
|
+
title: (opts && opts.title) ? opts.title + ': ' : key + ': ',
|
|
639
|
+
type: 'line',
|
|
640
|
+
});
|
|
641
|
+
if (!_rows) _rows = values.map(v => ({}));
|
|
642
|
+
values.forEach((v, i) => { if (_rows[i]) _rows[i][key] = (v == null || !isFinite(v)) ? null : v; });
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function plotLine(values, opts) { plot(values, opts); }
|
|
646
|
+
|
|
647
|
+
const ta = TA;
|
|
648
|
+
const math = Math;
|
|
649
|
+
|
|
650
|
+
${n}
|
|
651
|
+
|
|
652
|
+
return { name: _name, shortName: _shortName, overlay: _overlay, precision: _precision, figures: _figures, rows: _rows || [] };
|
|
653
|
+
`}var vi=class n{static _instance=null;_registry=new Map;constructor(){}static getInstance(){return n._instance||(n._instance=new n),n._instance}compile(e,t){let r=sc(e),i;try{i=new Function("open","high","low","close","volume","TA",r);}catch(l){throw new Error(`Script syntax error: ${l.message}`)}let o;try{o=i([],[],[],[],[],ra);}catch(l){throw new Error(`Script runtime error during metadata extraction: ${l.message}`)}let a=t??o.name??"Custom",s={name:a,shortName:o.shortName??a,series:o.overlay?"price":"normal",precision:o.precision??4,figures:o.figures,_source:e,calc(l){let c=l.map(g=>g.open),u=l.map(g=>g.high),h=l.map(g=>g.low),d=l.map(g=>g.close),m=l.map(g=>g.volume??0),p;try{p=i(c,u,h,d,m,ra);}catch(g){return console.error("[ScriptEngine] runtime error:",g),l.map(()=>({}))}return p.figures.length>0&&(this.figures=[...p.figures]),p.rows}};return this._registry.set(a,s),Xr(s),s}get(e){return this._registry.get(e)}list(){return [...this._registry.keys()]}remove(e){this._registry.delete(e);}},H_=vi;export{Xr as a,as as b,Ps as c,ws as d,Zp as e,Cn as f,Ds as g,Bs as h,O_ as i,N_ as j,V_ as k,H_ as l};
|