@cedros/trade-react 0.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/dist/index.cjs ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),g=require("react"),ke=require("./apiClient-CdeF3SAW.cjs"),Us=g.createContext(null);function Wi({config:n,children:t}){const e=g.useMemo(()=>({api:new ke.TradeApiClient(n.serverUrl,n.getAccessToken,n.apiKey),config:n}),[n.serverUrl,n.apiKey]);return u.jsx(Us.Provider,{value:e,children:t})}function Ee(){const n=g.useContext(Us);if(!n)throw new Error("useTradeContext must be used within <CedrosTradeProvider>");return n}function G(){return Ee().api}function qs(){const n=G(),[t,e]=g.useState(null),[s,i]=g.useState(null),[r,h]=g.useState(null),[o,l]=g.useState(!1),[c,a]=g.useState(null),d=g.useCallback(async(b,y,w,M)=>{l(!0),a(null);try{const S=await n.getQuote({inputMint:b,outputMint:y,amount:w,slippageBps:M});return e(S),S}catch(S){throw a(S.message),S}finally{l(!1)}},[n]),f=g.useCallback(async(b,y)=>{l(!0),a(null);try{const w=await n.buildSwap(b,y);return i(w),w}catch(w){throw a(w.message),w}finally{l(!1)}},[n]),m=g.useCallback(async(b,y,w)=>{l(!0),a(null);try{const M=await n.executeSwap(b,y,w);return h(M),M}catch(M){throw a(M.message),M}finally{l(!1)}},[n]),p=g.useCallback(async(b,y,w)=>{l(!0),a(null);try{return await n.compareQuotes(b,y,w)}catch(M){throw a(M.message),M}finally{l(!1)}},[n]),v=g.useCallback(()=>{e(null),i(null),h(null),a(null)},[]);return{quote:t,transaction:s,result:r,isLoading:o,error:c,getQuote:d,buildTransaction:f,execute:m,compareProviders:p,reset:v}}function Js(){const n=G(),[t,e]=g.useState(null),[s,i]=g.useState(null),[r,h]=g.useState(!1),[o,l]=g.useState(null),c=g.useCallback(async(m,p,v,b,y)=>{h(!0),l(null);try{const w=await n.buildTransfer({sender:m,recipient:p,mint:v,amount:b,memo:y});return e(w),w}catch(w){throw l(w.message),w}finally{h(!1)}},[n]),a=g.useCallback(async m=>{h(!0),l(null);try{const p=await n.executeTransfer(m);return i(p),p}catch(p){throw l(p.message),p}finally{h(!1)}},[n]),d=g.useCallback(async m=>n.resolveAddress(m),[n]),f=g.useCallback(()=>{e(null),i(null),l(null)},[]);return{buildResult:t,executeResult:s,isLoading:r,error:o,build:c,execute:a,resolveAddress:d,reset:f}}function Le(n){const t=G(),[e,s]=g.useState(null),[i,r]=g.useState(!1),[h,o]=g.useState(null),l=g.useCallback(async()=>{if(n){r(!0),o(null);try{s(await t.getPositions(n))}catch(c){o(c.message)}finally{r(!1)}}},[t,n]);return g.useEffect(()=>{l()},[l]),{positions:e,isLoading:i,error:h,refresh:l}}function Gs(n){const t=G(),[e,s]=g.useState([]),[i,r]=g.useState([]),[h,o]=g.useState(!1),[l,c]=g.useState(null),a=g.useCallback(async()=>{if(n){o(!0),c(null);try{const f=await t.getOpenOrders(n);s(f.limitOrders),r(f.dcaOrders)}catch(f){c(f.message)}finally{o(!1)}}},[t,n]);g.useEffect(()=>{a()},[a]);const d=g.useCallback(async(f,m)=>{const p=await t.cancelOrder(f,m);return await a(),p},[t,a]);return{limitOrders:e,dcaOrders:i,isLoading:h,error:l,refresh:a,cancelOrder:d}}function Di(){const n=G(),[t,e]=g.useState({}),[s,i]=g.useState(!1),[r,h]=g.useState(null),o=g.useRef(new Set),l=g.useRef(),c=g.useCallback(async()=>{const m=Array.from(o.current);if(m.length!==0)try{const{prices:p}=await n.getBatchPrices(m);e(v=>{const b={...v};for(const y of p)b[y.mint]=y;return b})}catch(p){h(p.message)}},[n]),a=g.useCallback(m=>{for(const p of m)o.current.add(p);c()},[c]),d=g.useCallback(m=>{for(const p of m)o.current.delete(p)},[]);g.useEffect(()=>(l.current=setInterval(c,1e4),()=>clearInterval(l.current)),[c]);const f=g.useCallback(async m=>{i(!0);try{const p=await n.getPrice(m);return e(v=>({...v,[m]:p})),p}catch(p){throw h(p.message),p}finally{i(!1)}},[n]);return{prices:t,isLoading:s,error:r,getPrice:f,subscribe:a,unsubscribe:d}}function Qs(){const n=G(),[t,e]=g.useState([]),[s,i]=g.useState(!1),[r,h]=g.useState(null),o=g.useCallback(async()=>{i(!0),h(null);try{const{tokens:a}=await n.getTokens();e(a)}catch(a){h(a.message)}finally{i(!1)}},[n]);g.useEffect(()=>{o()},[o]);const l=g.useCallback(a=>t.find(d=>d.mint===a),[t]),c=g.useCallback(a=>{const d=a.toUpperCase();return t.find(f=>f.symbol.toUpperCase()===d)},[t]);return{tokens:t,isLoading:s,error:r,refresh:o,getByMint:l,getBySymbol:c}}function Ys(){const n=G(),[t,e]=g.useState(!1),[s,i]=g.useState(null);g.useCallback(c=>async()=>{e(!0),i(null);try{return await c()}catch(a){throw i(a.message),a}finally{e(!1)}},[]);const r=g.useCallback(async c=>{e(!0),i(null);try{return await n.createLimitOrder(c)}catch(a){throw i(a.message),a}finally{e(!1)}},[n]),h=g.useCallback(async c=>{e(!0),i(null);try{return await n.createStopLoss(c)}catch(a){throw i(a.message),a}finally{e(!1)}},[n]),o=g.useCallback(async c=>{e(!0),i(null);try{return await n.createTakeProfit(c)}catch(a){throw i(a.message),a}finally{e(!1)}},[n]),l=g.useCallback(async c=>{e(!0),i(null);try{return await n.createDca(c)}catch(a){throw i(a.message),a}finally{e(!1)}},[n]);return{isLoading:t,error:s,createLimit:r,createStopLoss:h,createTakeProfit:o,createDca:l}}function Te(n){const t=G(),[e,s]=g.useState([]),[i,r]=g.useState(!1),[h,o]=g.useState(null);g.useRef(null);const l=g.useCallback(async()=>{if(n){r(!0),o(null);try{s(await t.getPendingActions(n))}catch(d){o(d.message)}finally{r(!1)}}},[t,n]);g.useEffect(()=>{if(!n)return;l();const d=setInterval(l,1e4);return()=>clearInterval(d)},[n,l]);const c=g.useCallback(async(d,f)=>{await t.completeAction(d,f),await l()},[t,l]),a=g.useCallback(async d=>{await t.dismissAction(d),await l()},[t,l]);return{actions:e,count:e.length,isLoading:i,error:h,refresh:l,complete:c,dismiss:a}}function Bi(n,t=!0){const{config:e}=Ee(),[s,i]=g.useState(null),[r,h]=g.useState(!1),[o,l]=g.useState(null),[c,a]=g.useState(!1),d=g.useRef(null),f=g.useCallback(async()=>{if(n){h(!0);try{const m=await fetch(`${e.serverUrl}/orderbook/${n}`);if(!m.ok)throw new Error("Failed to fetch orderbook");i(await m.json())}catch(m){l(m.message)}finally{h(!1)}}},[e.serverUrl,n]);return g.useEffect(()=>{if(!n||!t){f();return}const m=e.serverUrl.replace(/^http/,"ws")+`/ws/orderbook/${n}`,p=new WebSocket(m);return d.current=p,p.onopen=()=>a(!0),p.onmessage=v=>{try{i(JSON.parse(v.data))}catch{}},p.onerror=()=>{a(!1),f()},p.onclose=()=>a(!1),()=>{p.close(),d.current=null}},[n,t,e.serverUrl,f]),{data:s,isLoading:r,error:o,isStreaming:c}}function Pe({isOpen:n,onClose:t,onSelect:e,excludeMints:s=[],className:i=""}){const{tokens:r}=Qs(),[h,o]=g.useState(""),[l,c]=g.useState(()=>{try{return JSON.parse(localStorage.getItem("ct-favorite-tokens")||"[]")}catch{return[]}}),a=g.useMemo(()=>{const p=h.toLowerCase();return r.filter(v=>!s.includes(v.mint)).filter(v=>!p||v.symbol.toLowerCase().includes(p)||v.name.toLowerCase().includes(p)||v.mint.includes(p))},[r,h,s]),d=g.useMemo(()=>r.filter(p=>l.includes(p.mint)),[r,l]),f=g.useCallback(p=>{c(v=>{const b=v.includes(p)?v.filter(y=>y!==p):[...v,p];return localStorage.setItem("ct-favorite-tokens",JSON.stringify(b)),b})},[]),m=g.useCallback(p=>{e(p),t(),o("")},[e,t]);return g.useEffect(()=>{n&&o("")},[n]),n?u.jsx("div",{className:`ct-fixed ct-inset-0 ct-z-50 ct-flex ct-items-center ct-justify-center ct-bg-black/50 ${i}`,onClick:t,children:u.jsxs("div",{className:"ct-bg-[hsl(var(--cedros-background))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded-cedros ct-w-full ct-max-w-md ct-max-h-[80vh] ct-flex ct-flex-col ct-shadow-xl",onClick:p=>p.stopPropagation(),children:[u.jsxs("div",{className:"ct-flex ct-items-center ct-justify-between ct-px-4 ct-py-3 ct-border-b ct-border-[hsl(var(--cedros-border))]",children:[u.jsx("h3",{className:"ct-text-lg ct-font-semibold ct-text-[hsl(var(--cedros-foreground))]",children:"Select Token"}),u.jsx("button",{onClick:t,className:"ct-text-[hsl(var(--cedros-muted-foreground))] hover:ct-text-[hsl(var(--cedros-foreground))] ct-text-xl",children:"×"})]}),u.jsx("div",{className:"ct-px-4 ct-py-3",children:u.jsx("input",{type:"text",placeholder:"Search by name, symbol, or mint...",value:h,onChange:p=>o(p.target.value),className:"ct-w-full ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] ct-placeholder-[hsl(var(--cedros-muted-foreground))] ct-outline-none focus:ct-ring-2 focus:ct-ring-[hsl(var(--cedros-ring))]",autoFocus:!0})}),d.length>0&&!h&&u.jsx("div",{className:"ct-px-4 ct-pb-2 ct-flex ct-flex-wrap ct-gap-2",children:d.map(p=>u.jsx("button",{onClick:()=>m(p),className:"ct-px-3 ct-py-1 ct-rounded-full ct-text-sm ct-bg-[hsl(var(--cedros-muted))] ct-text-[hsl(var(--cedros-foreground))] hover:ct-bg-[hsl(var(--cedros-primary))] hover:ct-text-[hsl(var(--cedros-primary-foreground))] ct-transition",children:p.symbol},p.mint))}),u.jsxs("div",{className:"ct-flex-1 ct-overflow-y-auto ct-px-2 ct-pb-2",children:[a.map(p=>u.jsxs("button",{onClick:()=>m(p),className:"ct-w-full ct-flex ct-items-center ct-gap-3 ct-px-3 ct-py-2 ct-rounded-cedros hover:ct-bg-[hsl(var(--cedros-muted))] ct-transition ct-text-left",children:[p.logoUrl&&u.jsx("img",{src:p.logoUrl,alt:p.symbol,className:"ct-w-8 ct-h-8 ct-rounded-full"}),u.jsxs("div",{className:"ct-flex-1 ct-min-w-0",children:[u.jsx("div",{className:"ct-font-medium ct-text-[hsl(var(--cedros-foreground))]",children:p.symbol}),u.jsx("div",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))] ct-truncate",children:p.name})]}),u.jsx("button",{onClick:v=>{v.stopPropagation(),f(p.mint)},className:"ct-text-lg ct-text-[hsl(var(--cedros-muted-foreground))] hover:ct-text-yellow-400",children:l.includes(p.mint)?"★":"☆"})]},p.mint)),a.length===0&&u.jsx("div",{className:"ct-text-center ct-py-8 ct-text-[hsl(var(--cedros-muted-foreground))]",children:"No tokens found"})]})]})}):null}const Qe=[{label:"0.1%",bps:10},{label:"0.5%",bps:50},{label:"1.0%",bps:100}];function $e({value:n,onChange:t,className:e=""}){const[s,i]=g.useState(!Qe.some(l=>l.bps===n)),[r,h]=g.useState(s?(n/100).toString():""),o=l=>{h(l);const c=parseFloat(l);!isNaN(c)&&c>0&&c<=50&&t(Math.round(c*100))};return u.jsxs("div",{className:`ct-flex ct-items-center ct-gap-2 ${e}`,children:[u.jsx("span",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Slippage"}),u.jsxs("div",{className:"ct-flex ct-gap-1",children:[Qe.map(l=>u.jsx("button",{onClick:()=>{t(l.bps),i(!1)},className:`ct-px-2 ct-py-1 ct-rounded ct-text-xs ct-transition ${n===l.bps&&!s?"ct-bg-[hsl(var(--cedros-primary))] ct-text-[hsl(var(--cedros-primary-foreground))]":"ct-bg-[hsl(var(--cedros-muted))] ct-text-[hsl(var(--cedros-muted-foreground))] hover:ct-bg-[hsl(var(--cedros-border))]"}`,children:l.label},l.bps)),u.jsx("input",{type:"text",placeholder:"Custom",value:s?r:"",onFocus:()=>i(!0),onChange:l=>o(l.target.value),className:"ct-w-16 ct-px-2 ct-py-1 ct-rounded ct-text-xs ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] ct-outline-none focus:ct-ring-1 focus:ct-ring-[hsl(var(--cedros-ring))]"}),u.jsx("span",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"%"})]})]})}function ht({className:n=""}){return u.jsx("div",{className:`ct-inline-block ct-animate-spin ct-rounded-full ct-h-5 ct-w-5 ct-border-2 ct-border-current ct-border-t-transparent ${n}`,role:"status",children:u.jsx("span",{className:"ct-sr-only",children:"Loading..."})})}function Pt({message:n,className:t="",onDismiss:e}){return n?u.jsxs("div",{className:`ct-rounded-cedros ct-bg-red-500/10 ct-border ct-border-red-500/20 ct-px-3 ct-py-2 ct-text-sm ct-text-red-400 ct-flex ct-items-center ct-justify-between ${t}`,children:[u.jsx("span",{children:n}),e&&u.jsx("button",{onClick:e,className:"ct-ml-2 ct-text-red-400 hover:ct-text-red-300 ct-text-lg ct-leading-none",children:"×"})]}):null}const Ii="So11111111111111111111111111111111111111112",Fi="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";function Zs({walletAddress:n,onSign:t,onSuccess:e,onError:s,defaultInputMint:i=Ii,defaultOutputMint:r=Fi,className:h=""}){const{quote:o,isLoading:l,error:c,getQuote:a,buildTransaction:d,execute:f,reset:m}=qs(),[p,v]=g.useState(null),[b,y]=g.useState(null),[w,M]=g.useState(i),[S,N]=g.useState(r),[_,k]=g.useState(""),[C,V]=g.useState(50),[P,H]=g.useState(null),[L,B]=g.useState("quote");g.useEffect(()=>{if(!_||!w||!S)return;const z=setTimeout(()=>{a(w,S,_,C).catch(()=>{})},500);return()=>clearTimeout(z)},[_,w,S,C,a]);const U=g.useCallback(()=>{M(S),N(w);const z=p;v(b),y(z),k(""),m()},[w,S,p,b,m]),tt=g.useCallback(z=>{P==="input"?(M(z.mint),v(z)):(N(z.mint),y(z)),m()},[P,m]),I=g.useCallback(async()=>{if(!(!o||!n||!t))try{B("sign");const z=await d(o,n),A=await t(z.transaction,o.provider,z.requestId??void 0),et=await f(A,o.provider,z.requestId??void 0);B("done"),e==null||e(et.signature)}catch(z){B("quote"),s==null||s(z.message)}},[o,n,t,d,f,e,s]),mt=z=>{if(!z)return"";const A=(b==null?void 0:b.decimals)??6;return(parseInt(z.outAmount)/Math.pow(10,A)).toFixed(A>4?4:A)};return u.jsxs("div",{className:`ct-bg-[hsl(var(--cedros-background))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded-cedros ct-p-4 ct-space-y-4 ${h}`,children:[u.jsx("h3",{className:"ct-text-lg ct-font-semibold ct-text-[hsl(var(--cedros-foreground))]",children:"Swap"}),u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"You pay"}),u.jsxs("div",{className:"ct-flex ct-gap-2",children:[u.jsx("input",{type:"text",value:_,onChange:z=>k(z.target.value),placeholder:"0.00",className:"ct-flex-1 ct-px-3 ct-py-3 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-xl ct-text-[hsl(var(--cedros-foreground))] ct-outline-none focus:ct-ring-2 focus:ct-ring-[hsl(var(--cedros-ring))]"}),u.jsx("button",{onClick:()=>H("input"),className:"ct-px-4 ct-py-3 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] hover:ct-bg-[hsl(var(--cedros-border))] ct-font-medium ct-min-w-[100px]",children:(p==null?void 0:p.symbol)??"SOL"})]})]}),u.jsx("div",{className:"ct-flex ct-justify-center",children:u.jsx("button",{onClick:U,className:"ct-p-2 ct-rounded-full ct-bg-[hsl(var(--cedros-muted))] hover:ct-bg-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-muted-foreground))] ct-transition",children:"↕"})}),u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"You receive"}),u.jsxs("div",{className:"ct-flex ct-gap-2",children:[u.jsx("div",{className:"ct-flex-1 ct-px-3 ct-py-3 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-xl ct-text-[hsl(var(--cedros-foreground))]",children:l?u.jsx(ht,{}):mt(o)}),u.jsx("button",{onClick:()=>H("output"),className:"ct-px-4 ct-py-3 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] hover:ct-bg-[hsl(var(--cedros-border))] ct-font-medium ct-min-w-[100px]",children:(b==null?void 0:b.symbol)??"USDC"})]})]}),o&&u.jsxs("div",{className:"ct-space-y-1 ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:[u.jsxs("div",{className:"ct-flex ct-justify-between",children:[u.jsx("span",{children:"Provider"}),u.jsxs("span",{className:"ct-capitalize",children:[o.provider," ",o.gasless&&"(gasless)"]})]}),u.jsxs("div",{className:"ct-flex ct-justify-between",children:[u.jsx("span",{children:"Price impact"}),u.jsxs("span",{className:o.priceImpactPct>1?"ct-text-red-400":"",children:[o.priceImpactPct.toFixed(2),"%"]})]}),o.otherAmountThreshold&&u.jsxs("div",{className:"ct-flex ct-justify-between",children:[u.jsx("span",{children:"Min received"}),u.jsx("span",{children:(parseInt(o.otherAmountThreshold)/Math.pow(10,(b==null?void 0:b.decimals)??6)).toFixed(4)})]})]}),u.jsx($e,{value:C,onChange:V}),u.jsx(Pt,{message:c,onDismiss:m}),u.jsx("button",{onClick:I,disabled:!o||!n||l||L!=="quote",className:"ct-w-full ct-py-3 ct-rounded-cedros ct-font-semibold ct-text-[hsl(var(--cedros-primary-foreground))] ct-bg-[hsl(var(--cedros-primary))] hover:ct-opacity-90 disabled:ct-opacity-50 disabled:ct-cursor-not-allowed ct-transition",children:n?L==="sign"?"Signing...":L==="done"?"Swap Complete":l?"Fetching Quote...":o?"Swap":"Enter Amount":"Connect Wallet"}),u.jsx(Pe,{isOpen:P!==null,onClose:()=>H(null),onSelect:tt,excludeMints:P==="input"?[S]:[w]})]})}function Ai({title:n="Swap",...t}){return u.jsx("div",{className:"ct-max-w-md ct-mx-auto ct-py-8 ct-px-4",children:u.jsx(Zs,{...t})})}const Ki="So11111111111111111111111111111111111111112";function ti({walletAddress:n,onSign:t,onSuccess:e,onError:s,className:i=""}){const{buildResult:r,isLoading:h,error:o,build:l,execute:c,resolveAddress:a,reset:d}=Js(),[f,m]=g.useState(""),[p,v]=g.useState(""),[b,y]=g.useState(null),[w,M]=g.useState(Ki),[S,N]=g.useState(!1),[_,k]=g.useState(null),[C,V]=g.useState("form");g.useEffect(()=>{if(!f.endsWith(".sol")){k(null);return}const L=setTimeout(async()=>{try{const B=await a(f);k(B.resolved)}catch{k(null)}},500);return()=>clearTimeout(L)},[f,a]);const P=g.useCallback(L=>{y(L),M(L.mint)},[]),H=g.useCallback(async()=>{if(!(!n||!t))try{V("sign");const L=(b==null?void 0:b.decimals)??9,B=Math.round(parseFloat(p)*Math.pow(10,L)).toString(),U=await l(n,f,w,B),tt=await t(U.transaction),I=await c(tt);V("done"),e==null||e(I.signature)}catch(L){V("form"),s==null||s(L.message)}},[n,t,p,f,w,b,l,c,e,s]);return u.jsxs("div",{className:`ct-bg-[hsl(var(--cedros-background))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded-cedros ct-p-4 ct-space-y-4 ${i}`,children:[u.jsx("h3",{className:"ct-text-lg ct-font-semibold ct-text-[hsl(var(--cedros-foreground))]",children:"Send"}),u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Recipient"}),u.jsx("input",{type:"text",value:f,onChange:L=>m(L.target.value),placeholder:"Wallet address or name.sol",className:"ct-w-full ct-px-3 ct-py-3 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] ct-outline-none focus:ct-ring-2 focus:ct-ring-[hsl(var(--cedros-ring))]"}),_&&u.jsxs("div",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:["Resolves to: ",u.jsxs("span",{className:"ct-font-mono",children:[_.slice(0,8),"...",_.slice(-4)]})]})]}),u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Amount"}),u.jsxs("div",{className:"ct-flex ct-gap-2",children:[u.jsx("input",{type:"text",value:p,onChange:L=>v(L.target.value),placeholder:"0.00",className:"ct-flex-1 ct-px-3 ct-py-3 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-xl ct-text-[hsl(var(--cedros-foreground))] ct-outline-none focus:ct-ring-2 focus:ct-ring-[hsl(var(--cedros-ring))]"}),u.jsx("button",{onClick:()=>N(!0),className:"ct-px-4 ct-py-3 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] hover:ct-bg-[hsl(var(--cedros-border))] ct-font-medium ct-min-w-[100px]",children:(b==null?void 0:b.symbol)??"SOL"})]})]}),(r==null?void 0:r.createsAta)&&u.jsx("div",{className:"ct-rounded-cedros ct-bg-yellow-500/10 ct-border ct-border-yellow-500/20 ct-px-3 ct-py-2 ct-text-xs ct-text-yellow-400",children:"This will create a token account for the recipient (~0.002 SOL rent)."}),u.jsx(Pt,{message:o,onDismiss:d}),u.jsx("button",{onClick:H,disabled:!n||!f||!p||h||C!=="form",className:"ct-w-full ct-py-3 ct-rounded-cedros ct-font-semibold ct-text-[hsl(var(--cedros-primary-foreground))] ct-bg-[hsl(var(--cedros-primary))] hover:ct-opacity-90 disabled:ct-opacity-50 disabled:ct-cursor-not-allowed ct-transition",children:n?C==="sign"?"Signing...":C==="done"?"Sent!":h?u.jsx(ht,{}):"Send":"Connect Wallet"}),u.jsx(Pe,{isOpen:S,onClose:()=>N(!1),onSelect:P})]})}function Xi(n){return u.jsx("div",{className:"ct-max-w-md ct-mx-auto ct-py-8 ct-px-4",children:u.jsx(ti,{...n})})}function ei({symbol:n,interval:t="D",theme:e="dark",className:s=""}){const i=g.useRef(null);return g.useEffect(()=>{if(!i.current)return;const r=i.current;r.innerHTML="";const h=document.createElement("script");h.src="https://s3.tradingview.com/external-embedding/embed-widget-advanced-chart.js",h.async=!0,h.innerHTML=JSON.stringify({autosize:!0,symbol:n,interval:t,timezone:"Etc/UTC",theme:e,style:"1",locale:"en",enable_publishing:!1,allow_symbol_change:!0,save_image:!1,hide_top_toolbar:!1,hide_legend:!1,withdateranges:!0});const o=document.createElement("div");return o.className="tradingview-widget-container__widget",o.style.height="100%",o.style.width="100%",r.appendChild(o),r.appendChild(h),()=>{r.innerHTML=""}},[n,t,e]),u.jsx("div",{ref:i,className:`tradingview-widget-container ct-w-full ct-h-full ct-min-h-[400px] ${s}`,style:{height:"100%"}})}function E(n){var t=n.width,e=n.height;if(t<0)throw new Error("Negative width is not allowed for Size");if(e<0)throw new Error("Negative height is not allowed for Size");return{width:t,height:e}}function at(n,t){return n.width===t.width&&n.height===t.height}var Hi=function(){function n(t){var e=this;this._resolutionListener=function(){return e._onResolutionChanged()},this._resolutionMediaQueryList=null,this._observers=[],this._window=t,this._installResolutionListener()}return n.prototype.dispose=function(){this._uninstallResolutionListener(),this._window=null},Object.defineProperty(n.prototype,"value",{get:function(){return this._window.devicePixelRatio},enumerable:!1,configurable:!0}),n.prototype.subscribe=function(t){var e=this,s={next:t};return this._observers.push(s),{unsubscribe:function(){e._observers=e._observers.filter(function(i){return i!==s})}}},n.prototype._installResolutionListener=function(){if(this._resolutionMediaQueryList!==null)throw new Error("Resolution listener is already installed");var t=this._window.devicePixelRatio;this._resolutionMediaQueryList=this._window.matchMedia("all and (resolution: ".concat(t,"dppx)")),this._resolutionMediaQueryList.addListener(this._resolutionListener)},n.prototype._uninstallResolutionListener=function(){this._resolutionMediaQueryList!==null&&(this._resolutionMediaQueryList.removeListener(this._resolutionListener),this._resolutionMediaQueryList=null)},n.prototype._reinstallResolutionListener=function(){this._uninstallResolutionListener(),this._installResolutionListener()},n.prototype._onResolutionChanged=function(){var t=this;this._observers.forEach(function(e){return e.next(t._window.devicePixelRatio)}),this._reinstallResolutionListener()},n}();function Ui(n){return new Hi(n)}var qi=function(){function n(t,e,s){var i;this._canvasElement=null,this._bitmapSizeChangedListeners=[],this._suggestedBitmapSize=null,this._suggestedBitmapSizeChangedListeners=[],this._devicePixelRatioObservable=null,this._canvasElementResizeObserver=null,this._canvasElement=t,this._canvasElementClientSize=E({width:this._canvasElement.clientWidth,height:this._canvasElement.clientHeight}),this._transformBitmapSize=e??function(r){return r},this._allowResizeObserver=(i=s==null?void 0:s.allowResizeObserver)!==null&&i!==void 0?i:!0,this._chooseAndInitObserver()}return n.prototype.dispose=function(){var t,e;if(this._canvasElement===null)throw new Error("Object is disposed");(t=this._canvasElementResizeObserver)===null||t===void 0||t.disconnect(),this._canvasElementResizeObserver=null,(e=this._devicePixelRatioObservable)===null||e===void 0||e.dispose(),this._devicePixelRatioObservable=null,this._suggestedBitmapSizeChangedListeners.length=0,this._bitmapSizeChangedListeners.length=0,this._canvasElement=null},Object.defineProperty(n.prototype,"canvasElement",{get:function(){if(this._canvasElement===null)throw new Error("Object is disposed");return this._canvasElement},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"canvasElementClientSize",{get:function(){return this._canvasElementClientSize},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"bitmapSize",{get:function(){return E({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),n.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=E(t),this.canvasElement.style.width="".concat(this._canvasElementClientSize.width,"px"),this.canvasElement.style.height="".concat(this._canvasElementClientSize.height,"px"),this._invalidateBitmapSize()},n.prototype.subscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners.push(t)},n.prototype.unsubscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners=this._bitmapSizeChangedListeners.filter(function(e){return e!==t})},Object.defineProperty(n.prototype,"suggestedBitmapSize",{get:function(){return this._suggestedBitmapSize},enumerable:!1,configurable:!0}),n.prototype.subscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners.push(t)},n.prototype.unsubscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners=this._suggestedBitmapSizeChangedListeners.filter(function(e){return e!==t})},n.prototype.applySuggestedBitmapSize=function(){if(this._suggestedBitmapSize!==null){var t=this._suggestedBitmapSize;this._suggestedBitmapSize=null,this._resizeBitmap(t),this._emitSuggestedBitmapSizeChanged(t,this._suggestedBitmapSize)}},n.prototype._resizeBitmap=function(t){var e=this.bitmapSize;at(e,t)||(this.canvasElement.width=t.width,this.canvasElement.height=t.height,this._emitBitmapSizeChanged(e,t))},n.prototype._emitBitmapSizeChanged=function(t,e){var s=this;this._bitmapSizeChangedListeners.forEach(function(i){return i.call(s,t,e)})},n.prototype._suggestNewBitmapSize=function(t){var e=this._suggestedBitmapSize,s=E(this._transformBitmapSize(t,this._canvasElementClientSize)),i=at(this.bitmapSize,s)?null:s;e===null&&i===null||e!==null&&i!==null&&at(e,i)||(this._suggestedBitmapSize=i,this._emitSuggestedBitmapSizeChanged(e,i))},n.prototype._emitSuggestedBitmapSizeChanged=function(t,e){var s=this;this._suggestedBitmapSizeChangedListeners.forEach(function(i){return i.call(s,t,e)})},n.prototype._chooseAndInitObserver=function(){var t=this;if(!this._allowResizeObserver){this._initDevicePixelRatioObservable();return}Gi().then(function(e){return e?t._initResizeObserver():t._initDevicePixelRatioObservable()})},n.prototype._initDevicePixelRatioObservable=function(){var t=this;if(this._canvasElement!==null){var e=Ye(this._canvasElement);if(e===null)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=Ui(e),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},n.prototype._invalidateBitmapSize=function(){var t,e;if(this._canvasElement!==null){var s=Ye(this._canvasElement);if(s!==null){var i=(e=(t=this._devicePixelRatioObservable)===null||t===void 0?void 0:t.value)!==null&&e!==void 0?e:s.devicePixelRatio,r=this._canvasElement.getClientRects(),h=r[0]!==void 0?Qi(r[0],i):E({width:this._canvasElementClientSize.width*i,height:this._canvasElementClientSize.height*i});this._suggestNewBitmapSize(h)}}},n.prototype._initResizeObserver=function(){var t=this;this._canvasElement!==null&&(this._canvasElementResizeObserver=new ResizeObserver(function(e){var s=e.find(function(h){return h.target===t._canvasElement});if(!(!s||!s.devicePixelContentBoxSize||!s.devicePixelContentBoxSize[0])){var i=s.devicePixelContentBoxSize[0],r=E({width:i.inlineSize,height:i.blockSize});t._suggestNewBitmapSize(r)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},n}();function Ji(n,t){return new qi(n,t.transform,t.options)}function Ye(n){return n.ownerDocument.defaultView}function Gi(){return new Promise(function(n){var t=new ResizeObserver(function(e){n(e.every(function(s){return"devicePixelContentBoxSize"in s})),t.disconnect()});t.observe(document.body,{box:"device-pixel-content-box"})}).catch(function(){return!1})}function Qi(n,t){return E({width:Math.round(n.left*t+n.width*t)-Math.round(n.left*t),height:Math.round(n.top*t+n.height*t)-Math.round(n.top*t)})}var Yi=function(){function n(t,e,s){if(e.width===0||e.height===0)throw new TypeError("Rendering target could only be created on a media with positive width and height");if(this._mediaSize=e,s.width===0||s.height===0)throw new TypeError("Rendering target could only be created using a bitmap with positive integer width and height");this._bitmapSize=s,this._context=t}return n.prototype.useMediaCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),this._context.scale(this._horizontalPixelRatio,this._verticalPixelRatio),t({context:this._context,mediaSize:this._mediaSize})}finally{this._context.restore()}},n.prototype.useBitmapCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),t({context:this._context,mediaSize:this._mediaSize,bitmapSize:this._bitmapSize,horizontalPixelRatio:this._horizontalPixelRatio,verticalPixelRatio:this._verticalPixelRatio})}finally{this._context.restore()}},Object.defineProperty(n.prototype,"_horizontalPixelRatio",{get:function(){return this._bitmapSize.width/this._mediaSize.width},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"_verticalPixelRatio",{get:function(){return this._bitmapSize.height/this._mediaSize.height},enumerable:!1,configurable:!0}),n}();function ut(n,t){var e=n.canvasElementClientSize;if(e.width===0||e.height===0)return null;var s=n.bitmapSize;if(s.width===0||s.height===0)return null;var i=n.canvasElement.getContext("2d",t);return i===null?null:new Yi(i,e,s)}/*!
2
+ * @license
3
+ * TradingView Lightweight Charts™ v4.2.3
4
+ * Copyright (c) 2025 TradingView, Inc.
5
+ * Licensed under Apache License 2.0 https://www.apache.org/licenses/LICENSE-2.0
6
+ */const Zi={upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},tn={upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},en={color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},sn={topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},nn={baseValue:{type:"price",price:0},topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},rn={color:"#26a69a",base:0},si={color:"#2196f3"},ii={title:"",visible:!0,lastValueVisible:!0,priceLineVisible:!0,priceLineSource:0,priceLineWidth:1,priceLineColor:"",priceLineStyle:2,baseLineVisible:!0,baseLineWidth:1,baseLineColor:"#B2B5BE",baseLineStyle:0,priceFormat:{type:"price",precision:2,minMove:.01}};var Ze,ts;function dt(n,t){const e={0:[],1:[n.lineWidth,n.lineWidth],2:[2*n.lineWidth,2*n.lineWidth],3:[6*n.lineWidth,6*n.lineWidth],4:[n.lineWidth,4*n.lineWidth]}[t];n.setLineDash(e)}function ni(n,t,e,s){n.beginPath();const i=n.lineWidth%2?.5:0;n.moveTo(e,t+i),n.lineTo(s,t+i),n.stroke()}function rt(n,t){if(!n)throw new Error("Assertion failed"+(t?": "+t:""))}function O(n){if(n===void 0)throw new Error("Value is undefined");return n}function x(n){if(n===null)throw new Error("Value is null");return n}function gt(n){return x(O(n))}(function(n){n[n.Simple=0]="Simple",n[n.WithSteps=1]="WithSteps",n[n.Curved=2]="Curved"})(Ze||(Ze={})),function(n){n[n.Solid=0]="Solid",n[n.Dotted=1]="Dotted",n[n.Dashed=2]="Dashed",n[n.LargeDashed=3]="LargeDashed",n[n.SparseDotted=4]="SparseDotted"}(ts||(ts={}));const es={khaki:"#f0e68c",azure:"#f0ffff",aliceblue:"#f0f8ff",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",gray:"#808080",green:"#008000",honeydew:"#f0fff0",floralwhite:"#fffaf0",lightblue:"#add8e6",lightcoral:"#f08080",lemonchiffon:"#fffacd",hotpink:"#ff69b4",lightyellow:"#ffffe0",greenyellow:"#adff2f",lightgoldenrodyellow:"#fafad2",limegreen:"#32cd32",linen:"#faf0e6",lightcyan:"#e0ffff",magenta:"#f0f",maroon:"#800000",olive:"#808000",orange:"#ffa500",oldlace:"#fdf5e6",mediumblue:"#0000cd",transparent:"#0000",lime:"#0f0",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",midnightblue:"#191970",orchid:"#da70d6",mediumorchid:"#ba55d3",mediumturquoise:"#48d1cc",orangered:"#ff4500",royalblue:"#4169e1",powderblue:"#b0e0e6",red:"#f00",coral:"#ff7f50",turquoise:"#40e0d0",white:"#fff",whitesmoke:"#f5f5f5",wheat:"#f5deb3",teal:"#008080",steelblue:"#4682b4",bisque:"#ffe4c4",aquamarine:"#7fffd4",aqua:"#0ff",sienna:"#a0522d",silver:"#c0c0c0",springgreen:"#00ff7f",antiquewhite:"#faebd7",burlywood:"#deb887",brown:"#a52a2a",beige:"#f5f5dc",chocolate:"#d2691e",chartreuse:"#7fff00",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cadetblue:"#5f9ea0",tomato:"#ff6347",fuchsia:"#f0f",blue:"#00f",salmon:"#fa8072",blanchedalmond:"#ffebcd",slateblue:"#6a5acd",slategray:"#708090",thistle:"#d8bfd8",tan:"#d2b48c",cyan:"#0ff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",blueviolet:"#8a2be2",black:"#000",darkmagenta:"#8b008b",darkslateblue:"#483d8b",darkkhaki:"#bdb76b",darkorchid:"#9932cc",darkorange:"#ff8c00",darkgreen:"#006400",darkred:"#8b0000",dodgerblue:"#1e90ff",darkslategray:"#2f4f4f",dimgray:"#696969",deepskyblue:"#00bfff",firebrick:"#b22222",forestgreen:"#228b22",indigo:"#4b0082",ivory:"#fffff0",lavenderblush:"#fff0f5",feldspar:"#d19275",indianred:"#cd5c5c",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightskyblue:"#87cefa",lightslategray:"#789",lightslateblue:"#8470ff",snow:"#fffafa",lightseagreen:"#20b2aa",lightsalmon:"#ffa07a",darksalmon:"#e9967a",darkviolet:"#9400d3",mediumpurple:"#9370d8",mediumaquamarine:"#66cdaa",skyblue:"#87ceeb",lavender:"#e6e6fa",lightsteelblue:"#b0c4de",mediumvioletred:"#c71585",mintcream:"#f5fffa",navajowhite:"#ffdead",navy:"#000080",olivedrab:"#6b8e23",palevioletred:"#d87093",violetred:"#d02090",yellow:"#ff0",yellowgreen:"#9acd32",lawngreen:"#7cfc00",pink:"#ffc0cb",paleturquoise:"#afeeee",palegoldenrod:"#eee8aa",darkolivegreen:"#556b2f",darkseagreen:"#8fbc8f",darkturquoise:"#00ced1",peachpuff:"#ffdab9",deeppink:"#ff1493",violet:"#ee82ee",palegreen:"#98fb98",mediumseagreen:"#3cb371",peru:"#cd853f",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",purple:"#800080",seagreen:"#2e8b57",seashell:"#fff5ee",papayawhip:"#ffefd5",mediumslateblue:"#7b68ee",plum:"#dda0dd",mediumspringgreen:"#00fa9a"};function F(n){return n<0?0:n>255?255:Math.round(n)||0}function ri(n){return n<=0||n>1?Math.min(Math.max(n,0),1):Math.round(1e4*n)/1e4}const hn=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i,on=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i,ln=/^rgb\(\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*\)$/,cn=/^rgba\(\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*,\s*(-?\d*\.?\d+)\s*\)$/;function jt(n){(n=n.toLowerCase())in es&&(n=es[n]);{const t=cn.exec(n)||ln.exec(n);if(t)return[F(parseInt(t[1],10)),F(parseInt(t[2],10)),F(parseInt(t[3],10)),ri(t.length<5?1:parseFloat(t[4]))]}{const t=on.exec(n);if(t)return[F(parseInt(t[1],16)),F(parseInt(t[2],16)),F(parseInt(t[3],16)),1]}{const t=hn.exec(n);if(t)return[F(17*parseInt(t[1],16)),F(17*parseInt(t[2],16)),F(17*parseInt(t[3],16)),1]}throw new Error(`Cannot parse color: ${n}`)}function hi(n){return .199*n[0]+.687*n[1]+.114*n[2]}function Gt(n){const t=jt(n);return{t:`rgb(${t[0]}, ${t[1]}, ${t[2]})`,i:hi(t)>160?"black":"white"}}class T{constructor(){this.h=[]}l(t,e,s){const i={o:t,_:e,u:s===!0};this.h.push(i)}v(t){const e=this.h.findIndex(s=>t===s.o);e>-1&&this.h.splice(e,1)}p(t){this.h=this.h.filter(e=>e._!==t)}m(t,e,s){const i=[...this.h];this.h=this.h.filter(r=>!r.u),i.forEach(r=>r.o(t,e,s))}M(){return this.h.length>0}S(){this.h=[]}}function K(n,...t){for(const e of t)for(const s in e)e[s]!==void 0&&Object.prototype.hasOwnProperty.call(e,s)&&!["__proto__","constructor","prototype"].includes(s)&&(typeof e[s]!="object"||n[s]===void 0||Array.isArray(e[s])?n[s]=e[s]:K(n[s],e[s]));return n}function J(n){return typeof n=="number"&&isFinite(n)}function kt(n){return typeof n=="number"&&n%1==0}function $t(n){return typeof n=="string"}function Rt(n){return typeof n=="boolean"}function Y(n){const t=n;if(!t||typeof t!="object")return t;let e,s,i;for(s in e=Array.isArray(t)?[]:{},t)t.hasOwnProperty(s)&&(i=t[s],e[s]=i&&typeof i=="object"?Y(i):i);return e}function an(n){return n!==null}function Et(n){return n===null?void 0:n}const Ve="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function wt(n,t,e){return t===void 0&&(t=Ve),`${e=e!==void 0?`${e} `:""}${n}px ${t}`}class un{constructor(t){this.k={C:1,T:5,P:NaN,R:"",D:"",V:"",O:"",B:0,A:0,I:0,L:0,N:0},this.F=t}W(){const t=this.k,e=this.j(),s=this.H();return t.P===e&&t.D===s||(t.P=e,t.D=s,t.R=wt(e,s),t.L=2.5/12*e,t.B=t.L,t.A=e/12*t.T,t.I=e/12*t.T,t.N=0),t.V=this.$(),t.O=this.U(),this.k}$(){return this.F.W().layout.textColor}U(){return this.F.q()}j(){return this.F.W().layout.fontSize}H(){return this.F.W().layout.fontFamily}}class Re{constructor(){this.Y=[]}Z(t){this.Y=t}X(t,e,s){this.Y.forEach(i=>{i.X(t,e,s)})}}class X{X(t,e,s){t.useBitmapCoordinateSpace(i=>this.K(i,e,s))}}class dn extends X{constructor(){super(...arguments),this.G=null}J(t){this.G=t}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:s}){if(this.G===null||this.G.tt===null)return;const i=this.G.tt,r=this.G,h=Math.max(1,Math.floor(e))%2/2,o=l=>{t.beginPath();for(let c=i.to-1;c>=i.from;--c){const a=r.it[c],d=Math.round(a.nt*e)+h,f=a.st*s,m=l*s+h;t.moveTo(d,f),t.arc(d,f,m,0,2*Math.PI)}t.fill()};r.et>0&&(t.fillStyle=r.rt,o(r.ht+r.et)),t.fillStyle=r.lt,o(r.ht)}}function fn(){return{it:[{nt:0,st:0,ot:0,_t:0}],lt:"",rt:"",ht:0,et:0,tt:null}}const pn={from:0,to:1};class mn{constructor(t,e){this.ut=new Re,this.ct=[],this.dt=[],this.ft=!0,this.F=t,this.vt=e,this.ut.Z(this.ct)}bt(t){const e=this.F.wt();e.length!==this.ct.length&&(this.dt=e.map(fn),this.ct=this.dt.map(s=>{const i=new dn;return i.J(s),i}),this.ut.Z(this.ct)),this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.ut}Mt(){const t=this.vt.W().mode===2,e=this.F.wt(),s=this.vt.xt(),i=this.F.St();e.forEach((r,h)=>{var o;const l=this.dt[h],c=r.kt(s);if(t||c===null||!r.yt())return void(l.tt=null);const a=x(r.Ct());l.lt=c.Tt,l.ht=c.ht,l.et=c.Pt,l.it[0]._t=c._t,l.it[0].st=r.Dt().Rt(c._t,a.Vt),l.rt=(o=c.Ot)!==null&&o!==void 0?o:this.F.Bt(l.it[0].st/r.Dt().At()),l.it[0].ot=s,l.it[0].nt=i.It(s),l.tt=pn})}}class vn extends X{constructor(t){super(),this.zt=t}K({context:t,bitmapSize:e,horizontalPixelRatio:s,verticalPixelRatio:i}){if(this.zt===null)return;const r=this.zt.Lt.yt,h=this.zt.Et.yt;if(!r&&!h)return;const o=Math.round(this.zt.nt*s),l=Math.round(this.zt.st*i);t.lineCap="butt",r&&o>=0&&(t.lineWidth=Math.floor(this.zt.Lt.et*s),t.strokeStyle=this.zt.Lt.V,t.fillStyle=this.zt.Lt.V,dt(t,this.zt.Lt.Nt),function(c,a,d,f){c.beginPath();const m=c.lineWidth%2?.5:0;c.moveTo(a+m,d),c.lineTo(a+m,f),c.stroke()}(t,o,0,e.height)),h&&l>=0&&(t.lineWidth=Math.floor(this.zt.Et.et*i),t.strokeStyle=this.zt.Et.V,t.fillStyle=this.zt.Et.V,dt(t,this.zt.Et.Nt),ni(t,l,0,e.width))}}class gn{constructor(t){this.ft=!0,this.Ft={Lt:{et:1,Nt:0,V:"",yt:!1},Et:{et:1,Nt:0,V:"",yt:!1},nt:0,st:0},this.Wt=new vn(this.Ft),this.jt=t}bt(){this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.Wt}Mt(){const t=this.jt.yt(),e=x(this.jt.Ht()),s=e.$t().W().crosshair,i=this.Ft;if(s.mode===2)return i.Et.yt=!1,void(i.Lt.yt=!1);i.Et.yt=t&&this.jt.Ut(e),i.Lt.yt=t&&this.jt.qt(),i.Et.et=s.horzLine.width,i.Et.Nt=s.horzLine.style,i.Et.V=s.horzLine.color,i.Lt.et=s.vertLine.width,i.Lt.Nt=s.vertLine.style,i.Lt.V=s.vertLine.color,i.nt=this.jt.Yt(),i.st=this.jt.Zt()}}function bn(n,t,e,s,i,r){n.fillRect(t+r,e,s-2*r,r),n.fillRect(t+r,e+i-r,s-2*r,r),n.fillRect(t,e,r,i),n.fillRect(t+s-r,e,r,i)}function Qt(n,t,e,s,i,r){n.save(),n.globalCompositeOperation="copy",n.fillStyle=r,n.fillRect(t,e,s,i),n.restore()}function ss(n,t,e,s,i,r){n.beginPath(),n.roundRect?n.roundRect(t,e,s,i,r):(n.lineTo(t+s-r[1],e),r[1]!==0&&n.arcTo(t+s,e,t+s,e+r[1],r[1]),n.lineTo(t+s,e+i-r[2]),r[2]!==0&&n.arcTo(t+s,e+i,t+s-r[2],e+i,r[2]),n.lineTo(t+r[3],e+i),r[3]!==0&&n.arcTo(t,e+i,t,e+i-r[3],r[3]),n.lineTo(t,e+r[0]),r[0]!==0&&n.arcTo(t,e,t+r[0],e,r[0]))}function is(n,t,e,s,i,r,h=0,o=[0,0,0,0],l=""){if(n.save(),!h||!l||l===r)return ss(n,t,e,s,i,o),n.fillStyle=r,n.fill(),void n.restore();const c=h/2;var a;ss(n,t+c,e+c,s-h,i-h,(a=-c,o.map(d=>d===0?d:d+a))),r!=="transparent"&&(n.fillStyle=r,n.fill()),l!=="transparent"&&(n.lineWidth=h,n.strokeStyle=l,n.closePath(),n.stroke()),n.restore()}function oi(n,t,e,s,i,r,h){n.save(),n.globalCompositeOperation="copy";const o=n.createLinearGradient(0,0,0,i);o.addColorStop(0,r),o.addColorStop(1,h),n.fillStyle=o,n.fillRect(t,e,s,i),n.restore()}class ns{constructor(t,e){this.J(t,e)}J(t,e){this.zt=t,this.Xt=e}At(t,e){return this.zt.yt?t.P+t.L+t.B:0}X(t,e,s,i){if(!this.zt.yt||this.zt.Kt.length===0)return;const r=this.zt.V,h=this.Xt.t,o=t.useBitmapCoordinateSpace(l=>{const c=l.context;c.font=e.R;const a=this.Gt(l,e,s,i),d=a.Jt;return a.Qt?is(c,d.ti,d.ii,d.ni,d.si,h,d.ei,[d.ht,0,0,d.ht],h):is(c,d.ri,d.ii,d.ni,d.si,h,d.ei,[0,d.ht,d.ht,0],h),this.zt.hi&&(c.fillStyle=r,c.fillRect(d.ri,d.li,d.ai-d.ri,d.oi)),this.zt._i&&(c.fillStyle=e.O,c.fillRect(a.Qt?d.ui-d.ei:0,d.ii,d.ei,d.ci-d.ii)),a});t.useMediaCoordinateSpace(({context:l})=>{const c=o.di;l.font=e.R,l.textAlign=o.Qt?"right":"left",l.textBaseline="middle",l.fillStyle=r,l.fillText(this.zt.Kt,c.fi,(c.ii+c.ci)/2+c.pi)})}Gt(t,e,s,i){var r;const{context:h,bitmapSize:o,mediaSize:l,horizontalPixelRatio:c,verticalPixelRatio:a}=t,d=this.zt.hi||!this.zt.mi?e.T:0,f=this.zt.bi?e.C:0,m=e.L+this.Xt.wi,p=e.B+this.Xt.gi,v=e.A,b=e.I,y=this.zt.Kt,w=e.P,M=s.Mi(h,y),S=Math.ceil(s.xi(h,y)),N=w+m+p,_=e.C+v+b+S+d,k=Math.max(1,Math.floor(a));let C=Math.round(N*a);C%2!=k%2&&(C+=1);const V=f>0?Math.max(1,Math.floor(f*c)):0,P=Math.round(_*c),H=Math.round(d*c),L=(r=this.Xt.Si)!==null&&r!==void 0?r:this.Xt.ki,B=Math.round(L*a)-Math.floor(.5*a),U=Math.floor(B+k/2-C/2),tt=U+C,I=i==="right",mt=I?l.width-f:f,z=I?o.width-V:V;let A,et,St;return I?(A=z-P,et=z-H,St=mt-d-v-f):(A=z+P,et=z+H,St=mt+d+v),{Qt:I,Jt:{ii:U,li:B,ci:tt,ni:P,si:C,ht:2*c,ei:V,ti:A,ri:z,ai:et,oi:k,ui:o.width},di:{ii:U/a,ci:tt/a,fi:St,pi:M}}}}class Yt{constructor(t){this.yi={ki:0,t:"#000",gi:0,wi:0},this.Ci={Kt:"",yt:!1,hi:!0,mi:!1,Ot:"",V:"#FFF",_i:!1,bi:!1},this.Ti={Kt:"",yt:!1,hi:!1,mi:!0,Ot:"",V:"#FFF",_i:!0,bi:!0},this.ft=!0,this.Pi=new(t||ns)(this.Ci,this.yi),this.Ri=new(t||ns)(this.Ti,this.yi)}Kt(){return this.Di(),this.Ci.Kt}ki(){return this.Di(),this.yi.ki}bt(){this.ft=!0}At(t,e=!1){return Math.max(this.Pi.At(t,e),this.Ri.At(t,e))}Vi(){return this.yi.Si||0}Oi(t){this.yi.Si=t}Bi(){return this.Di(),this.Ci.yt||this.Ti.yt}Ai(){return this.Di(),this.Ci.yt}gt(t){return this.Di(),this.Ci.hi=this.Ci.hi&&t.W().ticksVisible,this.Ti.hi=this.Ti.hi&&t.W().ticksVisible,this.Pi.J(this.Ci,this.yi),this.Ri.J(this.Ti,this.yi),this.Pi}Ii(){return this.Di(),this.Pi.J(this.Ci,this.yi),this.Ri.J(this.Ti,this.yi),this.Ri}Di(){this.ft&&(this.Ci.hi=!0,this.Ti.hi=!1,this.zi(this.Ci,this.Ti,this.yi))}}class xn extends Yt{constructor(t,e,s){super(),this.jt=t,this.Li=e,this.Ei=s}zi(t,e,s){if(t.yt=!1,this.jt.W().mode===2)return;const i=this.jt.W().horzLine;if(!i.labelVisible)return;const r=this.Li.Ct();if(!this.jt.yt()||this.Li.Ni()||r===null)return;const h=Gt(i.labelBackgroundColor);s.t=h.t,t.V=h.i;const o=2/12*this.Li.P();s.wi=o,s.gi=o;const l=this.Ei(this.Li);s.ki=l.ki,t.Kt=this.Li.Fi(l._t,r),t.yt=!0}}const wn=/[1-9]/g;class li{constructor(){this.zt=null}J(t){this.zt=t}X(t,e){if(this.zt===null||this.zt.yt===!1||this.zt.Kt.length===0)return;const s=t.useMediaCoordinateSpace(({context:f})=>(f.font=e.R,Math.round(e.Wi.xi(f,x(this.zt).Kt,wn))));if(s<=0)return;const i=e.ji,r=s+2*i,h=r/2,o=this.zt.Hi;let l=this.zt.ki,c=Math.floor(l-h)+.5;c<0?(l+=Math.abs(0-c),c=Math.floor(l-h)+.5):c+r>o&&(l-=Math.abs(o-(c+r)),c=Math.floor(l-h)+.5);const a=c+r,d=Math.ceil(0+e.C+e.T+e.L+e.P+e.B);t.useBitmapCoordinateSpace(({context:f,horizontalPixelRatio:m,verticalPixelRatio:p})=>{const v=x(this.zt);f.fillStyle=v.t;const b=Math.round(c*m),y=Math.round(0*p),w=Math.round(a*m),M=Math.round(d*p),S=Math.round(2*m);if(f.beginPath(),f.moveTo(b,y),f.lineTo(b,M-S),f.arcTo(b,M,b+S,M,S),f.lineTo(w-S,M),f.arcTo(w,M,w,M-S,S),f.lineTo(w,y),f.fill(),v.hi){const N=Math.round(v.ki*m),_=y,k=Math.round((_+e.T)*p);f.fillStyle=v.V;const C=Math.max(1,Math.floor(m)),V=Math.floor(.5*m);f.fillRect(N-V,_,C,k-_)}}),t.useMediaCoordinateSpace(({context:f})=>{const m=x(this.zt),p=0+e.C+e.T+e.L+e.P/2;f.font=e.R,f.textAlign="left",f.textBaseline="middle",f.fillStyle=m.V;const v=e.Wi.Mi(f,"Apr0");f.translate(c+i,p+v),f.fillText(m.Kt,0,0)})}}class yn{constructor(t,e,s){this.ft=!0,this.Wt=new li,this.Ft={yt:!1,t:"#4c525e",V:"white",Kt:"",Hi:0,ki:NaN,hi:!0},this.vt=t,this.$i=e,this.Ei=s}bt(){this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.Wt.J(this.Ft),this.Wt}Mt(){const t=this.Ft;if(t.yt=!1,this.vt.W().mode===2)return;const e=this.vt.W().vertLine;if(!e.labelVisible)return;const s=this.$i.St();if(s.Ni())return;t.Hi=s.Hi();const i=this.Ei();if(i===null)return;t.ki=i.ki;const r=s.Ui(this.vt.xt());t.Kt=s.qi(x(r)),t.yt=!0;const h=Gt(e.labelBackgroundColor);t.t=h.t,t.V=h.i,t.hi=s.W().ticksVisible}}class Oe{constructor(){this.Yi=null,this.Zi=0}Xi(){return this.Zi}Ki(t){this.Zi=t}Dt(){return this.Yi}Gi(t){this.Yi=t}Ji(t){return[]}Qi(){return[]}yt(){return!0}}var rs;(function(n){n[n.Normal=0]="Normal",n[n.Magnet=1]="Magnet",n[n.Hidden=2]="Hidden"})(rs||(rs={}));class Sn extends Oe{constructor(t,e){super(),this.tn=null,this.nn=NaN,this.sn=0,this.en=!0,this.rn=new Map,this.hn=!1,this.ln=NaN,this.an=NaN,this._n=NaN,this.un=NaN,this.$i=t,this.cn=e,this.dn=new mn(t,this),this.fn=((i,r)=>h=>{const o=r(),l=i();if(h===x(this.tn).vn())return{_t:l,ki:o};{const c=x(h.Ct());return{_t:h.pn(o,c),ki:o}}})(()=>this.nn,()=>this.an);const s=((i,r)=>()=>{const h=this.$i.St().mn(i()),o=r();return h&&Number.isFinite(o)?{ot:h,ki:o}:null})(()=>this.sn,()=>this.Yt());this.bn=new yn(this,t,s),this.wn=new gn(this)}W(){return this.cn}gn(t,e){this._n=t,this.un=e}Mn(){this._n=NaN,this.un=NaN}xn(){return this._n}Sn(){return this.un}kn(t,e,s){this.hn||(this.hn=!0),this.en=!0,this.yn(t,e,s)}xt(){return this.sn}Yt(){return this.ln}Zt(){return this.an}yt(){return this.en}Cn(){this.en=!1,this.Tn(),this.nn=NaN,this.ln=NaN,this.an=NaN,this.tn=null,this.Mn()}Pn(t){return this.tn!==null?[this.wn,this.dn]:[]}Ut(t){return t===this.tn&&this.cn.horzLine.visible}qt(){return this.cn.vertLine.visible}Rn(t,e){this.en&&this.tn===t||this.rn.clear();const s=[];return this.tn===t&&s.push(this.Dn(this.rn,e,this.fn)),s}Qi(){return this.en?[this.bn]:[]}Ht(){return this.tn}Vn(){this.wn.bt(),this.rn.forEach(t=>t.bt()),this.bn.bt(),this.dn.bt()}On(t){return t&&!t.vn().Ni()?t.vn():null}yn(t,e,s){this.Bn(t,e,s)&&this.Vn()}Bn(t,e,s){const i=this.ln,r=this.an,h=this.nn,o=this.sn,l=this.tn,c=this.On(s);this.sn=t,this.ln=isNaN(t)?NaN:this.$i.St().It(t),this.tn=s;const a=c!==null?c.Ct():null;return c!==null&&a!==null?(this.nn=e,this.an=c.Rt(e,a)):(this.nn=NaN,this.an=NaN),i!==this.ln||r!==this.an||o!==this.sn||h!==this.nn||l!==this.tn}Tn(){const t=this.$i.wt().map(s=>s.In().An()).filter(an),e=t.length===0?null:Math.max(...t);this.sn=e!==null?e:NaN}Dn(t,e,s){let i=t.get(e);return i===void 0&&(i=new xn(this,e,s),t.set(e,i)),i}}function Zt(n){return n==="left"||n==="right"}class ${constructor(t){this.zn=new Map,this.Ln=[],this.En=t}Nn(t,e){const s=function(i,r){return i===void 0?r:{Fn:Math.max(i.Fn,r.Fn),Wn:i.Wn||r.Wn}}(this.zn.get(t),e);this.zn.set(t,s)}jn(){return this.En}Hn(t){const e=this.zn.get(t);return e===void 0?{Fn:this.En}:{Fn:Math.max(this.En,e.Fn),Wn:e.Wn}}$n(){this.Un(),this.Ln=[{qn:0}]}Yn(t){this.Un(),this.Ln=[{qn:1,Vt:t}]}Zn(t){this.Xn(),this.Ln.push({qn:5,Vt:t})}Un(){this.Xn(),this.Ln.push({qn:6})}Kn(){this.Un(),this.Ln=[{qn:4}]}Gn(t){this.Un(),this.Ln.push({qn:2,Vt:t})}Jn(t){this.Un(),this.Ln.push({qn:3,Vt:t})}Qn(){return this.Ln}ts(t){for(const e of t.Ln)this.ns(e);this.En=Math.max(this.En,t.En),t.zn.forEach((e,s)=>{this.Nn(s,e)})}static ss(){return new $(2)}static es(){return new $(3)}ns(t){switch(t.qn){case 0:this.$n();break;case 1:this.Yn(t.Vt);break;case 2:this.Gn(t.Vt);break;case 3:this.Jn(t.Vt);break;case 4:this.Kn();break;case 5:this.Zn(t.Vt);break;case 6:this.Xn()}}Xn(){const t=this.Ln.findIndex(e=>e.qn===5);t!==-1&&this.Ln.splice(t,1)}}const hs=".";function Z(n,t){if(!J(n))return"n/a";if(!kt(t))throw new TypeError("invalid length");if(t<0||t>16)throw new TypeError("invalid length");return t===0?n.toString():("0000000000000000"+n.toString()).slice(-t)}class te{constructor(t,e){if(e||(e=1),J(t)&&kt(t)||(t=100),t<0)throw new TypeError("invalid base");this.Li=t,this.rs=e,this.hs()}format(t){const e=t<0?"−":"";return t=Math.abs(t),e+this.ls(t)}hs(){if(this._s=0,this.Li>0&&this.rs>0){let t=this.Li;for(;t>1;)t/=10,this._s++}}ls(t){const e=this.Li/this.rs;let s=Math.floor(t),i="";const r=this._s!==void 0?this._s:NaN;if(e>1){let h=+(Math.round(t*e)-s*e).toFixed(this._s);h>=e&&(h-=e,s+=1),i=hs+Z(+h.toFixed(this._s)*this.rs,r)}else s=Math.round(s*e)/e,r>0&&(i=hs+Z(0,r));return s.toFixed(0)+i}}class ci extends te{constructor(t=100){super(t)}format(t){return`${super.format(t)}%`}}class Mn{constructor(t){this.us=t}format(t){let e="";return t<0&&(e="-",t=-t),t<995?e+this.cs(t):t<999995?e+this.cs(t/1e3)+"K":t<999999995?(t=1e3*Math.round(t/1e3),e+this.cs(t/1e6)+"M"):(t=1e6*Math.round(t/1e6),e+this.cs(t/1e9)+"B")}cs(t){let e;const s=Math.pow(10,this.us);return e=(t=Math.round(t*s)/s)>=1e-15&&t<1?t.toFixed(this.us).replace(/\.?0+$/,""):String(t),e.replace(/(\.[1-9]*)0+$/,(i,r)=>r)}}function ai(n,t,e,s,i,r,h){if(t.length===0||s.from>=t.length||s.to<=0)return;const{context:o,horizontalPixelRatio:l,verticalPixelRatio:c}=n,a=t[s.from];let d=r(n,a),f=a;if(s.to-s.from<2){const m=i/2;o.beginPath();const p={nt:a.nt-m,st:a.st},v={nt:a.nt+m,st:a.st};o.moveTo(p.nt*l,p.st*c),o.lineTo(v.nt*l,v.st*c),h(n,d,p,v)}else{const m=(v,b)=>{h(n,d,f,b),o.beginPath(),d=v,f=b};let p=f;o.beginPath(),o.moveTo(a.nt*l,a.st*c);for(let v=s.from+1;v<s.to;++v){p=t[v];const b=r(n,p);switch(e){case 0:o.lineTo(p.nt*l,p.st*c);break;case 1:o.lineTo(p.nt*l,t[v-1].st*c),b!==d&&(m(b,p),o.lineTo(p.nt*l,t[v-1].st*c)),o.lineTo(p.nt*l,p.st*c);break;case 2:{const[y,w]=Cn(t,v-1,v);o.bezierCurveTo(y.nt*l,y.st*c,w.nt*l,w.st*c,p.nt*l,p.st*c);break}}e!==1&&b!==d&&(m(b,p),o.moveTo(p.nt*l,p.st*c))}(f!==p||f===p&&e===1)&&h(n,d,f,p)}}const os=6;function se(n,t){return{nt:n.nt-t.nt,st:n.st-t.st}}function ls(n,t){return{nt:n.nt/t,st:n.st/t}}function Cn(n,t,e){const s=Math.max(0,t-1),i=Math.min(n.length-1,e+1);var r,h;return[(r=n[t],h=ls(se(n[e],n[s]),os),{nt:r.nt+h.nt,st:r.st+h.st}),se(n[e],ls(se(n[i],n[t]),os))]}function _n(n,t,e,s,i){const{context:r,horizontalPixelRatio:h,verticalPixelRatio:o}=t;r.lineTo(i.nt*h,n*o),r.lineTo(s.nt*h,n*o),r.closePath(),r.fillStyle=e,r.fill()}class ui extends X{constructor(){super(...arguments),this.G=null}J(t){this.G=t}K(t){var e;if(this.G===null)return;const{it:s,tt:i,ds:r,et:h,Nt:o,fs:l}=this.G,c=(e=this.G.vs)!==null&&e!==void 0?e:this.G.ps?0:t.mediaSize.height;if(i===null)return;const a=t.context;a.lineCap="butt",a.lineJoin="round",a.lineWidth=h,dt(a,o),a.lineWidth=1,ai(t,s,l,i,r,this.bs.bind(this),_n.bind(null,c))}}function ye(n,t,e){return Math.min(Math.max(n,t),e)}function Ot(n,t,e){return t-n<=e}function di(n){const t=Math.ceil(n);return t%2==0?t-1:t}class We{ws(t,e){const s=this.gs,{Ms:i,xs:r,Ss:h,ks:o,ys:l,vs:c}=e;if(this.Cs===void 0||s===void 0||s.Ms!==i||s.xs!==r||s.Ss!==h||s.ks!==o||s.vs!==c||s.ys!==l){const a=t.context.createLinearGradient(0,0,0,l);if(a.addColorStop(0,i),c!=null){const d=ye(c*t.verticalPixelRatio/l,0,1);a.addColorStop(d,r),a.addColorStop(d,h)}a.addColorStop(1,o),this.Cs=a,this.gs=e}return this.Cs}}class Nn extends ui{constructor(){super(...arguments),this.Ts=new We}bs(t,e){return this.Ts.ws(t,{Ms:e.Ps,xs:"",Ss:"",ks:e.Rs,ys:t.bitmapSize.height})}}function zn(n,t){const e=n.context;e.strokeStyle=t,e.stroke()}class fi extends X{constructor(){super(...arguments),this.G=null}J(t){this.G=t}K(t){if(this.G===null)return;const{it:e,tt:s,ds:i,fs:r,et:h,Nt:o,Ds:l}=this.G;if(s===null)return;const c=t.context;c.lineCap="butt",c.lineWidth=h*t.verticalPixelRatio,dt(c,o),c.lineJoin="round";const a=this.Vs.bind(this);r!==void 0&&ai(t,e,r,s,i,a,zn),l&&function(d,f,m,p,v){const{horizontalPixelRatio:b,verticalPixelRatio:y,context:w}=d;let M=null;const S=Math.max(1,Math.floor(b))%2/2,N=m*y+S;for(let _=p.to-1;_>=p.from;--_){const k=f[_];if(k){const C=v(d,k);C!==M&&(w.beginPath(),M!==null&&w.fill(),w.fillStyle=C,M=C);const V=Math.round(k.nt*b)+S,P=k.st*y;w.moveTo(V,P),w.arc(V,P,N,0,2*Math.PI)}}w.fill()}(t,e,l,s,a)}}class pi extends fi{Vs(t,e){return e.lt}}function mi(n,t,e,s,i=0,r=t.length){let h=r-i;for(;0<h;){const o=h>>1,l=i+o;s(t[l],e)===n?(i=l+1,h-=o+1):h=o}return i}const Vt=mi.bind(null,!0),vi=mi.bind(null,!1);function jn(n,t){return n.ot<t}function kn(n,t){return t<n.ot}function gi(n,t,e){const s=t.Os(),i=t.ui(),r=Vt(n,s,jn),h=vi(n,i,kn);if(!e)return{from:r,to:h};let o=r,l=h;return r>0&&r<n.length&&n[r].ot>=s&&(o=r-1),h>0&&h<n.length&&n[h-1].ot<=i&&(l=h+1),{from:o,to:l}}class De{constructor(t,e,s){this.Bs=!0,this.As=!0,this.Is=!0,this.zs=[],this.Ls=null,this.Es=t,this.Ns=e,this.Fs=s}bt(t){this.Bs=!0,t==="data"&&(this.As=!0),t==="options"&&(this.Is=!0)}gt(){return this.Es.yt()?(this.Ws(),this.Ls===null?null:this.js):null}Hs(){this.zs=this.zs.map(t=>Object.assign(Object.assign({},t),this.Es.Us().$s(t.ot)))}qs(){this.Ls=null}Ws(){this.As&&(this.Ys(),this.As=!1),this.Is&&(this.Hs(),this.Is=!1),this.Bs&&(this.Zs(),this.Bs=!1)}Zs(){const t=this.Es.Dt(),e=this.Ns.St();if(this.qs(),e.Ni()||t.Ni())return;const s=e.Xs();if(s===null||this.Es.In().Ks()===0)return;const i=this.Es.Ct();i!==null&&(this.Ls=gi(this.zs,s,this.Fs),this.Gs(t,e,i.Vt),this.Js())}}class ee extends De{constructor(t,e){super(t,e,!0)}Gs(t,e,s){e.Qs(this.zs,Et(this.Ls)),t.te(this.zs,s,Et(this.Ls))}ie(t,e){return{ot:t,_t:e,nt:NaN,st:NaN}}Ys(){const t=this.Es.Us();this.zs=this.Es.In().ne().map(e=>{const s=e.Vt[3];return this.se(e.ee,s,t)})}}class En extends ee{constructor(t,e){super(t,e),this.js=new Re,this.re=new Nn,this.he=new pi,this.js.Z([this.re,this.he])}se(t,e,s){return Object.assign(Object.assign({},this.ie(t,e)),s.$s(t))}Js(){const t=this.Es.W();this.re.J({fs:t.lineType,it:this.zs,Nt:t.lineStyle,et:t.lineWidth,vs:null,ps:t.invertFilledArea,tt:this.Ls,ds:this.Ns.St().le()}),this.he.J({fs:t.lineVisible?t.lineType:void 0,it:this.zs,Nt:t.lineStyle,et:t.lineWidth,tt:this.Ls,ds:this.Ns.St().le(),Ds:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}class Ln extends X{constructor(){super(...arguments),this.zt=null,this.ae=0,this.oe=0}J(t){this.zt=t}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:s}){if(this.zt===null||this.zt.In.length===0||this.zt.tt===null)return;this.ae=this._e(e),this.ae>=2&&Math.max(1,Math.floor(e))%2!=this.ae%2&&this.ae--,this.oe=this.zt.ue?Math.min(this.ae,Math.floor(e)):this.ae;let i=null;const r=this.oe<=this.ae&&this.zt.le>=Math.floor(1.5*e);for(let h=this.zt.tt.from;h<this.zt.tt.to;++h){const o=this.zt.In[h];i!==o.ce&&(t.fillStyle=o.ce,i=o.ce);const l=Math.floor(.5*this.oe),c=Math.round(o.nt*e),a=c-l,d=this.oe,f=a+d-1,m=Math.min(o.de,o.fe),p=Math.max(o.de,o.fe),v=Math.round(m*s)-l,b=Math.round(p*s)+l,y=Math.max(b-v,this.oe);t.fillRect(a,v,d,y);const w=Math.ceil(1.5*this.ae);if(r){if(this.zt.ve){const _=c-w;let k=Math.max(v,Math.round(o.pe*s)-l),C=k+d-1;C>v+y-1&&(C=v+y-1,k=C-d+1),t.fillRect(_,k,a-_,C-k+1)}const M=c+w;let S=Math.max(v,Math.round(o.me*s)-l),N=S+d-1;N>v+y-1&&(N=v+y-1,S=N-d+1),t.fillRect(f+1,S,M-f,N-S+1)}}}_e(t){const e=Math.floor(t);return Math.max(e,Math.floor(function(s,i){return Math.floor(.3*s*i)}(x(this.zt).le,t)))}}class bi extends De{constructor(t,e){super(t,e,!1)}Gs(t,e,s){e.Qs(this.zs,Et(this.Ls)),t.be(this.zs,s,Et(this.Ls))}we(t,e,s){return{ot:t,ge:e.Vt[0],Me:e.Vt[1],xe:e.Vt[2],Se:e.Vt[3],nt:NaN,pe:NaN,de:NaN,fe:NaN,me:NaN}}Ys(){const t=this.Es.Us();this.zs=this.Es.In().ne().map(e=>this.se(e.ee,e,t))}}class Tn extends bi{constructor(){super(...arguments),this.js=new Ln}se(t,e,s){return Object.assign(Object.assign({},this.we(t,e,s)),s.$s(t))}Js(){const t=this.Es.W();this.js.J({In:this.zs,le:this.Ns.St().le(),ve:t.openVisible,ue:t.thinBars,tt:this.Ls})}}class Pn extends ui{constructor(){super(...arguments),this.Ts=new We}bs(t,e){const s=this.G;return this.Ts.ws(t,{Ms:e.ke,xs:e.ye,Ss:e.Ce,ks:e.Te,ys:t.bitmapSize.height,vs:s.vs})}}class $n extends fi{constructor(){super(...arguments),this.Pe=new We}Vs(t,e){const s=this.G;return this.Pe.ws(t,{Ms:e.Re,xs:e.Re,Ss:e.De,ks:e.De,ys:t.bitmapSize.height,vs:s.vs})}}class Vn extends ee{constructor(t,e){super(t,e),this.js=new Re,this.Ve=new Pn,this.Oe=new $n,this.js.Z([this.Ve,this.Oe])}se(t,e,s){return Object.assign(Object.assign({},this.ie(t,e)),s.$s(t))}Js(){const t=this.Es.Ct();if(t===null)return;const e=this.Es.W(),s=this.Es.Dt().Rt(e.baseValue.price,t.Vt),i=this.Ns.St().le();this.Ve.J({it:this.zs,et:e.lineWidth,Nt:e.lineStyle,fs:e.lineType,vs:s,ps:!1,tt:this.Ls,ds:i}),this.Oe.J({it:this.zs,et:e.lineWidth,Nt:e.lineStyle,fs:e.lineVisible?e.lineType:void 0,Ds:e.pointMarkersVisible?e.pointMarkersRadius||e.lineWidth/2+2:void 0,vs:s,tt:this.Ls,ds:i})}}class Rn extends X{constructor(){super(...arguments),this.zt=null,this.ae=0}J(t){this.zt=t}K(t){if(this.zt===null||this.zt.In.length===0||this.zt.tt===null)return;const{horizontalPixelRatio:e}=t;this.ae=function(r,h){if(r>=2.5&&r<=4)return Math.floor(3*h);const o=1-.2*Math.atan(Math.max(4,r)-4)/(.5*Math.PI),l=Math.floor(r*o*h),c=Math.floor(r*h),a=Math.min(l,c);return Math.max(Math.floor(h),a)}(this.zt.le,e),this.ae>=2&&Math.floor(e)%2!=this.ae%2&&this.ae--;const s=this.zt.In;this.zt.Be&&this.Ae(t,s,this.zt.tt),this.zt._i&&this.Ie(t,s,this.zt.tt);const i=this.ze(e);(!this.zt._i||this.ae>2*i)&&this.Le(t,s,this.zt.tt)}Ae(t,e,s){if(this.zt===null)return;const{context:i,horizontalPixelRatio:r,verticalPixelRatio:h}=t;let o="",l=Math.min(Math.floor(r),Math.floor(this.zt.le*r));l=Math.max(Math.floor(r),Math.min(l,this.ae));const c=Math.floor(.5*l);let a=null;for(let d=s.from;d<s.to;d++){const f=e[d];f.Ee!==o&&(i.fillStyle=f.Ee,o=f.Ee);const m=Math.round(Math.min(f.pe,f.me)*h),p=Math.round(Math.max(f.pe,f.me)*h),v=Math.round(f.de*h),b=Math.round(f.fe*h);let y=Math.round(r*f.nt)-c;const w=y+l-1;a!==null&&(y=Math.max(a+1,y),y=Math.min(y,w));const M=w-y+1;i.fillRect(y,v,M,m-v),i.fillRect(y,p+1,M,b-p),a=w}}ze(t){let e=Math.floor(1*t);this.ae<=2*e&&(e=Math.floor(.5*(this.ae-1)));const s=Math.max(Math.floor(t),e);return this.ae<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}Ie(t,e,s){if(this.zt===null)return;const{context:i,horizontalPixelRatio:r,verticalPixelRatio:h}=t;let o="";const l=this.ze(r);let c=null;for(let a=s.from;a<s.to;a++){const d=e[a];d.Ne!==o&&(i.fillStyle=d.Ne,o=d.Ne);let f=Math.round(d.nt*r)-Math.floor(.5*this.ae);const m=f+this.ae-1,p=Math.round(Math.min(d.pe,d.me)*h),v=Math.round(Math.max(d.pe,d.me)*h);if(c!==null&&(f=Math.max(c+1,f),f=Math.min(f,m)),this.zt.le*r>2*l)bn(i,f,p,m-f+1,v-p+1,l);else{const b=m-f+1;i.fillRect(f,p,b,v-p+1)}c=m}}Le(t,e,s){if(this.zt===null)return;const{context:i,horizontalPixelRatio:r,verticalPixelRatio:h}=t;let o="";const l=this.ze(r);for(let c=s.from;c<s.to;c++){const a=e[c];let d=Math.round(Math.min(a.pe,a.me)*h),f=Math.round(Math.max(a.pe,a.me)*h),m=Math.round(a.nt*r)-Math.floor(.5*this.ae),p=m+this.ae-1;if(a.ce!==o){const v=a.ce;i.fillStyle=v,o=v}this.zt._i&&(m+=l,d+=l,p-=l,f-=l),d>f||i.fillRect(m,d,p-m+1,f-d+1)}}}class On extends bi{constructor(){super(...arguments),this.js=new Rn}se(t,e,s){return Object.assign(Object.assign({},this.we(t,e,s)),s.$s(t))}Js(){const t=this.Es.W();this.js.J({In:this.zs,le:this.Ns.St().le(),Be:t.wickVisible,_i:t.borderVisible,tt:this.Ls})}}class Wn{constructor(t,e){this.Fe=t,this.Li=e}X(t,e,s){this.Fe.draw(t,this.Li,e,s)}}class ie extends De{constructor(t,e,s){super(t,e,!1),this.wn=s,this.js=new Wn(this.wn.renderer(),i=>{const r=t.Ct();return r===null?null:t.Dt().Rt(i,r.Vt)})}We(t){return this.wn.priceValueBuilder(t)}je(t){return this.wn.isWhitespace(t)}Ys(){const t=this.Es.Us();this.zs=this.Es.In().ne().map(e=>Object.assign(Object.assign({ot:e.ee,nt:NaN},t.$s(e.ee)),{He:e.$e}))}Gs(t,e){e.Qs(this.zs,Et(this.Ls))}Js(){this.wn.update({bars:this.zs.map(Dn),barSpacing:this.Ns.St().le(),visibleRange:this.Ls},this.Es.W())}}function Dn(n){return{x:n.nt,time:n.ot,originalData:n.He,barColor:n.ce}}class Bn extends X{constructor(){super(...arguments),this.zt=null,this.Ue=[]}J(t){this.zt=t,this.Ue=[]}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:s}){if(this.zt===null||this.zt.it.length===0||this.zt.tt===null)return;this.Ue.length||this.qe(e);const i=Math.max(1,Math.floor(s)),r=Math.round(this.zt.Ye*s)-Math.floor(i/2),h=r+i;for(let o=this.zt.tt.from;o<this.zt.tt.to;o++){const l=this.zt.it[o],c=this.Ue[o-this.zt.tt.from],a=Math.round(l.st*s);let d,f;t.fillStyle=l.ce,a<=r?(d=a,f=h):(d=r,f=a-Math.floor(i/2)+i),t.fillRect(c.Os,d,c.ui-c.Os+1,f-d)}}qe(t){if(this.zt===null||this.zt.it.length===0||this.zt.tt===null)return void(this.Ue=[]);const e=Math.ceil(this.zt.le*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.zt.le*t)-e;this.Ue=new Array(this.zt.tt.to-this.zt.tt.from);for(let r=this.zt.tt.from;r<this.zt.tt.to;r++){const h=this.zt.it[r],o=Math.round(h.nt*t);let l,c;if(s%2){const a=(s-1)/2;l=o-a,c=o+a}else{const a=s/2;l=o-a,c=o+a-1}this.Ue[r-this.zt.tt.from]={Os:l,ui:c,Ze:o,Xe:h.nt*t,ot:h.ot}}for(let r=this.zt.tt.from+1;r<this.zt.tt.to;r++){const h=this.Ue[r-this.zt.tt.from],o=this.Ue[r-this.zt.tt.from-1];h.ot===o.ot+1&&h.Os-o.ui!==e+1&&(o.Ze>o.Xe?o.ui=h.Os-e-1:h.Os=o.ui+e+1)}let i=Math.ceil(this.zt.le*t);for(let r=this.zt.tt.from;r<this.zt.tt.to;r++){const h=this.Ue[r-this.zt.tt.from];h.ui<h.Os&&(h.ui=h.Os);const o=h.ui-h.Os+1;i=Math.min(o,i)}if(e>0&&i<4)for(let r=this.zt.tt.from;r<this.zt.tt.to;r++){const h=this.Ue[r-this.zt.tt.from];h.ui-h.Os+1>i&&(h.Ze>h.Xe?h.ui-=1:h.Os+=1)}}}class In extends ee{constructor(){super(...arguments),this.js=new Bn}se(t,e,s){return Object.assign(Object.assign({},this.ie(t,e)),s.$s(t))}Js(){const t={it:this.zs,le:this.Ns.St().le(),tt:this.Ls,Ye:this.Es.Dt().Rt(this.Es.W().base,x(this.Es.Ct()).Vt)};this.js.J(t)}}class Fn extends ee{constructor(){super(...arguments),this.js=new pi}se(t,e,s){return Object.assign(Object.assign({},this.ie(t,e)),s.$s(t))}Js(){const t=this.Es.W(),e={it:this.zs,Nt:t.lineStyle,fs:t.lineVisible?t.lineType:void 0,et:t.lineWidth,Ds:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,tt:this.Ls,ds:this.Ns.St().le()};this.js.J(e)}}const An=/[2-9]/g;class Lt{constructor(t=50){this.Ke=0,this.Ge=1,this.Je=1,this.Qe={},this.tr=new Map,this.ir=t}nr(){this.Ke=0,this.tr.clear(),this.Ge=1,this.Je=1,this.Qe={}}xi(t,e,s){return this.sr(t,e,s).width}Mi(t,e,s){const i=this.sr(t,e,s);return((i.actualBoundingBoxAscent||0)-(i.actualBoundingBoxDescent||0))/2}sr(t,e,s){const i=s||An,r=String(e).replace(i,"0");if(this.tr.has(r))return O(this.tr.get(r)).er;if(this.Ke===this.ir){const o=this.Qe[this.Je];delete this.Qe[this.Je],this.tr.delete(o),this.Je++,this.Ke--}t.save(),t.textBaseline="middle";const h=t.measureText(r);return t.restore(),h.width===0&&e.length||(this.tr.set(r,{er:h,rr:this.Ge}),this.Qe[this.Ge]=r,this.Ke++,this.Ge++),h}}class Kn{constructor(t){this.hr=null,this.k=null,this.lr="right",this.ar=t}_r(t,e,s){this.hr=t,this.k=e,this.lr=s}X(t){this.k!==null&&this.hr!==null&&this.hr.X(t,this.k,this.ar,this.lr)}}class xi{constructor(t,e,s){this.ur=t,this.ar=new Lt(50),this.cr=e,this.F=s,this.j=-1,this.Wt=new Kn(this.ar)}gt(){const t=this.F.dr(this.cr);if(t===null)return null;const e=t.vr(this.cr)?t.pr():this.cr.Dt();if(e===null)return null;const s=t.mr(e);if(s==="overlay")return null;const i=this.F.br();return i.P!==this.j&&(this.j=i.P,this.ar.nr()),this.Wt._r(this.ur.Ii(),i,s),this.Wt}}class Xn extends X{constructor(){super(...arguments),this.zt=null}J(t){this.zt=t}wr(t,e){var s;if(!(!((s=this.zt)===null||s===void 0)&&s.yt))return null;const{st:i,et:r,gr:h}=this.zt;return e>=i-r-7&&e<=i+r+7?{Mr:this.zt,gr:h}:null}K({context:t,bitmapSize:e,horizontalPixelRatio:s,verticalPixelRatio:i}){if(this.zt===null||this.zt.yt===!1)return;const r=Math.round(this.zt.st*i);r<0||r>e.height||(t.lineCap="butt",t.strokeStyle=this.zt.V,t.lineWidth=Math.floor(this.zt.et*s),dt(t,this.zt.Nt),ni(t,r,0,e.width))}}class Be{constructor(t){this.Sr={st:0,V:"rgba(0, 0, 0, 0)",et:1,Nt:0,yt:!1},this.kr=new Xn,this.ft=!0,this.Es=t,this.Ns=t.$t(),this.kr.J(this.Sr)}bt(){this.ft=!0}gt(){return this.Es.yt()?(this.ft&&(this.yr(),this.ft=!1),this.kr):null}}class Hn extends Be{constructor(t){super(t)}yr(){this.Sr.yt=!1;const t=this.Es.Dt(),e=t.Cr().Cr;if(e!==2&&e!==3)return;const s=this.Es.W();if(!s.baseLineVisible||!this.Es.yt())return;const i=this.Es.Ct();i!==null&&(this.Sr.yt=!0,this.Sr.st=t.Rt(i.Vt,i.Vt),this.Sr.V=s.baseLineColor,this.Sr.et=s.baseLineWidth,this.Sr.Nt=s.baseLineStyle)}}class Un extends X{constructor(){super(...arguments),this.zt=null}J(t){this.zt=t}$e(){return this.zt}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:s}){const i=this.zt;if(i===null)return;const r=Math.max(1,Math.floor(e)),h=r%2/2,o=Math.round(i.Xe.x*e)+h,l=i.Xe.y*s;t.fillStyle=i.Tr,t.beginPath();const c=Math.max(2,1.5*i.Pr)*e;t.arc(o,l,c,0,2*Math.PI,!1),t.fill(),t.fillStyle=i.Rr,t.beginPath(),t.arc(o,l,i.ht*e,0,2*Math.PI,!1),t.fill(),t.lineWidth=r,t.strokeStyle=i.Dr,t.beginPath(),t.arc(o,l,i.ht*e+r/2,0,2*Math.PI,!1),t.stroke()}}const qn=[{Vr:0,Or:.25,Br:4,Ar:10,Ir:.25,zr:0,Lr:.4,Er:.8},{Vr:.25,Or:.525,Br:10,Ar:14,Ir:0,zr:0,Lr:.8,Er:0},{Vr:.525,Or:1,Br:14,Ar:14,Ir:0,zr:0,Lr:0,Er:0}];function cs(n,t,e,s){return function(i,r){if(i==="transparent")return i;const h=jt(i),o=h[3];return`rgba(${h[0]}, ${h[1]}, ${h[2]}, ${r*o})`}(n,e+(s-e)*t)}function as(n,t){const e=n%2600/2600;let s;for(const l of qn)if(e>=l.Vr&&e<=l.Or){s=l;break}rt(s!==void 0,"Last price animation internal logic error");const i=(e-s.Vr)/(s.Or-s.Vr);return{Rr:cs(t,i,s.Ir,s.zr),Dr:cs(t,i,s.Lr,s.Er),ht:(r=i,h=s.Br,o=s.Ar,h+(o-h)*r)};var r,h,o}class Jn{constructor(t){this.Wt=new Un,this.ft=!0,this.Nr=!0,this.Fr=performance.now(),this.Wr=this.Fr-1,this.jr=t}Hr(){this.Wr=this.Fr-1,this.bt()}$r(){if(this.bt(),this.jr.W().lastPriceAnimation===2){const t=performance.now(),e=this.Wr-t;if(e>0)return void(e<650&&(this.Wr+=2600));this.Fr=t,this.Wr=t+2600}}bt(){this.ft=!0}Ur(){this.Nr=!0}yt(){return this.jr.W().lastPriceAnimation!==0}qr(){switch(this.jr.W().lastPriceAnimation){case 0:return!1;case 1:return!0;case 2:return performance.now()<=this.Wr}}gt(){return this.ft?(this.Mt(),this.ft=!1,this.Nr=!1):this.Nr&&(this.Yr(),this.Nr=!1),this.Wt}Mt(){this.Wt.J(null);const t=this.jr.$t().St(),e=t.Xs(),s=this.jr.Ct();if(e===null||s===null)return;const i=this.jr.Zr(!0);if(i.Xr||!e.Kr(i.ee))return;const r={x:t.It(i.ee),y:this.jr.Dt().Rt(i._t,s.Vt)},h=i.V,o=this.jr.W().lineWidth,l=as(this.Gr(),h);this.Wt.J({Tr:h,Pr:o,Rr:l.Rr,Dr:l.Dr,ht:l.ht,Xe:r})}Yr(){const t=this.Wt.$e();if(t!==null){const e=as(this.Gr(),t.Tr);t.Rr=e.Rr,t.Dr=e.Dr,t.ht=e.ht}}Gr(){return this.qr()?performance.now()-this.Fr:2599}}function Ct(n,t){return di(Math.min(Math.max(n,12),30)*t)}function Tt(n,t){switch(n){case"arrowDown":case"arrowUp":return Ct(t,1);case"circle":return Ct(t,.8);case"square":return Ct(t,.7)}}function wi(n){return function(t){const e=Math.ceil(t);return e%2!=0?e-1:e}(Ct(n,1))}function us(n){return Math.max(Ct(n,.1),3)}function ds(n,t,e){return t?n:e?Math.ceil(n/2):0}function yi(n,t,e,s,i){const r=Tt("square",e),h=(r-1)/2,o=n-h,l=t-h;return s>=o&&s<=o+r&&i>=l&&i<=l+r}function fs(n,t,e,s){const i=(Tt("arrowUp",s)-1)/2*e.Jr,r=(di(s/2)-1)/2*e.Jr;t.beginPath(),n?(t.moveTo(e.nt-i,e.st),t.lineTo(e.nt,e.st-i),t.lineTo(e.nt+i,e.st),t.lineTo(e.nt+r,e.st),t.lineTo(e.nt+r,e.st+i),t.lineTo(e.nt-r,e.st+i),t.lineTo(e.nt-r,e.st)):(t.moveTo(e.nt-i,e.st),t.lineTo(e.nt,e.st+i),t.lineTo(e.nt+i,e.st),t.lineTo(e.nt+r,e.st),t.lineTo(e.nt+r,e.st-i),t.lineTo(e.nt-r,e.st-i),t.lineTo(e.nt-r,e.st)),t.fill()}function Gn(n,t,e,s,i,r){return yi(t,e,s,i,r)}class Qn extends X{constructor(){super(...arguments),this.zt=null,this.ar=new Lt,this.j=-1,this.H="",this.Qr=""}J(t){this.zt=t}_r(t,e){this.j===t&&this.H===e||(this.j=t,this.H=e,this.Qr=wt(t,e),this.ar.nr())}wr(t,e){if(this.zt===null||this.zt.tt===null)return null;for(let s=this.zt.tt.from;s<this.zt.tt.to;s++){const i=this.zt.it[s];if(Zn(i,t,e))return{Mr:i.th,gr:i.gr}}return null}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:s},i,r){if(this.zt!==null&&this.zt.tt!==null){t.textBaseline="middle",t.font=this.Qr;for(let h=this.zt.tt.from;h<this.zt.tt.to;h++){const o=this.zt.it[h];o.Kt!==void 0&&(o.Kt.Hi=this.ar.xi(t,o.Kt.ih),o.Kt.At=this.j,o.Kt.nt=o.nt-o.Kt.Hi/2),Yn(o,t,e,s)}}}}function Yn(n,t,e,s){t.fillStyle=n.V,n.Kt!==void 0&&function(i,r,h,o,l,c){i.save(),i.scale(l,c),i.fillText(r,h,o),i.restore()}(t,n.Kt.ih,n.Kt.nt,n.Kt.st,e,s),function(i,r,h){if(i.Ks!==0){switch(i.nh){case"arrowDown":return void fs(!1,r,h,i.Ks);case"arrowUp":return void fs(!0,r,h,i.Ks);case"circle":return void function(o,l,c){const a=(Tt("circle",c)-1)/2;o.beginPath(),o.arc(l.nt,l.st,a*l.Jr,0,2*Math.PI,!1),o.fill()}(r,h,i.Ks);case"square":return void function(o,l,c){const a=Tt("square",c),d=(a-1)*l.Jr/2,f=l.nt-d,m=l.st-d;o.fillRect(f,m,a*l.Jr,a*l.Jr)}(r,h,i.Ks)}i.nh}}(n,t,function(i,r,h){const o=Math.max(1,Math.floor(r))%2/2;return{nt:Math.round(i.nt*r)+o,st:i.st*h,Jr:r}}(n,e,s))}function Zn(n,t,e){return!(n.Kt===void 0||!function(s,i,r,h,o,l){const c=h/2;return o>=s&&o<=s+r&&l>=i-c&&l<=i+c}(n.Kt.nt,n.Kt.st,n.Kt.Hi,n.Kt.At,t,e))||function(s,i,r){if(s.Ks===0)return!1;switch(s.nh){case"arrowDown":case"arrowUp":return Gn(0,s.nt,s.st,s.Ks,i,r);case"circle":return function(h,o,l,c,a){const d=2+Tt("circle",l)/2,f=h-c,m=o-a;return Math.sqrt(f*f+m*m)<=d}(s.nt,s.st,s.Ks,i,r);case"square":return yi(s.nt,s.st,s.Ks,i,r)}}(n,t,e)}function tr(n,t,e,s,i,r,h,o,l){const c=J(e)?e:e.Se,a=J(e)?e:e.Me,d=J(e)?e:e.xe,f=J(t.size)?Math.max(t.size,0):1,m=wi(o.le())*f,p=m/2;switch(n.Ks=m,t.position){case"inBar":return n.st=h.Rt(c,l),void(n.Kt!==void 0&&(n.Kt.st=n.st+p+r+.6*i));case"aboveBar":return n.st=h.Rt(a,l)-p-s.sh,n.Kt!==void 0&&(n.Kt.st=n.st-p-.6*i,s.sh+=1.2*i),void(s.sh+=m+r);case"belowBar":return n.st=h.Rt(d,l)+p+s.eh,n.Kt!==void 0&&(n.Kt.st=n.st+p+r+.6*i,s.eh+=1.2*i),void(s.eh+=m+r)}t.position}class er{constructor(t,e){this.ft=!0,this.rh=!0,this.hh=!0,this.ah=null,this.oh=null,this.Wt=new Qn,this.jr=t,this.$i=e,this.zt={it:[],tt:null}}bt(t){this.ft=!0,this.hh=!0,t==="data"&&(this.rh=!0,this.oh=null)}gt(t){if(!this.jr.yt())return null;this.ft&&this._h();const e=this.$i.W().layout;return this.Wt._r(e.fontSize,e.fontFamily),this.Wt.J(this.zt),this.Wt}uh(){if(this.hh){if(this.jr.dh().length>0){const t=this.$i.St().le(),e=us(t),s=1.5*wi(t)+2*e,i=this.fh();this.ah={above:ds(s,i.aboveBar,i.inBar),below:ds(s,i.belowBar,i.inBar)}}else this.ah=null;this.hh=!1}return this.ah}fh(){return this.oh===null&&(this.oh=this.jr.dh().reduce((t,e)=>(t[e.position]||(t[e.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1})),this.oh}_h(){const t=this.jr.Dt(),e=this.$i.St(),s=this.jr.dh();this.rh&&(this.zt.it=s.map(a=>({ot:a.time,nt:0,st:0,Ks:0,nh:a.shape,V:a.color,th:a.th,gr:a.id,Kt:void 0})),this.rh=!1);const i=this.$i.W().layout;this.zt.tt=null;const r=e.Xs();if(r===null)return;const h=this.jr.Ct();if(h===null||this.zt.it.length===0)return;let o=NaN;const l=us(e.le()),c={sh:l,eh:l};this.zt.tt=gi(this.zt.it,r,!0);for(let a=this.zt.tt.from;a<this.zt.tt.to;a++){const d=s[a];d.time!==o&&(c.sh=l,c.eh=l,o=d.time);const f=this.zt.it[a];f.nt=e.It(d.time),d.text!==void 0&&d.text.length>0&&(f.Kt={ih:d.text,nt:0,st:0,Hi:0,At:0});const m=this.jr.ph(d.time);m!==null&&tr(f,d,m,c,i.fontSize,l,t,e,h.Vt)}this.ft=!1}}class sr extends Be{constructor(t){super(t)}yr(){const t=this.Sr;t.yt=!1;const e=this.Es.W();if(!e.priceLineVisible||!this.Es.yt())return;const s=this.Es.Zr(e.priceLineSource===0);s.Xr||(t.yt=!0,t.st=s.ki,t.V=this.Es.mh(s.V),t.et=e.priceLineWidth,t.Nt=e.priceLineStyle)}}class ir extends Yt{constructor(t){super(),this.jt=t}zi(t,e,s){t.yt=!1,e.yt=!1;const i=this.jt;if(!i.yt())return;const r=i.W(),h=r.lastValueVisible,o=i.bh()!=="",l=r.seriesLastValueMode===0,c=i.Zr(!1);if(c.Xr)return;h&&(t.Kt=this.wh(c,h,l),t.yt=t.Kt.length!==0),(o||l)&&(e.Kt=this.gh(c,h,o,l),e.yt=e.Kt.length>0);const a=i.mh(c.V),d=Gt(a);s.t=d.t,s.ki=c.ki,e.Ot=i.$t().Bt(c.ki/i.Dt().At()),t.Ot=a,t.V=d.i,e.V=d.i}gh(t,e,s,i){let r="";const h=this.jt.bh();return s&&h.length!==0&&(r+=`${h} `),e&&i&&(r+=this.jt.Dt().Mh()?t.xh:t.Sh),r.trim()}wh(t,e,s){return e?s?this.jt.Dt().Mh()?t.Sh:t.xh:t.Kt:""}}function ps(n,t,e,s){const i=Number.isFinite(t),r=Number.isFinite(e);return i&&r?n(t,e):i||r?i?t:e:s}class W{constructor(t,e){this.kh=t,this.yh=e}Ch(t){return t!==null&&this.kh===t.kh&&this.yh===t.yh}Th(){return new W(this.kh,this.yh)}Ph(){return this.kh}Rh(){return this.yh}Dh(){return this.yh-this.kh}Ni(){return this.yh===this.kh||Number.isNaN(this.yh)||Number.isNaN(this.kh)}ts(t){return t===null?this:new W(ps(Math.min,this.Ph(),t.Ph(),-1/0),ps(Math.max,this.Rh(),t.Rh(),1/0))}Vh(t){if(!J(t)||this.yh-this.kh===0)return;const e=.5*(this.yh+this.kh);let s=this.yh-e,i=this.kh-e;s*=t,i*=t,this.yh=e+s,this.kh=e+i}Oh(t){J(t)&&(this.yh+=t,this.kh+=t)}Bh(){return{minValue:this.kh,maxValue:this.yh}}static Ah(t){return t===null?null:new W(t.minValue,t.maxValue)}}class qt{constructor(t,e){this.Ih=t,this.zh=e||null}Lh(){return this.Ih}Eh(){return this.zh}Bh(){return this.Ih===null?null:{priceRange:this.Ih.Bh(),margins:this.zh||void 0}}static Ah(t){return t===null?null:new qt(W.Ah(t.priceRange),t.margins)}}class nr extends Be{constructor(t,e){super(t),this.Nh=e}yr(){const t=this.Sr;t.yt=!1;const e=this.Nh.W();if(!this.Es.yt()||!e.lineVisible)return;const s=this.Nh.Fh();s!==null&&(t.yt=!0,t.st=s,t.V=e.color,t.et=e.lineWidth,t.Nt=e.lineStyle,t.gr=this.Nh.W().id)}}class rr extends Yt{constructor(t,e){super(),this.jr=t,this.Nh=e}zi(t,e,s){t.yt=!1,e.yt=!1;const i=this.Nh.W(),r=i.axisLabelVisible,h=i.title!=="",o=this.jr;if(!r||!o.yt())return;const l=this.Nh.Fh();if(l===null)return;h&&(e.Kt=i.title,e.yt=!0),e.Ot=o.$t().Bt(l/o.Dt().At()),t.Kt=this.Wh(i.price),t.yt=!0;const c=Gt(i.axisLabelColor||i.color);s.t=c.t;const a=i.axisLabelTextColor||c.i;t.V=a,e.V=a,s.ki=l}Wh(t){const e=this.jr.Ct();return e===null?"":this.jr.Dt().Fi(t,e.Vt)}}class hr{constructor(t,e){this.jr=t,this.cn=e,this.jh=new nr(t,this),this.ur=new rr(t,this),this.Hh=new xi(this.ur,t,t.$t())}$h(t){K(this.cn,t),this.bt(),this.jr.$t().Uh()}W(){return this.cn}qh(){return this.jh}Yh(){return this.Hh}Zh(){return this.ur}bt(){this.jh.bt(),this.ur.bt()}Fh(){const t=this.jr,e=t.Dt();if(t.$t().St().Ni()||e.Ni())return null;const s=t.Ct();return s===null?null:e.Rt(this.cn.price,s.Vt)}}class or extends Oe{constructor(t){super(),this.$i=t}$t(){return this.$i}}const lr={Bar:(n,t,e,s)=>{var i;const r=t.upColor,h=t.downColor,o=x(n(e,s)),l=gt(o.Vt[0])<=gt(o.Vt[3]);return{ce:(i=o.V)!==null&&i!==void 0?i:l?r:h}},Candlestick:(n,t,e,s)=>{var i,r,h;const o=t.upColor,l=t.downColor,c=t.borderUpColor,a=t.borderDownColor,d=t.wickUpColor,f=t.wickDownColor,m=x(n(e,s)),p=gt(m.Vt[0])<=gt(m.Vt[3]);return{ce:(i=m.V)!==null&&i!==void 0?i:p?o:l,Ne:(r=m.Ot)!==null&&r!==void 0?r:p?c:a,Ee:(h=m.Xh)!==null&&h!==void 0?h:p?d:f}},Custom:(n,t,e,s)=>{var i;return{ce:(i=x(n(e,s)).V)!==null&&i!==void 0?i:t.color}},Area:(n,t,e,s)=>{var i,r,h,o;const l=x(n(e,s));return{ce:(i=l.lt)!==null&&i!==void 0?i:t.lineColor,lt:(r=l.lt)!==null&&r!==void 0?r:t.lineColor,Ps:(h=l.Ps)!==null&&h!==void 0?h:t.topColor,Rs:(o=l.Rs)!==null&&o!==void 0?o:t.bottomColor}},Baseline:(n,t,e,s)=>{var i,r,h,o,l,c;const a=x(n(e,s));return{ce:a.Vt[3]>=t.baseValue.price?t.topLineColor:t.bottomLineColor,Re:(i=a.Re)!==null&&i!==void 0?i:t.topLineColor,De:(r=a.De)!==null&&r!==void 0?r:t.bottomLineColor,ke:(h=a.ke)!==null&&h!==void 0?h:t.topFillColor1,ye:(o=a.ye)!==null&&o!==void 0?o:t.topFillColor2,Ce:(l=a.Ce)!==null&&l!==void 0?l:t.bottomFillColor1,Te:(c=a.Te)!==null&&c!==void 0?c:t.bottomFillColor2}},Line:(n,t,e,s)=>{var i,r;const h=x(n(e,s));return{ce:(i=h.V)!==null&&i!==void 0?i:t.color,lt:(r=h.V)!==null&&r!==void 0?r:t.color}},Histogram:(n,t,e,s)=>{var i;return{ce:(i=x(n(e,s)).V)!==null&&i!==void 0?i:t.color}}};class cr{constructor(t){this.Kh=(e,s)=>s!==void 0?s.Vt:this.jr.In().Gh(e),this.jr=t,this.Jh=lr[t.Qh()]}$s(t,e){return this.Jh(this.Kh,this.jr.W(),t,e)}}var ms;(function(n){n[n.NearestLeft=-1]="NearestLeft",n[n.None=0]="None",n[n.NearestRight=1]="NearestRight"})(ms||(ms={}));const nt=30;class ar{constructor(){this.tl=[],this.il=new Map,this.nl=new Map}sl(){return this.Ks()>0?this.tl[this.tl.length-1]:null}el(){return this.Ks()>0?this.rl(0):null}An(){return this.Ks()>0?this.rl(this.tl.length-1):null}Ks(){return this.tl.length}Ni(){return this.Ks()===0}Kr(t){return this.hl(t,0)!==null}Gh(t){return this.ll(t)}ll(t,e=0){const s=this.hl(t,e);return s===null?null:Object.assign(Object.assign({},this.al(s)),{ee:this.rl(s)})}ne(){return this.tl}ol(t,e,s){if(this.Ni())return null;let i=null;for(const r of s)i=Wt(i,this._l(t,e,r));return i}J(t){this.nl.clear(),this.il.clear(),this.tl=t}rl(t){return this.tl[t].ee}al(t){return this.tl[t]}hl(t,e){const s=this.ul(t);if(s===null&&e!==0)switch(e){case-1:return this.cl(t);case 1:return this.dl(t);default:throw new TypeError("Unknown search mode")}return s}cl(t){let e=this.fl(t);return e>0&&(e-=1),e!==this.tl.length&&this.rl(e)<t?e:null}dl(t){const e=this.vl(t);return e!==this.tl.length&&t<this.rl(e)?e:null}ul(t){const e=this.fl(t);return e===this.tl.length||t<this.tl[e].ee?null:e}fl(t){return Vt(this.tl,t,(e,s)=>e.ee<s)}vl(t){return vi(this.tl,t,(e,s)=>e.ee>s)}pl(t,e,s){let i=null;for(let r=t;r<e;r++){const h=this.tl[r].Vt[s];Number.isNaN(h)||(i===null?i={ml:h,bl:h}:(h<i.ml&&(i.ml=h),h>i.bl&&(i.bl=h)))}return i}_l(t,e,s){if(this.Ni())return null;let i=null;const r=x(this.el()),h=x(this.An()),o=Math.max(t,r),l=Math.min(e,h),c=Math.ceil(o/nt)*nt,a=Math.max(c,Math.floor(l/nt)*nt);{const f=this.fl(o),m=this.vl(Math.min(l,c,e));i=Wt(i,this.pl(f,m,s))}let d=this.il.get(s);d===void 0&&(d=new Map,this.il.set(s,d));for(let f=Math.max(c+1,o);f<a;f+=nt){const m=Math.floor(f/nt);let p=d.get(m);if(p===void 0){const v=this.fl(m*nt),b=this.vl((m+1)*nt-1);p=this.pl(v,b,s),d.set(m,p)}i=Wt(i,p)}{const f=this.fl(a),m=this.vl(l);i=Wt(i,this.pl(f,m,s))}return i}}function Wt(n,t){return n===null?t:t===null?n:{ml:Math.min(n.ml,t.ml),bl:Math.max(n.bl,t.bl)}}class ur{constructor(t){this.wl=t}X(t,e,s){this.wl.draw(t)}gl(t,e,s){var i,r;(r=(i=this.wl).drawBackground)===null||r===void 0||r.call(i,t)}}class ne{constructor(t){this.tr=null,this.wn=t}gt(){var t;const e=this.wn.renderer();if(e===null)return null;if(((t=this.tr)===null||t===void 0?void 0:t.Ml)===e)return this.tr.xl;const s=new ur(e);return this.tr={Ml:e,xl:s},s}Sl(){var t,e,s;return(s=(e=(t=this.wn).zOrder)===null||e===void 0?void 0:e.call(t))!==null&&s!==void 0?s:"normal"}}function Si(n){var t,e,s,i,r;return{Kt:n.text(),ki:n.coordinate(),Si:(t=n.fixedCoordinate)===null||t===void 0?void 0:t.call(n),V:n.textColor(),t:n.backColor(),yt:(s=(e=n.visible)===null||e===void 0?void 0:e.call(n))===null||s===void 0||s,hi:(r=(i=n.tickVisible)===null||i===void 0?void 0:i.call(n))===null||r===void 0||r}}class dr{constructor(t,e){this.Wt=new li,this.kl=t,this.yl=e}gt(){return this.Wt.J(Object.assign({Hi:this.yl.Hi()},Si(this.kl))),this.Wt}}class fr extends Yt{constructor(t,e){super(),this.kl=t,this.Li=e}zi(t,e,s){const i=Si(this.kl);s.t=i.t,t.V=i.V;const r=2/12*this.Li.P();s.wi=r,s.gi=r,s.ki=i.ki,s.Si=i.Si,t.Kt=i.Kt,t.yt=i.yt,t.hi=i.hi}}class pr{constructor(t,e){this.Cl=null,this.Tl=null,this.Pl=null,this.Rl=null,this.Dl=null,this.Vl=t,this.jr=e}Ol(){return this.Vl}Vn(){var t,e;(e=(t=this.Vl).updateAllViews)===null||e===void 0||e.call(t)}Pn(){var t,e,s,i;const r=(s=(e=(t=this.Vl).paneViews)===null||e===void 0?void 0:e.call(t))!==null&&s!==void 0?s:[];if(((i=this.Cl)===null||i===void 0?void 0:i.Ml)===r)return this.Cl.xl;const h=r.map(o=>new ne(o));return this.Cl={Ml:r,xl:h},h}Qi(){var t,e,s,i;const r=(s=(e=(t=this.Vl).timeAxisViews)===null||e===void 0?void 0:e.call(t))!==null&&s!==void 0?s:[];if(((i=this.Tl)===null||i===void 0?void 0:i.Ml)===r)return this.Tl.xl;const h=this.jr.$t().St(),o=r.map(l=>new dr(l,h));return this.Tl={Ml:r,xl:o},o}Rn(){var t,e,s,i;const r=(s=(e=(t=this.Vl).priceAxisViews)===null||e===void 0?void 0:e.call(t))!==null&&s!==void 0?s:[];if(((i=this.Pl)===null||i===void 0?void 0:i.Ml)===r)return this.Pl.xl;const h=this.jr.Dt(),o=r.map(l=>new fr(l,h));return this.Pl={Ml:r,xl:o},o}Bl(){var t,e,s,i;const r=(s=(e=(t=this.Vl).priceAxisPaneViews)===null||e===void 0?void 0:e.call(t))!==null&&s!==void 0?s:[];if(((i=this.Rl)===null||i===void 0?void 0:i.Ml)===r)return this.Rl.xl;const h=r.map(o=>new ne(o));return this.Rl={Ml:r,xl:h},h}Al(){var t,e,s,i;const r=(s=(e=(t=this.Vl).timeAxisPaneViews)===null||e===void 0?void 0:e.call(t))!==null&&s!==void 0?s:[];if(((i=this.Dl)===null||i===void 0?void 0:i.Ml)===r)return this.Dl.xl;const h=r.map(o=>new ne(o));return this.Dl={Ml:r,xl:h},h}Il(t,e){var s,i,r;return(r=(i=(s=this.Vl).autoscaleInfo)===null||i===void 0?void 0:i.call(s,t,e))!==null&&r!==void 0?r:null}wr(t,e){var s,i,r;return(r=(i=(s=this.Vl).hitTest)===null||i===void 0?void 0:i.call(s,t,e))!==null&&r!==void 0?r:null}}function re(n,t,e,s){n.forEach(i=>{t(i).forEach(r=>{r.Sl()===e&&s.push(r)})})}function he(n){return n.Pn()}function mr(n){return n.Bl()}function vr(n){return n.Al()}class Ie extends or{constructor(t,e,s,i,r){super(t),this.zt=new ar,this.jh=new sr(this),this.zl=[],this.Ll=new Hn(this),this.El=null,this.Nl=null,this.Fl=[],this.Wl=[],this.jl=null,this.Hl=[],this.cn=e,this.$l=s;const h=new ir(this);this.rn=[h],this.Hh=new xi(h,this,t),s!=="Area"&&s!=="Line"&&s!=="Baseline"||(this.El=new Jn(this)),this.Ul(),this.ql(r)}S(){this.jl!==null&&clearTimeout(this.jl)}mh(t){return this.cn.priceLineColor||t}Zr(t){const e={Xr:!0},s=this.Dt();if(this.$t().St().Ni()||s.Ni()||this.zt.Ni())return e;const i=this.$t().St().Xs(),r=this.Ct();if(i===null||r===null)return e;let h,o;if(t){const d=this.zt.sl();if(d===null)return e;h=d,o=d.ee}else{const d=this.zt.ll(i.ui(),-1);if(d===null||(h=this.zt.Gh(d.ee),h===null))return e;o=d.ee}const l=h.Vt[3],c=this.Us().$s(o,{Vt:h}),a=s.Rt(l,r.Vt);return{Xr:!1,_t:l,Kt:s.Fi(l,r.Vt),xh:s.Yl(l),Sh:s.Zl(l,r.Vt),V:c.ce,ki:a,ee:o}}Us(){return this.Nl!==null||(this.Nl=new cr(this)),this.Nl}W(){return this.cn}$h(t){const e=t.priceScaleId;e!==void 0&&e!==this.cn.priceScaleId&&this.$t().Xl(this,e),K(this.cn,t),t.priceFormat!==void 0&&(this.Ul(),this.$t().Kl()),this.$t().Gl(this),this.$t().Jl(),this.wn.bt("options")}J(t,e){this.zt.J(t),this.Ql(),this.wn.bt("data"),this.dn.bt("data"),this.El!==null&&(e&&e.ta?this.El.$r():t.length===0&&this.El.Hr());const s=this.$t().dr(this);this.$t().ia(s),this.$t().Gl(this),this.$t().Jl(),this.$t().Uh()}na(t){this.Fl=t,this.Ql();const e=this.$t().dr(this);this.dn.bt("data"),this.$t().ia(e),this.$t().Gl(this),this.$t().Jl(),this.$t().Uh()}sa(){return this.Fl}dh(){return this.Wl}ea(t){const e=new hr(this,t);return this.zl.push(e),this.$t().Gl(this),e}ra(t){const e=this.zl.indexOf(t);e!==-1&&this.zl.splice(e,1),this.$t().Gl(this)}Qh(){return this.$l}Ct(){const t=this.ha();return t===null?null:{Vt:t.Vt[3],la:t.ot}}ha(){const t=this.$t().St().Xs();if(t===null)return null;const e=t.Os();return this.zt.ll(e,1)}In(){return this.zt}ph(t){const e=this.zt.Gh(t);return e===null?null:this.$l==="Bar"||this.$l==="Candlestick"||this.$l==="Custom"?{ge:e.Vt[0],Me:e.Vt[1],xe:e.Vt[2],Se:e.Vt[3]}:e.Vt[3]}aa(t){const e=[];re(this.Hl,he,"top",e);const s=this.El;return s!==null&&s.yt()&&(this.jl===null&&s.qr()&&(this.jl=setTimeout(()=>{this.jl=null,this.$t().oa()},0)),s.Ur(),e.unshift(s)),e}Pn(){const t=[];this._a()||t.push(this.Ll),t.push(this.wn,this.jh,this.dn);const e=this.zl.map(s=>s.qh());return t.push(...e),re(this.Hl,he,"normal",t),t}ua(){return this.ca(he,"bottom")}da(t){return this.ca(mr,t)}fa(t){return this.ca(vr,t)}va(t,e){return this.Hl.map(s=>s.wr(t,e)).filter(s=>s!==null)}Ji(t){return[this.Hh,...this.zl.map(e=>e.Yh())]}Rn(t,e){if(e!==this.Yi&&!this._a())return[];const s=[...this.rn];for(const i of this.zl)s.push(i.Zh());return this.Hl.forEach(i=>{s.push(...i.Rn())}),s}Qi(){const t=[];return this.Hl.forEach(e=>{t.push(...e.Qi())}),t}Il(t,e){if(this.cn.autoscaleInfoProvider!==void 0){const s=this.cn.autoscaleInfoProvider(()=>{const i=this.pa(t,e);return i===null?null:i.Bh()});return qt.Ah(s)}return this.pa(t,e)}ma(){return this.cn.priceFormat.minMove}ba(){return this.wa}Vn(){var t;this.wn.bt(),this.dn.bt();for(const e of this.rn)e.bt();for(const e of this.zl)e.bt();this.jh.bt(),this.Ll.bt(),(t=this.El)===null||t===void 0||t.bt(),this.Hl.forEach(e=>e.Vn())}Dt(){return x(super.Dt())}kt(t){if(!((this.$l==="Line"||this.$l==="Area"||this.$l==="Baseline")&&this.cn.crosshairMarkerVisible))return null;const e=this.zt.Gh(t);return e===null?null:{_t:e.Vt[3],ht:this.ga(),Ot:this.Ma(),Pt:this.xa(),Tt:this.Sa(t)}}bh(){return this.cn.title}yt(){return this.cn.visible}ka(t){this.Hl.push(new pr(t,this))}ya(t){this.Hl=this.Hl.filter(e=>e.Ol()!==t)}Ca(){if(this.wn instanceof ie)return t=>this.wn.We(t)}Ta(){if(this.wn instanceof ie)return t=>this.wn.je(t)}_a(){return!Zt(this.Dt().Pa())}pa(t,e){if(!kt(t)||!kt(e)||this.zt.Ni())return null;const s=this.$l==="Line"||this.$l==="Area"||this.$l==="Baseline"||this.$l==="Histogram"?[3]:[2,1],i=this.zt.ol(t,e,s);let r=i!==null?new W(i.ml,i.bl):null;if(this.Qh()==="Histogram"){const o=this.cn.base,l=new W(o,o);r=r!==null?r.ts(l):l}let h=this.dn.uh();return this.Hl.forEach(o=>{const l=o.Il(t,e);if(l!=null&&l.priceRange){const m=new W(l.priceRange.minValue,l.priceRange.maxValue);r=r!==null?r.ts(m):m}var c,a,d,f;l!=null&&l.margins&&(c=h,a=l.margins,h={above:Math.max((d=c==null?void 0:c.above)!==null&&d!==void 0?d:0,a.above),below:Math.max((f=c==null?void 0:c.below)!==null&&f!==void 0?f:0,a.below)})}),new qt(r,h)}ga(){switch(this.$l){case"Line":case"Area":case"Baseline":return this.cn.crosshairMarkerRadius}return 0}Ma(){switch(this.$l){case"Line":case"Area":case"Baseline":{const t=this.cn.crosshairMarkerBorderColor;if(t.length!==0)return t}}return null}xa(){switch(this.$l){case"Line":case"Area":case"Baseline":return this.cn.crosshairMarkerBorderWidth}return 0}Sa(t){switch(this.$l){case"Line":case"Area":case"Baseline":{const e=this.cn.crosshairMarkerBackgroundColor;if(e.length!==0)return e}}return this.Us().$s(t).ce}Ul(){switch(this.cn.priceFormat.type){case"custom":this.wa={format:this.cn.priceFormat.formatter};break;case"volume":this.wa=new Mn(this.cn.priceFormat.precision);break;case"percent":this.wa=new ci(this.cn.priceFormat.precision);break;default:{const t=Math.pow(10,this.cn.priceFormat.precision);this.wa=new te(t,this.cn.priceFormat.minMove*t)}}this.Yi!==null&&this.Yi.Ra()}Ql(){const t=this.$t().St();if(!t.Da()||this.zt.Ni())return void(this.Wl=[]);const e=x(this.zt.el());this.Wl=this.Fl.map((s,i)=>{const r=x(t.Va(s.time,!0)),h=r<e?1:-1;return{time:x(this.zt.ll(r,h)).ee,position:s.position,shape:s.shape,color:s.color,id:s.id,th:i,text:s.text,size:s.size,originalTime:s.originalTime}})}ql(t){switch(this.dn=new er(this,this.$t()),this.$l){case"Bar":this.wn=new Tn(this,this.$t());break;case"Candlestick":this.wn=new On(this,this.$t());break;case"Line":this.wn=new Fn(this,this.$t());break;case"Custom":this.wn=new ie(this,this.$t(),O(t));break;case"Area":this.wn=new En(this,this.$t());break;case"Baseline":this.wn=new Vn(this,this.$t());break;case"Histogram":this.wn=new In(this,this.$t());break;default:throw Error("Unknown chart style assigned: "+this.$l)}}ca(t,e){const s=[];return re(this.Hl,t,e,s),s}}class gr{constructor(t){this.cn=t}Oa(t,e,s){let i=t;if(this.cn.mode===0)return i;const r=s.vn(),h=r.Ct();if(h===null)return i;const o=r.Rt(t,h),l=s.Ba().filter(a=>a instanceof Ie).reduce((a,d)=>{if(s.vr(d)||!d.yt())return a;const f=d.Dt(),m=d.In();if(f.Ni()||!m.Kr(e))return a;const p=m.Gh(e);if(p===null)return a;const v=gt(d.Ct());return a.concat([f.Rt(p.Vt[3],v.Vt)])},[]);if(l.length===0)return i;l.sort((a,d)=>Math.abs(a-o)-Math.abs(d-o));const c=l[0];return i=r.pn(c,h),i}}class br extends X{constructor(){super(...arguments),this.zt=null}J(t){this.zt=t}K({context:t,bitmapSize:e,horizontalPixelRatio:s,verticalPixelRatio:i}){if(this.zt===null)return;const r=Math.max(1,Math.floor(s));t.lineWidth=r,function(h,o){h.save(),h.lineWidth%2&&h.translate(.5,.5),o(),h.restore()}(t,()=>{const h=x(this.zt);if(h.Aa){t.strokeStyle=h.Ia,dt(t,h.za),t.beginPath();for(const o of h.La){const l=Math.round(o.Ea*s);t.moveTo(l,-r),t.lineTo(l,e.height+r)}t.stroke()}if(h.Na){t.strokeStyle=h.Fa,dt(t,h.Wa),t.beginPath();for(const o of h.ja){const l=Math.round(o.Ea*i);t.moveTo(-r,l),t.lineTo(e.width+r,l)}t.stroke()}})}}class xr{constructor(t){this.Wt=new br,this.ft=!0,this.tn=t}bt(){this.ft=!0}gt(){if(this.ft){const t=this.tn.$t().W().grid,e={Na:t.horzLines.visible,Aa:t.vertLines.visible,Fa:t.horzLines.color,Ia:t.vertLines.color,Wa:t.horzLines.style,za:t.vertLines.style,ja:this.tn.vn().Ha(),La:(this.tn.$t().St().Ha()||[]).map(s=>({Ea:s.coord}))};this.Wt.J(e),this.ft=!1}return this.Wt}}class wr{constructor(t){this.wn=new xr(t)}qh(){return this.wn}}const oe={$a:4,Ua:1e-4};function bt(n,t){const e=100*(n-t)/t;return t<0?-e:e}function yr(n,t){const e=bt(n.Ph(),t),s=bt(n.Rh(),t);return new W(e,s)}function _t(n,t){const e=100*(n-t)/t+100;return t<0?-e:e}function Sr(n,t){const e=_t(n.Ph(),t),s=_t(n.Rh(),t);return new W(e,s)}function Jt(n,t){const e=Math.abs(n);if(e<1e-15)return 0;const s=Math.log10(e+t.Ua)+t.$a;return n<0?-s:s}function Nt(n,t){const e=Math.abs(n);if(e<1e-15)return 0;const s=Math.pow(10,e-t.$a)-t.Ua;return n<0?-s:s}function Mt(n,t){if(n===null)return null;const e=Jt(n.Ph(),t),s=Jt(n.Rh(),t);return new W(e,s)}function Dt(n,t){if(n===null)return null;const e=Nt(n.Ph(),t),s=Nt(n.Rh(),t);return new W(e,s)}function le(n){if(n===null)return oe;const t=Math.abs(n.Rh()-n.Ph());if(t>=1||t<1e-15)return oe;const e=Math.ceil(Math.abs(Math.log10(t))),s=oe.$a+e;return{$a:s,Ua:1/Math.pow(10,s)}}class ce{constructor(t,e){if(this.qa=t,this.Ya=e,function(s){if(s<0)return!1;for(let i=s;i>1;i/=10)if(i%10!=0)return!1;return!0}(this.qa))this.Za=[2,2.5,2];else{this.Za=[];for(let s=this.qa;s!==1;){if(s%2==0)this.Za.push(2),s/=2;else{if(s%5!=0)throw new Error("unexpected base");this.Za.push(2,2.5),s/=5}if(this.Za.length>100)throw new Error("something wrong with base")}}}Xa(t,e,s){const i=this.qa===0?0:1/this.qa;let r=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-e)))),h=0,o=this.Ya[0];for(;;){const d=Ot(r,i,1e-14)&&r>i+1e-14,f=Ot(r,s*o,1e-14),m=Ot(r,1,1e-14);if(!(d&&f&&m))break;r/=o,o=this.Ya[++h%this.Ya.length]}if(r<=i+1e-14&&(r=i),r=Math.max(1,r),this.Za.length>0&&(l=r,c=1,a=1e-14,Math.abs(l-c)<a))for(h=0,o=this.Za[0];Ot(r,s*o,1e-14)&&r>i+1e-14;)r/=o,o=this.Za[++h%this.Za.length];var l,c,a;return r}}class vs{constructor(t,e,s,i){this.Ka=[],this.Li=t,this.qa=e,this.Ga=s,this.Ja=i}Xa(t,e){if(t<e)throw new Error("high < low");const s=this.Li.At(),i=(t-e)*this.Qa()/s,r=new ce(this.qa,[2,2.5,2]),h=new ce(this.qa,[2,2,2.5]),o=new ce(this.qa,[2.5,2,2]),l=[];return l.push(r.Xa(t,e,i),h.Xa(t,e,i),o.Xa(t,e,i)),function(c){if(c.length<1)throw Error("array is empty");let a=c[0];for(let d=1;d<c.length;++d)c[d]<a&&(a=c[d]);return a}(l)}io(){const t=this.Li,e=t.Ct();if(e===null)return void(this.Ka=[]);const s=t.At(),i=this.Ga(s-1,e),r=this.Ga(0,e),h=this.Li.W().entireTextOnly?this.no()/2:0,o=h,l=s-1-h,c=Math.max(i,r),a=Math.min(i,r);if(c===a)return void(this.Ka=[]);let d=this.Xa(c,a),f=c%d;f+=f<0?d:0;const m=c>=a?1:-1;let p=null,v=0;for(let b=c-f;b>a;b-=d){const y=this.Ja(b,e,!0);p!==null&&Math.abs(y-p)<this.Qa()||y<o||y>l||(v<this.Ka.length?(this.Ka[v].Ea=y,this.Ka[v].so=t.eo(b)):this.Ka.push({Ea:y,so:t.eo(b)}),v++,p=y,t.ro()&&(d=this.Xa(b*m,a)))}this.Ka.length=v}Ha(){return this.Ka}no(){return this.Li.P()}Qa(){return Math.ceil(2.5*this.no())}}function Mi(n){return n.slice().sort((t,e)=>x(t.Xi())-x(e.Xi()))}var gs;(function(n){n[n.Normal=0]="Normal",n[n.Logarithmic=1]="Logarithmic",n[n.Percentage=2]="Percentage",n[n.IndexedTo100=3]="IndexedTo100"})(gs||(gs={}));const bs=new ci,xs=new te(100,1);class Mr{constructor(t,e,s,i){this.ho=0,this.lo=null,this.Ih=null,this.ao=null,this.oo={_o:!1,uo:null},this.co=0,this.do=0,this.fo=new T,this.vo=new T,this.po=[],this.mo=null,this.bo=null,this.wo=null,this.Mo=null,this.wa=xs,this.xo=le(null),this.So=t,this.cn=e,this.ko=s,this.yo=i,this.Co=new vs(this,100,this.To.bind(this),this.Po.bind(this))}Pa(){return this.So}W(){return this.cn}$h(t){if(K(this.cn,t),this.Ra(),t.mode!==void 0&&this.Ro({Cr:t.mode}),t.scaleMargins!==void 0){const e=O(t.scaleMargins.top),s=O(t.scaleMargins.bottom);if(e<0||e>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${e}`);if(s<0||s>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${s}`);if(e+s>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${e+s}`);this.Do(),this.bo=null}}Vo(){return this.cn.autoScale}ro(){return this.cn.mode===1}Mh(){return this.cn.mode===2}Oo(){return this.cn.mode===3}Cr(){return{Wn:this.cn.autoScale,Bo:this.cn.invertScale,Cr:this.cn.mode}}Ro(t){const e=this.Cr();let s=null;t.Wn!==void 0&&(this.cn.autoScale=t.Wn),t.Cr!==void 0&&(this.cn.mode=t.Cr,t.Cr!==2&&t.Cr!==3||(this.cn.autoScale=!0),this.oo._o=!1),e.Cr===1&&t.Cr!==e.Cr&&(function(r,h){if(r===null)return!1;const o=Nt(r.Ph(),h),l=Nt(r.Rh(),h);return isFinite(o)&&isFinite(l)}(this.Ih,this.xo)?(s=Dt(this.Ih,this.xo),s!==null&&this.Ao(s)):this.cn.autoScale=!0),t.Cr===1&&t.Cr!==e.Cr&&(s=Mt(this.Ih,this.xo),s!==null&&this.Ao(s));const i=e.Cr!==this.cn.mode;i&&(e.Cr===2||this.Mh())&&this.Ra(),i&&(e.Cr===3||this.Oo())&&this.Ra(),t.Bo!==void 0&&e.Bo!==t.Bo&&(this.cn.invertScale=t.Bo,this.Io()),this.vo.m(e,this.Cr())}zo(){return this.vo}P(){return this.ko.fontSize}At(){return this.ho}Lo(t){this.ho!==t&&(this.ho=t,this.Do(),this.bo=null)}Eo(){if(this.lo)return this.lo;const t=this.At()-this.No()-this.Fo();return this.lo=t,t}Lh(){return this.Wo(),this.Ih}Ao(t,e){const s=this.Ih;(e||s===null&&t!==null||s!==null&&!s.Ch(t))&&(this.bo=null,this.Ih=t)}Ni(){return this.Wo(),this.ho===0||!this.Ih||this.Ih.Ni()}jo(t){return this.Bo()?t:this.At()-1-t}Rt(t,e){return this.Mh()?t=bt(t,e):this.Oo()&&(t=_t(t,e)),this.Po(t,e)}te(t,e,s){this.Wo();const i=this.Fo(),r=x(this.Lh()),h=r.Ph(),o=r.Rh(),l=this.Eo()-1,c=this.Bo(),a=l/(o-h),d=s===void 0?0:s.from,f=s===void 0?t.length:s.to,m=this.Ho();for(let p=d;p<f;p++){const v=t[p],b=v._t;if(isNaN(b))continue;let y=b;m!==null&&(y=m(v._t,e));const w=i+a*(y-h),M=c?w:this.ho-1-w;v.st=M}}be(t,e,s){this.Wo();const i=this.Fo(),r=x(this.Lh()),h=r.Ph(),o=r.Rh(),l=this.Eo()-1,c=this.Bo(),a=l/(o-h),d=s===void 0?0:s.from,f=s===void 0?t.length:s.to,m=this.Ho();for(let p=d;p<f;p++){const v=t[p];let b=v.ge,y=v.Me,w=v.xe,M=v.Se;m!==null&&(b=m(v.ge,e),y=m(v.Me,e),w=m(v.xe,e),M=m(v.Se,e));let S=i+a*(b-h),N=c?S:this.ho-1-S;v.pe=N,S=i+a*(y-h),N=c?S:this.ho-1-S,v.de=N,S=i+a*(w-h),N=c?S:this.ho-1-S,v.fe=N,S=i+a*(M-h),N=c?S:this.ho-1-S,v.me=N}}pn(t,e){const s=this.To(t,e);return this.$o(s,e)}$o(t,e){let s=t;return this.Mh()?s=function(i,r){return r<0&&(i=-i),i/100*r+r}(s,e):this.Oo()&&(s=function(i,r){return i-=100,r<0&&(i=-i),i/100*r+r}(s,e)),s}Ba(){return this.po}Uo(){if(this.mo)return this.mo;let t=[];for(let e=0;e<this.po.length;e++){const s=this.po[e];s.Xi()===null&&s.Ki(e+1),t.push(s)}return t=Mi(t),this.mo=t,this.mo}qo(t){this.po.indexOf(t)===-1&&(this.po.push(t),this.Ra(),this.Yo())}Zo(t){const e=this.po.indexOf(t);if(e===-1)throw new Error("source is not attached to scale");this.po.splice(e,1),this.po.length===0&&(this.Ro({Wn:!0}),this.Ao(null)),this.Ra(),this.Yo()}Ct(){let t=null;for(const e of this.po){const s=e.Ct();s!==null&&(t===null||s.la<t.la)&&(t=s)}return t===null?null:t.Vt}Bo(){return this.cn.invertScale}Ha(){const t=this.Ct()===null;if(this.bo!==null&&(t||this.bo.Xo===t))return this.bo.Ha;this.Co.io();const e=this.Co.Ha();return this.bo={Ha:e,Xo:t},this.fo.m(),e}Ko(){return this.fo}Go(t){this.Mh()||this.Oo()||this.wo===null&&this.ao===null&&(this.Ni()||(this.wo=this.ho-t,this.ao=x(this.Lh()).Th()))}Jo(t){if(this.Mh()||this.Oo()||this.wo===null)return;this.Ro({Wn:!1}),(t=this.ho-t)<0&&(t=0);let e=(this.wo+.2*(this.ho-1))/(t+.2*(this.ho-1));const s=x(this.ao).Th();e=Math.max(e,.1),s.Vh(e),this.Ao(s)}Qo(){this.Mh()||this.Oo()||(this.wo=null,this.ao=null)}t_(t){this.Vo()||this.Mo===null&&this.ao===null&&(this.Ni()||(this.Mo=t,this.ao=x(this.Lh()).Th()))}i_(t){if(this.Vo()||this.Mo===null)return;const e=x(this.Lh()).Dh()/(this.Eo()-1);let s=t-this.Mo;this.Bo()&&(s*=-1);const i=s*e,r=x(this.ao).Th();r.Oh(i),this.Ao(r,!0),this.bo=null}n_(){this.Vo()||this.Mo!==null&&(this.Mo=null,this.ao=null)}ba(){return this.wa||this.Ra(),this.wa}Fi(t,e){switch(this.cn.mode){case 2:return this.s_(bt(t,e));case 3:return this.ba().format(_t(t,e));default:return this.Wh(t)}}eo(t){switch(this.cn.mode){case 2:return this.s_(t);case 3:return this.ba().format(t);default:return this.Wh(t)}}Yl(t){return this.Wh(t,x(this.e_()).ba())}Zl(t,e){return t=bt(t,e),this.s_(t,bs)}r_(){return this.po}h_(t){this.oo={uo:t,_o:!1}}Vn(){this.po.forEach(t=>t.Vn())}Ra(){this.bo=null;const t=this.e_();let e=100;t!==null&&(e=Math.round(1/t.ma())),this.wa=xs,this.Mh()?(this.wa=bs,e=100):this.Oo()?(this.wa=new te(100,1),e=100):t!==null&&(this.wa=t.ba()),this.Co=new vs(this,e,this.To.bind(this),this.Po.bind(this)),this.Co.io()}Yo(){this.mo=null}e_(){return this.po[0]||null}No(){return this.Bo()?this.cn.scaleMargins.bottom*this.At()+this.do:this.cn.scaleMargins.top*this.At()+this.co}Fo(){return this.Bo()?this.cn.scaleMargins.top*this.At()+this.co:this.cn.scaleMargins.bottom*this.At()+this.do}Wo(){this.oo._o||(this.oo._o=!0,this.l_())}Do(){this.lo=null}Po(t,e){if(this.Wo(),this.Ni())return 0;t=this.ro()&&t?Jt(t,this.xo):t;const s=x(this.Lh()),i=this.Fo()+(this.Eo()-1)*(t-s.Ph())/s.Dh();return this.jo(i)}To(t,e){if(this.Wo(),this.Ni())return 0;const s=this.jo(t),i=x(this.Lh()),r=i.Ph()+i.Dh()*((s-this.Fo())/(this.Eo()-1));return this.ro()?Nt(r,this.xo):r}Io(){this.bo=null,this.Co.io()}l_(){const t=this.oo.uo;if(t===null)return;let e=null;const s=this.r_();let i=0,r=0;for(const l of s){if(!l.yt())continue;const c=l.Ct();if(c===null)continue;const a=l.Il(t.Os(),t.ui());let d=a&&a.Lh();if(d!==null){switch(this.cn.mode){case 1:d=Mt(d,this.xo);break;case 2:d=yr(d,c.Vt);break;case 3:d=Sr(d,c.Vt)}if(e=e===null?d:e.ts(x(d)),a!==null){const f=a.Eh();f!==null&&(i=Math.max(i,f.above),r=Math.max(r,f.below))}}}if(i===this.co&&r===this.do||(this.co=i,this.do=r,this.bo=null,this.Do()),e!==null){if(e.Ph()===e.Rh()){const l=this.e_(),c=5*(l===null||this.Mh()||this.Oo()?1:l.ma());this.ro()&&(e=Dt(e,this.xo)),e=new W(e.Ph()-c,e.Rh()+c),this.ro()&&(e=Mt(e,this.xo))}if(this.ro()){const l=Dt(e,this.xo),c=le(l);if(h=c,o=this.xo,h.$a!==o.$a||h.Ua!==o.Ua){const a=this.ao!==null?Dt(this.ao,this.xo):null;this.xo=c,e=Mt(l,c),a!==null&&(this.ao=Mt(a,c))}}this.Ao(e)}else this.Ih===null&&(this.Ao(new W(-.5,.5)),this.xo=le(null));var h,o;this.oo._o=!0}Ho(){return this.Mh()?bt:this.Oo()?_t:this.ro()?t=>Jt(t,this.xo):null}a_(t,e,s){return e===void 0?(s===void 0&&(s=this.ba()),s.format(t)):e(t)}Wh(t,e){return this.a_(t,this.yo.priceFormatter,e)}s_(t,e){return this.a_(t,this.yo.percentageFormatter,e)}}class Cr{constructor(t,e){this.po=[],this.o_=new Map,this.ho=0,this.__=0,this.u_=1e3,this.mo=null,this.c_=new T,this.yl=t,this.$i=e,this.d_=new wr(this);const s=e.W();this.f_=this.v_("left",s.leftPriceScale),this.p_=this.v_("right",s.rightPriceScale),this.f_.zo().l(this.m_.bind(this,this.f_),this),this.p_.zo().l(this.m_.bind(this,this.p_),this),this.b_(s)}b_(t){if(t.leftPriceScale&&this.f_.$h(t.leftPriceScale),t.rightPriceScale&&this.p_.$h(t.rightPriceScale),t.localization&&(this.f_.Ra(),this.p_.Ra()),t.overlayPriceScales){const e=Array.from(this.o_.values());for(const s of e){const i=x(s[0].Dt());i.$h(t.overlayPriceScales),t.localization&&i.Ra()}}}w_(t){switch(t){case"left":return this.f_;case"right":return this.p_}return this.o_.has(t)?O(this.o_.get(t))[0].Dt():null}S(){this.$t().g_().p(this),this.f_.zo().p(this),this.p_.zo().p(this),this.po.forEach(t=>{t.S&&t.S()}),this.c_.m()}M_(){return this.u_}x_(t){this.u_=t}$t(){return this.$i}Hi(){return this.__}At(){return this.ho}S_(t){this.__=t,this.k_()}Lo(t){this.ho=t,this.f_.Lo(t),this.p_.Lo(t),this.po.forEach(e=>{if(this.vr(e)){const s=e.Dt();s!==null&&s.Lo(t)}}),this.k_()}Ba(){return this.po}vr(t){const e=t.Dt();return e===null||this.f_!==e&&this.p_!==e}qo(t,e,s){const i=s!==void 0?s:this.C_().y_+1;this.T_(t,e,i)}Zo(t){const e=this.po.indexOf(t);rt(e!==-1,"removeDataSource: invalid data source"),this.po.splice(e,1);const s=x(t.Dt()).Pa();if(this.o_.has(s)){const r=O(this.o_.get(s)),h=r.indexOf(t);h!==-1&&(r.splice(h,1),r.length===0&&this.o_.delete(s))}const i=t.Dt();i&&i.Ba().indexOf(t)>=0&&i.Zo(t),i!==null&&(i.Yo(),this.P_(i)),this.mo=null}mr(t){return t===this.f_?"left":t===this.p_?"right":"overlay"}R_(){return this.f_}D_(){return this.p_}V_(t,e){t.Go(e)}O_(t,e){t.Jo(e),this.k_()}B_(t){t.Qo()}A_(t,e){t.t_(e)}I_(t,e){t.i_(e),this.k_()}z_(t){t.n_()}k_(){this.po.forEach(t=>{t.Vn()})}vn(){let t=null;return this.$i.W().rightPriceScale.visible&&this.p_.Ba().length!==0?t=this.p_:this.$i.W().leftPriceScale.visible&&this.f_.Ba().length!==0?t=this.f_:this.po.length!==0&&(t=this.po[0].Dt()),t===null&&(t=this.p_),t}pr(){let t=null;return this.$i.W().rightPriceScale.visible?t=this.p_:this.$i.W().leftPriceScale.visible&&(t=this.f_),t}P_(t){t!==null&&t.Vo()&&this.L_(t)}E_(t){const e=this.yl.Xs();t.Ro({Wn:!0}),e!==null&&t.h_(e),this.k_()}N_(){this.L_(this.f_),this.L_(this.p_)}F_(){this.P_(this.f_),this.P_(this.p_),this.po.forEach(t=>{this.vr(t)&&this.P_(t.Dt())}),this.k_(),this.$i.Uh()}Uo(){return this.mo===null&&(this.mo=Mi(this.po)),this.mo}W_(){return this.c_}j_(){return this.d_}L_(t){const e=t.r_();if(e&&e.length>0&&!this.yl.Ni()){const s=this.yl.Xs();s!==null&&t.h_(s)}t.Vn()}C_(){const t=this.Uo();if(t.length===0)return{H_:0,y_:0};let e=0,s=0;for(let i=0;i<t.length;i++){const r=t[i].Xi();r!==null&&(r<e&&(e=r),r>s&&(s=r))}return{H_:e,y_:s}}T_(t,e,s){let i=this.w_(e);if(i===null&&(i=this.v_(e,this.$i.W().overlayPriceScales)),this.po.push(t),!Zt(e)){const r=this.o_.get(e)||[];r.push(t),this.o_.set(e,r)}i.qo(t),t.Gi(i),t.Ki(s),this.P_(i),this.mo=null}m_(t,e,s){e.Cr!==s.Cr&&this.L_(t)}v_(t,e){const s=Object.assign({visible:!0,autoScale:!0},Y(e)),i=new Mr(t,s,this.$i.W().layout,this.$i.W().localization);return i.Lo(this.At()),i}}class _r{constructor(t,e,s=50){this.Ke=0,this.Ge=1,this.Je=1,this.tr=new Map,this.Qe=new Map,this.U_=t,this.q_=e,this.ir=s}Y_(t){const e=t.time,s=this.q_.cacheKey(e),i=this.tr.get(s);if(i!==void 0)return i.Z_;if(this.Ke===this.ir){const h=this.Qe.get(this.Je);this.Qe.delete(this.Je),this.tr.delete(O(h)),this.Je++,this.Ke--}const r=this.U_(t);return this.tr.set(s,{Z_:r,rr:this.Ge}),this.Qe.set(this.Ge,s),this.Ke++,this.Ge++,r}}class zt{constructor(t,e){rt(t<=e,"right should be >= left"),this.X_=t,this.K_=e}Os(){return this.X_}ui(){return this.K_}G_(){return this.K_-this.X_+1}Kr(t){return this.X_<=t&&t<=this.K_}Ch(t){return this.X_===t.Os()&&this.K_===t.ui()}}function ws(n,t){return n===null||t===null?n===t:n.Ch(t)}class Nr{constructor(){this.J_=new Map,this.tr=null,this.Q_=!1}tu(t){this.Q_=t,this.tr=null}iu(t,e){this.nu(e),this.tr=null;for(let s=e;s<t.length;++s){const i=t[s];let r=this.J_.get(i.timeWeight);r===void 0&&(r=[],this.J_.set(i.timeWeight,r)),r.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}su(t,e){const s=Math.ceil(e/t);return this.tr!==null&&this.tr.eu===s||(this.tr={Ha:this.ru(s),eu:s}),this.tr.Ha}nu(t){if(t===0)return void this.J_.clear();const e=[];this.J_.forEach((s,i)=>{t<=s[0].index?e.push(i):s.splice(Vt(s,t,r=>r.index<t),1/0)});for(const s of e)this.J_.delete(s)}ru(t){let e=[];for(const s of Array.from(this.J_.keys()).sort((i,r)=>r-i)){if(!this.J_.get(s))continue;const i=e;e=[];const r=i.length;let h=0;const o=O(this.J_.get(s)),l=o.length;let c=1/0,a=-1/0;for(let d=0;d<l;d++){const f=o[d],m=f.index;for(;h<r;){const p=i[h],v=p.index;if(!(v<m)){c=v;break}h++,e.push(p),a=v,c=1/0}if(c-m>=t&&m-a>=t)e.push(f),a=m;else if(this.Q_)return i}for(;h<r;h++)e.push(i[h])}return e}}class xt{constructor(t){this.hu=t}lu(){return this.hu===null?null:new zt(Math.floor(this.hu.Os()),Math.ceil(this.hu.ui()))}au(){return this.hu}static ou(){return new xt(null)}}function zr(n,t){return n.weight>t.weight?n:t}class jr{constructor(t,e,s,i){this.__=0,this._u=null,this.uu=[],this.Mo=null,this.wo=null,this.cu=new Nr,this.du=new Map,this.fu=xt.ou(),this.vu=!0,this.pu=new T,this.mu=new T,this.bu=new T,this.wu=null,this.gu=null,this.Mu=[],this.cn=e,this.yo=s,this.xu=e.rightOffset,this.Su=e.barSpacing,this.$i=t,this.q_=i,this.ku(),this.cu.tu(e.uniformDistribution)}W(){return this.cn}yu(t){K(this.yo,t),this.Cu(),this.ku()}$h(t,e){var s;K(this.cn,t),this.cn.fixLeftEdge&&this.Tu(),this.cn.fixRightEdge&&this.Pu(),t.barSpacing!==void 0&&this.$i.Gn(t.barSpacing),t.rightOffset!==void 0&&this.$i.Jn(t.rightOffset),t.minBarSpacing!==void 0&&this.$i.Gn((s=t.barSpacing)!==null&&s!==void 0?s:this.Su),this.Cu(),this.ku(),this.bu.m()}mn(t){var e,s;return(s=(e=this.uu[t])===null||e===void 0?void 0:e.time)!==null&&s!==void 0?s:null}Ui(t){var e;return(e=this.uu[t])!==null&&e!==void 0?e:null}Va(t,e){if(this.uu.length<1)return null;if(this.q_.key(t)>this.q_.key(this.uu[this.uu.length-1].time))return e?this.uu.length-1:null;const s=Vt(this.uu,this.q_.key(t),(i,r)=>this.q_.key(i.time)<r);return this.q_.key(t)<this.q_.key(this.uu[s].time)?e?s:null:s}Ni(){return this.__===0||this.uu.length===0||this._u===null}Da(){return this.uu.length>0}Xs(){return this.Ru(),this.fu.lu()}Du(){return this.Ru(),this.fu.au()}Vu(){const t=this.Xs();if(t===null)return null;const e={from:t.Os(),to:t.ui()};return this.Ou(e)}Ou(t){const e=Math.round(t.from),s=Math.round(t.to),i=x(this.Bu()),r=x(this.Au());return{from:x(this.Ui(Math.max(i,e))),to:x(this.Ui(Math.min(r,s)))}}Iu(t){return{from:x(this.Va(t.from,!0)),to:x(this.Va(t.to,!0))}}Hi(){return this.__}S_(t){if(!isFinite(t)||t<=0||this.__===t)return;const e=this.Du(),s=this.__;if(this.__=t,this.vu=!0,this.cn.lockVisibleTimeRangeOnResize&&s!==0){const i=this.Su*t/s;this.Su=i}if(this.cn.fixLeftEdge&&e!==null&&e.Os()<=0){const i=s-t;this.xu-=Math.round(i/this.Su)+1,this.vu=!0}this.zu(),this.Lu()}It(t){if(this.Ni()||!kt(t))return 0;const e=this.Eu()+this.xu-t;return this.__-(e+.5)*this.Su-1}Qs(t,e){const s=this.Eu(),i=e===void 0?0:e.from,r=e===void 0?t.length:e.to;for(let h=i;h<r;h++){const o=t[h].ot,l=s+this.xu-o,c=this.__-(l+.5)*this.Su-1;t[h].nt=c}}Nu(t){return Math.ceil(this.Fu(t))}Jn(t){this.vu=!0,this.xu=t,this.Lu(),this.$i.Wu(),this.$i.Uh()}le(){return this.Su}Gn(t){this.ju(t),this.Lu(),this.$i.Wu(),this.$i.Uh()}Hu(){return this.xu}Ha(){if(this.Ni())return null;if(this.gu!==null)return this.gu;const t=this.Su,e=5*(this.$i.W().layout.fontSize+4)/8*(this.cn.tickMarkMaxCharacterLength||8),s=Math.round(e/t),i=x(this.Xs()),r=Math.max(i.Os(),i.Os()-s),h=Math.max(i.ui(),i.ui()-s),o=this.cu.su(t,e),l=this.Bu()+s,c=this.Au()-s,a=this.$u(),d=this.cn.fixLeftEdge||a,f=this.cn.fixRightEdge||a;let m=0;for(const p of o){if(!(r<=p.index&&p.index<=h))continue;let v;m<this.Mu.length?(v=this.Mu[m],v.coord=this.It(p.index),v.label=this.Uu(p),v.weight=p.weight):(v={needAlignCoordinate:!1,coord:this.It(p.index),label:this.Uu(p),weight:p.weight},this.Mu.push(v)),this.Su>e/2&&!a?v.needAlignCoordinate=!1:v.needAlignCoordinate=d&&p.index<=l||f&&p.index>=c,m++}return this.Mu.length=m,this.gu=this.Mu,this.Mu}qu(){this.vu=!0,this.Gn(this.cn.barSpacing),this.Jn(this.cn.rightOffset)}Yu(t){this.vu=!0,this._u=t,this.Lu(),this.Tu()}Zu(t,e){const s=this.Fu(t),i=this.le(),r=i+e*(i/10);this.Gn(r),this.cn.rightBarStaysOnScroll||this.Jn(this.Hu()+(s-this.Fu(t)))}Go(t){this.Mo&&this.n_(),this.wo===null&&this.wu===null&&(this.Ni()||(this.wo=t,this.Xu()))}Jo(t){if(this.wu===null)return;const e=ye(this.__-t,0,this.__),s=ye(this.__-x(this.wo),0,this.__);e!==0&&s!==0&&this.Gn(this.wu.le*e/s)}Qo(){this.wo!==null&&(this.wo=null,this.Ku())}t_(t){this.Mo===null&&this.wu===null&&(this.Ni()||(this.Mo=t,this.Xu()))}i_(t){if(this.Mo===null)return;const e=(this.Mo-t)/this.le();this.xu=x(this.wu).Hu+e,this.vu=!0,this.Lu()}n_(){this.Mo!==null&&(this.Mo=null,this.Ku())}Gu(){this.Ju(this.cn.rightOffset)}Ju(t,e=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(e)||e<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const s=this.xu,i=performance.now();this.$i.Zn({Qu:r=>(r-i)/e>=1,tc:r=>{const h=(r-i)/e;return h>=1?t:s+(t-s)*h}})}bt(t,e){this.vu=!0,this.uu=t,this.cu.iu(t,e),this.Lu()}nc(){return this.pu}sc(){return this.mu}ec(){return this.bu}Eu(){return this._u||0}rc(t){const e=t.G_();this.ju(this.__/e),this.xu=t.ui()-this.Eu(),this.Lu(),this.vu=!0,this.$i.Wu(),this.$i.Uh()}hc(){const t=this.Bu(),e=this.Au();t!==null&&e!==null&&this.rc(new zt(t,e+this.cn.rightOffset))}lc(t){const e=new zt(t.from,t.to);this.rc(e)}qi(t){return this.yo.timeFormatter!==void 0?this.yo.timeFormatter(t.originalTime):this.q_.formatHorzItem(t.time)}$u(){const{handleScroll:t,handleScale:e}=this.$i.W();return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||e.axisDoubleClickReset.time||e.axisPressedMouseMove.time||e.mouseWheel||e.pinch)}Bu(){return this.uu.length===0?null:0}Au(){return this.uu.length===0?null:this.uu.length-1}ac(t){return(this.__-1-t)/this.Su}Fu(t){const e=this.ac(t),s=this.Eu()+this.xu-e;return Math.round(1e6*s)/1e6}ju(t){const e=this.Su;this.Su=t,this.zu(),e!==this.Su&&(this.vu=!0,this.oc())}Ru(){if(!this.vu)return;if(this.vu=!1,this.Ni())return void this._c(xt.ou());const t=this.Eu(),e=this.__/this.Su,s=this.xu+t,i=new zt(s-e+1,s);this._c(new xt(i))}zu(){const t=this.uc();if(this.Su<t&&(this.Su=t,this.vu=!0),this.__!==0){const e=.5*this.__;this.Su>e&&(this.Su=e,this.vu=!0)}}uc(){return this.cn.fixLeftEdge&&this.cn.fixRightEdge&&this.uu.length!==0?this.__/this.uu.length:this.cn.minBarSpacing}Lu(){const t=this.cc();t!==null&&this.xu<t&&(this.xu=t,this.vu=!0);const e=this.dc();this.xu>e&&(this.xu=e,this.vu=!0)}cc(){const t=this.Bu(),e=this._u;return t===null||e===null?null:t-e-1+(this.cn.fixLeftEdge?this.__/this.Su:Math.min(2,this.uu.length))}dc(){return this.cn.fixRightEdge?0:this.__/this.Su-Math.min(2,this.uu.length)}Xu(){this.wu={le:this.le(),Hu:this.Hu()}}Ku(){this.wu=null}Uu(t){let e=this.du.get(t.weight);return e===void 0&&(e=new _r(s=>this.fc(s),this.q_),this.du.set(t.weight,e)),e.Y_(t)}fc(t){return this.q_.formatTickmark(t,this.yo)}_c(t){const e=this.fu;this.fu=t,ws(e.lu(),this.fu.lu())||this.pu.m(),ws(e.au(),this.fu.au())||this.mu.m(),this.oc()}oc(){this.gu=null}Cu(){this.oc(),this.du.clear()}ku(){this.q_.updateFormatter(this.yo)}Tu(){if(!this.cn.fixLeftEdge)return;const t=this.Bu();if(t===null)return;const e=this.Xs();if(e===null)return;const s=e.Os()-t;if(s<0){const i=this.xu-s-1;this.Jn(i)}this.zu()}Pu(){this.Lu(),this.zu()}}class kr{X(t,e,s){t.useMediaCoordinateSpace(i=>this.K(i,e,s))}gl(t,e,s){t.useMediaCoordinateSpace(i=>this.vc(i,e,s))}vc(t,e,s){}}class Er extends kr{constructor(t){super(),this.mc=new Map,this.zt=t}K(t){}vc(t){if(!this.zt.yt)return;const{context:e,mediaSize:s}=t;let i=0;for(const h of this.zt.bc){if(h.Kt.length===0)continue;e.font=h.R;const o=this.wc(e,h.Kt);o>s.width?h.Zu=s.width/o:h.Zu=1,i+=h.gc*h.Zu}let r=0;switch(this.zt.Mc){case"top":r=0;break;case"center":r=Math.max((s.height-i)/2,0);break;case"bottom":r=Math.max(s.height-i,0)}e.fillStyle=this.zt.V;for(const h of this.zt.bc){e.save();let o=0;switch(this.zt.xc){case"left":e.textAlign="left",o=h.gc/2;break;case"center":e.textAlign="center",o=s.width/2;break;case"right":e.textAlign="right",o=s.width-1-h.gc/2}e.translate(o,r),e.textBaseline="top",e.font=h.R,e.scale(h.Zu,h.Zu),e.fillText(h.Kt,0,h.Sc),e.restore(),r+=h.gc*h.Zu}}wc(t,e){const s=this.kc(t.font);let i=s.get(e);return i===void 0&&(i=t.measureText(e).width,s.set(e,i)),i}kc(t){let e=this.mc.get(t);return e===void 0&&(e=new Map,this.mc.set(t,e)),e}}class Lr{constructor(t){this.ft=!0,this.Ft={yt:!1,V:"",bc:[],Mc:"center",xc:"center"},this.Wt=new Er(this.Ft),this.jt=t}bt(){this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.Wt}Mt(){const t=this.jt.W(),e=this.Ft;e.yt=t.visible,e.yt&&(e.V=t.color,e.xc=t.horzAlign,e.Mc=t.vertAlign,e.bc=[{Kt:t.text,R:wt(t.fontSize,t.fontFamily,t.fontStyle),gc:1.2*t.fontSize,Sc:0,Zu:0}])}}class Tr extends Oe{constructor(t,e){super(),this.cn=e,this.wn=new Lr(this)}Rn(){return[]}Pn(){return[this.wn]}W(){return this.cn}Vn(){this.wn.bt()}}var ys,Ss,Ms,Se,Cs;(function(n){n[n.OnTouchEnd=0]="OnTouchEnd",n[n.OnNextTap=1]="OnNextTap"})(ys||(ys={}));class Pr{constructor(t,e,s){this.yc=[],this.Cc=[],this.__=0,this.Tc=null,this.Pc=new T,this.Rc=new T,this.Dc=null,this.Vc=t,this.cn=e,this.q_=s,this.Oc=new un(this),this.yl=new jr(this,e.timeScale,this.cn.localization,s),this.vt=new Sn(this,e.crosshair),this.Bc=new gr(e.crosshair),this.Ac=new Tr(this,e.watermark),this.Ic(),this.yc[0].x_(2e3),this.zc=this.Lc(0),this.Ec=this.Lc(1)}Kl(){this.Nc($.es())}Uh(){this.Nc($.ss())}oa(){this.Nc(new $(1))}Gl(t){const e=this.Fc(t);this.Nc(e)}Wc(){return this.Tc}jc(t){const e=this.Tc;this.Tc=t,e!==null&&this.Gl(e.Hc),t!==null&&this.Gl(t.Hc)}W(){return this.cn}$h(t){K(this.cn,t),this.yc.forEach(e=>e.b_(t)),t.timeScale!==void 0&&this.yl.$h(t.timeScale),t.localization!==void 0&&this.yl.yu(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Pc.m(),this.zc=this.Lc(0),this.Ec=this.Lc(1),this.Kl()}$c(t,e){if(t==="left")return void this.$h({leftPriceScale:e});if(t==="right")return void this.$h({rightPriceScale:e});const s=this.Uc(t);s!==null&&(s.Dt.$h(e),this.Pc.m())}Uc(t){for(const e of this.yc){const s=e.w_(t);if(s!==null)return{Ht:e,Dt:s}}return null}St(){return this.yl}qc(){return this.yc}Yc(){return this.Ac}Zc(){return this.vt}Xc(){return this.Rc}Kc(t,e){t.Lo(e),this.Wu()}S_(t){this.__=t,this.yl.S_(this.__),this.yc.forEach(e=>e.S_(t)),this.Wu()}Ic(t){const e=new Cr(this.yl,this);t!==void 0?this.yc.splice(t,0,e):this.yc.push(e);const s=t===void 0?this.yc.length-1:t,i=$.es();return i.Nn(s,{Fn:0,Wn:!0}),this.Nc(i),e}V_(t,e,s){t.V_(e,s)}O_(t,e,s){t.O_(e,s),this.Jl(),this.Nc(this.Gc(t,2))}B_(t,e){t.B_(e),this.Nc(this.Gc(t,2))}A_(t,e,s){e.Vo()||t.A_(e,s)}I_(t,e,s){e.Vo()||(t.I_(e,s),this.Jl(),this.Nc(this.Gc(t,2)))}z_(t,e){e.Vo()||(t.z_(e),this.Nc(this.Gc(t,2)))}E_(t,e){t.E_(e),this.Nc(this.Gc(t,2))}Jc(t){this.yl.Go(t)}Qc(t,e){const s=this.St();if(s.Ni()||e===0)return;const i=s.Hi();t=Math.max(1,Math.min(t,i)),s.Zu(t,e),this.Wu()}td(t){this.nd(0),this.sd(t),this.ed()}rd(t){this.yl.Jo(t),this.Wu()}hd(){this.yl.Qo(),this.Uh()}nd(t){this.yl.t_(t)}sd(t){this.yl.i_(t),this.Wu()}ed(){this.yl.n_(),this.Uh()}wt(){return this.Cc}ld(t,e,s,i,r){this.vt.gn(t,e);let h=NaN,o=this.yl.Nu(t);const l=this.yl.Xs();l!==null&&(o=Math.min(Math.max(l.Os(),o),l.ui()));const c=i.vn(),a=c.Ct();a!==null&&(h=c.pn(e,a)),h=this.Bc.Oa(h,o,i),this.vt.kn(o,h,i),this.oa(),r||this.Rc.m(this.vt.xt(),{x:t,y:e},s)}ad(t,e,s){const i=s.vn(),r=i.Ct(),h=i.Rt(t,x(r)),o=this.yl.Va(e,!0),l=this.yl.It(x(o));this.ld(l,h,null,s,!0)}od(t){this.Zc().Cn(),this.oa(),t||this.Rc.m(null,null,null)}Jl(){const t=this.vt.Ht();if(t!==null){const e=this.vt.xn(),s=this.vt.Sn();this.ld(e,s,null,t)}this.vt.Vn()}_d(t,e,s){const i=this.yl.mn(0);e!==void 0&&s!==void 0&&this.yl.bt(e,s);const r=this.yl.mn(0),h=this.yl.Eu(),o=this.yl.Xs();if(o!==null&&i!==null&&r!==null){const l=o.Kr(h),c=this.q_.key(i)>this.q_.key(r),a=t!==null&&t>h&&!c,d=this.yl.W().allowShiftVisibleRangeOnWhitespaceReplacement,f=l&&(s!==void 0||d)&&this.yl.W().shiftVisibleRangeOnNewBar;if(a&&!f){const m=t-h;this.yl.Jn(this.yl.Hu()-m)}}this.yl.Yu(t)}ia(t){t!==null&&t.F_()}dr(t){const e=this.yc.find(s=>s.Uo().includes(t));return e===void 0?null:e}Wu(){this.Ac.Vn(),this.yc.forEach(t=>t.F_()),this.Jl()}S(){this.yc.forEach(t=>t.S()),this.yc.length=0,this.cn.localization.priceFormatter=void 0,this.cn.localization.percentageFormatter=void 0,this.cn.localization.timeFormatter=void 0}ud(){return this.Oc}br(){return this.Oc.W()}g_(){return this.Pc}dd(t,e,s){const i=this.yc[0],r=this.fd(e,t,i,s);return this.Cc.push(r),this.Cc.length===1?this.Kl():this.Uh(),r}vd(t){const e=this.dr(t),s=this.Cc.indexOf(t);rt(s!==-1,"Series not found"),this.Cc.splice(s,1),x(e).Zo(t),t.S&&t.S()}Xl(t,e){const s=x(this.dr(t));s.Zo(t);const i=this.Uc(e);if(i===null){const r=t.Xi();s.qo(t,e,r)}else{const r=i.Ht===s?t.Xi():void 0;i.Ht.qo(t,e,r)}}hc(){const t=$.ss();t.$n(),this.Nc(t)}pd(t){const e=$.ss();e.Yn(t),this.Nc(e)}Kn(){const t=$.ss();t.Kn(),this.Nc(t)}Gn(t){const e=$.ss();e.Gn(t),this.Nc(e)}Jn(t){const e=$.ss();e.Jn(t),this.Nc(e)}Zn(t){const e=$.ss();e.Zn(t),this.Nc(e)}Un(){const t=$.ss();t.Un(),this.Nc(t)}md(){return this.cn.rightPriceScale.visible?"right":"left"}bd(){return this.Ec}q(){return this.zc}Bt(t){const e=this.Ec,s=this.zc;if(e===s)return e;if(t=Math.max(0,Math.min(100,Math.round(100*t))),this.Dc===null||this.Dc.Ps!==s||this.Dc.Rs!==e)this.Dc={Ps:s,Rs:e,wd:new Map};else{const r=this.Dc.wd.get(t);if(r!==void 0)return r}const i=function(r,h,o){const[l,c,a,d]=jt(r),[f,m,p,v]=jt(h),b=[F(l+o*(f-l)),F(c+o*(m-c)),F(a+o*(p-a)),ri(d+o*(v-d))];return`rgba(${b[0]}, ${b[1]}, ${b[2]}, ${b[3]})`}(s,e,t/100);return this.Dc.wd.set(t,i),i}Gc(t,e){const s=new $(e);if(t!==null){const i=this.yc.indexOf(t);s.Nn(i,{Fn:e})}return s}Fc(t,e){return e===void 0&&(e=2),this.Gc(this.dr(t),e)}Nc(t){this.Vc&&this.Vc(t),this.yc.forEach(e=>e.j_().qh().bt())}fd(t,e,s,i){const r=new Ie(this,t,e,s,i),h=t.priceScaleId!==void 0?t.priceScaleId:this.md();return s.qo(r,h),Zt(h)||r.$h(t),r}Lc(t){const e=this.cn.layout;return e.background.type==="gradient"?t===0?e.background.topColor:e.background.bottomColor:e.background.color}}function Me(n){return!J(n)&&!$t(n)}function Ci(n){return J(n)}(function(n){n[n.Disabled=0]="Disabled",n[n.Continuous=1]="Continuous",n[n.OnDataUpdate=2]="OnDataUpdate"})(Ss||(Ss={})),function(n){n[n.LastBar=0]="LastBar",n[n.LastVisible=1]="LastVisible"}(Ms||(Ms={})),function(n){n.Solid="solid",n.VerticalGradient="gradient"}(Se||(Se={})),function(n){n[n.Year=0]="Year",n[n.Month=1]="Month",n[n.DayOfMonth=2]="DayOfMonth",n[n.Time=3]="Time",n[n.TimeWithSeconds=4]="TimeWithSeconds"}(Cs||(Cs={}));const _s=n=>n.getUTCFullYear();function $r(n,t,e){return t.replace(/yyyy/g,(s=>Z(_s(s),4))(n)).replace(/yy/g,(s=>Z(_s(s)%100,2))(n)).replace(/MMMM/g,((s,i)=>new Date(s.getUTCFullYear(),s.getUTCMonth(),1).toLocaleString(i,{month:"long"}))(n,e)).replace(/MMM/g,((s,i)=>new Date(s.getUTCFullYear(),s.getUTCMonth(),1).toLocaleString(i,{month:"short"}))(n,e)).replace(/MM/g,(s=>Z((i=>i.getUTCMonth()+1)(s),2))(n)).replace(/dd/g,(s=>Z((i=>i.getUTCDate())(s),2))(n))}class _i{constructor(t="yyyy-MM-dd",e="default"){this.gd=t,this.Md=e}Y_(t){return $r(t,this.gd,this.Md)}}class Vr{constructor(t){this.xd=t||"%h:%m:%s"}Y_(t){return this.xd.replace("%h",Z(t.getUTCHours(),2)).replace("%m",Z(t.getUTCMinutes(),2)).replace("%s",Z(t.getUTCSeconds(),2))}}const Rr={Sd:"yyyy-MM-dd",kd:"%h:%m:%s",yd:" ",Cd:"default"};class Or{constructor(t={}){const e=Object.assign(Object.assign({},Rr),t);this.Td=new _i(e.Sd,e.Cd),this.Pd=new Vr(e.kd),this.Rd=e.yd}Y_(t){return`${this.Td.Y_(t)}${this.Rd}${this.Pd.Y_(t)}`}}function Bt(n){return 60*n*60*1e3}function ae(n){return 60*n*1e3}const It=[{Dd:(Ns=1,1e3*Ns),Vd:10},{Dd:ae(1),Vd:20},{Dd:ae(5),Vd:21},{Dd:ae(30),Vd:22},{Dd:Bt(1),Vd:30},{Dd:Bt(3),Vd:31},{Dd:Bt(6),Vd:32},{Dd:Bt(12),Vd:33}];var Ns;function zs(n,t){if(n.getUTCFullYear()!==t.getUTCFullYear())return 70;if(n.getUTCMonth()!==t.getUTCMonth())return 60;if(n.getUTCDate()!==t.getUTCDate())return 50;for(let e=It.length-1;e>=0;--e)if(Math.floor(t.getTime()/It[e].Dd)!==Math.floor(n.getTime()/It[e].Dd))return It[e].Vd;return 0}function ue(n){let t=n;if($t(n)&&(t=Fe(n)),!Me(t))throw new Error("time must be of type BusinessDay");const e=new Date(Date.UTC(t.year,t.month-1,t.day,0,0,0,0));return{Od:Math.round(e.getTime()/1e3),Bd:t}}function js(n){if(!Ci(n))throw new Error("time must be of type isUTCTimestamp");return{Od:n}}function Fe(n){const t=new Date(n);if(isNaN(t.getTime()))throw new Error(`Invalid date string=${n}, expected format=yyyy-mm-dd`);return{day:t.getUTCDate(),month:t.getUTCMonth()+1,year:t.getUTCFullYear()}}function ks(n){$t(n.time)&&(n.time=Fe(n.time))}class Es{options(){return this.cn}setOptions(t){this.cn=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(e){e.forEach(ks)}(t):ks(t)}createConverterToInternalObj(t){return x(function(e){return e.length===0?null:Me(e[0].time)||$t(e[0].time)?ue:js}(t))}key(t){return typeof t=="object"&&"Od"in t?t.Od:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const e=t;return e.Bd===void 0?new Date(1e3*e.Od).getTime():new Date(Date.UTC(e.Bd.year,e.Bd.month-1,e.Bd.day)).getTime()}convertHorzItemToInternal(t){return Ci(e=t)?js(e):Me(e)?ue(e):ue(Fe(e));var e}updateFormatter(t){if(!this.cn)return;const e=t.dateFormat;this.cn.timeScale.timeVisible?this.Ad=new Or({Sd:e,kd:this.cn.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",yd:" ",Cd:t.locale}):this.Ad=new _i(e,t.locale)}formatHorzItem(t){const e=t;return this.Ad.Y_(new Date(1e3*e.Od))}formatTickmark(t,e){const s=function(r,h,o){switch(r){case 0:case 10:return h?o?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return h?3:2;case 50:return 2;case 60:return 1;case 70:return 0}}(t.weight,this.cn.timeScale.timeVisible,this.cn.timeScale.secondsVisible),i=this.cn.timeScale;if(i.tickMarkFormatter!==void 0){const r=i.tickMarkFormatter(t.originalTime,s,e.locale);if(r!==null)return r}return function(r,h,o){const l={};switch(h){case 0:l.year="numeric";break;case 1:l.month="short";break;case 2:l.day="numeric";break;case 3:l.hour12=!1,l.hour="2-digit",l.minute="2-digit";break;case 4:l.hour12=!1,l.hour="2-digit",l.minute="2-digit",l.second="2-digit"}const c=r.Bd===void 0?new Date(1e3*r.Od):new Date(Date.UTC(r.Bd.year,r.Bd.month-1,r.Bd.day));return new Date(c.getUTCFullYear(),c.getUTCMonth(),c.getUTCDate(),c.getUTCHours(),c.getUTCMinutes(),c.getUTCSeconds(),c.getUTCMilliseconds()).toLocaleString(o,l)}(t.time,s,e.locale)}maxTickMarkWeight(t){let e=t.reduce(zr,t[0]).weight;return e>30&&e<50&&(e=30),e}fillWeightsForPoints(t,e){(function(s,i=0){if(s.length===0)return;let r=i===0?null:s[i-1].time.Od,h=r!==null?new Date(1e3*r):null,o=0;for(let l=i;l<s.length;++l){const c=s[l],a=new Date(1e3*c.time.Od);h!==null&&(c.timeWeight=zs(a,h)),o+=c.time.Od-(r||c.time.Od),r=c.time.Od,h=a}if(i===0&&s.length>1){const l=Math.ceil(o/(s.length-1)),c=new Date(1e3*(s[0].time.Od-l));s[0].timeWeight=zs(new Date(1e3*s[0].time.Od),c)}})(t,e)}static Id(t){return K({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}const yt=typeof window<"u";function Ls(){return!!yt&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function de(){return!!yt&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function Ce(n){return n+n%2}function fe(n,t){return n.zd-t.zd}function pe(n,t,e){const s=(n.zd-t.zd)/(n.ot-t.ot);return Math.sign(s)*Math.min(Math.abs(s),e)}class Wr{constructor(t,e,s,i){this.Ld=null,this.Ed=null,this.Nd=null,this.Fd=null,this.Wd=null,this.jd=0,this.Hd=0,this.$d=t,this.Ud=e,this.qd=s,this.rs=i}Yd(t,e){if(this.Ld!==null){if(this.Ld.ot===e)return void(this.Ld.zd=t);if(Math.abs(this.Ld.zd-t)<this.rs)return}this.Fd=this.Nd,this.Nd=this.Ed,this.Ed=this.Ld,this.Ld={ot:e,zd:t}}Vr(t,e){if(this.Ld===null||this.Ed===null||e-this.Ld.ot>50)return;let s=0;const i=pe(this.Ld,this.Ed,this.Ud),r=fe(this.Ld,this.Ed),h=[i],o=[r];if(s+=r,this.Nd!==null){const c=pe(this.Ed,this.Nd,this.Ud);if(Math.sign(c)===Math.sign(i)){const a=fe(this.Ed,this.Nd);if(h.push(c),o.push(a),s+=a,this.Fd!==null){const d=pe(this.Nd,this.Fd,this.Ud);if(Math.sign(d)===Math.sign(i)){const f=fe(this.Nd,this.Fd);h.push(d),o.push(f),s+=f}}}}let l=0;for(let c=0;c<h.length;++c)l+=o[c]/s*h[c];Math.abs(l)<this.$d||(this.Wd={zd:t,ot:e},this.Hd=l,this.jd=function(c,a){const d=Math.log(a);return Math.log(1*d/-c)/d}(Math.abs(l),this.qd))}tc(t){const e=x(this.Wd),s=t-e.ot;return e.zd+this.Hd*(Math.pow(this.qd,s)-1)/Math.log(this.qd)}Qu(t){return this.Wd===null||this.Zd(t)===this.jd}Zd(t){const e=t-x(this.Wd).ot;return Math.min(e,this.jd)}}class Dr{constructor(t,e){this.Xd=void 0,this.Kd=void 0,this.Gd=void 0,this.en=!1,this.Jd=t,this.Qd=e,this.tf()}bt(){this.tf()}if(){this.Xd&&this.Jd.removeChild(this.Xd),this.Kd&&this.Jd.removeChild(this.Kd),this.Xd=void 0,this.Kd=void 0}nf(){return this.en!==this.sf()||this.Gd!==this.ef()}ef(){return hi(jt(this.Qd.W().layout.textColor))>160?"dark":"light"}sf(){return this.Qd.W().layout.attributionLogo}rf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}tf(){this.nf()&&(this.if(),this.en=this.sf(),this.en&&(this.Gd=this.ef(),this.Kd=document.createElement("style"),this.Kd.innerText="a#tv-attr-logo{--fill:#131722;--stroke:#fff;position:absolute;left:10px;bottom:10px;height:19px;width:35px;margin:0;padding:0;border:0;z-index:3;}a#tv-attr-logo[data-dark]{--fill:#D1D4DC;--stroke:#131722;}",this.Xd=document.createElement("a"),this.Xd.href=`https://www.tradingview.com/?utm_medium=lwc-link&utm_campaign=lwc-chart${this.rf()}`,this.Xd.title="Charting by TradingView",this.Xd.id="tv-attr-logo",this.Xd.target="_blank",this.Xd.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35 19" width="35" height="19" fill="none"><g fill-rule="evenodd" clip-path="url(#a)" clip-rule="evenodd"><path fill="var(--stroke)" d="M2 0H0v10h6v9h21.4l.5-1.3 6-15 1-2.7H23.7l-.5 1.3-.2.6a5 5 0 0 0-7-.9V0H2Zm20 17h4l5.2-13 .8-2h-7l-1 2.5-.2.5-1.5 3.8-.3.7V17Zm-.8-10a3 3 0 0 0 .7-2.7A3 3 0 1 0 16.8 7h4.4ZM14 7V2H2v6h6v9h4V7h2Z"/><path fill="var(--fill)" d="M14 2H2v6h6v9h6V2Zm12 15h-7l6-15h7l-6 15Zm-7-9a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/></g><defs><clipPath id="a"><path fill="var(--stroke)" d="M0 0h35v19H0z"/></clipPath></defs></svg>',this.Xd.toggleAttribute("data-dark",this.Gd==="dark"),this.Jd.appendChild(this.Kd),this.Jd.appendChild(this.Xd)))}}function ft(n,t){const e=x(n.ownerDocument).createElement("canvas");n.appendChild(e);const s=Ji(e,{options:{allowResizeObserver:!1},transform:(i,r)=>({width:Math.max(i.width,r.width),height:Math.max(i.height,r.height)})});return s.resizeCanvasElement(t),s}function pt(n){var t;n.width=1,n.height=1,(t=n.getContext("2d"))===null||t===void 0||t.clearRect(0,0,1,1)}function _e(n,t,e,s){n.gl&&n.gl(t,e,s)}function Ut(n,t,e,s){n.X(t,e,s)}function Ne(n,t,e,s){const i=n(e,s);for(const r of i){const h=r.gt();h!==null&&t(h)}}function Br(n){yt&&window.chrome!==void 0&&n.addEventListener("mousedown",t=>{if(t.button===1)return t.preventDefault(),!1})}class Ae{constructor(t,e,s){this.hf=0,this.lf=null,this.af={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY},this._f=0,this.uf=null,this.cf={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY},this.df=null,this.ff=!1,this.vf=null,this.pf=null,this.mf=!1,this.bf=!1,this.wf=!1,this.gf=null,this.Mf=null,this.xf=null,this.Sf=null,this.kf=null,this.yf=null,this.Cf=null,this.Tf=0,this.Pf=!1,this.Rf=!1,this.Df=!1,this.Vf=0,this.Of=null,this.Bf=!de(),this.Af=i=>{this.If(i)},this.zf=i=>{if(this.Lf(i)){const r=this.Ef(i);if(++this._f,this.uf&&this._f>1){const{Nf:h}=this.Ff(q(i),this.cf);h<30&&!this.wf&&this.Wf(r,this.Hf.jf),this.$f()}}else{const r=this.Ef(i);if(++this.hf,this.lf&&this.hf>1){const{Nf:h}=this.Ff(q(i),this.af);h<5&&!this.bf&&this.Uf(r,this.Hf.qf),this.Yf()}}},this.Zf=t,this.Hf=e,this.cn=s,this.Xf()}S(){this.gf!==null&&(this.gf(),this.gf=null),this.Mf!==null&&(this.Mf(),this.Mf=null),this.Sf!==null&&(this.Sf(),this.Sf=null),this.kf!==null&&(this.kf(),this.kf=null),this.yf!==null&&(this.yf(),this.yf=null),this.xf!==null&&(this.xf(),this.xf=null),this.Kf(),this.Yf()}Gf(t){this.Sf&&this.Sf();const e=this.Jf.bind(this);if(this.Sf=()=>{this.Zf.removeEventListener("mousemove",e)},this.Zf.addEventListener("mousemove",e),this.Lf(t))return;const s=this.Ef(t);this.Uf(s,this.Hf.Qf),this.Bf=!0}Yf(){this.lf!==null&&clearTimeout(this.lf),this.hf=0,this.lf=null,this.af={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY}}$f(){this.uf!==null&&clearTimeout(this.uf),this._f=0,this.uf=null,this.cf={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY}}Jf(t){if(this.Df||this.pf!==null||this.Lf(t))return;const e=this.Ef(t);this.Uf(e,this.Hf.tv),this.Bf=!0}iv(t){const e=me(t.changedTouches,x(this.Of));if(e===null||(this.Vf=Ft(t),this.Cf!==null)||this.Rf)return;this.Pf=!0;const s=this.Ff(q(e),x(this.pf)),{nv:i,sv:r,Nf:h}=s;if(this.mf||!(h<5)){if(!this.mf){const o=.5*i,l=r>=o&&!this.cn.ev(),c=o>r&&!this.cn.rv();l||c||(this.Rf=!0),this.mf=!0,this.wf=!0,this.Kf(),this.$f()}if(!this.Rf){const o=this.Ef(t,e);this.Wf(o,this.Hf.hv),vt(t)}}}lv(t){if(t.button!==0)return;const e=this.Ff(q(t),x(this.vf)),{Nf:s}=e;if(s>=5&&(this.bf=!0,this.Yf()),this.bf){const i=this.Ef(t);this.Uf(i,this.Hf.av)}}Ff(t,e){const s=Math.abs(e.nt-t.nt),i=Math.abs(e.st-t.st);return{nv:s,sv:i,Nf:s+i}}ov(t){let e=me(t.changedTouches,x(this.Of));if(e===null&&t.touches.length===0&&(e=t.changedTouches[0]),e===null)return;this.Of=null,this.Vf=Ft(t),this.Kf(),this.pf=null,this.yf&&(this.yf(),this.yf=null);const s=this.Ef(t,e);if(this.Wf(s,this.Hf._v),++this._f,this.uf&&this._f>1){const{Nf:i}=this.Ff(q(e),this.cf);i<30&&!this.wf&&this.Wf(s,this.Hf.jf),this.$f()}else this.wf||(this.Wf(s,this.Hf.uv),this.Hf.uv&&vt(t));this._f===0&&vt(t),t.touches.length===0&&this.ff&&(this.ff=!1,vt(t))}If(t){if(t.button!==0)return;const e=this.Ef(t);if(this.vf=null,this.Df=!1,this.kf&&(this.kf(),this.kf=null),Ls()&&this.Zf.ownerDocument.documentElement.removeEventListener("mouseleave",this.Af),!this.Lf(t))if(this.Uf(e,this.Hf.cv),++this.hf,this.lf&&this.hf>1){const{Nf:s}=this.Ff(q(t),this.af);s<5&&!this.bf&&this.Uf(e,this.Hf.qf),this.Yf()}else this.bf||this.Uf(e,this.Hf.dv)}Kf(){this.df!==null&&(clearTimeout(this.df),this.df=null)}fv(t){if(this.Of!==null)return;const e=t.changedTouches[0];this.Of=e.identifier,this.Vf=Ft(t);const s=this.Zf.ownerDocument.documentElement;this.wf=!1,this.mf=!1,this.Rf=!1,this.pf=q(e),this.yf&&(this.yf(),this.yf=null);{const r=this.iv.bind(this),h=this.ov.bind(this);this.yf=()=>{s.removeEventListener("touchmove",r),s.removeEventListener("touchend",h)},s.addEventListener("touchmove",r,{passive:!1}),s.addEventListener("touchend",h,{passive:!1}),this.Kf(),this.df=setTimeout(this.vv.bind(this,t),240)}const i=this.Ef(t,e);this.Wf(i,this.Hf.pv),this.uf||(this._f=0,this.uf=setTimeout(this.$f.bind(this),500),this.cf=q(e))}mv(t){if(t.button!==0)return;const e=this.Zf.ownerDocument.documentElement;Ls()&&e.addEventListener("mouseleave",this.Af),this.bf=!1,this.vf=q(t),this.kf&&(this.kf(),this.kf=null);{const i=this.lv.bind(this),r=this.If.bind(this);this.kf=()=>{e.removeEventListener("mousemove",i),e.removeEventListener("mouseup",r)},e.addEventListener("mousemove",i),e.addEventListener("mouseup",r)}if(this.Df=!0,this.Lf(t))return;const s=this.Ef(t);this.Uf(s,this.Hf.bv),this.lf||(this.hf=0,this.lf=setTimeout(this.Yf.bind(this),500),this.af=q(t))}Xf(){this.Zf.addEventListener("mouseenter",this.Gf.bind(this)),this.Zf.addEventListener("touchcancel",this.Kf.bind(this));{const t=this.Zf.ownerDocument,e=s=>{this.Hf.wv&&(s.composed&&this.Zf.contains(s.composedPath()[0])||s.target&&this.Zf.contains(s.target)||this.Hf.wv())};this.Mf=()=>{t.removeEventListener("touchstart",e)},this.gf=()=>{t.removeEventListener("mousedown",e)},t.addEventListener("mousedown",e),t.addEventListener("touchstart",e,{passive:!0})}de()&&(this.xf=()=>{this.Zf.removeEventListener("dblclick",this.zf)},this.Zf.addEventListener("dblclick",this.zf)),this.Zf.addEventListener("mouseleave",this.gv.bind(this)),this.Zf.addEventListener("touchstart",this.fv.bind(this),{passive:!0}),Br(this.Zf),this.Zf.addEventListener("mousedown",this.mv.bind(this)),this.Mv(),this.Zf.addEventListener("touchmove",()=>{},{passive:!1})}Mv(){this.Hf.xv===void 0&&this.Hf.Sv===void 0&&this.Hf.kv===void 0||(this.Zf.addEventListener("touchstart",t=>this.yv(t.touches),{passive:!0}),this.Zf.addEventListener("touchmove",t=>{if(t.touches.length===2&&this.Cf!==null&&this.Hf.Sv!==void 0){const e=Ts(t.touches[0],t.touches[1])/this.Tf;this.Hf.Sv(this.Cf,e),vt(t)}},{passive:!1}),this.Zf.addEventListener("touchend",t=>{this.yv(t.touches)}))}yv(t){t.length===1&&(this.Pf=!1),t.length!==2||this.Pf||this.ff?this.Cv():this.Tv(t)}Tv(t){const e=this.Zf.getBoundingClientRect()||{left:0,top:0};this.Cf={nt:(t[0].clientX-e.left+(t[1].clientX-e.left))/2,st:(t[0].clientY-e.top+(t[1].clientY-e.top))/2},this.Tf=Ts(t[0],t[1]),this.Hf.xv!==void 0&&this.Hf.xv(),this.Kf()}Cv(){this.Cf!==null&&(this.Cf=null,this.Hf.kv!==void 0&&this.Hf.kv())}gv(t){if(this.Sf&&this.Sf(),this.Lf(t)||!this.Bf)return;const e=this.Ef(t);this.Uf(e,this.Hf.Pv),this.Bf=!de()}vv(t){const e=me(t.touches,x(this.Of));if(e===null)return;const s=this.Ef(t,e);this.Wf(s,this.Hf.Rv),this.wf=!0,this.ff=!0}Lf(t){return t.sourceCapabilities&&t.sourceCapabilities.firesTouchEvents!==void 0?t.sourceCapabilities.firesTouchEvents:Ft(t)<this.Vf+500}Wf(t,e){e&&e.call(this.Hf,t)}Uf(t,e){e&&e.call(this.Hf,t)}Ef(t,e){const s=e||t,i=this.Zf.getBoundingClientRect()||{left:0,top:0};return{clientX:s.clientX,clientY:s.clientY,pageX:s.pageX,pageY:s.pageY,screenX:s.screenX,screenY:s.screenY,localX:s.clientX-i.left,localY:s.clientY-i.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Dv:!t.type.startsWith("mouse")&&t.type!=="contextmenu"&&t.type!=="click",Vv:t.type,Ov:s.target,Bv:t.view,Av:()=>{t.type!=="touchstart"&&vt(t)}}}}function Ts(n,t){const e=n.clientX-t.clientX,s=n.clientY-t.clientY;return Math.sqrt(e*e+s*s)}function vt(n){n.cancelable&&n.preventDefault()}function q(n){return{nt:n.pageX,st:n.pageY}}function Ft(n){return n.timeStamp||performance.now()}function me(n,t){for(let e=0;e<n.length;++e)if(n[e].identifier===t)return n[e];return null}function At(n){return{Hc:n.Hc,Iv:{gr:n.zv.externalId},Lv:n.zv.cursorStyle}}function Ir(n,t,e){for(const s of n){const i=s.gt();if(i!==null&&i.wr){const r=i.wr(t,e);if(r!==null)return{Bv:s,Iv:r}}}return null}function ve(n,t){return e=>{var s,i,r,h;return((i=(s=e.Dt())===null||s===void 0?void 0:s.Pa())!==null&&i!==void 0?i:"")!==t?[]:(h=(r=e.da)===null||r===void 0?void 0:r.call(e,n))!==null&&h!==void 0?h:[]}}function Ps(n,t,e,s){if(!n.length)return;let i=0;const r=e/2,h=n[0].At(s,!0);let o=t===1?r-(n[0].Vi()-h/2):n[0].Vi()-h/2-r;o=Math.max(0,o);for(let l=1;l<n.length;l++){const c=n[l],a=n[l-1],d=a.At(s,!1),f=c.Vi(),m=a.Vi();if(t===1?f>m-d:f<m+d){const p=m-d*t;c.Oi(p);const v=p-t*d/2;if((t===1?v<0:v>e)&&o>0){const b=t===1?-1-v:v-e,y=Math.min(b,o);for(let w=i;w<n.length;w++)n[w].Oi(n[w].Vi()+t*y);o-=y}}else i=l,o=t===1?m-d-f:f-(m+d)}}class $s{constructor(t,e,s,i){this.Li=null,this.Ev=null,this.Nv=!1,this.Fv=new Lt(200),this.Qr=null,this.Wv=0,this.jv=!1,this.Hv=()=>{this.jv||this.tn.$v().$t().Uh()},this.Uv=()=>{this.jv||this.tn.$v().$t().Uh()},this.tn=t,this.cn=e,this.ko=e.layout,this.Oc=s,this.qv=i==="left",this.Yv=ve("normal",i),this.Zv=ve("top",i),this.Xv=ve("bottom",i),this.Kv=document.createElement("div"),this.Kv.style.height="100%",this.Kv.style.overflow="hidden",this.Kv.style.width="25px",this.Kv.style.left="0",this.Kv.style.position="relative",this.Gv=ft(this.Kv,E({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv);const r=this.Gv.canvasElement;r.style.position="absolute",r.style.zIndex="1",r.style.left="0",r.style.top="0",this.Jv=ft(this.Kv,E({width:16,height:16})),this.Jv.subscribeSuggestedBitmapSizeChanged(this.Uv);const h=this.Jv.canvasElement;h.style.position="absolute",h.style.zIndex="2",h.style.left="0",h.style.top="0";const o={bv:this.Qv.bind(this),pv:this.Qv.bind(this),av:this.tp.bind(this),hv:this.tp.bind(this),wv:this.ip.bind(this),cv:this.np.bind(this),_v:this.np.bind(this),qf:this.sp.bind(this),jf:this.sp.bind(this),Qf:this.ep.bind(this),Pv:this.rp.bind(this)};this.hp=new Ae(this.Jv.canvasElement,o,{ev:()=>!this.cn.handleScroll.vertTouchDrag,rv:()=>!0})}S(){this.hp.S(),this.Jv.unsubscribeSuggestedBitmapSizeChanged(this.Uv),pt(this.Jv.canvasElement),this.Jv.dispose(),this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),pt(this.Gv.canvasElement),this.Gv.dispose(),this.Li!==null&&this.Li.Ko().p(this),this.Li=null}lp(){return this.Kv}P(){return this.ko.fontSize}ap(){const t=this.Oc.W();return this.Qr!==t.R&&(this.Fv.nr(),this.Qr=t.R),t}op(){if(this.Li===null)return 0;let t=0;const e=this.ap(),s=x(this.Gv.canvasElement.getContext("2d"));s.save();const i=this.Li.Ha();s.font=this._p(),i.length>0&&(t=Math.max(this.Fv.xi(s,i[0].so),this.Fv.xi(s,i[i.length-1].so)));const r=this.up();for(let c=r.length;c--;){const a=this.Fv.xi(s,r[c].Kt());a>t&&(t=a)}const h=this.Li.Ct();if(h!==null&&this.Ev!==null&&(o=this.cn.crosshair).mode!==2&&o.horzLine.visible&&o.horzLine.labelVisible){const c=this.Li.pn(1,h),a=this.Li.pn(this.Ev.height-2,h);t=Math.max(t,this.Fv.xi(s,this.Li.Fi(Math.floor(Math.min(c,a))+.11111111111111,h)),this.Fv.xi(s,this.Li.Fi(Math.ceil(Math.max(c,a))-.11111111111111,h)))}var o;s.restore();const l=t||34;return Ce(Math.ceil(e.C+e.T+e.A+e.I+5+l))}cp(t){this.Ev!==null&&at(this.Ev,t)||(this.Ev=t,this.jv=!0,this.Gv.resizeCanvasElement(t),this.Jv.resizeCanvasElement(t),this.jv=!1,this.Kv.style.width=`${t.width}px`,this.Kv.style.height=`${t.height}px`)}dp(){return x(this.Ev).width}Gi(t){this.Li!==t&&(this.Li!==null&&this.Li.Ko().p(this),this.Li=t,t.Ko().l(this.fo.bind(this),this))}Dt(){return this.Li}nr(){const t=this.tn.fp();this.tn.$v().$t().E_(t,x(this.Dt()))}vp(t){if(this.Ev===null)return;if(t!==1){this.pp(),this.Gv.applySuggestedBitmapSize();const s=ut(this.Gv);s!==null&&(s.useBitmapCoordinateSpace(i=>{this.mp(i),this.Ie(i)}),this.tn.bp(s,this.Xv),this.wp(s),this.tn.bp(s,this.Yv),this.gp(s))}this.Jv.applySuggestedBitmapSize();const e=ut(this.Jv);e!==null&&(e.useBitmapCoordinateSpace(({context:s,bitmapSize:i})=>{s.clearRect(0,0,i.width,i.height)}),this.Mp(e),this.tn.bp(e,this.Zv))}xp(){return this.Gv.bitmapSize}Sp(t,e,s){const i=this.xp();i.width>0&&i.height>0&&t.drawImage(this.Gv.canvasElement,e,s)}bt(){var t;(t=this.Li)===null||t===void 0||t.Ha()}Qv(t){if(this.Li===null||this.Li.Ni()||!this.cn.handleScale.axisPressedMouseMove.price)return;const e=this.tn.$v().$t(),s=this.tn.fp();this.Nv=!0,e.V_(s,this.Li,t.localY)}tp(t){if(this.Li===null||!this.cn.handleScale.axisPressedMouseMove.price)return;const e=this.tn.$v().$t(),s=this.tn.fp(),i=this.Li;e.O_(s,i,t.localY)}ip(){if(this.Li===null||!this.cn.handleScale.axisPressedMouseMove.price)return;const t=this.tn.$v().$t(),e=this.tn.fp(),s=this.Li;this.Nv&&(this.Nv=!1,t.B_(e,s))}np(t){if(this.Li===null||!this.cn.handleScale.axisPressedMouseMove.price)return;const e=this.tn.$v().$t(),s=this.tn.fp();this.Nv=!1,e.B_(s,this.Li)}sp(t){this.cn.handleScale.axisDoubleClickReset.price&&this.nr()}ep(t){this.Li!==null&&(!this.tn.$v().$t().W().handleScale.axisPressedMouseMove.price||this.Li.Mh()||this.Li.Oo()||this.kp(1))}rp(t){this.kp(0)}up(){const t=[],e=this.Li===null?void 0:this.Li;return(s=>{for(let i=0;i<s.length;++i){const r=s[i].Rn(this.tn.fp(),e);for(let h=0;h<r.length;h++)t.push(r[h])}})(this.tn.fp().Uo()),t}mp({context:t,bitmapSize:e}){const{width:s,height:i}=e,r=this.tn.fp().$t(),h=r.q(),o=r.bd();h===o?Qt(t,0,0,s,i,h):oi(t,0,0,s,i,h,o)}Ie({context:t,bitmapSize:e,horizontalPixelRatio:s}){if(this.Ev===null||this.Li===null||!this.Li.W().borderVisible)return;t.fillStyle=this.Li.W().borderColor;const i=Math.max(1,Math.floor(this.ap().C*s));let r;r=this.qv?e.width-i:0,t.fillRect(r,0,i,e.height)}wp(t){if(this.Ev===null||this.Li===null)return;const e=this.Li.Ha(),s=this.Li.W(),i=this.ap(),r=this.qv?this.Ev.width-i.T:0;s.borderVisible&&s.ticksVisible&&t.useBitmapCoordinateSpace(({context:h,horizontalPixelRatio:o,verticalPixelRatio:l})=>{h.fillStyle=s.borderColor;const c=Math.max(1,Math.floor(l)),a=Math.floor(.5*l),d=Math.round(i.T*o);h.beginPath();for(const f of e)h.rect(Math.floor(r*o),Math.round(f.Ea*l)-a,d,c);h.fill()}),t.useMediaCoordinateSpace(({context:h})=>{var o;h.font=this._p(),h.fillStyle=(o=s.textColor)!==null&&o!==void 0?o:this.ko.textColor,h.textAlign=this.qv?"right":"left",h.textBaseline="middle";const l=this.qv?Math.round(r-i.A):Math.round(r+i.T+i.A),c=e.map(a=>this.Fv.Mi(h,a.so));for(let a=e.length;a--;){const d=e[a];h.fillText(d.so,l,d.Ea+c[a])}})}pp(){if(this.Ev===null||this.Li===null)return;const t=[],e=this.Li.Uo().slice(),s=this.tn.fp(),i=this.ap();this.Li===s.pr()&&this.tn.fp().Uo().forEach(h=>{s.vr(h)&&e.push(h)});const r=this.Li;e.forEach(h=>{h.Rn(s,r).forEach(o=>{o.Oi(null),o.Bi()&&t.push(o)})}),t.forEach(h=>h.Oi(h.ki())),this.Li.W().alignLabels&&this.yp(t,i)}yp(t,e){if(this.Ev===null)return;const s=this.Ev.height/2,i=t.filter(h=>h.ki()<=s),r=t.filter(h=>h.ki()>s);i.sort((h,o)=>o.ki()-h.ki()),r.sort((h,o)=>h.ki()-o.ki());for(const h of t){const o=Math.floor(h.At(e)/2),l=h.ki();l>-o&&l<o&&h.Oi(o),l>this.Ev.height-o&&l<this.Ev.height+o&&h.Oi(this.Ev.height-o)}Ps(i,1,this.Ev.height,e),Ps(r,-1,this.Ev.height,e)}gp(t){if(this.Ev===null)return;const e=this.up(),s=this.ap(),i=this.qv?"right":"left";e.forEach(r=>{r.Ai()&&r.gt(x(this.Li)).X(t,s,this.Fv,i)})}Mp(t){if(this.Ev===null||this.Li===null)return;const e=this.tn.$v().$t(),s=[],i=this.tn.fp(),r=e.Zc().Rn(i,this.Li);r.length&&s.push(r);const h=this.ap(),o=this.qv?"right":"left";s.forEach(l=>{l.forEach(c=>{c.gt(x(this.Li)).X(t,h,this.Fv,o)})})}kp(t){this.Kv.style.cursor=t===1?"ns-resize":"default"}fo(){const t=this.op();this.Wv<t&&this.tn.$v().$t().Kl(),this.Wv=t}_p(){return wt(this.ko.fontSize,this.ko.fontFamily)}}function Fr(n,t){var e,s;return(s=(e=n.ua)===null||e===void 0?void 0:e.call(n,t))!==null&&s!==void 0?s:[]}function Kt(n,t){var e,s;return(s=(e=n.Pn)===null||e===void 0?void 0:e.call(n,t))!==null&&s!==void 0?s:[]}function Ar(n,t){var e,s;return(s=(e=n.Ji)===null||e===void 0?void 0:e.call(n,t))!==null&&s!==void 0?s:[]}function Kr(n,t){var e,s;return(s=(e=n.aa)===null||e===void 0?void 0:e.call(n,t))!==null&&s!==void 0?s:[]}class Ke{constructor(t,e){this.Ev=E({width:0,height:0}),this.Cp=null,this.Tp=null,this.Pp=null,this.Rp=null,this.Dp=!1,this.Vp=new T,this.Op=new T,this.Bp=0,this.Ap=!1,this.Ip=null,this.zp=!1,this.Lp=null,this.Ep=null,this.jv=!1,this.Hv=()=>{this.jv||this.Np===null||this.$i().Uh()},this.Uv=()=>{this.jv||this.Np===null||this.$i().Uh()},this.Qd=t,this.Np=e,this.Np.W_().l(this.Fp.bind(this),this,!0),this.Wp=document.createElement("td"),this.Wp.style.padding="0",this.Wp.style.position="relative";const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.position="relative",s.style.overflow="hidden",this.jp=document.createElement("td"),this.jp.style.padding="0",this.Hp=document.createElement("td"),this.Hp.style.padding="0",this.Wp.appendChild(s),this.Gv=ft(s,E({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv);const i=this.Gv.canvasElement;i.style.position="absolute",i.style.zIndex="1",i.style.left="0",i.style.top="0",this.Jv=ft(s,E({width:16,height:16})),this.Jv.subscribeSuggestedBitmapSizeChanged(this.Uv);const r=this.Jv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0",this.$p=document.createElement("tr"),this.$p.appendChild(this.jp),this.$p.appendChild(this.Wp),this.$p.appendChild(this.Hp),this.Up(),this.hp=new Ae(this.Jv.canvasElement,this,{ev:()=>this.Ip===null&&!this.Qd.W().handleScroll.vertTouchDrag,rv:()=>this.Ip===null&&!this.Qd.W().handleScroll.horzTouchDrag})}S(){this.Cp!==null&&this.Cp.S(),this.Tp!==null&&this.Tp.S(),this.Pp=null,this.Jv.unsubscribeSuggestedBitmapSizeChanged(this.Uv),pt(this.Jv.canvasElement),this.Jv.dispose(),this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),pt(this.Gv.canvasElement),this.Gv.dispose(),this.Np!==null&&this.Np.W_().p(this),this.hp.S()}fp(){return x(this.Np)}qp(t){var e,s;this.Np!==null&&this.Np.W_().p(this),this.Np=t,this.Np!==null&&this.Np.W_().l(Ke.prototype.Fp.bind(this),this,!0),this.Up(),this.Qd.Yp().indexOf(this)===this.Qd.Yp().length-1?(this.Pp=(e=this.Pp)!==null&&e!==void 0?e:new Dr(this.Wp,this.Qd),this.Pp.bt()):((s=this.Pp)===null||s===void 0||s.if(),this.Pp=null)}$v(){return this.Qd}lp(){return this.$p}Up(){if(this.Np!==null&&(this.Zp(),this.$i().wt().length!==0)){if(this.Cp!==null){const t=this.Np.R_();this.Cp.Gi(x(t))}if(this.Tp!==null){const t=this.Np.D_();this.Tp.Gi(x(t))}}}Xp(){this.Cp!==null&&this.Cp.bt(),this.Tp!==null&&this.Tp.bt()}M_(){return this.Np!==null?this.Np.M_():0}x_(t){this.Np&&this.Np.x_(t)}Qf(t){if(!this.Np)return;this.Kp();const e=t.localX,s=t.localY;this.Gp(e,s,t)}bv(t){this.Kp(),this.Jp(),this.Gp(t.localX,t.localY,t)}tv(t){var e;if(!this.Np)return;this.Kp();const s=t.localX,i=t.localY;this.Gp(s,i,t);const r=this.wr(s,i);this.Qd.Qp((e=r==null?void 0:r.Lv)!==null&&e!==void 0?e:null),this.$i().jc(r&&{Hc:r.Hc,Iv:r.Iv})}dv(t){this.Np!==null&&(this.Kp(),this.tm(t))}qf(t){this.Np!==null&&this.im(this.Op,t)}jf(t){this.qf(t)}av(t){this.Kp(),this.nm(t),this.Gp(t.localX,t.localY,t)}cv(t){this.Np!==null&&(this.Kp(),this.Ap=!1,this.sm(t))}uv(t){this.Np!==null&&this.tm(t)}Rv(t){if(this.Ap=!0,this.Ip===null){const e={x:t.localX,y:t.localY};this.rm(e,e,t)}}Pv(t){this.Np!==null&&(this.Kp(),this.Np.$t().jc(null),this.hm())}lm(){return this.Vp}am(){return this.Op}xv(){this.Bp=1,this.$i().Un()}Sv(t,e){if(!this.Qd.W().handleScale.pinch)return;const s=5*(e-this.Bp);this.Bp=e,this.$i().Qc(t.nt,s)}pv(t){this.Ap=!1,this.zp=this.Ip!==null,this.Jp();const e=this.$i().Zc();this.Ip!==null&&e.yt()&&(this.Lp={x:e.Yt(),y:e.Zt()},this.Ip={x:t.localX,y:t.localY})}hv(t){if(this.Np===null)return;const e=t.localX,s=t.localY;if(this.Ip===null)this.nm(t);else{this.zp=!1;const i=x(this.Lp),r=i.x+(e-this.Ip.x),h=i.y+(s-this.Ip.y);this.Gp(r,h,t)}}_v(t){this.$v().W().trackingMode.exitMode===0&&(this.zp=!0),this.om(),this.sm(t)}wr(t,e){const s=this.Np;return s===null?null:function(i,r,h){const o=i.Uo(),l=function(c,a,d){var f,m;let p,v;for(const w of c){const M=(m=(f=w.va)===null||f===void 0?void 0:f.call(w,a,d))!==null&&m!==void 0?m:[];for(const S of M)b=S.zOrder,(!(y=p==null?void 0:p.zOrder)||b==="top"&&y!=="top"||b==="normal"&&y==="bottom")&&(p=S,v=w)}var b,y;return p&&v?{zv:p,Hc:v}:null}(o,r,h);if((l==null?void 0:l.zv.zOrder)==="top")return At(l);for(const c of o){if(l&&l.Hc===c&&l.zv.zOrder!=="bottom"&&!l.zv.isBackground)return At(l);const a=Ir(c.Pn(i),r,h);if(a!==null)return{Hc:c,Bv:a.Bv,Iv:a.Iv};if(l&&l.Hc===c&&l.zv.zOrder!=="bottom"&&l.zv.isBackground)return At(l)}return l!=null&&l.zv?At(l):null}(s,t,e)}_m(t,e){x(e==="left"?this.Cp:this.Tp).cp(E({width:t,height:this.Ev.height}))}um(){return this.Ev}cp(t){at(this.Ev,t)||(this.Ev=t,this.jv=!0,this.Gv.resizeCanvasElement(t),this.Jv.resizeCanvasElement(t),this.jv=!1,this.Wp.style.width=t.width+"px",this.Wp.style.height=t.height+"px")}dm(){const t=x(this.Np);t.P_(t.R_()),t.P_(t.D_());for(const e of t.Ba())if(t.vr(e)){const s=e.Dt();s!==null&&t.P_(s),e.Vn()}}xp(){return this.Gv.bitmapSize}Sp(t,e,s){const i=this.xp();i.width>0&&i.height>0&&t.drawImage(this.Gv.canvasElement,e,s)}vp(t){if(t===0||this.Np===null)return;if(t>1&&this.dm(),this.Cp!==null&&this.Cp.vp(t),this.Tp!==null&&this.Tp.vp(t),t!==1){this.Gv.applySuggestedBitmapSize();const s=ut(this.Gv);s!==null&&(s.useBitmapCoordinateSpace(i=>{this.mp(i)}),this.Np&&(this.fm(s,Fr),this.vm(s),this.pm(s),this.fm(s,Kt),this.fm(s,Ar)))}this.Jv.applySuggestedBitmapSize();const e=ut(this.Jv);e!==null&&(e.useBitmapCoordinateSpace(({context:s,bitmapSize:i})=>{s.clearRect(0,0,i.width,i.height)}),this.bm(e),this.fm(e,Kr))}wm(){return this.Cp}gm(){return this.Tp}bp(t,e){this.fm(t,e)}Fp(){this.Np!==null&&this.Np.W_().p(this),this.Np=null}tm(t){this.im(this.Vp,t)}im(t,e){const s=e.localX,i=e.localY;t.M()&&t.m(this.$i().St().Nu(s),{x:s,y:i},e)}mp({context:t,bitmapSize:e}){const{width:s,height:i}=e,r=this.$i(),h=r.q(),o=r.bd();h===o?Qt(t,0,0,s,i,o):oi(t,0,0,s,i,h,o)}vm(t){const e=x(this.Np).j_().qh().gt();e!==null&&e.X(t,!1)}pm(t){const e=this.$i().Yc();this.Mm(t,Kt,_e,e),this.Mm(t,Kt,Ut,e)}bm(t){this.Mm(t,Kt,Ut,this.$i().Zc())}fm(t,e){const s=x(this.Np).Uo();for(const i of s)this.Mm(t,e,_e,i);for(const i of s)this.Mm(t,e,Ut,i)}Mm(t,e,s,i){const r=x(this.Np),h=r.$t().Wc(),o=h!==null&&h.Hc===i,l=h!==null&&o&&h.Iv!==void 0?h.Iv.Mr:void 0;Ne(e,c=>s(c,t,o,l),i,r)}Zp(){if(this.Np===null)return;const t=this.Qd,e=this.Np.R_().W().visible,s=this.Np.D_().W().visible;e||this.Cp===null||(this.jp.removeChild(this.Cp.lp()),this.Cp.S(),this.Cp=null),s||this.Tp===null||(this.Hp.removeChild(this.Tp.lp()),this.Tp.S(),this.Tp=null);const i=t.$t().ud();e&&this.Cp===null&&(this.Cp=new $s(this,t.W(),i,"left"),this.jp.appendChild(this.Cp.lp())),s&&this.Tp===null&&(this.Tp=new $s(this,t.W(),i,"right"),this.Hp.appendChild(this.Tp.lp()))}xm(t){return t.Dv&&this.Ap||this.Ip!==null}Sm(t){return Math.max(0,Math.min(t,this.Ev.width-1))}km(t){return Math.max(0,Math.min(t,this.Ev.height-1))}Gp(t,e,s){this.$i().ld(this.Sm(t),this.km(e),s,x(this.Np))}hm(){this.$i().od()}om(){this.zp&&(this.Ip=null,this.hm())}rm(t,e,s){this.Ip=t,this.zp=!1,this.Gp(e.x,e.y,s);const i=this.$i().Zc();this.Lp={x:i.Yt(),y:i.Zt()}}$i(){return this.Qd.$t()}sm(t){if(!this.Dp)return;const e=this.$i(),s=this.fp();if(e.z_(s,s.vn()),this.Rp=null,this.Dp=!1,e.ed(),this.Ep!==null){const i=performance.now(),r=e.St();this.Ep.Vr(r.Hu(),i),this.Ep.Qu(i)||e.Zn(this.Ep)}}Kp(){this.Ip=null}Jp(){if(this.Np){if(this.$i().Un(),document.activeElement!==document.body&&document.activeElement!==document.documentElement)x(document.activeElement).blur();else{const t=document.getSelection();t!==null&&t.removeAllRanges()}!this.Np.vn().Ni()&&this.$i().St().Ni()}}nm(t){if(this.Np===null)return;const e=this.$i(),s=e.St();if(s.Ni())return;const i=this.Qd.W(),r=i.handleScroll,h=i.kineticScroll;if((!r.pressedMouseMove||t.Dv)&&(!r.horzTouchDrag&&!r.vertTouchDrag||!t.Dv))return;const o=this.Np.vn(),l=performance.now();if(this.Rp!==null||this.xm(t)||(this.Rp={x:t.clientX,y:t.clientY,Od:l,ym:t.localX,Cm:t.localY}),this.Rp!==null&&!this.Dp&&(this.Rp.x!==t.clientX||this.Rp.y!==t.clientY)){if(t.Dv&&h.touch||!t.Dv&&h.mouse){const c=s.le();this.Ep=new Wr(.2/c,7/c,.997,15/c),this.Ep.Yd(s.Hu(),this.Rp.Od)}else this.Ep=null;o.Ni()||e.A_(this.Np,o,t.localY),e.nd(t.localX),this.Dp=!0}this.Dp&&(o.Ni()||e.I_(this.Np,o,t.localY),e.sd(t.localX),this.Ep!==null&&this.Ep.Yd(s.Hu(),l))}}class Vs{constructor(t,e,s,i,r){this.ft=!0,this.Ev=E({width:0,height:0}),this.Hv=()=>this.vp(3),this.qv=t==="left",this.Oc=s.ud,this.cn=e,this.Tm=i,this.Pm=r,this.Kv=document.createElement("div"),this.Kv.style.width="25px",this.Kv.style.height="100%",this.Kv.style.overflow="hidden",this.Gv=ft(this.Kv,E({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv)}S(){this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),pt(this.Gv.canvasElement),this.Gv.dispose()}lp(){return this.Kv}um(){return this.Ev}cp(t){at(this.Ev,t)||(this.Ev=t,this.Gv.resizeCanvasElement(t),this.Kv.style.width=`${t.width}px`,this.Kv.style.height=`${t.height}px`,this.ft=!0)}vp(t){if(t<3&&!this.ft||this.Ev.width===0||this.Ev.height===0)return;this.ft=!1,this.Gv.applySuggestedBitmapSize();const e=ut(this.Gv);e!==null&&e.useBitmapCoordinateSpace(s=>{this.mp(s),this.Ie(s)})}xp(){return this.Gv.bitmapSize}Sp(t,e,s){const i=this.xp();i.width>0&&i.height>0&&t.drawImage(this.Gv.canvasElement,e,s)}Ie({context:t,bitmapSize:e,horizontalPixelRatio:s,verticalPixelRatio:i}){if(!this.Tm())return;t.fillStyle=this.cn.timeScale.borderColor;const r=Math.floor(this.Oc.W().C*s),h=Math.floor(this.Oc.W().C*i),o=this.qv?e.width-r:0;t.fillRect(o,0,r,h)}mp({context:t,bitmapSize:e}){Qt(t,0,0,e.width,e.height,this.Pm())}}function Xe(n){return t=>{var e,s;return(s=(e=t.fa)===null||e===void 0?void 0:e.call(t,n))!==null&&s!==void 0?s:[]}}const Xr=Xe("normal"),Hr=Xe("top"),Ur=Xe("bottom");class qr{constructor(t,e){this.Rm=null,this.Dm=null,this.k=null,this.Vm=!1,this.Ev=E({width:0,height:0}),this.Om=new T,this.Fv=new Lt(5),this.jv=!1,this.Hv=()=>{this.jv||this.Qd.$t().Uh()},this.Uv=()=>{this.jv||this.Qd.$t().Uh()},this.Qd=t,this.q_=e,this.cn=t.W().layout,this.Xd=document.createElement("tr"),this.Bm=document.createElement("td"),this.Bm.style.padding="0",this.Am=document.createElement("td"),this.Am.style.padding="0",this.Kv=document.createElement("td"),this.Kv.style.height="25px",this.Kv.style.padding="0",this.Im=document.createElement("div"),this.Im.style.width="100%",this.Im.style.height="100%",this.Im.style.position="relative",this.Im.style.overflow="hidden",this.Kv.appendChild(this.Im),this.Gv=ft(this.Im,E({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv);const s=this.Gv.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.Jv=ft(this.Im,E({width:16,height:16})),this.Jv.subscribeSuggestedBitmapSizeChanged(this.Uv);const i=this.Jv.canvasElement;i.style.position="absolute",i.style.zIndex="2",i.style.left="0",i.style.top="0",this.Xd.appendChild(this.Bm),this.Xd.appendChild(this.Kv),this.Xd.appendChild(this.Am),this.zm(),this.Qd.$t().g_().l(this.zm.bind(this),this),this.hp=new Ae(this.Jv.canvasElement,this,{ev:()=>!0,rv:()=>!this.Qd.W().handleScroll.horzTouchDrag})}S(){this.hp.S(),this.Rm!==null&&this.Rm.S(),this.Dm!==null&&this.Dm.S(),this.Jv.unsubscribeSuggestedBitmapSizeChanged(this.Uv),pt(this.Jv.canvasElement),this.Jv.dispose(),this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),pt(this.Gv.canvasElement),this.Gv.dispose()}lp(){return this.Xd}Lm(){return this.Rm}Em(){return this.Dm}bv(t){if(this.Vm)return;this.Vm=!0;const e=this.Qd.$t();!e.St().Ni()&&this.Qd.W().handleScale.axisPressedMouseMove.time&&e.Jc(t.localX)}pv(t){this.bv(t)}wv(){const t=this.Qd.$t();!t.St().Ni()&&this.Vm&&(this.Vm=!1,this.Qd.W().handleScale.axisPressedMouseMove.time&&t.hd())}av(t){const e=this.Qd.$t();!e.St().Ni()&&this.Qd.W().handleScale.axisPressedMouseMove.time&&e.rd(t.localX)}hv(t){this.av(t)}cv(){this.Vm=!1;const t=this.Qd.$t();t.St().Ni()&&!this.Qd.W().handleScale.axisPressedMouseMove.time||t.hd()}_v(){this.cv()}qf(){this.Qd.W().handleScale.axisDoubleClickReset.time&&this.Qd.$t().Kn()}jf(){this.qf()}Qf(){this.Qd.$t().W().handleScale.axisPressedMouseMove.time&&this.kp(1)}Pv(){this.kp(0)}um(){return this.Ev}Nm(){return this.Om}Fm(t,e,s){at(this.Ev,t)||(this.Ev=t,this.jv=!0,this.Gv.resizeCanvasElement(t),this.Jv.resizeCanvasElement(t),this.jv=!1,this.Kv.style.width=`${t.width}px`,this.Kv.style.height=`${t.height}px`,this.Om.m(t)),this.Rm!==null&&this.Rm.cp(E({width:e,height:t.height})),this.Dm!==null&&this.Dm.cp(E({width:s,height:t.height}))}Wm(){const t=this.jm();return Math.ceil(t.C+t.T+t.P+t.L+t.B+t.Hm)}bt(){this.Qd.$t().St().Ha()}xp(){return this.Gv.bitmapSize}Sp(t,e,s){const i=this.xp();i.width>0&&i.height>0&&t.drawImage(this.Gv.canvasElement,e,s)}vp(t){if(t===0)return;if(t!==1){this.Gv.applySuggestedBitmapSize();const s=ut(this.Gv);s!==null&&(s.useBitmapCoordinateSpace(i=>{this.mp(i),this.Ie(i),this.$m(s,Ur)}),this.wp(s),this.$m(s,Xr)),this.Rm!==null&&this.Rm.vp(t),this.Dm!==null&&this.Dm.vp(t)}this.Jv.applySuggestedBitmapSize();const e=ut(this.Jv);e!==null&&(e.useBitmapCoordinateSpace(({context:s,bitmapSize:i})=>{s.clearRect(0,0,i.width,i.height)}),this.Um([...this.Qd.$t().wt(),this.Qd.$t().Zc()],e),this.$m(e,Hr))}$m(t,e){const s=this.Qd.$t().wt();for(const i of s)Ne(e,r=>_e(r,t,!1,void 0),i,void 0);for(const i of s)Ne(e,r=>Ut(r,t,!1,void 0),i,void 0)}mp({context:t,bitmapSize:e}){Qt(t,0,0,e.width,e.height,this.Qd.$t().bd())}Ie({context:t,bitmapSize:e,verticalPixelRatio:s}){if(this.Qd.W().timeScale.borderVisible){t.fillStyle=this.qm();const i=Math.max(1,Math.floor(this.jm().C*s));t.fillRect(0,0,e.width,i)}}wp(t){const e=this.Qd.$t().St(),s=e.Ha();if(!s||s.length===0)return;const i=this.q_.maxTickMarkWeight(s),r=this.jm(),h=e.W();h.borderVisible&&h.ticksVisible&&t.useBitmapCoordinateSpace(({context:o,horizontalPixelRatio:l,verticalPixelRatio:c})=>{o.strokeStyle=this.qm(),o.fillStyle=this.qm();const a=Math.max(1,Math.floor(l)),d=Math.floor(.5*l);o.beginPath();const f=Math.round(r.T*c);for(let m=s.length;m--;){const p=Math.round(s[m].coord*l);o.rect(p-d,0,a,f)}o.fill()}),t.useMediaCoordinateSpace(({context:o})=>{const l=r.C+r.T+r.L+r.P/2;o.textAlign="center",o.textBaseline="middle",o.fillStyle=this.$(),o.font=this._p();for(const c of s)if(c.weight<i){const a=c.needAlignCoordinate?this.Ym(o,c.coord,c.label):c.coord;o.fillText(c.label,a,l)}this.Qd.W().timeScale.allowBoldLabels&&(o.font=this.Zm());for(const c of s)if(c.weight>=i){const a=c.needAlignCoordinate?this.Ym(o,c.coord,c.label):c.coord;o.fillText(c.label,a,l)}})}Ym(t,e,s){const i=this.Fv.xi(t,s),r=i/2,h=Math.floor(e-r)+.5;return h<0?e+=Math.abs(0-h):h+i>this.Ev.width&&(e-=Math.abs(this.Ev.width-(h+i))),e}Um(t,e){const s=this.jm();for(const i of t)for(const r of i.Qi())r.gt().X(e,s)}qm(){return this.Qd.W().timeScale.borderColor}$(){return this.cn.textColor}j(){return this.cn.fontSize}_p(){return wt(this.j(),this.cn.fontFamily)}Zm(){return wt(this.j(),this.cn.fontFamily,"bold")}jm(){this.k===null&&(this.k={C:1,N:NaN,L:NaN,B:NaN,ji:NaN,T:5,P:NaN,R:"",Wi:new Lt,Hm:0});const t=this.k,e=this._p();if(t.R!==e){const s=this.j();t.P=s,t.R=e,t.L=3*s/12,t.B=3*s/12,t.ji=9*s/12,t.N=0,t.Hm=4*s/12,t.Wi.nr()}return this.k}kp(t){this.Kv.style.cursor=t===1?"ew-resize":"default"}zm(){const t=this.Qd.$t(),e=t.W();e.leftPriceScale.visible||this.Rm===null||(this.Bm.removeChild(this.Rm.lp()),this.Rm.S(),this.Rm=null),e.rightPriceScale.visible||this.Dm===null||(this.Am.removeChild(this.Dm.lp()),this.Dm.S(),this.Dm=null);const s={ud:this.Qd.$t().ud()},i=()=>e.leftPriceScale.borderVisible&&t.St().W().borderVisible,r=()=>t.bd();e.leftPriceScale.visible&&this.Rm===null&&(this.Rm=new Vs("left",e,s,i,r),this.Bm.appendChild(this.Rm.lp())),e.rightPriceScale.visible&&this.Dm===null&&(this.Dm=new Vs("right",e,s,i,r),this.Am.appendChild(this.Dm.lp()))}}const Jr=!!yt&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(n=>n.brand.includes("Chromium"))&&!!yt&&(!((ge=navigator==null?void 0:navigator.userAgentData)===null||ge===void 0)&&ge.platform?navigator.userAgentData.platform==="Windows":navigator.userAgent.toLowerCase().indexOf("win")>=0);var ge;class Gr{constructor(t,e,s){var i;this.Xm=[],this.Km=0,this.ho=0,this.__=0,this.Gm=0,this.Jm=0,this.Qm=null,this.tb=!1,this.Vp=new T,this.Op=new T,this.Rc=new T,this.ib=null,this.nb=null,this.Jd=t,this.cn=e,this.q_=s,this.Xd=document.createElement("div"),this.Xd.classList.add("tv-lightweight-charts"),this.Xd.style.overflow="hidden",this.Xd.style.direction="ltr",this.Xd.style.width="100%",this.Xd.style.height="100%",(i=this.Xd).style.userSelect="none",i.style.webkitUserSelect="none",i.style.msUserSelect="none",i.style.MozUserSelect="none",i.style.webkitTapHighlightColor="transparent",this.sb=document.createElement("table"),this.sb.setAttribute("cellspacing","0"),this.Xd.appendChild(this.sb),this.eb=this.rb.bind(this),be(this.cn)&&this.hb(!0),this.$i=new Pr(this.Vc.bind(this),this.cn,s),this.$t().Xc().l(this.lb.bind(this),this),this.ab=new qr(this,this.q_),this.sb.appendChild(this.ab.lp());const r=e.autoSize&&this.ob();let h=this.cn.width,o=this.cn.height;if(r||h===0||o===0){const l=t.getBoundingClientRect();h=h||l.width,o=o||l.height}this._b(h,o),this.ub(),t.appendChild(this.Xd),this.cb(),this.$i.St().ec().l(this.$i.Kl.bind(this.$i),this),this.$i.g_().l(this.$i.Kl.bind(this.$i),this)}$t(){return this.$i}W(){return this.cn}Yp(){return this.Xm}fb(){return this.ab}S(){this.hb(!1),this.Km!==0&&window.cancelAnimationFrame(this.Km),this.$i.Xc().p(this),this.$i.St().ec().p(this),this.$i.g_().p(this),this.$i.S();for(const t of this.Xm)this.sb.removeChild(t.lp()),t.lm().p(this),t.am().p(this),t.S();this.Xm=[],x(this.ab).S(),this.Xd.parentElement!==null&&this.Xd.parentElement.removeChild(this.Xd),this.Rc.S(),this.Vp.S(),this.Op.S(),this.pb()}_b(t,e,s=!1){if(this.ho===e&&this.__===t)return;const i=function(o){const l=Math.floor(o.width),c=Math.floor(o.height);return E({width:l-l%2,height:c-c%2})}(E({width:t,height:e}));this.ho=i.height,this.__=i.width;const r=this.ho+"px",h=this.__+"px";x(this.Xd).style.height=r,x(this.Xd).style.width=h,this.sb.style.height=r,this.sb.style.width=h,s?this.mb($.es(),performance.now()):this.$i.Kl()}vp(t){t===void 0&&(t=$.es());for(let e=0;e<this.Xm.length;e++)this.Xm[e].vp(t.Hn(e).Fn);this.cn.timeScale.visible&&this.ab.vp(t.jn())}$h(t){const e=be(this.cn);this.$i.$h(t);const s=be(this.cn);s!==e&&this.hb(s),this.cb(),this.bb(t)}lm(){return this.Vp}am(){return this.Op}Xc(){return this.Rc}wb(){this.Qm!==null&&(this.mb(this.Qm,performance.now()),this.Qm=null);const t=this.gb(null),e=document.createElement("canvas");e.width=t.width,e.height=t.height;const s=x(e.getContext("2d"));return this.gb(s),e}Mb(t){return t==="left"&&!this.xb()||t==="right"&&!this.Sb()||this.Xm.length===0?0:x(t==="left"?this.Xm[0].wm():this.Xm[0].gm()).dp()}kb(){return this.cn.autoSize&&this.ib!==null}yb(){return this.Xd}Qp(t){this.nb=t,this.nb?this.yb().style.setProperty("cursor",t):this.yb().style.removeProperty("cursor")}Cb(){return this.nb}Tb(){return O(this.Xm[0]).um()}bb(t){(t.autoSize!==void 0||!this.ib||t.width===void 0&&t.height===void 0)&&(t.autoSize&&!this.ib&&this.ob(),t.autoSize===!1&&this.ib!==null&&this.pb(),t.autoSize||t.width===void 0&&t.height===void 0||this._b(t.width||this.__,t.height||this.ho))}gb(t){let e=0,s=0;const i=this.Xm[0],r=(o,l)=>{let c=0;for(let a=0;a<this.Xm.length;a++){const d=this.Xm[a],f=x(o==="left"?d.wm():d.gm()),m=f.xp();t!==null&&f.Sp(t,l,c),c+=m.height}};this.xb()&&(r("left",0),e+=x(i.wm()).xp().width);for(let o=0;o<this.Xm.length;o++){const l=this.Xm[o],c=l.xp();t!==null&&l.Sp(t,e,s),s+=c.height}e+=i.xp().width,this.Sb()&&(r("right",e),e+=x(i.gm()).xp().width);const h=(o,l,c)=>{x(o==="left"?this.ab.Lm():this.ab.Em()).Sp(x(t),l,c)};if(this.cn.timeScale.visible){const o=this.ab.xp();if(t!==null){let l=0;this.xb()&&(h("left",l,s),l=x(i.wm()).xp().width),this.ab.Sp(t,l,s),l+=o.width,this.Sb()&&h("right",l,s)}s+=o.height}return E({width:e,height:s})}Pb(){let t=0,e=0,s=0;for(const p of this.Xm)this.xb()&&(e=Math.max(e,x(p.wm()).op(),this.cn.leftPriceScale.minimumWidth)),this.Sb()&&(s=Math.max(s,x(p.gm()).op(),this.cn.rightPriceScale.minimumWidth)),t+=p.M_();e=Ce(e),s=Ce(s);const i=this.__,r=this.ho,h=Math.max(i-e-s,0),o=this.cn.timeScale.visible;let l=o?Math.max(this.ab.Wm(),this.cn.timeScale.minimumHeight):0;var c;l=(c=l)+c%2;const a=0+l,d=r<a?0:r-a,f=d/t;let m=0;for(let p=0;p<this.Xm.length;++p){const v=this.Xm[p];v.qp(this.$i.qc()[p]);let b=0,y=0;y=p===this.Xm.length-1?d-m:Math.round(v.M_()*f),b=Math.max(y,2),m+=b,v.cp(E({width:h,height:b})),this.xb()&&v._m(e,"left"),this.Sb()&&v._m(s,"right"),v.fp()&&this.$i.Kc(v.fp(),b)}this.ab.Fm(E({width:o?h:0,height:l}),o?e:0,o?s:0),this.$i.S_(h),this.Gm!==e&&(this.Gm=e),this.Jm!==s&&(this.Jm=s)}hb(t){t?this.Xd.addEventListener("wheel",this.eb,{passive:!1}):this.Xd.removeEventListener("wheel",this.eb)}Rb(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return Jr?1/window.devicePixelRatio:1}rb(t){if(!(t.deltaX!==0&&this.cn.handleScroll.mouseWheel||t.deltaY!==0&&this.cn.handleScale.mouseWheel))return;const e=this.Rb(t),s=e*t.deltaX/100,i=-e*t.deltaY/100;if(t.cancelable&&t.preventDefault(),i!==0&&this.cn.handleScale.mouseWheel){const r=Math.sign(i)*Math.min(1,Math.abs(i)),h=t.clientX-this.Xd.getBoundingClientRect().left;this.$t().Qc(h,r)}s!==0&&this.cn.handleScroll.mouseWheel&&this.$t().td(-80*s)}mb(t,e){var s;const i=t.jn();i===3&&this.Db(),i!==3&&i!==2||(this.Vb(t),this.Ob(t,e),this.ab.bt(),this.Xm.forEach(r=>{r.Xp()}),((s=this.Qm)===null||s===void 0?void 0:s.jn())===3&&(this.Qm.ts(t),this.Db(),this.Vb(this.Qm),this.Ob(this.Qm,e),t=this.Qm,this.Qm=null)),this.vp(t)}Ob(t,e){for(const s of t.Qn())this.ns(s,e)}Vb(t){const e=this.$i.qc();for(let s=0;s<e.length;s++)t.Hn(s).Wn&&e[s].N_()}ns(t,e){const s=this.$i.St();switch(t.qn){case 0:s.hc();break;case 1:s.lc(t.Vt);break;case 2:s.Gn(t.Vt);break;case 3:s.Jn(t.Vt);break;case 4:s.qu();break;case 5:t.Vt.Qu(e)||s.Jn(t.Vt.tc(e))}}Vc(t){this.Qm!==null?this.Qm.ts(t):this.Qm=t,this.tb||(this.tb=!0,this.Km=window.requestAnimationFrame(e=>{if(this.tb=!1,this.Km=0,this.Qm!==null){const s=this.Qm;this.Qm=null,this.mb(s,e);for(const i of s.Qn())if(i.qn===5&&!i.Vt.Qu(e)){this.$t().Zn(i.Vt);break}}}))}Db(){this.ub()}ub(){const t=this.$i.qc(),e=t.length,s=this.Xm.length;for(let i=e;i<s;i++){const r=O(this.Xm.pop());this.sb.removeChild(r.lp()),r.lm().p(this),r.am().p(this),r.S()}for(let i=s;i<e;i++){const r=new Ke(this,t[i]);r.lm().l(this.Bb.bind(this),this),r.am().l(this.Ab.bind(this),this),this.Xm.push(r),this.sb.insertBefore(r.lp(),this.ab.lp())}for(let i=0;i<e;i++){const r=t[i],h=this.Xm[i];h.fp()!==r?h.qp(r):h.Up()}this.cb(),this.Pb()}Ib(t,e,s){var i;const r=new Map;t!==null&&this.$i.wt().forEach(a=>{const d=a.In().ll(t);d!==null&&r.set(a,d)});let h;if(t!==null){const a=(i=this.$i.St().Ui(t))===null||i===void 0?void 0:i.originalTime;a!==void 0&&(h=a)}const o=this.$t().Wc(),l=o!==null&&o.Hc instanceof Ie?o.Hc:void 0,c=o!==null&&o.Iv!==void 0?o.Iv.gr:void 0;return{zb:h,ee:t??void 0,Lb:e??void 0,Eb:l,Nb:r,Fb:c,Wb:s??void 0}}Bb(t,e,s){this.Vp.m(()=>this.Ib(t,e,s))}Ab(t,e,s){this.Op.m(()=>this.Ib(t,e,s))}lb(t,e,s){this.Rc.m(()=>this.Ib(t,e,s))}cb(){const t=this.cn.timeScale.visible?"":"none";this.ab.lp().style.display=t}xb(){return this.Xm[0].fp().R_().W().visible}Sb(){return this.Xm[0].fp().D_().W().visible}ob(){return"ResizeObserver"in window&&(this.ib=new ResizeObserver(t=>{const e=t.find(s=>s.target===this.Jd);e&&this._b(e.contentRect.width,e.contentRect.height)}),this.ib.observe(this.Jd,{box:"border-box"}),!0)}pb(){this.ib!==null&&this.ib.disconnect(),this.ib=null}}function be(n){return!!(n.handleScroll.mouseWheel||n.handleScale.mouseWheel)}function Qr(n){return function(t){return t.open!==void 0}(n)||function(t){return t.value!==void 0}(n)}function Ni(n,t){var e={};for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&t.indexOf(s)<0&&(e[s]=n[s]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function"){var i=0;for(s=Object.getOwnPropertySymbols(n);i<s.length;i++)t.indexOf(s[i])<0&&Object.prototype.propertyIsEnumerable.call(n,s[i])&&(e[s[i]]=n[s[i]])}return e}function Rs(n,t,e,s){const i=e.value,r={ee:t,ot:n,Vt:[i,i,i,i],zb:s};return e.color!==void 0&&(r.V=e.color),r}function Yr(n,t,e,s){const i=e.value,r={ee:t,ot:n,Vt:[i,i,i,i],zb:s};return e.lineColor!==void 0&&(r.lt=e.lineColor),e.topColor!==void 0&&(r.Ps=e.topColor),e.bottomColor!==void 0&&(r.Rs=e.bottomColor),r}function Zr(n,t,e,s){const i=e.value,r={ee:t,ot:n,Vt:[i,i,i,i],zb:s};return e.topLineColor!==void 0&&(r.Re=e.topLineColor),e.bottomLineColor!==void 0&&(r.De=e.bottomLineColor),e.topFillColor1!==void 0&&(r.ke=e.topFillColor1),e.topFillColor2!==void 0&&(r.ye=e.topFillColor2),e.bottomFillColor1!==void 0&&(r.Ce=e.bottomFillColor1),e.bottomFillColor2!==void 0&&(r.Te=e.bottomFillColor2),r}function th(n,t,e,s){const i={ee:t,ot:n,Vt:[e.open,e.high,e.low,e.close],zb:s};return e.color!==void 0&&(i.V=e.color),i}function eh(n,t,e,s){const i={ee:t,ot:n,Vt:[e.open,e.high,e.low,e.close],zb:s};return e.color!==void 0&&(i.V=e.color),e.borderColor!==void 0&&(i.Ot=e.borderColor),e.wickColor!==void 0&&(i.Xh=e.wickColor),i}function sh(n,t,e,s,i){const r=O(i)(e),h=Math.max(...r),o=Math.min(...r),l=r[r.length-1],c=[l,h,o,l],a=e,{time:d,color:f}=a;return{ee:t,ot:n,Vt:c,zb:s,$e:Ni(a,["time","color"]),V:f}}function Xt(n){return n.Vt!==void 0}function Os(n,t){return t.customValues!==void 0&&(n.jb=t.customValues),n}function ct(n){return(t,e,s,i,r,h)=>function(o,l){return l?l(o):(c=o).open===void 0&&c.value===void 0;var c}(s,h)?Os({ot:t,ee:e,zb:i},s):Os(n(t,e,s,i,r),s)}function Ws(n){return{Candlestick:ct(eh),Bar:ct(th),Area:ct(Yr),Baseline:ct(Zr),Histogram:ct(Rs),Line:ct(Rs),Custom:ct(sh)}[n]}function Ds(n){return{ee:0,Hb:new Map,la:n}}function Bs(n,t){if(n!==void 0&&n.length!==0)return{$b:t.key(n[0].ot),Ub:t.key(n[n.length-1].ot)}}function Is(n){let t;return n.forEach(e=>{t===void 0&&(t=e.zb)}),O(t)}class ih{constructor(t){this.qb=new Map,this.Yb=new Map,this.Zb=new Map,this.Xb=[],this.q_=t}S(){this.qb.clear(),this.Yb.clear(),this.Zb.clear(),this.Xb=[]}Kb(t,e){let s=this.qb.size!==0,i=!1;const r=this.Yb.get(t);if(r!==void 0)if(this.Yb.size===1)s=!1,i=!0,this.qb.clear();else for(const l of this.Xb)l.pointData.Hb.delete(t)&&(i=!0);let h=[];if(e.length!==0){const l=e.map(m=>m.time),c=this.q_.createConverterToInternalObj(e),a=Ws(t.Qh()),d=t.Ca(),f=t.Ta();h=e.map((m,p)=>{const v=c(m.time),b=this.q_.key(v);let y=this.qb.get(b);y===void 0&&(y=Ds(v),this.qb.set(b,y),i=!0);const w=a(v,y.ee,m,l[p],d,f);return y.Hb.set(t,w),w})}s&&this.Gb(),this.Jb(t,h);let o=-1;if(i){const l=[];this.qb.forEach(c=>{l.push({timeWeight:0,time:c.la,pointData:c,originalTime:Is(c.Hb)})}),l.sort((c,a)=>this.q_.key(c.time)-this.q_.key(a.time)),o=this.Qb(l)}return this.tw(t,o,function(l,c,a){const d=Bs(l,a),f=Bs(c,a);if(d!==void 0&&f!==void 0)return{ta:d.Ub>=f.Ub&&d.$b>=f.$b}}(this.Yb.get(t),r,this.q_))}vd(t){return this.Kb(t,[])}iw(t,e){const s=e;(function(v){v.zb===void 0&&(v.zb=v.time)})(s),this.q_.preprocessData(e);const i=this.q_.createConverterToInternalObj([e])(e.time),r=this.Zb.get(t);if(r!==void 0&&this.q_.key(i)<this.q_.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${i}`);let h=this.qb.get(this.q_.key(i));const o=h===void 0;h===void 0&&(h=Ds(i),this.qb.set(this.q_.key(i),h));const l=Ws(t.Qh()),c=t.Ca(),a=t.Ta(),d=l(i,h.ee,e,s.zb,c,a);h.Hb.set(t,d),this.nw(t,d);const f={ta:Xt(d)};if(!o)return this.tw(t,-1,f);const m={timeWeight:0,time:h.la,pointData:h,originalTime:Is(h.Hb)},p=Vt(this.Xb,this.q_.key(m.time),(v,b)=>this.q_.key(v.time)<b);this.Xb.splice(p,0,m);for(let v=p;v<this.Xb.length;++v)xe(this.Xb[v].pointData,v);return this.q_.fillWeightsForPoints(this.Xb,p),this.tw(t,p,f)}nw(t,e){let s=this.Yb.get(t);s===void 0&&(s=[],this.Yb.set(t,s));const i=s.length!==0?s[s.length-1]:null;i===null||this.q_.key(e.ot)>this.q_.key(i.ot)?Xt(e)&&s.push(e):Xt(e)?s[s.length-1]=e:s.splice(-1,1),this.Zb.set(t,e.ot)}Jb(t,e){e.length!==0?(this.Yb.set(t,e.filter(Xt)),this.Zb.set(t,e[e.length-1].ot)):(this.Yb.delete(t),this.Zb.delete(t))}Gb(){for(const t of this.Xb)t.pointData.Hb.size===0&&this.qb.delete(this.q_.key(t.time))}Qb(t){let e=-1;for(let s=0;s<this.Xb.length&&s<t.length;++s){const i=this.Xb[s],r=t[s];if(this.q_.key(i.time)!==this.q_.key(r.time)){e=s;break}r.timeWeight=i.timeWeight,xe(r.pointData,s)}if(e===-1&&this.Xb.length!==t.length&&(e=Math.min(this.Xb.length,t.length)),e===-1)return-1;for(let s=e;s<t.length;++s)xe(t[s].pointData,s);return this.q_.fillWeightsForPoints(t,e),this.Xb=t,e}sw(){if(this.Yb.size===0)return null;let t=0;return this.Yb.forEach(e=>{e.length!==0&&(t=Math.max(t,e[e.length-1].ee))}),t}tw(t,e,s){const i={ew:new Map,St:{Eu:this.sw()}};if(e!==-1)this.Yb.forEach((r,h)=>{i.ew.set(h,{$e:r,rw:h===t?s:void 0})}),this.Yb.has(t)||i.ew.set(t,{$e:[],rw:s}),i.St.hw=this.Xb,i.St.lw=e;else{const r=this.Yb.get(t);i.ew.set(t,{$e:r||[],rw:s})}return i}}function xe(n,t){n.ee=t,n.Hb.forEach(e=>{e.ee=t})}function He(n){const t={value:n.Vt[3],time:n.zb};return n.jb!==void 0&&(t.customValues=n.jb),t}function Fs(n){const t=He(n);return n.V!==void 0&&(t.color=n.V),t}function nh(n){const t=He(n);return n.lt!==void 0&&(t.lineColor=n.lt),n.Ps!==void 0&&(t.topColor=n.Ps),n.Rs!==void 0&&(t.bottomColor=n.Rs),t}function rh(n){const t=He(n);return n.Re!==void 0&&(t.topLineColor=n.Re),n.De!==void 0&&(t.bottomLineColor=n.De),n.ke!==void 0&&(t.topFillColor1=n.ke),n.ye!==void 0&&(t.topFillColor2=n.ye),n.Ce!==void 0&&(t.bottomFillColor1=n.Ce),n.Te!==void 0&&(t.bottomFillColor2=n.Te),t}function zi(n){const t={open:n.Vt[0],high:n.Vt[1],low:n.Vt[2],close:n.Vt[3],time:n.zb};return n.jb!==void 0&&(t.customValues=n.jb),t}function hh(n){const t=zi(n);return n.V!==void 0&&(t.color=n.V),t}function oh(n){const t=zi(n),{V:e,Ot:s,Xh:i}=n;return e!==void 0&&(t.color=e),s!==void 0&&(t.borderColor=s),i!==void 0&&(t.wickColor=i),t}function ze(n){return{Area:nh,Line:Fs,Baseline:rh,Histogram:Fs,Bar:hh,Candlestick:oh,Custom:lh}[n]}function lh(n){const t=n.zb;return Object.assign(Object.assign({},n.$e),{time:t})}const ch={vertLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},horzLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},mode:1},ah={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},uh={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:Ve,attributionLogo:!0},we={autoScale:!0,mode:0,invertScale:!1,alignLabels:!0,borderVisible:!0,borderColor:"#2B2B43",entireTextOnly:!1,visible:!1,ticksVisible:!1,scaleMargins:{bottom:.1,top:.2},minimumWidth:0},dh={rightOffset:0,barSpacing:6,minBarSpacing:.5,fixLeftEdge:!1,fixRightEdge:!1,lockVisibleTimeRangeOnResize:!1,rightBarStaysOnScroll:!1,borderVisible:!0,borderColor:"#2B2B43",visible:!0,timeVisible:!1,secondsVisible:!0,shiftVisibleRangeOnNewBar:!0,allowShiftVisibleRangeOnWhitespaceReplacement:!1,ticksVisible:!1,uniformDistribution:!1,minimumHeight:0,allowBoldLabels:!0},fh={color:"rgba(0, 0, 0, 0)",visible:!1,fontSize:48,fontFamily:Ve,fontStyle:"",text:"",horzAlign:"center",vertAlign:"center"};function As(){return{width:0,height:0,autoSize:!1,layout:uh,crosshair:ch,grid:ah,overlayPriceScales:Object.assign({},we),leftPriceScale:Object.assign(Object.assign({},we),{visible:!1}),rightPriceScale:Object.assign(Object.assign({},we),{visible:!0}),timeScale:dh,watermark:fh,localization:{locale:yt?navigator.language:"",dateFormat:"dd MMM 'yy"},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0},handleScale:{axisPressedMouseMove:{time:!0,price:!0},axisDoubleClickReset:{time:!0,price:!0},mouseWheel:!0,pinch:!0},kineticScroll:{mouse:!1,touch:!0},trackingMode:{exitMode:1}}}class ph{constructor(t,e){this.aw=t,this.ow=e}applyOptions(t){this.aw.$t().$c(this.ow,t)}options(){return this.Li().W()}width(){return Zt(this.ow)?this.aw.Mb(this.ow):0}Li(){return x(this.aw.$t().Uc(this.ow)).Dt}}function Ks(n,t,e){const s=Ni(n,["time","originalTime"]),i=Object.assign({time:t},s);return e!==void 0&&(i.originalTime=e),i}const mh={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class vh{constructor(t){this.Nh=t}applyOptions(t){this.Nh.$h(t)}options(){return this.Nh.W()}_w(){return this.Nh}}class gh{constructor(t,e,s,i,r){this.uw=new T,this.Es=t,this.cw=e,this.dw=s,this.q_=r,this.fw=i}S(){this.uw.S()}priceFormatter(){return this.Es.ba()}priceToCoordinate(t){const e=this.Es.Ct();return e===null?null:this.Es.Dt().Rt(t,e.Vt)}coordinateToPrice(t){const e=this.Es.Ct();return e===null?null:this.Es.Dt().pn(t,e.Vt)}barsInLogicalRange(t){if(t===null)return null;const e=new xt(new zt(t.from,t.to)).lu(),s=this.Es.In();if(s.Ni())return null;const i=s.ll(e.Os(),1),r=s.ll(e.ui(),-1),h=x(s.el()),o=x(s.An());if(i!==null&&r!==null&&i.ee>r.ee)return{barsBefore:t.from-h,barsAfter:o-t.to};const l={barsBefore:i===null||i.ee===h?t.from-h:i.ee-h,barsAfter:r===null||r.ee===o?o-t.to:o-r.ee};return i!==null&&r!==null&&(l.from=i.zb,l.to=r.zb),l}setData(t){this.q_,this.Es.Qh(),this.cw.pw(this.Es,t),this.mw("full")}update(t){this.Es.Qh(),this.cw.bw(this.Es,t),this.mw("update")}dataByIndex(t,e){const s=this.Es.In().ll(t,e);return s===null?null:ze(this.seriesType())(s)}data(){const t=ze(this.seriesType());return this.Es.In().ne().map(e=>t(e))}subscribeDataChanged(t){this.uw.l(t)}unsubscribeDataChanged(t){this.uw.v(t)}setMarkers(t){this.q_;const e=t.map(s=>Ks(s,this.q_.convertHorzItemToInternal(s.time),s.time));this.Es.na(e)}markers(){return this.Es.sa().map(t=>Ks(t,t.originalTime,void 0))}applyOptions(t){this.Es.$h(t)}options(){return Y(this.Es.W())}priceScale(){return this.dw.priceScale(this.Es.Dt().Pa())}createPriceLine(t){const e=K(Y(mh),t),s=this.Es.ea(e);return new vh(s)}removePriceLine(t){this.Es.ra(t._w())}seriesType(){return this.Es.Qh()}attachPrimitive(t){this.Es.ka(t),t.attached&&t.attached({chart:this.fw,series:this,requestUpdate:()=>this.Es.$t().Kl()})}detachPrimitive(t){this.Es.ya(t),t.detached&&t.detached()}mw(t){this.uw.M()&&this.uw.m(t)}}class bh{constructor(t,e,s){this.ww=new T,this.mu=new T,this.Om=new T,this.$i=t,this.yl=t.St(),this.ab=e,this.yl.nc().l(this.gw.bind(this)),this.yl.sc().l(this.Mw.bind(this)),this.ab.Nm().l(this.xw.bind(this)),this.q_=s}S(){this.yl.nc().p(this),this.yl.sc().p(this),this.ab.Nm().p(this),this.ww.S(),this.mu.S(),this.Om.S()}scrollPosition(){return this.yl.Hu()}scrollToPosition(t,e){e?this.yl.Ju(t,1e3):this.$i.Jn(t)}scrollToRealTime(){this.yl.Gu()}getVisibleRange(){const t=this.yl.Vu();return t===null?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const e={from:this.q_.convertHorzItemToInternal(t.from),to:this.q_.convertHorzItemToInternal(t.to)},s=this.yl.Iu(e);this.$i.pd(s)}getVisibleLogicalRange(){const t=this.yl.Du();return t===null?null:{from:t.Os(),to:t.ui()}}setVisibleLogicalRange(t){rt(t.from<=t.to,"The from index cannot be after the to index."),this.$i.pd(t)}resetTimeScale(){this.$i.Kn()}fitContent(){this.$i.hc()}logicalToCoordinate(t){const e=this.$i.St();return e.Ni()?null:e.It(t)}coordinateToLogical(t){return this.yl.Ni()?null:this.yl.Nu(t)}timeToCoordinate(t){const e=this.q_.convertHorzItemToInternal(t),s=this.yl.Va(e,!1);return s===null?null:this.yl.It(s)}coordinateToTime(t){const e=this.$i.St(),s=e.Nu(t),i=e.Ui(s);return i===null?null:i.originalTime}width(){return this.ab.um().width}height(){return this.ab.um().height}subscribeVisibleTimeRangeChange(t){this.ww.l(t)}unsubscribeVisibleTimeRangeChange(t){this.ww.v(t)}subscribeVisibleLogicalRangeChange(t){this.mu.l(t)}unsubscribeVisibleLogicalRangeChange(t){this.mu.v(t)}subscribeSizeChange(t){this.Om.l(t)}unsubscribeSizeChange(t){this.Om.v(t)}applyOptions(t){this.yl.$h(t)}options(){return Object.assign(Object.assign({},Y(this.yl.W())),{barSpacing:this.yl.le()})}gw(){this.ww.M()&&this.ww.m(this.getVisibleRange())}Mw(){this.mu.M()&&this.mu.m(this.getVisibleLogicalRange())}xw(t){this.Om.m(t.width,t.height)}}function xh(n){if(n===void 0||n.type==="custom")return;const t=n;t.minMove!==void 0&&t.precision===void 0&&(t.precision=function(e){if(e>=1)return 0;let s=0;for(;s<8;s++){const i=Math.round(e);if(Math.abs(i-e)<1e-8)return s;e*=10}return s}(t.minMove))}function Xs(n){return function(t){if(Rt(t.handleScale)){const s=t.handleScale;t.handleScale={axisDoubleClickReset:{time:s,price:s},axisPressedMouseMove:{time:s,price:s},mouseWheel:s,pinch:s}}else if(t.handleScale!==void 0){const{axisPressedMouseMove:s,axisDoubleClickReset:i}=t.handleScale;Rt(s)&&(t.handleScale.axisPressedMouseMove={time:s,price:s}),Rt(i)&&(t.handleScale.axisDoubleClickReset={time:i,price:i})}const e=t.handleScroll;Rt(e)&&(t.handleScroll={horzTouchDrag:e,vertTouchDrag:e,mouseWheel:e,pressedMouseMove:e})}(n),n}class wh{constructor(t,e,s){this.Sw=new Map,this.kw=new Map,this.yw=new T,this.Cw=new T,this.Tw=new T,this.Pw=new ih(e);const i=s===void 0?Y(As()):K(Y(As()),Xs(s));this.q_=e,this.aw=new Gr(t,i,e),this.aw.lm().l(h=>{this.yw.M()&&this.yw.m(this.Rw(h()))},this),this.aw.am().l(h=>{this.Cw.M()&&this.Cw.m(this.Rw(h()))},this),this.aw.Xc().l(h=>{this.Tw.M()&&this.Tw.m(this.Rw(h()))},this);const r=this.aw.$t();this.Dw=new bh(r,this.aw.fb(),this.q_)}remove(){this.aw.lm().p(this),this.aw.am().p(this),this.aw.Xc().p(this),this.Dw.S(),this.aw.S(),this.Sw.clear(),this.kw.clear(),this.yw.S(),this.Cw.S(),this.Tw.S(),this.Pw.S()}resize(t,e,s){this.autoSizeActive()||this.aw._b(t,e,s)}addCustomSeries(t,e){const s=gt(t),i=Object.assign(Object.assign({},si),s.defaultOptions());return this.Vw("Custom",i,e,s)}addAreaSeries(t){return this.Vw("Area",sn,t)}addBaselineSeries(t){return this.Vw("Baseline",nn,t)}addBarSeries(t){return this.Vw("Bar",tn,t)}addCandlestickSeries(t={}){return function(e){e.borderColor!==void 0&&(e.borderUpColor=e.borderColor,e.borderDownColor=e.borderColor),e.wickColor!==void 0&&(e.wickUpColor=e.wickColor,e.wickDownColor=e.wickColor)}(t),this.Vw("Candlestick",Zi,t)}addHistogramSeries(t){return this.Vw("Histogram",rn,t)}addLineSeries(t){return this.Vw("Line",en,t)}removeSeries(t){const e=O(this.Sw.get(t)),s=this.Pw.vd(e);this.aw.$t().vd(e),this.Ow(s),this.Sw.delete(t),this.kw.delete(e)}pw(t,e){this.Ow(this.Pw.Kb(t,e))}bw(t,e){this.Ow(this.Pw.iw(t,e))}subscribeClick(t){this.yw.l(t)}unsubscribeClick(t){this.yw.v(t)}subscribeCrosshairMove(t){this.Tw.l(t)}unsubscribeCrosshairMove(t){this.Tw.v(t)}subscribeDblClick(t){this.Cw.l(t)}unsubscribeDblClick(t){this.Cw.v(t)}priceScale(t){return new ph(this.aw,t)}timeScale(){return this.Dw}applyOptions(t){this.aw.$h(Xs(t))}options(){return this.aw.W()}takeScreenshot(){return this.aw.wb()}autoSizeActive(){return this.aw.kb()}chartElement(){return this.aw.yb()}paneSize(){const t=this.aw.Tb();return{height:t.height,width:t.width}}setCrosshairPosition(t,e,s){const i=this.Sw.get(s);if(i===void 0)return;const r=this.aw.$t().dr(i);r!==null&&this.aw.$t().ad(t,e,r)}clearCrosshairPosition(){this.aw.$t().od(!0)}Vw(t,e,s={},i){xh(s.priceFormat);const r=K(Y(ii),Y(e),s),h=this.aw.$t().dd(t,r,i),o=new gh(h,this,this,this,this.q_);return this.Sw.set(o,h),this.kw.set(h,o),o}Ow(t){const e=this.aw.$t();e._d(t.St.Eu,t.St.hw,t.St.lw),t.ew.forEach((s,i)=>i.J(s.$e,s.rw)),e.Wu()}Bw(t){return O(this.kw.get(t))}Rw(t){const e=new Map;t.Nb.forEach((i,r)=>{const h=r.Qh(),o=ze(h)(i);if(h!=="Custom")rt(Qr(o));else{const l=r.Ta();rt(!l||l(o)===!1)}e.set(this.Bw(r),o)});const s=t.Eb!==void 0&&this.kw.has(t.Eb)?this.Bw(t.Eb):void 0;return{time:t.zb,logical:t.ee,point:t.Lb,hoveredSeries:s,hoveredObjectId:t.Fb,seriesData:e,sourceEvent:t.Wb}}}function yh(n,t,e){let s;if($t(n)){const r=document.getElementById(n);rt(r!==null,`Cannot find element in DOM with id=${n}`),s=r}else s=n;const i=new wh(s,t,e);return t.setOptions(i.options()),i}function Sh(n,t){return yh(n,new Es,Es.Id(t))}Object.assign(Object.assign({},ii),si);function ji({data:n=[],theme:t="dark",className:e=""}){const s=g.useRef(null),i=g.useRef(null),r=g.useRef(null),h=t==="dark";return g.useEffect(()=>{if(!s.current)return;const o=Sh(s.current,{layout:{background:{type:Se.Solid,color:h?"#0a0e14":"#ffffff"},textColor:h?"#9ca3af":"#374151"},grid:{vertLines:{color:h?"#1f2937":"#e5e7eb"},horzLines:{color:h?"#1f2937":"#e5e7eb"}},crosshair:{mode:0},rightPriceScale:{borderColor:h?"#374151":"#d1d5db"},timeScale:{borderColor:h?"#374151":"#d1d5db",timeVisible:!0}}),l=o.addCandlestickSeries({upColor:"#22c55e",downColor:"#ef4444",borderDownColor:"#ef4444",borderUpColor:"#22c55e",wickDownColor:"#ef4444",wickUpColor:"#22c55e"});i.current=o,r.current=l;const c=new ResizeObserver(a=>{const{width:d,height:f}=a[0].contentRect;o.applyOptions({width:d,height:f})});return c.observe(s.current),()=>{c.disconnect(),o.remove()}},[h]),g.useEffect(()=>{r.current&&n.length>0&&r.current.setData(n)},[n]),u.jsx("div",{ref:s,className:`ct-w-full ct-h-full ct-min-h-[400px] ${e}`})}function ki({chartType:n,symbol:t,theme:e="dark",chartData:s,className:i=""}){return u.jsx("div",{className:`ct-relative ct-w-full ct-h-full ${i}`,children:n==="tradingview"?u.jsx(ei,{symbol:t,theme:e}):u.jsx(ji,{data:s,theme:e})})}const Mh={priceTargets:[{price:"",percentage:""}],targetsEnabled:!1,profitProtection:{enabled:!1,dropPercent:"10",activateAbove:""},stopLoss:{enabled:!1,triggerPrice:""},trailingStop:{enabled:!1,trailPercent:"10"}};function Ch({state:n,onChange:t,className:e=""}){const s=i=>t({...n,...i});return u.jsxs("div",{className:`ct-space-y-3 ${e}`,children:[u.jsx(Ht,{enabled:n.targetsEnabled,onToggle:i=>s({targetsEnabled:i}),icon:"🎯",label:"Price Targets",color:"blue",description:"Set multiple price targets to auto-sell portions",children:u.jsxs("div",{className:"ct-space-y-2",children:[n.priceTargets.map((i,r)=>u.jsxs("div",{className:"ct-flex ct-items-center ct-gap-2",children:[u.jsx("input",{type:"number",value:i.price,placeholder:"Price",onChange:h=>{const o=[...n.priceTargets];o[r]={...o[r],price:h.target.value},s({priceTargets:o})},className:"ct-flex-1 ct-px-2 ct-py-1.5 ct-text-sm ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"}),u.jsx("input",{type:"number",value:i.percentage,placeholder:"%",onChange:h=>{const o=[...n.priceTargets];o[r]={...o[r],percentage:h.target.value},s({priceTargets:o})},className:"ct-w-20 ct-px-2 ct-py-1.5 ct-text-sm ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"}),n.priceTargets.length>1&&u.jsx("button",{onClick:()=>s({priceTargets:n.priceTargets.filter((h,o)=>o!==r)}),className:"ct-text-red-400 hover:ct-text-red-300 ct-text-sm",children:"×"})]},r)),u.jsx("button",{onClick:()=>s({priceTargets:[...n.priceTargets,{price:"",percentage:""}]}),className:"ct-text-xs ct-text-blue-400 hover:ct-text-blue-300",children:"+ Add Target"})]})}),u.jsx(Ht,{enabled:n.profitProtection.enabled,onToggle:i=>s({profitProtection:{...n.profitProtection,enabled:i}}),icon:"🛡️",label:"Profit Protection",color:"green",description:"Auto-sell if price drops from peak",children:u.jsxs("div",{className:"ct-space-y-2",children:[u.jsxs("div",{className:"ct-flex ct-items-center ct-gap-2",children:[u.jsx("input",{type:"number",value:n.profitProtection.dropPercent,placeholder:"Drop %",onChange:i=>s({profitProtection:{...n.profitProtection,dropPercent:i.target.value}}),className:"ct-flex-1 ct-px-2 ct-py-1.5 ct-text-sm ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"}),u.jsx("span",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"% from peak"})]}),u.jsxs("div",{className:"ct-flex ct-items-center ct-gap-2",children:[u.jsx("input",{type:"number",value:n.profitProtection.activateAbove,placeholder:"Activate above",onChange:i=>s({profitProtection:{...n.profitProtection,activateAbove:i.target.value}}),className:"ct-flex-1 ct-px-2 ct-py-1.5 ct-text-sm ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"}),u.jsx("span",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"price"})]})]})}),u.jsx(Ht,{enabled:n.stopLoss.enabled,onToggle:i=>s({stopLoss:{...n.stopLoss,enabled:i}}),icon:"🛑",label:"Stop Loss",color:"red",description:"Auto-sell if price drops below threshold",children:u.jsxs("div",{className:"ct-flex ct-items-center ct-gap-2",children:[u.jsx("input",{type:"number",value:n.stopLoss.triggerPrice,placeholder:"Stop price",onChange:i=>s({stopLoss:{...n.stopLoss,triggerPrice:i.target.value}}),className:"ct-flex-1 ct-px-2 ct-py-1.5 ct-text-sm ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"}),u.jsx("span",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"trigger"})]})}),u.jsx(Ht,{enabled:n.trailingStop.enabled,onToggle:i=>s({trailingStop:{...n.trailingStop,enabled:i}}),icon:"📉",label:"Trailing Stop",color:"orange",description:"Stop-loss that follows price upward",children:u.jsxs("div",{className:"ct-flex ct-items-center ct-gap-2",children:[u.jsx("input",{type:"number",value:n.trailingStop.trailPercent,placeholder:"Trail %",onChange:i=>s({trailingStop:{...n.trailingStop,trailPercent:i.target.value}}),className:"ct-flex-1 ct-px-2 ct-py-1.5 ct-text-sm ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"}),u.jsx("span",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"% below peak"})]})})]})}function Ht({enabled:n,onToggle:t,icon:e,label:s,color:i,description:r,children:h}){const o=n?`ct-border-${i}-500/50`:"ct-border-[hsl(var(--cedros-border))]",l=n?`ct-bg-${i}-500/5`:"";return u.jsxs("div",{className:`ct-border ct-rounded-cedros ct-p-3 ct-cursor-pointer ct-transition-all ${o} ${l}`,onClick:c=>{c.target.closest(".ct-card-body")||t(!n)},children:[u.jsxs("div",{className:"ct-flex ct-items-center ct-gap-2 ct-mb-1",children:[u.jsx("input",{type:"checkbox",checked:n,onChange:c=>{c.stopPropagation(),t(c.target.checked)},className:"ct-w-4 ct-h-4 ct-rounded"}),u.jsx("span",{className:"ct-text-base",children:e}),u.jsx("span",{className:"ct-text-sm ct-font-medium ct-text-[hsl(var(--cedros-foreground))]",children:s})]}),n&&u.jsxs("div",{className:"ct-card-body ct-mt-2 ct-space-y-2",onClick:c=>c.stopPropagation(),children:[u.jsx("p",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:r}),h]})]})}function je({walletAddress:n,inputMint:t,outputMint:e,inputSymbol:s="",outputSymbol:i="",currentPrice:r,onSign:h,onSuccess:o,className:l=""}){const{isLoading:c,error:a,createLimit:d,createStopLoss:f,createTakeProfit:m,createDca:p}=Ys(),v=G(),[b,y]=g.useState("limit"),[w,M]=g.useState("buy"),[S,N]=g.useState(""),[_,k]=g.useState(""),[C,V]=g.useState(100),[P,H]=g.useState("10"),[L,B]=g.useState("86400"),[U,tt]=g.useState("10"),[I,mt]=g.useState(""),[z,A]=g.useState(""),[et,St]=g.useState("10"),[qe,Li]=g.useState("30"),[Ti,Pi]=g.useState(Mh),[$i,ot]=g.useState(null),Vi=[{id:"limit",label:"Limit"},{id:"stop-loss",label:"Stop Loss"},{id:"take-profit",label:"Take Profit"},{id:"trailing-stop",label:"Trailing"},{id:"oco",label:"OCO"},{id:"bracket",label:"Bracket"},{id:"dca",label:"DCA"},{id:"auto",label:"Auto"}],st=w==="buy"?e:t,it=w==="buy"?t:e,Ri=g.useCallback(async()=>{var j,Je,Ge;if(!(!n||!h||!S)){ot(null);try{let Q;const lt=n;if(b==="limit"){if(!_){ot("Enter a price");return}const D=Math.round(parseFloat(S)*Math.pow(10,9)).toString(),Oi=Math.round(parseFloat(S)*parseFloat(_)*Math.pow(10,6)).toString();Q=await d({maker:lt,inputMint:st,outputMint:it,inAmount:D,outAmount:Oi})}else if(b==="stop-loss"){if(!_){ot("Enter a trigger price");return}const R=Math.round(parseFloat(S)*Math.pow(10,9)).toString();Q=await f({maker:lt,inputMint:st,outputMint:it,inAmount:R,triggerPrice:_,slippageBps:C})}else if(b==="take-profit"){if(!_){ot("Enter a trigger price");return}const R=Math.round(parseFloat(S)*Math.pow(10,9)).toString();Q=await m({maker:lt,inputMint:st,outputMint:it,inAmount:R,triggerPrice:_,slippageBps:C})}else if(b==="trailing-stop"){const R=await fetch(`${v.baseUrl}/orders/trailing-stop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({maker:lt,inputMint:st,outputMint:it,inAmount:Math.round(parseFloat(S)*1e9).toString(),trailPercent:parseFloat(U),slippageBps:C,walletId:""})}),D=await R.json();if(!R.ok)throw new Error(((j=D.error)==null?void 0:j.message)??"Failed");o==null||o(D.orderId),N("");return}else if(b==="oco"){if(!I||!z){ot("Enter both stop-loss and take-profit prices");return}const R=await fetch(`${v.baseUrl}/orders/oco`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({maker:lt,inputMint:st,outputMint:it,inAmount:Math.round(parseFloat(S)*1e9).toString(),stopLoss:{triggerPrice:I,slippageBps:C},takeProfit:{triggerPrice:z,slippageBps:50}})}),D=await R.json();if(!R.ok)throw new Error(((Je=D.error)==null?void 0:Je.message)??"Failed");o==null||o(D.ocoId),N("");return}else if(b==="bracket"){const R=await fetch(`${v.baseUrl}/orders/bracket`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({maker:lt,walletId:"",inputMint:st,outputMint:it,inAmount:Math.round(parseFloat(S)*1e9).toString(),stopLossPercent:parseFloat(et),takeProfitPercent:parseFloat(qe),trailingStop:!1})}),D=await R.json();if(!R.ok)throw new Error(((Ge=D.error)==null?void 0:Ge.message)??"Failed");Q={transaction:D.entryTransaction,orderId:D.bracketId}}else{const R=Math.round(parseFloat(S)*Math.pow(10,6)).toString(),D=Math.round(parseFloat(S)/parseInt(P)*Math.pow(10,6)).toString();Q=await p({maker:lt,inputMint:st,outputMint:it,totalInAmount:R,perCycleAmount:D,cycleInterval:parseInt(L)})}await h(Q.transaction),o==null||o(Q.orderId),N(""),k("")}catch(Q){ot(Q.message)}}},[n,h,S,_,b,w,C,st,it,P,L,d,f,m,p,o]);return u.jsxs("div",{className:`ct-bg-[hsl(var(--cedros-background))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded-cedros ct-p-4 ct-space-y-3 ${l}`,children:[u.jsxs("div",{className:"ct-flex ct-gap-1 ct-p-1 ct-bg-[hsl(var(--cedros-muted))] ct-rounded-cedros",children:[u.jsx("button",{onClick:()=>M("buy"),className:`ct-flex-1 ct-py-2 ct-rounded ct-text-sm ct-font-medium ct-transition ${w==="buy"?"ct-bg-green-500 ct-text-white":"ct-text-[hsl(var(--cedros-muted-foreground))]"}`,children:"Buy"}),u.jsx("button",{onClick:()=>M("sell"),className:`ct-flex-1 ct-py-2 ct-rounded ct-text-sm ct-font-medium ct-transition ${w==="sell"?"ct-bg-red-500 ct-text-white":"ct-text-[hsl(var(--cedros-muted-foreground))]"}`,children:"Sell"})]}),u.jsx("div",{className:"ct-flex ct-gap-1 ct-overflow-x-auto",children:Vi.map(j=>u.jsx("button",{onClick:()=>y(j.id),className:`ct-px-3 ct-py-1.5 ct-rounded ct-text-xs ct-font-medium ct-whitespace-nowrap ct-transition ${b===j.id?"ct-bg-[hsl(var(--cedros-primary))] ct-text-[hsl(var(--cedros-primary-foreground))]":"ct-text-[hsl(var(--cedros-muted-foreground))] hover:ct-bg-[hsl(var(--cedros-muted))]"}`,children:j.label},j.id))}),b!=="dca"&&u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:b==="limit"?"Limit Price":"Trigger Price"}),u.jsx("input",{type:"text",value:_,onChange:j=>k(j.target.value),placeholder:r?r.toFixed(2):"0.00",className:"ct-w-full ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] ct-outline-none focus:ct-ring-2 focus:ct-ring-[hsl(var(--cedros-ring))]"})]}),u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Amount"}),u.jsx("input",{type:"text",value:S,onChange:j=>N(j.target.value),placeholder:"0.00",className:"ct-w-full ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] ct-outline-none focus:ct-ring-2 focus:ct-ring-[hsl(var(--cedros-ring))]"}),u.jsx("div",{className:"ct-flex ct-gap-1",children:[25,50,75,100].map(j=>u.jsxs("button",{className:"ct-flex-1 ct-py-1 ct-text-xs ct-rounded ct-bg-[hsl(var(--cedros-muted))] ct-text-[hsl(var(--cedros-muted-foreground))] hover:ct-bg-[hsl(var(--cedros-border))]",children:[j,"%"]},j))})]}),b==="dca"&&u.jsxs("div",{className:"ct-grid ct-grid-cols-2 ct-gap-2",children:[u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Cycles"}),u.jsx("input",{type:"text",value:P,onChange:j=>H(j.target.value),className:"ct-w-full ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"})]}),u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Interval"}),u.jsxs("select",{value:L,onChange:j=>B(j.target.value),className:"ct-w-full ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))]",children:[u.jsx("option",{value:"3600",children:"Hourly"}),u.jsx("option",{value:"86400",children:"Daily"}),u.jsx("option",{value:"604800",children:"Weekly"})]})]})]}),b==="trailing-stop"&&u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Trail Percentage"}),u.jsxs("div",{className:"ct-flex ct-items-center ct-gap-2",children:[u.jsx("input",{type:"number",value:U,onChange:j=>tt(j.target.value),placeholder:"10",className:"ct-flex-1 ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"}),u.jsx("span",{className:"ct-text-sm ct-text-[hsl(var(--cedros-muted-foreground))]",children:"% below peak"})]})]}),b==="oco"&&u.jsxs("div",{className:"ct-grid ct-grid-cols-2 ct-gap-2",children:[u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-red-400",children:"Stop Loss Price"}),u.jsx("input",{type:"number",value:I,onChange:j=>mt(j.target.value),placeholder:"130.00",className:"ct-w-full ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-red-500/30 ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"})]}),u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-green-400",children:"Take Profit Price"}),u.jsx("input",{type:"number",value:z,onChange:j=>A(j.target.value),placeholder:"200.00",className:"ct-w-full ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-green-500/30 ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"})]})]}),b==="bracket"&&u.jsxs("div",{className:"ct-grid ct-grid-cols-2 ct-gap-2",children:[u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-red-400",children:"Stop Loss %"}),u.jsx("input",{type:"number",value:et,onChange:j=>St(j.target.value),placeholder:"10",className:"ct-w-full ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-red-500/30 ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"})]}),u.jsxs("div",{className:"ct-space-y-1",children:[u.jsx("label",{className:"ct-text-xs ct-text-green-400",children:"Take Profit %"}),u.jsx("input",{type:"number",value:qe,onChange:j=>Li(j.target.value),placeholder:"30",className:"ct-w-full ct-px-3 ct-py-2 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-green-500/30 ct-text-[hsl(var(--cedros-foreground))] ct-outline-none"})]})]}),b==="auto"&&u.jsx(Ch,{state:Ti,onChange:Pi}),(b==="stop-loss"||b==="take-profit"||b==="trailing-stop")&&u.jsx($e,{value:C,onChange:V}),u.jsx(Pt,{message:$i||a,onDismiss:()=>ot(null)}),u.jsx("button",{onClick:Ri,disabled:!n||!S||c,className:`ct-w-full ct-py-3 ct-rounded-cedros ct-font-semibold ct-text-white ct-transition disabled:ct-opacity-50 disabled:ct-cursor-not-allowed ${w==="buy"?"ct-bg-green-500 hover:ct-bg-green-600":"ct-bg-red-500 hover:ct-bg-red-600"}`,children:c?u.jsx(ht,{}):`${w==="buy"?"Buy":"Sell"} ${s}`})]})}function _h({marketAddress:n,tickSize:t=.01,maxLevels:e=15,onPriceClick:s,className:i=""}){const{data:r,isLoading:h,isStreaming:o}=Bi(n),l=g.useMemo(()=>{if(!r)return{bids:[],asks:[],maxTotal:1,spread:0};const c=(m,p)=>{const v=new Map;for(const y of m){const w=p?Math.ceil(y.price/t)*t:Math.floor(y.price/t)*t,M=v.get(w);M?(M.size+=y.size,M.total+=y.total):v.set(w,{price:w,size:y.size,total:y.total})}const b=Array.from(v.values());return b.sort((y,w)=>p?y.price-w.price:w.price-y.price),b.slice(0,e)},a=c(r.bids,!1),d=c(r.asks,!0),f=Math.max(...a.map(m=>m.total),...d.map(m=>m.total),1);return{bids:a,asks:d,maxTotal:f,spread:r.spread}},[r,t,e]);return h?u.jsx("div",{className:"ct-flex ct-justify-center ct-py-8",children:u.jsx(ht,{})}):r?u.jsxs("div",{className:`ct-text-sm ${i}`,children:[u.jsxs("div",{className:"ct-flex ct-items-center ct-justify-between ct-px-3 ct-py-1.5 ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:[u.jsx("span",{children:"Orderbook"}),u.jsx("span",{className:o?"ct-text-green-400":"ct-text-yellow-400",children:o?"● Live":"○ Polling"})]}),u.jsxs("div",{className:"ct-grid ct-grid-cols-3 ct-gap-2 ct-px-3 ct-py-1.5 ct-border-b ct-border-[hsl(var(--cedros-border))] ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:[u.jsx("div",{children:"Price"}),u.jsx("div",{className:"ct-text-right",children:"Size"}),u.jsx("div",{className:"ct-text-right",children:"Total"})]}),u.jsx("div",{className:"ct-max-h-48 ct-overflow-y-auto",children:l.asks.slice().reverse().map((c,a)=>u.jsx(Hs,{level:c,side:"ask",maxTotal:l.maxTotal,onClick:()=>s==null?void 0:s(c.price,"buy")},`ask-${a}`))}),u.jsxs("div",{className:"ct-px-3 ct-py-2 ct-bg-[hsl(var(--cedros-muted))] ct-border-y ct-border-[hsl(var(--cedros-border))]",children:[u.jsxs("div",{className:"ct-flex ct-items-center ct-justify-between ct-text-xs",children:[u.jsx("span",{className:"ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Spread"}),u.jsxs("span",{className:"ct-font-medium ct-text-[hsl(var(--cedros-foreground))]",children:[l.spread.toFixed(3),"%"]})]}),r.midPrice>0&&u.jsxs("div",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:["Mid: $",r.midPrice.toFixed(4)]})]}),u.jsx("div",{className:"ct-max-h-48 ct-overflow-y-auto",children:l.bids.map((c,a)=>u.jsx(Hs,{level:c,side:"bid",maxTotal:l.maxTotal,onClick:()=>s==null?void 0:s(c.price,"sell")},`bid-${a}`))})]}):u.jsx("div",{className:"ct-text-center ct-py-8 ct-text-[hsl(var(--cedros-muted-foreground))] ct-text-sm",children:"No orderbook data"})}function Hs({level:n,side:t,maxTotal:e,onClick:s}){const i=t==="ask",r=`${n.total/e*100}%`;return u.jsxs("div",{onClick:s,className:`ct-relative ct-px-3 ct-py-1 ct-cursor-pointer ct-transition-colors ${i?"hover:ct-bg-red-500/10":"hover:ct-bg-green-500/10"}`,children:[u.jsx("div",{className:`ct-absolute ct-inset-y-0 ct-left-0 ${i?"ct-bg-red-500/10":"ct-bg-green-500/10"}`,style:{width:r}}),u.jsxs("div",{className:"ct-relative ct-grid ct-grid-cols-3 ct-gap-2",children:[u.jsx("div",{className:`ct-font-medium ${i?"ct-text-red-400":"ct-text-green-400"}`,children:n.price.toFixed(4)}),u.jsx("div",{className:"ct-text-right ct-text-[hsl(var(--cedros-foreground))]",children:n.size.toFixed(2)}),u.jsxs("div",{className:"ct-text-right ct-text-[hsl(var(--cedros-muted-foreground))]",children:["$",(n.total/1e3).toFixed(1),"K"]})]})]})}function Ei({limitOrders:n,dcaOrders:t,isLoading:e,onCancel:s,className:i=""}){if(e)return u.jsx("div",{className:"ct-flex ct-justify-center ct-py-8",children:u.jsx(ht,{})});const r=n.length===0&&t.length===0;return u.jsxs("div",{className:`ct-space-y-2 ${i}`,children:[r&&u.jsx("div",{className:"ct-text-center ct-py-8 ct-text-[hsl(var(--cedros-muted-foreground))] ct-text-sm",children:"No open orders"}),n.length>0&&u.jsxs("table",{className:"ct-w-full ct-text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))] ct-border-b ct-border-[hsl(var(--cedros-border))]",children:[u.jsx("th",{className:"ct-text-left ct-py-2 ct-px-2",children:"Type"}),u.jsx("th",{className:"ct-text-left ct-py-2",children:"Pair"}),u.jsx("th",{className:"ct-text-right ct-py-2",children:"Amount"}),u.jsx("th",{className:"ct-text-right ct-py-2",children:"Trigger"}),u.jsx("th",{className:"ct-text-right ct-py-2",children:"Status"}),u.jsx("th",{className:"ct-text-right ct-py-2 ct-px-2"})]})}),u.jsx("tbody",{children:n.map(h=>u.jsxs("tr",{className:"ct-border-b ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))]",children:[u.jsx("td",{className:"ct-py-2 ct-px-2",children:u.jsx("span",{className:`ct-px-2 ct-py-0.5 ct-rounded ct-text-xs ct-font-medium ${h.orderType==="stop-loss"?"ct-bg-red-500/10 ct-text-red-400":h.orderType==="take-profit"?"ct-bg-green-500/10 ct-text-green-400":"ct-bg-blue-500/10 ct-text-blue-400"}`,children:h.orderType})}),u.jsxs("td",{className:"ct-py-2 ct-font-mono ct-text-xs",children:[h.inputMint.slice(0,4),"→",h.outputMint.slice(0,4)]}),u.jsx("td",{className:"ct-py-2 ct-text-right",children:h.inAmount}),u.jsx("td",{className:"ct-py-2 ct-text-right",children:h.triggerPrice??"-"}),u.jsx("td",{className:"ct-py-2 ct-text-right",children:h.status}),u.jsx("td",{className:"ct-py-2 ct-px-2 ct-text-right",children:s&&h.status==="open"&&u.jsx("button",{onClick:()=>s(h.orderId),className:"ct-text-xs ct-text-red-400 hover:ct-text-red-300",children:"Cancel"})})]},h.orderId))})]}),t.length>0&&u.jsxs("div",{className:"ct-space-y-2",children:[u.jsx("h4",{className:"ct-text-xs ct-font-medium ct-text-[hsl(var(--cedros-muted-foreground))] ct-px-2",children:"DCA Schedules"}),t.map(h=>u.jsxs("div",{className:"ct-flex ct-items-center ct-justify-between ct-px-2 ct-py-2 ct-rounded ct-bg-[hsl(var(--cedros-muted))]",children:[u.jsxs("div",{children:[u.jsxs("span",{className:"ct-text-sm ct-text-[hsl(var(--cedros-foreground))]",children:[h.completedCycles,"/",h.totalCycles," cycles"]}),u.jsx("span",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))] ct-ml-2",children:h.status})]}),h.nextCycleAt&&u.jsxs("span",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:["Next: ",new Date(h.nextCycleAt).toLocaleDateString()]})]},h.dcaAccountId))]})]})}function Ue({holdings:n,isLoading:t,totalValue:e,className:s=""}){return t?u.jsx("div",{className:"ct-flex ct-justify-center ct-py-8",children:u.jsx(ht,{})}):u.jsxs("div",{className:s,children:[e&&u.jsxs("div",{className:"ct-flex ct-justify-between ct-items-center ct-px-2 ct-py-2 ct-mb-2",children:[u.jsx("span",{className:"ct-text-sm ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Total Value"}),u.jsxs("span",{className:"ct-text-lg ct-font-semibold ct-text-[hsl(var(--cedros-foreground))]",children:["$",e]})]}),n.length===0?u.jsx("div",{className:"ct-text-center ct-py-8 ct-text-[hsl(var(--cedros-muted-foreground))] ct-text-sm",children:"No holdings"}):u.jsxs("table",{className:"ct-w-full ct-text-sm",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))] ct-border-b ct-border-[hsl(var(--cedros-border))]",children:[u.jsx("th",{className:"ct-text-left ct-py-2 ct-px-2",children:"Token"}),u.jsx("th",{className:"ct-text-right ct-py-2",children:"Balance"}),u.jsx("th",{className:"ct-text-right ct-py-2",children:"Price"}),u.jsx("th",{className:"ct-text-right ct-py-2 ct-px-2",children:"Value"})]})}),u.jsx("tbody",{children:n.map(i=>u.jsxs("tr",{className:"ct-border-b ct-border-[hsl(var(--cedros-border))] ct-text-[hsl(var(--cedros-foreground))]",children:[u.jsx("td",{className:"ct-py-2 ct-px-2 ct-font-medium",children:i.symbol??i.mint.slice(0,6)}),u.jsx("td",{className:"ct-py-2 ct-text-right ct-font-mono",children:i.uiBalance}),u.jsx("td",{className:"ct-py-2 ct-text-right",children:i.currentPrice?`$${i.currentPrice}`:"-"}),u.jsx("td",{className:"ct-py-2 ct-px-2 ct-text-right ct-font-medium",children:i.currentValue?`$${i.currentValue}`:"-"})]},i.mint))})]})]})}function Nh({walletAddress:n,inputMint:t="So11111111111111111111111111111111111111112",outputMint:e="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",inputSymbol:s="SOL",outputSymbol:i="USDC",tradingViewSymbol:r="SOLUSD",chartType:h="tradingview",manifestMarket:o,theme:l="dark",onSign:c,onOrderSuccess:a,className:d=""}){const[f,m]=g.useState("positions"),{limitOrders:p,dcaOrders:v,isLoading:b,cancelOrder:y}=Gs(n??null),{positions:w,isLoading:M}=Le(n??null);return u.jsxs("div",{className:`ct-flex ct-flex-col ct-h-full ct-min-h-screen ct-bg-[hsl(var(--cedros-background))] ${d}`,children:[u.jsxs("div",{className:"ct-flex ct-flex-1 ct-min-h-0",children:[u.jsx("div",{className:"ct-flex-1 ct-min-w-0 ct-border-r ct-border-[hsl(var(--cedros-border))]",children:u.jsx(ki,{chartType:h,symbol:r,theme:l})}),u.jsx("div",{className:"ct-hidden xl:ct-block ct-w-80 ct-flex-shrink-0 ct-overflow-y-auto",children:u.jsx(je,{walletAddress:n,inputMint:t,outputMint:e,inputSymbol:s,outputSymbol:i,onSign:c,onSuccess:a})})]}),u.jsxs("div",{className:"ct-border-t ct-border-[hsl(var(--cedros-border))]",children:[u.jsx("div",{className:"ct-flex ct-gap-4 ct-px-4 ct-border-b ct-border-[hsl(var(--cedros-border))]",children:["positions","orders",...o?["orderbook"]:[]].map(S=>u.jsxs("button",{onClick:()=>m(S),className:`ct-py-2 ct-text-sm ct-font-medium ct-border-b-2 ct-transition ct-capitalize ${f===S?"ct-border-[hsl(var(--cedros-primary))] ct-text-[hsl(var(--cedros-foreground))]":"ct-border-transparent ct-text-[hsl(var(--cedros-muted-foreground))] hover:ct-text-[hsl(var(--cedros-foreground))]"}`,children:[S," ",S==="orders"&&p.length>0&&`(${p.length})`]},S))}),u.jsxs("div",{className:"ct-max-h-64 ct-overflow-y-auto",children:[f==="positions"&&u.jsx(Ue,{holdings:(w==null?void 0:w.holdings)??[],isLoading:M,totalValue:w==null?void 0:w.totalValue}),f==="orders"&&u.jsx(Ei,{limitOrders:p,dcaOrders:v,isLoading:b,onCancel:n?S=>y(S,n):void 0}),f==="orderbook"&&o&&u.jsx(_h,{marketAddress:o})]})]}),u.jsx("div",{className:"xl:ct-hidden ct-p-4",children:u.jsx(je,{walletAddress:n,inputMint:t,outputMint:e,inputSymbol:s,outputSymbol:i,onSign:c,onSuccess:a})})]})}function zh({walletAddress:n,className:t=""}){const{positions:e,isLoading:s,error:i,refresh:r}=Le(n??null);return u.jsxs("div",{className:`ct-max-w-2xl ct-mx-auto ct-py-8 ct-px-4 ct-space-y-4 ${t}`,children:[u.jsxs("div",{className:"ct-flex ct-items-center ct-justify-between",children:[u.jsx("h2",{className:"ct-text-xl ct-font-semibold ct-text-[hsl(var(--cedros-foreground))]",children:"Portfolio"}),u.jsx("button",{onClick:r,disabled:s,className:"ct-text-sm ct-text-[hsl(var(--cedros-primary))] hover:ct-underline disabled:ct-opacity-50",children:"Refresh"})]}),n?u.jsxs(u.Fragment,{children:[u.jsx(Pt,{message:i}),e&&u.jsxs("div",{className:"ct-bg-[hsl(var(--cedros-muted))] ct-rounded-cedros ct-p-4 ct-grid ct-grid-cols-2 ct-gap-4",children:[u.jsxs("div",{children:[u.jsx("div",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Total Value"}),u.jsxs("div",{className:"ct-text-2xl ct-font-bold ct-text-[hsl(var(--cedros-foreground))]",children:["$",e.totalValue]})]}),u.jsxs("div",{children:[u.jsx("div",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Open Orders"}),u.jsx("div",{className:"ct-text-2xl ct-font-bold ct-text-[hsl(var(--cedros-foreground))]",children:e.openOrders})]})]}),u.jsx("div",{className:"ct-bg-[hsl(var(--cedros-background))] ct-border ct-border-[hsl(var(--cedros-border))] ct-rounded-cedros",children:u.jsx(Ue,{holdings:(e==null?void 0:e.holdings)??[],isLoading:s})})]}):u.jsx("div",{className:"ct-text-center ct-py-12 ct-text-[hsl(var(--cedros-muted-foreground))]",children:"Connect a wallet to view your portfolio"})]})}function jh({walletAddress:n,onSign:t,className:e=""}){const{actions:s,isLoading:i,complete:r,dismiss:h}=Te(n??null),[o,l]=g.useState(null),c=async(a,d)=>{if(t){l(a);try{const f=await t(d);await r(a,f)}catch{}finally{l(null)}}};return!n||s.length===0?null:u.jsxs("div",{className:`ct-space-y-2 ${e}`,children:[u.jsxs("h4",{className:"ct-text-sm ct-font-medium ct-text-[hsl(var(--cedros-foreground))]",children:["Pending Actions (",s.length,")"]}),s.map(a=>u.jsxs("div",{className:"ct-flex ct-items-center ct-gap-3 ct-p-3 ct-rounded-cedros ct-bg-[hsl(var(--cedros-muted))] ct-border ct-border-[hsl(var(--cedros-border))]",children:[u.jsxs("div",{className:"ct-flex-1 ct-min-w-0",children:[u.jsx("div",{className:"ct-text-sm ct-text-[hsl(var(--cedros-foreground))]",children:a.reason}),u.jsxs("div",{className:"ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))]",children:["Expires ",new Date(a.expiresAt).toLocaleTimeString()]})]}),u.jsxs("div",{className:"ct-flex ct-gap-2",children:[u.jsx("button",{onClick:()=>c(a.id,a.transaction),disabled:o===a.id,className:"ct-px-3 ct-py-1.5 ct-rounded ct-text-xs ct-font-medium ct-bg-[hsl(var(--cedros-primary))] ct-text-[hsl(var(--cedros-primary-foreground))] hover:ct-opacity-90 disabled:ct-opacity-50",children:o===a.id?u.jsx(ht,{className:"ct-h-3 ct-w-3"}):"Sign"}),u.jsx("button",{onClick:()=>h(a.id),className:"ct-px-3 ct-py-1.5 ct-rounded ct-text-xs ct-text-[hsl(var(--cedros-muted-foreground))] hover:ct-text-[hsl(var(--cedros-foreground))]",children:"Dismiss"})]})]},a.id))]})}function kh({walletAddress:n,onClick:t,className:e=""}){const{count:s}=Te(n??null);return s===0?null:u.jsx("button",{onClick:t,className:`ct-relative ct-inline-flex ct-items-center ct-justify-center ct-px-2 ct-py-1 ct-rounded-full ct-text-xs ct-font-medium ct-bg-red-500 ct-text-white ct-animate-pulse ${e}`,children:s})}exports.TradeApiClient=ke.TradeApiClient;exports.TradeApiError=ke.TradeApiError;exports.ActionNotificationBadge=kh;exports.ActionQueue=jh;exports.CedrosTradeProvider=Wi;exports.ChartContainer=ki;exports.ErrorMessage=Pt;exports.LightweightChart=ji;exports.LoadingSpinner=ht;exports.OpenOrdersTable=Ei;exports.OrderForm=je;exports.PortfolioPage=zh;exports.PositionsTable=Ue;exports.SlippageControl=$e;exports.SwapForm=Zs;exports.SwapPage=Ai;exports.TokenSelector=Pe;exports.TradingPage=Nh;exports.TradingViewChart=ei;exports.TransferForm=ti;exports.TransferPage=Xi;exports.useActionQueue=Te;exports.useLimitOrder=Ys;exports.useOpenOrders=Gs;exports.usePositions=Le;exports.usePrices=Di;exports.useSwap=qs;exports.useTokens=Qs;exports.useTradeApi=G;exports.useTradeContext=Ee;exports.useTransfer=Js;