@eaera-com/eaera-widgets-v2 0.1.65 → 0.1.66

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.
Files changed (57) hide show
  1. package/dist/THIRD-PARTY-NOTICES.md +390 -0
  2. package/dist/components/base/EaeraCarousel.mjs +1 -1
  3. package/dist/components/base/EaeraColorPicker.mjs +1 -1
  4. package/dist/components/base/EaeraSelectStatus.mjs +1 -1
  5. package/dist/components/base/EaeraSelectTag.mjs +1 -1
  6. package/dist/components/base/EaeraSlider.mjs +1 -1
  7. package/dist/components/base/EaeraTag.mjs +1 -1
  8. package/dist/components/chunks/{EaeraCarousel-BHSnSMBE.mjs → EaeraCarousel-BV02zb3u.mjs} +1 -1
  9. package/dist/components/chunks/{EaeraColorPicker-Cu_7WUyZ.mjs → EaeraColorPicker-BmBd0tPb.mjs} +1 -1
  10. package/dist/components/chunks/{EaeraCountryField-CZAxI23f.mjs → EaeraCountryField-CkYycI_a.mjs} +1 -1
  11. package/dist/components/chunks/{EaeraCountryFlag-BAHKigTb.mjs → EaeraCountryFlag-HdsCS-D7.mjs} +1 -1
  12. package/dist/components/chunks/{EaeraCurrencyIcon-CST3GPwg.mjs → EaeraCurrencyIcon-DCPxMDbT.mjs} +1 -1
  13. package/dist/components/chunks/{EaeraDynamicFieldRow-D6QQT5VJ.mjs → EaeraDynamicFieldRow-D3daws_R.mjs} +1 -1
  14. package/dist/components/chunks/{EaeraForm-C15vj2MY.mjs → EaeraForm-Dd5gzQ_5.mjs} +1 -1
  15. package/dist/components/chunks/{EaeraInputPhone-BaEpDpqm.mjs → EaeraInputPhone-BAfQ9DpC.mjs} +1 -1
  16. package/dist/components/chunks/{EaeraInputPhoneNumber-D8PD5mYd.mjs → EaeraInputPhoneNumber-CDZnyaLx.mjs} +1 -1
  17. package/dist/components/chunks/{EaeraSelectStatus-DzcWR8fd.mjs → EaeraSelectStatus-3bhsZt3A.mjs} +1 -1
  18. package/dist/components/chunks/{EaeraSelectTag-Cx9m6w-B.mjs → EaeraSelectTag-CGmqeNQJ.mjs} +1 -1
  19. package/dist/components/chunks/{EaeraSlider-Chaf-1YV.mjs → EaeraSlider-Bk51h1zv.mjs} +1 -1
  20. package/dist/components/chunks/{EaeraTableV2-BqxbiWNA.mjs → EaeraTableV2-BF5WVwr0.mjs} +1 -1
  21. package/dist/components/chunks/{EaeraTag-DOpHFhCO.mjs → EaeraTag-BgmzVuUW.mjs} +1 -1
  22. package/dist/components/chunks/{EaeraWidgetMarginCalculator-DTBQyb0O.mjs → EaeraWidgetMarginCalculator-D5S9uiyJ.mjs} +1 -1
  23. package/dist/components/chunks/{EaeraWidgetPositionCalculator-BSzwEN-M.mjs → EaeraWidgetPositionCalculator-C_Sdli_O.mjs} +1 -1
  24. package/dist/components/chunks/btc-6HS1P1ks.mjs +1 -0
  25. package/dist/components/chunks/{iconSvg-DTZkgsHi.mjs → iconSvg-BrZD7vO3.mjs} +1 -1
  26. package/dist/components/chunks/{index-Dy15Ym4c.mjs → index-C-vkb_jO.mjs} +1 -1
  27. package/dist/components/chunks/{index-DoROFnbZ.mjs → index-CqpcR_2l.mjs} +1 -1
  28. package/dist/components/chunks/{index-BEl5qk1J.mjs → index-CrK9v14t.mjs} +1 -1
  29. package/dist/components/chunks/{index-Ppl4vfEn.mjs → index-DBt7OBMQ.mjs} +1 -1
  30. package/dist/components/chunks/{index-D5VmN8v6.mjs → index-DaBf9nij.mjs} +1 -1
  31. package/dist/components/chunks/{index-hCcBQcsv.mjs → index-YzHmypKi.mjs} +1 -1
  32. package/dist/components/chunks/{index-CB28j-nX.mjs → index-f7_iVTcy.mjs} +1 -1
  33. package/dist/components/chunks/{index-DtugTV-F.mjs → index-iEvfkNT8.mjs} +1 -1
  34. package/dist/components/composite/EaeraDynamicFieldRow.mjs +1 -1
  35. package/dist/components/composite/EaeraForm.mjs +1 -1
  36. package/dist/components/composite/EaeraTableV2.mjs +1 -1
  37. package/dist/components/custom/EaeraCountryField.mjs +1 -1
  38. package/dist/components/custom/EaeraCountryFlag.mjs +1 -1
  39. package/dist/components/custom/EaeraCurrencyIcon.mjs +1 -1
  40. package/dist/components/custom/EaeraInputPhone.mjs +1 -1
  41. package/dist/components/custom/EaeraInputPhoneNumber.mjs +1 -1
  42. package/dist/components/custom/EaeraWidgetMarginCalculator.mjs +1 -1
  43. package/dist/components/custom/EaeraWidgetPositionCalculator.mjs +1 -1
  44. package/dist/components/index.mjs +1 -1
  45. package/dist/components/utils/symbolBadge.mjs +1 -1
  46. package/dist/components/webtrade/EaeraCfdWatchlist.mjs +1 -1
  47. package/dist/components/webtrade/EaeraDrawingOverlay.mjs +1 -1
  48. package/dist/components/webtrade/EaeraLightweightChart.mjs +1 -1
  49. package/dist/components/webtrade/EaeraOrderlineOverlay.mjs +1 -1
  50. package/dist/components/webtrade/EaeraSymbolSpec.mjs +1 -1
  51. package/dist/components/webtrade/EaeraTimeNSales.mjs +1 -1
  52. package/dist/components/webtrade/EaeraTradingTable.mjs +1 -1
  53. package/dist/components/webtrade/EaeraWatchlist.mjs +1 -1
  54. package/dist/eaera-widgets-v2.es.js +5 -10
  55. package/dist/eaera-widgets-v2.umd.cjs +1 -1
  56. package/package.json +1 -1
  57. package/dist/components/chunks/btc-C0ACyBQO.mjs +0 -1
@@ -1 +1 @@
1
- import{ref as e,watch as t,computed as i,provide as s,inject as r,defineComponent as o,nextTick as n,onUnmounted as a,openBlock as l,createElementBlock as c,normalizeClass as d,unref as u,createElementVNode as p,Fragment as w,renderList as m,createVNode as g,withCtx as v,createBlock as D,resolveDynamicComponent as b,mergeProps as P,createCommentVNode as x,withModifiers as y,normalizeStyle as f,toDisplayString as _,toRef as S,isRef as C,Teleport as T}from"vue";import k from"../composite/EaeraDropdownV2.mjs";import{_ as M}from"./EaeraDivider-Dggvc36a.mjs";import{_ as A}from"./EaeraTooltip-BIlULHv4.mjs";import{Plus as L,Ruler as V,PenTool as E,Type as O,Lock as R,LockOpen as U,Eye as B,EyeOff as F,Trash as N,GripVertical as z,PenLine as W}from"@lucide/vue";import{useI18n as I}from"vue-i18n";import"element-plus";import"element-plus/es";import"./vendor-email-misspelled-0hsXkSSK.mjs";import"./vendor-unorm-Degftfa1.mjs";import"./useEaeraInputPhoneNumber-B72aLnQs.mjs";import"@element-plus/icons-vue";import{_ as q}from"./EaeraColorPicker-Cu_7WUyZ.mjs";import"echarts/core";import"echarts/renderers";import"echarts/charts";import"echarts/components";import"vue-echarts";import"./vendor-currency-symbol-map-C-1fEG2R.mjs";import"./vendor-sortablejs-D3DyHO5Y.mjs";import{c as $}from"./vendor-es-toolkit-D-WXci__.mjs";import{i as j}from"./vendor-lodash-es-DUTj3yNB.mjs";const K={Brush:"brush",Line:"line",Text:"text",OrderLine:"order-line",None:"none"},H=Symbol("EAERA_DRAWING_OVERLAY_CONTEXT_KEY"),Y=(r,o)=>{const n=e(r.drawMode??K.None),a=e(r.lockAllDraw??!1),l=e(r.drawVisible??!0),c=e(r.selectedDrawMode??null),d=e(r.selectedDrawOptions);t(()=>r.drawMode,e=>{void 0!==e&&(n.value=e)}),t(()=>r.lockAllDraw,e=>{"boolean"==typeof e&&(a.value=e)}),t(()=>r.drawVisible,e=>{"boolean"==typeof e&&(l.value=e)}),t(()=>r.selectedDrawMode,e=>{void 0!==e&&(c.value=e)}),t(()=>r.selectedDrawOptions,e=>{d.value=e});const u=i(()=>({drawMode:n.value,lockAllDraw:a.value,drawVisible:l.value,selectedDrawMode:c.value,selectedDrawOptions:d.value}));t(u,e=>{o("stateChange",e)},{immediate:!0});const p={drawMode:i(()=>n.value),lockAllDraw:i(()=>a.value),drawVisible:i(()=>l.value),selectedDrawMode:i(()=>c.value),selectedDrawOptions:i(()=>d.value),showFloatingToolbar:i(()=>r.showFloatingToolbar??!0),showSidebar:i(()=>r.showSidebar??!0),drawingTools:i(()=>r.drawingTools??{}),state:u,onSetDrawMode:e=>{n.value=e,r.runtime?.setDrawMode&&r.runtime.setDrawMode(e),o("setDrawMode",e)},onToggleLockAll:e=>{a.value=e,r.runtime?.setLockAllDraw&&r.runtime.setLockAllDraw(e),o("toggleLockAll",e)},onToggleVisible:e=>{l.value=e,r.runtime?.setDrawVisible&&r.runtime.setDrawVisible(e),o("toggleVisible",e)},onDeleteAllDrawings:()=>{r.runtime?.deleteAllDrawings?.(),o("deleteAllDrawings")},onUpdateSelectedDrawOptions:(e,t=c.value)=>{c.value=t,d.value=e,r.runtime?.setSelectedDrawOptions?r.runtime.setSelectedDrawOptions(e,t):!r.runtime?.clearSelectedDrawing||e&&null!==t||r.runtime.clearSelectedDrawing(),o("updateSelectedDrawOptions",e,t)},onToggleSelectedLocked:()=>{const e=d.value;if(!e)return;const t={...e,locked:!e.locked};d.value=t,r.runtime?.setSelectedDrawOptions&&r.runtime.setSelectedDrawOptions(t,c.value),o("toggleSelectedLocked",t,c.value)},onDeleteSelectedDrawing:()=>{r.runtime?.clearSelectedDrawing?.(),o("deleteSelectedDrawing")}};return s(H,p),p},X=()=>{const e=r(H);if(!e)throw new Error("useEaeraDrawingOverlay must be used inside EaeraDrawingOverlayPanel");return e},Z={key:0,class:"custom-drawing-overlay__sidebar"},G={class:"custom-drawing-overlay__tools"},J=["onClick"],Q=["onClick"],ee={key:0,class:"custom-drawing-overlay__stroke-width"},te={class:"custom-drawing-overlay__stroke-width-trigger"},ie={class:"custom-drawing-overlay__stroke-width-value"},se={class:"custom-drawing-overlay__stroke-width-dropdown"},re=["onClick"],oe={class:"custom-drawing-overlay__stroke-width-option-label"},ne=o({__name:"EaeraDrawingOverlayPanel",props:{drawMode:{},lockAllDraw:{type:Boolean},drawVisible:{type:Boolean},selectedDrawMode:{},selectedDrawOptions:{},showFloatingToolbar:{type:Boolean},showSidebar:{type:Boolean},drawingTools:{},runtime:{}},emits:["setDrawMode","toggleLockAll","toggleVisible","deleteAllDrawings","updateSelectedDrawOptions","toggleSelectedLocked","deleteSelectedDrawing","stateChange"],setup(s,{expose:r,emit:o}){const S=Y(s,o),{drawMode:C,lockAllDraw:T,drawVisible:$,selectedDrawMode:j,selectedDrawOptions:H,showFloatingToolbar:X,showSidebar:ne,drawingTools:ae,state:le,onSetDrawMode:he,onToggleLockAll:ce,onToggleVisible:de,onDeleteAllDrawings:ue,onUpdateSelectedDrawOptions:pe,onToggleSelectedLocked:we,onDeleteSelectedDrawing:me}=S,{t:ge}=I(),ve=[1,2,3,4,8],De=[K.Line,K.Brush,K.Text],be=i(()=>ve.map(e=>({value:e,label:`${e}px`}))),Pe=i(()=>H.value?.strokeWidth??null),xe=e=>e===K.Line?ae.value.line:e===K.Brush?ae.value.brush:e===K.Text?ae.value.text:void 0,ye=()=>De.map(e=>xe(e)).filter(e=>!!e),fe=e(),_e=e("#3b82f6"),Se=e(!1),Ce=i(()=>({tools:[{icon:{component:L,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.crosshair"),value:K.None},{icon:{component:V,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.line-tool"),value:K.Line},{icon:{component:E,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.brush-tool"),value:K.Brush},{icon:{component:O,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.text-tool"),value:K.Text}],modifier:[{icon:T.value?{component:R,props:{size:16,absoluteStrokeWidth:!0}}:{component:U,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.lock-drawings"),value:"lock"},{icon:$.value?{component:B,props:{size:16,absoluteStrokeWidth:!0}}:{component:F,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.hide-drawings"),value:"hide"}]})),Te=e=>"lock"===e?T.value:"hide"===e&&!$.value,ke=i(()=>j.value===K.Text&&!!H.value),Me=i(()=>j.value!==K.Text&&!!H.value?.strokeColor),Ae=i(()=>j.value===K.Line||j.value===K.Brush),Le=i(()=>!!H.value?.locked||T.value),Ve=i(()=>Me.value?H.value?.strokeColor:ke.value?H.value?.textColor:"#3b82f6"),Ee=e=>{pe(e,j.value),e&&ye().forEach(t=>{t.isAnyDrawSelected()&&t.updateSelectedOptions(e)})},Oe=e=>{const t=e||"#3b82f6";_e.value=t,(e=>{H.value&&(ke.value?Ee({...H.value,textColor:e}):Ee({...H.value,strokeColor:e}))})(t),Se.value=!1,fe.value?.hide()},Re=()=>{_e.value=Ve.value||"#3b82f6",Se.value?fe.value?.hide():fe.value?.show(),Se.value=!Se.value},Ue=()=>{T.value||(ye().forEach(e=>{e.isAnyDrawSelected()&&e.toggleSelectedDrawLocked()}),we())},Be=async()=>{const e=ye().map(e=>e.removeSelectedDraw());e.length>0&&await Promise.allSettled(e),pe(void 0,null),me()},Fe=e({x:0,y:60}),Ne=e({x:0,y:0}),ze=e(!1),We=e(!1),Ie=e(null),qe=e=>{Fe.value=e},$e=e=>{if(!Ie.value||0!==e.button)return;e.stopPropagation(),e.preventDefault();const t=Ie.value.getBoundingClientRect();Ne.value={x:e.clientX-t.left,y:e.clientY-t.top},ze.value=!0},je=e=>{if(!Ie.value)return;const t=e.touches[0];if(!t)return;const i=Ie.value.getBoundingClientRect();Ne.value={x:t.clientX-i.left,y:t.clientY-i.top},ze.value=!0,e.stopPropagation(),e.preventDefault()},Ke=e=>{if(!ze.value||!Ie.value)return;const t=Ie.value.parentElement;if(!t)return;const i=t.getBoundingClientRect(),s=Ie.value.getBoundingClientRect();let r=e.clientX-i.left-Ne.value.x,o=e.clientY-i.top-Ne.value.y;const n=i.width-s.width,a=i.height-s.height;r=Math.max(0,Math.min(r,n)),o=Math.max(0,Math.min(o,a)),qe({x:r,y:o})},He=e=>{if(!ze.value||!Ie.value)return;const t=e.touches[0];if(!t)return;const i=Ie.value.parentElement;if(!i)return;const s=i.getBoundingClientRect(),r=Ie.value.getBoundingClientRect();let o=t.clientX-s.left-Ne.value.x,n=t.clientY-s.top-Ne.value.y;e.preventDefault();const a=s.width-r.width,l=s.height-r.height;o=Math.max(0,Math.min(o,a)),n=Math.max(0,Math.min(n,l)),qe({x:o,y:n})},Ye=()=>{ze.value=!1},Xe=()=>{document.removeEventListener("mousemove",Ke),document.removeEventListener("mouseup",Ye,!0),document.removeEventListener("touchmove",He),document.removeEventListener("touchend",Ye,!0),document.removeEventListener("touchcancel",Ye,!0),window.removeEventListener("blur",Ye)};t(ze,e=>{e?(document.addEventListener("mousemove",Ke),document.addEventListener("mouseup",Ye,!0),document.addEventListener("touchmove",He,{passive:!1}),document.addEventListener("touchend",Ye,{passive:!1,capture:!0}),document.addEventListener("touchcancel",Ye,{passive:!1,capture:!0}),window.addEventListener("blur",Ye)):Xe()});return t(H,async e=>{e&&X.value&&!We.value&&(await n(),(()=>{if(!Ie.value)return;const e=Ie.value.parentElement;if(!e)return;const t=e.getBoundingClientRect(),i=Ie.value.getBoundingClientRect(),s=Math.max(0,t.width-i.width),r=Math.max(0,Math.min((t.width-i.width)/2,s));qe({x:r,y:60}),We.value=!0})()),e||(We.value=!1,ze.value=!1,Se.value=!1,fe.value?.hide())},{immediate:!0}),t(Ve,e=>{_e.value=e||"#3b82f6"},{immediate:!0}),a(()=>{Xe()}),r({state:le}),(e,t)=>{const i=A,s=M,r=k;return l(),c("div",{class:d(["custom-drawing-overlay",{"custom-drawing-overlay--floating-only":u(X)&&!u(ne)}])},[u(ne)?(l(),c("div",Z,[p("div",G,[(l(!0),c(w,null,m(Ce.value.tools,e=>(l(),c("div",{key:e.value,class:d(["custom-drawing-overlay__tool-item",{"is-active":u(C)===e.value}]),onClick:t=>(e=>{const t=C.value;t!==K.None&&xe(t)?.stopDrawing(),e!==K.None&&t!==e?(xe(e)?.startDrawing(),he(e)):he(K.None)})(e.value)},[g(i,{placement:"right",content:e.tooltip},{default:v(()=>[(l(),D(b(e.icon.component),P({ref_for:!0},e.icon.props),null,16))]),_:2},1032,["content"])],10,J))),128)),g(s,{direction:"horizontal",class:"custom-drawing-overlay__divider"}),(l(!0),c(w,null,m(Ce.value.modifier,e=>(l(),c("div",{key:e.value,class:d(["custom-drawing-overlay__tool-item","custom-drawing-overlay__tool-item--modifier",{"is-active":Te(e.value)}]),onClick:t=>(e=>{const t=ye();if("lock"===e){const e=!T.value;return ce(e),void t.forEach(t=>{t.toggleAllDrawLocked(e)})}if("hide"===e){const e=!$.value;de(e),$.value!==e&&t.forEach(e=>{e.toggleDrawVisible()})}})(e.value)},[g(i,{placement:"right",content:e.tooltip},{default:v(()=>[(l(),D(b(e.icon.component),P({ref_for:!0},e.icon.props),null,16))]),_:2},1032,["content"])],10,Q))),128)),g(s,{direction:"horizontal",class:"custom-drawing-overlay__divider"}),p("div",{class:"custom-drawing-overlay__tool-item",onClick:t[0]||(t[0]=(...e)=>u(ue)&&u(ue)(...e))},[g(i,{placement:"right",content:u(ge)("chart.tools.tooltip.delete-drawings")},{default:v(()=>[g(u(N),{size:24})]),_:1},8,["content"])])])])):x("",!0),u(X)&&u(H)?(l(),c("div",{key:1,ref_key:"toolbarRef",ref:Ie,class:d(["custom-drawing-overlay__floating-toolbar",{"custom-drawing-overlay__floating-toolbar--dragging":ze.value}]),style:f({left:`${Fe.value.x}px`,top:`${Fe.value.y}px`,touchAction:"none"}),onMousedown:t[2]||(t[2]=y(()=>{},["stop"])),onMouseup:y(Ye,["stop"]),onClick:t[3]||(t[3]=y(()=>{},["stop"])),onTouchstart:t[4]||(t[4]=y(()=>{},["stop"])),onTouchend:y(Ye,["stop"]),onTouchcancel:y(Ye,["stop"])},[p("div",{class:"custom-drawing-overlay__drag-handle",onMousedown:$e,onTouchstart:je},[g(u(z),{size:16,class:"custom-drawing-overlay__drag-icon"})],32),p("div",{class:"custom-drawing-overlay__color-trigger",onClick:Re},[g(u(W),{size:24}),p("div",{class:"custom-drawing-overlay__color-preview",style:f({backgroundColor:Ve.value})},null,4),g(u(q),{ref_key:"colorPickerRef",ref:fe,modelValue:_e.value,"onUpdate:modelValue":t[1]||(t[1]=e=>_e.value=e),class:"custom-drawing-overlay__color-picker",onChange:Oe},null,8,["modelValue"])]),u(H)?.strokeWidth&&Ae.value?(l(),c("div",ee,[g(r,{trigger:"click"},{dropdown:v(()=>[p("div",se,[(l(!0),c(w,null,m(be.value,e=>(l(),c("button",{key:e.value,type:"button",class:d(["custom-drawing-overlay__stroke-width-option",{"custom-drawing-overlay__stroke-width-option--active":Pe.value===e.value}]),onClick:t=>{return i=e.value,void(H.value&&Ee({...H.value,strokeWidth:i}));var i}},[p("span",{class:"custom-drawing-overlay__stroke-width-option-line",style:f({height:`${e.value}px`})},null,4),p("span",oe,_(e.label),1)],10,re))),128))])]),default:v(()=>[p("div",te,[p("div",{class:"custom-drawing-overlay__stroke-width-line",style:f({height:`${u(H)?.strokeWidth}px`})},null,4),p("p",ie,_(u(H)?.strokeWidth)+"px ",1)])]),_:1})])):x("",!0),p("button",{class:d(["custom-drawing-overlay__toolbar-action",{"custom-drawing-overlay__toolbar-action--active":Le.value}]),onClick:Ue},[g(u(N),{size:24})],2),p("button",{class:"custom-drawing-overlay__toolbar-action",onClick:Be},[g(u(N),{size:24})])],38)):x("",!0)],2)}}});var ae=(e=>(e.Brush="brush",e.Line="line",e.Text="text",e.OrderLine="order-line",e.None="none",e))(ae||{}),le=(e=>(e.None="none",e.Clean="clean",e.New="new",e.Updating="updating",e))(le||{}),he=(e=>(e.DrawUpdate="draw_update",e))(he||{}),ce=(e=>(e.OneMinute="1m",e.FiveMinutes="5m",e.FifteenMinutes="15m",e.ThirtyMinutes="30m",e.OneHour="1h",e.FourHours="4h",e.OneDay="1d",e.OneWeek="1w",e.OneMonth="1mn",e))(ce||{});const de=e=>{const t=(e=>{if("number"==typeof e)return new Date(1e3*e);if("string"==typeof e){const t=new Date(e);return Number.isNaN(t.getTime())?null:t}return(e=>{if(!e||"object"!=typeof e)return!1;const t=e;return"number"==typeof t.year&&"number"==typeof t.month&&"number"==typeof t.day})(e)?new Date(e.year,e.month-1,e.day):null})(e);return t?new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(t):""},ue=e=>{const t=(e=>e?{textPrimary:"#F0F1F3",stroke:"#A259FB",paneFill:"#A259FB4D"}:{textPrimary:"#0f1115",stroke:"#A259FB",paneFill:"#A259FB4D"})(e);return{labelTextColor:t.textPrimary,labelBackgroundColor:t.stroke,paneFillColor:t.paneFill,strokeColor:t.stroke,strokeWidth:2,showLabels:!0,showPanes:!0,textSize:14,textColor:t.stroke,locked:!1,nealDrawThreshold:5,touchNealDrawThreshold:20,priceLabelFormatter:e=>e.toFixed(2),timeLabelFormatter:e=>de(e)}},pe={strokeColor:"#ef4444",fillColor:"white",strokeWidth:1,radius:4,touchRadius:12};var we=(e=>(e.Line="line",e.Brush="brush",e.Text="text",e))(we||{});function me(e,t){if(void 0===e)throw new Error("Value is undefined");return e}function ge(e,t){return t-e.getBoundingClientRect().y}function ve(e,t){return t-e.getBoundingClientRect().x}function De(e,t){if(null===e.x||null===e.y||null===t.x||null===t.y)return null;const i=t.x-e.x,s=t.y-e.y;return Math.sqrt(i*i+s*s)}const be=(e,t)=>({x:e.x*t,y:e.y*t}),Pe=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),xe=()=>"undefined"!=typeof window&&("ontouchstart"in window&&null!==window.ontouchstart||navigator&&"maxTouchPoints"in navigator&&navigator.maxTouchPoints>0);class ye{_chart=void 0;_series=void 0;_p1={};_p2={};textValue="";_options=ue();dataUpdated;requestUpdate(){this._requestUpdate&&this._requestUpdate()}_requestUpdate;attached({chart:e,series:t,requestUpdate:i}){this._chart=e,this._series=t,this._series.subscribeDataChanged(this._fireDataUpdated),this._requestUpdate=i,this.requestUpdate()}detached(){this._series?.unsubscribeDataChanged(this._fireDataUpdated),this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return me(this._chart)}get series(){return me(this._series)}_fireDataUpdated(e){this.dataUpdated&&this.dataUpdated(e)}}class fe{}class _e{p1;p2;fillColor;vertical=!1;constructor(e,t,i,s){this.p1=e,this.p2=t,this.fillColor=i,this.vertical=s}draw(e){e.useBitmapCoordinateSpace(e=>{if(null===this.p1||null===this.p2)return;const t=e.context;t.save();const i=function(e,t,i){const s=Math.round(i*e),r=Math.round(i*t);return{position:Math.min(s,r),length:Math.abs(r-s)+1}}(this.p1,this.p2,this.vertical?e.verticalPixelRatio:e.horizontalPixelRatio);t.fillStyle=this.fillColor,this.vertical?t.fillRect(0,i.position,60*e.horizontalPixelRatio,i.length):t.fillRect(i.position,0,i.length,36*e.verticalPixelRatio),t.restore()})}}class Se{source;p1=null;p2=null;axisPaneRenderer;constructor(e,t){this.source=e,this.axisPaneRenderer=new _e(this.p1,this.p2,this.source.drawingTool.options.paneFillColor,t)}update(){[this.p1,this.p2]=this.getPoints()}renderer(){const e=this.source._options.showPanes;return this.axisPaneRenderer.p1=this.p1,this.axisPaneRenderer.p2=this.p2,this.axisPaneRenderer.fillColor=e?this.source.drawingTool.options.paneFillColor:"transparent",this.axisPaneRenderer}zOrder(){return"bottom"}}class Ce{source;point;position=null;constructor(e,t){this.source=e,this.point=t}coordinate(){return this.position??-1}visible(){return this.source._options.showLabels}tickVisible(){return this.source._options.showLabels}textColor(){return this.source._options.labelTextColor}backColor(){return this.source._options.labelBackgroundColor}movePoint(e){this.point=e,this.update()}}class Te extends Se{getPoints(){const e=this.source.series;if(!this.source._p1||!this.source._p2)return[null,null];return[e.priceToCoordinate(this.source._p1.price),e.priceToCoordinate(this.source._p2.price)]}}class ke extends Se{getPoints(){const e=this.source.chart.timeScale();if(!this.source._p1||!this.source._p2)return[null,null];return[e.timeToCoordinate(this.source._p1.time),e.timeToCoordinate(this.source._p2.time)]}}class Me extends Ce{update(){const e=this.source.chart.timeScale();this.position=e.timeToCoordinate(this.point.time)}text(){return this.source._options.timeLabelFormatter(this.point.time)}}class Ae extends Ce{update(){this.position=this.source.series.priceToCoordinate(this.point.price)}text(){return this.source.series.priceFormatter().format(this.point.price)}}class Le{x;y;anchorSelected;source;style={...pe};constructor({style:e,source:t}={}){this.x=0,this.y=0,this.anchorSelected=!1,this.source=t,this.style={...pe,...e}}draw(e,t,i){this.x=t,this.y=i;const s=e.context;s.beginPath();const r="undefined"!=typeof window&&("ontouchstart"in window&&null!==window.ontouchstart||navigator&&"maxTouchPoints"in navigator&&navigator.maxTouchPoints>0)?this.style.touchRadius:this.style.radius;s.arc(this.x*e.horizontalPixelRatio,this.y*e.verticalPixelRatio,r*e.verticalPixelRatio,0,2*Math.PI),s.fillStyle=this.style.fillColor,s.fill();const o=this.source?.selected??!1;s.lineWidth=o?2*this.style.strokeWidth*e.verticalPixelRatio:this.style.strokeWidth*e.verticalPixelRatio,s.strokeStyle=this.style.strokeColor,s.stroke()}containPoint(e){if(null===e.x||null===e.y)return!1;const t=De(e,{x:this.x,y:this.y}),i=xe()?this.style.touchRadius:this.style.radius;return null!==t&&t<=i}handleClickAnchorPoint(e){this.containPoint(e)&&(this.anchorSelected=!0)}}class Ve{source;p1;p2;anchorPoints;constructor({p1:e,p2:t,source:i}){this.p1=e,this.p2=t,this.source=i,this.anchorPoints=[new Le({source:i,style:{strokeColor:i._options.strokeColor}}),new Le({source:i,style:{strokeColor:i._options.strokeColor}})]}draw(e){this.source.drawingTool.drawVisible&&e.useBitmapCoordinateSpace(e=>{const t=e.context;if(null===this.p1?.x||null===this.p1?.y||null===this.p2?.x||null===this.p2?.y)return;const i=this.p1.x*e.horizontalPixelRatio,s=this.p1.y*e.verticalPixelRatio,r=this.p2.x*e.horizontalPixelRatio,o=this.p2.y*e.verticalPixelRatio;t.beginPath(),t.moveTo(i,s),t.lineTo(r,o),t.strokeStyle=this.source._options.strokeColor??"blue",t.lineWidth=this.source._options.strokeWidth*e.verticalPixelRatio,t.stroke(),this.anchorPoints.forEach(e=>{e.style.strokeColor=this.source._options.strokeColor??"blue"}),(this.source.hovered||this.source.selected)&&(this.anchorPoints[0].draw(e,this.p1.x,this.p1.y),this.anchorPoints[1].draw(e,this.p2.x,this.p2.y))})}}class Ee{source;p1={x:null,y:null};p2={x:null,y:null};linePaneRenderer;dynamicZOrder="normal";constructor(e){this.source=e,this.linePaneRenderer=new Ve({p1:this.p1,p2:this.p2,source:e})}renderer(){return this.linePaneRenderer.p1=this.p1,this.linePaneRenderer.p2=this.p2,this.linePaneRenderer}zOrder(){return this.dynamicZOrder}update(){const e=this.source.series,t=this.source.chart.timeScale(),i=e.priceToCoordinate(this.source._p1.price),s=e.priceToCoordinate(this.source._p2.price),r=t.timeToCoordinate(this.source._p1.time),o=t.timeToCoordinate(this.source._p2.time);null!==r&&null!==o&&null!==i&&null!==s&&(this.p1={x:r,y:i},this.p2={x:o,y:s})}}class Oe extends ye{_paneViews;_timeAxisLabelViews;_priceAxisLabelViews;_priceAxisPaneViews;_timeAxisPaneViews;hoverCandidate=!1;hovered=!1;selectCandidate=!1;selected=!1;id;localId;createdAt;state;drawingTool;dragPoint;beforeDragPoints;constructor({p1:e,p2:t,drawingTool:i,state:s,id:r,createdAt:o,options:n,selected:a}){super(),this.id=r,this.createdAt=o||Date.now(),this.localId=i.type+"-"+this.createdAt,this.state=s||"clean",this.drawingTool=i,this._p1=e,this._p2=t,this._options=$({...i.options,...n}),this.selected=a||!1,this._paneViews=[new Ee(this)],this._timeAxisLabelViews=[new Me(this,e),new Me(this,t)],this._priceAxisLabelViews=[new Ae(this,e),new Ae(this,t)],this._priceAxisPaneViews=[new Te(this,!0)],this._timeAxisPaneViews=[new ke(this,!1)]}containPoint(e){const t=this._paneViews[0],i=t.linePaneRenderer.anchorPoints,s=i[0].style.strokeWidth,r=t.p1,o=t.p2;return i.some(t=>t.containPoint(e))||function(e,t,i,s,r=5){if(null===t.x||null===t.y||null===i.x||null===i.y||null===e.x||null===e.y)return!1;const o=i.x-t.x,n=i.y-t.y;if(Math.abs(n*e.x-o*e.y+i.x*t.y-i.y*t.x)/Math.sqrt(o*o+n*n)>s/2+r)return!1;const a=(e.x-t.x)*o+(e.y-t.y)*n;return a>=0&&a<=o*o+n*n}(e,r,o,s,xe()?this._options.touchNealDrawThreshold:this._options.nealDrawThreshold)}onMouseMove(e){if(this._options.locked||this.drawingTool.runtime.getLockAllDraw())return;const t=e.point,i=e.time,s=this._paneViews[0].linePaneRenderer.anchorPoints;if(!t||!i)return;const r=this.containPoint(t),o=this.hoverCandidate,n=this.hovered;let a=!1;if(s.forEach((e,s)=>{if(e.anchorSelected){if(a=!0,0===s){if(this._p1.time===i&&this._p1.price===this.series.coordinateToPrice(t.y))return;this._p1.time=i,this._p1.price=this.series.coordinateToPrice(t.y)}else{if(this._p2.time===i&&this._p2.price===this.series.coordinateToPrice(t.y))return;this._p2.time=i,this._p2.price=this.series.coordinateToPrice(t.y)}this.state="updating",this.requestUpdate()}}),!a){this.hoverCandidate=r,r||(this.hovered=r);const e=this.handleDragWholeDraw(t),i=o!==this.hoverCandidate||n!==this.hovered;(e||i)&&this.requestUpdate()}}onMouseDown(e){this.dragPoint=e,this.beforeDragPoints={p1:this._p1,p2:this._p2},this.containPoint(e)?(this.chart.applyOptions({handleScroll:!1}),this.selectCandidate=!0):(this.selectCandidate=!1,this.selected=!1,this.hovered=!1,this.hoverCandidate=!1);this._paneViews[0].linePaneRenderer.anchorPoints.forEach(t=>{t.handleClickAnchorPoint(e)})}onMouseUp(){const e=this._paneViews[0].linePaneRenderer.anchorPoints;this.selectCandidate&&!this.selected&&this.selectedDraw(),this.hovered=!1,this.hoverCandidate=!1,this.selectCandidate=!1,this.dragPoint=void 0,this.beforeDragPoints=void 0,e.forEach(e=>{e.anchorSelected=!1}),this.chart.applyOptions({handleScroll:!0}),this.requestUpdate()}handleDragWholeDraw(e){let t=!1;if(this.dragPoint&&this.selected){const i=e.x-this.dragPoint.x,s=e.y-this.dragPoint.y,r=this.beforeDragPoints?.p1,o=this.beforeDragPoints?.p2;if(!r||!o)return!1;const n=this.chart.timeScale().timeToCoordinate(r.time),a=this.series.priceToCoordinate(r.price),l=this.chart.timeScale().timeToCoordinate(o.time),c=this.series.priceToCoordinate(o.price);if(null===n||null===a||null===l||null===c)return!1;const d=this.chart.timeScale().coordinateToTime(n+i),u=this.series.coordinateToPrice(a+s),p=this.chart.timeScale().coordinateToTime(l+i),w=this.series.coordinateToPrice(c+s);if(!(d&&u&&p&&w))return!1;if(this._p1.time===d&&this._p1.price===u&&this._p2.time===p&&this._p2.price===w)return!1;this._p1={time:d,price:u},this._p2={time:p,price:w},this._priceAxisLabelViews[0].movePoint(this._p1),this._timeAxisLabelViews[0].movePoint(this._p1),this._priceAxisLabelViews[1].movePoint(this._p2),this._timeAxisLabelViews[1].movePoint(this._p2),this.state="updating",t=!0}return t}selectedDraw(){this.selected=!0,this.selectCandidate=!0,this.drawingTool.runtime.setSelectedDrawOptions(this._options,ae.Line)}getPoints(){return[this._p1,this._p2]}updateSelectedState(){this.selected?(this._options.showPanes=!0,this._options.showLabels=!0):(this._options.showPanes=!1,this._options.showLabels=!1)}updateAllViews(){this.updateSelectedState(),this._paneViews.forEach(e=>e.update()),this._timeAxisLabelViews.forEach(e=>e.update()),this._priceAxisLabelViews.forEach(e=>e.update()),this._priceAxisPaneViews.forEach(e=>e.update()),this._timeAxisPaneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}priceAxisViews(){return this._priceAxisLabelViews}timeAxisViews(){return this._timeAxisLabelViews}priceAxisPaneViews(){return this._priceAxisPaneViews}timeAxisPaneViews(){return this._timeAxisPaneViews}detached(){this._paneViews[0].update()}updateSelectedOptions(e){this.selected&&(Object.assign(this._options,{...this._options,...e}),this.state="updating",this.requestUpdate())}}class Re extends Oe{constructor({p1:e,p2:t,drawingTool:i}){super({p1:e,p2:t,drawingTool:i,selected:!0})}updateEndPoint(e){this._p2=e,this._paneViews.forEach(e=>e.update()),this._timeAxisLabelViews[1].movePoint(e),this._priceAxisLabelViews[1].movePoint(e),this.requestUpdate()}}const Ue=()=>{const e=new Set;let t=null;const i=()=>{t=null,e.forEach(e=>e.requestUpdate()),e.clear()};return{schedule:s=>{s.forEach(t=>{t&&e.add(t)}),null===t&&(t=window.requestAnimationFrame(i))},cancel:()=>{null!==t&&(window.cancelAnimationFrame(t),t=null),e.clear()}}},Be=()=>{let e=null,t="default",i="default";const s=()=>{e=null,i!==t&&(document.body.style.cursor=t,i=t)};return{setCursor:i=>{t=i,null===e&&(e=window.requestAnimationFrame(s))},reset:()=>{t="default",null!==e&&(window.cancelAnimationFrame(e),e=null),"default"!==i&&(document.body.style.cursor="default",i="default")}}},Fe=(e,t,i)=>{const s=e.chartElement();return{x:ve(s,t),y:ge(s,i)}},Ne=(e,t)=>Fe(e,t.clientX,t.clientY),ze=(e,t)=>Fe(e,t.clientX,t.clientY),We=(e,t)=>({point:t,time:e.timeScale().coordinateToTime(t.x)}),Ie=(e,t,i)=>{const s=e.timeScale().coordinateToTime(i.x),r=t.coordinateToPrice(i.y);return s&&null!=r?{time:s,price:r}:null},qe=(e,t)=>{e.forEach(e=>{e.onMouseDown(t)})},$e=e=>{e.forEach(e=>{e.onMouseUp()})},je=(e,t)=>e.some(e=>t(e)),Ke=({primitives:e,isDrawing:t,isPointerHit:i,clearSelection:s})=>{if(t)return;je(e,i)||s()},He=(e,t,i)=>(t.push(i),e.attachPrimitive(i),i),Ye=(e,t,i)=>(He(e,t,i),i.selectedDraw(),i),Xe=e=>e.map(e=>({time:e.time,price:e.price})),Ze=(e,t,i)=>e(t,i),Ge=async(e,t,i=e=>Xe(e.getPoints()))=>{const s=e.filter(e=>"number"==typeof e.id&&e.id>0&&e.state===le.Updating);await Promise.all(s.map(async e=>{try{await t(e.id,i(e)),e.state=le.Clean}catch{e.state=le.Updating}}))},Je=(e,t,i)=>{let s=null,r=!1;const o=async()=>{if(s)return r=!0,void(await s);s=(async()=>{do{r=!1,await Ge(e(),t,i)}while(r)})();try{await s}finally{s=null}};return{schedule:()=>{o()},flush:async()=>{await o()},cancel:()=>{r=!1}}},Qe=({chart:e,onClick:t,onCrosshairMove:i,onVisibleRangeChange:s,onMouseDown:r,onMouseUp:o,onContextMenu:n,onTouchStart:a,onTouchMove:l,onTouchEnd:c,textArea:d,onTextAreaChange:u,onTextAreaBlur:p})=>{t&&e.subscribeClick(t),i&&e.subscribeCrosshairMove(i),s&&e.timeScale().subscribeVisibleLogicalRangeChange(s);const w=e.chartElement();return r&&w.addEventListener("mousedown",r),o&&w.addEventListener("mouseup",o),n&&w.addEventListener("contextmenu",n),a&&w.addEventListener("touchstart",a,{passive:!1}),l&&w.addEventListener("touchmove",l,{passive:!1}),c&&w.addEventListener("touchend",c),d&&u&&d.addEventListener("change",u),d&&p&&d.addEventListener("blur",p),()=>{t&&e.unsubscribeClick(t),i&&e.unsubscribeCrosshairMove(i),s&&e.timeScale().unsubscribeVisibleLogicalRangeChange(s),r&&w.removeEventListener("mousedown",r),o&&w.removeEventListener("mouseup",o),n&&w.removeEventListener("contextmenu",n),a&&w.removeEventListener("touchstart",a),l&&w.removeEventListener("touchmove",l),c&&w.removeEventListener("touchend",c),d&&u&&d.removeEventListener("change",u),d&&p&&d.removeEventListener("blur",p)}},et=(e,t,i)=>{const s=!e;return i.schedule(t),s},tt=e=>{let t=!1;return e.forEach(e=>{e.selected&&(e._options.locked=!e._options.locked,e.state="updating",t=!0)}),t},it=(e,t)=>{let i=!1;return e.forEach(e=>{e._options.locked!==t&&(e._options.locked=t,e.state="updating",i=!0)}),i},st=e=>e.some(e=>e.selected),rt=(e,t)=>{let i=!1;e.forEach(e=>{e.selected&&(e.selected=!1,i=!0)}),i&&t()},ot=(e,t,i)=>(t.forEach(t=>{e.detachPrimitive(t)}),i(),[]),nt=async(e,t,i)=>{const s=[];for(const r of t)r.selected?(e.detachPrimitive(r),void 0!==r.id&&r.id>0&&await i(r.id)):s.push(r);return s};class at extends fe{type=ae.Line;chart;series;options;runtime;persistence;lines=[];currentPoints=[];previewLine;drawVisible=!0;primitiveUpdateScheduler=Ue();drawingUpdateScheduler;cursorScheduler=Be();pendingCreateOperations=new Set;unbindEvents;localRuntimeState={drawMode:ae.None,lockAllDraw:!1,selectedDrawMode:null,selectedDrawOptions:void 0,chartControlStateChangesLog:[]};handleVisibleRangeChange=()=>{this.primitiveUpdateScheduler.schedule([...this.lines,this.previewLine])};buildLinePayload(e,t=this.options.strokeWidth){return{points:Xe(e),width:t,color:this.options.strokeColor}}trackPendingCreate(e,t){const i=t.then(t=>{t&&(e.id=t.id,e.createdAt=t.created_at,e.state!==le.New?e.state===le.Updating&&this.checkUpdateDraw():e.state=le.Clean)}).finally(()=>{this.pendingCreateOperations.delete(i)});this.pendingCreateOperations.add(i)}constructor({chart:e,series:t,options:i,isDark:s,runtime:r,persistence:o}){super(),this.chart=e,this.series=t,this.options={...ue(s),...i},this.runtime=r??{getDrawMode:()=>this.localRuntimeState.drawMode,setDrawMode:e=>{this.localRuntimeState.drawMode=e},getLockAllDraw:()=>this.localRuntimeState.lockAllDraw,clearSelectedDrawing:()=>{this.localRuntimeState.selectedDrawMode=null,this.localRuntimeState.selectedDrawOptions=void 0},setSelectedDrawOptions:(e,t)=>{if(null===t)return this.localRuntimeState.selectedDrawMode=null,void(this.localRuntimeState.selectedDrawOptions=void 0);this.localRuntimeState.selectedDrawMode=t,this.localRuntimeState.selectedDrawOptions={...e}},getSelectedTimeFrame:()=>ce.OneMinute,getChartDataTimes:()=>[],getChartControlStateChangesLog:()=>this.localRuntimeState.chartControlStateChangesLog},this.persistence=o??{createDrawing:async()=>null,updateDrawing:async()=>{},deleteDrawing:async()=>{}},this.drawingUpdateScheduler=Je(()=>this.lines,this.persistence.updateDrawing,e=>({points:Xe(e.getPoints()),width:e._options.strokeWidth,color:e._options.strokeColor})),this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.subscribeEvents()}subscribeEvents(){this.unbindEvents=Qe({chart:this.chart,onClick:this.onClick,onCrosshairMove:this.onMouseMove,onVisibleRangeChange:this.handleVisibleRangeChange,onMouseDown:this.handleMouseDown,onMouseUp:this.handleMouseUp,onContextMenu:this.handleContextMenu,onTouchStart:this.handleTouchStart,onTouchMove:this.handleTouchMove,onTouchEnd:this.handleTouchEnd})}unsubscribeEvents(){this.unbindEvents?.(),this.unbindEvents=void 0}handleTouchStart=e=>{if(0===e.touches.length)return;this.chart.clearCrosshairPosition();const t=e.touches[0],i=ze(this.chart,t);qe(this.lines,i),this.previewLine?.onMouseDown(i),e.preventDefault()};handleTouchMove=e=>{if(0===e.touches.length)return;const t=e.touches[0],i=ze(this.chart,t);this.onMouseMove(We(this.chart,i)),e.preventDefault()};handleTouchEnd=()=>{$e(this.lines),this.previewLine?.onMouseUp(),this.finalizePreviewLine(),this.checkUpdateDraw()};handleMouseDown=e=>{const t=Ne(this.chart,e);Ke({primitives:this.lines,isDrawing:this.isDrawing(),isPointerHit:e=>e.containPoint(t),clearSelection:()=>this.unSelectAnyDraw()}),qe(this.lines,t)};handleMouseUp=()=>{$e(this.lines),this.checkUpdateDraw()};handleContextMenu=e=>{const t=Ne(this.chart,e);if(je(this.lines,e=>e.containPoint(t))){this.unSelectAnyDraw();const i=this.lines.find(e=>e.containPoint(t));i&&(i.selected=!0,this.runtime.setSelectedDrawOptions({strokeWidth:i._options.strokeWidth,strokeColor:i._options.strokeColor},ae.Line)),e.preventDefault(),e.stopPropagation()}};isDrawing(){return this.runtime.getDrawMode()===ae.Line}startDrawing(){this.runtime.setDrawMode(ae.Line)}stopDrawing(){this.currentPoints=[],this.removePreviewLine(),this.runtime.setDrawMode(ae.None)}onClick(e){if(!e.point||!e.time||!this.series)return;const t=Ie(this.chart,this.series,e.point);t&&this.isDrawing()&&this.addPoint(t)}onMouseMove(e){if(this.lines.forEach(t=>t.onMouseMove(e)),this.mouseStyling(),e.point&&this.series&&e.time&&this.isDrawing()&&this.previewLine){const t=Ie(this.chart,this.series,e.point);t&&this.previewLine.updateEndPoint(t)}}addPoint(e){this.currentPoints?.push(e),1===this.currentPoints?.length&&this.addPreviewLine(this.currentPoints[0]),2===this.currentPoints?.length&&(this.addNewLine(this.currentPoints[0],this.currentPoints[1]),this.stopDrawing())}addPreviewLine(e){this.previewLine=new Re({p1:e,p2:e,drawingTool:this}),this.series.attachPrimitive(this.previewLine)}addNewLine(e,t){const i=new Oe({p1:e,p2:t,drawingTool:this,state:"new"});Ye(this.series,this.lines,i),this.trackPendingCreate(i,Ze(this.persistence.createDrawing,we.Line,{points:Xe([e,t]),width:i._options.strokeWidth,color:i._options.strokeColor}))}finalizePreviewLine(){const e=this.previewLine?._p1,t=this.previewLine?._p2;e&&t&&!j(e,t)&&(this.addNewLine(e,t),this.removePreviewLine(),this.stopDrawing())}removePreviewLine(){this.previewLine&&this.series&&(this.series.detachPrimitive(this.previewLine),this.previewLine=void 0)}initData(e){if(!e||0===e.length)return;const t=this.runtime.getChartControlStateChangesLog(),i=t[t.length-1]===he.DrawUpdate;e.forEach(e=>{const{data:t}=e;if(!t.points)return;const s=!!i&&t.selected,r=new Oe({p1:t.points[0],p2:t.points[1],id:e.id,drawingTool:this,createdAt:t.createdAt,options:t.options,selected:s});s&&r.selectedDraw(),this.series.attachPrimitive(r),this.lines.push(r)})}checkUpdateDraw(){this.drawingUpdateScheduler.schedule()}toggleDrawVisible(){this.drawVisible=et(this.drawVisible,this.lines,this.primitiveUpdateScheduler)}toggleSelectedDrawLocked(){tt(this.lines)&&this.checkUpdateDraw()}toggleAllDrawLocked(e){it(this.lines,e)&&this.checkUpdateDraw()}isAnyDrawSelected(){return st(this.lines)}updateSelectedOptions(e){this.lines.forEach(t=>t.updateSelectedOptions(e)),this.checkUpdateDraw()}async flushPendingUpdates(){this.pendingCreateOperations.size>0&&await Promise.allSettled([...this.pendingCreateOperations]),await this.drawingUpdateScheduler.flush()}mouseStyling(){const e=this.lines.some(e=>e.hovered);this.cursorScheduler.setCursor(e?"pointer":"default")}unSelectAnyDraw(){rt(this.lines,this.runtime.clearSelectedDrawing)}cleanPrimitives(){this.lines=ot(this.series,this.lines,this.runtime.clearSelectedDrawing)}cleanAll(){this.unsubscribeEvents(),this.primitiveUpdateScheduler.cancel(),this.drawingUpdateScheduler.cancel(),this.removePreviewLine(),this.currentPoints=[],this.cursorScheduler.reset(),this.cleanPrimitives()}async removeSelectedDraw(){this.lines=await nt(this.series,this.lines,e=>this.persistence.deleteDrawing(e))}}const lt=e=>({[ce.OneMinute]:6e4,[ce.FiveMinutes]:3e5,[ce.FifteenMinutes]:9e5,[ce.ThirtyMinutes]:18e5,[ce.OneHour]:36e5,[ce.FourHours]:144e5,[ce.OneDay]:864e5,[ce.OneWeek]:6048e5,[ce.OneMonth]:2592e6}[e]??6e4),ht=e=>{const t=(e=>{if(null==e)return null;if("number"==typeof e){if(!Number.isFinite(e))return null;const t=e>1e11?e/1e3:e;return Math.trunc(t)}const t=(e instanceof Date?e:new Date(e)).getTime();return Number.isFinite(t)?Math.trunc(t/1e3):null})(e);return null===t?null:t+(e=>60*-new Date(1e3*e).getTimezoneOffset())(t)},ct=(e,t)=>{if(!t.length||!Number.isFinite(e))return e;const i=t[0],s=t[t.length-1];if(e<i||e>s)return e;let r=0,o=t.length-1;for(;r<=o;){const i=Math.floor((r+o)/2),s=t[i];if(s===e)return s;s<e?r=i+1:o=i-1}const n=t[Math.max(0,o)],a=t[Math.min(t.length-1,r)];return Math.abs(e-n)<=Math.abs(a-e)?n:a},dt=(e,t)=>{const i="number"==typeof e.time?e.time:Number(e.time);return Number.isFinite(i)?{...e,time:ct(i,t)}:e},ut=[ce.OneMinute,ce.FiveMinutes,ce.FifteenMinutes,ce.ThirtyMinutes,ce.OneHour,ce.FourHours,ce.OneDay,ce.OneWeek,ce.OneMonth],pt=(e,t=ce.OneMinute)=>Math.max(1,Math.floor(lt(((e,t=ce.OneMinute)=>ut.find(t=>t===e)??t)(e,t))/1e3)),wt=e=>{const t=[];return e.forEach(e=>{const i=(e=>({time:Number(e.time),price:e.price}))(e);if(!Number.isFinite(i.time)||!Number.isFinite(i.price))return;const s=t.at(-1);s&&s.time===i.time&&s.price===i.price||t.push(i)}),t},mt=(e,t)=>{const i=wt(e);if(!i.length)return null;const s=i[0],r=pt(t,t);return{version:2,anchorPoint:s,baseInterval:t,relativePoints:i.map(e=>({dxLogical:(e.time-s.time)/r,dyPrice:e.price-s.price}))}},gt=(e,t)=>{if(!Number.isFinite(e)||!t.length)return e;const i=t[0],s=t[t.length-1];return e<=i?i:e>=s?s:ct(e,t)},vt=(e,t,i)=>{const s=gt(e.anchorPoint.time,t),r=pt(e.baseInterval,ce.OneMinute),o=pt(i,ce.OneMinute),n=r/o,a={time:e.anchorPoint.time,price:e.anchorPoint.price},l={time:s,price:e.anchorPoint.price};return{version:2,anchorPoint:a,mountedAnchorPoint:l,baseInterval:e.baseInterval,relativePoints:e.relativePoints,points:e.relativePoints.map(e=>({time:s+e.dxLogical*o*n,price:l.price+e.dyPrice}))}};class Dt{drawPoints;source;anchorPoints;smoothPoints=[];drawFullyViewFirstTime=!1;lastViewportKey=null;lastPointsKey=null;constructor({source:e}){this.source=e,this.drawPoints=e.drawPoints,this.anchorPoints=[new Le({source:e,style:{strokeColor:e._options.strokeColor??"blue"}}),new Le({source:e,style:{strokeColor:e._options.strokeColor??"blue"}})]}mapTimePointsToPixelPoints(e){return e.map(e=>({x:this.source.chart.timeScale().timeToCoordinate(e.time),y:this.source.series.priceToCoordinate(e.price)})).filter(e=>null!==e.x&&null!==e.y&&Number.isFinite(e.x)&&Number.isFinite(e.y))}getBrushShapeKey(){if(2!==this.source.brushData?.version)return"legacy";const e=this.source.brushData.relativePoints[0],t=this.source.brushData.relativePoints[this.source.brushData.relativePoints.length-1];return["v2",this.source.drawingTool.runtime.getSelectedTimeFrame(),this.source.brushData.baseInterval,this.source.brushData.mountedAnchorPoint.time,this.source.brushData.mountedAnchorPoint.price,this.source.brushData.relativePoints.length,e?.dxLogical,e?.dyPrice,t?.dxLogical,t?.dyPrice].join("|")}getPixelsPerLogicalBar(){const e=this.source.chart.timeScale().getVisibleLogicalRange(),t=this.source.chart.paneSize?.(0),i=e?e.to-e.from:0;return!t?.width||!Number.isFinite(i)||i<=0?0:t.width/i}getPixelDrawPoints(){const e=this.mapTimePointsToPixelPoints(this.drawPoints);if(2===this.source.brushData?.version){const t=this.source.brushData.mountedAnchorPoint,i=this.source.chart.timeScale().timeToCoordinate(t.time),s=this.source.series.priceToCoordinate(t.price),r=this.getPixelsPerLogicalBar();if(null===i||null===s||!r)return e;const o=pt(this.source.brushData.baseInterval)/pt(this.source.drawingTool.runtime.getSelectedTimeFrame()),n=this.source.brushData.relativePoints.map(e=>({x:i+e.dxLogical*o*r,y:this.source.series.priceToCoordinate(t.price+e.dyPrice)})).filter(e=>Number.isFinite(e.x)&&null!==e.y&&Number.isFinite(e.y));return n.length?n:e}return e}getSmoothPoints(){const e=this.source.drawingTool?.chart.timeScale().getVisibleRange(),t=this.source.chart.timeScale().getVisibleLogicalRange(),i=this.source.series.priceScale().getVisibleRange(),s=this.source.chart.paneSize?.(0),r=e?.from,o=[e?`${e.from}-${e.to}`:"",t?`${t.from}-${t.to}`:"",i?`${i.from}-${i.to}`:"",s?`${s.width}-${s.height}`:""].join("|"),n=`${this.source.geometryVersion}-${this.source.drawPoints.length}-${this.getBrushShapeKey()}`;if(this.lastViewportKey===o&&this.lastPointsKey===n)return this.smoothPoints;const a=this.source._p2.time>r;if(2!==this.source.brushData?.version&&!this.drawFullyViewFirstTime){if(!a)return this.lastViewportKey=null,this.lastPointsKey=null,this.smoothPoints=[],[];this.drawFullyViewFirstTime=!0}const l=this.getPixelDrawPoints();if(!l.length)return this.lastViewportKey=null,this.lastPointsKey=null,this.smoothPoints=[],[];if(this.lastViewportKey=o,this.lastPointsKey=n,l.length<=2)return this.smoothPoints=l,l;const c=[];for(let u=1;u<l.length;u++){const e=l[u],t=l[u-1],i={x:e.x-t.x,y:e.y-t.y},s=Math.sqrt(i.x**2+i.y**2),r=Math.min(5,Math.floor(2*s/15)),o=be(be(i,1/s),s/r);for(let n=0;n<r-1;n++){const e=be(o,n),i={x:t.x+e.x,y:t.y+e.y};c.push(i)}c.push(e)}const d=this.smoothArray(c,15);return this.smoothPoints=void 0===d[0]?[]:d,this.smoothPoints}smoothArray(e,t){const i=new Array(e.length);if(1===e.length)return e;for(let s=0;s<e.length;s++){let r={x:0,y:0};for(let i=0;i<t;i++){const t=Math.max(s-i,0),o=Math.min(s+i,e.length-1);r=Pe(r,e[t]),r=Pe(r,e[o])}i[s]=be(r,.5/t)}return i.push(e[e.length-1]),i}drawBrush(e,t){if(0===t.length)return;const i=e.context,s=e.horizontalPixelRatio,r=e.verticalPixelRatio;i.strokeStyle=this.source._options.strokeColor??"blue";const o=this.source._options.strokeWidth*r;if(i.lineWidth=o,i.lineCap="round",i.lineJoin="round",i.fillStyle=this.source._options.strokeColor??"blue",this.anchorPoints.forEach(e=>{e.style.strokeColor=this.source._options.strokeColor??"blue"}),i.beginPath(),1===t.length){const{x:e,y:n}=t[0];return i.arc(e*s,n*r,o/2,0,2*Math.PI,!0),void i.fill()}if(2===t.length){const[e,o]=t;i.moveTo(e.x*s,e.y*r),i.lineTo(o.x*s,o.y*r)}else{const e=t[0];i.moveTo(e.x*s,e.y*r);for(let a=1;a<t.length-1;a++){const e=t[a],o=t[a+1],n=e.x*s,l=e.y*r,c=.5*(e.x+o.x)*s,d=.5*(e.y+o.y)*r;i.quadraticCurveTo(n,l,c,d)}const o=t[t.length-1],n=t[t.length-2];i.quadraticCurveTo(n.x*s,n.y*r,o.x*s,o.y*r)}i.stroke()}draw(e){this.smoothPoints=this.getSmoothPoints(),this.source.drawingTool?.drawVisible&&e.useBitmapCoordinateSpace(e=>{if(this.drawBrush(e,this.smoothPoints),this.source.hovered||this.source.selected){const t=this.smoothPoints[0],i=this.smoothPoints[this.smoothPoints.length-1];if(!t||!i)return;this.anchorPoints[0].draw(e,t.x,t.y),this.anchorPoints[1].draw(e,i.x,i.y)}})}}class bt{source;brushPaneRenderer;dynamicZOrder="normal";constructor(e){this.source=e,this.brushPaneRenderer=new Dt({source:e})}renderer(){return this.brushPaneRenderer}zOrder(){return this.dynamicZOrder}}class Pt extends ye{_paneViews;_timeAxisLabelViews;_priceAxisLabelViews;_priceAxisPaneViews;_timeAxisPaneViews;hoverCandidate=!1;hovered=!1;selectCandidate=!1;selected=!1;id;localId;createdAt;drawingTool;state;drawPoints=[];geometryVersion=0;dragPoint;drawPointsBeforeDrag=[];brushData;anchorPointBeforeDrag;boundingPointsBeforeDrag;constructor({drawPoints:e,boundingPoints:t,brushData:i,drawingTool:s,state:r,id:o,createdAt:n,selected:a,options:l}){super(),this.id=o,this.createdAt=n||Date.now(),this.localId=s.type+"-"+this.createdAt,this.state=r||"clean",this.drawingTool=s,this.drawPoints=e,this.brushData=i,this.selected=a||!1,this._options=$({...s.options,...l}),this._paneViews=[new bt(this)];const[c,d]=t;this._p1=c,this._p2=d,this._timeAxisLabelViews=[new Me(this,this._p1),new Me(this,this._p2)],this._priceAxisLabelViews=[new Ae(this,this._p1),new Ae(this,this._p2)],this._timeAxisPaneViews=[new ke(this,!1)],this._priceAxisPaneViews=[new Te(this,!0)]}onMouseMove(e){const{point:t}=e;if(this._options.locked||this.drawingTool.runtime.getLockAllDraw()||!t)return;const i=this.hoverCandidate,s=this.hovered,r=this.containPoint(t);this.drawingTool.isMouseDown||(this.hoverCandidate=r),r||(this.hovered=!1);const o=this.handleDrag(t),n=i!==this.hoverCandidate||s!==this.hovered;(o||n)&&this.requestUpdate()}onMouseDown({x:e,y:t}){this.dragPoint={x:e,y:t},this.drawPointsBeforeDrag=$(this.drawPoints),this.anchorPointBeforeDrag=this.brushData?$(this.brushData.mountedAnchorPoint):void 0,this.boundingPointsBeforeDrag={p1:$(this._p1),p2:$(this._p2)};this.containPoint({x:e,y:t})?(this.chart.applyOptions({handleScroll:!1}),this.selectCandidate=!0):(this.selectCandidate=!1,this.selected=!1,this.hovered=!1,this.hoverCandidate=!1)}onMouseUp(){this.selectCandidate&&!this.selected&&this.selectedDraw(),this.dragPoint=void 0,this.drawPointsBeforeDrag=[],this.anchorPointBeforeDrag=void 0,this.boundingPointsBeforeDrag=void 0,this.hovered=!1,this.hoverCandidate=!1,this.selectCandidate=!1,this.chart.applyOptions({handleScroll:!0}),this.requestUpdate()}handleDrag(e){let t=!1;if(this.selected&&this.dragPoint){const i=e.x-(this.dragPoint.x??0),s=e.y-(this.dragPoint.y??0);if(2===this.brushData?.version&&this.anchorPointBeforeDrag){const e=this.drawingTool.runtime.getChartDataTimes(),t=this.chart.timeScale().timeToCoordinate(this.anchorPointBeforeDrag.time),r=this.series.priceToCoordinate(this.anchorPointBeforeDrag.price);if(null===t||null===r)return!1;const o=this.chart.timeScale().coordinateToTime(t+i),n=this.series.coordinateToPrice(r+s);if(null===o||null===n)return!1;const a=gt(Number(o),e);return this.brushData.anchorPoint={time:a,price:n},this.brushData.mountedAnchorPoint={time:a,price:n},this.syncBrushDataDerivedState(),this.state="updating",!0}if(this.drawPointsBeforeDrag.forEach((e,t)=>{const r=this.chart.timeScale().timeToCoordinate(e.time),o=this.series.priceToCoordinate(e.price);if(null===r||null===o)return;const n=this.chart.timeScale().coordinateToTime(r+i),a=this.series.coordinateToPrice(o+s);this.drawPoints[t]={time:n,price:a}}),!this.boundingPointsBeforeDrag)return!1;const{p1:r,p2:o}=this.boundingPointsBeforeDrag,n=this.chart.timeScale().timeToCoordinate(r.time),a=this.series.priceToCoordinate(r.price),l=this.chart.timeScale().timeToCoordinate(o.time),c=this.series.priceToCoordinate(o.price);if(null===n||null===a||null===l||null===c)return!1;const d=this.chart.timeScale().coordinateToTime(n+i),u=this.series.coordinateToPrice(a+s),p=this.chart.timeScale().coordinateToTime(l+i),w=this.series.coordinateToPrice(c+s);if(!(d&&u&&p&&w))return!1;if(this._p1.time===d&&this._p1.price===u&&this._p2.time===p&&this._p2.price===w)return!1;this._p1={time:d,price:u},this._p2={time:p,price:w},this._priceAxisLabelViews[0].movePoint(this._p1),this._timeAxisLabelViews[0].movePoint(this._p1),this._priceAxisLabelViews[1].movePoint(this._p2),this._timeAxisLabelViews[1].movePoint(this._p2),this.geometryVersion+=1,this.state="updating",t=!0}return t}addPoint({price:e,time:t}){this.drawPoints.push({price:e,time:t}),this.geometryVersion+=1,this.requestUpdate()}syncBoundsFromPoints(e){if(!e.length)return;const t=$(e[0]),i=e.reduce((e,t)=>{const i=Number(t.time),s=Number(e.p1.time),r=Number(e.p2.time);return i<s&&(e.p1.time=t.time),i>r&&(e.p2.time=t.time),t.price>e.p1.price&&(e.p1.price=t.price),t.price<e.p2.price&&(e.p2.price=t.price),e},{p1:$(t),p2:$(t)});this._p1=i.p1,this._p2=i.p2,this._priceAxisLabelViews[0].movePoint(this._p1),this._timeAxisLabelViews[0].movePoint(this._p1),this._priceAxisLabelViews[1].movePoint(this._p2),this._timeAxisLabelViews[1].movePoint(this._p2)}getMountedBrushPoints(){if(!this.brushData?.version)return null;const e=this.drawingTool.runtime.getChartDataTimes();return vt({anchorPoint:{time:Number(this.brushData.anchorPoint.time),price:this.brushData.anchorPoint.price},baseInterval:this.brushData.baseInterval,relativePoints:this.brushData.relativePoints},e,this.drawingTool.runtime.getSelectedTimeFrame())}syncBrushDataDerivedState(){if(!this.brushData?.version)return;const e=this.getMountedBrushPoints();e&&(this.brushData={version:e.version,anchorPoint:e.anchorPoint,mountedAnchorPoint:e.mountedAnchorPoint,baseInterval:e.baseInterval,relativePoints:e.relativePoints},this.drawPoints=e.points,this.syncBoundsFromPoints(e.points),this.geometryVersion+=1,this.requestUpdate())}getPersistedBrushData(e){return 2===this.brushData?.version?{version:2,anchorPoint:{time:Number(this.brushData.anchorPoint.time),price:this.brushData.anchorPoint.price},baseInterval:this.brushData.baseInterval,relativePoints:this.brushData.relativePoints}:mt(this.drawPoints,e)}updateBoundingPoints({price:e,time:t}){const i=this._p1,s=this._p2;if(!i||!s)return;const r=$(i),o=$(s),n=t,a=i.time,l=s.time;n<a&&(r.time=t),n>l&&(o.time=t),e>i.price&&(r.price=e),e<s.price&&(o.price=e);(r.price!==i.price||r.time!==i.time||o.price!==s.price||o.time!==s.time)&&(this._p1=r,this._p2=o,this._priceAxisLabelViews[0].movePoint(this._p1),this._timeAxisLabelViews[0].movePoint(this._p1),this._priceAxisLabelViews[1].movePoint(this._p2),this._timeAxisLabelViews[1].movePoint(this._p2),this.geometryVersion+=1)}updateSelectedState(){this.selected?(this._options.showPanes=!0,this._options.showLabels=!0):(this._options.showPanes=!1,this._options.showLabels=!1)}paneViews(){return this._paneViews}priceAxisViews(){return this._priceAxisLabelViews}timeAxisViews(){return this._timeAxisLabelViews}priceAxisPaneViews(){return this._priceAxisPaneViews}timeAxisPaneViews(){return this._timeAxisPaneViews}detached(){}updateAllViews(){this.updateSelectedState(),this._priceAxisLabelViews.forEach(e=>e.update()),this._timeAxisLabelViews.forEach(e=>e.update()),this._priceAxisPaneViews.forEach(e=>e.update()),this._timeAxisPaneViews.forEach(e=>e.update())}updateSelectedOptions(e){this.selected&&(Object.assign(this._options,{...this._options,...e}),this.state="updating",this.requestUpdate())}containPoint(e){const t=this._paneViews[0]?.brushPaneRenderer;if(!t)return!1;const i=t.smoothPoints.length>0?t.smoothPoints:t.getSmoothPoints(),s=xe()?this._options.touchNealDrawThreshold:this._options.nealDrawThreshold;return void 0!==i.find(t=>{const i=De(t,e);return null!==i&&i<=s})}selectedDraw(){this.selected=!0,this.selectCandidate=!0,this.drawingTool.runtime.setSelectedDrawOptions(this._options,ae.Brush)}getPoints(){return this.drawPoints}}class xt extends fe{type=ae.Brush;chart;series;options;runtime;persistence;brushes=[];boundingPoints=[];isMouseDown=!1;drawVisible=!0;primitiveUpdateScheduler=Ue();drawingUpdateScheduler;cursorScheduler=Be();pendingCreateOperations=new Set;unbindEvents;localRuntimeState={drawMode:ae.None,lockAllDraw:!1,selectedDrawMode:null,selectedDrawOptions:void 0};handleVisibleRangeChange=()=>{this.primitiveUpdateScheduler.schedule(this.brushes)};trackPendingCreate(e,t){const i=t.then(t=>{t&&(e.id=t.id,e.createdAt=t.created_at,e.state!==le.New?e.state===le.Updating&&this.checkUpdateDraw():e.state=le.Clean)}).finally(()=>{this.pendingCreateOperations.delete(i)});this.pendingCreateOperations.add(i)}constructor({chart:e,series:t,options:i,isDark:s,runtime:r,persistence:o}){super(),this.chart=e,this.series=t,this.options={...ue(s),...i},this.runtime=r??{getDrawMode:()=>this.localRuntimeState.drawMode,setDrawMode:e=>{this.localRuntimeState.drawMode=e},getLockAllDraw:()=>this.localRuntimeState.lockAllDraw,clearSelectedDrawing:()=>{this.localRuntimeState.selectedDrawMode=null,this.localRuntimeState.selectedDrawOptions=void 0},setSelectedDrawOptions:(e,t)=>{if(null===t)return this.localRuntimeState.selectedDrawMode=null,void(this.localRuntimeState.selectedDrawOptions=void 0);this.localRuntimeState.selectedDrawMode=t,this.localRuntimeState.selectedDrawOptions={...e}},getSelectedTimeFrame:()=>ce.OneMinute,getChartDataTimes:()=>[],getChartControlStateChangesLog:()=>[]},this.persistence=o??{createDrawing:async()=>null,updateDrawing:async()=>{},deleteDrawing:async()=>{}},this.drawingUpdateScheduler=Je(()=>this.brushes,this.persistence.updateDrawing,e=>({brush:e.getPersistedBrushData(this.runtime.getSelectedTimeFrame())??void 0,width:e._options.strokeWidth,color:e._options.strokeColor})),this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.subscribeEvents()}subscribeEvents(){this.unbindEvents=Qe({chart:this.chart,onClick:this.onClick,onCrosshairMove:this.onMouseMove,onVisibleRangeChange:this.handleVisibleRangeChange,onMouseDown:this.handleMouseDown,onMouseUp:this.handleMouseUp,onContextMenu:this.handleContextMenu,onTouchStart:this.handleTouchStart,onTouchMove:this.handleTouchMove,onTouchEnd:this.handleTouchEnd})}unsubscribeEvents(){this.unbindEvents?.(),this.unbindEvents=void 0}handleTouchStart=e=>{if(0===e.touches.length)return;this.chart.clearCrosshairPosition();const t=e.touches[0],i=ze(this.chart,t);qe(this.brushes,i),this.isDrawing()&&this.startBrushStroke(i),e.preventDefault()};handleTouchMove=e=>{if(0===e.touches.length)return;const t=e.touches[0],i=ze(this.chart,t);this.onMouseMove(We(this.chart,i)),e.preventDefault()};handleTouchEnd=()=>{$e(this.brushes),this.checkUpdateDraw(),this.isMouseDown=!1,this.isDrawing()&&this.finalizeBrushStroke()};handleMouseDown=e=>{const t=Ne(this.chart,e),{x:i,y:s}=t;Ke({primitives:this.brushes,isDrawing:this.isDrawing(),isPointerHit:e=>e.containPoint({x:i,y:s}),clearSelection:()=>this.unSelectAnyDraw()}),qe(this.brushes,{x:i,y:s}),this.isDrawing()&&this.startBrushStroke(t)};handleMouseUp=()=>{$e(this.brushes),this.checkUpdateDraw(),this.isMouseDown=!1,this.isDrawing()&&this.finalizeBrushStroke()};handleContextMenu=e=>{const t=Ne(this.chart,e),{x:i,y:s}=t;if(je(this.brushes,e=>e.containPoint({x:i,y:s}))){this.unSelectAnyDraw();const t=this.brushes.find(e=>e.containPoint({x:i,y:s}));t&&(t.selected=!0,this.runtime.setSelectedDrawOptions({strokeWidth:t._options.strokeWidth,strokeColor:t._options.strokeColor},ae.Brush)),e.preventDefault(),e.stopPropagation()}};isDrawing(){return this.runtime.getDrawMode()===ae.Brush}startDrawing(){this.runtime.setDrawMode(ae.Brush)}stopDrawing(){this.boundingPoints=[],this.runtime.setDrawMode(ae.None)}onClick(e){e.point&&e.time}onMouseMove(e){this.brushes.forEach(t=>{t.onMouseMove(e)}),this.mouseStyling();const t=this.brushes.some(e=>e.selected);if(!this.isMouseDown||t)return;const{time:i,point:s}=e;if(i&&s){const e=Ie(this.chart,this.series,s);if(!e)return;this.handleBoundingPoints(e);const t=this.brushes[this.brushes.length-1],i=t.drawPoints[t.drawPoints.length-1];if(i&&i.time===e.time&&i.price===e.price)return;const r=t.drawPoints[t.drawPoints.length-1]?.price;if(r&&Math.abs(r-e.price)<0)return;t.addPoint(e)}}startBrushStroke(e){const t=Ie(this.chart,this.series,e);if(!t)return;if(this.boundingPoints.push({...t}),this.boundingPoints.push({...t}),this.isMouseDown=!0,this.brushes.some(e=>e.selected))return;const i=new Pt({state:"new",drawPoints:[t],drawingTool:this,boundingPoints:this.boundingPoints});He(this.series,this.brushes,i),this.chart.applyOptions({handleScroll:!1})}finalizeBrushStroke(){this.chart.applyOptions({handleScroll:!0});const e=this.brushes[this.brushes.length-1];if(e){e.selectedDraw();const t=mt(e.drawPoints,this.runtime.getSelectedTimeFrame());t&&this.trackPendingCreate(e,Ze(this.persistence.createDrawing,we.Brush,{brush:t,width:e._options.strokeWidth,color:e._options.strokeColor}))}this.stopDrawing()}handleBoundingPoints({price:e,time:t}){const i=this.boundingPoints,s=i[0],r=i[1],o=$(s),n=$(r),a=t,l=s.time,c=r.time;a<l&&(o.time=t),a>c&&(n.time=t),e>s.price&&(o.price=e),e<r.price&&(n.price=e),i[0].price=o.price,i[0].time=o.time,i[1].price=n.price,i[1].time=n.time}getInitBoundingPoints(e){if(0===e.length)return;const t=$(e[0]),i=$(e[0]);for(const s of e){const e=s.time,r=t.time,o=i.time;e<r&&(t.time=s.time),e>o&&(i.time=s.time),s.price>t.price&&(t.price=s.price),s.price<i.price&&(i.price=s.price)}return[t,i]}initData(e){e&&0!==e.length&&e.forEach(e=>{const{data:t}=e;if(!t.points||0===t.points.length)return;const i=$(t.points),s=this.getInitBoundingPoints(i);if(!s)return;const r=t.selected||!1,o=new Pt({drawPoints:i,boundingPoints:s,brushData:t.brush,id:e.id,drawingTool:this,createdAt:t.createdAt,options:t.options,selected:r,state:"clean"});this.series.attachPrimitive(o),this.brushes.push(o),2===t.brush?.version&&o.syncBrushDataDerivedState(),r&&o.selectedDraw()})}checkUpdateDraw(){this.drawingUpdateScheduler.schedule()}toggleDrawVisible(){this.drawVisible=et(this.drawVisible,this.brushes,this.primitiveUpdateScheduler)}toggleSelectedDrawLocked(){tt(this.brushes)&&this.checkUpdateDraw()}toggleAllDrawLocked(e){it(this.brushes,e)&&this.checkUpdateDraw()}isAnyDrawSelected(){return st(this.brushes)}updateSelectedOptions(e){this.brushes.forEach(t=>{t.updateSelectedOptions({...t._options,...e})}),this.checkUpdateDraw()}async flushPendingUpdates(){this.pendingCreateOperations.size>0&&await Promise.allSettled([...this.pendingCreateOperations]),await this.drawingUpdateScheduler.flush()}mouseStyling(){const e=this.brushes.some(e=>e.hovered);this.cursorScheduler.setCursor(e?"pointer":"default")}unSelectAnyDraw(){rt(this.brushes,this.runtime.clearSelectedDrawing)}cleanPrimitives(){this.brushes=ot(this.series,this.brushes,this.runtime.clearSelectedDrawing)}cleanAll(){this.unsubscribeEvents(),this.primitiveUpdateScheduler.cancel(),this.drawingUpdateScheduler.cancel(),this.isMouseDown=!1,this.boundingPoints=[],this.chart.applyOptions({handleScroll:!0}),this.cursorScheduler.reset(),this.cleanPrimitives()}async removeSelectedDraw(){this.brushes=await nt(this.series,this.brushes,e=>this.persistence.deleteDrawing(e))}}class yt{source;centerRenderer;constructor(e){this.source=e,this.centerRenderer=new Le({source:e,style:{strokeColor:this.source._options.strokeColor??"blue",radius:4}})}draw(e){this.source.drawingTool.drawVisible&&e.useBitmapCoordinateSpace(e=>{const t=this.source._p1,i=this.source._options,s=e.context,r=this.source.textValue.split(/\r?\n/),o=this.source.chart.timeScale().timeToCoordinate(t.time),n=this.source.series.priceToCoordinate(t.price);s.textAlign="left",s.textBaseline="top";const a=i.textSize*e.verticalPixelRatio;s.font=`${a}px Open Sans`,s.fillStyle=i.textColor,this.centerRenderer.style.strokeColor=this.source._options.textColor;const l=.2*i.textSize,c=i.textSize+l,d=r.map(t=>s.measureText(t||" ").width/e.horizontalPixelRatio),u=Math.max(...d),p=i.textSize+(r.length-1)*c,w=o+u+8,m=n+p+8;this.source._p2={time:this.source.chart.timeScale().coordinateToTime(w),price:this.source.series.coordinateToPrice(m)},r.forEach((t,i)=>{const r=(o+4)*e.horizontalPixelRatio,a=(n+4+i*c)*e.verticalPixelRatio;s.fillText(t,r,a)}),(this.source.hovered||this.source.selected)&&this.centerRenderer.draw(e,(o+w)/2,m+c/3)})}}class ft{source;textPaneRenderer;dynamicZOrder="normal";constructor(e){this.source=e,this.textPaneRenderer=new yt(e)}renderer(){return this.textPaneRenderer}zOrder(){return this.dynamicZOrder}}class _t extends ye{_paneViews;hoverCandidate=!1;hovered=!1;selectCandidate=!1;selected=!1;id;localId;createdAt;state;drawingTool;textValue;dragPoint;cornerPointBeforeDrag;constructor({textValue:e,cornerPoint:t,drawingTool:i,state:s,id:r,createdAt:o,selected:n,options:a}){super(),this.id=r,this.createdAt=o||Date.now(),this.localId=i.type+"-"+this.createdAt,this.state=s||"new",this.drawingTool=i,this.textValue=e,this.selected=n||!1,this._paneViews=[new ft(this)],this._options=$({...i.options,...a}),this._p1=t}paneViews(){return this._paneViews}containTimePoint(e){let t=!1;if(this._p1.time&&this._p2.time){const i=this._p1.time,s=this._p2.time,r=this._p1.price,o=this._p2.price,n=e.time,a=e.price;t=n>=i&&n<=s&&(a<=r&&a>=o)}if(this._p1.time&&!this._p2.time){const i=e.time>=this._p1.time,s=e.price<=this._p1.price&&e.price>=this._p2.price;t=i&&s}return t}onMouseMove(e){const{time:t,point:i}=e;if(this._options.locked||this.drawingTool.runtime.getLockAllDraw()||!i||!t)return;const s=this.series.coordinateToPrice(i.y),r=this.containTimePoint({time:t,price:s}),o=this.hoverCandidate,n=this.hovered;this.hoverCandidate=r,r||(this.hovered=r);const a=this.handleDrag(i),l=o!==this.hoverCandidate||n!==this.hovered;(a||l)&&this.requestUpdate()}onMouseDown(e){this.dragPoint=e,this.cornerPointBeforeDrag=$(this._p1);const t={time:this.chart.timeScale().coordinateToTime(e.x),price:this.series.coordinateToPrice(e.y)};this.containTimePoint(t)?(this.selectCandidate=!0,this.chart.applyOptions({handleScroll:!1})):(this.selectCandidate=!1,this.selected=!1,this.hovered=!1,this.hoverCandidate=!1)}onMouseUp(){this.selectCandidate&&!this.selected&&this.selectedDraw(),this.dragPoint=void 0,this.hovered=!1,this.hoverCandidate=!1,this.selectCandidate=!1,this.chart.applyOptions({handleScroll:!0}),this.requestUpdate()}handleDrag(e){let t=!1;if(this.selected&&this.dragPoint&&this.cornerPointBeforeDrag){const i=e.x-this.dragPoint.x,s=e.y-this.dragPoint.y,r=this.chart.timeScale().timeToCoordinate(this.cornerPointBeforeDrag.time),o=this.series.priceToCoordinate(this.cornerPointBeforeDrag.price);if(null===r||null===o)return!1;const n={time:this.chart.timeScale().coordinateToTime(r+i),price:this.series.coordinateToPrice(o+s)};if(!n.time||!n.price)return!1;if(this._p1.time===n.time&&this._p1.price===n.price)return!1;this._p1.price=n.price,this._p1.time=n.time,this.state="updating",t=!0}return t}selectedDraw(){this.selected=!0,this.selectCandidate=!0,this.drawingTool.runtime.setSelectedDrawOptions(this._options,ae.Text)}getPoints(){return[this._p1]}updateSelectedOptions(e){this.selected&&(Object.assign(this._options,{...this._options,...e}),this.state="updating",this.requestUpdate())}}class St extends fe{type=ae.Text;chart;series;options;runtime;persistence;texts=[];textArea=null;currentText="";currentCorner;isMouseDown=!1;drawVisible=!0;primitiveUpdateScheduler=Ue();drawingUpdateScheduler;pendingCreateOperations=new Set;unbindEvents;ownsTextArea=!1;localRuntimeState={drawMode:ae.None,lockAllDraw:!1,selectedDrawMode:null,selectedDrawOptions:void 0};handleVisibleRangeChange=()=>{this.primitiveUpdateScheduler.schedule(this.texts)};buildTextPayload(e,t,i=this.options.textColor){return{cornerPoint:Xe([e])[0],value:t,color:i}}trackPendingCreate(e,t){const i=t.then(t=>{t&&(e.id=t.id,e.createdAt=t.created_at,e.state!==le.New?e.state===le.Updating&&this.checkUpdateDraw():e.state=le.Clean)}).finally(()=>{this.pendingCreateOperations.delete(i)});this.pendingCreateOperations.add(i)}ensureTextAreaElement(){const e=document.getElementById("textarea-tool");if(e)return this.ownsTextArea=!1,e;const t=document.createElement("textarea");t.id=`textarea-tool-${Date.now()}-${Math.floor(1e3*Math.random())}`,t.style.display="none",t.style.position="absolute",t.style.zIndex="9999",t.style.minWidth="200px",t.style.minHeight="60px",t.style.padding="8px",t.style.fontSize="14px",t.style.border="1px solid #ccc",t.style.borderRadius="4px",t.style.background="white",t.style.color="black",t.style.opacity="0.6";return(this.chart.chartElement().parentElement??this.chart.chartElement()).appendChild(t),this.ownsTextArea=!0,t}constructor({chart:e,series:t,options:i,isDark:s,runtime:r,persistence:o,textArea:n}){super(),this.chart=e,this.series=t,this.options={...ue(s),...i},this.runtime=r??{getDrawMode:()=>this.localRuntimeState.drawMode,setDrawMode:e=>{this.localRuntimeState.drawMode=e},getLockAllDraw:()=>this.localRuntimeState.lockAllDraw,clearSelectedDrawing:()=>{this.localRuntimeState.selectedDrawMode=null,this.localRuntimeState.selectedDrawOptions=void 0},setSelectedDrawOptions:(e,t)=>{if(null===t)return this.localRuntimeState.selectedDrawMode=null,void(this.localRuntimeState.selectedDrawOptions=void 0);this.localRuntimeState.selectedDrawMode=t,this.localRuntimeState.selectedDrawOptions={...e}},getSelectedTimeFrame:()=>ce.OneMinute,getChartDataTimes:()=>[],getChartControlStateChangesLog:()=>[]},this.persistence=o??{createDrawing:async()=>null,updateDrawing:async()=>{},deleteDrawing:async()=>{}},this.drawingUpdateScheduler=Je(()=>this.texts,this.persistence.updateDrawing,e=>this.buildTextPayload(e._p1,e.textValue,e._options.textColor)),this.textArea=n??this.ensureTextAreaElement(),this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.subscribeEvents()}subscribeEvents(){this.unbindEvents=Qe({chart:this.chart,onClick:this.onClick,onCrosshairMove:this.onMouseMove,onVisibleRangeChange:this.handleVisibleRangeChange,onMouseDown:this.handleMouseDown,onMouseUp:this.handleMouseUp,onContextMenu:this.handleContextMenu,onTouchStart:this.handleTouchStart,onTouchMove:this.handleTouchMove,onTouchEnd:this.handleTouchEnd,textArea:this.textArea,onTextAreaChange:this.handleTextAreaChange,onTextAreaBlur:this.handleTextAreaBlur})}unsubscribeEvents(){this.unbindEvents?.(),this.unbindEvents=void 0}handleTouchStart=e=>{if(0===e.touches.length)return;this.chart.clearCrosshairPosition();const t=e.touches[0],i=ze(this.chart,t);qe(this.texts,i),e.preventDefault()};handleTouchMove=e=>{if(0===e.touches.length)return;const t=e.touches[0],i=ze(this.chart,t);this.onMouseMove(We(this.chart,i)),e.preventDefault()};handleTouchEnd=e=>{if(0===e.changedTouches.length)return;const t=e.changedTouches[0],i=ze(this.chart,t),s=this.chart.timeScale().coordinateToTime(i.x);if(this.textArea&&this.isDrawing()&&this.currentText){const e=document.elementFromPoint(t.clientX,t.clientY);if(!this.textArea.contains(e))return void this.addNewText()}s&&this.isDrawing()&&this.onClick(We(this.chart,i)),this.drawVisible&&(this.chart.applyOptions({handleScroll:!0}),$e(this.texts),this.checkUpdateDraw())};handleMouseDown=e=>{const t=Ne(this.chart,e),{x:i,y:s}=t;if(qe(this.texts,{x:i,y:s}),!this.textArea)return;const r=!this.textArea?.contains(e.target);!this.textArea&&this.isDrawing()&&r&&this.currentText&&this.addNewText()};handleMouseUp=()=>{this.drawVisible&&(this.chart.applyOptions({handleScroll:!0}),$e(this.texts),this.checkUpdateDraw())};handleContextMenu=e=>{const t=Ne(this.chart,e),{x:i,y:s}=t;if(je(this.texts,e=>e.containPoint({x:i,y:s}))){this.unSelectAnyDraw();const t=this.texts.find(e=>e.containPoint({x:i,y:s}));t&&(t.selected=!0,this.runtime.setSelectedDrawOptions({strokeColor:t._options.strokeColor},ae.Text)),e.preventDefault(),e.stopPropagation()}};handleTextAreaChange=e=>{this.currentText=e.target.value};handleTextAreaBlur=()=>{this.addNewText(),this.checkUpdateDraw()};addNewText(){const e=this.currentCorner?.price,t=this.currentCorner?.time;if(!e||!t)return;const i=new _t({textValue:this.currentText,cornerPoint:{time:t,price:e},drawingTool:this,state:"new"});Ye(this.series,this.texts,i),this.trackPendingCreate(i,Ze(this.persistence.createDrawing,we.Text,this.buildTextPayload({time:t,price:e},this.currentText,i._options.textColor))),this.stopDrawing()}isDrawing(){return this.runtime.getDrawMode()===ae.Text}startDrawing(){this.runtime.setDrawMode(ae.Text)}stopDrawing(){this.currentText="",this.currentCorner=void 0,this.textArea&&(this.textArea.style.display="none",this.textArea.value=""),this.runtime.setDrawMode(ae.None)}onClick(e){if(!e.point||!e.time||!this.isDrawing())return;if(this.isAnyDrawSelected())this.textArea&&(this.textArea.style.display="none");else if(this.textArea){const t=Ie(this.chart,this.series,e.point);if(!t)return;this.currentCorner=t,this.textArea.style.left=`${e.point.x}px`,this.textArea.style.top=`${e.point.y}px`,this.textArea.style.display="block",this.textArea.focus()}}onMouseMove(e){0!==this.texts.length&&this.drawVisible&&this.texts.forEach(t=>{t.onMouseMove(e)})}initData(e){e&&0!==e.length&&e.forEach(e=>{const{data:t}=e;if(!t.cornerPoint||!t.value)return;const i=t.selected||!1,s=new _t({id:e.id,textValue:t.value,cornerPoint:t.cornerPoint,drawingTool:this,createdAt:t.createdAt,options:t.options,selected:i,state:"clean"});i&&s.selectedDraw(),this.series.attachPrimitive(s),this.texts.push(s)})}checkUpdateDraw(){this.drawingUpdateScheduler.schedule()}toggleDrawVisible(){this.drawVisible=et(this.drawVisible,this.texts,this.primitiveUpdateScheduler)}toggleSelectedDrawLocked(){tt(this.texts)&&this.checkUpdateDraw()}toggleAllDrawLocked(e){it(this.texts,e)&&this.checkUpdateDraw()}isAnyDrawSelected(){return st(this.texts)}updateSelectedOptions(e){this.texts.forEach(t=>{t.updateSelectedOptions({...t._options,...e})}),this.checkUpdateDraw()}async flushPendingUpdates(){this.pendingCreateOperations.size>0&&await Promise.allSettled([...this.pendingCreateOperations]),await this.drawingUpdateScheduler.flush()}unSelectAnyDraw(){rt(this.texts,this.runtime.clearSelectedDrawing)}cleanPrimitives(){this.texts=ot(this.series,this.texts,this.runtime.clearSelectedDrawing)}cleanAll(){this.unsubscribeEvents(),this.primitiveUpdateScheduler.cancel(),this.drawingUpdateScheduler.cancel(),this.chart.applyOptions({handleScroll:!0}),document.body.style.cursor="default",this.cleanTextArea(),this.cleanPrimitives()}async removeSelectedDraw(){this.texts=await nt(this.series,this.texts,e=>this.persistence.deleteDrawing(e))}cleanTextArea(){this.textArea&&(this.textArea.style.display="none",this.textArea.value="",this.currentText="",this.currentCorner=void 0,this.ownsTextArea&&(this.textArea.remove(),this.textArea=null,this.ownsTextArea=!1))}}const Ct=(e,t)=>(e=>"object"==typeof e&&null!==e)(e)&&"function"==typeof e[t],Tt=e=>e.value,kt=e=>null===e?null:e,Mt=e=>null===e?null:e,At=s=>{const r=e(ae.None),o=e(!1),n=e(!0),a=e(null),l=e(void 0),c=new Map,d=e(0),u=()=>{a.value=null,l.value=void 0},p=()=>{c.forEach(e=>{e.unSelectAnyDraw()}),u()},w=(e,t)=>{c.get(e)?.cleanAll(),c.set(e,t),d.value+=1},m=e=>c.get(e),g=e=>{c.forEach((t,i)=>e(t,i))},v={getDrawMode:()=>Mt(r.value)??ae.None,setDrawMode:e=>{r.value=kt(e)??ae.None},getLockAllDraw:()=>o.value,clearSelectedDrawing:()=>{u()},setSelectedDrawOptions:(e,t=Mt(a.value))=>{e&&null!==t?(a.value=kt(t),l.value={...e}):u()},getSelectedTimeFrame:()=>Tt(s.selectedTimeFrame),getChartDataTimes:()=>Tt(s.chartDataTimes),getChartControlStateChangesLog:()=>[]},D=i(()=>(d.value,{line:m(ae.Line),brush:m(ae.Brush),text:m(ae.Text)})),b=async()=>{const e=[];c.forEach(t=>{e.push(t.flushPendingUpdates())}),e.length>0&&await Promise.allSettled(e)},P=()=>{c.forEach(e=>{e.cleanAll()}),c.clear(),d.value+=1,r.value=ae.None,u()},x=()=>{const t=Tt(s.chart),i=Tt(s.series);if(!(r=t,Ct(r,"subscribeClick")&&Ct(r,"unsubscribeClick")&&Ct(r,"subscribeCrosshairMove")&&Ct(r,"unsubscribeCrosshairMove")&&Ct(r,"timeScale")&&(e=>Ct(e,"attachPrimitive")&&Ct(e,"detachPrimitive")&&Ct(e,"priceToCoordinate")&&Ct(e,"coordinateToPrice"))(i)))return;var r;const a=t,l=i,d={priceLabelFormatter:e=>e.toFixed(2)};w(ae.Line,new at({chart:a,series:l,options:d,isDark:Tt(s.isDark??e(void 0)),runtime:v,persistence:s.persistence})),w(ae.Brush,new xt({chart:a,series:l,options:d,isDark:Tt(s.isDark??e(void 0)),runtime:v,persistence:s.persistence})),w(ae.Text,new St({chart:a,series:l,options:d,isDark:Tt(s.isDark??e(void 0)),runtime:v,persistence:s.persistence})),(()=>{const e=Array.from(c.values());n.value||e.forEach(e=>e.toggleDrawVisible()),o.value&&e.forEach(e=>e.toggleAllDrawLocked(!0))})()},y={line:ae.Line,brush:ae.Brush,text:ae.Text},f=e=>(e??[]).flatMap(e=>{const t=ht(e.time);return null===t?[]:[{time:t,price:e.price}]}),_=(e,t)=>{const i={..."number"==typeof e.data?.width?{strokeWidth:e.data.width}:{},..."string"==typeof e.data?.color?"text"===e.draw_type?{textColor:e.data.color}:{strokeColor:e.data.color}:{}},r=Object.keys(i).length?i:void 0;if("brush"===e.draw_type){const i=f(e.data?.points),o=e.data?.brush,n=2===o?.version?(()=>{const e=ht(o.anchorPoint.time);return null===e?null:{...o,anchorPoint:{...o.anchorPoint,time:e}}})():mt(i,((e,t=ce.OneMinute)=>{const i=wt(e),s=[...new Set(i.map(e=>e.time))].sort((e,t)=>e-t),r=s.slice(1).map((e,t)=>e-s[t]).filter(e=>e>0);if(!r.length)return t;const o=Math.min(...r);return ut.reduce((e,t)=>{const i=Math.floor(lt(t)/1e3);return Math.abs(i-o)<Math.abs(Math.floor(lt(e)/1e3)-o)?t:e},t)})(i,Tt(s.selectedTimeFrame))),a=n?vt(n,t,Tt(s.selectedTimeFrame)):null;return{id:e.id,Login:e.user_id,symbol:e.symbol,draw_type:y[e.draw_type],data:{points:a?.points,brush:a?{version:a.version,anchorPoint:a.anchorPoint,mountedAnchorPoint:a.mountedAnchorPoint,baseInterval:a.baseInterval,relativePoints:a.relativePoints}:void 0,value:e.data?.value,options:r,createdAt:e.created_at}}}const o=((e,t)=>e.length&&t.length?e.map(e=>dt(e,t)):e)(f(e.data?.points),t);return{id:e.id,Login:e.user_id,symbol:e.symbol,draw_type:y[e.draw_type],data:{points:o,value:e.data?.value,options:r,cornerPoint:e.data?.cornerPoint?dt({time:ht(e.data.cornerPoint.time)??e.data.cornerPoint.time,price:e.data.cornerPoint.price},t):o[0],createdAt:e.created_at}}},S=e=>{const t=m(ae.Line),i=m(ae.Brush),r=m(ae.Text),o=Tt(s.chartDataTimes);t?.cleanPrimitives(),i?.cleanPrimitives(),r?.cleanPrimitives();const n=e.map(e=>_(e,o)),a=n.filter(e=>e.draw_type===ae.Line),l=n.filter(e=>e.draw_type===ae.Brush),c=n.filter(e=>e.draw_type===ae.Text);t?.initData(a),i?.initData(l),r?.initData(c)},C=async()=>{Tt(s.symbol)?(await b(),await s.loadDrawings(),S(Tt(s.drawings))):S([])},T={setDrawMode:e=>{r.value=e},setLockAllDraw:e=>{o.value=e,g(t=>{t.toggleAllDrawLocked(e)})},setDrawVisible:e=>{n.value!==e&&(n.value=e,g(e=>{e.toggleDrawVisible()}))},clearSelectedDrawing:()=>{p()},setSelectedDrawOptions:(e,t)=>{e&&null!==t?(a.value=t,l.value={...e}):u()},deleteAllDrawings:async()=>{await s.deleteAllDrawings(),g(e=>{e.stopDrawing(),e.cleanPrimitives()}),r.value=ae.None,u()}},k=i(()=>{const e=Tt(s.chartDataTimes);return e.length?`${e[0]}-${e[e.length-1]}-${e.length}`:"0"});return t([()=>Tt(s.chart),()=>Tt(s.series)],async()=>{await b(),P(),x(),await C()},{immediate:!0}),t(()=>Tt(s.symbol),async(e,t)=>{e!==t&&await C()}),t([()=>Tt(s.selectedTimeFrame),k],()=>{0!==c.size&&S(Tt(s.drawings))}),t(()=>Tt(s.isDark??e(void 0)),async()=>{0!==c.size&&(await b(),P(),x(),S(Tt(s.drawings)))}),{drawMode:i(()=>r.value),lockAllDraw:i(()=>o.value),drawVisible:i(()=>n.value),selectedDrawMode:i(()=>a.value),selectedDrawOptions:i(()=>l.value),drawingTools:D,runtime:T,refreshDrawings:C,setDrawMode:e=>{const t=Mt(e)??ae.None,i=Mt(r.value)??ae.None;if(i!==ae.None&&m(i)?.stopDrawing(),t===ae.None||i===t)return void(r.value=ae.None);const s=m(t);s?(s.startDrawing(),r.value=t):r.value=ae.None},clearSelectedDrawing:p}},Lt=o({__name:"index",props:{chart:{},series:{},symbol:{},selectedTimeFrame:{},chartDataTimes:{},drawings:{},createDrawing:{},updateDrawing:{},deleteDrawing:{},loadDrawings:{},deleteAllDrawings:{},isDark:{type:Boolean},floatingTarget:{default:null},floatingLayerStyle:{default:()=>({})},showSidebar:{type:Boolean,default:!0},showFloatingToolbar:{type:Boolean,default:!0}},emits:["stateChange"],setup(e,{expose:s,emit:r}){const o=e,n=r,{drawMode:a,lockAllDraw:d,drawVisible:m,selectedDrawMode:v,selectedDrawOptions:b,drawingTools:P,runtime:y,refreshDrawings:_,setDrawMode:k,clearSelectedDrawing:M}=At({chart:S(o,"chart"),series:S(o,"series"),symbol:S(o,"symbol"),selectedTimeFrame:S(o,"selectedTimeFrame"),chartDataTimes:S(o,"chartDataTimes"),drawings:S(o,"drawings"),persistence:{createDrawing:o.createDrawing,updateDrawing:o.updateDrawing,deleteDrawing:o.deleteDrawing},loadDrawings:o.loadDrawings,deleteAllDrawings:o.deleteAllDrawings,isDark:S(o,"isDark")}),A=i(()=>o.showSidebar),L=i(()=>({position:"absolute",left:"0px",right:"0px",top:"0px",bottom:"0px",height:"auto",zIndex:20,...o.floatingLayerStyle??{}})),V=i(()=>C(o.floatingTarget)?o.floatingTarget.value:o.floatingTarget??null),E=i(()=>!!V.value),O=i(()=>!!o.showFloatingToolbar&&(!!V.value||!o.showSidebar)),R=i(()=>V.value??"body");return t([a,d,m,v,b],([e,t,i,s,r])=>{n("stateChange",{drawMode:e,lockAllDraw:t,drawVisible:i,selectedDrawMode:s,selectedDrawOptions:r})},{immediate:!0}),s({refreshDrawings:_,setDrawMode:k,clearSelectedDrawing:M}),(e,t)=>(l(),c(w,null,[A.value?(l(),D(ne,{key:0,"draw-mode":u(a),"lock-all-draw":u(d),"draw-visible":u(m),"selected-draw-mode":u(v),"selected-draw-options":u(b),"drawing-tools":u(P),runtime:u(y),"show-floating-toolbar":!1,"show-sidebar":!0},null,8,["draw-mode","lock-all-draw","draw-visible","selected-draw-mode","selected-draw-options","drawing-tools","runtime"])):x("",!0),O.value?(l(),D(T,{key:1,to:R.value,disabled:!E.value},[p("div",{class:"custom-drawing-overlay-widget__floating-layer",style:f(L.value)},[g(ne,{"draw-mode":u(a),"lock-all-draw":u(d),"draw-visible":u(m),"selected-draw-mode":u(v),"selected-draw-options":u(b),"drawing-tools":u(P),runtime:u(y),"show-floating-toolbar":!0,"show-sidebar":!1},null,8,["draw-mode","lock-all-draw","draw-visible","selected-draw-mode","selected-draw-options","drawing-tools","runtime"])],4)],8,["to","disabled"])):x("",!0)],64))}});export{K as D,Lt as _,At as a,Y as p,X as u};
1
+ import{ref as e,watch as t,computed as i,provide as s,inject as r,defineComponent as o,nextTick as n,onUnmounted as a,openBlock as l,createElementBlock as c,normalizeClass as d,unref as u,createElementVNode as p,Fragment as w,renderList as m,createVNode as g,withCtx as v,createBlock as D,resolveDynamicComponent as b,mergeProps as P,createCommentVNode as x,withModifiers as y,normalizeStyle as f,toDisplayString as _,toRef as S,isRef as C,Teleport as T}from"vue";import k from"../composite/EaeraDropdownV2.mjs";import{_ as M}from"./EaeraDivider-Dggvc36a.mjs";import{_ as A}from"./EaeraTooltip-BIlULHv4.mjs";import{Plus as L,Ruler as V,PenTool as E,Type as O,Lock as R,LockOpen as U,Eye as B,EyeOff as F,Trash as N,GripVertical as z,PenLine as W}from"@lucide/vue";import{useI18n as I}from"vue-i18n";import"element-plus";import"element-plus/es";import"./vendor-email-misspelled-0hsXkSSK.mjs";import"./vendor-unorm-Degftfa1.mjs";import"./useEaeraInputPhoneNumber-B72aLnQs.mjs";import"@element-plus/icons-vue";import{_ as q}from"./EaeraColorPicker-BmBd0tPb.mjs";import"echarts/core";import"echarts/renderers";import"echarts/charts";import"echarts/components";import"vue-echarts";import"./vendor-currency-symbol-map-C-1fEG2R.mjs";import"./vendor-sortablejs-D3DyHO5Y.mjs";import{c as $}from"./vendor-es-toolkit-D-WXci__.mjs";import{i as j}from"./vendor-lodash-es-DUTj3yNB.mjs";const K={Brush:"brush",Line:"line",Text:"text",OrderLine:"order-line",None:"none"},H=Symbol("EAERA_DRAWING_OVERLAY_CONTEXT_KEY"),Y=(r,o)=>{const n=e(r.drawMode??K.None),a=e(r.lockAllDraw??!1),l=e(r.drawVisible??!0),c=e(r.selectedDrawMode??null),d=e(r.selectedDrawOptions);t(()=>r.drawMode,e=>{void 0!==e&&(n.value=e)}),t(()=>r.lockAllDraw,e=>{"boolean"==typeof e&&(a.value=e)}),t(()=>r.drawVisible,e=>{"boolean"==typeof e&&(l.value=e)}),t(()=>r.selectedDrawMode,e=>{void 0!==e&&(c.value=e)}),t(()=>r.selectedDrawOptions,e=>{d.value=e});const u=i(()=>({drawMode:n.value,lockAllDraw:a.value,drawVisible:l.value,selectedDrawMode:c.value,selectedDrawOptions:d.value}));t(u,e=>{o("stateChange",e)},{immediate:!0});const p={drawMode:i(()=>n.value),lockAllDraw:i(()=>a.value),drawVisible:i(()=>l.value),selectedDrawMode:i(()=>c.value),selectedDrawOptions:i(()=>d.value),showFloatingToolbar:i(()=>r.showFloatingToolbar??!0),showSidebar:i(()=>r.showSidebar??!0),drawingTools:i(()=>r.drawingTools??{}),state:u,onSetDrawMode:e=>{n.value=e,r.runtime?.setDrawMode&&r.runtime.setDrawMode(e),o("setDrawMode",e)},onToggleLockAll:e=>{a.value=e,r.runtime?.setLockAllDraw&&r.runtime.setLockAllDraw(e),o("toggleLockAll",e)},onToggleVisible:e=>{l.value=e,r.runtime?.setDrawVisible&&r.runtime.setDrawVisible(e),o("toggleVisible",e)},onDeleteAllDrawings:()=>{r.runtime?.deleteAllDrawings?.(),o("deleteAllDrawings")},onUpdateSelectedDrawOptions:(e,t=c.value)=>{c.value=t,d.value=e,r.runtime?.setSelectedDrawOptions?r.runtime.setSelectedDrawOptions(e,t):!r.runtime?.clearSelectedDrawing||e&&null!==t||r.runtime.clearSelectedDrawing(),o("updateSelectedDrawOptions",e,t)},onToggleSelectedLocked:()=>{const e=d.value;if(!e)return;const t={...e,locked:!e.locked};d.value=t,r.runtime?.setSelectedDrawOptions&&r.runtime.setSelectedDrawOptions(t,c.value),o("toggleSelectedLocked",t,c.value)},onDeleteSelectedDrawing:()=>{r.runtime?.clearSelectedDrawing?.(),o("deleteSelectedDrawing")}};return s(H,p),p},X=()=>{const e=r(H);if(!e)throw new Error("useEaeraDrawingOverlay must be used inside EaeraDrawingOverlayPanel");return e},Z={key:0,class:"custom-drawing-overlay__sidebar"},G={class:"custom-drawing-overlay__tools"},J=["onClick"],Q=["onClick"],ee={key:0,class:"custom-drawing-overlay__stroke-width"},te={class:"custom-drawing-overlay__stroke-width-trigger"},ie={class:"custom-drawing-overlay__stroke-width-value"},se={class:"custom-drawing-overlay__stroke-width-dropdown"},re=["onClick"],oe={class:"custom-drawing-overlay__stroke-width-option-label"},ne=o({__name:"EaeraDrawingOverlayPanel",props:{drawMode:{},lockAllDraw:{type:Boolean},drawVisible:{type:Boolean},selectedDrawMode:{},selectedDrawOptions:{},showFloatingToolbar:{type:Boolean},showSidebar:{type:Boolean},drawingTools:{},runtime:{}},emits:["setDrawMode","toggleLockAll","toggleVisible","deleteAllDrawings","updateSelectedDrawOptions","toggleSelectedLocked","deleteSelectedDrawing","stateChange"],setup(s,{expose:r,emit:o}){const S=Y(s,o),{drawMode:C,lockAllDraw:T,drawVisible:$,selectedDrawMode:j,selectedDrawOptions:H,showFloatingToolbar:X,showSidebar:ne,drawingTools:ae,state:le,onSetDrawMode:he,onToggleLockAll:ce,onToggleVisible:de,onDeleteAllDrawings:ue,onUpdateSelectedDrawOptions:pe,onToggleSelectedLocked:we,onDeleteSelectedDrawing:me}=S,{t:ge}=I(),ve=[1,2,3,4,8],De=[K.Line,K.Brush,K.Text],be=i(()=>ve.map(e=>({value:e,label:`${e}px`}))),Pe=i(()=>H.value?.strokeWidth??null),xe=e=>e===K.Line?ae.value.line:e===K.Brush?ae.value.brush:e===K.Text?ae.value.text:void 0,ye=()=>De.map(e=>xe(e)).filter(e=>!!e),fe=e(),_e=e("#3b82f6"),Se=e(!1),Ce=i(()=>({tools:[{icon:{component:L,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.crosshair"),value:K.None},{icon:{component:V,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.line-tool"),value:K.Line},{icon:{component:E,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.brush-tool"),value:K.Brush},{icon:{component:O,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.text-tool"),value:K.Text}],modifier:[{icon:T.value?{component:R,props:{size:16,absoluteStrokeWidth:!0}}:{component:U,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.lock-drawings"),value:"lock"},{icon:$.value?{component:B,props:{size:16,absoluteStrokeWidth:!0}}:{component:F,props:{size:16,absoluteStrokeWidth:!0}},tooltip:ge("chart.tools.tooltip.hide-drawings"),value:"hide"}]})),Te=e=>"lock"===e?T.value:"hide"===e&&!$.value,ke=i(()=>j.value===K.Text&&!!H.value),Me=i(()=>j.value!==K.Text&&!!H.value?.strokeColor),Ae=i(()=>j.value===K.Line||j.value===K.Brush),Le=i(()=>!!H.value?.locked||T.value),Ve=i(()=>Me.value?H.value?.strokeColor:ke.value?H.value?.textColor:"#3b82f6"),Ee=e=>{pe(e,j.value),e&&ye().forEach(t=>{t.isAnyDrawSelected()&&t.updateSelectedOptions(e)})},Oe=e=>{const t=e||"#3b82f6";_e.value=t,(e=>{H.value&&(ke.value?Ee({...H.value,textColor:e}):Ee({...H.value,strokeColor:e}))})(t),Se.value=!1,fe.value?.hide()},Re=()=>{_e.value=Ve.value||"#3b82f6",Se.value?fe.value?.hide():fe.value?.show(),Se.value=!Se.value},Ue=()=>{T.value||(ye().forEach(e=>{e.isAnyDrawSelected()&&e.toggleSelectedDrawLocked()}),we())},Be=async()=>{const e=ye().map(e=>e.removeSelectedDraw());e.length>0&&await Promise.allSettled(e),pe(void 0,null),me()},Fe=e({x:0,y:60}),Ne=e({x:0,y:0}),ze=e(!1),We=e(!1),Ie=e(null),qe=e=>{Fe.value=e},$e=e=>{if(!Ie.value||0!==e.button)return;e.stopPropagation(),e.preventDefault();const t=Ie.value.getBoundingClientRect();Ne.value={x:e.clientX-t.left,y:e.clientY-t.top},ze.value=!0},je=e=>{if(!Ie.value)return;const t=e.touches[0];if(!t)return;const i=Ie.value.getBoundingClientRect();Ne.value={x:t.clientX-i.left,y:t.clientY-i.top},ze.value=!0,e.stopPropagation(),e.preventDefault()},Ke=e=>{if(!ze.value||!Ie.value)return;const t=Ie.value.parentElement;if(!t)return;const i=t.getBoundingClientRect(),s=Ie.value.getBoundingClientRect();let r=e.clientX-i.left-Ne.value.x,o=e.clientY-i.top-Ne.value.y;const n=i.width-s.width,a=i.height-s.height;r=Math.max(0,Math.min(r,n)),o=Math.max(0,Math.min(o,a)),qe({x:r,y:o})},He=e=>{if(!ze.value||!Ie.value)return;const t=e.touches[0];if(!t)return;const i=Ie.value.parentElement;if(!i)return;const s=i.getBoundingClientRect(),r=Ie.value.getBoundingClientRect();let o=t.clientX-s.left-Ne.value.x,n=t.clientY-s.top-Ne.value.y;e.preventDefault();const a=s.width-r.width,l=s.height-r.height;o=Math.max(0,Math.min(o,a)),n=Math.max(0,Math.min(n,l)),qe({x:o,y:n})},Ye=()=>{ze.value=!1},Xe=()=>{document.removeEventListener("mousemove",Ke),document.removeEventListener("mouseup",Ye,!0),document.removeEventListener("touchmove",He),document.removeEventListener("touchend",Ye,!0),document.removeEventListener("touchcancel",Ye,!0),window.removeEventListener("blur",Ye)};t(ze,e=>{e?(document.addEventListener("mousemove",Ke),document.addEventListener("mouseup",Ye,!0),document.addEventListener("touchmove",He,{passive:!1}),document.addEventListener("touchend",Ye,{passive:!1,capture:!0}),document.addEventListener("touchcancel",Ye,{passive:!1,capture:!0}),window.addEventListener("blur",Ye)):Xe()});return t(H,async e=>{e&&X.value&&!We.value&&(await n(),(()=>{if(!Ie.value)return;const e=Ie.value.parentElement;if(!e)return;const t=e.getBoundingClientRect(),i=Ie.value.getBoundingClientRect(),s=Math.max(0,t.width-i.width),r=Math.max(0,Math.min((t.width-i.width)/2,s));qe({x:r,y:60}),We.value=!0})()),e||(We.value=!1,ze.value=!1,Se.value=!1,fe.value?.hide())},{immediate:!0}),t(Ve,e=>{_e.value=e||"#3b82f6"},{immediate:!0}),a(()=>{Xe()}),r({state:le}),(e,t)=>{const i=A,s=M,r=k;return l(),c("div",{class:d(["custom-drawing-overlay",{"custom-drawing-overlay--floating-only":u(X)&&!u(ne)}])},[u(ne)?(l(),c("div",Z,[p("div",G,[(l(!0),c(w,null,m(Ce.value.tools,e=>(l(),c("div",{key:e.value,class:d(["custom-drawing-overlay__tool-item",{"is-active":u(C)===e.value}]),onClick:t=>(e=>{const t=C.value;t!==K.None&&xe(t)?.stopDrawing(),e!==K.None&&t!==e?(xe(e)?.startDrawing(),he(e)):he(K.None)})(e.value)},[g(i,{placement:"right",content:e.tooltip},{default:v(()=>[(l(),D(b(e.icon.component),P({ref_for:!0},e.icon.props),null,16))]),_:2},1032,["content"])],10,J))),128)),g(s,{direction:"horizontal",class:"custom-drawing-overlay__divider"}),(l(!0),c(w,null,m(Ce.value.modifier,e=>(l(),c("div",{key:e.value,class:d(["custom-drawing-overlay__tool-item","custom-drawing-overlay__tool-item--modifier",{"is-active":Te(e.value)}]),onClick:t=>(e=>{const t=ye();if("lock"===e){const e=!T.value;return ce(e),void t.forEach(t=>{t.toggleAllDrawLocked(e)})}if("hide"===e){const e=!$.value;de(e),$.value!==e&&t.forEach(e=>{e.toggleDrawVisible()})}})(e.value)},[g(i,{placement:"right",content:e.tooltip},{default:v(()=>[(l(),D(b(e.icon.component),P({ref_for:!0},e.icon.props),null,16))]),_:2},1032,["content"])],10,Q))),128)),g(s,{direction:"horizontal",class:"custom-drawing-overlay__divider"}),p("div",{class:"custom-drawing-overlay__tool-item",onClick:t[0]||(t[0]=(...e)=>u(ue)&&u(ue)(...e))},[g(i,{placement:"right",content:u(ge)("chart.tools.tooltip.delete-drawings")},{default:v(()=>[g(u(N),{size:24})]),_:1},8,["content"])])])])):x("",!0),u(X)&&u(H)?(l(),c("div",{key:1,ref_key:"toolbarRef",ref:Ie,class:d(["custom-drawing-overlay__floating-toolbar",{"custom-drawing-overlay__floating-toolbar--dragging":ze.value}]),style:f({left:`${Fe.value.x}px`,top:`${Fe.value.y}px`,touchAction:"none"}),onMousedown:t[2]||(t[2]=y(()=>{},["stop"])),onMouseup:y(Ye,["stop"]),onClick:t[3]||(t[3]=y(()=>{},["stop"])),onTouchstart:t[4]||(t[4]=y(()=>{},["stop"])),onTouchend:y(Ye,["stop"]),onTouchcancel:y(Ye,["stop"])},[p("div",{class:"custom-drawing-overlay__drag-handle",onMousedown:$e,onTouchstart:je},[g(u(z),{size:16,class:"custom-drawing-overlay__drag-icon"})],32),p("div",{class:"custom-drawing-overlay__color-trigger",onClick:Re},[g(u(W),{size:24}),p("div",{class:"custom-drawing-overlay__color-preview",style:f({backgroundColor:Ve.value})},null,4),g(u(q),{ref_key:"colorPickerRef",ref:fe,modelValue:_e.value,"onUpdate:modelValue":t[1]||(t[1]=e=>_e.value=e),class:"custom-drawing-overlay__color-picker",onChange:Oe},null,8,["modelValue"])]),u(H)?.strokeWidth&&Ae.value?(l(),c("div",ee,[g(r,{trigger:"click"},{dropdown:v(()=>[p("div",se,[(l(!0),c(w,null,m(be.value,e=>(l(),c("button",{key:e.value,type:"button",class:d(["custom-drawing-overlay__stroke-width-option",{"custom-drawing-overlay__stroke-width-option--active":Pe.value===e.value}]),onClick:t=>{return i=e.value,void(H.value&&Ee({...H.value,strokeWidth:i}));var i}},[p("span",{class:"custom-drawing-overlay__stroke-width-option-line",style:f({height:`${e.value}px`})},null,4),p("span",oe,_(e.label),1)],10,re))),128))])]),default:v(()=>[p("div",te,[p("div",{class:"custom-drawing-overlay__stroke-width-line",style:f({height:`${u(H)?.strokeWidth}px`})},null,4),p("p",ie,_(u(H)?.strokeWidth)+"px ",1)])]),_:1})])):x("",!0),p("button",{class:d(["custom-drawing-overlay__toolbar-action",{"custom-drawing-overlay__toolbar-action--active":Le.value}]),onClick:Ue},[g(u(N),{size:24})],2),p("button",{class:"custom-drawing-overlay__toolbar-action",onClick:Be},[g(u(N),{size:24})])],38)):x("",!0)],2)}}});var ae=(e=>(e.Brush="brush",e.Line="line",e.Text="text",e.OrderLine="order-line",e.None="none",e))(ae||{}),le=(e=>(e.None="none",e.Clean="clean",e.New="new",e.Updating="updating",e))(le||{}),he=(e=>(e.DrawUpdate="draw_update",e))(he||{}),ce=(e=>(e.OneMinute="1m",e.FiveMinutes="5m",e.FifteenMinutes="15m",e.ThirtyMinutes="30m",e.OneHour="1h",e.FourHours="4h",e.OneDay="1d",e.OneWeek="1w",e.OneMonth="1mn",e))(ce||{});const de=e=>{const t=(e=>{if("number"==typeof e)return new Date(1e3*e);if("string"==typeof e){const t=new Date(e);return Number.isNaN(t.getTime())?null:t}return(e=>{if(!e||"object"!=typeof e)return!1;const t=e;return"number"==typeof t.year&&"number"==typeof t.month&&"number"==typeof t.day})(e)?new Date(e.year,e.month-1,e.day):null})(e);return t?new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(t):""},ue=e=>{const t=(e=>e?{textPrimary:"#F0F1F3",stroke:"#A259FB",paneFill:"#A259FB4D"}:{textPrimary:"#0f1115",stroke:"#A259FB",paneFill:"#A259FB4D"})(e);return{labelTextColor:t.textPrimary,labelBackgroundColor:t.stroke,paneFillColor:t.paneFill,strokeColor:t.stroke,strokeWidth:2,showLabels:!0,showPanes:!0,textSize:14,textColor:t.stroke,locked:!1,nealDrawThreshold:5,touchNealDrawThreshold:20,priceLabelFormatter:e=>e.toFixed(2),timeLabelFormatter:e=>de(e)}},pe={strokeColor:"#ef4444",fillColor:"white",strokeWidth:1,radius:4,touchRadius:12};var we=(e=>(e.Line="line",e.Brush="brush",e.Text="text",e))(we||{});function me(e,t){if(void 0===e)throw new Error("Value is undefined");return e}function ge(e,t){return t-e.getBoundingClientRect().y}function ve(e,t){return t-e.getBoundingClientRect().x}function De(e,t){if(null===e.x||null===e.y||null===t.x||null===t.y)return null;const i=t.x-e.x,s=t.y-e.y;return Math.sqrt(i*i+s*s)}const be=(e,t)=>({x:e.x*t,y:e.y*t}),Pe=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),xe=()=>"undefined"!=typeof window&&("ontouchstart"in window&&null!==window.ontouchstart||navigator&&"maxTouchPoints"in navigator&&navigator.maxTouchPoints>0);class ye{_chart=void 0;_series=void 0;_p1={};_p2={};textValue="";_options=ue();dataUpdated;requestUpdate(){this._requestUpdate&&this._requestUpdate()}_requestUpdate;attached({chart:e,series:t,requestUpdate:i}){this._chart=e,this._series=t,this._series.subscribeDataChanged(this._fireDataUpdated),this._requestUpdate=i,this.requestUpdate()}detached(){this._series?.unsubscribeDataChanged(this._fireDataUpdated),this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return me(this._chart)}get series(){return me(this._series)}_fireDataUpdated(e){this.dataUpdated&&this.dataUpdated(e)}}class fe{}class _e{p1;p2;fillColor;vertical=!1;constructor(e,t,i,s){this.p1=e,this.p2=t,this.fillColor=i,this.vertical=s}draw(e){e.useBitmapCoordinateSpace(e=>{if(null===this.p1||null===this.p2)return;const t=e.context;t.save();const i=function(e,t,i){const s=Math.round(i*e),r=Math.round(i*t);return{position:Math.min(s,r),length:Math.abs(r-s)+1}}(this.p1,this.p2,this.vertical?e.verticalPixelRatio:e.horizontalPixelRatio);t.fillStyle=this.fillColor,this.vertical?t.fillRect(0,i.position,60*e.horizontalPixelRatio,i.length):t.fillRect(i.position,0,i.length,36*e.verticalPixelRatio),t.restore()})}}class Se{source;p1=null;p2=null;axisPaneRenderer;constructor(e,t){this.source=e,this.axisPaneRenderer=new _e(this.p1,this.p2,this.source.drawingTool.options.paneFillColor,t)}update(){[this.p1,this.p2]=this.getPoints()}renderer(){const e=this.source._options.showPanes;return this.axisPaneRenderer.p1=this.p1,this.axisPaneRenderer.p2=this.p2,this.axisPaneRenderer.fillColor=e?this.source.drawingTool.options.paneFillColor:"transparent",this.axisPaneRenderer}zOrder(){return"bottom"}}class Ce{source;point;position=null;constructor(e,t){this.source=e,this.point=t}coordinate(){return this.position??-1}visible(){return this.source._options.showLabels}tickVisible(){return this.source._options.showLabels}textColor(){return this.source._options.labelTextColor}backColor(){return this.source._options.labelBackgroundColor}movePoint(e){this.point=e,this.update()}}class Te extends Se{getPoints(){const e=this.source.series;if(!this.source._p1||!this.source._p2)return[null,null];return[e.priceToCoordinate(this.source._p1.price),e.priceToCoordinate(this.source._p2.price)]}}class ke extends Se{getPoints(){const e=this.source.chart.timeScale();if(!this.source._p1||!this.source._p2)return[null,null];return[e.timeToCoordinate(this.source._p1.time),e.timeToCoordinate(this.source._p2.time)]}}class Me extends Ce{update(){const e=this.source.chart.timeScale();this.position=e.timeToCoordinate(this.point.time)}text(){return this.source._options.timeLabelFormatter(this.point.time)}}class Ae extends Ce{update(){this.position=this.source.series.priceToCoordinate(this.point.price)}text(){return this.source.series.priceFormatter().format(this.point.price)}}class Le{x;y;anchorSelected;source;style={...pe};constructor({style:e,source:t}={}){this.x=0,this.y=0,this.anchorSelected=!1,this.source=t,this.style={...pe,...e}}draw(e,t,i){this.x=t,this.y=i;const s=e.context;s.beginPath();const r="undefined"!=typeof window&&("ontouchstart"in window&&null!==window.ontouchstart||navigator&&"maxTouchPoints"in navigator&&navigator.maxTouchPoints>0)?this.style.touchRadius:this.style.radius;s.arc(this.x*e.horizontalPixelRatio,this.y*e.verticalPixelRatio,r*e.verticalPixelRatio,0,2*Math.PI),s.fillStyle=this.style.fillColor,s.fill();const o=this.source?.selected??!1;s.lineWidth=o?2*this.style.strokeWidth*e.verticalPixelRatio:this.style.strokeWidth*e.verticalPixelRatio,s.strokeStyle=this.style.strokeColor,s.stroke()}containPoint(e){if(null===e.x||null===e.y)return!1;const t=De(e,{x:this.x,y:this.y}),i=xe()?this.style.touchRadius:this.style.radius;return null!==t&&t<=i}handleClickAnchorPoint(e){this.containPoint(e)&&(this.anchorSelected=!0)}}class Ve{source;p1;p2;anchorPoints;constructor({p1:e,p2:t,source:i}){this.p1=e,this.p2=t,this.source=i,this.anchorPoints=[new Le({source:i,style:{strokeColor:i._options.strokeColor}}),new Le({source:i,style:{strokeColor:i._options.strokeColor}})]}draw(e){this.source.drawingTool.drawVisible&&e.useBitmapCoordinateSpace(e=>{const t=e.context;if(null===this.p1?.x||null===this.p1?.y||null===this.p2?.x||null===this.p2?.y)return;const i=this.p1.x*e.horizontalPixelRatio,s=this.p1.y*e.verticalPixelRatio,r=this.p2.x*e.horizontalPixelRatio,o=this.p2.y*e.verticalPixelRatio;t.beginPath(),t.moveTo(i,s),t.lineTo(r,o),t.strokeStyle=this.source._options.strokeColor??"blue",t.lineWidth=this.source._options.strokeWidth*e.verticalPixelRatio,t.stroke(),this.anchorPoints.forEach(e=>{e.style.strokeColor=this.source._options.strokeColor??"blue"}),(this.source.hovered||this.source.selected)&&(this.anchorPoints[0].draw(e,this.p1.x,this.p1.y),this.anchorPoints[1].draw(e,this.p2.x,this.p2.y))})}}class Ee{source;p1={x:null,y:null};p2={x:null,y:null};linePaneRenderer;dynamicZOrder="normal";constructor(e){this.source=e,this.linePaneRenderer=new Ve({p1:this.p1,p2:this.p2,source:e})}renderer(){return this.linePaneRenderer.p1=this.p1,this.linePaneRenderer.p2=this.p2,this.linePaneRenderer}zOrder(){return this.dynamicZOrder}update(){const e=this.source.series,t=this.source.chart.timeScale(),i=e.priceToCoordinate(this.source._p1.price),s=e.priceToCoordinate(this.source._p2.price),r=t.timeToCoordinate(this.source._p1.time),o=t.timeToCoordinate(this.source._p2.time);null!==r&&null!==o&&null!==i&&null!==s&&(this.p1={x:r,y:i},this.p2={x:o,y:s})}}class Oe extends ye{_paneViews;_timeAxisLabelViews;_priceAxisLabelViews;_priceAxisPaneViews;_timeAxisPaneViews;hoverCandidate=!1;hovered=!1;selectCandidate=!1;selected=!1;id;localId;createdAt;state;drawingTool;dragPoint;beforeDragPoints;constructor({p1:e,p2:t,drawingTool:i,state:s,id:r,createdAt:o,options:n,selected:a}){super(),this.id=r,this.createdAt=o||Date.now(),this.localId=i.type+"-"+this.createdAt,this.state=s||"clean",this.drawingTool=i,this._p1=e,this._p2=t,this._options=$({...i.options,...n}),this.selected=a||!1,this._paneViews=[new Ee(this)],this._timeAxisLabelViews=[new Me(this,e),new Me(this,t)],this._priceAxisLabelViews=[new Ae(this,e),new Ae(this,t)],this._priceAxisPaneViews=[new Te(this,!0)],this._timeAxisPaneViews=[new ke(this,!1)]}containPoint(e){const t=this._paneViews[0],i=t.linePaneRenderer.anchorPoints,s=i[0].style.strokeWidth,r=t.p1,o=t.p2;return i.some(t=>t.containPoint(e))||function(e,t,i,s,r=5){if(null===t.x||null===t.y||null===i.x||null===i.y||null===e.x||null===e.y)return!1;const o=i.x-t.x,n=i.y-t.y;if(Math.abs(n*e.x-o*e.y+i.x*t.y-i.y*t.x)/Math.sqrt(o*o+n*n)>s/2+r)return!1;const a=(e.x-t.x)*o+(e.y-t.y)*n;return a>=0&&a<=o*o+n*n}(e,r,o,s,xe()?this._options.touchNealDrawThreshold:this._options.nealDrawThreshold)}onMouseMove(e){if(this._options.locked||this.drawingTool.runtime.getLockAllDraw())return;const t=e.point,i=e.time,s=this._paneViews[0].linePaneRenderer.anchorPoints;if(!t||!i)return;const r=this.containPoint(t),o=this.hoverCandidate,n=this.hovered;let a=!1;if(s.forEach((e,s)=>{if(e.anchorSelected){if(a=!0,0===s){if(this._p1.time===i&&this._p1.price===this.series.coordinateToPrice(t.y))return;this._p1.time=i,this._p1.price=this.series.coordinateToPrice(t.y)}else{if(this._p2.time===i&&this._p2.price===this.series.coordinateToPrice(t.y))return;this._p2.time=i,this._p2.price=this.series.coordinateToPrice(t.y)}this.state="updating",this.requestUpdate()}}),!a){this.hoverCandidate=r,r||(this.hovered=r);const e=this.handleDragWholeDraw(t),i=o!==this.hoverCandidate||n!==this.hovered;(e||i)&&this.requestUpdate()}}onMouseDown(e){this.dragPoint=e,this.beforeDragPoints={p1:this._p1,p2:this._p2},this.containPoint(e)?(this.chart.applyOptions({handleScroll:!1}),this.selectCandidate=!0):(this.selectCandidate=!1,this.selected=!1,this.hovered=!1,this.hoverCandidate=!1);this._paneViews[0].linePaneRenderer.anchorPoints.forEach(t=>{t.handleClickAnchorPoint(e)})}onMouseUp(){const e=this._paneViews[0].linePaneRenderer.anchorPoints;this.selectCandidate&&!this.selected&&this.selectedDraw(),this.hovered=!1,this.hoverCandidate=!1,this.selectCandidate=!1,this.dragPoint=void 0,this.beforeDragPoints=void 0,e.forEach(e=>{e.anchorSelected=!1}),this.chart.applyOptions({handleScroll:!0}),this.requestUpdate()}handleDragWholeDraw(e){let t=!1;if(this.dragPoint&&this.selected){const i=e.x-this.dragPoint.x,s=e.y-this.dragPoint.y,r=this.beforeDragPoints?.p1,o=this.beforeDragPoints?.p2;if(!r||!o)return!1;const n=this.chart.timeScale().timeToCoordinate(r.time),a=this.series.priceToCoordinate(r.price),l=this.chart.timeScale().timeToCoordinate(o.time),c=this.series.priceToCoordinate(o.price);if(null===n||null===a||null===l||null===c)return!1;const d=this.chart.timeScale().coordinateToTime(n+i),u=this.series.coordinateToPrice(a+s),p=this.chart.timeScale().coordinateToTime(l+i),w=this.series.coordinateToPrice(c+s);if(!(d&&u&&p&&w))return!1;if(this._p1.time===d&&this._p1.price===u&&this._p2.time===p&&this._p2.price===w)return!1;this._p1={time:d,price:u},this._p2={time:p,price:w},this._priceAxisLabelViews[0].movePoint(this._p1),this._timeAxisLabelViews[0].movePoint(this._p1),this._priceAxisLabelViews[1].movePoint(this._p2),this._timeAxisLabelViews[1].movePoint(this._p2),this.state="updating",t=!0}return t}selectedDraw(){this.selected=!0,this.selectCandidate=!0,this.drawingTool.runtime.setSelectedDrawOptions(this._options,ae.Line)}getPoints(){return[this._p1,this._p2]}updateSelectedState(){this.selected?(this._options.showPanes=!0,this._options.showLabels=!0):(this._options.showPanes=!1,this._options.showLabels=!1)}updateAllViews(){this.updateSelectedState(),this._paneViews.forEach(e=>e.update()),this._timeAxisLabelViews.forEach(e=>e.update()),this._priceAxisLabelViews.forEach(e=>e.update()),this._priceAxisPaneViews.forEach(e=>e.update()),this._timeAxisPaneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}priceAxisViews(){return this._priceAxisLabelViews}timeAxisViews(){return this._timeAxisLabelViews}priceAxisPaneViews(){return this._priceAxisPaneViews}timeAxisPaneViews(){return this._timeAxisPaneViews}detached(){this._paneViews[0].update()}updateSelectedOptions(e){this.selected&&(Object.assign(this._options,{...this._options,...e}),this.state="updating",this.requestUpdate())}}class Re extends Oe{constructor({p1:e,p2:t,drawingTool:i}){super({p1:e,p2:t,drawingTool:i,selected:!0})}updateEndPoint(e){this._p2=e,this._paneViews.forEach(e=>e.update()),this._timeAxisLabelViews[1].movePoint(e),this._priceAxisLabelViews[1].movePoint(e),this.requestUpdate()}}const Ue=()=>{const e=new Set;let t=null;const i=()=>{t=null,e.forEach(e=>e.requestUpdate()),e.clear()};return{schedule:s=>{s.forEach(t=>{t&&e.add(t)}),null===t&&(t=window.requestAnimationFrame(i))},cancel:()=>{null!==t&&(window.cancelAnimationFrame(t),t=null),e.clear()}}},Be=()=>{let e=null,t="default",i="default";const s=()=>{e=null,i!==t&&(document.body.style.cursor=t,i=t)};return{setCursor:i=>{t=i,null===e&&(e=window.requestAnimationFrame(s))},reset:()=>{t="default",null!==e&&(window.cancelAnimationFrame(e),e=null),"default"!==i&&(document.body.style.cursor="default",i="default")}}},Fe=(e,t,i)=>{const s=e.chartElement();return{x:ve(s,t),y:ge(s,i)}},Ne=(e,t)=>Fe(e,t.clientX,t.clientY),ze=(e,t)=>Fe(e,t.clientX,t.clientY),We=(e,t)=>({point:t,time:e.timeScale().coordinateToTime(t.x)}),Ie=(e,t,i)=>{const s=e.timeScale().coordinateToTime(i.x),r=t.coordinateToPrice(i.y);return s&&null!=r?{time:s,price:r}:null},qe=(e,t)=>{e.forEach(e=>{e.onMouseDown(t)})},$e=e=>{e.forEach(e=>{e.onMouseUp()})},je=(e,t)=>e.some(e=>t(e)),Ke=({primitives:e,isDrawing:t,isPointerHit:i,clearSelection:s})=>{if(t)return;je(e,i)||s()},He=(e,t,i)=>(t.push(i),e.attachPrimitive(i),i),Ye=(e,t,i)=>(He(e,t,i),i.selectedDraw(),i),Xe=e=>e.map(e=>({time:e.time,price:e.price})),Ze=(e,t,i)=>e(t,i),Ge=async(e,t,i=e=>Xe(e.getPoints()))=>{const s=e.filter(e=>"number"==typeof e.id&&e.id>0&&e.state===le.Updating);await Promise.all(s.map(async e=>{try{await t(e.id,i(e)),e.state=le.Clean}catch{e.state=le.Updating}}))},Je=(e,t,i)=>{let s=null,r=!1;const o=async()=>{if(s)return r=!0,void(await s);s=(async()=>{do{r=!1,await Ge(e(),t,i)}while(r)})();try{await s}finally{s=null}};return{schedule:()=>{o()},flush:async()=>{await o()},cancel:()=>{r=!1}}},Qe=({chart:e,onClick:t,onCrosshairMove:i,onVisibleRangeChange:s,onMouseDown:r,onMouseUp:o,onContextMenu:n,onTouchStart:a,onTouchMove:l,onTouchEnd:c,textArea:d,onTextAreaChange:u,onTextAreaBlur:p})=>{t&&e.subscribeClick(t),i&&e.subscribeCrosshairMove(i),s&&e.timeScale().subscribeVisibleLogicalRangeChange(s);const w=e.chartElement();return r&&w.addEventListener("mousedown",r),o&&w.addEventListener("mouseup",o),n&&w.addEventListener("contextmenu",n),a&&w.addEventListener("touchstart",a,{passive:!1}),l&&w.addEventListener("touchmove",l,{passive:!1}),c&&w.addEventListener("touchend",c),d&&u&&d.addEventListener("change",u),d&&p&&d.addEventListener("blur",p),()=>{t&&e.unsubscribeClick(t),i&&e.unsubscribeCrosshairMove(i),s&&e.timeScale().unsubscribeVisibleLogicalRangeChange(s),r&&w.removeEventListener("mousedown",r),o&&w.removeEventListener("mouseup",o),n&&w.removeEventListener("contextmenu",n),a&&w.removeEventListener("touchstart",a),l&&w.removeEventListener("touchmove",l),c&&w.removeEventListener("touchend",c),d&&u&&d.removeEventListener("change",u),d&&p&&d.removeEventListener("blur",p)}},et=(e,t,i)=>{const s=!e;return i.schedule(t),s},tt=e=>{let t=!1;return e.forEach(e=>{e.selected&&(e._options.locked=!e._options.locked,e.state="updating",t=!0)}),t},it=(e,t)=>{let i=!1;return e.forEach(e=>{e._options.locked!==t&&(e._options.locked=t,e.state="updating",i=!0)}),i},st=e=>e.some(e=>e.selected),rt=(e,t)=>{let i=!1;e.forEach(e=>{e.selected&&(e.selected=!1,i=!0)}),i&&t()},ot=(e,t,i)=>(t.forEach(t=>{e.detachPrimitive(t)}),i(),[]),nt=async(e,t,i)=>{const s=[];for(const r of t)r.selected?(e.detachPrimitive(r),void 0!==r.id&&r.id>0&&await i(r.id)):s.push(r);return s};class at extends fe{type=ae.Line;chart;series;options;runtime;persistence;lines=[];currentPoints=[];previewLine;drawVisible=!0;primitiveUpdateScheduler=Ue();drawingUpdateScheduler;cursorScheduler=Be();pendingCreateOperations=new Set;unbindEvents;localRuntimeState={drawMode:ae.None,lockAllDraw:!1,selectedDrawMode:null,selectedDrawOptions:void 0,chartControlStateChangesLog:[]};handleVisibleRangeChange=()=>{this.primitiveUpdateScheduler.schedule([...this.lines,this.previewLine])};buildLinePayload(e,t=this.options.strokeWidth){return{points:Xe(e),width:t,color:this.options.strokeColor}}trackPendingCreate(e,t){const i=t.then(t=>{t&&(e.id=t.id,e.createdAt=t.created_at,e.state!==le.New?e.state===le.Updating&&this.checkUpdateDraw():e.state=le.Clean)}).finally(()=>{this.pendingCreateOperations.delete(i)});this.pendingCreateOperations.add(i)}constructor({chart:e,series:t,options:i,isDark:s,runtime:r,persistence:o}){super(),this.chart=e,this.series=t,this.options={...ue(s),...i},this.runtime=r??{getDrawMode:()=>this.localRuntimeState.drawMode,setDrawMode:e=>{this.localRuntimeState.drawMode=e},getLockAllDraw:()=>this.localRuntimeState.lockAllDraw,clearSelectedDrawing:()=>{this.localRuntimeState.selectedDrawMode=null,this.localRuntimeState.selectedDrawOptions=void 0},setSelectedDrawOptions:(e,t)=>{if(null===t)return this.localRuntimeState.selectedDrawMode=null,void(this.localRuntimeState.selectedDrawOptions=void 0);this.localRuntimeState.selectedDrawMode=t,this.localRuntimeState.selectedDrawOptions={...e}},getSelectedTimeFrame:()=>ce.OneMinute,getChartDataTimes:()=>[],getChartControlStateChangesLog:()=>this.localRuntimeState.chartControlStateChangesLog},this.persistence=o??{createDrawing:async()=>null,updateDrawing:async()=>{},deleteDrawing:async()=>{}},this.drawingUpdateScheduler=Je(()=>this.lines,this.persistence.updateDrawing,e=>({points:Xe(e.getPoints()),width:e._options.strokeWidth,color:e._options.strokeColor})),this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.subscribeEvents()}subscribeEvents(){this.unbindEvents=Qe({chart:this.chart,onClick:this.onClick,onCrosshairMove:this.onMouseMove,onVisibleRangeChange:this.handleVisibleRangeChange,onMouseDown:this.handleMouseDown,onMouseUp:this.handleMouseUp,onContextMenu:this.handleContextMenu,onTouchStart:this.handleTouchStart,onTouchMove:this.handleTouchMove,onTouchEnd:this.handleTouchEnd})}unsubscribeEvents(){this.unbindEvents?.(),this.unbindEvents=void 0}handleTouchStart=e=>{if(0===e.touches.length)return;this.chart.clearCrosshairPosition();const t=e.touches[0],i=ze(this.chart,t);qe(this.lines,i),this.previewLine?.onMouseDown(i),e.preventDefault()};handleTouchMove=e=>{if(0===e.touches.length)return;const t=e.touches[0],i=ze(this.chart,t);this.onMouseMove(We(this.chart,i)),e.preventDefault()};handleTouchEnd=()=>{$e(this.lines),this.previewLine?.onMouseUp(),this.finalizePreviewLine(),this.checkUpdateDraw()};handleMouseDown=e=>{const t=Ne(this.chart,e);Ke({primitives:this.lines,isDrawing:this.isDrawing(),isPointerHit:e=>e.containPoint(t),clearSelection:()=>this.unSelectAnyDraw()}),qe(this.lines,t)};handleMouseUp=()=>{$e(this.lines),this.checkUpdateDraw()};handleContextMenu=e=>{const t=Ne(this.chart,e);if(je(this.lines,e=>e.containPoint(t))){this.unSelectAnyDraw();const i=this.lines.find(e=>e.containPoint(t));i&&(i.selected=!0,this.runtime.setSelectedDrawOptions({strokeWidth:i._options.strokeWidth,strokeColor:i._options.strokeColor},ae.Line)),e.preventDefault(),e.stopPropagation()}};isDrawing(){return this.runtime.getDrawMode()===ae.Line}startDrawing(){this.runtime.setDrawMode(ae.Line)}stopDrawing(){this.currentPoints=[],this.removePreviewLine(),this.runtime.setDrawMode(ae.None)}onClick(e){if(!e.point||!e.time||!this.series)return;const t=Ie(this.chart,this.series,e.point);t&&this.isDrawing()&&this.addPoint(t)}onMouseMove(e){if(this.lines.forEach(t=>t.onMouseMove(e)),this.mouseStyling(),e.point&&this.series&&e.time&&this.isDrawing()&&this.previewLine){const t=Ie(this.chart,this.series,e.point);t&&this.previewLine.updateEndPoint(t)}}addPoint(e){this.currentPoints?.push(e),1===this.currentPoints?.length&&this.addPreviewLine(this.currentPoints[0]),2===this.currentPoints?.length&&(this.addNewLine(this.currentPoints[0],this.currentPoints[1]),this.stopDrawing())}addPreviewLine(e){this.previewLine=new Re({p1:e,p2:e,drawingTool:this}),this.series.attachPrimitive(this.previewLine)}addNewLine(e,t){const i=new Oe({p1:e,p2:t,drawingTool:this,state:"new"});Ye(this.series,this.lines,i),this.trackPendingCreate(i,Ze(this.persistence.createDrawing,we.Line,{points:Xe([e,t]),width:i._options.strokeWidth,color:i._options.strokeColor}))}finalizePreviewLine(){const e=this.previewLine?._p1,t=this.previewLine?._p2;e&&t&&!j(e,t)&&(this.addNewLine(e,t),this.removePreviewLine(),this.stopDrawing())}removePreviewLine(){this.previewLine&&this.series&&(this.series.detachPrimitive(this.previewLine),this.previewLine=void 0)}initData(e){if(!e||0===e.length)return;const t=this.runtime.getChartControlStateChangesLog(),i=t[t.length-1]===he.DrawUpdate;e.forEach(e=>{const{data:t}=e;if(!t.points)return;const s=!!i&&t.selected,r=new Oe({p1:t.points[0],p2:t.points[1],id:e.id,drawingTool:this,createdAt:t.createdAt,options:t.options,selected:s});s&&r.selectedDraw(),this.series.attachPrimitive(r),this.lines.push(r)})}checkUpdateDraw(){this.drawingUpdateScheduler.schedule()}toggleDrawVisible(){this.drawVisible=et(this.drawVisible,this.lines,this.primitiveUpdateScheduler)}toggleSelectedDrawLocked(){tt(this.lines)&&this.checkUpdateDraw()}toggleAllDrawLocked(e){it(this.lines,e)&&this.checkUpdateDraw()}isAnyDrawSelected(){return st(this.lines)}updateSelectedOptions(e){this.lines.forEach(t=>t.updateSelectedOptions(e)),this.checkUpdateDraw()}async flushPendingUpdates(){this.pendingCreateOperations.size>0&&await Promise.allSettled([...this.pendingCreateOperations]),await this.drawingUpdateScheduler.flush()}mouseStyling(){const e=this.lines.some(e=>e.hovered);this.cursorScheduler.setCursor(e?"pointer":"default")}unSelectAnyDraw(){rt(this.lines,this.runtime.clearSelectedDrawing)}cleanPrimitives(){this.lines=ot(this.series,this.lines,this.runtime.clearSelectedDrawing)}cleanAll(){this.unsubscribeEvents(),this.primitiveUpdateScheduler.cancel(),this.drawingUpdateScheduler.cancel(),this.removePreviewLine(),this.currentPoints=[],this.cursorScheduler.reset(),this.cleanPrimitives()}async removeSelectedDraw(){this.lines=await nt(this.series,this.lines,e=>this.persistence.deleteDrawing(e))}}const lt=e=>({[ce.OneMinute]:6e4,[ce.FiveMinutes]:3e5,[ce.FifteenMinutes]:9e5,[ce.ThirtyMinutes]:18e5,[ce.OneHour]:36e5,[ce.FourHours]:144e5,[ce.OneDay]:864e5,[ce.OneWeek]:6048e5,[ce.OneMonth]:2592e6}[e]??6e4),ht=e=>{const t=(e=>{if(null==e)return null;if("number"==typeof e){if(!Number.isFinite(e))return null;const t=e>1e11?e/1e3:e;return Math.trunc(t)}const t=(e instanceof Date?e:new Date(e)).getTime();return Number.isFinite(t)?Math.trunc(t/1e3):null})(e);return null===t?null:t+(e=>60*-new Date(1e3*e).getTimezoneOffset())(t)},ct=(e,t)=>{if(!t.length||!Number.isFinite(e))return e;const i=t[0],s=t[t.length-1];if(e<i||e>s)return e;let r=0,o=t.length-1;for(;r<=o;){const i=Math.floor((r+o)/2),s=t[i];if(s===e)return s;s<e?r=i+1:o=i-1}const n=t[Math.max(0,o)],a=t[Math.min(t.length-1,r)];return Math.abs(e-n)<=Math.abs(a-e)?n:a},dt=(e,t)=>{const i="number"==typeof e.time?e.time:Number(e.time);return Number.isFinite(i)?{...e,time:ct(i,t)}:e},ut=[ce.OneMinute,ce.FiveMinutes,ce.FifteenMinutes,ce.ThirtyMinutes,ce.OneHour,ce.FourHours,ce.OneDay,ce.OneWeek,ce.OneMonth],pt=(e,t=ce.OneMinute)=>Math.max(1,Math.floor(lt(((e,t=ce.OneMinute)=>ut.find(t=>t===e)??t)(e,t))/1e3)),wt=e=>{const t=[];return e.forEach(e=>{const i=(e=>({time:Number(e.time),price:e.price}))(e);if(!Number.isFinite(i.time)||!Number.isFinite(i.price))return;const s=t.at(-1);s&&s.time===i.time&&s.price===i.price||t.push(i)}),t},mt=(e,t)=>{const i=wt(e);if(!i.length)return null;const s=i[0],r=pt(t,t);return{version:2,anchorPoint:s,baseInterval:t,relativePoints:i.map(e=>({dxLogical:(e.time-s.time)/r,dyPrice:e.price-s.price}))}},gt=(e,t)=>{if(!Number.isFinite(e)||!t.length)return e;const i=t[0],s=t[t.length-1];return e<=i?i:e>=s?s:ct(e,t)},vt=(e,t,i)=>{const s=gt(e.anchorPoint.time,t),r=pt(e.baseInterval,ce.OneMinute),o=pt(i,ce.OneMinute),n=r/o,a={time:e.anchorPoint.time,price:e.anchorPoint.price},l={time:s,price:e.anchorPoint.price};return{version:2,anchorPoint:a,mountedAnchorPoint:l,baseInterval:e.baseInterval,relativePoints:e.relativePoints,points:e.relativePoints.map(e=>({time:s+e.dxLogical*o*n,price:l.price+e.dyPrice}))}};class Dt{drawPoints;source;anchorPoints;smoothPoints=[];drawFullyViewFirstTime=!1;lastViewportKey=null;lastPointsKey=null;constructor({source:e}){this.source=e,this.drawPoints=e.drawPoints,this.anchorPoints=[new Le({source:e,style:{strokeColor:e._options.strokeColor??"blue"}}),new Le({source:e,style:{strokeColor:e._options.strokeColor??"blue"}})]}mapTimePointsToPixelPoints(e){return e.map(e=>({x:this.source.chart.timeScale().timeToCoordinate(e.time),y:this.source.series.priceToCoordinate(e.price)})).filter(e=>null!==e.x&&null!==e.y&&Number.isFinite(e.x)&&Number.isFinite(e.y))}getBrushShapeKey(){if(2!==this.source.brushData?.version)return"legacy";const e=this.source.brushData.relativePoints[0],t=this.source.brushData.relativePoints[this.source.brushData.relativePoints.length-1];return["v2",this.source.drawingTool.runtime.getSelectedTimeFrame(),this.source.brushData.baseInterval,this.source.brushData.mountedAnchorPoint.time,this.source.brushData.mountedAnchorPoint.price,this.source.brushData.relativePoints.length,e?.dxLogical,e?.dyPrice,t?.dxLogical,t?.dyPrice].join("|")}getPixelsPerLogicalBar(){const e=this.source.chart.timeScale().getVisibleLogicalRange(),t=this.source.chart.paneSize?.(0),i=e?e.to-e.from:0;return!t?.width||!Number.isFinite(i)||i<=0?0:t.width/i}getPixelDrawPoints(){const e=this.mapTimePointsToPixelPoints(this.drawPoints);if(2===this.source.brushData?.version){const t=this.source.brushData.mountedAnchorPoint,i=this.source.chart.timeScale().timeToCoordinate(t.time),s=this.source.series.priceToCoordinate(t.price),r=this.getPixelsPerLogicalBar();if(null===i||null===s||!r)return e;const o=pt(this.source.brushData.baseInterval)/pt(this.source.drawingTool.runtime.getSelectedTimeFrame()),n=this.source.brushData.relativePoints.map(e=>({x:i+e.dxLogical*o*r,y:this.source.series.priceToCoordinate(t.price+e.dyPrice)})).filter(e=>Number.isFinite(e.x)&&null!==e.y&&Number.isFinite(e.y));return n.length?n:e}return e}getSmoothPoints(){const e=this.source.drawingTool?.chart.timeScale().getVisibleRange(),t=this.source.chart.timeScale().getVisibleLogicalRange(),i=this.source.series.priceScale().getVisibleRange(),s=this.source.chart.paneSize?.(0),r=e?.from,o=[e?`${e.from}-${e.to}`:"",t?`${t.from}-${t.to}`:"",i?`${i.from}-${i.to}`:"",s?`${s.width}-${s.height}`:""].join("|"),n=`${this.source.geometryVersion}-${this.source.drawPoints.length}-${this.getBrushShapeKey()}`;if(this.lastViewportKey===o&&this.lastPointsKey===n)return this.smoothPoints;const a=this.source._p2.time>r;if(2!==this.source.brushData?.version&&!this.drawFullyViewFirstTime){if(!a)return this.lastViewportKey=null,this.lastPointsKey=null,this.smoothPoints=[],[];this.drawFullyViewFirstTime=!0}const l=this.getPixelDrawPoints();if(!l.length)return this.lastViewportKey=null,this.lastPointsKey=null,this.smoothPoints=[],[];if(this.lastViewportKey=o,this.lastPointsKey=n,l.length<=2)return this.smoothPoints=l,l;const c=[];for(let u=1;u<l.length;u++){const e=l[u],t=l[u-1],i={x:e.x-t.x,y:e.y-t.y},s=Math.sqrt(i.x**2+i.y**2),r=Math.min(5,Math.floor(2*s/15)),o=be(be(i,1/s),s/r);for(let n=0;n<r-1;n++){const e=be(o,n),i={x:t.x+e.x,y:t.y+e.y};c.push(i)}c.push(e)}const d=this.smoothArray(c,15);return this.smoothPoints=void 0===d[0]?[]:d,this.smoothPoints}smoothArray(e,t){const i=new Array(e.length);if(1===e.length)return e;for(let s=0;s<e.length;s++){let r={x:0,y:0};for(let i=0;i<t;i++){const t=Math.max(s-i,0),o=Math.min(s+i,e.length-1);r=Pe(r,e[t]),r=Pe(r,e[o])}i[s]=be(r,.5/t)}return i.push(e[e.length-1]),i}drawBrush(e,t){if(0===t.length)return;const i=e.context,s=e.horizontalPixelRatio,r=e.verticalPixelRatio;i.strokeStyle=this.source._options.strokeColor??"blue";const o=this.source._options.strokeWidth*r;if(i.lineWidth=o,i.lineCap="round",i.lineJoin="round",i.fillStyle=this.source._options.strokeColor??"blue",this.anchorPoints.forEach(e=>{e.style.strokeColor=this.source._options.strokeColor??"blue"}),i.beginPath(),1===t.length){const{x:e,y:n}=t[0];return i.arc(e*s,n*r,o/2,0,2*Math.PI,!0),void i.fill()}if(2===t.length){const[e,o]=t;i.moveTo(e.x*s,e.y*r),i.lineTo(o.x*s,o.y*r)}else{const e=t[0];i.moveTo(e.x*s,e.y*r);for(let a=1;a<t.length-1;a++){const e=t[a],o=t[a+1],n=e.x*s,l=e.y*r,c=.5*(e.x+o.x)*s,d=.5*(e.y+o.y)*r;i.quadraticCurveTo(n,l,c,d)}const o=t[t.length-1],n=t[t.length-2];i.quadraticCurveTo(n.x*s,n.y*r,o.x*s,o.y*r)}i.stroke()}draw(e){this.smoothPoints=this.getSmoothPoints(),this.source.drawingTool?.drawVisible&&e.useBitmapCoordinateSpace(e=>{if(this.drawBrush(e,this.smoothPoints),this.source.hovered||this.source.selected){const t=this.smoothPoints[0],i=this.smoothPoints[this.smoothPoints.length-1];if(!t||!i)return;this.anchorPoints[0].draw(e,t.x,t.y),this.anchorPoints[1].draw(e,i.x,i.y)}})}}class bt{source;brushPaneRenderer;dynamicZOrder="normal";constructor(e){this.source=e,this.brushPaneRenderer=new Dt({source:e})}renderer(){return this.brushPaneRenderer}zOrder(){return this.dynamicZOrder}}class Pt extends ye{_paneViews;_timeAxisLabelViews;_priceAxisLabelViews;_priceAxisPaneViews;_timeAxisPaneViews;hoverCandidate=!1;hovered=!1;selectCandidate=!1;selected=!1;id;localId;createdAt;drawingTool;state;drawPoints=[];geometryVersion=0;dragPoint;drawPointsBeforeDrag=[];brushData;anchorPointBeforeDrag;boundingPointsBeforeDrag;constructor({drawPoints:e,boundingPoints:t,brushData:i,drawingTool:s,state:r,id:o,createdAt:n,selected:a,options:l}){super(),this.id=o,this.createdAt=n||Date.now(),this.localId=s.type+"-"+this.createdAt,this.state=r||"clean",this.drawingTool=s,this.drawPoints=e,this.brushData=i,this.selected=a||!1,this._options=$({...s.options,...l}),this._paneViews=[new bt(this)];const[c,d]=t;this._p1=c,this._p2=d,this._timeAxisLabelViews=[new Me(this,this._p1),new Me(this,this._p2)],this._priceAxisLabelViews=[new Ae(this,this._p1),new Ae(this,this._p2)],this._timeAxisPaneViews=[new ke(this,!1)],this._priceAxisPaneViews=[new Te(this,!0)]}onMouseMove(e){const{point:t}=e;if(this._options.locked||this.drawingTool.runtime.getLockAllDraw()||!t)return;const i=this.hoverCandidate,s=this.hovered,r=this.containPoint(t);this.drawingTool.isMouseDown||(this.hoverCandidate=r),r||(this.hovered=!1);const o=this.handleDrag(t),n=i!==this.hoverCandidate||s!==this.hovered;(o||n)&&this.requestUpdate()}onMouseDown({x:e,y:t}){this.dragPoint={x:e,y:t},this.drawPointsBeforeDrag=$(this.drawPoints),this.anchorPointBeforeDrag=this.brushData?$(this.brushData.mountedAnchorPoint):void 0,this.boundingPointsBeforeDrag={p1:$(this._p1),p2:$(this._p2)};this.containPoint({x:e,y:t})?(this.chart.applyOptions({handleScroll:!1}),this.selectCandidate=!0):(this.selectCandidate=!1,this.selected=!1,this.hovered=!1,this.hoverCandidate=!1)}onMouseUp(){this.selectCandidate&&!this.selected&&this.selectedDraw(),this.dragPoint=void 0,this.drawPointsBeforeDrag=[],this.anchorPointBeforeDrag=void 0,this.boundingPointsBeforeDrag=void 0,this.hovered=!1,this.hoverCandidate=!1,this.selectCandidate=!1,this.chart.applyOptions({handleScroll:!0}),this.requestUpdate()}handleDrag(e){let t=!1;if(this.selected&&this.dragPoint){const i=e.x-(this.dragPoint.x??0),s=e.y-(this.dragPoint.y??0);if(2===this.brushData?.version&&this.anchorPointBeforeDrag){const e=this.drawingTool.runtime.getChartDataTimes(),t=this.chart.timeScale().timeToCoordinate(this.anchorPointBeforeDrag.time),r=this.series.priceToCoordinate(this.anchorPointBeforeDrag.price);if(null===t||null===r)return!1;const o=this.chart.timeScale().coordinateToTime(t+i),n=this.series.coordinateToPrice(r+s);if(null===o||null===n)return!1;const a=gt(Number(o),e);return this.brushData.anchorPoint={time:a,price:n},this.brushData.mountedAnchorPoint={time:a,price:n},this.syncBrushDataDerivedState(),this.state="updating",!0}if(this.drawPointsBeforeDrag.forEach((e,t)=>{const r=this.chart.timeScale().timeToCoordinate(e.time),o=this.series.priceToCoordinate(e.price);if(null===r||null===o)return;const n=this.chart.timeScale().coordinateToTime(r+i),a=this.series.coordinateToPrice(o+s);this.drawPoints[t]={time:n,price:a}}),!this.boundingPointsBeforeDrag)return!1;const{p1:r,p2:o}=this.boundingPointsBeforeDrag,n=this.chart.timeScale().timeToCoordinate(r.time),a=this.series.priceToCoordinate(r.price),l=this.chart.timeScale().timeToCoordinate(o.time),c=this.series.priceToCoordinate(o.price);if(null===n||null===a||null===l||null===c)return!1;const d=this.chart.timeScale().coordinateToTime(n+i),u=this.series.coordinateToPrice(a+s),p=this.chart.timeScale().coordinateToTime(l+i),w=this.series.coordinateToPrice(c+s);if(!(d&&u&&p&&w))return!1;if(this._p1.time===d&&this._p1.price===u&&this._p2.time===p&&this._p2.price===w)return!1;this._p1={time:d,price:u},this._p2={time:p,price:w},this._priceAxisLabelViews[0].movePoint(this._p1),this._timeAxisLabelViews[0].movePoint(this._p1),this._priceAxisLabelViews[1].movePoint(this._p2),this._timeAxisLabelViews[1].movePoint(this._p2),this.geometryVersion+=1,this.state="updating",t=!0}return t}addPoint({price:e,time:t}){this.drawPoints.push({price:e,time:t}),this.geometryVersion+=1,this.requestUpdate()}syncBoundsFromPoints(e){if(!e.length)return;const t=$(e[0]),i=e.reduce((e,t)=>{const i=Number(t.time),s=Number(e.p1.time),r=Number(e.p2.time);return i<s&&(e.p1.time=t.time),i>r&&(e.p2.time=t.time),t.price>e.p1.price&&(e.p1.price=t.price),t.price<e.p2.price&&(e.p2.price=t.price),e},{p1:$(t),p2:$(t)});this._p1=i.p1,this._p2=i.p2,this._priceAxisLabelViews[0].movePoint(this._p1),this._timeAxisLabelViews[0].movePoint(this._p1),this._priceAxisLabelViews[1].movePoint(this._p2),this._timeAxisLabelViews[1].movePoint(this._p2)}getMountedBrushPoints(){if(!this.brushData?.version)return null;const e=this.drawingTool.runtime.getChartDataTimes();return vt({anchorPoint:{time:Number(this.brushData.anchorPoint.time),price:this.brushData.anchorPoint.price},baseInterval:this.brushData.baseInterval,relativePoints:this.brushData.relativePoints},e,this.drawingTool.runtime.getSelectedTimeFrame())}syncBrushDataDerivedState(){if(!this.brushData?.version)return;const e=this.getMountedBrushPoints();e&&(this.brushData={version:e.version,anchorPoint:e.anchorPoint,mountedAnchorPoint:e.mountedAnchorPoint,baseInterval:e.baseInterval,relativePoints:e.relativePoints},this.drawPoints=e.points,this.syncBoundsFromPoints(e.points),this.geometryVersion+=1,this.requestUpdate())}getPersistedBrushData(e){return 2===this.brushData?.version?{version:2,anchorPoint:{time:Number(this.brushData.anchorPoint.time),price:this.brushData.anchorPoint.price},baseInterval:this.brushData.baseInterval,relativePoints:this.brushData.relativePoints}:mt(this.drawPoints,e)}updateBoundingPoints({price:e,time:t}){const i=this._p1,s=this._p2;if(!i||!s)return;const r=$(i),o=$(s),n=t,a=i.time,l=s.time;n<a&&(r.time=t),n>l&&(o.time=t),e>i.price&&(r.price=e),e<s.price&&(o.price=e);(r.price!==i.price||r.time!==i.time||o.price!==s.price||o.time!==s.time)&&(this._p1=r,this._p2=o,this._priceAxisLabelViews[0].movePoint(this._p1),this._timeAxisLabelViews[0].movePoint(this._p1),this._priceAxisLabelViews[1].movePoint(this._p2),this._timeAxisLabelViews[1].movePoint(this._p2),this.geometryVersion+=1)}updateSelectedState(){this.selected?(this._options.showPanes=!0,this._options.showLabels=!0):(this._options.showPanes=!1,this._options.showLabels=!1)}paneViews(){return this._paneViews}priceAxisViews(){return this._priceAxisLabelViews}timeAxisViews(){return this._timeAxisLabelViews}priceAxisPaneViews(){return this._priceAxisPaneViews}timeAxisPaneViews(){return this._timeAxisPaneViews}detached(){}updateAllViews(){this.updateSelectedState(),this._priceAxisLabelViews.forEach(e=>e.update()),this._timeAxisLabelViews.forEach(e=>e.update()),this._priceAxisPaneViews.forEach(e=>e.update()),this._timeAxisPaneViews.forEach(e=>e.update())}updateSelectedOptions(e){this.selected&&(Object.assign(this._options,{...this._options,...e}),this.state="updating",this.requestUpdate())}containPoint(e){const t=this._paneViews[0]?.brushPaneRenderer;if(!t)return!1;const i=t.smoothPoints.length>0?t.smoothPoints:t.getSmoothPoints(),s=xe()?this._options.touchNealDrawThreshold:this._options.nealDrawThreshold;return void 0!==i.find(t=>{const i=De(t,e);return null!==i&&i<=s})}selectedDraw(){this.selected=!0,this.selectCandidate=!0,this.drawingTool.runtime.setSelectedDrawOptions(this._options,ae.Brush)}getPoints(){return this.drawPoints}}class xt extends fe{type=ae.Brush;chart;series;options;runtime;persistence;brushes=[];boundingPoints=[];isMouseDown=!1;drawVisible=!0;primitiveUpdateScheduler=Ue();drawingUpdateScheduler;cursorScheduler=Be();pendingCreateOperations=new Set;unbindEvents;localRuntimeState={drawMode:ae.None,lockAllDraw:!1,selectedDrawMode:null,selectedDrawOptions:void 0};handleVisibleRangeChange=()=>{this.primitiveUpdateScheduler.schedule(this.brushes)};trackPendingCreate(e,t){const i=t.then(t=>{t&&(e.id=t.id,e.createdAt=t.created_at,e.state!==le.New?e.state===le.Updating&&this.checkUpdateDraw():e.state=le.Clean)}).finally(()=>{this.pendingCreateOperations.delete(i)});this.pendingCreateOperations.add(i)}constructor({chart:e,series:t,options:i,isDark:s,runtime:r,persistence:o}){super(),this.chart=e,this.series=t,this.options={...ue(s),...i},this.runtime=r??{getDrawMode:()=>this.localRuntimeState.drawMode,setDrawMode:e=>{this.localRuntimeState.drawMode=e},getLockAllDraw:()=>this.localRuntimeState.lockAllDraw,clearSelectedDrawing:()=>{this.localRuntimeState.selectedDrawMode=null,this.localRuntimeState.selectedDrawOptions=void 0},setSelectedDrawOptions:(e,t)=>{if(null===t)return this.localRuntimeState.selectedDrawMode=null,void(this.localRuntimeState.selectedDrawOptions=void 0);this.localRuntimeState.selectedDrawMode=t,this.localRuntimeState.selectedDrawOptions={...e}},getSelectedTimeFrame:()=>ce.OneMinute,getChartDataTimes:()=>[],getChartControlStateChangesLog:()=>[]},this.persistence=o??{createDrawing:async()=>null,updateDrawing:async()=>{},deleteDrawing:async()=>{}},this.drawingUpdateScheduler=Je(()=>this.brushes,this.persistence.updateDrawing,e=>({brush:e.getPersistedBrushData(this.runtime.getSelectedTimeFrame())??void 0,width:e._options.strokeWidth,color:e._options.strokeColor})),this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.subscribeEvents()}subscribeEvents(){this.unbindEvents=Qe({chart:this.chart,onClick:this.onClick,onCrosshairMove:this.onMouseMove,onVisibleRangeChange:this.handleVisibleRangeChange,onMouseDown:this.handleMouseDown,onMouseUp:this.handleMouseUp,onContextMenu:this.handleContextMenu,onTouchStart:this.handleTouchStart,onTouchMove:this.handleTouchMove,onTouchEnd:this.handleTouchEnd})}unsubscribeEvents(){this.unbindEvents?.(),this.unbindEvents=void 0}handleTouchStart=e=>{if(0===e.touches.length)return;this.chart.clearCrosshairPosition();const t=e.touches[0],i=ze(this.chart,t);qe(this.brushes,i),this.isDrawing()&&this.startBrushStroke(i),e.preventDefault()};handleTouchMove=e=>{if(0===e.touches.length)return;const t=e.touches[0],i=ze(this.chart,t);this.onMouseMove(We(this.chart,i)),e.preventDefault()};handleTouchEnd=()=>{$e(this.brushes),this.checkUpdateDraw(),this.isMouseDown=!1,this.isDrawing()&&this.finalizeBrushStroke()};handleMouseDown=e=>{const t=Ne(this.chart,e),{x:i,y:s}=t;Ke({primitives:this.brushes,isDrawing:this.isDrawing(),isPointerHit:e=>e.containPoint({x:i,y:s}),clearSelection:()=>this.unSelectAnyDraw()}),qe(this.brushes,{x:i,y:s}),this.isDrawing()&&this.startBrushStroke(t)};handleMouseUp=()=>{$e(this.brushes),this.checkUpdateDraw(),this.isMouseDown=!1,this.isDrawing()&&this.finalizeBrushStroke()};handleContextMenu=e=>{const t=Ne(this.chart,e),{x:i,y:s}=t;if(je(this.brushes,e=>e.containPoint({x:i,y:s}))){this.unSelectAnyDraw();const t=this.brushes.find(e=>e.containPoint({x:i,y:s}));t&&(t.selected=!0,this.runtime.setSelectedDrawOptions({strokeWidth:t._options.strokeWidth,strokeColor:t._options.strokeColor},ae.Brush)),e.preventDefault(),e.stopPropagation()}};isDrawing(){return this.runtime.getDrawMode()===ae.Brush}startDrawing(){this.runtime.setDrawMode(ae.Brush)}stopDrawing(){this.boundingPoints=[],this.runtime.setDrawMode(ae.None)}onClick(e){e.point&&e.time}onMouseMove(e){this.brushes.forEach(t=>{t.onMouseMove(e)}),this.mouseStyling();const t=this.brushes.some(e=>e.selected);if(!this.isMouseDown||t)return;const{time:i,point:s}=e;if(i&&s){const e=Ie(this.chart,this.series,s);if(!e)return;this.handleBoundingPoints(e);const t=this.brushes[this.brushes.length-1],i=t.drawPoints[t.drawPoints.length-1];if(i&&i.time===e.time&&i.price===e.price)return;const r=t.drawPoints[t.drawPoints.length-1]?.price;if(r&&Math.abs(r-e.price)<0)return;t.addPoint(e)}}startBrushStroke(e){const t=Ie(this.chart,this.series,e);if(!t)return;if(this.boundingPoints.push({...t}),this.boundingPoints.push({...t}),this.isMouseDown=!0,this.brushes.some(e=>e.selected))return;const i=new Pt({state:"new",drawPoints:[t],drawingTool:this,boundingPoints:this.boundingPoints});He(this.series,this.brushes,i),this.chart.applyOptions({handleScroll:!1})}finalizeBrushStroke(){this.chart.applyOptions({handleScroll:!0});const e=this.brushes[this.brushes.length-1];if(e){e.selectedDraw();const t=mt(e.drawPoints,this.runtime.getSelectedTimeFrame());t&&this.trackPendingCreate(e,Ze(this.persistence.createDrawing,we.Brush,{brush:t,width:e._options.strokeWidth,color:e._options.strokeColor}))}this.stopDrawing()}handleBoundingPoints({price:e,time:t}){const i=this.boundingPoints,s=i[0],r=i[1],o=$(s),n=$(r),a=t,l=s.time,c=r.time;a<l&&(o.time=t),a>c&&(n.time=t),e>s.price&&(o.price=e),e<r.price&&(n.price=e),i[0].price=o.price,i[0].time=o.time,i[1].price=n.price,i[1].time=n.time}getInitBoundingPoints(e){if(0===e.length)return;const t=$(e[0]),i=$(e[0]);for(const s of e){const e=s.time,r=t.time,o=i.time;e<r&&(t.time=s.time),e>o&&(i.time=s.time),s.price>t.price&&(t.price=s.price),s.price<i.price&&(i.price=s.price)}return[t,i]}initData(e){e&&0!==e.length&&e.forEach(e=>{const{data:t}=e;if(!t.points||0===t.points.length)return;const i=$(t.points),s=this.getInitBoundingPoints(i);if(!s)return;const r=t.selected||!1,o=new Pt({drawPoints:i,boundingPoints:s,brushData:t.brush,id:e.id,drawingTool:this,createdAt:t.createdAt,options:t.options,selected:r,state:"clean"});this.series.attachPrimitive(o),this.brushes.push(o),2===t.brush?.version&&o.syncBrushDataDerivedState(),r&&o.selectedDraw()})}checkUpdateDraw(){this.drawingUpdateScheduler.schedule()}toggleDrawVisible(){this.drawVisible=et(this.drawVisible,this.brushes,this.primitiveUpdateScheduler)}toggleSelectedDrawLocked(){tt(this.brushes)&&this.checkUpdateDraw()}toggleAllDrawLocked(e){it(this.brushes,e)&&this.checkUpdateDraw()}isAnyDrawSelected(){return st(this.brushes)}updateSelectedOptions(e){this.brushes.forEach(t=>{t.updateSelectedOptions({...t._options,...e})}),this.checkUpdateDraw()}async flushPendingUpdates(){this.pendingCreateOperations.size>0&&await Promise.allSettled([...this.pendingCreateOperations]),await this.drawingUpdateScheduler.flush()}mouseStyling(){const e=this.brushes.some(e=>e.hovered);this.cursorScheduler.setCursor(e?"pointer":"default")}unSelectAnyDraw(){rt(this.brushes,this.runtime.clearSelectedDrawing)}cleanPrimitives(){this.brushes=ot(this.series,this.brushes,this.runtime.clearSelectedDrawing)}cleanAll(){this.unsubscribeEvents(),this.primitiveUpdateScheduler.cancel(),this.drawingUpdateScheduler.cancel(),this.isMouseDown=!1,this.boundingPoints=[],this.chart.applyOptions({handleScroll:!0}),this.cursorScheduler.reset(),this.cleanPrimitives()}async removeSelectedDraw(){this.brushes=await nt(this.series,this.brushes,e=>this.persistence.deleteDrawing(e))}}class yt{source;centerRenderer;constructor(e){this.source=e,this.centerRenderer=new Le({source:e,style:{strokeColor:this.source._options.strokeColor??"blue",radius:4}})}draw(e){this.source.drawingTool.drawVisible&&e.useBitmapCoordinateSpace(e=>{const t=this.source._p1,i=this.source._options,s=e.context,r=this.source.textValue.split(/\r?\n/),o=this.source.chart.timeScale().timeToCoordinate(t.time),n=this.source.series.priceToCoordinate(t.price);s.textAlign="left",s.textBaseline="top";const a=i.textSize*e.verticalPixelRatio;s.font=`${a}px Open Sans`,s.fillStyle=i.textColor,this.centerRenderer.style.strokeColor=this.source._options.textColor;const l=.2*i.textSize,c=i.textSize+l,d=r.map(t=>s.measureText(t||" ").width/e.horizontalPixelRatio),u=Math.max(...d),p=i.textSize+(r.length-1)*c,w=o+u+8,m=n+p+8;this.source._p2={time:this.source.chart.timeScale().coordinateToTime(w),price:this.source.series.coordinateToPrice(m)},r.forEach((t,i)=>{const r=(o+4)*e.horizontalPixelRatio,a=(n+4+i*c)*e.verticalPixelRatio;s.fillText(t,r,a)}),(this.source.hovered||this.source.selected)&&this.centerRenderer.draw(e,(o+w)/2,m+c/3)})}}class ft{source;textPaneRenderer;dynamicZOrder="normal";constructor(e){this.source=e,this.textPaneRenderer=new yt(e)}renderer(){return this.textPaneRenderer}zOrder(){return this.dynamicZOrder}}class _t extends ye{_paneViews;hoverCandidate=!1;hovered=!1;selectCandidate=!1;selected=!1;id;localId;createdAt;state;drawingTool;textValue;dragPoint;cornerPointBeforeDrag;constructor({textValue:e,cornerPoint:t,drawingTool:i,state:s,id:r,createdAt:o,selected:n,options:a}){super(),this.id=r,this.createdAt=o||Date.now(),this.localId=i.type+"-"+this.createdAt,this.state=s||"new",this.drawingTool=i,this.textValue=e,this.selected=n||!1,this._paneViews=[new ft(this)],this._options=$({...i.options,...a}),this._p1=t}paneViews(){return this._paneViews}containTimePoint(e){let t=!1;if(this._p1.time&&this._p2.time){const i=this._p1.time,s=this._p2.time,r=this._p1.price,o=this._p2.price,n=e.time,a=e.price;t=n>=i&&n<=s&&(a<=r&&a>=o)}if(this._p1.time&&!this._p2.time){const i=e.time>=this._p1.time,s=e.price<=this._p1.price&&e.price>=this._p2.price;t=i&&s}return t}onMouseMove(e){const{time:t,point:i}=e;if(this._options.locked||this.drawingTool.runtime.getLockAllDraw()||!i||!t)return;const s=this.series.coordinateToPrice(i.y),r=this.containTimePoint({time:t,price:s}),o=this.hoverCandidate,n=this.hovered;this.hoverCandidate=r,r||(this.hovered=r);const a=this.handleDrag(i),l=o!==this.hoverCandidate||n!==this.hovered;(a||l)&&this.requestUpdate()}onMouseDown(e){this.dragPoint=e,this.cornerPointBeforeDrag=$(this._p1);const t={time:this.chart.timeScale().coordinateToTime(e.x),price:this.series.coordinateToPrice(e.y)};this.containTimePoint(t)?(this.selectCandidate=!0,this.chart.applyOptions({handleScroll:!1})):(this.selectCandidate=!1,this.selected=!1,this.hovered=!1,this.hoverCandidate=!1)}onMouseUp(){this.selectCandidate&&!this.selected&&this.selectedDraw(),this.dragPoint=void 0,this.hovered=!1,this.hoverCandidate=!1,this.selectCandidate=!1,this.chart.applyOptions({handleScroll:!0}),this.requestUpdate()}handleDrag(e){let t=!1;if(this.selected&&this.dragPoint&&this.cornerPointBeforeDrag){const i=e.x-this.dragPoint.x,s=e.y-this.dragPoint.y,r=this.chart.timeScale().timeToCoordinate(this.cornerPointBeforeDrag.time),o=this.series.priceToCoordinate(this.cornerPointBeforeDrag.price);if(null===r||null===o)return!1;const n={time:this.chart.timeScale().coordinateToTime(r+i),price:this.series.coordinateToPrice(o+s)};if(!n.time||!n.price)return!1;if(this._p1.time===n.time&&this._p1.price===n.price)return!1;this._p1.price=n.price,this._p1.time=n.time,this.state="updating",t=!0}return t}selectedDraw(){this.selected=!0,this.selectCandidate=!0,this.drawingTool.runtime.setSelectedDrawOptions(this._options,ae.Text)}getPoints(){return[this._p1]}updateSelectedOptions(e){this.selected&&(Object.assign(this._options,{...this._options,...e}),this.state="updating",this.requestUpdate())}}class St extends fe{type=ae.Text;chart;series;options;runtime;persistence;texts=[];textArea=null;currentText="";currentCorner;isMouseDown=!1;drawVisible=!0;primitiveUpdateScheduler=Ue();drawingUpdateScheduler;pendingCreateOperations=new Set;unbindEvents;ownsTextArea=!1;localRuntimeState={drawMode:ae.None,lockAllDraw:!1,selectedDrawMode:null,selectedDrawOptions:void 0};handleVisibleRangeChange=()=>{this.primitiveUpdateScheduler.schedule(this.texts)};buildTextPayload(e,t,i=this.options.textColor){return{cornerPoint:Xe([e])[0],value:t,color:i}}trackPendingCreate(e,t){const i=t.then(t=>{t&&(e.id=t.id,e.createdAt=t.created_at,e.state!==le.New?e.state===le.Updating&&this.checkUpdateDraw():e.state=le.Clean)}).finally(()=>{this.pendingCreateOperations.delete(i)});this.pendingCreateOperations.add(i)}ensureTextAreaElement(){const e=document.getElementById("textarea-tool");if(e)return this.ownsTextArea=!1,e;const t=document.createElement("textarea");t.id=`textarea-tool-${Date.now()}-${Math.floor(1e3*Math.random())}`,t.style.display="none",t.style.position="absolute",t.style.zIndex="9999",t.style.minWidth="200px",t.style.minHeight="60px",t.style.padding="8px",t.style.fontSize="14px",t.style.border="1px solid #ccc",t.style.borderRadius="4px",t.style.background="white",t.style.color="black",t.style.opacity="0.6";return(this.chart.chartElement().parentElement??this.chart.chartElement()).appendChild(t),this.ownsTextArea=!0,t}constructor({chart:e,series:t,options:i,isDark:s,runtime:r,persistence:o,textArea:n}){super(),this.chart=e,this.series=t,this.options={...ue(s),...i},this.runtime=r??{getDrawMode:()=>this.localRuntimeState.drawMode,setDrawMode:e=>{this.localRuntimeState.drawMode=e},getLockAllDraw:()=>this.localRuntimeState.lockAllDraw,clearSelectedDrawing:()=>{this.localRuntimeState.selectedDrawMode=null,this.localRuntimeState.selectedDrawOptions=void 0},setSelectedDrawOptions:(e,t)=>{if(null===t)return this.localRuntimeState.selectedDrawMode=null,void(this.localRuntimeState.selectedDrawOptions=void 0);this.localRuntimeState.selectedDrawMode=t,this.localRuntimeState.selectedDrawOptions={...e}},getSelectedTimeFrame:()=>ce.OneMinute,getChartDataTimes:()=>[],getChartControlStateChangesLog:()=>[]},this.persistence=o??{createDrawing:async()=>null,updateDrawing:async()=>{},deleteDrawing:async()=>{}},this.drawingUpdateScheduler=Je(()=>this.texts,this.persistence.updateDrawing,e=>this.buildTextPayload(e._p1,e.textValue,e._options.textColor)),this.textArea=n??this.ensureTextAreaElement(),this.onClick=this.onClick.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.subscribeEvents()}subscribeEvents(){this.unbindEvents=Qe({chart:this.chart,onClick:this.onClick,onCrosshairMove:this.onMouseMove,onVisibleRangeChange:this.handleVisibleRangeChange,onMouseDown:this.handleMouseDown,onMouseUp:this.handleMouseUp,onContextMenu:this.handleContextMenu,onTouchStart:this.handleTouchStart,onTouchMove:this.handleTouchMove,onTouchEnd:this.handleTouchEnd,textArea:this.textArea,onTextAreaChange:this.handleTextAreaChange,onTextAreaBlur:this.handleTextAreaBlur})}unsubscribeEvents(){this.unbindEvents?.(),this.unbindEvents=void 0}handleTouchStart=e=>{if(0===e.touches.length)return;this.chart.clearCrosshairPosition();const t=e.touches[0],i=ze(this.chart,t);qe(this.texts,i),e.preventDefault()};handleTouchMove=e=>{if(0===e.touches.length)return;const t=e.touches[0],i=ze(this.chart,t);this.onMouseMove(We(this.chart,i)),e.preventDefault()};handleTouchEnd=e=>{if(0===e.changedTouches.length)return;const t=e.changedTouches[0],i=ze(this.chart,t),s=this.chart.timeScale().coordinateToTime(i.x);if(this.textArea&&this.isDrawing()&&this.currentText){const e=document.elementFromPoint(t.clientX,t.clientY);if(!this.textArea.contains(e))return void this.addNewText()}s&&this.isDrawing()&&this.onClick(We(this.chart,i)),this.drawVisible&&(this.chart.applyOptions({handleScroll:!0}),$e(this.texts),this.checkUpdateDraw())};handleMouseDown=e=>{const t=Ne(this.chart,e),{x:i,y:s}=t;if(qe(this.texts,{x:i,y:s}),!this.textArea)return;const r=!this.textArea?.contains(e.target);!this.textArea&&this.isDrawing()&&r&&this.currentText&&this.addNewText()};handleMouseUp=()=>{this.drawVisible&&(this.chart.applyOptions({handleScroll:!0}),$e(this.texts),this.checkUpdateDraw())};handleContextMenu=e=>{const t=Ne(this.chart,e),{x:i,y:s}=t;if(je(this.texts,e=>e.containPoint({x:i,y:s}))){this.unSelectAnyDraw();const t=this.texts.find(e=>e.containPoint({x:i,y:s}));t&&(t.selected=!0,this.runtime.setSelectedDrawOptions({strokeColor:t._options.strokeColor},ae.Text)),e.preventDefault(),e.stopPropagation()}};handleTextAreaChange=e=>{this.currentText=e.target.value};handleTextAreaBlur=()=>{this.addNewText(),this.checkUpdateDraw()};addNewText(){const e=this.currentCorner?.price,t=this.currentCorner?.time;if(!e||!t)return;const i=new _t({textValue:this.currentText,cornerPoint:{time:t,price:e},drawingTool:this,state:"new"});Ye(this.series,this.texts,i),this.trackPendingCreate(i,Ze(this.persistence.createDrawing,we.Text,this.buildTextPayload({time:t,price:e},this.currentText,i._options.textColor))),this.stopDrawing()}isDrawing(){return this.runtime.getDrawMode()===ae.Text}startDrawing(){this.runtime.setDrawMode(ae.Text)}stopDrawing(){this.currentText="",this.currentCorner=void 0,this.textArea&&(this.textArea.style.display="none",this.textArea.value=""),this.runtime.setDrawMode(ae.None)}onClick(e){if(!e.point||!e.time||!this.isDrawing())return;if(this.isAnyDrawSelected())this.textArea&&(this.textArea.style.display="none");else if(this.textArea){const t=Ie(this.chart,this.series,e.point);if(!t)return;this.currentCorner=t,this.textArea.style.left=`${e.point.x}px`,this.textArea.style.top=`${e.point.y}px`,this.textArea.style.display="block",this.textArea.focus()}}onMouseMove(e){0!==this.texts.length&&this.drawVisible&&this.texts.forEach(t=>{t.onMouseMove(e)})}initData(e){e&&0!==e.length&&e.forEach(e=>{const{data:t}=e;if(!t.cornerPoint||!t.value)return;const i=t.selected||!1,s=new _t({id:e.id,textValue:t.value,cornerPoint:t.cornerPoint,drawingTool:this,createdAt:t.createdAt,options:t.options,selected:i,state:"clean"});i&&s.selectedDraw(),this.series.attachPrimitive(s),this.texts.push(s)})}checkUpdateDraw(){this.drawingUpdateScheduler.schedule()}toggleDrawVisible(){this.drawVisible=et(this.drawVisible,this.texts,this.primitiveUpdateScheduler)}toggleSelectedDrawLocked(){tt(this.texts)&&this.checkUpdateDraw()}toggleAllDrawLocked(e){it(this.texts,e)&&this.checkUpdateDraw()}isAnyDrawSelected(){return st(this.texts)}updateSelectedOptions(e){this.texts.forEach(t=>{t.updateSelectedOptions({...t._options,...e})}),this.checkUpdateDraw()}async flushPendingUpdates(){this.pendingCreateOperations.size>0&&await Promise.allSettled([...this.pendingCreateOperations]),await this.drawingUpdateScheduler.flush()}unSelectAnyDraw(){rt(this.texts,this.runtime.clearSelectedDrawing)}cleanPrimitives(){this.texts=ot(this.series,this.texts,this.runtime.clearSelectedDrawing)}cleanAll(){this.unsubscribeEvents(),this.primitiveUpdateScheduler.cancel(),this.drawingUpdateScheduler.cancel(),this.chart.applyOptions({handleScroll:!0}),document.body.style.cursor="default",this.cleanTextArea(),this.cleanPrimitives()}async removeSelectedDraw(){this.texts=await nt(this.series,this.texts,e=>this.persistence.deleteDrawing(e))}cleanTextArea(){this.textArea&&(this.textArea.style.display="none",this.textArea.value="",this.currentText="",this.currentCorner=void 0,this.ownsTextArea&&(this.textArea.remove(),this.textArea=null,this.ownsTextArea=!1))}}const Ct=(e,t)=>(e=>"object"==typeof e&&null!==e)(e)&&"function"==typeof e[t],Tt=e=>e.value,kt=e=>null===e?null:e,Mt=e=>null===e?null:e,At=s=>{const r=e(ae.None),o=e(!1),n=e(!0),a=e(null),l=e(void 0),c=new Map,d=e(0),u=()=>{a.value=null,l.value=void 0},p=()=>{c.forEach(e=>{e.unSelectAnyDraw()}),u()},w=(e,t)=>{c.get(e)?.cleanAll(),c.set(e,t),d.value+=1},m=e=>c.get(e),g=e=>{c.forEach((t,i)=>e(t,i))},v={getDrawMode:()=>Mt(r.value)??ae.None,setDrawMode:e=>{r.value=kt(e)??ae.None},getLockAllDraw:()=>o.value,clearSelectedDrawing:()=>{u()},setSelectedDrawOptions:(e,t=Mt(a.value))=>{e&&null!==t?(a.value=kt(t),l.value={...e}):u()},getSelectedTimeFrame:()=>Tt(s.selectedTimeFrame),getChartDataTimes:()=>Tt(s.chartDataTimes),getChartControlStateChangesLog:()=>[]},D=i(()=>(d.value,{line:m(ae.Line),brush:m(ae.Brush),text:m(ae.Text)})),b=async()=>{const e=[];c.forEach(t=>{e.push(t.flushPendingUpdates())}),e.length>0&&await Promise.allSettled(e)},P=()=>{c.forEach(e=>{e.cleanAll()}),c.clear(),d.value+=1,r.value=ae.None,u()},x=()=>{const t=Tt(s.chart),i=Tt(s.series);if(!(r=t,Ct(r,"subscribeClick")&&Ct(r,"unsubscribeClick")&&Ct(r,"subscribeCrosshairMove")&&Ct(r,"unsubscribeCrosshairMove")&&Ct(r,"timeScale")&&(e=>Ct(e,"attachPrimitive")&&Ct(e,"detachPrimitive")&&Ct(e,"priceToCoordinate")&&Ct(e,"coordinateToPrice"))(i)))return;var r;const a=t,l=i,d={priceLabelFormatter:e=>e.toFixed(2)};w(ae.Line,new at({chart:a,series:l,options:d,isDark:Tt(s.isDark??e(void 0)),runtime:v,persistence:s.persistence})),w(ae.Brush,new xt({chart:a,series:l,options:d,isDark:Tt(s.isDark??e(void 0)),runtime:v,persistence:s.persistence})),w(ae.Text,new St({chart:a,series:l,options:d,isDark:Tt(s.isDark??e(void 0)),runtime:v,persistence:s.persistence})),(()=>{const e=Array.from(c.values());n.value||e.forEach(e=>e.toggleDrawVisible()),o.value&&e.forEach(e=>e.toggleAllDrawLocked(!0))})()},y={line:ae.Line,brush:ae.Brush,text:ae.Text},f=e=>(e??[]).flatMap(e=>{const t=ht(e.time);return null===t?[]:[{time:t,price:e.price}]}),_=(e,t)=>{const i={..."number"==typeof e.data?.width?{strokeWidth:e.data.width}:{},..."string"==typeof e.data?.color?"text"===e.draw_type?{textColor:e.data.color}:{strokeColor:e.data.color}:{}},r=Object.keys(i).length?i:void 0;if("brush"===e.draw_type){const i=f(e.data?.points),o=e.data?.brush,n=2===o?.version?(()=>{const e=ht(o.anchorPoint.time);return null===e?null:{...o,anchorPoint:{...o.anchorPoint,time:e}}})():mt(i,((e,t=ce.OneMinute)=>{const i=wt(e),s=[...new Set(i.map(e=>e.time))].sort((e,t)=>e-t),r=s.slice(1).map((e,t)=>e-s[t]).filter(e=>e>0);if(!r.length)return t;const o=Math.min(...r);return ut.reduce((e,t)=>{const i=Math.floor(lt(t)/1e3);return Math.abs(i-o)<Math.abs(Math.floor(lt(e)/1e3)-o)?t:e},t)})(i,Tt(s.selectedTimeFrame))),a=n?vt(n,t,Tt(s.selectedTimeFrame)):null;return{id:e.id,Login:e.user_id,symbol:e.symbol,draw_type:y[e.draw_type],data:{points:a?.points,brush:a?{version:a.version,anchorPoint:a.anchorPoint,mountedAnchorPoint:a.mountedAnchorPoint,baseInterval:a.baseInterval,relativePoints:a.relativePoints}:void 0,value:e.data?.value,options:r,createdAt:e.created_at}}}const o=((e,t)=>e.length&&t.length?e.map(e=>dt(e,t)):e)(f(e.data?.points),t);return{id:e.id,Login:e.user_id,symbol:e.symbol,draw_type:y[e.draw_type],data:{points:o,value:e.data?.value,options:r,cornerPoint:e.data?.cornerPoint?dt({time:ht(e.data.cornerPoint.time)??e.data.cornerPoint.time,price:e.data.cornerPoint.price},t):o[0],createdAt:e.created_at}}},S=e=>{const t=m(ae.Line),i=m(ae.Brush),r=m(ae.Text),o=Tt(s.chartDataTimes);t?.cleanPrimitives(),i?.cleanPrimitives(),r?.cleanPrimitives();const n=e.map(e=>_(e,o)),a=n.filter(e=>e.draw_type===ae.Line),l=n.filter(e=>e.draw_type===ae.Brush),c=n.filter(e=>e.draw_type===ae.Text);t?.initData(a),i?.initData(l),r?.initData(c)},C=async()=>{Tt(s.symbol)?(await b(),await s.loadDrawings(),S(Tt(s.drawings))):S([])},T={setDrawMode:e=>{r.value=e},setLockAllDraw:e=>{o.value=e,g(t=>{t.toggleAllDrawLocked(e)})},setDrawVisible:e=>{n.value!==e&&(n.value=e,g(e=>{e.toggleDrawVisible()}))},clearSelectedDrawing:()=>{p()},setSelectedDrawOptions:(e,t)=>{e&&null!==t?(a.value=t,l.value={...e}):u()},deleteAllDrawings:async()=>{await s.deleteAllDrawings(),g(e=>{e.stopDrawing(),e.cleanPrimitives()}),r.value=ae.None,u()}},k=i(()=>{const e=Tt(s.chartDataTimes);return e.length?`${e[0]}-${e[e.length-1]}-${e.length}`:"0"});return t([()=>Tt(s.chart),()=>Tt(s.series)],async()=>{await b(),P(),x(),await C()},{immediate:!0}),t(()=>Tt(s.symbol),async(e,t)=>{e!==t&&await C()}),t([()=>Tt(s.selectedTimeFrame),k],()=>{0!==c.size&&S(Tt(s.drawings))}),t(()=>Tt(s.isDark??e(void 0)),async()=>{0!==c.size&&(await b(),P(),x(),S(Tt(s.drawings)))}),{drawMode:i(()=>r.value),lockAllDraw:i(()=>o.value),drawVisible:i(()=>n.value),selectedDrawMode:i(()=>a.value),selectedDrawOptions:i(()=>l.value),drawingTools:D,runtime:T,refreshDrawings:C,setDrawMode:e=>{const t=Mt(e)??ae.None,i=Mt(r.value)??ae.None;if(i!==ae.None&&m(i)?.stopDrawing(),t===ae.None||i===t)return void(r.value=ae.None);const s=m(t);s?(s.startDrawing(),r.value=t):r.value=ae.None},clearSelectedDrawing:p}},Lt=o({__name:"index",props:{chart:{},series:{},symbol:{},selectedTimeFrame:{},chartDataTimes:{},drawings:{},createDrawing:{},updateDrawing:{},deleteDrawing:{},loadDrawings:{},deleteAllDrawings:{},isDark:{type:Boolean},floatingTarget:{default:null},floatingLayerStyle:{default:()=>({})},showSidebar:{type:Boolean,default:!0},showFloatingToolbar:{type:Boolean,default:!0}},emits:["stateChange"],setup(e,{expose:s,emit:r}){const o=e,n=r,{drawMode:a,lockAllDraw:d,drawVisible:m,selectedDrawMode:v,selectedDrawOptions:b,drawingTools:P,runtime:y,refreshDrawings:_,setDrawMode:k,clearSelectedDrawing:M}=At({chart:S(o,"chart"),series:S(o,"series"),symbol:S(o,"symbol"),selectedTimeFrame:S(o,"selectedTimeFrame"),chartDataTimes:S(o,"chartDataTimes"),drawings:S(o,"drawings"),persistence:{createDrawing:o.createDrawing,updateDrawing:o.updateDrawing,deleteDrawing:o.deleteDrawing},loadDrawings:o.loadDrawings,deleteAllDrawings:o.deleteAllDrawings,isDark:S(o,"isDark")}),A=i(()=>o.showSidebar),L=i(()=>({position:"absolute",left:"0px",right:"0px",top:"0px",bottom:"0px",height:"auto",zIndex:20,...o.floatingLayerStyle??{}})),V=i(()=>C(o.floatingTarget)?o.floatingTarget.value:o.floatingTarget??null),E=i(()=>!!V.value),O=i(()=>!!o.showFloatingToolbar&&(!!V.value||!o.showSidebar)),R=i(()=>V.value??"body");return t([a,d,m,v,b],([e,t,i,s,r])=>{n("stateChange",{drawMode:e,lockAllDraw:t,drawVisible:i,selectedDrawMode:s,selectedDrawOptions:r})},{immediate:!0}),s({refreshDrawings:_,setDrawMode:k,clearSelectedDrawing:M}),(e,t)=>(l(),c(w,null,[A.value?(l(),D(ne,{key:0,"draw-mode":u(a),"lock-all-draw":u(d),"draw-visible":u(m),"selected-draw-mode":u(v),"selected-draw-options":u(b),"drawing-tools":u(P),runtime:u(y),"show-floating-toolbar":!1,"show-sidebar":!0},null,8,["draw-mode","lock-all-draw","draw-visible","selected-draw-mode","selected-draw-options","drawing-tools","runtime"])):x("",!0),O.value?(l(),D(T,{key:1,to:R.value,disabled:!E.value},[p("div",{class:"custom-drawing-overlay-widget__floating-layer",style:f(L.value)},[g(ne,{"draw-mode":u(a),"lock-all-draw":u(d),"draw-visible":u(m),"selected-draw-mode":u(v),"selected-draw-options":u(b),"drawing-tools":u(P),runtime:u(y),"show-floating-toolbar":!0,"show-sidebar":!1},null,8,["draw-mode","lock-all-draw","draw-visible","selected-draw-mode","selected-draw-options","drawing-tools","runtime"])],4)],8,["to","disabled"])):x("",!0)],64))}});export{K as D,Lt as _,At as a,Y as p,X as u};
@@ -1 +1 @@
1
- import{computed as e,provide as t,inject as l,defineComponent as o,shallowRef as s,ref as a,watch as i,resolveComponent as r,openBlock as c,createElementBlock as n,createElementVNode as m,createVNode as u,unref as d,createSlots as p,withCtx as v,toDisplayString as y,normalizeClass as b,normalizeStyle as g,Fragment as w,renderList as _,createBlock as f,withDirectives as S,withModifiers as k}from"vue";import{a as C}from"./vendor-vueuse-core-B96HGhR7.mjs";import x from"../composite/EaeraDropdownV2.mjs";import{_ as I}from"./EaeraInput-CkbcAxy0.mjs";import{useI18n as E}from"vue-i18n";import"element-plus";import{ElLoadingDirective as H}from"element-plus/es";import"@lucide/vue";import"./vendor-email-misspelled-0hsXkSSK.mjs";import"./vendor-unorm-Degftfa1.mjs";import"./useEaeraInputPhoneNumber-B72aLnQs.mjs";import"@element-plus/icons-vue";import"echarts/core";import"echarts/renderers";import"echarts/charts";import"echarts/components";import"vue-echarts";import"./vendor-currency-symbol-map-C-1fEG2R.mjs";import{_ as R}from"./EaeraTableV2-BqxbiWNA.mjs";import{_ as D}from"./EaeraTooltip-BIlULHv4.mjs";const G=Symbol("EAERA_WATCHLIST_CONTEXT_KEY"),T=(l,o)=>{const s={inputPlaceholder:e(()=>l.inputPlaceholder),searchData:e(()=>l.searchData),categories:e(()=>l.categories),selectedCategory:e(()=>l.selectedCategory),isFiltered:e(()=>l.isFiltered),tableHeight:e(()=>l.tableHeight),viewingSymbols:e(()=>l.viewingSymbols),viewingSymbolGroups:e(()=>l.viewingSymbolGroups),listSymbols:e(()=>l.listSymbols),groupLoadingRowIds:e(()=>l.groupLoadingRowIds),favoriteSymbolIds:e(()=>l.favoriteSymbolIds),viewingSymbolId:e(()=>l.viewingSymbolId),listSymbolsLoading:e(()=>l.listSymbolsLoading),sorting:e(()=>l.sorting),onResize:(e,t)=>o("resize",e,t),onSelectCategory:e=>o("selectCategory",e),onSearchDataUpdate:e=>o("update:searchData",e),onGroupExpandChange:e=>o("groupExpandChange",e),onGroupRowClick:e=>o("groupRowClick",e),onGroupSortChanged:e=>o("groupSortChanged",e),onItemSortChanged:e=>o("itemSortChanged",e),onSelectSymbol:e=>o("selectSymbol",e),onToggleFavorite:e=>o("toggleFavorite",e),onShowSymbolInfo:e=>o("showSymbolInfo",e)};return t(G,s),s},j=()=>{const e=l(G);if(!e)throw new Error("useEaeraWatchlist must be used inside EaeraWatchlist");return e},W={class:"custom-watchlist-filter"},F={class:"custom-watchlist-filter__row"},L={class:"custom-watchlist-filter__field"},z={class:"custom-watchlist-filter__field"},U=["onClick"],A={class:"custom-watchlist-filter__category-count"},N={class:"custom-watchlist-filter__dropdown-trigger-content"},B={key:0,class:"custom-watchlist-filter__selected"},V={key:1,class:"custom-watchlist-filter__placeholder"},P=o({__name:"EaeraWatchlistFilter",setup(e){const{inputPlaceholder:t,searchData:l,categories:o,selectedCategory:f,onSelectCategory:S,onSearchDataUpdate:k}=j(),C=s(),E=a(!1),H=a(!1),R=a(""),D=a(!1);i(l,e=>{e!==R.value&&(R.value=e)},{immediate:!0});const G=e=>{D.value||k(e)},T=()=>D.value=!0,P=e=>k(e.data),K=e=>{D.value=!1;const t=e.data??R.value;k(t)};return(e,s)=>{const a=r("eaera-icon"),i=I,k=x;return c(),n("div",W,[m("div",F,[m("div",L,[u(i,{modelValue:R.value,"onUpdate:modelValue":s[0]||(s[0]=e=>R.value=e),class:"watchlist-input",placeholder:d(t),clearable:"",onInput:G,onCompositionstart:T,onCompositionupdate:P,onCompositionend:K},p({_:2},[d(l)?void 0:{name:"suffix",fn:v(()=>[u(a,{icon:"Search2",size:"16",class:"icon-primary"})]),key:"0"}]),1032,["modelValue","placeholder"])]),m("div",z,[u(k,{class:"custom-watchlist-filter__dropdown","popper-class":"with-border",onVisibleChange:s[4]||(s[4]=e=>E.value=e)},{dropdown:v(()=>[m("div",{class:"custom-watchlist-filter__dropdown-menu",style:g({width:`${C.value?.clientWidth??100}px`})},[(c(!0),n(w,null,_(d(o),e=>(c(),n("div",{key:e.id,class:"custom-watchlist-filter__category"},[m("div",{class:"custom-watchlist-filter__category-content label-md",onClick:t=>d(S)(e)},[m("div",null,y(e.name),1),m("div",A,y(e.count),1)],8,U)]))),128))],4)]),default:v(()=>[m("div",{ref_key:"dropdownRef",ref:C,class:"custom-watchlist-filter__dropdown-trigger"},[m("div",N,[d(f)?.name?(c(),n("span",B,y(d(f).name),1)):(c(),n("span",V,y(e.$t("watch-list.filter.categories")),1)),m("div",{class:"custom-watchlist-filter__icon-wrapper",onMouseenter:s[1]||(s[1]=e=>H.value=!0),onMouseleave:s[2]||(s[2]=e=>H.value=!1),onClick:s[3]||(s[3]=e=>d(S)(null))},[u(a,{icon:H.value&&d(f)?"XCircle":"ChevronDown",size:"16",class:b(["icon-primary","custom-watchlist-filter__dropdown-icon",E.value&&"is-open"])},null,8,["icon","class"])],32)])],512)]),_:1})])])])}}}),K={class:"custom-watchlist-table"},M={key:0,class:"custom-watchlist-table__group"},O={key:1,class:"custom-watchlist-table__items"},$=o({__name:"EaeraWatchlistTable",setup(e){const{isFiltered:t,tableHeight:l,viewingSymbols:o,listSymbolsLoading:s}=j();return(e,a)=>(c(),n("div",K,[d(t)?(c(),n("div",O,[u(d(de),{symbols:d(o),"max-height":d(l),loading:d(s),"show-header":""},null,8,["symbols","max-height","loading"])])):(c(),n("div",M,[u(d(te))]))]))}}),X={class:"custom-watchlist-group-table__symbol-cell"},Y={class:"custom-watchlist-group-table__symbol body-md__w"},q={class:"custom-watchlist-group-table__name body-sm"},J={key:0},Q={class:"custom-watchlist-group-table__empty"},Z={class:"custom-watchlist-group-table__empty-content"},ee={class:"custom-watchlist-group-table__empty-text body-sm"},te=o({__name:"EaeraWatchlistGroupTable",setup(t){const{tableHeight:l,viewingSymbolGroups:o,listSymbols:s,groupLoadingRowIds:p,sorting:b,onGroupExpandChange:g,onGroupRowClick:w,onGroupSortChanged:_}=j(),{t:S}=E(),k=a(),C=({columnIndex:e})=>0===e?[1,1]:1===e?[1,4]:[0,0],x=e=>{g(e)},I=async e=>{await w(e),k.value?.rowExpansion(e)},H=e(()=>[{key:"expand",type:"expand",width:30},{key:"ticker_symbol",label:S("watch-list.table.symbol"),sortable:!0,sort_key:"ticker_symbol",customHeaderClass:"flex justify-start items-center",cellClass:"py-0",minWidth:100},{key:"last",label:S("watch-list.table.last-price"),sortable:!0,sort_key:"last",align:"right",minWidth:110},{key:"volume",label:S("watch-list.table.volume"),sortable:!0,sort_key:"volume",align:"right",minWidth:100}]),D=e(()=>k.value?.sort),G=e=>{_(e)},T=(e,t,l)=>e!==l?.key?"SortDefault2":"asc"===t?"SortUp2":"SortDown2",W=({row:e})=>p.value.includes(e.id)?"loading-row":"";return i(b,e=>{e||k.value?.sortTable("",null)}),(e,t)=>{const a=r("NoData"),i=r("eaera-icon");return c(),f(d(R),{ref_key:"watchListTableRef",ref:k,class:"watchlist-table","max-height":d(l),items:d(o),fields:H.value,"span-method":C,stripe:!1,"hide-footer":"","row-class-name":W,onRowClick:I,onExpandChange:x,"onUpdate:onSortChanged":G},{"cell(ticker_symbol)":v(({item:e})=>[m("div",X,[m("div",Y,y(e.host_exchange)+":"+y(e.base_symbol),1),m("div",q,y(e.name),1)])]),"cell(expand)":v(({row:e})=>[d(p).includes(e.id)?(c(),n("div",J)):(c(),f(d(de),{key:1,symbols:d(s)[e.id]||[],"inside-group":""},null,8,["symbols"]))]),empty:v(()=>[m("div",Q,[m("div",Z,[u(a),m("span",ee,y(d(S)("watch-list.table.empty.group")),1)])])]),"sort-icon":v(({sortKey:e,direction:t})=>[u(i,{icon:T(e,t,D.value),size:"14",class:"custom-watchlist-group-table__sort-icon","active-color":"var(--primary-green)"},null,8,["icon"])]),_:1},8,["max-height","items","fields"])}}});var le=(e=>(e.Active="active",e.MarketClosed="market-closed",e.Expired="expired",e.NotTradableYet="not-tradable-yet",e))(le||{});const oe={class:"custom-watchlist-item-table__symbol-cell"},se={class:"custom-watchlist-item-table__symbol-main body-md__w"},ae=["onClick"],ie={class:"custom-watchlist-item-table__description-row body-sm"},re={style:{width:"100%"}},ce={style:{width:"100%"}},ne={key:0},me={class:"custom-watchlist-item-table__empty-content"},ue={class:"custom-watchlist-item-table__empty-text body-sm"},de=o({__name:"EaeraWatchlistItemTable",props:{insideGroup:{type:Boolean},symbols:{},maxHeight:{},showHeader:{type:Boolean},loading:{type:Boolean}},setup(t){const{favoriteSymbolIds:l,viewingSymbolId:o,sorting:s,selectedCategory:p,listSymbolsLoading:w,onItemSortChanged:_,onSelectSymbol:C,onToggleFavorite:x,onShowSymbolInfo:I}=j(),{t:G}=E(),T=t,W=a(),F=a(null),L=e(()=>[{key:"",label:"",width:30},{key:"ticker_symbol",label:G("watch-list.table.symbol"),sortable:!0,sort_key:"ticker_symbol",customHeaderClass:"flex justify-start items-center",align:"left",minWidth:100},{key:"last",label:G("watch-list.table.last-price"),sortable:!0,sort_key:"last",align:"right",customHeaderClass:"flex justify-end items-center",minWidth:110},{key:"volume",label:G("watch-list.table.volume"),sortable:!0,sort_key:"volume",customHeaderClass:"flex justify-end items-center",minWidth:100,align:"right"}]),z=e(()=>F.value?"ticker_symbol"===F.value.key?[...T.symbols].sort((e,t)=>{const l=e.ticker_symbol.toUpperCase(),o=t.ticker_symbol.toUpperCase();return l<o?"desc"===F.value?.direction?-1:1:l>o?"desc"===F.value?.direction?1:-1:0}):"volume"===F.value.key?[...T.symbols].sort((e,t)=>e.volume<t.volume?"asc"===F.value?.direction?-1:1:e.volume>t.volume?"asc"===F.value?.direction?1:-1:0):"last"===F.value.key?[...T.symbols].sort((e,t)=>{const l=Number(e.last),o=Number(t.last);return l<o?"asc"===F.value?.direction?-1:1:l>o?"asc"===F.value?.direction?1:-1:0}):T.symbols:T.symbols),U=e(()=>e=>l.value.includes(e.id)?{icon:"Star3",color:"#FFD700"}:{icon:"StarOutline",color:"var(--primary-green)"}),A=e(()=>W.value?.sort),N=e(()=>T.insideGroup?T.loading:w.value),B=e=>e!==le.Active,V=({key:e,direction:t})=>{e&&t?(F.value={key:e,direction:t,selfSort:!0},_({key:e,direction:t})):(F.value?.selfSort&&_(null),F.value=null)},P=e=>{C(e)},K=({row:e})=>e.id===o.value?"active-row":"",M=(e,t)=>{if(t&&t!==le.Active)return"var(--text-disabled)";const l=Number(e);return l>0?"var(--text-green)":l<0?"var(--text-red)":"var(--text-primary)"},O=(e,t,l)=>e!==l?.key?"SortDefault2":"asc"===t?"SortUp2":"SortDown2";return i(W,e=>{e&&(T.insideGroup||s.value&&(e.sortTable("",s.value.sort_by),F.value={key:s.value.sort_by,direction:s.value.order,selfSort:!1}))}),i(()=>p.value?.id,()=>F.value=null),(e,t)=>{const l=r("eaera-icon"),o=D,s=r("client-only"),a=H;return c(),f(s,null,{default:v(()=>[S((c(),n("div",null,[u(d(R),{ref_key:"watchListTableRef",ref:W,class:b(["expanding-rows-table watchlist-table expanded",[!z.value?.length&&!T.insideGroup&&"empty",T.insideGroup&&"inside-group"]]),"allow-sort-reset":"","hide-footer":"","max-height":T.maxHeight,height:T.maxHeight,"show-header":T.showHeader,items:z.value,fields:L.value,stripe:!1,"row-class-name":K,loading:N.value,"onUpdate:onSortChanged":V,onOnRowClick:P},{"cell()":v(({item:e})=>[m("div",null,[u(l,{icon:"Info",size:"16",class:b(["custom-watchlist-item-table__info-icon",B(e.state)&&"is-disabled"]),onClick:k(t=>(async e=>{const t=T.symbols.find(t=>t.id===e);t&&await I(t)})(e.id),["stop"])},null,8,["class","onClick"])])]),"cell(ticker_symbol)":v(({item:e})=>[m("div",oe,[m("div",se,[m("span",{class:b(["custom-watchlist-item-table__symbol-text",B(e.state)&&"is-inactive"])},y(e.ticker_symbol),3),m("div",{class:"custom-watchlist-item-table__favorite",onClick:k(t=>{return l=e.id,void x(l);var l},["stop"])},[u(l,{icon:U.value(e).icon,color:U.value(e).color,size:"16"},null,8,["icon","color"])],8,ae)]),m("div",ie,[u(o,{content:e.description,placement:"right"},{default:v(()=>[m("span",{class:b(["custom-watchlist-item-table__description-text",B(e.state)&&"is-inactive"])},y(e.description),3)]),_:2},1032,["content"])])])]),"cell(last)":v(({item:e})=>[m("div",{style:g({color:M(e.last,e.state),width:"100%"})},[m("div",re,[m("div",null,y(e.last),1)])],4)]),"cell(volume)":v(({item:e})=>[m("div",{style:g({color:M(e.volume,e.state),width:"100%"})},[m("div",ce,[m("div",null,y(e.volume),1)])],4)]),empty:v(()=>[N.value?(c(),n("div",ne)):(c(),n("div",{key:1,class:"custom-watchlist-item-table__empty",style:g({height:T.maxHeight?`calc(${T.maxHeight} - 32px)`:"auto"})},[m("div",me,[m("span",ue,y(d(G)("watch-list.table.empty.symbol")),1)])],4))]),"sort-icon":v(({sortKey:e,direction:t})=>[u(l,{icon:O(e,t,A.value),size:"14",class:"custom-watchlist-item-table__sort-icon","active-color":"var(--icon-success)"},null,8,["icon"])]),_:1},8,["class","max-height","height","show-header","items","fields","loading"])])),[[a,N.value]])]),_:1})}}}),pe={class:"custom-watchlist__table"},he=o({__name:"index",props:{inputPlaceholder:{},searchData:{},categories:{},selectedCategory:{},isFiltered:{type:Boolean},tableHeight:{},viewingSymbols:{},viewingSymbolGroups:{},listSymbols:{},groupLoadingRowIds:{},favoriteSymbolIds:{},viewingSymbolId:{},listSymbolsLoading:{type:Boolean},sorting:{}},emits:["resize","selectCategory","update:searchData","groupExpandChange","groupRowClick","groupSortChanged","itemSortChanged","selectSymbol","toggleFavorite","showSymbolInfo"],setup(e,{emit:t}){const l=s(null),o=s(null),{width:a,height:r}=C(l),p=T(e,t);return i([a,r],()=>{l.value&&o.value&&p.onResize(a.value,r.value-o.value.clientHeight)}),(e,t)=>(c(),n("div",{ref_key:"watchlistRef",ref:l,class:"custom-watchlist"},[m("div",{ref_key:"watchlistFilterRef",ref:o,class:"custom-watchlist__filter"},[u(d(P))],512),m("div",pe,[u(d($))])],512))}});export{le as S,he as _,T as p,j as u};
1
+ import{computed as e,provide as t,inject as l,defineComponent as o,shallowRef as s,ref as a,watch as i,resolveComponent as r,openBlock as c,createElementBlock as n,createElementVNode as m,createVNode as u,unref as d,createSlots as p,withCtx as v,toDisplayString as y,normalizeClass as b,normalizeStyle as g,Fragment as w,renderList as _,createBlock as f,withDirectives as S,withModifiers as k}from"vue";import{a as C}from"./vendor-vueuse-core-B96HGhR7.mjs";import x from"../composite/EaeraDropdownV2.mjs";import{_ as I}from"./EaeraInput-CkbcAxy0.mjs";import{useI18n as E}from"vue-i18n";import"element-plus";import{ElLoadingDirective as H}from"element-plus/es";import"@lucide/vue";import"./vendor-email-misspelled-0hsXkSSK.mjs";import"./vendor-unorm-Degftfa1.mjs";import"./useEaeraInputPhoneNumber-B72aLnQs.mjs";import"@element-plus/icons-vue";import"echarts/core";import"echarts/renderers";import"echarts/charts";import"echarts/components";import"vue-echarts";import"./vendor-currency-symbol-map-C-1fEG2R.mjs";import{_ as R}from"./EaeraTableV2-BF5WVwr0.mjs";import{_ as D}from"./EaeraTooltip-BIlULHv4.mjs";const G=Symbol("EAERA_WATCHLIST_CONTEXT_KEY"),T=(l,o)=>{const s={inputPlaceholder:e(()=>l.inputPlaceholder),searchData:e(()=>l.searchData),categories:e(()=>l.categories),selectedCategory:e(()=>l.selectedCategory),isFiltered:e(()=>l.isFiltered),tableHeight:e(()=>l.tableHeight),viewingSymbols:e(()=>l.viewingSymbols),viewingSymbolGroups:e(()=>l.viewingSymbolGroups),listSymbols:e(()=>l.listSymbols),groupLoadingRowIds:e(()=>l.groupLoadingRowIds),favoriteSymbolIds:e(()=>l.favoriteSymbolIds),viewingSymbolId:e(()=>l.viewingSymbolId),listSymbolsLoading:e(()=>l.listSymbolsLoading),sorting:e(()=>l.sorting),onResize:(e,t)=>o("resize",e,t),onSelectCategory:e=>o("selectCategory",e),onSearchDataUpdate:e=>o("update:searchData",e),onGroupExpandChange:e=>o("groupExpandChange",e),onGroupRowClick:e=>o("groupRowClick",e),onGroupSortChanged:e=>o("groupSortChanged",e),onItemSortChanged:e=>o("itemSortChanged",e),onSelectSymbol:e=>o("selectSymbol",e),onToggleFavorite:e=>o("toggleFavorite",e),onShowSymbolInfo:e=>o("showSymbolInfo",e)};return t(G,s),s},j=()=>{const e=l(G);if(!e)throw new Error("useEaeraWatchlist must be used inside EaeraWatchlist");return e},W={class:"custom-watchlist-filter"},F={class:"custom-watchlist-filter__row"},L={class:"custom-watchlist-filter__field"},z={class:"custom-watchlist-filter__field"},U=["onClick"],A={class:"custom-watchlist-filter__category-count"},N={class:"custom-watchlist-filter__dropdown-trigger-content"},B={key:0,class:"custom-watchlist-filter__selected"},V={key:1,class:"custom-watchlist-filter__placeholder"},P=o({__name:"EaeraWatchlistFilter",setup(e){const{inputPlaceholder:t,searchData:l,categories:o,selectedCategory:f,onSelectCategory:S,onSearchDataUpdate:k}=j(),C=s(),E=a(!1),H=a(!1),R=a(""),D=a(!1);i(l,e=>{e!==R.value&&(R.value=e)},{immediate:!0});const G=e=>{D.value||k(e)},T=()=>D.value=!0,P=e=>k(e.data),K=e=>{D.value=!1;const t=e.data??R.value;k(t)};return(e,s)=>{const a=r("eaera-icon"),i=I,k=x;return c(),n("div",W,[m("div",F,[m("div",L,[u(i,{modelValue:R.value,"onUpdate:modelValue":s[0]||(s[0]=e=>R.value=e),class:"watchlist-input",placeholder:d(t),clearable:"",onInput:G,onCompositionstart:T,onCompositionupdate:P,onCompositionend:K},p({_:2},[d(l)?void 0:{name:"suffix",fn:v(()=>[u(a,{icon:"Search2",size:"16",class:"icon-primary"})]),key:"0"}]),1032,["modelValue","placeholder"])]),m("div",z,[u(k,{class:"custom-watchlist-filter__dropdown","popper-class":"with-border",onVisibleChange:s[4]||(s[4]=e=>E.value=e)},{dropdown:v(()=>[m("div",{class:"custom-watchlist-filter__dropdown-menu",style:g({width:`${C.value?.clientWidth??100}px`})},[(c(!0),n(w,null,_(d(o),e=>(c(),n("div",{key:e.id,class:"custom-watchlist-filter__category"},[m("div",{class:"custom-watchlist-filter__category-content label-md",onClick:t=>d(S)(e)},[m("div",null,y(e.name),1),m("div",A,y(e.count),1)],8,U)]))),128))],4)]),default:v(()=>[m("div",{ref_key:"dropdownRef",ref:C,class:"custom-watchlist-filter__dropdown-trigger"},[m("div",N,[d(f)?.name?(c(),n("span",B,y(d(f).name),1)):(c(),n("span",V,y(e.$t("watch-list.filter.categories")),1)),m("div",{class:"custom-watchlist-filter__icon-wrapper",onMouseenter:s[1]||(s[1]=e=>H.value=!0),onMouseleave:s[2]||(s[2]=e=>H.value=!1),onClick:s[3]||(s[3]=e=>d(S)(null))},[u(a,{icon:H.value&&d(f)?"XCircle":"ChevronDown",size:"16",class:b(["icon-primary","custom-watchlist-filter__dropdown-icon",E.value&&"is-open"])},null,8,["icon","class"])],32)])],512)]),_:1})])])])}}}),K={class:"custom-watchlist-table"},M={key:0,class:"custom-watchlist-table__group"},O={key:1,class:"custom-watchlist-table__items"},$=o({__name:"EaeraWatchlistTable",setup(e){const{isFiltered:t,tableHeight:l,viewingSymbols:o,listSymbolsLoading:s}=j();return(e,a)=>(c(),n("div",K,[d(t)?(c(),n("div",O,[u(d(de),{symbols:d(o),"max-height":d(l),loading:d(s),"show-header":""},null,8,["symbols","max-height","loading"])])):(c(),n("div",M,[u(d(te))]))]))}}),X={class:"custom-watchlist-group-table__symbol-cell"},Y={class:"custom-watchlist-group-table__symbol body-md__w"},q={class:"custom-watchlist-group-table__name body-sm"},J={key:0},Q={class:"custom-watchlist-group-table__empty"},Z={class:"custom-watchlist-group-table__empty-content"},ee={class:"custom-watchlist-group-table__empty-text body-sm"},te=o({__name:"EaeraWatchlistGroupTable",setup(t){const{tableHeight:l,viewingSymbolGroups:o,listSymbols:s,groupLoadingRowIds:p,sorting:b,onGroupExpandChange:g,onGroupRowClick:w,onGroupSortChanged:_}=j(),{t:S}=E(),k=a(),C=({columnIndex:e})=>0===e?[1,1]:1===e?[1,4]:[0,0],x=e=>{g(e)},I=async e=>{await w(e),k.value?.rowExpansion(e)},H=e(()=>[{key:"expand",type:"expand",width:30},{key:"ticker_symbol",label:S("watch-list.table.symbol"),sortable:!0,sort_key:"ticker_symbol",customHeaderClass:"flex justify-start items-center",cellClass:"py-0",minWidth:100},{key:"last",label:S("watch-list.table.last-price"),sortable:!0,sort_key:"last",align:"right",minWidth:110},{key:"volume",label:S("watch-list.table.volume"),sortable:!0,sort_key:"volume",align:"right",minWidth:100}]),D=e(()=>k.value?.sort),G=e=>{_(e)},T=(e,t,l)=>e!==l?.key?"SortDefault2":"asc"===t?"SortUp2":"SortDown2",W=({row:e})=>p.value.includes(e.id)?"loading-row":"";return i(b,e=>{e||k.value?.sortTable("",null)}),(e,t)=>{const a=r("NoData"),i=r("eaera-icon");return c(),f(d(R),{ref_key:"watchListTableRef",ref:k,class:"watchlist-table","max-height":d(l),items:d(o),fields:H.value,"span-method":C,stripe:!1,"hide-footer":"","row-class-name":W,onRowClick:I,onExpandChange:x,"onUpdate:onSortChanged":G},{"cell(ticker_symbol)":v(({item:e})=>[m("div",X,[m("div",Y,y(e.host_exchange)+":"+y(e.base_symbol),1),m("div",q,y(e.name),1)])]),"cell(expand)":v(({row:e})=>[d(p).includes(e.id)?(c(),n("div",J)):(c(),f(d(de),{key:1,symbols:d(s)[e.id]||[],"inside-group":""},null,8,["symbols"]))]),empty:v(()=>[m("div",Q,[m("div",Z,[u(a),m("span",ee,y(d(S)("watch-list.table.empty.group")),1)])])]),"sort-icon":v(({sortKey:e,direction:t})=>[u(i,{icon:T(e,t,D.value),size:"14",class:"custom-watchlist-group-table__sort-icon","active-color":"var(--primary-green)"},null,8,["icon"])]),_:1},8,["max-height","items","fields"])}}});var le=(e=>(e.Active="active",e.MarketClosed="market-closed",e.Expired="expired",e.NotTradableYet="not-tradable-yet",e))(le||{});const oe={class:"custom-watchlist-item-table__symbol-cell"},se={class:"custom-watchlist-item-table__symbol-main body-md__w"},ae=["onClick"],ie={class:"custom-watchlist-item-table__description-row body-sm"},re={style:{width:"100%"}},ce={style:{width:"100%"}},ne={key:0},me={class:"custom-watchlist-item-table__empty-content"},ue={class:"custom-watchlist-item-table__empty-text body-sm"},de=o({__name:"EaeraWatchlistItemTable",props:{insideGroup:{type:Boolean},symbols:{},maxHeight:{},showHeader:{type:Boolean},loading:{type:Boolean}},setup(t){const{favoriteSymbolIds:l,viewingSymbolId:o,sorting:s,selectedCategory:p,listSymbolsLoading:w,onItemSortChanged:_,onSelectSymbol:C,onToggleFavorite:x,onShowSymbolInfo:I}=j(),{t:G}=E(),T=t,W=a(),F=a(null),L=e(()=>[{key:"",label:"",width:30},{key:"ticker_symbol",label:G("watch-list.table.symbol"),sortable:!0,sort_key:"ticker_symbol",customHeaderClass:"flex justify-start items-center",align:"left",minWidth:100},{key:"last",label:G("watch-list.table.last-price"),sortable:!0,sort_key:"last",align:"right",customHeaderClass:"flex justify-end items-center",minWidth:110},{key:"volume",label:G("watch-list.table.volume"),sortable:!0,sort_key:"volume",customHeaderClass:"flex justify-end items-center",minWidth:100,align:"right"}]),z=e(()=>F.value?"ticker_symbol"===F.value.key?[...T.symbols].sort((e,t)=>{const l=e.ticker_symbol.toUpperCase(),o=t.ticker_symbol.toUpperCase();return l<o?"desc"===F.value?.direction?-1:1:l>o?"desc"===F.value?.direction?1:-1:0}):"volume"===F.value.key?[...T.symbols].sort((e,t)=>e.volume<t.volume?"asc"===F.value?.direction?-1:1:e.volume>t.volume?"asc"===F.value?.direction?1:-1:0):"last"===F.value.key?[...T.symbols].sort((e,t)=>{const l=Number(e.last),o=Number(t.last);return l<o?"asc"===F.value?.direction?-1:1:l>o?"asc"===F.value?.direction?1:-1:0}):T.symbols:T.symbols),U=e(()=>e=>l.value.includes(e.id)?{icon:"Star3",color:"#FFD700"}:{icon:"StarOutline",color:"var(--primary-green)"}),A=e(()=>W.value?.sort),N=e(()=>T.insideGroup?T.loading:w.value),B=e=>e!==le.Active,V=({key:e,direction:t})=>{e&&t?(F.value={key:e,direction:t,selfSort:!0},_({key:e,direction:t})):(F.value?.selfSort&&_(null),F.value=null)},P=e=>{C(e)},K=({row:e})=>e.id===o.value?"active-row":"",M=(e,t)=>{if(t&&t!==le.Active)return"var(--text-disabled)";const l=Number(e);return l>0?"var(--text-green)":l<0?"var(--text-red)":"var(--text-primary)"},O=(e,t,l)=>e!==l?.key?"SortDefault2":"asc"===t?"SortUp2":"SortDown2";return i(W,e=>{e&&(T.insideGroup||s.value&&(e.sortTable("",s.value.sort_by),F.value={key:s.value.sort_by,direction:s.value.order,selfSort:!1}))}),i(()=>p.value?.id,()=>F.value=null),(e,t)=>{const l=r("eaera-icon"),o=D,s=r("client-only"),a=H;return c(),f(s,null,{default:v(()=>[S((c(),n("div",null,[u(d(R),{ref_key:"watchListTableRef",ref:W,class:b(["expanding-rows-table watchlist-table expanded",[!z.value?.length&&!T.insideGroup&&"empty",T.insideGroup&&"inside-group"]]),"allow-sort-reset":"","hide-footer":"","max-height":T.maxHeight,height:T.maxHeight,"show-header":T.showHeader,items:z.value,fields:L.value,stripe:!1,"row-class-name":K,loading:N.value,"onUpdate:onSortChanged":V,onOnRowClick:P},{"cell()":v(({item:e})=>[m("div",null,[u(l,{icon:"Info",size:"16",class:b(["custom-watchlist-item-table__info-icon",B(e.state)&&"is-disabled"]),onClick:k(t=>(async e=>{const t=T.symbols.find(t=>t.id===e);t&&await I(t)})(e.id),["stop"])},null,8,["class","onClick"])])]),"cell(ticker_symbol)":v(({item:e})=>[m("div",oe,[m("div",se,[m("span",{class:b(["custom-watchlist-item-table__symbol-text",B(e.state)&&"is-inactive"])},y(e.ticker_symbol),3),m("div",{class:"custom-watchlist-item-table__favorite",onClick:k(t=>{return l=e.id,void x(l);var l},["stop"])},[u(l,{icon:U.value(e).icon,color:U.value(e).color,size:"16"},null,8,["icon","color"])],8,ae)]),m("div",ie,[u(o,{content:e.description,placement:"right"},{default:v(()=>[m("span",{class:b(["custom-watchlist-item-table__description-text",B(e.state)&&"is-inactive"])},y(e.description),3)]),_:2},1032,["content"])])])]),"cell(last)":v(({item:e})=>[m("div",{style:g({color:M(e.last,e.state),width:"100%"})},[m("div",re,[m("div",null,y(e.last),1)])],4)]),"cell(volume)":v(({item:e})=>[m("div",{style:g({color:M(e.volume,e.state),width:"100%"})},[m("div",ce,[m("div",null,y(e.volume),1)])],4)]),empty:v(()=>[N.value?(c(),n("div",ne)):(c(),n("div",{key:1,class:"custom-watchlist-item-table__empty",style:g({height:T.maxHeight?`calc(${T.maxHeight} - 32px)`:"auto"})},[m("div",me,[m("span",ue,y(d(G)("watch-list.table.empty.symbol")),1)])],4))]),"sort-icon":v(({sortKey:e,direction:t})=>[u(l,{icon:O(e,t,A.value),size:"14",class:"custom-watchlist-item-table__sort-icon","active-color":"var(--icon-success)"},null,8,["icon"])]),_:1},8,["class","max-height","height","show-header","items","fields","loading"])])),[[a,N.value]])]),_:1})}}}),pe={class:"custom-watchlist__table"},he=o({__name:"index",props:{inputPlaceholder:{},searchData:{},categories:{},selectedCategory:{},isFiltered:{type:Boolean},tableHeight:{},viewingSymbols:{},viewingSymbolGroups:{},listSymbols:{},groupLoadingRowIds:{},favoriteSymbolIds:{},viewingSymbolId:{},listSymbolsLoading:{type:Boolean},sorting:{}},emits:["resize","selectCategory","update:searchData","groupExpandChange","groupRowClick","groupSortChanged","itemSortChanged","selectSymbol","toggleFavorite","showSymbolInfo"],setup(e,{emit:t}){const l=s(null),o=s(null),{width:a,height:r}=C(l),p=T(e,t);return i([a,r],()=>{l.value&&o.value&&p.onResize(a.value,r.value-o.value.clientHeight)}),(e,t)=>(c(),n("div",{ref_key:"watchlistRef",ref:l,class:"custom-watchlist"},[m("div",{ref_key:"watchlistFilterRef",ref:o,class:"custom-watchlist__filter"},[u(d(P))],512),m("div",pe,[u(d($))])],512))}});export{le as S,he as _,T as p,j as u};
@@ -1 +1 @@
1
- import{_ as e}from"./EaeraTableV2-BqxbiWNA.mjs";import{_ as l}from"./EaeraTag-DOpHFhCO.mjs";import{_ as t}from"./EaeraSelect-BxZRZofe.mjs";import{_ as s}from"./EaeraButton-DGfjUoa6.mjs";import{_ as a}from"./EaeraInput-CkbcAxy0.mjs";import{defineComponent as o,openBlock as i,createBlock as r,withCtx as n,createElementVNode as c,createVNode as d,createTextVNode as m,createElementBlock as u,normalizeClass as v,toDisplayString as b,createCommentVNode as y,ref as p,shallowRef as g,computed as x,unref as f,withModifiers as C,resolveDynamicComponent as w}from"vue";import{X as L,Plus as S,ArrowUp as k,ArrowDown as _,ArrowDownUp as A,Star as N,ListPlus as $}from"@lucide/vue";import{_ as j}from"./EaeraDialog-uLsXC20k.mjs";import{a as D}from"./vendor-vueuse-core-B96HGhR7.mjs";import{b as z}from"./iconSvg-DTZkgsHi.mjs";const T={class:"flex flex-col gap-xs"},R={class:"m-0 text-title-md text-[var(--er-text-primary)]"},O={class:"flex w-full flex-col gap-md py-sm"},V={class:"flex justify-end gap-sm"},I=o({__name:"AddSymbolToListDialog",props:{dialogVisible:{type:Boolean},symbol:{},selectedListId:{},customListOptions:{},message:{},canAdd:{type:Boolean}},emits:["close","add","update:selectedListId"],setup(e,{emit:l}){const a=l;return(l,o)=>{const p=t,g=s,x=j;return i(),r(x,{"dialog-visible":e.dialogVisible,width:"400px","append-body":"","destroy-on-close":"","close-on-click-modal":!1,onClose:o[3]||(o[3]=e=>a("close"))},{header:n(()=>[c("div",T,[c("p",R," Add "+b(e.symbol?.symbol)+" to list ",1),o[4]||(o[4]=c("p",{class:"m-0 text-body-xs text-[var(--er-text-secondary)]"}," Existing memberships are kept unique. ",-1))])]),default:n(()=>[c("div",O,[d(p,{value:e.selectedListId,options:e.customListOptions,placeholder:"Select custom list","translate-label":!1,size:"md",class:"w-full",onChange:o[0]||(o[0]=e=>a("update:selectedListId",e))},null,8,["value","options"]),e.message?(i(),u("p",{key:0,class:v(["m-0 text-body-xs",e.message.includes("already")?"text-[var(--er-text-warning)]":"text-[var(--er-text-success)]"])},b(e.message),3)):y("",!0)])]),footer:n(()=>[c("div",V,[d(g,{color:"secondary",onClick:o[1]||(o[1]=e=>a("close"))},{default:n(()=>[...o[5]||(o[5]=[m("Close",-1)])]),_:1}),d(g,{color:"primary",disabled:!e.canAdd,onClick:o[2]||(o[2]=e=>a("add"))},{default:n(()=>[...o[6]||(o[6]=[m(" Add ",-1)])]),_:1},8,["disabled"])])]),_:1},8,["dialog-visible"])}}}),M={class:"flex flex-col gap-md py-sm"},F={class:"flex flex-col gap-xs"},E={class:"flex flex-col gap-xs"},U={key:0,class:"m-0 text-body-xs text-[var(--er-text-danger)]"},P={class:"flex justify-end gap-sm"},H=o({__name:"CreateCustomListDialog",props:{dialogVisible:{type:Boolean},listName:{},selectedSymbols:{},symbolOptions:{},error:{}},emits:["close","create","update:listName","update:selectedSymbols"],setup(e,{emit:l}){const o=l,v=e=>{o("update:selectedSymbols",e)};return(l,p)=>{const g=a,x=t,f=s,C=j;return i(),r(C,{"dialog-visible":e.dialogVisible,width:"420px","append-body":"","destroy-on-close":"","close-on-click-modal":!1,onClose:p[3]||(p[3]=e=>o("close"))},{header:n(()=>[...p[4]||(p[4]=[c("div",{class:"flex flex-col gap-xs"},[c("p",{class:"m-0 text-title-md text-[var(--er-text-primary)]"},"Create custom list"),c("p",{class:"m-0 text-body-xs text-[var(--er-text-secondary)]"}," Save a reusable set of symbols for Market Watch. ")],-1)])]),default:n(()=>[c("div",M,[c("div",F,[p[5]||(p[5]=c("span",{class:"text-label-md text-[var(--er-text-primary)]"},"List name",-1)),d(g,{value:e.listName,placeholder:"London Open",size:"md",onHandleChange:p[0]||(p[0]=e=>o("update:listName",e))},null,8,["value"])]),c("div",E,[p[6]||(p[6]=c("span",{class:"text-label-md text-[var(--er-text-primary)]"},"Symbols",-1)),d(x,{value:e.selectedSymbols,options:e.symbolOptions,multiple:"",filterable:"",clearable:"",size:"md",class:"w-full",onChange:v},null,8,["value","options"])]),e.error?(i(),u("p",U,b(e.error),1)):y("",!0)])]),footer:n(()=>[c("div",P,[d(f,{color:"secondary",onClick:p[1]||(p[1]=e=>o("close"))},{default:n(()=>[...p[7]||(p[7]=[m("Cancel",-1)])]),_:1}),d(f,{color:"primary",onClick:p[2]||(p[2]=e=>o("create"))},{default:n(()=>[...p[8]||(p[8]=[m("Create",-1)])]),_:1})])]),_:1},8,["dialog-visible"])}}}),B="archived-commodities",q="custom:",K=["symbol","lastPrice","volume"],W=[{label:"All Symbols",value:"all"},{label:"Favorites",value:"favorites"},{label:"Forex Majors",value:"forex-majors"},{label:"Metals",value:"metals"},{label:"Crypto",value:"crypto"},{label:"Archived Commodities",value:B,available:!1}],G={xauusd:["coin","usd"],xagusd:["coin","usd"]},J=[{key:"symbol",label:"Symbol",sortable:!0,sort_key:"symbol",minWidth:164,customHeaderClass:"flex justify-start items-center",headerLabelClass:"text-label-md text-[var(--er-text-secondary)]",cellClass:"watchlist-symbol-column",align:"left"},{key:"lastPrice",label:"Last Price",sortable:!0,sort_key:"lastPrice",width:104,align:"right",customHeaderClass:"flex justify-end items-center",headerLabelClass:"text-label-md text-[var(--er-text-secondary)]",cellClass:"watchlist-price-column"},{key:"volume",label:"Volume",sortable:!0,sort_key:"volume",width:88,align:"right",customHeaderClass:"flex justify-end items-center",headerLabelClass:"text-label-md text-[var(--er-text-secondary)]",cellClass:"watchlist-price-column"}],Q=e=>`${q}${e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")}-${Date.now()}`,X=e=>!!e&&K.includes(e);function Y(e,l){const t=p("all"),s=p(0),a=p(""),o=p({}),i=p(""),r=p(!1),n=p(""),c=p([]),d=p(""),m=p(!1),u=p(null),v=p(void 0),b=p(""),y=p({}),f=p([{id:`${q}metals-watch`,name:"Metals Watch",symbols:[]}]),C=g(null),w=g(null),{height:L}=D(C),{height:S}=D(w),k=x(()=>{const l=new Map;return e().forEach(e=>{l.has(e.symbol)||l.set(e.symbol,e)}),l}),_=x(()=>Array.from(k.value.values()).map(e=>({label:e.symbol,value:e.symbol}))),A=x(()=>f.value.map(e=>({label:e.name,value:e.id}))),N=x(()=>A.value),$=x(()=>[...W,...f.value.map(e=>({label:e.name,value:e.id,available:!0}))]),j=x(()=>Z(t.value)),z=x(()=>{if("favorites"===t.value)return e().filter(e=>P(e));if("all"===t.value)return e();const l=Z(t.value);return l?l.symbols.map(e=>k.value.get(e)).filter(e=>!!e):e().filter(e=>e.category===t.value)}),T=x(()=>{const e=a.value.trim().toLowerCase(),l=z.value.map(H);return e?l.filter(l=>l.symbol.toLowerCase().includes(e)||l.name.toLowerCase().includes(e)):l}),R=x(()=>{if(!L.value)return;const e=S.value+16,l=Math.floor(L.value-e);return Math.max(160,l)}),O=x(()=>{const e=o.value.key,l=o.value.direction;return X(e)&&l?[...T.value].sort((t,s)=>{const a=M(t,e),o=M(s,e),i=F(a,o);return"asc"===l?i:-i}):T.value}),V=x(()=>{const e=a.value.trim();if(e&&0===O.value.length)return`No symbols match “${e}” in the current view. Clear search to restore the list.`;const l=j.value;return l&&0===l.symbols.length?`${l.name} has no symbols. Add symbols to this list or choose another view.`:"No symbols match the current view."}),I=x(()=>f.value.length>0),M=(e,l)=>"lastPrice"===l||"volume"===l?E(e[l]):e.symbol,F=(e,l)=>"number"==typeof e&&"number"==typeof l?e-l:String(e).localeCompare(String(l)),E=e=>{const l=e.trim().toUpperCase(),t=l.endsWith("K")?1e3:l.endsWith("M")?1e6:1;return Number(l.replace(/,/g,"").replace(/[^\d.-]/g,""))*t||0},U=e=>{const l=e.symbol.toLowerCase(),t=G[l];return t||[l.slice(0,3),l.slice(3,6)||"usd"]},P=e=>y.value[e.symbol]??!!e.isFavorite,H=e=>({...e,isFavorite:P(e)}),K=()=>{r.value=!1,d.value=""},Y=()=>{m.value=!1,u.value=null,b.value=""},Z=e=>f.value.find(l=>l.id===e),ee=x(()=>{const e=j.value;return e?e.name:$.value.find(e=>e.value===t.value)?.label??"All Symbols"});return{selectedView:t,viewSelectRenderKey:s,searchText:a,sorting:o,viewNotice:i,createListDialogVisible:r,newListName:n,newListSymbols:c,createListError:d,addToListDialogVisible:m,symbolPendingListAdd:u,selectedCustomListId:v,addToListMessage:b,canAddToCustomList:I,panelBodyRef:C,filterControlsRef:w,viewOptions:$,tableFields:J,symbolOptions:_,customListOptions:A,customListSelectOptions:N,hasSelectedCustomList:()=>!!v.value,tableHeight:R,tableRows:O,emptyStateMessage:V,handleSymbolChange:(e,l)=>{l(e)},handleSearchChange:e=>{a.value=e},clearSearch:()=>{a.value=""},handleViewChange:e=>{const l=$.value.find(l=>l.value===e);if(!1===l?.available||e===B)return i.value=`${l?.label??e} is unavailable for this account. Current view remains ${ee.value}.`,void(s.value+=1);t.value=e,i.value=""},handleRowClick:(e,l)=>{l(e.symbol)},handleSortChanged:e=>{if(!e.key&&!e.direction)return o.value={},void(i.value="");X(String(e.key))?(o.value={key:e.key,direction:e.direction},i.value=""):i.value="Unsupported sort column ignored. Keeping the prior ordering."},getRowClass:({row:e})=>e.symbol===l()?"watchlist-row is-active":"watchlist-row",sortDirection:e=>{if(X(e)&&o.value.key===e)return o.value.direction},baseIcon:e=>U(e)[0],quoteIcon:e=>U(e)[1],toggleFavorite:e=>{y.value={...y.value,[e.symbol]:!P(e)}},openCreateListDialog:()=>{r.value=!0,n.value="",c.value=[],d.value=""},closeCreateListDialog:K,handleNewListNameChange:e=>{n.value=e,d.value=""},handleNewListSymbolsChange:e=>{c.value=Array.isArray(e)?e:e?[e]:[],d.value=""},createCustomList:()=>{const e=(e=>e.trim().replace(/\s+/g," "))(n.value);if(!e)return void(d.value="List name is required.");if(f.value.some(l=>l.name.trim().toLowerCase()===e.toLowerCase()))return void(d.value="List names must be unique.");const l=Array.from(new Set(c.value)),s={id:Q(e),name:e,symbols:l};f.value=[...f.value,s],t.value=s.id,i.value=`${e} created with ${l.length} symbol${1===l.length?"":"s"}.`,K()},openAddToListDialog:e=>{u.value=e,v.value=void 0,b.value="",m.value=!0},closeAddToListDialog:Y,handleSelectedCustomListChange:e=>{v.value=e||void 0,b.value=""},addSymbolToSelectedList:()=>{const e=u.value?.symbol,l=v.value,s=l?Z(l):void 0;e&&s?s.symbols.includes(e)?b.value=`${e} is already in ${s.name}.`:(f.value=f.value.map(l=>l.id===s.id?{...l,symbols:[...l.symbols,e]}:l),t.value=s.id,Y(),i.value=`${e} added to ${s.name}.`):b.value="Select a custom list first."},resetCategory:()=>{t.value="all",i.value=""},resetSort:()=>{o.value={}}}}const Z={class:"grid grid-cols-2 gap-lg"},ee={class:"flex items-center justify-center gap-xs"},le={key:0,class:"rounded-xs bg-[var(--er-surface-warning)] px-sm py-xs text-body-xs text-[var(--er-text-warning)]"},te={class:"watchlist-symbol-cell flex items-center gap-sm"},se={class:"watchlist-symbol-badge","aria-hidden":"true"},ae={class:"watchlist-symbol-meta flex-1"},oe={class:"flex items-center gap-xs"},ie={class:"whitespace-nowrap text-body-sm text-[var(--er-text-primary)]"},re=["aria-label","onClick"],ne=["disabled","aria-label","onClick"],ce={class:"watchlist-symbol-name text-body-xs text-[var(--er-text-secondary)]"},de={class:"watchlist-price-cell text-body-xs text-[var(--er-text-primary)]"},me={class:"watchlist-price-cell text-body-xs text-[var(--er-text-primary)]"},ue={class:"flex h-[120px] items-center justify-center px-md text-center text-body-sm text-[var(--er-text-secondary)]"},ve=o({__name:"index",props:{symbols:{},selectedSymbol:{}},emits:["selectSymbol"],setup(o,{expose:p,emit:g}){const x=o,j=g,{selectedView:D,viewSelectRenderKey:T,searchText:R,viewNotice:O,createListDialogVisible:V,newListName:M,newListSymbols:F,createListError:E,addToListDialogVisible:U,symbolPendingListAdd:P,selectedCustomListId:B,addToListMessage:q,canAddToCustomList:K,panelBodyRef:W,filterControlsRef:G,viewOptions:J,tableFields:Q,symbolOptions:X,customListOptions:ve,customListSelectOptions:be,hasSelectedCustomList:ye,tableHeight:pe,tableRows:ge,emptyStateMessage:he,handleSearchChange:xe,clearSearch:fe,handleViewChange:Ce,handleRowClick:we,handleSortChanged:Le,getRowClass:Se,sortDirection:ke,baseIcon:_e,quoteIcon:Ae,toggleFavorite:Ne,openCreateListDialog:$e,closeCreateListDialog:je,handleNewListNameChange:De,handleNewListSymbolsChange:ze,createCustomList:Te,openAddToListDialog:Re,closeAddToListDialog:Oe,handleSelectedCustomListChange:Ve,addSymbolToSelectedList:Ie,resetCategory:Me,resetSort:Fe}=Y(()=>x.symbols,()=>x.selectedSymbol),Ee=e=>{we(e,e=>j("selectSymbol",e))};return p({resetCategory:Me,resetSort:Fe}),(o,p)=>{const g=a,x=s,j=t,Y=l,ve=e;return i(),u("div",{ref_key:"panelBodyRef",ref:W,class:"h-full min-h-0 flex flex-col gap-lg bg-[var(--er-surface-container)] px-sm py-md"},[c("div",{ref_key:"filterControlsRef",ref:G,class:"flex flex-col gap-sm"},[c("div",Z,[d(g,{value:f(R),placeholder:"Search symbol",size:"md",class:"watchlist-input-control w-full",onHandleChange:f(xe)},{suffix:n(()=>[f(R)?(i(),u("button",{key:0,type:"button",class:"watchlist-clear-button","aria-label":"Clear symbol search",onClick:p[0]||(p[0]=C((...e)=>f(fe)&&f(fe)(...e),["stop"]))},[d(f(L),{size:14})])):y("",!0)]),_:1},8,["value","onHandleChange"]),(i(),r(j,{key:f(T),value:f(D),options:f(J),size:"md",class:"watchlist-control w-full",onChange:f(Ce)},{footer:n(()=>[d(x,{size:"sm",color:"secondary",background:!1,class:"w-full",onClick:f($e)},{default:n(()=>[c("div",ee,[d(f(S),{size:14}),p[1]||(p[1]=c("span",null,"Create custom list",-1))])]),_:1},8,["onClick"])]),_:1},8,["value","options","onChange"]))]),f(O)?(i(),u("div",le,b(f(O)),1)):y("",!0)],512),d(ve,{class:"watchlist-custom-table min-h-0 flex-1","allow-sort-reset":"","hide-footer":"",height:f(pe),"max-height":f(pe),"table-layout":"fixed",size:"small",items:f(ge),fields:f(Q),"total-rows":f(ge).length,stripe:!1,"show-filter-by-default":!1,"row-class-name":f(Se),onOnRowClick:Ee,"onUpdate:onSortChanged":f(Le)},{"cell(symbol)":n(({item:e})=>[c("div",te,[c("div",se,[(i(),r(w(f(z)(f(_e)(e))),{size:18,class:"watchlist-symbol-badge-icon watchlist-symbol-badge-icon--base"})),(i(),r(w(f(z)(f(Ae)(e))),{size:18,class:"watchlist-symbol-badge-icon watchlist-symbol-badge-icon--quote"}))]),c("div",ae,[c("div",oe,[c("span",ie,b(e.symbol),1),c("button",{type:"button",class:"watchlist-row-action","aria-label":e.isFavorite?`Remove ${e.symbol} from favorites`:`Add ${e.symbol} to favorites`,onClick:C(l=>f(Ne)(e),["stop"])},[d(f(N),{size:16,"stroke-width":1.8,fill:e.isFavorite?"var(--er-text-warning)":"none",class:v(e.isFavorite?"text-[var(--er-text-warning)]":"text-[var(--er-icon-secondary)]")},null,8,["fill","class"])],8,re),c("button",{type:"button",class:"watchlist-row-action",disabled:!f(K),"aria-label":`Add ${e.symbol} to a custom list`,onClick:C(l=>f(Re)(e),["stop"])},[d(f($),{size:15})],8,ne),"closed"===e.marketStatus?(i(),r(Y,{key:0,color:"warning",size:"sm"},{default:n(()=>[...p[2]||(p[2]=[m(" Closed ",-1)])]),_:1})):y("",!0)]),c("p",ce,b(e.name),1)])])]),"cell(lastPrice)":n(({item:e})=>[c("span",de,b(e.lastPrice),1)]),"cell(volume)":n(({item:e})=>[c("span",me,b(e.volume),1)]),"sort-icon":n(({sortKey:e})=>["asc"===f(ke)(e)?(i(),r(f(k),{key:0})):"desc"===f(ke)(e)?(i(),r(f(_),{key:1,size:16})):(i(),r(f(A),{key:2,size:16}))]),empty:n(()=>[c("div",ue,b(f(he)),1)]),_:1},8,["height","max-height","items","fields","total-rows","row-class-name","onUpdate:onSortChanged"]),d(H,{"dialog-visible":f(V),"list-name":f(M),"selected-symbols":f(F),"symbol-options":f(X),error:f(E),onClose:f(je),onCreate:f(Te),"onUpdate:listName":f(De),"onUpdate:selectedSymbols":f(ze)},null,8,["dialog-visible","list-name","selected-symbols","symbol-options","error","onClose","onCreate","onUpdate:listName","onUpdate:selectedSymbols"]),d(I,{"dialog-visible":f(U),symbol:f(P),"selected-list-id":f(B),"custom-list-options":f(be),message:f(q),"can-add":f(ye)(),onClose:f(Oe),onAdd:f(Ie),"onUpdate:selectedListId":f(Ve)},null,8,["dialog-visible","symbol","selected-list-id","custom-list-options","message","can-add","onClose","onAdd","onUpdate:selectedListId"])],512)}}});export{ve as _,Y as u};
1
+ import{_ as e}from"./EaeraTableV2-BF5WVwr0.mjs";import{_ as l}from"./EaeraTag-BgmzVuUW.mjs";import{_ as t}from"./EaeraSelect-BxZRZofe.mjs";import{_ as s}from"./EaeraButton-DGfjUoa6.mjs";import{_ as a}from"./EaeraInput-CkbcAxy0.mjs";import{defineComponent as o,openBlock as i,createBlock as r,withCtx as n,createElementVNode as c,createVNode as d,createTextVNode as m,createElementBlock as u,normalizeClass as v,toDisplayString as b,createCommentVNode as y,ref as p,shallowRef as g,computed as x,unref as f,withModifiers as C,resolveDynamicComponent as w}from"vue";import{X as L,Plus as S,ArrowUp as k,ArrowDown as _,ArrowDownUp as A,Star as N,ListPlus as $}from"@lucide/vue";import{_ as j}from"./EaeraDialog-uLsXC20k.mjs";import{a as D}from"./vendor-vueuse-core-B96HGhR7.mjs";import{b as z}from"./iconSvg-BrZD7vO3.mjs";const T={class:"flex flex-col gap-xs"},R={class:"m-0 text-title-md text-[var(--er-text-primary)]"},O={class:"flex w-full flex-col gap-md py-sm"},V={class:"flex justify-end gap-sm"},I=o({__name:"AddSymbolToListDialog",props:{dialogVisible:{type:Boolean},symbol:{},selectedListId:{},customListOptions:{},message:{},canAdd:{type:Boolean}},emits:["close","add","update:selectedListId"],setup(e,{emit:l}){const a=l;return(l,o)=>{const p=t,g=s,x=j;return i(),r(x,{"dialog-visible":e.dialogVisible,width:"400px","append-body":"","destroy-on-close":"","close-on-click-modal":!1,onClose:o[3]||(o[3]=e=>a("close"))},{header:n(()=>[c("div",T,[c("p",R," Add "+b(e.symbol?.symbol)+" to list ",1),o[4]||(o[4]=c("p",{class:"m-0 text-body-xs text-[var(--er-text-secondary)]"}," Existing memberships are kept unique. ",-1))])]),default:n(()=>[c("div",O,[d(p,{value:e.selectedListId,options:e.customListOptions,placeholder:"Select custom list","translate-label":!1,size:"md",class:"w-full",onChange:o[0]||(o[0]=e=>a("update:selectedListId",e))},null,8,["value","options"]),e.message?(i(),u("p",{key:0,class:v(["m-0 text-body-xs",e.message.includes("already")?"text-[var(--er-text-warning)]":"text-[var(--er-text-success)]"])},b(e.message),3)):y("",!0)])]),footer:n(()=>[c("div",V,[d(g,{color:"secondary",onClick:o[1]||(o[1]=e=>a("close"))},{default:n(()=>[...o[5]||(o[5]=[m("Close",-1)])]),_:1}),d(g,{color:"primary",disabled:!e.canAdd,onClick:o[2]||(o[2]=e=>a("add"))},{default:n(()=>[...o[6]||(o[6]=[m(" Add ",-1)])]),_:1},8,["disabled"])])]),_:1},8,["dialog-visible"])}}}),M={class:"flex flex-col gap-md py-sm"},F={class:"flex flex-col gap-xs"},E={class:"flex flex-col gap-xs"},U={key:0,class:"m-0 text-body-xs text-[var(--er-text-danger)]"},P={class:"flex justify-end gap-sm"},H=o({__name:"CreateCustomListDialog",props:{dialogVisible:{type:Boolean},listName:{},selectedSymbols:{},symbolOptions:{},error:{}},emits:["close","create","update:listName","update:selectedSymbols"],setup(e,{emit:l}){const o=l,v=e=>{o("update:selectedSymbols",e)};return(l,p)=>{const g=a,x=t,f=s,C=j;return i(),r(C,{"dialog-visible":e.dialogVisible,width:"420px","append-body":"","destroy-on-close":"","close-on-click-modal":!1,onClose:p[3]||(p[3]=e=>o("close"))},{header:n(()=>[...p[4]||(p[4]=[c("div",{class:"flex flex-col gap-xs"},[c("p",{class:"m-0 text-title-md text-[var(--er-text-primary)]"},"Create custom list"),c("p",{class:"m-0 text-body-xs text-[var(--er-text-secondary)]"}," Save a reusable set of symbols for Market Watch. ")],-1)])]),default:n(()=>[c("div",M,[c("div",F,[p[5]||(p[5]=c("span",{class:"text-label-md text-[var(--er-text-primary)]"},"List name",-1)),d(g,{value:e.listName,placeholder:"London Open",size:"md",onHandleChange:p[0]||(p[0]=e=>o("update:listName",e))},null,8,["value"])]),c("div",E,[p[6]||(p[6]=c("span",{class:"text-label-md text-[var(--er-text-primary)]"},"Symbols",-1)),d(x,{value:e.selectedSymbols,options:e.symbolOptions,multiple:"",filterable:"",clearable:"",size:"md",class:"w-full",onChange:v},null,8,["value","options"])]),e.error?(i(),u("p",U,b(e.error),1)):y("",!0)])]),footer:n(()=>[c("div",P,[d(f,{color:"secondary",onClick:p[1]||(p[1]=e=>o("close"))},{default:n(()=>[...p[7]||(p[7]=[m("Cancel",-1)])]),_:1}),d(f,{color:"primary",onClick:p[2]||(p[2]=e=>o("create"))},{default:n(()=>[...p[8]||(p[8]=[m("Create",-1)])]),_:1})])]),_:1},8,["dialog-visible"])}}}),B="archived-commodities",q="custom:",K=["symbol","lastPrice","volume"],W=[{label:"All Symbols",value:"all"},{label:"Favorites",value:"favorites"},{label:"Forex Majors",value:"forex-majors"},{label:"Metals",value:"metals"},{label:"Crypto",value:"crypto"},{label:"Archived Commodities",value:B,available:!1}],G={xauusd:["coin","usd"],xagusd:["coin","usd"]},J=[{key:"symbol",label:"Symbol",sortable:!0,sort_key:"symbol",minWidth:164,customHeaderClass:"flex justify-start items-center",headerLabelClass:"text-label-md text-[var(--er-text-secondary)]",cellClass:"watchlist-symbol-column",align:"left"},{key:"lastPrice",label:"Last Price",sortable:!0,sort_key:"lastPrice",width:104,align:"right",customHeaderClass:"flex justify-end items-center",headerLabelClass:"text-label-md text-[var(--er-text-secondary)]",cellClass:"watchlist-price-column"},{key:"volume",label:"Volume",sortable:!0,sort_key:"volume",width:88,align:"right",customHeaderClass:"flex justify-end items-center",headerLabelClass:"text-label-md text-[var(--er-text-secondary)]",cellClass:"watchlist-price-column"}],Q=e=>`${q}${e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")}-${Date.now()}`,X=e=>!!e&&K.includes(e);function Y(e,l){const t=p("all"),s=p(0),a=p(""),o=p({}),i=p(""),r=p(!1),n=p(""),c=p([]),d=p(""),m=p(!1),u=p(null),v=p(void 0),b=p(""),y=p({}),f=p([{id:`${q}metals-watch`,name:"Metals Watch",symbols:[]}]),C=g(null),w=g(null),{height:L}=D(C),{height:S}=D(w),k=x(()=>{const l=new Map;return e().forEach(e=>{l.has(e.symbol)||l.set(e.symbol,e)}),l}),_=x(()=>Array.from(k.value.values()).map(e=>({label:e.symbol,value:e.symbol}))),A=x(()=>f.value.map(e=>({label:e.name,value:e.id}))),N=x(()=>A.value),$=x(()=>[...W,...f.value.map(e=>({label:e.name,value:e.id,available:!0}))]),j=x(()=>Z(t.value)),z=x(()=>{if("favorites"===t.value)return e().filter(e=>P(e));if("all"===t.value)return e();const l=Z(t.value);return l?l.symbols.map(e=>k.value.get(e)).filter(e=>!!e):e().filter(e=>e.category===t.value)}),T=x(()=>{const e=a.value.trim().toLowerCase(),l=z.value.map(H);return e?l.filter(l=>l.symbol.toLowerCase().includes(e)||l.name.toLowerCase().includes(e)):l}),R=x(()=>{if(!L.value)return;const e=S.value+16,l=Math.floor(L.value-e);return Math.max(160,l)}),O=x(()=>{const e=o.value.key,l=o.value.direction;return X(e)&&l?[...T.value].sort((t,s)=>{const a=M(t,e),o=M(s,e),i=F(a,o);return"asc"===l?i:-i}):T.value}),V=x(()=>{const e=a.value.trim();if(e&&0===O.value.length)return`No symbols match “${e}” in the current view. Clear search to restore the list.`;const l=j.value;return l&&0===l.symbols.length?`${l.name} has no symbols. Add symbols to this list or choose another view.`:"No symbols match the current view."}),I=x(()=>f.value.length>0),M=(e,l)=>"lastPrice"===l||"volume"===l?E(e[l]):e.symbol,F=(e,l)=>"number"==typeof e&&"number"==typeof l?e-l:String(e).localeCompare(String(l)),E=e=>{const l=e.trim().toUpperCase(),t=l.endsWith("K")?1e3:l.endsWith("M")?1e6:1;return Number(l.replace(/,/g,"").replace(/[^\d.-]/g,""))*t||0},U=e=>{const l=e.symbol.toLowerCase(),t=G[l];return t||[l.slice(0,3),l.slice(3,6)||"usd"]},P=e=>y.value[e.symbol]??!!e.isFavorite,H=e=>({...e,isFavorite:P(e)}),K=()=>{r.value=!1,d.value=""},Y=()=>{m.value=!1,u.value=null,b.value=""},Z=e=>f.value.find(l=>l.id===e),ee=x(()=>{const e=j.value;return e?e.name:$.value.find(e=>e.value===t.value)?.label??"All Symbols"});return{selectedView:t,viewSelectRenderKey:s,searchText:a,sorting:o,viewNotice:i,createListDialogVisible:r,newListName:n,newListSymbols:c,createListError:d,addToListDialogVisible:m,symbolPendingListAdd:u,selectedCustomListId:v,addToListMessage:b,canAddToCustomList:I,panelBodyRef:C,filterControlsRef:w,viewOptions:$,tableFields:J,symbolOptions:_,customListOptions:A,customListSelectOptions:N,hasSelectedCustomList:()=>!!v.value,tableHeight:R,tableRows:O,emptyStateMessage:V,handleSymbolChange:(e,l)=>{l(e)},handleSearchChange:e=>{a.value=e},clearSearch:()=>{a.value=""},handleViewChange:e=>{const l=$.value.find(l=>l.value===e);if(!1===l?.available||e===B)return i.value=`${l?.label??e} is unavailable for this account. Current view remains ${ee.value}.`,void(s.value+=1);t.value=e,i.value=""},handleRowClick:(e,l)=>{l(e.symbol)},handleSortChanged:e=>{if(!e.key&&!e.direction)return o.value={},void(i.value="");X(String(e.key))?(o.value={key:e.key,direction:e.direction},i.value=""):i.value="Unsupported sort column ignored. Keeping the prior ordering."},getRowClass:({row:e})=>e.symbol===l()?"watchlist-row is-active":"watchlist-row",sortDirection:e=>{if(X(e)&&o.value.key===e)return o.value.direction},baseIcon:e=>U(e)[0],quoteIcon:e=>U(e)[1],toggleFavorite:e=>{y.value={...y.value,[e.symbol]:!P(e)}},openCreateListDialog:()=>{r.value=!0,n.value="",c.value=[],d.value=""},closeCreateListDialog:K,handleNewListNameChange:e=>{n.value=e,d.value=""},handleNewListSymbolsChange:e=>{c.value=Array.isArray(e)?e:e?[e]:[],d.value=""},createCustomList:()=>{const e=(e=>e.trim().replace(/\s+/g," "))(n.value);if(!e)return void(d.value="List name is required.");if(f.value.some(l=>l.name.trim().toLowerCase()===e.toLowerCase()))return void(d.value="List names must be unique.");const l=Array.from(new Set(c.value)),s={id:Q(e),name:e,symbols:l};f.value=[...f.value,s],t.value=s.id,i.value=`${e} created with ${l.length} symbol${1===l.length?"":"s"}.`,K()},openAddToListDialog:e=>{u.value=e,v.value=void 0,b.value="",m.value=!0},closeAddToListDialog:Y,handleSelectedCustomListChange:e=>{v.value=e||void 0,b.value=""},addSymbolToSelectedList:()=>{const e=u.value?.symbol,l=v.value,s=l?Z(l):void 0;e&&s?s.symbols.includes(e)?b.value=`${e} is already in ${s.name}.`:(f.value=f.value.map(l=>l.id===s.id?{...l,symbols:[...l.symbols,e]}:l),t.value=s.id,Y(),i.value=`${e} added to ${s.name}.`):b.value="Select a custom list first."},resetCategory:()=>{t.value="all",i.value=""},resetSort:()=>{o.value={}}}}const Z={class:"grid grid-cols-2 gap-lg"},ee={class:"flex items-center justify-center gap-xs"},le={key:0,class:"rounded-xs bg-[var(--er-surface-warning)] px-sm py-xs text-body-xs text-[var(--er-text-warning)]"},te={class:"watchlist-symbol-cell flex items-center gap-sm"},se={class:"watchlist-symbol-badge","aria-hidden":"true"},ae={class:"watchlist-symbol-meta flex-1"},oe={class:"flex items-center gap-xs"},ie={class:"whitespace-nowrap text-body-sm text-[var(--er-text-primary)]"},re=["aria-label","onClick"],ne=["disabled","aria-label","onClick"],ce={class:"watchlist-symbol-name text-body-xs text-[var(--er-text-secondary)]"},de={class:"watchlist-price-cell text-body-xs text-[var(--er-text-primary)]"},me={class:"watchlist-price-cell text-body-xs text-[var(--er-text-primary)]"},ue={class:"flex h-[120px] items-center justify-center px-md text-center text-body-sm text-[var(--er-text-secondary)]"},ve=o({__name:"index",props:{symbols:{},selectedSymbol:{}},emits:["selectSymbol"],setup(o,{expose:p,emit:g}){const x=o,j=g,{selectedView:D,viewSelectRenderKey:T,searchText:R,viewNotice:O,createListDialogVisible:V,newListName:M,newListSymbols:F,createListError:E,addToListDialogVisible:U,symbolPendingListAdd:P,selectedCustomListId:B,addToListMessage:q,canAddToCustomList:K,panelBodyRef:W,filterControlsRef:G,viewOptions:J,tableFields:Q,symbolOptions:X,customListOptions:ve,customListSelectOptions:be,hasSelectedCustomList:ye,tableHeight:pe,tableRows:ge,emptyStateMessage:he,handleSearchChange:xe,clearSearch:fe,handleViewChange:Ce,handleRowClick:we,handleSortChanged:Le,getRowClass:Se,sortDirection:ke,baseIcon:_e,quoteIcon:Ae,toggleFavorite:Ne,openCreateListDialog:$e,closeCreateListDialog:je,handleNewListNameChange:De,handleNewListSymbolsChange:ze,createCustomList:Te,openAddToListDialog:Re,closeAddToListDialog:Oe,handleSelectedCustomListChange:Ve,addSymbolToSelectedList:Ie,resetCategory:Me,resetSort:Fe}=Y(()=>x.symbols,()=>x.selectedSymbol),Ee=e=>{we(e,e=>j("selectSymbol",e))};return p({resetCategory:Me,resetSort:Fe}),(o,p)=>{const g=a,x=s,j=t,Y=l,ve=e;return i(),u("div",{ref_key:"panelBodyRef",ref:W,class:"h-full min-h-0 flex flex-col gap-lg bg-[var(--er-surface-container)] px-sm py-md"},[c("div",{ref_key:"filterControlsRef",ref:G,class:"flex flex-col gap-sm"},[c("div",Z,[d(g,{value:f(R),placeholder:"Search symbol",size:"md",class:"watchlist-input-control w-full",onHandleChange:f(xe)},{suffix:n(()=>[f(R)?(i(),u("button",{key:0,type:"button",class:"watchlist-clear-button","aria-label":"Clear symbol search",onClick:p[0]||(p[0]=C((...e)=>f(fe)&&f(fe)(...e),["stop"]))},[d(f(L),{size:14})])):y("",!0)]),_:1},8,["value","onHandleChange"]),(i(),r(j,{key:f(T),value:f(D),options:f(J),size:"md",class:"watchlist-control w-full",onChange:f(Ce)},{footer:n(()=>[d(x,{size:"sm",color:"secondary",background:!1,class:"w-full",onClick:f($e)},{default:n(()=>[c("div",ee,[d(f(S),{size:14}),p[1]||(p[1]=c("span",null,"Create custom list",-1))])]),_:1},8,["onClick"])]),_:1},8,["value","options","onChange"]))]),f(O)?(i(),u("div",le,b(f(O)),1)):y("",!0)],512),d(ve,{class:"watchlist-custom-table min-h-0 flex-1","allow-sort-reset":"","hide-footer":"",height:f(pe),"max-height":f(pe),"table-layout":"fixed",size:"small",items:f(ge),fields:f(Q),"total-rows":f(ge).length,stripe:!1,"show-filter-by-default":!1,"row-class-name":f(Se),onOnRowClick:Ee,"onUpdate:onSortChanged":f(Le)},{"cell(symbol)":n(({item:e})=>[c("div",te,[c("div",se,[(i(),r(w(f(z)(f(_e)(e))),{size:18,class:"watchlist-symbol-badge-icon watchlist-symbol-badge-icon--base"})),(i(),r(w(f(z)(f(Ae)(e))),{size:18,class:"watchlist-symbol-badge-icon watchlist-symbol-badge-icon--quote"}))]),c("div",ae,[c("div",oe,[c("span",ie,b(e.symbol),1),c("button",{type:"button",class:"watchlist-row-action","aria-label":e.isFavorite?`Remove ${e.symbol} from favorites`:`Add ${e.symbol} to favorites`,onClick:C(l=>f(Ne)(e),["stop"])},[d(f(N),{size:16,"stroke-width":1.8,fill:e.isFavorite?"var(--er-text-warning)":"none",class:v(e.isFavorite?"text-[var(--er-text-warning)]":"text-[var(--er-icon-secondary)]")},null,8,["fill","class"])],8,re),c("button",{type:"button",class:"watchlist-row-action",disabled:!f(K),"aria-label":`Add ${e.symbol} to a custom list`,onClick:C(l=>f(Re)(e),["stop"])},[d(f($),{size:15})],8,ne),"closed"===e.marketStatus?(i(),r(Y,{key:0,color:"warning",size:"sm"},{default:n(()=>[...p[2]||(p[2]=[m(" Closed ",-1)])]),_:1})):y("",!0)]),c("p",ce,b(e.name),1)])])]),"cell(lastPrice)":n(({item:e})=>[c("span",de,b(e.lastPrice),1)]),"cell(volume)":n(({item:e})=>[c("span",me,b(e.volume),1)]),"sort-icon":n(({sortKey:e})=>["asc"===f(ke)(e)?(i(),r(f(k),{key:0})):"desc"===f(ke)(e)?(i(),r(f(_),{key:1,size:16})):(i(),r(f(A),{key:2,size:16}))]),empty:n(()=>[c("div",ue,b(f(he)),1)]),_:1},8,["height","max-height","items","fields","total-rows","row-class-name","onUpdate:onSortChanged"]),d(H,{"dialog-visible":f(V),"list-name":f(M),"selected-symbols":f(F),"symbol-options":f(X),error:f(E),onClose:f(je),onCreate:f(Te),"onUpdate:listName":f(De),"onUpdate:selectedSymbols":f(ze)},null,8,["dialog-visible","list-name","selected-symbols","symbol-options","error","onClose","onCreate","onUpdate:listName","onUpdate:selectedSymbols"]),d(I,{"dialog-visible":f(U),symbol:f(P),"selected-list-id":f(B),"custom-list-options":f(be),message:f(q),"can-add":f(ye)(),onClose:f(Oe),onAdd:f(Ie),"onUpdate:selectedListId":f(Ve)},null,8,["dialog-visible","symbol","selected-list-id","custom-list-options","message","can-add","onClose","onAdd","onUpdate:selectedListId"])],512)}}});export{ve as _,Y as u};