@dwlf/charting 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charting/types.d.ts +29 -0
- package/dist/components/overlays/MarkerOverlay.d.ts +15 -1
- package/dist/index.cjs +4 -4
- package/dist/index.js +2481 -2413
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),s=require("react")
|
|
2
|
-
`),j=Math.max(...M.map(B=>B.length))*m+y*2,w=i*1.2,d=M.length*w+y*2;let E="above",Y=p-b-d;Y<0&&(E="below",Y=p+b,Y+d>u&&(E="above",Y=Math.max(0,p-b-d)));let k=N-j/2;k<0&&(k=0),k+j>o&&(k=o-j);const v=E==="above"?Y+d:Y,$=Math.min(Math.max(N,k+y),k+j-y);return{key:F,anchorX:N,anchorY:p,bubbleX:k,bubbleY:Y,bubbleWidth:j,bubbleHeight:d,direction:E,baseX:$,baseY:v,textLines:M}});return l.jsx("g",{className:"message-bubble-overlay",children:x.map(h=>l.jsxs("g",{children:[a&&l.jsx("line",{x1:h.baseX,y1:h.baseY,x2:h.anchorX,y2:h.anchorY,stroke:c,strokeWidth:1.2}),l.jsx("rect",{x:h.bubbleX,y:h.bubbleY,width:h.bubbleWidth,height:h.bubbleHeight,fill:c,rx:4,ry:4}),h.textLines.map((F,D)=>l.jsx("text",{x:h.bubbleX+y,y:h.bubbleY+y+i+D*i*1.2-i*.2,fontSize:i,fill:f,children:F},`txt-${h.key}-${D}`))]},`msg-bubble-${h.key}`))})}Qt.propTypes={messages:oe.arrayOf(oe.shape({date:oe.oneOfType([oe.number,oe.string,oe.instanceOf(Date)]).isRequired,price:oe.number.isRequired,text:oe.string.isRequired})),xScale:oe.func.isRequired,yScale:oe.func.isRequired,xBandwidth:oe.number,chartWidth:oe.number.isRequired,chartHeight:oe.number.isRequired,bubbleColor:oe.string,textColor:oe.string,fontSize:oe.number,pointer:oe.bool,padding:oe.number};function er({startDate:e,endDate:t,entryPrice:r,stopPrice:n,takePrice:o,xScale:u,yScale:c,riskColor:f="rgba(255,0,0,0.25)",rewardColor:i="rgba(0,255,0,0.25)",messages:a=[],xBandwidth:y=0,chartWidth:m,chartHeight:b,bubbleColor:x="rgba(0,0,0,0.8)",textColor:h="white",fontSize:F=11,pointer:D=!0,padding:N=6}){const[p,M]=s.useState(!1);if(e==null||r==null||n==null||o==null)return null;const S=(R,I)=>R==null?I:R instanceof Date||typeof R=="number"?R:new Date(R),j=S(e,0),w=S(t??e,j),d=u(j),E=u(w),Y=c(Math.max(r,n)),k=Math.abs(c(r)-c(n)),v=c(Math.max(r,o)),$=Math.abs(c(r)-c(o)),B=E-d;return B<=0?null:l.jsxs("g",{className:"position-overlay",onClick:R=>{R.stopPropagation(),M(I=>!I)},style:{cursor:a!=null&&a.length?"pointer":"default"},children:[l.jsx("rect",{x:d,y:Y,width:B,height:k,fill:f,stroke:"none"}),l.jsx("rect",{x:d,y:v,width:B,height:$,fill:i,stroke:"none"}),p&&a&&a.length>0&&m&&b&&l.jsx(Qt,{messages:a,xScale:u,yScale:c,xBandwidth:y,chartWidth:m,chartHeight:b,bubbleColor:x,textColor:h,fontSize:F,pointer:D,padding:N})]})}er.propTypes={startDate:oe.oneOfType([oe.number,oe.string,oe.instanceOf(Date)]).isRequired,endDate:oe.oneOfType([oe.number,oe.string,oe.instanceOf(Date)]),entryPrice:oe.number.isRequired,stopPrice:oe.number.isRequired,takePrice:oe.number.isRequired,xScale:oe.func.isRequired,yScale:oe.func.isRequired,riskColor:oe.string,rewardColor:oe.string,messages:oe.arrayOf(oe.shape({date:oe.oneOfType([oe.number,oe.string,oe.instanceOf(Date)]).isRequired,price:oe.number.isRequired,text:oe.string.isRequired})),xBandwidth:oe.number,chartWidth:oe.number,chartHeight:oe.number,bubbleColor:oe.string,textColor:oe.string,fontSize:oe.number,pointer:oe.bool,padding:oe.number};function tr(e,t=50,r=30,n="daily"){const o=(n||"").toLowerCase(),u=o==="hourly"?36e5:864e5,c=e.length+r,[f,i]=s.useState(()=>Math.max(0,c-t)),[a,y]=s.useState(c),m=s.useRef(),[b,x]=s.useState(!1),[h,F]=s.useState(0),N=s.useCallback(()=>{const R=Math.min(a,e.length),I=e.slice(f,R);let X=[];if(a>e.length&&e.length){const J=new Date(e[e.length-1].date),K=Math.max(f,e.length),U=Math.max(0,a-K),_=K-(e.length-1);X=Array.from({length:U},(A,P)=>{const L=_+P,g=new Date(J.getTime()+L*u).toISOString();return{date:o==="hourly"?g:g.split("T")[0],_virtual:!0}})}return[...I,...X]},[f,a,e,o,u])(),p=N.length,M=s.useCallback((R,I)=>{const X=Math.max(0,Math.min(I,c)),J=Math.max(0,Math.min(R,c-X));return{start:J,end:J+X}},[c]);s.useEffect(()=>{const R=a-f;if(R<=0)return;const{start:I,end:X}=M(f,R);I!==f&&i(I),X!==a&&y(X)},[M,f,a]);const S=s.useCallback(R=>{x(!0),F(R.clientX)},[]),j=s.useCallback(R=>{if(!b)return;const I=R.clientX-h,X=m.current;if(!X)return;const J=X.getBoundingClientRect(),K={left:10,right:20},_=(J.width-K.left-K.right)/p,A=Math.round(I/(_*1.5));if(A!==0){const{start:P,end:L}=M(f-A,p);i(P),y(L),F(R.clientX)}},[b,h,p,f,M]),w=s.useCallback(()=>x(!1),[]),d=s.useCallback(R=>{R.preventDefault();const I=R.currentTarget.getBoundingClientRect(),X={left:10,right:20},J=I.width-X.left-X.right;if(Math.abs(R.deltaX)>Math.abs(R.deltaY)){const H=J/p,Q=Math.round(R.deltaX/(H*1.5));if(Q){const{start:ne,end:q}=M(f-Q,p);i(ne),y(q)}return}const _=(R.clientX-I.left-X.left)/J,P=1+R.deltaY*.002,L=P<=0?.1:P,le=Math.max(5,Math.min(c,Math.round(p*L)));if(le===p)return;const g=f+_*p,O=Math.round(g-_*le),{start:ge,end:Z}=M(O,le);i(ge),y(Z)},[p,f,M,c]),E=s.useCallback(R=>{m.current&&m.current.removeEventListener("wheel",d),m.current=R,R&&R.addEventListener("wheel",d,{passive:!1})},[d]),Y=s.useCallback(()=>{const R=Math.max(5,Math.round((a-f)*.8)),I=(f+a)/2,{start:X,end:J}=M(Math.round(I-R/2),R);i(X),y(J)},[f,a,M]),k=s.useCallback(()=>{const R=Math.min(c,Math.round((a-f)*1.25)),I=(f+a)/2,{start:X,end:J}=M(Math.round(I-R/2),R);i(X),y(J)},[f,a,M,c]),v=s.useCallback(()=>{const{start:R,end:I}=M(c-t,t);i(R),y(I)},[t,M,c]),$=s.useCallback(()=>{const{start:R,end:I}=M(0,p);i(R),y(I)},[M,p]),B=s.useCallback(()=>{const{start:R,end:I}=M(c-p,p);i(R),y(I)},[M,p,c]);return{visibleData:N,viewportStart:f,viewportEnd:a,visibleCount:p,mouseHandlers:{onMouseDown:S,onMouseMove:j,onMouseUp:w,onMouseLeave:w},chartElementRef:E,zoomIn:Y,zoomOut:k,resetView:v,panToStart:$,panToEnd:B,isPanning:b}}function rr(){const e=s.useRef(null),[t,r]=s.useState({width:0,height:0});return s.useEffect(()=>{if(!e.current)return;const n=new ResizeObserver(([o])=>{const{width:u,height:c}=o.contentRect;r({width:u,height:c})});return n.observe(e.current),()=>n.disconnect()},[]),[e,t]}const Lr=[0,1],Yr=.15,Te=e=>Number.isFinite(e),sr=e=>{if(!Array.isArray(e))return!1;if(e.length===0)return!0;const t=e[0];return t&&typeof t.t=="number"&&typeof t.v=="number"},ir=e=>{if(!Array.isArray(e))return!1;if(e.length===0)return!0;const t=e[0];return t&&typeof t.t=="number"&&typeof t.o=="number"&&typeof t.h=="number"&&typeof t.l=="number"&&typeof t.c=="number"},Ar=e=>{const t=e.data??[];if(!Array.isArray(t)||t.length===0)return[];if(e.type==="ohlc"&&ir(t)){const n=t.map(u=>u.l).filter(Te),o=t.map(u=>u.h).filter(Te);return[...n,...o]}if(sr(t)){const n=t.map(o=>o.v).filter(Te);return e.type==="hist"?[...n,0]:n}if(e.type==="marker")return t.map(n=>n&&typeof n=="object"?Number(n.v):Number.NaN).filter(Te);if(e.type==="position")return t.flatMap(n=>{if(!n||typeof n!="object")return[];const o=Number(n.entry),u=Number(n.stop),c=Number(n.target);return[o,u,c]}).filter(Te);const r=t.flatMap(n=>Object.values(n??{})).filter(Te);return e.type==="hist"?[...r,0]:r},Vr=(e,t,r)=>e.type==="ohlc"||!r?!0:t,_r=(e,t)=>{const r=[],n=e.series.some(m=>m.type==="ohlc");if(e.series.filter(m=>Vr(m,t,n)).forEach(m=>{const b=Ar(m);if(!b.length)return;const x=Le.min(b),h=Le.max(b);!Te(x)||!Te(h)||r.push([x,h])}),!r.length)return Lr;const u=Le.min(r.map(([m])=>m)),c=Le.max(r.map(([,m])=>m));if(!Te(u)||!Te(c)||u===c){const m=Te(u)?u:0;return[m-1,m+1]}const i=(c-u)*Yr,a=u-i,y=c+i;return!Number.isFinite(a)||!Number.isFinite(y)?[u,c]:[a,y]},zr=(e,t={})=>{const r=t.includeOverlaysInAutoScale??!1;if(e.yScale.mode==="fixed"){const n=Te(e.yScale.min)?e.yScale.min:0,o=Te(e.yScale.max)?e.yScale.max:1;return n===o?[n-1,o+1]:[n,o]}return _r(e,r)},Tr=(e,t)=>{const r=Le.scaleLinear().domain(e).range([t,0]);return{domain:e,scale:u=>r(u),invert:u=>r.invert(u)}},Br=(e,t,r={})=>{const n=r.includeOverlaysInAutoScale??e.includeOverlaysInAutoScale??!1,o={};return e.panes.forEach(u=>{const c=t[u.id]??0;o[u.id]=Tr(zr(u,{includeOverlaysInAutoScale:n}),c)}),o},Ir=e=>{const t=e.data??[];return Array.isArray(t)?ir(t)?t.map(r=>r.t).filter(Te):sr(t)?t.map(r=>r.t).filter(Te):e.type==="marker"?t.map(r=>r&&typeof r=="object"?Number(r.t):Number.NaN).filter(Te):e.type==="position"?t.flatMap(r=>{if(!r||typeof r!="object")return[];const n=Number(r.start),o=Number(r.end),u=[];return Number.isFinite(n)&&u.push(n),Number.isFinite(o)&&u.push(o),u}).filter(Te):t.map(r=>r&&typeof r.t=="number"?r.t:void 0).filter(Te):[]},Ur=e=>{const t=[];return e.series.forEach(r=>{t.push(...Ir(r))}),t},zt=e=>{const t=new Set;return e.panes.forEach(r=>{Ur(r).forEach(n=>t.add(n))}),Array.from(t).sort((r,n)=>r-n)},nt=(e,t)=>{if(!e.length)return Number.NaN;let r=0,n=e.length-1;for(;r<=n;){const c=Math.floor((r+n)/2),f=e[c];if(f===t)return f;f<t?r=c+1:n=c-1}const o=e[Math.max(0,n)],u=e[Math.min(e.length-1,r)];return Math.abs(o-t)<=Math.abs(u-t)?o:u},He={solid:void 0,dashed:"8 4",dotted:"2 4"},_e=(e,t,r)=>{if(!r)return;const n=r(e);if(n!==void 0)return n;if(!t||!t.length)return;const o=nt(t,e);if(Number.isFinite(o))return r(o)},tt=(e,t,r,n,o,u)=>{let c;if(r&&n&&o>0?c=_e(e,u,r):r&&(c=r(e)),r&&c===void 0)return;const i=t(c??e);return Number.isFinite(i)?i:void 0},Tt=e=>e instanceof Date?e.getTime():e,Bt=(e,t,r,n,o,u,c)=>{const f=tt(e,t,r,n,o,u);if(f!==void 0)return f;let i,a,y,m;if(r&&n&&o>0){if(!u||u.length===0)return;const F=Math.min(u.length-1,o-1);i=u[0],a=u[F],y=t(0),m=t(F)}else if(t.invert){const F=t.range?t.range():[0,c??0],D=t.invert(F[0]),N=t.invert(F[1]);i=Tt(D),a=Tt(N),y=t(i),m=t(a)}if(i===void 0||a===void 0||!Number.isFinite(i)||!Number.isFinite(a)||y===void 0||m===void 0||!Number.isFinite(y)||!Number.isFinite(m))return;const b=a-i;if(!Number.isFinite(b)||b===0)return;const x=(m-y)/b;if(!Number.isFinite(x))return;const h=y+(e-i)*x;return Number.isFinite(h)?h:void 0},qr=e=>e.button===0,Fe=({onDragMove:e,onDragStart:t,onDragEnd:r,shouldStart:n=qr,stopPropagation:o=!0,preventDefault:u=!0})=>{const[c,f]=s.useState(!1),i=s.useRef(null),a=s.useRef(e),y=s.useRef(t),m=s.useRef(r);s.useEffect(()=>{a.current=e},[e]),s.useEffect(()=>{y.current=t},[t]),s.useEffect(()=>{m.current=r},[r]),s.useEffect(()=>()=>{var x;(x=i.current)==null||x.call(i)},[]);const b=s.useCallback(x=>{var N,p;if(!n(x))return;o&&x.stopPropagation(),u&&x.preventDefault(),(N=i.current)==null||N.call(i),f(!0),(p=y.current)==null||p.call(y,x);const h=M=>{a.current(M)},F=()=>{var M;f(!1),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",D),i.current=null,(M=m.current)==null||M.call(m)},D=()=>{F()};i.current=F,document.addEventListener("mousemove",h),document.addEventListener("mouseup",D)},[u,n,o]);return{isDragging:c,handleMouseDown:b}},Gr={solid:void 0,dashed:"8 4",dotted:"2 4"},Se=12,at=10,Ue=16,Ae=32,Be=8,Xe=24,Qe=4,ft=Qe+Xe/4,dt=Qe+Xe*3/4,cr=({annotation:e,yScale:t,chartWidth:r,paneHeight:n,darkMode:o=!1,selected:u=!1,onSelect:c,onDoubleClick:f,onMove:i})=>{const a=s.useRef(0),y=s.useRef(0),m=s.useRef(t);s.useEffect(()=>{m.current=t},[t]);const b=s.useCallback(E=>{E.stopPropagation(),c==null||c(e.id)},[e.id,c]),x=s.useCallback(E=>{E.stopPropagation(),f==null||f(e.id)},[e.id,f]),h=s.useCallback(E=>{a.current=E.clientY,y.current=e.price},[e.price]),F=s.useCallback(E=>{const Y=E.clientY-a.current,k=m.current,v=k.invert(k.scale(y.current)+Y);Number.isFinite(v)&&(i==null||i(e.id,v))},[e.id,i]),{isDragging:D,handleMouseDown:N}=Fe({onDragStart:h,onDragMove:F}),p=t.scale(e.price);if(!Number.isFinite(p)||p<-20||p>n+20)return null;const M=He[e.lineStyle]||void 0,S=e.label||(e.showPrice?e.price.toFixed(2):""),j=Math.max(50,S.length*7+16),w=u?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",d=o?"#e2e8f0":"#1f2937";return l.jsxs("g",{className:"hline-annotation",onClick:b,onDoubleClick:x,style:{cursor:D?"grabbing":"pointer"},children:[u&&l.jsx("line",{x1:0,x2:r,y1:p,y2:p,stroke:w,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:0,x2:r,y1:p,y2:p,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:0,x2:r,y1:p,y2:p,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:M,strokeLinecap:"round"}),S&&l.jsxs("g",{children:[l.jsx("rect",{x:r-j-8,y:p-10,width:j,height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:r-j/2-8,y:p,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:S})]}),u&&l.jsxs("g",{onMouseDown:N,style:{cursor:"ns-resize"},children:[l.jsx("rect",{x:Qe,y:p-Xe/2,width:Xe,height:Xe,fill:d,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:2}),l.jsx("line",{x1:ft,x2:dt,y1:p-2,y2:p-2,stroke:e.color,strokeWidth:1.5}),l.jsx("line",{x1:ft,x2:dt,y1:p+2,y2:p+2,stroke:e.color,strokeWidth:1.5})]})]})},Zr=e=>{const t=new Date(e),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),o=String(t.getUTCHours()).padStart(2,"0"),u=String(t.getUTCMinutes()).padStart(2,"0");return`${r}/${n} ${o}:${u}`},lr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onDoubleClick:i,onMove:a,timeToIndex:y,indexToTime:m,dataLength:b=0,compressedTimes:x,timeFormatter:h=Zr})=>{const F=s.useRef(0),D=s.useRef(0),N=s.useRef(t),p=s.useRef(y),M=s.useRef(m),S=s.useRef(x),j=s.useRef(b);s.useEffect(()=>{N.current=t,p.current=y,M.current=m,S.current=x,j.current=b},[t,y,m,x,b]);const w=s.useCallback(_=>{_.stopPropagation(),f==null||f(e.id)},[e.id,f]),d=s.useCallback(_=>{_.stopPropagation(),i==null||i(e.id)},[e.id,i]),E=s.useCallback(_=>{F.current=_.clientX,D.current=e.time},[e.time]),Y=s.useCallback(_=>{const A=_.clientX-F.current,P=N.current,L=p.current,le=M.current,g=S.current,O=j.current,ge=L&&le&&O>0?_e(D.current,g,L)??D.current:D.current,Z=P(ge)+A;let H=D.current;if(P.invert){const Q=P.invert(Z),ne=Q instanceof Date?Q.getTime():Q;H=le?le(Math.round(ne)):ne}Number.isFinite(H)&&(a==null||a(e.id,H))},[e.id,a]),{isDragging:k,handleMouseDown:v}=Fe({onDragStart:E,onDragMove:Y});let $;if(y&&m&&b>0?$=_e(e.time,x,y):y&&($=y(e.time)),y&&$===void 0)return null;const B=$??e.time,R=t(B);if(!Number.isFinite(R)||R<-20||R>n+20)return null;const I=He[e.lineStyle]||void 0,X=e.label||(e.showTime?h(e.time):""),J=Math.max(60,X.length*7+16),K=c?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",U=u?"#e2e8f0":"#1f2937";return l.jsxs("g",{className:"vline-annotation",onClick:w,onDoubleClick:d,style:{cursor:k?"grabbing":"pointer"},children:[c&&l.jsx("line",{x1:R,x2:R,y1:0,y2:o,stroke:K,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:R,x2:R,y1:0,y2:o,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:R,x2:R,y1:0,y2:o,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:I,strokeLinecap:"round"}),X&&l.jsxs("g",{children:[l.jsx("rect",{x:R-J/2,y:4,width:J,height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:R,y:14,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:X})]}),c&&l.jsxs("g",{onMouseDown:v,style:{cursor:"ew-resize"},children:[l.jsx("rect",{x:R-Xe/2,y:o-Xe-Qe,width:Xe,height:Xe,fill:U,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:2}),l.jsx("line",{x1:R-2,x2:R-2,y1:o-Xe*.75-Qe,y2:o-Xe*.25-Qe,stroke:e.color,strokeWidth:1.5}),l.jsx("line",{x1:R+2,x2:R+2,y1:o-Xe*.75-Qe,y2:o-Xe*.25-Qe,stroke:e.color,strokeWidth:1.5})]})]})},nr=({annotation:e,xScale:t,yScale:r,paneHeight:n,darkMode:o=!1,selected:u=!1,onSelect:c,onDoubleClick:f,onMove:i,onTextEdit:a,timeToIndex:y,indexToTime:m,dataLength:b=0,compressedTimes:x})=>{const h=s.useCallback(I=>{I.stopPropagation(),c==null||c(e.id)},[e.id,c]),F=s.useCallback(I=>{I.stopPropagation(),f==null||f(e.id),a==null||a(e.id)},[e.id,f,a]),{handleMouseDown:D,indexValue:N,isDragging:p}=Fe({annotationId:e.id,time:e.time,price:e.price});if(y&&N===void 0)return null;const M=N??e.time,S=t(M),j=r.scale(e.price);if(!Number.isFinite(S)||!Number.isFinite(j)||j<-50||j>n+50)return null;const w=6,d=e.text.split(`
|
|
3
|
-
`),E=e.fontSize*1.3,Y=d.reduce((I,X)=>I.length>X.length?I:X,""),k=Math.max(20,Y.length*(e.fontSize*.6)+w*2),v=d.length===1?e.fontSize+w*2:d.length*E+w*2,$=u?o?"rgba(99, 179, 237, 0.5)":"rgba(59, 130, 246, 0.5)":"transparent",B=e.backgroundColor||(o?"rgba(30, 41, 59, 0.95)":"rgba(255, 255, 255, 0.95)"),R=u?o?"#63b3ed":"#3b82f6":o?"#475569":"#cbd5e1";return l.jsxs("g",{className:"text-annotation",onClick:h,onDoubleClick:F,onMouseDown:u?D:void 0,style:{cursor:p?"grabbing":u?"grab":"pointer"},children:[u&&l.jsx("rect",{x:S-k/2-3,y:j-v/2-3,width:k+6,height:v+6,fill:"none",stroke:$,strokeWidth:3,rx:6}),l.jsx("rect",{x:S-k/2,y:j-v/2,width:k,height:v,fill:B,stroke:R,strokeWidth:1,rx:4}),l.jsx("text",{x:S,y:j-(d.length-1)*E/2,dy:"0.35em",textAnchor:"middle",fontSize:e.fontSize,fill:e.color,fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:d.map((I,X)=>l.jsx("tspan",{x:S,dy:X===0?0:E,children:I},X))}),u&&l.jsx("circle",{cx:S,cy:j-v/2-8,r:Se,fill:o?"#e2e8f0":"#1f2937",stroke:R,strokeWidth:1,style:{cursor:"move"}})]})},Hr=(e,t,r,n,o,u,c,f)=>{let i=e,a=t,y=r,m=n;const b=r-e,x=n-t;if(b===0&&x===0)return{ex1:i,ey1:a,ex2:y,ey2:m};if(b===0)return c&&(a=(t<n?-1:1)<0?0:u),f&&(m=(n>t?1:-1)>0?u:0),{ex1:i,ey1:a,ex2:y,ey2:m};if(x===0)return c&&(i=(e<r?-1:1)<0?0:o,a=t),f&&(y=(r>e?1:-1)>0?o:0,m=n),{ex1:i,ey1:a,ex2:y,ey2:m};const h=x/b,F=t-h*e;if(c){const D=e<r?-1:1,N=D<0?0:o,p=h*N+F;let M=N,S=p;p<0?(M=-F/h,S=0):p>u&&(M=(u-F)/h,S=u),(D<0&&M<=e||D>0&&M>=e)&&(i=M,a=S)}if(f){const D=r>e?1:-1,N=D>0?o:0,p=h*N+F;let M=N,S=p;p<0?(M=-F/h,S=0):p>u&&(M=(u-F)/h,S=u),(D>0&&M>=r||D<0&&M<=r)&&(y=M,m=S)}return{ex1:i,ey1:a,ex2:y,ey2:m}},At=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b})=>{const x=s.useRef({x:0,y:0}),h=s.useRef({time1:0,price1:0,time2:0,price2:0}),F=s.useRef(t),D=s.useRef(r),N=s.useRef(a),p=s.useRef(y),M=s.useRef(b),S=s.useRef(m);s.useEffect(()=>{F.current=t,D.current=r,N.current=a,p.current=y,M.current=b,S.current=m},[t,r,a,y,b,m]);const j=s.useCallback(re=>{re.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((re,z,C,V)=>{const G=F.current,W=D.current,ee=N.current,ie=p.current,te=M.current,ce=S.current,Ce=!!(ee&&ie&&ce>0)?_e(re,te,ee):null,pe=G(Ce??re)+C,be=W.scale(z)+V;let we=re;if(G.invert){const xe=G.invert(pe),Pe=xe instanceof Date?xe.getTime():xe;we=ee&&ie&&ce>0?ie(Math.round(Pe)):Pe}const Me=W.invert(be);return{time:Number.isFinite(we)?we:re,price:Number.isFinite(Me)?Me:z}},[]),d=s.useCallback(re=>{x.current={x:re.clientX,y:re.clientY},h.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),E=s.useCallback(re=>{const z=re.clientX-x.current.x,C=re.clientY-x.current.y,{time:V,price:G}=w(h.current.time1,h.current.price1,z,C);i==null||i(e.id,{time1:V,price1:G})},[e.id,i,w]),{isDragging:Y,handleMouseDown:k}=Fe({onDragStart:d,onDragMove:E}),v=s.useCallback(re=>{const z=re.clientX-x.current.x,C=re.clientY-x.current.y,{time:V,price:G}=w(h.current.time2,h.current.price2,z,C);i==null||i(e.id,{time2:V,price2:G})},[e.id,i,w]),{isDragging:$,handleMouseDown:B}=Fe({onDragStart:d,onDragMove:v}),R=s.useCallback(re=>{const z=re.clientX-x.current.x,C=re.clientY-x.current.y,V=w(h.current.time1,h.current.price1,z,C),G=w(h.current.time2,h.current.price2,z,C);i==null||i(e.id,{time1:V.time,price1:V.price,time2:G.time,price2:G.price})},[e.id,i,w]),{isDragging:I,handleMouseDown:X}=Fe({onDragStart:d,onDragMove:R}),J=Y||$||I,K=Bt(e.time1,t,a,y,m,b,n),U=Bt(e.time2,t,a,y,m,b,n);if(K===void 0||U===void 0)return null;const _=r.scale(e.price1),A=r.scale(e.price2);if(!Number.isFinite(_)||!Number.isFinite(A))return null;const{ex1:P,ey1:L,ex2:le,ey2:g}=Hr(K,_,U,A,n,o,e.extendLeft,e.extendRight),O=P<-50&&le<-50||P>n+50&&le>n+50,ge=L<-50&&g<-50||L>o+50&&g>o+50;if(O||ge)return null;const Z=He[e.lineStyle]||void 0,H=c?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",Q=u?"#e2e8f0":"#1f2937",ne=e.label||"",q=(K+U)/2,se=(_+A)/2;return l.jsxs("g",{className:"trendline-annotation",onClick:j,style:{cursor:J?"grabbing":"pointer"},children:[c&&l.jsx("line",{x1:P,y1:L,x2:le,y2:g,stroke:H,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:P,y1:L,x2:le,y2:g,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?X:void 0}),l.jsx("line",{x1:P,y1:L,x2:le,y2:g,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:Z,strokeLinecap:"round"}),ne&&l.jsxs("g",{children:[l.jsx("rect",{x:q-ne.length*3.5-8,y:se-10,width:Math.max(30,ne.length*7+16),height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:q,y:se,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:ne})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:K,cy:_,r:Se,fill:Q,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:k,style:{cursor:"move"}}),l.jsx("circle",{cx:U,cy:A,r:Se,fill:Q,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:B,style:{cursor:"move"}}),l.jsx("circle",{cx:q,cy:se,r:at,fill:e.color,fillOpacity:.6,onMouseDown:X,style:{cursor:"grab"}})]})]})},ur=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b})=>{const x=s.useMemo(()=>({...e,type:"trendline",extendLeft:!1,extendRight:!0}),[e]),h=s.useMemo(()=>{if(i)return(F,D)=>{const{extendLeft:N,extendRight:p,type:M,...S}=D;i(F,S)}},[i]);return l.jsx(At,{annotation:x,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:c,onSelect:f,onMove:h,timeToIndex:a,indexToTime:y,dataLength:m,compressedTimes:b})},Kr=e=>{const t=new Date(e),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),o=String(t.getUTCHours()).padStart(2,"0"),u=String(t.getUTCMinutes()).padStart(2,"0");return`${r}/${n} ${o}:${u}`},or=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b,timeFormatter:x=Kr})=>{const h=s.useRef({x:0,y:0}),F=s.useRef({time:0,price:0}),D=s.useRef(t),N=s.useRef(r),p=s.useRef(a),M=s.useRef(y),S=s.useRef(b),j=s.useRef(m);s.useEffect(()=>{D.current=t,N.current=r,p.current=a,M.current=y,S.current=b,j.current=m},[t,r,a,y,b,m]);const w=s.useCallback(A=>{A.stopPropagation(),f==null||f(e.id)},[e.id,f]),d=s.useCallback(A=>{h.current={x:A.clientX,y:A.clientY},F.current={time:e.time,price:e.price}},[e.time,e.price]),E=s.useCallback(A=>{const P=A.clientX-h.current.x,L=A.clientY-h.current.y,le=D.current,g=N.current,O=p.current,ge=M.current,Z=S.current,H=j.current;let Q;O&&ge&&H>0?Q=_e(F.current.time,Z,O)??F.current.time:Q=F.current.time;const ne=le(Q)+P,q=g.scale(F.current.price)+L;let se=F.current.time;if(le.invert){const z=le.invert(ne),C=z instanceof Date?z.getTime():z;se=ge?ge(Math.round(C)):C}const re=g.invert(q);Number.isFinite(se)&&Number.isFinite(re)&&(i==null||i(e.id,se,re))},[e.id,i]),{isDragging:Y,handleMouseDown:k}=Fe({onDragStart:d,onDragMove:E}),v=tt(e.time,t,a,y,m,b),$=r.scale(e.price);if(v===void 0||!Number.isFinite($))return null;if(v<-50||v>n+50||$<-50||$>o+50){const A=v>=-50&&v<=n+50,P=$>=-50&&$<=o+50;if(!A&&!P)return null}const B=He[e.lineStyle]||void 0,R=c?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",I=u?"#e2e8f0":"#1f2937",X=e.showPrice?e.price.toFixed(2):"",J=e.showTime?x(e.time):"",K=e.label||"",U=X?Math.max(50,X.length*7+16):0,_=J?Math.max(60,J.length*7+16):0;return l.jsxs("g",{className:"crossline-annotation",onClick:w,style:{cursor:Y?"grabbing":"pointer"},children:[c&&l.jsxs(l.Fragment,{children:[l.jsx("line",{x1:0,x2:n,y1:$,y2:$,stroke:R,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:v,x2:v,y1:0,y2:o,stroke:R,strokeWidth:e.lineWidth+6,strokeLinecap:"round"})]}),l.jsx("line",{x1:0,x2:n,y1:$,y2:$,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:v,x2:v,y1:0,y2:o,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:0,x2:n,y1:$,y2:$,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:B,strokeLinecap:"round"}),l.jsx("line",{x1:v,x2:v,y1:0,y2:o,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:B,strokeLinecap:"round"}),l.jsx("circle",{cx:v,cy:$,r:4,fill:e.color,fillOpacity:.9,stroke:u?"#1a1a2e":"#fff",strokeWidth:1.5}),X&&l.jsxs("g",{children:[l.jsx("rect",{x:n-U-8,y:$-10,width:U,height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:n-U/2-8,y:$,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:X})]}),J&&l.jsxs("g",{children:[l.jsx("rect",{x:v-_/2,y:o-20,width:_,height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:v,y:o-10,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:J})]}),K&&l.jsxs("g",{children:[l.jsx("rect",{x:v+8,y:$-22,width:Math.max(30,K.length*7+12),height:18,fill:e.color,fillOpacity:.85,rx:3}),l.jsx("text",{x:v+8+Math.max(30,K.length*7+12)/2,y:$-13,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:K})]}),c&&l.jsxs("g",{onMouseDown:k,style:{cursor:"move"},children:[l.jsx("circle",{cx:v,cy:$,r:Se,fill:I,fillOpacity:.9,stroke:e.color,strokeWidth:2}),l.jsx("line",{x1:v-3,x2:v+3,y1:$,y2:$,stroke:e.color,strokeWidth:1.5}),l.jsx("line",{x1:v,x2:v,y1:$-3,y2:$+3,stroke:e.color,strokeWidth:1.5})]})]})},Jr={solid:void 0,dashed:"8 4",dotted:"2 4"},Rt=(e,t,r)=>{if(!r)return;const n=r(e);if(n!==void 0)return n;if(!t||!t.length)return;const o=nt(t,e);if(Number.isFinite(o))return r(o)},ar=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b})=>{const x=s.useRef({x:0,y:0}),h=s.useRef({time1:0,price1:0,time2:0,price2:0}),F=s.useRef(t),D=s.useRef(r),N=s.useRef(a),p=s.useRef(y),M=s.useRef(b),S=s.useRef(m);s.useEffect(()=>{F.current=t,D.current=r,N.current=a,p.current=y,M.current=b,S.current=m},[t,r,a,y,b,m]);const j=s.useCallback(q=>{q.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((q,se)=>{const re=F.current,z=N.current,C=p.current,V=M.current,G=S.current,W=z&&C&&G>0?Rt(q,V,z)??q:q,ee=re(W)+se;if(!re.invert)return q;const ie=re.invert(ee),te=ie instanceof Date?ie.getTime():ie;return z&&C&&G>0?C(Math.round(te)):te},[]),d=s.useCallback(q=>{x.current={x:q.clientX,y:q.clientY},h.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),E=s.useCallback(q=>{const se=q.clientX-x.current.x,re=q.clientY-x.current.y,z=D.current,C=h.current,V=w(C.time1,se),G=w(C.time2,se),W=z.invert(z.scale(C.price1)+re),ee=z.invert(z.scale(C.price2)+re);[V,G,W,ee].every(Number.isFinite)&&(i==null||i(e.id,{time1:V,price1:W,time2:G,price2:ee}))},[e.id,i,w]),Y=s.useCallback(q=>se=>{const re=se.clientX-x.current.x,z=se.clientY-x.current.y,C=D.current,V=h.current,G=C.scale(V.price1),W=C.scale(V.price2),ee=G<=W,ie={},te=F.current,ce=N.current,De=M.current,Ce=(ce?Rt(V.time1,De,ce):void 0)??V.time1,je=(ce?Rt(V.time2,De,ce):void 0)??V.time2,pe=te(Ce),be=te(je),we=pe<=be;if(q==="tl"||q==="bl"){const Me=we?V.time1:V.time2,xe=w(Me,re);Number.isFinite(xe)&&(we?ie.time1=xe:ie.time2=xe)}else{const Me=we?V.time2:V.time1,xe=w(Me,re);Number.isFinite(xe)&&(we?ie.time2=xe:ie.time1=xe)}if(q==="tl"||q==="tr"){const Me=ee?V.price1:V.price2,xe=C.invert(C.scale(Me)+z);Number.isFinite(xe)&&(ee?ie.price1=xe:ie.price2=xe)}else{const Me=ee?V.price2:V.price1,xe=C.invert(C.scale(Me)+z);Number.isFinite(xe)&&(ee?ie.price2=xe:ie.price1=xe)}i==null||i(e.id,ie)},[e.id,i,w]),k=s.useRef(E),v=s.useCallback(q=>{k.current(q)},[]),{isDragging:$,handleMouseDown:B}=Fe({onDragStart:d,onDragMove:v}),R=s.useCallback(q=>{k.current=E,B(q)},[E,B]),I=s.useCallback(q=>se=>{k.current=Y(q),B(se)},[Y,B]),X=q=>{if(a&&y&&m>0)return Rt(q,b,a);if(a)return a(q)},J=X(e.time1),K=X(e.time2);if(a&&(J===void 0||K===void 0))return null;const U=t(J??e.time1),_=t(K??e.time2),A=r.scale(e.price1),P=r.scale(e.price2);if([U,_,A,P].some(q=>!Number.isFinite(q)))return null;const L=Math.min(U,_),le=Math.max(U,_),g=Math.min(A,P),O=Math.max(A,P),ge=le-L,Z=O-g;if(le<-50||L>n+50||O<-50||g>o+50)return null;const H=Jr[e.lineStyle]||void 0,Q=u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",ne=u?"#e2e8f0":"#1f2937";return l.jsxs("g",{className:"rectangle-annotation",onClick:j,style:{cursor:$?"grabbing":"pointer"},children:[c&&l.jsx("rect",{x:L-3,y:g-3,width:ge+6,height:Z+6,fill:"none",stroke:Q,strokeWidth:3,rx:2}),l.jsx("rect",{x:L-Be,y:g-Be,width:ge+Be*2,height:Z+Be*2,fill:"transparent",stroke:"transparent",strokeWidth:Be,style:{cursor:"pointer"}}),l.jsx("rect",{x:L,y:g,width:ge,height:Z,fill:e.color,fillOpacity:e.fillOpacity,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:H,rx:1,onMouseDown:c?R:void 0,style:{cursor:c?$?"grabbing":"move":"pointer"}}),e.label&&l.jsx("text",{x:L+6,y:g+14,fontSize:11,fill:e.color,fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:e.label}),c&&l.jsx("text",{x:le-6,y:O-6,fontSize:10,fill:u?"#94a3b8":"#64748b",textAnchor:"end",style:{pointerEvents:"none",userSelect:"none"},children:Math.abs(e.price2-e.price1).toFixed(2)}),c&&l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:L-Ue/2,y:g-Ue/2,width:Ue,height:Ue,fill:ne,stroke:e.color,strokeWidth:1.5,rx:2,onMouseDown:I("tl"),style:{cursor:"nwse-resize"}}),l.jsx("rect",{x:le-Ue/2,y:g-Ue/2,width:Ue,height:Ue,fill:ne,stroke:e.color,strokeWidth:1.5,rx:2,onMouseDown:I("tr"),style:{cursor:"nesw-resize"}}),l.jsx("rect",{x:L-Ue/2,y:O-Ue/2,width:Ue,height:Ue,fill:ne,stroke:e.color,strokeWidth:1.5,rx:2,onMouseDown:I("bl"),style:{cursor:"nesw-resize"}}),l.jsx("rect",{x:le-Ue/2,y:O-Ue/2,width:Ue,height:Ue,fill:ne,stroke:e.color,strokeWidth:1.5,rx:2,onMouseDown:I("br"),style:{cursor:"nwse-resize"}})]})]})},Qr=({annotationId:e,time:t,price:r,xScale:n,yScale:o,onMove:u,timeToIndex:c,indexToTime:f,dataLength:i=0,compressedTimes:a})=>{const y=s.useRef({x:0,y:0}),m=s.useRef({time:0,price:0}),b=s.useRef(n),x=s.useRef(o),h=s.useRef(c),F=s.useRef(f),D=s.useRef(i),N=s.useRef(a);s.useEffect(()=>{b.current=n,x.current=o,h.current=c,F.current=f,D.current=i,N.current=a},[n,o,c,f,i,a]);const p=s.useCallback(d=>{y.current={x:d.clientX,y:d.clientY},m.current={time:t,price:r}},[r,t]),M=s.useCallback(d=>{const E=d.clientX-y.current.x,Y=d.clientY-y.current.y,k=b.current,v=x.current,$=h.current,B=F.current,R=D.current,I=N.current;let X=m.current.time;$&&B&&R>0&&(X=_e(m.current.time,I,$)??m.current.time);const J=k(X)+E,K=v.scale(m.current.price)+Y;let U=m.current.time;if(k.invert){const A=k.invert(J),P=A instanceof Date?A.getTime():A;U=B?B(Math.round(P)):P}const _=v.invert(K);Number.isFinite(U)&&Number.isFinite(_)&&(u==null||u(e,U,_))},[e,u]),{isDragging:S,handleMouseDown:j}=Fe({onDragStart:p,onDragMove:M}),w=s.useMemo(()=>{if(c&&f&&i>0)return _e(t,a,c);if(c)return c(t)},[a,i,f,t,c]);return{handleMouseDown:j,indexValue:w,isDragging:S}},fr=({annotation:e,xScale:t,yScale:r,paneHeight:n,darkMode:o=!1,selected:u=!1,onSelect:c,onMove:f,timeToIndex:i,indexToTime:a,dataLength:y=0,compressedTimes:m})=>{const b=s.useCallback(w=>{w.stopPropagation(),c==null||c(e.id)},[e.id,c]),{handleMouseDown:x,indexValue:h,isDragging:F}=Qr({annotationId:e.id,time:e.time,price:e.price,xScale:t,yScale:r,onMove:f,timeToIndex:i,indexToTime:a,dataLength:y,compressedTimes:m});if(i&&h===void 0)return null;const D=h??e.time,N=t(D),p=r.scale(e.price);if(!Number.isFinite(N)||!Number.isFinite(p)||p<-50||p>n+50)return null;const M=e.size??24,S=M+8,j=o?"rgba(99, 179, 237, 0.5)":"rgba(59, 130, 246, 0.5)";return l.jsxs("g",{className:"emoji-annotation",onClick:b,onMouseDown:u?x:void 0,style:{cursor:F?"grabbing":u?"grab":"pointer"},children:[u&&l.jsx("circle",{cx:N,cy:p,r:S/2+4,fill:"none",stroke:j,strokeWidth:2.5,strokeDasharray:"4 3"}),l.jsx("circle",{cx:N,cy:p,r:S/2,fill:"transparent",style:{cursor:"pointer"}}),l.jsx("text",{x:N,y:p,dy:"0.35em",textAnchor:"middle",fontSize:M,style:{pointerEvents:"none",userSelect:"none"},children:e.emoji}),u&&l.jsx("circle",{cx:N,cy:p-S/2-8,r:Se,fill:o?"#e2e8f0":"#1f2937",stroke:o?"#475569":"#cbd5e1",strokeWidth:1,style:{cursor:"move"}})]})},es={solid:void 0,dashed:"8 4",dotted:"2 4"},dr=({annotation:e,xScale:t,chartWidth:r,paneHeight:n,darkMode:o=!1,selected:u=!1,onSelect:c,onMove:f,timeToIndex:i,indexToTime:a,dataLength:y=0,compressedTimes:m})=>{const b=s.useRef(0),x=s.useRef({time1:0,time2:0}),h=s.useRef(t),F=s.useRef(i),D=s.useRef(a),N=s.useRef(m);s.useEffect(()=>{h.current=t,F.current=i,D.current=a,N.current=m},[t,i,a,m]);const p=s.useCallback(H=>{H.stopPropagation(),c==null||c(e.id)},[e.id,c]),M=s.useCallback(H=>{const Q=F.current;if(!Q)return;const ne=N.current;return _e(H,ne,Q)??Q(H)},[]),S=s.useCallback((H,Q)=>{const ne=h.current,q=F.current,se=D.current;if(!!(q&&se)){const W=M(H);if(W===void 0)return H;const ee=ne(W)+Q;if(!ne.invert)return H;const ie=ne.invert(ee),te=ie instanceof Date?ie.getTime():ie;return se(Math.round(te))}const C=ne(H)+Q;if(!ne.invert)return H;const V=ne.invert(C);return V instanceof Date?V.getTime():V},[M]),j=s.useCallback(H=>{b.current=H.clientX,x.current={time1:e.time1,time2:e.time2}},[e.time1,e.time2]),w=s.useCallback(H=>{const Q=H.clientX-b.current,ne=x.current,q=S(ne.time1,Q),se=S(ne.time2,Q);Number.isFinite(q)&&Number.isFinite(se)&&(f==null||f(e.id,{time1:q,time2:se}))},[e.id,f,S]),d=s.useCallback(H=>Q=>{const ne=Q.clientX-b.current,q=x.current,se=h.current,re=F.current,z=D.current,C=!!(re&&z),V=C?M(q.time1):q.time1,G=C?M(q.time2):q.time2,W=V!==void 0&&G!==void 0?se(V)<=se(G):q.time1<=q.time2;if(H==="left"){const ee=W?q.time1:q.time2,ie=S(ee,ne);Number.isFinite(ie)&&(f==null||f(e.id,W?{time1:ie}:{time2:ie}))}else{const ee=W?q.time2:q.time1,ie=S(ee,ne);Number.isFinite(ie)&&(f==null||f(e.id,W?{time2:ie}:{time1:ie}))}},[e.id,f,S,M]),E=s.useRef(w),Y=s.useCallback(H=>{E.current(H)},[]),{isDragging:k,handleMouseDown:v}=Fe({onDragStart:j,onDragMove:Y}),$=s.useCallback(H=>{E.current=w,v(H)},[w,v]),B=s.useCallback(H=>Q=>{Q.stopPropagation(),E.current=d(H),v(Q)},[d,v]),R=H=>{if(i&&a&&y>0)return _e(H,m,i);if(i)return i(H)},I=R(e.time1),X=R(e.time2);if(i&&(I===void 0||X===void 0))return null;const J=I??e.time1,K=X??e.time2,U=t(J),_=t(K);if(!Number.isFinite(U)||!Number.isFinite(_))return null;const A=Math.min(U,_),P=Math.max(U,_),L=P-A;if(P<-50||A>r+50)return null;const le=es[e.lineStyle]||void 0,g=o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",O=o?"#e2e8f0":"#1f2937",ge=6,Z=40;return l.jsxs("g",{className:"timerange-annotation",onClick:p,style:{cursor:k?"grabbing":"pointer"},children:[u&&l.jsx("rect",{x:A-3,y:-3,width:L+6,height:n+6,fill:"none",stroke:g,strokeWidth:3}),l.jsx("rect",{x:A-Be,y:0,width:L+Be*2,height:n,fill:"transparent",stroke:"transparent",strokeWidth:Be,style:{cursor:"pointer"}}),l.jsx("rect",{x:A,y:0,width:L,height:n,fill:e.color,fillOpacity:e.fillOpacity,onMouseDown:u?$:void 0,style:{cursor:u?k?"grabbing":"move":"pointer"}}),l.jsx("line",{x1:A,x2:A,y1:0,y2:n,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:le}),l.jsx("line",{x1:P,x2:P,y1:0,y2:n,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:le}),e.label&&l.jsxs("g",{children:[l.jsx("rect",{x:A+4,y:4,width:Math.max(40,e.label.length*7+12),height:18,fill:e.color,fillOpacity:.85,rx:3}),l.jsx("text",{x:A+10,y:16,fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:e.label})]}),u&&l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:A-ge/2,y:n/2-Z/2,width:ge,height:Z,fill:O,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:1.5,onMouseDown:B("left"),style:{cursor:"ew-resize"}}),l.jsx("line",{x1:A-1,x2:A-1,y1:n/2-6,y2:n/2+6,stroke:e.color,strokeWidth:1,style:{pointerEvents:"none"}}),l.jsx("line",{x1:A+1,x2:A+1,y1:n/2-6,y2:n/2+6,stroke:e.color,strokeWidth:1,style:{pointerEvents:"none"}}),l.jsx("rect",{x:P-ge/2,y:n/2-Z/2,width:ge,height:Z,fill:O,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:1.5,onMouseDown:B("right"),style:{cursor:"ew-resize"}}),l.jsx("line",{x1:P-1,x2:P-1,y1:n/2-6,y2:n/2+6,stroke:e.color,strokeWidth:1,style:{pointerEvents:"none"}}),l.jsx("line",{x1:P+1,x2:P+1,y1:n/2-6,y2:n/2+6,stroke:e.color,strokeWidth:1,style:{pointerEvents:"none"}})]})]})},ts={solid:void 0,dashed:"8 4",dotted:"2 4"},rs=(e,t,r,n,o=12,u=Math.PI/6)=>{const c=Math.atan2(n-t,r-e),f=r-o*Math.cos(c-u),i=n-o*Math.sin(c-u),a=r-o*Math.cos(c+u),y=n-o*Math.sin(c+u);return`${f},${i} ${r},${n} ${a},${y}`},hr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,onDoubleClick:a,timeToIndex:y,indexToTime:m,dataLength:b=0,compressedTimes:x})=>{const h=s.useRef({x:0,y:0}),F=s.useRef({time1:0,price1:0,time2:0,price2:0}),D=s.useRef("body"),N=s.useRef(t),p=s.useRef(r),M=s.useRef(y),S=s.useRef(m),j=s.useRef(x);s.useEffect(()=>{N.current=t,p.current=r,M.current=y,S.current=m,j.current=x},[t,r,y,m,x]);const w=s.useCallback(te=>{te.stopPropagation(),f==null||f(e.id)},[e.id,f]),d=s.useCallback(te=>{te.stopPropagation(),a==null||a(e.id)},[e.id,a]),E=s.useCallback((te,ce,De,Ce)=>{const je=N.current,pe=p.current,be=M.current,we=S.current,Me=j.current,xe=be&&we?_e(te,Me,be)??te:te,Pe=je(xe)+De,Ge=pe.scale(ce)+Ce;let Re=te;if(je.invert){const Ve=je.invert(Pe),Ie=Ve instanceof Date?Ve.getTime():Ve;Re=we?we(Math.round(Ie)):Ie}const ze=pe.invert(Ge);return{time:Re,price:ze}},[]),Y=s.useCallback(te=>{h.current={x:te.clientX,y:te.clientY},F.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),k=s.useCallback(te=>{const ce=te.clientX-h.current.x,De=te.clientY-h.current.y,Ce=F.current,je=D.current;if(je==="point1"){const{time:pe,price:be}=E(Ce.time1,Ce.price1,ce,De);Number.isFinite(pe)&&Number.isFinite(be)&&(i==null||i(e.id,{time1:pe,price1:be}))}else if(je==="point2"){const{time:pe,price:be}=E(Ce.time2,Ce.price2,ce,De);Number.isFinite(pe)&&Number.isFinite(be)&&(i==null||i(e.id,{time2:pe,price2:be}))}else{const pe=E(Ce.time1,Ce.price1,ce,De),be=E(Ce.time2,Ce.price2,ce,De);Number.isFinite(pe.time)&&Number.isFinite(pe.price)&&Number.isFinite(be.time)&&Number.isFinite(be.price)&&(i==null||i(e.id,{time1:pe.time,price1:pe.price,time2:be.time,price2:be.price}))}},[e.id,i,E]),{isDragging:v,handleMouseDown:$}=Fe({onDragStart:Y,onDragMove:k}),B=s.useCallback(te=>ce=>{ce.stopPropagation(),D.current=te,$(ce)},[$]),R=te=>{if(y&&m&&b>0)return _e(te,x,y);if(y)return y(te)},I=R(e.time1),X=R(e.time2);if(y&&(I===void 0||X===void 0))return null;const J=t(I??e.time1),K=r.scale(e.price1),U=t(X??e.time2),_=r.scale(e.price2);if(!Number.isFinite(J)||!Number.isFinite(K)||!Number.isFinite(U)||!Number.isFinite(_))return null;const A=100;if(J<-A&&U<-A||J>n+A&&U>n+A||K<-A&&_<-A||K>o+A&&_>o+A)return null;const L=ts[e.lineStyle]||void 0,le=u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",g=u?"#e2e8f0":"#1f2937",O=6,ge=e.fontSize*1.3,Z=e.text||"",H=Z.split(`
|
|
4
|
-
`),Q=H.length,ne=Math.max(...H.map(te=>te.length),1),q=Math.max(24,ne*(e.fontSize*.6)+O*2),se=Q===1?e.fontSize+O*2:Q*ge+O*2,re=u?"rgba(30, 41, 59, 0.95)":"rgba(255, 255, 255, 0.95)",z=c?u?"#63b3ed":"#3b82f6":e.color,C=U-J,V=_-K,G=Math.sqrt(C*C+V*V);let W=J,ee=K;if(G>0&&Z){const te=q/2,ce=se/2,De=Math.abs(C)>0?te/Math.abs(C):Number.POSITIVE_INFINITY,Ce=Math.abs(V)>0?ce/Math.abs(V):Number.POSITIVE_INFINITY,je=Math.min(De,Ce),pe=Math.min(G*je,G*.4);W=J+C/G*pe,ee=K+V/G*pe}const ie=rs(W,ee,U,_,10+e.lineWidth*2);return l.jsxs("g",{className:"arrow-annotation",onClick:w,onDoubleClick:d,style:{cursor:v?"grabbing":"pointer"},children:[c&&l.jsx("line",{x1:W,y1:ee,x2:U,y2:_,stroke:le,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:J,y1:K,x2:U,y2:_,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:W,y1:ee,x2:U,y2:_,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:L,strokeLinecap:"round",onMouseDown:c?B("body"):void 0,style:{cursor:c?v?"grabbing":"move":"pointer"}}),l.jsx("polyline",{points:ie,fill:"none",stroke:e.color,strokeWidth:e.lineWidth+.5,strokeLinejoin:"round",strokeLinecap:"round",style:{pointerEvents:"none"}}),Z&&l.jsxs("g",{children:[c&&l.jsx("rect",{x:J-q/2-3,y:K-se/2-3,width:q+6,height:se+6,fill:"none",stroke:le,strokeWidth:3,rx:6}),l.jsx("rect",{x:J-q/2,y:K-se/2,width:q,height:se,fill:re,stroke:z,strokeWidth:1,rx:4,onMouseDown:c?B("point1"):void 0,style:{cursor:c?v?"grabbing":"move":"pointer"}}),l.jsx("text",{x:J,textAnchor:"middle",fontSize:e.fontSize,fill:e.color,fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:H.map((te,ce)=>l.jsx("tspan",{x:J,y:K-se/2+O+ge*(ce+.7),children:te},ce))})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:J,cy:K-se/2-8,r:Se,fill:g,stroke:e.color,strokeWidth:1.5,onMouseDown:B("point1"),style:{cursor:"move"}}),l.jsx("circle",{cx:U,cy:_,r:Se,fill:g,stroke:e.color,strokeWidth:1.5,onMouseDown:B("point2"),style:{cursor:"move"}})]})]})},ss={solid:void 0,dashed:"8 4",dotted:"2 4"},It=(e,t,r,n,o,u,c,f)=>{let i=e,a=t,y=r,m=n;const b=r-e,x=n-t;if(b===0&&x===0)return{ex1:i,ey1:a,ex2:y,ey2:m};if(b===0)return c&&(a=t<n?0:u),f&&(m=n>t?u:0),{ex1:i,ey1:a,ex2:y,ey2:m};const h=x/b,F=t-h*e;if(c){const N=(e<r?-1:1)<0?0:o;if(h===0)i=N,a=t;else{const p=h*N+F;p>=0&&p<=u?(i=N,a=p):p<0?(i=-F/h,a=0):(i=(u-F)/h,a=u)}}if(f){const N=(r>e?1:-1)>0?o:0;if(h===0)y=N,m=n;else{const p=h*N+F;p>=0&&p<=u?(y=N,m=p):p<0?(y=-F/h,m=0):(y=(u-F)/h,m=u)}}return{ex1:i,ey1:a,ex2:y,ey2:m}},mr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b})=>{const x=s.useRef({x:0,y:0}),h=s.useRef({time1:0,price1:0,time2:0,price2:0,priceOffset:0}),F=s.useRef(t),D=s.useRef(r),N=s.useRef(a),p=s.useRef(y),M=s.useRef(b),S=s.useRef(m);s.useEffect(()=>{F.current=t,D.current=r,N.current=a,p.current=y,M.current=b,S.current=m},[t,r,a,y,b,m]);const j=s.useCallback(G=>{G.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((G,W,ee,ie)=>{const te=F.current,ce=D.current,De=N.current,Ce=p.current,je=M.current,pe=S.current,be=De&&Ce&&pe>0?_e(G,je,De)??G:G,we=te(be)+ee,Me=ce.scale(W)+ie;let xe=G;if(te.invert){const Ge=te.invert(we),Re=Ge instanceof Date?Ge.getTime():Ge;xe=Ce?Ce(Math.round(Re)):Re}const Pe=ce.invert(Me);return{time:Number.isFinite(xe)?xe:G,price:Number.isFinite(Pe)?Pe:W}},[]),d=s.useCallback(G=>{x.current={x:G.clientX,y:G.clientY},h.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2,priceOffset:e.priceOffset}},[e.time1,e.price1,e.time2,e.price2,e.priceOffset]),E=s.useCallback(G=>{const W=G.clientX-x.current.x,ee=G.clientY-x.current.y,{time:ie,price:te}=w(h.current.time1,h.current.price1,W,ee);i==null||i(e.id,{time1:ie,price1:te})},[e.id,i,w]),{isDragging:Y,handleMouseDown:k}=Fe({onDragStart:d,onDragMove:E}),v=s.useCallback(G=>{const W=G.clientX-x.current.x,ee=G.clientY-x.current.y,{time:ie,price:te}=w(h.current.time2,h.current.price2,W,ee);i==null||i(e.id,{time2:ie,price2:te})},[e.id,i,w]),{isDragging:$,handleMouseDown:B}=Fe({onDragStart:d,onDragMove:v}),R=s.useCallback(G=>{const W=G.clientY-x.current.y,ee=D.current,ie=h.current.price1+h.current.priceOffset,te=ee.scale(ie),ce=ee.invert(te+W);if(Number.isFinite(ce)){const De=ce-h.current.price1;i==null||i(e.id,{priceOffset:De})}},[e.id,i]),{isDragging:I,handleMouseDown:X}=Fe({onDragStart:d,onDragMove:R}),J=s.useCallback(G=>{const W=G.clientX-x.current.x,ee=G.clientY-x.current.y,ie=w(h.current.time1,h.current.price1,W,ee),te=w(h.current.time2,h.current.price2,W,ee);i==null||i(e.id,{time1:ie.time,price1:ie.price,time2:te.time,price2:te.price})},[e.id,i,w]),{isDragging:K,handleMouseDown:U}=Fe({onDragStart:d,onDragMove:J}),_=Y||$||I||K,A=tt(e.time1,t,a,y,m,b),P=tt(e.time2,t,a,y,m,b);if(A===void 0||P===void 0)return null;const L=r.scale(e.price1),le=r.scale(e.price2);if(!Number.isFinite(L)||!Number.isFinite(le))return null;const g=r.scale(e.price1+e.priceOffset),O=r.scale(e.price2+e.priceOffset);if(!Number.isFinite(g)||!Number.isFinite(O)||A<-50&&P<-50||A>n+50&&P>n+50)return null;const Z=It(A,L,P,le,n,o,e.extendLeft,e.extendRight),H=It(A,g,P,O,n,o,e.extendLeft,e.extendRight),Q=ss[e.lineStyle]||void 0,ne=c?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",q=u?"#e2e8f0":"#1f2937",se=e.label||"",re=(A+P)/2,z=(L+le)/2,C=(g+O)/2,V=`${Z.ex1},${Z.ey1} ${Z.ex2},${Z.ey2} ${H.ex2},${H.ey2} ${H.ex1},${H.ey1}`;return l.jsxs("g",{className:"channel-annotation",onClick:j,style:{cursor:_?"grabbing":"pointer"},children:[l.jsx("polygon",{points:V,fill:e.color,fillOpacity:e.fillOpacity,stroke:"none",onMouseDown:c?U:void 0,style:{cursor:c?"grab":"pointer"}}),c&&l.jsxs(l.Fragment,{children:[l.jsx("line",{x1:Z.ex1,y1:Z.ey1,x2:Z.ex2,y2:Z.ey2,stroke:ne,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:H.ex1,y1:H.ey1,x2:H.ex2,y2:H.ey2,stroke:ne,strokeWidth:e.lineWidth+6,strokeLinecap:"round"})]}),l.jsx("line",{x1:Z.ex1,y1:Z.ey1,x2:Z.ex2,y2:Z.ey2,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:H.ex1,y1:H.ey1,x2:H.ex2,y2:H.ey2,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:Z.ex1,y1:Z.ey1,x2:Z.ex2,y2:Z.ey2,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:Q,strokeLinecap:"round"}),l.jsx("line",{x1:H.ex1,y1:H.ey1,x2:H.ex2,y2:H.ey2,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:Q,strokeLinecap:"round"}),se&&l.jsxs("g",{children:[l.jsx("rect",{x:re-se.length*3.5-8,y:z-10,width:Math.max(30,se.length*7+16),height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:re,y:z,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:se})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:A,cy:L,r:Se,fill:q,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:k,style:{cursor:"move"}}),l.jsx("circle",{cx:P,cy:le,r:Se,fill:q,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:B,style:{cursor:"move"}}),l.jsx("circle",{cx:re,cy:C,r:Se,fill:e.color,fillOpacity:.8,stroke:q,strokeWidth:2,onMouseDown:X,style:{cursor:"ns-resize"}}),l.jsx("circle",{cx:re,cy:z,r:at,fill:e.color,fillOpacity:.6,onMouseDown:U,style:{cursor:"grab"}})]})]})},yr=[0,.236,.382,.5,.618,.786,1],gr=[1.272,1.618,2,2.618],is={solid:void 0,dashed:"8 4",dotted:"2 4"},xr=(e,t,r)=>{if(!r)return;const n=r(e);if(n!==void 0)return n;if(!t||!t.length)return;const o=nt(t,e);if(Number.isFinite(o))return r(o)},Ut=(e,t,r,n,o,u)=>{let c;if(r&&n&&o>0?c=xr(e,u,r):r&&(c=r(e)),r&&c===void 0)return;const i=t(c??e);return Number.isFinite(i)?i:void 0},cs=e=>{const t=e*100;return t%1===0?`${t}%`:`${t.toFixed(1)}%`},ls=e=>Math.abs(e)<1?e.toPrecision(4):Math.abs(e)<10?e.toFixed(4):e.toFixed(2),br=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b})=>{const[x,h]=s.useState(null),F=s.useRef({x:0,y:0}),D=s.useRef({time1:0,price1:0,time2:0,price2:0}),N=s.useRef(t),p=s.useRef(r),M=s.useRef(a),S=s.useRef(y),j=s.useRef(b),w=s.useRef(m);s.useEffect(()=>{N.current=t,p.current=r,M.current=a,S.current=y,j.current=b,w.current=m},[t,r,a,y,b,m]);const d=s.useCallback(z=>{z.stopPropagation(),f==null||f(e.id)},[e.id,f]),E=s.useCallback((z,C,V,G)=>{const W=N.current,ee=p.current,ie=M.current,te=S.current,ce=j.current,De=w.current,Ce=ie&&te&&De>0?xr(z,ce,ie)??z:z,je=W(Ce)+V,pe=ee.scale(C)+G;let be=z;if(W.invert){const Me=W.invert(je),xe=Me instanceof Date?Me.getTime():Me;be=te?te(Math.round(xe)):xe}const we=ee.invert(pe);return{time:Number.isFinite(be)?be:z,price:Number.isFinite(we)?we:C}},[]),Y=s.useCallback(z=>{h(1),F.current={x:z.clientX,y:z.clientY},D.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),k=s.useCallback(z=>{const C=z.clientX-F.current.x,V=z.clientY-F.current.y,{time:G,price:W}=E(D.current.time1,D.current.price1,C,V);i==null||i(e.id,{time1:G,price1:W})},[e.id,i,E]),{isDragging:v,handleMouseDown:$}=Fe({onDragStart:Y,onDragMove:k,onDragEnd:()=>h(null)}),B=s.useCallback(z=>{h(2),F.current={x:z.clientX,y:z.clientY},D.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),R=s.useCallback(z=>{const C=z.clientX-F.current.x,V=z.clientY-F.current.y,{time:G,price:W}=E(D.current.time2,D.current.price2,C,V);i==null||i(e.id,{time2:G,price2:W})},[e.id,i,E]),{isDragging:I,handleMouseDown:X}=Fe({onDragStart:B,onDragMove:R,onDragEnd:()=>h(null)}),J=s.useCallback(z=>{h("whole"),F.current={x:z.clientX,y:z.clientY},D.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),K=s.useCallback(z=>{const C=z.clientX-F.current.x,V=z.clientY-F.current.y,G=E(D.current.time1,D.current.price1,C,V),W=E(D.current.time2,D.current.price2,C,V);i==null||i(e.id,{time1:G.time,price1:G.price,time2:W.time,price2:W.price})},[e.id,i,E]),{isDragging:U,handleMouseDown:_}=Fe({onDragStart:J,onDragMove:K,onDragEnd:()=>h(null)}),A=v||I||U,P=Ut(e.time1,t,a,y,m,b),L=Ut(e.time2,t,a,y,m,b),le=s.useMemo(()=>{const z=[...e.levels??[...yr]];if(e.showExtensions)for(const C of gr)z.includes(C)||z.push(C);return z.sort((C,V)=>C-V),z},[e.levels,e.showExtensions]);if(P===void 0||L===void 0)return null;const g=r.scale(e.price1),O=r.scale(e.price2);if(!Number.isFinite(g)||!Number.isFinite(O))return null;const ge=e.price2-e.price1,Z=Math.min(P,L),H=e.extendRight?n:Math.max(P,L),Q=H-Z;if(Q<1)return null;const ne=is[e.lineStyle]||void 0,q=c?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",se=u?"#e2e8f0":"#1f2937",re=le.map(z=>{const C=e.price1+ge*z;return{ratio:z,price:C,y:r.scale(C)}});return l.jsxs("g",{className:"fib-retracement-annotation",onClick:d,style:{cursor:A?"grabbing":"pointer"},children:[e.fillOpacity>0&&re.map((z,C)=>{if(C===0)return null;const V=re[C-1],G=Math.min(z.y,V.y),ee=Math.max(z.y,V.y)-G;return ee<.5?null:l.jsx("rect",{x:Z,y:G,width:Q,height:ee,fill:e.color,fillOpacity:e.fillOpacity*(C%2===0?1:.5),stroke:"none",onMouseDown:c?_:void 0,style:{cursor:c?"grab":"pointer"}},`fill-${z.ratio}`)}),c&&re.map(({ratio:z,y:C})=>l.jsx("line",{x1:Z,x2:H,y1:C,y2:C,stroke:q,strokeWidth:e.lineWidth+4,strokeLinecap:"round"},`glow-${z}`)),re.map(({ratio:z,price:C,y:V})=>{if(V<-50||V>o+50)return null;const G=cs(z),W=ls(C),ee=`${G} (${W})`,ie=Math.max(80,ee.length*6+16),te=z===0||z===.5||z===.618||z===1,ce=te?1:.7;return l.jsxs("g",{children:[l.jsx("line",{x1:Z,x2:H,y1:V,y2:V,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?_:void 0}),l.jsx("line",{x1:Z,x2:H,y1:V,y2:V,stroke:e.color,strokeWidth:te?e.lineWidth:e.lineWidth*.7,strokeDasharray:te?void 0:ne,strokeLinecap:"round",opacity:ce}),l.jsxs("g",{children:[l.jsx("rect",{x:H-ie-4,y:V-9,width:ie,height:18,fill:e.color,fillOpacity:te?.85:.65,rx:3}),l.jsx("text",{x:H-ie/2-4,y:V,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:te?600:400,style:{pointerEvents:"none",userSelect:"none"},children:ee})]})]},`level-${z}`)}),l.jsx("line",{x1:P,y1:g,x2:P,y2:O,stroke:e.color,strokeWidth:.5,strokeDasharray:"4 3",opacity:.5}),l.jsx("line",{x1:L,y1:g,x2:L,y2:O,stroke:e.color,strokeWidth:.5,strokeDasharray:"4 3",opacity:.5}),l.jsx("line",{x1:P,y1:g,x2:L,y2:O,stroke:e.color,strokeWidth:1,strokeDasharray:"6 3",opacity:.6}),e.label&&l.jsxs("g",{children:[l.jsx("rect",{x:Z+4,y:Math.min(g,O)-20,width:Math.max(40,e.label.length*7+12),height:16,fill:e.color,fillOpacity:.85,rx:3}),l.jsx("text",{x:Z+4+Math.max(40,e.label.length*7+12)/2,y:Math.min(g,O)-12,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:600,style:{pointerEvents:"none",userSelect:"none"},children:e.label})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:P,cy:g,r:Se,fill:se,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:$,style:{cursor:"move"}}),l.jsx("circle",{cx:L,cy:O,r:Se,fill:se,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:X,style:{cursor:"move"}}),l.jsx("circle",{cx:(P+L)/2,cy:(g+O)/2,r:at,fill:e.color,fillOpacity:.6,onMouseDown:_,style:{cursor:"grab"}})]})]})},ns=e=>{if(!e)return 864e5;const t=e.toLowerCase();return t.includes("1m")&&!t.includes("1mo")?6e4:t.includes("5m")?3e5:t.includes("15m")?9e5:t.includes("30m")?18e5:t.includes("hour")||t==="1h"||t==="60m"?36e5:t.includes("4h")?144e5:t.includes("week")?6048e5:t.includes("month")||t.includes("1mo")?2592e6:864e5},us=e=>{const t=Math.abs(e),r=Math.floor(t/6e4),n=Math.floor(t/36e5),o=Math.floor(t/864e5);if(o>0){const u=n-o*24;return u>0&&o<7?`${o}d ${u}h`:`${o}d`}if(n>0){const u=r-n*60;return u>0?`${n}h ${u}m`:`${n}h`}return`${r}m`},$t=e=>Math.abs(e)<.01?e.toPrecision(3):Math.abs(e)<1?e.toPrecision(4):Math.abs(e)<10?e.toFixed(4):Math.abs(e)<1e3?e.toFixed(2):e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),os=e=>`${e>=0?"+":""}${e.toFixed(2)}%`,pr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,currentTimeframe:a,timeToIndex:y,indexToTime:m,dataLength:b=0,compressedTimes:x})=>{const h=s.useRef({x:0,y:0}),F=s.useRef({time1:0,price1:0,time2:0,price2:0}),D=s.useRef(t),N=s.useRef(r),p=s.useRef(y),M=s.useRef(m),S=s.useRef(x),j=s.useRef(b);s.useEffect(()=>{D.current=t,N.current=r,p.current=y,M.current=m,S.current=x,j.current=b},[t,r,y,m,x,b]);const w=s.useCallback(Re=>{Re.stopPropagation(),f==null||f(e.id)},[e.id,f]),d=s.useCallback((Re,ze,Ve,Ie)=>{const qe=D.current,st=N.current,rt=p.current,ut=M.current,pt=S.current,ht=j.current,mt=!!(rt&&ut&&ht>0)?_e(Re,pt,rt):null,wt=qe(mt??Re)+Ve,kt=st.scale(ze)+Ie;let ot=Re;if(qe.invert){const gt=qe.invert(wt),Dt=gt instanceof Date?gt.getTime():gt;ot=rt&&ut&&ht>0?ut(Math.round(Dt)):Dt}const yt=st.invert(kt);return{time:Number.isFinite(ot)?ot:Re,price:Number.isFinite(yt)?yt:ze}},[]),E=s.useCallback(Re=>{h.current={x:Re.clientX,y:Re.clientY},F.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),Y=s.useCallback(Re=>{const ze=Re.clientX-h.current.x,Ve=Re.clientY-h.current.y,{time:Ie,price:qe}=d(F.current.time1,F.current.price1,ze,Ve);i==null||i(e.id,{time1:Ie,price1:qe})},[e.id,i,d]),{isDragging:k,handleMouseDown:v}=Fe({onDragStart:E,onDragMove:Y}),$=s.useCallback(Re=>{const ze=Re.clientX-h.current.x,Ve=Re.clientY-h.current.y,{time:Ie,price:qe}=d(F.current.time2,F.current.price2,ze,Ve);i==null||i(e.id,{time2:Ie,price2:qe})},[e.id,i,d]),{isDragging:B,handleMouseDown:R}=Fe({onDragStart:E,onDragMove:$}),I=s.useCallback(Re=>{const ze=Re.clientX-h.current.x,Ve=Re.clientY-h.current.y,Ie=d(F.current.time1,F.current.price1,ze,Ve),qe=d(F.current.time2,F.current.price2,ze,Ve);i==null||i(e.id,{time1:Ie.time,price1:Ie.price,time2:qe.time,price2:qe.price})},[e.id,i,d]),{isDragging:X,handleMouseDown:J}=Fe({onDragStart:E,onDragMove:I}),K=k||B||X,U=tt(e.time1,t,y,m,b,x),_=tt(e.time2,t,y,m,b,x),A=s.useMemo(()=>{const Re=e.price2-e.price1,ze=e.price1!==0?Re/e.price1*100:0,Ve=Math.abs(e.time2-e.time1),Ie=ns(a),qe=Math.max(1,Math.round(Ve/Ie)),st=us(Ve),rt=Re>=0;return{priceDiff:Re,pricePct:ze,timeDiffMs:Ve,barCount:qe,timeStr:st,isPositive:rt}},[e.price1,e.price2,e.time1,e.time2,a]);if(U===void 0||_===void 0)return null;const P=r.scale(e.price1),L=r.scale(e.price2);if(!Number.isFinite(P)||!Number.isFinite(L))return null;const{priceDiff:le,pricePct:g,barCount:O,timeStr:ge,isPositive:Z}=A,H=Math.min(U,_),Q=Math.max(U,_),ne=Math.min(P,L),q=Math.max(P,L),se=Math.max(Q-H,1),re=Math.max(q-ne,1),z=Z?"rgba(34, 197, 94, 0.12)":"rgba(239, 68, 68, 0.12)",C=Z?"#22c55e":"#ef4444",V=Z?"#4ade80":"#f87171",G=u?"rgba(23, 23, 23, 0.92)":"rgba(30, 30, 30, 0.92)",W=`${le>=0?"+":""}${$t(le)}`,ee=os(g),ie=`${O} bar${O!==1?"s":""}`,te=`${W} (${ee})`,ce=`${ie} • ${ge}`,De=11,Ce=16,je=Math.max(te.length,ce.length)*6.5+24,pe=Ce*2+14,be=(H+Q)/2,we=(ne+q)/2;let Me=be-je/2,xe=we-pe/2;Me<4&&(Me=4),Me+je>n-4&&(Me=n-je-4),xe<4&&(xe=4),xe+pe>o-4&&(xe=o-pe-4);const Pe=c?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",Ge=c?u?"#63b3ed":"#3b82f6":C;return l.jsxs("g",{className:"measure-annotation",onClick:w,style:{cursor:K?"grabbing":"pointer"},children:[c&&l.jsx("rect",{x:H-3,y:ne-3,width:se+6,height:re+6,fill:"none",stroke:Pe,strokeWidth:4,strokeDasharray:"6 3",opacity:.8}),c&&l.jsx("line",{x1:U,y1:P,x2:_,y2:L,stroke:Pe,strokeWidth:7,opacity:.6}),l.jsx("rect",{x:H,y:ne,width:se,height:re,fill:"transparent",style:{cursor:K?"grabbing":"grab"},onMouseDown:J}),l.jsx("rect",{x:H,y:ne,width:se,height:re,fill:z,stroke:C,strokeWidth:1,strokeDasharray:"6 3",style:{pointerEvents:"none"}}),l.jsx("line",{x1:U,y1:P,x2:_,y2:L,stroke:C,strokeWidth:1.5,strokeDasharray:"4 3",opacity:.8,style:{pointerEvents:"none"}}),l.jsx("circle",{cx:U,cy:P,r:c?Se:at,fill:Ge,fillOpacity:.9,stroke:c?u?"#1e293b":"#f8fafc":"none",strokeWidth:c?2:0,style:{cursor:k?"grabbing":"grab"},onMouseDown:v}),l.jsx("circle",{cx:_,cy:L,r:c?Se:at,fill:Ge,fillOpacity:.9,stroke:c?u?"#1e293b":"#f8fafc":"none",strokeWidth:c?2:0,style:{cursor:B?"grabbing":"grab"},onMouseDown:R}),l.jsx("line",{x1:H,y1:P,x2:Q,y2:P,stroke:C,strokeWidth:.5,strokeDasharray:"3 3",opacity:.4,style:{pointerEvents:"none"}}),l.jsx("line",{x1:H,y1:L,x2:Q,y2:L,stroke:C,strokeWidth:.5,strokeDasharray:"3 3",opacity:.4,style:{pointerEvents:"none"}}),l.jsx("line",{x1:U,y1:ne,x2:U,y2:q,stroke:C,strokeWidth:.5,strokeDasharray:"3 3",opacity:.4,style:{pointerEvents:"none"}}),l.jsx("line",{x1:_,y1:ne,x2:_,y2:q,stroke:C,strokeWidth:.5,strokeDasharray:"3 3",opacity:.4,style:{pointerEvents:"none"}}),l.jsxs("g",{style:{pointerEvents:"none"},children:[l.jsx("rect",{x:Me,y:xe,width:je,height:pe,fill:G,rx:6,stroke:C,strokeWidth:1,strokeOpacity:.6}),l.jsx("text",{x:Me+je/2,y:xe+12+Ce*0,dy:"0.35em",textAnchor:"middle",fontSize:De,fontWeight:700,fontFamily:"monospace",fill:V,style:{userSelect:"none"},children:te}),l.jsx("text",{x:Me+je/2,y:xe+12+Ce*1,dy:"0.35em",textAnchor:"middle",fontSize:De-1,fontWeight:400,fontFamily:"monospace",fill:u?"#a0a0a0":"#b0b0b0",style:{userSelect:"none"},children:ce})]}),l.jsxs("g",{style:{pointerEvents:"none"},children:[l.jsx("rect",{x:Q+4,y:P-9,width:70,height:18,fill:G,rx:3,stroke:C,strokeWidth:.5,strokeOpacity:.4}),l.jsx("text",{x:Q+39,y:P,dy:"0.35em",textAnchor:"middle",fontSize:10,fontFamily:"monospace",fill:u?"#d0d0d0":"#e0e0e0",style:{userSelect:"none"},children:$t(e.price1)})]}),l.jsxs("g",{style:{pointerEvents:"none"},children:[l.jsx("rect",{x:Q+4,y:L-9,width:70,height:18,fill:G,rx:3,stroke:C,strokeWidth:.5,strokeOpacity:.4}),l.jsx("text",{x:Q+39,y:L,dy:"0.35em",textAnchor:"middle",fontSize:10,fontFamily:"monospace",fill:u?"#d0d0d0":"#e0e0e0",style:{userSelect:"none"},children:$t(e.price2)})]})]})},as="M8 1.5a.5.5 0 0 1 .5.5v.54A4.002 4.002 0 0 1 12 6.5c0 1.57.39 2.8.87 3.66.24.43.46.72.62.89.08.09.13.13.15.15H2.36c.02-.02.07-.06.15-.15.16-.17.38-.46.62-.89C3.61 9.3 4 8.07 4 6.5A4.002 4.002 0 0 1 7.5 2.54V2a.5.5 0 0 1 .5-.5ZM6.5 13a1.5 1.5 0 0 0 3 0h-3Z",wr=({annotation:e,yScale:t,chartWidth:r,paneHeight:n,darkMode:o=!1,selected:u=!1,onSelect:c,onMove:f})=>{const i=s.useRef(0),a=s.useRef(0),y=s.useRef(t);s.useEffect(()=>{y.current=t},[t]);const m=s.useCallback(v=>{v.stopPropagation(),c==null||c(e.id)},[e.id,c]),b=s.useCallback(v=>{i.current=v.clientY,a.current=e.price},[e.price]),x=s.useCallback(v=>{const $=v.clientY-i.current,B=y.current,R=B.invert(B.scale(a.current)+$);Number.isFinite(R)&&(f==null||f(e.id,R))},[e.id,f]),{isDragging:h,handleMouseDown:F}=Fe({onDragStart:b,onDragMove:x}),D=t.scale(e.price);if(!Number.isFinite(D)||D<-20||D>n+20)return null;const N=Gr[e.lineStyle]??void 0,p=e.triggered,M=e.label??(e.showPrice?e.price.toFixed(2):""),j=Math.max(70,M.length*7+16+16+8),w=p?"#64748b":e.color,d=p?.5:1,E=u?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",Y=o?"#e2e8f0":"#1f2937",k=e.direction==="above"?`28,${D-2} 32,${D-8} 36,${D-2}`:`28,${D+2} 32,${D+8} 36,${D+2}`;return l.jsxs("g",{className:"alert-line-annotation",onClick:m,style:{cursor:h?"grabbing":"pointer"},children:[u&&l.jsx("line",{x1:0,x2:r,y1:D,y2:D,stroke:E,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:0,x2:r,y1:D,y2:D,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:0,x2:r,y1:D,y2:D,stroke:w,strokeWidth:e.lineWidth,strokeDasharray:N,strokeLinecap:"round",opacity:d}),!p&&l.jsx("polygon",{points:k,fill:w,opacity:.8}),l.jsxs("g",{children:[l.jsx("rect",{x:r-j-8,y:D-12,width:j,height:24,fill:p?"#64748b":w,fillOpacity:.9,rx:4}),l.jsxs("g",{transform:`translate(${r-j-2}, ${D-8}) scale(${p?.85:1})`,children:[l.jsx("path",{d:as,fill:"white",opacity:p?.5:1}),p&&l.jsx("line",{x1:2,y1:14,x2:14,y2:2,stroke:"white",strokeWidth:1.5,opacity:.8})]}),M&&l.jsx("text",{x:r-j/2+4,y:D,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},opacity:p?.6:1,children:M})]}),u&&l.jsxs("g",{onMouseDown:F,style:{cursor:"ns-resize"},children:[l.jsx("rect",{x:Qe,y:D-Xe/2,width:Xe,height:Xe,fill:Y,fillOpacity:.9,rx:3,stroke:w,strokeWidth:2}),l.jsx("line",{x1:ft,x2:dt,y1:D-2,y2:D-2,stroke:w,strokeWidth:1.5}),l.jsx("line",{x1:ft,x2:dt,y1:D+2,y2:D+2,stroke:w,strokeWidth:1.5})]})]})},Xt=(e,t,r,n)=>{if(r){let u=r(e);if(u===void 0&&n&&n.length>0){const f=nt(n,e);Number.isFinite(f)&&(u=r(f))}if(u===void 0)return;const c=t(u);return Number.isFinite(c)?c:void 0}const o=t(e);return Number.isFinite(o)?o:void 0},kr=({annotation:e,xScale:t,yScale:r,darkMode:n=!1,selected:o=!1,onSelect:u,onDoubleClick:c,onMove:f,timeToIndex:i,indexToTime:a,compressedTimes:y})=>{const m=s.useRef({x:0,y:0}),b=s.useRef([]),x=s.useRef(t),h=s.useRef(r);s.useEffect(()=>{x.current=t,h.current=r},[t,r]);const F=s.useCallback(Y=>{Y.stopPropagation(),u==null||u(e.id)},[e.id,u]),D=s.useCallback(Y=>{Y.stopPropagation(),c==null||c(e.id)},[e.id,c]),N=s.useMemo(()=>{const{points:Y}=e;if(!Y||Y.length<2)return"";const k=[];for(let v=0;v<Y.length;v++){const $=Xt(Y[v].t,t,i,y),B=r.scale(Y[v].v);$===void 0||!Number.isFinite(B)||k.push(k.length===0?`M${$},${B}`:`L${$},${B}`)}return k.join(" ")},[e,t,r,i,y]),p=s.useMemo(()=>{const{points:Y}=e;if(!Y||Y.length===0)return null;let k=1/0,v=-1/0,$=1/0,B=-1/0;for(const R of Y){const I=Xt(R.t,t,i,y),X=r.scale(R.v);I===void 0||!Number.isFinite(X)||(I<k&&(k=I),I>v&&(v=I),X<$&&($=X),X>B&&(B=X))}return Number.isFinite(k)?{minX:k,maxX:v,minY:$,maxY:B}:null},[e,t,r,i,y]),M=s.useCallback(Y=>{m.current={x:Y.clientX,y:Y.clientY},b.current=e.points.map(k=>({...k}))},[e.points]),S=s.useCallback(Y=>{const k=Y.clientX-m.current.x,v=Y.clientY-m.current.y,$=h.current,B=x.current,R=b.current;if(!R.length)return;let I,X,J;for(const P of R){const L=Xt(P.t,B,i,y),le=$.scale(P.v);if(L!==void 0&&Number.isFinite(le)){I=P,X=L,J=le;break}}if(!I||X===void 0||J===void 0)return;const K=$.invert(J+v);if(!Number.isFinite(K))return;const U=K-I.v;if(!Number.isFinite(U))return;let _=0;if(B.invert){const P=B.invert(X+k),L=P instanceof Date?P.getTime():P;if(!Number.isFinite(L))return;const le=a?a(Math.round(L)):L;if(!Number.isFinite(le))return;_=le-I.t}const A=R.map(P=>({t:P.t+_,v:P.v+U}));f==null||f(e.id,{points:A})},[e.id,f,i,a,y]),{isDragging:j,handleMouseDown:w}=Fe({onDragStart:M,onDragMove:S});if(!N)return null;const d=o?n?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",E=n?"#e2e8f0":"#1f2937";return l.jsxs("g",{className:"brush-annotation",onClick:F,onDoubleClick:D,style:{cursor:j?"grabbing":"pointer"},children:[o&&l.jsx("path",{d:N,fill:"none",stroke:d,strokeWidth:e.lineWidth+6,strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("path",{d:N,fill:"none",stroke:"transparent",strokeWidth:Math.max(Ae,e.lineWidth+8),strokeLinecap:"round",strokeLinejoin:"round",style:{cursor:"pointer"}}),l.jsx("path",{d:N,fill:"none",stroke:e.color,strokeWidth:e.lineWidth,strokeLinecap:"round",strokeLinejoin:"round"}),o&&p&&l.jsxs("g",{onMouseDown:w,style:{cursor:"grab"},children:[l.jsx("rect",{x:(p.minX+p.maxX)/2-Xe/2,y:p.minY-Xe-4,width:Xe,height:Xe,fill:E,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:2}),l.jsx("text",{x:(p.minX+p.maxX)/2,y:p.minY-Xe/2-4,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:e.color,style:{pointerEvents:"none",userSelect:"none"},children:"✥"})]})]})},qt=(e,t,r,n,o,u)=>{const c=r-e,f=n-t;if(c===0&&f===0)return{x:r,y:n};let i=1/0;return c>0?i=Math.min(i,(o-e)/c):c<0&&(i=Math.min(i,-e/c)),f>0?i=Math.min(i,(u-t)/f):f<0&&(i=Math.min(i,-t/f)),(!Number.isFinite(i)||i<0)&&(i=1),{x:e+c*i,y:t+f*i}},Dr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b})=>{const x=s.useRef({x:0,y:0}),h=s.useRef({time1:0,price1:0,time2:0,price2:0,time3:0,price3:0}),F=s.useRef(t),D=s.useRef(r),N=s.useRef(a),p=s.useRef(y),M=s.useRef(b),S=s.useRef(m);s.useEffect(()=>{F.current=t,D.current=r,N.current=a,p.current=y,M.current=b,S.current=m},[t,r,a,y,b,m]);const j=s.useCallback(W=>{W.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((W,ee,ie,te)=>{const ce=F.current,De=D.current,Ce=N.current,je=p.current,pe=M.current,be=S.current;let we;if(Ce&&je&&be>0){const Re=_e(W,pe,Ce);Re===void 0?we=W:we=Re}else we=W;const Me=ce(we)+ie,xe=De.scale(ee)+te;let Pe=W;if(ce.invert){const Re=ce.invert(Me),ze=Re instanceof Date?Re.getTime():Re;Pe=je?je(Math.round(ze)):ze}const Ge=De.invert(xe);return{time:Number.isFinite(Pe)?Pe:W,price:Number.isFinite(Ge)?Ge:ee}},[]),d=s.useCallback(W=>{x.current={x:W.clientX,y:W.clientY},h.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2,time3:e.time3,price3:e.price3}},[e.time1,e.price1,e.time2,e.price2,e.time3,e.price3]),E=s.useCallback(W=>{const ee=W.clientX-x.current.x,ie=W.clientY-x.current.y,{time:te,price:ce}=w(h.current.time1,h.current.price1,ee,ie);i==null||i(e.id,{time1:te,price1:ce})},[e.id,i,w]),{isDragging:Y,handleMouseDown:k}=Fe({onDragStart:d,onDragMove:E}),v=s.useCallback(W=>{const ee=W.clientX-x.current.x,ie=W.clientY-x.current.y,{time:te,price:ce}=w(h.current.time2,h.current.price2,ee,ie);i==null||i(e.id,{time2:te,price2:ce})},[e.id,i,w]),{isDragging:$,handleMouseDown:B}=Fe({onDragStart:d,onDragMove:v}),R=s.useCallback(W=>{const ee=W.clientX-x.current.x,ie=W.clientY-x.current.y,{time:te,price:ce}=w(h.current.time3,h.current.price3,ee,ie);i==null||i(e.id,{time3:te,price3:ce})},[e.id,i,w]),{isDragging:I,handleMouseDown:X}=Fe({onDragStart:d,onDragMove:R}),J=s.useCallback(W=>{const ee=W.clientX-x.current.x,ie=W.clientY-x.current.y,te=w(h.current.time1,h.current.price1,ee,ie),ce=w(h.current.time2,h.current.price2,ee,ie),De=w(h.current.time3,h.current.price3,ee,ie);i==null||i(e.id,{time1:te.time,price1:te.price,time2:ce.time,price2:ce.price,time3:De.time,price3:De.price})},[e.id,i,w]),{isDragging:K,handleMouseDown:U}=Fe({onDragStart:d,onDragMove:J}),_=Y||$||I||K,A=tt(e.time1,t,a,y,m,b),P=tt(e.time2,t,a,y,m,b),L=tt(e.time3,t,a,y,m,b);if(A===void 0||P===void 0||L===void 0)return null;const le=r.scale(e.price1),g=r.scale(e.price2),O=r.scale(e.price3);if(!Number.isFinite(le)||!Number.isFinite(g)||!Number.isFinite(O))return null;const ge=(P+L)/2,Z=(g+O)/2,H=ge-A,Q=Z-le,ne=(W,ee,ie,te)=>{if(e.extendRight){const be=qt(W,ee,W+ie,ee+te,n,o);return{endX:be.x,endY:be.y}}const ce=qt(W,ee,W+ie,ee+te,n,o),De=Math.sqrt(ie*ie+te*te);if(De===0)return{endX:W,endY:ee};const Ce=Math.sqrt((ce.x-W)**2+(ce.y-ee)**2),pe=Math.min(Ce,De*2)/De;return{endX:W+ie*pe,endY:ee+te*pe}},q=ne(A,le,H,Q),se=ne(P,g,H,Q),re=ne(L,O,H,Q),z=He[e.lineStyle]||void 0,C=c?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",V=u?"#e2e8f0":"#1f2937",G=`${P},${g} ${se.endX},${se.endY} ${re.endX},${re.endY} ${L},${O}`;return l.jsxs("g",{className:"pitchfork-annotation",onClick:j,style:{cursor:_?"grabbing":"pointer"},children:[l.jsx("polygon",{points:G,fill:e.color,fillOpacity:e.fillOpacity,stroke:"none",onMouseDown:c?U:void 0,style:{cursor:c?"grab":"pointer"}}),c&&l.jsxs(l.Fragment,{children:[l.jsx("line",{x1:A,y1:le,x2:q.endX,y2:q.endY,stroke:C,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:P,y1:g,x2:se.endX,y2:se.endY,stroke:C,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:L,y1:O,x2:re.endX,y2:re.endY,stroke:C,strokeWidth:e.lineWidth+6,strokeLinecap:"round"})]}),l.jsx("line",{x1:A,y1:le,x2:q.endX,y2:q.endY,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:P,y1:g,x2:se.endX,y2:se.endY,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:L,y1:O,x2:re.endX,y2:re.endY,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:A,y1:le,x2:P,y2:g,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:A,y1:le,x2:L,y2:O,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:A,y1:le,x2:q.endX,y2:q.endY,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:z,strokeLinecap:"round"}),l.jsx("line",{x1:P,y1:g,x2:se.endX,y2:se.endY,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:z,strokeLinecap:"round"}),l.jsx("line",{x1:L,y1:O,x2:re.endX,y2:re.endY,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:z,strokeLinecap:"round"}),l.jsx("line",{x1:A,y1:le,x2:P,y2:g,stroke:e.color,strokeWidth:e.lineWidth*.75,strokeDasharray:"4 3",strokeLinecap:"round",opacity:.5}),l.jsx("line",{x1:A,y1:le,x2:L,y2:O,stroke:e.color,strokeWidth:e.lineWidth*.75,strokeDasharray:"4 3",strokeLinecap:"round",opacity:.5}),e.label&&l.jsxs("g",{children:[l.jsx("rect",{x:ge-e.label.length*3.5-8,y:Z-10,width:Math.max(30,e.label.length*7+16),height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:ge,y:Z,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:e.label})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:A,cy:le,r:Se,fill:V,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:k,style:{cursor:"move"}}),l.jsx("circle",{cx:P,cy:g,r:Se,fill:V,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:B,style:{cursor:"move"}}),l.jsx("circle",{cx:L,cy:O,r:Se,fill:V,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:X,style:{cursor:"move"}}),l.jsx("circle",{cx:ge,cy:Z,r:at,fill:e.color,fillOpacity:.6,onMouseDown:U,style:{cursor:"grab"}})]})]})},fs={solid:void 0,dashed:"8 4",dotted:"2 4"},ds={0:"0%",.236:"23.6%",.382:"38.2%",.5:"50%",.618:"61.8%",.786:"78.6%",1:"100%",1.272:"127.2%",1.618:"161.8%",2:"200%",2.618:"261.8%",3.618:"361.8%",4.236:"423.6%"},hs=e=>ds[e]??`${(e*100).toFixed(1)}%`,Gt=["rgba(139, 92, 246, 0.06)","rgba(59, 130, 246, 0.06)","rgba(6, 182, 212, 0.06)","rgba(34, 197, 94, 0.06)","rgba(234, 179, 8, 0.06)","rgba(249, 115, 22, 0.06)","rgba(239, 68, 68, 0.06)"],St=(e,t,r,n,o,u)=>{let c;if(r&&n&&o>0?c=_e(e,u,r):r&&(c=r(e)),r&&c===void 0)return;const i=t(c??e);return Number.isFinite(i)?i:void 0},jr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b})=>{const x=s.useRef({x:0,y:0}),h=s.useRef({time1:0,price1:0,time2:0,price2:0,time3:0,price3:0}),F=s.useRef(t),D=s.useRef(r),N=s.useRef(a),p=s.useRef(y),M=s.useRef(b),S=s.useRef(m);s.useEffect(()=>{F.current=t,D.current=r,N.current=a,p.current=y,M.current=b,S.current=m},[t,r,a,y,b,m]);const j=s.useCallback(C=>{C.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((C,V,G,W)=>{const ee=F.current,ie=D.current,te=N.current,ce=p.current,De=M.current,Ce=S.current,je=te&&ce&&Ce>0?_e(C,De,te)??C:C,pe=ee(je)+G,be=ie.scale(V)+W;let we=C;if(ee.invert){const xe=ee.invert(pe),Pe=xe instanceof Date?xe.getTime():xe;we=ce?ce(Math.round(Pe)):Pe}const Me=ie.invert(be);return{time:Number.isFinite(we)?we:C,price:Number.isFinite(Me)?Me:V}},[]),d=s.useCallback(C=>{x.current={x:C.clientX,y:C.clientY},h.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2,time3:e.time3,price3:e.price3}},[e.time1,e.price1,e.time2,e.price2,e.time3,e.price3]),E=s.useCallback(C=>{const V=C.clientX-x.current.x,G=C.clientY-x.current.y,{time:W,price:ee}=w(h.current.time1,h.current.price1,V,G);i==null||i(e.id,{time1:W,price1:ee})},[e.id,i,w]),{isDragging:Y,handleMouseDown:k}=Fe({onDragStart:d,onDragMove:E}),v=s.useCallback(C=>{const V=C.clientX-x.current.x,G=C.clientY-x.current.y,{time:W,price:ee}=w(h.current.time2,h.current.price2,V,G);i==null||i(e.id,{time2:W,price2:ee})},[e.id,i,w]),{isDragging:$,handleMouseDown:B}=Fe({onDragStart:d,onDragMove:v}),R=s.useCallback(C=>{const V=C.clientX-x.current.x,G=C.clientY-x.current.y,{time:W,price:ee}=w(h.current.time3,h.current.price3,V,G);i==null||i(e.id,{time3:W,price3:ee})},[e.id,i,w]),{isDragging:I,handleMouseDown:X}=Fe({onDragStart:d,onDragMove:R}),J=s.useCallback(C=>{const V=C.clientX-x.current.x,G=C.clientY-x.current.y,W=w(h.current.time1,h.current.price1,V,G),ee=w(h.current.time2,h.current.price2,V,G),ie=w(h.current.time3,h.current.price3,V,G);i==null||i(e.id,{time1:W.time,price1:W.price,time2:ee.time,price2:ee.price,time3:ie.time,price3:ie.price})},[e.id,i,w]),{isDragging:K,handleMouseDown:U}=Fe({onDragStart:d,onDragMove:J}),_=Y||$||I||K,A=St(e.time1,t,a,y,m,b),P=St(e.time2,t,a,y,m,b),L=St(e.time3,t,a,y,m,b);if(A===void 0||P===void 0||L===void 0)return null;const le=r.scale(e.price1),g=r.scale(e.price2),O=r.scale(e.price3);if(!Number.isFinite(le)||!Number.isFinite(g)||!Number.isFinite(O))return null;const ge=e.price2-e.price1,Q=[...e.levels&&e.levels.length>0?e.levels:[0,.618,1,1.272,1.618,2,2.618]].sort((C,V)=>C-V).map(C=>{const V=e.price3+C*ge,G=r.scale(V);return{level:C,price:V,y:G}}).filter(C=>Number.isFinite(C.y)),ne=Math.min(A,P,L),q=fs[e.lineStyle]||void 0,se=c?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",re=u?"#e2e8f0":"#1f2937",z=u?"#1e1e1e":"#1f2937";return l.jsxs("g",{className:"fib-extension-annotation",onClick:j,style:{cursor:_?"grabbing":"pointer"},children:[e.fillOpacity>0&&Q.length>=2&&Q.map((C,V)=>{if(V===0)return null;const G=Q[V-1],W=Math.min(C.y,G.y),ie=Math.max(C.y,G.y)-W;return ie<1?null:l.jsx("rect",{x:ne,y:W,width:n-ne,height:ie,fill:Gt[V%Gt.length],fillOpacity:e.fillOpacity,style:{pointerEvents:"none"}},`fill-${C.level}`)}),c&&l.jsxs(l.Fragment,{children:[l.jsx("line",{x1:A,y1:le,x2:P,y2:g,stroke:se,strokeWidth:9,strokeLinecap:"round"}),l.jsx("line",{x1:P,y1:g,x2:L,y2:O,stroke:se,strokeWidth:9,strokeLinecap:"round"})]}),l.jsx("line",{x1:A,y1:le,x2:P,y2:g,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:P,y1:g,x2:L,y2:O,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:A,y1:le,x2:P,y2:g,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:"6 4",strokeLinecap:"round",opacity:.7}),l.jsx("line",{x1:P,y1:g,x2:L,y2:O,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:"6 4",strokeLinecap:"round",opacity:.7}),Q.map(C=>{const V=C.level===1||C.level===1.618||C.level===0,G=V?1:.7,W=V?e.lineWidth*1.5:e.lineWidth;return l.jsxs("g",{children:[c&&l.jsx("line",{x1:ne,x2:n,y1:C.y,y2:C.y,stroke:se,strokeWidth:W+6,strokeLinecap:"round"}),l.jsx("line",{x1:ne,x2:n,y1:C.y,y2:C.y,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?U:void 0}),l.jsx("line",{x1:ne,x2:n,y1:C.y,y2:C.y,stroke:e.color,strokeWidth:W,strokeDasharray:q,strokeLinecap:"round",opacity:G}),(()=>{const ee=hs(C.level),ie=e.showPrices?` (${ms(C.price)})`:"",te=`${ee}${ie}`,ce=Math.max(60,te.length*6.5+16);return l.jsxs("g",{children:[l.jsx("rect",{x:n-ce-8,y:C.y-10,width:ce,height:20,fill:z,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:.5,strokeOpacity:.5}),l.jsx("text",{x:n-ce/2-8,y:C.y,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:e.color,fontWeight:V?600:400,fontFamily:"monospace",style:{pointerEvents:"none",userSelect:"none"},children:te})]})})()]},`level-${C.level}`)}),e.label&&l.jsxs("g",{children:[l.jsx("rect",{x:L+8,y:O-10,width:Math.max(30,e.label.length*7+16),height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:L+8+Math.max(30,e.label.length*7+16)/2,y:O,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:e.label})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:A,cy:le,r:Se,fill:re,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:k,style:{cursor:"move"}}),l.jsx("text",{x:A,y:le-Se-4,textAnchor:"middle",fontSize:9,fill:e.color,style:{pointerEvents:"none",userSelect:"none"},children:"1"}),l.jsx("circle",{cx:P,cy:g,r:Se,fill:re,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:B,style:{cursor:"move"}}),l.jsx("text",{x:P,y:g-Se-4,textAnchor:"middle",fontSize:9,fill:e.color,style:{pointerEvents:"none",userSelect:"none"},children:"2"}),l.jsx("circle",{cx:L,cy:O,r:Se,fill:re,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:X,style:{cursor:"move"}}),l.jsx("text",{x:L,y:O-Se-4,textAnchor:"middle",fontSize:9,fill:e.color,style:{pointerEvents:"none",userSelect:"none"},children:"3"})]})]})};function ms(e){return Number.isFinite(e)?Math.abs(e)<1?e.toPrecision(4):Math.abs(e)<10?e.toFixed(4):e.toFixed(2):""}const ys={bullish:"#22c55e",bearish:"#ef4444"},gs=e=>e.color||ys[e.direction],xs=e=>e.state==="mitigated"?.15:e.state==="tested"?e.fillOpacity*.7:e.fillOpacity,bs=e=>e.state==="mitigated"?.3:1,Cr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b})=>{const x=s.useRef({x:0,y:0}),h=s.useRef({time:0,high:0,low:0}),F=s.useRef(r),D=s.useRef(t),N=s.useRef(a),p=s.useRef(y),M=s.useRef(b),S=s.useRef(m);s.useEffect(()=>{F.current=r,D.current=t,N.current=a,p.current=y,M.current=b,S.current=m},[r,t,a,y,b,m]);const j=s.useCallback(Z=>{Z.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback(Z=>{x.current={x:Z.clientX,y:Z.clientY},h.current={time:e.time,high:e.high,low:e.low}},[e.time,e.high,e.low]),d=s.useCallback((Z,H)=>{const Q=D.current,ne=N.current,q=p.current,se=M.current,re=S.current,z=ne&&q&&re>0&&se?ne(Z)!==void 0?ne(Z):ne(findClosestTime(se,Z))??Z:Z,C=Q(z)+H;if(!Q.invert)return Z;const V=Q.invert(C),G=V instanceof Date?V.getTime():V;return ne&&q&&re>0&&se?q(Math.round(G)):G},[]),E=s.useCallback(Z=>{const H=Z.clientX-x.current.x,Q=Z.clientY-x.current.y,ne=F.current,q=h.current,se=d(q.time,H),re=ne.invert(ne.scale(q.high)+Q),z=ne.invert(ne.scale(q.low)+Q);[se,re,z].every(Number.isFinite)&&(i==null||i(e.id,{time:se,high:re,low:z}))},[e.id,i,d]),{isDragging:Y,handleMouseDown:k}=Fe({onDragStart:w,onDragMove:E}),$=(Z=>{if(a&&y&&m>0)return _e(Z,b,a);if(a)return a(Z)})(e.time),B=t($??e.time),R=r.scale(e.high),I=r.scale(e.low);if([B,R,I].some(Z=>!Number.isFinite(Z)))return null;const X=B-20,J=B+20,K=Math.min(R,I),U=Math.max(R,I),_=J-X,A=U-K;if(J<-50||X>n+50||U<-50||K>o+50)return null;const P=gs(e),L=xs(e),le=bs(e),g=e.state==="tested"?He.dashed:He[e.lineStyle],O=u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",ge=e.label||(e.direction==="bullish"?"Buy OB":"Sell OB");return l.jsxs("g",{className:"order-block-annotation",onClick:j,style:{cursor:Y?"grabbing":"pointer"},children:[c&&l.jsx("rect",{x:X-3,y:K-3,width:_+6,height:A+6,fill:"none",stroke:O,strokeWidth:3,rx:2}),l.jsx("rect",{x:X-Be,y:K-Be,width:_+Be*2,height:A+Be*2,fill:"transparent",stroke:"transparent",strokeWidth:Be,style:{cursor:"pointer"}}),l.jsx("rect",{x:X,y:K,width:_,height:A,fill:P,fillOpacity:L,stroke:P,strokeWidth:e.lineWidth,strokeDasharray:g,strokeOpacity:le,rx:1,onMouseDown:c?k:void 0,style:{cursor:c?Y?"grabbing":"move":"pointer"}}),l.jsxs("g",{children:[l.jsx("rect",{x:X+2,y:K+2,width:Math.max(50,ge.length*7),height:16,fill:P,fillOpacity:.9,rx:2}),l.jsx("text",{x:X+2+Math.max(50,ge.length*7)/2,y:K+10,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:600,style:{pointerEvents:"none",userSelect:"none"},children:ge})]}),c&&l.jsx("text",{x:J-4,y:U-4,fontSize:9,fill:u?"#94a3b8":"#64748b",textAnchor:"end",style:{pointerEvents:"none",userSelect:"none"},children:(e.high-e.low).toFixed(2)})]})},ps={bullish:"#22c55e",bearish:"#ef4444"},ws=e=>e.color||ps[e.direction],ks=e=>e.filled?.1:e.fillOpacity,Ds=e=>e.filled?.3:1,Rr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:b})=>{const x=s.useRef({x:0,y:0}),h=s.useRef({time1:0,time2:0,top:0,bottom:0}),F=s.useRef(r),D=s.useRef(t),N=s.useRef(a),p=s.useRef(y),M=s.useRef(b),S=s.useRef(m);s.useEffect(()=>{F.current=r,D.current=t,N.current=a,p.current=y,M.current=b,S.current=m},[r,t,a,y,b,m]);const j=s.useCallback((Q,ne)=>{const q=D.current,se=N.current,re=p.current,z=M.current,C=S.current,V=se&&re&&C>0&&z?se(Q)!==void 0?se(Q):se(findClosestTime(z,Q))??Q:Q,G=q(V)+ne;if(!q.invert)return Q;const W=q.invert(G),ee=W instanceof Date?W.getTime():W;return se&&re&&C>0&&z?re(Math.round(ee)):ee},[]),w=s.useCallback(Q=>{Q.stopPropagation(),f==null||f(e.id)},[e.id,f]),d=s.useCallback(Q=>{x.current={x:Q.clientX,y:Q.clientY},h.current={time1:e.time1,time2:e.time2,top:e.top,bottom:e.bottom}},[e.time1,e.time2,e.top,e.bottom]),E=s.useCallback(Q=>{const ne=Q.clientX-x.current.x,q=Q.clientY-x.current.y,se=F.current,re=h.current,z=j(re.time1,ne),C=j(re.time2,ne),V=se.invert(se.scale(re.top)+q),G=se.invert(se.scale(re.bottom)+q);[z,C,V,G].every(Number.isFinite)&&(i==null||i(e.id,{time1:z,time2:C,top:V,bottom:G}))},[e.id,i,j]),{isDragging:Y,handleMouseDown:k}=Fe({onDragStart:d,onDragMove:E}),v=Q=>{if(a&&y&&m>0)return _e(Q,b,a);if(a)return a(Q)},$=v(e.time1)??e.time1,B=v(e.time2)??e.time2;if(!Number.isFinite($)||!Number.isFinite(B))return null;const R=t($),I=t(B),X=r.scale(e.top),J=r.scale(e.bottom);if([R,I,X,J].some(Q=>!Number.isFinite(Q)))return null;const K=Math.min(R,I),U=Math.max(R,I),_=Math.min(X,J),A=Math.max(X,J),P=U-K,L=A-_;if(U<-50||K>n+50||A<-50||_>o+50)return null;const le=ws(e),g=ks(e),O=Ds(e),ge=e.filled?He.dashed:He[e.lineStyle],Z=u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",H=e.label||"FVG";return l.jsxs("g",{className:"fair-value-gap-annotation",onClick:w,style:{cursor:Y?"grabbing":"pointer"},children:[c&&l.jsx("rect",{x:K-3,y:_-3,width:P+6,height:L+6,fill:"none",stroke:Z,strokeWidth:3,rx:2}),l.jsx("rect",{x:K-Be,y:_-Be,width:P+Be*2,height:L+Be*2,fill:"transparent",stroke:"transparent",strokeWidth:Be,style:{cursor:"pointer"}}),l.jsx("rect",{x:K,y:_,width:P,height:L,fill:le,fillOpacity:g,stroke:le,strokeWidth:e.lineWidth,strokeDasharray:ge,strokeOpacity:O,rx:1,onMouseDown:c?k:void 0,style:{cursor:c?Y?"grabbing":"move":"pointer"}}),l.jsxs("g",{children:[l.jsx("rect",{x:K+2,y:_+2,width:Math.max(50,H.length*7),height:16,fill:le,fillOpacity:.9,rx:2}),l.jsx("text",{x:K+2+Math.max(50,H.length*7)/2,y:_+10,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:600,style:{pointerEvents:"none",userSelect:"none"},children:H})]}),c&&l.jsx("text",{x:U-4,y:A-4,fontSize:9,fill:u?"#94a3b8":"#64748b",textAnchor:"end",style:{pointerEvents:"none",userSelect:"none"},children:(e.top-e.bottom).toFixed(2)})]})},js={bullish:"#22c55e",bearish:"#ef4444"},Cs=e=>e.color||js[e.direction],Rs=e=>e.bosType==="ChoCH"?He.dashed:He[e.lineStyle],Nr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selected:c=!1,onSelect:f,onDoubleClick:i,onMove:a,timeToIndex:y,dataLength:m=0,compressedTimes:b})=>{const x=s.useRef(0),h=s.useRef(0),F=s.useRef(r);s.useEffect(()=>{F.current=r},[r]);const D=s.useCallback(_=>{_.stopPropagation(),f==null||f(e.id)},[e.id,f]),N=s.useCallback(_=>{_.stopPropagation(),i==null||i(e.id)},[e.id,i]),p=s.useCallback(_=>{x.current=_.clientY,h.current=e.price},[e.price]),M=s.useCallback(_=>{const A=_.clientY-x.current,P=F.current,L=P.invert(P.scale(h.current)+A);Number.isFinite(L)&&(a==null||a(e.id,L))},[e.id,a]),{isDragging:S,handleMouseDown:j}=Fe({onDragStart:p,onDragMove:M}),w=r.scale(e.price);if(!Number.isFinite(w)||w<-20||w>o+20)return null;const d=Cs(e),E=Rs(e),Y=e.bosType==="ChoCH"?"ChoCH":"BOS",k=e.price.toFixed(2),v=Math.max(50,Y.length*7+16),$=Math.max(50,k.length*7+16),B=c?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",R=u?"#e2e8f0":"#1f2937",I=_e(e.time,b,y),X=t(I!==void 0?I:e.time),J=Number.isFinite(X)?X:0,K=e.confirmed?E:He.dashed,U=e.confirmed?1:.5;return l.jsxs("g",{className:"bos-line-annotation",onClick:D,onDoubleClick:N,style:{cursor:S?"grabbing":"pointer"},children:[c&&l.jsx("line",{x1:J,x2:n,y1:w,y2:w,stroke:B,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:J,x2:n,y1:w,y2:w,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:J,x2:n,y1:w,y2:w,stroke:d,strokeWidth:e.lineWidth,strokeDasharray:K,strokeLinecap:"round",opacity:U}),e.showLabel&&l.jsxs("g",{children:[l.jsx("rect",{x:J+4,y:w-10,width:v,height:20,fill:d,fillOpacity:.9,rx:4}),l.jsx("text",{x:J+4+v/2,y:w,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:600,style:{pointerEvents:"none",userSelect:"none"},children:Y})]}),e.showPrice&&l.jsxs("g",{children:[l.jsx("rect",{x:n-$-8,y:w-10,width:$,height:20,fill:d,fillOpacity:.9,rx:4}),l.jsx("text",{x:n-$/2-8,y:w,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:k})]}),c&&l.jsxs("g",{onMouseDown:j,style:{cursor:"ns-resize"},children:[l.jsx("rect",{x:J+Qe,y:w-Xe/2,width:Xe,height:Xe,fill:R,fillOpacity:.9,rx:3,stroke:d,strokeWidth:2}),l.jsx("line",{x1:J+ft,x2:J+dt,y1:w-2,y2:w-2,stroke:d,strokeWidth:1.5}),l.jsx("line",{x1:J+ft,x2:J+dt,y1:w+2,y2:w+2,stroke:d,strokeWidth:1.5})]})]})},vr=({annotations:e,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u=!1,selectedAnnotationId:c=null,onAnnotationSelect:f,onAnnotationDoubleClick:i,onAnnotationMove:a,onAnnotationTextEdit:y,timeToIndex:m,indexToTime:b,dataLength:x=0,compressedTimes:h,timeFormatter:F,currentTimeframe:D,animationPhase:N})=>{const p=s.useMemo(()=>D?e.filter(g=>!g.visibleTimeframes||g.visibleTimeframes.length===0||g.visibleTimeframes.includes(D)):e,[e,D]),M=s.useCallback((g,O)=>{a==null||a(g,{price:O})},[a]),S=s.useCallback((g,O)=>{a==null||a(g,{time:O})},[a]),j=s.useCallback((g,O,ge)=>{a==null||a(g,{time:O,price:ge})},[a]),w=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),d=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),E=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),Y=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),k=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),v=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),$=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),B=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),R=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),I=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),X=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),J=s.useCallback((g,O)=>{a==null||a(g,O)},[a]),K=s.useCallback((g,O)=>{a==null||a(g,{price:O})},[a]),U=s.useMemo(()=>[...p].sort((g,O)=>{if(g.id===c)return 1;if(O.id===c)return-1;const ge={brush:-1,timerange:0,rectangle:0,channel:0,pitchfork:0,fib_extension:0,order_block:0,fair_value_gap:0,arrow:1,text:2,emoji:2,fibRetracement:3,crossline:3,vline:3,trendline:4,ray:4,hline:5,bos_line:5,measure:6,alert_line:5},Z=ge[g.type]??2,H=ge[O.type]??2;return Z!==H?Z-H:0}),[p,c]),_=s.useMemo(()=>{if(h&&h.length>0)return h;if(!b||x<=0)return;const g=new Array(x);for(let O=0;O<x;O+=1)g[O]=b(O);return g},[h,b,x]),L=N!==void 0?N==="annotations"||N==="complete"?1:0:1,le={opacity:L,pointerEvents:L===0?"none":"auto",transition:N==="annotations"?"opacity 400ms ease-in-out":"none"};return l.jsx("g",{className:"annotation-layer",style:le,children:U.map(g=>g.type==="hline"?l.jsx(cr,{annotation:g,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:M},g.id):g.type==="vline"?l.jsx(lr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:S,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_,timeFormatter:F},g.id):g.type==="fib_extension"?l.jsx(jr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:I,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="order_block"?l.jsx(Cr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:X,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="fair_value_gap"?l.jsx(Rr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:J,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="bos_line"?l.jsx(Nr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:K,timeToIndex:m,dataLength:x,compressedTimes:_},g.id):g.type==="brush"?l.jsx(kr,{annotation:g,xScale:t,yScale:r,darkMode:u,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:a,timeToIndex:m,indexToTime:b,compressedTimes:_},g.id):g.type==="alert_line"?l.jsx(wr,{annotation:g,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:M},g.id):g.type==="trendline"?l.jsx(At,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:w,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="ray"?l.jsx(ur,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:d,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="crossline"?l.jsx(or,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:j,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_,timeFormatter:F},g.id):g.type==="rectangle"?l.jsx(ar,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:E,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="emoji"?l.jsx(fr,{annotation:g,xScale:t,yScale:r,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:j,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="timerange"?l.jsx(dr,{annotation:g,xScale:t,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:Y,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_,timeFormatter:F},g.id):g.type==="arrow"?l.jsx(hr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:k,onDoubleClick:i,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="channel"?l.jsx(mr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:v,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="fibRetracement"?l.jsx(br,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:$,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="measure"?l.jsx(pr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:B,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type==="pitchfork"?l.jsx(Dr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onMove:R,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id):g.type!=="text"?null:l.jsx(nr,{annotation:g,xScale:t,yScale:r,paneHeight:o,darkMode:u,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:j,onTextEdit:y,timeToIndex:m,indexToTime:b,dataLength:x,compressedTimes:_},g.id))})},Ns=(e,t,r,n={})=>{const o=Date.now();return{id:`hline-${o}-${Math.random().toString(36).slice(2,9)}`,type:"hline",symbol:e,timeframe:t,price:r,color:n.color??"#ef4444",lineStyle:n.lineStyle??"dashed",lineWidth:n.lineWidth??1.5,label:n.label,showPrice:n.showPrice??!0,visibleTimeframes:n.visibleTimeframes,createdAt:o,updatedAt:o}},vs=(e,t,r,n={})=>{const o=Date.now();return{id:`vline-${o}-${Math.random().toString(36).slice(2,9)}`,type:"vline",symbol:e,timeframe:t,time:r,color:n.color??"#3b82f6",lineStyle:n.lineStyle??"dashed",lineWidth:n.lineWidth??1.5,label:n.label,showTime:n.showTime??!0,visibleTimeframes:n.visibleTimeframes,createdAt:o,updatedAt:o}},Ms=(e,t,r,n,o,u={})=>{const c=Date.now();return{id:`text-${c}-${Math.random().toString(36).slice(2,9)}`,type:"text",symbol:e,timeframe:t,time:r,price:n,text:o,color:u.color??"#1f2937",backgroundColor:u.backgroundColor,fontSize:u.fontSize??12,visibleTimeframes:u.visibleTimeframes,createdAt:c,updatedAt:c}},Fs=(e,t,r,n,o,u,c={})=>{const f=Date.now();return{id:`trendline-${f}-${Math.random().toString(36).slice(2,9)}`,type:"trendline",symbol:e,timeframe:t,time1:r,price1:n,time2:o,price2:u,color:c.color??"#3b82f6",lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1.5,label:c.label,extendLeft:c.extendLeft??!1,extendRight:c.extendRight??!1,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Os=(e,t,r,n,o,u,c={})=>{const f=Date.now();return{id:`ray-${f}-${Math.random().toString(36).slice(2,9)}`,type:"ray",symbol:e,timeframe:t,time1:r,price1:n,time2:o,price2:u,color:c.color??"#f97316",lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1.5,label:c.label,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Ws=(e,t,r,n,o={})=>{const u=Date.now();return{id:`crossline-${u}-${Math.random().toString(36).slice(2,9)}`,type:"crossline",symbol:e,timeframe:t,time:r,price:n,color:o.color??"#06b6d4",lineStyle:o.lineStyle??"dashed",lineWidth:o.lineWidth??1,label:o.label,showPrice:o.showPrice??!0,showTime:o.showTime??!0,visibleTimeframes:o.visibleTimeframes??void 0,createdAt:u,updatedAt:u}},Ps=(e,t,r,n,o,u,c={})=>{const f=Date.now();return{id:`rect-${f}-${Math.random().toString(36).slice(2,9)}`,type:"rectangle",symbol:e,timeframe:t,time1:r,price1:n,time2:o,price2:u,color:c.color??"#3b82f6",fillOpacity:c.fillOpacity??.15,lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1.5,label:c.label,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Es=(e,t,r,n,o,u={})=>{const c=Date.now();return{id:`emoji-${c}-${Math.random().toString(36).slice(2,9)}`,type:"emoji",symbol:e,timeframe:t,time:r,price:n,emoji:o,size:u.size??24,visibleTimeframes:u.visibleTimeframes??void 0,createdAt:c,updatedAt:c}},$s=(e,t,r,n,o={})=>{const u=Date.now();return{id:`timerange-${u}-${Math.random().toString(36).slice(2,9)}`,type:"timerange",symbol:e,timeframe:t,time1:r,time2:n,color:o.color??"#8b5cf6",fillOpacity:o.fillOpacity??.12,lineStyle:o.lineStyle??"solid",lineWidth:o.lineWidth??1,label:o.label,visibleTimeframes:o.visibleTimeframes??void 0,createdAt:u,updatedAt:u}},Xs=(e,t,r,n,o,u,c,f={})=>{const i=Date.now();return{id:`arrow-${i}-${Math.random().toString(36).slice(2,9)}`,type:"arrow",symbol:e,timeframe:t,time1:r,price1:n,time2:o,price2:u,text:c,color:f.color??"#f97316",lineStyle:f.lineStyle??"solid",lineWidth:f.lineWidth??1.5,fontSize:f.fontSize??12,visibleTimeframes:f.visibleTimeframes??void 0,createdAt:i,updatedAt:i}},Ss=(e,t,r,n,o,u,c,f={})=>{const i=Date.now();return{id:`channel-${i}-${Math.random().toString(36).slice(2,9)}`,type:"channel",symbol:e,timeframe:t,time1:r,price1:n,time2:o,price2:u,priceOffset:c,color:f.color??"#8b5cf6",lineStyle:f.lineStyle??"solid",lineWidth:f.lineWidth??1.5,label:f.label,fillOpacity:f.fillOpacity??.08,extendLeft:f.extendLeft??!1,extendRight:f.extendRight??!1,visibleTimeframes:f.visibleTimeframes??void 0,createdAt:i,updatedAt:i}},Ls=(e,t,r,n,o,u,c={})=>{const f=Date.now();return{id:`fib-${f}-${Math.random().toString(36).slice(2,9)}`,type:"fibRetracement",symbol:e,timeframe:t,time1:r,price1:n,time2:o,price2:u,color:c.color??"#f59e0b",lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1,label:c.label,fillOpacity:c.fillOpacity??.1,levels:c.levels??[0,.236,.382,.5,.618,.786,1],showExtensions:c.showExtensions??!1,extendRight:c.extendRight??!0,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Ys=(e,t,r,n,o,u,c={})=>{const f=Date.now();return{id:`measure-${f}-${Math.random().toString(36).slice(2,9)}`,type:"measure",symbol:e,timeframe:t,time1:r,price1:n,time2:o,price2:u,color:c.color??"#f97316",visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},As=(e,t,r,n={})=>{const o=Date.now();return{id:`alert_line-${o}-${Math.random().toString(36).slice(2,9)}`,type:"alert_line",symbol:e,timeframe:t,price:r,color:n.color??"#f59e0b",lineStyle:n.lineStyle??"dashed",lineWidth:n.lineWidth??1.5,label:n.label,showPrice:n.showPrice??!0,triggered:n.triggered??!1,direction:n.direction??"above",alertId:n.alertId,visibleTimeframes:n.visibleTimeframes??void 0,createdAt:o,updatedAt:o}},Vs=(e,t,r,n={})=>{const o=Date.now();return{id:`brush-${o}-${Math.random().toString(36).slice(2,9)}`,type:"brush",symbol:e,timeframe:t,points:r,color:n.color??"#3b82f6",lineWidth:n.lineWidth??2,visibleTimeframes:n.visibleTimeframes??void 0,createdAt:o,updatedAt:o}},_s=(e,t,r,n,o,u,c,f,i={})=>{const a=Date.now();return{id:`pitchfork-${a}-${Math.random().toString(36).slice(2,9)}`,type:"pitchfork",symbol:e,timeframe:t,time1:r,price1:n,time2:o,price2:u,time3:c,price3:f,color:i.color??"#f97316",lineStyle:i.lineStyle??"solid",lineWidth:i.lineWidth??1.5,label:i.label,fillOpacity:i.fillOpacity??.06,extendRight:i.extendRight??!0,visibleTimeframes:i.visibleTimeframes??void 0,createdAt:a,updatedAt:a}},zs=(e,t,r,n,o,u,c,f,i={})=>{const a=Date.now();return{id:`fib_ext-${a}-${Math.random().toString(36).slice(2,9)}`,type:"fib_extension",symbol:e,timeframe:t,time1:r,price1:n,time2:o,price2:u,time3:c,price3:f,color:i.color??"#8b5cf6",lineStyle:i.lineStyle??"solid",lineWidth:i.lineWidth??1,label:i.label,levels:i.levels??[0,.618,1,1.272,1.618,2,2.618],fillOpacity:i.fillOpacity??.06,showPrices:i.showPrices??!0,visibleTimeframes:i.visibleTimeframes??void 0,createdAt:a,updatedAt:a}},Ts=(e,t,r,n,o,u,c={})=>{const f=Date.now(),i=u==="bullish"?"#22c55e":"#ef4444";return{id:`ob-${f}-${Math.random().toString(36).slice(2,9)}`,type:"order_block",symbol:e,timeframe:t,time:r,high:n,low:o,direction:u,state:c.state??"active",color:c.color??i,fillOpacity:c.fillOpacity??.25,lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1,label:c.label,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Bs=(e,t,r,n,o,u,c,f={})=>{const i=Date.now(),a=c==="bullish"?"#22c55e":"#ef4444";return{id:`fvg-${i}-${Math.random().toString(36).slice(2,9)}`,type:"fair_value_gap",symbol:e,timeframe:t,time1:r,time2:n,top:o,bottom:u,direction:c,filled:f.filled??!1,color:f.color??a,fillOpacity:f.fillOpacity??.2,lineStyle:f.lineStyle??"solid",lineWidth:f.lineWidth??1,label:f.label,visibleTimeframes:f.visibleTimeframes??void 0,createdAt:i,updatedAt:i}},Is=(e,t,r,n,o,u,c={})=>{const f=Date.now(),i=u==="bullish"?"#22c55e":"#ef4444";return{id:`bos-${f}-${Math.random().toString(36).slice(2,9)}`,type:"bos_line",symbol:e,timeframe:t,time:r,price:n,bosType:o,direction:u,confirmed:c.confirmed??!0,color:c.color??i,lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??2,showPrice:c.showPrice??!0,showLabel:c.showLabel??!0,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Us=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#64748b","#ffffff"],qs=400,Zt=16,Gs=Le.utcFormat("%Y-%m-%d %H:%M"),Mr=e=>{if(!Array.isArray(e))return!1;if(e.length===0)return!0;const t=e[0];return t&&typeof t.t=="number"&&typeof t.v=="number"},Fr=e=>{if(!Array.isArray(e))return!1;if(e.length===0)return!0;const t=e[0];return t&&typeof t.t=="number"&&typeof t.o=="number"&&typeof t.h=="number"&&typeof t.l=="number"&&typeof t.c=="number"},Ze=e=>{if(!Number.isFinite(e??NaN))return"—";const t=Math.abs(e);return t>=1e3?e.toFixed(0):t>=100?e.toFixed(1):e.toFixed(2)},Ht=(e,t)=>t?t(e):Gs(new Date(e)),Nt=e=>({...e,data:Array.isArray(e.data)?[...e.data]:[],style:e.style?{...e.style}:void 0}),Or=e=>({...e,series:e.series.map(Nt),guides:e.guides?e.guides.map(t=>({...t})):void 0}),bt=e=>({panes:e?e.panes.map(Or):[],timeFormatter:e==null?void 0:e.timeFormatter,onCrosshairMove:e==null?void 0:e.onCrosshairMove,onSeriesPointClick:e==null?void 0:e.onSeriesPointClick,includeOverlaysInAutoScale:e==null?void 0:e.includeOverlaysInAutoScale}),Zs=(e,t)=>{if(!e.panes.length||t<=0)return{rects:[],heights:{}};const r=e.panes.map(a=>a.heightRatio>0?a.heightRatio:1),n=r.reduce((a,y)=>a+y,0),o=Math.max(0,e.panes.length-1)*Zt,u=Math.max(0,t-o),c=[],f={};let i=0;return e.panes.forEach((a,y)=>{const m=r[y],b=u*(m/n);c.push({pane:a,y:i,height:b}),f[a.id]=b,i+=b+Zt}),{rects:c,heights:f}},Kt=(e,t)=>{if(!e.length)return null;let r=0,n=e.length-1;for(;r<=n;){const c=Math.floor((r+n)/2),f=e[c];if(f.t===t)return f;f.t<t?r=c+1:n=c-1}const o=e[Math.max(0,n)],u=e[Math.min(e.length-1,r)];return Math.abs(o.t-t)<=Math.abs(u.t-t)?o:u},Hs=(e,t)=>{if(!e.length)return null;let r=0,n=e.length-1;for(;r<=n;){const c=Math.floor((r+n)/2),f=e[c];if(f.t===t)return f;f.t<t?r=c+1:n=c-1}const o=e[Math.max(0,n)],u=e[Math.min(e.length-1,r)];return Math.abs(o.t-t)<=Math.abs(u.t-t)?o:u},Ks=(e,t,r)=>{if(!e.length)return Math.max(1,r*.01);if(e.length===1)return Math.max(4,Math.min(24,r*.6));let n=1/0;for(let o=1;o<e.length;o+=1){const u=t(e[o-1].t),c=t(e[o].t),f=Math.abs(c-u);f>0&&f<n&&(n=f)}return(!Number.isFinite(n)||n===1/0)&&(n=r/e.length),Math.max(1,Math.min(24,n*.7))},Wr=(e,t)=>{if(!Array.isArray(e)||e.length===0)return 6;if(e.length===1)return Math.max(4,Math.min(16,12));const r=[...e].sort((o,u)=>o.t-u.t);let n=1/0;for(let o=1;o<r.length;o+=1){const u=t(r[o-1].t),c=t(r[o].t),f=Math.abs(c-u);f>0&&f<n&&(n=f)}return!Number.isFinite(n)||n===1/0?6:Math.max(4,Math.min(18,n*.5))},Js=(e,t,r,n,o)=>{var F;const u=e.style??{},c=u.lineWidth??1.5,f=u.color??e.color??"#6b7280",i=u.opacity??1,a=u.dashed?"4 4":void 0,y=o&&o.phase!=="complete",m=((F=o==null?void 0:o.layerOpacities)==null?void 0:F[e.key])??(y?0:1),b=i*m;if(e.type==="hist"){let D=1/0;for(let M=1;M<t.length;M+=1){const S=n(t[M-1].t),j=n(t[M].t),w=Math.abs(j-S);w>0&&w<D&&(D=w)}(!Number.isFinite(D)||D===1/0)&&(D=8);const N=Math.max(2,Math.min(12,D*.4));let p="";return t.forEach(M=>{const S=n(M.t),j=r.scale(0),w=r.scale(M.v),d=Math.min(w,j),E=Math.max(w,j);p+=`M${S-N},${d}H${S+N}V${E}H${S-N}Z`}),l.jsx("path",{d:p,fill:f,opacity:b*.85,stroke:"none"})}if(e.type==="area"){const N=Le.area().defined(p=>Number.isFinite(p.v)).x(p=>n(p.t)).y0(()=>r.scale(r.domain[0])).y1(p=>r.scale(p.v))(t);return N?l.jsx("path",{d:N,fill:f,opacity:Math.min(.4,b),stroke:"none"}):null}const h=Le.line().defined(D=>Number.isFinite(D.v)).x(D=>n(D.t)).y(D=>r.scale(D.v))(t);return h?l.jsx("path",{d:h,stroke:f,strokeWidth:c,fill:"none",opacity:b,strokeDasharray:a}):null},Qs=(e,t,r,n,o)=>{var M,S,j,w,d,E,Y;if(!Array.isArray(t)||t.length===0)return null;const u=o==null?void 0:o.phase;if(u&&u!=="events"&&u!=="annotations"&&u!=="complete")return null;const c=Wr(t,n),f=((M=e.style)==null?void 0:M.markerShape)??"circle",i=((S=e.style)==null?void 0:S.markerSize)??6,a=((j=e.style)==null?void 0:j.color)??e.color??"#fbbf24",y=((w=e.style)==null?void 0:w.markerOffsetY)??0,m=((d=e.style)==null?void 0:d.markerFontSize)??10,b=((E=e.style)==null?void 0:E.markerTextColor)??a,x=((Y=e.style)==null?void 0:Y.markerTextOffsetY)??0,h=new Map,F=new Map;let D=0;if(t.forEach(k=>{if(!Number.isFinite(k==null?void 0:k.t)||!Number.isFinite(k==null?void 0:k.v))return;F.set(k,D),D+=1;const v=k.shape??f,$=k.size??i,B=k.color??a,R=k.offsetY??y,I=k.fontSize??m,X=k.textColor??b,J=k.textOffsetY??x,K={shape:v,size:$,color:B,offsetY:R,fontSize:I,textColor:X,textOffsetY:J},U=JSON.stringify(K);h.has(U)||h.set(U,{key:K,points:[]}),h.get(U).points.push(k)}),!h.size)return null;const N=k=>r.scale(k);let p=0;return l.jsx("g",{className:"dwlf-marker-series",children:Array.from(h.values()).map(({key:k,points:v},$)=>{const B=p;return p+=v.length,l.jsx(Jt,{points:v.map(R=>({date:R.t,actualTime:R.__rawTime??R.t,price:R.v,text:R.label,tooltip:R.tooltip||R.text,animationOrder:F.get(R)})),xScale:n,yScale:N,xBandwidth:c,shape:k.shape,size:k.size,color:k.color,offsetY:k.offsetY,fontSize:k.fontSize,textColor:k.textColor,textOffsetY:k.textOffsetY,animationPhase:o==null?void 0:o.phase,staggerDelay:100,staggerStartIndex:B},`${e.key}-marker-${$}`)})})},ei=(e,t,r,n,o)=>{var D,N,p,M,S,j,w;if(!Array.isArray(t)||t.length===0)return null;const u=Math.abs(r.scale(r.domain[0])-r.scale(r.domain[1]));if(!Number.isFinite(u)||u===0)return null;const c=t.flatMap(d=>{const E=[];return Number.isFinite(d.start)&&E.push({t:d.start}),Number.isFinite(d.end??NaN)&&E.push({t:d.end}),E}),f=Wr(c,n),i=((D=e.style)==null?void 0:D.riskColor)??"rgba(255, 107, 107, 0.25)",a=((N=e.style)==null?void 0:N.rewardColor)??"rgba(76, 175, 80, 0.25)",y=((p=e.style)==null?void 0:p.bubbleColor)??"rgba(0,0,0,0.85)",m=((M=e.style)==null?void 0:M.textColor)??"white",b=((S=e.style)==null?void 0:S.fontSize)??11,x=((j=e.style)==null?void 0:j.pointer)??!0,h=((w=e.style)==null?void 0:w.padding)??6,F=d=>r.scale(d);return l.jsx("g",{className:"dwlf-position-series",children:t.map((d,E)=>{if(!Number.isFinite(d==null?void 0:d.start)||!Number.isFinite(d==null?void 0:d.entry)||!Number.isFinite(d==null?void 0:d.stop)||!Number.isFinite(d==null?void 0:d.target))return null;const Y=Array.isArray(d.messages)?d.messages.filter(k=>Number.isFinite(k==null?void 0:k.t)&&Number.isFinite(k==null?void 0:k.v)&&(k==null?void 0:k.text)).map(k=>({date:k.t,actualTime:k.__rawTime??k.t,price:k.v,text:k.text})):void 0;return l.jsx(er,{startDate:d.start,endDate:Number.isFinite(d.end??NaN)?d.end:void 0,entryPrice:d.entry,stopPrice:d.stop,takePrice:d.target,xScale:n,yScale:F,xBandwidth:f,chartWidth:o,chartHeight:u,riskColor:d.riskColor??i,rewardColor:d.rewardColor??a,messages:Y,bubbleColor:d.bubbleColor??y,textColor:d.textColor??m,fontSize:d.fontSize??b,pointer:d.pointer??x,padding:d.padding??h},`${e.key}-position-${E}`)})})},ti=(e,t,r,n,o,u,c)=>{var S;const i=Ks(t,n,o)/2,a=((S=e.style)==null?void 0:S.color)??e.color??(u?"#22c55e":"#16a34a"),y=Le.color(a),b=y?y.darker(1.2).formatHex():u?"#ef4444":"#b91c1c",x=a;let h=t;(c==null?void 0:c.phase)==="background"||(c==null?void 0:c.phase)==="idle"?h=[]:(c==null?void 0:c.phase)==="candles"&&(h=t.slice(0,c.candleRevealIndex+1));const F=j=>{if(!c||c.phase!=="candles")return .9;const w=c.candleRevealIndex,d=10;if(j<=w-d)return .9;if(j>w)return 0;const E=(w-j)/d;return Math.max(0,Math.min(.9,E*.9))};let D="",N="",p="";const M=[];return h.forEach((j,w)=>{const d=n(j.t),E=r.scale(j.h),Y=r.scale(j.l),k=r.scale(j.o),v=r.scale(j.c),$=F(w);if($===0)return;const B=`M${d},${E}L${d},${Y}`,R=Math.min(k,v),I=Math.max(k,v),X=d-i,J=d+i,K=Math.max(1,I-R),U=`M${X},${R}H${J}V${R+K}H${X}Z`,_=j.c>=j.o;(c==null?void 0:c.phase)==="candles"&&$<.9?M.push(l.jsxs("g",{className:"dwlf-candle-individual",children:[l.jsx("path",{d:B,strokeWidth:1,stroke:u?"rgba(148, 163, 184, 0.6)":"rgba(100, 116, 139, 0.8)",fill:"none",opacity:$}),l.jsx("path",{d:U,fill:_?x:b,stroke:"none",opacity:$})]},`candle-${w}`)):(D+=B,_?N+=U:p+=U)}),l.jsxs("g",{className:"dwlf-candles",children:[D&&l.jsx("path",{d:D,strokeWidth:1,stroke:u?"rgba(148, 163, 184, 0.6)":"rgba(100, 116, 139, 0.8)",fill:"none"}),N&&l.jsx("path",{d:N,fill:x,stroke:"none",opacity:.9}),p&&l.jsx("path",{d:p,fill:b,stroke:"none",opacity:.9}),M]})},ri=(e,t,r,n)=>{const o=n,u=t-o,c=r+o,f=i=>{if(!Number.isFinite(i??NaN))return!1;const a=i;return a>=u&&a<=c};if(!Array.isArray(e.data))return[];if(e.type==="ohlc")return e.data.filter(i=>f(i==null?void 0:i.t));if(e.type==="line"||!e.type){if(e.data.length===2){const i=e.data[0],a=e.data[1];if(Number.isFinite((i==null?void 0:i.t)??NaN)&&Number.isFinite((a==null?void 0:a.t)??NaN)){const m=Number(i==null?void 0:i.t),b=Number(a==null?void 0:a.t),x=Math.min(m,b),F=Math.max(m,b)>=u&&x<=c;if(f(m)||f(b)||F)return e.data}}return e.data.filter(i=>f(i==null?void 0:i.t))}return e.type==="hist"||e.type==="area"?e.data.filter(i=>f(i==null?void 0:i.t)):e.type==="marker"?e.data.filter(i=>f(i==null?void 0:i.t)):e.type==="position"?e.data.filter(i=>{const a=Number.isFinite(i==null?void 0:i.start)?Number(i.start):Number(i==null?void 0:i.t)||0;return((Number.isFinite(i==null?void 0:i.end)?Number(i.end):void 0)??a)>=u&&a<=c}):e.data},si=(e,t,r,n,o,u)=>!Array.isArray(e.data)||e.data.length===0||(u==null?void 0:u.phase)==="loading"?null:e.type==="ohlc"&&Fr(e.data)?ti(e,e.data,t,r,n,o,u):e.type==="marker"?Qs(e,e.data,t,r,u):e.type==="position"?ei(e,e.data,t,r,n):Mr(e.data)?Js(e,e.data,t,r,u):null,Lt=(e,t)=>{var o,u,c,f,i,a,y,m,b,x,h,F,D;if(!Array.isArray(e.data)||e.data.length===0)return{key:e.key,color:((o=e.style)==null?void 0:o.color)??e.color,value:null,display:"—",raw:null};if(e.type==="ohlc"&&Fr(e.data)){const N=Hs(e.data,t);if(!N)return{key:e.key,color:((u=e.style)==null?void 0:u.color)??e.color,value:null,display:"—",raw:null};const p=e.tooltipFormatter?e.tooltipFormatter(N):`O ${Ze(N.o)} H ${Ze(N.h)} L ${Ze(N.l)} C ${Ze(N.c)}`;return{key:e.key,color:((c=e.style)==null?void 0:c.color)??e.color,value:N.c??null,display:p,raw:N}}if(e.type==="marker"){const N=e.data.filter(d=>Number.isFinite(d==null?void 0:d.t)&&Number.isFinite(d==null?void 0:d.v));if(!N.length)return{key:e.key,color:((f=e.style)==null?void 0:f.color)??e.color,value:null,display:"—",raw:null};const p=N.map(d=>({t:d.t,v:d.v})),M=Kt(p,t);if(!M)return{key:e.key,color:((i=e.style)==null?void 0:i.color)??e.color,value:null,display:"—",raw:null};const S=N.find(d=>d.t===M.t&&d.v===M.v)??null,j=e.tooltipFormatter?e.tooltipFormatter(S??M):S!=null&&S.label?`${S.label} ${Ze(M.v)}`:Ze(M.v),w=(S==null?void 0:S.color)??((a=e.style)==null?void 0:a.color);return{key:e.key,color:w,value:M.v??null,display:j,raw:S??M}}if(e.type==="position"){const N=e.data.filter(j=>Number.isFinite(j==null?void 0:j.start)&&Number.isFinite(j==null?void 0:j.entry)&&Number.isFinite(j==null?void 0:j.stop)&&Number.isFinite(j==null?void 0:j.target));if(!N.length)return{key:e.key,color:((y=e.style)==null?void 0:y.color)??e.color,value:null,display:"—",raw:null};const p=N.reduce((j,w)=>{const d=Math.abs(w.start-t),E=Number.isFinite(w.end??NaN)?Math.abs(w.end-t):d,Y=Math.min(d,E);if(!j)return w;const k=Math.abs(j.start-t),v=Number.isFinite(j.end??NaN)?Math.abs(j.end-t):k,$=Math.min(k,v);return Y<$?w:j},null);if(!p)return{key:e.key,color:((m=e.style)==null?void 0:m.color)??e.color,value:null,display:"—",raw:null};const M=e.tooltipFormatter?e.tooltipFormatter(p):`Entry ${Ze(p.entry)} Stop ${Ze(p.stop)} Target ${Ze(p.target)}`,S=((b=e.style)==null?void 0:b.color)??((x=e.style)==null?void 0:x.riskColor)??"rgba(239, 68, 68, 0.8)";return{key:e.key,color:S,value:p.entry??null,display:M,raw:p}}if(Mr(e.data)){const N=Kt(e.data,t);if(!N)return{key:e.key,color:((h=e.style)==null?void 0:h.color)??e.color,value:null,display:"—",raw:null};const p=e.tooltipFormatter?e.tooltipFormatter(N):Ze(N.v);return{key:e.key,color:((F=e.style)==null?void 0:F.color)??e.color,value:N.v??null,display:p,raw:N}}const r=e.data.find(N=>N&&typeof N.t=="number"),n=e.tooltipFormatter?e.tooltipFormatter(r):"—";return{key:e.key,color:((D=e.style)==null?void 0:D.color)??e.color,value:null,display:n,raw:r}},ii=s.forwardRef(function({spec:t,darkMode:r=!0,showGrid:n=!0,className:o,style:u,enablePanZoom:c=!1,timeframe:f="daily",initialVisibleCount:i=160,extraRightSlots:a=30,compressGaps:y=!1,axisColors:m,crosshairSnapMode:b="series",showCrosshairPriceLabel:x=!0,annotations:h=[],selectedAnnotationId:F=null,onAnnotationSelect:D,onAnnotationMove:N,onAnnotationTextEdit:p,onAnnotationDoubleClick:M,onChartCanvasClick:S,onCanvasMouseMove:j,onChartCanvasHover:w,animationState:d},E){const[Y,k]=s.useState(()=>bt(t));s.useEffect(()=>{k(bt(t))},[t]);const[v,$]=s.useState(!0),[B,R]=s.useState(null),[I,{width:X,height:J}]=rr(),K=s.useRef(null),U=J||qs,A=(f||"").toLowerCase()==="hourly"?36e5:864e5,P=s.useMemo(()=>{for(const T of Y.panes){const ue=T.series.find(ye=>ye.type==="ohlc"&&Array.isArray(ye.data));if(ue)return ue}return null},[Y]),L=s.useMemo(()=>!P||!Array.isArray(P.data)?[]:P.data.filter(T=>Number.isFinite(T==null?void 0:T.t)),[P]),le=s.useMemo(()=>L.map(T=>({date:new Date(T.t).toISOString()})),[L]),g=tr(le,i,a,f),O=c&&L.length>0,ge=y&&L.length>0,{mouseHandlers:Z,chartElementRef:H,zoomIn:Q,zoomOut:ne,resetView:q,panToStart:se,panToEnd:re}=g,z=s.useCallback(T=>{if(!L.length)return Date.now()+T*A;if(T<=0)return L[Math.max(0,T)].t;if(T<L.length)return L[T].t;const ue=L[L.length-1].t,ye=T-(L.length-1);return ue+ye*A},[L,A]),C=s.useMemo(()=>{if(!O)return null;const T=g.viewportStart,ue=Math.max(g.viewportEnd,T+1),ye=z(T),fe=z(ue),de=fe<=ye?ye+A:fe;return{startTime:ye,endTime:de,viewportStart:g.viewportStart,viewportEnd:g.viewportEnd,visibleCount:g.visibleCount}},[O,g.viewportStart,g.viewportEnd,g.visibleCount,z,A]),V=s.useRef(!1),G=s.useRef(L.length);s.useEffect(()=>{if(!O){V.current=!1;return}if(L.length===0){V.current=!1;return}if(!V.current){q(),V.current=!0,G.current=L.length;return}L.length!==G.current&&(q(),G.current=L.length)},[O,L.length,q]),s.useEffect(()=>{O&&(V.current=!1)},[t,O]);const W=s.useMemo(()=>{if(!ge)return null;let T=[];if(O&&C){const fe=Math.max(0,C.viewportEnd-C.viewportStart);T=Array.from({length:fe},(de,me)=>z(C.viewportStart+me))}else T=zt(Y);const ue=Array.from(new Set(T.filter(fe=>Number.isFinite(fe)))).sort((fe,de)=>fe-de);if(!ue.length)return null;const ye=new Map;return ue.forEach((fe,de)=>ye.set(fe,de)),{rawToIndex:ye,indexToRaw:ue}},[ge,O,C,Y,z]),ee=s.useMemo(()=>{if(W)return T=>W.rawToIndex.get(T)},[W]),ie=s.useMemo(()=>{if(W)return T=>{const ue=W.indexToRaw.length-1,ye=Math.max(0,Math.min(ue,T));return W.indexToRaw[ye]}},[W]),te=s.useCallback(T=>{O&&H(T),I&&(I.current=T)},[O,H,I]),ce=s.useMemo(()=>{const T=de=>{if(!W||!Number.isFinite(de))return de;const{rawToIndex:me,indexToRaw:ae}=W,he=me.get(de);if(he!==void 0)return he;const Ne=ae.length;if(Ne>0&&Number.isInteger(de)&&de>=0&&de<=Ne-1||!Ne)return de;const ke=nt(ae,de);return me.get(ke)??de},ue=de=>!W||!de?de:de.map(me=>{let ae=me;if(Number.isFinite(me.startTime??NaN)){const he=T(me.startTime);he!==me.startTime&&(ae={...ae,startTime:he})}if(Number.isFinite(me.endTime??NaN)){const he=T(me.endTime);he!==me.endTime&&(ae=ae===me?{...ae}:ae,ae.endTime=he)}return ae}),ye=(de,me)=>!W||!Array.isArray(me)?me:de.type==="position"?me.map(ae=>{if(!ae)return ae;const he={...ae},Ne=ae.__rawStart??ae.start;if(Number.isFinite(Ne)){const ke=W.rawToIndex.get(Ne);ke!==void 0&&(he.__rawStart=Ne,he.start=ke)}if(Number.isFinite(ae.end??NaN)){const ke=ae.__rawEnd??ae.end;if(Number.isFinite(ke)){const Oe=W.rawToIndex.get(ke);Oe!==void 0&&(he.__rawEnd=ke,he.end=Oe)}}return Array.isArray(ae.messages)&&(he.messages=ae.messages.map(ke=>{if(!Number.isFinite((ke==null?void 0:ke.t)??NaN))return ke;const Oe=ke.__rawTime??ke.t,Ee=W.rawToIndex.get(Oe);return Ee===void 0||ke.t===Ee&&ke.__rawTime?ke:{...ke,__rawTime:Oe,t:Ee}})),he}):me.map(ae=>{if(!ae||typeof ae.t!="number")return ae;const he=ae.__rawTime??ae.t,Ne=W.rawToIndex.get(he);return Ne===void 0||ae.t===Ne&&ae.__rawTime?ae:{...ae,__rawTime:he,t:Ne}});if(!O||!C){if(!W)return Y;const de=bt(Y);return de.panes=de.panes.map(me=>({...me,series:me.series.map(ae=>({...ae,data:Array.isArray(ae.data)?ye(ae,ae.data):ae.data})),guides:ue(me.guides)})),de}const fe=bt(Y);return fe.panes=fe.panes.map(de=>{const me=de.series.map(ae=>{const he=ri(ae,C.startTime,C.endTime,A);return Array.isArray(he)?{...ae,data:ye(ae,he)}:{...ae,data:he}});return{...de,series:me,guides:ue(de.guides)}}),fe},[Y,O,C,A,z,W]),{rects:De,heights:Ce}=s.useMemo(()=>Zs(ce,U),[ce,U]),je=s.useMemo(()=>{const T=new Map;return De.forEach(ue=>{T.set(ue.pane.id,ue)}),T},[De]),pe=s.useMemo(()=>Br(ce,Ce),[ce,Ce]),be=s.useMemo(()=>{if(W)return W.indexToRaw.map((ue,ye)=>ye);if(!O||!C)return zt(ce);const T=[];for(let ue=C.viewportStart;ue<C.viewportEnd;ue+=1)T.push(z(ue));return T.length?T:[C.startTime,C.endTime]},[W,O,C,ce,z]),we=s.useMemo(()=>{const T=Math.max(0,X);if(!be.length||T<=0){const fe=Date.now();return Le.scaleUtc().domain([fe-36e5,fe]).range([0,T||1])}if(W){const fe=W.indexToRaw.length,de=fe>1?fe-1:1;return Le.scaleLinear().domain([0,de]).range([0,T])}let ue=be[0],ye=be[be.length-1];return O&&C&&(ue=C.startTime,ye=C.endTime),ue===ye&&(ye=ue+A),Le.scaleUtc().domain([ue,ye]).range([0,T])},[be,X,O,C,A,W]),Me=s.useMemo(()=>{if(!be.length||X<=0)return[];const T=Math.min(12,Math.max(2,Math.floor(X/140)));if(W){const ue=W.indexToRaw.length;if(!ue)return[];const fe=Le.scaleLinear().domain([0,Math.max(1,ue-1)]).ticks(T);return Array.from(new Set(fe.map(me=>{const ae=Math.round(me);return Math.max(0,Math.min(ue-1,ae))}))).sort((me,ae)=>me-ae)}return we.ticks(T).map(ue=>ue instanceof Date?ue.valueOf():Number(ue))},[we,be,X,W]),xe=s.useCallback(T=>{if(W){if(!W.indexToRaw.length)return T;const ue=Math.max(0,Math.min(W.indexToRaw.length-1,Math.round(T)));return W.indexToRaw[ue]}return T},[W]),Pe=v?B:null,Ge=s.useCallback(T=>{var Ee;if(!v||!K.current)return;const ue=K.current.getBoundingClientRect(),ye=T.clientX-ue.left,fe=Math.max(0,Math.min(ye,Math.max(0,X))),de=we.invert(fe),me=de instanceof Date?de.valueOf():de;if(!Number.isFinite(me)){R(null);return}const ae=nt(be,me);if(!Number.isFinite(ae)){R(null);return}const he=T.clientY-ue.top;let Ne=null;if(b==="pointer")for(const We of je.values()){const ve=We.y+We.height;if(he>=We.y&&he<=ve){Ne=We.pane.id;break}}const ke={};ce.panes.forEach(We=>{const ve=pe[We.id];if(!ve)return;const Ye=We.series.filter(Je=>Je.showInTooltip!==!1).map(Je=>Lt(Je,ae)),it=Ye.find(Je=>Number.isFinite(Je.value??NaN)),Ke=je.get(We.id),xt=b==="pointer"?We.id===Ne:!0;let et=null;if(b==="pointer"&&Ke&&xt){const Je=he-Ke.y,ct=Math.max(0,Math.min(Je,Ke.height));et=Number.isFinite(ct)?ct:0}else it?et=ve.scale(it.value):et=ve.scale(ve.domain[0]);ke[We.id]={y:et,series:Ye,lineVisible:b==="pointer"?xt&&Ke!=null:!0}});const Oe=xe(ae);if(R({time:Oe,x:we(ae),perPane:ke}),(Ee=ce.onCrosshairMove)==null||Ee.call(ce,Oe),j||w)for(const[We,ve]of je.entries()){const $e=ve.y+ve.height;if(he>=ve.y&&he<=$e){const Ye=pe[We];if(Ye){const it=he-ve.y,Ke=Ye.invert(it);Number.isFinite(Ke)&&(j==null||j({time:Oe,price:Ke,paneId:We,screenX:T.clientX,screenY:T.clientY}),w==null||w({time:Oe,price:Ke}))}break}}},[v,K,X,we,be,ce,pe,xe,je,b,j,w]),Re=s.useCallback(()=>{R(null)},[]),ze=s.useCallback(T=>{var fe,de;if(!v||!K.current)return;let ue,ye;if(B)ue=B.time,ye=B.perPane;else{const me=K.current.getBoundingClientRect(),ae=T.clientX-me.left,he=Math.max(0,Math.min(ae,Math.max(0,X))),Ne=we.invert(he),ke=Ne instanceof Date?Ne.valueOf():Ne;if(!Number.isFinite(ke))return;const Oe=nt(be,ke);if(!Number.isFinite(Oe))return;const Ee=T.clientY-me.top;let We=null;if(b==="pointer")for(const $e of je.values()){const Ye=$e.y+$e.height;if(Ee>=$e.y&&Ee<=Ye){We=$e.pane.id;break}}ye={},ce.panes.forEach($e=>{const Ye=pe[$e.id];if(!Ye)return;const Ke=$e.series.filter(lt=>lt.showInTooltip!==!1).map(lt=>Lt(lt,Oe)),xt=Ke.find(lt=>Number.isFinite(lt.value??NaN)),et=je.get($e.id),Je=b==="pointer"?$e.id===We:!0;let ct=null;if(b==="pointer"&&et&&Je){const lt=Ee-et.y,_t=Math.max(0,Math.min(lt,et.height));ct=Number.isFinite(_t)?_t:0}else xt?ct=Ye.scale(xt.value):ct=Ye.scale(Ye.domain[0]);ye[$e.id]={y:ct,series:Ke,lineVisible:b==="pointer"?Je&&et!=null:!0}}),ue=xe(Oe)}if(S){const me=K.current.getBoundingClientRect(),ae=T.clientY-me.top;for(const[he,Ne]of je.entries()){const ke=Ne.y+Ne.height;if(ae>=Ne.y&&ae<=ke){const Oe=pe[he];if(Oe){const Ee=ae-Ne.y,We=Oe.invert(Ee);Number.isFinite(We)&&S({time:ue,price:We,paneId:he,screenX:T.clientX,screenY:T.clientY})}break}}}for(const me of ce.panes){const ae=ye[me.id],he=(ae==null?void 0:ae.series)??[],Ne=new Map;he.forEach(ve=>{ve&&ve.key&&Ne.set(ve.key,ve)});const ke=me.series.map(ve=>{const $e=Ne.get(ve.key);if($e)return $e;const Ye=Lt(ve,ue);return Ne.set(ve.key,Ye),Ye});let Oe=null,Ee=null;for(const ve of ke){if(!ve||ve.raw==null)continue;const $e=me.series.find(Ye=>Ye.key===ve.key);if($e&&typeof $e.onClick=="function"){Oe=ve,Ee=$e;break}}if(!Oe){const ve=ke.find($e=>$e&&$e.raw!=null);if(!ve)continue;Oe=ve,Ee=me.series.find($e=>$e.key===ve.key)??null}if(!Oe)continue;const We=Oe.raw;if(!Ee){(fe=ce.onSeriesPointClick)==null||fe.call(ce,{paneId:me.id,seriesKey:Oe.key,time:ue,raw:We});return}if(typeof Ee.onClick=="function")try{Ee.onClick(We)}catch(ve){console.error("DWLFChart: series onClick handler threw",ve)}(de=ce.onSeriesPointClick)==null||de.call(ce,{paneId:me.id,seriesKey:Ee.key,time:ue,raw:We});return}},[v,K,B,ce,X,we,be,pe,je,b,xe,S]),Ve=s.useCallback(T=>{k(bt(T))},[]),Ie=s.useCallback(T=>{k(ue=>({...ue,panes:[...ue.panes,Or(T)]}))},[]),qe=s.useCallback(T=>{k(ue=>({...ue,panes:ue.panes.filter(ye=>ye.id!==T)}))},[]),st=s.useCallback((T,ue)=>{k(ye=>({...ye,panes:ye.panes.map(fe=>{if(fe.id!==T)return fe;const de={...fe,...ue};return ue.series&&(de.series=ue.series.map(Nt)),ue.guides&&(de.guides=ue.guides.map(me=>({...me}))),de})}))},[]),rt=s.useCallback((T,ue)=>{k(ye=>({...ye,panes:ye.panes.map(fe=>{if(fe.id!==T)return fe;const de=fe.series.some(me=>me.key===ue.key)?fe.series.map(me=>me.key===ue.key?Nt(ue):me):[...fe.series,Nt(ue)];return{...fe,series:de}})}))},[]),ut=s.useCallback((T,ue,ye)=>{k(fe=>({...fe,panes:fe.panes.map(de=>{if(de.id!==T)return de;const me=de.series.map(ae=>ae.key===ue?{...ae,data:Array.isArray(ye)?[...ye]:[]}:ae);return{...de,series:me}})}))},[]),pt=s.useCallback((T,ue)=>{k(ye=>({...ye,panes:ye.panes.map(fe=>fe.id===T?{...fe,series:fe.series.filter(de=>de.key!==ue)}:fe)}))},[]),ht=s.useCallback((T,ue)=>{k(ye=>({...ye,panes:ye.panes.map(fe=>fe.id===T?{...fe,guides:[...fe.guides??[],{...ue}]}:fe)}))},[]),Mt=s.useCallback((T,ue)=>{k(ye=>({...ye,panes:ye.panes.map(fe=>fe.id===T?{...fe,guides:(fe.guides??[]).filter(de=>de.y!==ue)}:fe)}))},[]),mt=s.useCallback(T=>{$(!!T),T||R(null)},[]),Ft=s.useCallback(()=>{O&&Q()},[O,Q]),wt=s.useCallback(()=>{O&&ne()},[O,ne]),kt=s.useCallback(()=>{O&&q()},[O,q]),ot=s.useCallback(()=>{O&&se()},[O,se]),yt=s.useCallback(()=>{O&&re()},[O,re]),gt=s.useCallback(T=>{!O||!Z.onMouseDown||Z.onMouseDown(T)},[O,Z]),Dt=s.useCallback(T=>{!O||!Z.onMouseMove||Z.onMouseMove(T)},[O,Z]),Pr=s.useCallback(T=>{!O||!Z.onMouseUp||Z.onMouseUp(T)},[O,Z]),Er=s.useCallback(T=>{!O||!Z.onMouseLeave||Z.onMouseLeave(T)},[O,Z]);s.useImperativeHandle(E,()=>({setSpec:Ve,addPane:Ie,removePane:qe,updatePane:st,addSeries:rt,updateSeries:ut,removeSeries:pt,addGuide:ht,removeGuide:Mt,enableSharedCrosshair:mt,zoomIn:Ft,zoomOut:wt,resetView:kt,panToStart:ot,panToEnd:yt}),[Ve,Ie,qe,st,rt,ut,pt,ht,Mt,mt,Ft,wt,kt,ot,yt]);const Ot=r?"#0f172a":"#ffffff",jt=r?"rgba(148, 163, 184, 0.12)":"rgba(15, 23, 42, 0.08)",Wt=s.useMemo(()=>r?(m==null?void 0:m.dark)??"#94a3b8":(m==null?void 0:m.light)??"#475569",[m,r]),Pt=s.useMemo(()=>(r?m==null?void 0:m.dark:m==null?void 0:m.light)??(r?"#f1f5f9":"#0f172a"),[m,r]),Ct=r?"#e2e8f0":"#1f2937",Vt=r?"rgba(15, 23, 42, 0.9)":"rgba(255,255,255,0.95)",$r=["dwlf-chart-container",o,d?"fade-transition":"",(d==null?void 0:d.phase)||""].filter(Boolean).join(" ");return l.jsxs("div",{ref:te,className:$r,style:{position:"relative",width:"100%",height:"100%",background:Ot,...u??{}},children:[l.jsxs("svg",{ref:K,width:X,height:U,className:"dwlf-chart-svg",onClick:ze,onMouseDown:gt,onMouseMove:T=>{O&&Dt(T),Ge(T)},onMouseUp:Pr,onMouseLeave:T=>{O&&Er(T),Re()},children:[l.jsx("rect",{x:0,y:0,width:X,height:U,fill:Ot}),De.map(({pane:T,y:ue,height:ye})=>{var ae;const fe=pe[T.id];if(!fe)return null;const de=Le.scaleLinear().domain(fe.domain).ticks(4),me=Pe==null?void 0:Pe.perPane[T.id];return l.jsxs("g",{transform:`translate(0, ${ue})`,children:[l.jsx("rect",{x:0,y:0,width:X,height:ye,fill:Ot}),n&&Me.map((he,Ne)=>l.jsx("line",{x1:we(he),x2:we(he),y1:0,y2:ye,stroke:jt,strokeWidth:1},`x-grid-${he}-${Ne}`)),n&&de.map((he,Ne)=>{const ke=fe.scale(he);return Number.isFinite(ke)?l.jsx("line",{x1:0,x2:X,y1:ke,y2:ke,stroke:jt,strokeWidth:1},`y-grid-${he}-${Ne}`):null}),(ae=T.guides)==null?void 0:ae.map((he,Ne)=>{const ke=fe.scale(he.y);let Oe=0,Ee=X;if(he.startTime!==void 0&&Number.isFinite(he.startTime)){const We=we(he.startTime);Number.isFinite(We)&&(Oe=Math.max(0,We))}if(he.endTime!==void 0&&Number.isFinite(he.endTime)){const We=we(he.endTime);Number.isFinite(We)&&(Ee=Math.min(X,We))}return Oe>=X||Ee<=0||Oe>=Ee?null:l.jsxs("g",{children:[l.jsx("line",{x1:Oe,x2:Ee,y1:ke,y2:ke,stroke:he.color??jt,strokeDasharray:he.dashed?"4 4":void 0}),he.label&&l.jsx("text",{x:Oe+12,y:ke-4,fill:Wt,fontSize:11,children:he.label})]},`${he.y}-${Ne}`)}),T.series.map(he=>l.jsx(s.Fragment,{children:si(he,fe,we,X,r,d)},he.key)),T.id==="price"&&h.length>0&&l.jsx(vr,{annotations:h,xScale:we,yScale:fe,chartWidth:X,paneHeight:ye,darkMode:r,selectedAnnotationId:F,onAnnotationSelect:D,onAnnotationMove:N,onAnnotationTextEdit:p,onAnnotationDoubleClick:M,timeToIndex:ee,indexToTime:ie,dataLength:(W==null?void 0:W.indexToRaw.length)??be.length,compressedTimes:W==null?void 0:W.indexToRaw,currentTimeframe:f,animationPhase:d==null?void 0:d.phase}),Pe&&me&&x&&me.lineVisible!==!1&&Number.isFinite(me.y??NaN)&&(()=>{const Ee=Math.max(0,X-72-4),We=me.y,ve=Math.max(11,Math.min(ye-9-2,We)),$e=ve-9,Ye=fe.invert(ve);if(!Number.isFinite(Ye))return null;const it=Ze(Ye);return l.jsxs("g",{className:"dwlf-crosshair-price-label",children:[l.jsx("rect",{x:Ee,y:$e,width:72,height:18,rx:4,ry:4,fill:Vt,stroke:Pt,strokeWidth:1}),l.jsx("text",{x:Ee+72/2,y:ve,fill:Ct,fontSize:11,textAnchor:"middle",alignmentBaseline:"middle",children:it})]})})(),me&&me.lineVisible!==!1&&Number.isFinite(me.y??NaN)&&l.jsx("line",{x1:0,x2:X,y1:me.y,y2:me.y,stroke:Pt,strokeWidth:1.5,strokeDasharray:"3 3"}),l.jsx("g",{className:"dwlf-y-axis",transform:`translate(${X-40}, 0)`,children:de.map((he,Ne)=>l.jsx("text",{x:0,y:fe.scale(he),fill:Wt,fontSize:11,alignmentBaseline:"middle",children:Ze(he)},`${he}-${Ne}`))}),T.title&&l.jsx("text",{x:12,y:14,fill:Ct,fontSize:12,fontWeight:600,children:T.title})]},T.id)}),Pe&&l.jsx("g",{className:"dwlf-crosshair",children:l.jsx("line",{x1:Pe.x,x2:Pe.x,y1:0,y2:U,stroke:Pt,strokeWidth:1.5,strokeDasharray:"3 3"})}),l.jsx("g",{className:"dwlf-x-axis",children:Me.map(T=>l.jsx("text",{x:we(T),y:U-6,fill:Wt,fontSize:10,textAnchor:"middle",children:Ht(xe(T),ce.timeFormatter)},`tick-${T}`))})]}),Pe&&De.map(({pane:T,y:ue,height:ye})=>{const fe=Pe.perPane[T.id];return fe?l.jsxs("div",{className:"dwlf-pane-tooltip",style:{top:ue,left:0,color:Ct,borderColor:jt,backgroundColor:Vt,width:"100%"},children:[l.jsxs("div",{className:"dwlf-pane-tooltip__title",children:[T.title??"Pane"," · ",Ht(Pe.time,ce.timeFormatter)]}),l.jsx("div",{className:"dwlf-pane-tooltip__content",children:fe.series.map(de=>l.jsxs("div",{className:"dwlf-pane-tooltip__row",children:[l.jsx("span",{style:{color:de.color??Ct},children:de.key}),l.jsx("span",{children:de.display})]},de.key))})]},`tooltip-${T.id}`):null})]})}),ci={},li=(e,t,r)=>Math.max(t,Math.min(r,e));function ni(e,t,r,n="daily",o=!1){const u=e.filter(d=>!d._virtual),c=e.map(d=>new Date(d.date));u.map(d=>new Date(d.date));const f=c.filter(d=>isNaN(d.getTime()));f.length>0&&(typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:Et&&Et.tagName.toUpperCase()==="SCRIPT"&&Et.src||new URL("index.cjs",document.baseURI).href}>"u"||!ci)&&console.error("Found invalid dates in useCandlestickChart:",f);const i=new Map;for(let d=0;d<u.length;d++){const E=new Date(u[d].date).getTime();i.set(E,d)}const a=Le.extent(c),y=Math.max(0,((e==null?void 0:e.length)||0)-u.length),m=Math.max(0,u.length-1+y),b=Le.scaleLinear().domain([0,m]).range([0,t]),x=Le.scaleTime().domain(a).range([0,t]),h=(function(){if(!o)return x;const E=u.map(v=>new Date(v.date).getTime()),Y=Le.bisector(v=>v).left,k=v=>{if(v instanceof Date){const $=v.getTime();let B;return i.has($)?B=i.get($):(B=Y(E,$),B=Math.max(0,Math.min(u.length-1,B))),b(B)}return b(v)};return k.invert=v=>b.invert(v),k})(),F=Le.min(u,d=>d.low),D=Le.max(u,d=>d.high),p=(D-F||1)*.2,M=Le.scaleLinear().domain([F-p,D+p]).range([r,0]),S=(n||"").toLowerCase();let j;if(u.length>1){let d=1/0,E=null;for(let B=0;B<u.length;B++){const R=u[B],I=h(new Date(R.date));if(E!==null){const X=I-E;X>0&&(d=Math.min(d,X))}E=I}(!isFinite(d)||d<=0)&&(d=t/Math.max(1,u.length-1));const k=d*(S==="hourly"?.75:.8),[v,$]=S==="hourly"?[.5,12]:[2,18];j=li(k,v,$)}else j=S==="hourly"?Math.max(1,t*.006):Math.max(6,t*.012);return{xScale:h,yScale:M,getCandleProps:d=>{const E=M(d.open),Y=M(d.close);let k;if(o){const v=new Date(d.date).getTime(),$=i.has(v)?i.get(v):0;k=b($)}else k=x(new Date(d.date));return{x:k,y:Math.min(E,Y),height:Math.abs(E-Y),width:j,color:d.close>=d.open?"green":"red"}},xBandwidth:j,_compressed:o,_indexToDate:u.map(d=>new Date(d.date))}}function ui({width:e,height:t,margin:r}){const n=e,o=t,u=n-r.left-r.right,c=o-r.top-r.bottom;return{margin:r,fullWidth:n,fullHeight:o,innerWidth:u,innerHeight:c,chartTransform:`translate(${r.left}, ${r.top})`}}function oi(e,t=50){const[r,n]=s.useState(Math.max(0,e.length-t)),[o,u]=s.useState(e.length),[c,f]=s.useState(!1),[i,a]=s.useState(0),[y,m]=s.useState(0),b=s.useRef(),x=e.slice(r,o),h=o-r,F=s.useCallback(k=>{f(!0),a(k.clientX),k.preventDefault()},[]),D=s.useCallback(k=>{if(!c)return;const v=k.clientX-i,$=b.current;if(!$)return;const B=$.getBoundingClientRect(),R={left:50,right:20},I=B.width-R.left-R.right,X=I/h,J=I-X,K=A=>Math.max(-J,Math.min(0,A));let U=v;const _=o>=e.length;if(y!==0&&Math.sign(v)!==Math.sign(y)){const A=y+v,P=K(A),L=P-y;m(P),U=v-L}if(_&&U<0){const A=y+U,P=K(A),L=P-y;m(P),U-=L}if(U!==0){const A=Math.round(U/(X*1.5));if(A!==0){const P=Math.max(0,r-A),L=Math.min(e.length,P+h),le=Math.max(0,L-h);n(le),u(L),m(0)}}o<e.length&&y!==0&&m(0),a(k.clientX)},[c,i,r,h,y,e.length]),N=s.useCallback(()=>{f(!1)},[]),p=s.useCallback(k=>{k.preventDefault();const v=Math.abs(k.deltaX)>Math.abs(k.deltaY),$=k.currentTarget.getBoundingClientRect(),B={left:50,right:20},R=$.width-B.left-B.right;if(v){const se=R/h,re=Math.round(k.deltaX/(se*1.5));if(re!==0){const z=Math.max(0,r-re),C=Math.min(e.length,z+h),V=Math.max(0,C-h);n(V),u(C),m(0)}return}const X=(k.clientX-$.left-B.left-y)/R,J=r+X*h,K=o-r,_=1+k.deltaY*.002,A=_<=0?.1:_;let P=Math.round(K*A);if(P=Math.max(5,Math.min(e.length,P)),P===K)return;let g=Math.max(0,Math.min(e.length-1,J))-P*X;g=Math.max(0,Math.min(e.length-P,g));const O=g+P;n(Math.floor(g)),u(Math.floor(O));const ge=R/K,Z=R/P;let H=y*(Z/ge);const Q=Z*.7,ne=R-Q,q=Math.max(-ne,Math.min(0,H));q!==y&&m(q)},[r,o,h,e.length,y]),M=s.useCallback(k=>{b.current&&b.current.removeEventListener("wheel",p),b.current=k,k&&k.addEventListener("wheel",p,{passive:!1})},[p]),S={onMouseDown:F,onMouseMove:D,onMouseUp:N,onMouseLeave:N},j=s.useCallback(()=>{const k=o-r,v=(r+o)/2,$=Math.max(10,k*.8),B=Math.max(0,v-$/2),R=Math.min(e.length,B+$);n(Math.floor(B)),u(Math.floor(R))},[r,o,e.length]),w=s.useCallback(()=>{const k=o-r,v=(r+o)/2,$=Math.min(e.length,k*1.25),B=Math.max(0,v-$/2),R=Math.min(e.length,B+$);n(Math.floor(B)),u(Math.floor(R))},[r,o,e.length]),d=s.useCallback(()=>{n(Math.max(0,e.length-t)),u(e.length),m(0)},[e.length,t]),E=s.useCallback(()=>{n(0),u(Math.min(e.length,h))},[e.length,h]),Y=s.useCallback(()=>{n(Math.max(0,e.length-h)),u(e.length)},[e.length,h]);return{visibleData:x,viewportStart:r,viewportEnd:o,visibleCount:h,mouseHandlers:S,chartElementRef:M,zoomIn:j,zoomOut:w,resetView:d,panToStart:E,panToEnd:Y,isPanning:c,pixelOffset:y}}function ai(e,t={}){const r=s.useMemo(()=>fi.reduce((a,y)=>(a[y.id]=y,a),{}),[]),[n,o]=s.useState(new Set),u=s.useCallback(a=>{o(y=>{const m=new Set(y);return m.has(a)?m.delete(a):m.add(a),m})},[]),c=s.useMemo(()=>Array.from(n).map(a=>{const y=r[a];return y==null?void 0:y.generator(e,t)}).filter(Boolean),[n,r,e,t]),f=s.useCallback(a=>n.has(a),[n]);return{overlayDefinitions:r,activeKeys:n,overlays:c,toggleOverlay:u,toggleOverlayById:a=>{u(a)},isOverlayActive:f}}const fi=[{id:"sma20",label:"SMA 20",generator:(e,t)=>({type:"line",label:"sma20",data:t.sma20||[],color:"orange"})},{id:"sma50",label:"SMA 50",generator:(e,t)=>({type:"line",label:"sma50",data:t.sma50||[],color:"blue"})}],vt=["ema-10","ema-20","sma-10","sma-20","bollinger-upper","bollinger-middle","bollinger-lower","ema-50","sma-50","ema-200","sma-200"],Yt=vt.reduce((e,t)=>(e[t]=1,e),{});function di(e={}){const{totalCandles:t=0,animationSpeed:r=1,autoStart:n=!1,staggerDelay:o=100,onPhaseChange:u,onAnimationComplete:c}=e,f=Math.max(.1,Math.min(5,r)),i=s.useRef(u),a=s.useRef(c),y=s.useRef(f),m=s.useRef(!1),b=s.useRef("idle");s.useEffect(()=>{i.current=u},[u]),s.useEffect(()=>{a.current=c},[c]),s.useEffect(()=>{y.current=f},[f]);const[x,h]=s.useState({phase:n?"background":"idle",candleRevealIndex:0,layerOpacities:{},staggerDelay:o,isReducedMotion:!1});s.useEffect(()=>{b.current=x.phase},[x.phase]),s.useEffect(()=>{h(j=>({...j,staggerDelay:o}))},[o]);const F=s.useRef(!1);s.useEffect(()=>{const j=window.matchMedia("(prefers-reduced-motion: reduce)");m.current=j.matches,h(d=>({...d,isReducedMotion:j.matches}));const w=d=>{m.current=d.matches,h(E=>({...E,isReducedMotion:d.matches}))};return j.addEventListener("change",w),()=>j.removeEventListener("change",w)},[]),s.useEffect(()=>{var j,w;x.isReducedMotion&&x.phase!=="idle"&&x.phase!=="complete"&&(F.current=!1,b.current="complete",h(d=>({...d,phase:"complete",candleRevealIndex:Math.max(0,t-1),layerOpacities:{...Yt}})),(j=i.current)==null||j.call(i,"complete"),(w=a.current)==null||w.call(a))},[x.isReducedMotion,x.phase,t]),s.useEffect(()=>{if(x.phase!=="background")return;const j=setTimeout(()=>{var w;h(d=>({...d,phase:"candles"})),(w=i.current)==null||w.call(i,"candles")},o/y.current);return()=>clearTimeout(j)},[x.phase,o]),s.useEffect(()=>{var k;if(x.phase!=="candles")return;if(t===0){h(v=>({...v,phase:"indicators"})),(k=i.current)==null||k.call(i,"indicators");return}let j=null,w;const E=Math.max(30,t/2),Y=v=>{var R;j===null&&(j=v);const $=(v-j)/1e3,B=Math.min(Math.floor($*E*y.current),t-1);if(h(I=>({...I,candleRevealIndex:B})),B>=t-1){h(I=>({...I,phase:"indicators"})),(R=i.current)==null||R.call(i,"indicators");return}w=requestAnimationFrame(Y)};return w=requestAnimationFrame(Y),()=>cancelAnimationFrame(w)},[x.phase,t]),s.useEffect(()=>{if(x.phase!=="indicators")return;const j=80,w=[];vt.forEach((Y,k)=>{const v=setTimeout(()=>{h($=>({...$,layerOpacities:{...$.layerOpacities,[Y]:1}}))},k*j/y.current);w.push(v)});const d=(vt.length*j+100)/y.current,E=setTimeout(()=>{var Y;h(k=>({...k,phase:"events"})),(Y=i.current)==null||Y.call(i,"events")},d);return w.push(E),()=>w.forEach(Y=>clearTimeout(Y))},[x.phase]),s.useEffect(()=>{if(x.phase!=="events")return;const j=setTimeout(()=>{var w;h(d=>({...d,phase:"annotations"})),(w=i.current)==null||w.call(i,"annotations")},400/y.current);return()=>clearTimeout(j)},[x.phase]),s.useEffect(()=>{if(x.phase!=="annotations")return;const j=setTimeout(()=>{var w,d;h(E=>({...E,phase:"complete"})),(w=i.current)==null||w.call(i,"complete"),(d=a.current)==null||d.call(a)},200/y.current);return()=>clearTimeout(j)},[x.phase]);const D=s.useCallback(()=>{var d,E;const j=b.current,w=j!=="complete"&&j!=="idle";F.current=!1,b.current="complete",h(Y=>({...Y,phase:"complete",candleRevealIndex:Math.max(0,t-1),layerOpacities:{...Yt}})),w&&((d=i.current)==null||d.call(i,"complete"),(E=a.current)==null||E.call(a))},[t]),N=s.useCallback(()=>{var j,w,d;if(m.current){F.current=!1,h(E=>({...E,phase:"complete",candleRevealIndex:Math.max(0,t-1),layerOpacities:{...Yt}})),(j=i.current)==null||j.call(i,"complete"),(w=a.current)==null||w.call(a);return}F.current=!0,h(E=>({...E,phase:"background",candleRevealIndex:0,layerOpacities:{}})),(d=i.current)==null||d.call(i,"background")},[t]),p=s.useCallback(()=>{var j;F.current=!1,h(w=>({...w,phase:"idle",candleRevealIndex:0,layerOpacities:{}})),(j=i.current)==null||j.call(i,"idle")},[]),M=s.useCallback(j=>{y.current=Math.max(.1,Math.min(5,j))},[]),S=s.useMemo(()=>({startAnimation:N,skipToEnd:D,resetAnimation:p,setAnimationSpeed:M}),[N,D,p,M]);return s.useEffect(()=>{n&&t>0&&x.phase==="idle"&&!F.current&&N()},[n,t,x.phase,N]),{animationState:x,controls:S}}function hi(e,t){if(!Array.isArray(e)||e.length<t)return[];const r=[];for(let n=t-1;n<e.length;n++){const c=e.slice(n-t+1,n+1).reduce((f,i)=>f+i.close,0)/t;r.push({x:e[n].date,y:c})}return r}function mi(e,t){if(!Array.isArray(e)||e.length<t)return[];const r=[],n=2/(t+1);let o=e.slice(0,t).reduce((u,c)=>u+c.close,0)/t;r.push({x:e[t-1].date,y:o});for(let u=t;u<e.length;u++)o=e[u].close*n+o*(1-n),r.push({x:e[u].date,y:o});return r}exports.ANNOTATION_COLORS=Us;exports.AlertLineAnnotationView=wr;exports.AnnotationLayer=vr;exports.ArrowAnnotationView=hr;exports.BosLineAnnotationView=Nr;exports.BrushAnnotationView=kr;exports.ChannelAnnotationView=mr;exports.CrossLineAnnotationView=or;exports.DWLFChart=ii;exports.EmojiAnnotationView=fr;exports.FIB_EXTENSIONS_DEFAULT=gr;exports.FIB_LEVELS_DEFAULT=yr;exports.FairValueGapAnnotationView=Rr;exports.FibExtensionAnnotationView=jr;exports.FibRetracementAnnotationView=br;exports.HLineAnnotationView=cr;exports.INDICATOR_ANIMATION_ORDER=vt;exports.MeasureAnnotationView=pr;exports.OrderBlockAnnotationView=Cr;exports.PitchforkAnnotationView=Dr;exports.RayAnnotationView=ur;exports.RectangleAnnotationView=ar;exports.TextAnnotationView=nr;exports.TimeRangeAnnotationView=dr;exports.TrendLineAnnotationView=At;exports.VLineAnnotationView=lr;exports.calculateEMA=mi;exports.calculateSMA=hi;exports.createAlertLineAnnotation=As;exports.createArrowAnnotation=Xs;exports.createBosLineAnnotation=Is;exports.createBrushAnnotation=Vs;exports.createChannelAnnotation=Ss;exports.createCrossLineAnnotation=Ws;exports.createEmojiAnnotation=Es;exports.createFairValueGapAnnotation=Bs;exports.createFibExtensionAnnotation=zs;exports.createFibRetracementAnnotation=Ls;exports.createHLineAnnotation=Ns;exports.createMeasureAnnotation=Ys;exports.createOrderBlockAnnotation=Ts;exports.createPitchforkAnnotation=_s;exports.createRayAnnotation=Os;exports.createRectangleAnnotation=Ps;exports.createTextAnnotation=Ms;exports.createTimeRangeAnnotation=$s;exports.createTrendLineAnnotation=Fs;exports.createVLineAnnotation=vs;exports.useCandlestickChart=ni;exports.useChartAnimations=di;exports.useChartLayout=ui;exports.useChartPanZoom=oi;exports.useChartPanZoomVirtual=tr;exports.useContainerSize=rr;exports.useOverlayToggles=ai;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),s=require("react"),$r=require("d3"),ue=require("prop-types");var Et=typeof document<"u"?document.currentScript:null;function Xr(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const Le=Xr($r);function Jt({points:e=[],xScale:t,yScale:r,xBandwidth:n=0,shape:u="arrow-up",size:o=6,color:c="black",offsetY:f=0,text:i,fontSize:a=10,textColor:y=c,textOffsetY:m=0,variant:x="filled",strokeWidth:b=1.5,haloSize:d=0,haloOpacity:F=.25,onMarkerClick:k,animationPhase:R,staggerDelay:p=100,staggerStartIndex:M=0}){const[$,D]=s.useState(null),w=s.useRef(null);if(s.useEffect(()=>{const j=S=>{w.current&&!w.current.contains(S.target)&&D(null)};if($)return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[$]),!e||e.length===0)return null;const h=(j,S,V,v)=>{const z=v?"pointer":"default";if(u==="arrow-up"){const E=`M ${j} ${S} l ${-o} ${o} l ${2*o} 0 Z`;return l.jsx("path",{d:E,fill:c,stroke:c,style:{cursor:z}},V)}if(u==="arrow-down"){const E=`M ${j} ${S} l ${o} ${-o} l ${-2*o} 0 Z`;return l.jsx("path",{d:E,fill:c,stroke:c,style:{cursor:z}},V)}if(u==="none")return null;const X=x==="outline",K=[];return d>0&&K.push(l.jsx("circle",{cx:j,cy:S,r:o+d,fill:c,opacity:F,stroke:"none",style:{pointerEvents:"none"}},`${V}-halo`)),X?K.push(l.jsx("circle",{cx:j,cy:S,r:o,fill:"none",stroke:c,strokeWidth:b,style:{cursor:z,pointerEvents:"all"}},V)):K.push(l.jsx("circle",{cx:j,cy:S,r:o,fill:c,stroke:c,style:{cursor:z}},V)),K},A=(j,S,V)=>{j.tooltip&&D({point:j,cx:S,cy:V}),k&&k(j)};if(R&&R!=="events"&&R!=="annotations"&&R!=="complete")return null;const N=R==="events"?"marker-overlay marker-overlay-animated":"marker-overlay";return l.jsxs("g",{className:N,children:[e.map((j,S)=>{let V;typeof j.date=="number"||j.date instanceof Date?V=j.date:V=new Date(j.date);const v=t(V),z=r(j.price)+f,X=j.text||i,K=z+o+4+m,E=!!j.tooltip,q=Number.isFinite(j.animationOrder)?j.animationOrder:M+S,_=R==="events"?q*p:0,L={cursor:E?"pointer":"default",animationDelay:R==="events"?`${_}ms`:void 0};return l.jsxs("g",{className:R==="events"?"dwlf-marker-drop":"",onClick:E?()=>A(j,v,z):void 0,style:L,children:[h(v,z,`marker-${S}`,E),X&&l.jsx("text",{x:v,y:K,textAnchor:"middle",fontSize:a,fill:y,style:{cursor:E?"pointer":"default",pointerEvents:E?"auto":"none"},children:X})]},S)}),$&&l.jsx("g",{ref:w,children:l.jsx("foreignObject",{x:$.cx-150,y:$.cy-120,width:300,height:100,children:l.jsx("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{background:"rgba(15, 23, 42, 0.95)",color:"#f5f5f5",padding:"12px",borderRadius:"8px",fontSize:"12px",lineHeight:"1.4",maxHeight:"90px",overflow:"auto",boxShadow:"0 4px 12px rgba(0,0,0,0.3)",wordWrap:"break-word"},children:$.point.tooltip})})})]})}Jt.propTypes={points:ue.arrayOf(ue.shape({date:ue.oneOfType([ue.number,ue.string,ue.instanceOf(Date)]).isRequired,price:ue.number.isRequired,text:ue.string,tooltip:ue.string})),xScale:ue.func.isRequired,yScale:ue.func.isRequired,xBandwidth:ue.number,shape:ue.oneOf(["arrow-up","arrow-down","circle","none"]),size:ue.number,color:ue.string,offsetY:ue.number,text:ue.string,fontSize:ue.number,textColor:ue.string,textOffsetY:ue.number,variant:ue.oneOf(["filled","outline"]),strokeWidth:ue.number,haloSize:ue.number,haloOpacity:ue.number,onMarkerClick:ue.func,animationPhase:ue.string,staggerDelay:ue.number,staggerStartIndex:ue.number};function Qt({messages:e=[],xScale:t,yScale:r,xBandwidth:n=0,chartWidth:u,chartHeight:o,bubbleColor:c="rgba(0,0,0,0.8)",textColor:f="white",fontSize:i=11,pointer:a=!0,padding:y=6}){if(!e||e.length===0||!t||!r||!u||!o)return null;const m=i*.6,x=8,b=e.map((d,F)=>{let k;typeof d.date=="number"||d.date instanceof Date?k=d.date:k=new Date(d.date);const R=t(k),p=r(d.price),M=`${d.text}`.split(`
|
|
2
|
+
`),D=Math.max(...M.map(V=>V.length))*m+y*2,w=i*1.2,h=M.length*w+y*2;let A="above",I=p-x-h;I<0&&(A="below",I=p+x,I+h>o&&(A="above",I=Math.max(0,p-x-h)));let N=R-D/2;N<0&&(N=0),N+D>u&&(N=u-D);const j=A==="above"?I+h:I,S=Math.min(Math.max(R,N+y),N+D-y);return{key:F,anchorX:R,anchorY:p,bubbleX:N,bubbleY:I,bubbleWidth:D,bubbleHeight:h,direction:A,baseX:S,baseY:j,textLines:M}});return l.jsx("g",{className:"message-bubble-overlay",children:b.map(d=>l.jsxs("g",{children:[a&&l.jsx("line",{x1:d.baseX,y1:d.baseY,x2:d.anchorX,y2:d.anchorY,stroke:c,strokeWidth:1.2}),l.jsx("rect",{x:d.bubbleX,y:d.bubbleY,width:d.bubbleWidth,height:d.bubbleHeight,fill:c,rx:4,ry:4}),d.textLines.map((F,k)=>l.jsx("text",{x:d.bubbleX+y,y:d.bubbleY+y+i+k*i*1.2-i*.2,fontSize:i,fill:f,children:F},`txt-${d.key}-${k}`))]},`msg-bubble-${d.key}`))})}Qt.propTypes={messages:ue.arrayOf(ue.shape({date:ue.oneOfType([ue.number,ue.string,ue.instanceOf(Date)]).isRequired,price:ue.number.isRequired,text:ue.string.isRequired})),xScale:ue.func.isRequired,yScale:ue.func.isRequired,xBandwidth:ue.number,chartWidth:ue.number.isRequired,chartHeight:ue.number.isRequired,bubbleColor:ue.string,textColor:ue.string,fontSize:ue.number,pointer:ue.bool,padding:ue.number};function er({startDate:e,endDate:t,entryPrice:r,stopPrice:n,takePrice:u,xScale:o,yScale:c,riskColor:f="rgba(255,0,0,0.25)",rewardColor:i="rgba(0,255,0,0.25)",messages:a=[],xBandwidth:y=0,chartWidth:m,chartHeight:x,bubbleColor:b="rgba(0,0,0,0.8)",textColor:d="white",fontSize:F=11,pointer:k=!0,padding:R=6}){const[p,M]=s.useState(!1);if(e==null||r==null||n==null||u==null)return null;const $=(v,z)=>v==null?z:v instanceof Date||typeof v=="number"?v:new Date(v),D=$(e,0),w=$(t??e,D),h=o(D),A=o(w),I=c(Math.max(r,n)),N=Math.abs(c(r)-c(n)),j=c(Math.max(r,u)),S=Math.abs(c(r)-c(u)),V=A-h;return V<=0?null:l.jsxs("g",{className:"position-overlay",onClick:v=>{v.stopPropagation(),M(z=>!z)},style:{cursor:a!=null&&a.length?"pointer":"default"},children:[l.jsx("rect",{x:h,y:I,width:V,height:N,fill:f,stroke:"none"}),l.jsx("rect",{x:h,y:j,width:V,height:S,fill:i,stroke:"none"}),p&&a&&a.length>0&&m&&x&&l.jsx(Qt,{messages:a,xScale:o,yScale:c,xBandwidth:y,chartWidth:m,chartHeight:x,bubbleColor:b,textColor:d,fontSize:F,pointer:k,padding:R})]})}er.propTypes={startDate:ue.oneOfType([ue.number,ue.string,ue.instanceOf(Date)]).isRequired,endDate:ue.oneOfType([ue.number,ue.string,ue.instanceOf(Date)]),entryPrice:ue.number.isRequired,stopPrice:ue.number.isRequired,takePrice:ue.number.isRequired,xScale:ue.func.isRequired,yScale:ue.func.isRequired,riskColor:ue.string,rewardColor:ue.string,messages:ue.arrayOf(ue.shape({date:ue.oneOfType([ue.number,ue.string,ue.instanceOf(Date)]).isRequired,price:ue.number.isRequired,text:ue.string.isRequired})),xBandwidth:ue.number,chartWidth:ue.number,chartHeight:ue.number,bubbleColor:ue.string,textColor:ue.string,fontSize:ue.number,pointer:ue.bool,padding:ue.number};function tr(e,t=50,r=30,n="daily"){const u=(n||"").toLowerCase(),o=u==="hourly"?36e5:864e5,c=e.length+r,[f,i]=s.useState(()=>Math.max(0,c-t)),[a,y]=s.useState(c),m=s.useRef(),[x,b]=s.useState(!1),[d,F]=s.useState(0),R=s.useCallback(()=>{const v=Math.min(a,e.length),z=e.slice(f,v);let X=[];if(a>e.length&&e.length){const K=new Date(e[e.length-1].date),E=Math.max(f,e.length),q=Math.max(0,a-E),_=E-(e.length-1);X=Array.from({length:q},(L,O)=>{const Y=_+O,g=new Date(K.getTime()+Y*o).toISOString();return{date:u==="hourly"?g:g.split("T")[0],_virtual:!0}})}return[...z,...X]},[f,a,e,u,o])(),p=R.length,M=s.useCallback((v,z)=>{const X=Math.max(0,Math.min(z,c)),K=Math.max(0,Math.min(v,c-X));return{start:K,end:K+X}},[c]);s.useEffect(()=>{const v=a-f;if(v<=0)return;const{start:z,end:X}=M(f,v);z!==f&&i(z),X!==a&&y(X)},[M,f,a]);const $=s.useCallback(v=>{b(!0),F(v.clientX)},[]),D=s.useCallback(v=>{if(!x)return;const z=v.clientX-d,X=m.current;if(!X)return;const K=X.getBoundingClientRect(),E={left:10,right:20},_=(K.width-E.left-E.right)/p,L=Math.round(z/(_*1.5));if(L!==0){const{start:O,end:Y}=M(f-L,p);i(O),y(Y),F(v.clientX)}},[x,d,p,f,M]),w=s.useCallback(()=>b(!1),[]),h=s.useCallback(v=>{v.preventDefault();const z=v.currentTarget.getBoundingClientRect(),X={left:10,right:20},K=z.width-X.left-X.right;if(Math.abs(v.deltaX)>Math.abs(v.deltaY)){const J=K/p,Q=Math.round(v.deltaX/(J*1.5));if(Q){const{start:le,end:G}=M(f-Q,p);i(le),y(G)}return}const _=(v.clientX-z.left-X.left)/K,O=1+v.deltaY*.002,Y=O<=0?.1:O,ne=Math.max(5,Math.min(c,Math.round(p*Y)));if(ne===p)return;const g=f+_*p,W=Math.round(g-_*ne),{start:ge,end:H}=M(W,ne);i(ge),y(H)},[p,f,M,c]),A=s.useCallback(v=>{m.current&&m.current.removeEventListener("wheel",h),m.current=v,v&&v.addEventListener("wheel",h,{passive:!1})},[h]),I=s.useCallback(()=>{const v=Math.max(5,Math.round((a-f)*.8)),z=(f+a)/2,{start:X,end:K}=M(Math.round(z-v/2),v);i(X),y(K)},[f,a,M]),N=s.useCallback(()=>{const v=Math.min(c,Math.round((a-f)*1.25)),z=(f+a)/2,{start:X,end:K}=M(Math.round(z-v/2),v);i(X),y(K)},[f,a,M,c]),j=s.useCallback(()=>{const{start:v,end:z}=M(c-t,t);i(v),y(z)},[t,M,c]),S=s.useCallback(()=>{const{start:v,end:z}=M(0,p);i(v),y(z)},[M,p]),V=s.useCallback(()=>{const{start:v,end:z}=M(c-p,p);i(v),y(z)},[M,p,c]);return{visibleData:R,viewportStart:f,viewportEnd:a,visibleCount:p,mouseHandlers:{onMouseDown:$,onMouseMove:D,onMouseUp:w,onMouseLeave:w},chartElementRef:A,zoomIn:I,zoomOut:N,resetView:j,panToStart:S,panToEnd:V,isPanning:x}}function rr(){const e=s.useRef(null),[t,r]=s.useState({width:0,height:0});return s.useEffect(()=>{if(!e.current)return;const n=new ResizeObserver(([u])=>{const{width:o,height:c}=u.contentRect;r({width:o,height:c})});return n.observe(e.current),()=>n.disconnect()},[]),[e,t]}const Lr=[0,1],Yr=.15,Te=e=>Number.isFinite(e),sr=e=>{if(!Array.isArray(e))return!1;if(e.length===0)return!0;const t=e[0];return t&&typeof t.t=="number"&&typeof t.v=="number"},ir=e=>{if(!Array.isArray(e))return!1;if(e.length===0)return!0;const t=e[0];return t&&typeof t.t=="number"&&typeof t.o=="number"&&typeof t.h=="number"&&typeof t.l=="number"&&typeof t.c=="number"},Ar=e=>{const t=e.data??[];if(!Array.isArray(t)||t.length===0)return[];if(e.type==="ohlc"&&ir(t)){const n=t.map(o=>o.l).filter(Te),u=t.map(o=>o.h).filter(Te);return[...n,...u]}if(sr(t)){const n=t.map(u=>u.v).filter(Te);return e.type==="hist"?[...n,0]:n}if(e.type==="marker")return t.map(n=>n&&typeof n=="object"?Number(n.v):Number.NaN).filter(Te);if(e.type==="position")return t.flatMap(n=>{if(!n||typeof n!="object")return[];const u=Number(n.entry),o=Number(n.stop),c=Number(n.target);return[u,o,c]}).filter(Te);const r=t.flatMap(n=>Object.values(n??{})).filter(Te);return e.type==="hist"?[...r,0]:r},Vr=(e,t,r)=>e.type==="ohlc"||!r?!0:t,_r=(e,t)=>{const r=[],n=e.series.some(m=>m.type==="ohlc");if(e.series.filter(m=>Vr(m,t,n)).forEach(m=>{const x=Ar(m);if(!x.length)return;const b=Le.min(x),d=Le.max(x);!Te(b)||!Te(d)||r.push([b,d])}),!r.length)return Lr;const o=Le.min(r.map(([m])=>m)),c=Le.max(r.map(([,m])=>m));if(!Te(o)||!Te(c)||o===c){const m=Te(o)?o:0;return[m-1,m+1]}const i=(c-o)*Yr,a=o-i,y=c+i;return!Number.isFinite(a)||!Number.isFinite(y)?[o,c]:[a,y]},zr=(e,t={})=>{const r=t.includeOverlaysInAutoScale??!1;if(e.yScale.mode==="fixed"){const n=Te(e.yScale.min)?e.yScale.min:0,u=Te(e.yScale.max)?e.yScale.max:1;return n===u?[n-1,u+1]:[n,u]}return _r(e,r)},Tr=(e,t)=>{const r=Le.scaleLinear().domain(e).range([t,0]);return{domain:e,scale:o=>r(o),invert:o=>r.invert(o)}},Br=(e,t,r={})=>{const n=r.includeOverlaysInAutoScale??e.includeOverlaysInAutoScale??!1,u={};return e.panes.forEach(o=>{const c=t[o.id]??0;u[o.id]=Tr(zr(o,{includeOverlaysInAutoScale:n}),c)}),u},Ir=e=>{const t=e.data??[];return Array.isArray(t)?ir(t)?t.map(r=>r.t).filter(Te):sr(t)?t.map(r=>r.t).filter(Te):e.type==="marker"?t.map(r=>r&&typeof r=="object"?Number(r.t):Number.NaN).filter(Te):e.type==="position"?t.flatMap(r=>{if(!r||typeof r!="object")return[];const n=Number(r.start),u=Number(r.end),o=[];return Number.isFinite(n)&&o.push(n),Number.isFinite(u)&&o.push(u),o}).filter(Te):t.map(r=>r&&typeof r.t=="number"?r.t:void 0).filter(Te):[]},Ur=e=>{const t=[];return e.series.forEach(r=>{t.push(...Ir(r))}),t},zt=e=>{const t=new Set;return e.panes.forEach(r=>{Ur(r).forEach(n=>t.add(n))}),Array.from(t).sort((r,n)=>r-n)},nt=(e,t)=>{if(!e.length)return Number.NaN;let r=0,n=e.length-1;for(;r<=n;){const c=Math.floor((r+n)/2),f=e[c];if(f===t)return f;f<t?r=c+1:n=c-1}const u=e[Math.max(0,n)],o=e[Math.min(e.length-1,r)];return Math.abs(u-t)<=Math.abs(o-t)?u:o},He={solid:void 0,dashed:"8 4",dotted:"2 4"},_e=(e,t,r)=>{if(!r)return;const n=r(e);if(n!==void 0)return n;if(!t||!t.length)return;const u=nt(t,e);if(Number.isFinite(u))return r(u)},tt=(e,t,r,n,u,o)=>{let c;if(r&&n&&u>0?c=_e(e,o,r):r&&(c=r(e)),r&&c===void 0)return;const i=t(c??e);return Number.isFinite(i)?i:void 0},Tt=e=>e instanceof Date?e.getTime():e,Bt=(e,t,r,n,u,o,c)=>{const f=tt(e,t,r,n,u,o);if(f!==void 0)return f;let i,a,y,m;if(r&&n&&u>0){if(!o||o.length===0)return;const F=Math.min(o.length-1,u-1);i=o[0],a=o[F],y=t(0),m=t(F)}else if(t.invert){const F=t.range?t.range():[0,c??0],k=t.invert(F[0]),R=t.invert(F[1]);i=Tt(k),a=Tt(R),y=t(i),m=t(a)}if(i===void 0||a===void 0||!Number.isFinite(i)||!Number.isFinite(a)||y===void 0||m===void 0||!Number.isFinite(y)||!Number.isFinite(m))return;const x=a-i;if(!Number.isFinite(x)||x===0)return;const b=(m-y)/x;if(!Number.isFinite(b))return;const d=y+(e-i)*b;return Number.isFinite(d)?d:void 0},qr=e=>e.button===0,Fe=({onDragMove:e,onDragStart:t,onDragEnd:r,shouldStart:n=qr,stopPropagation:u=!0,preventDefault:o=!0})=>{const[c,f]=s.useState(!1),i=s.useRef(null),a=s.useRef(e),y=s.useRef(t),m=s.useRef(r);s.useEffect(()=>{a.current=e},[e]),s.useEffect(()=>{y.current=t},[t]),s.useEffect(()=>{m.current=r},[r]),s.useEffect(()=>()=>{var b;(b=i.current)==null||b.call(i)},[]);const x=s.useCallback(b=>{var R,p;if(!n(b))return;u&&b.stopPropagation(),o&&b.preventDefault(),(R=i.current)==null||R.call(i),f(!0),(p=y.current)==null||p.call(y,b);const d=M=>{a.current(M)},F=()=>{var M;f(!1),document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",k),i.current=null,(M=m.current)==null||M.call(m)},k=()=>{F()};i.current=F,document.addEventListener("mousemove",d),document.addEventListener("mouseup",k)},[o,n,u]);return{isDragging:c,handleMouseDown:x}},Gr={solid:void 0,dashed:"8 4",dotted:"2 4"},Xe=12,at=10,Ue=16,Ae=32,Be=8,$e=24,Qe=4,ft=Qe+$e/4,dt=Qe+$e*3/4,cr=({annotation:e,yScale:t,chartWidth:r,paneHeight:n,darkMode:u=!1,selected:o=!1,onSelect:c,onDoubleClick:f,onMove:i})=>{const a=s.useRef(0),y=s.useRef(0),m=s.useRef(t);s.useEffect(()=>{m.current=t},[t]);const x=s.useCallback(A=>{A.stopPropagation(),c==null||c(e.id)},[e.id,c]),b=s.useCallback(A=>{A.stopPropagation(),f==null||f(e.id)},[e.id,f]),d=s.useCallback(A=>{a.current=A.clientY,y.current=e.price},[e.price]),F=s.useCallback(A=>{const I=A.clientY-a.current,N=m.current,j=N.invert(N.scale(y.current)+I);Number.isFinite(j)&&(i==null||i(e.id,j))},[e.id,i]),{isDragging:k,handleMouseDown:R}=Fe({onDragStart:d,onDragMove:F}),p=t.scale(e.price);if(!Number.isFinite(p)||p<-20||p>n+20)return null;const M=He[e.lineStyle]||void 0,$=e.label||(e.showPrice?e.price.toFixed(2):""),D=Math.max(50,$.length*7+16),w=o?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",h=u?"#e2e8f0":"#1f2937";return l.jsxs("g",{className:"hline-annotation",onClick:x,onDoubleClick:b,style:{cursor:k?"grabbing":"pointer"},children:[o&&l.jsx("line",{x1:0,x2:r,y1:p,y2:p,stroke:w,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:0,x2:r,y1:p,y2:p,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:0,x2:r,y1:p,y2:p,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:M,strokeLinecap:"round"}),$&&l.jsxs("g",{children:[l.jsx("rect",{x:r-D-8,y:p-10,width:D,height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:r-D/2-8,y:p,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:$})]}),o&&l.jsxs("g",{onMouseDown:R,style:{cursor:"ns-resize"},children:[l.jsx("rect",{x:Qe,y:p-$e/2,width:$e,height:$e,fill:h,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:2}),l.jsx("line",{x1:ft,x2:dt,y1:p-2,y2:p-2,stroke:e.color,strokeWidth:1.5}),l.jsx("line",{x1:ft,x2:dt,y1:p+2,y2:p+2,stroke:e.color,strokeWidth:1.5})]})]})},Zr=e=>{const t=new Date(e),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),u=String(t.getUTCHours()).padStart(2,"0"),o=String(t.getUTCMinutes()).padStart(2,"0");return`${r}/${n} ${u}:${o}`},lr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onDoubleClick:i,onMove:a,timeToIndex:y,indexToTime:m,dataLength:x=0,compressedTimes:b,timeFormatter:d=Zr})=>{const F=s.useRef(0),k=s.useRef(0),R=s.useRef(t),p=s.useRef(y),M=s.useRef(m),$=s.useRef(b),D=s.useRef(x);s.useEffect(()=>{R.current=t,p.current=y,M.current=m,$.current=b,D.current=x},[t,y,m,b,x]);const w=s.useCallback(_=>{_.stopPropagation(),f==null||f(e.id)},[e.id,f]),h=s.useCallback(_=>{_.stopPropagation(),i==null||i(e.id)},[e.id,i]),A=s.useCallback(_=>{F.current=_.clientX,k.current=e.time},[e.time]),I=s.useCallback(_=>{const L=_.clientX-F.current,O=R.current,Y=p.current,ne=M.current,g=$.current,W=D.current,ge=Y&&ne&&W>0?_e(k.current,g,Y)??k.current:k.current,H=O(ge)+L;let J=k.current;if(O.invert){const Q=O.invert(H),le=Q instanceof Date?Q.getTime():Q;J=ne?ne(Math.round(le)):le}Number.isFinite(J)&&(a==null||a(e.id,J))},[e.id,a]),{isDragging:N,handleMouseDown:j}=Fe({onDragStart:A,onDragMove:I});let S;if(y&&m&&x>0?S=_e(e.time,b,y):y&&(S=y(e.time)),y&&S===void 0)return null;const V=S??e.time,v=t(V);if(!Number.isFinite(v)||v<-20||v>n+20)return null;const z=He[e.lineStyle]||void 0,X=e.label||(e.showTime?d(e.time):""),K=Math.max(60,X.length*7+16),E=c?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",q=o?"#e2e8f0":"#1f2937";return l.jsxs("g",{className:"vline-annotation",onClick:w,onDoubleClick:h,style:{cursor:N?"grabbing":"pointer"},children:[c&&l.jsx("line",{x1:v,x2:v,y1:0,y2:u,stroke:E,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:v,x2:v,y1:0,y2:u,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:v,x2:v,y1:0,y2:u,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:z,strokeLinecap:"round"}),X&&l.jsxs("g",{children:[l.jsx("rect",{x:v-K/2,y:4,width:K,height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:v,y:14,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:X})]}),c&&l.jsxs("g",{onMouseDown:j,style:{cursor:"ew-resize"},children:[l.jsx("rect",{x:v-$e/2,y:u-$e-Qe,width:$e,height:$e,fill:q,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:2}),l.jsx("line",{x1:v-2,x2:v-2,y1:u-$e*.75-Qe,y2:u-$e*.25-Qe,stroke:e.color,strokeWidth:1.5}),l.jsx("line",{x1:v+2,x2:v+2,y1:u-$e*.75-Qe,y2:u-$e*.25-Qe,stroke:e.color,strokeWidth:1.5})]})]})},nr=({annotation:e,xScale:t,yScale:r,paneHeight:n,darkMode:u=!1,selected:o=!1,onSelect:c,onDoubleClick:f,onMove:i,onTextEdit:a,timeToIndex:y,indexToTime:m,dataLength:x=0,compressedTimes:b})=>{const d=s.useCallback(z=>{z.stopPropagation(),c==null||c(e.id)},[e.id,c]),F=s.useCallback(z=>{z.stopPropagation(),f==null||f(e.id),a==null||a(e.id)},[e.id,f,a]),{handleMouseDown:k,indexValue:R,isDragging:p}=Fe({annotationId:e.id,time:e.time,price:e.price});if(y&&R===void 0)return null;const M=R??e.time,$=t(M),D=r.scale(e.price);if(!Number.isFinite($)||!Number.isFinite(D)||D<-50||D>n+50)return null;const w=6,h=e.text.split(`
|
|
3
|
+
`),A=e.fontSize*1.3,I=h.reduce((z,X)=>z.length>X.length?z:X,""),N=Math.max(20,I.length*(e.fontSize*.6)+w*2),j=h.length===1?e.fontSize+w*2:h.length*A+w*2,S=o?u?"rgba(99, 179, 237, 0.5)":"rgba(59, 130, 246, 0.5)":"transparent",V=e.backgroundColor||(u?"rgba(30, 41, 59, 0.95)":"rgba(255, 255, 255, 0.95)"),v=o?u?"#63b3ed":"#3b82f6":u?"#475569":"#cbd5e1";return l.jsxs("g",{className:"text-annotation",onClick:d,onDoubleClick:F,onMouseDown:o?k:void 0,style:{cursor:p?"grabbing":o?"grab":"pointer"},children:[o&&l.jsx("rect",{x:$-N/2-3,y:D-j/2-3,width:N+6,height:j+6,fill:"none",stroke:S,strokeWidth:3,rx:6}),l.jsx("rect",{x:$-N/2,y:D-j/2,width:N,height:j,fill:V,stroke:v,strokeWidth:1,rx:4}),l.jsx("text",{x:$,y:D-(h.length-1)*A/2,dy:"0.35em",textAnchor:"middle",fontSize:e.fontSize,fill:e.color,fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:h.map((z,X)=>l.jsx("tspan",{x:$,dy:X===0?0:A,children:z},X))}),o&&l.jsx("circle",{cx:$,cy:D-j/2-8,r:Xe,fill:u?"#e2e8f0":"#1f2937",stroke:v,strokeWidth:1,style:{cursor:"move"}})]})},Hr=(e,t,r,n,u,o,c,f)=>{let i=e,a=t,y=r,m=n;const x=r-e,b=n-t;if(x===0&&b===0)return{ex1:i,ey1:a,ex2:y,ey2:m};if(x===0)return c&&(a=(t<n?-1:1)<0?0:o),f&&(m=(n>t?1:-1)>0?o:0),{ex1:i,ey1:a,ex2:y,ey2:m};if(b===0)return c&&(i=(e<r?-1:1)<0?0:u,a=t),f&&(y=(r>e?1:-1)>0?u:0,m=n),{ex1:i,ey1:a,ex2:y,ey2:m};const d=b/x,F=t-d*e;if(c){const k=e<r?-1:1,R=k<0?0:u,p=d*R+F;let M=R,$=p;p<0?(M=-F/d,$=0):p>o&&(M=(o-F)/d,$=o),(k<0&&M<=e||k>0&&M>=e)&&(i=M,a=$)}if(f){const k=r>e?1:-1,R=k>0?u:0,p=d*R+F;let M=R,$=p;p<0?(M=-F/d,$=0):p>o&&(M=(o-F)/d,$=o),(k>0&&M>=r||k<0&&M<=r)&&(y=M,m=$)}return{ex1:i,ey1:a,ex2:y,ey2:m}},At=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x})=>{const b=s.useRef({x:0,y:0}),d=s.useRef({time1:0,price1:0,time2:0,price2:0}),F=s.useRef(t),k=s.useRef(r),R=s.useRef(a),p=s.useRef(y),M=s.useRef(x),$=s.useRef(m);s.useEffect(()=>{F.current=t,k.current=r,R.current=a,p.current=y,M.current=x,$.current=m},[t,r,a,y,x,m]);const D=s.useCallback(re=>{re.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((re,U,C,T)=>{const Z=F.current,P=k.current,ee=R.current,ie=p.current,te=M.current,ce=$.current,Ce=!!(ee&&ie&&ce>0)?_e(re,te,ee):null,pe=Z(Ce??re)+C,be=P.scale(U)+T;let we=re;if(Z.invert){const xe=Z.invert(pe),Pe=xe instanceof Date?xe.getTime():xe;we=ee&&ie&&ce>0?ie(Math.round(Pe)):Pe}const Me=P.invert(be);return{time:Number.isFinite(we)?we:re,price:Number.isFinite(Me)?Me:U}},[]),h=s.useCallback(re=>{b.current={x:re.clientX,y:re.clientY},d.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),A=s.useCallback(re=>{const U=re.clientX-b.current.x,C=re.clientY-b.current.y,{time:T,price:Z}=w(d.current.time1,d.current.price1,U,C);i==null||i(e.id,{time1:T,price1:Z})},[e.id,i,w]),{isDragging:I,handleMouseDown:N}=Fe({onDragStart:h,onDragMove:A}),j=s.useCallback(re=>{const U=re.clientX-b.current.x,C=re.clientY-b.current.y,{time:T,price:Z}=w(d.current.time2,d.current.price2,U,C);i==null||i(e.id,{time2:T,price2:Z})},[e.id,i,w]),{isDragging:S,handleMouseDown:V}=Fe({onDragStart:h,onDragMove:j}),v=s.useCallback(re=>{const U=re.clientX-b.current.x,C=re.clientY-b.current.y,T=w(d.current.time1,d.current.price1,U,C),Z=w(d.current.time2,d.current.price2,U,C);i==null||i(e.id,{time1:T.time,price1:T.price,time2:Z.time,price2:Z.price})},[e.id,i,w]),{isDragging:z,handleMouseDown:X}=Fe({onDragStart:h,onDragMove:v}),K=I||S||z,E=Bt(e.time1,t,a,y,m,x,n),q=Bt(e.time2,t,a,y,m,x,n);if(E===void 0||q===void 0)return null;const _=r.scale(e.price1),L=r.scale(e.price2);if(!Number.isFinite(_)||!Number.isFinite(L))return null;const{ex1:O,ey1:Y,ex2:ne,ey2:g}=Hr(E,_,q,L,n,u,e.extendLeft,e.extendRight),W=O<-50&&ne<-50||O>n+50&&ne>n+50,ge=Y<-50&&g<-50||Y>u+50&&g>u+50;if(W||ge)return null;const H=He[e.lineStyle]||void 0,J=c?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",Q=o?"#e2e8f0":"#1f2937",le=e.label||"",G=(E+q)/2,se=(_+L)/2;return l.jsxs("g",{className:"trendline-annotation",onClick:D,style:{cursor:K?"grabbing":"pointer"},children:[c&&l.jsx("line",{x1:O,y1:Y,x2:ne,y2:g,stroke:J,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:O,y1:Y,x2:ne,y2:g,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?X:void 0}),l.jsx("line",{x1:O,y1:Y,x2:ne,y2:g,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:H,strokeLinecap:"round"}),le&&l.jsxs("g",{children:[l.jsx("rect",{x:G-le.length*3.5-8,y:se-10,width:Math.max(30,le.length*7+16),height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:G,y:se,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:le})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:E,cy:_,r:Xe,fill:Q,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:N,style:{cursor:"move"}}),l.jsx("circle",{cx:q,cy:L,r:Xe,fill:Q,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:V,style:{cursor:"move"}}),l.jsx("circle",{cx:G,cy:se,r:at,fill:e.color,fillOpacity:.6,onMouseDown:X,style:{cursor:"grab"}})]})]})},or=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x})=>{const b=s.useMemo(()=>({...e,type:"trendline",extendLeft:!1,extendRight:!0}),[e]),d=s.useMemo(()=>{if(i)return(F,k)=>{const{extendLeft:R,extendRight:p,type:M,...$}=k;i(F,$)}},[i]);return l.jsx(At,{annotation:b,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:c,onSelect:f,onMove:d,timeToIndex:a,indexToTime:y,dataLength:m,compressedTimes:x})},Kr=e=>{const t=new Date(e),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),u=String(t.getUTCHours()).padStart(2,"0"),o=String(t.getUTCMinutes()).padStart(2,"0");return`${r}/${n} ${u}:${o}`},ur=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x,timeFormatter:b=Kr})=>{const d=s.useRef({x:0,y:0}),F=s.useRef({time:0,price:0}),k=s.useRef(t),R=s.useRef(r),p=s.useRef(a),M=s.useRef(y),$=s.useRef(x),D=s.useRef(m);s.useEffect(()=>{k.current=t,R.current=r,p.current=a,M.current=y,$.current=x,D.current=m},[t,r,a,y,x,m]);const w=s.useCallback(L=>{L.stopPropagation(),f==null||f(e.id)},[e.id,f]),h=s.useCallback(L=>{d.current={x:L.clientX,y:L.clientY},F.current={time:e.time,price:e.price}},[e.time,e.price]),A=s.useCallback(L=>{const O=L.clientX-d.current.x,Y=L.clientY-d.current.y,ne=k.current,g=R.current,W=p.current,ge=M.current,H=$.current,J=D.current;let Q;W&&ge&&J>0?Q=_e(F.current.time,H,W)??F.current.time:Q=F.current.time;const le=ne(Q)+O,G=g.scale(F.current.price)+Y;let se=F.current.time;if(ne.invert){const U=ne.invert(le),C=U instanceof Date?U.getTime():U;se=ge?ge(Math.round(C)):C}const re=g.invert(G);Number.isFinite(se)&&Number.isFinite(re)&&(i==null||i(e.id,se,re))},[e.id,i]),{isDragging:I,handleMouseDown:N}=Fe({onDragStart:h,onDragMove:A}),j=tt(e.time,t,a,y,m,x),S=r.scale(e.price);if(j===void 0||!Number.isFinite(S))return null;if(j<-50||j>n+50||S<-50||S>u+50){const L=j>=-50&&j<=n+50,O=S>=-50&&S<=u+50;if(!L&&!O)return null}const V=He[e.lineStyle]||void 0,v=c?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",z=o?"#e2e8f0":"#1f2937",X=e.showPrice?e.price.toFixed(2):"",K=e.showTime?b(e.time):"",E=e.label||"",q=X?Math.max(50,X.length*7+16):0,_=K?Math.max(60,K.length*7+16):0;return l.jsxs("g",{className:"crossline-annotation",onClick:w,style:{cursor:I?"grabbing":"pointer"},children:[c&&l.jsxs(l.Fragment,{children:[l.jsx("line",{x1:0,x2:n,y1:S,y2:S,stroke:v,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:j,x2:j,y1:0,y2:u,stroke:v,strokeWidth:e.lineWidth+6,strokeLinecap:"round"})]}),l.jsx("line",{x1:0,x2:n,y1:S,y2:S,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:j,x2:j,y1:0,y2:u,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:0,x2:n,y1:S,y2:S,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:V,strokeLinecap:"round"}),l.jsx("line",{x1:j,x2:j,y1:0,y2:u,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:V,strokeLinecap:"round"}),l.jsx("circle",{cx:j,cy:S,r:4,fill:e.color,fillOpacity:.9,stroke:o?"#1a1a2e":"#fff",strokeWidth:1.5}),X&&l.jsxs("g",{children:[l.jsx("rect",{x:n-q-8,y:S-10,width:q,height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:n-q/2-8,y:S,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:X})]}),K&&l.jsxs("g",{children:[l.jsx("rect",{x:j-_/2,y:u-20,width:_,height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:j,y:u-10,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:K})]}),E&&l.jsxs("g",{children:[l.jsx("rect",{x:j+8,y:S-22,width:Math.max(30,E.length*7+12),height:18,fill:e.color,fillOpacity:.85,rx:3}),l.jsx("text",{x:j+8+Math.max(30,E.length*7+12)/2,y:S-13,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:E})]}),c&&l.jsxs("g",{onMouseDown:N,style:{cursor:"move"},children:[l.jsx("circle",{cx:j,cy:S,r:Xe,fill:z,fillOpacity:.9,stroke:e.color,strokeWidth:2}),l.jsx("line",{x1:j-3,x2:j+3,y1:S,y2:S,stroke:e.color,strokeWidth:1.5}),l.jsx("line",{x1:j,x2:j,y1:S-3,y2:S+3,stroke:e.color,strokeWidth:1.5})]})]})},Jr={solid:void 0,dashed:"8 4",dotted:"2 4"},Rt=(e,t,r)=>{if(!r)return;const n=r(e);if(n!==void 0)return n;if(!t||!t.length)return;const u=nt(t,e);if(Number.isFinite(u))return r(u)},ar=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x})=>{const b=s.useRef({x:0,y:0}),d=s.useRef({time1:0,price1:0,time2:0,price2:0}),F=s.useRef(t),k=s.useRef(r),R=s.useRef(a),p=s.useRef(y),M=s.useRef(x),$=s.useRef(m);s.useEffect(()=>{F.current=t,k.current=r,R.current=a,p.current=y,M.current=x,$.current=m},[t,r,a,y,x,m]);const D=s.useCallback(G=>{G.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((G,se)=>{const re=F.current,U=R.current,C=p.current,T=M.current,Z=$.current,P=U&&C&&Z>0?Rt(G,T,U)??G:G,ee=re(P)+se;if(!re.invert)return G;const ie=re.invert(ee),te=ie instanceof Date?ie.getTime():ie;return U&&C&&Z>0?C(Math.round(te)):te},[]),h=s.useCallback(G=>{b.current={x:G.clientX,y:G.clientY},d.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),A=s.useCallback(G=>{const se=G.clientX-b.current.x,re=G.clientY-b.current.y,U=k.current,C=d.current,T=w(C.time1,se),Z=w(C.time2,se),P=U.invert(U.scale(C.price1)+re),ee=U.invert(U.scale(C.price2)+re);[T,Z,P,ee].every(Number.isFinite)&&(i==null||i(e.id,{time1:T,price1:P,time2:Z,price2:ee}))},[e.id,i,w]),I=s.useCallback(G=>se=>{const re=se.clientX-b.current.x,U=se.clientY-b.current.y,C=k.current,T=d.current,Z=C.scale(T.price1),P=C.scale(T.price2),ee=Z<=P,ie={},te=F.current,ce=R.current,De=M.current,Ce=(ce?Rt(T.time1,De,ce):void 0)??T.time1,je=(ce?Rt(T.time2,De,ce):void 0)??T.time2,pe=te(Ce),be=te(je),we=pe<=be;if(G==="tl"||G==="bl"){const Me=we?T.time1:T.time2,xe=w(Me,re);Number.isFinite(xe)&&(we?ie.time1=xe:ie.time2=xe)}else{const Me=we?T.time2:T.time1,xe=w(Me,re);Number.isFinite(xe)&&(we?ie.time2=xe:ie.time1=xe)}if(G==="tl"||G==="tr"){const Me=ee?T.price1:T.price2,xe=C.invert(C.scale(Me)+U);Number.isFinite(xe)&&(ee?ie.price1=xe:ie.price2=xe)}else{const Me=ee?T.price2:T.price1,xe=C.invert(C.scale(Me)+U);Number.isFinite(xe)&&(ee?ie.price2=xe:ie.price1=xe)}i==null||i(e.id,ie)},[e.id,i,w]),N=s.useRef(A),j=s.useCallback(G=>{N.current(G)},[]),{isDragging:S,handleMouseDown:V}=Fe({onDragStart:h,onDragMove:j}),v=s.useCallback(G=>{N.current=A,V(G)},[A,V]),z=s.useCallback(G=>se=>{N.current=I(G),V(se)},[I,V]),X=G=>{if(a&&y&&m>0)return Rt(G,x,a);if(a)return a(G)},K=X(e.time1),E=X(e.time2);if(a&&(K===void 0||E===void 0))return null;const q=t(K??e.time1),_=t(E??e.time2),L=r.scale(e.price1),O=r.scale(e.price2);if([q,_,L,O].some(G=>!Number.isFinite(G)))return null;const Y=Math.min(q,_),ne=Math.max(q,_),g=Math.min(L,O),W=Math.max(L,O),ge=ne-Y,H=W-g;if(ne<-50||Y>n+50||W<-50||g>u+50)return null;const J=Jr[e.lineStyle]||void 0,Q=o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",le=o?"#e2e8f0":"#1f2937";return l.jsxs("g",{className:"rectangle-annotation",onClick:D,style:{cursor:S?"grabbing":"pointer"},children:[c&&l.jsx("rect",{x:Y-3,y:g-3,width:ge+6,height:H+6,fill:"none",stroke:Q,strokeWidth:3,rx:2}),l.jsx("rect",{x:Y-Be,y:g-Be,width:ge+Be*2,height:H+Be*2,fill:"transparent",stroke:"transparent",strokeWidth:Be,style:{cursor:"pointer"}}),l.jsx("rect",{x:Y,y:g,width:ge,height:H,fill:e.color,fillOpacity:e.fillOpacity,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:J,rx:1,onMouseDown:c?v:void 0,style:{cursor:c?S?"grabbing":"move":"pointer"}}),e.label&&l.jsx("text",{x:Y+6,y:g+14,fontSize:11,fill:e.color,fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:e.label}),c&&l.jsx("text",{x:ne-6,y:W-6,fontSize:10,fill:o?"#94a3b8":"#64748b",textAnchor:"end",style:{pointerEvents:"none",userSelect:"none"},children:Math.abs(e.price2-e.price1).toFixed(2)}),c&&l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:Y-Ue/2,y:g-Ue/2,width:Ue,height:Ue,fill:le,stroke:e.color,strokeWidth:1.5,rx:2,onMouseDown:z("tl"),style:{cursor:"nwse-resize"}}),l.jsx("rect",{x:ne-Ue/2,y:g-Ue/2,width:Ue,height:Ue,fill:le,stroke:e.color,strokeWidth:1.5,rx:2,onMouseDown:z("tr"),style:{cursor:"nesw-resize"}}),l.jsx("rect",{x:Y-Ue/2,y:W-Ue/2,width:Ue,height:Ue,fill:le,stroke:e.color,strokeWidth:1.5,rx:2,onMouseDown:z("bl"),style:{cursor:"nesw-resize"}}),l.jsx("rect",{x:ne-Ue/2,y:W-Ue/2,width:Ue,height:Ue,fill:le,stroke:e.color,strokeWidth:1.5,rx:2,onMouseDown:z("br"),style:{cursor:"nwse-resize"}})]})]})},Qr=({annotationId:e,time:t,price:r,xScale:n,yScale:u,onMove:o,timeToIndex:c,indexToTime:f,dataLength:i=0,compressedTimes:a})=>{const y=s.useRef({x:0,y:0}),m=s.useRef({time:0,price:0}),x=s.useRef(n),b=s.useRef(u),d=s.useRef(c),F=s.useRef(f),k=s.useRef(i),R=s.useRef(a);s.useEffect(()=>{x.current=n,b.current=u,d.current=c,F.current=f,k.current=i,R.current=a},[n,u,c,f,i,a]);const p=s.useCallback(h=>{y.current={x:h.clientX,y:h.clientY},m.current={time:t,price:r}},[r,t]),M=s.useCallback(h=>{const A=h.clientX-y.current.x,I=h.clientY-y.current.y,N=x.current,j=b.current,S=d.current,V=F.current,v=k.current,z=R.current;let X=m.current.time;S&&V&&v>0&&(X=_e(m.current.time,z,S)??m.current.time);const K=N(X)+A,E=j.scale(m.current.price)+I;let q=m.current.time;if(N.invert){const L=N.invert(K),O=L instanceof Date?L.getTime():L;q=V?V(Math.round(O)):O}const _=j.invert(E);Number.isFinite(q)&&Number.isFinite(_)&&(o==null||o(e,q,_))},[e,o]),{isDragging:$,handleMouseDown:D}=Fe({onDragStart:p,onDragMove:M}),w=s.useMemo(()=>{if(c&&f&&i>0)return _e(t,a,c);if(c)return c(t)},[a,i,f,t,c]);return{handleMouseDown:D,indexValue:w,isDragging:$}},fr=({annotation:e,xScale:t,yScale:r,paneHeight:n,darkMode:u=!1,selected:o=!1,onSelect:c,onMove:f,timeToIndex:i,indexToTime:a,dataLength:y=0,compressedTimes:m})=>{const x=s.useCallback(w=>{w.stopPropagation(),c==null||c(e.id)},[e.id,c]),{handleMouseDown:b,indexValue:d,isDragging:F}=Qr({annotationId:e.id,time:e.time,price:e.price,xScale:t,yScale:r,onMove:f,timeToIndex:i,indexToTime:a,dataLength:y,compressedTimes:m});if(i&&d===void 0)return null;const k=d??e.time,R=t(k),p=r.scale(e.price);if(!Number.isFinite(R)||!Number.isFinite(p)||p<-50||p>n+50)return null;const M=e.size??24,$=M+8,D=u?"rgba(99, 179, 237, 0.5)":"rgba(59, 130, 246, 0.5)";return l.jsxs("g",{className:"emoji-annotation",onClick:x,onMouseDown:o?b:void 0,style:{cursor:F?"grabbing":o?"grab":"pointer"},children:[o&&l.jsx("circle",{cx:R,cy:p,r:$/2+4,fill:"none",stroke:D,strokeWidth:2.5,strokeDasharray:"4 3"}),l.jsx("circle",{cx:R,cy:p,r:$/2,fill:"transparent",style:{cursor:"pointer"}}),l.jsx("text",{x:R,y:p,dy:"0.35em",textAnchor:"middle",fontSize:M,style:{pointerEvents:"none",userSelect:"none"},children:e.emoji}),o&&l.jsx("circle",{cx:R,cy:p-$/2-8,r:Xe,fill:u?"#e2e8f0":"#1f2937",stroke:u?"#475569":"#cbd5e1",strokeWidth:1,style:{cursor:"move"}})]})},es={solid:void 0,dashed:"8 4",dotted:"2 4"},dr=({annotation:e,xScale:t,chartWidth:r,paneHeight:n,darkMode:u=!1,selected:o=!1,onSelect:c,onMove:f,timeToIndex:i,indexToTime:a,dataLength:y=0,compressedTimes:m})=>{const x=s.useRef(0),b=s.useRef({time1:0,time2:0}),d=s.useRef(t),F=s.useRef(i),k=s.useRef(a),R=s.useRef(m);s.useEffect(()=>{d.current=t,F.current=i,k.current=a,R.current=m},[t,i,a,m]);const p=s.useCallback(J=>{J.stopPropagation(),c==null||c(e.id)},[e.id,c]),M=s.useCallback(J=>{const Q=F.current;if(!Q)return;const le=R.current;return _e(J,le,Q)??Q(J)},[]),$=s.useCallback((J,Q)=>{const le=d.current,G=F.current,se=k.current;if(!!(G&&se)){const P=M(J);if(P===void 0)return J;const ee=le(P)+Q;if(!le.invert)return J;const ie=le.invert(ee),te=ie instanceof Date?ie.getTime():ie;return se(Math.round(te))}const C=le(J)+Q;if(!le.invert)return J;const T=le.invert(C);return T instanceof Date?T.getTime():T},[M]),D=s.useCallback(J=>{x.current=J.clientX,b.current={time1:e.time1,time2:e.time2}},[e.time1,e.time2]),w=s.useCallback(J=>{const Q=J.clientX-x.current,le=b.current,G=$(le.time1,Q),se=$(le.time2,Q);Number.isFinite(G)&&Number.isFinite(se)&&(f==null||f(e.id,{time1:G,time2:se}))},[e.id,f,$]),h=s.useCallback(J=>Q=>{const le=Q.clientX-x.current,G=b.current,se=d.current,re=F.current,U=k.current,C=!!(re&&U),T=C?M(G.time1):G.time1,Z=C?M(G.time2):G.time2,P=T!==void 0&&Z!==void 0?se(T)<=se(Z):G.time1<=G.time2;if(J==="left"){const ee=P?G.time1:G.time2,ie=$(ee,le);Number.isFinite(ie)&&(f==null||f(e.id,P?{time1:ie}:{time2:ie}))}else{const ee=P?G.time2:G.time1,ie=$(ee,le);Number.isFinite(ie)&&(f==null||f(e.id,P?{time2:ie}:{time1:ie}))}},[e.id,f,$,M]),A=s.useRef(w),I=s.useCallback(J=>{A.current(J)},[]),{isDragging:N,handleMouseDown:j}=Fe({onDragStart:D,onDragMove:I}),S=s.useCallback(J=>{A.current=w,j(J)},[w,j]),V=s.useCallback(J=>Q=>{Q.stopPropagation(),A.current=h(J),j(Q)},[h,j]),v=J=>{if(i&&a&&y>0)return _e(J,m,i);if(i)return i(J)},z=v(e.time1),X=v(e.time2);if(i&&(z===void 0||X===void 0))return null;const K=z??e.time1,E=X??e.time2,q=t(K),_=t(E);if(!Number.isFinite(q)||!Number.isFinite(_))return null;const L=Math.min(q,_),O=Math.max(q,_),Y=O-L;if(O<-50||L>r+50)return null;const ne=es[e.lineStyle]||void 0,g=u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",W=u?"#e2e8f0":"#1f2937",ge=6,H=40;return l.jsxs("g",{className:"timerange-annotation",onClick:p,style:{cursor:N?"grabbing":"pointer"},children:[o&&l.jsx("rect",{x:L-3,y:-3,width:Y+6,height:n+6,fill:"none",stroke:g,strokeWidth:3}),l.jsx("rect",{x:L-Be,y:0,width:Y+Be*2,height:n,fill:"transparent",stroke:"transparent",strokeWidth:Be,style:{cursor:"pointer"}}),l.jsx("rect",{x:L,y:0,width:Y,height:n,fill:e.color,fillOpacity:e.fillOpacity,onMouseDown:o?S:void 0,style:{cursor:o?N?"grabbing":"move":"pointer"}}),l.jsx("line",{x1:L,x2:L,y1:0,y2:n,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:ne}),l.jsx("line",{x1:O,x2:O,y1:0,y2:n,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:ne}),e.label&&l.jsxs("g",{children:[l.jsx("rect",{x:L+4,y:4,width:Math.max(40,e.label.length*7+12),height:18,fill:e.color,fillOpacity:.85,rx:3}),l.jsx("text",{x:L+10,y:16,fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:e.label})]}),o&&l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:L-ge/2,y:n/2-H/2,width:ge,height:H,fill:W,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:1.5,onMouseDown:V("left"),style:{cursor:"ew-resize"}}),l.jsx("line",{x1:L-1,x2:L-1,y1:n/2-6,y2:n/2+6,stroke:e.color,strokeWidth:1,style:{pointerEvents:"none"}}),l.jsx("line",{x1:L+1,x2:L+1,y1:n/2-6,y2:n/2+6,stroke:e.color,strokeWidth:1,style:{pointerEvents:"none"}}),l.jsx("rect",{x:O-ge/2,y:n/2-H/2,width:ge,height:H,fill:W,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:1.5,onMouseDown:V("right"),style:{cursor:"ew-resize"}}),l.jsx("line",{x1:O-1,x2:O-1,y1:n/2-6,y2:n/2+6,stroke:e.color,strokeWidth:1,style:{pointerEvents:"none"}}),l.jsx("line",{x1:O+1,x2:O+1,y1:n/2-6,y2:n/2+6,stroke:e.color,strokeWidth:1,style:{pointerEvents:"none"}})]})]})},ts={solid:void 0,dashed:"8 4",dotted:"2 4"},rs=(e,t,r,n,u=12,o=Math.PI/6)=>{const c=Math.atan2(n-t,r-e),f=r-u*Math.cos(c-o),i=n-u*Math.sin(c-o),a=r-u*Math.cos(c+o),y=n-u*Math.sin(c+o);return`${f},${i} ${r},${n} ${a},${y}`},hr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,onDoubleClick:a,timeToIndex:y,indexToTime:m,dataLength:x=0,compressedTimes:b})=>{const d=s.useRef({x:0,y:0}),F=s.useRef({time1:0,price1:0,time2:0,price2:0}),k=s.useRef("body"),R=s.useRef(t),p=s.useRef(r),M=s.useRef(y),$=s.useRef(m),D=s.useRef(b);s.useEffect(()=>{R.current=t,p.current=r,M.current=y,$.current=m,D.current=b},[t,r,y,m,b]);const w=s.useCallback(te=>{te.stopPropagation(),f==null||f(e.id)},[e.id,f]),h=s.useCallback(te=>{te.stopPropagation(),a==null||a(e.id)},[e.id,a]),A=s.useCallback((te,ce,De,Ce)=>{const je=R.current,pe=p.current,be=M.current,we=$.current,Me=D.current,xe=be&&we?_e(te,Me,be)??te:te,Pe=je(xe)+De,Ge=pe.scale(ce)+Ce;let Re=te;if(je.invert){const Ve=je.invert(Pe),Ie=Ve instanceof Date?Ve.getTime():Ve;Re=we?we(Math.round(Ie)):Ie}const ze=pe.invert(Ge);return{time:Re,price:ze}},[]),I=s.useCallback(te=>{d.current={x:te.clientX,y:te.clientY},F.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),N=s.useCallback(te=>{const ce=te.clientX-d.current.x,De=te.clientY-d.current.y,Ce=F.current,je=k.current;if(je==="point1"){const{time:pe,price:be}=A(Ce.time1,Ce.price1,ce,De);Number.isFinite(pe)&&Number.isFinite(be)&&(i==null||i(e.id,{time1:pe,price1:be}))}else if(je==="point2"){const{time:pe,price:be}=A(Ce.time2,Ce.price2,ce,De);Number.isFinite(pe)&&Number.isFinite(be)&&(i==null||i(e.id,{time2:pe,price2:be}))}else{const pe=A(Ce.time1,Ce.price1,ce,De),be=A(Ce.time2,Ce.price2,ce,De);Number.isFinite(pe.time)&&Number.isFinite(pe.price)&&Number.isFinite(be.time)&&Number.isFinite(be.price)&&(i==null||i(e.id,{time1:pe.time,price1:pe.price,time2:be.time,price2:be.price}))}},[e.id,i,A]),{isDragging:j,handleMouseDown:S}=Fe({onDragStart:I,onDragMove:N}),V=s.useCallback(te=>ce=>{ce.stopPropagation(),k.current=te,S(ce)},[S]),v=te=>{if(y&&m&&x>0)return _e(te,b,y);if(y)return y(te)},z=v(e.time1),X=v(e.time2);if(y&&(z===void 0||X===void 0))return null;const K=t(z??e.time1),E=r.scale(e.price1),q=t(X??e.time2),_=r.scale(e.price2);if(!Number.isFinite(K)||!Number.isFinite(E)||!Number.isFinite(q)||!Number.isFinite(_))return null;const L=100;if(K<-L&&q<-L||K>n+L&&q>n+L||E<-L&&_<-L||E>u+L&&_>u+L)return null;const Y=ts[e.lineStyle]||void 0,ne=o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",g=o?"#e2e8f0":"#1f2937",W=6,ge=e.fontSize*1.3,H=e.text||"",J=H.split(`
|
|
4
|
+
`),Q=J.length,le=Math.max(...J.map(te=>te.length),1),G=Math.max(24,le*(e.fontSize*.6)+W*2),se=Q===1?e.fontSize+W*2:Q*ge+W*2,re=o?"rgba(30, 41, 59, 0.95)":"rgba(255, 255, 255, 0.95)",U=c?o?"#63b3ed":"#3b82f6":e.color,C=q-K,T=_-E,Z=Math.sqrt(C*C+T*T);let P=K,ee=E;if(Z>0&&H){const te=G/2,ce=se/2,De=Math.abs(C)>0?te/Math.abs(C):Number.POSITIVE_INFINITY,Ce=Math.abs(T)>0?ce/Math.abs(T):Number.POSITIVE_INFINITY,je=Math.min(De,Ce),pe=Math.min(Z*je,Z*.4);P=K+C/Z*pe,ee=E+T/Z*pe}const ie=rs(P,ee,q,_,10+e.lineWidth*2);return l.jsxs("g",{className:"arrow-annotation",onClick:w,onDoubleClick:h,style:{cursor:j?"grabbing":"pointer"},children:[c&&l.jsx("line",{x1:P,y1:ee,x2:q,y2:_,stroke:ne,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:K,y1:E,x2:q,y2:_,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:P,y1:ee,x2:q,y2:_,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:Y,strokeLinecap:"round",onMouseDown:c?V("body"):void 0,style:{cursor:c?j?"grabbing":"move":"pointer"}}),l.jsx("polyline",{points:ie,fill:"none",stroke:e.color,strokeWidth:e.lineWidth+.5,strokeLinejoin:"round",strokeLinecap:"round",style:{pointerEvents:"none"}}),H&&l.jsxs("g",{children:[c&&l.jsx("rect",{x:K-G/2-3,y:E-se/2-3,width:G+6,height:se+6,fill:"none",stroke:ne,strokeWidth:3,rx:6}),l.jsx("rect",{x:K-G/2,y:E-se/2,width:G,height:se,fill:re,stroke:U,strokeWidth:1,rx:4,onMouseDown:c?V("point1"):void 0,style:{cursor:c?j?"grabbing":"move":"pointer"}}),l.jsx("text",{x:K,textAnchor:"middle",fontSize:e.fontSize,fill:e.color,fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:J.map((te,ce)=>l.jsx("tspan",{x:K,y:E-se/2+W+ge*(ce+.7),children:te},ce))})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:K,cy:E-se/2-8,r:Xe,fill:g,stroke:e.color,strokeWidth:1.5,onMouseDown:V("point1"),style:{cursor:"move"}}),l.jsx("circle",{cx:q,cy:_,r:Xe,fill:g,stroke:e.color,strokeWidth:1.5,onMouseDown:V("point2"),style:{cursor:"move"}})]})]})},ss={solid:void 0,dashed:"8 4",dotted:"2 4"},It=(e,t,r,n,u,o,c,f)=>{let i=e,a=t,y=r,m=n;const x=r-e,b=n-t;if(x===0&&b===0)return{ex1:i,ey1:a,ex2:y,ey2:m};if(x===0)return c&&(a=t<n?0:o),f&&(m=n>t?o:0),{ex1:i,ey1:a,ex2:y,ey2:m};const d=b/x,F=t-d*e;if(c){const R=(e<r?-1:1)<0?0:u;if(d===0)i=R,a=t;else{const p=d*R+F;p>=0&&p<=o?(i=R,a=p):p<0?(i=-F/d,a=0):(i=(o-F)/d,a=o)}}if(f){const R=(r>e?1:-1)>0?u:0;if(d===0)y=R,m=n;else{const p=d*R+F;p>=0&&p<=o?(y=R,m=p):p<0?(y=-F/d,m=0):(y=(o-F)/d,m=o)}}return{ex1:i,ey1:a,ex2:y,ey2:m}},mr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x})=>{const b=s.useRef({x:0,y:0}),d=s.useRef({time1:0,price1:0,time2:0,price2:0,priceOffset:0}),F=s.useRef(t),k=s.useRef(r),R=s.useRef(a),p=s.useRef(y),M=s.useRef(x),$=s.useRef(m);s.useEffect(()=>{F.current=t,k.current=r,R.current=a,p.current=y,M.current=x,$.current=m},[t,r,a,y,x,m]);const D=s.useCallback(Z=>{Z.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((Z,P,ee,ie)=>{const te=F.current,ce=k.current,De=R.current,Ce=p.current,je=M.current,pe=$.current,be=De&&Ce&&pe>0?_e(Z,je,De)??Z:Z,we=te(be)+ee,Me=ce.scale(P)+ie;let xe=Z;if(te.invert){const Ge=te.invert(we),Re=Ge instanceof Date?Ge.getTime():Ge;xe=Ce?Ce(Math.round(Re)):Re}const Pe=ce.invert(Me);return{time:Number.isFinite(xe)?xe:Z,price:Number.isFinite(Pe)?Pe:P}},[]),h=s.useCallback(Z=>{b.current={x:Z.clientX,y:Z.clientY},d.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2,priceOffset:e.priceOffset}},[e.time1,e.price1,e.time2,e.price2,e.priceOffset]),A=s.useCallback(Z=>{const P=Z.clientX-b.current.x,ee=Z.clientY-b.current.y,{time:ie,price:te}=w(d.current.time1,d.current.price1,P,ee);i==null||i(e.id,{time1:ie,price1:te})},[e.id,i,w]),{isDragging:I,handleMouseDown:N}=Fe({onDragStart:h,onDragMove:A}),j=s.useCallback(Z=>{const P=Z.clientX-b.current.x,ee=Z.clientY-b.current.y,{time:ie,price:te}=w(d.current.time2,d.current.price2,P,ee);i==null||i(e.id,{time2:ie,price2:te})},[e.id,i,w]),{isDragging:S,handleMouseDown:V}=Fe({onDragStart:h,onDragMove:j}),v=s.useCallback(Z=>{const P=Z.clientY-b.current.y,ee=k.current,ie=d.current.price1+d.current.priceOffset,te=ee.scale(ie),ce=ee.invert(te+P);if(Number.isFinite(ce)){const De=ce-d.current.price1;i==null||i(e.id,{priceOffset:De})}},[e.id,i]),{isDragging:z,handleMouseDown:X}=Fe({onDragStart:h,onDragMove:v}),K=s.useCallback(Z=>{const P=Z.clientX-b.current.x,ee=Z.clientY-b.current.y,ie=w(d.current.time1,d.current.price1,P,ee),te=w(d.current.time2,d.current.price2,P,ee);i==null||i(e.id,{time1:ie.time,price1:ie.price,time2:te.time,price2:te.price})},[e.id,i,w]),{isDragging:E,handleMouseDown:q}=Fe({onDragStart:h,onDragMove:K}),_=I||S||z||E,L=tt(e.time1,t,a,y,m,x),O=tt(e.time2,t,a,y,m,x);if(L===void 0||O===void 0)return null;const Y=r.scale(e.price1),ne=r.scale(e.price2);if(!Number.isFinite(Y)||!Number.isFinite(ne))return null;const g=r.scale(e.price1+e.priceOffset),W=r.scale(e.price2+e.priceOffset);if(!Number.isFinite(g)||!Number.isFinite(W)||L<-50&&O<-50||L>n+50&&O>n+50)return null;const H=It(L,Y,O,ne,n,u,e.extendLeft,e.extendRight),J=It(L,g,O,W,n,u,e.extendLeft,e.extendRight),Q=ss[e.lineStyle]||void 0,le=c?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",G=o?"#e2e8f0":"#1f2937",se=e.label||"",re=(L+O)/2,U=(Y+ne)/2,C=(g+W)/2,T=`${H.ex1},${H.ey1} ${H.ex2},${H.ey2} ${J.ex2},${J.ey2} ${J.ex1},${J.ey1}`;return l.jsxs("g",{className:"channel-annotation",onClick:D,style:{cursor:_?"grabbing":"pointer"},children:[l.jsx("polygon",{points:T,fill:e.color,fillOpacity:e.fillOpacity,stroke:"none",onMouseDown:c?q:void 0,style:{cursor:c?"grab":"pointer"}}),c&&l.jsxs(l.Fragment,{children:[l.jsx("line",{x1:H.ex1,y1:H.ey1,x2:H.ex2,y2:H.ey2,stroke:le,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:J.ex1,y1:J.ey1,x2:J.ex2,y2:J.ey2,stroke:le,strokeWidth:e.lineWidth+6,strokeLinecap:"round"})]}),l.jsx("line",{x1:H.ex1,y1:H.ey1,x2:H.ex2,y2:H.ey2,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:J.ex1,y1:J.ey1,x2:J.ex2,y2:J.ey2,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:H.ex1,y1:H.ey1,x2:H.ex2,y2:H.ey2,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:Q,strokeLinecap:"round"}),l.jsx("line",{x1:J.ex1,y1:J.ey1,x2:J.ex2,y2:J.ey2,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:Q,strokeLinecap:"round"}),se&&l.jsxs("g",{children:[l.jsx("rect",{x:re-se.length*3.5-8,y:U-10,width:Math.max(30,se.length*7+16),height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:re,y:U,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:se})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:L,cy:Y,r:Xe,fill:G,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:N,style:{cursor:"move"}}),l.jsx("circle",{cx:O,cy:ne,r:Xe,fill:G,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:V,style:{cursor:"move"}}),l.jsx("circle",{cx:re,cy:C,r:Xe,fill:e.color,fillOpacity:.8,stroke:G,strokeWidth:2,onMouseDown:X,style:{cursor:"ns-resize"}}),l.jsx("circle",{cx:re,cy:U,r:at,fill:e.color,fillOpacity:.6,onMouseDown:q,style:{cursor:"grab"}})]})]})},yr=[0,.236,.382,.5,.618,.786,1],gr=[1.272,1.618,2,2.618],is={solid:void 0,dashed:"8 4",dotted:"2 4"},xr=(e,t,r)=>{if(!r)return;const n=r(e);if(n!==void 0)return n;if(!t||!t.length)return;const u=nt(t,e);if(Number.isFinite(u))return r(u)},Ut=(e,t,r,n,u,o)=>{let c;if(r&&n&&u>0?c=xr(e,o,r):r&&(c=r(e)),r&&c===void 0)return;const i=t(c??e);return Number.isFinite(i)?i:void 0},cs=e=>{const t=e*100;return t%1===0?`${t}%`:`${t.toFixed(1)}%`},ls=e=>Math.abs(e)<1?e.toPrecision(4):Math.abs(e)<10?e.toFixed(4):e.toFixed(2),br=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x})=>{const[b,d]=s.useState(null),F=s.useRef({x:0,y:0}),k=s.useRef({time1:0,price1:0,time2:0,price2:0}),R=s.useRef(t),p=s.useRef(r),M=s.useRef(a),$=s.useRef(y),D=s.useRef(x),w=s.useRef(m);s.useEffect(()=>{R.current=t,p.current=r,M.current=a,$.current=y,D.current=x,w.current=m},[t,r,a,y,x,m]);const h=s.useCallback(U=>{U.stopPropagation(),f==null||f(e.id)},[e.id,f]),A=s.useCallback((U,C,T,Z)=>{const P=R.current,ee=p.current,ie=M.current,te=$.current,ce=D.current,De=w.current,Ce=ie&&te&&De>0?xr(U,ce,ie)??U:U,je=P(Ce)+T,pe=ee.scale(C)+Z;let be=U;if(P.invert){const Me=P.invert(je),xe=Me instanceof Date?Me.getTime():Me;be=te?te(Math.round(xe)):xe}const we=ee.invert(pe);return{time:Number.isFinite(be)?be:U,price:Number.isFinite(we)?we:C}},[]),I=s.useCallback(U=>{d(1),F.current={x:U.clientX,y:U.clientY},k.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),N=s.useCallback(U=>{const C=U.clientX-F.current.x,T=U.clientY-F.current.y,{time:Z,price:P}=A(k.current.time1,k.current.price1,C,T);i==null||i(e.id,{time1:Z,price1:P})},[e.id,i,A]),{isDragging:j,handleMouseDown:S}=Fe({onDragStart:I,onDragMove:N,onDragEnd:()=>d(null)}),V=s.useCallback(U=>{d(2),F.current={x:U.clientX,y:U.clientY},k.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),v=s.useCallback(U=>{const C=U.clientX-F.current.x,T=U.clientY-F.current.y,{time:Z,price:P}=A(k.current.time2,k.current.price2,C,T);i==null||i(e.id,{time2:Z,price2:P})},[e.id,i,A]),{isDragging:z,handleMouseDown:X}=Fe({onDragStart:V,onDragMove:v,onDragEnd:()=>d(null)}),K=s.useCallback(U=>{d("whole"),F.current={x:U.clientX,y:U.clientY},k.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),E=s.useCallback(U=>{const C=U.clientX-F.current.x,T=U.clientY-F.current.y,Z=A(k.current.time1,k.current.price1,C,T),P=A(k.current.time2,k.current.price2,C,T);i==null||i(e.id,{time1:Z.time,price1:Z.price,time2:P.time,price2:P.price})},[e.id,i,A]),{isDragging:q,handleMouseDown:_}=Fe({onDragStart:K,onDragMove:E,onDragEnd:()=>d(null)}),L=j||z||q,O=Ut(e.time1,t,a,y,m,x),Y=Ut(e.time2,t,a,y,m,x),ne=s.useMemo(()=>{const U=[...e.levels??[...yr]];if(e.showExtensions)for(const C of gr)U.includes(C)||U.push(C);return U.sort((C,T)=>C-T),U},[e.levels,e.showExtensions]);if(O===void 0||Y===void 0)return null;const g=r.scale(e.price1),W=r.scale(e.price2);if(!Number.isFinite(g)||!Number.isFinite(W))return null;const ge=e.price2-e.price1,H=Math.min(O,Y),J=e.extendRight?n:Math.max(O,Y),Q=J-H;if(Q<1)return null;const le=is[e.lineStyle]||void 0,G=c?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",se=o?"#e2e8f0":"#1f2937",re=ne.map(U=>{const C=e.price1+ge*U;return{ratio:U,price:C,y:r.scale(C)}});return l.jsxs("g",{className:"fib-retracement-annotation",onClick:h,style:{cursor:L?"grabbing":"pointer"},children:[e.fillOpacity>0&&re.map((U,C)=>{if(C===0)return null;const T=re[C-1],Z=Math.min(U.y,T.y),ee=Math.max(U.y,T.y)-Z;return ee<.5?null:l.jsx("rect",{x:H,y:Z,width:Q,height:ee,fill:e.color,fillOpacity:e.fillOpacity*(C%2===0?1:.5),stroke:"none",onMouseDown:c?_:void 0,style:{cursor:c?"grab":"pointer"}},`fill-${U.ratio}`)}),c&&re.map(({ratio:U,y:C})=>l.jsx("line",{x1:H,x2:J,y1:C,y2:C,stroke:G,strokeWidth:e.lineWidth+4,strokeLinecap:"round"},`glow-${U}`)),re.map(({ratio:U,price:C,y:T})=>{if(T<-50||T>u+50)return null;const Z=cs(U),P=ls(C),ee=`${Z} (${P})`,ie=Math.max(80,ee.length*6+16),te=U===0||U===.5||U===.618||U===1,ce=te?1:.7;return l.jsxs("g",{children:[l.jsx("line",{x1:H,x2:J,y1:T,y2:T,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?_:void 0}),l.jsx("line",{x1:H,x2:J,y1:T,y2:T,stroke:e.color,strokeWidth:te?e.lineWidth:e.lineWidth*.7,strokeDasharray:te?void 0:le,strokeLinecap:"round",opacity:ce}),l.jsxs("g",{children:[l.jsx("rect",{x:J-ie-4,y:T-9,width:ie,height:18,fill:e.color,fillOpacity:te?.85:.65,rx:3}),l.jsx("text",{x:J-ie/2-4,y:T,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:te?600:400,style:{pointerEvents:"none",userSelect:"none"},children:ee})]})]},`level-${U}`)}),l.jsx("line",{x1:O,y1:g,x2:O,y2:W,stroke:e.color,strokeWidth:.5,strokeDasharray:"4 3",opacity:.5}),l.jsx("line",{x1:Y,y1:g,x2:Y,y2:W,stroke:e.color,strokeWidth:.5,strokeDasharray:"4 3",opacity:.5}),l.jsx("line",{x1:O,y1:g,x2:Y,y2:W,stroke:e.color,strokeWidth:1,strokeDasharray:"6 3",opacity:.6}),e.label&&l.jsxs("g",{children:[l.jsx("rect",{x:H+4,y:Math.min(g,W)-20,width:Math.max(40,e.label.length*7+12),height:16,fill:e.color,fillOpacity:.85,rx:3}),l.jsx("text",{x:H+4+Math.max(40,e.label.length*7+12)/2,y:Math.min(g,W)-12,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:600,style:{pointerEvents:"none",userSelect:"none"},children:e.label})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:O,cy:g,r:Xe,fill:se,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:S,style:{cursor:"move"}}),l.jsx("circle",{cx:Y,cy:W,r:Xe,fill:se,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:X,style:{cursor:"move"}}),l.jsx("circle",{cx:(O+Y)/2,cy:(g+W)/2,r:at,fill:e.color,fillOpacity:.6,onMouseDown:_,style:{cursor:"grab"}})]})]})},ns=e=>{if(!e)return 864e5;const t=e.toLowerCase();return t.includes("1m")&&!t.includes("1mo")?6e4:t.includes("5m")?3e5:t.includes("15m")?9e5:t.includes("30m")?18e5:t.includes("hour")||t==="1h"||t==="60m"?36e5:t.includes("4h")?144e5:t.includes("week")?6048e5:t.includes("month")||t.includes("1mo")?2592e6:864e5},os=e=>{const t=Math.abs(e),r=Math.floor(t/6e4),n=Math.floor(t/36e5),u=Math.floor(t/864e5);if(u>0){const o=n-u*24;return o>0&&u<7?`${u}d ${o}h`:`${u}d`}if(n>0){const o=r-n*60;return o>0?`${n}h ${o}m`:`${n}h`}return`${r}m`},St=e=>Math.abs(e)<.01?e.toPrecision(3):Math.abs(e)<1?e.toPrecision(4):Math.abs(e)<10?e.toFixed(4):Math.abs(e)<1e3?e.toFixed(2):e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),us=e=>`${e>=0?"+":""}${e.toFixed(2)}%`,pr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,currentTimeframe:a,timeToIndex:y,indexToTime:m,dataLength:x=0,compressedTimes:b})=>{const d=s.useRef({x:0,y:0}),F=s.useRef({time1:0,price1:0,time2:0,price2:0}),k=s.useRef(t),R=s.useRef(r),p=s.useRef(y),M=s.useRef(m),$=s.useRef(b),D=s.useRef(x);s.useEffect(()=>{k.current=t,R.current=r,p.current=y,M.current=m,$.current=b,D.current=x},[t,r,y,m,b,x]);const w=s.useCallback(Re=>{Re.stopPropagation(),f==null||f(e.id)},[e.id,f]),h=s.useCallback((Re,ze,Ve,Ie)=>{const qe=k.current,st=R.current,rt=p.current,ot=M.current,pt=$.current,ht=D.current,mt=!!(rt&&ot&&ht>0)?_e(Re,pt,rt):null,wt=qe(mt??Re)+Ve,kt=st.scale(ze)+Ie;let ut=Re;if(qe.invert){const gt=qe.invert(wt),Dt=gt instanceof Date?gt.getTime():gt;ut=rt&&ot&&ht>0?ot(Math.round(Dt)):Dt}const yt=st.invert(kt);return{time:Number.isFinite(ut)?ut:Re,price:Number.isFinite(yt)?yt:ze}},[]),A=s.useCallback(Re=>{d.current={x:Re.clientX,y:Re.clientY},F.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2}},[e.time1,e.price1,e.time2,e.price2]),I=s.useCallback(Re=>{const ze=Re.clientX-d.current.x,Ve=Re.clientY-d.current.y,{time:Ie,price:qe}=h(F.current.time1,F.current.price1,ze,Ve);i==null||i(e.id,{time1:Ie,price1:qe})},[e.id,i,h]),{isDragging:N,handleMouseDown:j}=Fe({onDragStart:A,onDragMove:I}),S=s.useCallback(Re=>{const ze=Re.clientX-d.current.x,Ve=Re.clientY-d.current.y,{time:Ie,price:qe}=h(F.current.time2,F.current.price2,ze,Ve);i==null||i(e.id,{time2:Ie,price2:qe})},[e.id,i,h]),{isDragging:V,handleMouseDown:v}=Fe({onDragStart:A,onDragMove:S}),z=s.useCallback(Re=>{const ze=Re.clientX-d.current.x,Ve=Re.clientY-d.current.y,Ie=h(F.current.time1,F.current.price1,ze,Ve),qe=h(F.current.time2,F.current.price2,ze,Ve);i==null||i(e.id,{time1:Ie.time,price1:Ie.price,time2:qe.time,price2:qe.price})},[e.id,i,h]),{isDragging:X,handleMouseDown:K}=Fe({onDragStart:A,onDragMove:z}),E=N||V||X,q=tt(e.time1,t,y,m,x,b),_=tt(e.time2,t,y,m,x,b),L=s.useMemo(()=>{const Re=e.price2-e.price1,ze=e.price1!==0?Re/e.price1*100:0,Ve=Math.abs(e.time2-e.time1),Ie=ns(a),qe=Math.max(1,Math.round(Ve/Ie)),st=os(Ve),rt=Re>=0;return{priceDiff:Re,pricePct:ze,timeDiffMs:Ve,barCount:qe,timeStr:st,isPositive:rt}},[e.price1,e.price2,e.time1,e.time2,a]);if(q===void 0||_===void 0)return null;const O=r.scale(e.price1),Y=r.scale(e.price2);if(!Number.isFinite(O)||!Number.isFinite(Y))return null;const{priceDiff:ne,pricePct:g,barCount:W,timeStr:ge,isPositive:H}=L,J=Math.min(q,_),Q=Math.max(q,_),le=Math.min(O,Y),G=Math.max(O,Y),se=Math.max(Q-J,1),re=Math.max(G-le,1),U=H?"rgba(34, 197, 94, 0.12)":"rgba(239, 68, 68, 0.12)",C=H?"#22c55e":"#ef4444",T=H?"#4ade80":"#f87171",Z=o?"rgba(23, 23, 23, 0.92)":"rgba(30, 30, 30, 0.92)",P=`${ne>=0?"+":""}${St(ne)}`,ee=us(g),ie=`${W} bar${W!==1?"s":""}`,te=`${P} (${ee})`,ce=`${ie} • ${ge}`,De=11,Ce=16,je=Math.max(te.length,ce.length)*6.5+24,pe=Ce*2+14,be=(J+Q)/2,we=(le+G)/2;let Me=be-je/2,xe=we-pe/2;Me<4&&(Me=4),Me+je>n-4&&(Me=n-je-4),xe<4&&(xe=4),xe+pe>u-4&&(xe=u-pe-4);const Pe=c?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",Ge=c?o?"#63b3ed":"#3b82f6":C;return l.jsxs("g",{className:"measure-annotation",onClick:w,style:{cursor:E?"grabbing":"pointer"},children:[c&&l.jsx("rect",{x:J-3,y:le-3,width:se+6,height:re+6,fill:"none",stroke:Pe,strokeWidth:4,strokeDasharray:"6 3",opacity:.8}),c&&l.jsx("line",{x1:q,y1:O,x2:_,y2:Y,stroke:Pe,strokeWidth:7,opacity:.6}),l.jsx("rect",{x:J,y:le,width:se,height:re,fill:"transparent",style:{cursor:E?"grabbing":"grab"},onMouseDown:K}),l.jsx("rect",{x:J,y:le,width:se,height:re,fill:U,stroke:C,strokeWidth:1,strokeDasharray:"6 3",style:{pointerEvents:"none"}}),l.jsx("line",{x1:q,y1:O,x2:_,y2:Y,stroke:C,strokeWidth:1.5,strokeDasharray:"4 3",opacity:.8,style:{pointerEvents:"none"}}),l.jsx("circle",{cx:q,cy:O,r:c?Xe:at,fill:Ge,fillOpacity:.9,stroke:c?o?"#1e293b":"#f8fafc":"none",strokeWidth:c?2:0,style:{cursor:N?"grabbing":"grab"},onMouseDown:j}),l.jsx("circle",{cx:_,cy:Y,r:c?Xe:at,fill:Ge,fillOpacity:.9,stroke:c?o?"#1e293b":"#f8fafc":"none",strokeWidth:c?2:0,style:{cursor:V?"grabbing":"grab"},onMouseDown:v}),l.jsx("line",{x1:J,y1:O,x2:Q,y2:O,stroke:C,strokeWidth:.5,strokeDasharray:"3 3",opacity:.4,style:{pointerEvents:"none"}}),l.jsx("line",{x1:J,y1:Y,x2:Q,y2:Y,stroke:C,strokeWidth:.5,strokeDasharray:"3 3",opacity:.4,style:{pointerEvents:"none"}}),l.jsx("line",{x1:q,y1:le,x2:q,y2:G,stroke:C,strokeWidth:.5,strokeDasharray:"3 3",opacity:.4,style:{pointerEvents:"none"}}),l.jsx("line",{x1:_,y1:le,x2:_,y2:G,stroke:C,strokeWidth:.5,strokeDasharray:"3 3",opacity:.4,style:{pointerEvents:"none"}}),l.jsxs("g",{style:{pointerEvents:"none"},children:[l.jsx("rect",{x:Me,y:xe,width:je,height:pe,fill:Z,rx:6,stroke:C,strokeWidth:1,strokeOpacity:.6}),l.jsx("text",{x:Me+je/2,y:xe+12+Ce*0,dy:"0.35em",textAnchor:"middle",fontSize:De,fontWeight:700,fontFamily:"monospace",fill:T,style:{userSelect:"none"},children:te}),l.jsx("text",{x:Me+je/2,y:xe+12+Ce*1,dy:"0.35em",textAnchor:"middle",fontSize:De-1,fontWeight:400,fontFamily:"monospace",fill:o?"#a0a0a0":"#b0b0b0",style:{userSelect:"none"},children:ce})]}),l.jsxs("g",{style:{pointerEvents:"none"},children:[l.jsx("rect",{x:Q+4,y:O-9,width:70,height:18,fill:Z,rx:3,stroke:C,strokeWidth:.5,strokeOpacity:.4}),l.jsx("text",{x:Q+39,y:O,dy:"0.35em",textAnchor:"middle",fontSize:10,fontFamily:"monospace",fill:o?"#d0d0d0":"#e0e0e0",style:{userSelect:"none"},children:St(e.price1)})]}),l.jsxs("g",{style:{pointerEvents:"none"},children:[l.jsx("rect",{x:Q+4,y:Y-9,width:70,height:18,fill:Z,rx:3,stroke:C,strokeWidth:.5,strokeOpacity:.4}),l.jsx("text",{x:Q+39,y:Y,dy:"0.35em",textAnchor:"middle",fontSize:10,fontFamily:"monospace",fill:o?"#d0d0d0":"#e0e0e0",style:{userSelect:"none"},children:St(e.price2)})]})]})},as="M8 1.5a.5.5 0 0 1 .5.5v.54A4.002 4.002 0 0 1 12 6.5c0 1.57.39 2.8.87 3.66.24.43.46.72.62.89.08.09.13.13.15.15H2.36c.02-.02.07-.06.15-.15.16-.17.38-.46.62-.89C3.61 9.3 4 8.07 4 6.5A4.002 4.002 0 0 1 7.5 2.54V2a.5.5 0 0 1 .5-.5ZM6.5 13a1.5 1.5 0 0 0 3 0h-3Z",wr=({annotation:e,yScale:t,chartWidth:r,paneHeight:n,darkMode:u=!1,selected:o=!1,onSelect:c,onMove:f})=>{const i=s.useRef(0),a=s.useRef(0),y=s.useRef(t);s.useEffect(()=>{y.current=t},[t]);const m=s.useCallback(j=>{j.stopPropagation(),c==null||c(e.id)},[e.id,c]),x=s.useCallback(j=>{i.current=j.clientY,a.current=e.price},[e.price]),b=s.useCallback(j=>{const S=j.clientY-i.current,V=y.current,v=V.invert(V.scale(a.current)+S);Number.isFinite(v)&&(f==null||f(e.id,v))},[e.id,f]),{isDragging:d,handleMouseDown:F}=Fe({onDragStart:x,onDragMove:b}),k=t.scale(e.price);if(!Number.isFinite(k)||k<-20||k>n+20)return null;const R=Gr[e.lineStyle]??void 0,p=e.triggered,M=e.label??(e.showPrice?e.price.toFixed(2):""),D=Math.max(70,M.length*7+16+16+8),w=p?"#64748b":e.color,h=p?.5:1,A=o?u?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",I=u?"#e2e8f0":"#1f2937",N=e.direction==="above"?`28,${k-2} 32,${k-8} 36,${k-2}`:`28,${k+2} 32,${k+8} 36,${k+2}`;return l.jsxs("g",{className:"alert-line-annotation",onClick:m,style:{cursor:d?"grabbing":"pointer"},children:[o&&l.jsx("line",{x1:0,x2:r,y1:k,y2:k,stroke:A,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:0,x2:r,y1:k,y2:k,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:0,x2:r,y1:k,y2:k,stroke:w,strokeWidth:e.lineWidth,strokeDasharray:R,strokeLinecap:"round",opacity:h}),!p&&l.jsx("polygon",{points:N,fill:w,opacity:.8}),l.jsxs("g",{children:[l.jsx("rect",{x:r-D-8,y:k-12,width:D,height:24,fill:p?"#64748b":w,fillOpacity:.9,rx:4}),l.jsxs("g",{transform:`translate(${r-D-2}, ${k-8}) scale(${p?.85:1})`,children:[l.jsx("path",{d:as,fill:"white",opacity:p?.5:1}),p&&l.jsx("line",{x1:2,y1:14,x2:14,y2:2,stroke:"white",strokeWidth:1.5,opacity:.8})]}),M&&l.jsx("text",{x:r-D/2+4,y:k,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},opacity:p?.6:1,children:M})]}),o&&l.jsxs("g",{onMouseDown:F,style:{cursor:"ns-resize"},children:[l.jsx("rect",{x:Qe,y:k-$e/2,width:$e,height:$e,fill:I,fillOpacity:.9,rx:3,stroke:w,strokeWidth:2}),l.jsx("line",{x1:ft,x2:dt,y1:k-2,y2:k-2,stroke:w,strokeWidth:1.5}),l.jsx("line",{x1:ft,x2:dt,y1:k+2,y2:k+2,stroke:w,strokeWidth:1.5})]})]})},$t=(e,t,r,n)=>{if(r){let o=r(e);if(o===void 0&&n&&n.length>0){const f=nt(n,e);Number.isFinite(f)&&(o=r(f))}if(o===void 0)return;const c=t(o);return Number.isFinite(c)?c:void 0}const u=t(e);return Number.isFinite(u)?u:void 0},kr=({annotation:e,xScale:t,yScale:r,darkMode:n=!1,selected:u=!1,onSelect:o,onDoubleClick:c,onMove:f,timeToIndex:i,indexToTime:a,compressedTimes:y})=>{const m=s.useRef({x:0,y:0}),x=s.useRef([]),b=s.useRef(t),d=s.useRef(r);s.useEffect(()=>{b.current=t,d.current=r},[t,r]);const F=s.useCallback(I=>{I.stopPropagation(),o==null||o(e.id)},[e.id,o]),k=s.useCallback(I=>{I.stopPropagation(),c==null||c(e.id)},[e.id,c]),R=s.useMemo(()=>{const{points:I}=e;if(!I||I.length<2)return"";const N=[];for(let j=0;j<I.length;j++){const S=$t(I[j].t,t,i,y),V=r.scale(I[j].v);S===void 0||!Number.isFinite(V)||N.push(N.length===0?`M${S},${V}`:`L${S},${V}`)}return N.join(" ")},[e,t,r,i,y]),p=s.useMemo(()=>{const{points:I}=e;if(!I||I.length===0)return null;let N=1/0,j=-1/0,S=1/0,V=-1/0;for(const v of I){const z=$t(v.t,t,i,y),X=r.scale(v.v);z===void 0||!Number.isFinite(X)||(z<N&&(N=z),z>j&&(j=z),X<S&&(S=X),X>V&&(V=X))}return Number.isFinite(N)?{minX:N,maxX:j,minY:S,maxY:V}:null},[e,t,r,i,y]),M=s.useCallback(I=>{m.current={x:I.clientX,y:I.clientY},x.current=e.points.map(N=>({...N}))},[e.points]),$=s.useCallback(I=>{const N=I.clientX-m.current.x,j=I.clientY-m.current.y,S=d.current,V=b.current,v=x.current;if(!v.length)return;let z,X,K;for(const O of v){const Y=$t(O.t,V,i,y),ne=S.scale(O.v);if(Y!==void 0&&Number.isFinite(ne)){z=O,X=Y,K=ne;break}}if(!z||X===void 0||K===void 0)return;const E=S.invert(K+j);if(!Number.isFinite(E))return;const q=E-z.v;if(!Number.isFinite(q))return;let _=0;if(V.invert){const O=V.invert(X+N),Y=O instanceof Date?O.getTime():O;if(!Number.isFinite(Y))return;const ne=a?a(Math.round(Y)):Y;if(!Number.isFinite(ne))return;_=ne-z.t}const L=v.map(O=>({t:O.t+_,v:O.v+q}));f==null||f(e.id,{points:L})},[e.id,f,i,a,y]),{isDragging:D,handleMouseDown:w}=Fe({onDragStart:M,onDragMove:$});if(!R)return null;const h=u?n?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",A=n?"#e2e8f0":"#1f2937";return l.jsxs("g",{className:"brush-annotation",onClick:F,onDoubleClick:k,style:{cursor:D?"grabbing":"pointer"},children:[u&&l.jsx("path",{d:R,fill:"none",stroke:h,strokeWidth:e.lineWidth+6,strokeLinecap:"round",strokeLinejoin:"round"}),l.jsx("path",{d:R,fill:"none",stroke:"transparent",strokeWidth:Math.max(Ae,e.lineWidth+8),strokeLinecap:"round",strokeLinejoin:"round",style:{cursor:"pointer"}}),l.jsx("path",{d:R,fill:"none",stroke:e.color,strokeWidth:e.lineWidth,strokeLinecap:"round",strokeLinejoin:"round"}),u&&p&&l.jsxs("g",{onMouseDown:w,style:{cursor:"grab"},children:[l.jsx("rect",{x:(p.minX+p.maxX)/2-$e/2,y:p.minY-$e-4,width:$e,height:$e,fill:A,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:2}),l.jsx("text",{x:(p.minX+p.maxX)/2,y:p.minY-$e/2-4,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:e.color,style:{pointerEvents:"none",userSelect:"none"},children:"✥"})]})]})},qt=(e,t,r,n,u,o)=>{const c=r-e,f=n-t;if(c===0&&f===0)return{x:r,y:n};let i=1/0;return c>0?i=Math.min(i,(u-e)/c):c<0&&(i=Math.min(i,-e/c)),f>0?i=Math.min(i,(o-t)/f):f<0&&(i=Math.min(i,-t/f)),(!Number.isFinite(i)||i<0)&&(i=1),{x:e+c*i,y:t+f*i}},Dr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x})=>{const b=s.useRef({x:0,y:0}),d=s.useRef({time1:0,price1:0,time2:0,price2:0,time3:0,price3:0}),F=s.useRef(t),k=s.useRef(r),R=s.useRef(a),p=s.useRef(y),M=s.useRef(x),$=s.useRef(m);s.useEffect(()=>{F.current=t,k.current=r,R.current=a,p.current=y,M.current=x,$.current=m},[t,r,a,y,x,m]);const D=s.useCallback(P=>{P.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((P,ee,ie,te)=>{const ce=F.current,De=k.current,Ce=R.current,je=p.current,pe=M.current,be=$.current;let we;if(Ce&&je&&be>0){const Re=_e(P,pe,Ce);Re===void 0?we=P:we=Re}else we=P;const Me=ce(we)+ie,xe=De.scale(ee)+te;let Pe=P;if(ce.invert){const Re=ce.invert(Me),ze=Re instanceof Date?Re.getTime():Re;Pe=je?je(Math.round(ze)):ze}const Ge=De.invert(xe);return{time:Number.isFinite(Pe)?Pe:P,price:Number.isFinite(Ge)?Ge:ee}},[]),h=s.useCallback(P=>{b.current={x:P.clientX,y:P.clientY},d.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2,time3:e.time3,price3:e.price3}},[e.time1,e.price1,e.time2,e.price2,e.time3,e.price3]),A=s.useCallback(P=>{const ee=P.clientX-b.current.x,ie=P.clientY-b.current.y,{time:te,price:ce}=w(d.current.time1,d.current.price1,ee,ie);i==null||i(e.id,{time1:te,price1:ce})},[e.id,i,w]),{isDragging:I,handleMouseDown:N}=Fe({onDragStart:h,onDragMove:A}),j=s.useCallback(P=>{const ee=P.clientX-b.current.x,ie=P.clientY-b.current.y,{time:te,price:ce}=w(d.current.time2,d.current.price2,ee,ie);i==null||i(e.id,{time2:te,price2:ce})},[e.id,i,w]),{isDragging:S,handleMouseDown:V}=Fe({onDragStart:h,onDragMove:j}),v=s.useCallback(P=>{const ee=P.clientX-b.current.x,ie=P.clientY-b.current.y,{time:te,price:ce}=w(d.current.time3,d.current.price3,ee,ie);i==null||i(e.id,{time3:te,price3:ce})},[e.id,i,w]),{isDragging:z,handleMouseDown:X}=Fe({onDragStart:h,onDragMove:v}),K=s.useCallback(P=>{const ee=P.clientX-b.current.x,ie=P.clientY-b.current.y,te=w(d.current.time1,d.current.price1,ee,ie),ce=w(d.current.time2,d.current.price2,ee,ie),De=w(d.current.time3,d.current.price3,ee,ie);i==null||i(e.id,{time1:te.time,price1:te.price,time2:ce.time,price2:ce.price,time3:De.time,price3:De.price})},[e.id,i,w]),{isDragging:E,handleMouseDown:q}=Fe({onDragStart:h,onDragMove:K}),_=I||S||z||E,L=tt(e.time1,t,a,y,m,x),O=tt(e.time2,t,a,y,m,x),Y=tt(e.time3,t,a,y,m,x);if(L===void 0||O===void 0||Y===void 0)return null;const ne=r.scale(e.price1),g=r.scale(e.price2),W=r.scale(e.price3);if(!Number.isFinite(ne)||!Number.isFinite(g)||!Number.isFinite(W))return null;const ge=(O+Y)/2,H=(g+W)/2,J=ge-L,Q=H-ne,le=(P,ee,ie,te)=>{if(e.extendRight){const be=qt(P,ee,P+ie,ee+te,n,u);return{endX:be.x,endY:be.y}}const ce=qt(P,ee,P+ie,ee+te,n,u),De=Math.sqrt(ie*ie+te*te);if(De===0)return{endX:P,endY:ee};const Ce=Math.sqrt((ce.x-P)**2+(ce.y-ee)**2),pe=Math.min(Ce,De*2)/De;return{endX:P+ie*pe,endY:ee+te*pe}},G=le(L,ne,J,Q),se=le(O,g,J,Q),re=le(Y,W,J,Q),U=He[e.lineStyle]||void 0,C=c?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",T=o?"#e2e8f0":"#1f2937",Z=`${O},${g} ${se.endX},${se.endY} ${re.endX},${re.endY} ${Y},${W}`;return l.jsxs("g",{className:"pitchfork-annotation",onClick:D,style:{cursor:_?"grabbing":"pointer"},children:[l.jsx("polygon",{points:Z,fill:e.color,fillOpacity:e.fillOpacity,stroke:"none",onMouseDown:c?q:void 0,style:{cursor:c?"grab":"pointer"}}),c&&l.jsxs(l.Fragment,{children:[l.jsx("line",{x1:L,y1:ne,x2:G.endX,y2:G.endY,stroke:C,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:O,y1:g,x2:se.endX,y2:se.endY,stroke:C,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:Y,y1:W,x2:re.endX,y2:re.endY,stroke:C,strokeWidth:e.lineWidth+6,strokeLinecap:"round"})]}),l.jsx("line",{x1:L,y1:ne,x2:G.endX,y2:G.endY,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:O,y1:g,x2:se.endX,y2:se.endY,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:Y,y1:W,x2:re.endX,y2:re.endY,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:L,y1:ne,x2:O,y2:g,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:L,y1:ne,x2:Y,y2:W,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:L,y1:ne,x2:G.endX,y2:G.endY,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:U,strokeLinecap:"round"}),l.jsx("line",{x1:O,y1:g,x2:se.endX,y2:se.endY,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:U,strokeLinecap:"round"}),l.jsx("line",{x1:Y,y1:W,x2:re.endX,y2:re.endY,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:U,strokeLinecap:"round"}),l.jsx("line",{x1:L,y1:ne,x2:O,y2:g,stroke:e.color,strokeWidth:e.lineWidth*.75,strokeDasharray:"4 3",strokeLinecap:"round",opacity:.5}),l.jsx("line",{x1:L,y1:ne,x2:Y,y2:W,stroke:e.color,strokeWidth:e.lineWidth*.75,strokeDasharray:"4 3",strokeLinecap:"round",opacity:.5}),e.label&&l.jsxs("g",{children:[l.jsx("rect",{x:ge-e.label.length*3.5-8,y:H-10,width:Math.max(30,e.label.length*7+16),height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:ge,y:H,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:e.label})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:L,cy:ne,r:Xe,fill:T,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:N,style:{cursor:"move"}}),l.jsx("circle",{cx:O,cy:g,r:Xe,fill:T,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:V,style:{cursor:"move"}}),l.jsx("circle",{cx:Y,cy:W,r:Xe,fill:T,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:X,style:{cursor:"move"}}),l.jsx("circle",{cx:ge,cy:H,r:at,fill:e.color,fillOpacity:.6,onMouseDown:q,style:{cursor:"grab"}})]})]})},fs={solid:void 0,dashed:"8 4",dotted:"2 4"},ds={0:"0%",.236:"23.6%",.382:"38.2%",.5:"50%",.618:"61.8%",.786:"78.6%",1:"100%",1.272:"127.2%",1.618:"161.8%",2:"200%",2.618:"261.8%",3.618:"361.8%",4.236:"423.6%"},hs=e=>ds[e]??`${(e*100).toFixed(1)}%`,Gt=["rgba(139, 92, 246, 0.06)","rgba(59, 130, 246, 0.06)","rgba(6, 182, 212, 0.06)","rgba(34, 197, 94, 0.06)","rgba(234, 179, 8, 0.06)","rgba(249, 115, 22, 0.06)","rgba(239, 68, 68, 0.06)"],Xt=(e,t,r,n,u,o)=>{let c;if(r&&n&&u>0?c=_e(e,o,r):r&&(c=r(e)),r&&c===void 0)return;const i=t(c??e);return Number.isFinite(i)?i:void 0},jr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x})=>{const b=s.useRef({x:0,y:0}),d=s.useRef({time1:0,price1:0,time2:0,price2:0,time3:0,price3:0}),F=s.useRef(t),k=s.useRef(r),R=s.useRef(a),p=s.useRef(y),M=s.useRef(x),$=s.useRef(m);s.useEffect(()=>{F.current=t,k.current=r,R.current=a,p.current=y,M.current=x,$.current=m},[t,r,a,y,x,m]);const D=s.useCallback(C=>{C.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback((C,T,Z,P)=>{const ee=F.current,ie=k.current,te=R.current,ce=p.current,De=M.current,Ce=$.current,je=te&&ce&&Ce>0?_e(C,De,te)??C:C,pe=ee(je)+Z,be=ie.scale(T)+P;let we=C;if(ee.invert){const xe=ee.invert(pe),Pe=xe instanceof Date?xe.getTime():xe;we=ce?ce(Math.round(Pe)):Pe}const Me=ie.invert(be);return{time:Number.isFinite(we)?we:C,price:Number.isFinite(Me)?Me:T}},[]),h=s.useCallback(C=>{b.current={x:C.clientX,y:C.clientY},d.current={time1:e.time1,price1:e.price1,time2:e.time2,price2:e.price2,time3:e.time3,price3:e.price3}},[e.time1,e.price1,e.time2,e.price2,e.time3,e.price3]),A=s.useCallback(C=>{const T=C.clientX-b.current.x,Z=C.clientY-b.current.y,{time:P,price:ee}=w(d.current.time1,d.current.price1,T,Z);i==null||i(e.id,{time1:P,price1:ee})},[e.id,i,w]),{isDragging:I,handleMouseDown:N}=Fe({onDragStart:h,onDragMove:A}),j=s.useCallback(C=>{const T=C.clientX-b.current.x,Z=C.clientY-b.current.y,{time:P,price:ee}=w(d.current.time2,d.current.price2,T,Z);i==null||i(e.id,{time2:P,price2:ee})},[e.id,i,w]),{isDragging:S,handleMouseDown:V}=Fe({onDragStart:h,onDragMove:j}),v=s.useCallback(C=>{const T=C.clientX-b.current.x,Z=C.clientY-b.current.y,{time:P,price:ee}=w(d.current.time3,d.current.price3,T,Z);i==null||i(e.id,{time3:P,price3:ee})},[e.id,i,w]),{isDragging:z,handleMouseDown:X}=Fe({onDragStart:h,onDragMove:v}),K=s.useCallback(C=>{const T=C.clientX-b.current.x,Z=C.clientY-b.current.y,P=w(d.current.time1,d.current.price1,T,Z),ee=w(d.current.time2,d.current.price2,T,Z),ie=w(d.current.time3,d.current.price3,T,Z);i==null||i(e.id,{time1:P.time,price1:P.price,time2:ee.time,price2:ee.price,time3:ie.time,price3:ie.price})},[e.id,i,w]),{isDragging:E,handleMouseDown:q}=Fe({onDragStart:h,onDragMove:K}),_=I||S||z||E,L=Xt(e.time1,t,a,y,m,x),O=Xt(e.time2,t,a,y,m,x),Y=Xt(e.time3,t,a,y,m,x);if(L===void 0||O===void 0||Y===void 0)return null;const ne=r.scale(e.price1),g=r.scale(e.price2),W=r.scale(e.price3);if(!Number.isFinite(ne)||!Number.isFinite(g)||!Number.isFinite(W))return null;const ge=e.price2-e.price1,Q=[...e.levels&&e.levels.length>0?e.levels:[0,.618,1,1.272,1.618,2,2.618]].sort((C,T)=>C-T).map(C=>{const T=e.price3+C*ge,Z=r.scale(T);return{level:C,price:T,y:Z}}).filter(C=>Number.isFinite(C.y)),le=Math.min(L,O,Y),G=fs[e.lineStyle]||void 0,se=c?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",re=o?"#e2e8f0":"#1f2937",U=o?"#1e1e1e":"#1f2937";return l.jsxs("g",{className:"fib-extension-annotation",onClick:D,style:{cursor:_?"grabbing":"pointer"},children:[e.fillOpacity>0&&Q.length>=2&&Q.map((C,T)=>{if(T===0)return null;const Z=Q[T-1],P=Math.min(C.y,Z.y),ie=Math.max(C.y,Z.y)-P;return ie<1?null:l.jsx("rect",{x:le,y:P,width:n-le,height:ie,fill:Gt[T%Gt.length],fillOpacity:e.fillOpacity,style:{pointerEvents:"none"}},`fill-${C.level}`)}),c&&l.jsxs(l.Fragment,{children:[l.jsx("line",{x1:L,y1:ne,x2:O,y2:g,stroke:se,strokeWidth:9,strokeLinecap:"round"}),l.jsx("line",{x1:O,y1:g,x2:Y,y2:W,stroke:se,strokeWidth:9,strokeLinecap:"round"})]}),l.jsx("line",{x1:L,y1:ne,x2:O,y2:g,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:O,y1:g,x2:Y,y2:W,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:L,y1:ne,x2:O,y2:g,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:"6 4",strokeLinecap:"round",opacity:.7}),l.jsx("line",{x1:O,y1:g,x2:Y,y2:W,stroke:e.color,strokeWidth:e.lineWidth,strokeDasharray:"6 4",strokeLinecap:"round",opacity:.7}),Q.map(C=>{const T=C.level===1||C.level===1.618||C.level===0,Z=T?1:.7,P=T?e.lineWidth*1.5:e.lineWidth;return l.jsxs("g",{children:[c&&l.jsx("line",{x1:le,x2:n,y1:C.y,y2:C.y,stroke:se,strokeWidth:P+6,strokeLinecap:"round"}),l.jsx("line",{x1:le,x2:n,y1:C.y,y2:C.y,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"},onMouseDown:c?q:void 0}),l.jsx("line",{x1:le,x2:n,y1:C.y,y2:C.y,stroke:e.color,strokeWidth:P,strokeDasharray:G,strokeLinecap:"round",opacity:Z}),(()=>{const ee=hs(C.level),ie=e.showPrices?` (${ms(C.price)})`:"",te=`${ee}${ie}`,ce=Math.max(60,te.length*6.5+16);return l.jsxs("g",{children:[l.jsx("rect",{x:n-ce-8,y:C.y-10,width:ce,height:20,fill:U,fillOpacity:.9,rx:3,stroke:e.color,strokeWidth:.5,strokeOpacity:.5}),l.jsx("text",{x:n-ce/2-8,y:C.y,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:e.color,fontWeight:T?600:400,fontFamily:"monospace",style:{pointerEvents:"none",userSelect:"none"},children:te})]})})()]},`level-${C.level}`)}),e.label&&l.jsxs("g",{children:[l.jsx("rect",{x:Y+8,y:W-10,width:Math.max(30,e.label.length*7+16),height:20,fill:e.color,fillOpacity:.9,rx:4}),l.jsx("text",{x:Y+8+Math.max(30,e.label.length*7+16)/2,y:W,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:e.label})]}),c&&l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:L,cy:ne,r:Xe,fill:re,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:N,style:{cursor:"move"}}),l.jsx("text",{x:L,y:ne-Xe-4,textAnchor:"middle",fontSize:9,fill:e.color,style:{pointerEvents:"none",userSelect:"none"},children:"1"}),l.jsx("circle",{cx:O,cy:g,r:Xe,fill:re,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:V,style:{cursor:"move"}}),l.jsx("text",{x:O,y:g-Xe-4,textAnchor:"middle",fontSize:9,fill:e.color,style:{pointerEvents:"none",userSelect:"none"},children:"2"}),l.jsx("circle",{cx:Y,cy:W,r:Xe,fill:re,fillOpacity:.9,stroke:e.color,strokeWidth:2,onMouseDown:X,style:{cursor:"move"}}),l.jsx("text",{x:Y,y:W-Xe-4,textAnchor:"middle",fontSize:9,fill:e.color,style:{pointerEvents:"none",userSelect:"none"},children:"3"})]})]})};function ms(e){return Number.isFinite(e)?Math.abs(e)<1?e.toPrecision(4):Math.abs(e)<10?e.toFixed(4):e.toFixed(2):""}const ys={bullish:"#22c55e",bearish:"#ef4444"},gs=e=>e.color||ys[e.direction],xs=e=>e.state==="mitigated"?.15:e.state==="tested"?e.fillOpacity*.7:e.fillOpacity,bs=e=>e.state==="mitigated"?.3:1,Cr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x})=>{const b=s.useRef({x:0,y:0}),d=s.useRef({time:0,high:0,low:0}),F=s.useRef(r),k=s.useRef(t),R=s.useRef(a),p=s.useRef(y),M=s.useRef(x),$=s.useRef(m);s.useEffect(()=>{F.current=r,k.current=t,R.current=a,p.current=y,M.current=x,$.current=m},[r,t,a,y,x,m]);const D=s.useCallback(H=>{H.stopPropagation(),f==null||f(e.id)},[e.id,f]),w=s.useCallback(H=>{b.current={x:H.clientX,y:H.clientY},d.current={time:e.time,high:e.high,low:e.low}},[e.time,e.high,e.low]),h=s.useCallback((H,J)=>{const Q=k.current,le=R.current,G=p.current,se=M.current,re=$.current,U=le&&G&&re>0&&se?le(H)!==void 0?le(H):le(findClosestTime(se,H))??H:H,C=Q(U)+J;if(!Q.invert)return H;const T=Q.invert(C),Z=T instanceof Date?T.getTime():T;return le&&G&&re>0&&se?G(Math.round(Z)):Z},[]),A=s.useCallback(H=>{const J=H.clientX-b.current.x,Q=H.clientY-b.current.y,le=F.current,G=d.current,se=h(G.time,J),re=le.invert(le.scale(G.high)+Q),U=le.invert(le.scale(G.low)+Q);[se,re,U].every(Number.isFinite)&&(i==null||i(e.id,{time:se,high:re,low:U}))},[e.id,i,h]),{isDragging:I,handleMouseDown:N}=Fe({onDragStart:w,onDragMove:A}),S=(H=>{if(a&&y&&m>0)return _e(H,x,a);if(a)return a(H)})(e.time),V=t(S??e.time),v=r.scale(e.high),z=r.scale(e.low);if([V,v,z].some(H=>!Number.isFinite(H)))return null;const X=V-20,K=V+20,E=Math.min(v,z),q=Math.max(v,z),_=K-X,L=q-E;if(K<-50||X>n+50||q<-50||E>u+50)return null;const O=gs(e),Y=xs(e),ne=bs(e),g=e.state==="tested"?He.dashed:He[e.lineStyle],W=o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",ge=e.label||(e.direction==="bullish"?"Buy OB":"Sell OB");return l.jsxs("g",{className:"order-block-annotation",onClick:D,style:{cursor:I?"grabbing":"pointer"},children:[c&&l.jsx("rect",{x:X-3,y:E-3,width:_+6,height:L+6,fill:"none",stroke:W,strokeWidth:3,rx:2}),l.jsx("rect",{x:X-Be,y:E-Be,width:_+Be*2,height:L+Be*2,fill:"transparent",stroke:"transparent",strokeWidth:Be,style:{cursor:"pointer"}}),l.jsx("rect",{x:X,y:E,width:_,height:L,fill:O,fillOpacity:Y,stroke:O,strokeWidth:e.lineWidth,strokeDasharray:g,strokeOpacity:ne,rx:1,onMouseDown:c?N:void 0,style:{cursor:c?I?"grabbing":"move":"pointer"}}),l.jsxs("g",{children:[l.jsx("rect",{x:X+2,y:E+2,width:Math.max(50,ge.length*7),height:16,fill:O,fillOpacity:.9,rx:2}),l.jsx("text",{x:X+2+Math.max(50,ge.length*7)/2,y:E+10,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:600,style:{pointerEvents:"none",userSelect:"none"},children:ge})]}),c&&l.jsx("text",{x:K-4,y:q-4,fontSize:9,fill:o?"#94a3b8":"#64748b",textAnchor:"end",style:{pointerEvents:"none",userSelect:"none"},children:(e.high-e.low).toFixed(2)})]})},ps={bullish:"#22c55e",bearish:"#ef4444"},ws=e=>e.color||ps[e.direction],ks=e=>e.filled?.1:e.fillOpacity,Ds=e=>e.filled?.3:1,Rr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onMove:i,timeToIndex:a,indexToTime:y,dataLength:m=0,compressedTimes:x})=>{const b=s.useRef({x:0,y:0}),d=s.useRef({time1:0,time2:0,top:0,bottom:0}),F=s.useRef(r),k=s.useRef(t),R=s.useRef(a),p=s.useRef(y),M=s.useRef(x),$=s.useRef(m);s.useEffect(()=>{F.current=r,k.current=t,R.current=a,p.current=y,M.current=x,$.current=m},[r,t,a,y,x,m]);const D=s.useCallback((Q,le)=>{const G=k.current,se=R.current,re=p.current,U=M.current,C=$.current,T=se&&re&&C>0&&U?se(Q)!==void 0?se(Q):se(findClosestTime(U,Q))??Q:Q,Z=G(T)+le;if(!G.invert)return Q;const P=G.invert(Z),ee=P instanceof Date?P.getTime():P;return se&&re&&C>0&&U?re(Math.round(ee)):ee},[]),w=s.useCallback(Q=>{Q.stopPropagation(),f==null||f(e.id)},[e.id,f]),h=s.useCallback(Q=>{b.current={x:Q.clientX,y:Q.clientY},d.current={time1:e.time1,time2:e.time2,top:e.top,bottom:e.bottom}},[e.time1,e.time2,e.top,e.bottom]),A=s.useCallback(Q=>{const le=Q.clientX-b.current.x,G=Q.clientY-b.current.y,se=F.current,re=d.current,U=D(re.time1,le),C=D(re.time2,le),T=se.invert(se.scale(re.top)+G),Z=se.invert(se.scale(re.bottom)+G);[U,C,T,Z].every(Number.isFinite)&&(i==null||i(e.id,{time1:U,time2:C,top:T,bottom:Z}))},[e.id,i,D]),{isDragging:I,handleMouseDown:N}=Fe({onDragStart:h,onDragMove:A}),j=Q=>{if(a&&y&&m>0)return _e(Q,x,a);if(a)return a(Q)},S=j(e.time1)??e.time1,V=j(e.time2)??e.time2;if(!Number.isFinite(S)||!Number.isFinite(V))return null;const v=t(S),z=t(V),X=r.scale(e.top),K=r.scale(e.bottom);if([v,z,X,K].some(Q=>!Number.isFinite(Q)))return null;const E=Math.min(v,z),q=Math.max(v,z),_=Math.min(X,K),L=Math.max(X,K),O=q-E,Y=L-_;if(q<-50||E>n+50||L<-50||_>u+50)return null;const ne=ws(e),g=ks(e),W=Ds(e),ge=e.filled?He.dashed:He[e.lineStyle],H=o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)",J=e.label||"FVG";return l.jsxs("g",{className:"fair-value-gap-annotation",onClick:w,style:{cursor:I?"grabbing":"pointer"},children:[c&&l.jsx("rect",{x:E-3,y:_-3,width:O+6,height:Y+6,fill:"none",stroke:H,strokeWidth:3,rx:2}),l.jsx("rect",{x:E-Be,y:_-Be,width:O+Be*2,height:Y+Be*2,fill:"transparent",stroke:"transparent",strokeWidth:Be,style:{cursor:"pointer"}}),l.jsx("rect",{x:E,y:_,width:O,height:Y,fill:ne,fillOpacity:g,stroke:ne,strokeWidth:e.lineWidth,strokeDasharray:ge,strokeOpacity:W,rx:1,onMouseDown:c?N:void 0,style:{cursor:c?I?"grabbing":"move":"pointer"}}),l.jsxs("g",{children:[l.jsx("rect",{x:E+2,y:_+2,width:Math.max(50,J.length*7),height:16,fill:ne,fillOpacity:.9,rx:2}),l.jsx("text",{x:E+2+Math.max(50,J.length*7)/2,y:_+10,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:600,style:{pointerEvents:"none",userSelect:"none"},children:J})]}),c&&l.jsx("text",{x:q-4,y:L-4,fontSize:9,fill:o?"#94a3b8":"#64748b",textAnchor:"end",style:{pointerEvents:"none",userSelect:"none"},children:(e.top-e.bottom).toFixed(2)})]})},js={bullish:"#22c55e",bearish:"#ef4444"},Cs=e=>e.color||js[e.direction],Rs=e=>e.bosType==="ChoCH"?He.dashed:He[e.lineStyle],Nr=({annotation:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selected:c=!1,onSelect:f,onDoubleClick:i,onMove:a,timeToIndex:y,dataLength:m=0,compressedTimes:x})=>{const b=s.useRef(0),d=s.useRef(0),F=s.useRef(r);s.useEffect(()=>{F.current=r},[r]);const k=s.useCallback(_=>{_.stopPropagation(),f==null||f(e.id)},[e.id,f]),R=s.useCallback(_=>{_.stopPropagation(),i==null||i(e.id)},[e.id,i]),p=s.useCallback(_=>{b.current=_.clientY,d.current=e.price},[e.price]),M=s.useCallback(_=>{const L=_.clientY-b.current,O=F.current,Y=O.invert(O.scale(d.current)+L);Number.isFinite(Y)&&(a==null||a(e.id,Y))},[e.id,a]),{isDragging:$,handleMouseDown:D}=Fe({onDragStart:p,onDragMove:M}),w=r.scale(e.price);if(!Number.isFinite(w)||w<-20||w>u+20)return null;const h=Cs(e),A=Rs(e),I=e.bosType==="ChoCH"?"ChoCH":"BOS",N=e.price.toFixed(2),j=Math.max(50,I.length*7+16),S=Math.max(50,N.length*7+16),V=c?o?"rgba(99, 179, 237, 0.4)":"rgba(59, 130, 246, 0.4)":"transparent",v=o?"#e2e8f0":"#1f2937",z=_e(e.time,x,y),X=t(z!==void 0?z:e.time),K=Number.isFinite(X)?X:0,E=e.confirmed?A:He.dashed,q=e.confirmed?1:.5;return l.jsxs("g",{className:"bos-line-annotation",onClick:k,onDoubleClick:R,style:{cursor:$?"grabbing":"pointer"},children:[c&&l.jsx("line",{x1:K,x2:n,y1:w,y2:w,stroke:V,strokeWidth:e.lineWidth+6,strokeLinecap:"round"}),l.jsx("line",{x1:K,x2:n,y1:w,y2:w,stroke:"transparent",strokeWidth:Ae,style:{cursor:"pointer"}}),l.jsx("line",{x1:K,x2:n,y1:w,y2:w,stroke:h,strokeWidth:e.lineWidth,strokeDasharray:E,strokeLinecap:"round",opacity:q}),e.showLabel&&l.jsxs("g",{children:[l.jsx("rect",{x:K+4,y:w-10,width:j,height:20,fill:h,fillOpacity:.9,rx:4}),l.jsx("text",{x:K+4+j/2,y:w,dy:"0.35em",textAnchor:"middle",fontSize:10,fill:"white",fontWeight:600,style:{pointerEvents:"none",userSelect:"none"},children:I})]}),e.showPrice&&l.jsxs("g",{children:[l.jsx("rect",{x:n-S-8,y:w-10,width:S,height:20,fill:h,fillOpacity:.9,rx:4}),l.jsx("text",{x:n-S/2-8,y:w,dy:"0.35em",textAnchor:"middle",fontSize:11,fill:"white",fontWeight:500,style:{pointerEvents:"none",userSelect:"none"},children:N})]}),c&&l.jsxs("g",{onMouseDown:D,style:{cursor:"ns-resize"},children:[l.jsx("rect",{x:K+Qe,y:w-$e/2,width:$e,height:$e,fill:v,fillOpacity:.9,rx:3,stroke:h,strokeWidth:2}),l.jsx("line",{x1:K+ft,x2:K+dt,y1:w-2,y2:w-2,stroke:h,strokeWidth:1.5}),l.jsx("line",{x1:K+ft,x2:K+dt,y1:w+2,y2:w+2,stroke:h,strokeWidth:1.5})]})]})},vr=({annotations:e,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o=!1,selectedAnnotationId:c=null,onAnnotationSelect:f,onAnnotationDoubleClick:i,onAnnotationMove:a,onAnnotationTextEdit:y,timeToIndex:m,indexToTime:x,dataLength:b=0,compressedTimes:d,timeFormatter:F,currentTimeframe:k,animationPhase:R})=>{const p=s.useMemo(()=>k?e.filter(g=>!g.visibleTimeframes||g.visibleTimeframes.length===0||g.visibleTimeframes.includes(k)):e,[e,k]),M=s.useCallback((g,W)=>{a==null||a(g,{price:W})},[a]),$=s.useCallback((g,W)=>{a==null||a(g,{time:W})},[a]),D=s.useCallback((g,W,ge)=>{a==null||a(g,{time:W,price:ge})},[a]),w=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),h=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),A=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),I=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),N=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),j=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),S=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),V=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),v=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),z=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),X=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),K=s.useCallback((g,W)=>{a==null||a(g,W)},[a]),E=s.useCallback((g,W)=>{a==null||a(g,{price:W})},[a]),q=s.useMemo(()=>[...p].sort((g,W)=>{if(g.id===c)return 1;if(W.id===c)return-1;const ge={brush:-1,timerange:0,rectangle:0,channel:0,pitchfork:0,fib_extension:0,order_block:0,fair_value_gap:0,arrow:1,text:2,emoji:2,fibRetracement:3,crossline:3,vline:3,trendline:4,ray:4,hline:5,bos_line:5,measure:6,alert_line:5},H=ge[g.type]??2,J=ge[W.type]??2;return H!==J?H-J:0}),[p,c]),_=s.useMemo(()=>{if(d&&d.length>0)return d;if(!x||b<=0)return;const g=new Array(b);for(let W=0;W<b;W+=1)g[W]=x(W);return g},[d,x,b]),Y=R!==void 0?R==="annotations"||R==="complete"?1:0:1,ne={opacity:Y,pointerEvents:Y===0?"none":"auto",transition:R==="annotations"?"opacity 400ms ease-in-out":"none"};return l.jsx("g",{className:"annotation-layer",style:ne,children:q.map(g=>g.type==="hline"?l.jsx(cr,{annotation:g,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:M},g.id):g.type==="vline"?l.jsx(lr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:$,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_,timeFormatter:F},g.id):g.type==="fib_extension"?l.jsx(jr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:z,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="order_block"?l.jsx(Cr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:X,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="fair_value_gap"?l.jsx(Rr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:K,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="bos_line"?l.jsx(Nr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:E,timeToIndex:m,dataLength:b,compressedTimes:_},g.id):g.type==="brush"?l.jsx(kr,{annotation:g,xScale:t,yScale:r,darkMode:o,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:a,timeToIndex:m,indexToTime:x,compressedTimes:_},g.id):g.type==="alert_line"?l.jsx(wr,{annotation:g,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:M},g.id):g.type==="trendline"?l.jsx(At,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:w,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="ray"?l.jsx(or,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:h,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="crossline"?l.jsx(ur,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:D,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_,timeFormatter:F},g.id):g.type==="rectangle"?l.jsx(ar,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:A,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="emoji"?l.jsx(fr,{annotation:g,xScale:t,yScale:r,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:D,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="timerange"?l.jsx(dr,{annotation:g,xScale:t,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:I,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_,timeFormatter:F},g.id):g.type==="arrow"?l.jsx(hr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:N,onDoubleClick:i,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="channel"?l.jsx(mr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:j,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="fibRetracement"?l.jsx(br,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:S,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="measure"?l.jsx(pr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:V,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type==="pitchfork"?l.jsx(Dr,{annotation:g,xScale:t,yScale:r,chartWidth:n,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onMove:v,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id):g.type!=="text"?null:l.jsx(nr,{annotation:g,xScale:t,yScale:r,paneHeight:u,darkMode:o,selected:g.id===c,onSelect:f,onDoubleClick:i,onMove:D,onTextEdit:y,timeToIndex:m,indexToTime:x,dataLength:b,compressedTimes:_},g.id))})},Ns=(e,t,r,n={})=>{const u=Date.now();return{id:`hline-${u}-${Math.random().toString(36).slice(2,9)}`,type:"hline",symbol:e,timeframe:t,price:r,color:n.color??"#ef4444",lineStyle:n.lineStyle??"dashed",lineWidth:n.lineWidth??1.5,label:n.label,showPrice:n.showPrice??!0,visibleTimeframes:n.visibleTimeframes,createdAt:u,updatedAt:u}},vs=(e,t,r,n={})=>{const u=Date.now();return{id:`vline-${u}-${Math.random().toString(36).slice(2,9)}`,type:"vline",symbol:e,timeframe:t,time:r,color:n.color??"#3b82f6",lineStyle:n.lineStyle??"dashed",lineWidth:n.lineWidth??1.5,label:n.label,showTime:n.showTime??!0,visibleTimeframes:n.visibleTimeframes,createdAt:u,updatedAt:u}},Ms=(e,t,r,n,u,o={})=>{const c=Date.now();return{id:`text-${c}-${Math.random().toString(36).slice(2,9)}`,type:"text",symbol:e,timeframe:t,time:r,price:n,text:u,color:o.color??"#1f2937",backgroundColor:o.backgroundColor,fontSize:o.fontSize??12,visibleTimeframes:o.visibleTimeframes,createdAt:c,updatedAt:c}},Fs=(e,t,r,n,u,o,c={})=>{const f=Date.now();return{id:`trendline-${f}-${Math.random().toString(36).slice(2,9)}`,type:"trendline",symbol:e,timeframe:t,time1:r,price1:n,time2:u,price2:o,color:c.color??"#3b82f6",lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1.5,label:c.label,extendLeft:c.extendLeft??!1,extendRight:c.extendRight??!1,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Os=(e,t,r,n,u,o,c={})=>{const f=Date.now();return{id:`ray-${f}-${Math.random().toString(36).slice(2,9)}`,type:"ray",symbol:e,timeframe:t,time1:r,price1:n,time2:u,price2:o,color:c.color??"#f97316",lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1.5,label:c.label,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Ws=(e,t,r,n,u={})=>{const o=Date.now();return{id:`crossline-${o}-${Math.random().toString(36).slice(2,9)}`,type:"crossline",symbol:e,timeframe:t,time:r,price:n,color:u.color??"#06b6d4",lineStyle:u.lineStyle??"dashed",lineWidth:u.lineWidth??1,label:u.label,showPrice:u.showPrice??!0,showTime:u.showTime??!0,visibleTimeframes:u.visibleTimeframes??void 0,createdAt:o,updatedAt:o}},Ps=(e,t,r,n,u,o,c={})=>{const f=Date.now();return{id:`rect-${f}-${Math.random().toString(36).slice(2,9)}`,type:"rectangle",symbol:e,timeframe:t,time1:r,price1:n,time2:u,price2:o,color:c.color??"#3b82f6",fillOpacity:c.fillOpacity??.15,lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1.5,label:c.label,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Es=(e,t,r,n,u,o={})=>{const c=Date.now();return{id:`emoji-${c}-${Math.random().toString(36).slice(2,9)}`,type:"emoji",symbol:e,timeframe:t,time:r,price:n,emoji:u,size:o.size??24,visibleTimeframes:o.visibleTimeframes??void 0,createdAt:c,updatedAt:c}},Ss=(e,t,r,n,u={})=>{const o=Date.now();return{id:`timerange-${o}-${Math.random().toString(36).slice(2,9)}`,type:"timerange",symbol:e,timeframe:t,time1:r,time2:n,color:u.color??"#8b5cf6",fillOpacity:u.fillOpacity??.12,lineStyle:u.lineStyle??"solid",lineWidth:u.lineWidth??1,label:u.label,visibleTimeframes:u.visibleTimeframes??void 0,createdAt:o,updatedAt:o}},$s=(e,t,r,n,u,o,c,f={})=>{const i=Date.now();return{id:`arrow-${i}-${Math.random().toString(36).slice(2,9)}`,type:"arrow",symbol:e,timeframe:t,time1:r,price1:n,time2:u,price2:o,text:c,color:f.color??"#f97316",lineStyle:f.lineStyle??"solid",lineWidth:f.lineWidth??1.5,fontSize:f.fontSize??12,visibleTimeframes:f.visibleTimeframes??void 0,createdAt:i,updatedAt:i}},Xs=(e,t,r,n,u,o,c,f={})=>{const i=Date.now();return{id:`channel-${i}-${Math.random().toString(36).slice(2,9)}`,type:"channel",symbol:e,timeframe:t,time1:r,price1:n,time2:u,price2:o,priceOffset:c,color:f.color??"#8b5cf6",lineStyle:f.lineStyle??"solid",lineWidth:f.lineWidth??1.5,label:f.label,fillOpacity:f.fillOpacity??.08,extendLeft:f.extendLeft??!1,extendRight:f.extendRight??!1,visibleTimeframes:f.visibleTimeframes??void 0,createdAt:i,updatedAt:i}},Ls=(e,t,r,n,u,o,c={})=>{const f=Date.now();return{id:`fib-${f}-${Math.random().toString(36).slice(2,9)}`,type:"fibRetracement",symbol:e,timeframe:t,time1:r,price1:n,time2:u,price2:o,color:c.color??"#f59e0b",lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1,label:c.label,fillOpacity:c.fillOpacity??.1,levels:c.levels??[0,.236,.382,.5,.618,.786,1],showExtensions:c.showExtensions??!1,extendRight:c.extendRight??!0,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Ys=(e,t,r,n,u,o,c={})=>{const f=Date.now();return{id:`measure-${f}-${Math.random().toString(36).slice(2,9)}`,type:"measure",symbol:e,timeframe:t,time1:r,price1:n,time2:u,price2:o,color:c.color??"#f97316",visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},As=(e,t,r,n={})=>{const u=Date.now();return{id:`alert_line-${u}-${Math.random().toString(36).slice(2,9)}`,type:"alert_line",symbol:e,timeframe:t,price:r,color:n.color??"#f59e0b",lineStyle:n.lineStyle??"dashed",lineWidth:n.lineWidth??1.5,label:n.label,showPrice:n.showPrice??!0,triggered:n.triggered??!1,direction:n.direction??"above",alertId:n.alertId,visibleTimeframes:n.visibleTimeframes??void 0,createdAt:u,updatedAt:u}},Vs=(e,t,r,n={})=>{const u=Date.now();return{id:`brush-${u}-${Math.random().toString(36).slice(2,9)}`,type:"brush",symbol:e,timeframe:t,points:r,color:n.color??"#3b82f6",lineWidth:n.lineWidth??2,visibleTimeframes:n.visibleTimeframes??void 0,createdAt:u,updatedAt:u}},_s=(e,t,r,n,u,o,c,f,i={})=>{const a=Date.now();return{id:`pitchfork-${a}-${Math.random().toString(36).slice(2,9)}`,type:"pitchfork",symbol:e,timeframe:t,time1:r,price1:n,time2:u,price2:o,time3:c,price3:f,color:i.color??"#f97316",lineStyle:i.lineStyle??"solid",lineWidth:i.lineWidth??1.5,label:i.label,fillOpacity:i.fillOpacity??.06,extendRight:i.extendRight??!0,visibleTimeframes:i.visibleTimeframes??void 0,createdAt:a,updatedAt:a}},zs=(e,t,r,n,u,o,c,f,i={})=>{const a=Date.now();return{id:`fib_ext-${a}-${Math.random().toString(36).slice(2,9)}`,type:"fib_extension",symbol:e,timeframe:t,time1:r,price1:n,time2:u,price2:o,time3:c,price3:f,color:i.color??"#8b5cf6",lineStyle:i.lineStyle??"solid",lineWidth:i.lineWidth??1,label:i.label,levels:i.levels??[0,.618,1,1.272,1.618,2,2.618],fillOpacity:i.fillOpacity??.06,showPrices:i.showPrices??!0,visibleTimeframes:i.visibleTimeframes??void 0,createdAt:a,updatedAt:a}},Ts=(e,t,r,n,u,o,c={})=>{const f=Date.now(),i=o==="bullish"?"#22c55e":"#ef4444";return{id:`ob-${f}-${Math.random().toString(36).slice(2,9)}`,type:"order_block",symbol:e,timeframe:t,time:r,high:n,low:u,direction:o,state:c.state??"active",color:c.color??i,fillOpacity:c.fillOpacity??.25,lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??1,label:c.label,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Bs=(e,t,r,n,u,o,c,f={})=>{const i=Date.now(),a=c==="bullish"?"#22c55e":"#ef4444";return{id:`fvg-${i}-${Math.random().toString(36).slice(2,9)}`,type:"fair_value_gap",symbol:e,timeframe:t,time1:r,time2:n,top:u,bottom:o,direction:c,filled:f.filled??!1,color:f.color??a,fillOpacity:f.fillOpacity??.2,lineStyle:f.lineStyle??"solid",lineWidth:f.lineWidth??1,label:f.label,visibleTimeframes:f.visibleTimeframes??void 0,createdAt:i,updatedAt:i}},Is=(e,t,r,n,u,o,c={})=>{const f=Date.now(),i=o==="bullish"?"#22c55e":"#ef4444";return{id:`bos-${f}-${Math.random().toString(36).slice(2,9)}`,type:"bos_line",symbol:e,timeframe:t,time:r,price:n,bosType:u,direction:o,confirmed:c.confirmed??!0,color:c.color??i,lineStyle:c.lineStyle??"solid",lineWidth:c.lineWidth??2,showPrice:c.showPrice??!0,showLabel:c.showLabel??!0,visibleTimeframes:c.visibleTimeframes??void 0,createdAt:f,updatedAt:f}},Us=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#64748b","#ffffff"],qs=400,Zt=16,Gs=Le.utcFormat("%Y-%m-%d %H:%M"),Mr=e=>{if(!Array.isArray(e))return!1;if(e.length===0)return!0;const t=e[0];return t&&typeof t.t=="number"&&typeof t.v=="number"},Fr=e=>{if(!Array.isArray(e))return!1;if(e.length===0)return!0;const t=e[0];return t&&typeof t.t=="number"&&typeof t.o=="number"&&typeof t.h=="number"&&typeof t.l=="number"&&typeof t.c=="number"},Ze=e=>{if(!Number.isFinite(e??NaN))return"—";const t=Math.abs(e);return t>=1e3?e.toFixed(0):t>=100?e.toFixed(1):e.toFixed(2)},Ht=(e,t)=>t?t(e):Gs(new Date(e)),Nt=e=>({...e,data:Array.isArray(e.data)?[...e.data]:[],style:e.style?{...e.style}:void 0}),Or=e=>({...e,series:e.series.map(Nt),guides:e.guides?e.guides.map(t=>({...t})):void 0}),bt=e=>({panes:e?e.panes.map(Or):[],timeFormatter:e==null?void 0:e.timeFormatter,onCrosshairMove:e==null?void 0:e.onCrosshairMove,onSeriesPointClick:e==null?void 0:e.onSeriesPointClick,includeOverlaysInAutoScale:e==null?void 0:e.includeOverlaysInAutoScale}),Zs=(e,t)=>{if(!e.panes.length||t<=0)return{rects:[],heights:{}};const r=e.panes.map(a=>a.heightRatio>0?a.heightRatio:1),n=r.reduce((a,y)=>a+y,0),u=Math.max(0,e.panes.length-1)*Zt,o=Math.max(0,t-u),c=[],f={};let i=0;return e.panes.forEach((a,y)=>{const m=r[y],x=o*(m/n);c.push({pane:a,y:i,height:x}),f[a.id]=x,i+=x+Zt}),{rects:c,heights:f}},Kt=(e,t)=>{if(!e.length)return null;let r=0,n=e.length-1;for(;r<=n;){const c=Math.floor((r+n)/2),f=e[c];if(f.t===t)return f;f.t<t?r=c+1:n=c-1}const u=e[Math.max(0,n)],o=e[Math.min(e.length-1,r)];return Math.abs(u.t-t)<=Math.abs(o.t-t)?u:o},Hs=(e,t)=>{if(!e.length)return null;let r=0,n=e.length-1;for(;r<=n;){const c=Math.floor((r+n)/2),f=e[c];if(f.t===t)return f;f.t<t?r=c+1:n=c-1}const u=e[Math.max(0,n)],o=e[Math.min(e.length-1,r)];return Math.abs(u.t-t)<=Math.abs(o.t-t)?u:o},Ks=(e,t,r)=>{if(!e.length)return Math.max(1,r*.01);if(e.length===1)return Math.max(4,Math.min(24,r*.6));let n=1/0;for(let u=1;u<e.length;u+=1){const o=t(e[u-1].t),c=t(e[u].t),f=Math.abs(c-o);f>0&&f<n&&(n=f)}return(!Number.isFinite(n)||n===1/0)&&(n=r/e.length),Math.max(1,Math.min(24,n*.7))},Wr=(e,t)=>{if(!Array.isArray(e)||e.length===0)return 6;if(e.length===1)return Math.max(4,Math.min(16,12));const r=[...e].sort((u,o)=>u.t-o.t);let n=1/0;for(let u=1;u<r.length;u+=1){const o=t(r[u-1].t),c=t(r[u].t),f=Math.abs(c-o);f>0&&f<n&&(n=f)}return!Number.isFinite(n)||n===1/0?6:Math.max(4,Math.min(18,n*.5))},Js=(e,t,r,n,u)=>{var F;const o=e.style??{},c=o.lineWidth??1.5,f=o.color??e.color??"#6b7280",i=o.opacity??1,a=o.dashed?"4 4":void 0,y=u&&u.phase!=="complete",m=((F=u==null?void 0:u.layerOpacities)==null?void 0:F[e.key])??(y?0:1),x=i*m;if(e.type==="hist"){let k=1/0;for(let M=1;M<t.length;M+=1){const $=n(t[M-1].t),D=n(t[M].t),w=Math.abs(D-$);w>0&&w<k&&(k=w)}(!Number.isFinite(k)||k===1/0)&&(k=8);const R=Math.max(2,Math.min(12,k*.4));let p="";return t.forEach(M=>{const $=n(M.t),D=r.scale(0),w=r.scale(M.v),h=Math.min(w,D),A=Math.max(w,D);p+=`M${$-R},${h}H${$+R}V${A}H${$-R}Z`}),l.jsx("path",{d:p,fill:f,opacity:x*.85,stroke:"none"})}if(e.type==="area"){const R=Le.area().defined(p=>Number.isFinite(p.v)).x(p=>n(p.t)).y0(()=>r.scale(r.domain[0])).y1(p=>r.scale(p.v))(t);return R?l.jsx("path",{d:R,fill:f,opacity:Math.min(.4,x),stroke:"none"}):null}const d=Le.line().defined(k=>Number.isFinite(k.v)).x(k=>n(k.t)).y(k=>r.scale(k.v))(t);return d?l.jsx("path",{d,stroke:f,strokeWidth:c,fill:"none",opacity:x,strokeDasharray:a}):null},Qs=(e,t,r,n,u)=>{var h,A,I,N,j,S,V,v,z,X,K;if(!Array.isArray(t)||t.length===0)return null;const o=u==null?void 0:u.phase;if(o&&o!=="events"&&o!=="annotations"&&o!=="complete")return null;const c=Wr(t,n),f=((h=e.style)==null?void 0:h.markerShape)??"circle",i=((A=e.style)==null?void 0:A.markerSize)??6,a=((I=e.style)==null?void 0:I.color)??e.color??"#fbbf24",y=((N=e.style)==null?void 0:N.markerOffsetY)??0,m=((j=e.style)==null?void 0:j.markerFontSize)??10,x=((S=e.style)==null?void 0:S.markerTextColor)??a,b=((V=e.style)==null?void 0:V.markerTextOffsetY)??0,d=((v=e.style)==null?void 0:v.markerVariant)??"filled",F=((z=e.style)==null?void 0:z.markerStrokeWidth)??1.5,k=((X=e.style)==null?void 0:X.markerHaloSize)??0,R=((K=e.style)==null?void 0:K.markerHaloOpacity)??.25,p=new Map,M=new Map;let $=0;if(t.forEach(E=>{if(!Number.isFinite(E==null?void 0:E.t)||!Number.isFinite(E==null?void 0:E.v))return;M.set(E,$),$+=1;const q=E.shape??f,_=E.size??i,L=E.color??a,O=E.offsetY??y,Y=E.fontSize??m,ne=E.textColor??x,g=E.textOffsetY??b,W=E.variant??d,ge=E.strokeWidth??F,H=E.haloSize??k,J=E.haloOpacity??R,Q={shape:q,size:_,color:L,offsetY:O,fontSize:Y,textColor:ne,textOffsetY:g,variant:W,strokeWidth:ge,haloSize:H,haloOpacity:J},le=JSON.stringify(Q);p.has(le)||p.set(le,{key:Q,points:[]}),p.get(le).points.push(E)}),!p.size)return null;const D=E=>r.scale(E);let w=0;return l.jsx("g",{className:"dwlf-marker-series",children:Array.from(p.values()).map(({key:E,points:q},_)=>{const L=w;return w+=q.length,l.jsx(Jt,{points:q.map(O=>({date:O.t,actualTime:O.__rawTime??O.t,price:O.v,text:O.label,tooltip:O.tooltip||O.text,animationOrder:M.get(O)})),xScale:n,yScale:D,xBandwidth:c,shape:E.shape,size:E.size,color:E.color,offsetY:E.offsetY,fontSize:E.fontSize,textColor:E.textColor,textOffsetY:E.textOffsetY,variant:E.variant,strokeWidth:E.strokeWidth,haloSize:E.haloSize,haloOpacity:E.haloOpacity,animationPhase:u==null?void 0:u.phase,staggerDelay:100,staggerStartIndex:L},`${e.key}-marker-${_}`)})})},ei=(e,t,r,n,u)=>{var k,R,p,M,$,D,w;if(!Array.isArray(t)||t.length===0)return null;const o=Math.abs(r.scale(r.domain[0])-r.scale(r.domain[1]));if(!Number.isFinite(o)||o===0)return null;const c=t.flatMap(h=>{const A=[];return Number.isFinite(h.start)&&A.push({t:h.start}),Number.isFinite(h.end??NaN)&&A.push({t:h.end}),A}),f=Wr(c,n),i=((k=e.style)==null?void 0:k.riskColor)??"rgba(255, 107, 107, 0.25)",a=((R=e.style)==null?void 0:R.rewardColor)??"rgba(76, 175, 80, 0.25)",y=((p=e.style)==null?void 0:p.bubbleColor)??"rgba(0,0,0,0.85)",m=((M=e.style)==null?void 0:M.textColor)??"white",x=(($=e.style)==null?void 0:$.fontSize)??11,b=((D=e.style)==null?void 0:D.pointer)??!0,d=((w=e.style)==null?void 0:w.padding)??6,F=h=>r.scale(h);return l.jsx("g",{className:"dwlf-position-series",children:t.map((h,A)=>{if(!Number.isFinite(h==null?void 0:h.start)||!Number.isFinite(h==null?void 0:h.entry)||!Number.isFinite(h==null?void 0:h.stop)||!Number.isFinite(h==null?void 0:h.target))return null;const I=Array.isArray(h.messages)?h.messages.filter(N=>Number.isFinite(N==null?void 0:N.t)&&Number.isFinite(N==null?void 0:N.v)&&(N==null?void 0:N.text)).map(N=>({date:N.t,actualTime:N.__rawTime??N.t,price:N.v,text:N.text})):void 0;return l.jsx(er,{startDate:h.start,endDate:Number.isFinite(h.end??NaN)?h.end:void 0,entryPrice:h.entry,stopPrice:h.stop,takePrice:h.target,xScale:n,yScale:F,xBandwidth:f,chartWidth:u,chartHeight:o,riskColor:h.riskColor??i,rewardColor:h.rewardColor??a,messages:I,bubbleColor:h.bubbleColor??y,textColor:h.textColor??m,fontSize:h.fontSize??x,pointer:h.pointer??b,padding:h.padding??d},`${e.key}-position-${A}`)})})},ti=(e,t,r,n,u,o,c)=>{var $;const i=Ks(t,n,u)/2,a=(($=e.style)==null?void 0:$.color)??e.color??(o?"#22c55e":"#16a34a"),y=Le.color(a),x=y?y.darker(1.2).formatHex():o?"#ef4444":"#b91c1c",b=a;let d=t;(c==null?void 0:c.phase)==="background"||(c==null?void 0:c.phase)==="idle"?d=[]:(c==null?void 0:c.phase)==="candles"&&(d=t.slice(0,c.candleRevealIndex+1));const F=D=>{if(!c||c.phase!=="candles")return .9;const w=c.candleRevealIndex,h=10;if(D<=w-h)return .9;if(D>w)return 0;const A=(w-D)/h;return Math.max(0,Math.min(.9,A*.9))};let k="",R="",p="";const M=[];return d.forEach((D,w)=>{const h=n(D.t),A=r.scale(D.h),I=r.scale(D.l),N=r.scale(D.o),j=r.scale(D.c),S=F(w);if(S===0)return;const V=`M${h},${A}L${h},${I}`,v=Math.min(N,j),z=Math.max(N,j),X=h-i,K=h+i,E=Math.max(1,z-v),q=`M${X},${v}H${K}V${v+E}H${X}Z`,_=D.c>=D.o;(c==null?void 0:c.phase)==="candles"&&S<.9?M.push(l.jsxs("g",{className:"dwlf-candle-individual",children:[l.jsx("path",{d:V,strokeWidth:1,stroke:o?"rgba(148, 163, 184, 0.6)":"rgba(100, 116, 139, 0.8)",fill:"none",opacity:S}),l.jsx("path",{d:q,fill:_?b:x,stroke:"none",opacity:S})]},`candle-${w}`)):(k+=V,_?R+=q:p+=q)}),l.jsxs("g",{className:"dwlf-candles",children:[k&&l.jsx("path",{d:k,strokeWidth:1,stroke:o?"rgba(148, 163, 184, 0.6)":"rgba(100, 116, 139, 0.8)",fill:"none"}),R&&l.jsx("path",{d:R,fill:b,stroke:"none",opacity:.9}),p&&l.jsx("path",{d:p,fill:x,stroke:"none",opacity:.9}),M]})},ri=(e,t,r,n)=>{const u=n,o=t-u,c=r+u,f=i=>{if(!Number.isFinite(i??NaN))return!1;const a=i;return a>=o&&a<=c};if(!Array.isArray(e.data))return[];if(e.type==="ohlc")return e.data.filter(i=>f(i==null?void 0:i.t));if(e.type==="line"||!e.type){if(e.data.length===2){const i=e.data[0],a=e.data[1];if(Number.isFinite((i==null?void 0:i.t)??NaN)&&Number.isFinite((a==null?void 0:a.t)??NaN)){const m=Number(i==null?void 0:i.t),x=Number(a==null?void 0:a.t),b=Math.min(m,x),F=Math.max(m,x)>=o&&b<=c;if(f(m)||f(x)||F)return e.data}}return e.data.filter(i=>f(i==null?void 0:i.t))}return e.type==="hist"||e.type==="area"?e.data.filter(i=>f(i==null?void 0:i.t)):e.type==="marker"?e.data.filter(i=>f(i==null?void 0:i.t)):e.type==="position"?e.data.filter(i=>{const a=Number.isFinite(i==null?void 0:i.start)?Number(i.start):Number(i==null?void 0:i.t)||0;return((Number.isFinite(i==null?void 0:i.end)?Number(i.end):void 0)??a)>=o&&a<=c}):e.data},si=(e,t,r,n,u,o)=>!Array.isArray(e.data)||e.data.length===0||(o==null?void 0:o.phase)==="loading"?null:e.type==="ohlc"&&Fr(e.data)?ti(e,e.data,t,r,n,u,o):e.type==="marker"?Qs(e,e.data,t,r,o):e.type==="position"?ei(e,e.data,t,r,n):Mr(e.data)?Js(e,e.data,t,r,o):null,Lt=(e,t)=>{var u,o,c,f,i,a,y,m,x,b,d,F,k;if(!Array.isArray(e.data)||e.data.length===0)return{key:e.key,color:((u=e.style)==null?void 0:u.color)??e.color,value:null,display:"—",raw:null};if(e.type==="ohlc"&&Fr(e.data)){const R=Hs(e.data,t);if(!R)return{key:e.key,color:((o=e.style)==null?void 0:o.color)??e.color,value:null,display:"—",raw:null};const p=e.tooltipFormatter?e.tooltipFormatter(R):`O ${Ze(R.o)} H ${Ze(R.h)} L ${Ze(R.l)} C ${Ze(R.c)}`;return{key:e.key,color:((c=e.style)==null?void 0:c.color)??e.color,value:R.c??null,display:p,raw:R}}if(e.type==="marker"){const R=e.data.filter(h=>Number.isFinite(h==null?void 0:h.t)&&Number.isFinite(h==null?void 0:h.v));if(!R.length)return{key:e.key,color:((f=e.style)==null?void 0:f.color)??e.color,value:null,display:"—",raw:null};const p=R.map(h=>({t:h.t,v:h.v})),M=Kt(p,t);if(!M)return{key:e.key,color:((i=e.style)==null?void 0:i.color)??e.color,value:null,display:"—",raw:null};const $=R.find(h=>h.t===M.t&&h.v===M.v)??null,D=e.tooltipFormatter?e.tooltipFormatter($??M):$!=null&&$.label?`${$.label} ${Ze(M.v)}`:Ze(M.v),w=($==null?void 0:$.color)??((a=e.style)==null?void 0:a.color);return{key:e.key,color:w,value:M.v??null,display:D,raw:$??M}}if(e.type==="position"){const R=e.data.filter(D=>Number.isFinite(D==null?void 0:D.start)&&Number.isFinite(D==null?void 0:D.entry)&&Number.isFinite(D==null?void 0:D.stop)&&Number.isFinite(D==null?void 0:D.target));if(!R.length)return{key:e.key,color:((y=e.style)==null?void 0:y.color)??e.color,value:null,display:"—",raw:null};const p=R.reduce((D,w)=>{const h=Math.abs(w.start-t),A=Number.isFinite(w.end??NaN)?Math.abs(w.end-t):h,I=Math.min(h,A);if(!D)return w;const N=Math.abs(D.start-t),j=Number.isFinite(D.end??NaN)?Math.abs(D.end-t):N,S=Math.min(N,j);return I<S?w:D},null);if(!p)return{key:e.key,color:((m=e.style)==null?void 0:m.color)??e.color,value:null,display:"—",raw:null};const M=e.tooltipFormatter?e.tooltipFormatter(p):`Entry ${Ze(p.entry)} Stop ${Ze(p.stop)} Target ${Ze(p.target)}`,$=((x=e.style)==null?void 0:x.color)??((b=e.style)==null?void 0:b.riskColor)??"rgba(239, 68, 68, 0.8)";return{key:e.key,color:$,value:p.entry??null,display:M,raw:p}}if(Mr(e.data)){const R=Kt(e.data,t);if(!R)return{key:e.key,color:((d=e.style)==null?void 0:d.color)??e.color,value:null,display:"—",raw:null};const p=e.tooltipFormatter?e.tooltipFormatter(R):Ze(R.v);return{key:e.key,color:((F=e.style)==null?void 0:F.color)??e.color,value:R.v??null,display:p,raw:R}}const r=e.data.find(R=>R&&typeof R.t=="number"),n=e.tooltipFormatter?e.tooltipFormatter(r):"—";return{key:e.key,color:((k=e.style)==null?void 0:k.color)??e.color,value:null,display:n,raw:r}},ii=s.forwardRef(function({spec:t,darkMode:r=!0,showGrid:n=!0,className:u,style:o,enablePanZoom:c=!1,timeframe:f="daily",initialVisibleCount:i=160,extraRightSlots:a=30,compressGaps:y=!1,axisColors:m,crosshairSnapMode:x="series",showCrosshairPriceLabel:b=!0,annotations:d=[],selectedAnnotationId:F=null,onAnnotationSelect:k,onAnnotationMove:R,onAnnotationTextEdit:p,onAnnotationDoubleClick:M,onChartCanvasClick:$,onCanvasMouseMove:D,onChartCanvasHover:w,animationState:h},A){const[I,N]=s.useState(()=>bt(t));s.useEffect(()=>{N(bt(t))},[t]);const[j,S]=s.useState(!0),[V,v]=s.useState(null),[z,{width:X,height:K}]=rr(),E=s.useRef(null),q=K||qs,L=(f||"").toLowerCase()==="hourly"?36e5:864e5,O=s.useMemo(()=>{for(const B of I.panes){const oe=B.series.find(ye=>ye.type==="ohlc"&&Array.isArray(ye.data));if(oe)return oe}return null},[I]),Y=s.useMemo(()=>!O||!Array.isArray(O.data)?[]:O.data.filter(B=>Number.isFinite(B==null?void 0:B.t)),[O]),ne=s.useMemo(()=>Y.map(B=>({date:new Date(B.t).toISOString()})),[Y]),g=tr(ne,i,a,f),W=c&&Y.length>0,ge=y&&Y.length>0,{mouseHandlers:H,chartElementRef:J,zoomIn:Q,zoomOut:le,resetView:G,panToStart:se,panToEnd:re}=g,U=s.useCallback(B=>{if(!Y.length)return Date.now()+B*L;if(B<=0)return Y[Math.max(0,B)].t;if(B<Y.length)return Y[B].t;const oe=Y[Y.length-1].t,ye=B-(Y.length-1);return oe+ye*L},[Y,L]),C=s.useMemo(()=>{if(!W)return null;const B=g.viewportStart,oe=Math.max(g.viewportEnd,B+1),ye=U(B),fe=U(oe),de=fe<=ye?ye+L:fe;return{startTime:ye,endTime:de,viewportStart:g.viewportStart,viewportEnd:g.viewportEnd,visibleCount:g.visibleCount}},[W,g.viewportStart,g.viewportEnd,g.visibleCount,U,L]),T=s.useRef(!1),Z=s.useRef(Y.length);s.useEffect(()=>{if(!W){T.current=!1;return}if(Y.length===0){T.current=!1;return}if(!T.current){G(),T.current=!0,Z.current=Y.length;return}Y.length!==Z.current&&(G(),Z.current=Y.length)},[W,Y.length,G]),s.useEffect(()=>{W&&(T.current=!1)},[t,W]);const P=s.useMemo(()=>{if(!ge)return null;let B=[];if(W&&C){const fe=Math.max(0,C.viewportEnd-C.viewportStart);B=Array.from({length:fe},(de,me)=>U(C.viewportStart+me))}else B=zt(I);const oe=Array.from(new Set(B.filter(fe=>Number.isFinite(fe)))).sort((fe,de)=>fe-de);if(!oe.length)return null;const ye=new Map;return oe.forEach((fe,de)=>ye.set(fe,de)),{rawToIndex:ye,indexToRaw:oe}},[ge,W,C,I,U]),ee=s.useMemo(()=>{if(P)return B=>P.rawToIndex.get(B)},[P]),ie=s.useMemo(()=>{if(P)return B=>{const oe=P.indexToRaw.length-1,ye=Math.max(0,Math.min(oe,B));return P.indexToRaw[ye]}},[P]),te=s.useCallback(B=>{W&&J(B),z&&(z.current=B)},[W,J,z]),ce=s.useMemo(()=>{const B=de=>{if(!P||!Number.isFinite(de))return de;const{rawToIndex:me,indexToRaw:ae}=P,he=me.get(de);if(he!==void 0)return he;const Ne=ae.length;if(Ne>0&&Number.isInteger(de)&&de>=0&&de<=Ne-1||!Ne)return de;const ke=nt(ae,de);return me.get(ke)??de},oe=de=>!P||!de?de:de.map(me=>{let ae=me;if(Number.isFinite(me.startTime??NaN)){const he=B(me.startTime);he!==me.startTime&&(ae={...ae,startTime:he})}if(Number.isFinite(me.endTime??NaN)){const he=B(me.endTime);he!==me.endTime&&(ae=ae===me?{...ae}:ae,ae.endTime=he)}return ae}),ye=(de,me)=>!P||!Array.isArray(me)?me:de.type==="position"?me.map(ae=>{if(!ae)return ae;const he={...ae},Ne=ae.__rawStart??ae.start;if(Number.isFinite(Ne)){const ke=P.rawToIndex.get(Ne);ke!==void 0&&(he.__rawStart=Ne,he.start=ke)}if(Number.isFinite(ae.end??NaN)){const ke=ae.__rawEnd??ae.end;if(Number.isFinite(ke)){const Oe=P.rawToIndex.get(ke);Oe!==void 0&&(he.__rawEnd=ke,he.end=Oe)}}return Array.isArray(ae.messages)&&(he.messages=ae.messages.map(ke=>{if(!Number.isFinite((ke==null?void 0:ke.t)??NaN))return ke;const Oe=ke.__rawTime??ke.t,Ee=P.rawToIndex.get(Oe);return Ee===void 0||ke.t===Ee&&ke.__rawTime?ke:{...ke,__rawTime:Oe,t:Ee}})),he}):me.map(ae=>{if(!ae||typeof ae.t!="number")return ae;const he=ae.__rawTime??ae.t,Ne=P.rawToIndex.get(he);return Ne===void 0||ae.t===Ne&&ae.__rawTime?ae:{...ae,__rawTime:he,t:Ne}});if(!W||!C){if(!P)return I;const de=bt(I);return de.panes=de.panes.map(me=>({...me,series:me.series.map(ae=>({...ae,data:Array.isArray(ae.data)?ye(ae,ae.data):ae.data})),guides:oe(me.guides)})),de}const fe=bt(I);return fe.panes=fe.panes.map(de=>{const me=de.series.map(ae=>{const he=ri(ae,C.startTime,C.endTime,L);return Array.isArray(he)?{...ae,data:ye(ae,he)}:{...ae,data:he}});return{...de,series:me,guides:oe(de.guides)}}),fe},[I,W,C,L,U,P]),{rects:De,heights:Ce}=s.useMemo(()=>Zs(ce,q),[ce,q]),je=s.useMemo(()=>{const B=new Map;return De.forEach(oe=>{B.set(oe.pane.id,oe)}),B},[De]),pe=s.useMemo(()=>Br(ce,Ce),[ce,Ce]),be=s.useMemo(()=>{if(P)return P.indexToRaw.map((oe,ye)=>ye);if(!W||!C)return zt(ce);const B=[];for(let oe=C.viewportStart;oe<C.viewportEnd;oe+=1)B.push(U(oe));return B.length?B:[C.startTime,C.endTime]},[P,W,C,ce,U]),we=s.useMemo(()=>{const B=Math.max(0,X);if(!be.length||B<=0){const fe=Date.now();return Le.scaleUtc().domain([fe-36e5,fe]).range([0,B||1])}if(P){const fe=P.indexToRaw.length,de=fe>1?fe-1:1;return Le.scaleLinear().domain([0,de]).range([0,B])}let oe=be[0],ye=be[be.length-1];return W&&C&&(oe=C.startTime,ye=C.endTime),oe===ye&&(ye=oe+L),Le.scaleUtc().domain([oe,ye]).range([0,B])},[be,X,W,C,L,P]),Me=s.useMemo(()=>{if(!be.length||X<=0)return[];const B=Math.min(12,Math.max(2,Math.floor(X/140)));if(P){const oe=P.indexToRaw.length;if(!oe)return[];const fe=Le.scaleLinear().domain([0,Math.max(1,oe-1)]).ticks(B);return Array.from(new Set(fe.map(me=>{const ae=Math.round(me);return Math.max(0,Math.min(oe-1,ae))}))).sort((me,ae)=>me-ae)}return we.ticks(B).map(oe=>oe instanceof Date?oe.valueOf():Number(oe))},[we,be,X,P]),xe=s.useCallback(B=>{if(P){if(!P.indexToRaw.length)return B;const oe=Math.max(0,Math.min(P.indexToRaw.length-1,Math.round(B)));return P.indexToRaw[oe]}return B},[P]),Pe=j?V:null,Ge=s.useCallback(B=>{var Ee;if(!j||!E.current)return;const oe=E.current.getBoundingClientRect(),ye=B.clientX-oe.left,fe=Math.max(0,Math.min(ye,Math.max(0,X))),de=we.invert(fe),me=de instanceof Date?de.valueOf():de;if(!Number.isFinite(me)){v(null);return}const ae=nt(be,me);if(!Number.isFinite(ae)){v(null);return}const he=B.clientY-oe.top;let Ne=null;if(x==="pointer")for(const We of je.values()){const ve=We.y+We.height;if(he>=We.y&&he<=ve){Ne=We.pane.id;break}}const ke={};ce.panes.forEach(We=>{const ve=pe[We.id];if(!ve)return;const Ye=We.series.filter(Je=>Je.showInTooltip!==!1).map(Je=>Lt(Je,ae)),it=Ye.find(Je=>Number.isFinite(Je.value??NaN)),Ke=je.get(We.id),xt=x==="pointer"?We.id===Ne:!0;let et=null;if(x==="pointer"&&Ke&&xt){const Je=he-Ke.y,ct=Math.max(0,Math.min(Je,Ke.height));et=Number.isFinite(ct)?ct:0}else it?et=ve.scale(it.value):et=ve.scale(ve.domain[0]);ke[We.id]={y:et,series:Ye,lineVisible:x==="pointer"?xt&&Ke!=null:!0}});const Oe=xe(ae);if(v({time:Oe,x:we(ae),perPane:ke}),(Ee=ce.onCrosshairMove)==null||Ee.call(ce,Oe),D||w)for(const[We,ve]of je.entries()){const Se=ve.y+ve.height;if(he>=ve.y&&he<=Se){const Ye=pe[We];if(Ye){const it=he-ve.y,Ke=Ye.invert(it);Number.isFinite(Ke)&&(D==null||D({time:Oe,price:Ke,paneId:We,screenX:B.clientX,screenY:B.clientY}),w==null||w({time:Oe,price:Ke}))}break}}},[j,E,X,we,be,ce,pe,xe,je,x,D,w]),Re=s.useCallback(()=>{v(null)},[]),ze=s.useCallback(B=>{var fe,de;if(!j||!E.current)return;let oe,ye;if(V)oe=V.time,ye=V.perPane;else{const me=E.current.getBoundingClientRect(),ae=B.clientX-me.left,he=Math.max(0,Math.min(ae,Math.max(0,X))),Ne=we.invert(he),ke=Ne instanceof Date?Ne.valueOf():Ne;if(!Number.isFinite(ke))return;const Oe=nt(be,ke);if(!Number.isFinite(Oe))return;const Ee=B.clientY-me.top;let We=null;if(x==="pointer")for(const Se of je.values()){const Ye=Se.y+Se.height;if(Ee>=Se.y&&Ee<=Ye){We=Se.pane.id;break}}ye={},ce.panes.forEach(Se=>{const Ye=pe[Se.id];if(!Ye)return;const Ke=Se.series.filter(lt=>lt.showInTooltip!==!1).map(lt=>Lt(lt,Oe)),xt=Ke.find(lt=>Number.isFinite(lt.value??NaN)),et=je.get(Se.id),Je=x==="pointer"?Se.id===We:!0;let ct=null;if(x==="pointer"&&et&&Je){const lt=Ee-et.y,_t=Math.max(0,Math.min(lt,et.height));ct=Number.isFinite(_t)?_t:0}else xt?ct=Ye.scale(xt.value):ct=Ye.scale(Ye.domain[0]);ye[Se.id]={y:ct,series:Ke,lineVisible:x==="pointer"?Je&&et!=null:!0}}),oe=xe(Oe)}if($){const me=E.current.getBoundingClientRect(),ae=B.clientY-me.top;for(const[he,Ne]of je.entries()){const ke=Ne.y+Ne.height;if(ae>=Ne.y&&ae<=ke){const Oe=pe[he];if(Oe){const Ee=ae-Ne.y,We=Oe.invert(Ee);Number.isFinite(We)&&$({time:oe,price:We,paneId:he,screenX:B.clientX,screenY:B.clientY})}break}}}for(const me of ce.panes){const ae=ye[me.id],he=(ae==null?void 0:ae.series)??[],Ne=new Map;he.forEach(ve=>{ve&&ve.key&&Ne.set(ve.key,ve)});const ke=me.series.map(ve=>{const Se=Ne.get(ve.key);if(Se)return Se;const Ye=Lt(ve,oe);return Ne.set(ve.key,Ye),Ye});let Oe=null,Ee=null;for(const ve of ke){if(!ve||ve.raw==null)continue;const Se=me.series.find(Ye=>Ye.key===ve.key);if(Se&&typeof Se.onClick=="function"){Oe=ve,Ee=Se;break}}if(!Oe){const ve=ke.find(Se=>Se&&Se.raw!=null);if(!ve)continue;Oe=ve,Ee=me.series.find(Se=>Se.key===ve.key)??null}if(!Oe)continue;const We=Oe.raw;if(!Ee){(fe=ce.onSeriesPointClick)==null||fe.call(ce,{paneId:me.id,seriesKey:Oe.key,time:oe,raw:We});return}if(typeof Ee.onClick=="function")try{Ee.onClick(We)}catch(ve){console.error("DWLFChart: series onClick handler threw",ve)}(de=ce.onSeriesPointClick)==null||de.call(ce,{paneId:me.id,seriesKey:Ee.key,time:oe,raw:We});return}},[j,E,V,ce,X,we,be,pe,je,x,xe,$]),Ve=s.useCallback(B=>{N(bt(B))},[]),Ie=s.useCallback(B=>{N(oe=>({...oe,panes:[...oe.panes,Or(B)]}))},[]),qe=s.useCallback(B=>{N(oe=>({...oe,panes:oe.panes.filter(ye=>ye.id!==B)}))},[]),st=s.useCallback((B,oe)=>{N(ye=>({...ye,panes:ye.panes.map(fe=>{if(fe.id!==B)return fe;const de={...fe,...oe};return oe.series&&(de.series=oe.series.map(Nt)),oe.guides&&(de.guides=oe.guides.map(me=>({...me}))),de})}))},[]),rt=s.useCallback((B,oe)=>{N(ye=>({...ye,panes:ye.panes.map(fe=>{if(fe.id!==B)return fe;const de=fe.series.some(me=>me.key===oe.key)?fe.series.map(me=>me.key===oe.key?Nt(oe):me):[...fe.series,Nt(oe)];return{...fe,series:de}})}))},[]),ot=s.useCallback((B,oe,ye)=>{N(fe=>({...fe,panes:fe.panes.map(de=>{if(de.id!==B)return de;const me=de.series.map(ae=>ae.key===oe?{...ae,data:Array.isArray(ye)?[...ye]:[]}:ae);return{...de,series:me}})}))},[]),pt=s.useCallback((B,oe)=>{N(ye=>({...ye,panes:ye.panes.map(fe=>fe.id===B?{...fe,series:fe.series.filter(de=>de.key!==oe)}:fe)}))},[]),ht=s.useCallback((B,oe)=>{N(ye=>({...ye,panes:ye.panes.map(fe=>fe.id===B?{...fe,guides:[...fe.guides??[],{...oe}]}:fe)}))},[]),Mt=s.useCallback((B,oe)=>{N(ye=>({...ye,panes:ye.panes.map(fe=>fe.id===B?{...fe,guides:(fe.guides??[]).filter(de=>de.y!==oe)}:fe)}))},[]),mt=s.useCallback(B=>{S(!!B),B||v(null)},[]),Ft=s.useCallback(()=>{W&&Q()},[W,Q]),wt=s.useCallback(()=>{W&&le()},[W,le]),kt=s.useCallback(()=>{W&&G()},[W,G]),ut=s.useCallback(()=>{W&&se()},[W,se]),yt=s.useCallback(()=>{W&&re()},[W,re]),gt=s.useCallback(B=>{!W||!H.onMouseDown||H.onMouseDown(B)},[W,H]),Dt=s.useCallback(B=>{!W||!H.onMouseMove||H.onMouseMove(B)},[W,H]),Pr=s.useCallback(B=>{!W||!H.onMouseUp||H.onMouseUp(B)},[W,H]),Er=s.useCallback(B=>{!W||!H.onMouseLeave||H.onMouseLeave(B)},[W,H]);s.useImperativeHandle(A,()=>({setSpec:Ve,addPane:Ie,removePane:qe,updatePane:st,addSeries:rt,updateSeries:ot,removeSeries:pt,addGuide:ht,removeGuide:Mt,enableSharedCrosshair:mt,zoomIn:Ft,zoomOut:wt,resetView:kt,panToStart:ut,panToEnd:yt}),[Ve,Ie,qe,st,rt,ot,pt,ht,Mt,mt,Ft,wt,kt,ut,yt]);const Ot=r?"#0f172a":"#ffffff",jt=r?"rgba(148, 163, 184, 0.12)":"rgba(15, 23, 42, 0.08)",Wt=s.useMemo(()=>r?(m==null?void 0:m.dark)??"#94a3b8":(m==null?void 0:m.light)??"#475569",[m,r]),Pt=s.useMemo(()=>(r?m==null?void 0:m.dark:m==null?void 0:m.light)??(r?"#f1f5f9":"#0f172a"),[m,r]),Ct=r?"#e2e8f0":"#1f2937",Vt=r?"rgba(15, 23, 42, 0.9)":"rgba(255,255,255,0.95)",Sr=["dwlf-chart-container",u,h?"fade-transition":"",(h==null?void 0:h.phase)||""].filter(Boolean).join(" ");return l.jsxs("div",{ref:te,className:Sr,style:{position:"relative",width:"100%",height:"100%",background:Ot,...o??{}},children:[l.jsxs("svg",{ref:E,width:X,height:q,className:"dwlf-chart-svg",onClick:ze,onMouseDown:gt,onMouseMove:B=>{W&&Dt(B),Ge(B)},onMouseUp:Pr,onMouseLeave:B=>{W&&Er(B),Re()},children:[l.jsx("rect",{x:0,y:0,width:X,height:q,fill:Ot}),De.map(({pane:B,y:oe,height:ye})=>{var ae;const fe=pe[B.id];if(!fe)return null;const de=Le.scaleLinear().domain(fe.domain).ticks(4),me=Pe==null?void 0:Pe.perPane[B.id];return l.jsxs("g",{transform:`translate(0, ${oe})`,children:[l.jsx("rect",{x:0,y:0,width:X,height:ye,fill:Ot}),n&&Me.map((he,Ne)=>l.jsx("line",{x1:we(he),x2:we(he),y1:0,y2:ye,stroke:jt,strokeWidth:1},`x-grid-${he}-${Ne}`)),n&&de.map((he,Ne)=>{const ke=fe.scale(he);return Number.isFinite(ke)?l.jsx("line",{x1:0,x2:X,y1:ke,y2:ke,stroke:jt,strokeWidth:1},`y-grid-${he}-${Ne}`):null}),(ae=B.guides)==null?void 0:ae.map((he,Ne)=>{const ke=fe.scale(he.y);let Oe=0,Ee=X;if(he.startTime!==void 0&&Number.isFinite(he.startTime)){const We=we(he.startTime);Number.isFinite(We)&&(Oe=Math.max(0,We))}if(he.endTime!==void 0&&Number.isFinite(he.endTime)){const We=we(he.endTime);Number.isFinite(We)&&(Ee=Math.min(X,We))}return Oe>=X||Ee<=0||Oe>=Ee?null:l.jsxs("g",{children:[l.jsx("line",{x1:Oe,x2:Ee,y1:ke,y2:ke,stroke:he.color??jt,strokeDasharray:he.dashed?"4 4":void 0}),he.label&&l.jsx("text",{x:Oe+12,y:ke-4,fill:Wt,fontSize:11,children:he.label})]},`${he.y}-${Ne}`)}),B.series.map(he=>l.jsx(s.Fragment,{children:si(he,fe,we,X,r,h)},he.key)),B.id==="price"&&d.length>0&&l.jsx(vr,{annotations:d,xScale:we,yScale:fe,chartWidth:X,paneHeight:ye,darkMode:r,selectedAnnotationId:F,onAnnotationSelect:k,onAnnotationMove:R,onAnnotationTextEdit:p,onAnnotationDoubleClick:M,timeToIndex:ee,indexToTime:ie,dataLength:(P==null?void 0:P.indexToRaw.length)??be.length,compressedTimes:P==null?void 0:P.indexToRaw,currentTimeframe:f,animationPhase:h==null?void 0:h.phase}),Pe&&me&&b&&!B.hideYAxis&&me.lineVisible!==!1&&Number.isFinite(me.y??NaN)&&(()=>{const Ee=Math.max(0,X-72-4),We=me.y,ve=Math.max(11,Math.min(ye-9-2,We)),Se=ve-9,Ye=fe.invert(ve);if(!Number.isFinite(Ye))return null;const it=Ze(Ye);return l.jsxs("g",{className:"dwlf-crosshair-price-label",children:[l.jsx("rect",{x:Ee,y:Se,width:72,height:18,rx:4,ry:4,fill:Vt,stroke:Pt,strokeWidth:1}),l.jsx("text",{x:Ee+72/2,y:ve,fill:Ct,fontSize:11,textAnchor:"middle",alignmentBaseline:"middle",children:it})]})})(),me&&me.lineVisible!==!1&&Number.isFinite(me.y??NaN)&&l.jsx("line",{x1:0,x2:X,y1:me.y,y2:me.y,stroke:Pt,strokeWidth:1.5,strokeDasharray:"3 3"}),!B.hideYAxis&&l.jsx("g",{className:"dwlf-y-axis",transform:`translate(${X-40}, 0)`,children:de.map((he,Ne)=>l.jsx("text",{x:0,y:fe.scale(he),fill:Wt,fontSize:11,alignmentBaseline:"middle",children:Ze(he)},`${he}-${Ne}`))}),B.title&&l.jsx("text",{x:12,y:14,fill:Ct,fontSize:12,fontWeight:600,children:B.title})]},B.id)}),Pe&&l.jsx("g",{className:"dwlf-crosshair",children:l.jsx("line",{x1:Pe.x,x2:Pe.x,y1:0,y2:q,stroke:Pt,strokeWidth:1.5,strokeDasharray:"3 3"})}),l.jsx("g",{className:"dwlf-x-axis",children:Me.map(B=>l.jsx("text",{x:we(B),y:q-6,fill:Wt,fontSize:10,textAnchor:"middle",children:Ht(xe(B),ce.timeFormatter)},`tick-${B}`))})]}),Pe&&De.map(({pane:B,y:oe,height:ye})=>{const fe=Pe.perPane[B.id];return fe?l.jsxs("div",{className:"dwlf-pane-tooltip",style:{top:oe,left:0,color:Ct,borderColor:jt,backgroundColor:Vt,width:"100%"},children:[l.jsxs("div",{className:"dwlf-pane-tooltip__title",children:[B.title??"Pane"," · ",Ht(Pe.time,ce.timeFormatter)]}),l.jsx("div",{className:"dwlf-pane-tooltip__content",children:fe.series.map(de=>l.jsxs("div",{className:"dwlf-pane-tooltip__row",children:[l.jsx("span",{style:{color:de.color??Ct},children:de.key}),l.jsx("span",{children:de.display})]},de.key))})]},`tooltip-${B.id}`):null})]})}),ci={},li=(e,t,r)=>Math.max(t,Math.min(r,e));function ni(e,t,r,n="daily",u=!1){const o=e.filter(h=>!h._virtual),c=e.map(h=>new Date(h.date));o.map(h=>new Date(h.date));const f=c.filter(h=>isNaN(h.getTime()));f.length>0&&(typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:Et&&Et.tagName.toUpperCase()==="SCRIPT"&&Et.src||new URL("index.cjs",document.baseURI).href}>"u"||!ci)&&console.error("Found invalid dates in useCandlestickChart:",f);const i=new Map;for(let h=0;h<o.length;h++){const A=new Date(o[h].date).getTime();i.set(A,h)}const a=Le.extent(c),y=Math.max(0,((e==null?void 0:e.length)||0)-o.length),m=Math.max(0,o.length-1+y),x=Le.scaleLinear().domain([0,m]).range([0,t]),b=Le.scaleTime().domain(a).range([0,t]),d=(function(){if(!u)return b;const A=o.map(j=>new Date(j.date).getTime()),I=Le.bisector(j=>j).left,N=j=>{if(j instanceof Date){const S=j.getTime();let V;return i.has(S)?V=i.get(S):(V=I(A,S),V=Math.max(0,Math.min(o.length-1,V))),x(V)}return x(j)};return N.invert=j=>x.invert(j),N})(),F=Le.min(o,h=>h.low),k=Le.max(o,h=>h.high),p=(k-F||1)*.2,M=Le.scaleLinear().domain([F-p,k+p]).range([r,0]),$=(n||"").toLowerCase();let D;if(o.length>1){let h=1/0,A=null;for(let V=0;V<o.length;V++){const v=o[V],z=d(new Date(v.date));if(A!==null){const X=z-A;X>0&&(h=Math.min(h,X))}A=z}(!isFinite(h)||h<=0)&&(h=t/Math.max(1,o.length-1));const N=h*($==="hourly"?.75:.8),[j,S]=$==="hourly"?[.5,12]:[2,18];D=li(N,j,S)}else D=$==="hourly"?Math.max(1,t*.006):Math.max(6,t*.012);return{xScale:d,yScale:M,getCandleProps:h=>{const A=M(h.open),I=M(h.close);let N;if(u){const j=new Date(h.date).getTime(),S=i.has(j)?i.get(j):0;N=x(S)}else N=b(new Date(h.date));return{x:N,y:Math.min(A,I),height:Math.abs(A-I),width:D,color:h.close>=h.open?"green":"red"}},xBandwidth:D,_compressed:u,_indexToDate:o.map(h=>new Date(h.date))}}function oi({width:e,height:t,margin:r}){const n=e,u=t,o=n-r.left-r.right,c=u-r.top-r.bottom;return{margin:r,fullWidth:n,fullHeight:u,innerWidth:o,innerHeight:c,chartTransform:`translate(${r.left}, ${r.top})`}}function ui(e,t=50){const[r,n]=s.useState(Math.max(0,e.length-t)),[u,o]=s.useState(e.length),[c,f]=s.useState(!1),[i,a]=s.useState(0),[y,m]=s.useState(0),x=s.useRef(),b=e.slice(r,u),d=u-r,F=s.useCallback(N=>{f(!0),a(N.clientX),N.preventDefault()},[]),k=s.useCallback(N=>{if(!c)return;const j=N.clientX-i,S=x.current;if(!S)return;const V=S.getBoundingClientRect(),v={left:50,right:20},z=V.width-v.left-v.right,X=z/d,K=z-X,E=L=>Math.max(-K,Math.min(0,L));let q=j;const _=u>=e.length;if(y!==0&&Math.sign(j)!==Math.sign(y)){const L=y+j,O=E(L),Y=O-y;m(O),q=j-Y}if(_&&q<0){const L=y+q,O=E(L),Y=O-y;m(O),q-=Y}if(q!==0){const L=Math.round(q/(X*1.5));if(L!==0){const O=Math.max(0,r-L),Y=Math.min(e.length,O+d),ne=Math.max(0,Y-d);n(ne),o(Y),m(0)}}u<e.length&&y!==0&&m(0),a(N.clientX)},[c,i,r,d,y,e.length]),R=s.useCallback(()=>{f(!1)},[]),p=s.useCallback(N=>{N.preventDefault();const j=Math.abs(N.deltaX)>Math.abs(N.deltaY),S=N.currentTarget.getBoundingClientRect(),V={left:50,right:20},v=S.width-V.left-V.right;if(j){const se=v/d,re=Math.round(N.deltaX/(se*1.5));if(re!==0){const U=Math.max(0,r-re),C=Math.min(e.length,U+d),T=Math.max(0,C-d);n(T),o(C),m(0)}return}const X=(N.clientX-S.left-V.left-y)/v,K=r+X*d,E=u-r,_=1+N.deltaY*.002,L=_<=0?.1:_;let O=Math.round(E*L);if(O=Math.max(5,Math.min(e.length,O)),O===E)return;let g=Math.max(0,Math.min(e.length-1,K))-O*X;g=Math.max(0,Math.min(e.length-O,g));const W=g+O;n(Math.floor(g)),o(Math.floor(W));const ge=v/E,H=v/O;let J=y*(H/ge);const Q=H*.7,le=v-Q,G=Math.max(-le,Math.min(0,J));G!==y&&m(G)},[r,u,d,e.length,y]),M=s.useCallback(N=>{x.current&&x.current.removeEventListener("wheel",p),x.current=N,N&&N.addEventListener("wheel",p,{passive:!1})},[p]),$={onMouseDown:F,onMouseMove:k,onMouseUp:R,onMouseLeave:R},D=s.useCallback(()=>{const N=u-r,j=(r+u)/2,S=Math.max(10,N*.8),V=Math.max(0,j-S/2),v=Math.min(e.length,V+S);n(Math.floor(V)),o(Math.floor(v))},[r,u,e.length]),w=s.useCallback(()=>{const N=u-r,j=(r+u)/2,S=Math.min(e.length,N*1.25),V=Math.max(0,j-S/2),v=Math.min(e.length,V+S);n(Math.floor(V)),o(Math.floor(v))},[r,u,e.length]),h=s.useCallback(()=>{n(Math.max(0,e.length-t)),o(e.length),m(0)},[e.length,t]),A=s.useCallback(()=>{n(0),o(Math.min(e.length,d))},[e.length,d]),I=s.useCallback(()=>{n(Math.max(0,e.length-d)),o(e.length)},[e.length,d]);return{visibleData:b,viewportStart:r,viewportEnd:u,visibleCount:d,mouseHandlers:$,chartElementRef:M,zoomIn:D,zoomOut:w,resetView:h,panToStart:A,panToEnd:I,isPanning:c,pixelOffset:y}}function ai(e,t={}){const r=s.useMemo(()=>fi.reduce((a,y)=>(a[y.id]=y,a),{}),[]),[n,u]=s.useState(new Set),o=s.useCallback(a=>{u(y=>{const m=new Set(y);return m.has(a)?m.delete(a):m.add(a),m})},[]),c=s.useMemo(()=>Array.from(n).map(a=>{const y=r[a];return y==null?void 0:y.generator(e,t)}).filter(Boolean),[n,r,e,t]),f=s.useCallback(a=>n.has(a),[n]);return{overlayDefinitions:r,activeKeys:n,overlays:c,toggleOverlay:o,toggleOverlayById:a=>{o(a)},isOverlayActive:f}}const fi=[{id:"sma20",label:"SMA 20",generator:(e,t)=>({type:"line",label:"sma20",data:t.sma20||[],color:"orange"})},{id:"sma50",label:"SMA 50",generator:(e,t)=>({type:"line",label:"sma50",data:t.sma50||[],color:"blue"})}],vt=["ema-10","ema-20","sma-10","sma-20","bollinger-upper","bollinger-middle","bollinger-lower","ema-50","sma-50","ema-200","sma-200"],Yt=vt.reduce((e,t)=>(e[t]=1,e),{});function di(e={}){const{totalCandles:t=0,animationSpeed:r=1,autoStart:n=!1,staggerDelay:u=100,onPhaseChange:o,onAnimationComplete:c}=e,f=Math.max(.1,Math.min(5,r)),i=s.useRef(o),a=s.useRef(c),y=s.useRef(f),m=s.useRef(!1),x=s.useRef("idle");s.useEffect(()=>{i.current=o},[o]),s.useEffect(()=>{a.current=c},[c]),s.useEffect(()=>{y.current=f},[f]);const[b,d]=s.useState({phase:n?"background":"idle",candleRevealIndex:0,layerOpacities:{},staggerDelay:u,isReducedMotion:!1});s.useEffect(()=>{x.current=b.phase},[b.phase]),s.useEffect(()=>{d(D=>({...D,staggerDelay:u}))},[u]);const F=s.useRef(!1);s.useEffect(()=>{const D=window.matchMedia("(prefers-reduced-motion: reduce)");m.current=D.matches,d(h=>({...h,isReducedMotion:D.matches}));const w=h=>{m.current=h.matches,d(A=>({...A,isReducedMotion:h.matches}))};return D.addEventListener("change",w),()=>D.removeEventListener("change",w)},[]),s.useEffect(()=>{var D,w;b.isReducedMotion&&b.phase!=="idle"&&b.phase!=="complete"&&(F.current=!1,x.current="complete",d(h=>({...h,phase:"complete",candleRevealIndex:Math.max(0,t-1),layerOpacities:{...Yt}})),(D=i.current)==null||D.call(i,"complete"),(w=a.current)==null||w.call(a))},[b.isReducedMotion,b.phase,t]),s.useEffect(()=>{if(b.phase!=="background")return;const D=setTimeout(()=>{var w;d(h=>({...h,phase:"candles"})),(w=i.current)==null||w.call(i,"candles")},u/y.current);return()=>clearTimeout(D)},[b.phase,u]),s.useEffect(()=>{var N;if(b.phase!=="candles")return;if(t===0){d(j=>({...j,phase:"indicators"})),(N=i.current)==null||N.call(i,"indicators");return}let D=null,w;const A=Math.max(30,t/2),I=j=>{var v;D===null&&(D=j);const S=(j-D)/1e3,V=Math.min(Math.floor(S*A*y.current),t-1);if(d(z=>({...z,candleRevealIndex:V})),V>=t-1){d(z=>({...z,phase:"indicators"})),(v=i.current)==null||v.call(i,"indicators");return}w=requestAnimationFrame(I)};return w=requestAnimationFrame(I),()=>cancelAnimationFrame(w)},[b.phase,t]),s.useEffect(()=>{if(b.phase!=="indicators")return;const D=80,w=[];vt.forEach((I,N)=>{const j=setTimeout(()=>{d(S=>({...S,layerOpacities:{...S.layerOpacities,[I]:1}}))},N*D/y.current);w.push(j)});const h=(vt.length*D+100)/y.current,A=setTimeout(()=>{var I;d(N=>({...N,phase:"events"})),(I=i.current)==null||I.call(i,"events")},h);return w.push(A),()=>w.forEach(I=>clearTimeout(I))},[b.phase]),s.useEffect(()=>{if(b.phase!=="events")return;const D=setTimeout(()=>{var w;d(h=>({...h,phase:"annotations"})),(w=i.current)==null||w.call(i,"annotations")},400/y.current);return()=>clearTimeout(D)},[b.phase]),s.useEffect(()=>{if(b.phase!=="annotations")return;const D=setTimeout(()=>{var w,h;d(A=>({...A,phase:"complete"})),(w=i.current)==null||w.call(i,"complete"),(h=a.current)==null||h.call(a)},200/y.current);return()=>clearTimeout(D)},[b.phase]);const k=s.useCallback(()=>{var h,A;const D=x.current,w=D!=="complete"&&D!=="idle";F.current=!1,x.current="complete",d(I=>({...I,phase:"complete",candleRevealIndex:Math.max(0,t-1),layerOpacities:{...Yt}})),w&&((h=i.current)==null||h.call(i,"complete"),(A=a.current)==null||A.call(a))},[t]),R=s.useCallback(()=>{var D,w,h;if(m.current){F.current=!1,d(A=>({...A,phase:"complete",candleRevealIndex:Math.max(0,t-1),layerOpacities:{...Yt}})),(D=i.current)==null||D.call(i,"complete"),(w=a.current)==null||w.call(a);return}F.current=!0,d(A=>({...A,phase:"background",candleRevealIndex:0,layerOpacities:{}})),(h=i.current)==null||h.call(i,"background")},[t]),p=s.useCallback(()=>{var D;F.current=!1,d(w=>({...w,phase:"idle",candleRevealIndex:0,layerOpacities:{}})),(D=i.current)==null||D.call(i,"idle")},[]),M=s.useCallback(D=>{y.current=Math.max(.1,Math.min(5,D))},[]),$=s.useMemo(()=>({startAnimation:R,skipToEnd:k,resetAnimation:p,setAnimationSpeed:M}),[R,k,p,M]);return s.useEffect(()=>{n&&t>0&&b.phase==="idle"&&!F.current&&R()},[n,t,b.phase,R]),{animationState:b,controls:$}}function hi(e,t){if(!Array.isArray(e)||e.length<t)return[];const r=[];for(let n=t-1;n<e.length;n++){const c=e.slice(n-t+1,n+1).reduce((f,i)=>f+i.close,0)/t;r.push({x:e[n].date,y:c})}return r}function mi(e,t){if(!Array.isArray(e)||e.length<t)return[];const r=[],n=2/(t+1);let u=e.slice(0,t).reduce((o,c)=>o+c.close,0)/t;r.push({x:e[t-1].date,y:u});for(let o=t;o<e.length;o++)u=e[o].close*n+u*(1-n),r.push({x:e[o].date,y:u});return r}exports.ANNOTATION_COLORS=Us;exports.AlertLineAnnotationView=wr;exports.AnnotationLayer=vr;exports.ArrowAnnotationView=hr;exports.BosLineAnnotationView=Nr;exports.BrushAnnotationView=kr;exports.ChannelAnnotationView=mr;exports.CrossLineAnnotationView=ur;exports.DWLFChart=ii;exports.EmojiAnnotationView=fr;exports.FIB_EXTENSIONS_DEFAULT=gr;exports.FIB_LEVELS_DEFAULT=yr;exports.FairValueGapAnnotationView=Rr;exports.FibExtensionAnnotationView=jr;exports.FibRetracementAnnotationView=br;exports.HLineAnnotationView=cr;exports.INDICATOR_ANIMATION_ORDER=vt;exports.MeasureAnnotationView=pr;exports.OrderBlockAnnotationView=Cr;exports.PitchforkAnnotationView=Dr;exports.RayAnnotationView=or;exports.RectangleAnnotationView=ar;exports.TextAnnotationView=nr;exports.TimeRangeAnnotationView=dr;exports.TrendLineAnnotationView=At;exports.VLineAnnotationView=lr;exports.calculateEMA=mi;exports.calculateSMA=hi;exports.createAlertLineAnnotation=As;exports.createArrowAnnotation=$s;exports.createBosLineAnnotation=Is;exports.createBrushAnnotation=Vs;exports.createChannelAnnotation=Xs;exports.createCrossLineAnnotation=Ws;exports.createEmojiAnnotation=Es;exports.createFairValueGapAnnotation=Bs;exports.createFibExtensionAnnotation=zs;exports.createFibRetracementAnnotation=Ls;exports.createHLineAnnotation=Ns;exports.createMeasureAnnotation=Ys;exports.createOrderBlockAnnotation=Ts;exports.createPitchforkAnnotation=_s;exports.createRayAnnotation=Os;exports.createRectangleAnnotation=Ps;exports.createTextAnnotation=Ms;exports.createTimeRangeAnnotation=Ss;exports.createTrendLineAnnotation=Fs;exports.createVLineAnnotation=vs;exports.useCandlestickChart=ni;exports.useChartAnimations=di;exports.useChartLayout=oi;exports.useChartPanZoom=ui;exports.useChartPanZoomVirtual=tr;exports.useContainerSize=rr;exports.useOverlayToggles=ai;
|