lightweight-charts-drawing 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/index.d.ts +18 -6
- package/dist/lightweight-charts-drawing.es.js +1214 -1183
- package/dist/lightweight-charts-drawing.es.js.map +1 -1
- package/dist/lightweight-charts-drawing.umd.cjs +7 -7
- package/dist/lightweight-charts-drawing.umd.cjs.map +1 -1
- package/package.json +5 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(E,ot){typeof exports=="object"&&typeof module<"u"?ot(exports):typeof define=="function"&&define.amd?define(["exports"],ot):(E=typeof globalThis<"u"?globalThis:E||self,ot(E.LightweightChartsDrawing={}))})(this,(function(E){"use strict";var hf=Object.defineProperty;var uf=(E,ot,Ot)=>ot in E?hf(E,ot,{enumerable:!0,configurable:!0,writable:!0,value:Ot}):E[ot]=Ot;var Y=(E,ot,Ot)=>uf(E,typeof ot!="symbol"?ot+"":ot,Ot);const ot={color:"#2962ff",width:1,lineStyle:"solid"};function Ot(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 q="#808080",st="#f23645",it="#ff9800",rt="#4caf50",Z="#089981",et="#00bcd4",$="#2962ff",jt="#9c27b0",ut="#e91e63",qt="#673ab7",$t=[{coeff:0,color:q,visible:!0},{coeff:.236,color:st,visible:!0},{coeff:.382,color:it,visible:!0},{coeff:.5,color:rt,visible:!0},{coeff:.618,color:Z,visible:!0},{coeff:.786,color:et,visible:!0},{coeff:1,color:q,visible:!0},{coeff:1.618,color:$,visible:!0},{coeff:2.618,color:st,visible:!0},{coeff:3.618,color:jt,visible:!0},{coeff:4.236,color:ut,visible:!0},{coeff:1.272,color:it,visible:!1},{coeff:1.414,color:st,visible:!1},{coeff:2.272,color:it,visible:!1},{coeff:2.414,color:rt,visible:!1},{coeff:2,color:Z,visible:!1},{coeff:3,color:et,visible:!1},{coeff:3.272,color:q,visible:!1},{coeff:3.414,color:$,visible:!1},{coeff:4,color:st,visible:!1},{coeff:4.272,color:jt,visible:!1},{coeff:4.414,color:ut,visible:!1},{coeff:4.618,color:it,visible:!1},{coeff:4.764,color:Z,visible:!1}],Lt=[{coeff:.25,color:"#ffb74d",visible:!1},{coeff:.382,color:"#81c784",visible:!1},{coeff:.5,color:Z,visible:!0},{coeff:.618,color:Z,visible:!1},{coeff:.75,color:et,visible:!1},{coeff:1,color:$,visible:!0},{coeff:1.5,color:jt,visible:!1},{coeff:1.75,color:ut,visible:!1},{coeff:2,color:"#f77c80",visible:!1}],on=[{coeff:1/8,color:it,visible:!0,label:"1/8"},{coeff:1/4,color:Z,visible:!0,label:"1/4"},{coeff:1/3,color:rt,visible:!0,label:"1/3"},{coeff:1/2,color:Z,visible:!0,label:"1/2"},{coeff:1,color:et,visible:!0,label:"1/1"},{coeff:2,color:$,visible:!0,label:"2/1"},{coeff:3,color:jt,visible:!0,label:"3/1"},{coeff:4,color:ut,visible:!0,label:"4/1"},{coeff:8,color:st,visible:!0,label:"8/1"}],rn=[{coeff:.236,color:st,visible:!0},{coeff:.382,color:it,visible:!0},{coeff:.5,color:rt,visible:!0},{coeff:.618,color:Z,visible:!0},{coeff:.786,color:et,visible:!0},{coeff:1,color:q,visible:!0},{coeff:1.618,color:$,visible:!1},{coeff:2.618,color:st,visible:!1},{coeff:3.618,color:qt,visible:!1},{coeff:4.236,color:ut,visible:!1},{coeff:4.618,color:ut,visible:!1}],Ae=[{coeff:0,color:q,visible:!0},{coeff:.25,color:it,visible:!0},{coeff:.382,color:et,visible:!0},{coeff:.5,color:rt,visible:!0},{coeff:.618,color:Z,visible:!0},{coeff:.75,color:$,visible:!0},{coeff:1,color:q,visible:!0}],ln=[{coeff:0,color:q,visible:!0,width:2,style:"solid"},{coeff:.382,color:st,visible:!0,width:2,style:"solid"},{coeff:.5,color:"#81c784",visible:!1,width:2,style:"solid"},{coeff:.618,color:rt,visible:!0,width:2,style:"solid"},{coeff:1,color:Z,visible:!0,width:2,style:"solid"},{coeff:1.382,color:et,visible:!0,width:2,style:"solid"},{coeff:1.618,color:q,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:jt,visible:!0,width:2,style:"solid"},{coeff:3,color:"#673ab7",visible:!0,width:2,style:"solid"}],sn={visible:!0,color:q,width:2,style:"dashed"},Er=sn,zr={visible:!0,color:q,width:2,style:"solid"},Zt=(e,t)=>({color:e,width:2,visible:t}),G=(e,t,n,o)=>({color:e,width:2,visible:t,x:n,y:o}),cn=[Zt(q,!0),Zt(it,!0),Zt(et,!0),Zt(rt,!0),Zt(Z,!0),Zt(q,!0)],an=[G("#b39ddb",!1,8,1),G(st,!1,5,1),G(q,!1,4,1),G(it,!1,3,1),G(et,!0,2,1),G(rt,!0,1,1),G(Z,!0,1,2),G(Z,!1,1,3),G($,!1,1,4),G("#9575cd",!1,1,5),G("#b39ddb",!1,1,8)],fn=[G(it,!0,1,0),G(it,!0,1,1),G(it,!0,1.5,0),G(et,!0,2,0),G(et,!0,2,1),G(rt,!0,3,0),G(rt,!0,3,1),G(Z,!0,4,0),G(Z,!0,4,1),G($,!0,5,0),G($,!0,5,1)],to={visible:!0,color:"rgba(21, 56, 153, 0.8)",width:1,style:"solid"},hn=[{coeff:0,color:q,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}],un=[{coeff:1,color:rt,visible:!0},{coeff:2,color:"#808000",visible:!1},{coeff:3,color:"#00897b",visible:!1}],eo=[{visible:!0,color:rt,width:1,style:"solid"},{visible:!0,color:"#808000",width:1,style:"solid"},{visible:!0,color:"#00897b",width:1,style:"solid"}],dn=[{coeff:.236,color:st,visible:!0},{coeff:.382,color:it,visible:!0},{coeff:.5,color:Z,visible:!0},{coeff:.618,color:rt,visible:!0},{coeff:.786,color:et,visible:!0},{coeff:1,color:q,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:st,visible:!0}],xn=[{coeff:.236,color:st,visible:!0},{coeff:.382,color:it,visible:!0},{coeff:.5,color:Z,visible:!0},{coeff:.618,color:rt,visible:!0},{coeff:.786,color:et,visible:!0},{coeff:1,color:q,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:st,visible:!0}],$e=[{coeff:0,color:q,visible:!0},{coeff:.25,color:it,visible:!0},{coeff:.382,color:et,visible:!0},{coeff:.5,color:rt,visible:!0},{coeff:.618,color:Z,visible:!0},{coeff:.75,color:$,visible:!0},{coeff:1,color:q,visible:!0}],Rr=7,Wr={upColor:"#ACE5DC",downColor:"#FAA1A4",drawBorder:!0,borderUpColor:"#089981",borderDownColor:"#F23645",drawWick:!0,wickColor:"#808080"},no={base:{visible:!0,color:st,width:1,style:"dashed"},up:{visible:!0,color:$,width:2,style:"solid"},down:{visible:!0,color:$,width:2,style:"solid"}};function oo(e){const t=(n,o,i)=>({visible:n,color:o,width:i,style:"solid"});return{rowsLayout:"rows",rows:24,volume:"upDown",vaVolume:70,extendRight:!1,visible:!0,showValues:!1,valuesColor:"#DBDBDB",percentWidth:30,placement:e==="anchored-volume-profile"?"right":"left",upColor:"rgba(38, 198, 218, 0.5)",downColor:"rgba(236, 64, 122, 0.5)",vaUpColor:"rgba(38, 198, 218, 0.75)",vaDownColor:"rgba(236, 64, 122, 0.75)",vah:t(!1,"#DBDBDB",2),val:t(!1,"#DBDBDB",2),poc:t(!0,"#DBDBDB",2),developingPoc:t(!1,"#DBDBDB",1),developingVah:t(!1,"#00BCD4",1),developingVal:t(!1,"#00BCD4",1),boxColor:"rgba(38, 198, 218, 0.05)"}}function Be(e,t){return{...oo(e),...t.vp??{}}}const Ie=[-.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"})),Dr=Lt.map(e=>e.coeff===.5?{...e,color:et}:e),ae={"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,extendLine:!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:q,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:q,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:on,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:$e,vLevels:$e,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:hn,fillBackground:!1,transparency:80,showLabels:!0,horzLabelsAlign:"right",vertLabelsAlign:"bottom"}},"fib-circles":{kind:"fib-circles",pointCount:2,preview:"line",isBbox:!1,defaults:{color:q,width:2,levels:xn,fillBackground:!0,transparency:80}},"fib-speed-resistance-fan":{kind:"fib-speed-resistance-fan",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,levels:Ae,vLevels:Ae,fillBackground:!0,transparency:80,showLeftLabels:!0,showRightLabels:!0,showTopLabels:!0,showBottomLabels:!0,reverse:!1,fanGrid:to}},"fib-speed-resistance-arcs":{kind:"fib-speed-resistance-arcs",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,levels:dn,fillBackground:!0,transparency:80}},"fib-spiral":{kind:"fib-spiral",pointCount:2,preview:"line",isBbox:!1,defaults:{color:et,width:2}},"trend-based-fib-time":{kind:"trend-based-fib-time",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:ln,fibTrendLine:sn,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:cn,gannFans:an,gannArcs:fn,fillBackground:!0,transparency:80,reverse:!1}},"gann-square":{kind:"gann-square",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,gannLevels:cn,gannFans:an,gannArcs:fn,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:jt}},"fib-wedge":{kind:"fib-wedge",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:rn,fillBackground:!0,transparency:80}},pitchfan:{kind:"pitchfan",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Dr,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:$t,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:Ie,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:Lt,fillBackground:!0,transparency:80}},"trend-based-fib-extension":{kind:"trend-based-fib-extension",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:$t,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:Lt,fillBackground:!0,transparency:80}},"modified-schiff-pitchfork":{kind:"modified-schiff-pitchfork",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Lt,fillBackground:!0,transparency:80}},"inside-pitchfork":{kind:"inside-pitchfork",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Lt,fillBackground:!0,transparency:80}},"fib-channel":{kind:"fib-channel",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:$t,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:qt,width:2,fillBackground:!1,backgroundColor:qt,transparency:80}},"abcd-pattern":{kind:"abcd-pattern",pointCount:4,preview:"line",isBbox:!1,defaults:{color:Z,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:Z,width:2,textColor:"#ffffff",fontSize:12,fillBackground:!0,backgroundColor:Z,transparency:85}},"triangle-pattern":{kind:"triangle-pattern",pointCount:4,preview:"line",isBbox:!1,defaults:{color:qt,width:2,textColor:"#ffffff",fontSize:12,fillBackground:!0,backgroundColor:qt,transparency:85}},"three-drives-pattern":{kind:"three-drives-pattern",pointCount:7,preview:"line",isBbox:!1,defaults:{color:qt,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:it,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:et,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:et,width:2,fillBackground:!1,backgroundColor:et,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:no}},"anchored-vwap":{kind:"anchored-vwap",pointCount:1,preview:"none",isBbox:!1,defaults:{color:"#1e88e5",width:1,vwapSource:"hlc3",levels:un,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}},Or=new Set(Object.keys(ae));function Pe(e){if(e&&Or.has(e))return ae[e]}function Ft(e){const t={...ot,...ae[e].defaults,...io(e)};return t.levels&&(t.levels=t.levels.map(n=>({...n}))),t}function Fr(e){const t={...ot,...ae[e].defaults};return t.levels&&(t.levels=t.levels.map(n=>({...n}))),t}let io=()=>{};function _r(e){io=e}const nt=6,L=6,ro=9;function R(e){if(e.lineStyle==="dashed")return"6 4";if(e.lineStyle==="dotted")return"2 3"}function Ee(e){return Math.max(L,((e==null?void 0:e.width)??1)/2+2)}function fe(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 H(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 Kt(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 yt(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 _(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 Hr(e,t){const n=e[0];return Math.hypot(n.x-t.x,n.y-t.y)<=nt+L?{hit:"handle",handleIndex:0}:Math.abs(t.x-n.x)<=ro+L&&Math.abs(t.y-n.y)<=ro+L?{hit:"body"}:null}function lo(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 Nr=[["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 ze(e,t){var o;return((o=e.positionStats)==null?void 0:o[t])??Nr.find(i=>i[0]===t)[2]}function Re(e,t){const n=Math.abs(e).toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t});return e<0?`−${n}`:n}function so(e,t,n,o,i,r,l,s){const a=d=>ze(e,t+d),c=!!e.compactStats,f=Re(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!==""?" ":"")+Re(Math.round(n/i),0)),a("Amount")&&(u+=c?(u!==""?" ":"")+String(l):(u!==""?", ":"")+`Amount: ${l}`),a("PL")&&(u+=c?(u!==""?" ":"")+Re(s,r):(u!==""?", ":"")+`PnL: ${Re(s,r)}`),u}function Yr(e,t,n,o,i){const r=!!e.compactStats;let l="";return ze(e,"openClosePL")&&t&&(l+=r?t:`${n?"Closed":"Open"} PnL: ${t}`),ze(e,"qty")&&(l+=(l!==""?r?" ~ ":", ":"")+(r?String(o):`Qty: ${o}`)),ze(e,"riskRewardRatio")&&(l+=(l!==""?`
|
|
2
|
-
`:"")+(r?String(i):`Risk/reward ratio: ${i}`)),l}const he={accountSize:1e3,risk:25,leverage:1e4};function
|
|
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=>Bt(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",m=e.angle??0,b=Math.cos(m),g=Math.sin(m),w=(M,v)=>({x:(M-d)*b-(v-x)*g+d,y:(M-d)*g+(v-x)*b+x});return{lines:n,fs:t,lineStep:t+c,tx:p,y0:h+o+t/2+.05*t,anchor:y,rotate:`rotate(${m*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 po(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 j({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 mo(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",m=y==="middle",b=m?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:m?(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:b,wrapWidth:m?(h?n:s)-(f?0:l)-2*b:void 0,maxHeight:m?c-a:void 0},M=j(w);if(p==="left"&&f||p==="right"&&h){const v=f?0:Math.max(l,0),S=(h?n:Math.min(s,n))-v-M.box.width;if(S<0)return j({...w,offsetX:S})}return M}function De(e,t){return Math.floor(e/t+.5+1e-7)}function bo(e){const t=new Array(e.length);let n=NaN,o=!0;for(let i=0;i<e.length;i++){const r=e[i];let l;r.close>r.open?l=!0:r.close<r.open?l=!1:r.close>n?l=!0:r.close<n?l=!1:l=o,t[i]=l,n=r.close,o=l}return t}function Qr(e,t,n,o){const i=Math.max(1,Math.round(o)),r=Math.max(0,t-e);if(n==="Ticks Per Row"){const l=Math.floor(e/i)*i;return{start:l,tpr:i,count:Math.max(1,Math.ceil((t-l)/i))}}return{start:e,...Jr(r,i)}}function Jr(e,t){const n=l=>Math.max(1,Math.ceil(e/l)),o=Math.max(1,Math.floor(e/t)),i=Math.max(1,Math.ceil(e/t)),r=Math.abs(n(o)-t)<=Math.abs(n(i)-t)?o:i;return{tpr:r,count:n(r)}}function tl(e){let t=0;const n=(e.length-1)/2;for(let o=1;o<e.length;o++)(e[o]>e[t]||e[o]===e[t]&&Math.abs(o-n)<=Math.abs(t-n))&&(t=o);return t}function el(e,t,n){let o=0;for(const c of e)o+=c;const i=o*Math.max(0,Math.min(100,n))/100;let r=t,l=t,s=e[t]??0;const a=e.length;for(;r>0||l<a-1;){const c=l<a-1?e[l+1]:-1,f=r>0?e[r-1]:-1;let h;c!==f?h=c>f:h=l+1-t<=t-(r-1);const u=h?c:f;if(s+u>i)break;s+=u,h?l++:r--}return[r,l]}function go(e,t,n,o,i,r,l){if(o<n)return null;let s=1/0,a=-1/0;for(let b=n;b<=o;b++){const g=De(e[b].low,i),w=De(e[b].high,i);g<s&&(s=g),w>a&&(a=w)}if(!Number.isFinite(s)||!Number.isFinite(a))return null;let c,f,h;"fixedTpr"in r?(f=Math.max(1,r.fixedTpr),c=Math.floor(s/f)*f,h=Math.max(1,Math.ceil((a-c)/f))):{start:c,tpr:f,count:h}=Qr(s,a,r.layout,r.rowSize);const u=new Array(h).fill(0),d=new Array(h).fill(0);for(let b=n;b<=o;b++){const g=e[b],w=g.volume??0;if(!(w>0))continue;const M=t[b]?u:d,v=De(g.low,i)-c,k=De(g.high,i)-c;if(k<=v){M[Math.min(h-1,Math.max(0,Math.floor(v/f)))]+=w;continue}const S=k-v,C=Math.max(0,Math.floor(v/f)),I=Math.min(h-1,Math.ceil(k/f)-1);for(let A=C;A<=I;A++){const D=Math.max(v,A*f),F=Math.min(k,(A+1)*f);F>D&&(M[A]+=w*(F-D)/S)}}const x=u.map((b,g)=>b+d[g]),p=tl(x),[y,m]=el(x,p,l);return{lo:c*i,step:f*i,up:u,down:d,poc:p,vaLo:y,vaHi:m,boxLo:s*i,boxHi:a*i}}function nl(e){return{poc:e.lo+(e.poc+.5)*e.step,vah:e.lo+(e.vaHi+1)*e.step,val:e.lo+e.vaLo*e.step}}const ol=[["1",60],["5",300],["15",900],["30",1800],["60",3600],["240",14400],["1D",86400]];function il(e,t){if(t||e<=300)return"1S";for(const[n,o]of ol)if(e/o<5e3)return n;return"1D"}function wo(e,t){let n=0,o=e.length;for(;n<o;){const i=n+o>>1;e[i].time<t?n=i+1:o=i}return n}function Oe(e,t,n){const o=Math.min(t,n),i=Math.max(t,n),r=[];for(const l of e){const s=_(l.time);s!=null&&s>=o&&s<=i&&r.push(l)}return r}function rl(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 ll(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 Mo(e,t,n){const o=e.points[1],i=_(e.points[0].time),r=o?_(o.time):null;if(!t||i==null||r==null)return null;const l=Oe(t.bars(),i,r),s=e.style.regressionSource??"close",a=rl(l.map(S=>vo(S,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 S=0;S<c;S++){const C=a.b+a.m*S;u=Math.max(u,l[S].high-C),d=Math.max(d,C-l[S].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=(S,C)=>{const I=t.timeToX(S),A=t.priceToY(C);return I==null||A==null?null:{x:I,y:A}},m=y(l[0].time,f),b=y(l[c-1].time,h);if(!m||!b)return null;const g=y(l[0].time,f+x),w=y(l[c-1].time,h+x),M=y(l[0].time,f+p),v=y(l[c-1].time,h+p),k=S=>e.style.extendRight&&n!=null?ll(S,n):S;return{center:k([m,b]),upper:g&&w?k([g,w]):null,lower:M&&v?k([M,v]):null,pearsons:a.r,anchors:i<=r?[m,b]:[b,m]}}function vo(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 pn(e,t,n){const o=n==="upper"?e.vwapUpper:e.vwapLower,i=(e.levels??un)[t],r=eo[t]??eo[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 ko=new WeakMap;function Lo(e,t,n,o){const i=t[t.length-1],r=`${n}|${o}|${t.length}|${i?`${_(i.time)}:${i.close}:${i.volume}`:""}`;let l=ko.get(t);l||(l=new Map,ko.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 m=a+c>>1,b=_(t[m].time);b!=null&&b<n?a=m+1:c=m}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 m=0;m<f;m++){const b=t[a+m],g=vo(b,o),w=b.volume&&b.volume>0?b.volume:1;d+=g*w,x+=g*g*w,p+=w;const M=d/p;h[m]=M,u[m]=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 So(e,t){let n=0,o=e.length;for(;n<o;){const i=n+o>>1,r=_(e[i].time);r!=null&&r<t?n=i+1:o=i}return n}function sl(e,t){var n;return t?((n=cl(e,t.bars()))==null?void 0:n.vwap)??null:null}function cl(e,t){const n=e.points[0]?_(e.points[0].time):null;if(n==null||t.length===0)return null;const o=Lo(e,t,n,e.style.vwapSource??"hlc3"),i=o.vwap.length-1;return i>=0?{vwap:o.vwap[i],sd:o.sd[i]}:null}function Co(e,t){const 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??un).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=Lo(e,l,n,i);let a=s.start,c=l.length;const f=t.visibleTimeRange();f&&(a=Math.max(a,So(l,f.from)-1),c=Math.min(c,So(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 m=r?x*.01:s.sd[u];for(const b of o.bands){const g=t.priceToY(x+b.level.coeff*m),w=t.priceToY(x-b.level.coeff*m);g!=null&&b.upper.push({x:p,y:g}),w!=null&&b.lower.push({x:p,y:w})}}}return o}function To(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 al(e,t){const n=e.points[1];if(!t||!n)return"waiting";const o=_(n.time);if(o==null)return"waiting";const i=t.bars();if(i.length===0)return"waiting";const r=_(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=_(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"}const Ao=new WeakMap;function fl(e){let t=Ao.get(e);return(!t||t.length!==e.length)&&(t=bo(e),Ao.set(e,t)),t}function $o(e,t,n,o={}){const i=Oe(e,t,n);if(i.length===0)return null;const r=Math.min(1,Math.max(0,o.vaShare??.7))*100,l=o.tick&&o.tick>0?o.tick:.01,s={layout:o.rowsLayout==="ticks"?"Ticks Per Row":"Number Of Rows",rowSize:Math.max(1,Math.round(o.rows??24))},a=_(i[0].time)??0,c=_(i[i.length-1].time)??a;let f=i,h=0,u=i.length-1;const d=o.lower;if(d){const g=d.barEnd(c),w=d.bars(il(g-a,d.seconds),a);if(w&&w.length){const M=w,v=wo(M,a),k=wo(M,g)-1;k>=v&&(f=w,h=v,u=k)}}const x=f===i?bo(i):fl(f),p=go(f,x,h,u,l,s,r);if(!p)return null;let y=null;if(o.developing){y=[];let g=h;for(let w=0;w<i.length;w++){const M=w+1<i.length?_(i[w+1].time)??1/0:1/0;for(;g+1<=u&&(_(f[g+1].time)??0)<M;)g++;if((_(f[h].time)??0)>=M)continue;const v=g===u?p:go(f,x,h,g,l,s,r);if(!v)continue;const k=nl(v);y.push({time:i[w].time,poc:k.poc,vah:k.vah,val:k.val})}}const m=p.up.map((g,w)=>({up:g,down:p.down[w]})),b=m.map(g=>g.up+g.down);return{lo:p.lo,hi:p.lo+m.length*p.step,step:p.step,rows:m,poc:p.poc,vaFrom:p.vaLo,vaTo:p.vaHi,maxTotal:Math.max(...b),maxDelta:Math.max(...m.map(g=>Math.abs(g.up-g.down))),lastTime:i[i.length-1].time,developing:y}}function Bo(e,t){const n=Be(e.kind,e.style);return{rowsLayout:n.rowsLayout,rows:n.rows,tick:t.pipSize(),vaShare:n.vaVolume/100,developing:n.developingPoc.visible||n.developingVah.visible||n.developingVal.visible,lower:t.lowerTimeframe}}function Io(e,t,n){if(!n)return null;const o=n.bars();if(o.length===0)return null;const i=_(e.points[0].time),r=_(o[o.length-1].time);if(i==null||r==null)return null;const l=$o(o,i,r,Bo(e,n));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 Po(e,t,n){if(!n||e.points.length<2||t.length<2)return null;const o=_(e.points[0].time),i=_(e.points[1].time);if(o==null||i==null)return null;const r=n.bars(),l=Be(e.kind,e.style).extendRight,s=r.length?_(r[r.length-1].time):null,a=Math.min(o,i),c=l&&s!=null?Math.max(s,a):Math.max(o,i),f=$o(r,a,c,Bo(e,n));if(!f)return null;const h=n.priceToY(f.hi),u=n.priceToY(f.lo);if(h==null||u==null)return null;const d=Math.min(t[0].x,t[1].x),x=l?n.timeToX(f.lastTime):null,p=x!=null?Math.max(d,x):Math.max(t[0].x,t[1].x);return{left:d,right:p,top:Math.min(h,u),bottom:Math.max(h,u),vp:f}}function Eo(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 v=(n==null?void 0:n.priceToY(h+M.coeff*u))??d+M.coeff*x;return{coeff:M.coeff,color:M.color,y:v}}),y=(n==null?void 0:n.timeToBarIndex(c.time))??null,m=(n==null?void 0:n.timeToBarIndex(f.time))??null,b=a?i.x:r.x,g=a?r.x-i.x:i.x-r.x,w=s.map(M=>{let v=null;if(n&&y!=null&&m!=null){const k=n.barIndexToTime(Math.round((a?y:m)+M.coeff*(a?m-y:y-m)));v=k!=null?n.timeToX(k):null}return{coeff:M.coeff,color:M.color,x:v??b+M.coeff*g}});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 mn(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 hl=["bars","oc","line","line-open","line-high","line-low","line-hl2"];function zo(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 Ro(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 Wo(e,t,n){var F;if(e.kind!=="bar-pattern"||!n)return null;const o=((F=e.pattern)==null?void 0:F.bars)??[];if(o.length===0||t.length<2)return null;const i=e.style,[r,l]=t,s=hl.includes(i.patternMode??"")?i.patternMode:"bars";let a=o;if(i.mirrored){let T=1/0,z=-1/0;for(const P of a)T=Math.min(T,P[2],P[1]),z=Math.max(z,P[1],P[2]);if(T<z){const P=(T+z)/2,B=O=>P-(O-P);a=a.map(([O,U,tt,Mt])=>[B(O),B(U),B(tt),B(Mt)])}}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=Ro(a[0],s,!0,!!i.flipped),p=Ro(a[a.length-1],s,!1,!!i.flipped),y=n.priceToY(x),m=n.priceToY(p);if(u==null||d==null||y==null||m==null)return null;const b=m!==y?+((d-u)/(m-y)).toFixed(8):1,g=T=>(n.priceToY(T)??0)*b,w=n.timeToBarIndex(e.points[0].time),M=n.timeToBarIndex(e.points[1].time),k=w==null||M==null||w<=M?{x:r.x,y:u}:{x:l.x,y:d},S=a.length,C=S>1?Math.abs(r.x-l.x)/(S-1):0,I=k.y-g(x),A=a.map((T,z)=>Math.round(k.x+z*C+.5)),D=s!=="bars"&&s!=="oc";return D?{lineMode:D,bars:[],line:a.map((T,z)=>({x:A[z],y:Math.round(g(zo(T,s)[0]))+I}))}:{lineMode:D,line:[],bars:a.map((T,z)=>{const[P,B]=zo(T,s),O=Math.round(g(P))+I,U=Math.round(g(B))+I;return{x:A[z],top:Math.min(O,U),bottom:Math.max(O,U)}})}}let de=null;function ul(e,t){return de||(de=document.createElement("canvas").getContext("2d")),de?(de.font=t,de.measureText(e).width):e.length*8}function Do(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=>ul(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 _t=8,dt=1,dl=2,Oo=120,Fo=1.3,xl="#2962ff",yl="rgba(41, 98, 255, 0.2)",_o=3,Jt=1024;function pl(e){return Jt+(e.row==null?0:e.row+1)*Jt+(e.col==null?0:e.col+1)}function Ho(e){if(e<Jt)return null;const t=e-Jt,n=Math.floor(t/Jt),o=t%Jt;return{row:n===0?null:n-1,col:o===0?null:o-1}}function It(e){return e.tableCells??[["","",""],["","",""],["","",""]]}function xe(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]??Oo)}function bn(e){const t=It(e).length,n=e.tableRowHeights??[];return Array.from({length:t},(o,i)=>n[i]??0)}const No=e=>e.fontSize??14,Yo=e=>Bt("0",e,!1,!1);function ml(e){return Yo(e)+2*_t+2*dt}function Vo(e){return e+2*_t+dt}function bl(e,t){return Math.max(e-2*_t-2*dt,Yo(t))}function Uo(e,t,n){return e===""?[]:We(e,n,!1,!1,bl(t,n))}function gl(e,t){return e*t+(e-1)*t*(Fo-1)+2*_t+2*dt}function Xo(e,t=It(e),n=xe(e)){const o=No(e),i=bn(e),r=[];return{heights:i.map((s,a)=>{var f;let c=Vo(o);for(let h=0;h<n.length;h++)c=Math.max(c,gl(Uo(((f=t[a])==null?void 0:f[h])??"",n[h],o).length,o));return r.push(c),Math.max(s,c)}),mins:r}}function gn(e,t){const n=e.style,o=No(n),i=It(n),r=xe(n),{heights:l}=Xo(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)=>Uo(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 Go(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 wl(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 wn(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?wn(s,t,n):s}function Ml(e,t,n){var a;const o=It(e).map(c=>[...c]),i=xe(e),r=bn(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,Oo)}return{tableCells:o,tableColWidths:i,tableRowHeights:r}}function vl(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 kl(e,t,n){const o=It(e).map(c=>[...c]),i=xe(e),r=bn(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 Ll(e,t,n){const o=It(e).map(i=>[...i]);return o[t[0]]&&(o[t[0]][t[1]]=n),{tableCells:o}}const Sl=2e6,Mn=2e3,Cl={"image/png":"png","image/jpeg":"jpg","image/webp":"webp"},Pt=new Map;let jo=()=>Promise.reject(new Error("no image reader"));const vn=new Set;function Tl(e){jo=e}function qo(e){return vn.add(e),()=>vn.delete(e)}function Zo(){for(const e of vn)e()}function Ko(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 kn(e){if(!e)return null;const t=Pt.get(e);return t&&t!=="loading"&&t!=="error"?t:(t||(Pt.set(e,"loading"),jo(e).then(n=>Ko(URL.createObjectURL(n))).then(n=>Pt.set(e,n),n=>{Pt.set(e,"error"),console.warn("[image] read failed:",n)}).then(Zo)),null)}function Al(e){return!!e&&Pt.get(e)==="error"}function Qo(e,t){const n=e.image,o=kn(n==null?void 0:n.name);if(!n||!o||o.width>Mn||o.height>Mn)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 Jo(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 $l=[[-1,-1],[1,-1],[-1,1],[1,1]];function Bl(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 Il(e,t){(!Pt.has(e)||Pt.get(e)==="error")&&Pt.set(e,t),Zo()}const Pl="Add text",El={text:"Text",note:"Add text",pin:"Note",comment:"Comment","price-note":"Price note",signpost:"Signpost",callout:"Callout"};function zl(e){const t=!!(e.text&&e.text.length>0);return{txt:t?e.text:El[e.kind]??"Text",faint:!t}}function ti(e,t,n,o){const{txt:i,faint:r}=zl(e),l=t.fontSize??14,s=Bt(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 pt(e){return e.text?{text:e.text,faint:!1}:{text:Pl,faint:!0}}function ei(e,t){const n=e.style,o=n.fontSize??14,i=o/6;return j({x:t.x,y:t.y,text:pt(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 ni(e,t){const o=e.style.fontSize??16,i=Math.round(o/1.3),r=j({x:t.x,y:t.y,text:pt(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 Rl(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 Wl="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 oi(e,t,n){const o=e.style,i=o.fontSize??14,r=Math.min(236,n),l=We(pt(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 ii(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 ri(e,t,n){const o=Bt(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 Dl(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 li(e,t){const n=e.style,o=n.fontSize??14,i=n.wordWrap?n.wordWrapWidth??200:void 0,r=We(pt(e).text,o,!!n.bold,!!n.italic,i),l=i??Math.max(0,...r.map(u=>Bt(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 Ol(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=(g,w)=>`${o+g} ${i+w}`,m=(g,w)=>`A 8 8 0 0 1 ${y(g,w)}`;let b=`M ${y(8,0)}`;return d===10?b+=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)}`:b+=` L ${y(r-8,0)}`,b+=d===20?` L ${y(c,f)} L ${y(r,8)}`:` ${m(r,8)}`,d===21?b+=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)}`:b+=` L ${y(r,l-8)}`,b+=d===22?` L ${y(c,f)} L ${y(r-8,l)}`:` ${m(r-8,l)}`,d===12?b+=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)}`:b+=` L ${y(8,l)}`,b+=d===2?` L ${y(c,f)} L ${y(0,l-8)}`:` ${m(0,l-8)}`,d===1?b+=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)}`:b+=` L ${y(0,8)}`,b+=d===0?` L ${y(c,f)} L ${y(8,0)}`:` ${m(8,0)}`,b+" Z"}const Ht={pole:"#808080",labelBg:"#0f0f0f",labelBorder:"#2e2e2e",labelText:"#dbdbdb",plateBorder:"#0f0f0f"};function si(e,t){const n=e.barAt(t.time);return n?{high:n.high,low:n.low}:null}function ci(e,t,n){const o=si(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 Ln(e,t,n,o){const i=e.style,r=i.signpostPosition??50,l=r>=0?1:-1,s=si(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=v=>j({x:t.x,y:v,text:pt(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,m=l===1?Math.min(h-y,x):Math.max(h+y,x);m!==x&&(x=m,p=d(x));const b=i.showImage?80:0,g=x+(y+b)*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:g,plateY:w,gap:M,n:l,x:t.x}}function ai(e,t,n,o){const i=t.yToPrice(o);return i==null?null:ci(t,{time:e.points[0].time,price:i},n)}const lt=nt+L;function Nt(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)<=lt)return{hit:"handle",handleIndex:n};return null}function _l(e,t,n){const o=yt(e,t);for(let i=0;i<4;i++)if(Math.hypot(o[i].x-n.x,o[i].y-n.y)<=lt)return{hit:"handle",handleIndex:i};return null}function Hl(e,t,n,o=L){const i=e[0];return Math.hypot(.9*n-t.x,i.y-t.y)<=lt?{hit:"handle",handleIndex:0}:Math.abs(t.y-i.y)<=o?{hit:"body"}:null}function Nl(e,t,n,o=L){const i=e[0];return Math.hypot(i.x-t.x,.9*n-t.y)<=lt?{hit:"handle",handleIndex:0}:Math.abs(t.x-i.x)<=o?{hit:"body"}:null}function Yl(e,t,n=L){const o=e[0];return Math.hypot(o.x-t.x,o.y-t.y)<=lt?{hit:"handle",handleIndex:0}:Math.abs(t.y-o.y)<=n||Math.abs(t.x-o.x)<=n?{hit:"body"}:null}function fi(e,t,n=L){const o=e[0];return Math.hypot(o.x-t.x,o.y-t.y)<=lt?{hit:"handle",handleIndex:0}:t.x>=o.x-lt&&Math.abs(t.y-o.y)<=n?{hit:"body"}:null}function Vl(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 Ul(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 H(n.x,n.y,h,u)<=Ee(l)?{hit:"body"}:null}function hi(e,t,n=L){const o=W(e,t);return o||(H(t.x,t.y,e[0],e[1])<=n?{hit:"body"}:null)}function Xl(e,t,n,o){if(!e.points[0]||!e.points[1])return null;const i=yn(e,t,o);if(!i)return null;const{anchors:r,yStop:l,yTarget:s}=i,[a,c]=t,f=W(r,n);if(f)return f;const h=Math.min(a.x,c.x),u=Math.max(a.x,c.x),d=Math.min(s,l),x=Math.max(s,l);return n.x>=h-L&&n.x<=u+L&&n.y>=d-L&&n.y<=x+L?{hit:"body"}:null}function Fe(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 Sn(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=uo(e.kind,t);if(!l)return null;const s=e.style,a=x=>Qt(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??Lt).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(H(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(Sn(n,l.mid,p,l.half,-x,x,!!s.extendLines,!0))return{hit:"body"}}return null}function jl(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 ql(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??on).filter(f=>f.visible);for(const f of c){const h=ho(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(H(n.x,n.y,l,d)<=L)return{hit:"body"}}return null}function Zl(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??hn).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 H(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??xn).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 Ql(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,m=(y.levels??Ie).filter(g=>g.visible);if(m.length===0)return null;const b=(i+r)*2;for(const g of m){const w=f*g.coeff,[M,v]=Fe({x:l.x,y:l.y+w},{x:s.x,y:s.y+w},!!y.extendLeft,!!y.extendRight,b);if(H(n.x,n.y,M,v)<=o)return{hit:"body"}}return y.fillBackground!==!1&&Sn(n,l,s,{x:0,y:f},m[0].coeff,m[m.length-1].coeff,!!y.extendLeft,!!y.extendRight)?{hit:"body"}:null}function Jl(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[m,b]=Fe(p,y,!!d.extendLeft,!!d.extendRight,x);if(H(n.x,n.y,m,b)<=o)return{hit:"body"}}return null}function ts(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]=Fe(u,d,!!f.extendLeft,!!f.extendRight,h);if(H(n.x,n.y,x,p)<=o)return{hit:"body"}}return null}function es(e,t,n,o,i,r){const l=W(t,n);if(l)return l;const[s,a,c]=t;if(!c)return H(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??$t).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]=Fe({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(H(n.x,n.y,p,y)<=o)return{hit:"body"}}return f.fillBackground===!1?null:Sn(n,s,a,h,Math.min(...u),Math.max(...u),!!f.extendLeft,!!f.extendRight)?{hit:"body"}:null}function ns(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 ui(e,t){const[n,o,i,r]=yt(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 Cn(e,t,n=!1){const[o,i]=e,r=_l(o,i,t);if(r)return r;if(n){const f=ui(o,i);for(let h=0;h<4;h++)if(Math.hypot(f[h].x-t.x,f[h].y-t.y)<=lt)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 os(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 is(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 di(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 rs(e,t,n){const o=e.fmt===2,i=lo(t,o),r=o?[t[0],t[1],...i]:t,l=W(r,n);return l||(Kt(n.x,n.y,i)?{hit:"body"}:null)}function ls(e,t){const n=W(e,t);return n||(Kt(t.x,t.y,e)?{hit:"body"}:null)}function te(e,t,n=L){for(let o=1;o<e.length;o++)if(H(t.x,t.y,e[o-1],e[o])<=n)return{hit:"body"};return null}function ss(e,t,n,o,i=L){const r=W(t,n);if(r)return r;const l=Wo(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"}:H(n.x,n.y,s,a)<=i?{hit:"body"}:null}if(l.lineMode){for(let s=1;s<l.line.length;s++)if(H(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 cs(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=Do(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 as(e,t,n,o,i){const r=W(t,n);if(r)return r;const[l,s]=t,a=Eo(e,t,i,Ae),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=mn(l,d,o,c);if(H(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(H(n.x,n.y,d,x)<=L)return{hit:"body"};return null}function fs(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??Lt).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,m={x:r.x+x/y*f,y:r.y+p/y*f};if(H(n.x,n.y,r,m)<=L)return{hit:"body"}}return H(n.x,n.y,l,s)<=L?{hit:"body"}:null}function hs(e,t,n,o,i){const r=W(t,n);if(r)return r;const[l,s,a]=t;if(H(n.x,n.y,l,s)<=o)return{hit:"body"};if(a&&H(n.x,n.y,s,a)<=o)return{hit:"body"};const c=(e.style.levels??ln).filter(f=>f.visible);for(const f of xo(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 us(e,t,n){const o=W(t,n);if(o)return o;const i=ao(e,t);if(!i)return null;const r=fo(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 ds(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 xs(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(H(n.x,n.y,i,r)<=L)return{hit:"body"};if(H(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??rn).filter(y=>y.visible);for(const y of p)if(Math.abs(u-s*y.coeff)<=L)return{hit:"body"}}return null}function ys(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??dn).filter(f=>f.visible);for(const f of c)if(Math.abs(a-l*f.coeff)<=L)return{hit:"body"};return null}const ye=[0,1,2,3,5,8,13,21,34,55,89];function xi(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*(ye.length-1);for(let c=0;c<=a;c++){const f=c/50,h=Math.floor(f),u=Math.ceil(f);if(u>=ye.length)break;const d=Math.pow(f-h,1.15),x=(ye[h]+(ye[u]-ye[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 yi(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 Tn(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 pi(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),m=f*u*r*(Math.sin(p)-Math.sqrt(3)/2);d.push({x:e.x+l*y-s*m,y:e.y+s*y+l*m})}return d}function An(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 ps=new Set(["triangle-pattern"]);function ms(e,t,n){const o=W(t,n);if(o)return o;const i=Ee(e.style);for(let r=1;r<t.length;r++)if(H(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&&Kt(n.x,n.y,[t[0],t[1],t[2]])?{hit:"body"}:t.length>=5&&Kt(n.x,n.y,[t[2],t[3],t[4]])?{hit:"body"}:null;if(ps.has(e.kind)&&t.length>=3&&Kt(n.x,n.y,t))return{hit:"body"};if(e.kind==="polyline"&&e.closed===!0&&e.style.fillBackground!==!1&&t.length>=2){if(H(n.x,n.y,t[t.length-1],t[0])<=i)return{hit:"body"};if(t.length>=3&&Kt(n.x,n.y,t))return{hit:"body"}}return null}function bs(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)<=lt?{hit:"handle",handleIndex:0}:Math.hypot(e[o].x-t.x,e[o].y-t.y)<=lt?{hit:"handle",handleIndex:o}:te(e,t,n)}function pe(e,t,n,o=L){const i=W(t,n);return i||te(e,n,o)}function gs(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 H(t.x,t.y,r,l)<=o?{hit:"body"}:null}function ws(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 Ms(e,t,n,o){var s;const i=W(t,n);if(i)return i;if(t[1]&&H(n.x,n.y,t[0],t[1])<=L)return{hit:"body"};const r=(o==null?void 0:o.pipSize())??.01,l=(s=po(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 vs(e,t,n,o,i){const r=Mo(e,i,o),l=W(r?r.anchors:t,n);if(l)return l;if(!r)return hi(t,n);const s=[r.center,r.upper,r.lower];for(const a of s)if(a&&H(n.x,n.y,a[0],a[1])<=L)return{hit:"body"};return null}function ks(e,t,n,o){if(Math.hypot(t[0].x-n.x,t[0].y-n.y)<=lt)return{hit:"handle",handleIndex:0};const i=Co(e,o);if(i.line.length<2)return fi(t,n);const r=te(i.line,n);if(r)return r;for(const l of i.bands){if(l.upper.length>=2&&pn(e.style,l.index,"upper").visible&&te(l.upper,n))return{hit:"body"};if(l.lower.length>=2&&pn(e.style,l.index,"lower").visible&&te(l.lower,n))return{hit:"body"}}return null}function Ls(e,t,n=L){const o=W(e,t);return o||te(To(e[0],e[1]),t,n)}function Ss(e,t){const n=e[0];return Math.hypot(n.x-t.x,n.y-t.y)<=lt?{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 Cs(e,t,n,o){if(!e.ghost)return Cn(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(H(n.x,n.y,t[l-1],t[l])<=r)return{hit:"body"};return null}function mi(e,t,n,o,i,r,l=!1){var a;const s=Ee(e.style);switch(e.kind){case"horizontal-line":return Hl(t,n,o,s);case"horizontal-ray":return fi(t,n,s);case"vertical-line":return Nl(t,n,i,s);case"cross-line":return Yl(t,n,s);case"arrow-mark-up":case"arrow-mark-down":return cs(e,t,n,e.kind==="arrow-mark-up"?"up":"down");case"font-icon":return Hr(t,n);case"table":{const c=gn(e,t[0]),f=W(Go(c),n);if(f)return f;const h=wl(c,n,l);return h?"edge"in h?{hit:"handle",handleIndex:pl(h.edge)}:{hit:"body",cell:h.cell}:null}case"image":{const c=Qo(e,t[0]);if(!c)return null;const f=W(Jo(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=ri(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 Nt(n,{left:f.x,top:f.y,width:f.w,height:f.h})?{hit:"body"}:null}case"flag-mark":return Ss(t,n);case"trend-line":case"ray":case"extended-line":case"info-line":case"arrow":case"trend-angle":return Ul(e,t,n,o,i);case"arrow-marker":return hi(t,n,s);case"position-forecast":return Ls(t,n,s);case"long-position":case"short-position":return Xl(e,t,n,r);case"bar-pattern":return ss(e,t,n,r,s);case"ghost-feed":return Cs(e,t,n,r);case"gann-box":return Cn(t,n);case"gann-fan":return ql(e,t,n,o,i);case"fib-time-zone":return Zl(e,t,n,s);case"fib-circles":return Kl(e,t,n);case"fib-speed-resistance-fan":return as(e,t,n,o,r);case"pitchfan":return fs(e,t,n,o);case"fib-wedge":return xs(e,t,n);case"trend-based-fib-time":return hs(e,t,n,s,r);case"gann-square-fixed":case"gann-square":return us(e,t,n);case"sector":return ds(t,n);case"fib-speed-resistance-arcs":return ys(e,t,n);case"fib-spiral":return pe(xi(t[0],t[1],!!e.style.counterclockwise),t,n,s);case"sine-line":return pe(yi(t[0],t[1],o),t,n,s);case"time-cycles":return ws(t,n,o,s);case"cyclic-lines":return gs(t,n,o,s);case"curve":return pe(Tn(t,!!e.style.extendLeft,!!e.style.extendRight),t,n,s);case"arc":return pe((t.length===3?pi(t[0],t[1],t[2]):null)??[t[0],t[1]],t,n,s);case"double-curve":return pe(An(t,!!e.style.extendLeft,!!e.style.extendRight),t,n,s);case"text":{const c=ei(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 Nt(n,c.box)?{hit:"body"}:null}case"comment":{const c=W(t,n);return c||(Nt(n,ni(e,t[0]).l.box)?{hit:"body"}:null)}case"pin":{const c=W(t,n);if(c)return c;const f=oi(e,t[0],o),h=f.marker;return n.x>=h.left&&n.x<=h.right&&n.y>=h.top&&n.y<=h.bottom?{hit:"body"}:l&&Nt(n,{left:f.left,top:f.top,width:f.width,height:f.height})?{hit:"body"}:null}case"signpost":{if(!r)return null;const c=Ln(e,t[0],r,i);return Math.hypot(c.anchor.x-n.x,c.anchor.y-n.y)<=lt?{hit:"handle",handleIndex:0}:H(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"}:Nt(n,c.l.box)?{hit:"body"}:null}case"note":{const c=W(t,n);return c||(t[1]&&H(n.x,n.y,t[0],t[1])<=L?{hit:"body"}:t[1]&&Nt(n,ti(e,e.style,t[0],t[1]).box)?{hit:"body"}:null)}case"price-note":return Ms(e,t,n,r);case"callout":{const c=li(e,t[1]);return Math.hypot(t[0].x-n.x,t[0].y-n.y)<=lt?{hit:"handle",handleIndex:0}:l&&c.wrap!=null&&Math.hypot(t[1].x+c.wrap/2+10-n.x,t[1].y-n.y)<=lt?{hit:"handle",handleIndex:1}:Nt(n,{left:c.x,top:c.y,width:c.w,height:c.h})?{hit:"body"}:null}case"regression-trend":return vs(e,t,n,o,r);case"fixed-range-volume-profile":{const c=W(t,n);if(c)return c;const f=Po(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=Io(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 ks(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 ms(e,t,n);case"brush":case"highlighter":return bs(t,n,s);case"parallel-channel":return Ql(e,t,n,s,o,i);case"disjoint-channel":return Jl(e,t,n,s,o,i);case"flat-top-bottom":return ts(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 es(e,t,n,s,o,i);case"rotated-rectangle":return rs(e,t,n);case"trend-based-fib-extension":return jl(e,t,n);case"fib-retracement":return Vl(e,t,n);case"rectangle":{const c=(r==null?void 0:r.timeAxis().width)||o,f=Cn(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=mo(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 os(t,n);case"ellipse":return ns(t,n);case"price-range":return is(e,t,n,o);case"date-range":return di(t,n);case"date-and-price-range":return di(t,n);case"triangle":return ls(t,n)}}function Ts(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 St(e,t){if(t>=100)return e;const[n,o,i]=Ts(e);return`rgba(${n}, ${o}, ${i}, ${(t/100).toFixed(2)})`}function As(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 ee=(e,t)=>({...e,back:t,color:As(t)});function bi(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(ee({time:e.points[0].time},at(o.color).hex)),e.kind==="long-position"||e.kind==="short-position"){if(o.showPriceLabels!==!1){const l=yn(e,t,n);if(l){const s=e.points[0].price,a=e.kind==="long-position"?1:-1;i.push(ee({price:s},"#787b86"),ee({price:s+a*l.profit},"#089981"),ee({price:s-a*l.stop},"#f23645"))}}return{price:i,time:r}}if(e.kind==="anchored-vwap"){if(o.vwapPriceLabel!==!1){const l=sl(e,n);l!=null&&i.push(ee({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(ee({price:l.price},at(o.color).hex));return{price:i,time:r}}let $n=null,_e=null;function gi(){return $n||($n=document.createElement("canvas").getContext("2d")),$n}function ft(e,t){const n=gi();return n?(_e??(_e=getComputedStyle(document.body).fontFamily),n.font=`${t}px ${_e}`,n.measureText(e).width):e.length*t*.6}function $s(e,t){const n=gi();return n?(_e??(_e=getComputedStyle(document.body).fontFamily),n.font=`bold ${t}px ${_e}`,n.measureText(e).width):e.length*t*.65}function mt(e,t){const n=Math.abs(e).toFixed(t);return e<0?`−${n}`:n}function Bn(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 Bs(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 me(e){return e.length%2===1&&e[Math.floor(e.length/2)].trim()!==""}function wi(e,t,n,o,i,r,l,s,a,c,f){const h=Math.max(0,...n.map(g=>Bt(g,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),m=Math.sin(p),b=(g,w)=>({x:(g-e.x)*y-(w-e.y)*m+e.x,y:(g-e.x)*m+(w-e.y)*y+e.y});return[b(d,x),b(d+h,x),b(d+h,x+u),b(d,x+u)]}function X(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 Mi(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,m=i.fontSize??14,b=m/3,g=r??(c?b:0),w=l.split(`
|
|
5
|
-
`),M=Math.ceil(m),v=w.length*M+2*b,k=s==="bottom"?x.y-v:s==="top"?x.y:x.y-v/2,S=a==="left"?x.x+g:a==="right"?x.x-g:x.x,C=a==="left"?"start":a==="right"?"end":"middle";return{u:x,angle:y,fs:m,lines:w,lineH:M,top:k+b,x:S,anchor:C,vert:s,horz:a,padV:b,padH:g}}function He(e,t,n,o,i,r){const l=Mi(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 vi(e,t,n,o,i,r,l){const s=Mi(e,t,n,o,i,r);return!s||s.vert!=="middle"||!l&&!me(s.lines)?null:wi(s.u,s.angle,s.lines,s.fs,s.lineH,s.padV,s.padH,s.vert,s.horz,!!i.bold,!!i.italic)}const Yt={rectangle:[4,5,6,7],disjointChannel:[2],parallelChannel:[4,5],position:[1,2,3],single:[0]},Is=50,Ps={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 ki(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(mt(c,h)),o.showPercentPriceRange){const y=l.price!==0?`${mt(c/Math.abs(l.price)*100,2)}%`:"";y&&p.push(o.showPriceRange?`(${y})`:y)}x.push(p.join(" "))}o.showPipsPriceRange&&x.push(mt(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=_(l.time),y=_(s.time),m=p!=null&&y!=null?Bn(y-p):"";m&&(x+=o.showBarsRange?` (${m})`:m)}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 Li(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 Es(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:Li(e,t,0,0,n,o)}function Si(e,t,n,o,i,r,l){if(!i||n.length===0)return[];const s=o===3;if(s&&!Es(e,t,r,l))return[];const a=12,c=18,f=8,h=12;let d=Math.max(...n.map(k=>ft(k.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,m=t.y<e.y&&t.x<e.x||t.y>e.y&&t.x>e.x;let b=y.x+12,g=m?y.y-12-x:y.y+12;s&&(e.x!==t.x||e.y!==t.y)&&(b<0?b=0:b+d>r&&(b=r-d),g<0?g=0:g+x>l&&(g=l-x),Li(e,t,b,g,d,x)&&(g=m?p.y+12:p.y-12-x,b=Math.min(p.x,r)-d));const w=Math.floor(b),M=Math.floor(g),v=[{t:"rect",x:w,y:M,w:d,h:x,rx:4,ry:4,fill:"#464646",fillOpacity:230/255}];return n.forEach((k,S)=>{const C=M+h+S*(c+f);v.push({t:"path",d:Ps[k.icon],transform:`translate(${w+h}, ${C})`,fill:"#F9F9F9",fillRule:"evenodd"}),v.push({t:"text",x:w+h+c+h,y:C+c/2,text:k.text,size:a,fill:"#FFFFFF",baseline:"central"})}),[{t:"group",inert:!0,items:v}]}function Ne(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:Ne(e,t,n.width),fill:"none",stroke:n.color,strokeWidth:n.width,dash:R(n),join:"round",cap:(n.lineStyle??"solid")==="solid"?"round":"butt",inert:!0}]}function Ci(e){return{...e,horzLabelsAlign:e.horzLabelsAlign??"center",vertLabelsAlign:e.vertLabelsAlign??"bottom"}}function In(e,t,n){return vi(e,t,e,t,Ci(n),(n.fontSize??14)/3,!1)}function ne(e,t){return t&&t.length?{items:[{t:"clip",name:e,polys:[t]}],clip:e}:{items:[],clip:void 0}}function Pn(e,t,n,o,i,r,l,s,a){if(!e.points[0]||!e.points[1])return[];const c=ki(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(...He(t,n,t,n,Ci(o),(o.fontSize??14)/3)),u.push(...Si(t,n,c,f,h,i,r)),u}function zs(e,t,n){if(!n.text)return null;const o=n.horzLabelsAlign??"center";return j({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 Rs(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=j({...i,x:0}).box.width;return e.x+r+3>=t?j({...i,x:e.x+r+3}):j({...i,x:t,offsetX:3})}return j({...i,x:o==="center"?(e.x+t)/2:e.x})}function En(e,t){return e&&t==="middle"&&me(e.lines)?e.poly:null}const Ct=(e,t)=>({t:"hit",a:e,b:t,width:12}),Ti=e=>(e.lineStyle??"solid")==="solid"?"round":"butt";function Ws(e,t,n,o){const i=e[0],r=zs(i.y,n,o),l=ne("cut",En(r,o.vertLabelsAlign??"middle"));return[Ct({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:R(o),clip:l.clip},...r?[X(r,o.textColor??o.color,o.bold,o.italic)]:[],...t?[{t:"anchors",pts:[{x:.9*n,y:i.y}],squares:Yt.single}]:[]]}function Ds(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?j(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=ne("cut",s?c&&((h=o.text)!=null&&h.trim())?c.poly:null:En(c,r));return[Ct({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:R(o),clip:f.clip},...c?[X(c,o.textColor??o.color,o.bold,o.italic)]:[],...t?[{t:"anchors",pts:[{x:i.x,y:.9*n}],squares:Yt.single}]:[]]}function Os(e,t,n,o,i){const r=e[0],l=R(i);return[Ct({x:0,y:r.y},{x:n,y:r.y}),Ct({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 Ai(e,t,n,o,i,r,l,s){const[a,c]=t,f=ne("cut",In(a,c,r));return[Ct(a,c),...f.items,{t:"line",a,b:c,stroke:r.color,strokeWidth:r.width,dash:R(r),cap:Ti(r),clip:f.clip},...Pn(e,a,c,r,o,i,l,s,f.clip),...n?[{t:"anchors",pts:t}]:[]]}function Ye(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,m=(o+i)*2,b=l?{x:f.x-p*m,y:f.y-y*m}:f,g=s?{x:h.x+p*m,y:h.y+y*m}:h,w=ne("cut",In(f,h,r));return[Ct(f,h),...w.items,{t:"line",a:b,b:g,stroke:r.color,strokeWidth:r.width,dash:R(r),clip:w.clip},...Pn(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=Rs(i,n,o),l=ne("cut",En(r,o.vertLabelsAlign??"top"));return[Ct(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:R(o),clip:l.clip},...r?[X(r,o.textColor??o.color,o.bold,o.italic)]:[],...t?[{t:"anchors",pts:[i]}]:[]]}function _s(e,t,n,o,i,r,l,s){if(e.kind!=="info-line")return[];const[a,c]=t,f=ne("cut",In(a,c,r)),h=Math.hypot(c.x-a.x,c.y-a.y)||1,u=(o+i)*2,d=(c.x-a.x)/h,x=(c.y-a.y)/h,p=r.extendLeft?{x:a.x-d*u,y:a.y-x*u}:a,y=r.extendRight?{x:c.x+d*u,y:c.y+x*u}:c;return[Ct(a,c),...f.items,{t:"line",a:p,b:y,stroke:r.color,strokeWidth:r.width,dash:R(r),cap:"round",clip:f.clip},...Pn(e,a,c,r,o,i,l,s,f.clip),...n?[{t:"anchors",pts:t}]:[]]}function Hs(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=Is,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}`,m=r.fontSize??12,b=Math.hypot(f,h)||1,g=(o+i)*2,w=r.extendLeft?{x:a.x-f/b*g,y:a.y-h/b*g}:a,M=r.extendRight?{x:c.x+f/b*g,y:c.y+h/b*g}:c;return[Ct(a,c),{t:"line",a:w,b:M,stroke:r.color,strokeWidth:r.width,dash:R(r),cap:Ti(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+m/3,y:a.y,text:`${Math.round(u*100)/100}º`,size:m,anchor:"start",baseline:"central",weight:r.bold?700:400,fontStyle:r.italic?"italic":"normal",fill:r.color,inert:!0},...Si(a,c,ki(e,a,c,r,l,!1),r.statsPosition??2,s||!!r.showStats,o,i),...n?[{t:"anchors",pts:t}]:[]]}function Tt(e,t){return(e.levels??t).filter(n=>n.visible).slice().sort((n,o)=>n.coeff-o.coeff)}function K(e){return e.fillBackground===!1?0:Math.max(0,Math.min(1,(100-(e.transparency??80))/100))}function bt(e,t){return e.width??t.width}function gt(e,t){return e.style?R({...t,lineStyle:e.style}):R(t)}function Ve(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 Ns(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 Ys(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 Vs(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 Us(e,t,n,o,i){const[r,l]=e,{anchors:s,dy:a}=Ns(e),c=(n.levels??Ie).filter(b=>b.visible),f=(o+i)*2,h=b=>Ve({x:r.x,y:r.y+a*b},{x:l.x,y:l.y+a*b},!!n.extendLeft,!!n.extendRight,f),u=K(n),d=n.backgroundColor??n.color,x=Vs(r,l,a,c,n),p=vi(x.e,x.t,x.i,x.n,n,void 0,!0),y=p&&p.length?"cut":void 0,m=[];y&&m.push({t:"clip",name:y,polys:[p]}),c.slice(1).forEach((b,g)=>{const w=h(c[g].coeff),M=h(b.coeff);m.push({t:"polygon",pts:[w.l,w.r,M.r,M.l],fill:d,fillOpacity:u,stroke:"transparent"})});for(const b of c){const g=h(b.coeff);m.push({t:"hit",a:g.l,b:g.r,width:12}),m.push({t:"line",a:g.l,b:g.r,stroke:b.color,strokeWidth:bt(b,n),dash:gt(b,n),clip:y})}return m.push(...He(x.e,x.t,x.i,x.n,n)),t&&m.push({t:"anchors",pts:s,squares:Yt.parallelChannel}),m}function $i(e,t,n,o,i){const r=(s,a,c)=>j({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[X(r(e,t,n),l,i.priceLabelBold,i.priceLabelItalic),X(r(t,e,o),l,i.priceLabelBold,i.priceLabelItalic)]}function Bi(e,t,n,o,i,r,l,s,a,c,f){var g,w;const h=(a+c)*2,u=Ve(t,n,!!s.extendLeft,!!s.extendRight,h),d=Ve(o,i,!!s.extendLeft,!!s.extendRight,h),x=R(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)))),m=M=>M.toFixed(y),b=[];return s.fillBackground!==!1&&b.push({t:"polygon",pts:[u.l,u.r,d.r,d.l],fill:s.backgroundColor??s.color,fillOpacity:K(s),stroke:"transparent"}),b.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&&b.push(...Et(n,t,s),...Et(i,o,s)),s.rightEnd===1&&b.push(...Et(t,n,s),...Et(o,i,s)),s.showPrices&&(b.push(...$i(t,n,m(((g=e.points[0])==null?void 0:g.price)??0),m(((w=e.points[1])==null?void 0:w.price)??0),s)),b.push(...$i(i,o,m(r),m(l),s))),b}function Xs(e,t,n,o,i,r,l){var d,x;const[s,a]=t,{anchors:c,P:f,A:h}=Ys(t),u=((d=e.points[2])==null?void 0:d.price)??e.points[0].price;return[...Bi(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),...He(s,a,h,f,o),...n?[{t:"anchors",pts:c,squares:Yt.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[...Bi(e,s,a,f,h,u,u,o,i,r,l),...He(s,a,f,h,o),...n?[{t:"anchors",pts:t}]:[]]}function zn(e,t){return t?`${(100*e).toFixed(2)}%`:String(Math.round(e*1e4)/1e4)}function Ue(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"),j({x:t,y:e.y,text:e.text,fs:e.fs,vert:e.vert,horz:n,offsetX:4})}function zt(e){return e.toFixed(3).replace(/0+$/,"").replace(/\.$/,"")||"0"}const ct=(e,t)=>e?[{t:"anchors",pts:t}]:[],Rn=e=>Math.max(0,Math.min(8,Math.round(-Math.log10((e==null?void 0:e.pipSize())??.01))));function Wn(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 Vt(e,t,n,o=!1){const i=n.fibTrendLine??(o?zr:Er);return i.visible?[{t:"line",a:e,b:t,stroke:i.color,strokeWidth:i.width,dash:R({...n,lineStyle:i.style}),cap:i.style==="solid"?"round":"butt",inert:!0}]:[]}function Ii(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+=zn(t.coeff,!!s.fibLevelsAsPercents)),h&&(u+=` (${r.toFixed(l)})`);const d=Ue({...c,text:u,horz:s.horzLabelsAlign??"left",vert:s.vertLabelsAlign??"middle"}),x=s.showText!==!1&&t.text?Ue({...c,text:t.text,horz:s.horzTextAlign??"center",vert:s.vertTextAlign??"middle"}):null,p=Wn(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:bt(t,s),dash:gt(t,s),clip:p.clip},...d?[X(d,t.color)]:[],...x?[X(x,t.color)]:[]]}function Pi(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 js(e,t,n,o,i){const r=e.style;let l=null,s=0,a=0;if(e.kind==="fib-retracement"&&t.length>=2){const[p,y]=t,m=e.points[0].price,b=e.points[1].price;s=r.extendLeft?0:Math.min(p.x,y.x),a=r.extendRight?o:Math.max(p.x,y.x);const g=!!r.fibLevelsBasedOnLogScale&&!!(i!=null&&i.isLog())&&m>0&&b>0,w=v=>{const k=r.reverse?m:b,S=r.reverse?b:m;return g?Math.exp(Math.log(k)+v*(Math.log(S)-Math.log(k))):k+v*(S-k)},M=v=>r.reverse?p.y+(y.y-p.y)*v:y.y+(p.y-y.y)*v;l=v=>g?M(v):(i==null?void 0:i.priceToY(w(v)))??M(v)}else if(e.kind==="trend-based-fib-extension"&&t.length>=3&&e.points.length>=3){const[,p,y]=t,m=e.points[0].price,b=e.points[1].price,g=e.points[2].price,w=r.reverse?m-b:b-m,M=r.reverse?t[0].y-t[1].y:t[1].y-t[0].y;s=r.extendLeft?0:Math.min(p.x,y.x),a=r.extendRight?o:Math.max(p.x,y.x);const v=!!r.fibLevelsBasedOnLogScale&&!!(i!=null&&i.isLog())&&m>0&&b>0&&g>0,k=C=>{if(!v)return g+w*C;const I=r.reverse?Math.log(m)-Math.log(b):Math.log(b)-Math.log(m);return Math.exp(Math.log(g)+C*I)},S=C=>y.y+M*C;l=C=>v?S(C):(i==null?void 0:i.priceToY(k(C)))??S(C)}if(!l||n.x<s-L||n.x>a+L)return null;const c=r.levels??$t;let f=null;if(c.forEach((p,y)=>{if(!p.visible)return;const m=l(p.coeff),b=Math.abs(n.y-m);b<=6&&(!f||b<f.dist)&&(f={index:y,y:m,dist:b})}),!f)return null;const{index:h,y:u}=f,d=r.horzTextAlign??"center",x=d==="left"?s:d==="right"?a:(s+a)/2;return{index:h,y:u,left:s,right:a,textX:x}}function qs(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=Tt(i,$t),d=!!i.fibLevelsBasedOnLogScale&&!!(r!=null&&r.isLog())&&a>0&&c>0,x=b=>{const g=i.reverse?a:c,w=i.reverse?c:a;return d?Math.exp(Math.log(g)+b*(Math.log(w)-Math.log(g))):g+b*(w-g)},p=b=>i.reverse?l.y+(s.y-l.y)*b:s.y+(l.y-s.y)*b,y=b=>d?p(b):(r==null?void 0:r.priceToY(x(b)))??p(b),m=Rn(r);return[...Pi(u,y,f,h,K(i)),...u.flatMap((b,g)=>Ii(`l${g}`,b,y(b.coeff),f,h,x(b.coeff),m,i,o)),...Vt(l,s,i),...ct(n,t)]}function Zs(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=Tt(i,$t),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,m=M=>{if(!y)return f+h*M;const v=i.reverse?Math.log(a)-Math.log(c):Math.log(c)-Math.log(a);return Math.exp(Math.log(f)+M*v)},b=M=>s.y+u*M,g=M=>y?b(M):(r==null?void 0:r.priceToY(m(M)))??b(M),w=Rn(r);return[...Pi(d,g,x,p,K(i)),...d.flatMap((M,v)=>Ii(`l${v}`,M,g(M.coeff),x,p,m(M.coeff),w,i,o)),...Vt(t[0],t[1],i),...Vt(t[1],t[2],i),...ct(n,t)]}function Ks(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 v=d(M);return Ve(v.l,v.r,!!o.extendLeft,!!o.extendRight,u)},p=Tt(o,$t),y=K(o),m=Rn(i),b=(M,v)=>(i==null?void 0:i.yToPrice(v))??e.points[0].price+(e.points[2].price-e.points[0].price)*M,g=(M,v)=>{const k=o.showCoeffs!==!1,S=o.showPrices!==!1;if(!k&&!S)return null;let C="";k&&(C+=o.fibLevelsAsPercents?`${(100*M.coeff).toFixed(2)}%`:zt(M.coeff)),S&&(C+=` (${b(M.coeff,v.l.y).toFixed(m)})`);const I=o.horzLabelsAlign??"left",A=I==="left"?v.l:I==="right"?v.r:{x:(v.l.x+v.r.x)/2,y:(v.l.y+v.r.y)/2};return j({x:A.x,y:A.y,text:C,fs:o.labelFontSize??12,vert:o.vertLabelsAlign??"middle",horz:I==="left"?"right":I==="right"?"left":"center",offsetX:4})},w=[];return y>0&&p.slice(1).forEach((M,v)=>{const k=x(p[v].coeff),S=x(M.coeff);w.push({t:"polygon",pts:[k.l,k.r,S.r,S.l],fill:p[v].color,fillOpacity:y,stroke:"none",inert:!0})}),p.forEach((M,v)=>{const k=d(M.coeff),S=x(M.coeff),C=g(M,k),I=Wn(`l${v}`,[C?C.poly:null]);w.push({t:"hit",a:k.l,b:k.r,width:12},...I.items),w.push({t:"line",a:S.l,b:S.r,stroke:M.color,strokeWidth:bt(M,o),dash:gt(M,o),clip:I.clip}),C&&w.push(X(C,M.color))}),w.push(...ct(n,t)),w}function Ei(e,t,n,o,i,r,l){const s=Wn(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:bt(t,i),dash:gt(t,i),clip:s.clip},...r?[X(r,t.color)]:[]]}function Qs(e,t,n,o,i,r){const[l,s,a]=t,c=i.fibTrendLine??sn,f=R({...i,lineStyle:c.style,width:c.width}),h=xo(e,t,r,Tt(i,ln)),u=K(i),d=i.vertLabelsAlign??"bottom",x=i.horzLabelsAlign??"right",p=x==="left"?"right":x==="right"?"left":"center",y=(b,g)=>i.showLabels===!1?null:j({x:b,y:d==="top"?0:d==="middle"?.5*o:o,text:String(g),fs:12,vert:d,horz:p,offsetX:2}),m=[];return c.visible&&(m.push({t:"line",a:l,b:s,stroke:c.color,strokeWidth:c.width,dash:f}),a&&m.push({t:"line",a:s,b:a,stroke:c.color,strokeWidth:c.width,dash:f})),u>0&&h.slice(1).forEach((b,g)=>{const w=h[g].x;m.push({t:"rect",x:Math.min(w,b.x),y:0,w:Math.max(1,Math.abs(b.x-w)),h:o,fill:b.color,fillOpacity:u,stroke:"none",inert:!0})}),h.forEach((b,g)=>{const w=y(b.x,b.coeff);m.push(...Ei(`l${g}`,b,b.x,o,i,w,w&&x==="center"?w.poly:null))}),m.push(...ct(n,t)),m}function Js(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:j({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=Tt(o,hn),u=K(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,m=i.x+f*x.coeff;d.push({t:"rect",x:Math.min(y,m),y:0,w:Math.max(1,Math.abs(m-y)),h:n,fill:x.color,fillOpacity:u,stroke:"none",inert:!0})}),h.forEach((x,p)=>{const y=i.x+f*x.coeff,m=c(y,x.coeff);d.push(...Ei(`l${p}`,x,y,n,o,m,m&&l==="middle"&&me(m.lines)?m.poly:null))}),d.push(...ct(t,e)),d}const tc=[.236,.382,.5,.618,1];function ec(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=R(o);return[...tc.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??xn).filter(x=>x.visible),h=K(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?Ue({text:zn(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:bt(x,o),dash:gt(x,o)}),p&&d.push(X(p,x.color))}return d.push(...Vt(i,r,o),...ct(n,t)),d}function nc(e,t,n,o,i,r,l){const[s,a]=t,c=Eo(e,t,l,Ae),f=R(r),h=K(r),u=c.h.map(k=>({color:k.color,far:mn(s,{x:a.x,y:k.y},o,i)})),d=c.v.map(k=>({color:k.color,far:mn(s,{x:k.x,y:a.y},o,i)})),x=k=>k.slice(1).map((S,C)=>({color:S.color,pts:[s,S.far,k[C].far]})),{left:p,top:y,right:m,bottom:b}=c.box,g=r.fanGrid??to,w=R({...r,lineStyle:g.style,width:g.width}),M=(k,S,C,I,A,D,F)=>j({x:k,y:S,text:zt(C),fs:12,vert:I,horz:A,offsetX:D,offsetY:F}),v=[];if(h>0)for(const k of[...x(u),...x(d)])v.push({t:"polygon",pts:k.pts,fill:k.color,fillOpacity:h,stroke:"none",inert:!0});for(const k of c.h)g.visible&&v.push({t:"line",a:{x:p,y:k.y},b:{x:m,y:k.y},stroke:g.color,strokeWidth:g.width,dash:w,inert:!0}),r.showLeftLabels!==!1&&v.push(X(M(p,k.y,k.coeff,"middle","right",5,0),k.color)),r.showRightLabels!==!1&&v.push(X(M(m,k.y,k.coeff,"middle","left",5,0),k.color));for(const k of c.v)g.visible&&v.push({t:"line",a:{x:k.x,y},b:{x:k.x,y:b},stroke:g.color,strokeWidth:g.width,dash:w,inert:!0}),r.showTopLabels!==!1&&v.push(X(M(k.x,y,k.coeff,"bottom","center",0,5),k.color)),r.showBottomLabels!==!1&&v.push(X(M(k.x,b,k.coeff,"top","center",0,5),k.color));for(const k of[...u,...d])v.push({t:"hit",a:s,b:k.far,width:L*2}),v.push({t:"line",a:s,b:k.far,stroke:k.color,strokeWidth:r.width,dash:f,cap:"round"});return v.push(...ct(n,t)),v}function oc(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=R(n),a=Tt(n,dn),c=K(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,m=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:m,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:bt(d,n),dash:gt(d,n)??s}),n.showCoeffs!==!1){const p=Ue({text:zn(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(X(p,d.color))}}u.push(...Vt(o,i,n))}return u.push(...ct(t,e)),u}function ic(e,t,n,o,i){const[r,l]=e,s=xi(r,l,!!i.counterclockwise),a=R(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 rc(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=R(n),u=Tt(n,rn),d=K(n),x=24,p=m=>{const b=[];for(let g=0;g<=x;g++){const w=s+f*g/x;b.push({x:o.x+Math.cos(w)*m,y:o.y+Math.sin(w)*m})}return b},y=[{t:"hit",a:o,b:i,width:12},{t:"hit",a:o,b:c,width:12}];d>0&&u.slice(1).forEach((m,b)=>{const g=p(l*m.coeff),w=p(l*u[b].coeff).reverse();y.push({t:"polygon",pts:[...g,...w],fill:m.color,fillOpacity:d,stroke:"none",inert:!0})}),y.push(...Vt(o,i,n,!0),...Vt(o,c,n,!0));for(const m of u){const b=l*m.coeff,g=s+f/2;y.push({t:"polyline",pts:p(b),fill:"none",stroke:m.color,strokeWidth:bt(m,n),dash:gt(m,n)??h}),n.showCoeffs!==!1&&y.push({t:"text",x:o.x+Math.cos(g)*(b+8),y:o.y+Math.sin(g)*(b+8),text:zt(m.coeff),size:11,fill:m.color,anchor:"middle",inert:!0})}return y.push(...ct(t,e)),y}function lc(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=R(o),f=Tt(o,Lt),h=K(o),u=n*4,d=y=>{const m=y.x-i.x,b=y.y-i.y,g=Math.hypot(m,b)||1;return{x:i.x+m/g*u,y:i.y+b/g*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,lvl:y})),{t:s,color:o.color},...f.map(y=>({t:{x:s.x+a.x*y.coeff,y:s.y+a.y*y.coeff},color:y.color,lvl:y}))],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,m)=>p.push({t:"polygon",pts:[i,d(x[m].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.lvl?bt(y.lvl,o):o.width,dash:y.lvl?gt(y.lvl,o):c});return p.push(...ct(t,e)),p}const be=(e,t)=>e?[{t:"anchors",pts:t}]:[];function sc(e,t,n,o,i){var b;const r=ao(e,t);if(!r)return be(n,t);const l=o.gannLevels??cn,s=jr(r,l),a=qr(r,o.gannFans??an),c=Zr(r,o.gannArcs??fn),f=fo(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[g,w]=e.points,M=i.timeToBarIndex(g.time),v=i.timeToBarIndex(w.time);if(M==null||v==null)return[];const k=o.reverse?-1:1,S=(w.price-g.price)*k,C=(v-M)*k,I=Math.max(0,Math.min(8,Math.round(-Math.log10(i.pipSize())))),A=o.labelFontSize??12,D=(T,z,P,B,O,U)=>j({x:T,y:z,text:P,fs:A,bold:o.bold,italic:o.italic,horz:B,vert:O,offsetX:10,offsetY:U}),F=[D(r.start.x,r.end.y,mt(S,I),C>0?"right":"left",S>0?"bottom":"top",S>0?8:10),D(r.end.x,r.start.y,String(C),C>0?"left":"right",S>0?"top":"bottom",S>0?10:8)];return C!==0&&F.push(D(r.end.x,r.end.y,String(Number(Math.abs(S/C).toFixed(7))),C>0?"left":"right",S>0?"bottom":"top",S>0?8:10)),F})(),d=((b=l[l.length-1])==null?void 0:b.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 g of s)y.push({t:"line",a:{x:g.x,y:r.start.y},b:{x:g.x,y:r.end.y},stroke:g.color,strokeWidth:g.width,inert:!0}),y.push({t:"line",a:{x:r.start.x,y:g.y},b:{x:r.end.x,y:g.y},stroke:g.color,strokeWidth:g.width,inert:!0});for(const g of a)y.push({t:"line",a:g.from,b:g.to,stroke:g.color,strokeWidth:g.width,cap:"round",inert:!0});const m=[];for(const g of c){const w=Kr(r,g.r,g.prev);h>0&&m.push({t:"path",d:w.fill,fill:g.color,fillOpacity:h,stroke:"none"}),m.push({t:"path",d:w.stroke,fill:"none",stroke:g.color,strokeWidth:g.width})}y.push({t:"group",clip:"box",inert:!0,items:m});for(const g of u)y.push(X(g,d,o.bold,o.italic));return y.push(...be(n,t)),y}function cc(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??on).map((m,b)=>({...m,index:b+1})).filter(m=>m.visible),h=K(i),u=m=>m>1?{x:l.x,y:r.y+c/m}:{x:r.x+a*m,y:l.y},d=m=>{const b=ho(r,l,m),g=Math.hypot(b.x,b.y)||1;return{x:r.x+b.x/g*s,y:r.y+b.y/g*s}},x=[];f.forEach((m,b)=>{m.index<4&&b<f.length-1?x.push({from:m.coeff,to:f[b+1].coeff,color:m.color}):m.index>4&&b>0&&x.push({from:m.coeff,to:f[b-1].coeff,color:m.color})});const p=12/3,y=[{t:"hit",a:r,b:l,width:12}];for(const m of f)y.push({t:"hit",a:r,b:d(m.coeff),width:L*2});if(h>0)for(const m of x)y.push({t:"polygon",pts:[r,d(m.from),d(m.to)],fill:m.color,fillOpacity:h,stroke:"none",inert:!0});for(const m of f){const b=d(m.coeff),g=u(m.coeff);y.push({t:"line",a:r,b,stroke:m.color,strokeWidth:bt(m,i),dash:gt(m,i)}),i.showLabels!==!1&&y.push({t:"text",x:g.x+p,y:g.y,text:m.label??zt(m.coeff),size:12,fill:m.color,anchor:"start",baseline:"central",inert:!0})}return y.push(...be(t,e)),y}function ac(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=yt(r,l),u=o.levels??$e,d=o.vLevels??$e,x=R(o),[p,y]=e.points,m=!!o.reverse,b=T=>{const z=m?y.price:p.price,P=m?p.price-y.price:y.price-p.price;return(i==null?void 0:i.priceToY(z+T*P))??(m?l.y+T*(r.y-l.y):r.y+T*(l.y-r.y))},g=(i==null?void 0:i.timeToBarIndex(p.time))??null,w=(i==null?void 0:i.timeToBarIndex(y.time))??null,M=T=>{if(i&&g!=null&&w!=null){const z=m?w:g,P=m?g-w:w-g,B=i.barIndexToTime(Math.round(z+T*P)),O=B!=null?i.timeToX(B):null;if(O!=null)return O}return m?l.x+T*(r.x-l.x):r.x+T*(l.x-r.x)},v=u.filter(T=>T.visible).map(T=>({...T,y:b(T.coeff)})),k=d.filter(T=>T.visible).map(T=>({...T,x:M(T.coeff)})),S=o.fillBackground!==!1?Math.max(0,Math.min(1,(100-(o.transparency??80))/100)):0,C=o.fillVertBackground!==!1?Math.max(0,Math.min(1,(100-(o.vertTransparency??80))/100)):0,I=o.fans??{visible:!1,color:"#9C9C9C"},A=[];if(I.visible)for(let T=0;T<u.length;T++){const z=M(u[T].coeff);A.push([{x:s,y:f},{x:z,y:c}],[{x:a,y:f},{x:z,y:c}],[{x:s,y:c},{x:z,y:f}],[{x:a,y:c},{x:z,y:f}]);const P=d[T];if(!P)continue;const B=b(P.coeff);A.push([{x:s,y:f},{x:a,y:B}],[{x:a,y:f},{x:s,y:B}],[{x:s,y:c},{x:a,y:B}],[{x:a,y:c},{x:s,y:B}])}const D=(T,z,P,B,O,U,tt,Mt)=>X(j({x:T,y:z,text:P,fs:12,horz:O,vert:U,offsetX:tt,offsetY:Mt}),B),F=[{t:"rect",x:s,y:c,w:Math.max(1,a-s),h:Math.max(1,f-c),fill:"transparent"}];v.forEach((T,z)=>{z>0&&S>0&&F.push({t:"rect",x:s,y:Math.min(T.y,v[z-1].y),w:a-s,h:Math.abs(T.y-v[z-1].y),fill:T.color,fillOpacity:S,inert:!0}),F.push({t:"line",a:{x:s,y:T.y},b:{x:a,y:T.y},stroke:T.color,strokeWidth:o.width,dash:x}),o.showLeftLabels!==!1&&F.push(D(s,T.y,zt(T.coeff),T.color,"right","middle",5,0)),o.showRightLabels!==!1&&F.push(D(a,T.y,zt(T.coeff),T.color,"left","middle",5,0))}),k.forEach((T,z)=>{z>0&&C>0&&F.push({t:"rect",x:Math.min(T.x,k[z-1].x),y:c,w:Math.abs(T.x-k[z-1].x),h:f-c,fill:T.color,fillOpacity:C,inert:!0}),F.push({t:"line",a:{x:T.x,y:c},b:{x:T.x,y:f},stroke:T.color,strokeWidth:o.width,dash:x}),o.showTopLabels!==!1&&F.push(D(T.x,c,zt(T.coeff),T.color,"center","bottom",0,3)),o.showBottomLabels!==!1&&F.push(D(T.x,f,zt(T.coeff),T.color,"center","top",0,5))});for(const[T,z]of A)F.push({t:"line",a:T,b:z,stroke:I.color,strokeWidth:o.width,dash:x,inert:!0});return F.push(...be(n,h)),F}function fc(e,t,n,o,i){const r=uo(e,t);if(!r)return[];const l=Qt(r.pivot,r.dir,o),s=Math.hypot(r.dir.x,r.dir.y)||1,a=m=>i.extendLines?{x:m.x-r.dir.x/s*o*4,y:m.y-r.dir.y/s*o*4}:m,c=R(i),f=Tt(i,Lt),h=K(i),u=(m,b)=>({x:r.mid.x+r.half.x*m*b,y:r.mid.y+r.half.y*m*b}),d=[];let x=0;for(const m of f)d.push({from:x,to:m.coeff,color:m.color}),x=m.coeff;const p=[1,-1],y=[{t:"hit",a:r.pivot,b:l,width:L*2}];for(const m of p)for(const b of f){const g=u(b.coeff,m);y.push({t:"hit",a:g,b:Qt(g,r.dir,o),width:L*2})}if(h>0)for(const m of p)for(const b of d){const g=u(b.from,m),w=u(b.to,m);y.push({t:"polygon",pts:[a(g),Qt(g,r.dir,o),Qt(w,r.dir,o),a(w)],fill:b.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 m of p)for(const b of f)y.push({t:"line",a:a(u(b.coeff,m)),b:Qt(u(b.coeff,m),r.dir,o),stroke:b.color,strokeWidth:bt(b,i),dash:gt(b,i),cap:"round"});return y.push(...be(n,t)),y}const hc=.06;function Xe(e,t){const n=fe(e);return t&&n.fillOpacity>0?{fill:n.fill,fillOpacity:Math.min(1,n.fillOpacity+hc)}:n}function zi(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 uc(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 Dn=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 dc(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=Xe(i,r),d=mo(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:R(i)}];if(x!=null&&x.visible){const y=d&&(i.vertLabelsAlign??"middle")==="middle"&&me(d.lines)?d.poly:null,m=y&&y.length?"mid":void 0;m&&p.push({t:"clip",name:m,polys:[y]});const b=Math.floor((f+h)/2);p.push({t:"line",a:{x:a,y:b},b:{x:c,y:b},stroke:x.color,strokeWidth:x.width,dash:R({...i,lineStyle:x.style,width:x.width}),cap:"butt",clip:m,inert:!0})}return d&&p.push(X(d,i.textColor??i.color,i.bold,i.italic)),p.push(...ht(n,[...yt(l,s),...ui(l,s)],Yt.rectangle)),p}function xc(e,t,n,o){const i=e.fmt===2,r=lo(t,i),l=fe(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:R(o),join:"round"},...ht(n,s)]}function yc(e,t,n,o,i){const[r,l]=t,s=Math.hypot(l.x-r.x,l.y-r.y),a=Xe(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:R(o)},...zi(e,r.x,r.y,o),...ht(n,t)]}function pc(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=Xe(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:R(o)}]},...zi(e,a,c,o),...ht(n,t)]}function mc(e,t,n,o){const i=Xe(n,o);return[{t:"polygon",pts:e,fill:i.fill,fillOpacity:i.fillOpacity,stroke:n.color,strokeWidth:n.width,dash:R(n),join:"round"},...ht(t,e)]}function bc(e,t,n){const[o,i]=e,r=R(n),l=e.length===3?pi(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=Dn(l),a=fe(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 Ri(e,t,n,o,i,r){const l=[];if(n.fillBackground){const s=fe(n);l.push({t:"path",d:Dn(i)+" Z",fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"})}if(l.push({t:"path",d:Dn(o),fill:"none",stroke:n.color,strokeWidth:n.width,dash:R(n),cap:"round"}),l.push(...uc(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 gc(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=Tn(o,!!n.extendLeft,!!n.extendRight),a=n.extendLeft||n.extendRight?Tn(o):s;return Ri(e,t,n,s,a,[[i,r],[l,r]])}function wc(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=An(o,!!n.extendLeft,!!n.extendRight),c=n.extendLeft||n.extendRight?An(o):a;return Ri(e,t,n,a,c,[[i,r],[s,l]])}function Mc(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 vc(e,t,n,o,i){const[r,l]=e,s=l.x-r.x,a=R(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 kc(e,t,n,o){const i=yi(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:R(o)}),r.push(...ht(t,e)),r}function Lc(e,t,n,o){const[i,r]=e,l=Math.abs(r.x-i.x),s=l/2,a=R(o),c=fe(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 On={"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"]},Sc=new Set(["polyline"]),Cc=[{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}],Tc={"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"]},Wi=["0","i","ii","iii","iv","v"];function Ac(e,t){const n=Tc[e]??[];return e==="elliott-impulse"?t===1?Wi:t===3?Wi.map(o=>o.toUpperCase()):n:t%2===1?n.map(o=>o.toLowerCase()):n}function $c(e,t,n,o){const r=14-Math.max(0,Math.min(14,Math.round(o.elliottDegree??Rr))),l=Math.floor(r/3),s=["","brackets","circle"][r%3],a=Cc[l],c=Ac(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:R(o),join:"round",cap:"round"}),t.forEach((x,p)=>{if(p===0&&!n)return;const y=x.y+(u(p)===1?f:-f),m=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"?`(${m})`:m,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 Di(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 Ge(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 wt(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 Fn(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 oe(e,t,n,o,i,r){return[...Fn(e[t],e[n],r.bg,o),Ge((e[t].x+e[n].x)/2,(e[t].y+e[n].y)/2,0,i,r)]}const ie=e=>({bg:e.color,fg:e.textColor??"#ffffff",fontSize:e.fontSize??12,bold:e.bold,italic:e.italic});function Oi(e,t,n){const o=ie(n),i=[];return e.forEach((r,l)=>{t[l]&&i.push(Ge(r.x,r.y,Di(e,l)<0?-5:5,t[l],o))}),i}const ge=e=>({t:"polyline",pts:e,fill:"none",stroke:"transparent",strokeWidth:L*2});function Bc(e,t,n,o){const i=ie(o),r=e.points.map(s=>s.price),l=[ge(t),{t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:R(o),join:"round"}];return t.length>=3&&l.push(...oe(t,0,2,o.width,wt(r[0],r[1],r[2],3),i)),t.length>=4&&l.push(...oe(t,1,3,o.width,wt(r[1],r[2],r[3],3),i)),l.push(...Oi(t,On[e.kind],o)),n&&l.push({t:"anchors",pts:t}),l}function Ic(e,t,n,o){const i=e.kind==="cypher-pattern",r=ie(o),l=o.backgroundColor??o.color,s=o.fillBackground===!1?0:K(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(ge(t),{t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:R(o),join:"round"}),t.length>=3&&c.push(...oe(t,0,2,1,wt(a[0],a[1],a[2],3),r)),t.length>=4&&c.push(...oe(t,1,3,1,i?wt(a[1],a[0],a[3],3):wt(a[1],a[2],a[3],3),r)),t.length>=5){const f=i?wt(a[0],a[2],a[4],3):wt(a[0],a[1],a[4],3);c.push(...Fn(t[0],t[4],o.color,1),...Fn(t[2],t[4],o.color,1),Ge((t[2].x+t[4].x)/2,(t[2].y+t[4].y)/2,0,wt(a[2],a[3],a[4],3),r),Ge((t[0].x+t[4].x)/2,(t[0].y+t[4].y)/2,0,f,r))}return c.push(...Oi(t,On[e.kind],o)),n&&c.push({t:"anchors",pts:t}),c}function Pc(e,t,n,o){const i=ie(o),r=e.points.map(s=>s.price),l=[ge(t),{t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:R(o),join:"round"}];return t.length>=4&&l.push(...oe(t,1,3,o.width,wt(r[1],r[2],r[3],2),i)),t.length>=6&&l.push(...oe(t,3,5,o.width,wt(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=Bt(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 Ec(e,t,n){const[o,i,r,l]=e,s=ie(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=[ge(e)];return a&&c.push({t:"polygon",pts:a,fill:n.fillBackground===!1?"none":n.backgroundColor??n.color,fillOpacity:K({...n,transparency:n.transparency??85}),stroke:n.color,strokeWidth:n.width,dash:R({...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 Fi(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 zc(e,t,n){const o=K({...n,transparency:n.transparency??85}),i=n.backgroundColor??n.color,[r,l,s,a,c,f,h]=e,u=Fi(s,c,r,l),d=Fi(s,c,f,h),x=(b,g)=>({x:b.x+(g.x-b.x)*10,y:b.y+(g.y-b.y)*10}),p=ie(n),y=(b,g,w)=>({t:"polygon",pts:[b,g,w],fill:i,fillOpacity:o,stroke:"none",inert:!0}),m=[ge(e)];return n.fillBackground!==!1&&(m.push(y(s,a,c)),u&&m.push(y(u,l,s)),d&&m.push(y(c,f,d))),m.push({t:"line",a:u??x(c,s),b:d??x(s,c),stroke:n.color,strokeWidth:n.width,dash:R({...n,lineStyle:"dotted"}),inert:!0},{t:"polyline",pts:e,fill:"none",stroke:n.color,strokeWidth:n.width,dash:R(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&&m.push({t:"anchors",pts:e}),m}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 Wc(e,t,n,o){if(e.kind==="triangle-pattern"&&t.length>=4)return Ec(t,n,o);if(e.kind==="head-and-shoulders"&&t.length>=7)return zc(t,n,o);if(e.kind==="abcd-pattern"&&t.length>=2)return Bc(e,t,n,o);if((e.kind==="xabcd-pattern"||e.kind==="cypher-pattern")&&t.length>=2)return Ic(e,t,n,o);if(e.kind==="three-drives-pattern"&&t.length>=2)return Pc(e,t,n,o);if(e.kind.startsWith("elliott-"))return $c(e,t,n,o);const i=On[e.kind],r=Sc.has(e.kind)&&e.closed===!0,l=e.kind==="highlighter",s=e.kind==="brush"||l,a=o.width,c=s?Rc(t):t,f=s?void 0:R(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?K(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:K(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 m=Math.hypot(y.x-p.x,y.y-p.y),g=(o.lineStyle??"solid")==="solid"&&m>=1?{x:p.x+(y.x-p.x)*(m+o.width/2)/m,y:p.y+(y.y-p.y)*(m+o.width/2)/m}:y;return{t:"path",d:Ne(p,g,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+Di(t,x),text:i[x]??String(x+1),size:11,fill:o.color,anchor:"middle"})}),n&&u.push({t:"anchors",pts:h}),u}function Dc(e){return e<92?18:Math.min(Math.max(e*.25,18),106,e*.9)}function Oc(e,t,n){const[o,i]=e,r=Math.hypot(i.x-o.x,i.y-o.y),l=n.fontSize??16,s=(A,D,F)=>n.text?[{t:"text",x:A,y:D,text:n.text,anchor:F,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=Dc(h),m=h>=35?.1:0,b=[{x:0,y:0},{x:h-y+y*m,y:1.22*y/4},{x:h-y,y:1.22*y/2},{x:h,y:0}],g=(A,D)=>({x:a.x+u*A.x+x*A.y*D,y:a.y+d*A.x+p*A.y*D}),w=[...b.map(A=>g(A,1)),...b.slice(0,b.length-1).reverse().map(A=>g(A,-1))],M=Math.min(5,Math.max(2,Math.round(.02*h))),v=Math.atan2(c,f);let k=o.x,S=o.y,C="middle";v>-Math.PI/4&&v<Math.PI/4?S-=8:v>3*Math.PI/4||v<-3*Math.PI/4?S+=8+l:v<0?(k+=10,C="start",S+=l*.35):(k-=10,C="end",S+=l*.35);const I=[{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(k,S,C)];return t&&I.push({t:"anchors",pts:e}),I}function Fc(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=Do(e,r),s=o.fontSize??14,a=[{t:"path",d:Fc(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 Hi=22,je=17,_n=12,_c=5;function Hc(e,t,n){const o=e[0],i=o.y-Hi,r=o.x,l=[{x:r,y:i},{x:r+je,y:i},{x:r+je-_c,y:i+_n/2},{x:r+je,y:i+_n},{x:r,y:i+_n}],s=[{t:"rect",x:r-L,y:i-L,w:je+L*2,h:Hi+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 Nc(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=ri(a,r,c),h=100-(o.transparency??0),u=o.borderColor??o.color,d=[{t:"path",d:Dl(f),fill:St(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:St(at(u).hex,h),stroke:"#0f0f0f",strokeWidth:1}];return n&&d.push({t:"anchors",pts:[r]}),d}const Yc=28;function Vc(e,t,n){const[o]=t,i=e.style.fontSize??Yc,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 Uc="#089981",Xc="#f23645";function Gc(e,t){const n=[];for(const o of e){const i=o.up?Uc:Xc,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 jc(e,t,n,o,i){if(e.kind!=="bar-pattern")return[];const[r,l]=t,s=Wo(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=Ee(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 Ni(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 Yi=14;function qc(e,t,n,o,i){if(e.kind!=="ghost-feed")return[];if(e.ghost&&i&&e.points.length>=2){const v=e.ghost.amplitude,k=Math.max(0,Math.min(1,(o.variance??50)/100)),S=[];let C=8,I=!1;for(let A=0;A<e.points.length-1;A++){const D=i.timeToBarIndex(e.points[A].time),F=i.timeToBarIndex(e.points[A+1].time);if(D==null||F==null||D===F)continue;I=!0;const T=t[A].x<=t[A+1].x,z=i.priceToY(T?e.points[A].price:e.points[A+1].price),P=i.priceToY(T?e.points[A+1].price:e.points[A].price);if(z==null||P==null)continue;const B=Math.min(D,F),O=Math.abs(F-D)-(A===0?0:1),U=O>1?(P-z)/(O-1):0;for(let tt=0;tt<O;tt++){const Mt=i.barIndexToTime(B+tt),se=Mt==null?null:i.timeToX(Mt);if(se==null)continue;if(tt>0){const Se=i.barIndexToTime(B+tt-1),Ce=Se==null?null:i.timeToX(Se);Ce!=null&&(C=Math.abs(se-Ce)||C)}const At=i.yToPrice(z+tt*U);if(At==null)continue;const ce=Ni((e.ghost.seed^Math.imul(A,2654435769)^Math.imul(tt,2654435761))>>>0),ke=v*(1-2*ce())*k,vt=Math.max(1e-9,v*(1+(.5-ce())*k)),xt=ke-vt/2,Xt=xt+ce()*vt,Gt=xt+ce()*vt,Le=i.priceToY(At+Xt),Dt=i.priceToY(At+xt+vt),en=i.priceToY(At+xt),nn=i.priceToY(At+Gt);Le==null||Dt==null||en==null||nn==null||S.push({x:se,openY:Le,highY:Dt,lowY:en,closeY:nn,up:Gt>=Xt})}}if(I){const A=Math.floor(.3*C),D=o.ghostCandle??Wr,F=i.priceToY(e.points[0].price),T=i.priceToY(e.points[0].price+v),z=F!=null&&T!=null?Math.abs(T-F):10,P=[];for(const O of S)D.drawWick&&P.push({t:"line",a:{x:O.x,y:O.highY},b:{x:O.x,y:O.lowY},stroke:D.wickColor,strokeWidth:1}),P.push({t:"rect",x:Math.round(O.x)-A-.5,y:Math.min(O.openY,O.closeY),w:2*A+1,h:Math.max(1,Math.abs(O.closeY-O.openY)),fill:O.up?D.upColor:D.downColor,stroke:D.drawBorder?O.up?D.borderUpColor:D.borderDownColor:"none",strokeWidth:1});const B=[{t:"polyline",pts:t,fill:"none",stroke:"transparent",strokeWidth:Math.max(12,z*2)},{t:"polyline",pts:t,fill:"none",stroke:"#808080",strokeWidth:1,inert:!0},{t:"group",inert:!0,opacity:1-(o.transparency??50)/100,items:P}];return n&&B.push({t:"anchors",pts:t}),B}}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)^((_(e.points[0].time)??0)|0),x=Ni(d),p=h/Yi,y=Math.max(1,p*.6),m=u*.06,b=u*.12;let g=c+u/2;const w=[];for(let v=0;v<Yi;v++){const k=g,S=(x()-.5)*2*b;let C=k+S;C=Math.max(c+m,Math.min(f-m,C));const I=Math.min(k,C)-x()*m,A=Math.max(k,C)+x()*m;w.push({x:s+p*(v+.5),openY:k,highY:I,lowY:A,closeY:C,up:C<=k}),g=C}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:Gc(w,y)}];if(n)for(const v of yt(r,l))M.push({t:"circle",cx:v.x,cy:v.y,r:nt,fill:"#fff",stroke:o.color,strokeWidth:1.5,cursor:"nwse-resize"});return M}const Zc="#2e2e2e",Kc={dx:0,dy:1,blur:4,color:"rgba(0,0,0,0.4)"};function Qc(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 Hn(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 m="";if(x&&(m+=mt(h,d)),p){const b=c!==0?100*h/Math.abs(c):0;x&&(m+=" ("),m+=`${mt(Math.round(b*100)/100,2)}%`,x&&(m+=")")}y&&(x?m+=p?" ":", ":p&&(m+=", "),m+=mt(Math.round(h/u),0)),m&&l.push(m)}if(i){const c=r(t.showBarsRange),f=r(t.showDateTimeRange),h=r(t.showVolume);let u="";const d=_(s.time),x=_(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+=Bn(x-d)),u&&l.push(u),h&&n&&d!=null&&x!=null){const m=Oe(n.bars(),Math.min(d,x),Math.max(d,x));let b=0,g=!1;for(const w of m)w.volume!=null&&(b+=w.volume,g=!0);g&&l.push(`Vol ${Bs(b)}`)}}return l}function Jc(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=Qc(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??Zc,shadow:Kc}),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 Vi(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
|
|
7
|
-
`):[],ce=B!=null&&B<0?x:B!=null&&B>0?p:i.color,ke=Te=>{var Pr;const Ir=(Pr=((r==null?void 0:r.bars())??[])[Te])==null?void 0:Pr.time;return Ir!=null&&r?r.timeToX(Ir):null},vt=P&&r?r.priceToY(P.closePrice):null,xt=(P==null?void 0:P.entryIndex)!=null?ke(P.entryIndex):a.x,Xt=(P==null?void 0:P.closeIndex)!=null?ke(P.closeIndex):a.x,Gt=xt!=null&&Xt!=null&&vt!=null&&xt!==Xt?{x:Math.min(xt,Xt),y:Math.min(s.y,vt),w:Math.abs(Xt-xt),h:Math.abs(vt-s.y)}:null,Le=P?ke(P.closed?P.closeIndex:P.barIndex):null,Dt=(P==null?void 0:P.entryIndex)!=null&&xt!=null&&Le!=null&&vt!=null?{from:{x:xt,y:s.y},to:{x:Le,y:vt}}:null,en=n||!!i.showStats,nn=Math.max(0,ft(tt,i.fontSize??12),ft(Mt,i.fontSize??12),...At.map(Te=>ft(Te,i.fontSize??12)))+8,Se=h-f-nn-nt<=8,Ce=Se?nt+8:0,ff=Se?(M<w?1:-1)*(k>v?-1:1)*(.5*((i.fontSize??12)*2+2*(i.fontSize??12)/3)+nt+8):0,kt=[{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:g}];return Gt&&B!=null&&B<0&&kt.push({t:"rect",...Gt,fill:x,fillOpacity:1-(y/100)**3}),kt.push({t:"rect",x:f,y:Math.min(s.y,M),w:u,h:Math.abs(M-s.y),fill:b}),Gt&&B!=null&&B>0&&kt.push({t:"rect",...Gt,fill:p,fillOpacity:1-(m/100)**3}),Dt&&kt.push({t:"line",a:Dt.from,b:Dt.to,stroke:i.color,strokeWidth:1,dash:"6 4",inert:!0},{t:"path",d:Ne(Dt.from,Dt.to,1),fill:"none",stroke:i.color,strokeWidth:1,inert:!0}),kt.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:b,strokeWidth:i.width},{t:"line",a:{x:f,y:w},b:{x:h,y:w},stroke:g,strokeWidth:i.width}),en&&(tt&&kt.push(Un(d,M,M<s.y?"bottom":"top",Ce,[tt],p,i)),At.length>0&&kt.push(Un(d,s.y,"middle",ff,At,ce,i,"#ffffff")),Mt&&kt.push(Un(d,w,w>s.y?"top":"bottom",Ce,[Mt],x,i))),n&&kt.push({t:"anchors",pts:l.anchors,squares:Yt.position}),kt}const ya="#202020",qi=Ze.w;function Zi(e,t,n){const o=_(e);if(o==null)return"";const i=(n==null?void 0:n.timeInfo())??{timeZone:"UTC",intraday:!0},{date:r,time:l}=ua(o,i.timeZone);return i.intraday?`${r}${t}${l}`:r}function Ki(e){const t=u=>ft(u.text,u.size)+(u.clockThen?qi+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:ya}];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:Ze.href,x,y:d+1,w:Ze.w,h:Ze.h},{t:"text",x:x+qi+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=$s(h.text,14),p=r+Math.round((n-x)/2),y=h.icon,m=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:m,w:y.w,h:y.h})}return{t:"group",inert:!0,items:f}}function pa(e,t,n,o,i,r){if(e.kind!=="position-forecast")return[];const[l,s]=t,a=s.y<=l.y,c=To(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,m=[s,{x:p-d*(x/2),y:y+u*(x/2)},{x:p+d*(x/2),y:y-u*(x/2)}],b=e.points[1].price-e.points[0].price,g=e.points[0].price!==0?b/Math.abs(e.points[0].price)*100:0,w=_(e.points[0].time),M=_(e.points[1].time),v=w!=null&&M!=null?Bn(M-w):"",k=(r==null?void 0:r.pipSize())??.01,S=Math.max(0,Math.min(8,Math.round(-Math.log10(k)))),C=al(e,r),I=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:m,fill:i.color,stroke:i.color,strokeWidth:1,join:"round"},Ki({cx:l.x,y:l.y,below:a,paneW:o,height:32,rows:[{text:e.points[0].price.toFixed(S),size:12,dy:4},{text:Zi(e.points[0].time," ",r),size:10,dy:18}],bg:i.sourceBackColor??"#2962FF",stroke:i.sourceStrokeColor??"#2962FF",fg:i.sourceTextColor??"#ffffff",opacity:I}),Ki({cx:s.x,y:s.y,below:!a,paneW:o,height:38,rows:[{text:`${mt(b,S)} (${mt(Math.round(g*100)/100,2)}%)${v?` in ${v}`:""}`,size:14,dy:5},{text:e.points[1].price.toFixed(S),size:11,dy:22,clockThen:Zi(e.points[1].time," ",r)}],bg:i.targetBackColor??"#2962FF",stroke:i.targetStrokeColor??"#2962FF",fg:i.targetTextColor??"#ffffff",opacity:I,banner:C==="waiting"?void 0:{text:C==="success"?"SUCCESS":"FAILURE",icon:C==="success"?da:xa,bg:C==="success"?i.successBackground??"#4caf50":i.failureBackground??"#F23645",fg:C==="success"?i.successTextColor??"#ffffff":i.failureTextColor??"#ffffff",above:a}})];return n&&A.push({t:"anchors",pts:t}),A}const Qi={dx:0,dy:2,blur:4,color:"rgba(0,0,0,0.4)"},ma={dx:0,dy:1,blur:4,color:"rgba(0,0,0,0.4)"},we=e=>St(at(e).hex,50);function ba(e,t,n,o){const i=e.style,r=ei(e,t),l=pt(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?St(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(X(r,l?we(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 ga(e,t,n,o){const i=e.style,r=[{t:"path",d:Wl,transform:`translate(${t.x-12} ${t.y-30})`,fill:i.color,fillRule:"evenodd"}];if(!n)return r;const l=oi(e,t,o),s=pt(e).faint,a=i.textColor??"#dbdbdb",c=[];return i.fillBackground!==!1&&c.push({t:"path",d:ii(l,t.x),fill:St(at(i.backgroundColor??"#2e2e2e").hex,100-(i.transparency??0)),shadow:Qi}),i.drawBorder&&c.push({t:"path",d:ii(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?we(a):a,pre:!0,inert:!0})}),r.push({t:"group",items:c},{t:"anchors",pts:[t]}),r}function wa(e,t,n,o){const[i,r]=t;if(!r)return[];const{txt:l,faint:s,fs:a,box:c}=ti(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:Qi},{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 Ma(e,t,n,o){const[i]=t,{l:r,r:l}=ni(e,i),s=pt(e).faint,a=o.textColor??"#ffffff",c=r.box,f=[{t:"path",d:Rl(c.left,c.top,c.width,c.height,[l,l,l,2]),fill:St(at(o.backgroundColor??o.color).hex,100-(o.transparency??0)),stroke:o.borderColor??o.color,strokeWidth:2},X(r,s?we(a):a)];return n&&f.push({t:"anchors",pts:t}),f}function va(e,t,n,o,i){const r=n?Ln(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:Ht.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:Ht.pole,strokeWidth:1}),e.style.showImage&&l.push({t:"circle",cx:r.x,cy:r.plateY,r:35,fill:e.style.plateColor??"#2962ff",stroke:Ht.plateBorder,strokeWidth:1,shadow:ma},{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:Ht.labelBg,stroke:Ht.labelBorder,strokeWidth:1},X(r.l,pt(e).faint?we(Ht.labelText):Ht.labelText,e.style.bold,e.style.italic)),i&&l.push({t:"anchors",pts:[r.anchor],squares:Yt.single}),l}function ka(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=po(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",m=y==="left"?x:y==="right"?p:{x:(r.x+l.x)/2,y:(r.y+l.y)/2},b=Math.atan((p.y-x.y)/(p.x-x.x));return j({x:m.x,y:m.y,text:e.text,fs:o.fontSize??14,bold:o.bold,italic:o.italic,vert:o.vertLabelsAlign??"bottom",horz:y,angle:Number.isNaN(b)?0:b})})(),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(X(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},X(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 La(e,t,n,o){const[i,r]=t,l=li(e,r),s=pt(e).faint,a=o.textColor??"#ffffff",c=[{t:"path",d:Ol(l,i,r),fill:St(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?we(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 Sa(e,t,n,o){const i=gn(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],m=i.xs[p+1],b=i.ys[x],g=i.ys[x+1],w=dt,M=dl;c=[[y+w,b+w,m-y-w,M],[y+w,g-M,m-y-w,M],[y+w,b+w,M,g-b-w],[m-M,b+w,M,g-b-w]].map(([k,S,C,I])=>`M${k} ${S}h${C}v${I}h${-C}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,m)=>{var k;const b=o!=null&&o.editing&&o.cell&&o.cell[0]===p&&o.cell[1]===m?[]:((k=i.lines[p])==null?void 0:k[m])??[],g=i.xs[m],w=i.xs[m+1],M=h==="right"?w-dt-_t:h==="center"?g+(w-g)/2:g+dt+_t,v=i.ys[p]+dt+_t+i.fs/2+.05*i.fs;b.forEach((S,C)=>{u.push({t:"text",x:M,y:v+C*i.fs*Fo,text:S,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:xl,crisp:!0}),d.push({t:"group",inert:!0,items:u}),f&&d.push({t:"path",d:f,fill:yl,inert:!0}),n&&d.push({t:"anchors",pts:Go(i)}),d}function Ca(e,t,n){var r,l;const o=Qo(e,t);if(!o)return[];const i=[{t:"image",href:((l=kn((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:Jo(o)}),i}function Ke(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 Ws(t,l,o,c);case"vertical-line":return Ds(t,l,i,c);case"cross-line":return Os(t,l,o,i,c);case"trend-line":return c.extendLeft||c.extendRight?Ye(e,t,l,o,i,c,!!c.extendLeft,!!c.extendRight,r,a):Ai(e,t,l,o,i,c,r,a);case"horizontal-ray":return Fs(t,l,o,c);case"ray":return Ye(e,t,l,o,i,c,c.extendLeft??!1,c.extendRight??!0,r,a);case"extended-line":return Ye(e,t,l,o,i,c,c.extendLeft??!0,c.extendRight??!0,r,a);case"info-line":return _s(e,t,l,o,i,c,r,a);case"trend-angle":return Hs(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?Ye(e,t,l,o,i,f,!!f.extendLeft,!!f.extendRight,r,a):Ai(e,t,l,o,i,f,r,a)}case"long-position":return ji(e,t,l,"long",c,r);case"short-position":return ji(e,t,l,"short",c,r);case"position-forecast":return pa(e,t,l,o,c,r);case"parallel-channel":return Us(t,l,c,o,i);case"disjoint-channel":return Xs(e,t,l,c,o,i,r);case"flat-top-bottom":return Gs(e,t,l,c,o,i,r);case"fib-retracement":return qs(e,t,l,o,c,r);case"trend-based-fib-extension":return Zs(e,t,l,o,c,r);case"fib-channel":return Ks(e,t,l,c,r,o,i);case"trend-based-fib-time":return Qs(e,t,l,i,c,r);case"fib-time-zone":return Js(t,l,i,c);case"fib-circles":return ec(e,t,l,c);case"fib-speed-resistance-fan":return nc(e,t,l,o,i,c,r);case"fib-speed-resistance-arcs":return oc(t,l,c);case"fib-spiral":return ic(t,l,o,i,c);case"fib-wedge":return rc(t,l,c);case"pitchfan":return lc(t,l,o,c);case"pitchfork":case"schiff-pitchfork":case"modified-schiff-pitchfork":case"inside-pitchfork":return fc(e.kind,t,l,o,c);case"gann-fan":return cc(t,l,o,i,c);case"gann-box":return ac(e,t,l,c,r);case"gann-square-fixed":case"gann-square":return sc(e,t,l,c,r);case"rectangle":return dc(e,t,l,o,c,s);case"rotated-rectangle":return xc(e,t,l,c);case"circle":return yc(e,t,l,c,s);case"ellipse":return pc(e,t,l,c,s);case"triangle":return mc(t,l,c,s);case"arc":return bc(t,l,c);case"curve":return gc(t,l,c);case"double-curve":return wc(t,l,c);case"sector":return Mc(t,l,c);case"cyclic-lines":return vc(t,l,o,i,c);case"sine-line":return kc(t,l,o,c);case"time-cycles":return Lc(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 Wc(e,t,l,c);case"arrow-marker":return Oc(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 Nc(e,t,l,c,r);case"font-icon":return Vc(e,t,l);case"bar-pattern":return jc(e,t,l,c,r);case"ghost-feed":return qc(e,t,l,c,r);case"price-range":return oa(e,t,l,o,i,c,r);case"date-range":return ia(e,t,l,i,c,r);case"date-and-price-range":return ra(e,t,l,i,c,r);case"regression-trend":return la(e,t,l,o,c,r);case"anchored-vwap":return sa(e,t,l,o,c,r);case"fixed-range-volume-profile":return aa(e,t,l,r);case"anchored-volume-profile":return fa(e,t,l,r);case"text":return ba(e,t[0],n.textSelected??l,s);case"pin":return ga(e,t[0],l,o);case"note":return wa(e,t,l,c);case"comment":return Ma(e,t,l,c);case"price-note":return ka(e,t,l,c,r);case"signpost":return va(e,t[0],r,i,l);case"callout":return La(e,t,l,c);case"table":return Sa(e,t[0],l,n.tableUi??null);case"image":return Ca(e,t[0],l)}return[]}function Ji(e,t){return e.map(n=>({t:"group",inert:!0,items:[{t:"circle",cx:n.x,cy:n.y,r:nt+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 tr(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={...ot}),t.push(er(n)));return t}function er(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=Ie.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 Ta=3,nr=5,Aa=2,$a=50;function Me(e,t,n){return t.anchored?[{x:t.anchored.x*n.w,y:t.anchored.y*n.h}]:or(e,t.points)}function Xn(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=N(e,{x:s.x+o,y:s.y+i});if(!a)return null;l.push(a)}return V(t,l)}function J(e,t){const n=e.timeToX(t.time),o=e.priceToY(t.price);return n==null||o==null?null:{x:n,y:o}}function or(e,t){const n=[];for(const o of t){const i=J(e,o);if(!i)return null;n.push(i)}return n}function N(e,t){const n=e.xToTime(t.x),o=e.yToPrice(t.y);return n==null||o==null?null:{time:n,price:o}}function ir(e,t,n,o,i=!0){const r=t.barAt(e.time);if(!r)return null;const l=i?[r.open,r.high,r.low,r.close]:[];if(l.length===0)return null;const s=t.priceToY(e.price);let a=l[0],c=1/0;for(const f of l){const h=t.priceToY(f),u=s!=null&&h!=null?Math.abs(h-s):Math.abs(e.price-f);u<c&&(c=u,a=f)}return n==="weak"&&s!=null&&c>=$a?null:{time:e.time,price:a}}function V(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 rr(e,t){return Math.atan2(-(t.y-e.y),t.x-e.x)*180/Math.PI}const Ba=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 Ia(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,m=p!=null&&y!=null?Math.abs(y-p):0,b=m>0?Math.round(o/m):0,g=u+Math.max(3,Math.round(.15*b)),w=n.barIndexToTime(g)??r.time,M={...Ft(t),stopLevel:f,profitLevel:f};return{...e,points:[r,{time:w,price:r.price}],style:M}}function Pa(e,t,n){const o=e.points[1];if(!o)return e;const i=_(e.points[0].time),r=_(o.time);if(i==null||r==null)return e;const l=Oe(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 Ea(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 za(e,t){const n=e.points[0],o=e.points[e.points.length-1];if(!n||!o)return e;const i=J(t,n),r=J(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=>N(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 Ra(e,t){const n=J(t,e.points[0]),o=e.points[1]?J(t,e.points[1]):null;return!n||!o?e:{...e,style:{...e.style??Ft("trend-angle"),angle:rr(n,o)}}}function lr(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 Gn(e,t,n,o,i={}){let r=Qe(e,t);return r?((e==="long-position"||e==="short-position")&&n&&(r=Ia(r,e,n,o.w,o.h)),(e==="curve"||e==="double-curve")&&n&&(r=za(r,n)),e==="gann-square"&&n&&(r=lr(r,n)),e==="bar-pattern"&&n&&(r=Pa(r,n,Math.max(1,o.h))),e==="trend-angle"&&n&&(r=Ra(r,n)),e==="polyline"&&i.closed!==void 0&&(r={...r,closed:i.closed}),e==="ghost-feed"&&n&&(r=Ea(r,n)),e==="font-icon"&&(r={...r,glyph:i.glyph}),r):null}const sr=new Set(["trend-line","ray","extended-line","info-line","arrow","trend-angle","arrow-marker","circle","fib-circles","fib-speed-resistance-fan","price-note","note","rotated-rectangle"]),Wa=new Set(["parallel-channel","flat-top-bottom","disjoint-channel"]);function Je(e,t){const n=e.barIndexToTime(t),o=n==null?null:e.timeToX(n);return n==null||o==null?null:{i:t,time:n,x:o}}function tn(e,t){const n=e.xToTime(t),o=n==null?null:e.timeToBarIndex(n);return o==null?null:Je(e,o)}function re(e,t,n){const o=e.timeToX(n.time),i=e.timeToX(t.time),r=e.priceToY(n.price),l=e.priceToY(t.price);if(o==null||i==null||r==null||l==null)return t;const s=i-o,a=l-r,c=Math.round(Math.atan2(s,a)/Math.PI*4);if(Math.abs(c)===2)return{time:t.time,price:n.price};if(c===0||Math.abs(c)===4)return{time:n.time,price:t.price};const f=Math.hypot(s,a),h=s<0?-1:1,u=a<0?-1:1;let d=Math.max(Math.abs(a),Math.abs(s));d/=d*Math.SQRT2/f;const x=tn(e,o+d*h);if(!x)return t;const p=e.yToPrice(r+Math.abs(x.x-o)*u);return p==null?t:{time:x.time,price:p}}function cr(e,t,n){const o=J(e,t),i=J(e,n);if(!o||!i)return t;const r=o.x-i.x,l=o.y-i.y,s=Math.max(Math.abs(r),Math.abs(l)),a=tn(e,i.x+s*(r<0?-1:1));if(!a)return t;const c=e.yToPrice(i.y+Math.abs(a.x-i.x)*(l<0?-1:1));return c==null?t:{time:a.time,price:c}}const Wt=[4.5,9,11.25,18,22.5,36,45],jn=(()=>{const e=[],t=Wt.length-1;let n=1,o=0,i=0;for(;i<1e10;)i=Wt[o]*n,e.push(Math.round(i)),e.push(Math.ceil(-i)),o===t-1&&(n*=10),o=(o+1)%t;return e.sort((r,l)=>r-l)})();function ar(e,t,n){let o=t.time;const i=e.timeToBarIndex(t.time),r=e.timeToBarIndex(n.time);if(i!=null&&r!=null){const a=i-r;if(a!==0){let c=jn.length-2;for(;c>=0&&!(jn[c]<a);--c);c+=a>0?1:0,o=e.barIndexToTime(r+jn[c])??o}}let l=t.price;const s=Math.round(1e6*(t.price-n.price))/1e6;if(s!==0){const a=Wt[0],c=Wt[Wt.length-1];let f=1;const h=Math.abs(s);for(;h<a*f||c*f<h;)h<a*f?f*=.1:c*f<h&&(f*=10);let u=c*f;for(let d=Wt.length-2;d>=0&&!(Wt[d]*f<h);--d)u=Wt[d]*f;l=n.price+(s>=0?u:-u)}return{time:o,price:l}}function fr(e,t,n,o){const i=Math.atan2(n.y-t.y,n.x-t.x)+Math.PI/2,r=o??Math.hypot(n.x-t.x,n.y-t.y)/2;return N(e,{x:(t.x+n.x)/2+Math.cos(i)*r,y:(t.y+n.y)/2+Math.sin(i)*r})}function hr(e,t,n,o){const i=t.length;if(i===0)return{point:n};if(sr.has(e))return{point:re(o,n,t[i-1])};if(Wa.has(e))return{point:i===1?re(o,n,t[0]):n};if(e==="rectangle")return{point:i===1?cr(o,n,t[0]):n};if(e==="gann-box")return{point:ar(o,n,t[0])};if(e==="ellipse"&&i===1){const r=re(o,n,t[0]),l=J(o,t[0]),s=J(o,r),a=l&&s?fr(o,l,s):null;return a?{point:r,extra:a}:{point:r}}return{point:n}}function qn(e,t){const n=Math.abs(e),o=Math.abs(t);return n<10&&o<10?{dx:e,dy:t}:n<o?{dx:0,dy:t}:{dx:e,dy:0}}function ur(e,t,n){return t&&J(e,t)||n}function Da(e,t,n){const o=e.start;if(e.mode.hit!=="handle")return{cursor:t};const i=e.mode.handleIndex,r=o.points,l=e.startScreen,s=f=>N(n,f),a=(f,h=re)=>{const u=s(t);return f?{cursor:u?ur(n,h(n,u,f),t):t}:{cursor:t}},c=(f,h)=>{if(!h)return{cursor:t};const u={x:f.x+t.x-e.startCursor.x,y:f.y+t.y-e.startCursor.y},d=s(u);if(!d)return{cursor:t};const x=ur(n,re(n,d,h),u);return{cursor:{x:e.startCursor.x+x.x-f.x,y:e.startCursor.y+x.y-f.y}}};switch(o.kind){case"circle":{if(i===1)return a(r[0]);if(i===0&&l[0]){const f=qn(t.x-l[0].x,t.y-l[0].y);return{cursor:{x:l[0].x+f.dx,y:l[0].y+f.dy}}}return{cursor:t}}case"rotated-rectangle":return a(i===0?r[1]:r[i===1?0:1]);case"parallel-channel":{const[f,h,u]=l;if(!f||!h||!u)return{cursor:t};const d={x:h.x+u.x-f.x,y:h.y+u.y-f.y},x=s(d);return i===0?c(f,r[1]):i===1?c(h,r[0]):i===2&&x?c(u,x):i===3?c(d,r[2]):{cursor:t}}case"flat-top-bottom":case"disjoint-channel":return i===1?a(r[0]):{cursor:t};case"ellipse":return{cursor:t,drawing:i<=1?dr(e,t,n,!0):void 0};case"rectangle":{if(l.length!==2)return{cursor:t};const f=yt(l[0],l[1]);if(i<4){const h=s(f[(i+2)%4]);return h?a(h,cr):{cursor:t}}return{cursor:t,drawing:Fa(e,t,n)}}case"gann-box":{if(l.length!==2||i>=4)return{cursor:t};const f=s(yt(l[0],l[1])[(i+2)%4]);return f?a(f,ar):{cursor:t}}case"gann-square":return{cursor:t,drawing:i<=1?Oa(e,t,n):void 0}}return sr.has(o.kind)&&i<=1&&r.length>=2?a(r[i===0?1:0]):{cursor:t}}function dr(e,t,n,o,i=r=>r){const r=e.start;if(r.kind!=="ellipse"||e.mode.hit!=="handle")return null;const l=e.mode.handleIndex,[s,a,c]=e.startScreen;if(!s||!a||!c||l>1)return null;const f=N(n,t);if(!f)return null;const h=r.points[l===0?1:0],u=o?re(n,f,h):i(f),d=[...r.points];d[l]=u;const x=J(n,d[0]),p=J(n,d[1]);if(!x||!p)return null;const y=a.x-s.x,m=a.y-s.y,b=Math.hypot(y,m)||1,g=Math.abs(((c.x-s.x)*m-(c.y-s.y)*y)/b),w=fr(n,x,p,o?void 0:g);if(!w)return null;if(d[2]=w,o&&n.timeToBarIndex(d[0].time)===n.timeToBarIndex(d[1].time)){const M=d[l],v=d[l===0?1:0],k=J(n,M),S=J(n,v),C=n.timeToX(M.time),I=n.timeToX(w.time);if(k&&S&&C!=null&&I!=null){const A=2*Math.abs(C-I)*(v.price>M.price?1:-1),D=n.yToPrice(S.y+A);D!=null&&(d[l]={time:M.time,price:D})}}return V(r,d)}function Oa(e,t,n){const o=e.start;if(e.mode.hit!=="handle")return null;const i=e.mode.handleIndex,[r,l]=o.points,s=n.timeToBarIndex(r.time),a=n.timeToBarIndex(l.time),c=N(n,t);if(!c||s==null||a==null||s===a)return null;const f=Math.abs(l.price-r.price)/Math.abs(a-s),h=i===0?l:r,u=n.timeToBarIndex(c.time),d=n.timeToBarIndex(h.time);if(u==null||d==null)return null;const x=[...o.points];return x[i]={time:c.time,price:h.price+(c.price-h.price>0?1:-1)*Math.abs(u-d)*f},V(o,x)}function Fa(e,t,n){const o=e.start;if(e.mode.hit!=="handle")return null;const[i,,r]=yt(e.startScreen[0],e.startScreen[1]);let{x:l,y:s}=i,{x:a,y:c}=r;const f=e.mode.handleIndex;if(f===5||f===7){const d=f===5?t.x-a:l-t.x;f===5?a+=d:l-=d,s-=d/2,c+=d/2}else{const d=f===4?s-t.y:t.y-c,x=tn(n,l),p=tn(n,a);if(!x||!p)return null;const y=Je(n,p.i+1),m=y?y.x-p.x:0;if(m<=0)return null;const b=Math.round(d/m),g=Je(n,x.i-b),w=Je(n,p.i+b);if(!g||!w)return null;const M=w.x-p.x;l=g.x,a=w.x,f===4?s-=M:c+=M}const h=N(n,{x:l,y:s}),u=N(n,{x:a,y:c});return!h||!u?null:V(o,[h,u])}function _a(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}=co(i,a);if(r===0){const d=N(n,t);if(!d)return null;const x=o(d);return V(i,[x,{time:s.time,price:x.price}])}if(r===1){const d=n.xToTime(t.x);return d==null?null:V(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 Ha(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=>N(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:V(o,[u,h[1],d])}if(s===1||s===3){const u=f({x:r.x+a,y:r.y+c});return u?V(o,[h[0],u,h[2]]):null}if(s===4){const u=f({x:l.x,y:l.y+c});return u?V(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:V(o,[u,d,x])}return null}function Na(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=N(n,t);if(!a)return null;const c=l.slice();return c[r]=o(a),V(i,c)}const s=n.yToPrice(t.y);if(s==null)return null;if(r===2)return V(i,[l[0],l[1],{time:l[2].time,price:s}]);if(r===3){const a=l[2].price+l[1].price-s;return V(i,[{time:l[0].time,price:a},l[1],l[2]])}return null}function Ya(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=N(n,t);if(!l)return null;const s=i.points.slice();if(r>=2)return s[2]=l,V(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?J(n,p):a,m=r===1?J(n,p):c;if(!y||!m)return null;const b=Math.hypot(m.x-y.x,m.y-y.y)||1,g=N(n,{x:y.x+(m.y-y.y)/b*x,y:y.y-(m.x-y.x)/b*x});return g?(s[2]=g,V(i,s)):null}function xr(e,t,n,o,i=!1){var f,h;const r=Pe(e.start.kind);if(i&&e.mode.hit==="handle"){const u=Da(e,t,n);if(u.drawing!==void 0)return u.drawing;t=u.cursor}if(i&&e.mode.hit==="body"){const u=qn(t.x-e.startCursor.x,t.y-e.startCursor.y);t={x:e.startCursor.x+u.dx,y:e.startCursor.y+u.dy}}if(e.mode.hit==="handle")switch(e.start.kind){case"long-position":case"short-position":return _a(e,t,n,o);case"parallel-channel":return Ha(e,t,n);case"table":return Va(e,t,n);case"signpost":{const u=((f=e.pane)==null?void 0:f.h)??0,d=ai(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=N(n,{x:x+p/2+10,y:e.startScreen[1].y});return y?{...V(e.start,[e.start.points[0],y]),style:{...u,wordWrapWidth:p}}:null}case"image":return Ua(e,t,n);case"pin":if(e.start.anchored)return Xn(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)<nr){const p=N(n,t);if(!p)return null;const y=e.start.points.slice();return y[u]=o(p),{...V(e.start,y),closed:!0}}}break}case"disjoint-channel":return Na(e,t,n,o);case"ellipse":if(e.mode.handleIndex<=1)return dr(e,t,n,!1,o);break;case"rotated-rectangle":if(e.start.fmt===2)return Ya(e,t,n,o);break;case"horizontal-line":{const u=N(n,t);return u?V(e.start,[{time:e.start.points[0].time,price:o(u).price}]):null}case"vertical-line":{const u=N(n,t);return u?V(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=N(n,{x:e.startScreen[0].x+u,y:e.startScreen[0].y}),p=((h=e.pane)==null?void 0:h.h)??0,y=Ln(e.start,e.startScreen[0],n,p);if(!x)return null;const m=V(e.start,[{time:x.time,price:e.start.points[0].price}]),b=ai(m,n,p,y.anchor.y+d);return b==null?m:{...m,style:{...m.style,signpostPosition:b}}}if(e.mode.hit==="body")return Xn(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]=yt(e.startScreen[0],e.startScreen[1]);let{x,y:p}=u,{x:y,y:m}=d;switch(e.mode.handleIndex){case 4:p=t.y;break;case 5:y=t.x;break;case 6:m=t.y;break;case 7:x=t.x;break}const b=N(n,{x,y:p}),g=N(n,{x:y,y:m});return!b||!g?null:V(e.start,[b,g])}if(r!=null&&r.isBbox&&e.startScreen.length===2&&e.mode.handleIndex<4){const d=yt(e.startScreen[0],e.startScreen[1])[(e.mode.handleIndex+2)%4],x=N(n,t),p=N(n,d);return!x||!p?null:V(e.start,[o(x),p])}const l=N(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=V(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:rr(u,d)}}}return c}function yr(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 Va(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=xe(i),{heights:c,mins:f}=Xo(i),h=ml(s),u=a.map(()=>h),d=B=>B.reduce((O,U)=>O+U,0),x=d(a),p=d(c),y=Ho(r);if(y){const B={};if(y.col!=null){const O=l.x+d(a.slice(0,y.col));B.tableColWidths=a.map((U,tt)=>tt===y.col?Math.max(h,t.x-O):U)}if(y.row!=null){const O=l.y+d(c.slice(0,y.row));B.tableRowHeights=c.map((U,tt)=>tt===y.row?Math.max(f[tt],t.y-O):U)}return{...o,style:{...i,...B}}}if(r>3)return null;const m=r===0||r===1,b=r===0||r===2,g={x:l.x+(m?0:x),y:l.y+(b?0:p)},w={x:g.x+(m?x:-x),y:g.y+(b?p:-p)},M=h*a.length,v=d(f);let k=m?Math.min(t.x,w.x-M):Math.max(t.x,w.x+M);const S=b?Math.min(t.y,w.y-v):Math.max(t.y,w.y+v);let C=o.points[0].time;const I=o.anchored&&e.pane&&e.pane.w>0&&e.pane.h>0?e.pane:null;if(m&&!I){const B=yr(n,k),O=B==null?null:n.timeToX(B);if(B==null||O==null)return null;C=B,k=O}let A=o.points[0].price;if(b&&!I){const B=n.yToPrice(S);if(B==null)return null;A=B}const D=g.x-k,F=g.y-S,T=wn(a,u,m?x+D:x-D);m&&(T[T.length-1]+=Math.round(l.x+x)-k-d(T));const z=wn(c,f,b?p+F:p-F),P=Vo(s);if(I){const B=m?k:l.x,O=b?S:l.y;return{...o,anchored:{x:B/I.w,y:O/I.h},style:{...i,tableColWidths:T.map(U=>Math.max(U,h)),tableRowHeights:z.map(U=>Math.max(U,P))}}}return{...o,points:[{time:C,price:A}],style:{...i,tableColWidths:T.map(B=>Math.max(B,h)),tableRowHeights:z.map(B=>Math.max(B,P))}}}function Ua(e,t,n){const o=e.start,i=o.image,r=kn(i==null?void 0:i.name);if(!i||!r||e.mode.hit!=="handle"||e.mode.handleIndex>3)return null;const[l,s]=$l[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=N(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 pr(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 mr=new Set(["text","pin","table"]);function br(e){return mr.has(e)}function gr(e,t,n){if(!br(e.kind)||n.w<=0||n.h<=0)return null;if(!e.anchored){const c=J(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=yr(t,o),l=t.yToPrice(i);if(r==null||l==null)return null;const{anchored:s,...a}=e;return V(a,[{time:r,price:l}])}const Xa=1;function wr(e,t,n,o=()=>[],i=()=>({timeZone:"UTC",intraday:!0}),r=()=>null){return{priceToY:l=>t.priceToCoordinate(l),yToPrice:l=>t.coordinateToPrice(l),isLog:()=>t.priceScale().options().mode===Xa,timeToX:l=>{const s=e.timeScale().timeToCoordinate(l);if(s!=null)return s;const a=n();if(a.length===0)return null;const c=Q(l);if(c==null)return null;const f=vr(a,c,r())??Mr(a,c);return f==null?null:kr(e,f)},xToTime:l=>{const s=e.timeScale().coordinateToTime(l);if(s!=null)return s;const a=n();if(a.length===0)return null;const c=e.timeScale().coordinateToLogical(l),f=Q(a[a.length-1].time);if(c==null||f==null)return null;const h=r();if(h&&c>a.length-1){const d=Math.round(c-(a.length-1));if(d<=0)return a[a.length-1].time;const x=h.time(d,f);if(x!=null)return x}const u=ve(a);return u<=0?null:Math.round(f+(c-(a.length-1))*u)},barAt:l=>ja(n(),l),timeToBarIndex:l=>{const s=n();if(s.length===0)return null;const a=Q(l);if(a==null)return null;const c=s.length-1,f=Q(s[c].time),h=Q(s[0].time),u=f!=null&&a>f?r():null;if(u&&f!=null)return c+u.slots(a,f);const d=ve(s);if(f!=null&&a>f)return Math.round(c+(a-f)/d);if(h!=null&&a<h)return Math.round((a-h)/d);let x=0,p=1/0;for(let y=0;y<s.length;y++){const m=Q(s[y].time);if(m==null)continue;const b=Math.abs(m-a);b<p&&(p=b,x=y)}return x},barIndexToTime:l=>{const s=n();if(s.length===0)return null;if(l>=0&&l<s.length)return s[l].time;const a=s.length-1,c=Q(s[a].time);if(c==null)return null;const f=l>a?r():null,h=f?f.time(l-a,c):null;if(h!=null)return h;const u=ve(s);return Math.round(c+(l-a)*u)},bars:n,visibleTimeRange:()=>{const l=e.timeScale().getVisibleRange();if(!l)return null;const s=Q(l.from),a=Q(l.to);return s==null||a==null?null:{from:s,to:a}},indicatorValuesAt:l=>o(Q(l)),pipSize:()=>{const l=t.options().priceFormat;return l&&typeof l.minMove=="number"&&l.minMove>0?l.minMove:.01},addPriceLine:l=>t.createPriceLine(l),removePriceLine:l=>t.removePriceLine(l),zoomToScreenRect:(l,s,a,c)=>{const f=e.timeScale(),h=f.coordinateToLogical(Math.min(l,s)),u=f.coordinateToLogical(Math.max(l,s));h!=null&&u!=null&&u>h&&f.setVisibleLogicalRange({from:h,to:u});const d=t.coordinateToPrice(a),x=t.coordinateToPrice(c);if(d!=null&&x!=null){const p=Math.min(d,x),y=Math.max(d,x);if(y>p){const m=t.priceScale();m.setAutoScale(!1),m.setVisibleRange({from:p,to:y})}}},formatTime:l=>{const s=e.options().localization.timeFormatter;if(s)return s(l);const a=Q(l);if(a==null)return String(l);const c=e.options(),f=new Date(a*1e3),h=new Intl.DateTimeFormat(c.localization.locale,{month:"short",timeZone:"UTC"}).format(f),u=`${f.getUTCDate()} ${h} '${String(f.getUTCFullYear()%100).padStart(2,"0")}`;if(!c.timeScale.timeVisible)return u;const d=p=>String(p).padStart(2,"0"),x=`${d(f.getUTCHours())}:${d(f.getUTCMinutes())}${c.timeScale.secondsVisible?`:${d(f.getUTCSeconds())}`:""}`;return`${u} ${x}`},timeInfo:()=>i(),timeAxis:()=>{const l=e.options().layout;return{height:e.timeScale().height(),width:e.timeScale().width(),fontSize:l.fontSize,fontFamily:l.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 ve(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 Mr(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=ve(e);return c>0?n-1+(t-i)/c:null}if(t<=o){const c=ve(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 vr(e,t,n){if(!n)return null;const o=Q(e[e.length-1].time);return o==null||t<=o?null:e.length-1+n.slots(t,o)}function kr(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 Ga(e,t,n,o){if(n.length===0)return null;const i=vr(n,t,o)??Mr(n,t);return i==null?null:kr(e,i)}function ja(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 Zn="#1e53e5";function Lr(e,t,n){const o={clips:new Map,grads:new Map};for(const i of t)Kn(e,i,n,o)}function Kn(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,$r(s.color,s.opacity));o.grads.set(t.name,l);return}case"hit":case"hitPath":return;case"anchors":ef(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),le(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(),le(e,l,t,o,!0);break}case"path":{t.transform&&Jn(e,t.transform),le(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?Qn(l,t.x,t.y,t.w,t.h,s,a):l.rect(t.x,t.y,t.w,t.h),le(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),le(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),le(e,l,t,o,!0);break}case"text":Ka(e,t,n);break;case"image":Ja(e,t,n);break;case"glyph":tf(e,t,n);break;case"group":{if(t.transform&&Jn(e,t.transform),t.opacity!=null&&t.opacity<1){const l=qa(e);if(l){for(const s of t.items)Kn(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)Kn(e,l,n,o);break}}r&&e.restore()}function qa(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 le(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&&Sr(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")&&Sr(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(Za(n.dash)),e.stroke(t),e.restore()}}function Sr(e,t){e.shadowOffsetX=t.dx,e.shadowOffsetY=t.dy,e.shadowBlur=t.blur,e.shadowColor=t.color}function Za(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 Qn(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 Ka(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+=Qa(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 Cr=new Map;function Qa(e){let t=Cr.get(e.font);if(t==null){const n=e.measureText("H");t=(n.fontBoundingBoxAscent-n.fontBoundingBoxDescent)/2,Cr.set(e.font,t)}return t}const Tr=new Map;function Ar(e,t){let n=Tr.get(e);return n||(n=new Image,n.onload=()=>{var o;return(o=t.onAsyncLoad)==null?void 0:o.call(t)},n.src=e,Tr.set(e,n)),n.complete&&n.naturalWidth>0?n:null}function Ja(e,t,n){if(!t.href)return;const o=Ar(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 tf(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=Ar(`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 ef(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=$r(Zn,.2),e.lineWidth=3;const c=new Path2D;s?Qn(c,r.x-nt-1.5,r.y-nt-1.5,2*nt+3,2*nt+3,4.5,4.5):c.arc(r.x,r.y,nt+1.5,0,Math.PI*2),e.stroke(c)}const a=new Path2D;if(s){const c=2*nt-i;Qn(a,r.x-nt+i/2,r.y-nt+i/2,c,c,3,3)}else a.arc(r.x,r.y,nt-i/2,0,Math.PI*2);e.fillStyle=o.fillAt(r.y),e.fill(a),e.strokeStyle=Zn,e.lineWidth=i,e.stroke(a),e.restore()})}function $r(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 nf=()=>`dw_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`;class of{constructor(t,n,o={}){Y(this,"chart");Y(this,"series");Y(this,"opts");Y(this,"coords");Y(this,"primitive");Y(this,"el");Y(this,"listeners",{change:new Set,add:new Set,update:new Set,remove:new Set,selection:new Set,tool:new Set,visibility:new Set,textEdit:new Set,gestureEnd:new Set,tableEdit:new Set});Y(this,"list",[]);Y(this,"selected",[]);Y(this,"visible",!0);Y(this,"hovered",null);Y(this,"spec",null);Y(this,"glyph");Y(this,"pending",[]);Y(this,"cursor",null);Y(this,"gesture",null);Y(this,"tableUi",null);Y(this,"hoverCursor",null);Y(this,"shift",!1);Y(this,"ctrl",!1);Y(this,"savedScroll",null);Y(this,"off",[]);this.chart=t,this.series=n,this.opts={magnet:"off",...o};const i=o.bars??(()=>lf(n));this.coords=wr(t,n,i,()=>[],o.timeInfo),this.primitive=new cf(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(qo(()=>{var r;for(const l of this.list)l.kind==="image"&&Al((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?Pe(t)??null:null;o&&this.setDrawingsVisible(!0),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.dropHidden(),this.redraw()}setDrawingsVisible(t){this.visible!==t&&(this.visible=t,t||(this.spec&&this.setTool(null),this.dropHidden()),this.emit("visibility",t),this.redraw())}drawingsVisible(){return this.visible}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:nf(),style:Ft(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.dropHidden(),this.emit("update",t,n),this.changed())}setHidden(t,n){const o=this.get(t);!o||!!o.hidden===n||this.update({...o,hidden:n})}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=N(this.coords,{x:n/2,y:o/2});if(!i)return null;const r=Ft("image"),l=this.add({kind:"image",points:[i],image:{name:t.name,...Bl(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=gr(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,...Ll(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,...Ml(o.style,n==="insert-row"?"row":"column",i)}});else{const s=n==="remove-row"?"row":"column";if(!i||!vl(o.style,s))return;const a=kl(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=tr(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=Ke(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:Ji(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=bi(l,s,o);for(const c of a.price){const f=o.priceToY(c.price);f!=null&&t.push(Br(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(Br(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?sf(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 this.visible&&!t.hidden&&(this.opts.interval==null||Ot(t.visibility,this.opts.interval))}dropHidden(){const t=n=>{const o=this.get(n);return!!o&&this.shown(o)};this.hovered&&!t(this.hovered.id)&&(this.hovered=null,this.hoverCursor=null),this.selected.every(t)||this.select(this.selected.filter(t))}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(){var i;const t=this.opts.magnet??"off",n=t==="strong"?"strong":"weak",o=this.pending.length>0||!!((i=this.gesture)!=null&&i.active)&&this.gesture.mode.hit==="handle";return this.shift&&o?{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=>ir(o,n,t.mode)??o:o=>o}dataAt(t){const n=N(this.coords,t);return n?this.snapFn()(n):null}aimAt(t){const n=this.magnet();if(!n.enabled)return t;const o=N(this.coords,t),i=o?ir(o,this.coords,n.mode):null;return i&&J(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=mi(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"?Ho(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"?pr(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=Pe(n.drawing.kind))!=null&&i.textEditable)&&(t.stopPropagation(),this.emit("textEdit",n.drawing,rf(n.drawing,n.pts)))}placementClick(t){const n=this.spec;if(n.kind==="image")return;const o=t,i=this.pending,r=this.coords;if(n.variableLength&&i.length>=1){const d=x=>{const p=J(r,x);return!!p&&Math.hypot(p.x-o.x,p.y-o.y)<nr};if(d(i[i.length-1])){i.length>=2&&this.finishVariable(!1);return}if(n.kind==="polyline"&&i.length>=2&&d(i[0])){this.finishVariable(!0);return}}const l=this.dataAt(o);if(!l)return;const s=this.shift?hr(n.kind,i,l,r):{point:l},a=s.point,c=s.extra?[...i,a,s.extra]:[...i,a];if(n.variableLength||c.length<n.pointCount){this.pending=c,this.cursor=o,this.redraw();return}const{w:f,h}=this.paneSize();let u=Gn(n.kind,c,r,{w:f,h},{glyph:this.glyph});u&&n.kind==="signpost"&&(u={...u,style:{...Ft("signpost"),signpostPosition:ci(r,c[0],h)}}),this.pending=[],this.cursor=null,u?this.placeNew(u,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=Gn(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=N(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)<Aa)return;const c=N(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,...m}=p.image;this.update({...p,image:m})}}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)<Ta)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={dx:t.x-n.startCursor.x,dy:t.y-n.startCursor.y},{dx:r,dy:l}=this.shift?qn(i.dx,i.dy):i;for(const s of n.group){const a=Xn(this.coords,s.start,s.startScreen,r,l,this.paneSize());a&&this.update(a)}return}const o=xr(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=gn(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=>J(l,d)).filter(d=>!!d);if(!s.length)return null;const a=Ft(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&&!Ba.has(o.kind)&&s.length===i.length&&s.length<o.pointCount){const d=this.dataAt(c),x=d&&this.shift?hr(o.kind,i,d,l):null,p=x?x.point:d;if(p){const y=[...i,p];for(x!=null&&x.extra&&y.push(x.extra);y.length<o.pointCount;)y.push(p);const m=Qe(o.kind,y),b=m&&o.kind==="gann-square"?lr(m,l):m,g=b?{...b,id:"__preview__",style:a}:null,w=g?or(l,g.points):null;if(g&&w)return[...Ke(g,w,{w:t,h:n,coords:l,selected:!1}),...f]}}if(o.freehand&&s.length>=2)return Ke({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 rf(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 lf(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 sf(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 Br(e,t,n,o){return{coordinate:()=>e,text:()=>t,backColor:()=>n,textColor:()=>o,visible:()=>!0,tickVisible:()=>!0}}class cf{constructor(t){Y(this,"m");Y(this,"request",null);Y(this,"view");Y(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))Lr(n,c.scene,{fontFamily:l,anchors:{fillAt:s,selected:c.selected,hovered:c.hoveredAnchor},onAsyncLoad:a});n.restore()})}}const af="0.6.1";E.ANCHORABLE_KINDS=mr,E.DEFAULT_STYLE=ot,E.DrawingManager=of,E.IMAGE_MAX_BYTES=Sl,E.IMAGE_MAX_SIDE=Mn,E.IMAGE_TYPES=Cl,E.OVERLAY_SPECS=ae,E.TV_ANCHOR_COLOR=Zn,E.VERSION=af,E.anchorCursor=pr,E.applyDrag=xr,E.buildNewDrawing=Qe,E.cacheImage=Il,E.decodeImage=Ko,E.defaultStyleFor=Ft,E.drawScene=Lr,E.drawingAxisLabels=bi,E.factoryStyleFor=Fr,E.fibLevelAt=js,E.findOverlaySpec=Pe,E.finishPlacement=Gn,E.hitTestKind=mi,E.isAnchorable=br,E.isVisibleOnInterval=Ot,E.makeCoords=wr,E.migrateDrawing=er,E.onImagesChanged=qo,E.parseDrawings=tr,E.sceneLockedAnchors=Ji,E.sceneOf=Ke,E.setDefaultStyleOverride=_r,E.setImageReader=Tl,E.timeToXFallback=Ga,E.toggleAnchored=gr,E.volumeProfileDefaults=oo,E.volumeProfileStyle=Be,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(E,ot){typeof exports=="object"&&typeof module<"u"?ot(exports):typeof define=="function"&&define.amd?define(["exports"],ot):(E=typeof globalThis<"u"?globalThis:E||self,ot(E.LightweightChartsDrawing={}))})(this,(function(E){"use strict";var xf=Object.defineProperty;var yf=(E,ot,Dt)=>ot in E?xf(E,ot,{enumerable:!0,configurable:!0,writable:!0,value:Dt}):E[ot]=Dt;var Y=(E,ot,Dt)=>yf(E,typeof ot!="symbol"?ot+"":ot,Dt);const ot={color:"#2962ff",width:1,lineStyle:"solid"};function Dt(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 q="#808080",st="#f23645",it="#ff9800",rt="#4caf50",Z="#089981",tt="#00bcd4",$="#2962ff",jt="#9c27b0",ut="#e91e63",qt="#673ab7",$t=[{coeff:0,color:q,visible:!0},{coeff:.236,color:st,visible:!0},{coeff:.382,color:it,visible:!0},{coeff:.5,color:rt,visible:!0},{coeff:.618,color:Z,visible:!0},{coeff:.786,color:tt,visible:!0},{coeff:1,color:q,visible:!0},{coeff:1.618,color:$,visible:!0},{coeff:2.618,color:st,visible:!0},{coeff:3.618,color:jt,visible:!0},{coeff:4.236,color:ut,visible:!0},{coeff:1.272,color:it,visible:!1},{coeff:1.414,color:st,visible:!1},{coeff:2.272,color:it,visible:!1},{coeff:2.414,color:rt,visible:!1},{coeff:2,color:Z,visible:!1},{coeff:3,color:tt,visible:!1},{coeff:3.272,color:q,visible:!1},{coeff:3.414,color:$,visible:!1},{coeff:4,color:st,visible:!1},{coeff:4.272,color:jt,visible:!1},{coeff:4.414,color:ut,visible:!1},{coeff:4.618,color:it,visible:!1},{coeff:4.764,color:Z,visible:!1}],Lt=[{coeff:.25,color:"#ffb74d",visible:!1},{coeff:.382,color:"#81c784",visible:!1},{coeff:.5,color:Z,visible:!0},{coeff:.618,color:Z,visible:!1},{coeff:.75,color:tt,visible:!1},{coeff:1,color:$,visible:!0},{coeff:1.5,color:jt,visible:!1},{coeff:1.75,color:ut,visible:!1},{coeff:2,color:"#f77c80",visible:!1}],on=[{coeff:1/8,color:it,visible:!0,label:"1/8"},{coeff:1/4,color:Z,visible:!0,label:"1/4"},{coeff:1/3,color:rt,visible:!0,label:"1/3"},{coeff:1/2,color:Z,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:jt,visible:!0,label:"3/1"},{coeff:4,color:ut,visible:!0,label:"4/1"},{coeff:8,color:st,visible:!0,label:"8/1"}],rn=[{coeff:.236,color:st,visible:!0},{coeff:.382,color:it,visible:!0},{coeff:.5,color:rt,visible:!0},{coeff:.618,color:Z,visible:!0},{coeff:.786,color:tt,visible:!0},{coeff:1,color:q,visible:!0},{coeff:1.618,color:$,visible:!1},{coeff:2.618,color:st,visible:!1},{coeff:3.618,color:qt,visible:!1},{coeff:4.236,color:ut,visible:!1},{coeff:4.618,color:ut,visible:!1}],Te=[{coeff:0,color:q,visible:!0},{coeff:.25,color:it,visible:!0},{coeff:.382,color:tt,visible:!0},{coeff:.5,color:rt,visible:!0},{coeff:.618,color:Z,visible:!0},{coeff:.75,color:$,visible:!0},{coeff:1,color:q,visible:!0}],ln=[{coeff:0,color:q,visible:!0,width:2,style:"solid"},{coeff:.382,color:st,visible:!0,width:2,style:"solid"},{coeff:.5,color:"#81c784",visible:!1,width:2,style:"solid"},{coeff:.618,color:rt,visible:!0,width:2,style:"solid"},{coeff:1,color:Z,visible:!0,width:2,style:"solid"},{coeff:1.382,color:tt,visible:!0,width:2,style:"solid"},{coeff:1.618,color:q,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:jt,visible:!0,width:2,style:"solid"},{coeff:3,color:"#673ab7",visible:!0,width:2,style:"solid"}],sn={visible:!0,color:q,width:2,style:"dashed"},Pr=sn,Er={visible:!0,color:q,width:2,style:"solid"},Zt=(e,t)=>({color:e,width:2,visible:t}),G=(e,t,n,o)=>({color:e,width:2,visible:t,x:n,y:o}),cn=[Zt(q,!0),Zt(it,!0),Zt(tt,!0),Zt(rt,!0),Zt(Z,!0),Zt(q,!0)],an=[G("#b39ddb",!1,8,1),G(st,!1,5,1),G(q,!1,4,1),G(it,!1,3,1),G(tt,!0,2,1),G(rt,!0,1,1),G(Z,!0,1,2),G(Z,!1,1,3),G($,!1,1,4),G("#9575cd",!1,1,5),G("#b39ddb",!1,1,8)],fn=[G(it,!0,1,0),G(it,!0,1,1),G(it,!0,1.5,0),G(tt,!0,2,0),G(tt,!0,2,1),G(rt,!0,3,0),G(rt,!0,3,1),G(Z,!0,4,0),G(Z,!0,4,1),G($,!0,5,0),G($,!0,5,1)],eo={visible:!0,color:"rgba(21, 56, 153, 0.8)",width:1,style:"solid"},hn=[{coeff:0,color:q,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}],un=[{coeff:1,color:rt,visible:!0},{coeff:2,color:"#808000",visible:!1},{coeff:3,color:"#00897b",visible:!1}],no=[{visible:!0,color:rt,width:1,style:"solid"},{visible:!0,color:"#808000",width:1,style:"solid"},{visible:!0,color:"#00897b",width:1,style:"solid"}],dn=[{coeff:.236,color:st,visible:!0},{coeff:.382,color:it,visible:!0},{coeff:.5,color:Z,visible:!0},{coeff:.618,color:rt,visible:!0},{coeff:.786,color:tt,visible:!0},{coeff:1,color:q,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:st,visible:!0}],xn=[{coeff:.236,color:st,visible:!0},{coeff:.382,color:it,visible:!0},{coeff:.5,color:Z,visible:!0},{coeff:.618,color:rt,visible:!0},{coeff:.786,color:tt,visible:!0},{coeff:1,color:q,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:st,visible:!0}],Ae=[{coeff:0,color:q,visible:!0},{coeff:.25,color:it,visible:!0},{coeff:.382,color:tt,visible:!0},{coeff:.5,color:rt,visible:!0},{coeff:.618,color:Z,visible:!0},{coeff:.75,color:$,visible:!0},{coeff:1,color:q,visible:!0}],zr=7,Rr={upColor:"#ACE5DC",downColor:"#FAA1A4",drawBorder:!0,borderUpColor:"#089981",borderDownColor:"#F23645",drawWick:!0,wickColor:"#808080"},oo={base:{visible:!0,color:st,width:1,style:"dashed"},up:{visible:!0,color:$,width:2,style:"solid"},down:{visible:!0,color:$,width:2,style:"solid"}};function io(e){const t=(n,o,i)=>({visible:n,color:o,width:i,style:"solid"});return{rowsLayout:"rows",rows:24,volume:"upDown",vaVolume:70,extendRight:!1,visible:!0,showValues:!1,valuesColor:"#DBDBDB",percentWidth:30,placement:e==="anchored-volume-profile"?"right":"left",upColor:"rgba(38, 198, 218, 0.5)",downColor:"rgba(236, 64, 122, 0.5)",vaUpColor:"rgba(38, 198, 218, 0.75)",vaDownColor:"rgba(236, 64, 122, 0.75)",vah:t(!1,"#DBDBDB",2),val:t(!1,"#DBDBDB",2),poc:t(!0,"#DBDBDB",2),developingPoc:t(!1,"#DBDBDB",1),developingVah:t(!1,"#00BCD4",1),developingVal:t(!1,"#00BCD4",1),boxColor:"rgba(38, 198, 218, 0.05)"}}function $e(e,t){return{...io(e),...t.vp??{}}}const Be=[-.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"})),Wr=Lt.map(e=>e.coeff===.5?{...e,color:tt}:e),ae={"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,extendLine:!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:q,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:q,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:on,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:hn,fillBackground:!1,transparency:80,showLabels:!0,horzLabelsAlign:"right",vertLabelsAlign:"bottom"}},"fib-circles":{kind:"fib-circles",pointCount:2,preview:"line",isBbox:!1,defaults:{color:q,width:2,levels:xn,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:eo}},"fib-speed-resistance-arcs":{kind:"fib-speed-resistance-arcs",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,levels:dn,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:ln,fibTrendLine:sn,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:cn,gannFans:an,gannArcs:fn,fillBackground:!0,transparency:80,reverse:!1}},"gann-square":{kind:"gann-square",pointCount:2,preview:"line",isBbox:!1,defaults:{width:2,gannLevels:cn,gannFans:an,gannArcs:fn,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:jt}},"fib-wedge":{kind:"fib-wedge",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:rn,fillBackground:!0,transparency:80}},pitchfan:{kind:"pitchfan",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Wr,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:$t,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:Be,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:Lt,fillBackground:!0,transparency:80}},"trend-based-fib-extension":{kind:"trend-based-fib-extension",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:$t,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:Lt,fillBackground:!0,transparency:80}},"modified-schiff-pitchfork":{kind:"modified-schiff-pitchfork",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Lt,fillBackground:!0,transparency:80}},"inside-pitchfork":{kind:"inside-pitchfork",pointCount:3,preview:"line",isBbox:!1,defaults:{color:"#f23645",width:2,levels:Lt,fillBackground:!0,transparency:80}},"fib-channel":{kind:"fib-channel",pointCount:3,preview:"line",isBbox:!1,defaults:{width:2,levels:$t,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:qt,width:2,fillBackground:!1,backgroundColor:qt,transparency:80}},"abcd-pattern":{kind:"abcd-pattern",pointCount:4,preview:"line",isBbox:!1,defaults:{color:Z,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:Z,width:2,textColor:"#ffffff",fontSize:12,fillBackground:!0,backgroundColor:Z,transparency:85}},"triangle-pattern":{kind:"triangle-pattern",pointCount:4,preview:"line",isBbox:!1,defaults:{color:qt,width:2,textColor:"#ffffff",fontSize:12,fillBackground:!0,backgroundColor:qt,transparency:85}},"three-drives-pattern":{kind:"three-drives-pattern",pointCount:7,preview:"line",isBbox:!1,defaults:{color:qt,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:it,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:oo}},"anchored-vwap":{kind:"anchored-vwap",pointCount:1,preview:"none",isBbox:!1,defaults:{color:"#1e88e5",width:1,vwapSource:"hlc3",levels:un,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}},Or=new Set(Object.keys(ae));function Ie(e){if(e&&Or.has(e))return ae[e]}function Ft(e){const t={...ot,...ae[e].defaults,...ro(e)};return t.levels&&(t.levels=t.levels.map(n=>({...n}))),t}function Dr(e){const t={...ot,...ae[e].defaults};return t.levels&&(t.levels=t.levels.map(n=>({...n}))),t}let ro=()=>{};function Fr(e){ro=e}const et=6,L=6,lo=9;function R(e){if(e.lineStyle==="dashed")return"6 4";if(e.lineStyle==="dotted")return"2 3"}function Pe(e){return Math.max(L,((e==null?void 0:e.width)??1)/2+2)}function fe(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 H(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 Kt(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 yt(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 _(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 _r(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)<=lo+L&&Math.abs(t.y-n.y)<=lo+L?{hit:"body"}:null}function so(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 Hr=[["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])??Hr.find(i=>i[0]===t)[2]}function ze(e,t){const n=Math.abs(e).toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t});return e<0?`−${n}`:n}function co(e,t,n,o,i,r,l,s){const a=d=>Ee(e,t+d),c=!!e.compactStats,f=ze(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!==""?" ":"")+ze(Math.round(n/i),0)),a("Amount")&&(u+=c?(u!==""?" ":"")+String(l):(u!==""?", ":"")+`Amount: ${l}`),a("PL")&&(u+=c?(u!==""?" ":"")+ze(s,r):(u!==""?", ":"")+`PnL: ${ze(s,r)}`),u}function Nr(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 he={accountSize:1e3,risk:25,leverage:1e4};function ao(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 Yr(e){const t=e.accountSize??he.accountSize;return e.riskDisplayMode==="money"?Math.min(e.riskAmount??t*(e.riskPercent??he.risk)/100,t):(e.riskPercent??he.risk)/100*t}function Vr(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 Ur(e,t,n){const o=e.accountSize??he.accountSize,i=e.leverage??he.leverage,r=n>0?Yr(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:Vr(a/c,e.qtyPrecision)}}function yn(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}=ao(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 Xr(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 m=r[y];if(t==="long"?m.low<=n?x=n:m.high>=o&&(x=o):m.high>=n?x=n:m.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 fo(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 Gr(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 jr(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 qr(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 Zr(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 ho(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 uo(e,t,n){const o=t.x-e.x||1,i=t.y-e.y;return{x:o*n,y:i}}function xo(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 Qt(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 yo(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 ue=null,po=null;function Bt(e,t,n,o){return ue||(ue=document.createElement("canvas").getContext("2d")),ue?(po??(po=getComputedStyle(document.body).fontFamily),ue.font=`${o?"italic ":""}${n?"bold ":""}${t}px ${po}`,ue.measureText(e).width):e.length*t*.6}function Re(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=>Bt(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 m=0;m<y.length-1;m++)a.push(y[m]);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 j(e){const t=e.fs;let n=e.wrapWidth!=null?Re(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=>Bt(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",m=e.angle??0,b=Math.cos(m),g=Math.sin(m),w=(M,v)=>({x:(M-d)*b-(v-x)*g+d,y:(M-d)*g+(v-x)*b+x});return{lines:n,fs:t,lineStep:t+c,tx:p,y0:h+o+t/2+.05*t,anchor:y,rotate:`rotate(${m*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 mo(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 j({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 bo(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",m=y==="middle",b=m?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:m?(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:b,wrapWidth:m?(h?n:s)-(f?0:l)-2*b:void 0,maxHeight:m?c-a:void 0},M=j(w);if(p==="left"&&f||p==="right"&&h){const v=f?0:Math.max(l,0),S=(h?n:Math.min(s,n))-v-M.box.width;if(S<0)return j({...w,offsetX:S})}return M}function We(e,t){return Math.floor(e/t+.5+1e-7)}function go(e){const t=new Array(e.length);let n=NaN,o=!0;for(let i=0;i<e.length;i++){const r=e[i];let l;r.close>r.open?l=!0:r.close<r.open?l=!1:r.close>n?l=!0:r.close<n?l=!1:l=o,t[i]=l,n=r.close,o=l}return t}function Kr(e,t,n,o){const i=Math.max(1,Math.round(o)),r=Math.max(0,t-e);if(n==="Ticks Per Row"){const l=Math.floor(e/i)*i;return{start:l,tpr:i,count:Math.max(1,Math.ceil((t-l)/i))}}return{start:e,...Qr(r,i)}}function Qr(e,t){const n=l=>Math.max(1,Math.ceil(e/l)),o=Math.max(1,Math.floor(e/t)),i=Math.max(1,Math.ceil(e/t)),r=Math.abs(n(o)-t)<=Math.abs(n(i)-t)?o:i;return{tpr:r,count:n(r)}}function Jr(e){let t=0;const n=(e.length-1)/2;for(let o=1;o<e.length;o++)(e[o]>e[t]||e[o]===e[t]&&Math.abs(o-n)<=Math.abs(t-n))&&(t=o);return t}function tl(e,t,n){let o=0;for(const c of e)o+=c;const i=o*Math.max(0,Math.min(100,n))/100;let r=t,l=t,s=e[t]??0;const a=e.length;for(;r>0||l<a-1;){const c=l<a-1?e[l+1]:-1,f=r>0?e[r-1]:-1;let h;c!==f?h=c>f:h=l+1-t<=t-(r-1);const u=h?c:f;if(s+u>i)break;s+=u,h?l++:r--}return[r,l]}function wo(e,t,n,o,i,r,l){if(o<n)return null;let s=1/0,a=-1/0;for(let b=n;b<=o;b++){const g=We(e[b].low,i),w=We(e[b].high,i);g<s&&(s=g),w>a&&(a=w)}if(!Number.isFinite(s)||!Number.isFinite(a))return null;let c,f,h;"fixedTpr"in r?(f=Math.max(1,r.fixedTpr),c=Math.floor(s/f)*f,h=Math.max(1,Math.ceil((a-c)/f))):{start:c,tpr:f,count:h}=Kr(s,a,r.layout,r.rowSize);const u=new Array(h).fill(0),d=new Array(h).fill(0);for(let b=n;b<=o;b++){const g=e[b],w=g.volume??0;if(!(w>0))continue;const M=t[b]?u:d,v=We(g.low,i)-c,k=We(g.high,i)-c;if(k<=v){M[Math.min(h-1,Math.max(0,Math.floor(v/f)))]+=w;continue}const S=k-v,C=Math.max(0,Math.floor(v/f)),I=Math.min(h-1,Math.ceil(k/f)-1);for(let A=C;A<=I;A++){const O=Math.max(v,A*f),F=Math.min(k,(A+1)*f);F>O&&(M[A]+=w*(F-O)/S)}}const x=u.map((b,g)=>b+d[g]),p=Jr(x),[y,m]=tl(x,p,l);return{lo:c*i,step:f*i,up:u,down:d,poc:p,vaLo:y,vaHi:m,boxLo:s*i,boxHi:a*i}}function el(e){return{poc:e.lo+(e.poc+.5)*e.step,vah:e.lo+(e.vaHi+1)*e.step,val:e.lo+e.vaLo*e.step}}const nl=[["1",60],["5",300],["15",900],["30",1800],["60",3600],["240",14400],["1D",86400]];function ol(e,t){if(t||e<=300)return"1S";for(const[n,o]of nl)if(e/o<5e3)return n;return"1D"}function Mo(e,t){let n=0,o=e.length;for(;n<o;){const i=n+o>>1;e[i].time<t?n=i+1:o=i}return n}function Oe(e,t,n){const o=Math.min(t,n),i=Math.max(t,n),r=[];for(const l of e){const s=_(l.time);s!=null&&s>=o&&s<=i&&r.push(l)}return r}function il(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 rl(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 vo(e,t,n){const o=e.points[1],i=_(e.points[0].time),r=o?_(o.time):null;if(!t||i==null||r==null)return null;const l=Oe(t.bars(),i,r),s=e.style.regressionSource??"close",a=il(l.map(S=>ko(S,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 S=0;S<c;S++){const C=a.b+a.m*S;u=Math.max(u,l[S].high-C),d=Math.max(d,C-l[S].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=(S,C)=>{const I=t.timeToX(S),A=t.priceToY(C);return I==null||A==null?null:{x:I,y:A}},m=y(l[0].time,f),b=y(l[c-1].time,h);if(!m||!b)return null;const g=y(l[0].time,f+x),w=y(l[c-1].time,h+x),M=y(l[0].time,f+p),v=y(l[c-1].time,h+p),k=S=>e.style.extendRight&&n!=null?rl(S,n):S;return{center:k([m,b]),upper:g&&w?k([g,w]):null,lower:M&&v?k([M,v]):null,pearsons:a.r,anchors:i<=r?[m,b]:[b,m]}}function ko(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 pn(e,t,n){const o=n==="upper"?e.vwapUpper:e.vwapLower,i=(e.levels??un)[t],r=no[t]??no[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 Lo=new WeakMap;function So(e,t,n,o){const i=t[t.length-1],r=`${n}|${o}|${t.length}|${i?`${_(i.time)}:${i.close}:${i.volume}`:""}`;let l=Lo.get(t);l||(l=new Map,Lo.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 m=a+c>>1,b=_(t[m].time);b!=null&&b<n?a=m+1:c=m}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 m=0;m<f;m++){const b=t[a+m],g=ko(b,o),w=b.volume&&b.volume>0?b.volume:1;d+=g*w,x+=g*g*w,p+=w;const M=d/p;h[m]=M,u[m]=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 Co(e,t){let n=0,o=e.length;for(;n<o;){const i=n+o>>1,r=_(e[i].time);r!=null&&r<t?n=i+1:o=i}return n}function ll(e,t){var n;return t?((n=sl(e,t.bars()))==null?void 0:n.vwap)??null:null}function sl(e,t){const n=e.points[0]?_(e.points[0].time):null;if(n==null||t.length===0)return null;const o=So(e,t,n,e.style.vwapSource??"hlc3"),i=o.vwap.length-1;return i>=0?{vwap:o.vwap[i],sd:o.sd[i]}:null}function To(e,t){const 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??un).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=So(e,l,n,i);let a=s.start,c=l.length;const f=t.visibleTimeRange();f&&(a=Math.max(a,Co(l,f.from)-1),c=Math.min(c,Co(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 m=r?x*.01:s.sd[u];for(const b of o.bands){const g=t.priceToY(x+b.level.coeff*m),w=t.priceToY(x-b.level.coeff*m);g!=null&&b.upper.push({x:p,y:g}),w!=null&&b.lower.push({x:p,y:w})}}}return o}function Ao(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 cl(e,t){const n=e.points[1];if(!t||!n)return"waiting";const o=_(n.time);if(o==null)return"waiting";const i=t.bars();if(i.length===0)return"waiting";const r=_(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=_(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"}const $o=new WeakMap;function al(e){let t=$o.get(e);return(!t||t.length!==e.length)&&(t=go(e),$o.set(e,t)),t}function Bo(e,t,n,o={}){const i=Oe(e,t,n);if(i.length===0)return null;const r=Math.min(1,Math.max(0,o.vaShare??.7))*100,l=o.tick&&o.tick>0?o.tick:.01,s={layout:o.rowsLayout==="ticks"?"Ticks Per Row":"Number Of Rows",rowSize:Math.max(1,Math.round(o.rows??24))},a=_(i[0].time)??0,c=_(i[i.length-1].time)??a;let f=i,h=0,u=i.length-1;const d=o.lower;if(d){const g=d.barEnd(c),w=d.bars(ol(g-a,d.seconds),a);if(w&&w.length){const M=w,v=Mo(M,a),k=Mo(M,g)-1;k>=v&&(f=w,h=v,u=k)}}const x=f===i?go(i):al(f),p=wo(f,x,h,u,l,s,r);if(!p)return null;let y=null;if(o.developing){y=[];let g=h;for(let w=0;w<i.length;w++){const M=w+1<i.length?_(i[w+1].time)??1/0:1/0;for(;g+1<=u&&(_(f[g+1].time)??0)<M;)g++;if((_(f[h].time)??0)>=M)continue;const v=g===u?p:wo(f,x,h,g,l,s,r);if(!v)continue;const k=el(v);y.push({time:i[w].time,poc:k.poc,vah:k.vah,val:k.val})}}const m=p.up.map((g,w)=>({up:g,down:p.down[w]})),b=m.map(g=>g.up+g.down);return{lo:p.lo,hi:p.lo+m.length*p.step,step:p.step,rows:m,poc:p.poc,vaFrom:p.vaLo,vaTo:p.vaHi,maxTotal:Math.max(...b),maxDelta:Math.max(...m.map(g=>Math.abs(g.up-g.down))),lastTime:i[i.length-1].time,developing:y}}function Io(e,t){const n=$e(e.kind,e.style);return{rowsLayout:n.rowsLayout,rows:n.rows,tick:t.pipSize(),vaShare:n.vaVolume/100,developing:n.developingPoc.visible||n.developingVah.visible||n.developingVal.visible,lower:t.lowerTimeframe}}function Po(e,t,n){if(!n)return null;const o=n.bars();if(o.length===0)return null;const i=_(e.points[0].time),r=_(o[o.length-1].time);if(i==null||r==null)return null;const l=Bo(o,i,r,Io(e,n));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 Eo(e,t,n){if(!n||e.points.length<2||t.length<2)return null;const o=_(e.points[0].time),i=_(e.points[1].time);if(o==null||i==null)return null;const r=n.bars(),l=$e(e.kind,e.style).extendRight,s=r.length?_(r[r.length-1].time):null,a=Math.min(o,i),c=l&&s!=null?Math.max(s,a):Math.max(o,i),f=Bo(r,a,c,Io(e,n));if(!f)return null;const h=n.priceToY(f.hi),u=n.priceToY(f.lo);if(h==null||u==null)return null;const d=Math.min(t[0].x,t[1].x),x=l?n.timeToX(f.lastTime):null,p=x!=null?Math.max(d,x):Math.max(t[0].x,t[1].x);return{left:d,right:p,top:Math.min(h,u),bottom:Math.max(h,u),vp:f}}function zo(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 v=(n==null?void 0:n.priceToY(h+M.coeff*u))??d+M.coeff*x;return{coeff:M.coeff,color:M.color,y:v}}),y=(n==null?void 0:n.timeToBarIndex(c.time))??null,m=(n==null?void 0:n.timeToBarIndex(f.time))??null,b=a?i.x:r.x,g=a?r.x-i.x:i.x-r.x,w=s.map(M=>{let v=null;if(n&&y!=null&&m!=null){const k=n.barIndexToTime(Math.round((a?y:m)+M.coeff*(a?m-y:y-m)));v=k!=null?n.timeToX(k):null}return{coeff:M.coeff,color:M.color,x:v??b+M.coeff*g}});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 mn(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 fl=["bars","oc","line","line-open","line-high","line-low","line-hl2"];function Ro(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 Wo(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 Oo(e,t,n){var F;if(e.kind!=="bar-pattern"||!n)return null;const o=((F=e.pattern)==null?void 0:F.bars)??[];if(o.length===0||t.length<2)return null;const i=e.style,[r,l]=t,s=fl.includes(i.patternMode??"")?i.patternMode:"bars";let a=o;if(i.mirrored){let T=1/0,z=-1/0;for(const P of a)T=Math.min(T,P[2],P[1]),z=Math.max(z,P[1],P[2]);if(T<z){const P=(T+z)/2,B=D=>P-(D-P);a=a.map(([D,U,J,Mt])=>[B(D),B(U),B(J),B(Mt)])}}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=Wo(a[0],s,!0,!!i.flipped),p=Wo(a[a.length-1],s,!1,!!i.flipped),y=n.priceToY(x),m=n.priceToY(p);if(u==null||d==null||y==null||m==null)return null;const b=m!==y?+((d-u)/(m-y)).toFixed(8):1,g=T=>(n.priceToY(T)??0)*b,w=n.timeToBarIndex(e.points[0].time),M=n.timeToBarIndex(e.points[1].time),k=w==null||M==null||w<=M?{x:r.x,y:u}:{x:l.x,y:d},S=a.length,C=S>1?Math.abs(r.x-l.x)/(S-1):0,I=k.y-g(x),A=a.map((T,z)=>Math.round(k.x+z*C+.5)),O=s!=="bars"&&s!=="oc";return O?{lineMode:O,bars:[],line:a.map((T,z)=>({x:A[z],y:Math.round(g(Ro(T,s)[0]))+I}))}:{lineMode:O,line:[],bars:a.map((T,z)=>{const[P,B]=Ro(T,s),D=Math.round(g(P))+I,U=Math.round(g(B))+I;return{x:A[z],top:Math.min(D,U),bottom:Math.max(D,U)}})}}let de=null;function hl(e,t){return de||(de=document.createElement("canvas").getContext("2d")),de?(de.font=t,de.measureText(e).width):e.length*8}function Do(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=>hl(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 _t=8,dt=1,ul=2,Fo=120,_o=1.3,dl="#2962ff",xl="rgba(41, 98, 255, 0.2)",Ho=3,Jt=1024;function yl(e){return Jt+(e.row==null?0:e.row+1)*Jt+(e.col==null?0:e.col+1)}function No(e){if(e<Jt)return null;const t=e-Jt,n=Math.floor(t/Jt),o=t%Jt;return{row:n===0?null:n-1,col:o===0?null:o-1}}function It(e){return e.tableCells??[["","",""],["","",""],["","",""]]}function xe(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]??Fo)}function bn(e){const t=It(e).length,n=e.tableRowHeights??[];return Array.from({length:t},(o,i)=>n[i]??0)}const Yo=e=>e.fontSize??14,Vo=e=>Bt("0",e,!1,!1);function pl(e){return Vo(e)+2*_t+2*dt}function Uo(e){return e+2*_t+dt}function ml(e,t){return Math.max(e-2*_t-2*dt,Vo(t))}function Xo(e,t,n){return e===""?[]:Re(e,n,!1,!1,ml(t,n))}function bl(e,t){return e*t+(e-1)*t*(_o-1)+2*_t+2*dt}function Go(e,t=It(e),n=xe(e)){const o=Yo(e),i=bn(e),r=[];return{heights:i.map((s,a)=>{var f;let c=Uo(o);for(let h=0;h<n.length;h++)c=Math.max(c,bl(Xo(((f=t[a])==null?void 0:f[h])??"",n[h],o).length,o));return r.push(c),Math.max(s,c)}),mins:r}}function gn(e,t){const n=e.style,o=Yo(n),i=It(n),r=xe(n),{heights:l}=Go(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)=>Xo(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 jo(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 gl(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])<=Ho){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])<=Ho){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 wn(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?wn(s,t,n):s}function wl(e,t,n){var a;const o=It(e).map(c=>[...c]),i=xe(e),r=bn(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,Fo)}return{tableCells:o,tableColWidths:i,tableRowHeights:r}}function Ml(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 vl(e,t,n){const o=It(e).map(c=>[...c]),i=xe(e),r=bn(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 kl(e,t,n){const o=It(e).map(i=>[...i]);return o[t[0]]&&(o[t[0]][t[1]]=n),{tableCells:o}}const Ll=2e6,Mn=2e3,Sl={"image/png":"png","image/jpeg":"jpg","image/webp":"webp"},Pt=new Map;let qo=()=>Promise.reject(new Error("no image reader"));const vn=new Set;function Cl(e){qo=e}function Zo(e){return vn.add(e),()=>vn.delete(e)}function Ko(){for(const e of vn)e()}function Qo(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 kn(e){if(!e)return null;const t=Pt.get(e);return t&&t!=="loading"&&t!=="error"?t:(t||(Pt.set(e,"loading"),qo(e).then(n=>Qo(URL.createObjectURL(n))).then(n=>Pt.set(e,n),n=>{Pt.set(e,"error"),console.warn("[image] read failed:",n)}).then(Ko)),null)}function Tl(e){return!!e&&Pt.get(e)==="error"}function Jo(e,t){const n=e.image,o=kn(n==null?void 0:n.name);if(!n||!o||o.width>Mn||o.height>Mn)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 ti(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 Al=[[-1,-1],[1,-1],[-1,1],[1,1]];function $l(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 Bl(e,t){(!Pt.has(e)||Pt.get(e)==="error")&&Pt.set(e,t),Ko()}const Il="Add text",Pl={text:"Text",note:"Add text",pin:"Note",comment:"Comment","price-note":"Price note",signpost:"Signpost",callout:"Callout"};function El(e){const t=!!(e.text&&e.text.length>0);return{txt:t?e.text:Pl[e.kind]??"Text",faint:!t}}function ei(e,t,n,o){const{txt:i,faint:r}=El(e),l=t.fontSize??14,s=Bt(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 pt(e){return e.text?{text:e.text,faint:!1}:{text:Il,faint:!0}}function ni(e,t){const n=e.style,o=n.fontSize??14,i=o/6;return j({x:t.x,y:t.y,text:pt(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 oi(e,t){const o=e.style.fontSize??16,i=Math.round(o/1.3),r=j({x:t.x,y:t.y,text:pt(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 zl(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 Rl="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 ii(e,t,n){const o=e.style,i=o.fontSize??14,r=Math.min(236,n),l=Re(pt(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 ri(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 li(e,t,n){const o=Bt(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 Wl(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 si(e,t){const n=e.style,o=n.fontSize??14,i=n.wordWrap?n.wordWrapWidth??200:void 0,r=Re(pt(e).text,o,!!n.bold,!!n.italic,i),l=i??Math.max(0,...r.map(u=>Bt(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 Ol(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=(g,w)=>`${o+g} ${i+w}`,m=(g,w)=>`A 8 8 0 0 1 ${y(g,w)}`;let b=`M ${y(8,0)}`;return d===10?b+=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)}`:b+=` L ${y(r-8,0)}`,b+=d===20?` L ${y(c,f)} L ${y(r,8)}`:` ${m(r,8)}`,d===21?b+=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)}`:b+=` L ${y(r,l-8)}`,b+=d===22?` L ${y(c,f)} L ${y(r-8,l)}`:` ${m(r-8,l)}`,d===12?b+=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)}`:b+=` L ${y(8,l)}`,b+=d===2?` L ${y(c,f)} L ${y(0,l-8)}`:` ${m(0,l-8)}`,d===1?b+=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)}`:b+=` L ${y(0,8)}`,b+=d===0?` L ${y(c,f)} L ${y(8,0)}`:` ${m(8,0)}`,b+" Z"}const Ht={pole:"#808080",labelBg:"#0f0f0f",labelBorder:"#2e2e2e",labelText:"#dbdbdb",plateBorder:"#0f0f0f"};function ci(e,t){const n=e.barAt(t.time);return n?{high:n.high,low:n.low}:null}function ai(e,t,n){const o=ci(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 Dl(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 Ln(e,t,n,o){const i=e.style,r=i.signpostPosition??50,l=r>=0?1:-1,s=ci(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=v=>j({x:t.x,y:v,text:pt(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=Dl(r,o,f,l),p=d(x);const y=p.box.height,m=l===1?Math.min(h-y,x):Math.max(h+y,x);m!==x&&(x=m,p=d(x));const b=i.showImage?80:0,g=x+(y+b)*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:g,plateY:w,gap:M,n:l,x:t.x}}function fi(e,t,n,o){const i=t.yToPrice(o);return i==null?null:ai(t,{time:e.points[0].time,price:i},n)}const lt=et+L;function Nt(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)<=lt)return{hit:"handle",handleIndex:n};return null}function Fl(e,t,n){const o=yt(e,t);for(let i=0;i<4;i++)if(Math.hypot(o[i].x-n.x,o[i].y-n.y)<=lt)return{hit:"handle",handleIndex:i};return null}function _l(e,t,n,o=L){const i=e[0];return Math.hypot(.9*n-t.x,i.y-t.y)<=lt?{hit:"handle",handleIndex:0}:Math.abs(t.y-i.y)<=o?{hit:"body"}:null}function Hl(e,t,n,o=L){const i=e[0];return Math.hypot(i.x-t.x,.9*n-t.y)<=lt?{hit:"handle",handleIndex:0}:Math.abs(t.x-i.x)<=o?{hit:"body"}:null}function Nl(e,t,n=L){const o=e[0];return Math.hypot(o.x-t.x,o.y-t.y)<=lt?{hit:"handle",handleIndex:0}:Math.abs(t.y-o.y)<=n||Math.abs(t.x-o.x)<=n?{hit:"body"}:null}function hi(e,t,n=L){const o=e[0];return Math.hypot(o.x-t.x,o.y-t.y)<=lt?{hit:"handle",handleIndex:0}:t.x>=o.x-lt&&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 Vl(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 H(n.x,n.y,h,u)<=Pe(l)?{hit:"body"}:null}function ui(e,t,n=L){const o=W(e,t);return o||(H(t.x,t.y,e[0],e[1])<=n?{hit:"body"}:null)}function Ul(e,t,n,o){if(!e.points[0]||!e.points[1])return null;const i=yn(e,t,o);if(!i)return null;const{anchors:r,yStop:l,yTarget:s}=i,[a,c]=t,f=W(r,n);if(f)return f;const h=Math.min(a.x,c.x),u=Math.max(a.x,c.x),d=Math.min(s,l),x=Math.max(s,l);return n.x>=h-L&&n.x<=u+L&&n.y>=d-L&&n.y<=x+L?{hit:"body"}:null}function De(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 Sn(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 Xl(e,t,n,o,i){const r=W(t,n);if(r)return r;const l=xo(e.kind,t);if(!l)return null;const s=e.style,a=x=>Qt(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??Lt).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(H(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(Sn(n,l.mid,p,l.half,-x,x,!!s.extendLines,!0))return{hit:"body"}}return null}function Gl(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 jl(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??on).filter(f=>f.visible);for(const f of c){const h=uo(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(H(n.x,n.y,l,d)<=L)return{hit:"body"}}return null}function ql(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??hn).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 H(n.x,n.y,t[0],t[1])<=o?{hit:"body"}:null}function Zl(e,t,n){const o=W(t,n);if(o)return o;if(e.fmt===2){const l=(e.style.levels??xn).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 Kl(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,m=(y.levels??Be).filter(g=>g.visible);if(m.length===0)return null;const b=(i+r)*2;for(const g of m){const w=f*g.coeff,[M,v]=De({x:l.x,y:l.y+w},{x:s.x,y:s.y+w},!!y.extendLeft,!!y.extendRight,b);if(H(n.x,n.y,M,v)<=o)return{hit:"body"}}return y.fillBackground!==!1&&Sn(n,l,s,{x:0,y:f},m[0].coeff,m[m.length-1].coeff,!!y.extendLeft,!!y.extendRight)?{hit:"body"}:null}function Ql(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[m,b]=De(p,y,!!d.extendLeft,!!d.extendRight,x);if(H(n.x,n.y,m,b)<=o)return{hit:"body"}}return null}function Jl(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]=De(u,d,!!f.extendLeft,!!f.extendRight,h);if(H(n.x,n.y,x,p)<=o)return{hit:"body"}}return null}function ts(e,t,n,o,i,r){const l=W(t,n);if(l)return l;const[s,a,c]=t;if(!c)return H(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??$t).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]=De({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(H(n.x,n.y,p,y)<=o)return{hit:"body"}}return f.fillBackground===!1?null:Sn(n,s,a,h,Math.min(...u),Math.max(...u),!!f.extendLeft,!!f.extendRight)?{hit:"body"}:null}function es(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 di(e,t){const[n,o,i,r]=yt(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 Cn(e,t,n=!1){const[o,i]=e,r=Fl(o,i,t);if(r)return r;if(n){const f=di(o,i);for(let h=0;h<4;h++)if(Math.hypot(f[h].x-t.x,f[h].y-t.y)<=lt)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 ns(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 os(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 xi(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 is(e,t,n){const o=e.fmt===2,i=so(t,o),r=o?[t[0],t[1],...i]:t,l=W(r,n);return l||(Kt(n.x,n.y,i)?{hit:"body"}:null)}function rs(e,t){const n=W(e,t);return n||(Kt(t.x,t.y,e)?{hit:"body"}:null)}function te(e,t,n=L){for(let o=1;o<e.length;o++)if(H(t.x,t.y,e[o-1],e[o])<=n)return{hit:"body"};return null}function ls(e,t,n,o,i=L){const r=W(t,n);if(r)return r;const l=Oo(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"}:H(n.x,n.y,s,a)<=i?{hit:"body"}:null}if(l.lineMode){for(let s=1;s<l.line.length;s++)if(H(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 ss(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=Do(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 cs(e,t,n,o,i){const r=W(t,n);if(r)return r;const[l,s]=t,a=zo(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=mn(l,d,o,c);if(H(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(H(n.x,n.y,d,x)<=L)return{hit:"body"};return null}function as(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??Lt).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,m={x:r.x+x/y*f,y:r.y+p/y*f};if(H(n.x,n.y,r,m)<=L)return{hit:"body"}}return H(n.x,n.y,l,s)<=L?{hit:"body"}:null}function fs(e,t,n,o,i){const r=W(t,n);if(r)return r;const[l,s,a]=t;if(H(n.x,n.y,l,s)<=o)return{hit:"body"};if(a&&H(n.x,n.y,s,a)<=o)return{hit:"body"};const c=(e.style.levels??ln).filter(f=>f.visible);for(const f of yo(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 hs(e,t,n){const o=W(t,n);if(o)return o;const i=fo(e,t);if(!i)return null;const r=ho(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 us(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 ds(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(H(n.x,n.y,i,r)<=L)return{hit:"body"};if(H(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??rn).filter(y=>y.visible);for(const y of p)if(Math.abs(u-s*y.coeff)<=L)return{hit:"body"}}return null}function xs(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??dn).filter(f=>f.visible);for(const f of c)if(Math.abs(a-l*f.coeff)<=L)return{hit:"body"};return null}const ye=[0,1,2,3,5,8,13,21,34,55,89];function yi(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*(ye.length-1);for(let c=0;c<=a;c++){const f=c/50,h=Math.floor(f),u=Math.ceil(f);if(u>=ye.length)break;const d=Math.pow(f-h,1.15),x=(ye[h]+(ye[u]-ye[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 pi(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 Tn(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 mi(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),m=f*u*r*(Math.sin(p)-Math.sqrt(3)/2);d.push({x:e.x+l*y-s*m,y:e.y+s*y+l*m})}return d}function An(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 ys=new Set(["triangle-pattern"]);function ps(e,t,n){const o=W(t,n);if(o)return o;const i=Pe(e.style);for(let r=1;r<t.length;r++)if(H(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&&Kt(n.x,n.y,[t[0],t[1],t[2]])?{hit:"body"}:t.length>=5&&Kt(n.x,n.y,[t[2],t[3],t[4]])?{hit:"body"}:null;if(ys.has(e.kind)&&t.length>=3&&Kt(n.x,n.y,t))return{hit:"body"};if(e.kind==="polyline"&&e.closed===!0&&e.style.fillBackground!==!1&&t.length>=2){if(H(n.x,n.y,t[t.length-1],t[0])<=i)return{hit:"body"};if(t.length>=3&&Kt(n.x,n.y,t))return{hit:"body"}}return null}function ms(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)<=lt?{hit:"handle",handleIndex:0}:Math.hypot(e[o].x-t.x,e[o].y-t.y)<=lt?{hit:"handle",handleIndex:o}:te(e,t,n)}function pe(e,t,n,o=L){const i=W(t,n);return i||te(e,n,o)}function bs(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 H(t.x,t.y,r,l)<=o?{hit:"body"}:null}function gs(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 ws(e,t,n,o){var s;const i=W(t,n);if(i)return i;if(t[1]&&H(n.x,n.y,t[0],t[1])<=L)return{hit:"body"};const r=(o==null?void 0:o.pipSize())??.01,l=(s=mo(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 Ms(e,t,n,o,i){const r=vo(e,i,o),l=W(r?r.anchors:t,n);if(l)return l;if(!r)return ui(t,n);const s=[r.center,r.upper,r.lower];for(const a of s)if(a&&H(n.x,n.y,a[0],a[1])<=L)return{hit:"body"};return null}function vs(e,t,n,o){if(Math.hypot(t[0].x-n.x,t[0].y-n.y)<=lt)return{hit:"handle",handleIndex:0};const i=To(e,o);if(i.line.length<2)return hi(t,n);const r=te(i.line,n);if(r)return r;for(const l of i.bands){if(l.upper.length>=2&&pn(e.style,l.index,"upper").visible&&te(l.upper,n))return{hit:"body"};if(l.lower.length>=2&&pn(e.style,l.index,"lower").visible&&te(l.lower,n))return{hit:"body"}}return null}function ks(e,t,n=L){const o=W(e,t);return o||te(Ao(e[0],e[1]),t,n)}function Ls(e,t){const n=e[0];return Math.hypot(n.x-t.x,n.y-t.y)<=lt?{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 Ss(e,t,n,o){if(!e.ghost)return Cn(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(H(n.x,n.y,t[l-1],t[l])<=r)return{hit:"body"};return null}function bi(e,t,n,o,i,r,l=!1){var a;const s=Pe(e.style);switch(e.kind){case"horizontal-line":return _l(t,n,o,s);case"horizontal-ray":return hi(t,n,s);case"vertical-line":return Hl(t,n,i,s);case"cross-line":return Nl(t,n,s);case"arrow-mark-up":case"arrow-mark-down":return ss(e,t,n,e.kind==="arrow-mark-up"?"up":"down");case"font-icon":return _r(t,n);case"table":{const c=gn(e,t[0]),f=W(jo(c),n);if(f)return f;const h=gl(c,n,l);return h?"edge"in h?{hit:"handle",handleIndex:yl(h.edge)}:{hit:"body",cell:h.cell}:null}case"image":{const c=Jo(e,t[0]);if(!c)return null;const f=W(ti(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=li(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 Nt(n,{left:f.x,top:f.y,width:f.w,height:f.h})?{hit:"body"}:null}case"flag-mark":return Ls(t,n);case"trend-line":case"ray":case"extended-line":case"info-line":case"arrow":case"trend-angle":return Vl(e,t,n,o,i);case"arrow-marker":return ui(t,n,s);case"position-forecast":return ks(t,n,s);case"long-position":case"short-position":return Ul(e,t,n,r);case"bar-pattern":return ls(e,t,n,r,s);case"ghost-feed":return Ss(e,t,n,r);case"gann-box":return Cn(t,n);case"gann-fan":return jl(e,t,n,o,i);case"fib-time-zone":return ql(e,t,n,s);case"fib-circles":return Zl(e,t,n);case"fib-speed-resistance-fan":return cs(e,t,n,o,r);case"pitchfan":return as(e,t,n,o);case"fib-wedge":return ds(e,t,n);case"trend-based-fib-time":return fs(e,t,n,s,r);case"gann-square-fixed":case"gann-square":return hs(e,t,n);case"sector":return us(t,n);case"fib-speed-resistance-arcs":return xs(e,t,n);case"fib-spiral":return pe(yi(t[0],t[1],!!e.style.counterclockwise),t,n,s);case"sine-line":return pe(pi(t[0],t[1],o),t,n,s);case"time-cycles":return gs(t,n,o,s);case"cyclic-lines":return bs(t,n,o,s);case"curve":return pe(Tn(t,!!e.style.extendLeft,!!e.style.extendRight),t,n,s);case"arc":return pe((t.length===3?mi(t[0],t[1],t[2]):null)??[t[0],t[1]],t,n,s);case"double-curve":return pe(An(t,!!e.style.extendLeft,!!e.style.extendRight),t,n,s);case"text":{const c=ni(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 Nt(n,c.box)?{hit:"body"}:null}case"comment":{const c=W(t,n);return c||(Nt(n,oi(e,t[0]).l.box)?{hit:"body"}:null)}case"pin":{const c=W(t,n);if(c)return c;const f=ii(e,t[0],o),h=f.marker;return n.x>=h.left&&n.x<=h.right&&n.y>=h.top&&n.y<=h.bottom?{hit:"body"}:l&&Nt(n,{left:f.left,top:f.top,width:f.width,height:f.height})?{hit:"body"}:null}case"signpost":{if(!r)return null;const c=Ln(e,t[0],r,i);return Math.hypot(c.anchor.x-n.x,c.anchor.y-n.y)<=lt?{hit:"handle",handleIndex:0}:H(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"}:Nt(n,c.l.box)?{hit:"body"}:null}case"note":{const c=W(t,n);return c||(t[1]&&H(n.x,n.y,t[0],t[1])<=L?{hit:"body"}:t[1]&&Nt(n,ei(e,e.style,t[0],t[1]).box)?{hit:"body"}:null)}case"price-note":return ws(e,t,n,r);case"callout":{const c=si(e,t[1]);return Math.hypot(t[0].x-n.x,t[0].y-n.y)<=lt?{hit:"handle",handleIndex:0}:l&&c.wrap!=null&&Math.hypot(t[1].x+c.wrap/2+10-n.x,t[1].y-n.y)<=lt?{hit:"handle",handleIndex:1}:Nt(n,{left:c.x,top:c.y,width:c.w,height:c.h})?{hit:"body"}:null}case"regression-trend":return Ms(e,t,n,o,r);case"fixed-range-volume-profile":{const c=W(t,n);if(c)return c;const f=Eo(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=Po(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 vs(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 ps(e,t,n);case"brush":case"highlighter":return ms(t,n,s);case"parallel-channel":return Kl(e,t,n,s,o,i);case"disjoint-channel":return Ql(e,t,n,s,o,i);case"flat-top-bottom":return Jl(e,t,n,s,o,i);case"pitchfork":case"schiff-pitchfork":case"modified-schiff-pitchfork":case"inside-pitchfork":return Xl(e,t,n,o,i);case"fib-channel":return ts(e,t,n,s,o,i);case"rotated-rectangle":return is(e,t,n);case"trend-based-fib-extension":return Gl(e,t,n);case"fib-retracement":return Yl(e,t,n);case"rectangle":{const c=(r==null?void 0:r.timeAxis().width)||o,f=Cn(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=bo(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 ns(t,n);case"ellipse":return es(t,n);case"price-range":return os(e,t,n,o);case"date-range":return xi(t,n);case"date-and-price-range":return xi(t,n);case"triangle":return rs(t,n)}}function Cs(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 St(e,t){if(t>=100)return e;const[n,o,i]=Cs(e);return`rgba(${n}, ${o}, ${i}, ${(t/100).toFixed(2)})`}function Ts(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 ee=(e,t)=>({...e,back:t,color:Ts(t)});function gi(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(ee({time:e.points[0].time},at(o.color).hex)),e.kind==="long-position"||e.kind==="short-position"){if(o.showPriceLabels!==!1){const l=yn(e,t,n);if(l){const s=e.points[0].price,a=e.kind==="long-position"?1:-1;i.push(ee({price:s},"#787b86"),ee({price:s+a*l.profit},"#089981"),ee({price:s-a*l.stop},"#f23645"))}}return{price:i,time:r}}if(e.kind==="anchored-vwap"){if(o.vwapPriceLabel!==!1){const l=ll(e,n);l!=null&&i.push(ee({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(ee({price:l.price},at(o.color).hex));return{price:i,time:r}}let $n=null,Fe=null;function wi(){return $n||($n=document.createElement("canvas").getContext("2d")),$n}function ft(e,t){const n=wi();return n?(Fe??(Fe=getComputedStyle(document.body).fontFamily),n.font=`${t}px ${Fe}`,n.measureText(e).width):e.length*t*.6}function As(e,t){const n=wi();return n?(Fe??(Fe=getComputedStyle(document.body).fontFamily),n.font=`bold ${t}px ${Fe}`,n.measureText(e).width):e.length*t*.65}function mt(e,t){const n=Math.abs(e).toFixed(t);return e<0?`−${n}`:n}function Bn(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 $s(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 me(e){return e.length%2===1&&e[Math.floor(e.length/2)].trim()!==""}function Mi(e,t,n,o,i,r,l,s,a,c,f){const h=Math.max(0,...n.map(g=>Bt(g,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),m=Math.sin(p),b=(g,w)=>({x:(g-e.x)*y-(w-e.y)*m+e.x,y:(g-e.x)*m+(w-e.y)*y+e.y});return[b(d,x),b(d+h,x),b(d+h,x+u),b(d,x+u)]}function X(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 vi(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,m=i.fontSize??14,b=m/3,g=r??(c?b:0),w=l.split(`
|
|
5
|
+
`),M=Math.ceil(m),v=w.length*M+2*b,k=s==="bottom"?x.y-v:s==="top"?x.y:x.y-v/2,S=a==="left"?x.x+g:a==="right"?x.x-g:x.x,C=a==="left"?"start":a==="right"?"end":"middle";return{u:x,angle:y,fs:m,lines:w,lineH:M,top:k+b,x:S,anchor:C,vert:s,horz:a,padV:b,padH:g}}function _e(e,t,n,o,i,r){const l=vi(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 ki(e,t,n,o,i,r,l){const s=vi(e,t,n,o,i,r);return!s||s.vert!=="middle"||!l&&!me(s.lines)?null:Mi(s.u,s.angle,s.lines,s.fs,s.lineH,s.padV,s.padH,s.vert,s.horz,!!i.bold,!!i.italic)}const Yt={rectangle:[4,5,6,7],disjointChannel:[2],parallelChannel:[4,5],position:[1,2,3],single:[0]},Bs=50,Is={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 Li(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(mt(c,h)),o.showPercentPriceRange){const y=l.price!==0?`${mt(c/Math.abs(l.price)*100,2)}%`:"";y&&p.push(o.showPriceRange?`(${y})`:y)}x.push(p.join(" "))}o.showPipsPriceRange&&x.push(mt(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=_(l.time),y=_(s.time),m=p!=null&&y!=null?Bn(y-p):"";m&&(x+=o.showBarsRange?` (${m})`:m)}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 Si(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 Ps(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:Si(e,t,0,0,n,o)}function Ci(e,t,n,o,i,r,l){if(!i||n.length===0)return[];const s=o===3;if(s&&!Ps(e,t,r,l))return[];const a=12,c=18,f=8,h=12;let d=Math.max(...n.map(k=>ft(k.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,m=t.y<e.y&&t.x<e.x||t.y>e.y&&t.x>e.x;let b=y.x+12,g=m?y.y-12-x:y.y+12;s&&(e.x!==t.x||e.y!==t.y)&&(b<0?b=0:b+d>r&&(b=r-d),g<0?g=0:g+x>l&&(g=l-x),Si(e,t,b,g,d,x)&&(g=m?p.y+12:p.y-12-x,b=Math.min(p.x,r)-d));const w=Math.floor(b),M=Math.floor(g),v=[{t:"rect",x:w,y:M,w:d,h:x,rx:4,ry:4,fill:"#464646",fillOpacity:230/255}];return n.forEach((k,S)=>{const C=M+h+S*(c+f);v.push({t:"path",d:Is[k.icon],transform:`translate(${w+h}, ${C})`,fill:"#F9F9F9",fillRule:"evenodd"}),v.push({t:"text",x:w+h+c+h,y:C+c/2,text:k.text,size:a,fill:"#FFFFFF",baseline:"central"})}),[{t:"group",inert:!0,items:v}]}function He(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:He(e,t,n.width),fill:"none",stroke:n.color,strokeWidth:n.width,dash:R(n),join:"round",cap:(n.lineStyle??"solid")==="solid"?"round":"butt",inert:!0}]}function Ti(e){return{...e,horzLabelsAlign:e.horzLabelsAlign??"center",vertLabelsAlign:e.vertLabelsAlign??"bottom"}}function In(e,t,n){return ki(e,t,e,t,Ti(n),(n.fontSize??14)/3,!1)}function ne(e,t){return t&&t.length?{items:[{t:"clip",name:e,polys:[t]}],clip:e}:{items:[],clip:void 0}}function Pn(e,t,n,o,i,r,l,s,a){if(!e.points[0]||!e.points[1])return[];const c=Li(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(..._e(t,n,t,n,Ti(o),(o.fontSize??14)/3)),u.push(...Ci(t,n,c,f,h,i,r)),u}function Es(e,t,n){if(!n.text)return null;const o=n.horzLabelsAlign??"center";return j({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 zs(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=j({...i,x:0}).box.width;return e.x+r+3>=t?j({...i,x:e.x+r+3}):j({...i,x:t,offsetX:3})}return j({...i,x:o==="center"?(e.x+t)/2:e.x})}function En(e,t){return e&&t==="middle"&&me(e.lines)?e.poly:null}const Ct=(e,t)=>({t:"hit",a:e,b:t,width:12}),Ai=e=>(e.lineStyle??"solid")==="solid"?"round":"butt";function Rs(e,t,n,o){const i=e[0],r=Es(i.y,n,o),l=ne("cut",En(r,o.vertLabelsAlign??"middle"));return[Ct({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:R(o),clip:l.clip},...r?[X(r,o.textColor??o.color,o.bold,o.italic)]:[],...t?[{t:"anchors",pts:[{x:.9*n,y:i.y}],squares:Yt.single}]:[]]}function Ws(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?j(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=ne("cut",s?c&&((h=o.text)!=null&&h.trim())?c.poly:null:En(c,r));return[Ct({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:R(o),clip:f.clip},...c?[X(c,o.textColor??o.color,o.bold,o.italic)]:[],...t?[{t:"anchors",pts:[{x:i.x,y:.9*n}],squares:Yt.single}]:[]]}function Os(e,t,n,o,i){const r=e[0],l=R(i);return[Ct({x:0,y:r.y},{x:n,y:r.y}),Ct({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 $i(e,t,n,o,i,r,l,s){const[a,c]=t,f=ne("cut",In(a,c,r));return[Ct(a,c),...f.items,{t:"line",a,b:c,stroke:r.color,strokeWidth:r.width,dash:R(r),cap:Ai(r),clip:f.clip},...Pn(e,a,c,r,o,i,l,s,f.clip),...n?[{t:"anchors",pts:t}]:[]]}function Ne(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,m=(o+i)*2,b=l?{x:f.x-p*m,y:f.y-y*m}:f,g=s?{x:h.x+p*m,y:h.y+y*m}:h,w=ne("cut",In(f,h,r));return[Ct(f,h),...w.items,{t:"line",a:b,b:g,stroke:r.color,strokeWidth:r.width,dash:R(r),clip:w.clip},...Pn(e,f,h,r,o,i,a,c,w.clip),...n?[{t:"anchors",pts:t}]:[]]}function Ds(e,t,n,o){const i=e[0],r=zs(i,n,o),l=ne("cut",En(r,o.vertLabelsAlign??"top"));return[Ct(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:R(o),clip:l.clip},...r?[X(r,o.textColor??o.color,o.bold,o.italic)]:[],...t?[{t:"anchors",pts:[i]}]:[]]}function Fs(e,t,n,o,i,r,l,s){if(e.kind!=="info-line")return[];const[a,c]=t,f=ne("cut",In(a,c,r)),h=Math.hypot(c.x-a.x,c.y-a.y)||1,u=(o+i)*2,d=(c.x-a.x)/h,x=(c.y-a.y)/h,p=r.extendLeft?{x:a.x-d*u,y:a.y-x*u}:a,y=r.extendRight?{x:c.x+d*u,y:c.y+x*u}:c;return[Ct(a,c),...f.items,{t:"line",a:p,b:y,stroke:r.color,strokeWidth:r.width,dash:R(r),cap:"round",clip:f.clip},...Pn(e,a,c,r,o,i,l,s,f.clip),...n?[{t:"anchors",pts:t}]:[]]}function _s(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=Bs,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}`,m=r.fontSize??12,b=Math.hypot(f,h)||1,g=(o+i)*2,w=r.extendLeft?{x:a.x-f/b*g,y:a.y-h/b*g}:a,M=r.extendRight?{x:c.x+f/b*g,y:c.y+h/b*g}:c;return[Ct(a,c),{t:"line",a:w,b:M,stroke:r.color,strokeWidth:r.width,dash:R(r),cap:Ai(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+m/3,y:a.y,text:`${Math.round(u*100)/100}º`,size:m,anchor:"start",baseline:"central",weight:r.bold?700:400,fontStyle:r.italic?"italic":"normal",fill:r.color,inert:!0},...Ci(a,c,Li(e,a,c,r,l,!1),r.statsPosition??2,s||!!r.showStats,o,i),...n?[{t:"anchors",pts:t}]:[]]}function Tt(e,t){return(e.levels??t).filter(n=>n.visible).slice().sort((n,o)=>n.coeff-o.coeff)}function K(e){return e.fillBackground===!1?0:Math.max(0,Math.min(1,(100-(e.transparency??80))/100))}function bt(e,t){return e.width??t.width}function gt(e,t){return e.style?R({...t,lineStyle:e.style}):R(t)}function Ye(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 Hs(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 Ns(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 Vs(e,t,n,o,i){const[r,l]=e,{anchors:s,dy:a}=Hs(e),c=(n.levels??Be).filter(b=>b.visible),f=(o+i)*2,h=b=>Ye({x:r.x,y:r.y+a*b},{x:l.x,y:l.y+a*b},!!n.extendLeft,!!n.extendRight,f),u=K(n),d=n.backgroundColor??n.color,x=Ys(r,l,a,c,n),p=ki(x.e,x.t,x.i,x.n,n,void 0,!0),y=p&&p.length?"cut":void 0,m=[];y&&m.push({t:"clip",name:y,polys:[p]}),c.slice(1).forEach((b,g)=>{const w=h(c[g].coeff),M=h(b.coeff);m.push({t:"polygon",pts:[w.l,w.r,M.r,M.l],fill:d,fillOpacity:u,stroke:"transparent"})});for(const b of c){const g=h(b.coeff);m.push({t:"hit",a:g.l,b:g.r,width:12}),m.push({t:"line",a:g.l,b:g.r,stroke:b.color,strokeWidth:bt(b,n),dash:gt(b,n),clip:y})}return m.push(..._e(x.e,x.t,x.i,x.n,n)),t&&m.push({t:"anchors",pts:s,squares:Yt.parallelChannel}),m}function Bi(e,t,n,o,i){const r=(s,a,c)=>j({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[X(r(e,t,n),l,i.priceLabelBold,i.priceLabelItalic),X(r(t,e,o),l,i.priceLabelBold,i.priceLabelItalic)]}function Ii(e,t,n,o,i,r,l,s,a,c,f){var g,w;const h=(a+c)*2,u=Ye(t,n,!!s.extendLeft,!!s.extendRight,h),d=Ye(o,i,!!s.extendLeft,!!s.extendRight,h),x=R(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)))),m=M=>M.toFixed(y),b=[];return s.fillBackground!==!1&&b.push({t:"polygon",pts:[u.l,u.r,d.r,d.l],fill:s.backgroundColor??s.color,fillOpacity:K(s),stroke:"transparent"}),b.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&&b.push(...Et(n,t,s),...Et(i,o,s)),s.rightEnd===1&&b.push(...Et(t,n,s),...Et(o,i,s)),s.showPrices&&(b.push(...Bi(t,n,m(((g=e.points[0])==null?void 0:g.price)??0),m(((w=e.points[1])==null?void 0:w.price)??0),s)),b.push(...Bi(i,o,m(r),m(l),s))),b}function Us(e,t,n,o,i,r,l){var d,x;const[s,a]=t,{anchors:c,P:f,A:h}=Ns(t),u=((d=e.points[2])==null?void 0:d.price)??e.points[0].price;return[...Ii(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),..._e(s,a,h,f,o),...n?[{t:"anchors",pts:c,squares:Yt.disjointChannel}]:[]]}function Xs(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[...Ii(e,s,a,f,h,u,u,o,i,r,l),..._e(s,a,f,h,o),...n?[{t:"anchors",pts:t}]:[]]}function zn(e,t){return t?`${(100*e).toFixed(2)}%`:String(Math.round(e*1e4)/1e4)}function Ve(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"),j({x:t,y:e.y,text:e.text,fs:e.fs,vert:e.vert,horz:n,offsetX:4})}function zt(e){return e.toFixed(3).replace(/0+$/,"").replace(/\.$/,"")||"0"}const ct=(e,t)=>e?[{t:"anchors",pts:t}]:[],Rn=e=>Math.max(0,Math.min(8,Math.round(-Math.log10((e==null?void 0:e.pipSize())??.01))));function Wn(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 Vt(e,t,n,o=!1){const i=n.fibTrendLine??(o?Er:Pr);return i.visible?[{t:"line",a:e,b:t,stroke:i.color,strokeWidth:i.width,dash:R({...n,lineStyle:i.style}),cap:i.style==="solid"?"round":"butt",inert:!0}]:[]}function Pi(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+=zn(t.coeff,!!s.fibLevelsAsPercents)),h&&(u+=` (${r.toFixed(l)})`);const d=Ve({...c,text:u,horz:s.horzLabelsAlign??"left",vert:s.vertLabelsAlign??"middle"}),x=s.showText!==!1&&t.text?Ve({...c,text:t.text,horz:s.horzTextAlign??"center",vert:s.vertTextAlign??"middle"}):null,p=Wn(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:bt(t,s),dash:gt(t,s),clip:p.clip},...d?[X(d,t.color)]:[],...x?[X(x,t.color)]:[]]}function Ei(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 Gs(e,t,n,o,i){const r=e.style;let l=null,s=0,a=0;if(e.kind==="fib-retracement"&&t.length>=2){const[p,y]=t,m=e.points[0].price,b=e.points[1].price;s=r.extendLeft?0:Math.min(p.x,y.x),a=r.extendRight?o:Math.max(p.x,y.x);const g=!!r.fibLevelsBasedOnLogScale&&!!(i!=null&&i.isLog())&&m>0&&b>0,w=v=>{const k=r.reverse?m:b,S=r.reverse?b:m;return g?Math.exp(Math.log(k)+v*(Math.log(S)-Math.log(k))):k+v*(S-k)},M=v=>r.reverse?p.y+(y.y-p.y)*v:y.y+(p.y-y.y)*v;l=v=>g?M(v):(i==null?void 0:i.priceToY(w(v)))??M(v)}else if(e.kind==="trend-based-fib-extension"&&t.length>=3&&e.points.length>=3){const[,p,y]=t,m=e.points[0].price,b=e.points[1].price,g=e.points[2].price,w=r.reverse?m-b:b-m,M=r.reverse?t[0].y-t[1].y:t[1].y-t[0].y;s=r.extendLeft?0:Math.min(p.x,y.x),a=r.extendRight?o:Math.max(p.x,y.x);const v=!!r.fibLevelsBasedOnLogScale&&!!(i!=null&&i.isLog())&&m>0&&b>0&&g>0,k=C=>{if(!v)return g+w*C;const I=r.reverse?Math.log(m)-Math.log(b):Math.log(b)-Math.log(m);return Math.exp(Math.log(g)+C*I)},S=C=>y.y+M*C;l=C=>v?S(C):(i==null?void 0:i.priceToY(k(C)))??S(C)}if(!l||n.x<s-L||n.x>a+L)return null;const c=r.levels??$t;let f=null;if(c.forEach((p,y)=>{if(!p.visible)return;const m=l(p.coeff),b=Math.abs(n.y-m);b<=6&&(!f||b<f.dist)&&(f={index:y,y:m,dist:b})}),!f)return null;const{index:h,y:u}=f,d=r.horzTextAlign??"center",x=d==="left"?s:d==="right"?a:(s+a)/2;return{index:h,y:u,left:s,right:a,textX:x}}function js(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=Tt(i,$t),d=!!i.fibLevelsBasedOnLogScale&&!!(r!=null&&r.isLog())&&a>0&&c>0,x=b=>{const g=i.reverse?a:c,w=i.reverse?c:a;return d?Math.exp(Math.log(g)+b*(Math.log(w)-Math.log(g))):g+b*(w-g)},p=b=>i.reverse?l.y+(s.y-l.y)*b:s.y+(l.y-s.y)*b,y=b=>d?p(b):(r==null?void 0:r.priceToY(x(b)))??p(b),m=Rn(r);return[...Ei(u,y,f,h,K(i)),...u.flatMap((b,g)=>Pi(`l${g}`,b,y(b.coeff),f,h,x(b.coeff),m,i,o)),...Vt(l,s,i),...ct(n,t)]}function qs(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=Tt(i,$t),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,m=M=>{if(!y)return f+h*M;const v=i.reverse?Math.log(a)-Math.log(c):Math.log(c)-Math.log(a);return Math.exp(Math.log(f)+M*v)},b=M=>s.y+u*M,g=M=>y?b(M):(r==null?void 0:r.priceToY(m(M)))??b(M),w=Rn(r);return[...Ei(d,g,x,p,K(i)),...d.flatMap((M,v)=>Pi(`l${v}`,M,g(M.coeff),x,p,m(M.coeff),w,i,o)),...Vt(t[0],t[1],i),...Vt(t[1],t[2],i),...ct(n,t)]}function Zs(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 v=d(M);return Ye(v.l,v.r,!!o.extendLeft,!!o.extendRight,u)},p=Tt(o,$t),y=K(o),m=Rn(i),b=(M,v)=>(i==null?void 0:i.yToPrice(v))??e.points[0].price+(e.points[2].price-e.points[0].price)*M,g=(M,v)=>{const k=o.showCoeffs!==!1,S=o.showPrices!==!1;if(!k&&!S)return null;let C="";k&&(C+=o.fibLevelsAsPercents?`${(100*M.coeff).toFixed(2)}%`:zt(M.coeff)),S&&(C+=` (${b(M.coeff,v.l.y).toFixed(m)})`);const I=o.horzLabelsAlign??"left",A=I==="left"?v.l:I==="right"?v.r:{x:(v.l.x+v.r.x)/2,y:(v.l.y+v.r.y)/2};return j({x:A.x,y:A.y,text:C,fs:o.labelFontSize??12,vert:o.vertLabelsAlign??"middle",horz:I==="left"?"right":I==="right"?"left":"center",offsetX:4})},w=[];return y>0&&p.slice(1).forEach((M,v)=>{const k=x(p[v].coeff),S=x(M.coeff);w.push({t:"polygon",pts:[k.l,k.r,S.r,S.l],fill:p[v].color,fillOpacity:y,stroke:"none",inert:!0})}),p.forEach((M,v)=>{const k=d(M.coeff),S=x(M.coeff),C=g(M,k),I=Wn(`l${v}`,[C?C.poly:null]);w.push({t:"hit",a:k.l,b:k.r,width:12},...I.items),w.push({t:"line",a:S.l,b:S.r,stroke:M.color,strokeWidth:bt(M,o),dash:gt(M,o),clip:I.clip}),C&&w.push(X(C,M.color))}),w.push(...ct(n,t)),w}function zi(e,t,n,o,i,r,l){const s=Wn(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:bt(t,i),dash:gt(t,i),clip:s.clip},...r?[X(r,t.color)]:[]]}function Ks(e,t,n,o,i,r){const[l,s,a]=t,c=i.fibTrendLine??sn,f=R({...i,lineStyle:c.style,width:c.width}),h=yo(e,t,r,Tt(i,ln)),u=K(i),d=i.vertLabelsAlign??"bottom",x=i.horzLabelsAlign??"right",p=x==="left"?"right":x==="right"?"left":"center",y=(b,g)=>i.showLabels===!1?null:j({x:b,y:d==="top"?0:d==="middle"?.5*o:o,text:String(g),fs:12,vert:d,horz:p,offsetX:2}),m=[];return c.visible&&(m.push({t:"line",a:l,b:s,stroke:c.color,strokeWidth:c.width,dash:f}),a&&m.push({t:"line",a:s,b:a,stroke:c.color,strokeWidth:c.width,dash:f})),u>0&&h.slice(1).forEach((b,g)=>{const w=h[g].x;m.push({t:"rect",x:Math.min(w,b.x),y:0,w:Math.max(1,Math.abs(b.x-w)),h:o,fill:b.color,fillOpacity:u,stroke:"none",inert:!0})}),h.forEach((b,g)=>{const w=y(b.x,b.coeff);m.push(...zi(`l${g}`,b,b.x,o,i,w,w&&x==="center"?w.poly:null))}),m.push(...ct(n,t)),m}function Qs(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:j({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=Tt(o,hn),u=K(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,m=i.x+f*x.coeff;d.push({t:"rect",x:Math.min(y,m),y:0,w:Math.max(1,Math.abs(m-y)),h:n,fill:x.color,fillOpacity:u,stroke:"none",inert:!0})}),h.forEach((x,p)=>{const y=i.x+f*x.coeff,m=c(y,x.coeff);d.push(...zi(`l${p}`,x,y,n,o,m,m&&l==="middle"&&me(m.lines)?m.poly:null))}),d.push(...ct(t,e)),d}const Js=[.236,.382,.5,.618,1];function tc(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=R(o);return[...Js.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??xn).filter(x=>x.visible),h=K(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?Ve({text:zn(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:bt(x,o),dash:gt(x,o)}),p&&d.push(X(p,x.color))}return d.push(...Vt(i,r,o),...ct(n,t)),d}function ec(e,t,n,o,i,r,l){const[s,a]=t,c=zo(e,t,l,Te),f=R(r),h=K(r),u=c.h.map(k=>({color:k.color,far:mn(s,{x:a.x,y:k.y},o,i)})),d=c.v.map(k=>({color:k.color,far:mn(s,{x:k.x,y:a.y},o,i)})),x=k=>k.slice(1).map((S,C)=>({color:S.color,pts:[s,S.far,k[C].far]})),{left:p,top:y,right:m,bottom:b}=c.box,g=r.fanGrid??eo,w=R({...r,lineStyle:g.style,width:g.width}),M=(k,S,C,I,A,O,F)=>j({x:k,y:S,text:zt(C),fs:12,vert:I,horz:A,offsetX:O,offsetY:F}),v=[];if(h>0)for(const k of[...x(u),...x(d)])v.push({t:"polygon",pts:k.pts,fill:k.color,fillOpacity:h,stroke:"none",inert:!0});for(const k of c.h)g.visible&&v.push({t:"line",a:{x:p,y:k.y},b:{x:m,y:k.y},stroke:g.color,strokeWidth:g.width,dash:w,inert:!0}),r.showLeftLabels!==!1&&v.push(X(M(p,k.y,k.coeff,"middle","right",5,0),k.color)),r.showRightLabels!==!1&&v.push(X(M(m,k.y,k.coeff,"middle","left",5,0),k.color));for(const k of c.v)g.visible&&v.push({t:"line",a:{x:k.x,y},b:{x:k.x,y:b},stroke:g.color,strokeWidth:g.width,dash:w,inert:!0}),r.showTopLabels!==!1&&v.push(X(M(k.x,y,k.coeff,"bottom","center",0,5),k.color)),r.showBottomLabels!==!1&&v.push(X(M(k.x,b,k.coeff,"top","center",0,5),k.color));for(const k of[...u,...d])v.push({t:"hit",a:s,b:k.far,width:L*2}),v.push({t:"line",a:s,b:k.far,stroke:k.color,strokeWidth:r.width,dash:f,cap:"round"});return v.push(...ct(n,t)),v}function nc(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=R(n),a=Tt(n,dn),c=K(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,m=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:m,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:bt(d,n),dash:gt(d,n)??s}),n.showCoeffs!==!1){const p=Ve({text:zn(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(X(p,d.color))}}u.push(...Vt(o,i,n))}return u.push(...ct(t,e)),u}function oc(e,t,n,o,i){const[r,l]=e,s=yi(r,l,!!i.counterclockwise),a=R(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 ic(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=R(n),u=Tt(n,rn),d=K(n),x=24,p=m=>{const b=[];for(let g=0;g<=x;g++){const w=s+f*g/x;b.push({x:o.x+Math.cos(w)*m,y:o.y+Math.sin(w)*m})}return b},y=[{t:"hit",a:o,b:i,width:12},{t:"hit",a:o,b:c,width:12}];d>0&&u.slice(1).forEach((m,b)=>{const g=p(l*m.coeff),w=p(l*u[b].coeff).reverse();y.push({t:"polygon",pts:[...g,...w],fill:m.color,fillOpacity:d,stroke:"none",inert:!0})}),y.push(...Vt(o,i,n,!0),...Vt(o,c,n,!0));for(const m of u){const b=l*m.coeff,g=s+f/2;y.push({t:"polyline",pts:p(b),fill:"none",stroke:m.color,strokeWidth:bt(m,n),dash:gt(m,n)??h}),n.showCoeffs!==!1&&y.push({t:"text",x:o.x+Math.cos(g)*(b+8),y:o.y+Math.sin(g)*(b+8),text:zt(m.coeff),size:11,fill:m.color,anchor:"middle",inert:!0})}return y.push(...ct(t,e)),y}function rc(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=R(o),f=Tt(o,Lt),h=K(o),u=n*4,d=y=>{const m=y.x-i.x,b=y.y-i.y,g=Math.hypot(m,b)||1;return{x:i.x+m/g*u,y:i.y+b/g*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,lvl:y})),{t:s,color:o.color},...f.map(y=>({t:{x:s.x+a.x*y.coeff,y:s.y+a.y*y.coeff},color:y.color,lvl:y}))],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,m)=>p.push({t:"polygon",pts:[i,d(x[m].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.lvl?bt(y.lvl,o):o.width,dash:y.lvl?gt(y.lvl,o):c});return p.push(...ct(t,e)),p}const be=(e,t)=>e?[{t:"anchors",pts:t}]:[];function lc(e,t,n,o,i){var b;const r=fo(e,t);if(!r)return be(n,t);const l=o.gannLevels??cn,s=Gr(r,l),a=jr(r,o.gannFans??an),c=qr(r,o.gannArcs??fn),f=ho(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[g,w]=e.points,M=i.timeToBarIndex(g.time),v=i.timeToBarIndex(w.time);if(M==null||v==null)return[];const k=o.reverse?-1:1,S=(w.price-g.price)*k,C=(v-M)*k,I=Math.max(0,Math.min(8,Math.round(-Math.log10(i.pipSize())))),A=o.labelFontSize??12,O=(T,z,P,B,D,U)=>j({x:T,y:z,text:P,fs:A,bold:o.bold,italic:o.italic,horz:B,vert:D,offsetX:10,offsetY:U}),F=[O(r.start.x,r.end.y,mt(S,I),C>0?"right":"left",S>0?"bottom":"top",S>0?8:10),O(r.end.x,r.start.y,String(C),C>0?"left":"right",S>0?"top":"bottom",S>0?10:8)];return C!==0&&F.push(O(r.end.x,r.end.y,String(Number(Math.abs(S/C).toFixed(7))),C>0?"left":"right",S>0?"bottom":"top",S>0?8:10)),F})(),d=((b=l[l.length-1])==null?void 0:b.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 g of s)y.push({t:"line",a:{x:g.x,y:r.start.y},b:{x:g.x,y:r.end.y},stroke:g.color,strokeWidth:g.width,inert:!0}),y.push({t:"line",a:{x:r.start.x,y:g.y},b:{x:r.end.x,y:g.y},stroke:g.color,strokeWidth:g.width,inert:!0});for(const g of a)y.push({t:"line",a:g.from,b:g.to,stroke:g.color,strokeWidth:g.width,cap:"round",inert:!0});const m=[];for(const g of c){const w=Zr(r,g.r,g.prev);h>0&&m.push({t:"path",d:w.fill,fill:g.color,fillOpacity:h,stroke:"none"}),m.push({t:"path",d:w.stroke,fill:"none",stroke:g.color,strokeWidth:g.width})}y.push({t:"group",clip:"box",inert:!0,items:m});for(const g of u)y.push(X(g,d,o.bold,o.italic));return y.push(...be(n,t)),y}function sc(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??on).map((m,b)=>({...m,index:b+1})).filter(m=>m.visible),h=K(i),u=m=>m>1?{x:l.x,y:r.y+c/m}:{x:r.x+a*m,y:l.y},d=m=>{const b=uo(r,l,m),g=Math.hypot(b.x,b.y)||1;return{x:r.x+b.x/g*s,y:r.y+b.y/g*s}},x=[];f.forEach((m,b)=>{m.index<4&&b<f.length-1?x.push({from:m.coeff,to:f[b+1].coeff,color:m.color}):m.index>4&&b>0&&x.push({from:m.coeff,to:f[b-1].coeff,color:m.color})});const p=12/3,y=[{t:"hit",a:r,b:l,width:12}];for(const m of f)y.push({t:"hit",a:r,b:d(m.coeff),width:L*2});if(h>0)for(const m of x)y.push({t:"polygon",pts:[r,d(m.from),d(m.to)],fill:m.color,fillOpacity:h,stroke:"none",inert:!0});for(const m of f){const b=d(m.coeff),g=u(m.coeff);y.push({t:"line",a:r,b,stroke:m.color,strokeWidth:bt(m,i),dash:gt(m,i)}),i.showLabels!==!1&&y.push({t:"text",x:g.x+p,y:g.y,text:m.label??zt(m.coeff),size:12,fill:m.color,anchor:"start",baseline:"central",inert:!0})}return y.push(...be(t,e)),y}function cc(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=yt(r,l),u=o.levels??Ae,d=o.vLevels??Ae,x=R(o),[p,y]=e.points,m=!!o.reverse,b=T=>{const z=m?y.price:p.price,P=m?p.price-y.price:y.price-p.price;return(i==null?void 0:i.priceToY(z+T*P))??(m?l.y+T*(r.y-l.y):r.y+T*(l.y-r.y))},g=(i==null?void 0:i.timeToBarIndex(p.time))??null,w=(i==null?void 0:i.timeToBarIndex(y.time))??null,M=T=>{if(i&&g!=null&&w!=null){const z=m?w:g,P=m?g-w:w-g,B=i.barIndexToTime(Math.round(z+T*P)),D=B!=null?i.timeToX(B):null;if(D!=null)return D}return m?l.x+T*(r.x-l.x):r.x+T*(l.x-r.x)},v=u.filter(T=>T.visible).map(T=>({...T,y:b(T.coeff)})),k=d.filter(T=>T.visible).map(T=>({...T,x:M(T.coeff)})),S=o.fillBackground!==!1?Math.max(0,Math.min(1,(100-(o.transparency??80))/100)):0,C=o.fillVertBackground!==!1?Math.max(0,Math.min(1,(100-(o.vertTransparency??80))/100)):0,I=o.fans??{visible:!1,color:"#9C9C9C"},A=[];if(I.visible)for(let T=0;T<u.length;T++){const z=M(u[T].coeff);A.push([{x:s,y:f},{x:z,y:c}],[{x:a,y:f},{x:z,y:c}],[{x:s,y:c},{x:z,y:f}],[{x:a,y:c},{x:z,y:f}]);const P=d[T];if(!P)continue;const B=b(P.coeff);A.push([{x:s,y:f},{x:a,y:B}],[{x:a,y:f},{x:s,y:B}],[{x:s,y:c},{x:a,y:B}],[{x:a,y:c},{x:s,y:B}])}const O=(T,z,P,B,D,U,J,Mt)=>X(j({x:T,y:z,text:P,fs:12,horz:D,vert:U,offsetX:J,offsetY:Mt}),B),F=[{t:"rect",x:s,y:c,w:Math.max(1,a-s),h:Math.max(1,f-c),fill:"transparent"}];v.forEach((T,z)=>{z>0&&S>0&&F.push({t:"rect",x:s,y:Math.min(T.y,v[z-1].y),w:a-s,h:Math.abs(T.y-v[z-1].y),fill:T.color,fillOpacity:S,inert:!0}),F.push({t:"line",a:{x:s,y:T.y},b:{x:a,y:T.y},stroke:T.color,strokeWidth:o.width,dash:x}),o.showLeftLabels!==!1&&F.push(O(s,T.y,zt(T.coeff),T.color,"right","middle",5,0)),o.showRightLabels!==!1&&F.push(O(a,T.y,zt(T.coeff),T.color,"left","middle",5,0))}),k.forEach((T,z)=>{z>0&&C>0&&F.push({t:"rect",x:Math.min(T.x,k[z-1].x),y:c,w:Math.abs(T.x-k[z-1].x),h:f-c,fill:T.color,fillOpacity:C,inert:!0}),F.push({t:"line",a:{x:T.x,y:c},b:{x:T.x,y:f},stroke:T.color,strokeWidth:o.width,dash:x}),o.showTopLabels!==!1&&F.push(O(T.x,c,zt(T.coeff),T.color,"center","bottom",0,3)),o.showBottomLabels!==!1&&F.push(O(T.x,f,zt(T.coeff),T.color,"center","top",0,5))});for(const[T,z]of A)F.push({t:"line",a:T,b:z,stroke:I.color,strokeWidth:o.width,dash:x,inert:!0});return F.push(...be(n,h)),F}function ac(e,t,n,o,i){const r=xo(e,t);if(!r)return[];const l=Qt(r.pivot,r.dir,o),s=Math.hypot(r.dir.x,r.dir.y)||1,a=m=>i.extendLines?{x:m.x-r.dir.x/s*o*4,y:m.y-r.dir.y/s*o*4}:m,c=R(i),f=Tt(i,Lt),h=K(i),u=(m,b)=>({x:r.mid.x+r.half.x*m*b,y:r.mid.y+r.half.y*m*b}),d=[];let x=0;for(const m of f)d.push({from:x,to:m.coeff,color:m.color}),x=m.coeff;const p=[1,-1],y=[{t:"hit",a:r.pivot,b:l,width:L*2}];for(const m of p)for(const b of f){const g=u(b.coeff,m);y.push({t:"hit",a:g,b:Qt(g,r.dir,o),width:L*2})}if(h>0)for(const m of p)for(const b of d){const g=u(b.from,m),w=u(b.to,m);y.push({t:"polygon",pts:[a(g),Qt(g,r.dir,o),Qt(w,r.dir,o),a(w)],fill:b.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 m of p)for(const b of f)y.push({t:"line",a:a(u(b.coeff,m)),b:Qt(u(b.coeff,m),r.dir,o),stroke:b.color,strokeWidth:bt(b,i),dash:gt(b,i),cap:"round"});return y.push(...be(n,t)),y}const fc=.06;function Ue(e,t){const n=fe(e);return t&&n.fillOpacity>0?{fill:n.fill,fillOpacity:Math.min(1,n.fillOpacity+fc)}:n}function Ri(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 hc(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 On=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 uc(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=Ue(i,r),d=bo(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:R(i)}];if(x!=null&&x.visible){const y=d&&(i.vertLabelsAlign??"middle")==="middle"&&me(d.lines)?d.poly:null,m=y&&y.length?"mid":void 0;m&&p.push({t:"clip",name:m,polys:[y]});const b=Math.floor((f+h)/2);p.push({t:"line",a:{x:a,y:b},b:{x:c,y:b},stroke:x.color,strokeWidth:x.width,dash:R({...i,lineStyle:x.style,width:x.width}),cap:"butt",clip:m,inert:!0})}return d&&p.push(X(d,i.textColor??i.color,i.bold,i.italic)),p.push(...ht(n,[...yt(l,s),...di(l,s)],Yt.rectangle)),p}function dc(e,t,n,o){const i=e.fmt===2,r=so(t,i),l=fe(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:R(o),join:"round"},...ht(n,s)]}function xc(e,t,n,o,i){const[r,l]=t,s=Math.hypot(l.x-r.x,l.y-r.y),a=Ue(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:R(o)},...Ri(e,r.x,r.y,o),...ht(n,t)]}function yc(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=Ue(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:R(o)}]},...Ri(e,a,c,o),...ht(n,t)]}function pc(e,t,n,o){const i=Ue(n,o);return[{t:"polygon",pts:e,fill:i.fill,fillOpacity:i.fillOpacity,stroke:n.color,strokeWidth:n.width,dash:R(n),join:"round"},...ht(t,e)]}function mc(e,t,n){const[o,i]=e,r=R(n),l=e.length===3?mi(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=On(l),a=fe(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 Wi(e,t,n,o,i,r){const l=[];if(n.fillBackground){const s=fe(n);l.push({t:"path",d:On(i)+" Z",fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"})}if(l.push({t:"path",d:On(o),fill:"none",stroke:n.color,strokeWidth:n.width,dash:R(n),cap:"round"}),l.push(...hc(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 bc(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=Tn(o,!!n.extendLeft,!!n.extendRight),a=n.extendLeft||n.extendRight?Tn(o):s;return Wi(e,t,n,s,a,[[i,r],[l,r]])}function gc(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=An(o,!!n.extendLeft,!!n.extendRight),c=n.extendLeft||n.extendRight?An(o):a;return Wi(e,t,n,a,c,[[i,r],[s,l]])}function wc(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 Mc(e,t,n,o,i){const[r,l]=e,s=l.x-r.x,a=R(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 vc(e,t,n,o){const i=pi(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:R(o)}),r.push(...ht(t,e)),r}function kc(e,t,n,o){const[i,r]=e,l=Math.abs(r.x-i.x),s=l/2,a=R(o),c=fe(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 Dn={"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"]},Lc=new Set(["polyline"]),Sc=[{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}],Cc={"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"]},Oi=["0","i","ii","iii","iv","v"];function Tc(e,t){const n=Cc[e]??[];return e==="elliott-impulse"?t===1?Oi:t===3?Oi.map(o=>o.toUpperCase()):n:t%2===1?n.map(o=>o.toLowerCase()):n}function Ac(e,t,n,o){const r=14-Math.max(0,Math.min(14,Math.round(o.elliottDegree??zr))),l=Math.floor(r/3),s=["","brackets","circle"][r%3],a=Sc[l],c=Tc(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:R(o),join:"round",cap:"round"}),t.forEach((x,p)=>{if(p===0&&!n)return;const y=x.y+(u(p)===1?f:-f),m=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"?`(${m})`:m,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 Di(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 Xe(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 wt(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 Fn(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 oe(e,t,n,o,i,r){return[...Fn(e[t],e[n],r.bg,o),Xe((e[t].x+e[n].x)/2,(e[t].y+e[n].y)/2,0,i,r)]}const ie=e=>({bg:e.color,fg:e.textColor??"#ffffff",fontSize:e.fontSize??12,bold:e.bold,italic:e.italic});function Fi(e,t,n){const o=ie(n),i=[];return e.forEach((r,l)=>{t[l]&&i.push(Xe(r.x,r.y,Di(e,l)<0?-5:5,t[l],o))}),i}const ge=e=>({t:"polyline",pts:e,fill:"none",stroke:"transparent",strokeWidth:L*2});function $c(e,t,n,o){const i=ie(o),r=e.points.map(s=>s.price),l=[ge(t),{t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:R(o),join:"round"}];return t.length>=3&&l.push(...oe(t,0,2,o.width,wt(r[0],r[1],r[2],3),i)),t.length>=4&&l.push(...oe(t,1,3,o.width,wt(r[1],r[2],r[3],3),i)),l.push(...Fi(t,Dn[e.kind],o)),n&&l.push({t:"anchors",pts:t}),l}function Bc(e,t,n,o){const i=e.kind==="cypher-pattern",r=ie(o),l=o.backgroundColor??o.color,s=o.fillBackground===!1?0:K(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(ge(t),{t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:R(o),join:"round"}),t.length>=3&&c.push(...oe(t,0,2,1,wt(a[0],a[1],a[2],3),r)),t.length>=4&&c.push(...oe(t,1,3,1,i?wt(a[1],a[0],a[3],3):wt(a[1],a[2],a[3],3),r)),t.length>=5){const f=i?wt(a[0],a[2],a[4],3):wt(a[0],a[1],a[4],3);c.push(...Fn(t[0],t[4],o.color,1),...Fn(t[2],t[4],o.color,1),Xe((t[2].x+t[4].x)/2,(t[2].y+t[4].y)/2,0,wt(a[2],a[3],a[4],3),r),Xe((t[0].x+t[4].x)/2,(t[0].y+t[4].y)/2,0,f,r))}return c.push(...Fi(t,Dn[e.kind],o)),n&&c.push({t:"anchors",pts:t}),c}function Ic(e,t,n,o){const i=ie(o),r=e.points.map(s=>s.price),l=[ge(t),{t:"polyline",pts:t,fill:"none",stroke:o.color,strokeWidth:o.width,dash:R(o),join:"round"}];return t.length>=4&&l.push(...oe(t,1,3,o.width,wt(r[1],r[2],r[3],2),i)),t.length>=6&&l.push(...oe(t,3,5,o.width,wt(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=Bt(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 Pc(e,t,n){const[o,i,r,l]=e,s=ie(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=[ge(e)];return a&&c.push({t:"polygon",pts:a,fill:n.fillBackground===!1?"none":n.backgroundColor??n.color,fillOpacity:K({...n,transparency:n.transparency??85}),stroke:n.color,strokeWidth:n.width,dash:R({...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 _i(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 Ec(e,t,n){const o=K({...n,transparency:n.transparency??85}),i=n.backgroundColor??n.color,[r,l,s,a,c,f,h]=e,u=_i(s,c,r,l),d=_i(s,c,f,h),x=(b,g)=>({x:b.x+(g.x-b.x)*10,y:b.y+(g.y-b.y)*10}),p=ie(n),y=(b,g,w)=>({t:"polygon",pts:[b,g,w],fill:i,fillOpacity:o,stroke:"none",inert:!0}),m=[ge(e)];return n.fillBackground!==!1&&(m.push(y(s,a,c)),u&&m.push(y(u,l,s)),d&&m.push(y(c,f,d))),m.push({t:"line",a:u??x(c,s),b:d??x(s,c),stroke:n.color,strokeWidth:n.width,dash:R({...n,lineStyle:"dotted"}),inert:!0},{t:"polyline",pts:e,fill:"none",stroke:n.color,strokeWidth:n.width,dash:R(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&&m.push({t:"anchors",pts:e}),m}function zc(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 Rc(e,t,n,o){if(e.kind==="triangle-pattern"&&t.length>=4)return Pc(t,n,o);if(e.kind==="head-and-shoulders"&&t.length>=7)return Ec(t,n,o);if(e.kind==="abcd-pattern"&&t.length>=2)return $c(e,t,n,o);if((e.kind==="xabcd-pattern"||e.kind==="cypher-pattern")&&t.length>=2)return Bc(e,t,n,o);if(e.kind==="three-drives-pattern"&&t.length>=2)return Ic(e,t,n,o);if(e.kind.startsWith("elliott-"))return Ac(e,t,n,o);const i=Dn[e.kind],r=Lc.has(e.kind)&&e.closed===!0,l=e.kind==="highlighter",s=e.kind==="brush"||l,a=o.width,c=s?zc(t):t,f=s?void 0:R(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?K(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:K(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 m=Math.hypot(y.x-p.x,y.y-p.y),g=(o.lineStyle??"solid")==="solid"&&m>=1?{x:p.x+(y.x-p.x)*(m+o.width/2)/m,y:p.y+(y.y-p.y)*(m+o.width/2)/m}:y;return{t:"path",d:He(p,g,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+Di(t,x),text:i[x]??String(x+1),size:11,fill:o.color,anchor:"middle"})}),n&&u.push({t:"anchors",pts:h}),u}function Wc(e){return e<92?18:Math.min(Math.max(e*.25,18),106,e*.9)}function Oc(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,F)=>n.text?[{t:"text",x:A,y:O,text:n.text,anchor:F,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=Wc(h),m=h>=35?.1:0,b=[{x:0,y:0},{x:h-y+y*m,y:1.22*y/4},{x:h-y,y:1.22*y/2},{x:h,y:0}],g=(A,O)=>({x:a.x+u*A.x+x*A.y*O,y:a.y+d*A.x+p*A.y*O}),w=[...b.map(A=>g(A,1)),...b.slice(0,b.length-1).reverse().map(A=>g(A,-1))],M=Math.min(5,Math.max(2,Math.round(.02*h))),v=Math.atan2(c,f);let k=o.x,S=o.y,C="middle";v>-Math.PI/4&&v<Math.PI/4?S-=8:v>3*Math.PI/4||v<-3*Math.PI/4?S+=8+l:v<0?(k+=10,C="start",S+=l*.35):(k-=10,C="end",S+=l*.35);const I=[{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(k,S,C)];return t&&I.push({t:"anchors",pts:e}),I}function Dc(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 Hi(e,t,n,o,i){const r=t[0],l=Do(e,r),s=o.fontSize??14,a=[{t:"path",d:Dc(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 Ni=22,Ge=17,_n=12,Fc=5;function _c(e,t,n){const o=e[0],i=o.y-Ni,r=o.x,l=[{x:r,y:i},{x:r+Ge,y:i},{x:r+Ge-Fc,y:i+_n/2},{x:r+Ge,y:i+_n},{x:r,y:i+_n}],s=[{t:"rect",x:r-L,y:i-L,w:Ge+L*2,h:Ni+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 Hc(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=li(a,r,c),h=100-(o.transparency??0),u=o.borderColor??o.color,d=[{t:"path",d:Wl(f),fill:St(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:St(at(u).hex,h),stroke:"#0f0f0f",strokeWidth:1}];return n&&d.push({t:"anchors",pts:[r]}),d}const Nc=28;function Yc(e,t,n){const[o]=t,i=e.style.fontSize??Nc,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 Vc="#089981",Uc="#f23645";function Xc(e,t){const n=[];for(const o of e){const i=o.up?Vc:Uc,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=Oo(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=Pe(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 Yi(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 Vi=14;function jc(e,t,n,o,i){if(e.kind!=="ghost-feed")return[];if(e.ghost&&i&&e.points.length>=2){const v=e.ghost.amplitude,k=Math.max(0,Math.min(1,(o.variance??50)/100)),S=[];let C=8,I=!1;for(let A=0;A<e.points.length-1;A++){const O=i.timeToBarIndex(e.points[A].time),F=i.timeToBarIndex(e.points[A+1].time);if(O==null||F==null||O===F)continue;I=!0;const T=t[A].x<=t[A+1].x,z=i.priceToY(T?e.points[A].price:e.points[A+1].price),P=i.priceToY(T?e.points[A+1].price:e.points[A].price);if(z==null||P==null)continue;const B=Math.min(O,F),D=Math.abs(F-O)-(A===0?0:1),U=D>1?(P-z)/(D-1):0;for(let J=0;J<D;J++){const Mt=i.barIndexToTime(B+J),se=Mt==null?null:i.timeToX(Mt);if(se==null)continue;if(J>0){const Le=i.barIndexToTime(B+J-1),Se=Le==null?null:i.timeToX(Le);Se!=null&&(C=Math.abs(se-Se)||C)}const At=i.yToPrice(z+J*U);if(At==null)continue;const ce=Yi((e.ghost.seed^Math.imul(A,2654435769)^Math.imul(J,2654435761))>>>0),ve=v*(1-2*ce())*k,vt=Math.max(1e-9,v*(1+(.5-ce())*k)),xt=ve-vt/2,Xt=xt+ce()*vt,Gt=xt+ce()*vt,ke=i.priceToY(At+Xt),Ot=i.priceToY(At+xt+vt),en=i.priceToY(At+xt),nn=i.priceToY(At+Gt);ke==null||Ot==null||en==null||nn==null||S.push({x:se,openY:ke,highY:Ot,lowY:en,closeY:nn,up:Gt>=Xt})}}if(I){const A=Math.floor(.3*C),O=o.ghostCandle??Rr,F=i.priceToY(e.points[0].price),T=i.priceToY(e.points[0].price+v),z=F!=null&&T!=null?Math.abs(T-F):10,P=[];for(const D of S)O.drawWick&&P.push({t:"line",a:{x:D.x,y:D.highY},b:{x:D.x,y:D.lowY},stroke:O.wickColor,strokeWidth:1}),P.push({t:"rect",x:Math.round(D.x)-A-.5,y:Math.min(D.openY,D.closeY),w:2*A+1,h:Math.max(1,Math.abs(D.closeY-D.openY)),fill:D.up?O.upColor:O.downColor,stroke:O.drawBorder?D.up?O.borderUpColor:O.borderDownColor:"none",strokeWidth:1});const B=[{t:"polyline",pts:t,fill:"none",stroke:"transparent",strokeWidth:Math.max(12,z*2)},{t:"polyline",pts:t,fill:"none",stroke:"#808080",strokeWidth:1,inert:!0},{t:"group",inert:!0,opacity:1-(o.transparency??50)/100,items:P}];return n&&B.push({t:"anchors",pts:t}),B}}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)^((_(e.points[0].time)??0)|0),x=Yi(d),p=h/Vi,y=Math.max(1,p*.6),m=u*.06,b=u*.12;let g=c+u/2;const w=[];for(let v=0;v<Vi;v++){const k=g,S=(x()-.5)*2*b;let C=k+S;C=Math.max(c+m,Math.min(f-m,C));const I=Math.min(k,C)-x()*m,A=Math.max(k,C)+x()*m;w.push({x:s+p*(v+.5),openY:k,highY:I,lowY:A,closeY:C,up:C<=k}),g=C}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:Xc(w,y)}];if(n)for(const v of yt(r,l))M.push({t:"circle",cx:v.x,cy:v.y,r:et,fill:"#fff",stroke:o.color,strokeWidth:1.5,cursor:"nwse-resize"});return M}const qc="#2e2e2e",Zc={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 Hn(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 m="";if(x&&(m+=mt(h,d)),p){const b=c!==0?100*h/Math.abs(c):0;x&&(m+=" ("),m+=`${mt(Math.round(b*100)/100,2)}%`,x&&(m+=")")}y&&(x?m+=p?" ":", ":p&&(m+=", "),m+=mt(Math.round(h/u),0)),m&&l.push(m)}if(i){const c=r(t.showBarsRange),f=r(t.showDateTimeRange),h=r(t.showVolume);let u="";const d=_(s.time),x=_(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+=Bn(x-d)),u&&l.push(u),h&&n&&d!=null&&x!=null){const m=Oe(n.bars(),Math.min(d,x),Math.max(d,x));let b=0,g=!1;for(const w of m)w.volume!=null&&(b+=w.volume,g=!0);g&&l.push(`Vol ${$s(b)}`)}}return l}function Qc(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??qc,shadow:Zc}),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 Ui(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 Jc(e,t,n){const o=Ui(e,t,n);if(!o||!me(o.lines))return{items:[],clip:void 0};const i=o.fs/3,r=Mi({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 ta(e,t,n){const o=Ui(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 ea(e){return e.fillBackground===!1?0:Math.max(0,Math.min(1,(100-(e.transparency??85))/100))}function Nn(e,t,n,o,i){const r=ea(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 Rt=(e,t,n)=>({t:"line",a:e,b:t,stroke:n.color,strokeWidth:n.width,cap:"round"}),je=(e,t,n)=>({t:"path",d:He(e,t,n.width),fill:"none",stroke:n.color,strokeWidth:n.width,cap:"round",join:"round"});function Yn(e,t,n,o,i,r,l,s,a){const c=Jc(n,o,s),f=[...c.items,...e,{t:"group",clip:c.clip,items:t},...Qc((n.x+o.x)/2,n,o,l,a,s),...ta(i[0],i[1],s)];return r&&f.push({t:"anchors",pts:i}),f}function na(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=Hn(e,r,l,!0,!1),d=[Rt({x:h,y:s.y},{x:h,y:a.y},r)];Math.abs(a.y-s.y)>=15*r.width&&d.push(je({x:h,y:s.y},{x:h,y:a.y},r));const x=[Nn(c,Math.min(s.y,a.y),Math.max(1,f-c),Math.abs(a.y-s.y),r),Rt({x:c,y:s.y},{x:f,y:s.y},r),Rt({x:c,y:a.y},{x:f,y:a.y},r)];return Yn(x,d,s,a,t,n,i,r,u)}function oa(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=Hn(e,i,r,!1,!0),u=[Rt({x:l.x,y:f},{x:s.x,y:f},i)];Math.abs(s.x-l.x)>=15*i.width&&u.push(je({x:l.x,y:f},{x:s.x,y:f},i));const d=[Nn(Math.min(l.x,s.x),a,Math.max(1,Math.abs(s.x-l.x)),Math.max(1,c-a),i),Rt({x:l.x,y:a},{x:l.x,y:c},i),Rt({x:s.x,y:a},{x:s.x,y:c},i)];return Yn(d,u,l,s,t,n,o,i,h)}function ia(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=Hn(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,m=[Nn(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&&m.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 b=[Rt({x:d,y:a},{x,y:a},i),Rt({x:c,y:p},{x:c,y},i)];return Math.abs(s.x-l.x)>=25*i.width&&b.push(je({x:d,y:a},{x,y:a},i)),Math.abs(s.y-l.y)>=25*i.width&&b.push(je({x:c,y:p},{x:c,y},i)),Yn(m,b,l,s,t,n,o,i,f)}function ra(e,t,n,o,i,r){const l=i.regressionLines??oo,s=vo(e,r,o);if(!s){const u=[{t:"line",a:t[0],b:t[1],stroke:l.base.color,strokeWidth:l.base.width,dash:R({...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=K(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:R({...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 la(e,t,n,o,i,r){const l=R(i),s=To(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!==!1&&h.index===0&&c.push({t:"polygon",pts:[...h.upper,...h.lower.slice().reverse()],fill:i.backgroundColor??"#4caf50",fillOpacity:K({...i,transparency:i.transparency??95}),stroke:"none",inert:!0});for(const[u,d]of[["upper",h.upper],["lower",h.lower]]){const x=pn(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}const Xi=e=>e==="dashed"?"6 4":e==="dotted"?"2 3":void 0;function sa(e){const t=Math.abs(e),n=(o,i)=>`${(e<0?-o:o).toFixed(o>=100?0:o>=10?1:2)}${i}`;return t>=1e9?n(t/1e9,"B"):t>=1e6?n(t/1e6,"M"):t>=1e3?n(t/1e3,"K"):String(Math.round(e))}function Gi(e,t,n){const o=$e(n.kind,n.style),{left:i,right:r,top:l,bottom:s,vp:a}=e,c=Math.max(1,r-i),f=Math.max(0,Math.min(100,o.percentWidth))/100*c,h=o.placement==="right",u=p=>{const y=t.priceToY(a.lo+(p+1)*a.step)??l,m=t.priceToY(a.lo+p*a.step)??s;return{y:Math.min(y,m),h:Math.abs(m-y)}},d=[];if(o.visible){const p=o.volume==="delta"?a.maxDelta:a.maxTotal,y=11;a.rows.forEach((m,b)=>{const g=u(b),w=b>=a.vaFrom&&b<=a.vaTo,M=w?o.vaUpColor:o.upColor,v=w?o.vaDownColor:o.downColor,k=Math.max(1,g.h-1),S=A=>p>0?A/p*f:0,C=o.volume==="total"?[{w:S(m.up+m.down),color:M}]:o.volume==="delta"?[{w:S(Math.abs(m.up-m.down)),color:m.up>=m.down?M:v}]:[{w:S(m.up),color:M},{w:S(m.down),color:v}];let I=0;for(const A of C){const O=h?r-I-A.w:i+I;d.push({t:"rect",x:O,y:g.y,w:A.w,h:k,fill:A.color}),I+=A.w}if(o.showValues&&g.h>=y-2){const A=o.volume==="delta"?m.up-m.down:m.up+m.down;d.push({t:"text",x:h?r-I-4:i+I+4,y:g.y+g.h/2,text:sa(A),size:y,fill:o.valuesColor,anchor:h?"end":"start",baseline:"central"})}})}const x=(p,y)=>{const m=t.priceToY(p);m!=null&&d.push({t:"line",a:{x:i,y:m},b:{x:r,y:m},stroke:y.color,strokeWidth:y.width,dash:Xi(y.style)})};if(o.vah.visible&&x(a.lo+(a.vaTo+1)*a.step,o.vah),o.val.visible&&x(a.lo+a.vaFrom*a.step,o.val),o.poc.visible&&x(a.lo+(a.poc+.5)*a.step,o.poc),a.developing){const p=(y,m)=>{if(!m.visible)return;const b=[];for(const g of a.developing){const w=t.timeToX(g.time),M=t.priceToY(y(g));w==null||M==null||(b.length&&b.push({x:w,y:b[b.length-1].y}),b.push({x:w,y:M}))}b.length>1&&d.push({t:"polyline",pts:b,fill:"none",stroke:m.color,strokeWidth:m.width,dash:Xi(m.style)})};p(y=>y.poc,o.developingPoc),p(y=>y.vah,o.developingVah),p(y=>y.val,o.developingVal)}return[{t:"rect",x:i,y:l,w:c,h:Math.max(1,s-l),fill:o.boxColor},{t:"group",inert:!0,items:d}]}function ca(e,t,n,o){const i=Eo(e,t,o),r=i&&o?Gi(i,o,e):[];return n&&r.push({t:"anchors",pts:t}),r}function aa(e,t,n,o){const i=Po(e,t,o),r=i&&o?Gi(i,o,e):[];return n&&r.push({t:"anchors",pts:[t[0]]}),r}const ji=new Map;function fa(e,t){let n=ji.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"}),ji.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 Vn=(e,t)=>String(e).padStart(t,"0");function ha(e,t){const n=fa(e,t);return{date:`${Vn(n.y,4)}-${Vn(n.m,2)}-${Vn(n.d,2)}`,time:`${n.hh}:${n.mi}`}}const qe={href:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAQAAABKmM6bAAAAZ0lEQVR4Xl2OsQmAMBRErwgSsHAJV3GHgEVKl3ADixSClViKYPkHfEI+Wsg1j8dxnCQCiQ1jJRFcFIybHsNYCCJXvCSsJonzp/YXbiKzs7d8pavyEBP2yQEji5YV+1KIkmjI/ouRID31wXKLSuZPUAAAAABJRU5ErkJggg==",w:9,h:9},ua={href:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAKCAQAAADI+WwIAAAAb0lEQVQIHWXAMQpBAQAG4L9eKQdQSr3JpFzC5CoOoJzBSUzK+iallNWkrG99pUymDxHw5Z+RdX4ZOpnmm57aXiuWunnScXAxTGLhqMyNth1muVNq1AYKK2wVeTBGo8JZP2/mgEk+KWxQ5ZfSUS8vV97kThm/FD/aAAAAAElFTkSuQmCC",w:11,h:10},da={href:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAQAAABKmM6bAAAARElEQVR4AWMgHvy/9//5f34gzQZiQYSeAyEPkOYE0iAhMJOTAc4ixXjR/13/r/7////h/zn/pSFCT/43/lcHS6X9fwgANMArS3ikrioAAAAASUVORK5CYII=",w:9,h:9};function Un(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 qi(e,t,n,o,i,r){const l=yn(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,m=i.targetTransparency??80,b=St(p,100-m),g=St(x,100-y),{yStop:w,yTarget:M,stop:v,profit:k}=l,S=i.accountSize??1e3,{qty:C,shown:I}=Ur(i,c,v),A=Ce=>parseFloat(Ce.toFixed(2)),O=A(S+k*C),F=A(S-v*C),T=v>0?Math.round(100*k/v)/100:0,z=o==="long"?1:-1,P=Xr(e,o,c-z*v,c+z*k,r),B=P?(P.closePrice-c)*z:null,D=(r==null?void 0:r.pipSize())??.01,U=Math.max(0,Math.min(8,Math.round(-Math.log10(D)))),J=co(i,"tp",k,c,D,U,O,k*C),Mt=co(i,"sl",v,c,D,U,F,-v*C),se=Nr(i,B!=null?mt(B,U):null,!!(P!=null&&P.closed),I,T),At=se?se.split(`
|
|
7
|
+
`):[],ce=B!=null&&B<0?x:B!=null&&B>0?p:i.color,ve=Ce=>{var Ir;const Br=(Ir=((r==null?void 0:r.bars())??[])[Ce])==null?void 0:Ir.time;return Br!=null&&r?r.timeToX(Br):null},vt=P&&r?r.priceToY(P.closePrice):null,xt=(P==null?void 0:P.entryIndex)!=null?ve(P.entryIndex):a.x,Xt=(P==null?void 0:P.closeIndex)!=null?ve(P.closeIndex):a.x,Gt=xt!=null&&Xt!=null&&vt!=null&&xt!==Xt?{x:Math.min(xt,Xt),y:Math.min(s.y,vt),w:Math.abs(Xt-xt),h:Math.abs(vt-s.y)}:null,ke=P?ve(P.closed?P.closeIndex:P.barIndex):null,Ot=(P==null?void 0:P.entryIndex)!=null&&xt!=null&&ke!=null&&vt!=null?{from:{x:xt,y:s.y},to:{x:ke,y:vt}}:null,en=n||!!i.showStats,nn=Math.max(0,ft(J,i.fontSize??12),ft(Mt,i.fontSize??12),...At.map(Ce=>ft(Ce,i.fontSize??12)))+8,Le=h-f-nn-et<=8,Se=Le?et+8:0,df=Le?(M<w?1:-1)*(k>v?-1:1)*(.5*((i.fontSize??12)*2+2*(i.fontSize??12)/3)+et+8):0,kt=[{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:g}];return Gt&&B!=null&&B<0&&kt.push({t:"rect",...Gt,fill:x,fillOpacity:1-(y/100)**3}),kt.push({t:"rect",x:f,y:Math.min(s.y,M),w:u,h:Math.abs(M-s.y),fill:b}),Gt&&B!=null&&B>0&&kt.push({t:"rect",...Gt,fill:p,fillOpacity:1-(m/100)**3}),Ot&&kt.push({t:"line",a:Ot.from,b:Ot.to,stroke:i.color,strokeWidth:1,dash:"6 4",inert:!0},{t:"path",d:He(Ot.from,Ot.to,1),fill:"none",stroke:i.color,strokeWidth:1,inert:!0}),kt.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:b,strokeWidth:i.width},{t:"line",a:{x:f,y:w},b:{x:h,y:w},stroke:g,strokeWidth:i.width}),en&&(J&&kt.push(Un(d,M,M<s.y?"bottom":"top",Se,[J],p,i)),At.length>0&&kt.push(Un(d,s.y,"middle",df,At,ce,i,"#ffffff")),Mt&&kt.push(Un(d,w,w>s.y?"top":"bottom",Se,[Mt],x,i))),n&&kt.push({t:"anchors",pts:l.anchors,squares:Yt.position}),kt}const xa="#202020",Zi=qe.w;function Ki(e,t,n){const o=_(e);if(o==null)return"";const i=(n==null?void 0:n.timeInfo())??{timeZone:"UTC",intraday:!0},{date:r,time:l}=ha(o,i.timeZone);return i.intraday?`${r}${t}${l}`:r}function Qi(e){const t=u=>ft(u.text,u.size)+(u.clockThen?Zi+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:xa}];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:qe.href,x,y:d+1,w:qe.w,h:qe.h},{t:"text",x:x+Zi+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=As(h.text,14),p=r+Math.round((n-x)/2),y=h.icon,m=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:m,w:y.w,h:y.h})}return{t:"group",inert:!0,items:f}}function ya(e,t,n,o,i,r){if(e.kind!=="position-forecast")return[];const[l,s]=t,a=s.y<=l.y,c=Ao(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,m=[s,{x:p-d*(x/2),y:y+u*(x/2)},{x:p+d*(x/2),y:y-u*(x/2)}],b=e.points[1].price-e.points[0].price,g=e.points[0].price!==0?b/Math.abs(e.points[0].price)*100:0,w=_(e.points[0].time),M=_(e.points[1].time),v=w!=null&&M!=null?Bn(M-w):"",k=(r==null?void 0:r.pipSize())??.01,S=Math.max(0,Math.min(8,Math.round(-Math.log10(k)))),C=cl(e,r),I=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:m,fill:i.color,stroke:i.color,strokeWidth:1,join:"round"},Qi({cx:l.x,y:l.y,below:a,paneW:o,height:32,rows:[{text:e.points[0].price.toFixed(S),size:12,dy:4},{text:Ki(e.points[0].time," ",r),size:10,dy:18}],bg:i.sourceBackColor??"#2962FF",stroke:i.sourceStrokeColor??"#2962FF",fg:i.sourceTextColor??"#ffffff",opacity:I}),Qi({cx:s.x,y:s.y,below:!a,paneW:o,height:38,rows:[{text:`${mt(b,S)} (${mt(Math.round(g*100)/100,2)}%)${v?` in ${v}`:""}`,size:14,dy:5},{text:e.points[1].price.toFixed(S),size:11,dy:22,clockThen:Ki(e.points[1].time," ",r)}],bg:i.targetBackColor??"#2962FF",stroke:i.targetStrokeColor??"#2962FF",fg:i.targetTextColor??"#ffffff",opacity:I,banner:C==="waiting"?void 0:{text:C==="success"?"SUCCESS":"FAILURE",icon:C==="success"?ua:da,bg:C==="success"?i.successBackground??"#4caf50":i.failureBackground??"#F23645",fg:C==="success"?i.successTextColor??"#ffffff":i.failureTextColor??"#ffffff",above:a}})];return n&&A.push({t:"anchors",pts:t}),A}const Ji={dx:0,dy:2,blur:4,color:"rgba(0,0,0,0.4)"},pa={dx:0,dy:1,blur:4,color:"rgba(0,0,0,0.4)"},we=e=>St(at(e).hex,50);function ma(e,t,n,o){const i=e.style,r=ni(e,t),l=pt(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?St(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(X(r,l?we(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 ba(e,t,n,o){const i=e.style,r=[{t:"path",d:Rl,transform:`translate(${t.x-12} ${t.y-30})`,fill:i.color,fillRule:"evenodd"}];if(!n)return r;const l=ii(e,t,o),s=pt(e).faint,a=i.textColor??"#dbdbdb",c=[];return i.fillBackground!==!1&&c.push({t:"path",d:ri(l,t.x),fill:St(at(i.backgroundColor??"#2e2e2e").hex,100-(i.transparency??0)),shadow:Ji}),i.drawBorder&&c.push({t:"path",d:ri(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?we(a):a,pre:!0,inert:!0})}),r.push({t:"group",items:c},{t:"anchors",pts:[t]}),r}function ga(e,t,n,o){const[i,r]=t;if(!r)return[];const{txt:l,faint:s,fs:a,box:c}=ei(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:Ji},{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 wa(e,t,n,o){const[i]=t,{l:r,r:l}=oi(e,i),s=pt(e).faint,a=o.textColor??"#ffffff",c=r.box,f=[{t:"path",d:zl(c.left,c.top,c.width,c.height,[l,l,l,2]),fill:St(at(o.backgroundColor??o.color).hex,100-(o.transparency??0)),stroke:o.borderColor??o.color,strokeWidth:2},X(r,s?we(a):a)];return n&&f.push({t:"anchors",pts:t}),f}function Ma(e,t,n,o,i){const r=n?Ln(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:Ht.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:Ht.pole,strokeWidth:1}),e.style.showImage&&l.push({t:"circle",cx:r.x,cy:r.plateY,r:35,fill:e.style.plateColor??"#2962ff",stroke:Ht.plateBorder,strokeWidth:1,shadow:pa},{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:Ht.labelBg,stroke:Ht.labelBorder,strokeWidth:1},X(r.l,pt(e).faint?we(Ht.labelText):Ht.labelText,e.style.bold,e.style.italic)),i&&l.push({t:"anchors",pts:[r.anchor],squares:Yt.single}),l}function va(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=mo(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",m=y==="left"?x:y==="right"?p:{x:(r.x+l.x)/2,y:(r.y+l.y)/2},b=Math.atan((p.y-x.y)/(p.x-x.x));return j({x:m.x,y:m.y,text:e.text,fs:o.fontSize??14,bold:o.bold,italic:o.italic,vert:o.vertLabelsAlign??"bottom",horz:y,angle:Number.isNaN(b)?0:b})})(),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(X(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},X(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 ka(e,t,n,o){const[i,r]=t,l=si(e,r),s=pt(e).faint,a=o.textColor??"#ffffff",c=[{t:"path",d:Ol(l,i,r),fill:St(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?we(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 La(e,t,n,o){const i=gn(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],m=i.xs[p+1],b=i.ys[x],g=i.ys[x+1],w=dt,M=ul;c=[[y+w,b+w,m-y-w,M],[y+w,g-M,m-y-w,M],[y+w,b+w,M,g-b-w],[m-M,b+w,M,g-b-w]].map(([k,S,C,I])=>`M${k} ${S}h${C}v${I}h${-C}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,m)=>{var k;const b=o!=null&&o.editing&&o.cell&&o.cell[0]===p&&o.cell[1]===m?[]:((k=i.lines[p])==null?void 0:k[m])??[],g=i.xs[m],w=i.xs[m+1],M=h==="right"?w-dt-_t:h==="center"?g+(w-g)/2:g+dt+_t,v=i.ys[p]+dt+_t+i.fs/2+.05*i.fs;b.forEach((S,C)=>{u.push({t:"text",x:M,y:v+C*i.fs*_o,text:S,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:dl,crisp:!0}),d.push({t:"group",inert:!0,items:u}),f&&d.push({t:"path",d:f,fill:xl,inert:!0}),n&&d.push({t:"anchors",pts:jo(i)}),d}function Sa(e,t,n){var r,l;const o=Jo(e,t);if(!o)return[];const i=[{t:"image",href:((l=kn((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:ti(o)}),i}function Ze(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 Rs(t,l,o,c);case"vertical-line":return Ws(t,l,i,c);case"cross-line":return Os(t,l,o,i,c);case"trend-line":return c.extendLeft||c.extendRight?Ne(e,t,l,o,i,c,!!c.extendLeft,!!c.extendRight,r,a):$i(e,t,l,o,i,c,r,a);case"horizontal-ray":return Ds(t,l,o,c);case"ray":return Ne(e,t,l,o,i,c,c.extendLeft??!1,c.extendRight??!0,r,a);case"extended-line":return Ne(e,t,l,o,i,c,c.extendLeft??!0,c.extendRight??!0,r,a);case"info-line":return Fs(e,t,l,o,i,c,r,a);case"trend-angle":return _s(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?Ne(e,t,l,o,i,f,!!f.extendLeft,!!f.extendRight,r,a):$i(e,t,l,o,i,f,r,a)}case"long-position":return qi(e,t,l,"long",c,r);case"short-position":return qi(e,t,l,"short",c,r);case"position-forecast":return ya(e,t,l,o,c,r);case"parallel-channel":return Vs(t,l,c,o,i);case"disjoint-channel":return Us(e,t,l,c,o,i,r);case"flat-top-bottom":return Xs(e,t,l,c,o,i,r);case"fib-retracement":return js(e,t,l,o,c,r);case"trend-based-fib-extension":return qs(e,t,l,o,c,r);case"fib-channel":return Zs(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 Qs(t,l,i,c);case"fib-circles":return tc(e,t,l,c);case"fib-speed-resistance-fan":return ec(e,t,l,o,i,c,r);case"fib-speed-resistance-arcs":return nc(t,l,c);case"fib-spiral":return oc(t,l,o,i,c);case"fib-wedge":return ic(t,l,c);case"pitchfan":return rc(t,l,o,c);case"pitchfork":case"schiff-pitchfork":case"modified-schiff-pitchfork":case"inside-pitchfork":return ac(e.kind,t,l,o,c);case"gann-fan":return sc(t,l,o,i,c);case"gann-box":return cc(e,t,l,c,r);case"gann-square-fixed":case"gann-square":return lc(e,t,l,c,r);case"rectangle":return uc(e,t,l,o,c,s);case"rotated-rectangle":return dc(e,t,l,c);case"circle":return xc(e,t,l,c,s);case"ellipse":return yc(e,t,l,c,s);case"triangle":return pc(t,l,c,s);case"arc":return mc(t,l,c);case"curve":return bc(t,l,c);case"double-curve":return gc(t,l,c);case"sector":return wc(t,l,c);case"cyclic-lines":return Mc(t,l,o,i,c);case"sine-line":return vc(t,l,o,c);case"time-cycles":return kc(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 Rc(e,t,l,c);case"arrow-marker":return Oc(t,l,c);case"arrow-mark-up":return Hi(e,t,l,c,"up");case"arrow-mark-down":return Hi(e,t,l,c,"down");case"flag-mark":return _c(t,l,c);case"price-label":return Hc(e,t,l,c,r);case"font-icon":return Yc(e,t,l);case"bar-pattern":return Gc(e,t,l,c,r);case"ghost-feed":return jc(e,t,l,c,r);case"price-range":return na(e,t,l,o,i,c,r);case"date-range":return oa(e,t,l,i,c,r);case"date-and-price-range":return ia(e,t,l,i,c,r);case"regression-trend":return ra(e,t,l,o,c,r);case"anchored-vwap":return la(e,t,l,o,c,r);case"fixed-range-volume-profile":return ca(e,t,l,r);case"anchored-volume-profile":return aa(e,t,l,r);case"text":return ma(e,t[0],n.textSelected??l,s);case"pin":return ba(e,t[0],l,o);case"note":return ga(e,t,l,c);case"comment":return wa(e,t,l,c);case"price-note":return va(e,t,l,c,r);case"signpost":return Ma(e,t[0],r,i,l);case"callout":return ka(e,t,l,c);case"table":return La(e,t[0],l,n.tableUi??null);case"image":return Sa(e,t[0],l)}return[]}function tr(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 er(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={...ot}),t.push(nr(n)));return t}function nr(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=Be.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 Ca=3,or=5,Ta=2,Aa=50;function Me(e,t,n){return t.anchored?[{x:t.anchored.x*n.w,y:t.anchored.y*n.h}]:ir(e,t.points)}function Xn(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=N(e,{x:s.x+o,y:s.y+i});if(!a)return null;l.push(a)}return $a(e,t.points,l)?V(t,l.map((s,a)=>{var c;return{time:((c=t.points[a])==null?void 0:c.time)??s.time,price:s.price}})):V(t,l)}function $a(e,t,n){if(t.length!==n.length)return!1;for(let o=0;o<t.length;o++){if(t[o].time===n[o].time)continue;const i=e.timeToBarIndex(t[o].time),r=e.timeToBarIndex(n[o].time);if(i==null||r==null||i!==r)return!1}return!0}function Q(e,t){const n=e.timeToX(t.time),o=e.priceToY(t.price);return n==null||o==null?null:{x:n,y:o}}function ir(e,t){const n=[];for(const o of t){const i=Q(e,o);if(!i)return null;n.push(i)}return n}function N(e,t){const n=e.xToTime(t.x),o=e.yToPrice(t.y);return n==null||o==null?null:{time:n,price:o}}function rr(e,t,n,o,i=!0){const r=t.barAt(e.time);if(!r)return null;const l=i?[r.open,r.high,r.low,r.close]:[];if(l.length===0)return null;const s=t.priceToY(e.price);let a=l[0],c=1/0;for(const f of l){const h=t.priceToY(f),u=s!=null&&h!=null?Math.abs(h-s):Math.abs(e.price-f);u<c&&(c=u,a=f)}return n==="weak"&&s!=null&&c>=Aa?null:{time:e.time,price:a}}function V(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 lr(e,t){return Math.atan2(-(t.y-e.y),t.x-e.x)*180/Math.PI}const Ba=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 Ke(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 Ia(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,m=p!=null&&y!=null?Math.abs(y-p):0,b=m>0?Math.round(o/m):0,g=u+Math.max(3,Math.round(.15*b)),w=n.barIndexToTime(g)??r.time,M={...Ft(t),stopLevel:f,profitLevel:f};return{...e,points:[r,{time:w,price:r.price}],style:M}}function Pa(e,t,n){const o=e.points[1];if(!o)return e;const i=_(e.points[0].time),r=_(o.time);if(i==null||r==null)return e;const l=Oe(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 Ea(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 za(e,t){const n=e.points[0],o=e.points[e.points.length-1];if(!n||!o)return e;const i=Q(t,n),r=Q(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=>N(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 Ra(e,t){const n=Q(t,e.points[0]),o=e.points[1]?Q(t,e.points[1]):null;return!n||!o?e:{...e,style:{...e.style??Ft("trend-angle"),angle:lr(n,o)}}}function sr(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 Gn(e,t,n,o,i={}){let r=Ke(e,t);return r?((e==="long-position"||e==="short-position")&&n&&(r=Ia(r,e,n,o.w,o.h)),(e==="curve"||e==="double-curve")&&n&&(r=za(r,n)),e==="gann-square"&&n&&(r=sr(r,n)),e==="bar-pattern"&&n&&(r=Pa(r,n,Math.max(1,o.h))),e==="trend-angle"&&n&&(r=Ra(r,n)),e==="polyline"&&i.closed!==void 0&&(r={...r,closed:i.closed}),e==="ghost-feed"&&n&&(r=Ea(r,n)),e==="font-icon"&&(r={...r,glyph:i.glyph}),r):null}const cr=new Set(["trend-line","ray","extended-line","info-line","arrow","trend-angle","arrow-marker","circle","fib-circles","fib-speed-resistance-fan","price-note","note","rotated-rectangle"]),Wa=new Set(["parallel-channel","flat-top-bottom","disjoint-channel"]);function Qe(e,t){const n=e.barIndexToTime(t),o=n==null?null:e.timeToX(n);return n==null||o==null?null:{i:t,time:n,x:o}}function Je(e,t){const n=e.xToTime(t),o=n==null?null:e.timeToBarIndex(n);return o==null?null:Qe(e,o)}function re(e,t,n){const o=e.timeToX(n.time),i=e.timeToX(t.time),r=e.priceToY(n.price),l=e.priceToY(t.price);if(o==null||i==null||r==null||l==null)return t;const s=i-o,a=l-r,c=Math.round(Math.atan2(s,a)/Math.PI*4);if(Math.abs(c)===2)return{time:t.time,price:n.price};if(c===0||Math.abs(c)===4)return{time:n.time,price:t.price};const f=Math.hypot(s,a),h=s<0?-1:1,u=a<0?-1:1;let d=Math.max(Math.abs(a),Math.abs(s));d/=d*Math.SQRT2/f;const x=Je(e,o+d*h);if(!x)return t;const p=e.yToPrice(r+Math.abs(x.x-o)*u);return p==null?t:{time:x.time,price:p}}function ar(e,t,n){const o=Q(e,t),i=Q(e,n);if(!o||!i)return t;const r=o.x-i.x,l=o.y-i.y,s=Math.max(Math.abs(r),Math.abs(l)),a=Je(e,i.x+s*(r<0?-1:1));if(!a)return t;const c=e.yToPrice(i.y+Math.abs(a.x-i.x)*(l<0?-1:1));return c==null?t:{time:a.time,price:c}}const Wt=[4.5,9,11.25,18,22.5,36,45],jn=(()=>{const e=[],t=Wt.length-1;let n=1,o=0,i=0;for(;i<1e10;)i=Wt[o]*n,e.push(Math.round(i)),e.push(Math.ceil(-i)),o===t-1&&(n*=10),o=(o+1)%t;return e.sort((r,l)=>r-l)})();function fr(e,t,n){let o=t.time;const i=e.timeToBarIndex(t.time),r=e.timeToBarIndex(n.time);if(i!=null&&r!=null){const a=i-r;if(a!==0){let c=jn.length-2;for(;c>=0&&!(jn[c]<a);--c);c+=a>0?1:0,o=e.barIndexToTime(r+jn[c])??o}}let l=t.price;const s=Math.round(1e6*(t.price-n.price))/1e6;if(s!==0){const a=Wt[0],c=Wt[Wt.length-1];let f=1;const h=Math.abs(s);for(;h<a*f||c*f<h;)h<a*f?f*=.1:c*f<h&&(f*=10);let u=c*f;for(let d=Wt.length-2;d>=0&&!(Wt[d]*f<h);--d)u=Wt[d]*f;l=n.price+(s>=0?u:-u)}return{time:o,price:l}}function hr(e,t,n,o){const i=Math.atan2(n.y-t.y,n.x-t.x)+Math.PI/2,r=o??Math.hypot(n.x-t.x,n.y-t.y)/2;return N(e,{x:(t.x+n.x)/2+Math.cos(i)*r,y:(t.y+n.y)/2+Math.sin(i)*r})}function ur(e,t,n,o){const i=t.length;if(i===0)return{point:n};if(cr.has(e))return{point:re(o,n,t[i-1])};if(Wa.has(e))return{point:i===1?re(o,n,t[0]):n};if(e==="rectangle")return{point:i===1?ar(o,n,t[0]):n};if(e==="gann-box")return{point:fr(o,n,t[0])};if(e==="ellipse"&&i===1){const r=re(o,n,t[0]),l=Q(o,t[0]),s=Q(o,r),a=l&&s?hr(o,l,s):null;return a?{point:r,extra:a}:{point:r}}return{point:n}}function qn(e,t){const n=Math.abs(e),o=Math.abs(t);return n<10&&o<10?{dx:e,dy:t}:n<o?{dx:0,dy:t}:{dx:e,dy:0}}function dr(e,t,n){return t&&Q(e,t)||n}function Oa(e,t,n){const o=e.start;if(e.mode.hit!=="handle")return{cursor:t};const i=e.mode.handleIndex,r=o.points,l=e.startScreen,s=f=>N(n,f),a=(f,h=re)=>{const u=s(t);return f?{cursor:u?dr(n,h(n,u,f),t):t}:{cursor:t}},c=(f,h)=>{if(!h)return{cursor:t};const u={x:f.x+t.x-e.startCursor.x,y:f.y+t.y-e.startCursor.y},d=s(u);if(!d)return{cursor:t};const x=dr(n,re(n,d,h),u);return{cursor:{x:e.startCursor.x+x.x-f.x,y:e.startCursor.y+x.y-f.y}}};switch(o.kind){case"circle":{if(i===1)return a(r[0]);if(i===0&&l[0]){const f=qn(t.x-l[0].x,t.y-l[0].y);return{cursor:{x:l[0].x+f.dx,y:l[0].y+f.dy}}}return{cursor:t}}case"rotated-rectangle":return a(i===0?r[1]:r[i===1?0:1]);case"parallel-channel":{const[f,h,u]=l;if(!f||!h||!u)return{cursor:t};const d={x:h.x+u.x-f.x,y:h.y+u.y-f.y},x=s(d);return i===0?c(f,r[1]):i===1?c(h,r[0]):i===2&&x?c(u,x):i===3?c(d,r[2]):{cursor:t}}case"flat-top-bottom":case"disjoint-channel":return i===1?a(r[0]):{cursor:t};case"ellipse":return{cursor:t,drawing:i<=1?xr(e,t,n,!0):void 0};case"rectangle":{if(l.length!==2)return{cursor:t};const f=yt(l[0],l[1]);if(i<4){const h=s(f[(i+2)%4]);return h?a(h,ar):{cursor:t}}return{cursor:t,drawing:Fa(e,t,n)}}case"gann-box":{if(l.length!==2||i>=4)return{cursor:t};const f=s(yt(l[0],l[1])[(i+2)%4]);return f?a(f,fr):{cursor:t}}case"gann-square":return{cursor:t,drawing:i<=1?Da(e,t,n):void 0}}return cr.has(o.kind)&&i<=1&&r.length>=2?a(r[i===0?1:0]):{cursor:t}}function xr(e,t,n,o,i=r=>r){const r=e.start;if(r.kind!=="ellipse"||e.mode.hit!=="handle")return null;const l=e.mode.handleIndex,[s,a,c]=e.startScreen;if(!s||!a||!c||l>1)return null;const f=N(n,t);if(!f)return null;const h=r.points[l===0?1:0],u=o?re(n,f,h):i(f),d=[...r.points];d[l]=u;const x=Q(n,d[0]),p=Q(n,d[1]);if(!x||!p)return null;const y=a.x-s.x,m=a.y-s.y,b=Math.hypot(y,m)||1,g=Math.abs(((c.x-s.x)*m-(c.y-s.y)*y)/b),w=hr(n,x,p,o?void 0:g);if(!w)return null;if(d[2]=w,o&&n.timeToBarIndex(d[0].time)===n.timeToBarIndex(d[1].time)){const M=d[l],v=d[l===0?1:0],k=Q(n,M),S=Q(n,v),C=n.timeToX(M.time),I=n.timeToX(w.time);if(k&&S&&C!=null&&I!=null){const A=2*Math.abs(C-I)*(v.price>M.price?1:-1),O=n.yToPrice(S.y+A);O!=null&&(d[l]={time:M.time,price:O})}}return V(r,d)}function Da(e,t,n){const o=e.start;if(e.mode.hit!=="handle")return null;const i=e.mode.handleIndex,[r,l]=o.points,s=n.timeToBarIndex(r.time),a=n.timeToBarIndex(l.time),c=N(n,t);if(!c||s==null||a==null||s===a)return null;const f=Math.abs(l.price-r.price)/Math.abs(a-s),h=i===0?l:r,u=n.timeToBarIndex(c.time),d=n.timeToBarIndex(h.time);if(u==null||d==null)return null;const x=[...o.points];return x[i]={time:c.time,price:h.price+(c.price-h.price>0?1:-1)*Math.abs(u-d)*f},V(o,x)}function Fa(e,t,n){const o=e.start;if(e.mode.hit!=="handle")return null;const[i,,r]=yt(e.startScreen[0],e.startScreen[1]);let{x:l,y:s}=i,{x:a,y:c}=r;const f=e.mode.handleIndex;if(f===5||f===7){const d=f===5?t.x-a:l-t.x;f===5?a+=d:l-=d,s-=d/2,c+=d/2}else{const d=f===4?s-t.y:t.y-c,x=Je(n,l),p=Je(n,a);if(!x||!p)return null;const y=Qe(n,p.i+1),m=y?y.x-p.x:0;if(m<=0)return null;const b=Math.round(d/m),g=Qe(n,x.i-b),w=Qe(n,p.i+b);if(!g||!w)return null;const M=w.x-p.x;l=g.x,a=w.x,f===4?s-=M:c+=M}const h=N(n,{x:l,y:s}),u=N(n,{x:a,y:c});return!h||!u?null:V(o,[h,u])}function _a(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}=ao(i,a);if(r===0){const d=N(n,t);if(!d)return null;const x=o(d);return V(i,[x,{time:s.time,price:x.price}])}if(r===1){const d=n.xToTime(t.x);return d==null?null:V(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 Ha(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=>N(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:V(o,[u,h[1],d])}if(s===1||s===3){const u=f({x:r.x+a,y:r.y+c});return u?V(o,[h[0],u,h[2]]):null}if(s===4){const u=f({x:l.x,y:l.y+c});return u?V(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:V(o,[u,d,x])}return null}function Na(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=N(n,t);if(!a)return null;const c=l.slice();return c[r]=o(a),V(i,c)}const s=n.yToPrice(t.y);if(s==null)return null;if(r===2)return V(i,[l[0],l[1],{time:l[2].time,price:s}]);if(r===3){const a=l[2].price+l[1].price-s;return V(i,[{time:l[0].time,price:a},l[1],l[2]])}return null}function Ya(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=N(n,t);if(!l)return null;const s=i.points.slice();if(r>=2)return s[2]=l,V(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?Q(n,p):a,m=r===1?Q(n,p):c;if(!y||!m)return null;const b=Math.hypot(m.x-y.x,m.y-y.y)||1,g=N(n,{x:y.x+(m.y-y.y)/b*x,y:y.y-(m.x-y.x)/b*x});return g?(s[2]=g,V(i,s)):null}function yr(e,t,n,o,i=!1){return Va(n,e.start,Ua(e,t,n,o,i))}function Va(e,t,n){if(!n||n.points.length!==t.points.length)return n;let o=!1;const i=n.points.map((r,l)=>{const s=t.points[l];if(r.time===s.time)return r;const a=e.timeToBarIndex(s.time);return a==null||a!==e.timeToBarIndex(r.time)?r:(o=!0,{time:s.time,price:r.price})});return o?{...n,points:i}:n}function Ua(e,t,n,o,i){var f,h;const r=Ie(e.start.kind);if(i&&e.mode.hit==="handle"){const u=Oa(e,t,n);if(u.drawing!==void 0)return u.drawing;t=u.cursor}if(i&&e.mode.hit==="body"){const u=qn(t.x-e.startCursor.x,t.y-e.startCursor.y);t={x:e.startCursor.x+u.dx,y:e.startCursor.y+u.dy}}if(e.mode.hit==="handle")switch(e.start.kind){case"long-position":case"short-position":return _a(e,t,n,o);case"parallel-channel":return Ha(e,t,n);case"table":return Xa(e,t,n);case"signpost":{const u=((f=e.pane)==null?void 0:f.h)??0,d=fi(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=N(n,{x:x+p/2+10,y:e.startScreen[1].y});return y?{...V(e.start,[e.start.points[0],y]),style:{...u,wordWrapWidth:p}}:null}case"image":return Ga(e,t,n);case"pin":if(e.start.anchored)return Xn(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)<or){const p=N(n,t);if(!p)return null;const y=e.start.points.slice();return y[u]=o(p),{...V(e.start,y),closed:!0}}}break}case"disjoint-channel":return Na(e,t,n,o);case"ellipse":if(e.mode.handleIndex<=1)return xr(e,t,n,!1,o);break;case"rotated-rectangle":if(e.start.fmt===2)return Ya(e,t,n,o);break;case"horizontal-line":{const u=N(n,t);return u?V(e.start,[{time:e.start.points[0].time,price:o(u).price}]):null}case"vertical-line":{const u=N(n,t);return u?V(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=N(n,{x:e.startScreen[0].x+u,y:e.startScreen[0].y}),p=((h=e.pane)==null?void 0:h.h)??0,y=Ln(e.start,e.startScreen[0],n,p);if(!x)return null;const m=V(e.start,[{time:x.time,price:e.start.points[0].price}]),b=fi(m,n,p,y.anchor.y+d);return b==null?m:{...m,style:{...m.style,signpostPosition:b}}}if(e.mode.hit==="body")return Xn(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]=yt(e.startScreen[0],e.startScreen[1]);let{x,y:p}=u,{x:y,y:m}=d;switch(e.mode.handleIndex){case 4:p=t.y;break;case 5:y=t.x;break;case 6:m=t.y;break;case 7:x=t.x;break}const b=N(n,{x,y:p}),g=N(n,{x:y,y:m});return!b||!g?null:V(e.start,[b,g])}if(r!=null&&r.isBbox&&e.startScreen.length===2&&e.mode.handleIndex<4){const d=yt(e.startScreen[0],e.startScreen[1])[(e.mode.handleIndex+2)%4],x=N(n,t),p=N(n,d);return!x||!p?null:V(e.start,[o(x),p])}const l=N(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=V(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:lr(u,d)}}}return c}function pr(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 Xa(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=xe(i),{heights:c,mins:f}=Go(i),h=pl(s),u=a.map(()=>h),d=B=>B.reduce((D,U)=>D+U,0),x=d(a),p=d(c),y=No(r);if(y){const B={};if(y.col!=null){const D=l.x+d(a.slice(0,y.col));B.tableColWidths=a.map((U,J)=>J===y.col?Math.max(h,t.x-D):U)}if(y.row!=null){const D=l.y+d(c.slice(0,y.row));B.tableRowHeights=c.map((U,J)=>J===y.row?Math.max(f[J],t.y-D):U)}return{...o,style:{...i,...B}}}if(r>3)return null;const m=r===0||r===1,b=r===0||r===2,g={x:l.x+(m?0:x),y:l.y+(b?0:p)},w={x:g.x+(m?x:-x),y:g.y+(b?p:-p)},M=h*a.length,v=d(f);let k=m?Math.min(t.x,w.x-M):Math.max(t.x,w.x+M);const S=b?Math.min(t.y,w.y-v):Math.max(t.y,w.y+v);let C=o.points[0].time;const I=o.anchored&&e.pane&&e.pane.w>0&&e.pane.h>0?e.pane:null;if(m&&!I){const B=pr(n,k),D=B==null?null:n.timeToX(B);if(B==null||D==null)return null;C=B,k=D}let A=o.points[0].price;if(b&&!I){const B=n.yToPrice(S);if(B==null)return null;A=B}const O=g.x-k,F=g.y-S,T=wn(a,u,m?x+O:x-O);m&&(T[T.length-1]+=Math.round(l.x+x)-k-d(T));const z=wn(c,f,b?p+F:p-F),P=Uo(s);if(I){const B=m?k:l.x,D=b?S:l.y;return{...o,anchored:{x:B/I.w,y:D/I.h},style:{...i,tableColWidths:T.map(U=>Math.max(U,h)),tableRowHeights:z.map(U=>Math.max(U,P))}}}return{...o,points:[{time:C,price:A}],style:{...i,tableColWidths:T.map(B=>Math.max(B,h)),tableRowHeights:z.map(B=>Math.max(B,P))}}}function Ga(e,t,n){const o=e.start,i=o.image,r=kn(i==null?void 0:i.name);if(!i||!r||e.mode.hit!=="handle"||e.mode.handleIndex>3)return null;const[l,s]=Al[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=N(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 mr(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 br=new Set(["text","pin","table"]);function gr(e){return br.has(e)}function wr(e,t,n){if(!gr(e.kind)||n.w<=0||n.h<=0)return null;if(!e.anchored){const c=Q(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=pr(t,o),l=t.yToPrice(i);if(r==null||l==null)return null;const{anchored:s,...a}=e;return V(a,[{time:r,price:l}])}const ja=1;function Mr(e,t,n,o=()=>[],i=()=>({timeZone:"UTC",intraday:!0}),r=()=>null){return{priceToY:l=>t.priceToCoordinate(l),yToPrice:l=>t.coordinateToPrice(l),isLog:()=>t.priceScale().options().mode===ja,timeToX:l=>{const s=e.timeScale().timeToCoordinate(l);if(s!=null)return s;const a=n();if(a.length===0)return null;const c=nt(l);if(c==null)return null;const f=Zn(a,c,r());return f==null?null:vr(e,f)},xToTime:l=>{const s=e.timeScale().coordinateToTime(l);if(s!=null)return s;const a=n();if(a.length===0)return null;const c=e.timeScale().coordinateToLogical(l),f=nt(a[a.length-1].time);if(c==null||f==null)return null;const h=r();if(h&&c>a.length-1){const x=Math.round(c-(a.length-1));if(x<=0)return a[a.length-1].time;const p=h.time(x,f);if(p!=null)return p}const u=nt(a[0].time);if(h!=null&&h.pastTime&&u!=null&&c<0){const x=Math.round(-c);if(x<=0)return a[0].time;const p=h.pastTime(x,u);if(p!=null)return p}const d=tn(a);return d<=0?null:Math.round(f+(c-(a.length-1))*d)},barAt:l=>Ka(n(),l),timeToBarIndex:l=>{const s=n();if(s.length===0)return null;const a=nt(l);if(a==null)return null;const c=Zn(s,a,r());return c==null?null:Math.round(c)},barIndexToTime:l=>{const s=n();if(s.length===0)return null;if(l>=0&&l<s.length)return s[l].time;const a=s.length-1,c=nt(s[a].time);if(c==null)return null;const f=r();if(f&&l>a){const d=f.time(l-a,c);if(d!=null)return d}const h=nt(s[0].time);if(f!=null&&f.pastTime&&h!=null&&l<0){const d=f.pastTime(-l,h);if(d!=null)return d}const u=tn(s);return Math.round(c+(l-a)*u)},bars:n,visibleTimeRange:()=>{const l=e.timeScale().getVisibleRange();if(!l)return null;const s=nt(l.from),a=nt(l.to);return s==null||a==null?null:{from:s,to:a}},indicatorValuesAt:l=>o(nt(l)),pipSize:()=>{const l=t.options().priceFormat;return l&&typeof l.minMove=="number"&&l.minMove>0?l.minMove:.01},addPriceLine:l=>t.createPriceLine(l),removePriceLine:l=>t.removePriceLine(l),zoomToScreenRect:(l,s,a,c)=>{const f=e.timeScale(),h=f.coordinateToLogical(Math.min(l,s)),u=f.coordinateToLogical(Math.max(l,s));h!=null&&u!=null&&u>h&&f.setVisibleLogicalRange({from:h,to:u});const d=t.coordinateToPrice(a),x=t.coordinateToPrice(c);if(d!=null&&x!=null){const p=Math.min(d,x),y=Math.max(d,x);if(y>p){const m=t.priceScale();m.setAutoScale(!1),m.setVisibleRange({from:p,to:y})}}},formatTime:l=>{const s=e.options().localization.timeFormatter;if(s)return s(l);const a=nt(l);if(a==null)return String(l);const c=e.options(),f=new Date(a*1e3),h=new Intl.DateTimeFormat(c.localization.locale,{month:"short",timeZone:"UTC"}).format(f),u=`${f.getUTCDate()} ${h} '${String(f.getUTCFullYear()%100).padStart(2,"0")}`;if(!c.timeScale.timeVisible)return u;const d=p=>String(p).padStart(2,"0"),x=`${d(f.getUTCHours())}:${d(f.getUTCMinutes())}${c.timeScale.secondsVisible?`:${d(f.getUTCSeconds())}`:""}`;return`${u} ${x}`},timeInfo:()=>i(),timeAxis:()=>{const l=e.options().layout;return{height:e.timeScale().height(),width:e.timeScale().width(),fontSize:l.fontSize,fontFamily:l.fontFamily}}}}function nt(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 tn(e){if(e.length<2)return 86400;const t=[];for(let n=Math.max(1,e.length-50);n<e.length;n++){const o=nt(e[n-1].time),i=nt(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 Zn(e,t,n){const o=e.length,i=nt(e[0].time),r=nt(e[o-1].time);if(i==null||r==null)return null;const l=(n==null?void 0:n.timeKey)??(a=>a),s=l(t);if(s>=l(r)){if(n)return o-1+n.slots(t,r);if(t<=r)return o-1;const a=tn(e);return a>0?o-1+(t-r)/a:null}if(s<l(i)){if(n!=null&&n.pastSlots)return-n.pastSlots(t,i);const a=tn(e);return a>0?(t-i)/a:null}return qa(e,s,l)}function qa(e,t,n){let o=0,i=e.length-1;for(;o<i;){const r=o+i+1>>1,l=nt(e[r].time);l!=null&&n(l)<=t?o=r:i=r-1}return o}function vr(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 Za(e,t,n,o){if(n.length===0)return null;const i=Zn(n,t,o);return i==null?null:vr(e,i)}function Ka(e,t){if(e.length===0)return null;const n=nt(t);if(n==null)return e[0];let o=e[0],i=1/0;for(const r of e){const l=nt(r.time);if(l==null)continue;const s=Math.abs(l-n);s<i&&(o=r,i=s)}return o}const Kn="#1e53e5";function kr(e,t,n){const o={clips:new Map,grads:new Map};for(const i of t)Qn(e,i,n,o)}function Qn(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":rf(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),le(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(),le(e,l,t,o,!0);break}case"path":{t.transform&&to(e,t.transform),le(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?Jn(l,t.x,t.y,t.w,t.h,s,a):l.rect(t.x,t.y,t.w,t.h),le(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),le(e,l,t,o,!0);break}case"ellipse":{if(t.transform&&to(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),le(e,l,t,o,!0);break}case"text":tf(e,t,n);break;case"image":nf(e,t,n);break;case"glyph":of(e,t,n);break;case"group":{if(t.transform&&to(e,t.transform),t.opacity!=null&&t.opacity<1){const l=Qa(e);if(l){for(const s of t.items)Qn(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)Qn(e,l,n,o);break}}r&&e.restore()}function Qa(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 le(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&&Lr(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")&&Lr(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(Ja(n.dash)),e.stroke(t),e.restore()}}function Lr(e,t){e.shadowOffsetX=t.dx,e.shadowOffsetY=t.dy,e.shadowBlur=t.blur,e.shadowColor=t.color}function Ja(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 Jn(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 to(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 tf(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+=ef(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 Sr=new Map;function ef(e){let t=Sr.get(e.font);if(t==null){const n=e.measureText("H");t=(n.fontBoundingBoxAscent-n.fontBoundingBoxDescent)/2,Sr.set(e.font,t)}return t}const Cr=new Map;function Tr(e,t){let n=Cr.get(e);return n||(n=new Image,n.onload=()=>{var o;return(o=t.onAsyncLoad)==null?void 0:o.call(t)},n.src=e,Cr.set(e,n)),n.complete&&n.naturalWidth>0?n:null}function nf(e,t,n){if(!t.href)return;const o=Tr(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 of(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=Tr(`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 rf(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(Kn,.2),e.lineWidth=3;const c=new Path2D;s?Jn(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;Jn(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=Kn,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 lf=()=>`dw_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`;class sf{constructor(t,n,o={}){Y(this,"chart");Y(this,"series");Y(this,"opts");Y(this,"coords");Y(this,"primitive");Y(this,"el");Y(this,"listeners",{change:new Set,add:new Set,update:new Set,remove:new Set,selection:new Set,tool:new Set,visibility:new Set,textEdit:new Set,gestureEnd:new Set,tableEdit:new Set});Y(this,"list",[]);Y(this,"selected",[]);Y(this,"visible",!0);Y(this,"hovered",null);Y(this,"spec",null);Y(this,"glyph");Y(this,"pending",[]);Y(this,"cursor",null);Y(this,"gesture",null);Y(this,"tableUi",null);Y(this,"hoverCursor",null);Y(this,"shift",!1);Y(this,"ctrl",!1);Y(this,"savedScroll",null);Y(this,"off",[]);this.chart=t,this.series=n,this.opts={magnet:"off",...o};const i=o.bars??(()=>af(n));this.coords=Mr(t,n,i,()=>[],o.timeInfo),this.primitive=new hf(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(Zo(()=>{var r;for(const l of this.list)l.kind==="image"&&Tl((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;o&&this.setDrawingsVisible(!0),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.dropHidden(),this.redraw()}setDrawingsVisible(t){this.visible!==t&&(this.visible=t,t||(this.spec&&this.setTool(null),this.dropHidden()),this.emit("visibility",t),this.redraw())}drawingsVisible(){return this.visible}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:lf(),style:Ft(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.dropHidden(),this.emit("update",t,n),this.changed())}setHidden(t,n){const o=this.get(t);!o||!!o.hidden===n||this.update({...o,hidden:n})}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=N(this.coords,{x:n/2,y:o/2});if(!i)return null;const r=Ft("image"),l=this.add({kind:"image",points:[i],image:{name:t.name,...$l(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=wr(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,...kl(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,...wl(o.style,n==="insert-row"?"row":"column",i)}});else{const s=n==="remove-row"?"row":"column";if(!i||!Ml(o.style,s))return;const a=vl(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=er(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=Ze(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:tr(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=gi(l,s,o);for(const c of a.price){const f=o.priceToY(c.price);f!=null&&t.push($r(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($r(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?ff(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 this.visible&&!t.hidden&&(this.opts.interval==null||Dt(t.visibility,this.opts.interval))}dropHidden(){const t=n=>{const o=this.get(n);return!!o&&this.shown(o)};this.hovered&&!t(this.hovered.id)&&(this.hovered=null,this.hoverCursor=null),this.selected.every(t)||this.select(this.selected.filter(t))}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(){var i;const t=this.opts.magnet??"off",n=t==="strong"?"strong":"weak",o=this.pending.length>0||!!((i=this.gesture)!=null&&i.active)&&this.gesture.mode.hit==="handle";return this.shift&&o?{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=>rr(o,n,t.mode)??o:o=>o}dataAt(t){const n=N(this.coords,t);return n?this.snapFn()(n):null}aimAt(t){const n=this.magnet();if(!n.enabled)return t;const o=N(this.coords,t),i=o?rr(o,this.coords,n.mode):null;return i&&Q(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=bi(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"?No(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"?mr(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,cf(n.drawing,n.pts)))}placementClick(t){const n=this.spec;if(n.kind==="image")return;const o=t,i=this.pending,r=this.coords;if(n.variableLength&&i.length>=1){const d=x=>{const p=Q(r,x);return!!p&&Math.hypot(p.x-o.x,p.y-o.y)<or};if(d(i[i.length-1])){i.length>=2&&this.finishVariable(!1);return}if(n.kind==="polyline"&&i.length>=2&&d(i[0])){this.finishVariable(!0);return}}const l=this.dataAt(o);if(!l)return;const s=this.shift?ur(n.kind,i,l,r):{point:l},a=s.point,c=s.extra?[...i,a,s.extra]:[...i,a];if(n.variableLength||c.length<n.pointCount){this.pending=c,this.cursor=o,this.redraw();return}const{w:f,h}=this.paneSize();let u=Gn(n.kind,c,r,{w:f,h},{glyph:this.glyph});u&&n.kind==="signpost"&&(u={...u,style:{...Ft("signpost"),signpostPosition:ai(r,c[0],h)}}),this.pending=[],this.cursor=null,u?this.placeNew(u,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=Gn(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=N(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)<Ta)return;const c=N(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?Ke(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,...m}=p.image;this.update({...p,image:m})}}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)<Ca)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={dx:t.x-n.startCursor.x,dy:t.y-n.startCursor.y},{dx:r,dy:l}=this.shift?qn(i.dx,i.dy):i;for(const s of n.group){const a=Xn(this.coords,s.start,s.startScreen,r,l,this.paneSize());a&&this.update(a)}return}const o=yr(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=gn(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=>Q(l,d)).filter(d=>!!d);if(!s.length)return null;const a=Ft(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&&!Ba.has(o.kind)&&s.length===i.length&&s.length<o.pointCount){const d=this.dataAt(c),x=d&&this.shift?ur(o.kind,i,d,l):null,p=x?x.point:d;if(p){const y=[...i,p];for(x!=null&&x.extra&&y.push(x.extra);y.length<o.pointCount;)y.push(p);const m=Ke(o.kind,y),b=m&&o.kind==="gann-square"?sr(m,l):m,g=b?{...b,id:"__preview__",style:a}:null,w=g?ir(l,g.points):null;if(g&&w)return[...Ze(g,w,{w:t,h:n,coords:l,selected:!1}),...f]}}if(o.freehand&&s.length>=2)return Ze({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 cf(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 af(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 ff(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 $r(e,t,n,o){return{coordinate:()=>e,text:()=>t,backColor:()=>n,textColor:()=>o,visible:()=>!0,tickVisible:()=>!0}}class hf{constructor(t){Y(this,"m");Y(this,"request",null);Y(this,"view");Y(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))kr(n,c.scene,{fontFamily:l,anchors:{fillAt:s,selected:c.selected,hovered:c.hoveredAnchor},onAsyncLoad:a});n.restore()})}}const uf="0.6.2";E.ANCHORABLE_KINDS=br,E.DEFAULT_STYLE=ot,E.DrawingManager=sf,E.IMAGE_MAX_BYTES=Ll,E.IMAGE_MAX_SIDE=Mn,E.IMAGE_TYPES=Sl,E.OVERLAY_SPECS=ae,E.TV_ANCHOR_COLOR=Kn,E.VERSION=uf,E.anchorCursor=mr,E.applyDrag=yr,E.buildNewDrawing=Ke,E.cacheImage=Bl,E.decodeImage=Qo,E.defaultStyleFor=Ft,E.drawScene=kr,E.drawingAxisLabels=gi,E.factoryStyleFor=Dr,E.fibLevelAt=Gs,E.findOverlaySpec=Ie,E.finishPlacement=Gn,E.hitTestKind=bi,E.isAnchorable=gr,E.isVisibleOnInterval=Dt,E.makeCoords=Mr,E.migrateDrawing=nr,E.onImagesChanged=Zo,E.parseDrawings=er,E.sceneLockedAnchors=tr,E.sceneOf=Ze,E.setDefaultStyleOverride=Fr,E.setImageReader=Cl,E.timeToXFallback=Za,E.toggleAnchored=wr,E.volumeProfileDefaults=io,E.volumeProfileStyle=$e,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|
|
8
8
|
//# sourceMappingURL=lightweight-charts-drawing.umd.cjs.map
|