@dwlf/charting 1.0.0 → 1.1.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/README.md +184 -19
- package/dist/charting/__tests__/chartSpec.test.d.ts +1 -0
- package/dist/charting/scales.d.ts +14 -0
- package/dist/charting/types.d.ts +454 -0
- package/dist/charting.css +1 -1
- package/dist/components/DWLFChart.d.ts +119 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/overlays/AlertLineAnnotationView.d.ts +14 -0
- package/dist/components/overlays/AnnotationLayer.d.ts +55 -0
- package/dist/components/overlays/ArrowAnnotationView.d.ts +24 -0
- package/dist/components/overlays/BosLineAnnotationView.d.ts +22 -0
- package/dist/components/overlays/BrushAnnotationView.d.ts +20 -0
- package/dist/components/overlays/ChannelAnnotationView.d.ts +23 -0
- package/dist/components/overlays/CrossLineAnnotationView.d.ts +29 -0
- package/dist/components/overlays/DiagonalLineOverlay.d.ts +31 -0
- package/dist/components/overlays/EmojiAnnotationView.d.ts +22 -0
- package/dist/components/overlays/FairValueGapAnnotationView.d.ts +23 -0
- package/dist/components/overlays/FibExtensionAnnotationView.d.ts +19 -0
- package/dist/components/overlays/FibRetracementAnnotationView.d.ts +19 -0
- package/dist/components/overlays/HLineAnnotationView.d.ts +15 -0
- package/dist/components/overlays/HorizontalLineOverlay.d.ts +23 -0
- package/dist/components/overlays/MarkerOverlay.d.ts +66 -0
- package/dist/components/overlays/MeasureAnnotationView.d.ts +25 -0
- package/dist/components/overlays/MessageBubbleOverlay.d.ts +55 -0
- package/dist/components/overlays/OrderBlockAnnotationView.d.ts +23 -0
- package/dist/components/overlays/PitchforkAnnotationView.d.ts +19 -0
- package/dist/components/overlays/PositionOverlay.d.ts +52 -0
- package/dist/components/overlays/RayAnnotationView.d.ts +30 -0
- package/dist/components/overlays/RectangleAnnotationView.d.ts +23 -0
- package/dist/components/overlays/SMAOverlay.d.ts +20 -0
- package/dist/components/overlays/TextAnnotationView.d.ts +24 -0
- package/dist/components/overlays/TimeRangeAnnotationView.d.ts +22 -0
- package/dist/components/overlays/TrendLineAnnotationView.d.ts +23 -0
- package/dist/components/overlays/VLineAnnotationView.d.ts +26 -0
- package/dist/components/overlays/annotationConstants.d.ts +21 -0
- package/dist/components/overlays/annotationUtils.d.ts +13 -0
- package/dist/components/overlays/useAnnotationDrag.d.ts +18 -0
- package/dist/components/overlays/usePointAnnotationDrag.d.ts +23 -0
- package/dist/hooks/useCandlestickChart.d.ts +18 -0
- package/dist/hooks/useChartAnimations.d.ts +49 -0
- package/dist/hooks/useChartLayout.d.ts +12 -0
- package/dist/hooks/useChartPanZoom.d.ts +7 -0
- package/dist/hooks/useChartPanZoomVirtual.d.ts +24 -0
- package/dist/hooks/useContainerSize.d.ts +4 -0
- package/dist/hooks/useOverlayToggles.d.ts +19 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +56 -0
- package/dist/index.js +13 -13
- package/dist/utils/indicators.d.ts +40 -0
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),s=require("react"),Xr=require("d3"),oe=require("prop-types");var Et=typeof document<"u"?document.currentScript:null;function Sr(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=Sr(Xr);function Jt({points:e=[],xScale:t,yScale:r,xBandwidth:n=0,shape:o="arrow-up",size:u=6,color:c="black",offsetY:f=0,text:i,fontSize:a=10,textColor:y=c,textOffsetY:m=0,onMarkerClick:b,animationPhase:x,staggerDelay:h=100,staggerStartIndex:F=0}){const[D,N]=s.useState(null),p=s.useRef(null);if(s.useEffect(()=>{const d=E=>{p.current&&!p.current.contains(E.target)&&N(null)};if(D)return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[D]),!e||e.length===0)return null;const M=(d,E,Y,k)=>{const v=k?"pointer":"default";if(o==="arrow-up"){const $=`M ${d} ${E} l ${-u} ${u} l ${2*u} 0 Z`;return l.jsx("path",{d:$,fill:c,stroke:c,style:{cursor:v}},Y)}if(o==="arrow-down"){const $=`M ${d} ${E} l ${u} ${-u} l ${-2*u} 0 Z`;return l.jsx("path",{d:$,fill:c,stroke:c,style:{cursor:v}},Y)}return o==="none"?null:l.jsx("circle",{cx:d,cy:E,r:u,fill:c,stroke:c,style:{cursor:v}},Y)},S=(d,E,Y)=>{d.tooltip&&N({point:d,cx:E,cy:Y}),b&&b(d)};if(x&&x!=="events"&&x!=="annotations"&&x!=="complete")return null;const w=x==="events"?"marker-overlay marker-overlay-animated":"marker-overlay";return l.jsxs("g",{className:w,children:[e.map((d,E)=>{let Y;typeof d.date=="number"||d.date instanceof Date?Y=d.date:Y=new Date(d.date);const k=t(Y),v=r(d.price)+f,$=d.text||i,B=v+u+4+m,R=!!d.tooltip,I=Number.isFinite(d.animationOrder)?d.animationOrder:F+E,X=x==="events"?I*h:0,J={cursor:R?"pointer":"default",animationDelay:x==="events"?`${X}ms`:void 0};return l.jsxs("g",{className:x==="events"?"dwlf-marker-drop":"",onClick:R?()=>S(d,k,v):void 0,style:J,children:[M(k,v,`marker-${E}`,R),$&&l.jsx("text",{x:k,y:B,textAnchor:"middle",fontSize:a,fill:y,style:{cursor:R?"pointer":"default",pointerEvents:R?"auto":"none"},children:$})]},E)}),D&&l.jsx("g",{ref:p,children:l.jsx("foreignObject",{x:D.cx-150,y:D.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:D.point.tooltip})})})]})}Jt.propTypes={points:oe.arrayOf(oe.shape({date:oe.oneOfType([oe.number,oe.string,oe.instanceOf(Date)]).isRequired,price:oe.number.isRequired,text:oe.string,tooltip:oe.string})),xScale:oe.func.isRequired,yScale:oe.func.isRequired,xBandwidth:oe.number,shape:oe.oneOf(["arrow-up","arrow-down","circle","none"]),size:oe.number,color:oe.string,offsetY:oe.number,text:oe.string,fontSize:oe.number,textColor:oe.string,textOffsetY:oe.number,onMarkerClick:oe.func,animationPhase:oe.string,staggerDelay:oe.number,staggerStartIndex:oe.number};function Qt({messages:e=[],xScale:t,yScale:r,xBandwidth:n=0,chartWidth:o,chartHeight:u,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||!o||!u)return null;const m=i*.6,b=8,x=e.map((h,F)=>{let D;typeof h.date=="number"||h.date instanceof Date?D=h.date:D=new Date(h.date);const N=t(D),p=r(h.price),M=`${h.text}`.split(`
|
|
2
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
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??"#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)??"#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)??(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,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,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,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,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,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,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,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,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,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,value:null,display:n,raw:r}},ii=s.forwardRef(function({spec:t,darkMode:r=!1,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;
|
|
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=!1,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;
|