openalgo-charts
Version:
From-scratch, dependency-free canvas charting engine for OpenAlgo: professional-grade interactive rendering, advanced on-chart trading, and a one-call widget tier that adds the toolbar, drawing rail, dialogs and shortcuts.
3 lines • 228 kB
JavaScript
import{PRICE_SCALE_MODES as t,tryResolveInterval as e,getIndicator as i,plotStyleKeys as n}from"./openalgo-charts.mjs";function r(t,e){return(t??e).filter(t=>!1!==t.enabled&&Number.isFinite(t.ratio))}const s="#787b86",o=[[.236,"#f23645"],[.25,"#7e57c2"],[.382,"#ff9800"],[.5,"#4caf50"],[.618,"#089981"],[.75,"#26c6da"],[.786,"#00bcd4"],[1.272,"#2962ff"],[1.414,"#9c27b0"],[1.618,"#e91e63"],[2.618,"#ff5252"],[3.618,"#9575cd"],[4.236,"#64b5f6"]],l=1e-6;function a(t){if(!Number.isFinite(t))return s;for(const[e,i]of o)if(Math.abs(e-t)<=l)return i;return s}const c=["#2962ff","#f23645","#089981","#ff9800","#9c27b0","#00bcd4","#e91e63","#4caf50"];function h(t){const e=c.length,i=Number.isFinite(t)?Math.trunc(t):0;return c[(i%e+e)%e]}function d(t){return`${(100*t).toFixed(1)}%`}function u(t){if(!Number.isFinite(t)||t<=0)return String(t);if(t>=1)return`${t}x1`;const e=1/t;return Math.abs(e-Math.round(e))<=l?`1x${Math.round(e)}`:`${t}x1`}function p(t){for(const e of t)Object.freeze(e);return Object.freeze(t)}function f(t){return t.map(t=>({...t}))}const y=p([0,.236,.382,.5,.618,.786,1].map(t=>({ratio:t,color:a(t)}))),x=p([.236,.382,.5,.618,.786,1].map(t=>({ratio:t,color:a(t)}))),g=p([0,.25,.382,.5,.618,.75,1].map(t=>({ratio:t,color:a(t)}))),m=p([.125,.25,.5,1,2,4,8].map((t,e)=>({ratio:t,color:h(e),label:u(t)}))),_=p([0,1,2,3,5,8,13,21,34,55].map(t=>({ratio:t})));function b(t,e,i,n,r){if(t.x===e.x)return;const s=n?-1/0:t.x,o=r?1/0:e.x;return i<Math.min(s,o)-1e-7||i>Math.max(s,o)+1e-7?void 0:t.y+(e.y-t.y)*(i-t.x)/(e.x-t.x)}function v(t,e){if(void 0===e)return;const i=t.fromY(e);return null!==i&&Number.isFinite(i)?{price:i}:void 0}function w(t=!1,e=!1){return(i,n)=>{if(!(i.pts.length<2||void 0!==n&&"line"!==n))return v(i,b(i.pts[0],i.pts[1],i.x,i.drawing.style.extendLeft??t,i.drawing.style.extendRight??e))}}function M(t=!1){return(e,i)=>{if(!(!e.pts[0]||t&&e.x<e.pts[0].x||void 0!==i&&"line"!==i))return{price:e.drawing.points[0].price}}}function P(){return[{id:"band",title:"Channel band"},{id:"base",title:"First boundary"},{id:"boundary",title:"Second boundary"},{id:"middle",title:"Middle"}]}function k(t){return(e,i="band")=>{if(e.pts.length<("disjoint"===t?4:3))return;const[n,r,s]=e.pts,o=s.y-(n.y+r.y)/2,l="disjoint"===t?[s,e.pts[3]]:"flat"===t?[{x:n.x,y:s.y},{x:r.x,y:s.y}]:[{x:n.x,y:n.y+o},{x:r.x,y:r.y+o}],a="parallel"!==t&&!0===e.drawing.style.extendLeft,c="parallel"!==t&&!0===e.drawing.style.extendRight,h=(i,n)=>"parallel"!==t&&i.x>n.x?b(n,i,e.x,a,c):b(i,n,e.x,a,c),d=h(n,r),u=h(l[0],l[1]);if("base"===i)return v(e,d);if("boundary"===i)return v(e,u);if(void 0===d||void 0===u)return;if("middle"===i)return v(e,(d+u)/2);if("band"!==i)return;const p=v(e,d),f=v(e,u);return p&&f?{price:Math.min(p.price,f.price),upperPrice:Math.max(p.price,f.price)}:void 0}}function S(t){return e=>[...new Map(r(e.style.levels,t).map(t=>{const e=`ratio:${t.ratio}`;return[e,{id:e,title:t.label??d(t.ratio)}]})).values()]}function T(t,e){return(i,n)=>{const s=r(i.drawing.style.levels,e).find(t=>`ratio:${t.ratio}`===n);if(!s||i.pts.length<(2===t?2:3))return;const[o,l,a]=i.pts,c=!0===i.drawing.style.extendLeft,h=!0===i.drawing.style.extendRight;if("channel"===t){const t=t=>({x:t.x+(a.x-l.x)*s.ratio,y:t.y+(a.y-l.y)*s.ratio});return v(i,b(t(o),t(l),i.x,c,h))}const d=i.pts[t-1];if(!c&&i.x<Math.min(o.x,d.x)||!h&&i.x>Math.max(o.x,d.x))return;const u=i.drawing.points;return{price:(2===t?u[0].price:u[2].price)+(u[1].price-u[0].price)*s.ratio}}}function I(t,e,i,n){const r=n.x-i.x,s=n.y-i.y,o=r*r+s*s;if(0===o)return Math.hypot(t-i.x,e-i.y);let l=((t-i.x)*r+(e-i.y)*s)/o;return l=l<0?0:l>1?1:l,Math.hypot(t-(i.x+l*r),e-(i.y+l*s))}function O(t,e,i,n){const r=n.x-i.x,s=n.y-i.y,o=Math.hypot(r,s);return 0===o?Math.hypot(t-i.x,e-i.y):Math.abs(s*(t-i.x)-r*(e-i.y))/o}function F(t,e){return Math.abs(t-e)}function L(t,e){return Math.abs(t-e)}function A(t,e,i){let n=1/0;for(let r=1;r<i.length;r++){const s=I(t,e,i[r-1],i[r]);s<n&&(n=s)}return n}function z(t,e){return{x0:Math.min(t.x,e.x),y0:Math.min(t.y,e.y),x1:Math.max(t.x,e.x),y1:Math.max(t.y,e.y)}}function N(t){let e=1/0,i=1/0,n=-1/0,r=-1/0;for(const s of t)s.x<e&&(e=s.x),s.y<i&&(i=s.y),s.x>n&&(n=s.x),s.y>r&&(r=s.y);return{x0:e,y0:i,x1:n,y1:r}}function C(t,e,i,n,r){const s=z(i,n);if(t>=s.x0&&t<=s.x1&&e>=s.y0&&e<=s.y1&&r)return 0;const o=[{x:s.x0,y:s.y0},{x:s.x1,y:s.y0},{x:s.x1,y:s.y1},{x:s.x0,y:s.y1}];let l=1/0;for(let i=0;i<4;i++){const n=I(t,e,o[i],o[(i+1)%4]);n<l&&(l=n)}return l}function $(t,e,i,n,r){const s=z(i,n),o=(s.x0+s.x1)/2,l=(s.y0+s.y1)/2,a=Math.max(1e-6,(s.x1-s.x0)/2),c=Math.max(1e-6,(s.y1-s.y0)/2),h=(t-o)/a,d=(e-l)/c,u=Math.hypot(h,d);return r&&u<=1?0:Math.abs(u-1)*Math.min(a,c)}function D(t,e,i,n,r){const s=e.x-t.x;if(0===s)return[t,e];const o=(e.y-t.y)/s;return[n?{x:0,y:t.y+(0-t.x)*o}:t,r?{x:i,y:t.y+(i-t.x)*o}:e]}const j=[{value:"solid",label:"Solid"},{value:"dashed",label:"Dashed"},{value:"dotted",label:"Dotted"}],H=[{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}],B=[{value:"top",label:"Top"},{value:"middle",label:"Middle"},{value:"bottom",label:"Bottom"}],W=[{value:"inside",label:"Inside"},{value:"outside",label:"Outside"}],R=[{value:"data",label:"Time and price"},{value:"viewport",label:"Screen"}],V=[{value:"ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif",label:"Sans"},{value:"ui-serif, Georgia, Times New Roman, serif",label:"Serif"},{value:"ui-monospace, Menlo, Consolas, monospace",label:"Mono"}],E={path:"style.color",label:"Color",kind:"color",group:"line"},J={path:"style.lineWidth",label:"Width",kind:"number",min:1,max:12,step:.5,group:"line"},K={path:"style.lineStyle",label:"Line style",kind:"lineStyle",options:j,group:"line"},U=[E,J,K],Y=[{path:"style.fill",label:"Fill",kind:"boolean",group:"fill"},{path:"style.fillColor",label:"Fill color",kind:"color",group:"fill"},{path:"style.fillOpacity",label:"Fill opacity",kind:"opacity",min:0,max:1,step:.01,group:"fill"}],q=[{path:"style.extendLeft",label:"Extend left",kind:"boolean",group:"behavior"},{path:"style.extendRight",label:"Extend right",kind:"boolean",group:"behavior"}],G={path:"space",label:"Anchor",kind:"select",options:R,group:"behavior",defaultValue:"data"},X=[{path:"intervals.from",label:"Show from",kind:"interval",group:"visibility"},{path:"intervals.to",label:"Show up to",kind:"interval",group:"visibility"}],Z={path:"style.showLabels",label:"Show labels",kind:"boolean",group:"behavior"},Q=[{path:"style.levels",label:"Levels",kind:"levels",group:"levels"},{...Z,group:"levels"}],tt=[{path:"text.color",label:"Text color",kind:"color",group:"text"},{path:"text.fontSize",label:"Font size",kind:"number",min:6,max:96,step:1,group:"text"},{path:"text.fontFamily",label:"Font",kind:"select",options:V,group:"text"},{path:"text.bold",label:"Bold",kind:"boolean",group:"text"},{path:"text.italic",label:"Italic",kind:"boolean",group:"text"}],et={path:"text.value",label:"Text",kind:"text",group:"text"},it=[et,...tt,{path:"text.align",label:"Align",kind:"select",options:H,group:"text"},{path:"text.valign",label:"Vertical align",kind:"select",options:B,group:"text"},{path:"text.wrap",label:"Wrap",kind:"boolean",group:"text"},{path:"text.wrapWidth",label:"Wrap width",kind:"number",min:40,max:2e3,step:10,group:"text"},{path:"text.background",label:"Background",kind:"boolean",group:"text"},{path:"text.backgroundColor",label:"Background color",kind:"color",group:"text"},{path:"text.backgroundOpacity",label:"Background opacity",kind:"opacity",min:0,max:1,step:.01,group:"text"},{path:"text.border",label:"Border",kind:"boolean",group:"text"},{path:"text.borderColor",label:"Border color",kind:"color",group:"text"}],nt=[et,...tt,{path:"text.align",label:"Align",kind:"select",options:H,group:"text"},{path:"text.valign",label:"Vertical align",kind:"select",options:B,group:"text"},{path:"text.wrap",label:"Wrap",kind:"boolean",group:"text"},{path:"text.position",label:"Label position",kind:"select",options:W,group:"text"}],rt=[et,...tt,{path:"text.backgroundColor",label:"Plate color",kind:"color",group:"text"},{path:"text.backgroundOpacity",label:"Plate opacity",kind:"opacity",min:0,max:1,step:.01,group:"text"},{path:"text.border",label:"Border",kind:"boolean",group:"text"},{path:"text.borderColor",label:"Border color",kind:"color",group:"text"}];function st(t,e={}){const i=new Set,n=[];for(const e of t)for(const t of Array.isArray(e)?e:[e])i.has(t.path)||(i.add(t.path),n.push(t));return!0===e.textIsContent?{fields:n,textIsContent:!0}:{fields:n}}const ot=new Set(["style","text","props","intervals"]),lt=new Set(["locked","visible","zIndex","space"]);function at(t){const e=t.split(".");return 1===e.length&<.has(e[0])?{root:e[0],key:null}:2===e.length&&ot.has(e[0])&&""!==e[1]?{root:e[0],key:e[1]}:null}function ct(t,e){const i=at(e);if(null===i)return;if(null===i.key)return t[i.root];const n=t[i.root],r=n?.[i.key];return Array.isArray(r)?r.map(t=>({...t})):r}function ht(t,e){const i={};for(const n of e.fields)i[n.path]=ct(t,n.path)??n.defaultValue;return i}const dt=new Set(["solid","dashed","dotted"]);function ut(t){return"boolean"==typeof t?t:"true"===t||1===t||"1"===t||"false"!==t&&0!==t&&"0"!==t&&void 0}function pt(t){const e="number"==typeof t?t:"string"==typeof t&&""!==t.trim()?Number(t):NaN;return Number.isFinite(e)?e:void 0}function ft(t){if("object"!=typeof t||null===t)return null;const e=t,i=pt(e.ratio);if(void 0===i)return null;const n={ratio:i};"string"==typeof e.color&&""!==e.color&&(n.color=e.color);const r=ut(e.enabled);return void 0!==r&&(n.enabled=r),"string"==typeof e.label&&""!==e.label&&(n.label=e.label),n}function yt(t,e){if(null!=e)switch(t.kind){case"color":case"text":return"string"==typeof e?e:String(e);case"number":{const i=pt(e);if(void 0===i)return;const n=t.min??-1/0,r=t.max??1/0;return i<n?n:i>r?r:i}case"opacity":{const t=pt(e);return void 0===t?void 0:t<0?0:t>1?1:t}case"boolean":return ut(e);case"lineStyle":return"string"==typeof e&&dt.has(e)?e:void 0;case"select":if("string"!=typeof e)return;return void 0===t.options||t.options.some(t=>t.value===e)?e:void 0;case"interval":{const t="string"==typeof e?e.trim():"";return""===t?void 0:t}case"levels":{if(!Array.isArray(e))return;const t=[];for(const i of e){const e=ft(i);null!==e&&t.push(e)}return t}default:return}}function xt(t,e,i){const n=void 0===i?null:new Map(i.fields.map(t=>[t.path,t])),r={},s={};for(const i of Object.keys(e)){const o=at(i);if(null===o)continue;let l=e[i];if(null!==n){const t=n.get(i);if(void 0===t)continue;l=yt(t,l)}if(null===o.key){if(void 0===l)continue;"zIndex"===o.root?"number"==typeof l&&Number.isFinite(l)&&(r.zIndex=l):"space"===o.root?"data"!==l&&"viewport"!==l||(r.space=l):"boolean"==typeof l&&(r[o.root]=l);continue}const a=s[o.root]??{...t[o.root]};s[o.root]=a,void 0===l?delete a[o.key]:a[o.key]=l}if(void 0!==s.style&&(r.style=s.style),void 0!==s.props&&(r.props=s.props),void 0!==s.intervals){const{from:t,to:e}=s.intervals;r.intervals={..."string"==typeof t?{from:t}:{},..."string"==typeof e?{to:e}:{}}}if(void 0!==s.text){const t=s.text;"string"!=typeof t.value&&(t.value=""),r.text=t}return r}function gt(t,e,i){return t<e?e:t>i?i:t}function mt(t,e){const i=t.length;if(!(e>0)||i<3)return t.map(t=>({x:t.x,y:t.y}));const n=new Uint8Array(i);n[0]=1,n[i-1]=1;const r=[0,i-1];for(;r.length>0;){const i=r.pop(),s=r.pop(),o=t[s],l=t[i];let a=-1,c=e;for(let e=s+1;e<i;e++){const i=I(t[e].x,t[e].y,o,l);i>c&&(c=i,a=e)}a<0||(n[a]=1,r.push(s,a,a,i))}const s=[];for(let e=0;e<i;e++)1===n[e]&&s.push({x:t[e].x,y:t[e].y});return s}function _t(t,e,i=.5){const n=e.length;if(n<2)return;if(t.moveTo(e[0].x,e[0].y),2===n)return void t.lineTo(e[1].x,e[1].y);const r=gt(i,0,1)/3;for(let i=0;i<n-1;i++){const s=e[0===i?0:i-1],o=e[i],l=e[i+1],a=e[i+2<n?i+2:n-1];t.bezierCurveTo(o.x+(l.x-s.x)*r,o.y+(l.y-s.y)*r,l.x-(a.x-o.x)*r,l.y-(a.y-o.y)*r,l.x,l.y)}}function bt(t,e,i=.6){return t*(1+2*((Number.isFinite(e)?gt(e,0,1):.5)-.5)*gt(i,0,1))}const vt=new WeakMap;function wt(t,e){const i=vt.get(t);if(!i)return t.measureText(e).width;const n=t.font+"\0"+e,r=i.get(n);if(void 0!==r)return r;const s=t.measureText(e).width;return i.size<1024&&i.set(n,s),s}function Mt(t,e,i,n){return"number"==typeof t&&Number.isFinite(t)?Math.max(i,Math.min(n,t)):e}function Pt(t,e,i=!1){let n=0,r=t.length;for(;n<r;){const s=n+r>>>1;(i?t[s].time<=e:t[s].time<e)?n=s+1:r=s}return n}function kt(t,e,i,n,r){return 0===t?"empty":e?r||i>0||n>0?"partial":"ready":i>0?"missing-volume":n>0?"invalid-data":"zero-volume"}function St(t,e){switch(e){case"close":return t.close;case"hl2":return t.low/2+t.high/2;case"ohlc4":return t.open/4+t.high/4+t.low/4+t.close/4;default:return t.high/3+t.low/3+t.close/3}}function Tt(t,e,i={}){const n={status:"empty",historyPartial:!1,points:[],missingVolumeBars:0,invalidPriceBars:0};if(!Number.isFinite(e))return n;n.historyPartial=t.length>0&&e<t[0].time;const r=Pt(t,e);let s=0,o=0,l=0,a=0,c=0,h=!1;for(let e=r;e<t.length;e++){const r=t[e],d=r.volume;if(void 0===d||!Number.isFinite(d)||d<0){n.missingVolumeBars++,h=!0;continue}const u=St(r,i.source??"hlc3");if(Number.isFinite(u)){if(d>0){if(0===s&&(l=u),d>o){const t=o/d;s*=t,c*=t,o=d}const t=d/o,e=s+t,i=u-l-a;a+=i*(t/e),c+=t*i*(u-l-a),s=e}if(s>0){const t=l+a,e=Math.sqrt(Math.max(0,c/s));if(!Number.isFinite(t)||!Number.isFinite(e))return{...n,status:"invalid-data",points:[]};n.points.push({time:r.time,value:t,deviation:e,breakBefore:h}),h=!1}}else n.invalidPriceBars++,h=!0}return n.status=kt(t.length-r,s>0,n.missingVolumeBars,n.invalidPriceBars,n.historyPartial),n}function It(t,e,i,n={}){const r={status:"empty",historyPartial:!1,rows:[],totalVolume:0,poc:null,valueAreaLow:null,valueAreaHigh:null,missingVolumeBars:0,invalidPriceBars:0};if(!Number.isFinite(e)||!Number.isFinite(i))return r;r.historyPartial=t.length>0&&Math.min(e,i)<t[0].time;const s=Pt(t,Math.min(e,i)),o=Pt(t,Math.max(e,i),!0);let l=1/0,a=-1/0,c=0;for(let e=s;e<o;e++){const i=t[e],n=i.volume;if(void 0===n||!Number.isFinite(n)||n<0){r.missingVolumeBars++;continue}const s=i.low,o=i.high;if(!Number.isFinite(s)||!Number.isFinite(o)||o<s){r.invalidPriceBars++;continue}l=Math.min(l,s),a=Math.max(a,o);const h=n-c,d=r.totalVolume+h;c=d-r.totalVolume-h,r.totalVolume=d}if(r.status=kt(o-s,r.totalVolume>0,r.missingVolumeBars,r.invalidPriceBars,r.historyPartial),!Number.isFinite(r.totalVolume)||r.totalVolume>0&&!Number.isFinite(a-l))return{...r,status:"invalid-data",totalVolume:0};if(r.totalVolume<=0)return r;const h=Math.round(Mt(n.rows,48,4,200)),d=[l];for(let t=1;t<h;t++){const e=l+t/h*(a-l);e>d[d.length-1]&&e<a&&d.push(e)}d.push(a);const u=d.length-1,p=(a-l)/u,f=t=>d[t],y=new Float64Array(u),x=new Float64Array(u+1),g=t=>{let e=0,i=u;for(;e<i;){const n=e+i+1>>>1;d[n]<=t?e=n:i=n-1}return Math.min(u-1,e)};for(let e=s;e<o;e++){const i=t[e],n=i.volume,s=i.low,o=i.high;if(void 0===n||!Number.isFinite(n)||n<=0||!Number.isFinite(s)||!Number.isFinite(o)||o<s)continue;const l=n/r.totalVolume,a=g(s),c=g(o);if(a===c){y[a]+=l;continue}const h=o-s;if(y[a]+=l*((f(a+1)-s)/h),y[c]+=l*((o-f(c))/h),c>a+1){const t=l*(p/h);x[a+1]+=t,x[c]-=t}}let m=0,_=0;for(let t=0;t<u;t++){m+=x[t];const e=1===u?0:m*((f(t+1)-f(t))/p);y[t]=Math.max(0,Math.min(1,y[t]+e))*r.totalVolume,y[t]>y[_]&&(_=t),r.rows.push({low:f(t),high:f(t+1),volume:y[t],valueArea:!1})}let b=_,v=_,w=y[_];const M=r.totalVolume*(Mt(n.valueArea,70,1,100)/100);for(;w<M&&(b>0||v<u-1);){w+=(b>0?y[b-1]:-1)>=(v<u-1?y[v+1]:-1)?y[--b]:y[++v]}for(let t=b;t<=v;t++)r.rows[t].valueArea=!0;return r.poc=f(_)/2+f(_+1)/2,r.valueAreaLow=f(b),r.valueAreaHigh=f(v+1),r}function Ot(t){const e=function(t){const e=t.trim();if(e.startsWith("#")){const t=e.slice(1);if(3===t.length||4===t.length){const[e,i,n,r]=[...t].map(t=>parseInt(t+t,16));return[e,i,n].some(Number.isNaN)?null:{r:e,g:i,b:n,a:4===t.length?r/255:1}}if(6===t.length||8===t.length){const e=parseInt(t.slice(0,6),16);if(Number.isNaN(e))return null;const i=8===t.length?parseInt(t.slice(6,8),16)/255:1;return{r:e>>16&255,g:e>>8&255,b:255&e,a:Number.isNaN(i)?1:i}}return null}const i=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(e);return null===i?null:{r:Number(i[1]),g:Number(i[2]),b:Number(i[3]),a:void 0===i[4]?1:Number(i[4])}}(t);return(null!==e?function(t){return.2126*Ft(t.r)+.7152*Ft(t.g)+.0722*Ft(t.b)}(e):.5)>.45?"#10131a":"#ffffff"}const Ft=t=>{const e=t/255;return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)};function Lt(t,e,i,n,r,s){const o=t.roundRect;"function"==typeof o?o.call(t,e,i,n,r,Math.max(0,Math.min(s,n/2,r/2))):t.rect(e,i,n,r)}function At(t,e){return"dashed"===t?[6*e,4*e]:"dotted"===t?[1*e,3*e]:[]}const zt={path:"style.fillOpacity",label:"Opacity",kind:"opacity",min:0,max:1,step:.01,group:"fill"},Nt=(t,e)=>Math.max(1,Math.round(t*e));function Ct(t,e){return{x:t.timeScale.indexToX(t.dataLayer.timeToIndexFloat(e.time)),y:t.priceScale.priceToY(e.price)}}function $t(t){const{ctx:e,rc:i,style:n}=t,r=i.dpr;e.strokeStyle=n.color,e.lineWidth=Nt(n.lineWidth,r),e.lineJoin="round",e.lineCap="round",e.setLineDash(At(n.lineStyle,r))}function Dt(t){return t.style.fillColor??t.style.color}function jt(t,e){if(!0!==t.style.fill)return;const{ctx:i}=t;i.save(),i.globalAlpha=t.style.fillOpacity??.12,i.fillStyle=Dt(t),e(),i.restore()}const Ht={value:""};function Bt(t){return t.text??Ht}function Wt(t,e,i){const n=i??(!0===t.bold?"700":"");return`${!0===t.italic?"italic ":""}${""===n?"":`${n} `}${e}px ${void 0===t.fontFamily||""===t.fontFamily?"ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif":t.fontFamily}`}function Rt(t,e){const i=t.text?.value;return void 0===i||""===i?e:i}function Vt(t,e,i,n,r,s={}){const{ctx:o,rc:l,style:a}=t,c=Bt(t.drawing),h=(c.fontSize??11)*l.dpr;o.save(),o.setLineDash([]),o.font=Wt(c,h),o.textBaseline="middle",o.textAlign="left";const d=wt(o,e),u=!0===s.center?i-d/2:i;o.globalAlpha=.85,o.fillStyle=l.theme.background,o.fillRect(u-2*l.dpr,n-.75*h,d+4*l.dpr,1.5*h),void 0!==s.tint&&(o.globalAlpha=.22,o.fillStyle=s.tint,o.fillRect(u-2*l.dpr,n-.75*h,d+4*l.dpr,1.5*h)),o.globalAlpha=1,o.fillStyle=c.color??r??a.color,o.fillText(e,u,n),o.restore()}function Et(t,e,i,n,r,s={}){const{ctx:o,rc:l}=t,a=l.dpr,c=Bt(t.drawing),h=(c.fontSize??11)*a;o.save(),o.setLineDash([]),o.globalAlpha=1,o.font=Wt(c,h),o.textBaseline="middle",o.textAlign="left";const d=5*a,u=3*a,p=1.35*h;let f=0;for(const t of e)f=Math.max(f,wt(o,t));const y=f+2*d,x=p*e.length+2*u,g=s.align??"left",m="center"===g?i-y/2:"right"===g?i-y:i,_=s.place??"above",b="above"===_?n-x-4*a:"below"===_?n+4*a:n-x/2;o.beginPath(),Lt(o,m,b,y,x,3*a),o.fillStyle=r,o.fill(),o.fillStyle=c.color??Ot(r);for(let t=0;t<e.length;t++)o.fillText(e[t],m+d,b+u+p*(t+.5));return o.restore(),x}function Jt(t,e=0){const[i,n]=Math.abs(t).toFixed(e).split(".");return(t<0?"-":"")+i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+(void 0===n?"":"."+n)}function Kt(t,e,i){const n=Math.max(8,5*t.style.lineWidth)*t.rc.dpr,r=Math.atan2(i.y-e.y,i.x-e.x);t.ctx.beginPath(),t.ctx.moveTo(i.x,i.y),t.ctx.lineTo(i.x-n*Math.cos(r-.4),i.y-n*Math.sin(r-.4)),t.ctx.lineTo(i.x-n*Math.cos(r+.4),i.y-n*Math.sin(r+.4)),t.ctx.closePath(),t.ctx.fillStyle=t.style.color,t.ctx.fill()}const Ut=(t,e)=>e?t.rc.theme.upColor:t.rc.theme.downColor,Yt="#16a34a",qt="#dc2626",Gt=1.35,Xt=14;function Zt(t,e,i,n){const r=i.split("\n");if(!0!==e.wrap)return r;const s=[];for(const e of r){const i=e.split(/\s+/).filter(t=>""!==t);if(0===i.length){s.push("");continue}let r=i[0];for(let e=1;e<i.length;e++){const o=`${r} ${i[e]}`;t.measureText(o).width>n?(s.push(r),r=i[e]):r=o}s.push(r)}return s}function Qt(t,e,i,n){const r=(e.fontSize??Xt)*n;t.font=Wt(e,r);const s=Zt(t,e,i,(e.wrapWidth??220)*n);let o=0;for(const e of s)o=Math.max(o,t.measureText(e).width);const l=r*Gt;return{lines:s,width:o+10*n,height:s.length*l+10*n,lineHeight:l}}function te(t,e,i="left",n="top"){const{ctx:r,rc:s,style:o}=t,l=Bt(t.drawing);if(""===l.value)return;r.save(),r.setLineDash([]);const a=ee(r,l,e,s.dpr,i,n);r.fillStyle=l.color??o.color,r.textBaseline="top",r.textAlign=a.align;let c=a.y;for(const t of a.lines)r.fillText(t,a.x,c),c+=a.lineHeight;r.restore()}function ee(t,e,i,n,r,s){const o=(e.fontSize??Xt)*n,l=6*n;null!==t&&(t.font=Wt(e,o));const a=null===t?e.value.split("\n"):Zt(t,e,e.value,Math.max(20*n,i.x1-i.x0-2*l)),c=o*Gt,h=a.length*c,d=e.align??r,u="center"===d?(i.x0+i.x1)/2:"right"===d?i.x1-l:i.x0+l,p=e.valign??s;return{lines:a,align:d,x:u,y:"outside"===e.position?i.y0-h-l:"middle"===p?(i.y0+i.y1-h)/2:"bottom"===p?i.y1-h-l:i.y0+l,lineHeight:c,height:h}}function ie(t,e){return(i,n)=>{const r=z(i[0],i[1]),s=Bt(n);if(""===s.value)return r;const o=re(),l=ee(o,s,r,1,t,e);let a=0;for(const t of l.lines)a=Math.max(a,null===o?t.length*(s.fontSize??Xt)*.6:o.measureText(t).width);const c="center"===l.align?l.x-a/2:"right"===l.align?l.x-a:l.x;return{x0:Math.min(r.x0,c),y0:Math.min(r.y0,l.y),x1:Math.max(r.x1,c+a),y1:Math.max(r.y1,l.y+l.height)}}}let ne;function re(){if(void 0!==ne)return ne;try{ne="undefined"==typeof document?null:document.createElement("canvas").getContext("2d")}catch{ne=null}return ne}const se=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),oe=(t,e,i)=>({x:t.x+(e.x-t.x)*i,y:t.y+(e.y-t.y)*i}),le=t=>Number.isFinite(t.x)&&Number.isFinite(t.y);function ae(t,e,i,n,r){return Mt(t.props?.[e],i,n,r)}function ce(t,e,i,n=0,r=1){if(!le(t)||!le(e))return[];const s=e.x-t.x,o=e.y-t.y;if(0===s&&0===o)return t.x>=0&&t.x<=i.plotWidth&&t.y>=0&&t.y<=i.plotHeight?[t,t]:[];for(const[e,l,a]of[[t.x,s,i.plotWidth],[t.y,o,i.plotHeight]]){if(0===l){if(e<0||e>a)return[];continue}const t=-e/l,i=(a-e)/l;if((n=Math.max(n,Math.min(t,i)))>(r=Math.min(r,Math.max(t,i))))return[]}return[oe(t,e,n),oe(t,e,r)]}function he(t,e,i){if(t.x===e.x)return ce(t,e,i.rc);const n=e.x>=t.x;return ce(t,e,i.rc,!0===(n?i.drawing.style.extendLeft:i.drawing.style.extendRight)?-1/0:0,!0===(n?i.drawing.style.extendRight:i.drawing.style.extendLeft)?1/0:1)}function de(t,e){if(!t.every(le))return[];let i=t.slice();for(const[t,n,r]of[["x",0,1],["x",e.plotWidth,-1],["y",0,1],["y",e.plotHeight,-1]]){const e=i;i=[];for(let s=0;s<e.length;s++){const o=e[s],l=e[(s+1)%e.length],a=(o[t]-n)*r>=0,c=(l[t]-n)*r>=0;a&&i.push(o),a!==c&&i.push(oe(o,l,(n-o[t])/(l[t]-o[t])))}}return i}function ue(t,e,i){let n=!1;for(let r=0,s=i.length-1;r<i.length;s=r++){const o=i[r],l=i[s];o.y>e!=l.y>e&&t<(l.x-o.x)*(e-o.y)/(l.y-o.y)+o.x&&(n=!n)}return n}function pe(t,e,i,n,r){const s=Math.max(2,Math.min(96,Math.ceil(Math.abs(r)*Math.max(Math.abs(e),Math.abs(i))/4)));return Array.from({length:s+1},(o,l)=>{const a=n+r*l/s;return{x:t.x+e*Math.cos(a),y:t.y+i*Math.sin(a)}})}const fe=2*Math.PI;function ye(t,e){return le(t)&&Number.isFinite(t.x*e)&&Number.isFinite(t.y*e)}function xe(t,e){const i=t.arc;return void 0===i?t.points.length>=2&&t.points.every(t=>ye(t,e)):function(t){return le(t.center)&&[t.rx,t.ry,t.start,t.sweep,t.start+t.sweep].every(Number.isFinite)&&t.rx>0&&t.ry>0}(i)&&ye(i.center,e)&&Number.isFinite(i.rx*e)&&Number.isFinite(i.ry*e)}function ge(t,e){return{x:t.center.x+t.rx*Math.cos(e),y:t.center.y+t.ry*Math.sin(e)}}function me(t,e){if(0===e.sweep)return!1;const i=((t-e.start)*Math.sign(e.sweep)%fe+fe)%fe;return Math.abs(e.sweep)>=fe-1e-12||i<=Math.abs(e.sweep)+1e-12}function _e(t,e,i){if(i.rx===i.ry&&Math.abs(i.sweep)>=fe-1e-12)return Math.abs(Math.hypot(t-i.center.x,e-i.center.y)-i.rx);const n=ge(i,i.start),r=ge(i,i.start+i.sweep),s=Math.hypot(t-n.x,e-n.y),o=Math.hypot(t-r.x,e-r.y),l=Math.min(s,o);if(i.rx===i.ry)return me(Math.atan2(e-i.center.y,t-i.center.x),i)?Math.abs(Math.hypot(t-i.center.x,e-i.center.y)-i.rx):l;const a=n=>{const r=ge(i,i.start+i.sweep*n);return Math.hypot(t-r.x,e-r.y)};let c=l,h=o<s?32:0;for(let t=0;t<=32;t++){const e=a(t/32);e<c&&(c=e,h=t)}let d=Math.max(0,(h-1)/32),u=Math.min(1,(h+1)/32);const p=Math.min(80,Math.max(32,2*Math.ceil(Math.log2(Math.max(i.rx,i.ry)))+8));for(let t=0;t<p;t++){const t=d+(u-d)/3,e=u-(u-d)/3;a(t)<a(e)?u=e:d=t}return Math.min(c,a((d+u)/2))}function be(t,e,i){const n=(t-i.center.x)/i.rx,r=(e-i.center.y)/i.ry;if(n*n+r*r>1)return!1;if(Math.abs(i.sweep)>=fe-1e-12)return!0;if(!0===i.sector)return me(Math.atan2(r,n),i);const s=i.start+i.sweep/2;return n*Math.cos(s)+r*Math.sin(s)>=Math.cos(Math.abs(i.sweep)/2)}function ve(t,e){const{ctx:i,rc:n,style:r}=t,s=n.dpr;i.save(),i.strokeStyle=r.color,i.lineWidth=Nt(r.lineWidth,s),i.lineJoin="round",i.lineCap="round",i.setLineDash(At(r.lineStyle,s));for(const t of e.paths)if(xe(t,s)){if(i.beginPath(),void 0!==t.arc){const e=t.arc;!0===e.sector&&i.moveTo(e.center.x*s,e.center.y*s),e.rx===e.ry?i.arc(e.center.x*s,e.center.y*s,e.rx*s,e.start,e.start+e.sweep,e.sweep<0):i.ellipse(e.center.x*s,e.center.y*s,e.rx*s,e.ry*s,0,e.start,e.start+e.sweep,e.sweep<0)}else{i.moveTo(t.points[0].x*s,t.points[0].y*s);for(let e=1;e<t.points.length;e++)i.lineTo(t.points[e].x*s,t.points[e].y*s)}!0===t.closed&&i.closePath(),!0===t.fill&&!0===r.fill&&(i.save(),i.globalAlpha*=Math.max(0,Math.min(1,r.fillOpacity??.12)),i.fillStyle=r.fillColor??r.color,i.fill("evenodd"),i.restore()),!1!==t.stroke&&(i.strokeStyle=t.color??r.color,i.stroke())}const o=t.drawing.text,l=(o?.fontSize??11)*s;i.font=Wt(Bt(t.drawing),l),i.textAlign="left",i.textBaseline="bottom";const a=[],c=l/s*1.3;for(const t of e.labels??[]){if(!ye(t.at,s))continue;let{x:e,y:h}=t.at;if(e>=0&&e<=n.plotWidth&&h>=0&&h<=n.plotHeight){const r=wt(i,t.text)/s;e=Math.max(0,Math.min(e,n.plotWidth-r));let o=!1;for(const t of[0,-1,1,-2,2,-3,3,-4]){const i=h+t*c;if(!(i<l/s||i>n.plotHeight)&&!a.some(t=>e<t.x+t.width+3&&e+r+3>t.x&&Math.abs(i-t.y)<c-.01)){h=i,a.push({x:e,y:h,width:r}),o=!0;break}}if(!o)continue}i.fillStyle=o?.color??t.color??r.color,i.fillText(t.text,e*s,h*s)}i.restore()}function we(t,e){return{...t,draw(t){const i=t.pts.map(e=>({x:e.x/t.rc.dpr,y:e.y/t.rc.dpr}));ve(t,e({pts:i,drawing:{...t.drawing,style:t.style},rc:t.rc}))},distance:(t,i,n)=>t<0||i<0||t>n.rc.plotWidth||i>n.rc.plotHeight?null:function(t,e,i,n,r=1){let s=1/0;for(const o of i.paths){if(!xe(o,r))continue;if(void 0!==o.arc){const i=o.arc;if(!0===o.fill&&!0===n.style.fill&&(n.style.fillOpacity??.12)>0&&be(t,e,i))return 0;if(!1!==o.stroke&&(s=Math.min(s,_e(t,e,i)),!0===i.sector||!0===o.closed)){const n=ge(i,i.start),r=ge(i,i.start+i.sweep);!0===i.sector?(s=Math.min(s,I(t,e,i.center,n)),!0===o.closed&&(s=Math.min(s,I(t,e,r,i.center)))):s=Math.min(s,I(t,e,r,n))}continue}const i=o.points;if(!0===o.fill&&!0===n.style.fill&&(n.style.fillOpacity??.12)>0&&ue(t,e,i))return 0;if(!1!==o.stroke){for(let n=1;n<i.length;n++)s=Math.min(s,I(t,e,i[n-1],i[n]));!0===o.closed&&(s=Math.min(s,I(t,e,i[i.length-1],i[0])))}}return Number.isFinite(s)?s:null}(t,i,e(n),n.drawing,n.rc.dpr)}}const Me=st([U,Y,q]),Pe=[{ratio:0},{ratio:.5},{ratio:1}],ke=[0,.382,.618,1,1.272,1.618,2,2.618,3.618,4.236].map(t=>({ratio:t})),Se=[0,.382,.5,.618,1].map(t=>({ratio:t,color:a(t)})),Te=(t,e)=>({points:[t,e]});function Ie(t,e,i){const n=e.x-t.x;if(0===n)return[t,e];const r=!0===i.drawing.style.extendLeft?0:Math.min(t.x,e.x),s=!0===i.drawing.style.extendRight?i.rc.plotWidth:Math.max(t.x,e.x),o=i=>({x:i,y:t.y+(e.y-t.y)*(i-t.x)/n});return n>0?[o(r),o(s)]:[o(s),o(r)]}function Oe(t,e){const[i,n]=t.pts,r=he(i,n,t),s=he(e[0],e[1],t),o=[];if(!0===t.drawing.style.fill){const r=Ie(i,n,t),s=Ie(e[0],e[1],t);o.push({points:de([r[0],r[1],s[1],s[0]],t.rc),closed:!0,fill:!0,stroke:!1})}return o.push({points:r},{points:s}),{paths:o}}const Fe=we({id:"disjoint-channel",name:"Disjoint Channel",points:4,alertValue:k("disjoint"),alertLevels:P,defaultStyle:{fill:!0},settings:Me},t=>t.pts.length<4?{paths:[]}:Oe(t,t.pts.slice(2,4))),Le=we({id:"flat-top-bottom",name:"Flat Top/Bottom",points:3,alertValue:k("flat"),alertLevels:P,defaultStyle:{fill:!0},settings:Me,constrain(t){const e=t.map(t=>({...t}));return e.length>=3&&(e[2].time=(e[0].time+e[1].time)/2),e}},t=>t.pts.length<3?{paths:[]}:Oe(t,[{x:t.pts[0].x,y:t.pts[2].y},{x:t.pts[1].x,y:t.pts[2].y}])),Ae=we({id:"regression-channel",name:"Regression Channel",points:2,defaultStyle:{fill:!0,showLabels:!0},settings:st([U,Y,q,Z,tt,{path:"props.deviation",label:"Deviation multiplier",kind:"number",min:.01,max:20,step:.1,group:"behavior"}])},t=>{if(t.pts.length<2)return{paths:[]};const e=t.rc.bars?.()??[],[i,n]=t.drawing.points,r=Pt(e,Math.min(i.time,n.time)),s=Pt(e,Math.max(i.time,n.time),!0);let o=0,l=0,a=0,c=0,h=0,d=0,u=0,p=0,f=0,y=0;for(let i=r;i<s;i++){const n=e[i],r=n.close,s=t.rc.dataLayer.timeToIndex?.(n.time)??t.rc.dataLayer.timeToIndexFloat(n.time);if(!Number.isFinite(s)||!Number.isFinite(r))continue;0===o&&(u=n.time,f=s),p=n.time,y=s,o++;const x=s-l,g=r-a;l+=x/o,a+=g/o,c+=x*(s-l),h+=x*(r-a),d+=g*(r-a)}if(0===o)return{paths:[],labels:!1===t.drawing.style.showLabels?[]:[{at:t.pts[0],text:"No bars in range"}]};const x=c>0?h/c:0,g=Math.sqrt(Math.max(0,d-x*h)/o)*ae(t.drawing,"deviation",2,.01,20),m=d>0?Math.max(0,Math.min(1,x*h/d)):1,_=(e,i,n)=>{return Ct(t.rc,{time:e,price:(r=i,a+x*(r-l)+n)});var r},b=[0,g,-g].map(e=>({points:he(_(u,f,e),_(p,y,e),t)}));if(!0===t.drawing.style.fill){const e=Ie(_(u,f,g),_(p,y,g),t),i=Ie(_(u,f,-g),_(p,y,-g),t);b.push({points:de([e[0],e[1],i[1],i[0]],t.rc),closed:!0,fill:!0,stroke:!1})}return{paths:b,labels:!1===t.drawing.style.showLabels?[]:[{at:_(u,f,g),text:`R^2 ${m.toFixed(3)} ${o} bars`}]}});function ze(t,e,i){return we({id:t,name:e,points:3,defaultStyle:{fill:!0,showLabels:!0,levels:f(Pe)},settings:st([U,Y,Q,tt])},t=>{if(t.pts.length<3)return{paths:[]};const[e,n,s]=t.pts,o=se(n,s),[l,a]=t.drawing.points,c={time:"schiff"===i?l.time:(l.time+a.time)/2,price:(l.price+a.price)/2},h="standard"===i?e:Ct(t.rc,c),u="inside"===i?o:h,p="inside"===i?{x:s.x-h.x,y:s.y-h.y}:{x:o.x-h.x,y:o.y-h.y},f=e=>ce(e,{x:e.x+p.x,y:e.y+p.y},t.rc,0,1/0),y=[],x=[],g=r(t.drawing.style.levels,Pe);for(const e of g){const i=e.color,r=0===e.ratio?[u]:[oe(o,n,e.ratio),oe(o,s,e.ratio)];for(const n of r){const r=f(n);y.push({points:r,color:i}),!1!==t.drawing.style.showLabels&&2===r.length&&x.push({at:{x:r[0].x+4,y:r[0].y-4},text:e.label??d(e.ratio),color:i})}}const m=g.reduce((t,e)=>Math.max(t,Math.abs(e.ratio)),0);if(!0===t.drawing.style.fill&&m>0){const e=oe(o,n,m),i=oe(o,s,m),r=Math.hypot(p.x,p.y);if(r>0){const n=(Math.max(Math.hypot(e.x,e.y),Math.hypot(i.x,i.y))+Math.hypot(t.rc.plotWidth,t.rc.plotHeight))/r+1,s=t=>({x:t.x+p.x*n,y:t.y+p.y*n});y.unshift({points:de([e,s(e),s(i),i],t.rc),closed:!0,fill:!0,stroke:!1})}}return y.push(Te(n,s)),"inside"===i&&y.push(Te(h,s),Te(e,n)),{paths:y,labels:x}})}const Ne=we({id:"info-line",name:"Info Line",points:2,angleLock:!0,defaultStyle:{showLabels:!0},settings:st([U,q,Z,tt])},t=>{if(t.pts.length<2)return{paths:[]};const[e,i]=t.pts,[n,r]=t.drawing.points,s=r.price-n.price,o=s>=0?"+":"",l=0===n.price?"n/a":`${o}${(s/Math.abs(n.price)*100).toFixed(2)}%`,a=Math.abs(Math.round(t.rc.dataLayer.timeToIndexFloat(r.time)-t.rc.dataLayer.timeToIndexFloat(n.time)));return{paths:[{points:he(e,i,t)}],labels:!1===t.drawing.style.showLabels?[]:[{at:{x:(e.x+i.x)/2,y:(e.y+i.y)/2-8},text:`${o}${t.rc.priceScale.format(s)} (${l}) ${a} bars`}]}}),Ce=we({id:"trend-angle",name:"Trend Angle",points:2,angleLock:!0,alertValue:w(),defaultStyle:{showLabels:!0},settings:st([U,Z,tt])},t=>{if(t.pts.length<2)return{paths:[]};const[e,i]=t.pts,n=Math.atan2(i.y-e.y,i.x-e.x),r=Math.max(12,Math.min(40,Math.hypot(i.x-e.x,i.y-e.y)/3));return{paths:[Te(e,i),Te(e,{x:e.x+1.5*r,y:e.y}),{points:pe(e,r,r,0,n)}],labels:!1===t.drawing.style.showLabels?[]:[{at:{x:e.x+r+6,y:e.y-6},text:`${(180*-n/Math.PI).toFixed(1)} deg`}]}}),$e=we({id:"fib-extension-two-point",name:"Fib Extension (Two Point)",points:2,alertValue:T(2,ke),alertLevels:S(ke),defaultStyle:{levels:f(ke),showLabels:!0,fill:!0,fillOpacity:.06},settings:st([U,Q,Y,q,tt])},t=>{if(t.pts.length<2)return{paths:[]};const[e,i]=t.pts,[n,s]=t.drawing.points,o=[],l=[],c=r(t.drawing.style.levels,ke);if(!0===t.drawing.style.fill&&e.x!==i.x){const r=c.map(e=>t.rc.priceScale.priceToY(n.price+(s.price-n.price)*e.ratio)).filter(Number.isFinite).sort((t,e)=>t-e),l=!0===t.drawing.style.extendLeft?0:Math.min(e.x,i.x),a=!0===t.drawing.style.extendRight?t.rc.plotWidth:Math.max(e.x,i.x);for(let e=1;e<r.length;e++)r[e]!==r[e-1]&&o.push({points:de([{x:l,y:r[e-1]},{x:a,y:r[e-1]},{x:a,y:r[e]},{x:l,y:r[e]}],t.rc),closed:!0,fill:!0,stroke:!1})}o.push(Te(e,i));for(const r of c){const c=n.price+(s.price-n.price)*r.ratio,h=t.rc.priceScale.priceToY(c),u=r.color??a(r.ratio);o.push({points:he({x:e.x,y:h},{x:i.x,y:h},t),color:u}),!1!==t.drawing.style.showLabels&&l.push({at:{x:Math.min(e.x,i.x)+4,y:h-3},text:`${r.label??d(r.ratio)} ${t.rc.priceScale.format(c)}`,color:u})}return{paths:o,labels:l}});function De(t,e){if(t.pts.length<2)return{paths:[]};const[i,n]=t.pts,s=[],o=[];s.push({points:[{x:i.x,y:n.y},n,{x:n.x,y:i.y}]});const l=1.2*(t.drawing.text?.fontSize??11),c=[],h=(n,r,s,a,h)=>{const d=Math.min(i.x,r.x),u=Math.max(i.x,r.x),p=Math.min(i.y,r.y),f=Math.max(i.y,r.y);if(!e||!1===t.drawing.style.showLabels||c.length>=32)return;const y=e(a);if(!(!Number.isFinite(y)||y<=0||!Number.isFinite(l)||l<=0||(s?f-p<l:u-d<y)))for(const e of[0,-l,l]){let x,g;s?(x=r.x>=i.x?r.x+4:r.x-y-4,(x<0||x+y>t.rc.plotWidth)&&(x=r.x>=i.x?r.x-y-4:r.x+4),g=Math.max(p+l,Math.min(f,n.y+l/2+e))):(x=Math.max(d,Math.min(u-y,n.x-y/2+e)),g=r.y<i.y?r.y-4:r.y+l+4,(g-l<0||g>t.rc.plotHeight)&&(g=r.y<i.y?r.y+l+4:r.y-4));const m={x:x,y:g-l,width:y,height:l};if(!(x<0||x+y>t.rc.plotWidth||m.y<0||g>t.rc.plotHeight)&&!c.some(t=>x<t.x+t.width+3&&x+y+3>t.x&&m.y<t.y+t.height+3&&m.y+l+3>t.y))return c.push(m),void o.push({at:{x:x,y:g},text:a,color:h})}};for(const e of r(t.drawing.style.levels,Se)){const r=[{x:n.x,y:i.y+(n.y-i.y)*e.ratio}];1!==e.ratio&&r.push({x:i.x+(n.x-i.x)*e.ratio,y:n.y}),r.forEach((r,o)=>{const l=ce(i,r,t.rc,0,1/0),c=e.color??a(e.ratio);if(s.push({points:l,color:c}),2===l.length){const t={x:i.x+(Math.sign(r.x-i.x)||Math.sign(n.x-i.x))*Math.abs(n.x-i.x),y:i.y+(Math.sign(r.y-i.y)||Math.sign(n.y-i.y))*Math.abs(n.y-i.y)},s=Math.abs(e.ratio),l=oe(i,r,1/Math.max(1,s));h(l,t,s<=1?0===o:0!==o,e.label??String(e.ratio),c)}})}return{paths:s,labels:o}}const je={...we({id:"fib-speed-resistance-fan",name:"Fib Speed Resistance Fan",points:2,defaultStyle:{levels:f(Se),showLabels:!0},settings:st([U,Q,tt])},t=>De(t)),draw(t){const{ctx:e,rc:i}=t,n=t.drawing.text;let r;e.save();try{e.font=Wt(Bt(t.drawing),(n?.fontSize??11)*i.dpr),r=De({rc:i,drawing:{...t.drawing,style:t.style},pts:t.pts.map(t=>({x:t.x/i.dpr,y:t.y/i.dpr}))},t=>e.measureText(t).width/i.dpr)}finally{e.restore()}ve(t,r)}},He=we({id:"icon-stamp",name:"Icon Stamp",points:1,defaultStyle:{fill:!0,fillOpacity:.8},settings:st([U,Y,{path:"props.shape",label:"Shape",kind:"select",group:"behavior",options:["star","diamond","circle","arrow up","arrow down","check","cross"].map(t=>({value:t.replace(" ","-"),label:t[0].toUpperCase()+t.slice(1)}))},{path:"props.size",label:"Size",kind:"number",min:8,max:160,step:2,group:"behavior"}])},t=>{if(t.pts.length<1)return{paths:[]};const e=t.pts[0],i=ae(t.drawing,"size",28,8,160)/2,n=(t,n)=>({x:e.x+t*i,y:e.y+n*i}),r=t.drawing.props?.shape;let s;if("diamond"===r)s=[n(0,-1),n(1,0),n(0,1),n(-1,0)];else if("circle"===r)s=pe(e,i,i,0,2*Math.PI);else if("arrow-up"===r||"arrow-down"===r){const t="arrow-up"===r?1:-1;s=[[0,-1],[1,0],[.35,0],[.35,1],[-.35,1],[-.35,0],[-1,0]].map(([e,i])=>n(e,i*t))}else s="check"===r?[[-1,0],[-.65,-.3],[-.2,.2],[.75,-.85],[1,-.55],[-.2,.85]].map(([t,e])=>n(t,e)):"cross"===r?[[-1,-.65],[-.65,-1],[0,-.35],[.65,-1],[1,-.65],[.35,0],[1,.65],[.65,1],[0,.35],[-.65,1],[-1,.65],[-.35,0]].map(([t,e])=>n(t,e)):Array.from({length:10},(t,e)=>{const i=-Math.PI/2+e*Math.PI/5,r=e%2==0?1:.45;return n(Math.cos(i)*r,Math.sin(i)*r)});return{paths:[{points:s,closed:!0,fill:!0}]}}),Be=[Fe,Le,Ae,ze("pitchfork","Pitchfork","standard"),ze("schiff-pitchfork","Schiff Pitchfork","schiff"),ze("modified-schiff-pitchfork","Modified Schiff Pitchfork","modified"),ze("inside-pitchfork","Inside Pitchfork","inside"),Ne,Ce,$e,je,He],We=2*Math.PI,Re=(1+Math.sqrt(5))/2,Ve=t=>t.map(t=>({ratio:t})),Ee=Ve([.236,.382,.5,.618,.786,1,1.618,2.618]),Je=Ee.slice(0,6),Ke=Ve([0,.382,.618,1,1.382,1.618,2,2.382,2.618,3]),Ue=Ve([0,.25,.382,.5,.618,.75,1]),Ye=Ve(Array.from({length:12},(t,e)=>e+1)),qe=Ve([.236,.382,.5,.618,.786,1,1.618,2.618,4.236,6.854,11.09]),Ge=st([U,Q,tt]),Xe=st([U,Y,Q,tt]),Ze=(t,e,i)=>({points:[t,e],color:i}),Qe=(t,e,i=e,n=0,r=We,s)=>({points:[],arc:{center:t,rx:e,ry:i,start:n,sweep:r},color:s}),ti=(t,e=2)=>t.pts.length>=e&&t.pts.every(le),ei=(t,e,i)=>!1===t.drawing.style.showLabels?[]:[{at:i,text:e.label??String(e.ratio),color:e.color}];function ii(t){return ti(t)?{paths:[Ze(t.pts[0],t.pts[1])]}:{paths:[]}}const ni=we({id:"trend-fib-time",name:"Trend Fib Time",points:3,defaultStyle:{levels:f(Ke)},settings:Ge},t=>{if(!ti(t,3))return ii(t);const[e,i,n]=t.drawing.points,s=e=>t.rc.dataLayer.timeToIndexFloat(e),o=s(i.time)-s(e.time),l=s(n.time),a=[],c=[];for(const e of r(t.drawing.style.levels,Ke)){const i=t.rc.timeScale.indexToX(l+o*e.ratio);!Number.isFinite(i)||i<0||i>t.rc.plotWidth||(a.push(Ze({x:i,y:0},{x:i,y:t.rc.plotHeight},e.color)),c.push(...ei(t,e,{x:i+3,y:15})))}return{paths:a,labels:c}});function ri(t,e,i){const n="wedge"===i?Je:Ee;return we({id:t,name:e,points:"wedge"===i?3:2,defaultStyle:{fill:!1,levels:f(n)},settings:Xe},t=>{if(!ti(t,"wedge"===i?3:2))return ii(t);const[e,s,o]=t.pts,l=Math.hypot(s.x-e.x,s.y-e.y);if(!Number.isFinite(l)||0===l)return ii(t);let a=0,c=We;const h=[],d=[];if("circle"!==i)if(a=Math.atan2(s.y-e.y,s.x-e.x),h.push(Ze(e,s)),"arc"===i)a-=Math.PI/2,c=Math.PI;else{const t=Math.atan2(o.y-e.y,o.x-e.x);c=(t-a+3*Math.PI)%We-Math.PI,h.push(Ze(e,{x:e.x+l*Math.cos(t),y:e.y+l*Math.sin(t)}))}let u=0;for(const s of r(t.drawing.style.levels,n)){const n=l*s.ratio;if(!(n>0&&Number.isFinite(n)))continue;u=Math.max(u,n),h.push(Qe(e,n,n,a,c,s.color));const r="circle"===i?0:a+c/2;d.push(...ei(t,s,{x:e.x+n*Math.cos(r)+3,y:e.y+n*Math.sin(r)}))}if(u>0&&!0===t.drawing.style.fill){const t=Qe(e,u,u,a,c);t.arc.sector="circle"!==i,h.unshift({...t,fill:!0,stroke:!1,closed:!0})}return{paths:h,labels:d}})}const si=we({id:"fib-spiral",name:"Fib Spiral",points:2,settings:st([U])},t=>{if(!ti(t))return{paths:[]};const[e,i]=t.pts,n=Math.hypot(i.x-e.x,i.y-e.y);if(!Number.isFinite(n)||n<.5)return ii(t);const r=Math.log(Re)/(Math.PI/2),s=Math.atan2(i.y-e.y,i.x-e.x),o=Math.max(-16*Math.PI,Math.log(.5/n)/r),l=[],a=[o];for(let t=Math.ceil(o/(Math.PI/2));t<2;t++)a.push(t*Math.PI/2);a.push(Math.PI);for(let t=1;t<a.length;t++){const i=a[t-1],o=a[t],c=Math.max(2,Math.min(32,Math.ceil((o-i)*Math.sqrt(n*Math.exp(r*o)/.8))));for(let a=1===t?0:1;a<=c;a++){const t=i+(o-i)*a/c,h=n*Math.exp(r*t);l.push({x:e.x+h*Math.cos(s+t),y:e.y+h*Math.sin(s+t)})}}return{paths:[{points:l}]}}),oi=we({id:"gann-square",name:"Gann Square",points:2,defaultStyle:{fill:!1,levels:f(Ue)},settings:Xe},t=>{if(!ti(t))return{paths:[]};const[e,i]=t.pts,[n,s]=t.drawing.points,o=i.x-e.x,l=i.y-e.y,a=Math.min(e.x,i.x),c=Math.max(e.x,i.x),h=Math.min(e.y,i.y),d=Math.max(e.y,i.y),u=[],p=[];!0===t.drawing.style.fill&&u.push({points:[{x:a,y:h},{x:c,y:h},{x:c,y:d},{x:a,y:d}],closed:!0,fill:!0,stroke:!1});const f=t.rc.dataLayer.timeToIndexFloat(n.time),y=t.rc.dataLayer.timeToIndexFloat(s.time);for(const e of r(t.drawing.style.levels,Ue)){const i=t.rc.timeScale.indexToX(f+(y-f)*e.ratio),r=t.rc.priceScale.priceToY(n.price+(s.price-n.price)*e.ratio);u.push(Ze({x:a,y:r},{x:c,y:r},e.color),Ze({x:i,y:h},{x:i,y:d},e.color)),p.push(...ei(t,e,{x:a+3,y:r-3}))}for(const[i,n,r]of[[1,1/3,"3x1"],[1,.5,"2x1"],[1,1,"1x1"],[.5,1,"1x2"],[1/3,1,"1x3"]]){const s={x:e.x+o*i,y:e.y+l*n};u.push(Ze(e,s)),!1!==t.drawing.style.showLabels&&p.push({at:{x:s.x+3,y:s.y},text:r})}if(0!==o&&0!==l)for(const t of[.25,.5,.75,1])u.push(Qe(e,Math.abs(o)*t,Math.abs(l)*t,o>0?0:Math.PI,Math.sign(o*l)*Math.PI/2));return{paths:u,labels:p}});function li(t,e,i,n,r,s){const o=[-Math.PI,0];for(const r of[i,n]){const i=(r-t.x)/e;Math.abs(i)<1&&o.push(-Math.acos(i))}for(const i of[r,s]){const n=(i-t.y)/e;if(n>-1&&n<0){const t=Math.asin(n);o.push(t,-Math.PI-t)}}o.sort((t,e)=>t-e);const l=[];for(let a=1;a<o.length;a++){const c=o[a-1],h=o[a]-c;if(h<1e-12)continue;const d=c+h/2,u=t.x+e*Math.cos(d),p=t.y+e*Math.sin(d);u<i||u>n||p<r||p>s||l.push(Qe(t,e,e,c,h))}return l}const ai=we({id:"dedekind-tessellation",name:"Dedekind Tessellation",points:2,settings:st([U,{path:"props.maxCurvature",label:"Max curvature",kind:"number",min:1,max:64,step:1,group:"behavior"}])},t=>{if(!ti(t))return{paths:[]};const[e,i]=t.pts,n=Math.min(e.x,i.x),r=Math.max(e.x,i.x),s=Math.min(e.y,i.y),o=Math.max(e.y,i.y),l=o-s;if(l<.75||r-n<.75||!Number.isFinite(l))return ii(t);const a=Math.max(0,n),c=Math.min(t.rc.plotWidth,r),h=Math.max(0,s),d=Math.min(t.rc.plotHeight,o);if(a>c||h>d)return{paths:[]};const u=[{x:n,y:s},{x:r,y:s},{x:r,y:o},{x:n,y:o}],p=u.map((e,i)=>({points:ce(e,u[(i+1)%4],t.rc)})),f=(a-n)/l,y=(c-n)/l,x=Math.ceil(f-.5)+.5,g=Math.min(2048,Math.floor(y-x)+1);for(let t=0;t<g;t++){const e=n+(x+t)*l;p.push(Ze({x:e,y:d},{x:e,y:h}))}const m=Math.min(Math.round(ae(t.drawing,"maxCurvature",24,1,64)),Math.floor(l/.75));for(let t=1;t<=m&&p.length<4096;t++){if(t%2==0&&t%8!=0)continue;const e=l/t;if(!(o-e>d))for(let i=0;i<t&&p.length<4096;i++){const r=i*i-1;if(r%t!==0||t%8==0&&Math.abs(r/t)%2!=1)continue;const s=Math.ceil(f-1/t-i/t),u=Math.floor(y+1/t-i/t),x=Math.min(4096-p.length,u-s+1);for(let r=0;r<x;r++){const u={x:n+(s+r+i/t)*l,y:o};p.push(...li(u,e,a,c,h,d))}}}return{paths:p}});function ci(t,e,i,n){const s=i?qe:Ye;return we({id:t,name:e,points:2,defaultStyle:{levels:f(s)},settings:st([U,Q,tt,...i?[]:[{path:"props.waveCount",label:"Wave limit",kind:"number",min:1,max:12,step:1,group:"behavior"}],...n?[{path:"props.mach",label:"Mach number",kind:"number",min:1.01,max:20,step:.5,group:"behavior"}]:[]])},t=>{if(!ti(t))return{paths:[]};const[e,o]=t.pts,l=se(e,o),a=Math.hypot(o.x-e.x,o.y-e.y)/2;if(!Number.isFinite(a)||a<.5)return ii(t);const c=(o.x-e.x)/(2*a),h=(o.y-e.y)/(2*a),d=n?ae(t.drawing,"mach",2,1.01,20):1,u={x:l.x-d*a*c,y:l.y-d*a*h},p=r(t.drawing.style.levels,s).filter(t=>t.ratio>0).slice().sort((t,e)=>t.ratio-e.ratio);i||p.splice(Math.round(ae(t.drawing,"waveCount",6,1,12)));const f=[],y=[];let x=0;for(const e of p){const i=a*e.ratio,n={x:u.x+d*i*c,y:u.y+d*i*h};Number.isFinite(i)&&le(n)&&(x=Math.max(x,i),f.push(Qe(n,i,i,0,We,e.color)),y.push(...ei(t,e,{x:n.x+c*i+4,y:n.y+h*i})))}if(0===x)return{paths:[]};const g=d*x+2*a;if(n){const t=1/d,e=Math.sqrt(1-t*t);for(const i of[-1,1])f.push(Ze(u,{x:u.x+g*(c*e-i*h*t),y:u.y+g*(h*e+i*c*t)}))}else f.push(Ze({x:u.x-h*g,y:u.y+c*g},{x:u.x+h*g,y:u.y-c*g}));return{paths:f,labels:y}})}const hi=[ni,ri("fib-circles","Fib Circles","circle"),ri("fib-speed-resistance-arcs","Fib Speed Resistance Arcs","arc"),ri("fib-wedge","Fib Wedge","wedge"),si,oi,ai,ci("sonic","Sonic",!1,!1),ci("supersonic","Supersonic",!1,!0),ci("golden-sonic","Golden Sonic",!0,!1),ci("golden-supersonic","Golden Supersonic",!0,!0)],di={min:1.272,max:1.414},ui={min:.74,max:.83},pi={gartley:{ab:{min:.55,max:.68},bc:{min:.382,max:.886},cd:{min:1.13,max:1.618},ad:{min:.74,max:.83}},bat:{ab:{min:.382,max:.5},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:.84,max:.92}},butterfly:{ab:{min:.74,max:.83},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:1.272,max:1.618}},crab:{ab:{min:.382,max:.618},bc:{min:.382,max:.886},cd:{min:2.618,max:3.618},ad:{min:1.55,max:1.69}},shark:{ab:{min:.382,max:.618},bc:{min:1.13,max:1.618},cd:{min:1.618,max:2.24},ad:{min:.886,max:1.13}}},fi=st([U,Z,tt]),yi=st([U,Y,Z,tt]),xi=(t,e,i)=>({points:ce(t,e,i.rc)});function gi(t,e){return Number.isFinite(t)&&Number.isFinite(e)&&Math.abs(e)>=1e-9?Math.abs(t)/Math.abs(e):null}function mi(t,e,i){const n=t[e]?.price,r=t[i]?.price;return Number.isFinite(n)&&Number.isFinite(r)?Math.abs(r-n):NaN}function _i(t){return null!==t.value&&void 0!==t.band&&t.value>=t.band.min&&t.value<=t.band.max}function bi(t,e,i,n){const r=e.x-t.x,s=e.y-t.y,o=n.x-i.x,l=n.y-i.y,a=o*s-l*r;if(!Number.isFinite(a)||Math.abs(a)<1e-9)return null;const c=((i.y-t.y)*r-(i.x-t.x)*s)/a;return!Number.isFinite(c)||c<0||c>1?null:{x:i.x+c*o,y:i.y+c*l}}function vi(t,e){const i=e.pts.slice(0,t.labels.length),n=e.drawing.points.slice(0,t.labels.length);if(i.length<2)return{paths:[]};const r=[];if(!0===t.fill)for(const t of[[0,1,2],[2,3,4]]){const n=t.map(t=>i[t]);n.every(t=>void 0!==t&&le(t))&&r.push({points:de(n,e.rc),closed:!0,fill:!0,stroke:!1})}for(let t=1;t<i.length;t++)r.push(xi(i[t-1],i[t],e));if(void 0!==t.neckline&&i.length>=t.labels.length){const[n,s]=t.neckline,o=i[n],l=i[s],a=bi(o,l,i[0],i[1])??o,c=i.length-1,h=bi(o,l,i[c-1],i[c])??l;r.push(...function(t,e,i){const n=ce(t,e,i.rc);if(n.length<2)return[];const[r,s]=n,o=s.x-r.x,l=s.y-r.y,a=Math.hypot(o,l);if(!(a>0&&Number.isFinite(a)))return[{points:n}];const c=[];for(let t=0;t<a;t+=12){const e=t/a,i=Math.min(t+7,a)/a;c.push({points:[{x:r.x+o*e,y:r.y+l*e},{x:r.x+o*i,y:r.y+l*i}]})}return c}(a,h,e))}if(!1===e.drawing.style.showLabels)return{paths:r};const s=function(t,e){return e.flatMap((i,n)=>{const r=t.labels[n];if(!r||!le(i))return[];const s=e[n-1]?.y??i.y,o=e[n+1]?.y??i.y,l=i.y<=(s+o)/2;return[{at:{x:i.x+4,y:i.y+(l?-6:14)},text:r}]})}(t,i),o=void 0!==t.harmonic?function(t,e){const i=mi(t,0,1),n=mi(t,1,2);if("cypher"===e){const e=mi(t,0,3);return[{name:"AB/XA",value:gi(n,i),band:{min:.382,max:.618},anchor:2},{name:"XC/XA",value:gi(e,i),band:di,anchor:3},{name:"CD/XC",value:gi(mi(t,3,4),e),band:ui,anchor:4}]}const r=mi(t,2,3);return[{name:"AB/XA",value:gi(n,i),band:e.ab,anchor:2},{name:"BC/AB",value:gi(r,n),band:e.bc,anchor:3},{name:"CD/BC",value:gi(mi(t,3,4),r),band:e.cd,anchor:4},{name:"AD/XA",value:gi(mi(t,1,4),i),band:e.ad,anchor:4}]}(n,t.harmonic):void 0!==t.ratios?function(t,e){if("xabcd"===e){const e=mi(t,0,1),i=mi(t,1,2),n=mi(t,2,3);return[{name:"AB/XA",value:gi(i,e),anchor:2},{name:"BC/AB",value:gi(n,i),anchor:3},{name:"CD/BC",value:gi(mi(t,3,4),n),anchor:4}]}const i=mi(t,0,1),n=mi(t,1,2);return[{name:"BC/AB",value:gi(n,i),anchor:2},{name:"CD/BC",value:gi(mi(t,2,3),n),anchor:3}]}(n,t.ratios):[];if(s.push(...function(t,e){const i=[];for(let n=0;n<t.length;n++){const r=t[n];if(null===r.value||!Number.isFinite(r.value))continue;const s=e[r.anchor],o=e[Math.max(0,r.anchor-1)];if(!(s&&o&&le(s)&&le(o)))continue;const l=void 0!==r.band,a=l&&_i(r),c=l?a?" OK":" OUT":"",h=se(o,s);i.push({at:{x:h.x+6,y:h.y+(n===t.length-1&&r.anchor===t[n-1]?.anchor?14:-3)},text:`${r.name} ${r.value.toFixed(3)}${c}`,color:l?a?Yt:qt:void 0})}return i}(o,i)),void 0!==t.harmonic&&i.length>=t.labels.length){const e=function(t,e){if(t.length<e)return!1;let i=t[1].price-t[0].price;if(!Number.isFinite(i)||0===i)return!1;for(let n=2;n<e;n++){const e=t[n].price-t[n-1].price;if(!Number.isFinite(e)||0===e||Math.sign(e)===Math.sign(i))return!1;i=e}return!0}(n,t.labels.length),r=e&&o.length>0&&o.every(_i),l=i[t.labels.length-1];l&&le(l)&&s.push({at:{x:l.x+4,y:l.y+30},text:`${t.name}: ${e?r?"valid":"outside range":"invalid sequence"}`,color:r?Yt:qt})}return{paths:r,labels:s}}function wi(t){return we({id:t.id,name:t.name,points:t.labels.length,defaultStyle:!0===t.fill?{fill:!0,fillOpacity:.12,showLabels:!0}:{showLabels:!0},settings:!0===t.fill?yi:fi},e=>vi(t,e))}const Mi=["X","A","B","C","D"],Pi=[wi({id:"xabcd-pattern",name:"XABCD Pattern",labels:Mi,fill:!0,ratios:"xabcd"}),wi({id:"abcd-pattern",name:"ABCD Pattern",labels:["A","B","C","D"],ratios:"abcd"}),wi({id:"elliott-impulse",name:"Elliott Impulse",labels:["1","2","3","4","5"]}),wi({id:"elliott-correction",name:"Elliott Correction",labels:["A","B","C"]}),wi({id:"head-shoulders",name:"Head and Shoulders",labels:["","LS","","H","","RS",""],neckline:[2,4]}),wi({id:"gartley",name:"Gartley",labels:Mi,fill:!0,harmonic:pi.gartley}),wi({id:"bat",name:"Bat",labels:Mi,fill:!0,harmonic:pi.bat}),wi({id:"butterfly",name:"Butterfly",labels:Mi,fill:!0,harmonic:pi.butterfly}),wi({id:"crab",name:"Crab",labels:Mi,fill:!0,harmonic:pi.crab}),wi({id:"shark",name:"Shark",labels:Mi,fill:!0,harmonic:pi.shark}),wi({id:"cypher",name:"Cypher",labels:Mi,fill:!0,harmonic:"cypher"})],ki=new Map;function Si(t){ki.set(t.id,t)}function Ti(t){const e=ki.get(t);if(void 0===e)throw new Error(`openalgo-charts: unknown drawing tool "${t}"`);return e}function Ii(t){return ki.has(t)}function Oi(t){return!0===ki.get(t)?.viewport}function Fi(){return Array.from(ki.values())}function Li(t){const e=t.split("+").map(t=>t.trim().toLowerCase());return{key:e[e.length-1]??"",alt:e.includes("alt"),ctrl:e.includes("ctrl")||e.includes("control"),shift:e.includes("shift")}}function Ai(t){const e=t.key??"",i=!0!==t.altKey||/^[a-z]$/i.test(e)?null:/^Key([A-Z])$/.exec(t.code??""),n=(null!==i?i[1]:e).toLowerCase();if(""===n)return null;const r=!0===t.altKey,s=!0===t.ctrlKey||!0===t.metaKey,o=!0===t.shiftKey;if(!r&&!s)return null;for(const t of ki.values()){if(void 0===t.shortcut)continue;const e=Li(t.shortcut);if(e.key===n&&e.alt===r&&e.ctrl===s&&e.shift===o)return t.id}return null}function zi(){return Object.fromEntries(Array.from(ki.values(),t=>[t.id,t.shortcut]).filter(t=>void 0!==t[1]))}const Ni=st([U]);function Ci(t){return ki.get(t)?.settings??Ni}function $i(t){return t.color??a(t.ratio)}function Di(t){return t.label??d(t.ratio)}const ji=st([U,Q,Y,q,tt]);function Hi(t,e,i){return{id:t,name:e,points:i,alertValue:T(i,y),alertLevels:S(y),defaultStyle:{showLabels:!0,levels:f(y),fill:!0,fillOpacity:.06},settings:ji,draw:t=>{const e=r(t.style.levels,y),n=t.drawing.points,s=t.rc.dpr,o=2===i?n[0].price:n[2].price,l=n[1].price-n[0].price,a=Math.min(t.pts[0].x,t.pts[i-1].x),c=Math.max(t.pts[0].x,t.pts[i-1].x),h=!0===t.style.extendLeft?0:a,d=!0===t.style.extendRight?t.rc.plotWidth*s:c;$t(t),t.ctx.beginPath(),t.ctx.moveTo(t.pts[0].x,t.pts[0].y),t.ctx.lineTo(t.pts[1].x,t.pts[1].y),3===i&&t.ctx.lineTo(t.pts[2].x,t.pts[2].y),t.ctx.stroke();let u=null;for(const i of e){const e=o+l*i.ratio,n=Math.round(t.rc.priceScale.priceToY(e)*s)+.5,r=$i(i);!0===t.style.fill&&null!==u&&(t.ctx.save(),t.ctx.globalAlpha=t.style.fillOpacity??.06,t.ctx.fillStyle=t.style.fillColor??r,t.ctx.fillRect(h,Math.min(u,n),d-h,Math.abs(n-u)),t.ctx.restore()),u=n,t.ctx.strokeStyle=r,t.ctx.beginPath(),t.ctx.moveTo(h,n),t.ctx.lineTo(d,n),t.ctx.stroke(),!1!==t.style.showLabels&&Vt(t,`${Di(i)} ${t.formatPrice(e)}`,h+4*s,n-8*s,r)}t.ctx.setLineDash([])},distance:(t,e,n)=>{const s=r(n.drawing.style.levels,y),o=n.drawing.points,l=2===i?o[0].price:o[2].price,a=o[1].price-o[0].price,c=!0===n.drawing.style.extendLeft?0:Math.min(n.pts[0].x,n.pts[i-1].x),h=!0===n.drawing.style.extendRight?n.rc.plotWidth:Math.max(n.pts[0].x,n.pts[i-1].x);if(t<c-4||t>h+4)return null;let d=1/0;for(const t of s){const i=Math.abs(e-n.rc.priceScale.priceToY(l+a*t.ratio));i<d&&(d=i)}return d}}}const Bi=Hi("fib-retracement","Fib Retracement",2),Wi=Hi("fib-extension","Fib Extension",3),Ri=st([J,K,Q,tt]),Vi={id:"fib-channel",name:"Fib Channel",points:3,alertValue:T("channel",y),alertLevels:S(y),defaultStyle:{showLabels:!0,levels:f(y)},settings:st([J,K,Q,q,tt]),draw:t=>{const e=r(t.style.levels,y),[i,n,s]=t.pts,o=t.rc.dpr,l=s.x-n.x,a=s.y-n.y,c=!0===t.style.extendLeft,h=!0===t.style.extendRight;$t(t);for(const r of e){const[e,s]=D({x:i.x+l*r.ratio,y:i.y+a*r.ratio},{x:n.x+l*r.ratio,y:n.y+a*r.ratio},t.rc.plotWidth*o,c,h),d=$i(r);t.ctx.strokeStyle=d,t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.lineTo(s.x,s.y),t.ctx.stroke(),!1!==t.style.showLabels&&Vt(t,Di(r),n.x+l*r.ratio+4*o,n.y+a*r.ratio,d)}t.ctx.setLineDash([])},distance:(t,e,i)=>{const n=r(i.drawing.style.levels,y),[s,o,l]=i.pts,a=!0===i.drawing.style.extendLeft,c=!0===i.drawing.style.extendRight;let h=1/0;for(const r of n){const[n,d]=D({x:s.x+(l.x-o.x)*r.ratio,y:s.y+(l.y-o.y)*r.ratio},{x:o.x+(l.x-o.x)*r.ratio,y:o.y+(l.y-o.y)*r.ratio},i.rc.plotWidth,a,c),u=I(t,e,n,d);u<h&&(h=u)}return h}},Ei={id:"fib-time-zone",name:"Fib Time Zone",points:2,defaultStyle:{showLabels:!0,levels:f(_)},settings:st([U,Q,tt]),draw:t=>{const[e,i]=t.pts,n=i.x-e.x;if(Math.abs(n)<.5)return;const s=t.rc.dpr,o=t.rc.plotWidth*s,l=r(t.style.levels,_);$t(t);for(const i of l){const r=e.x+n*i.ratio;if(r<-10||r>o+10)continue;const l=i.color??t.style.color;t.ctx.strokeStyle=l,t.ctx.beginPath(),t.ctx.moveTo(Math.round(r)+.5,0),t.ctx.lineTo(Math.round(r)+.5,t.rc.plotHeight*s),t.ctx.stroke(),!1!==t.style.showLabels&&Vt(t,i.label??String(i.ratio),r+3*s,12*s,l)}t.ctx.setLineDash([])},distance:(t,e,i)=>{const[n,s]=i.pts,o=s.x-n.x;if(Math.abs(o)<.5)return null;let l=1/0;for(const e of r(i.drawing.style.levels,_))l=Math.min(l,Math.abs(t-(n.x+o*e.ratio)));return Number.isFinite(l)?l:null}},Ji={id:"fib-fan",name:"Fib Fan",points:2,defaultStyle:{showLabels:!0,levels:f(x)},settings:Ri,draw:t=>{const e=r(t.style.levels,x),[i,n]=t.pts,s=t.rc.dpr,o=t.rc.plotWidth*s;$t(t);for(const r of e){const e=D(i,{x:n.x,y:i.y+(n.y-i.y)*r.ratio},o,!1,!0)[1],l=$i(r);t.ctx.strokeStyle=l,t.ctx.beginPath(),t.ctx.moveTo(i.x,i.y),t.ctx.lineTo(e.x,e.y),t.ctx.stroke(),!1!==t.style.showLabels&&Vt(t,Di(r),n.x+4*s,i.y+(n.y-i.y)*r.ratio,l)}t.ctx.setLineDash([])},distance:(t,e,i)=>{const n=r(i.drawing.style.levels,x),[s,o]=i.pts;let l=1/0;for(const r of n)l=Math.min(l,I(t,e,s,D(s,{x:o.x,y:s.y+(o.y-s.y)*r.ratio},i.rc.plotWidth,!1,!0)[1]));return Number.isFinite(l)?l:null}},Ki={id:"gann-fan",name:"Gann Fan",points:2,defaultStyle:{showLabels:!0,levels:f(m)},settings:Ri,draw:t=>{const[e,i]=t.pts,n=t.rc.dpr,s=t.rc.plotWidth*n,o=i.x-e.x,l=i.y-e.y;if(Math.abs(o)<.5)return;const a=r(t.style.levels,m);$t(t),a.forEach((r,a)=>{const c=D(e,{x:e.x+o,y:e.y+l*r.ratio},s,!1,!0)[1],d=r.color??h(a);t.ctx.strokeStyle=d,t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.lineTo(c.x,c.y),t.ctx.stroke(),!1!==t.style.showLabels&&Vt(t,r.label??u(r.ratio),i.x+4*n,e.y+l*r.ratio,d)}),t.ctx.setLineDash([])},distance:(t,e,i)=>{const[n,s]=i.pts,o=s.x-n.x,l=s.y-n.y;if(Math.abs(o)<.5)return null;let a=1/0;for(const s of r(i.drawing.style.levels,m))a=Math.min(a,I(t,e,n,D(n,{x:n.x+o,y:n.y+l*s.ratio},i.rc.plotWidth,!1,!0)[1]));return Number.isFinite(a)?a:null}},Ui={id:"gann-box",name:"Gann Box",points:2,defaultStyle:{fill:!0,fillOpacity:.05,showLabels:!0,levels:f(g)},settings:st([U,Y,Q,tt]),draw:t=>{const[e,i]=t.pts,n=z(e,i),s=t.rc.dpr,o=t.drawing.points,l=r(t.style.levels,g);jt(t,()=>t.ctx.fillRect(n.x0,n.y0,n.x1-n.x0,n.y1-n.y0)),$t(t),t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.lineTo(i.x,i.y),t.ctx.stroke();for(const r of l){const l=Math.round(e.x+(i.x-e.x)*r.ratio)+.5,a=o[0].price+(o[1].price-o[0].price)*r.ratio,c=Math.round(t.rc.priceScale.priceToY(a)*s)+.5,h=$i(r);t.ctx.strokeStyle=h,t.ctx.beginPath(),t.ctx.moveTo(l,n.y0),t.ctx.lineTo(l,n.y1),t.ctx.moveTo(n.x0,c),t.ctx.lineTo(n.x1,c),t.ctx.stroke(),!1!==t.style.showLabels&&Vt(t,Di(r),n.x1+4*s,c,h)}t.ctx.setLineDash([])},distance:(t,e,i)=>C(t,e,i.pts[0],i.pts[1],!0===i.drawing.style.fill)},Yi=[{path:"style.accountSize",label:"Account size",kind:"number",min:0,step:1e3,group:"behavior"},{path:"style.risk",label:"Risk %",kind:"number",min:0,max:100,step:.1,group:"behavior"},{path:"props.showHeader",label:"Show direction and ratio",kind:"boolean",group:"behavior"},{path:"props.showLossSize",label:"Show loss and size",kind:"boolean",group:"behavior"},{path:"props.showTargetLabel",label:"Show target label",kind:"boolean",group:"behavior"},{path:"props.showStopLabel",label:"Show stop label",kind:"boolean",group:"behavior"},{path:"props.showPrices",label:"Show level prices",kind:"boolean",group:"behavior"},{path:"props.profitColor",label:"Profit zone",kind:"color",group:"fill"},{path:"props.lossColor",label:"Loss zone",kind:"color",group:"fill"}];function qi(t){const e=new Date(1e3*t),i=t=>String(t).padStart(2,"0");return`${e.getUTCFullYear()}-${i(e.getUTCMonth()+1)}-${i(e.getUTCDate())}`}function Gi(t){const e=Math.max(0,Math.round(Math.abs(t))),i=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return i>0?`${i}d ${n}h`:n>0?`${n}h ${r}m`:`${r}m`}const Xi=st([J,K,zt,Z,tt]),Zi={id:"measure",name:"Measure",points:2,defaultStyle:{fill:!0,showLabels:!0,fillOpacity:.14},settings:Xi,draw:t=>{const e=z(t.pts[0],t.pts[1]),i=t.rc.dpr,n=t.drawing.points,r=n[1].price-n[0].price,s=0!==n[0].price?r/n[0].price*100:0,o=r>=0,l=Ut(t,o);t.ctx.save(),t.ctx.globalAlpha=t.style.fillOpacity??.14,t.ctx.fillStyle=l,t.ctx.fillRect(e.x0,e.y0,e.x1-e.x0,e.y1-e.y0),t.ctx.restore(),$t(t),t.ctx.strokeStyle=l,t.ctx.strokeRect(e.x0,e.y0,e.x1-e.x0,e.y1-e.y0),t.ctx.setLineDash([]);const a=(e.x0+e.x1)/2,c=t.pts[0].y,h=t.pts[1].y;if(t.ctx.strokeStyle=l,t.ctx.beginPath(),t.ctx.moveTo(e.x0,c),t.ctx.lineTo(e.x1,c),t.ctx.stroke(),Kt(t,{x:e.x0,y:c},{x:e.x1,y:c}),t.ctx.beginPath(),t.ctx.moveTo(a,c),t.ctx.lineTo(a,h),t.ctx.stroke(),Kt(t,{x:a,y:c},{x:a,y:h}),!1===t.style.showLabels)return;const d=t.rc.dataLayer.timeToIndexFloat(n[0].time),u=t.rc.dataLayer.timeToIndexFloat(n[1].time),p=Math.abs(Math.round(u-d)),f=o?"+":"",y=[`${f}${t.formatPrice(r)} (${f}${s.toFixed(2)}%)`,`${Jt(p)} bars, ${Gi(n[1].time-n[0].time)}`],x=t.rc.bars?.();if(void 0!==x&&x.length>0){const t=Math.min(n[0].time,n[1].time),e=Math.max(n[0].time,n[1].time);let i=0,r=!1;for(let n=Pt(x,t);n<x.length;n++){const t=x[n];if(t.time>e)break;void 0!==t.volume&&(i+=t.volume,r=!0)}r&&y.push(`Vol ${function(t){const e=Math.abs(t);return e>=1e9?`${(t/1e9).toFixed(2)}B`:e>=1e6?`${(t/1e6).toFixed(2)}M`:e>=1e3?`${(t/1e3).toFixed(2)}K`:Jt(t)}(i)}`)}Et(t,y,a,Math.max(c,h)+6*i,l,{align:"center",place:"below"})},distance:(t,e,i)=>C(t,e,i.pts[0],i.pts[1],!0)};function Qi(t){return!Number.isFinite(t)||t<=0?"0":t>=100?Jt(t):t>=1?Jt(t,2).replace(/\.?0+$/,""):t.toPrecision(3).replace(/\.?0+$/,"")}function tn(t,e,i){return{id:t,name:e,points:2,defaultStyle:{showLabels:!0,fillOpacity:.13,accountSize:1e5,risk:1},settings:st([U,zt,Z,Yi,tt]),expand:(t,e)=>function(t,e,i){const n=t[0],r=t[1]??n,s=i?1:-1;if(void 0!==e.toPixel&&void 0!==e.fromPixel){const t=e.toPixel(n),i=e.toPixel(r);if(null!==t&&null!==i){const r=Math.abs(i.y-t.y)>=6,o=r?i.y:t.y-64*s*2,l=t.x+(r?Math.max(Math.abs(i.x-t.x),48):150),a=t.y-(o-t.y)/2,c=e.fromPixel({x:l,y:o}),h=e.fromPixel({x:l,y:a});if(null!==c&&null!==h)return[{...n},c,h]}}const o=r.price!==n.price,l=o?r.price-n.price:s*(.02*Math.abs(n.price)||2),a=Math.max(5,Math.round(.08*e.visibleBars)),c=Math.max(1,e.barSeconds)*a,h=o&&r.time>n.time?r.time:n.time+c;return[{...n},{time:h,price:n.price+l},{time:h,price:n.price-l/2}]}(t,e,i),constrain:(t,e)=>function(t,e){const i=t.map(t=>({...t}));if(i.length<3)return i;const[n,r,s]=i,o=Math.sign(r.price-n.price),l=Math.sign(s.price-n.price);return 0===o||0===l||o!==l||(1===e?s.price=2*n.price-s.price:r.price=2*n.price-r.price),i}(t,e),draw:t=>{const e=t.drawing.points;if(e.length<2||t.pts.length<2)return;const[n,r]=e,s=e.length>=3?e[2]:{time:r.time,price:n.price-(r.price-n.price)/2},o=t.rc.dpr,l=t.pts.map(t=>t.x),a=Math.min(...l),c=Math.max(...l),h=t.rc.priceScale.priceToY(n.price)*o,d=t.rc.priceScale.priceToY(r.price)*o,u=t.rc.priceScale.priceToY(s.price)*o,p=t.drawing.props??{},f="string"==typeof p.profitColor?p.profitColor:Ut(t,!0),y="string"==typeof p.lossColor?p.lossColor:Ut(t,!1),x=(e,i,n)=>{t.ctx.save(),t.ctx.globalAlpha=t.style.fillOpacity??.13,t.ctx.fillStyle=n,t.ctx.fillRect(a,Math.min(e,i),c-a,Math.abs(i-e)),t.ctx.restore()};x(h,d,f),x(h,u,y),$t(t);for(const[e,i]of[[d,f],[u,y],[h,t.style.color]]){const n=Math.round(e)+.5;t.ctx.strokeStyle=i,t.ctx.beginPath(),t.ctx.moveTo(a,n),t.ctx.lineTo(c,n),t.ctx.stroke()}if(t.ctx.setLineDash([]),!1===t.style.showLabels)return;const g=Math.abs(n.price-s.price),m=Math.abs(r.price-n.price),_=g>0?m/g:0,b=t=>(0!==n.price?t/n.price*100:0).toFixed(2),v=r.price===n.price?i?"Long":"Short":r.price>n.price?"Long":"Short",w=t.style.accountSize??0,M=w>0?w*(t.style.risk??0)/100:0,P=g>0?M/g:0,k=(a+c)/2,S=e=>!0===p.showPrices?` @ ${t.formatPrice(e)}`:"";let T=Math.min(h,d,u);!1!==p.showLossSize&&M>0&&(T-=Et(t,[`Loss ${Jt(M,2)} Size ${Qi(P)}`],k,T,t.rc.theme.background,{align:"center",place:"above"})+4*o),!1!==p.showHeader&&Et(t,[`${v} R:R ${_.toFixed(2)}`],k,T,t.rc.theme.background,{align:"center",place:"above"}),!1!==p.showTargetLabel&&m>0&&Et(t,[`Target +${b(m)}%${S(r.price)}`],k,(h+d)/2,f,{align:"center",place:"middle"}),!1!==p.showStopLabel&&g>0&&Et(t,[`Stop -${b(g)}%${S(s.price)}`],k,(h+u)/2,y,{align:"center",place:"middle"})},distance:(t,e,i)=>{const n=i.drawing.points;if(i.pts.length<2||n.length<2)return null;const r=i.pts.map(t=>t.x),s=Math.min(...r),o=Math.max(...r);if(t<s-4||t>o+4)return null;const[l,a]=n,c=n.length>=3?n[2].price:l.price-(a.price-l.price)/2,h=[l.price,a.price,c].map(t=>i.rc.priceScale.priceToY(t)),d=Math.min(...h),u=Math.max(...h);return e>=d&&e<=u?0:Math.min(Math.abs(e-d),Math.abs(e-u))}}}const en=tn("long-position","Long Position",!0),nn=tn("short-position","Short Position",!1),rn={id:"price-range",name:"Price Range",points:2,defaultStyle:{fill:!0,showLabels:!0,fillOpacity:.1},settings:Xi,draw:t=>{const e=t.rc.dpr,i=t.drawing.points,n=i[1].price-i[0].price,r=0!==i[0].price?n/i[0].price*100:0,s=n>=0,o=Ut(t,s),l=Math.min(t.pts[0].x,t.pts[1].x),a=Math.max(t.pts[0].x,t.pts[1].x)+(t.pts[0].x===t.pts[1].x?60*e:0),c=t.pts[0].y,h=t.pts[1].y;t.ctx.save(),t.ctx.globalAlpha=t.style.fillOpacity??.1,t.ctx.fillStyle=o,t.ctx.fillRect(l,Math.min(c,h),a-l,Math.abs(h-c)),t.ctx.restore(),$t(t),t.ctx.strokeStyle=o,t.ctx.beginPath();for(const e of[c,h])t.ctx.moveTo(l,Math.round(e)+.5),t.ctx.lineTo(a,Math.round(e)+.5);const d=(l+a)/2;t.ctx.moveTo(d,c),t.ctx.lineTo(d,h);const u=h>c?1:-1;if(t.ctx.moveTo(d-4*e,h-5*e*u),t.ctx.lineTo(d,h),t.ctx.lineTo(d+4*e,h-5*e*u),t.ctx.moveTo(d-4*e,c+5*e*u),t.ctx.lineTo(d,c),t.ctx.lineTo(d+4*e,c+5*e*u),t.ctx.stroke(),t.ctx.setLineDash([]),!1===t.style.showLabels)return;const p=s?"+":"";Vt(t,`${p}${t.formatPrice(n)} (${p}${r.toFixed(2)}%)`,d+6*e,(c+h)/2,o)},distance:(t,e,i)=>C(t,e,i.pts[0],i.pts[1],!0)},sn={id:"date-range",name:"Date Range",points:2,defaultStyle:{fill:!0,showLabels:!0,fillOpacity:.1},settings:st([U,zt,Z,tt]),draw:t=>{const e=t.rc.dpr,i=t.drawing.points,n=t.style.color,r=t.pts[0].x,s=t.pts[1].x,o=Math.min(t.pts[0].y,t.pts[1].y),l=Math.max(t.pts[0].y,t.pts[1].y)+(t.pts[0].y===t.pts[1].y?40*e:0);t.ctx.save(),t.ctx.globalAlpha=t.style.fillOpacity??.1,t.ctx.fillStyle=n,t.ctx.fillRect(Math.min(r,s),o,Math.abs(s-r),l-o),t.ctx.restore(),$t(t),t.ctx.beginPath();for(const e of[r,s])t.ctx.moveTo(Math.round(e)+.5,o),t.ctx.lineTo(Math.round(e)+.5,l);const a=(o+l)/2;t.ctx.moveTo(r,a),t.ctx.lineTo(s,a);const c=s>r?1:-1;if(t.ctx.moveTo(s-5*e*c,a-4*e),t.ctx.lineTo(s,a),t.ctx.lineTo(s-5*e*c,a+4*e),t.ctx.moveTo(r+5*e*c,a-4*e),t.ctx.lineTo(r,a),t.ctx.lineTo(r+5*e*c,a+4*e),t.ctx.stroke(),t.ctx.setLineDash([]),!1===t.style.showLabels)return;const h=t.rc.dataLayer.timeToIndexFloat(i[0].time),d=t.rc.dataLayer.timeToIndexFloat(i[1].time);Vt(t,`${Math.abs(Math.round(d-h))} bars`,(r+s)/2,o-10*e,n)},distance:(t,e,i)=>C(t,e,i.pts[0],i.pts[1],!0)},on={id:"forecast",name:"Forecast",points:2,defaultStyle:{fill:!0,showLabels:!0,fillOpacity:.12,lineStyle:"dashed"},settings:Xi,draw:t=>{const e=t.rc.dpr,i=t.drawing.points,[n,r]=t.pts,s=i[1].price-i[0].price,o=0!==i[0].price?s/i[0].price*100:0,l=s>=0,a=Ut(t,l),c=.35*Math.abs(r.y-n.y)+6*e;if(t.ctx.save(),t.ctx.globalAlpha=t.style.fillOpacity??.12,t.ctx.fillStyle=a,t.ctx.beginPath(),t.ctx.moveTo(n.x,n.y),t.ctx.lineTo(r.x,r.y-c),t.ctx.lineTo(r.x,r.y+c),t.ctx.closePath(),t.ctx.fill(),t.ctx.restore(),$t(t),t.ctx.strokeStyle=a,t.ctx.beginPath(),t.ctx.moveTo(n.x,n.y),t.ctx.lineTo(r.x,r.y),t.ctx.stroke(),t.ctx.setLineDash([]),t.ctx.beginPath(),t.ctx.arc(n.x,n.y,3*e,0,2*Math.PI),t.ctx.fillStyle=a,t.ctx.fill(),!1===t.style.showLabels)return;const h=l?"+":"";Et(t,[t.formatPrice(i[0].price),qi(i[0].time)],n.x,n.y,a,{align:"center"}),Et(t,[`${h}${t.formatPrice(s)} (${h}${o.toFixed(2)}%) in ${Gi(i[1].time-i[0].time)}`,`${t.formatPrice(i[1].price)}, ${qi(i[1].time)}`],r.x,r.y,a,{align:"center",place:"below"});const d=t.rc.bars?.();if(void 0!==d&&d.length>0&&d[d.length-1].time>=i[1].time){let n=!1;for(const t of d)if(!(t.time<i[0].time)){if(t.time>i[1].time)break;if(l?t.high>=i[1].price:t.low<=i[1].price){n=!0;break}}Et(t,[n?"SUCCESS":"MISSED"],r.x,r.y+36*e,n?Yt:qt,{align:"center",place:"below"})}},distance:(t,e,i)=>I(t,e,i.pts[0],i.pts[1])},ln={id:"text",name:"Text",points:1,viewport:!0,defaultText:{value:"Text",fontSize:Xt},settings:st([it,G],{textIsContent:!0}),draw:t=>{const{ctx:e,rc:i,style:n}=t,r=i.dpr,s=Bt(t.drawing),o=Qt(e,s,Rt(t.drawing,"Text"),r),l=t.pts[0].x,a=s.valign??"top",c="middle"===a?t.pts[0].y-o.height/2:"bottom"===a?t.pts[0].y-o.height:t.pts[0].y;e.save(),e.setLineDash([]),!0===s.background&&(e.globalAlpha=s.backgroundOpacity??1,e.fillStyle=s.backgroundColor??i.theme.background,e.beginPath(),e.roundRect(l,c,o.width,o.height,4*r),e.fill(),e.globalAlpha=1),!0===s.border&&(e.strokeStyle=s.borderColor??n.color,e.lineWidth=Math.max(1,n.lineWidth*r),e.beginPath(),e.roundRect(l,c,o.width,o.height,4*r),e.stroke()),e.font=Wt(s,(s.fontSize??Xt)*r),e.fillStyle=s.color??n.color,e.textBaseline="top";const h=s.align??"left";e.textAlign=h;const d="center"===h?l+o.width/2:"right"===h?l+o.width-5*r:l+5*r;let u=c+5*r;for(const t of o.lines)e.fillText(t,d,u),u+=o.lineHeight;e.restore()},distance:(t,e,i)=>{const n=an(i.pts[0],i.drawing);return t>=n.x0-3&&t<=n.x1+3&&e>=n.y0-3&&e<=n.y1+3?0:null},bounds:(t,e)=>an(t[0],e)};function an(t,e){const i=Bt(e),n=Rt(e,"Text"),r=i.fontSize??Xt,s=re(),o=null===s?{width:n.length*r*.6+10,height:r*Gt+10}:Qt(s,i,n,1),l=i.valign??"top",a="middle"===l?t.y-o.height/2:"bottom"===l?t.y-o.height:t.y;return{x0:t.x,y0:a,x1:t.x+o.width,y1:a+o.height}}const cn=st([E,et,tt],{textIsContent:!0}),hn={id:"price-label",name:"Price Label",points:1,settings:st([E,{...et,label:"Text (blank shows the price)"},tt]),draw:t=>{const e=t.pts[0],i=t.rc.dpr,n=Rt(t.drawing,t.formatPrice(t.drawing.points[0].price)),r=fn(t,[n],e.x+18*i,e.y-30*i,12);xn(t,r,e,t.style.color),gn(t,r,[n],t.style.color,12)},distance:(t,e,i)=>Pn(t,e,dn(i.pts[0],i.drawing,i.rc))};function dn(t,e,i){return{plate:yn(e,[Rt(e,i.priceScale.format(e.points[0].price))],t.x+18,t.y-30,50),dot:{at:t,r:10}}}const un={id:"callout",name:"Callout",points:2,defaultText:{value:"Note",fontSize:12},settings:cn,draw:t=>{if(t.pts.length<2)return;const[e,i]=t.pts,n=Rt(t.drawing,"Note").split("\n"),r=fn(t,n,i.x,i.y,12);xn(t,r,e,t.style.color),gn(t,r,n,t.style.color,12)},distance:(t,e,i)=>{if(i.pts.length<2)return null;const[n,r]=i.pts,s=pn(r,i.drawing);return null!==Tn(t,e,s.x,s.y,s.w,s.h)?0:I(t,e,n,r)}};function pn(t,e){return yn(e,Rt(e,"Note").split("\n"),t.x,t.y,106)}function fn(t,e,i,n,r){const s=t.rc.dpr,o=Bt(t.drawing),l=(o.fontSize??r)*s,a=bn(t.ctx,o,e,l)+14*s,c=1.4*l*e.length+8*s;return{x:i-a/2,y:n-c/2,w:a,h:c}}function yn(t,e,i,n,r){const s=Bt(t),o=s.fontSize??12,l=re(),a=(null===l?r:bn(l,s,e,o))+14,c=1.4*o*e.length+8;return{x:i-a/2,y:n-c/2,w:a,h:c}}function xn(t,e,i,n){const r=t.rc.dpr,s=e.x+e.w/2,o=e.y+e.h/2,l=Math.atan2(i.y-o,i.x-s),a=5*r,c=s+Math.cos(l)*(e.w/2-a),h=o+Math.sin(l)*(e.h/2-a);t.ctx.save(),t.ctx.setLineDash([]),t.ctx.fillStyle=n,t.ctx.beginPath(),t.ctx.moveTo(i.x,i.y),t.ctx.lineTo(c-Math.sin(l)*a,h+Math.cos(l)*a),t.ctx.lineTo(c+Math.sin(l)*a,h-Math.cos(l)*a),t.ctx.closePath(),t.ctx.fill(),t.ctx.beginPath(),Lt(t.ctx,e.x,e.y,e.w,e.h,5*r),t.ctx.fill(),t.ctx.beginPath(),t.ctx.arc(i.x,i.y,2.5*r,0,2*Math.PI),t.ctx.fill(),t.ctx.restore()}function gn(t,e,i,n,r){const s=t.rc.dpr,o=Bt(t.drawing),l=(o.fontSize??r)*s;t.ctx.save(),t.ctx.setLineDash([]),t.ctx.font=Wt(o,l),t.ctx.textAlign="center",t.ctx.textBaseline="middle",t.ctx.fillStyle=o.color??Ot(n);const a=1.4*l,c=e.y+e.h/2-a*(i.length-1)/2;for(let n=0;n<i.length;n++)t.ctx.fillText(i[n],e.x+e.w/2,c+a*n);t.ctx.restore()}const mn=st([U,Y]),_n={id:"flag-mark",name:"Flag Mark",points:1,defaultStyle:{fill:!0,fillOpacity:.95},settings:mn,draw:t=>{const e=t.pts[0],i=t.rc.dpr,n=22*i,r=15*i,s=11*i;$t(t),t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.lineTo(e.x,e.y-n),t.ctx.stroke(),t.ctx.setLineDash([]),t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y-n),t.ctx.lineTo(e.x+r,e.y-n+.28*s),t.ctx.lineTo(e.x+.72*r,e.y-n+.5*s),t.ctx.lineTo(e.x+r,e.y-n+.72*s),t.ctx.lineTo(e.x,e.y-n+s),t.ctx.closePath(),!1!==t.style.fill&&(t.ctx.save(),t.ctx.globalAlpha=t.style.fillOpacity??.95,t.ctx.fillStyle=Dt(t),t.ctx.fill(),t.ctx.restore()),t.ctx.stroke()},distance:(t,e,i)=>{const n=i.pts[0];return t>=n.x-4&&t<=n.x+16&&e>=n.y-24&&e<=n.y+2||Math.hypot(t-n.x,e-n.y)<=8?0:null}};function bn(t,e,i,n){t.save(),t.font=Wt(e,n);let r=0;for(const e of i)r=Math.max(r,t.measureText(e).width);return t.restore(),r}function vn(t,e,i){const n=Rt(e,t.fallback).split("\n");return!0===t.price?[i(e.points[0].price),...n]:n}function wn(t,e,i,n){const r=t.rc.dpr,s=(Bt(t.drawing).fontSize??n.size)*r,o=bn(t.ctx,Bt(t.drawing),i,s)+16*r,l=1.45*s*i.length+10*r;return{...n.at(e,o,l,r),w:o,h:l}}function Mn(t,e,i,n){const r=Bt(i),s=r.fontSize??t.size,o=vn(t,i,t=>n.priceScale.format(t)),l=re(),a=null===l?120:bn(l,r,o,s)+16,c=1.45*s*o.length+10,h={...t.at(e,a,c,1),w:a,h:c};return void 0===t.post?{plate:h,dot:{at:e,r:8}}:{plate:h,post:t.post(e)}}function Pn(t,e,i){const{plate:n,dot:r,post:s}=i;return null!==Tn(t,e,n.x,n.y,n.w,n.h)?0:void 0!==r?Math.hypot(t-r.at.x,e-r.at.y)<=r.r?0:null:void 0!==s&&null!==Tn(t,e,s.x,s.y,s.w,s.h)?0:null}function kn(t){return t.drawing.text?.backgroundColor??t.style.color}function Sn(t,e,i,n,r=6){const s=t.rc.dpr,o=Bt(t.drawing),l=(o.fontSize??n.size)*s,a=kn(t);t.ctx.save(),t.ctx.setLineDash([]),t.ctx.globalAlpha=o.backgroundOpacity??n.opacity,t.ctx.fillStyle=a,t.ctx.beginPath(),Lt(t.ctx,e.x,e.y,e.w,e.h,r*s),t.ctx.fill(),t.ctx.globalAlpha=1,!0===o.border&&(t.ctx.strokeStyle=o.borderColor??t.style.color,t.ctx.lineWidth=Math.max(1,t.style.lineWidth*s),t.ctx.stroke()),t.ctx.font=Wt(o,l),t.ctx.textAlign="left",t.ctx.textBaseline="middle",t.ctx.fillStyle=o.color??Ot(a);const c=1.45*l,h=e.y+e.h/2-c*(i.length-1)/2;for(let n=0;n<i.length;n++)t.ctx.fillText(i[n],e.x+8*s,h+c*n);t.ctx.restore()}function Tn(t,e,i,n,r,s){return t>=i&&t<=i+r&&e>=n&&e<=n+s?0:null}const In=st([E,J,rt],{textIsContent:!0}),On=st([E,rt],{textIsContent:!0}),Fn={size:12,opacity:.95,fallback:"Note",at:(t,e,i,n)=>({x:t.x+16*n,y:t.y-34*n})},Ln={id:"note",name:"Note",points:1,defaultText:{value:"Note",fontSize:Fn.size},settings:In,draw:t=>{const e=t.rc.dpr,i=t.pts[0],n=vn(Fn,t.drawing,t.formatPrice),r=wn(t,i,n,Fn);t.ctx.save(),t.ctx.setLineDash([]),t.ctx.strokeStyle=t.style.color,t.ctx.lineWidth=Math.max(1,t.style.lineWidth*e),t.ctx.beginPath(),t.ctx.moveTo(i.x,i.y),t.ctx.lineTo(r.x,r.y+r.h),t.ctx.stroke(),t.ctx.fillStyle=t.style.color,t.ctx.beginPath(),t.ctx.arc(i.x,i.y,3.5*e,0,2*Math.PI),t.ctx.fill(),t.ctx.restore(),Sn(t,r,n,Fn)},distance:(t,e,i)=>Pn(t,e,Mn(Fn,i.pts[0],i.drawing,i.rc))},An={size:12,opacity:.95,fallback:"Balloon",at:(t,e,i,n)=>({x:t.x-e/2,y:t.y-i-12*n})},zn={id:"balloon",name:"Balloon",points:1,defaultText:{value:"Balloon",fontSize:An.size},settings:On,draw:t=>{const e=t.rc.dpr,i=t.pts[0],n=vn(An,t.drawing,t.formatPrice),r=wn(t,i,n,An);t.ctx.save(),t.ctx.setLineDash([]),t.ctx.globalAlpha=t.drawing.text?.backgroundOpacity??An.opacity,t.ctx.fillStyle=kn(t),t.ctx.beginPath(),t.ctx.moveTo(i.x,i.y),t.ctx.lineTo(i.x-6*e,r.y+r.h),t.ctx.lineTo(i.x+6*e,r.y+r.h),t.ctx.closePath(),t.ctx.fill(),t.ctx.restore(),Sn(t,r,n,An,8)},distance:(t,e,i)=>Pn(t,e,Mn(An,i.pts[0],i.drawing,i.rc))},Nn={size:11,opacity:.92,fallback:"Comment",at:(t,e,i,n)=>({x:t.x+8*n,y:t.y-i-10*n})},Cn={id:"comment",name:"Comment",points:1,defaultText:{value:"Comment",fontSize:Nn.size},settings:On,draw:t=>{const e=t.rc.dpr,i=t.pts[0],n=vn(Nn,t.drawing,t.formatPrice),r=wn(t,i,n,Nn);t.ctx.save(),t.ctx.setLineDash([]),t.ctx.globalAlpha=t.drawing.text?.backgroundOpacity??Nn.opacity,t.ctx.fillStyle=kn(t),t.ctx.beginPath(),t.ctx.moveTo(i.x,i.y),t.ctx.lineTo(r.x,r.y+r.h-5*e),t.ctx.lineTo(r.x+10*e,r.y+r.h),t.ctx.closePath(),t.ctx.fill(),t.ctx.restore(),Sn(t,r,n,Nn,3)},distance:(t,e,i)=>Pn(t,e,Mn(Nn,i.pts[0],i.drawing,i.rc))},$n={size:11,opacity:.95,fallback:"Event",at:(t,e,i,n)=>({x:t.x-e/2,y:t.y-34*n-i}),post:t=>({x:t.x-5,y:t.y-34,w:10,h:38})},Dn={id:"signpost",name:"Signpost",points:1,defaultText:{value:"Event",fontSize:$n.size},settings:In,draw:t=>{const e=t.rc.dpr,i=t.pts[0],n=vn($n,t.drawing,t.formatPrice),r=wn(t,i,n,$n);t.ctx.save(),t.ctx.setLineDash([]),t.ctx.strokeStyle=t.style.color,t.ctx.lineWidth=Math.max(1,t.style.lineWidth*e),t.ctx.beginPath(),t.ctx.moveTo(i.x,i.y),t.ctx.lineTo(i.x,i.y-34*e),t.ctx.stroke(),t.ctx.fillStyle=t.style.color,t.ctx.beginPath(),t.ctx.arc(i.x,i.y,3*e,0,2*Math.PI),t.ctx.fill(),t.ctx.restore(),Sn(t,r,n,$n,4)},distance:(t,e,i)=>Pn(t,e,Mn($n,i.pts[0],i.drawing,i.rc))},jn={size:11,opacity:.95,fallback:"Note",price:!0,at:(t,e,i,n)=>({x:t.x+14*n,y:t.y-12*n})},Hn={id:"price-note",name:"Price Note",points:1,defaultText:{value:"Note",fontSize:jn.size},settings:In,draw:t=>{const e=t.rc.dpr,i=t.pts[0],n=vn(jn,t.drawing,t.formatPrice),r=wn(t,i,n,jn);t.ctx.save(),t.ctx.setLineDash([]),t.ctx.strokeStyle=t.style.color,t.ctx.lineWidth=Math.max(1,t.style.lineWidth*e),t.ctx.beginPath(),t.ctx.moveTo(i.x,i.y),t.ctx.lineTo(r.x,i.y),t.ctx.stroke(),t.ctx.restore(),Sn(t,r,n,jn,4)},distance:(t,e,i)=>Pn(t,e,Mn(jn,i.pts[0],i.drawing,i.rc))},Bn=new Map([[Ln,Fn],[zn,An],[Cn,Nn],[Dn,$n],[Hn,jn]]);function Wn(t,e,i,n){const r=(e.fontSize??11)*n,s=Array.from({length:Math.max(...i.map(t=>t.length))},()=>0);t?.save();try{for(let o=0;o<i.length;o++){null!==t&&(t.font=Wt(e,r,0===o?!0===e.bold?"800":"600":void 0));for(let e=0;e<s.length;e++){const l=i[o][e]??"",a=null===t?l.length*r*.6:wt(t,l);s[e]=Math.max(s[e],a+14*n)}}}finally{t?.restore()}return s}const Rn={id:"table",name:"Table",points:1,viewport:!0,defaultText:{value:"Level|Price\nEntry|-\nStop|-",fontSize:11},settings:st([E,{...J,label:"Border width"},et,tt,{path:"text.backgroundColor",label:"Background color",kind:"color",group:"text"},{path:"text.backgroundOpacity",label:"Background opacity",kind:"opacity",min:0,max:1,step:.01,group:"text"},{path:"text.border",label:"Border",kind:"boolean",group:"text"},{path:"text.borderColor",label:"Border color",kind:"color",group:"text"},G],{textIsContent:!0}),draw:t=>{const e=t.rc.dpr,i=t.pts[0],n=Bt(t.drawing),r=En(t.drawing),s=(n.fontSize??11)*e,o=7*e,l=1.7*s;t.ctx.save();const a=Wn(t.ctx,n,r,e),c=a.reduce((t,e)=>t+e,0),h=l*r.length;if(t.ctx.setLineDash([]),t.ctx.globalAlpha=n.backgroundOpacity??.92,t.ctx.fillStyle=n.backgroundColor??t.rc.theme.background,t.ctx.beginPath(),Lt(t.ctx,i.x,i.y,c,h,4*e),t.ctx.fill(),t.ctx.globalAlpha=1,!1!==n.border){t.ctx.strokeStyle=n.borderColor??t.style.color,t.ctx.lineWidth=Math.max(1,t.style.lineWidth*e),t.ctx.stroke(),t.ctx.globalAlpha=.45,t.ctx.beginPath();for(let e=1;e<r.length;e++)t.ctx.moveTo(i.x,i.y+l*e),t.ctx.lineTo(i.x+c,i.y+l*e);let s=i.x;for(let e=0;e<a.length-1;e++)s+=a[e],t.ctx.moveTo(s,i.y),t.ctx.lineTo(s,i.y+h);t.ctx.stroke(),t.ctx.globalAlpha=1}t.ctx.textBaseline="middle",t.ctx.textAlign="left";const d=Wt(n,s,!0===n.bold?"800":"600"),u=Wt(n,s);for(let e=0;e<r.length;e++){t.ctx.fillStyle=n.color??t.style.color,t.ctx.font=0===e?d:u;let s=i.x;for(let n=0;n<a.length;n++)t.ctx.fillText(r[e][n]??"",s+o,i.y+l*e+l/2),s+=a[n]}t.ctx.restore()},distance:(t,e,i)=>{const n=Vn(i.pts[0],i.drawing);return Tn(t,e,n.x0,n.y0,n.x1-n.x0,n.y1-n.y0)},bounds:(t,e)=>Vn(t[0],e)};function Vn(t,e){const i=En(e),n=e.text?.fontSize??11,r=Wn(re(),Bt(e),i,1).reduce((t,e)=>t+e,0);return{x0:t.x,y0:t.y,x1:t.x+r,y1:t.y+1.7*n*i.length}}function En(t){return Rt(t,"Level|Price").split("\n").map(t=>t.split("|"))}function Jn(t,e,i,n="vertical"){return{id:t,name:e,points:1,defaultStyle:{fill:!0,fillOpacity:.9},settings:mn,draw:t=>{const e=t.rc.dpr,{x:r,y:s}=t.pts[0],o=16*e,l=6*e,a=i?1:-1,c=s+2*a*e;if(t.ctx.beginPath(),"vertical"!==n){const i="right"===n?-1:1,a=r+2*i*e;t.ctx.moveTo(a,s),t.ctx.lineTo(a+i*l,s-l),t.ctx.lineTo(a+i*l,s-l/2.4),t.ctx.lineTo(a+i*o,s-l/2.4),t.ctx.lineTo(a+i*o,s+l/2.4),t.ctx.lineTo(a+i*l,s+l/2.4),t.ctx.lineTo(a+i*l,s+l),t.ctx.closePath()}else t.ctx.moveTo(r,c),t.ctx.lineTo(r-l,c+a*l),t.ctx.lineTo(r-l/2.4,c+a*l),t.ctx.lineTo(r-l/2.4,c+a*o),t.ctx.lineTo(r+l/2.4,c+a*o),t.ctx.lineTo(r+l/2.4,c+a*l),t.ctx.lineTo(r+l,c+a*l),t.ctx.closePath();!1!==t.style.fill&&(t.ctx.save(),t.ctx.globalAlpha=t.style.fillOpacity??.9,t.ctx.fillStyle=Dt(t),t.ctx.fill(),t.ctx.restore()),$t(t),t.ctx.stroke(),t.ctx.setLineDash([])},distance:(t,e,n)=>{const r=n.pts[0],s=i?e-r.y:r.y-e;return Math.abs(t-r.x)<=8&&s>=-4&&s<=20?0:null}}}const Kn=Jn("arrow-up","Arrow Up",!0),Un=Jn("arrow-down","Arrow Down",!1),Yn=Jn("arrow-left","Arrow Left",!0,"left"),qn=Jn("arrow-right","Arrow Right",!0,"right");function Gn(t){const e=t.props?.source;return"close"===e||"hl2"===e||"ohlc4"===e?e:"hlc3"}function Xn(t){const e=t.historyPartial?" (partial history)":"";switch(t.status){case"partial":return e+(t.missingVolumeBars>0||t.invalidPriceBars>0?" (partial volume/data)":"");case"missing-volume":return": volume unavailable"+e;case"zero-volume":return": zero volume"+e;case"invalid-data":return": data unavailable"+e;case"empty":return": no bars in range"+e;default:return""}}function Zn(t,e){for(const i of e.drawing.points){const n=Ct(e.rc,i);for(const[i,r]of[[{x:n.x-4,y:n.y},{x:n.x+4,y:n.y}],[{x:n.x,y:n.y-4},{x:n.x,y:n.y+4}]]){const n=ce(i,r,e.rc);n.length>0&&t.lines.push(n)}}}function Qn(t){const e={lines:[],bands:[],rects:[],label:"",labelAt:{x:0,y:0},status:"empty"},i=t.drawing.points[0];if(!i)return e;const n=Tt(t.rc.bars?.()??[],i.time,{source:Gn(t.drawing)});e.status=n.status;const r=!1!==t.drawing.props?.showBands,s=Mt(t.drawing.props?.bandMultiplier,1,0,5),o=n.points[n.points.length-1];e.labelAt=Ct(t.rc,o?{time:o.time,price:o.value}:i),e.label=`AVWAP${o?` ${t.rc.priceScale.format(o.value)}`:""}${Xn(n)}`;for(const i of r&&s>0?[0,-s,s]:[0]){let r;for(const s of n.points){const n=Ct(t.rc,{time:s.time,price:s.value+s.deviation*i});s.breakBefore&&(r=void 0);const o=ce(r||{x:n.x-2,y:n.y},n,t.rc);o.length>0&&(0===i?e.lines:e.bands).push(o),r=n}}return o||Zn(e,t),e}function tr(t){const e={lines:[],bands:[],rects:[],label:"",labelAt:{x:0,y:0},status:"empty"},[i,n]=t.drawing.points;if(!i||!n)return e;const r=It(t.rc.bars?.()??[],i.time,n.time,{rows:Mt(t.drawing.props?.rows,48,4,200),valueArea:Mt(t.drawing.props?.valueArea,70,1,100)});e.status=r.status;const s=Ct(t.rc,i),o=Ct(t.rc,n),l=Math.min(s.x,o.x),a=Math.max(s.x,o.x),c=Math.max(0,...r.rows.map(t=>t.volume)),h=Math.max(12,a-l)*Mt(t.drawing.props?.width,35,5,100)/100,d="right"===t.drawing.props?.side,u=!1!==t.drawing.props?.showValueArea;e.label=`Volume profile (estimated)${Xn(r)}`,e.labelAt={x:l,y:Math.min(s.y,o.y)};for(const i of r.rows){const n=t.rc.priceScale.priceToY(i.low),r=t.rc.priceScale.priceToY(i.high);if(![n,r].every(Number.isFinite)||c<=0||i.volume<=0)continue;const s=h*i.volume/c,o=d?a-s:l,p=d?a:l+s,f=Math.max(0,Math.min(n,r)),y=Math.min(t.rc.plotHeight,Math.max(n,r)+(n===r?1:0)),x={left:Math.max(0,o),right:Math.min(t.rc.plotWidth,p),top:f,bottom:y,area:u&&i.valueArea};x.left<x.right&&x.top<x.bottom&&e.rects.push(x)}const p=(e,i)=>{if(null===e)return;const n=t.rc.priceScale.priceToY(e),r=ce({x:l,y:n},{x:a===l?a+12:a,y:n},t.rc);r.length>0&&i.push(r)};return!1!==t.drawing.props?.showPoc&&p(r.poc,e.lines),u&&(p(r.valueAreaLow,e.bands),p(r.valueAreaHigh,e.bands)),null!==r.valueAreaHigh&&(e.labelAt.y=t.rc.priceScale.priceToY(r.rows[r.rows.length-1].high)),0===r.rows.length&&Zn(e,t),e}function er(t,e){const{ctx:i,rc:n,drawing:r,style:s}=t,o=n.dpr;if(!(n.plotWidth>0&&n.plotHeight>0))return;const l=e({drawing:r,rc:n,pts:[]});i.save(),i.beginPath(),i.rect(0,0,n.plotWidth*o,n.plotHeight*o),i.clip(),i.strokeStyle=s.color,i.fillStyle=s.color,i.lineWidth=Nt(s.lineWidth,o),i.setLineDash(At(s.lineStyle,o));for(const t of l.rects)i.save(),i.globalAlpha*=Mt(s.fillOpacity,.4,0,1)*(t.area?1:.45),i.fillRect(t.left*o,t.top*o,(t.right-t.left)*o,(t.bottom-t.top)*o),i.restore();const a=t=>{if(0!==t.length){i.beginPath();for(const e of t)i.moveTo(e[0].x*o,e[0].y*o),i.lineTo(e[1].x*o,e[1].y*o);i.stroke()}};if(a(l.lines),i.save(),i.globalAlpha*=.6,a(l.bands),i.restore(),(!1!==s.showLabels||"ready"!==l.status)&&l.label&&Number.isFinite(l.labelAt.x)&&Number.isFinite(l.labelAt.y)){const t=r.text,e=Mt(t?.fontSize,11,6,96);i.fillStyle=t?.color??s.color,i.font=Wt(Bt(r),e*o),i.textAlign="left",i.textBaseline="bottom";const a=i.measureText(l.label).width/o,c=Math.max(4,Math.min(n.plotWidth-a-4,l.labelAt.x+4)),h=Math.max(e+3,Math.min(n.plotHeight-3,l.labelAt.y-5));i.fillText(l.label,c*o,h*o)}i.restore()}function ir(t,e,i,n){if(t<0||e<0||t>i.rc.plotWidth||e>i.rc.plotHeight)return null;const r=n(i);let s=1/0;for(const i of[...r.lines,...r.bands])s=Math.min(s,I(t,e,i[0],i[1]));if(Mt(i.drawing.style.fillOpacity,.4,0,1)>0)for(const i of r.rects)s=Math.min(s,C(t,e,{x:i.left,y:i.top},{x:i.right,y:i.bottom},!0));return Number.isFinite(s)?s:null}const nr={id:"anchored-vwap",name:"Anchored VWAP",points:1,defaultStyle:{showLabels:!0,lineWidth:2},settings:st([U,Z,tt,{path:"props.source",label:"Price source",kind:"select",group:"behavior",defaultValue:"hlc3",options:[{value:"hlc3",label:"HLC3"},{value:"close",label:"Close"},{value:"hl2",label:"HL2"},{value:"ohlc4",label:"OHLC4"}]},{path:"props.showBands",label:"Deviation bands",kind:"boolean",group:"behavior",defaultValue:!0},{path:"props.bandMultiplier",label:"Band multiplier",kind:"number",min:0,max:5,step:.25,group:"behavior",defaultValue:1}]),draw:t=>er(t,Qn),distance:(t,e,i)=>ir(t,e,i,Qn)},rr={id:"fixed-range-volume-profile",name:"Fixed Range Volume Profile",points:2,defaultStyle:{showLabels:!0,fillOpacity:.4},settings:st([U,Z,tt,{path:"style.fillOpacity",label:"Histogram opacity",kind:"opacity",min:0,max:1,step:.05,group:"fill",defaultValue:.4},{path:"props.rows",label:"Price rows",kind:"number",min:4,max:200,step:1,group:"behavior",defaultValue:48},{path:"props.valueArea",label:"Value area (%)",kind:"number",min:1,max:100,step:1,group:"behavior",defaultValue:70},{path:"props.width",label:"Range width (%)",kind:"number",min:5,max:100,step:1,group:"behavior",defaultValue:35},{path:"props.side",label:"Histogram side",kind:"select",group:"behavior",defaultValue:"left",options:[{value:"left",label:"Left"},{value:"right",label:"Right"}]},{path:"props.showPoc",label:"Point of control",kind:"boolean",group:"behavior",defaultValue:!0},{path:"props.showValueArea",label:"Value area levels",kind:"boolean",group:"behavior",defaultValue:!0}]),draw:t=>er(t,tr),distance:(t,e,i)=>ir(t,e,i,tr)},sr={...Z,label:"Show price"},or={path:"style.showStats",label:"Show stats",kind:"boolean",group:"behavior"},lr={path:"style.pressure",label:"Pen pressure",kind:"boolean",group:"line"};function ar(t){if(!0!==t.style.showStats)return;const[e,i]=t.pts,[n,r]=t.drawing.points,s=r.price-n.price,o=0!==n.price?s/n.price*100:0,l=s>=0,a=l?"+":"",c=t.rc.dataLayer.timeToIndexFloat(n.time),h=t.rc.dataLayer.timeToIndexFloat(r.time),d=Math.abs(Math.round(h-c)),u=180*Math.atan2(e.y-i.y,i.x-e.x)/Math.PI,p=`${a}${t.formatPrice(s)} (${a}${o.toFixed(2)}%) ${Jt(d)} bars ${u.toFixed(1)} deg`;Vt(t,p,(e.x+i.x)/2,(e.y+i.y)/2-10*t.rc.dpr,t.style.color,{tint:Ut(t,l),center:!0})}function cr(t,e,i){const{ctx:n,style:r}=t,s=t.pts;if(n.save(),n.globalAlpha=i,n.lineCap="round",n.lineJoin="round",!0!==r.pressure)return n.strokeStyle=r.color,n.lineWidth=e,n.beginPath(),_t(n,s),n.stroke(),void n.restore();const o=s.length,l=[],a=[];for(let i=0;i<o;i++){const n=s[0===i?0:i-1],r=s[i===o-1?o-1:i+1],c=Math.hypot(r.x-n.x,r.y-n.y)||1,h=-(r.y-n.y)/c,d=(r.x-n.x)/c,u=t.drawing.points[i]?.pressure,p=bt(e,u??.5)/2;l.push({x:s[i].x+h*p,y:s[i].y+d*p}),a.push({x:s[i].x-h*p,y:s[i].y-d*p})}a.reverse(),n.fillStyle=r.color,n.beginPath(),_t(n,l.concat(a)),n.closePath(),n.fill(),n.restore()}function hr(t,e,i,n){return{id:t,name:e,points:2,angleLock:!0,alertValue:w(i,n),defaultStyle:{extendLeft:i,extendRight:n},settings:st([U,q,or]),draw:t=>{const[e,r]=D(t.pts[0],t.pts[1],t.rc.plotWidth*t.rc.dpr,t.style.extendLeft??i,t.style.extendRight??n);$t(t),t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.lineTo(r.x,r.y),t.ctx.stroke(),t.ctx.setLineDash([]),ar(t)},distance:(t,e,r)=>{const s=r.drawing.style.extendLeft??i,o=r.drawing.style.extendRight??n;if(s&&o)return O(t,e,r.pts[0],r.pts[1]);const[l,a]=D(r.pts[0],r.pts[1],r.rc.plotWidth,s,o);return I(t,e,l,a)}}}const dr={...hr("trend-line","Trend Line",!1,!1),shortcut:"Alt+T"},ur=hr("ray","Ray",!1,!0),pr=hr("extended-line","Extended Line",!0,!0),fr={id:"arrow",name:"Arrow",points:2,angleLock:!0,settings:st([U,or]),draw:t=>{const[e,i]=t.pts;$t(t),t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.lineTo(i.x,i.y),t.ctx.stroke(),Kt(t,e,i),t.ctx.setLineDash([]),ar(t)},distance:(t,e,i)=>I(t,e,i.pts[0],i.pts[1])},yr={id:"horizontal-line",name:"Horizontal Line",points:1,shortcut:"Alt+H",alertValue:M(),defaultStyle:{showLabels:!0},settings:st([U,sr,tt]),draw:t=>{const e=Math.round(t.pts[0].y)+.5;$t(t),t.ctx.beginPath(),t.ctx.moveTo(0,e),t.ctx.lineTo(t.rc.plotWidth*t.rc.dpr,e),t.ctx.stroke(),t.ctx.setLineDash([]),!1!==t.style.showLabels&&Vt(t,t.formatPrice(t.drawing.points[0].price),4*t.rc.dpr,e-8*t.rc.dpr)},distance:(t,e,i)=>F(e,i.pts[0].y)},xr={id:"horizontal-ray",name:"Horizontal Ray",points:1,shortcut:"Alt+J",alertValue:M(!0),defaultStyle:{showLabels:!0},settings:st([U,sr,tt]),draw:t=>{const e=Math.round(t.pts[0].y)+.5;$t(t),t.ctx.beginPath(),t.ctx.moveTo(t.pts[0].x,e),t.ctx.lineTo(t.rc.plotWidth*t.rc.dpr,e),t.ctx.stroke(),t.ctx.setLineDash([]),!1!==t.style.showLabels&&Vt(t,t.formatPrice(t.drawing.points[0].price),t.pts[0].x+4*t.rc.dpr,e-8*t.rc.dpr)},distance:(t,e,i)=>t<i.pts[0].x?null:F(e,i.pts[0].y)},gr={id:"vertical-line",name:"Vertical Line",points:1,shortcut:"Alt+V",settings:Ni,draw:t=>{const e=Math.round(t.pts[0].x)+.5;$t(t),t.ctx.beginPath(),t.ctx.moveTo(e,0),t.ctx.lineTo(e,t.rc.plotHeight*t.rc.dpr),t.ctx.stroke(),t.ctx.setLineDash([])},distance:(t,e,i)=>L(t,i.pts[0].x)},mr={id:"cross-line",name:"Cross Line",points:1,shortcut:"Alt+C",settings:Ni,draw:t=>{const e=Math.round(t.pts[0].x)+.5,i=Math.round(t.pts[0].y)+.5;$t(t),t.ctx.beginPath(),t.ctx.moveTo(e,0),t.ctx.lineTo(e,t.rc.plotHeight*t.rc.dpr),t.ctx.moveTo(0,i),t.ctx.lineTo(t.rc.plotWidth*t.rc.dpr,i),t.ctx.stroke(),t.ctx.setLineDash([])},distance:(t,e,i)=>Math.min(L(t,i.pts[0].x),F(e,i.pts[0].y))},_r=st([U,Y,nt]),br=st([_r.fields,G]),vr={id:"rectangle",name:"Rectangle",points:2,viewport:!0,defaultStyle:{fill:!0},settings:br,draw:t=>{const e=z(t.pts[0],t.pts[1]);jt(t,()=>t.ctx.fillRect(e.x0,e.y0,e.x1-e.x0,e.y1-e.y0)),$t(t),t.ctx.strokeRect(e.x0,e.y0,e.x1-e.x0,e.y1-e.y0),t.ctx.setLineDash([]),te(t,e)},distance:(t,e,i)=>C(t,e,i.pts[0],i.pts[1],!0===i.drawing.style.fill),bounds:ie("left","top")},wr={id:"ellipse",name:"Ellipse",points:2,viewport:!0,defaultStyle:{fill:!0},settings:br,draw:t=>{const e=z(t.pts[0],t.pts[1]),i=(e.x0+e.x1)/2,n=(e.y0+e.y1)/2,r=Math.max(1,(e.x1-e.x0)/2),s=Math.max(1,(e.y1-e.y0)/2),o=()=>{t.ctx.beginPath(),t.ctx.ellipse(i,n,r,s,0,0,2*Math.PI)};jt(t,()=>{o(),t.ctx.fill()}),$t(t),o(),t.ctx.stroke(),t.ctx.setLineDash([]),te(t,e,"center","middle")},distance:(t,e,i)=>$(t,e,i.pts[0],i.pts[1],!0===i.drawing.style.fill),bounds:ie("center","middle")},Mr={id:"parallel-channel",name:"Parallel Channel",points:3,alertValue:k("parallel"),alertLevels:P,defaultStyle:{fill:!0},settings:_r,draw:t=>{const[e,i,n]=t.pts,r=n.y-(e.y+.5*(i.y-e.y)),s={x:e.x,y:e.y+r},o={x:i.x,y:i.y+r};jt(t,()=>{t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.lineTo(i.x,i.y),t.ctx.lineTo(o.x,o.y),t.ctx.lineTo(s.x,s.y),t.ctx.closePath(),t.ctx.fill()}),$t(t),t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.lineTo(i.x,i.y),t.ctx.moveTo(s.x,s.y),t.ctx.lineTo(o.x,o.y),t.ctx.stroke(),t.ctx.setLineDash([]),te(t,N([e,i,s,o]))},distance:(t,e,i)=>{const[n,r,s]=i.pts,o=s.y-(n.y+.5*(r.y-n.y)),l=I(t,e,n,r),a=I(t,e,{x:n.x,y:n.y+o},{x:r.x,y:r.y+o});return Math.min(l,a)}},Pr={id:"path",name:"Path",points:0,settings:Ni,draw:t=>{if(!(t.pts.length<2)){$t(t),t.ctx.beginPath(),t.ctx.moveTo(t.pts[0].x,t.pts[0].y);for(let e=1;e<t.pts.length;e++)t.ctx.lineTo(t.pts[e].x,t.pts[e].y);t.ctx.stroke(),t.ctx.setLineDash([]),Kt(t,t.pts[t.pts.length-2],t.pts[t.pts.length-1])}},distance:(t,e,i)=>i.pts.length<2?null:A(t,e,i.pts)},kr={id:"brush",name:"Brush",points:0,freehand:!0,defaultStyle:{lineWidth:2},settings:st([U,lr]),draw:t=>{t.pts.length<2||($t(t),cr(t,Math.max(1,Math.round(t.style.lineWidth*t.rc.dpr)),1),t.ctx.setLineDash([]))},distance:(t,e,i)=>i.pts.length<2?null:A(t,e,i.pts)},Sr={id:"rotated-rectangle",name:"Rotated Rectangle",points:3,defaultStyle:{fill:!0,fillOpacity:.12},settings:_r,draw:t=>{if(t.pts.length<3)return;const e=Tr(t.pts[0],t.pts[1],t.pts[2]);t.ctx.beginPath(),t.ctx.moveTo(e[0].x,e[0].y);for(let i=1;i<4;i++)t.ctx.lineTo(e[i].x,e[i].y);t.ctx.closePath(),jt(t,()=>t.ctx.fill()),$t(t),t.ctx.stroke(),t.ctx.setLineDash([]),te(t,N(e),"center","middle")},distance:(t,e,i)=>{if(i.pts.length<3)return null;const n=Tr(i.pts[0],i.pts[1],i.pts[2]);if(!0===i.drawing.style.fill&&ue(t,e,n))return 0;let r=1/0;for(let i=0;i<4;i++)r=Math.min(r,I(t,e,n[i],n[(i+1)%4]));return r}};function Tr(t,e,i){const n=e.x-t.x,r=e.y-t.y,s=Math.hypot(n,r)||1,o=-r/s,l=n/s,a=(i.x-e.x)*o+(i.y-e.y)*l;return[t,e,{x:e.x+o*a,y:e.y+l*a},{x:t.x+o*a,y:t.y+l*a}]}const Ir={id:"double-curve",name:"Double Curve",points:3,settings:Ni,draw:t=>{if(t.pts.length<3)return;const[e,i,n]=t.pts;$t(t),t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.bezierCurveTo(i.x,i.y,e.x+n.x-i.x,e.y+n.y-i.y,n.x,n.y),t.ctx.stroke(),t.ctx.setLineDash([])},distance:(t,e,i)=>{if(i.pts.length<3)return null;const[n,r,s]=i.pts;return A(t,e,function(t,e,i,n,r){const s=[];for(let o=0;o<=r;o++){const l=o/r,a=1-l,c=a*a*a,h=3*a*a*l,d=3*a*l*l,u=l*l*l;s.push({x:c*t.x+h*e.x+d*i.x+u*n.x,y:c*t.y+h*e.y+d*i.y+u*n.y})}return s}(n,r,{x:n.x+s.x-r.x,y:n.y+s.y-r.y},s,24))}};const Or={id:"cyclic-lines",name:"Cyclic Lines",points:2,defaultStyle:{lineStyle:"dashed"},settings:Ni,draw:t=>{const[e,i]=t.pts,n=i.x-e.x;if(!Number.isFinite(n)||Math.abs(n)<.5)return;const r=t.rc.plotHeight*t.rc.dpr,s=t.rc.plotWidth*t.rc.dpr;$t(t),t.ctx.beginPath();for(let i=0;i<=12;i++){const o=Math.round(e.x+n*i)+.5;o<0||o>s||(t.ctx.moveTo(o,0),t.ctx.lineTo(o,r))}t.ctx.stroke(),t.ctx.setLineDash([])},distance:(t,e,i)=>{const n=i.pts[1].x-i.pts[0].x;if(!Number.isFinite(n)||Math.abs(n)<.5)return null;const r=Math.round((t-i.pts[0].x)/n);return r<0||r>12?null:Math.abs(t-(i.pts[0].x+n*r))}},Fr={id:"time-cycles",name:"Time Cycles",points:2,settings:Ni,draw:t=>{const[e,i]=t.pts,n=i.x-e.x;if(!Number.isFinite(n)||Math.abs(n)<1)return;const r=Math.abs(n)/2;$t(t),t.ctx.beginPath();for(let i=0;i<12;i++){const s=e.x+n*i+n/2;s+r<0||s-r>t.rc.plotWidth*t.rc.dpr||(t.ctx.moveTo(s+r,e.y),t.ctx.arc(s,e.y,r,0,Math.PI,!0))}t.ctx.stroke(),t.ctx.setLineDash([])},distance:(t,e,i)=>{const[n,r]=i.pts,s=r.x-n.x;if(!Number.isFinite(s)||Math.abs(s)<1)return null;const o=Math.abs(s)/2;let l=1/0;for(let i=0;i<12;i++){const r=n.x+s*i+s/2;e>n.y+2||(l=Math.min(l,Math.abs(Math.hypot(t-r,e-n.y)-o)))}return Number.isFinite(l)?l:null}},Lr={id:"sine-line",name:"Sine Line",points:2,settings:Ni,draw:t=>{const e=Ar(t.pts[0],t.pts[1]);if(null!==e){$t(t),t.ctx.beginPath(),t.ctx.moveTo(e[0].x,e[0].y);for(let i=1;i<e.length;i++)t.ctx.lineTo(e[i].x,e[i].y);t.ctx.stroke(),t.ctx.setLineDash([])}},distance:(t,e,i)=>{const n=Ar(i.pts[0],i.pts[1]);return null===n?null:A(t,e,n)}};function Ar(t,e){const i=e.x-t.x,n=e.y-t.y;if(!Number.isFinite(i)||Math.abs(i)<1)return null;const r=[];for(let e=0;e<=64;e++){const s=e/64;r.push({x:t.x+i*s,y:t.y+n*Math.sin(s*Math.PI*2)})}return r}const zr={id:"circle",name:"Circle",points:2,defaultStyle:{fill:!0},settings:_r,draw:t=>{const[e,i]=t.pts,n=Math.hypot(i.x-e.x,i.y-e.y);t.ctx.beginPath(),t.ctx.arc(e.x,e.y,n,0,2*Math.PI),jt(t,()=>t.ctx.fill()),$t(t),t.ctx.stroke(),t.ctx.setLineDash([]),te(t,{x0:e.x-n,y0:e.y-n,x1:e.x+n,y1:e.y+n},"center","middle")},distance:(t,e,i)=>{const[n,r]=i.pts,s=Math.hypot(r.x-n.x,r.y-n.y),o=Math.hypot(t-n.x,e-n.y);return!0===i.drawing.style.fill&&o<=s?0:Math.abs(o-s)}},Nr={id:"triangle",name:"Triangle",points:3,defaultStyle:{fill:!0},settings:_r,draw:t=>{t.ctx.beginPath(),t.ctx.moveTo(t.pts[0].x,t.pts[0].y),t.ctx.lineTo(t.pts[1].x,t.pts[1].y),t.ctx.lineTo(t.pts[2].x,t.pts[2].y),t.ctx.closePath(),jt(t,()=>t.ctx.fill()),$t(t),t.ctx.stroke(),t.ctx.setLineDash([]),te(t,N(t.pts.slice(0,3)),"center","middle")},distance:(t,e,i)=>A(t,e,[...i.pts,i.pts[0]])},Cr={id:"polyline",name:"Polyline",points:0,defaultStyle:{fill:!1},settings:st([U,Y]),draw:t=>{if(!(t.pts.length<2)){t.ctx.beginPath(),t.ctx.moveTo(t.pts[0].x,t.pts[0].y);for(let e=1;e<t.pts.length;e++)t.ctx.lineTo(t.pts[e].x,t.pts[e].y);!0===t.style.fill&&(t.ctx.closePath(),jt(t,()=>t.ctx.fill())),$t(t),t.ctx.stroke(),t.ctx.setLineDash([])}},distance:(t,e,i)=>A(t,e,i.pts)};const $r={id:"arc",name:"Arc",points:3,settings:Ni,draw:t=>{const[e,i,n]=t.pts;$t(t),t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.quadraticCurveTo(2*i.x-(e.x+n.x)/2,2*i.y-(e.y+n.y)/2,n.x,n.y),t.ctx.stroke(),t.ctx.setLineDash([])},distance:(t,e,i)=>A(t,e,function(t,e,i){const n=2*e.x-(t.x+i.x)/2,r=2*e.y-(t.y+i.y)/2,s=[];for(let e=0;e<=16;e++){const o=e/16,l=1-o;s.push({x:l*l*t.x+2*l*o*n+o*o*i.x,y:l*l*t.y+2*l*o*r+o*o*i.y})}return s}(i.pts[0],i.pts[1],i.pts[2]))},Dr={id:"curve",name:"Curve",points:3,settings:Ni,draw:t=>{const[e,i,n]=t.pts;$t(t),t.ctx.beginPath(),t.ctx.moveTo(e.x,e.y),t.ctx.quadraticCurveTo(i.x,i.y,n.x,n.y),t.ctx.stroke(),t.ctx.setLineDash([])},distance:(t,e,i)=>{const[n,r,s]=i.pts,o=[];for(let t=0;t<=16;t++){const e=t/16,i=1-e;o.push({x:i*i*n.x+2*i*e*r.x+e*e*s.x,y:i*i*n.y+2*i*e*r.y+e*e*s.y})}return A(t,e,o)}},jr={id:"highlighter",name:"Highlighter",points:0,freehand:!0,defaultStyle:{lineWidth:12,fillOpacity:.28},settings:st([E,J,zt,lr]),draw:t=>{t.pts.length<2||(t.ctx.setLineDash([]),cr(t,Math.max(2,(t.style.lineWidth||12)*t.rc.dpr),t.style.fillOpacity??.28))},distance:(t,e,i)=>{const n=A(t,e,i.pts);return n<=Math.max(6,(i.drawing.style.lineWidth??12)/2)?0:n}},Hr=[dr,ur,pr,fr,yr,xr,gr,mr,vr,wr,Mr,Bi,Wi,en,nn,on,Zi,rn,sn,zr,Nr,Cr,$r,Dr,Sr,Ir,Kn,Un,jr,kr,Vi,Ei,Ji,Ki,Ui,Or,Fr,Lr,ln,Pr,hn,un,_n,Ln,zn,Cn,Dn,Hn,Rn,Yn,qn,...Be,...hi,...Pi,nr,rr];let Br=!1;function Wr(){if(!Br){Br=!0;for(const t of Hr)Si(t)}}function Rr(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}const Vr=t=>"number"==typeof t&&Number.isFinite(t),Er=t=>"string"==typeof t,Jr=(t,e)=>"string"==typeof t&&e.includes(t),Kr=t=>"__proto__"===t||"constructor"===t||"prototype"===t,Ur=["solid","dashed","dotted"],Yr=["left","center","right"],qr=["top","middle","bottom"],Gr=["inside","outside"],Xr=["color","fillColor"],Zr=["lineWidth","fillOpacity","accountSize","risk"],Qr=["fill","extendLeft","extendRight","showLabels","showStats","pressure"],ts=["color","fontFamily","backgroundColor","borderColor"],es=["fontSize","wrapWidth","backgroundOpacity"],is=["bold","italic","wrap","background","border"];function ns(t,e,i){const n={value:t};for(const t of ts){const r=e[t];i(r)&&(n[t]=r)}for(const t of es){const i=e[t];Vr(i)&&(n[t]=i)}for(const t of is){const i=e[t];"boolean"==typeof i&&(n[t]=i)}return Jr(e.align,Yr)&&(n.align=e.align),Jr(e.valign,qr)&&(n.valign=e.valign),Jr(e.position,Gr)&&(n.position=e.position),n}function rs(t){return{color:t.fontColor,fontSize:t.fontSize,fontFamily:t.fontFamily,bold:"bold"===t.fontWeight||void 0,italic:"italic"===t.fontStyle||void 0,align:t.textAlign,valign:t.textVAlign,position:t.textPosition,wrap:t.wrap,wrapWidth:t.wrapWidth,background:t.background,backgroundColor:t.backgroundColor,backgroundOpacity:t.backgroundOpacity,border:t.border,borderColor:t.borderColor}}function ss(t,e=1/0){if(!Array.isArray(t)||0===t.length||t.length>e)return null;const i=[];for(const e of t){if(!Rr(e)||!Vr(e.time)||!Vr(e.price))return null;const t={time:e.time,price:e.price};Vr(e.pressure)&&e.pressure>=0&&e.pressure<=1&&(t.pressure=e.pressure),i.push(t)}return i}const os=t=>"viewport"===t.space?t.viewportPoints?.length??0:t.points.length;function ls(t,e=1/0){if(!Array.isArray(t)||0===t.length||t.length>e)return null;const i=[];for(const e of t){if(!Rr(e)||!Vr(e.x)||!Vr(e.y))return null;i.push({x:e.x,y:e.y})}return i}const as=(t,e,i)=>t<0||e-t>i?-t:e>i?i-e:0;const cs={x0:1/0,y0:1/0,x1:-1/0,y1:-1/0},hs={x0:-1/0,y0:-1/0,x1:1/0,y1:1/0};function ds(t,e,i){return!(e<t.x0||e>t.x1||i<t.y0||i>t.y1)}function us(t,e){let i=1/0,n=1/0,r=-1/0,s=-1/0;for(const e of t)i=Math.min(i,e.x),n=Math.min(n,e.y),r=Math.max(r,e.x),s=Math.max(s,e.y);return{x0:i-e,y0:n-e,x1:r+e,y1:s+e}}const ps=(t,e)=>({x0:Math.min(t.x0,e.x0),y0:Math.min(t.y0,e.y0),x1:Math.max(t.x1,e.x1),y1:Math.max(t.y1,e.y1)}),fs=(t,e,i,n)=>us(t,n),ys=(t,e)=>(i,n,r,s)=>{const o=n.style.extendLeft??t,l=n.style.extendRight??e,[a,c]=i;return o&&l?a.x===c.x&&a.y===c.y?us([a],s):a.y===c.y?{x0:-1/0,y0:a.y-s,x1:1/0,y1:a.y+s}:a.x===c.x?{x0:a.x-s,y0:-1/0,x1:a.x+s,y1:1/0}:hs:us(D(a,c,r.plotWidth,o,l),s)},xs=t=>(e,i,n,s)=>{const o=i.points,l=2===t?o[0].price:o[2].price,a=o[1].price-o[0].price,c=e[0].x,h=e[t-1].x,d=!0===i.style.extendLeft?0:Math.min(c,h),u=!0===i.style.extendRight?n.plotWidth:Math.max(c,h);let p=1/0,f=-1/0;for(const t of r(i.style.levels,y)){const e=n.priceScale.priceToY(l+a*t.ratio);p=Math.min(p,e),f=Math.max(f,e)}return{x0:d-4,y0:p-s,x1:u+4,y1:f+s}},gs=(t,e,i,n)=>{const r=e.points;if(t.length<2||r.length<2)return cs;const s=us(t,4);if(r.length<3)return{x0:s.x0,y0:-1/0,x1:s.x1,y1:1/0};const o=us(r.slice(0,3).map(t=>({x:0,y:i.priceScale.priceToY(t.price)})),n);return{x0:s.x0,y0:o.y0,x1:s.x1,y1:o.y1}},ms=(t,e)=>(i,n)=>{const r=t.bounds?.(i,n);return void 0===r?hs:{x0:r.x0-e,y0:r.y0-e,x1:r.x1+e,y1:r.y1+e}},_s=(t,e,i,n)=>r=>{const s=r[0];return{x0:s.x+t,y0:s.y+e,x1:s.x+i,y1:s.y+n}},bs=t=>(e,i,n)=>function(t,e,i,n){const r=Bn.get(t),s=e[0],o=e[1];let l;if(t===un&&void 0!==o)l={plate:pn(o,i)};else if(t===hn&&void 0!==s)l=dn(s,i,n);else{if(void 0===r||void 0===s)return;l=Mn(r,s,i,n)}const{plate:a,dot:c,post:h}=l,d=void 0!==c?{x:c.at.x-c.r,y:c.at.y-c.r,w:2*c.r,h:2*c.r}:h??a;return{x0:Math.min(a.x,d.x),y0:Math.min(a.y,d.y),x1:Math.max(a.x+a.w,d.x+d.w),y1:Math.max(a.y+a.h,d.y+d.h)}}(t,e,i,n)??hs,vs=new Map([[dr,ys(!1,!1)],[ur,ys(!1,!0)],[pr,ys(!0,!0)],[fr,fs],[on,fs],[Pr,fs],[kr,fs],[Cr,fs],[Nr,fs],[Dr,fs],[vr,fs],[Zi,fs],[rn,fs],[sn,fs],[Ui,fs],[yr,(t,e,i,n)=>({x0:-1/0,y0:t[0].y-n,x1:1/0,y1:t[0].y+n})],[xr,(t,e,i,n)=>({x0:t[0].x,y0:t[0].y-n,x1:1/0,y1:t[0].y+n})],[gr,(t,e,i,n)=>({x0:t[0].x-n,y0:-1/0,x1:t[0].x+n,y1:1/0})],[wr,(t,e,i,n)=>{const r=us(t.slice(0,2),0),s=Math.max(1e-6,(r.x1-r.x0)/2),o=Math.max(1e-6,(r.y1-r.y0)/2),l=1+n/Math.min(s,o),a=(r.x0+r.x1)/2,c=(r.y0+r.y1)/2;return{x0:a-s*l,y0:c-o*l,x1:a+s*l,y1:c+o*l}}],[zr,(t,e,i,n)=>{const[r,s]=t;return us([r],Math.hypot(s.x-r.x,s.y-r.y)+n)}],[Mr,(t,e,i,n)=>{const[r,s,o]=t,l=o.y-(r.y+.5*(s.y-r.y));return us([r,s,{x:r.x,y:r.y+l},{x:s.x,y:s.y+l}],n)}],[Sr,(t,e,i,n)=>t.length<3?cs:us(t.slice(0,2),Math.hypot(t[2].x-t[1].x,t[2].y-t[1].y)+n)],[$r,(t,e,i,n)=>{const[r,s,o]=t;return us([r,o,{x:2*s.x-(r.x+o.x)/2,y:2*s.y-(r.y+o.y)/2}],n)}],[Ir,(t,e,i,n)=>{if(t.length<3)return cs;const[r,s,o]=t;return us([r,s,o,{x:r.x+o.x-s.x,y:r.y+o.y-s.y}],n)}],[jr,(t,e,i,n)=>us(t,Math.max(n,Math.max(6,(e.style.lineWidth??12)/2)))],[Bi,xs(2)],[Wi,xs(3)],[en,gs],[nn,gs],[ln,ms(ln,3)],[Rn,ms(Rn,0)],[Or,(t,e,i,n)=>{const[r,s]=t,o=r.x+12*(s.x-r.x);return{x0:Math.min(r.x,o)-n,y0:-1/0,x1:Math.max(r.x,o)+n,y1:1/0}}],[Fr,(t,e,i,n)=>{const[r,s]=t,o=r.x+12*(s.x-r.x);return{x0:Math.min(r.x,o)-n,y0:r.y-Math.abs(s.x-r.x)/2-n,x1:Math.max(r.x,o)+n,y1:r.y+2}}],[Lr,(t,e,i,n)=>{const[r,s]=t,o=Math.abs(s.y-r.y);return us([{x:r.x,y:r.y-o},{x:s.x,y:r.y+o}],n)}],[Ei,(t,e,i,n)=>{const[s,o]=t,l=r(e.style.levels,_).map(t=>({x:s.x+(o.x-s.x)*t.ratio,y:0})),a=us(l,n);return{x0:a.x0,y0:0===l.length?1/0:-1/0,x1:a.x1,y1:0===l.length?-1/0:1/0}}],[Ji,(t,e,i,n)=>{const[s,o]=t;return us([s,...r(e.style.levels,x).map(t=>D(s,{x:o.x,y:s.y+(o.y-s.y)*t.ratio},i.plotWidth,!1,!0)[1])],n)}],[Ki,(t,e,i,n)=>{const[s,o]=t;return us([s,...r(e.style.levels,m).map(t=>D(s,{x:o.x,y:s.y+(o.y-s.y)*t.ratio},i.plotWidth,!1,!0)[1])],n)}],[Vi,(t,e,i,n)=>{const[s,o,l]=t,a=l.x-o.x,c=l.y-o.y;let h=cs;for(const t of r(e.style.levels,y))h=ps(h,us(D({x:s.x+a*t.ratio,y:s.y+c*t.ratio},{x:o.x+a*t.ratio,y:o.y+c*t.ratio},i.plotWidth,!0===e.style.extendLeft,!0===e.style.extendRight),n));return h}],[un,(t,e,i,n)=>t.length<2?cs:ps(us(t.slice(0,2),n),bs(un)(t,e,i,n))],[hn,bs(hn)],[_n,_s(-8,-24,16,8)],[Kn,_s(-8,-20,8,20)],[Un,_s(-8,-20,8,20)],[Yn,_s(-8,-20,8,20)],[qn,_s(-8,-20,8,20)],[Ln,bs(Ln)],[zn,bs(zn)],[Cn,bs(Cn)],[Dn,bs(Dn)],[Hn,bs(Hn)]]);for(const t of Pi)vs.set(t,fs);const ws=.01;let Ms=0,Ps=!1;function ks(){const e=[],i=[],n=[];let r=0,s=!1,o=[];const l=t=>{const e=r++;Object.is(n[e],t)||(n[e]=t,s=!0)},a=(t,e)=>{const i=void 0===t||"viewport"===t.space?void 0:t.points[0];l(void 0===i?null:e.dataLayer.timeToIndexFloat(i.time)),l(void 0===i?null:e.priceScale.priceToY(i.price))};return{bodies:e,anchors:i,reset(t){e.length=0,i.length=0,n.length=0,o=[...new Set(t.map(t=>t.tool))]},check(c,h,d){!function(){if(!Ps){Ps=!0;try{globalThis.document?.fonts?.addEventListener?.("loadingdone",()=>{Ms++})}catch{}}}(),r=0,s=!1;const u=c.timeScale,p=c.dataLayer,f=c.priceScale,y=p.length;l(Ms),l(d),l(c.plotWidth),l(c.plotHeight),l(u.indexToX(0)),l(u.indexToX(1)),l(y),l(p.indexToTime?.(0)),l(p.indexToTime?.(1)),l(p.indexToTime?.(y-2)),l(p.indexToTime?.(y-1)),l(p.sessionCalendar),l(f.priceToY(1)),l(f.priceToY(1e3)),l(void 0===f.options?.mode?-1:t.indexOf(f.options.mode));const x=c.bars?.();l(void 0!==x&&x.length>0?x:null),a(h[0],c),a(h[h.length-1],c);for(const t of o)l(Ii(t)?Ti(t):null);r!==n.length&&(n.length=r,s=!0),s&&(e.length=0,i.length=0)}}}const Ss=t=>Number.isFinite(t.zIndex)?t.zIndex:0,Ts=t=>!1===t?.policy?.editable;function Is(t){return Ii(t.tool)&&("viewport"!==t.space||!0===Ti(t.tool).viewport)}function Os(t,e,i,n){const r=function(t,e,i){return t.map(t=>({x:t.x*e,y:t.y*i}))}(e,i,n);return 0===r.length?r:function(t,e,i,n){const r=as(e.x0,e.x1,i),s=as(e.y0,e.y1,n);return t.map(t=>({x:t.x+r,y:t.y+s}))}(r,Fs(t,r)??N(r),i,n)}function Fs(t,e){const i=Ii(t.tool)?Ti(t.tool):void 0;return void 0!==i&&e.length>=Math.max(1,i.points)?i.bounds?.(e,t):void 0}function Ls(t,e){return"viewport"===e.space?Os(e,e.viewportPoints??[],t.plotWidth,t.plotHeight):e.points.map(e=>Ct(t,e))}function As(t){return t.slice().sort((t,e)=>Ss(t)-Ss(e))}function zs(t,e){return Ii(t)&&!0===Ti(t).freehand&&e>2?[0,e-1]:Array.from({length:e},(t,e)=>e)}class Ns{constructor(t="top"){Object.defineProperty(this,"_order",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_drawings",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_selected",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_hovered",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_snap",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_preview",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_below",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_above",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_touch",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_index",{enumerable:!0,configurable:!0,writable:!0,value:ks()}),Object.defineProperty(this,"_selectedAt",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._order=t}attached(t){this._host=t}detached(){this._host=null}zOrder(){return"series"===this._order?"normal":this._order}autoscaleInfo(){return null}setDrawings(t){this._drawings=As(t),this._index.reset(this._drawings),this._selectedAt=null,this._host?.requestUpdate()}setSelected(t){t.length===this._selected.length&&t.every((t,e)=>t===this._selected[e])||(this._selected=t.slice(),this._selectedAt=null,this._host?.requestUpdate())}setHovered(t){t!==this._hovered&&(this._hovered=t,this._requestOverlay())}hovered(){return this._hovered}setSnapPoint(t){(null===t?null!==this._snap:null===this._snap||this._snap.time!==t.time||this._snap.price!==t.price)&&(this._snap=null===t?null:{time:t.time,price:t.price},this._requestOverlay())}snapPoint(){return this._snap}setPointerType(t){this._touch="touch"===t}setPreview(t){this._preview=t,this._host?.requestUpdate()}setBelow(t){const e=null===t?[]:Array.isArray(t)?[...t]:[t];if(e.length!==this._below.length||!e.every((t,e)=>t===this._below[e])){for(const t of this._below)e.includes(t)||(t._above=null,t._host?.requestUpdate());this._below=e;for(const t of e)null!==t._above&&t._above!==this&&(t._above._below=t._above._below.filter(e=>e!==t)),t._above=this,t._host?.requestUpdate();this._host?.requestUpdate()}}_requestOverlay(){null===this._above&&this._host?.requestUpdate()}_isTouch(t){const e=t.pointerType;return"touch"===e||"mouse"!==e&&"pen"!==e&&this._touch}_grabRadius(t){return this._isTouch(t)?12:6}_handleRadius(t){return this._isTouch(t)?10:5}_points(t,e){return Ls(t,e)}_handled(){if(0===this._selected.length)return[];const t=new Set(this._selected);return this._drawings.filter(e=>t.has(e.id)&&!0!==e.locked&&!1!==e.visible&&Is(e))}_hoverHandled(){const t=this._hovered;if(null===t||this._selected.includes(t))return null;const e=this._drawings.find(e=>e.id===t);return void 0===e||!0===e.locked||!1===e.visible||Ts(e)||!Is(e)?null:e}draw(t,e){t.save(),t.beginPath(),t.rect(0,0,Math.round(e.plotWidth*e.dpr),Math.round(e.plotHeight*e.dpr)),t.clip();try{!function(t,e){const i=vt.get(t);vt.set(t,new Map);try{return e()}finally{i?vt.set(t,i):vt.delete(t)}}(t,()=>this._drawContent(t,this._drawingContext(e)))}finally{t.restore()}}_drawingContext(t){return t.readoutPriceScale?{...t,priceScale:t.readoutPriceScale}:t}_drawContent(t,e){const i=new Set(this._selected),n=null===this._preview?this._drawings:[...this._drawings,this._preview];for(const r of n){if(!1===r.visible||!Is(r))continue;const n=Ti(r.tool),s=this._points(e,r);if(0===s.length||!s.every(t=>Number.isFinite(t.x)&&Number.isFinite(t.y)))continue;if(os(r)<Math.max(1,n.points)){r===this._preview&&this._drawPlacementGuide(t,e,s,r);continue}const o={color:r.style.color??e.theme.lineColor,lineWidth:r.style.lineWidth??1.5,...r.style},l=e.dpr;t.save(),r===this._preview&&(t.globalAlpha=.7),n.draw({ctx:t,rc:e,drawing:r,selected:i.has(r.id),pts:s.map(t=>({x:t.x*l,y:t.y*l})),style:{...o,color:o.color,lineWidth:o.lineWidth},formatPrice:t=>e.priceScale.format(t)}),t.restore()}if(null!==this._above)return;const r=[this,...this._below];for(const i of r){const n=i._hoverHandled();null!==n&&this._drawHandles(t,e,this._points(e,n),n.tool,!0)}for(const i of r)for(const n of i._handled())this._drawHandles(t,e,this._points(e,n),n.tool,Ts(n));null!==this._snap&&this._drawSnapRing(t,e,Ct(e,this._snap))}_drawPlacementGuide(t,e,i,n){const r=e.dpr;t.save(),t.globalAlpha*=.7,t.strokeStyle=n.style.color??e.theme.lineColor,t.lineWidth=Math.max(1,(n.style.lineWidth??1.5)*r),t.setLineDash([3*r,3*r]),t.beginPath(),t.moveTo(i[0].x*r,i[0].y*r);for(let e=1;e<i.length;e++)t.lineTo(i[e].x*r,i[e].y*r);t.stroke(),t.setLineDash([]);for(const n of i)t.beginPath(),t.arc(n.x*r,n.y*r,3*r,0,2*Math.PI),t.fillStyle=e.theme.background,t.fill(),t.stroke();t.restore()}_drawHandles(t,e,i,n,r){const s=e.dpr;t.save(),t.setLineDash([]),t.lineWidth=Math.max(1,Math.round((r?1:1.5)*s)),r&&(t.globalAlpha=.6);for(const r of zs(n,i.length)){const n=i[r];t.beginPath(),t.arc(n.x*s,n.y*s,5*s,0,2*Math.PI),t.fillStyle=e.theme.background,t.fill(),t.strokeStyle=e.theme.lineColor,t.stroke()}t.restore()}_drawSnapRing(t,e,i){if(!Number.isFinite(i.x)||!Number.isFinite(i.y))return;const n=e.dpr;t.save(),t.setLineDash([]),t.globalAlpha=.9,t.lineWidth=Math.max(1,Math.round(1.5*n)),t.strokeStyle=e.theme.axisText,t.beginPath(),t.arc(i.x*n,i.y*n,5.5*n,0,2*Math.PI),t.stroke(),t.restore()}hitTest(t,e,i){if(i=this._drawingContext(i),null!==this._above)return null;const n=[this,...this._below];for(const t of n)t._index.check(i,t._drawings,t._grabRadius(i));for(const r of n){const n=r._hitHandle(t,e,i);if(null!==n)return n}const r=this._hitBody(t,e,i);if(null!==r)return r;for(const n of this._below){const r=n._hitBody(t,e,i);if(null!==r)return{...r,paintedBy:n}}return null}_selectedPositions(){if(null!==this._selectedAt)return this._selectedAt;const t=new Set(this._selected),e=[];return t.size>0&&this._drawings.forEach((i,n)=>{t.has(i.id)&&!0!==i.locked&&!1!==i.visible&&e.push(n)}),this._selectedAt=e}_measure(t,e,i){if(!1===t.visible||!0===t.locked||!1===t.policy?.selectable||!Is(t))return cs;const n=Ti(t.tool);return os(t)<Math.max(1,n.points)?cs:function(t,e,i,n,r){const s=vs.get(t);if(void 0!==s)try{const t=s(e,i,n,r);return{x0:t.x0-ws,y0:t.y0-ws,x1:t.x1+ws,y1:t.y1+ws}}catch{return hs}}(n,this._points(e,t),t,e,i)??hs}_hitHandle(t,e,i){var n;const r=this._handleRadius(i)+2;for(const s of this._selectedPositions()){const o=this._drawings[s];if(!Is(o)||Ts(o))continue;if(!ds((n=this._index.anchors)[s]??(n[s]=us(this._points(i,o),r)),t,e))continue;const l=this._points(i,o);for(const i of zs(o.tool,l.length))if(Math.hypot(t-l[i].x,e-l[i].y)<=r)return{externalId:`draw:${o.id}#${i}`,zOrder:"top",distance:0,cursor:"grabbing",draggable:!0}}return null}_hitBody(t,e,i){var n;const r=this._grabRadius(i);let s=null;for(let o=this._drawings.length-1;o>=0;o--){const l=this._drawings[o];if(!ds((n=this._index.bodies)[o]??(n[o]=this._measure(l,i,r)),t,e))continue;if(!1===l.visible||!0===l.locked||!1===l.policy?.selectable||!Is(l))continue;const a=Ti(l.tool);if(os(l)<Math.max(1,a.points))continue;const c=a.distance(t,e,{pts:this._points(i,l),drawing:l,rc:i});if(null!==c&&Number.isFinite(c)&&!(c>r)&&((null===s||c<s.distance)&&(s={d:l,distance:c}),0===c))break}if(null===s)return null;const o=Ts(s.d);return{externalId:`draw:${s.d.id}`,zOrder:"top",distance:s.distance,cursor:o?"pointer":"move",draggable:!o}}}const Cs=3,$s={month:1,quarter:3,year:12},Ds=t=>"string"==typeof t&&""!==t.trim()&&t.length<=64?t.trim():void 0;function js(t){if(!Rr(t))return null;const e=Ds(t.from),i=Ds(t.to);return void 0===e&&void 0===i?null:{...void 0===e?{}:{from:e},...void 0===i?{}:{to:i}}}function Hs(t){if("string"!=typeof t||""===t.trim())return null;const i=e(t);if(null===i)return null;const n=i.bucketing;return"interval"===n.mode?n.seconds:"calendar"===n.mode?$s[n.unit]*Math.max(1,Math.floor(n.count??1))*2629746:null}function Bs(t){const e="object"==typeof t&&null!==t?t.interval:void 0;return"string"==typeof e&&""!==e.trim()?e:null}const Ws=Symbol.for("openalgo-charts.data-context.passing");function Rs(t){const e=Hs(t);return null===e?()=>!0:t=>{const i=t.intervals;if(void 0===i)return!0;const n=Hs(i.from),r=Hs(i.to),s=null!==n&&null!==r?Math.min(n,r):n,o=null!==n&&null!==r?Math.max(n,r):r;return(null===s||e>=s)&&(null===o||e<=o)}}function Vs(t,e){return Rs(e)(t)}function Es(t){return t.some(t=>void 0!==t.intervals)?3:2}const Js=["selectable","editable","persistent","listed"];let Ks=1;function Us(t){const e=Array.isArray(t)?t:Rr(t)&&Array.isArray(t.drawings)?t.drawings:null,i=[];if(null===e)return{version:Es(i),drawings:i};const n=new Set;for(const t of e){const e=qs(t);if(null!==e){for(;""===e.id||n.has(e.id);)e.id="m"+Ks++;n.add(e.id),i.push(e)}}const r=Ys(Rr(t)?t.groups:void 0,i);return{version:Es(i),drawings:i,...r.length?{groups:r}:{}}}function Ys(t,e){if(!Array.isArray(t))return[];const i=new Set(e.map(t=>t.id)),n=new Set,r=new Set,s=[];for(const e of t){if(!Rr(e)||"string"!=typeof e.id||!e.id.trim()||n.has(e.id)||"string"!=typeof e.name||!e.name.trim()||!Array.isArray(e.members))continue;const t=[];for(const n of e.members)"string"==typeof n&&i.has(n)&&!r.has(n)&&(t.push(n),r.add(n));t.length&&(n.add(e.id),s.push({id:e.id,name:e.name.trim(),members:t}))}return s}function qs(t){if(!Rr(t))return null;const e=t.tool;if("string"!=typeof e||""===e)return null;const i="viewport"===t.space?ls(t.viewportPoints):void 0;if(null===i)return null;const n=void 0===i?ss(t.points):[];if(null===n)return null;const r=void 0===t.paneIndex?0:t.paneIndex;if(!Vr(r)||r<0||!Number.isInteger(r))return null;const s=Rr(t.style)?t.style:{},o={id:"string"==typeof t.id?t.id:Vr(t.id)?String(t.id):"",tool:e,points:n,...void 0===i?{}:{space:"viewport",viewportPoints:i},style:Gs(s,e),paneIndex:r,zIndex:Vr(t.zIndex)?t.zIndex:0},l=(Rr(a=t.text)&&"string"==typeof a.value?ns(a.value,a,Er):null)??function(t){return"string"==typeof t.text?ns(t.text,rs(t),Er):null}(s);var a;null!==l&&(o.text=l),Rr(t.props)&&(o.props=Xs(t.props,0)),"boolean"==typeof t.locked&&(o.locked=t.locked),"boolean"==typeof t.visible&&(o.visible=t.visible);const c=js(t.intervals);if(null!==c&&(o.intervals=c),Rr(t.policy)){const e={};for(const i of Js)"boolean"==typeof t.policy[i]&&(e[i]=t.policy[i]);Object.keys(e).length>0&&(o.policy=e)}return"string"==typeof t.stackAbove&&""!==t.stackAbove&&(o.stackAbove=t.stackAbove),Vr(t.createdAt)&&(o.createdAt=t.createdAt),o}function Gs(t,e){const i={};for(const e of Xr){const n=t[e];"string"==typeof n&&(i[e]=n)}for(const e of Zr){const n=t[e];Vr(n)&&(i[e]=n)}for(const e of Qr){const n=t[e];"boolean"==typeof n&&(i[e]=n)}Jr(t.lineStyle,Ur)&&(i.lineStyle=t.lineStyle);const n=function(t,e){if(!Array.isArray(t))return null;const i=[];return t.forEach((t,n)=>{if(Vr(t))i.push(function(t,e,i){return"fib-time-zone"===t?{ratio:e}:"gann-fan"===t?{ratio:e,color:h(i)}:{ratio:e,color:a(e)}}(e,t,n));else if(Rr(t)&&Vr(t.ratio)){const e={ratio:t.ratio};"string"==typeof t.color&&(e.color=t.color),"boolean"==typeof t.enabled&&(e.enabled=t.enabled),"string"==typeof t.label&&(e.label=t.label),i.push(e)}}),0===i.length&&t.length>0?null:i}(t.levels,e);return null!==n&&(i.levels=n),i}function Xs(t,e){const i={};for(const[n,r]of Object.entries(t)){if(Kr(n))continue;const t=Zs(r,e);void 0!==t&&(i[n]=t)}return i}function Zs(t,e){return null===t||"boolean"==typeof t||"string"==typeof t?t:"number"==typeof t?Number.isFinite(t)?t:void 0:e>=8?void 0:Array.isArray(t)?t.map(t=>Zs(t,e+1)??null):Rr(t)?Xs(t,e+1):void 0}const Qs="openalgo-charts/drawings",to=3,eo=4096;let io=null;function no(){io=null}function ro(){const t=globalThis.navigator,e=t?.clipboard;return void 0===e||"function"!=typeof e.writeText||"function"!=typeof e.readText?null:e}function so(t){const{id:e,createdAt:i,policy:n,...r}=oo(t);return r}function oo(t){const e={...t,points:t.points.map(lo),style:ao(t.style)};return void 0!==t.viewportPoints&&(e.viewportPoints=t.viewportPoints.map(t=>({x:t.x,y:t.y}))),void 0!==t.text&&(e.text={...t.text}),void 0!==t.props&&(e.props=JSON.parse(JSON.stringify(t.props))),void 0!==t.policy&&(e.policy={...t.policy}),void 0!==t.intervals&&(e.intervals={...t.intervals}),e}function lo(t){return void 0===t.pressure?{time:t.time,price:t.price}:{time:t.time,price:t.price,pressure:t.pressure}}function ao(t){const e={...t};return void 0!==t.levels&&(e.levels=t.levels.map(t=>({...t}))),e}function co(t){return JSON.stringify({[Qs]:{version:Es(t),drawings:t.map(t=>({tool:t.tool,points:t.points.map(lo),..."viewport"===t.space?{space:"viewport",viewportPoints:(t.viewportPoints??[]).map(t=>({x:t.x,y:t.y}))}:{},style:t.style??{},...void 0===t.text?{}:{text:t.text},...void 0===t.props?{}:{props:t.props},paneIndex:t.paneIndex,zIndex:Number.isFinite(t.zIndex)?t.zIndex:0,...void 0===t.stackAbove?{}:{stackAbove:t.stackAbove},...void 0===t.locked?{}:{locked:t.locked},...void 0===t.visible?{}:{visible:t.visible},...void 0===t.intervals?{}:{intervals:{...t.intervals}}}))}})}const ho=t=>"string"==typeof t&&t.length<=eo,uo=["text","fontSize","fontFamily","fontWeight","fontStyle","background","backgroundColor","backgroundOpacity","border","borderColor","wrap","wrapWidth","textAlign","textVAlign","textPosition","fontColor"];function po(t){if(!Array.isArray(t)||t.length>64)return null;const e=[];for(const i of t)if(Vr(i))e.push({ratio:i});else{if(!Rr(i)||!Vr(i.ratio))return null;{const t={ratio:i.ratio};ho(i.color)&&(t.color=i.color),"boolean"==typeof i.enabled&&(t.enabled=i.enabled),ho(i.label)&&(t.label=i.label),e.push(t)}}return e}function fo(t){return Rr(t)&&ho(t.value)?ns(t.value,t,ho):null}function yo(t,e=0){if(!Rr(t))return null;const i={};let n=0;for(const[r,s]of Object.entries(t)){if(Kr(r))continue;if(++n>64)return null;const t=xo(s,e);void 0!==t&&(i[r]=t)}return i}function xo(t,e){if("boolean"==typeof t||Vr(t))return t;if("string"==typeof t)return t.length<=eo?t:void 0;if(Array.isArray(t)){if(t.length>64||e+1>=3)return;const i=[];for(const n of t){const t=xo(n,e+1);if(void 0===t)return;i.push(t)}return i}if(Rr(t)){if(e+1>=3)return;return yo(t,e+1)??void 0}}function go(t){if(!Rr(t))return null;if("string"!=typeof t.tool||""===t.tool||t.tool.length>eo)return null;if(!Ii(t.tool))return null;const e="viewport"===t.space?ls(t.viewportPoints,2e4):void 0;if(null===e||void 0!==e&&!Oi(t.tool))return null;const i=void 0===e?ss(t.points,2e4):[];if(null===i)return null;const n=function(t){if(void 0===t)return{};if(!Rr(t))return null;const e={};let i=0;for(const[n,r]of Object.entries(t))if(!Kr(n)){if(++i>64)return null;if(!uo.includes(n))if(Jr(n,Xr))ho(r)&&(e[n]=r);else if(Jr(n,Zr))Vr(r)&&(e[n]=r);else if(Jr(n,Qr))"boolean"==typeof r&&(e[n]=r);else if("lineStyle"===n)Jr(r,Ur)&&(e[n]=r);else if("levels"===n){const t=po(r);null!==t&&(e[n]=t)}else if("string"==typeof r){if(r.length>eo)return null;e[n]=r}else if("boolean"==typeof r||Vr(r))e[n]=r;else if(Array.isArray(r)){if(r.length>64)return null;r.every(Vr)&&(e[n]=r.slice())}}return e}(t.style);if(null===n)return null;const r=void 0===t.paneIndex?0:t.paneIndex;if(!Vr(r)||r<0||!Number.isInteger(r))return null;if(void 0!==t.locked&&"boolean"!=typeof t.locked)return null;if(void 0!==t.visible&&"boolean"!=typeof t.visible)return null;const s=void 0===t.intervals?void 0:function(t){const e=js(t);if(null===e||!Rr(t))return null;const i=i=>void 0===t[i]==(void 0===e[i]);return i("from")&&i("to")?e:null}(t.intervals);if(null===s)return null;const o=fo(t.text)??(Rr(t.style)?function(t){return"string"==typeof t.text?fo({value:t.text,...rs(t)}):null}(t.style):null),l=void 0===t.props?null:yo(t.props),a={tool:t.tool,points:i,...void 0===e?{}:{space:"viewport",viewportPoints:e},style:n,paneIndex:r,zIndex:Vr(t.zIndex)?t.zIndex:0};return null!==o&&(a.text=o),null!==l&&(a.props=l),void 0!==t.locked&&(a.locked=t.locked),void 0!==t.visible&&(a.visible=t.visible),void 0!==s&&(a.intervals=s),ho(t.stackAbove)&&""!==t.stackAbove&&(a.stackAbove=t.stackAbove),Vr(t.createdAt)&&(a.createdAt=t.createdAt),a}function mo(t){if("string"!=typeof t||0===t.length)return null;let e;try{e=JSON.parse(t)}catch{return null}if(!Rr(e))return null;const i=e[Qs];if(!Rr(i))return null;if(!Vr(i.version)||i.version<1||i.version>3)return null;const n=i.drawings;if(!Array.isArray(n)||0===n.length||n.length>512)return null;for(const t of n)if(null===go(t))return null;const r=Us(n).drawings;if(r.length!==n.length)return null;const s=[];for(const t of r){const e=go(t);if(null===e)return null;s.push(e)}return s}class _o{constructor(t={}){Object.defineProperty(this,"_port",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_fallback",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_lastError",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._port=void 0===t.port?ro():t.port,this._fallback=t.fallbackToMemory??!0}setPort(t){this._port=t}setFallbackToMemory(t){this._fallback=t}lastError(){return this._lastError}async write(t){if(0===t.length)return!1;let e;try{e=co(t)}catch(t){return this._lastError=String(t),!1}this._lastError=null;let i=!1;if(null!==this._port)try{await this._port.writeText(e),i=!0}catch(t){this._lastError=String(t)}else this._lastError="openalgo-charts: no system clipboard available";return this._fallback?(io=e,!0):i}async read(){if(this._lastError=null,null!==this._port)try{const t=mo(await this._port.readText());if(null!==t)return t}catch(t){this._lastError=String(t)}return this._fallback?mo(io):null}}const bo=t=>Number.isFinite(t.time)&&Number.isFinite(t.price),vo="input-anchor:";function wo(t,e,n){let r;try{r=i(e.indicatorId)}catch{return null}const s=r.inputs.find(t=>t.key===n);if("price"!==s?.type)return null;const o="object"==typeof s.pick&&null!==s.pick?s.pick:{};if(void 0!==o.paneIndex&&void 0!==o.priceScaleId)return{paneIndex:o.paneIndex,priceScaleId:o.priceScaleId};const l=t.panes?.()??[],a=new Map;for(const t of r.plots){const i=e.series(t.key),n=e.plotPriceScaleId(t.key);if(!i||null===n)continue;const r=i.priceScale(),s=l.findIndex(t=>t.scales().includes(r));s<0||void 0!==o.paneIndex&&o.paneIndex!==s||void 0!==o.priceScaleId&&o.priceScaleId!==n||a.set(`${s}:${n}`,{paneIndex:s,priceScaleId:n})}return 1===a.size?[...a.values()][0]:null}class Mo{constructor(t,e,i,n,r,s,o){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"studyId",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"priceKey",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"timeKey",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"target",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"_scale",{enumerable:!0,configurable:!0,writable:!0,value:s}),Object.defineProperty(this,"_live",{enumerable:!0,configurable:!0,writable:!0,value:o}),Object.defineProperty(this,"time",{enumerable:!0,configurable:!0,writable:!0,value:Number.NaN}),Object.defineProperty(this,"price",{enumerable:!0,configurable:!0,writable:!0,value:Number.NaN}),Object.defineProperty(this,"color",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"editable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null})}attached(t){this._host=t}detached(){this._host=null}zOrder(){return"top"}autoscaleInfo(){return null}update(){this._host?.requestUpdate()}scale(){return this._scale(this.target)}_at(t){const e=this.scale();if(null===e||!Number.isFinite(this.time)||!Number.isFinite(this.price))return null;const i=t.timeScale.indexToX(t.dataLayer.timeToIndexFloat(this.time)),n=e.priceToY(this.price);return Number.isFinite(i)&&Number.isFinite(n)?{x:i,y:n}:null}draw(t,e){const i=this._at(e);if(null===i)return;const{dpr:n}=e,r=this.editable&&(e.hoverId===this.id||e.dragId===this.id),s=this.color??e.theme.crosshair,o=i.x*n,l=i.y*n,a=e.plotWidth*n,c=e.plotHeight*n;if(t.save(),t.beginPath(),t.rect(0,0,Math.round(a),Math.round(c)),t.clip(),r){const e=Math.round(o)+.5,i=Math.round(l)+.5;t.globalAlpha=.6,t.strokeStyle=s,t.lineWidth=Math.max(1,Math.round(n)),t.setLineDash([4*n,4*n]),t.beginPath(),t.moveTo(e,0),t.lineTo(e,c),t.moveTo(0,i),t.lineTo(a,i),t.stroke(),t.setLineDash([]),t.globalAlpha=1}t.beginPath(),t.arc(o,l,(r?6:5)*n,0,2*Math.PI),t.fillStyle=e.theme.background,t.fill(),t.lineWidth=2*n,t.strokeStyle=s,t.stroke(),t.beginPath(),t.arc(o,l,1.5*n,0,2*Math.PI),t.fillStyle=s,t.fill(),t.restore()}hitTest(t,e,i){if(!this.editable||!this._live())return null;const n=this._at(i);if(null===n||n.x<0||n.x>i.plotWidth||n.y<0||n.y>i.plotHeight)return null;const r=Math.hypot(t-n.x,e-n.y);if(r>9)return null;const s=this.scale();return{externalId:this.id,zOrder:"top",distance:r,cursor:"move",draggable:!0,cancelOnEscape:!0,...null===s?{}:{priceScale:s}}}}class Po{constructor(t,e){Object.defineProperty(this,"_chart",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"_hooks",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_handles",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_points",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_off",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_drag",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_picking",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_live",{enumerable:!0,configurable:!0,writable:!0,value:()=>!this._picking&&!this._hooks.placing()}),Object.defineProperty(this,"_scaleOf",{enumerable:!0,configurable:!0,writable:!0,value:t=>{const e=(this._chart.panes?.()??[])[t.paneIndex];return e&&Object.prototype.hasOwnProperty.call(e.scaleStates(),t.priceScaleId)?e.scaleFor(t.priceScaleId):null}});const i=(e,i)=>{this._off.push(t.on(e,i))};for(const t of["objects:change","indicatorRemoved","paneMoved","paneRemoved"])i(t,()=>this._sync());i("drag:start",t=>this._onDragStart(t)),i("drag",t=>this._onDrag(t)),i("drag:end",t=>this._onDragEnd(t)),i("drag:cancel",t=>{this._drag?.handle.id===t.id&&this._cancelDrag()}),i("draw:tool",()=>{this._cancelDrag(),this._refresh()}),i("pick:start",()=>{this._picking=!0,this._cancelDrag(),this._refresh()}),i("pick:end",()=>{this._picking=!1,this._refresh()}),i("data:context",()=>this._cancelDrag()),i("destroy",()=>this.destroy()),this._sync()}destroy(){if(!this._destroyed){this._destroyed=!0;for(const t of this._off.splice(0))t();for(const t of this._handles.values())this._chart.removePrimitive(t);this._handles.clear(),this._points.clear(),this._drag=null}}_study(t){return this._chart.indicators?.().find(e=>e.id===t)}_sync(){if(this._destroyed)return;const t=new Set,e=new Set;for(const r of this._chart.indicators?.()??[]){let s;try{s=i(r.indicatorId)}catch{continue}for(const i of s.inputs){if("price"!==i.type||!0!==i.anchor||void 0===i.timeKey)continue;const o=`${vo}${r.id}:${i.key}`;if(e.add(o),this._watch(o,r,{studyId:r.id,priceKey:i.key,timeKey:i.timeKey}),!r.visible())continue;const l=wo(this._chart,r,i.key);if(null===l)continue;t.add(o);let a=this._handles.get(o);void 0!==a&&a.target.paneIndex!==l.paneIndex&&(this._chart.removePrimitive(a),a=void 0),void 0===a&&(a=new Mo(o,r.id,i.key,i.timeKey,l,this._scaleOf,this._live),this._handles.set(o,a),this._chart.addPrimitive(a,l.paneIndex)),a.target=l;const c=r.settings();a.editable=!1!==r.policy().configurable;const h=s.plots[0],d=void 0===h?void 0:c[n(h).color];a.color="string"==typeof d&&d?d:null,this._drag?.handle!==a&&(a.time=c[i.timeKey],a.price=c[i.key]),a.update()}}for(const[e,i]of this._handles)t.has(e)||(this._drag?.handle===i&&(this._drag=null),this._chart.removePrimitive(i),this._handles.delete(e));for(const t of this._points.keys())e.has(t)||this._points.delete(t)}_watch(t,e,i){const n=e.settings(),r={time:n[i.timeKey],price:n[i.priceKey]},s=this._points.get(t);if(this._points.set(t,{study:e,point:r}),void 0===s||s.study!==e||(o=s.point,l=r,Object.is(o.time,l.time)&&Object.is(o.price,l.price)))return;var o,l;if(!1===e.policy().configurable||!bo(s.point)||!bo(r))return;const a=s.point;this._hooks.record({undo:()=>this._apply(i,r,a),redo:()=>this._apply(i,a,r)},!0)}_refresh(){for(const t of this._handles.values())t.update()}_handle(t){return"string"==typeof t&&t.startsWith(vo)?this._handles.get(t):void 0}_point(t,e,n){if("number"!=typeof e||"number"!=typeof n||!Number.isFinite(e)||!Number.isFinite(n))return null;const r=this._chart.dataLayer,s=r.indexToTime(Math.round(r.timeToIndexFloat(e)))??e,o=this._study(t.studyId);if(!o||!Number.isFinite(s))return null;const l=i(o.indicatorId).inputs,a=(t,e)=>{const i=l.find(e=>e.key===t);return Math.min(i?.max??1/0,Math.max(i?.min??-1/0,e))};return{time:a(t.timeKey,s),price:a(t.priceKey,n)}}move(t,e,i,n){const r=this._handles.get(`${vo}${t}:${e}`);if(void 0===r||!r.editable||this._drag?.handle===r)return!1;const s={time:r.time,price:r.price},o=this._point(r,i,n);return!(null===o||o.time===s.time&&o.price===s.price||!this._apply(r,s,o))&&(this._hooks.record({undo:()=>this._apply(r,o,s),redo:()=>this._apply(r,s,o)},!1),!0)}_onDragStart(t){const e=this._handle(t.id);void 0!==e&&e.editable&&this._live()&&(this._drag={handle:e,from:{time:e.time,price:e.price}})}_onDrag(t){const e=this._drag;if(null===e||e.handle.id!==t.id)return;const i=this._point(e.handle,t.time,t.price);null!==i&&(e.handle.time=i.time,e.handle.price=i.price,e.handle.update())}_onDragEnd(t){const e=this._drag;if(null===e||e.handle.id!==t.id)return;this._drag=null;const{handle:i,from:n}=e,r=this._point(i,t.time,t.price),s=this._study(i.studyId);null===r||void 0===s||r.time===n.time&&r.price===n.price||!this._apply(i,n,r)?this._sync():this._hooks.record({undo:()=>this._apply(i,r,n),redo:()=>this._apply(i,n,r)},!1)}_apply(t,e,i){const n=this._study(t.studyId);if(void 0===n)return!1;const r=n.settings();if(r[t.timeKey]!==e.time||r[t.priceKey]!==e.price)return!1;const s=this._points.get(`${vo}${t.studyId}:${t.priceKey}`),o=s?.point;void 0!==s&&s.study===n&&(s.point=i);let l=!1;try{l=n.setSettings({[t.timeKey]:i.time,[t.priceKey]:i.price})}catch{l=!1}return l||void 0===s||void 0===o||s.point!==i||(s.point=o),l}_cancelDrag(){null!==this._drag&&(this._drag=null,this._sync())}}const ko=Math.PI/4,So=(t,e,i,n,r)=>{const s=Math.max(0,i-t),o=Math.max(0,e-n);return i=>e-t<=r?i:s+o<r?Math.min(Math.max(i,s),r-o):gt(i,0,r)};class To{constructor(t){Object.defineProperty(this,"_chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._chart=t}barSeconds(){const t=this._chart.dataLayer,e=t.baseIndex,i=e>0?t.indexToTime(e-1):void 0,n=e>=0?t.indexToTime(e):void 0;return void 0!==i&&void 0!==n&&n>i?n-i:60}offsetPrice(t,e,i){if(0===i)return t;const n=this._chart.priceToCoordinate,r=this._chart.coordinateToPrice;if(void 0===n||void 0===r)return t;const s=n.call(this._chart,t,e);if(null===s||!Number.isFinite(s))return t;const o=r.call(this._chart,s+i,e);return null!==o&&Number.isFinite(o)?o:t}offsetTime(t,e){if(0===e)return t;const i=this._chart.timeToCoordinate,n=this._chart.coordinateToTime;if(void 0!==i&&void 0!==n){const r=i.call(this._chart,t);if(Number.isFinite(r)){const t=n.call(this._chart,r+e);if(Number.isFinite(t))return t}}return t+e/8*this.barSeconds()}pixelDelta(t,e,i){const n=this._chart.priceToCoordinate;if(void 0===n)return 0;const r=n.call(this._chart,t,i),s=n.call(this._chart,e,i);return null!==r&&null!==s&&Number.isFinite(r)&&Number.isFinite(s)?s-r:0}toPixel(t,e){const i=this._chart.timeToCoordinate,n=this._chart.priceToCoordinate;if(void 0===i||void 0===n)return null;const r=i.call(this._chart,t.time),s=n.call(this._chart,t.price,e);return null!==s&&Number.isFinite(r)&&Number.isFinite(s)?{x:r,y:s}:null}fromPixel(t,e){const i=this._chart.coordinateToTime,n=this._chart.coordinateToPrice;if(void 0===i||void 0===n)return null;const r=i.call(this._chart,t.x),s=n.call(this._chart,t.y,e);return null!==s&&Number.isFinite(r)&&Number.isFinite(s)?{time:r,price:s}:null}lockAngle(t,e,i){const n=this.toPixel(t,i),r=this.toPixel(e,i);if(null===n||null===r)return null;const s=r.x-n.x,o=r.y-n.y;if(0===s&&0===o)return null;const l=Math.round(Math.atan2(o,s)/ko)*ko,a=Math.cos(l),c=Math.sin(l),h=s*a+o*c;return this.fromPixel({x:n.x+h*a,y:n.y+h*c},i)}coalesced(t,e,i){const n=t.samples,r={...e,...this.pressureOf(t.pressure)},s=this._chart.coordinateToTime,o=this._chart.coordinateToPrice;if(!Array.isArray(n)||n.length<2||void 0===s||void 0===o||null===t.point||void 0===t.point)return[r];const l=n[n.length-1],a=t.point.y-l.y;if(!Number.isFinite(a))return[r];const c=[];for(let t=0;t<n.length-1;t++){const e=n[t],r=s.call(this._chart,e.x),l=o.call(this._chart,e.y+a,i);null!==l&&Number.isFinite(r)&&Number.isFinite(l)&&c.push({time:r,price:l,...this.pressureOf(e.pressure)})}return c.push({...r,...this.pressureOf(l.pressure??t.pressure)}),c}pressureOf(t){return"number"==typeof t&&Number.isFinite(t)&&.5!==t?{pressure:Math.min(1,Math.max(0,t))}:{}}thinStroke(t,e){const i=[];for(const n of t){const r=this.toPixel(n,e);if(null===r)return t;i.push(r)}const n=mt(i,1.5),r=[];let s=0;for(const e of n){for(;s<i.length&&(i[s].x!==e.x||i[s].y!==e.y);)s++;if(s>=i.length)return t;r.push(t[s]),s++}return r}pane(t){const e=this._chart.panes?.()[t];return"function"==typeof e?.priceToY&&"function"==typeof e.yToPrice?e:null}plotFrame(t){const e=null===this.pane(t)?null:this._chart.plotRect?.(t)??null;return null!==e&&e.width>0&&e.height>0?e:null}gesturePlot(t,e){const i=this.pane(e),n=this._chart.timeScale;if(null===i||!Number.isFinite(t.price))return null;const r=void 0!==t.point&&null!==t.point?t.point.x-(this.plotFrame(e)?.left??Number.NaN):void 0===n?Number.NaN:n.indexToX(this._chart.dataLayer.timeToIndexFloat(t.time)),s=i.priceToY(t.price);return Number.isFinite(r)&&Number.isFinite(s)?{x:r,y:s}:null}dragOrigin(t){return void 0!==t.fromTime&&void 0!==t.fromPrice&&this._chart.dataLayer.length>=2?this.gesturePlot({time:t.fromTime,price:t.fromPrice},t.paneIndex):this.gesturePlot(t,t.paneIndex)}toViewport(t,e,i){const n=this.plotFrame(e),r=this.pane(e),s=this._chart.timeScale;if(null===n||null===r||void 0===s||0===t.length)return null;const o=[];for(const e of t){const t=s.indexToX(this._chart.dataLayer.timeToIndexFloat(e.time)),i=r.priceToY(e.price);if(!Number.isFinite(t)||!Number.isFinite(i))return null;o.push({x:t,y:i})}const l=N(o),a=Fs(i,o)??l,c=So(a.x0,a.x1,l.x0,l.x1,n.width),h=So(a.y0,a.y1,l.y0,l.y1,n.height);return this.pinPlot(i,o.map(t=>({x:c(t.x),y:h(t.y)})),n)}fromViewport(t,e,i){const n=this.plotFrame(e),r=this.pane(e),s=this._chart.timeScale;if(null===n||null===r||void 0===s||0===t.length)return null;const o=[];for(const e of Os(i,t,n.width,n.height)){const t=this._chart.dataLayer.indexToTimeFloat(s.xToIndex(e.x)),i=r.yToPrice(e.y);if(!Number.isFinite(t)||!Number.isFinite(i))return null;o.push({time:t,price:i})}return o}pinPlot(t,e,i){const n=t=>({x:t.x/i.width,y:t.y/i.height});return Os(t,e.map(n),i.width,i.height).map(n)}shiftPinned(t,e,i,n,r){const s=Os(t,e,r.width,r.height);return this.pinPlot(t,s.map(t=>({x:t.x+i,y:t.y+n})),r)}}function Io(t){return!0===t?"strong":"weak"===t||"strong"===t?t:"off"}function Oo(t,e){let i=0,n=t.length-1;for(;i<=n;){const r=i+n>>1,s=t[r].time;if(s===e)return r;s<e?i=r+1:n=r-1}return-1}function Fo(t,e){const i=t.primaryBars?.();if(void 0===i||0===i.length||!Number.isFinite(e))return null;const n=t.dataLayer.indexToTime(Math.round(t.dataLayer.timeToIndexFloat(e))),r=void 0===n?-1:Oo(i,n);if(r<0)return null;const{open:s,high:o,low:l,close:a}=i[r];return{time:i[r].time,open:s,high:o,low:l,close:a}}function Lo(t){const e=t?.trim().toLowerCase()??"";if("transparent"===e)return!0;if(/^#[0-9a-f]{4}$/.test(e))return"0"===e[4];if(/^#[0-9a-f]{8}$/.test(e))return e.endsWith("00");const i=/^(?:rgb|hsl)a?\((.*)\)$/.exec(e)?.[1].split(/[\s,/]+/).filter(Boolean);return 4===i?.length&&0===parseFloat(i[3])}function Ao(t,e,n,r,s,o){if(null===o)return null;const l=t.priceToCoordinate;if(n===s){const i=[o.open,o.high,o.low,o.close];if("strong"===r){let t=i[0],n=1/0;for(const r of i){const i=Math.abs(r-e.price);i<n&&(n=i,t=r)}return{time:o.time,price:t}}if(void 0===l)return null;const s=l.call(t,e.price,n);if(null===s||!Number.isFinite(s))return null;let a=null,c=8;for(const e of i){const i=l.call(t,e,n);if(null===i||!Number.isFinite(i))continue;const r=Math.abs(i-s);r<=c&&(c=r,a=e)}return null===a?null:{time:o.time,price:a}}const a=function(t,e){const i=(t.panes?.()??[])[e];return"function"==typeof i?.scales&&"function"==typeof i.priceToY&&"function"==typeof i.yToPrice?i:null}(t,n),c=a?.priceToY(e.price)??Number.NaN;if(null===a||!Number.isFinite(c))return null;let h=null,d="strong"===r?1/0:8;for(const e of function(t,e,n){const r=t.indicators?.()??[];if(0===r.length)return[];const s=t.primaryBars?.(),o=void 0===s?Math.round(t.dataLayer.timeToIndexFloat(n)):Oo(s,n);if(o<0)return[];const l=[];for(const n of r){if(!n.visible())continue;let r;try{r=i(n.indicatorId).plots}catch{continue}const s=n.values();for(const i of r){const r=n.series(i.key);if(void 0===r)continue;const a=r.priceScale();if(!e.scales().includes(a))continue;const c=t.seriesStyle?.(r);if(!1===c?.visible||Lo(c?.color))continue;const h=void 0===i.ohlc?[i.key]:[i.ohlc.open,i.ohlc.high,i.ohlc.low,i.ohlc.close];for(const t of h){const n=s[t]?.[o-(i.offset??0)];if(null==n||!Number.isFinite(n))continue;const r=a.priceToY(n);Number.isFinite(r)&&l.push({y:r,value:n,own:Math.abs(e.priceToY(n)-r)<1e-6})}}}return l}(t,a,o.time)){const t=Math.abs(e.y-c);t<=d&&(d=t,h=e)}if(null===h)return null;const u=h.own?h.value:a.yToPrice(h.y);return Number.isFinite(u)?{time:o.time,price:u}:null}function zo(t,e){if(!1===t.visible||!Ii(t.tool))return null;const i=Ti(t.tool);if("viewport"===t.space&&!0!==i.viewport||os(t)<Math.max(1,i.points))return null;const n=Ls(e,t);return 0!==n.length&&n.every(t=>Number.isFinite(t.x)&&Number.isFinite(t.y))?{tool:i,hit:{pts:n,drawing:t,rc:e}}:null}const No=(t,e,i,n)=>{const r=t.tool.distance(e,i,t.hit);return null!==r&&Number.isFinite(r)&&r<=n};function Co(t){return{x0:Math.min(t.x0,t.x1),y0:Math.min(t.y0,t.y1),x1:Math.max(t.x0,t.x1),y1:Math.max(t.y0,t.y1)}}function $o(t,e){const i=e*Math.SQRT2;return{nx:Math.max(1,Math.ceil((t.x1-t.x0)/i)),ny:Math.max(1,Math.ceil((t.y1-t.y0)/i))}}function Do(t,e,i,n,r){const s=zo(t,e);if(null===s)return!1;const o=Math.max(1,Math.ceil(Math.hypot(n.x-i.x,n.y-i.y)/(r/2)));for(let t=0;t<=o;t++)if(No(s,i.x+(n.x-i.x)*t/o,i.y+(n.y-i.y)*t/o,r))return!0;return!1}const jo=t=>!1!==t.visible&&!0!==t.locked&&!1!==t.policy?.selectable&&!Ts(t);class Ho{constructor(t){Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_measure",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_box",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_keys",{enumerable:!0,configurable:!0,writable:!0,value:{shift:!1,mod:!1,alt:!1}}),Object.defineProperty(this,"_hit",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_over",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_picking",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_ready",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_swallow",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_eraser",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_sweep",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_ringPane",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._host=t}measuring(){return null!==this._measure}click(t){if(null!==this._box)return this._boxClick(t);if(this._swallow&&!0===t.viaDrag)return this._swallow=!1,!0;if(this._swallow=!1,this._eraser)return this._eraserClick(t);if(this.endMeasure())return!0;const{shift:e,mod:i,alt:n}=t.keys;if(!this._host.options().measure||null!==this._host.tool()||null!==t.id||!0===t.viaDrag||!e||i||n||null===t.price||!Number.isFinite(t.price)||!Number.isFinite(t.time)||!Ii("measure"))return!1;const r=this._host.aim({time:t.time,price:t.price},t.paneIndex);return this._measure={pane:t.paneIndex,start:r,end:r},this._host.preview(),this._host.emit("draw:measure",{active:!0}),!0}follow(t){const e=this._measure;return null!==e&&null!==t&&t.paneIndex===e.pane&&(e.end=this._host.aim({time:t.time,price:t.price},e.pane),!0)}ruler(){const t=this._measure;return null===t?null:{id:"__measure",tool:"measure",points:[{...t.start},{...t.end}],paneIndex:t.pane,zIndex:0,style:{...this._host.style(),...Ti("measure").defaultStyle}}}endMeasure(){return null!==this._measure&&(this._measure=null,this._host.preview(),this._host.emit("draw:measure",{active:!1}),!0)}reset(){this.endMeasure(),this._dropBox(),this._dropSweep()}erasing(){return this._eraser}setEraser(t){return t!==this._eraser&&(this._dropSweep(),this._eraser=t,t||this._ring(null),this._host.placement(),this._host.emit("draw:eraser",{active:t}),!0)}_eraserClick(t){if(null!==this._sweep)return this._commitSweep(),this._swallow=!0!==t.viaDrag,!0;if(!0!==t.viaDrag&&null!==t.id&&t.id.startsWith("draw:")){const e=t.id.slice(5).split("#")[0],i=this._host.drawings().find(t=>t.id===e);void 0!==i&&jo(i)&&this._host.erase([e])}return!0}_eraserPointer(t){const e=null===t.paneIndex||null===t.point?null:this._host.plotRect(t.paneIndex);if(null===e||null===t.paneIndex||null===t.point)return void this._ring(null);const i={x:t.point.x-e.left,y:t.point.y-e.top},n=t.touch?12:6;if(this._ring(t.paneIndex,i,n),!t.pressed)return this._commitSweep(),void(this._over={pane:t.paneIndex,x:t.point.x,y:t.point.y});let r=this._sweep;if(null===r||r.pane!==t.paneIndex){const n=null===r&&this._over?.pane===t.paneIndex?{x:this._over.x-e.left,y:this._over.y-e.top}:i;r=this._sweep={pane:t.paneIndex,last:n,ids:r?.ids??new Set}}const s=this._host.layer(r.pane)?.context()??null;if(null!==s){const t=r.ids.size;for(const t of this._host.drawings())t.paneIndex===r.pane&&!r.ids.has(t.id)&&jo(t)&&Do(t,s,r.last,i,n)&&r.ids.add(t.id);r.ids.size!==t&&this._host.hide(r.ids)}r.last=i}_commitSweep(){const t=this._sweep;null!==t&&(this._sweep=null,t.ids.size>0&&this._host.erase([...t.ids]),this._host.hide(new Set))}_dropSweep(){null!==this._sweep&&(this._sweep=null,this._host.hide(new Set))}_ring(t,e,i){null!==this._ringPane&&this._ringPane!==t&&this._host.layer(this._ringPane)?.setRing(null),this._ringPane=t,null!==t&&void 0!==e&&this._host.layer(t,!0)?.setRing(e,i)}hover(t){this._hit=t,this._host.placement()}picking(t){this._picking=t,this._host.placement()}wantsPlacement(){return this._ready=null===this._box&&this._host.options().boxSelect&&null===this._host.tool()&&!this._eraser&&null===this._measure&&!this._picking&&this._keys.mod&&null===this._hit&&null!==this._over,this._eraser||null!==this._box||this._ready}pointer(t){if(this._swallow=!1,this._keys=t.keys,this._eraser)this._eraserPointer(t);else if(null===this._box)t.pressed?this._ready&&null===this._host.tool()&&null!==t.point&&null!==t.paneIndex&&this._startBox(t.paneIndex,t.point):(this._over=null===t.point||null===t.paneIndex?null:{pane:t.paneIndex,x:t.point.x,y:t.point.y},this._host.placement());else{if(null===t.point)return;t.pressed?this._growBox(t.point):this._finishBox()}}_startBox(t,e){const i=this._host.plotRect(t);if(null===i)return;const n=this._over?.pane===t?this._over:e,r=gt(n.x-i.left,0,i.width),s=gt(n.y-i.top,0,i.height);this._box={pane:t,x0:r,y0:s,x1:r,y1:s,base:this._keys.shift?[...this._host.selection()]:[],moved:!1},this._growBox(e)}_growBox(t){const e=this._box,i=this._host.plotRect(e.pane);null!==i&&(e.x1=gt(t.x-i.left,0,i.width),e.y1=gt(t.y-i.top,0,i.height),e.moved||(e.moved=Math.abs(e.x1-e.x0)>3||Math.abs(e.y1-e.y0)>3),e.moved&&(this._host.layer(e.pane)?.setBox(e),this._selectBox(e,!1)))}_boxClick(t){const e=this._box;if(!e.moved)return this._dropBox(),!1;if(!0!==t.viaDrag&&void 0!==t.point){const i=this._host.plotRect(e.pane);null!==i&&(e.x0=gt(t.point.x-i.left,0,i.width),e.y0=gt(t.point.y,0,i.height))}return this._finishBox(),this._swallow=!0!==t.viaDrag,!0}_finishBox(){const t=this._box;null!==t&&(t.moved&&this._selectBox(t,!0),this._dropBox())}_dropBox(){const t=this._box;null!==t&&(this._box=null,this._host.layer(t.pane)?.setBox(null),this._host.placement())}_selectBox(t,e){const i=this._host.layer(t.pane)?.context()??null;if(null===i)return;const n=Co(t),r=this._host.drawings().filter(e=>e.paneIndex===t.pane&&!0!==e.locked&&!1!==e.policy?.selectable);if(!e&&r.length*function(t,e){const{nx:i,ny:n}=$o(Co(t),e);return(i+1)*(n+1)}(n,6)>4e4)return;const s=r.filter(t=>function(t,e,i,n){const r=zo(t,e);if(null===r)return!1;const s=Co(i);if(r.hit.pts.some(t=>t.x>=s.x0&&t.x<=s.x1&&t.y>=s.y0&&t.y<=s.y1))return!0;const{nx:o,ny:l}=$o(s,n);for(let t=0;t<=l;t++){const e=s.y0+(s.y1-s.y0)*t/l;for(let t=0;t<=o;t++)if(No(r,s.x0+(s.x1-s.x0)*t/o,e,n))return!0}return!1}(t,i,n,6)).map(t=>t.id);this._host.select([...t.base,...s.filter(e=>!t.base.includes(e))])}}function Bo(t,e,i){if(JSON.stringify(e)===JSON.stringify(i))return t;if(null===e||null===i||"object"!=typeof e||"object"!=typeof i||Array.isArray(e)||Array.isArray(i))return i;const n=e,r=i,s={...t};for(const t of new Set([...Object.keys(n),...Object.keys(r)]))JSON.stringify(n[t])!==JSON.stringify(r[t])&&(t in r?s[t]=Bo(s[t],n[t],r[t]):delete s[t]);return s}let Wo=1;class Ro{constructor(t){Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_undo",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_redo",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_pendingHistory",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_untracked",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_hostEdit",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_hostPatches",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this._host=t}undo(){this._host._drag._onDragEnd();for(let t=this._undo.pop();void 0!==t;t=this._undo.pop())if(this._redo.push(t),t.external?this._external(t.external.undo(),"undo"):this._applyHistory(t.after,t.before,"undo"))return!0;return!1}redo(){this._host._drag._onDragEnd();for(let t=this._redo.pop();void 0!==t;t=this._redo.pop())if(this._undo.push(t),t.external?this._external(t.external.redo(),"redo"):this._applyHistory(t.before,t.after,"redo"))return!0;return!1}_delta(t,e){const i=Us(JSON.parse(t)),n=Us(JSON.parse(e)),r=i.drawings,s=n.drawings,o=new Map(r.map(t=>[t.id,t])),l=new Map(s.map(t=>[t.id,t])),a=r.filter(t=>l.has(t.id)).map(t=>t.id),c=s.filter(t=>o.has(t.id)).map(t=>t.id),h=c.some(t=>a.indexOf(t)!==c.indexOf(t));let d=!1;const u=[...new Set([...o.keys(),...l.keys()])].filter(t=>{const e=o.get(t),i=l.get(t);return(JSON.stringify(e)!==JSON.stringify(i)||a.indexOf(t)!==c.indexOf(t))&&(!!(!(Ts(e)||Ts(i)||Ts(this._host.get(t)))||e&&i&&JSON.stringify({...e,zIndex:0})===JSON.stringify({...i,zIndex:0}))||(d=!0,!1))}),p=new Map((i.groups??[]).map(t=>[t.id,t])),f=new Map((n.groups??[]).map(t=>[t.id,t])),y=new Set([...p.keys(),...f.keys()].filter(t=>JSON.stringify(this._place(p.get(t),t))!==JSON.stringify(this._place(f.get(t),t)))),x=!u.length&&!y.size&&!h;return{left:o,right:l,after:s,beforeOrder:a,afterOrder:c,ids:u,afterGroups:f,changedGroups:y,idle:x,held:d}}_place(t,e,i){const n=t=>Ts(this._host.get(t)),r=this._host._groups.find(t=>t.id===e),s=r?.members.filter(n)??[];if(!s.length&&!t?.members.some(n))return t;const o=t?.members.filter(t=>!n(t)||i&&s.includes(t))??[],l=[...new Set([...o,...s])];return l.length?{id:e,name:(s.length?r:t).name,members:l}:void 0}_applyHistory(t,e,i){const{left:n,right:r,after:s,beforeOrder:o,afterOrder:l,ids:a,afterGroups:c,changedGroups:h,idle:d,held:u}=this._delta(t,e);if(d&&u)return!1;const p=new Set(a),f=new Map(this._host._drawings.map(t=>[t.id,t])),y=[...h].map(t=>this._place(c.get(t),t,!0));this._host._groups=this._host._groups.filter(t=>!h.has(t.id));for(const t of y)t&&this._host._groups.push(t);this._host._drawings=this._host._drawings.filter(t=>!p.has(t.id)||r.has(t.id)).map(t=>p.has(t.id)?Bo(t,n.get(t.id),r.get(t.id)):t);for(let t=0;t<s.length;t++){const e=s[t];if(!p.has(e.id)||f.has(e.id)||n.has(e.id))continue;const i=s.slice(t+1).find(t=>void 0!==this._host.get(t.id)),r=void 0===i?this._host._drawings.length:this._host._drawings.findIndex(t=>t.id===i.id);this._host._drawings.splice(r,0,e)}const x=l.filter(t=>o.indexOf(t)!==l.indexOf(t)).map(t=>this._host.get(t)).filter(t=>void 0!==t),g=new Set(x.map(t=>t.id));let m=0;this._host._drawings=this._host._drawings.map(t=>g.has(t.id)?x[m++]:t),this._host._pruneSelection(),this._host._sync();for(const t of a){const e=this._host.get(t),i=f.get(t);void 0!==e?this._host._chart.emit(void 0===i?"draw:add":"draw:update",{drawing:e,history:!0}):void 0!==i&&this._host._chart.emit("draw:remove",{drawing:i,history:!0})}return this._host._emitChange(a,i),!0}untracked(t){this._untracked++;try{return t()}finally{0===--this._untracked&&this._takeInHostEdit()}}_takeInHostEdit(){const t=this._hostEdit;if(null===t)return;this._hostEdit=null;const e=Us(JSON.parse(t)),i=this._host._document(this._host._drawings),n=(t,e,i)=>{const n=new Map(e.map(t=>[t.id,JSON.stringify(t)])),r=new Map(i.map(t=>[t.id,t])),s=new Set([...n.keys(),...r.keys()].filter(t=>n.get(t)!==(r.has(t)?JSON.stringify(r.get(t)):void 0))),o=t.filter(t=>!s.has(t.id)||r.has(t.id)).map(t=>s.has(t.id)?r.get(t.id):t);for(const t of s)n.has(t)||o.some(e=>e.id===t)||o.push(r.get(t));return o};this._rebase(t=>{t.drawings=n(t.drawings,e.drawings,i.drawings),t.groups=n(t.groups??[],e.groups??[],i.groups??[])})}_recordStep(t,e=!1){if(e||this._host._drag._onDragEnd(),this._untracked>0)return;const i=this._host._anchorSteps;if(null!==i)return void(e||i(t));const n=this._host._historyText();this._undo.push({before:n,after:n,step:Wo++,external:t}),this._undo.length>this._host._opts.historyLimit&&this._undo.shift(),this._redo=[],this._external(!0,"update")}_external(t,e){return t&&this._host._chart.emit("drawing:change",{ids:[],kind:e}),t}_pushUndo(){this._host._drag._onDragEnd();const t=this._host._historyText();this._untracked>0?this._hostEdit??(this._hostEdit=t):(this._pendingHistory={before:t,after:t,step:Wo++},this._undo.push(this._pendingHistory),this._undo.length>this._host._opts.historyLimit&&this._undo.shift(),this._redo=[])}_begin(t){t?this._pushUndo():this._host._drag._onDragEnd()}_rebase(t){const e=e=>{const i=JSON.parse(e);for(const t of i.drawings){const{points:e,...i}=this._hostPatches.get(t.id)??{};this._host._applyPatch(t,i),e&&(t.points=e)}return t?.(i),JSON.stringify(i)},i=t=>(t.before=e(t.before),t.after=e(t.after),t===this._pendingHistory||void 0!==t.external||!this._delta(t.before,t.after).idle),n=this._host._drag._dragStart;n&&(n.undo=n.undo.filter(i),n.redo=n.redo.filter(i)),this._undo=this._undo.filter(i),this._redo=this._redo.filter(i),this._hostPatches.clear()}}class Vo{constructor(t){Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_lifted",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_dragStart",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._host=t}_grabbedAnchor(t,e){if("viewport"===t.space||0===t.points.length)return null;const i=this._host._screen.toPixel({time:e.fromTime??e.time,price:e.fromPrice??e.price},t.paneIndex);let n=0,r=1/0;return t.points.forEach((e,s)=>{const o=null===i?null:this._host._screen.toPixel(e,t.paneIndex),l=null===o||null===i?s:Math.hypot(o.x-i.x,o.y-i.y);l<r&&(r=l,n=s)}),n}_pullShape(t,e,i){const n=null===t.anchor?void 0:t.items.find(e=>e.id===t.lead),r=void 0===n||void 0!==n.viewportPoints?void 0:n.points[t.anchor];if(void 0===r)return null;const s={time:r.time+e,price:r.price+i},o=this._host._snapPoint(s,n.paneIndex,Fo(this._host._chart,s.time));return null===o?null:{dt:o.time-r.time,dp:o.price-r.price}}_onDrag(t){if(!t.id.startsWith("draw:"))return;const[e,i]=t.id.slice(5).split("#"),n=this._host.get(e);if(void 0===n||!0===n.locked||Ts(n)||!this._host._selectable(e))return;const r=void 0===i?null:Number(i);if(this._host._notePointer(t),this._host._noteKeys(t),null===this._dragStart||this._dragStart.id!==e||this._dragStart.handle!==r){null!==r||this._host._selection.includes(e)||this._host.select(e);let i=null===r?this._host._targets(this._host._selection).filter(t=>!0!==t.locked&&!Ts(t)):[n];const s=null===r&&this._host._opts.gestures.dragCopy&&!0===t.modifiers?.alt;if(s&&!this._travelled(t))return;const o=this._host._history._undo.slice(),l=this._host._history._redo.slice();this._host._history._pushUndo();const a=this._host._selection.slice(),c=i.indexOf(n);s&&(i=this._copies(i)),this._dragStart={id:e,handle:r,undo:o,redo:l,from:{time:t.fromTime??t.time,price:t.fromPrice??t.price},origin:this._host._screen.dragOrigin(t),anchor:null===r?this._grabbedAnchor(n,t):null,lead:i[c]?.id??e,...s?{copy:{ids:i.map(t=>t.id),sources:a}}:{},items:i.map(t=>({id:t.id,paneIndex:t.paneIndex,points:t.points.map(t=>({...t})),..."viewport"===t.space?{viewportPoints:(t.viewportPoints??[]).map(t=>({...t}))}:{}}))};let h=!1;for(const t of i)this._host._layerSet._onTop(t)||(this._lifted.add(t.id),h=!0);return this._moveDrag(t,n,r),h?this._host._sync():this._syncDrag(),void this._emitDragPreview()}this._moveDrag(t,n,r),this._syncDrag(),this._emitDragPreview()}_travelled(t){const e=this._host._screen.toPixel({time:t.fromTime??t.time,price:t.fromPrice??t.price},t.paneIndex),i=this._host._screen.toPixel({time:t.time,price:t.price},t.paneIndex);return null===e||null===i||Math.hypot(i.x-e.x,i.y-e.y)>3}_copies(t){const e=t.map(t=>this._host._insert(so(t)));return this._host._setSelection(e.map(t=>t.id)),e}_dropCopies(t){if(void 0===t.copy)return;const e=new Set(t.copy.ids);this._host._drawings=this._host._drawings.filter(t=>!e.has(t.id)),this._host._setSelection(t.copy.sources.filter(t=>this._host._selectable(t)))}_emitDragPreview(){const t=this._dragStart?.items.map(t=>this._host.get(t.id)).filter(t=>void 0!==t)??[];this._host._chart.emit("draw:preview",{drawings:t.map(oo)})}cancelDrag(t=!0){const e=this._dragStart;if(null===e)return!1;this._dragStart=null;for(const t of e.items){const e=this._host.get(t.id);void 0!==e&&this._restoreAnchors(e,t)}return this._dropCopies(e),this._host._history._undo=e.undo,this._host._history._redo=e.redo,this._host._history._pendingHistory=null,this._lifted.clear(),t&&!0!==this._host._chart.isDestroyed&&this._host._sync(),this._host._chart.emit("draw:preview-clear",{ids:e.items.map(t=>t.id)}),!0}_moveDrag(t,e,i){const n=this._dragStart;if(null===i){const e=this._pullShape(n,t.time-n.from.time,t.price-n.from.price),i=e?.dt??t.time-n.from.time,r=e?.dp??t.price-n.from.price,s=this._host._screen.pixelDelta(n.from.price,null===e?t.price:n.from.price+r,t.paneIndex),o=this._host._screen.gesturePlot(t,t.paneIndex),l=null===o||null===n.origin?null:{x:o.x-n.origin.x,y:o.y-n.origin.y};for(const e of n.items){const n=this._host.get(e.id);if(void 0===n)continue;if(void 0!==e.viewportPoints){const t=this._host._screen.plotFrame(e.paneIndex);null!==t&&null!==l&&(n.viewportPoints=this._host._screen.shiftPinned(n,e.viewportPoints,l.x,l.y,t));continue}const o=e.paneIndex===t.paneIndex;n.points=e.points.map(t=>({...t,time:t.time+i,price:o?t.price+r:this._host._screen.offsetPrice(t.price,e.paneIndex,s)}))}}else if("viewport"===e.space){const r=n.items[0].viewportPoints??[],s=this._host._screen.gesturePlot(t,e.paneIndex),o=this._host._screen.plotFrame(e.paneIndex);if(i>=0&&i<r.length&&null!==s&&null!==o){const{width:t,height:n}=o,l=Os(e,r,t,n);l[i]={x:gt(s.x,0,t),y:gt(s.y,0,n)},l[i]=Os(e,l.map(e=>({x:e.x/t,y:e.y/n})),t,n)[i],e.viewportPoints=this._host._screen.pinPlot(e,l,o)}}else if(i>=0&&i<e.points.length){const r=n.items[0],s={time:t.time,price:t.price},o=(this._host._shift&&2===r.points.length&&Ii(e.tool)&&!0===Ti(e.tool).angleLock?this._host._screen.lockAngle(r.points[1-i],s,e.paneIndex):null)??this._host._snapPoint(s,e.paneIndex,Fo(this._host._chart,s.time))??s,l=r.points.map((t,e)=>e===i?{...t,...o}:{...t}),a=Ii(e.tool)?Ti(e.tool):void 0;e.points=void 0===a?.constrain?l:a.constrain(l,i)}}_restoreAnchors(t,e){t.points=e.points.map(t=>({...t})),void 0!==e.viewportPoints&&(t.viewportPoints=e.viewportPoints.map(t=>({...t})))}_onDragEnd(){if(null===this._dragStart)return;const t=this._dragStart.items.map(t=>this._host.get(t.id)).filter(t=>void 0!==t),e=void 0!==this._dragStart.copy;this._dragStart=null,this._host._chart.emit("draw:preview-clear",{ids:t.map(t=>t.id)}),this._lifted.size>0&&(this._lifted.clear(),this._host._sync());for(const i of t)this._host._chart.emit(e?"draw:add":"draw:update",{drawing:i});t.length>0&&this._host._emitChange(t.map(t=>t.id),e?"add":"update")}_syncDrag(){const t=this._dragStart;if(null===t)return;const e=new Set(t.items.map(t=>t.paneIndex)),i=this._host._shownFilter();for(const t of e){const e=this._host._layerSet._layers.get(t);void 0!==e&&e.top.setDrawings(this._host._drawings.filter(e=>e.paneIndex===t&&this._host._layerSet._onTop(e)&&i(e)))}this._host._chart.setDrawingState(this._host.toJSON())}}class Eo extends Ns{constructor(){super("top"),Object.defineProperty(this,"_overlayHost",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_rc",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_box",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_ring",{enumerable:!0,configurable:!0,writable:!0,value:null})}attached(t){super.attached(t),this._overlayHost=t}detached(){super.detached(),this._overlayHost=null}draw(t,e){super.draw(t,e),this._rc=e,null!==this._box&&this._drawBox(t,e,this._box),null!==this._ring&&this._drawRing(t,e,this._ring.at,this._ring.radius)}hitTest(t,e,i){return this._rc=i,super.hitTest(t,e,i)}context(){const t=this._rc;return null!==t&&t.readoutPriceScale?{...t,priceScale:t.readoutPriceScale}:t}setBox(t){const e=this._box;(null===t?null!==e:null===e||e.x0!==t.x0||e.y0!==t.y0||e.x1!==t.x1||e.y1!==t.y1)&&(this._box=null===t?null:{x0:t.x0,y0:t.y0,x1:t.x1,y1:t.y1},this._overlayHost?.requestUpdate())}box(){return null===this._box?null:{...this._box}}setRing(t,e=0){const i=this._ring;(null===t?null!==i:null===i||i.at.x!==t.x||i.at.y!==t.y||i.radius!==e)&&(this._ring=null===t?null:{at:{x:t.x,y:t.y},radius:e},this._overlayHost?.requestUpdate())}_drawRing(t,e,i,n){const r=e.dpr;t.save(),t.setLineDash([]),t.globalAlpha=.9,t.lineWidth=Math.max(1,Math.round(r)),t.strokeStyle=e.theme.axisText,t.beginPath(),t.arc(i.x*r,i.y*r,n*r,0,2*Math.PI),t.stroke(),t.restore()}_drawBox(t,e,i){const n=e.dpr,r=Math.round(Math.min(i.x0,i.x1)*n)+.5,s=Math.round(Math.min(i.y0,i.y1)*n)+.5,o=Math.round(Math.abs(i.x1-i.x0)*n),l=Math.round(Math.abs(i.y1-i.y0)*n),a=e.theme.lineColor;t.save(),t.beginPath(),t.rect(0,0,Math.round(e.plotWidth*n),Math.round(e.plotHeight*n)),t.clip(),t.globalAlpha=.12,t.fillStyle=a,t.fillRect(r,s,o,l),t.globalAlpha=.9,t.strokeStyle=a,t.lineWidth=Math.max(1,Math.round(n)),t.setLineDash([]),t.strokeRect(r,s,o,l),t.restore()}}function Jo(t,e){return void 0!==t.stackAbove&&e.includes(t.stackAbove)?"entry:"+t.stackAbove:t.zIndex<0?"below":"above"}class Ko{constructor(t){Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_layers",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_hidden",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_slotKey",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_offInterval",{enumerable:!0,configurable:!0,writable:!0,value:""}),this._host=t}_allLayers(){return[...this._layers.values()].flatMap(t=>[t.bottom,t.top,...t.series.values()])}_layerFor(t){let e=this._layers.get(t);return void 0===e&&(e={bottom:new Ns("bottom"),top:new Eo,series:new Map},this._host._chart.addPrimitive(e.bottom,t),this._host._chart.addPrimitive(e.top,t),e.top.setBelow(e.bottom),e.bottom.setSelected(this._host._selection),e.top.setSelected(this._host._selection),this._layers.set(t,e)),e}_onTop(t,e=this._host._entries(t.paneIndex)){return this._host._drag._lifted.has(t.id)||"above"===Jo(t,e)}_slotSignature(){const t=new Map;let e="";for(const i of this._host._drawings){if(void 0===i.stackAbove)continue;let n=t.get(i.paneIndex);void 0===n&&t.set(i.paneIndex,n=this._host._entries(i.paneIndex)),e+=i.id+"\0"+Jo(i,n)+"\0"}return e}_syncLayers(){this._slotKey=this._slotSignature();const t=new Map,e=new Map,i=this._host._shownFilter(),n=[];for(const r of this._host._drawings){if(!i(r)){n.push(r.id);continue}if(this._hidden.has(r.id))continue;const s=this._host._linkedPreviews.get(r.id)??r;let o=t.get(s.paneIndex);void 0===o&&(o={below:[],above:[],series:new Map},t.set(s.paneIndex,o));let l=e.get(s.paneIndex);void 0===l&&e.set(s.paneIndex,l=this._host._entries(s.paneIndex));const a=this._host._drag._lifted.has(s.id)?"above":Jo(s,l);if("above"===a)o.above.push(s);else if("below"===a)o.below.push(s);else{const t=o.series.get(a.slice(6));t?t.push(s):o.series.set(a.slice(6),[s])}}for(const[i,n]of t){const t=this._layerFor(i);t.bottom.setDrawings(n.below),t.top.setDrawings(n.above),this._syncSeriesLayers(i,t,n.series,e.get(i)??[])}for(const[e,i]of this._layers){t.has(e)||(i.bottom.setDrawings([]),i.top.setDrawings([]),this._syncSeriesLayers(e,i,new Map,[]));for(const t of[i.bottom,i.top,...i.series.values()])t.setSelected(this._host._selection)}this._offInterval=n.join("\0")}_syncSeriesLayers(t,e,i,n){for(const[t,n]of e.series)i.has(t)||(e.series.delete(t),this._host._chart.removePrimitive(n));for(const[n,r]of i){let i=e.series.get(n);void 0===i&&(i=new Ns("series"),this._host._chart.addPrimitive(i,t),this._host._chart.setPrimitiveStackAbove?.(i,n),i.setPointerType(this._host._pointerKind),i.setHovered(this._host._hovered),e.series.set(n,i)),i.setDrawings(r)}e.top.setBelow([...n].reverse().flatMap(t=>e.series.get(t)??[]).concat(e.bottom))}_syncPreview(){for(const t of this._layers.values())t.top.setPreview(null);const t=this._host._gestures.ruler();if(null!==t&&this._layerFor(t.paneIndex).top.setPreview(t),null===this._host._tool||0===this._host._pending.length)return;const e=this._host._lastCursor,i=null===e||e.paneIndex!==this._host._pendingPane?this._host._pending:[...this._host._pending,this._host._aimPoint({time:e.time,price:e.price},e.paneIndex)];this._layerFor(this._host._pendingPane).top.setPreview({id:"__preview",tool:this._host._tool,points:i,style:this._host._opts.defaultStyle,paneIndex:this._host._pendingPane,zIndex:0})}_syncSnapRing(){const t=this._host._lastCursor;let e=null,i=t?.paneIndex??this._host._pendingPane;null===t||null===this._host._tool||this._host._isFreehand()||null!==this._host._lockedPoint({time:t.time,price:t.price},t.paneIndex)||(e=this._host._snapPoint({time:t.time,price:t.price},t.paneIndex),i=t.paneIndex);for(const[t,n]of this._layers)n.top.setSnapPoint(t===i?e:null);null===e||this._layers.has(i)||this._layerFor(i).top.setSnapPoint(e)}}let Uo=1;const Yo=(t,e)=>t.length===e.length&&t.every((t,i)=>t===e[i]),qo=(t,e)=>!0===t.modifiers?.[e]||!0===t[`${e}Key`],Go=t=>({shift:qo(t,"shift"),mod:qo(t,"ctrl")||qo(t,"meta"),alt:!0===t.modifiers?.alt}),Xo=(t,e={})=>({...t,...Object.fromEntries(Object.entries(e).filter(([e,i])=>e in t&&"boolean"==typeof i))}),Zo={snapModifier:!0,measure:!0,boxSelect:!0,dragCopy:!0},Qo="openalgo-charts/drawing-link";class tl{constructor(t,e={}){Object.defineProperty(this,"_chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_clipboard",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_screen",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_gestures",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_layerSet",{enumerable:!0,configurable:!0,writable:!0,value:new Ko(this)}),Object.defineProperty(this,"_drawings",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_groups",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_nextGroup",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"_linkedPreviews",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_tool",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_toolSpace",{enumerable:!0,configurable:!0,writable:!0,value:"data"}),Object.defineProperty(this,"_pending",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_pendingPane",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_selection",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_hovered",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_shift",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_strong",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_placing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_interval",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_pointerKind",{enumerable:!0,configurable:!0,writable:!0,value:"mouse"}),Object.defineProperty(this,"_history",{enumerable:!0,configurable:!0,writable:!0,value:new Ro(this)}),Object.defineProperty(this,"_drag",{enumerable:!0,configurable:!0,writable:!0,value:new Vo(this)}),Object.defineProperty(this,"_off",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_anchors",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_anchorSteps",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_lastCursor",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_lastBar",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._chart=t,this._screen=new To(t),this._gestures=new Ho({tool:()=>this._tool,options:()=>this._opts.gestures,aim:(t,e)=>this._aimPoint(t,e),style:()=>this._opts.defaultStyle,preview:()=>this._layerSet._syncPreview(),emit:(t,e)=>this._chart.emit(t,e),drawings:()=>this._drawings.filter(this._shownFilter()),selection:()=>this._selection,select:t=>this.select(t),layer:(t,e)=>!0===e?this._layerSet._layerFor(t).top:this._layerSet._layers.get(t)?.top,hide:t=>{this._layerSet._hidden=t,this._layerSet._syncLayers()},erase:t=>{this._removeIds(t,!0)},plotRect:t=>this._chart.plotRect?.(t)??null,placement:()=>{this._destroyed||this._placementWanted()===this._placing||this._setPlacementMode(!this._placing)}}),this._opts={magnet:Io(e.magnet),gestures:Xo(Zo,e.gestures),stayInDrawingMode:e.stayInDrawingMode??!1,historyLimit:e.historyLimit??50,pasteOffsetBars:e.pasteOffsetBars??2,pasteOffsetPixels:e.pasteOffsetPixels??16,defaultStyle:e.defaultStyle??{}},this._clipboard=new _o({...void 0===e.clipboard?{}:{port:e.clipboard},...void 0===e.clipboardFallbackToMemory?{}:{fallbackToMemory:e.clipboardFallbackToMemory}}),this._off.push(t.on("click",t=>this._onClick(t))),this._off.push(t.on("crosshair:move",t=>this._onCrosshair(t))),this._off.push(t.on("hover",t=>this._onHover(t))),this._off.push(t.on("drag",t=>this._drag._onDrag(t))),this._off.push(t.on("drag:end",()=>this._drag._onDragEnd())),this._off.push(t.on("drag:cancel",()=>{this.cancelDrag()})),this._off.push(t.on("data:context",t=>{this.cancelDrag(),this._gestures.reset(),this._followInterval(t)})),this._off.push(t.on("dblclick",()=>{this.finish()})),this._off.push(t.on("drawings:restore",t=>this.fromJSON(t))),this._off.push(t.on("pick:start",()=>this._gestures.picking(!0))),this._off.push(t.on("pick:end",()=>this._gestures.picking(!1)));const i=t.drawingState();if(null!=i){const t=Us(i);this._drawings=t.drawings,this._groups=t.groups??[]}this._off.push(t.on("paneRemoved",t=>{const{paneIndex:e}=t;this._remapPanes(t=>t===e?null:t>e?t-1:t)})),this._off.push(t.on("paneMoved",t=>{const{from:e,to:i}=t;this._remapPanes(t=>t===e?i:t===i?e:t)}));for(const e of["objects:change","indicatorRemoved"])this._off.push(t.on(e,()=>{this._layerSet._slotKey!==this._layerSet._slotSignature()&&this._layerSet._syncLayers()}));this._interval=Bs(t.getDataContext?.()),this._sync(),!1!==e.inputAnchors&&"function"==typeof t.indicators&&(this._anchors=new Po(t,{record:(t,e)=>this._history._recordStep(t,e),placing:()=>null!==this._tool}))}setTool(t,e={}){if(null!==t&&!Ii(t))throw new Error(`openalgo-charts: unknown drawing tool "${t}"`);const i=null!==t&&"viewport"===e.space?"viewport":"data";if("viewport"===i&&!Oi(t))throw new Error(`openalgo-charts: drawing tool "${t}" cannot be anchored to the viewport`);this.cancelDrag(),this._gestures.reset(),this._gestures.setEraser(!1),this._tool=t,this._toolSpace=i,this._pending=[],this._setPlacementMode(this._placementWanted()),this._layerSet._syncPreview(),this._layerSet._syncSnapRing(),this._emitTool()}activeToolSpace(){return this._toolSpace}_emitTool(){this._chart.emit("draw:tool","viewport"===this._toolSpace?{tool:this._tool,space:"viewport"}:{tool:this._tool})}_setPlacementMode(t){this._placing=t,this._chart.setPlacementMode?.(t)}_placementWanted(){const t=this._gestures.wantsPlacement();return null!==this._tool||t}activeTool(){return this._tool}setOptions(t){const{clipboard:e,clipboardFallbackToMemory:i,inputAnchors:n,magnet:r,gestures:s,...o}=t;this._opts={...this._opts,...o,defaultStyle:t.defaultStyle??this._opts.defaultStyle,magnet:void 0===r?this._opts.magnet:Io(r),gestures:Xo(this._opts.gestures,s)},void 0!==e&&this._clipboard.setPort(e),void 0!==i&&this._clipboard.setFallbackToMemory(i),this._layerSet._syncSnapRing()}magnetMode(){return this._opts.magnet}measuring(){return this._gestures.measuring()}setEraser(t){this._destroyed||t===this._gestures.erasing()||(t&&(this.cancelDrag(),this._gestures.reset(),null!==this._tool&&(this._tool=null,this._toolSpace="data",this._pending=[],this._layerSet._syncPreview(),this._layerSet._syncSnapRing(),this._emitTool())),this._gestures.setEraser(t))}erasing(){return this._gestures.erasing()}hovered(){return this._hovered}clipboard(){return this._clipboard}groups(){return this._groups.map(t=>({...t,members:[...t.members]}))}createGroup(t,e,i={}){const n=[...new Set(e)].filter(t=>void 0!==this.get(t)&&(i.force||!Ts(this.get(t))));if(this._destroyed||!t.trim()||!n.length)return null;let r;do{r="group-"+this._nextGroup++}while(this._groups.some(t=>t.id===r)||[...this._history._undo,...this._history._redo].some(t=>(t.before+t.after).includes(`"${r}"`)));const s={id:r,name:t.trim(),members:n},o=new Set(n);return this._regroup(i.force,t=>t.map(t=>({...t,members:t.members.filter(t=>!o.has(t))})).concat({...s,members:[...n]})),this._sync(),this._emitChange(n,"update"),{...s,members:[...n]}}renameGroup(t,e,i={}){const n=this._group(t,i);return!(!n||!e.trim())&&(this._regroup(i.force,i=>i.map(i=>i.id===t?{...i,name:e.trim()}:i)),this._sync(),this._emitChange(n.members,"update"),!0)}removeGroup(t,e=!1,i={}){const n=this._group(t,i);return!!n&&(this._regroup(i.force,e=>e.filter(e=>e.id!==t)),e&&0!==this._removeIds(n.members,!1,i.force).length||(this._sync(),this._emitChange(n.members,"update")),!0)}_regroup(t,e){this._history._begin(!t),this._groups=e(this._groups),t&&this._history._rebase(t=>{t.groups=e(t.groups??[])})}_group(t,e){const i=this._groups.find(e=>e.id===t);return this._destroyed||!e.force&&i?.members.some(t=>Ts(this.get(t)))?void 0:i}reorder(t,e){const i=this.get(t);if(!i||this._destroyed||-1!==e&&1!==e)return!1;const n=this._entries(i.paneIndex),r=Jo(i,n),s=this._drawings.filter(t=>t.paneIndex===i.paneIndex&&Jo(t,n)===r).sort((t,e)=>t.zIndex-e.zIndex),o=s.indexOf(i),l=o+e;if(l<0||l>=s.length)return!1;this._history._pushUndo(),[s[o],s[l]]=[s[l],s[o]];const a=new Set(s);let c=0;this._drawings=this._drawings.map(t=>a.has(t)?s[c++]:t),s.forEach((t,e)=>{t.zIndex="below"===r?e-s.length:e}),this._sync();for(const t of s)this._chart.emit("draw:update",{drawing:t});return this._emitChange(s.map(t=>t.id),"reorder"),!0}placeInStack(t,e,i){const n=this.get(t);if(void 0===n||this._destroyed||"above"!==i&&"below"!==i||null===e||"object"!=typeof e)return!1;const r=this._entries(n.paneIndex);let s,o;if("drawing"in e){const t=this.get(e.drawing);if(void 0===t||t===n||t.paneIndex!==n.paneIndex)return!1;s=Jo(t,r),o=this._slotMembers(n.paneIndex,s,r).filter(t=>t!==n).indexOf(t)+("above"===i?1:0)}else{const t=r.indexOf(e.entry);if(t<0)return!1;s="above"===i?"entry:"+r[t]:0===t?"below":"entry:"+r[t-1],o="above"===i?0:this._slotMembers(n.paneIndex,s,r).filter(t=>t!==n).length}const l=this._slotMembers(n.paneIndex,s,r);if(Jo(n,r)===s&&l.indexOf(n)===o)return!1;this._history._pushUndo();const a=l.filter(t=>t!==n);a.splice(o,0,n),s.startsWith("entry:")?n.stackAbove=s.slice(6):delete n.stackAbove,a.forEach((t,e)=>{t.zIndex="below"===s?e-a.length:e}),this._sync();for(const t of a)this._chart.emit("draw:update",{drawing:t});return this._emitChange(a.map(t=>t.id),"reorder"),!0}_entries(t){return this._chart.seriesStack?.(t)??[]}_slotMembers(t,e,i){return As(this._drawings.filter(n=>n.paneIndex===t&&Jo(n,i)===e))}_remapPanes(t){this._drag.cancelDrag(!1),this._pending=[],this._lastCursor=null,this._gestures.reset(),this._linkedPreviews.clear();const e=e=>{const i=Us(JSON.parse(e));return i.drawings=i.drawings.filter(e=>{const i=t(e.paneIndex);return null!==i&&(e.paneIndex=i,!0)}),i.groups=Ys(i.groups,i.drawings),JSON.stringify(i)};for(const t of new Set([...this._history._undo,...this._history._redo]))t.before=e(t.before),t.after=e(t.after);const i=[];this._drawings=this._drawings.filter(e=>{const n=t(e.paneIndex);return null===n?(i.push(e),!1):(e.paneIndex=n,!0)});const n=[...this._layerSet._layers.entries()];this._layerSet._layers.clear();for(const[e,i]of n){const n=t(e);null!==n&&this._layerSet._layers.set(n,i)}this._pruneSelection(),this._sync();for(const t of i)this._chart.emit("draw:remove",{drawing:t});this._emitChange(this._drawings.map(t=>t.id),"update")}drawings(){return this._drawings}get(t){return this._drawings.find(e=>e.id===t)}interval(){return this._interval}shownOnInterval(t){const e=this.get(t);return void 0!==e&&this._shownFilter()(e)}hiddenOnInterval(){const t=this._shownFilter();return this._drawings.filter(e=>!t(e)).map(t=>t.id)}_shownFilter(){return Rs(this._interval)}_followInterval(t){if(this._destroyed||(t=>"object"==typeof t&&null!==t&&!0===t[Ws])(t))return;const e=this._chart.getDataContext;if(this._interval=Bs(void 0===e?t:e.call(this._chart)),this.hiddenOnInterval().join("\0")===this._layerSet._offInterval)return;const i=this._shownFilter();this._layerSet._syncLayers();const n=this._selection.filter(t=>{const e=this.get(t);return void 0!==e&&i(e)});Yo(n,this._selection)||this._setSelection(n),null===this._hovered||this.shownOnInterval(this._hovered)||this._setHovered(null)}get isDestroyed(){return this._destroyed}applyLinkedDrawing(t,e){if(this._destroyed||!0===this._chart.isDestroyed)return;this._drag._dragStart?.items.some(e=>e.id===t)&&this.cancelDrag();const i=this._drawings.findIndex(e=>e.id===t);if(this._linkedPreviews.delete(t),null===e){if(i<0)return;this._drawings.splice(i,1),this._pruneSelection()}else{const n=oo({...e,id:t}),r=JSON.stringify(this._drawings[i]?.policy);i<0?this._drawings.push(n):this._drawings[i]=n,JSON.stringify(n.policy)!==r&&this._history._rebase(e=>{for(const i of e.drawings)i.id===t&&(i.policy=n.policy)})}this._sync(),this._chart.emit("drawing:change",{ids:[t],kind:null===e?"remove":i<0?"add":"update",linked:!0})}setLinkedPreview(t,e){this._destroyed||!0===this._chart.isDestroyed||(null===e?this._linkedPreviews.delete(t):void 0!==this.get(t)&&this._linkedPreviews.set(t,oo({...e,id:t})),this._sync())}reorderLinkedDrawings(t){if(this._destroyed||!0===this._chart.isDestroyed)return;const e=[...new Set(t)].map(t=>this.get(t)).filter(t=>void 0!==t),i=new Set(e.map(t=>t.id));let n=0;const r=this._drawings.map(t=>i.has(t.id)?e[n++]:t);r.every((t,e)=>t===this._drawings[e])||(this._drawings=r,this._sync(),this._chart.emit("drawing:change",{ids:e.map(t=>t.id),kind:"reorder",linked:!0}))}alertInfo(t){const e=this.get(t);if(!e||!Ii(e.tool))return{available:!1,reason:"Drawing is unavailable",levels:[]};const i=Ti(e.tool);if("viewport"===e.space)return{available:!1,reason:"A drawing pinned to the screen has no price",paneIndex:e.paneIndex,levels:[]};if(!i.alertValue)return{available:!1,reason:"This tool has no numeric alert value",paneIndex:e.paneIndex,levels:[]};const n=i.alertLevels?.(e)??[{id:"line",title:"Line"}];return this._chart.timeToCoordinate&&this._chart.priceToCoordinate&&this._chart.coordinateToPrice?{available:n.length>0,reason:n.length?void 0:"No active drawing levels",paneIndex:e.paneIndex,levels:n.map(t=>({...t}))}:{available:!1,reason:"Drawing coordinate maps are unavailable",levels:[],paneIndex:e.paneIndex}}valueAt(t,e,i){const n=this.get(t);if(!n||"viewport"===n.space||!Ii(n.tool)||!Number.isFinite(e))return;const r=Ti(n.tool),s=this._chart.timeToCoordinate,o=this._chart.coordinateToPrice;if(!r.alertValue||!s||!o)return;const l=n.paneIndex;let a=t=>o.call(this._chart,t,l),c=n.points.map(t=>this._screen.toPixel(t,l));if(c.includes(null)){const t=this._chart.panes?.()[l];if("function"!=typeof t?.priceToY||"function"!=typeof t.yToPrice)return;c=n.points.map(e=>({x:s.call(this._chart,e.time),y:t.priceToY(e.price)})),a=e=>t.yToPrice(e)}const h=s.call(this._chart,e);if(!Number.isFinite(h))return;const d=r.alertValue({drawing:n,pts:c,time:e,x:h,fromY:a},i);return d&&Number.isFinite(d.price)&&(void 0===d.upperPrice||Number.isFinite(d.upperPrice))?{...d,paneIndex:n.paneIndex}:void 0}add(t){if("viewport"===t.space&&(!Oi(t.tool)||null===ls(t.viewportPoints)))throw new Error(`openalgo-charts: a "${t.tool}" drawing cannot be anchored to the viewport with those viewportPoints`);this._history._begin(!Object.values(t.policy??{}).includes(!1));const e=this._insert(t);return this._sync(),this._chart.emit("draw:add",{drawing:e}),this._emitChange([e.id],"add"),e}_insert(t){const e=Ti(t.tool);let i=t.id??this._mintId();for(;void 0===t.id&&void 0!==this.get(i);)i=this._mintId();const{id:n,...r}=t,s={...r,id:i,style:{...this._opts.defaultStyle,...e.defaultStyle,...t.style},zIndex:Number.isFinite(t.zIndex)?t.zIndex:0,createdAt:t.createdAt??Date.now()};t.policy&&(s.policy={...t.policy}),"viewport"===t.space?(s.points=[],s.viewportPoints=ls(t.viewportPoints)??[]):(delete s.space,delete s.viewportPoints);const o=js(t.intervals);return null===o?delete s.intervals:s.intervals=o,void 0!==s.props?.[Qo]&&(s.props={...s.props},delete s.props[Qo]),void 0===t.text&&void 0===e.defaultText||(s.text={value:"",...e.defaultText,...t.text}),this._drawings.push(s),s}_mintId(){return"d"+Uo++}update(t,e,i={}){const n=this.get(t);return!(void 0===n||Ts(n)&&!0!==i.force)&&(this.updateMany([{id:t,patch:e}],i),void 0===e.space||"viewport"===n.space==("viewport"===e.space))}updateMany(t,e={}){const i=t.map(t=>({d:this.get(t.id),patch:t.patch})).filter(t=>void 0!==t.d&&(!0===e.force||!Ts(t.d))).map(({d:t,patch:e})=>({d:t,patch:this._spacePatch(t,e),asked:Object.keys(e).length})).filter(({patch:t,asked:e})=>0===e||Object.keys(t).length>0);if(0===i.length)return;this._history._begin(!e.force&&i.some(({patch:t})=>!t.policy));for(const{d:t,patch:e}of i)this._applyPatch(t,e);let n=!1;for(const{d:t,patch:{points:r,...s}}of i){if(!e.force&&!s.policy)continue;const i=this._history._hostPatches.get(t.id)??{};this._applyPatch(i,s),void 0!==s.space&&(i.space=s.space),void 0!==s.stackAbove&&(i.stackAbove=s.stackAbove),void 0!==s.intervals&&(i.intervals=void 0===t.intervals?null:{...t.intervals}),r&&(i.points=t.points),this._history._hostPatches.set(t.id,i),n||(n=!Ts(t)||!!s.policy||void 0!==s.zIndex||void 0!==s.stackAbove)}n&&this._history._rebase(),this._sync();for(const{d:t}of i)this._chart.emit("draw:update",{drawing:t});this._emitChange(i.map(t=>t.d.id),"update")}_spacePatch(t,e){const{space:i,points:n,viewportPoints:r,...s}=e,o="viewport"===t.space?"viewport":"data";let l=void 0===i?o:"viewport"===i?"viewport":"data";if("viewport"!==l||"data"!==o||Oi(t.tool)||(l="data"),"viewport"===l){const e=void 0===r?null:ls(r);if(l===o)return null===e?s:{...s,viewportPoints:e};const i=e??this._screen.toViewport(n??t.points,t.paneIndex,t);return null===i?s:{...s,space:"viewport",points:[],viewportPoints:i}}if(l===o)return void 0===n?s:{...s,points:n};const a=n??this._screen.fromViewport(ls(r)??t.viewportPoints??[],t.paneIndex,t);return null===a?s:{...s,space:"data",points:a}}_applyPatch(t,e){if(void 0!==e.points){const i=e.points.map(t=>({...t})),n=Ii(t.tool)?Ti(t.tool):void 0;t.points=void 0===n?.constrain||0===i.length?i:n.constrain(i,function(t,e){if(t.length!==e.length)return null;let i=null;for(let n=0;n<e.length;n++)if(t[n].time!==e[n].time||t[n].price!==e[n].price){if(null!==i)return null;i=n}return i}(t.points,i))}if(void 0!==e.space&&("viewport"===e.space?t.space="viewport":(delete t.space,delete t.viewportPoints)),void 0!==e.viewportPoints&&(t.viewportPoints=e.viewportPoints.map(t=>({x:t.x,y:t.y}))),void 0!==e.style&&(t.style={...t.style,...e.style}),void 0!==e.text&&(t.text={...t.text,...e.text}),void 0!==e.props&&(t.props={...t.props,...e.props}),void 0!==e.locked&&(t.locked=e.locked),void 0!==e.visible&&(t.visible=e.visible),void 0!==e.intervals){const i=null===e.intervals?null:js(e.intervals);null===i?delete t.intervals:t.intervals=i}void 0!==e.zIndex&&Number.isFinite(e.zIndex)&&(t.zIndex=e.zIndex),void 0!==e.policy&&(t.policy={...t.policy,...e.policy}),"string"==typeof e.stackAbove&&""!==e.stackAbove?t.stackAbove=e.stackAbove:null===e.stackAbove&&delete t.stackAbove}remove(t,e={}){return this._removeIds([t],!0,e.force).length>0}removeMany(t,e={}){this._removeIds(t,!0,e.force)}_removeIds(t,e,i=!1){const n=new Set(t),r=this._drawings.filter(t=>n.has(t.id)&&(i||!Ts(t)));if(0===r.length)return[];e&&this._history._begin(!i);const s=new Set(r.map(t=>t.id));this._drawings=this._drawings.filter(t=>!s.has(t.id)),i&&this._history._rebase(t=>{t.drawings=t.drawings.filter(t=>!s.has(t.id))}),this._selection=this._selection.filter(t=>!s.has(t)),this._sync();for(const t of r)this._chart.emit("draw:remove",{drawing:t});return this._emitChange(r.map(t=>t.id),"remove"),r}clear(t={}){0!==this._drawings.length&&(this._removeIds(this._drawings.map(t=>t.id),!0,t.force),this._setSelection([]))}select(t,e=!1){const i=null===t?[]:"string"==typeof t?[t]:t,n=[];for(const t of i)this._selectable(t)&&!n.includes(t)&&n.push(t);if(!e)return void this._setSelection(n);const r=this._selection.slice();for(const t of n){const e=r.indexOf(t);e>=0?r.splice(e,1):r.push(t)}this._setSelection(r)}_selectable(t){const e=this.get(t);return void 0!==e&&!1!==e.policy?.selectable}selected(){return 0===this._selection.length?null:this._selection[0]}selection(){return this._selection}_setSelection(t){const e=!Yo(t,this._selection);this._selection=t;for(const e of this._layerSet._allLayers())e.setSelected(t);e&&(this._chart.emit("draw:select",{id:this.selected()}),this._chart.emit("drawing:select",{ids:t.slice()}))}_emitChange(t,e){const i=this._history._pendingHistory;null!==i&&(i.after=this._historyText(),this._history._pendingHistory=null),this._history._takeInHostEdit();const n={ids:t.slice(),kind:e};null!==i&&this._history._undo.includes(i)&&(n.step=i.step),this._chart.emit("drawing:change",n)}setZIndex(t,e){const i=this.get(t);void 0!==i&&Number.isFinite(e)&&i.zIndex!==e&&(this._history._pushUndo(),i.zIndex=e,this._sync(),this._chart.emit("draw:update",{drawing:i}),this._emitChange([t],"reorder"))}bringToFront(t){const e=this.get(t);if(void 0===e)return;const i=this._band(e),n=0===i.length?e.zIndex:Math.max(...i.map(t=>t.zIndex));this._reorder(e,n,"end")}sendToBack(t){const e=this.get(t);if(void 0===e)return;const i=this._band(e),n=0===i.length?e.zIndex:Math.min(...i.map(t=>t.zIndex));this._reorder(e,n,"start")}sendBehindSeries(t){const e=this.get(t);void 0===e||void 0===e.stackAbove&&"below"===Jo(e,this._entries(e.paneIndex))||this._crossSeries(e,-1)}bringAboveSeries(t){const e=this.get(t);void 0===e||void 0===e.stackAbove&&"above"===Jo(e,this._entries(e.paneIndex))||this._crossSeries(e,0)}_crossSeries(t,e){this._history._pushUndo(),t.zIndex=e,delete t.stackAbove,this._sync(),this._chart.emit("draw:update",{drawing:t}),this._emitChange([t.id],"reorder")}_band(t){const e=this._entries(t.paneIndex),i=Jo(t,e);return this._drawings.filter(n=>n!==t&&n.paneIndex===t.paneIndex&&Jo(n,e)===i)}_reorder(t,e,i){const n=this._drawings.indexOf(t);n===("end"===i?this._drawings.length-1:0)&&t.zIndex===e||(this._history._pushUndo(),t.zIndex=e,this._drawings.splice(n,1),"end"===i?this._drawings.push(t):this._drawings.unshift(t),this._sync(),this._chart.emit("draw:update",{drawing:t}),this._emitChange([t.id],"reorder"))}nudge(t,e,i){if(0===e&&0===i)return;const n=this._targets(t).filter(t=>!0!==t.locked&&!Ts(t));if(0!==n.length){this._history._pushUndo();for(const t of n){if("viewport"===t.space){const n=this._screen.plotFrame(t.paneIndex);null!==n&&(t.viewportPoints=this._screen.shiftPinned(t,t.viewportPoints??[],e,i,n));continue}t.points=t.points.map(n=>({time:this._screen.offsetTime(n.time,e),price:this._screen.offsetPrice(n.price,t.paneIndex,i)}))}this._sync();for(const t of n)this._chart.emit("draw:update",{drawing:t});this._emitChange(n.map(t=>t.id),"update")}}duplicate(t){const e=this._targets(t);if(0===e.length)return[];this._history._pushUndo();const i=e.map(t=>this._insert({...so(t),...this._offsetAnchors(t,t.paneIndex)}));this._sync();for(const t of i)this._chart.emit("draw:add",{drawing:t});return this._emitChange(i.map(t=>t.id),"add"),this.select(i.map(t=>t.id)),i}async copy(t){const e=this._targets(t);if(0===e.length)return!1;const i=await this._clipboard.write(this._portable(e));return i&&this._chart.emit("draw:copy",{drawings:e.map(oo)}),i}async cut(t){const e=this._targets(t).filter(t=>!Ts(t));if(0===e.length)return!1;if(!await this._clipboard.write(this._portable(e)))return!1;const i=this._removeIds(e.map(t=>t.id),!0);return 0!==i.length&&(this._chart.emit("draw:cut",{drawings:i}),!0)}async paste(){const t=await this._clipboard.read();if(null===t||0===t.length)return[];for(const e of t)if(!Ii(e.tool))return[];const e=this._shownFilter(),i=t.map(t=>{const i=this._clampPane(t.paneIndex);return{...t,paneIndex:i,...this._offsetAnchors(t,i),...e(t)?{}:{intervals:void 0}}});this._history._pushUndo();const n=i.map(t=>this._insert(t));this._sync();for(const t of n)this._chart.emit("draw:add",{drawing:t});return this._emitChange(n.map(t=>t.id),"add"),this._chart.emit("draw:paste",{drawings:n}),this.select(n.map(t=>t.id)),n}_targets(t){const e=null==t?this._selection:"string"==typeof t?[t]:t,i=[];for(const t of e){const e=this.get(t);void 0===e||i.includes(e)||i.push(e)}return i}_pricePane(){return this._chart.primaryPaneIndex?.()??0}_portable(t){const e=this._pricePane();return t.map(t=>({...t,paneIndex:t.paneIndex===e?0:t.paneIndex<e?t.paneIndex+1:t.paneIndex}))}_clampPane(t){const e=this._chart.panes,i=void 0===e?t+1:e.call(this._chart).length,n=0===i?0:Math.min(t,i-1),r=this._pricePane();return 0===n?r:n<=r?n-1:n}_offsetAnchors(t,e){if("viewport"!==t.space)return{points:this._offsetPoints(t.points,e)};const i=t.viewportPoints??[],n=this._screen.plotFrame(e),r=this._opts.pasteOffsetPixels;return{points:[],viewportPoints:null===n?i.map(t=>({x:t.x,y:t.y})):this._screen.shiftPinned({...t,id:""},i,r,r,n)}}_offsetPoints(t,e){const i=this._screen.barSeconds()*this._opts.pasteOffsetBars,n=this._opts.pasteOffsetPixels;return t.map(t=>({time:t.time+i,price:this._screen.offsetPrice(t.price,e,n)}))}moveInputAnchor(t,e,i){return this._anchors?.move(t,e,i.time,i.price)??!1}delegateInputAnchorSteps(t){return this._anchorSteps=t,()=>{this._anchorSteps===t&&(this._anchorSteps=null)}}undo(){return this._history.undo()}redo(){return this._history.redo()}_pruneSelection(){const t=this._selection.filter(t=>this._selectable(t));Yo(t,this._selection)||this._setSelection(t)}canUndo(){return this._history._undo.length>0}canRedo(){return this._history._redo.length>0}historySteps(){return{undo:this._history._undo.filter(t=>t!==this._history._pendingHistory).map(t=>t.step),redo:this._history._redo.map(t=>t.step)}}untracked(t){return this._history.untracked(t)}toJSON(){return this._document(this._drawings.filter(t=>!1!==t.policy?.persistent))}_document(t){const e=Ys(this._groups,t);return{version:Es(t),drawings:t.map(oo),...e.length?{groups:e}:{}}}_historyText(){return JSON.stringify(this._document(this._drawings))}fromJSON(t){this.cancelDrag(),this._gestures.reset(),this._linkedPreviews.clear();const e=Us(t);this._drawings=e.drawings,this._groups=e.groups??[],this._history._undo=[],this._history._redo=[],this._history._hostPatches.clear(),this._history._pendingHistory=null,this._setSelection([]),this._sync(),this._chart.emit("draw:restore",{}),this._emitChange(this._drawings.map(t=>t.id),"update")}destroy(){if(!this._destroyed){this.cancelDrag(),this._gestures.reset(),this._gestures.setEraser(!1),this._destroyed=!0,this._linkedPreviews.clear(),this._chart.emit("draw:destroy",{controller:this}),this._anchors?.destroy(),this._setPlacementMode(!1);for(const t of this._off)t();this._off.length=0;for(const t of this._layerSet._layers.values()){t.top.setBelow(null),this._chart.removePrimitive(t.top),this._chart.removePrimitive(t.bottom);for(const e of t.series.values())this._chart.removePrimitive(e)}this._layerSet._layers.clear()}}_onCrosshair(t){const e=t.time??null,i=e??(t.point?this._chart.coordinateToTime?.(t.point.x)??null:null),n=t.price??null,r=t.paneIndex??null;this._lastCursor=null!==i&&Number.isFinite(i)&&null!==n&&null!==r?{time:i,price:n,paneIndex:r}:null;const s=t.bar??null;if(this._lastBar=null===s||null===e?null:{time:e,...s},this._noteKeys(t),this._notePointer(t),this._gestures.pointer({paneIndex:r,point:t.point??null,pressed:!0===t.pressed,keys:Go(t),touch:"touch"===this._pointerKind}),null===i&&null===n&&this._setHovered(null),null!==this._tool&&!0===t.pressed&&this._isFreehand()&&null!==i&&null!==n&&null!==r&&Number.isFinite(i)&&Number.isFinite(n))for(const e of this._screen.coalesced(t,{time:i,price:n},r))this._inkPoint(e,r);else this._layerSet._syncSnapRing(),(null!==this._tool&&this._pending.length>0||this._gestures.follow(this._lastCursor))&&this._layerSet._syncPreview()}_onHover(t){const e=t.id??null;this._gestures.hover(e);const i=null!==e&&e.startsWith("draw:")?e.slice(5).split("#")[0]:null;this._setHovered(null!==i&&this._selectable(i)?i:null)}_setHovered(t){if(t!==this._hovered){this._hovered=t;for(const e of this._layerSet._allLayers())e.setHovered(t);this._chart.emit("drawing:hover",{id:t})}}_notePointer(t){const e=(t=>"touch"===t.pointerType||"pen"===t.pointerType?t.pointerType:"mouse")(t);if(e!==this._pointerKind){this._pointerKind=e;for(const t of this._layerSet._allLayers())t.setPointerType(e)}}_expand(t,e){if(void 0===t.expand)return e;const i=this._chart.getVisibleLogicalRange(),n=null===i?60:Math.max(1,i.to-i.from),r=this._pendingPane,s=void 0!==this._chart.timeToCoordinate&&void 0!==this._chart.priceToCoordinate&&void 0!==this._chart.coordinateToTime&&void 0!==this._chart.coordinateToPrice,o=t.expand(e,{barSeconds:this._screen.barSeconds(),visibleBars:n,...s?{toPixel:t=>this._screen.toPixel(t,r),fromPixel:t=>this._screen.fromPixel(t,r)}:{}});return void 0===t.constrain?o:t.constrain(o,null)}_isFreehand(){return null!==this._tool&&!0===Ti(this._tool).freehand}_inkPoint(t,e){if(0===this._pending.length)this._pendingPane=e;else{if(e!==this._pendingPane)return;{const e=this._pending[this._pending.length-1];if(e.time===t.time&&e.price===t.price)return}}this._pending.push(t),this._layerSet._syncPreview()}_commit(t){const e=Ti(this._tool),i=this._pendingPane,n=void 0===e.defaultText?{}:{text:{...e.defaultText}},r="viewport"===this._toolSpace?this._screen.toViewport(t,i,{id:"",tool:e.id,points:[],style:{},paneIndex:i,zIndex:0,...n}):null,s=this.add(null===r?{tool:e.id,points:t,style:{},paneIndex:i}:{tool:e.id,points:[],space:"viewport",viewportPoints:r,style:{},paneIndex:i});this._pending=[],this._opts.stayInDrawingMode||(this._tool=null,this._toolSpace="data",this._setPlacementMode(this._placementWanted())),this._layerSet._syncPreview(),this._layerSet._syncSnapRing(),this.select(s.id),this._emitTool()}_finishFreehand(){const t=this._pending;this._pending=[],t.length<2?this._layerSet._syncPreview():this._commit(this._screen.thinStroke(t,this._pendingPane))}finish(){if(null===this._tool||0===this._pending.length)return!1;const t=Ti(this._tool);if(0!==t.points||!0===t.freehand)return!1;const e=this._pending;return e.length<2?(this._pending=[],this._layerSet._syncPreview(),!1):(this._commit(e),!0)}cancel(){if(this.cancelDrag()||this._gestures.endMeasure()||this._gestures.setEraser(!1))return!0;if(null===this._tool)return!1;const t=this._pending.length>0;return this._pending=[],t&&this._opts.stayInDrawingMode?(this._layerSet._syncPreview(),!0):(this._tool=null,this._toolSpace="data",this._setPlacementMode(this._placementWanted()),this._layerSet._syncPreview(),this._layerSet._syncSnapRing(),this._chart.emit("draw:tool",{tool:null}),!0)}popAnchor(){if(null===this._tool||0===this._pending.length)return!1;const t=Ti(this._tool);return 0===t.points&&!0!==t.freehand&&(this._pending.pop(),this._layerSet._syncPreview(),!0)}_onClick(t){if(this._notePointer(t),this._gestures.click({...t,keys:Go(t)}))return;if(null!==this._tool){if(this._isFreehand())return void(!0===t.viaDrag&&this._finishFreehand());if(!0===t.viaDrag&&0===this._pending.length)return;if(null===t.price||!Number.isFinite(t.price)||!Number.isFinite(t.time))return;return this._noteKeys(t),void this._placePoint(this._aimPoint({time:t.time,price:t.price},t.paneIndex),t.paneIndex)}const e=["shift","ctrl","meta"].some(e=>qo(t,e));null!==t.id&&t.id.startsWith("draw:")?this.select(t.id.slice(5).split("#")[0],e):null!==t.id||e||this.select(null)}_placePoint(t,e){0===this._pending.length&&(this._pendingPane=e),this._pending.push(t);const i=Ti(this._tool);i.points>0&&this._pending.length>=i.points?this._commit(this._expand(i,this._pending)):this._layerSet._syncPreview()}_aimPoint(t,e){const i=this._lockedPoint(t,e);return null!==i?i:this._snapPoint(t,e)??t}_lockedPoint(t,e){return this._shift&&null!==this._tool&&1===this._pending.length?!0!==Ti(this._tool).angleLock||e!==this._pendingPane?null:this._screen.lockAngle(this._pending[0],t,e):null}_snapPoint(t,e,i=this._lastBar){const n=this._strong?"strong":this._opts.magnet;return"off"===n||"viewport"===this._toolSpace?null:Ao(this._chart,t,e,n,this._pricePane(),i)}_noteKeys(t){this._shift=qo(t,"shift"),this._strong=this._opts.gestures.snapModifier&&(qo(t,"ctrl")||qo(t,"meta"))}cancelDrag(){return this._drag.cancelDrag()}screenPoints(t){const e=this.get(t);if(void 0===e)return null;if("viewport"!==e.space){const t=[];for(const i of e.points){const n=this._screen.toPixel(i,e.paneIndex);if(null===n)return null;t.push(n)}return t}const i=this._screen.plotFrame(e.paneIndex);return null===i?null:Os(e,e.viewportPoints??[],i.width,i.height).map(t=>({x:i.left+t.x,y:i.top+t.y}))}_sync(){this._groups=Ys(this._groups,this._drawings),this._layerSet._syncLayers(),this._pruneSelection(),null===this._hovered||this._selectable(this._hovered)&&this.shownOnInterval(this._hovered)||this._setHovered(null),this._chart.setDrawingState(this.toJSON())}}function el(t){return"string"==typeof t?.symbol&&t.symbol.trim()&&"string"==typeof t.exchange&&t.exchange.trim()?JSON.stringify([t.symbol,t.exchange]):null}function il(t){try{return("function"==typeof t?t():t)??void 0}catch{return}}let nl,rl=1,sl=1;const ol=(t,e)=>t.paneIndex===e&&"viewport"!==t.space;function ll(t,e){const i=t.props?.[Qo];return 1===i?.version&&i.context===e&&"string"==typeof i.id&&i.id.length>0?i.id:void 0}class al{constructor(t={}){Object.defineProperty(this,"_members",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_enabled",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_broadcasting",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._enabled=t.enabled??!1}options(){return{enabled:this._enabled}}add(t,e,i){if(this._destroyed||!0===t.isDestroyed||e.isDestroyed)return;const n=this._members.get(t);if(n?.controller===e)return void(void 0!==i&&(n.resolveContext="function"==typeof i?i:null,this.setContext(t,il(i))));void 0!==n&&this.remove(t);const r={chart:t,controller:e,context:el(il(i??(()=>t.getDataContext?.()))),resolveContext:"function"==typeof i?i:null,drawings:new Map,off:[]};this._members.set(t,r);for(const e of["draw:add","draw:update","draw:remove"])r.off.push(t.on(e,t=>{const i=t;void 0!==i?.drawing&&this._change(r,i.drawing,"draw:remove"===e,"draw:add"===e&&!0!==i.history)}));r.off.push(t.on("draw:preview",t=>{const e=t?.drawings;void 0!==e&&this._preview(r,e)}),t.on("draw:preview-clear",()=>this._clearMemberPreviews(r)),t.on("drawing:change",t=>{!0!==t?.linked&&this._syncOrder(r)}),t.on("data:context",e=>this.setContext(t,null===r.resolveContext?e:il(r.resolveContext))),t.on("symbol",()=>this.setContext(t,il(r.resolveContext??void 0))),t.on("draw:restore",()=>{this._detachDrawings(r,!1),this._reconnect(r)}),t.on("draw:destroy",i=>{i?.controller===e&&this.remove(t)}),t.on("destroy",()=>this.remove(t))),this._reconnect(r)}setOptions(t){if(void 0!==t.enabled&&!this._destroyed){if(!t.enabled)for(const t of this._members.values())this._clearMemberPreviews(t);if(this._enabled=t.enabled,this._enabled)for(const t of this._members.values())this._reconnect(t)}}setContext(t,e){const i=this._members.get(t);if(void 0===i)return;const n=el(e);for(const t of i.drawings.values())this._clearPreview(t);n!==i.context&&(i.controller.cancelDrag(),this._detachDrawings(i,!0),i.context=n,this._reconnect(i))}share(t,e){const i=this._members.get(t);if(void 0===i||!this._eligible(i)||this._broadcasting)return 0;let n=0;for(const t of new Set(e??i.controller.drawings().map(t=>t.id))){const e=i.controller.get(t);if(void 0===e||!ol(e,this._pricePane(i)))continue;const r=i.drawings.get(t)??this._create(i,e);this._commit(r,i,e,!0),n++}return this._syncOrder(i),n}has(t){return this._members.has(t)}remove(t){const e=this._members.get(t);if(void 0!==e){this._detachDrawings(e,!1);for(const t of e.off)t();this._members.delete(t)}}destroy(){this._destroyed=!0;for(const t of[...this._members.keys()])this.remove(t)}_pricePane(t){return t.chart.primaryPaneIndex?.()??0}_onPricePane(t,e){return null===e?null:{...e,paneIndex:this._pricePane(t)}}_eligible(t){return!this._destroyed&&this._enabled&&null!==t.context&&this._members.get(t.chart)===t&&!0!==t.chart.isDestroyed&&!t.controller.isDestroyed}_create(t,e){const i=t.context,n=ll(e,i)??`${function(){if(void 0===nl){const t=globalThis.crypto;if("function"==typeof t?.randomUUID)nl=t.randomUUID();else{if("function"!=typeof t?.getRandomValues)throw new Error("openalgo-charts: drawing links require Web Crypto");nl=Array.from(t.getRandomValues(new Uint8Array(16)),t=>t.toString(16).padStart(2,"0")).join("")}}return nl}()}:${sl++}`;for(const r of this._members.values())for(const s of r.drawings.values())if(s.context===i&&s.lineage===n)return s.bindings.set(t,{id:e.id,local:!0}),t.drawings.set(e.id,s),s;const r={id:e.id,context:i,lineage:n,drawing:oo({...e,paneIndex:0}),bindings:new Map([[t,{id:e.id,local:!0}]]),previewFrom:null};return t.drawings.set(e.id,r),r}_reconnect(t){if(this._broadcasting||!this._eligible(t))return;const e=t.context,i=new Set;this._broadcasting=!0;try{for(const n of[...t.controller.drawings()]){if(!ol(n,this._pricePane(t))||t.drawings.has(n.id))continue;const r=ll(n,e);if(void 0!==r)for(const s of this._members.values()){if(s===t||!this._eligible(s)||s.context!==e)continue;let o=[...s.drawings.values()].find(t=>t.context===e&&t.lineage===r);if(void 0===o){const t=s.controller.drawings().find(t=>ol(t,this._pricePane(s))&&ll(t,e)===r);void 0!==t&&(o=this._create(s,t))}if(void 0!==o){o.bindings.set(t,{id:n.id,local:!1}),t.drawings.set(n.id,o),t.controller.applyLinkedDrawing(n.id,this._onPricePane(t,o.drawing)),i.add(s);break}}}for(const e of i)this._orderFrom(e,t)}finally{this._broadcasting=!1}}_change(t,e,i,n){if(this._broadcasting||!this._eligible(t)||e.paneIndex!==this._pricePane(t))return;if(!i&&"viewport"===e.space)return void this._unlink(t,e);let r=t.drawings.get(e.id);void 0!==r||n||i||(r=this._rejoin(t,e));const s=void 0===r&&n;void 0===r&&n&&(r=this._create(t,e)),void 0!==r&&this._commit(r,t,i?null:e,s)}_unlink(t,e){const i=t.drawings.get(e.id);if(void 0!==i&&(this._clearPreview(i),i.bindings.delete(t),t.drawings.delete(e.id)),void 0===e.props?.[Qo])return;const n={...e.props};delete n[Qo],this._broadcasting=!0;try{t.controller.applyLinkedDrawing(e.id,{...e,props:n})}finally{this._broadcasting=!1}}_rejoin(t,e){const i=ll(e,t.context);if(void 0!==i&&ol(e,this._pricePane(t)))for(const n of this._members.values())for(const r of n.drawings.values())if(r.context===t.context&&r.lineage===i)return null===r.drawing?void this._unlink(t,e):(r.bindings.set(t,{id:e.id,local:!0}),t.drawings.set(e.id,r),r)}_commit(t,e,i,n){this._broadcasting=!0;try{this._clearPreview(t);const r=null===i?null:{...i,props:{...i.props,[Qo]:{version:1,id:t.lineage,context:t.context}}};null!==r&&ll(i,t.context)!==t.lineage&&e.controller.applyLinkedDrawing(i.id,r),t.drawing=null===r?null:oo({...r,id:t.id,paneIndex:0});for(const r of[...this._members.values()]){if(r===e||!this._eligible(r)||r.context!==t.context)continue;let s=t.bindings.get(r);if(void 0===s){if(null===i||!n)continue;const e=r.controller.drawings().find(e=>ol(e,this._pricePane(r))&&!r.drawings.has(e.id)&&ll(e,t.context)===t.lineage);let o=e?.id??t.id;if(void 0===e)for(;void 0!==r.controller.get(o)||r.drawings.has(o);)o="linked"+rl++;s={id:o,local:!1},t.bindings.set(r,s),r.drawings.set(o,t)}r.controller.applyLinkedDrawing(s.id,this._onPricePane(r,t.drawing))}}finally{this._broadcasting=!1}}_preview(t,e){if(!this._broadcasting&&this._eligible(t))for(const i of e){const e=t.drawings.get(i.id);if(void 0!==e){e.previewFrom=t;for(const[n,r]of e.bindings)n!==t&&this._eligible(n)&&n.context===e.context&&n.controller.setLinkedPreview(r.id,this._onPricePane(n,i))}}}_syncOrder(t){if(!this._broadcasting&&this._eligible(t)){this._broadcasting=!0;try{for(const e of this._members.values())e!==t&&this._eligible(e)&&e.context===t.context&&this._orderFrom(t,e)}finally{this._broadcasting=!1}}}_orderFrom(t,e){const i=t.controller.drawings().map(i=>t.drawings.get(i.id)?.bindings.get(e)?.id).filter(t=>void 0!==t);e.controller.reorderLinkedDrawings(i)}_clearPreview(t){if(null!==t.previewFrom){for(const[e,i]of t.bindings)e.controller.setLinkedPreview(i.id,null);t.previewFrom=null}}_clearMemberPreviews(t){for(const e of t.drawings.values())e.previewFrom===t&&this._clearPreview(e)}_detachDrawings(t,e){for(const i of t.drawings.values()){const n=i.bindings.get(t);this._clearPreview(i),i.bindings.delete(t),e&&!1===n?.local&&t.controller.applyLinkedDrawing(n.id,null)}t.drawings.clear()}}function cl(t={}){return new al(t)}const hl={version:Es([]),drawings:[]},dl=t=>0===t.drawings.length&&!t.groups?.length;function ul(t){const e="string"==typeof t?.symbol?t.symbol.trim():"";if(""===e)return null;const i="string"==typeof t?.exchange?t.exchange.trim():"";return""===i?encodeURIComponent(e):`${encodeURIComponent(i)}:${encodeURIComponent(e)}`}function pl(){const t=new Map;return{get:e=>{const i=t.get(e);return void 0===i?null:JSON.parse(i)},set:(e,i)=>(t.set(e,JSON.stringify(i)),!0),remove:e=>{t.delete(e)}}}function fl(t,e){return{get:i=>{const n=t.getItem(e+i);return null===n?null:JSON.parse(n)},set:(i,n)=>{t.setItem(e+i,JSON.stringify(n))},remove:i=>{t.removeItem(e+i)}}}function yl(t,e,i){if(null===e)return!1;const n=Us(i);if(dl(n))return!1;let r;try{r=t.get(e)}catch{return!1}if(null!=r)return!1;try{return!1!==t.set(e,n)}catch{return!1}}class xl{constructor(t,e,i={}){if(Object.defineProperty(this,"_draw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_store",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_keyOf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_onError",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_key",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_text",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_held",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_swapping",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_off",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this._draw=e,this._store=i.store??pl(),this._keyOf=i.key??ul,this._onError=i.onError,!0===t.isDestroyed||e.isDestroyed)return void(this._destroyed=!0);this._off.push(t.on("data:context",t=>this._follow(t)),t.on("drawing:change",()=>this._changed()),t.on("draw:destroy",t=>{t?.controller===e&&this.destroy()}),t.on("destroy",()=>this.destroy()));const n=this._keyFor(t.getDataContext?.());null!==n&&this._start(n,i.prefer??"stored")}get isDestroyed(){return this._destroyed}key(){return this._key}setInstrument(t){this._destroyed||null===t||this._follow(t)}document(t){const e=this._keyFor(t);if(null===e)return null;const i=e!==this._key||this._destroyed?this._read(e):this._draw.toJSON();return null===i||dl(i)?null:i}setDocument(t,e){const i=this._keyFor(t);this._destroyed||null===i||(i!==this._key?this._write(i,JSON.stringify(Us(e))):this._draw.fromJSON(e))}save(){if(this._destroyed)return 0===this._held.size;for(const[t,e]of[...this._held])t!==this._key&&this._write(t,e);return null!==this._key&&this._saveCurrent(!0),0===this._held.size}destroy(){if(!this._destroyed){this._destroyed=!0;for(const t of this._off.splice(0))t()}}_keyFor(t){if(null==t)return null;try{return this._keyOf(t)}catch{return null}}_live(){return JSON.stringify(this._draw.toJSON())}_start(t,e){this._key=t;const i=this._read(t),n=this._live();if(null!==i&&"stored"===e)return JSON.stringify(i)!==n&&this._load(i),void(this._text=this._live());null===i&&dl(JSON.parse(n))?this._text=n:(this._text=null,this._saveCurrent(!1))}_follow(t){if(this._destroyed||this._draw.isDestroyed)return;const e=this._keyFor(t);null!==e&&e!==this._key&&(null!==this._key?this._swap(e):this._start(e,"stored"))}_swap(t){const e=this._draw;e.cancelDrag();const i=e.activeTool();null!==i&&e.setTool(i,{space:e.activeToolSpace()}),this._saveCurrent(!1),this._key=t;const n=this._read(t);this._load(n??hl);const r=this._live();this._text=null===n?JSON.stringify(hl):JSON.stringify(n),r!==this._text&&this._saveCurrent(!1)}_load(t){this._swapping=!0;try{this._draw.fromJSON(t)}finally{this._swapping=!1}}_changed(){this._swapping||this._destroyed||null===this._key||this._draw.isDestroyed||this._saveCurrent(!1)}_saveCurrent(t){const e=this._key;if(null===e)return;const i=this._live();(t||i!==this._text||this._held.has(e))&&(this._text=i,this._write(e,i))}_write(t,e){const i=JSON.parse(e),n=dl(i)?"remove":"write";try{if("remove"===n)this._store.remove(t);else if(!1===this._store.set(t,i))throw new Error("The drawing store refused the write");this._held.delete(t)}catch(i){this._held.set(t,e),this._report(n,t,i)}}_read(t){const e=this._held.get(t);if(void 0!==e)return JSON.parse(e);let i;try{i=this._store.get(t)}catch(e){return this._report("read",t,e),null}if(null==i)return null;const n=Us(i);return dl(n)?null:n}_report(t,e,i){try{this._onError?.({operation:t,key:e,error:i})}catch{}}}function gl(t,e,i={}){return new xl(t,e,i)}const ml="0 0 24 24",_l=2,bl={viewBox:ml,fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};function vl(t,e,i=1){return`M${t-i} ${e}a${i} ${i} 0 0 0 ${2*i} 0a${i} ${i} 0 0 0 ${-2*i} 0z`}const wl=(t,e,i)=>vl(t,e,i);function Ml(t,e,i,n,r){return`M2 ${t} 7 ${e} 12 ${i} 17 ${n} 22 ${r}M2 ${t} 12 ${i} 22 ${r}`}const Pl="M5 3h2v3H5zM17 3h2v3h-2z",kl=vl(6,18)+vl(18,6),Sl=vl(4,18),Tl=vl(8,16)+vl(16,8),Il="M20 4l-2 8-6-6z",Ol=vl(8,12),Fl=vl(12,12),Ll="M20 8l-6 2 4 4z",Al=vl(4,19,2)+vl(9,7,2)+vl(14,16,2),zl="M10 11l3-4 3 4z",Nl="M10 13l3 4 3-4z",Cl=vl(12,21),$l=vl(19,14),Dl=vl(19,20),jl=vl(12,20),Hl="M5 2v8h14V2",Bl={cursor:"M6 3v15l4-4h7zM11 15l3 6",magnet:"M6 7v5a6 6 0 0 0 12 0V7"+Pl,"trend-line":"M6 18 18 6"+kl,ray:"M4 18 22 6"+Sl,"extended-line":"M2 22 22 2"+Tl,arrow:"M4 20 15 9"+Il,"horizontal-line":"M2 12h20","horizontal-ray":"M8 12h14"+Ol,"vertical-line":"M12 2v20","cross-line":"M2 12h20M12 2v20"+Fl,"trend-angle":"M4 20 18 8M4 20h12M8 20a8 8 0 0 0 2-5","info-line":"M6 18 18 6M3 3h8v5H3z"+kl,path:"M3 20 7 7l5 9 5-5"+Ll,polyline:"M4 19 9 7l5 9 6-11"+Al,"parallel-channel":"M2 16 14 4M8 22 20 10","disjoint-channel":"M2 16 14 6M8 22 22 14","flat-bottom":"M2 14 14 4M2 20h20","fib-channel":"M2 14 14 4M4 18 16 8M6 22 18 12","regression-trend":"M2 18 20 6M4 20 22 8M2 14 20 2","flat-top-bottom":"M3 6h18M3 20 21 12M3 6v14","regression-channel":"M3 18 19 6M5 21 21 9M3 12 17 2M10 16h4",pitchfork:Hl+"M12 2v19"+Cl,"schiff-pitchfork":Hl+"M12 2v12h7"+$l,"modified-schiff-pitchfork":Hl+"M12 2v13M5 10l14 10"+Dl,"inside-pitchfork":Hl+"M12 2v8M5 10l7 10 7-10"+jl,"fib-extension-two-point":"M3 4h18M3 10h18M3 16h18M3 21h18M6 4v12","fib-speed-resistance-fan":"M3 3h18v18M3 21 21 3M21 12 3 21 12 3","icon-stamp":"M12 3l3 6 6 3-6 3-3 6-3-6-6-3 6-3z",rectangle:"M3 5h18v14H3z","rotated-rectangle":"M2 14 10 4l12 6-8 10z",ellipse:"M12 5c5 0 9 3 9 7s-4 7-9 7-9-3-9-7 4-7 9-7z",circle:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18z",triangle:"M12 4 21 20H3z",arc:"M3 19a12 12 0 0 1 18 0",curve:"M3 18c4-12 14-12 18 0","double-curve":"M3 18c3-9 7-9 9 0 2 9 6 9 9 0",brush:"M3 19c4 0 4-8 8-8s4 8 9 4",highlighter:"M4 16 14 6l4 4-10 10H4z","fib-retracement":"M3 4h18M3 9h18M3 14h18M3 19h18","fib-extension":"M3 5h18M3 12h18M3 19h18M8 5v14","fib-fan":"M3 20 21 4M3 20 21 10M3 20 21 16M3 20h18","fib-time-zone":"M4 3v18M8 3v18M14 3v18M22 3v18","fib-circles":wl(12,12,3)+wl(12,12,6)+wl(12,12,9),"fib-spiral":"M8 10A2 2 0 0 0 10 8 3 3 0 0 0 7 5 5 5 0 0 0 2 10 8 8 0 0 0 10 18 13 13 0 0 0 22 10","fib-wedge":"M20 18H5l9-12M10 18A5 5 0 0 0 8 14M15 18A10 10 0 0 0 11 10M20 18A15 15 0 0 0 14 6","fib-speed-fan":"M3 20V4M3 20h18M3 20 21 4M3 20 13 4","gann-fan":"M3 20 21 2M3 20 21 9M3 20 21 15M3 20h18","gann-box":"M3 3h18v18H3zM3 3l18 18M3 21 21 3","trend-fib-time":"M3 20 8 8 12 15M12 3v18M16 3v18M22 3v18","fib-speed-resistance-arcs":"M10 14 22 2M2 6a8 8 0 0 1 16 16M6 10a4 4 0 0 1 8 8","gann-square":"M3 3h18v18H3zM9 3v18M15 3v18M3 9h18M3 15h18M3 21 21 3","dedekind-tessellation":"M3 3h18v18H3zM3 3A18 18 0 0 1 21 21M21 3A18 18 0 0 0 3 21M3 21a6 6 0 0 1 12 0M9 21a6 6 0 0 1 12 0M12 3 12 21",sonic:"M3 12a9 9 0 0 1 18 0M6 12a6 6 0 0 1 12 0M9 12a3 3 0 0 1 6 0M3 12h18",supersonic:"M22 3 2 12l20 9"+wl(7,12,2)+wl(12,12,4),"golden-sonic":"M3 12a9 9 0 0 1 18 0M7 12a5 5 0 0 1 10 0M10 12a2 2 0 0 1 4 0M3 16h18M12 16v5","golden-supersonic":"M22 5 2 12l20 7"+wl(7,12,2)+wl(11,12,3)+wl(17,12,5),"xabcd-pattern":"M3 19 7 4 12 16 16 8 21 20M3 19 12 16 21 20M7 4 16 8","abcd-pattern":"M3 18 9 4 15 15 21 3M3 18 15 15M9 4 21 3","elliott-impulse":"M2 21 6 12 9 17 13 5 17 11 22 2","elliott-correction":"M3 4 9 18 15 8 21 21M3 4h4M17 21h4","head-shoulders":"M2 20 5 10 8 17 12 3 16 17 19 10 22 20M3 17h18",gartley:Ml(21,3,14,7,17),bat:Ml(21,3,11,5,19),butterfly:Ml(16,3,13,6,21),crab:Ml(14,2,9,4,21),shark:Ml(22,5,13,2,22),cypher:Ml(21,7,14,2,17),measure:"M4 16h16M4 12v8M20 12v8M8 4h8M12 4v6","anchored-vwap":"M4 4v16M4 15 8 12 12 14 16 8 20 6M2 4h4","fixed-range-volume-profile":"M4 3v18M4 5h8v3H4M4 10h16v3H4M4 15h12v3H4","price-range":"M12 4v16M7 9l5-5 5 5M7 15l5 5 5-5","date-range":"M4 12h16M9 7l-5 5 5 5M15 7l5 5-5 5","date-price-range":"M5 6h14v12H5zM5 12h14M12 6v12","cyclic-lines":"M4 4v16M10 4v16M16 4v16M22 4v16","time-cycles":"M4 12a4 4 0 0 1 8 0 4 4 0 0 0 8 0M4 4v16","sine-line":"M2 12c3-9 6-9 9 0 3 9 6 9 9 0","long-position":"M2 14h4M6 3h15v17H6zM6 14h15"+zl,"short-position":"M2 10h4M6 4h15v17H6zM6 10h15"+Nl,forecast:"M3 18 9 10l4 4 8-10M13 4h8v8","risk-reward-long":"M2 14h20M8 14V3M5 3h6M17 14v6M14 20h6","risk-reward-short":"M2 10h20M8 10v11M5 21h6M17 10V4M14 4h6",text:"M4 5h16M12 5v14M8 19h8",note:"M4 20 9 15M9 5h13v10H9zM4 20v-4",callout:"M3 3h18v9H11l-6 8 1-8H3z",balloon:"M3 4h18v12H9l-4 4v-4H3z",comment:"M3 5h18v10H3zM6 15v4l4-4",signpost:"M12 21V9M5 3h14v6H5z","price-label":"M3 12 8 7h13v10H8z","price-note":"M2 12h5M7 6h15v12H7zM10 12h9",table:"M3 5h18v14H3zM3 10h18M9 10v9M15 10v9","flag-mark":"M6 21V3M6 3h12l-3 4 3 4H6","arrow-up":"M12 3v18M6 9l6-6 6 6","arrow-down":"M12 3v18M6 15l6 6 6-6","arrow-left":"M3 12h18M9 6l-6 6 6 6","arrow-right":"M3 12h18M15 6l6 6-6 6"},Wl={magnet:Pl,"trend-line":kl,ray:Sl,"extended-line":Tl,arrow:Il,"horizontal-ray":Ol,"cross-line":Fl,"info-line":kl,path:Ll,polyline:Al,"long-position":zl,"short-position":Nl,pitchfork:Cl,"schiff-pitchfork":$l,"modified-schiff-pitchfork":Dl,"inside-pitchfork":jl},Rl=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Vl(t){return Rl(Bl,t)}function El(t){return Rl(Wl,t)}function Jl(){return Object.keys(Bl)}const Kl="0 0 16 16",Ul=2,Yl={viewBox:Kl,fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"},ql="M3 2h2v2H3zM11 2h2v2h-2z",Gl=vl(8,8),Xl=vl(5,5,2)+vl(11,11,2),Zl=vl(8,9),Ql=vl(4,12)+vl(12,4),ta=vl(5,5,2)+vl(10,11,2),ea=vl(8,5,2),ia=(t,e)=>`M${t} ${e}h0`,na={cursor:"M4 2v10l3-3h5zM8 10l2 4",magnet:"M4 5v3a4 4 0 0 0 8 0V5"+ql,lock:"M3 8h10v6H3zM5 8V6a3 3 0 0 1 6 0v2",unlock:"M3 8h10v6H3zM8 8V5a3 3 0 0 0-6 0",eye:"M2 8c2-3 4-5 6-5s4 2 6 5c-2 3-4 5-6 5s-4-2-6-5z"+Gl,"eye-off":"M2 8c2-3 4-5 6-5s4 2 6 5c-2 3-4 5-6 5s-4-2-6-5zM3 3l10 10",star:"M8 2l2 4h4l-3 3 1 5-4-3-4 3 1-5-3-3h4z","star-filled":"M8 2l4 12-10-8h12L4 14z",trash:"M2 4h12M6 4V2h4v2M3 4l1 10h8l1-10",settings:"M2 5h12M2 11h12"+Xl,undo:"M3 6h7a4 4 0 0 1 0 8H6M6 3 3 6l3 3",redo:"M13 6H6a4 4 0 0 0 0 8h4M10 3l3 3-3 3",copy:"M6 6h8v8H6zM10 6V2H2v8h4",paste:"M3 3h10v11H3zM6 2h4v2H6zM6 8h4M6 11h4",duplicate:"M8 8h6v6H8zM5 2v6M2 5h6",front:"M2 9h6v5H2zM11 14V2M8 5l3-3 3 3",back:"M2 2h6v5H2zM11 2v12M8 11l3 3 3-3",text:"M3 3h10M8 3v10M6 13h4","chevron-down":"M3 6l5 5 5-5","chevron-right":"M6 3l5 5-5 5",close:"M3 3l10 10M13 3 3 13",plus:"M8 2v12M2 8h12",minus:"M2 8h12",search:"M7 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10zM11 11l3 3",grid:"M2 2h12v12H2zM2 8h12M8 2v12",link:"M6 5H5a3 3 0 0 0 0 6h1M10 5h1a3 3 0 0 1 0 6h-1M6 8h4",unlink:"M6 5H5a3 3 0 0 0 0 6h1M10 5h1a3 3 0 0 1 0 6h-1M8 2v1M8 13v1",camera:"M2 5h3l1-2h4l1 2h3v8H2z"+Zl,download:"M8 2v9M4 7l4 4 4-4M2 14h12","capture-grid":"M2 5 2 2 5 2M11 2 14 2 14 5M14 11 14 14 11 14M5 14 2 14 2 11"+ia(6,6)+ia(10,6)+ia(6,10)+ia(10,10),"chevron-up":"M3 10l5-5 5 5","chevron-left":"M10 3 5 8l5 5",check:"M3 8l4 4 6-8",more:ia(8,3)+ia(8,8)+ia(8,13),grip:ia(6,4)+ia(10,4)+ia(6,8)+ia(10,8)+ia(6,12)+ia(10,12),refresh:"M10 12A5 5 0 1 1 12 8M10 6l2 2 2-2",swap:"M2 5h11M10 2l3 3-3 3M14 11H3M6 8l-3 3 3 3",layout:"M2 2 6 2 6 14 2 14zM10 2 14 2 14 6 10 6zM10 10 14 10 14 14 10 14z",maximize:"M10 6 14 2M11 2h3v3M6 10 2 14M2 11v3h3",restore:"M13 3 9 7M12 7H9V4M3 13l4-4M4 9h3v3",fullscreen:"M2 6V2h4M10 2h4v4M14 10v4h-4M6 14H2v-4","fullscreen-exit":"M6 2v4H2M14 6h-4V2M10 14v-4h4M2 10h4v4","link-group":"M2 3h4v10H2zM10 3h4v10h-4zM6 8h4","drawing-sync":"M4 12 12 4"+Ql,crosshair:wl(8,8,4)+"M8 2 8 4M8 12 8 14M2 8 4 8M12 8 14 8","time-range":"M3 4v8M13 4v8M3 8h10",palette:"M8 14A6 6 0 1 1 14 8L10 10z"+ia(5,8)+ia(7,5)+ia(10,5),calendar:"M2 4h12v10H2zM2 7h12M6 2v3M10 2v3M5 10h2",clock:wl(8,8,5)+"M8 6v2h2",globe:wl(8,8,6)+"M8 2a3 6 0 0 0 0 12a3 6 0 0 0 0-12M2 8h12","market-open":wl(8,8,2)+"M8 2 8 3M2 8 3 8M13 8 14 8M3 3 4 4M13 3 12 4M2 13h12","market-pre":"M2 13h12M5 13a3 3 0 0 1 6 0M8 7V2M5 5l3-3 3 3","market-post":"M2 13h12M6 13a2 2 0 0 1 4 0M8 3v5M5 5l3 3 3-3","market-closed":"M8 2A4 4 0 1 0 12 6 4 4 0 0 1 8 2zM2 13h12","market-holiday":"M2 4h12v10H2zM6 2v3M10 2v3M6 8l4 4M10 8l-4 4",replay:"M8 3v10L2 8zM14 3v10L8 8z",play:"M5 3v10l8-5z",pause:"M4 3h1v10H4zM11 3h1v10h-1z",stop:"M4 4h8v8H4z","step-forward":"M3 3v10l6-5zM12 3v10","step-back":"M13 3v10L7 8zM4 3v10",record:vl(8,8,4),"scale-auto":"M8 2v12M5 5l3-3 3 3M5 11l3 3 3-3","scale-log":"M2 2v12h12M4 12C8 11 11 8 13 3","scale-percent":"M13 3 3 13"+wl(4,4,2)+wl(12,12,2),folder:"M2 3h4l2 2h6v8H2z",save:"M2 2h9l3 3v9H2zM5 2v4h5V2M5 14v-4h6v4","save-as":"M9 14H2V2h9l3 3v4M12 10v4M10 12h4",autosave:"M3 8A5 5 0 0 1 12 5M12 2v3H9M13 8A5 5 0 0 1 4 11M4 14v-3h3",rename:"M9 5H2v6h7M12 3v10M10 3h4M10 13h4",recent:"M6 12A5 5 0 1 0 4 8M6 6 4 8 2 6M9 6v2h2",template:"M2 2h12v4H2zM2 9h5v5H2zM10 9h4M10 12h4",keyboard:"M2 3h12v10H2z"+ia(5,6)+ia(8,6)+ia(11,6)+"M5 10h6",bell:"M4 11V7a4 4 0 0 1 8 0v4M2 11h12M7 14h2","bell-off":"M4 11V7a4 4 0 0 1 8 0v4M2 11h12M7 14h2M2 2l12 12",pin:"M5 2h6M6 2v5l-2 3h8l-2-3V2M8 10v4","pin-filled":"M5 2h6M6 2h4v5l2 3H4l2-3zM8 10v4",info:wl(8,8,6)+ia(8,5)+"M8 8v3",warning:"M8 2l6 12H2zM8 7v1"+ia(8,11),error:"M8 2l6 6-6 6-6-6zM8 5v2"+ia(8,10),sun:wl(8,8,2)+"M8 2 8 3M8 13 8 14M2 8 3 8M13 8 14 8M3 3 4 4M12 12 13 13M13 3 12 4M3 13 4 12",moon:"M12 11A5 5 0 1 1 5 4a7 7 0 0 0 7 7z",eraser:"M2 10 8 4l6 6-4 4H6zM5 7l6 6",measure:"M2 5h12v6H2zM5 5v3M8 5v2M11 5v3",fill:"M8 2l4 6a4 4 0 1 1-8 0z",bold:"M4 2h5a3 3 0 0 1 0 6H4zM4 8h6a3 3 0 0 1 0 6H4z",italic:"M7 2h6M3 14h6M10 2 6 14",watchlist:ia(3,4)+ia(3,8)+ia(3,12)+"M6 4h8M6 8h8M6 12h8",news:"M4 12V3h10v10H3a1 1 0 0 1-1-1V6h2M7 6h4M7 9h4",account:ea+"M3 14a5 4 0 0 1 10 0",compare:"M2 7 6 3 10 6 14 2M2 14 6 10 10 12 14 8",indicators:"M4 14V5a2 2 0 0 1 2-2h1M2 7h4M9 8l5 6M14 8l-5 6",buy:"M8 3l6 9H2z",sell:"M8 13 2 4h12z","close-position":"M9 2H2v12h7M6 8h8M11 5l3 3-3 3",reverse:"M5 13V3M2 6l3-3 3 3M11 3v10M8 10l3 3 3-3",bracket:"M2 8h12M4 3h8M4 13h8M8 3v10","dom-ladder":"M4 2v12M12 2v12M4 5h8M4 8h8M4 11h8",legend:"M2 4h8M2 8h12M2 12h9",axes:"M3 2v11h11M3 6h2M3 10h2M7 13v-2M11 13v-2",panels:"M2 3h12v10H2zM2 8h12M7 3v10",trading:"M2 11l4-4 3 2 5-5M11 4h3v3M2 14h12",brush:"M14 2 9 7M9 7 7 5M9 7l-2 4-4 2 2-4z","above-series":"M3 3h10M8 14V7M5 10l3-3 3 3","behind-series":"M3 13h10M8 2v7M5 6l3 3 3-3",fit:"M2 8h12M5 5 2 8l3 3M11 5l3 3-3 3",coordinates:"M3 2v11h11"+ia(10,6)+"M3 6h4M10 13v-4","line-dashed":"M3 8h2M11 8h2","line-dotted":ia(2,8)+ia(6,8)+ia(10,8)+ia(14,8),"line-mixed":"M2 5h12M3 11h2M11 11h2","chart-candlestick":"M5 2 5 5M3 5h4v6H3zM5 11 5 14M12 3 12 13M11 5h2v6h-2z","chart-hollow-candle":"M5 2 5 4M3 4h4v5H3zM5 9 5 12M11 4 11 7M9 7h4v5H9zM11 12 11 14","chart-volume-candle":"M4 3 4 13M3 5h2v5H3zM8 4h6v7H8zM11 2 11 4M11 11 11 14","chart-heikin-ashi":"M3 8h4v6H3zM5 6 5 8M9 4h4v7H9zM11 2 11 4","chart-bar":"M5 2 5 14M2 5 5 5M5 11 8 11M11 3 11 12M8 9 11 9M11 5 14 5","chart-high-low":"M4 3 4 11M8 5 8 14M12 2 12 9","chart-line":"M2 12 6 6 9 10 14 3","chart-line-markers":"M2 10 5 5 10 11 14 4"+ta,"chart-step":"M2 12h3V8h4v3h3V4h2","chart-area":"M2 14V10l4-5 3 3 5-6v12z","chart-hlc-area":"M2 6 6 4 10 6 14 3V9l-4 3-4-2-4 2z","chart-baseline":"M2 8h12M2 12 6 4 10 12 14 5","chart-column":"M3 14 3 9M6 14 6 5M9 14 9 8M12 14 12 3","chart-histogram":"M2 8h12M4 8 4 4M7 8 7 2M10 8 10 12M13 8 13 14","chart-point-figure":"M2 2 6 6M6 2 2 6M2 8 6 12M6 8 2 12"+wl(11,5,2)+wl(11,11,2),"chart-kagi":"M3 13V5h4v6h3V3h3v7","chart-renko":"M2 10 6 10 6 14 2 14zM6 6 10 6 10 10 6 10zM10 2 14 2 14 6 10 6z","chart-range-bars":"M3 9 4 9 4 14 3 14zM7 6 8 6 8 11 7 11zM11 3 12 3 12 8 11 8z","chart-line-break":"M2 9 6 9 6 14 2 14zM6 4 10 4 10 9 6 9zM10 7 14 7 14 11 10 11z"},ra={magnet:ql,eye:Gl,settings:Xl,camera:Zl,"drawing-sync":Ql,account:ea,"chart-line-markers":ta},sa=new Set(["star-filled","pin-filled","replay","play","stop","step-forward","step-back","record","buy","sell","moon","market-closed"]);function oa(t){return Rl(na,t)}function la(t){return Rl(ra,t)}function aa(){return Object.keys(na)}function ca(t){return Rl(na,`chart-${t}`)}function ha(t,e,i){const n=t=>Number.isInteger(t)&&t>=1&&t<=4;if(!n(t)||!n(e))throw new RangeError(`openalgo-charts: a layout glyph takes 1..4 rows and columns, not ${t}x${e}`);const r=Array.from({length:t*e},(t,e)=>-1-e);(i??[]).forEach((i,n)=>{const s=i.rowSpan??1,o=i.columnSpan??1;if(!(Number.isInteger(i.row)&&Number.isInteger(i.column)&&Number.isInteger(s)&&Number.isInteger(o)&&i.row>=0&&i.column>=0&&s>=1&&o>=1&&i.row+s<=t&&i.column+o<=e))throw new RangeError(`openalgo-charts: layout slot ${n} is outside a ${t}x${e} grid`);for(let t=i.row;t<i.row+s;t++)for(let s=i.column;s<i.column+o;s++){if(r[t*e+s]>=0)throw new RangeError(`openalgo-charts: layout slot ${n} overlaps slot ${r[t*e+s]}`);r[t*e+s]=n}});const s=(t,e)=>2+12/e*t;let o="M2 2h12v12H2z";const l=(t,e,i,n)=>{for(let r=1;r<t;r++){let t=-1;for(let s=0;s<=e;s++){const l=s<e&&i(r,s);l&&t<0&&(t=s),!l&&t>=0&&(o+=n(r,t,s),t=-1)}}};return l(e,t,(t,i)=>r[i*e+t-1]!==r[i*e+t],(i,n,r)=>`M${s(i,e)} ${s(n,t)} ${s(i,e)} ${s(r,t)}`),l(t,e,(t,i)=>r[(t-1)*e+i]!==r[t*e+i],(i,n,r)=>`M${s(n,e)} ${s(i,t)} ${s(r,e)} ${s(i,t)}`),o}const da="http://www.w3.org/2000/svg",ua="oac-icon-";function pa(t){return String(t).replace(/[&<>"]/g,t=>"&"===t?"&":"<"===t?"<":">"===t?">":""")}function fa(t,e,i){const n=t(e);if(void 0===n)throw new Error(`openalgo-charts: no ${i} icon "${e}"`);return n}function ya(t,e){return`<path d="${pa(t)}"/>`+(void 0===e?"":`<path d="${pa(e)}" fill="currentColor" stroke="none"/>`)}function xa(t){return Number(t.viewBox.split(" ")[2])}function ga(t,e,i,n){const r=pa(n.size??xa(e)),s=pa(n.stroke??e.strokeWidth),o=void 0!==n.className&&""!==n.className?` class="${pa(n.className)}"`:"";return`<svg xmlns="${da}" viewBox="${pa(e.viewBox)}" width="${r}" height="${r}" fill="${pa(i)}" stroke="${pa(e.stroke)}" stroke-width="${s}" stroke-linecap="${pa(e.strokeLinecap)}" stroke-linejoin="${pa(e.strokeLinejoin)}"${o} aria-hidden="true">${t}</svg>`}function ma(t,e={}){return ga(ya(fa(Vl,t,"tool"),Wl[t]),bl,bl.fill,e)}function _a(t,e={}){const i=fa(oa,t,"chrome"),n=sa.has(t)?"currentColor":Yl.fill;return ga(ya(i,ra[t]),Yl,n,e)}function ba(t=Object.keys(Bl)){let e="";for(const i of new Set(t)){const t=fa(Vl,i,"tool");e+=`<symbol id="${pa(ua+i)}" viewBox="${pa(bl.viewBox)}">${ya(t,Wl[i])}</symbol>`}return`<svg xmlns="${da}" style="display:none" aria-hidden="true">${e}</svg>`}function va(t,e={}){return fa(Vl,t,"tool"),ga(`<use href="#${pa(ua+t)}"/>`,bl,bl.fill,e)}function wa(t,e={}){const i=fa(Vl,t,"tool"),n=e.size??20;if(!(Number.isFinite(n)&&n>0&&n<=128))throw new RangeError(`openalgo-charts: cursor size ${n} is outside 1..128`);const[r,s]=e.hotspot??[n/2,n/2],o=e.color??"#fff",l=e.halo??function(t){const e=/^#([0-9a-f]{3,8})$/i.exec(t.trim());if(!e)return"#000";const i=e[1],n=i.length<6?i.split("").map(t=>t+t).join(""):i;return(.2126*parseInt(n.slice(0,2),16)+.7152*parseInt(n.slice(2,4),16)+.0722*parseInt(n.slice(4,6),16))/255>.5?"#000":"#fff"}(o),a=e.fallback??"crosshair",c=xa(bl)/n,h=Math.round(100*(2+2*c))/100,d=Wl[t],u=`<svg xmlns="${da}" viewBox="${bl.viewBox}" width="${n}" height="${n}" fill="none" stroke-linecap="${bl.strokeLinecap}" stroke-linejoin="${bl.strokeLinejoin}"><path d="${i}" stroke="${pa(l)}" stroke-width="${h}"/><path d="${i}" stroke="${pa(o)}" stroke-width="2"/>`+(void 0===d?"":`<path d="${d}" fill="${pa(o)}"/>`)+"</svg>";return`url("data:image/svg+xml,${encodeURIComponent(u)}") ${Math.round(r)} ${Math.round(s)}, ${a}`}const Ma=1,Pa=10;function ka(t,e){if(e.editingText)return null;const i=t.key??"";if(""===i)return null;const n=!0===t.ctrlKey||!0===t.metaKey,r=!0===t.shiftKey;if(!0===t.altKey)return null;if(!0===e.placing&&!n&&!r){if("Escape"===i)return{type:"cancel"};if("Enter"===i)return{type:"finish"};if("Backspace"===i)return{type:"popAnchor"}}const s=e.hasSelection||e.hasTarget;if(n)switch(i.toLowerCase()){case"z":return r?{type:"redo"}:{type:"undo"};case"y":return r?null:{type:"redo"};case"c":return!r&&s?{type:"copy"}:null;case"x":return!r&&s?{type:"cut"}:null;case"v":return r?null:{type:"paste"};case"d":return!r&&s?{type:"duplicate"}:null;default:return null}if("Delete"===i||"Backspace"===i)return!r&&s?{type:"delete"}:null;if(!e.hasSelection)return null;const o=r?10:1;switch(i){case"ArrowLeft":return{type:"nudge",dx:-o,dy:0};case"ArrowRight":return{type:"nudge",dx:o,dy:0};case"ArrowUp":return{type:"nudge",dx:0,dy:-o};case"ArrowDown":return{type:"nudge",dx:0,dy:o};default:return null}}const Sa="draw";Wr();export{hi as ADVANCED_GEOMETRY_TOOLS,Be as ADVANCED_LINE_TOOLS,H as ALIGN_OPTIONS,nr as ANCHORED_VWAP,$r as ARC,fr as ARROW,Un as ARROW_DOWN,Yn as ARROW_LEFT,qn as ARROW_RIGHT,Kn as ARROW_UP,zn as BALLOON,kr as BRUSH,Hr as BUILTIN_DRAWING_TOOLS,un as CALLOUT,na as CHROME_ICONS,ra as CHROME_ICON_ACCENTS,Yl as CHROME_ICON_ATTRS,sa as CHROME_ICON_FILLED,Ul as CHROME_ICON_STROKE,Kl as CHROME_ICON_VIEWBOX,zr as CIRCLE,E as COLOR_FIELD,Cn as COMMENT,mr as CROSS_LINE,Dr as CURVE,c as CYCLE_PALETTE,Or as CYCLIC_LINES,sn as DATE_RANGE,y as DEFAULT_FIB,x as DEFAULT_FIB_FAN,_ as DEFAULT_FIB_TIME_ZONE,g as DEFAULT_GANN_BOX,m as DEFAULT_GANN_FAN,Ir as DOUBLE_CURVE,Qs as DRAWING_CLIPBOARD_KEY,to as DRAWING_CLIPBOARD_VERSION,Cs as DRAWING_STATE_VERSION,Wl as DRAWING_TOOL_ACCENTS,Bl as DRAWING_TOOL_ICONS,Sa as DRAW_TIER,_o as DrawingClipboard,tl as DrawingController,Ns as DrawingLayer,al as DrawingLinkGroup,wr as ELLIPSE,pr as EXTENDED_LINE,q as EXTEND_FIELDS,Vi as FIB_CHANNEL,Wi as FIB_EXTENSION,Ji as FIB_FAN,Bi as FIB_RETRACEMENT,Ei as FIB_TIME_ZONE,Y as FILL_FIELDS,rr as FIXED_RANGE_VOLUME_PROFILE,_n as FLAG_MARK,tt as FONT_FIELDS,V as FONT_OPTIONS,on as FORECAST,Ui as GANN_BOX,Ki as GANN_FAN,jr as HIGHLIGHTER,yr as HORIZONTAL_LINE,xr as HORIZONTAL_RAY,bl as ICON_ATTRS,_l as ICON_STROKE,ua as ICON_SYMBOL_PREFIX,ml as ICON_VIEWBOX,X as INTERVAL_FIELDS,xl as InstrumentDrawings,Q as LEVEL_FIELDS,s as LEVEL_NEUTRAL,U as LINE_FIELDS,K as LINE_STYLE_FIELD,j as LINE_STYLE_OPTIONS,J as LINE_WIDTH_FIELD,en as LONG_POSITION,Zi as MEASURE,Ln as NOTE,Ma as NUDGE_STEP_PX,Pa as NUDGE_STEP_SHIFT_PX,Mr as PARALLEL_CHANNEL,Pr as PATH,Pi as PATTERN_DRAWING_TOOLS,rt as PLATE_TEXT_FIELDS,Cr as POLYLINE,hn as PRICE_LABEL,Hn as PRICE_NOTE,rn as PRICE_RANGE,ur as RAY,vr as RECTANGLE,Sr as ROTATED_RECTANGLE,nt as SHAPE_TEXT_FIELDS,nn as SHORT_POSITION,Z as SHOW_LABELS_FIELD,Dn as SIGNPOST,Lr as SINE_LINE,G as SPACE_FIELD,R as SPACE_OPTIONS,Rn as TABLE,ln as TEXT,it as TEXT_FIELDS,W as TEXT_POSITION_OPTIONS,et as TEXT_VALUE_FIELD,Fr as TIME_CYCLES,dr as TREND_LINE,Nr as TRIANGLE,B as VALIGN_OPTIONS,gr as VERTICAL_LINE,Tt as anchoredVwapAnalysis,xt as applyDrawingSettings,N as boundsOf,_t as catmullRom,ca as chartTypeIcon,oa as chromeIcon,la as chromeIconAccent,aa as chromeIconIds,_a as chromeIconSvg,no as clearMemoryClipboard,oo as cloneDrawing,f as cloneLevels,yt as coerceSettingValue,st as composeSettings,cl as createDrawingLinkGroup,gl as createInstrumentDrawings,h as cycleColor,mo as decodeClipboardPayload,$ as distToEllipse,O as distToLine,A as distToPolyline,C as distToRect,I as distToSegment,Ci as drawingSettingsSchema,zi as drawingShortcuts,Vs as drawingShownOnInterval,El as drawingToolAccent,Vl as drawingToolIcon,Jl as drawingToolIconIds,co as encodeClipboardPayload,D as extendSegment,It as fixedRangeVolumeProfileAnalysis,d as formatRatio,u as gannLabel,Ti as getDrawingTool,Ii as hasDrawingTool,ba as iconSprite,ma as iconSvg,va as iconUse,ul as instrumentDrawingsKey,ka as keyToDrawingAction,ha as layoutIconPath,a as levelColor,Ai as matchDrawingShortcut,pl as memoryDrawingStore,Us as migrateDrawings,yl as migrateUnscopedDrawings,bt as pressureWidth,mt as rdpSimplify,ct as readDrawingSetting,ht as readDrawingSettings,z as rectOf,Wr as registerBuiltinDrawingTools,Si as registerDrawingTool,Fi as registeredDrawingTools,go as sanitizeDrawing,As as sortByZIndex,wo as studyInputTarget,ro as systemClipboard,wa as toolCursor,fl as webStorageDrawingStore};
//# sourceMappingURL=openalgo-charts.draw.mjs.map