@eaera-com/eaera-widgets-v2 0.1.82 → 0.1.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/base/EaeraAlert.d.ts +1 -1
- package/dist/components/base/EaeraAutoComplete.d.ts +1 -1
- package/dist/components/base/EaeraAvatarGroup.d.ts +1 -1
- package/dist/components/base/EaeraBacktop.d.ts +1 -1
- package/dist/components/base/EaeraBadge.d.ts +2 -2
- package/dist/components/base/EaeraBreadcrumb.d.ts +1 -1
- package/dist/components/base/EaeraButton.d.ts +4 -4
- package/dist/components/base/EaeraCarousel.d.ts +4 -4
- package/dist/components/base/EaeraCarousel.mjs +1 -1
- package/dist/components/base/EaeraCheckbox.d.ts +2 -2
- package/dist/components/base/EaeraColorPicker.d.ts +1 -1
- package/dist/components/base/EaeraColorPicker.mjs +1 -1
- package/dist/components/base/EaeraDatePicker.d.ts +3 -3
- package/dist/components/base/EaeraDateTimePicker.d.ts +3 -3
- package/dist/components/base/EaeraDescriptions.d.ts +1 -1
- package/dist/components/base/EaeraDialog.d.ts +2 -2
- package/dist/components/base/EaeraDropdown.d.ts +1 -1
- package/dist/components/base/EaeraImage.d.ts +1 -1
- package/dist/components/base/EaeraInput.d.ts +1 -1
- package/dist/components/base/EaeraInputCode.d.ts +3 -3
- package/dist/components/base/EaeraInputNumber.d.ts +1 -1
- package/dist/components/base/EaeraInputTag.d.ts +1 -1
- package/dist/components/base/EaeraLink.d.ts +1 -1
- package/dist/components/base/EaeraPagination.d.ts +7 -7
- package/dist/components/base/EaeraPopconfirm.d.ts +2 -2
- package/dist/components/base/EaeraPopover.d.ts +2 -2
- package/dist/components/base/EaeraProgress.d.ts +3 -3
- package/dist/components/base/EaeraScrollbar.d.ts +4 -4
- package/dist/components/base/EaeraSegmented.d.ts +6 -6
- package/dist/components/base/EaeraSelect.d.ts +3 -3
- package/dist/components/base/EaeraSelectStatus.mjs +1 -1
- package/dist/components/base/EaeraSelectTag.mjs +1 -1
- package/dist/components/base/EaeraSkeleton.d.ts +1 -1
- package/dist/components/base/EaeraSlider.d.ts +1 -1
- package/dist/components/base/EaeraSlider.mjs +1 -1
- package/dist/components/base/EaeraSwitch.d.ts +1 -1
- package/dist/components/base/EaeraTab.d.ts +2 -2
- package/dist/components/base/EaeraTag.d.ts +3 -3
- package/dist/components/base/EaeraTag.mjs +1 -1
- package/dist/components/base/EaeraTimePicker.d.ts +1 -1
- package/dist/components/base/EaeraTimeSelect.d.ts +2 -2
- package/dist/components/base/EaeraTooltip.d.ts +38 -38
- package/dist/components/base/EaeraTreeSelect.d.ts +1 -1
- package/dist/components/base/EaeraUploadDefault.d.ts +1 -1
- package/dist/components/chunks/{EaeraCarousel-nVdAknBO.mjs → EaeraCarousel-5a2qdFil.mjs} +1 -1
- package/dist/components/chunks/{EaeraColorPicker-BmBd0tPb.mjs → EaeraColorPicker-B2VKi4o6.mjs} +1 -1
- package/dist/components/chunks/{EaeraCountryField-BAUKKPoc.mjs → EaeraCountryField-CrX6AtMI.mjs} +1 -1
- package/dist/components/chunks/{EaeraCountryFlag-HdsCS-D7.mjs → EaeraCountryFlag-Vr9lnLti.mjs} +1 -1
- package/dist/components/chunks/{EaeraCurrencyIcon-DCPxMDbT.mjs → EaeraCurrencyIcon-BHJ0P96z.mjs} +1 -1
- package/dist/components/chunks/{EaeraDynamicFieldRow-mZ5_nqkn.mjs → EaeraDynamicFieldRow-C-VUPCvg.mjs} +1 -1
- package/dist/components/chunks/{EaeraForm-DEoXRjat.mjs → EaeraForm-DRMCdjw4.mjs} +1 -1
- package/dist/components/chunks/{EaeraInputPhone-BAfQ9DpC.mjs → EaeraInputPhone-Cui1yXmx.mjs} +1 -1
- package/dist/components/chunks/{EaeraInputPhoneNumber-CDZnyaLx.mjs → EaeraInputPhoneNumber-YIRrq5-L.mjs} +1 -1
- package/dist/components/chunks/{EaeraSelectStatus-3bhsZt3A.mjs → EaeraSelectStatus-DF8-Svsr.mjs} +1 -1
- package/dist/components/chunks/{EaeraSelectTag-CGmqeNQJ.mjs → EaeraSelectTag-fwPFHO14.mjs} +1 -1
- package/dist/components/chunks/{EaeraSlider-Bk51h1zv.mjs → EaeraSlider-Ckftdbsw.mjs} +1 -1
- package/dist/components/chunks/{EaeraTableV2-CBaM5zp9.mjs → EaeraTableV2-CyfoAwDF.mjs} +1 -1
- package/dist/components/chunks/{EaeraTag-BgmzVuUW.mjs → EaeraTag-DsDZxISm.mjs} +1 -1
- package/dist/components/chunks/{EaeraWidgetBasicTradingStatistics-BMQMj5lo.mjs → EaeraWidgetBasicTradingStatistics-B_vLQ-YR.mjs} +1 -1
- package/dist/components/chunks/{EaeraWidgetMarginCalculator-BokNy1a7.mjs → EaeraWidgetMarginCalculator-BoV_EWi6.mjs} +1 -1
- package/dist/components/chunks/{EaeraWidgetPositionCalculator-D36MGO-E.mjs → EaeraWidgetPositionCalculator-DVbflfoJ.mjs} +1 -1
- package/dist/components/chunks/{iconSvg-BrZD7vO3.mjs → iconSvg-B2wrn2gi.mjs} +1 -1
- package/dist/components/chunks/{index-DhwN0sRS.mjs → index-4sT0yI4F.mjs} +1 -1
- package/dist/components/chunks/{index-9zJYqMyX.mjs → index-Bva_01ak.mjs} +1 -1
- package/dist/components/chunks/{index-ChWzksXo.mjs → index-C95yVkcL.mjs} +1 -1
- package/dist/components/chunks/{index-Cu4uZ9Nd.mjs → index-CLfZnTKh.mjs} +1 -1
- package/dist/components/chunks/{index-wGZD3Xyh.mjs → index-CdY_wl4g.mjs} +1 -1
- package/dist/components/chunks/{index-C-vkb_jO.mjs → index-DBNGSXX7.mjs} +1 -1
- package/dist/components/chunks/{index-DaBf9nij.mjs → index-DXC-pgpu.mjs} +1 -1
- package/dist/components/chunks/{index-BhBXYVZv.mjs → index-IeLjCes0.mjs} +1 -1
- package/dist/components/chunks/{index-Cm-cRnqS.mjs → index-Ton12Mr0.mjs} +1 -1
- package/dist/components/chunks/{index-CgcRJ8oq.mjs → index-ocf8b0Fd.mjs} +1 -1
- package/dist/components/chunks/{vendor-currency-symbol-map-C-1fEG2R.mjs → vendor-currency-symbol-map-3_wzZimq.mjs} +1 -1
- package/dist/components/chunks/vendor-dayjs-BwyIiGHg.mjs +1 -0
- package/dist/components/chunks/vendor-unorm-DkILX5Kw.mjs +1 -0
- package/dist/components/composite/EaeraDropdownV2.d.ts +7 -7
- package/dist/components/composite/EaeraDynamicFieldRow.mjs +1 -1
- package/dist/components/composite/EaeraForm.mjs +1 -1
- package/dist/components/composite/EaeraTableV2.mjs +1 -1
- package/dist/components/custom/EaeraChatBox/components/EaeraChatBoxBlockedState.d.ts +11 -0
- package/dist/components/custom/EaeraChatBox/components/EaeraChatBoxCodeBlock.d.ts +7 -0
- package/dist/components/custom/EaeraChatBox/components/EaeraChatBoxComposer.d.ts +133 -0
- package/dist/components/custom/EaeraChatBox/components/EaeraChatBoxHistoryList.d.ts +13 -0
- package/dist/components/custom/EaeraChatBox/components/EaeraChatBoxMarkdown.d.ts +8 -0
- package/dist/components/custom/EaeraChatBox/components/EaeraChatBoxMessageBubble.d.ts +7 -0
- package/dist/components/custom/EaeraChatBox/components/EaeraChatBoxMessageList.d.ts +10 -0
- package/dist/components/custom/EaeraChatBox/components/EaeraChatBoxMessageNav.d.ts +9 -0
- package/dist/components/custom/EaeraChatBox/components/EaeraChatBoxTypingIndicator.d.ts +3 -0
- package/dist/components/custom/EaeraChatBox/index.d.ts +22 -0
- package/dist/components/custom/EaeraCountryField.d.ts +1 -1
- package/dist/components/custom/EaeraCountryField.mjs +1 -1
- package/dist/components/custom/EaeraCountryFlag.d.ts +1 -1
- package/dist/components/custom/EaeraCountryFlag.mjs +1 -1
- package/dist/components/custom/EaeraCurrencyIcon.mjs +1 -1
- package/dist/components/custom/EaeraInputPhone.mjs +1 -1
- package/dist/components/custom/EaeraInputPhoneNumber.d.ts +17 -17
- package/dist/components/custom/EaeraInputPhoneNumber.mjs +1 -1
- package/dist/components/custom/EaeraMaskIcon.d.ts +1 -1
- package/dist/components/custom/EaeraSelectOther.d.ts +2 -2
- package/dist/components/custom/EaeraTreeV2.d.ts +1 -1
- package/dist/components/custom/EaeraWidgetBasicTradingStatistics.mjs +1 -1
- package/dist/components/custom/EaeraWidgetGrowthBalanceProfitChart.d.ts +1 -1
- package/dist/components/custom/EaeraWidgetMarginCalculator.mjs +1 -1
- package/dist/components/custom/EaeraWidgetMonthlyGainChart.d.ts +1 -1
- package/dist/components/custom/EaeraWidgetPLCalendar.d.ts +1 -1
- package/dist/components/custom/EaeraWidgetPositionCalculator.mjs +1 -1
- package/dist/components/custom/EaeraWidgetScoreChart.d.ts +1 -1
- package/dist/components/custom/EaeraWidgetTradeVolumeStatistics.d.ts +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.mjs +7 -1
- package/dist/components/utils/symbolBadge.mjs +1 -1
- package/dist/components/webtrade/EaeraCfdOrderPlacement/index.d.ts +2 -2
- package/dist/components/webtrade/EaeraCfdWatchlist.mjs +1 -1
- package/dist/components/webtrade/EaeraDrawingOverlay.mjs +1 -1
- package/dist/components/webtrade/EaeraLightweightChart.mjs +1 -1
- package/dist/components/webtrade/EaeraMarketDepth.mjs +1 -1
- package/dist/components/webtrade/EaeraOrderPlacement/index.d.ts +4 -4
- package/dist/components/webtrade/EaeraOrderPlacement.mjs +1 -1
- package/dist/components/webtrade/EaeraOrderlineOverlay.mjs +1 -1
- package/dist/components/webtrade/EaeraSymbolSpec.mjs +1 -1
- package/dist/components/webtrade/EaeraTimeNSales.mjs +1 -1
- package/dist/components/webtrade/EaeraTradingTable/index.d.ts +5 -5
- package/dist/components/webtrade/EaeraTradingTable.mjs +1 -1
- package/dist/components/webtrade/EaeraWatchlist/index.d.ts +2 -2
- package/dist/components/webtrade/EaeraWatchlist.mjs +1 -1
- package/dist/eaera-widgets-v2.es.js +14715 -13762
- package/dist/eaera-widgets-v2.umd.cjs +20 -19
- package/dist/index.d.ts +4 -0
- package/dist/stories/Popover/showcase/Basic.d.ts +8 -8
- package/dist/style.css +1 -1
- package/dist/types/EaeraChatBox.d.ts +45 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +7 -1
- package/dist/components/chunks/vendor-dayjs-D8w0D2To.mjs +0 -1
- package/dist/components/chunks/vendor-unorm-Degftfa1.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-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
|
+
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-DkILX5Kw.mjs";import"./useEaeraInputPhoneNumber-B72aLnQs.mjs";import"@element-plus/icons-vue";import{_ as q}from"./EaeraColorPicker-B2VKi4o6.mjs";import"echarts/core";import"echarts/renderers";import"echarts/charts";import"echarts/components";import"vue-echarts";import"./vendor-currency-symbol-map-3_wzZimq.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{ref as e,watch as t,computed as s,provide as a,inject as r,defineComponent as i,shallowRef as o,openBlock as l,createElementBlock as c,createVNode as p,unref as n,createSlots as d,withCtx as m,createElementVNode as u,renderSlot as v,normalizeStyle as k,toDisplayString as y,Fragment as b,renderList as _,normalizeClass as w,createBlock as f,resolveDynamicComponent as z,createCommentVNode as S,useSlots as g,normalizeProps as L,guardReactiveProps as D}from"vue";import{a as E}from"./vendor-vueuse-core-B96HGhR7.mjs";import{useI18n as x}from"vue-i18n";import"element-plus";import"element-plus/es";import{Search as C,ArrowDown as O,ArrowUp as P,MoveUp as V}from"@lucide/vue";import"./vendor-email-misspelled-0hsXkSSK.mjs";import{_ as N}from"./EaeraInput-CkbcAxy0.mjs";import"./vendor-unorm-
|
|
1
|
+
import{ref as e,watch as t,computed as s,provide as a,inject as r,defineComponent as i,shallowRef as o,openBlock as l,createElementBlock as c,createVNode as p,unref as n,createSlots as d,withCtx as m,createElementVNode as u,renderSlot as v,normalizeStyle as k,toDisplayString as y,Fragment as b,renderList as _,normalizeClass as w,createBlock as f,resolveDynamicComponent as z,createCommentVNode as S,useSlots as g,normalizeProps as L,guardReactiveProps as D}from"vue";import{a as E}from"./vendor-vueuse-core-B96HGhR7.mjs";import{useI18n as x}from"vue-i18n";import"element-plus";import"element-plus/es";import{Search as C,ArrowDown as O,ArrowUp as P,MoveUp as V}from"@lucide/vue";import"./vendor-email-misspelled-0hsXkSSK.mjs";import{_ as N}from"./EaeraInput-CkbcAxy0.mjs";import"./vendor-unorm-DkILX5Kw.mjs";import"./useEaeraInputPhoneNumber-B72aLnQs.mjs";import"@element-plus/icons-vue";import A from"../composite/EaeraDropdownV2.mjs";import"echarts/core";import"echarts/renderers";import"echarts/charts";import"echarts/components";import"vue-echarts";import"./vendor-currency-symbol-map-3_wzZimq.mjs";import"./vendor-sortablejs-D3DyHO5Y.mjs";const M={Bid:"bid",Ask:"ask",Last:"last"},R={Up:"up",Down:"down",Flat:"flat"},B={Up:"Up",Down:"Down",Center:"Center"},F=Symbol("EAERA_MARKET_DEPTH_CONTEXT_KEY"),j=(r,i)=>{const{t:o}=x(),l=e(r.searchValue),c=e(!1);t(()=>r.searchValue,e=>{l.value=e});const p=(e,t)=>{const s=o(e);return"string"==typeof s&&s.trim().length>0?s:t},n=s(()=>({searchValue:l.value,showingDropdown:c.value}));t(n,e=>{i("stateChange",e)},{immediate:!0});const d={searchValue:s({get:()=>l.value,set:e=>{l.value=e,i("update:searchValue",e)}}),searchPlaceholder:s(()=>r.searchPlaceholder??""),searchOptions:s(()=>r.searchOptions??[]),selectedSearchOption:s(()=>r.selectedSearchOption??""),loadingSearchOptions:s(()=>r.loadingSearchOptions??!1),rows:s(()=>r.rows),levels:s(()=>r.levels),lastPrice:s(()=>r.lastPrice),previousPrice:s(()=>r.previousPrice),tickSize:s(()=>r.tickSize),priceDirection:s(()=>r.priceDirection??R.Flat),viewportVsLast:s(()=>r.viewportVsLast??B.Center),shouldRenderEmptyState:s(()=>r.shouldRenderEmptyState??!1),priceLabel:s(()=>r.priceLabel||p("market.depth.table.price","Price")),sizeLabel:s(()=>r.sizeLabel||p("market.depth.table.size","Size")),fetchingSymbolLabel:s(()=>r.fetchingSymbolLabel||p("market.search.fetching-symbol","Fetching symbol")),symbolNotFoundLabel:s(()=>r.symbolNotFoundLabel||p("market.search.symbol-not-found","Symbol not found")),showingDropdown:s({get:()=>c.value,set:e=>{c.value=e}}),state:n,onResize:(e,t)=>i("resize",e,t),onSelectSearchOption:e=>i("select-search-option",e),onWheel:e=>i("wheel",e),onBackCenter:()=>i("back-center")};return a(F,d),d},$=()=>{const e=r(F);if(!e)throw new Error("useEaeraMarketDepth must be used inside EaeraMarketDepth");return e},U={class:"custom-market-depth-search__dropdown-anchor"},T={key:0,class:"custom-market-depth-search__empty body-sm text-placeholder"},W={key:0},I={key:1},K={key:1,class:"custom-market-depth-search__option-list"},Y=["onClick"],q={class:"body-md__w"},G={class:"body-sm"},H=i({__name:"EaeraMarketDepthSearch",setup(a){const{searchValue:r,searchPlaceholder:i,searchOptions:f,selectedSearchOption:z,loadingSearchOptions:S,fetchingSymbolLabel:g,symbolNotFoundLabel:L,showingDropdown:D,onSelectSearchOption:x}=$(),O=o(null),P=e(),{width:V}=E(O),M=s(()=>`${Math.max(V.value,200)}px`),R=e(r.value),B=e(!1);t(r,e=>{R.value=e});const F=e=>{B.value||(r.value=e)},j=()=>{B.value=!0},H=e=>{r.value=e.data},X=e=>{B.value=!1;const t=e.data??R.value;r.value=t},J=e=>{x(e)},Q=e=>{D.value=e};return t(r,e=>{e?P.value?.openDropdown():P.value?.closeDropdown()},{immediate:!0}),(e,t)=>(l(),c("div",{ref_key:"searchRef",ref:O,class:"custom-market-depth-search"},[p(n(N),{modelValue:R.value,"onUpdate:modelValue":t[0]||(t[0]=e=>R.value=e),placeholder:n(i),clearable:"",class:"watchlist-input custom-market-depth-search__input",onInput:F,onCompositionstart:j,onCompositionupdate:H,onCompositionend:X},d({_:2},[n(r)?void 0:{name:"suffix",fn:m(()=>[p(n(C),{size:16,class:"icon-primary"})]),key:"0"}]),1032,["modelValue","placeholder"]),u("div",U,[p(n(A),{ref_key:"dropdownRef",ref:P,trigger:"click",placement:"bottom-start",class:"custom-market-depth-search__dropdown",onVisibleChange:Q},{dropdown:m(()=>[v(e.$slots,"dropdown",{options:n(f),selected:n(z),minWidth:M.value,loading:n(S),fetchingSymbolLabel:n(g),symbolNotFoundLabel:n(L),selectOption:J},()=>[u("div",{class:"custom-market-depth-search__dropdown-panel",style:k({minWidth:M.value})},[n(S)||!n(f).length?(l(),c("div",T,[n(S)?(l(),c("div",W,y(n(g)),1)):(l(),c("div",I,y(n(L)),1))])):(l(),c("div",K,[(l(!0),c(b,null,_(n(f),e=>(l(),c("div",{key:e.value,class:w(["custom-market-depth-search__option",e.value===n(z)&&"is-selected"]),onClick:t=>J(e.value)},[u("div",q,y(e.label),1),u("div",G,y(e.description),1)],10,Y))),128))]))],4)])]),default:m(()=>[t[1]||(t[1]=u("div",{class:"custom-market-depth-search__dropdown-trigger"},null,-1))]),_:3},512)])],512))}}),X={class:"custom-market-depth-table"},J={class:"custom-market-depth-table__header text-primary"},Q={class:"custom-market-depth-table__header-price label-lg"},Z={class:"custom-market-depth-table__header-size label-lg"},ee=i({__name:"EaeraMarketDepthTable",setup(e){const{rows:t,levels:a,lastPrice:r,tickSize:i,priceDirection:o,viewportVsLast:p,shouldRenderEmptyState:d,priceLabel:m,sizeLabel:v,onWheel:k,onBackCenter:w}=$(),g={[B.Up]:P,[B.Down]:O},L=e=>{if(null==e)return null;const t=(e=>{if("number"!=typeof e||!Number.isFinite(e)||e<=0)return 2;const t=e.toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:20}),s=(t.includes(".")?t.replace(/0+$/,"").replace(/\.$/,""):t).split(".")[1];return s?s.length:0})(i.value);return Number(e).toFixed(t)},D=(e,t,s)=>({key:`${t}-${e.price}${s?.keySuffix?`-${s.keySuffix}`:""}`,price:L(e.price),size:t===M.Last?null:s?.sizeOverride??(t===M.Ask?e.askSize:e.bidSize),type:t,isEmpty:!1}),E=s(()=>g[p.value]),x=s(()=>{const e=Math.max(a.value,0);if(!e)return[];if(d.value)return Array.from({length:e},(e,t)=>({key:`empty-${t}`,price:null,size:null,type:null,isEmpty:!0}));const s=[...t.value].reverse().flatMap(e=>{const t=(e=>e.price>r.value?M.Ask:e.price<r.value?M.Bid:M.Last)(e),s=Math.abs(e.price-r.value)<1e-10;if(t!==M.Last||!s)return[D(e,t)];const a=D(e,M.Last),i=o.value!==R.Down,l=D(e,i?M.Bid:M.Ask,{keySuffix:"synthetic-last",sizeOverride:e.bidSize+e.askSize});return i?[a,l]:[l,a]});return s.length<=e?s:o.value===R.Down?s.slice(s.length-e):s.slice(0,e)}),C=s(()=>Math.max(...x.value.filter(e=>!e.isEmpty&&e.type!==M.Last).map(e=>e.size??0),1));return(e,t)=>(l(),c("div",X,[u("div",J,[u("div",Q,y(n(m)),1),u("div",Z,y(n(v)),1)]),u("div",{class:"custom-market-depth-table__rows",onWheel:t[0]||(t[0]=e=>n(k)(e.deltaY))},[(l(!0),c(b,null,_(x.value,(e,t)=>(l(),f(n(le),{key:e.key,price:e.price,type:e.type,size:e.size,"max-size":C.value,empty:e.isEmpty,"first-child":!t},null,8,["price","type","size","max-size","empty","first-child"]))),128))],32),n(d)||n(p)===n(B).Center?S("",!0):(l(),c("div",{key:0,class:"custom-market-depth-table__back-center",onClick:t[1]||(t[1]=(...e)=>n(w)&&n(w)(...e))},[(l(),f(z(E.value),{size:16,class:"icon-secondary"}))]))]))}}),te={key:0},se={key:1},ae={class:"custom-market-depth-price-row__size text-primary"},re={key:2},ie={class:"custom-market-depth-price-row__last-price"},oe={class:"custom-market-depth-price-row__last-icon"},le=i({__name:"EaeraMarketDepthPriceRow",props:{type:{},price:{},size:{},maxSize:{},firstChild:{type:Boolean},empty:{type:Boolean}},setup(e){const{lastPrice:t,previousPrice:a}=$(),r=e,i=s(()=>{const e=r.size??0,t=r.maxSize||1;return 100*Math.min(e/t,1)+"%"}),o=s(()=>t.value>a.value?{className:"is-increase",icon:"ArrowNarrowUp"}:t.value<a.value?{className:"is-decrease",icon:"ArrowNarrowDown"}:void 0);return(e,t)=>(l(),c("div",null,[r.empty?(l(),c("div",te,[u("div",{class:w(["custom-market-depth-price-row custom-market-depth-price-row--empty body-sm",r.firstChild&&"is-first-child"])},[...t[0]||(t[0]=[u("div",{class:"custom-market-depth-price-row__price"}," ",-1),u("div",{class:"custom-market-depth-price-row__size text-primary"}," ",-1)])],2)])):r.type===n(M).Ask||r.type===n(M).Bid?(l(),c("div",se,[u("div",{class:w(["custom-market-depth-price-row custom-market-depth-price-row--quantity body-sm",r.type===n(M).Ask?"custom-market-depth-price-row--ask":"custom-market-depth-price-row--bid",r.firstChild&&"is-first-child"]),style:k({"--size-percent":i.value})},[u("div",{class:w(["custom-market-depth-price-row__price",r.type===n(M).Ask?"is-ask":"is-bid"])},y(r.price),3),u("div",ae,y(r.size),1)],6)])):(l(),c("div",re,[u("div",{class:w(["custom-market-depth-price-row custom-market-depth-price-row--last-price body-lg__w",r.firstChild&&"is-first-child",o.value?.className])},[u("div",ie,[u("span",null,y(r.price),1)]),u("div",oe,[o.value?(l(),f(n(V),{key:0,size:16})):S("",!0)])],2)]))]))}}),ce={class:"custom-market-depth"},pe={class:"custom-market-depth__table"},ne=i({__name:"index",props:{searchValue:{},searchPlaceholder:{},searchOptions:{},selectedSearchOption:{},loadingSearchOptions:{type:Boolean},rows:{},levels:{},lastPrice:{},previousPrice:{},tickSize:{},priceDirection:{},viewportVsLast:{},shouldRenderEmptyState:{type:Boolean},priceLabel:{},sizeLabel:{},fetchingSymbolLabel:{},symbolNotFoundLabel:{}},emits:["resize","update:searchValue","select-search-option","wheel","back-center","stateChange"],setup(e,{expose:s,emit:a}){const r=g(),i=o(null),{width:k,height:y}=E(i),b=j(e,a);return s({state:b.state}),t([k,y],()=>{i.value&&b.onResize(k.value,y.value)}),(e,t)=>(l(),c("div",ce,[u("div",{ref_key:"searchRef",ref:i,class:"custom-market-depth__search"},[p(n(H),null,d({_:2},[n(r)["search-dropdown"]?{name:"dropdown",fn:m(t=>[v(e.$slots,"search-dropdown",L(D(t)))]),key:"0"}:void 0]),1024)],512),u("div",pe,[p(n(ee))])]))}});export{R as E,ne as _,M as a,B as b,j as p,$ as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineComponent as e,ref as l,computed as t,watch as n,openBlock as r,createElementBlock as i,withModifiers as a,createElementVNode as o,toDisplayString as s,createCommentVNode as u,createVNode as d,unref as c,createBlock as v,withCtx as m,createTextVNode as p,Fragment as f,normalizeClass as g,provide as y,inject as b,onMounted as _,onBeforeUnmount as x,normalizeStyle as k,renderList as P}from"vue";import{_ as S}from"./EaeraButton-BPVKRBOn.mjs";import{_ as C}from"./EaeraInput-CkbcAxy0.mjs";import{_ as w}from"./EaeraCheckbox-C_faN0pV.mjs";import{_ as L}from"./EaeraSwitch-BI3E0zPf.mjs";import{_ as E}from"./EaeraInputNumber-COC6rdNn.mjs";import{_ as T}from"./EaeraTag-BgmzVuUW.mjs";import{X as B}from"@lucide/vue";import{_ as N}from"./_plugin-vue_export-helper-BCo6x5W8.mjs";const z={class:"orderline-context-menu__header"},M={class:"orderline-context-menu__title-group"},D={class:"orderline-context-menu__title"},I={key:0,class:"orderline-context-menu__status"},A={class:"orderline-context-menu__status-text"},F={key:0,class:"orderline-context-menu__market"},R={class:"orderline-context-menu__market-left"},$={key:1,class:"orderline-context-menu__prices"},O={class:"orderline-context-menu__price-value"},q={key:1,class:"orderline-context-menu__price-sep"},H={class:"orderline-context-menu__price-value"},V={key:0,class:"orderline-context-menu__symbol-info"},j={class:"orderline-context-menu__symbol"},U={class:"orderline-context-menu__inputs"},Y={class:"orderline-context-menu__field"},K={key:0,class:"orderline-context-menu__field"},W={class:"orderline-context-menu__field"},X={key:1,class:"orderline-context-menu__margin"},G={class:"orderline-context-menu__advanced-toggle"},J={class:"orderline-context-menu__sl-tp"},Q={class:"orderline-context-menu__field"},Z={class:"orderline-context-menu__field-header"},ee={class:"orderline-context-menu__field-label-inline"},le={key:0,class:"orderline-context-menu__field-error"},te={class:"orderline-context-menu__field"},ne={class:"orderline-context-menu__field-header"},re={class:"orderline-context-menu__field-label-inline"},ie={key:0,class:"orderline-context-menu__field-error"},ae={class:"orderline-context-menu__comment"},oe={class:"orderline-context-menu__comment-header"},se={class:"orderline-context-menu__comment-counter"},ue={class:"orderline-context-menu__actions"},de=N(e({__name:"OrderlineContextMenu",props:{title:{},statusTagText:{default:""},side:{default:void 0},bid:{default:null},ask:{default:null},symbol:{default:""},advanced:{type:Boolean,default:!1},showStopLimitPrice:{type:Boolean,default:!1},marginText:{default:""},initialPrice:{default:""},initialStopLimitPrice:{default:""},initialVolume:{default:"0.01"},initialStopLoss:{default:""},initialTakeProfit:{default:""},initialStopLossEnabled:{type:Boolean,default:!1},initialTakeProfitEnabled:{type:Boolean,default:!1},initialComment:{default:""},referencePrice:{default:null},tickSize:{default:null},priceDisabled:{type:Boolean,default:!1},volumeDisabled:{type:Boolean,default:!1}},emits:["confirm","discard","close","update:advanced","update:stop-loss","update:take-profit"],setup(e,{emit:y}){const b=e,_=y,x=l(null!==b.initialPrice&&void 0!==b.initialPrice?String(b.initialPrice):b.referencePrice?String(b.referencePrice):""),k=l(null!==b.initialStopLimitPrice&&void 0!==b.initialStopLimitPrice?String(b.initialStopLimitPrice):""),P=l(null!==b.initialVolume&&void 0!==b.initialVolume?String(b.initialVolume):""),N=l(b.initialStopLossEnabled),de=l(null!==b.initialStopLoss&&void 0!==b.initialStopLoss?String(b.initialStopLoss):""),ce=l(b.initialTakeProfitEnabled),ve=l(null!==b.initialTakeProfit&&void 0!==b.initialTakeProfit?String(b.initialTakeProfit):""),me=l(b.initialComment),pe=t(()=>{const e=Number(de.value);return Number.isFinite(e)?e:void 0}),fe=t(()=>{const e=Number(ve.value);return Number.isFinite(e)?e:void 0}),ge=t(()=>{const e=Number(b.tickSize);return Number.isFinite(e)&&e>0?e:1e-5}),ye=t(()=>{const e=Number(b.referencePrice);return Number.isFinite(e)?e:null}),be=t(()=>N.value&&void 0!==pe.value&&null!==ye.value&&pe.value>=ye.value?"Must be below order price":""),he=t(()=>ce.value&&void 0!==fe.value&&null!==ye.value&&fe.value<=ye.value?"Must be above order price":""),_e=()=>{_("update:stop-loss",{enabled:N.value,price:pe.value})},xe=()=>{_("update:take-profit",{enabled:ce.value,price:fe.value})};n(()=>b.initialPrice,e=>{null!=e&&(x.value=String(e))}),n(()=>b.initialStopLoss,e=>{de.value=null!=e?String(e):""}),n(()=>b.initialTakeProfit,e=>{ve.value=null!=e?String(e):""}),n(()=>b.initialComment,e=>{me.value=e??""});const ke=e=>{x.value=null==e?"":String(e)},Pe=e=>{k.value=null==e?"":String(e)},Se=e=>{P.value=null==e?"":String(e)},Ce=e=>{de.value=null==e?"":String(e),_e()},we=e=>{ve.value=null==e?"":String(e),xe()},Le=e=>{me.value=e??""},Ee=()=>{_("confirm",{price:x.value,stopLimitPrice:k.value,volume:P.value,stopLossEnabled:N.value,stopLoss:de.value,takeProfitEnabled:ce.value,takeProfit:ve.value,comment:me.value}),_("close")},Te=()=>{_("discard"),_("close")};return(l,t)=>{const n=T,y=E,Be=L,Ne=w,ze=C,Me=S;return r(),i("div",{class:"orderline-context-menu",onMousedown:t[4]||(t[4]=a(()=>{},["stop"]))},[o("div",z,[o("div",M,[o("span",D,s(e.title),1),e.statusTagText?(r(),i("div",I,[t[5]||(t[5]=o("span",{class:"orderline-context-menu__status-dot"},null,-1)),o("span",A,s(e.statusTagText),1)])):u("",!0)]),o("button",{type:"button",class:"orderline-context-menu__close","aria-label":"Close",onClick:t[0]||(t[0]=e=>_("close"))},[d(c(B),{size:18})])]),e.side||e.bid||e.ask?(r(),i("div",F,[o("div",R,[e.side?(r(),v(n,{key:0,color:"buy"===e.side?"success":"danger",size:"sm",effect:"light",round:!1},{default:m(()=>[p(s("buy"===e.side?"BUY":"SELL"),1)]),_:1},8,["color"])):u("",!0),e.bid||e.ask?(r(),i("div",$,[e.bid?(r(),i(f,{key:0},[t[6]||(t[6]=o("span",{class:"orderline-context-menu__price-label"},"Bid",-1)),o("span",O,s(e.bid),1)],64)):u("",!0),e.bid&&e.ask?(r(),i("span",q,"/")):u("",!0),e.ask?(r(),i(f,{key:2},[t[7]||(t[7]=o("span",{class:"orderline-context-menu__price-label"},"Ask",-1)),o("span",H,s(e.ask),1)],64)):u("",!0)])):u("",!0)]),e.symbol?(r(),i("div",V,[o("span",j,s(e.symbol),1),t[8]||(t[8]=o("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none"},[o("circle",{cx:"6",cy:"6",r:"5.25",stroke:"currentColor","stroke-width":"1"}),o("path",{d:"M6 5v3.5M6 3.5v.5",stroke:"currentColor","stroke-width":"1","stroke-linecap":"round"})],-1))])):u("",!0)])):u("",!0),o("div",U,[o("div",Y,[t[9]||(t[9]=o("div",{class:"orderline-context-menu__field-label"},[o("span",null,"Price"),o("span",{class:"orderline-context-menu__required"},"*")],-1)),d(y,{value:x.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:ge.value,disabled:e.priceDisabled},class:"w-full",onHandleChange:ke},null,8,["value","other-props"])]),e.showStopLimitPrice?(r(),i("div",K,[t[10]||(t[10]=o("div",{class:"orderline-context-menu__field-label"},[o("span",null,"Stop Limit Price"),o("span",{class:"orderline-context-menu__required"},"*")],-1)),d(y,{value:k.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:ge.value},class:"w-full",onHandleChange:Pe},null,8,["value","other-props"])])):u("",!0),o("div",W,[t[11]||(t[11]=o("div",{class:"orderline-context-menu__field-label"},[o("span",null,"Volume"),o("span",{class:"orderline-context-menu__required"},"*")],-1)),d(y,{value:P.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:.01,disabled:e.volumeDisabled},class:"w-full",onHandleChange:Se},null,8,["value","other-props"])])]),e.marginText?(r(),i("p",X,s(e.marginText),1)):u("",!0),o("div",G,[o("span",{class:g(["orderline-context-menu__advanced-label",{"orderline-context-menu__advanced-label--active":e.advanced}])}," Advanced ",2),d(Be,{"model-value":e.advanced,size:"sm","onUpdate:modelValue":t[1]||(t[1]=e=>_("update:advanced",e))},null,8,["model-value"])]),e.advanced?(r(),i(f,{key:2},[o("div",J,[o("div",Q,[o("div",Z,[o("div",ee,[d(Ne,{"model-value":N.value,size:"sm",color:"success","onUpdate:modelValue":t[2]||(t[2]=e=>(e=>{if(N.value=e,e&&!de.value&&null!==ye.value){const e=ge.value,l="buy"===b.side?ye.value-20*e:ye.value+20*e;de.value=String(Number(l.toFixed(8)))}_e()})(Boolean(e)))},null,8,["model-value"]),t[12]||(t[12]=o("span",null,"Stop Loss",-1))]),t[13]||(t[13]=o("span",{class:"orderline-context-menu__required"},"*",-1))]),d(y,{value:pe.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:ge.value,disabled:!N.value},class:"w-full",onHandleChange:Ce},null,8,["value","other-props"]),be.value?(r(),i("span",le,s(be.value),1)):u("",!0)]),o("div",te,[o("div",ne,[o("div",re,[t[14]||(t[14]=o("span",null,"Take Profit",-1)),d(Ne,{"model-value":ce.value,size:"sm",color:"success","onUpdate:modelValue":t[3]||(t[3]=e=>(e=>{if(ce.value=e,e&&!ve.value&&null!==ye.value){const e=ge.value,l="buy"===b.side?ye.value+30*e:ye.value-30*e;ve.value=String(Number(l.toFixed(8)))}xe()})(Boolean(e)))},null,8,["model-value"])]),t[15]||(t[15]=o("span",{class:"orderline-context-menu__required"},"*",-1))]),d(y,{value:fe.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:ge.value,disabled:!ce.value},class:"w-full",onHandleChange:we},null,8,["value","other-props"]),he.value?(r(),i("span",ie,s(he.value),1)):u("",!0)])]),o("div",ae,[o("div",oe,[t[16]||(t[16]=o("span",null,"Comment",-1)),o("span",se,s(me.value.length)+"/"+s(30),1)]),d(ze,{value:me.value,placeholder:"Add a comment",size:"sm","other-props":{maxlength:30},class:"w-full",onHandleChange:Le},null,8,["value","other-props"])])],64)):u("",!0),o("div",ue,[d(Me,{color:"contrast",plain:"",size:"sm",onClick:Te},{default:m(()=>[...t[17]||(t[17]=[p("Discard",-1)])]),_:1}),d(Me,{color:"primary",size:"sm",onClick:Ee},{default:m(()=>[...t[18]||(t[18]=[p("Confirm",-1)])]),_:1})])],32)}}}),[["__scopeId","data-v-2d8976ac"]]),ce=e=>e?{surfacePrimary:"#191D23",surfacePositive:"#16c784",surfaceNegative:"#ef4444",surfaceElevated:"#323A45",surfaceAction:"#A259FB",textPrimary:"#F0F1F3",textSecondary:"#B1B9C5",borderPrimary:"#323A45",borderPrimaryInverse:"#D8DCE2",borderAction:"#A259FB"}:{surfacePrimary:"white",surfacePositive:"#16c784",surfaceNegative:"#ef4444",surfaceElevated:"#d8dce2",surfaceAction:"#A259FB",textPrimary:"#0f1115",textSecondary:"#4b5768",borderPrimary:"#d8dce2",borderPrimaryInverse:"#323a45",borderAction:"#A259FB"},ve=(e="neutral",l="order",t,n)=>{const r=ce(t),i="position"===l;let a;return a="stop-loss"===n?r.surfaceNegative:"take-profit"===n?r.surfacePositive:i?r.borderAction:"buy"===e?r.surfacePositive:"sell"===e?r.surfaceNegative:r.borderAction,{lineColor:a,lineWidth:2,lineDash:[0,0],badgeBackgroundColor:r.surfacePrimary,badgeBorderColor:a,badgeTextColor:i?r.textPrimary:a,handleColor:a,handleBackgroundColor:i?r.surfacePrimary:"transparent",handleBorderColor:i?r.surfacePrimary:"transparent",deleteColor:i?r.textPrimary:a,deleteBackgroundColor:i?r.borderAction:r.surfacePrimary,deleteBorderColor:a,fontSize:12}},me=Symbol("EAERA_ORDERLINE_OVERLAY_CONTEXT_KEY"),pe=(e,r)=>{const i=l(null),a=l({}),o=t(()=>({draggingLineId:i.value,draftPrices:a.value}));n(o,e=>{r("stateChange",e)},{immediate:!0});const s={orderLines:t(()=>e.orderLines??[]),chartInstance:t(()=>e.chartInstance??null),seriesInstance:t(()=>e.seriesInstance??null),orderLineTool:t(()=>e.orderLineTool??null),renderKey:t(()=>e.renderKey??0),marketPrice:t(()=>e.marketPrice??null),tickSize:t(()=>e.tickSize??null),dark:t(()=>e.dark),state:o,onDeleteLine:e=>{r("deleteLine",e)},onLinePriceChange:(e,l)=>{r("linePriceChange",e,l)},onLinePricePreview:(e,l)=>{r("linePricePreview",e,l)},onDragStateChange:e=>{i.value=e,r("dragStateChange",e)},onDraftPricesChange:e=>{a.value=e},onSLTPChange:(e,l,t)=>{r("slTpChange",e,l,t)}};return y(me,s),s},fe=()=>{const e=b(me);if(!e)throw new Error("useEaeraOrderlineOverlay must be used inside EaeraOrderlineOverlay");return e},ge=["onMousedown","onDblclick"],ye=["onDblclick"],be=e({__name:"index",props:{orderLines:{},chartInstance:{},seriesInstance:{},orderLineTool:{},renderKey:{},marketPrice:{},tickSize:{},dark:{type:Boolean}},emits:["deleteLine","linePriceChange","linePricePreview","dragStateChange","slTpChange","stateChange"],setup(e,{expose:a,emit:d}){const m=pe(e,d),{orderLines:y,chartInstance:b,seriesInstance:S,orderLineTool:C,renderKey:w,marketPrice:L,tickSize:E,dark:T,state:B,onDeleteLine:N,onLinePriceChange:z,onLinePricePreview:M,onDragStateChange:D,onDraftPricesChange:I,onSLTPChange:A}=m,F=l(0),R=l(0),$=new Set,O=l(!1);let q=null,H=null,V=null;const j=l(null),U=l(null),Y=l({}),K=()=>b.value,W=()=>S.value,X=(e,l,t)=>Math.min(Math.max(e,l),t),G=(e,l,t)=>{const n=t.filter(e=>e>0),r={height:`${Math.max(l,1)}px`};if(n.length>=2){const[l,t]=n;return{...r,backgroundImage:`repeating-linear-gradient(to right, ${e} 0, ${e} ${l}px, transparent ${l}px, transparent ${l+t}px)`,backgroundSize:`${l+t}px 100%`}}return{...r,backgroundColor:e}},J=()=>{null!==H&&"undefined"!=typeof window&&(window.cancelAnimationFrame(H),H=null)},Q=()=>{R.value+=1,H=window.requestAnimationFrame(Q)},Z=()=>{"undefined"!=typeof window&&null===H&&0!==y.value.length&&(H=window.requestAnimationFrame(Q))},ee=()=>{q?.disconnect(),$.clear()},le=()=>{if("undefined"==typeof ResizeObserver)return;q||(q=new ResizeObserver(()=>{F.value+=1}));const e=K(),l=e?.chartElement(),t=[l,e&&"function"==typeof e.panes?e.panes()[0]?.getHTMLElement?.()??null:null].filter(e=>null!=e);t.length===$.size&&t.every(e=>$.has(e))||(ee(),t.forEach(e=>{q?.observe(e),$.add(e)}),F.value+=1)},te=e=>{const l=(e=>{const l=Number(e);if(!Number.isFinite(l)||l<=0)return 2;const t=l.toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:20}),n=(t.includes(".")?t.replace(/0+$/,"").replace(/\.$/,""):t).split(".")[1];return n?n.length:0})(E.value);return Number(e).toFixed(l)},ne=(e,l)=>{if(!Number.isFinite(l))return l;const t=Number(E.value)||1e-5;if("stop-loss"===e.lineRole&&void 0!==e.entryPrice)return"buy"===e.side?Math.min(l,e.entryPrice-t):Math.max(l,e.entryPrice+t);if("take-profit"===e.lineRole&&void 0!==e.entryPrice)return"buy"===e.side?Math.max(l,e.entryPrice+t):Math.min(l,e.entryPrice-t);const n=(e=>{if("number"==typeof e)return Number.isFinite(e)?e:null;if("string"==typeof e&&""!==e.trim()){const l=Number(e);return Number.isFinite(l)?l:null}return null})(L.value);return null===n?l:"buy"===e.side?Math.min(l,n):"sell"===e.side?Math.max(l,n):l},re=t(()=>{const e=w.value,l=F.value,t=R.value;return e<0||l<0||t<0?null:(()=>{const e=K(),l=j.value?.getBoundingClientRect();if(!e||!l)return null;const t=e.chartElement(),n=t.getBoundingClientRect(),r="function"==typeof e.panes?e.panes()[0]?.getHTMLElement?.()??null:null,i=r?.getBoundingClientRect(),a=e.paneSize?.(0),o=e.priceScale("left").width(),s=e.priceScale("right").width(),u=e.timeScale().height(),d=a?.width??Math.max(0,t.clientWidth-o-s),c=a?.height??Math.max(0,t.clientHeight-u);return{top:(i?i.top:n.top)-l.top,left:n.left-l.left+o,width:d,height:i?.height??c}})()}),ie=t(()=>{const e=re.value;return e?{top:`${e.top}px`,left:`${e.left}px`,width:`${e.width}px`,height:`${e.height}px`}:null}),ae=l(null),oe=l(null),se=new Set;let ue=!0;const me=e=>{const l=y.value.find(l=>l.id===e);l&&(be.value={x:0,y:0},oe.value=e,ae.value=(e=>{const{primary:l,quantity:t}=(e=>{const l=e.split("|").map(e=>e.trim());return{primary:l[0]??"",quantity:l[1]??"",price:l[2]??""}})(e.label),n=e.readonly&&"order"===e.type,r=l.replace(/^[+-]/,""),i=e.parentId??e.id,a=y.value.find(e=>e.parentId===i&&"stop-loss"===e.lineRole),o=y.value.find(e=>e.parentId===i&&"take-profit"===e.lineRole),s=y.value.find(e=>e.id===i),u=s?.price??e.entryPrice??e.price;return{title:n?"Market Order":"Order",statusTagText:t?`${l} ${t}`:l,price:e.price,side:"neutral"!==e.side?e.side:void 0,volume:r,advanced:n,entryPrice:u,initialStopLossEnabled:!!a,initialStopLoss:a?.price,initialTakeProfitEnabled:!!o,initialTakeProfit:o?.price}})(l))};n(()=>y.value,e=>{const l=new Set;for(const t of e)l.add(t.id);se.clear(),l.forEach(e=>se.add(e)),ue?ue=!1:oe.value&&!l.has(oe.value)&&(ae.value=null,oe.value=null)},{deep:!0});const fe=t(()=>!!oe.value&&(y.value.find(e=>e.id===oe.value)?.readonly??!1)),be=l({x:0,y:0}),he=l(!1),_e=t(()=>{const e=K(),l=j.value;return e&&l?{width:l.clientWidth,height:l.clientHeight}:null}),xe=t(()=>{if(!ae.value||!_e.value)return null;const{width:e,height:l}=_e.value,t=X(e-382-20+be.value.x,0,e-382);return{position:"absolute",top:`${X(20+be.value.y,0,l-460)}px`,left:`${t}px`}});let ke=0,Pe=0;const Se=e=>{if(!_e.value)return;e.target.closest('input, button, select, textarea, [role="switch"], [role="checkbox"]')||(he.value=!0,ke=e.clientX-be.value.x,Pe=e.clientY-be.value.y,document.body.style.userSelect="none",window.addEventListener("pointermove",Ce),window.addEventListener("pointerup",we))},Ce=e=>{be.value={x:e.clientX-ke,y:e.clientY-Pe}},we=()=>{he.value=!1,document.body.style.userSelect="",window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",we)},Le=e=>{const l=y.value.find(l=>l.id===e);return l?l.parentId??l.id:null},Ee=e=>{const l=Le(oe.value??"");if(!l)return;const t=y.value.find(e=>e.parentId===l&&"take-profit"===e.lineRole),n=t?.price??null,r=e.enabled&&void 0!==e.price?e.price:null;A(l,r,n)},Te=e=>{const l=Le(oe.value??"");if(!l)return;const t=y.value.find(e=>e.parentId===l&&"stop-loss"===e.lineRole),n=t?.price??null,r=e.enabled&&void 0!==e.price?e.price:null;A(l,n,r)},Be=e=>{ae.value=null,oe.value=null},Ne=()=>{ae.value=null,oe.value=null},ze=()=>{oe.value&&(N(oe.value),Ne())},Me=t(()=>"boolean"==typeof T.value?T.value:O.value),De=t(()=>{const e=w.value,l=R.value,t=W(),n=K(),r=re.value;return!t||!n||!r||e<0||l<0?[]:y.value.map(e=>{const l=(e=>Y.value[e.id]??e.price)(e),t=((e,l)=>{const t=W();if(!t)return null;const n=t.priceToCoordinate(e);if(null!==n)return n;const r=t.priceScale().getVisibleRange();if(!r)return null;const i=Math.min(r.from,r.to);return e>Math.max(r.from,r.to)?-1:e<i?l+1:null})(l,r.height);if(null===t)return null;const n=((e,l)=>e<0?"top":e>l?"bottom":"middle")(t,r.height),i=X(t,0,r.height),a=ce(Me.value),o={...ve(e.side,e.type,Me.value,e.lineRole),...e.options},[s,u,d]=((e,l)=>{const t=e.split("|").map(e=>e.trim()),n=te(l);return t.length>=3?(t[t.length-1]=n,t):2===t.length?[...t,n]:1===t.length?[t[0],"",n]:["","",n]})(e.label,l),c=a.textPrimary,[v]=[s],m={volume:v,pnl:u,price:d};return{...e,livePrice:l,edgePlacement:n,orderParts:{primary:v,quantity:u,price:d},positionParts:m,containerStyle:{top:`${i}px`},lineStyle:G(o.lineColor,o.lineWidth,o.lineDash),lineColor:o.lineColor,badgeWrapperStyle:{marginLeft:"12px"},badgeStyle:{borderColor:o.badgeBorderColor,backgroundColor:o.badgeBackgroundColor,color:o.badgeTextColor},middleStyle:{backgroundColor:o.badgeBackgroundColor,color:a.textPrimary},volumeStyle:{backgroundColor:"transparent",color:a.textPrimary},separatorStyle:{backgroundColor:a.borderPrimaryInverse},deleteStyle:{backgroundColor:o.deleteBackgroundColor,color:o.deleteColor,borderColor:o.deleteBorderColor},deleteButtonStyle:{color:o.deleteColor,borderColor:o.deleteBorderColor},priceStyle:{color:a.textPrimary},pnlStyle:{color:c},dragStyle:{backgroundColor:o.handleBackgroundColor,color:o.handleColor}}}).filter(e=>null!==e)}),Ie=()=>{const e=U.value;if(!e)return;const l=Y.value[e];if(U.value=null,D(null),document.body.style.userSelect="",window.removeEventListener("mousemove",Ae),window.removeEventListener("mouseup",Ie),"number"==typeof l){z(e,l);const{[e]:t,...n}=Y.value;Y.value=n,I(n)}},Ae=e=>{const l=U.value,t=W(),n=(()=>{const e=K();if(!e)return null;const l="function"==typeof e.panes?e.panes()[0]?.getHTMLElement?.()??null:null;return l?.getBoundingClientRect()??e.chartElement().getBoundingClientRect()})();if(!l||!t||!n)return;const r=e.clientY-n.top,i=t.coordinateToPrice(r);if("number"!=typeof i||Number.isNaN(i))return;const a=y.value.find(e=>e.id===l);if(!a)return;const o=ne(a,i),s=Number(te(o)),u={...Y.value,[l]:s};Y.value=u,I(u),M(l,s),((e,l)=>{const t=C.value?.orderLines.find(l=>l.localId===e);t?.updatePrice(l)})(l,s)},Fe=e=>{O.value=e.matches};return n(()=>w.value,()=>{le()},{immediate:!0}),n(()=>y.value.length,e=>{e>0?Z():J()},{immediate:!0}),_(()=>{le(),Z(),"undefined"!=typeof window&&"function"==typeof window.matchMedia&&(V=window.matchMedia("(prefers-color-scheme: dark)"),O.value=V.matches,V.addEventListener("change",Fe))}),x(()=>{window.removeEventListener("mousemove",Ae),window.removeEventListener("mouseup",Ie),window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",we),ee(),J(),V?.removeEventListener("change",Fe),V=null}),a({state:B,openMenu:e=>{be.value={x:0,y:0},oe.value=e.lineId??null,ae.value=e.menuData}}),(e,l)=>(r(),i("div",{ref_key:"overlayRootRef",ref:j,class:"custom-order-line-overlay"},[ie.value?(r(),i("div",{key:0,class:"custom-order-line-overlay__pane",style:k(ie.value)},[(r(!0),i(f,null,P(De.value,e=>(r(),i("div",{key:e.id,class:g(["custom-order-line-item",`custom-order-line-item--edge-${e.edgePlacement}`]),style:k(e.containerStyle)},["middle"===e.edgePlacement?(r(),i("div",{key:0,class:g(["custom-order-line-item__line",{"custom-order-line-item__line--draggable":"order"===e.type&&!e.readonly,"custom-order-line-item__line--clickable":e.readonly}]),style:k(e.lineStyle),onMousedown:l=>{return"order"!==e.type||e.readonly?void 0:(t=e.id,(n=l).preventDefault(),n.stopPropagation(),U.value=t,D(t),document.body.style.userSelect="none",window.addEventListener("mousemove",Ae),void window.addEventListener("mouseup",Ie));var t,n},onDblclick:l=>e.readonly?me(e.id):void 0},null,46,ge)):u("",!0),o("div",{class:g(["custom-order-line-item__label",{"custom-order-line-item__label--clickable":e.readonly}]),style:k({color:e.lineColor}),onDblclick:l=>e.readonly?me(e.id):void 0},[p(s(e.orderParts.primary)+" ",1),l[0]||(l[0]=o("span",{class:"custom-order-line-item__label-sep"},"·",-1)),p(" "+s(e.orderParts.quantity)+" ",1),l[1]||(l[1]=o("span",{class:"custom-order-line-item__label-sep"},"·",-1)),p(" "+s(e.orderParts.price),1)],46,ye)],6))),128))],4)):u("",!0),ae.value&&xe.value?(r(),v(de,{key:1,class:g(["custom-order-line-overlay__menu",{"custom-order-line-overlay__menu--dragging":he.value}]),style:k(xe.value),title:ae.value.title,"status-tag-text":ae.value.statusTagText,"reference-price":ae.value.entryPrice??ae.value.price,"tick-size":c(E),side:ae.value.side,advanced:ae.value.advanced,"initial-volume":ae.value.volume,"initial-stop-loss":ae.value.initialStopLoss,"initial-take-profit":ae.value.initialTakeProfit,"initial-stop-loss-enabled":ae.value.initialStopLossEnabled,"initial-take-profit-enabled":ae.value.initialTakeProfitEnabled,"price-disabled":fe.value,"volume-disabled":fe.value,onPointerdown:Se,onClose:Ne,onConfirm:Be,onDiscard:ze,"onUpdate:stopLoss":Ee,"onUpdate:takeProfit":Te},null,8,["class","style","title","status-tag-text","reference-price","tick-size","side","advanced","initial-volume","initial-stop-loss","initial-take-profit","initial-stop-loss-enabled","initial-take-profit-enabled","price-disabled","volume-disabled"])):u("",!0)],512))}});export{de as O,be as _,pe as p,fe as u};
|
|
1
|
+
import{defineComponent as e,ref as l,computed as t,watch as n,openBlock as r,createElementBlock as i,withModifiers as a,createElementVNode as o,toDisplayString as s,createCommentVNode as u,createVNode as d,unref as c,createBlock as v,withCtx as m,createTextVNode as p,Fragment as f,normalizeClass as g,provide as y,inject as b,onMounted as _,onBeforeUnmount as x,normalizeStyle as k,renderList as P}from"vue";import{_ as S}from"./EaeraButton-BPVKRBOn.mjs";import{_ as C}from"./EaeraInput-CkbcAxy0.mjs";import{_ as w}from"./EaeraCheckbox-C_faN0pV.mjs";import{_ as L}from"./EaeraSwitch-BI3E0zPf.mjs";import{_ as E}from"./EaeraInputNumber-COC6rdNn.mjs";import{_ as T}from"./EaeraTag-DsDZxISm.mjs";import{X as B}from"@lucide/vue";import{_ as N}from"./_plugin-vue_export-helper-BCo6x5W8.mjs";const z={class:"orderline-context-menu__header"},M={class:"orderline-context-menu__title-group"},D={class:"orderline-context-menu__title"},I={key:0,class:"orderline-context-menu__status"},A={class:"orderline-context-menu__status-text"},F={key:0,class:"orderline-context-menu__market"},R={class:"orderline-context-menu__market-left"},$={key:1,class:"orderline-context-menu__prices"},O={class:"orderline-context-menu__price-value"},q={key:1,class:"orderline-context-menu__price-sep"},H={class:"orderline-context-menu__price-value"},V={key:0,class:"orderline-context-menu__symbol-info"},j={class:"orderline-context-menu__symbol"},U={class:"orderline-context-menu__inputs"},Y={class:"orderline-context-menu__field"},K={key:0,class:"orderline-context-menu__field"},W={class:"orderline-context-menu__field"},X={key:1,class:"orderline-context-menu__margin"},G={class:"orderline-context-menu__advanced-toggle"},J={class:"orderline-context-menu__sl-tp"},Q={class:"orderline-context-menu__field"},Z={class:"orderline-context-menu__field-header"},ee={class:"orderline-context-menu__field-label-inline"},le={key:0,class:"orderline-context-menu__field-error"},te={class:"orderline-context-menu__field"},ne={class:"orderline-context-menu__field-header"},re={class:"orderline-context-menu__field-label-inline"},ie={key:0,class:"orderline-context-menu__field-error"},ae={class:"orderline-context-menu__comment"},oe={class:"orderline-context-menu__comment-header"},se={class:"orderline-context-menu__comment-counter"},ue={class:"orderline-context-menu__actions"},de=N(e({__name:"OrderlineContextMenu",props:{title:{},statusTagText:{default:""},side:{default:void 0},bid:{default:null},ask:{default:null},symbol:{default:""},advanced:{type:Boolean,default:!1},showStopLimitPrice:{type:Boolean,default:!1},marginText:{default:""},initialPrice:{default:""},initialStopLimitPrice:{default:""},initialVolume:{default:"0.01"},initialStopLoss:{default:""},initialTakeProfit:{default:""},initialStopLossEnabled:{type:Boolean,default:!1},initialTakeProfitEnabled:{type:Boolean,default:!1},initialComment:{default:""},referencePrice:{default:null},tickSize:{default:null},priceDisabled:{type:Boolean,default:!1},volumeDisabled:{type:Boolean,default:!1}},emits:["confirm","discard","close","update:advanced","update:stop-loss","update:take-profit"],setup(e,{emit:y}){const b=e,_=y,x=l(null!==b.initialPrice&&void 0!==b.initialPrice?String(b.initialPrice):b.referencePrice?String(b.referencePrice):""),k=l(null!==b.initialStopLimitPrice&&void 0!==b.initialStopLimitPrice?String(b.initialStopLimitPrice):""),P=l(null!==b.initialVolume&&void 0!==b.initialVolume?String(b.initialVolume):""),N=l(b.initialStopLossEnabled),de=l(null!==b.initialStopLoss&&void 0!==b.initialStopLoss?String(b.initialStopLoss):""),ce=l(b.initialTakeProfitEnabled),ve=l(null!==b.initialTakeProfit&&void 0!==b.initialTakeProfit?String(b.initialTakeProfit):""),me=l(b.initialComment),pe=t(()=>{const e=Number(de.value);return Number.isFinite(e)?e:void 0}),fe=t(()=>{const e=Number(ve.value);return Number.isFinite(e)?e:void 0}),ge=t(()=>{const e=Number(b.tickSize);return Number.isFinite(e)&&e>0?e:1e-5}),ye=t(()=>{const e=Number(b.referencePrice);return Number.isFinite(e)?e:null}),be=t(()=>N.value&&void 0!==pe.value&&null!==ye.value&&pe.value>=ye.value?"Must be below order price":""),he=t(()=>ce.value&&void 0!==fe.value&&null!==ye.value&&fe.value<=ye.value?"Must be above order price":""),_e=()=>{_("update:stop-loss",{enabled:N.value,price:pe.value})},xe=()=>{_("update:take-profit",{enabled:ce.value,price:fe.value})};n(()=>b.initialPrice,e=>{null!=e&&(x.value=String(e))}),n(()=>b.initialStopLoss,e=>{de.value=null!=e?String(e):""}),n(()=>b.initialTakeProfit,e=>{ve.value=null!=e?String(e):""}),n(()=>b.initialComment,e=>{me.value=e??""});const ke=e=>{x.value=null==e?"":String(e)},Pe=e=>{k.value=null==e?"":String(e)},Se=e=>{P.value=null==e?"":String(e)},Ce=e=>{de.value=null==e?"":String(e),_e()},we=e=>{ve.value=null==e?"":String(e),xe()},Le=e=>{me.value=e??""},Ee=()=>{_("confirm",{price:x.value,stopLimitPrice:k.value,volume:P.value,stopLossEnabled:N.value,stopLoss:de.value,takeProfitEnabled:ce.value,takeProfit:ve.value,comment:me.value}),_("close")},Te=()=>{_("discard"),_("close")};return(l,t)=>{const n=T,y=E,Be=L,Ne=w,ze=C,Me=S;return r(),i("div",{class:"orderline-context-menu",onMousedown:t[4]||(t[4]=a(()=>{},["stop"]))},[o("div",z,[o("div",M,[o("span",D,s(e.title),1),e.statusTagText?(r(),i("div",I,[t[5]||(t[5]=o("span",{class:"orderline-context-menu__status-dot"},null,-1)),o("span",A,s(e.statusTagText),1)])):u("",!0)]),o("button",{type:"button",class:"orderline-context-menu__close","aria-label":"Close",onClick:t[0]||(t[0]=e=>_("close"))},[d(c(B),{size:18})])]),e.side||e.bid||e.ask?(r(),i("div",F,[o("div",R,[e.side?(r(),v(n,{key:0,color:"buy"===e.side?"success":"danger",size:"sm",effect:"light",round:!1},{default:m(()=>[p(s("buy"===e.side?"BUY":"SELL"),1)]),_:1},8,["color"])):u("",!0),e.bid||e.ask?(r(),i("div",$,[e.bid?(r(),i(f,{key:0},[t[6]||(t[6]=o("span",{class:"orderline-context-menu__price-label"},"Bid",-1)),o("span",O,s(e.bid),1)],64)):u("",!0),e.bid&&e.ask?(r(),i("span",q,"/")):u("",!0),e.ask?(r(),i(f,{key:2},[t[7]||(t[7]=o("span",{class:"orderline-context-menu__price-label"},"Ask",-1)),o("span",H,s(e.ask),1)],64)):u("",!0)])):u("",!0)]),e.symbol?(r(),i("div",V,[o("span",j,s(e.symbol),1),t[8]||(t[8]=o("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none"},[o("circle",{cx:"6",cy:"6",r:"5.25",stroke:"currentColor","stroke-width":"1"}),o("path",{d:"M6 5v3.5M6 3.5v.5",stroke:"currentColor","stroke-width":"1","stroke-linecap":"round"})],-1))])):u("",!0)])):u("",!0),o("div",U,[o("div",Y,[t[9]||(t[9]=o("div",{class:"orderline-context-menu__field-label"},[o("span",null,"Price"),o("span",{class:"orderline-context-menu__required"},"*")],-1)),d(y,{value:x.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:ge.value,disabled:e.priceDisabled},class:"w-full",onHandleChange:ke},null,8,["value","other-props"])]),e.showStopLimitPrice?(r(),i("div",K,[t[10]||(t[10]=o("div",{class:"orderline-context-menu__field-label"},[o("span",null,"Stop Limit Price"),o("span",{class:"orderline-context-menu__required"},"*")],-1)),d(y,{value:k.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:ge.value},class:"w-full",onHandleChange:Pe},null,8,["value","other-props"])])):u("",!0),o("div",W,[t[11]||(t[11]=o("div",{class:"orderline-context-menu__field-label"},[o("span",null,"Volume"),o("span",{class:"orderline-context-menu__required"},"*")],-1)),d(y,{value:P.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:.01,disabled:e.volumeDisabled},class:"w-full",onHandleChange:Se},null,8,["value","other-props"])])]),e.marginText?(r(),i("p",X,s(e.marginText),1)):u("",!0),o("div",G,[o("span",{class:g(["orderline-context-menu__advanced-label",{"orderline-context-menu__advanced-label--active":e.advanced}])}," Advanced ",2),d(Be,{"model-value":e.advanced,size:"sm","onUpdate:modelValue":t[1]||(t[1]=e=>_("update:advanced",e))},null,8,["model-value"])]),e.advanced?(r(),i(f,{key:2},[o("div",J,[o("div",Q,[o("div",Z,[o("div",ee,[d(Ne,{"model-value":N.value,size:"sm",color:"success","onUpdate:modelValue":t[2]||(t[2]=e=>(e=>{if(N.value=e,e&&!de.value&&null!==ye.value){const e=ge.value,l="buy"===b.side?ye.value-20*e:ye.value+20*e;de.value=String(Number(l.toFixed(8)))}_e()})(Boolean(e)))},null,8,["model-value"]),t[12]||(t[12]=o("span",null,"Stop Loss",-1))]),t[13]||(t[13]=o("span",{class:"orderline-context-menu__required"},"*",-1))]),d(y,{value:pe.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:ge.value,disabled:!N.value},class:"w-full",onHandleChange:Ce},null,8,["value","other-props"]),be.value?(r(),i("span",le,s(be.value),1)):u("",!0)]),o("div",te,[o("div",ne,[o("div",re,[t[14]||(t[14]=o("span",null,"Take Profit",-1)),d(Ne,{"model-value":ce.value,size:"sm",color:"success","onUpdate:modelValue":t[3]||(t[3]=e=>(e=>{if(ce.value=e,e&&!ve.value&&null!==ye.value){const e=ge.value,l="buy"===b.side?ye.value+30*e:ye.value-30*e;ve.value=String(Number(l.toFixed(8)))}xe()})(Boolean(e)))},null,8,["model-value"])]),t[15]||(t[15]=o("span",{class:"orderline-context-menu__required"},"*",-1))]),d(y,{value:fe.value,placeholder:"0",controls:!0,size:"sm","other-props":{min:0,step:ge.value,disabled:!ce.value},class:"w-full",onHandleChange:we},null,8,["value","other-props"]),he.value?(r(),i("span",ie,s(he.value),1)):u("",!0)])]),o("div",ae,[o("div",oe,[t[16]||(t[16]=o("span",null,"Comment",-1)),o("span",se,s(me.value.length)+"/"+s(30),1)]),d(ze,{value:me.value,placeholder:"Add a comment",size:"sm","other-props":{maxlength:30},class:"w-full",onHandleChange:Le},null,8,["value","other-props"])])],64)):u("",!0),o("div",ue,[d(Me,{color:"contrast",plain:"",size:"sm",onClick:Te},{default:m(()=>[...t[17]||(t[17]=[p("Discard",-1)])]),_:1}),d(Me,{color:"primary",size:"sm",onClick:Ee},{default:m(()=>[...t[18]||(t[18]=[p("Confirm",-1)])]),_:1})])],32)}}}),[["__scopeId","data-v-2d8976ac"]]),ce=e=>e?{surfacePrimary:"#191D23",surfacePositive:"#16c784",surfaceNegative:"#ef4444",surfaceElevated:"#323A45",surfaceAction:"#A259FB",textPrimary:"#F0F1F3",textSecondary:"#B1B9C5",borderPrimary:"#323A45",borderPrimaryInverse:"#D8DCE2",borderAction:"#A259FB"}:{surfacePrimary:"white",surfacePositive:"#16c784",surfaceNegative:"#ef4444",surfaceElevated:"#d8dce2",surfaceAction:"#A259FB",textPrimary:"#0f1115",textSecondary:"#4b5768",borderPrimary:"#d8dce2",borderPrimaryInverse:"#323a45",borderAction:"#A259FB"},ve=(e="neutral",l="order",t,n)=>{const r=ce(t),i="position"===l;let a;return a="stop-loss"===n?r.surfaceNegative:"take-profit"===n?r.surfacePositive:i?r.borderAction:"buy"===e?r.surfacePositive:"sell"===e?r.surfaceNegative:r.borderAction,{lineColor:a,lineWidth:2,lineDash:[0,0],badgeBackgroundColor:r.surfacePrimary,badgeBorderColor:a,badgeTextColor:i?r.textPrimary:a,handleColor:a,handleBackgroundColor:i?r.surfacePrimary:"transparent",handleBorderColor:i?r.surfacePrimary:"transparent",deleteColor:i?r.textPrimary:a,deleteBackgroundColor:i?r.borderAction:r.surfacePrimary,deleteBorderColor:a,fontSize:12}},me=Symbol("EAERA_ORDERLINE_OVERLAY_CONTEXT_KEY"),pe=(e,r)=>{const i=l(null),a=l({}),o=t(()=>({draggingLineId:i.value,draftPrices:a.value}));n(o,e=>{r("stateChange",e)},{immediate:!0});const s={orderLines:t(()=>e.orderLines??[]),chartInstance:t(()=>e.chartInstance??null),seriesInstance:t(()=>e.seriesInstance??null),orderLineTool:t(()=>e.orderLineTool??null),renderKey:t(()=>e.renderKey??0),marketPrice:t(()=>e.marketPrice??null),tickSize:t(()=>e.tickSize??null),dark:t(()=>e.dark),state:o,onDeleteLine:e=>{r("deleteLine",e)},onLinePriceChange:(e,l)=>{r("linePriceChange",e,l)},onLinePricePreview:(e,l)=>{r("linePricePreview",e,l)},onDragStateChange:e=>{i.value=e,r("dragStateChange",e)},onDraftPricesChange:e=>{a.value=e},onSLTPChange:(e,l,t)=>{r("slTpChange",e,l,t)}};return y(me,s),s},fe=()=>{const e=b(me);if(!e)throw new Error("useEaeraOrderlineOverlay must be used inside EaeraOrderlineOverlay");return e},ge=["onMousedown","onDblclick"],ye=["onDblclick"],be=e({__name:"index",props:{orderLines:{},chartInstance:{},seriesInstance:{},orderLineTool:{},renderKey:{},marketPrice:{},tickSize:{},dark:{type:Boolean}},emits:["deleteLine","linePriceChange","linePricePreview","dragStateChange","slTpChange","stateChange"],setup(e,{expose:a,emit:d}){const m=pe(e,d),{orderLines:y,chartInstance:b,seriesInstance:S,orderLineTool:C,renderKey:w,marketPrice:L,tickSize:E,dark:T,state:B,onDeleteLine:N,onLinePriceChange:z,onLinePricePreview:M,onDragStateChange:D,onDraftPricesChange:I,onSLTPChange:A}=m,F=l(0),R=l(0),$=new Set,O=l(!1);let q=null,H=null,V=null;const j=l(null),U=l(null),Y=l({}),K=()=>b.value,W=()=>S.value,X=(e,l,t)=>Math.min(Math.max(e,l),t),G=(e,l,t)=>{const n=t.filter(e=>e>0),r={height:`${Math.max(l,1)}px`};if(n.length>=2){const[l,t]=n;return{...r,backgroundImage:`repeating-linear-gradient(to right, ${e} 0, ${e} ${l}px, transparent ${l}px, transparent ${l+t}px)`,backgroundSize:`${l+t}px 100%`}}return{...r,backgroundColor:e}},J=()=>{null!==H&&"undefined"!=typeof window&&(window.cancelAnimationFrame(H),H=null)},Q=()=>{R.value+=1,H=window.requestAnimationFrame(Q)},Z=()=>{"undefined"!=typeof window&&null===H&&0!==y.value.length&&(H=window.requestAnimationFrame(Q))},ee=()=>{q?.disconnect(),$.clear()},le=()=>{if("undefined"==typeof ResizeObserver)return;q||(q=new ResizeObserver(()=>{F.value+=1}));const e=K(),l=e?.chartElement(),t=[l,e&&"function"==typeof e.panes?e.panes()[0]?.getHTMLElement?.()??null:null].filter(e=>null!=e);t.length===$.size&&t.every(e=>$.has(e))||(ee(),t.forEach(e=>{q?.observe(e),$.add(e)}),F.value+=1)},te=e=>{const l=(e=>{const l=Number(e);if(!Number.isFinite(l)||l<=0)return 2;const t=l.toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:20}),n=(t.includes(".")?t.replace(/0+$/,"").replace(/\.$/,""):t).split(".")[1];return n?n.length:0})(E.value);return Number(e).toFixed(l)},ne=(e,l)=>{if(!Number.isFinite(l))return l;const t=Number(E.value)||1e-5;if("stop-loss"===e.lineRole&&void 0!==e.entryPrice)return"buy"===e.side?Math.min(l,e.entryPrice-t):Math.max(l,e.entryPrice+t);if("take-profit"===e.lineRole&&void 0!==e.entryPrice)return"buy"===e.side?Math.max(l,e.entryPrice+t):Math.min(l,e.entryPrice-t);const n=(e=>{if("number"==typeof e)return Number.isFinite(e)?e:null;if("string"==typeof e&&""!==e.trim()){const l=Number(e);return Number.isFinite(l)?l:null}return null})(L.value);return null===n?l:"buy"===e.side?Math.min(l,n):"sell"===e.side?Math.max(l,n):l},re=t(()=>{const e=w.value,l=F.value,t=R.value;return e<0||l<0||t<0?null:(()=>{const e=K(),l=j.value?.getBoundingClientRect();if(!e||!l)return null;const t=e.chartElement(),n=t.getBoundingClientRect(),r="function"==typeof e.panes?e.panes()[0]?.getHTMLElement?.()??null:null,i=r?.getBoundingClientRect(),a=e.paneSize?.(0),o=e.priceScale("left").width(),s=e.priceScale("right").width(),u=e.timeScale().height(),d=a?.width??Math.max(0,t.clientWidth-o-s),c=a?.height??Math.max(0,t.clientHeight-u);return{top:(i?i.top:n.top)-l.top,left:n.left-l.left+o,width:d,height:i?.height??c}})()}),ie=t(()=>{const e=re.value;return e?{top:`${e.top}px`,left:`${e.left}px`,width:`${e.width}px`,height:`${e.height}px`}:null}),ae=l(null),oe=l(null),se=new Set;let ue=!0;const me=e=>{const l=y.value.find(l=>l.id===e);l&&(be.value={x:0,y:0},oe.value=e,ae.value=(e=>{const{primary:l,quantity:t}=(e=>{const l=e.split("|").map(e=>e.trim());return{primary:l[0]??"",quantity:l[1]??"",price:l[2]??""}})(e.label),n=e.readonly&&"order"===e.type,r=l.replace(/^[+-]/,""),i=e.parentId??e.id,a=y.value.find(e=>e.parentId===i&&"stop-loss"===e.lineRole),o=y.value.find(e=>e.parentId===i&&"take-profit"===e.lineRole),s=y.value.find(e=>e.id===i),u=s?.price??e.entryPrice??e.price;return{title:n?"Market Order":"Order",statusTagText:t?`${l} ${t}`:l,price:e.price,side:"neutral"!==e.side?e.side:void 0,volume:r,advanced:n,entryPrice:u,initialStopLossEnabled:!!a,initialStopLoss:a?.price,initialTakeProfitEnabled:!!o,initialTakeProfit:o?.price}})(l))};n(()=>y.value,e=>{const l=new Set;for(const t of e)l.add(t.id);se.clear(),l.forEach(e=>se.add(e)),ue?ue=!1:oe.value&&!l.has(oe.value)&&(ae.value=null,oe.value=null)},{deep:!0});const fe=t(()=>!!oe.value&&(y.value.find(e=>e.id===oe.value)?.readonly??!1)),be=l({x:0,y:0}),he=l(!1),_e=t(()=>{const e=K(),l=j.value;return e&&l?{width:l.clientWidth,height:l.clientHeight}:null}),xe=t(()=>{if(!ae.value||!_e.value)return null;const{width:e,height:l}=_e.value,t=X(e-382-20+be.value.x,0,e-382);return{position:"absolute",top:`${X(20+be.value.y,0,l-460)}px`,left:`${t}px`}});let ke=0,Pe=0;const Se=e=>{if(!_e.value)return;e.target.closest('input, button, select, textarea, [role="switch"], [role="checkbox"]')||(he.value=!0,ke=e.clientX-be.value.x,Pe=e.clientY-be.value.y,document.body.style.userSelect="none",window.addEventListener("pointermove",Ce),window.addEventListener("pointerup",we))},Ce=e=>{be.value={x:e.clientX-ke,y:e.clientY-Pe}},we=()=>{he.value=!1,document.body.style.userSelect="",window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",we)},Le=e=>{const l=y.value.find(l=>l.id===e);return l?l.parentId??l.id:null},Ee=e=>{const l=Le(oe.value??"");if(!l)return;const t=y.value.find(e=>e.parentId===l&&"take-profit"===e.lineRole),n=t?.price??null,r=e.enabled&&void 0!==e.price?e.price:null;A(l,r,n)},Te=e=>{const l=Le(oe.value??"");if(!l)return;const t=y.value.find(e=>e.parentId===l&&"stop-loss"===e.lineRole),n=t?.price??null,r=e.enabled&&void 0!==e.price?e.price:null;A(l,n,r)},Be=e=>{ae.value=null,oe.value=null},Ne=()=>{ae.value=null,oe.value=null},ze=()=>{oe.value&&(N(oe.value),Ne())},Me=t(()=>"boolean"==typeof T.value?T.value:O.value),De=t(()=>{const e=w.value,l=R.value,t=W(),n=K(),r=re.value;return!t||!n||!r||e<0||l<0?[]:y.value.map(e=>{const l=(e=>Y.value[e.id]??e.price)(e),t=((e,l)=>{const t=W();if(!t)return null;const n=t.priceToCoordinate(e);if(null!==n)return n;const r=t.priceScale().getVisibleRange();if(!r)return null;const i=Math.min(r.from,r.to);return e>Math.max(r.from,r.to)?-1:e<i?l+1:null})(l,r.height);if(null===t)return null;const n=((e,l)=>e<0?"top":e>l?"bottom":"middle")(t,r.height),i=X(t,0,r.height),a=ce(Me.value),o={...ve(e.side,e.type,Me.value,e.lineRole),...e.options},[s,u,d]=((e,l)=>{const t=e.split("|").map(e=>e.trim()),n=te(l);return t.length>=3?(t[t.length-1]=n,t):2===t.length?[...t,n]:1===t.length?[t[0],"",n]:["","",n]})(e.label,l),c=a.textPrimary,[v]=[s],m={volume:v,pnl:u,price:d};return{...e,livePrice:l,edgePlacement:n,orderParts:{primary:v,quantity:u,price:d},positionParts:m,containerStyle:{top:`${i}px`},lineStyle:G(o.lineColor,o.lineWidth,o.lineDash),lineColor:o.lineColor,badgeWrapperStyle:{marginLeft:"12px"},badgeStyle:{borderColor:o.badgeBorderColor,backgroundColor:o.badgeBackgroundColor,color:o.badgeTextColor},middleStyle:{backgroundColor:o.badgeBackgroundColor,color:a.textPrimary},volumeStyle:{backgroundColor:"transparent",color:a.textPrimary},separatorStyle:{backgroundColor:a.borderPrimaryInverse},deleteStyle:{backgroundColor:o.deleteBackgroundColor,color:o.deleteColor,borderColor:o.deleteBorderColor},deleteButtonStyle:{color:o.deleteColor,borderColor:o.deleteBorderColor},priceStyle:{color:a.textPrimary},pnlStyle:{color:c},dragStyle:{backgroundColor:o.handleBackgroundColor,color:o.handleColor}}}).filter(e=>null!==e)}),Ie=()=>{const e=U.value;if(!e)return;const l=Y.value[e];if(U.value=null,D(null),document.body.style.userSelect="",window.removeEventListener("mousemove",Ae),window.removeEventListener("mouseup",Ie),"number"==typeof l){z(e,l);const{[e]:t,...n}=Y.value;Y.value=n,I(n)}},Ae=e=>{const l=U.value,t=W(),n=(()=>{const e=K();if(!e)return null;const l="function"==typeof e.panes?e.panes()[0]?.getHTMLElement?.()??null:null;return l?.getBoundingClientRect()??e.chartElement().getBoundingClientRect()})();if(!l||!t||!n)return;const r=e.clientY-n.top,i=t.coordinateToPrice(r);if("number"!=typeof i||Number.isNaN(i))return;const a=y.value.find(e=>e.id===l);if(!a)return;const o=ne(a,i),s=Number(te(o)),u={...Y.value,[l]:s};Y.value=u,I(u),M(l,s),((e,l)=>{const t=C.value?.orderLines.find(l=>l.localId===e);t?.updatePrice(l)})(l,s)},Fe=e=>{O.value=e.matches};return n(()=>w.value,()=>{le()},{immediate:!0}),n(()=>y.value.length,e=>{e>0?Z():J()},{immediate:!0}),_(()=>{le(),Z(),"undefined"!=typeof window&&"function"==typeof window.matchMedia&&(V=window.matchMedia("(prefers-color-scheme: dark)"),O.value=V.matches,V.addEventListener("change",Fe))}),x(()=>{window.removeEventListener("mousemove",Ae),window.removeEventListener("mouseup",Ie),window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",we),ee(),J(),V?.removeEventListener("change",Fe),V=null}),a({state:B,openMenu:e=>{be.value={x:0,y:0},oe.value=e.lineId??null,ae.value=e.menuData}}),(e,l)=>(r(),i("div",{ref_key:"overlayRootRef",ref:j,class:"custom-order-line-overlay"},[ie.value?(r(),i("div",{key:0,class:"custom-order-line-overlay__pane",style:k(ie.value)},[(r(!0),i(f,null,P(De.value,e=>(r(),i("div",{key:e.id,class:g(["custom-order-line-item",`custom-order-line-item--edge-${e.edgePlacement}`]),style:k(e.containerStyle)},["middle"===e.edgePlacement?(r(),i("div",{key:0,class:g(["custom-order-line-item__line",{"custom-order-line-item__line--draggable":"order"===e.type&&!e.readonly,"custom-order-line-item__line--clickable":e.readonly}]),style:k(e.lineStyle),onMousedown:l=>{return"order"!==e.type||e.readonly?void 0:(t=e.id,(n=l).preventDefault(),n.stopPropagation(),U.value=t,D(t),document.body.style.userSelect="none",window.addEventListener("mousemove",Ae),void window.addEventListener("mouseup",Ie));var t,n},onDblclick:l=>e.readonly?me(e.id):void 0},null,46,ge)):u("",!0),o("div",{class:g(["custom-order-line-item__label",{"custom-order-line-item__label--clickable":e.readonly}]),style:k({color:e.lineColor}),onDblclick:l=>e.readonly?me(e.id):void 0},[p(s(e.orderParts.primary)+" ",1),l[0]||(l[0]=o("span",{class:"custom-order-line-item__label-sep"},"·",-1)),p(" "+s(e.orderParts.quantity)+" ",1),l[1]||(l[1]=o("span",{class:"custom-order-line-item__label-sep"},"·",-1)),p(" "+s(e.orderParts.price),1)],46,ye)],6))),128))],4)):u("",!0),ae.value&&xe.value?(r(),v(de,{key:1,class:g(["custom-order-line-overlay__menu",{"custom-order-line-overlay__menu--dragging":he.value}]),style:k(xe.value),title:ae.value.title,"status-tag-text":ae.value.statusTagText,"reference-price":ae.value.entryPrice??ae.value.price,"tick-size":c(E),side:ae.value.side,advanced:ae.value.advanced,"initial-volume":ae.value.volume,"initial-stop-loss":ae.value.initialStopLoss,"initial-take-profit":ae.value.initialTakeProfit,"initial-stop-loss-enabled":ae.value.initialStopLossEnabled,"initial-take-profit-enabled":ae.value.initialTakeProfitEnabled,"price-disabled":fe.value,"volume-disabled":fe.value,onPointerdown:Se,onClose:Ne,onConfirm:Be,onDiscard:ze,"onUpdate:stopLoss":Ee,"onUpdate:takeProfit":Te},null,8,["class","style","title","status-tag-text","reference-price","tick-size","side","advanced","initial-volume","initial-stop-loss","initial-take-profit","initial-stop-loss-enabled","initial-take-profit-enabled","price-disabled","volume-disabled"])):u("",!0)],512))}});export{de as O,be as _,pe as p,fe as u};
|