lightweight-charts-drawing 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ (function(z,nt){typeof exports=="object"&&typeof module<"u"?nt(exports):typeof define=="function"&&define.amd?define(["exports"],nt):(z=typeof globalThis<"u"?globalThis:z||self,nt(z.LightweightChartsDrawing={}))})(this,(function(z){"use strict";var $a=Object.defineProperty;var Ia=(z,nt,Rt)=>nt in z?$a(z,nt,{enumerable:!0,configurable:!0,writable:!0,value:Rt}):z[nt]=Rt;var H=(z,nt,Rt)=>Ia(z,typeof nt!="symbol"?nt+"":nt,Rt);const nt={color:"#2962ff",width:1,lineStyle:"solid"};function Rt(e,t){if(!e||!t)return!0;const n=/^(\d+)([A-Z]+)?$/.exec(t.trim().toUpperCase());if(!n)return!0;const o=Math.max(1,parseInt(n[1],10)),i=(r,l)=>r.on&&l>=r.from&&l<=r.to;switch(n[2]){case"T":return e.ticks;case"R":return e.ranges;case"S":return i(e.seconds,o);case"D":return i(e.days,o);case"W":return i(e.weeks,o);case"M":return i(e.months,o);case void 0:return o%60===0?i(e.hours,o/60):o<60?i(e.minutes,o):i(e.hours,Math.round(o/60));default:return!0}}const j="#808080",lt="#f23645",ot="#ff9800",it="#4caf50",q="#089981",tt="#00bcd4",$="#2962ff",Gt="#9c27b0",ut="#e91e63",jt="#673ab7",Ft=[{coeff:0,color:j,visible:!0},{coeff:.236,color:lt,visible:!0},{coeff:.382,color:ot,visible:!0},{coeff:.5,color:it,visible:!0},{coeff:.618,color:q,visible:!0},{coeff:.786,color:tt,visible:!0},{coeff:1,color:j,visible:!0},{coeff:1.618,color:$,visible:!0},{coeff:2.618,color:lt,visible:!0},{coeff:3.618,color:Gt,visible:!0},{coeff:4.236,color:ut,visible:!0},{coeff:1.272,color:ot,visible:!1},{coeff:1.414,color:lt,visible:!1},{coeff:2.272,color:ot,visible:!1},{coeff:2.414,color:it,visible:!1},{coeff:2,color:q,visible:!1},{coeff:3,color:tt,visible:!1},{coeff:3.272,color:j,visible:!1},{coeff:3.414,color:$,visible:!1},{coeff:4,color:lt,visible:!1},{coeff:4.272,color:Gt,visible:!1},{coeff:4.414,color:ut,visible:!1},{coeff:4.618,color:ot,visible:!1},{coeff:4.764,color:q,visible:!1}],Mt=[{coeff:.25,color:"#ffb74d",visible:!1},{coeff:.382,color:"#81c784",visible:!1},{coeff:.5,color:q,visible:!0},{coeff:.618,color:q,visible:!1},{coeff:.75,color:tt,visible:!1},{coeff:1,color:$,visible:!0},{coeff:1.5,color:Gt,visible:!1},{coeff:1.75,color:ut,visible:!1},{coeff:2,color:"#f77c80",visible:!1}],Qe=[{coeff:1/8,color:ot,visible:!0,label:"1/8"},{coeff:1/4,color:q,visible:!0,label:"1/4"},{coeff:1/3,color:it,visible:!0,label:"1/3"},{coeff:1/2,color:q,visible:!0,label:"1/2"},{coeff:1,color:tt,visible:!0,label:"1/1"},{coeff:2,color:$,visible:!0,label:"2/1"},{coeff:3,color:Gt,visible:!0,label:"3/1"},{coeff:4,color:ut,visible:!0,label:"4/1"},{coeff:8,color:lt,visible:!0,label:"8/1"}],Je=[{coeff:.236,color:lt,visible:!0},{coeff:.382,color:ot,visible:!0},{coeff:.5,color:it,visible:!0},{coeff:.618,color:q,visible:!0},{coeff:.786,color:tt,visible:!0},{coeff:1,color:j,visible:!0},{coeff:1.618,color:$,visible:!1},{coeff:2.618,color:lt,visible:!1},{coeff:3.618,color:jt,visible:!1},{coeff:4.236,color:ut,visible:!1},{coeff:4.618,color:ut,visible:!1}],Te=[{coeff:0,color:j,visible:!0},{coeff:.25,color:ot,visible:!0},{coeff:.382,color:tt,visible:!0},{coeff:.5,color:it,visible:!0},{coeff:.618,color:q,visible:!0},{coeff:.75,color:$,visible:!0},{coeff:1,color:j,visible:!0}],tn=[{coeff:0,color:j,visible:!0,width:2,style:"solid"},{coeff:.382,color:lt,visible:!0,width:2,style:"solid"},{coeff:.5,color:"#81c784",visible:!1,width:2,style:"solid"},{coeff:.618,color:it,visible:!0,width:2,style:"solid"},{coeff:1,color:q,visible:!0,width:2,style:"solid"},{coeff:1.382,color:tt,visible:!0,width:2,style:"solid"},{coeff:1.618,color:j,visible:!0,width:2,style:"solid"},{coeff:2,color:$,visible:!0,width:2,style:"solid"},{coeff:2.382,color:ut,visible:!0,width:2,style:"solid"},{coeff:2.618,color:Gt,visible:!0,width:2,style:"solid"},{coeff:3,color:"#673ab7",visible:!0,width:2,style:"solid"}],en={visible:!0,color:j,width:2,style:"dashed"},dr=en,xr={visible:!0,color:j,width:2,style:"solid"},qt=(e,t)=>({color:e,width:2,visible:t}),X=(e,t,n,o)=>({color:e,width:2,visible:t,x:n,y:o}),nn=[qt(j,!0),qt(ot,!0),qt(tt,!0),qt(it,!0),qt(q,!0),qt(j,!0)],on=[X("#b39ddb",!1,8,1),X(lt,!1,5,1),X(j,!1,4,1),X(ot,!1,3,1),X(tt,!0,2,1),X(it,!0,1,1),X(q,!0,1,2),X(q,!1,1,3),X($,!1,1,4),X("#9575cd",!1,1,5),X("#b39ddb",!1,1,8)],rn=[X(ot,!0,1,0),X(ot,!0,1,1),X(ot,!0,1.5,0),X(tt,!0,2,0),X(tt,!0,2,1),X(it,!0,3,0),X(it,!0,3,1),X(q,!0,4,0),X(q,!0,4,1),X($,!0,5,0),X($,!0,5,1)],qn={visible:!0,color:"rgba(21, 56, 153, 0.8)",width:1,style:"solid"},ln=[{coeff:0,color:j,visible:!0},{coeff:1,color:$,visible:!0},{coeff:2,color:$,visible:!0},{coeff:3,color:$,visible:!0},{coeff:5,color:$,visible:!0},{coeff:8,color:$,visible:!0},{coeff:13,color:$,visible:!0},{coeff:21,color:$,visible:!0},{coeff:34,color:$,visible:!0},{coeff:55,color:$,visible:!0},{coeff:89,color:$,visible:!0}],sn=[{coeff:1,color:it,visible:!0},{coeff:2,color:"#808000",visible:!1},{coeff:3,color:"#00897b",visible:!1}],Zn=[{visible:!0,color:it,width:1,style:"solid"},{visible:!0,color:"#808000",width:1,style:"solid"},{visible:!0,color:"#00897b",width:1,style:"solid"}],cn=[{coeff:.236,color:lt,visible:!0},{coeff:.382,color:ot,visible:!0},{coeff:.5,color:q,visible:!0},{coeff:.618,color:it,visible:!0},{coeff:.786,color:tt,visible:!0},{coeff:1,color:j,visible:!0},{coeff:1.618,color:$,visible:!0},{coeff:2.618,color:ut,visible:!0},{coeff:3.618,color:$,visible:!0},{coeff:4.236,color:ut,visible:!0},{coeff:4.618,color:lt,visible:!0}],an=[{coeff:.236,color:lt,visible:!0},{coeff:.382,color:ot,visible:!0},{coeff:.5,color:q,visible:!0},{coeff:.618,color:it,visible:!0},{coeff:.786,color:tt,visible:!0},{coeff:1,color:j,visible:!0},{coeff:1.618,color:$,visible:!0},{coeff:2.618,color:ut,visible:!0},{coeff:3.618,color:$,visible:!0},{coeff:4.236,color:ut,visible:!0},{coeff:4.618,color:lt,visible:!0}],Ae=[{coeff:0,color:j,visible:!0},{coeff:.25,color:ot,visible:!0},{coeff:.382,color:tt,visible:!0},{coeff:.5,color:it,visible:!0},{coeff:.618,color:q,visible:!0},{coeff:.75,color:$,visible:!0},{coeff:1,color:j,visible:!0}],yr=7,pr={upColor:"#ACE5DC",downColor:"#FAA1A4",drawBorder:!0,borderUpColor:"#089981",borderDownColor:"#F23645",drawWick:!0,wickColor:"#808080"},Kn={base:{visible:!0,color:lt,width:1,style:"dashed"},up:{visible:!0,color:$,width:2,style:"solid"},down:{visible:!0,color:$,width:2,style:"solid"}},$e=[-.25,0,.25,.5,.75,1,1.25].map((e,t)=>({coeff:e,color:$,visible:t===1||t===3||t===5,width:t===1||t===5?2:1,style:t===3?"dashed":"solid"})),br=Mt.map(e=>e.coeff===.5?{...e,color:tt}:e),se={"horizontal-line":{kind:"horizontal-line",pointCount:1,preview:"none",isBbox:!1,hotkey:"Alt + H",defaults:{width:2,textColor:"#2962ff",showPriceLabels:!0}},"horizontal-ray":{kind:"horizontal-ray",pointCount:1,preview:"none",isBbox:!1,hotkey:"Alt + J",defaults:{width:2,showPriceLabels:!0}},"vertical-line":{kind:"vertical-line",pointCount:1,preview:"none",isBbox:!1,hotkey:"Alt + V",defaults:{width:2,textColor:"#2962ff",showTime:!0}},"cross-line":{kind:"cross-line",pointCount:1,preview:"none",isBbox:!1,hotkey:"Alt + C",defaults:{width:2,textColor:"#ffffff",showPriceLabels:!0,showTime:!0}},"arrow-marker":{kind:"arrow-marker",pointCount:2,preview:"line",isBbox:!1,defaults:{color:"#1e53e5",width:2,textColor:"#1e53e5",fontSize:16,bold:!0}},"arrow-mark-up":{kind:"arrow-mark-up",pointCount:1,preview:"none",isBbox:!1,defaults:{color:"#089981",fontSize:14}},"arrow-mark-down":{kind:"arrow-mark-down",pointCount:1,preview:"none",isBbox:!1,defaults:{color:"#cc2f3c",fontSize:14}},"price-label":{kind:"price-label",pointCount:1,preview:"none",isBbox:!1,defaults:{color:$,textColor:"#ffffff",fontSize:14,backgroundColor:$,borderColor:$,transparency:0}},"flag-mark":{kind:"flag-mark",pointCount:1,preview:"none",isBbox:!1,defaults:{color:"#2962ff"}},"trend-line":{kind:"trend-line",pointCount:2,preview:"line",isBbox:!1,hotkey:"Alt + T",defaults:{width:2,textColor:"#2962ff",fontSize:14,horzLabelsAlign:"center",vertLabelsAlign:"bottom"}},ray:{kind:"ray",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,textColor:"#2962ff",fontSize:14,horzLabelsAlign:"center",vertLabelsAlign:"bottom",extendRight:!0}},"extended-line":{kind:"extended-line",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,textColor:"#2962ff",fontSize:14,horzLabelsAlign:"center",vertLabelsAlign:"bottom",extendLeft:!0,extendRight:!0}},"info-line":{kind:"info-line",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,textColor:"#2962ff",fontSize:14,horzLabelsAlign:"center",vertLabelsAlign:"bottom",showStats:!0,showPriceRange:!0,showPercentPriceRange:!0,showPipsPriceRange:!0,showBarsRange:!0,showDateTimeRange:!0,showDistance:!0,showAngle:!0}},"trend-angle":{kind:"trend-angle",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,fontSize:12}},"long-position":{kind:"long-position",pointCount:1,preview:"none",isBbox:!1,defaults:{color:j,width:1,textColor:"#ffffff",fontSize:12,stopColor:"#f23645",stopTransparency:80,targetColor:"#089981",targetTransparency:80,showPriceLabels:!0,accountSize:1e3,riskPercent:25,lotSize:1,riskDisplayMode:"percents",leverage:1e4,qtyPrecision:"default"}},"short-position":{kind:"short-position",pointCount:1,preview:"none",isBbox:!1,defaults:{color:j,width:1,textColor:"#ffffff",fontSize:12,stopColor:"#f23645",stopTransparency:80,targetColor:"#089981",targetTransparency:80,showPriceLabels:!0,accountSize:1e3,riskPercent:25,lotSize:1,riskDisplayMode:"percents",leverage:1e4,qtyPrecision:"default"}},"gann-fan":{kind:"gann-fan",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,levels:Qe,fillBackground:!0,transparency:80}},"gann-box":{kind:"gann-box",pointCount:2,preview:"rect",isBbox:!0,defaults:{color:"rgba(21, 56, 153, 0.8)",width:2,lineStyle:"solid",levels:Ae,vLevels:Ae,showLeftLabels:!0,showRightLabels:!0,showTopLabels:!0,showBottomLabels:!0,fillBackground:!0,transparency:80,fillVertBackground:!0,vertTransparency:80,fans:{visible:!1,color:"#9C9C9C"},reverse:!1}},"fib-time-zone":{kind:"fib-time-zone",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,levels:ln,fillBackground:!1,transparency:80,showLabels:!0,horzLabelsAlign:"right",vertLabelsAlign:"bottom"}},"fib-circles":{kind:"fib-circles",pointCount:2,preview:"line",isBbox:!1,defaults:{color:j,width:2,levels:an,fillBackground:!0,transparency:80}},"fib-speed-resistance-fan":{kind:"fib-speed-resistance-fan",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,levels:Te,vLevels:Te,fillBackground:!0,transparency:80,showLeftLabels:!0,showRightLabels:!0,showTopLabels:!0,showBottomLabels:!0,reverse:!1,fanGrid:qn}},"fib-speed-resistance-arcs":{kind:"fib-speed-resistance-arcs",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,levels:cn,fillBackground:!0,transparency:80}},"fib-spiral":{kind:"fib-spiral",pointCount:2,preview:"line",isBbox:!1,defaults:{color:tt,width:2}},"trend-based-fib-time":{kind:"trend-based-fib-time",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:tn,fibTrendLine:en,fillBackground:!0,transparency:80,showLabels:!0,horzLabelsAlign:"right",vertLabelsAlign:"bottom"}},"gann-square-fixed":{kind:"gann-square-fixed",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,gannLevels:nn,gannFans:on,gannArcs:rn,fillBackground:!0,transparency:80,reverse:!1}},"gann-square":{kind:"gann-square",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,gannLevels:nn,gannFans:on,gannArcs:rn,fillBackground:!0,transparency:80,reverse:!1,showLabels:!0,labelFontSize:12}},sector:{kind:"sector",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#9c9c9c",width:2,fillBackground:!0,transparency:80,sectorColor1:$,sectorColor2:Gt}},"fib-wedge":{kind:"fib-wedge",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:Je,fillBackground:!0,transparency:80}},pitchfan:{kind:"pitchfan",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:br,fillBackground:!0,transparency:80}},"cyclic-lines":{kind:"cyclic-lines",pointCount:2,preview:"line",isBbox:!1,defaults:{color:"#80ccdb",width:2}},"sine-line":{kind:"sine-line",pointCount:2,preview:"line",isBbox:!1,defaults:{color:"#159980",width:2}},"time-cycles":{kind:"time-cycles",pointCount:2,preview:"line",isBbox:!1,defaults:{color:"#159980",width:2,fillBackground:!0,backgroundColor:"#6aa84f",transparency:50}},"fib-retracement":{kind:"fib-retracement",pointCount:2,preview:"line",isBbox:!1,hotkey:"Alt + F",defaults:{width:2,levels:Ft,fillBackground:!0,transparency:80}},arrow:{kind:"arrow",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,textColor:$,fontSize:14,horzLabelsAlign:"center",vertLabelsAlign:"bottom",leftEnd:0,rightEnd:1}},rectangle:{kind:"rectangle",pointCount:2,preview:"rect",isBbox:!0,hotkey:"Alt + Shift + R",defaults:{color:"#9c27b0",width:2,fillBackground:!0,backgroundColor:"#9c27b0",transparency:50,rectMiddleLine:{visible:!1,color:"#9c27b0",width:1,style:"dashed"}}},circle:{kind:"circle",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,color:"#ff9800",fillBackground:!0,backgroundColor:"#ff9800",transparency:80}},ellipse:{kind:"ellipse",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,color:"#f23645",fillBackground:!0,backgroundColor:"#f23645",transparency:50}},"price-range":{kind:"price-range",pointCount:2,preview:"rect",isBbox:!1,defaults:{width:2,color:$,fillBackground:!0,backgroundColor:$,transparency:85,textColor:"#ffffff",fontSize:12,customTextColor:$,customTextSize:12}},"date-range":{kind:"date-range",pointCount:2,preview:"rect",isBbox:!1,defaults:{width:2,color:$,fillBackground:!0,backgroundColor:$,transparency:85,textColor:"#ffffff",fontSize:12,customTextColor:$,customTextSize:12}},"date-and-price-range":{kind:"date-and-price-range",pointCount:2,preview:"rect",isBbox:!1,defaults:{width:2,color:$,fillBackground:!0,backgroundColor:$,transparency:85,textColor:"#ffffff",fontSize:12,customTextColor:$,customTextSize:12}},"position-forecast":{kind:"position-forecast",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,color:"#2962FF",transparency:10,sourceTextColor:"#ffffff",sourceBackColor:"#2962FF",sourceStrokeColor:"#2962FF",targetTextColor:"#ffffff",targetBackColor:"#2962FF",targetStrokeColor:"#2962FF",successTextColor:"#ffffff",successBackground:"#4caf50",failureTextColor:"#ffffff",failureBackground:"#F23645"}},"bar-pattern":{kind:"bar-pattern",pointCount:2,preview:"rect",isBbox:!0},"ghost-feed":{kind:"ghost-feed",pointCount:2,preview:"line",isBbox:!1,variableLength:!0,defaults:{variance:50,transparency:50}},triangle:{kind:"triangle",pointCount:3,preview:"none",isBbox:!1,defaults:{width:2,color:"#089981",fillBackground:!0,backgroundColor:"#089981",transparency:80}},"parallel-channel":{kind:"parallel-channel",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:$e,fillBackground:!0,transparency:80,textColor:$,fontSize:14,horzLabelsAlign:"left",vertLabelsAlign:"bottom"}},pitchfork:{kind:"pitchfork",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Mt,fillBackground:!0,transparency:80}},"trend-based-fib-extension":{kind:"trend-based-fib-extension",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:Ft,fillBackground:!0,transparency:80}},"disjoint-channel":{kind:"disjoint-channel",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#089981",width:2,fillBackground:!0,backgroundColor:"#089981",transparency:80,textColor:"#089981",fontSize:14,horzLabelsAlign:"left",vertLabelsAlign:"bottom",showPrices:!1,priceLabelTextColor:"#089981",priceLabelFontSize:12,leftEnd:0,rightEnd:0}},"flat-top-bottom":{kind:"flat-top-bottom",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#ff9800",width:2,fillBackground:!0,backgroundColor:"#ff9800",transparency:80,textColor:"#ff9800",fontSize:14,horzLabelsAlign:"left",vertLabelsAlign:"bottom",showPrices:!1,priceLabelTextColor:"#ff9800",priceLabelFontSize:12,leftEnd:0,rightEnd:0}},"schiff-pitchfork":{kind:"schiff-pitchfork",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Mt,fillBackground:!0,transparency:80}},"modified-schiff-pitchfork":{kind:"modified-schiff-pitchfork",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Mt,fillBackground:!0,transparency:80}},"inside-pitchfork":{kind:"inside-pitchfork",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Mt,fillBackground:!0,transparency:80}},"fib-channel":{kind:"fib-channel",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:Ft,fillBackground:!0,transparency:80,showPrices:!0,showCoeffs:!0,fibLevelsAsPercents:!1,labelFontSize:12,horzLabelsAlign:"left",vertLabelsAlign:"middle"}},"rotated-rectangle":{kind:"rotated-rectangle",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#4caf50",width:2,fillBackground:!0,backgroundColor:"#4caf50",transparency:50}},curve:{kind:"curve",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,fillBackground:!1,backgroundColor:"#2962ff",transparency:50}},arc:{kind:"arc",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,color:"#e91e63",fillBackground:!0,backgroundColor:"#e91e63",transparency:80}},"double-curve":{kind:"double-curve",pointCount:2,preview:"line",isBbox:!1,defaults:{color:jt,width:2,fillBackground:!1,backgroundColor:jt,transparency:80}},"abcd-pattern":{kind:"abcd-pattern",pointCount:4,preview:"line",isBbox:!1,defaults:{color:q,width:2,textColor:"#ffffff",fontSize:12}},"xabcd-pattern":{kind:"xabcd-pattern",pointCount:5,preview:"line",isBbox:!1,defaults:{color:$,width:2,textColor:"#ffffff",backgroundColor:$,fillBackground:!0,transparency:85,fontSize:12}},"cypher-pattern":{kind:"cypher-pattern",pointCount:5,preview:"line",isBbox:!1,defaults:{color:$,width:2,textColor:"#ffffff",backgroundColor:$,fillBackground:!0,transparency:85,fontSize:12}},"head-and-shoulders":{kind:"head-and-shoulders",pointCount:7,preview:"line",isBbox:!1,defaults:{color:q,width:2,textColor:"#ffffff",fontSize:12,fillBackground:!0,backgroundColor:q,transparency:85}},"triangle-pattern":{kind:"triangle-pattern",pointCount:4,preview:"line",isBbox:!1,defaults:{color:jt,width:2,textColor:"#ffffff",fontSize:12,fillBackground:!0,backgroundColor:jt,transparency:85}},"three-drives-pattern":{kind:"three-drives-pattern",pointCount:7,preview:"line",isBbox:!1,defaults:{color:jt,width:2,textColor:"#ffffff",fontSize:12}},"elliott-impulse":{kind:"elliott-impulse",pointCount:6,preview:"line",isBbox:!1,defaults:{color:"#3d85c6",width:2}},"elliott-correction":{kind:"elliott-correction",pointCount:4,preview:"line",isBbox:!1,defaults:{color:"#3d85c6",width:2}},"elliott-triangle":{kind:"elliott-triangle",pointCount:6,preview:"line",isBbox:!1,defaults:{color:ot,width:2}},"elliott-double-combo":{kind:"elliott-double-combo",pointCount:4,preview:"line",isBbox:!1,defaults:{color:"#6aa84f",width:2}},"elliott-triple-combo":{kind:"elliott-triple-combo",pointCount:6,preview:"line",isBbox:!1,defaults:{color:"#6aa84f",width:2}},polyline:{kind:"polyline",pointCount:2,preview:"line",isBbox:!1,variableLength:!0,defaults:{color:tt,width:2,fillBackground:!0,transparency:80}},path:{kind:"path",pointCount:2,preview:"line",isBbox:!1,variableLength:!0,defaults:{width:2,leftEnd:0,rightEnd:1}},brush:{kind:"brush",pointCount:2,preview:"line",isBbox:!1,freehand:!0,defaults:{color:tt,width:2,fillBackground:!1,backgroundColor:tt,transparency:80,leftEnd:0,rightEnd:0}},highlighter:{kind:"highlighter",pointCount:2,preview:"line",isBbox:!1,freehand:!0,defaults:{color:"#f23645",width:20}},text:{kind:"text",pointCount:1,preview:"none",isBbox:!1,textEditable:!0,defaults:{color:$,fontSize:14,fillBackground:!1,backgroundColor:$,transparency:75,drawBorder:!1,borderColor:"#707070",wordWrap:!1,wordWrapWidth:200}},note:{kind:"note",pointCount:2,preview:"line",isBbox:!1,textEditable:!0,defaults:{color:"#dbdbdb",textColor:"#dbdbdb",backgroundColor:"#2e2e2e",fillBackground:!0,fontSize:14}},pin:{kind:"pin",pointCount:1,preview:"none",isBbox:!1,textEditable:!0,defaults:{color:"#2962ff",textColor:"#dbdbdb",fontSize:14,fillBackground:!0,backgroundColor:"#2e2e2e",transparency:0,drawBorder:!1,borderColor:"#4a4a4a"}},comment:{kind:"comment",pointCount:1,preview:"none",isBbox:!1,textEditable:!0,defaults:{color:$,textColor:"#ffffff",fontSize:16,backgroundColor:$,borderColor:$,transparency:0}},"price-note":{kind:"price-note",pointCount:2,preview:"line",isBbox:!1,textEditable:!0,defaults:{color:$,textColor:$,fontSize:14,horzLabelsAlign:"center",vertLabelsAlign:"bottom",priceLabelTextColor:"#ffffff",priceLabelFontSize:12,priceLabelBackgroundColor:$,priceLabelBorderColor:$}},signpost:{kind:"signpost",pointCount:1,preview:"none",isBbox:!1,textEditable:!0,defaults:{fontSize:12,showImage:!1,plateColor:$,signpostPosition:50}},callout:{kind:"callout",pointCount:2,preview:"line",isBbox:!1,textEditable:!0,defaults:{color:"#0097a7",width:2,textColor:"#ffffff",fontSize:14,backgroundColor:"#0097a7",transparency:50,wordWrap:!1,wordWrapWidth:200}},"font-icon":{kind:"font-icon",pointCount:1,preview:"none",isBbox:!1,defaults:{fontSize:72,color:$}},table:{kind:"table",pointCount:1,preview:"none",isBbox:!1,defaults:{color:"#575757",backgroundColor:"#0f0f0f",textColor:"#dbdbdb",fontSize:14,horzLabelsAlign:"left"}},image:{kind:"image",pointCount:1,preview:"none",isBbox:!1,defaults:{transparency:0}},"regression-trend":{kind:"regression-trend",pointCount:2,preview:"line",isBbox:!1,defaults:{upperDeviation:2,lowerDeviation:-2,useUpperDeviation:!0,useLowerDeviation:!0,regressionSource:"close",showPearsons:!0,fillBackground:!0,transparency:70,regressionLines:Kn}},"anchored-vwap":{kind:"anchored-vwap",pointCount:1,preview:"none",isBbox:!1,defaults:{color:"#1e88e5",width:1,vwapSource:"hlc3",levels:sn,fillBackground:!0,backgroundColor:"#4caf50",transparency:95}},"fixed-range-volume-profile":{kind:"fixed-range-volume-profile",pointCount:2,preview:"rect",isBbox:!0},"anchored-volume-profile":{kind:"anchored-volume-profile",pointCount:1,preview:"none",isBbox:!1}},gr=new Set(Object.keys(se));function Ie(e){if(e&&gr.has(e))return se[e]}function Ot(e){const t={...nt,...se[e].defaults,...Qn(e)};return t.levels&&(t.levels=t.levels.map(n=>({...n}))),t}function mr(e){const t={...nt,...se[e].defaults};return t.levels&&(t.levels=t.levels.map(n=>({...n}))),t}let Qn=()=>{};function wr(e){Qn=e}const et=6,L=6,Jn=9;function P(e){if(e.lineStyle==="dashed")return"6 4";if(e.lineStyle==="dotted")return"2 3"}function Be(e){return Math.max(L,((e==null?void 0:e.width)??1)/2+2)}function ce(e){if(e.fillBackground===!1)return{fill:"none",fillOpacity:0};const t=e.backgroundColor||e.color,n=e.transparency!=null?Math.max(0,Math.min(1,(100-e.transparency)/100)):.08;return{fill:t,fillOpacity:n}}function _(e,t,n,o){const i=o.x-n.x,r=o.y-n.y,l=i*i+r*r;if(l===0)return Math.hypot(e-n.x,t-n.y);let s=((e-n.x)*i+(t-n.y)*r)/l;return s=Math.max(0,Math.min(1,s)),Math.hypot(e-(n.x+s*i),t-(n.y+s*r))}function Zt(e,t,n){let o=!1;for(let i=0,r=n.length-1;i<n.length;r=i++){const l=n[i].x,s=n[i].y,a=n[r].x,c=n[r].y;s>t!=c>t&&e<(a-l)*(t-s)/(c-s||1e-9)+l&&(o=!o)}return o}function At(e,t){const n=Math.min(e.x,t.x),o=Math.max(e.x,t.x),i=Math.min(e.y,t.y),r=Math.max(e.y,t.y);return[{x:n,y:i},{x:o,y:i},{x:o,y:r},{x:n,y:r}]}function N(e){if(typeof e=="number")return e;if(typeof e=="string"){const t=Date.parse(e);return Number.isFinite(t)?t/1e3:null}return typeof e=="object"&&e!==null&&"year"in e?Date.UTC(e.year,e.month-1,e.day)/1e3:null}function Mr(e,t){const n=e[0];return Math.hypot(n.x-t.x,n.y-t.y)<=et+L?{hit:"handle",handleIndex:0}:Math.abs(t.x-n.x)<=Jn+L&&Math.abs(t.y-n.y)<=Jn+L?{hit:"body"}:null}function to(e,t){const[n,o,i]=e,r=o.x-n.x,l=o.y-n.y,s=Math.hypot(r,l)||1,a=l/s,c=-r/s;if(t){const h=i?Math.abs((i.x-n.x)*a+(i.y-n.y)*c):0;return[{x:n.x+a*h,y:n.y+c*h},{x:o.x+a*h,y:o.y+c*h},{x:o.x-a*h,y:o.y-c*h},{x:n.x-a*h,y:n.y-c*h}]}const f=i?(i.x-o.x)*-a+(i.y-o.y)*-c:0;return[n,o,{x:o.x-a*f,y:o.y-c*f},{x:n.x-a*f,y:n.y-c*f}]}const kr=[["tpPriceOffset","TP price offset",!0],["tpPercentOffset","TP percent offset",!0],["tpTickOffset","TP tick offset",!0],["tpAmount","TP amount",!0],["tpPL","TP PL",!1],["openClosePL","Open/closed PL",!0],["qty","Qty",!0],["riskRewardRatio","Risk/reward ratio",!0],["slPriceOffset","SL price offset",!0],["slPercentOffset","SL percent offset",!0],["slTickOffset","SL tick offset",!0],["slAmount","SL amount",!0],["slPL","SL PL",!1]];function Ee(e,t){var o;return((o=e.positionStats)==null?void 0:o[t])??kr.find(i=>i[0]===t)[2]}function Pe(e,t){const n=Math.abs(e).toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t});return e<0?`−${n}`:n}function eo(e,t,n,o,i,r,l,s){const a=d=>Ee(e,t+d),c=!!e.compactStats,f=Pe(n,r),h=`${(o!==0?Math.round(100*1e3*n/o)/1e3:0).toFixed(3)}%`;let u="";return a("PriceOffset")&&(u+=c?f:`${t==="tp"?"Target":"Stop"}: ${f}`),a("PercentOffset")&&(u+=u!==""?` (${h})`:h),a("TickOffset")&&(u+=(u!==""?" ":"")+Pe(Math.round(n/i),0)),a("Amount")&&(u+=c?(u!==""?" ":"")+String(l):(u!==""?", ":"")+`Amount: ${l}`),a("PL")&&(u+=c?(u!==""?" ":"")+Pe(s,r):(u!==""?", ":"")+`PnL: ${Pe(s,r)}`),u}function vr(e,t,n,o,i){const r=!!e.compactStats;let l="";return Ee(e,"openClosePL")&&t&&(l+=r?t:`${n?"Closed":"Open"} PnL: ${t}`),Ee(e,"qty")&&(l+=(l!==""?r?" ~ ":", ":"")+(r?String(o):`Qty: ${o}`)),Ee(e,"riskRewardRatio")&&(l+=(l!==""?`
2
+ `:"")+(r?String(i):`Risk/reward ratio: ${i}`)),l}const ae={accountSize:1e3,risk:25,leverage:1e4};function fn(e,t){const n=e.points[0],o=e.points[1],i=n&&o?Math.abs(o.price-n.price):0;return{stop:e.style.stopLevel??(i||t*100),profit:e.style.profitLevel??(i||t*100)}}function Lr(e){const t=e.accountSize??ae.accountSize;return e.riskDisplayMode==="money"?Math.min(e.riskAmount??t*(e.riskPercent??ae.risk)/100,t):(e.riskPercent??ae.risk)/100*t}function Sr(e,t){if(!t||t==="default")return Math.floor(e);const n=Math.pow(10,parseInt(t,10));return Math.round(e*n)/n}function Cr(e,t,n){const o=e.accountSize??ae.accountSize,i=e.leverage??ae.leverage,r=n>0?Lr(e)/n:1/0,l=t>0?i*o/t:1/0,s=Math.min(r,l),a=Number.isFinite(s)?s:0,c=e.lotSize&&e.lotSize>0?e.lotSize:1;return{qty:a,shown:Sr(a/c,e.qtyPrecision)}}function no(e,t,n){if(e.kind!=="long-position"&&e.kind!=="short-position")return null;const[o,i]=t,r=e.points[0].price,{stop:l,profit:s}=fn(e,(n==null?void 0:n.pipSize())??.01),a=e.kind==="long-position"?1:-1,c=(n==null?void 0:n.priceToY(r+a*s))??o.y-40,f=(n==null?void 0:n.priceToY(r-a*l))??o.y+40;return c==null||f==null?null:{anchors:[o,{x:i.x,y:o.y},{x:o.x,y:f},{x:o.x,y:c}],yStop:f,yTarget:c,stop:l,profit:s}}function Tr(e,t,n,o,i){if(!i||e.points.length<2)return null;const r=i.bars();if(r.length===0)return null;const l=r.length-1,s=i.timeToBarIndex(e.points[0].time),a=e.points[1];if(!a)return null;const c=i.timeToBarIndex(a.time);if(s==null||c==null||c<0)return null;const f=e.points[0].price,h=Math.min(l,c-1);let u=null;for(let y=Math.max(s,0);y<=h;y++)if(r[y].high>=f&&r[y].low<=f){u=y;break}let d=null,x=null;if(u!=null)for(let y=u;y<=h;y++){const b=r[y];if(t==="long"?b.low<=n?x=n:b.high>=o&&(x=o):b.high>=n?x=n:b.low<=o&&(x=o),x!=null){d=y;break}}if(d!=null&&x!=null)return{entryIndex:u,closeIndex:d,closed:!0,closePrice:x,barIndex:Math.min(l,d)};const p=Math.min(l,c);return{entryIndex:u,closeIndex:null,closed:!1,closePrice:r[p].close,barIndex:p}}function oo(e,t){const[n,o]=t;if(!n||!o)return null;if(e.kind==="gann-square-fixed"){const l=o.x-n.x,s=o.y-n.y,a=Math.hypot(l,s);if(a<1e-9)return null;const c={x:n.x+5*a*(l<0?-1:1),y:n.y+5*a*(s<0?-1:1)};return{start:n,end:c,dx:c.x-n.x,dy:c.y-n.y}}const[i,r]=e.style.reverse?[o,n]:[n,o];return{start:i,end:r,dx:r.x-i.x,dy:r.y-i.y}}function Ar(e,t){return t.map((n,o)=>({l:n,t:o/5})).filter(n=>n.l.visible).map(({l:n,t:o})=>({color:n.color,width:n.width,x:e.start.x+o*e.dx,y:e.start.y+o*e.dy}))}function $r(e,t){return t.filter(n=>n.visible).map(n=>{const o=n.x>n.y?{x:e.end.x,y:e.start.y+n.y/n.x*e.dy}:{x:e.start.x+n.x/n.y*e.dx,y:e.end.y};return{color:n.color,width:n.width,from:e.start,to:o}})}function Ir(e,t){const n=e.dx!==0?e.dy/e.dx:0,o=(l,s)=>n!==0?Math.hypot(l,s/n):Math.abs(l);let i=0;const r=[];for(const l of t){if(!l.visible)continue;const s=o(l.x/5*e.dx,l.y/5*e.dy);r.push({color:l.color,width:l.width,r:s,prev:i}),i=s}return r}function Br(e,t,n){const o=e.dx<0?-1:1,i=e.dy<0?-1:1,r=e.dx!==0?Math.abs(e.dy/e.dx):1,l=o*i>0?1:0,{x:s,y:a}=e.start,c=`M ${s+o*t} ${a} A ${t} ${t*r} 0 0 ${l} ${s} ${a+i*t*r}`,f=n>0?`L ${s} ${a+i*n*r} A ${n} ${n*r} 0 0 ${1-l} ${s+o*n} ${a}`:`L ${s} ${a}`,h=`M ${s+o*n} ${a} L ${s+o*t} ${a} A ${t} ${t*r} 0 0 ${l} ${s} ${a+i*t*r} ${f} Z`;return{stroke:c,fill:h}}function io(e){return{left:Math.min(e.start.x,e.end.x),top:Math.min(e.start.y,e.end.y),right:Math.max(e.start.x,e.end.x),bottom:Math.max(e.start.y,e.end.y)}}function ro(e,t,n){const o=t.x-e.x||1,i=t.y-e.y;return{x:o*n,y:i}}function lo(e,t){const[n,o,i]=t,r={x:(o.x+i.x)/2,y:(o.y+i.y)/2},l={x:(i.x-o.x)/2,y:(i.y-o.y)/2};let s=n,a;if(e==="schiff-pitchfork")s={x:n.x,y:(n.y+o.y)/2},a={x:r.x-s.x,y:r.y-s.y};else if(e==="modified-schiff-pitchfork")s={x:(n.x+o.x)/2,y:(n.y+o.y)/2},a={x:r.x-s.x,y:r.y-s.y};else if(e==="inside-pitchfork"){const c={x:(n.x+o.x)/2,y:(n.y+o.y)/2};s=r,a={x:i.x-c.x,y:i.y-c.y}}else a={x:r.x-s.x,y:r.y-s.y};return Math.hypot(a.x,a.y)<1e-6?null:{pivot:s,dir:a,t1:o,t2:i,mid:r,half:l}}function Kt(e,t,n){if(t.x<=0)return e;const o=(n-e.x)/t.x;return{x:n,y:e.y+t.y*o}}function so(e,t,n,o){const[i,r,l]=t;if(!i||!r||!l)return[];const[s,a,c]=e.points,f=n&&s?n.timeToBarIndex(s.time):null,h=n&&a?n.timeToBarIndex(a.time):null,u=n&&c?n.timeToBarIndex(c.time):null;return f!=null&&h!=null&&f===h?[]:o.map(d=>{let x=null;if(n&&f!=null&&h!=null&&u!=null){const p=n.barIndexToTime(Math.round(u+d.coeff*(h-f)));x=p!=null?n.timeToX(p):null}return{...d,x:x??l.x+d.coeff*(r.x-i.x)}})}let fe=null,co=null;function $t(e,t,n,o){return fe||(fe=document.createElement("canvas").getContext("2d")),fe?(co??(co=getComputedStyle(document.body).fontFamily),fe.font=`${o?"italic ":""}${n?"bold ":""}${t}px ${co}`,fe.measureText(e).width):e.length*t*.6}function ze(e,t,n,o,i){const r=e.split(/\r\n|\r|\n/);if(i==null||!Number.isFinite(i)||i<=0)return r;const l=c=>$t(c,t,n,o);if(l("x")>i)return r;const s=c=>{const f=[];for(;c.length;){let h=0,u=c.length;for(;h<u;){const x=h+u>>1;l(c.slice(0,x+1))>i?u=x:h=x+1}const d=Math.max(1,h);f.push(c.slice(0,d)),c=c.slice(d)}return f},a=[];for(const c of r){if(l(c)<=i){a.push(c);continue}const f=[];let h=c;do{const x=h.match(/\s+/);if(!x||x.index===void 0){f.push({word:h,spaces:""});break}f.push({word:h.slice(0,x.index),spaces:x[0]}),h=h.slice(x.index+x[0].length)}while(h.length);let u="",d=0;for(;d<f.length;){const x=f[d];let p=`${u}${x.word}`;if(l(p)>i){if(u!=="")a.push(u),u="";else if(p.length===1)a.push(p),x.word="";else{const y=s(p);for(let b=0;b<y.length-1;b++)a.push(y[b]);x.word=y[y.length-1]}continue}if(p=`${u}${x.word}${x.spaces}`,l(p)<i){u=p,d+=1;continue}a.push(s(p)[0]),u="",d+=1}u!==""&&a.push(u)}return a}function G(e){const t=e.fs;let n=e.wrapWidth!=null?ze(e.text,t,!!e.bold,!!e.italic,e.wrapWidth):e.text.split(`
3
+ `);e.maxHeight!=null&&(n=n.slice(0,Math.max(0,Math.floor(e.maxHeight/t))));const o=e.padV??t/3,i=e.padH??t/3,r=e.offsetX??0,l=e.offsetY??0,s=e.boxWidthFromWrap&&e.wrapWidth!=null?e.wrapWidth:Math.max(0,...n.map(M=>$t(M,t,!!e.bold,!!e.italic)));let a=Math.round(s+2*i);a%2&&(a+=1);const c=e.lineSpacing??0,f=t*n.length+c*Math.max(0,n.length-1)+2*o,h=e.vert==="bottom"?e.y-f-l:e.vert==="middle"?e.y-f/2:e.y+l,u=e.horz==="left"?e.x+r:e.horz==="center"?e.x-a/2:e.x-a-r,d=e.horz==="center"?u+a/2:e.horz==="left"?u:u+a,x=e.vert==="middle"?h+f/2:e.vert==="top"?h:h+f,p=e.horz==="left"?u+i:e.horz==="right"?u+a-i:u+a/2,y=e.horz==="left"?"start":e.horz==="right"?"end":"middle",b=e.angle??0,g=Math.cos(b),m=Math.sin(b),w=(M,k)=>({x:(M-d)*g-(k-x)*m+d,y:(M-d)*m+(k-x)*g+x});return{lines:n,fs:t,lineStep:t+c,tx:p,y0:h+o+t/2+.05*t,anchor:y,rotate:`rotate(${b*180/Math.PI} ${d} ${x})`,box:{left:u,top:h,width:a,height:f},poly:[w(u,h),w(u+a,h),w(u+a,h+f),w(u,h+f)]}}function ao(e,t,n){const[o,i]=t,r=e.points[0];if(!o||!i||!r)return null;const l=Math.round(Math.atan2(i.y-o.y,i.x-o.x)*180/Math.PI),[s,a]=l>=-135&&l<=-45?["center","bottom"]:l>-45&&l<45?["left","middle"]:l>=45&&l<=135?["center","top"]:["right","middle"],c=e.style;return G({x:i.x,y:i.y,text:r.price.toFixed(n),fs:c.priceLabelFontSize??12,bold:c.priceLabelBold,italic:c.priceLabelItalic,horz:s,vert:a,padV:6,padH:8})}function fo(e,t,n){const[o,i]=t;if(!e.text||!o||!i)return null;const r=e.style,l=Math.min(o.x,i.x),s=Math.max(o.x,i.x),a=Math.min(o.y,i.y),c=Math.max(o.y,i.y),f=!!r.extendLeft,h=!!r.extendRight,u=(l<=n||f)&&(s>=0||h),d=r.fontSize??14,x=d/3,p=r.horzLabelsAlign??"center",y=r.vertLabelsAlign??"middle",b=y==="middle",g=b?x:0,w={x:p==="left"?f?u?0:s:l:p==="right"?h?u?n:l:s:((f&&u?0:l)+(h&&u?n:s))/2,y:b?(a+c)/2:y==="top"?c:a,text:e.text,fs:d,bold:r.bold,italic:r.italic,vert:y,horz:p,padV:x,padH:g,wrapWidth:b?(h?n:s)-(f?0:l)-2*g:void 0,maxHeight:b?c-a:void 0},M=G(w);if(p==="left"&&f||p==="right"&&h){const k=f?0:Math.max(l,0),C=(h?n:Math.min(s,n))-k-M.box.width;if(C<0)return G({...w,offsetX:C})}return M}function We(e,t,n){const o=Math.min(t,n),i=Math.max(t,n),r=[];for(const l of e){const s=N(l.time);s!=null&&s>=o&&s<=i&&r.push(l)}return r}function Er(e){const t=e.length;if(t<2)return null;let n=0,o=0,i=0,r=0,l=0;for(let d=0;d<t;d++){const x=e[d];n+=d,o+=x,i+=d*d,r+=d*x,l+=x*x}const s=t*i-n*n;if(Math.abs(s)<1e-9)return null;const a=(t*r-n*o)/s,c=(o-a*n)/t;let f=0;for(let d=0;d<t;d++){const x=e[d]-(c+a*d);f+=x*x}const h=t*l-o*o,u=h>1e-12?(t*r-n*o)/Math.sqrt(s*h):0;return{m:a,b:c,sd:Math.sqrt(f/(t-1)),r:u}}function Pr(e,t){const[n,o]=e;if(o.x<=n.x||t<=o.x)return e;const i=(t-n.x)/(o.x-n.x);return[n,{x:t,y:n.y+(o.y-n.y)*i}]}function ho(e,t,n){const o=e.points[1],i=N(e.points[0].time),r=o?N(o.time):null;if(!t||i==null||r==null)return null;const l=We(t.bars(),i,r),s=e.style.regressionSource??"close",a=Er(l.map(C=>uo(C,s)));if(!a)return null;const c=l.length,f=a.b,h=a.b+a.m*(c-1);let u=-1/0,d=-1/0;for(let C=0;C<c;C++){const T=a.b+a.m*C;u=Math.max(u,l[C].high-T),d=Math.max(d,T-l[C].low)}const x=e.style.useUpperDeviation===!1?u:(e.style.upperDeviation??2)*a.sd,p=e.style.useLowerDeviation===!1?-d:(e.style.lowerDeviation??-2)*a.sd,y=(C,T)=>{const F=t.timeToX(C),A=t.priceToY(T);return F==null||A==null?null:{x:F,y:A}},b=y(l[0].time,f),g=y(l[c-1].time,h);if(!b||!g)return null;const m=y(l[0].time,f+x),w=y(l[c-1].time,h+x),M=y(l[0].time,f+p),k=y(l[c-1].time,h+p),v=C=>e.style.extendRight&&n!=null?Pr(C,n):C;return{center:v([b,g]),upper:m&&w?v([m,w]):null,lower:M&&k?v([M,k]):null,pearsons:a.r,anchors:i<=r?[b,g]:[g,b]}}function uo(e,t){switch(t){case"open":return e.open;case"high":return e.high;case"low":return e.low;case"close":return e.close;case"hl2":return(e.high+e.low)/2;case"ohlc4":return(e.open+e.high+e.low+e.close)/4;case"hlcc4":return(e.high+e.low+e.close+e.close)/4;case"hlc3":default:return(e.high+e.low+e.close)/3}}function hn(e,t,n){const o=n==="upper"?e.vwapUpper:e.vwapLower,i=(e.levels??sn)[t],r=Zn[t]??Zn[0];return(o==null?void 0:o[t])??{...r,color:(i==null?void 0:i.color)??r.color,width:(i==null?void 0:i.width)??r.width}}const xo=new WeakMap;function yo(e,t,n,o){const i=t[t.length-1],r=`${n}|${o}|${t.length}|${i?`${N(i.time)}:${i.close}:${i.volume}`:""}`;let l=xo.get(t);l||(l=new Map,xo.set(t,l));const s=l.get(e.id);if(s&&s.key===r)return s.data;let a=0,c=t.length;for(;a<c;){const b=a+c>>1,g=N(t[b].time);g!=null&&g<n?a=b+1:c=b}const f=t.length-a,h=new Float64Array(Math.max(0,f)),u=new Float64Array(Math.max(0,f));let d=0,x=0,p=0;for(let b=0;b<f;b++){const g=t[a+b],m=uo(g,o),w=g.volume&&g.volume>0?g.volume:1;d+=m*w,x+=m*m*w,p+=w;const M=d/p;h[b]=M,u[b]=Math.sqrt(Math.max(0,x/p-M*M))}const y={start:a,vwap:h,sd:u};return l.set(e.id,{key:r,data:y}),y}function po(e,t){let n=0,o=e.length;for(;n<o;){const i=n+o>>1,r=N(e[i].time);r!=null&&r<t?n=i+1:o=i}return n}function zr(e,t){const n=N(e.points[0].time);if(!t||n==null)return null;const o=t.bars();if(o.length===0)return null;const i=yo(e,o,n,e.style.vwapSource??"hlc3");return i.vwap.length>0?i.vwap[i.vwap.length-1]:null}function bo(e,t){const n=N(e.points[0].time),o={line:[],bands:[]};if(!t||n==null)return o;const i=e.style.vwapSource??"hlc3";o.bands=(e.style.levels??sn).map((h,u)=>({level:h,index:u,upper:[],lower:[]})).filter(h=>h.level.visible);const r=e.style.vwapBandsMode==="percent",l=t.bars();if(l.length===0)return o;const s=yo(e,l,n,i);let a=s.start,c=l.length;const f=t.visibleTimeRange();f&&(a=Math.max(a,po(l,f.from)-1),c=Math.min(c,po(l,f.to)+2));for(let h=a;h<c;h++){const u=h-s.start,d=l[h],x=s.vwap[u],p=t.timeToX(d.time),y=t.priceToY(x);if(!(p==null||y==null)&&(o.line.push({x:p,y}),o.bands.length>0)){const b=r?x*.01:s.sd[u];for(const g of o.bands){const m=t.priceToY(x+g.level.coeff*b),w=t.priceToY(x-g.level.coeff*b);m!=null&&g.upper.push({x:p,y:m}),w!=null&&g.lower.push({x:p,y:w})}}}return o}function go(e,t,n=32){const o=t.x-e.x,i=t.y-e.y;if(Math.abs(o)<1||Math.abs(i)<1)return[e,t];const r=Math.abs(o),l=Math.abs(i),s=i<0?Math.PI/2:-Math.PI/2,a=o>0?0:i<0?Math.PI:-Math.PI,c=[];for(let f=0;f<=n;f++){const h=s+(a-s)*f/n;c.push({x:e.x+r*Math.cos(h),y:t.y+l*Math.sin(h)})}return c}function Wr(e,t){const n=e.points[1];if(!t||!n)return"waiting";const o=N(n.time);if(o==null)return"waiting";const i=t.bars();if(i.length===0)return"waiting";const r=N(i[i.length-1].time);if(r==null||o>r)return"waiting";let l=null,s=!1;for(let c=i.length-1;c>=0;c--){const f=N(i[c].time);if(f!=null&&f<=o){l=i[c],s=c===i.length-1;break}}return l?(n.price>e.points[0].price?l.high>=n.price:l.low<=n.price)?"success":s?"waiting":"failure":"waiting"}function mo(e,t,n,o=24,i=.7){const r=We(e,t,n);if(r.length===0)return null;let l=1/0,s=-1/0;for(const y of r)l=Math.min(l,y.low),s=Math.max(s,y.high);s>l||(s=l+1e-9);const a=(s-l)/o,c=Array.from({length:o},()=>({up:0,down:0}));for(const y of r){const b=y.volume??0;if(b<=0)continue;const g=y.close>=y.open,m=y.high-y.low;if(m<=0){const k=Math.min(o-1,Math.max(0,Math.floor((y.close-l)/a)));g?c[k].up+=b:c[k].down+=b;continue}const w=Math.max(0,Math.floor((y.low-l)/a)),M=Math.min(o-1,Math.floor((y.high-l)/a));for(let k=w;k<=M;k++){const v=Math.max(y.low,l+k*a),C=Math.min(y.high,l+(k+1)*a),T=C>v?(C-v)/m*b:0;g?c[k].up+=T:c[k].down+=T}}const f=c.map(y=>y.up+y.down);let h=0;for(let y=1;y<o;y++)f[y]>f[h]&&(h=y);const u=f.reduce((y,b)=>y+b,0);let d=h,x=h,p=f[h];for(;p<u*i&&(d>0||x<o-1);){const y=d>0?f[d-1]:-1;(x<o-1?f[x+1]:-1)>=y?p+=f[++x]:p+=f[--d]}return{lo:l,hi:s,rows:c,poc:h,vaFrom:d,vaTo:x,maxTotal:Math.max(...f),lastTime:r[r.length-1].time}}function wo(e,t,n){if(!n)return null;const o=n.bars();if(o.length===0)return null;const i=N(e.points[0].time),r=N(o[o.length-1].time);if(i==null||r==null)return null;const l=mo(o,i,r);if(!l)return null;const s=n.timeToX(l.lastTime),a=n.priceToY(l.hi),c=n.priceToY(l.lo);return s==null||a==null||c==null?null:{left:t[0].x,right:s,top:Math.min(a,c),bottom:Math.max(a,c),vp:l}}function Mo(e,t,n){if(!n||e.points.length<2||t.length<2)return null;const o=N(e.points[0].time),i=N(e.points[1].time);if(o==null||i==null)return null;const r=mo(n.bars(),Math.min(o,i),Math.max(o,i));if(!r)return null;const l=n.priceToY(r.hi),s=n.priceToY(r.lo);return l==null||s==null?null:{left:Math.min(t[0].x,t[1].x),right:Math.max(t[0].x,t[1].x),top:Math.min(l,s),bottom:Math.max(l,s),vp:r}}function ko(e,t,n,o){const[i,r]=t,l=(e.style.levels??o).filter(M=>M.visible),s=(e.style.vLevels??e.style.levels??o).filter(M=>M.visible),a=!!e.style.reverse,c=e.points[0],f=e.points[1]??e.points[0],h=a?c.price:f.price,u=a?f.price-c.price:c.price-f.price,d=a?i.y:r.y,x=a?r.y-i.y:i.y-r.y,p=l.map(M=>{const k=(n==null?void 0:n.priceToY(h+M.coeff*u))??d+M.coeff*x;return{coeff:M.coeff,color:M.color,y:k}}),y=(n==null?void 0:n.timeToBarIndex(c.time))??null,b=(n==null?void 0:n.timeToBarIndex(f.time))??null,g=a?i.x:r.x,m=a?r.x-i.x:i.x-r.x,w=s.map(M=>{let k=null;if(n&&y!=null&&b!=null){const v=n.barIndexToTime(Math.round((a?y:b)+M.coeff*(a?b-y:y-b)));k=v!=null?n.timeToX(v):null}return{coeff:M.coeff,color:M.color,x:k??g+M.coeff*m}});return{h:p,v:w,box:{left:Math.min(i.x,r.x),top:Math.min(i.y,r.y),right:Math.max(i.x,r.x),bottom:Math.max(i.y,r.y)}}}function un(e,t,n,o){const i=t.x-e.x,r=t.y-e.y,l=Math.hypot(i,r);if(l<1e-9)return t;const s=Math.max(1,2*(n+o)/l);return{x:e.x+i*s,y:e.y+r*s}}const Rr=["bars","oc","line","line-open","line-high","line-low","line-hl2"];function vo(e,t){const[n,o,i,r]=e;switch(t){case"bars":return[o,i];case"oc":return[n,r];case"line":return[r];case"line-open":return[n];case"line-high":return[o];case"line-low":return[i];default:return[(o+i)/2]}}function Lo(e,t,n,o){const[i,r,l,s]=e;if(t==="line-hl2")return(r+l)/2;const a=n!==o;switch(t){case"bars":return a?r:l;case"oc":return a?i:s;case"line":return s;case"line-open":return i;case"line-high":return r;default:return l}}function So(e,t,n){var D;if(e.kind!=="bar-pattern"||!n)return null;const o=((D=e.pattern)==null?void 0:D.bars)??[];if(o.length===0||t.length<2)return null;const i=e.style,[r,l]=t,s=Rr.includes(i.patternMode??"")?i.patternMode:"bars";let a=o;if(i.mirrored){let S=1/0,E=-1/0;for(const B of a)S=Math.min(S,B[2],B[1]),E=Math.max(E,B[1],B[2]);if(S<E){const B=(S+E)/2,I=R=>B-(R-B);a=a.map(([R,Y,J,gt])=>[I(R),I(Y),I(J),I(gt)])}}i.flipped&&(a=[...a].reverse());const c=!!i.mirrored!=!!i.flipped,f=c?e.points[1].price:e.points[0].price,h=c?e.points[0].price:e.points[1].price,u=n.priceToY(f),d=n.priceToY(h),x=Lo(a[0],s,!0,!!i.flipped),p=Lo(a[a.length-1],s,!1,!!i.flipped),y=n.priceToY(x),b=n.priceToY(p);if(u==null||d==null||y==null||b==null)return null;const g=b!==y?+((d-u)/(b-y)).toFixed(8):1,m=S=>(n.priceToY(S)??0)*g,w=n.timeToBarIndex(e.points[0].time),M=n.timeToBarIndex(e.points[1].time),v=w==null||M==null||w<=M?{x:r.x,y:u}:{x:l.x,y:d},C=a.length,T=C>1?Math.abs(r.x-l.x)/(C-1):0,F=v.y-m(x),A=a.map((S,E)=>Math.round(v.x+E*T+.5)),O=s!=="bars"&&s!=="oc";return O?{lineMode:O,bars:[],line:a.map((S,E)=>({x:A[E],y:Math.round(m(vo(S,s)[0]))+F}))}:{lineMode:O,line:[],bars:a.map((S,E)=>{const[B,I]=vo(S,s),R=Math.round(m(B))+F,Y=Math.round(m(I))+F;return{x:A[E],top:Math.min(R,Y),bottom:Math.max(R,Y)}})}}let he=null;function Fr(e,t){return he||(he=document.createElement("canvas").getContext("2d")),he?(he.font=t,he.measureText(e).width):e.length*8}function Co(e,t){const n=e.text??"";if(n===""||e.kind!=="arrow-mark-up"&&e.kind!=="arrow-mark-down")return null;const o=e.style,i=o.fontSize??14,r=i/3,l=Math.ceil(i),s=n.split(`
4
+ `),a=`${o.italic?"italic ":""}${o.bold?"bold ":""}${i}px ${getComputedStyle(document.body).fontFamily}`;let c=Math.round(Math.max(...s.map(u=>Fr(u,a)))+2*r);c%2&&(c+=1);const f=s.length*l+2*r,h=e.kind==="arrow-mark-up"?t.y+20:t.y-20-f;return{left:t.x-c/2,top:h,width:c,height:f,lines:s,lineH:l,pad:r}}const Dt=8,dt=1,Or=2,To=120,Ao=1.3,Dr="#2962ff",_r="rgba(41, 98, 255, 0.2)",$o=3,Qt=1024;function Hr(e){return Qt+(e.row==null?0:e.row+1)*Qt+(e.col==null?0:e.col+1)}function Io(e){if(e<Qt)return null;const t=e-Qt,n=Math.floor(t/Qt),o=t%Qt;return{row:n===0?null:n-1,col:o===0?null:o-1}}function It(e){return e.tableCells??[["","",""],["","",""],["","",""]]}function ue(e){var o;const t=((o=It(e)[0])==null?void 0:o.length)??0,n=e.tableColWidths??[];return Array.from({length:t},(i,r)=>n[r]??To)}function dn(e){const t=It(e).length,n=e.tableRowHeights??[];return Array.from({length:t},(o,i)=>n[i]??0)}const Bo=e=>e.fontSize??14,Eo=e=>$t("0",e,!1,!1);function Nr(e){return Eo(e)+2*Dt+2*dt}function Po(e){return e+2*Dt+dt}function Yr(e,t){return Math.max(e-2*Dt-2*dt,Eo(t))}function zo(e,t,n){return e===""?[]:ze(e,n,!1,!1,Yr(t,n))}function Ur(e,t){return e*t+(e-1)*t*(Ao-1)+2*Dt+2*dt}function Wo(e,t=It(e),n=ue(e)){const o=Bo(e),i=dn(e),r=[];return{heights:i.map((s,a)=>{var f;let c=Po(o);for(let h=0;h<n.length;h++)c=Math.max(c,Ur(zo(((f=t[a])==null?void 0:f[h])??"",n[h],o).length,o));return r.push(c),Math.max(s,c)}),mins:r}}function xn(e,t){const n=e.style,o=Bo(n),i=It(n),r=ue(n),{heights:l}=Wo(n,i,r),s=[Math.round(t.x)];let a=0;for(const h of r)a+=h,s.push(Math.round(t.x+a));const c=[Math.round(t.y)];a=0;for(const h of l)a+=h,c.push(Math.round(t.y+a));const f=i.map(h=>h.map((u,d)=>zo(u,r[d],o)));return{left:s[0],top:c[0],right:s[s.length-1],bottom:c[c.length-1],xs:s,ys:c,cells:i,lines:f,fs:o}}function Ro(e){return[{x:e.left,y:e.top},{x:e.left,y:e.bottom},{x:e.right,y:e.top},{x:e.right,y:e.bottom}]}function Vr(e,t,n){if(n){let o=null,i=null;if(t.x>=e.left&&t.x<=e.right){for(let r=0;r<e.ys.length-1;r++)if(Math.abs(t.y-e.ys[r+1])<=$o){o=r;break}}if(t.y>=e.top&&t.y<=e.bottom){for(let r=0;r<e.xs.length-1;r++)if(Math.abs(t.x-e.xs[r+1])<=$o){i=r;break}}if(o!=null||i!=null)return{edge:{row:o,col:i}}}for(let o=0;o<e.ys.length-1;o++)for(let i=0;i<e.xs.length-1;i++)if(t.x>=e.xs[i]&&t.x<=e.xs[i+1]&&t.y>=e.ys[o]&&t.y<=e.ys[o+1])return{cell:[o,i]};return null}function yn(e,t,n){const o=a=>a.reduce((c,f)=>c+f,0);let i=o(e),r=Math.max(n,o(t));if(i===r)return[...e];if(r<i)for(let a=0;a<e.length;a++)e[a]===t[a]&&(i-=e[a],r-=e[a]);const l=r/i,s=e.map((a,c)=>Math.max(t[c],a*l));return o(s)>r+.01?yn(s,t,n):s}function Xr(e,t,n){var a;const o=It(e).map(c=>[...c]),i=ue(e),r=dn(e),[l,s]=n??[o.length-1,(((a=o[0])==null?void 0:a.length)??1)-1];if(t==="row"){const c=l+1;o.splice(c,0,new Array(i.length).fill("")),r.splice(c,0,0)}else{const c=s+1;for(const f of o)f.splice(c,0,"");i.splice(c,0,To)}return{tableCells:o,tableColWidths:i,tableRowHeights:r}}function Gr(e,t){var o;const n=It(e);return t==="row"?n.length>1:(((o=n[0])==null?void 0:o.length)??0)>1}function jr(e,t,n){const o=It(e).map(c=>[...c]),i=ue(e),r=dn(e),[l,s]=n;if(t==="row")o.splice(l,1),r.splice(l,1);else{for(const c of o)c.splice(s,1);i.splice(s,1)}const a=[Math.min(l,o.length-1),Math.min(s,i.length-1)];return{patch:{tableCells:o,tableColWidths:i,tableRowHeights:r},cell:a}}function qr(e,t,n){const o=It(e).map(i=>[...i]);return o[t[0]]&&(o[t[0]][t[1]]=n),{tableCells:o}}const Zr=2e6,pn=2e3,Kr={"image/png":"png","image/jpeg":"jpg","image/webp":"webp"},Bt=new Map;let Fo=()=>Promise.reject(new Error("no image reader"));const bn=new Set;function Qr(e){Fo=e}function Oo(e){return bn.add(e),()=>bn.delete(e)}function Do(){for(const e of bn)e()}function _o(e){return new Promise((t,n)=>{const o=new Image;o.onload=()=>t({url:e,width:o.naturalWidth,height:o.naturalHeight}),o.onerror=()=>n(new Error("image decode failed")),o.src=e})}function gn(e){if(!e)return null;const t=Bt.get(e);return t&&t!=="loading"&&t!=="error"?t:(t||(Bt.set(e,"loading"),Fo(e).then(n=>_o(URL.createObjectURL(n))).then(n=>Bt.set(e,n),n=>{Bt.set(e,"error"),console.warn("[image] read failed:",n)}).then(Do)),null)}function Jr(e){return!!e&&Bt.get(e)==="error"}function Ho(e,t){const n=e.image,o=gn(n==null?void 0:n.name);if(!n||!o||o.width>pn||o.height>pn)return null;const i=t.x+(n.dx??0);return{left:i-n.cssWidth/2,top:t.y-n.cssHeight/2,right:i+n.cssWidth/2,bottom:t.y+n.cssHeight/2}}function No(e){return[{x:e.left+1,y:e.top+1},{x:e.right-1,y:e.top+1},{x:e.left+1,y:e.bottom-1},{x:e.right-1,y:e.bottom-1}]}const tl=[[-1,-1],[1,-1],[-1,1],[1,1]];function el(e,t,n,o){const i=Math.min(Math.min(1,n/4/e),Math.min(1,o/4/t));return{cssWidth:Math.round(i*e),cssHeight:Math.round(i*t)}}function nl(e,t){(!Bt.has(e)||Bt.get(e)==="error")&&Bt.set(e,t),Do()}const ol="Add text",il={text:"Text",note:"Add text",pin:"Note",comment:"Comment","price-note":"Price note",signpost:"Signpost",callout:"Callout"};function rl(e){const t=!!(e.text&&e.text.length>0);return{txt:t?e.text:il[e.kind]??"Text",faint:!t}}function Yo(e,t,n,o){const{txt:i,faint:r}=rl(e),l=t.fontSize??14,s=$t(i,l,!1,!1)+16,a=l+12,c=Math.round(180*Math.atan2(o.y-n.y,o.x-n.x)/Math.PI);let f=o.x,h=o.y-a/2;return c>=-135&&c<=-45?(f=o.x-s/2,h=o.y-a):c>-45&&c<45?f=o.x:c>=45&&c<=135?(f=o.x-s/2,h=o.y):f=o.x-s,{txt:i,faint:r,fs:l,box:{left:f,top:h,width:s,height:a}}}function yt(e){return e.text?{text:e.text,faint:!1}:{text:ol,faint:!0}}function Uo(e,t){const n=e.style,o=n.fontSize??14,i=o/6;return G({x:t.x,y:t.y,text:yt(e).text,fs:o,bold:n.bold,italic:n.italic,vert:"top",horz:"left",padV:i,padH:i,wrapWidth:n.wordWrap?n.wordWrapWidth??200:void 0,boxWidthFromWrap:!0})}function Vo(e,t){const o=e.style.fontSize??16,i=Math.round(o/1.3),r=G({x:t.x,y:t.y,text:yt(e).text,fs:o,vert:"bottom",horz:"left",padV:i,padH:12}),l=Math.min(r.box.width,o+2*i)/2;return{l:r,r:l}}function ll(e,t,n,o,[i,r,l,s]){return`M ${e+i} ${t} H ${e+n-r} A ${r} ${r} 0 0 1 ${e+n} ${t+r} V ${t+o-l} A ${l} ${l} 0 0 1 ${e+n-l} ${t+o} H ${e+s} A ${s} ${s} 0 0 1 ${e} ${t+o-s} V ${t+i} A ${i} ${i} 0 0 1 ${e+i} ${t} Z`}const sl="m12 30 .88-.77C20.25 22.73 24 17.07 24 12.09 24 5.04 18.54 0 12 0S0 5.04 0 12.1c0 4.97 3.75 10.64 11.12 17.13L12 30Zm0-13a5 5 0 1 0 0-10 5 5 0 0 0 0 10Z";function Xo(e,t,n){const o=e.style,i=o.fontSize??14,r=Math.min(236,n),l=ze(yt(e).text,i,!!o.bold,!!o.italic,r-24);let s=l.length*i+24;l.length>1&&(s+=5*(l.length-1));let a=Math.round(t.x-r/2),c=Math.round(t.y-30-s-13);const f=t.x<24||t.x+24>n;let h=f?null:"top";return c<10?c=t.y+13:f||(h="bottom"),a<10?a=10:a+r+10>n&&(a=n-r-10),{fs:i,width:r,height:s,left:a,top:c,lines:l,caret:h,marker:{left:t.x-12,top:t.y-30,right:t.x+12,bottom:t.y}}}function Go(e,t){const{left:n,top:o,width:i,height:r,caret:l}=e,s=4,a=t-6,c=t+6;let f=`M ${n} ${o+s} A ${s} ${s} 0 0 1 ${n+s} ${o}`;return l==="top"&&(f+=` L ${a} ${o} L ${t} ${o-10} L ${c} ${o}`),f+=` L ${n+i-s} ${o} A ${s} ${s} 0 0 1 ${n+i} ${o+s} L ${n+i} ${o+r-s} A ${s} ${s} 0 0 1 ${n+i-s} ${o+r}`,l==="bottom"&&(f+=` L ${c} ${o+r} L ${t} ${o+r+10} L ${a} ${o+r}`),f+=` L ${n+s} ${o+r} A ${s} ${s} 0 0 1 ${n} ${o+r-s} Z`,f}function jo(e,t,n){const o=$t(e,n,!0,!1)+20,i=n+10,r=t.x+9,l=t.y-(i+15);return{x:r,y:l,w:o,h:i,fs:n}}function cl(e){const{x:t,y:n,w:o,h:i}=e,r=3;return`M ${t+12} ${n+i} L ${t-9} ${n+i+15} L ${t+5} ${n+i} L ${t+r} ${n+i} A ${r} ${r} 0 0 1 ${t} ${n+i-r} L ${t} ${n+r} A ${r} ${r} 0 0 1 ${t+r} ${n} L ${t+o-r} ${n} A ${r} ${r} 0 0 1 ${t+o} ${n+r} L ${t+o} ${n+i-r} A ${r} ${r} 0 0 1 ${t+o-r} ${n+i} Z`}function qo(e,t){const n=e.style,o=n.fontSize??14,i=n.wordWrap?n.wordWrapWidth??200:void 0,r=ze(yt(e).text,o,!!n.bold,!!n.italic,i),l=i??Math.max(0,...r.map(u=>$t(u,o,!!n.bold,!!n.italic))),s=o*r.length,a=l+20,c=s+20,f=t.x-a/2,h=t.y-c/2;return{fs:o,lines:r,textW:l,textH:s,x:f,y:h,w:a,h:c,wrap:i}}function al(e,t,n){const{x:o,y:i,w:r,h:l,textW:s,textH:a}=e,c=t.x-o,f=t.y-i,h=n.x-o,u=n.y-i;let d=0;t.x>o+r?d=20:t.x>o&&(d=10),t.y>i+l?d+=2:t.y>i&&(d+=1);const x=s+4>16,p=a+4>16,y=(m,w)=>`${o+m} ${i+w}`,b=(m,w)=>`A 8 8 0 0 1 ${y(m,w)}`;let g=`M ${y(8,0)}`;return d===10?g+=x?` L ${y(h-8,0)} L ${y(c,f)} L ${y(h+8,0)} L ${y(r-8,0)}`:` L ${y(c,f)} L ${y(r-8,0)}`:g+=` L ${y(r-8,0)}`,g+=d===20?` L ${y(c,f)} L ${y(r,8)}`:` ${b(r,8)}`,d===21?g+=p?` L ${y(r,u-8)} L ${y(c,f)} L ${y(r,u+8)} L ${y(r,l-8)}`:` L ${y(c,f)} L ${y(r,l-8)}`:g+=` L ${y(r,l-8)}`,g+=d===22?` L ${y(c,f)} L ${y(r-8,l)}`:` ${b(r-8,l)}`,d===12?g+=x?` L ${y(h+8,l)} L ${y(c,f)} L ${y(h-8,l)} L ${y(8,l)}`:` L ${y(c,f)} L ${y(8,l)}`:g+=` L ${y(8,l)}`,g+=d===2?` L ${y(c,f)} L ${y(0,l-8)}`:` ${b(0,l-8)}`,d===1?g+=p?` L ${y(0,u+8)} L ${y(c,f)} L ${y(0,u-8)} L ${y(0,8)}`:` L ${y(c,f)} L ${y(0,8)}`:g+=` L ${y(0,8)}`,g+=d===0?` L ${y(c,f)} L ${y(8,0)}`:` ${b(8,0)}`,g+" Z"}const _t={pole:"#808080",labelBg:"#0f0f0f",labelBorder:"#2e2e2e",labelText:"#dbdbdb",plateBorder:"#0f0f0f"};function Zo(e,t){const n=e.barAt(t.time);return n?{high:n.high,low:n.low}:null}function Ko(e,t,n){const o=Zo(e,t),i=e.priceToY(t.price);if(i==null)return 50;let r=1,l=n/2;o?(r=t.price>=o.low?1:-1,l=e.priceToY(r===1?o.high:o.low)??l):r=i<=n/2?1:-1;const s=r===1?l:n-l,a=Math.min(n,Math.abs(i-l));return s>0?Math.max(0,Math.min(100,100*a/s))*r:50*r}function fl(e,t,n,o){const i=Math.min(t,Math.max(0,o===1?n:t-n));return n-o*Math.abs(i*e/100)}function mn(e,t,n,o){const i=e.style,r=i.signpostPosition??50,l=r>=0?1:-1,s=Zo(n,e.points[0]),a=s?n.priceToY(l===1?s.high:s.low):null,c=a!=null,f=c?a:o/2,h=c?f-l*3:o,u=i.fontSize??12,d=k=>G({x:t.x,y:k,text:yt(e).text,fs:u,bold:i.bold,italic:i.italic,vert:l===1?"top":"bottom",horz:"center",padV:6,padH:8,wrapWidth:134,lineSpacing:3});let x=fl(r,o,f,l),p=d(x);const y=p.box.height,b=l===1?Math.min(h-y,x):Math.max(h+y,x);b!==x&&(x=b,p=d(x));const g=i.showImage?80:0,m=x+(y+g)*l,w=x+(y+10+35)*l,M=i.showImage?[x+y*l,x+y*l+10*l]:null;return{l:p,anchor:{x:t.x,y:x},poleStart:h,poleEnd:m,plateY:w,gap:M,n:l,x:t.x}}function Qo(e,t,n,o){const i=t.yToPrice(o);return i==null?null:Ko(t,{time:e.points[0].time,price:i},n)}const rt=et+L;function Ht(e,t){return e.x>=t.left&&e.x<=t.left+t.width&&e.y>=t.top&&e.y<=t.top+t.height}function W(e,t){for(let n=0;n<e.length;n++)if(Math.hypot(e[n].x-t.x,e[n].y-t.y)<=rt)return{hit:"handle",handleIndex:n};return null}function hl(e,t,n){const o=At(e,t);for(let i=0;i<4;i++)if(Math.hypot(o[i].x-n.x,o[i].y-n.y)<=rt)return{hit:"handle",handleIndex:i};return null}function ul(e,t,n,o=L){const i=e[0];return Math.hypot(.9*n-t.x,i.y-t.y)<=rt?{hit:"handle",handleIndex:0}:Math.abs(t.y-i.y)<=o?{hit:"body"}:null}function dl(e,t,n,o=L){const i=e[0];return Math.hypot(i.x-t.x,.9*n-t.y)<=rt?{hit:"handle",handleIndex:0}:Math.abs(t.x-i.x)<=o?{hit:"body"}:null}function xl(e,t,n=L){const o=e[0];return Math.hypot(o.x-t.x,o.y-t.y)<=rt?{hit:"handle",handleIndex:0}:Math.abs(t.y-o.y)<=n||Math.abs(t.x-o.x)<=n?{hit:"body"}:null}function Jo(e,t,n=L){const o=e[0];return Math.hypot(o.x-t.x,o.y-t.y)<=rt?{hit:"handle",handleIndex:0}:t.x>=o.x-rt&&Math.abs(t.y-o.y)<=n?{hit:"body"}:null}function yl(e,t,n){const o=W(t,n);if(o)return o;const i=e.style,r=i.extendLeft?-1/0:Math.min(t[0].x,t[1].x),l=i.extendRight?1/0:Math.max(t[0].x,t[1].x),s=Math.min(t[0].y,t[1].y),a=Math.max(t[0].y,t[1].y);return n.x>=r-L&&n.x<=l+L&&n.y>=s-L&&n.y<=a+L?{hit:"body"}:null}function pl(e,t,n,o,i){const r=W(t,n);if(r)return r;const l=e.style,s=l.extendLeft??e.kind==="extended-line",a=l.extendRight??(e.kind==="ray"||e.kind==="extended-line"),[c,f]=t;let h=c,u=f;const d=f.x-c.x,x=f.y-c.y,p=Math.hypot(d,x);if(p>1e-6){const y=(o+i)*2;a&&(u={x:f.x+d/p*y,y:f.y+x/p*y}),s&&(h={x:c.x-d/p*y,y:c.y-x/p*y})}return _(n.x,n.y,h,u)<=Be(l)?{hit:"body"}:null}function ti(e,t,n=L){const o=W(e,t);return o||(_(t.x,t.y,e[0],e[1])<=n?{hit:"body"}:null)}function bl(e,t,n,o){const i=t[0],r=t[1],l=e.points[0],s=e.points[1];if(!l||!s)return null;const a=l.price,{stop:c,profit:f}=fn(e,(o==null?void 0:o.pipSize())??.01),h=e.kind==="long-position"?1:-1,u=(o==null?void 0:o.priceToY(a+h*f))??i.y-40,d=(o==null?void 0:o.priceToY(a-h*c))??i.y+40;if(u==null||d==null)return null;const x=(i.x+r.x)/2,p=[i,{x:r.x,y:i.y},{x,y:d},{x,y:u}],y=W(p,n);if(y)return y;const b=Math.min(i.x,r.x),g=Math.max(i.x,r.x),m=Math.min(u,d),w=Math.max(u,d);return n.x>=b-L&&n.x<=g+L&&n.y>=m-L&&n.y<=w+L?{hit:"body"}:null}function Re(e,t,n,o,i){const r=t.x-e.x,l=t.y-e.y,s=Math.hypot(r,l)||1;return[n?{x:e.x-r/s*i,y:e.y-l/s*i}:e,o?{x:t.x+r/s*i,y:t.y+l/s*i}:t]}function wn(e,t,n,o,i,r,l,s){const a=n.x-t.x,c=n.y-t.y,f=a*o.y-c*o.x;if(Math.abs(f)<1e-9)return!1;const h=e.x-t.x,u=e.y-t.y,d=(h*o.y-u*o.x)/f,x=(a*u-c*h)/f;return(l||d>=0)&&(s||d<=1)&&x>=Math.min(i,r)&&x<=Math.max(i,r)}function gl(e,t,n,o,i){const r=W(t,n);if(r)return r;const l=lo(e.kind,t);if(!l)return null;const s=e.style,a=x=>Kt(x,l.dir,o),c=(o+i)*2,f=Math.hypot(l.dir.x,l.dir.y)||1,h=x=>s.extendLines?{x:x.x-l.dir.x/f*c,y:x.y-l.dir.y/f*c}:x,u=[[h(l.pivot),a(l.pivot)],[t[1],t[2]]],d=(s.levels??Mt).filter(x=>x.visible);for(const x of d)for(const p of[1,-1]){const y={x:l.mid.x+l.half.x*x.coeff*p,y:l.mid.y+l.half.y*x.coeff*p};u.push([h(y),a(y)])}for(const[x,p]of u)if(_(n.x,n.y,x,p)<=L)return{hit:"body"};if(s.fillBackground!==!1&&d.length>0){const x=Math.max(...d.map(y=>y.coeff)),p={x:l.mid.x+l.dir.x,y:l.mid.y+l.dir.y};if(wn(n,l.mid,p,l.half,-x,x,!!s.extendLines,!0))return{hit:"body"}}return null}function ml(e,t,n){const o=W(t,n);if(o)return o;const i=e.style,r=i.extendLeft?-1/0:Math.min(t[1].x,t[2].x),l=i.extendRight?1/0:Math.max(t[1].x,t[2].x),s=Math.min(t[0].y,t[1].y,t[2].y),a=Math.max(t[0].y,t[1].y,t[2].y);return n.x>=r-L&&n.x<=l+L&&n.y>=s-L&&n.y<=a+L?{hit:"body"}:null}function wl(e,t,n,o,i){const r=W(t,n);if(r)return r;const[l,s]=t,a=(o+i)*2,c=(e.style.levels??Qe).filter(f=>f.visible);for(const f of c){const h=ro(l,s,f.coeff),u=Math.hypot(h.x,h.y)||1,d={x:l.x+h.x/u*a,y:l.y+h.y/u*a};if(_(n.x,n.y,l,d)<=L)return{hit:"body"}}return null}function Ml(e,t,n,o){const i=W(t,n);if(i)return i;const r=t[1].x-t[0].x,l=(e.style.levels??ln).filter(s=>s.visible);for(const s of l)if(Math.abs(n.x-(t[0].x+r*s.coeff))<=Math.max(o,(s.width??1)/2+2))return{hit:"body"};return _(n.x,n.y,t[0],t[1])<=o?{hit:"body"}:null}function kl(e,t,n){const o=W(t,n);if(o)return o;if(e.fmt===2){const l=(e.style.levels??an).filter(u=>u.visible).map(u=>u.coeff);if(l.length===0)return null;const s=Math.max(...l),a=Math.abs(t[1].x-t[0].x)/2*s+L,c=Math.abs(t[1].y-t[0].y)/2*s+L,f=(n.x-(t[0].x+t[1].x)/2)/a,h=(n.y-(t[0].y+t[1].y)/2)/c;return f*f+h*h<=1?{hit:"body"}:null}const i=Math.hypot(t[1].x-t[0].x,t[1].y-t[0].y);return Math.hypot(n.x-t[0].x,n.y-t[0].y)<=i+L?{hit:"body"}:null}function vl(e,t,n,o,i,r){const[l,s,a]=t,c=s.x-l.x===0?0:(a.x-l.x)/(s.x-l.x),f=a.y-(l.y+(s.y-l.y)*c),h={x:l.x,y:l.y+f},u={x:s.x,y:s.y+f},d={x:(l.x+s.x)/2,y:(l.y+s.y)/2},x=[l,s,h,u,{x:d.x,y:d.y+f},d],p=W(x,n);if(p)return p;const y=e.style,b=(y.levels??$e).filter(m=>m.visible);if(b.length===0)return null;const g=(i+r)*2;for(const m of b){const w=f*m.coeff,[M,k]=Re({x:l.x,y:l.y+w},{x:s.x,y:s.y+w},!!y.extendLeft,!!y.extendRight,g);if(_(n.x,n.y,M,k)<=o)return{hit:"body"}}return y.fillBackground!==!1&&wn(n,l,s,{x:0,y:f},b[0].coeff,b[b.length-1].coeff,!!y.extendLeft,!!y.extendRight)?{hit:"body"}:null}function Ll(e,t,n,o,i,r){const[l,s,a]=t,c={x:s.x,y:a.y},f={x:l.x,y:a.y+(s.y-l.y)},u=W([l,s,c,f],n);if(u)return u;const d=e.style,x=(i+r)*2;for(const[p,y]of[[l,s],[f,c]]){const[b,g]=Re(p,y,!!d.extendLeft,!!d.extendRight,x);if(_(n.x,n.y,b,g)<=o)return{hit:"body"}}return null}function Sl(e,t,n,o,i,r){const l=W(t,n);if(l)return l;const[s,a,c]=t,f=e.style,h=(i+r)*2;for(const[u,d]of[[s,a],[{x:s.x,y:c.y},{x:a.x,y:c.y}]]){const[x,p]=Re(u,d,!!f.extendLeft,!!f.extendRight,h);if(_(n.x,n.y,x,p)<=o)return{hit:"body"}}return null}function Cl(e,t,n,o,i,r){const l=W(t,n);if(l)return l;const[s,a,c]=t;if(!c)return _(n.x,n.y,s,a)<=o?{hit:"body"}:null;const f=e.style,h={x:c.x-s.x,y:c.y-s.y},u=(f.levels??Ft).filter(x=>x.visible).map(x=>x.coeff);if(u.length===0)return null;const d=(i+r)*2;for(const x of u){const[p,y]=Re({x:s.x+h.x*x,y:s.y+h.y*x},{x:a.x+h.x*x,y:a.y+h.y*x},!!f.extendLeft,!!f.extendRight,d);if(_(n.x,n.y,p,y)<=o)return{hit:"body"}}return f.fillBackground===!1?null:wn(n,s,a,h,Math.min(...u),Math.max(...u),!!f.extendLeft,!!f.extendRight)?{hit:"body"}:null}function Tl(e,t){const n=W(e,t);if(n)return n;const[o,i,r]=e;if(!r)return null;const l=(o.x+i.x)/2,s=(o.y+i.y)/2,a=Math.max(1,Math.hypot(i.x-o.x,i.y-o.y)/2),c=Math.atan2(i.y-o.y,i.x-o.x),f=-Math.sin(c),h=Math.cos(c),u=Math.max(1,Math.abs((r.x-l)*f+(r.y-s)*h)),d=t.x-l,x=t.y-s,p=d*Math.cos(-c)-x*Math.sin(-c),y=d*Math.sin(-c)+x*Math.cos(-c);return(p/(a+L))**2+(y/(u+L))**2<=1?{hit:"body"}:null}function ei(e,t){const[n,o,i,r]=At(e,t);return[{x:(n.x+o.x)/2,y:n.y},{x:o.x,y:(o.y+i.y)/2},{x:(r.x+i.x)/2,y:i.y},{x:n.x,y:(n.y+r.y)/2}]}function Mn(e,t,n=!1){const[o,i]=e,r=hl(o,i,t);if(r)return r;if(n){const f=ei(o,i);for(let h=0;h<4;h++)if(Math.hypot(f[h].x-t.x,f[h].y-t.y)<=rt)return{hit:"handle",handleIndex:4+h}}const l=Math.min(o.x,i.x),s=Math.max(o.x,i.x),a=Math.min(o.y,i.y),c=Math.max(o.y,i.y);return t.x>=l-L&&t.x<=s+L&&t.y>=a-L&&t.y<=c+L?{hit:"body"}:null}function Al(e,t){const n=W(e,t);if(n)return n;const[o,i]=e,r=Math.hypot(i.x-o.x,i.y-o.y);return Math.hypot(t.x-o.x,t.y-o.y)<=r+L?{hit:"body"}:null}function $l(e,t,n,o){const i=W(t,n);if(i)return i;const r=e.style.extendLeft?0:Math.min(t[0].x,t[1].x),l=e.style.extendRight?o:Math.max(t[0].x,t[1].x),s=Math.min(t[0].y,t[1].y),a=Math.max(t[0].y,t[1].y);return n.x>=r-L&&n.x<=l+L&&n.y>=s-L&&n.y<=a+L?{hit:"body"}:null}function ni(e,t){const n=W(e,t);if(n)return n;const o=Math.min(e[0].x,e[1].x),i=Math.max(e[0].x,e[1].x),r=Math.min(e[0].y,e[1].y),l=Math.max(e[0].y,e[1].y);return t.x>=o-L&&t.x<=i+L&&t.y>=r-L&&t.y<=l+L?{hit:"body"}:null}function Il(e,t,n){const o=e.fmt===2,i=to(t,o),r=o?[t[0],t[1],...i]:t,l=W(r,n);return l||(Zt(n.x,n.y,i)?{hit:"body"}:null)}function Bl(e,t){const n=W(e,t);return n||(Zt(t.x,t.y,e)?{hit:"body"}:null)}function Jt(e,t,n=L){for(let o=1;o<e.length;o++)if(_(t.x,t.y,e[o-1],e[o])<=n)return{hit:"body"};return null}function El(e,t,n,o,i=L){const r=W(t,n);if(r)return r;const l=So(e,t,o);if(!l){const[s,a]=t;return Math.abs(n.x-s.x)<=i||Math.abs(n.x-a.x)<=i?{hit:"body"}:_(n.x,n.y,s,a)<=i?{hit:"body"}:null}if(l.lineMode){for(let s=1;s<l.line.length;s++)if(_(n.x,n.y,l.line[s-1],l.line[s])<=i)return{hit:"body"};return null}for(const s of l.bars)if(Math.abs(n.x-s.x)<=1+i&&n.y>=s.top-i&&n.y<=s.bottom+i)return{hit:"body"};return null}function Pl(e,t,n,o){const i=W(t,n);if(i)return i;const r=t[0],l=o==="up"?r.y:r.y-22;if(n.x>=r.x-9.75&&n.x<=r.x+9.75&&n.y>=l&&n.y<=l+22)return{hit:"body"};const s=Co(e,r);return s&&n.x>=s.left&&n.x<=s.left+s.width&&n.y>=s.top&&n.y<=s.top+s.height?{hit:"body"}:null}function zl(e,t,n,o,i){const r=W(t,n);if(r)return r;const[l,s]=t,a=ko(e,t,i,Te),c=Math.max(o,Math.abs(s.y-l.y)+Math.max(l.y,s.y)),f=[...a.h.map(d=>({x:s.x,y:d.y})),...a.v.map(d=>({x:d.x,y:s.y}))];for(const d of f){const x=un(l,d,o,c);if(_(n.x,n.y,l,x)<=L)return{hit:"body"}}const h={x:s.x,y:l.y},u={x:l.x,y:s.y};for(const[d,x]of[[l,h],[h,s],[s,u],[u,l]])if(_(n.x,n.y,d,x)<=L)return{hit:"body"};return null}function Wl(e,t,n,o){const i=W(t,n);if(i)return i;const[r,l,s]=t;if(!s)return null;const a={x:(l.x+s.x)/2,y:(l.y+s.y)/2},c={x:(s.x-l.x)/2,y:(s.y-l.y)/2},f=o*4,h=[a],u=(e.style.levels??Mt).filter(d=>d.visible);for(const d of u)h.push({x:a.x+c.x*d.coeff,y:a.y+c.y*d.coeff}),h.push({x:a.x-c.x*d.coeff,y:a.y-c.y*d.coeff});for(const d of h){const x=d.x-r.x,p=d.y-r.y,y=Math.hypot(x,p)||1,b={x:r.x+x/y*f,y:r.y+p/y*f};if(_(n.x,n.y,r,b)<=L)return{hit:"body"}}return _(n.x,n.y,l,s)<=L?{hit:"body"}:null}function Rl(e,t,n,o,i){const r=W(t,n);if(r)return r;const[l,s,a]=t;if(_(n.x,n.y,l,s)<=o)return{hit:"body"};if(a&&_(n.x,n.y,s,a)<=o)return{hit:"body"};const c=(e.style.levels??tn).filter(f=>f.visible);for(const f of so(e,t,i,c))if(Math.abs(n.x-f.x)<=Math.max(o,(f.width??1)/2+2))return{hit:"body"};return null}function Fl(e,t,n){const o=W(t,n);if(o)return o;const i=oo(e,t);if(!i)return null;const r=io(i);return n.x>=r.left-L&&n.x<=r.right+L&&n.y>=r.top-L&&n.y<=r.bottom+L?{hit:"body"}:null}function Ol(e,t){const n=W(e,t);if(n)return n;const[o,i,r]=e;if(!r)return null;const l=Math.hypot(i.x-o.x,i.y-o.y);if(l<1e-6)return null;const s=Math.atan2(i.y-o.y,i.x-o.x);let c=Math.atan2(r.y-o.y,r.x-o.x)-s;for(;c>Math.PI;)c-=2*Math.PI;for(;c<-Math.PI;)c+=2*Math.PI;const f=Math.hypot(t.x-o.x,t.y-o.y);let h=Math.atan2(t.y-o.y,t.x-o.x)-s;for(;h>Math.PI;)h-=2*Math.PI;for(;h<-Math.PI;)h+=2*Math.PI;return(c>=0?h>=-.05&&h<=c+.05:h<=.05&&h>=c-.05)&&f<=l+L?{hit:"body"}:null}function Dl(e,t,n){const o=W(t,n);if(o)return o;const[i,r,l]=t;if(!l)return null;const s=Math.hypot(r.x-i.x,r.y-i.y);if(s<1e-6)return null;const a=Math.atan2(r.y-i.y,r.x-i.x),c=Math.atan2(l.y-i.y,l.x-i.x),f={x:i.x+Math.cos(c)*s,y:i.y+Math.sin(c)*s};if(_(n.x,n.y,i,r)<=L)return{hit:"body"};if(_(n.x,n.y,i,f)<=L)return{hit:"body"};let h=c-a;for(;h>Math.PI;)h-=2*Math.PI;for(;h<-Math.PI;)h+=2*Math.PI;const u=Math.hypot(n.x-i.x,n.y-i.y);let d=Math.atan2(n.y-i.y,n.x-i.x)-a;for(;d>Math.PI;)d-=2*Math.PI;for(;d<-Math.PI;)d+=2*Math.PI;if(h>=0?d>=-.05&&d<=h+.05:d<=.05&&d>=h-.05){const p=(e.style.levels??Je).filter(y=>y.visible);for(const y of p)if(Math.abs(u-s*y.coeff)<=L)return{hit:"body"}}return null}function _l(e,t,n){const o=W(t,n);if(o)return o;const[i,r]=t,l=Math.hypot(r.x-i.x,r.y-i.y);if(l<1e-6)return null;const s=r.y>=i.y?1:-1;if((n.y-i.y)*s<-L)return null;const a=Math.hypot(n.x-i.x,n.y-i.y),c=(e.style.levels??cn).filter(f=>f.visible);for(const f of c)if(Math.abs(a-l*f.coeff)<=L)return{hit:"body"};return null}const de=[0,1,2,3,5,8,13,21,34,55,89];function oi(e,t,n=!1){const o=t.x-e.x,i=t.y-e.y,r=Math.hypot(o,i);if(r<1e-6)return[];const l=Math.atan2(i,o),s=[],a=50*(de.length-1);for(let c=0;c<=a;c++){const f=c/50,h=Math.floor(f),u=Math.ceil(f);if(u>=de.length)break;const d=Math.pow(f-h,1.15),x=(de[h]+(de[u]-de[h])*d)*(r/5),p=l+(n?-1:1)*c*Math.PI/100;s.push({x:e.x+Math.cos(p)*x,y:e.y+Math.sin(p)*x})}return s}function ii(e,t,n){const o=Math.abs(t.x-e.x);if(o<.001)return[];const i=t.y-e.y,r=Math.max(1,o/30),l=[];for(let s=0;s<=n+r;s+=r)l.push({x:s,y:e.y+i/2-Math.cos((s-e.x)*Math.PI/o)*i/2});return l}function kn(e,t=!1,n=!1){const[o,i,r]=e,l=t?-4:0,s=n?5:1,a=Math.ceil(32*(s-l)),c=[];for(let f=0;f<=a;f++){const h=l+(s-l)*f/a,u=1-h;c.push({x:u*u*o.x+2*u*h*i.x+h*h*r.x,y:u*u*o.y+2*u*h*i.y+h*h*r.y})}return c}function ri(e,t,n){const o=t.x-e.x,i=t.y-e.y,r=Math.hypot(o,i);if(r<.001)return null;const l=o/r,s=i/r,a=-s*(n.x-e.x)+l*(n.y-e.y),c=Math.abs(a);if(c<1)return null;const f=a<0?-1:1,h=1-Math.sqrt(3)/2,u=c/(r*h),d=[];for(let x=0;x<=48;x++){const p=2*Math.PI/3-x/48*(Math.PI/3),y=r/2+r*Math.cos(p),b=f*u*r*(Math.sin(p)-Math.sqrt(3)/2);d.push({x:e.x+l*y-s*b,y:e.y+s*y+l*b})}return d}function vn(e,t=!1,n=!1){const[o,i,r,l]=e,s=t?-3:0,a=n?4:1,c=Math.ceil(32*(a-s)),f=[];for(let h=0;h<=c;h++){const u=s+(a-s)*h/c,d=1-u;f.push({x:d*d*d*o.x+3*d*d*u*i.x+3*d*u*u*r.x+u*u*u*l.x,y:d*d*d*o.y+3*d*d*u*i.y+3*d*u*u*r.y+u*u*u*l.y})}return f}const Hl=new Set(["triangle-pattern"]);function Nl(e,t,n){const o=W(t,n);if(o)return o;const i=Be(e.style);for(let r=1;r<t.length;r++)if(_(n.x,n.y,t[r-1],t[r])<=i)return{hit:"body"};if(e.kind==="xabcd-pattern"||e.kind==="cypher-pattern")return t.length>=3&&Zt(n.x,n.y,[t[0],t[1],t[2]])?{hit:"body"}:t.length>=5&&Zt(n.x,n.y,[t[2],t[3],t[4]])?{hit:"body"}:null;if(Hl.has(e.kind)&&t.length>=3&&Zt(n.x,n.y,t))return{hit:"body"};if(e.kind==="polyline"&&e.closed===!0&&e.style.fillBackground!==!1&&t.length>=2){if(_(n.x,n.y,t[t.length-1],t[0])<=i)return{hit:"body"};if(t.length>=3&&Zt(n.x,n.y,t))return{hit:"body"}}return null}function Yl(e,t,n=L){if(e.length===0)return null;const o=e.length-1;return Math.hypot(e[0].x-t.x,e[0].y-t.y)<=rt?{hit:"handle",handleIndex:0}:Math.hypot(e[o].x-t.x,e[o].y-t.y)<=rt?{hit:"handle",handleIndex:o}:Jt(e,t,n)}function xe(e,t,n,o=L){const i=W(t,n);return i||Jt(e,n,o)}function Ul(e,t,n,o){const i=W(e,t);if(i)return i;const[r,l]=e,s=l.x-r.x;if(Math.abs(s)<.001)return null;for(let a=r.x;s>0?a<=n+o:a>=-o;a+=s)if(Math.abs(t.x-a)<=o)return{hit:"body"};return _(t.x,t.y,r,l)<=o?{hit:"body"}:null}function Vl(e,t,n,o){const i=W(e,t);if(i)return i;const[r,l]=e,s=Math.abs(l.x-r.x);if(s<.001)return null;const a=r.y;if(t.y-a>o)return null;const c=s/2,f=Math.min(r.x,l.x),h=Math.floor(-f/s)-1,u=Math.ceil((n-f)/s)+1;for(let d=h;d<=u;d++){const x=f+d*s+c,p=Math.hypot(t.x-x,t.y-a);if(Math.abs(p-c)<=o)return{hit:"body"}}return null}function Xl(e,t,n,o){var s;const i=W(t,n);if(i)return i;if(t[1]&&_(n.x,n.y,t[0],t[1])<=L)return{hit:"body"};const r=(o==null?void 0:o.pipSize())??.01,l=(s=ao(e,t,Math.max(0,Math.min(8,Math.round(-Math.log10(r))))))==null?void 0:s.box;return l&&n.x>=l.left&&n.x<=l.left+l.width&&n.y>=l.top&&n.y<=l.top+l.height?{hit:"body"}:null}function Gl(e,t,n,o,i){const r=ho(e,i,o),l=W(r?r.anchors:t,n);if(l)return l;if(!r)return ti(t,n);const s=[r.center,r.upper,r.lower];for(const a of s)if(a&&_(n.x,n.y,a[0],a[1])<=L)return{hit:"body"};return null}function jl(e,t,n,o){if(Math.hypot(t[0].x-n.x,t[0].y-n.y)<=rt)return{hit:"handle",handleIndex:0};const i=bo(e,o);if(i.line.length<2)return Jo(t,n);const r=Jt(i.line,n);if(r)return r;for(const l of i.bands){if(l.upper.length>=2&&hn(e.style,l.index,"upper").visible&&Jt(l.upper,n))return{hit:"body"};if(l.lower.length>=2&&hn(e.style,l.index,"lower").visible&&Jt(l.lower,n))return{hit:"body"}}return null}function ql(e,t,n=L){const o=W(e,t);return o||Jt(go(e[0],e[1]),t,n)}function Zl(e,t){const n=e[0];return Math.hypot(n.x-t.x,n.y-t.y)<=rt?{hit:"handle",handleIndex:0}:t.x>=n.x-L&&t.x<=n.x+17+L&&t.y>=n.y-22-L&&t.y<=n.y+L?{hit:"body"}:null}function Kl(e,t,n,o){if(!e.ghost)return Mn(t,n);const i=W(t,n);if(i)return i;let r=L;if(o){const l=o.priceToY(e.points[0].price),s=o.priceToY(e.points[0].price+e.ghost.amplitude);l!=null&&s!=null&&(r=Math.max(r,Math.abs(s-l)))}for(let l=1;l<t.length;l++)if(_(n.x,n.y,t[l-1],t[l])<=r)return{hit:"body"};return null}function li(e,t,n,o,i,r,l=!1){var a;const s=Be(e.style);switch(e.kind){case"horizontal-line":return ul(t,n,o,s);case"horizontal-ray":return Jo(t,n,s);case"vertical-line":return dl(t,n,i,s);case"cross-line":return xl(t,n,s);case"arrow-mark-up":case"arrow-mark-down":return Pl(e,t,n,e.kind==="arrow-mark-up"?"up":"down");case"font-icon":return Mr(t,n);case"table":{const c=xn(e,t[0]),f=W(Ro(c),n);if(f)return f;const h=Vr(c,n,l);return h?"edge"in h?{hit:"handle",handleIndex:Hr(h.edge)}:{hit:"body",cell:h.cell}:null}case"image":{const c=Ho(e,t[0]);if(!c)return null;const f=W(No(c),n);return f||(n.x>=c.left&&n.x<=c.right&&n.y>=c.top&&n.y<=c.bottom?{hit:"body"}:null)}case"price-label":{const c=W(t,n);if(c)return c;const f=jo(e.points[0].price.toFixed(Math.max(0,Math.min(8,Math.round(-Math.log10((r==null?void 0:r.pipSize())??.01))))),t[0],e.style.fontSize??14);return Ht(n,{left:f.x,top:f.y,width:f.w,height:f.h})?{hit:"body"}:null}case"flag-mark":return Zl(t,n);case"trend-line":case"ray":case"extended-line":case"info-line":case"arrow":case"trend-angle":return pl(e,t,n,o,i);case"arrow-marker":return ti(t,n,s);case"position-forecast":return ql(t,n,s);case"long-position":case"short-position":return bl(e,t,n,r);case"bar-pattern":return El(e,t,n,r,s);case"ghost-feed":return Kl(e,t,n,r);case"gann-box":return Mn(t,n);case"gann-fan":return wl(e,t,n,o,i);case"fib-time-zone":return Ml(e,t,n,s);case"fib-circles":return kl(e,t,n);case"fib-speed-resistance-fan":return zl(e,t,n,o,r);case"pitchfan":return Wl(e,t,n,o);case"fib-wedge":return Dl(e,t,n);case"trend-based-fib-time":return Rl(e,t,n,s,r);case"gann-square-fixed":case"gann-square":return Fl(e,t,n);case"sector":return Ol(t,n);case"fib-speed-resistance-arcs":return _l(e,t,n);case"fib-spiral":return xe(oi(t[0],t[1],!!e.style.counterclockwise),t,n,s);case"sine-line":return xe(ii(t[0],t[1],o),t,n,s);case"time-cycles":return Vl(t,n,o,s);case"cyclic-lines":return Ul(t,n,o,s);case"curve":return xe(kn(t,!!e.style.extendLeft,!!e.style.extendRight),t,n,s);case"arc":return xe((t.length===3?ri(t[0],t[1],t[2]):null)??[t[0],t[1]],t,n,s);case"double-curve":return xe(vn(t,!!e.style.extendLeft,!!e.style.extendRight),t,n,s);case"text":{const c=Uo(e,t[0]);if(l&&e.style.wordWrap){const f=W([t[0],{x:c.box.left+c.box.width,y:c.box.top+c.box.height/2}],n);if(f&&f.hit==="handle"&&f.handleIndex===1)return f}return Ht(n,c.box)?{hit:"body"}:null}case"comment":{const c=W(t,n);return c||(Ht(n,Vo(e,t[0]).l.box)?{hit:"body"}:null)}case"pin":{const c=Xo(e,t[0],o),f=c.marker;return n.x>=f.left&&n.x<=f.right&&n.y>=f.top&&n.y<=f.bottom?{hit:"body"}:l&&Ht(n,{left:c.left,top:c.top,width:c.width,height:c.height})?{hit:"body"}:null}case"signpost":{if(!r)return null;const c=mn(e,t[0],r,i);return Math.hypot(c.anchor.x-n.x,c.anchor.y-n.y)<=rt?{hit:"handle",handleIndex:0}:_(n.x,n.y,{x:c.x,y:c.poleStart},{x:c.x,y:c.poleEnd})<3?{hit:"body"}:e.style.showImage&&Math.hypot(n.x-c.x,n.y-c.plateY)<=38?{hit:"body"}:Ht(n,c.l.box)?{hit:"body"}:null}case"note":{const c=W(t,n);return c||(t[1]&&_(n.x,n.y,t[0],t[1])<=L?{hit:"body"}:t[1]&&Ht(n,Yo(e,e.style,t[0],t[1]).box)?{hit:"body"}:null)}case"price-note":return Xl(e,t,n,r);case"callout":{const c=qo(e,t[1]);return Math.hypot(t[0].x-n.x,t[0].y-n.y)<=rt?{hit:"handle",handleIndex:0}:l&&c.wrap!=null&&Math.hypot(t[1].x+c.wrap/2+10-n.x,t[1].y-n.y)<=rt?{hit:"handle",handleIndex:1}:Ht(n,{left:c.x,top:c.y,width:c.w,height:c.h})?{hit:"body"}:null}case"regression-trend":return Gl(e,t,n,o,r);case"fixed-range-volume-profile":{const c=W(t,n);if(c)return c;const f=Mo(e,t,r);return f&&n.x>=f.left&&n.x<=f.right&&n.y>=f.top&&n.y<=f.bottom?{hit:"body"}:null}case"anchored-volume-profile":{const c=W([t[0]],n);if(c)return c;const f=wo(e,t,r);return f&&n.x>=f.left&&n.x<=f.right&&n.y>=f.top&&n.y<=f.bottom?{hit:"body"}:null}case"anchored-vwap":return jl(e,t,n,r);case"abcd-pattern":case"xabcd-pattern":case"cypher-pattern":case"head-and-shoulders":case"triangle-pattern":case"three-drives-pattern":case"elliott-impulse":case"elliott-correction":case"elliott-triangle":case"elliott-double-combo":case"elliott-triple-combo":case"polyline":case"path":return Nl(e,t,n);case"brush":case"highlighter":return Yl(t,n,s);case"parallel-channel":return vl(e,t,n,s,o,i);case"disjoint-channel":return Ll(e,t,n,s,o,i);case"flat-top-bottom":return Sl(e,t,n,s,o,i);case"pitchfork":case"schiff-pitchfork":case"modified-schiff-pitchfork":case"inside-pitchfork":return gl(e,t,n,o,i);case"fib-channel":return Cl(e,t,n,s,o,i);case"rotated-rectangle":return Il(e,t,n);case"trend-based-fib-extension":return ml(e,t,n);case"fib-retracement":return yl(e,t,n);case"rectangle":{const c=(r==null?void 0:r.timeAxis().width)||o,f=Mn(t,n,!0);if(f)return f;if(e.style.extendLeft||e.style.extendRight){const u=Math.min(t[0].y,t[1].y),d=Math.max(t[0].y,t[1].y),x=e.style.extendLeft?0:Math.min(t[0].x,t[1].x),p=e.style.extendRight?c:Math.max(t[0].x,t[1].x);if(n.x>=x&&n.x<=p&&n.y>=u-L&&n.y<=d+L)return{hit:"body"}}const h=(a=fo(e,t,c))==null?void 0:a.box;return h&&n.x>=h.left&&n.x<=h.left+h.width&&n.y>=h.top&&n.y<=h.top+h.height?{hit:"body"}:null}case"circle":return Al(t,n);case"ellipse":return Tl(t,n);case"price-range":return $l(e,t,n,o);case"date-range":return ni(t,n);case"date-and-price-range":return ni(t,n);case"triangle":return Bl(t,n)}}function Ql(e){const t=e.replace("#",""),n=t.length===3?t.split("").map(o=>o+o).join(""):t;return[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}function at(e){if(/^rgba?\(/.test(e)){const t=e.match(/[\d.]+/g);if(t&&t.length>=3)return{hex:("#"+t.slice(0,3).map(o=>Number(o).toString(16).padStart(2,"0")).join("")).toUpperCase(),opacity:t[3]!=null?Math.round(Number(t[3])*100):100}}return{hex:(e||"#000000").toUpperCase(),opacity:100}}function kt(e,t){if(t>=100)return e;const[n,o,i]=Ql(e);return`rgba(${n}, ${o}, ${i}, ${(t/100).toFixed(2)})`}function Jl(e){let t=0,n=0,o=0;const i=e.match(/^#([0-9a-f]{6})/i);if(i){const r=parseInt(i[1],16);t=r>>16,n=r>>8&255,o=r&255}else{const r=e.match(/rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/i);r&&(t=+r[1],n=+r[2],o=+r[3])}return .199*t+.687*n+.114*o>=150?"#000000":"#ffffff"}const te=(e,t)=>({...e,back:t,color:Jl(t)});function si(e,t,n){const o=e.style,i=[],r=[];if((e.kind==="vertical-line"||e.kind==="cross-line")&&o.showTime&&e.points[0]&&r.push(te({time:e.points[0].time},at(o.color).hex)),e.kind==="long-position"||e.kind==="short-position"){if(o.showPriceLabels!==!1){const l=no(e,t,n);if(l){const s=e.points[0].price,a=e.kind==="long-position"?1:-1;i.push(te({price:s},"#787b86"),te({price:s+a*l.profit},"#089981"),te({price:s-a*l.stop},"#f23645"))}}return{price:i,time:r}}if(e.kind==="anchored-vwap"){if(o.vwapPriceLabel!==!1){const l=zr(e,n);l!=null&&i.push(te({price:l},at(o.color).hex))}return{price:i,time:r}}if(o.showPriceLabels&&e.kind!=="vertical-line")for(const l of e.points)i.push(te({price:l.price},at(o.color).hex));return{price:i,time:r}}let Ln=null,Fe=null;function ci(){return Ln||(Ln=document.createElement("canvas").getContext("2d")),Ln}function ft(e,t){const n=ci();return n?(Fe??(Fe=getComputedStyle(document.body).fontFamily),n.font=`${t}px ${Fe}`,n.measureText(e).width):e.length*t*.6}function ts(e,t){const n=ci();return n?(Fe??(Fe=getComputedStyle(document.body).fontFamily),n.font=`bold ${t}px ${Fe}`,n.measureText(e).width):e.length*t*.65}function pt(e,t){const n=Math.abs(e).toFixed(t);return e<0?`−${n}`:n}function Sn(e){const t=e<0;let n=Math.abs(Math.round(e));const o=Math.floor(n/86400);n-=o*86400;const i=Math.floor(n/3600);n-=i*3600;const r=Math.floor(n/60);n-=r*60;const l=[];o&&l.push(`${o.toLocaleString("en-US")}d`),i&&l.push(`${i}h`),r&&l.push(`${r}m`),n&&l.push(`${n}s`);const s=l.join(" ");return t?`-${s}`:s}function es(e){const t=[[1e9," B"],[1e6," M"],[1e3," K"]];for(const[n,o]of t)if(Math.abs(e)>=n)return`${Number((e/n).toFixed(2))}${o}`;return String(Math.round(e))}function ye(e){return e.length%2===1&&e[Math.floor(e.length/2)].trim()!==""}function ai(e,t,n,o,i,r,l,s,a,c,f){const h=Math.max(0,...n.map(m=>$t(m,o,c,f)))+2*l,u=n.length*i+2*r,d=a==="left"?e.x:a==="right"?e.x-h:e.x-h/2,x=s==="bottom"?e.y-u:s==="top"?e.y:e.y-u/2,p=t*Math.PI/180,y=Math.cos(p),b=Math.sin(p),g=(m,w)=>({x:(m-e.x)*y-(w-e.y)*b+e.x,y:(m-e.x)*b+(w-e.y)*y+e.y});return[g(d,x),g(d+h,x),g(d+h,x+u),g(d,x+u)]}function U(e,t,n,o){return{t:"group",transform:e.rotate,inert:!0,items:e.lines.map((i,r)=>({t:"text",x:e.tx,y:e.y0+r*e.lineStep,text:i,size:e.fs,anchor:e.anchor,baseline:"central",weight:n?700:400,fontStyle:o?"italic":"normal",fill:t,pre:!0}))}}function fi(e,t,n,o,i,r){const l=i.text??"";if(l==="")return null;const s=i.vertLabelsAlign??"bottom",a=i.horzLabelsAlign??"left",c=s==="middle";let f,h;s==="bottom"?[f,h]=e.y<n.y?[e,t]:[n,o]:s==="top"?[f,h]=e.y>n.y?[e,t]:[n,o]:[f,h]=[{x:(e.x+n.x)/2,y:(e.y+n.y)/2},{x:(t.x+o.x)/2,y:(t.y+o.y)/2}];const u=f.x<h.x?f:h,d=u===f?h:f,x=a==="left"?u:a==="right"?d:{x:(u.x+d.x)/2,y:(u.y+d.y)/2},p=Math.atan((u.y-d.y)/(u.x-d.x)),y=Number.isNaN(p)?0:p*180/Math.PI,b=i.fontSize??14,g=b/3,m=r??(c?g:0),w=l.split(`
5
+ `),M=Math.ceil(b),k=w.length*M+2*g,v=s==="bottom"?x.y-k:s==="top"?x.y:x.y-k/2,C=a==="left"?x.x+m:a==="right"?x.x-m:x.x,T=a==="left"?"start":a==="right"?"end":"middle";return{u:x,angle:y,fs:b,lines:w,lineH:M,top:v+g,x:C,anchor:T,vert:s,horz:a,padV:g,padH:m}}function Oe(e,t,n,o,i,r){const l=fi(e,t,n,o,i,r);return l?[{t:"group",transform:`rotate(${l.angle} ${l.u.x} ${l.u.y})`,inert:!0,items:l.lines.map((s,a)=>({t:"text",x:l.x,y:l.top+a*l.lineH,text:s,size:l.fs,anchor:l.anchor,baseline:"hanging",weight:i.bold?700:400,fontStyle:i.italic?"italic":"normal",fill:i.textColor??i.color,pre:!0}))}]:[]}function hi(e,t,n,o,i,r,l){const s=fi(e,t,n,o,i,r);return!s||s.vert!=="middle"||!l&&!ye(s.lines)?null:ai(s.u,s.angle,s.lines,s.fs,s.lineH,s.padV,s.padH,s.vert,s.horz,!!i.bold,!!i.italic)}const Nt={rectangle:[4,5,6,7],disjointChannel:[2],parallelChannel:[4,5],position:[1,2,3],single:[0]},ns=50,os={price:"M3 2h11v1H3V2Zm5.5 1.8.35.35 2 2 .36.35-.71.7-.35-.35L9 5.71v6.58l1.15-1.14.35-.36.7.71-.35.35-2 2-.35.36-.35-.36-2-2-.36-.35.71-.7.35.35L8 12.29V5.71L6.85 6.85l-.35.36-.7-.71.35-.35 2-2 .35-.36ZM3.5 16H3v-1h11v1H3.5Z",bars:"M2 3v2H1v9h1v2h1v-2h1V5H3V3H2Zm6.2 4.5-.35.35L6.71 9h4.58l-1.14-1.15-.36-.35.71-.7.35.35 2 2 .36.35-.36.35-2 2-.35.36-.7-.71.35-.35L11.29 10H6.71l1.14 1.15.36.35-.71.7-.35-.35-2-2-.36-.35.36-.35 2-2 .35-.36.7.71ZM3 6H2v7h1V6Zm12-2.5V3h1v2h1v9h-1v2h-1v-2h-1V5h1V3.5ZM15 6h1v7h-1V6Z",angle:"M8.55 2.78 2.7 15H15v-1h-4.01a6.2 6.2 0 0 0-1.36-3.95 7.94 7.94 0 0 0-2.57-1.83l2.4-5-.91-.44ZM6.63 9.12 4.29 14H10a5.18 5.18 0 0 0-1.12-3.3 6.93 6.93 0 0 0-2.24-1.58Z"};function ui(e,t,n,o,i,r){const l=e.points[0],s=e.points[1];if(!l||!s)return[];const a=[],c=s.price-l.price,f=(i==null?void 0:i.pipSize())??.01,h=Math.max(0,Math.min(8,Math.round(-Math.log10(f))));if(o.showPriceRange||o.showPercentPriceRange||o.showPipsPriceRange){const x=[];if(o.showPriceRange||o.showPercentPriceRange){const p=[];if(o.showPriceRange&&p.push(pt(c,h)),o.showPercentPriceRange){const y=l.price!==0?`${pt(c/Math.abs(l.price)*100,2)}%`:"";y&&p.push(o.showPriceRange?`(${y})`:y)}x.push(p.join(" "))}o.showPipsPriceRange&&x.push(pt(Math.round(c/f),0)),a.push({icon:"price",text:x.join(", ")})}const u=r&&!!o.showDateTimeRange,d=r&&!!o.showDistance;if(o.showBarsRange||u||d){let x="";if(o.showBarsRange){const p=i?i.timeToBarIndex(l.time):null,y=i?i.timeToBarIndex(s.time):null;x+=`${p!=null&&y!=null?y-p:0} bars`}if(u){const p=N(l.time),y=N(s.time),b=p!=null&&y!=null?Sn(y-p):"";b&&(x+=o.showBarsRange?` (${b})`:b)}d&&(x+=(x?", ":"")+`distance: ${Math.round(Math.hypot(n.x-t.x,n.y-t.y))} px`),x&&a.push({icon:"bars",text:x})}if(r&&o.showAngle&&Math.hypot(n.x-t.x,n.y-t.y)>0){const x=Math.atan2(-(n.y-t.y),n.x-t.x)*180/Math.PI;a.push({icon:"angle",text:`${Math.round(x*100)/100}º`})}return a}function di(e,t,n,o,i,r){const l=t.x-e.x,s=t.y-e.y;let a=0,c=1;const f=(h,u)=>{if(h===0)return u>=0;const d=u/h;if(h<0){if(d>c)return!1;d>a&&(a=d)}else{if(d<a)return!1;d<c&&(c=d)}return!0};return f(-l,e.x-n)&&f(l,n+i-e.x)&&f(-s,e.y-o)&&f(s,o+r-e.y)&&a<=c}function is(e,t,n,o){return e.x===t.x&&e.y===t.y?e.x>=0&&e.x<=n&&e.y>=0&&e.y<=o:di(e,t,0,0,n,o)}function xi(e,t,n,o,i,r,l){if(!i||n.length===0)return[];const s=o===3;if(s&&!is(e,t,r,l))return[];const a=12,c=18,f=8,h=12;let d=Math.max(...n.map(v=>ft(v.text,a)))+h*2+c+h;Math.round(d)%2!==0&&(d=Math.round(d)+1);const x=c*n.length+f*(n.length-1)+h*2,p={x:(e.x+t.x)/2,y:(e.y+t.y)/2},y=o===0?e:o===2?t:p,b=t.y<e.y&&t.x<e.x||t.y>e.y&&t.x>e.x;let g=y.x+12,m=b?y.y-12-x:y.y+12;s&&(e.x!==t.x||e.y!==t.y)&&(g<0?g=0:g+d>r&&(g=r-d),m<0?m=0:m+x>l&&(m=l-x),di(e,t,g,m,d,x)&&(m=b?p.y+12:p.y-12-x,g=Math.min(p.x,r)-d));const w=Math.floor(g),M=Math.floor(m),k=[{t:"rect",x:w,y:M,w:d,h:x,rx:4,ry:4,fill:"#464646",fillOpacity:230/255}];return n.forEach((v,C)=>{const T=M+h+C*(c+f);k.push({t:"path",d:os[v.icon],transform:`translate(${w+h}, ${T})`,fill:"#F9F9F9",fillRule:"evenodd"}),k.push({t:"text",x:w+h+c+h,y:T+c/2,text:v.text,size:a,fill:"#FFFFFF",baseline:"central"})}),[{t:"group",inert:!0,items:k}]}function De(e,t,n){const o=Math.hypot(t.x-e.x,t.y-e.y)||1,i=(t.x-e.x)/o,r=(t.y-e.y)/o,l=5*n,s=t.x-i*l,a=t.y-r*l;return`M ${s-r*l} ${a+i*l} L ${t.x} ${t.y} L ${s+r*l} ${a-i*l}`}function Et(e,t,n){return Math.hypot(t.x-e.x,t.y-e.y)<1?[]:[{t:"path",d:De(e,t,n.width),fill:"none",stroke:n.color,strokeWidth:n.width,dash:P(n),join:"round",cap:(n.lineStyle??"solid")==="solid"?"round":"butt",inert:!0}]}function yi(e){return{...e,horzLabelsAlign:e.horzLabelsAlign??"center",vertLabelsAlign:e.vertLabelsAlign??"bottom"}}function Cn(e,t,n){return hi(e,t,e,t,yi(n),(n.fontSize??14)/3,!1)}function ee(e,t){return t&&t.length?{items:[{t:"clip",name:e,polys:[t]}],clip:e}:{items:[],clip:void 0}}function Tn(e,t,n,o,i,r,l,s,a){if(!e.points[0]||!e.points[1])return[];const c=ui(e,t,n,o,l,!0),f=o.statsPosition??(e.kind==="info-line"?1:2),h=s||!!o.showStats,u=[{t:"group",clip:a,items:[...o.leftEnd===1?Et(n,t,o):[],...o.rightEnd===1?Et(t,n,o):[]]}];return o.showMiddlePoint&&s&&u.push({t:"anchors",pts:[{x:(t.x+n.x)/2,y:(t.y+n.y)/2}]}),u.push(...Oe(t,n,t,n,yi(o),(o.fontSize??14)/3)),u.push(...xi(t,n,c,f,h,i,r)),u}function rs(e,t,n){if(!n.text)return null;const o=n.horzLabelsAlign??"center";return G({x:o==="left"?3:o==="right"?t:t/2,y:e,text:n.text,fs:n.fontSize??12,bold:n.bold,italic:n.italic,vert:n.vertLabelsAlign??"middle",horz:o,offsetX:o==="right"?3:0})}function ls(e,t,n){if(!n.text)return null;const o=n.horzLabelsAlign??"center",i={y:e.y,text:n.text,fs:n.fontSize??12,bold:n.bold,italic:n.italic,vert:n.vertLabelsAlign??"top",horz:o};if(o==="right"){const r=G({...i,x:0}).box.width;return e.x+r+3>=t?G({...i,x:e.x+r+3}):G({...i,x:t,offsetX:3})}return G({...i,x:o==="center"?(e.x+t)/2:e.x})}function An(e,t){return e&&t==="middle"&&ye(e.lines)?e.poly:null}const vt=(e,t)=>({t:"hit",a:e,b:t,width:12}),pi=e=>(e.lineStyle??"solid")==="solid"?"round":"butt";function ss(e,t,n,o){const i=e[0],r=rs(i.y,n,o),l=ee("cut",An(r,o.vertLabelsAlign??"middle"));return[vt({x:0,y:i.y},{x:n,y:i.y}),...l.items,{t:"line",a:{x:0,y:i.y},b:{x:n,y:i.y},stroke:o.color,strokeWidth:o.width,dash:P(o),clip:l.clip},...r?[U(r,o.textColor??o.color,o.bold,o.italic)]:[],...t?[{t:"anchors",pts:[{x:.9*n,y:i.y}],squares:Nt.single}]:[]]}function cs(e,t,n,o){var h;const i=e[0],r=o.vertLabelsAlign??"middle",l=o.horzLabelsAlign??"center",s=o.textOrientation==="horizontal",a=r==="top"?n:r==="middle"?n/2:0,c=o.text?G(s?{x:i.x,y:a,text:o.text,fs:o.fontSize??14,bold:o.bold,italic:o.italic,horz:l==="left"?"right":l==="right"?"left":"center",vert:r==="top"?"bottom":r==="bottom"?"top":"middle",offsetX:5}:{x:i.x,y:a,text:o.text,fs:o.fontSize??14,bold:o.bold,italic:o.italic,horz:r==="top"?"left":r==="middle"?"center":"right",vert:l==="left"?"bottom":l==="right"?"top":"middle",angle:-Math.PI/2}):null,f=ee("cut",s?c&&((h=o.text)!=null&&h.trim())?c.poly:null:An(c,r));return[vt({x:i.x,y:0},{x:i.x,y:n}),...f.items,{t:"line",a:{x:i.x,y:0},b:{x:i.x,y:n},stroke:o.color,strokeWidth:o.width,dash:P(o),clip:f.clip},...c?[U(c,o.textColor??o.color,o.bold,o.italic)]:[],...t?[{t:"anchors",pts:[{x:i.x,y:.9*n}],squares:Nt.single}]:[]]}function as(e,t,n,o,i){const r=e[0],l=P(i);return[vt({x:0,y:r.y},{x:n,y:r.y}),vt({x:r.x,y:0},{x:r.x,y:o}),{t:"line",a:{x:0,y:r.y},b:{x:n,y:r.y},stroke:i.color,strokeWidth:i.width,dash:l},{t:"line",a:{x:r.x,y:0},b:{x:r.x,y:o},stroke:i.color,strokeWidth:i.width,dash:l},...t?[{t:"anchors",pts:[r]}]:[]]}function bi(e,t,n,o,i,r,l,s){const[a,c]=t,f=ee("cut",Cn(a,c,r));return[vt(a,c),...f.items,{t:"line",a,b:c,stroke:r.color,strokeWidth:r.width,dash:P(r),cap:pi(r),clip:f.clip},...Tn(e,a,c,r,o,i,l,s,f.clip),...n?[{t:"anchors",pts:t}]:[]]}function _e(e,t,n,o,i,r,l,s,a,c){const[f,h]=t,u=h.x-f.x,d=h.y-f.y,x=Math.hypot(u,d)||1,p=u/x,y=d/x,b=(o+i)*2,g=l?{x:f.x-p*b,y:f.y-y*b}:f,m=s?{x:h.x+p*b,y:h.y+y*b}:h,w=ee("cut",Cn(f,h,r));return[vt(f,h),...w.items,{t:"line",a:g,b:m,stroke:r.color,strokeWidth:r.width,dash:P(r),clip:w.clip},...Tn(e,f,h,r,o,i,a,c,w.clip),...n?[{t:"anchors",pts:t}]:[]]}function fs(e,t,n,o){const i=e[0],r=ls(i,n,o),l=ee("cut",An(r,o.vertLabelsAlign??"top"));return[vt(i,{x:n,y:i.y}),...l.items,{t:"line",a:i,b:{x:n,y:i.y},stroke:o.color,strokeWidth:o.width,dash:P(o),clip:l.clip},...r?[U(r,o.textColor??o.color,o.bold,o.italic)]:[],...t?[{t:"anchors",pts:[i]}]:[]]}function hs(e,t,n,o,i,r,l,s){if(e.kind!=="info-line")return[];const[a,c]=t,f=ee("cut",Cn(a,c,r));return[vt(a,c),...f.items,{t:"line",a,b:c,stroke:r.color,strokeWidth:r.width,dash:P(r),cap:"round",clip:f.clip},...Tn(e,a,c,r,o,i,l,s,f.clip),...n?[{t:"anchors",pts:t}]:[]]}function us(e,t,n,o,i,r,l,s){const[a,c]=t,f=c.x-a.x,h=c.y-a.y,u=r.angle??Math.atan2(-h,f)*180/Math.PI,d=u*Math.PI/180,x=ns,p={x:a.x+x*Math.cos(d),y:a.y-x*Math.sin(d)},y=`M ${a.x} ${a.y} L ${a.x+x} ${a.y} A ${x} ${x} 0 ${Math.abs(d)>Math.PI?1:0} ${d>0?0:1} ${p.x} ${p.y}`,b=r.fontSize??12,g=Math.hypot(f,h)||1,m=(o+i)*2,w=r.extendLeft?{x:a.x-f/g*m,y:a.y-h/g*m}:a,M=r.extendRight?{x:c.x+f/g*m,y:c.y+h/g*m}:c;return[vt(a,c),{t:"line",a:w,b:M,stroke:r.color,strokeWidth:r.width,dash:P(r),cap:pi(r)},...r.showMiddlePoint&&s?[{t:"anchors",pts:[{x:(a.x+c.x)/2,y:(a.y+c.y)/2}]}]:[],{t:"path",d:y,fill:"none",stroke:r.color,strokeWidth:1,dash:"1 2",inert:!0},{t:"text",x:a.x+x+5+b/3,y:a.y,text:`${Math.round(u*100)/100}º`,size:b,anchor:"start",baseline:"central",weight:r.bold?700:400,fontStyle:r.italic?"italic":"normal",fill:r.color,inert:!0},...xi(a,c,ui(e,a,c,r,l,!1),r.statsPosition??2,s||!!r.showStats,o,i),...n?[{t:"anchors",pts:t}]:[]]}function Lt(e,t){return(e.levels??t).filter(n=>n.visible).slice().sort((n,o)=>n.coeff-o.coeff)}function Z(e){return e.fillBackground===!1?0:Math.max(0,Math.min(1,(100-(e.transparency??80))/100))}function St(e,t){return e.width??t.width}function Ct(e,t){return e.style?P({...t,lineStyle:e.style}):P(t)}function He(e,t,n,o,i){const r=t.x-e.x,l=t.y-e.y,s=Math.hypot(r,l)||1;return{l:n?{x:e.x-r/s*i,y:e.y-l/s*i}:e,r:o?{x:t.x+r/s*i,y:t.y+l/s*i}:t}}function ds(e){const[t,n,o]=e,i=n.x-t.x===0?0:(o.x-t.x)/(n.x-t.x),r=o.y-(t.y+(n.y-t.y)*i),l={x:(t.x+n.x)/2,y:(t.y+n.y)/2};return{anchors:[t,n,{x:t.x,y:t.y+r},{x:n.x,y:n.y+r},{x:l.x,y:l.y+r},l],dy:r}}function xs(e){const[t,n,o]=e,i={x:n.x,y:o.y},r={x:t.x,y:o.y+(n.y-t.y)};return{anchors:[t,n,i,r],P:i,A:r}}function ys(e,t,n,o,i){const r=(i.vertLabelsAlign??"bottom")==="middle",l=r?0:o.length>0?o[0].coeff:0,s=r?1:o.length>0?o[o.length-1].coeff:0;return{e:{x:e.x,y:e.y+n*l},t:{x:t.x,y:t.y+n*l},i:{x:e.x,y:e.y+n*s},n:{x:t.x,y:t.y+n*s}}}function ps(e,t,n,o,i){const[r,l]=e,{anchors:s,dy:a}=ds(e),c=(n.levels??$e).filter(g=>g.visible),f=(o+i)*2,h=g=>He({x:r.x,y:r.y+a*g},{x:l.x,y:l.y+a*g},!!n.extendLeft,!!n.extendRight,f),u=Z(n),d=n.backgroundColor??n.color,x=ys(r,l,a,c,n),p=hi(x.e,x.t,x.i,x.n,n,void 0,!0),y=p&&p.length?"cut":void 0,b=[];y&&b.push({t:"clip",name:y,polys:[p]}),c.slice(1).forEach((g,m)=>{const w=h(c[m].coeff),M=h(g.coeff);b.push({t:"polygon",pts:[w.l,w.r,M.r,M.l],fill:d,fillOpacity:u,stroke:"transparent"})});for(const g of c){const m=h(g.coeff);b.push({t:"hit",a:m.l,b:m.r,width:12}),b.push({t:"line",a:m.l,b:m.r,stroke:g.color,strokeWidth:St(g,n),dash:Ct(g,n),clip:y})}return b.push(...Oe(x.e,x.t,x.i,x.n,n)),t&&b.push({t:"anchors",pts:s,squares:Nt.parallelChannel}),b}function gi(e,t,n,o,i){const r=(s,a,c)=>G({x:s.x,y:s.y,text:c,fs:i.priceLabelFontSize??12,bold:i.priceLabelBold,italic:i.priceLabelItalic,vert:"middle",horz:s.x>a.x?"left":"right",offsetX:6,padH:0,padV:0}),l=i.priceLabelTextColor??i.color;return[U(r(e,t,n),l,i.priceLabelBold,i.priceLabelItalic),U(r(t,e,o),l,i.priceLabelBold,i.priceLabelItalic)]}function mi(e,t,n,o,i,r,l,s,a,c,f){var m,w;const h=(a+c)*2,u=He(t,n,!!s.extendLeft,!!s.extendRight,h),d=He(o,i,!!s.extendLeft,!!s.extendRight,h),x=P(s),p=(s.lineStyle??"solid")==="solid"?"round":"butt",y=Math.max(0,Math.min(8,Math.round(-Math.log10((f==null?void 0:f.pipSize())??.01)))),b=M=>M.toFixed(y),g=[];return s.fillBackground!==!1&&g.push({t:"polygon",pts:[u.l,u.r,d.r,d.l],fill:s.backgroundColor??s.color,fillOpacity:Z(s),stroke:"transparent"}),g.push({t:"hit",a:t,b:n,width:12},{t:"hit",a:o,b:i,width:12},{t:"line",a:u.l,b:u.r,stroke:s.color,strokeWidth:s.width,dash:x,cap:p},{t:"line",a:d.l,b:d.r,stroke:s.color,strokeWidth:s.width,dash:x,cap:p}),s.leftEnd===1&&g.push(...Et(n,t,s),...Et(i,o,s)),s.rightEnd===1&&g.push(...Et(t,n,s),...Et(o,i,s)),s.showPrices&&(g.push(...gi(t,n,b(((m=e.points[0])==null?void 0:m.price)??0),b(((w=e.points[1])==null?void 0:w.price)??0),s)),g.push(...gi(i,o,b(r),b(l),s))),g}function bs(e,t,n,o,i,r,l){var d,x;const[s,a]=t,{anchors:c,P:f,A:h}=xs(t),u=((d=e.points[2])==null?void 0:d.price)??e.points[0].price;return[...mi(e,s,a,h,f,u,u+((((x=e.points[1])==null?void 0:x.price)??0)-e.points[0].price),o,i,r,l),...Oe(s,a,h,f,o),...n?[{t:"anchors",pts:c,squares:Nt.disjointChannel}]:[]]}function gs(e,t,n,o,i,r,l){var d;const[s,a,c]=t,f={x:s.x,y:c.y},h={x:a.x,y:c.y},u=((d=e.points[2])==null?void 0:d.price)??e.points[0].price;return[...mi(e,s,a,f,h,u,u,o,i,r,l),...Oe(s,a,f,h,o),...n?[{t:"anchors",pts:t}]:[]]}function $n(e,t){return t?`${(100*e).toFixed(2)}%`:String(Math.round(e*1e4)/1e4)}function Ne(e){if(!e.text)return null;let t,n;return e.horz==="left"?(t=e.extendLeft?0:e.left,n=e.extendLeft?"left":"right"):e.horz==="right"?(t=e.extendRight?e.paneW:e.right,n=e.extendRight?"right":"left"):(t=((e.extendLeft?0:e.left)+(e.extendRight?e.paneW:e.right))/2,n="center"),G({x:t,y:e.y,text:e.text,fs:e.fs,vert:e.vert,horz:n,offsetX:4})}function Pt(e){return e.toFixed(3).replace(/0+$/,"").replace(/\.$/,"")||"0"}const ct=(e,t)=>e?[{t:"anchors",pts:t}]:[],In=e=>Math.max(0,Math.min(8,Math.round(-Math.log10((e==null?void 0:e.pipSize())??.01))));function Bn(e,t){const n=t.filter(o=>!!o&&o.length>0);return n.length?{items:[{t:"clip",name:e,polys:n}],clip:e}:{items:[],clip:void 0}}function Yt(e,t,n,o=!1){const i=n.fibTrendLine??(o?xr:dr);return i.visible?[{t:"line",a:e,b:t,stroke:i.color,strokeWidth:i.width,dash:P({...n,lineStyle:i.style}),cap:i.style==="solid"?"round":"butt",inert:!0}]:[]}function wi(e,t,n,o,i,r,l,s,a){const c={y:n,left:o,right:i,extendLeft:!!s.extendLeft,extendRight:!!s.extendRight,paneW:a,fs:s.labelFontSize??12},f=s.showCoeffs!==!1,h=s.showPrices!==!1;let u="";f&&(u+=$n(t.coeff,!!s.fibLevelsAsPercents)),h&&(u+=` (${r.toFixed(l)})`);const d=Ne({...c,text:u,horz:s.horzLabelsAlign??"left",vert:s.vertLabelsAlign??"middle"}),x=s.showText!==!1&&t.text?Ne({...c,text:t.text,horz:s.horzTextAlign??"center",vert:s.vertTextAlign??"middle"}):null,p=Bn(e,[(d==null?void 0:d.poly)??null,x==null?void 0:x.poly]);return[{t:"hit",a:{x:o,y:n},b:{x:i,y:n},width:10},...p.items,{t:"line",a:{x:o,y:n},b:{x:i,y:n},stroke:t.color,strokeWidth:St(t,s),dash:Ct(t,s),clip:p.clip},...d?[U(d,t.color)]:[],...x?[U(x,t.color)]:[]]}function Mi(e,t,n,o,i){return i>0?e.slice(1).map((r,l)=>{const s=t(e[l].coeff),a=t(r.coeff);return{t:"rect",x:n,y:Math.min(s,a),w:Math.max(1,o-n),h:Math.abs(a-s),fill:r.color,fillOpacity:i,stroke:"none",inert:!0}}):[]}function ms(e,t,n,o,i,r){if(e.kind!=="fib-retracement")return[];const[l,s]=t,a=e.points[0].price,c=e.points[1].price,f=i.extendLeft?0:Math.min(l.x,s.x),h=i.extendRight?o:Math.max(l.x,s.x),u=Lt(i,Ft),d=!!i.fibLevelsBasedOnLogScale&&!!(r!=null&&r.isLog())&&a>0&&c>0,x=g=>{const m=i.reverse?a:c,w=i.reverse?c:a;return d?Math.exp(Math.log(m)+g*(Math.log(w)-Math.log(m))):m+g*(w-m)},p=g=>i.reverse?l.y+(s.y-l.y)*g:s.y+(l.y-s.y)*g,y=g=>d?p(g):(r==null?void 0:r.priceToY(x(g)))??p(g),b=In(r);return[...Mi(u,y,f,h,Z(i)),...u.flatMap((g,m)=>wi(`l${m}`,g,y(g.coeff),f,h,x(g.coeff),b,i,o)),...Yt(l,s,i),...ct(n,t)]}function ws(e,t,n,o,i,r){if(e.kind!=="trend-based-fib-extension")return[];const[,l,s]=t,a=e.points[0].price,c=e.points[1].price,f=e.points[2].price,h=i.reverse?a-c:c-a,u=i.reverse?t[0].y-t[1].y:t[1].y-t[0].y,d=Lt(i,Ft),x=i.extendLeft?0:Math.min(l.x,s.x),p=i.extendRight?o:Math.max(l.x,s.x),y=!!i.fibLevelsBasedOnLogScale&&!!(r!=null&&r.isLog())&&a>0&&c>0&&f>0,b=M=>{if(!y)return f+h*M;const k=i.reverse?Math.log(a)-Math.log(c):Math.log(c)-Math.log(a);return Math.exp(Math.log(f)+M*k)},g=M=>s.y+u*M,m=M=>y?g(M):(r==null?void 0:r.priceToY(b(M)))??g(M),w=In(r);return[...Mi(d,m,x,p,Z(i)),...d.flatMap((M,k)=>wi(`l${k}`,M,m(M.coeff),x,p,b(M.coeff),w,i,o)),...Yt(t[0],t[1],i),...Yt(t[1],t[2],i),...ct(n,t)]}function Ms(e,t,n,o,i,r,l){if(e.kind!=="fib-channel")return[];const[s,a,c]=t,f=c.x-s.x,h=c.y-s.y,u=(r+l)*2,d=M=>({l:{x:s.x+f*M,y:s.y+h*M},r:{x:a.x+f*M,y:a.y+h*M}}),x=M=>{const k=d(M);return He(k.l,k.r,!!o.extendLeft,!!o.extendRight,u)},p=Lt(o,Ft),y=Z(o),b=In(i),g=(M,k)=>(i==null?void 0:i.yToPrice(k))??e.points[0].price+(e.points[2].price-e.points[0].price)*M,m=(M,k)=>{const v=o.showCoeffs!==!1,C=o.showPrices!==!1;if(!v&&!C)return null;let T="";v&&(T+=o.fibLevelsAsPercents?`${(100*M.coeff).toFixed(2)}%`:Pt(M.coeff)),C&&(T+=` (${g(M.coeff,k.l.y).toFixed(b)})`);const F=o.horzLabelsAlign??"left",A=F==="left"?k.l:F==="right"?k.r:{x:(k.l.x+k.r.x)/2,y:(k.l.y+k.r.y)/2};return G({x:A.x,y:A.y,text:T,fs:o.labelFontSize??12,vert:o.vertLabelsAlign??"middle",horz:F==="left"?"right":F==="right"?"left":"center",offsetX:4})},w=[];return y>0&&p.slice(1).forEach((M,k)=>{const v=x(p[k].coeff),C=x(M.coeff);w.push({t:"polygon",pts:[v.l,v.r,C.r,C.l],fill:p[k].color,fillOpacity:y,stroke:"none",inert:!0})}),p.forEach((M,k)=>{const v=d(M.coeff),C=x(M.coeff),T=m(M,v),F=Bn(`l${k}`,[T?T.poly:null]);w.push({t:"hit",a:v.l,b:v.r,width:12},...F.items),w.push({t:"line",a:C.l,b:C.r,stroke:M.color,strokeWidth:St(M,o),dash:Ct(M,o),clip:F.clip}),T&&w.push(U(T,M.color))}),w.push(...ct(n,t)),w}function ki(e,t,n,o,i,r,l){const s=Bn(e,[l]);return[{t:"hit",a:{x:n,y:0},b:{x:n,y:o},width:8},...s.items,{t:"line",a:{x:n,y:0},b:{x:n,y:o},stroke:t.color,strokeWidth:St(t,i),dash:Ct(t,i),clip:s.clip},...r?[U(r,t.color)]:[]]}function ks(e,t,n,o,i,r){const[l,s,a]=t,c=i.fibTrendLine??en,f=P({...i,lineStyle:c.style,width:c.width}),h=so(e,t,r,Lt(i,tn)),u=Z(i),d=i.vertLabelsAlign??"bottom",x=i.horzLabelsAlign??"right",p=x==="left"?"right":x==="right"?"left":"center",y=(g,m)=>i.showLabels===!1?null:G({x:g,y:d==="top"?0:d==="middle"?.5*o:o,text:String(m),fs:12,vert:d,horz:p,offsetX:2}),b=[];return c.visible&&(b.push({t:"line",a:l,b:s,stroke:c.color,strokeWidth:c.width,dash:f}),a&&b.push({t:"line",a:s,b:a,stroke:c.color,strokeWidth:c.width,dash:f})),u>0&&h.slice(1).forEach((g,m)=>{const w=h[m].x;b.push({t:"rect",x:Math.min(w,g.x),y:0,w:Math.max(1,Math.abs(g.x-w)),h:o,fill:g.color,fillOpacity:u,stroke:"none",inert:!0})}),h.forEach((g,m)=>{const w=y(g.x,g.coeff);b.push(...ki(`l${m}`,g,g.x,o,i,w,w&&x==="center"?w.poly:null))}),b.push(...ct(n,t)),b}function vs(e,t,n,o){const[i,r]=e,l=o.vertLabelsAlign??"bottom",s=o.horzLabelsAlign??"right",a=s==="left"?"right":s==="right"?"left":"center",c=(x,p)=>o.showLabels===!1?null:G({x,y:l==="top"?0:l==="middle"?.5*n:n,text:String(p),fs:12,vert:l,horz:a,offsetX:2}),f=r.x-i.x,h=Lt(o,ln),u=Z(o),d=[{t:"line",a:i,b:r,stroke:"#808080",strokeWidth:1,dash:"6 4"}];return u>0&&h.slice(1).forEach((x,p)=>{const y=i.x+f*h[p].coeff,b=i.x+f*x.coeff;d.push({t:"rect",x:Math.min(y,b),y:0,w:Math.max(1,Math.abs(b-y)),h:n,fill:x.color,fillOpacity:u,stroke:"none",inert:!0})}),h.forEach((x,p)=>{const y=i.x+f*x.coeff,b=c(y,x.coeff);d.push(...ki(`l${p}`,x,y,n,o,b,b&&l==="middle"&&ye(b.lines)?b.poly:null))}),d.push(...ct(t,e)),d}const Ls=[.236,.382,.5,.618,1];function Ss(e,t,n,o){const[i,r]=t;if(e.fmt!==2){const x=Math.hypot(r.x-i.x,r.y-i.y),p=P(o);return[...Ls.map(y=>({t:"circle",cx:i.x,cy:i.y,r:x*y,fill:"none",stroke:o.color,strokeWidth:o.width,dash:p,strokeOpacity:y===1?1:.55})),{t:"line",a:i,b:r,stroke:o.color,strokeWidth:1,strokeOpacity:.4,dash:"2 3"},...ct(n,t)]}const l=(i.x+r.x)/2,s=(i.y+r.y)/2,a=Math.abs(r.x-i.x)/2,c=Math.abs(r.y-i.y)/2,f=(o.levels??an).filter(x=>x.visible),h=Z(o),u=x=>`M ${l-a*x} ${s} a ${a*x} ${c*x} 0 1 0 ${2*a*x} 0 a ${a*x} ${c*x} 0 1 0 ${-2*a*x} 0 Z`,d=[];h>0&&f.forEach((x,p)=>d.push({t:"path",d:u(x.coeff)+(p>0?" "+u(f[p-1].coeff):""),fill:x.color,fillOpacity:h,fillRule:"evenodd",stroke:"none",inert:!0}));for(const x of f){const p=o.showCoeffs!==!1?Ne({text:$n(x.coeff,!!o.fibLevelsAsPercents),y:s+c*x.coeff,left:l,right:l,extendLeft:!1,extendRight:!1,paneW:0,horz:"left",vert:"middle",fs:12}):null;d.push({t:"ellipse",cx:l,cy:s,rx:a*x.coeff,ry:c*x.coeff,fill:"none",stroke:x.color,strokeWidth:St(x,o),dash:Ct(x,o)}),p&&d.push(U(p,x.color))}return d.push(...Yt(i,r,o),...ct(n,t)),d}function Cs(e,t,n,o,i,r,l){const[s,a]=t,c=ko(e,t,l,Te),f=P(r),h=Z(r),u=c.h.map(v=>({color:v.color,far:un(s,{x:a.x,y:v.y},o,i)})),d=c.v.map(v=>({color:v.color,far:un(s,{x:v.x,y:a.y},o,i)})),x=v=>v.slice(1).map((C,T)=>({color:C.color,pts:[s,C.far,v[T].far]})),{left:p,top:y,right:b,bottom:g}=c.box,m=r.fanGrid??qn,w=P({...r,lineStyle:m.style,width:m.width}),M=(v,C,T,F,A,O,D)=>G({x:v,y:C,text:Pt(T),fs:12,vert:F,horz:A,offsetX:O,offsetY:D}),k=[];if(h>0)for(const v of[...x(u),...x(d)])k.push({t:"polygon",pts:v.pts,fill:v.color,fillOpacity:h,stroke:"none",inert:!0});for(const v of c.h)m.visible&&k.push({t:"line",a:{x:p,y:v.y},b:{x:b,y:v.y},stroke:m.color,strokeWidth:m.width,dash:w,inert:!0}),r.showLeftLabels!==!1&&k.push(U(M(p,v.y,v.coeff,"middle","right",5,0),v.color)),r.showRightLabels!==!1&&k.push(U(M(b,v.y,v.coeff,"middle","left",5,0),v.color));for(const v of c.v)m.visible&&k.push({t:"line",a:{x:v.x,y},b:{x:v.x,y:g},stroke:m.color,strokeWidth:m.width,dash:w,inert:!0}),r.showTopLabels!==!1&&k.push(U(M(v.x,y,v.coeff,"bottom","center",0,5),v.color)),r.showBottomLabels!==!1&&k.push(U(M(v.x,g,v.coeff,"top","center",0,5),v.color));for(const v of[...u,...d])k.push({t:"hit",a:s,b:v.far,width:L*2}),k.push({t:"line",a:s,b:v.far,stroke:v.color,strokeWidth:r.width,dash:f,cap:"round"});return k.push(...ct(n,t)),k}function Ts(e,t,n){const[o,i]=e,r=Math.hypot(i.x-o.x,i.y-o.y),l=i.y>=o.y?1:-1,s=P(n),a=Lt(n,cn),c=Z(n),f=!!n.fullCircles,h=d=>f?`M ${o.x-d} ${o.y} A ${d} ${d} 0 1 0 ${o.x+d} ${o.y} A ${d} ${d} 0 1 0 ${o.x-d} ${o.y}`:`M ${o.x-d} ${o.y} A ${d} ${d} 0 0 ${l>0?0:1} ${o.x+d} ${o.y}`,u=[];if(r>=1e-6){c>0&&a.slice(1).forEach((d,x)=>{const p=r*a[x].coeff,y=r*d.coeff,b=f?`${h(y)} Z ${h(p)} Z`:`M ${o.x-y} ${o.y} A ${y} ${y} 0 0 ${l>0?0:1} ${o.x+y} ${o.y} L ${o.x+p} ${o.y} A ${p} ${p} 0 0 ${l>0?1:0} ${o.x-p} ${o.y} Z`;u.push({t:"path",d:b,fill:d.color,fillOpacity:c,fillRule:"evenodd",stroke:"none",inert:!0})});for(const d of a){const x=r*d.coeff;if(u.push({t:"hitPath",d:h(x),width:L*2}),u.push({t:"path",d:h(x),fill:"none",stroke:d.color,strokeWidth:St(d,n),dash:Ct(d,n)??s}),n.showCoeffs!==!1){const p=Ne({text:$n(d.coeff,!1),y:o.y+l*x,left:o.x,right:o.x,extendLeft:!1,extendRight:!1,paneW:0,horz:"left",vert:"middle",fs:12});p&&u.push(U(p,d.color))}}u.push(...Yt(o,i,n))}return u.push(...ct(t,e)),u}function As(e,t,n,o,i){const[r,l]=e,s=oi(r,l,!!i.counterclockwise),a=P(i),c=l.x-r.x,f=l.y-r.y,h=Math.hypot(c,f)||1,u=(n+o)*2,d={x:l.x+c/h*u,y:l.y+f/h*u};return[...s.length>=2?[{t:"line",a:r,b:d,stroke:i.color,strokeWidth:i.width,dash:a},{t:"polyline",pts:s,fill:"none",stroke:i.color,strokeWidth:i.width,dash:a,join:"round",cap:"round"}]:[],...ct(t,e)]}function $s(e,t,n){const[o,i,r]=e,l=Math.hypot(i.x-o.x,i.y-o.y);if(l<1e-6)return ct(t,e);const s=Math.atan2(i.y-o.y,i.x-o.x),a=Math.atan2(r.y-o.y,r.x-o.x),c={x:o.x+Math.cos(a)*l,y:o.y+Math.sin(a)*l};let f=a-s;for(;f>Math.PI;)f-=2*Math.PI;for(;f<-Math.PI;)f+=2*Math.PI;const h=P(n),u=Lt(n,Je),d=Z(n),x=24,p=b=>{const g=[];for(let m=0;m<=x;m++){const w=s+f*m/x;g.push({x:o.x+Math.cos(w)*b,y:o.y+Math.sin(w)*b})}return g},y=[{t:"hit",a:o,b:i,width:12},{t:"hit",a:o,b:c,width:12}];d>0&&u.slice(1).forEach((b,g)=>{const m=p(l*b.coeff),w=p(l*u[g].coeff).reverse();y.push({t:"polygon",pts:[...m,...w],fill:b.color,fillOpacity:d,stroke:"none",inert:!0})}),y.push(...Yt(o,i,n,!0),...Yt(o,c,n,!0));for(const b of u){const g=l*b.coeff,m=s+f/2;y.push({t:"polyline",pts:p(g),fill:"none",stroke:b.color,strokeWidth:St(b,n),dash:Ct(b,n)??h}),n.showCoeffs!==!1&&y.push({t:"text",x:o.x+Math.cos(m)*(g+8),y:o.y+Math.sin(m)*(g+8),text:Pt(b.coeff),size:11,fill:b.color,anchor:"middle",inert:!0})}return y.push(...ct(t,e)),y}function Is(e,t,n,o){const[i,r,l]=e,s={x:(r.x+l.x)/2,y:(r.y+l.y)/2},a={x:(l.x-r.x)/2,y:(l.y-r.y)/2},c=P(o),f=Lt(o,Mt),h=Z(o),u=n*4,d=y=>{const b=y.x-i.x,g=y.y-i.y,m=Math.hypot(b,g)||1;return{x:i.x+b/m*u,y:i.y+g/m*u}},x=[...f.slice().reverse().map(y=>({t:{x:s.x-a.x*y.coeff,y:s.y-a.y*y.coeff},color:y.color})),{t:s,color:o.color,median:!0},...f.map(y=>({t:{x:s.x+a.x*y.coeff,y:s.y+a.y*y.coeff},color:y.color}))],p=[{t:"line",a:r,b:l,stroke:o.color,strokeWidth:o.width,dash:c}];for(const y of x)p.push({t:"hit",a:i,b:d(y.t),width:L*2});h>0&&x.slice(1).forEach((y,b)=>p.push({t:"polygon",pts:[i,d(x[b].t),d(y.t)],fill:y.color,fillOpacity:h,stroke:"none",inert:!0}));for(const y of x)p.push({t:"line",a:i,b:d(y.t),stroke:y.color,strokeWidth:y.median?o.width:1,dash:c});return p.push(...ct(t,e)),p}const pe=(e,t)=>e?[{t:"anchors",pts:t}]:[];function Bs(e,t,n,o,i){var g;const r=oo(e,t);if(!r)return pe(n,t);const l=o.gannLevels??nn,s=Ar(r,l),a=$r(r,o.gannFans??on),c=Ir(r,o.gannArcs??rn),f=io(r),h=o.fillBackground===!1?0:Math.max(0,Math.min(1,(100-(o.transparency??80))/100)),u=(()=>{if(e.kind!=="gann-square"||o.showLabels===!1||!i)return[];const[m,w]=e.points,M=i.timeToBarIndex(m.time),k=i.timeToBarIndex(w.time);if(M==null||k==null)return[];const v=o.reverse?-1:1,C=(w.price-m.price)*v,T=(k-M)*v,F=Math.max(0,Math.min(8,Math.round(-Math.log10(i.pipSize())))),A=o.labelFontSize??12,O=(S,E,B,I,R,Y)=>G({x:S,y:E,text:B,fs:A,bold:o.bold,italic:o.italic,horz:I,vert:R,offsetX:10,offsetY:Y}),D=[O(r.start.x,r.end.y,pt(C,F),T>0?"right":"left",C>0?"bottom":"top",C>0?8:10),O(r.end.x,r.start.y,String(T),T>0?"left":"right",C>0?"top":"bottom",C>0?10:8)];return T!==0&&D.push(O(r.end.x,r.end.y,String(Number(Math.abs(C/T).toFixed(7))),T>0?"left":"right",C>0?"bottom":"top",C>0?8:10)),D})(),d=((g=l[l.length-1])==null?void 0:g.color)??"#808080",x=f.right-f.left,p=f.bottom-f.top,y=[{t:"clipRect",name:"box",x:f.left,y:f.top,w:x,h:p,idPrefix:"gann-clip-"},{t:"rect",x:f.left,y:f.top,w:x,h:p,fill:"transparent"}];for(const m of s)y.push({t:"line",a:{x:m.x,y:r.start.y},b:{x:m.x,y:r.end.y},stroke:m.color,strokeWidth:m.width,inert:!0}),y.push({t:"line",a:{x:r.start.x,y:m.y},b:{x:r.end.x,y:m.y},stroke:m.color,strokeWidth:m.width,inert:!0});for(const m of a)y.push({t:"line",a:m.from,b:m.to,stroke:m.color,strokeWidth:m.width,cap:"round",inert:!0});const b=[];for(const m of c){const w=Br(r,m.r,m.prev);h>0&&b.push({t:"path",d:w.fill,fill:m.color,fillOpacity:h,stroke:"none"}),b.push({t:"path",d:w.stroke,fill:"none",stroke:m.color,strokeWidth:m.width})}y.push({t:"group",clip:"box",inert:!0,items:b});for(const m of u)y.push(U(m,d,o.bold,o.italic));return y.push(...pe(n,t)),y}function Es(e,t,n,o,i){const[r,l]=e,s=(n+o)*2,a=l.x-r.x,c=l.y-r.y,f=(i.levels??Qe).map((b,g)=>({...b,index:g+1})).filter(b=>b.visible),h=Z(i),u=b=>b>1?{x:l.x,y:r.y+c/b}:{x:r.x+a*b,y:l.y},d=b=>{const g=ro(r,l,b),m=Math.hypot(g.x,g.y)||1;return{x:r.x+g.x/m*s,y:r.y+g.y/m*s}},x=[];f.forEach((b,g)=>{b.index<4&&g<f.length-1?x.push({from:b.coeff,to:f[g+1].coeff,color:b.color}):b.index>4&&g>0&&x.push({from:b.coeff,to:f[g-1].coeff,color:b.color})});const p=12/3,y=[{t:"hit",a:r,b:l,width:12}];for(const b of f)y.push({t:"hit",a:r,b:d(b.coeff),width:L*2});if(h>0)for(const b of x)y.push({t:"polygon",pts:[r,d(b.from),d(b.to)],fill:b.color,fillOpacity:h,stroke:"none",inert:!0});for(const b of f){const g=d(b.coeff),m=u(b.coeff);y.push({t:"line",a:r,b:g,stroke:b.color,strokeWidth:St(b,i),dash:Ct(b,i)}),i.showLabels!==!1&&y.push({t:"text",x:m.x+p,y:m.y,text:b.label??Pt(b.coeff),size:12,fill:b.color,anchor:"start",baseline:"central",inert:!0})}return y.push(...pe(t,e)),y}function Ps(e,t,n,o,i){const[r,l]=t,s=Math.min(r.x,l.x),a=Math.max(r.x,l.x),c=Math.min(r.y,l.y),f=Math.max(r.y,l.y),h=At(r,l),u=o.levels??Ae,d=o.vLevels??Ae,x=P(o),[p,y]=e.points,b=!!o.reverse,g=S=>{const E=b?y.price:p.price,B=b?p.price-y.price:y.price-p.price;return(i==null?void 0:i.priceToY(E+S*B))??(b?l.y+S*(r.y-l.y):r.y+S*(l.y-r.y))},m=(i==null?void 0:i.timeToBarIndex(p.time))??null,w=(i==null?void 0:i.timeToBarIndex(y.time))??null,M=S=>{if(i&&m!=null&&w!=null){const E=b?w:m,B=b?m-w:w-m,I=i.barIndexToTime(Math.round(E+S*B)),R=I!=null?i.timeToX(I):null;if(R!=null)return R}return b?l.x+S*(r.x-l.x):r.x+S*(l.x-r.x)},k=u.filter(S=>S.visible).map(S=>({...S,y:g(S.coeff)})),v=d.filter(S=>S.visible).map(S=>({...S,x:M(S.coeff)})),C=o.fillBackground!==!1?Math.max(0,Math.min(1,(100-(o.transparency??80))/100)):0,T=o.fillVertBackground!==!1?Math.max(0,Math.min(1,(100-(o.vertTransparency??80))/100)):0,F=o.fans??{visible:!1,color:"#9C9C9C"},A=[];if(F.visible)for(let S=0;S<u.length;S++){const E=M(u[S].coeff);A.push([{x:s,y:f},{x:E,y:c}],[{x:a,y:f},{x:E,y:c}],[{x:s,y:c},{x:E,y:f}],[{x:a,y:c},{x:E,y:f}]);const B=d[S];if(!B)continue;const I=g(B.coeff);A.push([{x:s,y:f},{x:a,y:I}],[{x:a,y:f},{x:s,y:I}],[{x:s,y:c},{x:a,y:I}],[{x:a,y:c},{x:s,y:I}])}const O=(S,E,B,I,R,Y,J,gt)=>U(G({x:S,y:E,text:B,fs:12,horz:R,vert:Y,offsetX:J,offsetY:gt}),I),D=[{t:"rect",x:s,y:c,w:Math.max(1,a-s),h:Math.max(1,f-c),fill:"transparent"}];k.forEach((S,E)=>{E>0&&C>0&&D.push({t:"rect",x:s,y:Math.min(S.y,k[E-1].y),w:a-s,h:Math.abs(S.y-k[E-1].y),fill:S.color,fillOpacity:C,inert:!0}),D.push({t:"line",a:{x:s,y:S.y},b:{x:a,y:S.y},stroke:S.color,strokeWidth:o.width,dash:x}),o.showLeftLabels!==!1&&D.push(O(s,S.y,Pt(S.coeff),S.color,"right","middle",5,0)),o.showRightLabels!==!1&&D.push(O(a,S.y,Pt(S.coeff),S.color,"left","middle",5,0))}),v.forEach((S,E)=>{E>0&&T>0&&D.push({t:"rect",x:Math.min(S.x,v[E-1].x),y:c,w:Math.abs(S.x-v[E-1].x),h:f-c,fill:S.color,fillOpacity:T,inert:!0}),D.push({t:"line",a:{x:S.x,y:c},b:{x:S.x,y:f},stroke:S.color,strokeWidth:o.width,dash:x}),o.showTopLabels!==!1&&D.push(O(S.x,c,Pt(S.coeff),S.color,"center","bottom",0,3)),o.showBottomLabels!==!1&&D.push(O(S.x,f,Pt(S.coeff),S.color,"center","top",0,5))});for(const[S,E]of A)D.push({t:"line",a:S,b:E,stroke:F.color,strokeWidth:o.width,dash:x,inert:!0});return D.push(...pe(n,h)),D}function zs(e,t,n,o,i){const r=lo(e,t);if(!r)return[];const l=Kt(r.pivot,r.dir,o),s=Math.hypot(r.dir.x,r.dir.y)||1,a=b=>i.extendLines?{x:b.x-r.dir.x/s*o*4,y:b.y-r.dir.y/s*o*4}:b,c=P(i),f=Lt(i,Mt),h=Z(i),u=(b,g)=>({x:r.mid.x+r.half.x*b*g,y:r.mid.y+r.half.y*b*g}),d=[];let x=0;for(const b of f)d.push({from:x,to:b.coeff,color:b.color}),x=b.coeff;const p=[1,-1],y=[{t:"hit",a:r.pivot,b:l,width:L*2}];for(const b of p)for(const g of f){const m=u(g.coeff,b);y.push({t:"hit",a:m,b:Kt(m,r.dir,o),width:L*2})}if(h>0)for(const b of p)for(const g of d){const m=u(g.from,b),w=u(g.to,b);y.push({t:"polygon",pts:[a(m),Kt(m,r.dir,o),Kt(w,r.dir,o),a(w)],fill:g.color,fillOpacity:h,stroke:"none",inert:!0})}y.push({t:"line",a:t[1],b:t[2],stroke:i.color,strokeWidth:i.width,dash:c,cap:"round"}),y.push({t:"line",a:a(r.pivot),b:l,stroke:i.color,strokeWidth:i.width,dash:c,cap:"round"});for(const b of p)for(const g of f)y.push({t:"line",a:a(u(g.coeff,b)),b:Kt(u(g.coeff,b),r.dir,o),stroke:g.color,strokeWidth:St(g,i),dash:Ct(g,i),cap:"round"});return y.push(...pe(n,t)),y}const Ws=.06;function Ye(e,t){const n=ce(e);return t&&n.fillOpacity>0?{fill:n.fill,fillOpacity:Math.min(1,n.fillOpacity+Ws)}:n}function vi(e,t,n,o){return e.text?[{t:"text",x:t,y:n,text:e.text,size:o.fontSize??14,fill:o.textColor??o.color,anchor:"middle",baseline:"middle",weight:o.bold?700:400,fontStyle:o.italic?"italic":"normal",inert:!0}]:[]}function Rs(e,t){if(e.length<2)return[];const n=[];return t.leftEnd===1&&n.push(...Et(e[1],e[0],t)),t.rightEnd===1&&n.push(...Et(e[e.length-2],e[e.length-1],t)),n}const En=e=>e.map((t,n)=>`${n===0?"M":"L"} ${t.x} ${t.y}`).join(" "),ht=(e,t,n)=>e?[n?{t:"anchors",pts:t,squares:n}:{t:"anchors",pts:t}]:[];function Fs(e,t,n,o,i,r){const[l,s]=t,a=i.extendLeft?-i.width:Math.min(l.x,s.x),c=i.extendRight?o+i.width:Math.max(l.x,s.x),f=Math.min(l.y,s.y),h=Math.max(l.y,s.y),u=Ye(i,r),d=fo(e,t,o),x=i.rectMiddleLine,p=[{t:"rect",x:a,y:f,w:c-a,h:h-f,fill:u.fill,fillOpacity:u.fillOpacity,stroke:i.color,strokeWidth:i.width,dash:P(i)}];if(x!=null&&x.visible){const y=d&&(i.vertLabelsAlign??"middle")==="middle"&&ye(d.lines)?d.poly:null,b=y&&y.length?"mid":void 0;b&&p.push({t:"clip",name:b,polys:[y]});const g=Math.floor((f+h)/2);p.push({t:"line",a:{x:a,y:g},b:{x:c,y:g},stroke:x.color,strokeWidth:x.width,dash:P({...i,lineStyle:x.style,width:x.width}),cap:"butt",clip:b,inert:!0})}return d&&p.push(U(d,i.textColor??i.color,i.bold,i.italic)),p.push(...ht(n,[...At(l,s),...ei(l,s)],Nt.rectangle)),p}function Os(e,t,n,o){const i=e.fmt===2,r=to(t,i),l=ce(o),s=i?[t[0],t[1],...r]:t;return[{t:"polygon",pts:r,fill:l.fill,fillOpacity:l.fillOpacity,stroke:o.color,strokeWidth:o.width,dash:P(o),join:"round"},...ht(n,s)]}function Ds(e,t,n,o,i){const[r,l]=t,s=Math.hypot(l.x-r.x,l.y-r.y),a=Ye(o,i);return[{t:"circle",cx:r.x,cy:r.y,r:Math.max(0,s),fill:a.fill,fillOpacity:a.fillOpacity,stroke:o.color,strokeWidth:o.width,dash:P(o)},...vi(e,r.x,r.y,o),...ht(n,t)]}function _s(e,t,n,o,i){const[r,l,s]=t,a=(r.x+l.x)/2,c=(r.y+l.y)/2,f=Math.max(1,Math.hypot(l.x-r.x,l.y-r.y)/2),h=Math.atan2(l.y-r.y,l.x-r.x),u=-Math.sin(h),d=Math.cos(h),x=Math.max(1,Math.abs((s.x-a)*u+(s.y-c)*d)),p=h*180/Math.PI,y=Ye(o,i);return[{t:"group",transform:`rotate(${p} ${a} ${c})`,items:[{t:"ellipse",cx:a,cy:c,rx:f,ry:x,fill:"transparent",stroke:"transparent",strokeWidth:L*2},{t:"ellipse",cx:a,cy:c,rx:f,ry:x,fill:y.fill,fillOpacity:y.fillOpacity,stroke:o.color,strokeWidth:o.width,dash:P(o)}]},...vi(e,a,c,o),...ht(n,t)]}function Hs(e,t,n,o){const i=Ye(n,o);return[{t:"polygon",pts:e,fill:i.fill,fillOpacity:i.fillOpacity,stroke:n.color,strokeWidth:n.width,dash:P(n),join:"round"},...ht(t,e)]}function Ns(e,t,n){const[o,i]=e,r=P(n),l=e.length===3?ri(o,i,e[2]):null;if(!l)return[{t:"line",a:o,b:i,stroke:n.color,strokeWidth:n.width,dash:r,cap:"round"},...ht(t,e)];const s=En(l),a=ce(n);return[{t:"path",d:`${s} Z`,fill:a.fill,fillOpacity:a.fillOpacity,stroke:"none"},{t:"path",d:s,fill:"none",stroke:n.color,strokeWidth:n.width,dash:r,cap:"round"},...ht(t,e)]}function Li(e,t,n,o,i,r){const l=[];if(n.fillBackground){const s=ce(n);l.push({t:"path",d:En(i)+" Z",fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"})}if(l.push({t:"path",d:En(o),fill:"none",stroke:n.color,strokeWidth:n.width,dash:P(n),cap:"round"}),l.push(...Rs(i,n)),t){for(const[s,a]of r)l.push({t:"line",a:s,b:a,stroke:n.color,strokeOpacity:.3,dash:"3 3"});l.push({t:"anchors",pts:e})}return l}function Ys(e,t,n){const o=e.length>=3?e:[e[0],{x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2},e[1]],[i,r,l]=o,s=kn(o,!!n.extendLeft,!!n.extendRight),a=n.extendLeft||n.extendRight?kn(o):s;return Li(e,t,n,s,a,[[i,r],[l,r]])}function Us(e,t,n){const o=e.length>=4?e:[e[0],{x:e[0].x+(e[1].x-e[0].x)/3,y:e[0].y+(e[1].y-e[0].y)/3},{x:e[0].x+(e[1].x-e[0].x)*2/3,y:e[0].y+(e[1].y-e[0].y)*2/3},e[1]],[i,r,l,s]=o,a=vn(o,!!n.extendLeft,!!n.extendRight),c=n.extendLeft||n.extendRight?vn(o):a;return Li(e,t,n,a,c,[[i,r],[s,l]])}function Vs(e,t,n){const[o,i,r]=e,l=Math.hypot(i.x-o.x,i.y-o.y);if(!r||l<1e-6)return[{t:"line",a:o,b:i,stroke:n.color,strokeWidth:n.width},...ht(t,e)];const s=Math.atan2(i.y-o.y,i.x-o.x),a=Math.atan2(r.y-o.y,r.x-o.x),c={x:o.x+Math.cos(a)*l,y:o.y+Math.sin(a)*l};let f=a-s;for(;f>Math.PI;)f-=2*Math.PI;for(;f<-Math.PI;)f+=2*Math.PI;const h=[];for(let d=0;d<=32;d++){const x=s+f*d/32;h.push({x:o.x+Math.cos(x)*l,y:o.y+Math.sin(x)*l})}const u=n.fillBackground===!1?0:Math.max(0,Math.min(1,(100-(n.transparency??80))/100));return[{t:"radialGradient",name:"sector",idPrefix:"sector-grad-",cx:o.x,cy:o.y,r:l,stops:[{offset:0,color:n.sectorColor1??"#2962ff",opacity:u},{offset:1,color:n.sectorColor2??"#9c27b0",opacity:u}]},{t:"polygon",pts:[o,...h],fillRef:"sector",stroke:"none"},{t:"line",a:o,b:i,stroke:n.color,strokeWidth:n.width},{t:"line",a:o,b:c,stroke:n.color,strokeWidth:n.width},{t:"polyline",pts:h,fill:"none",stroke:n.color,strokeWidth:n.width},...ht(t,e)]}function Xs(e,t,n,o,i){const[r,l]=e,s=l.x-r.x,a=P(i),c=[{t:"line",a:r,b:l,stroke:"#808080",strokeWidth:1,dash:"6 4"}];if(Math.abs(s)>=2)for(let f=r.x;s>0?f<=n+2:f>=-2;f+=s)c.push({t:"line",a:{x:f,y:0},b:{x:f,y:o},stroke:i.color,strokeWidth:i.width,dash:a});return c.push(...ht(t,e)),c}function Gs(e,t,n,o){const i=ii(e[0],e[1],n),r=[];return i.length>=2&&r.push({t:"polyline",pts:i,fill:"none",stroke:o.color,strokeWidth:o.width,dash:P(o)}),r.push(...ht(t,e)),r}function js(e,t,n,o){const[i,r]=e,l=Math.abs(r.x-i.x),s=l/2,a=P(o),c=ce(o),f=i.y,h=[];if(l>=2){const u=Math.min(i.x,r.x),d=Math.floor(-u/l)-1,x=Math.ceil((n-u)/l)+1;for(let p=d;p<=x;p++){const y=u+p*l;c.fillOpacity>0&&h.push({t:"path",d:`M ${y} ${f} A ${s} ${s} 0 0 1 ${y+l} ${f} Z`,fill:c.fill,fillOpacity:c.fillOpacity,stroke:"none",inert:!0}),h.push({t:"path",d:`M ${y} ${f} A ${s} ${s} 0 0 1 ${y+l} ${f}`,fill:"none",stroke:o.color,strokeWidth:o.width,dash:a})}}return h.push(...ht(t,e)),h}const Pn={"xabcd-pattern":["X","A","B","C","D"],"cypher-pattern":["X","A","B","C","D"],"abcd-pattern":["A","B","C","D"],"head-and-shoulders":["","LS","","H","","RS",""],"triangle-pattern":["A","B","C","D"],"three-drives-pattern":["1","2","3","4","5","6","7"],"elliott-impulse":["0","1","2","3","4","5"],"elliott-correction":["0","A","B","C"],"elliott-triangle":["0","A","B","C","D","E"],"elliott-double-combo":["0","W","X","Y"],"elliott-triple-combo":["0","W","X","Y","X","Z"]},qs=new Set(["polyline"]),Zs=[{font:11,circle:14,bold:!0},{font:16,circle:22,bold:!1},{font:18,circle:22,bold:!1},{font:20,circle:28,bold:!1},{font:24,circle:36,bold:!0}],Ks={"elliott-impulse":["0","1","2","3","4","5"],"elliott-correction":["0","A","B","C"],"elliott-triangle":["0","A","B","C","D","E"],"elliott-double-combo":["0","W","X","Y"],"elliott-triple-combo":["0","W","X","Y","X","Z"]},Si=["0","i","ii","iii","iv","v"];function Qs(e,t){const n=Ks[e]??[];return e==="elliott-impulse"?t===1?Si:t===3?Si.map(o=>o.toUpperCase()):n:t%2===1?n.map(o=>o.toLowerCase()):n}function Js(e,t,n,o){const r=14-Math.max(0,Math.min(14,Math.round(o.elliottDegree??yr))),l=Math.floor(r/3),s=["","brackets","circle"][r%3],a=Zs[l],c=Qs(e.kind,l),f=10+a.circle/2,h=t.length>2?Math.sign(t[2].y-t[1].y):1,u=x=>x%2===0?h:-h,d=[{t:"polyline",pts:t,fill:"none",stroke:"transparent",strokeWidth:Math.max(L*2,o.width)}];return o.showWave!==!1&&d.push({t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:P(o),join:"round",cap:"round"}),t.forEach((x,p)=>{if(p===0&&!n)return;const y=x.y+(u(p)===1?f:-f),b=c[p]??String(p);s==="circle"&&d.push({t:"circle",cx:x.x,cy:y,r:a.circle/2-.5,fill:"none",stroke:o.color,strokeWidth:1,inert:!0}),d.push({t:"text",x:x.x,y:y+.05*a.font,text:s==="brackets"?`(${b})`:b,size:a.font,weight:a.bold?700:400,fill:o.color,anchor:"middle",baseline:"central",inert:!0})}),n&&d.push({t:"anchors",pts:t}),d}function Ci(e,t){const n=e[t-1]??e[t+1]??e[t],o=e[t+1]??e[t-1]??e[t];return e[t].y<=Math.min(n.y,o.y)?-8:16}function Ue(e,t,n,o,i){const r=o.length*i.fontSize*.62+8,l=i.fontSize+6,s=n<0?t+n-l:n>0?t+n:t-l/2;return{t:"group",inert:!0,items:[{t:"rect",x:e-r/2,y:s,w:r,h:l,rx:4,fill:i.bg},{t:"text",x:e,y:s+l/2+.5,text:o,size:i.fontSize,weight:i.bold?700:400,fontStyle:i.italic?"italic":"normal",fill:i.fg,anchor:"middle",baseline:"middle"}]}}function bt(e,t,n,o){const i=t-e;if(Math.abs(i)<1e-12)return"∞";const r=Math.pow(10,o);return String(Math.round(Math.abs((n-t)/i)*r)/r)}function zn(e,t,n,o){return[{t:"hit",a:e,b:t,width:L*2},{t:"line",a:e,b:t,stroke:n,strokeWidth:o,dash:"2 3"}]}function ne(e,t,n,o,i,r){return[...zn(e[t],e[n],r.bg,o),Ue((e[t].x+e[n].x)/2,(e[t].y+e[n].y)/2,0,i,r)]}const oe=e=>({bg:e.color,fg:e.textColor??"#ffffff",fontSize:e.fontSize??12,bold:e.bold,italic:e.italic});function Ti(e,t,n){const o=oe(n),i=[];return e.forEach((r,l)=>{t[l]&&i.push(Ue(r.x,r.y,Ci(e,l)<0?-5:5,t[l],o))}),i}const be=e=>({t:"polyline",pts:e,fill:"none",stroke:"transparent",strokeWidth:L*2});function tc(e,t,n,o){const i=oe(o),r=e.points.map(s=>s.price),l=[be(t),{t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:P(o),join:"round"}];return t.length>=3&&l.push(...ne(t,0,2,o.width,bt(r[0],r[1],r[2],3),i)),t.length>=4&&l.push(...ne(t,1,3,o.width,bt(r[1],r[2],r[3],3),i)),l.push(...Ti(t,Pn[e.kind],o)),n&&l.push({t:"anchors",pts:t}),l}function ec(e,t,n,o){const i=e.kind==="cypher-pattern",r=oe(o),l=o.backgroundColor??o.color,s=o.fillBackground===!1?0:Z(o),a=e.points.map(f=>f.price),c=[];if(s>0&&t.length>=3&&c.push({t:"polygon",pts:[t[0],t[1],t[2]],fill:l,fillOpacity:s,stroke:"none"}),s>0&&t.length>=5&&c.push({t:"polygon",pts:[t[2],t[3],t[4]],fill:l,fillOpacity:s,stroke:"none"}),c.push(be(t),{t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:P(o),join:"round"}),t.length>=3&&c.push(...ne(t,0,2,1,bt(a[0],a[1],a[2],3),r)),t.length>=4&&c.push(...ne(t,1,3,1,i?bt(a[1],a[0],a[3],3):bt(a[1],a[2],a[3],3),r)),t.length>=5){const f=i?bt(a[0],a[2],a[4],3):bt(a[0],a[1],a[4],3);c.push(...zn(t[0],t[4],o.color,1),...zn(t[2],t[4],o.color,1),Ue((t[2].x+t[4].x)/2,(t[2].y+t[4].y)/2,0,bt(a[2],a[3],a[4],3),r),Ue((t[0].x+t[4].x)/2,(t[0].y+t[4].y)/2,0,f,r))}return c.push(...Ti(t,Pn[e.kind],o)),n&&c.push({t:"anchors",pts:t}),c}function nc(e,t,n,o){const i=oe(o),r=e.points.map(s=>s.price),l=[be(t),{t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:P(o),join:"round"}];return t.length>=4&&l.push(...ne(t,1,3,o.width,bt(r[1],r[2],r[3],2),i)),t.length>=6&&l.push(...ne(t,3,5,o.width,bt(r[3],r[4],r[5],2),i)),n&&l.push({t:"anchors",pts:t}),l}function Ut(e,t,n,o){const i=o.fontSize/3,r=$t(n,o.fontSize,!!o.bold,!!o.italic)+2*i,l=o.fontSize+2*i,s=t?e.y-5-l:e.y+5;return{t:"group",inert:!0,items:[{t:"rect",x:e.x-r/2,y:s,w:r,h:l,rx:4,fill:o.bg},{t:"text",x:e.x,y:s+l/2,text:n,size:o.fontSize,weight:o.bold?700:400,fontStyle:o.italic?"italic":"normal",fill:o.fg,anchor:"middle",baseline:"central"}]}}function oc(e,t,n){const[o,i,r,l]=e,s=oe(n);let a=null;if(Math.abs(r.x-o.x)>=1&&Math.abs(l.x-i.x)>=1){const f=(r.y-o.y)/(r.x-o.x),h=(l.y-i.y)/(l.x-i.x);if(Math.abs(f-h)>=1e-6){let u=Math.min(o.x,i.x,r.x,l.x),d={x:u,y:o.y+(u-o.x)*f},x={x:u,y:i.y+(u-i.x)*h};const p=(i.y-o.y+(o.x*f-i.x*h))/(f-h);p<u&&(u=Math.max(o.x,i.x,r.x,l.x),d={x:u,y:o.y+(u-o.x)*f},x={x:u,y:i.y+(u-i.x)*h}),a=[d,x,{x:p,y:o.y+(p-o.x)*f}]}}const c=[be(e)];return a&&c.push({t:"polygon",pts:a,fill:n.fillBackground===!1?"none":n.backgroundColor??n.color,fillOpacity:Z(n)||.15,stroke:n.color,strokeWidth:n.width,dash:P({...n,lineStyle:"dotted"}),inert:!0}),c.push({t:"polyline",pts:e,fill:"none",stroke:n.color,strokeWidth:n.width,join:"round"},Ut(o,i.y>o.y,"A",s),Ut(i,i.y<o.y,"B",s),Ut(r,r.y<i.y,"C",s),Ut(l,l.y<r.y,"D",s)),t&&c.push({t:"anchors",pts:e}),c}function Ai(e,t,n,o){const i={x:t.x-e.x,y:t.y-e.y},r={x:o.x-n.x,y:o.y-n.y},l=i.x*r.y-i.y*r.x;if(Math.abs(l)<1e-9)return null;const s=((n.x-e.x)*i.y-(n.y-e.y)*i.x)/l;return s<0||s>1?null:{x:n.x+r.x*s,y:n.y+r.y*s}}function ic(e,t,n){const o=Z(n)||.15,i=n.backgroundColor??n.color,[r,l,s,a,c,f,h]=e,u=Ai(s,c,r,l),d=Ai(s,c,f,h),x=(g,m)=>({x:g.x+(m.x-g.x)*10,y:g.y+(m.y-g.y)*10}),p=oe(n),y=(g,m,w)=>({t:"polygon",pts:[g,m,w],fill:i,fillOpacity:o,stroke:"none",inert:!0}),b=[be(e)];return n.fillBackground!==!1&&(b.push(y(s,a,c)),u&&b.push(y(u,l,s)),d&&b.push(y(c,f,d))),b.push({t:"line",a:u??x(c,s),b:d??x(s,c),stroke:n.color,strokeWidth:n.width,dash:P({...n,lineStyle:"dotted"}),inert:!0},{t:"polyline",pts:e,fill:"none",stroke:n.color,strokeWidth:n.width,dash:P(n),join:"round"},Ut(l,l.y<r.y,"Left Shoulder",p),Ut(a,a.y<s.y,"Head",p),Ut(f,f.y<c.y,"Right Shoulder",p)),t&&b.push({t:"anchors",pts:e}),b}function rc(e,t=5){if(e.length<2)return e;const n=Math.max(1,t),o=[e[0]];for(let r=1;r<e.length;r++){const l=e[r].x-e[r-1].x,s=e[r].y-e[r-1].y,a=Math.hypot(l,s),c=Math.min(5,Math.floor(a/n));for(let f=0;f<c-1;f++)o.push({x:e[r-1].x+l/c*f,y:e[r-1].y+s/c*f});o.push(e[r])}const i=new Array(o.length);for(let r=0;r<o.length;r++){let l=0,s=0;for(let a=0;a<n;a++){const c=o[Math.max(r-a,0)],f=o[Math.min(r+a,o.length-1)];l+=c.x+f.x,s+=c.y+f.y}i[r]={x:l*.5/n,y:s*.5/n}}return i.push(o[o.length-1]),i}function lc(e,t,n,o){if(e.kind==="triangle-pattern"&&t.length>=4)return oc(t,n,o);if(e.kind==="head-and-shoulders"&&t.length>=7)return ic(t,n,o);if(e.kind==="abcd-pattern"&&t.length>=2)return tc(e,t,n,o);if((e.kind==="xabcd-pattern"||e.kind==="cypher-pattern")&&t.length>=2)return ec(e,t,n,o);if(e.kind==="three-drives-pattern"&&t.length>=2)return nc(e,t,n,o);if(e.kind.startsWith("elliott-"))return Js(e,t,n,o);const i=Pn[e.kind],r=qs.has(e.kind)&&e.closed===!0,l=e.kind==="highlighter",s=e.kind==="brush"||l,a=l?Math.max(o.width,12):o.width,c=s?rc(t):t,f=s?void 0:P(o),h=s&&t.length>1?[t[0],t[t.length-1]]:t,u=[];if(r){const d=o.backgroundColor??o.color,x=o.fillBackground!==void 0?Z(o):.08;u.push({t:"polygon",pts:c,fill:d,fillOpacity:x,stroke:"transparent",strokeWidth:L*2},{t:"polygon",pts:c,fill:d,fillOpacity:x,stroke:o.color,strokeWidth:o.width,dash:f,join:"round"})}else{e.kind==="brush"&&o.fillBackground===!0&&u.push({t:"polygon",pts:c,fill:o.backgroundColor??o.color,fillOpacity:Z(o),stroke:"none",inert:!0}),u.push({t:"polyline",pts:c,fill:"none",stroke:"transparent",strokeWidth:Math.max(L*2,a)},{t:"polyline",pts:c,fill:"none",stroke:o.color,strokeWidth:a,strokeOpacity:l?.2:1,dash:f,join:"round",cap:"round"});const d=(p,y)=>{const b=Math.hypot(y.x-p.x,y.y-p.y),m=(o.lineStyle??"solid")==="solid"&&b>=1?{x:p.x+(y.x-p.x)*(b+o.width/2)/b,y:p.y+(y.y-p.y)*(b+o.width/2)/b}:y;return{t:"path",d:De(p,m,o.width),fill:"none",stroke:o.color,strokeWidth:o.width,dash:f,join:"round",cap:"round",inert:!0}},x=e.kind==="path"||e.kind==="brush";x&&c.length>1&&(o.leftEnd??0)===1&&u.push(d(c[1],c[0])),x&&c.length>1&&(o.rightEnd??(e.kind==="path"?1:0))===1&&u.push(d(c[c.length-2],c[c.length-1]))}return i&&t.forEach((d,x)=>{u.push({t:"text",x:d.x,y:d.y+Ci(t,x),text:i[x]??String(x+1),size:11,fill:o.color,anchor:"middle"})}),n&&u.push({t:"anchors",pts:h}),u}function sc(e){return e<92?18:Math.min(Math.max(e*.25,18),106,e*.9)}function cc(e,t,n){const[o,i]=e,r=Math.hypot(i.x-o.x,i.y-o.y),l=n.fontSize??16,s=(A,O,D)=>n.text?[{t:"text",x:A,y:O,text:n.text,anchor:D,size:l,weight:n.bold!==!1?700:400,fontStyle:n.italic?"italic":"normal",fill:n.textColor??n.color,inert:!0}]:[];if(r<1){const A=[{t:"circle",cx:i.x,cy:i.y,r:9,fill:n.color},...s(i.x+12,i.y+l*.35,"start")];return t&&A.push({t:"anchors",pts:[i]}),A}let a=o;if(r<22){const A={x:(i.x-o.x)/r,y:(i.y-o.y)/r};a={x:i.x-A.x*22,y:i.y-A.y*22}}const c=i.x-a.x,f=i.y-a.y,h=Math.hypot(c,f),u=c/h,d=f/h,x=-d,p=u,y=sc(h),b=h>=35?.1:0,g=[{x:0,y:0},{x:h-y+y*b,y:1.22*y/4},{x:h-y,y:1.22*y/2},{x:h,y:0}],m=(A,O)=>({x:a.x+u*A.x+x*A.y*O,y:a.y+d*A.x+p*A.y*O}),w=[...g.map(A=>m(A,1)),...g.slice(0,g.length-1).reverse().map(A=>m(A,-1))],M=Math.min(5,Math.max(2,Math.round(.02*h))),k=Math.atan2(c,f);let v=o.x,C=o.y,T="middle";k>-Math.PI/4&&k<Math.PI/4?C-=8:k>3*Math.PI/4||k<-3*Math.PI/4?C+=8+l:k<0?(v+=10,T="start",C+=l*.35):(v-=10,T="end",C+=l*.35);const F=[{t:"hit",a,b:i,width:Math.max(12,1.22*y/2)},{t:"polygon",pts:w,fill:n.color,stroke:n.color,strokeWidth:M,join:"round",cap:"round"},...s(v,C,T)];return t&&F.push({t:"anchors",pts:e}),F}function ac(e,t){const n=t==="up"?1:-1,o=n*12,i=n*10,r=19.5/2,l=5;return`M ${e.x} ${e.y} L ${e.x+r} ${e.y+o} L ${e.x+l} ${e.y+o} L ${e.x+l} ${e.y+o+i} L ${e.x-l} ${e.y+o+i} L ${e.x-l} ${e.y+o} L ${e.x-r} ${e.y+o} Z`}function $i(e,t,n,o,i){const r=t[0],l=Co(e,r),s=o.fontSize??14,a=[{t:"path",d:ac(r,i),fill:o.color}];return l&&(a.push({t:"rect",x:l.left,y:l.top,w:l.width,h:l.height,fill:"transparent"}),l.lines.forEach((c,f)=>{a.push({t:"text",x:r.x,y:l.top+l.pad+f*l.lineH,text:c,anchor:"middle",baseline:"hanging",size:s,weight:o.bold?700:400,fontStyle:o.italic?"italic":"normal",fill:o.textColor??o.color,inert:!0,pre:!0})})),n&&a.push({t:"anchors",pts:[r]}),a}const Ii=22,Ve=17,Wn=12,fc=5;function hc(e,t,n){const o=e[0],i=o.y-Ii,r=o.x,l=[{x:r,y:i},{x:r+Ve,y:i},{x:r+Ve-fc,y:i+Wn/2},{x:r+Ve,y:i+Wn},{x:r,y:i+Wn}],s=[{t:"rect",x:r-L,y:i-L,w:Ve+L*2,h:Ii+L*2,fill:"transparent"},{t:"line",a:{x:r,y:i},b:{x:r,y:o.y},stroke:n.color,strokeWidth:Math.max(2,n.width+1),cap:"round"},{t:"polygon",pts:l,fill:n.color,stroke:n.color,strokeWidth:1,join:"round"}];return t&&s.push({t:"anchors",pts:[o]}),s}function uc(e,t,n,o,i){const r=t[0],l=(i==null?void 0:i.pipSize())??.01,s=Math.max(0,Math.min(8,Math.round(-Math.log10(l)))),a=e.points[0].price.toFixed(s),c=o.fontSize??14,f=jo(a,r,c),h=100-(o.transparency??0),u=o.borderColor??o.color,d=[{t:"path",d:cl(f),fill:kt(at(o.backgroundColor??o.color).hex,h),stroke:u,strokeWidth:2,join:"round"},{t:"text",x:f.x+10,y:f.y+f.h/2+Math.floor(.35*c),text:a,size:c,weight:"bold",fill:o.textColor??"#ffffff",pre:!0},{t:"circle",cx:r.x,cy:r.y,r:2.5,fill:kt(at(u).hex,h),stroke:"#0f0f0f",strokeWidth:1}];return n&&d.push({t:"anchors",pts:[r]}),d}const dc=28;function xc(e,t,n){const[o]=t,i=e.style.fontSize??dc,r=i/2,l=[];return n&&l.push({t:"rect",x:o.x-r-2,y:o.y-r-2,w:i+4,h:i+4,fill:"none",stroke:"#2962ff",strokeWidth:1,dash:"3 3",rx:3}),l.push({t:"glyph",x:o.x-r,y:o.y-r,size:i,glyph:e.glyph??"",color:e.style.color}),[{t:"group",items:l}]}const yc="#089981",pc="#f23645";function bc(e,t){const n=[];for(const o of e){const i=o.up?yc:pc,r=Math.min(o.openY,o.closeY),l=Math.max(1,Math.abs(o.closeY-o.openY));n.push({t:"line",a:{x:o.x,y:o.highY},b:{x:o.x,y:o.lowY},stroke:i,strokeWidth:1},{t:"rect",x:o.x-t/2,y:r,w:t,h:l,fill:i})}return n}function gc(e,t,n,o,i){if(e.kind!=="bar-pattern")return[];const[r,l]=t,s=So(e,t,i),a=n?[{t:"anchors",pts:t}]:[];if(!s){const h={stroke:"#808080",strokeWidth:1,inert:!0};return[{t:"line",a:{x:r.x,y:0},b:{x:r.x,y:99999},...h},{t:"line",a:{x:l.x,y:0},b:{x:l.x,y:99999},...h},{t:"line",a:r,b:l,...h},...a]}const c=o.color,f=Be(o);return s.lineMode?[{t:"polyline",pts:s.line,fill:"none",stroke:"transparent",strokeWidth:f*2},{t:"polyline",pts:s.line,fill:"none",stroke:c,strokeOpacity:.9,strokeWidth:2,inert:!0},...a]:[...s.bars.map(h=>({t:"rect",x:h.x-1-f,y:h.top-f,w:2+2*f,h:h.bottom-h.top+2*f,fill:"transparent"})),{t:"group",inert:!0,items:s.bars.map(h=>({t:"rect",x:h.x-1,y:h.top,w:2,h:Math.max(1,h.bottom-h.top),fill:c,fillOpacity:.9,stroke:c,strokeWidth:1}))},...a]}function Bi(e){let t=e>>>0;return()=>{t+=1831565813;let n=Math.imul(t^t>>>15,1|t);return n^=n+Math.imul(n^n>>>7,61|n),((n^n>>>14)>>>0)/4294967296}}const Ei=14;function mc(e,t,n,o,i){if(e.kind!=="ghost-feed")return[];if(e.ghost&&i&&e.points.length>=2){const k=e.ghost.amplitude,v=Math.max(0,Math.min(1,(o.variance??50)/100)),C=[];let T=8,F=!1;for(let A=0;A<e.points.length-1;A++){const O=i.timeToBarIndex(e.points[A].time),D=i.timeToBarIndex(e.points[A+1].time);if(O==null||D==null||O===D)continue;F=!0;const S=t[A].x<=t[A+1].x,E=i.priceToY(S?e.points[A].price:e.points[A+1].price),B=i.priceToY(S?e.points[A+1].price:e.points[A].price);if(E==null||B==null)continue;const I=Math.min(O,D),R=Math.abs(D-O)-(A===0?0:1),Y=R>1?(B-E)/(R-1):0;for(let J=0;J<R;J++){const gt=i.barIndexToTime(I+J),re=gt==null?null:i.timeToX(gt);if(re==null)continue;if(J>0){const Le=i.barIndexToTime(I+J-1),Se=Le==null?null:i.timeToX(Le);Se!=null&&(T=Math.abs(re-Se)||T)}const Tt=i.yToPrice(E+J*Y);if(Tt==null)continue;const le=Bi((e.ghost.seed^Math.imul(A,2654435769)^Math.imul(J,2654435761))>>>0),ke=k*(1-2*le())*v,mt=Math.max(1e-9,k*(1+(.5-le())*v)),xt=ke-mt/2,Vt=xt+le()*mt,Xt=xt+le()*mt,ve=i.priceToY(Tt+Vt),Wt=i.priceToY(Tt+xt+mt),Ze=i.priceToY(Tt+xt),Ke=i.priceToY(Tt+Xt);ve==null||Wt==null||Ze==null||Ke==null||C.push({x:re,openY:ve,highY:Wt,lowY:Ze,closeY:Ke,up:Xt>=Vt})}}if(F){const A=Math.floor(.3*T),O=o.ghostCandle??pr,D=i.priceToY(e.points[0].price),S=i.priceToY(e.points[0].price+k),E=D!=null&&S!=null?Math.abs(S-D):10,B=[];for(const R of C)O.drawWick&&B.push({t:"line",a:{x:R.x,y:R.highY},b:{x:R.x,y:R.lowY},stroke:O.wickColor,strokeWidth:1}),B.push({t:"rect",x:Math.round(R.x)-A-.5,y:Math.min(R.openY,R.closeY),w:2*A+1,h:Math.max(1,Math.abs(R.closeY-R.openY)),fill:R.up?O.upColor:O.downColor,stroke:O.drawBorder?R.up?O.borderUpColor:O.borderDownColor:"none",strokeWidth:1});const I=[{t:"polyline",pts:t,fill:"none",stroke:"transparent",strokeWidth:Math.max(12,E*2)},{t:"polyline",pts:t,fill:"none",stroke:"#808080",strokeWidth:1,inert:!0},{t:"group",inert:!0,opacity:1-(o.transparency??50)/100,items:B}];return n&&I.push({t:"anchors",pts:t}),I}}const[r,l]=t,s=Math.min(r.x,l.x),a=Math.max(r.x,l.x),c=Math.min(r.y,l.y),f=Math.max(r.y,l.y),h=a-s,u=f-c,d=Math.round((e.points[0].price+e.points[1].price)*1e3)^((N(e.points[0].time)??0)|0),x=Bi(d),p=h/Ei,y=Math.max(1,p*.6),b=u*.06,g=u*.12;let m=c+u/2;const w=[];for(let k=0;k<Ei;k++){const v=m,C=(x()-.5)*2*g;let T=v+C;T=Math.max(c+b,Math.min(f-b,T));const F=Math.min(v,T)-x()*b,A=Math.max(v,T)+x()*b;w.push({x:s+p*(k+.5),openY:v,highY:F,lowY:A,closeY:T,up:T<=v}),m=T}const M=[{t:"rect",x:s,y:c,w:h,h:u,fill:o.color,fillOpacity:.04,stroke:o.color,strokeWidth:o.width,dash:"4 3"},{t:"line",a:{x:s,y:c+u/2},b:{x:a,y:c+u/2},stroke:o.color,strokeWidth:1,strokeOpacity:.4,dash:"2 3",inert:!0},{t:"group",inert:!0,items:bc(w,y)}];if(n)for(const k of At(r,l))M.push({t:"circle",cx:k.x,cy:k.y,r:et,fill:"#fff",stroke:o.color,strokeWidth:1.5,cursor:"nwse-resize"});return M}const wc="#2e2e2e",Mc={dx:0,dy:1,blur:4,color:"rgba(0,0,0,0.4)"};function kc(e,t,n,o){const i=n/2,r=10+i,l=Math.min(e.y,t.y),s=Math.max(e.y,t.y);let a;if(e.y>t.y){a=l-r;const c=i-a;if(c>0){const f=s+r;f+i<=o?a=f:a+=c}}else{a=s+r;const c=a+i-o;if(c>0){const f=l-r;f-i>=0?a=f:a-=c}}return a}function Rn(e,t,n,o,i){const r=c=>c!==!1,l=[],[s,a]=e.points;if(!s||!a)return l;if(o){const c=s.price,h=a.price-c,u=(n==null?void 0:n.pipSize())??.01,d=Math.max(0,Math.min(8,Math.round(-Math.log10(u)))),x=r(t.showPriceRange),p=r(t.showPercentPriceRange),y=r(t.showPipsPriceRange);let b="";if(x&&(b+=pt(h,d)),p){const g=c!==0?100*h/Math.abs(c):0;x&&(b+=" ("),b+=`${pt(Math.round(g*100)/100,2)}%`,x&&(b+=")")}y&&(x?b+=p?" ":", ":p&&(b+=", "),b+=pt(Math.round(h/u),0)),b&&l.push(b)}if(i){const c=r(t.showBarsRange),f=r(t.showDateTimeRange),h=r(t.showVolume);let u="";const d=N(s.time),x=N(a.time),p=(n==null?void 0:n.timeToBarIndex(s.time))??null,y=(n==null?void 0:n.timeToBarIndex(a.time))??null;if(c&&p!=null&&y!=null&&(u+=`${y-p} bars`),f&&d!=null&&x!=null&&(c&&(u+=", "),u+=Sn(x-d)),u&&l.push(u),h&&n&&d!=null&&x!=null){const b=We(n.bars(),Math.min(d,x),Math.max(d,x));let g=0,m=!1;for(const w of b)w.volume!=null&&(g+=w.volume,m=!0);m&&l.push(`Vol ${es(g)}`)}}return l}function vc(e,t,n,o,i,r){if(!i.length)return[];const l=r.fontSize??12,s=l*.4+l/3,a=l*.2+l/3,c=Math.max(...i.map(d=>ft(d,l)))+s*2,f=l*i.length+8*(i.length-1)+a*2,h=kc(t,n,f,o),u=[];return r.fillLabelBackground!==!1&&u.push({t:"rect",x:e-c/2,y:h-f/2,w:c,h:f,rx:4,fill:r.labelBackgroundColor??wc,shadow:Mc}),i.forEach((d,x)=>{u.push({t:"text",x:e,y:h-f/2+a+x*(l+8)+l/2,text:d,size:l,fill:r.textColor??"#ffffff",anchor:"middle",baseline:"central"})}),[{t:"group",inert:!0,items:u}]}function Pi(e,t,n){const o=n.text??"";if(o==="")return null;const i=n.customTextSize??12,r=o.split(`
6
+ `),l=Math.ceil(i),s=Math.round((e.y+t.y)/2);return{x:(e.x+t.x)/2,cy:s,top:s-r.length*l/2,lines:r,lineH:l,fs:i}}function Lc(e,t,n){const o=Pi(e,t,n);if(!o||!ye(o.lines))return{items:[],clip:void 0};const i=o.fs/3,r=ai({x:o.x,y:o.cy},0,o.lines,o.fs,o.lineH,i,i,"middle","center",!!n.customTextBold,!!n.customTextItalic);return r.length?{items:[{t:"clip",name:"text",polys:[r]}],clip:"text"}:{items:[],clip:void 0}}function Sc(e,t,n){const o=Pi(e,t,n);return o?o.lines.map((i,r)=>({t:"text",x:o.x,y:o.top+r*o.lineH,text:i,anchor:"middle",baseline:"hanging",size:o.fs,weight:n.customTextBold?700:400,fontStyle:n.customTextItalic?"italic":"normal",fill:n.customTextColor??"#2962ff",inert:!0,pre:!0})):[]}function Cc(e){return e.fillBackground===!1?0:Math.max(0,Math.min(1,(100-(e.transparency??85))/100))}function Fn(e,t,n,o,i){const r=Cc(i);return{t:"rect",x:e,y:t,w:n,h:o,fill:r>0?i.backgroundColor??i.color:"transparent",fillOpacity:r>0?r:1}}const zt=(e,t,n)=>({t:"line",a:e,b:t,stroke:n.color,strokeWidth:n.width,cap:"round"}),Xe=(e,t,n)=>({t:"path",d:De(e,t,n.width),fill:"none",stroke:n.color,strokeWidth:n.width,cap:"round",join:"round"});function On(e,t,n,o,i,r,l,s,a){const c=Lc(n,o,s),f=[...c.items,...e,{t:"group",clip:c.clip,items:t},...vc((n.x+o.x)/2,n,o,l,a,s),...Sc(i[0],i[1],s)];return r&&f.push({t:"anchors",pts:i}),f}function Tc(e,t,n,o,i,r,l){if(e.kind!=="price-range")return[];const[s,a]=t,c=r.extendLeft?0:Math.min(s.x,a.x),f=r.extendRight?o:Math.max(s.x,a.x),h=Math.round((s.x+a.x)/2),u=Rn(e,r,l,!0,!1),d=[zt({x:h,y:s.y},{x:h,y:a.y},r)];Math.abs(a.y-s.y)>=15*r.width&&d.push(Xe({x:h,y:s.y},{x:h,y:a.y},r));const x=[Fn(c,Math.min(s.y,a.y),Math.max(1,f-c),Math.abs(a.y-s.y),r),zt({x:c,y:s.y},{x:f,y:s.y},r),zt({x:c,y:a.y},{x:f,y:a.y},r)];return On(x,d,s,a,t,n,i,r,u)}function Ac(e,t,n,o,i,r){if(e.kind!=="date-range")return[];const[l,s]=t,a=i.extendTop?0:Math.min(l.y,s.y),c=i.extendBottom?o:Math.max(l.y,s.y),f=Math.round((l.y+s.y)/2),h=Rn(e,i,r,!1,!0),u=[zt({x:l.x,y:f},{x:s.x,y:f},i)];Math.abs(s.x-l.x)>=15*i.width&&u.push(Xe({x:l.x,y:f},{x:s.x,y:f},i));const d=[Fn(Math.min(l.x,s.x),a,Math.max(1,Math.abs(s.x-l.x)),Math.max(1,c-a),i),zt({x:l.x,y:a},{x:l.x,y:c},i),zt({x:s.x,y:a},{x:s.x,y:c},i)];return On(d,u,l,s,t,n,o,i,h)}function $c(e,t,n,o,i,r){if(e.kind!=="date-and-price-range")return[];const[l,s]=t,a=Math.round((l.y+s.y)/2),c=Math.round((l.x+s.x)/2),f=Rn(e,i,r,!0,!0),h=i.drawBorder?i.borderWidth??1:0,u=h/2,d=l.x+Math.sign(s.x-l.x)*u,x=s.x+Math.sign(l.x-s.x)*u,p=l.y+Math.sign(s.y-l.y)*u,y=s.y+Math.sign(l.y-s.y)*u,b=[Fn(Math.min(l.x,s.x),Math.min(l.y,s.y),Math.max(1,Math.abs(s.x-l.x)),Math.max(1,Math.abs(s.y-l.y)),i)];h>0&&b.push({t:"rect",x:Math.min(l.x,s.x),y:Math.min(l.y,s.y),w:Math.abs(s.x-l.x),h:Math.abs(s.y-l.y),fill:"none",stroke:i.borderColor??i.color,strokeWidth:h});const g=[zt({x:d,y:a},{x,y:a},i),zt({x:c,y:p},{x:c,y},i)];return Math.abs(s.x-l.x)>=25*i.width&&g.push(Xe({x:d,y:a},{x,y:a},i)),Math.abs(s.y-l.y)>=25*i.width&&g.push(Xe({x:c,y:p},{x:c,y},i)),On(b,g,l,s,t,n,o,i,f)}function Ic(e,t,n,o,i,r){const l=i.regressionLines??Kn,s=ho(e,r,o);if(!s){const u=[{t:"line",a:t[0],b:t[1],stroke:l.base.color,strokeWidth:l.base.width,dash:P({...i,lineStyle:l.base.style}),cap:"round"}];return n&&u.push({t:"anchors",pts:t}),u}const a=[{seg:s.lower,st:l.down},{seg:s.center,st:l.base},{seg:s.upper,st:l.up}].filter(u=>!!u.seg&&u.st.visible),c=Z(i),f=[];c>0&&a.slice(1).forEach((u,d)=>{const x=a[d].seg;f.push({t:"polygon",pts:[x[0],x[1],u.seg[1],u.seg[0]],fill:u.st.color,fillOpacity:c,stroke:"none",inert:!0})});for(const u of a)f.push({t:"hit",a:u.seg[0],b:u.seg[1],width:L*2},{t:"line",a:u.seg[0],b:u.seg[1],stroke:u.st.color,strokeWidth:u.st.width,dash:P({...i,lineStyle:u.st.style}),cap:"round"});const h=s.lower;return i.showPearsons!==!1&&h&&f.push({t:"text",x:h[0].x,y:h[0].y+4,text:String(s.pearsons),anchor:"middle",baseline:"hanging",size:12,fill:l.down.color,inert:!0}),n&&f.push({t:"anchors",pts:s.anchors}),f}function Bc(e,t,n,o,i,r){const l=P(i),s=bo(e,r),a=[{t:"circle",cx:t[0].x,cy:t[0].y,r:et+L,fill:"transparent"}];if(n&&a.push({t:"anchors",pts:t}),s.line.length<2){const h={x:o,y:t[0].y};return[{t:"hit",a:t[0],b:h,width:12},{t:"line",a:t[0],b:h,stroke:i.color,strokeWidth:i.width,dash:l},...a]}const c=[],f=(h,u,d,x)=>[{t:"polyline",pts:h,fill:"none",stroke:"transparent",strokeWidth:L*2,join:"round"},{t:"polyline",pts:h,fill:"none",stroke:u,strokeWidth:d,dash:x,join:"round"}];for(const h of s.bands)if(!(h.upper.length<2||h.lower.length<2)){i.fillBackground===!0&&h.index===0&&c.push({t:"polygon",pts:[...h.upper,...h.lower.slice().reverse()],fill:i.backgroundColor??"#4caf50",fillOpacity:Z(i),stroke:"none",inert:!0});for(const[u,d]of[["upper",h.upper],["lower",h.lower]]){const x=hn(i,h.index,u);x.visible&&c.push(...f(d,x.color,x.width))}}return c.push(...f(s.line,i.color,i.width,l),...a),c}function zi(e,t,n){const{left:o,right:i,top:r,bottom:l,vp:s}=e,a=Math.max(1,i-o),c=.3*a,f=s.rows.length,h=(s.hi-s.lo)/f,u=y=>{const b=t.priceToY(s.lo+(y+1)*h)??r,g=t.priceToY(s.lo+y*h)??l;return{y:Math.min(b,g),h:Math.abs(g-b)}},d=u(s.poc),x=d.y+d.h/2,p=[];return s.rows.forEach((y,b)=>{const g=u(b),m=b>=s.vaFrom&&b<=s.vaTo,w=s.maxTotal>0?y.up/s.maxTotal*c:0,M=s.maxTotal>0?y.down/s.maxTotal*c:0,k=Math.max(1,g.h-1),v=n?i-w:o,C=n?i-w-M:o+w;p.push({t:"rect",x:v,y:g.y,w,h:k,fill:m?"rgba(38,198,218,0.75)":"rgba(38,198,218,0.5)"},{t:"rect",x:C,y:g.y,w:M,h:k,fill:m?"rgba(236,64,122,0.75)":"rgba(236,64,122,0.5)"})}),p.push({t:"line",a:{x:o,y:x},b:{x:i,y:x},stroke:"#DBDBDB",strokeWidth:2}),[{t:"rect",x:o,y:r,w:a,h:Math.max(1,l-r),fill:"rgba(38,198,218,0.05)"},{t:"group",inert:!0,items:p}]}function Ec(e,t,n,o){const i=Mo(e,t,o),r=i&&o?zi(i,o,!1):[];return n&&r.push({t:"anchors",pts:t}),r}function Pc(e,t,n,o){const i=wo(e,t,o),r=i&&o?zi(i,o,!0):[];return n&&r.push({t:"anchors",pts:[t[0]]}),r}const Wi=new Map;function zc(e,t){let n=Wi.get(t);n||(n=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"numeric",day:"numeric",weekday:"short",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}),Wi.set(t,n));const o=n.formatToParts(new Date(e*1e3)),i=r=>{var l;return((l=o.find(s=>s.type===r))==null?void 0:l.value)??""};return{y:Number(i("year")),m:Number(i("month")),d:Number(i("day")),wd:i("weekday"),hh:i("hour"),mi:i("minute"),ss:i("second")}}const Dn=(e,t)=>String(e).padStart(t,"0");function Wc(e,t){const n=zc(e,t);return{date:`${Dn(n.y,4)}-${Dn(n.m,2)}-${Dn(n.d,2)}`,time:`${n.hh}:${n.mi}`}}const Ge={href:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAQAAABKmM6bAAAAZ0lEQVR4Xl2OsQmAMBRErwgSsHAJV3GHgEVKl3ADixSClViKYPkHfEI+Wsg1j8dxnCQCiQ1jJRFcFIybHsNYCCJXvCSsJonzp/YXbiKzs7d8pavyEBP2yQEji5YV+1KIkmjI/ouRID31wXKLSuZPUAAAAABJRU5ErkJggg==",w:9,h:9},Rc={href:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAKCAQAAADI+WwIAAAAb0lEQVQIHWXAMQpBAQAG4L9eKQdQSr3JpFzC5CoOoJzBSUzK+iallNWkrG99pUymDxHw5Z+RdX4ZOpnmm57aXiuWunnScXAxTGLhqMyNth1muVNq1AYKK2wVeTBGo8JZP2/mgEk+KWxQ5ZfSUS8vV97kThm/FD/aAAAAAElFTkSuQmCC",w:11,h:10},Fc={href:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAQAAABKmM6bAAAARElEQVR4AWMgHvy/9//5f34gzQZiQYSeAyEPkOYE0iAhMJOTAc4ixXjR/13/r/7////h/zn/pSFCT/43/lcHS6X9fwgANMArS3ikrioAAAAASUVORK5CYII=",w:9,h:9};function _n(e,t,n,o,i,r,l,s){const a=l.fontSize??12,c=4,f=a/3,h=Math.max(...i.map(x=>ft(x,a)))+c*2,u=a*i.length+f*2,d=n==="bottom"?t-o-u:n==="top"?t+o:t-u/2+o;return{t:"group",inert:!0,items:[{t:"rect",x:e-h/2,y:d,w:h,h:u,rx:4,fill:r,stroke:s??"none",strokeWidth:s?1:0},...i.map((x,p)=>({t:"text",x:e,y:d+f+p*a+a/2,text:x,anchor:"middle",baseline:"central",size:a,fill:l.textColor??"#ffffff"}))]}}function Ri(e,t,n,o,i,r){const l=no(e,t,r);if(!l)return[];const[s,a]=t,c=e.points[0].price,f=Math.min(s.x,a.x),h=Math.max(s.x,a.x),u=Math.max(8,h-f),d=(f+h)/2,x=at(i.stopColor??"#f23645").hex,p=at(i.targetColor??"#089981").hex,y=i.stopTransparency??80,b=i.targetTransparency??80,g=kt(p,100-b),m=kt(x,100-y),{yStop:w,yTarget:M,stop:k,profit:v}=l,C=i.accountSize??1e3,{qty:T,shown:F}=Cr(i,c,k),A=Ce=>parseFloat(Ce.toFixed(2)),O=A(C+v*T),D=A(C-k*T),S=k>0?Math.round(100*v/k)/100:0,E=o==="long"?1:-1,B=Tr(e,o,c-E*k,c+E*v,r),I=B?(B.closePrice-c)*E:null,R=(r==null?void 0:r.pipSize())??.01,Y=Math.max(0,Math.min(8,Math.round(-Math.log10(R)))),J=eo(i,"tp",v,c,R,Y,O,v*T),gt=eo(i,"sl",k,c,R,Y,D,-k*T),re=vr(i,I!=null?pt(I,Y):null,!!(B!=null&&B.closed),F,S),Tt=re?re.split(`
7
+ `):[],le=I!=null&&I<0?x:I!=null&&I>0?p:i.color,ke=Ce=>{var ur;const hr=(ur=((r==null?void 0:r.bars())??[])[Ce])==null?void 0:ur.time;return hr!=null&&r?r.timeToX(hr):null},mt=B&&r?r.priceToY(B.closePrice):null,xt=(B==null?void 0:B.entryIndex)!=null?ke(B.entryIndex):a.x,Vt=(B==null?void 0:B.closeIndex)!=null?ke(B.closeIndex):a.x,Xt=xt!=null&&Vt!=null&&mt!=null&&xt!==Vt?{x:Math.min(xt,Vt),y:Math.min(s.y,mt),w:Math.abs(Vt-xt),h:Math.abs(mt-s.y)}:null,ve=B?ke(B.closed?B.closeIndex:B.barIndex):null,Wt=(B==null?void 0:B.entryIndex)!=null&&xt!=null&&ve!=null&&mt!=null?{from:{x:xt,y:s.y},to:{x:ve,y:mt}}:null,Ze=n||!!i.showStats,Ke=Math.max(0,ft(J,i.fontSize??12),ft(gt,i.fontSize??12),...Tt.map(Ce=>ft(Ce,i.fontSize??12)))+8,Le=h-f-Ke-et<=8,Se=Le?et+8:0,Aa=Le?(M<w?1:-1)*(v>k?-1:1)*(.5*((i.fontSize??12)*2+2*(i.fontSize??12)/3)+et+8):0,wt=[{t:"rect",x:f,y:Math.min(M,w),w:u,h:Math.abs(M-w),fill:"transparent"},{t:"rect",x:f,y:Math.min(s.y,w),w:u,h:Math.abs(w-s.y),fill:m}];return Xt&&I!=null&&I<0&&wt.push({t:"rect",...Xt,fill:x,fillOpacity:1-(y/100)**3}),wt.push({t:"rect",x:f,y:Math.min(s.y,M),w:u,h:Math.abs(M-s.y),fill:g}),Xt&&I!=null&&I>0&&wt.push({t:"rect",...Xt,fill:p,fillOpacity:1-(b/100)**3}),Wt&&wt.push({t:"line",a:Wt.from,b:Wt.to,stroke:i.color,strokeWidth:1,dash:"6 4",inert:!0},{t:"path",d:De(Wt.from,Wt.to,1),fill:"none",stroke:i.color,strokeWidth:1,inert:!0}),wt.push({t:"line",a:{x:f,y:s.y},b:{x:h,y:s.y},stroke:i.color,strokeWidth:i.width},{t:"line",a:{x:f,y:M},b:{x:h,y:M},stroke:g,strokeWidth:i.width},{t:"line",a:{x:f,y:w},b:{x:h,y:w},stroke:m,strokeWidth:i.width}),Ze&&(J&&wt.push(_n(d,M,M<s.y?"bottom":"top",Se,[J],p,i)),Tt.length>0&&wt.push(_n(d,s.y,"middle",Aa,Tt,le,i,"#ffffff")),gt&&wt.push(_n(d,w,w>s.y?"top":"bottom",Se,[gt],x,i))),n&&wt.push({t:"anchors",pts:l.anchors,squares:Nt.position}),wt}const Oc="#202020",Fi=Ge.w;function Oi(e,t,n){const o=N(e);if(o==null)return"";const i=(n==null?void 0:n.timeInfo())??{timeZone:"UTC",intraday:!0},{date:r,time:l}=Wc(o,i.timeZone);return i.intraday?`${r}${t}${l}`:r}function Di(e){const t=u=>ft(u.text,u.size)+(u.clockThen?Fi+2*ft(" ",u.size)+ft(u.clockThen,u.size):0),n=Math.max(...e.rows.map(t))+12,o=e.height,i=Math.max(20,Math.min(n-15,e.cx+n-e.paneW+5)),r=e.cx-i,l=e.below?e.y+11:e.y-11-o,s=e.below?l:l+o,a=e.y+(e.below?3:-3);let c=l+4;const f=[{t:"rect",x:r,y:l,w:n,h:o,rx:3,fill:e.bg,fillOpacity:e.opacity,stroke:e.stroke,strokeOpacity:e.opacity,strokeWidth:2},{t:"path",d:`M ${e.cx-5} ${s} L ${e.cx} ${a} L ${e.cx+5} ${s} Z`,fill:e.bg,fillOpacity:e.opacity},{t:"circle",cx:e.cx,cy:e.y,r:3,fill:Oc}];for(const u of e.rows){const d=u.dy!=null?l+u.dy:c;if(c=d+u.size+4,f.push({t:"text",x:r+6,y:d,text:u.text,size:u.size,fill:e.fg,baseline:"hanging"}),u.clockThen){const x=r+6+ft(u.text,u.size)+ft(" ",u.size);f.push({t:"image",href:Ge.href,x,y:d+1,w:Ge.w,h:Ge.h},{t:"text",x:x+Fi+ft(" ",u.size),y:d,text:u.clockThen,size:u.size,fill:e.fg,baseline:"hanging"})}}const h=e.banner;if(h){const d=h.above?l-18-2:l+o+2,x=ts(h.text,14),p=r+Math.round((n-x)/2),y=h.icon,b=h.above?d+Math.abs(18-y.h)/2:d+8-Math.abs(18-y.h)/2;f.push({t:"rect",x:r-1,y:d,w:n+2,h:18,rx:5,fill:h.bg,fillOpacity:e.opacity},{t:"text",x:p,y:d+3,text:h.text,size:14,weight:"bold",fill:h.fg,baseline:"hanging"},{t:"image",href:y.href,x:p-y.w-4,y:b,w:y.w,h:y.h})}return{t:"group",inert:!0,items:f}}function Dc(e,t,n,o,i,r){if(e.kind!=="position-forecast")return[];const[l,s]=t,a=s.y<=l.y,c=go(l,s),f=c[c.length-2]??l,h=Math.hypot(s.x-f.x,s.y-f.y)||1,u=(s.x-f.x)/h,d=(s.y-f.y)/h,x=Math.max(8,4*i.width),p=s.x-u*x,y=s.y-d*x,b=[s,{x:p-d*(x/2),y:y+u*(x/2)},{x:p+d*(x/2),y:y-u*(x/2)}],g=e.points[1].price-e.points[0].price,m=e.points[0].price!==0?g/Math.abs(e.points[0].price)*100:0,w=N(e.points[0].time),M=N(e.points[1].time),k=w!=null&&M!=null?Sn(M-w):"",v=(r==null?void 0:r.pipSize())??.01,C=Math.max(0,Math.min(8,Math.round(-Math.log10(v)))),T=Wr(e,r),F=Math.max(0,Math.min(1,(100-(i.transparency??10))/100)),A=[{t:"polyline",pts:c,fill:"none",stroke:"transparent",strokeWidth:12},{t:"polyline",pts:c,fill:"none",stroke:i.color,strokeWidth:i.width,join:"round"},{t:"polygon",pts:b,fill:i.color,stroke:i.color,strokeWidth:1,join:"round"},Di({cx:l.x,y:l.y,below:a,paneW:o,height:32,rows:[{text:e.points[0].price.toFixed(C),size:12,dy:4},{text:Oi(e.points[0].time," ",r),size:10,dy:18}],bg:i.sourceBackColor??"#2962FF",stroke:i.sourceStrokeColor??"#2962FF",fg:i.sourceTextColor??"#ffffff",opacity:F}),Di({cx:s.x,y:s.y,below:!a,paneW:o,height:38,rows:[{text:`${pt(g,C)} (${pt(Math.round(m*100)/100,2)}%)${k?` in ${k}`:""}`,size:14,dy:5},{text:e.points[1].price.toFixed(C),size:11,dy:22,clockThen:Oi(e.points[1].time," ",r)}],bg:i.targetBackColor??"#2962FF",stroke:i.targetStrokeColor??"#2962FF",fg:i.targetTextColor??"#ffffff",opacity:F,banner:T==="waiting"?void 0:{text:T==="success"?"SUCCESS":"FAILURE",icon:T==="success"?Rc:Fc,bg:T==="success"?i.successBackground??"#4caf50":i.failureBackground??"#F23645",fg:T==="success"?i.successTextColor??"#ffffff":i.failureTextColor??"#ffffff",above:a}})];return n&&A.push({t:"anchors",pts:t}),A}const _i={dx:0,dy:2,blur:4,color:"rgba(0,0,0,0.4)"},_c={dx:0,dy:1,blur:4,color:"rgba(0,0,0,0.4)"},ge=e=>kt(at(e).hex,50);function Hc(e,t,n,o){const i=e.style,r=Uo(e,t),l=yt(e).faint,s=Math.max(1,Math.round(Math.max((i.fontSize??14)/12,1))),a=n?"#2962ff":o?"rgba(41, 98, 255, 0.4)":null,c=r.box,f=[{t:"rect",x:c.left,y:c.top,w:c.width,h:c.height,fill:i.fillBackground?kt(at(i.backgroundColor??i.color).hex,100-(i.transparency??75)):"transparent"}];if(i.drawBorder&&f.push({t:"rect",x:c.left-s/2,y:c.top-s/2,w:c.width+s,h:c.height+s,fill:"none",stroke:i.borderColor??"#707070",strokeWidth:s,inert:!0}),f.push(U(r,l?ge(i.color):i.color,i.bold,i.italic)),a){const h=i.drawBorder?s:0;f.push({t:"path",d:`M ${c.left-h-2} ${c.top-h-2} h ${c.width+2*h+4} v ${c.height+2*h+4} h ${-(c.width+2*h+4)} Z M ${c.left-h} ${c.top-h} v ${c.height+2*h} h ${c.width+2*h} v ${-(c.height+2*h)} Z`,fill:a,fillRule:"evenodd",inert:!0})}return n&&i.wordWrap&&f.push({t:"anchors",pts:[{x:c.left+c.width,y:c.top+c.height/2}]}),f}function Nc(e,t,n,o){const i=e.style,r=[{t:"path",d:sl,transform:`translate(${t.x-12} ${t.y-30})`,fill:i.color,fillRule:"evenodd"}];if(!n)return r;const l=Xo(e,t,o),s=yt(e).faint,a=i.textColor??"#dbdbdb",c=[];return i.fillBackground!==!1&&c.push({t:"path",d:Go(l,t.x),fill:kt(at(i.backgroundColor??"#2e2e2e").hex,100-(i.transparency??0)),shadow:_i}),i.drawBorder&&c.push({t:"path",d:Go(l,t.x),fill:"none",stroke:i.borderColor??"#4a4a4a",strokeWidth:1,inert:!0}),l.lines.forEach((f,h)=>{c.push({t:"text",x:l.left+12,y:l.top+12+l.fs/2+h*(l.fs+5),text:f,baseline:"central",size:l.fs,weight:i.bold?700:400,fontStyle:i.italic?"italic":"normal",fill:s?ge(a):a,pre:!0,inert:!0})}),r.push({t:"group",items:c},{t:"anchors",pts:[t]}),r}function Yc(e,t,n,o){const[i,r]=t;if(!r)return[];const{txt:l,faint:s,fs:a,box:c}=Yo(e,o,i,r),f=c.left,h=c.top,u=c.width,d=c.height,x=o.color??"#dbdbdb",p=[{t:"hit",a:i,b:r,width:L*2},{t:"line",a:i,b:r,stroke:x,strokeWidth:1},{t:"circle",cx:i.x,cy:i.y,r:2,fill:x},{t:"circle",cx:i.x,cy:i.y,r:2.5,fill:"none",stroke:"#1f1f1f",strokeWidth:1},{t:"rect",x:f,y:h,w:u,h:d,rx:4,fill:o.fillBackground===!1?"transparent":o.backgroundColor??"#2e2e2e",stroke:o.drawBorder?o.borderColor??"#4a4a4a":void 0,strokeWidth:o.drawBorder?1:void 0,shadow:o.fillBackground===!1&&!o.drawBorder?void 0:_i},{t:"text",x:f+8,y:h+d/2,text:l,size:a,weight:o.bold?700:400,fontStyle:o.italic?"italic":"normal",fill:o.textColor??"#dbdbdb",baseline:"central",opacity:s?.6:1}];return n&&p.push({t:"anchors",pts:t}),p}function Uc(e,t,n,o){const[i]=t,{l:r,r:l}=Vo(e,i),s=yt(e).faint,a=o.textColor??"#ffffff",c=r.box,f=[{t:"path",d:ll(c.left,c.top,c.width,c.height,[l,l,l,2]),fill:kt(at(o.backgroundColor??o.color).hex,100-(o.transparency??0)),stroke:o.borderColor??o.color,strokeWidth:2},U(r,s?ge(a):a)];return n&&f.push({t:"anchors",pts:t}),f}function Vc(e,t,n,o,i){const r=n?mn(e,t,n,o):null;if(!r)return[];const l=[{t:"line",a:{x:r.x,y:r.poleStart},b:{x:r.x,y:r.poleEnd},stroke:_t.pole,strokeWidth:1}];r.gap&&l.push({t:"line",a:{x:r.x,y:r.gap[0]},b:{x:r.x,y:r.gap[1]},stroke:_t.pole,strokeWidth:1}),e.style.showImage&&l.push({t:"circle",cx:r.x,cy:r.plateY,r:35,fill:e.style.plateColor??"#2962ff",stroke:_t.plateBorder,strokeWidth:1,shadow:_c},{t:"text",x:r.x,y:r.plateY,text:e.glyph||"🙂",anchor:"middle",baseline:"central",size:32,inert:!0});const s=r.l.box;return l.push({t:"rect",x:s.left,y:s.top,w:s.width,h:s.height,rx:4,fill:_t.labelBg,stroke:_t.labelBorder,strokeWidth:1},U(r.l,yt(e).faint?ge(_t.labelText):_t.labelText,e.style.bold,e.style.italic)),i&&l.push({t:"anchors",pts:[r.anchor],squares:Nt.single}),l}function Xc(e,t,n,o,i){const[r,l]=t,s=(i==null?void 0:i.pipSize())??.01,a=Math.max(0,Math.min(8,Math.round(-Math.log10(s)))),c=ao(e,t,a),f=(()=>{if(!e.text)return null;const x=r.x<l.x?r:l,p=x===r?l:r,y=o.horzLabelsAlign??"center",b=y==="left"?x:y==="right"?p:{x:(r.x+l.x)/2,y:(r.y+l.y)/2},g=Math.atan((p.y-x.y)/(p.x-x.x));return G({x:b.x,y:b.y,text:e.text,fs:o.fontSize??14,bold:o.bold,italic:o.italic,vert:o.vertLabelsAlign??"bottom",horz:y,angle:Number.isNaN(g)?0:g})})(),h=f&&(o.vertLabelsAlign??"bottom")==="middle"?f.poly:null,u=h&&h.length?"text":void 0,d=[{t:"hit",a:r,b:l,width:12}];if(f&&d.push(U(f,o.textColor??"#2962ff",o.bold,o.italic)),d.push({t:"circle",cx:r.x,cy:r.y,r:2,fill:o.color}),u&&d.push({t:"clip",name:u,polys:[h]}),d.push({t:"line",a:r,b:l,stroke:o.color,strokeWidth:1,cap:"round",clip:u}),c){const x=c.box;d.push({t:"rect",x:x.left,y:x.top,w:x.width,h:x.height,rx:4,fill:o.priceLabelBackgroundColor??"#2962ff",stroke:o.priceLabelBorderColor??"#2962ff",strokeWidth:1},U(c,o.priceLabelTextColor??"#ffffff",o.priceLabelBold,o.priceLabelItalic))}return d.push({t:"circle",cx:r.x,cy:r.y,r:2.5,fill:"none",stroke:"#0f0f0f",strokeWidth:1,inert:!0}),n&&d.push({t:"anchors",pts:t}),d}function Gc(e,t,n,o){const[i,r]=t,l=qo(e,r),s=yt(e).faint,a=o.textColor??"#ffffff",c=[{t:"path",d:al(l,i,r),fill:kt(at(o.backgroundColor??o.color).hex,100-(o.transparency??50)),stroke:o.borderColor??o.color,strokeWidth:o.width,join:"round"}];return l.lines.forEach((f,h)=>{c.push({t:"text",x:l.x+10,y:l.y+10+h*l.fs+l.fs/2,text:f,baseline:"central",size:l.fs,weight:o.bold?700:400,fontStyle:o.italic?"italic":"normal",fill:s?ge(a):a,pre:!0})}),n&&c.push({t:"anchors",pts:l.wrap!=null?[i,{x:r.x+l.wrap/2+10,y:r.y}]:[i]}),c}function jc(e,t,n,o){const i=xn(e,t),r=e.style,l=i.right-i.left,s=i.bottom-i.top;let a="";for(const x of i.ys)a+=`M${i.left} ${x}h${l}v${dt}h${-l}Z`;for(const x of i.xs)a+=`M${x} ${i.top}h${dt}v${s}h${-dt}Z`;let c="";if(o!=null&&o.cell&&o.cell[0]<i.ys.length-1&&o.cell[1]<i.xs.length-1){const[x,p]=o.cell,y=i.xs[p],b=i.xs[p+1],g=i.ys[x],m=i.ys[x+1],w=dt,M=Or;c=[[y+w,g+w,b-y-w,M],[y+w,m-M,b-y-w,M],[y+w,g+w,M,m-g-w],[b-M,g+w,M,m-g-w]].map(([v,C,T,F])=>`M${v} ${C}h${T}v${F}h${-T}Z`).join("")}let f="";o!=null&&o.edge&&(o.edge.col!=null&&i.xs[o.edge.col+1]!=null&&(f+=`M${i.xs[o.edge.col+1]-3} ${i.top}h7v${i.bottom-i.top}h-7Z`),o.edge.row!=null&&i.ys[o.edge.row+1]!=null&&(f+=`M${i.left} ${i.ys[o.edge.row+1]-3}h${i.right-i.left}v7h${-(i.right-i.left)}Z`));const h=r.horzLabelsAlign??"left",u=[];i.cells.forEach((x,p)=>{x.forEach((y,b)=>{var v;const g=o!=null&&o.editing&&o.cell&&o.cell[0]===p&&o.cell[1]===b?[]:((v=i.lines[p])==null?void 0:v[b])??[],m=i.xs[b],w=i.xs[b+1],M=h==="right"?w-dt-Dt:h==="center"?m+(w-m)/2:m+dt+Dt,k=i.ys[p]+dt+Dt+i.fs/2+.05*i.fs;g.forEach((C,T)=>{u.push({t:"text",x:M,y:k+T*i.fs*Ao,text:C,anchor:h==="right"?"end":h==="center"?"middle":"start",baseline:"central",size:i.fs,fill:r.textColor??"#dbdbdb",pre:!0})})})});const d=[{t:"rect",x:i.left-3,y:i.top-3,w:l+7,h:s+7,fill:"transparent"},{t:"rect",x:i.left,y:i.top,w:l,h:s,fill:r.backgroundColor??"#0f0f0f"},{t:"path",d:a,fill:r.color,crisp:!0}];return c&&d.push({t:"path",d:c,fill:Dr,crisp:!0}),d.push({t:"group",inert:!0,items:u}),f&&d.push({t:"path",d:f,fill:_r,inert:!0}),n&&d.push({t:"anchors",pts:Ro(i)}),d}function qc(e,t,n){var r,l;const o=Ho(e,t);if(!o)return[];const i=[{t:"image",href:((l=gn((r=e.image)==null?void 0:r.name))==null?void 0:l.url)??"",x:o.left,y:o.top,w:o.right-o.left,h:o.bottom-o.top,stretch:!0,opacity:(100-(e.style.transparency??0))/100}];return n&&i.push({t:"anchors",pts:No(o)}),i}function je(e,t,n){const{w:o,h:i,coords:r,selected:l}=n,s=!!n.hovered,a=l||s,c=e.style;switch(e.kind){case"horizontal-line":return ss(t,l,o,c);case"vertical-line":return cs(t,l,i,c);case"cross-line":return as(t,l,o,i,c);case"trend-line":return c.extendLeft||c.extendRight?_e(e,t,l,o,i,c,!!c.extendLeft,!!c.extendRight,r,a):bi(e,t,l,o,i,c,r,a);case"horizontal-ray":return fs(t,l,o,c);case"ray":return _e(e,t,l,o,i,c,c.extendLeft??!1,c.extendRight??!0,r,a);case"extended-line":return _e(e,t,l,o,i,c,c.extendLeft??!0,c.extendRight??!0,r,a);case"info-line":return hs(e,t,l,o,i,c,r,a);case"trend-angle":return us(e,t,l,o,i,c,r,a);case"arrow":{const f={...c,leftEnd:c.leftEnd??0,rightEnd:c.rightEnd??1};return f.extendLeft||f.extendRight?_e(e,t,l,o,i,f,!!f.extendLeft,!!f.extendRight,r,a):bi(e,t,l,o,i,f,r,a)}case"long-position":return Ri(e,t,l,"long",c,r);case"short-position":return Ri(e,t,l,"short",c,r);case"position-forecast":return Dc(e,t,l,o,c,r);case"parallel-channel":return ps(t,l,c,o,i);case"disjoint-channel":return bs(e,t,l,c,o,i,r);case"flat-top-bottom":return gs(e,t,l,c,o,i,r);case"fib-retracement":return ms(e,t,l,o,c,r);case"trend-based-fib-extension":return ws(e,t,l,o,c,r);case"fib-channel":return Ms(e,t,l,c,r,o,i);case"trend-based-fib-time":return ks(e,t,l,i,c,r);case"fib-time-zone":return vs(t,l,i,c);case"fib-circles":return Ss(e,t,l,c);case"fib-speed-resistance-fan":return Cs(e,t,l,o,i,c,r);case"fib-speed-resistance-arcs":return Ts(t,l,c);case"fib-spiral":return As(t,l,o,i,c);case"fib-wedge":return $s(t,l,c);case"pitchfan":return Is(t,l,o,c);case"pitchfork":case"schiff-pitchfork":case"modified-schiff-pitchfork":case"inside-pitchfork":return zs(e.kind,t,l,o,c);case"gann-fan":return Es(t,l,o,i,c);case"gann-box":return Ps(e,t,l,c,r);case"gann-square-fixed":case"gann-square":return Bs(e,t,l,c,r);case"rectangle":return Fs(e,t,l,o,c,s);case"rotated-rectangle":return Os(e,t,l,c);case"circle":return Ds(e,t,l,c,s);case"ellipse":return _s(e,t,l,c,s);case"triangle":return Hs(t,l,c,s);case"arc":return Ns(t,l,c);case"curve":return Ys(t,l,c);case"double-curve":return Us(t,l,c);case"sector":return Vs(t,l,c);case"cyclic-lines":return Xs(t,l,o,i,c);case"sine-line":return Gs(t,l,o,c);case"time-cycles":return js(t,l,o,c);case"abcd-pattern":case"xabcd-pattern":case"cypher-pattern":case"head-and-shoulders":case"triangle-pattern":case"three-drives-pattern":case"elliott-impulse":case"elliott-correction":case"elliott-triangle":case"elliott-double-combo":case"elliott-triple-combo":case"polyline":case"path":case"brush":case"highlighter":return lc(e,t,l,c);case"arrow-marker":return cc(t,l,c);case"arrow-mark-up":return $i(e,t,l,c,"up");case"arrow-mark-down":return $i(e,t,l,c,"down");case"flag-mark":return hc(t,l,c);case"price-label":return uc(e,t,l,c,r);case"font-icon":return xc(e,t,l);case"bar-pattern":return gc(e,t,l,c,r);case"ghost-feed":return mc(e,t,l,c,r);case"price-range":return Tc(e,t,l,o,i,c,r);case"date-range":return Ac(e,t,l,i,c,r);case"date-and-price-range":return $c(e,t,l,i,c,r);case"regression-trend":return Ic(e,t,l,o,c,r);case"anchored-vwap":return Bc(e,t,l,o,c,r);case"fixed-range-volume-profile":return Ec(e,t,l,r);case"anchored-volume-profile":return Pc(e,t,l,r);case"text":return Hc(e,t[0],n.textSelected??l,s);case"pin":return Nc(e,t[0],l,o);case"note":return Yc(e,t,l,c);case"comment":return Uc(e,t,l,c);case"price-note":return Xc(e,t,l,c,r);case"signpost":return Vc(e,t[0],r,i,l);case"callout":return Gc(e,t,l,c);case"table":return jc(e,t[0],l,n.tableUi??null);case"image":return qc(e,t[0],l)}return[]}function Hi(e,t){return e.map(n=>({t:"group",inert:!0,items:[{t:"circle",cx:n.x,cy:n.y,r:et+3,fill:"#fff",stroke:t,strokeWidth:1.5},{t:"path",d:`M ${n.x-2} ${n.y-.5} v -1.5 a 2 2 0 0 1 4 0 v 1.5`,fill:"none",stroke:t,strokeWidth:1.2},{t:"rect",x:n.x-3.2,y:n.y-.5,w:6.4,h:4.6,rx:1,fill:t}]}))}function Ni(e){if(!Array.isArray(e))return[];const t=[];for(const n of e)!n||typeof n!="object"||typeof n.id!="string"||typeof n.kind!="string"||!Array.isArray(n.points)||n.points.length===0||!n.points.every(i=>i!=null&&typeof i=="object"&&"time"in i&&"price"in i&&typeof i.price=="number")||((!n.style||typeof n.style!="object")&&(n.style={...nt}),t.push(Yi(n)));return t}function Yi(e){const t=e.points,n=t.length,o=i=>({...i});switch(e.kind){case"polyline":return e.closed===void 0?{...e,closed:!0}:e;case"fib-speed-resistance-fan":{const i=e.style.levels;if(!i)return e;const r=s=>i.some(a=>a.coeff===s);if(r(0)&&r(1))return e;const l=[...r(0)?[]:[{coeff:0,color:"#808080",visible:!0}],...i,...r(1)?[]:[{coeff:1,color:"#808080",visible:!0}]];return{...e,style:{...e.style,levels:l}}}case"parallel-channel":{if(e.style.levels)return e;const i=e.style,{middleLine:r,...l}=i,s=$e.map(a=>({...a,color:i.color,...a.coeff===0||a.coeff===1?{width:i.width,style:i.lineStyle??"solid"}:{},...a.coeff===.5?{visible:r!==!1}:{}}));return{...e,style:{...l,levels:s}}}case"fib-wedge":case"pitchfan":if(n===2){const i={time:t[1].time,price:2*t[0].price-t[1].price};return{...e,points:[t[0],t[1],i]}}return e;case"ellipse":if(n===2){const i=(t[0].price+t[1].price)/2,r=Number(t[0].time),l=Number(t[1].time),s=Number.isFinite(r)&&Number.isFinite(l)?(r+l)/2:Number(t[0].time);return{...e,points:[{time:t[0].time,price:i},{time:t[1].time,price:i},{time:s,price:t[1].price}]}}return e;case"price-note":return n===1?{...e,points:[t[0],o(t[0])]}:e;case"head-and-shoulders":return n===5?{...e,points:[o(t[0]),...t,o(t[4])]}:e;case"elliott-impulse":case"elliott-triangle":case"elliott-triple-combo":return n===5?{...e,points:[o(t[0]),...t]}:e;case"elliott-correction":case"elliott-double-combo":return n===3?{...e,points:[o(t[0]),...t]}:e;case"note":return n===1?{...e,kind:"pin",points:[t[0]]}:e;case"anchored-volume-profile":return n>1?{...e,points:[t[0]]}:e;case"anchored-vwap":return e.style.fillBackground===void 0?{...e,style:{...e.style,fillBackground:!1}}:e;case"circle":if(e.fmt!==2&&n===2){const i=Number(t[0].time),r=Number(t[1].time),s={time:Number.isFinite(i)&&Number.isFinite(r)?(i+r)/2:t[0].time,price:(t[0].price+t[1].price)/2};return{...e,fmt:2,points:[s,o(t[1])]}}return e;case"arc":return e.fmt!==2&&n===3?{...e,fmt:2,points:[t[0],t[2],t[1]]}:e;default:return e}}const Zc=3,Ui=5,Kc=2,Qc=50;function me(e,t,n){return t.anchored?[{x:t.anchored.x*n.w,y:t.anchored.y*n.h}]:Vi(e,t.points)}function Hn(e,t,n,o,i,r){if(t.anchored&&r&&r.w>0&&r.h>0)return{...t,anchored:{x:(n[0].x+o)/r.w,y:(n[0].y+i)/r.h}};const l=[];for(const s of n){const a=V(e,{x:s.x+o,y:s.y+i});if(!a)return null;l.push(a)}return K(t,l)}function st(e,t){const n=e.timeToX(t.time),o=e.priceToY(t.price);return n==null||o==null?null:{x:n,y:o}}function Vi(e,t){const n=[];for(const o of t){const i=st(e,o);if(!i)return null;n.push(i)}return n}function we(e,t){const n=t.x-e.x,o=t.y-e.y,i=Math.hypot(n,o);if(i===0)return t;const r=Math.PI/4,l=Math.round(Math.atan2(o,n)/r)*r;return{x:e.x+Math.cos(l)*i,y:e.y+Math.sin(l)*i}}function V(e,t){const n=e.xToTime(t.x),o=e.yToPrice(t.y);return n==null||o==null?null:{time:n,price:o}}function Xi(e,t,n,o){const i=t.barAt(e.time);if(!i)return null;const r=[i.open,i.high,i.low,i.close],l=t.priceToY(e.price);let s=i.close,a=1/0;for(const c of r){const f=t.priceToY(c),h=l!=null&&f!=null?Math.abs(f-l):Math.abs(e.price-c);h<a&&(a=h,s=c)}return n==="weak"&&l!=null&&a>=Qc?null:{time:e.time,price:s}}function K(e,t){switch(e.kind){case"horizontal-line":case"horizontal-ray":case"vertical-line":case"cross-line":case"arrow-mark-up":case"arrow-mark-down":case"price-label":case"flag-mark":case"text":case"pin":case"comment":case"signpost":case"font-icon":case"table":case"image":case"anchored-vwap":return{...e,points:[t[0]]};case"price-note":case"note":return{...e,points:[t[0],t[1]]};case"arrow-marker":case"trend-line":case"ray":case"extended-line":case"info-line":case"trend-angle":case"long-position":case"short-position":case"gann-fan":case"gann-box":case"gann-square-fixed":case"gann-square":case"fib-time-zone":case"fib-circles":case"fib-speed-resistance-fan":case"fib-speed-resistance-arcs":case"fib-spiral":case"cyclic-lines":case"sine-line":case"time-cycles":case"arrow":case"rectangle":case"circle":case"fib-retracement":case"price-range":case"date-range":case"date-and-price-range":case"position-forecast":case"bar-pattern":case"callout":case"regression-trend":case"fixed-range-volume-profile":return{...e,points:[t[0],t[1]]};case"anchored-volume-profile":return{...e,points:[t[0]]};case"triangle":case"parallel-channel":case"pitchfork":case"schiff-pitchfork":case"modified-schiff-pitchfork":case"inside-pitchfork":case"trend-based-fib-extension":case"trend-based-fib-time":case"sector":case"disjoint-channel":case"flat-top-bottom":case"fib-channel":case"rotated-rectangle":case"curve":case"fib-wedge":case"pitchfan":case"ellipse":case"arc":return{...e,points:[t[0],t[1],t[2]]};case"double-curve":return{...e,points:[t[0],t[1],t[2],t[3]]};case"abcd-pattern":case"xabcd-pattern":case"cypher-pattern":case"head-and-shoulders":case"triangle-pattern":case"three-drives-pattern":case"elliott-impulse":case"elliott-correction":case"elliott-triangle":case"elliott-double-combo":case"elliott-triple-combo":case"polyline":case"path":case"brush":case"highlighter":case"ghost-feed":return{...e,points:t}}}function Gi(e,t){return Math.atan2(-(t.y-e.y),t.x-e.x)*180/Math.PI}const Nn=new Set(["trend-line","ray","extended-line","info-line","trend-angle","arrow","circle"]),Yn=new Set(["pitchfork","schiff-pitchfork","modified-schiff-pitchfork","inside-pitchfork","pitchfan","triangle","trend-based-fib-extension"]),Jc=new Set(["abcd-pattern","xabcd-pattern","cypher-pattern","head-and-shoulders","triangle-pattern","three-drives-pattern","elliott-impulse","elliott-correction","elliott-triangle","elliott-double-combo","elliott-triple-combo"]);function qe(e,t){switch(e){case"horizontal-line":case"horizontal-ray":case"vertical-line":case"cross-line":case"arrow-mark-up":case"arrow-mark-down":case"price-label":case"flag-mark":case"text":case"pin":case"comment":case"signpost":case"font-icon":case"table":case"image":case"anchored-vwap":return{kind:e,points:[t[0]]};case"price-note":return{kind:e,points:[t[0],t[1]]};case"note":return{kind:e,points:[t[0],t[1]]};case"long-position":case"short-position":return{kind:e,points:[t[0],{...t[0]}]};case"parallel-channel":{const[n,o,i]=t,r=Number(n.time),l=Number(o.time),s=Number(i.time);if(Number.isFinite(r)&&Number.isFinite(l)&&Number.isFinite(s)&&l!==r){const a=(s-r)/(l-r),c=i.price-(n.price+(o.price-n.price)*a);return{kind:e,points:[n,o,{time:n.time,price:n.price+c}]}}return{kind:e,points:[n,o,i]}}case"arrow-marker":case"trend-line":case"ray":case"extended-line":case"info-line":case"trend-angle":case"gann-fan":case"gann-box":case"gann-square-fixed":case"gann-square":case"fib-time-zone":case"fib-speed-resistance-fan":case"fib-speed-resistance-arcs":case"fib-spiral":case"cyclic-lines":case"sine-line":case"time-cycles":case"arrow":case"rectangle":case"fib-retracement":case"price-range":case"date-range":case"date-and-price-range":case"position-forecast":case"bar-pattern":case"callout":case"regression-trend":case"fixed-range-volume-profile":return{kind:e,points:[t[0],t[1]]};case"anchored-volume-profile":return{kind:e,points:[t[0]]};case"circle":return{kind:e,points:[t[0],t[1]],fmt:2};case"arc":return{kind:e,points:[t[0],t[1],t[2]],fmt:2};case"fib-circles":return{kind:e,points:[t[0],t[1]],fmt:2};case"rotated-rectangle":return{kind:e,points:[t[0],t[1],t[2]],fmt:2};case"triangle":case"pitchfork":case"schiff-pitchfork":case"modified-schiff-pitchfork":case"inside-pitchfork":case"trend-based-fib-extension":case"trend-based-fib-time":case"sector":case"disjoint-channel":case"flat-top-bottom":case"fib-channel":case"fib-wedge":case"pitchfan":case"ellipse":return{kind:e,points:[t[0],t[1],t[2]]};case"curve":{const n={time:(Number(t[0].time)+Number(t[1].time))/2,price:(t[0].price+t[1].price)/2};return{kind:e,points:[t[0],n,t[1]]}}case"double-curve":{const n=Number(t[0].time),o=Number(t[1].time),i={time:n+(o-n)/3,price:t[0].price+(t[1].price-t[0].price)/3},r={time:n+(o-n)*2/3,price:t[0].price+(t[1].price-t[0].price)*2/3};return{kind:e,points:[t[0],i,r,t[1]]}}case"abcd-pattern":case"xabcd-pattern":case"cypher-pattern":case"head-and-shoulders":case"triangle-pattern":case"three-drives-pattern":case"elliott-impulse":case"elliott-correction":case"elliott-triangle":case"elliott-double-combo":case"elliott-triple-combo":case"polyline":case"path":case"brush":case"highlighter":case"ghost-feed":return{kind:e,points:t.slice()}}return null}function ta(e,t,n,o,i){const r=e.points[0],l=n.pipSize(),s=n.yToPrice(0),a=n.yToPrice(Math.max(1,i)),c=s!=null&&a!=null?Math.abs(s-a):0,f=Math.max(l,Math.round((c||l*500)*.2/l)*l),h=n.bars(),u=n.timeToBarIndex(r.time)??h.length,d=n.barIndexToTime(u),x=n.barIndexToTime(u+1),p=d!=null?n.timeToX(d):null,y=x!=null?n.timeToX(x):null,b=p!=null&&y!=null?Math.abs(y-p):0,g=b>0?Math.round(o/b):0,m=u+Math.max(3,Math.round(.15*g)),w=n.barIndexToTime(m)??r.time,M={...Ot(t),stopLevel:f,profitLevel:f};return{...e,points:[r,{time:w,price:r.price}],style:M}}function ea(e,t,n){const o=e.points[1];if(!o)return e;const i=N(e.points[0].time),r=N(o.time);if(i==null||r==null)return e;const l=We(t.bars(),Math.min(i,r),Math.max(i,r));if(l.length===0)return e;const s=l[0],a=l[l.length-1],c=t.priceToY(s.high),f=c!=null?t.yToPrice(c-.05*n)??s.high:s.high,h=f+(a.low-s.high);return{...e,points:[{time:s.time,price:f},{time:a.time,price:h}],pattern:{base:s.open,bars:l.map(u=>[u.open,u.high,u.low,u.close])}}}function na(e,t){const n=t.bars(),o=t.pipSize(),i=n.length>0?n.reduce((l,s)=>l+(s.high-s.low),0)/n.length:0,r=i>0?Math.max(1,Math.round(i/o))*o:Math.abs(e.points[0].price)*.01||1;return{...e,ghost:{seed:Math.floor(Math.random()*2147483647),amplitude:r}}}function oa(e,t){const n=e.points[0],o=e.points[e.points.length-1];if(!n||!o)return e;const i=st(t,n),r=st(t,o);if(!i||!r)return e;const l=r.x-i.x,s=r.y-i.y,a=Math.hypot(l,s)||1,c=-s/a*a*.15,f=l/a*a*.15,h=u=>V(t,{x:i.x+l*u+c,y:i.y+s*u+f});if(e.kind==="curve"){const u=h(.5);return u?{...e,points:[e.points[0],u,e.points[2]]}:e}if(e.kind==="double-curve"){const u=h(.3333333333333333),d=h(2/3);return!u||!d?e:{...e,points:[e.points[0],u,d,e.points[3]]}}return e}function ia(e,t){const n=st(t,e.points[0]),o=e.points[1]?st(t,e.points[1]):null;return!n||!o?e:{...e,style:{...e.style??Ot("trend-angle"),angle:Gi(n,o)}}}function ji(e,t){const[n,o]=e.points;if(!n||!o||t.isLog())return e;const i=t.timeToBarIndex(n.time),r=t.timeToBarIndex(o.time);if(i==null||r==null)return e;const l=t.priceToY(n.price),s=t.priceToY(n.price+1),a=t.barIndexToTime(i),c=t.barIndexToTime(i+1),f=a!=null?t.timeToX(a):null,h=c!=null?t.timeToX(c):null;if(l==null||s==null||f==null||h==null||l===s)return e;const u=Math.abs(h-f)/Math.abs(s-l),d=o.price-n.price>=0?1:-1;return{...e,points:[n,{...o,price:n.price+d*Math.abs(r-i)*u}]}}function Un(e,t,n,o,i={}){let r=qe(e,t);return r?((e==="long-position"||e==="short-position")&&n&&(r=ta(r,e,n,o.w,o.h)),(e==="curve"||e==="double-curve")&&n&&(r=oa(r,n)),e==="gann-square"&&n&&(r=ji(r,n)),e==="bar-pattern"&&n&&(r=ea(r,n,Math.max(1,o.h))),e==="trend-angle"&&n&&(r=ia(r,n)),e==="polyline"&&i.closed!==void 0&&(r={...r,closed:i.closed}),e==="ghost-feed"&&n&&(r=na(r,n)),e==="font-icon"&&(r={...r,glyph:i.glyph}),r):null}function ra(e,t,n,o){const i=e.start;if(i.kind!=="long-position"&&i.kind!=="short-position"||e.mode.hit!=="handle")return null;const r=e.mode.handleIndex,[l,s]=i.points,a=n.pipSize(),c=i.kind==="long-position"?1:-1,{stop:f,profit:h}=fn(i,a);if(r===0){const d=V(n,t);if(!d)return null;const x=o(d);return K(i,[x,{time:s.time,price:x.price}])}if(r===1){const d=n.xToTime(t.x);return d==null?null:K(i,[l,{time:d,price:l.price}])}const u=n.yToPrice(t.y);if(u==null)return null;if(r===2){const d=Math.max(a,(l.price-u)*c);return{...i,style:{...i.style,stopLevel:d,profitLevel:h}}}if(r===3){const d=Math.max(a,(u-l.price)*c);return{...i,style:{...i.style,profitLevel:d,stopLevel:f}}}return null}function la(e,t,n){const o=e.start;if(o.kind!=="parallel-channel"||e.mode.hit!=="handle")return null;const[i,r,l]=e.startScreen;if(!i||!r||!l)return null;const s=e.mode.handleIndex,a=t.x-e.startCursor.x,c=t.y-e.startCursor.y,f=u=>V(n,u),h=o.points;if(s===0||s===2){const u=f({x:i.x+a,y:i.y+c}),d=f({x:l.x+a,y:l.y+c});return!u||!d?null:K(o,[u,h[1],d])}if(s===1||s===3){const u=f({x:r.x+a,y:r.y+c});return u?K(o,[h[0],u,h[2]]):null}if(s===4){const u=f({x:l.x,y:l.y+c});return u?K(o,[h[0],h[1],u]):null}if(s===5){const u=f({x:i.x,y:i.y+c}),d=f({x:r.x,y:r.y+c}),x=f({x:l.x,y:l.y+c});return!u||!d||!x?null:K(o,[u,d,x])}return null}function sa(e,t,n,o){const i=e.start;if(i.kind!=="disjoint-channel"||e.mode.hit!=="handle")return null;const r=e.mode.handleIndex,l=i.points;if(r===0||r===1){const a=V(n,t);if(!a)return null;const c=l.slice();return c[r]=o(a),K(i,c)}const s=n.yToPrice(t.y);if(s==null)return null;if(r===2)return K(i,[l[0],l[1],{time:l[2].time,price:s}]);if(r===3){const a=l[2].price+l[1].price-s;return K(i,[{time:l[0].time,price:a},l[1],l[2]])}return null}function ca(e,t,n,o){const i=e.start;if(i.kind!=="rotated-rectangle"||e.mode.hit!=="handle")return null;const r=e.mode.handleIndex,l=V(n,t);if(!l)return null;const s=i.points.slice();if(r>=2)return s[2]=l,K(i,s);const[a,c,f]=e.startScreen,h=c.x-a.x,u=c.y-a.y,d=Math.hypot(h,u)||1,x=Math.abs(((f.x-a.x)*u-(f.y-a.y)*h)/d),p=o(l);s[r]=p;const y=r===0?st(n,p):a,b=r===1?st(n,p):c;if(!y||!b)return null;const g=Math.hypot(b.x-y.x,b.y-y.y)||1,m=V(n,{x:y.x+(b.y-y.y)/g*x,y:y.y-(b.x-y.x)/g*x});return m?(s[2]=m,K(i,s)):null}function qi(e,t,n,o,i=!1){var f,h;const r=Ie(e.start.kind);if(i&&e.mode.hit==="handle"){if(Nn.has(e.start.kind)&&e.startScreen.length===2&&e.mode.handleIndex>=0&&e.mode.handleIndex<=1&&(e.start.kind!=="circle"||e.mode.handleIndex===1)){const u=e.startScreen[1-e.mode.handleIndex];u&&(t=we(u,t))}else if(r!=null&&r.isBbox&&e.startScreen.length===2&&e.mode.handleIndex<4){const d=At(e.startScreen[0],e.startScreen[1])[(e.mode.handleIndex+2)%4];if(d){const x=t.x-d.x,p=t.y-d.y,y=Math.max(Math.abs(x),Math.abs(p));t={x:d.x+Math.sign(x||1)*y,y:d.y+Math.sign(p||1)*y}}}else if(Yn.has(e.start.kind)&&e.mode.handleIndex>=0&&e.mode.handleIndex<e.startScreen.length){const u=e.mode.handleIndex,d=e.startScreen[u>0?u-1:1];d&&(t=we(d,t))}}if(e.mode.hit==="handle")switch(e.start.kind){case"long-position":case"short-position":return ra(e,t,n,o);case"parallel-channel":return la(e,t,n);case"table":return aa(e,t,n);case"signpost":{const u=((f=e.pane)==null?void 0:f.h)??0,d=Qo(e.start,n,u,t.y);return d==null?null:{...e.start,style:{...e.start.style,signpostPosition:d}}}case"text":{if(e.mode.handleIndex!==1)break;const u=e.start.style.fontSize??14;return{...e.start,style:{...e.start.style,wordWrapWidth:Math.max(100,t.x-e.startScreen[0].x-Math.floor(u/6))}}}case"callout":{if(e.mode.handleIndex!==1)break;const u=e.start.style,d=u.wordWrapWidth??200,x=e.startScreen[1].x-d/2-10,p=Math.max(100,t.x-x-10),y=V(n,{x:x+p/2+10,y:e.startScreen[1].y});return y?{...K(e.start,[e.start.points[0],y]),style:{...u,wordWrapWidth:p}}:null}case"image":return fa(e,t,n);case"pin":if(e.start.anchored)return Hn(n,e.start,e.startScreen,t.x-e.startCursor.x,t.y-e.startCursor.y,e.pane);break;case"polyline":{const u=e.mode.handleIndex,d=e.startScreen.length;if(d>2&&(u===0||u===d-1)){const x=e.startScreen[u===0?d-1:0];if(Math.hypot(t.x-x.x,t.y-x.y)<Ui){const p=V(n,t);if(!p)return null;const y=e.start.points.slice();return y[u]=o(p),{...K(e.start,y),closed:!0}}}break}case"disjoint-channel":return sa(e,t,n,o);case"rotated-rectangle":if(e.start.fmt===2)return ca(e,t,n,o);break;case"horizontal-line":{const u=V(n,t);return u?K(e.start,[{time:e.start.points[0].time,price:o(u).price}]):null}case"vertical-line":{const u=V(n,t);return u?K(e.start,[{time:o(u).time,price:e.start.points[0].price}]):null}}if(e.mode.hit==="body"&&e.start.kind==="signpost"){const u=t.x-e.startCursor.x,d=t.y-e.startCursor.y,x=V(n,{x:e.startScreen[0].x+u,y:e.startScreen[0].y}),p=((h=e.pane)==null?void 0:h.h)??0,y=mn(e.start,e.startScreen[0],n,p);if(!x)return null;const b=K(e.start,[{time:x.time,price:e.start.points[0].price}]),g=Qo(b,n,p,y.anchor.y+d);return g==null?b:{...b,style:{...b.style,signpostPosition:g}}}if(e.mode.hit==="body")return Hn(n,e.start,e.startScreen,t.x-e.startCursor.x,t.y-e.startCursor.y,e.pane);if(e.start.kind==="rectangle"&&e.mode.handleIndex>=4&&e.startScreen.length===2){const[u,,d]=At(e.startScreen[0],e.startScreen[1]);let{x,y:p}=u,{x:y,y:b}=d;switch(e.mode.handleIndex){case 4:p=t.y;break;case 5:y=t.x;break;case 6:b=t.y;break;case 7:x=t.x;break}const g=V(n,{x,y:p}),m=V(n,{x:y,y:b});return!g||!m?null:K(e.start,[g,m])}if(r!=null&&r.isBbox&&e.startScreen.length===2&&e.mode.handleIndex<4){const d=At(e.startScreen[0],e.startScreen[1])[(e.mode.handleIndex+2)%4],x=V(n,t),p=V(n,d);return!x||!p?null:K(e.start,[o(x),p])}const l=V(n,t);if(!l)return null;const s=e.mode.handleIndex,a=e.start.points.slice();if(s<0||s>=a.length)return null;a[s]=o(l);const c=K(e.start,a);if(c.kind==="trend-angle"&&e.startScreen.length===2&&s<=1){const u=s===0?t:e.startScreen[0],d=s===1?t:e.startScreen[1];return{...c,style:{...c.style,angle:Gi(u,d)}}}return c}function Zi(e,t){const n=e.xToTime(t);if(n==null)return null;const o=e.timeToX(n);if(o==null||o<=t+1e-6)return n;const i=e.timeToBarIndex(n);return i==null?n:e.barIndexToTime(i-1)??n}function aa(e,t,n){if(e.mode.hit!=="handle")return null;const o=e.start,i=o.style,r=e.mode.handleIndex,l=e.startScreen[0],s=i.fontSize??14,a=ue(i),{heights:c,mins:f}=Wo(i),h=Nr(s),u=a.map(()=>h),d=I=>I.reduce((R,Y)=>R+Y,0),x=d(a),p=d(c),y=Io(r);if(y){const I={};if(y.col!=null){const R=l.x+d(a.slice(0,y.col));I.tableColWidths=a.map((Y,J)=>J===y.col?Math.max(h,t.x-R):Y)}if(y.row!=null){const R=l.y+d(c.slice(0,y.row));I.tableRowHeights=c.map((Y,J)=>J===y.row?Math.max(f[J],t.y-R):Y)}return{...o,style:{...i,...I}}}if(r>3)return null;const b=r===0||r===1,g=r===0||r===2,m={x:l.x+(b?0:x),y:l.y+(g?0:p)},w={x:m.x+(b?x:-x),y:m.y+(g?p:-p)},M=h*a.length,k=d(f);let v=b?Math.min(t.x,w.x-M):Math.max(t.x,w.x+M);const C=g?Math.min(t.y,w.y-k):Math.max(t.y,w.y+k);let T=o.points[0].time;const F=o.anchored&&e.pane&&e.pane.w>0&&e.pane.h>0?e.pane:null;if(b&&!F){const I=Zi(n,v),R=I==null?null:n.timeToX(I);if(I==null||R==null)return null;T=I,v=R}let A=o.points[0].price;if(g&&!F){const I=n.yToPrice(C);if(I==null)return null;A=I}const O=m.x-v,D=m.y-C,S=yn(a,u,b?x+O:x-O);b&&(S[S.length-1]+=Math.round(l.x+x)-v-d(S));const E=yn(c,f,g?p+D:p-D),B=Po(s);if(F){const I=b?v:l.x,R=g?C:l.y;return{...o,anchored:{x:I/F.w,y:R/F.h},style:{...i,tableColWidths:S.map(Y=>Math.max(Y,h)),tableRowHeights:E.map(Y=>Math.max(Y,B))}}}return{...o,points:[{time:T,price:A}],style:{...i,tableColWidths:S.map(I=>Math.max(I,h)),tableRowHeights:E.map(I=>Math.max(I,B))}}}function fa(e,t,n){const o=e.start,i=o.image,r=gn(i==null?void 0:i.name);if(!i||!r||e.mode.hit!=="handle"||e.mode.handleIndex>3)return null;const[l,s]=tl[e.mode.handleIndex],a={x:e.startScreen[0].x+(i.dx??0),y:e.startScreen[0].y},c={x:a.x-l*i.cssWidth/2,y:a.y-s*i.cssHeight/2},f=Math.max(Math.abs(c.x-t.x)/r.width,Math.abs(c.y-t.y)/r.height),h=Math.round(r.width*f),u=Math.round(r.height*f),d={x:c.x+l*h/2,y:c.y+s*u/2},x=V(n,d);if(!x)return null;const p=n.timeToX(x.time);return{...o,points:[x],image:{...i,cssWidth:h,cssHeight:u,dx:p==null?0:d.x-p}}}function Ki(e,t){if(t.length<2)return"grab";let n=0,o=0;for(const s of t)n+=s.x,o+=s.y;n/=t.length,o/=t.length;const i=e.x-n,r=e.y-o;if(Math.hypot(i,r)<1)return"grab";const l=(Math.atan2(r,i)*180/Math.PI+360)%180;return l<22.5||l>=157.5?"ew-resize":l<67.5?"nwse-resize":l<112.5?"ns-resize":"nesw-resize"}const Qi=new Set(["text","pin","table"]);function Ji(e){return Qi.has(e)}function tr(e,t,n){if(!Ji(e.kind)||n.w<=0||n.h<=0)return null;if(!e.anchored){const c=st(t,e.points[0]);return c?{...e,anchored:{x:c.x/n.w,y:c.y/n.h}}:null}const o=e.anchored.x*n.w,i=e.anchored.y*n.h,r=Zi(t,o),l=t.yToPrice(i);if(r==null||l==null)return null;const{anchored:s,...a}=e;return K(a,[{time:r,price:l}])}const ha=1;function er(e,t,n,o=()=>[],i=()=>({timeZone:"UTC",intraday:!0})){return{priceToY:r=>t.priceToCoordinate(r),yToPrice:r=>t.coordinateToPrice(r),isLog:()=>t.priceScale().options().mode===ha,timeToX:r=>{const l=e.timeScale().timeToCoordinate(r);if(l!=null)return l;const s=n();if(s.length===0)return null;const a=Q(r);if(a==null)return null;const c=nr(s,a);return c==null?null:or(e,c)},xToTime:r=>{const l=e.timeScale().coordinateToTime(r);if(l!=null)return l;const s=n();if(s.length===0)return null;const a=e.timeScale().coordinateToLogical(r),c=Q(s[s.length-1].time);if(a==null||c==null)return null;const f=Me(s);return f<=0?null:Math.round(c+(a-(s.length-1))*f)},barAt:r=>da(n(),r),timeToBarIndex:r=>{const l=n();if(l.length===0)return null;const s=Q(r);if(s==null)return null;const a=l.length-1,c=Q(l[a].time),f=Q(l[0].time),h=Me(l);if(c!=null&&s>c)return Math.round(a+(s-c)/h);if(f!=null&&s<f)return Math.round((s-f)/h);let u=0,d=1/0;for(let x=0;x<l.length;x++){const p=Q(l[x].time);if(p==null)continue;const y=Math.abs(p-s);y<d&&(d=y,u=x)}return u},barIndexToTime:r=>{const l=n();if(l.length===0)return null;if(r>=0&&r<l.length)return l[r].time;const s=l.length-1,a=Q(l[s].time);if(a==null)return null;const c=Me(l);return Math.round(a+(r-s)*c)},bars:n,visibleTimeRange:()=>{const r=e.timeScale().getVisibleRange();if(!r)return null;const l=Q(r.from),s=Q(r.to);return l==null||s==null?null:{from:l,to:s}},indicatorValuesAt:r=>o(Q(r)),pipSize:()=>{const r=t.options().priceFormat;return r&&typeof r.minMove=="number"&&r.minMove>0?r.minMove:.01},addPriceLine:r=>t.createPriceLine(r),removePriceLine:r=>t.removePriceLine(r),zoomToScreenRect:(r,l,s,a)=>{const c=e.timeScale(),f=c.coordinateToLogical(Math.min(r,l)),h=c.coordinateToLogical(Math.max(r,l));f!=null&&h!=null&&h>f&&c.setVisibleLogicalRange({from:f,to:h});const u=t.coordinateToPrice(s),d=t.coordinateToPrice(a);if(u!=null&&d!=null){const x=Math.min(u,d),p=Math.max(u,d);if(p>x){const y=t.priceScale();y.setAutoScale(!1),y.setVisibleRange({from:x,to:p})}}},formatTime:r=>{const l=e.options().localization.timeFormatter;if(l)return l(r);const s=Q(r);if(s==null)return String(r);const a=e.options(),c=new Date(s*1e3),f=new Intl.DateTimeFormat(a.localization.locale,{month:"short",timeZone:"UTC"}).format(c),h=`${c.getUTCDate()} ${f} '${String(c.getUTCFullYear()%100).padStart(2,"0")}`;if(!a.timeScale.timeVisible)return h;const u=x=>String(x).padStart(2,"0"),d=`${u(c.getUTCHours())}:${u(c.getUTCMinutes())}${a.timeScale.secondsVisible?`:${u(c.getUTCSeconds())}`:""}`;return`${h} ${d}`},timeInfo:()=>i(),timeAxis:()=>{const r=e.options().layout;return{height:e.timeScale().height(),width:e.timeScale().width(),fontSize:r.fontSize,fontFamily:r.fontFamily}}}}function Q(e){if(typeof e=="number")return e;if(typeof e=="string"){const t=Date.parse(e);return Number.isFinite(t)?t/1e3:null}return typeof e=="object"&&e!==null&&"year"in e?Date.UTC(e.year,e.month-1,e.day)/1e3:null}function Me(e){if(e.length<2)return 86400;const t=[];for(let n=Math.max(1,e.length-50);n<e.length;n++){const o=Q(e[n-1].time),i=Q(e[n].time);o!=null&&i!=null&&i>o&&t.push(i-o)}return t.length===0?86400:(t.sort((n,o)=>n-o),t[Math.floor(t.length/2)])}function nr(e,t){const n=e.length,o=Q(e[0].time),i=Q(e[n-1].time);if(o==null||i==null)return null;if(t>=i){const c=Me(e);return c>0?n-1+(t-i)/c:null}if(t<=o){const c=Me(e);return c>0?(t-o)/c:null}let r=0,l=n-1;for(;r<l;){const c=r+l+1>>1,f=Q(e[c].time);f!=null&&f<=t?r=c:l=c-1}const s=Q(e[r].time),a=r+1<n?Q(e[r+1].time):null;return s==null||a==null||a<=s?r:r+(t-s)/(a-s)}function or(e,t){const n=e.timeScale(),o=Math.floor(t),i=n.logicalToCoordinate(o);if(i==null)return null;const r=t-o;if(r===0)return i;const l=n.logicalToCoordinate(o+1);return l==null?i:i+r*(l-i)}function ua(e,t,n){if(n.length===0)return null;const o=nr(n,t);return o==null?null:or(e,o)}function da(e,t){if(e.length===0)return null;const n=Q(t);if(n==null)return e[0];let o=e[0],i=1/0;for(const r of e){const l=Q(r.time);if(l==null)continue;const s=Math.abs(l-n);s<i&&(o=r,i=s)}return o}const Vn="#1e53e5";function ir(e,t,n){const o={clips:new Map,grads:new Map};for(const i of t)Xn(e,i,n,o)}function Xn(e,t,n,o){switch(t.t){case"clip":{const l=t.polys;o.clips.set(t.name,s=>{const c=new Path2D;c.rect(-1e5,-1e5,2*1e5,2*1e5);for(const f of l)if(f.length){c.moveTo(f[0].x,f[0].y);for(let h=1;h<f.length;h++)c.lineTo(f[h].x,f[h].y);c.closePath()}s.clip(c,"evenodd")});return}case"clipRect":{const{x:l,y:s,w:a,h:c}=t;o.clips.set(t.name,f=>{const h=new Path2D;h.rect(l,s,a,c),f.clip(h)});return}case"radialGradient":{const l=e.createRadialGradient(t.cx,t.cy,0,t.cx,t.cy,t.r);for(const s of t.stops)l.addColorStop(s.offset,ar(s.color,s.opacity));o.grads.set(t.name,l);return}case"hit":case"hitPath":return;case"anchors":wa(e,t.pts,t.squares,n.anchors);return}const i="clip"in t&&t.clip?o.clips.get(t.clip):void 0,r=!!i||t.t==="group"||"transform"in t&&!!t.transform;switch(r&&e.save(),i&&i(e),t.t){case"line":{const l=new Path2D;l.moveTo(t.a.x,t.a.y),l.lineTo(t.b.x,t.b.y),ie(e,l,t,o,!1);break}case"polyline":case"polygon":{const l=new Path2D;t.pts.forEach((s,a)=>a===0?l.moveTo(s.x,s.y):l.lineTo(s.x,s.y)),t.t==="polygon"&&t.pts.length&&l.closePath(),ie(e,l,t,o,!0);break}case"path":{t.transform&&jn(e,t.transform),ie(e,new Path2D(t.d),t,o,!0);break}case"rect":{if(t.w<0||t.h<0)break;const l=new Path2D,s=Math.min(t.rx??t.ry??0,t.w/2),a=Math.min(t.ry??t.rx??0,t.h/2);s>0||a>0?Gn(l,t.x,t.y,t.w,t.h,s,a):l.rect(t.x,t.y,t.w,t.h),ie(e,l,t,o,!0);break}case"circle":{if(t.r<=0)break;const l=new Path2D;l.arc(t.cx,t.cy,t.r,0,Math.PI*2),ie(e,l,t,o,!0);break}case"ellipse":{if(t.transform&&jn(e,t.transform),t.rx<=0||t.ry<=0)break;const l=new Path2D;l.ellipse(t.cx,t.cy,t.rx,t.ry,0,0,Math.PI*2),ie(e,l,t,o,!0);break}case"text":pa(e,t,n);break;case"image":ga(e,t,n);break;case"glyph":ma(e,t,n);break;case"group":{if(t.transform&&jn(e,t.transform),t.opacity!=null&&t.opacity<1){const l=xa(e);if(l){for(const s of t.items)Xn(l,s,n,o);e.save(),e.setTransform(1,0,0,1,0,0),e.globalAlpha*=t.opacity,e.drawImage(l.canvas,0,0),e.restore();break}e.globalAlpha*=t.opacity}for(const l of t.items)Xn(e,l,n,o);break}}r&&e.restore()}function xa(e){const t=e.canvas.width,n=e.canvas.height;if(!t||!n)return null;const o=document.createElement("canvas");o.width=t,o.height=n;const i=o.getContext("2d");return i?(i.setTransform(e.getTransform()),i):null}function ie(e,t,n,o,i){const r=n.fillRef?o.grads.get(n.fillRef)??null:i?n.fill??"#000000":null,l=n.stroke,s=n.shadow;if(r&&r!=="none"&&r!=="transparent"&&(e.save(),s&&rr(e,s),e.globalAlpha*=n.fillOpacity??1,e.fillStyle=r,e.fill(t,n.fillRule==="evenodd"?"evenodd":"nonzero"),e.restore()),l&&l!=="none"&&l!=="transparent"){const a=n.strokeWidth??1;if(a<=0)return;e.save(),s&&(!r||r==="none"||r==="transparent")&&rr(e,s),e.globalAlpha*=n.strokeOpacity??1,e.strokeStyle=l,e.lineWidth=a,e.lineCap=n.cap??"butt",e.lineJoin=n.join??"miter",e.setLineDash(ya(n.dash)),e.stroke(t),e.restore()}}function rr(e,t){e.shadowOffsetX=t.dx,e.shadowOffsetY=t.dy,e.shadowBlur=t.blur,e.shadowColor=t.color}function ya(e){if(!e||e==="none")return[];const t=e.split(/[\s,]+/).map(Number).filter(n=>Number.isFinite(n)&&n>=0);return!t.length||t.every(n=>n===0)?[]:t.length%2?[...t,...t]:t}function Gn(e,t,n,o,i,r,l){e.moveTo(t+r,n),e.lineTo(t+o-r,n),e.ellipse(t+o-r,n+l,r,l,0,-Math.PI/2,0),e.lineTo(t+o,n+i-l),e.ellipse(t+o-r,n+i-l,r,l,0,0,Math.PI/2),e.lineTo(t+r,n+i),e.ellipse(t+r,n+i-l,r,l,0,Math.PI/2,Math.PI),e.lineTo(t,n+l),e.ellipse(t+r,n+l,r,l,0,Math.PI,3*Math.PI/2),e.closePath()}function jn(e,t){const n=/(rotate|translate|scale|matrix)\s*\(([^)]*)\)/g;let o;for(;o=n.exec(t);){const i=o[2].split(/[\s,]+/).filter(Boolean).map(Number);switch(o[1]){case"rotate":{const r=(i[0]??0)*Math.PI/180;i.length>=3?(e.translate(i[1],i[2]),e.rotate(r),e.translate(-i[1],-i[2])):e.rotate(r);break}case"translate":e.translate(i[0]??0,i[1]??0);break;case"scale":e.scale(i[0]??1,i[1]??i[0]??1);break;case"matrix":e.transform(i[0],i[1],i[2],i[3],i[4],i[5]);break}}}function pa(e,t,n){const o=t.pre?t.text:t.text.replace(/\s+/g," ").trim();if(!o)return;e.save(),t.opacity!=null&&(e.globalAlpha*=t.opacity);const i=t.weight==="bold"?700:t.weight??400;e.font=`${t.fontStyle==="italic"?"italic ":""}${i} ${t.size}px ${t.family??n.fontFamily}`,e.textAlign=t.anchor==="middle"?"center":t.anchor==="end"?"right":"left";let r=t.y;t.baseline==="central"?(e.textBaseline="alphabetic",r+=ba(e)):e.textBaseline=t.baseline==="middle"?"middle":t.baseline==="hanging"?"hanging":"alphabetic",e.fillStyle=t.fill??"#000000",e.fillText(o,t.x,r),e.restore()}const lr=new Map;function ba(e){let t=lr.get(e.font);if(t==null){const n=e.measureText("H");t=(n.fontBoundingBoxAscent-n.fontBoundingBoxDescent)/2,lr.set(e.font,t)}return t}const sr=new Map;function cr(e,t){let n=sr.get(e);return n||(n=new Image,n.onload=()=>{var o;return(o=t.onAsyncLoad)==null?void 0:o.call(t)},n.src=e,sr.set(e,n)),n.complete&&n.naturalWidth>0?n:null}function ga(e,t,n){if(!t.href)return;const o=cr(t.href,n);if(o){if(e.save(),t.opacity!=null&&(e.globalAlpha*=t.opacity),t.stretch)e.drawImage(o,t.x,t.y,t.w,t.h);else{const i=Math.min(t.w/o.naturalWidth,t.h/o.naturalHeight),r=o.naturalWidth*i,l=o.naturalHeight*i;e.drawImage(o,t.x+(t.w-r)/2,t.y+(t.h-l)/2,r,l)}e.restore()}}function ma(e,t,n){const o=t.glyph.trim();if(o){if(o.startsWith("<svg")){let i=o.replace(/currentColor/g,t.color);/xmlns=/.test(i)||(i=i.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"'));const r=cr(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`,n);r&&e.drawImage(r,t.x,t.y,t.size,t.size);return}e.save(),e.font=`${t.size-4}px ${n.fontFamily}`,e.textAlign="center",e.textBaseline="middle",e.fillStyle=t.color,e.fillText(o,t.x+t.size/2,t.y+t.size/2),e.restore()}}function wa(e,t,n,o){const i=o.selected?2:1;t.forEach((r,l)=>{const s=!!(n!=null&&n.includes(l));if(e.save(),o.hovered===l){e.strokeStyle=ar(Vn,.2),e.lineWidth=3;const c=new Path2D;s?Gn(c,r.x-et-1.5,r.y-et-1.5,2*et+3,2*et+3,4.5,4.5):c.arc(r.x,r.y,et+1.5,0,Math.PI*2),e.stroke(c)}const a=new Path2D;if(s){const c=2*et-i;Gn(a,r.x-et+i/2,r.y-et+i/2,c,c,3,3)}else a.arc(r.x,r.y,et-i/2,0,Math.PI*2);e.fillStyle=o.fillAt(r.y),e.fill(a),e.strokeStyle=Vn,e.lineWidth=i,e.stroke(a),e.restore()})}function ar(e,t){if(t>=1)return e;const n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(n){const i=n[1].length===3?n[1].split("").map(l=>l+l).join(""):n[1],r=parseInt(i,16);return`rgba(${r>>16}, ${r>>8&255}, ${r&255}, ${t})`}const o=/^rgba?\(([^)]*)\)$/i.exec(e);if(o){const[i,r,l,s]=o[1].split(/[\s,/]+/).filter(Boolean).map(Number);return`rgba(${i}, ${r}, ${l}, ${(s??1)*t})`}return e}const Ma=()=>`dw_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`;class ka{constructor(t,n,o={}){H(this,"chart");H(this,"series");H(this,"opts");H(this,"coords");H(this,"primitive");H(this,"el");H(this,"listeners",{change:new Set,add:new Set,update:new Set,remove:new Set,selection:new Set,tool:new Set,textEdit:new Set,gestureEnd:new Set,tableEdit:new Set});H(this,"list",[]);H(this,"selected",[]);H(this,"hovered",null);H(this,"spec",null);H(this,"glyph");H(this,"pending",[]);H(this,"cursor",null);H(this,"gesture",null);H(this,"tableUi",null);H(this,"hoverCursor",null);H(this,"shift",!1);H(this,"ctrl",!1);H(this,"savedScroll",null);H(this,"off",[]);this.chart=t,this.series=n,this.opts={magnet:"off",...o};const i=o.bars??(()=>La(n));this.coords=er(t,n,i,()=>[],o.timeInfo),this.primitive=new Ca(this),n.attachPrimitive(this.primitive),this.el=t.chartElement(),this.listen(this.el,"pointerdown",r=>this.onPointerDown(r),!0),this.listen(this.el,"pointermove",r=>this.onHover(r)),this.listen(this.el,"pointerleave",()=>{this.hoverCursor=null,this.setHover(null)}),this.listen(this.el,"dblclick",r=>this.onDoubleClick(r),!0),this.listen(window,"keydown",r=>this.onKey(r)),this.listen(window,"keyup",r=>this.onKey(r)),this.listen(window,"blur",()=>{this.shift=!1,this.ctrl=!1}),this.off.push(Oo(()=>{var r;for(const l of this.list)l.kind==="image"&&Jr((r=l.image)==null?void 0:r.name)&&this.remove(l.id);this.redraw()}))}on(t,n){return this.listeners[t].add(n),()=>this.listeners[t].delete(n)}setTool(t,n={}){const o=t?Ie(t)??null:null;this.spec=o,this.glyph=n.glyph,this.pending=[],this.cursor=null,this.emit("tool",o?o.kind:null),this.redraw()}tool(){var t;return((t=this.spec)==null?void 0:t.kind)??null}setMagnet(t){this.opts.magnet=t}setInterval(t){this.opts.interval=t,this.redraw()}setStayInDrawingMode(t){this.opts.stayInDrawingMode=t}drawings(){return this.list}get(t){return this.list.find(n=>n.id===t)}add(t){const n={id:Ma(),style:Ot(t.kind),...t};return this.list=[...this.list,n],this.emit("add",n),this.changed(),n.id}update(t){const n=this.get(t.id);n&&(this.list=this.list.map(o=>o.id===t.id?t:o),this.emit("update",t,n),this.changed())}remove(t){const n=this.get(t);n&&(this.list=this.list.filter(o=>o.id!==t),this.selected.includes(t)&&this.select(this.selected.filter(o=>o!==t)),this.emit("remove",n),this.changed())}clear(){this.list=[],this.select([]),this.changed()}bringToFront(t){this.reorder(t,this.list.length-1)}sendToBack(t){this.reorder(t,0)}select(t){this.selected=t.filter(n=>this.get(n)),this.tableUi&&!this.selected.includes(this.tableUi.id)&&(this.tableUi=null),this.emit("selection",this.selected),this.redraw()}selection(){return this.selected}addImage(t){const{w:n,h:o}=this.paneSize(),i=V(this.coords,{x:n/2,y:o/2});if(!i)return null;const r=Ot("image"),l=this.add({kind:"image",points:[i],image:{name:t.name,...el(t.width,t.height,n,o)},style:{...r,transparency:t.transparency??r.transparency}});return this.select([l]),l}toggleAnchored(t){const n=this.get(t);if(!n)return!1;const o=tr(n,this.coords,this.paneSize());return o?(this.update(o),this.emit("gestureEnd"),!0):!1}tableState(){return this.tableUi}setTableCellText(t,n,o){const i=this.get(t);(i==null?void 0:i.kind)==="table"&&this.update({...i,style:{...i.style,...qr(i.style,n,o)}})}endTableEdit(){this.tableUi&&(this.tableUi={...this.tableUi,editing:!1}),this.redraw()}tableOp(t,n){var r,l;const o=this.get(t);if((o==null?void 0:o.kind)!=="table")return;const i=((r=this.tableUi)==null?void 0:r.id)===t?this.tableUi.cell:null;if(n==="insert-column"||n==="insert-row")this.update({...o,style:{...o.style,...Xr(o.style,n==="insert-row"?"row":"column",i)}});else{const s=n==="remove-row"?"row":"column";if(!i||!Gr(o.style,s))return;const a=jr(o.style,s,i);this.update({...o,style:{...o.style,...a.patch}}),this.tableUi={id:t,cell:a.cell,editing:((l=this.tableUi)==null?void 0:l.editing)??!1,edge:null}}this.emit("gestureEnd")}exportJSON(){return JSON.stringify(this.list)}importJSON(t){const n=typeof t=="string"?JSON.parse(t):t;return this.list=Ni(n),this.select([]),this.changed(),this.list.length}redraw(){this.primitive.requestUpdate()}destroy(){this.endGesture();for(const t of this.off)t();this.series.detachPrimitive(this.primitive)}scenes(t,n){var s,a;const o=[],i=this.coords,r={w:t,h:n};for(const c of this.list){if(!this.shown(c))continue;const f=me(i,c,r);if(!f)continue;const h=this.selected.includes(c.id),u=((s=this.hovered)==null?void 0:s.id)===c.id&&!c.locked,d=h||u&&!this.spec,x=c.kind==="table"&&h&&((a=this.tableUi)==null?void 0:a.id)===c.id?this.tableUi:null,p=je(c,f,{w:t,h:n,coords:i,selected:d&&!c.locked,hovered:u,textSelected:h,tableUi:x});o.push({scene:p,selected:h,hoveredAnchor:u?this.hovered.anchor:-1}),h&&c.locked&&o.push({scene:Hi(f,c.style.color),selected:h,hoveredAnchor:-1})}const l=this.previewScene(t,n);return l&&o.push({scene:l,selected:!1,hoveredAnchor:-1}),o}axisViews(){const t=[],n=[],o=this.coords,i=this.paneSize(),r=this.series.priceFormatter();for(const l of this.list){if(!this.shown(l))continue;const s=me(o,l,i);if(!s)continue;const a=si(l,s,o);for(const c of a.price){const f=o.priceToY(c.price);f!=null&&t.push(fr(f,r.format(c.price),c.back,c.color))}for(const c of a.time){const f=o.timeToX(c.time);f!=null&&n.push(fr(f,o.formatTime(c.time),c.back,c.color))}}return{price:t,time:n}}hoveredId(){var t;return((t=this.hovered)==null?void 0:t.id)??null}cursorAt(){var t;return this.spec?"crosshair":(t=this.gesture)!=null&&t.active?this.gesture.mode.hit==="body"?"move":this.hoverCursor:this.hoverCursor}fontFamily(){return this.opts.fontFamily??this.chart.options().layout.fontFamily}backgroundAt(t,n){const o=this.chart.options().layout.background;return o.type==="gradient"&&o.topColor&&o.bottomColor?Sa(o.topColor,o.bottomColor,n>0?Math.max(0,Math.min(1,t/n)):0):o.color??"#ffffff"}listen(t,n,o,i=!1){t.addEventListener(n,o,i),this.off.push(()=>t.removeEventListener(n,o,i))}emit(t,...n){for(const o of this.listeners[t])o(...n)}changed(){this.emit("change",this.list),this.redraw()}reorder(t,n){const o=this.list.findIndex(l=>l.id===t);if(o<0)return;const i=this.list.slice(),[r]=i.splice(o,1);i.splice(Math.max(0,Math.min(i.length,n)),0,r),this.list=i,this.changed()}shown(t){return!t.hidden&&(this.opts.interval==null||Rt(t.visibility,this.opts.interval))}paneSize(){const t=this.series.getPane().paneIndex(),n=this.chart.paneSize(t);return{w:n.width,h:n.height}}panePoint(t){const o=(this.series.getPane().getHTMLElement()??this.el).getBoundingClientRect(),i=this.chart.priceScale("left").width(),r=this.el.getBoundingClientRect().left;return{x:t.clientX-r-i,y:t.clientY-o.top}}magnet(){const t=this.opts.magnet??"off",n=t==="strong"?"strong":"weak";return this.shift?{enabled:!1,mode:n}:this.ctrl?{enabled:t==="off",mode:"strong"}:{enabled:t!=="off",mode:n}}snapFn(){const t=this.magnet(),n=this.coords;return t.enabled?o=>Xi(o,n,t.mode)??o:o=>o}dataAt(t){const n=V(this.coords,t);return n?this.snapFn()(n):null}aimAt(t){const n=this.magnet();if(!n.enabled)return t;const o=V(this.coords,t),i=o?Xi(o,this.coords,n.mode):null;return i&&st(this.coords,i)||t}hitTopmost(t){const{w:n,h:o}=this.paneSize();if(t.x<0||t.x>n||t.y<0||t.y>o)return null;for(let i=this.list.length-1;i>=0;i--){const r=this.list[i];if(!this.shown(r))continue;const l=me(this.coords,r,{w:n,h:o});if(!l)continue;const s=li(r,l,t,n,o,this.coords,this.selected.includes(r.id));if(s)return{drawing:r,mode:s,pts:l}}return null}setHover(t){var n,o;((n=this.hovered)==null?void 0:n.id)===(t==null?void 0:t.id)&&((o=this.hovered)==null?void 0:o.anchor)===(t==null?void 0:t.anchor)||(this.hovered=t,this.redraw())}holdChart(){if(this.savedScroll)return;const t=this.chart.options();this.savedScroll={handleScroll:structuredClone(t.handleScroll),handleScale:structuredClone(t.handleScale)},this.chart.applyOptions({handleScroll:!1,handleScale:!1})}releaseChart(){this.savedScroll&&(this.chart.applyOptions(this.savedScroll),this.savedScroll=null)}onKey(t){const n=t.type==="keydown";if(t.key==="Shift"?this.shift=n:(t.key==="Control"||t.key==="Meta")&&(this.ctrl=n),!n)return;const o=t.target;if(!(o&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))){if(t.key==="Escape"){if(this.pending.length)this.pending=[],this.redraw();else if(this.spec)this.setTool(null);else if(this.selected.length)this.select([]);else return;t.preventDefault()}else if((t.key==="Delete"||t.key==="Backspace")&&this.selected.length){const i=this.selected.filter(r=>{var l;return!((l=this.get(r))!=null&&l.locked)});if(!i.length)return;for(const r of i)this.remove(r);t.preventDefault()}}}onHover(t){var l,s;if(this.gesture||t.buttons)return;const n=this.panePoint(t);if(this.spec){this.cursor=n,this.redraw();return}const o=this.hitTopmost(n);this.setHover(o?{id:o.drawing.id,anchor:o.mode.hit==="handle"?o.mode.handleIndex:-1}:null);const i=(o==null?void 0:o.drawing.kind)==="table"&&o.mode.hit==="handle"?Io(o.mode.handleIndex):null,r=this.tableUi;(o==null?void 0:o.drawing.kind)==="table"&&this.selected.includes(o.drawing.id)?((((l=r==null?void 0:r.edge)==null?void 0:l.row)??-1)!==((i==null?void 0:i.row)??-1)||(((s=r==null?void 0:r.edge)==null?void 0:s.col)??-1)!==((i==null?void 0:i.col)??-1)||(r==null?void 0:r.id)!==o.drawing.id)&&(this.tableUi=r&&r.id===o.drawing.id?{...r,edge:i}:{id:o.drawing.id,cell:null,editing:!1,edge:i},this.redraw()):r!=null&&r.edge&&(this.tableUi={...r,edge:null},this.redraw()),this.hoverCursor=o?o.drawing.locked?"default":i?i.col!=null&&i.row!=null?"default":i.col!=null?"ew-resize":"ns-resize":o.mode.hit==="handle"?Ki(o.pts[o.mode.handleIndex]??n,o.pts):this.selected.includes(o.drawing.id)?"move":"pointer":null}onPointerDown(t){if(t.button!==0)return;const n=this.panePoint(t),{w:o,h:i}=this.paneSize();if(!(n.x<0||n.x>o||n.y<0||n.y>i)){if(this.spec){t.stopPropagation(),this.holdChart(),this.spec.freehand?this.startFreehand(n):(this.placementClick(n),window.addEventListener("pointerup",()=>this.releaseChart(),{once:!0}));return}this.selectionDown(t,n)}}onDoubleClick(t){var o,i;if((o=this.spec)!=null&&o.variableLength){t.stopPropagation(),this.finishVariable(!1);return}if(this.spec)return;const n=this.hitTopmost(this.panePoint(t));n&&((i=Ie(n.drawing.kind))!=null&&i.textEditable)&&(t.stopPropagation(),this.emit("textEdit",n.drawing,va(n.drawing,n.pts)))}placementClick(t){const n=this.spec;if(n.kind==="image")return;let o=t;const i=this.pending,r=this.coords;if(this.shift&&i.length===1&&n.pointCount===2&&Nn.has(n.kind)){const h=st(r,i[0]);h&&(o=we(h,o))}if(this.shift&&i.length>=1&&Yn.has(n.kind)){const h=st(r,i[i.length-1]);h&&(o=we(h,o))}if(this.shift&&i.length===1&&n.isBbox){const h=st(r,i[0]);if(h){const u=o.x-h.x,d=o.y-h.y,x=Math.max(Math.abs(u),Math.abs(d));o={x:h.x+Math.sign(u||1)*x,y:h.y+Math.sign(d||1)*x}}}if(n.variableLength&&i.length>=1){const h=u=>{const d=st(r,u);return!!d&&Math.hypot(d.x-o.x,d.y-o.y)<Ui};if(h(i[i.length-1])){i.length>=2&&this.finishVariable(!1);return}if(n.kind==="polyline"&&i.length>=2&&h(i[0])){this.finishVariable(!0);return}}const l=this.dataAt(o);if(!l)return;const s=[...i,l];if(n.variableLength||s.length<n.pointCount){this.pending=s,this.cursor=o,this.redraw();return}const{w:a,h:c}=this.paneSize();let f=Un(n.kind,s,r,{w:a,h:c},{glyph:this.glyph});f&&n.kind==="signpost"&&(f={...f,style:{...Ot("signpost"),signpostPosition:Ko(r,s[0],c)}}),this.pending=[],this.cursor=null,f?this.placeNew(f,n.textEditable?o:null):this.afterPlacement()}finishVariable(t){const n=this.spec;if(!(n!=null&&n.variableLength)||this.pending.length<2)return;const{w:o,h:i}=this.paneSize(),r=Un(n.kind,this.pending,this.coords,{w:o,h:i},{closed:t});this.pending=[],this.cursor=null,r?this.placeNew(r,null):this.afterPlacement()}placeNew(t,n){const o=this.add(t);this.opts.stayInDrawingMode||this.select([o]);const i=this.get(o);i&&n&&this.emit("textEdit",i,n),this.afterPlacement()}afterPlacement(){this.emit("gestureEnd"),this.opts.stayInDrawingMode?this.redraw():this.setTool(null)}startFreehand(t){const n=this.spec,o=V(this.coords,t);if(!o)return;this.pending=[o],this.cursor=t;let i=t;const r=s=>{const a=this.panePoint(s);if(this.cursor=a,Math.hypot(a.x-i.x,a.y-i.y)<Kc)return;const c=V(this.coords,a);c&&(i=a,this.pending=[...this.pending,c],this.redraw())},l=()=>{document.removeEventListener("pointermove",r),document.removeEventListener("pointerup",l),this.releaseChart();const s=this.pending;this.pending=[],this.cursor=null;const a=s.length>=2?qe(n.kind,s):null;a?this.placeNew(a,null):this.afterPlacement()};document.addEventListener("pointermove",r),document.addEventListener("pointerup",l)}selectionDown(t,n){const o=this.hitTopmost(n),i=t.ctrlKey||t.metaKey;if(!o){!i&&this.selected.length&&this.select([]);return}t.stopPropagation(),this.holdChart();const r=this.selected,l=r.includes(o.drawing.id),s=l&&r.length>1;if(!i&&!l&&this.select([o.drawing.id]),o.drawing.locked){i?this.toggle(o.drawing.id):s&&this.select([o.drawing.id]),window.addEventListener("pointerup",()=>this.releaseChart(),{once:!0});return}const a=this.paneSize(),c=s&&o.mode.hit==="body"?r.map(u=>this.get(u)).filter(u=>!!u&&!u.locked&&this.shown(u)).map(u=>({start:u,startScreen:me(this.coords,u,a)})).filter(u=>!!u.startScreen):void 0;this.gesture={id:o.drawing.id,start:o.drawing,startCursor:n,startScreen:o.pts,mode:o.mode,active:!1,group:c,pendingToggle:i,pendingCollapse:!i&&s,pane:a,canDrag:o.mode.hit==="handle"||l};const f=u=>this.dragMove(this.panePoint(u)),h=()=>{var d,x;document.removeEventListener("pointermove",f),document.removeEventListener("pointerup",h);const u=this.gesture;if(u&&!u.active&&(u.pendingToggle?this.toggle(u.id):u.pendingCollapse&&this.select([u.id]),u.start.kind==="table"&&!i&&(u.mode.hit==="body"&&u.mode.cell&&l?this.openCell(u.start,u.mode.cell):u.mode.hit==="handle"&&u.mode.handleIndex<4&&((d=this.tableUi)==null?void 0:d.id)===u.id&&(this.tableUi={...this.tableUi,cell:null,editing:!1},this.redraw()))),u!=null&&u.active&&u.start.kind==="image"){const p=this.get(u.id);if(((x=p==null?void 0:p.image)==null?void 0:x.dx)!=null){const{dx:y,...b}=p.image;this.update({...p,image:b})}}this.endGesture(),this.emit("gestureEnd")};document.addEventListener("pointermove",f),document.addEventListener("pointerup",h)}dragMove(t){const n=this.gesture;if(!n)return;if(!n.active){if(!n.canDrag||Math.hypot(t.x-n.startCursor.x,t.y-n.startCursor.y)<Zc)return;if(n.pendingToggle&&n.mode.hit==="body"&&!n.group){const{id:i,...r}=n.start;this.add(r),this.select([n.id])}n.active=!0,n.pendingToggle=!1,n.pendingCollapse=!1}if(n.group){const i=t.x-n.startCursor.x,r=t.y-n.startCursor.y;for(const l of n.group){const s=Hn(this.coords,l.start,l.startScreen,i,r,this.paneSize());s&&this.update(s)}return}const o=qi(n,t,this.coords,this.snapFn(),this.shift);o&&this.update(o)}endGesture(){this.gesture=null,this.releaseChart()}openCell(t,n){this.tableUi={id:t.id,cell:n,editing:!0,edge:null},this.redraw();const o=me(this.coords,t,this.paneSize());if(!o)return;const i=xn(t,o[0]),[r,l]=n;this.emit("tableEdit",t,n,{left:i.xs[l],top:i.ys[r],width:i.xs[l+1]-i.xs[l],height:i.ys[r+1]-i.ys[r]})}toggle(t){this.select(this.selected.includes(t)?this.selected.filter(n=>n!==t):[...this.selected,t])}previewScene(t,n){const o=this.spec,i=this.pending,r=this.cursor;if(!o||!i.length||!r)return null;const l=this.coords,s=i.map(d=>st(l,d)).filter(d=>!!d);if(!s.length)return null;const a=Ot(o.kind),c=this.aimAt(r),f=s.map(d=>({t:"circle",cx:d.x,cy:d.y,r:3,fill:a.color}));if(!o.variableLength&&!o.freehand&&!Jc.has(o.kind)&&s.length===i.length&&s.length<o.pointCount){let d=c;this.shift&&(s.length===1&&o.pointCount===2&&Nn.has(o.kind)||Yn.has(o.kind))&&(d=we(s[s.length-1],c));const x=this.dataAt(d);if(x){const p=[...i];for(;p.length<o.pointCount;)p.push(x);const y=qe(o.kind,p),b=y&&o.kind==="gann-square"?ji(y,l):y,g=b?{...b,id:"__preview__",style:a}:null,m=g?Vi(l,g.points):null;if(g&&m)return[...je(g,m,{w:t,h:n,coords:l,selected:!1}),...f]}}if(o.freehand&&s.length>=2)return je({id:"__preview__",kind:o.kind,points:i,style:a},s,{w:t,h:n,coords:l,selected:!1});const h=s[s.length-1],u=[];return s.length>=2&&u.push({t:"polyline",pts:s,fill:"none",stroke:a.color,strokeWidth:a.width,cap:"round"}),u.push({t:"line",a:h,b:c,stroke:a.color,strokeWidth:a.width,cap:"round"}),[...u,...f]}}function va(e,t){return(e.kind==="callout"||e.kind==="note")&&t[1]?t[1]:e.kind==="price-note"&&t[1]?{x:(t[0].x+t[1].x)/2,y:(t[0].y+t[1].y)/2}:t[0]}function La(e){return e.data().map(t=>{const n=t,o=n.value??n.close??0;return{time:n.time,open:n.open??o,high:n.high??o,low:n.low??o,close:n.close??o,volume:n.volume}})}function Sa(e,t,n){const o=/^#([0-9a-f]{6})$/i.exec(e),i=/^#([0-9a-f]{6})$/i.exec(t);if(!o||!i)return e;const r=parseInt(o[1],16),l=parseInt(i[1],16),s=a=>Math.round((r>>a&255)+((l>>a&255)-(r>>a&255))*n);return"#"+(s(16)<<16|s(8)<<8|s(0)).toString(16).padStart(6,"0")}function fr(e,t,n,o){return{coordinate:()=>e,text:()=>t,backColor:()=>n,textColor:()=>o,visible:()=>!0,tickVisible:()=>!0}}class Ca{constructor(t){H(this,"m");H(this,"request",null);H(this,"view");H(this,"axis",{price:[],time:[]});this.m=t;const n={draw:o=>this.draw(o)};this.view={zOrder:()=>"top",renderer:()=>n}}attached(t){this.request=t.requestUpdate}detached(){this.request=null}paneViews(){return[this.view]}updateAllViews(){this.axis=this.m.axisViews()}priceAxisViews(){return this.axis.price}timeAxisViews(){return this.axis.time}requestUpdate(){var t;(t=this.request)==null||t.call(this)}hitTest(){const t=this.m.cursorAt();return t?{cursorStyle:t,externalId:`lwcd:${this.m.hoveredId()??""}:${t}`,zOrder:"top"}:null}draw(t){t.useMediaCoordinateSpace(({context:n,mediaSize:o})=>{const i=o.width,r=o.height;n.save(),n.beginPath(),n.rect(0,0,i,r),n.clip();const l=this.m.fontFamily(),s=c=>this.m.backgroundAt(c,r),a=()=>this.requestUpdate();for(const c of this.m.scenes(i,r))ir(n,c.scene,{fontFamily:l,anchors:{fillAt:s,selected:c.selected,hovered:c.hoveredAnchor},onAsyncLoad:a});n.restore()})}}const Ta="0.2.0";z.ANCHORABLE_KINDS=Qi,z.DEFAULT_STYLE=nt,z.DrawingManager=ka,z.IMAGE_MAX_BYTES=Zr,z.IMAGE_MAX_SIDE=pn,z.IMAGE_TYPES=Kr,z.OVERLAY_SPECS=se,z.TV_ANCHOR_COLOR=Vn,z.VERSION=Ta,z.anchorCursor=Ki,z.applyDrag=qi,z.buildNewDrawing=qe,z.cacheImage=nl,z.decodeImage=_o,z.defaultStyleFor=Ot,z.drawScene=ir,z.drawingAxisLabels=si,z.factoryStyleFor=mr,z.findOverlaySpec=Ie,z.finishPlacement=Un,z.hitTestKind=li,z.isAnchorable=Ji,z.isVisibleOnInterval=Rt,z.makeCoords=er,z.migrateDrawing=Yi,z.onImagesChanged=Oo,z.parseDrawings=Ni,z.sceneLockedAnchors=Hi,z.sceneOf=je,z.setDefaultStyleOverride=wr,z.setImageReader=Qr,z.timeToXFallback=ua,z.toggleAnchored=tr,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})}));
8
+ //# sourceMappingURL=lightweight-charts-drawing.umd.cjs.map