@luxalgo/vela 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  var Vela=(function(exports){'use strict';function vn(r,e,t=1e3){return r===true?e:typeof r!="number"||!Number.isFinite(r)||r<=0?0:Math.min(r,t)}function lh(r){return vn(r,90,1e3)}function ch(r){let e={style:false,duration:0};if(r===true)return {style:"settle",duration:650};if(r==="settle"||r==="grow")return {style:r,duration:650};if(r&&typeof r=="object"){let t=r,n=t.duration;return {style:t.style==="grow"?"grow":"settle",duration:typeof n=="number"&&Number.isFinite(n)&&n>0?Math.min(n,5e3):650}}return e}function Tf(r){if(r===false)return {animZoom:0,animPan:0,animScroll:0,animAutoscale:0,animLiveBar:0,animIntro:{style:false,duration:0}};let e=r===true||r==null?{}:r,t=vn(e.pan??true,110);return {animZoom:vn(e.zoom??true,70),animPan:t,animScroll:e.scroll===void 0?t>0?130:0:vn(e.scroll,130),animAutoscale:vn(e.autoscale??true,80),animLiveBar:lh(e.liveBar),animIntro:ch(e.intro??true)}}function at(r){return r.kind!=="candle"&&r.kind!=="bar"&&r.kind!=="markers"}function nn(r,e){return r.display?r.display[e]!==false:r.visible!==false}function sl(r){return nn(r,"pane")||nn(r,"priceScale")}var jr=class{constructor(){this.handlers=new Map;}on(e,t){let n=this.handlers.get(e);n||(n=new Set,this.handlers.set(e,n));let i=n;return i.add(t),()=>{i.delete(t);}}off(e,t){this.handlers.get(e)?.delete(t);}hasListeners(e){return (this.handlers.get(e)?.size??0)>0}emit(e,t){let n=this.handlers.get(e);if(n)for(let i of n)try{i(t);}catch(o){console.error(`[vela] event handler error for "${String(e)}"`,o);}}clear(){this.handlers.clear();}};var al=class{constructor(){this.records=new Map;this.counter=0;}nextId(e="ind",t=()=>false){let n;do this.counter+=1,n=`${e}-${this.counter}`;while(this.records.has(n)||t(n));return n}add(e){this.records.set(e.id,e);}get(e){return this.records.get(e)}remove(e){let t=this.records.get(e);return this.records.delete(e),t}all(){return [...this.records.values()]}};var P1=/[‎‏؜]/g;function et(r){return r.replace(P1,"")}var kf=new Map;function yn(r,e){let t=`${r.locale}|${r.numberingSystem}|${JSON.stringify(e)}`,n=kf.get(t);if(!n){try{n=new Intl.NumberFormat(r.locale,{...e,numberingSystem:r.numberingSystem});}catch{n=new Intl.NumberFormat("en",e);}kf.set(t,n);}return n}var Lf=new Map;function Mf(r){let e=`${r.locale}|${r.numberingSystem}`,t=Lf.get(e);if(t)return t;let n=yn(r,{useGrouping:false,minimumFractionDigits:1,maximumFractionDigits:1}).formatToParts(-1.5),i=et(n.find(d=>d.type==="decimal")?.value??".")||".",o=et(n.find(d=>d.type==="minusSign")?.value??"-")||"-",s=yn(r,{useGrouping:false,maximumFractionDigits:0}),a=Array.from({length:10},(d,u)=>et(s.format(u)));return t={ascii:i==="."&&o==="-"&&a.every((d,u)=>d===String(u)),decimal:i,minus:o,digits:a},Lf.set(e,t),t}function Ht(r,e){let t=Mf(e);if(t.ascii)return r;let n="";for(let i of r){let o=i.charCodeAt(0);o>=48&&o<=57?n+=t.digits[o-48]:i==="."?n+=t.decimal:i==="-"?n+=t.minus:n+=i;}return n}function dh(r,e){let t=Mf(e);return t.digits.every((n,i)=>n===String(i))?r:r.replace(/[0-9]/g,n=>t.digits[Number(n)])}var ll=r=>Number.isFinite(r)?Math.max(0,Math.min(20,Math.trunc(r))):2;function I1(r,e,t){return Ht(r.toFixed(ll(e)),t)}function A1(r,e,t){let n=ll(e);return et(yn(t,{minimumFractionDigits:n,maximumFractionDigits:n}).format(r))}function cl(r,e,t){return et(t==="integer"?yn(e,{maximumFractionDigits:0}).format(r):t==="percent"?yn(e,{style:"percent"}).format(r):yn(e,{}).format(r))}function uh(r,e,t){let n=ll(e?.decimals??2),i=e?.signed??true;if(t.english){let s=i?`${r>=0?"+":"-"}${Math.abs(r).toFixed(n)}%`:`${r.toFixed(n)}%`;return Ht(s,t)}let o=yn(t,{style:"percent",minimumFractionDigits:n,maximumFractionDigits:n,signDisplay:i?"always":"auto"});return et(o.format(r/100))}function Ef(r,e,t){let n=e.mode??"price";return n==="percent"?uh(r,{decimals:e.decimals,signed:true},t):n==="indexed"||!e.grouping?I1(r,e.decimals,t):A1(r,e.decimals,t)}var R1=[[1e9,"B"],[1e6,"M"],[1e3,"K"]];function Pf(r,e,t){let n=ll(e?.decimals??2),i=e?.trimZeros??true;if(t.english){let s=Math.abs(r),a=1,l="";for(let[h,p]of R1)if(s>=h){a=h,l=p;break}let d=r/a,u=i?Number(d.toFixed(n)).toString():d.toFixed(n);return Ht(u,t)+l}let o=yn(t,{notation:"compact",compactDisplay:"short",maximumFractionDigits:n,minimumFractionDigits:i?0:n});return et(o.format(r))}var Of=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],D1=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],ph=r=>r<10?`0${r}`:String(r),hh=864e5,If=new Map;function mh(r,e){if(!e||e==="UTC")return 0;let t=If.get(e);if(t===void 0){try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"});}catch{t=null;}If.set(e,t);}if(!t)return 0;try{let n=t.formatToParts(new Date(r)),i=s=>Number(n.find(a=>a.type===s)?.value);return Date.UTC(i("year"),i("month")-1,i("day"),i("hour")%24,i("minute"),i("second"))-r}catch{return 0}}var Af=new Map;function mr(r,e){let t=`${r.locale}|${r.numberingSystem}|${JSON.stringify(e)}`,n=Af.get(t);if(!n){let i={...e,timeZone:"UTC",calendar:"gregory",numberingSystem:r.numberingSystem};try{n=new Intl.DateTimeFormat(r.locale,i);}catch{n=new Intl.DateTimeFormat("en",{...e,timeZone:"UTC",calendar:"gregory"});}Af.set(t,n);}return n}function gh(r){return r.hourCycle==="h23"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:r.hourCycle==="h12"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:{hour:"numeric",minute:"2-digit"}}function Nf(r,e){return e.hourCycle==="h23"?Ht(`${ph(r.getUTCHours())}:${ph(r.getUTCMinutes())}`,e):et(mr(e,gh(e)).format(r))}var O1={year:{year:"numeric"},month:{month:"short"},day:{month:"short",day:"numeric"}},Rf=r=>r==="hour"||r==="minute"||r==="second";function Ff(r,e,t){let n=new Date(r+(e.offsetMs??0)),i=e.unit;if(t.english){if(Rf(i))return Nf(n,t);let s=Of[n.getUTCMonth()];return i==="year"?Ht(String(n.getUTCFullYear()),t):i==="month"?s:Ht(`${s} ${n.getUTCDate()}`,t)}let o=Rf(i)?gh(t):O1[i];return et(mr(t,o).format(n))}function Bf(r,e,t){let n=new Date(r+mh(r,e?.timeZone??"UTC")),i=e?.withTime??true;if(t.english){let s=Ht(`${D1[n.getUTCDay()]} ${n.getUTCDate()} ${Of[n.getUTCMonth()]} '${ph(n.getUTCFullYear()%100)}`,t);return i?`${s} ${Nf(n,t)}`:s}let o={weekday:"short",day:"numeric",month:"short",year:"2-digit",...i?gh(t):{}};return et(mr(t,o).format(n))}function N1(r){let e=Math.max(0,Math.ceil(r/1e3)),t=e%60,n=Math.floor(e/60)%60,i=Math.floor(e/3600),o=s=>String(s).padStart(2,"0");return i>0?`${i}:${o(n)}:${o(t)}`:`${o(n)}:${o(t)}`}function F1(r){let e=Math.abs(r),t=36e5,n=6e4;if(e>=hh){let i=Math.floor(e/hh),o=Math.round(e%hh/t);return o?[[i,"day"],[o,"hour"]]:[[i,"day"]]}if(e>=t){let i=Math.floor(e/t),o=Math.round(e%t/n);return o?[[i,"hour"],[o,"minute"]]:[[i,"hour"]]}return e>=n?[[Math.round(e/n),"minute"]]:[[Math.round(e/1e3),"second"]]}var B1={day:"d",hour:"h",minute:"m",second:"s"};function Vf(r,e,t){if((e?.style??"countdown")==="countdown")return dh(N1(r),t);let n=F1(r);return t.english?dh(n.map(([i,o])=>`${i}${B1[o]}`).join(" "),t):n.map(([i,o])=>et(yn(t,{style:"unit",unit:o,unitDisplay:"narrow"}).format(i))).join(" ")}var Df=new Map;function Hf(r,e,t){let n=e?.timeZone??"UTC",i=e?.seconds??true,o=t.english&&t.hourCycle==="h23",s=`${o?"en-GB":t.locale}|${t.numberingSystem}|${t.hourCycle}|${n}|${i}`,a=Df.get(s);if(a===void 0){let l={hour:"2-digit",minute:"2-digit",...i?{second:"2-digit"}:{},timeZone:n};try{a=o?new Intl.DateTimeFormat("en-GB",{...l,hour12:!1}):new Intl.DateTimeFormat(t.locale,{...l,calendar:"gregory",numberingSystem:t.numberingSystem,...t.hourCycle==="locale"?{}:{hourCycle:t.hourCycle}});}catch{a=null;}Df.set(s,a);}if(!a)return "";try{return et(a.format(new Date(r)))}catch{return ""}}function zf(r){return {price:(e,t)=>Ef(e,t,r),percent:(e,t)=>uh(e,t,r),compact:(e,t)=>Pf(e,t,r),timeTick:(e,t)=>Ff(e,t,r),timeStamp:(e,t)=>Bf(e,t,r),duration:(e,t)=>Vf(e,t,r),clock:(e,t)=>Hf(e,t,r)}}var fh=Object.freeze({locale:"en",numberingSystem:"latn",hourCycle:"h23",english:true}),Pt=zf(fh),_f=false;function qr(r,e,t,n){try{let i=r(e,t);if(typeof i=="string")return i}catch(i){_f||(_f=true,console.warn("[vela] a host formatter threw; the built-in formatting is used instead.",i));}return n()}function Wf(r,e){let t=zf(r);if(!e)return t;let n=(o,s,a,l)=>({locale:r.locale,timeZone:a??"UTC",surface:o??s,fallback:l}),i=e;return {price(o,s){let a=()=>t.price(o,s);return typeof i.price!="function"?a():qr(i.price,o,{...n(s.surface,"priceAxis",void 0,a),decimals:s.decimals,mintick:s.mintick,mode:s.mode??"price",paneId:s.paneId,grouping:s.grouping??false},a)},percent(o,s){let a=()=>t.percent(o,s);return typeof i.percent!="function"?a():qr(i.percent,o,{...n(s?.surface,"statusLine",void 0,a),decimals:s?.decimals??2,signed:s?.signed??true},a)},compact(o,s){let a=()=>t.compact(o,s);return typeof i.compact!="function"?a():qr(i.compact,o,{...n(s?.surface,"priceAxis",void 0,a),decimals:s?.decimals??2,trimZeros:s?.trimZeros??true},a)},timeTick(o,s){let a=()=>t.timeTick(o,s);return typeof i.timeTick!="function"?a():qr(i.timeTick,o,{...n(s.surface,"timeAxis",s.timeZone,a),unit:s.unit,major:s.major,offsetMs:s.offsetMs??0},a)},timeStamp(o,s){let a=()=>t.timeStamp(o,s);return typeof i.timeStamp!="function"?a():qr(i.timeStamp,o,{...n(s?.surface,"crosshair",s?.timeZone,a),withTime:s?.withTime??true},a)},duration(o,s){let a=()=>t.duration(o,s);return typeof i.duration!="function"?a():qr(i.duration,o,{...n(s?.surface,"lastPrice",void 0,a),style:s?.style??"countdown"},a)},clock(o,s){let a=()=>t.clock(o,s);return typeof i.clock!="function"?a():qr(i.clock,o,{...n(s?.surface,"clock",s?.timeZone,a),seconds:s?.seconds??true},a)}}}var bh=class{constructor(e){this.src=e;this.i=0;}parse(){let e=this.message(false,0);if(this.i<this.src.length)throw this.error("unmatched }");return e}error(e){return new SyntaxError(`[vela] message syntax: ${e} at ${this.i} in "${this.src}"`)}message(e,t){if(t>8)throw this.error("nesting too deep");let n=this.src,i=[],o="",s=()=>{o&&i.push(o),o="";};for(;this.i<n.length;){let a=n[this.i];if(a==="'"){let l=n[this.i+1];if(l==="'")o+="'",this.i+=2;else if(l==="{"||l==="}"||e&&l==="#")for(this.i+=1;this.i<n.length;){let d=n[this.i];if(d==="'"){if(n[this.i+1]==="'"){o+="'",this.i+=2;continue}this.i+=1;break}o+=d,this.i+=1;}else o+="'",this.i+=1;}else if(a==="{")s(),this.i+=1,i.push(this.argument(t));else {if(a==="}")break;a==="#"&&e?(s(),i.push({kind:"pound"}),this.i+=1):(o+=a,this.i+=1);}}return s(),i}skipSpace(){for(;this.i<this.src.length&&/\s/.test(this.src[this.i]);)this.i+=1;}word(){this.skipSpace();let e=this.i;for(;this.i<this.src.length&&!/[\s,{}]/.test(this.src[this.i]);)this.i+=1;return this.src.slice(e,this.i)}expect(e){if(this.skipSpace(),this.src[this.i]!==e)throw this.error(`expected "${e}"`);this.i+=1;}argument(e){let t=this.word();if(!t)throw this.error("empty argument name");if(this.skipSpace(),this.src[this.i]==="}")return this.i+=1,{kind:"arg",name:t};this.expect(",");let n=this.word();if(this.skipSpace(),n==="number"){let i;return this.src[this.i]===","&&(this.i+=1,i=this.word()||void 0),this.expect("}"),{kind:"arg",name:t,format:"number",style:i}}if(n==="plural"||n==="selectordinal"||n==="select"){this.expect(",");let i=0;if(this.skipSpace(),n!=="select"&&this.src.startsWith("offset:",this.i)&&(this.i+=7,i=Number(this.word()),!Number.isFinite(i)))throw this.error("bad offset");let o={};for(;;){if(this.skipSpace(),this.src[this.i]==="}"){this.i+=1;break}let s=this.word();if(!s)throw this.error("expected a selector");this.expect("{"),o[s]=this.message(n!=="select",e+1),this.expect("}");}if(!o.other)throw this.error(`"${t}" has no "other" option`);return n==="select"?{kind:"select",name:t,options:o}:{kind:"plural",name:t,ordinal:n==="selectordinal",offset:i,options:o}}throw this.error(`unknown argument type "${n}"`)}},dl=new Map,V1=2e3;function H1(r){let e=dl.get(r);return e||(e=new bh(r).parse(),dl.size>=V1&&dl.clear(),dl.set(r,e)),e}var Gf=new Map;function _1(r,e){let t=`${r}|${e?"o":"c"}`,n=Gf.get(t);if(!n){try{n=new Intl.PluralRules(r,{type:e?"ordinal":"cardinal"});}catch{n=new Intl.PluralRules("en",{type:e?"ordinal":"cardinal"});}Gf.set(t,n);}return n}function vh(r,e,t,n){let i="";for(let o of r){if(typeof o=="string"){i+=o;continue}if(o.kind==="pound"){i+=n==null?"#":t.formatNumber(n);continue}let s=e?.[o.name];if(o.kind==="arg"){s===void 0?i+=`{${o.name}}`:typeof s=="number"?i+=t.formatNumber(s,o.format==="number"?o.style:void 0):o.format==="number"&&s.trim()!==""&&Number.isFinite(Number(s))?i+=t.formatNumber(Number(s),o.style):i+=s;continue}if(o.kind==="select"){let d=o.options[String(s)]??o.options.other;i+=vh(d,e,t,n);continue}let a=typeof s=="number"?s:Number(s),l;Number.isFinite(a)&&(l=o.options[`=${a}`]??o.options[_1(t.locale,o.ordinal).select(a-o.offset)]),i+=vh(l??o.options.other,e,t,Number.isFinite(a)?a-o.offset:null);}return i}function cs(r,e,t){return r.indexOf("{")<0&&r.indexOf("'")<0?r:vh(H1(r),e,t,null)}var z1=["January","February","March","April","May","June","July","August","September","October","November","December"],W1=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],G1=["Su","Mo","Tu","We","Th","Fr","Sa"];function yh(r,e){if(r.english)return [...e==="long"?z1:W1];let t=mr(r,{month:e});return Array.from({length:12},(n,i)=>et(t.format(Date.UTC(2e3,i,15))))}function $f(r){if(r.english)return [...G1];let e=mr(r,{weekday:"short"});return Array.from({length:7},(t,n)=>et(e.format(Date.UTC(2e3,0,2+n))))}function Yf(r,e){return r.english?Ht(String(e),r):et(mr(r,{year:"numeric"}).format(Date.UTC(e,6,1)))}function Kf(r,e){return Ht(String(Math.trunc(e)),r)}var Uf=new Map;function Xf(r){if(r.english)return false;let e=`${r.locale}|${r.numberingSystem}`,t=Uf.get(e);if(t===void 0){let n=mr(r,{year:"numeric",month:"long"}).formatToParts(Date.UTC(2026,8,15)).map(i=>i.type);t=n.indexOf("year")<n.indexOf("month"),Uf.set(e,t);}return t}var U1=new Set(["AG","AS","BD","BR","BS","BT","BW","BZ","CA","CN","CO","DM","DO","ET","GT","GU","HK","HN","ID","IL","IN","JM","JP","KE","KH","KR","LA","MH","MM","MO","MT","MX","MZ","NI","NP","PA","PE","PH","PK","PR","PT","PY","SA","SG","SV","TH","TT","TW","UM","US","VE","VI","WS","YE","ZA","ZW"]),$1=new Set(["AE","AF","BH","DJ","DZ","EG","IQ","IR","JO","KW","LY","OM","QA","SD","SY"]);function jf(r){let e;try{e=new Intl.Locale(r);}catch{return 1}try{let n=e,o=(typeof n.getWeekInfo=="function"?n.getWeekInfo():n.weekInfo)?.firstDay;if(typeof o=="number")return o===7?0:o===6?6:1}catch{}let t=e.region;if(!t)try{t=e.maximize().region;}catch{t=void 0;}return t&&U1.has(t)?0:t&&$1.has(t)?6:1}function ul(r){let e=typeof r=="string"?r.trim():"";if(!e)return "en";try{return Intl.getCanonicalLocales(e)[0]??e}catch{return e}}function hl(r){try{return new Intl.Locale(r)}catch{return null}}function pl(r){return (hl(r)?.language??r.split(/[-_]/)[0]??r).toLowerCase()}function Zf(r){let e=[],t=i=>{i&&!e.includes(i)&&e.push(i);};t(r);let n=hl(r);if(n){let i=n.baseName;t(i);let o=i.split("-"),s;if(!n.script)try{s=n.maximize().script;}catch{s=void 0;}for(let a=o.length-1;a>=1;a-=1)a===1&&s&&n.region&&t(`${n.language}-${s}`),t(o.slice(0,a).join("-"));s&&!n.region&&t(`${n.language}-${s}`);try{let a=new Intl.Locale(n.language).maximize();a.region&&a.script===(n.script??s)&&t(`${n.language}-${a.region}`);}catch{}}return t("en"),e}var Y1=new Set(["Arab","Hebr","Thaa","Syrc","Nkoo","Adlm","Rohg","Mand","Samr","Yezi"]),K1=new Set(["ar","he","iw","fa","ur","ps","sd","ug","yi","dv","ckb","ks"]);function Qf(r){let e=hl(r);if(e){try{let t=e,n=typeof t.getTextInfo=="function"?t.getTextInfo():t.textInfo;if(n?.direction==="rtl"||n?.direction==="ltr")return n.direction}catch{}try{let t=e.script??e.maximize().script;if(t)return Y1.has(t)?"rtl":"ltr"}catch{}}return K1.has(pl(r))?"rtl":"ltr"}var qf=new Map;function Jf(r,e){let t=`${r}|${e??""}`,n=qf.get(t);if(n)return n;let i="latn";try{e==="locale"?i=new Intl.NumberFormat(r).resolvedOptions().numberingSystem:e?i=new Intl.NumberFormat(r,{numberingSystem:e}).resolvedOptions().numberingSystem:hl(r)?.numberingSystem&&(i=new Intl.NumberFormat(r).resolvedOptions().numberingSystem);}catch{i="latn";}return qf.set(t,i),i}var ds=[],ml=0,eb=new Map;function tb(r){if(!r||typeof r.locale!="string"||!r.messages||typeof r.messages!="object")throw new TypeError("[vela] registerLocale expects { locale: string, messages: Record<string, string> }");let e={tag:ul(r.locale),messages:r.messages};ds.push(e),ml+=1;let t=false;return ()=>{if(t)return;t=true;let n=ds.indexOf(e);n>=0&&(ds.splice(n,1),ml+=1);}}function nb(){return [...new Set(ds.map(r=>r.tag))]}function rb(r){let e=r.join("|"),t=eb.get(e);if(t&&t.version===ml)return t.map;let n=new Map;for(let i=r.length-1;i>=0;i-=1){let o=r[i];for(let s of ds)if(s.tag===o)for(let[a,l]of Object.entries(s.messages))typeof l=="string"&&n.set(a,l);}return eb.set(e,{version:ml,map:n}),n}function gl(r){return typeof r=="object"&&r!==null&&typeof r.id=="string"&&typeof r.defaultMessage=="string"}var X1=["locale","direction","messages","numberingSystem","hourCycle","weekStart","formatters"];function wh(r){let e={};for(let t of X1)t in r&&(e[t]=r[t]);return e}var ib=false;function xh(r,e){if(!r)return;let t=null;for(let n of Object.keys(r)){let i=r[n];typeof i=="object"&&i!==null&&(t??(t={...r}),t[n]=e(i));}return t??r}var zn=class{constructor(e={}){this.runtime={locale:"en",formatNumber:(e,t)=>cl(e,this.settings,t)};this.opts={...e},this.resolve();}get options(){return this.opts}get localeExplicit(){return this.opts.locale!==void 0}get directionExplicit(){return this.opts.direction!==void 0}update(e){let t=typeof e=="string"?{locale:e}:e;this.opts={...this.opts,...t};for(let n of Object.keys(this.opts))this.opts[n]===void 0&&delete this.opts[n];this.resolve();}resolve(){let e=this.opts,t=ul(e.locale),n=Jf(t,e.numberingSystem),i=e.hourCycle==="h12"||e.hourCycle==="locale"?e.hourCycle:"h23";this.settings={locale:t,numberingSystem:n,hourCycle:i,english:pl(t)==="en"},this.chain=Zf(t),this.resolvedDirection=e.direction==="rtl"||e.direction==="ltr"?e.direction:e.direction==="auto"?Qf(t):"ltr",this.resolvedWeekStart=e.weekStart===0||e.weekStart===1||e.weekStart===6?e.weekStart:jf(t),this.runtime.locale=t,this.formatters=Wf(this.settings,e.formatters);}get locale(){return this.settings.locale}get direction(){return this.resolvedDirection}get numberingSystem(){return this.settings.numberingSystem}get hourCycle(){return this.settings.hourCycle}get weekStart(){return this.resolvedWeekStart}get format(){return this.formatters}get formatSettings(){return this.settings}t(e,t){if(typeof e=="string")return e;if(!gl(e))return e==null?"":String(e);let{id:n,defaultMessage:i}=e,o=e.values,s=xh(o?t?{...o,...t}:o:t,d=>this.t(d)),a=this.opts.messages?.[n],l=typeof a=="string"?a:rb(this.chain).get(n)??i;try{return cs(l,s,this.runtime)}catch(d){if(ib||(ib=true,console.warn(`[vela] message "${n}" could not be formatted; the English text is used instead.`,d)),l===i)return i;try{return cs(i,s,this.runtime)}catch{return i}}}};function sb(r){return new zn(r)}var ob=null;function Ae(){return ob??(ob=new zn),ob}function us(r){return r instanceof zn?r.formatSettings:r?{locale:r.locale,numberingSystem:r.numberingSystem,hourCycle:r.hourCycle,english:pl(r.locale)==="en"}:Ae().formatSettings}var j1={locale:"en",formatNumber:(r,e)=>cl(r,fh,e)};function Re(r,e){if(r==null)return "";if(typeof r=="string")return r;if(!gl(r))return String(r);let t=r.values,n=xh(t?t:e,i=>Re(i));try{return cs(r.defaultMessage,n,j1)}catch{return r.defaultMessage}}function X(r,e,t){return (r??Ae()).t(e,t)}function lb(r,e){try{return r.toLocaleUpperCase(e)}catch{return r.toUpperCase()}}function qe(r,e){return Ht(r,us(e))}function Sh(r,e){if(e<=0)return "";if(/^[ -~]*$/.test(r))return r.slice(0,e);let t=Ch(void 0,"grapheme");if(t){let n="",i=0;for(let{segment:o}of t.segment(r)){if(i++>=e)break;n+=o;}return n}return Array.from(r).slice(0,e).join("")}var ab=new Map;function Ch(r,e){let t=`${""}|${e}`,n=ab.get(t);if(n===void 0){let i=Intl.Segmenter;try{n=i?new i(r,{granularity:e}):null;}catch{n=null;}ab.set(t,n);}return n}function cb(r,e){return `${r}#${e}`}var Zr=new Map;function gr(r){Zr.set(r.type,r);}function db(r){Zr.delete(r);}function ub(r,e){if(typeof r.title=="string"&&(r.shortTitle===void 0||typeof r.shortTitle=="string"))return r;let t={title:X(e,r.title)};return r.shortTitle!==void 0&&(t.shortTitle=X(e,r.shortTitle)),Object.assign(Object.create(r),t)}function hb(r,e){let t=Zr.get(r);return t?ub(t,e):void 0}function pb(){return [...Zr.keys()]}function mb(r){return [...Zr.values()].map(e=>ub(e,r))}function Th(r){return Zr.get(r)}function gb(){return [...Zr.values()]}var fl=class{constructor(e,t,n){this.feed=e;this.market=t;this.onBar=n;this.unsubscribe=null;}start(){this.unsubscribe||(this.unsubscribe=this.feed.subscribe(this.market,this.onBar));}stop(){this.unsubscribe?.(),this.unsubscribe=null;}};var Ki=class{constructor(e,t,n,i,o){this.controller=n;this.schema=[];this.propsSchema=[];this.visibleState=true;this.bus=new jr;this.id=e,this.title=t,i!==void 0&&(this.source=i),o!==void 0&&(this.nativeType=o);}get inputs(){return this.schema}get props(){return this.propsSchema}get visible(){return this.visibleState}inputValues(){return this.controller.inputValuesOf(this.id)}propValues(){return this.controller.propValuesOf(this.id)}setInput(e,t){this.controller.applyInputs(this.id,{[e]:t});}setInputs(e){this.controller.applyInputs(this.id,e);}setProp(e,t){this.controller.applyProps(this.id,{[e]:t});}setProps(e){this.controller.applyProps(this.id,e);}updateCode(e){return this.controller.updateCode(this.id,e)}setVisible(e){this.controller.setVisible(this.id,e);}moveTo(e){this.controller.moveIndicator(this.id,e);}on(e,t){return this.bus.on(e,t)}context(e){return this.controller.getIndicatorContext(this.id,e)}remove(){this.controller.removeIndicator(this.id);}setSchema(e){this.schema=e;}setPropsSchema(e){this.propsSchema=e;}setSource(e){this.source=e;}setVisibleState(e){this.visibleState=e;}emit(e,t){this.bus.emit(e,t);}};function q1(r){let e={};for(let i of r.series)e[i.kind]=(e[i.kind]??0)+1;let t=i=>i?.filter(o=>o.overlay===true).length??0,n=t(r.series)+t(r.fills)+t(r.backgrounds)+t(r.lines)+t(r.boxes)+t(r.labels)+t(r.polylines)+t(r.linefills)+t(r.tables);return {id:r.id,title:r.title,overlay:r.overlay,paneId:r.paneId,native:!!r.native,nativeType:r.native?.type,series:e,fills:r.fills.length,backgrounds:r.backgrounds.length,priceLines:r.priceLines.length,lines:r.lines?.length??0,boxes:r.boxes?.length??0,labels:r.labels?.length??0,polylines:r.polylines?.length??0,linefills:r.linefills?.length??0,tables:r.tables?.length??0,barColors:r.barColors?.length??0,trades:r.trades?.length??0,inputs:r.inputs.length,forcedOverlay:n}}function fb(r){let e=r.map(q1),t=n=>e.reduce((i,o)=>i+n(o),0);return {indicators:e,totals:{panes:new Set(e.map(n=>n.paneId??"price")).size,series:t(n=>Object.values(n.series).reduce((i,o)=>i+o,0)),fills:t(n=>n.fills),backgrounds:t(n=>n.backgrounds),priceLines:t(n=>n.priceLines),lines:t(n=>n.lines),boxes:t(n=>n.boxes),labels:t(n=>n.labels),polylines:t(n=>n.polylines),linefills:t(n=>n.linefills),tables:t(n=>n.tables),barColors:t(n=>n.barColors),trades:t(n=>n.trades),forcedOverlay:t(n=>n.forcedOverlay)}}}var Z1={"1D":864e5,"1W":6048e5,"1M":2592e6,"3M":7776e6,"6M":15552e6,"1Y":31536e6,"5Y":15768e7};function bb(r,e){if(e.length===0)return null;let t=e[0].time,n=e[e.length-1].time;if(r==="ALL")return {from:t,to:n};let i;return r==="YTD"?i=Date.UTC(new Date(n).getUTCFullYear(),0,1):i=n-Z1[r],{from:Math.max(t,i),to:n}}function c(r,e){return Object.freeze({id:r,defaultMessage:e})}function We(r,e){return Object.freeze({id:r.id,defaultMessage:r.defaultMessage,values:{...r.values,...e}})}var xt="#2962ff",Xi="#38c0fd",N="#089981",O="#f23645",R="#787b86",yb="#e0b400",q="#ff9800",be="#5b9cf6",wb="#ff5d00",bl="#0ecb81",vl="#f6465d",CH="#f97316",TH="#0ea5e9",kH="#9ca3af",hs="#3b82f6",xb="#9aa0ad",Sb="#1e293b",Cb="#475569",Tb="#595959",kb=xt,Lb=O,Mb="#d500f9",vb=[xt,N,O,q,"#7e57c2","#26a69a",be,"#e573b5"];function LH(r){let e=0;for(let t=0;t<r.length;t++)e=e*31+r.charCodeAt(t)>>>0;return vb[e%vb.length]}var H=Xi;function kh(){return {lineColor:H,lineWidth:2,lineStyle:"solid"}}function rn(r=""){return {value:r,size:"normal",hAlign:"left",vAlign:"top"}}var yl=6e4,Mh=60*yl,Lh=24*Mh,Wn=[{key:"s",label:c("drawing.showOn.seconds","Sec"),fromMs:0},{key:"1",label:c("drawing.showOn.minute1","1m"),fromMs:yl},{key:"5",label:c("drawing.showOn.minute5","5m"),fromMs:5*yl},{key:"15",label:c("drawing.showOn.minute15","15m"),fromMs:15*yl},{key:"60",label:c("drawing.showOn.hour1","1H"),fromMs:Mh},{key:"240",label:c("drawing.showOn.hour4","4H"),fromMs:4*Mh},{key:"D",label:c("drawing.showOn.day","D"),fromMs:Lh},{key:"W",label:c("drawing.showOn.week","W"),fromMs:7*Lh},{key:"M",label:c("drawing.showOn.month","M"),fromMs:28*Lh}],Q1=new Set(Wn.map(r=>r.key));function wl(r){if(!(r>0))return null;let e=null;for(let t of Wn)r>=t.fromMs&&(e=t.key);return e}function Eh(r,e){if(!r)return true;let t=wl(e);return t===null||r.includes(t)}function ps(r){if(!Array.isArray(r))return;let e=new Set(r.filter(t=>typeof t=="string"&&Q1.has(t)));return Wn.map(t=>t.key).filter(t=>e.has(t))}var xl=class xl{constructor(e){this.locked=false;this.visible=true;this.zIndex=0;this.id=e.id??`dw-${xl.seq+=1}`,this.paneId=e.paneId,this.anchors=(e.anchors??[]).map(t=>({time:t.time,price:t.price})),this.style=e.style?{...e.style}:kh(),this.text=e.text?{...e.text}:void 0,this.locked=e.locked??false,this.visible=e.visible??true,this.zIndex=e.zIndex??0,this.showOn=ps(e.showOn),this.createdAt=e.createdAt??Date.now(),e.props&&this.readProps(e.props);}isComplete(){return this.anchors.length>=this.anchorSchema().min}placementMode(){return "click"}onPlaced(e){}constrainHandleDrag(e){}translateBody(e,t,n){return n.map(i=>({time:i.time+e,price:i.price+t}))}timeExtent(){if(this.anchors.length===0)return null;let e=1/0,t=-1/0;for(let n of this.anchors)n.time<e&&(e=n.time),n.time>t&&(t=n.time);return {min:e,max:t}}placeholderText(){return null}editableLevels(){return null}applySettings(e){for(let[t,n]of Object.entries(e))t.startsWith("text.")&&!this.text&&(this.text=rn()),Eb(this,t,n);}applyProps(e){this.readProps(e);}serialize(){return {id:this.id,type:this.type,paneId:this.paneId,anchors:this.anchors.map(e=>({time:e.time,price:e.price})),style:{...this.style},text:this.text?{...this.text}:void 0,locked:this.locked,visible:this.visible,zIndex:this.zIndex,createdAt:this.createdAt,props:this.writeProps(),showOn:this.showOn?[...this.showOn]:void 0}}writeProps(){}readProps(e){}};xl.seq=0;var Z=xl;function Eb(r,e,t){let n=e.split("."),i=r;for(let o=0;o<n.length-1;o+=1){let s=n[o],a=i[s];(a==null||typeof a!="object")&&(a={},i[s]=a),i=a;}i[n[n.length-1]]=t;}var Ph=new Map;function z(r,e){Ph.set(r,e);}function ji(r){return Ph.get(r)??null}function ae(r){return Ph.get(r)??""}function Ge(r,e){return ae(r).replace("<svg ",`<svg width="${e}" height="${e}" `)}function Pb(r,e=""){return `<svg viewBox="0 0 16 16" width="1em" height="1em" ${e?e+" ":""}fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round">${r}</svg>`}function V(r,e=""){return `<svg viewBox="0 0 24 24" width="1em" height="1em" ${e?e+" ":""}fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${r}</svg>`}function Ih(r){return `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" stroke="none">${r}</svg>`}var Q=Pb;z("style-candles",Q('<path d="M4.5 2v2M4.5 12v2M11.5 2v1.5M11.5 11v3"/><rect x="2.8" y="4" width="3.4" height="8" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="3.5" width="3.4" height="7.5" rx="0.6" fill="currentColor"/>'));z("style-bars",Q('<path d="M4.5 2.5v11M2.5 5h2M4.5 11h2"/><path d="M11.5 2.5v11M9.5 4.5h2M11.5 10.5h2"/>'));z("style-line",Q('<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/>'));z("style-area",Q('<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/><path d="M1.5 11.5 5.5 7l3 2.5 5-6V13.5h-12z" fill="currentColor" fill-opacity="0.25" stroke="none"/>'));z("style-baseline",Q('<path d="M1.5 8h13" stroke-dasharray="2 2"/><path d="M2.5 8 5.25 4.5 8 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M2.5 8 5.25 4.5 8 8"/><path d="M8 8l2.75 3.5L13.5 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M8 8l2.75 3.5L13.5 8"/>'));z("style-heikinashi",Q('<path d="M4.5 12v2M11.5 2v2"/><rect x="2.8" y="5" width="3.4" height="7" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="4" width="3.4" height="7" rx="0.6" fill="currentColor"/>'));z("indicators",Q('<path d="M1.5 12.5 5 7l2.5 3.5L11 4l3.5 5"/><circle cx="11" cy="4" r="1.4" fill="currentColor" stroke="none"/>'));z("undo",Q('<path d="M6.2 9.5 2.7 6l3.5-3.5"/><path d="M2.7 6h6.8a3.65 3.65 0 0 1 0 7.3H7.5"/>'));z("redo",Q('<path d="M9.8 9.5 13.3 6 9.8 2.5"/><path d="M13.3 6H6.5a3.65 3.65 0 0 0 0 7.3h2"/>'));z("objects",Q('<path d="M8 1.8 14 5 8 8.2 2 5z"/><path d="M2 8l6 3.2L14 8" opacity="0.7"/><path d="M2 11l6 3.2 6-3.2" opacity="0.4"/>'));z("clock",Q('<circle cx="8" cy="8" r="6.2"/><path d="M8 4.8V8l2.4 1.6"/>'));z("calendar",Q('<rect x="2.2" y="3.2" width="11.6" height="10.6" rx="1.4"/><path d="M5.2 1.8v2.8M10.8 1.8v2.8M2.2 6.8h11.6"/>'));z("datawindow",Q('<rect x="1.8" y="2.5" width="12.4" height="11" rx="1.5"/><path d="M4.5 5.5h4M4.5 8h7M4.5 10.5h5.5"/>'));z("camera",Q('<path d="M5.5 4 6.5 2.5h3L10.5 4h3A1 1 0 0 1 14.5 5v7.5a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1z"/><circle cx="8" cy="8.5" r="2.6"/>'));z("gear",Q('<path d="M6.55 1.4h2.9l.32 1.72c.48.14.92.38 1.3.7l1.66-.55 1.45 2.5-1.35 1.1c.08.34.12.7.12 1.07s-.04.73-.12 1.07l1.35 1.1-1.45 2.5-1.66-.55a4.3 4.3 0 0 1-1.3.7L9.45 14.6h-2.9l-.32-1.72a4.3 4.3 0 0 1-1.3-.7l-1.66.55-1.45-2.5 1.35-1.1A4.4 4.4 0 0 1 3.05 7.94c0-.37.04-.73.12-1.07l-1.35-1.1 1.45-2.5 1.66.55c.38-.32.82-.56 1.3-.7L6.55 1.4z"/><circle cx="8" cy="8" r="2.2"/>'));z("search",Q('<circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3.5 3.5"/>'));z("bell",Q('<path d="M8 2a4 4 0 0 0-4 4v2.5L2.5 11v1h11v-1L12 8.5V6a4 4 0 0 0-4-4z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/>'));z("market-open",V('<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>'));z("market-pre",V('<path d="M12 2v8"/><path d="m4.93 10.93 1.41 1.41"/><path d="M2 18h2"/><path d="M20 18h2"/><path d="m19.07 10.93-1.41 1.41"/><path d="M22 22H2"/><path d="m8 6 4-4 4 4"/><path d="M16 18a4 4 0 0 0-8 0"/>'));z("market-post",V('<path d="M12 10V2"/><path d="m4.93 10.93 1.41 1.41"/><path d="M2 18h2"/><path d="M20 18h2"/><path d="m19.07 10.93-1.41 1.41"/><path d="M22 22H2"/><path d="m16 14-4 4-4-4"/><path d="M16 6a4 4 0 0 0-8 0"/>'));z("market-extended",V('<path d="M22 22H2"/><path d="M12 3a5 5 0 0 0 7.5 7.5A7.5 7.5 0 1 1 12 3Z"/>'));z("market-closed",V('<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>'));z("market-holiday",V('<path d="m10 20-1.25-2.5L6 16"/><path d="M10 4 8.75 6.5 6 8"/><path d="m14 20 1.25-2.5L18 16"/><path d="m14 4 1.25 2.5L18 8"/><path d="m17 10-5 5-5-5"/><path d="M4 12h16"/>'));z("chevron-right",Q('<path d="m6 3.5 4.5 4.5L6 12.5"/>'));z("chevron-left",Q('<path d="M10 3.5 5.5 8l4.5 4.5"/>'));z("chevron-down",Q('<path d="M3.5 6 8 10.5 12.5 6"/>'));z("chevron-up",Q('<path d="M3.5 10 8 5.5 12.5 10"/>'));z("chevrons-right",Q('<path d="m4 3.5 4.5 4.5L4 12.5"/><path d="m8.5 3.5 4.5 4.5-4.5 4.5"/>'));z("chevrons-left",Q('<path d="M12 3.5 7.5 8l4.5 4.5"/><path d="M7.5 3.5 3 8l4.5 4.5"/>'));z("replay",Q('<path d="M14 4.2v7.6L8.6 8z"/><path d="M7.4 4.2v7.6L2 8z"/>'));z("check",Q('<path d="m2.8 8.4 3.4 3.4 7-7.6"/>'));z("close",Q('<path d="m3.8 3.8 8.4 8.4M12.2 3.8l-8.4 8.4"/>'));z("pin",Q('<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/>'));z("pin-filled",Q('<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/><path d="M6.4 2.5h3.2v3.6l2 2.3v.9H4.4v-.9l2-2.3z" fill="currentColor" stroke="none"/>'));z("eye",Q('<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="1.8"/>'));z("eye-off",Q('<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z" opacity="0.45"/><path d="m3 13 10-10"/>'));z("lock",Q('<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.8 0V7"/>'));z("unlock",Q('<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.7-.7"/>'));z("trash",Q('<path d="M2.5 4.3h11M6.2 4.3V3.1a1 1 0 0 1 1-1h1.6a1 1 0 0 1 1 1v1.2M4.2 4.3l.5 9.1a1.15 1.15 0 0 0 1.15 1.1h4.3a1.15 1.15 0 0 0 1.15-1.1l.5-9.1M6.5 7v4.5M9.5 7v4.5"/>'));z("group",Q('<path d="M1.8 4.5V2.4a.6.6 0 0 1 .6-.6h2.1M11.5 1.8h2.1a.6.6 0 0 1 .6.6v2.1M14.2 11.5v2.1a.6.6 0 0 1-.6.6h-2.1M4.5 14.2H2.4a.6.6 0 0 1-.6-.6v-2.1"/><rect x="4" y="4" width="4.2" height="4.2" rx="0.7"/><rect x="7.8" y="7.8" width="4.2" height="4.2" rx="0.7"/>'));z("ungroup",Q('<rect x="1.6" y="1.6" width="6.2" height="6.2" rx="0.9"/><rect x="8.2" y="8.2" width="6.2" height="6.2" rx="0.9" stroke-dasharray="2 1.5"/>'));z("clone",Q('<rect x="5.5" y="5.5" width="9" height="9" rx="1.2"/><path d="M11 5.5v-3a1 1 0 0 0-1-1H2.5a1 1 0 0 0-1 1V10a1 1 0 0 0 1 1h3"/>'));z("arrow-up",Q('<path d="M8 13.2V3M4.2 6.8 8 3l3.8 3.8"/>'));z("arrow-down",Q('<path d="M8 2.8V13M4.2 9.2 8 13l3.8-3.8"/>'));z("move-vertical",Q('<path d="M8 2.5v11M5 5.5 8 2.5l3 3M5 10.5l3 3 3-3"/>'));z("move",Q('<path d="M8 1.8v12.4M1.8 8h12.4M5.6 4.2 8 1.8l2.4 2.4M5.6 11.8 8 14.2l2.4-2.4M4.2 5.6 1.8 8l2.4 2.4M11.8 5.6 14.2 8l-2.4 2.4"/>'));z("pen",Q('<path d="m10.8 2.2 3 3-8 8-3.6.6.6-3.6z"/><path d="m9.2 3.8 3 3"/>'));z("wave",Q('<path d="M1.5 10.4c1.6 0 1.9-4.8 3.4-4.8s1.8 4.8 3.4 4.8 1.8-4.8 3.4-4.8 1.6 4.8 2.8 4.8"/>'));z("folder-plus",Q('<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M8 7.6v3.6M6.2 9.4h3.6"/>'));z("folder-minus",Q('<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M6.2 9.4h3.6"/>'));z("collapse",Q('<path d="M3 8h10"/>'));z("expand",Q('<rect x="2.2" y="2.2" width="11.6" height="11.6" rx="1.4"/><path d="M8 5.4v5.2M5.4 8h5.2"/>'));z("plus",Q('<path d="M8 2.8v10.4M2.8 8h10.4"/>'));z("minus",Q('<path d="M2.8 8h10.4"/>'));z("maximize",Q('<path d="M2.5 6V3a.5.5 0 0 1 .5-.5h3M10 2.5h3a.5.5 0 0 1 .5.5v3M13.5 10v3a.5.5 0 0 1-.5.5h-3M6 13.5H3a.5.5 0 0 1-.5-.5v-3"/>'));z("restore",Q('<path d="M6 2.5v3a.5.5 0 0 1-.5.5h-3M13.5 6h-3a.5.5 0 0 1-.5-.5v-3M10 13.5v-3a.5.5 0 0 1 .5-.5h3M2.5 10h3a.5.5 0 0 1 .5.5v3"/>'));z("restore",Q('<path d="M6.2 2.5v3.7H2.5M9.8 13.5V9.8h3.7M13.5 6.2H9.8V2.5M2.5 9.8h3.7v3.7"/>'));z("star",Q('<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>'));z("star-filled",Q('<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>','fill="currentColor"'));z("grip",Q('<circle cx="6" cy="3.5" r="1"/><circle cx="10" cy="3.5" r="1"/><circle cx="6" cy="8" r="1"/><circle cx="10" cy="8" r="1"/><circle cx="6" cy="12.5" r="1"/><circle cx="10" cy="12.5" r="1"/>','fill="currentColor" stroke="none"'));z("kebab",Q('<circle cx="8" cy="3.2" r="1.2"/><circle cx="8" cy="8" r="1.2"/><circle cx="8" cy="12.8" r="1.2"/>','fill="currentColor" stroke="none"'));z("burger",Q('<path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/>'));z("info",Q('<path d="M8 7.4v4.4"/><circle cx="8" cy="4.6" r="0.9" fill="currentColor" stroke="none"/>'));z("reset",Q('<path d="M2 8a6 6 0 1 0 6-6 6.5 6.5 0 0 0-4.5 1.83L2 5.33"/><path d="M2 2v3.33h3.33"/>'));z("pane-collapse",Q('<path d="M2.6 9.4h4v4M13.4 6.6h-4v-4"/><path d="m9.4 6.6 4.2-4.2M2.4 13.6l4.2-4.2"/>'));z("pane-expand",Q('<path d="M9.8 2.4h3.8v3.8M6.2 13.6H2.4V9.8"/><path d="m13.6 2.4-4.4 4.4M2.4 13.6l4.4-4.4"/>'));z("cursor",V('<path d="M5 3l6 16 2-6 6-2z"/>','fill="currentColor" stroke="none"'));z("ruler",V('<path d="M21.3 15.3 8.7 2.7a1 1 0 0 0-1.4 0L2.7 7.3a1 1 0 0 0 0 1.4l12.6 12.6a1 1 0 0 0 1.4 0l4.6-4.6a1 1 0 0 0 0-1.4Z"/><path d="m7.5 10.5 2 2"/><path d="m10.5 7.5 2 2"/><path d="m13.5 4.5 2 2"/><path d="m4.5 13.5 2 2"/>'));z("magnet",V('<path d="m6 15-4-4 6.75-6.77a7.79 7.79 0 0 1 11 11L13 22l-4-4 6.39-6.36a2.14 2.14 0 0 0-3-3L6 15"/><path d="m5 8 4 4"/><path d="m12 15 4 4"/>'));z("eraser",V('<path d="m7 21-4.3-4.3a1 1 0 0 1 0-1.4L13 5a2 2 0 0 1 2.8 0l4.2 4.2a2 2 0 0 1 0 2.8L12 20"/><path d="M22 21H7"/><path d="m5 11 9 9"/>'));z("pen-lock",V('<path d="M13.8 4.2a2.1 2.1 0 0 1 3 3L8.5 15.5l-3.5 1 1-3.5Z"/><rect x="13" y="14.5" width="8" height="6" rx="1.2"/><path d="M15 14.5v-1.6a2 2 0 0 1 4 0v1.6"/>'));z("pen-sync",V('<path d="M13.8 4.2a2.1 2.1 0 0 1 3 3L8.5 15.5l-3.5 1 1-3.5Z"/><rect x="12.5" y="13.5" width="6" height="4.8" rx="1"/><path d="M15.5 18.3v1a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-2.8a1 1 0 0 0-1-1h-1"/>'));z("brush",V('<path d="M9.5 12 17 4.5a2.12 2.12 0 0 1 3 3L12.5 15"/><path d="M7 14a3 3 0 0 0-3 3c0 1.3-1.2 1.5-1.5 2 .8.9 2 1.5 3.5 1.5a3.5 3.5 0 0 0 3.5-3.5 3 3 0 0 0-2.5-3Z"/>'));z("bucket",V('<path d="m18.5 11.5-7-7L4 12a1.8 1.8 0 0 0 0 2.5l5 5a1.8 1.8 0 0 0 2.5 0Z"/><path d="m5 5 4 4"/><path d="M3.5 13.5h13"/><path d="M21 17.5c0 1.1-.9 2-2 2s-2-.9-2-2c0-1 1.2-1.7 2-3 .8 1.3 2 2 2 3Z"/>'));z("type",V('<path d="M5 6V4.5h14V6"/><path d="M12 4.5v15"/><path d="M9.5 19.5h5"/>'));z("bold",V('<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7Z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7Z"/>','stroke-width="2.4"'));z("italic",V('<path d="M15 5h-5M14 19H9M14.5 5 10 19"/>','stroke-width="2.2"'));z("price-delta",V('<path d="M12 4v16"/><path d="M8 8l4-4 4 4"/><path d="M8 16l4 4 4-4"/>'));z("date-delta",V('<path d="M4 12h16"/><path d="M8 8l-4 4 4 4"/><path d="M16 8l4 4-4 4"/>'));z("bring-front",V('<rect x="8.5" y="8.5" width="7" height="7" rx="1.5"/><path d="M4.5 10.5V6a1.5 1.5 0 0 1 1.5-1.5h4.5"/><path d="M19.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5h-4.5"/>'));z("send-back",V('<rect x="8.5" y="8.5" width="7" height="7" rx="1.5" fill="currentColor" stroke="none" opacity="0.35"/><path d="M4.5 10.5V6a1.5 1.5 0 0 1 1.5-1.5h4.5"/><path d="M19.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5h-4.5"/><rect x="8.5" y="8.5" width="7" height="7" rx="1.5"/>'));z("r-squared",'<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" stroke="none"><text x="2.5" y="17.5" font-size="14" font-family="serif">R\xB2</text></svg>');z("bands",V('<path d="M3 6h18"/><path d="M3 18h18"/><path d="M3 12h18" stroke-dasharray="3 3"/>'));z("dedekind",V('<path d="M2 20h20"/><path d="M4 20a8 8 0 0 1 16 0"/><path d="M8 20a4 4 0 0 1 8 0"/><path d="M12 4v16"/>'));z("sonic",V('<circle cx="15" cy="12" r="4"/><circle cx="12" cy="12" r="2.5"/><path d="M8 5v14"/>'));z("supersonic",V('<circle cx="16" cy="12" r="3.5"/><path d="M6 12 15 6M6 12 15 18"/>'));var tt=[{value:"solid",label:c("drawing.option.solid","Solid")},{value:"dashed",label:c("drawing.option.dashed","Dashed")},{value:"dotted",label:c("drawing.option.dotted","Dotted")}],K=[{path:"style.lineColor",label:c("drawing.field.lineColor","Line color"),kind:"color",group:"line"},{path:"style.lineWidth",label:c("drawing.field.lineWidth","Line width"),kind:"number",min:1,max:10,step:1,group:"line"},{path:"style.lineStyle",label:c("drawing.field.lineStyle","Line style"),kind:"lineStyle",options:tt,group:"line"}],fr=[{path:"style.lineColor",label:c("drawing.field.borderColor","Border color"),kind:"color",group:"line"},{path:"style.lineWidth",label:c("drawing.field.borderWidth","Border width"),kind:"number",min:1,max:10,step:1,group:"line"},{path:"style.lineStyle",label:c("drawing.field.borderStyle","Border style"),kind:"lineStyle",options:tt,group:"line"}],Ce=[{path:"style.fillColor",label:c("drawing.field.fillColor","Fill color"),kind:"color",group:"fill"}],St=[{value:"small",label:c("drawing.option.small","Small")},{value:"normal",label:c("drawing.option.normal","Normal")},{value:"large",label:c("drawing.option.large","Large")},{value:"huge",label:c("drawing.option.huge","Huge")}],Y=[{path:"text.value",label:c("drawing.field.text","Text"),kind:"text",group:"text"},{path:"text.color",label:c("drawing.field.textColor","Text color"),kind:"color",group:"text"},{path:"text.size",label:c("drawing.field.textSize","Text size"),kind:"select",options:St,group:"text"},{path:"text.bold",label:c("drawing.field.bold","Bold"),kind:"boolean",group:"text"},{path:"text.italic",label:c("drawing.field.italic","Italic"),kind:"boolean",group:"text"}];function fe(r,e,t,n,i,o){let s=i-t,a=o-n,l=s*s+a*a;if(l<=1e-9)return Math.hypot(r-t,e-n);let d=((r-t)*s+(e-n)*a)/l;return d=d<0?0:d>1?1:d,Math.hypot(r-(t+d*s),e-(n+d*a))}function qi(r,e,t){let n=1/0;for(let i=1;i<t.length;i+=1){let o=t[i-1],s=t[i],a=fe(r,e,o[0],o[1],s[0],s[1]);a<n&&(n=a);}return n}function lt(r,e,t,n,i,o,s=0){let a=Math.min(t,i)-s,l=Math.max(t,i)+s,d=Math.min(n,o)-s,u=Math.max(n,o)+s;return r>=a&&r<=l&&e>=d&&e<=u}function wn(r,e,t){let n=false;for(let i=0,o=t.length-1;i<t.length;o=i,i+=1){let s=t[i],a=t[o];s[1]>e!=a[1]>e&&r<(a[0]-s[0])*(e-s[1])/(a[1]-s[1])+s[0]&&(n=!n);}return n}function Ah(r,e,t,n,i,o,s,a){let l=t-r,d=n-e,u=s-i,h=a-o,p=u*d-h*l;if(Math.abs(p)<1e-9)return null;let m=((o-e)*l-(i-r)*d)/p;return m<0||m>1?null:[i+m*u,o+m*h]}function ee(r,e,t,n=6){for(let i=0;i<t.length;i+=1){let o=t[i];if(Math.hypot(r-o[0],e-o[1])<=n)return i}return -1}function Oe(r,e,t,n,i,o,s){if(i==="none")return [r,e,t,n];let a=t-r,l=i==="left"||i==="both",d=i==="right"||i==="both";if(Math.abs(a)<1e-6){if(l&&d)return [r,0,t,s];let g=n>=e;return d?g?[r,e,t,s]:[r,e,t,0]:g?[r,0,t,n]:[r,s,t,n]}let u=(n-e)/a,h=g=>e+u*(g-r),p=l?-2:Math.min(r,t),m=d?o+2:Math.max(r,t);return [p,h(p),m,h(m)]}var Qr=class extends Z{constructor(){super(...arguments);this.type="trendline";}anchorSchema(){return {min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?null:[t.xOf(n.time),o,t.xOf(i.time),s]}extension(){let{extendLeft:t,extendRight:n}=this.style;return t&&n?"both":t?"left":n?"right":"none"}hitTest(t,n,i,o){let s=this.pixels(i);if(!s)return false;let[a,l,d,u]=Oe(s[0],s[1],s[2],s[3],this.extension(),i.width,i.height);return fe(t,n,a,l,d,u)<=o}handlePoints(t){let n=this.pixels(t);return n?[[n[0],n[1]],[n[2],n[3]]]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.pixels(t);if(!n)return null;let i=Math.min(n[0],n[2]),o=Math.min(n[1],n[3]);return {x:i,y:o,w:Math.abs(n[2]-n[0]),h:Math.abs(n[3]-n[1])}}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,{path:"style.arrowRight",label:c("drawing.trendline.arrowRight","Arrow"),kind:"boolean",group:"line"},{path:"style.extendLeft",label:c("drawing.trendline.extendLeft","Extend left"),kind:"boolean",group:"line"},{path:"style.extendRight",label:c("drawing.trendline.extendRight","Extend right"),kind:"boolean",group:"line"},...Y]}}};var Sl=class extends Z{constructor(){super(...arguments);this.type="hline";}anchorSchema(){return {min:1,max:1,slots:[{role:"p",free:"y"}]}}y(t){let n=this.anchors[0];return n?t.yOf(n.price,this.paneId):null}hitTest(t,n,i,o){let s=this.y(i);return s!=null&&Math.abs(n-s)<=o}handlePoints(t){let n=this.anchors[0],i=this.y(t);return !n||i==null?[]:[[t.xOf(n.time),i]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.y(t);return n==null?null:{x:0,y:n-1,w:t.width,h:2}}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}timeExtent(){return null}schema(){return {fields:[...K,...Y]}}};var Cl=class extends Z{constructor(){super(...arguments);this.type="ray";}anchorSchema(){return {min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?null:[t.xOf(n.time),o,t.xOf(i.time),s]}hitTest(t,n,i,o){let s=this.pixels(i);if(!s)return false;let[a,l,d,u]=Oe(s[0],s[1],s[2],s[3],"right",i.width,i.height);return fe(t,n,a,l,d,u)<=o}handlePoints(t){let n=this.pixels(t);return n?[[n[0],n[1]],[n[2],n[3]]]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.pixels(t);return n?{x:Math.min(n[0],n[2]),y:Math.min(n[1],n[3]),w:Math.abs(n[2]-n[0]),h:Math.abs(n[3]-n[1])}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,...Y]}}};var br=class extends Z{anchorSchema(){return {min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=e.yOf(t.price,this.paneId),o=e.yOf(n.price,this.paneId);return i==null||o==null?null:[e.xOf(t.time),i,e.xOf(n.time),o]}hitTest(e,t,n,i){let o=this.pixels(n);return o!=null&&fe(e,t,o[0],o[1],o[2],o[3])<=i}handlePoints(e){let t=this.pixels(e);return t?[[t[0],t[1]],[t[2],t[3]]]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.pixels(e);return t?{x:Math.min(t[0],t[2]),y:Math.min(t[1],t[3]),w:Math.abs(t[2]-t[0]),h:Math.abs(t[3]-t[1])}:null}priceRange(){let e=this.anchors[0],t=this.anchors[1];return !e||!t?null:{min:Math.min(e.price,t.price),max:Math.max(e.price,t.price)}}schema(){return {fields:[...K,...Y]}}};var Tl=class extends br{constructor(){super(...arguments);this.type="extendedline";}hitTest(t,n,i,o){let s=this.pixels(i);if(!s)return false;let[a,l,d,u]=Oe(s[0],s[1],s[2],s[3],"both",i.width,i.height);return fe(t,n,a,l,d,u)<=o}timeExtent(){return null}};var kl=class extends Z{constructor(){super(...arguments);this.type="vline";}anchorSchema(){return {min:1,max:1,slots:[{role:"p",free:"x"}]}}x(t){let n=this.anchors[0];return n?t.xOf(n.time):null}hitTest(t,n,i,o){let s=this.x(i);return s!=null&&Math.abs(t-s)<=o}handlePoints(t){let n=this.anchors[0],i=this.x(t);if(!n||i==null)return [];let o=t.yOf(n.price,this.paneId);return o==null?[]:[[i,o]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.x(t);return n==null?null:{x:n-1,y:0,w:2,h:t.height}}priceRange(){return null}schema(){return {fields:[...K,...Y]}}};var Ll=class extends Z{constructor(){super(...arguments);this.type="hray";}anchorSchema(){return {min:1,max:1,slots:[{role:"p",free:"both"}]}}pt(t){let n=this.anchors[0];if(!n)return null;let i=t.yOf(n.price,this.paneId);return i==null?null:[t.xOf(n.time),i]}hitTest(t,n,i,o){let s=this.pt(i);return s!=null&&fe(t,n,s[0],s[1],i.width,s[1])<=o}handlePoints(t){let n=this.pt(t);return n?[n]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.pt(t);return n?{x:n[0],y:n[1]-1,w:Math.max(0,t.width-n[0]),h:2}:null}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}timeExtent(){let t=this.anchors[0];return t?{min:t.time,max:Number.POSITIVE_INFINITY}:null}schema(){return {fields:[...K,...Y]}}};var Ml=class extends Z{constructor(){super(...arguments);this.type="crossline";}anchorSchema(){return {min:1,max:1,slots:[{role:"p",free:"both"}]}}pt(t){let n=this.anchors[0];if(!n)return null;let i=t.yOf(n.price,this.paneId);return i==null?null:[t.xOf(n.time),i]}hitTest(t,n,i,o){let s=this.pt(i);return s!=null&&(Math.abs(n-s[1])<=o||Math.abs(t-s[0])<=o)}handlePoints(t){let n=this.pt(t);return n?[n]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.pt(t);return n?{x:n[0]-1,y:n[1]-1,w:2,h:2}:null}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}timeExtent(){return null}schema(){return {fields:[...K,...Y]}}};var El=class extends br{constructor(){super(...arguments);this.type="infoline";}};var Pl=class extends br{constructor(){super(...arguments);this.type="trendangle";}};var Il=class extends Z{constructor(){super(...arguments);this.type="box";}anchorSchema(){return {min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}rect(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?null:{x1:t.xOf(n.time),y1:o,x2:t.xOf(i.time),y2:s}}hitTest(t,n,i,o){let s=this.rect(i);return s?this.style.fillColor&&lt(t,n,s.x1,s.y1,s.x2,s.y2)?true:[[s.x1,s.y1,s.x2,s.y1],[s.x2,s.y1,s.x2,s.y2],[s.x2,s.y2,s.x1,s.y2],[s.x1,s.y2,s.x1,s.y1]].some(l=>fe(t,n,l[0],l[1],l[2],l[3])<=o):false}handlePoints(t){let n=this.rect(t);return n?[[n.x1,n.y1],[n.x2,n.y2]]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.rect(t);return n?{x:Math.min(n.x1,n.x2),y:Math.min(n.y1,n.y2),w:Math.abs(n.x2-n.x1),h:Math.abs(n.y2-n.y1)}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...fr,{path:"style.fillColor",label:c("drawing.box.fillColor","Fill color"),kind:"color",group:"fill"},...Y]}}};var J1={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},vr=class extends Z{defaultLabel(){return c("drawing.text.placeholder","Text")}placeholderText(){return this.defaultLabel()}labelText(){return this.text?.value??Re(this.defaultLabel())}anchorSchema(){return {min:1,max:1,slots:[{role:"p",free:"both"}]}}box(e){let t=this.anchors[0];if(!t)return null;let n=e.yOf(t.price,this.paneId);if(n==null)return null;let i=J1[this.text?.size??"normal"]??14,o=this.labelText().split(`
2
2
  `),s=Math.max(1,...o.map(a=>a.length));return {x:e.xOf(t.time),y:n,w:Math.max(12,s*i*.6)+8,h:o.length*i*1.4+4}}hitTest(e,t,n,i){let o=this.box(n);return o!=null&&lt(e,t,o.x,o.y,o.x+o.w,o.y+o.h)}handlePoints(e){let t=this.anchors[0],n=t?e.yOf(t.price,this.paneId):null;return t&&n!=null?[[e.xOf(t.time),n]]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){return this.box(e)}priceRange(){let e=this.anchors[0];return e?{min:e.price,max:e.price}:null}};var Gn=class extends vr{constructor(t){super(t);this.type="text";this.text||(this.text={...rn(),size:"large"});}schema(){return {fields:[...Y],textIsContent:true}}};var Jr=class extends vr{constructor(t){super(t);this.type="note";this.text||(this.text=rn(Re(this.defaultLabel())));}defaultLabel(){return c("drawing.note.placeholder","Note")}schema(){return {fields:[...K,...Ce,...Y],textIsContent:true}}};var ei=class extends vr{constructor(){super(...arguments);this.type="pricelabel";}labelText(){let t=this.anchors[0]?.price;return t==null?"0.00":t.toFixed(2)}schema(){return {fields:[...K,...Ce,...Y.filter(t=>t.path!=="text.value")]}}};var eL={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},Ut=class extends Z{constructor(e){super(e),this.text||(this.text=rn(Re(this.defaultLabel())));}defaultLabel(){return c("drawing.callout.placeholder","Callout")}placeholderText(){let e=this.defaultLabel();return Re(e)===""?null:e}labelText(){return this.text?.value??Re(this.defaultLabel())}anchorSchema(){return {min:2,max:2,slots:[{role:"target",free:"both"},{role:"box",free:"both"}]}}box(e){let t=this.anchors[1];if(!t)return null;let n=e.yOf(t.price,this.paneId);if(n==null)return null;let i=eL[this.text?.size??"normal"]??14,o=this.labelText().split(`
3
- `),s=Math.max(1,...o.map(d=>d.length)),a=Math.max(20,s*i*.6)+16,l=o.length*i*1.4+12;return {x:e.xOf(t.time)-a/2,y:n-l/2,w:a,h:l}}points(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=e.yOf(t.price,this.paneId),o=e.yOf(n.price,this.paneId);return i==null||o==null?null:[[e.xOf(t.time),i],[e.xOf(n.time),o]]}hitTest(e,t,n,i){let o=this.box(n);if(o&&lt(e,t,o.x,o.y,o.x+o.w,o.y+o.h,i))return true;let s=this.points(n);return s!=null&&fe(e,t,s[0][0],s[0][1],s[1][0],s[1][1])<=i}handlePoints(e){let t=this.points(e);return t?[t[0]]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}translateBody(e,t,n){let i=n[0],o=n[1];return !i||!o?n.map(s=>({time:s.time+e,price:s.price+t})):[{time:i.time,price:i.price},{time:o.time+e,price:o.price+t}]}bounds(e){return this.box(e)}priceRange(){let e=this.anchors[0],t=this.anchors[1];return !e||!t?null:{min:Math.min(e.price,t.price),max:Math.max(e.price,t.price)}}schema(){return {fields:[...K,...Ce,...Y],textIsContent:true}}};var xn=class extends Ut{constructor(){super(...arguments);this.type="callout";}};var ti=class extends Ut{constructor(){super(...arguments);this.type="pricenote";}defaultLabel(){return ""}labelText(){let t=this.anchors[0]?.price;return t==null?"0.00":t.toFixed(2)}schema(){return {fields:[...K,...Ce,...Y.filter(t=>t.path!=="text.value")]}}};var ni=class extends Ut{constructor(){super(...arguments);this.type="comment";}defaultLabel(){return c("drawing.comment.placeholder","Comment")}};var ri=class extends Ut{constructor(){super(...arguments);this.type="signpost";}defaultLabel(){return c("drawing.signpost.placeholder","Signpost")}};var Le=class extends Z{hitTest(e,t,n,i){let o=this.geometry(n);return o?this.style.fillColor&&o.fill&&wn(e,t,o.fill)?true:o.segments.some(s=>fe(e,t,s[0],s[1],s[2],s[3])<=i):false}handlePoints(e){let t=[];for(let n of this.anchors){let i=e.yOf(n.price,this.paneId);if(i==null)return [];t.push([e.xOf(n.time),i]);}return t}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.handlePoints(e);if(t.length===0)return null;let n=t.map(a=>a[0]),i=t.map(a=>a[1]),o=Math.min(...n),s=Math.min(...i);return {x:o,y:s,w:Math.max(...n)-o,h:Math.max(...i)-s}}};var Al=class extends Le{constructor(){super(...arguments);this.type="parallelchannel";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"offset",free:"y"}]}}offset(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[2];return !t||!n||!i?0:i.price-(t.price+n.price)/2}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return [];let a=[[t.xOf(n.time),o],[t.xOf(i.time),s]],l=this.anchors[2];if(l){let d=t.yOf(l.price,this.paneId);d!=null&&a.push([t.xOf((n.time+i.time)/2),d]);}return a}timeExtent(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.time,n.time),max:Math.max(t.time,n.time)}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=this.offset(),s=t.xOf(n.time),a=t.xOf(i.time),l=t.yOf(n.price,this.paneId),d=t.yOf(i.price,this.paneId),u=t.yOf(n.price+o,this.paneId),h=t.yOf(i.price+o,this.paneId);return l==null||d==null||u==null||h==null?null:{segments:[[s,l,a,d],[s,u,a,h]],fill:[[s,l],[a,d],[a,h],[s,u]]}}priceRange(){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=this.offset(),o=[t.price,n.price,t.price+i,n.price+i],s=this.anchors[2];return s&&o.push(s.price),{min:Math.min(...o),max:Math.max(...o)}}schema(){return {fields:[...K,...Ce,...Y]}}};var Rl=class extends Le{constructor(){super(...arguments);this.type="disjointchannel";}anchorSchema(){return {min:4,max:4,slots:[{role:"top1",free:"both"},{role:"top2",free:"both"},{role:"bot1",free:"both"},{role:"bot2",free:"both"}]}}seg(t,n,i){let o=this.anchors[t],s=this.anchors[n];if(!o||!s)return null;let a=i.yOf(o.price,this.paneId),l=i.yOf(s.price,this.paneId);return a==null||l==null?null:[i.xOf(o.time),a,i.xOf(s.time),l]}geometry(t){let n=this.seg(0,1,t),i=this.seg(2,3,t),o=[n,i].filter(a=>a!=null);if(o.length===0)return null;let s=n&&i?[[n[0],n[1]],[n[2],n[3]],[i[2],i[3]],[i[0],i[1]]]:null;return {segments:o,fill:s}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Ce,...Y]}}};var Dl=class extends Le{constructor(){super(...arguments);this.type="flattopbottom";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"flat",free:"y"}]}}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return [];let a=[[t.xOf(n.time),o],[t.xOf(i.time),s]],l=this.anchors[2];if(l){let d=t.yOf(l.price,this.paneId);d!=null&&a.push([t.xOf((n.time+i.time)/2),d]);}return a}timeExtent(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.time,n.time),max:Math.max(t.time,n.time)}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.xOf(n.time),s=t.xOf(i.time),a=t.yOf(n.price,this.paneId),l=t.yOf(i.price,this.paneId);if(a==null||l==null)return null;let d=this.anchors[2];if(!d)return {segments:[[o,a,s,l]],fill:null};let u=t.yOf(d.price,this.paneId);return u==null?null:{segments:[[o,a,s,l],[o,u,s,u]],fill:[[o,a],[s,l],[s,u],[o,u]]}}priceRange(){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=[t.price,n.price],o=this.anchors[2];return o&&i.push(o.price),{min:Math.min(...i),max:Math.max(...i)}}schema(){return {fields:[...K,...Ce,...Y]}}};var tL=2;function Ib(){return {midColor:R,midStyle:"solid",upperColor:N,upperStyle:"solid",lowerColor:O,lowerStyle:"solid",upperFill:`${N}26`,lowerFill:`${O}26`,showR2:true}}function Ab(r){let e=r.length;if(e<2)return null;let t=0,n=0,i=0,o=0,s=0;for(let g=0;g<e;g+=1){let b=r[g].close;t+=g,n+=b,i+=g*b,o+=g*g,s+=b*b;}let a=e*o-t*t,l=a===0?0:(e*i-t*n)/a,d=(n-l*t)/e,u=0;for(let g=0;g<e;g+=1){let b=r[g].close-(d+l*g);u+=b*b;}let h=Math.sqrt(u/e),p=Math.sqrt(a*(e*s-n*n)),m=p===0?0:(e*i-t*n)/p;return {t0:r[0].time,t1:r[e-1].time,mid0:d,mid1:d+l*(e-1),dev:tL*h,r2:Math.max(0,Math.min(1,m*m)),n:e}}var Un=class extends Z{constructor(t){super(t);this.type="regressionchannel";this.cachedRange=null;this.reg||(this.reg=Ib());}anchorSchema(){return {min:2,max:2,slots:[{role:"start",free:"x"},{role:"end",free:"x"}]}}fit(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=Math.min(n.time,i.time),s=Math.max(n.time,i.time),a=t.barsInRange?.(o,s)??null,l=a?Ab(a):null;return l&&(this.cachedRange={min:Math.min(l.mid0,l.mid1)-l.dev,max:Math.max(l.mid0,l.mid1)+l.dev}),l}layout(t){let n=this.fit(t);if(!n)return null;let i=t.yOf(n.mid0,this.paneId),o=t.yOf(n.mid1,this.paneId),s=t.yOf(n.mid0+n.dev,this.paneId),a=t.yOf(n.mid1+n.dev,this.paneId),l=t.yOf(n.mid0-n.dev,this.paneId),d=t.yOf(n.mid1-n.dev,this.paneId);return i==null||o==null||s==null||a==null||l==null||d==null?null:{x0:t.xOf(n.t0),x1:t.xOf(n.t1),midY0:i,midY1:o,upperY0:s,upperY1:a,lowerY0:l,lowerY1:d,r2:n.r2,showR2:this.reg.showR2}}band(t){let n=this.layout(t);return n?[[n.x0,n.upperY0],[n.x1,n.upperY1],[n.x1,n.lowerY1],[n.x0,n.lowerY0]]:null}hitTest(t,n,i,o){let s=this.layout(i);if(!s)return false;let a=[[s.x0,s.upperY0],[s.x1,s.upperY1],[s.x1,s.lowerY1],[s.x0,s.lowerY0]];return wn(t,n,a)?true:[[s.x0,s.midY0,s.x1,s.midY1],[s.x0,s.upperY0,s.x1,s.upperY1],[s.x0,s.lowerY0,s.x1,s.lowerY1]].some(d=>fe(t,n,d[0],d[1],d[2],d[3])<=o)}handlePoints(t){let n=this.layout(t);if(n)return [[n.x0,n.midY0],[n.x1,n.midY1]];let i=[];for(let o of this.anchors){let s=t.yOf(o.price,this.paneId);if(s==null)return [];i.push([t.xOf(o.time),s]);}return i}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.band(t);if(!n)return null;let i=n.map(l=>l[0]),o=n.map(l=>l[1]),s=Math.min(...i),a=Math.min(...o);return {x:s,y:a,w:Math.max(...i)-s,h:Math.max(...o)-a}}priceRange(){if(this.cachedRange)return this.cachedRange;let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[{path:"reg.midColor",label:c("drawing.regressionchannel.regMidColor","Midline color"),kind:"color",group:"line"},{path:"reg.midStyle",label:c("drawing.regressionchannel.regMidStyle","Midline style"),kind:"lineStyle",group:"line"},{path:"reg.upperColor",label:c("drawing.regressionchannel.regUpperColor","Upper line color"),kind:"color",group:"line"},{path:"reg.upperStyle",label:c("drawing.regressionchannel.regUpperStyle","Upper line style"),kind:"lineStyle",group:"line"},{path:"reg.lowerColor",label:c("drawing.regressionchannel.regLowerColor","Lower line color"),kind:"color",group:"line"},{path:"reg.lowerStyle",label:c("drawing.regressionchannel.regLowerStyle","Lower line style"),kind:"lineStyle",group:"line"},{path:"reg.upperFill",label:c("drawing.regressionchannel.regUpperFill","Upper fill"),kind:"color",group:"fill"},{path:"reg.lowerFill",label:c("drawing.regressionchannel.regLowerFill","Lower fill"),kind:"color",group:"fill"},{path:"reg.showR2",label:c("drawing.regressionchannel.regShowR2","Show R\xB2"),kind:"boolean",group:"behavior"}]}}writeProps(){return {...this.reg}}readProps(t){this.reg={...Ib(),...t};}};var Rb=`${be}00`;function Db(){return {midColor:be,midStyle:"solid",multiplier:1,upperColor:Rb,upperStyle:"solid",lowerColor:Rb,lowerStyle:"solid",bandFill:`${be}33`}}function Ob(r,e){let t=r.length;if(t<1)return null;let n=0;for(let d of r)n+=d.volume>0?d.volume:0;let i=n>0,o=0,s=0,a=0,l=[];for(let d=0;d<t;d+=1){let u=r[d],h=(u.high+u.low+u.close)/3,p=i?Math.max(0,u.volume):1;o+=p,s+=h*p,a+=h*h*p;let m=o>0?s/o:h,g=o>0?Math.max(0,a/o-m*m):0,b=Math.sqrt(g)*e;l.push({time:u.time,mid:m,upper:m+b,lower:m-b});}return l}var ii=class extends Z{constructor(t){super(t);this.type="anchoredvwap";this.cachedRange=null;this.cachedExtent=null;this.vwap||(this.vwap=Db());}anchorSchema(){return {min:1,max:1,slots:[{role:"anchor",free:"x"}]}}series(t){let n=this.anchors[0];if(!n)return null;let i=t.barsInRange?.(n.time,Number.POSITIVE_INFINITY)??null;if(!i||i.length<1)return null;let o=Ob(i.map(s=>({time:s.time,high:s.high,low:s.low,close:s.close,volume:s.volume??0})),this.vwap.multiplier);if(o&&o.length>0){let s=1/0,a=-1/0;for(let l of o)l.lower<s&&(s=l.lower),l.upper>a&&(a=l.upper);this.cachedRange={min:s,max:a},this.cachedExtent={min:o[0].time,max:o[o.length-1].time};}return o}layout(t){let n=this.series(t);if(!n)return null;let i=[],o=[],s=[];for(let a of n){let l=t.xOf(a.time),d=t.yOf(a.mid,this.paneId),u=t.yOf(a.upper,this.paneId),h=t.yOf(a.lower,this.paneId);d==null||u==null||h==null||(i.push([l,d]),o.push([l,u]),s.push([l,h]));}return i.length>0?{mid:i,upper:o,lower:s}:null}bandPolygon(t){return [...t.upper,...[...t.lower].reverse()]}hitTest(t,n,i,o){let s=this.layout(i);return s?wn(t,n,this.bandPolygon(s))?true:Rh(t,n,s.mid,o)||Rh(t,n,s.upper,o)||Rh(t,n,s.lower,o):false}handlePoints(t){let n=this.layout(t);if(n&&n.mid.length>0)return [n.mid[0]];let i=this.anchors[0];if(!i)return [];let o=t.yOf(i.price,this.paneId);return o==null?[]:[[t.xOf(i.time),o]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.layout(t);if(!n)return null;let i=[...n.upper,...n.lower],o=i.map(d=>d[0]),s=i.map(d=>d[1]),a=Math.min(...o),l=Math.min(...s);return {x:a,y:l,w:Math.max(...o)-a,h:Math.max(...s)-l}}priceRange(){return this.cachedRange}timeExtent(){return this.cachedExtent}schema(){return {fields:[{path:"vwap.midColor",label:c("drawing.anchoredvwap.vwapMidColor","VWAP color"),kind:"color",group:"line"},{path:"vwap.midStyle",label:c("drawing.anchoredvwap.vwapMidStyle","VWAP style"),kind:"lineStyle",group:"line"},{path:"vwap.multiplier",label:c("drawing.anchoredvwap.vwapMultiplier","Band multiplier"),kind:"number",min:.5,max:5,step:.5,group:"behavior"},{path:"vwap.upperColor",label:c("drawing.anchoredvwap.vwapUpperColor","Upper band color"),kind:"color",group:"line"},{path:"vwap.lowerColor",label:c("drawing.anchoredvwap.vwapLowerColor","Lower band color"),kind:"color",group:"line"},{path:"vwap.bandFill",label:c("drawing.anchoredvwap.vwapBandFill","Band fill"),kind:"color",group:"fill"}]}}writeProps(){return {...this.vwap}}readProps(t){this.vwap={...Db(),...t};}};function Rh(r,e,t,n){for(let i=1;i<t.length;i+=1)if(fe(r,e,t[i-1][0],t[i-1][1],t[i][0],t[i][1])<=n)return true;return false}var nL=`${N}66`,rL=`${O}66`,iL=`${N}BF`,oL=`${O}BF`;function Nb(){return {rows:24,valueAreaPct:70,widthPct:35,anchor:"left",upColor:nL,downColor:rL,vaUpColor:iL,vaDownColor:oL,showVah:true,vahColor:R,vahStyle:"solid",showVal:true,valColor:R,valStyle:"solid",showPoc:true,pocColor:void 0,pocStyle:"solid",showDevelopingPoc:false,developingPocColor:xt,developingPocStyle:"dotted",showDevelopingVa:false,developingVaColor:xt,developingVaStyle:"dotted"}}function sL(r,e){return r<0?0:r>=e?e-1:r}function Fb(r,e,t){let n=r.length,i=0,o=0;for(let u=0;u<n;u+=1){let h=r[u].up+r[u].down;i+=h,h>o&&(o=h);}let s=i*Math.min(1,Math.max(0,t)),a=e,l=e,d=o;for(;d<s&&(a>0||l<n-1);){let u=a>0?r[a-1].up+r[a-1].down:-1,h=l<n-1?r[l+1].up+r[l+1].down:-1;h>u?(l+=1,d+=h):(a-=1,d+=u);}return {vaFrom:a,vaTo:l}}function Bb(r,e,t,n){let i=n.volume;if(!(i>0))return;let o=r.length,s=n.close>=n.open?"up":"down",a=new Set;for(let l of [n.open,n.high,n.low,n.close])a.add(sL(Math.floor((l-e)/t),o));for(let l of a)r[l][s]+=i;}function Vb(r){let e=0,t=0;for(let n=0;n<r.length;n+=1){let i=r[n].up+r[n].down;i>e&&(e=i,t=n);}return e>0?{poc:t,maxTotal:e}:null}function Hb(r,e,t){let n=1/0,i=-1/0;for(let m of r)m.volume>0&&(m.low<n&&(n=m.low),m.high>i&&(i=m.high));if(!Number.isFinite(n))return null;let o=i>n?Math.max(1,Math.round(e)):1,s=i>n?(i-n)/o:1,a=Array.from({length:o},(m,g)=>({price:n+g*s,up:0,down:0}));for(let m of r)Bb(a,n,s,m);let l=Vb(a);if(!l)return null;let{poc:d,maxTotal:u}=l,{vaFrom:h,vaTo:p}=Fb(a,d,t);return {rows:a,rowH:s,min:n,maxTotal:u,poc:d,vaFrom:h,vaTo:p}}function _b(r,e,t,n){let i=Hb(r,e,t);if(!i)return null;if(!n||r.length<1)return {profile:i,developingPoc:[],developingVaHigh:[],developingVaLow:[]};let{min:o,rowH:s}=i,a=i.rows.length,l=Array.from({length:a},(p,m)=>({price:o+m*s,up:0,down:0})),d=[],u=[],h=[];for(let p of r){Bb(l,o,s,p);let m=Vb(l);if(!m)continue;let{poc:g}=m,{vaFrom:b,vaTo:f}=Fb(l,g,t);d.push({time:p.time,price:l[g].price+s/2}),u.push({time:p.time,price:l[f].price+s}),h.push({time:p.time,price:l[b].price});}return {profile:i,developingPoc:d,developingVaHigh:u,developingVaLow:h}}var $t=class extends Z{constructor(t){super(t);this.type="fixedrangevp";this.cachedRange=null;this.frvp||(this.frvp=Nb());}anchorSchema(){return {min:2,max:2,slots:[{role:"start",free:"x"},{role:"end",free:"x"}]}}barsInSpan(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=Math.min(n.time,i.time),s=Math.max(n.time,i.time),a=t.barsInRange?.(o,s)??null;return !a||a.length<1?null:a.map(l=>({time:l.time,open:l.open,high:l.high,low:l.low,close:l.close,volume:l.volume??0}))}compute(t){let n=this.barsInSpan(t);if(!n)return null;let i=this.frvp,o=i.showDevelopingPoc||i.showDevelopingVa,s=_b(n,i.rows,i.valueAreaPct/100,o);if(s){let{profile:a}=s;this.cachedRange={min:a.min,max:a.min+a.rowH*a.rows.length};}return s}layout(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=this.compute(t);if(!o)return null;let{profile:s}=o,a=Math.min(n.time,i.time),l=Math.max(n.time,i.time),d=t.xOf(a),u=t.xOf(l),h=Math.abs(u-d),p=Math.max(1,Math.min(100,Math.max(0,this.frvp.widthPct))/100*h),m=this.frvp.anchor==="left",g=m?Math.min(d,u):Math.max(d,u),b=m?1:-1,f=[];for(let C=0;C<=s.rows.length;C+=1){let L=t.yOf(s.min+C*s.rowH,this.paneId);if(L==null)return null;f.push(L);}let v=C=>t.yOf(C,this.paneId),w=s.rows[s.vaTo].price+s.rowH,x=s.rows[s.vaFrom].price,T=s.rows[s.poc].price+s.rowH/2,M=C=>{let L=[];for(let y of C){let E=v(y.price);E!=null&&L.push([t.xOf(y.time),E]);}return L};return {x0:Math.min(d,u),x1:Math.max(d,u),anchorX:g,maxW:p,grow:b,profile:s,yEdges:f,vahY:v(w),valY:v(x),pocY:v(T),developingPoc:M(o.developingPoc),developingVaHigh:M(o.developingVaHigh),developingVaLow:M(o.developingVaLow)}}hitTest(t,n,i,o){let s=this.layout(i);if(!s)return false;let a=s.grow===1?s.anchorX:s.anchorX-s.maxW,l=s.grow===1?s.anchorX+s.maxW:s.anchorX,d=Math.min(s.yEdges[0],s.yEdges[s.yEdges.length-1]),u=Math.max(s.yEdges[0],s.yEdges[s.yEdges.length-1]);if(wn(t,n,[[a,d],[l,d],[l,u],[a,u]]))return true;let h=[[s.x0,s.vahY],[s.x0,s.valY],[s.x0,s.pocY]];for(let[,p]of h)if(p!=null&&fe(t,n,s.x0,p,s.x1,p)<=o)return true;for(let p of [s.developingPoc,s.developingVaHigh,s.developingVaLow])for(let m=1;m<p.length;m+=1)if(fe(t,n,p[m-1][0],p[m-1][1],p[m][0],p[m][1])<=o)return true;return false}handlePoints(t){let n=this.layout(t);if(n&&n.pocY!=null)return [[n.x0,n.pocY],[n.x1,n.pocY]];let i=[];for(let o of this.anchors){let s=t.yOf(o.price,this.paneId);if(s==null)return [];i.push([t.xOf(o.time),s]);}return i}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.layout(t);if(!n)return null;let i=Math.min(n.x0,n.grow===1?n.anchorX:n.anchorX-n.maxW),o=Math.max(n.x1,n.grow===1?n.anchorX+n.maxW:n.anchorX),s=Math.min(n.yEdges[0],n.yEdges[n.yEdges.length-1]),a=Math.max(n.yEdges[0],n.yEdges[n.yEdges.length-1]);return {x:i,y:s,w:o-i,h:a-s}}priceRange(){if(this.cachedRange)return this.cachedRange;let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[{path:"frvp.rows",label:c("drawing.fixedrangevp.frvpRows","Rows"),kind:"number",min:1,max:500,step:1,group:"behavior"},{path:"frvp.valueAreaPct",label:c("drawing.fixedrangevp.frvpValueAreaPct","Value Area"),kind:"number",min:0,max:100,step:1,group:"behavior"},{path:"frvp.widthPct",label:c("drawing.fixedrangevp.frvpWidthPct","Width %"),kind:"number",min:0,max:100,step:1,group:"behavior"},{path:"frvp.anchor",label:c("drawing.fixedrangevp.frvpAnchor","Anchor"),kind:"select",options:[{value:"right",label:c("drawing.fixedrangevp.option.right","Right")},{value:"left",label:c("drawing.fixedrangevp.option.left","Left")}],group:"behavior"},{path:"frvp.upColor",label:c("drawing.fixedrangevp.frvpUpColor","Up Volume"),kind:"color",group:"fill"},{path:"frvp.downColor",label:c("drawing.fixedrangevp.frvpDownColor","Down Volume"),kind:"color",group:"fill"},{path:"frvp.vaUpColor",label:c("drawing.fixedrangevp.frvpVaUpColor","Value Area Up"),kind:"color",group:"fill"},{path:"frvp.vaDownColor",label:c("drawing.fixedrangevp.frvpVaDownColor","Value Area Down"),kind:"color",group:"fill"},{path:"frvp.showVah",label:c("drawing.fixedrangevp.frvpShowVah","VAH"),kind:"boolean",group:"line"},{path:"frvp.vahColor",label:c("drawing.fixedrangevp.frvpVahColor","VAH color"),kind:"color",group:"line"},{path:"frvp.vahStyle",label:c("drawing.fixedrangevp.frvpVahStyle","VAH style"),kind:"lineStyle",options:tt,group:"line"},{path:"frvp.showVal",label:c("drawing.fixedrangevp.frvpShowVal","VAL"),kind:"boolean",group:"line"},{path:"frvp.valColor",label:c("drawing.fixedrangevp.frvpValColor","VAL color"),kind:"color",group:"line"},{path:"frvp.valStyle",label:c("drawing.fixedrangevp.frvpValStyle","VAL style"),kind:"lineStyle",options:tt,group:"line"},{path:"frvp.showPoc",label:c("drawing.fixedrangevp.frvpShowPoc","POC"),kind:"boolean",group:"line"},{path:"frvp.pocColor",label:c("drawing.fixedrangevp.frvpPocColor","POC color"),kind:"color",group:"line"},{path:"frvp.pocStyle",label:c("drawing.fixedrangevp.frvpPocStyle","POC style"),kind:"lineStyle",options:tt,group:"line"},{path:"frvp.showDevelopingPoc",label:c("drawing.fixedrangevp.frvpShowDevelopingPoc","Developing POC"),kind:"boolean",group:"line"},{path:"frvp.developingPocColor",label:c("drawing.fixedrangevp.frvpDevelopingPocColor","Developing POC color"),kind:"color",group:"line"},{path:"frvp.developingPocStyle",label:c("drawing.fixedrangevp.frvpDevelopingPocStyle","Developing POC style"),kind:"lineStyle",options:tt,group:"line"},{path:"frvp.showDevelopingVa",label:c("drawing.fixedrangevp.frvpShowDevelopingVa","Developing VA"),kind:"boolean",group:"line"},{path:"frvp.developingVaColor",label:c("drawing.fixedrangevp.frvpDevelopingVaColor","Developing VA color"),kind:"color",group:"line"},{path:"frvp.developingVaStyle",label:c("drawing.fixedrangevp.frvpDevelopingVaStyle","Developing VA style"),kind:"lineStyle",options:tt,group:"line"}]}}writeProps(){return {...this.frvp}}readProps(t){this.frvp={...Nb(),...t};}};var Ol=class extends Le{constructor(){super(...arguments);this.type="pitchfork";}anchorSchema(){return {min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=f=>{let v=t.yOf(f.price,this.paneId);return v==null?null:[t.xOf(f.time),v]},s=o(n),a=o(i);if(!s||!a)return null;let l=this.anchors[2];if(!l)return {segments:[[s[0],s[1],a[0],a[1]]],fill:null};let d=o(l);if(!d)return null;let u=(a[0]+d[0])/2,h=(a[1]+d[1])/2,p=u-s[0],m=h-s[1],g=t.width,b=t.height;return {segments:[Oe(s[0],s[1],u,h,"right",g,b),Oe(a[0],a[1],a[0]+p,a[1]+m,"right",g,b),Oe(d[0],d[1],d[0]+p,d[1]+m,"right",g,b),[a[0],a[1],d[0],d[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Y]}}};var Zi=class extends Le{anchorSchema(){return {min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=f=>{let v=e.yOf(f.price,this.paneId);return v==null?null:[e.xOf(f.time),v]},o=i(t),s=i(n);if(!o||!s)return null;let a=this.anchors[2];if(!a)return {segments:[[o[0],o[1],s[0],s[1]]],fill:null};let l=i(this.medianStart(t,n,a)),d=i(a);if(!l||!d)return null;let u=(s[0]+d[0])/2,h=(s[1]+d[1])/2,p=u-l[0],m=h-l[1],g=e.width,b=e.height;return {segments:[Oe(l[0],l[1],u,h,"right",g,b),Oe(s[0],s[1],s[0]+p,s[1]+m,"right",g,b),Oe(d[0],d[1],d[0]+p,d[1]+m,"right",g,b),[s[0],s[1],d[0],d[1]],[o[0],o[1],s[0],s[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let e=this.anchors.map(t=>t.price);return {min:Math.min(...e),max:Math.max(...e)}}schema(){return {fields:[...K,...Y]}}};var Nl=class extends Zi{constructor(){super(...arguments);this.type="schiffpitchfork";}medianStart(t,n){return {time:t.time,price:(t.price+n.price)/2}}};var Fl=class extends Zi{constructor(){super(...arguments);this.type="modifiedschiffpitchfork";}medianStart(t,n){return {time:(t.time+n.time)/2,price:(t.price+n.price)/2}}};var Bl=class extends Le{constructor(){super(...arguments);this.type="insidepitchfork";}anchorSchema(){return {min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=v=>{let w=t.yOf(v.price,this.paneId);return w==null?null:[t.xOf(v.time),w]},s=o(n),a=o(i);if(!s||!a)return null;let l=this.anchors[2];if(!l)return {segments:[[s[0],s[1],a[0],a[1]]],fill:null};let d=o({time:(n.time+i.time)/2,price:(n.price+i.price)/2}),u=o(l);if(!d||!u)return null;let h=(a[0]+u[0])/2,p=(a[1]+u[1])/2,m=u[0]-d[0],g=u[1]-d[1],b=t.width,f=t.height;return {segments:[Oe(h,p,h+m,p+g,"right",b,f),Oe(a[0],a[1],a[0]+m,a[1]+g,"right",b,f),Oe(u[0],u[1],u[0]+m,u[1]+g,"right",b,f),[a[0],a[1],u[0],u[1]],[d[0],d[1],u[0],u[1]],[s[0],s[1],a[0],a[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Y]}}};var Vl=class extends Z{constructor(){super(...arguments);this.type="arrow";}anchorSchema(){return {min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?null:[t.xOf(n.time),o,t.xOf(i.time),s]}hitTest(t,n,i,o){let s=this.pixels(i);return s!=null&&fe(t,n,s[0],s[1],s[2],s[3])<=o}handlePoints(t){let n=this.pixels(t);return n?[[n[0],n[1]],[n[2],n[3]]]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.pixels(t);return n?{x:Math.min(n[0],n[2]),y:Math.min(n[1],n[3]),w:Math.abs(n[2]-n[0]),h:Math.abs(n[3]-n[1])}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,{path:"style.arrowRight",label:c("drawing.arrow.arrowRight","Head (end)"),kind:"boolean",group:"line"},{path:"style.arrowLeft",label:c("drawing.arrow.arrowLeft","Head (start)"),kind:"boolean",group:"line"},...Y]}}};var zb=48,Hl=class extends Z{constructor(){super(...arguments);this.type="ellipse";}anchorSchema(){return {min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}oval(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time);return {cx:(a+l)/2,cy:(o+s)/2,rx:Math.abs(l-a)/2,ry:Math.abs(s-o)/2}}perimeter(t){let n=[];for(let i=0;i<=zb;i+=1){let o=i/zb*Math.PI*2;n.push([t.cx+t.rx*Math.cos(o),t.cy+t.ry*Math.sin(o)]);}return n}hitTest(t,n,i,o){let s=this.oval(i);if(!s||s.rx<1||s.ry<1)return false;let a=((t-s.cx)/s.rx)**2+((n-s.cy)/s.ry)**2;return this.style.fillColor&&a<=1?true:qi(t,n,this.perimeter(s))<=o}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?[]:[[t.xOf(n.time),o],[t.xOf(i.time),s]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.oval(t);return n?{x:n.cx-n.rx,y:n.cy-n.ry,w:n.rx*2,h:n.ry*2}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,...Ce,...Y]}}};var _l=class extends Le{constructor(){super(...arguments);this.type="triangle";}anchorSchema(){return {min:3,max:3,slots:[{role:"v1",free:"both"},{role:"v2",free:"both"},{role:"v3",free:"both"}]}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=u=>{let h=t.yOf(u.price,this.paneId);return h==null?null:[t.xOf(u.time),h]},s=o(n),a=o(i);if(!s||!a)return null;let l=this.anchors[2];if(!l)return {segments:[[s[0],s[1],a[0],a[1]]],fill:null};let d=o(l);return d?{segments:[[s[0],s[1],a[0],a[1]],[a[0],a[1],d[0],d[1]],[d[0],d[1],s[0],s[1]]],fill:[s,a,d]}:null}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Ce,...Y]}}};var aL=512,yr=class extends Le{anchorSchema(){return {min:2,max:aL,slots:[]}}geometry(e){let t=[];for(let i of this.anchors){let o=e.yOf(i.price,this.paneId);if(o==null)return null;t.push([e.xOf(i.time),o]);}if(t.length<2)return null;let n=[];for(let i=1;i<t.length;i+=1)n.push([t[i-1][0],t[i-1][1],t[i][0],t[i][1]]);return {segments:n,fill:null}}priceRange(){if(this.anchors.length===0)return null;let e=this.anchors.map(t=>t.price);return {min:Math.min(...e),max:Math.max(...e)}}schema(){return {fields:[...K,...Y]}}};var zl=class extends yr{constructor(){super(...arguments);this.type="polyline";}};var ms=class extends yr{placementMode(){return "freehand"}handlePoints(e){return []}bounds(e){let t=[],n=[];for(let s of this.anchors){let a=e.yOf(s.price,this.paneId);a!=null&&(t.push(e.xOf(s.time)),n.push(a));}if(t.length===0)return null;let i=Math.min(...t),o=Math.min(...n);return {x:i,y:o,w:Math.max(...t)-i,h:Math.max(...n)-o}}},Wl=class extends ms{constructor(){super(...arguments);this.type="freehand";}};var lL=[{path:"style.lineColor",label:c("drawing.highlighter.lineColor","Color"),kind:"color",group:"line"},{path:"style.lineWidth",label:c("drawing.highlighter.lineWidth","Width"),kind:"number",min:4,max:60,step:1,group:"line"}],Gl=class extends ms{constructor(){super(...arguments);this.type="highlighter";}schema(){return {fields:lL}}};var Ul=class extends Z{constructor(){super(...arguments);this.type="circle";}anchorSchema(){return {min:2,max:2,slots:[{role:"center",free:"both"},{role:"edge",free:"both"}]}}geom(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time);return {cx:a,cy:o,r:Math.hypot(l-a,s-o)}}hitTest(t,n,i,o){let s=this.geom(i);if(!s||s.r<1)return false;let a=Math.hypot(t-s.cx,n-s.cy);return this.style.fillColor&&a<=s.r?true:Math.abs(a-s.r)<=o}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?[]:[[t.xOf(n.time),o],[t.xOf(i.time),s]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.geom(t);return n?{x:n.cx-n.r,y:n.cy-n.r,w:n.r*2,h:n.r*2}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,...Ce,...Y]}}};var $l=class extends Le{constructor(){super(...arguments);this.type="rotatedrect";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"w",free:"both"}]}}px(t,n){let i=this.anchors[n];if(!i)return null;let o=t.yOf(i.price,this.paneId);return o==null?null:[t.xOf(i.time),o]}geometry(t){let n=this.px(t,0),i=this.px(t,1);if(!n||!i)return null;let o=this.px(t,2);if(!o||this.anchors.length<3)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let s=i[0]-n[0],a=i[1]-n[1],l=Math.hypot(s,a);if(l<1e-6)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let d=-a/l,u=s/l,h=(o[0]-n[0])*d+(o[1]-n[1])*u,p=d*h,m=u*h,g=n,b=i,f=[i[0]+p,i[1]+m],v=[n[0]+p,n[1]+m];return {segments:[[g[0],g[1],b[0],b[1]],[b[0],b[1],f[0],f[1]],[f[0],f[1],v[0],v[1]],[v[0],v[1],g[0],g[1]]],fill:[g,b,f,v]}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...fr,...Ce,...Y]}}};var Yl=class extends yr{constructor(){super(...arguments);this.type="path";}};var Wb=40,Kl=class extends Le{constructor(){super(...arguments);this.type="arc";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"apex",free:"both"}]}}pinApex(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[2];t&&n&&i&&(i.time=(t.time+n.time)/2);}onPlaced(){this.pinApex();}constrainHandleDrag(){this.pinApex();}px(t,n){let i=this.anchors[n];if(!i)return null;let o=t.yOf(i.price,this.paneId);return o==null?null:[t.xOf(i.time),o]}geometry(t){let n=this.px(t,0),i=this.px(t,1);if(!n||!i)return null;let o=this.anchors[2];if(!o||this.anchors.length<3)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let s=t.yOf(o.price,this.paneId);if(s==null)return null;let a=(n[0]+i[0])/2,l=(n[1]+i[1])/2,d=(i[0]-n[0])/2,u=(i[1]-n[1])/2,h=Math.hypot(d,u);if(h<1e-6)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let p=-u/h,m=d/h,g=(s-l)*m;g<0&&(p=-p,m=-m);let b=Math.abs(g),f=[];for(let w=0;w<=Wb;w+=1){let x=w/Wb*Math.PI,T=Math.cos(x),M=Math.sin(x);f.push([a+T*d+M*b*p,l+T*u+M*b*m]);}let v=[];for(let w=1;w<f.length;w+=1)v.push([f[w-1][0],f[w-1][1],f[w][0],f[w][1]]);return v.push([f[f.length-1][0],f[f.length-1][1],f[0][0],f[0][1]]),{segments:v,fill:f}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...fr,...Ce,...Y]}}};var Gb=40,Xl=class extends Le{constructor(){super(...arguments);this.type="curve";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"control",free:"both"}]}}px(t,n){let i=this.anchors[n];if(!i)return null;let o=t.yOf(i.price,this.paneId);return o==null?null:[t.xOf(i.time),o]}geometry(t){let n=this.px(t,0),i=this.px(t,1);if(!n||!i)return null;let o=this.px(t,2);if(!o||this.anchors.length<3)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let s=[];for(let l=0;l<=Gb;l+=1){let d=l/Gb,u=1-d;s.push([u*u*n[0]+2*u*d*o[0]+d*d*i[0],u*u*n[1]+2*u*d*o[1]+d*d*i[1]]);}let a=[];for(let l=1;l<s.length;l+=1)a.push([s[l-1][0],s[l-1][1],s[l][0],s[l][1]]);return {segments:a,fill:s}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Ce,...Y]}}};var cL={head:11,headW:9,stemW:3.5,len:22},wr=class extends Z{anchorSchema(){return {min:1,max:1,slots:[{role:"p",free:"both"}]}}glyphPoints(e){let t=this.anchors[0];if(!t)return null;let n=e.yOf(t.price,this.paneId);if(n==null)return null;let i=e.xOf(t.time),{head:o,headW:s,stemW:a,len:l}=cL,d=[[0,0],[-s,o],[-a,o],[-a,l],[a,l],[a,o],[s,o]],u=this.dir(),h=([p,m])=>{switch(u){case "up":return [p,m];case "down":return [p,-m];case "left":return [m,p];default:return [-m,p]}};return d.map(p=>{let[m,g]=h(p);return [i+m,n+g]})}hitTest(e,t,n,i){let o=this.glyphPoints(n);return o!=null&&wn(e,t,o)}handlePoints(e){let t=this.anchors[0];if(!t)return [];let n=e.yOf(t.price,this.paneId);return n==null?[]:[[e.xOf(t.time),n]]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.glyphPoints(e);if(!t)return null;let n=t.map(a=>a[0]),i=t.map(a=>a[1]),o=Math.min(...n),s=Math.min(...i);return {x:o,y:s,w:Math.max(...n)-o,h:Math.max(...i)-s}}priceRange(){let e=this.anchors[0];return e?{min:e.price,max:e.price}:null}schema(){return {fields:[{path:"style.lineColor",label:c("drawing.arrowmarkup.lineColor","Color"),kind:"color",group:"line"},...Y]}}},gs=class extends wr{constructor(){super(...arguments);this.type="arrowmarkup";}dir(){return "up"}},fs=class extends wr{constructor(){super(...arguments);this.type="arrowmarkdown";}dir(){return "down"}};var ys=["\u2605","\u2606","\u25CF","\u25C6","\u25B2","\u25BC","\u27A4","\u2691","\u271A","\u2715","\u2764","\u2666"],jl=["small","normal","large","huge"],Ub={small:16,normal:22,large:32,huge:44},oi=class extends Z{constructor(e){super(e),this.glyph||(this.glyph=this.defaultGlyph()),this.size||(this.size="normal");}sizePx(){return Ub[this.size]??Ub.normal}anchorSchema(){return {min:1,max:1,slots:[{role:"p",free:"both"}]}}center(e){let t=this.anchors[0];if(!t)return null;let n=e.yOf(t.price,this.paneId);return n==null?null:[e.xOf(t.time),n]}hitTest(e,t,n,i){let o=this.center(n);if(!o)return false;let s=this.sizePx()/2+i;return Math.abs(e-o[0])<=s&&Math.abs(t-o[1])<=s}handlePoints(e){let t=this.center(e);return t?[t]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.center(e);if(!t)return null;let n=this.sizePx();return {x:t[0]-n/2,y:t[1]-n/2,w:n,h:n}}priceRange(){let e=this.anchors[0];return e?{min:e.price,max:e.price}:null}schema(){return {fields:[{path:"glyph",label:c("drawing.flagmark.glyph","Icon"),kind:"select",options:ys.map(e=>({value:e,label:e})),group:"line"},{path:"size",label:c("drawing.flagmark.size","Size"),kind:"select",options:jl.map(e=>({value:e,label:e})),group:"line"},{path:"style.lineColor",label:c("drawing.flagmark.lineColor","Color"),kind:"color",group:"line"},...Y]}}writeProps(){return {glyph:this.glyph,size:this.size}}readProps(e){typeof e.glyph=="string"&&(this.glyph=e.glyph),typeof e.size=="string"&&(this.size=e.size);}},bs=class extends oi{constructor(){super(...arguments);this.type="flagmark";}defaultGlyph(){return "\u2691"}},vs=class extends oi{constructor(){super(...arguments);this.type="iconstamp";}defaultGlyph(){return "\u2605"}};var $b=r=>r==="small"||r==="normal"||r==="large"||r==="huge";function dL(r){if(!r||typeof r!="object")return null;let e=r;return typeof e.ratio!="number"||typeof e.color!="string"?null:{ratio:e.ratio,color:e.color,enabled:e.enabled!==false,...typeof e.label=="string"&&e.label?{label:e.label}:{}}}var Pe=class extends Z{constructor(e){super(e),this.levels||(this.levels=this.defaultLevels().map(t=>({...t}))),this.numbersSize||(this.numbersSize="small"),this.labelsSize||(this.labelsSize="normal");}fillBands(e){return []}editableLevels(){return this.levels}anchorSchema(){return {min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}hitTest(e,t,n,i){let o=this.entryLines(n);return o!=null&&o.some(s=>fe(e,t,s.x1,s.y1,s.x2,s.y2)<=i)}handlePoints(e){let t=[];for(let n of this.anchors){let i=e.yOf(n.price,this.paneId);if(i==null)return [];t.push([e.xOf(n.time),i]);}return t}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.handlePoints(e);if(t.length===0)return null;let n=t.map(a=>a[0]),i=t.map(a=>a[1]),o=Math.min(...n),s=Math.min(...i);return {x:o,y:s,w:Math.max(...n)-o,h:Math.max(...i)-s}}schema(){return {fields:K.filter(e=>e.path!=="style.lineColor")}}writeProps(){return {levels:this.levels.map(e=>({...e})),numbersSize:this.numbersSize,labelsSize:this.labelsSize}}readProps(e){if(Array.isArray(e.levels)){let t=e.levels.map(dL).filter(n=>n!=null);t.length&&(this.levels=t);}$b(e.numbersSize)&&(this.numbersSize=e.numbersSize),$b(e.labelsSize)&&(this.labelsSize=e.labelsSize);}};var Sn=class extends Pe{constructor(e){super(e),this.showRatios===void 0&&(this.showRatios=true),this.showPrices===void 0&&(this.showPrices=true),this.labelSide===void 0&&(this.labelSide="left"),this.background===void 0&&(this.background=true);}levelPrice(e,t,n){return t+e*(n-t)}levelLines(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=e.xOf(t.time),o=e.xOf(n.time),s=this.style.extendLeft?0:Math.min(i,o),a=this.style.extendRight?e.width:Math.max(i,o),l=[];for(let d of this.levels){if(!d.enabled)continue;let u=this.levelPrice(d.ratio,t.price,n.price),h=e.yOf(u,this.paneId);h!=null&&l.push({ratio:d.ratio,color:d.color,label:d.label,price:u,x1:s,x2:a,y:h});}return l}entryLines(e){let t=this.levelLines(e);if(!t)return null;let n=this.labelSide==="right";return t.map(i=>({color:i.color,label:i.label,x1:i.x1,y1:i.y,x2:i.x2,y2:i.y,numberText:this.levelText(i.ratio,i.price),numberX:n?i.x2-4:i.x1+4,numberY:i.y-7,numberAlign:n?"right":"left",labelX:(i.x1+i.x2)/2,labelY:i.y-7}))}levelText(e,t){let n=t.toFixed(2);return this.showRatios&&this.showPrices?`${e} (${n})`:this.showRatios?String(e):this.showPrices?n:""}fillBands(e){if(!this.background)return [];let t=this.levelLines(e)?.sort((i,o)=>i.ratio-o.ratio);if(!t)return [];let n=[];for(let i=1;i<t.length;i+=1){let o=t[i-1],s=t[i];n.push({color:s.color,x:o.x1,y:Math.min(o.y,s.y),w:o.x2-o.x1,h:Math.abs(s.y-o.y)});}return n}priceRange(){let e=this.anchors[0],t=this.anchors[1];if(!e||!t)return null;let n=this.levels.filter(i=>i.enabled).map(i=>this.levelPrice(i.ratio,e.price,t.price));return n.length===0?null:{min:Math.min(...n),max:Math.max(...n)}}schema(){return {fields:[...super.schema().fields,{path:"style.extendLeft",label:c("drawing.field.extendLeft","Extend left"),kind:"boolean",group:"line"},{path:"style.extendRight",label:c("drawing.field.extendRight","Extend right"),kind:"boolean",group:"line"}]}}writeProps(){return {...super.writeProps(),showRatios:this.showRatios,showPrices:this.showPrices,labelSide:this.labelSide,background:this.background}}readProps(e){super.readProps(e),typeof e.showRatios=="boolean"&&(this.showRatios=e.showRatios),typeof e.showPrices=="boolean"&&(this.showPrices=e.showPrices),(e.labelSide==="left"||e.labelSide==="right")&&(this.labelSide=e.labelSide),typeof e.background=="boolean"&&(this.background=e.background);}};var si=R,Cn=O,Tn=q,ai="#4caf50",xr=N,on=be,kn="#9c27b0",ql="#e91e63",ws="#26a69a",Dh="#ab47bc",Yb="#ef5350",Ji="#ffb74d",Oh="#38c0fd",Zl="#b2b5be",Qi=[Oh,on,xr,ai,Tn,Cn,ql,kn,si,ws,Dh,Yb];function Kb(r){return Qi[(r%Qi.length+Qi.length)%Qi.length]}var uL=[[0,si],[.125,Cn],[.236,Cn],[.25,Cn],[.382,Tn],[.5,ai],[.618,xr],[.75,on],[.786,on],[1,si],[.705,Ji],[.886,kn],[1.272,on],[1.382,Tn],[1.414,ws],[1.618,Cn],[2,si],[2.272,Dh],[2.382,Tn],[2.414,ql],[2.618,Tn],[3,si],[3.272,Yb],[3.618,kn],[4.236,ai],[4.618,ql],[-0.27,Oh],[-0.272,Oh],[-0.62,on],[-0.618,on],[-1,ws],[-1.5,Dh],[-2,kn],[-2.5,ql],[6.854,xr],[11.09,on]];function hL(r,e=0){return uL.find(([t])=>t===r)?.[1]??Kb(e)}function De(r){return r.map((e,t)=>{let n=typeof e=="number"?{ratio:e}:e;return {ratio:n.ratio,color:n.color??hL(n.ratio,t),enabled:n.enabled!==false,...n.label?{label:n.label}:{}}})}function Xb(r,e=r){return Array.from({length:r},(t,n)=>({ratio:n+1,color:Kb(n),enabled:n<e,label:String(n+1)}))}var jb=[0,.236,.382,.5,.618,.705,.786,.886,1,1.272,1.414,1.618,2,2.272,2.414,2.618,3,3.272,3.618,4.236,4.618,-0.272,-0.618,-1],pL=[0,.236,.382,.5,.62,.705,.79,.886,1,1.272,1.414,1.618,2,2.618,3,3.618,4.236,4.618,-0.27,-0.62,-1,-1.5,-2,-2.5];function xs(r,e,t={}){return De(r.map(n=>({ratio:n,enabled:e.includes(n),color:t[String(n)]})))}var li=[{key:"classic",label:c("drawing.fibPreset.classic","Classic"),reverse:false,levels:xs(jb,[0,.236,.382,.5,.618,.786,1])},{key:"extension",label:c("drawing.fibPreset.extension","Extension"),reverse:true,levels:xs(jb,[0,1,1.272,1.414,1.618,2,2.618,3.618,4.236])},{key:"ote",label:c("drawing.fibPreset.ote","OTE"),reverse:false,levels:xs(pL,[0,.5,.62,.705,.79,1,-0.27,-0.62],{"0.62":Ji,"0.79":Ji})}];function Nh(r,e){let t=i=>JSON.stringify(i.map(o=>[o.ratio,o.color,o.enabled,o.label??""])),n=t(r);return li.find(i=>i.reverse===e&&t(i.levels)===n)?.key??null}var mL=li[0].levels,Sr=class extends Sn{constructor(t){super(t);this.type="fibretracement";this.reverse===void 0&&(this.reverse=false);}defaultLevels(){return mL}levelPrice(t,n,i){return this.reverse?n+t*(i-n):i+t*(n-i)}writeProps(){return {...super.writeProps(),reverse:this.reverse}}readProps(t){super.readProps(t),this.reverse=typeof t.reverse=="boolean"?t.reverse:true;}};var gL=xs([0,.236,.382,.5,.618,.786,1,1.272,1.414,1.618,2,2.272,2.414,2.618,3,3.272,3.618,4.236,4.618],[0,.382,.618,1,1.272,1.618,2.618],{"2.618":kn}),Ql=class extends Sn{constructor(){super(...arguments);this.type="fibextension";}defaultLevels(){return gL}};var fL=De([0,.382,.5,.618,1,1.618,{ratio:2.618,color:kn}]),Jl=class extends Pe{constructor(){super(...arguments);this.type="fibextensiontrend";}anchorSchema(){return {min:3,max:3,slots:[{role:"a",free:"both"},{role:"b",free:"both"},{role:"c",free:"both"}]}}defaultLevels(){return fL}entryLines(t){let n=this.anchors[0],i=this.anchors[1],o=this.anchors[2];if(!n||!i||!o)return null;let s=i.price-n.price,a=[t.xOf(n.time),t.xOf(i.time),t.xOf(o.time)],l=Math.min(...a),d=Math.max(...a),u=[];for(let h of this.levels){if(!h.enabled)continue;let p=o.price+h.ratio*s,m=t.yOf(p,this.paneId);m!=null&&u.push({color:h.color,label:h.label,x1:l,y1:m,x2:d,y2:m,numberText:`${h.ratio} (${p.toFixed(2)})`,numberX:l+4,numberY:m-7,numberAlign:"left",labelX:(l+d)/2,labelY:m-7});}return u}priceRange(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[2];if(!t||!n||!i)return null;let o=n.price-t.price,s=this.levels.filter(a=>a.enabled).map(a=>i.price+a.ratio*o);return s.push(t.price,n.price,i.price),{min:Math.min(...s),max:Math.max(...s)}}};var bL=De([.236,.382,.5,.618,.786,1]),ec=class extends Pe{constructor(){super(...arguments);this.type="fibfan";}defaultLevels(){return bL}fanLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.xOf(n.time),s=t.yOf(n.price,this.paneId);if(s==null)return null;let a=t.xOf(i.time),l=i.price-n.price,d=[];for(let u of this.levels){if(!u.enabled)continue;let h=t.yOf(n.price+u.ratio*l,this.paneId);if(h==null)continue;let[p,m,g,b]=Oe(o,s,a,h,"right",t.width,t.height);d.push({ratio:u.ratio,color:u.color,label:u.label,x1:p,y1:m,x2:g,y2:b,labelX:a+5,labelY:h});}return d}entryLines(t){let n=this.fanLines(t);return n?n.map(i=>({color:i.color,label:i.label,x1:i.x1,y1:i.y1,x2:i.x2,y2:i.y2,numberText:String(i.ratio),numberX:i.labelX,numberY:i.labelY,numberAlign:"left",labelX:i.labelX,labelY:i.labelY+13})):null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var vL=[0,1,2,3,5,8,13,21,34].map(r=>({ratio:r,color:H,enabled:true})),tc=class extends Pe{constructor(){super(...arguments);this.type="fibtimezones";}defaultLevels(){return vL}zoneLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=i.time-n.time;if(Math.abs(o)<1e-9)return null;let s=[];for(let a of this.levels)a.enabled&&s.push({n:a.ratio,color:a.color,label:a.label,x:t.xOf(n.time+a.ratio*o)});return s}entryLines(t){let n=this.zoneLines(t);if(!n)return null;let i=t.height;return n.map(o=>({color:o.color,label:o.label,x1:o.x,y1:0,x2:o.x,y2:i,numberText:String(o.n),numberX:o.x,numberY:9,numberAlign:"center",labelX:o.x,labelY:24}))}priceRange(){return null}timeExtent(){return null}};var yL=De([0,.236,.382,.5,.618,.786,1,1.618,2.618]),nc=class extends Pe{constructor(){super(...arguments);this.type="fibchannel";}defaultLevels(){return yL}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"offset",free:"both"}]}}entryLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time),d=0,u=0,h=this.anchors[2];if(h){let m=t.yOf(h.price,this.paneId);if(m==null)return null;d=t.xOf(h.time)-a,u=m-o;}let p=[];for(let m of this.levels){if(!m.enabled)continue;let g=m.ratio*d,b=m.ratio*u,f=l+g,v=s+b;p.push({color:m.color,label:m.label,x1:a+g,y1:o+b,x2:f,y2:v,numberText:String(m.ratio),numberX:f+5,numberY:v,numberAlign:"left",labelX:f+5,labelY:v+13});}return p}priceRange(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[2];if(!t||!n)return null;let o=i?i.price-t.price:0,s=1/0,a=-1/0;for(let l of this.levels)if(l.enabled)for(let d of [t.price,n.price]){let u=d+l.ratio*o;u<s&&(s=u),u>a&&(a=u);}return s<=a?{min:s,max:a}:null}};var wL=De([0,.236,.382,.5,.618,.786,1]),rc=class extends Pe{constructor(){super(...arguments);this.type="fibspeedfan";}defaultLevels(){return wL}entryLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),d=t.xOf(i.time)-a,u=s-o,h=d>=0?"right":"left",p=t.width,m=t.height,g=[];for(let b of this.levels){if(!b.enabled)continue;let f=a+d,v=o+u*b.ratio,w=Oe(a,o,f,v,h,p,m);if(g.push({color:b.color,label:b.label,x1:w[0],y1:w[1],x2:w[2],y2:w[3],numberText:String(b.ratio),numberX:h==="right"?f+5:f-5,numberY:v,numberAlign:h==="right"?"left":"right",labelX:f,labelY:v}),b.ratio===1)continue;let x=a+d*b.ratio,T=o+u,M=Oe(a,o,x,T,h,p,m);g.push({color:b.color,label:b.label,x1:M[0],y1:M[1],x2:M[2],y2:M[3],numberText:String(b.ratio),numberX:x,numberY:T+(u>=0?12:-12),numberAlign:"center",labelX:x,labelY:T+12});}return g}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var xL=De([0,.382,{ratio:.5,enabled:false},.618,1,1.382,1.618,2,2.382,2.618,3]),ic=class extends Pe{constructor(){super(...arguments);this.type="trendfibtime";}defaultLevels(){return xL}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"p3",free:"both"}]}}entryLines(t){let n=this.anchors[0],i=this.anchors[1],o=this.anchors[2];if(!n||!i||!o)return null;let s=i.time-n.time;if(Math.abs(s)<1e-9)return null;let a=t.height,l=[];for(let d of this.levels){if(!d.enabled)continue;let u=t.xOf(o.time+d.ratio*s);l.push({color:d.color,label:d.label,x1:u,y1:0,x2:u,y2:a,numberText:String(d.ratio),numberX:u,numberY:9,numberAlign:"center",labelX:u,labelY:24});}return l}priceRange(){return null}timeExtent(){return null}};function SL(r,e,t){if(t-e>=Math.PI*2-.001)return true;let n=r-e,i=Math.PI*2;for(;n<0;)n+=i;for(;n>=i;)n-=i;return n<=t-e+1e-6}var sn=class extends Pe{boundingLines(e){return []}entryLines(e){return []}hitTest(e,t,n,i){let o=this.radial(n);if(o){let s=Math.hypot(e-o.cx,t-o.cy),a=Math.atan2(t-o.cy,e-o.cx);if(SL(a,o.a0,o.a1)){for(let l of this.levels)if(l.enabled&&Math.abs(s-o.R0*l.ratio)<=i)return true}}return this.boundingLines(n).some(s=>fe(e,t,s[0],s[1],s[2],s[3])<=i)}priceRange(){if(this.anchors.length===0)return null;let e=this.anchors.map(t=>t.price);return {min:Math.min(...e),max:Math.max(...e)}}};var CL=De([.236,.382,.5,.618,.786,1,1.618,2.618]),oc=class extends sn{constructor(){super(...arguments);this.type="fibcircles";}defaultLevels(){return CL}radial(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time);return {cx:a,cy:o,R0:Math.hypot(l-a,s-o),a0:0,a1:Math.PI*2}}};var TL=De([.236,.382,.5,.618,.786,1,1.618,2.618]),sc=class extends sn{constructor(){super(...arguments);this.type="fibarcs";}defaultLevels(){return TL}pts(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?null:{cx:t.xOf(n.time),cy:o,ex:t.xOf(i.time),ey:s}}radial(t){let n=this.pts(t);if(!n)return null;let i=Math.hypot(n.ex-n.cx,n.ey-n.cy),o=Math.atan2(n.ey-n.cy,n.ex-n.cx);return {cx:n.cx,cy:n.cy,R0:i,a0:o-Math.PI/2,a1:o+Math.PI/2}}boundingLines(t){let n=this.pts(t);return n?[[n.cx,n.cy,n.ex,n.ey]]:[]}};var kL=De([.236,.382,.5,.618,.786,1]),ac=class extends sn{constructor(){super(...arguments);this.type="fibwedge";}defaultLevels(){return kL}anchorSchema(){return {min:3,max:3,slots:[{role:"apex",free:"both"},{role:"radius",free:"both"},{role:"angle",free:"both"}]}}px(t,n){let i=this.anchors[n];if(!i)return null;let o=t.yOf(i.price,this.paneId);return o==null?null:[t.xOf(i.time),o]}radial(t){let n=this.px(t,0),i=this.px(t,1),o=this.px(t,2);if(!n||!i||!o)return null;let s=Math.hypot(i[0]-n[0],i[1]-n[1]);if(s<1)return null;let a=Math.atan2(i[1]-n[1],i[0]-n[0]),l=Math.atan2(o[1]-n[1],o[0]-n[0]),d=Math.min(a,l),u=Math.max(a,l);return u-d>Math.PI&&([d,u]=[u,d+Math.PI*2]),{cx:n[0],cy:n[1],R0:s,a0:d,a1:u}}boundingLines(t){let n=this.px(t,0),i=this.px(t,1);if(!n||!i)return [];let o=[[n[0],n[1],i[0],i[1]]],s=this.px(t,2);if(s){let a=Math.hypot(i[0]-n[0],i[1]-n[1]),l=Math.hypot(s[0]-n[0],s[1]-n[1]);l>1e-6&&o.push([n[0],n[1],n[0]+(s[0]-n[0])/l*a,n[1]+(s[1]-n[1])/l*a]);}return o}};var LL=1.6180339887,qb=Math.log(LL)/(Math.PI/2),ML=Math.PI/64,EL=Math.PI,PL=.5,ci=class extends Z{constructor(){super(...arguments);this.type="fibspiral";}anchorSchema(){return {min:2,max:2,slots:[{role:"center",free:"both"},{role:"edge",free:"both"}]}}spiralPoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time),d=Math.hypot(l-a,s-o);if(d<1)return null;let u=Math.atan2(s-o,l-a),h=Math.max(Math.log(PL/d)/qb,-8*Math.PI*2),p=[];for(let m=h;m<=EL;m+=ML){let g=d*Math.exp(qb*m),b=u+m;p.push([a+g*Math.cos(b),o+g*Math.sin(b)]);}return p}hitTest(t,n,i,o){let s=this.spiralPoints(i);return s!=null&&s.length>=2&&qi(t,n,s)<=o}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?[]:[[t.xOf(n.time),o],[t.xOf(i.time),s]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.handlePoints(t);if(n.length<2)return null;let i=n.map(l=>l[0]),o=n.map(l=>l[1]),s=Math.min(...i),a=Math.min(...o);return {x:s,y:a,w:Math.max(...i)-s,h:Math.max(...o)-a}}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,...Y]}}};var IL=De([{ratio:.125,color:Cn,label:"1/8"},{ratio:.25,color:Tn,label:"1/4"},{ratio:.333,color:Ji,label:"1/3"},{ratio:.5,color:ai,label:"1/2"},{ratio:1,color:Zl,label:"1/1"},{ratio:2,color:xr,label:"2/1"},{ratio:3,color:on,label:"3/1"},{ratio:4,color:ws,label:"4/1"},{ratio:8,color:kn,label:"8/1"}]),lc=class extends Pe{constructor(){super(...arguments);this.type="gannfan";}defaultLevels(){return IL}entryLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.xOf(n.time),s=t.yOf(n.price,this.paneId);if(s==null)return null;let a=t.xOf(i.time),l=i.price-n.price,d=[];for(let u of this.levels){if(!u.enabled)continue;let h=t.yOf(n.price+l*u.ratio,this.paneId);if(h==null)continue;let[p,m,g,b]=Oe(o,s,a,h,"right",t.width,t.height);d.push({color:u.color,x1:p,y1:m,x2:g,y2:b,numberText:u.label??String(u.ratio),numberX:a+5,numberY:h,numberAlign:"left",labelX:a+5,labelY:h});}return d}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var AL=De([0,.25,.382,.5,.618,.75,1].map(r=>({ratio:r,label:String(r)}))),cc=class extends Pe{constructor(){super(...arguments);this.type="gannbox";}defaultLevels(){return AL}corners(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.xOf(n.time),s=t.xOf(i.time),a=t.yOf(n.price,this.paneId),l=t.yOf(i.price,this.paneId);return a==null||l==null?null:{c1:n,c2:i,left:Math.min(o,s),right:Math.max(o,s),top:Math.min(a,l),bot:Math.max(a,l)}}entryLines(t){let n=this.corners(t);if(!n)return null;let{c1:i,c2:o,left:s,right:a,top:l,bot:d}=n,u=[];for(let p of this.levels){if(!p.enabled)continue;let m=t.yOf(i.price+p.ratio*(o.price-i.price),this.paneId);m!=null&&u.push({color:p.color,x1:s,y1:m,x2:a,y2:m,numberText:p.label??String(p.ratio),numberX:s-5,numberY:m,numberAlign:"right",labelX:s,labelY:m});let g=t.xOf(i.time+p.ratio*(o.time-i.time));u.push({color:p.color,x1:g,y1:l,x2:g,y2:d,numberText:"",numberX:g,numberY:l,numberAlign:"center",labelX:g,labelY:l});}let h=this.levels.find(p=>p.ratio===1)?.color??si;return u.push({color:h,x1:s,y1:l,x2:a,y2:d,numberText:"",numberX:0,numberY:0,numberAlign:"left",labelX:0,labelY:0}),u.push({color:h,x1:s,y1:d,x2:a,y2:l,numberText:"",numberX:0,numberY:0,numberAlign:"left",labelX:0,labelY:0}),u}hitTest(t,n,i,o){let s=this.corners(i);return s!=null&&lt(t,n,s.left,s.top,s.right,s.bot,o)}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var RL=De([0,.25,.382,.5,.618,.75,1].map(r=>({ratio:r,label:String(r)}))),DL=[{label:"3x1",x:3,y:1,color:Cn},{label:"2x1",x:2,y:1,color:Tn},{label:"1x1",x:1,y:1,color:Zl},{label:"1x2",x:1,y:2,color:xr},{label:"1x3",x:1,y:3,color:on}],Fh=[{k:.25,color:Cn},{k:.5,color:Tn},{k:.75,color:ai},{k:1,color:xr}],di=class extends Pe{constructor(){super(...arguments);this.type="gannsquare";}defaultLevels(){return RL}box(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time);return {ox:a,oy:o,bx:l-a,py:s-o,left:Math.min(a,l),top:Math.min(o,s),right:Math.max(a,l),bot:Math.max(o,s)}}arcGeom(t){let n=this.box(t);return n?{ox:n.ox,oy:n.oy,bx:n.bx,py:n.py}:null}entryLines(t){let n=this.box(t);if(!n)return null;let i=this.anchors[0],o=this.anchors[1],s=[];for(let a of this.levels){if(!a.enabled)continue;let l=t.yOf(i.price+a.ratio*(o.price-i.price),this.paneId);l!=null&&s.push({color:a.color,x1:n.left,y1:l,x2:n.right,y2:l,numberText:a.label??String(a.ratio),numberX:n.left-5,numberY:l,numberAlign:"right",labelX:n.left,labelY:l});let d=t.xOf(i.time+a.ratio*(o.time-i.time));s.push({color:a.color,x1:d,y1:n.top,x2:d,y2:n.bot,numberText:"",numberX:d,numberY:n.top,numberAlign:"center",labelX:d,labelY:n.top});}for(let a of DL){let l,d;a.x>a.y?(l=n.ox+n.bx,d=n.oy+a.y/a.x*n.py):(d=n.oy+n.py,l=n.ox+a.x/a.y*n.bx),s.push({color:a.color,x1:n.ox,y1:n.oy,x2:l,y2:d,numberText:a.label,numberX:l+4,numberY:d,numberAlign:"left",labelX:l+4,labelY:d});}return s}hitTest(t,n,i,o){let s=this.box(i);return s!=null&&lt(t,n,s.left,s.top,s.right,s.bot,o)}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var Bh=[4,8,12,16,24,32,48,64],OL=24,NL=.75;function Zb(r,e){if(!Number.isInteger(r)||!Number.isInteger(e)||e<=0)return false;let t=r*r-1;return e%2===1?t%e===0:e%8===0?t%e!==0?false:t/e%2!==0:false}function Qb(r){let e=[];for(let t=0;t<r;t+=1)Zb(t,r)&&e.push(t);return e}var ui=class extends Z{constructor(t){super(t);this.type="dedekind";this.maxCurvature===void 0&&(this.maxCurvature=OL);}anchorSchema(){return {min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}box(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=Math.min(t.xOf(n.time),t.xOf(i.time)),l=Math.max(t.xOf(n.time),t.xOf(i.time)),d=Math.min(o,s),u=Math.max(o,s),h=l-a,p=u-d;if(h<1||p<1)return null;let m=p,g=h/m;return {left:a,right:l,top:d,bot:u,unitPx:m,x0:0,realSpan:g}}geodesics(t){let n=this.box(t);if(!n)return null;let{left:i,top:o,bot:s,unitPx:a,x0:l,realSpan:d}=n,u=Math.max(1,Math.min(64,Math.round(this.maxCurvature))),h=l-1/u,p=l+d+1/u,m=i+d*a,g=[],b=Math.floor(h*2),f=Math.ceil(p*2);for(let v=b;v<=f;v+=1){if(v%2===0)continue;let w=i+(v/2-l)*a;w<i-.5||w>m+.5||g.push({kind:"vline",x:w,y0:s,y1:o});}for(let v=1;v<=u;v+=1){let w=1/v,x=w*a;if(x<NL)continue;let T=Qb(v);if(T.length===0)continue;let M=Math.floor(h)-1,C=Math.ceil(p)+1;for(let L=M;L<=C;L+=1)for(let y of T){let E=y/v+L;if(E+w<h||E-w>p)continue;let S=i+(E-l)*a;S+x<i-1||S-x>m+1||g.push({kind:"arc",cx:S,cy:s,r:x});}}return g}hitTest(t,n,i,o){let s=this.box(i);return s!=null&&lt(t,n,s.left,s.top,s.right,s.bot,o)}handlePoints(t){let n=this.box(t);return n?[[n.left,n.top],[n.right,n.bot]]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.box(t);return n?{x:n.left,y:n.top,w:n.right-n.left,h:n.bot-n.top}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,{path:"maxCurvature",label:c("drawing.dedekind.maxCurvature","Max curvature"),kind:"number",min:4,max:64,step:4,group:"behavior"},...Y]}}writeProps(){return {maxCurvature:this.maxCurvature}}readProps(t){typeof t.maxCurvature=="number"&&Number.isFinite(t.maxCurvature)&&(this.maxCurvature=Math.max(1,Math.min(64,Math.round(t.maxCurvature))));}};var Vh=[3,4,5,6,8,10,12],Hh=[1.5,2,2.5,3,4,5],dc=6,FL=2;function _h(r=dc){return [...Xb(Qi.length,r)]}function BL(r){if(!r||typeof r!="object")return null;let e=r;return typeof e.ratio!="number"||typeof e.color!="string"?null:{ratio:e.ratio,color:e.color,enabled:e.enabled!==false,...typeof e.label=="string"&&e.label?{label:e.label}:{}}}var eo={path:"showRatios",label:c("drawing.sonic.showRatios","Show ratios"),kind:"boolean",group:"behavior"},It=class extends Z{constructor(e){super(e),this.waveCount===void 0&&(this.waveCount=dc),this.showRatios===void 0&&(this.showRatios=true);let t=Array.isArray(e.props?.levels);this.levels||(this.levels=this.defaultLevels().map(n=>({...n}))),!t&&this.shouldSyncWaveCount()&&this.syncLevelsToWaveCount();}shouldSyncWaveCount(){return true}syncLevelsToWaveCount(){let e=Math.max(1,Math.min(this.levels.length,Math.round(this.waveCount)));this.waveCount=e;for(let t=0;t<this.levels.length;t+=1)this.levels[t].enabled=t<e;}editableLevels(){return this.levels}anchorSchema(){return {min:2,max:2,slots:[{role:"d1",free:"both"},{role:"d2",free:"both"}]}}geom(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=e.yOf(t.price,this.paneId),o=e.yOf(n.price,this.paneId);if(i==null||o==null)return null;let s=e.xOf(t.time),a=e.xOf(n.time),l=(s+a)/2,d=(i+o)/2,u=Math.hypot(a-s,o-i)/2;if(u<1)return null;let h=a-s,p=o-i,m=Math.hypot(h,p);m<1e-9?(h=1,p=0):(h/=m,p/=m);let g=this.levels.filter(C=>C.enabled&&C.ratio>0).slice().sort((C,L)=>C.ratio-L.ratio);if(g.length===0)return null;let b=Math.max(1,this.machNumber()),f=[];for(let C of g){let L=C.ratio*u;f.push({cx:l+b*(L-u)*h,cy:d+b*(L-u)*p,r:L,color:C.color,ratio:C.ratio});}let v=l-b*u*h,w=d-b*u*p,x=f[f.length-1].r,T=b*x+2*u,M=[];if(b<=1+1e-9){let C=-p,L=h;M.push([v-C*T,w-L*T,v+C*T,w+L*T]);}else {let C=Math.asin(1/b),L=Math.cos(C),y=Math.sin(C),E=(G,j,se)=>[G*L-j*se*y,G*se*y+j*L],[S,P]=E(h,p,1),[A,F]=E(h,p,-1);M.push([v,w,v+S*T,w+P*T]),M.push([v,w,v+A*T,w+F*T]);}return {c0x:l,c0y:d,R:u,fx:h,fy:p,noseX:v,noseY:w,circles:f,rays:M}}hitTest(e,t,n,i){let o=this.geom(n);if(!o)return false;for(let s of o.circles)if(Math.abs(Math.hypot(e-s.cx,t-s.cy)-s.r)<=i)return true;return o.rays.some(s=>fe(e,t,s[0],s[1],s[2],s[3])<=i)}handlePoints(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return [];let i=e.yOf(t.price,this.paneId),o=e.yOf(n.price,this.paneId);return i==null||o==null?[]:[[e.xOf(t.time),i],[e.xOf(n.time),o]]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.geom(e);if(!t)return null;let n=t.noseX,i=t.noseX,o=t.noseY,s=t.noseY;for(let a of t.circles)n=Math.min(n,a.cx-a.r),i=Math.max(i,a.cx+a.r),o=Math.min(o,a.cy-a.r),s=Math.max(s,a.cy+a.r);for(let a of t.rays)n=Math.min(n,a[0],a[2]),i=Math.max(i,a[0],a[2]),o=Math.min(o,a[1],a[3]),s=Math.max(s,a[1],a[3]);return {x:n,y:o,w:i-n,h:s-o}}priceRange(){let e=this.anchors[0],t=this.anchors[1];return !e||!t?null:{min:Math.min(e.price,t.price),max:Math.max(e.price,t.price)}}applySettings(e){if(super.applySettings(e),Object.prototype.hasOwnProperty.call(e,"waveCount")&&typeof this.waveCount=="number"){let t=Math.max(1,Math.min(this.levels.length,Math.round(this.waveCount)));this.waveCount=t;for(let n=0;n<this.levels.length;n+=1)this.levels[n].enabled=n<t;}}schema(){return {fields:[...K,{path:"waveCount",label:c("drawing.sonic.waveCount","Waves"),kind:"number",min:3,max:12,step:1,group:"behavior"},eo,...Y]}}writeProps(){return {waveCount:this.waveCount,showRatios:this.showRatios,levels:this.levels.map(e=>({...e}))}}readProps(e){if(typeof e.waveCount=="number"&&Number.isFinite(e.waveCount)&&(this.waveCount=Math.max(2,Math.min(12,Math.round(e.waveCount)))),typeof e.showRatios=="boolean"&&(this.showRatios=e.showRatios),Array.isArray(e.levels)){let t=e.levels.map(BL).filter(n=>n!=null);t.length&&(this.levels=t);}}},Ss=class extends It{constructor(){super(...arguments);this.type="sonic";}defaultLevels(){return _h(dc)}machNumber(){return 1}},Cs=class extends It{constructor(t){super(t);this.type="supersonic";this.mach===void 0&&(this.mach=FL);}defaultLevels(){return _h(dc)}machNumber(){return Math.max(1.01,this.mach)}schema(){return {fields:[...K,{path:"mach",label:c("drawing.supersonic.mach","Mach number"),kind:"number",min:1.5,max:5,step:.5,group:"behavior"},{path:"waveCount",label:c("drawing.supersonic.waveCount","Waves"),kind:"number",min:3,max:12,step:1,group:"behavior"},eo,...Y]}}writeProps(){return {...super.writeProps(),mach:this.mach}}readProps(t){super.readProps(t),typeof t.mach=="number"&&Number.isFinite(t.mach)&&(this.mach=Math.max(1.01,Math.min(20,t.mach)));}};var Jb=De([.236,.382,.5,.618,.786,1,1.618,2.618,4.236,6.854,11.09]),VL=2,uc=class extends It{constructor(){super(...arguments);this.type="goldensonic";}shouldSyncWaveCount(){return false}defaultLevels(){return Jb}machNumber(){return 1}schema(){return {fields:[...K,eo,...Y]}}},hc=class extends It{constructor(t){super(t);this.type="goldensupersonic";this.mach===void 0&&(this.mach=VL);}shouldSyncWaveCount(){return false}defaultLevels(){return Jb}machNumber(){return Math.max(1.01,this.mach)}schema(){return {fields:[...K,{path:"mach",label:c("drawing.goldensupersonic.mach","Mach number"),kind:"number",min:1.5,max:5,step:.5,group:"behavior"},eo,...Y]}}writeProps(){return {...super.writeProps(),mach:this.mach}}readProps(t){super.readProps(t),typeof t.mach=="number"&&Number.isFinite(t.mach)&&(this.mach=Math.max(1.01,Math.min(20,t.mach)));}};var nt=class extends Z{legRatios(){return false}fillTriangles(){return []}necklineIndices(){return null}anchorSchema(){let e=this.vertexLabels().length,t=[];for(let n=0;n<e;n+=1)t.push({role:`p${n}`,free:"both"});return {min:e,max:e,slots:t}}handlePoints(e){let t=[];for(let n of this.anchors){let i=e.yOf(n.price,this.paneId);if(i==null)return [];t.push([e.xOf(n.time),i]);}return t}hitTest(e,t,n,i){let o=this.handlePoints(n);return o.length>=2&&qi(e,t,o)<=i}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.handlePoints(e);if(t.length===0)return null;let n=t.map(a=>a[0]),i=t.map(a=>a[1]),o=Math.min(...n),s=Math.min(...i);return {x:o,y:s,w:Math.max(...n)-o,h:Math.max(...i)-s}}priceRange(){if(this.anchors.length===0)return null;let e=this.anchors.map(t=>t.price);return {min:Math.min(...e),max:Math.max(...e)}}patternName(){return null}ratioOk(e){return null}valid(){return null}ratioAt(e){let t=this.anchors[e-2],n=this.anchors[e-1],i=this.anchors[e];if(!t||!n||!i)return null;let o=Math.abs(n.price-t.price);return o<1e-9?null:Math.abs(i.price-n.price)/o}schema(){return {fields:[...K,...this.fillTriangles().length?Ce:[]]}}};var pc=class extends nt{constructor(){super(...arguments);this.type="xabcd";}vertexLabels(){return ["X","A","B","C","D"]}legRatios(){return true}fillTriangles(){return [[0,1,2],[2,3,4]]}};var mc=class extends nt{constructor(){super(...arguments);this.type="abcd";}vertexLabels(){return ["A","B","C","D"]}legRatios(){return true}};var gc=class extends nt{constructor(){super(...arguments);this.type="elliottimpulse";}vertexLabels(){return ["1","2","3","4","5"]}};var fc=class extends nt{constructor(){super(...arguments);this.type="elliottcorrection";}vertexLabels(){return ["A","B","C"]}};var HL=c("drawing.headshoulders.leftShoulder","LS"),_L=c("drawing.headshoulders.head","H"),zL=c("drawing.headshoulders.rightShoulder","RS"),bc=class extends nt{constructor(){super(...arguments);this.type="headshoulders";}vertexLabels(){return ["",HL,"",_L,"",zL,""]}necklineIndices(){return [2,4]}};var At=class extends nt{vertexLabels(){return ["X","A","B","C","D"]}legRatios(){return true}fillTriangles(){return [[0,1,2],[2,3,4]]}legValue(e){let[t,n,i,o,s]=this.anchors;if(!t||!n||!i||!o||!s)return null;let a=(h,p)=>Math.abs(p.price-h.price),l=a(t,n),d=a(n,i),u=a(i,o);switch(e){case "ab":return l<1e-9?null:d/l;case "bc":return d<1e-9?null:u/d;case "cd":return u<1e-9?null:a(o,s)/u;default:return l<1e-9?null:a(n,s)/l}}inBand(e,t){return e!=null&&e>=t.min&&e<=t.max}ratioOk(e){let t=this.ranges();return e===2?this.inBand(this.legValue("ab"),t.ab):e===3?this.inBand(this.legValue("bc"),t.bc):e===4?this.inBand(this.legValue("cd"),t.cd):null}valid(){if(this.anchors.length<5)return null;let e=this.ranges();return this.inBand(this.legValue("ab"),e.ab)&&this.inBand(this.legValue("bc"),e.bc)&&this.inBand(this.legValue("cd"),e.cd)&&this.inBand(this.legValue("ad"),e.ad)}};var vc=class extends At{constructor(){super(...arguments);this.type="gartley";}patternName(){return c("drawing.gartley.patternName","Gartley")}ranges(){return {ab:{min:.55,max:.68},bc:{min:.382,max:.886},cd:{min:1.13,max:1.618},ad:{min:.74,max:.83}}}};var yc=class extends At{constructor(){super(...arguments);this.type="bat";}patternName(){return c("drawing.bat.patternName","Bat")}ranges(){return {ab:{min:.382,max:.5},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:.84,max:.92}}}};var wc=class extends At{constructor(){super(...arguments);this.type="butterfly";}patternName(){return c("drawing.butterfly.patternName","Butterfly")}ranges(){return {ab:{min:.74,max:.83},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:1.272,max:1.618}}}};var xc=class extends At{constructor(){super(...arguments);this.type="crab";}patternName(){return c("drawing.crab.patternName","Crab")}ranges(){return {ab:{min:.382,max:.618},bc:{min:.382,max:.886},cd:{min:2.618,max:3.618},ad:{min:1.55,max:1.69}}}};var Sc=class extends At{constructor(){super(...arguments);this.type="shark";}patternName(){return c("drawing.shark.patternName","Shark")}ranges(){return {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}}}};var WL={min:1.272,max:1.414},GL={min:.74,max:.83},Cc=class extends At{constructor(){super(...arguments);this.type="cypher";}patternName(){return c("drawing.cypher.patternName","Cypher")}ranges(){return {ab:{min:.382,max:.618},bc:{min:0,max:1/0},cd:{min:0,max:1/0},ad:{min:0,max:1/0}}}xcOverXa(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[3];if(!t||!n||!i)return null;let o=Math.abs(n.price-t.price);return o<1e-9?null:Math.abs(i.price-t.price)/o}cdOverXc(){let t=this.anchors[0],n=this.anchors[3],i=this.anchors[4];if(!t||!n||!i)return null;let o=Math.abs(n.price-t.price);return o<1e-9?null:Math.abs(i.price-n.price)/o}ratioOk(t){return t===2?this.inBand(this.legValue("ab"),this.ranges().ab):null}valid(){return this.anchors.length<5?null:this.inBand(this.legValue("ab"),this.ranges().ab)&&this.inBand(this.xcOverXa(),WL)&&this.inBand(this.cdOverXc(),GL)}};var ev={priceChange:c("drawing.measure.priceChange","{change} ({percent}%)"),barsAndDuration:c("drawing.measure.barsAndDuration","{count, plural, one {{bars} bar} other {{bars} bars}}, {duration}")};function tv(r){return `${r>=0?"+":""}${r.toFixed(2)}`}var hi=class extends Z{constructor(e){super(e),this.showPrice===void 0&&(this.showPrice=true),this.showDate===void 0&&(this.showDate=true);}anchorSchema(){return {min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}measureLabel(e,t){let n=[];return this.showPrice&&n.push(this.priceLabel(t)),this.showDate&&n.push(this.timeLabel(e,t)),n}isUp(){let e=this.anchors[0],t=this.anchors[1];return e!=null&&t!=null&&t.price>=e.price}priceLabel(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return "";let i=n.price-t.price,o=t.price!==0?i/t.price*100:0;return X(e,ev.priceChange,{change:qe(tv(i),e),percent:qe(tv(o),e)})}timeLabel(e,t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return "";let o=(t??Ae()).format.duration(i.time-n.time,{style:"span",surface:"drawing"}),s=e.barsBetween?Math.round(e.barsBetween(n.time,i.time)):null;return s!=null?X(t,ev.barsAndDuration,{count:s,bars:qe(String(s),t),duration:o}):o}rect(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=e.yOf(t.price,this.paneId),o=e.yOf(n.price,this.paneId);return i==null||o==null?null:{x1:e.xOf(t.time),y1:i,x2:e.xOf(n.time),y2:o}}hitTest(e,t,n,i){let o=this.rect(n);return o!=null&&lt(e,t,o.x1,o.y1,o.x2,o.y2,i)}handlePoints(e){let t=this.rect(e);return t?[[t.x1,t.y1],[t.x2,t.y2]]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.rect(e);return t?{x:Math.min(t.x1,t.x2),y:Math.min(t.y1,t.y2),w:Math.abs(t.x2-t.x1),h:Math.abs(t.y2-t.y1)}:null}priceRange(){let e=this.anchors[0],t=this.anchors[1];return !e||!t?null:{min:Math.min(e.price,t.price),max:Math.max(e.price,t.price)}}schema(){return {fields:[{path:"showPrice",label:c("drawing.measure.showPrice","Show price"),kind:"boolean",group:"behavior"},{path:"showDate",label:c("drawing.measure.showDate","Show date"),kind:"boolean",group:"behavior"},...K.filter(e=>e.path!=="style.lineColor"),{path:"text.color",label:c("drawing.field.textColor","Text color"),kind:"color",group:"text"},{path:"text.size",label:c("drawing.field.textSize","Text size"),kind:"select",options:St,group:"text"}]}}writeProps(){return {showPrice:this.showPrice,showDate:this.showDate}}readProps(e){typeof e.showPrice=="boolean"&&(this.showPrice=e.showPrice),typeof e.showDate=="boolean"&&(this.showDate=e.showDate);}};var Tc=class extends hi{constructor(){super(...arguments);this.type="datepricerange";}};var to={header:c("drawing.position.header","{direction, select, long {LONG} other {SHORT}} \xB7 R:R {ratio}"),lossSize:c("drawing.position.lossSize","Loss {loss} \xB7 Size {size}"),target:c("drawing.position.targetLabel","Target +{percent}%"),targetAt:c("drawing.position.targetLabelAt","Target +{percent}% @ {price}"),stop:c("drawing.position.stopLabel","Stop \u2212{percent}%"),stopAt:c("drawing.position.stopLabelAt","Stop \u2212{percent}% @ {price}")},kc=[{value:"long",label:c("drawing.position.option.long","Long")},{value:"short",label:c("drawing.position.option.short","Short")}],Ue=class Ue extends Z{constructor(t){super(t);this.type="position";this.riskPercent===void 0&&(this.riskPercent=Ue.DEFAULT_RISK_PERCENT),this.accountBalance===void 0&&(this.accountBalance=Ue.DEFAULT_ACCOUNT_BALANCE),this.showText===void 0&&(this.showText=true),this.showHeader===void 0&&(this.showHeader=true),this.showPrices===void 0&&(this.showPrices=false),this.showLossSize===void 0&&(this.showLossSize=true),this.showTargetLabel===void 0&&(this.showTargetLabel=true),this.showStopLabel===void 0&&(this.showStopLabel=true),this.profitColor===void 0&&(this.profitColor=Ue.DEFAULT_PROFIT_COLOR),this.lossColor===void 0&&(this.lossColor=Ue.DEFAULT_LOSS_COLOR);}directionLabel(){let t=this.prices();return t&&t.target>=t.entry?"LONG":"SHORT"}get direction(){return this.directionLabel()==="LONG"?"long":"short"}set direction(t){let n=this.anchors[0],i=this.anchors[1],o=this.anchors[2];!n||!i||!o||(t==="long"||t==="short")&&t!==this.direction&&(i.price=2*n.price-i.price,o.price=2*n.price-o.price);}get quantity(){return this.positionSize()}set quantity(t){let n=this.prices();if(!n||!Number.isFinite(t)||t<0)return;let i=Math.abs(n.entry-n.stop);i<1e-9||this.accountBalance<=0||(this.riskPercent=t*i/this.accountBalance*100);}get entryPrice(){return this.anchors[0]?.price??0}set entryPrice(t){let n=this.anchors[0];n&&Number.isFinite(t)&&(n.price=t,this.constrainHandleDrag(0));}get stopPrice(){return this.anchors[1]?.price??0}set stopPrice(t){let n=this.anchors[1];n&&Number.isFinite(t)&&(n.price=t,this.constrainHandleDrag(1));}get targetPrice(){return this.anchors[2]?.price??0}set targetPrice(t){let n=this.anchors[2];n&&Number.isFinite(t)&&(n.price=t,this.constrainHandleDrag(2));}anchorSchema(){return {min:2,max:2,slots:[{role:"entry",free:"both"},{role:"stop",free:"both"},{role:"target",free:"both"}]}}onPlaced(t){let n=this.anchors[0];if(!n)return;let i=t.xOf(n.time),o=t.yOf(n.price,this.paneId);if(o==null)return;let s=this.anchors[1],a=s?t.yOf(s.price,this.paneId):null,l,d;s&&a!=null&&Math.abs(a-o)>=Ue.MIN_DRAG_PX?(l=a,d=i+Math.max(Math.abs(t.xOf(s.time)-i),Ue.MIN_WIDTH_PX)):(l=o-Ue.DEFAULT_RISK_PX*Ue.DEFAULT_RR,d=i+Ue.DEFAULT_WIDTH_PX);let u=o-(l-o)/Ue.DEFAULT_RR,h=t.pxToPoint(d,o,this.paneId).time;this.anchors=[{time:n.time,price:n.price},{time:h,price:t.pxToPoint(i,u,this.paneId).price},{time:h,price:t.pxToPoint(i,l,this.paneId).price}];}constrainHandleDrag(t){let n=this.anchors[0],i=this.anchors[1],o=this.anchors[2];if(!n||!i||!o)return;let s=Math.sign(i.price-n.price),a=Math.sign(o.price-n.price);s===0||a===0||s!==a||(t===2?i.price=2*n.price-i.price:o.price=2*n.price-o.price);}resolved(){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;if(this.anchors[2])return [t,n,this.anchors[2]];let i={time:n.time,price:t.price-(n.price-t.price)/Ue.DEFAULT_RR};return [t,i,n]}prices(){let t=this.resolved();return t?{entry:t[0].price,stop:t[1].price,target:t[2].price}:null}rr(){let t=this.prices();if(!t)return 0;let n=Math.abs(t.entry-t.stop);return n<1e-9?0:Math.abs(t.target-t.entry)/n}rewardPct(){let t=this.prices();return t&&t.entry!==0?Math.abs(t.target-t.entry)/t.entry*100:0}riskPct(){let t=this.prices();return t&&t.entry!==0?Math.abs(t.entry-t.stop)/t.entry*100:0}dollarLoss(){return Math.max(0,this.accountBalance)*(Math.max(0,this.riskPercent)/100)}positionSize(){let t=this.prices();if(!t)return 0;let n=Math.abs(t.entry-t.stop);return n<1e-9?0:this.dollarLoss()/n}headerLabel(t){return X(t,to.header,{direction:this.directionLabel()==="LONG"?"long":"short",ratio:qe(this.rr().toFixed(2),t)})}lossSizeLabel(t){return X(t,to.lossSize,{loss:qe(UL(this.dollarLoss()),t),size:qe($L(this.positionSize()),t)})}targetLabel(t){let n=this.prices(),i=qe(this.rewardPct().toFixed(2),t);return this.showPrices&&n?X(t,to.targetAt,{percent:i,price:qe(nv(n.target),t)}):X(t,to.target,{percent:i})}stopLabel(t){let n=this.prices(),i=qe(this.riskPct().toFixed(2),t);return this.showPrices&&n?X(t,to.stopAt,{percent:i,price:qe(nv(n.stop),t)}):X(t,to.stop,{percent:i})}levelDisplayValue(t,n){let i=this.prices();if(!i)return 0;let o=t==="stop"?i.stop:i.target;return rv(n==="price"?o:Math.abs(o-i.entry))}levelPriceFromDisplay(t,n,i){let o=this.prices();if(!o||n==="price")return i;let s=t==="stop"?o.stop:o.target,a=Math.sign(s-o.entry);return a===0&&(a=(t==="target"?1:-1)*(this.direction==="long"?1:-1)),o.entry+a*Math.abs(i)}box(t){let n=this.handlePoints(t);if(n.length<3)return null;let i=n.map(o=>o[0]);return {x1:Math.min(...i),x2:Math.max(...i),ey:n[0][1],sy:n[1][1],ty:n[2][1]}}layout(t){return this.box(t)}hitTest(t,n,i,o){let s=this.box(i);if(!s)return false;let a=Math.min(s.ey,s.sy,s.ty),l=Math.max(s.ey,s.sy,s.ty);return lt(t,n,s.x1,a,s.x2,l,o)}handlePoints(t){let n=this.resolved();if(!n)return [];let i=[];for(let o of n){let s=t.yOf(o.price,this.paneId);if(s==null)return [];i.push([t.xOf(o.time),s]);}return i}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.box(t);if(!n)return null;let i=Math.min(n.ey,n.sy,n.ty);return {x:n.x1,y:i,w:n.x2-n.x1,h:Math.max(n.ey,n.sy,n.ty)-i}}priceRange(){let t=this.resolved();if(!t)return null;let n=t.map(i=>i.price);return {min:Math.min(...n),max:Math.max(...n)}}schema(){return {fields:[{path:"riskPercent",label:c("drawing.position.riskPercent","Risk %"),kind:"number",min:0,max:100,step:.1,group:"behavior"},{path:"accountBalance",label:c("drawing.position.accountBalance","Account balance"),kind:"number",min:0,max:1e12,step:1,group:"behavior"},{path:"quantity",label:c("drawing.position.quantity","Position size"),kind:"number",group:"behavior"},{path:"direction",label:c("drawing.position.direction","Direction"),kind:"select",options:kc,group:"behavior"},{path:"entryPrice",label:c("drawing.position.entryPrice","Entry price"),kind:"number",group:"behavior"},{path:"stopPrice",label:c("drawing.position.stopPrice","Stop price"),kind:"number",group:"behavior"},{path:"targetPrice",label:c("drawing.position.targetPrice","Target price"),kind:"number",group:"behavior"},{path:"showText",label:c("drawing.position.showText","Show text"),kind:"boolean",group:"behavior"},{path:"showHeader",label:c("drawing.position.showHeader","Show direction & ratio"),kind:"boolean",group:"behavior"},{path:"showLossSize",label:c("drawing.position.showLossSize","Show loss & size"),kind:"boolean",group:"behavior"},{path:"showTargetLabel",label:c("drawing.position.showTargetLabel","Show target label"),kind:"boolean",group:"behavior"},{path:"showStopLabel",label:c("drawing.position.showStopLabel","Show stop label"),kind:"boolean",group:"behavior"},{path:"showPrices",label:c("drawing.position.showPrices","Show level prices"),kind:"boolean",group:"behavior"},{path:"profitColor",label:c("drawing.position.profitColor","Profit zone"),kind:"color",group:"fill"},{path:"lossColor",label:c("drawing.position.lossColor","Loss zone"),kind:"color",group:"fill"},...K.filter(t=>t.path!=="style.lineColor"),{path:"text.color",label:c("drawing.position.textColor","Text color"),kind:"color",group:"text"},{path:"text.size",label:c("drawing.position.textSize","Text size"),kind:"select",options:St,group:"text"}]}}writeProps(){return {riskPercent:this.riskPercent,accountBalance:this.accountBalance,showText:this.showText,showHeader:this.showHeader,showPrices:this.showPrices,showLossSize:this.showLossSize,showTargetLabel:this.showTargetLabel,showStopLabel:this.showStopLabel,profitColor:this.profitColor,lossColor:this.lossColor}}readProps(t){typeof t.riskPercent=="number"&&Number.isFinite(t.riskPercent)&&(this.riskPercent=t.riskPercent),typeof t.accountBalance=="number"&&Number.isFinite(t.accountBalance)&&(this.accountBalance=t.accountBalance),typeof t.showText=="boolean"&&(this.showText=t.showText),typeof t.showHeader=="boolean"&&(this.showHeader=t.showHeader),typeof t.showPrices=="boolean"&&(this.showPrices=t.showPrices),typeof t.showLossSize=="boolean"&&(this.showLossSize=t.showLossSize),typeof t.showTargetLabel=="boolean"&&(this.showTargetLabel=t.showTargetLabel),typeof t.showStopLabel=="boolean"&&(this.showStopLabel=t.showStopLabel),typeof t.profitColor=="string"&&(this.profitColor=t.profitColor),typeof t.lossColor=="string"&&(this.lossColor=t.lossColor);}};Ue.DEFAULT_RR=2,Ue.MIN_DRAG_PX=6,Ue.DEFAULT_RISK_PX=64,Ue.DEFAULT_WIDTH_PX=150,Ue.MIN_WIDTH_PX=48,Ue.DEFAULT_RISK_PERCENT=1,Ue.DEFAULT_ACCOUNT_BALANCE=1e4,Ue.DEFAULT_PROFIT_COLOR=bl,Ue.DEFAULT_LOSS_COLOR=vl;var Rt=Ue;function UL(r){if(!Number.isFinite(r))return "0";let e=Math.round(r*100)/100;return Number.isInteger(e)?String(e):e.toFixed(2)}function $L(r){return !Number.isFinite(r)||r===0?"0":r>=100?r.toFixed(2):r>=1?r.toFixed(4).replace(/\.?0+$/,""):r.toPrecision(4).replace(/\.?0+$/,"")}function nv(r){return Number.isFinite(r)?Math.abs(r)>=1?r.toFixed(2):r.toPrecision(4).replace(/\.?0+$/,""):"0"}function rv(r){return Math.round(r*1e8)/1e8}var no=[{value:"auto",label:c("drawing.magnifier.option.auto","Auto"),ms:0},{value:"1",label:c("drawing.magnifier.option.n1","1m"),ms:6e4},{value:"5",label:c("drawing.magnifier.option.n5","5m"),ms:3e5},{value:"15",label:c("drawing.magnifier.option.n15","15m"),ms:9e5},{value:"30",label:c("drawing.magnifier.option.n30","30m"),ms:18e5},{value:"60",label:c("drawing.magnifier.option.n60","1h"),ms:36e5},{value:"240",label:c("drawing.magnifier.option.n240","4h"),ms:144e5},{value:"D",label:c("drawing.magnifier.option.d","1D"),ms:864e5}];function ro(r){if(!(r>0))return [...no];let e=no.filter(t=>t.ms>0&&t.ms<r);return e.length>0?[no[0],...e]:[]}function Ts(r){let e=no.find(n=>n.value===r);if(e)return e.label;let t=Number(r);return Number.isFinite(t)&&t>0?t%1440===0?`${t/1440}D`:t%60===0?`${t/60}h`:`${t}m`:r}function iv(){return {timeframe:"auto",upColor:"",downColor:""}}var Dt=class extends Z{constructor(t){super(t);this.type="magnifier";this.chipRect=null;this.magnifier||(this.magnifier=iv());}anchorSchema(){return {min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}placementMode(){return "drag"}rect(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?null:{x1:t.xOf(n.time),y1:o,x2:t.xOf(i.time),y2:s}}hitTest(t,n,i,o){let s=this.rect(i);return s?lt(t,n,s.x1,s.y1,s.x2,s.y2)?true:[[s.x1,s.y1,s.x2,s.y1],[s.x2,s.y1,s.x2,s.y2],[s.x2,s.y2,s.x1,s.y2],[s.x1,s.y2,s.x1,s.y1]].some(l=>fe(t,n,l[0],l[1],l[2],l[3])<=o):false}handlePoints(t){let n=this.rect(t);return n?[[n.x1,n.y1],[n.x2,n.y2]]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.rect(t);return n?{x:Math.min(n.x1,n.x2),y:Math.min(n.y1,n.y2),w:Math.abs(n.x2-n.x1),h:Math.abs(n.y2-n.y1)}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[{path:"magnifier.timeframe",label:c("drawing.magnifier.magnifierTimeframe","Timeframe"),kind:"select",options:no,group:"behavior"},...fr,{path:"magnifier.upColor",label:c("drawing.magnifier.magnifierUpColor","Up candles"),kind:"color",group:"fill"},{path:"magnifier.downColor",label:c("drawing.magnifier.magnifierDownColor","Down candles"),kind:"color",group:"fill"}]}}writeProps(){return {...this.magnifier}}readProps(t){this.magnifier={...iv(),...t};}};function ov(r,e){if(r.length===0)return -1;let t=0,n=r.length-1;for(;t<n;){let i=t+n>>1;r[i].time<e?t=i+1:n=i;}return t>0&&Math.abs(r[t-1].time-e)<=Math.abs(r[t].time-e)?t-1:t}function YL(r,e){let t=r[e-1],n=r[e+1];return !t||!n||!r[e]?null:n.low>t.high?{bull:true,top:n.low,bottom:t.high}:n.high<t.low?{bull:false,top:t.low,bottom:n.high}:null}function KL(r,e){for(let t=0;t<=3;t+=1)for(let n of t===0?[e]:[e-t,e+t]){let i=YL(r,n);if(i)return {index:n,...i}}return null}function sv(r,e){let t=KL(r,e);if(!t)return null;let{index:n,bull:i,top:o,bottom:s}=t,a=(o+s)/2,l=null,d=null,u=null,h=null;for(let p=n+2;p<r.length&&h===null;p+=1){let m=r[p],g=i?m.low:m.high,b=f=>i?g<=f:g>=f;l===null&&b(i?o:s)&&(l=p),d===null&&b(a)&&(d=p),u===null&&b(i?s:o)&&(u=p),u!==null&&(i?m.close<s:m.close>o)&&(h=p);}return {index:n,bull:i,top:o,bottom:s,mid:a,tested:l,half:d,filled:u,inverted:h}}function av(r,e,t){let n=r[e];if(!n)return null;let i=n.close<n.open,o=t==="body"?Math.max(n.open,n.close):n.high,s=t==="body"?Math.min(n.open,n.close):n.low,a=(o+s)/2,l=false,d=null,u=null,h=null,p=false,m=null;for(let g=e+1;g<r.length&&m===null;g+=1){let b=r[g];h===null?(l?(d===null&&(i?b.low<=o:b.high>=s)&&(d=g),u===null&&(i?b.low<=a:b.high>=a)&&(u=g)):l=i?b.low>o:b.high<s,(i?b.close<s:b.close>o)&&(h=g)):p?(i?b.high>=s:b.low<=o)&&(m=g):p=i?b.high<s:b.low>o;}return {index:e,bull:i,top:o,bottom:s,mid:a,tested:d,half:u,broken:h,retest:m}}function lv(r,e,t){let n=r[e];if(!n)return null;let i=t==="high",o=i?n.high:n.low,s=null,a=null;for(let l=e+1;l<r.length&&a===null;l+=1){let d=r[l];(i?d.close>o:d.close<o)?a=l:s===null&&(i?d.high>o:d.low<o)&&(s=l);}return {index:e,high:i,price:o,swept:s,broken:a}}var cv=new WeakMap,ks=class extends Z{anchorSchema(){return {min:1,max:1,slots:[{role:"candle",free:"x"}]}}candles(e){let t=this.anchors[0];if(!t)return null;let n=cv.get(e);return n||(n=e.barsInRange?.(Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY)??[],cv.set(e,n)),n.length>0?{bars:n,at:ov(n,t.time)}:null}halfBar(e,t,n){let i=t[Math.max(0,n-1)],o=t[Math.min(t.length-1,Math.max(1,n))];return !i||!o||i===o?3:Math.max(1,Math.abs(e.xOf(o.time)-e.xOf(i.time))/2)}rightEdge(e,t,n){return n===null?Math.max(e.width,e.xOf(t[t.length-1].time)):e.xOf(t[n].time)+this.halfBar(e,t,n)}anchorHandle(e){let t=this.anchors[0],n=t?e.yOf(t.price,this.paneId):null;return t&&n!=null?[[e.xOf(t.time),n]]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}priceRange(){return null}},$n=class extends ks{zone(e){let t=this.candles(e),n=t&&this.formation(t.bars,t.at);if(!t||!n)return null;let i=e.yOf(n.top,this.paneId),o=e.yOf(n.bottom,this.paneId);if(i==null||o==null)return null;let{bars:s}=t,a=this.settings(),l=b=>e.xOf(s[b].time)-this.halfBar(e,s,b),d=Math.min(i,o),u=Math.max(i,o),h=e.yOf(n.mid,this.paneId)??(d+u)/2,p=n.flip&&{x1:l(n.flip.from),x2:this.rightEdge(e,s,n.flip.to),fill:n.bull?a.downColor:a.upColor},m=a.extend==="tested"?n.bull?n.top:n.bottom:a.extend==="half"?n.mid:n.bull?n.bottom:n.top,g=e.yOf(m,this.paneId);return {x1:l(n.start),x2:this.rightEdge(e,s,n.end),yTop:d,yBottom:u,fill:n.bull?a.upColor:a.downColor,border:a.border,midY:a.midline?h:null,faded:n.end!==null&&a.fade&&!p,marker:n.end!==null&&!p&&g!=null?{x:e.xOf(s[n.end].time),y:g}:null,flip:p,handle:[e.xOf(s[n.index].time),h]}}hitTest(e,t,n,i){let o=this.zone(n);if(!o){let a=this.anchors[0];return a!=null&&Math.abs(e-n.xOf(a.time))<=i}let s=t>=o.yTop-i&&t<=o.yBottom+i;return s&&e>=o.x1-i&&e<=o.x2+i?true:o.flip!=null&&s&&e>=o.flip.x1-i&&e<=o.flip.x2+i}handlePoints(e){let t=this.zone(e);return t?[t.handle]:this.anchorHandle(e)}bounds(e){let t=this.zone(e);if(!t)return null;let n=Math.min(e.width,t.flip?t.flip.x2:t.x2);return {x:t.x1,y:t.yTop,w:Math.max(1,n-t.x1),h:Math.max(1,t.yBottom-t.yTop)}}};var dv=[{value:"tested",label:c("drawing.fairvaluegap.option.tested","Until tested")},{value:"half",label:c("drawing.fairvaluegap.option.half","Until 50%")},{value:"filled",label:c("drawing.fairvaluegap.option.filled","Until filled")},{value:"always",label:c("drawing.fairvaluegap.option.always","Always")}];function uv(){return {extend:"filled",upColor:`${N}33`,downColor:`${O}33`,midline:true,border:false,fade:true,inverse:false}}var Lc=class extends $n{constructor(t){super(t);this.type="fairvaluegap";this.gap||(this.gap=uv());}settings(){return this.gap}formation(t,n){let i=sv(t,n);if(!i)return null;let{extend:o,inverse:s}=this.gap,a=s&&o==="filled"&&i.inverted!==null?{from:i.inverted,to:null}:null;return {...i,start:i.index-1,end:o==="always"?null:i[o],flip:a}}schema(){return {fields:[{path:"gap.extend",label:c("drawing.fairvaluegap.gapExtend","Extend right"),kind:"select",options:dv,group:"behavior"},{path:"gap.upColor",label:c("drawing.fairvaluegap.gapUpColor","Bullish"),kind:"color",group:"fill"},{path:"gap.downColor",label:c("drawing.fairvaluegap.gapDownColor","Bearish"),kind:"color",group:"fill"},{path:"gap.midline",label:c("drawing.fairvaluegap.gapMidline","Midline"),kind:"boolean",group:"line"},{path:"gap.border",label:c("drawing.fairvaluegap.gapBorder","Border"),kind:"boolean",group:"line"},{path:"gap.fade",label:c("drawing.fairvaluegap.gapFade","Fade at end"),kind:"boolean",group:"behavior",when:{path:"gap.extend",in:["tested","half","filled"]}},{path:"gap.inverse",label:c("drawing.fairvaluegap.gapInverse","Flip on close"),kind:"boolean",group:"behavior",when:{path:"gap.extend",in:["filled"]}}]}}writeProps(){return {...this.gap}}readProps(t){let n=uv(),i=t;this.gap={extend:dv.some(o=>o.value===i.extend)?i.extend:n.extend,upColor:typeof i.upColor=="string"?i.upColor:n.upColor,downColor:typeof i.downColor=="string"?i.downColor:n.downColor,midline:typeof i.midline=="boolean"?i.midline:n.midline,border:typeof i.border=="boolean"?i.border:n.border,fade:typeof i.fade=="boolean"?i.fade:n.fade,inverse:typeof i.inverse=="boolean"?i.inverse:n.inverse};}};var XL=[{value:"body",label:c("drawing.orderblock.option.body","Body")},{value:"wick",label:c("drawing.orderblock.option.wick","Full range")}],hv=[{value:"tested",label:c("drawing.orderblock.option.tested","Until tested")},{value:"half",label:c("drawing.orderblock.option.half","Until 50%")},{value:"broken",label:c("drawing.orderblock.option.broken","Until broken")},{value:"always",label:c("drawing.orderblock.option.always","Always")}];function pv(){return {range:"body",extend:"broken",upColor:`${N}29`,downColor:`${O}29`,midline:true,border:true,fade:true,breaker:true}}var Mc=class extends $n{constructor(t){super(t);this.type="orderblock";this.block||(this.block=pv());}settings(){return this.block}formation(t,n){let i=av(t,n,this.block.range);if(!i)return null;let{extend:o,breaker:s}=this.block,a=s&&o==="broken"&&i.broken!==null?{from:i.broken,to:i.retest}:null;return {...i,start:i.index,end:o==="always"?null:i[o],flip:a}}schema(){return {fields:[{path:"block.range",label:c("drawing.orderblock.blockRange","Zone"),kind:"select",options:XL,group:"behavior"},{path:"block.extend",label:c("drawing.orderblock.blockExtend","Extend right"),kind:"select",options:hv,group:"behavior"},{path:"block.upColor",label:c("drawing.orderblock.blockUpColor","Bullish"),kind:"color",group:"fill"},{path:"block.downColor",label:c("drawing.orderblock.blockDownColor","Bearish"),kind:"color",group:"fill"},{path:"block.midline",label:c("drawing.orderblock.blockMidline","Midline"),kind:"boolean",group:"line"},{path:"block.border",label:c("drawing.orderblock.blockBorder","Border"),kind:"boolean",group:"line"},{path:"block.fade",label:c("drawing.orderblock.blockFade","Fade at end"),kind:"boolean",group:"behavior",when:{path:"block.extend",in:["tested","half","broken"]}},{path:"block.breaker",label:c("drawing.orderblock.blockBreaker","Breaker"),kind:"boolean",group:"behavior",when:{path:"block.extend",in:["broken"]}}]}}writeProps(){return {...this.block}}readProps(t){let n=pv(),i=t;this.block={range:i.range==="body"||i.range==="wick"?i.range:n.range,extend:hv.some(o=>o.value===i.extend)?i.extend:n.extend,upColor:typeof i.upColor=="string"?i.upColor:n.upColor,downColor:typeof i.downColor=="string"?i.downColor:n.downColor,midline:typeof i.midline=="boolean"?i.midline:n.midline,border:typeof i.border=="boolean"?i.border:n.border,fade:typeof i.fade=="boolean"?i.fade:n.fade,breaker:typeof i.breaker=="boolean"?i.breaker:n.breaker};}};var mv=[{value:"swept",label:c("drawing.liquidity.option.swept","Until swept")},{value:"broken",label:c("drawing.liquidity.option.broken","Until broken")},{value:"always",label:c("drawing.liquidity.option.always","Always")}];function gv(){return {extend:"swept",markSweep:true}}var pi=class extends ks{constructor(t){super(t);this.type="liquidity";this.liq||(this.liq=gv());}anchorSchema(){return {min:1,max:1,slots:[{role:"candle",free:"both"}]}}state(t){let n=this.candles(t),i=this.anchors[0];if(!n||!i)return null;let o=n.bars[n.at];return lv(n.bars,n.at,i.price>=(o.high+o.low)/2?"high":"low")}line(t){let n=this.candles(t),i=this.state(t);if(!n||!i)return null;let o=t.yOf(i.price,this.paneId);if(o==null)return null;let{bars:s}=n,{extend:a,markSweep:l}=this.liq,d=a==="always"?null:a==="broken"?i.broken:i.swept??i.broken,u=t.xOf(s[i.index].time),h=null;if(l&&i.swept!==null&&(d===null||i.swept<=d)){let p=s[i.swept],m=t.yOf(i.high?p.high:p.low,this.paneId);m!=null&&(h={x:t.xOf(p.time),y:m+(i.high?-9:9)});}return {x1:u,x2:this.rightEdge(t,s,d),y:o,sweep:h,handle:[u,o]}}hitTest(t,n,i,o){let s=this.line(i);return s!=null&&t>=s.x1-o&&t<=s.x2+o&&Math.abs(n-s.y)<=o}handlePoints(t){let n=this.line(t);return n?[n.handle]:this.anchorHandle(t)}bounds(t){let n=this.line(t);return n?{x:n.x1,y:n.y-4,w:Math.max(1,Math.min(t.width,n.x2)-n.x1),h:8}:null}schema(){return {fields:[...K,{path:"liq.extend",label:c("drawing.liquidity.liqExtend","Extend right"),kind:"select",options:mv,group:"behavior"},{path:"liq.markSweep",label:c("drawing.liquidity.liqMarkSweep","Mark sweep"),kind:"boolean",group:"behavior"}]}}writeProps(){return {...this.liq}}readProps(t){let n=gv(),i=t;this.liq={extend:mv.some(o=>o.value===i.extend)?i.extend:n.extend,markSweep:typeof i.markSweep=="boolean"?i.markSweep:n.markSweep};}};var mi=new Map;function $(r){mi.set(r.type,r);}function fv(r,e){if(typeof r.label=="string"&&(r.placementHint===void 0||typeof r.placementHint=="string"))return r;let t={...r,label:X(e,r.label),placementHint:void 0};return r.placementHint!==void 0?t.placementHint=X(e,r.placementHint):delete t.placementHint,t}function _t(r,e){let t=mi.get(r);return t?fv(t,e):void 0}function bv(r){return [...mi.values()].map(e=>fv(e,r))}function zh(r){return mi.get(r)}function vv(){return [...mi.values()]}function Yn(r,e){let t=mi.get(r);if(!t)return null;let n={...t.defaultStyle,...e.style??{}};return t.create({...e,style:n})}function Ec(r){let e=Yn(r.type,{paneId:r.paneId});if(!e)return;r.style={...e.style};let t=r.text?.value;e.text?(r.text={...e.text},t!==void 0&&(r.text.value=t)):r.text=void 0;let n=e.serialize().props;n!==void 0&&r.applyProps(n);}function zt(r){let e=mi.get(r.type);return e?e.create(r):null}var jL=V('<line x1="4" y1="19" x2="20" y2="5"/>'),qL=V('<line x1="3" y1="12" x2="21" y2="12"/>');$({type:"trendline",group:"lines",label:c("drawing.trendline.label","Trend Line"),icon:jL,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Qr(r)});$({type:"hline",group:"lines",label:c("drawing.hline.label","Horizontal Line"),icon:qL,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"dashed"},create:r=>new Sl(r)});var ZL=V('<line x1="3" y1="20" x2="21" y2="6"/><circle cx="3" cy="20" r="1.6" fill="currentColor"/>'),QL=V('<rect x="4" y="6" width="16" height="12" rx="1"/>'),JL=V('<path d="M5 6h14M12 6v13"/>');$({type:"ray",group:"lines",label:c("drawing.ray.label","Ray"),icon:ZL,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Cl(r)});var eM=V('<path d="M5 19 19 5"/><path d="M5 19 8.5 19M5 19 5 15.5"/><path d="M19 5 15.5 5M19 5 19 8.5"/>'),tM=V('<line x1="12" y1="3" x2="12" y2="21"/>'),nM=V('<line x1="5" y1="12" x2="21" y2="12"/><circle cx="5" cy="12" r="1.6" fill="currentColor"/>'),rM=V('<line x1="3" y1="12" x2="21" y2="12"/><line x1="12" y1="3" x2="12" y2="21"/>'),iM=V('<path d="M4 20 20 4"/><rect x="9" y="9" width="9" height="6" rx="1"/>'),oM=V('<path d="M4 20 20 6"/><path d="M4 20 15 20"/><path d="M11 20a7 7 0 0 0-2-4.9"/>');$({type:"extendedline",group:"lines",label:c("drawing.extendedline.label","Extended Line"),icon:eM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Tl(r)});$({type:"vline",group:"lines",label:c("drawing.vline.label","Vertical Line"),icon:tM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new kl(r)});$({type:"hray",group:"lines",label:c("drawing.hray.label","Horizontal Ray"),icon:nM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Ll(r)});$({type:"crossline",group:"lines",label:c("drawing.crossline.label","Cross Line"),icon:rM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Ml(r)});$({type:"infoline",group:"lines",label:c("drawing.infoline.label","Info Line"),icon:iM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new El(r)});$({type:"trendangle",group:"lines",label:c("drawing.trendangle.label","Trend Angle"),icon:oM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Pl(r)});$({type:"box",group:"shapes",label:c("drawing.box.label","Rectangle"),icon:QL,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}26`},create:r=>new Il(r)});$({type:"text",group:"annotations",label:c("drawing.text.label","Text"),icon:JL,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Gn(r)});var sM=V('<path d="M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-6l-5 5v-5H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z"/>');$({type:"callout",group:"annotations",label:c("drawing.callout.label","Callout"),icon:sM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new xn(r)});var aM=V('<path d="M5 4h14a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-7l-4 4v-4H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1Z"/><path d="M8 8.5h8M8 12h5"/>'),lM=V('<rect x="10" y="4.5" width="11" height="8" rx="1.5"/><path d="M10 8.5 4 16"/><circle cx="3.5" cy="16.5" r="1.6" fill="currentColor" stroke="none"/>'),cM=V('<path d="M5 4.5h14a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-7l-4 4v-4H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2Z"/>'),dM=V('<path d="M3 12 7 8h12a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H7Z"/><path d="M10.5 12.5h6" stroke-width="1.4"/>'),uM=V('<path d="M12 11.5V21"/><rect x="5" y="4" width="14" height="7" rx="1"/><path d="M9 7.5h6"/>');$({type:"note",group:"annotations",label:c("drawing.note.label","Note"),icon:aM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new Jr(r)});$({type:"pricenote",group:"annotations",label:c("drawing.pricenote.label","Price Note"),icon:lM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new ti(r)});$({type:"comment",group:"annotations",label:c("drawing.comment.label","Comment"),icon:cM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new ni(r)});$({type:"pricelabel",group:"annotations",label:c("drawing.pricelabel.label","Price Label"),icon:dM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new ei(r)});$({type:"signpost",group:"annotations",label:c("drawing.signpost.label","Signpost"),icon:uM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new ri(r)});var hM=V('<line x1="3" y1="16" x2="21" y2="8"/><line x1="3" y1="21" x2="21" y2="13"/>'),pM=V('<line x1="3" y1="7" x2="21" y2="10"/><line x1="3" y1="18" x2="21" y2="14"/>'),mM=V('<circle cx="4" cy="12" r="1.6" fill="currentColor"/><line x1="4" y1="12" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>');$({type:"parallelchannel",group:"channels",label:c("drawing.parallelchannel.label","Parallel Channel"),icon:hM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Al(r)});$({type:"disjointchannel",group:"channels",label:c("drawing.disjointchannel.label","Disjoint Channel"),icon:pM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Rl(r)});var gM=V('<line x1="3" y1="7" x2="21" y2="7"/><line x1="3" y1="18" x2="21" y2="11"/>');$({type:"flattopbottom",group:"channels",label:c("drawing.flattopbottom.label","Flat Top/Bottom"),icon:gM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Dl(r)});var fM=V('<line x1="3" y1="8" x2="21" y2="4"/><line x1="3" y1="16" x2="21" y2="12"/><line x1="3" y1="12" x2="21" y2="8" stroke-dasharray="3 3"/>');$({type:"regressionchannel",group:"channels",label:c("drawing.regressionchannel.label","Linear Regression"),icon:fM,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:r=>new Un(r)});$({type:"pitchfork",group:"pitchforks",label:c("drawing.pitchfork.label","Pitchfork"),icon:mM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Ol(r)});var bM=V('<circle cx="4" cy="8" r="1.6" fill="currentColor"/><line x1="4" y1="8" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>'),vM=V('<circle cx="6" cy="9" r="1.6" fill="currentColor"/><line x1="6" y1="9" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>'),yM=V('<line x1="4" y1="12" x2="10" y2="12"/><line x1="10" y1="8" x2="10" y2="16"/><line x1="10" y1="8" x2="21" y2="8"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="16" x2="21" y2="16"/>');$({type:"schiffpitchfork",group:"pitchforks",label:c("drawing.schiffpitchfork.label","Schiff Pitchfork"),icon:bM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Nl(r)});$({type:"modifiedschiffpitchfork",group:"pitchforks",label:c("drawing.modifiedschiffpitchfork.label","Modified Schiff Pitchfork"),icon:vM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Fl(r)});$({type:"insidepitchfork",group:"pitchforks",label:c("drawing.insidepitchfork.label","Inside Pitchfork"),icon:yM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Bl(r)});var wM=V('<path d="M7 7h10v10"/><path d="M7 17 17 7"/>'),xM=V('<ellipse cx="12" cy="12" rx="9" ry="6"/>'),SM=V('<path d="M12 4 20 19 4 19Z"/>');$({type:"arrow",group:"shapes",label:c("drawing.arrow.label","Arrow"),icon:wM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",arrowRight:true},create:r=>new Vl(r)});$({type:"ellipse",group:"shapes",label:c("drawing.ellipse.label","Ellipse"),icon:xM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Hl(r)});$({type:"triangle",group:"shapes",label:c("drawing.triangle.label","Triangle"),icon:SM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new _l(r)});var CM=V('<polyline points="3 17 9 10 13 14 21 5"/>'),TM=V('<path d="M9.5 12 17 4.5a2.12 2.12 0 0 1 3 3L12.5 15"/><path d="M7 14a3 3 0 0 0-3 3c0 1.3-1.2 1.5-1.5 2 .8.9 2 1.5 3.5 1.5a3.5 3.5 0 0 0 3.5-3.5 3 3 0 0 0-2.5-3Z"/>'),kM=V('<path d="M9 11 15 5l4 4-6 6H9Z"/><path d="M9 15l-2 2"/><path d="M4 21h6"/>');$({type:"polyline",group:"shapes",label:c("drawing.polyline.label","Polyline"),icon:CM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new zl(r)});$({type:"freehand",group:"shapes",label:c("drawing.freehand.label","Brush"),icon:TM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Wl(r)});$({type:"highlighter",group:"shapes",label:c("drawing.highlighter.label","Highlighter"),icon:kM,defaultStyle:{lineColor:`${wb}59`,lineWidth:14,lineStyle:"solid"},create:r=>new Gl(r)});var LM=V('<circle cx="12" cy="12" r="8"/>'),MM=V('<path d="M5 14 9.5 5 19 10 14.5 19 Z"/>'),EM=V('<path d="M4 19 9 11 13 14 17 8 20 4"/><path d="M17.2 5.5 20 4 19.4 7.1"/>'),PM=V('<path d="M4 17a8 8 0 0 1 16 0"/><path d="M4 17 20 17"/>'),IM=V('<path d="M4 18Q12 1 20 14"/>'),AM=V('<path d="M12 5 12 19"/><path d="M6 11 12 5 18 11"/>'),RM=V('<path d="M12 5 12 19"/><path d="M6 13 12 19 18 13"/>');$({type:"circle",group:"shapes",label:c("drawing.circle.label","Circle"),icon:LM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Ul(r)});$({type:"rotatedrect",group:"shapes",label:c("drawing.rotatedrect.label","Rotated Rectangle"),icon:MM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}26`},create:r=>new $l(r)});$({type:"path",group:"shapes",label:c("drawing.path.label","Path"),icon:EM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Yl(r)});$({type:"arc",group:"shapes",label:c("drawing.arc.label","Arc"),icon:PM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}26`},create:r=>new Kl(r)});$({type:"curve",group:"shapes",label:c("drawing.curve.label","Curve"),icon:IM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Xl(r)});$({type:"arrowmarkup",group:"shapes",label:c("drawing.arrowmarkup.label","Arrow Mark Up"),icon:AM,defaultStyle:{lineColor:N,lineWidth:1,lineStyle:"solid"},create:r=>new gs(r)});$({type:"arrowmarkdown",group:"shapes",label:c("drawing.arrowmarkdown.label","Arrow Mark Down"),icon:RM,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:r=>new fs(r)});var DM=V('<path d="M6 21V4"/><path d="M6 5h11l-2.5 3.5L17 12H6" fill="currentColor" stroke="none"/>'),OM=V('<path d="m12 3 2.6 5.8 6.4.6-4.8 4.2 1.4 6.2L12 16.9 6.4 19.8 7.8 13.6 3 9.4l6.4-.6Z"/>');$({type:"flagmark",group:"stamps",label:c("drawing.flagmark.label","Flag"),icon:DM,defaultStyle:{lineColor:xt,lineWidth:1,lineStyle:"solid"},create:r=>new bs(r)});$({type:"iconstamp",group:"stamps",label:c("drawing.iconstamp.label","Icon"),icon:OM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new vs(r)});var NM=V('<line x1="3" y1="5" x2="21" y2="5"/><line x1="3" y1="10" x2="21" y2="10"/><line x1="3" y1="14" x2="21" y2="14"/><line x1="3" y1="19" x2="21" y2="19"/>'),FM=V('<line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="11" x2="21" y2="11"/><line x1="3" y1="15" x2="14" y2="15"/><line x1="3" y1="20" x2="14" y2="20"/>');$({type:"fibretracement",group:"fibonacci",label:c("drawing.fibretracement.label","Fib Retracement"),icon:NM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Sr(r)});$({type:"fibextension",group:"fibonacci",label:c("drawing.fibextension.label","Fib Extension"),icon:FM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Ql(r)});var BM=V('<path d="M3 20 10 9l4 5"/><path d="M14 14h7M14 9h7M14 4h7"/>');$({type:"fibextensiontrend",group:"fibonacci",label:c("drawing.fibextensiontrend.label","Trend-Based Fib Extension"),icon:BM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Jl(r)});var VM=V('<path d="M4 20 20 5M4 20 21 11M4 20 21 17M4 20 20 20"/>'),HM=V('<path d="M3 5v14M6 5v14M11 5v14M19 5v14"/>');$({type:"fibfan",group:"fibonacci",label:c("drawing.fibfan.label","Fib Fan"),icon:VM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new ec(r)});$({type:"fibtimezones",group:"fibonacci",label:c("drawing.fibtimezones.label","Fib Time Zones"),icon:HM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"dashed"},create:r=>new tc(r)});var _M=V('<path d="M3 18 18 9M5 21 20 12M6 13 21 4"/>'),zM=V('<path d="M4 4 20 20M4 4 20 12M4 4 12 20M4 4 20 4M4 4 4 20"/>'),WM=V('<path d="M3 19 9 8M9 8 12 5v14M14 5v14M18 5v14M21 5v14"/>');$({type:"fibchannel",group:"fibonacci",label:c("drawing.fibchannel.label","Fib Channel"),icon:_M,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new nc(r)});$({type:"fibspeedfan",group:"fibonacci",label:c("drawing.fibspeedfan.label","Fib Speed Resistance Fan"),icon:zM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new rc(r)});$({type:"trendfibtime",group:"fibonacci",label:c("drawing.trendfibtime.label","Trend-Based Fib Time"),icon:WM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"dashed"},create:r=>new ic(r)});var GM=V('<circle cx="12" cy="12" r="3"/><circle cx="12" cy="12" r="6.5"/><circle cx="12" cy="12" r="10"/>'),UM=V('<path d="M8 20a4 4 0 0 1 8 0"/><path d="M4.5 20a7.5 7.5 0 0 1 15 0"/><circle cx="12" cy="20" r="1.4" fill="currentColor" stroke="none"/>'),$M=V('<path d="M4 20 20 16M4 20 14 4"/><path d="M11.8 18.1A8 8 0 0 0 8.2 13.2"/><path d="M16.6 16.9A13 13 0 0 0 10.9 9"/>'),YM=V('<path d="M13 12a2 2 0 1 1-2-2 4 4 0 0 1 4 4 6 6 0 0 1-9 5.2 9 9 0 0 1 .5-15"/>');$({type:"fibcircles",group:"fibonacci",label:c("drawing.fibcircles.label","Fib Circles"),icon:GM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new oc(r)});$({type:"fibarcs",group:"fibonacci",label:c("drawing.fibarcs.label","Fib Speed Resistance Arcs"),icon:UM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new sc(r)});$({type:"fibwedge",group:"fibonacci",label:c("drawing.fibwedge.label","Fib Wedge"),icon:$M,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new ac(r)});$({type:"fibspiral",group:"fibonacci",label:c("drawing.fibspiral.label","Fib Spiral"),icon:YM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new ci(r)});var KM=V('<path d="M4 20 20 20M4 20 20 13M4 20 20 6M4 20 15 4M4 20 9 4M4 20 4 4"/>'),XM=V('<rect x="4" y="4" width="16" height="16" rx="1"/><path d="M4 12h16M12 4v16M4 4 20 20" opacity="0.6"/>');$({type:"gannfan",group:"fibonacci",label:c("drawing.gannfan.label","Gann Fan"),icon:KM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new lc(r)});$({type:"gannbox",group:"fibonacci",label:c("drawing.gannbox.label","Gann Box"),icon:XM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new cc(r)});var jM=V('<rect x="4" y="4" width="16" height="16" rx="1"/><path d="M4 20 20 4M4 20 20 12M4 20 12 4" opacity="0.7"/><path d="M4 20a16 16 0 0 1 16-16" opacity="0.5"/>');$({type:"gannsquare",group:"fibonacci",label:c("drawing.gannsquare.label","Gann Square"),icon:jM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new di(r)});var qM=V('<path d="M2 20h20"/><path d="M4 20a8 8 0 0 1 16 0" opacity="0.9"/><path d="M6 20a4 4 0 0 1 8 0" opacity="0.75"/><path d="M10 20a2 2 0 0 1 4 0" opacity="0.6"/><path d="M8 20v-6M12 20v-9M16 20v-6" opacity="0.45"/>');$({type:"dedekind",group:"geometry",label:c("drawing.dedekind.label","Dedekind Tessellation"),icon:qM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new ui(r)});var ZM=V('<circle cx="16" cy="12" r="5" opacity="0.55"/><circle cx="13" cy="12" r="3.5" opacity="0.75"/><circle cx="10.5" cy="12" r="2"/><path d="M8 4v16"/>'),QM=V('<circle cx="17" cy="12" r="4.5" opacity="0.45"/><circle cx="13" cy="12" r="3" opacity="0.7"/><circle cx="10" cy="12" r="1.6"/><path d="M6 12 16 5M6 12 16 19"/>');$({type:"sonic",group:"geometry",label:c("drawing.sonic.label","Sonic"),icon:ZM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Ss(r)});$({type:"supersonic",group:"geometry",label:c("drawing.supersonic.label","Supersonic"),icon:QM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Cs(r)});var JM=V('<circle cx="16" cy="12" r="5" opacity="0.4"/><circle cx="13" cy="12" r="3.2" opacity="0.65"/><circle cx="10.8" cy="12" r="1.8"/><path d="M8 4v16"/><path d="M15 8.5h2M12.5 10h2" opacity="0.5"/>'),eE=V('<circle cx="17" cy="12" r="4.5" opacity="0.4"/><circle cx="12.5" cy="12" r="2.8" opacity="0.65"/><circle cx="9.8" cy="12" r="1.4"/><path d="M6 12 16 5M6 12 16 19"/>');$({type:"goldensonic",group:"geometry",label:c("drawing.goldensonic.label","Golden Sonic"),icon:JM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new uc(r)});$({type:"goldensupersonic",group:"geometry",label:c("drawing.goldensupersonic.label","Golden Supersonic"),icon:eE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new hc(r)});var tE=V('<path d="M3 18 7 8 11 14 15 6 20 16"/>'),nE=V('<path d="M4 17 9 7 14 15 20 5"/>'),rE=V('<path d="M3 19 8 9 12 13 17 5 21 9"/>'),iE=V('<path d="M4 7 11 16 20 9"/>'),oE=V('<path d="M3 18 6 12 9 16 12 5 15 16 18 12 21 18"/>');$({type:"xabcd",group:"patterns",label:c("drawing.xabcd.label","XABCD Pattern"),icon:tE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new pc(r)});$({type:"abcd",group:"patterns",label:c("drawing.abcd.label","ABCD Pattern"),icon:nE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new mc(r)});$({type:"elliottimpulse",group:"patterns",label:c("drawing.elliottimpulse.label","Elliott Impulse Wave (1-5)"),icon:rE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new gc(r)});$({type:"elliottcorrection",group:"patterns",label:c("drawing.elliottcorrection.label","Elliott Correction Wave (ABC)"),icon:iE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new fc(r)});$({type:"headshoulders",group:"patterns",label:c("drawing.headshoulders.label","Head & Shoulders"),icon:oE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new bc(r)});var sE=V('<path d="M3 17 7 6 12 14 17 5 21 16"/><path d="M3 17 21 16" opacity="0.45"/>'),io={group:"patterns",icon:sE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"}};$({type:"gartley",label:c("drawing.gartley.label","Gartley"),...io,create:r=>new vc(r)});$({type:"bat",label:c("drawing.bat.label","Bat"),...io,create:r=>new yc(r)});$({type:"butterfly",label:c("drawing.butterfly.label","Butterfly"),...io,create:r=>new wc(r)});$({type:"crab",label:c("drawing.crab.label","Crab"),...io,create:r=>new xc(r)});$({type:"shark",label:c("drawing.shark.label","Shark"),...io,create:r=>new Sc(r)});$({type:"cypher",label:c("drawing.cypher.label","Cypher"),...io,create:r=>new Cc(r)});var aE=V('<rect x="4" y="6" width="16" height="12" rx="1"/><path d="M4 18 20 6" opacity="0.5"/>');$({type:"datepricerange",group:"measure",label:c("drawing.datepricerange.label","Date & Price Range"),icon:aE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Tc(r)});var lE=V('<rect x="4.5" y="4.5" width="15" height="7.5" rx="1" fill="currentColor" fill-opacity="0.25"/><rect x="4.5" y="12" width="15" height="7.5" rx="1"/>');$({type:"position",group:"measure",label:c("drawing.position.label","Long/Short Position"),icon:lE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Rt(r)});var cE=V('<circle cx="10.5" cy="10.5" r="6.5"/><path d="m15.3 15.3 5.2 5.2"/><path d="M8 12.5v-3M10.5 13.5v-5.5M13 12v-2"/>');$({type:"magnifier",group:"measure",label:c("drawing.magnifier.label","Magnifier"),icon:cE,defaultStyle:{lineColor:"",lineWidth:1,lineStyle:"solid"},coversSeries:true,placementHint:c("drawing.magnifier.placementHint","Drag an area on the chart to view it at a lower timeframe"),create:r=>new Dt(r)});var dE=V('<line x1="5" y1="3" x2="5" y2="21"/><path d="M5 16c4 0 5-9 8-9s3 5 8 3"/>');$({type:"anchoredvwap",group:"measure",label:c("drawing.anchoredvwap.label","Anchored VWAP"),icon:dE,defaultStyle:{lineColor:be,lineWidth:2,lineStyle:"solid"},create:r=>new ii(r)});var uE=V('<path d="M4 4v16"/><path d="M4 8h10"/><path d="M4 12h14"/><path d="M4 16h8"/><path d="M4 20h12"/>');$({type:"fixedrangevp",group:"measure",label:c("drawing.fixedrangevp.label","Fixed Range Volume Profile"),icon:uE,defaultStyle:{lineColor:N,lineWidth:1,lineStyle:"solid"},create:r=>new $t(r)});var hE=V('<path d="M6 15v6M12 3v18M18 2v6"/><rect x="3.5" y="9.5" width="17" height="5" rx="1" fill="currentColor" fill-opacity="0.28" stroke-width="1.4"/>'),pE=V('<rect x="4" y="7.5" width="5" height="8" rx="1"/><path d="M6.5 4v3.5M6.5 15.5V19"/><rect x="9" y="7.5" width="11.5" height="8" rx="1" fill="currentColor" fill-opacity="0.22" stroke-width="1.4"/>'),mE=V('<path d="M3 8h12" stroke-dasharray="2.5 2.5"/><path d="m16.5 4.5 4 4m0-4-4 4"/><path d="M3.5 20 8 13.5l4 3.5 5-8"/>');$({type:"fairvaluegap",group:"priceaction",label:c("drawing.fairvaluegap.label","Fair Value Gap"),icon:hE,defaultStyle:{lineColor:N,lineWidth:1,lineStyle:"solid"},placementHint:c("drawing.fairvaluegap.placementHint","Click the middle candle of a gap"),create:r=>new Lc(r)});$({type:"orderblock",group:"priceaction",label:c("drawing.orderblock.label","Order Block"),icon:pE,defaultStyle:{lineColor:N,lineWidth:1,lineStyle:"solid"},placementHint:c("drawing.orderblock.placementHint","Click the candle that forms the block"),create:r=>new Mc(r)});$({type:"liquidity",group:"priceaction",label:c("drawing.liquidity.label","Liquidity"),icon:mE,defaultStyle:{lineColor:q,lineWidth:1,lineStyle:"solid"},placementHint:c("drawing.liquidity.placementHint","Click near a candle's high or low"),create:r=>new pi(r)});var gE=["fibretracement","fibextension","fibextensiontrend","fibfan","fibtimezones","fibchannel","fibspeedfan","trendfibtime","fibcircles","fibarcs","fibwedge","fibspiral"],fE=["fairvaluegap","orderblock","liquidity"],bE=["gannfan","gannbox","gannsquare"],vE=["dedekind","sonic","supersonic","goldensonic","goldensupersonic"],yE=["xabcd","abcd","headshoulders"],wE=["elliottimpulse","elliottcorrection"],xE=["gartley","bat","butterfly","crab","shark","cypher"],SE=["position","datepricerange","magnifier"],CE=["anchoredvwap","fixedrangevp"],TE=["freehand","highlighter"],kE=["arrow","arrowmarkup","arrowmarkdown"],LE=["box","ellipse","triangle","polyline","circle","rotatedrect","path","arc","curve"],ME=["text","callout","note","pricenote","comment","pricelabel","signpost"],EE=["flagmark","iconstamp"],PE=[{id:"lines-channels-pitchforks",label:c("drawing.toolbar.group.linesChannelsPitchforks","Lines"),sections:[{label:c("drawing.toolbar.section.lines","Lines"),registryGroup:"lines"},{label:c("drawing.toolbar.section.channels","Channels"),registryGroup:"channels"},{label:c("drawing.toolbar.section.pitchforks","Pitchforks"),registryGroup:"pitchforks"}]},{id:"fibonacci-gann",label:c("drawing.toolbar.group.fibonacciGann","Fibonacci"),sections:[{label:c("drawing.toolbar.section.fibonacci","Fibonacci"),types:gE},{label:c("drawing.toolbar.section.priceAction","Price Action"),types:fE},{label:c("drawing.toolbar.section.gann","Gann"),types:bE},{label:c("drawing.toolbar.section.geometry","Geometry"),types:vE}]},{id:"patterns-waves-harmonics",label:c("drawing.toolbar.group.patternsWavesHarmonics","Patterns"),sections:[{label:c("drawing.toolbar.section.patterns","Patterns"),types:yE},{label:c("drawing.toolbar.section.elliottWaves","Elliott Waves"),types:wE},{label:c("drawing.toolbar.section.harmonics","Harmonics"),types:xE}]},{id:"measurements",label:c("drawing.toolbar.group.measurements","Measurements"),sections:[{label:c("drawing.toolbar.section.measurements","Measurements"),types:SE},{label:c("drawing.toolbar.section.volume","Volume"),types:CE}]},{id:"brushes-arrows-shapes",label:c("drawing.toolbar.group.brushesArrowsShapes","Shapes"),sections:[{label:c("drawing.toolbar.section.brushes","Brushes"),types:TE},{label:c("drawing.toolbar.section.arrows","Arrows"),types:kE},{label:c("drawing.toolbar.section.shapes","Shapes"),types:LE}]},{id:"text",label:c("drawing.toolbar.group.text","Text"),sections:[{label:c("drawing.toolbar.section.text","Text"),types:ME}]},{id:"icons",label:c("drawing.toolbar.group.icons","Icons"),sections:[{label:c("drawing.toolbar.section.icons","Icons"),types:EE}]}];function IE(r){let e=zh(r);return e?{type:e.type,label:e.label,icon:e.icon}:null}function AE(r){let e=new Map;for(let t of vv()){if(r&&!r.has(t.type))continue;let n={type:t.type,label:t.label,icon:t.icon};e.has(t.group)||e.set(t.group,[]),e.get(t.group).push(n);}return e}function RE(r,e,t){return "registryGroup"in r?e.get(r.registryGroup)??[]:r.types.map(n=>t.get(n)).filter(n=>n!=null)}function Ls(r){let e=AE(r),t=new Map;for(let i of e.values())for(let o of i)t.set(o.type,o);let n=[];for(let i of PE){let o=[],s=[];for(let a of i.sections){let l=RE(a,e,t);l.length!==0&&(o.push({label:a.label,tools:l}),s.push(...l));}s.length!==0&&n.push({id:i.id,label:i.label,tools:s,sections:o.length>0?o:void 0});}return {groups:n}}function DE(r){let e=new Set;for(let t of r)zh(t)&&e.add(t);return Ls(e)}function OE(r){let e=[];for(let t of r){let n=t.tools.map(IE).filter(i=>i!=null);n.length>0&&e.push({id:t.id,label:t.label,tools:n});}return {groups:e}}function yv(r,e){let t=new Map,n=i=>{let o=t.get(i);return o||(o={type:i.type,label:X(e,i.label),icon:i.icon},t.set(i,o)),o};return {groups:r.groups.map(i=>({id:i.id,label:X(e,i.label),tools:i.tools.map(n),sections:i.sections?.map(o=>({label:X(e,o.label),tools:o.tools.map(n)}))}))}}function wv(r){return yv(Ls(),r)}function oo(r,e){let{definition:t,visible:n}=NE(r);return {definition:yv(t,e),visible:n}}function NE(r){if(r===false)return {definition:Ls(),visible:false};if(r===void 0||r===true)return {definition:Ls(),visible:true};let e=r.toolbar??true;return r.groups?{definition:OE(r.groups),visible:e}:r.tools?{definition:DE(r.tools),visible:e}:{definition:Ls(),visible:e}}function ct(r){let e=globalThis.structuredClone;return e?e(r):JSON.parse(JSON.stringify(r))}function xv(r){if(!r||typeof r!="object")return false;let e=r;return typeof e.id=="string"&&typeof e.type=="string"&&typeof e.paneId=="string"&&Array.isArray(e.anchors)&&e.anchors.every(t=>t&&typeof t.time=="number"&&typeof t.price=="number")&&!!e.style&&typeof e.style=="object"}function Wh(r){let e=r;return !e||typeof e!="object"||e.version!==1||!Array.isArray(e.drawings)?{version:1,drawings:[]}:{version:1,drawings:e.drawings.filter(xv)}}var so=class{constructor(){this.byId=new Map;this.seq=0;this.zCounter=1;this.listeners=new Set;}nextId(){return this.seq+=1,`dw-${this.seq}`}add(e){return e.zIndex||(e.zIndex=this.zCounter),this.zCounter=Math.max(this.zCounter,Math.ceil(e.zIndex))+1,this.byId.set(e.id,e),this.emit(),e}remove(e){let t=this.byId.delete(e);return t&&this.emit(),t}get(e){return this.byId.get(e)}has(e){return this.byId.has(e)}update(e,t){let n=this.byId.get(e);return n?(t.anchors&&(n.anchors=t.anchors.map(i=>({time:i.time,price:i.price}))),t.style&&(n.style={...t.style}),t.text!==void 0&&(n.text=t.text?{...t.text}:void 0),t.paneId!==void 0&&(n.paneId=t.paneId),t.locked!==void 0&&(n.locked=t.locked),t.visible!==void 0&&(n.visible=t.visible),t.zIndex!==void 0&&(n.zIndex=t.zIndex),t.props!==void 0&&n.applyProps(t.props),"showOn"in t&&(n.showOn=ps(t.showOn)),this.emit(),n):null}all(){return [...this.byId.values()].sort((e,t)=>e.zIndex-t.zIndex)}byPane(e){return this.all().filter(t=>t.paneId===e)}bringToFront(e,t=0){let n=this.byId.get(e);n&&(n.zIndex=Math.max(this.zCounter,Math.floor(t)+1),this.zCounter=n.zIndex+1,this.emit());}sendToBack(e,t=1){let n=this.byId.get(e);if(!n)return;let i=Math.min(...[...this.byId.values()].map(o=>o.zIndex),Math.ceil(t));n.zIndex=i-1,this.emit();}setLocked(e,t){let n=this.byId.get(e);n&&(n.locked=t,this.emit());}setVisible(e,t){let n=this.byId.get(e);n&&(n.visible=t,this.emit());}clear(){this.byId.size!==0&&(this.byId.clear(),this.emit());}serialize(){return {version:1,drawings:this.all().map(e=>e.serialize())}}load(e){let t=Wh(e);this.byId.clear(),this.seq=0,this.zCounter=1;for(let n of t.drawings){let i=zt(n);i&&(this.byId.set(i.id,i),this.zCounter=Math.max(this.zCounter,i.zIndex)+1,this.bumpSeqPast(i.id));}this.emit();}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}bumpSeqPast(e){let t=/^dw-(\d+)$/.exec(e);t&&(this.seq=Math.max(this.seq,Number(t[1])));}emit(){for(let e of this.listeners)e();}};var Pc=class{constructor(e=100){this.cap=e;this.undoStack=[];this.redoStack=[];this.pending=null;this.dirtied=false;this.depth=0;}begin(e){this.depth+=1,this.depth===1&&(this.pending=ct(e),this.dirtied=false);}markDirty(){this.depth===0||this.dirtied||!this.pending||(this.push(this.pending),this.dirtied=true);}commit(){this.depth!==0&&(this.depth-=1,this.depth===0&&(this.pending=null,this.dirtied=false));}abort(){this.commit();}record(e){if(this.depth>0){this.markDirty();return}this.push(ct(e));}undo(e){let t=this.undoStack.pop();return t?(this.redoStack.push(ct(e)),t):null}redo(e){let t=this.redoStack.pop();return t?(this.undoStack.push(ct(e)),t):null}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}clear(){this.undoStack=[],this.redoStack=[],this.pending=null,this.dirtied=false,this.depth=0;}push(e){this.undoStack.push(e),this.undoStack.length>this.cap&&this.undoStack.shift(),this.redoStack=[];}};function Cr(r){let e={style:{...r.style}};if(r.text){let{value:n,...i}=r.text;e.text=i;}let t=r.serialize().props;return t!==void 0&&(e.props=ct(t)),e}function Kn(r,e){e&&(e.style&&(r.style={...r.style,...e.style}),e.text&&(r.text={...r.text??rn(),...e.text,value:r.text?.value??""}),e.props&&r.applyProps(ct(e.props)));}function Ms(r,e){return JSON.stringify(r??null)===JSON.stringify(e??null)}function Ic(r){if(r==null||typeof r!="object"||Array.isArray(r))return null;let e=r,t=a=>a!=null&&typeof a=="object"&&!Array.isArray(a)?a:void 0,n={},i=t(e.style);i&&(n.style=i);let o=t(e.text);if(o){let{value:a,...l}=o;n.text=l;}let s=t(e.props);return s&&(n.props=s),n.style||n.text||n.props?n:null}var FE=60;function Gh(r){if(!Array.isArray(r))return [];let e=new Map;for(let t of r){if(t==null||typeof t!="object")continue;let n=t,i=typeof n.name=="string"?n.name.trim().slice(0,FE):"",o=Ic(n.settings);i&&o&&e.set(i,{name:i,settings:o});}return [...e.values()]}var BE=new Set(["trendline","ray","extendedline","hline","hray","vline","crossline","infoline","trendangle"]),VE=new Set(["box","rotatedrect","ellipse","circle","triangle","parallelchannel","disjointchannel","flattopbottom"]);function Ac(r){return BE.has(r)?[{name:"Support",label:c("drawing.template.support","Support"),settings:{style:{lineColor:N,lineWidth:2,lineStyle:"solid"}}},{name:"Resistance",label:c("drawing.template.resistance","Resistance"),settings:{style:{lineColor:O,lineWidth:2,lineStyle:"solid"}}},{name:"Projection",label:c("drawing.template.projection","Projection"),settings:{style:{lineColor:R,lineWidth:1,lineStyle:"dashed"}}}]:VE.has(r)?[{name:"Demand",label:c("drawing.template.demand","Demand"),settings:{style:{lineColor:N,fillColor:`${N}26`}}},{name:"Supply",label:c("drawing.template.supply","Supply"),settings:{style:{lineColor:O,fillColor:`${O}26`}}}]:[]}function HE(r){let e=Yn(r.type,{paneId:r.paneId});return e?Cr(e):void 0}var Rc=class{constructor(e,t,n,i,o=()=>null){this.events=t;this.i18n=o;this.store=new so;this.history=new Pc;this.activeTool=null;this.snapMode="off";this.stayInDrawingMode=false;this.mode=null;this.favs=new Set;this.selectedIds=[];this.clipboard=[];this.defaults=new Map;this.templates=new Map;this.subs=[];if(this.enabled=!!e.capabilities.userDrawings&&!!e.userDrawingsPort,this.port=this.enabled?e.userDrawingsPort:null,this.toolbarOption=n,this.port){let{definition:s,visible:a}=oo(n,this.i18n());this.port.setToolbar(s),this.port.showToolbar(a),i&&this.port.setSeriesGateway?.(i),this.subs.push(this.port.onDrawingIntent(l=>this.onIntent(l))),this.subs.push(this.store.onChange(()=>this.sync()));}}get supported(){return this.enabled}setTool(e){if(!this.port)return;let t=e!==this.activeTool;this.activeTool=e;let n=e?this.defaults.get(e):void 0;this.port.setActiveTool(e,n?.style,n),t&&this.events.emit("drawing:tool",{type:e});}getTool(){return this.activeTool}getSnapMode(){return this.snapMode}setSnapMode(e){!this.port||e===this.snapMode||(this.snapMode=e,this.port.setSnapMode?.(e),this.events.emit("drawing:snap",{mode:e}));}getStayMode(){return this.stayInDrawingMode}setStayMode(e){!this.port||e===this.stayInDrawingMode||(this.stayInDrawingMode=e,this.port.setStayMode?.(e),this.events.emit("drawing:stay",{on:e}));}getMode(){return this.mode}setMode(e){!this.port||e===this.mode||(this.mode=e,this.port.setMode?.(e),this.events.emit("drawing:mode",{mode:e}));}showToolbar(e){this.port?.showToolbar(e);}favorites(){return [...this.favs]}isFavorite(e){return this.favs.has(e)}setFavorite(e,t){_t(e)&&t!==this.favs.has(e)&&(t?this.favs.add(e):this.favs.delete(e),this.pushFavorites());}setFavorites(e){let t=e.filter(n=>_t(n)!=null);t.length===this.favs.size&&t.every(n=>this.favs.has(n))||(this.favs=new Set(t),this.pushFavorites());}pushFavorites(){let e=[...this.favs];this.port?.setFavorites?.(e),this.events.emit("drawing:favorites",{favorites:e});}toolDefaults(){let e={};for(let[t,n]of this.defaults)e[t]=ct(n);return e}setToolDefaults(e){let t=new Map;for(let[i,o]of Object.entries(e??{})){if(!_t(i))continue;let s=Ic(o);s&&t.set(i,ct(s));}let n=new Set([...this.defaults.keys(),...t.keys()]);for(let i of [...n])Ms(this.defaults.get(i),t.get(i))&&n.delete(i);if(n.size!==0){this.defaults.clear();for(let[i,o]of t)this.defaults.set(i,o);this.activeTool&&n.has(this.activeTool)&&this.setTool(this.activeTool);for(let i of n)this.events.emit("drawing:defaults",{type:i});}}resetToolDefaults(e){let t=e?this.defaults.has(e)?[e]:[]:[...this.defaults.keys()];for(let n of t)this.defaults.delete(n),this.events.emit("drawing:defaults",{type:n});}toolTemplates(){let e={};for(let[t,n]of this.templates)e[t]=ct(n);return e}setToolTemplates(e){let t=new Map;for(let[i,o]of Object.entries(e??{})){if(!_t(i))continue;let s=Gh(o);s.length>0&&t.set(i,s);}let n=[...new Set([...this.templates.keys(),...t.keys()])].filter(i=>JSON.stringify(this.templates.get(i)??[])!==JSON.stringify(t.get(i)??[]));if(n.length!==0){this.templates=t,this.pushTemplates();for(let i of n)this.events.emit("drawing:templates",{type:i});}}saveToolTemplate(e,t,n){if(!_t(e))return;let[i]=Gh([{name:t,settings:n}]);if(!i)return;let o=(this.templates.get(e)??[]).filter(s=>s.name!==i.name);this.templates.set(e,[...o,ct(i)]),this.pushTemplates(),this.events.emit("drawing:templates",{type:e});}removeToolTemplate(e,t){let n=this.templates.get(e);if(!n?.some(o=>o.name===t))return;let i=n.filter(o=>o.name!==t);i.length>0?this.templates.set(e,i):this.templates.delete(e),this.pushTemplates(),this.events.emit("drawing:templates",{type:e});}pushTemplates(){this.port?.setToolTemplates?.(this.toolTemplates());}setToolbar(e){this.toolbarOption=e,this.port?.setToolbar(oo(e,this.i18n()).definition);}relocalize(){this.port?.setToolbar(oo(this.toolbarOption,this.i18n()).definition);}setExternalGhost(e){this.port?.setExternalGhost?.(e);}setToolShortcuts(e){this.port?.setToolShortcuts?.(e);}add(e,t={}){if(!this.enabled)return null;let n=this.defaults.get(e),i=Yn(e,{id:this.store.nextId(),paneId:t.paneId??"price",anchors:t.anchors,text:t.text,zIndex:t.zIndex??this.startZ(e,t.paneId??"price")});return i?(Kn(i,n),t.style&&(i.style={...i.style,...t.style}),t.text&&(i.text={...i.text??t.text,...t.text}),t.props&&i.applyProps(t.props),this.history.record(this.store.serialize()),this.store.add(i),this.captureDefaults(i.id),this.events.emit("drawing:created",{id:i.id}),i):null}remove(e){this.deleteMany([e]);}update(e,t){let n=this.store.serialize(),i=t.style?this.store.get(e):void 0,o=t.style&&i?{...t,style:{...i.style,...t.style}}:t;this.updateDrawing(e,o)&&(this.history.record(n),this.events.emit("drawing:edited",{id:e}));}updateMany(e){this.history.begin(this.store.serialize());for(let{id:t,patch:n}of e)this.updateDrawing(t,n)&&(this.history.markDirty(),this.events.emit("drawing:edited",{id:t}));this.history.commit();}removeMany(e){this.deleteMany(e);}setLocked(e,t){let n=this.store.serialize();this.history.record(n),this.store.setLocked(e,t),this.events.emit("drawing:edited",{id:e});}setVisible(e,t){let n=this.store.serialize();this.history.record(n),this.store.setVisible(e,t),this.events.emit("drawing:edited",{id:e});}bringToFront(e){let t=this.store.serialize();this.history.record(t),this.store.bringToFront(e,this.seriesTopZ(this.store.get(e)?.paneId)),this.events.emit("drawing:edited",{id:e});}sendToBack(e){let t=this.store.serialize();this.history.record(t),this.store.sendToBack(e,this.seriesBottomZ(this.store.get(e)?.paneId)),this.events.emit("drawing:edited",{id:e});}seriesTopZ(e){return e!==void 0?this.port?.stackRange?.(e)?.front??0:0}seriesBottomZ(e){return e!==void 0?this.port?.stackRange?.(e)?.back??1:1}startZ(e,t){let n=this.port?.stackRange?.(t);if(n)return _t(e)?.coversSeries?n.front+.5:(n.price??n.front)-.5}select(e,t=false){this.setSelection(e,t);}openSettings(e){this.port?.openSettings(e);}undo(){let e=this.history.undo(this.store.serialize());e&&this.restoreSnapshot(e);}redo(){let e=this.history.redo(this.store.serialize());e&&this.restoreSnapshot(e);}canUndo(){return this.history.canUndo()}canRedo(){return this.history.canRedo()}duplicate(e){if(!this.enabled)return [];let t=this.resolve(e);return t.length===0?[]:this.insertClones(t.map(n=>n.serialize()))}clone(e){return this.duplicate([e])[0]??null}copy(e){let t=this.resolve(e).map(n=>ct(n.serialize()));t.length&&(this.clipboard=t);}paste(){return !this.enabled||this.clipboard.length===0?[]:this.insertClones(this.clipboard)}all(){return this.store.serialize().drawings}toJSON(){return this.store.serialize()}fromJSON(e){this.history.clear(),this.selectedIds=[],this.store.load(e);}destroy(){for(let e of this.subs)e();this.subs.length=0;}setSelection(e,t=false){let n;if(t){n=[...this.selectedIds];for(let i of e){let o=n.indexOf(i);o>=0?n.splice(o,1):n.push(i);}}else n=[...e];this.selectedIds=n.filter(i=>this.store.has(i)),this.announceSelection();}announceSelection(){this.port?.setSelection(this.selectedIds),this.events.emit("drawing:selected",{id:this.selectedIds[0]??null,ids:[...this.selectedIds]});}restoreSnapshot(e){this.store.load(e),this.selectedIds=this.selectedIds.filter(t=>this.store.has(t)),this.announceSelection();}deleteMany(e){this.history.begin(this.store.serialize());let t=[];for(let i of e)this.store.remove(i)&&t.push(i),this.history.markDirty();if(this.history.commit(),t.length===0)return;let n=this.selectedIds.filter(i=>this.store.has(i));n.length!==this.selectedIds.length&&this.setSelection(n);for(let i of t)this.events.emit("drawing:removed",{id:i});}insertClones(e){this.history.begin(this.store.serialize());let t=[];for(let n of e){let i=zt({...n,id:this.store.nextId()});i&&(this.store.add(i),this.history.markDirty(),t.push(i));}if(this.history.commit(),t.length){this.setSelection(t.map(n=>n.id));for(let n of t)this.events.emit("drawing:created",{id:n.id});}return t}resolve(e){return e.map(t=>this.store.get(t)).filter(t=>t!=null)}updateDrawing(e,t){let n=this.store.get(e),i=n?Cr(n):void 0;if(!this.store.update(e,t))return false;let o=this.store.get(e);return o&&!Ms(i,Cr(o))&&this.captureDefaults(e),true}captureDefaults(e){let t=this.store.get(e);if(!t)return;let n=Cr(t),i=Ms(n,HE(t))?void 0:n;Ms(this.defaults.get(t.type),i)||(i?this.defaults.set(t.type,i):this.defaults.delete(t.type),this.events.emit("drawing:defaults",{type:t.type}));}sync(){this.port?.syncDrawings(this.store.serialize().drawings);}onIntent(e){switch(e.kind){case "arm":this.setTool(e.type);break;case "draft":this.events.emit("drawing:draft",{doc:e.doc});break;case "create":{let t=this.store.serialize(),n=zt({...e.doc,id:this.store.nextId()});if(!n)return;Kn(n,this.defaults.get(n.type)),n.zIndex||(n.zIndex=this.startZ(n.type,n.paneId)??0),this.history.record(t),this.store.add(n),this.captureDefaults(n.id),this.events.emit("drawing:created",{id:n.id});break}case "edit":{let t=this.store.serialize();this.updateDrawing(e.doc.id,e.doc)&&(this.history.record(t),this.events.emit("drawing:edited",{id:e.doc.id}));break}case "edit-many":{this.history.begin(this.store.serialize());for(let t of e.docs)this.updateDrawing(t.id,t)&&(this.history.markDirty(),this.events.emit("drawing:edited",{id:t.id}));this.history.commit();break}case "select":this.setSelection(e.ids,e.additive);break;case "delete":this.deleteMany(e.ids);break;case "reorder":e.to==="front"?this.bringToFront(e.id):this.sendToBack(e.id);break;case "settings":this.events.emit("drawing:settings",{id:e.id});break;case "favorite":this.setFavorite(e.type,e.on);break;case "template-save":this.saveToolTemplate(e.type,e.name,e.settings);break;case "template-remove":this.removeToolTemplate(e.type,e.name);break;case "snap-mode":e.mode!==this.snapMode&&(this.snapMode=e.mode,this.events.emit("drawing:snap",{mode:e.mode}));break;case "stay-mode":e.on!==this.stayInDrawingMode&&(this.stayInDrawingMode=e.on,this.events.emit("drawing:stay",{on:e.on}));break;case "mode":e.mode!==this.mode&&(this.mode=e.mode,this.events.emit("drawing:mode",{mode:e.mode}));break;case "tool-finished":!this.stayInDrawingMode&&e.type!=="freehand"&&e.type!=="highlighter"&&this.setTool(null);break;case "undo":this.undo();break;case "redo":this.redo();break;case "duplicate":this.duplicate(e.ids);break;case "clone":this.enabled&&e.docs.length&&this.insertClones(e.docs);break;case "copy":this.copy(e.ids);break;case "paste":this.paste();break}}};function Dc(r,e,t){let n=r[e];return typeof n=="boolean"?n:t.find(i=>i.id===e)?.visible!==false}function Oc(r,e,t){if(e===void 0)return true;let n=new Set,i=e;for(;i!==void 0&&!n.has(i);){if(n.add(i),!Dc(r,i,t))return false;let o=t.find(s=>s.id===i)?.parent;i=o!==void 0&&t.some(s=>s.id===o)?o:void 0;}return true}function Uh(r){let e=new Set(r.map(o=>o.id)),t=[],n=new Set,i=(o,s)=>{if(!n.has(o.id)){n.add(o.id),t.push({group:o,depth:s});for(let a of r)a.parent===o.id&&a.id!==o.id&&i(a,s+1);}};for(let o of r)o.parent!==void 0&&e.has(o.parent)&&o.parent!==o.id||i(o,0);for(let o of r)i(o,0);return t}var Nc=class{constructor(e,t){this.renderer=e;this.marks=new Map;this.groups=new Map;this.subs=[];this.enabled=!!e.capabilities.timelineMarks&&typeof e.setTimelineMarks=="function",this.enabled&&e.onMarkClick&&this.subs.push(e.onMarkClick(n=>t.emit("mark:click",n)));}get supported(){return this.enabled}add(e){this.marks.set(e.id,Cv(e)),this.sync();}set(e){this.marks.clear();for(let t of e)this.marks.set(t.id,Cv(t));this.sync();}remove(e){let t=this.marks.delete(e);return t&&this.sync(),t}clear(){this.marks.size!==0&&(this.marks.clear(),this.sync());}all(){return [...this.marks.values()].map(e=>({...e,glyph:{...e.glyph}}))}defineGroup(e){if(!e||typeof e.id!="string"||e.id.length===0)throw new Error("[vela] marks.defineGroup: `id` must be a non-empty string");if(typeof e.label!="string")throw new Error(`[vela] marks.defineGroup: group "${e.id}" needs a string \`label\``);if(e.parent!==void 0&&(typeof e.parent!="string"||e.parent.length===0))throw new Error(`[vela] marks.defineGroup: group "${e.id}" has a \`parent\` that is not a group id`);this.groups.set(e.id,{...e}),this.sync();}groupDefinitions(){return [...this.groups.values()].map(e=>({...e}))}setGroupVisible(e,t){if(!this.renderer.features.includes("marks")){console.warn(`[vela] renderer "${this.renderer.name}" does not paint timeline marks \u2014 setGroupVisible ignored.`);return}this.renderer.applyFeature("marks",{groups:{[e]:t}});}isGroupVisible(e){let t=this.renderer.readFeature("marks"),n={};for(let[i,o]of Object.entries(t?.groups??{}))typeof o=="boolean"&&(n[i]=o);return Oc(n,e,[...this.groups.values()])}destroy(){for(let e of this.subs)e();this.subs.length=0;}sync(){this.enabled&&this.renderer.setTimelineMarks([...this.marks.values()],[...this.groups.values()]);}};function Cv(r){if(!r||typeof r!="object")throw new Error("[vela] marks: a mark must be an object");if(typeof r.id!="string"||r.id.length===0)throw new Error("[vela] marks: `id` must be a non-empty string");if(typeof r.time!="number"||!Number.isFinite(r.time))throw new Error(`[vela] marks: mark "${r.id}" needs a finite epoch-ms \`time\``);if(!r.glyph||typeof r.glyph!="object"||typeof r.glyph.color!="string")throw new Error(`[vela] marks: mark "${r.id}" needs a glyph with a \`color\``);return {...r,glyph:{...r.glyph}}}var Tv={D:864e5,W:6048e5,M:2592e6};function an(r){let e=r.trim();if(Tv[e])return Tv[e];let t=/^(\d+)\s*(m|h|d|w)?$/i.exec(e);if(t){let n=parseInt(t[1],10),i=(t[2]??"m").toLowerCase();return n*(i==="m"?6e4:i==="h"?36e5:i==="d"?864e5:6048e5)}return 36e5}var _E=5e3,zE=.25,WE=16,GE=15e3,$h=["240","60","30","15","5","1"],Fc=class{constructor(e){this.deps=e;this.cache=new Map;this.listeners=new Set;}seriesInRange(e,t,n){if(!this.deps.canFetch())return {state:"unavailable",reason:"no-source"};let i=this.resolveTimeframe(e);if(typeof i!="string")return {state:"unavailable",reason:i.reason};let o=an(i),s=Math.min(t,n),a=Math.max(t,n);if(!(a>s)||!(o>0))return {state:"unavailable",reason:"not-lower"};if((a-s)/o>_E)return {state:"unavailable",reason:"too-wide"};let l=`${this.deps.marketKey()}|${i}`,d=this.cache.get(l)??[],u=d.find(h=>h.from<=s&&h.to>=a);if(u){if(u.pending)return this.loading(d,i,o,s,a);if(u.failedAt>0){if(Date.now()-u.failedAt<GE)return this.loading(d,i,o,s,a);d.splice(d.indexOf(u),1);}else return this.maybeRefresh(l,u,i,o,a),{state:"ready",bars:this.slice(u.bars,s,a),timeframe:i,barMs:o}}return this.fetchWindow(l,d,i,s,a),this.loading(d,i,o,s,a)}onUpdate(e){return this.listeners.add(e),()=>this.listeners.delete(e)}resolveTimeframe(e){let t=an(this.deps.chartTimeframe()),n=$h[$h.length-1];if(an(n)>=t)return {reason:"none-lower"};let i=e.trim()||"auto";if(i==="auto"){for(let o of $h)if(an(o)<=t/4)return o;return n}return an(i)<t?i:{reason:"not-lower"}}loading(e,t,n,i,o){let s=new Map;for(let l of e)if(!(l.pending||l.failedAt>0)&&!(l.to<i||l.from>o))for(let d of this.slice(l.bars,i,o))s.set(d.time,d);if(s.size===0)return {state:"loading",timeframe:t,barMs:n};let a=[...s.values()].sort((l,d)=>l.time-d.time);return {state:"loading",timeframe:t,barMs:n,bars:a}}fetchWindow(e,t,n,i,o){if(t.some(l=>l.pending&&l.to>=i&&l.from<=o))return;let s=(o-i)*zE,a={from:i-s,to:o+s,bars:[],fetchedAt:0,pending:true,failedAt:0};t.push(a),this.cache.set(e,t),this.evict(),this.deps.fetchBars(n,{from:a.from,to:a.to}).then(l=>{a.bars=l,a.fetchedAt=Date.now(),a.pending=false,this.absorbOverlaps(e,a),this.fire();}).catch(()=>{a.pending=false,a.failedAt=Date.now(),this.fire();});}maybeRefresh(e,t,n,i,o){if(t.pending)return;let s=t.bars.length>0?t.bars[t.bars.length-1].time:t.from;o<s||Date.now()-t.fetchedAt<i||(t.pending=true,this.deps.fetchBars(n,{from:t.from,to:t.to}).then(a=>{t.bars=a,t.fetchedAt=Date.now(),t.pending=false,this.fire();}).catch(()=>{t.pending=false,t.fetchedAt=Date.now();}));}absorbOverlaps(e,t){let n=this.cache.get(e);if(n)for(let i=n.length-1;i>=0;i-=1){let o=n[i];if(o===t||o.pending||o.failedAt>0||o.to<t.from||o.from>t.to)continue;let s=new Map;for(let a of o.bars)s.set(a.time,a);for(let a of t.bars)s.set(a.time,a);t.bars=[...s.values()].sort((a,l)=>a.time-l.time),t.from=Math.min(t.from,o.from),t.to=Math.max(t.to,o.to),t.fetchedAt=Math.min(t.fetchedAt,o.fetchedAt||t.fetchedAt),n.splice(i,1);}}evict(){let e=0;for(let t of this.cache.values())e+=t.length;for(;e>WE;){let t=null,n=-1,i=1/0;for(let[s,a]of this.cache)for(let l=0;l<a.length;l+=1){let d=a[l];if(d.pending)continue;let u=d.fetchedAt||d.failedAt;u<i&&(t=s,n=l,i=u);}if(t==null)return;let o=this.cache.get(t);o.splice(n,1),o.length===0&&this.cache.delete(t),e-=1;}}slice(e,t,n){let i=[];for(let o of e)if(!(o.time<t)){if(o.time>n)break;i.push(o);}return i}fire(){for(let e of [...this.listeners])e();}};function Es(r){return r.group!=null&&r.ticker===r.group}function kv(r){return `${(r.prefix??r.provider??"").toLowerCase()}:${(r.group??"").toUpperCase()}`}function UE(r,e){let t=kv(e);return r.filter(n=>n.group!=null&&!Es(n)&&kv(n)===t)}function Lv(r,e){let t=UE(r,e),n=t.filter(i=>i.default);return (n.length===1?n[0]:t[0])??null}var Ln=r=>r.trim().toLowerCase(),Xn=r=>r.trim().toUpperCase();function Mn(r){let e=r.trim(),t=/^(?:([A-Za-z0-9_.]+):)?(.+)$/.exec(e);if(!t)return {provider:null,ticker:e};let n=t[1]?Ln(t[1]):null,i=t[2],o=i.lastIndexOf("."),s=o>0?i.slice(o+1):void 0;return {provider:n,ticker:i,ext:s}}var Bc=class{constructor(){this.entries=new Map;this.changeListeners=new Set;this.waits=new Set;this.unresolvedCbs=new Set;}register(e,t){let n=Ln(e),i={name:n,provider:t,index:null,prefixIndex:null,byTicker:null,descriptors:[],settled:false,settle:Promise.resolve()};return this.entries.set(n,i),i.settle=this.buildIndex(i),queueMicrotask(()=>this.notify(false)),i.settle}async buildIndex(e){await Promise.resolve();try{if(e.provider.listSymbols){let t=await e.provider.listSymbols();e.descriptors=t,e.index=new Set(t.map(n=>Xn(n.ticker))),e.byTicker=new Map(t.map(n=>[Xn(n.ticker),n])),e.prefixIndex=new Map;for(let n of t)n.prefix&&e.prefixIndex.set(`${Ln(n.prefix)}:${Xn(n.ticker)}`,n);}}catch{e.index=null;}finally{e.settled=true,this.notify(true);}}notify(e){for(let t of [...this.changeListeners])t(e);}onChange(e){return this.changeListeners.add(e),()=>this.changeListeners.delete(e)}unregister(e){this.entries.delete(Ln(e)),this.notify(false);}has(e){return this.entries.has(Ln(e))}get(e){return this.entries.get(Ln(e))?.provider}names(){return [...this.entries.keys()]}parse(e){return Mn(e)}resolve(e,t={}){let{provider:n,ticker:i}=this.parse(e);if(n){if(this.entries.has(n)){let a=this.entries.get(n).byTicker?.get(Xn(i));return {provider:n,ticker:a!=null&&Es(a)?this.loadableTicker(n,a):i}}let s=`${n}:${Xn(i)}`;for(let a of this.candidateOrder(t.default)){let l=this.entries.get(a).prefixIndex?.get(s);if(l)return {provider:a,ticker:this.loadableTicker(a,l)}}return null}let o=Xn(i);for(let s of this.candidateOrder(t.default)){let a=this.entries.get(s);if(a.index?.has(o)){let l=a.byTicker?.get(o);return {provider:s,ticker:l!=null&&Es(l)?this.loadableTicker(s,l):i}}}if(t.lenient&&this.entries.size===1){let s=this.names()[0],a=this.entries.get(s);if(a.settled&&a.index==null)return {provider:s,ticker:i}}return null}loadableTicker(e,t){return Es(t)?Lv(this.entries.get(e)?.descriptors??[],t)?.ticker??t.ticker:t.ticker}whenResolvable(e,t={}){let n=this.resolve(e,{...t,lenient:true});return n?Promise.resolve(n):new Promise(i=>{let o=this.onChange(a=>{let l=this.resolve(e,{...t,lenient:true});l?(s(),i(l)):a&&this.allSettled()&&this.reportUnresolved(e);}),s=()=>{o(),this.waits.delete(s);};this.waits.add(s);})}allSettled(){for(let e of this.entries.values())if(!e.settled)return false;return true}cancelWaits(){for(let e of [...this.waits])e();}onUnresolved(e){return this.unresolvedCbs.add(e),()=>this.unresolvedCbs.delete(e)}reportUnresolved(e){let t=this.names();console.warn(`[vela] symbol "${e}" not yet resolvable \u2014 registered providers: [${t.join(", ")||"none"}]. Register a provider that serves it.`);for(let n of this.unresolvedCbs)n({symbol:e,providers:t});}candidateOrder(e){let t=this.names();if(e){let n=Ln(e);if(this.entries.has(n))return [n,...t.filter(i=>i!==n)]}return t}displayPrefixOf(e){return this.entries.get(e.provider)?.byTicker?.get(Xn(e.ticker))?.prefix??e.provider}canonicalSymbol(e){let t=this.entries.get(e.provider)?.byTicker?.get(Xn(e.ticker));return `${t?.prefix??e.provider}:${t?.ticker??e.ticker}`}symbolIconOf(e){let t=e.provider?Ln(e.provider):[...this.entries.keys()][0],n=t!==void 0?this.entries.get(t):void 0;try{return n?.provider.resolveSymbolIcon?.(e)??void 0}catch{return}}symbolIcon(e){if(!e)return;let t=this.entries.get(e.provider)?.byTicker?.get(Xn(e.ticker));return this.symbolIconOf({...t??{ticker:e.ticker},provider:t?.provider??e.provider})}symbolsOf(e){return e!=null?this.entries.get(Ln(e))?.descriptors??[]:[...this.entries.entries()].flatMap(([t,n])=>n.descriptors.map(i=>({...i,provider:t})))}infoOf(e){let t=Ln(e),n=this.entries.get(t);if(!n)return {name:t,capabilities:{enumerate:false,stream:false,symbolInfo:false}};let i=n.provider;return i.info?.()??{name:n.name,capabilities:{enumerate:!!i.listSymbols,stream:!!i.subscribe,symbolInfo:!!i.getSymbolInfo}}}indexReady(){return Promise.all([...this.entries.values()].map(e=>e.settle)).then(()=>{})}};var $E=c("chart.settings.rangeMin","{label} \u2014 min"),YE=c("chart.settings.rangeMax","{label} \u2014 max");function ao(r){switch(r.kind){case "row":return {label:r.label,toggle:r.toggle,controls:r.controls,when:r.when};case "toggle":{let e=[];r.number&&e.push({kind:"number",...r.number});for(let t of r.colors??[])e.push({kind:"color",...t});return r.width&&e.push({kind:"width",...r.width}),{label:r.label,toggle:{key:r.key,defval:r.defval},controls:e,when:r.when}}case "number":return {label:r.label,controls:[{kind:"number",key:r.key,label:r.label,defval:r.defval,min:r.min,max:r.max,step:r.step}],when:r.when};case "color":return {label:r.label,controls:[{kind:"color",key:r.key,label:r.label,defval:r.defval}],when:r.when};case "select":return {label:r.label,controls:[{kind:"select",key:r.key,label:r.label,options:r.options,defval:r.defval}],when:r.when};case "range":return {label:r.label,controls:[{kind:"number",key:r.minKey,label:We($E,{label:r.label}),defval:r.defval,min:r.min,max:r.max,step:r.step,placeholder:r.placeholder},{kind:"hint",text:"\u2013"},{kind:"number",key:r.maxKey,label:We(YE,{label:r.label}),defval:r.defval,min:r.min,max:r.max,step:r.step,placeholder:r.placeholder}],when:r.when}}}function Ps(r){if(r.kind==="heading"||r.kind==="header")return [];let e=ao(r),t=[];e.toggle&&t.push({key:e.toggle.key,type:"boolean",defval:e.toggle.defval});for(let n of e.controls)n.kind!=="hint"&&(n.kind==="color"||n.kind==="select"?t.push({key:n.key,type:"string",defval:n.defval}):t.push({key:n.key,type:"number",defval:n.defval}));return t}function gi(r,e){return r?(Array.isArray(r)?r:[r]).every(n=>n.anyOf?n.anyOf.some(i=>i===e[n.key]):e[n.key]===n.equals):true}var Is=new Map;function Yh(r){Is.set(r.id,r);}function KE(r){Is.delete(r);}function jn(r){return typeof r=="string"?Is.get(r):void 0}function Yt(){return [...Is.values()]}function Kh(){return [...Is.values()].filter(r=>r.tickerModifier??r.barTransform!=null).map(r=>r.id)}function lo(r){return jn(r)?.barTransform??null}function Mv(r){let e=r.lastIndexOf(";");if(e<=0||e===r.length-1)return {symbol:r,modifier:null,transform:null};let t=r.slice(e+1).toLowerCase();return t!=="standard"&&!Kh().includes(t)?{symbol:r,modifier:null,transform:null}:{symbol:r.slice(0,e),modifier:t,transform:lo(t)}}var En={background:"#151619",textColor:"#b2b5be",gridColor:"#20222c",borderColor:"#2a2b30",upColor:N,downColor:O,fontFamily:"sans-serif"},As={background:"#ffffff",textColor:"#1e293b",gridColor:"#cccccc",borderColor:"#d4dae3",upColor:N,downColor:O,fontFamily:"sans-serif"};function co(r){return !r||r==="dark"?En:r==="light"?As:r}function qn(r){return r!=null&&typeof r!="string"?r:void 0}function Wt(r,e={}){let{title:t,tooltip:n,display:i,...o}=r,s={...i},a=qn(t);a&&!s.title&&(s.title=a);let l=qn(n);l&&!s.tooltip&&(s.tooltip=l);let d=o.group!=null?e.groups?.[o.group]:void 0;if(d&&!s.group&&(s.group=d),o.options&&e.options&&!s.options){let h={},p=false;for(let m of o.options){let g=e.options[m];g&&(h[m]=g,p=true);}p&&(s.options=h);}let u={...o,title:Re(t)};return n!=null&&(u.tooltip=Re(n)),Object.keys(s).length>0&&(u.display=s),u}var XE=150,jE=1e3,qE=300,ZE=5e3,Ev=1e4,QE=20,JE=1.5,Pv=5e3,eP=16,Vc=class r{constructor(e,t,n,i,o,s){this.renderer=t;this.feed=n;this.config=o;this.dataControl=s;this.events=new jr;this.registry=new al;this.paneOrder=["price"];this.collapsedPanes=new Set;this.maximizedPaneId=null;this.paneActionUnsub=null;this.i18n=Ae();this.handles=new Map;this.engines=new Map;this.live=null;this.bars=[];this.rawBars=[];this.barTransform=null;this.typeEngines=new Map;this.suspendedEngines=new WeakSet;this.typeSettings=new Map;this.activeEngineStyle=null;this.priceStyle="candles";this.priceStyleWillChangeUnsub=null;this.unresolvedUnsub=null;this.visibleRange=null;this.viewportUnsub=null;this.viewportTimer=null;this.healing=false;this.healBuffer=[];this.lastHealAt=0;this.onVisible=null;this.replayQueue=null;this.replayTimer=null;this.replayPlaying=false;this.replayIntervalMs=1e3;this.replayDepth=null;this.replayLoading=null;this.replayCarrying=null;this.replayTickSource=null;this.replayForming=null;this.replayTickFetches=new Map;this.replayTickAbort=null;this.barCause="tick";this.historyState="complete";this.generation=0;this.progressiveAbort=null;this.supersedeWaiters=[];this.historyCompleted=false;this.historyCompletePromise=new Promise(e=>{this.resolveHistoryComplete=e;});this.switchingMarket=false;this.loadingUp=false;this.volumeOptedOut=false;this.contextEmitAt=new Map;this.runEmitAt=new Map;for(let d of i)this.registerEngine(d.language,d);this.defaultLanguage=o.defaultLanguage,this.renderer.mount(e,o.theme),this.renderer.onInputChange(d=>d.kind==="prop"?this.applyProps(d.indicatorId,{[d.key]:d.value}):this.applyInputs(d.indicatorId,{[d.key]:d.value})),this.renderer.onRemoveIndicator(d=>this.removeIndicator(d)),this.renderer.onToggleIndicatorVisible?.((d,u)=>this.setVisible(d,u)),this.paneActionUnsub=this.renderer.onPaneAction?.(d=>this.handlePaneAction(d))??null,this.renderer.onChartTypeSettingsChange?.((d,u)=>{this.typeSettings.set(d,u),this.typeEngines.get(d)?.onSettings?.(u);}),this.renderer.onMoveIndicator?.((d,u)=>this.moveIndicator(d,u)),this.renderer.onThemeSelect?.(d=>this.setTheme(co(d))),this.viewportUnsub=this.renderer.onViewportChange(d=>this.onViewportChange(d)),this.renderer.onPriceStyleChange?.(d=>this.syncPriceStyle(d)),this.priceStyleWillChangeUnsub=this.renderer.onPriceStyleWillChange?.((d,u)=>this.events.emit("priceStyle:change",{from:d,to:u}))??null;let a=this.renderer.readFeature("priceStyle");typeof a=="string"&&(this.priceStyle=a),this.barTransform=lo(a);let l=new Fc({fetchBars:(d,u)=>this.fetchSeries(this.config.market.symbol??"",d,u),canFetch:()=>!!this.feed.loadRange&&!this.config.market.data?.length&&!!this.config.market.symbol,chartTimeframe:()=>this.config.market.timeframe??"60",marketKey:()=>`${this.config.market.symbol??""}|${this.config.market.session??""}`});this.drawings=new Rc(this.renderer,this.events,o.drawings,l,()=>this.i18n),this.marks=new Nc(this.renderer,this.events),this.unresolvedUnsub=this.feed.onUnresolved?.(d=>{this.endLoad(),this.events.emit("data:unresolved",d);})??null,this.readyPromise=this.init(),jn(a)?.dataEngine&&this.syncChartTypeEngine(a);}currentVisibleRange(){if(this.visibleRange)return this.visibleRange;let e=this.renderer.getVisibleRange();return e?{left:e.from,right:e.to}:void 0}engineFor(e){let t=e??this.defaultLanguage,n=this.engines.get(t);if(!n)throw new Error(`[vela] no scripting engine registered for language "${t}". Vela ships none \u2014 install one (Pine Script: @luxalgo/vela-pinets) and register it before addIndicator, e.g. chart.registerEngine('pine', new PineEngine()).`);return n}market(){return {symbol:this.config.market.symbol??"TEST",timeframe:this.config.market.timeframe??"60",symbolInfo:this.feed.symbolInfo?.(this.config.market),chartStyle:this.priceStyle}}async fetchSeries(e,t,n){let i=Mv(e),o={symbol:i.symbol,timeframe:t},s=await(this.feed.loadRange?this.feed.loadRange(o,n):this.feed.load({...o,bars:n.limit}));return i.transform?i.transform.full(s):s}onViewportChange(e){this.visibleRange={left:e.from,right:e.to},this.events.emit("viewport:changed",{from:e.from,to:e.to}),this.viewportTimer!=null&&clearTimeout(this.viewportTimer),this.viewportTimer=setTimeout(()=>{if(this.viewportTimer=null,this.switchingMarket)return;let t=this.visibleRange;if(t){for(let n of this.registry.all())!n.renderHandle||n.hidden||(n.session&&n.prepared?.reactsToViewport?(n.pendingCause="viewport",n.session.setVisibleRange(t)):n.native?.descriptor.reactsToViewport&&n.native.instance.onViewport({from:t.left,to:t.right}));this.activeEngineStyle&&this.typeEngines.get(this.activeEngineStyle)?.onViewport?.({from:t.left,to:t.right});}},XE);}async init(){let e=this.bumpGeneration();this.beginLoad(true),await this.loadMarket(e,{firstLoad:true}),this.generation===e&&(this.startLive(),this.events.emit("ready",void 0));}bumpGeneration(){let e=++this.generation;this.progressiveAbort?.abort(),this.progressiveAbort=null;for(let t of this.supersedeWaiters.splice(0))t();return e}beginLoad(e){if(this.loadingUp)return;this.loadingUp=true,this.renderer.setLoading?.(true);let t=this.config.market;this.events.emit("load:start",{symbol:t.symbol??"TEST",timeframe:t.timeframe??"60",firstLoad:e});}endLoad(){if(!this.loadingUp)return;this.loadingUp=false,this.renderer.setLoading?.(false);let e=this.config.market;this.events.emit("load:end",{symbol:e.symbol??"TEST",timeframe:e.timeframe??"60",bars:this.bars.length});}async loadMarket(e,t){try{await this.loadMarketInner(e,t);}finally{this.generation===e&&this.endLoad();}}async loadMarketInner(e,t){let n=this.config.market,i=n.bars??500,o=n.visibleRange,s=!n.data?.length&&o==null&&i>ZE,a=false;if(!n.data?.length&&o==null&&this.feed.loadProgressive){let l=false,d=(h,p)=>{if(this.generation!==e||!p&&h.length===0||!l&&!p&&h.length<Math.min(i,QE))return;if(l&&this.replayQueue){this.mergeHistoryIntoReplay(h);return}let m=l;this.setBarSeries(h,m?{preserveView:true}:void 0),!l&&h.length>0&&(l=true,t.firstLoad&&this.activateBarLayers(),p||(this.historyState="backfill")),m&&!p&&this.notifySessionsBars("backfill");},u=new AbortController;this.progressiveAbort=u,a=await new Promise(h=>{let p=false,m=g=>{p||(p=true,h(g));};u.signal.addEventListener("abort",()=>m(true),{once:true}),this.feed.loadProgressive(n,g=>{d(g,false),l&&m(true);},{signal:u.signal}).then(g=>{if(this.progressiveAbort===u&&(this.progressiveAbort=null),g==null)return m(false);if(this.generation!==e)return m(true);d(g,true),this.completeHistory(g.length>=i?"depth":"genesis"),m(true);}).catch(()=>{this.progressiveAbort===u&&(this.progressiveAbort=null),this.generation===e&&this.completeHistory("aborted"),m(true);});});}if(!a)if(s&&this.feed.loadRange){let l=await this.feed.load({...n,bars:Math.min(i,Ev)});if(this.generation!==e)return;this.setBarSeries(l),t.firstLoad&&this.activateBarLayers(),l.length>0&&i>l.length?(this.historyState="backfill",this.backfillHistory(e,i)):this.completeHistory("depth");}else if(s){let l=await this.feed.load({...n,bars:qE});if(this.generation!==e)return;this.setBarSeries(l),t.firstLoad&&this.activateBarLayers();let d=await this.feed.load(n);if(this.generation!==e)return;this.setBarSeries(d,{preserveView:true}),this.completeHistory("depth");}else {let l=await this.feed.load(n);if(this.generation!==e)return;this.setBarSeries(l),t.firstLoad&&this.activateBarLayers(),this.completeHistory("depth");}o!=null&&(typeof o=="string"?this.setVisibleRangePreset(o):this.renderer.setVisibleRange(o)),this.refreshPriceFormat(),this.ensurePriceFormat();}startLive(){this.config.live&&(this.live=new fl(this.feed,this.config.market,e=>this.onBar(e)),this.live.start(),typeof document<"u"&&(this.onVisible=()=>{if(document.visibilityState!=="visible")return;let e=this.bars[this.bars.length-1];!e||this.healing||!this.canHeal()||Date.now()-this.lastHealAt<=Pv||this.healGap(e.time);},document.addEventListener("visibilitychange",this.onVisible)));}stopLive(){this.live?.stop(),this.live=null,this.onVisible&&typeof document<"u"&&document.removeEventListener("visibilitychange",this.onVisible),this.onVisible=null,this.healing=false,this.healBuffer=[],this.lastHealAt=0;}resetHistoryTracking(){this.resolveHistoryComplete(),this.historyCompleted=false,this.historyState="complete",this.historyCompletePromise=new Promise(e=>{this.resolveHistoryComplete=e;});}marketSnapshot(){let e=this.config.market;return {symbol:e.symbol,provider:Mn(e.symbol??"").provider??void 0,timeframe:e.timeframe,bars:e.bars,session:e.session,offline:e.data!==void 0}}async setMarket(e){let t=this.config.market,n=e.symbol!==void 0&&e.symbol!==t.symbol||e.timeframe!==void 0&&e.timeframe!==t.timeframe||e.session!==void 0&&e.session!==t.session||e.data!==void 0,i=e.bars!==void 0&&e.bars!==t.bars,o=n&&e.data===void 0&&(e.symbol===void 0||e.symbol===t.symbol)&&(e.timeframe!==void 0||e.session!==void 0),s=n?this.replayCarrying:null;s&&(this.replayCarrying=null,o||(s.cancelled=true,this.events.emit("replay:end",{reason:"market"})));let a=this.replayQueue&&o&&this.rawBars.length>0?{revealedEnd:this.rawBars[this.rawBars.length-1].time+this.barIntervalMs(),playing:this.replayPlaying,cancelled:false}:s&&o?{revealedEnd:s.revealedEnd,playing:s.playing,cancelled:false}:null;if(s&&(s.cancelled=true),a&&(this.replayCarrying=a),a&&this.replayQueue){this.endReplay(null,{restore:false,resume:false});let w=this.replayDepth;this.replayDepth=null,w&&e.bars===void 0&&(w.bars===void 0?delete t.bars:t.bars=w.bars);}if(this.replayQueue&&(n||i)&&this.endReplay("market",{restore:!n,resume:false}),this.replayLoading&&(n||i)){let w=this.replayDepth;this.abandonReplayLoad("market"),w&&e.bars===void 0&&(w.bars===void 0?delete t.bars:t.bars=w.bars);}let l=i&&!n&&this.rawBars.length>0&&!t.data?.length&&((e.bars??0)<=this.rawBars.length||typeof this.feed.loadRange=="function");if(!n&&!i){typeof e.visibleRange=="string"?this.setVisibleRangePreset(e.visibleRange):e.visibleRange&&this.renderer.setVisibleRange(e.visibleRange);return}let d={symbol:t.symbol??"TEST",timeframe:t.timeframe??"60"},h=n&&e.session!==void 0&&e.data===void 0&&(e.symbol===void 0||e.symbol===t.symbol)&&(e.timeframe===void 0||e.timeframe===t.timeframe)&&e.visibleRange===void 0?this.currentVisibleRange():void 0,p=h?this.rawBars.filter(w=>w.time>=h.left&&w.time<=h.right).length:0,m=this.bumpGeneration();this.switchingMarket=true;try{if(this.stopLive(),this.viewportTimer!=null&&(clearTimeout(this.viewportTimer),this.viewportTimer=null),this.visibleRange=null,this.resetHistoryTracking(),e.symbol!==void 0&&(t.symbol=e.symbol),e.timeframe!==void 0&&(t.timeframe=e.timeframe),e.bars!==void 0&&(t.bars=e.bars),e.session!==void 0&&(t.session=e.session),h){let w=Math.min(Math.ceil((Date.now()-h.left)/this.barIntervalMs())+50,5e3);w>(t.bars??500)&&(t.bars=w);}if(e.data!==void 0?t.data=e.data:e.symbol!==void 0&&delete t.data,t.visibleRange=e.visibleRange??(h?{from:h.left,to:h.right}:void 0),n){this.beginLoad(!1),this.setBarSeries([],{clearing:!0}),this.blankIndicatorVisuals(),this.activeEngineStyle&&(this.suspendTypeEngine(this.typeEngines.get(this.activeEngineStyle)),this.renderer.setNativeData?.(this.activeEngineStyle,void 0),this.renderer.setNativeData?.(`${this.activeEngineStyle}-pending`,[]));for(let w of this.registry.all())w.native?.started&&(this.stopNativeInstance(w.native),this.renderer.setNativeData?.(this.nativeChannel(w),void 0));}if(l?this.extendDepth(m,t.bars??500):await Promise.race([this.loadMarket(m,{firstLoad:!1}),new Promise(w=>this.supersedeWaiters.push(w))]),this.generation!==m)return}finally{this.generation===m&&(this.switchingMarket=false);}if(h&&p>=2&&this.rawBars.length>0){let w=this.rawBars,x=w.length-1;for(;x>0&&w[x].time>h.right;)x-=1;let T=w[Math.max(0,x-(p-1))].time;this.renderer.setVisibleRange({from:T,to:Math.max(h.right,w[x].time+1)});}let g=a&&!a.cancelled?a:null,b=g?g.revealedEnd-this.barIntervalMs():0,f=g!=null&&this.rawBars.length>0&&b>=this.rawBars[0].time,v=f&&this.resumeCarriedReplay(this.replayStart({from:b}),g);!l&&!v&&(this.restartNativeIndicators(),this.restartChartTypeEngine(),this.reexecuteIndicators()),l&&this.releaseHeldNatives(),v||this.startLive(),n&&this.events.emit("market:changed",{symbol:t.symbol??"TEST",timeframe:t.timeframe??"60",prev:d}),g&&!f&&this.resumeCarriedReplay(this.replayStart({from:b}),g);}restartNativeIndicators(){for(let e of this.registry.all())if(e.native)if(this.stopNativeInstance(e.native),e.native.instance=e.native.descriptor.create(),e.pendingStructural=true,e.hidden)e.native.stale=true;else {let t=this.handles.get(e.id);t&&this.startNativeIndicator(e.id,t);}}restartChartTypeEngine(){for(let e of this.typeEngines.values())e.stop();this.typeEngines.clear(),this.activeEngineStyle&&this.startChartTypeEngine(this.activeEngineStyle);}suspendTypeEngine(e){e&&(e.suspend(),this.suspendedEngines.add(e));}stopNativeInstance(e){e.started&&e.instance.stop(),e.started=false,e.revokeContext?.(),e.revokeContext=void 0;}activateBarLayers(){this.maybeAutoAddVolume();}extendDepth(e,t){if(this.rawBars.length>t){this.setBarSeries(this.rawBars.slice(this.rawBars.length-t),{preserveView:true}),this.completeHistory("depth");return}if(this.rawBars.length===t){this.completeHistory("depth");return}this.historyState="backfill",this.backfillHistory(e,t);}async backfillHistory(e,t){try{for(;this.generation===e&&this.rawBars.length<t&&this.rawBars.length>0;){let n=t-this.rawBars.length,i=Ev,o=await this.feed.loadRange(this.config.market,{to:this.rawBars[0].time,limit:Math.min(i,n)+1});if(this.generation!==e)return;let s=this.rawBars[0].time,a=o.filter(l=>l.time<s);if(a.length===0){this.completeHistory("genesis");return}for(let l=1;l<a.length;l+=1)if(a[l].time<=a[l-1].time){console.warn("[vela] non-monotonic history chunk \u2014 stopping the backfill"),this.completeHistory("aborted");return}this.setBarSeries([...a,...this.rawBars],{preserveView:!0}),this.notifySessionsBars("backfill"),this.events.emit("history:progress",{loaded:this.rawBars.length,target:t});}this.generation===e&&this.completeHistory("depth");}catch(n){console.warn(`[vela] history backfill failed \u2014 keeping ${this.rawBars.length} bars (${n instanceof Error?n.message:String(n)})`),this.generation===e&&this.completeHistory("aborted");}}completeHistory(e){this.historyCompleted||(this.historyCompleted=true,this.historyState="complete",this.notifySessionsBars("complete"),this.events.emit("history:complete",{reason:e,oldestTime:this.rawBars[0]?.time??0,barsLoaded:this.rawBars.length}),this.resolveHistoryComplete());}historyComplete(){return this.historyCompletePromise}async replayStart(e){if(this.rawBars.length===0){console.warn("[vela] chart.replay.start() ignored \u2014 the chart has no bars yet");return}let t=this.generation;if(e.from<this.rawBars[0].time&&(await this.historyCompletePromise,this.generation!==t||this.rawBars.length===0))return;let n=this.rawBars[0].time;if(e.from<n&&this.canHeal()&&typeof this.feed.loadRange=="function"){let l=this.rawBars.length+(this.replayQueue?.length??0)+Math.ceil((n-e.from)/this.barIntervalMs())+1,d=this.replayQueue!==null;d&&this.endReplay(null,{restore:true,resume:false}),this.replayDepth??(this.replayDepth={bars:this.config.market.bars});let u=this.setMarket({bars:l});if(this.replayLoading={seek:d},await u,t=this.generation,await this.historyCompletePromise,!this.replayLoading||this.generation!==t||this.rawBars.length===0)return;this.replayLoading=null;}this.settleFormingBar(),this.dropTickFetches();let i=this.replayQueue?[...this.rawBars,...this.replayQueue]:this.rawBars,o=0;for(;o<i.length&&i[o].time<=e.from;)o+=1;if(o=Math.max(1,o),o>=i.length){console.warn("[vela] chart.replay.start() ignored \u2014 no bar opens after the requested time");return}let s=this.replayPlaying;this.clearReplayTimer(),this.replayQueue||this.stopLive(),this.replayQueue=i.slice(o),this.setBarSeries(i.slice(0,o)),this.restartBarConsumers({blank:true}),s&&this.events.emit("replay:pause",void 0),this.events.emit("replay:start",{cursorTime:i[o-1].time,remaining:this.replayQueue.length}),this.prefetchTicks();}replayStep(){if(this.replayForming)return this.finishFormingBar(),true;let e=this.replayQueue,t=e?.shift();return !e||!t?false:(this.replayTickFetches.delete(t.time),this.applyBar(t),this.completeReveal(t),this.prefetchTicks(),true)}resumeCarriedReplay(e,t){return this.replayQueue&&this.replayCarrying===t&&(this.replayCarrying=null),e.then(()=>{this.replayCarrying===t&&(this.replayCarrying=null),!t.cancelled&&(this.replayQueue?t.playing&&this.replayPlay():this.events.emit("replay:end",{reason:"market"}));}),this.replayQueue!==null}replayStepUpdate(){if(!this.replayQueue)return false;if(this.replayForming)return this.applyReplayTicks(1),true;let e=this.replayQueue[0];if(!e)return false;let t=this.replayTickSource?this.requestTicks(e):null;if(t&&!t.ticks){let n=this.replayTickAbort;return t.done.then(()=>{!this.replayPlaying&&!this.replayForming&&this.replayTickAbort===n&&this.replayQueue?.[0]===e&&this.replayStepUpdate();}),true}return t?.ticks?.length?(this.openFormingBar(t.ticks,1),true):this.replayStep()}replaySetTicks(e){this.finishFormingBar(),this.dropTickFetches(),this.replayTickSource=e,this.prefetchTicks();}replayPlay(e){if(this.replayQueue){if(e!==void 0){if(!(Number.isFinite(e)&&e>0)){console.warn(`[vela] chart.replay.play(${e}) ignored \u2014 the interval must be a positive number of ms`);return}this.replayIntervalMs=e;}this.clearReplayTimer(),this.replayPlaying=true,this.replayForming&&this.paceFormingBar(this.replayForming),this.scheduleReplayStep(this.replayForming?.delayMs),this.events.emit("replay:play",{intervalMs:this.replayIntervalMs});}}replayPause(){this.replayPlaying&&(this.clearReplayTimer(),this.events.emit("replay:pause",void 0));}replayStop(){let e=this.replayCarrying;if(e&&(e.cancelled=true,this.replayCarrying=null,this.events.emit("replay:end",{reason:"stopped"})),this.replayLoading){let t=this.replayDepth;this.abandonReplayLoad("stopped"),this.setMarket({bars:t?.bars??500});return}this.endReplay("stopped",{restore:true,resume:true});}abandonReplayLoad(e){let t=this.replayLoading;t&&(this.replayLoading=null,this.replayDepth=null,t.seek&&this.events.emit("replay:end",{reason:e}));}replayState(){let e=this.replayQueue!==null;return {active:e||this.replayCarrying!==null,playing:this.replayCarrying?.playing??this.replayPlaying,cursorTime:e?this.rawBars[this.rawBars.length-1]?.time??null:null,remaining:this.replayQueue?.length??0,nextTime:this.replayForming?.bar.time??this.replayQueue?.[0]?.time??null,intervalMs:this.replayIntervalMs}}replayBounds(){let e=this.rawBars[0],t=this.replayQueue?.[this.replayQueue.length-1]??this.rawBars[this.rawBars.length-1];return e&&t?{first:e.time,last:t.time}:null}scheduleReplayStep(e=this.replayIntervalMs){this.replayTimer=setTimeout(()=>{this.replayTimer=null,this.replayAdvance();},e);}replayAdvance(){if(!this.replayPlaying||!this.replayQueue)return;let e=this.replayForming;if(e){let i=Math.floor((Iv()-e.origin)/this.replayIntervalMs)+1;this.applyReplayTicks(Math.max(e.batch,i-e.next)),this.replayPlaying&&this.scheduleReplayStep(e.delayMs);return}let t=this.replayQueue[0];if(!t)return;let n=this.replayTickSource?this.requestTicks(t):null;if(n&&!n.ticks){let i=this.replayTickAbort;n.done.then(()=>{this.replayPlaying&&this.replayTimer==null&&this.replayTickAbort===i&&this.replayQueue?.[0]===t&&this.replayAdvance();});return}if(!n?.ticks?.length){this.replayStep()&&this.replayPlaying&&this.scheduleReplayStep();return}this.openFormingBar(n.ticks),this.replayPlaying&&this.scheduleReplayStep(this.replayForming?.delayMs);}openFormingBar(e,t){let n=this.replayQueue.shift(),i=e.every(s=>s.volume===void 0)?(n.volume??0)/e.length:null,o={bar:n,ticks:e,next:0,candle:null,volumeEach:i,batch:1,delayMs:this.replayIntervalMs,origin:0};this.paceFormingBar(o),this.replayForming=o,this.applyReplayTicks(t??o.batch),this.prefetchTicks();}paceFormingBar(e){e.batch=Math.max(1,Math.ceil(eP/this.replayIntervalMs)),e.delayMs=this.replayIntervalMs*e.batch,e.origin=Iv()-Math.max(0,e.next-1)*this.replayIntervalMs;}applyReplayTicks(e){let t=this.replayForming;if(!t)return;let n=t.candle,i=Math.min(t.ticks.length,t.next+e);for(;t.next<i;t.next+=1){let o=t.ticks[t.next],s=t.volumeEach??o.volume??0,a=Math.max(o.high??o.price,o.price),l=Math.min(o.low??o.price,o.price);if(n)n={...n,high:Math.max(n.high,a),low:Math.min(n.low,l),close:o.price,volume:(n.volume??0)+s};else {let d=o.open??o.price;n={time:t.bar.time,open:d,high:Math.max(d,a),low:Math.min(d,l),close:o.price,volume:s};}}if(t.candle=n,t.next>=t.ticks.length){this.finishFormingBar();return}this.applyBar(n),this.events.emit("replay:tick",{cursorTime:t.bar.time,index:t.next-1,count:t.ticks.length});}finishFormingBar(){let e=this.replayForming;e&&(this.replayForming=null,this.replayTickFetches.delete(e.bar.time),this.applyBar(e.bar),this.events.emit("replay:tick",{cursorTime:e.bar.time,index:e.ticks.length-1,count:e.ticks.length}),this.completeReveal(e.bar));}settleFormingBar(){let e=this.replayForming;e&&(this.replayForming=null,this.applyBar(e.bar));}mergeHistoryIntoReplay(e){let t=this.replayQueue,n=this.rawBars[0];if(!t||!n)return;let i=t[t.length-1]??this.rawBars[this.rawBars.length-1],o=0;for(;o<e.length&&e[o].time<n.time;)o+=1;let s=e.length;for(;s>o&&e[s-1].time>i.time;)s-=1;s<e.length&&t.push(...e.slice(s)),o>0&&(this.setBarSeries([...e.slice(0,o),...this.rawBars],{preserveView:true}),this.notifySessionsBars("backfill"));}completeReveal(e){let t=this.replayQueue;t&&(this.events.emit("replay:step",{cursorTime:e.time,remaining:t.length}),t.length===0&&this.endReplay("finished",{restore:true,resume:true}));}prefetchTicks(){let e=this.replayQueue?.[0];e&&this.replayTickSource&&this.requestTicks(e);}requestTicks(e){let t=this.replayTickFetches.get(e.time);if(t)return t;let n=this.replayTickSource;this.replayTickAbort??(this.replayTickAbort=new AbortController);let i=this.replayTickAbort.signal,o=this.replayQueue??[],s=o[o.indexOf(e)+1]?.time??e.time+this.barIntervalMs(),a={ticks:null,done:Promise.resolve()},l=u=>{a.ticks=tP(u);},d=u=>{i.aborted||console.warn(`[vela] replay tick source failed \u2014 revealing the bar whole (${u instanceof Error?u.message:String(u)})`),l([]);};try{let u=n(e,{end:s,signal:i});Array.isArray(u)?l(u):a.done=Promise.resolve(u).then(l,d);}catch(u){d(u);}return this.replayTickFetches.set(e.time,a),a}dropTickFetches(){this.replayTickAbort?.abort(),this.replayTickAbort=null,this.replayTickFetches.clear();}clearReplayTimer(){this.replayTimer!=null&&clearTimeout(this.replayTimer),this.replayTimer=null,this.replayPlaying=false;}endReplay(e,t){let n=this.replayQueue;if(!n)return;this.clearReplayTimer(),t.restore?this.settleFormingBar():this.replayForming=null,this.dropTickFetches(),this.replayQueue=null;let i=e?this.replayDepth:null;if(e&&(this.replayDepth=null),i&&(i.bars===void 0?delete this.config.market.bars:this.config.market.bars=i.bars),t.restore){let o=i?i.bars??500:1/0;if(n.length>0||this.rawBars.length>o){let s=[...this.rawBars,...n];this.setBarSeries(s.length>o?s.slice(s.length-o):s),this.restartBarConsumers({blank:false});}else this.config.live&&(this.restartNativeIndicators(),this.restartChartTypeEngine());}if(t.resume&&this.config.live){this.startLive();let o=this.rawBars[this.rawBars.length-1];o&&this.canHeal()&&this.healGap(o.time);}e&&this.events.emit("replay:end",{reason:e});}restartBarConsumers(e){e.blank&&this.blankIndicatorVisuals(),this.restartNativeIndicators(),this.restartChartTypeEngine(),this.reexecuteIndicators();}qualifiedSymbol(){let e=this.config.market;return e.symbol?e.symbol:null}refreshPriceFormat(){if(!this.renderer.setPricePrecision)return;let e=this.feed.symbolInfo?.(this.config.market)?.mintick;this.renderer.setPricePrecision(typeof e=="number"&&e>0?e:void 0);}async ensurePriceFormat(){if(!this.renderer.setPricePrecision)return;let e=this.qualifiedSymbol();if(e)try{await this.dataControl.symbolInfo(e),this.refreshPriceFormat();}catch{}}maybeAutoAddVolume(){!this.config.volume||this.volumeOptedOut||!this.renderer.setNativeData||Th("volume")&&this.addNativeIndicator("volume");}syncPriceStyle(e){typeof e=="string"&&(this.priceStyle=e),this.syncBarTransform(e),this.syncChartTypeEngine(e);}syncChartTypeEngine(e){let t=typeof e=="string"?e:null,i=jn(t)?.dataEngine?t:null;i!==this.activeEngineStyle&&(this.activeEngineStyle&&this.suspendTypeEngine(this.typeEngines.get(this.activeEngineStyle)),this.activeEngineStyle=i,i&&this.startChartTypeEngine(i));}async startChartTypeEngine(e){if(!this.renderer.setNativeData||(await this.readyPromise,this.activeEngineStyle!==e))return;let t=this.typeEngines.get(e);if(t){this.suspendedEngines.delete(t),t.resume();return}let n=jn(e);if(!n?.dataEngine)return;let i=n.dataEngine();this.typeEngines.set(e,i);let o=this.typeSettings.get(e);o&&i.onSettings?.(o);let s=()=>this.typeEngines.get(e)===i&&!this.suspendedEngines.has(i);i.start({symbol:this.config.market.symbol??"TEST",timeframe:this.config.market.timeframe??"60",live:(this.config.live??false)&&this.replayQueue===null,session:this.config.market.session,bars:()=>this.bars,data:this.dataControl,pushData:a=>{s()&&this.renderer.setNativeData?.(e,a);},pushPending:a=>{s()&&this.renderer.setNativeData?.(`${e}-pending`,a);}});}syncBarTransform(e){let t=lo(e);if(t!==this.barTransform&&(this.barTransform=t,this.rawBars.length!==0&&(this.bars=t?t.full(this.rawBars):this.rawBars,this.renderer.setBars(this.bars,{preserveView:true}),this.reexecuteIndicators(),!this.switchingMarket)))for(let n of this.registry.all())n.native?.started&&n.renderHandle&&!n.hidden&&this.pokeNative(n);}blankIndicatorVisuals(){for(let e of this.registry.all())e.hidden||!e.renderHandle||!e.model||(e.model=iP(e.model),e.renderHandle=this.renderer.mountIndicator(e.model),e.pendingStructural=true,this.setLoading(e,true));}reexecuteIndicators(){for(let e of this.registry.all()){if(e.hidden||!e.session)continue;e.session.stop(),e.session=void 0,e.pendingStructural=true,e.pendingCause="market",this.setLoading(e,true);let t=this.handles.get(e.id);t&&this.executeIndicator(e.id,t);}}onBar(e){if(this.healing){this.healBuffer.push(e);return}let t=this.rawBars[this.rawBars.length-1];if(t&&this.canHeal()&&e.time>t.time+this.barIntervalMs()*JE&&Date.now()-this.lastHealAt>Pv){this.healBuffer.push(e),this.healGap(t.time);return}this.applyBar(e);}setBarSeries(e,t){this.rawBars=e,this.bars=this.barTransform?this.barTransform.full(e):e,this.renderer.setBars(this.bars,{preserveView:t?.preserveView}),!t?.clearing&&this.bars.length>0&&this.endLoad();}applyBar(e,t=true){let n=this.rawBars[this.rawBars.length-1],i=e;if(n&&e.time===n.time)this.rawBars[this.rawBars.length-1]=e,this.barCause="tick",this.barTransform&&(i=this.barTransform.next(e,this.bars[this.bars.length-2]),this.bars[this.bars.length-1]=i);else if(!n||e.time>n.time)this.rawBars.push(e),this.barCause="bar",this.barTransform&&(i=this.barTransform.next(e,this.bars[this.bars.length-1]),this.bars.push(i));else return;this.renderer.updateBar(i),this.events.emit("bar",e),t&&this.notifySessionsBars(this.historyState==="backfill"?"backfill":void 0);}notifySessionsBars(e){if(this.switchingMarket)return;let t=e?"history":this.barCause;for(let n of this.registry.all())!n.renderHandle||n.hidden||(n.session?(n.pendingCause=t,n.session.notifyBars(e)):n.native&&this.pokeNative(n));this.activeEngineStyle&&this.typeEngines.get(this.activeEngineStyle)?.onBars?.();}pokeNative(e){let t=e.native;if(!t.descriptor.waitsForHistory){t.instance.onBars();return}if(this.historyState!=="backfill"){if(t.heldForHistory){t.heldForHistory=false;let n=this.handles.get(e.id);n&&this.startNativeIndicator(e.id,n);return}t.started&&t.instance.onBars();}}releaseHeldNatives(){if(this.historyState!=="backfill")for(let e of this.registry.all())e.native?.heldForHistory&&!e.hidden&&this.pokeNative(e);}canHeal(){return !!this.feed.loadRange&&!this.config.market.data?.length}barIntervalMs(){return an(this.config.market.timeframe??"60")}async healGap(e){let t=this.generation;this.healing=true,this.lastHealAt=Date.now();try{let n=await this.feed.loadRange(this.config.market,{from:e});if(this.generation!==t||this.replayQueue)return;for(let i of n)this.applyBar(i,!1);}catch{}finally{if(this.generation===t&&!this.replayQueue){this.healing=false;let n=this.healBuffer;this.healBuffer=[];for(let i of n)this.applyBar(i,false);this.notifySessionsBars(this.historyState==="backfill"?"backfill":void 0);}}}registerEngine(e,t){let n=this.engines.get(e);n&&n!==t&&console.warn(`[vela] re-registering scripting engine for language "${e}"; replacing ${n.constructor.name} with ${t.constructor.name}.`),this.engines.set(e,t);}addIndicator(e,t={}){let n=this.claimIndicatorId(t.id),i=t.title??"Indicator",o=new Ki(n,i,this,e);return this.handles.set(n,o),this.registry.add({id:n,title:i,source:e,options:t,inputValues:{...t.inputs??{}},propValues:{...t.props??{}}}),this.startIndicator(n,e,t,o),o}addNativeIndicator(e,t={}){let n=Th(e);if(!n?.multiInstance){let l=this.registry.all().find(d=>d.native?.type===e);if(l)return this.handles.get(l.id)??new Ki(l.id,l.title,this,void 0,e)}let i=this.registry.nextId("native",l=>this.handles.has(l)),o=n?X(this.i18n,n.title):e,s=new Ki(i,o,this,void 0,e);if(this.handles.set(i,s),!n)return console.warn(`[vela] addNativeIndicator("${e}") \u2014 no native indicator registered for this type.`),s;let a={...n.defaultInputs(),...t.inputs??{}};return this.registry.add({id:i,title:o,source:e,inputValues:a,propValues:{},native:{type:e,instance:n.create(),descriptor:n}}),s.setSchema(n.inputsSchema()),this.startNativeIndicator(i,s),s}presentNativeIndicators(){return this.registry.all().map(e=>e.native?.type).filter(e=>!!e)}async availableNativeIndicators(){let e=this.qualifiedSymbol(),t=new Set(this.presentNativeIndicators());return Promise.all(gb().map(async n=>({type:n.type,title:X(this.i18n,n.title),supported:await this.isNativeSupported(n,e),present:t.has(n.type),beta:n.beta,...n.multiInstance?{multiInstance:true}:{}})))}async isNativeSupported(e,t){if(!e.isSupported)return true;if(!t)return false;try{return await e.isSupported(t,this.dataControl)}catch{return false}}applyInputs(e,t){let n=this.registry.get(e);!n||!n.session&&!n.native||(n.inputValues={...n.inputValues,...t},n.renderHandle&&this.renderer.setIndicatorInputs(n.renderHandle,n.inputValues),n.pendingStructural=true,!n.hidden&&!n.native&&this.setLoading(n,true),n.pendingCause="inputs",n.session?n.session.update(n.inputValues):n.native&&!n.hidden&&n.native.instance.setInputs(n.inputValues),this.events.emit("indicator:inputs",{id:e}));}inputValuesOf(e){return {...this.registry.get(e)?.inputValues}}propValuesOf(e){return {...this.registry.get(e)?.propValues}}applyProps(e,t){let n=this.registry.get(e);n?.session&&(n.propValues={...n.propValues,...t},n.renderHandle&&this.renderer.setIndicatorInputs(n.renderHandle,n.inputValues,n.propValues),n.pendingStructural=true,n.hidden||this.setLoading(n,true),n.pendingCause="inputs",n.session.update(n.inputValues,n.propValues),this.events.emit("indicator:inputs",{id:e}));}updateCode(e,t){let n=this.registry.get(e),i=this.handles.get(e);return !n||!i?Promise.resolve({ok:false,error:new Error(`[vela] updateCode("${e}") \u2014 the indicator is no longer on the chart.`)}):n.native?(console.warn(`[vela] updateCode("${e}") \u2014 a native indicator has no script to update.`),Promise.resolve({ok:false,error:new Error(`[vela] updateCode("${e}") \u2014 a native indicator has no script to update.`)})):!(n.pendingSource!==void 0||n.codeTrial!==void 0)&&t===n.source?Promise.resolve({ok:true,error:null}):new Promise(s=>{(n.codeWaiters??(n.codeWaiters=[])).push(s),!(n.pendingSource===t||n.pendingSource===void 0&&n.codeTrial&&n.source===t)&&(n.pendingSource=t,this.swapSource(e,t,i));})}async swapSource(e,t,n){let i=this.registry.get(e)?.engine??this.engineFor(this.registry.get(e)?.options?.language),o;try{o=await i.prepare(t,e);}catch(l){let d=this.registry.get(e);d?.pendingSource===t&&(d.pendingSource=void 0,this.rejectCode(e,d,n,l));return}let s=this.registry.get(e);if(!s||s.pendingSource!==t)return;s.pendingSource=void 0;let a=s.codeTrial?.previous??{source:s.source,engine:s.engine,prepared:s.prepared,inputValues:s.inputValues,propValues:s.propValues,inputs:[...n.inputs],props:[...n.props]};if(s.inputValues=Av(o.inputs,s.inputValues,s.prepared?.inputs),s.propValues=Av(o.props??[],s.propValues,s.prepared?.props),s.source=t,s.engine=i,s.prepared=o,n.setSource(t),n.setSchema(o.inputs),n.setPropsSchema(o.props??[]),s.session?.stop(),s.session=void 0,s.pendingStructural=true,s.pendingCause="code",s.hidden){s.codeTrial=void 0,s.renderHandle&&this.renderer.setIndicatorInputs(s.renderHandle,s.inputValues,s.propValues),this.settleCode(s,{ok:true,error:null});return}s.codeTrial={previous:a},s.renderHandle?(this.renderer.setIndicatorInputs(s.renderHandle,s.inputValues,s.propValues),this.setLoading(s,true)):this.mountLoadingPlaceholder(e,s),this.executeIndicator(e,n),this.bars.length===0&&s.codeTrial&&(s.codeTrial=void 0,this.settleCode(s,{ok:true,error:null}));}settleCode(e,t){let n=e.codeWaiters;if(e.codeWaiters=void 0,n)for(let i of n)i(t);}rejectCode(e,t,n,i){let o=t.codeTrial;if(t.codeTrial=void 0,this.fail(e,n,i),o){let a=o.previous;t.session?.stop(),t.session=void 0,t.source=a.source,t.engine=a.engine,t.prepared=a.prepared,t.inputValues=a.inputValues,t.propValues=a.propValues,n.setSource(a.source),n.setSchema(a.inputs),n.setPropsSchema(a.props),t.pendingStructural=true,t.pendingCause=void 0,t.renderHandle&&this.renderer.setIndicatorInputs(t.renderHandle,t.inputValues,t.propValues),t.hidden||this.executeIndicator(e,n);}let s=i instanceof Error?i:new Error(String(i));this.settleCode(t,{ok:false,error:s});}listIndicators(){return [...this.handles.values()]}getIndicatorContext(e,t){return this.registry.get(e)?.session?.getContext?.(t)??Promise.resolve(null)}removeIndicator(e){let t=this.registry.remove(e);t?.native?.type==="volume"&&(this.volumeOptedOut=true),t&&this.settleCode(t,{ok:false,error:new Error(`[vela] updateCode("${e}") \u2014 the indicator was removed.`)}),t?.session?.stop(),t?.native&&this.stopNativeInstance(t.native),this.handles.delete(e),t?.renderHandle&&this.renderer.removeIndicator(t.renderHandle);let n=t?.model?.paneId;n&&n!=="price"&&!this.paneStillUsed(n)&&(this.renderer.removePane(n),this.forgetPane(n),this.events.emit("pane:changed",void 0)),this.events.emit("indicator:removed",{id:e});}setVisible(e,t){let n=this.registry.get(e);if(!(!n||n.hidden===!t)){if(n.hidden=!t,this.handles.get(e)?.setVisibleState(t),!t)n.session?.stop(),n.session=void 0,n.codeTrial&&(n.codeTrial=void 0,this.settleCode(n,{ok:true,error:null})),n.native?.started&&n.native.instance.suspend(),n.renderHandle?this.renderer.setIndicatorVisible?.(n.renderHandle,false):n.native&&this.mountHiddenNativeRow(e,n);else if(n.renderHandle&&this.renderer.setIndicatorVisible?.(n.renderHandle,true),n.pendingStructural=true,n.native)if(n.native.stale||!n.native.started){n.native.stale=false;let i=this.handles.get(e);i&&this.startNativeIndicator(e,i);}else n.native.instance.resume();else {this.setLoading(n,true);let i=this.handles.get(e);i&&this.executeIndicator(e,i);}this.events.emit("indicator:visibility",{id:e,visible:t});}}ready(){return this.readyPromise}inspect(){let e=[...this.registry.all()].filter(t=>!t.loading).sort((t,n)=>(n.native?1:0)-(t.native?1:0));return fb(e.map(t=>t.model).filter(t=>t!=null))}resize(){this.renderer.resize();}setTheme(e){let t=this.config.theme;Object.keys(e).every(n=>e[n]===t[n])||(this.config.theme=e,this.renderer.setTheme(e),this.events.emit("theme:changed",e));}getVisibleRange(){return this.renderer.getVisibleRange()}setVisibleRange(e){this.renderer.setVisibleRange(e);}panBy(e){if(this.renderer.panBy){this.renderer.panBy(e);return}let t=this.renderer.getVisibleRange();if(!t)return;let n=(t.to-t.from)*e;this.renderer.setVisibleRange({from:t.from+n,to:t.to+n});}setVisibleRangePreset(e){let t=bb(e,this.bars);t&&this.renderer.setVisibleRange(t);}destroy(){this.bumpGeneration(),this.resolveHistoryComplete(),this.clearReplayTimer(),this.replayQueue=null,this.replayForming=null,this.replayCarrying=null,this.dropTickFetches(),this.replayDepth=null,this.replayLoading=null,this.stopLive(),this.viewportTimer!=null&&clearTimeout(this.viewportTimer),this.viewportUnsub?.(),this.paneActionUnsub?.(),this.priceStyleWillChangeUnsub?.(),this.priceStyleWillChangeUnsub=null;for(let e of this.registry.all())this.settleCode(e,{ok:false,error:new Error("[vela] updateCode \u2014 the chart was destroyed.")}),e.session?.stop(),e.native&&this.stopNativeInstance(e.native);for(let e of this.typeEngines.values())e.stop();this.typeEngines.clear(),this.activeEngineStyle=null,this.unresolvedUnsub?.(),this.unresolvedUnsub=null,this.feed.destroy?.(),this.drawings.destroy(),this.marks.destroy(),this.renderer.destroy(),this.events.clear();}claimIndicatorId(e){if(e===void 0)return this.registry.nextId("ind",t=>this.handles.has(t));if(typeof e!="string"||e.length===0)throw new TypeError("[vela] addIndicator: `id` must be a non-empty string");if(this.handles.has(e)||this.registry.get(e))throw new Error(`[vela] addIndicator: indicator id "${e}" is already live on this chart`);return e}async startIndicator(e,t,n,i){try{if(await this.readyPromise,!this.registry.get(e))return;await nP();let o=this.registry.get(e);if(!o)return;let s=this.engineFor(n.language);o.engine=s;let a=await s.prepare(t,e);if(o.source!==t)return;o.prepared=a;let l={};for(let u of a.inputs)l[u.key]=u.defval;o.inputValues={...l,...o.inputValues},i.setSchema(a.inputs);let d={};for(let u of a.props??[])d[u.key]=u.defval;o.propValues={...d,...o.propValues},i.setPropsSchema(a.props??[]),this.mountLoadingPlaceholder(e,o),this.executeIndicator(e,i);}catch(o){this.fail(e,i,o);}}executeIndicator(e,t){let n=this.registry.get(e);if(!n||!n.engine||!n.prepared||n.hidden)return;let i=this.config.live&&!n.prepared.reactsToViewport&&n.engine.capabilities.streaming?"live":"static",o=n.prepared,s=n.engine.execute({prepared:n.prepared,market:this.market(),bars:this.bars,getBars:()=>this.bars,fetchSeries:(a,l,d)=>this.fetchSeries(a,l,d),inputs:n.inputValues,props:n.propValues,visibleRange:this.currentVisibleRange(),mode:i,historyState:this.historyState},{onModel:a=>{let l=!n.announced,d=n.pendingCause??"history";this.applyModel(e,a)&&(n.pendingCause=void 0,n.codeTrial&&(n.codeTrial=void 0,this.settleCode(n,{ok:true,error:null})),this.emitContextChanged(e),this.emitScriptRun(e,d,l));},onAlert:a=>{if(this.replayQueue||this.replayCarrying)return;let l=n.options?.title??n.prepared?.meta.title??n.title;this.events.emit("alert",{...a,indicator:l}),t.emit("alert",{id:a.id,message:a.message,title:a.title,time:a.time});},onWarning:a=>this.events.emit("warning",a),onError:a=>{n.codeTrial?this.rejectCode(e,n,t,a):this.fail(e,t,a);}});if(n.prepared!==o){s.stop();return}n.session=s,this.emitContextChanged(e);}async startNativeIndicator(e,t){try{await this.readyPromise;let n=this.registry.get(e);if(!n?.native||n.hidden)return;let i=n.native;if(i.started)return;if(i.descriptor.waitsForHistory&&this.historyState==="backfill"){i.heldForHistory=!0,this.mountNativePlaceholder(e,n);return}i.heldForHistory=!1;let o=this.nativeChannel(n),s=!0;i.revokeContext=()=>{s=!1;};let a={id:e,symbol:this.config.market.symbol??"TEST",timeframe:this.config.market.timeframe??"60",live:this.config.live&&this.replayQueue===null,session:this.config.market.session,bars:()=>this.bars,data:this.dataControl,emit:l=>{s&&this.applyModel(e,this.buildNativeModel(n,l,this.bars[0]?.time));},pushData:l=>{s&&this.renderer.setNativeData?.(o,l);},setStatus:l=>{s&&n.renderHandle&&!n.hidden&&this.renderer.setIndicatorStatus?.(n.renderHandle,l);}};i.instance.start(a,n.inputValues),i.started=!0;}catch(n){this.fail(e,t,n);}}nativeChannel(e){let{type:t,descriptor:n}=e.native;return n.multiInstance?cb(t,e.id):t}buildNativeModel(e,t,n){let i=e.native.descriptor,o=e.native.type,s=this.nativeChannel(e),a=qn(i.title),l=qn(i.shortTitle);return {id:e.id,title:e.title,...i.shortTitle?{shorttitle:X(this.i18n,i.shortTitle)}:{},...a?{displayTitle:a}:{},...l?{displayShorttitle:l}:{},overlay:i.overlay,paneHint:i.paneHint,native:{type:o,...s!==o?{channel:s}:{}},...n!=null?{anchorTime:n}:{},...i.legend===false?{legend:false}:{},...t.paneAxis!=null?{paneAxis:t.paneAxis}:{},series:t.series??[],fills:t.fills??[],backgrounds:t.backgrounds??[],priceLines:t.priceLines??[],...t.lines?{lines:t.lines}:{},...t.boxes?{boxes:t.boxes}:{},...t.labels?{labels:t.labels}:{},...t.polylines?{polylines:t.polylines}:{},...t.linefills?{linefills:t.linefills}:{},...t.tables?{tables:t.tables}:{},inputs:i.inputsSchema(),inputValues:e.inputValues}}mountLoadingPlaceholder(e,t){if(t.renderHandle||!t.prepared)return;let n=t.prepared.meta,i={id:e,title:t.options?.title??n.title,overlay:n.overlay,paneHint:n.overlay?"price":"new",series:[],fills:[],backgrounds:[],priceLines:[],inputs:t.prepared.inputs,inputValues:t.inputValues,...t.prepared.props?{props:t.prepared.props,propValues:t.propValues}:{}},o=this.routePane(e,i,t.options??{});this.placeModel(i,e,o),t.model=i;let s=this.ensurePaneFor(o);if(t.renderHandle=this.renderer.mountIndicator(i),s&&this.events.emit("pane:changed",void 0),t.pendingStructural=true,t.hidden){this.renderer.setIndicatorVisible?.(t.renderHandle,false),this.announce(t,this.handles.get(e));return}this.setLoading(t,true);}mountHiddenNativeRow(e,t){if(t.renderHandle||!t.native)return;let n=this.buildNativeModel(t,{}),i=this.routePane(e,n,t.options??{});this.placeModel(n,e,i),t.model=n;let o=this.ensurePaneFor(i);t.renderHandle=this.renderer.mountIndicator(n),o&&this.events.emit("pane:changed",void 0),t.pendingStructural=true,this.renderer.setIndicatorVisible?.(t.renderHandle,false),this.announce(t,this.handles.get(e));}mountNativePlaceholder(e,t){if(t.pendingStructural=true,!t.renderHandle){let n=this.buildNativeModel(t,{}),i=this.routePane(e,n,t.options??{});this.placeModel(n,e,i),t.model=n;let o=this.ensurePaneFor(i);t.renderHandle=this.renderer.mountIndicator(n),o&&this.events.emit("pane:changed",void 0);}this.setLoading(t,true);}setLoading(e,t){e.loading=t,e.renderHandle&&!e.hidden&&this.renderer.setIndicatorStatus?.(e.renderHandle,t?"loading":"idle");}ensurePaneFor(e){let t=!this.paneOrder.includes(e);return t&&this.paneOrder.push(e),this.renderer.ensurePane({id:e,kind:e==="price"?"price":"study",order:this.paneOrder.indexOf(e)}),t}paneStillUsed(e){for(let t of this.registry.all())if(t.model?.paneId===e)return true;return false}forgetPane(e){let t=this.paneOrder.indexOf(e);t>0&&this.paneOrder.splice(t,1),this.collapsedPanes.delete(e),this.maximizedPaneId===e&&(this.maximizedPaneId=null);}setTranslator(e){this.i18n=e,this.drawings.relocalize();}relocalize(){this.drawings.relocalize();for(let e of this.registry.all()){let t=e.native?.descriptor;if(!t)continue;e.title=X(this.i18n,t.title);let n=this.handles.get(e.id);n&&(n.title=e.title),e.model&&(e.model.title=e.title,t.shortTitle!==void 0&&(e.model.shorttitle=X(this.i18n,t.shortTitle)));}}paneManagementSupported(){return this.renderer.capabilities.paneManagement===true&&typeof this.renderer.setIndicatorPane=="function"}listPanes(){let e=new Map;for(let n of this.registry.all()){let i=n.model;if(!i||i.legend===false)continue;let o=i.paneId??"price";e.has(o)||e.set(o,[]),e.get(o).push({id:n.id,title:i.title||n.title,...i.shorttitle?{shorttitle:i.shorttitle}:{},ownScale:i.ownScale===true});}let t=[];for(let n of this.paneOrder){if(n!=="price"&&!e.has(n))continue;let i=this.renderer.paneHeightWeight?.(n)??null;t.push({id:n,kind:n==="price"?"price":"study",order:t.length,collapsed:this.collapsedPanes.has(n),maximized:this.maximizedPaneId===n,...i!==null?{heightWeight:i}:{},indicators:e.get(n)??[]});}return t}movePane(e,t){if(e==="price")return;let n=this.existingPaneIds(),i=n.indexOf(e);if(i<0)return;let o=t==="up"?i-1:i+1;o<=0||o>=n.length||([n[i],n[o]]=[n[o],n[i]],this.reorderPanes(n),this.events.emit("pane:moved",{paneId:e,dir:t}));}removePaneAndIndicators(e){if(e!=="price")for(let t of [...this.registry.all()])t.model?.paneId===e&&this.removeIndicator(t.id);}collapsePane(e,t){t?this.collapsedPanes.add(e):this.collapsedPanes.delete(e),this.renderer.setPaneCollapsed?.(e,t),this.events.emit("pane:changed",void 0);}maximizePane(e){this.maximizedPaneId=e,this.renderer.setPaneMaximized?.(e),this.events.emit("pane:changed",void 0);}setPaneHeightWeight(e,t){if(!this.renderer.setPaneHeightWeight){console.warn("[vela] the active renderer does not support pane sizing \u2014 chart.panes.setHeightWeight ignored.");return}if(typeof t!="number"||!Number.isFinite(t)||t<=0){console.warn(`[vela] chart.panes.setHeightWeight: weight must be a positive number (got ${String(t)}).`);return}if(!this.existingPaneIds().includes(e)){console.warn(`[vela] chart.panes.setHeightWeight: no pane "${e}".`);return}this.renderer.setPaneHeightWeight(e,t),this.events.emit("pane:changed",void 0);}moveIndicator(e,t){if(!this.paneManagementSupported()||!this.renderer.setIndicatorPane){console.warn("[vela] the active renderer does not support moving indicators between panes.");return}let n=this.registry.get(e);if(!n?.renderHandle||!n.model)return;let i=n.model,o=i.paneId??"price",s=this.resolveMoveTarget(e,i,t);if(!s)return;let{paneId:a,ownScale:l,insert:d}=s;a===o&&i.ownScale===true===l||(d?this.insertPaneOrder(a,d):this.paneOrder.includes(a)||this.paneOrder.push(a),i.ownScale=l,n.paneLocked=true,this.placeModel(i,e,a),this.ensurePaneFor(a),this.renderer.setIndicatorPane(n.renderHandle,a,{ownScale:l}),o!=="price"&&o!==a&&!this.paneStillUsed(o)&&(this.renderer.removePane(o),this.forgetPane(o)),this.reorderPanes(this.existingPaneIds()),this.events.emit("indicator:moved",{id:e,paneId:a}),this.events.emit("pane:changed",void 0));}resolveMoveTarget(e,t,n){if(n==="price"||typeof n=="object"&&"pane"in n&&n.pane==="price")return {paneId:"price",ownScale:!t.overlay};if("pane"in n)return this.existingPaneIds().includes(n.pane)?{paneId:n.pane,ownScale:true}:null;let i=n.newPane===true?{}:n.newPane;return {paneId:this.freshPaneId(e,t.paneId??"price"),ownScale:false,insert:i}}freshPaneId(e,t){let n=new Set(this.existingPaneIds()),i=`pane-${e}`;for(let o=2;i===t||n.has(i);o+=1)i=`pane-${e}-${o}`;return i}insertPaneOrder(e,t){let n=this.paneOrder.indexOf(e);n>0&&this.paneOrder.splice(n,1);let i=this.paneOrder.length;t.before&&this.paneOrder.includes(t.before)?i=this.paneOrder.indexOf(t.before):t.after&&this.paneOrder.includes(t.after)&&(i=this.paneOrder.indexOf(t.after)+1),i<1&&(i=1),this.paneOrder.splice(i,0,e);}existingPaneIds(){return this.paneOrder.filter(e=>e==="price"||this.paneStillUsed(e))}reorderPanes(e){this.paneOrder.length=0,this.paneOrder.push(...e),this.renderer.orderPanes?.(e),this.events.emit("pane:changed",void 0);}handlePaneAction(e){switch(e.type){case "remove":this.removePaneAndIndicators(e.paneId);break;case "move":{let t=this.existingPaneIds(),n=t.indexOf(e.paneId),i=e.dir==="up"?n-1:n+1;n>0&&i>0&&i<t.length&&([t[n],t[i]]=[t[i],t[n]],this.paneOrder.length=0,this.paneOrder.push(...t),this.events.emit("pane:changed",void 0),this.events.emit("pane:moved",{paneId:e.paneId,dir:e.dir}));break}case "collapse":e.collapsed?this.collapsedPanes.add(e.paneId):this.collapsedPanes.delete(e.paneId),this.events.emit("pane:changed",void 0);break;case "maximize":this.maximizedPaneId=e.maximized?e.paneId:null,this.events.emit("pane:changed",void 0);break;case "resize":this.events.emit("pane:changed",void 0);break}}announce(e,t){e.announced||(e.announced=true,this.events.emit("indicator:added",{id:e.id}),this.emitContextChanged(e.id),t?.emit("ready",void 0));}applyModel(e,t){let n=this.registry.get(e);if(!n||n.hidden)return true;if(this.switchingMarket||n.loading&&this.bars.length===0&&!r.modelHasOutput(t))return false;let i=this.handles.get(e);if(!n.renderHandle){let l=this.routePane(e,t,n.options??{});this.placeModel(t,e,l),n.model=t;let d=this.ensurePaneFor(l);return n.renderHandle=this.renderer.mountIndicator(t),n.pendingStructural=false,d&&this.events.emit("pane:changed",void 0),this.announce(n,i),true}let o=n.model?.paneId??"price",s=n.model?.ownScale===true,a=false;if(n.loading&&!n.paneLocked){let l=this.routePane(e,t,n.options??{});l!==o&&(o!=="price"&&!this.registry.all().some(d=>d.id!==e&&d.model?.paneId===o)&&(this.renderer.removePane(o),this.forgetPane(o)),this.ensurePaneFor(l),n.pendingStructural=true,o=l,a=true);}return this.placeModel(t,e,o),n.paneLocked&&(t.ownScale=s),n.model=t,n.pendingStructural?(n.renderHandle=this.renderer.mountIndicator(t),this.renderer.setIndicatorInputs(n.renderHandle,n.inputValues,n.propValues),n.pendingStructural=false):this.renderer.updateIndicator(n.renderHandle,oP(t)),a&&this.events.emit("pane:changed",void 0),n.loading&&this.setLoading(n,false),this.announce(n,i),true}static modelHasOutput(e){return e.series.length>0||e.fills.length>0||e.backgrounds.length>0||e.priceLines.length>0||(e.lines?.length??0)>0||(e.boxes?.length??0)>0||(e.labels?.length??0)>0||(e.polylines?.length??0)>0||(e.linefills?.length??0)>0||(e.tables?.length??0)>0||(e.barColors?.length??0)>0||(e.trades?.length??0)>0}routePane(e,t,n){return n.pane==="new"?`pane-${e}`:n.pane==="price"||(n.overlay??t.overlay)?"price":`pane-${e}`}static plotsAtLastBar(e,t){let n={};for(let i of e.series){if(!at(i))continue;let o=i.points.length-1;if(t!==void 0)for(;o>=0&&i.points[o].time>t;)o-=1;n[i.title]=i.points[o]?.value??null;}return n}placeModel(e,t,n){e.id=t,e.paneId=n;let i=o=>o.overlay===true?"price":n;for(let o of e.series)o.paneId=i(o);for(let o of e.fills)o.paneId=i(o);for(let o of e.backgrounds)o.paneId=i(o);for(let o of e.priceLines)o.paneId=n;if(e.lines)for(let o of e.lines)o.paneId=i(o);if(e.boxes)for(let o of e.boxes)o.paneId=i(o);if(e.labels)for(let o of e.labels)o.paneId=i(o);if(e.polylines)for(let o of e.polylines)o.paneId=i(o);if(e.linefills)for(let o of e.linefills)o.paneId=i(o);if(e.tables)for(let o of e.tables)o.paneId=i(o);}emitContextChanged(e){if(!this.registry.get(e)?.session?.getContext)return;let t=Date.now();t-(this.contextEmitAt.get(e)??0)<1e3||(this.contextEmitAt.set(e,t),this.events.emit("context:changed",{id:e}));}emitScriptRun(e,t,n){let i=this.registry.get(e);if(!i||i.native||!this.events.hasListeners("script:run"))return;let o=Date.now();t==="tick"&&o-(this.runEmitAt.get(e)??0)<jE||(this.runEmitAt.set(e,o),Promise.resolve().then(()=>this.buildScriptRun(i,t,n)).then(s=>{s&&this.registry.get(e)&&this.events.emit("script:run",s);}));}async buildScriptRun(e,t,n){let i=e.model;if(!i)return null;let o=await this.pullContext(e,["variables","strategy","warnings"]),s=this.bars[this.bars.length-1];return {id:e.id,title:i.title,kind:o?.strategy||(i.trades?.length??0)>0?"strategy":"indicator",cause:t,first:n,bar:Math.max(0,this.bars.length-1),time:s?.time??0,forming:this.config.live&&this.bars.length>0,complete:this.historyState!=="backfill",plots:r.plotsAtLastBar(i,s?.time),vars:o?.variables??{},...o?.strategy?{strategy:o.strategy}:{},warnings:o?.warnings??[],trades:async()=>(await this.pullContext(e,["trades"]))?.trades??[],series:async a=>((await this.pullContext(e,["plots"]))?.plots?.[a]??[]).map(d=>({time:d.time,value:typeof d.value=="number"?d.value:null}))}}async pullContext(e,t){try{return await e.session?.getContext?.(t)??null}catch{return null}}fail(e,t,n){let i=this.registry.get(e);i?.loading&&this.setLoading(i,false);let o=n instanceof Error?n:new Error(String(n));console.error(`[vela] indicator "${e}" failed:`,o.message),this.events.emit("indicator:error",{id:e,error:o}),t?.emit("error",{error:o});}};function Iv(){return typeof performance<"u"?performance.now():Date.now()}function tP(r){if(!Array.isArray(r))return [];let e=t=>t===void 0||Number.isFinite(t);return r.filter(t=>t!=null&&Number.isFinite(t.price)&&e(t.volume)&&e(t.high)&&e(t.low)&&e(t.open))}function nP(){return typeof requestAnimationFrame=="function"?new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(()=>r()))):new Promise(r=>setTimeout(r,0))}function Av(r,e,t=[]){let n={},i=new Set;for(let s of r)n[s.key]=s.defval,i.add(s.key),i.add(s.title);let o=new Map;for(let s of t)o.set(s.key,s.defval),o.has(s.title)||o.set(s.title,s.defval);for(let[s,a]of Object.entries(e))i.has(s)&&(o.has(s)&&rP(o.get(s),a)||(n[s]=a));return n}function rP(r,e){return r===e?true:typeof r=="object"&&r!==null&&typeof e=="object"&&e!==null&&JSON.stringify(r)===JSON.stringify(e)}function iP(r){let{anchorTime:e,...t}=r;return {...t,series:r.series.map(n=>n.kind==="candle"||n.kind==="bar"?{...n,bars:[]}:n.kind==="markers"?{...n,markers:[]}:{...n,points:[]}),fills:[],backgrounds:[],priceLines:[],lines:[],boxes:[],labels:[],polylines:[],linefills:[],tables:[],barColors:[],trades:[]}}function oP(r){let e=[],t=Number.POSITIVE_INFINITY,n=0;for(let i of r.series)if(i.kind==="candle"||i.kind==="bar"){e.push({seriesId:i.id,kind:"bars",bars:i.bars,barColors:i.barColors??[]});for(let o of i.bars)o&&(o.time<t&&(t=o.time),o.time>n&&(n=o.time));}else if(at(i)){e.push({seriesId:i.id,kind:"points",points:i.points});for(let o of i.points)o&&(o.time<t&&(t=o.time),o.time>n&&(n=o.time));}return {kind:"value",indicatorId:r.id,dirty:{from:Number.isFinite(t)?t:0,to:n},anchorTime:r.anchorTime??null,series:e,lines:r.lines??[],boxes:r.boxes??[],labels:r.labels??[],polylines:r.polylines??[],linefills:r.linefills??[],tables:r.tables??[],trades:r.trades??[]}}var Rs=class{constructor(e){this.renderer=e;}get name(){return this.renderer.name}get capabilities(){return this.renderer.capabilities}supports(e){return this.renderer.features.includes(e)}get(e){return this.renderer.readFeature(e)}set(e,t){let n=typeof e=="string"?[[e,t]]:Object.entries(e);for(let[i,o]of n)this.renderer.features.includes(i)?this.renderer.applyFeature(i,o):console.warn(`[vela] renderer "${this.renderer.name}" has no feature "${i}" \u2014 set ignored.`);return this}setLegendActions(e){this.renderer.setLegendActions?.(e);}setLegendCallouts(e){this.renderer.setLegendCallouts?.(e);}setLegendOverviewAction(e){return this.renderer.setLegendOverviewAction?.(e),this}get supportsIndicatorSettings(){return typeof this.renderer.openIndicatorSettings=="function"}openIndicatorSettings(e){return this.renderer.openIndicatorSettings?.(e),this}screenshot(){return typeof this.renderer.screenshot=="function"?this.renderer.screenshot():(console.warn(`[vela] renderer "${this.renderer.name}" does not support screenshot().`),null)}screenshotCanvas(){return typeof this.renderer.screenshotCanvas=="function"?this.renderer.screenshotCanvas():null}getConfig(){return typeof this.renderer.getConfig=="function"?this.renderer.getConfig():(console.warn(`[vela] renderer "${this.renderer.name}" does not support getConfig().`),null)}applyConfig(e){return typeof this.renderer.applyConfig=="function"?this.renderer.applyConfig(e):console.warn(`[vela] renderer "${this.renderer.name}" does not support applyConfig().`),this}onConfigChanged(e){return this.renderer.onConfigChanged?.(e)??(()=>{})}onCrosshairMove(e){return this.renderer.onCrosshairMove(e)}onClick(e){return this.renderer.onClick(e)}onAxisLongPress(e){return this.renderer.onAxisLongPress?.(e)??(()=>{})}dataWindowReadout(){return this.renderer.getDataWindowReadout?.()??null}setSymbolPicker(e){return typeof this.renderer.setSymbolPicker=="function"?this.renderer.setSymbolPicker(e):console.warn(`[vela] renderer "${this.renderer.name}" does not support setSymbolPicker().`),this}focus(){return this.renderer.focus?.(),this}get supportsExternalCrosshair(){return typeof this.renderer.setExternalCrosshair=="function"}setExternalCrosshair(e,t=null){return this.renderer.setExternalCrosshair?.(e,t),this}closeDialogs(){return this.renderer.closeDialogs?.(),this}openSettings(e){return this.renderer.openSettingsDialog?.(e),this}setSettingsSections(e){return this.renderer.setSettingsSections?.(e),this}setSettingsVisibility(e){return this.renderer.setSettingsVisibility?.(e),this}listSettingsIds(){return this.renderer.listSettingsIds?.()??[]}setLayoutMode(e){return this.renderer.setLayoutMode?.(e),this}setWallClock(e){return this.renderer.setWallClock?.(e),this}};var uo=new Map;function sP(r){let e=Object.entries(r);for(let[t,n]of e)uo.set(t,n);return ()=>{for(let[t,n]of e)uo.get(t)===n&&uo.delete(t);}}function aP(...r){if(r.length===0)uo.clear();else for(let e of r)uo.delete(e);}function Xh(){return Object.fromEntries(uo)}var Hc=class{constructor(e){this.controller=e;}get supported(){return this.controller.paneManagementSupported()}list(){return this.controller.listPanes()}move(e,t){return this.guard()&&this.controller.movePane(e,t),this}remove(e){return this.guard()&&this.controller.removePaneAndIndicators(e),this}collapse(e,t=true){return this.guard()&&this.controller.collapsePane(e,t),this}maximize(e){return this.guard()&&this.controller.maximizePane(e),this}setHeightWeight(e,t){return this.guard()&&this.controller.setPaneHeightWeight(e,t),this}moveIndicator(e,t){return this.guard()&&this.controller.moveIndicator(e,t),this}guard(){return this.controller.paneManagementSupported()?true:(console.warn("[vela] the active renderer does not support pane management \u2014 chart.panes mutation ignored."),false)}};function Rv(r,e,t,n){return `${r}|${e}|${t}${n&&n!=="regular"?`|${n}`:""}`}function lP(r){return r.split("|")[1]??""}var _c=class{constructor(){this.series=new Map;this.coveredFrom=new Map;this.retained=new Set;this.retainedByOwner=new Map;}get(e){return this.series.get(e)}markCovered(e,t){this.coveredFrom.set(e,Math.min(this.coveredFrom.get(e)??1/0,t));}coveredFromOf(e){return this.coveredFrom.get(e)}merge(e,t){if(t.length===0)return this.series.get(e)??[];let n=new Map;for(let o of this.series.get(e)??[])n.set(o.time,o);for(let o of t)n.set(o.time,o);let i=[...n.values()].sort((o,s)=>o.time-s.time);return this.series.set(e,i),i}retainSymbol(e){this.currentSymbol!==e&&(this.currentSymbol=e,this.purgeOutside(e));}retain(e,t="default"){e.size===0?this.retainedByOwner.delete(t):this.retainedByOwner.set(t,new Set(e));let n=new Set;for(let i of this.retainedByOwner.values())for(let o of i)n.add(o);this.retained=n,this.purgeOutside(this.currentSymbol);}purgeOutside(e){for(let t of [...this.series.keys()]){let n=lP(t);n!==e&&!this.retained.has(n)&&(this.series.delete(t),this.coveredFrom.delete(t));}}clear(){this.series.clear(),this.coveredFrom.clear();}},Ds=new _c;function jh(r,e,t){let{provider:n,ticker:i}=Mn(r);return Rv(n??"",i,e,t)}var Ns=1e4,cP=Ns+1,Fs=class{constructor(e,t=Ds){this.inner=e;this.store=t;}async load(e){if(e.data&&e.data.length>0)return this.inner.load(e);let t=e.symbol??"TEST",n=jh(t,e.timeframe??"60",e.session);this.store.retainSymbol(t);let i=this.store.get(n),o=e.bars??500,s=i?.[i.length-1];if(i&&s&&i.length>=o-1&&this.inner.loadRange){let{bars:l}=await this.fetchRange(e,{from:s.time}),d=this.store.merge(n,Os(l));return Dv(d,l[l.length-1]).slice(-o)}let a=await this.inner.load(e);return this.store.merge(n,Os(a)),a}async loadProgressive(e,t,n){if(e.data&&e.data.length>0)return this.inner.load(e);if(!this.inner.loadProgressive)return null;let i=e.symbol??"TEST",o=jh(i,e.timeframe??"60",e.session),s=this.store.get(o),a=e.bars??500,l=s?.[s.length-1];if(s&&l&&s.length>=a-1&&this.inner.loadRange)return this.load(e);this.store.retainSymbol(i);let d=await this.inner.loadProgressive(e,t,n);return d==null?null:(this.store.merge(o,Os(d)),d)}async loadRange(e,t){if(!this.inner.loadRange)return this.inner.load(e);let n=jh(e.symbol??"TEST",e.timeframe??"60",e.session),i=this.store.get(n),o=i?.[i.length-1];if(t.to!=null&&o&&t.to<o.time){let u=i.filter(b=>b.time<=t.to),h=this.store.coveredFromOf(n)??1/0;if(t.limit!=null?u.length>=t.limit&&(t.from==null||h<=t.from):t.from!=null&&h<=t.from){let b=t.from!=null?u.filter(f=>f.time>=t.from):u;return t.limit!=null&&b.length>t.limit&&(b=b.slice(-t.limit)),b}let m=await this.fetchRange(e,t),g=m.bars.filter(b=>b.time<=t.to);return g.length>0&&(this.store.merge(n,g),this.store.markCovered(n,m.coveredDownTo??g[0].time)),g}if(o&&t.from!=null){let u=this.store.coveredFromOf(n);if(u!=null&&u>t.from){let{bars:h,coveredDownTo:p}=await this.fetchRange(e,{from:t.from,to:u});this.store.merge(n,h.filter(m=>m.time<=u)),this.store.markCovered(n,p??t.from),i=this.store.get(n),o=i?.[i.length-1];}}let s=this.store.coveredFromOf(n);if(!!i&&i.length>0&&!!o&&(t.from!=null?s!=null&&s<=t.from:t.limit==null||i.length>=t.limit)&&o){let{bars:u}=await this.fetchRange(e,{from:o.time,to:t.to,limit:t.limit}),h=this.store.merge(n,Os(u)),p=Dv(h,u[u.length-1]),m=t.from!=null?p.filter(g=>g.time>=t.from):p;return t.to!=null&&(m=m.filter(g=>g.time<=t.to)),m}let{bars:l,coveredDownTo:d}=await this.fetchRange(e,t);return this.store.merge(n,Os(l)),this.store.markCovered(n,d??t.from??l[0]?.time??0),l}async fetchRange(e,t){let n=an(e.timeframe??"60"),i=dP(t,n);if(i<=cP){let d=await this.inner.loadRange(e,{...t,limit:t.limit??i});return {bars:d,coveredDownTo:t.from??d[0]?.time}}let o=new Map,s=t.to??Date.now();for(;!(t.from!=null&&s<t.from);){let d=t.limit!=null?t.limit-o.size:Ns;if(d<=0)break;let u=await this.inner.loadRange(e,{to:s,limit:Math.min(Ns,d)}),h=1/0;for(let p of u)p.time<h&&(h=p.time),p.time<=s&&(t.from==null||p.time>=t.from)&&o.set(p.time,p);if(u.length===0){if(t.from==null)break;s-=Ns*n;continue}if(h-1>=s)break;s=h-1;}let a=[...o.values()].sort((d,u)=>d.time-u.time),l=t.from!=null&&s<t.from;return {bars:a,coveredDownTo:l?t.from:a[0]?.time}}subscribe(e,t){return this.inner.subscribe(e,t)}symbolInfo(e){return this.inner.symbolInfo?.(e)}};function dP(r,e){if(r.limit!=null)return r.limit;if(r.from==null)return Ns;let t=Math.max(0,(r.to??Date.now())-r.from);return Math.ceil(t/e*1.1)+2}function Os(r){return r.length>0?r.slice(0,-1):r}function Dv(r,e){if(!e)return r;let t=r[r.length-1];return !t||e.time>t.time?[...r,e]:r}var fi=class{constructor(e=Ds){this.registry=new Bc;this.primaryProvider=null;this.symInfoCache=new Map;this.symInfoInflight=new Map;this.cache=new Fs(new qh(this.registry),e);}registerProvider(e,t){return this.registry.register(e,t)}unregisterProvider(e){this.registry.unregister(e);}providers(){return this.registry.names().map(e=>this.registry.infoOf(e))}resolveSymbol(e){return this.registry.resolve(e,{default:this.primaryProvider})}displayPrefix(e){let t=this.resolveSymbol(e);return t?this.registry.displayPrefixOf(t):null}canonicalSymbol(e){let t=this.resolveSymbol(e);return t?this.registry.canonicalSymbol(t):null}providerInstance(e){return this.registry.get(e)}symbolIconOf(e){return this.registry.symbolIconOf(e)}symbolIcon(e){return this.registry.symbolIcon(this.resolveSymbol(e))}symbols(e){return this.registry.symbolsOf(e)}onUnresolved(e){return this.registry.onUnresolved(e)}destroy(){this.registry.cancelWaits();}ready(){return this.registry.indexReady()}async symbolInfoFor(e){let t=this.registry.resolve(e,{default:this.primaryProvider});if(t)return this.fetchSymbolInfo(t)}fetchSymbolInfo(e){let t=Ov(e),n=this.symInfoCache.get(t);if(n&&Date.now()-n.at<uP)return Promise.resolve(n.info);let i=this.symInfoInflight.get(t);if(i)return i;let o=this.registry.get(e.provider)?.getSymbolInfo;if(!o)return Promise.resolve(void 0);let s=Promise.resolve(o.call(this.registry.get(e.provider),e.ticker)).then(a=>(a&&this.symInfoCache.set(t,{info:a,at:Date.now()}),a)).finally(()=>{this.symInfoInflight.delete(t);});return this.symInfoInflight.set(t,s),s}capabilitiesFor(e){let t=this.registry.resolve(e,{default:this.primaryProvider});if(!t)return null;let n=this.registry.get(t.provider);return n?n.capabilitiesFor?.(t.ticker)??this.registry.infoOf(t.provider).capabilities:null}async load(e){if(e.data&&e.data.length>0)return e.data;let t=await this.registry.whenResolvable(Bs(e),{default:this.primaryProvider});return this.primaryProvider=t.provider,this.prefetchSymbolInfo(t),this.cache.load(zc(e,t))}async loadProgressive(e,t,n){if(e.data&&e.data.length>0)return e.data;let i=await this.registry.whenResolvable(Bs(e),{default:this.primaryProvider});return this.primaryProvider=i.provider,this.prefetchSymbolInfo(i),this.cache.loadProgressive(zc(e,i),t,n)}symbolInfo(e){if(e.data&&e.data.length>0)return;let t=this.registry.resolve(Bs(e),{default:this.primaryProvider});return t?this.symInfoCache.get(Ov(t))?.info:void 0}prefetchSymbolInfo(e){this.fetchSymbolInfo(e).catch(()=>{});}async loadRange(e,t){if(e.data&&e.data.length>0)return this.cache.loadRange(e,t);let n=this.registry.resolve(Bs(e),{default:this.primaryProvider});return n?this.cache.loadRange(zc(e,n),t):[]}subscribe(e,t){if(e.data&&e.data.length>0)return ()=>{};let n=this.registry.resolve(Bs(e),{default:this.primaryProvider});return n?this.cache.subscribe(zc(e,n),t):()=>{}}};function Bs(r){return r.symbol??""}function zc(r,e){return {...r,symbol:`${e.provider}:${e.ticker}`}}function Ov(r){return `${r.provider}|${r.ticker.trim().toUpperCase()}`}var uP=10*6e4;async function Nv(r,e,t,n){try{return await r.getBars(e,t,n)}catch(i){return console.warn(`[vela] data fetch failed for ${e} ${t} \u2014 ${i instanceof Error?i.message:String(i)}`),[]}}var qh=class{constructor(e){this.registry=e;}load(e){let{provider:t,ticker:n}=Mn(e.symbol??""),i=this.registry.get(t??"");return i?Nv(i,n,e.timeframe??"60",{limit:e.bars??500,session:e.session}):Promise.resolve([])}async loadProgressive(e,t,n){let{provider:i,ticker:o}=Mn(e.symbol??""),s=this.registry.get(i??"");if(!s)return [];if(!s.getBarsProgressive)return null;try{return await s.getBarsProgressive(o,e.timeframe??"60",{limit:e.bars??500,session:e.session},t,n)}catch(a){return console.warn(`[vela] progressive fetch failed for ${o} ${e.timeframe??"60"} \u2014 ${a instanceof Error?a.message:String(a)}`),[]}}loadRange(e,t){let{provider:n,ticker:i}=Mn(e.symbol??""),o=this.registry.get(n??"");return o?Nv(o,i,e.timeframe??"60",{...t,session:e.session}):Promise.resolve([])}subscribe(e,t){let{provider:n,ticker:i}=Mn(e.symbol??""),o=this.registry.get(n??"");if(!o)return ()=>{};let s=e.timeframe??"60";if(o.subscribe)return o.subscribe(i,s,t,e.session?{session:e.session}:void 0);let a=false,l=null,d=async()=>{if(!a){try{let u=await o.getBars(i,s,{limit:2,session:e.session});if(a)return;for(let h of u)t(h);}catch{}a||(l=setTimeout(()=>{d();},3e3));}};return l=setTimeout(()=>{d();},3e3),()=>{a=true,l&&clearTimeout(l);}}};var Vs=class{constructor(e){this.registry=e instanceof fi?e:null;}registerProvider(e,t){return this.registry?(this.registry.registerProvider(e,t),this):(console.warn(`[vela] chart.data.registerProvider("${e}") ignored \u2014 the active data feed is a custom feed (deps.dataFeed), not the default provider registry.`),this)}unregisterProvider(e){return this.registry?.unregisterProvider(e),this}providers(){return this.registry?.providers()??[]}resolve(e){return this.registry?.resolveSymbol(e)??null}displayPrefix(e){return this.registry?.displayPrefix(e)??null}canonicalSymbol(e){return this.registry?.canonicalSymbol(e)??null}providerInstance(e){return this.registry?.providerInstance(e)}symbols(e){return this.registry?.symbols(e)??[]}symbolIcon(e){return this.registry?.symbolIcon(e)}symbolInfo(e){return this.registry?.symbolInfoFor(e)??Promise.resolve(void 0)}capabilities(e){return this.registry?.capabilitiesFor(e)??null}ready(){return this.registry?.ready()??Promise.resolve()}};var Hs=class{constructor(e){this.ctrl=e;}get supported(){return this.ctrl.supported}setTool(e){return this.ok("setTool")&&this.ctrl.setTool(e),this}getTool(){return this.ctrl.getTool()}setSnapMode(e){return this.ok("setSnapMode")&&this.ctrl.setSnapMode(e),this}getSnapMode(){return this.ctrl.getSnapMode()}setStayMode(e){return this.ok("setStayMode")&&this.ctrl.setStayMode(e),this}getStayMode(){return this.ctrl.getStayMode()}setMode(e){return this.ok("setMode")&&this.ctrl.setMode(e),this}getMode(){return this.ctrl.getMode()}showToolbar(e=true){return this.ok("showToolbar")&&this.ctrl.showToolbar(e),this}setToolbar(e){return this.ok("setToolbar")&&this.ctrl.setToolbar(e),this}setToolShortcuts(e){return this.ok("setToolShortcuts")&&this.ctrl.setToolShortcuts(e),this}setExternalGhost(e){return this.ctrl.setExternalGhost(e),this}add(e,t={}){return this.ok("add")?this.ctrl.add(e,t):null}remove(e){return this.ctrl.remove(e),this}update(e,t){return this.ctrl.update(e,t),this}updateMany(e){return this.ctrl.updateMany(e),this}removeMany(e){return this.ctrl.removeMany(e),this}lock(e,t=true){return this.ctrl.setLocked(e,t),this}show(e,t=true){return this.ctrl.setVisible(e,t),this}select(e){return this.ok("select")&&this.ctrl.select(e==null?[]:typeof e=="string"?[e]:e),this}openSettings(e){return this.ok("openSettings")&&this.ctrl.openSettings(e),this}bringToFront(e){return this.ctrl.bringToFront(e),this}sendToBack(e){return this.ctrl.sendToBack(e),this}undo(){return this.ctrl.undo(),this}redo(){return this.ctrl.redo(),this}canUndo(){return this.ctrl.canUndo()}canRedo(){return this.ctrl.canRedo()}clone(e){return this.ok("clone")&&this.ctrl.clone(e),this}duplicate(e){return this.ok("duplicate")&&this.ctrl.duplicate(e),this}copyToClipboard(e){return this.ok("copy")&&this.ctrl.copy(e),this}paste(){return this.ok("paste")&&this.ctrl.paste(),this}all(){return this.ctrl.all()}toJSON(){return this.ctrl.toJSON()}fromJSON(e){return this.ctrl.fromJSON(e),this}favorites(){return this.ctrl.favorites()}isFavorite(e){return this.ctrl.isFavorite(e)}setFavorite(e,t){return this.ok("setFavorite")&&this.ctrl.setFavorite(e,t),this}setFavorites(e){return this.ok("setFavorites")&&this.ctrl.setFavorites([...e]),this}toolDefaults(){return this.ctrl.toolDefaults()}setToolDefaults(e){return this.ctrl.setToolDefaults(e),this}resetToolDefaults(e){return this.ctrl.resetToolDefaults(e),this}toolTemplates(){return this.ctrl.toolTemplates()}setToolTemplates(e){return this.ctrl.setToolTemplates(e),this}getConfig(){return this.ctrl.toJSON()}applyConfig(e){return this.ctrl.fromJSON(e),this}ok(e){return this.ctrl.supported?true:(console.warn(`[vela] chart.drawings.${e}() ignored \u2014 the active renderer has no userDrawings capability.`),false)}};var _s=class{constructor(e){this.ctrl=e;}get supported(){return this.ctrl.supported}add(e){return this.ctrl.add(e),this}set(e){return this.ctrl.set(e),this}remove(e){return this.ctrl.remove(e),this}clear(){return this.ctrl.clear(),this}all(){return this.ctrl.all()}defineGroup(e){return this.ctrl.defineGroup(e),this}groups(){return this.ctrl.groupDefinitions()}setGroupVisible(e,t=true){return this.ctrl.setGroupVisible(e,t),this}isGroupVisible(e){return this.ctrl.isGroupVisible(e)}};var zs=class{constructor(e){this.ctrl=e;}start(e){return this.ctrl.replayStart(e)}step(){return this.ctrl.replayStep()}stepUpdate(){return this.ctrl.replayStepUpdate()}play(e){return this.ctrl.replayPlay(e),this}pause(){return this.ctrl.replayPause(),this}stop(){return this.ctrl.replayStop(),this}get state(){return this.ctrl.replayState()}get bounds(){return this.ctrl.replayBounds()}setTicks(e){return this.ctrl.replaySetTicks(e),this}};var Ws=class r{constructor(e=()=>Date.now()){this.now=e;this.subs=new Set;this.timer=null;}onTick(e){return this.subs.add(e),this.timer==null&&this.arm(),()=>{this.subs.delete(e),this.subs.size===0&&this.timer!=null&&(clearTimeout(this.timer),this.timer=null);}}static delayToNextSecond(e){return 1e3-(e%1e3+1e3)%1e3+5}arm(){this.timer=setTimeout(()=>{this.timer=null;let e=this.now();for(let t of this.subs)t(e);this.subs.size>0&&this.arm();},r.delayToNextSecond(this.now()));}};function Gs(r){let e=r.trim(),t=/^#([0-9a-f]{3})$/i.exec(e);if(t){let i=t[1];return {r:parseInt(i[0]+i[0],16),g:parseInt(i[1]+i[1],16),b:parseInt(i[2]+i[2],16)}}if(t=/^#([0-9a-f]{6})[0-9a-f]{0,2}$/i.exec(e),t){let i=t[1];return {r:parseInt(i.slice(0,2),16),g:parseInt(i.slice(2,4),16),b:parseInt(i.slice(4,6),16)}}let n=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i.exec(e);return n?{r:parseFloat(n[1]),g:parseFloat(n[2]),b:parseFloat(n[3])}:null}function ie(r,e){let t=Gs(r);return t?`rgba(${t.r},${t.g},${t.b},${e})`:r}function Fv(r,e,t){let n=Gs(r),i=Gs(e);if(!n||!i)return r;let o=(s,a)=>Math.round(s+(a-s)*t);return `rgb(${o(n.r,i.r)},${o(n.g,i.g)},${o(n.b,i.b)})`}function Zh(r,e="#888888"){let t=Gs(r);if(!t)return e;let n=i=>Math.max(0,Math.min(255,Math.round(i))).toString(16).padStart(2,"0");return `#${n(t.r)}${n(t.g)}${n(t.b)}`}function Gt(r){let e=Gs(r);return e?.2126*e.r+.7152*e.g+.0722*e.b<128:true}var Wc={"--vela-space-1":"4px","--vela-space-2":"8px","--vela-space-3":"12px","--vela-space-4":"16px","--vela-radius-sm":"4px","--vela-radius-md":"6px","--vela-radius-lg":"10px","--vela-z-tooltip":"60","--vela-z-menu":"50","--vela-z-dialog":"40","--vela-z-popover":"6000","--vela-ease":"cubic-bezier(0.22, 1, 0.36, 1)","--vela-dur-fast":"90ms","--vela-dur-med":"160ms","--vela-font-size-sm":"11px","--vela-font-size-md":"12px","--vela-font-size-lg":"14px"};function Gc(r){let e=Gt(r.background),t=i=>e?`rgba(255,255,255,${i})`:ie(r.textColor,i+.02),n=Fv(r.background,e?"#ffffff":r.textColor,e?.03:.05);return {"--vela-font":r.fontFamily,"--vela-bg":r.background,"--vela-fg":e?"#d1d4dc":r.textColor,"--vela-fg-muted":e?"#868a96":ie(r.textColor,.62),"--vela-fg-faint":ie(r.textColor,.35),"--vela-fg-bright":e?"#f0f3fa":"#000000","--vela-surface":r.background,"--vela-surface-elev":n,"--vela-surface-overlay":n,"--vela-surface-sunken":r.background,"--vela-border":r.borderColor,"--vela-border-strong":e?"#34353b":ie(r.textColor,.28),"--vela-border-soft":r.borderColor,"--vela-border-faint":ie(r.textColor,.08),"--vela-hover":t(.06),"--vela-active":t(.1),"--vela-hover-strong":t(.16),"--vela-focus":ie(r.textColor,.5),"--vela-focus-soft":ie(r.textColor,.12),"--vela-separator-hover-band":ie(r.textColor,.1),"--vela-separator-hover-line":ie(r.textColor,.55),"--vela-scroll":ie(r.textColor,.3),"--vela-accent":xt,"--vela-accent-bright":Xi,"--vela-highlight":yb,"--vela-selected-bg":e?"#f0f3fa":r.textColor,"--vela-selected-fg":e?r.background:"#ffffff","--vela-fg-on-fill":"#ffffff","--vela-up":r.upColor,"--vela-down":r.downColor,"--vela-danger":r.downColor,"--vela-shadow":"0 8px 30px rgba(0,0,0,0.5)","--vela-shadow-dialog":"0 20px 60px rgba(0,0,0,0.5)","--vela-backdrop":"rgba(0,0,0,0.45)"}}function Xe(r,e){let t=n=>{for(let i in n)r.style.setProperty(i,n[i]);};t(Wc),t(Gc(e));}function Pn(r,e){let t=null,n=null,i=()=>{t!==null&&(clearTimeout(t),t=null),n?.remove(),n=null;},o=()=>{let a=e.text();if(!a)return;n=r.ownerDocument.createElement("div"),n.textContent=a,n.style.cssText="position:absolute;z-index:var(--vela-z-tooltip);pointer-events:none;background:var(--vela-bg);border:1px solid var(--vela-border);color:var(--vela-fg);border-radius:var(--vela-radius-md);padding:4px 9px;box-shadow:var(--vela-shadow);font:var(--vela-font-size-md) var(--vela-font);"+(e.wrap?"max-width:260px;":"white-space:nowrap;"),Xe(n,e.theme()),e.host.appendChild(n);let d=r.getBoundingClientRect(),u=e.host.getBoundingClientRect();if(e.placement==="right")n.style.left=`${d.right-u.left+8}px`,n.style.top=`${d.top-u.top+(d.height-n.offsetHeight)/2}px`;else {let h=Math.min(d.left-u.left,Math.max(0,u.width-n.offsetWidth-4));n.style.left=`${Math.max(0,h)}px`,n.style.top=e.placement==="above"?`${Math.max(0,d.top-u.top-n.offsetHeight-6)}px`:`${d.bottom-u.top+6}px`;}},s=a=>{a.pointerType==="mouse"&&(i(),t=window.setTimeout(o,e.delayMs??700));};return r.addEventListener("pointerenter",s),r.addEventListener("pointerleave",i),r.addEventListener("pointerdown",i),()=>{r.removeEventListener("pointerenter",s),r.removeEventListener("pointerleave",i),r.removeEventListener("pointerdown",i),i();}}function Uc(r,e){let t=e.size??16,n=document.createElement("span");n.className="vela-hint",n.setAttribute("role","img"),n.setAttribute("aria-label",r),n.innerHTML=Ge("info",t),n.style.cssText=`flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:${t}px;height:${t}px;border-radius:50%;cursor:help;user-select:none;background:var(--vela-hover);color:var(--vela-fg-muted);transition:background var(--vela-dur-fast) ease,color var(--vela-dur-fast) ease;`;let i=s=>{n.style.background=s?"var(--vela-active)":"var(--vela-hover)",n.style.color=s?"var(--vela-fg-bright)":"var(--vela-fg-muted)";};n.addEventListener("pointerenter",()=>i(true)),n.addEventListener("pointerleave",()=>i(false));let o=Pn(n,{host:e.host,theme:e.theme,text:()=>r,wrap:true,delayMs:250});return {el:n,dispose:o}}var hP=Object.defineProperty,pP=(r,e,t)=>e in r?hP(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t,we=(r,e,t)=>pP(r,typeof e!="symbol"?e+"":e,t);function Bv(r){return r==null?[]:Array.isArray(r)?r:[r]}var Vv=r=>r[0],Hv=r=>r[r.length-1];function _v(r,e,t={}){let{step:n=1,loop:i=true}=t,o=e+n,s=r.length,a=s-1;return e===-1?n>0?0:a:o<0?i?a:0:o>=s?i?0:e>s?s:e:o}function zv(r,e,t={}){return r[_v(r,e,t)]}function mP(r,e,t={}){let{step:n=1,loop:i=true}=t;return _v(r,e,{step:-n,loop:i})}function Wv(r,e,t={}){return r[mP(r,e,t)]}var Gv=r=>r?.constructor.name==="Array",gP=(r,e)=>{if(r.length!==e.length)return false;for(let t=0;t<r.length;t++)if(!ho(r[t],e[t]))return false;return true},ho=(r,e)=>{if(Object.is(r,e))return true;if(r==null&&e!=null||r!=null&&e==null)return false;if(typeof r?.isEqual=="function"&&typeof e?.isEqual=="function")return r.isEqual(e);if(typeof r=="function"&&typeof e=="function")return r.toString()===e.toString();if(Gv(r)&&Gv(e))return gP(Array.from(r),Array.from(e));if(typeof r!="object"||typeof e!="object")return false;let t=Object.keys(e??Object.create(null)),n=t.length;for(let i=0;i<n;i++)if(!Reflect.has(r,t[i]))return false;for(let i=0;i<n;i++){let o=t[i];if(!ho(r[o],e[o]))return false}return true};var fP=r=>r!=null&&typeof r=="object";var po=r=>typeof r=="string",Ot=r=>typeof r=="function",Uv=r=>r==null,Us=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),bP=r=>Object.prototype.toString.call(r),$v=Function.prototype.toString,vP=$v.call(Object),bi=r=>{if(!fP(r)||bP(r)!="[object Object]"||xP(r))return false;let e=Object.getPrototypeOf(r);if(e===null)return true;let t=Us(e,"constructor")&&e.constructor;return typeof t=="function"&&t instanceof t&&$v.call(t)==vP},yP=r=>typeof r=="object"&&r!==null&&"$$typeof"in r&&"props"in r,wP=r=>typeof r=="object"&&r!==null&&"__v_isVNode"in r,xP=r=>yP(r)||wP(r);var $s=(r,...e)=>(typeof r=="function"?r(...e):r)??void 0,Qh=r=>r,Yv=r=>r(),Jh=()=>{},Tr=(...r)=>(...e)=>{r.forEach(function(t){t?.(...e);});};function kr(r){if(!bi(r)||r===void 0)return r;let e=Reflect.ownKeys(r).filter(n=>typeof n=="string"),t={};for(let n of e){let i=r[n];i!==void 0&&(t[n]=kr(i));}return t}function mo(...r){r.length===1?r[0]:r[1];r.length===2?r[0]:true;}function ep(...r){r.length===1?r[0]:r[1];r.length===2?r[0]:true;}function Ys(r,e){if(r==null)throw new Error(e())}var SP=(...r)=>r.map(e=>e?.trim?.()).filter(Boolean).join(" "),CP=/((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g,Kv=r=>{let e={},t;for(;t=CP.exec(r);)e[t[1]]=t[2];return e},TP=(r,e)=>{if(po(r)){if(po(e))return `${r};${e}`;r=Kv(r);}else po(e)&&(e=Kv(e));return Object.assign({},r??{},e??{})};function Xv(...r){let e={};for(let t of r){if(!t)continue;for(let i in e){if(i.startsWith("on")&&typeof e[i]=="function"&&typeof t[i]=="function"){e[i]=Tr(t[i],e[i]);continue}if(i==="className"||i==="class"){e[i]=SP(e[i],t[i]);continue}if(i==="style"){e[i]=TP(e[i],t[i]);continue}e[i]=t[i]!==void 0?t[i]:e[i];}for(let i in t)e[i]===void 0&&(e[i]=t[i]);let n=Object.getOwnPropertySymbols(t);for(let i of n)e[i]=t[i];}return e}var Lr=".",Zv="#",jv=new WeakMap,Qv=new WeakMap;function tp(r){return r.join(Lr)}function kP(r){return r.includes(Lr)}function Jv(r){return r.startsWith(Zv)}function LP(r){return r.startsWith(Lr)}function MP(r){return Jv(r)?r.slice(Zv.length):r}function np(r,e){return r?`${r}${Lr}${e}`:e}function EP(r){let e=new Map,t=new Map,n=(i,o)=>{e.set(i,o);let s=o.id;s&&(t.has(s)&&ep(`[zag-js] Duplicate state id: "${s}"`),t.set(s,i));let a=o.states;if(a){Ys(o.initial,()=>`[zag-js] Compound state "${i}" has child states but no "initial" property`),o.initial in a||ep(`[zag-js] Compound state "${i}" has initial "${String(o.initial)}" which is not a child state`);for(let[l,d]of Object.entries(a)){if(!d)continue;let u=np(i,l);n(u,d);}}};for(let[i,o]of Object.entries(r.states))o&&n(i,o);return {index:e,idIndex:t}}function go(r){let e=jv.get(r);if(e)return e;let{index:t,idIndex:n}=EP(r);return jv.set(r,t),Qv.set(r,n),t}function PP(r,e){return go(r),Qv.get(r)?.get(e)}function rp(r){return r?String(r).split(Lr).filter(Boolean):[]}function $c(r,e){if(!e)return [];let t=go(r),n=rp(e),i=[],o=[];for(let s of n){o.push(s);let a=tp(o),l=t.get(a);if(!l)break;i.push({path:a,state:l});}return i}function Ks(r,e){let t=go(r),n=rp(e);if(!n.length)return e;let i=[];for(let a of n){i.push(a);let l=tp(i);if(!t.has(l))return e}let o=tp(i),s=t.get(o);for(;s?.initial;){let a=`${o}${Lr}${s.initial}`,l=t.get(a);if(!l)break;o=a,s=l;}return o}function qv(r,e){return go(r).has(e)}function ip(r,e,t){let n=String(e);if(Jv(n)){let i=MP(n),o=PP(r,i);return Ys(o,()=>`[zag-js] Unknown state id: "${i}"`),Ks(r,o)}if(LP(n)&&t){let i=np(t,n.slice(1));return Ks(r,i)}if(!kP(n)&&t){let i=rp(t);for(let o=i.length-1;o>=1;o--){let s=i.slice(0,o).join(Lr),a=np(s,n);if(qv(r,a))return Ks(r,a)}if(qv(r,n))return Ks(r,n)}return Ks(r,n)}function ey(r,e,t){let n=$c(r,e);for(let o=n.length-1;o>=0;o--){let a=n[o]?.state.on?.[t];if(a)return {transitions:a,source:n[o]?.path}}return {transitions:r.on?.[t],source:void 0}}function ty(r,e,t,n){let i=e?$c(r,e):[],o=$c(r,t),s=0;for(;s<i.length&&s<o.length&&i[s]?.path===o[s]?.path;)s+=1;let a=i.slice(s).reverse(),l=o.slice(s),d=i.at(-1)?.path===o.at(-1)?.path;return n&&d&&(a=i.slice().reverse(),l=o),{exiting:a,entering:l}}function ny(r,e){return r?r===e||r.startsWith(`${e}${Lr}`):false}function ry(r,e,t){return $c(r,e).some(n=>n.state.tags?.includes(t))}function iy(){return {and:(...r)=>function(t){return r.every(n=>t.guard(n))},or:(...r)=>function(t){return r.some(n=>t.guard(n))},not:r=>function(t){return !t.guard(r)}}}function Yc(r){return go(r),r}var fo=(r=>(r.NotStarted="Not Started",r.Started="Started",r.Stopped="Stopped",r))(fo||{}),Xs="__init__";var IP=Object.defineProperty,AP=(r,e,t)=>e in r?IP(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t,Kc=(r,e,t)=>AP(r,typeof e!="symbol"?e+"":e,t);var oy=(r,e)=>r.map((t,n)=>r[(Math.max(e,0)+n)%r.length]);var js=()=>{},qs=r=>typeof r=="object"&&r!==null;var Kt=r=>r?"":void 0,op=r=>r?"true":void 0;var RP=1,DP=9,OP=11;var Se=r=>qs(r)&&r.nodeType===RP&&typeof r.nodeName=="string",Zs=r=>qs(r)&&r.nodeType===DP,NP=r=>qs(r)&&r===r.window;var sy=r=>Se(r)?r.localName||"":"#document";function ay(r){return ["html","body","#document"].includes(sy(r))}var ly=r=>qs(r)&&r.nodeType!==void 0,vi=r=>ly(r)&&r.nodeType===OP&&"host"in r,sp=r=>Se(r)&&r.localName==="input",cy=r=>!!r?.matches("a[href]"),dy=r=>Se(r)?r.offsetWidth>0||r.offsetHeight>0||r.getClientRects().length>0:false;function Qs(r){if(!r)return false;let e=r.getRootNode();return In(e)===r}var FP=/(textarea|select)/;function bo(r){if(r==null||!Se(r))return false;try{return sp(r)&&r.selectionStart!=null||FP.test(r.localName)||r.isContentEditable||r.getAttribute("contenteditable")==="true"||r.getAttribute("contenteditable")===""}catch{return false}}function Nt(r,e){if(!r||!e||!Se(r)||!ly(e))return false;if(Se(e)&&r===e||r.contains(e))return true;let t=e.getRootNode?.();if(t&&vi(t)){let n=e;for(;n;){if(r===n)return true;n=n.parentNode||n.host;}}return false}function $e(r){return Zs(r)?r:NP(r)?r.document:r?.ownerDocument??document}function BP(r){return $e(r).documentElement}function _e(r){return vi(r)?_e(r.host):Zs(r)?r.defaultView??window:Se(r)?r.ownerDocument?.defaultView??window:window}function In(r){let e=r.activeElement;for(;e?.shadowRoot;){let t=e.shadowRoot.activeElement;if(!t||t===e)break;e=t;}return e}function uy(r){if(sy(r)==="html")return r;let e=r.assignedSlot||r.parentNode||vi(r)&&r.host||BP(r);return vi(e)?e.host:e}function Xc(r){let e;try{if(e=r.getRootNode({composed:!0}),Zs(e)||vi(e))return e}catch{}return r.ownerDocument??document}var ap=new WeakMap;function vo(r){return ap.has(r)||ap.set(r,_e(r).getComputedStyle(r)),ap.get(r)}var lp=new Set(["menu","listbox","dialog","grid","tree","region","application"]),VP=r=>lp.has(r),hy=r=>r.getAttribute("aria-controls")?.split(" ")||[];function jc(r,e){let t=new Set,n=Xc(r),i=o=>{let s=o.querySelectorAll("[aria-controls]");for(let a of s){if(a.getAttribute("aria-expanded")!=="true")continue;let l=hy(a);for(let d of l){if(!d||t.has(d))continue;t.add(d);let u=n.getElementById(d);if(u){let h=u.getAttribute("role"),p=u.getAttribute("aria-modal")==="true";if(h&&VP(h)&&!p&&(u===e||u.contains(e)||i(u)))return true}}}return false};return i(r)}function cp(r,e){let t=Xc(r),n=new Set,i=o=>{let s=o.querySelectorAll("[aria-controls]");for(let a of s){if(a.getAttribute("aria-expanded")!=="true")continue;let l=hy(a);for(let d of l){if(!d||n.has(d))continue;n.add(d);let u=t.getElementById(d);if(u){let h=u.getAttribute("role"),p=u.getAttribute("aria-modal")==="true";h&&lp.has(h)&&!p&&(e(u),i(u));}}}};i(r);}function py(r){let e=new Set;return cp(r,t=>{r.contains(t)||e.add(t);}),Array.from(e)}function HP(r){let e=r.getAttribute("role");return !!(e&&lp.has(e))}function _P(r){return r.hasAttribute("aria-controls")&&r.getAttribute("aria-expanded")==="true"}function my(r){return _P(r)?true:!!r.querySelector?.('[aria-controls][aria-expanded="true"]')}function gy(r){if(!r.id)return false;let e=Xc(r),t=CSS.escape(r.id),n=`[aria-controls~="${t}"][aria-expanded="true"], [aria-controls="${t}"][aria-expanded="true"]`;return !!(e.querySelector(n)&&HP(r))}var dp=()=>typeof document<"u";function zP(){return navigator.userAgentData?.platform??navigator.platform}function WP(){let r=navigator.userAgentData;return r&&Array.isArray(r.brands)?r.brands.map(({brand:e,version:t})=>`${e}/${t}`).join(" "):navigator.userAgent}var up=r=>dp()&&r.test(zP()),fy=r=>dp()&&r.test(WP());var hp=()=>dp()&&!!navigator.maxTouchPoints,GP=()=>up(/^iPhone/i),UP=()=>up(/^iPad/i)||yo()&&navigator.maxTouchPoints>1,by=()=>GP()||UP();var yo=()=>up(/^Mac/i);var vy=()=>fy(/Firefox/i);var yy=()=>fy(/Android/i);function $P(r){return r.composedPath?.()??r.nativeEvent?.composedPath?.()}function Ze(r){return $P(r)?.[0]??r.target}function pp(r){let e=r.currentTarget;if(!e||!e.matches("a[href], button[type='submit'], input[type='submit']"))return false;let n=r.button===1,i=YP(r);return n||i}function mp(r){let e=r.currentTarget;if(!e)return false;let t=e.localName;return r.altKey?t==="a"||t==="button"&&e.type==="submit"||t==="input"&&e.type==="submit":false}function YP(r){return yo()?r.metaKey:r.ctrlKey}function xy(r){return r.key.length===1&&!r.ctrlKey&&!r.metaKey}function Sy(r){return r.pointerType===""&&r.isTrusted?true:yy()&&r.pointerType?r.type==="click"&&r.buttons===1:r.detail===0&&!r.pointerType}var qc=r=>r.button===2||yo()&&r.ctrlKey&&r.button===0,Cy=r=>r.ctrlKey||r.altKey||r.metaKey,KP=r=>"touches"in r&&r.touches.length>0,XP={Up:"ArrowUp",Down:"ArrowDown",Esc:"Escape"," ":"Space",",":"Comma",Left:"ArrowLeft",Right:"ArrowRight"},wy={ArrowLeft:"ArrowRight",ArrowRight:"ArrowLeft"};function gp(r,e={}){let{dir:t="ltr",orientation:n="horizontal"}=e,i=r.key;return i=XP[i]??i,t==="rtl"&&n==="horizontal"&&i in wy&&(i=wy[i]),i}function wo(r,e="client"){let t=KP(r)?r.touches[0]||r.changedTouches[0]:r;return {x:t[`${e}X`],y:t[`${e}Y`]}}var Ct=(r,e,t,n)=>{let i=typeof r=="function"?r():r;return i?.addEventListener(e,t,n),()=>{i?.removeEventListener(e,t,n);}};var Ty=r=>Se(r)&&r.tagName==="IFRAME",jP=/^(audio|video|details)$/;function ky(r){let e=r.getAttribute("tabindex");return e?parseInt(e,10):NaN}var qP=r=>!Number.isNaN(ky(r)),ZP=r=>ky(r)<0;function QP(r){return sp(r)&&r.type==="radio"}function JP(r){if(!QP(r)||!r.name||r.checked)return true;let e=`input[type="radio"][name="${CSS.escape(r.name)}"]`,t=r.form??r.ownerDocument,n=Array.from(t.querySelectorAll(e)).filter(o=>o.form===r.form&&Xt(o)),i=n.find(o=>o.checked);return i?i===r:n[0]===r}function eI(r,e){if(!e)return null;if(e===true)return r.shadowRoot||null;let t=e(r);return (t===true?r.shadowRoot:t)||null}function Ly(r,e,t){let n=[...r],i=[...r],o=new Set,s=new Map;r.forEach((l,d)=>s.set(l,d));let a=0;for(;a<i.length;){let l=i[a++];if(!l||o.has(l))continue;o.add(l);let d=eI(l,e);if(d){let u=Array.from(d.querySelectorAll(Zc)).filter(t),h=s.get(l);if(h!==void 0){let p=h+1;n.splice(p,0,...u),u.forEach((m,g)=>{s.set(m,p+g);});for(let m=p+u.length;m<n.length;m++)s.set(n[m],m);}else {let p=n.length;n.push(...u),u.forEach((m,g)=>{s.set(m,p+g);});}i.push(...u);}}return n}var Zc="input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type",fp=(r,e={})=>{if(!r)return [];let{includeContainer:t=false,getShadowRoot:n}=e,i=Array.from(r.querySelectorAll(Zc));(t==true||t=="if-empty"&&i.length===0)&&Se(r)&&Xt(r)&&i.unshift(r);let s=[];for(let a of i)if(Xt(a)){if(Ty(a)&&a.contentDocument){let l=a.contentDocument.body;s.push(...fp(l,{getShadowRoot:n}));continue}s.push(a);}return n?Ly(s,n,Xt):s};function Xt(r){return !Se(r)||r.closest("[inert]")?false:r.matches(Zc)&&dy(r)}function xo(r,e={}){if(!r)return [];let{includeContainer:t,getShadowRoot:n}=e,i=Array.from(r.querySelectorAll(Zc));t&&Mr(r)&&i.unshift(r);let o=[];for(let s of i)if(Mr(s)){if(Ty(s)&&s.contentDocument){let a=s.contentDocument.body;o.push(...xo(a,{getShadowRoot:n}));continue}o.push(s);}if(n){let s=Ly(o,n,Mr);return !s.length&&t?i:s}return !o.length&&t?i:o}function Mr(r){return Se(r)&&r.tabIndex>0?true:!Xt(r)||ZP(r)?false:JP(r)}function My(r,e={}){let t=xo(r,e),n=t[0]||null,i=t[t.length-1]||null;return [n,i]}function So(r){return r.tabIndex<0&&(jP.test(r.localName)||bo(r))&&!qP(r)?0:r.tabIndex}function Qc(r){let{root:e,getInitialEl:t,filter:n,enabled:i=true}=r;if(!i)return;let o=null;if(o||(o=typeof t=="function"?t():t),o||(o=e?.querySelector("[data-autofocus],[autofocus]")),!o){let s=xo(e);o=n?s.filter(n)[0]:s[0];}return o||e||void 0}function Ey(r){let e=r.currentTarget;if(!e)return false;let[t,n]=My(e);return !(Qs(t)&&r.shiftKey||Qs(n)&&!r.shiftKey||!t&&!n)}var tI=class Py{constructor(){Kc(this,"id",null),Kc(this,"fn_cleanup"),Kc(this,"cleanup",()=>{this.cancel();});}static create(){return new Py}request(e){this.cancel(),this.id=globalThis.requestAnimationFrame(()=>{this.id=null,this.fn_cleanup=e?.();});}cancel(){this.id!==null&&(globalThis.cancelAnimationFrame(this.id),this.id=null),this.fn_cleanup?.(),this.fn_cleanup=void 0;}isActive(){return this.id!==null}};function je(r){let e=tI.create();return e.request(r),e.cleanup}function Iy(r){let e=new Set;function t(n){let i=globalThis.requestAnimationFrame(n);e.add(()=>globalThis.cancelAnimationFrame(i));}return t(()=>t(r)),function(){e.forEach(i=>i());}}function Ay(r,e,t){let n=je(()=>{r.removeEventListener(e,i,true),t();}),i=()=>{n(),t();};return r.addEventListener(e,i,{once:true,capture:true}),n}function nI(r,e){if(!r)return;let{attributes:t,callback:n}=e,i=r.ownerDocument.defaultView||window,o=new i.MutationObserver(s=>{for(let a of s)a.type==="attributes"&&a.attributeName&&t.includes(a.attributeName)&&n(a);});return o.observe(r,{attributes:true,attributeFilter:t}),()=>o.disconnect()}function Ry(r,e){let n=je,i=[];return i.push(n(()=>{let o=typeof r=="function"?r():r;i.push(nI(o,e));})),()=>{i.forEach(o=>o?.());}}function Dy(r){let e=()=>{let t=_e(r);r.dispatchEvent(new t.MouseEvent("click"));};vy()?Ay(r,"keyup",e):queueMicrotask(e);}function Jc(r){let e=uy(r);return ay(e)?$e(e).body:Se(e)&&bp(e)?e:Jc(e)}var rI=/auto|scroll|overlay|hidden|clip/,iI=new Set(["inline","contents"]);function bp(r){let e=_e(r),{overflow:t,overflowX:n,overflowY:i,display:o}=e.getComputedStyle(r);return rI.test(t+i+n)&&!iI.has(o)}function Co(r,e){return Array.from(r?.querySelectorAll(e)??[])}var ed=r=>r.id;function oI(r,e,t=ed){return r.find(n=>t(n)===e)}function Oy(r,e,t=ed){let n=oI(r,e,t);return n?r.indexOf(n):-1}function sI(r){return r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth}function Ny(r,e){let{rootEl:t,...n}=e||{};!r||!t||!bp(t)||!sI(t)||r.scrollIntoView(n);}var aI=r=>r.split("").map(e=>{let t=e.charCodeAt(0);return t>0&&t<128?e:t>=128&&t<=255?`/x${t.toString(16)}`.replace("/","\\"):""}).join("").trim(),lI=r=>aI(r.dataset?.valuetext??r.textContent??""),cI=(r,e)=>r.trim().toLowerCase().startsWith(e.toLowerCase());function Fy(r,e,t,n=ed){let i=t?Oy(r,t,n):-1,o=t?oy(r,i):r;return e.length===1&&(o=o.filter(a=>n(a)!==t)),o.find(a=>cI(lI(a),e))}function Js(r,e){if(!r)return js;let t=Object.keys(e).reduce((n,i)=>(n[i]=r.style.getPropertyValue(i),n),{});return dI(t,e)?js:(Object.assign(r.style,e),()=>{Object.assign(r.style,t),r.style.length===0&&r.removeAttribute("style");})}function By(r,e,t){if(!r)return js;let n=r.style.getPropertyValue(e);return n===t?js:(r.style.setProperty(e,t),()=>{r.style.setProperty(e,n),r.style.length===0&&r.removeAttribute("style");})}function dI(r,e){return Object.keys(r).every(t=>r[t]===e[t])}function uI(r,e){let{state:t,activeId:n,key:i,timeout:o=350,itemToId:s}=e,a=t.keysSoFar+i,d=a.length>1&&Array.from(a).every(g=>g===a[0])?a[0]:a,u=r.slice(),h=Fy(u,d,n,s);function p(){clearTimeout(t.timer),t.timer=-1;}function m(g){t.keysSoFar=g,p(),g!==""&&(t.timer=+setTimeout(()=>{m(""),p();},o));}return m(a),h}var td=Object.assign(uI,{defaultOptions:{keysSoFar:"",timer:-1},isValidEvent:hI});function hI(r){return r.key.length===1&&!r.ctrlKey&&!r.metaKey}function pI(r,e,t){let{signal:n}=e;return [new Promise((s,a)=>{let l=setTimeout(()=>{a(new Error(`Timeout of ${t}ms exceeded`));},t);n.addEventListener("abort",()=>{clearTimeout(l),a(new DOMException("Promise aborted","AbortError"));}),r.then(d=>{n.aborted||(clearTimeout(l),s(d));}).catch(d=>{n.aborted||(clearTimeout(l),a(d));});}),()=>e.abort()]}function Vy(r,e){let{timeout:t,rootNode:n}=e,i=_e(n),o=$e(n),s=new i.AbortController;return pI(new Promise(a=>{let l=r();if(l){a(l);return}let d=new i.MutationObserver(()=>{let u=r();u&&u.isConnected&&(d.disconnect(),a(u));});d.observe(o.body,{childList:true,subtree:true});}),s,t)}function Hy(r){let e=()=>r.getRootNode?.()??document,t=()=>$e(e());return {...r,getRootNode:e,getDoc:t,getWin:()=>t().defaultView??window,getActiveElement:()=>In(e()),isActiveElement:Qs,getById:s=>e().getElementById(s)}}function _y(r){return new Proxy({},{get(e,t){return t==="style"?n=>r({style:n}).style:r}})}var zy={onFocus:"onFocusin",onBlur:"onFocusout",onChange:"onInput",onDoubleClick:"onDblclick",htmlFor:"for",className:"class",defaultValue:"value",defaultChecked:"checked"},mI=new Set(["viewBox","preserveAspectRatio"]),gI=r=>{let e="";for(let t in r){let n=r[t];n!=null&&(t.startsWith("--")||(t=t.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)),e+=`${t}:${n};`);}return e},To=_y(r=>Object.entries(r).reduce((e,[t,n])=>{if(n===void 0)return e;if(t in zy&&(t=zy[t]),t==="style"&&typeof n=="object")return e.style=gI(n),e;let i=mI.has(t)?t:t.toLowerCase();return e[i]=n,e},{}));var nd=new WeakMap,Wy=new Set(["value","checked","selected"]),fI=new Set(["viewBox","preserveAspectRatio","clipPath","clipRule","fillRule","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeDashoffset","strokeMiterlimit"]),bI=r=>r.tagName==="svg"||r.namespaceURI==="http://www.w3.org/2000/svg",rd=(r,e)=>bI(r)&&fI.has(e)?e:e.toLowerCase();function Ft(r,e,t){let n=t||"default",i=nd.get(r);i||(i=new Map,nd.set(r,i));let o=i.get(n)||{},s=Object.keys(e),a=(b,f)=>{r.addEventListener(b.toLowerCase(),f);},l=(b,f)=>{r.removeEventListener(b.toLowerCase(),f);},d=b=>b.startsWith("on"),u=b=>!b.startsWith("on"),h=b=>a(b.substring(2),e[b]),p=b=>l(b.substring(2),e[b]),m=b=>{let f=e[b],v=o[b];if(f!==v){if(b==="class"){r.className=f??"";return}if(Wy.has(b)){r[b]=f??"";return}if(typeof f=="boolean"&&!b.includes("aria-")){r.toggleAttribute(rd(r,b),f);return}if(b==="children"){r.innerHTML=f;return}if(f!=null){r.setAttribute(rd(r,b),f);return}r.removeAttribute(rd(r,b));}};for(let b in o)e[b]==null&&(b==="class"?r.className="":Wy.has(b)?r[b]="":r.removeAttribute(rd(r,b)));return Object.keys(o).filter(d).forEach(b=>{l(b.substring(2),o[b]);}),s.filter(d).forEach(h),s.filter(u).forEach(m),i.set(n,e),function(){s.filter(d).forEach(p);let f=nd.get(r);f&&(f.delete(n),f.size===0&&nd.delete(r));}}function vI(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function vp(r,e){let t=vI();return t?(t[r]||(t[r]=e()),t[r]):e()}var ko=vp("__zag__refSet",()=>new WeakSet);var yI=r=>typeof r=="object"&&r!==null&&"$$typeof"in r&&"props"in r,wI=r=>typeof r=="object"&&r!==null&&"__v_isVNode"in r,xI=r=>typeof r=="object"&&r!==null&&"nodeType"in r&&typeof r.nodeName=="string",SI=r=>yI(r)||wI(r)||xI(r),id=r=>r!==null&&typeof r=="object",yp=r=>id(r)&&!ko.has(r)&&(Array.isArray(r)||!(Symbol.iterator in r))&&!SI(r)&&!(r instanceof WeakMap)&&!(r instanceof WeakSet)&&!(r instanceof Error)&&!(r instanceof Number)&&!(r instanceof Date)&&!(r instanceof String)&&!(r instanceof RegExp)&&!(r instanceof ArrayBuffer)&&!(r instanceof Promise)&&!(r instanceof File)&&!(r instanceof Blob)&&!(r instanceof AbortController);var CI=Symbol();var Gy=Object.getPrototypeOf,wp=new WeakMap,TI=r=>r&&(wp.has(r)?wp.get(r):Gy(r)===Object.prototype||Gy(r)===Array.prototype);var Uy=r=>TI(r)&&r[CI]||null,xp=(r,e=true)=>{wp.set(r,e);};var yi=vp("__zag__proxyStateMap",()=>new WeakMap),kI=(r=Object.is,e=(a,l)=>new Proxy(a,l),t=new WeakMap,n=(a,l)=>{let d=t.get(a);if(d?.[0]===l)return d[1];let u=Array.isArray(a)?[]:Object.create(Object.getPrototypeOf(a));return xp(u,true),t.set(a,[l,u]),Reflect.ownKeys(a).forEach(h=>{let p=Reflect.get(a,h);ko.has(p)?(xp(p,false),u[h]=p):yi.has(p)?u[h]=$y(p):u[h]=p;}),Object.freeze(u)},i=new WeakMap,o=[1,1],s=a=>{if(!id(a))throw new Error("object required");let l=i.get(a);if(l)return l;let d=o[0],u=new Set,h=(L,y=++o[0])=>{d!==y&&(d=y,u.forEach(E=>E(L,y)));},p=o[1],m=(L=++o[1])=>(p!==L&&!u.size&&(p=L,b.forEach(([y])=>{let E=y[1](L);E>d&&(d=E);})),d),g=L=>(y,E)=>{let S=[...y];S[1]=[L,...S[1]],h(S,E);},b=new Map,f=(L,y)=>{if(u.size){let E=y[3](g(L));b.set(L,[y,E]);}else b.set(L,[y]);},v=L=>{let y=b.get(L);y&&(b.delete(L),y[1]?.());},w=L=>(u.add(L),u.size===1&&b.forEach(([E,S],P)=>{let A=E[3](g(P));b.set(P,[E,A]);}),()=>{u.delete(L),u.size===0&&b.forEach(([E,S],P)=>{S&&(S(),b.set(P,[E]));});}),x=Array.isArray(a)?[]:Object.create(Object.getPrototypeOf(a)),M=e(x,{deleteProperty(L,y){let E=Reflect.get(L,y);v(y);let S=Reflect.deleteProperty(L,y);return S&&h(["delete",[y],E]),S},set(L,y,E,S){let P=Reflect.has(L,y),A=Reflect.get(L,y,S);if(P&&(r(A,E)||i.has(E)&&r(A,i.get(E))))return true;v(y),id(E)&&(E=Uy(E)||E);let F=E;if(!Object.getOwnPropertyDescriptor(L,y)?.set){!yi.has(E)&&yp(E)&&(F=od(E));let G=!ko.has(F)&&yi.get(F);G&&f(y,G);}return Reflect.set(L,y,F,S),h(["set",[y],E,A]),true}});i.set(a,M);let C=[x,m,n,w];return yi.set(M,C),Reflect.ownKeys(a).forEach(L=>{let y=Object.getOwnPropertyDescriptor(a,L);y.get||y.set?Object.defineProperty(x,L,y):M[L]=a[L];}),M})=>[s,yi,ko,r,e,yp,t,n,i,o],[LI]=kI();function od(r={}){return LI(r)}function sd(r,e,t){let n=yi.get(r);let i,o=[],s=n[3],a=false,d=s(u=>{if(o.push(u),t);i||(i=Promise.resolve().then(()=>{i=void 0,a&&e(o.splice(0));}));});return a=true,()=>{a=false,d();}}function $y(r){let e=yi.get(r);let[t,n,i]=e;return i(t,n())}function ta(r){let e=r().value??r().defaultValue;r().debug&&console.log(`[bindable > ${r().debug}] initial`,e);let t=r().isEqual??Object.is,n=od({value:e}),i=()=>r().value!==void 0;return {initial:e,ref:n,get(){return i()?r().value:n.value},set(o){let s=i()?r().value:n.value,a=Ot(o)?o(s):o;r().debug&&console.log(`[bindable > ${r().debug}] setValue`,{next:a,prev:s}),i()||(n.value=a),t(a,s)||r().onChange?.(a,s);},invoke(o,s){r().onChange?.(o,s);},hash(o){return r().hash?.(o)??String(o)}}}ta.cleanup=r=>{};ta.ref=r=>{let e=r;return {get:()=>e,set:t=>{e=t;}}};function Yy(r){let e={current:r};return {get(t){return e.current[t]},set(t,n){e.current[t]=n;}}}function Sp(r,e){if(!bi(r)||!bi(e))return e===void 0?r:e;let t={...r};for(let n of Object.keys(e)){let i=e[n],o=r[n];i!==void 0&&(bi(o)&&bi(i)?t[n]=Sp(o,i):t[n]=i);}return t}var Cp=class{constructor(r,e={}){we(this,"machine",r),we(this,"scope"),we(this,"context"),we(this,"prop"),we(this,"state"),we(this,"refs"),we(this,"computed"),we(this,"event",{type:""}),we(this,"previousEvent",{type:""}),we(this,"effects",new Map),we(this,"transition",null),we(this,"cleanups",[]),we(this,"subscriptions",[]),we(this,"userPropsRef"),we(this,"getEvent",()=>({...this.event,current:()=>this.event,previous:()=>this.previousEvent})),we(this,"getState",()=>({...this.state,matches:(...h)=>h.some(p=>ny(this.state.get(),p)),hasTag:h=>ry(this.machine,this.state.get(),h)})),we(this,"debug",(...h)=>{this.machine.debug&&console.log(...h);}),we(this,"notify",()=>{this.publish();}),we(this,"send",h=>{this.status===fo.Started&&queueMicrotask(()=>{if(!h)return;this.previousEvent=this.event,this.event=h,this.debug("send",h);let p=this.state.get(),m=h.type,{transitions:g,source:b}=ey(this.machine,p,m),f=this.choose(g);if(!f)return;this.transition=f;let v=ip(this.machine,f.target??p,b);this.debug("transition",f),v!==p?this.state.set(v):f.reenter?this.state.invoke(p,p):this.action(f.actions);});}),we(this,"action",h=>{let p=Ot(h)?h(this.getParams()):h;if(!p)return;let m=p.map(g=>{let b=this.machine.implementations?.actions?.[g];return b||mo(`[zag-js] No implementation found for action "${JSON.stringify(g)}"`),b});for(let g of m)g?.(this.getParams());}),we(this,"guard",h=>{if(Ot(h))return h(this.getParams());let p=this.machine.implementations?.guards?.[h];return p||mo(`[zag-js] No implementation found for guard "${JSON.stringify(h)}"`),p?.(this.getParams())}),we(this,"effect",h=>{let p=Ot(h)?h(this.getParams()):h;if(!p)return;let m=p.map(b=>{let f=this.machine.implementations?.effects?.[b];return f||mo(`[zag-js] No implementation found for effect "${JSON.stringify(b)}"`),f}),g=[];for(let b of m){let f=b?.(this.getParams());f&&g.push(f);}return ()=>g.forEach(b=>b?.())}),we(this,"choose",h=>Bv(h).find(p=>{let m=!p.guard;return po(p.guard)?m=!!this.guard(p.guard):Ot(p.guard)&&(m=p.guard(this.getParams())),m})),we(this,"subscribe",h=>(this.subscriptions.push(h),()=>{let p=this.subscriptions.indexOf(h);p>-1&&this.subscriptions.splice(p,1);})),we(this,"status",fo.NotStarted),we(this,"publish",()=>{this.callTrackers(),this.subscriptions.forEach(h=>h(this.service));}),we(this,"trackers",[]),we(this,"setupTrackers",()=>{this.machine.watch?.(this.getParams());}),we(this,"callTrackers",()=>{this.trackers.forEach(({deps:h,fn:p})=>{let m=h.map(g=>g());ho(p.prev,m)||(p(),p.prev=m);});}),we(this,"getParams",()=>({state:this.getState(),context:this.context,event:this.getEvent(),prop:this.prop,send:this.send,action:this.action,guard:this.guard,track:(h,p)=>{p.prev=h.map(m=>m()),this.trackers.push({deps:h,fn:p});},refs:this.refs,computed:this.computed,flush:Yv,scope:this.scope,choose:this.choose})),this.userPropsRef={current:e};let{id:t,ids:n,getRootNode:i}=$s(e);this.scope=Hy({id:t,ids:n,getRootNode:i});let o=h=>{let p=$s(this.userPropsRef.current);return (r.props?.({props:kr(p),scope:this.scope})??p)[h]};this.prop=o;let s=r.context?.({prop:o,bindable:ta,scope:this.scope,flush(h){queueMicrotask(h);},getContext(){return a},getComputed(){return l},getRefs(){return d},getEvent:this.getEvent.bind(this)});s&&Object.values(s).forEach(h=>{let p=sd(h.ref,()=>this.notify());this.cleanups.push(p);});let a={get(h){return s?.[h].get()},set(h,p){s?.[h].set(p);},initial(h){return s?.[h].initial},hash(h){let p=s?.[h].get();return s?.[h].hash(p)}};this.context=a;let l=h=>(Ys(r.computed,()=>"[zag-js] No computed object found on machine"),r.computed[h]({context:a,event:this.getEvent(),prop:o,refs:this.refs,scope:this.scope,computed:l}));this.computed=l;let d=Yy(r.refs?.({prop:o,context:a})??{});this.refs=d;let u=ta(()=>({defaultValue:ip(r,r.initialState({prop:o})),onChange:(h,p)=>{let{exiting:m,entering:g}=ty(this.machine,p,h,this.transition?.reenter);if(m.forEach(b=>{this.effects.get(b.path)?.(),this.effects.delete(b.path);}),m.forEach(b=>{this.action(b.state?.exit);}),this.action(this.transition?.actions),g.forEach(b=>{let f=this.effect(b.state?.effects);if(f){let v=this.effects.get(b.path);this.effects.set(b.path,v?Tr(v,f):f);}}),p===Xs){this.action(r.entry);let b=this.effect(r.effects);if(b){let f=this.effects.get(Xs);this.effects.set(Xs,f?Tr(f,b):b);}}g.forEach(b=>{this.action(b.state?.entry);});}}));this.state=u,this.cleanups.push(sd(this.state.ref,()=>this.notify()));}updateProps(r){let e=this.userPropsRef.current;this.userPropsRef.current=()=>{let t=$s(e),n=$s(r);return Sp(t,n)},this.notify();}start(){this.status=fo.Started,this.debug("initializing..."),this.state.invoke(this.state.initial,Xs),this.setupTrackers();}stop(){this.effects.forEach(r=>r?.()),this.effects.clear(),this.transition=null,this.action(this.machine.exit),this.cleanups.forEach(r=>r()),this.cleanups=[],this.subscriptions=[],this.status=fo.Stopped,this.debug("unmounting...");}get service(){return {state:this.getState(),send:this.send,context:this.context,prop:this.prop,scope:this.scope,refs:this.refs,computed:this.computed,event:this.getEvent(),getStatus:()=>this.status}}};function ad(r,e,t){let n=new Cp(r,e),i=n.subscribe(t);return n.start(),t(n.service),{service:n.service,flush:()=>t(n.service),stop:()=>{i(),n.stop();}}}var MI=0;function ld(r){return `${r}-${++MI}`}function wi(r,e=8){return `${r}::-webkit-scrollbar{width:${e}px;height:${e}px;}${r}::-webkit-scrollbar-thumb{background:var(--vela-scroll);border-radius:4px;border:2px solid transparent;background-clip:padding-box;}${r}::-webkit-scrollbar-track{background:transparent;}${r}::-webkit-scrollbar-button{display:none;width:0;height:0;}`}var Ky="outline:none;transition:border-color .12s ease,box-shadow .12s ease;",Xy="border-color:var(--vela-focus);box-shadow:0 0 0 3px var(--vela-focus-soft);";function xe(r,e,t=document){if(typeof document>"u")return;let n=t instanceof Document?t.head:t;if(t.getElementById?.(r)??n.querySelector(`#${CSS.escape(r)}`))return;let i=document.createElement("style");i.id=r,i.textContent=e,n.appendChild(i);}var EI="vela-ui-tokens",PI=Object.entries(Wc).map(([r,e])=>` ${r}: ${e};`).join(`
3
+ `),s=Math.max(1,...o.map(d=>d.length)),a=Math.max(20,s*i*.6)+16,l=o.length*i*1.4+12;return {x:e.xOf(t.time)-a/2,y:n-l/2,w:a,h:l}}points(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=e.yOf(t.price,this.paneId),o=e.yOf(n.price,this.paneId);return i==null||o==null?null:[[e.xOf(t.time),i],[e.xOf(n.time),o]]}hitTest(e,t,n,i){let o=this.box(n);if(o&&lt(e,t,o.x,o.y,o.x+o.w,o.y+o.h,i))return true;let s=this.points(n);return s!=null&&fe(e,t,s[0][0],s[0][1],s[1][0],s[1][1])<=i}handlePoints(e){let t=this.points(e);return t?[t[0]]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}translateBody(e,t,n){let i=n[0],o=n[1];return !i||!o?n.map(s=>({time:s.time+e,price:s.price+t})):[{time:i.time,price:i.price},{time:o.time+e,price:o.price+t}]}bounds(e){return this.box(e)}priceRange(){let e=this.anchors[0],t=this.anchors[1];return !e||!t?null:{min:Math.min(e.price,t.price),max:Math.max(e.price,t.price)}}schema(){return {fields:[...K,...Ce,...Y],textIsContent:true}}};var xn=class extends Ut{constructor(){super(...arguments);this.type="callout";}};var ti=class extends Ut{constructor(){super(...arguments);this.type="pricenote";}defaultLabel(){return ""}labelText(){let t=this.anchors[0]?.price;return t==null?"0.00":t.toFixed(2)}schema(){return {fields:[...K,...Ce,...Y.filter(t=>t.path!=="text.value")]}}};var ni=class extends Ut{constructor(){super(...arguments);this.type="comment";}defaultLabel(){return c("drawing.comment.placeholder","Comment")}};var ri=class extends Ut{constructor(){super(...arguments);this.type="signpost";}defaultLabel(){return c("drawing.signpost.placeholder","Signpost")}};var Le=class extends Z{hitTest(e,t,n,i){let o=this.geometry(n);return o?this.style.fillColor&&o.fill&&wn(e,t,o.fill)?true:o.segments.some(s=>fe(e,t,s[0],s[1],s[2],s[3])<=i):false}handlePoints(e){let t=[];for(let n of this.anchors){let i=e.yOf(n.price,this.paneId);if(i==null)return [];t.push([e.xOf(n.time),i]);}return t}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.handlePoints(e);if(t.length===0)return null;let n=t.map(a=>a[0]),i=t.map(a=>a[1]),o=Math.min(...n),s=Math.min(...i);return {x:o,y:s,w:Math.max(...n)-o,h:Math.max(...i)-s}}};var Al=class extends Le{constructor(){super(...arguments);this.type="parallelchannel";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"offset",free:"y"}]}}offset(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[2];return !t||!n||!i?0:i.price-(t.price+n.price)/2}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return [];let a=[[t.xOf(n.time),o],[t.xOf(i.time),s]],l=this.anchors[2];if(l){let d=t.yOf(l.price,this.paneId);d!=null&&a.push([t.xOf((n.time+i.time)/2),d]);}return a}timeExtent(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.time,n.time),max:Math.max(t.time,n.time)}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=this.offset(),s=t.xOf(n.time),a=t.xOf(i.time),l=t.yOf(n.price,this.paneId),d=t.yOf(i.price,this.paneId),u=t.yOf(n.price+o,this.paneId),h=t.yOf(i.price+o,this.paneId);return l==null||d==null||u==null||h==null?null:{segments:[[s,l,a,d],[s,u,a,h]],fill:[[s,l],[a,d],[a,h],[s,u]]}}priceRange(){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=this.offset(),o=[t.price,n.price,t.price+i,n.price+i],s=this.anchors[2];return s&&o.push(s.price),{min:Math.min(...o),max:Math.max(...o)}}schema(){return {fields:[...K,...Ce,...Y]}}};var Rl=class extends Le{constructor(){super(...arguments);this.type="disjointchannel";}anchorSchema(){return {min:4,max:4,slots:[{role:"top1",free:"both"},{role:"top2",free:"both"},{role:"bot1",free:"both"},{role:"bot2",free:"both"}]}}seg(t,n,i){let o=this.anchors[t],s=this.anchors[n];if(!o||!s)return null;let a=i.yOf(o.price,this.paneId),l=i.yOf(s.price,this.paneId);return a==null||l==null?null:[i.xOf(o.time),a,i.xOf(s.time),l]}geometry(t){let n=this.seg(0,1,t),i=this.seg(2,3,t),o=[n,i].filter(a=>a!=null);if(o.length===0)return null;let s=n&&i?[[n[0],n[1]],[n[2],n[3]],[i[2],i[3]],[i[0],i[1]]]:null;return {segments:o,fill:s}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Ce,...Y]}}};var Dl=class extends Le{constructor(){super(...arguments);this.type="flattopbottom";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"flat",free:"y"}]}}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return [];let a=[[t.xOf(n.time),o],[t.xOf(i.time),s]],l=this.anchors[2];if(l){let d=t.yOf(l.price,this.paneId);d!=null&&a.push([t.xOf((n.time+i.time)/2),d]);}return a}timeExtent(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.time,n.time),max:Math.max(t.time,n.time)}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.xOf(n.time),s=t.xOf(i.time),a=t.yOf(n.price,this.paneId),l=t.yOf(i.price,this.paneId);if(a==null||l==null)return null;let d=this.anchors[2];if(!d)return {segments:[[o,a,s,l]],fill:null};let u=t.yOf(d.price,this.paneId);return u==null?null:{segments:[[o,a,s,l],[o,u,s,u]],fill:[[o,a],[s,l],[s,u],[o,u]]}}priceRange(){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=[t.price,n.price],o=this.anchors[2];return o&&i.push(o.price),{min:Math.min(...i),max:Math.max(...i)}}schema(){return {fields:[...K,...Ce,...Y]}}};var tL=2;function Ib(){return {midColor:R,midStyle:"solid",upperColor:N,upperStyle:"solid",lowerColor:O,lowerStyle:"solid",upperFill:`${N}26`,lowerFill:`${O}26`,showR2:true}}function Ab(r){let e=r.length;if(e<2)return null;let t=0,n=0,i=0,o=0,s=0;for(let g=0;g<e;g+=1){let b=r[g].close;t+=g,n+=b,i+=g*b,o+=g*g,s+=b*b;}let a=e*o-t*t,l=a===0?0:(e*i-t*n)/a,d=(n-l*t)/e,u=0;for(let g=0;g<e;g+=1){let b=r[g].close-(d+l*g);u+=b*b;}let h=Math.sqrt(u/e),p=Math.sqrt(a*(e*s-n*n)),m=p===0?0:(e*i-t*n)/p;return {t0:r[0].time,t1:r[e-1].time,mid0:d,mid1:d+l*(e-1),dev:tL*h,r2:Math.max(0,Math.min(1,m*m)),n:e}}var Un=class extends Z{constructor(t){super(t);this.type="regressionchannel";this.cachedRange=null;this.reg||(this.reg=Ib());}anchorSchema(){return {min:2,max:2,slots:[{role:"start",free:"x"},{role:"end",free:"x"}]}}fit(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=Math.min(n.time,i.time),s=Math.max(n.time,i.time),a=t.barsInRange?.(o,s)??null,l=a?Ab(a):null;return l&&(this.cachedRange={min:Math.min(l.mid0,l.mid1)-l.dev,max:Math.max(l.mid0,l.mid1)+l.dev}),l}layout(t){let n=this.fit(t);if(!n)return null;let i=t.yOf(n.mid0,this.paneId),o=t.yOf(n.mid1,this.paneId),s=t.yOf(n.mid0+n.dev,this.paneId),a=t.yOf(n.mid1+n.dev,this.paneId),l=t.yOf(n.mid0-n.dev,this.paneId),d=t.yOf(n.mid1-n.dev,this.paneId);return i==null||o==null||s==null||a==null||l==null||d==null?null:{x0:t.xOf(n.t0),x1:t.xOf(n.t1),midY0:i,midY1:o,upperY0:s,upperY1:a,lowerY0:l,lowerY1:d,r2:n.r2,showR2:this.reg.showR2}}band(t){let n=this.layout(t);return n?[[n.x0,n.upperY0],[n.x1,n.upperY1],[n.x1,n.lowerY1],[n.x0,n.lowerY0]]:null}hitTest(t,n,i,o){let s=this.layout(i);if(!s)return false;let a=[[s.x0,s.upperY0],[s.x1,s.upperY1],[s.x1,s.lowerY1],[s.x0,s.lowerY0]];return wn(t,n,a)?true:[[s.x0,s.midY0,s.x1,s.midY1],[s.x0,s.upperY0,s.x1,s.upperY1],[s.x0,s.lowerY0,s.x1,s.lowerY1]].some(d=>fe(t,n,d[0],d[1],d[2],d[3])<=o)}handlePoints(t){let n=this.layout(t);if(n)return [[n.x0,n.midY0],[n.x1,n.midY1]];let i=[];for(let o of this.anchors){let s=t.yOf(o.price,this.paneId);if(s==null)return [];i.push([t.xOf(o.time),s]);}return i}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.band(t);if(!n)return null;let i=n.map(l=>l[0]),o=n.map(l=>l[1]),s=Math.min(...i),a=Math.min(...o);return {x:s,y:a,w:Math.max(...i)-s,h:Math.max(...o)-a}}priceRange(){if(this.cachedRange)return this.cachedRange;let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[{path:"reg.midColor",label:c("drawing.regressionchannel.regMidColor","Midline color"),kind:"color",group:"line"},{path:"reg.midStyle",label:c("drawing.regressionchannel.regMidStyle","Midline style"),kind:"lineStyle",group:"line"},{path:"reg.upperColor",label:c("drawing.regressionchannel.regUpperColor","Upper line color"),kind:"color",group:"line"},{path:"reg.upperStyle",label:c("drawing.regressionchannel.regUpperStyle","Upper line style"),kind:"lineStyle",group:"line"},{path:"reg.lowerColor",label:c("drawing.regressionchannel.regLowerColor","Lower line color"),kind:"color",group:"line"},{path:"reg.lowerStyle",label:c("drawing.regressionchannel.regLowerStyle","Lower line style"),kind:"lineStyle",group:"line"},{path:"reg.upperFill",label:c("drawing.regressionchannel.regUpperFill","Upper fill"),kind:"color",group:"fill"},{path:"reg.lowerFill",label:c("drawing.regressionchannel.regLowerFill","Lower fill"),kind:"color",group:"fill"},{path:"reg.showR2",label:c("drawing.regressionchannel.regShowR2","Show R\xB2"),kind:"boolean",group:"behavior"}]}}writeProps(){return {...this.reg}}readProps(t){this.reg={...Ib(),...t};}};var Rb=`${be}00`;function Db(){return {midColor:be,midStyle:"solid",multiplier:1,upperColor:Rb,upperStyle:"solid",lowerColor:Rb,lowerStyle:"solid",bandFill:`${be}33`}}function Ob(r,e){let t=r.length;if(t<1)return null;let n=0;for(let d of r)n+=d.volume>0?d.volume:0;let i=n>0,o=0,s=0,a=0,l=[];for(let d=0;d<t;d+=1){let u=r[d],h=(u.high+u.low+u.close)/3,p=i?Math.max(0,u.volume):1;o+=p,s+=h*p,a+=h*h*p;let m=o>0?s/o:h,g=o>0?Math.max(0,a/o-m*m):0,b=Math.sqrt(g)*e;l.push({time:u.time,mid:m,upper:m+b,lower:m-b});}return l}var ii=class extends Z{constructor(t){super(t);this.type="anchoredvwap";this.cachedRange=null;this.cachedExtent=null;this.vwap||(this.vwap=Db());}anchorSchema(){return {min:1,max:1,slots:[{role:"anchor",free:"x"}]}}series(t){let n=this.anchors[0];if(!n)return null;let i=t.barsInRange?.(n.time,Number.POSITIVE_INFINITY)??null;if(!i||i.length<1)return null;let o=Ob(i.map(s=>({time:s.time,high:s.high,low:s.low,close:s.close,volume:s.volume??0})),this.vwap.multiplier);if(o&&o.length>0){let s=1/0,a=-1/0;for(let l of o)l.lower<s&&(s=l.lower),l.upper>a&&(a=l.upper);this.cachedRange={min:s,max:a},this.cachedExtent={min:o[0].time,max:o[o.length-1].time};}return o}layout(t){let n=this.series(t);if(!n)return null;let i=[],o=[],s=[];for(let a of n){let l=t.xOf(a.time),d=t.yOf(a.mid,this.paneId),u=t.yOf(a.upper,this.paneId),h=t.yOf(a.lower,this.paneId);d==null||u==null||h==null||(i.push([l,d]),o.push([l,u]),s.push([l,h]));}return i.length>0?{mid:i,upper:o,lower:s}:null}bandPolygon(t){return [...t.upper,...[...t.lower].reverse()]}hitTest(t,n,i,o){let s=this.layout(i);return s?wn(t,n,this.bandPolygon(s))?true:Rh(t,n,s.mid,o)||Rh(t,n,s.upper,o)||Rh(t,n,s.lower,o):false}handlePoints(t){let n=this.layout(t);if(n&&n.mid.length>0)return [n.mid[0]];let i=this.anchors[0];if(!i)return [];let o=t.yOf(i.price,this.paneId);return o==null?[]:[[t.xOf(i.time),o]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.layout(t);if(!n)return null;let i=[...n.upper,...n.lower],o=i.map(d=>d[0]),s=i.map(d=>d[1]),a=Math.min(...o),l=Math.min(...s);return {x:a,y:l,w:Math.max(...o)-a,h:Math.max(...s)-l}}priceRange(){return this.cachedRange}timeExtent(){return this.cachedExtent}schema(){return {fields:[{path:"vwap.midColor",label:c("drawing.anchoredvwap.vwapMidColor","VWAP color"),kind:"color",group:"line"},{path:"vwap.midStyle",label:c("drawing.anchoredvwap.vwapMidStyle","VWAP style"),kind:"lineStyle",group:"line"},{path:"vwap.multiplier",label:c("drawing.anchoredvwap.vwapMultiplier","Band multiplier"),kind:"number",min:.5,max:5,step:.5,group:"behavior"},{path:"vwap.upperColor",label:c("drawing.anchoredvwap.vwapUpperColor","Upper band color"),kind:"color",group:"line"},{path:"vwap.lowerColor",label:c("drawing.anchoredvwap.vwapLowerColor","Lower band color"),kind:"color",group:"line"},{path:"vwap.bandFill",label:c("drawing.anchoredvwap.vwapBandFill","Band fill"),kind:"color",group:"fill"}]}}writeProps(){return {...this.vwap}}readProps(t){this.vwap={...Db(),...t};}};function Rh(r,e,t,n){for(let i=1;i<t.length;i+=1)if(fe(r,e,t[i-1][0],t[i-1][1],t[i][0],t[i][1])<=n)return true;return false}var nL=`${N}66`,rL=`${O}66`,iL=`${N}BF`,oL=`${O}BF`;function Nb(){return {rows:24,valueAreaPct:70,widthPct:35,anchor:"left",upColor:nL,downColor:rL,vaUpColor:iL,vaDownColor:oL,showVah:true,vahColor:R,vahStyle:"solid",showVal:true,valColor:R,valStyle:"solid",showPoc:true,pocColor:void 0,pocStyle:"solid",showDevelopingPoc:false,developingPocColor:xt,developingPocStyle:"dotted",showDevelopingVa:false,developingVaColor:xt,developingVaStyle:"dotted"}}function sL(r,e){return r<0?0:r>=e?e-1:r}function Fb(r,e,t){let n=r.length,i=0,o=0;for(let u=0;u<n;u+=1){let h=r[u].up+r[u].down;i+=h,h>o&&(o=h);}let s=i*Math.min(1,Math.max(0,t)),a=e,l=e,d=o;for(;d<s&&(a>0||l<n-1);){let u=a>0?r[a-1].up+r[a-1].down:-1,h=l<n-1?r[l+1].up+r[l+1].down:-1;h>u?(l+=1,d+=h):(a-=1,d+=u);}return {vaFrom:a,vaTo:l}}function Bb(r,e,t,n){let i=n.volume;if(!(i>0))return;let o=r.length,s=n.close>=n.open?"up":"down",a=new Set;for(let l of [n.open,n.high,n.low,n.close])a.add(sL(Math.floor((l-e)/t),o));for(let l of a)r[l][s]+=i;}function Vb(r){let e=0,t=0;for(let n=0;n<r.length;n+=1){let i=r[n].up+r[n].down;i>e&&(e=i,t=n);}return e>0?{poc:t,maxTotal:e}:null}function Hb(r,e,t){let n=1/0,i=-1/0;for(let m of r)m.volume>0&&(m.low<n&&(n=m.low),m.high>i&&(i=m.high));if(!Number.isFinite(n))return null;let o=i>n?Math.max(1,Math.round(e)):1,s=i>n?(i-n)/o:1,a=Array.from({length:o},(m,g)=>({price:n+g*s,up:0,down:0}));for(let m of r)Bb(a,n,s,m);let l=Vb(a);if(!l)return null;let{poc:d,maxTotal:u}=l,{vaFrom:h,vaTo:p}=Fb(a,d,t);return {rows:a,rowH:s,min:n,maxTotal:u,poc:d,vaFrom:h,vaTo:p}}function _b(r,e,t,n){let i=Hb(r,e,t);if(!i)return null;if(!n||r.length<1)return {profile:i,developingPoc:[],developingVaHigh:[],developingVaLow:[]};let{min:o,rowH:s}=i,a=i.rows.length,l=Array.from({length:a},(p,m)=>({price:o+m*s,up:0,down:0})),d=[],u=[],h=[];for(let p of r){Bb(l,o,s,p);let m=Vb(l);if(!m)continue;let{poc:g}=m,{vaFrom:b,vaTo:f}=Fb(l,g,t);d.push({time:p.time,price:l[g].price+s/2}),u.push({time:p.time,price:l[f].price+s}),h.push({time:p.time,price:l[b].price});}return {profile:i,developingPoc:d,developingVaHigh:u,developingVaLow:h}}var $t=class extends Z{constructor(t){super(t);this.type="fixedrangevp";this.cachedRange=null;this.frvp||(this.frvp=Nb());}anchorSchema(){return {min:2,max:2,slots:[{role:"start",free:"x"},{role:"end",free:"x"}]}}barsInSpan(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=Math.min(n.time,i.time),s=Math.max(n.time,i.time),a=t.barsInRange?.(o,s)??null;return !a||a.length<1?null:a.map(l=>({time:l.time,open:l.open,high:l.high,low:l.low,close:l.close,volume:l.volume??0}))}compute(t){let n=this.barsInSpan(t);if(!n)return null;let i=this.frvp,o=i.showDevelopingPoc||i.showDevelopingVa,s=_b(n,i.rows,i.valueAreaPct/100,o);if(s){let{profile:a}=s;this.cachedRange={min:a.min,max:a.min+a.rowH*a.rows.length};}return s}layout(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=this.compute(t);if(!o)return null;let{profile:s}=o,a=Math.min(n.time,i.time),l=Math.max(n.time,i.time),d=t.xOf(a),u=t.xOf(l),h=Math.abs(u-d),p=Math.max(1,Math.min(100,Math.max(0,this.frvp.widthPct))/100*h),m=this.frvp.anchor==="left",g=m?Math.min(d,u):Math.max(d,u),b=m?1:-1,f=[];for(let C=0;C<=s.rows.length;C+=1){let L=t.yOf(s.min+C*s.rowH,this.paneId);if(L==null)return null;f.push(L);}let v=C=>t.yOf(C,this.paneId),w=s.rows[s.vaTo].price+s.rowH,x=s.rows[s.vaFrom].price,T=s.rows[s.poc].price+s.rowH/2,M=C=>{let L=[];for(let y of C){let E=v(y.price);E!=null&&L.push([t.xOf(y.time),E]);}return L};return {x0:Math.min(d,u),x1:Math.max(d,u),anchorX:g,maxW:p,grow:b,profile:s,yEdges:f,vahY:v(w),valY:v(x),pocY:v(T),developingPoc:M(o.developingPoc),developingVaHigh:M(o.developingVaHigh),developingVaLow:M(o.developingVaLow)}}hitTest(t,n,i,o){let s=this.layout(i);if(!s)return false;let a=s.grow===1?s.anchorX:s.anchorX-s.maxW,l=s.grow===1?s.anchorX+s.maxW:s.anchorX,d=Math.min(s.yEdges[0],s.yEdges[s.yEdges.length-1]),u=Math.max(s.yEdges[0],s.yEdges[s.yEdges.length-1]);if(wn(t,n,[[a,d],[l,d],[l,u],[a,u]]))return true;let h=[[s.x0,s.vahY],[s.x0,s.valY],[s.x0,s.pocY]];for(let[,p]of h)if(p!=null&&fe(t,n,s.x0,p,s.x1,p)<=o)return true;for(let p of [s.developingPoc,s.developingVaHigh,s.developingVaLow])for(let m=1;m<p.length;m+=1)if(fe(t,n,p[m-1][0],p[m-1][1],p[m][0],p[m][1])<=o)return true;return false}handlePoints(t){let n=this.layout(t);if(n&&n.pocY!=null)return [[n.x0,n.pocY],[n.x1,n.pocY]];let i=[];for(let o of this.anchors){let s=t.yOf(o.price,this.paneId);if(s==null)return [];i.push([t.xOf(o.time),s]);}return i}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.layout(t);if(!n)return null;let i=Math.min(n.x0,n.grow===1?n.anchorX:n.anchorX-n.maxW),o=Math.max(n.x1,n.grow===1?n.anchorX+n.maxW:n.anchorX),s=Math.min(n.yEdges[0],n.yEdges[n.yEdges.length-1]),a=Math.max(n.yEdges[0],n.yEdges[n.yEdges.length-1]);return {x:i,y:s,w:o-i,h:a-s}}priceRange(){if(this.cachedRange)return this.cachedRange;let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[{path:"frvp.rows",label:c("drawing.fixedrangevp.frvpRows","Rows"),kind:"number",min:1,max:500,step:1,group:"behavior"},{path:"frvp.valueAreaPct",label:c("drawing.fixedrangevp.frvpValueAreaPct","Value Area"),kind:"number",min:0,max:100,step:1,group:"behavior"},{path:"frvp.widthPct",label:c("drawing.fixedrangevp.frvpWidthPct","Width %"),kind:"number",min:0,max:100,step:1,group:"behavior"},{path:"frvp.anchor",label:c("drawing.fixedrangevp.frvpAnchor","Anchor"),kind:"select",options:[{value:"right",label:c("drawing.fixedrangevp.option.right","Right")},{value:"left",label:c("drawing.fixedrangevp.option.left","Left")}],group:"behavior"},{path:"frvp.upColor",label:c("drawing.fixedrangevp.frvpUpColor","Up Volume"),kind:"color",group:"fill"},{path:"frvp.downColor",label:c("drawing.fixedrangevp.frvpDownColor","Down Volume"),kind:"color",group:"fill"},{path:"frvp.vaUpColor",label:c("drawing.fixedrangevp.frvpVaUpColor","Value Area Up"),kind:"color",group:"fill"},{path:"frvp.vaDownColor",label:c("drawing.fixedrangevp.frvpVaDownColor","Value Area Down"),kind:"color",group:"fill"},{path:"frvp.showVah",label:c("drawing.fixedrangevp.frvpShowVah","VAH"),kind:"boolean",group:"line"},{path:"frvp.vahColor",label:c("drawing.fixedrangevp.frvpVahColor","VAH color"),kind:"color",group:"line"},{path:"frvp.vahStyle",label:c("drawing.fixedrangevp.frvpVahStyle","VAH style"),kind:"lineStyle",options:tt,group:"line"},{path:"frvp.showVal",label:c("drawing.fixedrangevp.frvpShowVal","VAL"),kind:"boolean",group:"line"},{path:"frvp.valColor",label:c("drawing.fixedrangevp.frvpValColor","VAL color"),kind:"color",group:"line"},{path:"frvp.valStyle",label:c("drawing.fixedrangevp.frvpValStyle","VAL style"),kind:"lineStyle",options:tt,group:"line"},{path:"frvp.showPoc",label:c("drawing.fixedrangevp.frvpShowPoc","POC"),kind:"boolean",group:"line"},{path:"frvp.pocColor",label:c("drawing.fixedrangevp.frvpPocColor","POC color"),kind:"color",group:"line"},{path:"frvp.pocStyle",label:c("drawing.fixedrangevp.frvpPocStyle","POC style"),kind:"lineStyle",options:tt,group:"line"},{path:"frvp.showDevelopingPoc",label:c("drawing.fixedrangevp.frvpShowDevelopingPoc","Developing POC"),kind:"boolean",group:"line"},{path:"frvp.developingPocColor",label:c("drawing.fixedrangevp.frvpDevelopingPocColor","Developing POC color"),kind:"color",group:"line"},{path:"frvp.developingPocStyle",label:c("drawing.fixedrangevp.frvpDevelopingPocStyle","Developing POC style"),kind:"lineStyle",options:tt,group:"line"},{path:"frvp.showDevelopingVa",label:c("drawing.fixedrangevp.frvpShowDevelopingVa","Developing VA"),kind:"boolean",group:"line"},{path:"frvp.developingVaColor",label:c("drawing.fixedrangevp.frvpDevelopingVaColor","Developing VA color"),kind:"color",group:"line"},{path:"frvp.developingVaStyle",label:c("drawing.fixedrangevp.frvpDevelopingVaStyle","Developing VA style"),kind:"lineStyle",options:tt,group:"line"}]}}writeProps(){return {...this.frvp}}readProps(t){this.frvp={...Nb(),...t};}};var Ol=class extends Le{constructor(){super(...arguments);this.type="pitchfork";}anchorSchema(){return {min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=f=>{let v=t.yOf(f.price,this.paneId);return v==null?null:[t.xOf(f.time),v]},s=o(n),a=o(i);if(!s||!a)return null;let l=this.anchors[2];if(!l)return {segments:[[s[0],s[1],a[0],a[1]]],fill:null};let d=o(l);if(!d)return null;let u=(a[0]+d[0])/2,h=(a[1]+d[1])/2,p=u-s[0],m=h-s[1],g=t.width,b=t.height;return {segments:[Oe(s[0],s[1],u,h,"right",g,b),Oe(a[0],a[1],a[0]+p,a[1]+m,"right",g,b),Oe(d[0],d[1],d[0]+p,d[1]+m,"right",g,b),[a[0],a[1],d[0],d[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Y]}}};var Zi=class extends Le{anchorSchema(){return {min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=f=>{let v=e.yOf(f.price,this.paneId);return v==null?null:[e.xOf(f.time),v]},o=i(t),s=i(n);if(!o||!s)return null;let a=this.anchors[2];if(!a)return {segments:[[o[0],o[1],s[0],s[1]]],fill:null};let l=i(this.medianStart(t,n,a)),d=i(a);if(!l||!d)return null;let u=(s[0]+d[0])/2,h=(s[1]+d[1])/2,p=u-l[0],m=h-l[1],g=e.width,b=e.height;return {segments:[Oe(l[0],l[1],u,h,"right",g,b),Oe(s[0],s[1],s[0]+p,s[1]+m,"right",g,b),Oe(d[0],d[1],d[0]+p,d[1]+m,"right",g,b),[s[0],s[1],d[0],d[1]],[o[0],o[1],s[0],s[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let e=this.anchors.map(t=>t.price);return {min:Math.min(...e),max:Math.max(...e)}}schema(){return {fields:[...K,...Y]}}};var Nl=class extends Zi{constructor(){super(...arguments);this.type="schiffpitchfork";}medianStart(t,n){return {time:t.time,price:(t.price+n.price)/2}}};var Fl=class extends Zi{constructor(){super(...arguments);this.type="modifiedschiffpitchfork";}medianStart(t,n){return {time:(t.time+n.time)/2,price:(t.price+n.price)/2}}};var Bl=class extends Le{constructor(){super(...arguments);this.type="insidepitchfork";}anchorSchema(){return {min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=v=>{let w=t.yOf(v.price,this.paneId);return w==null?null:[t.xOf(v.time),w]},s=o(n),a=o(i);if(!s||!a)return null;let l=this.anchors[2];if(!l)return {segments:[[s[0],s[1],a[0],a[1]]],fill:null};let d=o({time:(n.time+i.time)/2,price:(n.price+i.price)/2}),u=o(l);if(!d||!u)return null;let h=(a[0]+u[0])/2,p=(a[1]+u[1])/2,m=u[0]-d[0],g=u[1]-d[1],b=t.width,f=t.height;return {segments:[Oe(h,p,h+m,p+g,"right",b,f),Oe(a[0],a[1],a[0]+m,a[1]+g,"right",b,f),Oe(u[0],u[1],u[0]+m,u[1]+g,"right",b,f),[a[0],a[1],u[0],u[1]],[d[0],d[1],u[0],u[1]],[s[0],s[1],a[0],a[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Y]}}};var Vl=class extends Z{constructor(){super(...arguments);this.type="arrow";}anchorSchema(){return {min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?null:[t.xOf(n.time),o,t.xOf(i.time),s]}hitTest(t,n,i,o){let s=this.pixels(i);return s!=null&&fe(t,n,s[0],s[1],s[2],s[3])<=o}handlePoints(t){let n=this.pixels(t);return n?[[n[0],n[1]],[n[2],n[3]]]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.pixels(t);return n?{x:Math.min(n[0],n[2]),y:Math.min(n[1],n[3]),w:Math.abs(n[2]-n[0]),h:Math.abs(n[3]-n[1])}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,{path:"style.arrowRight",label:c("drawing.arrow.arrowRight","Head (end)"),kind:"boolean",group:"line"},{path:"style.arrowLeft",label:c("drawing.arrow.arrowLeft","Head (start)"),kind:"boolean",group:"line"},...Y]}}};var zb=48,Hl=class extends Z{constructor(){super(...arguments);this.type="ellipse";}anchorSchema(){return {min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}oval(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time);return {cx:(a+l)/2,cy:(o+s)/2,rx:Math.abs(l-a)/2,ry:Math.abs(s-o)/2}}perimeter(t){let n=[];for(let i=0;i<=zb;i+=1){let o=i/zb*Math.PI*2;n.push([t.cx+t.rx*Math.cos(o),t.cy+t.ry*Math.sin(o)]);}return n}hitTest(t,n,i,o){let s=this.oval(i);if(!s||s.rx<1||s.ry<1)return false;let a=((t-s.cx)/s.rx)**2+((n-s.cy)/s.ry)**2;return this.style.fillColor&&a<=1?true:qi(t,n,this.perimeter(s))<=o}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?[]:[[t.xOf(n.time),o],[t.xOf(i.time),s]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.oval(t);return n?{x:n.cx-n.rx,y:n.cy-n.ry,w:n.rx*2,h:n.ry*2}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,...Ce,...Y]}}};var _l=class extends Le{constructor(){super(...arguments);this.type="triangle";}anchorSchema(){return {min:3,max:3,slots:[{role:"v1",free:"both"},{role:"v2",free:"both"},{role:"v3",free:"both"}]}}geometry(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=u=>{let h=t.yOf(u.price,this.paneId);return h==null?null:[t.xOf(u.time),h]},s=o(n),a=o(i);if(!s||!a)return null;let l=this.anchors[2];if(!l)return {segments:[[s[0],s[1],a[0],a[1]]],fill:null};let d=o(l);return d?{segments:[[s[0],s[1],a[0],a[1]],[a[0],a[1],d[0],d[1]],[d[0],d[1],s[0],s[1]]],fill:[s,a,d]}:null}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Ce,...Y]}}};var aL=512,yr=class extends Le{anchorSchema(){return {min:2,max:aL,slots:[]}}geometry(e){let t=[];for(let i of this.anchors){let o=e.yOf(i.price,this.paneId);if(o==null)return null;t.push([e.xOf(i.time),o]);}if(t.length<2)return null;let n=[];for(let i=1;i<t.length;i+=1)n.push([t[i-1][0],t[i-1][1],t[i][0],t[i][1]]);return {segments:n,fill:null}}priceRange(){if(this.anchors.length===0)return null;let e=this.anchors.map(t=>t.price);return {min:Math.min(...e),max:Math.max(...e)}}schema(){return {fields:[...K,...Y]}}};var zl=class extends yr{constructor(){super(...arguments);this.type="polyline";}};var ms=class extends yr{placementMode(){return "freehand"}handlePoints(e){return []}bounds(e){let t=[],n=[];for(let s of this.anchors){let a=e.yOf(s.price,this.paneId);a!=null&&(t.push(e.xOf(s.time)),n.push(a));}if(t.length===0)return null;let i=Math.min(...t),o=Math.min(...n);return {x:i,y:o,w:Math.max(...t)-i,h:Math.max(...n)-o}}},Wl=class extends ms{constructor(){super(...arguments);this.type="freehand";}};var lL=[{path:"style.lineColor",label:c("drawing.highlighter.lineColor","Color"),kind:"color",group:"line"},{path:"style.lineWidth",label:c("drawing.highlighter.lineWidth","Width"),kind:"number",min:4,max:60,step:1,group:"line"}],Gl=class extends ms{constructor(){super(...arguments);this.type="highlighter";}schema(){return {fields:lL}}};var Ul=class extends Z{constructor(){super(...arguments);this.type="circle";}anchorSchema(){return {min:2,max:2,slots:[{role:"center",free:"both"},{role:"edge",free:"both"}]}}geom(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time);return {cx:a,cy:o,r:Math.hypot(l-a,s-o)}}hitTest(t,n,i,o){let s=this.geom(i);if(!s||s.r<1)return false;let a=Math.hypot(t-s.cx,n-s.cy);return this.style.fillColor&&a<=s.r?true:Math.abs(a-s.r)<=o}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?[]:[[t.xOf(n.time),o],[t.xOf(i.time),s]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.geom(t);return n?{x:n.cx-n.r,y:n.cy-n.r,w:n.r*2,h:n.r*2}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,...Ce,...Y]}}};var $l=class extends Le{constructor(){super(...arguments);this.type="rotatedrect";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"w",free:"both"}]}}px(t,n){let i=this.anchors[n];if(!i)return null;let o=t.yOf(i.price,this.paneId);return o==null?null:[t.xOf(i.time),o]}geometry(t){let n=this.px(t,0),i=this.px(t,1);if(!n||!i)return null;let o=this.px(t,2);if(!o||this.anchors.length<3)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let s=i[0]-n[0],a=i[1]-n[1],l=Math.hypot(s,a);if(l<1e-6)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let d=-a/l,u=s/l,h=(o[0]-n[0])*d+(o[1]-n[1])*u,p=d*h,m=u*h,g=n,b=i,f=[i[0]+p,i[1]+m],v=[n[0]+p,n[1]+m];return {segments:[[g[0],g[1],b[0],b[1]],[b[0],b[1],f[0],f[1]],[f[0],f[1],v[0],v[1]],[v[0],v[1],g[0],g[1]]],fill:[g,b,f,v]}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...fr,...Ce,...Y]}}};var Yl=class extends yr{constructor(){super(...arguments);this.type="path";}};var Wb=40,Kl=class extends Le{constructor(){super(...arguments);this.type="arc";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"apex",free:"both"}]}}pinApex(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[2];t&&n&&i&&(i.time=(t.time+n.time)/2);}onPlaced(){this.pinApex();}constrainHandleDrag(){this.pinApex();}px(t,n){let i=this.anchors[n];if(!i)return null;let o=t.yOf(i.price,this.paneId);return o==null?null:[t.xOf(i.time),o]}geometry(t){let n=this.px(t,0),i=this.px(t,1);if(!n||!i)return null;let o=this.anchors[2];if(!o||this.anchors.length<3)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let s=t.yOf(o.price,this.paneId);if(s==null)return null;let a=(n[0]+i[0])/2,l=(n[1]+i[1])/2,d=(i[0]-n[0])/2,u=(i[1]-n[1])/2,h=Math.hypot(d,u);if(h<1e-6)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let p=-u/h,m=d/h,g=(s-l)*m;g<0&&(p=-p,m=-m);let b=Math.abs(g),f=[];for(let w=0;w<=Wb;w+=1){let x=w/Wb*Math.PI,T=Math.cos(x),M=Math.sin(x);f.push([a+T*d+M*b*p,l+T*u+M*b*m]);}let v=[];for(let w=1;w<f.length;w+=1)v.push([f[w-1][0],f[w-1][1],f[w][0],f[w][1]]);return v.push([f[f.length-1][0],f[f.length-1][1],f[0][0],f[0][1]]),{segments:v,fill:f}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...fr,...Ce,...Y]}}};var Gb=40,Xl=class extends Le{constructor(){super(...arguments);this.type="curve";}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"control",free:"both"}]}}px(t,n){let i=this.anchors[n];if(!i)return null;let o=t.yOf(i.price,this.paneId);return o==null?null:[t.xOf(i.time),o]}geometry(t){let n=this.px(t,0),i=this.px(t,1);if(!n||!i)return null;let o=this.px(t,2);if(!o||this.anchors.length<3)return {segments:[[n[0],n[1],i[0],i[1]]],fill:null};let s=[];for(let l=0;l<=Gb;l+=1){let d=l/Gb,u=1-d;s.push([u*u*n[0]+2*u*d*o[0]+d*d*i[0],u*u*n[1]+2*u*d*o[1]+d*d*i[1]]);}let a=[];for(let l=1;l<s.length;l+=1)a.push([s[l-1][0],s[l-1][1],s[l][0],s[l][1]]);return {segments:a,fill:s}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(n=>n.price);return {min:Math.min(...t),max:Math.max(...t)}}schema(){return {fields:[...K,...Ce,...Y]}}};var cL={head:11,headW:9,stemW:3.5,len:22},wr=class extends Z{anchorSchema(){return {min:1,max:1,slots:[{role:"p",free:"both"}]}}glyphPoints(e){let t=this.anchors[0];if(!t)return null;let n=e.yOf(t.price,this.paneId);if(n==null)return null;let i=e.xOf(t.time),{head:o,headW:s,stemW:a,len:l}=cL,d=[[0,0],[-s,o],[-a,o],[-a,l],[a,l],[a,o],[s,o]],u=this.dir(),h=([p,m])=>{switch(u){case "up":return [p,m];case "down":return [p,-m];case "left":return [m,p];default:return [-m,p]}};return d.map(p=>{let[m,g]=h(p);return [i+m,n+g]})}hitTest(e,t,n,i){let o=this.glyphPoints(n);return o!=null&&wn(e,t,o)}handlePoints(e){let t=this.anchors[0];if(!t)return [];let n=e.yOf(t.price,this.paneId);return n==null?[]:[[e.xOf(t.time),n]]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.glyphPoints(e);if(!t)return null;let n=t.map(a=>a[0]),i=t.map(a=>a[1]),o=Math.min(...n),s=Math.min(...i);return {x:o,y:s,w:Math.max(...n)-o,h:Math.max(...i)-s}}priceRange(){let e=this.anchors[0];return e?{min:e.price,max:e.price}:null}schema(){return {fields:[{path:"style.lineColor",label:c("drawing.arrowmarkup.lineColor","Color"),kind:"color",group:"line"},...Y]}}},gs=class extends wr{constructor(){super(...arguments);this.type="arrowmarkup";}dir(){return "up"}},fs=class extends wr{constructor(){super(...arguments);this.type="arrowmarkdown";}dir(){return "down"}};var ys=["\u2605","\u2606","\u25CF","\u25C6","\u25B2","\u25BC","\u27A4","\u2691","\u271A","\u2715","\u2764","\u2666"],jl=["small","normal","large","huge"],Ub={small:16,normal:22,large:32,huge:44},oi=class extends Z{constructor(e){super(e),this.glyph||(this.glyph=this.defaultGlyph()),this.size||(this.size="normal");}sizePx(){return Ub[this.size]??Ub.normal}anchorSchema(){return {min:1,max:1,slots:[{role:"p",free:"both"}]}}center(e){let t=this.anchors[0];if(!t)return null;let n=e.yOf(t.price,this.paneId);return n==null?null:[e.xOf(t.time),n]}hitTest(e,t,n,i){let o=this.center(n);if(!o)return false;let s=this.sizePx()/2+i;return Math.abs(e-o[0])<=s&&Math.abs(t-o[1])<=s}handlePoints(e){let t=this.center(e);return t?[t]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.center(e);if(!t)return null;let n=this.sizePx();return {x:t[0]-n/2,y:t[1]-n/2,w:n,h:n}}priceRange(){let e=this.anchors[0];return e?{min:e.price,max:e.price}:null}schema(){return {fields:[{path:"glyph",label:c("drawing.flagmark.glyph","Icon"),kind:"select",options:ys.map(e=>({value:e,label:e})),group:"line"},{path:"size",label:c("drawing.flagmark.size","Size"),kind:"select",options:jl.map(e=>({value:e,label:e})),group:"line"},{path:"style.lineColor",label:c("drawing.flagmark.lineColor","Color"),kind:"color",group:"line"},...Y]}}writeProps(){return {glyph:this.glyph,size:this.size}}readProps(e){typeof e.glyph=="string"&&(this.glyph=e.glyph),typeof e.size=="string"&&(this.size=e.size);}},bs=class extends oi{constructor(){super(...arguments);this.type="flagmark";}defaultGlyph(){return "\u2691"}},vs=class extends oi{constructor(){super(...arguments);this.type="iconstamp";}defaultGlyph(){return "\u2605"}};var $b=r=>r==="small"||r==="normal"||r==="large"||r==="huge";function dL(r){if(!r||typeof r!="object")return null;let e=r;return typeof e.ratio!="number"||typeof e.color!="string"?null:{ratio:e.ratio,color:e.color,enabled:e.enabled!==false,...typeof e.label=="string"&&e.label?{label:e.label}:{}}}var Pe=class extends Z{constructor(e){super(e),this.levels||(this.levels=this.defaultLevels().map(t=>({...t}))),this.numbersSize||(this.numbersSize="small"),this.labelsSize||(this.labelsSize="normal");}fillBands(e){return []}editableLevels(){return this.levels}anchorSchema(){return {min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}hitTest(e,t,n,i){let o=this.entryLines(n);return o!=null&&o.some(s=>fe(e,t,s.x1,s.y1,s.x2,s.y2)<=i)}handlePoints(e){let t=[];for(let n of this.anchors){let i=e.yOf(n.price,this.paneId);if(i==null)return [];t.push([e.xOf(n.time),i]);}return t}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.handlePoints(e);if(t.length===0)return null;let n=t.map(a=>a[0]),i=t.map(a=>a[1]),o=Math.min(...n),s=Math.min(...i);return {x:o,y:s,w:Math.max(...n)-o,h:Math.max(...i)-s}}schema(){return {fields:K.filter(e=>e.path!=="style.lineColor")}}writeProps(){return {levels:this.levels.map(e=>({...e})),numbersSize:this.numbersSize,labelsSize:this.labelsSize}}readProps(e){if(Array.isArray(e.levels)){let t=e.levels.map(dL).filter(n=>n!=null);t.length&&(this.levels=t);}$b(e.numbersSize)&&(this.numbersSize=e.numbersSize),$b(e.labelsSize)&&(this.labelsSize=e.labelsSize);}};var Sn=class extends Pe{constructor(e){super(e),this.showRatios===void 0&&(this.showRatios=true),this.showPrices===void 0&&(this.showPrices=true),this.labelSide===void 0&&(this.labelSide="left"),this.background===void 0&&(this.background=true);}levelPrice(e,t,n){return t+e*(n-t)}levelLines(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=e.xOf(t.time),o=e.xOf(n.time),s=this.style.extendLeft?0:Math.min(i,o),a=this.style.extendRight?e.width:Math.max(i,o),l=[];for(let d of this.levels){if(!d.enabled)continue;let u=this.levelPrice(d.ratio,t.price,n.price),h=e.yOf(u,this.paneId);h!=null&&l.push({ratio:d.ratio,color:d.color,label:d.label,price:u,x1:s,x2:a,y:h});}return l}entryLines(e){let t=this.levelLines(e);if(!t)return null;let n=this.labelSide==="right";return t.map(i=>({color:i.color,label:i.label,x1:i.x1,y1:i.y,x2:i.x2,y2:i.y,numberText:this.levelText(i.ratio,i.price),numberX:n?i.x2-4:i.x1+4,numberY:i.y-7,numberAlign:n?"right":"left",labelX:(i.x1+i.x2)/2,labelY:i.y-7}))}levelText(e,t){let n=t.toFixed(2);return this.showRatios&&this.showPrices?`${e} (${n})`:this.showRatios?String(e):this.showPrices?n:""}fillBands(e){if(!this.background)return [];let t=this.levelLines(e)?.sort((i,o)=>i.ratio-o.ratio);if(!t)return [];let n=[];for(let i=1;i<t.length;i+=1){let o=t[i-1],s=t[i];n.push({color:s.color,x:o.x1,y:Math.min(o.y,s.y),w:o.x2-o.x1,h:Math.abs(s.y-o.y)});}return n}priceRange(){let e=this.anchors[0],t=this.anchors[1];if(!e||!t)return null;let n=this.levels.filter(i=>i.enabled).map(i=>this.levelPrice(i.ratio,e.price,t.price));return n.length===0?null:{min:Math.min(...n),max:Math.max(...n)}}schema(){return {fields:[...super.schema().fields,{path:"style.extendLeft",label:c("drawing.field.extendLeft","Extend left"),kind:"boolean",group:"line"},{path:"style.extendRight",label:c("drawing.field.extendRight","Extend right"),kind:"boolean",group:"line"}]}}writeProps(){return {...super.writeProps(),showRatios:this.showRatios,showPrices:this.showPrices,labelSide:this.labelSide,background:this.background}}readProps(e){super.readProps(e),typeof e.showRatios=="boolean"&&(this.showRatios=e.showRatios),typeof e.showPrices=="boolean"&&(this.showPrices=e.showPrices),(e.labelSide==="left"||e.labelSide==="right")&&(this.labelSide=e.labelSide),typeof e.background=="boolean"&&(this.background=e.background);}};var si=R,Cn=O,Tn=q,ai="#4caf50",xr=N,on=be,kn="#9c27b0",ql="#e91e63",ws="#26a69a",Dh="#ab47bc",Yb="#ef5350",Ji="#ffb74d",Oh="#38c0fd",Zl="#b2b5be",Qi=[Oh,on,xr,ai,Tn,Cn,ql,kn,si,ws,Dh,Yb];function Kb(r){return Qi[(r%Qi.length+Qi.length)%Qi.length]}var uL=[[0,si],[.125,Cn],[.236,Cn],[.25,Cn],[.382,Tn],[.5,ai],[.618,xr],[.75,on],[.786,on],[1,si],[.705,Ji],[.886,kn],[1.272,on],[1.382,Tn],[1.414,ws],[1.618,Cn],[2,si],[2.272,Dh],[2.382,Tn],[2.414,ql],[2.618,Tn],[3,si],[3.272,Yb],[3.618,kn],[4.236,ai],[4.618,ql],[-0.27,Oh],[-0.272,Oh],[-0.62,on],[-0.618,on],[-1,ws],[-1.5,Dh],[-2,kn],[-2.5,ql],[6.854,xr],[11.09,on]];function hL(r,e=0){return uL.find(([t])=>t===r)?.[1]??Kb(e)}function De(r){return r.map((e,t)=>{let n=typeof e=="number"?{ratio:e}:e;return {ratio:n.ratio,color:n.color??hL(n.ratio,t),enabled:n.enabled!==false,...n.label?{label:n.label}:{}}})}function Xb(r,e=r){return Array.from({length:r},(t,n)=>({ratio:n+1,color:Kb(n),enabled:n<e,label:String(n+1)}))}var jb=[0,.236,.382,.5,.618,.705,.786,.886,1,1.272,1.414,1.618,2,2.272,2.414,2.618,3,3.272,3.618,4.236,4.618,-0.272,-0.618,-1],pL=[0,.236,.382,.5,.62,.705,.79,.886,1,1.272,1.414,1.618,2,2.618,3,3.618,4.236,4.618,-0.27,-0.62,-1,-1.5,-2,-2.5];function xs(r,e,t={}){return De(r.map(n=>({ratio:n,enabled:e.includes(n),color:t[String(n)]})))}var li=[{key:"classic",label:c("drawing.fibPreset.classic","Classic"),reverse:false,levels:xs(jb,[0,.236,.382,.5,.618,.786,1])},{key:"extension",label:c("drawing.fibPreset.extension","Extension"),reverse:true,levels:xs(jb,[0,1,1.272,1.414,1.618,2,2.618,3.618,4.236])},{key:"ote",label:c("drawing.fibPreset.ote","OTE"),reverse:false,levels:xs(pL,[0,.5,.62,.705,.79,1,-0.27,-0.62],{"0.62":Ji,"0.79":Ji})}];function Nh(r,e){let t=i=>JSON.stringify(i.map(o=>[o.ratio,o.color,o.enabled,o.label??""])),n=t(r);return li.find(i=>i.reverse===e&&t(i.levels)===n)?.key??null}var mL=li[0].levels,Sr=class extends Sn{constructor(t){super(t);this.type="fibretracement";this.reverse===void 0&&(this.reverse=false);}defaultLevels(){return mL}levelPrice(t,n,i){return this.reverse?n+t*(i-n):i+t*(n-i)}writeProps(){return {...super.writeProps(),reverse:this.reverse}}readProps(t){super.readProps(t),this.reverse=typeof t.reverse=="boolean"?t.reverse:true;}};var gL=xs([0,.236,.382,.5,.618,.786,1,1.272,1.414,1.618,2,2.272,2.414,2.618,3,3.272,3.618,4.236,4.618],[0,.382,.618,1,1.272,1.618,2.618],{"2.618":kn}),Ql=class extends Sn{constructor(){super(...arguments);this.type="fibextension";}defaultLevels(){return gL}};var fL=De([0,.382,.5,.618,1,1.618,{ratio:2.618,color:kn}]),Jl=class extends Pe{constructor(){super(...arguments);this.type="fibextensiontrend";}anchorSchema(){return {min:3,max:3,slots:[{role:"a",free:"both"},{role:"b",free:"both"},{role:"c",free:"both"}]}}defaultLevels(){return fL}entryLines(t){let n=this.anchors[0],i=this.anchors[1],o=this.anchors[2];if(!n||!i||!o)return null;let s=i.price-n.price,a=[t.xOf(n.time),t.xOf(i.time),t.xOf(o.time)],l=Math.min(...a),d=Math.max(...a),u=[];for(let h of this.levels){if(!h.enabled)continue;let p=o.price+h.ratio*s,m=t.yOf(p,this.paneId);m!=null&&u.push({color:h.color,label:h.label,x1:l,y1:m,x2:d,y2:m,numberText:`${h.ratio} (${p.toFixed(2)})`,numberX:l+4,numberY:m-7,numberAlign:"left",labelX:(l+d)/2,labelY:m-7});}return u}priceRange(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[2];if(!t||!n||!i)return null;let o=n.price-t.price,s=this.levels.filter(a=>a.enabled).map(a=>i.price+a.ratio*o);return s.push(t.price,n.price,i.price),{min:Math.min(...s),max:Math.max(...s)}}};var bL=De([.236,.382,.5,.618,.786,1]),ec=class extends Pe{constructor(){super(...arguments);this.type="fibfan";}defaultLevels(){return bL}fanLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.xOf(n.time),s=t.yOf(n.price,this.paneId);if(s==null)return null;let a=t.xOf(i.time),l=i.price-n.price,d=[];for(let u of this.levels){if(!u.enabled)continue;let h=t.yOf(n.price+u.ratio*l,this.paneId);if(h==null)continue;let[p,m,g,b]=Oe(o,s,a,h,"right",t.width,t.height);d.push({ratio:u.ratio,color:u.color,label:u.label,x1:p,y1:m,x2:g,y2:b,labelX:a+5,labelY:h});}return d}entryLines(t){let n=this.fanLines(t);return n?n.map(i=>({color:i.color,label:i.label,x1:i.x1,y1:i.y1,x2:i.x2,y2:i.y2,numberText:String(i.ratio),numberX:i.labelX,numberY:i.labelY,numberAlign:"left",labelX:i.labelX,labelY:i.labelY+13})):null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var vL=[0,1,2,3,5,8,13,21,34].map(r=>({ratio:r,color:H,enabled:true})),tc=class extends Pe{constructor(){super(...arguments);this.type="fibtimezones";}defaultLevels(){return vL}zoneLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=i.time-n.time;if(Math.abs(o)<1e-9)return null;let s=[];for(let a of this.levels)a.enabled&&s.push({n:a.ratio,color:a.color,label:a.label,x:t.xOf(n.time+a.ratio*o)});return s}entryLines(t){let n=this.zoneLines(t);if(!n)return null;let i=t.height;return n.map(o=>({color:o.color,label:o.label,x1:o.x,y1:0,x2:o.x,y2:i,numberText:String(o.n),numberX:o.x,numberY:9,numberAlign:"center",labelX:o.x,labelY:24}))}priceRange(){return null}timeExtent(){return null}};var yL=De([0,.236,.382,.5,.618,.786,1,1.618,2.618]),nc=class extends Pe{constructor(){super(...arguments);this.type="fibchannel";}defaultLevels(){return yL}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"offset",free:"both"}]}}entryLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time),d=0,u=0,h=this.anchors[2];if(h){let m=t.yOf(h.price,this.paneId);if(m==null)return null;d=t.xOf(h.time)-a,u=m-o;}let p=[];for(let m of this.levels){if(!m.enabled)continue;let g=m.ratio*d,b=m.ratio*u,f=l+g,v=s+b;p.push({color:m.color,label:m.label,x1:a+g,y1:o+b,x2:f,y2:v,numberText:String(m.ratio),numberX:f+5,numberY:v,numberAlign:"left",labelX:f+5,labelY:v+13});}return p}priceRange(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[2];if(!t||!n)return null;let o=i?i.price-t.price:0,s=1/0,a=-1/0;for(let l of this.levels)if(l.enabled)for(let d of [t.price,n.price]){let u=d+l.ratio*o;u<s&&(s=u),u>a&&(a=u);}return s<=a?{min:s,max:a}:null}};var wL=De([0,.236,.382,.5,.618,.786,1]),rc=class extends Pe{constructor(){super(...arguments);this.type="fibspeedfan";}defaultLevels(){return wL}entryLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),d=t.xOf(i.time)-a,u=s-o,h=d>=0?"right":"left",p=t.width,m=t.height,g=[];for(let b of this.levels){if(!b.enabled)continue;let f=a+d,v=o+u*b.ratio,w=Oe(a,o,f,v,h,p,m);if(g.push({color:b.color,label:b.label,x1:w[0],y1:w[1],x2:w[2],y2:w[3],numberText:String(b.ratio),numberX:h==="right"?f+5:f-5,numberY:v,numberAlign:h==="right"?"left":"right",labelX:f,labelY:v}),b.ratio===1)continue;let x=a+d*b.ratio,T=o+u,M=Oe(a,o,x,T,h,p,m);g.push({color:b.color,label:b.label,x1:M[0],y1:M[1],x2:M[2],y2:M[3],numberText:String(b.ratio),numberX:x,numberY:T+(u>=0?12:-12),numberAlign:"center",labelX:x,labelY:T+12});}return g}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var xL=De([0,.382,{ratio:.5,enabled:false},.618,1,1.382,1.618,2,2.382,2.618,3]),ic=class extends Pe{constructor(){super(...arguments);this.type="trendfibtime";}defaultLevels(){return xL}anchorSchema(){return {min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"p3",free:"both"}]}}entryLines(t){let n=this.anchors[0],i=this.anchors[1],o=this.anchors[2];if(!n||!i||!o)return null;let s=i.time-n.time;if(Math.abs(s)<1e-9)return null;let a=t.height,l=[];for(let d of this.levels){if(!d.enabled)continue;let u=t.xOf(o.time+d.ratio*s);l.push({color:d.color,label:d.label,x1:u,y1:0,x2:u,y2:a,numberText:String(d.ratio),numberX:u,numberY:9,numberAlign:"center",labelX:u,labelY:24});}return l}priceRange(){return null}timeExtent(){return null}};function SL(r,e,t){if(t-e>=Math.PI*2-.001)return true;let n=r-e,i=Math.PI*2;for(;n<0;)n+=i;for(;n>=i;)n-=i;return n<=t-e+1e-6}var sn=class extends Pe{boundingLines(e){return []}entryLines(e){return []}hitTest(e,t,n,i){let o=this.radial(n);if(o){let s=Math.hypot(e-o.cx,t-o.cy),a=Math.atan2(t-o.cy,e-o.cx);if(SL(a,o.a0,o.a1)){for(let l of this.levels)if(l.enabled&&Math.abs(s-o.R0*l.ratio)<=i)return true}}return this.boundingLines(n).some(s=>fe(e,t,s[0],s[1],s[2],s[3])<=i)}priceRange(){if(this.anchors.length===0)return null;let e=this.anchors.map(t=>t.price);return {min:Math.min(...e),max:Math.max(...e)}}};var CL=De([.236,.382,.5,.618,.786,1,1.618,2.618]),oc=class extends sn{constructor(){super(...arguments);this.type="fibcircles";}defaultLevels(){return CL}radial(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time);return {cx:a,cy:o,R0:Math.hypot(l-a,s-o),a0:0,a1:Math.PI*2}}};var TL=De([.236,.382,.5,.618,.786,1,1.618,2.618]),sc=class extends sn{constructor(){super(...arguments);this.type="fibarcs";}defaultLevels(){return TL}pts(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?null:{cx:t.xOf(n.time),cy:o,ex:t.xOf(i.time),ey:s}}radial(t){let n=this.pts(t);if(!n)return null;let i=Math.hypot(n.ex-n.cx,n.ey-n.cy),o=Math.atan2(n.ey-n.cy,n.ex-n.cx);return {cx:n.cx,cy:n.cy,R0:i,a0:o-Math.PI/2,a1:o+Math.PI/2}}boundingLines(t){let n=this.pts(t);return n?[[n.cx,n.cy,n.ex,n.ey]]:[]}};var kL=De([.236,.382,.5,.618,.786,1]),ac=class extends sn{constructor(){super(...arguments);this.type="fibwedge";}defaultLevels(){return kL}anchorSchema(){return {min:3,max:3,slots:[{role:"apex",free:"both"},{role:"radius",free:"both"},{role:"angle",free:"both"}]}}px(t,n){let i=this.anchors[n];if(!i)return null;let o=t.yOf(i.price,this.paneId);return o==null?null:[t.xOf(i.time),o]}radial(t){let n=this.px(t,0),i=this.px(t,1),o=this.px(t,2);if(!n||!i||!o)return null;let s=Math.hypot(i[0]-n[0],i[1]-n[1]);if(s<1)return null;let a=Math.atan2(i[1]-n[1],i[0]-n[0]),l=Math.atan2(o[1]-n[1],o[0]-n[0]),d=Math.min(a,l),u=Math.max(a,l);return u-d>Math.PI&&([d,u]=[u,d+Math.PI*2]),{cx:n[0],cy:n[1],R0:s,a0:d,a1:u}}boundingLines(t){let n=this.px(t,0),i=this.px(t,1);if(!n||!i)return [];let o=[[n[0],n[1],i[0],i[1]]],s=this.px(t,2);if(s){let a=Math.hypot(i[0]-n[0],i[1]-n[1]),l=Math.hypot(s[0]-n[0],s[1]-n[1]);l>1e-6&&o.push([n[0],n[1],n[0]+(s[0]-n[0])/l*a,n[1]+(s[1]-n[1])/l*a]);}return o}};var LL=1.6180339887,qb=Math.log(LL)/(Math.PI/2),ML=Math.PI/64,EL=Math.PI,PL=.5,ci=class extends Z{constructor(){super(...arguments);this.type="fibspiral";}anchorSchema(){return {min:2,max:2,slots:[{role:"center",free:"both"},{role:"edge",free:"both"}]}}spiralPoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time),d=Math.hypot(l-a,s-o);if(d<1)return null;let u=Math.atan2(s-o,l-a),h=Math.max(Math.log(PL/d)/qb,-8*Math.PI*2),p=[];for(let m=h;m<=EL;m+=ML){let g=d*Math.exp(qb*m),b=u+m;p.push([a+g*Math.cos(b),o+g*Math.sin(b)]);}return p}hitTest(t,n,i,o){let s=this.spiralPoints(i);return s!=null&&s.length>=2&&qi(t,n,s)<=o}handlePoints(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return [];let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?[]:[[t.xOf(n.time),o],[t.xOf(i.time),s]]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.handlePoints(t);if(n.length<2)return null;let i=n.map(l=>l[0]),o=n.map(l=>l[1]),s=Math.min(...i),a=Math.min(...o);return {x:s,y:a,w:Math.max(...i)-s,h:Math.max(...o)-a}}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,...Y]}}};var IL=De([{ratio:.125,color:Cn,label:"1/8"},{ratio:.25,color:Tn,label:"1/4"},{ratio:.333,color:Ji,label:"1/3"},{ratio:.5,color:ai,label:"1/2"},{ratio:1,color:Zl,label:"1/1"},{ratio:2,color:xr,label:"2/1"},{ratio:3,color:on,label:"3/1"},{ratio:4,color:ws,label:"4/1"},{ratio:8,color:kn,label:"8/1"}]),lc=class extends Pe{constructor(){super(...arguments);this.type="gannfan";}defaultLevels(){return IL}entryLines(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.xOf(n.time),s=t.yOf(n.price,this.paneId);if(s==null)return null;let a=t.xOf(i.time),l=i.price-n.price,d=[];for(let u of this.levels){if(!u.enabled)continue;let h=t.yOf(n.price+l*u.ratio,this.paneId);if(h==null)continue;let[p,m,g,b]=Oe(o,s,a,h,"right",t.width,t.height);d.push({color:u.color,x1:p,y1:m,x2:g,y2:b,numberText:u.label??String(u.ratio),numberX:a+5,numberY:h,numberAlign:"left",labelX:a+5,labelY:h});}return d}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var AL=De([0,.25,.382,.5,.618,.75,1].map(r=>({ratio:r,label:String(r)}))),cc=class extends Pe{constructor(){super(...arguments);this.type="gannbox";}defaultLevels(){return AL}corners(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.xOf(n.time),s=t.xOf(i.time),a=t.yOf(n.price,this.paneId),l=t.yOf(i.price,this.paneId);return a==null||l==null?null:{c1:n,c2:i,left:Math.min(o,s),right:Math.max(o,s),top:Math.min(a,l),bot:Math.max(a,l)}}entryLines(t){let n=this.corners(t);if(!n)return null;let{c1:i,c2:o,left:s,right:a,top:l,bot:d}=n,u=[];for(let p of this.levels){if(!p.enabled)continue;let m=t.yOf(i.price+p.ratio*(o.price-i.price),this.paneId);m!=null&&u.push({color:p.color,x1:s,y1:m,x2:a,y2:m,numberText:p.label??String(p.ratio),numberX:s-5,numberY:m,numberAlign:"right",labelX:s,labelY:m});let g=t.xOf(i.time+p.ratio*(o.time-i.time));u.push({color:p.color,x1:g,y1:l,x2:g,y2:d,numberText:"",numberX:g,numberY:l,numberAlign:"center",labelX:g,labelY:l});}let h=this.levels.find(p=>p.ratio===1)?.color??si;return u.push({color:h,x1:s,y1:l,x2:a,y2:d,numberText:"",numberX:0,numberY:0,numberAlign:"left",labelX:0,labelY:0}),u.push({color:h,x1:s,y1:d,x2:a,y2:l,numberText:"",numberX:0,numberY:0,numberAlign:"left",labelX:0,labelY:0}),u}hitTest(t,n,i,o){let s=this.corners(i);return s!=null&&lt(t,n,s.left,s.top,s.right,s.bot,o)}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var RL=De([0,.25,.382,.5,.618,.75,1].map(r=>({ratio:r,label:String(r)}))),DL=[{label:"3x1",x:3,y:1,color:Cn},{label:"2x1",x:2,y:1,color:Tn},{label:"1x1",x:1,y:1,color:Zl},{label:"1x2",x:1,y:2,color:xr},{label:"1x3",x:1,y:3,color:on}],Fh=[{k:.25,color:Cn},{k:.5,color:Tn},{k:.75,color:ai},{k:1,color:xr}],di=class extends Pe{constructor(){super(...arguments);this.type="gannsquare";}defaultLevels(){return RL}box(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=t.xOf(n.time),l=t.xOf(i.time);return {ox:a,oy:o,bx:l-a,py:s-o,left:Math.min(a,l),top:Math.min(o,s),right:Math.max(a,l),bot:Math.max(o,s)}}arcGeom(t){let n=this.box(t);return n?{ox:n.ox,oy:n.oy,bx:n.bx,py:n.py}:null}entryLines(t){let n=this.box(t);if(!n)return null;let i=this.anchors[0],o=this.anchors[1],s=[];for(let a of this.levels){if(!a.enabled)continue;let l=t.yOf(i.price+a.ratio*(o.price-i.price),this.paneId);l!=null&&s.push({color:a.color,x1:n.left,y1:l,x2:n.right,y2:l,numberText:a.label??String(a.ratio),numberX:n.left-5,numberY:l,numberAlign:"right",labelX:n.left,labelY:l});let d=t.xOf(i.time+a.ratio*(o.time-i.time));s.push({color:a.color,x1:d,y1:n.top,x2:d,y2:n.bot,numberText:"",numberX:d,numberY:n.top,numberAlign:"center",labelX:d,labelY:n.top});}for(let a of DL){let l,d;a.x>a.y?(l=n.ox+n.bx,d=n.oy+a.y/a.x*n.py):(d=n.oy+n.py,l=n.ox+a.x/a.y*n.bx),s.push({color:a.color,x1:n.ox,y1:n.oy,x2:l,y2:d,numberText:a.label,numberX:l+4,numberY:d,numberAlign:"left",labelX:l+4,labelY:d});}return s}hitTest(t,n,i,o){let s=this.box(i);return s!=null&&lt(t,n,s.left,s.top,s.right,s.bot,o)}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}};var Bh=[4,8,12,16,24,32,48,64],OL=24,NL=.75;function Zb(r,e){if(!Number.isInteger(r)||!Number.isInteger(e)||e<=0)return false;let t=r*r-1;return e%2===1?t%e===0:e%8===0?t%e!==0?false:t/e%2!==0:false}function Qb(r){let e=[];for(let t=0;t<r;t+=1)Zb(t,r)&&e.push(t);return e}var ui=class extends Z{constructor(t){super(t);this.type="dedekind";this.maxCurvature===void 0&&(this.maxCurvature=OL);}anchorSchema(){return {min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}box(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);if(o==null||s==null)return null;let a=Math.min(t.xOf(n.time),t.xOf(i.time)),l=Math.max(t.xOf(n.time),t.xOf(i.time)),d=Math.min(o,s),u=Math.max(o,s),h=l-a,p=u-d;if(h<1||p<1)return null;let m=p,g=h/m;return {left:a,right:l,top:d,bot:u,unitPx:m,x0:0,realSpan:g}}geodesics(t){let n=this.box(t);if(!n)return null;let{left:i,top:o,bot:s,unitPx:a,x0:l,realSpan:d}=n,u=Math.max(1,Math.min(64,Math.round(this.maxCurvature))),h=l-1/u,p=l+d+1/u,m=i+d*a,g=[],b=Math.floor(h*2),f=Math.ceil(p*2);for(let v=b;v<=f;v+=1){if(v%2===0)continue;let w=i+(v/2-l)*a;w<i-.5||w>m+.5||g.push({kind:"vline",x:w,y0:s,y1:o});}for(let v=1;v<=u;v+=1){let w=1/v,x=w*a;if(x<NL)continue;let T=Qb(v);if(T.length===0)continue;let M=Math.floor(h)-1,C=Math.ceil(p)+1;for(let L=M;L<=C;L+=1)for(let y of T){let E=y/v+L;if(E+w<h||E-w>p)continue;let S=i+(E-l)*a;S+x<i-1||S-x>m+1||g.push({kind:"arc",cx:S,cy:s,r:x});}}return g}hitTest(t,n,i,o){let s=this.box(i);return s!=null&&lt(t,n,s.left,s.top,s.right,s.bot,o)}handlePoints(t){let n=this.box(t);return n?[[n.left,n.top],[n.right,n.bot]]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.box(t);return n?{x:n.left,y:n.top,w:n.right-n.left,h:n.bot-n.top}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[...K,{path:"maxCurvature",label:c("drawing.dedekind.maxCurvature","Max curvature"),kind:"number",min:4,max:64,step:4,group:"behavior"},...Y]}}writeProps(){return {maxCurvature:this.maxCurvature}}readProps(t){typeof t.maxCurvature=="number"&&Number.isFinite(t.maxCurvature)&&(this.maxCurvature=Math.max(1,Math.min(64,Math.round(t.maxCurvature))));}};var Vh=[3,4,5,6,8,10,12],Hh=[1.5,2,2.5,3,4,5],dc=6,FL=2;function _h(r=dc){return [...Xb(Qi.length,r)]}function BL(r){if(!r||typeof r!="object")return null;let e=r;return typeof e.ratio!="number"||typeof e.color!="string"?null:{ratio:e.ratio,color:e.color,enabled:e.enabled!==false,...typeof e.label=="string"&&e.label?{label:e.label}:{}}}var eo={path:"showRatios",label:c("drawing.sonic.showRatios","Show ratios"),kind:"boolean",group:"behavior"},It=class extends Z{constructor(e){super(e),this.waveCount===void 0&&(this.waveCount=dc),this.showRatios===void 0&&(this.showRatios=true);let t=Array.isArray(e.props?.levels);this.levels||(this.levels=this.defaultLevels().map(n=>({...n}))),!t&&this.shouldSyncWaveCount()&&this.syncLevelsToWaveCount();}shouldSyncWaveCount(){return true}syncLevelsToWaveCount(){let e=Math.max(1,Math.min(this.levels.length,Math.round(this.waveCount)));this.waveCount=e;for(let t=0;t<this.levels.length;t+=1)this.levels[t].enabled=t<e;}editableLevels(){return this.levels}anchorSchema(){return {min:2,max:2,slots:[{role:"d1",free:"both"},{role:"d2",free:"both"}]}}geom(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=e.yOf(t.price,this.paneId),o=e.yOf(n.price,this.paneId);if(i==null||o==null)return null;let s=e.xOf(t.time),a=e.xOf(n.time),l=(s+a)/2,d=(i+o)/2,u=Math.hypot(a-s,o-i)/2;if(u<1)return null;let h=a-s,p=o-i,m=Math.hypot(h,p);m<1e-9?(h=1,p=0):(h/=m,p/=m);let g=this.levels.filter(C=>C.enabled&&C.ratio>0).slice().sort((C,L)=>C.ratio-L.ratio);if(g.length===0)return null;let b=Math.max(1,this.machNumber()),f=[];for(let C of g){let L=C.ratio*u;f.push({cx:l+b*(L-u)*h,cy:d+b*(L-u)*p,r:L,color:C.color,ratio:C.ratio});}let v=l-b*u*h,w=d-b*u*p,x=f[f.length-1].r,T=b*x+2*u,M=[];if(b<=1+1e-9){let C=-p,L=h;M.push([v-C*T,w-L*T,v+C*T,w+L*T]);}else {let C=Math.asin(1/b),L=Math.cos(C),y=Math.sin(C),E=(G,j,se)=>[G*L-j*se*y,G*se*y+j*L],[S,P]=E(h,p,1),[A,F]=E(h,p,-1);M.push([v,w,v+S*T,w+P*T]),M.push([v,w,v+A*T,w+F*T]);}return {c0x:l,c0y:d,R:u,fx:h,fy:p,noseX:v,noseY:w,circles:f,rays:M}}hitTest(e,t,n,i){let o=this.geom(n);if(!o)return false;for(let s of o.circles)if(Math.abs(Math.hypot(e-s.cx,t-s.cy)-s.r)<=i)return true;return o.rays.some(s=>fe(e,t,s[0],s[1],s[2],s[3])<=i)}handlePoints(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return [];let i=e.yOf(t.price,this.paneId),o=e.yOf(n.price,this.paneId);return i==null||o==null?[]:[[e.xOf(t.time),i],[e.xOf(n.time),o]]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.geom(e);if(!t)return null;let n=t.noseX,i=t.noseX,o=t.noseY,s=t.noseY;for(let a of t.circles)n=Math.min(n,a.cx-a.r),i=Math.max(i,a.cx+a.r),o=Math.min(o,a.cy-a.r),s=Math.max(s,a.cy+a.r);for(let a of t.rays)n=Math.min(n,a[0],a[2]),i=Math.max(i,a[0],a[2]),o=Math.min(o,a[1],a[3]),s=Math.max(s,a[1],a[3]);return {x:n,y:o,w:i-n,h:s-o}}priceRange(){let e=this.anchors[0],t=this.anchors[1];return !e||!t?null:{min:Math.min(e.price,t.price),max:Math.max(e.price,t.price)}}applySettings(e){if(super.applySettings(e),Object.prototype.hasOwnProperty.call(e,"waveCount")&&typeof this.waveCount=="number"){let t=Math.max(1,Math.min(this.levels.length,Math.round(this.waveCount)));this.waveCount=t;for(let n=0;n<this.levels.length;n+=1)this.levels[n].enabled=n<t;}}schema(){return {fields:[...K,{path:"waveCount",label:c("drawing.sonic.waveCount","Waves"),kind:"number",min:3,max:12,step:1,group:"behavior"},eo,...Y]}}writeProps(){return {waveCount:this.waveCount,showRatios:this.showRatios,levels:this.levels.map(e=>({...e}))}}readProps(e){if(typeof e.waveCount=="number"&&Number.isFinite(e.waveCount)&&(this.waveCount=Math.max(2,Math.min(12,Math.round(e.waveCount)))),typeof e.showRatios=="boolean"&&(this.showRatios=e.showRatios),Array.isArray(e.levels)){let t=e.levels.map(BL).filter(n=>n!=null);t.length&&(this.levels=t);}}},Ss=class extends It{constructor(){super(...arguments);this.type="sonic";}defaultLevels(){return _h(dc)}machNumber(){return 1}},Cs=class extends It{constructor(t){super(t);this.type="supersonic";this.mach===void 0&&(this.mach=FL);}defaultLevels(){return _h(dc)}machNumber(){return Math.max(1.01,this.mach)}schema(){return {fields:[...K,{path:"mach",label:c("drawing.supersonic.mach","Mach number"),kind:"number",min:1.5,max:5,step:.5,group:"behavior"},{path:"waveCount",label:c("drawing.supersonic.waveCount","Waves"),kind:"number",min:3,max:12,step:1,group:"behavior"},eo,...Y]}}writeProps(){return {...super.writeProps(),mach:this.mach}}readProps(t){super.readProps(t),typeof t.mach=="number"&&Number.isFinite(t.mach)&&(this.mach=Math.max(1.01,Math.min(20,t.mach)));}};var Jb=De([.236,.382,.5,.618,.786,1,1.618,2.618,4.236,6.854,11.09]),VL=2,uc=class extends It{constructor(){super(...arguments);this.type="goldensonic";}shouldSyncWaveCount(){return false}defaultLevels(){return Jb}machNumber(){return 1}schema(){return {fields:[...K,eo,...Y]}}},hc=class extends It{constructor(t){super(t);this.type="goldensupersonic";this.mach===void 0&&(this.mach=VL);}shouldSyncWaveCount(){return false}defaultLevels(){return Jb}machNumber(){return Math.max(1.01,this.mach)}schema(){return {fields:[...K,{path:"mach",label:c("drawing.goldensupersonic.mach","Mach number"),kind:"number",min:1.5,max:5,step:.5,group:"behavior"},eo,...Y]}}writeProps(){return {...super.writeProps(),mach:this.mach}}readProps(t){super.readProps(t),typeof t.mach=="number"&&Number.isFinite(t.mach)&&(this.mach=Math.max(1.01,Math.min(20,t.mach)));}};var nt=class extends Z{legRatios(){return false}fillTriangles(){return []}necklineIndices(){return null}anchorSchema(){let e=this.vertexLabels().length,t=[];for(let n=0;n<e;n+=1)t.push({role:`p${n}`,free:"both"});return {min:e,max:e,slots:t}}handlePoints(e){let t=[];for(let n of this.anchors){let i=e.yOf(n.price,this.paneId);if(i==null)return [];t.push([e.xOf(n.time),i]);}return t}hitTest(e,t,n,i){let o=this.handlePoints(n);return o.length>=2&&qi(e,t,o)<=i}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.handlePoints(e);if(t.length===0)return null;let n=t.map(a=>a[0]),i=t.map(a=>a[1]),o=Math.min(...n),s=Math.min(...i);return {x:o,y:s,w:Math.max(...n)-o,h:Math.max(...i)-s}}priceRange(){if(this.anchors.length===0)return null;let e=this.anchors.map(t=>t.price);return {min:Math.min(...e),max:Math.max(...e)}}patternName(){return null}ratioOk(e){return null}valid(){return null}ratioAt(e){let t=this.anchors[e-2],n=this.anchors[e-1],i=this.anchors[e];if(!t||!n||!i)return null;let o=Math.abs(n.price-t.price);return o<1e-9?null:Math.abs(i.price-n.price)/o}schema(){return {fields:[...K,...this.fillTriangles().length?Ce:[]]}}};var pc=class extends nt{constructor(){super(...arguments);this.type="xabcd";}vertexLabels(){return ["X","A","B","C","D"]}legRatios(){return true}fillTriangles(){return [[0,1,2],[2,3,4]]}};var mc=class extends nt{constructor(){super(...arguments);this.type="abcd";}vertexLabels(){return ["A","B","C","D"]}legRatios(){return true}};var gc=class extends nt{constructor(){super(...arguments);this.type="elliottimpulse";}vertexLabels(){return ["1","2","3","4","5"]}};var fc=class extends nt{constructor(){super(...arguments);this.type="elliottcorrection";}vertexLabels(){return ["A","B","C"]}};var HL=c("drawing.headshoulders.leftShoulder","LS"),_L=c("drawing.headshoulders.head","H"),zL=c("drawing.headshoulders.rightShoulder","RS"),bc=class extends nt{constructor(){super(...arguments);this.type="headshoulders";}vertexLabels(){return ["",HL,"",_L,"",zL,""]}necklineIndices(){return [2,4]}};var At=class extends nt{vertexLabels(){return ["X","A","B","C","D"]}legRatios(){return true}fillTriangles(){return [[0,1,2],[2,3,4]]}legValue(e){let[t,n,i,o,s]=this.anchors;if(!t||!n||!i||!o||!s)return null;let a=(h,p)=>Math.abs(p.price-h.price),l=a(t,n),d=a(n,i),u=a(i,o);switch(e){case "ab":return l<1e-9?null:d/l;case "bc":return d<1e-9?null:u/d;case "cd":return u<1e-9?null:a(o,s)/u;default:return l<1e-9?null:a(n,s)/l}}inBand(e,t){return e!=null&&e>=t.min&&e<=t.max}ratioOk(e){let t=this.ranges();return e===2?this.inBand(this.legValue("ab"),t.ab):e===3?this.inBand(this.legValue("bc"),t.bc):e===4?this.inBand(this.legValue("cd"),t.cd):null}valid(){if(this.anchors.length<5)return null;let e=this.ranges();return this.inBand(this.legValue("ab"),e.ab)&&this.inBand(this.legValue("bc"),e.bc)&&this.inBand(this.legValue("cd"),e.cd)&&this.inBand(this.legValue("ad"),e.ad)}};var vc=class extends At{constructor(){super(...arguments);this.type="gartley";}patternName(){return c("drawing.gartley.patternName","Gartley")}ranges(){return {ab:{min:.55,max:.68},bc:{min:.382,max:.886},cd:{min:1.13,max:1.618},ad:{min:.74,max:.83}}}};var yc=class extends At{constructor(){super(...arguments);this.type="bat";}patternName(){return c("drawing.bat.patternName","Bat")}ranges(){return {ab:{min:.382,max:.5},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:.84,max:.92}}}};var wc=class extends At{constructor(){super(...arguments);this.type="butterfly";}patternName(){return c("drawing.butterfly.patternName","Butterfly")}ranges(){return {ab:{min:.74,max:.83},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:1.272,max:1.618}}}};var xc=class extends At{constructor(){super(...arguments);this.type="crab";}patternName(){return c("drawing.crab.patternName","Crab")}ranges(){return {ab:{min:.382,max:.618},bc:{min:.382,max:.886},cd:{min:2.618,max:3.618},ad:{min:1.55,max:1.69}}}};var Sc=class extends At{constructor(){super(...arguments);this.type="shark";}patternName(){return c("drawing.shark.patternName","Shark")}ranges(){return {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}}}};var WL={min:1.272,max:1.414},GL={min:.74,max:.83},Cc=class extends At{constructor(){super(...arguments);this.type="cypher";}patternName(){return c("drawing.cypher.patternName","Cypher")}ranges(){return {ab:{min:.382,max:.618},bc:{min:0,max:1/0},cd:{min:0,max:1/0},ad:{min:0,max:1/0}}}xcOverXa(){let t=this.anchors[0],n=this.anchors[1],i=this.anchors[3];if(!t||!n||!i)return null;let o=Math.abs(n.price-t.price);return o<1e-9?null:Math.abs(i.price-t.price)/o}cdOverXc(){let t=this.anchors[0],n=this.anchors[3],i=this.anchors[4];if(!t||!n||!i)return null;let o=Math.abs(n.price-t.price);return o<1e-9?null:Math.abs(i.price-n.price)/o}ratioOk(t){return t===2?this.inBand(this.legValue("ab"),this.ranges().ab):null}valid(){return this.anchors.length<5?null:this.inBand(this.legValue("ab"),this.ranges().ab)&&this.inBand(this.xcOverXa(),WL)&&this.inBand(this.cdOverXc(),GL)}};var ev={priceChange:c("drawing.measure.priceChange","{change} ({percent}%)"),barsAndDuration:c("drawing.measure.barsAndDuration","{count, plural, one {{bars} bar} other {{bars} bars}}, {duration}")};function tv(r){return `${r>=0?"+":""}${r.toFixed(2)}`}var hi=class extends Z{constructor(e){super(e),this.showPrice===void 0&&(this.showPrice=true),this.showDate===void 0&&(this.showDate=true);}anchorSchema(){return {min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}measureLabel(e,t){let n=[];return this.showPrice&&n.push(this.priceLabel(t)),this.showDate&&n.push(this.timeLabel(e,t)),n}isUp(){let e=this.anchors[0],t=this.anchors[1];return e!=null&&t!=null&&t.price>=e.price}priceLabel(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return "";let i=n.price-t.price,o=t.price!==0?i/t.price*100:0;return X(e,ev.priceChange,{change:qe(tv(i),e),percent:qe(tv(o),e)})}timeLabel(e,t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return "";let o=(t??Ae()).format.duration(i.time-n.time,{style:"span",surface:"drawing"}),s=e.barsBetween?Math.round(e.barsBetween(n.time,i.time)):null;return s!=null?X(t,ev.barsAndDuration,{count:s,bars:qe(String(s),t),duration:o}):o}rect(e){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;let i=e.yOf(t.price,this.paneId),o=e.yOf(n.price,this.paneId);return i==null||o==null?null:{x1:e.xOf(t.time),y1:i,x2:e.xOf(n.time),y2:o}}hitTest(e,t,n,i){let o=this.rect(n);return o!=null&&lt(e,t,o.x1,o.y1,o.x2,o.y2,i)}handlePoints(e){let t=this.rect(e);return t?[[t.x1,t.y1],[t.x2,t.y2]]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}bounds(e){let t=this.rect(e);return t?{x:Math.min(t.x1,t.x2),y:Math.min(t.y1,t.y2),w:Math.abs(t.x2-t.x1),h:Math.abs(t.y2-t.y1)}:null}priceRange(){let e=this.anchors[0],t=this.anchors[1];return !e||!t?null:{min:Math.min(e.price,t.price),max:Math.max(e.price,t.price)}}schema(){return {fields:[{path:"showPrice",label:c("drawing.measure.showPrice","Show price"),kind:"boolean",group:"behavior"},{path:"showDate",label:c("drawing.measure.showDate","Show date"),kind:"boolean",group:"behavior"},...K.filter(e=>e.path!=="style.lineColor"),{path:"text.color",label:c("drawing.field.textColor","Text color"),kind:"color",group:"text"},{path:"text.size",label:c("drawing.field.textSize","Text size"),kind:"select",options:St,group:"text"}]}}writeProps(){return {showPrice:this.showPrice,showDate:this.showDate}}readProps(e){typeof e.showPrice=="boolean"&&(this.showPrice=e.showPrice),typeof e.showDate=="boolean"&&(this.showDate=e.showDate);}};var Tc=class extends hi{constructor(){super(...arguments);this.type="datepricerange";}};var to={header:c("drawing.position.header","{direction, select, long {LONG} other {SHORT}} \xB7 R:R {ratio}"),lossSize:c("drawing.position.lossSize","Loss {loss} \xB7 Size {size}"),target:c("drawing.position.targetLabel","Target +{percent}%"),targetAt:c("drawing.position.targetLabelAt","Target +{percent}% @ {price}"),stop:c("drawing.position.stopLabel","Stop \u2212{percent}%"),stopAt:c("drawing.position.stopLabelAt","Stop \u2212{percent}% @ {price}")},kc=[{value:"long",label:c("drawing.position.option.long","Long")},{value:"short",label:c("drawing.position.option.short","Short")}],Ue=class Ue extends Z{constructor(t){super(t);this.type="position";this.riskPercent===void 0&&(this.riskPercent=Ue.DEFAULT_RISK_PERCENT),this.accountBalance===void 0&&(this.accountBalance=Ue.DEFAULT_ACCOUNT_BALANCE),this.showText===void 0&&(this.showText=true),this.showHeader===void 0&&(this.showHeader=true),this.showPrices===void 0&&(this.showPrices=false),this.showLossSize===void 0&&(this.showLossSize=true),this.showTargetLabel===void 0&&(this.showTargetLabel=true),this.showStopLabel===void 0&&(this.showStopLabel=true),this.profitColor===void 0&&(this.profitColor=Ue.DEFAULT_PROFIT_COLOR),this.lossColor===void 0&&(this.lossColor=Ue.DEFAULT_LOSS_COLOR);}directionLabel(){let t=this.prices();return t&&t.target>=t.entry?"LONG":"SHORT"}get direction(){return this.directionLabel()==="LONG"?"long":"short"}set direction(t){let n=this.anchors[0],i=this.anchors[1],o=this.anchors[2];!n||!i||!o||(t==="long"||t==="short")&&t!==this.direction&&(i.price=2*n.price-i.price,o.price=2*n.price-o.price);}get quantity(){return this.positionSize()}set quantity(t){let n=this.prices();if(!n||!Number.isFinite(t)||t<0)return;let i=Math.abs(n.entry-n.stop);i<1e-9||this.accountBalance<=0||(this.riskPercent=t*i/this.accountBalance*100);}get entryPrice(){return this.anchors[0]?.price??0}set entryPrice(t){let n=this.anchors[0];n&&Number.isFinite(t)&&(n.price=t,this.constrainHandleDrag(0));}get stopPrice(){return this.anchors[1]?.price??0}set stopPrice(t){let n=this.anchors[1];n&&Number.isFinite(t)&&(n.price=t,this.constrainHandleDrag(1));}get targetPrice(){return this.anchors[2]?.price??0}set targetPrice(t){let n=this.anchors[2];n&&Number.isFinite(t)&&(n.price=t,this.constrainHandleDrag(2));}anchorSchema(){return {min:2,max:2,slots:[{role:"entry",free:"both"},{role:"stop",free:"both"},{role:"target",free:"both"}]}}onPlaced(t){let n=this.anchors[0];if(!n)return;let i=t.xOf(n.time),o=t.yOf(n.price,this.paneId);if(o==null)return;let s=this.anchors[1],a=s?t.yOf(s.price,this.paneId):null,l,d;s&&a!=null&&Math.abs(a-o)>=Ue.MIN_DRAG_PX?(l=a,d=i+Math.max(Math.abs(t.xOf(s.time)-i),Ue.MIN_WIDTH_PX)):(l=o-Ue.DEFAULT_RISK_PX*Ue.DEFAULT_RR,d=i+Ue.DEFAULT_WIDTH_PX);let u=o-(l-o)/Ue.DEFAULT_RR,h=t.pxToPoint(d,o,this.paneId).time;this.anchors=[{time:n.time,price:n.price},{time:h,price:t.pxToPoint(i,u,this.paneId).price},{time:h,price:t.pxToPoint(i,l,this.paneId).price}];}constrainHandleDrag(t){let n=this.anchors[0],i=this.anchors[1],o=this.anchors[2];if(!n||!i||!o)return;let s=Math.sign(i.price-n.price),a=Math.sign(o.price-n.price);s===0||a===0||s!==a||(t===2?i.price=2*n.price-i.price:o.price=2*n.price-o.price);}resolved(){let t=this.anchors[0],n=this.anchors[1];if(!t||!n)return null;if(this.anchors[2])return [t,n,this.anchors[2]];let i={time:n.time,price:t.price-(n.price-t.price)/Ue.DEFAULT_RR};return [t,i,n]}prices(){let t=this.resolved();return t?{entry:t[0].price,stop:t[1].price,target:t[2].price}:null}rr(){let t=this.prices();if(!t)return 0;let n=Math.abs(t.entry-t.stop);return n<1e-9?0:Math.abs(t.target-t.entry)/n}rewardPct(){let t=this.prices();return t&&t.entry!==0?Math.abs(t.target-t.entry)/t.entry*100:0}riskPct(){let t=this.prices();return t&&t.entry!==0?Math.abs(t.entry-t.stop)/t.entry*100:0}dollarLoss(){return Math.max(0,this.accountBalance)*(Math.max(0,this.riskPercent)/100)}positionSize(){let t=this.prices();if(!t)return 0;let n=Math.abs(t.entry-t.stop);return n<1e-9?0:this.dollarLoss()/n}headerLabel(t){return X(t,to.header,{direction:this.directionLabel()==="LONG"?"long":"short",ratio:qe(this.rr().toFixed(2),t)})}lossSizeLabel(t){return X(t,to.lossSize,{loss:qe(UL(this.dollarLoss()),t),size:qe($L(this.positionSize()),t)})}targetLabel(t){let n=this.prices(),i=qe(this.rewardPct().toFixed(2),t);return this.showPrices&&n?X(t,to.targetAt,{percent:i,price:qe(nv(n.target),t)}):X(t,to.target,{percent:i})}stopLabel(t){let n=this.prices(),i=qe(this.riskPct().toFixed(2),t);return this.showPrices&&n?X(t,to.stopAt,{percent:i,price:qe(nv(n.stop),t)}):X(t,to.stop,{percent:i})}levelDisplayValue(t,n){let i=this.prices();if(!i)return 0;let o=t==="stop"?i.stop:i.target;return rv(n==="price"?o:Math.abs(o-i.entry))}levelPriceFromDisplay(t,n,i){let o=this.prices();if(!o||n==="price")return i;let s=t==="stop"?o.stop:o.target,a=Math.sign(s-o.entry);return a===0&&(a=(t==="target"?1:-1)*(this.direction==="long"?1:-1)),o.entry+a*Math.abs(i)}box(t){let n=this.handlePoints(t);if(n.length<3)return null;let i=n.map(o=>o[0]);return {x1:Math.min(...i),x2:Math.max(...i),ey:n[0][1],sy:n[1][1],ty:n[2][1]}}layout(t){return this.box(t)}hitTest(t,n,i,o){let s=this.box(i);if(!s)return false;let a=Math.min(s.ey,s.sy,s.ty),l=Math.max(s.ey,s.sy,s.ty);return lt(t,n,s.x1,a,s.x2,l,o)}handlePoints(t){let n=this.resolved();if(!n)return [];let i=[];for(let o of n){let s=t.yOf(o.price,this.paneId);if(s==null)return [];i.push([t.xOf(o.time),s]);}return i}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.box(t);if(!n)return null;let i=Math.min(n.ey,n.sy,n.ty);return {x:n.x1,y:i,w:n.x2-n.x1,h:Math.max(n.ey,n.sy,n.ty)-i}}priceRange(){let t=this.resolved();if(!t)return null;let n=t.map(i=>i.price);return {min:Math.min(...n),max:Math.max(...n)}}schema(){return {fields:[{path:"riskPercent",label:c("drawing.position.riskPercent","Risk %"),kind:"number",min:0,max:100,step:.1,group:"behavior"},{path:"accountBalance",label:c("drawing.position.accountBalance","Account balance"),kind:"number",min:0,max:1e12,step:1,group:"behavior"},{path:"quantity",label:c("drawing.position.quantity","Position size"),kind:"number",group:"behavior"},{path:"direction",label:c("drawing.position.direction","Direction"),kind:"select",options:kc,group:"behavior"},{path:"entryPrice",label:c("drawing.position.entryPrice","Entry price"),kind:"number",group:"behavior"},{path:"stopPrice",label:c("drawing.position.stopPrice","Stop price"),kind:"number",group:"behavior"},{path:"targetPrice",label:c("drawing.position.targetPrice","Target price"),kind:"number",group:"behavior"},{path:"showText",label:c("drawing.position.showText","Show text"),kind:"boolean",group:"behavior"},{path:"showHeader",label:c("drawing.position.showHeader","Show direction & ratio"),kind:"boolean",group:"behavior"},{path:"showLossSize",label:c("drawing.position.showLossSize","Show loss & size"),kind:"boolean",group:"behavior"},{path:"showTargetLabel",label:c("drawing.position.showTargetLabel","Show target label"),kind:"boolean",group:"behavior"},{path:"showStopLabel",label:c("drawing.position.showStopLabel","Show stop label"),kind:"boolean",group:"behavior"},{path:"showPrices",label:c("drawing.position.showPrices","Show level prices"),kind:"boolean",group:"behavior"},{path:"profitColor",label:c("drawing.position.profitColor","Profit zone"),kind:"color",group:"fill"},{path:"lossColor",label:c("drawing.position.lossColor","Loss zone"),kind:"color",group:"fill"},...K.filter(t=>t.path!=="style.lineColor"),{path:"text.color",label:c("drawing.position.textColor","Text color"),kind:"color",group:"text"},{path:"text.size",label:c("drawing.position.textSize","Text size"),kind:"select",options:St,group:"text"}]}}writeProps(){return {riskPercent:this.riskPercent,accountBalance:this.accountBalance,showText:this.showText,showHeader:this.showHeader,showPrices:this.showPrices,showLossSize:this.showLossSize,showTargetLabel:this.showTargetLabel,showStopLabel:this.showStopLabel,profitColor:this.profitColor,lossColor:this.lossColor}}readProps(t){typeof t.riskPercent=="number"&&Number.isFinite(t.riskPercent)&&(this.riskPercent=t.riskPercent),typeof t.accountBalance=="number"&&Number.isFinite(t.accountBalance)&&(this.accountBalance=t.accountBalance),typeof t.showText=="boolean"&&(this.showText=t.showText),typeof t.showHeader=="boolean"&&(this.showHeader=t.showHeader),typeof t.showPrices=="boolean"&&(this.showPrices=t.showPrices),typeof t.showLossSize=="boolean"&&(this.showLossSize=t.showLossSize),typeof t.showTargetLabel=="boolean"&&(this.showTargetLabel=t.showTargetLabel),typeof t.showStopLabel=="boolean"&&(this.showStopLabel=t.showStopLabel),typeof t.profitColor=="string"&&(this.profitColor=t.profitColor),typeof t.lossColor=="string"&&(this.lossColor=t.lossColor);}};Ue.DEFAULT_RR=2,Ue.MIN_DRAG_PX=6,Ue.DEFAULT_RISK_PX=64,Ue.DEFAULT_WIDTH_PX=150,Ue.MIN_WIDTH_PX=48,Ue.DEFAULT_RISK_PERCENT=1,Ue.DEFAULT_ACCOUNT_BALANCE=1e4,Ue.DEFAULT_PROFIT_COLOR=bl,Ue.DEFAULT_LOSS_COLOR=vl;var Rt=Ue;function UL(r){if(!Number.isFinite(r))return "0";let e=Math.round(r*100)/100;return Number.isInteger(e)?String(e):e.toFixed(2)}function $L(r){return !Number.isFinite(r)||r===0?"0":r>=100?r.toFixed(2):r>=1?r.toFixed(4).replace(/\.?0+$/,""):r.toPrecision(4).replace(/\.?0+$/,"")}function nv(r){return Number.isFinite(r)?Math.abs(r)>=1?r.toFixed(2):r.toPrecision(4).replace(/\.?0+$/,""):"0"}function rv(r){return Math.round(r*1e8)/1e8}var no=[{value:"auto",label:c("drawing.magnifier.option.auto","Auto"),ms:0},{value:"1",label:c("drawing.magnifier.option.n1","1m"),ms:6e4},{value:"5",label:c("drawing.magnifier.option.n5","5m"),ms:3e5},{value:"15",label:c("drawing.magnifier.option.n15","15m"),ms:9e5},{value:"30",label:c("drawing.magnifier.option.n30","30m"),ms:18e5},{value:"60",label:c("drawing.magnifier.option.n60","1h"),ms:36e5},{value:"240",label:c("drawing.magnifier.option.n240","4h"),ms:144e5},{value:"D",label:c("drawing.magnifier.option.d","1D"),ms:864e5}];function ro(r){if(!(r>0))return [...no];let e=no.filter(t=>t.ms>0&&t.ms<r);return e.length>0?[no[0],...e]:[]}function Ts(r){let e=no.find(n=>n.value===r);if(e)return e.label;let t=Number(r);return Number.isFinite(t)&&t>0?t%1440===0?`${t/1440}D`:t%60===0?`${t/60}h`:`${t}m`:r}function iv(){return {timeframe:"auto",upColor:"",downColor:""}}var Dt=class extends Z{constructor(t){super(t);this.type="magnifier";this.chipRect=null;this.magnifier||(this.magnifier=iv());}anchorSchema(){return {min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}placementMode(){return "drag"}rect(t){let n=this.anchors[0],i=this.anchors[1];if(!n||!i)return null;let o=t.yOf(n.price,this.paneId),s=t.yOf(i.price,this.paneId);return o==null||s==null?null:{x1:t.xOf(n.time),y1:o,x2:t.xOf(i.time),y2:s}}hitTest(t,n,i,o){let s=this.rect(i);return s?lt(t,n,s.x1,s.y1,s.x2,s.y2)?true:[[s.x1,s.y1,s.x2,s.y1],[s.x2,s.y1,s.x2,s.y2],[s.x2,s.y2,s.x1,s.y2],[s.x1,s.y2,s.x1,s.y1]].some(l=>fe(t,n,l[0],l[1],l[2],l[3])<=o):false}handlePoints(t){let n=this.rect(t);return n?[[n.x1,n.y1],[n.x2,n.y2]]:[]}hitHandle(t,n,i,o){return ee(t,n,this.handlePoints(i),o+3)}bounds(t){let n=this.rect(t);return n?{x:Math.min(n.x1,n.x2),y:Math.min(n.y1,n.y2),w:Math.abs(n.x2-n.x1),h:Math.abs(n.y2-n.y1)}:null}priceRange(){let t=this.anchors[0],n=this.anchors[1];return !t||!n?null:{min:Math.min(t.price,n.price),max:Math.max(t.price,n.price)}}schema(){return {fields:[{path:"magnifier.timeframe",label:c("drawing.magnifier.magnifierTimeframe","Timeframe"),kind:"select",options:no,group:"behavior"},...fr,{path:"magnifier.upColor",label:c("drawing.magnifier.magnifierUpColor","Up candles"),kind:"color",group:"fill"},{path:"magnifier.downColor",label:c("drawing.magnifier.magnifierDownColor","Down candles"),kind:"color",group:"fill"}]}}writeProps(){return {...this.magnifier}}readProps(t){this.magnifier={...iv(),...t};}};function ov(r,e){if(r.length===0)return -1;let t=0,n=r.length-1;for(;t<n;){let i=t+n>>1;r[i].time<e?t=i+1:n=i;}return t>0&&Math.abs(r[t-1].time-e)<=Math.abs(r[t].time-e)?t-1:t}function YL(r,e){let t=r[e-1],n=r[e+1];return !t||!n||!r[e]?null:n.low>t.high?{bull:true,top:n.low,bottom:t.high}:n.high<t.low?{bull:false,top:t.low,bottom:n.high}:null}function KL(r,e){for(let t=0;t<=3;t+=1)for(let n of t===0?[e]:[e-t,e+t]){let i=YL(r,n);if(i)return {index:n,...i}}return null}function sv(r,e){let t=KL(r,e);if(!t)return null;let{index:n,bull:i,top:o,bottom:s}=t,a=(o+s)/2,l=null,d=null,u=null,h=null;for(let p=n+2;p<r.length&&h===null;p+=1){let m=r[p],g=i?m.low:m.high,b=f=>i?g<=f:g>=f;l===null&&b(i?o:s)&&(l=p),d===null&&b(a)&&(d=p),u===null&&b(i?s:o)&&(u=p),u!==null&&(i?m.close<s:m.close>o)&&(h=p);}return {index:n,bull:i,top:o,bottom:s,mid:a,tested:l,half:d,filled:u,inverted:h}}function av(r,e,t){let n=r[e];if(!n)return null;let i=n.close<n.open,o=t==="body"?Math.max(n.open,n.close):n.high,s=t==="body"?Math.min(n.open,n.close):n.low,a=(o+s)/2,l=false,d=null,u=null,h=null,p=false,m=null;for(let g=e+1;g<r.length&&m===null;g+=1){let b=r[g];h===null?(l?(d===null&&(i?b.low<=o:b.high>=s)&&(d=g),u===null&&(i?b.low<=a:b.high>=a)&&(u=g)):l=i?b.low>o:b.high<s,(i?b.close<s:b.close>o)&&(h=g)):p?(i?b.high>=s:b.low<=o)&&(m=g):p=i?b.high<s:b.low>o;}return {index:e,bull:i,top:o,bottom:s,mid:a,tested:d,half:u,broken:h,retest:m}}function lv(r,e,t){let n=r[e];if(!n)return null;let i=t==="high",o=i?n.high:n.low,s=null,a=null;for(let l=e+1;l<r.length&&a===null;l+=1){let d=r[l];(i?d.close>o:d.close<o)?a=l:s===null&&(i?d.high>o:d.low<o)&&(s=l);}return {index:e,high:i,price:o,swept:s,broken:a}}var cv=new WeakMap,ks=class extends Z{anchorSchema(){return {min:1,max:1,slots:[{role:"candle",free:"x"}]}}candles(e){let t=this.anchors[0];if(!t)return null;let n=cv.get(e);return n||(n=e.barsInRange?.(Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY)??[],cv.set(e,n)),n.length>0?{bars:n,at:ov(n,t.time)}:null}halfBar(e,t,n){let i=t[Math.max(0,n-1)],o=t[Math.min(t.length-1,Math.max(1,n))];return !i||!o||i===o?3:Math.max(1,Math.abs(e.xOf(o.time)-e.xOf(i.time))/2)}rightEdge(e,t,n){return n===null?Math.max(e.width,e.xOf(t[t.length-1].time)):e.xOf(t[n].time)+this.halfBar(e,t,n)}anchorHandle(e){let t=this.anchors[0],n=t?e.yOf(t.price,this.paneId):null;return t&&n!=null?[[e.xOf(t.time),n]]:[]}hitHandle(e,t,n,i){return ee(e,t,this.handlePoints(n),i+3)}priceRange(){return null}},$n=class extends ks{zone(e){let t=this.candles(e),n=t&&this.formation(t.bars,t.at);if(!t||!n)return null;let i=e.yOf(n.top,this.paneId),o=e.yOf(n.bottom,this.paneId);if(i==null||o==null)return null;let{bars:s}=t,a=this.settings(),l=b=>e.xOf(s[b].time)-this.halfBar(e,s,b),d=Math.min(i,o),u=Math.max(i,o),h=e.yOf(n.mid,this.paneId)??(d+u)/2,p=n.flip&&{x1:l(n.flip.from),x2:this.rightEdge(e,s,n.flip.to),fill:n.bull?a.downColor:a.upColor},m=a.extend==="tested"?n.bull?n.top:n.bottom:a.extend==="half"?n.mid:n.bull?n.bottom:n.top,g=e.yOf(m,this.paneId);return {x1:l(n.start),x2:this.rightEdge(e,s,n.end),yTop:d,yBottom:u,fill:n.bull?a.upColor:a.downColor,border:a.border,midY:a.midline?h:null,faded:n.end!==null&&a.fade&&!p,marker:n.end!==null&&!p&&g!=null?{x:e.xOf(s[n.end].time),y:g}:null,flip:p,handle:[e.xOf(s[n.index].time),h]}}hitTest(e,t,n,i){let o=this.zone(n);if(!o){let a=this.anchors[0];return a!=null&&Math.abs(e-n.xOf(a.time))<=i}let s=t>=o.yTop-i&&t<=o.yBottom+i;return s&&e>=o.x1-i&&e<=o.x2+i?true:o.flip!=null&&s&&e>=o.flip.x1-i&&e<=o.flip.x2+i}handlePoints(e){let t=this.zone(e);return t?[t.handle]:this.anchorHandle(e)}bounds(e){let t=this.zone(e);if(!t)return null;let n=Math.min(e.width,t.flip?t.flip.x2:t.x2);return {x:t.x1,y:t.yTop,w:Math.max(1,n-t.x1),h:Math.max(1,t.yBottom-t.yTop)}}};var dv=[{value:"tested",label:c("drawing.fairvaluegap.option.tested","Until tested")},{value:"half",label:c("drawing.fairvaluegap.option.half","Until 50%")},{value:"filled",label:c("drawing.fairvaluegap.option.filled","Until filled")},{value:"always",label:c("drawing.fairvaluegap.option.always","Always")}];function uv(){return {extend:"filled",upColor:`${N}33`,downColor:`${O}33`,midline:true,border:false,fade:true,inverse:false}}var Lc=class extends $n{constructor(t){super(t);this.type="fairvaluegap";this.gap||(this.gap=uv());}settings(){return this.gap}formation(t,n){let i=sv(t,n);if(!i)return null;let{extend:o,inverse:s}=this.gap,a=s&&o==="filled"&&i.inverted!==null?{from:i.inverted,to:null}:null;return {...i,start:i.index-1,end:o==="always"?null:i[o],flip:a}}schema(){return {fields:[{path:"gap.extend",label:c("drawing.fairvaluegap.gapExtend","Extend right"),kind:"select",options:dv,group:"behavior"},{path:"gap.upColor",label:c("drawing.fairvaluegap.gapUpColor","Bullish"),kind:"color",group:"fill"},{path:"gap.downColor",label:c("drawing.fairvaluegap.gapDownColor","Bearish"),kind:"color",group:"fill"},{path:"gap.midline",label:c("drawing.fairvaluegap.gapMidline","Midline"),kind:"boolean",group:"line"},{path:"gap.border",label:c("drawing.fairvaluegap.gapBorder","Border"),kind:"boolean",group:"line"},{path:"gap.fade",label:c("drawing.fairvaluegap.gapFade","Fade at end"),kind:"boolean",group:"behavior",when:{path:"gap.extend",in:["tested","half","filled"]}},{path:"gap.inverse",label:c("drawing.fairvaluegap.gapInverse","Flip on close"),kind:"boolean",group:"behavior",when:{path:"gap.extend",in:["filled"]}}]}}writeProps(){return {...this.gap}}readProps(t){let n=uv(),i=t;this.gap={extend:dv.some(o=>o.value===i.extend)?i.extend:n.extend,upColor:typeof i.upColor=="string"?i.upColor:n.upColor,downColor:typeof i.downColor=="string"?i.downColor:n.downColor,midline:typeof i.midline=="boolean"?i.midline:n.midline,border:typeof i.border=="boolean"?i.border:n.border,fade:typeof i.fade=="boolean"?i.fade:n.fade,inverse:typeof i.inverse=="boolean"?i.inverse:n.inverse};}};var XL=[{value:"body",label:c("drawing.orderblock.option.body","Body")},{value:"wick",label:c("drawing.orderblock.option.wick","Full range")}],hv=[{value:"tested",label:c("drawing.orderblock.option.tested","Until tested")},{value:"half",label:c("drawing.orderblock.option.half","Until 50%")},{value:"broken",label:c("drawing.orderblock.option.broken","Until broken")},{value:"always",label:c("drawing.orderblock.option.always","Always")}];function pv(){return {range:"body",extend:"broken",upColor:`${N}29`,downColor:`${O}29`,midline:true,border:true,fade:true,breaker:true}}var Mc=class extends $n{constructor(t){super(t);this.type="orderblock";this.block||(this.block=pv());}settings(){return this.block}formation(t,n){let i=av(t,n,this.block.range);if(!i)return null;let{extend:o,breaker:s}=this.block,a=s&&o==="broken"&&i.broken!==null?{from:i.broken,to:i.retest}:null;return {...i,start:i.index,end:o==="always"?null:i[o],flip:a}}schema(){return {fields:[{path:"block.range",label:c("drawing.orderblock.blockRange","Zone"),kind:"select",options:XL,group:"behavior"},{path:"block.extend",label:c("drawing.orderblock.blockExtend","Extend right"),kind:"select",options:hv,group:"behavior"},{path:"block.upColor",label:c("drawing.orderblock.blockUpColor","Bullish"),kind:"color",group:"fill"},{path:"block.downColor",label:c("drawing.orderblock.blockDownColor","Bearish"),kind:"color",group:"fill"},{path:"block.midline",label:c("drawing.orderblock.blockMidline","Midline"),kind:"boolean",group:"line"},{path:"block.border",label:c("drawing.orderblock.blockBorder","Border"),kind:"boolean",group:"line"},{path:"block.fade",label:c("drawing.orderblock.blockFade","Fade at end"),kind:"boolean",group:"behavior",when:{path:"block.extend",in:["tested","half","broken"]}},{path:"block.breaker",label:c("drawing.orderblock.blockBreaker","Breaker"),kind:"boolean",group:"behavior",when:{path:"block.extend",in:["broken"]}}]}}writeProps(){return {...this.block}}readProps(t){let n=pv(),i=t;this.block={range:i.range==="body"||i.range==="wick"?i.range:n.range,extend:hv.some(o=>o.value===i.extend)?i.extend:n.extend,upColor:typeof i.upColor=="string"?i.upColor:n.upColor,downColor:typeof i.downColor=="string"?i.downColor:n.downColor,midline:typeof i.midline=="boolean"?i.midline:n.midline,border:typeof i.border=="boolean"?i.border:n.border,fade:typeof i.fade=="boolean"?i.fade:n.fade,breaker:typeof i.breaker=="boolean"?i.breaker:n.breaker};}};var mv=[{value:"swept",label:c("drawing.liquidity.option.swept","Until swept")},{value:"broken",label:c("drawing.liquidity.option.broken","Until broken")},{value:"always",label:c("drawing.liquidity.option.always","Always")}];function gv(){return {extend:"swept",markSweep:true}}var pi=class extends ks{constructor(t){super(t);this.type="liquidity";this.liq||(this.liq=gv());}anchorSchema(){return {min:1,max:1,slots:[{role:"candle",free:"both"}]}}state(t){let n=this.candles(t),i=this.anchors[0];if(!n||!i)return null;let o=n.bars[n.at];return lv(n.bars,n.at,i.price>=(o.high+o.low)/2?"high":"low")}line(t){let n=this.candles(t),i=this.state(t);if(!n||!i)return null;let o=t.yOf(i.price,this.paneId);if(o==null)return null;let{bars:s}=n,{extend:a,markSweep:l}=this.liq,d=a==="always"?null:a==="broken"?i.broken:i.swept??i.broken,u=t.xOf(s[i.index].time),h=null;if(l&&i.swept!==null&&(d===null||i.swept<=d)){let p=s[i.swept],m=t.yOf(i.high?p.high:p.low,this.paneId);m!=null&&(h={x:t.xOf(p.time),y:m+(i.high?-9:9)});}return {x1:u,x2:this.rightEdge(t,s,d),y:o,sweep:h,handle:[u,o]}}hitTest(t,n,i,o){let s=this.line(i);return s!=null&&t>=s.x1-o&&t<=s.x2+o&&Math.abs(n-s.y)<=o}handlePoints(t){let n=this.line(t);return n?[n.handle]:this.anchorHandle(t)}bounds(t){let n=this.line(t);return n?{x:n.x1,y:n.y-4,w:Math.max(1,Math.min(t.width,n.x2)-n.x1),h:8}:null}schema(){return {fields:[...K,{path:"liq.extend",label:c("drawing.liquidity.liqExtend","Extend right"),kind:"select",options:mv,group:"behavior"},{path:"liq.markSweep",label:c("drawing.liquidity.liqMarkSweep","Mark sweep"),kind:"boolean",group:"behavior"}]}}writeProps(){return {...this.liq}}readProps(t){let n=gv(),i=t;this.liq={extend:mv.some(o=>o.value===i.extend)?i.extend:n.extend,markSweep:typeof i.markSweep=="boolean"?i.markSweep:n.markSweep};}};var mi=new Map;function $(r){mi.set(r.type,r);}function fv(r,e){if(typeof r.label=="string"&&(r.placementHint===void 0||typeof r.placementHint=="string"))return r;let t={...r,label:X(e,r.label),placementHint:void 0};return r.placementHint!==void 0?t.placementHint=X(e,r.placementHint):delete t.placementHint,t}function _t(r,e){let t=mi.get(r);return t?fv(t,e):void 0}function bv(r){return [...mi.values()].map(e=>fv(e,r))}function zh(r){return mi.get(r)}function vv(){return [...mi.values()]}function Yn(r,e){let t=mi.get(r);if(!t)return null;let n={...t.defaultStyle,...e.style??{}};return t.create({...e,style:n})}function Ec(r){let e=Yn(r.type,{paneId:r.paneId});if(!e)return;r.style={...e.style};let t=r.text?.value;e.text?(r.text={...e.text},t!==void 0&&(r.text.value=t)):r.text=void 0;let n=e.serialize().props;n!==void 0&&r.applyProps(n);}function zt(r){let e=mi.get(r.type);return e?e.create(r):null}var jL=V('<line x1="4" y1="19" x2="20" y2="5"/>'),qL=V('<line x1="3" y1="12" x2="21" y2="12"/>');$({type:"trendline",group:"lines",label:c("drawing.trendline.label","Trend Line"),icon:jL,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Qr(r)});$({type:"hline",group:"lines",label:c("drawing.hline.label","Horizontal Line"),icon:qL,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"dashed"},create:r=>new Sl(r)});var ZL=V('<line x1="3" y1="20" x2="21" y2="6"/><circle cx="3" cy="20" r="1.6" fill="currentColor"/>'),QL=V('<rect x="4" y="6" width="16" height="12" rx="1"/>'),JL=V('<path d="M5 6h14M12 6v13"/>');$({type:"ray",group:"lines",label:c("drawing.ray.label","Ray"),icon:ZL,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Cl(r)});var eM=V('<path d="M5 19 19 5"/><path d="M5 19 8.5 19M5 19 5 15.5"/><path d="M19 5 15.5 5M19 5 19 8.5"/>'),tM=V('<line x1="12" y1="3" x2="12" y2="21"/>'),nM=V('<line x1="5" y1="12" x2="21" y2="12"/><circle cx="5" cy="12" r="1.6" fill="currentColor"/>'),rM=V('<line x1="3" y1="12" x2="21" y2="12"/><line x1="12" y1="3" x2="12" y2="21"/>'),iM=V('<path d="M4 20 20 4"/><rect x="9" y="9" width="9" height="6" rx="1"/>'),oM=V('<path d="M4 20 20 6"/><path d="M4 20 15 20"/><path d="M11 20a7 7 0 0 0-2-4.9"/>');$({type:"extendedline",group:"lines",label:c("drawing.extendedline.label","Extended Line"),icon:eM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Tl(r)});$({type:"vline",group:"lines",label:c("drawing.vline.label","Vertical Line"),icon:tM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new kl(r)});$({type:"hray",group:"lines",label:c("drawing.hray.label","Horizontal Ray"),icon:nM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Ll(r)});$({type:"crossline",group:"lines",label:c("drawing.crossline.label","Cross Line"),icon:rM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Ml(r)});$({type:"infoline",group:"lines",label:c("drawing.infoline.label","Info Line"),icon:iM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new El(r)});$({type:"trendangle",group:"lines",label:c("drawing.trendangle.label","Trend Angle"),icon:oM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Pl(r)});$({type:"box",group:"shapes",label:c("drawing.box.label","Rectangle"),icon:QL,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}26`},create:r=>new Il(r)});$({type:"text",group:"annotations",label:c("drawing.text.label","Text"),icon:JL,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Gn(r)});var sM=V('<path d="M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-6l-5 5v-5H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z"/>');$({type:"callout",group:"annotations",label:c("drawing.callout.label","Callout"),icon:sM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new xn(r)});var aM=V('<path d="M5 4h14a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-7l-4 4v-4H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1Z"/><path d="M8 8.5h8M8 12h5"/>'),lM=V('<rect x="10" y="4.5" width="11" height="8" rx="1.5"/><path d="M10 8.5 4 16"/><circle cx="3.5" cy="16.5" r="1.6" fill="currentColor" stroke="none"/>'),cM=V('<path d="M5 4.5h14a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-7l-4 4v-4H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2Z"/>'),dM=V('<path d="M3 12 7 8h12a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H7Z"/><path d="M10.5 12.5h6" stroke-width="1.4"/>'),uM=V('<path d="M12 11.5V21"/><rect x="5" y="4" width="14" height="7" rx="1"/><path d="M9 7.5h6"/>');$({type:"note",group:"annotations",label:c("drawing.note.label","Note"),icon:aM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new Jr(r)});$({type:"pricenote",group:"annotations",label:c("drawing.pricenote.label","Price Note"),icon:lM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new ti(r)});$({type:"comment",group:"annotations",label:c("drawing.comment.label","Comment"),icon:cM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new ni(r)});$({type:"pricelabel",group:"annotations",label:c("drawing.pricelabel.label","Price Label"),icon:dM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new ei(r)});$({type:"signpost",group:"annotations",label:c("drawing.signpost.label","Signpost"),icon:uM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid",fillColor:`${H}d9`},create:r=>new ri(r)});var hM=V('<line x1="3" y1="16" x2="21" y2="8"/><line x1="3" y1="21" x2="21" y2="13"/>'),pM=V('<line x1="3" y1="7" x2="21" y2="10"/><line x1="3" y1="18" x2="21" y2="14"/>'),mM=V('<circle cx="4" cy="12" r="1.6" fill="currentColor"/><line x1="4" y1="12" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>');$({type:"parallelchannel",group:"channels",label:c("drawing.parallelchannel.label","Parallel Channel"),icon:hM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Al(r)});$({type:"disjointchannel",group:"channels",label:c("drawing.disjointchannel.label","Disjoint Channel"),icon:pM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Rl(r)});var gM=V('<line x1="3" y1="7" x2="21" y2="7"/><line x1="3" y1="18" x2="21" y2="11"/>');$({type:"flattopbottom",group:"channels",label:c("drawing.flattopbottom.label","Flat Top/Bottom"),icon:gM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Dl(r)});var fM=V('<line x1="3" y1="8" x2="21" y2="4"/><line x1="3" y1="16" x2="21" y2="12"/><line x1="3" y1="12" x2="21" y2="8" stroke-dasharray="3 3"/>');$({type:"regressionchannel",group:"channels",label:c("drawing.regressionchannel.label","Linear Regression"),icon:fM,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:r=>new Un(r)});$({type:"pitchfork",group:"pitchforks",label:c("drawing.pitchfork.label","Pitchfork"),icon:mM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Ol(r)});var bM=V('<circle cx="4" cy="8" r="1.6" fill="currentColor"/><line x1="4" y1="8" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>'),vM=V('<circle cx="6" cy="9" r="1.6" fill="currentColor"/><line x1="6" y1="9" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>'),yM=V('<line x1="4" y1="12" x2="10" y2="12"/><line x1="10" y1="8" x2="10" y2="16"/><line x1="10" y1="8" x2="21" y2="8"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="16" x2="21" y2="16"/>');$({type:"schiffpitchfork",group:"pitchforks",label:c("drawing.schiffpitchfork.label","Schiff Pitchfork"),icon:bM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Nl(r)});$({type:"modifiedschiffpitchfork",group:"pitchforks",label:c("drawing.modifiedschiffpitchfork.label","Modified Schiff Pitchfork"),icon:vM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Fl(r)});$({type:"insidepitchfork",group:"pitchforks",label:c("drawing.insidepitchfork.label","Inside Pitchfork"),icon:yM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Bl(r)});var wM=V('<path d="M7 7h10v10"/><path d="M7 17 17 7"/>'),xM=V('<ellipse cx="12" cy="12" rx="9" ry="6"/>'),SM=V('<path d="M12 4 20 19 4 19Z"/>');$({type:"arrow",group:"shapes",label:c("drawing.arrow.label","Arrow"),icon:wM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",arrowRight:true},create:r=>new Vl(r)});$({type:"ellipse",group:"shapes",label:c("drawing.ellipse.label","Ellipse"),icon:xM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Hl(r)});$({type:"triangle",group:"shapes",label:c("drawing.triangle.label","Triangle"),icon:SM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new _l(r)});var CM=V('<polyline points="3 17 9 10 13 14 21 5"/>'),TM=V('<path d="M9.5 12 17 4.5a2.12 2.12 0 0 1 3 3L12.5 15"/><path d="M7 14a3 3 0 0 0-3 3c0 1.3-1.2 1.5-1.5 2 .8.9 2 1.5 3.5 1.5a3.5 3.5 0 0 0 3.5-3.5 3 3 0 0 0-2.5-3Z"/>'),kM=V('<path d="M9 11 15 5l4 4-6 6H9Z"/><path d="M9 15l-2 2"/><path d="M4 21h6"/>');$({type:"polyline",group:"shapes",label:c("drawing.polyline.label","Polyline"),icon:CM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new zl(r)});$({type:"freehand",group:"shapes",label:c("drawing.freehand.label","Brush"),icon:TM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Wl(r)});$({type:"highlighter",group:"shapes",label:c("drawing.highlighter.label","Highlighter"),icon:kM,defaultStyle:{lineColor:`${wb}59`,lineWidth:14,lineStyle:"solid"},create:r=>new Gl(r)});var LM=V('<circle cx="12" cy="12" r="8"/>'),MM=V('<path d="M5 14 9.5 5 19 10 14.5 19 Z"/>'),EM=V('<path d="M4 19 9 11 13 14 17 8 20 4"/><path d="M17.2 5.5 20 4 19.4 7.1"/>'),PM=V('<path d="M4 17a8 8 0 0 1 16 0"/><path d="M4 17 20 17"/>'),IM=V('<path d="M4 18Q12 1 20 14"/>'),AM=V('<path d="M12 5 12 19"/><path d="M6 11 12 5 18 11"/>'),RM=V('<path d="M12 5 12 19"/><path d="M6 13 12 19 18 13"/>');$({type:"circle",group:"shapes",label:c("drawing.circle.label","Circle"),icon:LM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}1a`},create:r=>new Ul(r)});$({type:"rotatedrect",group:"shapes",label:c("drawing.rotatedrect.label","Rotated Rectangle"),icon:MM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}26`},create:r=>new $l(r)});$({type:"path",group:"shapes",label:c("drawing.path.label","Path"),icon:EM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Yl(r)});$({type:"arc",group:"shapes",label:c("drawing.arc.label","Arc"),icon:PM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid",fillColor:`${H}26`},create:r=>new Kl(r)});$({type:"curve",group:"shapes",label:c("drawing.curve.label","Curve"),icon:IM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new Xl(r)});$({type:"arrowmarkup",group:"shapes",label:c("drawing.arrowmarkup.label","Arrow Mark Up"),icon:AM,defaultStyle:{lineColor:N,lineWidth:1,lineStyle:"solid"},create:r=>new gs(r)});$({type:"arrowmarkdown",group:"shapes",label:c("drawing.arrowmarkdown.label","Arrow Mark Down"),icon:RM,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:r=>new fs(r)});var DM=V('<path d="M6 21V4"/><path d="M6 5h11l-2.5 3.5L17 12H6" fill="currentColor" stroke="none"/>'),OM=V('<path d="m12 3 2.6 5.8 6.4.6-4.8 4.2 1.4 6.2L12 16.9 6.4 19.8 7.8 13.6 3 9.4l6.4-.6Z"/>');$({type:"flagmark",group:"stamps",label:c("drawing.flagmark.label","Flag"),icon:DM,defaultStyle:{lineColor:xt,lineWidth:1,lineStyle:"solid"},create:r=>new bs(r)});$({type:"iconstamp",group:"stamps",label:c("drawing.iconstamp.label","Icon"),icon:OM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new vs(r)});var NM=V('<line x1="3" y1="5" x2="21" y2="5"/><line x1="3" y1="10" x2="21" y2="10"/><line x1="3" y1="14" x2="21" y2="14"/><line x1="3" y1="19" x2="21" y2="19"/>'),FM=V('<line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="11" x2="21" y2="11"/><line x1="3" y1="15" x2="14" y2="15"/><line x1="3" y1="20" x2="14" y2="20"/>');$({type:"fibretracement",group:"fibonacci",label:c("drawing.fibretracement.label","Fib Retracement"),icon:NM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Sr(r)});$({type:"fibextension",group:"fibonacci",label:c("drawing.fibextension.label","Fib Extension"),icon:FM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Ql(r)});var BM=V('<path d="M3 20 10 9l4 5"/><path d="M14 14h7M14 9h7M14 4h7"/>');$({type:"fibextensiontrend",group:"fibonacci",label:c("drawing.fibextensiontrend.label","Trend-Based Fib Extension"),icon:BM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Jl(r)});var VM=V('<path d="M4 20 20 5M4 20 21 11M4 20 21 17M4 20 20 20"/>'),HM=V('<path d="M3 5v14M6 5v14M11 5v14M19 5v14"/>');$({type:"fibfan",group:"fibonacci",label:c("drawing.fibfan.label","Fib Fan"),icon:VM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new ec(r)});$({type:"fibtimezones",group:"fibonacci",label:c("drawing.fibtimezones.label","Fib Time Zones"),icon:HM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"dashed"},create:r=>new tc(r)});var _M=V('<path d="M3 18 18 9M5 21 20 12M6 13 21 4"/>'),zM=V('<path d="M4 4 20 20M4 4 20 12M4 4 12 20M4 4 20 4M4 4 4 20"/>'),WM=V('<path d="M3 19 9 8M9 8 12 5v14M14 5v14M18 5v14M21 5v14"/>');$({type:"fibchannel",group:"fibonacci",label:c("drawing.fibchannel.label","Fib Channel"),icon:_M,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new nc(r)});$({type:"fibspeedfan",group:"fibonacci",label:c("drawing.fibspeedfan.label","Fib Speed Resistance Fan"),icon:zM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new rc(r)});$({type:"trendfibtime",group:"fibonacci",label:c("drawing.trendfibtime.label","Trend-Based Fib Time"),icon:WM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"dashed"},create:r=>new ic(r)});var GM=V('<circle cx="12" cy="12" r="3"/><circle cx="12" cy="12" r="6.5"/><circle cx="12" cy="12" r="10"/>'),UM=V('<path d="M8 20a4 4 0 0 1 8 0"/><path d="M4.5 20a7.5 7.5 0 0 1 15 0"/><circle cx="12" cy="20" r="1.4" fill="currentColor" stroke="none"/>'),$M=V('<path d="M4 20 20 16M4 20 14 4"/><path d="M11.8 18.1A8 8 0 0 0 8.2 13.2"/><path d="M16.6 16.9A13 13 0 0 0 10.9 9"/>'),YM=V('<path d="M13 12a2 2 0 1 1-2-2 4 4 0 0 1 4 4 6 6 0 0 1-9 5.2 9 9 0 0 1 .5-15"/>');$({type:"fibcircles",group:"fibonacci",label:c("drawing.fibcircles.label","Fib Circles"),icon:GM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new oc(r)});$({type:"fibarcs",group:"fibonacci",label:c("drawing.fibarcs.label","Fib Speed Resistance Arcs"),icon:UM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new sc(r)});$({type:"fibwedge",group:"fibonacci",label:c("drawing.fibwedge.label","Fib Wedge"),icon:$M,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new ac(r)});$({type:"fibspiral",group:"fibonacci",label:c("drawing.fibspiral.label","Fib Spiral"),icon:YM,defaultStyle:{lineColor:H,lineWidth:2,lineStyle:"solid"},create:r=>new ci(r)});var KM=V('<path d="M4 20 20 20M4 20 20 13M4 20 20 6M4 20 15 4M4 20 9 4M4 20 4 4"/>'),XM=V('<rect x="4" y="4" width="16" height="16" rx="1"/><path d="M4 12h16M12 4v16M4 4 20 20" opacity="0.6"/>');$({type:"gannfan",group:"fibonacci",label:c("drawing.gannfan.label","Gann Fan"),icon:KM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new lc(r)});$({type:"gannbox",group:"fibonacci",label:c("drawing.gannbox.label","Gann Box"),icon:XM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new cc(r)});var jM=V('<rect x="4" y="4" width="16" height="16" rx="1"/><path d="M4 20 20 4M4 20 20 12M4 20 12 4" opacity="0.7"/><path d="M4 20a16 16 0 0 1 16-16" opacity="0.5"/>');$({type:"gannsquare",group:"fibonacci",label:c("drawing.gannsquare.label","Gann Square"),icon:jM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new di(r)});var qM=V('<path d="M2 20h20"/><path d="M4 20a8 8 0 0 1 16 0" opacity="0.9"/><path d="M6 20a4 4 0 0 1 8 0" opacity="0.75"/><path d="M10 20a2 2 0 0 1 4 0" opacity="0.6"/><path d="M8 20v-6M12 20v-9M16 20v-6" opacity="0.45"/>');$({type:"dedekind",group:"geometry",label:c("drawing.dedekind.label","Dedekind Tessellation"),icon:qM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new ui(r)});var ZM=V('<circle cx="16" cy="12" r="5" opacity="0.55"/><circle cx="13" cy="12" r="3.5" opacity="0.75"/><circle cx="10.5" cy="12" r="2"/><path d="M8 4v16"/>'),QM=V('<circle cx="17" cy="12" r="4.5" opacity="0.45"/><circle cx="13" cy="12" r="3" opacity="0.7"/><circle cx="10" cy="12" r="1.6"/><path d="M6 12 16 5M6 12 16 19"/>');$({type:"sonic",group:"geometry",label:c("drawing.sonic.label","Sonic"),icon:ZM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Ss(r)});$({type:"supersonic",group:"geometry",label:c("drawing.supersonic.label","Supersonic"),icon:QM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Cs(r)});var JM=V('<circle cx="16" cy="12" r="5" opacity="0.4"/><circle cx="13" cy="12" r="3.2" opacity="0.65"/><circle cx="10.8" cy="12" r="1.8"/><path d="M8 4v16"/><path d="M15 8.5h2M12.5 10h2" opacity="0.5"/>'),eE=V('<circle cx="17" cy="12" r="4.5" opacity="0.4"/><circle cx="12.5" cy="12" r="2.8" opacity="0.65"/><circle cx="9.8" cy="12" r="1.4"/><path d="M6 12 16 5M6 12 16 19"/>');$({type:"goldensonic",group:"geometry",label:c("drawing.goldensonic.label","Golden Sonic"),icon:JM,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new uc(r)});$({type:"goldensupersonic",group:"geometry",label:c("drawing.goldensupersonic.label","Golden Supersonic"),icon:eE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new hc(r)});var tE=V('<path d="M3 18 7 8 11 14 15 6 20 16"/>'),nE=V('<path d="M4 17 9 7 14 15 20 5"/>'),rE=V('<path d="M3 19 8 9 12 13 17 5 21 9"/>'),iE=V('<path d="M4 7 11 16 20 9"/>'),oE=V('<path d="M3 18 6 12 9 16 12 5 15 16 18 12 21 18"/>');$({type:"xabcd",group:"patterns",label:c("drawing.xabcd.label","XABCD Pattern"),icon:tE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new pc(r)});$({type:"abcd",group:"patterns",label:c("drawing.abcd.label","ABCD Pattern"),icon:nE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new mc(r)});$({type:"elliottimpulse",group:"patterns",label:c("drawing.elliottimpulse.label","Elliott Impulse Wave (1-5)"),icon:rE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new gc(r)});$({type:"elliottcorrection",group:"patterns",label:c("drawing.elliottcorrection.label","Elliott Correction Wave (ABC)"),icon:iE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new fc(r)});$({type:"headshoulders",group:"patterns",label:c("drawing.headshoulders.label","Head & Shoulders"),icon:oE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new bc(r)});var sE=V('<path d="M3 17 7 6 12 14 17 5 21 16"/><path d="M3 17 21 16" opacity="0.45"/>'),io={group:"patterns",icon:sE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"}};$({type:"gartley",label:c("drawing.gartley.label","Gartley"),...io,create:r=>new vc(r)});$({type:"bat",label:c("drawing.bat.label","Bat"),...io,create:r=>new yc(r)});$({type:"butterfly",label:c("drawing.butterfly.label","Butterfly"),...io,create:r=>new wc(r)});$({type:"crab",label:c("drawing.crab.label","Crab"),...io,create:r=>new xc(r)});$({type:"shark",label:c("drawing.shark.label","Shark"),...io,create:r=>new Sc(r)});$({type:"cypher",label:c("drawing.cypher.label","Cypher"),...io,create:r=>new Cc(r)});var aE=V('<rect x="4" y="6" width="16" height="12" rx="1"/><path d="M4 18 20 6" opacity="0.5"/>');$({type:"datepricerange",group:"measure",label:c("drawing.datepricerange.label","Date & Price Range"),icon:aE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Tc(r)});var lE=V('<rect x="4.5" y="4.5" width="15" height="7.5" rx="1" fill="currentColor" fill-opacity="0.25"/><rect x="4.5" y="12" width="15" height="7.5" rx="1"/>');$({type:"position",group:"measure",label:c("drawing.position.label","Long/Short Position"),icon:lE,defaultStyle:{lineColor:H,lineWidth:1,lineStyle:"solid"},create:r=>new Rt(r)});var cE=V('<circle cx="10.5" cy="10.5" r="6.5"/><path d="m15.3 15.3 5.2 5.2"/><path d="M8 12.5v-3M10.5 13.5v-5.5M13 12v-2"/>');$({type:"magnifier",group:"measure",label:c("drawing.magnifier.label","Magnifier"),icon:cE,defaultStyle:{lineColor:"",lineWidth:1,lineStyle:"solid"},coversSeries:true,placementHint:c("drawing.magnifier.placementHint","Drag an area on the chart to view it at a lower timeframe"),create:r=>new Dt(r)});var dE=V('<line x1="5" y1="3" x2="5" y2="21"/><path d="M5 16c4 0 5-9 8-9s3 5 8 3"/>');$({type:"anchoredvwap",group:"measure",label:c("drawing.anchoredvwap.label","Anchored VWAP"),icon:dE,defaultStyle:{lineColor:be,lineWidth:2,lineStyle:"solid"},create:r=>new ii(r)});var uE=V('<path d="M4 4v16"/><path d="M4 8h10"/><path d="M4 12h14"/><path d="M4 16h8"/><path d="M4 20h12"/>');$({type:"fixedrangevp",group:"measure",label:c("drawing.fixedrangevp.label","Fixed Range Volume Profile"),icon:uE,defaultStyle:{lineColor:N,lineWidth:1,lineStyle:"solid"},create:r=>new $t(r)});var hE=V('<path d="M6 15v6M12 3v18M18 2v6"/><rect x="3.5" y="9.5" width="17" height="5" rx="1" fill="currentColor" fill-opacity="0.28" stroke-width="1.4"/>'),pE=V('<rect x="4" y="7.5" width="5" height="8" rx="1"/><path d="M6.5 4v3.5M6.5 15.5V19"/><rect x="9" y="7.5" width="11.5" height="8" rx="1" fill="currentColor" fill-opacity="0.22" stroke-width="1.4"/>'),mE=V('<path d="M3 8h12" stroke-dasharray="2.5 2.5"/><path d="m16.5 4.5 4 4m0-4-4 4"/><path d="M3.5 20 8 13.5l4 3.5 5-8"/>');$({type:"fairvaluegap",group:"priceaction",label:c("drawing.fairvaluegap.label","Fair Value Gap"),icon:hE,defaultStyle:{lineColor:N,lineWidth:1,lineStyle:"solid"},placementHint:c("drawing.fairvaluegap.placementHint","Click the middle candle of a gap"),create:r=>new Lc(r)});$({type:"orderblock",group:"priceaction",label:c("drawing.orderblock.label","Order Block"),icon:pE,defaultStyle:{lineColor:N,lineWidth:1,lineStyle:"solid"},placementHint:c("drawing.orderblock.placementHint","Click the candle that forms the block"),create:r=>new Mc(r)});$({type:"liquidity",group:"priceaction",label:c("drawing.liquidity.label","Liquidity"),icon:mE,defaultStyle:{lineColor:q,lineWidth:1,lineStyle:"solid"},placementHint:c("drawing.liquidity.placementHint","Click near a candle's high or low"),create:r=>new pi(r)});var gE=["fibretracement","fibextension","fibextensiontrend","fibfan","fibtimezones","fibchannel","fibspeedfan","trendfibtime","fibcircles","fibarcs","fibwedge","fibspiral"],fE=["fairvaluegap","orderblock","liquidity"],bE=["gannfan","gannbox","gannsquare"],vE=["dedekind","sonic","supersonic","goldensonic","goldensupersonic"],yE=["xabcd","abcd","headshoulders"],wE=["elliottimpulse","elliottcorrection"],xE=["gartley","bat","butterfly","crab","shark","cypher"],SE=["position","datepricerange","magnifier"],CE=["anchoredvwap","fixedrangevp"],TE=["freehand","highlighter"],kE=["arrow","arrowmarkup","arrowmarkdown"],LE=["box","ellipse","triangle","polyline","circle","rotatedrect","path","arc","curve"],ME=["text","callout","note","pricenote","comment","pricelabel","signpost"],EE=["flagmark","iconstamp"],PE=[{id:"lines-channels-pitchforks",label:c("drawing.toolbar.group.linesChannelsPitchforks","Lines"),sections:[{label:c("drawing.toolbar.section.lines","Lines"),registryGroup:"lines"},{label:c("drawing.toolbar.section.channels","Channels"),registryGroup:"channels"},{label:c("drawing.toolbar.section.pitchforks","Pitchforks"),registryGroup:"pitchforks"}]},{id:"fibonacci-gann",label:c("drawing.toolbar.group.fibonacciGann","Fibonacci"),sections:[{label:c("drawing.toolbar.section.fibonacci","Fibonacci"),types:gE},{label:c("drawing.toolbar.section.priceAction","Price Action"),types:fE},{label:c("drawing.toolbar.section.gann","Gann"),types:bE},{label:c("drawing.toolbar.section.geometry","Geometry"),types:vE}]},{id:"patterns-waves-harmonics",label:c("drawing.toolbar.group.patternsWavesHarmonics","Patterns"),sections:[{label:c("drawing.toolbar.section.patterns","Patterns"),types:yE},{label:c("drawing.toolbar.section.elliottWaves","Elliott Waves"),types:wE},{label:c("drawing.toolbar.section.harmonics","Harmonics"),types:xE}]},{id:"measurements",label:c("drawing.toolbar.group.measurements","Measurements"),sections:[{label:c("drawing.toolbar.section.measurements","Measurements"),types:SE},{label:c("drawing.toolbar.section.volume","Volume"),types:CE}]},{id:"brushes-arrows-shapes",label:c("drawing.toolbar.group.brushesArrowsShapes","Shapes"),sections:[{label:c("drawing.toolbar.section.brushes","Brushes"),types:TE},{label:c("drawing.toolbar.section.arrows","Arrows"),types:kE},{label:c("drawing.toolbar.section.shapes","Shapes"),types:LE}]},{id:"text",label:c("drawing.toolbar.group.text","Text"),sections:[{label:c("drawing.toolbar.section.text","Text"),types:ME}]},{id:"icons",label:c("drawing.toolbar.group.icons","Icons"),sections:[{label:c("drawing.toolbar.section.icons","Icons"),types:EE}]}];function IE(r){let e=zh(r);return e?{type:e.type,label:e.label,icon:e.icon}:null}function AE(r){let e=new Map;for(let t of vv()){if(r&&!r.has(t.type))continue;let n={type:t.type,label:t.label,icon:t.icon};e.has(t.group)||e.set(t.group,[]),e.get(t.group).push(n);}return e}function RE(r,e,t){return "registryGroup"in r?e.get(r.registryGroup)??[]:r.types.map(n=>t.get(n)).filter(n=>n!=null)}function Ls(r){let e=AE(r),t=new Map;for(let i of e.values())for(let o of i)t.set(o.type,o);let n=[];for(let i of PE){let o=[],s=[];for(let a of i.sections){let l=RE(a,e,t);l.length!==0&&(o.push({label:a.label,tools:l}),s.push(...l));}s.length!==0&&n.push({id:i.id,label:i.label,tools:s,sections:o.length>0?o:void 0});}return {groups:n}}function DE(r){let e=new Set;for(let t of r)zh(t)&&e.add(t);return Ls(e)}function OE(r){let e=[];for(let t of r){let n=t.tools.map(IE).filter(i=>i!=null);n.length>0&&e.push({id:t.id,label:t.label,tools:n});}return {groups:e}}function yv(r,e){let t=new Map,n=i=>{let o=t.get(i);return o||(o={type:i.type,label:X(e,i.label),icon:i.icon},t.set(i,o)),o};return {groups:r.groups.map(i=>({id:i.id,label:X(e,i.label),tools:i.tools.map(n),sections:i.sections?.map(o=>({label:X(e,o.label),tools:o.tools.map(n)}))}))}}function wv(r){return yv(Ls(),r)}function oo(r,e){let{definition:t,visible:n}=NE(r);return {definition:yv(t,e),visible:n}}function NE(r){if(r===false)return {definition:Ls(),visible:false};if(r===void 0||r===true)return {definition:Ls(),visible:true};let e=r.toolbar??true;return r.groups?{definition:OE(r.groups),visible:e}:r.tools?{definition:DE(r.tools),visible:e}:{definition:Ls(),visible:e}}function ct(r){let e=globalThis.structuredClone;return e?e(r):JSON.parse(JSON.stringify(r))}function xv(r){if(!r||typeof r!="object")return false;let e=r;return typeof e.id=="string"&&typeof e.type=="string"&&typeof e.paneId=="string"&&Array.isArray(e.anchors)&&e.anchors.every(t=>t&&typeof t.time=="number"&&typeof t.price=="number")&&!!e.style&&typeof e.style=="object"}function Wh(r){let e=r;return !e||typeof e!="object"||e.version!==1||!Array.isArray(e.drawings)?{version:1,drawings:[]}:{version:1,drawings:e.drawings.filter(xv)}}var so=class{constructor(){this.byId=new Map;this.seq=0;this.zCounter=1;this.listeners=new Set;}nextId(){return this.seq+=1,`dw-${this.seq}`}add(e){return e.zIndex||(e.zIndex=this.zCounter),this.zCounter=Math.max(this.zCounter,Math.ceil(e.zIndex))+1,this.byId.set(e.id,e),this.emit(),e}remove(e){let t=this.byId.delete(e);return t&&this.emit(),t}get(e){return this.byId.get(e)}has(e){return this.byId.has(e)}update(e,t){let n=this.byId.get(e);return n?(t.anchors&&(n.anchors=t.anchors.map(i=>({time:i.time,price:i.price}))),t.style&&(n.style={...t.style}),t.text!==void 0&&(n.text=t.text?{...t.text}:void 0),t.paneId!==void 0&&(n.paneId=t.paneId),t.locked!==void 0&&(n.locked=t.locked),t.visible!==void 0&&(n.visible=t.visible),t.zIndex!==void 0&&(n.zIndex=t.zIndex),t.props!==void 0&&n.applyProps(t.props),"showOn"in t&&(n.showOn=ps(t.showOn)),this.emit(),n):null}all(){return [...this.byId.values()].sort((e,t)=>e.zIndex-t.zIndex)}byPane(e){return this.all().filter(t=>t.paneId===e)}bringToFront(e,t=0){let n=this.byId.get(e);n&&(n.zIndex=Math.max(this.zCounter,Math.floor(t)+1),this.zCounter=n.zIndex+1,this.emit());}sendToBack(e,t=1){let n=this.byId.get(e);if(!n)return;let i=Math.min(...[...this.byId.values()].map(o=>o.zIndex),Math.ceil(t));n.zIndex=i-1,this.emit();}setLocked(e,t){let n=this.byId.get(e);n&&(n.locked=t,this.emit());}setVisible(e,t){let n=this.byId.get(e);n&&(n.visible=t,this.emit());}clear(){this.byId.size!==0&&(this.byId.clear(),this.emit());}serialize(){return {version:1,drawings:this.all().map(e=>e.serialize())}}load(e){let t=Wh(e);this.byId.clear(),this.seq=0,this.zCounter=1;for(let n of t.drawings){let i=zt(n);i&&(this.byId.set(i.id,i),this.zCounter=Math.max(this.zCounter,i.zIndex)+1,this.bumpSeqPast(i.id));}this.emit();}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}bumpSeqPast(e){let t=/^dw-(\d+)$/.exec(e);t&&(this.seq=Math.max(this.seq,Number(t[1])));}emit(){for(let e of this.listeners)e();}};var Pc=class{constructor(e=100){this.cap=e;this.undoStack=[];this.redoStack=[];this.pending=null;this.dirtied=false;this.depth=0;}begin(e){this.depth+=1,this.depth===1&&(this.pending=ct(e),this.dirtied=false);}markDirty(){this.depth===0||this.dirtied||!this.pending||(this.push(this.pending),this.dirtied=true);}commit(){this.depth!==0&&(this.depth-=1,this.depth===0&&(this.pending=null,this.dirtied=false));}abort(){this.commit();}record(e){if(this.depth>0){this.markDirty();return}this.push(ct(e));}undo(e){let t=this.undoStack.pop();return t?(this.redoStack.push(ct(e)),t):null}redo(e){let t=this.redoStack.pop();return t?(this.undoStack.push(ct(e)),t):null}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}clear(){this.undoStack=[],this.redoStack=[],this.pending=null,this.dirtied=false,this.depth=0;}push(e){this.undoStack.push(e),this.undoStack.length>this.cap&&this.undoStack.shift(),this.redoStack=[];}};function Cr(r){let e={style:{...r.style}};if(r.text){let{value:n,...i}=r.text;e.text=i;}let t=r.serialize().props;return t!==void 0&&(e.props=ct(t)),e}function Kn(r,e){e&&(e.style&&(r.style={...r.style,...e.style}),e.text&&(r.text={...r.text??rn(),...e.text,value:r.text?.value??""}),e.props&&r.applyProps(ct(e.props)));}function Ms(r,e){return JSON.stringify(r??null)===JSON.stringify(e??null)}function Ic(r){if(r==null||typeof r!="object"||Array.isArray(r))return null;let e=r,t=a=>a!=null&&typeof a=="object"&&!Array.isArray(a)?a:void 0,n={},i=t(e.style);i&&(n.style=i);let o=t(e.text);if(o){let{value:a,...l}=o;n.text=l;}let s=t(e.props);return s&&(n.props=s),n.style||n.text||n.props?n:null}var FE=60;function Gh(r){if(!Array.isArray(r))return [];let e=new Map;for(let t of r){if(t==null||typeof t!="object")continue;let n=t,i=typeof n.name=="string"?n.name.trim().slice(0,FE):"",o=Ic(n.settings);i&&o&&e.set(i,{name:i,settings:o});}return [...e.values()]}var BE=new Set(["trendline","ray","extendedline","hline","hray","vline","crossline","infoline","trendangle"]),VE=new Set(["box","rotatedrect","ellipse","circle","triangle","parallelchannel","disjointchannel","flattopbottom"]);function Ac(r){return BE.has(r)?[{name:"Support",label:c("drawing.template.support","Support"),settings:{style:{lineColor:N,lineWidth:2,lineStyle:"solid"}}},{name:"Resistance",label:c("drawing.template.resistance","Resistance"),settings:{style:{lineColor:O,lineWidth:2,lineStyle:"solid"}}},{name:"Projection",label:c("drawing.template.projection","Projection"),settings:{style:{lineColor:R,lineWidth:1,lineStyle:"dashed"}}}]:VE.has(r)?[{name:"Demand",label:c("drawing.template.demand","Demand"),settings:{style:{lineColor:N,fillColor:`${N}26`}}},{name:"Supply",label:c("drawing.template.supply","Supply"),settings:{style:{lineColor:O,fillColor:`${O}26`}}}]:[]}function HE(r){let e=Yn(r.type,{paneId:r.paneId});return e?Cr(e):void 0}var Rc=class{constructor(e,t,n,i,o=()=>null){this.events=t;this.i18n=o;this.store=new so;this.history=new Pc;this.activeTool=null;this.snapMode="off";this.stayInDrawingMode=false;this.mode=null;this.favs=new Set;this.selectedIds=[];this.clipboard=[];this.defaults=new Map;this.templates=new Map;this.subs=[];if(this.enabled=!!e.capabilities.userDrawings&&!!e.userDrawingsPort,this.port=this.enabled?e.userDrawingsPort:null,this.toolbarOption=n,this.port){let{definition:s,visible:a}=oo(n,this.i18n());this.port.setToolbar(s),this.port.showToolbar(a),i&&this.port.setSeriesGateway?.(i),this.subs.push(this.port.onDrawingIntent(l=>this.onIntent(l))),this.subs.push(this.store.onChange(()=>this.sync()));}}get supported(){return this.enabled}setTool(e){if(!this.port)return;let t=e!==this.activeTool;this.activeTool=e;let n=e?this.defaults.get(e):void 0;this.port.setActiveTool(e,n?.style,n),t&&this.events.emit("drawing:tool",{type:e});}getTool(){return this.activeTool}getSnapMode(){return this.snapMode}setSnapMode(e){!this.port||e===this.snapMode||(this.snapMode=e,this.port.setSnapMode?.(e),this.events.emit("drawing:snap",{mode:e}));}getStayMode(){return this.stayInDrawingMode}setStayMode(e){!this.port||e===this.stayInDrawingMode||(this.stayInDrawingMode=e,this.port.setStayMode?.(e),this.events.emit("drawing:stay",{on:e}));}getMode(){return this.mode}setMode(e){!this.port||e===this.mode||(this.mode=e,this.port.setMode?.(e),this.events.emit("drawing:mode",{mode:e}));}showToolbar(e){this.port?.showToolbar(e);}favorites(){return [...this.favs]}isFavorite(e){return this.favs.has(e)}setFavorite(e,t){_t(e)&&t!==this.favs.has(e)&&(t?this.favs.add(e):this.favs.delete(e),this.pushFavorites());}setFavorites(e){let t=e.filter(n=>_t(n)!=null);t.length===this.favs.size&&t.every(n=>this.favs.has(n))||(this.favs=new Set(t),this.pushFavorites());}pushFavorites(){let e=[...this.favs];this.port?.setFavorites?.(e),this.events.emit("drawing:favorites",{favorites:e});}toolDefaults(){let e={};for(let[t,n]of this.defaults)e[t]=ct(n);return e}setToolDefaults(e){let t=new Map;for(let[i,o]of Object.entries(e??{})){if(!_t(i))continue;let s=Ic(o);s&&t.set(i,ct(s));}let n=new Set([...this.defaults.keys(),...t.keys()]);for(let i of [...n])Ms(this.defaults.get(i),t.get(i))&&n.delete(i);if(n.size!==0){this.defaults.clear();for(let[i,o]of t)this.defaults.set(i,o);this.activeTool&&n.has(this.activeTool)&&this.setTool(this.activeTool);for(let i of n)this.events.emit("drawing:defaults",{type:i});}}resetToolDefaults(e){let t=e?this.defaults.has(e)?[e]:[]:[...this.defaults.keys()];for(let n of t)this.defaults.delete(n),this.events.emit("drawing:defaults",{type:n});}toolTemplates(){let e={};for(let[t,n]of this.templates)e[t]=ct(n);return e}setToolTemplates(e){let t=new Map;for(let[i,o]of Object.entries(e??{})){if(!_t(i))continue;let s=Gh(o);s.length>0&&t.set(i,s);}let n=[...new Set([...this.templates.keys(),...t.keys()])].filter(i=>JSON.stringify(this.templates.get(i)??[])!==JSON.stringify(t.get(i)??[]));if(n.length!==0){this.templates=t,this.pushTemplates();for(let i of n)this.events.emit("drawing:templates",{type:i});}}saveToolTemplate(e,t,n){if(!_t(e))return;let[i]=Gh([{name:t,settings:n}]);if(!i)return;let o=(this.templates.get(e)??[]).filter(s=>s.name!==i.name);this.templates.set(e,[...o,ct(i)]),this.pushTemplates(),this.events.emit("drawing:templates",{type:e});}removeToolTemplate(e,t){let n=this.templates.get(e);if(!n?.some(o=>o.name===t))return;let i=n.filter(o=>o.name!==t);i.length>0?this.templates.set(e,i):this.templates.delete(e),this.pushTemplates(),this.events.emit("drawing:templates",{type:e});}pushTemplates(){this.port?.setToolTemplates?.(this.toolTemplates());}setToolbar(e){this.toolbarOption=e,this.port?.setToolbar(oo(e,this.i18n()).definition);}relocalize(){this.port?.setToolbar(oo(this.toolbarOption,this.i18n()).definition);}setExternalGhost(e){this.port?.setExternalGhost?.(e);}setToolShortcuts(e){this.port?.setToolShortcuts?.(e);}add(e,t={}){if(!this.enabled)return null;let n=this.defaults.get(e),i=Yn(e,{id:this.store.nextId(),paneId:t.paneId??"price",anchors:t.anchors,text:t.text,zIndex:t.zIndex??this.startZ(e,t.paneId??"price")});return i?(Kn(i,n),t.style&&(i.style={...i.style,...t.style}),t.text&&(i.text={...i.text??t.text,...t.text}),t.props&&i.applyProps(t.props),this.history.record(this.store.serialize()),this.store.add(i),this.captureDefaults(i.id),this.events.emit("drawing:created",{id:i.id}),i):null}remove(e){this.deleteMany([e]);}update(e,t){let n=this.store.serialize(),i=t.style?this.store.get(e):void 0,o=t.style&&i?{...t,style:{...i.style,...t.style}}:t;this.updateDrawing(e,o)&&(this.history.record(n),this.events.emit("drawing:edited",{id:e}));}updateMany(e){this.history.begin(this.store.serialize());for(let{id:t,patch:n}of e)this.updateDrawing(t,n)&&(this.history.markDirty(),this.events.emit("drawing:edited",{id:t}));this.history.commit();}removeMany(e){this.deleteMany(e);}setLocked(e,t){let n=this.store.serialize();this.history.record(n),this.store.setLocked(e,t),this.events.emit("drawing:edited",{id:e});}setVisible(e,t){let n=this.store.serialize();this.history.record(n),this.store.setVisible(e,t),this.events.emit("drawing:edited",{id:e});}bringToFront(e){let t=this.store.serialize();this.history.record(t),this.store.bringToFront(e,this.seriesTopZ(this.store.get(e)?.paneId)),this.events.emit("drawing:edited",{id:e});}sendToBack(e){let t=this.store.serialize();this.history.record(t),this.store.sendToBack(e,this.seriesBottomZ(this.store.get(e)?.paneId)),this.events.emit("drawing:edited",{id:e});}seriesTopZ(e){return e!==void 0?this.port?.stackRange?.(e)?.front??0:0}seriesBottomZ(e){return e!==void 0?this.port?.stackRange?.(e)?.back??1:1}startZ(e,t){let n=this.port?.stackRange?.(t);if(n)return _t(e)?.coversSeries?n.front+.5:(n.price??n.front)-.5}select(e,t=false){this.setSelection(e,t);}openSettings(e){this.port?.openSettings(e);}undo(){let e=this.history.undo(this.store.serialize());e&&this.restoreSnapshot(e);}redo(){let e=this.history.redo(this.store.serialize());e&&this.restoreSnapshot(e);}canUndo(){return this.history.canUndo()}canRedo(){return this.history.canRedo()}duplicate(e){if(!this.enabled)return [];let t=this.resolve(e);return t.length===0?[]:this.insertClones(t.map(n=>n.serialize()))}clone(e){return this.duplicate([e])[0]??null}copy(e){let t=this.resolve(e).map(n=>ct(n.serialize()));t.length&&(this.clipboard=t);}paste(){return !this.enabled||this.clipboard.length===0?[]:this.insertClones(this.clipboard)}all(){return this.store.serialize().drawings}toJSON(){return this.store.serialize()}fromJSON(e){this.history.clear(),this.selectedIds=[],this.store.load(e);}destroy(){for(let e of this.subs)e();this.subs.length=0;}setSelection(e,t=false){let n;if(t){n=[...this.selectedIds];for(let i of e){let o=n.indexOf(i);o>=0?n.splice(o,1):n.push(i);}}else n=[...e];this.selectedIds=n.filter(i=>this.store.has(i)),this.announceSelection();}announceSelection(){this.port?.setSelection(this.selectedIds),this.events.emit("drawing:selected",{id:this.selectedIds[0]??null,ids:[...this.selectedIds]});}restoreSnapshot(e){this.store.load(e),this.selectedIds=this.selectedIds.filter(t=>this.store.has(t)),this.announceSelection();}deleteMany(e){this.history.begin(this.store.serialize());let t=[];for(let i of e)this.store.remove(i)&&t.push(i),this.history.markDirty();if(this.history.commit(),t.length===0)return;let n=this.selectedIds.filter(i=>this.store.has(i));n.length!==this.selectedIds.length&&this.setSelection(n);for(let i of t)this.events.emit("drawing:removed",{id:i});}insertClones(e){this.history.begin(this.store.serialize());let t=[];for(let n of e){let i=zt({...n,id:this.store.nextId()});i&&(this.store.add(i),this.history.markDirty(),t.push(i));}if(this.history.commit(),t.length){this.setSelection(t.map(n=>n.id));for(let n of t)this.events.emit("drawing:created",{id:n.id});}return t}resolve(e){return e.map(t=>this.store.get(t)).filter(t=>t!=null)}updateDrawing(e,t){let n=this.store.get(e),i=n?Cr(n):void 0;if(!this.store.update(e,t))return false;let o=this.store.get(e);return o&&!Ms(i,Cr(o))&&this.captureDefaults(e),true}captureDefaults(e){let t=this.store.get(e);if(!t)return;let n=Cr(t),i=Ms(n,HE(t))?void 0:n;Ms(this.defaults.get(t.type),i)||(i?this.defaults.set(t.type,i):this.defaults.delete(t.type),this.events.emit("drawing:defaults",{type:t.type}));}sync(){this.port?.syncDrawings(this.store.serialize().drawings);}onIntent(e){switch(e.kind){case "arm":this.setTool(e.type);break;case "draft":this.events.emit("drawing:draft",{doc:e.doc});break;case "create":{let t=this.store.serialize(),n=zt({...e.doc,id:this.store.nextId()});if(!n)return;Kn(n,this.defaults.get(n.type)),n.zIndex||(n.zIndex=this.startZ(n.type,n.paneId)??0),this.history.record(t),this.store.add(n),this.captureDefaults(n.id),this.events.emit("drawing:created",{id:n.id});break}case "edit":{let t=this.store.serialize();this.updateDrawing(e.doc.id,e.doc)&&(this.history.record(t),this.events.emit("drawing:edited",{id:e.doc.id}));break}case "edit-many":{this.history.begin(this.store.serialize());for(let t of e.docs)this.updateDrawing(t.id,t)&&(this.history.markDirty(),this.events.emit("drawing:edited",{id:t.id}));this.history.commit();break}case "select":this.setSelection(e.ids,e.additive);break;case "delete":this.deleteMany(e.ids);break;case "reorder":e.to==="front"?this.bringToFront(e.id):this.sendToBack(e.id);break;case "settings":this.events.emit("drawing:settings",{id:e.id});break;case "favorite":this.setFavorite(e.type,e.on);break;case "template-save":this.saveToolTemplate(e.type,e.name,e.settings);break;case "template-remove":this.removeToolTemplate(e.type,e.name);break;case "snap-mode":e.mode!==this.snapMode&&(this.snapMode=e.mode,this.events.emit("drawing:snap",{mode:e.mode}));break;case "stay-mode":e.on!==this.stayInDrawingMode&&(this.stayInDrawingMode=e.on,this.events.emit("drawing:stay",{on:e.on}));break;case "mode":e.mode!==this.mode&&(this.mode=e.mode,this.events.emit("drawing:mode",{mode:e.mode}));break;case "tool-finished":!this.stayInDrawingMode&&e.type!=="freehand"&&e.type!=="highlighter"&&this.setTool(null);break;case "undo":this.undo();break;case "redo":this.redo();break;case "duplicate":this.duplicate(e.ids);break;case "clone":this.enabled&&e.docs.length&&this.insertClones(e.docs);break;case "copy":this.copy(e.ids);break;case "paste":this.paste();break}}};function Dc(r,e,t){let n=r[e];return typeof n=="boolean"?n:t.find(i=>i.id===e)?.visible!==false}function Oc(r,e,t){if(e===void 0)return true;let n=new Set,i=e;for(;i!==void 0&&!n.has(i);){if(n.add(i),!Dc(r,i,t))return false;let o=t.find(s=>s.id===i)?.parent;i=o!==void 0&&t.some(s=>s.id===o)?o:void 0;}return true}function Uh(r){let e=new Set(r.map(o=>o.id)),t=[],n=new Set,i=(o,s)=>{if(!n.has(o.id)){n.add(o.id),t.push({group:o,depth:s});for(let a of r)a.parent===o.id&&a.id!==o.id&&i(a,s+1);}};for(let o of r)o.parent!==void 0&&e.has(o.parent)&&o.parent!==o.id||i(o,0);for(let o of r)i(o,0);return t}var Nc=class{constructor(e,t){this.renderer=e;this.marks=new Map;this.groups=new Map;this.subs=[];this.enabled=!!e.capabilities.timelineMarks&&typeof e.setTimelineMarks=="function",this.enabled&&e.onMarkClick&&this.subs.push(e.onMarkClick(n=>t.emit("mark:click",n)));}get supported(){return this.enabled}add(e){this.marks.set(e.id,Cv(e)),this.sync();}set(e){this.marks.clear();for(let t of e)this.marks.set(t.id,Cv(t));this.sync();}remove(e){let t=this.marks.delete(e);return t&&this.sync(),t}clear(){this.marks.size!==0&&(this.marks.clear(),this.sync());}all(){return [...this.marks.values()].map(e=>({...e,glyph:{...e.glyph}}))}defineGroup(e){if(!e||typeof e.id!="string"||e.id.length===0)throw new Error("[vela] marks.defineGroup: `id` must be a non-empty string");if(typeof e.label!="string")throw new Error(`[vela] marks.defineGroup: group "${e.id}" needs a string \`label\``);if(e.parent!==void 0&&(typeof e.parent!="string"||e.parent.length===0))throw new Error(`[vela] marks.defineGroup: group "${e.id}" has a \`parent\` that is not a group id`);this.groups.set(e.id,{...e}),this.sync();}groupDefinitions(){return [...this.groups.values()].map(e=>({...e}))}setGroupVisible(e,t){if(!this.renderer.features.includes("marks")){console.warn(`[vela] renderer "${this.renderer.name}" does not paint timeline marks \u2014 setGroupVisible ignored.`);return}this.renderer.applyFeature("marks",{groups:{[e]:t}});}isGroupVisible(e){let t=this.renderer.readFeature("marks"),n={};for(let[i,o]of Object.entries(t?.groups??{}))typeof o=="boolean"&&(n[i]=o);return Oc(n,e,[...this.groups.values()])}destroy(){for(let e of this.subs)e();this.subs.length=0;}sync(){this.enabled&&this.renderer.setTimelineMarks([...this.marks.values()],[...this.groups.values()]);}};function Cv(r){if(!r||typeof r!="object")throw new Error("[vela] marks: a mark must be an object");if(typeof r.id!="string"||r.id.length===0)throw new Error("[vela] marks: `id` must be a non-empty string");if(typeof r.time!="number"||!Number.isFinite(r.time))throw new Error(`[vela] marks: mark "${r.id}" needs a finite epoch-ms \`time\``);if(!r.glyph||typeof r.glyph!="object"||typeof r.glyph.color!="string")throw new Error(`[vela] marks: mark "${r.id}" needs a glyph with a \`color\``);return {...r,glyph:{...r.glyph}}}var Tv={D:864e5,W:6048e5,M:2592e6};function an(r){let e=r.trim();if(Tv[e])return Tv[e];let t=/^(\d+)\s*(m|h|d|w)?$/i.exec(e);if(t){let n=parseInt(t[1],10),i=(t[2]??"m").toLowerCase();return n*(i==="m"?6e4:i==="h"?36e5:i==="d"?864e5:6048e5)}return 36e5}var _E=5e3,zE=.25,WE=16,GE=15e3,$h=["240","60","30","15","5","1"],Fc=class{constructor(e){this.deps=e;this.cache=new Map;this.listeners=new Set;}seriesInRange(e,t,n){if(!this.deps.canFetch())return {state:"unavailable",reason:"no-source"};let i=this.resolveTimeframe(e);if(typeof i!="string")return {state:"unavailable",reason:i.reason};let o=an(i),s=Math.min(t,n),a=Math.max(t,n);if(!(a>s)||!(o>0))return {state:"unavailable",reason:"not-lower"};if((a-s)/o>_E)return {state:"unavailable",reason:"too-wide"};let l=`${this.deps.marketKey()}|${i}`,d=this.cache.get(l)??[],u=d.find(h=>h.from<=s&&h.to>=a);if(u){if(u.pending)return this.loading(d,i,o,s,a);if(u.failedAt>0){if(Date.now()-u.failedAt<GE)return this.loading(d,i,o,s,a);d.splice(d.indexOf(u),1);}else return this.maybeRefresh(l,u,i,o,a),{state:"ready",bars:this.slice(u.bars,s,a),timeframe:i,barMs:o}}return this.fetchWindow(l,d,i,s,a),this.loading(d,i,o,s,a)}onUpdate(e){return this.listeners.add(e),()=>this.listeners.delete(e)}resolveTimeframe(e){let t=an(this.deps.chartTimeframe()),n=$h[$h.length-1];if(an(n)>=t)return {reason:"none-lower"};let i=e.trim()||"auto";if(i==="auto"){for(let o of $h)if(an(o)<=t/4)return o;return n}return an(i)<t?i:{reason:"not-lower"}}loading(e,t,n,i,o){let s=new Map;for(let l of e)if(!(l.pending||l.failedAt>0)&&!(l.to<i||l.from>o))for(let d of this.slice(l.bars,i,o))s.set(d.time,d);if(s.size===0)return {state:"loading",timeframe:t,barMs:n};let a=[...s.values()].sort((l,d)=>l.time-d.time);return {state:"loading",timeframe:t,barMs:n,bars:a}}fetchWindow(e,t,n,i,o){if(t.some(l=>l.pending&&l.to>=i&&l.from<=o))return;let s=(o-i)*zE,a={from:i-s,to:o+s,bars:[],fetchedAt:0,pending:true,failedAt:0};t.push(a),this.cache.set(e,t),this.evict(),this.deps.fetchBars(n,{from:a.from,to:a.to}).then(l=>{a.bars=l,a.fetchedAt=Date.now(),a.pending=false,this.absorbOverlaps(e,a),this.fire();}).catch(()=>{a.pending=false,a.failedAt=Date.now(),this.fire();});}maybeRefresh(e,t,n,i,o){if(t.pending)return;let s=t.bars.length>0?t.bars[t.bars.length-1].time:t.from;o<s||Date.now()-t.fetchedAt<i||(t.pending=true,this.deps.fetchBars(n,{from:t.from,to:t.to}).then(a=>{t.bars=a,t.fetchedAt=Date.now(),t.pending=false,this.fire();}).catch(()=>{t.pending=false,t.fetchedAt=Date.now();}));}absorbOverlaps(e,t){let n=this.cache.get(e);if(n)for(let i=n.length-1;i>=0;i-=1){let o=n[i];if(o===t||o.pending||o.failedAt>0||o.to<t.from||o.from>t.to)continue;let s=new Map;for(let a of o.bars)s.set(a.time,a);for(let a of t.bars)s.set(a.time,a);t.bars=[...s.values()].sort((a,l)=>a.time-l.time),t.from=Math.min(t.from,o.from),t.to=Math.max(t.to,o.to),t.fetchedAt=Math.min(t.fetchedAt,o.fetchedAt||t.fetchedAt),n.splice(i,1);}}evict(){let e=0;for(let t of this.cache.values())e+=t.length;for(;e>WE;){let t=null,n=-1,i=1/0;for(let[s,a]of this.cache)for(let l=0;l<a.length;l+=1){let d=a[l];if(d.pending)continue;let u=d.fetchedAt||d.failedAt;u<i&&(t=s,n=l,i=u);}if(t==null)return;let o=this.cache.get(t);o.splice(n,1),o.length===0&&this.cache.delete(t),e-=1;}}slice(e,t,n){let i=[];for(let o of e)if(!(o.time<t)){if(o.time>n)break;i.push(o);}return i}fire(){for(let e of [...this.listeners])e();}};function Es(r){return r.group!=null&&r.ticker===r.group}function kv(r){return `${(r.prefix??r.provider??"").toLowerCase()}:${(r.group??"").toUpperCase()}`}function UE(r,e){let t=kv(e);return r.filter(n=>n.group!=null&&!Es(n)&&kv(n)===t)}function Lv(r,e){let t=UE(r,e),n=t.filter(i=>i.default);return (n.length===1?n[0]:t[0])??null}var Ln=r=>r.trim().toLowerCase(),Xn=r=>r.trim().toUpperCase();function Mn(r){let e=r.trim(),t=/^(?:([A-Za-z0-9_.]+):)?(.+)$/.exec(e);if(!t)return {provider:null,ticker:e};let n=t[1]?Ln(t[1]):null,i=t[2],o=i.lastIndexOf("."),s=o>0?i.slice(o+1):void 0;return {provider:n,ticker:i,ext:s}}var Bc=class{constructor(){this.entries=new Map;this.changeListeners=new Set;this.waits=new Set;this.unresolvedCbs=new Set;}register(e,t){let n=Ln(e),i={name:n,provider:t,index:null,prefixIndex:null,byTicker:null,descriptors:[],settled:false,settle:Promise.resolve()};return this.entries.set(n,i),i.settle=this.buildIndex(i),queueMicrotask(()=>this.notify(false)),i.settle}async buildIndex(e){await Promise.resolve();try{if(e.provider.listSymbols){let t=await e.provider.listSymbols();e.descriptors=t,e.index=new Set(t.map(n=>Xn(n.ticker))),e.byTicker=new Map(t.map(n=>[Xn(n.ticker),n])),e.prefixIndex=new Map;for(let n of t)n.prefix&&e.prefixIndex.set(`${Ln(n.prefix)}:${Xn(n.ticker)}`,n);}}catch{e.index=null;}finally{e.settled=true,this.notify(true);}}notify(e){for(let t of [...this.changeListeners])t(e);}onChange(e){return this.changeListeners.add(e),()=>this.changeListeners.delete(e)}unregister(e){this.entries.delete(Ln(e)),this.notify(false);}has(e){return this.entries.has(Ln(e))}get(e){return this.entries.get(Ln(e))?.provider}names(){return [...this.entries.keys()]}parse(e){return Mn(e)}resolve(e,t={}){let{provider:n,ticker:i}=this.parse(e);if(n){if(this.entries.has(n)){let a=this.entries.get(n).byTicker?.get(Xn(i));return {provider:n,ticker:a!=null&&Es(a)?this.loadableTicker(n,a):i}}let s=`${n}:${Xn(i)}`;for(let a of this.candidateOrder(t.default)){let l=this.entries.get(a).prefixIndex?.get(s);if(l)return {provider:a,ticker:this.loadableTicker(a,l)}}return null}let o=Xn(i);for(let s of this.candidateOrder(t.default)){let a=this.entries.get(s);if(a.index?.has(o)){let l=a.byTicker?.get(o);return {provider:s,ticker:l!=null&&Es(l)?this.loadableTicker(s,l):i}}}if(t.lenient&&this.entries.size===1){let s=this.names()[0],a=this.entries.get(s);if(a.settled&&a.index==null)return {provider:s,ticker:i}}return null}loadableTicker(e,t){return Es(t)?Lv(this.entries.get(e)?.descriptors??[],t)?.ticker??t.ticker:t.ticker}whenResolvable(e,t={}){let n=this.resolve(e,{...t,lenient:true});return n?Promise.resolve(n):new Promise(i=>{let o=this.onChange(a=>{let l=this.resolve(e,{...t,lenient:true});l?(s(),i(l)):a&&this.allSettled()&&this.reportUnresolved(e);}),s=()=>{o(),this.waits.delete(s);};this.waits.add(s);})}allSettled(){for(let e of this.entries.values())if(!e.settled)return false;return true}cancelWaits(){for(let e of [...this.waits])e();}onUnresolved(e){return this.unresolvedCbs.add(e),()=>this.unresolvedCbs.delete(e)}reportUnresolved(e){let t=this.names();console.warn(`[vela] symbol "${e}" not yet resolvable \u2014 registered providers: [${t.join(", ")||"none"}]. Register a provider that serves it.`);for(let n of this.unresolvedCbs)n({symbol:e,providers:t});}candidateOrder(e){let t=this.names();if(e){let n=Ln(e);if(this.entries.has(n))return [n,...t.filter(i=>i!==n)]}return t}displayPrefixOf(e){return this.entries.get(e.provider)?.byTicker?.get(Xn(e.ticker))?.prefix??e.provider}canonicalSymbol(e){let t=this.entries.get(e.provider)?.byTicker?.get(Xn(e.ticker));return `${t?.prefix??e.provider}:${t?.ticker??e.ticker}`}symbolIconOf(e){let t=e.provider?Ln(e.provider):[...this.entries.keys()][0],n=t!==void 0?this.entries.get(t):void 0;try{return n?.provider.resolveSymbolIcon?.(e)??void 0}catch{return}}symbolIcon(e){if(!e)return;let t=this.entries.get(e.provider)?.byTicker?.get(Xn(e.ticker));return this.symbolIconOf({...t??{ticker:e.ticker},provider:t?.provider??e.provider})}symbolsOf(e){return e!=null?this.entries.get(Ln(e))?.descriptors??[]:[...this.entries.entries()].flatMap(([t,n])=>n.descriptors.map(i=>({...i,provider:t})))}infoOf(e){let t=Ln(e),n=this.entries.get(t);if(!n)return {name:t,capabilities:{enumerate:false,stream:false,symbolInfo:false}};let i=n.provider;return i.info?.()??{name:n.name,capabilities:{enumerate:!!i.listSymbols,stream:!!i.subscribe,symbolInfo:!!i.getSymbolInfo}}}indexReady(){return Promise.all([...this.entries.values()].map(e=>e.settle)).then(()=>{})}};var $E=c("chart.settings.rangeMin","{label} \u2014 min"),YE=c("chart.settings.rangeMax","{label} \u2014 max");function ao(r){switch(r.kind){case "row":return {label:r.label,toggle:r.toggle,controls:r.controls,when:r.when};case "toggle":{let e=[];r.number&&e.push({kind:"number",...r.number});for(let t of r.colors??[])e.push({kind:"color",...t});return r.width&&e.push({kind:"width",...r.width}),{label:r.label,toggle:{key:r.key,defval:r.defval},controls:e,when:r.when}}case "number":return {label:r.label,controls:[{kind:"number",key:r.key,label:r.label,defval:r.defval,min:r.min,max:r.max,step:r.step}],when:r.when};case "color":return {label:r.label,controls:[{kind:"color",key:r.key,label:r.label,defval:r.defval}],when:r.when};case "select":return {label:r.label,controls:[{kind:"select",key:r.key,label:r.label,options:r.options,defval:r.defval}],when:r.when};case "range":return {label:r.label,controls:[{kind:"number",key:r.minKey,label:We($E,{label:r.label}),defval:r.defval,min:r.min,max:r.max,step:r.step,placeholder:r.placeholder},{kind:"hint",text:"\u2013"},{kind:"number",key:r.maxKey,label:We(YE,{label:r.label}),defval:r.defval,min:r.min,max:r.max,step:r.step,placeholder:r.placeholder}],when:r.when}}}function Ps(r){if(r.kind==="heading"||r.kind==="header")return [];let e=ao(r),t=[];e.toggle&&t.push({key:e.toggle.key,type:"boolean",defval:e.toggle.defval});for(let n of e.controls)n.kind!=="hint"&&(n.kind==="color"||n.kind==="select"?t.push({key:n.key,type:"string",defval:n.defval}):t.push({key:n.key,type:"number",defval:n.defval}));return t}function gi(r,e){return r?(Array.isArray(r)?r:[r]).every(n=>n.anyOf?n.anyOf.some(i=>i===e[n.key]):e[n.key]===n.equals):true}var Is=new Map;function Yh(r){Is.set(r.id,r);}function KE(r){Is.delete(r);}function jn(r){return typeof r=="string"?Is.get(r):void 0}function Yt(){return [...Is.values()]}function Kh(){return [...Is.values()].filter(r=>r.tickerModifier??r.barTransform!=null).map(r=>r.id)}function lo(r){return jn(r)?.barTransform??null}function Mv(r){let e=r.lastIndexOf(";");if(e<=0||e===r.length-1)return {symbol:r,modifier:null,transform:null};let t=r.slice(e+1).toLowerCase();return t!=="standard"&&!Kh().includes(t)?{symbol:r,modifier:null,transform:null}:{symbol:r.slice(0,e),modifier:t,transform:lo(t)}}var En={background:"#151619",textColor:"#b2b5be",gridColor:"#20222c",borderColor:"#2a2b30",upColor:N,downColor:O,fontFamily:"sans-serif"},As={background:"#ffffff",textColor:"#1e293b",gridColor:"#cccccc",borderColor:"#d4dae3",upColor:N,downColor:O,fontFamily:"sans-serif"};function co(r){return !r||r==="dark"?En:r==="light"?As:r}function qn(r){return r!=null&&typeof r!="string"?r:void 0}function Wt(r,e={}){let{title:t,tooltip:n,display:i,...o}=r,s={...i},a=qn(t);a&&!s.title&&(s.title=a);let l=qn(n);l&&!s.tooltip&&(s.tooltip=l);let d=o.group!=null?e.groups?.[o.group]:void 0;if(d&&!s.group&&(s.group=d),o.options&&e.options&&!s.options){let h={},p=false;for(let m of o.options){let g=e.options[m];g&&(h[m]=g,p=true);}p&&(s.options=h);}let u={...o,title:Re(t)};return n!=null&&(u.tooltip=Re(n)),Object.keys(s).length>0&&(u.display=s),u}var XE=150,jE=1e3,qE=300,ZE=5e3,Ev=1e4,QE=20,JE=1.5,Pv=5e3,eP=16,Vc=class r{constructor(e,t,n,i,o,s){this.renderer=t;this.feed=n;this.config=o;this.dataControl=s;this.events=new jr;this.registry=new al;this.paneOrder=["price"];this.collapsedPanes=new Set;this.maximizedPaneId=null;this.paneActionUnsub=null;this.i18n=Ae();this.handles=new Map;this.engines=new Map;this.live=null;this.bars=[];this.rawBars=[];this.barTransform=null;this.typeEngines=new Map;this.suspendedEngines=new WeakSet;this.typeSettings=new Map;this.activeEngineStyle=null;this.priceStyle="candles";this.priceStyleWillChangeUnsub=null;this.unresolvedUnsub=null;this.visibleRange=null;this.viewportUnsub=null;this.viewportTimer=null;this.healing=false;this.healBuffer=[];this.lastHealAt=0;this.onVisible=null;this.replayQueue=null;this.replayTimer=null;this.replayPlaying=false;this.replayIntervalMs=1e3;this.replayDepth=null;this.replayLoading=null;this.replayCarrying=null;this.replayTickSource=null;this.replayForming=null;this.replayTickFetches=new Map;this.replayTickAbort=null;this.barCause="tick";this.historyState="complete";this.generation=0;this.progressiveAbort=null;this.supersedeWaiters=[];this.historyCompleted=false;this.historyCompletePromise=new Promise(e=>{this.resolveHistoryComplete=e;});this.switchingMarket=false;this.loadingUp=false;this.volumeOptedOut=false;this.contextEmitAt=new Map;this.runEmitAt=new Map;for(let d of i)this.registerEngine(d.language,d);this.defaultLanguage=o.defaultLanguage,this.renderer.mount(e,o.theme),this.renderer.onInputChange(d=>d.kind==="prop"?this.applyProps(d.indicatorId,{[d.key]:d.value}):this.applyInputs(d.indicatorId,{[d.key]:d.value})),this.renderer.onRemoveIndicator(d=>this.removeIndicator(d)),this.renderer.onToggleIndicatorVisible?.((d,u)=>this.setVisible(d,u)),this.paneActionUnsub=this.renderer.onPaneAction?.(d=>this.handlePaneAction(d))??null,this.renderer.onChartTypeSettingsChange?.((d,u)=>{this.typeSettings.set(d,u),this.typeEngines.get(d)?.onSettings?.(u);}),this.renderer.onMoveIndicator?.((d,u)=>this.moveIndicator(d,u)),this.renderer.onThemeSelect?.(d=>this.setTheme(co(d))),this.viewportUnsub=this.renderer.onViewportChange(d=>this.onViewportChange(d)),this.renderer.onPriceStyleChange?.(d=>this.syncPriceStyle(d)),this.priceStyleWillChangeUnsub=this.renderer.onPriceStyleWillChange?.((d,u)=>this.events.emit("priceStyle:change",{from:d,to:u}))??null;let a=this.renderer.readFeature("priceStyle");typeof a=="string"&&(this.priceStyle=a),this.barTransform=lo(a);let l=new Fc({fetchBars:(d,u)=>this.fetchSeries(this.config.market.symbol??"",d,u),canFetch:()=>!!this.feed.loadRange&&!this.config.market.data?.length&&!!this.config.market.symbol,chartTimeframe:()=>this.config.market.timeframe??"60",marketKey:()=>`${this.config.market.symbol??""}|${this.config.market.session??""}`});this.drawings=new Rc(this.renderer,this.events,o.drawings,l,()=>this.i18n),this.marks=new Nc(this.renderer,this.events),this.unresolvedUnsub=this.feed.onUnresolved?.(d=>{this.endLoad(),this.events.emit("data:unresolved",d);})??null,this.readyPromise=this.init(),jn(a)?.dataEngine&&this.syncChartTypeEngine(a);}currentVisibleRange(){if(this.visibleRange)return this.visibleRange;let e=this.renderer.getVisibleRange();return e?{left:e.from,right:e.to}:void 0}engineFor(e){let t=e??this.defaultLanguage,n=this.engines.get(t);if(!n)throw new Error(`[vela] no scripting engine registered for language "${t}". Vela ships none \u2014 install one (Pine Script: @luxalgo/vela-pinets) and register it before addIndicator, e.g. chart.registerEngine('pine', new PineEngine()).`);return n}market(){return {symbol:this.config.market.symbol??"TEST",timeframe:this.config.market.timeframe??"60",symbolInfo:this.feed.symbolInfo?.(this.config.market),chartStyle:this.priceStyle,session:this.config.market.session}}async fetchSeries(e,t,n){let i=Mv(e),o={symbol:i.symbol,timeframe:t},s=await(this.feed.loadRange?this.feed.loadRange(o,n):this.feed.load({...o,bars:n.limit}));return i.transform?i.transform.full(s):s}onViewportChange(e){this.visibleRange={left:e.from,right:e.to},this.events.emit("viewport:changed",{from:e.from,to:e.to}),this.viewportTimer!=null&&clearTimeout(this.viewportTimer),this.viewportTimer=setTimeout(()=>{if(this.viewportTimer=null,this.switchingMarket)return;let t=this.visibleRange;if(t){for(let n of this.registry.all())!n.renderHandle||n.hidden||(n.session&&n.prepared?.reactsToViewport?(n.pendingCause="viewport",n.session.setVisibleRange(t)):n.native?.descriptor.reactsToViewport&&n.native.instance.onViewport({from:t.left,to:t.right}));this.activeEngineStyle&&this.typeEngines.get(this.activeEngineStyle)?.onViewport?.({from:t.left,to:t.right});}},XE);}async init(){let e=this.bumpGeneration();this.beginLoad(true),await this.loadMarket(e,{firstLoad:true}),this.generation===e&&(this.startLive(),this.events.emit("ready",void 0));}bumpGeneration(){let e=++this.generation;this.progressiveAbort?.abort(),this.progressiveAbort=null;for(let t of this.supersedeWaiters.splice(0))t();return e}beginLoad(e){if(this.loadingUp)return;this.loadingUp=true,this.renderer.setLoading?.(true);let t=this.config.market;this.events.emit("load:start",{symbol:t.symbol??"TEST",timeframe:t.timeframe??"60",firstLoad:e});}endLoad(){if(!this.loadingUp)return;this.loadingUp=false,this.renderer.setLoading?.(false);let e=this.config.market;this.events.emit("load:end",{symbol:e.symbol??"TEST",timeframe:e.timeframe??"60",bars:this.bars.length});}async loadMarket(e,t){try{await this.loadMarketInner(e,t);}finally{this.generation===e&&this.endLoad();}}async loadMarketInner(e,t){let n=this.config.market,i=n.bars??500,o=n.visibleRange,s=!n.data?.length&&o==null&&i>ZE,a=false;if(!n.data?.length&&o==null&&this.feed.loadProgressive){let l=false,d=(h,p)=>{if(this.generation!==e||!p&&h.length===0||!l&&!p&&h.length<Math.min(i,QE))return;if(l&&this.replayQueue){this.mergeHistoryIntoReplay(h);return}let m=l;this.setBarSeries(h,m?{preserveView:true}:void 0),!l&&h.length>0&&(l=true,t.firstLoad&&this.activateBarLayers(),p||(this.historyState="backfill")),m&&!p&&this.notifySessionsBars("backfill");},u=new AbortController;this.progressiveAbort=u,a=await new Promise(h=>{let p=false,m=g=>{p||(p=true,h(g));};u.signal.addEventListener("abort",()=>m(true),{once:true}),this.feed.loadProgressive(n,g=>{d(g,false),l&&m(true);},{signal:u.signal}).then(g=>{if(this.progressiveAbort===u&&(this.progressiveAbort=null),g==null)return m(false);if(this.generation!==e)return m(true);d(g,true),this.completeHistory(g.length>=i?"depth":"genesis"),m(true);}).catch(()=>{this.progressiveAbort===u&&(this.progressiveAbort=null),this.generation===e&&this.completeHistory("aborted"),m(true);});});}if(!a)if(s&&this.feed.loadRange){let l=await this.feed.load({...n,bars:Math.min(i,Ev)});if(this.generation!==e)return;this.setBarSeries(l),t.firstLoad&&this.activateBarLayers(),l.length>0&&i>l.length?(this.historyState="backfill",this.backfillHistory(e,i)):this.completeHistory("depth");}else if(s){let l=await this.feed.load({...n,bars:qE});if(this.generation!==e)return;this.setBarSeries(l),t.firstLoad&&this.activateBarLayers();let d=await this.feed.load(n);if(this.generation!==e)return;this.setBarSeries(d,{preserveView:true}),this.completeHistory("depth");}else {let l=await this.feed.load(n);if(this.generation!==e)return;this.setBarSeries(l),t.firstLoad&&this.activateBarLayers(),this.completeHistory("depth");}o!=null&&(typeof o=="string"?this.setVisibleRangePreset(o):this.renderer.setVisibleRange(o)),this.refreshPriceFormat(),this.ensurePriceFormat();}startLive(){this.config.live&&(this.live=new fl(this.feed,this.config.market,e=>this.onBar(e)),this.live.start(),typeof document<"u"&&(this.onVisible=()=>{if(document.visibilityState!=="visible")return;let e=this.bars[this.bars.length-1];!e||this.healing||!this.canHeal()||Date.now()-this.lastHealAt<=Pv||this.healGap(e.time);},document.addEventListener("visibilitychange",this.onVisible)));}stopLive(){this.live?.stop(),this.live=null,this.onVisible&&typeof document<"u"&&document.removeEventListener("visibilitychange",this.onVisible),this.onVisible=null,this.healing=false,this.healBuffer=[],this.lastHealAt=0;}resetHistoryTracking(){this.resolveHistoryComplete(),this.historyCompleted=false,this.historyState="complete",this.historyCompletePromise=new Promise(e=>{this.resolveHistoryComplete=e;});}marketSnapshot(){let e=this.config.market;return {symbol:e.symbol,provider:Mn(e.symbol??"").provider??void 0,timeframe:e.timeframe,bars:e.bars,session:e.session,offline:e.data!==void 0}}async setMarket(e){let t=this.config.market,n=e.symbol!==void 0&&e.symbol!==t.symbol||e.timeframe!==void 0&&e.timeframe!==t.timeframe||e.session!==void 0&&e.session!==t.session||e.data!==void 0,i=e.bars!==void 0&&e.bars!==t.bars,o=n&&e.data===void 0&&(e.symbol===void 0||e.symbol===t.symbol)&&(e.timeframe!==void 0||e.session!==void 0),s=n?this.replayCarrying:null;s&&(this.replayCarrying=null,o||(s.cancelled=true,this.events.emit("replay:end",{reason:"market"})));let a=this.replayQueue&&o&&this.rawBars.length>0?{revealedEnd:this.rawBars[this.rawBars.length-1].time+this.barIntervalMs(),playing:this.replayPlaying,cancelled:false}:s&&o?{revealedEnd:s.revealedEnd,playing:s.playing,cancelled:false}:null;if(s&&(s.cancelled=true),a&&(this.replayCarrying=a),a&&this.replayQueue){this.endReplay(null,{restore:false,resume:false});let w=this.replayDepth;this.replayDepth=null,w&&e.bars===void 0&&(w.bars===void 0?delete t.bars:t.bars=w.bars);}if(this.replayQueue&&(n||i)&&this.endReplay("market",{restore:!n,resume:false}),this.replayLoading&&(n||i)){let w=this.replayDepth;this.abandonReplayLoad("market"),w&&e.bars===void 0&&(w.bars===void 0?delete t.bars:t.bars=w.bars);}let l=i&&!n&&this.rawBars.length>0&&!t.data?.length&&((e.bars??0)<=this.rawBars.length||typeof this.feed.loadRange=="function");if(!n&&!i){typeof e.visibleRange=="string"?this.setVisibleRangePreset(e.visibleRange):e.visibleRange&&this.renderer.setVisibleRange(e.visibleRange);return}let d={symbol:t.symbol??"TEST",timeframe:t.timeframe??"60"},h=n&&e.session!==void 0&&e.data===void 0&&(e.symbol===void 0||e.symbol===t.symbol)&&(e.timeframe===void 0||e.timeframe===t.timeframe)&&e.visibleRange===void 0?this.currentVisibleRange():void 0,p=h?this.rawBars.filter(w=>w.time>=h.left&&w.time<=h.right).length:0,m=this.bumpGeneration();this.switchingMarket=true;try{if(this.stopLive(),this.viewportTimer!=null&&(clearTimeout(this.viewportTimer),this.viewportTimer=null),this.visibleRange=null,this.resetHistoryTracking(),e.symbol!==void 0&&(t.symbol=e.symbol),e.timeframe!==void 0&&(t.timeframe=e.timeframe),e.bars!==void 0&&(t.bars=e.bars),e.session!==void 0&&(t.session=e.session),h){let w=Math.min(Math.ceil((Date.now()-h.left)/this.barIntervalMs())+50,5e3);w>(t.bars??500)&&(t.bars=w);}if(e.data!==void 0?t.data=e.data:e.symbol!==void 0&&delete t.data,t.visibleRange=e.visibleRange??(h?{from:h.left,to:h.right}:void 0),n){this.beginLoad(!1),this.setBarSeries([],{clearing:!0}),this.blankIndicatorVisuals(),this.activeEngineStyle&&(this.suspendTypeEngine(this.typeEngines.get(this.activeEngineStyle)),this.renderer.setNativeData?.(this.activeEngineStyle,void 0),this.renderer.setNativeData?.(`${this.activeEngineStyle}-pending`,[]));for(let w of this.registry.all())w.native?.started&&(this.stopNativeInstance(w.native),this.renderer.setNativeData?.(this.nativeChannel(w),void 0));}if(l?this.extendDepth(m,t.bars??500):await Promise.race([this.loadMarket(m,{firstLoad:!1}),new Promise(w=>this.supersedeWaiters.push(w))]),this.generation!==m)return}finally{this.generation===m&&(this.switchingMarket=false);}if(h&&p>=2&&this.rawBars.length>0){let w=this.rawBars,x=w.length-1;for(;x>0&&w[x].time>h.right;)x-=1;let T=w[Math.max(0,x-(p-1))].time;this.renderer.setVisibleRange({from:T,to:Math.max(h.right,w[x].time+1)});}let g=a&&!a.cancelled?a:null,b=g?g.revealedEnd-this.barIntervalMs():0,f=g!=null&&this.rawBars.length>0&&b>=this.rawBars[0].time,v=f&&this.resumeCarriedReplay(this.replayStart({from:b}),g);!l&&!v&&(this.restartNativeIndicators(),this.restartChartTypeEngine(),this.reexecuteIndicators()),l&&this.releaseHeldNatives(),v||this.startLive(),n&&this.events.emit("market:changed",{symbol:t.symbol??"TEST",timeframe:t.timeframe??"60",prev:d}),g&&!f&&this.resumeCarriedReplay(this.replayStart({from:b}),g);}restartNativeIndicators(){for(let e of this.registry.all())if(e.native)if(this.stopNativeInstance(e.native),e.native.instance=e.native.descriptor.create(),e.pendingStructural=true,e.hidden)e.native.stale=true;else {let t=this.handles.get(e.id);t&&this.startNativeIndicator(e.id,t);}}restartChartTypeEngine(){for(let e of this.typeEngines.values())e.stop();this.typeEngines.clear(),this.activeEngineStyle&&this.startChartTypeEngine(this.activeEngineStyle);}suspendTypeEngine(e){e&&(e.suspend(),this.suspendedEngines.add(e));}stopNativeInstance(e){e.started&&e.instance.stop(),e.started=false,e.revokeContext?.(),e.revokeContext=void 0;}activateBarLayers(){this.maybeAutoAddVolume();}extendDepth(e,t){if(this.rawBars.length>t){this.setBarSeries(this.rawBars.slice(this.rawBars.length-t),{preserveView:true}),this.completeHistory("depth");return}if(this.rawBars.length===t){this.completeHistory("depth");return}this.historyState="backfill",this.backfillHistory(e,t);}async backfillHistory(e,t){try{for(;this.generation===e&&this.rawBars.length<t&&this.rawBars.length>0;){let n=t-this.rawBars.length,i=Ev,o=await this.feed.loadRange(this.config.market,{to:this.rawBars[0].time,limit:Math.min(i,n)+1});if(this.generation!==e)return;let s=this.rawBars[0].time,a=o.filter(l=>l.time<s);if(a.length===0){this.completeHistory("genesis");return}for(let l=1;l<a.length;l+=1)if(a[l].time<=a[l-1].time){console.warn("[vela] non-monotonic history chunk \u2014 stopping the backfill"),this.completeHistory("aborted");return}this.setBarSeries([...a,...this.rawBars],{preserveView:!0}),this.notifySessionsBars("backfill"),this.events.emit("history:progress",{loaded:this.rawBars.length,target:t});}this.generation===e&&this.completeHistory("depth");}catch(n){console.warn(`[vela] history backfill failed \u2014 keeping ${this.rawBars.length} bars (${n instanceof Error?n.message:String(n)})`),this.generation===e&&this.completeHistory("aborted");}}completeHistory(e){this.historyCompleted||(this.historyCompleted=true,this.historyState="complete",this.notifySessionsBars("complete"),this.events.emit("history:complete",{reason:e,oldestTime:this.rawBars[0]?.time??0,barsLoaded:this.rawBars.length}),this.resolveHistoryComplete());}historyComplete(){return this.historyCompletePromise}async replayStart(e){if(this.rawBars.length===0){console.warn("[vela] chart.replay.start() ignored \u2014 the chart has no bars yet");return}let t=this.generation;if(e.from<this.rawBars[0].time&&(await this.historyCompletePromise,this.generation!==t||this.rawBars.length===0))return;let n=this.rawBars[0].time;if(e.from<n&&this.canHeal()&&typeof this.feed.loadRange=="function"){let l=this.rawBars.length+(this.replayQueue?.length??0)+Math.ceil((n-e.from)/this.barIntervalMs())+1,d=this.replayQueue!==null;d&&this.endReplay(null,{restore:true,resume:false}),this.replayDepth??(this.replayDepth={bars:this.config.market.bars});let u=this.setMarket({bars:l});if(this.replayLoading={seek:d},await u,t=this.generation,await this.historyCompletePromise,!this.replayLoading||this.generation!==t||this.rawBars.length===0)return;this.replayLoading=null;}this.settleFormingBar(),this.dropTickFetches();let i=this.replayQueue?[...this.rawBars,...this.replayQueue]:this.rawBars,o=0;for(;o<i.length&&i[o].time<=e.from;)o+=1;if(o=Math.max(1,o),o>=i.length){console.warn("[vela] chart.replay.start() ignored \u2014 no bar opens after the requested time");return}let s=this.replayPlaying;this.clearReplayTimer(),this.replayQueue||this.stopLive(),this.replayQueue=i.slice(o),this.setBarSeries(i.slice(0,o)),this.restartBarConsumers({blank:true}),s&&this.events.emit("replay:pause",void 0),this.events.emit("replay:start",{cursorTime:i[o-1].time,remaining:this.replayQueue.length}),this.prefetchTicks();}replayStep(){if(this.replayForming)return this.finishFormingBar(),true;let e=this.replayQueue,t=e?.shift();return !e||!t?false:(this.replayTickFetches.delete(t.time),this.applyBar(t),this.completeReveal(t),this.prefetchTicks(),true)}resumeCarriedReplay(e,t){return this.replayQueue&&this.replayCarrying===t&&(this.replayCarrying=null),e.then(()=>{this.replayCarrying===t&&(this.replayCarrying=null),!t.cancelled&&(this.replayQueue?t.playing&&this.replayPlay():this.events.emit("replay:end",{reason:"market"}));}),this.replayQueue!==null}replayStepUpdate(){if(!this.replayQueue)return false;if(this.replayForming)return this.applyReplayTicks(1),true;let e=this.replayQueue[0];if(!e)return false;let t=this.replayTickSource?this.requestTicks(e):null;if(t&&!t.ticks){let n=this.replayTickAbort;return t.done.then(()=>{!this.replayPlaying&&!this.replayForming&&this.replayTickAbort===n&&this.replayQueue?.[0]===e&&this.replayStepUpdate();}),true}return t?.ticks?.length?(this.openFormingBar(t.ticks,1),true):this.replayStep()}replaySetTicks(e){this.finishFormingBar(),this.dropTickFetches(),this.replayTickSource=e,this.prefetchTicks();}replayPlay(e){if(this.replayQueue){if(e!==void 0){if(!(Number.isFinite(e)&&e>0)){console.warn(`[vela] chart.replay.play(${e}) ignored \u2014 the interval must be a positive number of ms`);return}this.replayIntervalMs=e;}this.clearReplayTimer(),this.replayPlaying=true,this.replayForming&&this.paceFormingBar(this.replayForming),this.scheduleReplayStep(this.replayForming?.delayMs),this.events.emit("replay:play",{intervalMs:this.replayIntervalMs});}}replayPause(){this.replayPlaying&&(this.clearReplayTimer(),this.events.emit("replay:pause",void 0));}replayStop(){let e=this.replayCarrying;if(e&&(e.cancelled=true,this.replayCarrying=null,this.events.emit("replay:end",{reason:"stopped"})),this.replayLoading){let t=this.replayDepth;this.abandonReplayLoad("stopped"),this.setMarket({bars:t?.bars??500});return}this.endReplay("stopped",{restore:true,resume:true});}abandonReplayLoad(e){let t=this.replayLoading;t&&(this.replayLoading=null,this.replayDepth=null,t.seek&&this.events.emit("replay:end",{reason:e}));}replayState(){let e=this.replayQueue!==null;return {active:e||this.replayCarrying!==null,playing:this.replayCarrying?.playing??this.replayPlaying,cursorTime:e?this.rawBars[this.rawBars.length-1]?.time??null:null,remaining:this.replayQueue?.length??0,nextTime:this.replayForming?.bar.time??this.replayQueue?.[0]?.time??null,intervalMs:this.replayIntervalMs}}replayBounds(){let e=this.rawBars[0],t=this.replayQueue?.[this.replayQueue.length-1]??this.rawBars[this.rawBars.length-1];return e&&t?{first:e.time,last:t.time}:null}scheduleReplayStep(e=this.replayIntervalMs){this.replayTimer=setTimeout(()=>{this.replayTimer=null,this.replayAdvance();},e);}replayAdvance(){if(!this.replayPlaying||!this.replayQueue)return;let e=this.replayForming;if(e){let i=Math.floor((Iv()-e.origin)/this.replayIntervalMs)+1;this.applyReplayTicks(Math.max(e.batch,i-e.next)),this.replayPlaying&&this.scheduleReplayStep(e.delayMs);return}let t=this.replayQueue[0];if(!t)return;let n=this.replayTickSource?this.requestTicks(t):null;if(n&&!n.ticks){let i=this.replayTickAbort;n.done.then(()=>{this.replayPlaying&&this.replayTimer==null&&this.replayTickAbort===i&&this.replayQueue?.[0]===t&&this.replayAdvance();});return}if(!n?.ticks?.length){this.replayStep()&&this.replayPlaying&&this.scheduleReplayStep();return}this.openFormingBar(n.ticks),this.replayPlaying&&this.scheduleReplayStep(this.replayForming?.delayMs);}openFormingBar(e,t){let n=this.replayQueue.shift(),i=e.every(s=>s.volume===void 0)?(n.volume??0)/e.length:null,o={bar:n,ticks:e,next:0,candle:null,volumeEach:i,batch:1,delayMs:this.replayIntervalMs,origin:0};this.paceFormingBar(o),this.replayForming=o,this.applyReplayTicks(t??o.batch),this.prefetchTicks();}paceFormingBar(e){e.batch=Math.max(1,Math.ceil(eP/this.replayIntervalMs)),e.delayMs=this.replayIntervalMs*e.batch,e.origin=Iv()-Math.max(0,e.next-1)*this.replayIntervalMs;}applyReplayTicks(e){let t=this.replayForming;if(!t)return;let n=t.candle,i=Math.min(t.ticks.length,t.next+e);for(;t.next<i;t.next+=1){let o=t.ticks[t.next],s=t.volumeEach??o.volume??0,a=Math.max(o.high??o.price,o.price),l=Math.min(o.low??o.price,o.price);if(n)n={...n,high:Math.max(n.high,a),low:Math.min(n.low,l),close:o.price,volume:(n.volume??0)+s};else {let d=o.open??o.price;n={time:t.bar.time,open:d,high:Math.max(d,a),low:Math.min(d,l),close:o.price,volume:s};}}if(t.candle=n,t.next>=t.ticks.length){this.finishFormingBar();return}this.applyBar(n),this.events.emit("replay:tick",{cursorTime:t.bar.time,index:t.next-1,count:t.ticks.length});}finishFormingBar(){let e=this.replayForming;e&&(this.replayForming=null,this.replayTickFetches.delete(e.bar.time),this.applyBar(e.bar),this.events.emit("replay:tick",{cursorTime:e.bar.time,index:e.ticks.length-1,count:e.ticks.length}),this.completeReveal(e.bar));}settleFormingBar(){let e=this.replayForming;e&&(this.replayForming=null,this.applyBar(e.bar));}mergeHistoryIntoReplay(e){let t=this.replayQueue,n=this.rawBars[0];if(!t||!n)return;let i=t[t.length-1]??this.rawBars[this.rawBars.length-1],o=0;for(;o<e.length&&e[o].time<n.time;)o+=1;let s=e.length;for(;s>o&&e[s-1].time>i.time;)s-=1;s<e.length&&t.push(...e.slice(s)),o>0&&(this.setBarSeries([...e.slice(0,o),...this.rawBars],{preserveView:true}),this.notifySessionsBars("backfill"));}completeReveal(e){let t=this.replayQueue;t&&(this.events.emit("replay:step",{cursorTime:e.time,remaining:t.length}),t.length===0&&this.endReplay("finished",{restore:true,resume:true}));}prefetchTicks(){let e=this.replayQueue?.[0];e&&this.replayTickSource&&this.requestTicks(e);}requestTicks(e){let t=this.replayTickFetches.get(e.time);if(t)return t;let n=this.replayTickSource;this.replayTickAbort??(this.replayTickAbort=new AbortController);let i=this.replayTickAbort.signal,o=this.replayQueue??[],s=o[o.indexOf(e)+1]?.time??e.time+this.barIntervalMs(),a={ticks:null,done:Promise.resolve()},l=u=>{a.ticks=tP(u);},d=u=>{i.aborted||console.warn(`[vela] replay tick source failed \u2014 revealing the bar whole (${u instanceof Error?u.message:String(u)})`),l([]);};try{let u=n(e,{end:s,signal:i});Array.isArray(u)?l(u):a.done=Promise.resolve(u).then(l,d);}catch(u){d(u);}return this.replayTickFetches.set(e.time,a),a}dropTickFetches(){this.replayTickAbort?.abort(),this.replayTickAbort=null,this.replayTickFetches.clear();}clearReplayTimer(){this.replayTimer!=null&&clearTimeout(this.replayTimer),this.replayTimer=null,this.replayPlaying=false;}endReplay(e,t){let n=this.replayQueue;if(!n)return;this.clearReplayTimer(),t.restore?this.settleFormingBar():this.replayForming=null,this.dropTickFetches(),this.replayQueue=null;let i=e?this.replayDepth:null;if(e&&(this.replayDepth=null),i&&(i.bars===void 0?delete this.config.market.bars:this.config.market.bars=i.bars),t.restore){let o=i?i.bars??500:1/0;if(n.length>0||this.rawBars.length>o){let s=[...this.rawBars,...n];this.setBarSeries(s.length>o?s.slice(s.length-o):s),this.restartBarConsumers({blank:false});}else this.config.live&&(this.restartNativeIndicators(),this.restartChartTypeEngine());}if(t.resume&&this.config.live){this.startLive();let o=this.rawBars[this.rawBars.length-1];o&&this.canHeal()&&this.healGap(o.time);}e&&this.events.emit("replay:end",{reason:e});}restartBarConsumers(e){e.blank&&this.blankIndicatorVisuals(),this.restartNativeIndicators(),this.restartChartTypeEngine(),this.reexecuteIndicators();}qualifiedSymbol(){let e=this.config.market;return e.symbol?e.symbol:null}refreshPriceFormat(){if(!this.renderer.setPricePrecision)return;let e=this.feed.symbolInfo?.(this.config.market)?.mintick;this.renderer.setPricePrecision(typeof e=="number"&&e>0?e:void 0);}async ensurePriceFormat(){if(!this.renderer.setPricePrecision)return;let e=this.qualifiedSymbol();if(e)try{await this.dataControl.symbolInfo(e),this.refreshPriceFormat();}catch{}}maybeAutoAddVolume(){!this.config.volume||this.volumeOptedOut||!this.renderer.setNativeData||Th("volume")&&this.addNativeIndicator("volume");}syncPriceStyle(e){typeof e=="string"&&(this.priceStyle=e),this.syncBarTransform(e),this.syncChartTypeEngine(e);}syncChartTypeEngine(e){let t=typeof e=="string"?e:null,i=jn(t)?.dataEngine?t:null;i!==this.activeEngineStyle&&(this.activeEngineStyle&&this.suspendTypeEngine(this.typeEngines.get(this.activeEngineStyle)),this.activeEngineStyle=i,i&&this.startChartTypeEngine(i));}async startChartTypeEngine(e){if(!this.renderer.setNativeData||(await this.readyPromise,this.activeEngineStyle!==e))return;let t=this.typeEngines.get(e);if(t){this.suspendedEngines.delete(t),t.resume();return}let n=jn(e);if(!n?.dataEngine)return;let i=n.dataEngine();this.typeEngines.set(e,i);let o=this.typeSettings.get(e);o&&i.onSettings?.(o);let s=()=>this.typeEngines.get(e)===i&&!this.suspendedEngines.has(i);i.start({symbol:this.config.market.symbol??"TEST",timeframe:this.config.market.timeframe??"60",live:(this.config.live??false)&&this.replayQueue===null,session:this.config.market.session,bars:()=>this.bars,data:this.dataControl,pushData:a=>{s()&&this.renderer.setNativeData?.(e,a);},pushPending:a=>{s()&&this.renderer.setNativeData?.(`${e}-pending`,a);}});}syncBarTransform(e){let t=lo(e);if(t!==this.barTransform&&(this.barTransform=t,this.rawBars.length!==0&&(this.bars=t?t.full(this.rawBars):this.rawBars,this.renderer.setBars(this.bars,{preserveView:true}),this.reexecuteIndicators(),!this.switchingMarket)))for(let n of this.registry.all())n.native?.started&&n.renderHandle&&!n.hidden&&this.pokeNative(n);}blankIndicatorVisuals(){for(let e of this.registry.all())e.hidden||!e.renderHandle||!e.model||(e.model=iP(e.model),e.renderHandle=this.renderer.mountIndicator(e.model),e.pendingStructural=true,this.setLoading(e,true));}reexecuteIndicators(){for(let e of this.registry.all()){if(e.hidden||!e.session)continue;e.session.stop(),e.session=void 0,e.pendingStructural=true,e.pendingCause="market",this.setLoading(e,true);let t=this.handles.get(e.id);t&&this.executeIndicator(e.id,t);}}onBar(e){if(this.healing){this.healBuffer.push(e);return}let t=this.rawBars[this.rawBars.length-1];if(t&&this.canHeal()&&e.time>t.time+this.barIntervalMs()*JE&&Date.now()-this.lastHealAt>Pv){this.healBuffer.push(e),this.healGap(t.time);return}this.applyBar(e);}setBarSeries(e,t){this.rawBars=e,this.bars=this.barTransform?this.barTransform.full(e):e,this.renderer.setBars(this.bars,{preserveView:t?.preserveView}),!t?.clearing&&this.bars.length>0&&this.endLoad();}applyBar(e,t=true){let n=this.rawBars[this.rawBars.length-1],i=e;if(n&&e.time===n.time)this.rawBars[this.rawBars.length-1]=e,this.barCause="tick",this.barTransform&&(i=this.barTransform.next(e,this.bars[this.bars.length-2]),this.bars[this.bars.length-1]=i);else if(!n||e.time>n.time)this.rawBars.push(e),this.barCause="bar",this.barTransform&&(i=this.barTransform.next(e,this.bars[this.bars.length-1]),this.bars.push(i));else return;this.renderer.updateBar(i),this.events.emit("bar",e),t&&this.notifySessionsBars(this.historyState==="backfill"?"backfill":void 0);}notifySessionsBars(e){if(this.switchingMarket)return;let t=e?"history":this.barCause;for(let n of this.registry.all())!n.renderHandle||n.hidden||(n.session?(n.pendingCause=t,n.session.notifyBars(e)):n.native&&this.pokeNative(n));this.activeEngineStyle&&this.typeEngines.get(this.activeEngineStyle)?.onBars?.();}pokeNative(e){let t=e.native;if(!t.descriptor.waitsForHistory){t.instance.onBars();return}if(this.historyState!=="backfill"){if(t.heldForHistory){t.heldForHistory=false;let n=this.handles.get(e.id);n&&this.startNativeIndicator(e.id,n);return}t.started&&t.instance.onBars();}}releaseHeldNatives(){if(this.historyState!=="backfill")for(let e of this.registry.all())e.native?.heldForHistory&&!e.hidden&&this.pokeNative(e);}canHeal(){return !!this.feed.loadRange&&!this.config.market.data?.length}barIntervalMs(){return an(this.config.market.timeframe??"60")}async healGap(e){let t=this.generation;this.healing=true,this.lastHealAt=Date.now();try{let n=await this.feed.loadRange(this.config.market,{from:e});if(this.generation!==t||this.replayQueue)return;for(let i of n)this.applyBar(i,!1);}catch{}finally{if(this.generation===t&&!this.replayQueue){this.healing=false;let n=this.healBuffer;this.healBuffer=[];for(let i of n)this.applyBar(i,false);this.notifySessionsBars(this.historyState==="backfill"?"backfill":void 0);}}}registerEngine(e,t){let n=this.engines.get(e);n&&n!==t&&console.warn(`[vela] re-registering scripting engine for language "${e}"; replacing ${n.constructor.name} with ${t.constructor.name}.`),this.engines.set(e,t);}addIndicator(e,t={}){let n=this.claimIndicatorId(t.id),i=t.title??"Indicator",o=new Ki(n,i,this,e);return this.handles.set(n,o),this.registry.add({id:n,title:i,source:e,options:t,inputValues:{...t.inputs??{}},propValues:{...t.props??{}}}),this.startIndicator(n,e,t,o),o}addNativeIndicator(e,t={}){let n=Th(e);if(!n?.multiInstance){let l=this.registry.all().find(d=>d.native?.type===e);if(l)return this.handles.get(l.id)??new Ki(l.id,l.title,this,void 0,e)}let i=this.registry.nextId("native",l=>this.handles.has(l)),o=n?X(this.i18n,n.title):e,s=new Ki(i,o,this,void 0,e);if(this.handles.set(i,s),!n)return console.warn(`[vela] addNativeIndicator("${e}") \u2014 no native indicator registered for this type.`),s;let a={...n.defaultInputs(),...t.inputs??{}};return this.registry.add({id:i,title:o,source:e,inputValues:a,propValues:{},native:{type:e,instance:n.create(),descriptor:n}}),s.setSchema(n.inputsSchema()),this.startNativeIndicator(i,s),s}presentNativeIndicators(){return this.registry.all().map(e=>e.native?.type).filter(e=>!!e)}async availableNativeIndicators(){let e=this.qualifiedSymbol(),t=new Set(this.presentNativeIndicators());return Promise.all(gb().map(async n=>({type:n.type,title:X(this.i18n,n.title),supported:await this.isNativeSupported(n,e),present:t.has(n.type),beta:n.beta,...n.multiInstance?{multiInstance:true}:{}})))}async isNativeSupported(e,t){if(!e.isSupported)return true;if(!t)return false;try{return await e.isSupported(t,this.dataControl)}catch{return false}}applyInputs(e,t){let n=this.registry.get(e);!n||!n.session&&!n.native||(n.inputValues={...n.inputValues,...t},n.renderHandle&&this.renderer.setIndicatorInputs(n.renderHandle,n.inputValues),n.pendingStructural=true,!n.hidden&&!n.native&&this.setLoading(n,true),n.pendingCause="inputs",n.session?n.session.update(n.inputValues):n.native&&!n.hidden&&n.native.instance.setInputs(n.inputValues),this.events.emit("indicator:inputs",{id:e}));}inputValuesOf(e){return {...this.registry.get(e)?.inputValues}}propValuesOf(e){return {...this.registry.get(e)?.propValues}}applyProps(e,t){let n=this.registry.get(e);n?.session&&(n.propValues={...n.propValues,...t},n.renderHandle&&this.renderer.setIndicatorInputs(n.renderHandle,n.inputValues,n.propValues),n.pendingStructural=true,n.hidden||this.setLoading(n,true),n.pendingCause="inputs",n.session.update(n.inputValues,n.propValues),this.events.emit("indicator:inputs",{id:e}));}updateCode(e,t){let n=this.registry.get(e),i=this.handles.get(e);return !n||!i?Promise.resolve({ok:false,error:new Error(`[vela] updateCode("${e}") \u2014 the indicator is no longer on the chart.`)}):n.native?(console.warn(`[vela] updateCode("${e}") \u2014 a native indicator has no script to update.`),Promise.resolve({ok:false,error:new Error(`[vela] updateCode("${e}") \u2014 a native indicator has no script to update.`)})):!(n.pendingSource!==void 0||n.codeTrial!==void 0)&&t===n.source?Promise.resolve({ok:true,error:null}):new Promise(s=>{(n.codeWaiters??(n.codeWaiters=[])).push(s),!(n.pendingSource===t||n.pendingSource===void 0&&n.codeTrial&&n.source===t)&&(n.pendingSource=t,this.swapSource(e,t,i));})}async swapSource(e,t,n){let i=this.registry.get(e)?.engine??this.engineFor(this.registry.get(e)?.options?.language),o;try{o=await i.prepare(t,e);}catch(l){let d=this.registry.get(e);d?.pendingSource===t&&(d.pendingSource=void 0,this.rejectCode(e,d,n,l));return}let s=this.registry.get(e);if(!s||s.pendingSource!==t)return;s.pendingSource=void 0;let a=s.codeTrial?.previous??{source:s.source,engine:s.engine,prepared:s.prepared,inputValues:s.inputValues,propValues:s.propValues,inputs:[...n.inputs],props:[...n.props]};if(s.inputValues=Av(o.inputs,s.inputValues,s.prepared?.inputs),s.propValues=Av(o.props??[],s.propValues,s.prepared?.props),s.source=t,s.engine=i,s.prepared=o,n.setSource(t),n.setSchema(o.inputs),n.setPropsSchema(o.props??[]),s.session?.stop(),s.session=void 0,s.pendingStructural=true,s.pendingCause="code",s.hidden){s.codeTrial=void 0,s.renderHandle&&this.renderer.setIndicatorInputs(s.renderHandle,s.inputValues,s.propValues),this.settleCode(s,{ok:true,error:null});return}s.codeTrial={previous:a},s.renderHandle?(this.renderer.setIndicatorInputs(s.renderHandle,s.inputValues,s.propValues),this.setLoading(s,true)):this.mountLoadingPlaceholder(e,s),this.executeIndicator(e,n),this.bars.length===0&&s.codeTrial&&(s.codeTrial=void 0,this.settleCode(s,{ok:true,error:null}));}settleCode(e,t){let n=e.codeWaiters;if(e.codeWaiters=void 0,n)for(let i of n)i(t);}rejectCode(e,t,n,i){let o=t.codeTrial;if(t.codeTrial=void 0,this.fail(e,n,i),o){let a=o.previous;t.session?.stop(),t.session=void 0,t.source=a.source,t.engine=a.engine,t.prepared=a.prepared,t.inputValues=a.inputValues,t.propValues=a.propValues,n.setSource(a.source),n.setSchema(a.inputs),n.setPropsSchema(a.props),t.pendingStructural=true,t.pendingCause=void 0,t.renderHandle&&this.renderer.setIndicatorInputs(t.renderHandle,t.inputValues,t.propValues),t.hidden||this.executeIndicator(e,n);}let s=i instanceof Error?i:new Error(String(i));this.settleCode(t,{ok:false,error:s});}listIndicators(){return [...this.handles.values()]}getIndicatorContext(e,t){return this.registry.get(e)?.session?.getContext?.(t)??Promise.resolve(null)}removeIndicator(e){let t=this.registry.remove(e);t?.native?.type==="volume"&&(this.volumeOptedOut=true),t&&this.settleCode(t,{ok:false,error:new Error(`[vela] updateCode("${e}") \u2014 the indicator was removed.`)}),t?.session?.stop(),t?.native&&this.stopNativeInstance(t.native),this.handles.delete(e),t?.renderHandle&&this.renderer.removeIndicator(t.renderHandle);let n=t?.model?.paneId;n&&n!=="price"&&!this.paneStillUsed(n)&&(this.renderer.removePane(n),this.forgetPane(n),this.events.emit("pane:changed",void 0)),this.events.emit("indicator:removed",{id:e});}setVisible(e,t){let n=this.registry.get(e);if(!(!n||n.hidden===!t)){if(n.hidden=!t,this.handles.get(e)?.setVisibleState(t),!t)n.session?.stop(),n.session=void 0,n.codeTrial&&(n.codeTrial=void 0,this.settleCode(n,{ok:true,error:null})),n.native?.started&&n.native.instance.suspend(),n.renderHandle?this.renderer.setIndicatorVisible?.(n.renderHandle,false):n.native&&this.mountHiddenNativeRow(e,n);else if(n.renderHandle&&this.renderer.setIndicatorVisible?.(n.renderHandle,true),n.pendingStructural=true,n.native)if(n.native.stale||!n.native.started){n.native.stale=false;let i=this.handles.get(e);i&&this.startNativeIndicator(e,i);}else n.native.instance.resume();else {this.setLoading(n,true);let i=this.handles.get(e);i&&this.executeIndicator(e,i);}this.events.emit("indicator:visibility",{id:e,visible:t});}}ready(){return this.readyPromise}inspect(){let e=[...this.registry.all()].filter(t=>!t.loading).sort((t,n)=>(n.native?1:0)-(t.native?1:0));return fb(e.map(t=>t.model).filter(t=>t!=null))}resize(){this.renderer.resize();}setTheme(e){let t=this.config.theme;Object.keys(e).every(n=>e[n]===t[n])||(this.config.theme=e,this.renderer.setTheme(e),this.events.emit("theme:changed",e));}getVisibleRange(){return this.renderer.getVisibleRange()}setVisibleRange(e){this.renderer.setVisibleRange(e);}panBy(e){if(this.renderer.panBy){this.renderer.panBy(e);return}let t=this.renderer.getVisibleRange();if(!t)return;let n=(t.to-t.from)*e;this.renderer.setVisibleRange({from:t.from+n,to:t.to+n});}setVisibleRangePreset(e){let t=bb(e,this.bars);t&&this.renderer.setVisibleRange(t);}destroy(){this.bumpGeneration(),this.resolveHistoryComplete(),this.clearReplayTimer(),this.replayQueue=null,this.replayForming=null,this.replayCarrying=null,this.dropTickFetches(),this.replayDepth=null,this.replayLoading=null,this.stopLive(),this.viewportTimer!=null&&clearTimeout(this.viewportTimer),this.viewportUnsub?.(),this.paneActionUnsub?.(),this.priceStyleWillChangeUnsub?.(),this.priceStyleWillChangeUnsub=null;for(let e of this.registry.all())this.settleCode(e,{ok:false,error:new Error("[vela] updateCode \u2014 the chart was destroyed.")}),e.session?.stop(),e.native&&this.stopNativeInstance(e.native);for(let e of this.typeEngines.values())e.stop();this.typeEngines.clear(),this.activeEngineStyle=null,this.unresolvedUnsub?.(),this.unresolvedUnsub=null,this.feed.destroy?.(),this.drawings.destroy(),this.marks.destroy(),this.renderer.destroy(),this.events.clear();}claimIndicatorId(e){if(e===void 0)return this.registry.nextId("ind",t=>this.handles.has(t));if(typeof e!="string"||e.length===0)throw new TypeError("[vela] addIndicator: `id` must be a non-empty string");if(this.handles.has(e)||this.registry.get(e))throw new Error(`[vela] addIndicator: indicator id "${e}" is already live on this chart`);return e}async startIndicator(e,t,n,i){try{if(await this.readyPromise,!this.registry.get(e))return;await nP();let o=this.registry.get(e);if(!o)return;let s=this.engineFor(n.language);o.engine=s;let a=await s.prepare(t,e);if(o.source!==t)return;o.prepared=a;let l={};for(let u of a.inputs)l[u.key]=u.defval;o.inputValues={...l,...o.inputValues},i.setSchema(a.inputs);let d={};for(let u of a.props??[])d[u.key]=u.defval;o.propValues={...d,...o.propValues},i.setPropsSchema(a.props??[]),this.mountLoadingPlaceholder(e,o),this.executeIndicator(e,i);}catch(o){this.fail(e,i,o);}}executeIndicator(e,t){let n=this.registry.get(e);if(!n||!n.engine||!n.prepared||n.hidden)return;let i=this.config.live&&!n.prepared.reactsToViewport&&n.engine.capabilities.streaming?"live":"static",o=n.prepared,s=n.engine.execute({prepared:n.prepared,market:this.market(),bars:this.bars,getBars:()=>this.bars,fetchSeries:(a,l,d)=>this.fetchSeries(a,l,d),inputs:n.inputValues,props:n.propValues,visibleRange:this.currentVisibleRange(),mode:i,historyState:this.historyState},{onModel:a=>{let l=!n.announced,d=n.pendingCause??"history";this.applyModel(e,a)&&(n.pendingCause=void 0,n.codeTrial&&(n.codeTrial=void 0,this.settleCode(n,{ok:true,error:null})),this.emitContextChanged(e),this.emitScriptRun(e,d,l));},onAlert:a=>{if(this.replayQueue||this.replayCarrying)return;let l=n.options?.title??n.prepared?.meta.title??n.title;this.events.emit("alert",{...a,indicator:l}),t.emit("alert",{id:a.id,message:a.message,title:a.title,time:a.time});},onWarning:a=>this.events.emit("warning",a),onError:a=>{n.codeTrial?this.rejectCode(e,n,t,a):this.fail(e,t,a);}});if(n.prepared!==o){s.stop();return}n.session=s,this.emitContextChanged(e);}async startNativeIndicator(e,t){try{await this.readyPromise;let n=this.registry.get(e);if(!n?.native||n.hidden)return;let i=n.native;if(i.started)return;if(i.descriptor.waitsForHistory&&this.historyState==="backfill"){i.heldForHistory=!0,this.mountNativePlaceholder(e,n);return}i.heldForHistory=!1;let o=this.nativeChannel(n),s=!0;i.revokeContext=()=>{s=!1;};let a={id:e,symbol:this.config.market.symbol??"TEST",timeframe:this.config.market.timeframe??"60",live:this.config.live&&this.replayQueue===null,session:this.config.market.session,bars:()=>this.bars,data:this.dataControl,emit:l=>{s&&this.applyModel(e,this.buildNativeModel(n,l,this.bars[0]?.time));},pushData:l=>{s&&this.renderer.setNativeData?.(o,l);},setStatus:l=>{s&&n.renderHandle&&!n.hidden&&this.renderer.setIndicatorStatus?.(n.renderHandle,l);}};i.instance.start(a,n.inputValues),i.started=!0;}catch(n){this.fail(e,t,n);}}nativeChannel(e){let{type:t,descriptor:n}=e.native;return n.multiInstance?cb(t,e.id):t}buildNativeModel(e,t,n){let i=e.native.descriptor,o=e.native.type,s=this.nativeChannel(e),a=qn(i.title),l=qn(i.shortTitle);return {id:e.id,title:e.title,...i.shortTitle?{shorttitle:X(this.i18n,i.shortTitle)}:{},...a?{displayTitle:a}:{},...l?{displayShorttitle:l}:{},overlay:i.overlay,paneHint:i.paneHint,native:{type:o,...s!==o?{channel:s}:{}},...n!=null?{anchorTime:n}:{},...i.legend===false?{legend:false}:{},...t.paneAxis!=null?{paneAxis:t.paneAxis}:{},series:t.series??[],fills:t.fills??[],backgrounds:t.backgrounds??[],priceLines:t.priceLines??[],...t.lines?{lines:t.lines}:{},...t.boxes?{boxes:t.boxes}:{},...t.labels?{labels:t.labels}:{},...t.polylines?{polylines:t.polylines}:{},...t.linefills?{linefills:t.linefills}:{},...t.tables?{tables:t.tables}:{},inputs:i.inputsSchema(),inputValues:e.inputValues}}mountLoadingPlaceholder(e,t){if(t.renderHandle||!t.prepared)return;let n=t.prepared.meta,i={id:e,title:t.options?.title??n.title,overlay:n.overlay,paneHint:n.overlay?"price":"new",series:[],fills:[],backgrounds:[],priceLines:[],inputs:t.prepared.inputs,inputValues:t.inputValues,...t.prepared.props?{props:t.prepared.props,propValues:t.propValues}:{}},o=this.routePane(e,i,t.options??{});this.placeModel(i,e,o),t.model=i;let s=this.ensurePaneFor(o);if(t.renderHandle=this.renderer.mountIndicator(i),s&&this.events.emit("pane:changed",void 0),t.pendingStructural=true,t.hidden){this.renderer.setIndicatorVisible?.(t.renderHandle,false),this.announce(t,this.handles.get(e));return}this.setLoading(t,true);}mountHiddenNativeRow(e,t){if(t.renderHandle||!t.native)return;let n=this.buildNativeModel(t,{}),i=this.routePane(e,n,t.options??{});this.placeModel(n,e,i),t.model=n;let o=this.ensurePaneFor(i);t.renderHandle=this.renderer.mountIndicator(n),o&&this.events.emit("pane:changed",void 0),t.pendingStructural=true,this.renderer.setIndicatorVisible?.(t.renderHandle,false),this.announce(t,this.handles.get(e));}mountNativePlaceholder(e,t){if(t.pendingStructural=true,!t.renderHandle){let n=this.buildNativeModel(t,{}),i=this.routePane(e,n,t.options??{});this.placeModel(n,e,i),t.model=n;let o=this.ensurePaneFor(i);t.renderHandle=this.renderer.mountIndicator(n),o&&this.events.emit("pane:changed",void 0);}this.setLoading(t,true);}setLoading(e,t){e.loading=t,e.renderHandle&&!e.hidden&&this.renderer.setIndicatorStatus?.(e.renderHandle,t?"loading":"idle");}ensurePaneFor(e){let t=!this.paneOrder.includes(e);return t&&this.paneOrder.push(e),this.renderer.ensurePane({id:e,kind:e==="price"?"price":"study",order:this.paneOrder.indexOf(e)}),t}paneStillUsed(e){for(let t of this.registry.all())if(t.model?.paneId===e)return true;return false}forgetPane(e){let t=this.paneOrder.indexOf(e);t>0&&this.paneOrder.splice(t,1),this.collapsedPanes.delete(e),this.maximizedPaneId===e&&(this.maximizedPaneId=null);}setTranslator(e){this.i18n=e,this.drawings.relocalize();}relocalize(){this.drawings.relocalize();for(let e of this.registry.all()){let t=e.native?.descriptor;if(!t)continue;e.title=X(this.i18n,t.title);let n=this.handles.get(e.id);n&&(n.title=e.title),e.model&&(e.model.title=e.title,t.shortTitle!==void 0&&(e.model.shorttitle=X(this.i18n,t.shortTitle)));}}paneManagementSupported(){return this.renderer.capabilities.paneManagement===true&&typeof this.renderer.setIndicatorPane=="function"}listPanes(){let e=new Map;for(let n of this.registry.all()){let i=n.model;if(!i||i.legend===false)continue;let o=i.paneId??"price";e.has(o)||e.set(o,[]),e.get(o).push({id:n.id,title:i.title||n.title,...i.shorttitle?{shorttitle:i.shorttitle}:{},ownScale:i.ownScale===true});}let t=[];for(let n of this.paneOrder){if(n!=="price"&&!e.has(n))continue;let i=this.renderer.paneHeightWeight?.(n)??null;t.push({id:n,kind:n==="price"?"price":"study",order:t.length,collapsed:this.collapsedPanes.has(n),maximized:this.maximizedPaneId===n,...i!==null?{heightWeight:i}:{},indicators:e.get(n)??[]});}return t}movePane(e,t){if(e==="price")return;let n=this.existingPaneIds(),i=n.indexOf(e);if(i<0)return;let o=t==="up"?i-1:i+1;o<=0||o>=n.length||([n[i],n[o]]=[n[o],n[i]],this.reorderPanes(n),this.events.emit("pane:moved",{paneId:e,dir:t}));}removePaneAndIndicators(e){if(e!=="price")for(let t of [...this.registry.all()])t.model?.paneId===e&&this.removeIndicator(t.id);}collapsePane(e,t){t?this.collapsedPanes.add(e):this.collapsedPanes.delete(e),this.renderer.setPaneCollapsed?.(e,t),this.events.emit("pane:changed",void 0);}maximizePane(e){this.maximizedPaneId=e,this.renderer.setPaneMaximized?.(e),this.events.emit("pane:changed",void 0);}setPaneHeightWeight(e,t){if(!this.renderer.setPaneHeightWeight){console.warn("[vela] the active renderer does not support pane sizing \u2014 chart.panes.setHeightWeight ignored.");return}if(typeof t!="number"||!Number.isFinite(t)||t<=0){console.warn(`[vela] chart.panes.setHeightWeight: weight must be a positive number (got ${String(t)}).`);return}if(!this.existingPaneIds().includes(e)){console.warn(`[vela] chart.panes.setHeightWeight: no pane "${e}".`);return}this.renderer.setPaneHeightWeight(e,t),this.events.emit("pane:changed",void 0);}moveIndicator(e,t){if(!this.paneManagementSupported()||!this.renderer.setIndicatorPane){console.warn("[vela] the active renderer does not support moving indicators between panes.");return}let n=this.registry.get(e);if(!n?.renderHandle||!n.model)return;let i=n.model,o=i.paneId??"price",s=this.resolveMoveTarget(e,i,t);if(!s)return;let{paneId:a,ownScale:l,insert:d}=s;a===o&&i.ownScale===true===l||(d?this.insertPaneOrder(a,d):this.paneOrder.includes(a)||this.paneOrder.push(a),i.ownScale=l,n.paneLocked=true,this.placeModel(i,e,a),this.ensurePaneFor(a),this.renderer.setIndicatorPane(n.renderHandle,a,{ownScale:l}),o!=="price"&&o!==a&&!this.paneStillUsed(o)&&(this.renderer.removePane(o),this.forgetPane(o)),this.reorderPanes(this.existingPaneIds()),this.events.emit("indicator:moved",{id:e,paneId:a}),this.events.emit("pane:changed",void 0));}resolveMoveTarget(e,t,n){if(n==="price"||typeof n=="object"&&"pane"in n&&n.pane==="price")return {paneId:"price",ownScale:!t.overlay};if("pane"in n)return this.existingPaneIds().includes(n.pane)?{paneId:n.pane,ownScale:true}:null;let i=n.newPane===true?{}:n.newPane;return {paneId:this.freshPaneId(e,t.paneId??"price"),ownScale:false,insert:i}}freshPaneId(e,t){let n=new Set(this.existingPaneIds()),i=`pane-${e}`;for(let o=2;i===t||n.has(i);o+=1)i=`pane-${e}-${o}`;return i}insertPaneOrder(e,t){let n=this.paneOrder.indexOf(e);n>0&&this.paneOrder.splice(n,1);let i=this.paneOrder.length;t.before&&this.paneOrder.includes(t.before)?i=this.paneOrder.indexOf(t.before):t.after&&this.paneOrder.includes(t.after)&&(i=this.paneOrder.indexOf(t.after)+1),i<1&&(i=1),this.paneOrder.splice(i,0,e);}existingPaneIds(){return this.paneOrder.filter(e=>e==="price"||this.paneStillUsed(e))}reorderPanes(e){this.paneOrder.length=0,this.paneOrder.push(...e),this.renderer.orderPanes?.(e),this.events.emit("pane:changed",void 0);}handlePaneAction(e){switch(e.type){case "remove":this.removePaneAndIndicators(e.paneId);break;case "move":{let t=this.existingPaneIds(),n=t.indexOf(e.paneId),i=e.dir==="up"?n-1:n+1;n>0&&i>0&&i<t.length&&([t[n],t[i]]=[t[i],t[n]],this.paneOrder.length=0,this.paneOrder.push(...t),this.events.emit("pane:changed",void 0),this.events.emit("pane:moved",{paneId:e.paneId,dir:e.dir}));break}case "collapse":e.collapsed?this.collapsedPanes.add(e.paneId):this.collapsedPanes.delete(e.paneId),this.events.emit("pane:changed",void 0);break;case "maximize":this.maximizedPaneId=e.maximized?e.paneId:null,this.events.emit("pane:changed",void 0);break;case "resize":this.events.emit("pane:changed",void 0);break}}announce(e,t){e.announced||(e.announced=true,this.events.emit("indicator:added",{id:e.id}),this.emitContextChanged(e.id),t?.emit("ready",void 0));}applyModel(e,t){let n=this.registry.get(e);if(!n||n.hidden)return true;if(this.switchingMarket||n.loading&&this.bars.length===0&&!r.modelHasOutput(t))return false;let i=this.handles.get(e);if(!n.renderHandle){let l=this.routePane(e,t,n.options??{});this.placeModel(t,e,l),n.model=t;let d=this.ensurePaneFor(l);return n.renderHandle=this.renderer.mountIndicator(t),n.pendingStructural=false,d&&this.events.emit("pane:changed",void 0),this.announce(n,i),true}let o=n.model?.paneId??"price",s=n.model?.ownScale===true,a=false;if(n.loading&&!n.paneLocked){let l=this.routePane(e,t,n.options??{});l!==o&&(o!=="price"&&!this.registry.all().some(d=>d.id!==e&&d.model?.paneId===o)&&(this.renderer.removePane(o),this.forgetPane(o)),this.ensurePaneFor(l),n.pendingStructural=true,o=l,a=true);}return this.placeModel(t,e,o),n.paneLocked&&(t.ownScale=s),n.model=t,n.pendingStructural?(n.renderHandle=this.renderer.mountIndicator(t),this.renderer.setIndicatorInputs(n.renderHandle,n.inputValues,n.propValues),n.pendingStructural=false):this.renderer.updateIndicator(n.renderHandle,oP(t)),a&&this.events.emit("pane:changed",void 0),n.loading&&this.setLoading(n,false),this.announce(n,i),true}static modelHasOutput(e){return e.series.length>0||e.fills.length>0||e.backgrounds.length>0||e.priceLines.length>0||(e.lines?.length??0)>0||(e.boxes?.length??0)>0||(e.labels?.length??0)>0||(e.polylines?.length??0)>0||(e.linefills?.length??0)>0||(e.tables?.length??0)>0||(e.barColors?.length??0)>0||(e.trades?.length??0)>0}routePane(e,t,n){return n.pane==="new"?`pane-${e}`:n.pane==="price"||(n.overlay??t.overlay)?"price":`pane-${e}`}static plotsAtLastBar(e,t){let n={};for(let i of e.series){if(!at(i))continue;let o=i.points.length-1;if(t!==void 0)for(;o>=0&&i.points[o].time>t;)o-=1;n[i.title]=i.points[o]?.value??null;}return n}placeModel(e,t,n){e.id=t,e.paneId=n;let i=o=>o.overlay===true?"price":n;for(let o of e.series)o.paneId=i(o);for(let o of e.fills)o.paneId=i(o);for(let o of e.backgrounds)o.paneId=i(o);for(let o of e.priceLines)o.paneId=n;if(e.lines)for(let o of e.lines)o.paneId=i(o);if(e.boxes)for(let o of e.boxes)o.paneId=i(o);if(e.labels)for(let o of e.labels)o.paneId=i(o);if(e.polylines)for(let o of e.polylines)o.paneId=i(o);if(e.linefills)for(let o of e.linefills)o.paneId=i(o);if(e.tables)for(let o of e.tables)o.paneId=i(o);}emitContextChanged(e){if(!this.registry.get(e)?.session?.getContext)return;let t=Date.now();t-(this.contextEmitAt.get(e)??0)<1e3||(this.contextEmitAt.set(e,t),this.events.emit("context:changed",{id:e}));}emitScriptRun(e,t,n){let i=this.registry.get(e);if(!i||i.native||!this.events.hasListeners("script:run"))return;let o=Date.now();t==="tick"&&o-(this.runEmitAt.get(e)??0)<jE||(this.runEmitAt.set(e,o),Promise.resolve().then(()=>this.buildScriptRun(i,t,n)).then(s=>{s&&this.registry.get(e)&&this.events.emit("script:run",s);}));}async buildScriptRun(e,t,n){let i=e.model;if(!i)return null;let o=await this.pullContext(e,["variables","strategy","warnings"]),s=this.bars[this.bars.length-1];return {id:e.id,title:i.title,kind:o?.strategy||(i.trades?.length??0)>0?"strategy":"indicator",cause:t,first:n,bar:Math.max(0,this.bars.length-1),time:s?.time??0,forming:this.config.live&&this.bars.length>0,complete:this.historyState!=="backfill",plots:r.plotsAtLastBar(i,s?.time),vars:o?.variables??{},...o?.strategy?{strategy:o.strategy}:{},warnings:o?.warnings??[],trades:async()=>(await this.pullContext(e,["trades"]))?.trades??[],series:async a=>((await this.pullContext(e,["plots"]))?.plots?.[a]??[]).map(d=>({time:d.time,value:typeof d.value=="number"?d.value:null}))}}async pullContext(e,t){try{return await e.session?.getContext?.(t)??null}catch{return null}}fail(e,t,n){let i=this.registry.get(e);i?.loading&&this.setLoading(i,false);let o=n instanceof Error?n:new Error(String(n));console.error(`[vela] indicator "${e}" failed:`,o.message),this.events.emit("indicator:error",{id:e,error:o}),t?.emit("error",{error:o});}};function Iv(){return typeof performance<"u"?performance.now():Date.now()}function tP(r){if(!Array.isArray(r))return [];let e=t=>t===void 0||Number.isFinite(t);return r.filter(t=>t!=null&&Number.isFinite(t.price)&&e(t.volume)&&e(t.high)&&e(t.low)&&e(t.open))}function nP(){return typeof requestAnimationFrame=="function"?new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(()=>r()))):new Promise(r=>setTimeout(r,0))}function Av(r,e,t=[]){let n={},i=new Set;for(let s of r)n[s.key]=s.defval,i.add(s.key),i.add(s.title);let o=new Map;for(let s of t)o.set(s.key,s.defval),o.has(s.title)||o.set(s.title,s.defval);for(let[s,a]of Object.entries(e))i.has(s)&&(o.has(s)&&rP(o.get(s),a)||(n[s]=a));return n}function rP(r,e){return r===e?true:typeof r=="object"&&r!==null&&typeof e=="object"&&e!==null&&JSON.stringify(r)===JSON.stringify(e)}function iP(r){let{anchorTime:e,...t}=r;return {...t,series:r.series.map(n=>n.kind==="candle"||n.kind==="bar"?{...n,bars:[]}:n.kind==="markers"?{...n,markers:[]}:{...n,points:[]}),fills:[],backgrounds:[],priceLines:[],lines:[],boxes:[],labels:[],polylines:[],linefills:[],tables:[],barColors:[],trades:[]}}function oP(r){let e=[],t=Number.POSITIVE_INFINITY,n=0;for(let i of r.series)if(i.kind==="candle"||i.kind==="bar"){e.push({seriesId:i.id,kind:"bars",bars:i.bars,barColors:i.barColors??[]});for(let o of i.bars)o&&(o.time<t&&(t=o.time),o.time>n&&(n=o.time));}else if(at(i)){e.push({seriesId:i.id,kind:"points",points:i.points});for(let o of i.points)o&&(o.time<t&&(t=o.time),o.time>n&&(n=o.time));}return {kind:"value",indicatorId:r.id,dirty:{from:Number.isFinite(t)?t:0,to:n},anchorTime:r.anchorTime??null,series:e,lines:r.lines??[],boxes:r.boxes??[],labels:r.labels??[],polylines:r.polylines??[],linefills:r.linefills??[],tables:r.tables??[],trades:r.trades??[]}}var Rs=class{constructor(e){this.renderer=e;}get name(){return this.renderer.name}get capabilities(){return this.renderer.capabilities}supports(e){return this.renderer.features.includes(e)}get(e){return this.renderer.readFeature(e)}set(e,t){let n=typeof e=="string"?[[e,t]]:Object.entries(e);for(let[i,o]of n)this.renderer.features.includes(i)?this.renderer.applyFeature(i,o):console.warn(`[vela] renderer "${this.renderer.name}" has no feature "${i}" \u2014 set ignored.`);return this}setLegendActions(e){this.renderer.setLegendActions?.(e);}setLegendCallouts(e){this.renderer.setLegendCallouts?.(e);}setLegendOverviewAction(e){return this.renderer.setLegendOverviewAction?.(e),this}get supportsIndicatorSettings(){return typeof this.renderer.openIndicatorSettings=="function"}openIndicatorSettings(e){return this.renderer.openIndicatorSettings?.(e),this}screenshot(){return typeof this.renderer.screenshot=="function"?this.renderer.screenshot():(console.warn(`[vela] renderer "${this.renderer.name}" does not support screenshot().`),null)}screenshotCanvas(){return typeof this.renderer.screenshotCanvas=="function"?this.renderer.screenshotCanvas():null}getConfig(){return typeof this.renderer.getConfig=="function"?this.renderer.getConfig():(console.warn(`[vela] renderer "${this.renderer.name}" does not support getConfig().`),null)}applyConfig(e){return typeof this.renderer.applyConfig=="function"?this.renderer.applyConfig(e):console.warn(`[vela] renderer "${this.renderer.name}" does not support applyConfig().`),this}onConfigChanged(e){return this.renderer.onConfigChanged?.(e)??(()=>{})}onCrosshairMove(e){return this.renderer.onCrosshairMove(e)}onClick(e){return this.renderer.onClick(e)}onAxisLongPress(e){return this.renderer.onAxisLongPress?.(e)??(()=>{})}dataWindowReadout(){return this.renderer.getDataWindowReadout?.()??null}setSymbolPicker(e){return typeof this.renderer.setSymbolPicker=="function"?this.renderer.setSymbolPicker(e):console.warn(`[vela] renderer "${this.renderer.name}" does not support setSymbolPicker().`),this}focus(){return this.renderer.focus?.(),this}get supportsExternalCrosshair(){return typeof this.renderer.setExternalCrosshair=="function"}setExternalCrosshair(e,t=null){return this.renderer.setExternalCrosshair?.(e,t),this}closeDialogs(){return this.renderer.closeDialogs?.(),this}openSettings(e){return this.renderer.openSettingsDialog?.(e),this}setSettingsSections(e){return this.renderer.setSettingsSections?.(e),this}setSettingsVisibility(e){return this.renderer.setSettingsVisibility?.(e),this}listSettingsIds(){return this.renderer.listSettingsIds?.()??[]}setLayoutMode(e){return this.renderer.setLayoutMode?.(e),this}setWallClock(e){return this.renderer.setWallClock?.(e),this}};var uo=new Map;function sP(r){let e=Object.entries(r);for(let[t,n]of e)uo.set(t,n);return ()=>{for(let[t,n]of e)uo.get(t)===n&&uo.delete(t);}}function aP(...r){if(r.length===0)uo.clear();else for(let e of r)uo.delete(e);}function Xh(){return Object.fromEntries(uo)}var Hc=class{constructor(e){this.controller=e;}get supported(){return this.controller.paneManagementSupported()}list(){return this.controller.listPanes()}move(e,t){return this.guard()&&this.controller.movePane(e,t),this}remove(e){return this.guard()&&this.controller.removePaneAndIndicators(e),this}collapse(e,t=true){return this.guard()&&this.controller.collapsePane(e,t),this}maximize(e){return this.guard()&&this.controller.maximizePane(e),this}setHeightWeight(e,t){return this.guard()&&this.controller.setPaneHeightWeight(e,t),this}moveIndicator(e,t){return this.guard()&&this.controller.moveIndicator(e,t),this}guard(){return this.controller.paneManagementSupported()?true:(console.warn("[vela] the active renderer does not support pane management \u2014 chart.panes mutation ignored."),false)}};function Rv(r,e,t,n){return `${r}|${e}|${t}${n&&n!=="regular"?`|${n}`:""}`}function lP(r){return r.split("|")[1]??""}var _c=class{constructor(){this.series=new Map;this.coveredFrom=new Map;this.retained=new Set;this.retainedByOwner=new Map;}get(e){return this.series.get(e)}markCovered(e,t){this.coveredFrom.set(e,Math.min(this.coveredFrom.get(e)??1/0,t));}coveredFromOf(e){return this.coveredFrom.get(e)}merge(e,t){if(t.length===0)return this.series.get(e)??[];let n=new Map;for(let o of this.series.get(e)??[])n.set(o.time,o);for(let o of t)n.set(o.time,o);let i=[...n.values()].sort((o,s)=>o.time-s.time);return this.series.set(e,i),i}retainSymbol(e){this.currentSymbol!==e&&(this.currentSymbol=e,this.purgeOutside(e));}retain(e,t="default"){e.size===0?this.retainedByOwner.delete(t):this.retainedByOwner.set(t,new Set(e));let n=new Set;for(let i of this.retainedByOwner.values())for(let o of i)n.add(o);this.retained=n,this.purgeOutside(this.currentSymbol);}purgeOutside(e){for(let t of [...this.series.keys()]){let n=lP(t);n!==e&&!this.retained.has(n)&&(this.series.delete(t),this.coveredFrom.delete(t));}}clear(){this.series.clear(),this.coveredFrom.clear();}},Ds=new _c;function jh(r,e,t){let{provider:n,ticker:i}=Mn(r);return Rv(n??"",i,e,t)}var Ns=1e4,cP=Ns+1,Fs=class{constructor(e,t=Ds){this.inner=e;this.store=t;}async load(e){if(e.data&&e.data.length>0)return this.inner.load(e);let t=e.symbol??"TEST",n=jh(t,e.timeframe??"60",e.session);this.store.retainSymbol(t);let i=this.store.get(n),o=e.bars??500,s=i?.[i.length-1];if(i&&s&&i.length>=o-1&&this.inner.loadRange){let{bars:l}=await this.fetchRange(e,{from:s.time}),d=this.store.merge(n,Os(l));return Dv(d,l[l.length-1]).slice(-o)}let a=await this.inner.load(e);return this.store.merge(n,Os(a)),a}async loadProgressive(e,t,n){if(e.data&&e.data.length>0)return this.inner.load(e);if(!this.inner.loadProgressive)return null;let i=e.symbol??"TEST",o=jh(i,e.timeframe??"60",e.session),s=this.store.get(o),a=e.bars??500,l=s?.[s.length-1];if(s&&l&&s.length>=a-1&&this.inner.loadRange)return this.load(e);this.store.retainSymbol(i);let d=await this.inner.loadProgressive(e,t,n);return d==null?null:(this.store.merge(o,Os(d)),d)}async loadRange(e,t){if(!this.inner.loadRange)return this.inner.load(e);let n=jh(e.symbol??"TEST",e.timeframe??"60",e.session),i=this.store.get(n),o=i?.[i.length-1];if(t.to!=null&&o&&t.to<o.time){let u=i.filter(b=>b.time<=t.to),h=this.store.coveredFromOf(n)??1/0;if(t.limit!=null?u.length>=t.limit&&(t.from==null||h<=t.from):t.from!=null&&h<=t.from){let b=t.from!=null?u.filter(f=>f.time>=t.from):u;return t.limit!=null&&b.length>t.limit&&(b=b.slice(-t.limit)),b}let m=await this.fetchRange(e,t),g=m.bars.filter(b=>b.time<=t.to);return g.length>0&&(this.store.merge(n,g),this.store.markCovered(n,m.coveredDownTo??g[0].time)),g}if(o&&t.from!=null){let u=this.store.coveredFromOf(n);if(u!=null&&u>t.from){let{bars:h,coveredDownTo:p}=await this.fetchRange(e,{from:t.from,to:u});this.store.merge(n,h.filter(m=>m.time<=u)),this.store.markCovered(n,p??t.from),i=this.store.get(n),o=i?.[i.length-1];}}let s=this.store.coveredFromOf(n);if(!!i&&i.length>0&&!!o&&(t.from!=null?s!=null&&s<=t.from:t.limit==null||i.length>=t.limit)&&o){let{bars:u}=await this.fetchRange(e,{from:o.time,to:t.to,limit:t.limit}),h=this.store.merge(n,Os(u)),p=Dv(h,u[u.length-1]),m=t.from!=null?p.filter(g=>g.time>=t.from):p;return t.to!=null&&(m=m.filter(g=>g.time<=t.to)),m}let{bars:l,coveredDownTo:d}=await this.fetchRange(e,t);return this.store.merge(n,Os(l)),this.store.markCovered(n,d??t.from??l[0]?.time??0),l}async fetchRange(e,t){let n=an(e.timeframe??"60"),i=dP(t,n);if(i<=cP){let d=await this.inner.loadRange(e,{...t,limit:t.limit??i});return {bars:d,coveredDownTo:t.from??d[0]?.time}}let o=new Map,s=t.to??Date.now();for(;!(t.from!=null&&s<t.from);){let d=t.limit!=null?t.limit-o.size:Ns;if(d<=0)break;let u=await this.inner.loadRange(e,{to:s,limit:Math.min(Ns,d)}),h=1/0;for(let p of u)p.time<h&&(h=p.time),p.time<=s&&(t.from==null||p.time>=t.from)&&o.set(p.time,p);if(u.length===0){if(t.from==null)break;s-=Ns*n;continue}if(h-1>=s)break;s=h-1;}let a=[...o.values()].sort((d,u)=>d.time-u.time),l=t.from!=null&&s<t.from;return {bars:a,coveredDownTo:l?t.from:a[0]?.time}}subscribe(e,t){return this.inner.subscribe(e,t)}symbolInfo(e){return this.inner.symbolInfo?.(e)}};function dP(r,e){if(r.limit!=null)return r.limit;if(r.from==null)return Ns;let t=Math.max(0,(r.to??Date.now())-r.from);return Math.ceil(t/e*1.1)+2}function Os(r){return r.length>0?r.slice(0,-1):r}function Dv(r,e){if(!e)return r;let t=r[r.length-1];return !t||e.time>t.time?[...r,e]:r}var fi=class{constructor(e=Ds){this.registry=new Bc;this.primaryProvider=null;this.symInfoCache=new Map;this.symInfoInflight=new Map;this.cache=new Fs(new qh(this.registry),e);}registerProvider(e,t){return this.registry.register(e,t)}unregisterProvider(e){this.registry.unregister(e);}providers(){return this.registry.names().map(e=>this.registry.infoOf(e))}resolveSymbol(e){return this.registry.resolve(e,{default:this.primaryProvider})}displayPrefix(e){let t=this.resolveSymbol(e);return t?this.registry.displayPrefixOf(t):null}canonicalSymbol(e){let t=this.resolveSymbol(e);return t?this.registry.canonicalSymbol(t):null}providerInstance(e){return this.registry.get(e)}symbolIconOf(e){return this.registry.symbolIconOf(e)}symbolIcon(e){return this.registry.symbolIcon(this.resolveSymbol(e))}symbols(e){return this.registry.symbolsOf(e)}onUnresolved(e){return this.registry.onUnresolved(e)}destroy(){this.registry.cancelWaits();}ready(){return this.registry.indexReady()}async symbolInfoFor(e){let t=this.registry.resolve(e,{default:this.primaryProvider});if(t)return this.fetchSymbolInfo(t)}fetchSymbolInfo(e){let t=Ov(e),n=this.symInfoCache.get(t);if(n&&Date.now()-n.at<uP)return Promise.resolve(n.info);let i=this.symInfoInflight.get(t);if(i)return i;let o=this.registry.get(e.provider)?.getSymbolInfo;if(!o)return Promise.resolve(void 0);let s=Promise.resolve(o.call(this.registry.get(e.provider),e.ticker)).then(a=>(a&&this.symInfoCache.set(t,{info:a,at:Date.now()}),a)).finally(()=>{this.symInfoInflight.delete(t);});return this.symInfoInflight.set(t,s),s}capabilitiesFor(e){let t=this.registry.resolve(e,{default:this.primaryProvider});if(!t)return null;let n=this.registry.get(t.provider);return n?n.capabilitiesFor?.(t.ticker)??this.registry.infoOf(t.provider).capabilities:null}async load(e){if(e.data&&e.data.length>0)return e.data;let t=await this.registry.whenResolvable(Bs(e),{default:this.primaryProvider});return this.primaryProvider=t.provider,this.prefetchSymbolInfo(t),this.cache.load(zc(e,t))}async loadProgressive(e,t,n){if(e.data&&e.data.length>0)return e.data;let i=await this.registry.whenResolvable(Bs(e),{default:this.primaryProvider});return this.primaryProvider=i.provider,this.prefetchSymbolInfo(i),this.cache.loadProgressive(zc(e,i),t,n)}symbolInfo(e){if(e.data&&e.data.length>0)return;let t=this.registry.resolve(Bs(e),{default:this.primaryProvider});return t?this.symInfoCache.get(Ov(t))?.info:void 0}prefetchSymbolInfo(e){this.fetchSymbolInfo(e).catch(()=>{});}async loadRange(e,t){if(e.data&&e.data.length>0)return this.cache.loadRange(e,t);let n=this.registry.resolve(Bs(e),{default:this.primaryProvider});return n?this.cache.loadRange(zc(e,n),t):[]}subscribe(e,t){if(e.data&&e.data.length>0)return ()=>{};let n=this.registry.resolve(Bs(e),{default:this.primaryProvider});return n?this.cache.subscribe(zc(e,n),t):()=>{}}};function Bs(r){return r.symbol??""}function zc(r,e){return {...r,symbol:`${e.provider}:${e.ticker}`}}function Ov(r){return `${r.provider}|${r.ticker.trim().toUpperCase()}`}var uP=10*6e4;async function Nv(r,e,t,n){try{return await r.getBars(e,t,n)}catch(i){return console.warn(`[vela] data fetch failed for ${e} ${t} \u2014 ${i instanceof Error?i.message:String(i)}`),[]}}var qh=class{constructor(e){this.registry=e;}load(e){let{provider:t,ticker:n}=Mn(e.symbol??""),i=this.registry.get(t??"");return i?Nv(i,n,e.timeframe??"60",{limit:e.bars??500,session:e.session}):Promise.resolve([])}async loadProgressive(e,t,n){let{provider:i,ticker:o}=Mn(e.symbol??""),s=this.registry.get(i??"");if(!s)return [];if(!s.getBarsProgressive)return null;try{return await s.getBarsProgressive(o,e.timeframe??"60",{limit:e.bars??500,session:e.session},t,n)}catch(a){return console.warn(`[vela] progressive fetch failed for ${o} ${e.timeframe??"60"} \u2014 ${a instanceof Error?a.message:String(a)}`),[]}}loadRange(e,t){let{provider:n,ticker:i}=Mn(e.symbol??""),o=this.registry.get(n??"");return o?Nv(o,i,e.timeframe??"60",{...t,session:e.session}):Promise.resolve([])}subscribe(e,t){let{provider:n,ticker:i}=Mn(e.symbol??""),o=this.registry.get(n??"");if(!o)return ()=>{};let s=e.timeframe??"60";if(o.subscribe)return o.subscribe(i,s,t,e.session?{session:e.session}:void 0);let a=false,l=null,d=async()=>{if(!a){try{let u=await o.getBars(i,s,{limit:2,session:e.session});if(a)return;for(let h of u)t(h);}catch{}a||(l=setTimeout(()=>{d();},3e3));}};return l=setTimeout(()=>{d();},3e3),()=>{a=true,l&&clearTimeout(l);}}};var Vs=class{constructor(e){this.registry=e instanceof fi?e:null;}registerProvider(e,t){return this.registry?(this.registry.registerProvider(e,t),this):(console.warn(`[vela] chart.data.registerProvider("${e}") ignored \u2014 the active data feed is a custom feed (deps.dataFeed), not the default provider registry.`),this)}unregisterProvider(e){return this.registry?.unregisterProvider(e),this}providers(){return this.registry?.providers()??[]}resolve(e){return this.registry?.resolveSymbol(e)??null}displayPrefix(e){return this.registry?.displayPrefix(e)??null}canonicalSymbol(e){return this.registry?.canonicalSymbol(e)??null}providerInstance(e){return this.registry?.providerInstance(e)}symbols(e){return this.registry?.symbols(e)??[]}symbolIcon(e){return this.registry?.symbolIcon(e)}symbolInfo(e){return this.registry?.symbolInfoFor(e)??Promise.resolve(void 0)}capabilities(e){return this.registry?.capabilitiesFor(e)??null}ready(){return this.registry?.ready()??Promise.resolve()}};var Hs=class{constructor(e){this.ctrl=e;}get supported(){return this.ctrl.supported}setTool(e){return this.ok("setTool")&&this.ctrl.setTool(e),this}getTool(){return this.ctrl.getTool()}setSnapMode(e){return this.ok("setSnapMode")&&this.ctrl.setSnapMode(e),this}getSnapMode(){return this.ctrl.getSnapMode()}setStayMode(e){return this.ok("setStayMode")&&this.ctrl.setStayMode(e),this}getStayMode(){return this.ctrl.getStayMode()}setMode(e){return this.ok("setMode")&&this.ctrl.setMode(e),this}getMode(){return this.ctrl.getMode()}showToolbar(e=true){return this.ok("showToolbar")&&this.ctrl.showToolbar(e),this}setToolbar(e){return this.ok("setToolbar")&&this.ctrl.setToolbar(e),this}setToolShortcuts(e){return this.ok("setToolShortcuts")&&this.ctrl.setToolShortcuts(e),this}setExternalGhost(e){return this.ctrl.setExternalGhost(e),this}add(e,t={}){return this.ok("add")?this.ctrl.add(e,t):null}remove(e){return this.ctrl.remove(e),this}update(e,t){return this.ctrl.update(e,t),this}updateMany(e){return this.ctrl.updateMany(e),this}removeMany(e){return this.ctrl.removeMany(e),this}lock(e,t=true){return this.ctrl.setLocked(e,t),this}show(e,t=true){return this.ctrl.setVisible(e,t),this}select(e){return this.ok("select")&&this.ctrl.select(e==null?[]:typeof e=="string"?[e]:e),this}openSettings(e){return this.ok("openSettings")&&this.ctrl.openSettings(e),this}bringToFront(e){return this.ctrl.bringToFront(e),this}sendToBack(e){return this.ctrl.sendToBack(e),this}undo(){return this.ctrl.undo(),this}redo(){return this.ctrl.redo(),this}canUndo(){return this.ctrl.canUndo()}canRedo(){return this.ctrl.canRedo()}clone(e){return this.ok("clone")&&this.ctrl.clone(e),this}duplicate(e){return this.ok("duplicate")&&this.ctrl.duplicate(e),this}copyToClipboard(e){return this.ok("copy")&&this.ctrl.copy(e),this}paste(){return this.ok("paste")&&this.ctrl.paste(),this}all(){return this.ctrl.all()}toJSON(){return this.ctrl.toJSON()}fromJSON(e){return this.ctrl.fromJSON(e),this}favorites(){return this.ctrl.favorites()}isFavorite(e){return this.ctrl.isFavorite(e)}setFavorite(e,t){return this.ok("setFavorite")&&this.ctrl.setFavorite(e,t),this}setFavorites(e){return this.ok("setFavorites")&&this.ctrl.setFavorites([...e]),this}toolDefaults(){return this.ctrl.toolDefaults()}setToolDefaults(e){return this.ctrl.setToolDefaults(e),this}resetToolDefaults(e){return this.ctrl.resetToolDefaults(e),this}toolTemplates(){return this.ctrl.toolTemplates()}setToolTemplates(e){return this.ctrl.setToolTemplates(e),this}getConfig(){return this.ctrl.toJSON()}applyConfig(e){return this.ctrl.fromJSON(e),this}ok(e){return this.ctrl.supported?true:(console.warn(`[vela] chart.drawings.${e}() ignored \u2014 the active renderer has no userDrawings capability.`),false)}};var _s=class{constructor(e){this.ctrl=e;}get supported(){return this.ctrl.supported}add(e){return this.ctrl.add(e),this}set(e){return this.ctrl.set(e),this}remove(e){return this.ctrl.remove(e),this}clear(){return this.ctrl.clear(),this}all(){return this.ctrl.all()}defineGroup(e){return this.ctrl.defineGroup(e),this}groups(){return this.ctrl.groupDefinitions()}setGroupVisible(e,t=true){return this.ctrl.setGroupVisible(e,t),this}isGroupVisible(e){return this.ctrl.isGroupVisible(e)}};var zs=class{constructor(e){this.ctrl=e;}start(e){return this.ctrl.replayStart(e)}step(){return this.ctrl.replayStep()}stepUpdate(){return this.ctrl.replayStepUpdate()}play(e){return this.ctrl.replayPlay(e),this}pause(){return this.ctrl.replayPause(),this}stop(){return this.ctrl.replayStop(),this}get state(){return this.ctrl.replayState()}get bounds(){return this.ctrl.replayBounds()}setTicks(e){return this.ctrl.replaySetTicks(e),this}};var Ws=class r{constructor(e=()=>Date.now()){this.now=e;this.subs=new Set;this.timer=null;}onTick(e){return this.subs.add(e),this.timer==null&&this.arm(),()=>{this.subs.delete(e),this.subs.size===0&&this.timer!=null&&(clearTimeout(this.timer),this.timer=null);}}static delayToNextSecond(e){return 1e3-(e%1e3+1e3)%1e3+5}arm(){this.timer=setTimeout(()=>{this.timer=null;let e=this.now();for(let t of this.subs)t(e);this.subs.size>0&&this.arm();},r.delayToNextSecond(this.now()));}};function Gs(r){let e=r.trim(),t=/^#([0-9a-f]{3})$/i.exec(e);if(t){let i=t[1];return {r:parseInt(i[0]+i[0],16),g:parseInt(i[1]+i[1],16),b:parseInt(i[2]+i[2],16)}}if(t=/^#([0-9a-f]{6})[0-9a-f]{0,2}$/i.exec(e),t){let i=t[1];return {r:parseInt(i.slice(0,2),16),g:parseInt(i.slice(2,4),16),b:parseInt(i.slice(4,6),16)}}let n=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i.exec(e);return n?{r:parseFloat(n[1]),g:parseFloat(n[2]),b:parseFloat(n[3])}:null}function ie(r,e){let t=Gs(r);return t?`rgba(${t.r},${t.g},${t.b},${e})`:r}function Fv(r,e,t){let n=Gs(r),i=Gs(e);if(!n||!i)return r;let o=(s,a)=>Math.round(s+(a-s)*t);return `rgb(${o(n.r,i.r)},${o(n.g,i.g)},${o(n.b,i.b)})`}function Zh(r,e="#888888"){let t=Gs(r);if(!t)return e;let n=i=>Math.max(0,Math.min(255,Math.round(i))).toString(16).padStart(2,"0");return `#${n(t.r)}${n(t.g)}${n(t.b)}`}function Gt(r){let e=Gs(r);return e?.2126*e.r+.7152*e.g+.0722*e.b<128:true}var Wc={"--vela-space-1":"4px","--vela-space-2":"8px","--vela-space-3":"12px","--vela-space-4":"16px","--vela-radius-sm":"4px","--vela-radius-md":"6px","--vela-radius-lg":"10px","--vela-z-tooltip":"60","--vela-z-menu":"50","--vela-z-dialog":"40","--vela-z-popover":"6000","--vela-ease":"cubic-bezier(0.22, 1, 0.36, 1)","--vela-dur-fast":"90ms","--vela-dur-med":"160ms","--vela-font-size-sm":"11px","--vela-font-size-md":"12px","--vela-font-size-lg":"14px"};function Gc(r){let e=Gt(r.background),t=i=>e?`rgba(255,255,255,${i})`:ie(r.textColor,i+.02),n=Fv(r.background,e?"#ffffff":r.textColor,e?.03:.05);return {"--vela-font":r.fontFamily,"--vela-bg":r.background,"--vela-fg":e?"#d1d4dc":r.textColor,"--vela-fg-muted":e?"#868a96":ie(r.textColor,.62),"--vela-fg-faint":ie(r.textColor,.35),"--vela-fg-bright":e?"#f0f3fa":"#000000","--vela-surface":r.background,"--vela-surface-elev":n,"--vela-surface-overlay":n,"--vela-surface-sunken":r.background,"--vela-border":r.borderColor,"--vela-border-strong":e?"#34353b":ie(r.textColor,.28),"--vela-border-soft":r.borderColor,"--vela-border-faint":ie(r.textColor,.08),"--vela-hover":t(.06),"--vela-active":t(.1),"--vela-hover-strong":t(.16),"--vela-focus":ie(r.textColor,.5),"--vela-focus-soft":ie(r.textColor,.12),"--vela-separator-hover-band":ie(r.textColor,.1),"--vela-separator-hover-line":ie(r.textColor,.55),"--vela-scroll":ie(r.textColor,.3),"--vela-accent":xt,"--vela-accent-bright":Xi,"--vela-highlight":yb,"--vela-selected-bg":e?"#f0f3fa":r.textColor,"--vela-selected-fg":e?r.background:"#ffffff","--vela-fg-on-fill":"#ffffff","--vela-up":r.upColor,"--vela-down":r.downColor,"--vela-danger":r.downColor,"--vela-shadow":"0 8px 30px rgba(0,0,0,0.5)","--vela-shadow-dialog":"0 20px 60px rgba(0,0,0,0.5)","--vela-backdrop":"rgba(0,0,0,0.45)"}}function Xe(r,e){let t=n=>{for(let i in n)r.style.setProperty(i,n[i]);};t(Wc),t(Gc(e));}function Pn(r,e){let t=null,n=null,i=()=>{t!==null&&(clearTimeout(t),t=null),n?.remove(),n=null;},o=()=>{let a=e.text();if(!a)return;n=r.ownerDocument.createElement("div"),n.textContent=a,n.style.cssText="position:absolute;z-index:var(--vela-z-tooltip);pointer-events:none;background:var(--vela-bg);border:1px solid var(--vela-border);color:var(--vela-fg);border-radius:var(--vela-radius-md);padding:4px 9px;box-shadow:var(--vela-shadow);font:var(--vela-font-size-md) var(--vela-font);"+(e.wrap?"max-width:260px;":"white-space:nowrap;"),Xe(n,e.theme()),e.host.appendChild(n);let d=r.getBoundingClientRect(),u=e.host.getBoundingClientRect();if(e.placement==="right")n.style.left=`${d.right-u.left+8}px`,n.style.top=`${d.top-u.top+(d.height-n.offsetHeight)/2}px`;else {let h=Math.min(d.left-u.left,Math.max(0,u.width-n.offsetWidth-4));n.style.left=`${Math.max(0,h)}px`,n.style.top=e.placement==="above"?`${Math.max(0,d.top-u.top-n.offsetHeight-6)}px`:`${d.bottom-u.top+6}px`;}},s=a=>{a.pointerType==="mouse"&&(i(),t=window.setTimeout(o,e.delayMs??700));};return r.addEventListener("pointerenter",s),r.addEventListener("pointerleave",i),r.addEventListener("pointerdown",i),()=>{r.removeEventListener("pointerenter",s),r.removeEventListener("pointerleave",i),r.removeEventListener("pointerdown",i),i();}}function Uc(r,e){let t=e.size??16,n=document.createElement("span");n.className="vela-hint",n.setAttribute("role","img"),n.setAttribute("aria-label",r),n.innerHTML=Ge("info",t),n.style.cssText=`flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:${t}px;height:${t}px;border-radius:50%;cursor:help;user-select:none;background:var(--vela-hover);color:var(--vela-fg-muted);transition:background var(--vela-dur-fast) ease,color var(--vela-dur-fast) ease;`;let i=s=>{n.style.background=s?"var(--vela-active)":"var(--vela-hover)",n.style.color=s?"var(--vela-fg-bright)":"var(--vela-fg-muted)";};n.addEventListener("pointerenter",()=>i(true)),n.addEventListener("pointerleave",()=>i(false));let o=Pn(n,{host:e.host,theme:e.theme,text:()=>r,wrap:true,delayMs:250});return {el:n,dispose:o}}var hP=Object.defineProperty,pP=(r,e,t)=>e in r?hP(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t,we=(r,e,t)=>pP(r,typeof e!="symbol"?e+"":e,t);function Bv(r){return r==null?[]:Array.isArray(r)?r:[r]}var Vv=r=>r[0],Hv=r=>r[r.length-1];function _v(r,e,t={}){let{step:n=1,loop:i=true}=t,o=e+n,s=r.length,a=s-1;return e===-1?n>0?0:a:o<0?i?a:0:o>=s?i?0:e>s?s:e:o}function zv(r,e,t={}){return r[_v(r,e,t)]}function mP(r,e,t={}){let{step:n=1,loop:i=true}=t;return _v(r,e,{step:-n,loop:i})}function Wv(r,e,t={}){return r[mP(r,e,t)]}var Gv=r=>r?.constructor.name==="Array",gP=(r,e)=>{if(r.length!==e.length)return false;for(let t=0;t<r.length;t++)if(!ho(r[t],e[t]))return false;return true},ho=(r,e)=>{if(Object.is(r,e))return true;if(r==null&&e!=null||r!=null&&e==null)return false;if(typeof r?.isEqual=="function"&&typeof e?.isEqual=="function")return r.isEqual(e);if(typeof r=="function"&&typeof e=="function")return r.toString()===e.toString();if(Gv(r)&&Gv(e))return gP(Array.from(r),Array.from(e));if(typeof r!="object"||typeof e!="object")return false;let t=Object.keys(e??Object.create(null)),n=t.length;for(let i=0;i<n;i++)if(!Reflect.has(r,t[i]))return false;for(let i=0;i<n;i++){let o=t[i];if(!ho(r[o],e[o]))return false}return true};var fP=r=>r!=null&&typeof r=="object";var po=r=>typeof r=="string",Ot=r=>typeof r=="function",Uv=r=>r==null,Us=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),bP=r=>Object.prototype.toString.call(r),$v=Function.prototype.toString,vP=$v.call(Object),bi=r=>{if(!fP(r)||bP(r)!="[object Object]"||xP(r))return false;let e=Object.getPrototypeOf(r);if(e===null)return true;let t=Us(e,"constructor")&&e.constructor;return typeof t=="function"&&t instanceof t&&$v.call(t)==vP},yP=r=>typeof r=="object"&&r!==null&&"$$typeof"in r&&"props"in r,wP=r=>typeof r=="object"&&r!==null&&"__v_isVNode"in r,xP=r=>yP(r)||wP(r);var $s=(r,...e)=>(typeof r=="function"?r(...e):r)??void 0,Qh=r=>r,Yv=r=>r(),Jh=()=>{},Tr=(...r)=>(...e)=>{r.forEach(function(t){t?.(...e);});};function kr(r){if(!bi(r)||r===void 0)return r;let e=Reflect.ownKeys(r).filter(n=>typeof n=="string"),t={};for(let n of e){let i=r[n];i!==void 0&&(t[n]=kr(i));}return t}function mo(...r){r.length===1?r[0]:r[1];r.length===2?r[0]:true;}function ep(...r){r.length===1?r[0]:r[1];r.length===2?r[0]:true;}function Ys(r,e){if(r==null)throw new Error(e())}var SP=(...r)=>r.map(e=>e?.trim?.()).filter(Boolean).join(" "),CP=/((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g,Kv=r=>{let e={},t;for(;t=CP.exec(r);)e[t[1]]=t[2];return e},TP=(r,e)=>{if(po(r)){if(po(e))return `${r};${e}`;r=Kv(r);}else po(e)&&(e=Kv(e));return Object.assign({},r??{},e??{})};function Xv(...r){let e={};for(let t of r){if(!t)continue;for(let i in e){if(i.startsWith("on")&&typeof e[i]=="function"&&typeof t[i]=="function"){e[i]=Tr(t[i],e[i]);continue}if(i==="className"||i==="class"){e[i]=SP(e[i],t[i]);continue}if(i==="style"){e[i]=TP(e[i],t[i]);continue}e[i]=t[i]!==void 0?t[i]:e[i];}for(let i in t)e[i]===void 0&&(e[i]=t[i]);let n=Object.getOwnPropertySymbols(t);for(let i of n)e[i]=t[i];}return e}var Lr=".",Zv="#",jv=new WeakMap,Qv=new WeakMap;function tp(r){return r.join(Lr)}function kP(r){return r.includes(Lr)}function Jv(r){return r.startsWith(Zv)}function LP(r){return r.startsWith(Lr)}function MP(r){return Jv(r)?r.slice(Zv.length):r}function np(r,e){return r?`${r}${Lr}${e}`:e}function EP(r){let e=new Map,t=new Map,n=(i,o)=>{e.set(i,o);let s=o.id;s&&(t.has(s)&&ep(`[zag-js] Duplicate state id: "${s}"`),t.set(s,i));let a=o.states;if(a){Ys(o.initial,()=>`[zag-js] Compound state "${i}" has child states but no "initial" property`),o.initial in a||ep(`[zag-js] Compound state "${i}" has initial "${String(o.initial)}" which is not a child state`);for(let[l,d]of Object.entries(a)){if(!d)continue;let u=np(i,l);n(u,d);}}};for(let[i,o]of Object.entries(r.states))o&&n(i,o);return {index:e,idIndex:t}}function go(r){let e=jv.get(r);if(e)return e;let{index:t,idIndex:n}=EP(r);return jv.set(r,t),Qv.set(r,n),t}function PP(r,e){return go(r),Qv.get(r)?.get(e)}function rp(r){return r?String(r).split(Lr).filter(Boolean):[]}function $c(r,e){if(!e)return [];let t=go(r),n=rp(e),i=[],o=[];for(let s of n){o.push(s);let a=tp(o),l=t.get(a);if(!l)break;i.push({path:a,state:l});}return i}function Ks(r,e){let t=go(r),n=rp(e);if(!n.length)return e;let i=[];for(let a of n){i.push(a);let l=tp(i);if(!t.has(l))return e}let o=tp(i),s=t.get(o);for(;s?.initial;){let a=`${o}${Lr}${s.initial}`,l=t.get(a);if(!l)break;o=a,s=l;}return o}function qv(r,e){return go(r).has(e)}function ip(r,e,t){let n=String(e);if(Jv(n)){let i=MP(n),o=PP(r,i);return Ys(o,()=>`[zag-js] Unknown state id: "${i}"`),Ks(r,o)}if(LP(n)&&t){let i=np(t,n.slice(1));return Ks(r,i)}if(!kP(n)&&t){let i=rp(t);for(let o=i.length-1;o>=1;o--){let s=i.slice(0,o).join(Lr),a=np(s,n);if(qv(r,a))return Ks(r,a)}if(qv(r,n))return Ks(r,n)}return Ks(r,n)}function ey(r,e,t){let n=$c(r,e);for(let o=n.length-1;o>=0;o--){let a=n[o]?.state.on?.[t];if(a)return {transitions:a,source:n[o]?.path}}return {transitions:r.on?.[t],source:void 0}}function ty(r,e,t,n){let i=e?$c(r,e):[],o=$c(r,t),s=0;for(;s<i.length&&s<o.length&&i[s]?.path===o[s]?.path;)s+=1;let a=i.slice(s).reverse(),l=o.slice(s),d=i.at(-1)?.path===o.at(-1)?.path;return n&&d&&(a=i.slice().reverse(),l=o),{exiting:a,entering:l}}function ny(r,e){return r?r===e||r.startsWith(`${e}${Lr}`):false}function ry(r,e,t){return $c(r,e).some(n=>n.state.tags?.includes(t))}function iy(){return {and:(...r)=>function(t){return r.every(n=>t.guard(n))},or:(...r)=>function(t){return r.some(n=>t.guard(n))},not:r=>function(t){return !t.guard(r)}}}function Yc(r){return go(r),r}var fo=(r=>(r.NotStarted="Not Started",r.Started="Started",r.Stopped="Stopped",r))(fo||{}),Xs="__init__";var IP=Object.defineProperty,AP=(r,e,t)=>e in r?IP(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t,Kc=(r,e,t)=>AP(r,typeof e!="symbol"?e+"":e,t);var oy=(r,e)=>r.map((t,n)=>r[(Math.max(e,0)+n)%r.length]);var js=()=>{},qs=r=>typeof r=="object"&&r!==null;var Kt=r=>r?"":void 0,op=r=>r?"true":void 0;var RP=1,DP=9,OP=11;var Se=r=>qs(r)&&r.nodeType===RP&&typeof r.nodeName=="string",Zs=r=>qs(r)&&r.nodeType===DP,NP=r=>qs(r)&&r===r.window;var sy=r=>Se(r)?r.localName||"":"#document";function ay(r){return ["html","body","#document"].includes(sy(r))}var ly=r=>qs(r)&&r.nodeType!==void 0,vi=r=>ly(r)&&r.nodeType===OP&&"host"in r,sp=r=>Se(r)&&r.localName==="input",cy=r=>!!r?.matches("a[href]"),dy=r=>Se(r)?r.offsetWidth>0||r.offsetHeight>0||r.getClientRects().length>0:false;function Qs(r){if(!r)return false;let e=r.getRootNode();return In(e)===r}var FP=/(textarea|select)/;function bo(r){if(r==null||!Se(r))return false;try{return sp(r)&&r.selectionStart!=null||FP.test(r.localName)||r.isContentEditable||r.getAttribute("contenteditable")==="true"||r.getAttribute("contenteditable")===""}catch{return false}}function Nt(r,e){if(!r||!e||!Se(r)||!ly(e))return false;if(Se(e)&&r===e||r.contains(e))return true;let t=e.getRootNode?.();if(t&&vi(t)){let n=e;for(;n;){if(r===n)return true;n=n.parentNode||n.host;}}return false}function $e(r){return Zs(r)?r:NP(r)?r.document:r?.ownerDocument??document}function BP(r){return $e(r).documentElement}function _e(r){return vi(r)?_e(r.host):Zs(r)?r.defaultView??window:Se(r)?r.ownerDocument?.defaultView??window:window}function In(r){let e=r.activeElement;for(;e?.shadowRoot;){let t=e.shadowRoot.activeElement;if(!t||t===e)break;e=t;}return e}function uy(r){if(sy(r)==="html")return r;let e=r.assignedSlot||r.parentNode||vi(r)&&r.host||BP(r);return vi(e)?e.host:e}function Xc(r){let e;try{if(e=r.getRootNode({composed:!0}),Zs(e)||vi(e))return e}catch{}return r.ownerDocument??document}var ap=new WeakMap;function vo(r){return ap.has(r)||ap.set(r,_e(r).getComputedStyle(r)),ap.get(r)}var lp=new Set(["menu","listbox","dialog","grid","tree","region","application"]),VP=r=>lp.has(r),hy=r=>r.getAttribute("aria-controls")?.split(" ")||[];function jc(r,e){let t=new Set,n=Xc(r),i=o=>{let s=o.querySelectorAll("[aria-controls]");for(let a of s){if(a.getAttribute("aria-expanded")!=="true")continue;let l=hy(a);for(let d of l){if(!d||t.has(d))continue;t.add(d);let u=n.getElementById(d);if(u){let h=u.getAttribute("role"),p=u.getAttribute("aria-modal")==="true";if(h&&VP(h)&&!p&&(u===e||u.contains(e)||i(u)))return true}}}return false};return i(r)}function cp(r,e){let t=Xc(r),n=new Set,i=o=>{let s=o.querySelectorAll("[aria-controls]");for(let a of s){if(a.getAttribute("aria-expanded")!=="true")continue;let l=hy(a);for(let d of l){if(!d||n.has(d))continue;n.add(d);let u=t.getElementById(d);if(u){let h=u.getAttribute("role"),p=u.getAttribute("aria-modal")==="true";h&&lp.has(h)&&!p&&(e(u),i(u));}}}};i(r);}function py(r){let e=new Set;return cp(r,t=>{r.contains(t)||e.add(t);}),Array.from(e)}function HP(r){let e=r.getAttribute("role");return !!(e&&lp.has(e))}function _P(r){return r.hasAttribute("aria-controls")&&r.getAttribute("aria-expanded")==="true"}function my(r){return _P(r)?true:!!r.querySelector?.('[aria-controls][aria-expanded="true"]')}function gy(r){if(!r.id)return false;let e=Xc(r),t=CSS.escape(r.id),n=`[aria-controls~="${t}"][aria-expanded="true"], [aria-controls="${t}"][aria-expanded="true"]`;return !!(e.querySelector(n)&&HP(r))}var dp=()=>typeof document<"u";function zP(){return navigator.userAgentData?.platform??navigator.platform}function WP(){let r=navigator.userAgentData;return r&&Array.isArray(r.brands)?r.brands.map(({brand:e,version:t})=>`${e}/${t}`).join(" "):navigator.userAgent}var up=r=>dp()&&r.test(zP()),fy=r=>dp()&&r.test(WP());var hp=()=>dp()&&!!navigator.maxTouchPoints,GP=()=>up(/^iPhone/i),UP=()=>up(/^iPad/i)||yo()&&navigator.maxTouchPoints>1,by=()=>GP()||UP();var yo=()=>up(/^Mac/i);var vy=()=>fy(/Firefox/i);var yy=()=>fy(/Android/i);function $P(r){return r.composedPath?.()??r.nativeEvent?.composedPath?.()}function Ze(r){return $P(r)?.[0]??r.target}function pp(r){let e=r.currentTarget;if(!e||!e.matches("a[href], button[type='submit'], input[type='submit']"))return false;let n=r.button===1,i=YP(r);return n||i}function mp(r){let e=r.currentTarget;if(!e)return false;let t=e.localName;return r.altKey?t==="a"||t==="button"&&e.type==="submit"||t==="input"&&e.type==="submit":false}function YP(r){return yo()?r.metaKey:r.ctrlKey}function xy(r){return r.key.length===1&&!r.ctrlKey&&!r.metaKey}function Sy(r){return r.pointerType===""&&r.isTrusted?true:yy()&&r.pointerType?r.type==="click"&&r.buttons===1:r.detail===0&&!r.pointerType}var qc=r=>r.button===2||yo()&&r.ctrlKey&&r.button===0,Cy=r=>r.ctrlKey||r.altKey||r.metaKey,KP=r=>"touches"in r&&r.touches.length>0,XP={Up:"ArrowUp",Down:"ArrowDown",Esc:"Escape"," ":"Space",",":"Comma",Left:"ArrowLeft",Right:"ArrowRight"},wy={ArrowLeft:"ArrowRight",ArrowRight:"ArrowLeft"};function gp(r,e={}){let{dir:t="ltr",orientation:n="horizontal"}=e,i=r.key;return i=XP[i]??i,t==="rtl"&&n==="horizontal"&&i in wy&&(i=wy[i]),i}function wo(r,e="client"){let t=KP(r)?r.touches[0]||r.changedTouches[0]:r;return {x:t[`${e}X`],y:t[`${e}Y`]}}var Ct=(r,e,t,n)=>{let i=typeof r=="function"?r():r;return i?.addEventListener(e,t,n),()=>{i?.removeEventListener(e,t,n);}};var Ty=r=>Se(r)&&r.tagName==="IFRAME",jP=/^(audio|video|details)$/;function ky(r){let e=r.getAttribute("tabindex");return e?parseInt(e,10):NaN}var qP=r=>!Number.isNaN(ky(r)),ZP=r=>ky(r)<0;function QP(r){return sp(r)&&r.type==="radio"}function JP(r){if(!QP(r)||!r.name||r.checked)return true;let e=`input[type="radio"][name="${CSS.escape(r.name)}"]`,t=r.form??r.ownerDocument,n=Array.from(t.querySelectorAll(e)).filter(o=>o.form===r.form&&Xt(o)),i=n.find(o=>o.checked);return i?i===r:n[0]===r}function eI(r,e){if(!e)return null;if(e===true)return r.shadowRoot||null;let t=e(r);return (t===true?r.shadowRoot:t)||null}function Ly(r,e,t){let n=[...r],i=[...r],o=new Set,s=new Map;r.forEach((l,d)=>s.set(l,d));let a=0;for(;a<i.length;){let l=i[a++];if(!l||o.has(l))continue;o.add(l);let d=eI(l,e);if(d){let u=Array.from(d.querySelectorAll(Zc)).filter(t),h=s.get(l);if(h!==void 0){let p=h+1;n.splice(p,0,...u),u.forEach((m,g)=>{s.set(m,p+g);});for(let m=p+u.length;m<n.length;m++)s.set(n[m],m);}else {let p=n.length;n.push(...u),u.forEach((m,g)=>{s.set(m,p+g);});}i.push(...u);}}return n}var Zc="input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type",fp=(r,e={})=>{if(!r)return [];let{includeContainer:t=false,getShadowRoot:n}=e,i=Array.from(r.querySelectorAll(Zc));(t==true||t=="if-empty"&&i.length===0)&&Se(r)&&Xt(r)&&i.unshift(r);let s=[];for(let a of i)if(Xt(a)){if(Ty(a)&&a.contentDocument){let l=a.contentDocument.body;s.push(...fp(l,{getShadowRoot:n}));continue}s.push(a);}return n?Ly(s,n,Xt):s};function Xt(r){return !Se(r)||r.closest("[inert]")?false:r.matches(Zc)&&dy(r)}function xo(r,e={}){if(!r)return [];let{includeContainer:t,getShadowRoot:n}=e,i=Array.from(r.querySelectorAll(Zc));t&&Mr(r)&&i.unshift(r);let o=[];for(let s of i)if(Mr(s)){if(Ty(s)&&s.contentDocument){let a=s.contentDocument.body;o.push(...xo(a,{getShadowRoot:n}));continue}o.push(s);}if(n){let s=Ly(o,n,Mr);return !s.length&&t?i:s}return !o.length&&t?i:o}function Mr(r){return Se(r)&&r.tabIndex>0?true:!Xt(r)||ZP(r)?false:JP(r)}function My(r,e={}){let t=xo(r,e),n=t[0]||null,i=t[t.length-1]||null;return [n,i]}function So(r){return r.tabIndex<0&&(jP.test(r.localName)||bo(r))&&!qP(r)?0:r.tabIndex}function Qc(r){let{root:e,getInitialEl:t,filter:n,enabled:i=true}=r;if(!i)return;let o=null;if(o||(o=typeof t=="function"?t():t),o||(o=e?.querySelector("[data-autofocus],[autofocus]")),!o){let s=xo(e);o=n?s.filter(n)[0]:s[0];}return o||e||void 0}function Ey(r){let e=r.currentTarget;if(!e)return false;let[t,n]=My(e);return !(Qs(t)&&r.shiftKey||Qs(n)&&!r.shiftKey||!t&&!n)}var tI=class Py{constructor(){Kc(this,"id",null),Kc(this,"fn_cleanup"),Kc(this,"cleanup",()=>{this.cancel();});}static create(){return new Py}request(e){this.cancel(),this.id=globalThis.requestAnimationFrame(()=>{this.id=null,this.fn_cleanup=e?.();});}cancel(){this.id!==null&&(globalThis.cancelAnimationFrame(this.id),this.id=null),this.fn_cleanup?.(),this.fn_cleanup=void 0;}isActive(){return this.id!==null}};function je(r){let e=tI.create();return e.request(r),e.cleanup}function Iy(r){let e=new Set;function t(n){let i=globalThis.requestAnimationFrame(n);e.add(()=>globalThis.cancelAnimationFrame(i));}return t(()=>t(r)),function(){e.forEach(i=>i());}}function Ay(r,e,t){let n=je(()=>{r.removeEventListener(e,i,true),t();}),i=()=>{n(),t();};return r.addEventListener(e,i,{once:true,capture:true}),n}function nI(r,e){if(!r)return;let{attributes:t,callback:n}=e,i=r.ownerDocument.defaultView||window,o=new i.MutationObserver(s=>{for(let a of s)a.type==="attributes"&&a.attributeName&&t.includes(a.attributeName)&&n(a);});return o.observe(r,{attributes:true,attributeFilter:t}),()=>o.disconnect()}function Ry(r,e){let n=je,i=[];return i.push(n(()=>{let o=typeof r=="function"?r():r;i.push(nI(o,e));})),()=>{i.forEach(o=>o?.());}}function Dy(r){let e=()=>{let t=_e(r);r.dispatchEvent(new t.MouseEvent("click"));};vy()?Ay(r,"keyup",e):queueMicrotask(e);}function Jc(r){let e=uy(r);return ay(e)?$e(e).body:Se(e)&&bp(e)?e:Jc(e)}var rI=/auto|scroll|overlay|hidden|clip/,iI=new Set(["inline","contents"]);function bp(r){let e=_e(r),{overflow:t,overflowX:n,overflowY:i,display:o}=e.getComputedStyle(r);return rI.test(t+i+n)&&!iI.has(o)}function Co(r,e){return Array.from(r?.querySelectorAll(e)??[])}var ed=r=>r.id;function oI(r,e,t=ed){return r.find(n=>t(n)===e)}function Oy(r,e,t=ed){let n=oI(r,e,t);return n?r.indexOf(n):-1}function sI(r){return r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth}function Ny(r,e){let{rootEl:t,...n}=e||{};!r||!t||!bp(t)||!sI(t)||r.scrollIntoView(n);}var aI=r=>r.split("").map(e=>{let t=e.charCodeAt(0);return t>0&&t<128?e:t>=128&&t<=255?`/x${t.toString(16)}`.replace("/","\\"):""}).join("").trim(),lI=r=>aI(r.dataset?.valuetext??r.textContent??""),cI=(r,e)=>r.trim().toLowerCase().startsWith(e.toLowerCase());function Fy(r,e,t,n=ed){let i=t?Oy(r,t,n):-1,o=t?oy(r,i):r;return e.length===1&&(o=o.filter(a=>n(a)!==t)),o.find(a=>cI(lI(a),e))}function Js(r,e){if(!r)return js;let t=Object.keys(e).reduce((n,i)=>(n[i]=r.style.getPropertyValue(i),n),{});return dI(t,e)?js:(Object.assign(r.style,e),()=>{Object.assign(r.style,t),r.style.length===0&&r.removeAttribute("style");})}function By(r,e,t){if(!r)return js;let n=r.style.getPropertyValue(e);return n===t?js:(r.style.setProperty(e,t),()=>{r.style.setProperty(e,n),r.style.length===0&&r.removeAttribute("style");})}function dI(r,e){return Object.keys(r).every(t=>r[t]===e[t])}function uI(r,e){let{state:t,activeId:n,key:i,timeout:o=350,itemToId:s}=e,a=t.keysSoFar+i,d=a.length>1&&Array.from(a).every(g=>g===a[0])?a[0]:a,u=r.slice(),h=Fy(u,d,n,s);function p(){clearTimeout(t.timer),t.timer=-1;}function m(g){t.keysSoFar=g,p(),g!==""&&(t.timer=+setTimeout(()=>{m(""),p();},o));}return m(a),h}var td=Object.assign(uI,{defaultOptions:{keysSoFar:"",timer:-1},isValidEvent:hI});function hI(r){return r.key.length===1&&!r.ctrlKey&&!r.metaKey}function pI(r,e,t){let{signal:n}=e;return [new Promise((s,a)=>{let l=setTimeout(()=>{a(new Error(`Timeout of ${t}ms exceeded`));},t);n.addEventListener("abort",()=>{clearTimeout(l),a(new DOMException("Promise aborted","AbortError"));}),r.then(d=>{n.aborted||(clearTimeout(l),s(d));}).catch(d=>{n.aborted||(clearTimeout(l),a(d));});}),()=>e.abort()]}function Vy(r,e){let{timeout:t,rootNode:n}=e,i=_e(n),o=$e(n),s=new i.AbortController;return pI(new Promise(a=>{let l=r();if(l){a(l);return}let d=new i.MutationObserver(()=>{let u=r();u&&u.isConnected&&(d.disconnect(),a(u));});d.observe(o.body,{childList:true,subtree:true});}),s,t)}function Hy(r){let e=()=>r.getRootNode?.()??document,t=()=>$e(e());return {...r,getRootNode:e,getDoc:t,getWin:()=>t().defaultView??window,getActiveElement:()=>In(e()),isActiveElement:Qs,getById:s=>e().getElementById(s)}}function _y(r){return new Proxy({},{get(e,t){return t==="style"?n=>r({style:n}).style:r}})}var zy={onFocus:"onFocusin",onBlur:"onFocusout",onChange:"onInput",onDoubleClick:"onDblclick",htmlFor:"for",className:"class",defaultValue:"value",defaultChecked:"checked"},mI=new Set(["viewBox","preserveAspectRatio"]),gI=r=>{let e="";for(let t in r){let n=r[t];n!=null&&(t.startsWith("--")||(t=t.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)),e+=`${t}:${n};`);}return e},To=_y(r=>Object.entries(r).reduce((e,[t,n])=>{if(n===void 0)return e;if(t in zy&&(t=zy[t]),t==="style"&&typeof n=="object")return e.style=gI(n),e;let i=mI.has(t)?t:t.toLowerCase();return e[i]=n,e},{}));var nd=new WeakMap,Wy=new Set(["value","checked","selected"]),fI=new Set(["viewBox","preserveAspectRatio","clipPath","clipRule","fillRule","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeDashoffset","strokeMiterlimit"]),bI=r=>r.tagName==="svg"||r.namespaceURI==="http://www.w3.org/2000/svg",rd=(r,e)=>bI(r)&&fI.has(e)?e:e.toLowerCase();function Ft(r,e,t){let n=t||"default",i=nd.get(r);i||(i=new Map,nd.set(r,i));let o=i.get(n)||{},s=Object.keys(e),a=(b,f)=>{r.addEventListener(b.toLowerCase(),f);},l=(b,f)=>{r.removeEventListener(b.toLowerCase(),f);},d=b=>b.startsWith("on"),u=b=>!b.startsWith("on"),h=b=>a(b.substring(2),e[b]),p=b=>l(b.substring(2),e[b]),m=b=>{let f=e[b],v=o[b];if(f!==v){if(b==="class"){r.className=f??"";return}if(Wy.has(b)){r[b]=f??"";return}if(typeof f=="boolean"&&!b.includes("aria-")){r.toggleAttribute(rd(r,b),f);return}if(b==="children"){r.innerHTML=f;return}if(f!=null){r.setAttribute(rd(r,b),f);return}r.removeAttribute(rd(r,b));}};for(let b in o)e[b]==null&&(b==="class"?r.className="":Wy.has(b)?r[b]="":r.removeAttribute(rd(r,b)));return Object.keys(o).filter(d).forEach(b=>{l(b.substring(2),o[b]);}),s.filter(d).forEach(h),s.filter(u).forEach(m),i.set(n,e),function(){s.filter(d).forEach(p);let f=nd.get(r);f&&(f.delete(n),f.size===0&&nd.delete(r));}}function vI(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function vp(r,e){let t=vI();return t?(t[r]||(t[r]=e()),t[r]):e()}var ko=vp("__zag__refSet",()=>new WeakSet);var yI=r=>typeof r=="object"&&r!==null&&"$$typeof"in r&&"props"in r,wI=r=>typeof r=="object"&&r!==null&&"__v_isVNode"in r,xI=r=>typeof r=="object"&&r!==null&&"nodeType"in r&&typeof r.nodeName=="string",SI=r=>yI(r)||wI(r)||xI(r),id=r=>r!==null&&typeof r=="object",yp=r=>id(r)&&!ko.has(r)&&(Array.isArray(r)||!(Symbol.iterator in r))&&!SI(r)&&!(r instanceof WeakMap)&&!(r instanceof WeakSet)&&!(r instanceof Error)&&!(r instanceof Number)&&!(r instanceof Date)&&!(r instanceof String)&&!(r instanceof RegExp)&&!(r instanceof ArrayBuffer)&&!(r instanceof Promise)&&!(r instanceof File)&&!(r instanceof Blob)&&!(r instanceof AbortController);var CI=Symbol();var Gy=Object.getPrototypeOf,wp=new WeakMap,TI=r=>r&&(wp.has(r)?wp.get(r):Gy(r)===Object.prototype||Gy(r)===Array.prototype);var Uy=r=>TI(r)&&r[CI]||null,xp=(r,e=true)=>{wp.set(r,e);};var yi=vp("__zag__proxyStateMap",()=>new WeakMap),kI=(r=Object.is,e=(a,l)=>new Proxy(a,l),t=new WeakMap,n=(a,l)=>{let d=t.get(a);if(d?.[0]===l)return d[1];let u=Array.isArray(a)?[]:Object.create(Object.getPrototypeOf(a));return xp(u,true),t.set(a,[l,u]),Reflect.ownKeys(a).forEach(h=>{let p=Reflect.get(a,h);ko.has(p)?(xp(p,false),u[h]=p):yi.has(p)?u[h]=$y(p):u[h]=p;}),Object.freeze(u)},i=new WeakMap,o=[1,1],s=a=>{if(!id(a))throw new Error("object required");let l=i.get(a);if(l)return l;let d=o[0],u=new Set,h=(L,y=++o[0])=>{d!==y&&(d=y,u.forEach(E=>E(L,y)));},p=o[1],m=(L=++o[1])=>(p!==L&&!u.size&&(p=L,b.forEach(([y])=>{let E=y[1](L);E>d&&(d=E);})),d),g=L=>(y,E)=>{let S=[...y];S[1]=[L,...S[1]],h(S,E);},b=new Map,f=(L,y)=>{if(u.size){let E=y[3](g(L));b.set(L,[y,E]);}else b.set(L,[y]);},v=L=>{let y=b.get(L);y&&(b.delete(L),y[1]?.());},w=L=>(u.add(L),u.size===1&&b.forEach(([E,S],P)=>{let A=E[3](g(P));b.set(P,[E,A]);}),()=>{u.delete(L),u.size===0&&b.forEach(([E,S],P)=>{S&&(S(),b.set(P,[E]));});}),x=Array.isArray(a)?[]:Object.create(Object.getPrototypeOf(a)),M=e(x,{deleteProperty(L,y){let E=Reflect.get(L,y);v(y);let S=Reflect.deleteProperty(L,y);return S&&h(["delete",[y],E]),S},set(L,y,E,S){let P=Reflect.has(L,y),A=Reflect.get(L,y,S);if(P&&(r(A,E)||i.has(E)&&r(A,i.get(E))))return true;v(y),id(E)&&(E=Uy(E)||E);let F=E;if(!Object.getOwnPropertyDescriptor(L,y)?.set){!yi.has(E)&&yp(E)&&(F=od(E));let G=!ko.has(F)&&yi.get(F);G&&f(y,G);}return Reflect.set(L,y,F,S),h(["set",[y],E,A]),true}});i.set(a,M);let C=[x,m,n,w];return yi.set(M,C),Reflect.ownKeys(a).forEach(L=>{let y=Object.getOwnPropertyDescriptor(a,L);y.get||y.set?Object.defineProperty(x,L,y):M[L]=a[L];}),M})=>[s,yi,ko,r,e,yp,t,n,i,o],[LI]=kI();function od(r={}){return LI(r)}function sd(r,e,t){let n=yi.get(r);let i,o=[],s=n[3],a=false,d=s(u=>{if(o.push(u),t);i||(i=Promise.resolve().then(()=>{i=void 0,a&&e(o.splice(0));}));});return a=true,()=>{a=false,d();}}function $y(r){let e=yi.get(r);let[t,n,i]=e;return i(t,n())}function ta(r){let e=r().value??r().defaultValue;r().debug&&console.log(`[bindable > ${r().debug}] initial`,e);let t=r().isEqual??Object.is,n=od({value:e}),i=()=>r().value!==void 0;return {initial:e,ref:n,get(){return i()?r().value:n.value},set(o){let s=i()?r().value:n.value,a=Ot(o)?o(s):o;r().debug&&console.log(`[bindable > ${r().debug}] setValue`,{next:a,prev:s}),i()||(n.value=a),t(a,s)||r().onChange?.(a,s);},invoke(o,s){r().onChange?.(o,s);},hash(o){return r().hash?.(o)??String(o)}}}ta.cleanup=r=>{};ta.ref=r=>{let e=r;return {get:()=>e,set:t=>{e=t;}}};function Yy(r){let e={current:r};return {get(t){return e.current[t]},set(t,n){e.current[t]=n;}}}function Sp(r,e){if(!bi(r)||!bi(e))return e===void 0?r:e;let t={...r};for(let n of Object.keys(e)){let i=e[n],o=r[n];i!==void 0&&(bi(o)&&bi(i)?t[n]=Sp(o,i):t[n]=i);}return t}var Cp=class{constructor(r,e={}){we(this,"machine",r),we(this,"scope"),we(this,"context"),we(this,"prop"),we(this,"state"),we(this,"refs"),we(this,"computed"),we(this,"event",{type:""}),we(this,"previousEvent",{type:""}),we(this,"effects",new Map),we(this,"transition",null),we(this,"cleanups",[]),we(this,"subscriptions",[]),we(this,"userPropsRef"),we(this,"getEvent",()=>({...this.event,current:()=>this.event,previous:()=>this.previousEvent})),we(this,"getState",()=>({...this.state,matches:(...h)=>h.some(p=>ny(this.state.get(),p)),hasTag:h=>ry(this.machine,this.state.get(),h)})),we(this,"debug",(...h)=>{this.machine.debug&&console.log(...h);}),we(this,"notify",()=>{this.publish();}),we(this,"send",h=>{this.status===fo.Started&&queueMicrotask(()=>{if(!h)return;this.previousEvent=this.event,this.event=h,this.debug("send",h);let p=this.state.get(),m=h.type,{transitions:g,source:b}=ey(this.machine,p,m),f=this.choose(g);if(!f)return;this.transition=f;let v=ip(this.machine,f.target??p,b);this.debug("transition",f),v!==p?this.state.set(v):f.reenter?this.state.invoke(p,p):this.action(f.actions);});}),we(this,"action",h=>{let p=Ot(h)?h(this.getParams()):h;if(!p)return;let m=p.map(g=>{let b=this.machine.implementations?.actions?.[g];return b||mo(`[zag-js] No implementation found for action "${JSON.stringify(g)}"`),b});for(let g of m)g?.(this.getParams());}),we(this,"guard",h=>{if(Ot(h))return h(this.getParams());let p=this.machine.implementations?.guards?.[h];return p||mo(`[zag-js] No implementation found for guard "${JSON.stringify(h)}"`),p?.(this.getParams())}),we(this,"effect",h=>{let p=Ot(h)?h(this.getParams()):h;if(!p)return;let m=p.map(b=>{let f=this.machine.implementations?.effects?.[b];return f||mo(`[zag-js] No implementation found for effect "${JSON.stringify(b)}"`),f}),g=[];for(let b of m){let f=b?.(this.getParams());f&&g.push(f);}return ()=>g.forEach(b=>b?.())}),we(this,"choose",h=>Bv(h).find(p=>{let m=!p.guard;return po(p.guard)?m=!!this.guard(p.guard):Ot(p.guard)&&(m=p.guard(this.getParams())),m})),we(this,"subscribe",h=>(this.subscriptions.push(h),()=>{let p=this.subscriptions.indexOf(h);p>-1&&this.subscriptions.splice(p,1);})),we(this,"status",fo.NotStarted),we(this,"publish",()=>{this.callTrackers(),this.subscriptions.forEach(h=>h(this.service));}),we(this,"trackers",[]),we(this,"setupTrackers",()=>{this.machine.watch?.(this.getParams());}),we(this,"callTrackers",()=>{this.trackers.forEach(({deps:h,fn:p})=>{let m=h.map(g=>g());ho(p.prev,m)||(p(),p.prev=m);});}),we(this,"getParams",()=>({state:this.getState(),context:this.context,event:this.getEvent(),prop:this.prop,send:this.send,action:this.action,guard:this.guard,track:(h,p)=>{p.prev=h.map(m=>m()),this.trackers.push({deps:h,fn:p});},refs:this.refs,computed:this.computed,flush:Yv,scope:this.scope,choose:this.choose})),this.userPropsRef={current:e};let{id:t,ids:n,getRootNode:i}=$s(e);this.scope=Hy({id:t,ids:n,getRootNode:i});let o=h=>{let p=$s(this.userPropsRef.current);return (r.props?.({props:kr(p),scope:this.scope})??p)[h]};this.prop=o;let s=r.context?.({prop:o,bindable:ta,scope:this.scope,flush(h){queueMicrotask(h);},getContext(){return a},getComputed(){return l},getRefs(){return d},getEvent:this.getEvent.bind(this)});s&&Object.values(s).forEach(h=>{let p=sd(h.ref,()=>this.notify());this.cleanups.push(p);});let a={get(h){return s?.[h].get()},set(h,p){s?.[h].set(p);},initial(h){return s?.[h].initial},hash(h){let p=s?.[h].get();return s?.[h].hash(p)}};this.context=a;let l=h=>(Ys(r.computed,()=>"[zag-js] No computed object found on machine"),r.computed[h]({context:a,event:this.getEvent(),prop:o,refs:this.refs,scope:this.scope,computed:l}));this.computed=l;let d=Yy(r.refs?.({prop:o,context:a})??{});this.refs=d;let u=ta(()=>({defaultValue:ip(r,r.initialState({prop:o})),onChange:(h,p)=>{let{exiting:m,entering:g}=ty(this.machine,p,h,this.transition?.reenter);if(m.forEach(b=>{this.effects.get(b.path)?.(),this.effects.delete(b.path);}),m.forEach(b=>{this.action(b.state?.exit);}),this.action(this.transition?.actions),g.forEach(b=>{let f=this.effect(b.state?.effects);if(f){let v=this.effects.get(b.path);this.effects.set(b.path,v?Tr(v,f):f);}}),p===Xs){this.action(r.entry);let b=this.effect(r.effects);if(b){let f=this.effects.get(Xs);this.effects.set(Xs,f?Tr(f,b):b);}}g.forEach(b=>{this.action(b.state?.entry);});}}));this.state=u,this.cleanups.push(sd(this.state.ref,()=>this.notify()));}updateProps(r){let e=this.userPropsRef.current;this.userPropsRef.current=()=>{let t=$s(e),n=$s(r);return Sp(t,n)},this.notify();}start(){this.status=fo.Started,this.debug("initializing..."),this.state.invoke(this.state.initial,Xs),this.setupTrackers();}stop(){this.effects.forEach(r=>r?.()),this.effects.clear(),this.transition=null,this.action(this.machine.exit),this.cleanups.forEach(r=>r()),this.cleanups=[],this.subscriptions=[],this.status=fo.Stopped,this.debug("unmounting...");}get service(){return {state:this.getState(),send:this.send,context:this.context,prop:this.prop,scope:this.scope,refs:this.refs,computed:this.computed,event:this.getEvent(),getStatus:()=>this.status}}};function ad(r,e,t){let n=new Cp(r,e),i=n.subscribe(t);return n.start(),t(n.service),{service:n.service,flush:()=>t(n.service),stop:()=>{i(),n.stop();}}}var MI=0;function ld(r){return `${r}-${++MI}`}function wi(r,e=8){return `${r}::-webkit-scrollbar{width:${e}px;height:${e}px;}${r}::-webkit-scrollbar-thumb{background:var(--vela-scroll);border-radius:4px;border:2px solid transparent;background-clip:padding-box;}${r}::-webkit-scrollbar-track{background:transparent;}${r}::-webkit-scrollbar-button{display:none;width:0;height:0;}`}var Ky="outline:none;transition:border-color .12s ease,box-shadow .12s ease;",Xy="border-color:var(--vela-focus);box-shadow:0 0 0 3px var(--vela-focus-soft);";function xe(r,e,t=document){if(typeof document>"u")return;let n=t instanceof Document?t.head:t;if(t.getElementById?.(r)??n.querySelector(`#${CSS.escape(r)}`))return;let i=document.createElement("style");i.id=r,i.textContent=e,n.appendChild(i);}var EI="vela-ui-tokens",PI=Object.entries(Wc).map(([r,e])=>` ${r}: ${e};`).join(`
4
4
  `),II=`
5
5
  .vela-ui, .vela-ui-layer {
6
6
  ${PI}