@luxalgo/vela-pinets 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/vela-pinets.global.js +1282 -1269
- package/dist/vela-pinets.global.min.js +17 -17
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1342,7 +1342,7 @@ var PineEngine = class {
|
|
|
1342
1342
|
};
|
|
1343
1343
|
|
|
1344
1344
|
// inline-worker:D:\Projects\LuxAlgo-Vela\repos\Vela-pinets\src\pinets-worker\worker.ts
|
|
1345
|
-
var worker_default = '"use strict";(()=>{var Ul=Object.defineProperty;var ql=(t,e,r)=>e in t?Ul(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var $s=(t,e,r)=>ql(t,typeof e!="symbol"?e+"":e,r);function zl(t){return e=>new q(e.array.map(r=>Math.abs(r)),e.type,t)}function Kl(t){return e=>{let r=0,n=0;for(let i of e.array){let s=Number(i);isNaN(s)||(n++,r+=(s-r)/n)}return n===0?NaN:t.precision(r)}}function Hl(t){return(e,r)=>{let n=e.array,i=0,s=n.length-1;for(;i<=s;){let a=Math.floor((i+s)/2),o=n[a];if(o===r)return a;o<r?i=a+1:s=a-1}return-1}}function Gl(t){return(e,r)=>{let n=e.array,i=0,s=n.length;for(;i<s;){let a=Math.floor((i+s)/2);n[a]<r?i=a+1:s=a}return i<n.length&&n[i]===r?i:i-1}}function Yl(t){return(e,r)=>{let n=e.array,i=0,s=n.length;for(;i<s;){let a=Math.floor((i+s)/2);n[a]<=r?i=a+1:s=a}return i>0&&n[i-1]===r?i-1:i}}function Zl(t){return e=>{e.array.length=0}}function Xl(t){return(e,r)=>(e.array.push(...r.array),e)}function Ql(t){return e=>new q([...e.array],e.type,t)}function Jl(t){return(e,r,n=!0)=>{let i=e.array,s=r.array;if(i.length!==s.length)return NaN;let a=0,o=0,l=0,c=[];for(let f=0;f<i.length;f++){let m=Number(i[f]),x=Number(s[f]);!isNaN(m)&&m!==null&&m!==void 0&&!isNaN(x)&&x!==null&&x!==void 0&&(a+=m,o+=x,l++,c.push(f))}if(l===0)return NaN;let u=a/l,h=o/l,p=0;for(let f of c){let m=Number(i[f]),x=Number(s[f]);p+=(m-u)*(x-h)}let d=n?l:l-1;return d<=0?NaN:t.precision(p/d)}}function ec(t){return e=>e.array.every(r=>!isNaN(r)&&r)}function tc(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?z.int:z.float:t.every(e=>typeof e=="string")?z.string:t.every(e=>typeof e=="boolean")?z.bool:z.any}function it(t){return typeof t=="number"?Number.isInteger(t)?z.int:z.float:typeof t=="string"?z.string:typeof t=="boolean"?z.bool:z.any}function $r(t,e){if(typeof t=="number"&&isNaN(t)||e===z.any)return!0;switch(e){case z.int:return Number.isInteger(t)||isNaN(t);case z.float:return typeof t=="number";case z.string:return typeof t=="string";case z.bool:return typeof t=="boolean";case z.box:case z.label:case z.line:case z.linefill:case z.table:case z.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function rc(t){return(e,r,n=0,i)=>{let s=e.array.length,a=i!==void 0?Math.min(i,s):s;for(let o=n;o<a;o++){if(!$r(r,e.type))throw new Error(`Cannot call \'array.fill\' with argument \'value\'=\'${r}\'. An argument of \'literal ${typeof r}\' type was used but a \'${e.type}\' is expected.`);e.array[o]=typeof r=="number"?t.precision(r):r}}}function nc(t){return e=>e.array.length>0?e.array[0]:t.NA}function ic(t){return(e,r)=>(r<0&&(r=e.array.length+r),r<0||r>=e.array.length?(t.warn(`Index ${r} is out of bounds, array size is ${e.array.length}.`,"array.get"),NaN):e.array[r])}function sc(t){return(e,r)=>e.array.includes(r)}function ac(t){return(e,r)=>typeof r=="number"&&r!==r?e.array.findIndex(n=>typeof n=="number"&&n!==n):e.array.indexOf(r)}function oc(t){return(e,r,n)=>{if(!$r(n,e.type))throw new Error(`Cannot call \'array.insert\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);if(r<0&&(r=e.array.length+r),r<0||r>e.array.length){t.warn(`Index ${r} is out of bounds, array size is ${e.array.length}.`,"array.insert");return}e.array.splice(r,0,n)}}function lc(t){return(e,r=",")=>e.array.join(r)}function cc(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function uc(t){return(e,r)=>e.array.lastIndexOf(r)}function pc(t){return(e,r=0)=>{let n=e.array;if(n.length===0)return t.NA;if(r===0){let i=n[0];for(let s=1;s<n.length;s++)n[s]>i&&(i=n[s]);return i??t.NA}return[...n].sort((i,s)=>s-i)[r]??t.NA}}function hc(t){return e=>{let r=e.array;if(r.length===0)return NaN;let n=new Array(r.length);for(let s=0;s<r.length;s++)n[s]=r[s];n.sort((s,a)=>s-a);let i=Math.floor(n.length/2);return n.length%2!==0?n[i]:(n[i-1]+n[i])/2}}function dc(t){return(e,r=0)=>{let n=e.array;if(n.length===0)return t.NA;if(r===0){let i=n[0];for(let s=1;s<n.length;s++)n[s]<i&&(i=n[s]);return i??t.NA}return[...n].sort((i,s)=>i-s)[r]??t.NA}}function fc(t){return e=>{if(e.array.length===0)return NaN;let r=new Map,n=0;for(let s of e.array){let a=(r.get(s)||0)+1;r.set(s,a),a>n&&(n=a)}let i=[];for(let[s,a]of r)a===n&&i.push(s);return i.sort((s,a)=>typeof s=="number"&&typeof a=="number"?s-a:typeof s=="string"&&typeof a=="string"?s<a?-1:s>a?1:0:0),i[0]}}function mc(t){return(e,r)=>{let n=e.array,i=n.length;if(i===0)return NaN;let s=new Array(i);for(let c=0;c<i;c++){let u=Number(n[c]);if(isNaN(u)||u===null||u===void 0)return NaN;s[c]=u}s.sort((c,u)=>c-u),r<0&&(r=0),r>100&&(r=100);let a=r/100*i-.5;if(a<=0)return t.precision(s[0]);if(a>=i-1)return t.precision(s[i-1]);let o=Math.floor(a),l=a-o;return t.precision(s[o]*(1-l)+s[o+1]*l)}}function yc(t){return(e,r)=>{let n=e.array,i=n.length;if(i===0)return NaN;let s=new Array;for(let o=0;o<i;o++){let l=Number(n[o]);!isNaN(l)&&l!==null&&l!==void 0&&s.push(l)}if(s.length===0)return NaN;s.sort((o,l)=>o-l),r<0&&(r=0),r>100&&(r=100);let a=Math.ceil(r/100*i);return a<=0?s[0]:a>s.length?NaN:s[a-1]}}function gc(t){return(e,r)=>{if(e.array.length===0)return NaN;let n=Math.floor(r);if(n<0||n>=e.array.length)return NaN;let i=Number(e.array[n]);if(isNaN(i)||i===null||i===void 0)return NaN;let s=0;for(let o of e.array){let l=Number(o);!isNaN(l)&&l!==null&&l!==void 0&&l<i&&s++}let a=e.array.length-1;return a<=0?NaN:s/a*100}}function _c(t){return e=>e.array.pop()}function xc(t){return(e,r)=>{if(!$r(r,e.type))throw new Error(`Cannot call \'array.push\' with argument \'value\'=\'${r}\'. An argument of \'literal ${typeof r}\' type was used but a \'${e.type}\' is expected.`);e.array.push(typeof r=="number"?t.precision(r):r)}}function bc(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function vc(t){return(e,r)=>(r<0&&(r=e.array.length+r),r<0||r>=e.array.length?(t.warn(`Index ${r} is out of bounds, array size is ${e.array.length}.`,"array.remove"),NaN):e.array.splice(r,1)[0])}function wc(t){return e=>{e.array.reverse()}}function Ec(t){return(e,r,n)=>{if(!$r(n,e.type))throw new Error(`Cannot call \'array.set\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);if(r<0&&(r=e.array.length+r),r<0||r>=e.array.length){t.warn(`Index ${r} is out of bounds, array size is ${e.array.length}.`,"array.set");return}e.array[r]=typeof n=="number"?t.precision(n):n}}function Sc(t){return e=>e.array.shift()}function Cc(t){return e=>e.array.length}function Nc(t){return(e,r,n)=>{let i=n!==void 0?n:void 0;return new q(e.array.slice(r,i),e.type,t)}}function kc(t){return e=>e.array.some(r=>!isNaN(r)&&r)}var mr=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(mr||{}),Sa=(t=>(t.AED="AED",t.ARS="ARS",t.AUD="AUD",t.BDT="BDT",t.BHD="BHD",t.BRL="BRL",t.BTC="BTC",t.CAD="CAD",t.CHF="CHF",t.CLP="CLP",t.CNY="CNY",t.COP="COP",t.CZK="CZK",t.DKK="DKK",t.EGP="EGP",t.ETH="ETH",t.EUR="EUR",t.GBP="GBP",t.HKD="HKD",t.HUF="HUF",t.IDR="IDR",t.ILS="ILS",t.INR="INR",t.ISK="ISK",t.JPY="JPY",t.KES="KES",t.KRW="KRW",t.KWD="KWD",t.LKR="LKR",t.MAD="MAD",t.MXN="MXN",t.MYR="MYR",t.NGN="NGN",t.NOK="NOK",t.NONE="NONE",t.NZD="NZD",t.PEN="PEN",t.PHP="PHP",t.PKR="PKR",t.PLN="PLN",t.QAR="QAR",t.RON="RON",t.RSD="RSD",t.RUB="RUB",t.SAR="SAR",t.SEK="SEK",t.SGD="SGD",t.THB="THB",t.TND="TND",t.TRY="TRY",t.TWD="TWD",t.USD="USD",t.USDT="USDT",t.VES="VES",t.VND="VND",t.ZAR="ZAR",t))(Sa||{}),Ca=(t=>(t[t.sunday=1]="sunday",t[t.monday=2]="monday",t[t.tuesday=3]="tuesday",t[t.wednesday=4]="wednesday",t[t.thursday=5]="thursday",t[t.friday=6]="friday",t[t.saturday=7]="saturday",t))(Ca||{}),Na=(t=>(t.all="all",t.data_window="data_window",t.none="none",t.pane="pane",t.price_scale="price_scale",t.status_line="status_line",t))(Na||{}),ka=(t=>(t.flag="shape_flag",t.arrowdown="shape_arrow_down",t.arrowup="shape_arrow_up",t.circle="shape_circle",t.cross="shape_cross",t.diamond="shape_diamond",t.labeldown="shape_label_down",t.labelup="shape_label_up",t.square="shape_square",t.triangledown="shape_triangle_down",t.triangleup="shape_triangle_up",t.xcross="shape_xcross",t))(ka||{}),Ia=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(Ia||{}),Aa=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(Aa||{}),Ta=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(Ta||{}),Ic=(t=>(t.linestyle_dashed="linestyle_dashed",t.linestyle_dotted="linestyle_dotted",t.linestyle_solid="linestyle_solid",t.style_area="style_area",t.style_areabr="style_areabr",t.style_circles="style_circles",t.style_columns="style_columns",t.style_cross="style_cross",t.style_histogram="style_histogram",t.style_line="style_line",t.style_linebr="style_linebr",t.style_stepline="style_stepline",t.style_stepline_diamond="style_stepline_diamond",t.style_steplinebr="style_steplinebr",t))(Ic||{}),Da=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(Da||{}),Ma=(t=>(t.bar_index="bi",t.bar_time="bt",t))(Ma||{}),Pa=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(Pa||{}),Ra=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(Ra||{}),Fa=(t=>(t.align_bottom="bottom",t.align_top="top",t.align_left="left",t.align_center="center",t.align_right="right",t.wrap_auto="auto",t.wrap_none="none",t.format_bold="bold",t.format_italic="italic",t.format_none="none",t))(Fa||{}),Ba=(t=>(t.family_default="default",t.family_monospace="monospace",t))(Ba||{}),La=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(La||{}),Oa=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(Oa||{}),Va=(t=>(t.actual="earnings_actual",t.estimate="earnings_estimate",t.standardized="earnings_standardized",t.future_eps="earnings_future_eps",t.future_period_end_time="earnings_future_period_end_time",t.future_revenue="earnings_future_revenue",t.future_time="earnings_future_time",t))(Va||{}),ja=(t=>(t.gross="dividends_gross",t.net="dividends_net",t.future_amount="dividends_future_amount",t.future_ex_date="dividends_future_ex_date",t.future_pay_date="dividends_future_pay_date",t))(ja||{}),$a=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))($a||{}),Wa=(t=>(t.top_left="top_left",t.top_center="top_center",t.top_right="top_right",t.middle_left="middle_left",t.middle_center="middle_center",t.middle_right="middle_right",t.bottom_left="bottom_left",t.bottom_center="bottom_center",t.bottom_right="bottom_right",t))(Wa||{}),Ua=(t=>(t.left="left",t.none="none",t.right="right",t))(Ua||{}),qa=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(qa||{}),Ac={order:mr,currency:Sa,dayofweek:Ca,display:Na,shape:ka,location:Ia,size:Aa,format:Ta,barmerge:Da,xloc:Ma,yloc:Pa,extend:Ra,text:Fa,font:Ba,adjustment:La,backadjustment:Oa,earnings:Va,dividends:ja,splits:$a,position:Wa,scale:Ua,settlement_as_close:qa};function Tc(t){return(e,r=mr.ascending)=>{e.array.sort((n,i)=>{let s=isNaN(n)?1/0:n,a=isNaN(i)?1/0:i;return r===mr.ascending?s-a:a-s})}}function Dc(t){return(e,r=mr.ascending)=>{let n=e.array.map((i,s)=>s);return n.sort((i,s)=>{let a=isNaN(e.array[i])?1/0:e.array[i],o=isNaN(e.array[s])?1/0:e.array[s];return r===mr.ascending?a-o:o-a}),new q(n,z.int,t)}}function Mc(t){return e=>{let r=t.array.avg(e),n=t.array.stdev(e);return isNaN(n)?new q(e.array.map(()=>NaN),z.int,t):n===0?new q(e.array.map(()=>1),z.int,t):new q(e.array.map(i=>(i-r)/n),z.int,t)}}function Pc(t){return(e,r=!0)=>{let n=e.array,i=n.length;if(i===0)return NaN;let s=0,a=0,o=0;for(let u=0;u<i;u++){let h=Number(n[u]);!isNaN(h)&&h!==null&&h!==void 0&&(s+=h,a+=h*h,o++)}if(o===0)return NaN;let l=s/o,c=a/o-l*l;return c<0?NaN:(!r&&o>1&&(c=c*o/(o-1)),!r&&o===1?0:t.precision(Math.sqrt(c)))}}function Rc(t){return e=>t.precision(e.array.reduce((r,n)=>{let i=Number(n);return isNaN(i)?r:r+i},0))}function Fc(t){return(e,r)=>{if(!$r(r,e.type))throw new Error(`Cannot call \'array.unshift\' with argument \'value\'=\'${r}\'. An argument of \'literal ${typeof r}\' type was used but a \'${e.type}\' is expected.`);e.array.unshift(typeof r=="number"?t.precision(r):r)}}function Bc(t){return(e,r=!0)=>{let n=0,i=0;for(let l of e.array){let c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(n+=c,i++)}if(i===0)return NaN;let s=n/i,a=0;for(let l of e.array){let c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(a+=(c-s)*(c-s))}let o=r?i:i-1;return o<=0?NaN:t.precision(a/o)}}var Lc=Object.defineProperty,Oc=(t,e,r)=>e in t?Lc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Y=(t,e,r)=>Oc(t,typeof e!="symbol"?e+"":e,r),z=(t=>(t.any="",t.box="box",t.bool="bool",t.color="color",t.float="float",t.int="int",t.label="label",t.line="line",t.linefill="linefill",t.string="string",t.table="table",t))(z||{}),q=class{constructor(e,r,n){this.array=e,this.type=r,this.context=n,Y(this,"_abs"),Y(this,"_avg"),Y(this,"_binary_search"),Y(this,"_binary_search_leftmost"),Y(this,"_binary_search_rightmost"),Y(this,"_clear"),Y(this,"_concat"),Y(this,"_copy"),Y(this,"_covariance"),Y(this,"_every"),Y(this,"_fill"),Y(this,"_first"),Y(this,"_get"),Y(this,"_includes"),Y(this,"_indexof"),Y(this,"_insert"),Y(this,"_join"),Y(this,"_last"),Y(this,"_lastindexof"),Y(this,"_max"),Y(this,"_median"),Y(this,"_min"),Y(this,"_mode"),Y(this,"_percentile_linear_interpolation"),Y(this,"_percentile_nearest_rank"),Y(this,"_percentrank"),Y(this,"_pop"),Y(this,"_push"),Y(this,"_range"),Y(this,"_remove"),Y(this,"_reverse"),Y(this,"_set"),Y(this,"_shift"),Y(this,"_size"),Y(this,"_slice"),Y(this,"_some"),Y(this,"_sort"),Y(this,"_sort_indices"),Y(this,"_standardize"),Y(this,"_stdev"),Y(this,"_sum"),Y(this,"_unshift"),Y(this,"_variance"),this._abs=zl(this.context),this._avg=Kl(this.context),this._binary_search=Hl(this.context),this._binary_search_leftmost=Gl(this.context),this._binary_search_rightmost=Yl(this.context),this._clear=Zl(this.context),this._concat=Xl(this.context),this._copy=Ql(this.context),this._covariance=Jl(this.context),this._every=ec(this.context),this._fill=rc(this.context),this._first=nc(this.context),this._get=ic(this.context),this._includes=sc(this.context),this._indexof=ac(this.context),this._insert=oc(this.context),this._join=lc(this.context),this._last=cc(this.context),this._lastindexof=uc(this.context),this._max=pc(this.context),this._median=hc(this.context),this._min=dc(this.context),this._mode=fc(this.context),this._percentile_linear_interpolation=mc(this.context),this._percentile_nearest_rank=yc(this.context),this._percentrank=gc(this.context),this._pop=_c(this.context),this._push=xc(this.context),this._range=bc(this.context),this._remove=vc(this.context),this._reverse=wc(this.context),this._set=Ec(this.context),this._shift=Sc(this.context),this._size=Cc(this.context),this._slice=Nc(this.context),this._some=kc(this.context),this._sort=Tc(this.context),this._sort_indices=Dc(this.context),this._standardize=Mc(this.context),this._stdev=Pc(this.context),this._sum=Rc(this.context),this._unshift=Fc(this.context),this._variance=Bc(this.context)}toString(){return"["+this.array.toString().replace(/,/g,", ")+"]"}[Symbol.iterator](){return this.array[Symbol.iterator]()}abs(...e){return this._abs(this,...e)}avg(...e){return this._avg(this,...e)}binary_search(...e){return this._binary_search(this,...e)}binary_search_leftmost(...e){return this._binary_search_leftmost(this,...e)}binary_search_rightmost(...e){return this._binary_search_rightmost(this,...e)}clear(...e){return this._clear(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}covariance(...e){return this._covariance(this,...e)}every(...e){return this._every(this,...e)}fill(...e){return this._fill(this,...e)}first(...e){return this._first(this,...e)}get(...e){return this._get(this,...e)}includes(...e){return this._includes(this,...e)}indexof(...e){return this._indexof(this,...e)}insert(...e){return this._insert(this,...e)}join(...e){return this._join(this,...e)}last(...e){return this._last(this,...e)}lastindexof(...e){return this._lastindexof(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}percentile_linear_interpolation(...e){return this._percentile_linear_interpolation(this,...e)}percentile_nearest_rank(...e){return this._percentile_nearest_rank(this,...e)}percentrank(...e){return this._percentrank(this,...e)}pop(...e){return this._pop(this,...e)}push(...e){return this._push(this,...e)}range(...e){return this._range(this,...e)}remove(...e){return this._remove(this,...e)}reverse(...e){return this._reverse(this,...e)}set(...e){return this._set(this,...e)}shift(...e){return this._shift(this,...e)}size(...e){return this._size(this,...e)}slice(...e){return this._slice(this,...e)}some(...e){return this._some(this,...e)}sort(...e){return this._sort(this,...e)}sort_indices(...e){return this._sort_indices(this,...e)}standardize(...e){return this._standardize(this,...e)}stdev(...e){return this._stdev(this,...e)}sum(...e){return this._sum(this,...e)}unshift(...e){return this._unshift(this,...e)}variance(...e){return this._variance(this,...e)}};function Vc(t){return(...e)=>new q([...e],tc(e),t)}function jc(t){return(e,r)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;if(r===void 0){let i=n?Array(n).fill(0):[];return new q(i,z.any,t)}return new q(Array(n).fill(t.precision(r||0)),it(r||0),t)}}function $c(t){return(e=0,r=!1)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.bool,t)}}function Wc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.box,t)}}function Uc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.color,t)}}function qc(t){return(e=0,r=NaN)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(t.precision(r)),z.float,t)}}function zc(t){return(e=0,r=0)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(t.precision(r)),z.int,t)}}function Kc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.label,t)}}function Hc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.line,t)}}function Gc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.linefill,t)}}function Yc(t){return(e=0,r="")=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.string,t)}}function Zc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.table,t)}}var y=class t{constructor(e,r=0){this.data=e,this.offset=r}get(e){let r=this.offset+e;Number.isInteger(r)||(r=Math.trunc(r));let n=this.data.length-1-r;return n<0||n>=this.data.length?NaN:this.data[n]}set(e,r){let n=this.data.length-1-(this.offset+e);n>=0&&n<this.data.length&&(this.data[n]=r)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof t?e:Array.isArray(e)?new t(e):e!=null&&typeof e=="object"&&"__value"in e&&e.__value instanceof t?e.__value:new t([e])}};function Xc(t){return(e,r=0)=>y.from(e).get(r)}var pi=class{constructor(e){this.context=e,this.abs=(r,...n)=>r.abs(...n),this.avg=(r,...n)=>r.avg(...n),this.binary_search=(r,...n)=>r.binary_search(...n),this.binary_search_leftmost=(r,...n)=>r.binary_search_leftmost(...n),this.binary_search_rightmost=(r,...n)=>r.binary_search_rightmost(...n),this.clear=(r,...n)=>r.clear(...n),this.concat=(r,...n)=>r.concat(...n),this.copy=(r,...n)=>r.copy(...n),this.covariance=(r,...n)=>r.covariance(...n),this.every=(r,...n)=>r.every(...n),this.fill=(r,...n)=>r.fill(...n),this.first=(r,...n)=>r.first(...n),this.from=Vc(e),this.get=(r,...n)=>r.get(...n),this.includes=(r,...n)=>r.includes(...n),this.indexof=(r,...n)=>r.indexof(...n),this.insert=(r,...n)=>r.insert(...n),this.join=(r,...n)=>r.join(...n),this.last=(r,...n)=>r.last(...n),this.lastindexof=(r,...n)=>r.lastindexof(...n),this.max=(r,...n)=>r.max(...n),this.median=(r,...n)=>r.median(...n),this.min=(r,...n)=>r.min(...n),this.mode=(r,...n)=>r.mode(...n),this.new=jc(e),this.new_bool=$c(e),this.new_box=Wc(e),this.new_color=Uc(e),this.new_float=qc(e),this.new_int=zc(e),this.new_label=Kc(e),this.new_line=Hc(e),this.new_linefill=Gc(e),this.new_string=Yc(e),this.new_table=Zc(e),this.param=Xc(),this.percentile_linear_interpolation=(r,...n)=>r.percentile_linear_interpolation(...n),this.percentile_nearest_rank=(r,...n)=>r.percentile_nearest_rank(...n),this.percentrank=(r,...n)=>r.percentrank(...n),this.pop=(r,...n)=>r.pop(...n),this.push=(r,...n)=>r.push(...n),this.range=(r,...n)=>r.range(...n),this.remove=(r,...n)=>r.remove(...n),this.reverse=(r,...n)=>r.reverse(...n),this.set=(r,...n)=>r.set(...n),this.shift=(r,...n)=>r.shift(...n),this.size=(r,...n)=>r.size(...n),this.slice=(r,...n)=>r.slice(...n),this.some=(r,...n)=>r.some(...n),this.sort=(r,...n)=>r.sort(...n),this.sort_indices=(r,...n)=>r.sort_indices(...n),this.standardize=(r,...n)=>r.standardize(...n),this.stdev=(r,...n)=>r.stdev(...n),this.sum=(r,...n)=>r.sum(...n),this.unshift=(r,...n)=>r.unshift(...n),this.variance=(r,...n)=>r.variance(...n)}};function Qc(t){return e=>{e.map.clear()}}function Jc(t){return(e,r)=>e.map.has(r)}function eu(t){return e=>{let r=new cn(t);return r.map=new Map(e.map),r}}function tu(t){return(e,r)=>{let n=e.map.get(r);return n===void 0?NaN:n}}function ru(t){return e=>{let r=Array.from(e.map.keys()),n=it(r[0]);return new q(r,n,t)}}function nu(t){return(e,r,n)=>{let i=e.map.get(r);return e.map.set(r,n),i===void 0?NaN:i}}function iu(t){return(e,r)=>{for(let[n,i]of r.map)e.map.set(n,i)}}function su(t){return(e,r)=>{let n=e.map.get(r);return e.map.delete(r)?n:NaN}}function au(t){return e=>e.map.size}function ou(t){return e=>{let r=Array.from(e.map.values()),n=it(r[0]);return new q(r,n,t)}}var lu=Object.defineProperty,cu=(t,e,r)=>e in t?lu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ot=(t,e,r)=>cu(t,typeof e!="symbol"?e+"":e,r),cn=class{constructor(e){this.context=e,ot(this,"map"),ot(this,"_clear"),ot(this,"_contains"),ot(this,"_copy"),ot(this,"_get"),ot(this,"_keys"),ot(this,"_put"),ot(this,"_put_all"),ot(this,"_remove"),ot(this,"_size"),ot(this,"_values"),this.map=new Map,this._clear=Qc(this.context),this._contains=Jc(this.context),this._copy=eu(this.context),this._get=tu(this.context),this._keys=ru(this.context),this._put=nu(this.context),this._put_all=iu(this.context),this._remove=su(this.context),this._size=au(this.context),this._values=ou(this.context)}toString(){return`PineMapObject(${this.map.size})`}clear(...e){return this._clear(this,...e)}contains(...e){return this._contains(this,...e)}copy(...e){return this._copy(this,...e)}get(...e){return this._get(this,...e)}keys(...e){return this._keys(this,...e)}put(...e){return this._put(this,...e)}put_all(...e){return this._put_all(this,...e)}remove(...e){return this._remove(this,...e)}size(...e){return this._size(this,...e)}values(...e){return this._values(this,...e)}};function uu(t){return()=>new cn(t)}function pu(t){return(e,r=0)=>y.from(e).get(r)}var hi=class{constructor(e){this.context=e,this.clear=(r,...n)=>r.clear(...n),this.contains=(r,...n)=>r.contains(...n),this.copy=(r,...n)=>r.copy(...n),this.get=(r,...n)=>r.get(...n),this.keys=(r,...n)=>r.keys(...n),this.new=uu(e),this.param=pu(),this.put=(r,...n)=>r.put(...n),this.put_all=(r,...n)=>r.put_all(...n),this.remove=(r,...n)=>r.remove(...n),this.size=(r,...n)=>r.size(...n),this.values=(r,...n)=>r.values(...n)}};function hu(t){return(e,r,n)=>{let i=e.matrix.length,s=[];if(n&&(n instanceof q?s=n.array:Array.isArray(n)?s=n:s=[n]),i===0){for(let l=0;l<s.length;l++){let c=s[l];c instanceof y&&(c=c.get(0)),e.matrix.push([c])}return}let a=e.matrix[0].length,o=r!==void 0?r:a;for(let l=0;l<i;l++){let c=l<s.length?s[l]:NaN;c instanceof y&&(c=c.get(0)),e.matrix[l].splice(o,0,c)}}}function du(t){return(e,r,n)=>{let i=e.matrix.length,s=[];if(n)if(n instanceof q)s=n.array;else if(Array.isArray(n))s=n;else if(n instanceof y){let c=n.get(0);Array.isArray(c)?s=c:s=[c]}else s=[n];let a=i>0?e.matrix[0].length:s.length,o=r!==void 0?r:i,l=[];for(let c=0;c<a;c++)if(c<s.length){let u=s[c];u instanceof y&&(u=u.get(0)),l.push(u)}else l.push(NaN);e.matrix.splice(o,0,l)}}function fu(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length;if(n===0)return NaN;let i=0,s=0;for(let a=0;a<r;a++)for(let o=0;o<n;o++){let l=e.matrix[a][o];isNaN(l)||(i+=l,s++)}return s===0?NaN:i/s}}function mu(t){return(e,r)=>{let n=e.matrix.length,i=n>0?e.matrix[0].length:0;if(r<0||r>=i){t.warn(`Column index ${r} is out of bounds, matrix has ${i} columns.`,"matrix.col");let o=n>0?it(e.matrix[0][0]):"float";return new q([],o,t)}let s=[];for(let o=0;o<n;o++)s.push(e.matrix[o][r]);let a=it(s[0]);return new q(s,a,t)}}function yu(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function gu(t){return(e,r)=>{let n=e.matrix.length,i=r.matrix.length;if(n===0){for(let o=0;o<i;o++)e.matrix.push([...r.matrix[o]]);return}let s=e.matrix[0].length,a=i>0?r.matrix[0].length:0;if(s!==a&&i>0){console.error(`matrix.concat: Column count mismatch ${s} vs ${a}`);return}for(let o=0;o<i;o++)e.matrix.push([...r.matrix[o]])}}function _u(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0,i=new te(r,n,NaN,t);return i.matrix=e.matrix.map(s=>[...s]),i}}function xu(t){let e=t.length;if(e===0)return 0;if(e===1)return t[0][0];if(e===2)return t[0][0]*t[1][1]-t[0][1]*t[1][0];let r=t.map(i=>[...i]),n=1;for(let i=0;i<e;i++){let s=i;for(;s<e&&r[s][i]===0;)s++;if(s===e)return 0;s!==i&&([r[i],r[s]]=[r[s],r[i]],n*=-1),n*=r[i][i];for(let a=i+1;a<e;a++){let o=r[a][i]/r[i][i];for(let l=i;l<e;l++)r[a][l]-=o*r[i][l]}}return n}function bu(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0;return r!==n?NaN:xu(e.matrix)}}function vu(t){return(e,r)=>{let n=e.matrix.length;if(n===0)return new te(0,0,NaN,t);let i=e.matrix[0].length,s=new te(n,i,NaN,t);if(r instanceof te)for(let a=0;a<n;a++)for(let o=0;o<i;o++){let l=e.matrix[a][o],c=r.matrix[a]&&r.matrix[a][o]!==void 0?r.matrix[a][o]:NaN;s.matrix[a][o]=l-c}else{let a=r;for(let o=0;o<n;o++)for(let l=0;l<i;l++)s.matrix[o][l]=e.matrix[o][l]-a}return s}}function wu(t){let e=t.length;if(e!==2)return Array(e).fill(NaN);let r=t[0][0],n=t[0][1],i=t[1][0],s=t[1][1],a=r+s,o=r*s-n*i,l=a*a-4*o;if(l<0)return[NaN,NaN];let c=(a+Math.sqrt(l))/2,u=(a-Math.sqrt(l))/2;return[c,u]}function Eu(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n){let a=it(e.matrix[0][0]);return new q([],a,t)}let i=wu(e.matrix),s=it(i[0]);return new q(i,s,t)}}function Su(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n)return new te(0,0,NaN,t);let i=new te(r,n,0,t);for(let s=0;s<r;s++)i.matrix[s][s]=1;return i}}function Cu(t){return e=>{let r=e.matrix.length;return r===0?0:r*e.matrix[0].length}}function Nu(t){return(e,r,n,i,s,a)=>{let o=e.matrix.length;if(o===0)return;let l=e.matrix[0].length,c=n!==void 0?n:0,u=i!==void 0?i:o,h=s!==void 0?s:0,p=a!==void 0?a:l;for(let d=c;d<u&&!(d>=o);d++)for(let f=h;f<p&&!(f>=l);f++)e.matrix[d][f]=r}}function ku(t){return(e,r,n)=>{let i=e.matrix.length,s=i>0?e.matrix[0].length:0;if(r<0||r>=i)return t.warn(`Row index ${r} is out of bounds, matrix has ${i} rows.`,"matrix.get"),NaN;if(n<0||n>=s)return t.warn(`Column index ${n} is out of bounds, matrix has ${s} columns.`,"matrix.get"),NaN;let a=e.matrix[r][n];return a===void 0?NaN:a}}function rn(t){let e=t.length;if(e===0)return[];let r=new Array(e);for(let i=0;i<e;i++){r[i]=new Array(2*e);for(let s=0;s<e;s++)r[i][s]=t[i][s];for(let s=0;s<e;s++)r[i][e+s]=i===s?1:0}for(let i=0;i<e;i++){let s=Math.abs(r[i][i]),a=i;for(let l=i+1;l<e;l++){let c=Math.abs(r[l][i]);c>s&&(s=c,a=l)}if(s<1e-14)return t.map(l=>l.map(()=>NaN));if(a!==i){let l=r[i];r[i]=r[a],r[a]=l}let o=r[i][i];for(let l=i;l<2*e;l++)r[i][l]/=o;for(let l=0;l<e;l++){if(l===i)continue;let c=r[l][i];if(c!==0)for(let u=i;u<2*e;u++)r[l][u]-=c*r[i][u]}}let n=new Array(e);for(let i=0;i<e;i++){n[i]=new Array(e);for(let s=0;s<e;s++)n[i][s]=r[i][e+s]}return n}function Iu(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n)return new te(r,n,NaN,t);let i=rn(e.matrix),s=new te(r,n,NaN,t);return s.matrix=i,s}}function Au(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(i+s!==r-1&&e.matrix[i][s]!==0)return!1;return!0}}function Tu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(e.matrix[s][i]!==-e.matrix[i][s])return!1;return!0}}function Du(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;for(let i=0;i<r;i++)for(let s=0;s<n;s++){let a=e.matrix[i][s];if(a!==0&&a!==1)return!1}return!0}}function Mu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(i!==s&&e.matrix[i][s]!==0)return!1;return!0}}function Pu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(i===s){if(e.matrix[i][s]!==1)return!1}else if(e.matrix[i][s]!==0)return!1;return!0}}function Ru(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;return r===n}}function Fu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;for(let i=0;i<r;i++){let s=0;for(let a=0;a<n;a++){let o=e.matrix[i][a];if(o<0)return!1;s+=o}if(Math.abs(s-1)>1e-10)return!1}return!0}}function Bu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<i;s++)if(e.matrix[i][s]!==e.matrix[s][i])return!1;return!0}}function Lu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;let i=!0,s=!0;for(let a=0;a<r;a++)for(let o=0;o<n;o++)a>o&&e.matrix[a][o]!==0&&(i=!1),a<o&&e.matrix[a][o]!==0&&(s=!1);return i||s}}function Ou(t){return e=>{let r=e.matrix.length;if(r===0)return!0;let n=e.matrix[0].length;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(e.matrix[i][s]!==0)return!1;return!0}}function Vu(t){return(e,r)=>{let n=e.matrix.length,i=n>0?e.matrix[0].length:0,s=r.matrix.length,a=s>0?r.matrix[0].length:0,o=n*s,l=i*a,c=new te(o,l,NaN,t);for(let u=0;u<n;u++)for(let h=0;h<i;h++){let p=e.matrix[u][h];for(let d=0;d<s;d++)for(let f=0;f<a;f++){let m=r.matrix[d][f];c.matrix[u*s+d][h*a+f]=p*m}}return c}}function ju(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length,i=-1/0,s=!1;for(let a=0;a<r;a++)for(let o=0;o<n;o++){let l=e.matrix[a][o];isNaN(l)||(l>i&&(i=l),s=!0)}return s?i:NaN}}function $u(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length,i=[];for(let a=0;a<r;a++)for(let o=0;o<n;o++){let l=e.matrix[a][o];isNaN(l)||i.push(l)}if(i.length===0)return NaN;i.sort((a,o)=>a-o);let s=Math.floor(i.length/2);return i.length%2!==0?i[s]:(i[s-1]+i[s])/2}}function Wu(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length,i=1/0,s=!1;for(let a=0;a<r;a++)for(let o=0;o<n;o++){let l=e.matrix[a][o];isNaN(l)||(l<i&&(i=l),s=!0)}return s?i:NaN}}function Uu(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length,i=new Map,s=0,a=NaN;for(let o=0;o<r;o++)for(let l=0;l<n;l++){let c=e.matrix[o][l];if(!isNaN(c)){let u=(i.get(c)||0)+1;i.set(c,u),u>s?(s=u,a=c):u===s&&c<a&&(a=c)}}return a}}function qu(t){return(e,r)=>{let n=e.matrix.length,i=n>0?e.matrix[0].length:0;if(r instanceof te){let s=r.matrix.length,a=s>0?r.matrix[0].length:0;if(i!==s)return new te(0,0,NaN,t);let o=new te(n,a,0,t);for(let l=0;l<n;l++)for(let c=0;c<a;c++){let u=0;for(let h=0;h<i;h++)u+=e.matrix[l][h]*r.matrix[h][c];o.matrix[l][c]=u}return o}else if(r instanceof q||Array.isArray(r.array||r)){let s=r.array||r;if(i!==s.length)return new q([],"float",t);let a=[];for(let o=0;o<n;o++){let l=0;for(let c=0;c<i;c++)l+=e.matrix[o][c]*s[c];a.push(l)}return new q(a,"float",t)}else{let s=r,a=new te(n,i,NaN,t);for(let o=0;o<n;o++)for(let l=0;l<i;l++)a.matrix[o][l]=e.matrix[o][l]*s;return a}}}function zu(t){return e=>{let r=e.matrix.length;if(r===0)return new te(0,0,NaN,t);let n=e.matrix[0].length;if(r===n){let u=rn(e.matrix),h=new te(r,n,NaN,t);return h.matrix=u,h}let i=u=>{let h=u.length,p=u[0].length,d=new Array(p);for(let f=0;f<p;f++){d[f]=new Array(h);for(let m=0;m<h;m++)d[f][m]=u[m][f]}return d},s=(u,h)=>{let p=u.length,d=u[0].length,f=h[0].length,m=new Array(p);for(let x=0;x<p;x++){m[x]=new Array(f).fill(0);for(let b=0;b<d;b++){let w=u[x][b];if(w!==0)for(let v=0;v<f;v++)m[x][v]+=w*h[b][v]}}return m},a=e.matrix,o=i(a),l;if(r>n){let u=s(o,a),h=rn(u);l=s(h,o)}else{let u=s(a,o),h=rn(u);l=s(o,h)}let c=new te(n,r,NaN,t);return c.matrix=l,c}}function Ku(t){return(e,r)=>{let n=e.matrix.length,i=n>0?e.matrix[0].length:0;if(n!==i)return new te(0,0,NaN,t);let s=new te(n,i,0,t);for(let l=0;l<n;l++)s.matrix[l][l]=1;let a=new te(n,i,NaN,t);for(let l=0;l<n;l++)a.matrix[l]=[...e.matrix[l]];let o=Math.floor(r);if(o<0)return new te(n,i,NaN,t);for(;o>0;){if(o%2===1){let c=new te(n,i,0,t);for(let u=0;u<n;u++)for(let h=0;h<i;h++){let p=0;for(let d=0;d<n;d++)p+=s.matrix[u][d]*a.matrix[d][h];c.matrix[u][h]=p}s=c}let l=new te(n,i,0,t);for(let c=0;c<n;c++)for(let u=0;u<i;u++){let h=0;for(let p=0;p<n;p++)h+=a.matrix[c][p]*a.matrix[p][u];l.matrix[c][u]=h}a=l,o=Math.floor(o/2)}return s}}function Hu(t){return e=>{let r=e.matrix.length;if(r===0)return 0;let n=e.matrix[0].length,i=e.matrix.map(a=>[...a]),s=0;for(let a=0;a<n&&s<r;a++){let o=s;for(;o<r&&Math.abs(i[o][a])<1e-10;)o++;if(o<r){[i[s],i[o]]=[i[o],i[s]];let l=i[s][a];for(let c=a;c<n;c++)i[s][c]/=l;for(let c=0;c<r;c++)if(c!==s){let u=i[c][a];for(let h=a;h<n;h++)i[c][h]-=u*i[s][h]}s++}}return s}}function Gu(t){return(e,r)=>{let n=e.matrix.length;if(n===0){let a=it(e.matrix[0][0]);return new q([],a,t)}let i=[];for(let a=0;a<n;a++){let o=e.matrix[a].splice(r,1);i.push(o[0])}let s=it(i[0]);return new q(i,s,t)}}function Yu(t){return(e,r)=>{let n=e.matrix.splice(r,1),i=it(n[0][0]);return new q(n[0]||[],i,t)}}function Zu(t){return(e,r,n)=>{let i=e.matrix.length,s=i>0?e.matrix[0].length:0,a=r*n,o=[];for(let u=0;u<i;u++)for(let h=0;h<s;h++)o.push(e.matrix[u][h]);for(;o.length<a;)o.push(NaN);o.length>a&&(o.length=a);let l=[],c=0;for(let u=0;u<r;u++){let h=[];for(let p=0;p<n;p++)h.push(o[c++]);l.push(h)}e.matrix=l}}function Xu(t){return e=>{e.matrix.reverse();for(let r of e.matrix)r.reverse()}}function Qu(t){return(e,r)=>{let n=e.matrix.length;if(r<0||r>=n){t.warn(`Row index ${r} is out of bounds, matrix has ${n} rows.`,"matrix.row");let s=n>0?it(e.matrix[0][0]):"float";return new q([],s,t)}let i=it(e.matrix[r][0]);return new q([...e.matrix[r]],i,t)}}function Ju(t){return e=>e.matrix.length}function ep(t){return(e,r,n,i)=>{let s=e.matrix.length,a=s>0?e.matrix[0].length:0;if(r<0||r>=s){t.warn(`Row index ${r} is out of bounds, matrix has ${s} rows.`,"matrix.set");return}if(n<0||n>=a){t.warn(`Column index ${n} is out of bounds, matrix has ${a} columns.`,"matrix.set");return}e.matrix[r][n]=i}}function tp(t){return(e,r=0,n="asc")=>{e.matrix.length!==0&&e.matrix.sort((i,s)=>{let a=i[r],o=s[r];return a<o?n==="asc"?-1:1:a>o?n==="asc"?1:-1:0})}}function rp(t){return(e,r,n,i,s)=>{let a=n-r,o=s-i,l=new te(a,o,NaN,t);for(let c=0;c<a;c++){let u=r+c;if(u>=e.matrix.length)break;for(let h=0;h<o;h++){let p=i+h;if(p>=e.matrix[u].length)break;l.matrix[c][h]=e.matrix[u][p]}}return l}}function np(t){return(e,r)=>{let n=e.matrix.length;if(n===0)return new te(0,0,NaN,t);let i=e.matrix[0].length,s=new te(n,i,NaN,t);if(r instanceof te)for(let a=0;a<n;a++)for(let o=0;o<i;o++){let l=e.matrix[a][o],c=r.matrix[a]&&r.matrix[a][o]!==void 0?r.matrix[a][o]:NaN;s.matrix[a][o]=l+c}else{let a=r;for(let o=0;o<n;o++)for(let l=0;l<i;l++)s.matrix[o][l]=e.matrix[o][l]+a}return s}}function ip(t){return(e,r,n)=>{let i=e.matrix.length;for(let s=0;s<i;s++){let a=e.matrix[s][r];e.matrix[s][r]=e.matrix[s][n],e.matrix[s][n]=a}}}function sp(t){return(e,r,n)=>{let i=e.matrix[r];e.matrix[r]=e.matrix[n],e.matrix[n]=i}}function ap(t){return e=>{let r=e.matrix.length;if(r===0)return 0;let n=e.matrix[0].length,i=Math.min(r,n),s=0;for(let a=0;a<i;a++)s+=e.matrix[a][a];return s}}function op(t){return e=>{let r=e.matrix.length;if(r===0)return new te(0,0,NaN,t);let n=e.matrix[0].length,i=new te(n,r,NaN,t);for(let s=0;s<r;s++)for(let a=0;a<n;a++)i.matrix[a][s]=e.matrix[s][a];return i}}var lp=Object.defineProperty,cp=(t,e,r)=>e in t?lp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,U=(t,e,r)=>cp(t,typeof e!="symbol"?e+"":e,r),te=class{constructor(e=0,r=0,n=NaN,i){if(this.context=i,U(this,"matrix"),U(this,"_add_col"),U(this,"_add_row"),U(this,"_avg"),U(this,"_col"),U(this,"_columns"),U(this,"_concat"),U(this,"_copy"),U(this,"_det"),U(this,"_diff"),U(this,"_eigenvalues"),U(this,"_eigenvectors"),U(this,"_elements_count"),U(this,"_fill"),U(this,"_get"),U(this,"_inv"),U(this,"_is_antidiagonal"),U(this,"_is_antisymmetric"),U(this,"_is_binary"),U(this,"_is_diagonal"),U(this,"_is_identity"),U(this,"_is_square"),U(this,"_is_stochastic"),U(this,"_is_symmetric"),U(this,"_is_triangular"),U(this,"_is_zero"),U(this,"_kron"),U(this,"_max"),U(this,"_median"),U(this,"_min"),U(this,"_mode"),U(this,"_mult"),U(this,"_pinv"),U(this,"_pow"),U(this,"_rank"),U(this,"_remove_col"),U(this,"_remove_row"),U(this,"_reshape"),U(this,"_reverse"),U(this,"_row"),U(this,"_rows"),U(this,"_set"),U(this,"_sort"),U(this,"_submatrix"),U(this,"_sum"),U(this,"_swap_columns"),U(this,"_swap_rows"),U(this,"_trace"),U(this,"_transpose"),this.matrix=[],e>0&&r>0)for(let s=0;s<e;s++)this.matrix.push(Array(r).fill(n));this._add_col=hu(this.context),this._add_row=du(this.context),this._avg=fu(this.context),this._col=mu(this.context),this._columns=yu(this.context),this._concat=gu(this.context),this._copy=_u(this.context),this._det=bu(this.context),this._diff=vu(this.context),this._eigenvalues=Eu(this.context),this._eigenvectors=Su(this.context),this._elements_count=Cu(this.context),this._fill=Nu(this.context),this._get=ku(this.context),this._inv=Iu(this.context),this._is_antidiagonal=Au(this.context),this._is_antisymmetric=Tu(this.context),this._is_binary=Du(this.context),this._is_diagonal=Mu(this.context),this._is_identity=Pu(this.context),this._is_square=Ru(this.context),this._is_stochastic=Fu(this.context),this._is_symmetric=Bu(this.context),this._is_triangular=Lu(this.context),this._is_zero=Ou(this.context),this._kron=Vu(this.context),this._max=ju(this.context),this._median=$u(this.context),this._min=Wu(this.context),this._mode=Uu(this.context),this._mult=qu(this.context),this._pinv=zu(this.context),this._pow=Ku(this.context),this._rank=Hu(this.context),this._remove_col=Gu(this.context),this._remove_row=Yu(this.context),this._reshape=Zu(this.context),this._reverse=Xu(this.context),this._row=Qu(this.context),this._rows=Ju(this.context),this._set=ep(this.context),this._sort=tp(this.context),this._submatrix=rp(this.context),this._sum=np(this.context),this._swap_columns=ip(this.context),this._swap_rows=sp(this.context),this._trace=ap(this.context),this._transpose=op(this.context)}toString(){let e="";for(let r=0;r<this.matrix.length;r++)e+=e===""?"":`\n`,e+="["+this.matrix[r].join(", ")+"]";return e}add_col(...e){return this._add_col(this,...e)}add_row(...e){return this._add_row(this,...e)}avg(...e){return this._avg(this,...e)}col(...e){return this._col(this,...e)}columns(...e){return this._columns(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}det(...e){return this._det(this,...e)}diff(...e){return this._diff(this,...e)}eigenvalues(...e){return this._eigenvalues(this,...e)}eigenvectors(...e){return this._eigenvectors(this,...e)}elements_count(...e){return this._elements_count(this,...e)}fill(...e){return this._fill(this,...e)}get(...e){return this._get(this,...e)}inv(...e){return this._inv(this,...e)}is_antidiagonal(...e){return this._is_antidiagonal(this,...e)}is_antisymmetric(...e){return this._is_antisymmetric(this,...e)}is_binary(...e){return this._is_binary(this,...e)}is_diagonal(...e){return this._is_diagonal(this,...e)}is_identity(...e){return this._is_identity(this,...e)}is_square(...e){return this._is_square(this,...e)}is_stochastic(...e){return this._is_stochastic(this,...e)}is_symmetric(...e){return this._is_symmetric(this,...e)}is_triangular(...e){return this._is_triangular(this,...e)}is_zero(...e){return this._is_zero(this,...e)}kron(...e){return this._kron(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}mult(...e){return this._mult(this,...e)}pinv(...e){return this._pinv(this,...e)}pow(...e){return this._pow(this,...e)}rank(...e){return this._rank(this,...e)}remove_col(...e){return this._remove_col(this,...e)}remove_row(...e){return this._remove_row(this,...e)}reshape(...e){return this._reshape(this,...e)}reverse(...e){return this._reverse(this,...e)}row(...e){return this._row(this,...e)}rows(...e){return this._rows(this,...e)}set(...e){return this._set(this,...e)}sort(...e){return this._sort(this,...e)}submatrix(...e){return this._submatrix(this,...e)}sum(...e){return this._sum(this,...e)}swap_columns(...e){return this._swap_columns(this,...e)}swap_rows(...e){return this._swap_rows(this,...e)}trace(...e){return this._trace(this,...e)}transpose(...e){return this._transpose(this,...e)}};function lt(t){return(e,r,n)=>new te(e,r,n,t)}function up(t){return(e,r=0)=>y.from(e).get(r)}var di=class{constructor(e){this.context=e,this.add_col=(r,...n)=>r.add_col(...n),this.add_row=(r,...n)=>r.add_row(...n),this.avg=(r,...n)=>r.avg(...n),this.col=(r,...n)=>r.col(...n),this.columns=(r,...n)=>r.columns(...n),this.concat=(r,...n)=>r.concat(...n),this.copy=(r,...n)=>r.copy(...n),this.det=(r,...n)=>r.det(...n),this.diff=(r,...n)=>r.diff(...n),this.eigenvalues=(r,...n)=>r.eigenvalues(...n),this.eigenvectors=(r,...n)=>r.eigenvectors(...n),this.elements_count=(r,...n)=>r.elements_count(...n),this.fill=(r,...n)=>r.fill(...n),this.get=(r,...n)=>r.get(...n),this.inv=(r,...n)=>r.inv(...n),this.is_antidiagonal=(r,...n)=>r.is_antidiagonal(...n),this.is_antisymmetric=(r,...n)=>r.is_antisymmetric(...n),this.is_binary=(r,...n)=>r.is_binary(...n),this.is_diagonal=(r,...n)=>r.is_diagonal(...n),this.is_identity=(r,...n)=>r.is_identity(...n),this.is_square=(r,...n)=>r.is_square(...n),this.is_stochastic=(r,...n)=>r.is_stochastic(...n),this.is_symmetric=(r,...n)=>r.is_symmetric(...n),this.is_triangular=(r,...n)=>r.is_triangular(...n),this.is_zero=(r,...n)=>r.is_zero(...n),this.kron=(r,...n)=>r.kron(...n),this.max=(r,...n)=>r.max(...n),this.median=(r,...n)=>r.median(...n),this.min=(r,...n)=>r.min(...n),this.mode=(r,...n)=>r.mode(...n),this.mult=(r,...n)=>r.mult(...n),this.new=lt(e),this.param=up(),this.pinv=(r,...n)=>r.pinv(...n),this.pow=(r,...n)=>r.pow(...n),this.rank=(r,...n)=>r.rank(...n),this.remove_col=(r,...n)=>r.remove_col(...n),this.remove_row=(r,...n)=>r.remove_row(...n),this.reshape=(r,...n)=>r.reshape(...n),this.reverse=(r,...n)=>r.reverse(...n),this.row=(r,...n)=>r.row(...n),this.rows=(r,...n)=>r.rows(...n),this.set=(r,...n)=>r.set(...n),this.sort=(r,...n)=>r.sort(...n),this.submatrix=(r,...n)=>r.submatrix(...n),this.sum=(r,...n)=>r.sum(...n),this.swap_columns=(r,...n)=>r.swap_columns(...n),this.swap_rows=(r,...n)=>r.swap_rows(...n),this.trace=(r,...n)=>r.trace(...n),this.transpose=(r,...n)=>r.transpose(...n),this.new_float=lt(e),this.new_int=lt(e),this.new_string=lt(e),this.new_bool=lt(e),this.new_color=lt(e),this.new_line=lt(e),this.new_label=lt(e),this.new_box=lt(e),this.new_linefill=lt(e),this.new_table=lt(e)}},pp=Object.defineProperty,hp=(t,e,r)=>e in t?pp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dp=(t,e,r)=>hp(t,typeof e!="symbol"?e+"":e,r),fi=class{constructor(e){this.context=e,dp(this,"_live",!1)}setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.length-1}get isrealtime(){return this.context.idx===this.context.length-1}get isconfirmed(){return this.context.data.closeTime.data[this.context.idx]<=Date.now()}get islastconfirmedhistory(){let e=this.context.idx,r=this.context.length;if(e===r-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===r-2){let n=this.context.marketData?.[r-1]?.closeTime;return n!==void 0?n>Date.now():!1}return!1}},fp=Object.defineProperty,mp=(t,e,r)=>e in t?fp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yp=(t,e,r)=>mp(t,typeof e!="symbol"?e+"":e,r),Lt=class t{constructor(e,r,n){this._definition=e,this.context=r,yp(this,"_udt");for(let i in e)this[i]=e[i];this._udt=n}get __def__(){return this._definition}copy(){return new t(this.__def__,this.context,this._udt)}toString(){let e={};for(let r in this.__def__){let n=this[r];n!=null&&typeof n=="object"&&typeof n.toString=="function"&&!(n instanceof Array)?e[r]=n.toString():e[r]=n}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(r=>`"${r}":${String(e[r])}`).join(",")+"}"}}},gp=Object.defineProperty,_p=(t,e,r)=>e in t?gp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ei=(t,e,r)=>_p(t,typeof e!="symbol"?e+"":e,r),Oe=class t{constructor(e,r,n){ei(this,"time"),ei(this,"index"),ei(this,"price"),this.time=e,this.index=r,this.price=n}copy(){return new t(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}};function xp(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}var Ws={series:t=>t instanceof y||typeof t=="number"||typeof t=="string"||typeof t=="boolean",string:t=>typeof t=="string",color:t=>typeof t=="string"||t===null||typeof t=="number"&&isNaN(t)||t instanceof y,number:t=>typeof t=="number",boolean:t=>typeof t=="boolean",array:t=>Array.isArray(t),object:t=>typeof t=="object",point:t=>t instanceof Oe,primitive:t=>typeof t===null||typeof t!="object"&&typeof t!="function",function:t=>typeof t=="function",undefined:t=>t===void 0,null:t=>t===null,NaN:t=>isNaN(t),any:()=>!0,remaining_options:t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof y)&&!(t instanceof Oe)&&!xp(t)};function ht(t){let e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function le(t,e,r,n){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);let i={},s={},a=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){let l=t[o];if(Ws.remaining_options(l)){s=l;break}let c=e.map((u,h)=>a[h]?u[o]:void 0);for(let u=0;u<c.length;u++){let h=c[u];if(h===void 0){a[u]=!1;continue}let p=r[h];if(typeof l=="number"&&isNaN(l)&&(p==="number"||p==="series"))i[h]=l;else{let d=Ws[r[h]];typeof d=="function"&&d(l)?i[h]=l:a[u]=!1}}}return{...i,...s,...n}}function N(t,e,r){let n=r.value;return typeof n!="function"||(r.value=function(...i){return this&&this.context&&this.context.isSecondaryContext?null:n.apply(this,i)}),r}var za=Object.defineProperty,bp=Object.getOwnPropertyDescriptor,vp=(t,e,r)=>e in t?za(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ka=(t,e,r,n)=>{for(var i=n>1?void 0:n?bp(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&za(e,r,i),i},dr=(t,e,r)=>vp(t,typeof e!="symbol"?e+"":e,r),wp=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],Ep={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},Sp=["title","shorttitle","overlay","format","precision","scale","max_bars_back","timeframe","timeframe_gaps","explicit_plot_zorder","max_lines_count","max_labels_count","max_boxes_count","calc_bars_count","max_polylines_count","dynamic_requests","behind_chart"],Cp={title:"string",shorttitle:"string",overlay:"boolean",format:"string",precision:"number",scale:"string",max_bars_back:"number",timeframe:"string",timeframe_gaps:"boolean",explicit_plot_zorder:"boolean",max_lines_count:"number",max_labels_count:"number",max_boxes_count:"number",calc_bars_count:"number",max_polylines_count:"number",dynamic_requests:"boolean",behind_chart:"boolean"};function Np(t){return le(t,Sp,Cp)}var Ze=class t{get __value(){return NaN}param(e,r=0){return y.from(e).get(r)}any(e){if(e instanceof t)return!0;let r=y.from(e).get(0);return r instanceof t||r==null?!0:typeof r=="number"?r!==r:!1}},sr={freq_all:"alert.freq_all",freq_once_per_bar:"alert.freq_once_per_bar",freq_once_per_bar_close:"alert.freq_once_per_bar_close"},un=class{constructor(e){this.context=e,dr(this,"_firedKeys",new Set),dr(this,"_fallbackCounter",0),dr(this,"_fallbackLastExecTick",-1)}get freq_all(){return sr.freq_all}get freq_once_per_bar(){return sr.freq_once_per_bar}get freq_once_per_bar_close(){return sr.freq_once_per_bar_close}param(e,r,n){return y.from(e).get(0)}any(e,r,n){let i=y.from(e).get(0),s=r?y.from(r).get(0):sr.freq_once_per_bar,a;if(n&&typeof n=="object"&&n.__callsiteId)a=n.__callsiteId;else{let u=this.context._execTick||0;u!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=u),a=`alert_${this._fallbackCounter++}`}let o=this.context.idx,l=this.context.pine?.barstate?.isrealtime??o===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;let c=`${a}:${o}`;if(s===sr.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(s===sr.freq_once_per_bar_close){if(!(this.context.pine?.barstate?.isconfirmed??!0)||this._firedKeys.has(c))return;this._firedKeys.add(c)}this.context.alerts.push({type:"alert",id:a,message:i,freq:s,bar_index:o,time:this.context.data.openTime?.data?.[o]??0})}};Ka([N],un.prototype,"any",1);var pn=class{constructor(e){this.context=e,dr(this,"_acCounter",0),dr(this,"_acLastExecTick",-1),dr(this,"_acFiredKeys",new Set)}extractPlotOptions(e){let r={};for(let n in e)r[n]=y.from(e[n]).get(0);return r}indicator(...e){let r=e.map(s=>s instanceof y?s.get(0):s),n=Np(r),i={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"points",max_bars_back:0,timeframe:"",timeframe_gaps:!0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,max_polylines_count:50,dynamic_requests:!1,behind_chart:!0};return this.context.indicator={...i,...n,...this.context._propOverrides??{}},this.context.indicator}get bar_index(){return this.context.idx}na(e){let r=y.from(e).get(0);return r==null||typeof r=="number"&&isNaN(r)}nz(e,r=0){let n=y.from(e).get(0),i=y.from(r).get(0);return n==null||typeof n=="number"&&isNaN(n)?i:n}fixnan(e){let r=y.from(e);for(let n=0;n<r.length;n++){let i=r.get(n);if(!isNaN(i))return i}return NaN}alertcondition(e,r,n){let i=y.from(e).get(0),s=this.context.idx,a=this.context._execTick||0;a!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=a);let o=`alertcondition_${this._acCounter++}`;if(!i)return;let l=this.context.pine?.barstate?.isrealtime??s===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;let c=`${o}:${s}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);let u=r?y.from(r).get(0):"",h=n?y.from(n).get(0):"";this.context.alerts.push({type:"alertcondition",id:o,title:u,message:h,bar_index:s,time:this.context.data.openTime?.data?.[s]??0})}error(...e){console.error("error called but is currently not implemented",e)}max_bars_back(e,r){}timestamp(...e){let r=e.map(i=>i instanceof y?i.get(0):i),n=le(r,wp,Ep);if(n.year!==void 0){let i=n.year,s=n.month,a=n.day,o=n.hour||0,l=n.minute||0,c=n.second||0,u=n.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(u,i,s,a,o,l,c)}if(n.dateString!==void 0){let i=n.dateString.trim();if(/[Zz]$/.test(i)||/[+-]\\d{2}:?\\d{2}$/.test(i))return new Date(i).getTime();let s=i.includes("T")?i+"Z":i.replace(/\\s+/,"T")+"Z",a=new Date(s);if(!isNaN(a.getTime())){let o=this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(o,a.getUTCFullYear(),a.getUTCMonth()+1,a.getUTCDate(),a.getUTCHours(),a.getUTCMinutes(),a.getUTCSeconds())}return new Date(i).getTime()}return NaN}_timestampFromComponents(e,r,n,i,s,a,o){let l=new Date(Date.UTC(r,n-1,i,s,a,o));r>=0&&r<100&&l.setUTCFullYear(r);let c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();let u=c.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(u){let h=u[1]==="+"?1:-1,p=parseInt(u[2],10),d=parseInt(u[3]||"0",10),f=h*(p*60+d)*60*1e3;return l.getTime()-f}try{return this._timestampFromIANA(e,r,n,i,s,a,o)}catch{return l.getTime()}}_timestampFromIANA(e,r,n,i,s,a,o){let l=new Date(Date.UTC(r,n-1,i,s,a,o));r>=0&&r<100&&l.setUTCFullYear(r);let c=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(l),u=v=>parseInt(c.find(E=>E.type===v)?.value||"0",10),h=u("year"),p=u("month"),d=u("day"),f=u("hour");f===24&&(f=0);let m=u("minute"),x=u("second"),b=new Date(Date.UTC(h,p-1,d,f,m,x));h>=0&&h<100&&b.setUTCFullYear(h);let w=b.getTime()-l.getTime();return l.getTime()-w}bool(e){let r=y.from(e).get(0);return!isNaN(r)&&r!==0}int(e){let r=y.from(e).get(0);if(typeof r!="number")throw new Error(`Cannot call "int" with argument "x"="${r}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.trunc(r)}float(e){let r=y.from(e).get(0);if(typeof r!="number")throw new Error(`Cannot call "float" with argument "x"="${r}". An argument of "literal string" type was used but a "const float" is expected.`);return r}string(e){return y.from(e).get(0).toString()}Type(e){let r=Object.keys(e),n={};for(let s of r){let a=e[s];a instanceof y&&(a=a.data),Array.isArray(a)&&(a[0],n[s]=a[1])}let i={new:function(...s){let a={},o=null;if(s.length>0){let l=s[s.length-1];if(l&&typeof l=="object"&&!(l instanceof y)&&!Array.isArray(l)&&!(l instanceof Lt)){let c=Object.keys(l);c.length>0&&c.some(u=>r.includes(u))&&(o=l,s=s.slice(0,-1))}}for(let l=0;l<r.length;l++){let c=r[l];o&&c in o?a[c]=o[c]:l<s.length?a[c]=s[l]:c in n&&(a[c]=y.from(n[c]).get(0))}return new Lt(a,this.context,i)},copy:function(s){return new Lt(s.__def__,this.context,i)},_fieldDefaults:n,_definitionKeys:r};return i}};Ka([N],pn.prototype,"alertcondition",1);function Kt(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){let r=t.slice(1);return r.length===6?[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16),1]:r.length===8?[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16),parseInt(r.slice(6,8),16)/255]:null}let e=t.match(/rgba?\\(\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*([\\d.]+))?\\s*\\)/);return e?[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),e[4]?parseFloat(e[4]):1]:null}function kp(t,e,r,n){let i=Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0"),s=Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0"),a=Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");if(n>=1)return`#${i}${s}${a}`.toUpperCase();let o=Math.round(Math.max(0,Math.min(255,n*255))).toString(16).padStart(2,"0");return`#${i}${s}${a}${o}`.toUpperCase()}var xe={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#F23645",silver:"#B2B5BE",teal:"#089981",white:"#FFFFFF",yellow:"#FDD835"};function Ha(t){if(typeof t!="string")return null;let e=t.trim(),r=e.startsWith("color.")?e.slice(6):e;return Object.prototype.hasOwnProperty.call(xe,r)&&(e=xe[r]),Kt(e)}function mi(t,e,r,n){let i=s=>Math.round(Math.max(0,Math.min(255,s))).toString(16).padStart(2,"0");return`#${i(t)}${i(e)}${i(r)}${i(n*255)}`.toUpperCase()}function Ip(t){let e=Ha(t);return e?mi(e[0],e[1],e[2],e[3]):t}function gt(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}var yi=class{constructor(e){this.context=e}any(e){let r=y.from(e).get(0);return typeof r=="number"&&isNaN(r)?null:r}param(e,r=0){return y.from(e).get(r)}new(e,r){if(e=gt(e),!e||typeof e!="string")return e;if(typeof r=="number"&&isNaN(r)&&(r=void 0),e.startsWith("#")){let n=e.slice(1),i=n.length===8?n.slice(0,6):n;return r!=null?`#${i}${Math.round(255/100*(100-r)).toString(16).padStart(2,"0").toUpperCase()}`:`#${n}`}else{let n=xe[e];if(n)return r!=null?`#${n.slice(1)}${Math.round(255/100*(100-r)).toString(16).padStart(2,"0").toUpperCase()}`:n;let i=e.match(/rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)(?:\\s*,\\s*([\\d.]+))?\\s*\\)/);if(i){let s=i[1],a=i[2],o=i[3];if(r!=null){let l=parseInt(s).toString(16).padStart(2,"0"),c=parseInt(a).toString(16).padStart(2,"0"),u=parseInt(o).toString(16).padStart(2,"0"),h=Math.round(255/100*(100-r)).toString(16).padStart(2,"0").toUpperCase();return`#${l}${c}${u}${h}`}return e}return r!=null?`rgba(${e}, ${(100-r)/100})`:e}}rgb(e,r,n,i){return typeof i=="number"&&isNaN(i)&&(i=void 0),i!=null?`rgba(${e}, ${r}, ${n}, ${(100-i)/100})`:`rgb(${e}, ${r}, ${n})`}from_gradient(e,r,n,i,s){if(e=gt(e),r=gt(r),n=gt(n),i=gt(i),s=gt(s),e==null||typeof e=="number"&&isNaN(e)||r==null||typeof r=="number"&&isNaN(r)||n==null||typeof n=="number"&&isNaN(n)||i==null||typeof i=="number"&&isNaN(i)||s==null||typeof s=="number"&&isNaN(s))return;let a=0;n!==r&&(a=(e-r)/(n-r)),a=Math.max(0,Math.min(1,a));let o=Kt(typeof i=="string"?i:"#000000")||[0,0,0,1],l=Kt(typeof s=="string"?s:"#FFFFFF")||[255,255,255,1],c=o[0]+(l[0]-o[0])*a,u=o[1]+(l[1]-o[1])*a,h=o[2]+(l[2]-o[2])*a,p=o[3]+(l[3]-o[3])*a;return kp(c,u,h,p)}r(e){if(e=gt(e),!e||typeof e!="string")return NaN;let r=Kt(e);return r?r[0]:NaN}g(e){if(e=gt(e),!e||typeof e!="string")return NaN;let r=Kt(e);return r?r[1]:NaN}b(e){if(e=gt(e),!e||typeof e!="string")return NaN;let r=Kt(e);return r?r[2]:NaN}t(e){if(e=gt(e),!e||typeof e!="string")return NaN;let r=Kt(e);return r?Math.round(100-r[3]*100):NaN}aqua(){return xe.aqua}black(){return xe.black}blue(){return xe.blue}fuchsia(){return xe.fuchsia}gray(){return xe.gray}green(){return xe.green}lime(){return xe.lime}maroon(){return xe.maroon}navy(){return xe.navy}olive(){return xe.olive}orange(){return xe.orange}purple(){return xe.purple}red(){return xe.red}silver(){return xe.silver}teal(){return xe.teal}white(){return xe.white}yellow(){return xe.yellow}},Ap=Object.defineProperty,Tp=(t,e,r)=>e in t?Ap(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hn=(t,e,r)=>Tp(t,typeof e!="symbol"?e+"":e,r);function gi(t){if(!t)return"";let e=t.trim().toUpperCase();return e==="1D"||e==="D"?"D":e==="1W"||e==="W"?"W":e==="1M"||e==="M"?"M":e}function _i(t,e){let r=Dp(e);if(e==="M"){let o=new Date(t);return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),1)}if(e==="W"){let o=new Date(t),l=o.getUTCDay(),c=l===0?6:l-1;return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),o.getUTCDate()-c)}if(e==="D"||r>=1440)return Math.floor(t/864e5)*864e5;let n=r*6e4,i=Math.floor(t/864e5)*864e5,s=t-i,a=Math.floor(s/n)*n;return i+a}function Dp(t){if(t==="D")return 1440;if(t==="W")return 10080;if(t==="M")return 43200;let e=parseInt(t,10);return isNaN(e)?1440:e}function Zt(t,e){let r=e.trim();if(r==="UTC"||r==="GMT"||r==="Etc/UTC"){let i=new Date(t);return{year:i.getUTCFullYear(),month:i.getUTCMonth()+1,day:i.getUTCDate(),hour:i.getUTCHours(),minute:i.getUTCMinutes(),second:i.getUTCSeconds(),dayOfWeek:i.getUTCDay()}}let n=r.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(n){let i=n[1]==="+"?1:-1,s=parseInt(n[2],10),a=parseInt(n[3]||"0",10),o=i*(s*60+a)*60*1e3,l=new Date(t+o);return{year:l.getUTCFullYear(),month:l.getUTCMonth()+1,day:l.getUTCDate(),hour:l.getUTCHours(),minute:l.getUTCMinutes(),second:l.getUTCSeconds(),dayOfWeek:l.getUTCDay()}}try{let i=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",weekday:"short",hour12:!1}).formatToParts(new Date(t)),s=c=>parseInt(i.find(u=>u.type===c)?.value||"0",10),a=s("hour");a===24&&(a=0);let o=i.find(c=>c.type==="weekday")?.value||"Sun",l={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:s("year"),month:s("month"),day:s("day"),hour:a,minute:s("minute"),second:s("second"),dayOfWeek:l[o]??0}}catch{let i=new Date(t);return{year:i.getUTCFullYear(),month:i.getUTCMonth()+1,day:i.getUTCDate(),hour:i.getUTCHours(),minute:i.getUTCMinutes(),second:i.getUTCSeconds(),dayOfWeek:i.getUTCDay()}}}function Mp(t,e,r){let n=new Date(Date.UTC(t,e-1,r)),i=n.getUTCDay()||7;n.setUTCDate(n.getUTCDate()+4-i);let s=new Date(Date.UTC(n.getUTCFullYear(),0,1));return Math.ceil(((n.getTime()-s.getTime())/864e5+1)/7)}var Pp=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],Rp={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"},dn=class{constructor(e,r="openTime"){hn(this,"context"),hn(this,"dataField"),this.context=e,this.dataField=r}get __value(){return this.context.data[this.dataField]}param(e,r=0){return y.from(e).get(r)}any(...e){let r=e.map(p=>p instanceof y?p.get(0):p),n=le(r,Pp,Rp),i=n.bars_back??0,s=n.timeframe||"",a=this.context.data[this.dataField],o=y.from(a).get(i);if(isNaN(o)||o==null)return NaN;let l=this.context.timeframe||"",c=gi(s),u=gi(l),h;if(!c||c===u?h=o:h=_i(o,c),n.session!==void 0&&n.session!==""){let p=n.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(h,n.session,p)?h:NaN}return h}_isInSession(e,r,n){let i=r.match(/^(\\d{2})(\\d{2})-(\\d{2})(\\d{2})$/);if(!i)return!0;let s=parseInt(i[1],10),a=parseInt(i[2],10),o=parseInt(i[3],10),l=parseInt(i[4],10),c=Zt(e,n),u=c.hour,h=c.minute,p=u*60+h,d=s*60+a,f=o*60+l;return d<=f?p>=d&&p<f:p>=d||p<f}},Fp=[[],["time"],["time","timezone"]],Bp={time:"number",timezone:"string"},xt=class{constructor(e,r){hn(this,"context"),hn(this,"extractor"),this.context=e,this.extractor=r}get __value(){let e=y.from(this.context.data.openTime).get(0);if(isNaN(e))return NaN;let r=this.context.pine?.syminfo?.timezone||"UTC",n=Zt(e,r);return this.extractor(n)}param(e,r=0){return y.from(e).get(r)}any(...e){let r=e.map(o=>o instanceof y?o.get(0):o);if(r.length===0)return this.__value;let n=le(r,Fp,Bp),i=n.time;if(i===void 0||isNaN(i))return NaN;let s=n.timezone||this.context.pine?.syminfo?.timezone||"UTC",a=Zt(i,s);return this.extractor(a)}},Ft={dayofmonth:t=>t.day,dayofweek:t=>t.dayOfWeek===0?1:t.dayOfWeek+1,hour:t=>t.hour,minute:t=>t.minute,month:t=>t.month,second:t=>t.second,weekofyear:t=>Mp(t.year,t.month,t.day),year:t=>t.year},Lp=[["defval","title","tooltip","inline","group","display"],["defval","title","tooltip","group","confirm","display"],["defval","title","tooltip","inline","group","confirm","display"],["defval","title","options","tooltip","inline","group","confirm","display"],["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display"]],Op={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function Ke(t){let e,r=t[t.length-1];r&&typeof r=="object"&&Object.prototype.hasOwnProperty.call(r,"__varId")&&(e=r.__varId,t=t.slice(0,-1));let n=le(t,Lp,Op);return e!==void 0&&(n.__varId=e),n}function Xe(t,e){return e.__varId&&t.inputs&&t.inputs[e.__varId]!==void 0?t.inputs[e.__varId]:e.title&&t.inputs&&t.inputs[e.title]!==void 0?t.inputs[e.title]:e.defval}function Vp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function jp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function $p(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Wp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Up(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function qp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function zp(t){return(e,r=0)=>y.from(e).get(r)}function Kp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Hp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Gp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Yp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Zp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Xp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Qp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Jp(t){return(...e)=>Ke(e).defval}var eh=Object.defineProperty,th=(t,e,r)=>e in t?eh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Be=(t,e,r)=>th(t,typeof e!="symbol"?e+"":e,r),rh={any:Vp,bool:jp,color:$p,enum:Wp,float:Up,int:qp,param:zp,price:Kp,session:Hp,source:Gp,string:Yp,symbol:Zp,text_area:Xp,time:Qp,timeframe:Jp},xi=class{constructor(e){this.context=e,Be(this,"any"),Be(this,"bool"),Be(this,"color"),Be(this,"enum"),Be(this,"float"),Be(this,"int"),Be(this,"param"),Be(this,"price"),Be(this,"session"),Be(this,"source"),Be(this,"string"),Be(this,"symbol"),Be(this,"text_area"),Be(this,"time"),Be(this,"timeframe"),Object.entries(rh).forEach(([r,n])=>{this[r]=n(e)})}};function nh(t){return e=>Math.abs(y.from(e).get(0))}function ih(t){return e=>Math.acos(y.from(e).get(0))}function sh(t){return e=>Math.asin(y.from(e).get(0))}function ah(t){return e=>Math.atan(y.from(e).get(0))}function oh(t){return(...e)=>{let r=e.map(n=>y.from(n).get(0));return r.reduce((n,i)=>n+i,0)/r.length}}function lh(t){return e=>Math.ceil(y.from(e).get(0))}function ch(t){return e=>Math.cos(y.from(e).get(0))}function uh(t){return()=>Math.E}function ph(t){return e=>Math.exp(y.from(e).get(0))}function hh(t){return e=>Math.floor(y.from(e).get(0))}function dh(t){return e=>Math.log(y.from(e).get(0))}function fh(t){return e=>Math.log(y.from(e).get(0))}function mh(t){return e=>Math.log10(y.from(e).get(0))}function yh(t){return(...e)=>{let r=e.map(n=>y.from(n).get(0));return Math.max(...r)}}function gh(t){return(...e)=>{let r=e.map(n=>y.from(n).get(0));return Math.min(...r)}}function _h(t){return(e,r,n)=>typeof e=="string"?e:e instanceof y?r?new y(e.data,e.offset+r):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[n]||(t.params[n]=[]),Array.isArray(e)?new y(e,r||0):(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,new y(t.params[n],r||0)))}function xh(t){return()=>1.618033988749895}function bh(t){return()=>Math.PI}function vh(t){return(e,r)=>Math.pow(y.from(e).get(0),y.from(r).get(0))}function wh(t){return()=>Math.random()}function ti(t){return t!==t?NaN:Math.sign(t)*Math.round(Math.abs(t))}function Eh(t){return(e,r)=>{let n=y.from(e).get(0);if(r==null)return ti(n);let i=y.from(r).get(0);if(i===0)return ti(n);let s=Math.pow(10,i);return ti(n*s)/s}}function Sh(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Ch(t){return()=>.6180339887498948}function Nh(t){return e=>Math.sign(y.from(e).get(0))}function kh(t){return e=>Math.sin(y.from(e).get(0))}function Ih(t){return e=>Math.sqrt(y.from(e).get(0))}function Ah(t){return(e,r)=>{let n=y.from(r).get(0),i=y.from(e),s=0;for(let a=0;a<n;a++){let o=i.get(a);s+=o}return s}}function Th(t){return e=>Math.tan(y.from(e).get(0))}function Dh(t){return e=>{let r=y.from(e).get(0);return r==null||Number.isNaN(r)?NaN:r*(180/Math.PI)}}function Mh(t){return e=>{let r=y.from(e).get(0);return r==null||Number.isNaN(r)?NaN:r*(Math.PI/180)}}function Ph(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10:n===i}}function Rh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10?!0:n>i:n>=i}}function Fh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10?!1:n>i:n>i}}function Bh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n!="number"||typeof i!="number"?n/i:isNaN(n)||isNaN(i)?NaN:Math.trunc(n/i)}}function Lh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10?!0:n<i:n<=i}}function Oh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10?!1:n<i:n<i}}function Vh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)>=1e-10:n!==i}}var jh=Object.defineProperty,$h=(t,e,r)=>e in t?jh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Z=(t,e,r)=>$h(t,typeof e!="symbol"?e+"":e,r),Wh={abs:nh,acos:ih,asin:sh,atan:ah,avg:oh,ceil:lh,cos:ch,e:uh,exp:ph,floor:hh,ln:dh,log:fh,log10:mh,max:yh,min:gh,param:_h,phi:xh,pi:bh,pow:vh,random:wh,round:Eh,round_to_mintick:Sh,rphi:Ch,sign:Nh,sin:kh,sqrt:Ih,sum:Ah,tan:Th,todegrees:Dh,toradians:Mh,__eq:Ph,__ge:Rh,__gt:Fh,__idiv:Bh,__le:Lh,__lt:Oh,__neq:Vh},bi=class{constructor(e){this.context=e,Z(this,"_cache",{}),Z(this,"abs"),Z(this,"acos"),Z(this,"asin"),Z(this,"atan"),Z(this,"avg"),Z(this,"ceil"),Z(this,"cos"),Z(this,"e"),Z(this,"exp"),Z(this,"floor"),Z(this,"ln"),Z(this,"log"),Z(this,"log10"),Z(this,"max"),Z(this,"min"),Z(this,"param"),Z(this,"phi"),Z(this,"pi"),Z(this,"pow"),Z(this,"random"),Z(this,"round"),Z(this,"round_to_mintick"),Z(this,"rphi"),Z(this,"sign"),Z(this,"sin"),Z(this,"sqrt"),Z(this,"sum"),Z(this,"tan"),Z(this,"todegrees"),Z(this,"toradians"),Z(this,"__eq"),Z(this,"__ge"),Z(this,"__gt"),Z(this,"__idiv"),Z(this,"__le"),Z(this,"__lt"),Z(this,"__neq"),Object.entries(Wh).forEach(([r,n])=>{this[r]=n(e)})}};function Uh(t){return(e,r,n)=>{t.params[n]||(t.params[n]=[]);let i;if(e instanceof y)i=e.get(r||0);else if(Array.isArray(e)){let s=e.some(o=>o instanceof y),a=e.every(o=>!(o instanceof y)&&!Array.isArray(o));(s||a)&&e.length>=1?i=e.map(o=>o instanceof y?o.get(0):o):i=y.from(e).get(r||0)}else i=e;return t.params[n].length===0?t.params[n].push(i):t.params[n][t.params[n].length-1]=i,t._requestParamSources||(t._requestParamSources={}),t._requestParamSources[n]=e,[i,n]}}var qh=new Set(["heikinashi","standard"]);function Lr(t){if(typeof t!="string")return{symbol:t,modifier:null};let e=t.lastIndexOf(";");if(e<=0||e===t.length-1)return{symbol:t,modifier:null};let r=t.slice(e+1).toLowerCase();return qh.has(r)?{symbol:t.slice(0,e),modifier:r}:{symbol:t,modifier:null}}function Ot(t){return Lr(t).symbol}function vi(t,e){return`${Ot(t)};${e}`}var yr=["1","3","5","15","30","45","60","120","180","240","D","W","M"],Kr={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function fn(t){if(yr.includes(t))return t;if(Kr[t])return Kr[t];let e=t.toLowerCase();if(Kr[e])return Kr[e];let r=t.toUpperCase();return yr.includes(r)?r:t}function Us(t,e,r,n,i=!1,s=!1){for(let a=0;a<r.length;a++)if(r[a]<=t&&t<n[a])return i||s||e>=n[a]?a:a-1;return-1}function qs(t,e,r,n,i=!1,s,a=!1){for(let o=r.length-1;o>=0;o--){if(n[o]<=e&&r[o]>=t){let l=s&&e>s;if(a&&i)for(let c=0;c<r.length;c++){if(r[c]>=t&&r[c]<e)return c;if(r[c]>=e)break}if(l&&i&&!a)for(let c=0;c<r.length;c++){if(r[c]>=t&&r[c]<e)return c;if(r[c]>=e)break}return o}if(n[o]<t)break}return-1}var zs=[["symbol","timeframe","expression"],["symbol","timeframe","expression","gaps"],["symbol","timeframe","expression","gaps","lookahead"],["symbol","timeframe","expression","gaps","lookahead","ignore_invalid_symbol"],["symbol","timeframe","expression","gaps","lookahead","ignore_invalid_symbol","currency"],["symbol","timeframe","expression","gaps","lookahead","ignore_invalid_symbol","currency","calc_bars_count"]],zh={symbol:"series",timeframe:"series",expression:"any",gaps:"series",lookahead:"series",ignore_invalid_symbol:"series",currency:"series",calc_bars_count:"series"};function ls(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function Kh(t,e){return t.map(r=>ls(r)?(e.push(r[1]),r[0]):(e.push(void 0),r))}function ar(t){return ls(t)?t[0]:t}function Hh(t,e,r,n){let i=e[e.length-1].indexOf(t);if(i>=0&&i<r.length&&r[i]!==void 0)return r[i];if(ls(n))return n[1]}function wi(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(wi):t}function Gh(t){return async(...e)=>{let r=[],n=Kh(e,r),i=le(n,zs,zh),s=ar(i.symbol),a=ar(i.timeframe),o=ar(i.expression),l=ar(i.gaps),c=ar(i.lookahead),u=s instanceof y?s.get(0):s,h=typeof t.tickerId=="string"&&t.tickerId.includes(":")?t.tickerId.split(":")[1]:t.tickerId,p=typeof h=="string"?Lr(h):{symbol:h,modifier:null},d=p.modifier==="standard"?null:p.modifier,f=u===""?t.tickerId:u,m=typeof f=="string"&&f.includes(":")?f.split(":")[1]:f,x=a instanceof y?a.get(0):a,b=x===""?t.timeframe:typeof x=="string"?x:String(x??""),w=o,v=Hh("expression",zs,r,i.expression),E=l,A=c,C=E===!0||E==="gaps_on",D=A===!0||A==="lookahead_on",j=(()=>{let Ae=ar(i.calc_bars_count);return typeof Ae=="number"&&Ae>0?Ae:void 0})();if(t.isSecondaryContext){let Ae=wi(w);return Array.isArray(Ae)?[Ae]:Ae}let k=yr.indexOf(fn(t.timeframe)),V=yr.indexOf(fn(b));if(k==-1||V==-1)throw new Error("Invalid timeframe");let T=typeof m=="string"?Lr(m):{symbol:m,modifier:null},W=T.modifier==="standard"?null:T.modifier,R=!m||m===""||T.symbol===p.symbol&&W===d;if(k===V&&R){let Ae=wi(w);return Array.isArray(Ae)?[Ae]:Ae}let M=k>V,H=y.from(t.data.openTime).get(0),ee=y.from(t.data.closeTime).get(0),we=t.idx===t.length-1&&ee>Date.now(),se=`${m}_${b}_${v}`,Fe=`${se}_prevIdx`;if(t.cache[se]){let Ae=t.cache[se];t.dataVersion>Ae.dataVersion&&(await Ae.pineTS.updateTail(Ae.context),Ae.dataVersion=t.dataVersion);let wr=Ae.context,zr=M?qs(H,ee,wr.data.openTime.data,wr.data.closeTime.data,D,t.eDate,C):Us(H,ee,wr.data.openTime.data,wr.data.closeTime.data,D,we);if(zr==-1)return NaN;let ir=wr.params[v][zr];if(!M&&C){let js=t.cache[Fe];return js!==void 0&&js===zr?NaN:(t.cache[Fe]=zr,Array.isArray(ir)?[ir]:ir)}return Array.isArray(ir)?[ir]:ir}let vr=1e3*60*60*24*30,Ls=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),jl=j?void 0:Ls?Ls-vr:void 0,$l=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),qr=new Wt(t.source,m,b,j,jl,$l);qr.markAsSecondary();let Os=typeof v=="string"?v:"",Wl=Os.match(/p\\d+$/)?.[0]??Os,Vs=t._ltfTruncatedBodies?.[Wl],nr=Vs?await qr.runPretranspiled(Vs):await qr.run(t.pineTSCode);t.cache[se]={pineTS:qr,context:nr,dataVersion:t.dataVersion};let Qn=M?qs(H,ee,nr.data.openTime.data,nr.data.closeTime.data,D,t.eDate,C):Us(H,ee,nr.data.openTime.data,nr.data.closeTime.data,D,we);if(Qn==-1)return NaN;let Jn=nr.params[v][Qn];return!M&&C?(t.cache[Fe]=Qn,NaN):Array.isArray(Jn)?[Jn]:Jn}}var Ks=[["symbol","timeframe","expression"],["symbol","timeframe","expression","ignore_invalid_symbol"],["symbol","timeframe","expression","ignore_invalid_symbol","currency"],["symbol","timeframe","expression","ignore_invalid_symbol","currency","ignore_invalid_timeframe"],["symbol","timeframe","expression","ignore_invalid_symbol","currency","ignore_invalid_timeframe","calc_bars_count"]],Yh={symbol:"series",timeframe:"series",expression:"any",ignore_invalid_symbol:"series",currency:"series",ignore_invalid_timeframe:"series",calc_bars_count:"series"};function cs(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function Zh(t,e){return t.map(r=>cs(r)?(e.push(r[1]),r[0]):(e.push(void 0),r))}function or(t){return cs(t)?t[0]:t}function Xh(t,e,r,n){let i=e[e.length-1].indexOf(t);if(i>=0&&i<r.length&&r[i]!==void 0)return r[i];if(cs(n))return n[1]}function lr(t){return typeof t=="number"?z.float:typeof t=="boolean"?z.bool:typeof t=="string"?z.string:z.any}var Ga={open:t=>t.open,high:t=>t.high,low:t=>t.low,close:t=>t.close,volume:t=>t.volume,hl2:t=>(t.high+t.low)/2,hlc3:t=>(t.high+t.low+t.close)/3,ohlc4:t=>(t.high+t.low+t.open+t.close)/4,hlcc4:t=>(t.high+t.low+t.close+t.close)/4,time:t=>t.openTime,openTime:t=>t.openTime,closeTime:t=>t.closeTime};function Ei(t,e){if(!(t instanceof y))return null;let r=e?.data;if(!r)return null;for(let n of Object.keys(Ga))if(t===r[n])return n;return null}function Qh(t,e){if(t instanceof y&&(t=t.get(0)),!(t instanceof Lt))return null;let r=t._udt;if(!r||!r._fieldDefaults||!Array.isArray(r._definitionKeys))return null;let n=r._definitionKeys;if(n.length===0)return null;let i=[];for(let s of n){if(!(s in r._fieldDefaults))return null;let a=r._fieldDefaults[s],o=Ei(a,e);if(o===null)return null;i.push(o)}return{kind:"udt",builtinNames:i,fieldNames:n,udt:r}}function Jh(t,e){if(t===void 0)return null;if(Array.isArray(t)){let n=[];for(let i of t){let s=Ei(i,e);if(s===null)return null;n.push(s)}return n.length>0?{kind:"tuple",builtinNames:n}:null}let r=Ei(t,e);return r!==null?{kind:"series",builtinNames:[r]}:Qh(t,e)}async function Hs(t,e,r,n,i,s){let a=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),o=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),l=new Wt(t.source,e,r,n,a,o);l.markAsSecondary(),await l.ready();let c=l.openTime,u=l.closeTime,h=l.data,p=i.builtinNames.map(f=>Ga[f]),d;if(i.kind==="series")d=h.map(f=>p[0](f));else if(i.kind==="tuple")d=h.map(f=>p.map(m=>m(f)));else{let f=i.fieldNames,m=i.udt;d=h.map(x=>{let b={};for(let w=0;w<f.length;w++)b[f[w]]=p[w](x);return new Lt(b,t,m)})}return{data:{openTime:{data:c},closeTime:{data:u}},params:{[s]:d}}}function ed(t){return async(...e)=>{let r=[],n=Zh(e,r),i=le(n,Ks,Yh),s=or(i.symbol),a=or(i.timeframe),o=or(i.expression),l=s instanceof y?s.get(0):s,c=l===""?t.tickerId:l,u=typeof c=="string"&&c.includes(":")?c.split(":")[1]:c,h=a instanceof y?a.get(0):a,p=h===""?t.timeframe:typeof h=="string"?h:String(h??""),d=o,f=Xh("expression",Ks,r,i.expression);or(i.ignore_invalid_symbol);let m=or(i.ignore_invalid_timeframe),x=(()=>{let M=or(i.calc_bars_count);return typeof M=="number"&&M>0?M:void 0})();if(t.isSecondaryContext)return Array.isArray(d)?[d.map(M=>new q([M],lr(M),t))]:new q([d],lr(d),t);let b=yr.indexOf(fn(t.timeframe)),w=yr.indexOf(fn(p));if(b===-1||w===-1){if(m)return NaN;throw new Error("Invalid timeframe")}if(w>b){if(m)return NaN;throw new Error(`Timeframe ${p} is not lower than or equal to chart timeframe ${t.timeframe}`)}if(w===b)return Array.isArray(d)?[d.map(M=>new q([M],lr(M),t))]:new q([d],lr(d),t);let v=`${u}_${p}_${f}_lower`,E=t._requestParamSources?.[f],A=Jh(E,t);if(!t.cache[v])if(A!==null){let M=await Hs(t,u,p,x,A,f);t.cache[v]={pineTS:null,context:M,dataVersion:t.dataVersion,_fastPath:!0,_fastPathArgs:{builtinExpr:A}}}else{let M=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),H=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),ee=new Wt(t.source,u,p,x,M,H);ee.markAsSecondary();let we=typeof f=="string"?f:"",se=we.match(/p\\d+$/)?.[0]??we,Fe=t._ltfTruncatedBodies?.[se],vr;Fe?vr=await ee.runPretranspiled(Fe):vr=await ee.run(t.pineTSCode),t.cache[v]={pineTS:ee,context:vr,dataVersion:t.dataVersion}}let C=t.cache[v];if(t.dataVersion>C.dataVersion)if(C._fastPath){let M=await Hs(t,u,p,x,C._fastPathArgs.builtinExpr,f);C.context=M,C.dataVersion=t.dataVersion}else await C.pineTS.updateTail(C.context),C.dataVersion=t.dataVersion;let D=C.context,j=y.from(t.data.openTime).get(0),k=y.from(t.data.closeTime).get(0),V=D.data.openTime.data,T=D.data.closeTime.data,W=D.params[f];if(!W)return Array.isArray(d)?[d.map(()=>new q([],z.float,t))]:new q([],z.float,t);let R=[];for(let M=0;M<V.length;M++){let H=V[M];if(!(T[M]<=j)){if(H>=k)break;H>=j&&H<k&&R.push(W[M])}}if(R.length>0&&Array.isArray(R[0])){let M=R[0].length,H=[];for(let ee=0;ee<M;ee++){let we=R.map(Fe=>Fe[ee]),se=we.length>0?lr(we[0]):z.float;H.push(new q(we,se,t))}return[H]}else{let M=R.length>0?lr(R[0]):z.float;return new q(R,M,t)}}}var td=Object.defineProperty,rd=(t,e,r)=>e in t?td(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Hr=(t,e,r)=>rd(t,typeof e!="symbol"?e+"":e,r),nd={param:Uh,security:Gh,security_lower_tf:ed},Si=class{constructor(e){this.context=e,Hr(this,"_cache",{}),Hr(this,"param"),Hr(this,"security"),Hr(this,"security_lower_tf"),Object.entries(nd).forEach(([r,n])=>{this[r]=n(e)})}};function id(t){return e=>{t.taState||(t.taState={});let r=e||"accdist";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),o=t.get(t.data.volume,0);if(isNaN(i)||isNaN(s)||isNaN(a)||isNaN(o))return n.currentCumulativeSum=n.prevCumulativeSum,t.precision(n.prevCumulativeSum);let l=s-a,c=0;l!==0&&(c=(i-a-(s-i))/l*o);let u=n.prevCumulativeSum+c;return n.currentCumulativeSum=u,t.precision(u)}}function sd(t){return(e,r,n,i,s)=>{let a=y.from(r).get(0),o=y.from(n).get(0),l=y.from(i).get(0);t.taState||(t.taState={});let c=s||`alma_${a}_${o}_${l}`;if(!t.taState[c]){let m=o*(a-1),x=a/l,b=[],w=0;for(let v=0;v<a;v++){let E=Math.exp(-Math.pow(v-m,2)/(2*x*x));b.push(E),w+=E}for(let v=0;v<b.length;v++)b[v]/=w;t.taState[c]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weights:b}}let u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.prevWindow=[...u.currentWindow],u.prevCallCount=u.currentCallCount),u.lastIdx=t.idx);let h=y.from(e).get(0),p=[...u.prevWindow];for(p.unshift(h);p.length>a;)p.pop();let d=u.prevCallCount+1;if(p.length<a&&(d>=a||t.idx>=a-1)){let m=y.from(e);for(;p.length<a;)p.push(m.get(p.length))}if(u.currentWindow=p,u.currentCallCount=d,p.length<a)return NaN;let f=0;for(let m=0;m<a;m++)f+=u.weights[m]*p[a-1-m];return t.precision(f)}}function ad(t){return(e,r)=>{let n=y.from(e).get(0);t.taState||(t.taState={});let i=r||`atr_${n}`;t.taState[i]||(t.taState[i]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});let s=t.taState[i];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevAtr=s.currentAtr,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);let a=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(l))return NaN;let c=t.idx>0?t.get(t.data.close,1):null,u;if(c!==null&&!isNaN(c)){let m=a-o,x=Math.abs(a-c),b=Math.abs(o-c);u=Math.max(m,x,b)}else u=a-o;let h=s.prevInitCount,p=s.prevInitSum,d=s.prevAtr;if(h<n){if(p+=u,h++,s.currentInitSum=p,s.currentInitCount=h,h===n){let m=p/n;return s.currentAtr=m,t.precision(m)}return NaN}let f=(d*(n-1)+u)/n;return s.currentAtr=f,t.precision(f)}}function od(t){return(e,r)=>{t.taState||(t.taState={});let n=r||"barssince";t.taState[n]||(t.taState[n]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});let i=t.taState[n];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevLastTrueIndex=i.currentLastTrueIndex),i.lastIdx=t.idx);let s=y.from(e).get(0),a=i.prevLastTrueIndex;return s&&(a=t.idx),i.currentLastTrueIndex=a,a===null?NaN:t.idx-a}}function ld(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`bb_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];let u=[...l.prevWindow],h=l.prevSum;for(u.unshift(c),h+=c;u.length>s;){let b=u.pop();h-=b}if(u.length<s&&t.idx>=s-1){let b=y.from(e);for(;u.length<s;){let w=b.get(u.length);if(isNaN(w))break;u.push(w),h+=w}}if(l.currentWindow=u,l.currentSum=h,u.length<s)return[[NaN,NaN,NaN]];let p=h/s,d=0;for(let b=0;b<s;b++)d+=Math.pow(u[b]-p,2);let f=Math.sqrt(d/s),m=p+a*f,x=p-a*f;return[[t.precision(p),t.precision(m),t.precision(x)]]}}function cd(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`bbw_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;let u=[...l.prevWindow],h=l.prevSum;for(u.unshift(c),h+=c;u.length>s;){let w=u.pop();h-=w}if(u.length<s&&t.idx>=s-1){let w=y.from(e);for(;u.length<s;){let v=w.get(u.length);if(isNaN(v))break;u.push(v),h+=v}}if(l.currentWindow=u,l.currentSum=h,u.length<s)return NaN;let p=h/s,d=0;for(let w=0;w<s;w++){let v=u[w]-p;d+=v*v}let f=d/s,m=Math.sqrt(f),x=a*m;if(p===0)return t.precision(0);let b=2*x/p*100;return t.precision(b)}}function ud(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`cci_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0);if(isNaN(o))return NaN;let l=[...a.prevWindow],c=a.prevSum;for(l.unshift(o),c+=o;l.length>i;){let m=l.pop();c-=m}let u=a.prevCallCount+1;if(l.length<i&&(u>=i||t.idx>=i-1)){let m=y.from(e);for(;l.length<i;){let x=m.get(l.length);if(isNaN(x))break;l.push(x),c+=x}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=u,l.length<i)return NaN;let h=c/i,p=0;for(let m=0;m<i;m++)p+=Math.abs(l[m]-h);let d=p/i;if(d===0)return 0;let f=(o-h)/(.015*d);return t.precision(f)}}function pd(t){return(e,r=1,n)=>{typeof r=="string"&&(n=r,r=1);let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`change_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i+1;)l.pop();let c=a.prevCallCount+1;if(l.length<i+1&&(c>=i+1||t.idx>=i)){let h=y.from(e);for(;l.length<i+1;)l.push(h.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=i)return NaN;let u=o-l[i];return t.precision(u)}}function hd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`cmo_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevGainsWindow=[...a.currentGainsWindow],a.prevLossesWindow=[...a.currentLossesWindow],a.prevGainsSum=a.currentGainsSum,a.prevLossesSum=a.currentLossesSum),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;let c=o-l,u=c>=0?c:0,h=c>=0?0:-c,p=[...a.prevGainsWindow],d=[...a.prevLossesWindow],f=a.prevGainsSum,m=a.prevLossesSum;if(p.unshift(u),d.unshift(h),f+=u,m+=h,p.length<i)return a.currentGainsWindow=p,a.currentLossesWindow=d,a.currentGainsSum=f,a.currentLossesSum=m,NaN;if(p.length>i){let w=p.pop(),v=d.pop();f-=w,m-=v}a.currentGainsWindow=p,a.currentLossesWindow=d,a.currentGainsSum=f,a.currentLossesSum=m;let x=f+m;if(x===0)return t.precision(0);let b=100*(f-m)/x;return t.precision(b)}}function dd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e),a=0,o=!1;for(let u=0;u<i;u++){let h=s.get(u);if(isNaN(h)){o=!0;break}a+=h}if(o)return NaN;let l=0;for(let u=0;u<i;u++){let h=s.get(u);l+=h*(u+1)}if(a===0)return NaN;let c=-l/a;return t.precision(c)}}function fd(t){return(e,r,n,i)=>{let s=y.from(n).get(0),a=y.from(e),o=y.from(r);if(t.idx<s-1)return NaN;let l=0,c=0,u=0,h=0,p=0,d=0;for(let w=0;w<s;w++){let v=a.get(w),E=o.get(w);isNaN(v)||isNaN(E)||(l+=v,c+=E,u+=v*E,h+=v*v,p+=E*E,d++)}if(d<2)return NaN;let f=d*u-l*c,m=d*h-l*l,x=d*p-c*c;if(m<=0||x<=0)return t.precision(0);let b=f/Math.sqrt(m*x);return t.precision(b)}}function md(t){return(e,r,n)=>{let i=y.from(e),s=y.from(r),a=i.get(0),o=s.get(0),l=i.get(1),c=s.get(1);if(isNaN(a)||isNaN(o)||isNaN(l)||isNaN(c))return!1;let u=a>o&&l<=c,h=a<o&&l>=c;return u||h}}function yd(t){return(e,r)=>{let n=y.from(e),i=y.from(r),s=n.get(0),a=i.get(0),o=n.get(1),l=i.get(1);return o<=l&&s>a}}function gd(t){return(e,r)=>{let n=y.from(e),i=y.from(r),s=n.get(0),a=i.get(0),o=n.get(1),l=i.get(1);return o>=l&&s<a}}function _d(t){return(e,r)=>{t.taState||(t.taState={});let n=r||"cum";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let i=t.taState[n];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevCumulativeSum=i.currentCumulativeSum),i.lastIdx=t.idx);let s=y.from(e).get(0);if(isNaN(s))return i.currentCumulativeSum=i.prevCumulativeSum,t.precision(i.prevCumulativeSum);let a=i.prevCumulativeSum+s;return i.currentCumulativeSum=a,t.precision(a)}}function xd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`dev_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0)||0,l=[...a.prevWindow],c=a.prevSum;for(l.unshift(o),c+=o;l.length>i;){let f=l.pop();c-=f}let u=a.prevCallCount+1;if(l.length<i&&(u>=i||t.idx>=i-1)){let f=y.from(e);for(;l.length<i;){let m=f.get(l.length);l.push(m),c+=m}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=u,l.length<i)return NaN;let h=c/i,p=0;for(let f=0;f<i;f++)p+=Math.abs(l[f]-h);let d=p/i;return t.precision(d)}}function bd(t){return(e,r,n)=>{let i=y.from(e).get(0),s=y.from(r).get(0);t.taState||(t.taState={});let a=n||`dmi_${i}_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevTrInitSum:0,prevPlusInitSum:0,prevMinusInitSum:0,prevInitCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,prevDxInitSum:0,prevAdxInitCount:0,prevADX:NaN,currentTrInitSum:0,currentPlusInitSum:0,currentMinusInitSum:0,currentInitCount:0,currentSmoothedTR:NaN,currentSmoothedPlus:NaN,currentSmoothedMinus:NaN,currentDxInitSum:0,currentAdxInitCount:0,currentADX:NaN});let o=t.taState[a];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrInitSum=o.currentTrInitSum,o.prevPlusInitSum=o.currentPlusInitSum,o.prevMinusInitSum=o.currentMinusInitSum,o.prevInitCount=o.currentInitCount,o.prevSmoothedTR=o.currentSmoothedTR,o.prevSmoothedPlus=o.currentSmoothedPlus,o.prevSmoothedMinus=o.currentSmoothedMinus,o.prevDxInitSum=o.currentDxInitSum,o.prevAdxInitCount=o.currentAdxInitCount,o.prevADX=o.currentADX),o.lastIdx=t.idx);let l=t.get(t.data.high,0),c=t.get(t.data.low,0),u=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(u))return[[NaN,NaN,NaN]];let h=t.idx>0?t.get(t.data.high,1):NaN,p=t.idx>0?t.get(t.data.low,1):NaN,d=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(h))return[[NaN,NaN,NaN]];let f=Math.max(l-c,Math.abs(l-d),Math.abs(c-d)),m=l-h,x=p-c,b=m>x&&m>0?m:0,w=x>m&&x>0?x:0,v=o.prevInitCount,E=o.prevTrInitSum,A=o.prevPlusInitSum,C=o.prevMinusInitSum,D=o.prevSmoothedTR,j=o.prevSmoothedPlus,k=o.prevSmoothedMinus;if(v++,v<=i)E+=f,A+=b,C+=w,v===i&&(D=E/i,j=A/i,k=C/i);else{let se=1/i;D=se*f+(1-se)*D,j=se*b+(1-se)*j,k=se*w+(1-se)*k}if(o.currentInitCount=v,o.currentTrInitSum=E,o.currentPlusInitSum=A,o.currentMinusInitSum=C,o.currentSmoothedTR=D,o.currentSmoothedPlus=j,o.currentSmoothedMinus=k,v<i)return[[NaN,NaN,NaN]];let V=D===0?0:100*j/D,T=D===0?0:100*k/D,W=V+T,R=W===0?0:100*Math.abs(V-T)/W,M=o.prevAdxInitCount,H=o.prevDxInitSum,ee=o.prevADX,we=NaN;if(M++,M<=s)H+=R,M===s&&(ee=H/s,we=ee);else{let se=1/s;ee=se*R+(1-se)*ee,we=ee}return o.currentAdxInitCount=M,o.currentDxInitSum=H,o.currentADX=ee,[[t.precision(V),t.precision(T),t.precision(we)]]}}function vd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`ema_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevEma=a.currentEma,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);let o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=a.prevInitCount,c=a.prevInitSum,u=a.prevEma;if(l<i){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===i){let d=c/i;return a.currentEma=d,t.precision(d)}return NaN}let h=2/(i+1),p=o*h+u*(1-h);return a.currentEma=p,t.precision(p)}}function wd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);for(let a=0;a<i;a++){let o=s.get(a),l=s.get(a+1);if(isNaN(o)||isNaN(l)||o>=l)return!1}return!0}}function Ed(t){return(e,r,n)=>{typeof r=="string"&&n===void 0&&(n=r,r=e,e=t.data.high);let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`highest_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let p=y.from(e);for(;l.length<i;)l.push(p.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.filter(p=>!isNaN(p)&&p!==void 0);if(u.length===0)return NaN;let h=Math.max(...u);return t.precision(h)}}function Sd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=-1/0,o=NaN;for(let l=0;l<i;l++){let c=s.get(l);isNaN(c)||(isNaN(o)||c>a)&&(a=c,o=-l)}return o}}function Cd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=Math.floor(i/2),a=Math.floor(Math.sqrt(i)),o=t.pine.ta.wma,l=o(e,s,n?`${n}_wma1`:void 0),c=o(e,i,n?`${n}_wma2`:void 0);if(isNaN(l)||isNaN(c))return NaN;t.taState||(t.taState={});let u=n||`hma_raw_${i}`;t.taState[u]||(t.taState[u]={lastIdx:-1,prevValues:[],currentValues:[]});let h=t.taState[u];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.prevValues=[...h.currentValues]),h.lastIdx=t.idx);let p=2*l-c,d=[...h.prevValues];d.unshift(p),d.length>a+1&&d.pop(),h.currentValues=d;let f=n?`${n}_hma_final`:`hma_final_${i}`;t.taState[f]||(t.taState[f]={lastIdx:-1,prevWindow:[],currentWindow:[]});let m=t.taState[f];t.idx>m.lastIdx&&(m.lastIdx>=0&&(m.prevWindow=[...m.currentWindow]),m.lastIdx=t.idx);let x=[...m.prevWindow];if(x.unshift(p),x.length<a)return m.currentWindow=x,NaN;for(;x.length>a;)x.pop();m.currentWindow=x;let b=0,w=0;for(let E=0;E<a;E++){let A=a-E;b+=x[E]*A,w+=A}let v=b/w;return t.precision(v)}}function Nd(t){return e=>{let r=t.get(t.data.close,0),n=t.get(t.data.high,0),i=t.get(t.data.low,0),s=t.get(t.data.volume,0);if(isNaN(r)||isNaN(n)||isNaN(i)||isNaN(s))return NaN;let a=(n-i)*s;if(a===0)return t.precision(0);let o=(2*r-n-i)/a;return t.precision(o)}}function kd(t){return(e,r,n,i,s)=>{let a=y.from(r).get(0),o=y.from(n).get(0),l=!0;typeof i=="string"?s=i:i!==void 0&&(l=y.from(i).get(0));let c,u=t.get(t.data.high,0),h=t.get(t.data.low,0);if(l){let E=t.get(t.data.close,1);isNaN(E)?c=NaN:c=Math.max(u-h,Math.abs(u-E),Math.abs(h-E))}else c=u-h;let p=y.from(e).get(0);t.taState||(t.taState={});let d=s||`kc_${a}_${o}_${l}`;t.taState[d]||(t.taState[d]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});let f=t.taState[d];t.idx>f.lastIdx&&(f.lastIdx>=0&&(f.basisState={...f.currentBasisState},f.rangeState={...f.currentRangeState}),f.lastIdx=t.idx);let m=(E,A,C,D)=>{if(isNaN(C))return Object.assign(A,E),A.prevEma!==null?A.prevEma:NaN;let j=E.initCount,k=E.initSum,V=E.prevEma;if(j<D){if(k+=C,j++,A.initSum=k,A.initCount=j,A.prevEma=V,j===D){let R=k/D;return A.prevEma=R,R}return NaN}let T=2/(D+1),W=C*T+V*(1-T);return A.prevEma=W,A.initSum=k,A.initCount=j,W},x=m(f.basisState,f.currentBasisState,p,a),b=m(f.rangeState,f.currentRangeState,c,a);if(isNaN(x)||isNaN(b))return[[NaN,NaN,NaN]];let w=x+b*o,v=x-b*o;return[[t.precision(x),t.precision(w),t.precision(v)]]}}function Id(t){return(e,r,n,i,s)=>{let a=y.from(r).get(0),o=y.from(n).get(0),l=!0;typeof i=="string"?s=i:i!==void 0&&(l=y.from(i).get(0)),t.taState||(t.taState={});let c=s||`kcw_${a}_${o}_${l}`;t.taState[c]||(t.taState[c]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});let u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.basisState={...u.currentBasisState},u.rangeState={...u.currentRangeState}),u.lastIdx=t.idx);let h=(v,E,A,C)=>{if(isNaN(A))return Object.assign(E,v),E.prevEma!==null?E.prevEma:NaN;let D=v.initCount,j=v.initSum,k=v.prevEma;if(D<C){if(j+=A,D++,E.initSum=j,E.initCount=D,E.prevEma=k,D===C){let W=j/C;return E.prevEma=W,W}return NaN}let V=2/(C+1),T=A*V+k*(1-V);return E.prevEma=T,E.initSum=j,E.initCount=D,T},p,d=t.get(t.data.high,0),f=t.get(t.data.low,0);if(l){let v=t.get(t.data.close,1);isNaN(v)?p=NaN:p=Math.max(d-f,Math.abs(d-v),Math.abs(f-v))}else p=d-f;let m=y.from(e).get(0),x=h(u.basisState,u.currentBasisState,m,a),b=h(u.rangeState,u.currentRangeState,p,a);if(isNaN(x)||isNaN(b))return NaN;if(x===0)return t.precision(0);let w=2*b*o/x;return t.precision(w)}}function Ad(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`linreg_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);let c=y.from(e).get(0),u=[...l.prevWindow];for(u.unshift(c);u.length>s;)u.pop();let h=l.prevCallCount+1;if(u.length<s&&(h>=s||t.idx>=s-1)){let E=y.from(e);for(;u.length<s;)u.push(E.get(u.length))}if(l.currentWindow=u,l.currentCallCount=h,u.length<s)return NaN;let p=0,d=0,f=0,m=0,x=s;for(let E=0;E<s;E++){let A=s-1-E,C=u[E];p+=A,d+=C,f+=A*C,m+=A*A}let b=x*m-p*p;if(b===0)return NaN;let w=(x*f-p*d)/b,v=(d-w*p)/x+w*(s-1-a);return t.precision(v)}}function Td(t){return(e,r,n)=>{typeof r=="string"&&n===void 0&&(n=r,r=e,e=t.data.low);let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`lowest_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let p=y.from(e);for(;l.length<i;)l.push(p.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.filter(p=>!isNaN(p)&&p!==void 0);if(u.length===0)return NaN;let h=Math.min(...u);return t.precision(h)}}function Dd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=1/0,o=NaN;for(let l=0;l<i;l++){let c=s.get(l);isNaN(c)||(isNaN(o)||c<a)&&(a=c,o=-l)}return o}}function Md(t){return(e,r,n,i,s)=>{let a=y.from(r).get(0),o=y.from(n).get(0),l=y.from(i).get(0),c=s||`macd_${a}_${o}_${l}`,u=`${c}_fast`,h=`${c}_slow`,p=`${c}_signal`,d=t.pine.ta.ema(e,a,u),f=t.pine.ta.ema(e,o,h),m=NaN;!isNaN(d)&&!isNaN(f)&&(m=d-f);let x=NaN;isNaN(m)||(x=t.pine.ta.ema(m,l,p));let b=NaN;return!isNaN(m)&&!isNaN(x)&&(b=m-x),[[t.precision(m),t.precision(x),t.precision(b)]]}}function Pd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`median_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let d=y.from(e);for(;l.length<i;)l.push(d.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.slice().sort((d,f)=>d-f),h=Math.floor(i/2),p=i%2===0?(u[h-1]+u[h])/2:u[h];return t.precision(p)}}function Rd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`mfi_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevUpperWindow=[...a.currentUpperWindow],a.prevLowerWindow=[...a.currentLowerWindow],a.prevUpperSum=a.currentUpperSum,a.prevLowerSum=a.currentLowerSum),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(e).get(1),c=t.get(t.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;let u=isNaN(l)?NaN:o-l,h=c*(u<=0?0:o),p=c*(u>=0?0:o),d=[...a.prevUpperWindow],f=[...a.prevLowerWindow],m=a.prevUpperSum,x=a.prevLowerSum;if(d.unshift(h),f.unshift(p),m+=h,x+=p,d.length<i)return a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=x,NaN;if(d.length>i){let w=d.pop(),v=f.pop();m-=w,x-=v}if(a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=x,x===0)return t.precision(100);if(m===0)return t.precision(0);let b=100-100/(1+m/x);return t.precision(b)}}function Fd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=new Map;for(let c=0;c<i;c++){let u=s.get(c);isNaN(u)||a.set(u,(a.get(u)||0)+1)}if(a.size===0)return NaN;let o=NaN,l=-1;for(let[c,u]of a.entries())u>l?(l=u,o=c):u===l&&c<o&&(o=c);return o}}function Bd(t){return(e,r,n)=>{let i=y.from(r).get(0);return t.pine.ta.change(e,i,n)}}function Ld(t){return e=>{t.taState||(t.taState={});let r=e||"nvi";t.taState[r]||(t.taState[r]={lastIdx:-1,committedNVI:1,tentativeNVI:1});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.committedNVI=n.tentativeNVI),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(i)?0:i,c=isNaN(s)?0:s,u=isNaN(a)?0:a,h=isNaN(o)?0:o,p=n.committedNVI;if(!(l===0||c===0)&&u<h){let d=(l-c)/c;p=p+d*p}return n.tentativeNVI=p,t.precision(p)}}function Od(t){return()=>{t.taState||(t.taState={});let e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});let r=t.taState[e];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedOBV=r.tentativeOBV),r.lastIdx=t.idx);let n=t.get(t.data.close,0),i=t.get(t.data.volume,0),s=t.get(t.data.close,1);if(isNaN(s))return r.tentativeOBV=0,t.precision(0);let a=r.committedOBV;return n>s?a+=i:n<s&&(a-=i),r.tentativeOBV=a,t.precision(a)}}function Vd(t){return(e,r,n)=>e instanceof y?r?new y(e.data,e.offset+r):e:(t.params[n]||(t.params[n]=[]),Array.isArray(e)?new y(e,r||0):(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,new y(t.params[n],r||0)))}function jd(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0),o=y.from(e);if(t.idx<s-1)return NaN;let l=[];for(let f=0;f<s;f++){let m=o.get(f);if(isNaN(m))return NaN;l.push(m)}l.sort((f,m)=>f-m);let c=a/100*s-.5;c<0&&(c=0),c>s-1&&(c=s-1);let u=Math.floor(c),h=Math.ceil(c);if(u===h)return t.precision(l[u]);let p=c-u,d=l[u]+p*(l[h]-l[u]);return t.precision(d)}}function $d(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0),o=y.from(e);if(t.idx<s-1)return NaN;let l=[];for(let u=0;u<s;u++){let h=o.get(u);isNaN(h)||l.push(h)}if(l.length===0)return NaN;l.sort((u,h)=>u-h);let c=Math.ceil(a/100*l.length)-1;return c<0&&(c=0),c>=l.length&&(c=l.length-1),t.precision(l[c])}}function Wd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);if(t.idx<i)return NaN;let a=s.get(0);if(isNaN(a))return NaN;let o=0,l=0;for(let c=1;c<=i;c++){let u=s.get(c);isNaN(u)||(l++,u<=a&&o++)}return l===0?NaN:t.precision(o/l*100)}}function Ud(t,e,r){let n=new Array(t.length).fill(NaN);for(let i=e+r;i<t.length;i++){let s=t[i-r],a=!0;for(let o=1;o<=e;o++)if(t[i-r-o]>=s){a=!1;break}if(a){for(let o=1;o<=r;o++)if(t[i-r+o]>=s){a=!1;break}}a&&(n[i]=s)}return n}function qd(t){return(e,r,n,i)=>{typeof n=="string"&&(n=r,r=e,e=t.data.high);let s=y.from(r).get(0),a=y.from(n).get(0),o=y.from(e).toArray(),l=Ud(o,s,a),c=t.idx;return t.precision(l[c])}}function zd(t,e,r){let n=new Array(t.length).fill(NaN);for(let i=e+r;i<t.length;i++){let s=t[i-r],a=!0;for(let o=1;o<=e;o++)if(t[i-r-o]<=s){a=!1;break}if(a){for(let o=1;o<=r;o++)if(t[i-r+o]<=s){a=!1;break}}a&&(n[i]=s)}return n}function Kd(t){return(e,r,n,i)=>{typeof n=="string"&&(n=r,r=e,e=t.data.low);let s=y.from(r).get(0),a=y.from(n).get(0),o=y.from(e).toArray(),l=zd(o,s,a),c=t.idx;return t.precision(l[c])}}function Hd(t){return e=>{t.taState||(t.taState={});let r=e||"pvi";t.taState[r]||(t.taState[r]={lastIdx:-1,committedPVI:1,tentativePVI:1});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.committedPVI=n.tentativePVI),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(i)?0:i,c=isNaN(s)?0:s,u=isNaN(a)?0:a,h=isNaN(o)?0:o,p=n.committedPVI;if(!(l===0||c===0)&&u>h){let d=(l-c)/c;p=p+d*p}return n.tentativePVI=p,t.precision(p)}}function Gd(t){return e=>{t.taState||(t.taState={});let r=e||"pvt";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=n.prevCumulativeSum;if(!isNaN(i)&&!isNaN(s)&&!isNaN(a)&&s!==0){let l=(i-s)/s*a;o+=l}return n.currentCumulativeSum=o,t.precision(o)}}function Yd(t){return(e,r,n)=>{let i=t.pine.ta.highest(e,r,(n||"range")+"_h"),s=t.pine.ta.lowest(e,r,(n||"range")+"_l");return isNaN(i)||isNaN(s)?NaN:t.precision(i-s)}}function Zd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);for(let a=0;a<i;a++){let o=s.get(a),l=s.get(a+1);if(isNaN(o)||isNaN(l)||o<=l)return!1}return!0}}function Xd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`rma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevRma=a.currentRma,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);let o=y.from(e).get(0)||0,l=a.prevInitCount,c=a.prevInitSum,u=a.prevRma;if(l<i){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===i){let d=c/i;return a.currentRma=d,t.precision(d)}return NaN}let h=1/i,p=o*h+u*(1-h);return a.currentRma=p,t.precision(p)}}function Qd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`roc_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i+1;)l.pop();let c=a.prevCallCount+1;if(l.length<i+1&&(c>=i+1||t.idx>=i)){let p=y.from(e);for(;l.length<i+1;)l.push(p.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=i)return NaN;let u=l[i],h=(o-u)/u*100;return t.precision(h)}}function Jd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`rsi_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevPrevValue=a.currentPrevValue,a.prevAvgGain=a.currentAvgGain,a.prevAvgLoss=a.currentAvgLoss,a.prevInitGains=[...a.currentInitGains],a.prevInitLosses=[...a.currentInitLosses]),a.lastIdx=t.idx);let o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=a.prevPrevValue;if(l===null||isNaN(l))return a.currentPrevValue=o,a.currentInitGains=[...a.prevInitGains],a.currentInitLosses=[...a.prevInitLosses],a.currentAvgGain=a.prevAvgGain,a.currentAvgLoss=a.prevAvgLoss,NaN;let c=a.prevAvgGain,u=a.prevAvgLoss,h=[...a.prevInitGains],p=[...a.prevInitLosses],d=o-l,f=d>0?d:0,m=d<0?-d:0;if(h.length<i){if(h.push(f),p.push(m),a.currentInitGains=h,a.currentInitLosses=p,a.currentPrevValue=o,h.length===i){c=h.reduce((w,v)=>w+v,0)/i,u=p.reduce((w,v)=>w+v,0)/i,a.currentAvgGain=c,a.currentAvgLoss=u;let b=u===0?100:100-100/(1+c/u);return t.precision(b)}return NaN}c=(c*(i-1)+f)/i,u=(u*(i-1)+m)/i,a.currentAvgGain=c,a.currentAvgLoss=u,a.currentPrevValue=o;let x=u===0?100:100-100/(1+c/u);return t.precision(x)}}function ef(t){return(e,r,n,i)=>{let s=y.from(e).get(0),a=y.from(r).get(0),o=y.from(n).get(0);t.taState||(t.taState={});let l=i||`sar_${s}_${a}_${o}`;t.taState[l]||(t.taState[l]={lastIdx:-1,prevResult:NaN,prevMaxMin:NaN,prevAcceleration:NaN,prevIsBelow:!1,prevBarIndex:0,currentResult:NaN,currentMaxMin:NaN,currentAcceleration:NaN,currentIsBelow:!1,currentBarIndex:0});let c=t.taState[l];t.idx>c.lastIdx&&(c.lastIdx>=0&&(c.prevResult=c.currentResult,c.prevMaxMin=c.currentMaxMin,c.prevAcceleration=c.currentAcceleration,c.prevIsBelow=c.currentIsBelow,c.prevBarIndex=c.currentBarIndex),c.lastIdx=t.idx);let u=c.prevResult,h=c.prevMaxMin,p=c.prevAcceleration,d=c.prevIsBelow,f=c.prevBarIndex,m=t.get(t.data.high,0),x=t.get(t.data.low,0),b=t.get(t.data.close,0),w=t.get(t.data.close,1),v=t.get(t.data.high,1),E=t.get(t.data.low,1),A=t.get(t.data.high,2),C=t.get(t.data.low,2);if(isNaN(m)||isNaN(x)||isNaN(b))return c.currentResult=u,c.currentMaxMin=h,c.currentAcceleration=p,c.currentIsBelow=d,c.currentBarIndex=f,NaN;let D=!1;return f===1&&(b>w?(d=!0,h=m,u=E):(d=!1,h=x,u=v),D=!0,p=s),f>=1&&(u=u+p*(h-u),d?u>x&&(D=!0,d=!1,u=Math.max(m,h),h=x,p=s):u<m&&(D=!0,d=!0,u=Math.min(x,h),h=m,p=s),D||(d?m>h&&(h=m,p=Math.min(p+a,o)):x<h&&(h=x,p=Math.min(p+a,o))),d?(u=Math.min(u,E),f>1&&(u=Math.min(u,C))):(u=Math.max(u,v),f>1&&(u=Math.max(u,A)))),f++,c.currentResult=u,c.currentMaxMin=h,c.currentAcceleration=p,c.currentIsBelow=d,c.currentBarIndex=f,f<=1?NaN:t.precision(u)}}function tf(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`sma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1,u=!1;if(l.length<i&&(c>=i||t.idx>=i-1)){let m=y.from(e);for(;l.length<i;)l.push(m.get(l.length));u=!0}let h,p=o==null||Number.isNaN(o),d=!Number.isNaN(a.prevSum)&&!p&&!u;if(d){let m=a.prevSum+o;if(a.prevWindow.length>=i){let x=a.prevWindow[a.prevWindow.length-1];x==null||Number.isNaN(x)?d=!1:m-=x}d&&(h=m)}if(!d){h=0;let m=!1;for(let x of l){if(x==null||Number.isNaN(x)){m=!0;break}h+=x}m&&(h=NaN)}if(a.currentWindow=l,a.currentSum=h,a.currentCallCount=c,l.length<i)return NaN;let f=h/i;return t.precision(f)}}function rf(t){return(e,r,n=!0,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`stdev_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum,l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);let c=y.from(e).get(0);if(c==null||isNaN(c))return NaN;let u=[...l.prevWindow],h=l.prevSum;for(u.unshift(c),h+=c;u.length>s;){let b=u.pop();h-=b}let p=l.prevCallCount+1;if(u.length<s&&(p>=s||t.idx>=s-1)){let b=y.from(e);for(;u.length<s;){let w=b.get(u.length);if(w==null||isNaN(w))break;u.push(w),h+=w}}if(l.currentWindow=u,l.currentSum=h,l.currentCallCount=p,u.length<s)return NaN;let d=h/s,f=0;for(let b=0;b<s;b++)f+=Math.pow(u[b]-d,2);let m=a?s:s-1,x=Math.sqrt(f/m);return t.precision(x)}}function nf(t){return(e,r,n,i,s)=>{let a=y.from(i).get(0);t.taState||(t.taState={});let o=s||`stoch_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow]),l.lastIdx=t.idx);let c=y.from(e).get(0),u=y.from(r).get(0),h=y.from(n).get(0);if(isNaN(c)||isNaN(u)||isNaN(h))return l.currentHighWindow=[...l.prevHighWindow],l.currentLowWindow=[...l.prevLowWindow],NaN;let p=[...l.prevHighWindow],d=[...l.prevLowWindow];if(p.unshift(u),d.unshift(h),p.length>a&&(p.pop(),d.pop()),l.currentHighWindow=p,l.currentLowWindow=d,p.length<a)return NaN;let f=p[0],m=d[0];for(let w=1;w<a;w++)p[w]>f&&(f=p[w]),d[w]<m&&(m=d[w]);let x=f-m;if(x===0)return NaN;let b=100*(c-m)/x;return t.precision(b)}}function sf(t){return(e,r,n)=>{let i=y.from(e).get(0),s=y.from(r).get(0);t.taState||(t.taState={});let a=n||`supertrend_${i}_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevTrSum:0,prevAtrValue:NaN,prevAtrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,currentTrSum:0,currentAtrValue:NaN,currentAtrCount:0,currentLowerBand:NaN,currentUpperBand:NaN,currentSuperTrend:NaN,currentDirection:NaN});let o=t.taState[a];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrSum=o.currentTrSum,o.prevAtrValue=o.currentAtrValue,o.prevAtrCount=o.currentAtrCount,o.prevLowerBand=o.currentLowerBand,o.prevUpperBand=o.currentUpperBand,o.prevSuperTrend=o.currentSuperTrend,o.prevDirection=o.currentDirection),o.lastIdx=t.idx);let l=t.get(t.data.high,0),c=t.get(t.data.low,0),u=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(u))return[[NaN,NaN]];let h=(l+c)/2,p=t.idx>0?t.get(t.data.close,1):NaN,d;isNaN(p)?d=l-c:d=Math.max(l-c,Math.abs(l-p),Math.abs(c-p));let f=o.prevAtrCount,m=o.prevTrSum,x=o.prevAtrValue;f++,f<=s?(m+=d,f===s&&(x=m/s)):x=(x*(s-1)+d)/s;let b=x;if(o.currentAtrCount=f,o.currentTrSum=m,o.currentAtrValue=x,isNaN(b))return[[NaN,NaN]];let w=h+i*b,v=h-i*b,E=isNaN(o.prevLowerBand)?0:o.prevLowerBand,A=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||v>E||p<E||(v=E),isNaN(o.prevUpperBand)||w<A||p>A||(w=A);let C,D,j=o.prevSuperTrend;return f===s?C=1:j===o.prevUpperBand?C=u>w?-1:1:C=u<v?1:-1,D=C===-1?v:w,o.currentLowerBand=v,o.currentUpperBand=w,o.currentSuperTrend=D,o.currentDirection=C,[[t.precision(D),C]]}}function af(t){return(e,r)=>{let n=[1,2,2,1],i=6;t.taState||(t.taState={});let s=r||"swma";t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],currentWindow:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>4;)l.pop();if(l.length<4&&t.idx>=3){let u=y.from(e);for(;l.length<4;)l.push(u.get(l.length))}if(a.currentWindow=l,l.length<4)return NaN;let c=0;for(let u=0;u<4;u++)c+=n[u]*l[3-u];return c/=i,t.precision(c)}}function of(t){return(e,r)=>{let n=!0;typeof e=="string"||e!==void 0&&(n=y.from(e).get(0));let i=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.close,1);if(isNaN(a))return n?t.precision(i-s):NaN;let o=Math.max(i-s,Math.abs(i-a),Math.abs(s-a));return t.precision(o)}}function lf(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`tsi_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevSource:NaN,prevEma1PcValue:NaN,prevEma1PcCount:0,prevEma1PcSum:0,prevEma2PcValue:NaN,prevEma2PcCount:0,prevEma2PcSum:0,prevEma1AbsValue:NaN,prevEma1AbsCount:0,prevEma1AbsSum:0,prevEma2AbsValue:NaN,prevEma2AbsCount:0,prevEma2AbsSum:0,currentSource:NaN,currentEma1PcValue:NaN,currentEma1PcCount:0,currentEma1PcSum:0,currentEma2PcValue:NaN,currentEma2PcCount:0,currentEma2PcSum:0,currentEma1AbsValue:NaN,currentEma1AbsCount:0,currentEma1AbsSum:0,currentEma2AbsValue:NaN,currentEma2AbsCount:0,currentEma2AbsSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevSource=l.currentSource,l.prevEma1PcValue=l.currentEma1PcValue,l.prevEma1PcCount=l.currentEma1PcCount,l.prevEma1PcSum=l.currentEma1PcSum,l.prevEma2PcValue=l.currentEma2PcValue,l.prevEma2PcCount=l.currentEma2PcCount,l.prevEma2PcSum=l.currentEma2PcSum,l.prevEma1AbsValue=l.currentEma1AbsValue,l.prevEma1AbsCount=l.currentEma1AbsCount,l.prevEma1AbsSum=l.currentEma1AbsSum,l.prevEma2AbsValue=l.currentEma2AbsValue,l.prevEma2AbsCount=l.currentEma2AbsCount,l.prevEma2AbsSum=l.currentEma2AbsSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return NaN;let u=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(u))return NaN;let h=Math.abs(u),p=2/(a+1),d=2/(s+1),f=2/(a+1),m=2/(s+1),x=l.prevEma1PcCount,b=l.prevEma1PcSum,w=l.prevEma1PcValue;x++,x<=a?(b+=u,x===a&&(w=b/a)):w=u*p+w*(1-p);let v=l.prevEma1AbsCount,E=l.prevEma1AbsSum,A=l.prevEma1AbsValue;if(v++,v<=a?(E+=h,v===a&&(A=E/a)):A=h*f+A*(1-f),isNaN(w)||isNaN(A))return l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=w,l.currentEma1AbsCount=v,l.currentEma1AbsSum=E,l.currentEma1AbsValue=A,NaN;let C=l.prevEma2PcCount,D=l.prevEma2PcSum,j=l.prevEma2PcValue;C++,C<=s?(D+=w,C===s&&(j=D/s)):j=w*d+j*(1-d);let k=l.prevEma2AbsCount,V=l.prevEma2AbsSum,T=l.prevEma2AbsValue;if(k++,k<=s?(V+=A,k===s&&(T=V/s)):T=A*m+T*(1-m),l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=w,l.currentEma1AbsCount=v,l.currentEma1AbsSum=E,l.currentEma1AbsValue=A,l.currentEma2PcCount=C,l.currentEma2PcSum=D,l.currentEma2PcValue=j,l.currentEma2AbsCount=k,l.currentEma2AbsSum=V,l.currentEma2AbsValue=T,isNaN(j)||isNaN(T))return NaN;if(T===0)return t.precision(0);let W=j/T;return t.precision(W)}}function cf(t){return(e,r,n,i)=>{t.taState||(t.taState={});let s=i||"valuewhen";t.taState[s]||(t.taState[s]={lastIdx:-1,prevValues:[],currentValues:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevValues=[...a.currentValues]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(r).get(0),c=y.from(n).get(0),u=[...a.prevValues];if(o&&u.push(l),a.currentValues=u,isNaN(c)||c<0)return NaN;let h=u.length-1-c;if(h<0)return NaN;let p=u[h];return typeof p=="number"?t.precision(p):p}}function uf(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`variance_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let f=y.from(e);for(;l.length<i;)l.push(f.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=0,h=0;for(let f=0;f<i;f++)u+=l[f],h+=l[f]*l[f];let p=u/i,d=h/i-p*p;return t.precision(d)}}function pf(t){return(e,r)=>{t.taState||(t.taState={});let n=r||"vwap";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentLastSessionDate:null});let i=t.taState[n];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevCumulativePV=i.currentCumulativePV,i.prevCumulativeVolume=i.currentCumulativeVolume,i.prevLastSessionDate=i.currentLastSessionDate),i.lastIdx=t.idx);let s=y.from(e).get(0),a=y.from(t.data.volume).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.timezone||"UTC",c=Zt(o,l),u=`${c.year}-${String(c.month).padStart(2,"0")}-${String(c.day).padStart(2,"0")}`,h=i.prevCumulativePV,p=i.prevCumulativeVolume,d=i.prevLastSessionDate;if(d!==u&&(h=0,p=0,d=u),h+=s*a,p+=a,i.currentCumulativePV=h,i.currentCumulativeVolume=p,i.currentLastSessionDate=d,p===0)return NaN;let f=h/p;return t.precision(f)}}function hf(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`vwma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevVolumeWindow:[],currentWindow:[],currentVolumeWindow:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevVolumeWindow=[...a.currentVolumeWindow]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=t.get(t.data.volume,0),c=[...a.prevWindow],u=[...a.prevVolumeWindow];for(c.unshift(o),u.unshift(l);c.length>i;)c.pop(),u.pop();if(c.length<i&&t.idx>=i-1){let f=y.from(e),m=y.from(t.data.volume);for(;c.length<i;)c.push(f.get(c.length)),u.push(m.get(u.length))}if(a.currentWindow=c,a.currentVolumeWindow=u,c.length<i)return NaN;let h=0,p=0;for(let f=0;f<i;f++)h+=c[f]*u[f],p+=u[f];let d=h/p;return t.precision(d)}}function df(t){return e=>{t.taState||(t.taState={});let r=e||"wad";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),o=t.get(t.data.close,1);if(isNaN(i)||isNaN(s)||isNaN(a))return n.currentCumulativeSum=n.prevCumulativeSum,t.precision(n.prevCumulativeSum);let l=0;if(!isNaN(o)){let u=Math.max(s,o),h=Math.min(a,o),p=i-o;p>0?l=i-h:p<0&&(l=i-u)}let c=n.prevCumulativeSum+l;return n.currentCumulativeSum=c,t.precision(c)}}function ff(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`wma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let d=y.from(e);for(;l.length<i;)l.push(d.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=0,h=0;for(let d=0;d<i;d++){let f=i-d;u+=l[d]*f,h+=f}let p=u/h;return t.precision(p)}}function mf(t){return(e,r)=>{let n=y.from(e).get(0);t.taState||(t.taState={});let i=r||`wpr_${n}`;t.taState[i]||(t.taState[i]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});let s=t.taState[i];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevHighWindow=[...s.currentHighWindow],s.prevLowWindow=[...s.currentLowWindow]),s.lastIdx=t.idx);let a=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(l))return s.currentHighWindow=[...s.prevHighWindow],s.currentLowWindow=[...s.prevLowWindow],NaN;let c=[...s.prevHighWindow],u=[...s.prevLowWindow];if(c.unshift(a),u.unshift(o),c.length>n&&(c.pop(),u.pop()),s.currentHighWindow=c,s.currentLowWindow=u,c.length<n)return NaN;let h=c[0],p=u[0];for(let m=1;m<n;m++)c[m]>h&&(h=c[m]),u[m]<p&&(p=u[m]);let d=h-p;if(d===0)return t.precision(0);let f=(h-l)/d*-100;return t.precision(f)}}function yf(t){return e=>{let r=t.get(t.data.close,0),n=t.get(t.data.open,0),i=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(r)||isNaN(n)||isNaN(i)||isNaN(s)||isNaN(a))return NaN;let o=i-s;if(o===0)return t.precision(0);let l=(r-n)/o*a;return t.precision(l)}}var gf=Object.defineProperty,_f=(t,e,r)=>e in t?gf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,F=(t,e,r)=>_f(t,typeof e!="symbol"?e+"":e,r),xf={accdist:id,alma:sd,atr:ad,barssince:od,bb:ld,bbw:cd,cci:ud,change:pd,cmo:hd,cog:dd,correlation:fd,cross:md,crossover:yd,crossunder:gd,cum:_d,dev:xd,dmi:bd,ema:vd,falling:wd,highest:Ed,highestbars:Sd,hma:Cd,iii:Nd,kc:kd,kcw:Id,linreg:Ad,lowest:Td,lowestbars:Dd,macd:Md,median:Pd,mfi:Rd,mode:Fd,mom:Bd,nvi:Ld,obv:Od,param:Vd,percentile_linear_interpolation:jd,percentile_nearest_rank:$d,percentrank:Wd,pivothigh:qd,pivotlow:Kd,pvi:Hd,pvt:Gd,range:Yd,rising:Zd,rma:Xd,roc:Qd,rsi:Jd,sar:ef,sma:tf,stdev:rf,stoch:nf,supertrend:sf,swma:af,tr:of,tsi:lf,valuewhen:cf,variance:uf,vwap:pf,vwma:hf,wad:df,wma:ff,wpr:mf,wvad:yf},Ci=class{constructor(e){this.context=e,F(this,"accdist"),F(this,"alma"),F(this,"atr"),F(this,"barssince"),F(this,"bb"),F(this,"bbw"),F(this,"cci"),F(this,"change"),F(this,"cmo"),F(this,"cog"),F(this,"correlation"),F(this,"cross"),F(this,"crossover"),F(this,"crossunder"),F(this,"cum"),F(this,"dev"),F(this,"dmi"),F(this,"ema"),F(this,"falling"),F(this,"highest"),F(this,"highestbars"),F(this,"hma"),F(this,"iii"),F(this,"kc"),F(this,"kcw"),F(this,"linreg"),F(this,"lowest"),F(this,"lowestbars"),F(this,"macd"),F(this,"median"),F(this,"mfi"),F(this,"mode"),F(this,"mom"),F(this,"nvi"),F(this,"obv"),F(this,"param"),F(this,"percentile_linear_interpolation"),F(this,"percentile_nearest_rank"),F(this,"percentrank"),F(this,"pivothigh"),F(this,"pivotlow"),F(this,"pvi"),F(this,"pvt"),F(this,"range"),F(this,"rising"),F(this,"rma"),F(this,"roc"),F(this,"rsi"),F(this,"sar"),F(this,"sma"),F(this,"stdev"),F(this,"stoch"),F(this,"supertrend"),F(this,"swma"),F(this,"tr"),F(this,"tsi"),F(this,"valuewhen"),F(this,"variance"),F(this,"vwap"),F(this,"vwma"),F(this,"wad"),F(this,"wma"),F(this,"wpr"),F(this,"wvad"),Object.entries(xf).forEach(([r,n])=>{this[r]=n(e)})}};function bf(t){if(t.length===0)return{};if(typeof t[0]=="object"&&t[0]!==null)return t[0];let e={};typeof t[0]=="string"&&(e.title=t[0]);let r=null;for(let n=1;n<t.length;n++){let i=t[n];typeof i=="string"?e.shorttitle===void 0&&(e.shorttitle=i):typeof i=="object"&&i!==null&&(r=i)}return r&&Object.assign(e,r),e}function Cr(t,e,r){if(!r||r<=0||!Number.isFinite(t)||t===e)return t;let n=t/r,i=1e-9;return t>e?Math.ceil(n-i)*r:Math.floor(n+i)*r}function mn(t,e,r,n){return Math.abs(t)*e*n*r/100}function vf(t,e){let r=t.strategy,n=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of $n(r)){let a=s.dir===1?e-s.entry_price:s.entry_price-e;i+=a*s.qty*n}return r.initial_capital+r.netprofit+i}function wf(t,e){let r=t.strategy,n=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of r.opentrades){let a=Math.sign(s.size)===1?r.config.margin_long??100:r.config.margin_short??100;i+=mn(s.size,e,a,n)}return i}function us(t,e,r,n){let i=t.strategy,s=i.config.default_qty_type||"fixed",a=i.config.default_qty_value||1;typeof s=="function"&&(s=s()),typeof a=="function"&&(a=a());let o=1e6,l=u=>Math.floor(u*o)/o;if(e!=null)return l(Math.abs(e));let c;switch(s){case"fixed":c=a;break;case"cash":c=a/n;break;case"percent_of_equity":{c=i.equity*a/100/n;break}default:c=a}return l(c)}function Ef(t){if(!t.strategy)return;let e=t.strategy,{pending_orders:r}=e,n=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.pointvalue??1;for(let c of e.opentrades){let u=Math.abs(c.size),h=c.size>0,p=c.commission??0,d=h?(c.entry_price-s)*u*l:(i-c.entry_price)*u*l,f=h?(i-c.entry_price)*u*l:(c.entry_price-s)*u*l,m=Math.max(0,d)+p,x=Math.max(0,f-p);m>(c.max_drawdown??0)&&(c.max_drawdown=m),x>(c.max_runup??0)&&(c.max_runup=x)}yn(t,n);for(let c of r){if(c.status!=="pending"||(c.category??"entry")==="exit"||c.bar>=t.idx)continue;let u=!1,h=n;switch(c.type){case"market":u=!0,h=n;break;case"limit":if(c.limit!==void 0){let p=Vt(c.direction);(p===1&&s<=c.limit||p===-1&&i>=c.limit)&&(u=!0,h=c.limit)}break;case"stop":if(c.stop!==void 0){let p=Vt(c.direction);(p===1&&i>=c.stop||p===-1&&s<=c.stop)&&(u=!0,h=c.stop)}break}if(u){if(Cf(e,c)){c.status="cancelled";continue}let p=Vt(c.direction);h=Ni(t,p,h);let d=p===1?e.config.margin_long??100:e.config.margin_short??100;{let f=e.position_size,m=Math.sign(f),x=m!==0&&m!==p,b=x?Math.max(0,c.qty-Math.abs(f)):c.qty;if(b>0){let w=t.pine?.syminfo?.pointvalue??1,v=0;m===p&&(v=wf(t,n));let E=e.equity-v;if(mn(b,h,d,w)>E){let A=Math.min(Math.abs(f),c.qty);x&&A>0?(Yt(t,A,h,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=h,c.fill_bar=t.idx,c.fill_time=o):c.status="cancelled";continue}}}kf(t,c,h,o),c.status="filled",c.fill_price=h,c.fill_bar=t.idx,c.fill_time=o}}e.pending_orders=r.filter(c=>c.status==="pending"),yn(t,a),Of(t)}function Vt(t){return typeof t=="number"?t:t==="long"?1:t==="short"?-1:0}function Ya(t,e,r,n){let i=e.config.commission_type??"percent",s=e.config.commission_value??0;if(!s||s===0)return 0;let a=t.pine?.syminfo?.pointvalue??1;switch(i){case"percent":return Math.abs(r)*n*a*(s/100);case"cash_per_contract":return Math.abs(r)*s;case"cash_per_order":return s;default:return 0}}function Ni(t,e,r){let n=t.strategy.config.slippage??0;if(!n||n===0)return r;let i=t.pine?.syminfo?.mintick??.01,s=n*i;return e===1?r+s:r-s}function Za(t){let e=Math.abs(t.position_size);e>t.max_contracts_held_all&&(t.max_contracts_held_all=e),t.position_size>t.max_contracts_held_long&&(t.max_contracts_held_long=t.position_size),-t.position_size>t.max_contracts_held_short&&(t.max_contracts_held_short=-t.position_size)}function Sf(t,e){let r=t.config.pyramiding??1,n=0;for(let i of t.opentrades)Math.sign(i.size)===e&&n++;return n>=r}function Cf(t,e){if(t.risk_halted)return!0;let r=t.risk_rules,n=e.direction;if(r.allow_entry_in&&(r.allow_entry_in==="long"&&n===-1||r.allow_entry_in==="short"&&n===1))return!0;if(r.max_position_size!==void 0){let i=t.position_size+n*e.qty;if(Math.abs(i)>r.max_position_size)return!0}return!1}function Nf(t){if(t.risk_halted)return;let e=t.risk_rules;if(e.max_drawdown){let r=e.max_drawdown.type==="percent_of_equity"?e.max_drawdown.value/100*t.equity_peak:e.max_drawdown.value;if(t.max_drawdown>=r){t.risk_halted=!0;return}}if(e.max_intraday_loss){let r=e.max_intraday_loss.type==="percent_of_equity"?e.max_intraday_loss.value/100*t.initial_capital:e.max_intraday_loss.value;if(t.grossloss>=r){t.risk_halted=!0;return}}if(e.max_cons_loss_days){let r=0;for(let n=t.closedtrades.length-1;n>=0&&(t.closedtrades[n].profit??0)<0;n--)r++;r>=e.max_cons_loss_days.count&&(t.risk_halted=!0)}}function Gr(t,e,r,n,i,s,a,o){let l=t.strategy,c=l.opentrades.length+l.closedtrades.length,u=l.config.commission_type??"percent",h=o&&u==="cash_per_order",p=Ya(t,l,n,i),d=h?p/2:p,f={id:`trade_${c}`,entry_id:e,entry_comment:a??e,entry_price:i,_bracket_entry:i,entry_bar_index:t.idx,entry_time:s,size:r*n,commission:d,max_drawdown:0,max_runup:0,status:"open"};l.opentrades.push(f),l._first_entry_price===void 0&&(l._first_entry_price=i),(l._ledger_entries??(l._ledger_entries=[])).push({entry_id:e,entry_price:i,entry_time:s,entry_bar_index:t.idx,entry_comment:f.entry_comment,qty:n,commission:d}),d>0&&(l.netprofit-=d,l.grossloss+=d);let m=y.from(t.data.high).get(0),x=y.from(t.data.low).get(0),b=t.pine?.syminfo?.mintick??.01,w=r===1?x:m,v=r===1?m:x;for(let k of l.pending_orders){if((k.category??"entry")!=="exit"||k.from_entry&&k.from_entry!==e)continue;let V;k.stop!==void 0?V=k.stop:k.loss!==void 0&&(V=r===1?i-k.loss*b:i+k.loss*b);let T;k.limit!==void 0?T=k.limit:k.profit!==void 0&&(T=r===1?i+k.profit*b:i-k.profit*b),r===1?(V!==void 0&&V>w&&(w=V),T!==void 0&&T<v&&(v=T)):(V!==void 0&&V<w&&(w=V),T!==void 0&&T>v&&(v=T))}let E=t.pine?.syminfo?.pointvalue??1,A=r===1?(i-w)*n*E:(w-i)*n*E,C=r===1?(v-i)*n*E:(i-v)*n*E;f.max_drawdown=Math.max(0,A)+d,f.max_runup=Math.max(0,C-d);let D=l.position_size,j=D+f.size;if(D===0)l.position_size=j,l.position_avg_price=i,l.position_entry_name=e;else if(Math.sign(D)===Math.sign(j)){let k=Math.abs(D)*l.position_avg_price+n*i,V=Math.abs(j);l.position_avg_price=k/V,l.position_size=j}Za(l)}function kf(t,e,r,n){let i=t.strategy,s=Vt(e.direction),a=i.position_size,o=Math.sign(a);if(o===1&&s===-1||o===-1&&s===1){let l=Math.min(Math.abs(a),e.qty),c=e.qty-l,u=c>0;if(Yt(t,l,r,n,{exitId:e.id,exitComment:e.comment,isImplicitReversal:u}),c>0){let h=e._base_qty;h!==void 0&&c>h+1e-9?(Gr(t,e.id,s,h,r,n,e.comment,!0),Gr(t,e.id,s,c-h,r,n,e.comment,!0)):Gr(t,e.id,s,c,r,n,e.comment,!0)}}else Gr(t,e.id,s,e.qty,r,n,e.comment)}function If(t,e,r){let n=[],i=r,s=t._ledger_entries??[];for(let a of s){if(i<=1e-9)break;if(a.entry_id!==e.entry_id||a.qty<=1e-9)continue;let o=Math.min(a.qty,i),l=a.qty>0?a.commission*(o/a.qty):0;n.push({qty:o,entry_price:a.entry_price,entry_time:a.entry_time,entry_bar_index:a.entry_bar_index,entry_comment:a.entry_comment,commission:l}),a.qty-=o,a.commission-=l,i-=o}if(t._ledger_entries=s.filter(a=>a.qty>1e-9),i>1e-9){let a=Math.abs(e.size);n.push({qty:i,entry_price:e.entry_price,entry_time:e.entry_time,entry_bar_index:e.entry_bar_index,entry_comment:e.entry_comment,commission:a>0?(e.commission??0)*(i/a):0})}return n}function Yt(t,e,r,n,i){let s=t.strategy,a=t.pine?.syminfo?.pointvalue??1,o=e,l=[...s.opentrades];s.opentrades=[];for(let p of l){if(o<=0){s.opentrades.push(p);continue}let d=Math.abs(p.size),f=Math.min(d,o),m=Math.sign(p.size),x=b=>{let w=s.config.commission_type??"percent",v=i?.isImplicitReversal&&w==="cash_per_order",E=Ya(t,s,b,r),A=v?E/2:E,C=If(s,p,b);for(let D of C){let j=A*(D.qty/b),k=(m===1?r-D.entry_price:D.entry_price-r)*D.qty*a,V={id:`trade_${s.opentrades.length+s.closedtrades.length+l.length}`,entry_id:p.entry_id,entry_comment:D.entry_comment,entry_price:D.entry_price,_bracket_entry:p._bracket_entry,entry_bar_index:D.entry_bar_index,entry_time:D.entry_time,size:m*D.qty,commission:D.commission+j,max_drawdown:p.max_drawdown,max_runup:p.max_runup,status:"closed",exit_price:r,exit_bar_index:t.idx,exit_time:n,exit_id:i?.exitId??p.exit_id,exit_comment:i?.exitComment??p.exit_comment,profit:k-D.commission-j};i?.triggerKind==="loss"&&(V.max_runup=0),i?.triggerKind==="profit"&&(V.max_drawdown=D.commission),s.netprofit+=k-j,s.grossloss-=D.commission,V.profit>0?(s.grossprofit+=V.profit,s.wintrades++,s.wintrades_total_profit+=V.profit):V.profit<0?(s.grossloss+=Math.abs(V.profit),s.losstrades++,s.losstrades_total_loss+=Math.abs(V.profit)):s.eventrades++,s.closedtrades.push(V)}};if(f>=d-1e-9)p.status="closed",p.exit_price=r,p.exit_bar_index=t.idx,p.exit_time=n,x(d),o-=f;else{x(f);let b=(p.commission??0)*(f/d);p.size=m*(d-f),p.commission=(p.commission??0)-b,s.opentrades.push(p),o=0}}Nf(s);let c=s.position_size,u=Math.sign(c)*e,h=c-u;if(Math.abs(h)<1e-9&&(h=0),s.position_size=h,Za(s),h===0)s.position_avg_price=NaN,s.position_entry_name="";else if(s.opentrades.length>0){let p=0,d=0;for(let f of $n(s))p+=f.qty*f.entry_price,d+=f.qty;s.position_avg_price=p/d,s.position_entry_name=s.opentrades[0].entry_id}}function $n(t){let e=t._ledger_entries??[],r=Math.sign(t.position_size)||1;return e.length>0?e.map(n=>({qty:n.qty,entry_price:n.entry_price,commission:n.commission,dir:r})):t.opentrades.map(n=>({qty:Math.abs(n.size),entry_price:n.entry_price,commission:n.commission??0,dir:Math.sign(n.size)}))}function yn(t,e){let r=t.strategy,n=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of $n(r)){let a=s.dir===1?e-s.entry_price:s.entry_price-e;i+=a*s.qty*n}r.openprofit=i,r.equity=r.initial_capital+r.netprofit+i}function Af(t,e,r){let n=t.strategy,i=t.pine?.syminfo?.pointvalue??1,s=n.initial_capital+n.netprofit,a=0;for(let f of $n(n))a+=f.commission;let o=s+a;o>n.equity_peak&&(n.equity_peak=o),s<n.equity_trough&&(n.equity_trough=s);let l=n.position_size,c=n.position_avg_price,u=0,h=0;if(l!==0&&Number.isFinite(c)){let f=l>0?r:e,m=l>0?e:r;u=l*(c-f)*i,h=l*(m-c)*i}let p=n.equity_peak-s+u;if(p>n.max_drawdown&&(n.max_drawdown=p,n.equity_at_drawdown_peak=n.equity_peak,n.equity_peak>0)){let f=100*p/n.equity_peak;f>n.max_drawdown_percent_value&&(n.max_drawdown_percent_value=f)}let d=s-n.equity_trough+h;if(d>n.max_runup&&(n.max_runup=d,n.equity_at_runup_peak=s+h,n.equity_at_runup_peak>0)){let f=100*d/n.equity_at_runup_peak;f>n.max_runup_percent_value&&(n.max_runup_percent_value=f)}}function Gs(t,e,r,n,i,s,a){let o=t.strategy;if(a!==void 0){let p=[],d=[];for(let m of o.opentrades)m.id===a?p.push(m):d.push(m);if(p.length===0)return;let f=Math.abs(p[0].size);o.opentrades=[...p,...d],Yt(t,Math.min(r,f),n,i,s);return}if(!e||e===""){Yt(t,r,n,i,s);return}let l=[],c=[];for(let p of o.opentrades)p.entry_id===e?l.push(p):c.push(p);let u=l.reduce((p,d)=>p+Math.abs(d.size),0);if(u===0)return;let h=Math.min(r,u);o.opentrades=[...l,...c],Yt(t,h,n,i,s)}function Tf(t,e="intrabar"){if(!t.strategy)return;let r=t.strategy;if(r.pending_orders.length===0)return;let n=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.mintick??.01;for(let c of r.pending_orders){if(c.status!=="pending"||(c.category??"entry")!=="exit")continue;let u=r.opentrades.filter(T=>!c.from_entry||T.entry_id===c.from_entry);if(c._intended_trade_ids){let T=new Set(c._intended_trade_ids);u=u.filter(W=>T.has(W.id))}if(u.length===0){e==="intrabar"&&(c.status="cancelled");continue}let h=u.reduce((T,W)=>T+Math.abs(W.size),0),p=Math.sign(u[0].size);if(c.type==="market"&&c.profit===void 0&&c.loss===void 0&&c.limit===void 0&&c.stop===void 0&&c.trail_price===void 0&&c.trail_points===void 0){if(e==="open"||c.bar>=t.idx)continue;let T=c.immediately?a:n;T=Ni(t,-p,T);let W=h;c.qty&&c.qty>0?W=Math.min(c.qty,h):c.qty_percent&&c.qty_percent>0&&(W=h*(c.qty_percent/100)),Gs(t,c.from_entry,W,T,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=T,c.fill_bar=t.idx,c.fill_time=o;continue}let d=0;for(let T of u)d+=Math.abs(T.size)*T.entry_price;let f=d/h,m=p===1,x=c.limit,b=c.stop;c._isPersistent||(b!==void 0&&((m?b<f:b>f)||(b=void 0)),x!==void 0&&((m?x>f:x<f)||(x=void 0))),c._attachedAtReversal&&!c._isPersistent&&(c.limit!==void 0&&(x=void 0),c.stop!==void 0&&(b=void 0));let w=!1;if(e==="intrabar"&&!c.trail_armed&&(c.trail_price!==void 0||c.trail_points!==void 0)){let T;c.trail_price!==void 0?T=c.trail_price:c.trail_points!==void 0&&(T=m?f+c.trail_points*l:f-c.trail_points*l),T!==void 0&&(m?i>=T:s<=T)&&(c.trail_armed=!0,c.trail_peak=m?i:s,w=!0)}let v=Math.abs(i-n)<=Math.abs(n-s),E=m?v:!v,A=[],C=[],D=r._mc_exit_lock,j=D&&D.bar===t.idx;for(let T of u){if(j&&T.id!==D.tradeId)continue;let W=T._bracket_entry??T.entry_price,R=Math.abs(T.size),M=x;M===void 0&&c.profit!==void 0&&(M=m?W+c.profit*l:W-c.profit*l);let H=b;H===void 0&&c.loss!==void 0&&(H=m?W-c.loss*l:W+c.loss*l);let ee=M!==void 0&&(e==="open"?m?n>=M:n<=M:m?i>=M:s<=M),we=H!==void 0&&(e==="open"?m?n<=H:n>=H:m?s<=H:i>=H),se=null;if(ee&&we?se=E?"profit":"loss":ee?se="profit":we&&(se="loss"),se==="loss"){let Fe=m?n<=H:n>=H;!m&&Fe&&T.entry_bar_index===t.idx?ee&&(se="profit"):C.push({qty:R,price:Fe?n:H,kind:"loss",tradeId:T.id})}if(se==="profit"){let Fe=m?n>=M:n<=M;A.push({qty:R,price:Fe?n:M,kind:"profit",tradeId:T.id})}}A.sort((T,W)=>m?T.price-W.price:W.price-T.price),C.sort((T,W)=>m?W.price-T.price:T.price-W.price);let k=null;if(e==="intrabar"&&!j&&c.trail_armed&&c.trail_offset!==void 0){let T=()=>{m?c.trail_peak=Math.max(c.trail_peak??-1/0,i):c.trail_peak=Math.min(c.trail_peak??1/0,s)},W=()=>m?c.trail_peak-c.trail_offset*l:c.trail_peak+c.trail_offset*l,R=M=>{k={qty:1/0,price:M,kind:"trailing"}};if(w){let M=W();E?(m?s<=M:i>=M)&&R(M):(m?a<=M:a>=M)&&R(M)}else if(E){T();let M=W();(m?s<=M:i>=M)&&R(M)}else{let M=W();if(m?s<=M:i>=M)R(M);else{T();let H=W();(m?a<=H:a>=H)&&R(H)}}}let V=E?[...A,...C,...k?[k]:[]]:[...C,...k?[k]:[],...A];if(V.length>0){let T=h;c.qty&&c.qty>0?T=Math.min(c.qty,h):c.qty_percent&&c.qty_percent>0&&(T=h*(c.qty_percent/100));let W=()=>r.opentrades.filter(H=>!c.from_entry||H.entry_id===c.from_entry).reduce((H,ee)=>H+Math.abs(ee.size),0),R=NaN,M=!1;for(let H of V){if(T<=1e-9)break;let ee=W();if(ee<=1e-9)break;let we=Math.min(H.qty===1/0?ee:H.qty,T,ee),se=Ni(t,-p,H.price),Fe=H.kind==="profit"?c.comment_profit??c.comment:H.kind==="loss"?c.comment_loss??c.comment:c.comment_trailing??c.comment;Gs(t,c.from_entry,we,se,o,{triggerKind:H.kind,exitId:c.id,exitComment:Fe},H.tradeId),T-=we,R=se,M=!0}M&&(W()<=1e-9||T<=1e-9)&&(c.status="filled",c.fill_price=R,c.fill_bar=t.idx,c.fill_time=o)}}r.pending_orders=r.pending_orders.filter(c=>c.status==="pending"),yn(t,a)}function Df(t){let e=t.strategy;if(!e)return;let r=e._pending_close_mc;if(r&&(e._pending_close_mc=null,!(e.opentrades.length===0||Math.sign(e.position_size)!==r.dir)&&(Yt(t,Math.min(r.qty,Math.abs(e.position_size)),r.price,r.time,{exitId:"Margin call",exitComment:"Margin call"}),Math.abs(e.position_size)>1e-9))){for(let n of e.pending_orders)n.status==="pending"&&(n.category??"entry")==="entry"&&!n._isReversalEntry&&Vt(n.direction)===r.dir&&(n.status="cancelled");e.pending_orders=e.pending_orders.filter(n=>n.status==="pending")}}function Mf(t){let e=t.strategy,r=Math.sign(e?.position_size??0);if(r===0)return!1;let n=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=Math.abs(i-n)<=Math.abs(n-s);return r===1?!a:a}function ri(t,e="extreme"){let r=t.strategy;if(!r||r.opentrades.length===0)return;let n=Math.sign(r.position_size);if(n===0)return;let i=n===1?r.config.margin_long??100:r.config.margin_short??100,s=y.from(t.data.open).get(0),a=y.from(t.data.high).get(0),o=y.from(t.data.low).get(0),l=y.from(t.data.close).get(0),c=y.from(t.data.openTime).get(0),u=t.pine?.syminfo?.pointvalue??1,h=e==="open"?s:e==="close"?l:n===1?o:a,p=Math.abs(r.position_size),d=vf(t,h),f=mn(p,h,i,u);if(d<f){let m=f-d,x=i/100,b=m/(h*u*x),w=Math.min(p,4*b),v=[...r.opentrades],E=v[0],A=Math.abs(E.size),C=E.entry_price;if(Yt(t,w,h,c,{exitId:"Margin call",exitComment:"Margin call"}),e==="extreme"&&w>=A-1e-9&&Math.abs(r.position_size)>1e-9){let j=mn(A,h,i,u),k=A*(h-C)*n*u,V=m-j+k;if(V>0){let T=y.from(t.data.close).get(0),W=(M=>Math.trunc(M*1e6)/1e6)(V/(h*u*x)),R=Math.min(Math.abs(r.position_size),4*W);R>1e-9&&(r._pending_close_mc={qty:R,price:T,time:c,dir:n})}}let D=v.find(j=>j.status==="open");r._mc_exit_lock={bar:t.idx,tradeId:D?.id??null}}}function Pf(t){if(!t.strategy)return;let e=t.strategy,r=y.from(t.data.high).get(0),n=y.from(t.data.low).get(0),i=y.from(t.data.close).get(0);yn(t,i),Af(t,r,n);let s=y.from(t.data.openTime).get(0);if(Number.isFinite(s)){let a=new Date(s),o=a.getUTCFullYear()*12+a.getUTCMonth(),l=e._monthly_equity??(e._monthly_equity=[]);e._last_month_key===o&&l.length>0?l[l.length-1]=e.equity:(l.push(e.equity),e._last_month_key=o)}}function Rf(t){let e=t?.strategy;if(!e)return;e.cagr=Bf(t),Lf(t);let r=e._monthly_equity??[],n=[e.initial_capital,...r],i=[];for(let d=1;d<n.length;d++){let f=n[d-1];f!==0&&Number.isFinite(f)&&Number.isFinite(n[d])&&i.push(n[d]/f-1)}if(i.length<2){e.sharpe_ratio=0,e.sortino_ratio=0;return}let s=(e.config.risk_free_rate??2)/100/12,a=i.length,o=i.reduce((d,f)=>d+f,0)/a,l=o-s,c=i.reduce((d,f)=>d+(f-o)**2,0)/a,u=Math.sqrt(c),h=i.reduce((d,f)=>d+Math.min(0,f-s)**2,0)/a,p=Math.sqrt(h);e.sharpe_ratio=u>0?l/u:0,e.sortino_ratio=p>0?l/p:0}var Ff=1440*60*1e3;function Bf(t){let e=t?.strategy;if(!e)return NaN;let r=t?.marketData;if(!Array.isArray(r)||r.length===0)return NaN;let n=r[0]?.openTime,i=r[r.length-1]?.openTime;if(!Number.isFinite(n)||!Number.isFinite(i))return NaN;let s=e.initial_capital??0,a=s+(e.netprofit??0),o=(i-n)/Ff;if(o<1||!Number.isFinite(s)||!Number.isFinite(a)||s===0)return NaN;let l=o/365;return 100*(Math.pow(a/s,1/l)-1)}function Lf(t){let e=t?.strategy;if(!e)return;let r=e._first_entry_price,n=t?.marketData,i=Array.isArray(n)&&n.length>0?n[n.length-1]?.close:NaN;if(!Number.isFinite(r)||!Number.isFinite(i)||r===0){e.buy_and_hold_pnl=NaN,e.buy_and_hold_per_gain=NaN,e.strategy_outperformance=NaN;return}let s=r,a=(i-s)/s;e.buy_and_hold_per_gain=a*100,e.buy_and_hold_pnl=(e.initial_capital??0)*a,e.strategy_outperformance=(e.netprofit??0)-e.buy_and_hold_pnl}function Of(t){t.strategy}function Vf(t,e){let r={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"right",pyramiding:1,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:"fixed",default_qty_value:1,initial_capital:1e6,currency:"USD",slippage:0,commission_type:"percent",commission_value:0,margin_long:100,margin_short:100,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,max_polylines_count:50,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,...e,...t._propOverrides??{}},n=r.initial_capital;t.strategy={config:r,opentrades:[],closedtrades:[],pending_orders:[],position_size:0,position_avg_price:NaN,position_entry_name:"",initial_capital:n,account_currency:r.currency||"USD",equity:n,netprofit:0,grossprofit:0,grossloss:0,openprofit:0,max_drawdown:0,max_runup:0,equity_peak:n,equity_trough:n,equity_at_runup_peak:n,equity_at_drawdown_peak:n,max_drawdown_percent_value:0,max_runup_percent_value:0,sharpe_ratio:0,sortino_ratio:0,cagr:NaN,buy_and_hold_pnl:NaN,buy_and_hold_per_gain:NaN,strategy_outperformance:NaN,_first_entry_price:void 0,_monthly_equity:[],_last_month_key:-1,wintrades:0,losstrades:0,eventrades:0,wintrades_total_profit:0,losstrades_total_loss:0,max_contracts_held_all:0,max_contracts_held_long:0,max_contracts_held_short:0,risk_rules:{},risk_halted:!1,_exit_call_history:new Map,_exit_fallback_counter:0,_exit_fallback_last_bar:-1}}function Nr(t){if(Array.isArray(t))return t.map(Nr);if(t instanceof Map){let e=new Map;return t.forEach((r,n)=>e.set(n,Nr(r))),e}if(t!==null&&typeof t=="object"){let e={};for(let r of Object.keys(t))e[r]=Nr(t[r]);return e}return t}function jf(t){if(!t)return null;let e={};for(let r of Object.keys(t))r==="config"||r==="closedtrades"||(e[r]=Nr(t[r]));return{fields:e,closedtradesLength:t.closedtrades.length}}function $f(t,e){if(!(!t||!e)){for(let r of Object.keys(t))r==="config"||r==="closedtrades"||Object.prototype.hasOwnProperty.call(e.fields,r)||delete t[r];t.closedtrades.length>e.closedtradesLength&&(t.closedtrades.length=e.closedtradesLength);for(let r of Object.keys(e.fields))t[r]=Nr(e.fields[r])}}function Wf(t){return(...e)=>{let r=bf(e);return t.strategy?t.strategy.config={...t.strategy.config,...r,...t._propOverrides??{}}:Vf(t,r),t.strategy.config}}var Uf=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],qf={id:"string",direction:"series",qty:"series",limit:"series",stop:"series",oca_name:"string",oca_type:"string",comment:"string",alert_message:"string",disable_alert:"boolean"};function zf(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.order() called before strategy() declaration");let r=le(e,Uf,qf),n=w=>w==null||typeof w=="string"||typeof w=="number"||typeof w=="boolean"?w:typeof w=="function"?w():w instanceof y?w.get(0):Array.isArray(w)?w[w.length-1]:typeof w=="object"&&w.get!==void 0?w.get(0):w,i=n(r.id),s=n(r.direction),a=n(r.qty),o=n(r.limit),l=n(r.stop),c=n(r.oca_name),u=n(r.oca_type),h=n(r.comment),p=Vt(s),d=y.from(t.data.close).get(0),f=us(t,a,p,d),m="market";o!==void 0&&l!==void 0?m="stop-limit":o!==void 0?m="limit":l!==void 0&&(m="stop");let x=y.from(t.data.openTime).get(0),b={id:i,direction:p,qty:f,type:m,limit:o,stop:l,bar:t.idx,time:x,status:"pending",oca_name:c,oca_type:u,comment:h};return t.strategy.pending_orders.push(b),b}}function Kf(t){return(e,r)=>y.from(e).get(r||0)}function Hf(t){return()=>{let e=(t.strategy?.opentrades??[]).slice(),r=p=>e[Number(p)],n=()=>{let p=t.marketData;return Array.isArray(p)&&t.idx>=0&&t.idx<p.length?p[t.idx]?.close??NaN:NaN},i={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},s=t.pine?.syminfo?.pointvalue??1,a=(p,d)=>{let f=t.strategy?.config,m=f?.commission_type??"percent",x=f?.commission_value??0;if(!x)return 0;let b=Math.abs(p.size);switch(m){case"percent":return b*d*s*(x/100);case"cash_per_contract":return b*x;case"cash_per_order":return x;default:return 0}},o=p=>Math.abs(p.size)*p.entry_price*s+(p.commission??0);i.profit=p=>{let d=r(p);if(!d)return NaN;let f=n();return Number.isFinite(f)?(Math.sign(d.size)===1?f-d.entry_price:d.entry_price-f)*Math.abs(d.size)*s-(d.commission??0)-a(d,f):NaN},i.profit_percent=p=>{let d=r(p);if(!d)return NaN;let f=i.profit(p);if(!Number.isFinite(f))return NaN;let m=o(d);return m>0?100*f/m:NaN},i.size=p=>r(p)?.size??NaN,i.commission=p=>r(p)?.commission??NaN,i.entry_price=p=>r(p)?.entry_price??NaN,i.entry_bar_index=p=>r(p)?.entry_bar_index??NaN,i.entry_id=p=>r(p)?.entry_id??"",i.entry_comment=p=>r(p)?.entry_comment??r(p)?.entry_id??"",i.entry_time=p=>r(p)?.entry_time??NaN,i.max_drawdown=p=>r(p)?.max_drawdown??0,i.max_drawdown_percent=p=>{let d=r(p);if(!d||!d.max_drawdown)return 0;let f=o(d);return f>0?100*d.max_drawdown/f:0},i.max_runup=p=>r(p)?.max_runup??0,i.max_runup_percent=p=>{let d=r(p);if(!d||!d.max_runup)return 0;let f=o(d);return f>0?100*d.max_runup/f:0};let l=t.strategy,c=l?.config?.margin_long??100,u=l?.config?.margin_short??100,h=c!==100||u!==100;if(!l||l.opentrades.length===0||!h)i.capital_held=NaN;else{let p=0;for(let d of l.opentrades){let f=Math.abs(d.size)*d.entry_price,m=d.size>0?c:u;p+=f*(m/100)}i.capital_held=p}return i}}function Gf(t){return()=>{let e=(t.strategy?.closedtrades??[]).slice(),r=a=>e[Number(a)],n={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},i=t.pine?.syminfo?.pointvalue??1,s=a=>{let o=Math.abs(a.size)*a.entry_price*i,l=(a.commission??0)/2;return o+l};return n.profit=a=>r(a)?.profit??NaN,n.profit_percent=a=>{let o=r(a);if(!o||o.profit===void 0)return NaN;let l=s(o);return l>0?100*o.profit/l:NaN},n.size=a=>r(a)?.size??NaN,n.commission=a=>r(a)?.commission??NaN,n.entry_price=a=>r(a)?.entry_price??NaN,n.entry_bar_index=a=>r(a)?.entry_bar_index??NaN,n.entry_id=a=>r(a)?.entry_id??"",n.entry_comment=a=>r(a)?.entry_comment??r(a)?.entry_id??"",n.entry_time=a=>r(a)?.entry_time??NaN,n.exit_price=a=>r(a)?.exit_price??NaN,n.exit_bar_index=a=>r(a)?.exit_bar_index??NaN,n.exit_id=a=>r(a)?.exit_id??"",n.exit_comment=a=>r(a)?.exit_comment??r(a)?.exit_id??"",n.exit_time=a=>r(a)?.exit_time??NaN,n.max_drawdown=a=>r(a)?.max_drawdown??0,n.max_drawdown_percent=a=>{let o=r(a);if(!o||!o.max_drawdown)return 0;let l=s(o);return l>0?100*o.max_drawdown/l:0},n.max_runup=a=>r(a)?.max_runup??0,n.max_runup_percent=a=>{let o=r(a);if(!o||!o.max_runup)return 0;let l=s(o);return l>0?100*o.max_runup/l:0},n.first_index=0,n}}function Yf(t){return()=>t.strategy?.netprofit??0}function Zf(t){return()=>t.strategy?.position_size??0}function Xf(t){return()=>{let e=t.strategy;return!e||e.position_size===0?NaN:e.position_avg_price}}function Qf(t){return()=>t.strategy?.equity??t.strategy?.config?.initial_capital??1e4}function Jf(t){return()=>"long"}function em(t){return()=>"short"}function tm(t){return()=>"cash"}function rm(t){return()=>"percent_of_equity"}function nm(t){return()=>"fixed"}function im(t){return()=>t.strategy?.openprofit??0}function sm(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.openprofit/e.initial_capital}}function am(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.netprofit/e.initial_capital}}function om(t){return()=>t.strategy?.grossprofit??0}function lm(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossprofit/e.initial_capital}}function cm(t){return()=>t.strategy?.grossloss??0}function um(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossloss/e.initial_capital}}function pm(t){return()=>t.strategy?.wintrades??0}function hm(t){return()=>t.strategy?.losstrades??0}function dm(t){return()=>t.strategy?.eventrades??0}function fm(t){return()=>{let e=t.strategy;return!e||!e.closedtrades||e.closedtrades.length===0?NaN:e.netprofit/e.closedtrades.length}}function mm(t){return()=>{let e=t.strategy;if(!e||!e.closedtrades||e.closedtrades.length===0)return NaN;let r=0;for(let n of e.closedtrades){let i=Math.abs(n.size)*n.entry_price;i>0&&(r+=100*(n.profit??0)/i)}return r/e.closedtrades.length}}function ym(t){return()=>{let e=t.strategy;return!e||e.wintrades===0?NaN:e.wintrades_total_profit/e.wintrades}}function gm(t){return()=>{let e=t.strategy;if(!e||e.wintrades===0)return NaN;let r=0;for(let n of e.closedtrades)if((n.profit??0)>0){let i=Math.abs(n.size)*n.entry_price;i>0&&(r+=100*(n.profit??0)/i)}return r/e.wintrades}}function _m(t){return()=>{let e=t.strategy;return!e||e.losstrades===0?NaN:e.losstrades_total_loss/e.losstrades}}function xm(t){return()=>{let e=t.strategy;if(!e||e.losstrades===0)return NaN;let r=0;for(let n of e.closedtrades)if((n.profit??0)<0){let i=Math.abs(n.size)*n.entry_price;i>0&&(r+=100*(n.profit??0)/i)}return r/e.losstrades}}function bm(t){return()=>t.strategy?.max_drawdown??0}function vm(t){return()=>{let e=t.strategy;return e?e.max_drawdown_percent_value??0:0}}function wm(t){return()=>t.strategy?.max_runup??0}function Em(t){return()=>{let e=t.strategy;return e?e.max_runup_percent_value??0:0}}function Sm(t){return()=>t.strategy?.max_contracts_held_all??0}function Cm(t){return()=>t.strategy?.max_contracts_held_long??0}function Nm(t){return()=>t.strategy?.max_contracts_held_short??0}function km(t){return()=>t.strategy?.position_entry_name??""}function Im(t){return()=>t.strategy?.initial_capital??0}function Am(t){return()=>t.strategy?.account_currency??"USD"}function Tm(t){return()=>{let e=t.strategy;if(!e||e.position_size===0)return NaN;let r=e.position_avg_price;if(!Number.isFinite(r))return NaN;let n=Math.sign(e.position_size),i=n===1?e.config.margin_long??100:e.config.margin_short??100;if(i>=100)return NaN;let s=Math.abs(e.position_size),a=t.pine?.syminfo?.pointvalue??1,o=((e.initial_capital??0)+(e.netprofit??0))/(a*s)-n*r,l=i/100-n,c=o/l,u=t.pine?.syminfo?.mintick??.01;return n===1?Math.floor(c/u)*u:Math.ceil(c/u)*u}}var Dm=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],Mm={id:"string",direction:"series",qty:"series",limit:"series",stop:"series",oca_name:"string",oca_type:"string",comment:"string",alert_message:"string",disable_alert:"boolean"};function Pm(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.entry() called before strategy() declaration");let r=le(e,Dm,Mm),n=k=>k==null||typeof k=="string"||typeof k=="number"||typeof k=="boolean"?k:typeof k=="function"?k():k instanceof y?k.get(0):Array.isArray(k)?k[k.length-1]:typeof k=="object"&&k.get!==void 0?k.get(0):k,i=n(r.id),s=n(r.direction),a=n(r.qty),o=n(r.limit),l=n(r.stop),c=n(r.oca_name),u=n(r.oca_type),h=n(r.comment),p=Vt(s),d=t.strategy,f=d.position_size;for(let k of d.pending_orders)k.bar===t.idx&&k.category==="entry"&&k.type==="market"&&(f+=Vt(k.direction)*k.qty);if(Math.sign(f)===p&&f!==0&&Sf(d,p))return;let m=y.from(t.data.close).get(0),x=us(t,a,p,m),b=f!==0&&Math.sign(f)!==p,w=b?Math.abs(f)+x:x,v="market";o!==void 0&&l!==void 0?v="stop-limit":o!==void 0?v="limit":l!==void 0&&(v="stop");let E=t.pine?.syminfo?.mintick??0,A=o!==void 0?Cr(o,m,E):void 0,C=l!==void 0?Cr(l,m,E):void 0,D=y.from(t.data.openTime).get(0),j={id:i,direction:p,qty:w,type:v,limit:A,stop:C,bar:t.idx,time:D,status:"pending",category:"entry",oca_name:c,oca_type:u,comment:h,_isReversalEntry:b,_base_qty:x};d.pending_orders.push(j)}}var Rm=[["id","from_entry","qty","qty_percent","profit","limit","loss","stop","trail_price","trail_points","trail_offset","oca_name","comment","comment_profit","comment_loss","comment_trailing","alert_message","alert_profit","alert_loss","alert_trailing","disable_alert"]],Fm={id:"string",from_entry:"string",qty:"series",qty_percent:"series",profit:"series",limit:"series",loss:"series",stop:"series",trail_price:"series",trail_points:"series",trail_offset:"series",oca_name:"string",comment:"string",comment_profit:"string",comment_loss:"string",comment_trailing:"string",alert_message:"string",alert_profit:"string",alert_loss:"string",alert_trailing:"string",disable_alert:"boolean"};function Bm(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.exit() called before strategy() declaration");let r=ht(e);if(r===void 0){let R=t.strategy;R._exit_fallback_last_bar!==t.idx&&(R._exit_fallback_counter=0,R._exit_fallback_last_bar=t.idx),r=`exit_raw_${R._exit_fallback_counter++}`}let n=le(e,Rm,Fm),i=R=>R==null||typeof R=="string"||typeof R=="number"||typeof R=="boolean"?R:typeof R=="function"?R():R instanceof y?R.get(0):Array.isArray(R)?R[R.length-1]:typeof R=="object"&&R.get!==void 0?R.get(0):R,s=i(n.id),a=i(n.from_entry),o=i(n.qty),l=i(n.qty_percent),c=i(n.profit),u=i(n.limit),h=i(n.loss),p=i(n.stop),d=i(n.trail_price),f=i(n.trail_points),m=i(n.trail_offset),x=t.pine?.syminfo?.mintick??0,b=y.from(t.data.close).get(0),w=u!==void 0?Cr(u,b,x):void 0,v=p!==void 0?Cr(p,b,x):void 0,E=d!==void 0?Cr(d,b,x):void 0,A=a??"",C=!!(A?t.strategy.pending_orders.find(R=>R.category==="entry"&&R.id===A&&R.status==="pending"):t.strategy.pending_orders.find(R=>R.category==="entry"&&R.status==="pending"))?._isReversalEntry,D=t.strategy._exit_call_history,j=D.get(r),k=j!==void 0&&j===t.idx-1;D.set(r,t.idx);let V={id:s??"exit",direction:0,qty:o!==void 0?Math.abs(Number(o)):0,qty_percent:l,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:A,profit:c,loss:h,limit:w,stop:v,trail_price:E,trail_points:f,trail_offset:m,oca_name:i(n.oca_name),comment:i(n.comment),comment_profit:i(n.comment_profit),comment_loss:i(n.comment_loss),comment_trailing:i(n.comment_trailing),alert_message:i(n.alert_message),alert_profit:i(n.alert_profit),alert_loss:i(n.alert_loss),alert_trailing:i(n.alert_trailing),disable_alert:i(n.disable_alert),trail_armed:!1,trail_peak:NaN,_attachedAtReversal:C,_isPersistent:k,_callsiteId:r},T=V.id,W=t.strategy.pending_orders;for(let R=W.length-1;R>=0;R--){let M=W[R];M.category==="exit"&&M.id===T&&(M.from_entry??"")===(V.from_entry??"")&&M.status==="pending"&&(M.trail_armed&&(V.trail_armed=!0,V.trail_peak=M.trail_peak),W.splice(R,1))}W.push(V)}}var Lm=[["id","comment","qty","qty_percent","alert_message","immediately","disable_alert"]],Om={id:"string",comment:"string",qty:"series",qty_percent:"series",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function Vm(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close() called before strategy() declaration");let r=le(e,Lm,Om),n=r.id;if(n==null||!t.strategy.opentrades.some(o=>o.entry_id===n))return;let i=o=>(o.category??"entry")==="exit"&&(o.profit!==void 0||o.loss!==void 0||o.limit!==void 0||o.stop!==void 0||o.trail_price!==void 0||o.trail_points!==void 0),s=t.strategy.pending_orders;for(let o of s)i(o)&&(o.from_entry??"")===n&&o.status==="pending"&&(o.status="cancelled");t.strategy.pending_orders=s.filter(o=>o.status==="pending");let a={id:`close_${n}`,direction:0,qty:0,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:n,qty_percent:r.qty_percent,comment:r.comment,alert_message:r.alert_message,immediately:r.immediately===!0,disable_alert:r.disable_alert,_intended_trade_ids:t.strategy.opentrades.filter(o=>o.entry_id===n).map(o=>o.id)};r.qty!==void 0&&(a.qty=Math.abs(Number(r.qty))),t.strategy.pending_orders.push(a)}}var jm=[["comment","alert_message","immediately","disable_alert"]],$m={comment:"string",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function Wm(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close_all() called before strategy() declaration");let r=le(e,jm,$m);if(t.strategy.opentrades.length===0)return;let n=a=>(a.category??"entry")==="exit"&&(a.profit!==void 0||a.loss!==void 0||a.limit!==void 0||a.stop!==void 0||a.trail_price!==void 0||a.trail_points!==void 0),i=t.strategy.pending_orders;for(let a of i)n(a)&&a.status==="pending"&&(a.status="cancelled");t.strategy.pending_orders=i.filter(a=>a.status==="pending");let s={id:"close_all",direction:0,qty:0,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:"",comment:r.comment,alert_message:r.alert_message,immediately:r.immediately===!0,disable_alert:r.disable_alert,_intended_trade_ids:t.strategy.opentrades.map(a=>a.id)};t.strategy.pending_orders.push(s)}}var Um=[["id","immediately"]],qm={id:"string",immediately:"boolean"};function zm(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.cancel() called before strategy() declaration");let r=le(e,Um,qm).id;r!=null&&(t.strategy.pending_orders=t.strategy.pending_orders.filter(n=>!(n.status==="pending"&&n.id===r)))}}function Km(t){return()=>{if(!t.strategy)throw new Error("strategy.cancel_all() called before strategy() declaration");t.strategy.pending_orders=t.strategy.pending_orders.filter(e=>!(e.status==="pending"&&(e.category??"entry")==="entry"))}}function Hm(t){return{allow_entry_in:e=>{t.strategy&&(t.strategy.risk_rules.allow_entry_in=e)},max_cons_loss_days:(e,r)=>{t.strategy&&(t.strategy.risk_rules.max_cons_loss_days={count:e,alert_message:r})},max_drawdown:(e,r,n)=>{t.strategy&&(t.strategy.risk_rules.max_drawdown={value:e,type:r})},max_intraday_filled_orders:(e,r)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_filled_orders={count:e,alert_message:r})},max_intraday_loss:(e,r,n)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_loss={value:e,type:r})},max_position_size:e=>{t.strategy&&(t.strategy.risk_rules.max_position_size=e)}}}function Gm(t){return e=>{let r=t.strategy,n=t.pine?.syminfo?.currency,i=r?.account_currency??"USD";return n&&n!==i?NaN:e}}function Ym(t){return e=>{let r=t.strategy,n=t.pine?.syminfo?.currency,i=r?.account_currency??"USD";return n&&n!==i?NaN:e}}function Zm(t){return e=>t.strategy?us(t,void 0,1,e):0}var Xm={any:Wf,order:zf,param:Kf,opentrades:Hf,closedtrades:Gf,netprofit:Yf,position_size:Zf,position_avg_price:Xf,equity:Qf,long:Jf,short:em,cash:tm,percent_of_equity:rm,fixed:nm,openprofit:im,openprofit_percent:sm,netprofit_percent:am,grossprofit:om,grossprofit_percent:lm,grossloss:cm,grossloss_percent:um,wintrades:pm,losstrades:hm,eventrades:dm,avg_trade:fm,avg_trade_percent:mm,avg_winning_trade:ym,avg_winning_trade_percent:gm,avg_losing_trade:_m,avg_losing_trade_percent:xm,max_drawdown:bm,max_drawdown_percent:vm,max_runup:wm,max_runup_percent:Em,max_contracts_held_all:Sm,max_contracts_held_long:Cm,max_contracts_held_short:Nm,position_entry_name:km,initial_capital:Im,account_currency:Am,margin_liquidation_price:Tm,entry:Pm,exit:Bm,close:Vm,close_all:Wm,cancel:zm,cancel_all:Km,convert_to_account:Gm,convert_to_symbol:Ym,default_entry_qty:Zm},Qm={long:"long",short:"short",all:"all"},Jm={none:"none",cancel:"cancel",reduce:"reduce"},ey={percent:"percent",cash_per_order:"cash_per_order",cash_per_contract:"cash_per_contract"},ki=class{constructor(e){this.context=e,Object.entries(Xm).forEach(([n,i])=>{this[n]=i(e)}),this.direction=()=>Qm,this.oca=()=>Jm,this.commission=()=>ey;let r=Hm(e);this.risk=()=>r}};function ty(t,e){let r=e.trim();if(r==="UTC"||r==="GMT"||r==="Etc/UTC")return 0;let n=r.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(n){let a=n[1]==="+"?1:-1,o=parseInt(n[2],10),l=parseInt(n[3]||"0",10);return a*(o*60+l)}let i=Zt(t,e),s=new Date(Date.UTC(i.year,i.month-1,i.day,i.hour,i.minute,i.second));return Math.round((s.getTime()-t)/6e4)}function ry(t,e){let r=e>=0?"+":"-",n=s=>String(Math.floor(Math.abs(s))).padStart(2,"0"),i=r+n(e/60)+":"+n(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${i}]`}var Ii=class{constructor(e){this.context=e}logFormat(e,...r){return e.replace(/{(\\d+)}/g,(n,i)=>r[i])}param(e,r=0,n){return y.from(e).get(r)}_formatTimestamp(){let e=this.context.data.openTime.data[this.context.idx],r=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",n=ty(e,r);return ry(e,n)}warning(e,...r){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...r)}`)}error(e,...r){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...r)}`)}info(e,...r){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...r)}`)}},ny=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],iy=["January","February","March","April","May","June","July","August","September","October","November","December"],sy=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],ay=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],He=(t,e)=>String(t).padStart(e,"0"),Ai=class{constructor(e){this.context=e}param(e,r=0,n){return y.from(e).get(r)}tostring(e,r){if(typeof e!="number"||isNaN(e)||!r)return String(e);if(r==="mintick"){let i=this.context.pine?.syminfo?.mintick||.01,s=Math.max(0,-Math.floor(Math.log10(i)));return e.toFixed(s)}if(r==="integer")return String(Math.round(e));if(r==="percent")return(e*100).toFixed(2)+"%";if(r==="price"){let i=this.context.pine?.syminfo?.mintick||.01,s=Math.max(0,-Math.floor(Math.log10(i)));return e.toFixed(s)}if(r==="volume")return String(Math.round(e));let n=r.indexOf(".");if(n>=0){let i=r.substring(n+1).length;return e.toFixed(i)}return r.includes("#")||r.includes("0")?String(Math.round(e)):String(e)}tonumber(e){return Number(e)}lower(e){return String(e).toLowerCase()}upper(e){return String(e).toUpperCase()}trim(e){return String(e).trim()}repeat(e,r,n=""){return Array(r).fill(e).join(n||"")}replace_all(e,r,n){return String(e).replaceAll(r,n)}replace(e,r,n,i=0){let s=String(e),a=String(r),o=String(n),l=Math.floor(Number(i))||0;if(a==="")return s;let c=0,u=0;for(;;){let h=s.indexOf(a,c);if(h===-1)return s;if(u===l)return s.substring(0,h)+o+s.substring(h+a.length);u++,c=h+a.length}}contains(e,r){return String(e).includes(r)}endswith(e,r){return String(e).endsWith(r)}startswith(e,r){return String(e).startsWith(r)}pos(e,r){let n=String(e).indexOf(r);return n===-1?NaN:n}length(e){return String(e).length}match(e,r){return String(e).match(new RegExp(r))}split(e,r){return new q(String(e).split(r),z.string,this.context)}substring(e,r,n){return String(e).substring(r,n)}format_time(e,r="yyyy-MM-dd\'T\'HH:mm:ssZ",n){if(e==null||typeof e=="number"&&isNaN(e))return"NaN";let i=Number(e),s=n||this.context.pine?.syminfo?.timezone||"UTC",a=Zt(i,s),o=Date.UTC(a.year,a.month-1,a.day,a.hour,a.minute,a.second),l=Math.round((o-i)/6e4),c=Date.UTC(a.year,0,1),u=Math.floor((o-c)/864e5)+1,h=a.hour%12===0?12:a.hour%12,p="",d=0;for(;d<r.length;){let f=r[d];if(f==="\'"){if(r[d+1]==="\'"){p+="\'",d+=2;continue}let m=r.indexOf("\'",d+1);if(m===-1){p+=r.substring(d+1);break}p+=r.substring(d+1,m),d=m+1;continue}if(f>="a"&&f<="z"||f>="A"&&f<="Z"){let m=1;for(;r[d+m]===f;)m++;switch(d+=m,f){case"y":p+=m===2?He(a.year%100,2):m>=4?He(a.year,4):String(a.year);break;case"M":m>=4?p+=iy[a.month-1]:m===3?p+=ny[a.month-1]:m===2?p+=He(a.month,2):p+=String(a.month);break;case"d":p+=m===2?He(a.day,2):String(a.day);break;case"D":p+=m>=3?He(u,3):m===2?He(u,2):String(u);break;case"E":p+=m>=4?ay[a.dayOfWeek]:sy[a.dayOfWeek];break;case"a":p+=a.hour<12?"AM":"PM";break;case"h":p+=m===2?He(h,2):String(h);break;case"H":p+=m===2?He(a.hour,2):String(a.hour);break;case"m":p+=m===2?He(a.minute,2):String(a.minute);break;case"s":p+=m===2?He(a.second,2):String(a.second);break;case"S":{let x=i-Math.floor(i/1e3)*1e3;p+=He(x,3).substring(0,m);break}case"Z":{let x=l>=0?"+":"-",b=Math.abs(l);p+=`${x}${He(Math.floor(b/60),2)}${He(b%60,2)}`;break}default:p+=f.repeat(m)}continue}p+=f,d++}return p}format(e,...r){return e.replace(/\\{(\\d+)(?:,number,([^}]+))?\\}/g,(n,i,s)=>{let a=r[i];return s&&typeof a=="number"&&!isNaN(a)?this.tostring(a,s):String(a)})}},oy=Object.defineProperty,ly=(t,e,r)=>e in t?oy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cy=(t,e,r)=>ly(t,typeof e!="symbol"?e+"":e,r),Yr={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function Ys(t){if(!t||/^\\d+$/.test(t))return t;if(Yr[t])return Yr[t];let e=t.toLowerCase();if(Yr[e])return Yr[e];if(t.length===1){let n=t.toUpperCase();if(["D","W","M","S"].includes(n))return n}let r=t.slice(-1).toUpperCase();if(["D","W","M","S"].includes(r)){let n=parseInt(t);if(!isNaN(n))return n+r}return t}var Ti=class{constructor(e){this.context=e,cy(this,"_normalized",null)}param(e,r=0,n){return y.from(e).get(r)}get normalized(){return this._normalized===null&&(this._normalized=Ys(this.context.timeframe)),this._normalized}get unit(){return this.normalized.slice(-1).toUpperCase()}get main_period(){return this.normalized}get period(){return this.normalized}get multiplier(){let e=parseInt(this.normalized);return isNaN(e)?1:e}get isdwm(){return["D","W","M"].includes(this.unit)}get isdaily(){return this.unit==="D"}get isweekly(){return this.unit==="W"}get ismonthly(){return this.unit==="M"}get isseconds(){return this.unit==="S"}get isminutes(){return/^\\d+$/.test(this.normalized)}get isintraday(){return!this.isdwm}change(e){let r=typeof e=="function"?e():e,n=r instanceof y?r.get(0):r,i=gi(n||"");if(!i)return!1;let s=y.from(this.context.data.openTime).get(0),a=y.from(this.context.data.openTime).get(1);if(isNaN(s)||isNaN(a))return!1;let o=_i(s,i),l=_i(a,i);return o!==l}from_seconds(e){return e<60?Math.ceil(e/5)*5+"S":e<3600*24?Math.ceil(e/60):e<=3600*24*7*52?e%(3600*24*7)===0?Math.ceil(e/604800)+"W":Math.ceil(e/(3600*24))+"D":"12M"}in_seconds(e){e==null?e=this.normalized:e=Ys(e);let r=e.slice(-1).toUpperCase(),n=parseInt(e);return r==="S"?isNaN(n)?1:n:r==="D"?(isNaN(n)?1:n)*60*60*24:r==="W"?(isNaN(n)?1:n)*60*60*24*7:r==="M"?(isNaN(n)?1:n)*60*60*24*30:isNaN(n)?0:n*60}},uy=Object.defineProperty,py=Object.getOwnPropertyDescriptor,bt=(t,e,r,n)=>{for(var i=n>1?void 0:n?py(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&uy(e,r,i),i},hy=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],dy=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],fy={series:"series",title:"string",char:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},my=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],yy=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],gy=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],_y=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],Zs=["color","offset","editable","show_last","title","display","force_overlay"],xy=["price","title","color","linestyle","linewidth","editable","display"],by=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],vy={series:"series",title:"string",color:"color",linewidth:"number",style:"string",trackprice:"boolean",histbase:"number",offset:"number",join:"bool",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},wy={series:"series",title:"string",style:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Ey={series:"series",title:"string",colorup:"color",colordown:"color",offset:"number",minheight:"number",maxheight:"number",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Sy={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Cy={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",wickcolor:"color",bordercolor:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Xs={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},Ny={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},ky={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"},dt=class{constructor(e){this.context=e}_resolvePlotKey(e,r){if(e){let n=this.context.plots[e];return!n||!r||n._callsiteId===r?e:e+r}return r||"plot"}extractPlotOptions(e){let r={};for(let n in e)r[n]=y.from(e[n]).get(0);return r}get linestyle_dashed(){return"linestyle_dashed"}get linestyle_dotted(){return"linestyle_dotted"}get linestyle_solid(){return"linestyle_solid"}get style_area(){return"style_area"}get style_areabr(){return"style_areabr"}get style_circles(){return"style_circles"}get style_columns(){return"style_columns"}get style_cross(){return"style_cross"}get style_histogram(){return"style_histogram"}get style_line(){return"style_line"}get style_linebr(){return"style_linebr"}get style_stepline(){return"style_stepline"}get style_stepline_diamond(){return"style_stepline_diamond"}get style_steplinebr(){return"style_steplinebr"}param(e,r=0,n){return y.from(e).get(r)}plotchar(...e){let r=ht(e),n=le(e,dy,fy),{series:i,title:s,...a}=n,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,r);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:s,_plotKey:l,_callsiteId:r});let c=y.from(i).get(0);return this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:c,options:{char:o.char,color:o.color,textcolor:o.textcolor,location:o.location,size:o.size,offset:o.offset}}),this.context.plots[l]}any(...e){let r=ht(e),n=le(e,hy,vy),{series:i,title:s,...a}=n,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,r),c="color"in a;if(!this.context.plots[l]){let d=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:d},title:s,_plotKey:l,_callsiteId:r}}let u=y.from(i).get(0),h=o.color;typeof h=="function"&&(h=h());let p={color:c?typeof h=="string"?h:void 0:h||"#2962ff"};return"offset"in a&&(p.offset=o.offset),this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:u,options:p}),this.context.plots[l]}plotshape(...e){let r=ht(e),n=le(e,my,wy),{series:i,title:s,...a}=n,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,r);if(!this.context.plots[l]){let u=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,style:"shape",shape:o.style,overlay:u},title:s,_plotKey:l,_callsiteId:r}}let c=y.from(i).get(0);return this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:c,options:o?.location==="absolute"||c?{text:o.text,textcolor:o.textcolor,color:o.color,offset:o.offset,shape:o.style,location:o.location,size:o.size}:void 0}),this.context.plots[l]}plotarrow(...e){let r=ht(e),n=le(e,yy,Ey),{series:i,title:s,...a}=n,o=y.from(i).get(0),l=this.extractPlotOptions(a),c=this._resolvePlotKey(s,r);if(!this.context.plots[c]){let u=l.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[c]={data:[],options:{...l,style:"shape",overlay:u},title:s,_plotKey:c,_callsiteId:r}}return this.context.plots[c].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:o,options:typeof o=="number"&&!isNaN(o)&&o!==0?{text:void 0,textcolor:void 0,color:o>0?l.colorup:l.colordown,offset:l.offset,shape:o>0?"shape_arrow_up":"shape_arrow_down",location:o>0?"BelowBar":"AboveBar",height:l.maxheight}:void 0}),this.context.plots[c]}plotbar(...e){let r=ht(e),n=le(e,gy,Sy),{open:i,high:s,low:a,close:o,title:l,...c}=n,u=this.extractPlotOptions(c),h=this._resolvePlotKey(l,r);if(!this.context.plots[h]){let d=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[h]={data:[],options:{...u,style:"bar",overlay:d},title:l,_plotKey:h,_callsiteId:r}}let p=[y.from(i).get(0),y.from(s).get(0),y.from(a).get(0),y.from(o).get(0)];this.context.plots[h].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:p,options:{color:u.color}})}plotcandle(...e){let r=ht(e),n=le(e,_y,Cy),{open:i,high:s,low:a,close:o,title:l,...c}=n,u=this.extractPlotOptions(c),h=this._resolvePlotKey(l,r);if(!this.context.plots[h]){let d=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[h]={data:[],options:{...u,style:"candle",overlay:d},title:l,_plotKey:h,_callsiteId:r}}let p=[y.from(i).get(0),y.from(s).get(0),y.from(a).get(0),y.from(o).get(0)];return this.context.plots[h].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:p,options:{color:u.color,wickcolor:u.wickcolor,bordercolor:u.bordercolor}}),this.context.plots[h]}bgcolor(...e){let r=ht(e),n=le(e,Zs,Xs),{title:i,...s}=n,a=this.extractPlotOptions(s),o=this._resolvePlotKey(i,r);if(!this.context.plots[o]){let l=a.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...a,style:"background",overlay:l},title:i,_plotKey:o,_callsiteId:r}}this.context.plots[o].data.push({title:i,time:this.context.marketData[this.context.idx].openTime,value:a.color&&a.color!=="na"&&a?.color.toString()!=="NaN",options:{color:a.color}})}barcolor(...e){let r=ht(e),n=le(e,Zs,Xs),{title:i,...s}=n,a=this.extractPlotOptions(s),o=this._resolvePlotKey(i,r);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...a,style:"barcolor"},title:i,_plotKey:o,_callsiteId:r}),this.context.plots[o].data.push({title:i,time:this.context.marketData[this.context.idx].openTime,value:a.color&&a.color!=="na"&&a?.color.toString()!=="NaN",options:{color:a.color}}),this.context.plots[o]}};bt([N],dt.prototype,"plotchar",1),bt([N],dt.prototype,"any",1),bt([N],dt.prototype,"plotshape",1),bt([N],dt.prototype,"plotarrow",1),bt([N],dt.prototype,"plotbar",1),bt([N],dt.prototype,"plotcandle",1),bt([N],dt.prototype,"bgcolor",1),bt([N],dt.prototype,"barcolor",1);var gn=class{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,r=0,n){return y.from(e).get(r)}any(...e){let r=ht(e),n=le(e,xy,Ny),{price:i,title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u}=n,h=[i,{title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u,style:"hline"}];return r&&h.push({__callsiteId:r}),this.context.pine.plot.any(...h)}};bt([N],gn.prototype,"any",1);var _n=class{constructor(e){this.context=e}param(e,r=0,n){return y.from(e).get(r)}any(...e){let r=ht(e),n=e.length>=6&&typeof e[2]=="number",i=!n&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(n||i!==null){let s=e[0],a=e[1],o=i?y.from(i.top_value).get(0):e[2],l=i?y.from(i.bottom_value).get(0):e[3],c=i?y.from(i.top_color).get(0):e[4],u=i?y.from(i.bottom_color).get(0):e[5],h=i?i.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,p=s?._plotKey||s?.title,d=a?._plotKey||a?.title,f=h||"fill",m=this.context.plots[f];m&&r&&m._callsiteId!==r&&(f=r),this.context.plots[f]||(this.context.plots[f]={title:h||"Fill",plot1:p,plot2:d,data:[],options:{plot1:p,plot2:d,style:"fill",gradient:!0},_plotKey:f,_callsiteId:r}),this.context.plots[f].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{top_value:o,bottom_value:l,top_color:c,bottom_color:u}})}else{let s=le(e,by,ky),{plot1:a,plot2:o,color:l,title:c,editable:u,show_last:h,fillgaps:p,display:d}=s,f=c||"fill",m=this.context.plots[f];m&&r&&m._callsiteId!==r&&(f=r);let x=y.from(l).get(0);if(!this.context.plots[f]){let b=a?._plotKey||a?.title,w=o?._plotKey||o?.title;this.context.plots[f]={title:c||"Fill",plot1:b,plot2:w,data:[],options:{plot1:b,plot2:w,color:x,editable:u,show_last:h,fillgaps:p,display:d,style:"fill"},_plotKey:f,_callsiteId:r}}this.context.plots[f].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:x}})}}};bt([N],_n.prototype,"any",1);var Iy=Object.defineProperty,Ay=(t,e,r)=>e in t?Iy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ty=(t,e,r)=>Ay(t,typeof e!="symbol"?e+"":e,r),Di=class{constructor(e){this.context=e,Ty(this,"point");let r=this.context,n=i=>i==null?i:typeof i=="object"&&Array.isArray(i.data)&&typeof i.get=="function"?i.get(0):typeof i=="function"?i():i;this.point={new(i,s,a){return new Oe(n(i),n(s),n(a)??NaN)},from_index(i,s){return new Oe(void 0,n(i),n(s))},from_time(i,s){return new Oe(n(i),void 0,n(s))},copy(i){return i.copy()},now(i){let s=r.idx,a=r.marketData[s]?.openTime;return new Oe(a,s,n(i))}}}param(e,r=0,n){return y.from(e).get(r)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){let e=this.context?.chartStyle;return e==null||e==="standard"}is_heikinashi(){return this.context?.chartStyle==="heikinashi"}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}},Dy=Object.defineProperty,My=(t,e,r)=>e in t?Dy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Te=(t,e,r)=>My(t,typeof e!="symbol"?e+"":e,r),Py=0,kr=class t{constructor(e,r,n="",i="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",h="",p="default",d=!1){Te(this,"id"),Te(this,"x"),Te(this,"y"),Te(this,"text"),Te(this,"xloc"),Te(this,"yloc"),Te(this,"color"),Te(this,"style"),Te(this,"textcolor"),Te(this,"size"),Te(this,"textalign"),Te(this,"tooltip"),Te(this,"text_font_family"),Te(this,"force_overlay"),Te(this,"_deleted"),Te(this,"_helper"),Te(this,"_createdAtBar",-1),this.id=Py++,this.x=e,this.y=r,this.text=n,this.xloc=i,this.yloc=s,this.color=a,this.style=o,this.textcolor=l,this.size=c,this.textalign=u,this.tooltip=h,this.text_font_family=p,this.force_overlay=d,this._deleted=!1,this._helper=null}set_x(e){this._helper?this._helper.set_x(this,e):this._deleted||(this.x=e)}set_y(e){this._helper?this._helper.set_y(this,e):this._deleted||(this.y=e)}set_xy(e,r){this._helper?this._helper.set_xy(this,e,r):this._deleted||(this.x=e,this.y=r)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_textcolor(e){this._helper?this._helper.set_textcolor(this,e):this._deleted||(this.textcolor=e)}set_size(e){this._helper?this._helper.set_size(this,e):this._deleted||(this.size=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_textalign(e){this._helper?this._helper.set_textalign(this,e):this._deleted||(this.textalign=e)}set_tooltip(e){this._helper?this._helper.set_tooltip(this,e):this._deleted||(this.tooltip=e)}set_xloc(e){this._helper?this._helper.set_xloc(this,e):this._deleted||(this.xloc=e)}set_yloc(e){this._helper?this._helper.set_yloc(this,e):this._deleted||(this.yloc=e)}set_point(e){this._helper&&this._helper.set_point(this,e)}set_text_font_family(e){this._deleted||(this.text_font_family=e)}get_x(){return this.x}get_y(){return this.y}get_text(){return this.text}delete(){this._deleted=!0}copy(){return new t(this.x,this.y,this.text,this.xloc,this.yloc,this.color,this.style,this.textcolor,this.size,this.textalign,this.tooltip,this.text_font_family,this.force_overlay)}toPlotData(){return{id:this.id,x:this.x,y:this.y,text:this.text,xloc:this.xloc,yloc:this.yloc,color:this.color,style:this.style,textcolor:this.textcolor,size:this.size,textalign:this.textalign,tooltip:this.tooltip,text_font_family:this.text_font_family,force_overlay:this.force_overlay,_deleted:this._deleted}}},Xa=Object.defineProperty,Ry=Object.getOwnPropertyDescriptor,Fy=(t,e,r)=>e in t?Xa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Me=(t,e,r,n)=>{for(var i=n>1?void 0:n?Ry(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&Xa(e,r,i),i},By=(t,e,r)=>Fy(t,typeof e!="symbol"?e+"":e,r),Ly=[["x","y","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"],["point","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"]],Oy={x:"number",y:"number",text:"string",xloc:"string",yloc:"string",color:"color",style:"string",textcolor:"color",size:"string",textalign:"string",tooltip:"string",text_font_family:"string",force_overlay:"boolean",point:"point"},Ee=class{constructor(e){this.context=e,By(this,"_labels",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._labels=this._labels.filter(s=>!s._deleted);let r=this._labels.map(s=>s.toPlotData()),n=r.filter(s=>!s.force_overlay),i=r.filter(s=>s.force_overlay);this.context.plots.__labels__.data=[{time:e,value:n,options:{style:"label"}}],i.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:i,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof Ze)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){let r=e.get(0);return typeof r=="number"&&isNaN(r)?null:r}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,r,n="",i="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",h="",p="default",d=!1){let f=new kr(e,r,this._resolve(n),this._resolve(i),this._resolve(s),this._resolve(a),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(u),this._resolve(h),this._resolve(p),d);return f._helper=this,f._createdAtBar=this.context.idx,this._labels.push(f),this._enforceMaxCount(),f}_enforceMaxCount(){let e=this.context.indicator?.max_labels_count??50,r=this._labels.filter(n=>!n._deleted);if(r.length>e){let n=r.length-e,i=0;for(let s of this._labels){if(i>=n)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let r=le(e,Ly,Oy),n,i,s=r.xloc;if(r.point instanceof Oe){let a=r.point,o=a.index!==void 0&&!(typeof a.index=="number"&&isNaN(a.index)),l=a.time!==void 0&&!(typeof a.time=="number"&&isNaN(a.time));o?(n=a.index,s=s||"bi"):l?(n=a.time,s=s||"bt"):(n=0,s=s||"bi"),i=a.price}else n=this._resolve(r.x),i=this._resolve(r.y);return this._createLabel(n,i,r.text,s,r.yloc,r.color,r.style,r.textcolor,r.size,r.textalign,r.tooltip,r.text_font_family,r.force_overlay)}any(...e){if(e.length===1){let r=e[0];if(r==null||r instanceof Ze||typeof r=="number"&&isNaN(r))return null;if(r instanceof kr)return r;if(r instanceof y){let n=r.get(0);if(n==null||typeof n=="number"&&isNaN(n))return null;if(n instanceof kr)return n}return null}return this.new(...e)}set_x(e,r){e&&!e._deleted&&(e.x=r)}set_y(e,r){e&&!e._deleted&&(e.y=r)}set_xy(e,r,n){e&&!e._deleted&&(e.x=r,e.y=n)}set_text(e,r){e&&!e._deleted&&(e.text=r)}set_color(e,r){e&&!e._deleted&&(e.color=r)}set_textcolor(e,r){e&&!e._deleted&&(e.textcolor=r)}set_size(e,r){e&&!e._deleted&&(e.size=r)}set_style(e,r){e&&!e._deleted&&(e.style=r)}set_textalign(e,r){e&&!e._deleted&&(e.textalign=r)}set_tooltip(e,r){e&&!e._deleted&&(e.tooltip=r)}set_xloc(e,r){e&&!e._deleted&&(e.xloc=r)}set_yloc(e,r){e&&!e._deleted&&(e.yloc=r)}set_point(e,r){if(e&&!e._deleted&&r){let n=r.index!==void 0&&!(typeof r.index=="number"&&isNaN(r.index)),i=r.time!==void 0&&!(typeof r.time=="number"&&isNaN(r.time));n?(e.x=r.index,e.xloc="bi"):i&&(e.x=r.time,e.xloc="bt"),e.y=r.price}}get_x(e){return e?e.x:NaN}get_y(e){return e?e.y:NaN}get_text(e){return e?e.text:""}copy(e){if(!e)return;let r=e.copy();return r._helper=this,r._createdAtBar=this.context.idx,this._labels.push(r),this._enforceMaxCount(),r}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(r=>r._createdAtBar<e),this.syncToPlot()}get style_label_down(){return"style_label_down"}get style_label_up(){return"style_label_up"}get style_label_left(){return"style_label_left"}get style_label_right(){return"style_label_right"}get style_label_lower_left(){return"style_label_lower_left"}get style_label_lower_right(){return"style_label_lower_right"}get style_label_upper_left(){return"style_label_upper_left"}get style_label_upper_right(){return"style_label_upper_right"}get style_label_center(){return"style_label_center"}get style_circle(){return"style_circle"}get style_square(){return"style_square"}get style_diamond(){return"style_diamond"}get style_flag(){return"style_flag"}get style_arrowup(){return"style_arrowup"}get style_arrowdown(){return"style_arrowdown"}get style_cross(){return"style_cross"}get style_xcross(){return"style_xcross"}get style_triangleup(){return"style_triangleup"}get style_triangledown(){return"style_triangledown"}get style_none(){return"style_none"}get style_text_outline(){return"style_text_outline"}};Me([N],Ee.prototype,"new",1),Me([N],Ee.prototype,"set_x",1),Me([N],Ee.prototype,"set_y",1),Me([N],Ee.prototype,"set_xy",1),Me([N],Ee.prototype,"set_text",1),Me([N],Ee.prototype,"set_color",1),Me([N],Ee.prototype,"set_textcolor",1),Me([N],Ee.prototype,"set_size",1),Me([N],Ee.prototype,"set_style",1),Me([N],Ee.prototype,"set_textalign",1),Me([N],Ee.prototype,"set_tooltip",1),Me([N],Ee.prototype,"set_xloc",1),Me([N],Ee.prototype,"set_yloc",1),Me([N],Ee.prototype,"set_point",1),Me([N],Ee.prototype,"copy",1),Me([N],Ee.prototype,"delete",1);var Vy=Object.defineProperty,jy=(t,e,r)=>e in t?Vy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$e=(t,e,r)=>jy(t,typeof e!="symbol"?e+"":e,r),$y=0,Ir=class t{constructor(e,r,n,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){$e(this,"id"),$e(this,"x1"),$e(this,"y1"),$e(this,"x2"),$e(this,"y2"),$e(this,"xloc"),$e(this,"extend"),$e(this,"color"),$e(this,"style"),$e(this,"width"),$e(this,"force_overlay"),$e(this,"_deleted"),$e(this,"_helper"),$e(this,"_createdAtBar",-1),this.id=$y++,this.x1=e,this.y1=r,this.x2=n,this.y2=i,this.xloc=s,this.extend=a,this.color=o,this.style=l,this.width=c,this.force_overlay=u,this._deleted=!1,this._helper=null}set_x1(e){this._helper?this._helper.set_x1(this,e):this._deleted||(this.x1=e)}set_y1(e){this._helper?this._helper.set_y1(this,e):this._deleted||(this.y1=e)}set_x2(e){this._helper?this._helper.set_x2(this,e):this._deleted||(this.x2=e)}set_y2(e){this._helper?this._helper.set_y2(this,e):this._deleted||(this.y2=e)}set_xy1(e,r){this._helper?this._helper.set_xy1(this,e,r):this._deleted||(this.x1=e,this.y1=r)}set_xy2(e,r){this._helper?this._helper.set_xy2(this,e,r):this._deleted||(this.x2=e,this.y2=r)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_width(e){this._helper?this._helper.set_width(this,e):this._deleted||(this.width=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_xloc(e,r,n){this._helper?this._helper.set_xloc(this,e,r,n):this._deleted||(this.x1=e,this.x2=r,this.xloc=n)}set_first_point(e){this._helper&&this._helper.set_first_point(this,e)}set_second_point(e){this._helper&&this._helper.set_second_point(this,e)}get_x1(){return this.x1}get_y1(){return this.y1}get_x2(){return this.x2}get_y2(){return this.y2}get_price(e){return this._helper?this._helper.get_price(this,e):NaN}delete(){this._deleted=!0}copy(){return new t(this.x1,this.y1,this.x2,this.y2,this.xloc,this.extend,this.color,this.style,this.width,this.force_overlay)}toPlotData(){return{id:this.id,x1:this.x1,y1:this.y1,x2:this.x2,y2:this.y2,xloc:this.xloc,extend:this.extend,color:this.color,style:this.style,width:this.width,force_overlay:this.force_overlay,_deleted:this._deleted}}},Qa=Object.defineProperty,Wy=Object.getOwnPropertyDescriptor,Uy=(t,e,r)=>e in t?Qa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Pe=(t,e,r,n)=>{for(var i=n>1?void 0:n?Wy(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&Qa(e,r,i),i},qy=(t,e,r)=>Uy(t,typeof e!="symbol"?e+"":e,r),zy=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],Ky={x1:"number",y1:"number",x2:"number",y2:"number",xloc:"string",extend:"string",color:"color",style:"string",width:"number",force_overlay:"boolean",first_point:"point",second_point:"point"},Se=class{constructor(e){this.context=e,qy(this,"_lines",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__lines__||(this.context.plots.__lines__={title:"__lines__",data:[],options:{style:"drawing_line",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._lines=this._lines.filter(s=>!s._deleted);let r=this._lines.map(s=>s.toPlotData()),n=r.filter(s=>!s.force_overlay),i=r.filter(s=>s.force_overlay);this.context.plots.__lines__.data=[{time:e,value:n,options:{style:"drawing_line"}}],i.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:i,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e){let r=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),n=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return r?{x:e.index,xloc:"bi"}:n?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Ze?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){let r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r}_createLine(e,r,n,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){let h=new Ir(e,r,n,i,s,this._resolve(a),this._resolveColor(o),this._resolve(l),this._resolve(c)||1,u);return h._helper=this,h._createdAtBar=this.context.idx,this._lines.push(h),this._enforceMaxCount(),h}_enforceMaxCount(){let e=this.context.indicator?.max_lines_count??50,r=this._lines.filter(n=>!n._deleted);if(r.length>e){let n=r.length-e,i=0;for(let s of this._lines){if(i>=n)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let r=le(e,zy,Ky),n,i,s,a,o=r.xloc;if(r.first_point instanceof Oe){let l=r.first_point,c=r.second_point,u=this._resolvePoint(l);n=u.x,i=l.price,o=o||u.xloc,c instanceof Oe?(s=this._resolvePoint(c).x,a=c.price):(s=0,a=NaN)}else n=this._resolve(r.x1),i=this._resolve(r.y1),s=this._resolve(r.x2),a=this._resolve(r.y2);return this._createLine(n,i,s,a,o,r.extend,r.color,r.style,r.width,r.force_overlay)}any(...e){if(e.length===1){let r=e[0];if(r==null||r instanceof Ze||typeof r=="number"&&isNaN(r))return null;if(r instanceof Ir)return r;if(r instanceof y){let n=r.get(0);if(n==null||typeof n=="number"&&isNaN(n))return null;if(n instanceof Ir)return n}return null}return this.new(...e)}set_x1(e,r){e&&!e._deleted&&(e.x1=this._resolve(r))}set_y1(e,r){e&&!e._deleted&&(e.y1=this._resolve(r))}set_x2(e,r){e&&!e._deleted&&(e.x2=this._resolve(r))}set_y2(e,r){e&&!e._deleted&&(e.y2=this._resolve(r))}set_xy1(e,r,n){e&&!e._deleted&&(e.x1=this._resolve(r),e.y1=this._resolve(n))}set_xy2(e,r,n){e&&!e._deleted&&(e.x2=this._resolve(r),e.y2=this._resolve(n))}set_color(e,r){e&&!e._deleted&&(e.color=this._resolveColor(r))}set_width(e,r){e&&!e._deleted&&(e.width=this._resolve(r)||1)}set_style(e,r){e&&!e._deleted&&(e.style=this._resolve(r))}set_extend(e,r){e&&!e._deleted&&(e.extend=this._resolve(r))}set_xloc(e,r,n,i){e&&!e._deleted&&(e.x1=r,e.x2=n,e.xloc=i)}set_first_point(e,r){if(e&&!e._deleted&&r){let n=this._resolvePoint(r);e.x1=n.x,e.y1=r.price,e.xloc=n.xloc}}set_second_point(e,r){if(e&&!e._deleted&&r){let n=this._resolvePoint(r);e.x2=n.x,e.y2=r.price,e.xloc=n.xloc}}get_x1(e){return e?e.x1:NaN}get_y1(e){return e?e.y1:NaN}get_x2(e){return e?e.x2:NaN}get_y2(e){return e?e.y2:NaN}get_price(e,r){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;let n=e.x2-e.x1;return n===0?e.y1:e.y1+(r-e.x1)/n*(e.y2-e.y1)}copy(e){if(!e)return;let r=e.copy();return r._helper=this,r._createdAtBar=this.context.idx,this._lines.push(r),this._enforceMaxCount(),r}delete(e){e&&(e._deleted=!0)}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(r=>r._createdAtBar<e),this.syncToPlot()}get style_solid(){return"style_solid"}get style_dotted(){return"style_dotted"}get style_dashed(){return"style_dashed"}get style_arrow_left(){return"style_arrow_left"}get style_arrow_right(){return"style_arrow_right"}get style_arrow_both(){return"style_arrow_both"}};Pe([N],Se.prototype,"new",1),Pe([N],Se.prototype,"set_x1",1),Pe([N],Se.prototype,"set_y1",1),Pe([N],Se.prototype,"set_x2",1),Pe([N],Se.prototype,"set_y2",1),Pe([N],Se.prototype,"set_xy1",1),Pe([N],Se.prototype,"set_xy2",1),Pe([N],Se.prototype,"set_color",1),Pe([N],Se.prototype,"set_width",1),Pe([N],Se.prototype,"set_style",1),Pe([N],Se.prototype,"set_extend",1),Pe([N],Se.prototype,"set_xloc",1),Pe([N],Se.prototype,"set_first_point",1),Pe([N],Se.prototype,"set_second_point",1),Pe([N],Se.prototype,"copy",1),Pe([N],Se.prototype,"delete",1);var Hy=Object.defineProperty,Gy=(t,e,r)=>e in t?Hy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,de=(t,e,r)=>Gy(t,typeof e!="symbol"?e+"":e,r),Yy=0,Ar=class t{constructor(e,r,n,i,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",h="",p="#000000",d="auto",f="center",m="center",x="wrap_none",b="default",w="format_none",v=!1){de(this,"id"),de(this,"left"),de(this,"top"),de(this,"right"),de(this,"bottom"),de(this,"xloc"),de(this,"extend"),de(this,"border_color"),de(this,"border_style"),de(this,"border_width"),de(this,"bgcolor"),de(this,"text"),de(this,"text_color"),de(this,"text_size"),de(this,"text_halign"),de(this,"text_valign"),de(this,"text_wrap"),de(this,"text_font_family"),de(this,"text_formatting"),de(this,"force_overlay"),de(this,"_deleted"),de(this,"_helper"),de(this,"_createdAtBar",-1),this.id=Yy++,this.left=e,this.top=r,this.right=n,this.bottom=i,this.xloc=s,this.extend=a,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=u,this.text=h,this.text_color=p,this.text_size=d,this.text_halign=f,this.text_valign=m,this.text_wrap=x,this.text_font_family=b,this.text_formatting=w,this.force_overlay=v,this._deleted=!1,this._helper=null}set_left(e){this._helper?this._helper.set_left(this,e):this._deleted||(this.left=e)}set_right(e){this._helper?this._helper.set_right(this,e):this._deleted||(this.right=e)}set_top(e){this._helper?this._helper.set_top(this,e):this._deleted||(this.top=e)}set_bottom(e){this._helper?this._helper.set_bottom(this,e):this._deleted||(this.bottom=e)}set_lefttop(e,r){this._helper?this._helper.set_lefttop(this,e,r):this._deleted||(this.left=e,this.top=r)}set_rightbottom(e,r){this._helper?this._helper.set_rightbottom(this,e,r):this._deleted||(this.right=e,this.bottom=r)}set_top_left_point(e){this._helper&&this._helper.set_top_left_point(this,e)}set_bottom_right_point(e){this._helper&&this._helper.set_bottom_right_point(this,e)}set_xloc(e,r,n){this._helper?this._helper.set_xloc(this,e,r,n):this._deleted||(this.left=e,this.right=r,this.xloc=n)}set_bgcolor(e){this._helper?this._helper.set_bgcolor(this,e):this._deleted||(this.bgcolor=e)}set_border_color(e){this._helper?this._helper.set_border_color(this,e):this._deleted||(this.border_color=e)}set_border_width(e){this._helper?this._helper.set_border_width(this,e):this._deleted||(this.border_width=e)}set_border_style(e){this._helper?this._helper.set_border_style(this,e):this._deleted||(this.border_style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_text_color(e){this._helper?this._helper.set_text_color(this,e):this._deleted||(this.text_color=e)}set_text_size(e){this._helper?this._helper.set_text_size(this,e):this._deleted||(this.text_size=e)}set_text_halign(e){this._helper?this._helper.set_text_halign(this,e):this._deleted||(this.text_halign=e)}set_text_valign(e){this._helper?this._helper.set_text_valign(this,e):this._deleted||(this.text_valign=e)}set_text_wrap(e){this._helper?this._helper.set_text_wrap(this,e):this._deleted||(this.text_wrap=e)}set_text_font_family(e){this._helper?this._helper.set_text_font_family(this,e):this._deleted||(this.text_font_family=e)}set_text_formatting(e){this._helper?this._helper.set_text_formatting(this,e):this._deleted||(this.text_formatting=e)}get_left(){return this.left}get_right(){return this.right}get_top(){return this.top}get_bottom(){return this.bottom}delete(){this._deleted=!0}toPlotData(){return{id:this.id,left:this.left,top:this.top,right:this.right,bottom:this.bottom,xloc:this.xloc,extend:this.extend,border_color:this.border_color,border_style:this.border_style,border_width:this.border_width,bgcolor:this.bgcolor,text:this.text,text_color:this.text_color,text_size:this.text_size,text_halign:this.text_halign,text_valign:this.text_valign,text_wrap:this.text_wrap,text_font_family:this.text_font_family,text_formatting:this.text_formatting,force_overlay:this.force_overlay,_deleted:this._deleted}}copy(){return new t(this.left,this.top,this.right,this.bottom,this.xloc,this.extend,this.border_color,this.border_style,this.border_width,this.bgcolor,this.text,this.text_color,this.text_size,this.text_halign,this.text_valign,this.text_wrap,this.text_font_family,this.text_formatting,this.force_overlay)}},Ja=Object.defineProperty,Zy=Object.getOwnPropertyDescriptor,Xy=(t,e,r)=>e in t?Ja(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ce=(t,e,r,n)=>{for(var i=n>1?void 0:n?Zy(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&Ja(e,r,i),i},Qy=(t,e,r)=>Xy(t,typeof e!="symbol"?e+"":e,r),Jy=[["left","top","right","bottom","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"],["top_left","bottom_right","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"]],eg={left:"number",top:"number",right:"number",bottom:"number",top_left:"point",bottom_right:"point",border_color:"color",border_width:"number",border_style:"string",extend:"string",xloc:"string",bgcolor:"color",text:"string",text_size:"string",text_color:"color",text_halign:"string",text_valign:"string",text_wrap:"string",text_font_family:"string",force_overlay:"boolean"},oe=class{constructor(e){this.context=e,Qy(this,"_boxes",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__boxes__||(this.context.plots.__boxes__={title:"__boxes__",data:[],options:{style:"drawing_box",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._boxes=this._boxes.filter(s=>!s._deleted);let r=this._boxes.map(s=>s.toPlotData()),n=r.filter(s=>!s.force_overlay),i=r.filter(s=>s.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:n,options:{style:"drawing_box"}}],i.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:i,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e){let r=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),n=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return r?{x:e.index,xloc:"bi"}:n?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Ze?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,r){let n=this._resolve(e);return n==null?n:typeof n=="number"&&isNaN(n)?NaN:n||r}_createBox(e,r,n,i,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",h="",p="#000000",d="auto",f="center",m="center",x="wrap_none",b="default",w="format_none",v=!1){let E=new Ar(e,r,n,i,s,this._resolve(a),this._resolveColor(o,"#2962ff"),this._resolve(l)||"style_solid",this._resolve(c)??1,this._resolveColor(u,"#2962ff"),this._resolve(h)||"",this._resolveColor(p,"#000000"),this._resolve(d)||"auto",this._resolve(f)||"center",this._resolve(m)||"center",this._resolve(x)||"wrap_none",this._resolve(b)||"default",this._resolve(w)||"format_none",v);return E._helper=this,E._createdAtBar=this.context.idx,this._boxes.push(E),this._enforceMaxCount(),E}_enforceMaxCount(){let e=this.context.indicator?.max_boxes_count??50,r=this._boxes.filter(n=>!n._deleted);if(r.length>e){let n=r.length-e,i=0;for(let s of this._boxes){if(i>=n)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let r=le(e,Jy,eg),n,i,s,a,o=r.xloc;if(r.top_left instanceof Oe){let l=r.top_left,c=r.bottom_right,u=this._resolvePoint(l);n=u.x,i=l.price,o=o||u.xloc,c instanceof Oe?(s=this._resolvePoint(c).x,a=c.price):(s=0,a=NaN)}else n=this._resolve(r.left),i=this._resolve(r.top),s=this._resolve(r.right),a=this._resolve(r.bottom);return this._createBox(n,i,s,a,o,r.extend,r.border_color,r.border_style,r.border_width,r.bgcolor,r.text,r.text_color,r.text_size,r.text_halign,r.text_valign,r.text_wrap,r.text_font_family,void 0,r.force_overlay)}any(...e){if(e.length===1){let r=e[0];if(r==null||r instanceof Ze||typeof r=="number"&&isNaN(r))return null;if(r instanceof Ar)return r;if(r instanceof y){let n=r.get(0);if(n==null||typeof n=="number"&&isNaN(n))return null;if(n instanceof Ar)return n}return null}return this.new(...e)}set_left(e,r){e&&!e._deleted&&(e.left=this._resolve(r))}set_right(e,r){e&&!e._deleted&&(e.right=this._resolve(r))}set_top(e,r){e&&!e._deleted&&(e.top=this._resolve(r))}set_bottom(e,r){e&&!e._deleted&&(e.bottom=this._resolve(r))}set_lefttop(e,r,n){e&&!e._deleted&&(e.left=this._resolve(r),e.top=this._resolve(n))}set_rightbottom(e,r,n){e&&!e._deleted&&(e.right=this._resolve(r),e.bottom=this._resolve(n))}set_top_left_point(e,r){if(e&&!e._deleted&&r){let n=this._resolvePoint(r);e.left=n.x,e.top=r.price,e.xloc=n.xloc}}set_bottom_right_point(e,r){if(e&&!e._deleted&&r){let n=this._resolvePoint(r);e.right=n.x,e.bottom=r.price,e.xloc=n.xloc}}set_xloc(e,r,n,i){e&&!e._deleted&&(e.left=this._resolve(r),e.right=this._resolve(n),e.xloc=this._resolve(i))}set_bgcolor(e,r){e&&!e._deleted&&(e.bgcolor=this._resolve(r))}set_border_color(e,r){e&&!e._deleted&&(e.border_color=this._resolve(r))}set_border_width(e,r){e&&!e._deleted&&(e.border_width=this._resolve(r)??1)}set_border_style(e,r){e&&!e._deleted&&(e.border_style=this._resolve(r))}set_extend(e,r){e&&!e._deleted&&(e.extend=this._resolve(r))}set_text(e,r){e&&!e._deleted&&(e.text=this._resolve(r)||"")}set_text_color(e,r){e&&!e._deleted&&(e.text_color=this._resolve(r))}set_text_size(e,r){e&&!e._deleted&&(e.text_size=this._resolve(r))}set_text_halign(e,r){e&&!e._deleted&&(e.text_halign=this._resolve(r))}set_text_valign(e,r){e&&!e._deleted&&(e.text_valign=this._resolve(r))}set_text_wrap(e,r){e&&!e._deleted&&(e.text_wrap=this._resolve(r))}set_text_font_family(e,r){e&&!e._deleted&&(e.text_font_family=this._resolve(r))}set_text_formatting(e,r){e&&!e._deleted&&(e.text_formatting=this._resolve(r))}get_left(e){return e?e.left:NaN}get_right(e){return e?e.right:NaN}get_top(e){return e?e.top:NaN}get_bottom(e){return e?e.bottom:NaN}copy(e){if(!e)return;let r=e.copy();return r._helper=this,r._createdAtBar=this.context.idx,this._boxes.push(r),this._enforceMaxCount(),r}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(r=>r._createdAtBar<e),this.syncToPlot()}};ce([N],oe.prototype,"new",1),ce([N],oe.prototype,"set_left",1),ce([N],oe.prototype,"set_right",1),ce([N],oe.prototype,"set_top",1),ce([N],oe.prototype,"set_bottom",1),ce([N],oe.prototype,"set_lefttop",1),ce([N],oe.prototype,"set_rightbottom",1),ce([N],oe.prototype,"set_top_left_point",1),ce([N],oe.prototype,"set_bottom_right_point",1),ce([N],oe.prototype,"set_xloc",1),ce([N],oe.prototype,"set_bgcolor",1),ce([N],oe.prototype,"set_border_color",1),ce([N],oe.prototype,"set_border_width",1),ce([N],oe.prototype,"set_border_style",1),ce([N],oe.prototype,"set_extend",1),ce([N],oe.prototype,"set_text",1),ce([N],oe.prototype,"set_text_color",1),ce([N],oe.prototype,"set_text_size",1),ce([N],oe.prototype,"set_text_halign",1),ce([N],oe.prototype,"set_text_valign",1),ce([N],oe.prototype,"set_text_wrap",1),ce([N],oe.prototype,"set_text_font_family",1),ce([N],oe.prototype,"set_text_formatting",1),ce([N],oe.prototype,"copy",1),ce([N],oe.prototype,"delete",1);var tg=Object.defineProperty,rg=(t,e,r)=>e in t?tg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cr=(t,e,r)=>rg(t,typeof e!="symbol"?e+"":e,r),ng=0,xn=class{constructor(e,r,n){cr(this,"id"),cr(this,"line1"),cr(this,"line2"),cr(this,"color"),cr(this,"_deleted"),cr(this,"_createdAtBar",-1),this.id=ng++,this.line1=e,this.line2=r,this.color=n,this._deleted=!1}get_line1(){return this.line1}get_line2(){return this.line2}set_color(e){this._deleted||(typeof e=="function"&&(e=e()),e&&typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"&&(e=e.get(0)),this.color=e||"")}delete(){this._deleted=!0}toPlotData(){let e=n=>n?{id:n.id,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,xloc:n.xloc,extend:n.extend,color:n.color,style:n.style,width:n.width,_deleted:n._deleted}:null,r=!!(this.line1?.force_overlay||this.line2?.force_overlay);return{id:this.id,line1:e(this.line1),line2:e(this.line2),color:this.color,force_overlay:r,_deleted:this._deleted}}},eo=Object.defineProperty,ig=Object.getOwnPropertyDescriptor,sg=(t,e,r)=>e in t?eo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ni=(t,e,r,n)=>{for(var i=n>1?void 0:n?ig(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&eo(e,r,i),i},ag=(t,e,r)=>sg(t,typeof e!="symbol"?e+"":e,r),fr=class{constructor(e){this.context=e,ag(this,"_linefills",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._linefills=this._linefills.filter(s=>!s._deleted);let r=this._linefills.map(s=>s.toPlotData()),n=r.filter(s=>!s.force_overlay),i=r.filter(s=>s.force_overlay);this.context.plots.__linefills__.data=[{time:e,value:n,options:{style:"linefill"}}],i.length>0?this.context.plots.__linefills_overlay__={title:"__linefills_overlay__",data:[{time:e,value:i,options:{style:"linefill"}}],options:{style:"linefill",overlay:!0}}:delete this.context.plots.__linefills_overlay__}_resolve(e){return e==null?e:e instanceof Ze?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){let r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r}new(e,r,n){let i=this._resolve(e),s=this._resolve(r),a=n&&typeof n=="object"&&!Array.isArray(n)&&"color"in n?n.color:n,o=this._resolveColor(a);if(i&&s){let c=i.id,u=s.id;for(let h of this._linefills){if(h._deleted)continue;let p=h.line1?.id,d=h.line2?.id;if(p===c&&d===u||p===u&&d===c)return h.color=o,h._createdAtBar=this.context.idx,h}}let l=new xn(i,s,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),l}any(...e){if(e.length===1){let r=e[0];return r==null||r instanceof Ze||typeof r=="number"&&isNaN(r)?null:r instanceof xn?r:null}return this.new(e[0],e[1],e[2])}set_color(e,r){e&&!e._deleted&&(e.color=this._resolveColor(r))}get_line1(e){return e?e.line1:void 0}get_line2(e){return e?e.line2:void 0}delete(e){e&&(e._deleted=!0)}get all(){return this._linefills.filter(e=>!e._deleted)}rollbackFromBar(e){this._linefills=this._linefills.filter(r=>r._createdAtBar<e),this.syncToPlot()}};ni([N],fr.prototype,"new",1),ni([N],fr.prototype,"set_color",1),ni([N],fr.prototype,"delete",1);var og=Object.defineProperty,lg=(t,e,r)=>e in t?og(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Je=(t,e,r)=>lg(t,typeof e!="symbol"?e+"":e,r),cg=0,Tr=class{constructor(e,r=!1,n=!1,i="bi",s="#2962ff",a="",o="style_solid",l=1,c=!1){Je(this,"id"),Je(this,"points"),Je(this,"curved"),Je(this,"closed"),Je(this,"xloc"),Je(this,"line_color"),Je(this,"fill_color"),Je(this,"line_style"),Je(this,"line_width"),Je(this,"force_overlay"),Je(this,"_deleted"),Je(this,"_createdAtBar",-1),this.id=cg++,this.points=e,this.curved=r,this.closed=n,this.xloc=i,this.line_color=s,this.fill_color=a,this.line_style=o,this.line_width=l,this.force_overlay=c,this._deleted=!1}delete(){this._deleted=!0}toPlotData(){return{id:this.id,points:this.points.map(e=>({time:e.time,index:e.index,price:e.price})),curved:this.curved,closed:this.closed,xloc:this.xloc,line_color:this.line_color,fill_color:this.fill_color,line_style:this.line_style,line_width:this.line_width,force_overlay:this.force_overlay,_deleted:this._deleted}}},to=Object.defineProperty,ug=Object.getOwnPropertyDescriptor,pg=(t,e,r)=>e in t?to(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qs=(t,e,r,n)=>{for(var i=n>1?void 0:n?ug(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&to(e,r,i),i},hg=(t,e,r)=>pg(t,typeof e!="symbol"?e+"":e,r),Or=class{constructor(e){this.context=e,hg(this,"_polylines",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__polylines__||(this.context.plots.__polylines__={title:"__polylines__",data:[],options:{style:"drawing_polyline",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._polylines=this._polylines.filter(r=>!r._deleted),this.context.plots.__polylines__.data=[{time:e,value:this._polylines.map(r=>r.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof Ze?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,r){let n=this._resolve(e);return n==null?n:typeof n=="number"&&isNaN(n)?NaN:n||r}_extractPoints(e){let r=this._resolve(e),n=r&&r.array?r.array:r;return Array.isArray(n)?n.filter(i=>i instanceof Oe):[]}new(...e){let r,n=!1,i=!1,s="bi",a="#2962ff",o="",l="style_solid",c=1,u=!1,h=(b,w)=>Object.prototype.hasOwnProperty.call(b,w),p=b=>{h(b,"curved")&&(n=b.curved),h(b,"closed")&&(i=b.closed),h(b,"xloc")&&(s=b.xloc),h(b,"line_color")&&(a=b.line_color),h(b,"fill_color")&&(o=b.fill_color),h(b,"line_style")&&(l=b.line_style),h(b,"line_width")&&(c=b.line_width),h(b,"force_overlay")&&(u=b.force_overlay)},d=e.length>=1?e[e.length-1]:null,f=e.length>=2&&d&&typeof d=="object"&&!Array.isArray(d)&&!(d instanceof y)&&!(d instanceof Oe);if(e.length===1&&d&&typeof d=="object"&&!Array.isArray(d)&&"points"in d)r=d.points,p(d);else{let b=f?e.slice(0,-1):e;r=b[0],b.length>1&&(n=b[1]),b.length>2&&(i=b[2]),b.length>3&&(s=b[3]),b.length>4&&(a=b[4]),b.length>5&&(o=b[5]),b.length>6&&(l=b[6]),b.length>7&&(c=b[7]),b.length>8&&(u=b[8]),f&&p(d)}let m=this._extractPoints(r),x=new Tr(m,this._resolve(n)??!1,this._resolve(i)??!1,this._resolve(s)||"bi",this._resolveColor(a,"#2962ff"),this._resolveColor(o,""),this._resolve(l)||"style_solid",this._resolve(c)||1,this._resolve(u)??!1);return x._createdAtBar=this.context.idx,this._polylines.push(x),this._enforceMaxCount(),x}_enforceMaxCount(){let e=this.context.indicator?.max_polylines_count??50,r=this._polylines.filter(n=>!n._deleted);if(r.length>e){let n=r.length-e,i=0;for(let s of this._polylines){if(i>=n)break;s._deleted||(s._deleted=!0,i++)}}}any(...e){if(e.length===1){let r=e[0];if(r==null||r instanceof Ze||typeof r=="number"&&isNaN(r))return null;if(r instanceof Tr)return r;if(r instanceof y){let n=r.get(0);if(n==null||typeof n=="number"&&isNaN(n))return null;if(n instanceof Tr)return n}return null}return this.new(...e)}delete(e){e&&(e._deleted=!0)}get all(){return this._polylines.filter(e=>!e._deleted)}rollbackFromBar(e){this._polylines=this._polylines.filter(r=>r._createdAtBar<e),this.syncToPlot()}};Qs([N],Or.prototype,"new",1),Qs([N],Or.prototype,"delete",1);var dg=Object.defineProperty,fg=(t,e,r)=>e in t?dg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e,r)=>fg(t,typeof e!="symbol"?e+"":e,r),mg=0,bn=class{constructor(e="top_right",r=1,n=1,i="",s="",a=0,o="",l=0,c=!1){We(this,"id"),We(this,"position"),We(this,"columns"),We(this,"rows"),We(this,"bgcolor"),We(this,"frame_color"),We(this,"frame_width"),We(this,"border_color"),We(this,"border_width"),We(this,"force_overlay"),We(this,"_deleted"),We(this,"cells"),We(this,"merges"),We(this,"_helper"),this.id=mg++,this.position=e,this.columns=r,this.rows=n,this.bgcolor=i,this.frame_color=s,this.frame_width=a,this.border_color=o,this.border_width=l,this.force_overlay=c,this._deleted=!1,this.merges=[],this.cells=[];for(let u=0;u<n;u++){this.cells[u]=[];for(let h=0;h<r;h++)this.cells[u][h]=null}}delete(){this._deleted=!0}toPlotData(){let e=this.cells.map(r=>r.map(n=>n?{...n}:null));return{id:this.id,position:this.position,columns:this.columns,rows:this.rows,bgcolor:this.bgcolor,frame_color:this.frame_color,frame_width:this.frame_width,border_color:this.border_color,border_width:this.border_width,force_overlay:this.force_overlay,_deleted:this._deleted,cells:e,merges:this.merges.map(r=>({...r}))}}setCell(e,r,n){if(r<0||r>=this.rows||e<0||e>=this.columns)return;let i=this.cells[r][e];if(i&&i._merged&&i._merge_parent){let[a,o]=i._merge_parent;if(a===e&&o===r)i._merged=!1,i._merge_parent=void 0;else{this.setCell(a,o,n);return}}let s=i||this._defaultCell();Object.assign(s,n),this.cells[r][e]=s}getCell(e,r){return r<0||r>=this.rows||e<0||e>=this.columns?null:this.cells[r][e]}clearCell(e,r){r<0||r>=this.rows||e<0||e>=this.columns||(this.cells[r][e]=null)}_setHelper(e){this._helper=e}cell(...e){return this._helper.cell(this,...e)}clear(...e){return this._helper.clear(this,...e)}merge_cells(...e){return this._helper.merge_cells(this,...e)}cell_set_text(...e){return this._helper.cell_set_text(this,...e)}cell_set_bgcolor(...e){return this._helper.cell_set_bgcolor(this,...e)}cell_set_text_color(...e){return this._helper.cell_set_text_color(this,...e)}cell_set_text_size(...e){return this._helper.cell_set_text_size(this,...e)}cell_set_height(...e){return this._helper.cell_set_height(this,...e)}cell_set_width(...e){return this._helper.cell_set_width(this,...e)}cell_set_tooltip(...e){return this._helper.cell_set_tooltip(this,...e)}cell_set_text_halign(...e){return this._helper.cell_set_text_halign(this,...e)}cell_set_text_valign(...e){return this._helper.cell_set_text_valign(this,...e)}cell_set_text_font_family(...e){return this._helper.cell_set_text_font_family(this,...e)}set_position(...e){return this._helper.set_position(this,...e)}set_bgcolor(...e){return this._helper.set_bgcolor(this,...e)}set_border_color(...e){return this._helper.set_border_color(this,...e)}set_border_width(...e){return this._helper.set_border_width(this,...e)}set_frame_color(...e){return this._helper.set_frame_color(this,...e)}set_frame_width(...e){return this._helper.set_frame_width(this,...e)}_defaultCell(){return{text:"",width:0,height:0,text_color:"#000000",text_halign:"center",text_valign:"center",text_size:"normal",bgcolor:"",tooltip:"",text_font_family:"default",_merged:!1,_merge_parent:null}}},ro=Object.defineProperty,yg=Object.getOwnPropertyDescriptor,gg=(t,e,r)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ye=(t,e,r,n)=>{for(var i=n>1?void 0:n?yg(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&ro(e,r,i),i},_g=(t,e,r)=>gg(t,typeof e!="symbol"?e+"":e,r),ue=class{constructor(e){this.context=e,_g(this,"_tables",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._tables=this._tables.filter(r=>!r._deleted),this.context.plots.__tables__.data=[{time:e,value:this._tables.map(r=>r.toPlotData()),options:{style:"table"}}]}_resolve(e){return e==null?e:typeof e=="object"&&"__value"in e?e.__value:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(...e){let r="top_right",n=1,i=1,s="",a="",o=0,l="",c=0,u=!1,h=e[e.length-1];if(h&&typeof h=="object"&&!Array.isArray(h)&&("bgcolor"in h||"frame_color"in h||"border_color"in h||"position"in h||"columns"in h||"rows"in h)){let d=h,f=e.slice(0,-1);r=f[0]??d.position??r,n=f[1]??d.columns??n,i=f[2]??d.rows??i,s=d.bgcolor??s,a=d.frame_color??a,o=d.frame_width??o,l=d.border_color??l,c=d.border_width??c,u=d.force_overlay??u}else r=e[0]??r,n=e[1]??n,i=e[2]??i,s=e[3]??s,a=e[4]??a,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u;let p=new bn(this._resolve(r)||"top_right",this._resolve(n)||1,this._resolve(i)||1,this._resolve(s)||"",this._resolve(a)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(u)??!1);return p._setHelper(this),this._tables.push(p),p}any(...e){if(e.length===1){let r=e[0];return r==null||typeof r=="object"&&"__value"in r||typeof r=="number"&&isNaN(r)?null:r instanceof bn?r:null}return this.new(...e)}cell(...e){let r,n,i,s="",a=0,o=0,l="#000000",c="center",u="center",h="normal",p="",d="",f="default",m=e[e.length-1];if(m&&typeof m=="object"&&!Array.isArray(m)&&("text"in m||"bgcolor"in m||"text_color"in m||"text_size"in m||"text_halign"in m||"tooltip"in m||"column"in m||"row"in m||"height"in m||"width"in m||"text_valign"in m||"text_font_family"in m)){let v=m,E=e.slice(0,-1);r=E[0],n=E.length>1?E[1]:v.column??0,i=E.length>2?E[2]:v.row??0,s=E[3]??v.text??s,a=E[4]??v.width??a,o=E[5]??v.height??o,l=E[6]??v.text_color??l,c=E[7]??v.text_halign??c,u=E[8]??v.text_valign??u,h=E[9]??v.text_size??h,p=E[10]??v.bgcolor??p,d=E[11]??v.tooltip??d,f=E[12]??v.text_font_family??f}else r=e[0],n=e[1]??0,i=e[2]??0,s=e[3]??s,a=e[4]??a,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u,h=e[9]??h,p=e[10]??p,d=e[11]??d,f=e[12]??f;let x=this._resolve(r);if(!x||x._deleted)return;let b=this._resolve(n)??0,w=this._resolve(i)??0;x.setCell(b,w,{text:this._resolveText(this._resolve(s)),width:this._resolve(a)||0,height:this._resolve(o)||0,text_color:this._resolve(l)||"#000000",text_halign:this._resolve(c)||"center",text_valign:this._resolve(u)||"center",text_size:this._resolve(h)||"normal",bgcolor:this._resolve(p)||"",tooltip:this._resolveText(this._resolve(d)),text_font_family:this._resolve(f)||"default"})}delete(e){e&&(e._deleted=!0)}clear(...e){let r,n,i,s,a,o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){let d=o;r=e[0],n=e.length>2?e[1]:d.start_column??0,i=e.length>3?e[2]:d.start_row??0,s=d.end_column??(e.length>4?e[3]:n),a=d.end_row??(e.length>5?e[4]:i)}else r=e[0],n=e[1]??0,i=e[2]??0,s=e[3]??n,a=e[4]??i;let l=this._resolve(r);if(!l||l._deleted)return;let c=this._resolve(n)??0,u=this._resolve(i)??0,h=this._resolve(s)??c,p=this._resolve(a)??u;for(let d=u;d<=p;d++)for(let f=c;f<=h;f++)l.clearCell(f,d)}merge_cells(...e){let r,n,i,s,a,o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){let d=o;r=e[0],n=e.length>2?e[1]:d.start_column??0,i=e.length>3?e[2]:d.start_row??0,s=d.end_column??(e.length>4?e[3]:0),a=d.end_row??(e.length>5?e[4]:0)}else r=e[0],n=e[1]??0,i=e[2]??0,s=e[3]??0,a=e[4]??0;let l=this._resolve(r);if(!l||l._deleted)return;let c=this._resolve(n)??0,u=this._resolve(i)??0,h=this._resolve(s)??0,p=this._resolve(a)??0;for(let d=u;d<=p;d++)for(let f=c;f<=h;f++)d===u&&f===c||l.setCell(f,d,{_merged:!0,_merge_parent:[c,u]});l.merges.push({startCol:c,startRow:u,endCol:h,endRow:p})}cell_set_text(e,r,n,i){this._setCellProp(e,r,n,"text",i,!0)}cell_set_bgcolor(e,r,n,i){this._setCellProp(e,r,n,"bgcolor",i)}cell_set_text_color(e,r,n,i){this._setCellProp(e,r,n,"text_color",i)}cell_set_text_size(e,r,n,i){this._setCellProp(e,r,n,"text_size",i)}cell_set_height(e,r,n,i){this._setCellProp(e,r,n,"height",i)}cell_set_width(e,r,n,i){this._setCellProp(e,r,n,"width",i)}cell_set_tooltip(e,r,n,i){this._setCellProp(e,r,n,"tooltip",i,!0)}cell_set_text_halign(e,r,n,i){this._setCellProp(e,r,n,"text_halign",i)}cell_set_text_valign(e,r,n,i){this._setCellProp(e,r,n,"text_valign",i)}cell_set_text_font_family(e,r,n,i){this._setCellProp(e,r,n,"text_font_family",i)}set_position(e,r){let n=this._resolve(e);!n||n._deleted||(n.position=this._resolve(r)||n.position)}set_bgcolor(e,r){let n=this._resolve(e);!n||n._deleted||(n.bgcolor=this._resolve(r)||"")}set_border_color(e,r){let n=this._resolve(e);!n||n._deleted||(n.border_color=this._resolve(r)||"")}set_border_width(e,r){let n=this._resolve(e);!n||n._deleted||(n.border_width=this._resolve(r)||0)}set_frame_color(e,r){let n=this._resolve(e);!n||n._deleted||(n.frame_color=this._resolve(r)||"")}set_frame_width(e,r){let n=this._resolve(e);!n||n._deleted||(n.frame_width=this._resolve(r)||0)}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,r,n,i,s,a=!1){let o=this._resolve(e);if(!o||o._deleted)return;let l=this._resolve(r)??0,c=this._resolve(n)??0,u=this._resolve(s);o.setCell(l,c,{[i]:a?this._resolveText(u):u})}_resolveText(e){return e==null||e!==e?"":String(e)}};ye([N],ue.prototype,"new",1),ye([N],ue.prototype,"cell",1),ye([N],ue.prototype,"delete",1),ye([N],ue.prototype,"clear",1),ye([N],ue.prototype,"merge_cells",1),ye([N],ue.prototype,"cell_set_text",1),ye([N],ue.prototype,"cell_set_bgcolor",1),ye([N],ue.prototype,"cell_set_text_color",1),ye([N],ue.prototype,"cell_set_text_size",1),ye([N],ue.prototype,"cell_set_height",1),ye([N],ue.prototype,"cell_set_width",1),ye([N],ue.prototype,"cell_set_tooltip",1),ye([N],ue.prototype,"cell_set_text_halign",1),ye([N],ue.prototype,"cell_set_text_valign",1),ye([N],ue.prototype,"cell_set_text_font_family",1),ye([N],ue.prototype,"set_position",1),ye([N],ue.prototype,"set_bgcolor",1),ye([N],ue.prototype,"set_border_color",1),ye([N],ue.prototype,"set_border_width",1),ye([N],ue.prototype,"set_frame_color",1),ye([N],ue.prototype,"set_frame_width",1);var Mi=class{constructor(e){this.context=e}param(e,r=0,n){return typeof e=="string"?e:y.from(e).get(r)}inherit(e,r){let n=this._coerce(e),i=Ot(this._coerce(r)),{modifier:s}=Lr(n);return s&&s!=="standard"?vi(i,s):i}new(e,r,n,i,s,a){let o=this._coerce(e),l=this._coerce(r);return o?l?`${o}:${l}`:o:l}modify(e,r,n,i,s){return this._coerce(e)}standard(e){return e==null?Ot(this.context?.pine?.syminfo?.tickerid||this.context?.tickerId||""):Ot(this._coerce(e))}heikinashi(e){return vi(this._coerce(e),"heikinashi")}renko(e,r,n,i,s){return this._coerce(e)}kagi(e,r){return this._coerce(e)}linebreak(e,r){return this._coerce(e)}pointfigure(e,r,n,i,s){return this._coerce(e)}_coerce(e){if(e==null)return"";if(e instanceof y){let r=e.get(0);return r==null?"":String(r)}return typeof e=="number"&&isNaN(e)?"":String(e)}},xg=Object.defineProperty,bg=(t,e,r)=>e in t?xg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,G=(t,e,r)=>bg(t,typeof e!="symbol"?e+"":e,r),Pi=class nn{constructor({marketData:e,source:r,tickerId:n,timeframe:i,limit:s,sDate:a,eDate:o,fullContext:l,inputs:c}){G(this,"data",{open:new y([]),high:new y([]),low:new y([]),close:new y([]),volume:new y([]),hl2:new y([]),hlc3:new y([]),ohlc4:new y([]),hlcc4:new y([]),bar_index:new y([])}),G(this,"indicator"),G(this,"cache",{}),G(this,"taState",{}),G(this,"strategy"),G(this,"isSecondaryContext",!1),G(this,"chartTimezone",null),G(this,"chartStyle","standard"),G(this,"dataVersion",0),G(this,"__maxLoops",5e5),G(this,"NA",NaN),G(this,"warnings",[]),G(this,"alerts",[]),G(this,"_alertMode","realtime"),G(this,"_propOverrides",{}),G(this,"_execTick",0),G(this,"lang"),G(this,"length",0),G(this,"_drawingHelpers",[]),G(this,"pine"),G(this,"idx",0),G(this,"params",{}),G(this,"const",{}),G(this,"var",{}),G(this,"let",{}),G(this,"lctx",new Map),G(this,"result"),G(this,"plots",{}),G(this,"marketData"),G(this,"source"),G(this,"tickerId"),G(this,"timeframe",""),G(this,"limit"),G(this,"sDate"),G(this,"eDate"),G(this,"fullContext"),G(this,"viewportLeft"),G(this,"viewportRight"),G(this,"pineTSCode"),G(this,"inputs",{}),G(this,"_callStack",[]),G(this,"_pathStack",[]),this.marketData=e,this.source=r,this.tickerId=n,this.timeframe=i,this.limit=s,this.sDate=a,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};let u=new pn(this),h={Type:u.Type.bind(u),na:new Ze,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),alert:new un(this),error:u.error.bind(u),max_bars_back:u.max_bars_back.bind(u),timestamp:u.timestamp.bind(u),time:new dn(this,"openTime"),time_close:new dn(this,"closeTime"),dayofmonth:new xt(this,Ft.dayofmonth),dayofweek:new xt(this,Ft.dayofweek),hour:new xt(this,Ft.hour),minute:new xt(this,Ft.minute),month:new xt(this,Ft.month),second:new xt(this,Ft.second),weekofyear:new xt(this,Ft.weekofyear),year:new xt(this,Ft.year),bool:u.bool.bind(u),int:u.int.bind(u),float:u.float.bind(u),string:u.string.bind(u)},p=this;this.pine={input:new xi(this),ta:new Ci(this),math:new bi(this),request:new Si(this),array:new pi(this),map:new hi(this),matrix:new di(this),ticker:new Mi(this),strategy:new ki(this),syminfo:null,timeframe:new Ti(this),barstate:new fi(this),get bar_index(){return p.data.bar_index},get last_bar_index(){return p.data.close.length-1},get last_bar_time(){let k=p.marketData;return Array.isArray(k)&&k.length>0?k[k.length-1].openTime:p.data.openTime.get(0)},get timenow(){return new Date().getTime()},get time_tradingday(){let k=y.from(p.data.closeTime).get(0);if(isNaN(k))return NaN;let V=p.pine?.syminfo?.timezone||"UTC",T=Zt(k,V);return Date.UTC(T.year,T.month-1,T.day,0,0,0)},get inputs(){return p.inputs},log:new Ii(this),str:new Ai(this),...h,...Ac};let d=h.dayofweek;Object.assign(d,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=d;let f=new dt(this),m=new gn(this),x=new _n(this);this.bindContextObject(f,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(f,["any","param","linestyle_dashed","linestyle_dotted","linestyle_solid","style_area","style_areabr","style_circles","style_columns","style_cross","style_histogram","style_line","style_linebr","style_stepline","style_stepline_diamond","style_steplinebr"],"plot"),this.bindContextObject(m,["any","style_dashed","style_solid","style_dotted","param"],"hline"),this.bindContextObject(x,["any","param"],"fill");let b=new Di(this);this.pine.chart={param:b.param.bind(b),bg_color:b.bg_color.bind(b),fg_color:b.fg_color.bind(b),get is_standard(){return b.is_standard()},get is_heikinashi(){return b.is_heikinashi()},get is_kagi(){return b.is_kagi()},get is_linebreak(){return b.is_linebreak()},get is_pnf(){return b.is_pnf()},get is_range(){return b.is_range()},get is_renko(){return b.is_renko()},point:b.point,get left_visible_bar_time(){if(p.viewportLeft!==void 0)return p.viewportLeft;let k=p.marketData;return Array.isArray(k)&&k.length>0?k[0].openTime:NaN},get right_visible_bar_time(){if(p.viewportRight!==void 0)return p.viewportRight;let k=p.marketData;return Array.isArray(k)&&k.length>0?k[k.length-1].openTime:NaN}};let w=new Ee(this);this.bindContextObject(w,["any","new","param","set_x","set_y","set_xy","set_text","set_color","set_textcolor","set_size","set_style","set_textalign","set_tooltip","set_point","set_xloc","set_yloc","get_x","get_y","get_text","copy","delete","style_label_down","style_label_up","style_label_left","style_label_right","style_label_lower_left","style_label_lower_right","style_label_upper_left","style_label_upper_right","style_label_center","style_circle","style_square","style_diamond","style_flag","style_arrowup","style_arrowdown","style_cross","style_xcross","style_triangleup","style_triangledown","style_none","style_text_outline"],"label"),Object.defineProperty(this.pine.label,"all",{get:()=>w.all});let v=new Se(this);this.bindContextObject(v,["any","new","param","set_x1","set_y1","set_x2","set_y2","set_xy1","set_xy2","set_color","set_width","set_style","set_extend","set_xloc","set_first_point","set_second_point","get_x1","get_y1","get_x2","get_y2","get_price","copy","delete","style_solid","style_dotted","style_dashed","style_arrow_left","style_arrow_right","style_arrow_both"],"line"),Object.defineProperty(this.pine.line,"all",{get:()=>v.all});let E=new oe(this);this.bindContextObject(E,["any","new","param","copy","delete","set_left","set_right","set_top","set_bottom","set_lefttop","set_rightbottom","set_top_left_point","set_bottom_right_point","set_bgcolor","set_border_color","set_border_width","set_border_style","set_extend","set_xloc","set_text","set_text_color","set_text_size","set_text_halign","set_text_valign","set_text_wrap","set_text_font_family","set_text_formatting","get_left","get_right","get_top","get_bottom"],"box"),Object.defineProperty(this.pine.box,"all",{get:()=>E.all});let A=new fr(this);this.bindContextObject(A,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>A.all});let C=new Or(this);this.bindContextObject(C,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>C.all});let D=new ue(this);this.bindContextObject(D,["any","new","param","cell","delete","clear","merge_cells","cell_set_text","cell_set_bgcolor","cell_set_text_color","cell_set_text_size","cell_set_height","cell_set_width","cell_set_tooltip","cell_set_text_halign","cell_set_text_valign","cell_set_text_font_family","set_position","set_bgcolor","set_border_color","set_border_width","set_frame_color","set_frame_width"],"table"),Object.defineProperty(this.pine.table,"all",{get:()=>D.all}),this._drawingHelpers=[w,v,E,A,C,D];let j=new yi(this);this.bindContextObject(j,["any","param","new","rgb","from_gradient","r","g","b","t","aqua","black","blue","fuchsia","gray","green","lime","maroon","navy","olive","orange","purple","red","silver","teal","white","yellow"],"color")}warn(e,r){this.warnings.push({message:e,method:r,bar:this.idx})}rollbackDrawings(e){for(let r of this._drawingHelpers)r.rollbackFromBar(e)}bindContextObject(e,r,n=""){n&&!this.pine[n]&&(this.pine[n]={});let i=n?this.pine[n]:this.pine;for(let s of r)typeof e[s]=="function"?i[s]=e[s].bind(e):i[s]=e[s]}init(e,r,n=0){let i;return r instanceof y?i=r.get(0):Array.isArray(r)?Array.isArray(r[0])?i=r[0]:i=r[r.length-1+n]:i=r,e?e instanceof y?(e.data[e.data.length-1]=i,e):Array.isArray(e)?(e[e.length-1]=i,new y(e)):new y([i]):new y([i])}initVar(e,r){if(e)return e;if(typeof r=="function"&&(r=r()),r instanceof Lt){let i=r.__def__;for(let s in i)typeof r[s]=="function"&&(r[s]=r[s]())}let n;return r instanceof y?n=r.get(0):Array.isArray(r)?Array.isArray(r[0])?n=r[0]:n=this.precision(r[r.length-1]):n=this.precision(r),new y([n])}precision(e,r=10){let n=r===10?nn.PRECISION_EPSILON:10**r;return typeof e=="number"?Math.round(e*n)/n:e}param(e,r,n){return typeof e=="string"?e:e instanceof y?r?new y(e.data,e.offset+r):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[n]||(this.params[n]=[]),Array.isArray(e)?new y(e,r||0):(this.params[n].length===0?this.params[n].push(e):this.params[n][this.params[n].length-1]=e,new y(this.params[n],r||0)))}get(e,r){if(typeof r=="number"&&!Number.isInteger(r)&&(r=Math.trunc(r)),e instanceof y)return e.get(r);if(Array.isArray(e)){let n=e.length-1-r;return n<0||n>=e.length?NaN:e[n]}return e}set(e,r){if(e instanceof y){e.set(0,typeof r=="number"?this.precision(r):r);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=r:e.push(r);return}}iter(e){return e==null?[]:Array.isArray(e.array)?e.array:e.map instanceof Map?e.map:e}entries(e){return e==null?[].entries():Array.isArray(e.array)?e.array.entries():e.map instanceof Map?e.map.entries():Array.isArray(e)||typeof e.entries=="function"?e.entries():[].entries()}pushId(e){let r=this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:"",n=r?r+"|"+e:e;this._callStack.push(e),this._pathStack.push(n)}popId(){this._callStack.pop(),this._pathStack.pop()}peekId(){return this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:""}peekCtx(){let e=this.peekId();if(!e)return this;let r=this.lctx.get(e);return r||(r={id:e,let:{},const:{},var:{}},this.lctx.set(e,r)),r}call(e,r,...n){this.pushId(r);try{return e(...n)}finally{this.popId()}}get math(){return this._showDeprecationWarning("const math = context.math","const { math, ta, input } = context.pine"),this.pine.math}get ta(){return this._showDeprecationWarning("const ta = context.ta","const { ta, math, input } = context.pine"),this.pine.ta}get input(){return this._showDeprecationWarning("const input = context.input","const { input, math, ta } = context.pine"),this.pine.input}get request(){return this._showDeprecationWarning("const request = context.request","const { request, math, ta } = context.pine"),this.pine.request}get array(){return this._showDeprecationWarning("const array = context.array","const { array, math, ta } = context.pine"),this.pine.array}get core(){return this._showDeprecationWarning("context.core.*","context.pine (e.g., const { na, plotchar, color, plot, nz } = context.pine)"),{na:this.pine.na,fill:this.pine.fill,plotchar:this.pine.plotchar,plotshape:this.pine.plotshape,plotarrow:this.pine.plotarrow,color:this.pine.color,plot:this.pine.plot,nz:this.pine.nz}}_showDeprecationWarning(e,r){let n=`${e}->${r}`;nn._deprecationWarningsShown.has(n)||(nn._deprecationWarningsShown.add(n),typeof window<"u"?console.warn("%c[WARNING]%c %s syntax is deprecated. Use %s instead. This will be removed in a future version.","color: #FFA500; font-weight: bold;","color: #FFA500;",e,r):console.warn(`\\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${r} instead. This will be removed in a future version.\\x1B[0m`))}};G(Pi,"_deprecationWarningsShown",new Set),G(Pi,"PRECISION_EPSILON",10**10);var Js=Pi,vg=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,7,9,32,4,318,1,78,5,71,10,50,3,123,2,54,14,32,10,3,1,11,3,46,10,8,0,46,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,3,0,158,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,68,8,2,0,3,0,2,3,2,4,2,0,15,1,83,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,7,19,58,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,199,7,137,9,54,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,55,9,266,3,10,1,2,0,49,6,4,4,14,10,5350,0,7,14,11465,27,2343,9,87,9,39,4,60,6,26,9,535,9,470,0,2,54,8,3,82,0,12,1,19628,1,4178,9,519,45,3,22,543,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,101,0,161,6,10,9,357,0,62,13,499,13,245,1,2,9,233,0,3,0,8,1,6,0,475,6,110,6,6,9,4759,9,787719,239],no=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,13,10,2,14,2,6,2,1,2,10,2,14,2,6,2,1,4,51,13,310,10,21,11,7,25,5,2,41,2,8,70,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,7,25,39,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,39,27,10,22,251,41,7,1,17,5,57,28,11,0,9,21,43,17,47,20,28,22,13,52,58,1,3,0,14,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,20,1,64,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,31,9,2,0,3,0,2,37,2,0,26,0,2,0,45,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,38,6,186,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,19,72,200,32,32,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,24,43,261,18,16,0,2,12,2,33,125,0,80,921,103,110,18,195,2637,96,16,1071,18,5,26,3994,6,582,6842,29,1763,568,8,30,18,78,18,29,19,47,17,3,32,20,6,18,433,44,212,63,33,24,3,24,45,74,6,0,67,12,65,1,2,0,15,4,10,7381,42,31,98,114,8702,3,2,6,2,1,2,290,16,0,30,2,3,0,15,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,1845,30,7,5,262,61,147,44,11,6,17,0,322,29,19,43,485,27,229,29,3,0,208,30,2,2,2,1,2,6,3,4,10,1,225,6,2,3,2,1,2,14,2,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42719,33,4381,3,5773,3,7472,16,621,2467,541,1507,4938,6,8489],wg="\\u200C\\u200D\\xB7\\u0300-\\u036F\\u0387\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u0669\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u06F0-\\u06F9\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07C0-\\u07C9\\u07EB-\\u07F3\\u07FD\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0859-\\u085B\\u0897-\\u089F\\u08CA-\\u08E1\\u08E3-\\u0903\\u093A-\\u093C\\u093E-\\u094F\\u0951-\\u0957\\u0962\\u0963\\u0966-\\u096F\\u0981-\\u0983\\u09BC\\u09BE-\\u09C4\\u09C7\\u09C8\\u09CB-\\u09CD\\u09D7\\u09E2\\u09E3\\u09E6-\\u09EF\\u09FE\\u0A01-\\u0A03\\u0A3C\\u0A3E-\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A66-\\u0A71\\u0A75\\u0A81-\\u0A83\\u0ABC\\u0ABE-\\u0AC5\\u0AC7-\\u0AC9\\u0ACB-\\u0ACD\\u0AE2\\u0AE3\\u0AE6-\\u0AEF\\u0AFA-\\u0AFF\\u0B01-\\u0B03\\u0B3C\\u0B3E-\\u0B44\\u0B47\\u0B48\\u0B4B-\\u0B4D\\u0B55-\\u0B57\\u0B62\\u0B63\\u0B66-\\u0B6F\\u0B82\\u0BBE-\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCD\\u0BD7\\u0BE6-\\u0BEF\\u0C00-\\u0C04\\u0C3C\\u0C3E-\\u0C44\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0C66-\\u0C6F\\u0C81-\\u0C83\\u0CBC\\u0CBE-\\u0CC4\\u0CC6-\\u0CC8\\u0CCA-\\u0CCD\\u0CD5\\u0CD6\\u0CE2\\u0CE3\\u0CE6-\\u0CEF\\u0CF3\\u0D00-\\u0D03\\u0D3B\\u0D3C\\u0D3E-\\u0D44\\u0D46-\\u0D48\\u0D4A-\\u0D4D\\u0D57\\u0D62\\u0D63\\u0D66-\\u0D6F\\u0D81-\\u0D83\\u0DCA\\u0DCF-\\u0DD4\\u0DD6\\u0DD8-\\u0DDF\\u0DE6-\\u0DEF\\u0DF2\\u0DF3\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0E50-\\u0E59\\u0EB1\\u0EB4-\\u0EBC\\u0EC8-\\u0ECE\\u0ED0-\\u0ED9\\u0F18\\u0F19\\u0F20-\\u0F29\\u0F35\\u0F37\\u0F39\\u0F3E\\u0F3F\\u0F71-\\u0F84\\u0F86\\u0F87\\u0F8D-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102B-\\u103E\\u1040-\\u1049\\u1056-\\u1059\\u105E-\\u1060\\u1062-\\u1064\\u1067-\\u106D\\u1071-\\u1074\\u1082-\\u108D\\u108F-\\u109D\\u135D-\\u135F\\u1369-\\u1371\\u1712-\\u1715\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B4-\\u17D3\\u17DD\\u17E0-\\u17E9\\u180B-\\u180D\\u180F-\\u1819\\u18A9\\u1920-\\u192B\\u1930-\\u193B\\u1946-\\u194F\\u19D0-\\u19DA\\u1A17-\\u1A1B\\u1A55-\\u1A5E\\u1A60-\\u1A7C\\u1A7F-\\u1A89\\u1A90-\\u1A99\\u1AB0-\\u1ABD\\u1ABF-\\u1ADD\\u1AE0-\\u1AEB\\u1B00-\\u1B04\\u1B34-\\u1B44\\u1B50-\\u1B59\\u1B6B-\\u1B73\\u1B80-\\u1B82\\u1BA1-\\u1BAD\\u1BB0-\\u1BB9\\u1BE6-\\u1BF3\\u1C24-\\u1C37\\u1C40-\\u1C49\\u1C50-\\u1C59\\u1CD0-\\u1CD2\\u1CD4-\\u1CE8\\u1CED\\u1CF4\\u1CF7-\\u1CF9\\u1DC0-\\u1DFF\\u200C\\u200D\\u203F\\u2040\\u2054\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2D7F\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\u30FB\\uA620-\\uA629\\uA66F\\uA674-\\uA67D\\uA69E\\uA69F\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA823-\\uA827\\uA82C\\uA880\\uA881\\uA8B4-\\uA8C5\\uA8D0-\\uA8D9\\uA8E0-\\uA8F1\\uA8FF-\\uA909\\uA926-\\uA92D\\uA947-\\uA953\\uA980-\\uA983\\uA9B3-\\uA9C0\\uA9D0-\\uA9D9\\uA9E5\\uA9F0-\\uA9F9\\uAA29-\\uAA36\\uAA43\\uAA4C\\uAA4D\\uAA50-\\uAA59\\uAA7B-\\uAA7D\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uAAEB-\\uAAEF\\uAAF5\\uAAF6\\uABE3-\\uABEA\\uABEC\\uABED\\uABF0-\\uABF9\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE2F\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF10-\\uFF19\\uFF3F\\uFF65",io="\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0560-\\u0588\\u05D0-\\u05EA\\u05EF-\\u05F2\\u0620-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u0860-\\u086A\\u0870-\\u0887\\u0889-\\u088F\\u08A0-\\u08C9\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u09FC\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0AF9\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58-\\u0C5A\\u0C5C\\u0C5D\\u0C60\\u0C61\\u0C80\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDC-\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D04-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D54-\\u0D56\\u0D5F-\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E86-\\u0E8A\\u0E8C-\\u0EA3\\u0EA5\\u0EA7-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F5\\u13F8-\\u13FD\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F8\\u1700-\\u1711\\u171F-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1878\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4C\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1C80-\\u1C8A\\u1C90-\\u1CBA\\u1CBD-\\u1CBF\\u1CE9-\\u1CEC\\u1CEE-\\u1CF3\\u1CF5\\u1CF6\\u1CFA\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2118-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2160-\\u2188\\u2C00-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u309B-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312F\\u3131-\\u318E\\u31A0-\\u31BF\\u31F0-\\u31FF\\u3400-\\u4DBF\\u4E00-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6EF\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA7DC\\uA7F1-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA8FD\\uA8FE\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB69\\uAB70-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC",ii={3:"abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",5:"class enum extends super const export import",6:"enum",strict:"implements interface let package private protected public static yield",strictBind:"eval arguments"},si="break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this",Eg={5:si,"5module":si+" export import",6:si+" const class extends export import super"},so=/^in(stanceof)?$/,Sg=new RegExp("["+io+"]"),Cg=new RegExp("["+io+wg+"]");function Ri(t,e){for(var r=65536,n=0;n<e.length;n+=2){if(r+=e[n],r>t)return!1;if(r+=e[n+1],r>=t)return!0}return!1}function Nt(t,e){return t<65?t===36:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&Sg.test(String.fromCharCode(t)):e===!1?!1:Ri(t,no)}function jt(t,e){return t<48?t===36:t<58?!0:t<65?!1:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&Cg.test(String.fromCharCode(t)):e===!1?!1:Ri(t,no)||Ri(t,vg)}var J=function(t,e){e===void 0&&(e={}),this.label=t,this.keyword=e.keyword,this.beforeExpr=!!e.beforeExpr,this.startsExpr=!!e.startsExpr,this.isLoop=!!e.isLoop,this.isAssign=!!e.isAssign,this.prefix=!!e.prefix,this.postfix=!!e.postfix,this.binop=e.binop||null,this.updateContext=null};function et(t,e){return new J(t,{beforeExpr:!0,binop:e})}var tt={beforeExpr:!0},Ue={startsExpr:!0},ps={};function Q(t,e){return e===void 0&&(e={}),e.keyword=t,ps[t]=new J(t,e)}var g={num:new J("num",Ue),regexp:new J("regexp",Ue),string:new J("string",Ue),name:new J("name",Ue),privateId:new J("privateId",Ue),eof:new J("eof"),bracketL:new J("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new J("]"),braceL:new J("{",{beforeExpr:!0,startsExpr:!0}),braceR:new J("}"),parenL:new J("(",{beforeExpr:!0,startsExpr:!0}),parenR:new J(")"),comma:new J(",",tt),semi:new J(";",tt),colon:new J(":",tt),dot:new J("."),question:new J("?",tt),questionDot:new J("?."),arrow:new J("=>",tt),template:new J("template"),invalidTemplate:new J("invalidTemplate"),ellipsis:new J("...",tt),backQuote:new J("`",Ue),dollarBraceL:new J("${",{beforeExpr:!0,startsExpr:!0}),eq:new J("=",{beforeExpr:!0,isAssign:!0}),assign:new J("_=",{beforeExpr:!0,isAssign:!0}),incDec:new J("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new J("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:et("||",1),logicalAND:et("&&",2),bitwiseOR:et("|",3),bitwiseXOR:et("^",4),bitwiseAND:et("&",5),equality:et("==/!=/===/!==",6),relational:et("</>/<=/>=",7),bitShift:et("<</>>/>>>",8),plusMin:new J("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:et("%",10),star:et("*",10),slash:et("/",10),starstar:new J("**",{beforeExpr:!0}),coalesce:et("??",1),_break:Q("break"),_case:Q("case",tt),_catch:Q("catch"),_continue:Q("continue"),_debugger:Q("debugger"),_default:Q("default",tt),_do:Q("do",{isLoop:!0,beforeExpr:!0}),_else:Q("else",tt),_finally:Q("finally"),_for:Q("for",{isLoop:!0}),_function:Q("function",Ue),_if:Q("if"),_return:Q("return",tt),_switch:Q("switch"),_throw:Q("throw",tt),_try:Q("try"),_var:Q("var"),_const:Q("const"),_while:Q("while",{isLoop:!0}),_with:Q("with"),_new:Q("new",{beforeExpr:!0,startsExpr:!0}),_this:Q("this",Ue),_super:Q("super",Ue),_class:Q("class",Ue),_extends:Q("extends",tt),_export:Q("export"),_import:Q("import",Ue),_null:Q("null",Ue),_true:Q("true",Ue),_false:Q("false",Ue),_in:Q("in",{beforeExpr:!0,binop:7}),_instanceof:Q("instanceof",{beforeExpr:!0,binop:7}),_typeof:Q("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:Q("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:Q("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},ze=/\\r\\n?|\\n|\\u2028|\\u2029/,Ng=new RegExp(ze.source,"g");function gr(t){return t===10||t===13||t===8232||t===8233}function ao(t,e,r){r===void 0&&(r=t.length);for(var n=e;n<r;n++){var i=t.charCodeAt(n);if(gr(i))return n<r-1&&i===13&&t.charCodeAt(n+1)===10?n+2:n+1}return-1}var oo=/[\\u1680\\u2000-\\u200a\\u202f\\u205f\\u3000\\ufeff]/,Re=/(?:\\s|\\/\\/.*|\\/\\*[^]*?\\*\\/)*/g,lo=Object.prototype,kg=lo.hasOwnProperty,Ig=lo.toString,_r=Object.hasOwn||(function(t,e){return kg.call(t,e)}),ea=Array.isArray||(function(t){return Ig.call(t)==="[object Array]"}),ta=Object.create(null);function Bt(t){return ta[t]||(ta[t]=new RegExp("^(?:"+t.replace(/ /g,"|")+")$"))}function Mt(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(t&1023)+56320))}var Ag=/(?:[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF])/,Vr=function(t,e){this.line=t,this.column=e};Vr.prototype.offset=function(t){return new Vr(this.line,this.column+t)};var Wn=function(t,e,r){this.start=e,this.end=r,t.sourceFile!==null&&(this.source=t.sourceFile)};function co(t,e){for(var r=1,n=0;;){var i=ao(t,n,e);if(i<0)return new Vr(r,e-n);++r,n=i}}var Fi={ecmaVersion:null,sourceType:"script",onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowAwaitOutsideFunction:null,allowSuperOutsideMethod:null,allowHashBang:!1,checkPrivateFields:!0,locations:!1,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1},ra=!1;function Tg(t){var e={};for(var r in Fi)e[r]=t&&_r(t,r)?t[r]:Fi[r];if(e.ecmaVersion==="latest"?e.ecmaVersion=1e8:e.ecmaVersion==null?(!ra&&typeof console=="object"&&console.warn&&(ra=!0,console.warn(`Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.`)),e.ecmaVersion=11):e.ecmaVersion>=2015&&(e.ecmaVersion-=2009),e.allowReserved==null&&(e.allowReserved=e.ecmaVersion<5),(!t||t.allowHashBang==null)&&(e.allowHashBang=e.ecmaVersion>=14),ea(e.onToken)){var n=e.onToken;e.onToken=function(i){return n.push(i)}}if(ea(e.onComment)&&(e.onComment=Dg(e,e.onComment)),e.sourceType==="commonjs"&&e.allowAwaitOutsideFunction)throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs");return e}function Dg(t,e){return function(r,n,i,s,a,o){var l={type:r?"Block":"Line",value:n,start:i,end:s};t.locations&&(l.loc=new Wn(this,a,o)),t.ranges&&(l.range=[i,s]),e.push(l)}}var Xt=1,Jt=2,hs=4,uo=8,ds=16,po=32,Un=64,ho=128,er=256,Wr=512,fo=1024,qn=Xt|Jt|er;function fs(t,e){return Jt|(t?hs:0)|(e?uo:0)}var vn=0,ms=1,Rt=2,mo=3,yo=4,go=5,Ie=function(t,e,r){this.options=t=Tg(t),this.sourceFile=t.sourceFile,this.keywords=Bt(Eg[t.ecmaVersion>=6?6:t.sourceType==="module"?"5module":5]);var n="";t.allowReserved!==!0&&(n=ii[t.ecmaVersion>=6?6:t.ecmaVersion===5?5:3],t.sourceType==="module"&&(n+=" await")),this.reservedWords=Bt(n);var i=(n?n+" ":"")+ii.strict;this.reservedWordsStrict=Bt(i),this.reservedWordsStrictBind=Bt(i+" "+ii.strictBind),this.input=String(e),this.containsEsc=!1,r?(this.pos=r,this.lineStart=this.input.lastIndexOf(`\n`,r-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(ze).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=g.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule=t.sourceType==="module",this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.potentialArrowInForAwait=!1,this.yieldPos=this.awaitPos=this.awaitIdentPos=0,this.labels=[],this.undefinedExports=Object.create(null),this.pos===0&&t.allowHashBang&&this.input.slice(0,2)==="#!"&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(this.options.sourceType==="commonjs"?Jt:Xt),this.regexpState=null,this.privateNameStack=[]},st={inFunction:{configurable:!0},inGenerator:{configurable:!0},inAsync:{configurable:!0},canAwait:{configurable:!0},allowReturn:{configurable:!0},allowSuper:{configurable:!0},allowDirectSuper:{configurable:!0},treatFunctionsAsVar:{configurable:!0},allowNewDotTarget:{configurable:!0},allowUsing:{configurable:!0},inClassStaticBlock:{configurable:!0}};Ie.prototype.parse=function(){var t=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(t)};st.inFunction.get=function(){return(this.currentVarScope().flags&Jt)>0};st.inGenerator.get=function(){return(this.currentVarScope().flags&uo)>0};st.inAsync.get=function(){return(this.currentVarScope().flags&hs)>0};st.canAwait.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],r=e.flags;if(r&(er|Wr))return!1;if(r&Jt)return(r&hs)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction};st.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&Xt)};st.allowSuper.get=function(){var t=this.currentThisScope(),e=t.flags;return(e&Un)>0||this.options.allowSuperOutsideMethod};st.allowDirectSuper.get=function(){return(this.currentThisScope().flags&ho)>0};st.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())};st.allowNewDotTarget.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],r=e.flags;if(r&(er|Wr)||r&Jt&&!(r&ds))return!0}return!1};st.allowUsing.get=function(){var t=this.currentScope(),e=t.flags;return!(e&fo||!this.inModule&&e&Xt)};st.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&er)>0};Ie.extend=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];for(var r=this,n=0;n<t.length;n++)r=t[n](r);return r};Ie.parse=function(t,e){return new this(e,t).parse()};Ie.parseExpressionAt=function(t,e,r){var n=new this(r,t,e);return n.nextToken(),n.parseExpression()};Ie.tokenizer=function(t,e){return new this(e,t)};Object.defineProperties(Ie.prototype,st);var je=Ie.prototype,Mg=/^(?:\'((?:\\\\[^]|[^\'\\\\])*?)\'|"((?:\\\\[^]|[^"\\\\])*?)")/;je.strictDirective=function(t){if(this.options.ecmaVersion<5)return!1;for(;;){Re.lastIndex=t,t+=Re.exec(this.input)[0].length;var e=Mg.exec(this.input.slice(t));if(!e)return!1;if((e[1]||e[2])==="use strict"){Re.lastIndex=t+e[0].length;var r=Re.exec(this.input),n=r.index+r[0].length,i=this.input.charAt(n);return i===";"||i==="}"||ze.test(r[0])&&!(/[(`.[+\\-/*%<>=,?^&]/.test(i)||i==="!"&&this.input.charAt(n+1)==="=")}t+=e[0].length,Re.lastIndex=t,t+=Re.exec(this.input)[0].length,this.input[t]===";"&&t++}};je.eat=function(t){return this.type===t?(this.next(),!0):!1};je.isContextual=function(t){return this.type===g.name&&this.value===t&&!this.containsEsc};je.eatContextual=function(t){return this.isContextual(t)?(this.next(),!0):!1};je.expectContextual=function(t){this.eatContextual(t)||this.unexpected()};je.canInsertSemicolon=function(){return this.type===g.eof||this.type===g.braceR||ze.test(this.input.slice(this.lastTokEnd,this.start))};je.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0};je.semicolon=function(){!this.eat(g.semi)&&!this.insertSemicolon()&&this.unexpected()};je.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0};je.expect=function(t){this.eat(t)||this.unexpected()};je.unexpected=function(t){this.raise(t??this.start,"Unexpected token")};var zn=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};je.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element");var r=e?t.parenthesizedAssign:t.parenthesizedBind;r>-1&&this.raiseRecoverable(r,e?"Assigning to rvalue":"Parenthesized pattern")}};je.checkExpressionErrors=function(t,e){if(!t)return!1;var r=t.shorthandAssign,n=t.doubleProto;if(!e)return r>=0||n>=0;r>=0&&this.raise(r,"Shorthand property assignments are valid only in destructuring patterns"),n>=0&&this.raiseRecoverable(n,"Redefinition of __proto__ property")};je.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos<this.awaitPos)&&this.raise(this.yieldPos,"Yield expression cannot be a default value"),this.awaitPos&&this.raise(this.awaitPos,"Await expression cannot be a default value")};je.isSimpleAssignTarget=function(t){return t.type==="ParenthesizedExpression"?this.isSimpleAssignTarget(t.expression):t.type==="Identifier"||t.type==="MemberExpression"};var L=Ie.prototype;L.parseTopLevel=function(t){var e=Object.create(null);for(t.body||(t.body=[]);this.type!==g.eof;){var r=this.parseStatement(null,!0,e);t.body.push(r)}if(this.inModule)for(var n=0,i=Object.keys(this.undefinedExports);n<i.length;n+=1){var s=i[n];this.raiseRecoverable(this.undefinedExports[s].start,"Export \'"+s+"\' is not defined")}return this.adaptDirectivePrologue(t.body),this.next(),t.sourceType=this.options.sourceType==="commonjs"?"script":this.options.sourceType,this.finishNode(t,"Program")};var ys={kind:"loop"},Pg={kind:"switch"};L.isLet=function(t){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;Re.lastIndex=this.pos;var e=Re.exec(this.input),r=this.pos+e[0].length,n=this.fullCharCodeAt(r);if(n===91||n===92)return!0;if(t)return!1;if(n===123)return!0;if(Nt(n)){var i=r;do r+=n<=65535?1:2;while(jt(n=this.fullCharCodeAt(r)));if(n===92)return!0;var s=this.input.slice(i,r);if(!so.test(s))return!0}return!1};L.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;Re.lastIndex=this.pos;var t=Re.exec(this.input),e=this.pos+t[0].length,r;return!ze.test(this.input.slice(this.pos,e))&&this.input.slice(e,e+8)==="function"&&(e+8===this.input.length||!(jt(r=this.fullCharCodeAt(e+8))||r===92))};L.isUsingKeyword=function(t,e){if(this.options.ecmaVersion<17||!this.isContextual(t?"await":"using"))return!1;Re.lastIndex=this.pos;var r=Re.exec(this.input),n=this.pos+r[0].length;if(ze.test(this.input.slice(this.pos,n)))return!1;if(t){var i=n+5,s;if(this.input.slice(n,i)!=="using"||i===this.input.length||jt(s=this.fullCharCodeAt(i))||s===92)return!1;Re.lastIndex=i;var a=Re.exec(this.input);if(n=i+a[0].length,a&&ze.test(this.input.slice(i,n)))return!1}var o=this.fullCharCodeAt(n);if(!Nt(o)&&o!==92)return!1;var l=n;do n+=o<=65535?1:2;while(jt(o=this.fullCharCodeAt(n)));if(o===92)return!0;var c=this.input.slice(l,n);return!(so.test(c)||e&&c==="of")};L.isAwaitUsing=function(t){return this.isUsingKeyword(!0,t)};L.isUsing=function(t){return this.isUsingKeyword(!1,t)};L.parseStatement=function(t,e,r){var n=this.type,i=this.startNode(),s;switch(this.isLet(t)&&(n=g._var,s="let"),n){case g._break:case g._continue:return this.parseBreakContinueStatement(i,n.keyword);case g._debugger:return this.parseDebuggerStatement(i);case g._do:return this.parseDoStatement(i);case g._for:return this.parseForStatement(i);case g._function:return t&&(this.strict||t!=="if"&&t!=="label")&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(i,!1,!t);case g._class:return t&&this.unexpected(),this.parseClass(i,!0);case g._if:return this.parseIfStatement(i);case g._return:return this.parseReturnStatement(i);case g._switch:return this.parseSwitchStatement(i);case g._throw:return this.parseThrowStatement(i);case g._try:return this.parseTryStatement(i);case g._const:case g._var:return s=s||this.value,t&&s!=="var"&&this.unexpected(),this.parseVarStatement(i,s);case g._while:return this.parseWhileStatement(i);case g._with:return this.parseWithStatement(i);case g.braceL:return this.parseBlock(!0,i);case g.semi:return this.parseEmptyStatement(i);case g._export:case g._import:if(this.options.ecmaVersion>10&&n===g._import){Re.lastIndex=this.pos;var a=Re.exec(this.input),o=this.pos+a[0].length,l=this.input.charCodeAt(o);if(l===40||l===46)return this.parseExpressionStatement(i,this.parseExpression())}return this.options.allowImportExportEverywhere||(e||this.raise(this.start,"\'import\' and \'export\' may only appear at the top level"),this.inModule||this.raise(this.start,"\'import\' and \'export\' may appear only with \'sourceType: module\'")),n===g._import?this.parseImport(i):this.parseExport(i,r);default:if(this.isAsyncFunction())return t&&this.unexpected(),this.next(),this.parseFunctionStatement(i,!0,!t);var c=this.isAwaitUsing(!1)?"await using":this.isUsing(!1)?"using":null;if(c)return this.allowUsing||this.raise(this.start,"Using declaration cannot appear in the top level when source type is `script` or in the bare case statement"),c==="await using"&&(this.canAwait||this.raise(this.start,"Await using cannot appear outside of async function"),this.next()),this.next(),this.parseVar(i,!1,c),this.semicolon(),this.finishNode(i,"VariableDeclaration");var u=this.value,h=this.parseExpression();return n===g.name&&h.type==="Identifier"&&this.eat(g.colon)?this.parseLabeledStatement(i,u,h,t):this.parseExpressionStatement(i,h)}};L.parseBreakContinueStatement=function(t,e){var r=e==="break";this.next(),this.eat(g.semi)||this.insertSemicolon()?t.label=null:this.type!==g.name?this.unexpected():(t.label=this.parseIdent(),this.semicolon());for(var n=0;n<this.labels.length;++n){var i=this.labels[n];if((t.label==null||i.name===t.label.name)&&(i.kind!=null&&(r||i.kind==="loop")||t.label&&r))break}return n===this.labels.length&&this.raise(t.start,"Unsyntactic "+e),this.finishNode(t,r?"BreakStatement":"ContinueStatement")};L.parseDebuggerStatement=function(t){return this.next(),this.semicolon(),this.finishNode(t,"DebuggerStatement")};L.parseDoStatement=function(t){return this.next(),this.labels.push(ys),t.body=this.parseStatement("do"),this.labels.pop(),this.expect(g._while),t.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(g.semi):this.semicolon(),this.finishNode(t,"DoWhileStatement")};L.parseForStatement=function(t){this.next();var e=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(ys),this.enterScope(0),this.expect(g.parenL),this.type===g.semi)return e>-1&&this.unexpected(e),this.parseFor(t,null);var r=this.isLet();if(this.type===g._var||this.type===g._const||r){var n=this.startNode(),i=r?"let":this.value;return this.next(),this.parseVar(n,!0,i),this.finishNode(n,"VariableDeclaration"),this.parseForAfterInit(t,n,e)}var s=this.isContextual("let"),a=!1,o=this.isUsing(!0)?"using":this.isAwaitUsing(!0)?"await using":null;if(o){var l=this.startNode();return this.next(),o==="await using"&&(this.canAwait||this.raise(this.start,"Await using cannot appear outside of async function"),this.next()),this.parseVar(l,!0,o),this.finishNode(l,"VariableDeclaration"),this.parseForAfterInit(t,l,e)}var c=this.containsEsc,u=new zn,h=this.start,p=e>-1?this.parseExprSubscripts(u,"await"):this.parseExpression(!0,u);return this.type===g._in||(a=this.options.ecmaVersion>=6&&this.isContextual("of"))?(e>-1?(this.type===g._in&&this.unexpected(e),t.await=!0):a&&this.options.ecmaVersion>=8&&(p.start===h&&!c&&p.type==="Identifier"&&p.name==="async"?this.unexpected():this.options.ecmaVersion>=9&&(t.await=!1)),s&&a&&this.raise(p.start,"The left-hand side of a for-of loop may not start with \'let\'."),this.toAssignable(p,!1,u),this.checkLValPattern(p),this.parseForIn(t,p)):(this.checkExpressionErrors(u,!0),e>-1&&this.unexpected(e),this.parseFor(t,p))};L.parseForAfterInit=function(t,e,r){return(this.type===g._in||this.options.ecmaVersion>=6&&this.isContextual("of"))&&e.declarations.length===1?(this.options.ecmaVersion>=9&&(this.type===g._in?r>-1&&this.unexpected(r):t.await=r>-1),this.parseForIn(t,e)):(r>-1&&this.unexpected(r),this.parseFor(t,e))};L.parseFunctionStatement=function(t,e,r){return this.next(),this.parseFunction(t,Dr|(r?0:Bi),!1,e)};L.parseIfStatement=function(t){return this.next(),t.test=this.parseParenExpression(),t.consequent=this.parseStatement("if"),t.alternate=this.eat(g._else)?this.parseStatement("if"):null,this.finishNode(t,"IfStatement")};L.parseReturnStatement=function(t){return this.allowReturn||this.raise(this.start,"\'return\' outside of function"),this.next(),this.eat(g.semi)||this.insertSemicolon()?t.argument=null:(t.argument=this.parseExpression(),this.semicolon()),this.finishNode(t,"ReturnStatement")};L.parseSwitchStatement=function(t){this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(g.braceL),this.labels.push(Pg),this.enterScope(fo);for(var e,r=!1;this.type!==g.braceR;)if(this.type===g._case||this.type===g._default){var n=this.type===g._case;e&&this.finishNode(e,"SwitchCase"),t.cases.push(e=this.startNode()),e.consequent=[],this.next(),n?e.test=this.parseExpression():(r&&this.raiseRecoverable(this.lastTokStart,"Multiple default clauses"),r=!0,e.test=null),this.expect(g.colon)}else e||this.unexpected(),e.consequent.push(this.parseStatement(null));return this.exitScope(),e&&this.finishNode(e,"SwitchCase"),this.next(),this.labels.pop(),this.finishNode(t,"SwitchStatement")};L.parseThrowStatement=function(t){return this.next(),ze.test(this.input.slice(this.lastTokEnd,this.start))&&this.raise(this.lastTokEnd,"Illegal newline after throw"),t.argument=this.parseExpression(),this.semicolon(),this.finishNode(t,"ThrowStatement")};var Rg=[];L.parseCatchClauseParam=function(){var t=this.parseBindingAtom(),e=t.type==="Identifier";return this.enterScope(e?po:0),this.checkLValPattern(t,e?yo:Rt),this.expect(g.parenR),t};L.parseTryStatement=function(t){if(this.next(),t.block=this.parseBlock(),t.handler=null,this.type===g._catch){var e=this.startNode();this.next(),this.eat(g.parenL)?e.param=this.parseCatchClauseParam():(this.options.ecmaVersion<10&&this.unexpected(),e.param=null,this.enterScope(0)),e.body=this.parseBlock(!1),this.exitScope(),t.handler=this.finishNode(e,"CatchClause")}return t.finalizer=this.eat(g._finally)?this.parseBlock():null,!t.handler&&!t.finalizer&&this.raise(t.start,"Missing catch or finally clause"),this.finishNode(t,"TryStatement")};L.parseVarStatement=function(t,e,r){return this.next(),this.parseVar(t,!1,e,r),this.semicolon(),this.finishNode(t,"VariableDeclaration")};L.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(ys),t.body=this.parseStatement("while"),this.labels.pop(),this.finishNode(t,"WhileStatement")};L.parseWithStatement=function(t){return this.strict&&this.raise(this.start,"\'with\' in strict mode"),this.next(),t.object=this.parseParenExpression(),t.body=this.parseStatement("with"),this.finishNode(t,"WithStatement")};L.parseEmptyStatement=function(t){return this.next(),this.finishNode(t,"EmptyStatement")};L.parseLabeledStatement=function(t,e,r,n){for(var i=0,s=this.labels;i<s.length;i+=1){var a=s[i];a.name===e&&this.raise(r.start,"Label \'"+e+"\' is already declared")}for(var o=this.type.isLoop?"loop":this.type===g._switch?"switch":null,l=this.labels.length-1;l>=0;l--){var c=this.labels[l];if(c.statementStart===t.start)c.statementStart=this.start,c.kind=o;else break}return this.labels.push({name:e,kind:o,statementStart:this.start}),t.body=this.parseStatement(n?n.indexOf("label")===-1?n+"label":n:"label"),this.labels.pop(),t.label=r,this.finishNode(t,"LabeledStatement")};L.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")};L.parseBlock=function(t,e,r){for(t===void 0&&(t=!0),e===void 0&&(e=this.startNode()),e.body=[],this.expect(g.braceL),t&&this.enterScope(0);this.type!==g.braceR;){var n=this.parseStatement(null);e.body.push(n)}return r&&(this.strict=!1),this.next(),t&&this.exitScope(),this.finishNode(e,"BlockStatement")};L.parseFor=function(t,e){return t.init=e,this.expect(g.semi),t.test=this.type===g.semi?null:this.parseExpression(),this.expect(g.semi),t.update=this.type===g.parenR?null:this.parseExpression(),this.expect(g.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,"ForStatement")};L.parseForIn=function(t,e){var r=this.type===g._in;return this.next(),e.type==="VariableDeclaration"&&e.declarations[0].init!=null&&(!r||this.options.ecmaVersion<8||this.strict||e.kind!=="var"||e.declarations[0].id.type!=="Identifier")&&this.raise(e.start,(r?"for-in":"for-of")+" loop variable declaration may not have an initializer"),t.left=e,t.right=r?this.parseExpression():this.parseMaybeAssign(),this.expect(g.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,r?"ForInStatement":"ForOfStatement")};L.parseVar=function(t,e,r,n){for(t.declarations=[],t.kind=r;;){var i=this.startNode();if(this.parseVarId(i,r),this.eat(g.eq)?i.init=this.parseMaybeAssign(e):!n&&r==="const"&&!(this.type===g._in||this.options.ecmaVersion>=6&&this.isContextual("of"))?this.unexpected():!n&&(r==="using"||r==="await using")&&this.options.ecmaVersion>=17&&this.type!==g._in&&!this.isContextual("of")?this.raise(this.lastTokEnd,"Missing initializer in "+r+" declaration"):!n&&i.id.type!=="Identifier"&&!(e&&(this.type===g._in||this.isContextual("of")))?this.raise(this.lastTokEnd,"Complex binding patterns require an initialization value"):i.init=null,t.declarations.push(this.finishNode(i,"VariableDeclarator")),!this.eat(g.comma))break}return t};L.parseVarId=function(t,e){t.id=e==="using"||e==="await using"?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(t.id,e==="var"?ms:Rt,!1)};var Dr=1,Bi=2,_o=4;L.parseFunction=function(t,e,r,n,i){this.initFunction(t),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!n)&&(this.type===g.star&&e&Bi&&this.unexpected(),t.generator=this.eat(g.star)),this.options.ecmaVersion>=8&&(t.async=!!n),e&Dr&&(t.id=e&_o&&this.type!==g.name?null:this.parseIdent(),t.id&&!(e&Bi)&&this.checkLValSimple(t.id,this.strict||t.generator||t.async?this.treatFunctionsAsVar?ms:Rt:mo));var s=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(fs(t.async,t.generator)),e&Dr||(t.id=this.type===g.name?this.parseIdent():null),this.parseFunctionParams(t),this.parseFunctionBody(t,r,!1,i),this.yieldPos=s,this.awaitPos=a,this.awaitIdentPos=o,this.finishNode(t,e&Dr?"FunctionDeclaration":"FunctionExpression")};L.parseFunctionParams=function(t){this.expect(g.parenL),t.params=this.parseBindingList(g.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()};L.parseClass=function(t,e){this.next();var r=this.strict;this.strict=!0,this.parseClassId(t,e),this.parseClassSuper(t);var n=this.enterClassBody(),i=this.startNode(),s=!1;for(i.body=[],this.expect(g.braceL);this.type!==g.braceR;){var a=this.parseClassElement(t.superClass!==null);a&&(i.body.push(a),a.type==="MethodDefinition"&&a.kind==="constructor"?(s&&this.raiseRecoverable(a.start,"Duplicate constructor in the same class"),s=!0):a.key&&a.key.type==="PrivateIdentifier"&&Fg(n,a)&&this.raiseRecoverable(a.key.start,"Identifier \'#"+a.key.name+"\' has already been declared"))}return this.strict=r,this.next(),t.body=this.finishNode(i,"ClassBody"),this.exitClassBody(),this.finishNode(t,e?"ClassDeclaration":"ClassExpression")};L.parseClassElement=function(t){if(this.eat(g.semi))return null;var e=this.options.ecmaVersion,r=this.startNode(),n="",i=!1,s=!1,a="method",o=!1;if(this.eatContextual("static")){if(e>=13&&this.eat(g.braceL))return this.parseClassStaticBlock(r),r;this.isClassElementNameStart()||this.type===g.star?o=!0:n="static"}if(r.static=o,!n&&e>=8&&this.eatContextual("async")&&((this.isClassElementNameStart()||this.type===g.star)&&!this.canInsertSemicolon()?s=!0:n="async"),!n&&(e>=9||!s)&&this.eat(g.star)&&(i=!0),!n&&!s&&!i){var l=this.value;(this.eatContextual("get")||this.eatContextual("set"))&&(this.isClassElementNameStart()?a=l:n=l)}if(n?(r.computed=!1,r.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),r.key.name=n,this.finishNode(r.key,"Identifier")):this.parseClassElementName(r),e<13||this.type===g.parenL||a!=="method"||i||s){var c=!r.static&&wn(r,"constructor"),u=c&&t;c&&a!=="method"&&this.raise(r.key.start,"Constructor can\'t have get/set modifier"),r.kind=c?"constructor":a,this.parseClassMethod(r,i,s,u)}else this.parseClassField(r);return r};L.isClassElementNameStart=function(){return this.type===g.name||this.type===g.privateId||this.type===g.num||this.type===g.string||this.type===g.bracketL||this.type.keyword};L.parseClassElementName=function(t){this.type===g.privateId?(this.value==="constructor"&&this.raise(this.start,"Classes can\'t have an element named \'#constructor\'"),t.computed=!1,t.key=this.parsePrivateIdent()):this.parsePropertyName(t)};L.parseClassMethod=function(t,e,r,n){var i=t.key;t.kind==="constructor"?(e&&this.raise(i.start,"Constructor can\'t be a generator"),r&&this.raise(i.start,"Constructor can\'t be an async method")):t.static&&wn(t,"prototype")&&this.raise(i.start,"Classes may not have a static property named prototype");var s=t.value=this.parseMethod(e,r,n);return t.kind==="get"&&s.params.length!==0&&this.raiseRecoverable(s.start,"getter should have no params"),t.kind==="set"&&s.params.length!==1&&this.raiseRecoverable(s.start,"setter should have exactly one param"),t.kind==="set"&&s.params[0].type==="RestElement"&&this.raiseRecoverable(s.params[0].start,"Setter cannot use rest params"),this.finishNode(t,"MethodDefinition")};L.parseClassField=function(t){return wn(t,"constructor")?this.raise(t.key.start,"Classes can\'t have a field named \'constructor\'"):t.static&&wn(t,"prototype")&&this.raise(t.key.start,"Classes can\'t have a static field named \'prototype\'"),this.eat(g.eq)?(this.enterScope(Wr|Un),t.value=this.parseMaybeAssign(),this.exitScope()):t.value=null,this.semicolon(),this.finishNode(t,"PropertyDefinition")};L.parseClassStaticBlock=function(t){t.body=[];var e=this.labels;for(this.labels=[],this.enterScope(er|Un);this.type!==g.braceR;){var r=this.parseStatement(null);t.body.push(r)}return this.next(),this.exitScope(),this.labels=e,this.finishNode(t,"StaticBlock")};L.parseClassId=function(t,e){this.type===g.name?(t.id=this.parseIdent(),e&&this.checkLValSimple(t.id,Rt,!1)):(e===!0&&this.unexpected(),t.id=null)};L.parseClassSuper=function(t){t.superClass=this.eat(g._extends)?this.parseExprSubscripts(null,!1):null};L.enterClassBody=function(){var t={declared:Object.create(null),used:[]};return this.privateNameStack.push(t),t.declared};L.exitClassBody=function(){var t=this.privateNameStack.pop(),e=t.declared,r=t.used;if(this.options.checkPrivateFields)for(var n=this.privateNameStack.length,i=n===0?null:this.privateNameStack[n-1],s=0;s<r.length;++s){var a=r[s];_r(e,a.name)||(i?i.used.push(a):this.raiseRecoverable(a.start,"Private field \'#"+a.name+"\' must be declared in an enclosing class"))}};function Fg(t,e){var r=e.key.name,n=t[r],i="true";return e.type==="MethodDefinition"&&(e.kind==="get"||e.kind==="set")&&(i=(e.static?"s":"i")+e.kind),n==="iget"&&i==="iset"||n==="iset"&&i==="iget"||n==="sget"&&i==="sset"||n==="sset"&&i==="sget"?(t[r]="true",!1):n?!0:(t[r]=i,!1)}function wn(t,e){var r=t.computed,n=t.key;return!r&&(n.type==="Identifier"&&n.name===e||n.type==="Literal"&&n.value===e)}L.parseExportAllDeclaration=function(t,e){return this.options.ecmaVersion>=11&&(this.eatContextual("as")?(t.exported=this.parseModuleExportName(),this.checkExport(e,t.exported,this.lastTokStart)):t.exported=null),this.expectContextual("from"),this.type!==g.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ExportAllDeclaration")};L.parseExport=function(t,e){if(this.next(),this.eat(g.star))return this.parseExportAllDeclaration(t,e);if(this.eat(g._default))return this.checkExport(e,"default",this.lastTokStart),t.declaration=this.parseExportDefaultDeclaration(),this.finishNode(t,"ExportDefaultDeclaration");if(this.shouldParseExportStatement())t.declaration=this.parseExportDeclaration(t),t.declaration.type==="VariableDeclaration"?this.checkVariableExport(e,t.declaration.declarations):this.checkExport(e,t.declaration.id,t.declaration.id.start),t.specifiers=[],t.source=null,this.options.ecmaVersion>=16&&(t.attributes=[]);else{if(t.declaration=null,t.specifiers=this.parseExportSpecifiers(e),this.eatContextual("from"))this.type!==g.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause());else{for(var r=0,n=t.specifiers;r<n.length;r+=1){var i=n[r];this.checkUnreserved(i.local),this.checkLocalExport(i.local),i.local.type==="Literal"&&this.raise(i.local.start,"A string literal cannot be used as an exported binding without `from`.")}t.source=null,this.options.ecmaVersion>=16&&(t.attributes=[])}this.semicolon()}return this.finishNode(t,"ExportNamedDeclaration")};L.parseExportDeclaration=function(t){return this.parseStatement(null)};L.parseExportDefaultDeclaration=function(){var t;if(this.type===g._function||(t=this.isAsyncFunction())){var e=this.startNode();return this.next(),t&&this.next(),this.parseFunction(e,Dr|_o,!1,t)}else if(this.type===g._class){var r=this.startNode();return this.parseClass(r,"nullableID")}else{var n=this.parseMaybeAssign();return this.semicolon(),n}};L.checkExport=function(t,e,r){t&&(typeof e!="string"&&(e=e.type==="Identifier"?e.name:e.value),_r(t,e)&&this.raiseRecoverable(r,"Duplicate export \'"+e+"\'"),t[e]=!0)};L.checkPatternExport=function(t,e){var r=e.type;if(r==="Identifier")this.checkExport(t,e,e.start);else if(r==="ObjectPattern")for(var n=0,i=e.properties;n<i.length;n+=1){var s=i[n];this.checkPatternExport(t,s)}else if(r==="ArrayPattern")for(var a=0,o=e.elements;a<o.length;a+=1){var l=o[a];l&&this.checkPatternExport(t,l)}else r==="Property"?this.checkPatternExport(t,e.value):r==="AssignmentPattern"?this.checkPatternExport(t,e.left):r==="RestElement"&&this.checkPatternExport(t,e.argument)};L.checkVariableExport=function(t,e){if(t)for(var r=0,n=e;r<n.length;r+=1){var i=n[r];this.checkPatternExport(t,i.id)}};L.shouldParseExportStatement=function(){return this.type.keyword==="var"||this.type.keyword==="const"||this.type.keyword==="class"||this.type.keyword==="function"||this.isLet()||this.isAsyncFunction()};L.parseExportSpecifier=function(t){var e=this.startNode();return e.local=this.parseModuleExportName(),e.exported=this.eatContextual("as")?this.parseModuleExportName():e.local,this.checkExport(t,e.exported,e.exported.start),this.finishNode(e,"ExportSpecifier")};L.parseExportSpecifiers=function(t){var e=[],r=!0;for(this.expect(g.braceL);!this.eat(g.braceR);){if(r)r=!1;else if(this.expect(g.comma),this.afterTrailingComma(g.braceR))break;e.push(this.parseExportSpecifier(t))}return e};L.parseImport=function(t){return this.next(),this.type===g.string?(t.specifiers=Rg,t.source=this.parseExprAtom()):(t.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),t.source=this.type===g.string?this.parseExprAtom():this.unexpected()),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ImportDeclaration")};L.parseImportSpecifier=function(){var t=this.startNode();return t.imported=this.parseModuleExportName(),this.eatContextual("as")?t.local=this.parseIdent():(this.checkUnreserved(t.imported),t.local=t.imported),this.checkLValSimple(t.local,Rt),this.finishNode(t,"ImportSpecifier")};L.parseImportDefaultSpecifier=function(){var t=this.startNode();return t.local=this.parseIdent(),this.checkLValSimple(t.local,Rt),this.finishNode(t,"ImportDefaultSpecifier")};L.parseImportNamespaceSpecifier=function(){var t=this.startNode();return this.next(),this.expectContextual("as"),t.local=this.parseIdent(),this.checkLValSimple(t.local,Rt),this.finishNode(t,"ImportNamespaceSpecifier")};L.parseImportSpecifiers=function(){var t=[],e=!0;if(this.type===g.name&&(t.push(this.parseImportDefaultSpecifier()),!this.eat(g.comma)))return t;if(this.type===g.star)return t.push(this.parseImportNamespaceSpecifier()),t;for(this.expect(g.braceL);!this.eat(g.braceR);){if(e)e=!1;else if(this.expect(g.comma),this.afterTrailingComma(g.braceR))break;t.push(this.parseImportSpecifier())}return t};L.parseWithClause=function(){var t=[];if(!this.eat(g._with))return t;this.expect(g.braceL);for(var e={},r=!0;!this.eat(g.braceR);){if(r)r=!1;else if(this.expect(g.comma),this.afterTrailingComma(g.braceR))break;var n=this.parseImportAttribute(),i=n.key.type==="Identifier"?n.key.name:n.key.value;_r(e,i)&&this.raiseRecoverable(n.key.start,"Duplicate attribute key \'"+i+"\'"),e[i]=!0,t.push(n)}return t};L.parseImportAttribute=function(){var t=this.startNode();return t.key=this.type===g.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never"),this.expect(g.colon),this.type!==g.string&&this.unexpected(),t.value=this.parseExprAtom(),this.finishNode(t,"ImportAttribute")};L.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===g.string){var t=this.parseLiteral(this.value);return Ag.test(t.value)&&this.raise(t.start,"An export name cannot include a lone surrogate."),t}return this.parseIdent(!0)};L.adaptDirectivePrologue=function(t){for(var e=0;e<t.length&&this.isDirectiveCandidate(t[e]);++e)t[e].directive=t[e].expression.raw.slice(1,-1)};L.isDirectiveCandidate=function(t){return this.options.ecmaVersion>=5&&t.type==="ExpressionStatement"&&t.expression.type==="Literal"&&typeof t.expression.value=="string"&&(this.input[t.start]===\'"\'||this.input[t.start]==="\'")};var at=Ie.prototype;at.toAssignable=function(t,e,r){if(this.options.ecmaVersion>=6&&t)switch(t.type){case"Identifier":this.inAsync&&t.name==="await"&&this.raise(t.start,"Cannot use \'await\' as identifier inside an async function");break;case"ObjectPattern":case"ArrayPattern":case"AssignmentPattern":case"RestElement":break;case"ObjectExpression":t.type="ObjectPattern",r&&this.checkPatternErrors(r,!0);for(var n=0,i=t.properties;n<i.length;n+=1){var s=i[n];this.toAssignable(s,e),s.type==="RestElement"&&(s.argument.type==="ArrayPattern"||s.argument.type==="ObjectPattern")&&this.raise(s.argument.start,"Unexpected token")}break;case"Property":t.kind!=="init"&&this.raise(t.key.start,"Object pattern can\'t contain getter or setter"),this.toAssignable(t.value,e);break;case"ArrayExpression":t.type="ArrayPattern",r&&this.checkPatternErrors(r,!0),this.toAssignableList(t.elements,e);break;case"SpreadElement":t.type="RestElement",this.toAssignable(t.argument,e),t.argument.type==="AssignmentPattern"&&this.raise(t.argument.start,"Rest elements cannot have a default value");break;case"AssignmentExpression":t.operator!=="="&&this.raise(t.left.end,"Only \'=\' operator can be used for specifying default value."),t.type="AssignmentPattern",delete t.operator,this.toAssignable(t.left,e);break;case"ParenthesizedExpression":this.toAssignable(t.expression,e,r);break;case"ChainExpression":this.raiseRecoverable(t.start,"Optional chaining cannot appear in left-hand side");break;case"MemberExpression":if(!e)break;default:this.raise(t.start,"Assigning to rvalue")}else r&&this.checkPatternErrors(r,!0);return t};at.toAssignableList=function(t,e){for(var r=t.length,n=0;n<r;n++){var i=t[n];i&&this.toAssignable(i,e)}if(r){var s=t[r-1];this.options.ecmaVersion===6&&e&&s&&s.type==="RestElement"&&s.argument.type!=="Identifier"&&this.unexpected(s.argument.start)}return t};at.parseSpread=function(t){var e=this.startNode();return this.next(),e.argument=this.parseMaybeAssign(!1,t),this.finishNode(e,"SpreadElement")};at.parseRestBinding=function(){var t=this.startNode();return this.next(),this.options.ecmaVersion===6&&this.type!==g.name&&this.unexpected(),t.argument=this.parseBindingAtom(),this.finishNode(t,"RestElement")};at.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case g.bracketL:var t=this.startNode();return this.next(),t.elements=this.parseBindingList(g.bracketR,!0,!0),this.finishNode(t,"ArrayPattern");case g.braceL:return this.parseObj(!0)}return this.parseIdent()};at.parseBindingList=function(t,e,r,n){for(var i=[],s=!0;!this.eat(t);)if(s?s=!1:this.expect(g.comma),e&&this.type===g.comma)i.push(null);else{if(r&&this.afterTrailingComma(t))break;if(this.type===g.ellipsis){var a=this.parseRestBinding();this.parseBindingListItem(a),i.push(a),this.type===g.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.expect(t);break}else i.push(this.parseAssignableListItem(n))}return i};at.parseAssignableListItem=function(t){var e=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(e),e};at.parseBindingListItem=function(t){return t};at.parseMaybeDefault=function(t,e,r){if(r=r||this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(g.eq))return r;var n=this.startNodeAt(t,e);return n.left=r,n.right=this.parseMaybeAssign(),this.finishNode(n,"AssignmentPattern")};at.checkLValSimple=function(t,e,r){e===void 0&&(e=vn);var n=e!==vn;switch(t.type){case"Identifier":this.strict&&this.reservedWordsStrictBind.test(t.name)&&this.raiseRecoverable(t.start,(n?"Binding ":"Assigning to ")+t.name+" in strict mode"),n&&(e===Rt&&t.name==="let"&&this.raiseRecoverable(t.start,"let is disallowed as a lexically bound name"),r&&(_r(r,t.name)&&this.raiseRecoverable(t.start,"Argument name clash"),r[t.name]=!0),e!==go&&this.declareName(t.name,e,t.start));break;case"ChainExpression":this.raiseRecoverable(t.start,"Optional chaining cannot appear in left-hand side");break;case"MemberExpression":n&&this.raiseRecoverable(t.start,"Binding member expression");break;case"ParenthesizedExpression":return n&&this.raiseRecoverable(t.start,"Binding parenthesized expression"),this.checkLValSimple(t.expression,e,r);default:this.raise(t.start,(n?"Binding":"Assigning to")+" rvalue")}};at.checkLValPattern=function(t,e,r){switch(e===void 0&&(e=vn),t.type){case"ObjectPattern":for(var n=0,i=t.properties;n<i.length;n+=1){var s=i[n];this.checkLValInnerPattern(s,e,r)}break;case"ArrayPattern":for(var a=0,o=t.elements;a<o.length;a+=1){var l=o[a];l&&this.checkLValInnerPattern(l,e,r)}break;default:this.checkLValSimple(t,e,r)}};at.checkLValInnerPattern=function(t,e,r){switch(e===void 0&&(e=vn),t.type){case"Property":this.checkLValInnerPattern(t.value,e,r);break;case"AssignmentPattern":this.checkLValPattern(t.left,e,r);break;case"RestElement":this.checkLValPattern(t.argument,e,r);break;default:this.checkLValPattern(t,e,r)}};var ct=function(t,e,r,n,i){this.token=t,this.isExpr=!!e,this.preserveSpace=!!r,this.override=n,this.generator=!!i},pe={b_stat:new ct("{",!1),b_expr:new ct("{",!0),b_tmpl:new ct("${",!1),p_stat:new ct("(",!1),p_expr:new ct("(",!0),q_tmpl:new ct("`",!0,!0,function(t){return t.tryReadTemplateToken()}),f_stat:new ct("function",!1),f_expr:new ct("function",!0),f_expr_gen:new ct("function",!0,!1,null,!0),f_gen:new ct("function",!1,!1,null,!0)},xr=Ie.prototype;xr.initialContext=function(){return[pe.b_stat]};xr.curContext=function(){return this.context[this.context.length-1]};xr.braceIsBlock=function(t){var e=this.curContext();return e===pe.f_expr||e===pe.f_stat?!0:t===g.colon&&(e===pe.b_stat||e===pe.b_expr)?!e.isExpr:t===g._return||t===g.name&&this.exprAllowed?ze.test(this.input.slice(this.lastTokEnd,this.start)):t===g._else||t===g.semi||t===g.eof||t===g.parenR||t===g.arrow?!0:t===g.braceL?e===pe.b_stat:t===g._var||t===g._const||t===g.name?!1:!this.exprAllowed};xr.inGeneratorContext=function(){for(var t=this.context.length-1;t>=1;t--){var e=this.context[t];if(e.token==="function")return e.generator}return!1};xr.updateContext=function(t){var e,r=this.type;r.keyword&&t===g.dot?this.exprAllowed=!1:(e=r.updateContext)?e.call(this,t):this.exprAllowed=r.beforeExpr};xr.overrideContext=function(t){this.curContext()!==t&&(this.context[this.context.length-1]=t)};g.parenR.updateContext=g.braceR.updateContext=function(){if(this.context.length===1){this.exprAllowed=!0;return}var t=this.context.pop();t===pe.b_stat&&this.curContext().token==="function"&&(t=this.context.pop()),this.exprAllowed=!t.isExpr};g.braceL.updateContext=function(t){this.context.push(this.braceIsBlock(t)?pe.b_stat:pe.b_expr),this.exprAllowed=!0};g.dollarBraceL.updateContext=function(){this.context.push(pe.b_tmpl),this.exprAllowed=!0};g.parenL.updateContext=function(t){var e=t===g._if||t===g._for||t===g._with||t===g._while;this.context.push(e?pe.p_stat:pe.p_expr),this.exprAllowed=!0};g.incDec.updateContext=function(){};g._function.updateContext=g._class.updateContext=function(t){t.beforeExpr&&t!==g._else&&!(t===g.semi&&this.curContext()!==pe.p_stat)&&!(t===g._return&&ze.test(this.input.slice(this.lastTokEnd,this.start)))&&!((t===g.colon||t===g.braceL)&&this.curContext()===pe.b_stat)?this.context.push(pe.f_expr):this.context.push(pe.f_stat),this.exprAllowed=!1};g.colon.updateContext=function(){this.curContext().token==="function"&&this.context.pop(),this.exprAllowed=!0};g.backQuote.updateContext=function(){this.curContext()===pe.q_tmpl?this.context.pop():this.context.push(pe.q_tmpl),this.exprAllowed=!1};g.star.updateContext=function(t){if(t===g._function){var e=this.context.length-1;this.context[e]===pe.f_expr?this.context[e]=pe.f_expr_gen:this.context[e]=pe.f_gen}this.exprAllowed=!0};g.name.updateContext=function(t){var e=!1;this.options.ecmaVersion>=6&&t!==g.dot&&(this.value==="of"&&!this.exprAllowed||this.value==="yield"&&this.inGeneratorContext())&&(e=!0),this.exprAllowed=e};var K=Ie.prototype;K.checkPropClash=function(t,e,r){if(!(this.options.ecmaVersion>=9&&t.type==="SpreadElement")&&!(this.options.ecmaVersion>=6&&(t.computed||t.method||t.shorthand))){var n=t.key,i;switch(n.type){case"Identifier":i=n.name;break;case"Literal":i=String(n.value);break;default:return}var s=t.kind;if(this.options.ecmaVersion>=6){i==="__proto__"&&s==="init"&&(e.proto&&(r?r.doubleProto<0&&(r.doubleProto=n.start):this.raiseRecoverable(n.start,"Redefinition of __proto__ property")),e.proto=!0);return}i="$"+i;var a=e[i];if(a){var o;s==="init"?o=this.strict&&a.init||a.get||a.set:o=a.init||a[s],o&&this.raiseRecoverable(n.start,"Redefinition of property")}else a=e[i]={init:!1,get:!1,set:!1};a[s]=!0}};K.parseExpression=function(t,e){var r=this.start,n=this.startLoc,i=this.parseMaybeAssign(t,e);if(this.type===g.comma){var s=this.startNodeAt(r,n);for(s.expressions=[i];this.eat(g.comma);)s.expressions.push(this.parseMaybeAssign(t,e));return this.finishNode(s,"SequenceExpression")}return i};K.parseMaybeAssign=function(t,e,r){if(this.isContextual("yield")){if(this.inGenerator)return this.parseYield(t);this.exprAllowed=!1}var n=!1,i=-1,s=-1,a=-1;e?(i=e.parenthesizedAssign,s=e.trailingComma,a=e.doubleProto,e.parenthesizedAssign=e.trailingComma=-1):(e=new zn,n=!0);var o=this.start,l=this.startLoc;(this.type===g.parenL||this.type===g.name)&&(this.potentialArrowAt=this.start,this.potentialArrowInForAwait=t==="await");var c=this.parseMaybeConditional(t,e);if(r&&(c=r.call(this,c,o,l)),this.type.isAssign){var u=this.startNodeAt(o,l);return u.operator=this.value,this.type===g.eq&&(c=this.toAssignable(c,!1,e)),n||(e.parenthesizedAssign=e.trailingComma=e.doubleProto=-1),e.shorthandAssign>=c.start&&(e.shorthandAssign=-1),this.type===g.eq?this.checkLValPattern(c):this.checkLValSimple(c),u.left=c,this.next(),u.right=this.parseMaybeAssign(t),a>-1&&(e.doubleProto=a),this.finishNode(u,"AssignmentExpression")}else n&&this.checkExpressionErrors(e,!0);return i>-1&&(e.parenthesizedAssign=i),s>-1&&(e.trailingComma=s),c};K.parseMaybeConditional=function(t,e){var r=this.start,n=this.startLoc,i=this.parseExprOps(t,e);if(this.checkExpressionErrors(e))return i;if(this.eat(g.question)){var s=this.startNodeAt(r,n);return s.test=i,s.consequent=this.parseMaybeAssign(),this.expect(g.colon),s.alternate=this.parseMaybeAssign(t),this.finishNode(s,"ConditionalExpression")}return i};K.parseExprOps=function(t,e){var r=this.start,n=this.startLoc,i=this.parseMaybeUnary(e,!1,!1,t);return this.checkExpressionErrors(e)||i.start===r&&i.type==="ArrowFunctionExpression"?i:this.parseExprOp(i,r,n,-1,t)};K.parseExprOp=function(t,e,r,n,i){var s=this.type.binop;if(s!=null&&(!i||this.type!==g._in)&&s>n){var a=this.type===g.logicalOR||this.type===g.logicalAND,o=this.type===g.coalesce;o&&(s=g.logicalAND.binop);var l=this.value;this.next();var c=this.start,u=this.startLoc,h=this.parseExprOp(this.parseMaybeUnary(null,!1,!1,i),c,u,s,i),p=this.buildBinary(e,r,t,h,l,a||o);return(a&&this.type===g.coalesce||o&&(this.type===g.logicalOR||this.type===g.logicalAND))&&this.raiseRecoverable(this.start,"Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"),this.parseExprOp(p,e,r,n,i)}return t};K.buildBinary=function(t,e,r,n,i,s){n.type==="PrivateIdentifier"&&this.raise(n.start,"Private identifier can only be left side of binary expression");var a=this.startNodeAt(t,e);return a.left=r,a.operator=i,a.right=n,this.finishNode(a,s?"LogicalExpression":"BinaryExpression")};K.parseMaybeUnary=function(t,e,r,n){var i=this.start,s=this.startLoc,a;if(this.isContextual("await")&&this.canAwait)a=this.parseAwait(n),e=!0;else if(this.type.prefix){var o=this.startNode(),l=this.type===g.incDec;o.operator=this.value,o.prefix=!0,this.next(),o.argument=this.parseMaybeUnary(null,!0,l,n),this.checkExpressionErrors(t,!0),l?this.checkLValSimple(o.argument):this.strict&&o.operator==="delete"&&xo(o.argument)?this.raiseRecoverable(o.start,"Deleting local variable in strict mode"):o.operator==="delete"&&Li(o.argument)?this.raiseRecoverable(o.start,"Private fields can not be deleted"):e=!0,a=this.finishNode(o,l?"UpdateExpression":"UnaryExpression")}else if(!e&&this.type===g.privateId)(n||this.privateNameStack.length===0)&&this.options.checkPrivateFields&&this.unexpected(),a=this.parsePrivateIdent(),this.type!==g._in&&this.unexpected();else{if(a=this.parseExprSubscripts(t,n),this.checkExpressionErrors(t))return a;for(;this.type.postfix&&!this.canInsertSemicolon();){var c=this.startNodeAt(i,s);c.operator=this.value,c.prefix=!1,c.argument=a,this.checkLValSimple(a),this.next(),a=this.finishNode(c,"UpdateExpression")}}if(!r&&this.eat(g.starstar))if(e)this.unexpected(this.lastTokStart);else return this.buildBinary(i,s,a,this.parseMaybeUnary(null,!1,!1,n),"**",!1);else return a};function xo(t){return t.type==="Identifier"||t.type==="ParenthesizedExpression"&&xo(t.expression)}function Li(t){return t.type==="MemberExpression"&&t.property.type==="PrivateIdentifier"||t.type==="ChainExpression"&&Li(t.expression)||t.type==="ParenthesizedExpression"&&Li(t.expression)}K.parseExprSubscripts=function(t,e){var r=this.start,n=this.startLoc,i=this.parseExprAtom(t,e);if(i.type==="ArrowFunctionExpression"&&this.input.slice(this.lastTokStart,this.lastTokEnd)!==")")return i;var s=this.parseSubscripts(i,r,n,!1,e);return t&&s.type==="MemberExpression"&&(t.parenthesizedAssign>=s.start&&(t.parenthesizedAssign=-1),t.parenthesizedBind>=s.start&&(t.parenthesizedBind=-1),t.trailingComma>=s.start&&(t.trailingComma=-1)),s};K.parseSubscripts=function(t,e,r,n,i){for(var s=this.options.ecmaVersion>=8&&t.type==="Identifier"&&t.name==="async"&&this.lastTokEnd===t.end&&!this.canInsertSemicolon()&&t.end-t.start===5&&this.potentialArrowAt===t.start,a=!1;;){var o=this.parseSubscript(t,e,r,n,s,a,i);if(o.optional&&(a=!0),o===t||o.type==="ArrowFunctionExpression"){if(a){var l=this.startNodeAt(e,r);l.expression=o,o=this.finishNode(l,"ChainExpression")}return o}t=o}};K.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(g.arrow)};K.parseSubscriptAsyncArrow=function(t,e,r,n){return this.parseArrowExpression(this.startNodeAt(t,e),r,!0,n)};K.parseSubscript=function(t,e,r,n,i,s,a){var o=this.options.ecmaVersion>=11,l=o&&this.eat(g.questionDot);n&&l&&this.raise(this.lastTokStart,"Optional chaining cannot appear in the callee of new expressions");var c=this.eat(g.bracketL);if(c||l&&this.type!==g.parenL&&this.type!==g.backQuote||this.eat(g.dot)){var u=this.startNodeAt(e,r);u.object=t,c?(u.property=this.parseExpression(),this.expect(g.bracketR)):this.type===g.privateId&&t.type!=="Super"?u.property=this.parsePrivateIdent():u.property=this.parseIdent(this.options.allowReserved!=="never"),u.computed=!!c,o&&(u.optional=l),t=this.finishNode(u,"MemberExpression")}else if(!n&&this.eat(g.parenL)){var h=new zn,p=this.yieldPos,d=this.awaitPos,f=this.awaitIdentPos;this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0;var m=this.parseExprList(g.parenR,this.options.ecmaVersion>=8,!1,h);if(i&&!l&&this.shouldParseAsyncArrow())return this.checkPatternErrors(h,!1),this.checkYieldAwaitInDefaultParams(),this.awaitIdentPos>0&&this.raise(this.awaitIdentPos,"Cannot use \'await\' as identifier inside an async function"),this.yieldPos=p,this.awaitPos=d,this.awaitIdentPos=f,this.parseSubscriptAsyncArrow(e,r,m,a);this.checkExpressionErrors(h,!0),this.yieldPos=p||this.yieldPos,this.awaitPos=d||this.awaitPos,this.awaitIdentPos=f||this.awaitIdentPos;var x=this.startNodeAt(e,r);x.callee=t,x.arguments=m,o&&(x.optional=l),t=this.finishNode(x,"CallExpression")}else if(this.type===g.backQuote){(l||s)&&this.raise(this.start,"Optional chaining cannot appear in the tag of tagged template expressions");var b=this.startNodeAt(e,r);b.tag=t,b.quasi=this.parseTemplate({isTagged:!0}),t=this.finishNode(b,"TaggedTemplateExpression")}return t};K.parseExprAtom=function(t,e,r){this.type===g.slash&&this.readRegexp();var n,i=this.potentialArrowAt===this.start;switch(this.type){case g._super:return this.allowSuper||this.raise(this.start,"\'super\' keyword outside a method"),n=this.startNode(),this.next(),this.type===g.parenL&&!this.allowDirectSuper&&this.raise(n.start,"super() call outside constructor of a subclass"),this.type!==g.dot&&this.type!==g.bracketL&&this.type!==g.parenL&&this.unexpected(),this.finishNode(n,"Super");case g._this:return n=this.startNode(),this.next(),this.finishNode(n,"ThisExpression");case g.name:var s=this.start,a=this.startLoc,o=this.containsEsc,l=this.parseIdent(!1);if(this.options.ecmaVersion>=8&&!o&&l.name==="async"&&!this.canInsertSemicolon()&&this.eat(g._function))return this.overrideContext(pe.f_expr),this.parseFunction(this.startNodeAt(s,a),0,!1,!0,e);if(i&&!this.canInsertSemicolon()){if(this.eat(g.arrow))return this.parseArrowExpression(this.startNodeAt(s,a),[l],!1,e);if(this.options.ecmaVersion>=8&&l.name==="async"&&this.type===g.name&&!o&&(!this.potentialArrowInForAwait||this.value!=="of"||this.containsEsc))return l=this.parseIdent(!1),(this.canInsertSemicolon()||!this.eat(g.arrow))&&this.unexpected(),this.parseArrowExpression(this.startNodeAt(s,a),[l],!0,e)}return l;case g.regexp:var c=this.value;return n=this.parseLiteral(c.value),n.regex={pattern:c.pattern,flags:c.flags},n;case g.num:case g.string:return this.parseLiteral(this.value);case g._null:case g._true:case g._false:return n=this.startNode(),n.value=this.type===g._null?null:this.type===g._true,n.raw=this.type.keyword,this.next(),this.finishNode(n,"Literal");case g.parenL:var u=this.start,h=this.parseParenAndDistinguishExpression(i,e);return t&&(t.parenthesizedAssign<0&&!this.isSimpleAssignTarget(h)&&(t.parenthesizedAssign=u),t.parenthesizedBind<0&&(t.parenthesizedBind=u)),h;case g.bracketL:return n=this.startNode(),this.next(),n.elements=this.parseExprList(g.bracketR,!0,!0,t),this.finishNode(n,"ArrayExpression");case g.braceL:return this.overrideContext(pe.b_expr),this.parseObj(!1,t);case g._function:return n=this.startNode(),this.next(),this.parseFunction(n,0);case g._class:return this.parseClass(this.startNode(),!1);case g._new:return this.parseNew();case g.backQuote:return this.parseTemplate();case g._import:return this.options.ecmaVersion>=11?this.parseExprImport(r):this.unexpected();default:return this.parseExprAtomDefault()}};K.parseExprAtomDefault=function(){this.unexpected()};K.parseExprImport=function(t){var e=this.startNode();if(this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword import"),this.next(),this.type===g.parenL&&!t)return this.parseDynamicImport(e);if(this.type===g.dot){var r=this.startNodeAt(e.start,e.loc&&e.loc.start);return r.name="import",e.meta=this.finishNode(r,"Identifier"),this.parseImportMeta(e)}else this.unexpected()};K.parseDynamicImport=function(t){if(this.next(),t.source=this.parseMaybeAssign(),this.options.ecmaVersion>=16)this.eat(g.parenR)?t.options=null:(this.expect(g.comma),this.afterTrailingComma(g.parenR)?t.options=null:(t.options=this.parseMaybeAssign(),this.eat(g.parenR)||(this.expect(g.comma),this.afterTrailingComma(g.parenR)||this.unexpected())));else if(!this.eat(g.parenR)){var e=this.start;this.eat(g.comma)&&this.eat(g.parenR)?this.raiseRecoverable(e,"Trailing comma is not allowed in import()"):this.unexpected(e)}return this.finishNode(t,"ImportExpression")};K.parseImportMeta=function(t){this.next();var e=this.containsEsc;return t.property=this.parseIdent(!0),t.property.name!=="meta"&&this.raiseRecoverable(t.property.start,"The only valid meta property for import is \'import.meta\'"),e&&this.raiseRecoverable(t.start,"\'import.meta\' must not contain escaped characters"),this.options.sourceType!=="module"&&!this.options.allowImportExportEverywhere&&this.raiseRecoverable(t.start,"Cannot use \'import.meta\' outside a module"),this.finishNode(t,"MetaProperty")};K.parseLiteral=function(t){var e=this.startNode();return e.value=t,e.raw=this.input.slice(this.start,this.end),e.raw.charCodeAt(e.raw.length-1)===110&&(e.bigint=e.value!=null?e.value.toString():e.raw.slice(0,-1).replace(/_/g,"")),this.next(),this.finishNode(e,"Literal")};K.parseParenExpression=function(){this.expect(g.parenL);var t=this.parseExpression();return this.expect(g.parenR),t};K.shouldParseArrow=function(t){return!this.canInsertSemicolon()};K.parseParenAndDistinguishExpression=function(t,e){var r=this.start,n=this.startLoc,i,s=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var a=this.start,o=this.startLoc,l=[],c=!0,u=!1,h=new zn,p=this.yieldPos,d=this.awaitPos,f;for(this.yieldPos=0,this.awaitPos=0;this.type!==g.parenR;)if(c?c=!1:this.expect(g.comma),s&&this.afterTrailingComma(g.parenR,!0)){u=!0;break}else if(this.type===g.ellipsis){f=this.start,l.push(this.parseParenItem(this.parseRestBinding())),this.type===g.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element");break}else l.push(this.parseMaybeAssign(!1,h,this.parseParenItem));var m=this.lastTokEnd,x=this.lastTokEndLoc;if(this.expect(g.parenR),t&&this.shouldParseArrow(l)&&this.eat(g.arrow))return this.checkPatternErrors(h,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=p,this.awaitPos=d,this.parseParenArrowList(r,n,l,e);(!l.length||u)&&this.unexpected(this.lastTokStart),f&&this.unexpected(f),this.checkExpressionErrors(h,!0),this.yieldPos=p||this.yieldPos,this.awaitPos=d||this.awaitPos,l.length>1?(i=this.startNodeAt(a,o),i.expressions=l,this.finishNodeAt(i,"SequenceExpression",m,x)):i=l[0]}else i=this.parseParenExpression();if(this.options.preserveParens){var b=this.startNodeAt(r,n);return b.expression=i,this.finishNode(b,"ParenthesizedExpression")}else return i};K.parseParenItem=function(t){return t};K.parseParenArrowList=function(t,e,r,n){return this.parseArrowExpression(this.startNodeAt(t,e),r,!1,n)};var Bg=[];K.parseNew=function(){this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword new");var t=this.startNode();if(this.next(),this.options.ecmaVersion>=6&&this.type===g.dot){var e=this.startNodeAt(t.start,t.loc&&t.loc.start);e.name="new",t.meta=this.finishNode(e,"Identifier"),this.next();var r=this.containsEsc;return t.property=this.parseIdent(!0),t.property.name!=="target"&&this.raiseRecoverable(t.property.start,"The only valid meta property for new is \'new.target\'"),r&&this.raiseRecoverable(t.start,"\'new.target\' must not contain escaped characters"),this.allowNewDotTarget||this.raiseRecoverable(t.start,"\'new.target\' can only be used in functions and class static block"),this.finishNode(t,"MetaProperty")}var n=this.start,i=this.startLoc;return t.callee=this.parseSubscripts(this.parseExprAtom(null,!1,!0),n,i,!0,!1),this.eat(g.parenL)?t.arguments=this.parseExprList(g.parenR,this.options.ecmaVersion>=8,!1):t.arguments=Bg,this.finishNode(t,"NewExpression")};K.parseTemplateElement=function(t){var e=t.isTagged,r=this.startNode();return this.type===g.invalidTemplate?(e||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),r.value={raw:this.value.replace(/\\r\\n?/g,`\n`),cooked:null}):r.value={raw:this.input.slice(this.start,this.end).replace(/\\r\\n?/g,`\n`),cooked:this.value},this.next(),r.tail=this.type===g.backQuote,this.finishNode(r,"TemplateElement")};K.parseTemplate=function(t){t===void 0&&(t={});var e=t.isTagged;e===void 0&&(e=!1);var r=this.startNode();this.next(),r.expressions=[];var n=this.parseTemplateElement({isTagged:e});for(r.quasis=[n];!n.tail;)this.type===g.eof&&this.raise(this.pos,"Unterminated template literal"),this.expect(g.dollarBraceL),r.expressions.push(this.parseExpression()),this.expect(g.braceR),r.quasis.push(n=this.parseTemplateElement({isTagged:e}));return this.next(),this.finishNode(r,"TemplateLiteral")};K.isAsyncProp=function(t){return!t.computed&&t.key.type==="Identifier"&&t.key.name==="async"&&(this.type===g.name||this.type===g.num||this.type===g.string||this.type===g.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===g.star)&&!ze.test(this.input.slice(this.lastTokEnd,this.start))};K.parseObj=function(t,e){var r=this.startNode(),n=!0,i={};for(r.properties=[],this.next();!this.eat(g.braceR);){if(n)n=!1;else if(this.expect(g.comma),this.options.ecmaVersion>=5&&this.afterTrailingComma(g.braceR))break;var s=this.parseProperty(t,e);t||this.checkPropClash(s,i,e),r.properties.push(s)}return this.finishNode(r,t?"ObjectPattern":"ObjectExpression")};K.parseProperty=function(t,e){var r=this.startNode(),n,i,s,a;if(this.options.ecmaVersion>=9&&this.eat(g.ellipsis))return t?(r.argument=this.parseIdent(!1),this.type===g.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.finishNode(r,"RestElement")):(r.argument=this.parseMaybeAssign(!1,e),this.type===g.comma&&e&&e.trailingComma<0&&(e.trailingComma=this.start),this.finishNode(r,"SpreadElement"));this.options.ecmaVersion>=6&&(r.method=!1,r.shorthand=!1,(t||e)&&(s=this.start,a=this.startLoc),t||(n=this.eat(g.star)));var o=this.containsEsc;return this.parsePropertyName(r),!t&&!o&&this.options.ecmaVersion>=8&&!n&&this.isAsyncProp(r)?(i=!0,n=this.options.ecmaVersion>=9&&this.eat(g.star),this.parsePropertyName(r)):i=!1,this.parsePropertyValue(r,t,n,i,s,a,e,o),this.finishNode(r,"Property")};K.parseGetterSetter=function(t){var e=t.key.name;this.parsePropertyName(t),t.value=this.parseMethod(!1),t.kind=e;var r=t.kind==="get"?0:1;if(t.value.params.length!==r){var n=t.value.start;t.kind==="get"?this.raiseRecoverable(n,"getter should have no params"):this.raiseRecoverable(n,"setter should have exactly one param")}else t.kind==="set"&&t.value.params[0].type==="RestElement"&&this.raiseRecoverable(t.value.params[0].start,"Setter cannot use rest params")};K.parsePropertyValue=function(t,e,r,n,i,s,a,o){(r||n)&&this.type===g.colon&&this.unexpected(),this.eat(g.colon)?(t.value=e?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,a),t.kind="init"):this.options.ecmaVersion>=6&&this.type===g.parenL?(e&&this.unexpected(),t.method=!0,t.value=this.parseMethod(r,n),t.kind="init"):!e&&!o&&this.options.ecmaVersion>=5&&!t.computed&&t.key.type==="Identifier"&&(t.key.name==="get"||t.key.name==="set")&&this.type!==g.comma&&this.type!==g.braceR&&this.type!==g.eq?((r||n)&&this.unexpected(),this.parseGetterSetter(t)):this.options.ecmaVersion>=6&&!t.computed&&t.key.type==="Identifier"?((r||n)&&this.unexpected(),this.checkUnreserved(t.key),t.key.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=i),e?t.value=this.parseMaybeDefault(i,s,this.copyNode(t.key)):this.type===g.eq&&a?(a.shorthandAssign<0&&(a.shorthandAssign=this.start),t.value=this.parseMaybeDefault(i,s,this.copyNode(t.key))):t.value=this.copyNode(t.key),t.kind="init",t.shorthand=!0):this.unexpected()};K.parsePropertyName=function(t){if(this.options.ecmaVersion>=6){if(this.eat(g.bracketL))return t.computed=!0,t.key=this.parseMaybeAssign(),this.expect(g.bracketR),t.key;t.computed=!1}return t.key=this.type===g.num||this.type===g.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never")};K.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)};K.parseMethod=function(t,e,r){var n=this.startNode(),i=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.initFunction(n),this.options.ecmaVersion>=6&&(n.generator=t),this.options.ecmaVersion>=8&&(n.async=!!e),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(fs(e,n.generator)|Un|(r?ho:0)),this.expect(g.parenL),n.params=this.parseBindingList(g.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(n,!1,!0,!1),this.yieldPos=i,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(n,"FunctionExpression")};K.parseArrowExpression=function(t,e,r,n){var i=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.enterScope(fs(r,!1)|ds),this.initFunction(t),this.options.ecmaVersion>=8&&(t.async=!!r),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,t.params=this.toAssignableList(e,!0),this.parseFunctionBody(t,!0,!1,n),this.yieldPos=i,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(t,"ArrowFunctionExpression")};K.parseFunctionBody=function(t,e,r,n){var i=e&&this.type!==g.braceL,s=this.strict,a=!1;if(i)t.body=this.parseMaybeAssign(n),t.expression=!0,this.checkParams(t,!1);else{var o=this.options.ecmaVersion>=7&&!this.isSimpleParamList(t.params);(!s||o)&&(a=this.strictDirective(this.end),a&&o&&this.raiseRecoverable(t.start,"Illegal \'use strict\' directive in function with non-simple parameter list"));var l=this.labels;this.labels=[],a&&(this.strict=!0),this.checkParams(t,!s&&!a&&!e&&!r&&this.isSimpleParamList(t.params)),this.strict&&t.id&&this.checkLValSimple(t.id,go),t.body=this.parseBlock(!1,void 0,a&&!s),t.expression=!1,this.adaptDirectivePrologue(t.body.body),this.labels=l}this.exitScope()};K.isSimpleParamList=function(t){for(var e=0,r=t;e<r.length;e+=1){var n=r[e];if(n.type!=="Identifier")return!1}return!0};K.checkParams=function(t,e){for(var r=Object.create(null),n=0,i=t.params;n<i.length;n+=1){var s=i[n];this.checkLValInnerPattern(s,ms,e?null:r)}};K.parseExprList=function(t,e,r,n){for(var i=[],s=!0;!this.eat(t);){if(s)s=!1;else if(this.expect(g.comma),e&&this.afterTrailingComma(t))break;var a=void 0;r&&this.type===g.comma?a=null:this.type===g.ellipsis?(a=this.parseSpread(n),n&&this.type===g.comma&&n.trailingComma<0&&(n.trailingComma=this.start)):a=this.parseMaybeAssign(!1,n),i.push(a)}return i};K.checkUnreserved=function(t){var e=t.start,r=t.end,n=t.name;if(this.inGenerator&&n==="yield"&&this.raiseRecoverable(e,"Cannot use \'yield\' as identifier inside a generator"),this.inAsync&&n==="await"&&this.raiseRecoverable(e,"Cannot use \'await\' as identifier inside an async function"),!(this.currentThisScope().flags&qn)&&n==="arguments"&&this.raiseRecoverable(e,"Cannot use \'arguments\' in class field initializer"),this.inClassStaticBlock&&(n==="arguments"||n==="await")&&this.raise(e,"Cannot use "+n+" in class static initialization block"),this.keywords.test(n)&&this.raise(e,"Unexpected keyword \'"+n+"\'"),!(this.options.ecmaVersion<6&&this.input.slice(e,r).indexOf("\\\\")!==-1)){var i=this.strict?this.reservedWordsStrict:this.reservedWords;i.test(n)&&(!this.inAsync&&n==="await"&&this.raiseRecoverable(e,"Cannot use keyword \'await\' outside an async function"),this.raiseRecoverable(e,"The keyword \'"+n+"\' is reserved"))}};K.parseIdent=function(t){var e=this.parseIdentNode();return this.next(!!t),this.finishNode(e,"Identifier"),t||(this.checkUnreserved(e),e.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=e.start)),e};K.parseIdentNode=function(){var t=this.startNode();return this.type===g.name?t.name=this.value:this.type.keyword?(t.name=this.type.keyword,(t.name==="class"||t.name==="function")&&(this.lastTokEnd!==this.lastTokStart+1||this.input.charCodeAt(this.lastTokStart)!==46)&&this.context.pop(),this.type=g.name):this.unexpected(),t};K.parsePrivateIdent=function(){var t=this.startNode();return this.type===g.privateId?t.name=this.value:this.unexpected(),this.next(),this.finishNode(t,"PrivateIdentifier"),this.options.checkPrivateFields&&(this.privateNameStack.length===0?this.raise(t.start,"Private field \'#"+t.name+"\' must be declared in an enclosing class"):this.privateNameStack[this.privateNameStack.length-1].used.push(t)),t};K.parseYield=function(t){this.yieldPos||(this.yieldPos=this.start);var e=this.startNode();return this.next(),this.type===g.semi||this.canInsertSemicolon()||this.type!==g.star&&!this.type.startsExpr?(e.delegate=!1,e.argument=null):(e.delegate=this.eat(g.star),e.argument=this.parseMaybeAssign(t)),this.finishNode(e,"YieldExpression")};K.parseAwait=function(t){this.awaitPos||(this.awaitPos=this.start);var e=this.startNode();return this.next(),e.argument=this.parseMaybeUnary(null,!0,!1,t),this.finishNode(e,"AwaitExpression")};var En=Ie.prototype;En.raise=function(t,e){var r=co(this.input,t);e+=" ("+r.line+":"+r.column+")",this.sourceFile&&(e+=" in "+this.sourceFile);var n=new SyntaxError(e);throw n.pos=t,n.loc=r,n.raisedAt=this.pos,n};En.raiseRecoverable=En.raise;En.curPosition=function(){if(this.options.locations)return new Vr(this.curLine,this.pos-this.lineStart)};var Ut=Ie.prototype,Lg=function(t){this.flags=t,this.var=[],this.lexical=[],this.functions=[]};Ut.enterScope=function(t){this.scopeStack.push(new Lg(t))};Ut.exitScope=function(){this.scopeStack.pop()};Ut.treatFunctionsAsVarInScope=function(t){return t.flags&Jt||!this.inModule&&t.flags&Xt};Ut.declareName=function(t,e,r){var n=!1;if(e===Rt){var i=this.currentScope();n=i.lexical.indexOf(t)>-1||i.functions.indexOf(t)>-1||i.var.indexOf(t)>-1,i.lexical.push(t),this.inModule&&i.flags&Xt&&delete this.undefinedExports[t]}else if(e===yo){var s=this.currentScope();s.lexical.push(t)}else if(e===mo){var a=this.currentScope();this.treatFunctionsAsVar?n=a.lexical.indexOf(t)>-1:n=a.lexical.indexOf(t)>-1||a.var.indexOf(t)>-1,a.functions.push(t)}else for(var o=this.scopeStack.length-1;o>=0;--o){var l=this.scopeStack[o];if(l.lexical.indexOf(t)>-1&&!(l.flags&po&&l.lexical[0]===t)||!this.treatFunctionsAsVarInScope(l)&&l.functions.indexOf(t)>-1){n=!0;break}if(l.var.push(t),this.inModule&&l.flags&Xt&&delete this.undefinedExports[t],l.flags&qn)break}n&&this.raiseRecoverable(r,"Identifier \'"+t+"\' has already been declared")};Ut.checkLocalExport=function(t){this.scopeStack[0].lexical.indexOf(t.name)===-1&&this.scopeStack[0].var.indexOf(t.name)===-1&&(this.undefinedExports[t.name]=t)};Ut.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]};Ut.currentVarScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(qn|Wr|er))return e}};Ut.currentThisScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(qn|Wr|er)&&!(e.flags&ds))return e}};var Kn=function(t,e,r){this.type="",this.start=e,this.end=0,t.options.locations&&(this.loc=new Wn(t,r)),t.options.directSourceFile&&(this.sourceFile=t.options.directSourceFile),t.options.ranges&&(this.range=[e,0])},Ur=Ie.prototype;Ur.startNode=function(){return new Kn(this,this.start,this.startLoc)};Ur.startNodeAt=function(t,e){return new Kn(this,t,e)};function bo(t,e,r,n){return t.type=e,t.end=r,this.options.locations&&(t.loc.end=n),this.options.ranges&&(t.range[1]=r),t}Ur.finishNode=function(t,e){return bo.call(this,t,e,this.lastTokEnd,this.lastTokEndLoc)};Ur.finishNodeAt=function(t,e,r,n){return bo.call(this,t,e,r,n)};Ur.copyNode=function(t){var e=new Kn(this,t.start,this.startLoc);for(var r in t)e[r]=t[r];return e};var Og="Berf Beria_Erfe Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sidetic Sidt Sunu Sunuwar Tai_Yo Tayo Todhri Todr Tolong_Siki Tols Tulu_Tigalari Tutg Unknown Zzzz",vo="ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS",wo=vo+" Extended_Pictographic",Eo=wo,So=Eo+" EBase EComp EMod EPres ExtPict",Co=So,Vg=Co,jg={9:vo,10:wo,11:Eo,12:So,13:Co,14:Vg},$g="Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji",Wg={9:"",10:"",11:"",12:"",13:"",14:$g},na="Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu",No="Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb",ko=No+" Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd",Io=ko+" Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho",Ao=Io+" Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi",To=Ao+" Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith",Ug=To+" "+Og,qg={9:No,10:ko,11:Io,12:Ao,13:To,14:Ug},Do={};function zg(t){var e=Do[t]={binary:Bt(jg[t]+" "+na),binaryOfStrings:Bt(Wg[t]),nonBinary:{General_Category:Bt(na),Script:Bt(qg[t])}};e.nonBinary.Script_Extensions=e.nonBinary.Script,e.nonBinary.gc=e.nonBinary.General_Category,e.nonBinary.sc=e.nonBinary.Script,e.nonBinary.scx=e.nonBinary.Script_Extensions}for(Zr=0,ai=[9,10,11,12,13,14];Zr<ai.length;Zr+=1)ia=ai[Zr],zg(ia);var ia,Zr,ai,B=Ie.prototype,Sn=function(t,e){this.parent=t,this.base=e||this};Sn.prototype.separatedFrom=function(t){for(var e=this;e;e=e.parent)for(var r=t;r;r=r.parent)if(e.base===r.base&&e!==r)return!0;return!1};Sn.prototype.sibling=function(){return new Sn(this.parent,this.base)};var kt=function(t){this.parser=t,this.validFlags="gim"+(t.options.ecmaVersion>=6?"uy":"")+(t.options.ecmaVersion>=9?"s":"")+(t.options.ecmaVersion>=13?"d":"")+(t.options.ecmaVersion>=15?"v":""),this.unicodeProperties=Do[t.options.ecmaVersion>=14?14:t.options.ecmaVersion],this.source="",this.flags="",this.start=0,this.switchU=!1,this.switchV=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue="",this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=Object.create(null),this.backReferenceNames=[],this.branchID=null};kt.prototype.reset=function(t,e,r){var n=r.indexOf("v")!==-1,i=r.indexOf("u")!==-1;this.start=t|0,this.source=e+"",this.flags=r,n&&this.parser.options.ecmaVersion>=15?(this.switchU=!0,this.switchV=!0,this.switchN=!0):(this.switchU=i&&this.parser.options.ecmaVersion>=6,this.switchV=!1,this.switchN=i&&this.parser.options.ecmaVersion>=9)};kt.prototype.raise=function(t){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+t)};kt.prototype.at=function(t,e){e===void 0&&(e=!1);var r=this.source,n=r.length;if(t>=n)return-1;var i=r.charCodeAt(t);if(!(e||this.switchU)||i<=55295||i>=57344||t+1>=n)return i;var s=r.charCodeAt(t+1);return s>=56320&&s<=57343?(i<<10)+s-56613888:i};kt.prototype.nextIndex=function(t,e){e===void 0&&(e=!1);var r=this.source,n=r.length;if(t>=n)return n;var i=r.charCodeAt(t),s;return!(e||this.switchU)||i<=55295||i>=57344||t+1>=n||(s=r.charCodeAt(t+1))<56320||s>57343?t+1:t+2};kt.prototype.current=function(t){return t===void 0&&(t=!1),this.at(this.pos,t)};kt.prototype.lookahead=function(t){return t===void 0&&(t=!1),this.at(this.nextIndex(this.pos,t),t)};kt.prototype.advance=function(t){t===void 0&&(t=!1),this.pos=this.nextIndex(this.pos,t)};kt.prototype.eat=function(t,e){return e===void 0&&(e=!1),this.current(e)===t?(this.advance(e),!0):!1};kt.prototype.eatChars=function(t,e){e===void 0&&(e=!1);for(var r=this.pos,n=0,i=t;n<i.length;n+=1){var s=i[n],a=this.at(r,e);if(a===-1||a!==s)return!1;r=this.nextIndex(r,e)}return this.pos=r,!0};B.validateRegExpFlags=function(t){for(var e=t.validFlags,r=t.flags,n=!1,i=!1,s=0;s<r.length;s++){var a=r.charAt(s);e.indexOf(a)===-1&&this.raise(t.start,"Invalid regular expression flag"),r.indexOf(a,s+1)>-1&&this.raise(t.start,"Duplicate regular expression flag"),a==="u"&&(n=!0),a==="v"&&(i=!0)}this.options.ecmaVersion>=15&&n&&i&&this.raise(t.start,"Invalid regular expression flag")};function Kg(t){for(var e in t)return!0;return!1}B.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&Kg(t.groupNames)&&(t.switchN=!0,this.regexp_pattern(t))};B.regexp_pattern=function(t){t.pos=0,t.lastIntValue=0,t.lastStringValue="",t.lastAssertionIsQuantifiable=!1,t.numCapturingParens=0,t.maxBackReference=0,t.groupNames=Object.create(null),t.backReferenceNames.length=0,t.branchID=null,this.regexp_disjunction(t),t.pos!==t.source.length&&(t.eat(41)&&t.raise("Unmatched \')\'"),(t.eat(93)||t.eat(125))&&t.raise("Lone quantifier brackets")),t.maxBackReference>t.numCapturingParens&&t.raise("Invalid escape");for(var e=0,r=t.backReferenceNames;e<r.length;e+=1){var n=r[e];t.groupNames[n]||t.raise("Invalid named capture referenced")}};B.regexp_disjunction=function(t){var e=this.options.ecmaVersion>=16;for(e&&(t.branchID=new Sn(t.branchID,null)),this.regexp_alternative(t);t.eat(124);)e&&(t.branchID=t.branchID.sibling()),this.regexp_alternative(t);e&&(t.branchID=t.branchID.parent),this.regexp_eatQuantifier(t,!0)&&t.raise("Nothing to repeat"),t.eat(123)&&t.raise("Lone quantifier brackets")};B.regexp_alternative=function(t){for(;t.pos<t.source.length&&this.regexp_eatTerm(t););};B.regexp_eatTerm=function(t){return this.regexp_eatAssertion(t)?(t.lastAssertionIsQuantifiable&&this.regexp_eatQuantifier(t)&&t.switchU&&t.raise("Invalid quantifier"),!0):(t.switchU?this.regexp_eatAtom(t):this.regexp_eatExtendedAtom(t))?(this.regexp_eatQuantifier(t),!0):!1};B.regexp_eatAssertion=function(t){var e=t.pos;if(t.lastAssertionIsQuantifiable=!1,t.eat(94)||t.eat(36))return!0;if(t.eat(92)){if(t.eat(66)||t.eat(98))return!0;t.pos=e}if(t.eat(40)&&t.eat(63)){var r=!1;if(this.options.ecmaVersion>=9&&(r=t.eat(60)),t.eat(61)||t.eat(33))return this.regexp_disjunction(t),t.eat(41)||t.raise("Unterminated group"),t.lastAssertionIsQuantifiable=!r,!0}return t.pos=e,!1};B.regexp_eatQuantifier=function(t,e){return e===void 0&&(e=!1),this.regexp_eatQuantifierPrefix(t,e)?(t.eat(63),!0):!1};B.regexp_eatQuantifierPrefix=function(t,e){return t.eat(42)||t.eat(43)||t.eat(63)||this.regexp_eatBracedQuantifier(t,e)};B.regexp_eatBracedQuantifier=function(t,e){var r=t.pos;if(t.eat(123)){var n=0,i=-1;if(this.regexp_eatDecimalDigits(t)&&(n=t.lastIntValue,t.eat(44)&&this.regexp_eatDecimalDigits(t)&&(i=t.lastIntValue),t.eat(125)))return i!==-1&&i<n&&!e&&t.raise("numbers out of order in {} quantifier"),!0;t.switchU&&!e&&t.raise("Incomplete quantifier"),t.pos=r}return!1};B.regexp_eatAtom=function(t){return this.regexp_eatPatternCharacters(t)||t.eat(46)||this.regexp_eatReverseSolidusAtomEscape(t)||this.regexp_eatCharacterClass(t)||this.regexp_eatUncapturingGroup(t)||this.regexp_eatCapturingGroup(t)};B.regexp_eatReverseSolidusAtomEscape=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatAtomEscape(t))return!0;t.pos=e}return!1};B.regexp_eatUncapturingGroup=function(t){var e=t.pos;if(t.eat(40)){if(t.eat(63)){if(this.options.ecmaVersion>=16){var r=this.regexp_eatModifiers(t),n=t.eat(45);if(r||n){for(var i=0;i<r.length;i++){var s=r.charAt(i);r.indexOf(s,i+1)>-1&&t.raise("Duplicate regular expression modifiers")}if(n){var a=this.regexp_eatModifiers(t);!r&&!a&&t.current()===58&&t.raise("Invalid regular expression modifiers");for(var o=0;o<a.length;o++){var l=a.charAt(o);(a.indexOf(l,o+1)>-1||r.indexOf(l)>-1)&&t.raise("Duplicate regular expression modifiers")}}}}if(t.eat(58)){if(this.regexp_disjunction(t),t.eat(41))return!0;t.raise("Unterminated group")}}t.pos=e}return!1};B.regexp_eatCapturingGroup=function(t){if(t.eat(40)){if(this.options.ecmaVersion>=9?this.regexp_groupSpecifier(t):t.current()===63&&t.raise("Invalid group"),this.regexp_disjunction(t),t.eat(41))return t.numCapturingParens+=1,!0;t.raise("Unterminated group")}return!1};B.regexp_eatModifiers=function(t){for(var e="",r=0;(r=t.current())!==-1&&Hg(r);)e+=Mt(r),t.advance();return e};function Hg(t){return t===105||t===109||t===115}B.regexp_eatExtendedAtom=function(t){return t.eat(46)||this.regexp_eatReverseSolidusAtomEscape(t)||this.regexp_eatCharacterClass(t)||this.regexp_eatUncapturingGroup(t)||this.regexp_eatCapturingGroup(t)||this.regexp_eatInvalidBracedQuantifier(t)||this.regexp_eatExtendedPatternCharacter(t)};B.regexp_eatInvalidBracedQuantifier=function(t){return this.regexp_eatBracedQuantifier(t,!0)&&t.raise("Nothing to repeat"),!1};B.regexp_eatSyntaxCharacter=function(t){var e=t.current();return Mo(e)?(t.lastIntValue=e,t.advance(),!0):!1};function Mo(t){return t===36||t>=40&&t<=43||t===46||t===63||t>=91&&t<=94||t>=123&&t<=125}B.regexp_eatPatternCharacters=function(t){for(var e=t.pos,r=0;(r=t.current())!==-1&&!Mo(r);)t.advance();return t.pos!==e};B.regexp_eatExtendedPatternCharacter=function(t){var e=t.current();return e!==-1&&e!==36&&!(e>=40&&e<=43)&&e!==46&&e!==63&&e!==91&&e!==94&&e!==124?(t.advance(),!0):!1};B.regexp_groupSpecifier=function(t){if(t.eat(63)){this.regexp_eatGroupName(t)||t.raise("Invalid group");var e=this.options.ecmaVersion>=16,r=t.groupNames[t.lastStringValue];if(r)if(e)for(var n=0,i=r;n<i.length;n+=1){var s=i[n];s.separatedFrom(t.branchID)||t.raise("Duplicate capture group name")}else t.raise("Duplicate capture group name");e?(r||(t.groupNames[t.lastStringValue]=[])).push(t.branchID):t.groupNames[t.lastStringValue]=!0}};B.regexp_eatGroupName=function(t){if(t.lastStringValue="",t.eat(60)){if(this.regexp_eatRegExpIdentifierName(t)&&t.eat(62))return!0;t.raise("Invalid capture group name")}return!1};B.regexp_eatRegExpIdentifierName=function(t){if(t.lastStringValue="",this.regexp_eatRegExpIdentifierStart(t)){for(t.lastStringValue+=Mt(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=Mt(t.lastIntValue);return!0}return!1};B.regexp_eatRegExpIdentifierStart=function(t){var e=t.pos,r=this.options.ecmaVersion>=11,n=t.current(r);return t.advance(r),n===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,r)&&(n=t.lastIntValue),Gg(n)?(t.lastIntValue=n,!0):(t.pos=e,!1)};function Gg(t){return Nt(t,!0)||t===36||t===95}B.regexp_eatRegExpIdentifierPart=function(t){var e=t.pos,r=this.options.ecmaVersion>=11,n=t.current(r);return t.advance(r),n===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,r)&&(n=t.lastIntValue),Yg(n)?(t.lastIntValue=n,!0):(t.pos=e,!1)};function Yg(t){return jt(t,!0)||t===36||t===95||t===8204||t===8205}B.regexp_eatAtomEscape=function(t){return this.regexp_eatBackReference(t)||this.regexp_eatCharacterClassEscape(t)||this.regexp_eatCharacterEscape(t)||t.switchN&&this.regexp_eatKGroupName(t)?!0:(t.switchU&&(t.current()===99&&t.raise("Invalid unicode escape"),t.raise("Invalid escape")),!1)};B.regexp_eatBackReference=function(t){var e=t.pos;if(this.regexp_eatDecimalEscape(t)){var r=t.lastIntValue;if(t.switchU)return r>t.maxBackReference&&(t.maxBackReference=r),!0;if(r<=t.numCapturingParens)return!0;t.pos=e}return!1};B.regexp_eatKGroupName=function(t){if(t.eat(107)){if(this.regexp_eatGroupName(t))return t.backReferenceNames.push(t.lastStringValue),!0;t.raise("Invalid named reference")}return!1};B.regexp_eatCharacterEscape=function(t){return this.regexp_eatControlEscape(t)||this.regexp_eatCControlLetter(t)||this.regexp_eatZero(t)||this.regexp_eatHexEscapeSequence(t)||this.regexp_eatRegExpUnicodeEscapeSequence(t,!1)||!t.switchU&&this.regexp_eatLegacyOctalEscapeSequence(t)||this.regexp_eatIdentityEscape(t)};B.regexp_eatCControlLetter=function(t){var e=t.pos;if(t.eat(99)){if(this.regexp_eatControlLetter(t))return!0;t.pos=e}return!1};B.regexp_eatZero=function(t){return t.current()===48&&!Hn(t.lookahead())?(t.lastIntValue=0,t.advance(),!0):!1};B.regexp_eatControlEscape=function(t){var e=t.current();return e===116?(t.lastIntValue=9,t.advance(),!0):e===110?(t.lastIntValue=10,t.advance(),!0):e===118?(t.lastIntValue=11,t.advance(),!0):e===102?(t.lastIntValue=12,t.advance(),!0):e===114?(t.lastIntValue=13,t.advance(),!0):!1};B.regexp_eatControlLetter=function(t){var e=t.current();return Po(e)?(t.lastIntValue=e%32,t.advance(),!0):!1};function Po(t){return t>=65&&t<=90||t>=97&&t<=122}B.regexp_eatRegExpUnicodeEscapeSequence=function(t,e){e===void 0&&(e=!1);var r=t.pos,n=e||t.switchU;if(t.eat(117)){if(this.regexp_eatFixedHexDigits(t,4)){var i=t.lastIntValue;if(n&&i>=55296&&i<=56319){var s=t.pos;if(t.eat(92)&&t.eat(117)&&this.regexp_eatFixedHexDigits(t,4)){var a=t.lastIntValue;if(a>=56320&&a<=57343)return t.lastIntValue=(i-55296)*1024+(a-56320)+65536,!0}t.pos=s,t.lastIntValue=i}return!0}if(n&&t.eat(123)&&this.regexp_eatHexDigits(t)&&t.eat(125)&&Zg(t.lastIntValue))return!0;n&&t.raise("Invalid unicode escape"),t.pos=r}return!1};function Zg(t){return t>=0&&t<=1114111}B.regexp_eatIdentityEscape=function(t){if(t.switchU)return this.regexp_eatSyntaxCharacter(t)?!0:t.eat(47)?(t.lastIntValue=47,!0):!1;var e=t.current();return e!==99&&(!t.switchN||e!==107)?(t.lastIntValue=e,t.advance(),!0):!1};B.regexp_eatDecimalEscape=function(t){t.lastIntValue=0;var e=t.current();if(e>=49&&e<=57){do t.lastIntValue=10*t.lastIntValue+(e-48),t.advance();while((e=t.current())>=48&&e<=57);return!0}return!1};var Ro=0,Pt=1,nt=2;B.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(Xg(e))return t.lastIntValue=-1,t.advance(),Pt;var r=!1;if(t.switchU&&this.options.ecmaVersion>=9&&((r=e===80)||e===112)){t.lastIntValue=-1,t.advance();var n;if(t.eat(123)&&(n=this.regexp_eatUnicodePropertyValueExpression(t))&&t.eat(125))return r&&n===nt&&t.raise("Invalid property name"),n;t.raise("Invalid property name")}return Ro};function Xg(t){return t===100||t===68||t===115||t===83||t===119||t===87}B.regexp_eatUnicodePropertyValueExpression=function(t){var e=t.pos;if(this.regexp_eatUnicodePropertyName(t)&&t.eat(61)){var r=t.lastStringValue;if(this.regexp_eatUnicodePropertyValue(t)){var n=t.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(t,r,n),Pt}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var i=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,i)}return Ro};B.regexp_validateUnicodePropertyNameAndValue=function(t,e,r){_r(t.unicodeProperties.nonBinary,e)||t.raise("Invalid property name"),t.unicodeProperties.nonBinary[e].test(r)||t.raise("Invalid property value")};B.regexp_validateUnicodePropertyNameOrValue=function(t,e){if(t.unicodeProperties.binary.test(e))return Pt;if(t.switchV&&t.unicodeProperties.binaryOfStrings.test(e))return nt;t.raise("Invalid property name")};B.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";Fo(e=t.current());)t.lastStringValue+=Mt(e),t.advance();return t.lastStringValue!==""};function Fo(t){return Po(t)||t===95}B.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";Qg(e=t.current());)t.lastStringValue+=Mt(e),t.advance();return t.lastStringValue!==""};function Qg(t){return Fo(t)||Hn(t)}B.regexp_eatLoneUnicodePropertyNameOrValue=function(t){return this.regexp_eatUnicodePropertyValue(t)};B.regexp_eatCharacterClass=function(t){if(t.eat(91)){var e=t.eat(94),r=this.regexp_classContents(t);return t.eat(93)||t.raise("Unterminated character class"),e&&r===nt&&t.raise("Negated character class may contain strings"),!0}return!1};B.regexp_classContents=function(t){return t.current()===93?Pt:t.switchV?this.regexp_classSetExpression(t):(this.regexp_nonEmptyClassRanges(t),Pt)};B.regexp_nonEmptyClassRanges=function(t){for(;this.regexp_eatClassAtom(t);){var e=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassAtom(t)){var r=t.lastIntValue;t.switchU&&(e===-1||r===-1)&&t.raise("Invalid character class"),e!==-1&&r!==-1&&e>r&&t.raise("Range out of order in character class")}}};B.regexp_eatClassAtom=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatClassEscape(t))return!0;if(t.switchU){var r=t.current();(r===99||Oo(r))&&t.raise("Invalid class escape"),t.raise("Invalid escape")}t.pos=e}var n=t.current();return n!==93?(t.lastIntValue=n,t.advance(),!0):!1};B.regexp_eatClassEscape=function(t){var e=t.pos;if(t.eat(98))return t.lastIntValue=8,!0;if(t.switchU&&t.eat(45))return t.lastIntValue=45,!0;if(!t.switchU&&t.eat(99)){if(this.regexp_eatClassControlLetter(t))return!0;t.pos=e}return this.regexp_eatCharacterClassEscape(t)||this.regexp_eatCharacterEscape(t)};B.regexp_classSetExpression=function(t){var e=Pt,r;if(!this.regexp_eatClassSetRange(t))if(r=this.regexp_eatClassSetOperand(t)){r===nt&&(e=nt);for(var n=t.pos;t.eatChars([38,38]);){if(t.current()!==38&&(r=this.regexp_eatClassSetOperand(t))){r!==nt&&(e=Pt);continue}t.raise("Invalid character in character class")}if(n!==t.pos)return e;for(;t.eatChars([45,45]);)this.regexp_eatClassSetOperand(t)||t.raise("Invalid character in character class");if(n!==t.pos)return e}else t.raise("Invalid character in character class");for(;;)if(!this.regexp_eatClassSetRange(t)){if(r=this.regexp_eatClassSetOperand(t),!r)return e;r===nt&&(e=nt)}};B.regexp_eatClassSetRange=function(t){var e=t.pos;if(this.regexp_eatClassSetCharacter(t)){var r=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassSetCharacter(t)){var n=t.lastIntValue;return r!==-1&&n!==-1&&r>n&&t.raise("Range out of order in character class"),!0}t.pos=e}return!1};B.regexp_eatClassSetOperand=function(t){return this.regexp_eatClassSetCharacter(t)?Pt:this.regexp_eatClassStringDisjunction(t)||this.regexp_eatNestedClass(t)};B.regexp_eatNestedClass=function(t){var e=t.pos;if(t.eat(91)){var r=t.eat(94),n=this.regexp_classContents(t);if(t.eat(93))return r&&n===nt&&t.raise("Negated character class may contain strings"),n;t.pos=e}if(t.eat(92)){var i=this.regexp_eatCharacterClassEscape(t);if(i)return i;t.pos=e}return null};B.regexp_eatClassStringDisjunction=function(t){var e=t.pos;if(t.eatChars([92,113])){if(t.eat(123)){var r=this.regexp_classStringDisjunctionContents(t);if(t.eat(125))return r}else t.raise("Invalid escape");t.pos=e}return null};B.regexp_classStringDisjunctionContents=function(t){for(var e=this.regexp_classString(t);t.eat(124);)this.regexp_classString(t)===nt&&(e=nt);return e};B.regexp_classString=function(t){for(var e=0;this.regexp_eatClassSetCharacter(t);)e++;return e===1?Pt:nt};B.regexp_eatClassSetCharacter=function(t){var e=t.pos;if(t.eat(92))return this.regexp_eatCharacterEscape(t)||this.regexp_eatClassSetReservedPunctuator(t)?!0:t.eat(98)?(t.lastIntValue=8,!0):(t.pos=e,!1);var r=t.current();return r<0||r===t.lookahead()&&Jg(r)||e_(r)?!1:(t.advance(),t.lastIntValue=r,!0)};function Jg(t){return t===33||t>=35&&t<=38||t>=42&&t<=44||t===46||t>=58&&t<=64||t===94||t===96||t===126}function e_(t){return t===40||t===41||t===45||t===47||t>=91&&t<=93||t>=123&&t<=125}B.regexp_eatClassSetReservedPunctuator=function(t){var e=t.current();return t_(e)?(t.lastIntValue=e,t.advance(),!0):!1};function t_(t){return t===33||t===35||t===37||t===38||t===44||t===45||t>=58&&t<=62||t===64||t===96||t===126}B.regexp_eatClassControlLetter=function(t){var e=t.current();return Hn(e)||e===95?(t.lastIntValue=e%32,t.advance(),!0):!1};B.regexp_eatHexEscapeSequence=function(t){var e=t.pos;if(t.eat(120)){if(this.regexp_eatFixedHexDigits(t,2))return!0;t.switchU&&t.raise("Invalid escape"),t.pos=e}return!1};B.regexp_eatDecimalDigits=function(t){var e=t.pos,r=0;for(t.lastIntValue=0;Hn(r=t.current());)t.lastIntValue=10*t.lastIntValue+(r-48),t.advance();return t.pos!==e};function Hn(t){return t>=48&&t<=57}B.regexp_eatHexDigits=function(t){var e=t.pos,r=0;for(t.lastIntValue=0;Bo(r=t.current());)t.lastIntValue=16*t.lastIntValue+Lo(r),t.advance();return t.pos!==e};function Bo(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function Lo(t){return t>=65&&t<=70?10+(t-65):t>=97&&t<=102?10+(t-97):t-48}B.regexp_eatLegacyOctalEscapeSequence=function(t){if(this.regexp_eatOctalDigit(t)){var e=t.lastIntValue;if(this.regexp_eatOctalDigit(t)){var r=t.lastIntValue;e<=3&&this.regexp_eatOctalDigit(t)?t.lastIntValue=e*64+r*8+t.lastIntValue:t.lastIntValue=e*8+r}else t.lastIntValue=e;return!0}return!1};B.regexp_eatOctalDigit=function(t){var e=t.current();return Oo(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)};function Oo(t){return t>=48&&t<=55}B.regexp_eatFixedHexDigits=function(t,e){var r=t.pos;t.lastIntValue=0;for(var n=0;n<e;++n){var i=t.current();if(!Bo(i))return t.pos=r,!1;t.lastIntValue=16*t.lastIntValue+Lo(i),t.advance()}return!0};var gs=function(t){this.type=t.type,this.value=t.value,this.start=t.start,this.end=t.end,t.options.locations&&(this.loc=new Wn(t,t.startLoc,t.endLoc)),t.options.ranges&&(this.range=[t.start,t.end])},X=Ie.prototype;X.next=function(t){!t&&this.type.keyword&&this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword "+this.type.keyword),this.options.onToken&&this.options.onToken(new gs(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()};X.getToken=function(){return this.next(),new gs(this)};typeof Symbol<"u"&&(X[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===g.eof,value:e}}}});X.nextToken=function(){var t=this.curContext();if((!t||!t.preserveSpace)&&this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length)return this.finishToken(g.eof);if(t.override)return t.override(this);this.readToken(this.fullCharCodeAtPos())};X.readToken=function(t){return Nt(t,this.options.ecmaVersion>=6)||t===92?this.readWord():this.getTokenFromCode(t)};X.fullCharCodeAt=function(t){var e=this.input.charCodeAt(t);if(e<=55295||e>=56320)return e;var r=this.input.charCodeAt(t+1);return r<=56319||r>=57344?e:(e<<10)+r-56613888};X.fullCharCodeAtPos=function(){return this.fullCharCodeAt(this.pos)};X.skipBlockComment=function(){var t=this.options.onComment&&this.curPosition(),e=this.pos,r=this.input.indexOf("*/",this.pos+=2);if(r===-1&&this.raise(this.pos-2,"Unterminated comment"),this.pos=r+2,this.options.locations)for(var n=void 0,i=e;(n=ao(this.input,i,this.pos))>-1;)++this.curLine,i=this.lineStart=n;this.options.onComment&&this.options.onComment(!0,this.input.slice(e+2,r),e,this.pos,t,this.curPosition())};X.skipLineComment=function(t){for(var e=this.pos,r=this.options.onComment&&this.curPosition(),n=this.input.charCodeAt(this.pos+=t);this.pos<this.input.length&&!gr(n);)n=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(e+t,this.pos),e,this.pos,r,this.curPosition())};X.skipSpace=function(){e:for(;this.pos<this.input.length;){var t=this.input.charCodeAt(this.pos);switch(t){case 32:case 160:++this.pos;break;case 13:this.input.charCodeAt(this.pos+1)===10&&++this.pos;case 10:case 8232:case 8233:++this.pos,this.options.locations&&(++this.curLine,this.lineStart=this.pos);break;case 47:switch(this.input.charCodeAt(this.pos+1)){case 42:this.skipBlockComment();break;case 47:this.skipLineComment(2);break;default:break e}break;default:if(t>8&&t<14||t>=5760&&oo.test(String.fromCharCode(t)))++this.pos;else break e}}};X.finishToken=function(t,e){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var r=this.type;this.type=t,this.value=e,this.updateContext(r)};X.readToken_dot=function(){var t=this.input.charCodeAt(this.pos+1);if(t>=48&&t<=57)return this.readNumber(!0);var e=this.input.charCodeAt(this.pos+2);return this.options.ecmaVersion>=6&&t===46&&e===46?(this.pos+=3,this.finishToken(g.ellipsis)):(++this.pos,this.finishToken(g.dot))};X.readToken_slash=function(){var t=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):t===61?this.finishOp(g.assign,2):this.finishOp(g.slash,1)};X.readToken_mult_modulo_exp=function(t){var e=this.input.charCodeAt(this.pos+1),r=1,n=t===42?g.star:g.modulo;return this.options.ecmaVersion>=7&&t===42&&e===42&&(++r,n=g.starstar,e=this.input.charCodeAt(this.pos+2)),e===61?this.finishOp(g.assign,r+1):this.finishOp(n,r)};X.readToken_pipe_amp=function(t){var e=this.input.charCodeAt(this.pos+1);if(e===t){if(this.options.ecmaVersion>=12){var r=this.input.charCodeAt(this.pos+2);if(r===61)return this.finishOp(g.assign,3)}return this.finishOp(t===124?g.logicalOR:g.logicalAND,2)}return e===61?this.finishOp(g.assign,2):this.finishOp(t===124?g.bitwiseOR:g.bitwiseAND,1)};X.readToken_caret=function(){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(g.assign,2):this.finishOp(g.bitwiseXOR,1)};X.readToken_plus_min=function(t){var e=this.input.charCodeAt(this.pos+1);return e===t?e===45&&!this.inModule&&this.input.charCodeAt(this.pos+2)===62&&(this.lastTokEnd===0||ze.test(this.input.slice(this.lastTokEnd,this.pos)))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(g.incDec,2):e===61?this.finishOp(g.assign,2):this.finishOp(g.plusMin,1)};X.readToken_lt_gt=function(t){var e=this.input.charCodeAt(this.pos+1),r=1;return e===t?(r=t===62&&this.input.charCodeAt(this.pos+2)===62?3:2,this.input.charCodeAt(this.pos+r)===61?this.finishOp(g.assign,r+1):this.finishOp(g.bitShift,r)):e===33&&t===60&&!this.inModule&&this.input.charCodeAt(this.pos+2)===45&&this.input.charCodeAt(this.pos+3)===45?(this.skipLineComment(4),this.skipSpace(),this.nextToken()):(e===61&&(r=2),this.finishOp(g.relational,r))};X.readToken_eq_excl=function(t){var e=this.input.charCodeAt(this.pos+1);return e===61?this.finishOp(g.equality,this.input.charCodeAt(this.pos+2)===61?3:2):t===61&&e===62&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(g.arrow)):this.finishOp(t===61?g.eq:g.prefix,1)};X.readToken_question=function(){var t=this.options.ecmaVersion;if(t>=11){var e=this.input.charCodeAt(this.pos+1);if(e===46){var r=this.input.charCodeAt(this.pos+2);if(r<48||r>57)return this.finishOp(g.questionDot,2)}if(e===63){if(t>=12){var n=this.input.charCodeAt(this.pos+2);if(n===61)return this.finishOp(g.assign,3)}return this.finishOp(g.coalesce,2)}}return this.finishOp(g.question,1)};X.readToken_numberSign=function(){var t=this.options.ecmaVersion,e=35;if(t>=13&&(++this.pos,e=this.fullCharCodeAtPos(),Nt(e,!0)||e===92))return this.finishToken(g.privateId,this.readWord1());this.raise(this.pos,"Unexpected character \'"+Mt(e)+"\'")};X.getTokenFromCode=function(t){switch(t){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(g.parenL);case 41:return++this.pos,this.finishToken(g.parenR);case 59:return++this.pos,this.finishToken(g.semi);case 44:return++this.pos,this.finishToken(g.comma);case 91:return++this.pos,this.finishToken(g.bracketL);case 93:return++this.pos,this.finishToken(g.bracketR);case 123:return++this.pos,this.finishToken(g.braceL);case 125:return++this.pos,this.finishToken(g.braceR);case 58:return++this.pos,this.finishToken(g.colon);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(g.backQuote);case 48:var e=this.input.charCodeAt(this.pos+1);if(e===120||e===88)return this.readRadixNumber(16);if(this.options.ecmaVersion>=6){if(e===111||e===79)return this.readRadixNumber(8);if(e===98||e===66)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(t);case 47:return this.readToken_slash();case 37:case 42:return this.readToken_mult_modulo_exp(t);case 124:case 38:return this.readToken_pipe_amp(t);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(t);case 60:case 62:return this.readToken_lt_gt(t);case 61:case 33:return this.readToken_eq_excl(t);case 63:return this.readToken_question();case 126:return this.finishOp(g.prefix,1);case 35:return this.readToken_numberSign()}this.raise(this.pos,"Unexpected character \'"+Mt(t)+"\'")};X.finishOp=function(t,e){var r=this.input.slice(this.pos,this.pos+e);return this.pos+=e,this.finishToken(t,r)};X.readRegexp=function(){for(var t,e,r=this.pos;;){this.pos>=this.input.length&&this.raise(r,"Unterminated regular expression");var n=this.input.charAt(this.pos);if(ze.test(n)&&this.raise(r,"Unterminated regular expression"),t)t=!1;else{if(n==="[")e=!0;else if(n==="]"&&e)e=!1;else if(n==="/"&&!e)break;t=n==="\\\\"}++this.pos}var i=this.input.slice(r,this.pos);++this.pos;var s=this.pos,a=this.readWord1();this.containsEsc&&this.unexpected(s);var o=this.regexpState||(this.regexpState=new kt(this));o.reset(r,i,a),this.validateRegExpFlags(o),this.validateRegExpPattern(o);var l=null;try{l=new RegExp(i,a)}catch{}return this.finishToken(g.regexp,{pattern:i,flags:a,value:l})};X.readInt=function(t,e,r){for(var n=this.options.ecmaVersion>=12&&e===void 0,i=r&&this.input.charCodeAt(this.pos)===48,s=this.pos,a=0,o=0,l=0,c=e??1/0;l<c;++l,++this.pos){var u=this.input.charCodeAt(this.pos),h=void 0;if(n&&u===95){i&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed in legacy octal numeric literals"),o===95&&this.raiseRecoverable(this.pos,"Numeric separator must be exactly one underscore"),l===0&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed at the first of digits"),o=u;continue}if(u>=97?h=u-97+10:u>=65?h=u-65+10:u>=48&&u<=57?h=u-48:h=1/0,h>=t)break;o=u,a=a*t+h}return n&&o===95&&this.raiseRecoverable(this.pos-1,"Numeric separator is not allowed at the last of digits"),this.pos===s||e!=null&&this.pos-s!==e?null:a};function r_(t,e){return e?parseInt(t,8):parseFloat(t.replace(/_/g,""))}function Vo(t){return typeof BigInt!="function"?null:BigInt(t.replace(/_/g,""))}X.readRadixNumber=function(t){var e=this.pos;this.pos+=2;var r=this.readInt(t);return r==null&&this.raise(this.start+2,"Expected number in radix "+t),this.options.ecmaVersion>=11&&this.input.charCodeAt(this.pos)===110?(r=Vo(this.input.slice(e,this.pos)),++this.pos):Nt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(g.num,r)};X.readNumber=function(t){var e=this.pos;!t&&this.readInt(10,void 0,!0)===null&&this.raise(e,"Invalid number");var r=this.pos-e>=2&&this.input.charCodeAt(e)===48;r&&this.strict&&this.raise(e,"Invalid number");var n=this.input.charCodeAt(this.pos);if(!r&&!t&&this.options.ecmaVersion>=11&&n===110){var i=Vo(this.input.slice(e,this.pos));return++this.pos,Nt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(g.num,i)}r&&/[89]/.test(this.input.slice(e,this.pos))&&(r=!1),n===46&&!r&&(++this.pos,this.readInt(10),n=this.input.charCodeAt(this.pos)),(n===69||n===101)&&!r&&(n=this.input.charCodeAt(++this.pos),(n===43||n===45)&&++this.pos,this.readInt(10)===null&&this.raise(e,"Invalid number")),Nt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var s=r_(this.input.slice(e,this.pos),r);return this.finishToken(g.num,s)};X.readCodePoint=function(){var t=this.input.charCodeAt(this.pos),e;if(t===123){this.options.ecmaVersion<6&&this.unexpected();var r=++this.pos;e=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,e>1114111&&this.invalidStringToken(r,"Code point out of bounds")}else e=this.readHexChar(4);return e};X.readString=function(t){for(var e="",r=++this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated string constant");var n=this.input.charCodeAt(this.pos);if(n===t)break;n===92?(e+=this.input.slice(r,this.pos),e+=this.readEscapedChar(!1),r=this.pos):n===8232||n===8233?(this.options.ecmaVersion<10&&this.raise(this.start,"Unterminated string constant"),++this.pos,this.options.locations&&(this.curLine++,this.lineStart=this.pos)):(gr(n)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return e+=this.input.slice(r,this.pos++),this.finishToken(g.string,e)};var jo={};X.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t===jo)this.readInvalidTemplateToken();else throw t}this.inTemplateElement=!1};X.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw jo;this.raise(t,e)};X.readTmplToken=function(){for(var t="",e=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var r=this.input.charCodeAt(this.pos);if(r===96||r===36&&this.input.charCodeAt(this.pos+1)===123)return this.pos===this.start&&(this.type===g.template||this.type===g.invalidTemplate)?r===36?(this.pos+=2,this.finishToken(g.dollarBraceL)):(++this.pos,this.finishToken(g.backQuote)):(t+=this.input.slice(e,this.pos),this.finishToken(g.template,t));if(r===92)t+=this.input.slice(e,this.pos),t+=this.readEscapedChar(!0),e=this.pos;else if(gr(r)){switch(t+=this.input.slice(e,this.pos),++this.pos,r){case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:t+=`\n`;break;default:t+=String.fromCharCode(r);break}this.options.locations&&(++this.curLine,this.lineStart=this.pos),e=this.pos}else++this.pos}};X.readInvalidTemplateToken=function(){for(;this.pos<this.input.length;this.pos++)switch(this.input[this.pos]){case"\\\\":++this.pos;break;case"$":if(this.input[this.pos+1]!=="{")break;case"`":return this.finishToken(g.invalidTemplate,this.input.slice(this.start,this.pos));case"\\r":this.input[this.pos+1]===`\n`&&++this.pos;case`\n`:case"\\u2028":case"\\u2029":++this.curLine,this.lineStart=this.pos+1;break}this.raise(this.start,"Unterminated template")};X.readEscapedChar=function(t){var e=this.input.charCodeAt(++this.pos);switch(++this.pos,e){case 110:return`\n`;case 114:return"\\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return Mt(this.readCodePoint());case 116:return" ";case 98:return"\\b";case 118:return"\\v";case 102:return"\\f";case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"";case 56:case 57:if(this.strict&&this.invalidStringToken(this.pos-1,"Invalid escape sequence"),t){var r=this.pos-1;this.invalidStringToken(r,"Invalid escape sequence in template string")}default:if(e>=48&&e<=55){var n=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],i=parseInt(n,8);return i>255&&(n=n.slice(0,-1),i=parseInt(n,8)),this.pos+=n.length-1,e=this.input.charCodeAt(this.pos),(n!=="0"||e===56||e===57)&&(this.strict||t)&&this.invalidStringToken(this.pos-1-n.length,t?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(i)}return gr(e)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),""):String.fromCharCode(e)}};X.readHexChar=function(t){var e=this.pos,r=this.readInt(16,t);return r===null&&this.invalidStringToken(e,"Bad character escape sequence"),r};X.readWord1=function(){this.containsEsc=!1;for(var t="",e=!0,r=this.pos,n=this.options.ecmaVersion>=6;this.pos<this.input.length;){var i=this.fullCharCodeAtPos();if(jt(i,n))this.pos+=i<=65535?1:2;else if(i===92){this.containsEsc=!0,t+=this.input.slice(r,this.pos);var s=this.pos;this.input.charCodeAt(++this.pos)!==117&&this.invalidStringToken(this.pos,"Expecting Unicode escape sequence \\\\uXXXX"),++this.pos;var a=this.readCodePoint();(e?Nt:jt)(a,n)||this.invalidStringToken(s,"Invalid Unicode escape"),t+=Mt(a),r=this.pos}else break;e=!1}return t+this.input.slice(r,this.pos)};X.readWord=function(){var t=this.readWord1(),e=g.name;return this.keywords.test(t)&&(e=ps[t]),this.finishToken(e,t)};var n_="8.16.0";Ie.acorn={Parser:Ie,version:n_,defaultOptions:Fi,Position:Vr,SourceLocation:Wn,getLineInfo:co,Node:Kn,TokenType:J,tokTypes:g,keywordTypes:ps,TokContext:ct,tokContexts:pe,isIdentifierChar:jt,isIdentifierStart:Nt,Token:gs,isNewLine:gr,lineBreak:ze,lineBreakG:Ng,nonASCIIwhitespace:oo};function _s(t,e){return Ie.parse(t,e)}var{stringify:i_}=JSON;if(!String.prototype.repeat)throw new Error("String.prototype.repeat is undefined, see https://github.com/davidbonnet/astring#installation");if(!String.prototype.endsWith)throw new Error("String.prototype.endsWith is undefined, see https://github.com/davidbonnet/astring#installation");var Xr={"||":2,"??":3,"&&":4,"|":5,"^":6,"&":7,"==":8,"!=":8,"===":8,"!==":8,"<":9,">":9,"<=":9,">=":9,in:9,instanceof:9,"<<":10,">>":10,">>>":10,"+":11,"-":11,"*":12,"%":12,"/":12,"**":13},ft=17,s_={ArrayExpression:20,TaggedTemplateExpression:20,ThisExpression:20,Identifier:20,PrivateIdentifier:20,Literal:18,TemplateLiteral:20,Super:20,SequenceExpression:20,MemberExpression:19,ChainExpression:19,CallExpression:19,NewExpression:19,ArrowFunctionExpression:ft,ClassExpression:ft,FunctionExpression:ft,ObjectExpression:ft,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function ur(t,e){let{generator:r}=t;if(t.write("("),e!=null&&e.length>0){r[e[0].type](e[0],t);let{length:n}=e;for(let i=1;i<n;i++){let s=e[i];t.write(", "),r[s.type](s,t)}}t.write(")")}function $o(t,e,r,n){let i=t.expressionsPrecedence[e.type];if(i===ft)return!0;let s=t.expressionsPrecedence[r.type];return i!==s?!n&&i===15&&s===14&&r.operator==="**"||i<s:i!==13&&i!==14?!1:e.operator==="**"&&r.operator==="**"?!n:i===13&&s===13&&(e.operator==="??"||r.operator==="??")?!0:n?Xr[e.operator]<=Xr[r.operator]:Xr[e.operator]<Xr[r.operator]}function Qr(t,e,r,n){let{generator:i}=t;$o(t,e,r,n)?(t.write("("),i[e.type](e,t),t.write(")")):i[e.type](e,t)}function a_(t,e,r,n){let i=e.split(`\n`),s=i.length-1;if(t.write(i[0].trim()),s>0){t.write(n);for(let a=1;a<s;a++)t.write(r+i[a].trim()+n);t.write(r+i[s].trim())}}function Le(t,e,r,n){let{length:i}=e;for(let s=0;s<i;s++){let a=e[s];t.write(r),a.type[0]==="L"?t.write("// "+a.value.trim()+`\n`,a):(t.write("/*"),a_(t,a.value,r,n),t.write("*/"+n))}}function o_(t){let e=t;for(;e!=null;){let{type:r}=e;if(r[0]==="C"&&r[1]==="a")return!0;if(r[0]==="M"&&r[1]==="e"&&r[2]==="m")e=e.object;else return!1}}function oi(t,e){let{generator:r}=t,{declarations:n}=e;t.write(e.kind+" ");let{length:i}=n;if(i>0){r.VariableDeclarator(n[0],t);for(let s=1;s<i;s++)t.write(", "),r.VariableDeclarator(n[s],t)}}var sa,aa,oa,la,ca,ua,xs={Program(t,e){let r=e.indent.repeat(e.indentLevel),{lineEnd:n,writeComments:i}=e;i&&t.comments!=null&&Le(e,t.comments,r,n);let s=t.body,{length:a}=s;for(let o=0;o<a;o++){let l=s[o];i&&l.comments!=null&&Le(e,l.comments,r,n),e.write(r),this[l.type](l,e),e.write(n)}i&&t.trailingComments!=null&&Le(e,t.trailingComments,r,n)},BlockStatement:ua=function(t,e){let r=e.indent.repeat(e.indentLevel++),{lineEnd:n,writeComments:i}=e,s=r+e.indent;e.write("{");let a=t.body;if(a!=null&&a.length>0){e.write(n),i&&t.comments!=null&&Le(e,t.comments,s,n);let{length:o}=a;for(let l=0;l<o;l++){let c=a[l];i&&c.comments!=null&&Le(e,c.comments,s,n),e.write(s),this[c.type](c,e),e.write(n)}e.write(r)}else i&&t.comments!=null&&(e.write(n),Le(e,t.comments,s,n),e.write(r));i&&t.trailingComments!=null&&Le(e,t.trailingComments,s,n),e.write("}"),e.indentLevel--},ClassBody:ua,StaticBlock(t,e){e.write("static "),this.BlockStatement(t,e)},EmptyStatement(t,e){e.write(";")},ExpressionStatement(t,e){let r=e.expressionsPrecedence[t.expression.type];r===ft||r===3&&t.expression.left.type[0]==="O"?(e.write("("),this[t.expression.type](t.expression,e),e.write(")")):this[t.expression.type](t.expression,e),e.write(";")},IfStatement(t,e){e.write("if ("),this[t.test.type](t.test,e),e.write(") "),this[t.consequent.type](t.consequent,e),t.alternate!=null&&(e.write(" else "),this[t.alternate.type](t.alternate,e))},LabeledStatement(t,e){this[t.label.type](t.label,e),e.write(": "),this[t.body.type](t.body,e)},BreakStatement(t,e){e.write("break"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},ContinueStatement(t,e){e.write("continue"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},WithStatement(t,e){e.write("with ("),this[t.object.type](t.object,e),e.write(") "),this[t.body.type](t.body,e)},SwitchStatement(t,e){let r=e.indent.repeat(e.indentLevel++),{lineEnd:n,writeComments:i}=e;e.indentLevel++;let s=r+e.indent,a=s+e.indent;e.write("switch ("),this[t.discriminant.type](t.discriminant,e),e.write(") {"+n);let{cases:o}=t,{length:l}=o;for(let c=0;c<l;c++){let u=o[c];i&&u.comments!=null&&Le(e,u.comments,s,n),u.test?(e.write(s+"case "),this[u.test.type](u.test,e),e.write(":"+n)):e.write(s+"default:"+n);let{consequent:h}=u,{length:p}=h;for(let d=0;d<p;d++){let f=h[d];i&&f.comments!=null&&Le(e,f.comments,a,n),e.write(a),this[f.type](f,e),e.write(n)}}e.indentLevel-=2,e.write(r+"}")},ReturnStatement(t,e){e.write("return"),t.argument&&(e.write(" "),this[t.argument.type](t.argument,e)),e.write(";")},ThrowStatement(t,e){e.write("throw "),this[t.argument.type](t.argument,e),e.write(";")},TryStatement(t,e){if(e.write("try "),this[t.block.type](t.block,e),t.handler){let{handler:r}=t;r.param==null?e.write(" catch "):(e.write(" catch ("),this[r.param.type](r.param,e),e.write(") ")),this[r.body.type](r.body,e)}t.finalizer&&(e.write(" finally "),this[t.finalizer.type](t.finalizer,e))},WhileStatement(t,e){e.write("while ("),this[t.test.type](t.test,e),e.write(") "),this[t.body.type](t.body,e)},DoWhileStatement(t,e){e.write("do "),this[t.body.type](t.body,e),e.write(" while ("),this[t.test.type](t.test,e),e.write(");")},ForStatement(t,e){if(e.write("for ("),t.init!=null){let{init:r}=t;r.type[0]==="V"?oi(e,r):this[r.type](r,e)}e.write("; "),t.test&&this[t.test.type](t.test,e),e.write("; "),t.update&&this[t.update.type](t.update,e),e.write(") "),this[t.body.type](t.body,e)},ForInStatement:sa=function(t,e){e.write(`for ${t.await?"await ":""}(`);let{left:r}=t;r.type[0]==="V"?oi(e,r):this[r.type](r,e),e.write(t.type[3]==="I"?" in ":" of "),this[t.right.type](t.right,e),e.write(") "),this[t.body.type](t.body,e)},ForOfStatement:sa,DebuggerStatement(t,e){e.write("debugger;",t)},FunctionDeclaration:aa=function(t,e){e.write((t.async?"async ":"")+(t.generator?"function* ":"function ")+(t.id?t.id.name:""),t),ur(e,t.params),e.write(" "),this[t.body.type](t.body,e)},FunctionExpression:aa,VariableDeclaration(t,e){oi(e,t),e.write(";")},VariableDeclarator(t,e){this[t.id.type](t.id,e),t.init!=null&&(e.write(" = "),this[t.init.type](t.init,e))},ClassDeclaration(t,e){if(e.write("class "+(t.id?`${t.id.name} `:""),t),t.superClass){e.write("extends ");let{superClass:r}=t,{type:n}=r,i=e.expressionsPrecedence[n];(n[0]!=="C"||n[1]!=="l"||n[5]!=="E")&&(i===ft||i<e.expressionsPrecedence.ClassExpression)?(e.write("("),this[t.superClass.type](r,e),e.write(")")):this[r.type](r,e),e.write(" ")}this.ClassBody(t.body,e)},ImportDeclaration(t,e){e.write("import ");let{specifiers:r,attributes:n}=t,{length:i}=r,s=0;if(i>0){for(;s<i;){s>0&&e.write(", ");let a=r[s],o=a.type[6];if(o==="D")e.write(a.local.name,a),s++;else if(o==="N")e.write("* as "+a.local.name,a),s++;else break}if(s<i){for(e.write("{");;){let a=r[s],{name:o}=a.imported;if(e.write(o,a),o!==a.local.name&&e.write(" as "+a.local.name),++s<i)e.write(", ");else break}e.write("}")}e.write(" from ")}if(this.Literal(t.source,e),n&&n.length>0){e.write(" with { ");for(let a=0;a<n.length;a++)this.ImportAttribute(n[a],e),a<n.length-1&&e.write(", ");e.write(" }")}e.write(";")},ImportAttribute(t,e){this.Identifier(t.key,e),e.write(": "),this.Literal(t.value,e)},ImportExpression(t,e){e.write("import("),this[t.source.type](t.source,e),e.write(")")},ExportDefaultDeclaration(t,e){e.write("export default "),this[t.declaration.type](t.declaration,e),e.expressionsPrecedence[t.declaration.type]!=null&&t.declaration.type[0]!=="F"&&e.write(";")},ExportNamedDeclaration(t,e){if(e.write("export "),t.declaration)this[t.declaration.type](t.declaration,e);else{e.write("{");let{specifiers:r}=t,{length:n}=r;if(n>0)for(let i=0;;){let s=r[i],{name:a}=s.local;if(e.write(a,s),a!==s.exported.name&&e.write(" as "+s.exported.name),++i<n)e.write(", ");else break}if(e.write("}"),t.source&&(e.write(" from "),this.Literal(t.source,e)),t.attributes&&t.attributes.length>0){e.write(" with { ");for(let i=0;i<t.attributes.length;i++)this.ImportAttribute(t.attributes[i],e),i<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")}},ExportAllDeclaration(t,e){if(t.exported!=null?e.write("export * as "+t.exported.name+" from "):e.write("export * from "),this.Literal(t.source,e),t.attributes&&t.attributes.length>0){e.write(" with { ");for(let r=0;r<t.attributes.length;r++)this.ImportAttribute(t.attributes[r],e),r<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")},MethodDefinition(t,e){t.static&&e.write("static ");let r=t.kind[0];(r==="g"||r==="s")&&e.write(t.kind+" "),t.value.async&&e.write("async "),t.value.generator&&e.write("*"),t.computed?(e.write("["),this[t.key.type](t.key,e),e.write("]")):this[t.key.type](t.key,e),ur(e,t.value.params),e.write(" "),this[t.value.body.type](t.value.body,e)},ClassExpression(t,e){this.ClassDeclaration(t,e)},ArrowFunctionExpression(t,e){e.write(t.async?"async ":"",t);let{params:r}=t;r!=null&&(r.length===1&&r[0].type[0]==="I"?e.write(r[0].name,r[0]):ur(e,t.params)),e.write(" => "),t.body.type[0]==="O"?(e.write("("),this.ObjectExpression(t.body,e),e.write(")")):this[t.body.type](t.body,e)},ThisExpression(t,e){e.write("this",t)},Super(t,e){e.write("super",t)},RestElement:oa=function(t,e){e.write("..."),this[t.argument.type](t.argument,e)},SpreadElement:oa,YieldExpression(t,e){e.write(t.delegate?"yield*":"yield"),t.argument&&(e.write(" "),this[t.argument.type](t.argument,e))},AwaitExpression(t,e){e.write("await ",t),Qr(e,t.argument,t)},TemplateLiteral(t,e){let{quasis:r,expressions:n}=t;e.write("`");let{length:i}=n;for(let a=0;a<i;a++){let o=n[a],l=r[a];e.write(l.value.raw,l),e.write("${"),this[o.type](o,e),e.write("}")}let s=r[r.length-1];e.write(s.value.raw,s),e.write("`")},TemplateElement(t,e){e.write(t.value.raw,t)},TaggedTemplateExpression(t,e){Qr(e,t.tag,t),this[t.quasi.type](t.quasi,e)},ArrayExpression:ca=function(t,e){if(e.write("["),t.elements.length>0){let{elements:r}=t,{length:n}=r;for(let i=0;;){let s=r[i];if(s!=null&&this[s.type](s,e),++i<n)e.write(", ");else{s==null&&e.write(", ");break}}}e.write("]")},ArrayPattern:ca,ObjectExpression(t,e){let r=e.indent.repeat(e.indentLevel++),{lineEnd:n,writeComments:i}=e,s=r+e.indent;if(e.write("{"),t.properties.length>0){e.write(n),i&&t.comments!=null&&Le(e,t.comments,s,n);let a=","+n,{properties:o}=t,{length:l}=o;for(let c=0;;){let u=o[c];if(i&&u.comments!=null&&Le(e,u.comments,s,n),e.write(s),this[u.type](u,e),++c<l)e.write(a);else break}e.write(n),i&&t.trailingComments!=null&&Le(e,t.trailingComments,s,n),e.write(r+"}")}else i?t.comments!=null?(e.write(n),Le(e,t.comments,s,n),t.trailingComments!=null&&Le(e,t.trailingComments,s,n),e.write(r+"}")):t.trailingComments!=null?(e.write(n),Le(e,t.trailingComments,s,n),e.write(r+"}")):e.write("}"):e.write("}");e.indentLevel--},Property(t,e){t.method||t.kind[0]!=="i"?this.MethodDefinition(t,e):(t.shorthand||(t.computed?(e.write("["),this[t.key.type](t.key,e),e.write("]")):this[t.key.type](t.key,e),e.write(": ")),this[t.value.type](t.value,e))},PropertyDefinition(t,e){if(t.static&&e.write("static "),t.computed&&e.write("["),this[t.key.type](t.key,e),t.computed&&e.write("]"),t.value==null){t.key.type[0]!=="F"&&e.write(";");return}e.write(" = "),this[t.value.type](t.value,e),e.write(";")},ObjectPattern(t,e){if(e.write("{"),t.properties.length>0){let{properties:r}=t,{length:n}=r;for(let i=0;this[r[i].type](r[i],e),++i<n;)e.write(", ")}e.write("}")},SequenceExpression(t,e){ur(e,t.expressions)},UnaryExpression(t,e){if(t.prefix){let{operator:r,argument:n,argument:{type:i}}=t;e.write(r);let s=$o(e,n,t);!s&&(r.length>1||i[0]==="U"&&(i[1]==="n"||i[1]==="p")&&n.prefix&&n.operator[0]===r&&(r==="+"||r==="-"))&&e.write(" "),s?(e.write(r.length>1?" (":"("),this[i](n,e),e.write(")")):this[i](n,e)}else this[t.argument.type](t.argument,e),e.write(t.operator)},UpdateExpression(t,e){t.prefix?(e.write(t.operator),this[t.argument.type](t.argument,e)):(this[t.argument.type](t.argument,e),e.write(t.operator))},AssignmentExpression(t,e){this[t.left.type](t.left,e),e.write(" "+t.operator+" "),this[t.right.type](t.right,e)},AssignmentPattern(t,e){this[t.left.type](t.left,e),e.write(" = "),this[t.right.type](t.right,e)},BinaryExpression:la=function(t,e){let r=t.operator==="in";r&&e.write("("),Qr(e,t.left,t,!1),e.write(" "+t.operator+" "),Qr(e,t.right,t,!0),r&&e.write(")")},LogicalExpression:la,ConditionalExpression(t,e){let{test:r}=t,n=e.expressionsPrecedence[r.type];n===ft||n<=e.expressionsPrecedence.ConditionalExpression?(e.write("("),this[r.type](r,e),e.write(")")):this[r.type](r,e),e.write(" ? "),this[t.consequent.type](t.consequent,e),e.write(" : "),this[t.alternate.type](t.alternate,e)},NewExpression(t,e){e.write("new ");let r=e.expressionsPrecedence[t.callee.type];r===ft||r<e.expressionsPrecedence.CallExpression||o_(t.callee)?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),ur(e,t.arguments)},CallExpression(t,e){let r=e.expressionsPrecedence[t.callee.type];r===ft||r<e.expressionsPrecedence.CallExpression?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),t.optional&&e.write("?."),ur(e,t.arguments)},ChainExpression(t,e){this[t.expression.type](t.expression,e)},MemberExpression(t,e){let r=e.expressionsPrecedence[t.object.type];r===ft||r<e.expressionsPrecedence.MemberExpression?(e.write("("),this[t.object.type](t.object,e),e.write(")")):this[t.object.type](t.object,e),t.computed?(t.optional&&e.write("?."),e.write("["),this[t.property.type](t.property,e),e.write("]")):(t.optional?e.write("?."):e.write("."),this[t.property.type](t.property,e))},MetaProperty(t,e){e.write(t.meta.name+"."+t.property.name,t)},Identifier(t,e){e.write(t.name,t)},PrivateIdentifier(t,e){e.write(`#${t.name}`,t)},Literal(t,e){t.raw!=null?e.write(t.raw,t):t.regex!=null?this.RegExpLiteral(t,e):t.bigint!=null?e.write(t.bigint+"n",t):e.write(i_(t.value),t)},RegExpLiteral(t,e){let{regex:r}=t;e.write(`/${r.pattern}/${r.flags}`,t)}},l_={},c_=xs,Oi=class{constructor(e){let r=e??l_;this.output="",r.output!=null?(this.output=r.output,this.write=this.writeToStream):this.output="",this.generator=r.generator!=null?r.generator:xs,this.expressionsPrecedence=r.expressionsPrecedence!=null?r.expressionsPrecedence:s_,this.indent=r.indent!=null?r.indent:" ",this.lineEnd=r.lineEnd!=null?r.lineEnd:`\n`,this.indentLevel=r.startingIndentLevel!=null?r.startingIndentLevel:0,this.writeComments=r.comments?r.comments:!1,r.sourceMap!=null&&(this.write=r.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=r.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`\n`).length-1,this.mapping={original:null,generated:this,name:void 0,source:r.sourceMap.file||r.sourceMap._file})}write(e){this.output+=e}writeToStream(e){this.output.write(e)}writeAndMap(e,r){this.output+=e,this.map(e,r)}writeToStreamAndMap(e,r){this.output.write(e),this.map(e,r)}map(e,r){if(r!=null){let{type:s}=r;if(s[0]==="L"&&s[2]==="n"){this.column=0,this.line++;return}if(r.loc!=null){let{mapping:a}=this;a.original=r.loc.start,a.name=r.name,this.sourceMap.addMapping(a)}if(s[0]==="T"&&s[8]==="E"||s[0]==="L"&&s[1]==="i"&&typeof r.value=="string"){let{length:a}=e,{column:o,line:l}=this;for(let c=0;c<a;c++)e[c]===`\n`?(o=0,l++):o++;this.column=o,this.line=l;return}}let{length:n}=e,{lineEnd:i}=this;n>0&&(this.lineEndSize>0&&(i.length===1?e[n-1]===i:e.endsWith(i))?(this.line+=this.lineEndSize,this.column=0):this.column+=n)}toString(){return this.output}};function bs(t,e){let r=new Oi(e);return r.generator[t.type](t,r),r.output}var u_=Object.defineProperty,p_=(t,e,r)=>e in t?u_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ne=(t,e,r)=>p_(t,typeof e!="symbol"?e+"":e,r),h_=new Set(["Infinity","NaN","undefined","null","true","false"]),d_=new Set(["Math","Array","Object","String","Number","Boolean","Date","RegExp","Error","JSON","Promise","Set","Map","WeakSet","WeakMap","Symbol","BigInt","Proxy","Reflect","console","isNaN","isFinite","parseInt","parseFloat","encodeURI","decodeURI","encodeURIComponent","decodeURIComponent"]),Vi=class{constructor(){ne(this,"scopes",[]),ne(this,"scopeTypes",[]),ne(this,"scopeCounts",new Map),ne(this,"contextBoundVars",new Set),ne(this,"arrayPatternElements",new Set),ne(this,"rootParams",new Set),ne(this,"localSeriesVars",new Set),ne(this,"varKinds",new Map),ne(this,"loopVars",new Set),ne(this,"loopVarNames",new Map),ne(this,"paramIdCounter",0),ne(this,"cacheIdCounter",0),ne(this,"tempVarCounter",0),ne(this,"taCallIdCounter",0),ne(this,"userCallIdCounter",0),ne(this,"plotCallIdCounter",0),ne(this,"alertCallIdCounter",0),ne(this,"loopGuardCounter",0),ne(this,"hoistingStack",[]),ne(this,"suppressHoisting",!1),ne(this,"reservedNames",new Set),ne(this,"userFunctions",new Set),ne(this,"userMethods",new Set),ne(this,"regularUserFunctions",new Set),ne(this,"udtTypeNames",new Map),ne(this,"udtInstances",new Map),ne(this,"functionReturnTypes",new Map),ne(this,"functionReturnTupleTypes",new Map),ne(this,"functionParamUdtTypes",new Map),this.pushScope("glb")}get nextParamIdArg(){return{type:"Identifier",name:`\'p${this.paramIdCounter++}\'`}}get nextCacheIdArg(){return{type:"Identifier",name:`\'cache_${this.cacheIdCounter++}\'`}}getNextTACallId(){return{type:"Literal",value:`_ta${this.taCallIdCounter++}`}}getNextUserCallId(){return{type:"Literal",value:`_fn${this.userCallIdCounter++}`}}getNextPlotCallId(){return{type:"Literal",value:`#${this.plotCallIdCounter++}`}}getNextAlertCallId(){return{type:"Literal",value:`alert_${this.alertCallIdCounter++}`}}getNextLoopGuardName(){return`__lg${this.loopGuardCounter++}`}pushScope(e){this.scopes.push(new Map),this.scopeTypes.push(e),this.scopeCounts.set(e,(this.scopeCounts.get(e)||0)+1)}popScope(){this.scopes.pop(),this.scopeTypes.pop()}getCurrentScopeType(){return this.scopeTypes[this.scopeTypes.length-1]}isInsideFunctionScope(){for(let e=this.scopeTypes.length-1;e>=0;e--)if(this.scopeTypes[e]==="fn")return!0;return!1}getCurrentScopeCount(){return this.scopeCounts.get(this.getCurrentScopeType())||1}addLocalSeriesVar(e){this.localSeriesVars.add(e)}removeLocalSeriesVar(e){this.localSeriesVars.delete(e)}isLocalSeriesVar(e){return this.localSeriesVars.has(e)}addUdtTypeName(e,r={}){this.udtTypeNames.set(e,r)}isUdtTypeName(e){return this.udtTypeNames.has(e)}getUdtTypeFields(e){return this.udtTypeNames.get(e)}markVariableAsUdtInstance(e,r){this.udtInstances.set(e,r)}getVariableUdtType(e){return this.udtInstances.get(e)}isUdtInstance(e){return this.udtInstances.has(e)}setFunctionReturnType(e,r){let n=this.functionReturnTypes.get(e);if(n&&n!==r){this.functionReturnTypes.delete(e);return}this.functionReturnTypes.set(e,r)}getFunctionReturnType(e){return this.functionReturnTypes.get(e)}setFunctionReturnTupleType(e,r){let n=this.functionReturnTupleTypes.get(e);if(n&&(n.length!==r.length||n.some((i,s)=>i!==r[s]))){this.functionReturnTupleTypes.delete(e);return}this.functionReturnTupleTypes.set(e,r)}getFunctionReturnTupleType(e){return this.functionReturnTupleTypes.get(e)}setFunctionParamUdtTypes(e,r){this.functionParamUdtTypes.set(e,r)}getFunctionParamUdtTypes(e){return this.functionParamUdtTypes.get(e)}unmarkVariableAsUdtInstance(e){this.udtInstances.delete(e)}addContextBoundVar(e,r=!1){this.contextBoundVars.add(e),r&&this.rootParams.add(e)}removeContextBoundVar(e){this.contextBoundVars.has(e)&&(this.contextBoundVars.delete(e),this.rootParams.has(e)&&this.rootParams.delete(e))}addArrayPatternElement(e){this.arrayPatternElements.add(e)}isContextBound(e){return h_.has(e)||d_.has(e)?!1:this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,r){this.loopVars.add(e),this.loopVarNames.set(e,r)}removeLoopVariable(e){this.loopVars.delete(e),this.loopVarNames.delete(e)}getLoopVariableName(e){return this.loopVarNames.get(e)}isLoopVariable(e){return this.loopVars.has(e)}addReservedName(e){this.reservedNames.add(e)}addUserFunction(e){this.userFunctions.add(e)}isUserFunction(e){return this.userFunctions.has(e)}addUserMethod(e){this.userMethods.add(e)}isUserMethod(e){return this.userMethods.has(e)}addRegularUserFunction(e){this.regularUserFunctions.add(e)}isRegularUserFunction(e){return this.regularUserFunctions.has(e)}addVariable(e,r){if(this.isContextBound(e))return e;let n=this.scopes[this.scopes.length-1],i=this.scopeTypes[this.scopeTypes.length-1],s=this.scopeCounts.get(i)||1,a=`${i}${s}_${e}`;return n.set(e,a),this.varKinds.set(a,r),a}getVariable(e){if(this.loopVars.has(e)){let r=this.loopVarNames.get(e);if(r)return[r,"let"]}if(this.isContextBound(e))return[e,"let"];for(let r=this.scopes.length-1;r>=0;r--){let n=this.scopes[r];if(n.has(e)){let i=n.get(e),s=this.varKinds.get(i)||"let";return[i,s]}}return[e,"let"]}isVariableInFunctionScope(e){for(let r=this.scopes.length-1;r>=0;r--)if(this.scopes[r].has(e)){for(let n=0;n<=r;n++)if(this.scopeTypes[n]==="fn")return!0;return!1}return!1}generateTempVar(){return`temp_${++this.tempVarCounter}`}enterHoistingScope(){this.hoistingStack.push([])}exitHoistingScope(){return this.hoistingStack.pop()||[]}addHoistedStatement(e){this.hoistingStack.length>0&&!this.suppressHoisting&&this.hoistingStack[this.hoistingStack.length-1].push(e)}addOuterHoistedStatement(e){if(this.hoistingStack.length>0&&!this.suppressHoisting){let r=Math.min(1,this.hoistingStack.length-1);this.hoistingStack[r].push(e)}}getCurrentHoistingScope(){return this.hoistingStack.length===0?null:this.hoistingStack[this.hoistingStack.length-1]}setSuppressHoisting(e){this.suppressHoisting=e}shouldSuppressHoisting(){return this.suppressHoisting}hasVariableInScope(e){if(this.reservedNames.has(e))return!0;for(let r=this.scopes.length-1;r>=0;r--)if(this.scopes[r].has(e))return!0;return!!(this.contextBoundVars.has(e)||this.loopVars.has(e)||this.localSeriesVars.has(e))}generateParamId(){let e=`p${this.paramIdCounter++}`;for(;this.hasVariableInScope(e);)e=`p${this.paramIdCounter++}`;let r=this.scopes[this.scopes.length-1];return r&&r.set(e,e),e}};function mt(t,e,r,n,i){r||(r=I),(function s(a,o,l){var c=l||a.type;Uo(r,c,a,o,s),e[c]&&e[c](a,o)})(t,n,i)}function Wo(t,e,r,n,i){var s=[];r||(r=I),(function a(o,l,c){var u=c||o.type,h=o!==s[s.length-1];h&&s.push(o),Uo(r,u,o,l,a),e[u]&&e[u](o,l||s,s),h&&s.pop()})(t,n,i)}function Ne(t,e,r,n,i){var s=r?f_(r,n||void 0):n;(function a(o,l,c){s[c||o.type](o,l,a)})(t,e,i)}function f_(t,e){var r=Object.create(e||I);for(var n in t)r[n]=t[n];return r}function vs(t,e,r){r(t,e)}function tr(t,e,r){}function Uo(t,e,r,n,i){if(t[e]==null)throw new Error("No walker function defined for node type "+e);t[e](r,n,i)}var I={};I.Program=I.BlockStatement=I.StaticBlock=function(t,e,r){for(var n=0,i=t.body;n<i.length;n+=1){var s=i[n];r(s,e,"Statement")}};I.Statement=vs;I.EmptyStatement=tr;I.ExpressionStatement=I.ParenthesizedExpression=I.ChainExpression=function(t,e,r){return r(t.expression,e,"Expression")};I.IfStatement=function(t,e,r){r(t.test,e,"Expression"),r(t.consequent,e,"Statement"),t.alternate&&r(t.alternate,e,"Statement")};I.LabeledStatement=function(t,e,r){return r(t.body,e,"Statement")};I.BreakStatement=I.ContinueStatement=tr;I.WithStatement=function(t,e,r){r(t.object,e,"Expression"),r(t.body,e,"Statement")};I.SwitchStatement=function(t,e,r){r(t.discriminant,e,"Expression");for(var n=0,i=t.cases;n<i.length;n+=1){var s=i[n];r(s,e)}};I.SwitchCase=function(t,e,r){t.test&&r(t.test,e,"Expression");for(var n=0,i=t.consequent;n<i.length;n+=1){var s=i[n];r(s,e,"Statement")}};I.ReturnStatement=I.YieldExpression=I.AwaitExpression=function(t,e,r){t.argument&&r(t.argument,e,"Expression")};I.ThrowStatement=I.SpreadElement=function(t,e,r){return r(t.argument,e,"Expression")};I.TryStatement=function(t,e,r){r(t.block,e,"Statement"),t.handler&&r(t.handler,e),t.finalizer&&r(t.finalizer,e,"Statement")};I.CatchClause=function(t,e,r){t.param&&r(t.param,e,"Pattern"),r(t.body,e,"Statement")};I.WhileStatement=I.DoWhileStatement=function(t,e,r){r(t.test,e,"Expression"),r(t.body,e,"Statement")};I.ForStatement=function(t,e,r){t.init&&r(t.init,e,"ForInit"),t.test&&r(t.test,e,"Expression"),t.update&&r(t.update,e,"Expression"),r(t.body,e,"Statement")};I.ForInStatement=I.ForOfStatement=function(t,e,r){r(t.left,e,"ForInit"),r(t.right,e,"Expression"),r(t.body,e,"Statement")};I.ForInit=function(t,e,r){t.type==="VariableDeclaration"?r(t,e):r(t,e,"Expression")};I.DebuggerStatement=tr;I.FunctionDeclaration=function(t,e,r){return r(t,e,"Function")};I.VariableDeclaration=function(t,e,r){for(var n=0,i=t.declarations;n<i.length;n+=1){var s=i[n];r(s,e)}};I.VariableDeclarator=function(t,e,r){r(t.id,e,"Pattern"),t.init&&r(t.init,e,"Expression")};I.Function=function(t,e,r){t.id&&r(t.id,e,"Pattern");for(var n=0,i=t.params;n<i.length;n+=1){var s=i[n];r(s,e,"Pattern")}r(t.body,e,t.expression?"Expression":"Statement")};I.Pattern=function(t,e,r){t.type==="Identifier"?r(t,e,"VariablePattern"):t.type==="MemberExpression"?r(t,e,"MemberPattern"):r(t,e)};I.VariablePattern=tr;I.MemberPattern=vs;I.RestElement=function(t,e,r){return r(t.argument,e,"Pattern")};I.ArrayPattern=function(t,e,r){for(var n=0,i=t.elements;n<i.length;n+=1){var s=i[n];s&&r(s,e,"Pattern")}};I.ObjectPattern=function(t,e,r){for(var n=0,i=t.properties;n<i.length;n+=1){var s=i[n];s.type==="Property"?(s.computed&&r(s.key,e,"Expression"),r(s.value,e,"Pattern")):s.type==="RestElement"&&r(s.argument,e,"Pattern")}};I.Expression=vs;I.ThisExpression=I.Super=I.MetaProperty=tr;I.ArrayExpression=function(t,e,r){for(var n=0,i=t.elements;n<i.length;n+=1){var s=i[n];s&&r(s,e,"Expression")}};I.ObjectExpression=function(t,e,r){for(var n=0,i=t.properties;n<i.length;n+=1){var s=i[n];r(s,e)}};I.FunctionExpression=I.ArrowFunctionExpression=I.FunctionDeclaration;I.SequenceExpression=function(t,e,r){for(var n=0,i=t.expressions;n<i.length;n+=1){var s=i[n];r(s,e,"Expression")}};I.TemplateLiteral=function(t,e,r){for(var n=0,i=t.quasis;n<i.length;n+=1){var s=i[n];r(s,e)}for(var a=0,o=t.expressions;a<o.length;a+=1){var l=o[a];r(l,e,"Expression")}};I.TemplateElement=tr;I.UnaryExpression=I.UpdateExpression=function(t,e,r){r(t.argument,e,"Expression")};I.BinaryExpression=I.LogicalExpression=function(t,e,r){r(t.left,e,"Expression"),r(t.right,e,"Expression")};I.AssignmentExpression=I.AssignmentPattern=function(t,e,r){r(t.left,e,"Pattern"),r(t.right,e,"Expression")};I.ConditionalExpression=function(t,e,r){r(t.test,e,"Expression"),r(t.consequent,e,"Expression"),r(t.alternate,e,"Expression")};I.NewExpression=I.CallExpression=function(t,e,r){if(r(t.callee,e,"Expression"),t.arguments)for(var n=0,i=t.arguments;n<i.length;n+=1){var s=i[n];r(s,e,"Expression")}};I.MemberExpression=function(t,e,r){r(t.object,e,"Expression"),t.computed&&r(t.property,e,"Expression")};I.ExportNamedDeclaration=I.ExportDefaultDeclaration=function(t,e,r){if(t.declaration&&r(t.declaration,e,t.type==="ExportNamedDeclaration"||t.declaration.id?"Statement":"Expression"),t.source&&r(t.source,e,"Expression"),t.attributes)for(var n=0,i=t.attributes;n<i.length;n+=1){var s=i[n];r(s,e)}};I.ExportAllDeclaration=function(t,e,r){if(t.exported&&r(t.exported,e),r(t.source,e,"Expression"),t.attributes)for(var n=0,i=t.attributes;n<i.length;n+=1){var s=i[n];r(s,e)}};I.ImportAttribute=function(t,e,r){r(t.value,e,"Expression")};I.ImportDeclaration=function(t,e,r){for(var n=0,i=t.specifiers;n<i.length;n+=1){var s=i[n];r(s,e)}if(r(t.source,e,"Expression"),t.attributes)for(var a=0,o=t.attributes;a<o.length;a+=1){var l=o[a];r(l,e)}};I.ImportExpression=function(t,e,r){r(t.source,e,"Expression"),t.options&&r(t.options,e,"Expression")};I.ImportSpecifier=I.ImportDefaultSpecifier=I.ImportNamespaceSpecifier=I.Identifier=I.PrivateIdentifier=I.Literal=tr;I.TaggedTemplateExpression=function(t,e,r){r(t.tag,e,"Expression"),r(t.quasi,e,"Expression")};I.ClassDeclaration=I.ClassExpression=function(t,e,r){return r(t,e,"Class")};I.Class=function(t,e,r){t.id&&r(t.id,e,"Pattern"),t.superClass&&r(t.superClass,e,"Expression"),r(t.body,e)};I.ClassBody=function(t,e,r){for(var n=0,i=t.body;n<i.length;n+=1){var s=i[n];r(s,e)}};I.MethodDefinition=I.PropertyDefinition=I.Property=function(t,e,r){t.computed&&r(t.key,e,"Expression"),t.value&&r(t.value,e,"Expression")};var fe="$",S={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,r=!1){return{type:"MemberExpression",object:t,property:e,computed:r}},createContextIdentifier(){return this.createIdentifier("$")},createLocalContextIdentifier(){return this.createIdentifier("$$")},createContextVariableReference(t,e){let r=this.createContextIdentifier(),n=this.createIdentifier(t),i=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(r,n,!1),i,!1)},createLocalContextVariableReference(t,e){let r=this.createLocalContextIdentifier(),n=this.createIdentifier(t),i=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(r,n,!1),i,!1)},createDynamicContextVariableReference(t,e){let r=this.createContextIdentifier(),n=this.createIdentifier(t);return this.createMemberExpression(this.createMemberExpression(r,n,!1),e,!0)},createContextVariableAccess0(t,e){let r=this.createContextVariableReference(t,e);return this.createGetCall(r,0)},createDynamicContextVariableAccess0(t,e){let r=this.createDynamicContextVariableReference(t,e);return this.createGetCall(r,0)},createArrayAccess(t,e){let r=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,r,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,r="="){return{type:"AssignmentExpression",operator:r,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,r){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),i=[t,e];return r&&i.push(r),this.createCallExpression(n,i)},createInitVarCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("initVar"),!1),n=[t,e];return this.createCallExpression(r,n)},createGetCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),n=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(r,[t,n])},createSetCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(r,[t,e])},createMathEqCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),n=this.createMemberExpression(r,this.createIdentifier("math"),!1),i=this.createMemberExpression(n,this.createIdentifier("__eq"),!1);return this.createCallExpression(i,[t,e])},createMathNeqCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),n=this.createMemberExpression(r,this.createIdentifier("math"),!1),i=this.createMemberExpression(n,this.createIdentifier("__neq"),!1);return this.createCallExpression(i,[t,e])},createMathCompareCall(t,e,r){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),i=this.createMemberExpression(n,this.createIdentifier("math"),!1),s=this.createMemberExpression(i,this.createIdentifier(t),!1);return this.createCallExpression(s,[e,r])},createMathIntDivCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),n=this.createMemberExpression(r,this.createIdentifier("math"),!1),i=this.createMemberExpression(n,this.createIdentifier("__idiv"),!1);return this.createCallExpression(i,[t,e])},createWrapperFunction(t){return{type:"FunctionDeclaration",id:null,params:[this.createIdentifier("context")],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:t}]}}},createVariableDeclaration(t,e){return{type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:this.createIdentifier(t),init:e}]}},createAwaitExpression(t){return{type:"AwaitExpression",argument:t}}},$t=["ta","math","request","array","input","color","ticker","strategy"],yt=["hline","plot","fill","label","line","box","linefill","polyline","table","na","alert","time","time_close","dayofmonth","dayofweek","hour","minute","month","second","weekofyear","year"],m_=["request.security","request.security_lower_tf"],y_=["chart.left_visible_bar_time","chart.right_visible_bar_time"],pa=["plot","hline","fill","strategy.exit"],g_=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],__=new Set([...$t,"fill","plot","hline","label","line","size","extend","display","format","location","shape","text","xloc","yloc","linefill","polyline","box","table","map","matrix","chart","alert","barstate","syminfo","timeframe","strategy","log","str"]),ha=new Set(["await","debugger","default","delete","extends","finally","function","implements","instanceof","interface","let","new","package","private","protected","public","static","super","throw","typeof","void","with","yield"]),qo=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],ws=[...$t,"plotchar","plotshape","plotarrow","plotbar","plotcandle","plot","bgcolor","barcolor","hline","fill","indicator","library","alertcondition","alert","error","max_bars_back","fixnan","na","nz","timestamp","str","box","line","label","table","chart","linefill","polyline","map","matrix","log","Type","bool","int","float","string","timeframe","syminfo","barstate","bar_index","last_bar_index","last_bar_time","inputs","time","time_close","time_tradingday","dayofmonth","hour","minute","month","second","weekofyear","year","order","currency","display","shape","location","size","format","dayofweek","xloc","yloc","text","font","extend","position","barmerge","adjustment","backadjustment","earnings","dividends","splits"],x_=["na","nz","plot","plotchar","color","hline","fill"];function b_(t){let e=null,r=fe;if(t.type==="Program"&&t.body.length>0){let d=t.body[0];if(d.type==="ExpressionStatement"&&(d.expression.type==="ArrowFunctionExpression"||d.expression.type==="FunctionExpression")){let f=d.expression;f.body.type==="BlockStatement"&&(e=f.body.body,f.params.length>0&&f.params[0].type==="Identifier"&&(r=f.params[0].name))}}if(!e)return;let n=new Set,i=new Set,s=d=>{d.type==="Identifier"?n.add(d.name):d.type==="ObjectPattern"?d.properties.forEach(f=>s(f.value)):d.type==="ArrayPattern"&&d.elements.forEach(f=>{f&&s(f)})};Ne(t,{},{VariableDeclarator(d,f,m){s(d.id),d.init&&m(d.init,f)},FunctionDeclaration(d,f,m){s(d.id);for(let x of d.params)x&&x.type==="AssignmentPattern"&&x.right&&m(x.right,f);m(d.body,f)},Identifier(d,f,m){i.add(d.name)},MemberExpression(d,f,m){m(d.object,f),d.computed&&m(d.property,f)},Property(d,f,m){d.computed&&m(d.key,f),m(d.value,f)}}),e.forEach(d=>{d.type==="VariableDeclaration"?d.declarations.forEach(f=>s(f.id)):d.type==="FunctionDeclaration"&&s(d.id)});let a=qo,o=ws,l=a.filter(d=>!n.has(d)),c=o.filter(d=>!n.has(d)),u=l.filter(d=>i.has(d)),h=c.filter(d=>i.has(d)),p=[];u.length>0&&p.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:u.map(d=>({type:"Property",key:{type:"Identifier",name:d},value:{type:"Identifier",name:d},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:r},property:{type:"Identifier",name:"data"},computed:!1}}]}),h.length>0&&p.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:h.map(d=>({type:"Property",key:{type:"Identifier",name:d},value:{type:"Identifier",name:d},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:r},property:{type:"Identifier",name:"pine"},computed:!1}}]}),p.length>0&&e.unshift(...p)}function v_(t){let e=null,r=fe;if(t.type==="Program"&&t.body.length>0){let o=t.body[0];if(o.type==="ExpressionStatement"&&(o.expression.type==="ArrowFunctionExpression"||o.expression.type==="FunctionExpression")){let l=o.expression;l.body.type==="BlockStatement"&&(e=l.body.body,l.params.length>0&&l.params[0].type==="Identifier"&&(r=l.params[0].name))}}if(!e)return;let n=new Set(qo),i=new Set(ws),s=new Set(x_),a=new Map;e.forEach(o=>{o.type==="VariableDeclaration"&&o.declarations.forEach(l=>{if(l.init&&l.init.type==="MemberExpression"&&l.init.object.type==="Identifier"&&l.init.object.name===r&&l.init.property.type==="Identifier"){let c=l.init.property.name,u=null;if(c==="data"?u=n:c==="pine"?u=i:c==="core"&&(u=s),u&&l.id.type==="ObjectPattern")l.id.properties.forEach(h=>{if(h.type==="Property"&&h.key.type==="Identifier"&&h.value.type==="Identifier"){let p=h.key.name,d=h.value.name;u.has(p)&&p!==d&&(a.set(d,p),h.value.name=p,h.shorthand=!0)}});else if(l.id.type==="Identifier"&&$t.includes(c)){let h=c,p=l.id.name;h!==p&&(a.set(p,h),l.id.name=h)}}})}),a.size>0&&Ne(t,{},{Identifier(o){a.has(o.name)&&(o.name=a.get(o.name))},MemberExpression(o,l,c){c(o.object,l),o.computed&&c(o.property,l)},Property(o,l,c){o.computed&&c(o.key,l),c(o.value,l)}})}function w_(t){try{let e=_s(t,{ecmaVersion:"latest",sourceType:"module"});if(e.type==="Program"&&e.body.length===1){let r=e.body[0];if(r.type==="ExpressionStatement"){let n=r.expression;if(n.type==="ArrowFunctionExpression"||n.type==="FunctionExpression")return{isWrapped:!0,isAsync:n.async||!1,functionNode:n}}if(r.type==="FunctionDeclaration")return{isWrapped:!0,isAsync:r.async||!1,functionNode:r}}return{isWrapped:!1,isAsync:!1}}catch{return{isWrapped:!1,isAsync:!1}}}function E_(t){return t.async=!0,bs(t)}function S_(t){t=t.trim();let{isWrapped:e,isAsync:r,functionNode:n}=w_(t);return e&&n?r?t:E_(n):`async (context) => {\n${t}\n}`}function C_(t){Ne(t,null,{VariableDeclaration(e,r,n){e.declarations&&e.declarations.length>0&&e.declarations.forEach(i=>{if(i.init&&i.init.type==="ArrowFunctionExpression"&&i.init.start!==0){let s={type:"FunctionDeclaration",id:i.id,params:i.init.params,body:i.init.body.type==="BlockStatement"?i.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:i.init.body}]},async:i.init.async,generator:!1};Object.assign(e,s)}}),e.body&&e.body.body&&e.body.body.forEach(i=>n(i,r))}})}function N_(t,e){mt(t,{VariableDeclaration(n){for(let i of n.declarations)if(!(i.id?.type!=="Identifier"||!i.init)&&i.init.type==="CallExpression"&&i.init.callee?.type==="Identifier"&&i.init.callee.name==="Type"&&i.init.arguments?.length===1&&i.init.arguments[0]?.type==="ObjectExpression"){let s={};for(let a of i.init.arguments[0].properties)a.type!=="Property"||a.key?.type!=="Identifier"||(a.value?.type==="ArrayExpression"&&a.value.elements?.[0]?.type==="Literal"?s[a.key.name]=String(a.value.elements[0].value):a.value?.type==="Literal"&&(s[a.key.name]=String(a.value.value)));e.addUdtTypeName(i.id.name,s)}}});let r=!0;for(;r;)r=!1,mt(t,{FunctionDeclaration(n){if(!n.id?.name)return;let i=n.id.name;if(e.getFunctionReturnType(i)||e.getFunctionReturnTupleType(i))return;let s=k_(n.body);if(s.length===0)return;if(s.every(l=>l.type==="ArrayExpression")){let l=s[0].elements.length;if(l>0&&s.every(c=>c.elements.length===l)){let c=[],u=!0;for(let h=0;h<l;h++){let p=s.map(f=>Mr(f.elements[h],e)),d=p[0];if(!p.every(f=>f===d)){u=!1;break}c.push(d)}if(u&&c.some(h=>!!h)){e.setFunctionReturnTupleType(i,c),r=!0;return}}}let a=s.map(l=>Mr(l,e)),o=a[0];!o||!a.every(l=>l===o)||(e.setFunctionReturnType(i,o),r=!0)}});mt(t,{VariableDeclaration(n){for(let i of n.declarations)if(i.init){if(i.id?.type==="Identifier"){let s=Mr(i.init,e);s&&e.markVariableAsUdtInstance(i.id.name,s);continue}if(i.id?.type==="ArrayPattern"&&i.init.type==="CallExpression"&&i.init.callee?.type==="Identifier"){let s=e.getFunctionReturnTupleType(i.init.callee.name);if(!s)continue;i.id.elements?.forEach((a,o)=>{if(!a||a.type!=="Identifier")return;let l=s[o];l&&e.markVariableAsUdtInstance(a.name,l)})}}},ExpressionStatement(n){let i=n.expression;if(i?.type==="Literal"&&typeof i.value=="string"&&i.value.startsWith("__pineUdtVar:")){let s=i.value.match(/^__pineUdtVar:([A-Za-z_$][\\w$]*)=([A-Za-z_$][\\w$]*)$/);if(s){let[,a,o]=s;e.isUdtTypeName(o)&&e.markVariableAsUdtInstance(a,o)}}}}),mt(t,{ExpressionStatement(n){let i=n.expression;if(!i||i.type!=="AssignmentExpression"||i.operator!=="=")return;let s=i.left;if(s?.type!=="MemberExpression"||s.computed||s.property?.type!=="Identifier"||s.property.name!=="__pineParamTypes__"||s.object?.type!=="Identifier"||i.right?.type!=="ObjectExpression")return;let a=s.object.name,o=a.startsWith("$M_")?a.slice(3):a,l={};for(let c of i.right.properties){if(c.type!=="Property")continue;let u;if(c.key?.type==="Identifier"?u=c.key.name:c.key?.type==="Literal"&&typeof c.key.value=="string"&&(u=c.key.value),!u||c.value?.type!=="Literal"||typeof c.value.value!="string")continue;let h=c.value.value.split(/\\s+/).pop();e.isUdtTypeName(h)&&(l[u]=h)}Object.keys(l).length>0&&e.setFunctionParamUdtTypes(o,l)}})}function k_(t){let e=[];if(!t)return e;function r(n){if(!(!n||typeof n!="object")&&!(n.type==="FunctionDeclaration"||n.type==="FunctionExpression"||n.type==="ArrowFunctionExpression")){if(n.type==="ReturnStatement"&&n.argument){e.push(n.argument);return}for(let i of Object.keys(n)){if(i==="type")continue;let s=n[i];Array.isArray(s)?s.forEach(r):s&&typeof s=="object"&&s.type&&r(s)}}}return r(t),e}function Mr(t,e){if(t){if(t.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&!t.callee.computed&&t.callee.object?.type==="Identifier"&&t.callee.property?.type==="Identifier"&&(t.callee.property.name==="new"||t.callee.property.name==="copy")&&e.isUdtTypeName(t.callee.object.name))return t.callee.object.name;if(t.type==="CallExpression"&&t.callee?.type==="Identifier"){let r=e.getFunctionReturnType(t.callee.name);if(r)return r}if(t.type==="ConditionalExpression"){let r=Mr(t.consequent,e),n=Mr(t.alternate,e);if(r&&r===n)return r}}}function I_(t,e){mt(t,{VariableDeclaration(r){r.declarations.forEach(n=>{let i=n.init&&n.init.type==="MemberExpression"&&n.init.object&&(n.init.object.name==="context"||n.init.object.name===fe||n.init.object.name==="context2"),s=n.init&&n.init.type==="MemberExpression"&&n.init.object?.object&&(n.init.object.object.name==="context"||n.init.object.object.name===fe||n.init.object.object.name==="context2");(i||s)&&(n.id.name&&e.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(a=>{a.key.name&&e.addContextBoundVar(a.key.name)}))})}})}function A_(t,e,r=!1){t.params.forEach(n=>{n.type==="Identifier"&&r&&e.addContextBoundVar(n.name,r)})}function T_(t,e){let r;return Wo(t,{FunctionDeclaration(n){n.id&&n.id.name&&(e.addReservedName(n.id.name),e.addUserFunction(n.id.name),n.id.name.startsWith("$M_")||e.addRegularUserFunction(n.id.name))},ExpressionStatement(n){let i=n.expression;if(i&&i.type==="AssignmentExpression"&&i.operator==="="&&i.left?.type==="MemberExpression"&&i.left.property?.name==="__pineMethod__"&&i.left.object?.type==="Identifier"&&i.right?.value===!0){let s=i.left.object.name,a=s.startsWith("$M_")?s.slice(3):s;e.addUserMethod(a),e.addUserFunction(a)}},ArrowFunctionExpression(n){let i=n.start===0;i&&n.params&&n.params.length>0&&(r=n.params[0].name,n.params[0].name=fe),A_(n,e,i)},VariableDeclaration(n,i){let s=i.length>1?i[i.length-2]:null,a=s&&(s.type==="ForOfStatement"||s.type==="ForInStatement")&&s.left===n;n.declarations.forEach(o=>{if(o.id.type==="Identifier")e.addReservedName(o.id.name);else if(o.id.type==="ObjectPattern")o.id.properties.forEach(l=>{l.key&&l.key.type==="Identifier"&&e.addReservedName(l.key.name)});else if(o.id.type==="ArrayPattern"){if(o.id.elements?.forEach(p=>{p&&p.type==="Identifier"&&e.addReservedName(p.name)}),a)return;let l=e.generateTempVar(),c={type:"VariableDeclaration",kind:n.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:l},init:o.init}]},u=c.declarations[0].init;u&&u.type==="CallExpression"&&(u.callee.type==="ArrowFunctionExpression"||u.callee.type==="FunctionExpression")&&mt(u.callee.body,{ReturnStatement(p){p.argument&&p.argument.type==="ArrayExpression"&&(p.argument={type:"ArrayExpression",elements:[p.argument]})}}),o.id.elements?.forEach(p=>{p.type==="Identifier"&&e.addArrayPatternElement(p.name)});let h=o.id.elements.map((p,d)=>({type:"VariableDeclaration",kind:n.kind,declarations:[{type:"VariableDeclarator",id:p,init:{type:"MemberExpression",object:{type:"Identifier",name:l},property:{type:"Literal",value:d},computed:!0}}]}));Object.assign(n,{type:"BlockStatement",body:[c,...h]})}})},ForStatement(n){}}),r}var D_=Object.defineProperty,M_=(t,e,r)=>e in t?D_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,P_=(t,e,r)=>M_(t,typeof e!="symbol"?e+"":e,r),R_=new Set(["bar_index","last_bar_index","time","time_close","timenow","year","month","weekofyear","dayofmonth","dayofweek","hour","minute","second"]),F_=new Set(["input.int","math.floor","math.ceil","array.size","matrix.rows","matrix.columns","str.length","timestamp","ta.barssince","ta.highestbars","ta.lowestbars"]);function B_(t){return t&&t.type==="Literal"&&typeof t.value=="number"&&Number.isInteger(t.value)&&!(typeof t.raw=="string"&&/[.eE]/.test(t.raw))}function L_(t){return t?t.type==="Identifier"?t.name:t.type==="MemberExpression"&&!t.computed&&t.object?.type==="Identifier"&&t.property?.type==="Identifier"?`${t.object.name}.${t.property.name}`:null:null}var ji=class{constructor(){P_(this,"stack",[new Map])}push(){this.stack.push(new Map)}pop(){this.stack.length>1&&this.stack.pop()}set(e,r){this.stack[this.stack.length-1].set(e,r)}get(e){for(let r=this.stack.length-1;r>=0;r--){let n=this.stack[r].get(e);if(n!==void 0)return n}}assign(e,r){for(let n=this.stack.length-1;n>=0;n--)if(this.stack[n].has(e)){let i=this.stack[n].get(e);this.stack[n].set(e,i==="int"&&r==="int"?"int":"notint");return}this.stack[this.stack.length-1].set(e,r)}};function O_(t,e){let r=new ji;function n(s){if(!s||typeof s!="object")return"notint";switch(s.type){case"Literal":return typeof s.value=="number"&&B_(s)?"int":"notint";case"Identifier":return R_.has(s.name)?"int":r.get(s.name)??"notint";case"UnaryExpression":return s.operator==="-"||s.operator==="+"?n(s.argument):(n(s.argument),"notint");case"BinaryExpression":{let a=n(s.left),o=n(s.right),l=a==="int"&&o==="int";if(s.operator==="/"){if(l){let c=S.createMathIntDivCall(s.left,s.right);return Object.assign(s,c),"int"}return"notint"}return(s.operator==="+"||s.operator==="-"||s.operator==="*"||s.operator==="%")&&l?"int":"notint"}case"ConditionalExpression":{n(s.test);let a=n(s.consequent),o=n(s.alternate);return a==="int"&&o==="int"?"int":"notint"}case"LogicalExpression":return n(s.left),n(s.right),"notint";case"CallExpression":{s.callee?.type==="MemberExpression"&&n(s.callee.object);for(let o of s.arguments||[])n(o);let a=L_(s.callee);return a&&F_.has(a)?"int":"notint"}case"MemberExpression":return n(s.object),s.computed&&n(s.property),"notint";case"VariableDeclaration":{for(let a of s.declarations||[]){let o=a.init?n(a.init):"notint";a.id?.type==="Identifier"&&r.set(a.id.name,o)}return"notint"}case"AssignmentExpression":{let a=n(s.right);return s.left?.type==="Identifier"?r.assign(s.left.name,a):n(s.left),a}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":{r.push();for(let a of s.params||[]){let o=a.type==="AssignmentPattern"?a.left:a;o?.type==="Identifier"&&r.set(o.name,"notint")}return n(s.body),r.pop(),"notint"}default:return i(s),"notint"}}function i(s){for(let a in s){if(a==="type"||a==="start"||a==="end"||a==="loc"||a==="raw")continue;let o=s[a];if(Array.isArray(o))for(let l of o)l&&typeof l.type=="string"&&n(l);else o&&typeof o.type=="string"&&n(o)}}n(t)}var Cn={type:"Identifier",name:"undefined"};function Pr(t,e){let r={type:"Identifier",name:`\'${e}\'`};if(!t.isInsideFunctionScope())return r;let[n]=t.getVariable("$$");return n?{type:"BinaryExpression",operator:"+",left:S.createMemberExpression(S.createLocalContextIdentifier(),S.createIdentifier("id")),right:r}:r}function ke(t,e){let[r,n]=e.getVariable(t);if((r.match(/^fn\\d+_/)||e.isVariableInFunctionScope(t))&&t!=="$$"){let[i]=e.getVariable("$$");if(i)return S.createLocalContextVariableReference(n,r)}return S.createContextVariableReference(n,r)}function $i(t,e){let r=ke(t,e);return S.createGetCall(r,0)}function rr(t,e){if(t.computed&&t.property.type==="Identifier"){if(e.isLoopVariable(t.property.name)){if(t.object.type==="Identifier"&&!e.isLoopVariable(t.object.name)){if(e.isLocalSeriesVar(t.object.name)){let r=S.createIdentifier(t.object.name);r._skipTransformation=!0;let n=S.createGetCall(r,t.property);Object.assign(t,n),t._indexTransformed=!0;return}if(!e.isContextBound(t.object.name)){let r=ke(t.object.name,e),n=S.createGetCall(r,t.property);Object.assign(t,n),t._indexTransformed=!0}}return}if(!e.isContextBound(t.property.name))if(e.isLocalSeriesVar(t.property.name)){let r=S.createIdentifier(t.property.name);r._skipTransformation=!0,t.property=S.createGetCall(r,0)}else t.property=ke(t.property.name,e),t.property=S.createGetCall(t.property,0)}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(e.isLocalSeriesVar(t.object.name)){let r=S.createIdentifier(t.object.name);r._skipTransformation=!0;let n=S.createGetCall(r,t.property);Object.assign(t,n),t._indexTransformed=!0;return}if(e.isContextBound(t.object.name)||(t.object=ke(t.object.name,e)),t.property.type==="MemberExpression"){let r=t.property;r._indexTransformed||(rr(r,e),r._indexTransformed=!0)}}t.computed&&t.property.type!=="Identifier"&&t.property.type!=="MemberExpression"&&!t._indexTransformed&&(t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression")&&(t.property=Ct(t.property,e))}function Ve(t,e){let r=S.createGetCall(S.createIdentifier(t.name),0);t.start!==void 0&&(r.start=t.start),t.end!==void 0&&(r.end=t.end),r._indexTransformed=!0,Object.assign(t,r)}function Ce(t,e){if(!t._skipTransformation&&t.name!==fe){if(yt.includes(t.name)&&e.isContextBound(t.name)){let p=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,d=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&!t.parent.computed;if(!p&&!d){let f={type:"MemberExpression",object:{type:"Identifier",name:t.name},property:{type:"Identifier",name:"__value"},computed:!1},m=S.createGetCall(f,0);Object.assign(t,m),delete t.name;return}}if(t.name==="Math"||t.name==="NaN"||t.name==="undefined"||t.name==="Infinity"||t.name==="null"||t.name.startsWith("\'")&&t.name.endsWith("\'")||t.name.startsWith(\'"\')&&t.name.endsWith(\'"\')||t.name.startsWith("`")&&t.name.endsWith("`")||e.isLoopVariable(t.name))return;let r=!1;if(t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t)){let p=t.parent.callee;if(p.type==="MemberExpression"&&p.object&&p.object.name===fe&&["get","set","init","param","call"].includes(p.property.name)){let d=t.parent.arguments.indexOf(t);p.property.name==="call"?d>=2&&(r=!0):d===0&&(r=!0)}else{let d=p.type==="MemberExpression"&&p.object&&p.object.type==="Identifier"&&$t.includes(p.object.name);p.type==="MemberExpression"&&!d?r=!1:r=!0}}let n=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&e.isContextBound(t.name),i=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.property.name==="param";t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left;let s=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,a=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.object===t,o=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.property===t&&t.parent.parent&&t.parent.parent.type==="CallExpression"&&t.parent.parent.callee&&t.parent.parent.callee.type==="MemberExpression"&&e.isContextBound(t.parent.parent.callee.object.name);if(n||i||r||o||s){if(s||t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.object&&t.parent.callee.object.name===fe&&t.parent.callee.property.name==="call"&&t.parent.arguments[0]===t||e.isLocalSeriesVar(t.name)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;let p=ke(t.name,e);Object.assign(t,p);return}let l=e.isContextBound(t.name)&&!e.isRootParam(t.name);if(l){let p=t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t),d=t.parent&&t.parent.type==="SwitchStatement"&&t.parent.discriminant===t,f=t.parent&&t.parent.type==="SwitchCase"&&t.parent.test===t;if(!p&&!d&&!f)return}if(e.isLocalSeriesVar(t.name)){if(!a){let p=S.createIdentifier(t.name),d=S.createGetCall(p,0);Object.assign(t,d)}return}let[c,u]=e.getVariable(t.name),h;if(l)h=S.createIdentifier(t.name);else{if(c===t.name&&!e.isContextBound(t.name))return;h=ke(t.name,e)}if(a)Object.assign(t,h);else{let p=S.createGetCall(h,0);Object.assign(t,p)}}}function ge(t,e,r){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;if(t.computed&&t.object&&t.object.type==="CallExpression"&&!t._historyTransformed){t.object._transformed||ve(t.object,r);let l=r.generateParamId(),c={type:"CallExpression",callee:S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("param")),arguments:[t.object,Cn,Pr(r,l)],_transformed:!0,_isParamCall:!0},u=S.createGetCall(c,t.property);u._transformed=!0,u._historyTransformed=!0,Object.assign(t,u),delete t.object,delete t.property,delete t.computed;return}if(t.object&&t.object.type==="Identifier"&&$t.includes(t.object.name)&&r.isContextBound(t.object.name)&&!t.computed){let l=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,c=t.parent&&(t.parent.type==="VariableDeclarator"&&(t.parent.id.type==="ArrayPattern"||t.parent.id.type==="ObjectPattern")||t.parent.type==="AssignmentExpression"&&(t.parent.left.type==="ArrayPattern"||t.parent.left.type==="ObjectPattern")||t.parent.type==="Property");if(!l&&!c){let u={type:"CallExpression",callee:{type:"MemberExpression",object:t.object,property:t.property,computed:!1},arguments:[],_transformed:!1};t.start!==void 0&&(u.start=t.start),t.end!==void 0&&(u.end=t.end),Object.assign(t,u);return}}if(!t.computed&&t.object&&t.object.type==="Identifier"&&r.isLocalSeriesVar(t.object.name)){let l=S.createIdentifier(t.object.name);l._skipTransformation=!0,t.object=S.createGetCall(l,0);return}let n=r.getCurrentScopeType()=="if",i=r.getCurrentScopeType()=="els",s=r.getCurrentScopeType()=="for";if(!n&&!i&&!s&&t.object&&t.object.type==="Identifier"&&r.isContextBound(t.object.name)&&!r.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(rr(t,r),t._indexTransformed=!0);let a=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&(t.object.object.object.name===fe||t.object.object.object.name==="$$"),o=t.object&&t.object.type==="Identifier"&&r.isContextBound(t.object.name);if(t.computed&&(a||o)){if(t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left===t)return;t.object.type==="Identifier"&&yt.includes(t.object.name)&&r.isContextBound(t.object.name)&&(t.object={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1});let l=S.createGetCall(t.object,t.property);t.start&&(l.start=t.start),t.end&&(l.end=t.end),Object.assign(t,l),delete t.object,delete t.property,delete t.computed;return}if(t.computed&&t.object&&t.object.type==="MemberExpression"){let l=t.object;for(;l.object&&l.object.type==="MemberExpression";)l=l.object;if(l.object&&l.object.type==="Identifier"&&r.isUdtInstance(l.object.name)){let c=l.object.name,u=r.isLocalSeriesVar(c)?(()=>{let p=S.createIdentifier(c);return p._skipTransformation=!0,p})():ke(c,r);l.object=S.createGetCall(u,t.property);let h=t.object;Object.assign(t,h),delete t.computed;return}}}function Rr(t,e){if(t.type==="Identifier"){if(yt.includes(t.name)&&e.isContextBound(t.name)){let s=t.name;return Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:s},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name,t}if(e.isLoopVariable(t.name))return t;if(e.isRootParam(t.name)){let[s,a]=e.getVariable(t.name);return S.createContextVariableReference(a,s)}if(e.isContextBound(t.name))return t;let[r,n]=e.getVariable(t.name),i=r!==t.name;return e.isLocalSeriesVar(t.name)&&!i?t:i?ke(t.name,e):r===t.name&&!e.isContextBound(t.name)?t:ke(t.name,e)}return t}function Ct(t,e,r=""){switch(t.type){case"BinaryExpression":return sn(t,e,r);case"LogicalExpression":return an(t,e,r);case"MemberExpression":{let n=!t.computed&&t.object.type==="Identifier"&&yt.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&yt.includes(t.object.name)&&e.isContextBound(t.object.name)){let a={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1};return S.createGetCall(a,t.property)}let i=t.object.type==="Identifier"&&!n?Rr(t.object,e):t.object,s=i;if(!t.computed&&t.object.type==="Identifier"&&!n){let[a]=e.getVariable(t.object.name);a!==t.object.name&&!e.isLoopVariable(t.object.name)&&(s=S.createGetCall(i,0))}return{type:"MemberExpression",object:s,property:t.property,computed:t.computed}}case"Identifier":{if(e.isLoopVariable(t.name)||t.parent&&t.parent.type==="MemberExpression"&&t.parent.property===t)return t;let n=Rr(t,e);return n.type==="Identifier"&&(n.name==="NaN"||n.name==="undefined"||n.name==="Infinity"||n.name==="null"||n.name==="Math")?n:S.createGetCall(n,0)}case"UnaryExpression":return on(t,e,r);case"ConditionalExpression":{let n=Ct(t.test,e,r),i=Ct(t.consequent,e,r),s=Ct(t.alternate,e,r);return{type:"ConditionalExpression",test:n,consequent:i,alternate:s,start:t.start,end:t.end}}}return t}function sn(t,e,r){let n=Ct(t.left,e,r),i=Ct(t.right,e,r),s={type:"BinaryExpression",operator:t.operator,left:n,right:i,start:t.start,end:t.end};return Ne(s,e,{CallExpression(a,o){a._transformed||ve(a,o)},MemberExpression(a){ge(a,"",e)}}),s}function an(t,e,r){let n=Ct(t.left,e,r),i=Ct(t.right,e,r),s={type:"LogicalExpression",operator:t.operator,left:n,right:i,start:t.start,end:t.end};return Ne(s,e,{CallExpression(a,o){a._transformed||ve(a,o)}}),s}function li(t,e,r){Ne(t,{parent:t,inNamespaceCall:!1},{Identifier(a,o,l){if(a.name=="NaN")return;if(yt.includes(a.name)&&e.isContextBound(a.name)){if(o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===a&&!o.parent.computed)return;let u={type:"MemberExpression",object:{type:"Identifier",name:a.name},property:{type:"Identifier",name:"__value"},computed:!1},h=S.createGetCall(u,0);Object.assign(a,h),delete a.name;return}a.parent=o.parent,Ce(a,e);let c=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||c)&&(a.type==="MemberExpression"?rr(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===fe&&a.parent.callee.property.name==="get"||Ve(a)))},MemberExpression(a,o,l){ge(a,"",e),a.object&&l(a.object,{parent:a,inNamespaceCall:o.inNamespaceCall})},ConditionalExpression(a,o,l){let c={...o,parent:a};a.test&&l(a.test,c),a.consequent&&l(a.consequent,c),a.alternate&&l(a.alternate,c)},BinaryExpression(a,o,l){let c={...o,parent:a};l(a.left,c),l(a.right,c)},LogicalExpression(a,o,l){let c={...o,parent:a};l(a.left,c),l(a.right,c)},UnaryExpression(a,o,l){let c={...o,parent:a};l(a.argument,c)},CallExpression(a,o,l){let c=a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&a.callee.object.type==="Identifier"&&e.isContextBound(a.callee.object.name);ve(a,e),a.arguments.forEach(u=>l(u,{parent:a,inNamespaceCall:c||o.inNamespaceCall}))}});let n=S.createMemberExpression(S.createIdentifier(r),S.createIdentifier("param")),i=e.generateParamId(),s={type:"CallExpression",callee:n,arguments:[t,Cn,Pr(e,i)],_transformed:!0,_isParamCall:!0};if(!e.shouldSuppressHoisting()){let a=i;e.addLocalSeriesVar(a);let o=S.createVariableDeclaration(a,s);return e.addHoistedStatement(o),S.createIdentifier(a)}return s}function on(t,e,r){let n=Ct(t.argument,e,r),i={type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:n,start:t.start,end:t.end};return Ne(i,e,{CallExpression(s,a){s._transformed||ve(s,a)},MemberExpression(s){ge(s,"",e)}}),i}function Ht(t,e,r){switch(t?.type){case"BinaryExpression":t=sn(t,r,e);break;case"LogicalExpression":t=an(t,r,e);break;case"ConditionalExpression":return li(t,r,e);case"UnaryExpression":t=on(t,r,e);break;case"ArrayExpression":t.elements=t.elements.map(c=>{if(c.type==="Identifier"){if(r.isContextBound(c.name)&&!r.isRootParam(c.name))return c;if(r.isLocalSeriesVar(c.name)){let u=S.createIdentifier(c.name);return S.createGetCall(u,0)}return $i(c.name,r)}return c.type==="CallExpression"?(ve(c,r),c):c.type==="BinaryExpression"?sn(c,r,e):c.type==="LogicalExpression"?an(c,r,e):c.type==="ConditionalExpression"?li(c,r,e):c.type==="UnaryExpression"?on(c,r,e):(c.type==="MemberExpression"&&ge(c,e,r),c)});break}let n=t.type==="MemberExpression"&&t.computed&&t.property,i=t.type==="MemberExpression"&&!t.computed;if(n){if(t.object&&t.object.type==="MemberExpression"){let f=t.object;for(;f.object&&f.object.type==="MemberExpression";)f=f.object;if(f.object?.type==="Identifier"&&r.isUdtInstance(f.object.name)){let m=f.object.name,x=r.isLocalSeriesVar(m)?(()=>{let b=S.createIdentifier(m);return b._skipTransformation=!0,b})():ke(m,r);return f.object=S.createGetCall(x,t.property),t.object}}if(t.object.type==="CallExpression")ve(t.object,r);else if(t.object.type==="MemberExpression"){ge(t.object,"",r);let f=t.object;for(;f&&f.type==="MemberExpression"&&f.object;){if(f.object.type==="Identifier"){let m=f.object,[x]=r.getVariable(m.name);x!==m.name&&!r.isContextBound(m.name)&&!r.isRootParam(m.name)&&!r.isLoopVariable(m.name)&&!r.isLocalSeriesVar(m.name)&&!yt.includes(m.name)&&!$t.includes(m.name)&&(f.object=$i(m.name,r));break}f=f.object}}else t.object.type==="BinaryExpression"?t.object=sn(t.object,r,e):t.object.type==="LogicalExpression"?t.object=an(t.object,r,e):t.object.type==="ConditionalExpression"?t.object=li(t.object,r,e):t.object.type==="UnaryExpression"&&(t.object=on(t.object,r,e));let c=t.object.type==="Identifier"&&r.isContextBound(t.object.name)&&!r.isRootParam(t.object.name)?t.object:Rr(t.object,r),u;t.property.type==="Identifier"&&!r.isContextBound(t.property.name)&&!r.isLoopVariable(t.property.name)?u=S.createGetCall(Rr(t.property,r),0):t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression"?u=Ct(t.property,r,e):u=t.property;let h=S.createMemberExpression(S.createIdentifier(e),S.createIdentifier("param")),p=r.generateParamId(),d={type:"CallExpression",callee:h,arguments:[c,u,Pr(r,p)],_transformed:!0,_isParamCall:!0};if(!r.shouldSuppressHoisting()){let f=p;r.addLocalSeriesVar(f);let m=S.createVariableDeclaration(f,d);return r.addHoistedStatement(m),S.createIdentifier(f)}return d}if(i){if(t.object.type==="Identifier"&&$t.includes(t.object.name)&&r.isContextBound(t.object.name)&&!t.computed){let c=t.object.name,u={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:t.property.name},computed:!1},arguments:[],_transformed:!0};c==="ta"&&u.arguments.push(r.getNextTACallId());let h=r.generateTempVar();r.addLocalSeriesVar(h);let p=S.createVariableDeclaration(h,u);return r.addOuterHoistedStatement(p),Object.assign(t,S.createIdentifier(h)),t}if(t.object.type==="Identifier"){let c=t.object.name,[u,h]=r.getVariable(c);if(u!==c&&!r.isLoopVariable(c)){let p=ke(c,r),d=S.createGetCall(p,0);t.object=d}else if(r.isLocalSeriesVar(c)){let p=S.createIdentifier(c);p._skipTransformation=!0,t.object=S.createGetCall(p,0)}}else t.object.type==="MemberExpression"?Ht(t.object,e,r):t.object.type==="CallExpression"&&(t.object._transformed||ve(t.object,r))}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(c=>c.value.name?r.isContextBound(c.value.name)||r.isLocalSeriesVar(c.value.name)||r.isLoopVariable(c.value.name)?{type:"Property",key:{type:"Identifier",name:c.key.name},value:S.createIdentifier(c.value.name),kind:"init",method:!1,shorthand:!1,computed:!1}:{type:"Property",key:{type:"Identifier",name:c.key.name},value:ke(c.value.name,r),kind:"init",method:!1,shorthand:!1,computed:!1}:(c.value.type!=="Literal"&&(c.value=Ht(c.value,e,r)),c))),t.type==="Identifier"){if(yt.includes(t.name)&&r.isContextBound(t.name)){let c=t.name;Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name}else if(r.isContextBound(t.name)&&!r.isRootParam(t.name)){let c=S.createMemberExpression(S.createIdentifier(e),S.createIdentifier("param")),u=r.generateParamId(),h={type:"CallExpression",callee:c,arguments:[t,Cn,Pr(r,u)],_transformed:!0,_isParamCall:!0};if(!r.shouldSuppressHoisting()){let p=u;r.addLocalSeriesVar(p);let d=S.createVariableDeclaration(p,h);return r.addHoistedStatement(d),S.createIdentifier(p)}return h}}t?.type==="CallExpression"&&ve(t,r);let s=S.createMemberExpression(S.createIdentifier(e),S.createIdentifier("param")),a=t.type==="Identifier"?Rr(t,r):t,o=r.generateParamId(),l={type:"CallExpression",callee:s,arguments:[a,Cn,Pr(r,o)],_transformed:!0,_isParamCall:!0};if(!r.shouldSuppressHoisting()){let c=o;r.addLocalSeriesVar(c);let u=S.createVariableDeclaration(c,l);return r.addHoistedStatement(u),S.createIdentifier(c)}return l}function Sr(t){if(!t)return!1;if(zo(t))return!0;if(t.type==="MemberExpression")return Sr(t.object);if(t.type==="ChainExpression")return Sr(t.expression);if(t.type==="CallExpression"){let e=t.callee;if(e?.type==="MemberExpression")return Sr(e.object);if(e?.type==="ChainExpression")return Sr(e.expression)}return!1}function zo(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function Wi(t,e,r){t&&(t.type==="Identifier"?(t.parent=e,Ce(t,r)):t.type==="MemberExpression"?Wi(t.object,t,r):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&Wi(t.callee.object,t.callee,r),t._transformed||ve(t,r)))}function ve(t,e,r){if(t._transformed)return;t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&($t.includes(t.callee.name)||yt.includes(t.callee.name))&&e.isContextBound(t.callee.name)&&(t.callee=S.createMemberExpression(t.callee,S.createIdentifier("any")));let n=t.callee&&t.callee.type==="MemberExpression"&&t.callee.object&&t.callee.object.type==="Identifier"&&(e.isContextBound(t.callee.object.name)||t.callee.object.name==="math"||t.callee.object.name==="ta");if(n){if(t.callee.object.name===fe&&["get","init","param"].includes(t.callee.property.name))return;let i=t.callee.object.name,s=[];t.arguments.forEach(p=>{if(p._isParamCall){s.push(p);return}s.push(Ht(p,i,e))}),t.arguments=s;let a=t.callee.property.name,o=`${i}.${a}`;if(pa.includes(i)||pa.includes(o)){let p=e.getNextPlotCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:p,kind:"init",computed:!1,shorthand:!1}]})}if(i==="input"&&t._varId!==void 0&&t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__varId"},value:{type:"Literal",value:t._varId},kind:"init",computed:!1,shorthand:!1}]}),i==="alert"){let p=e.getNextAlertCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:p,kind:"init",computed:!1,shorthand:!1}]})}if(i==="ta")if(e.getCurrentScopeType()==="fn"){let p=e.getNextTACallId(),[d]=e.getVariable("$$"),f;d?f=S.createMemberExpression(S.createLocalContextIdentifier(),S.createIdentifier("id")):f=S.createLiteral("");let m={type:"BinaryExpression",operator:"+",left:f,right:p};t.arguments.push(m)}else t.arguments.push(e.getNextTACallId());let l=t.callee.property.name,c=`${i}.${l}`,u=m_.includes(c),h=t._insideAwait===!0;if(u&&!h){let p=Object.assign({},t),d=S.createAwaitExpression(p);Object.assign(t,d)}if(!e.shouldSuppressHoisting()){let p=e.generateTempVar();e.addLocalSeriesVar(p);let d=t._insideAwait===!0,f=Object.assign({},t);d&&(f=S.createAwaitExpression(f));let m=S.createVariableDeclaration(p,f);e.addHoistedStatement(m);let x=S.createIdentifier(p);Object.assign(t,x),t._wasHoisted=!0,t._wasInsideAwait=d;return}t._transformed=!0}else if(t.callee&&t.callee.type==="Identifier"){if(t.arguments=t.arguments.map(i=>i._isParamCall?i:Ht(i,fe,e)),!e.isContextBound(t.callee.name)){let i=e.getNextUserCallId(),s=S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("call")),a=t.callee.name,o=t.callee;e.isUserMethod(a)&&!e.isRegularUserFunction(a)&&(o=S.createIdentifier(`$M_${a}`),o._skipTransformation=!0);let l=[o,i,...t.arguments];t.callee=s,t.arguments=l}t._transformed=!0}if(!n&&t.callee&&t.callee.type==="MemberExpression"){let i=t.callee.property.name,s=e.isUserFunction(i),a=t.callee.object,o=a.type==="Identifier"&&e.isLocalSeriesVar(a.name),l=a.type==="MemberExpression",c=e.isUserMethod(i),u=!!a.name&&e.isUdtInstance(a.name);if(s&&c&&!e.isContextBound(i)&&!o&&!l&&u){let h=t.callee.object;t.callee.property;let p=t.arguments.map(w=>w._isParamCall?w:Ht(w,fe,e)),d=h;h.type==="Identifier"?d=Ht(h,fe,e):h.type==="CallExpression"&&(ve(h,e),d=Ht(h,fe,e));let f=S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("call")),m=e.getNextUserCallId(),x=S.createIdentifier(`$M_${i}`);x._skipTransformation=!0;let b=[x,m,d,...p];t.callee=f,t.arguments=b,t._transformed=!0;return}t.callee.object.type==="Identifier"?Ce(t.callee.object,e):Wi(t.callee.object,t.callee,e)}if(t.arguments.forEach(i=>{Ne(i,{parent:t},{Identifier(s,a,o){s.parent=a.parent,Ce(s,e);let l=s.parent&&s.parent.type==="BinaryExpression";(s.parent&&s.parent.type==="ConditionalExpression"||l)&&(s.type==="MemberExpression"?rr(s,e):s.type==="Identifier"&&(s.parent&&s.parent.type==="CallExpression"&&s.parent.callee&&s.parent.callee.object&&s.parent.callee.object.name===fe&&s.parent.callee.property.name==="get"||Ve(s)))},BinaryExpression(s,a,o){let l={...a,parent:s};o(s.left,l),o(s.right,l)},LogicalExpression(s,a,o){let l={...a,parent:s};o(s.left,l),o(s.right,l)},UnaryExpression(s,a,o){let l={...a,parent:s};o(s.argument,l)},CallExpression(s,a,o){s.callee&&s.callee.type==="MemberExpression"&&s.callee.object&&(s.callee.object.parent=s.callee,o(s.callee.object,{parent:s.callee})),s._transformed||ve(s,e)},MemberExpression(s,a,o){ge(s,"",e),s.object&&o(s.object,{parent:s})}})}),t.callee&&t.callee.type==="MemberExpression"){let i=t.callee.object,s=zo(i),a=i?.type==="MemberExpression"&&Sr(i);if(s||a){let o=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:o},t.optional=!0}}}function Es(t){let e={type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:t},init:{type:"Literal",value:0}}]},r={type:"IfStatement",test:{type:"BinaryExpression",operator:">",_skipCompare:!0,left:{type:"UpdateExpression",operator:"++",prefix:!0,argument:{type:"Identifier",name:t}},right:{type:"Identifier",name:"__maxLoops"}},consequent:{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[{type:"Literal",value:`Loop exceeded maximum iterations (${t})`}]}},alternate:null};return{counterDecl:e,guardCheck:r}}function Nn(t,e){let r=null;if(t.left.type==="Identifier")r=ke(t.left.name,e);else if(t.left.type==="MemberExpression"&&t.left.computed){if(t.left.object.type==="Identifier"){let n=t.left.object.name,[i,s]=e.getVariable(n),a=i!==n,o=e.isContextBound(n);(a||o)&&!e.isLoopVariable(n)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(r=ke(n,e))}}else if(t.left.type==="MemberExpression"&&!t.left.computed){let n=null,i=t.left;for(;i.type==="MemberExpression"&&!i.computed;){if(i.object.type==="Identifier"){n=i;break}i=i.object}if(n){let s=n.object.name,[a,o]=e.getVariable(s);if(a!==s&&!e.isLoopVariable(s)){let l=ke(s,e),c=S.createGetCall(l,0);n.object=c}else if(e.isLocalSeriesVar(s)){let l=S.createIdentifier(s);l._skipTransformation=!0,n.object=S.createGetCall(l,0)}}}if(Ne(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(n,i,s){let a=i.parent&&i.parent.type==="MemberExpression"&&!i.parent.computed&&i.parent.object===n;if(yt.includes(n.name)&&e.isContextBound(n.name)&&!a){let m={type:"MemberExpression",object:{type:"Identifier",name:n.name},property:{type:"Identifier",name:"__value"},computed:!1},x=S.createGetCall(m,0);Object.assign(n,x),delete n.name;return}n.parent=i.parent,Ce(n,e);let o=n.parent&&n.parent.type==="BinaryExpression",l=n.parent&&n.parent.type==="ConditionalExpression",c=e.isContextBound(n.name)&&!e.isRootParam(n.name),u=n.parent&&n.parent.type==="MemberExpression"&&n.parent.computed&&n.parent.object===n,h=n.parent&&n.parent._isParamCall,p=n.parent&&n.parent.type==="MemberExpression",d=n.name==="NaN",f=n.parent&&n.parent.type==="CallExpression"&&n.parent.callee&&n.parent.callee.object&&n.parent.callee.object.name===fe&&n.parent.callee.property.name==="get";(c||l||o)&&(n.type==="MemberExpression"?rr(n,e):n.type==="Identifier"&&!p&&!u&&!h&&!d&&!f&&Ve(n))},MemberExpression(n,i,s){ge(n,"",e),n.type==="CallExpression"?n.arguments.forEach(a=>s(a,{parent:n,inNamespaceCall:i.inNamespaceCall})):n.object&&s(n.object,{parent:n,inNamespaceCall:i.inNamespaceCall})},CallExpression(n,i,s){let a=n.callee&&n.callee.type==="MemberExpression"&&n.callee.object&&n.callee.object.type==="Identifier"&&e.isContextBound(n.callee.object.name);ve(n,e),n.type==="CallExpression"&&(n.callee.type==="MemberExpression"&&s(n.callee,{parent:n,inNamespaceCall:a||i.inNamespaceCall}),n.arguments.forEach(o=>s(o,{parent:n,inNamespaceCall:a||i.inNamespaceCall})))}}),r){let n=t.right;if(t.operator!=="="){let s=t.operator.replace("=",""),a=S.createGetCall(r,0);n={type:"BinaryExpression",operator:s,left:a,right:t.right,start:t.start,end:t.end}}let i=S.createSetCall(r,n);t.start&&(i.start=t.start),t.end&&(i.end=t.end),Object.assign(t,i)}}function Ko(t,e){t._skipTransformation||t.declarations.forEach(r=>{if(r.init?.type==="CallExpression"&&r.id?.type==="Identifier"){let p=r.init.callee;(p?.type==="MemberExpression"&&p.object?.type==="Identifier"&&p.object.name==="input"||p?.type==="Identifier"&&p.name==="input")&&(r.init._varId=r.id.name)}if(r.init&&r.init.type==="Identifier"&&yt.includes(r.init.name)&&e.isContextBound(r.init.name)){let p=r.init.name;Object.assign(r.init,{type:"MemberExpression",object:{type:"Identifier",name:p},property:{type:"Identifier",name:"__value"},computed:!1}),delete r.init.name}let n=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===fe||r.init.object.name==="context2"),i=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===fe||r.init.object.object.name==="context2"),s=r.init&&r.init.type==="ArrowFunctionExpression";if(n){r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),r.init.object.name=fe;return}if(i){r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),r.init.object.object.name=fe;return}e.addVariable(r.id.name,t.kind);let a=t.kind,o=e.isArrayPatternElement(r.id.name)&&r.init&&r.init.type==="MemberExpression"&&r.init.computed;r.init&&!s&&!o&&(r.init.type==="CallExpression"&&r.init.callee.type==="MemberExpression"&&r.init.callee.object&&r.init.callee.object.type==="Identifier"&&e.isContextBound(r.init.callee.object.name)?ve(r.init,e):Ne(r.init,{parent:r.init},{Identifier(p,d){p.parent=d.parent,Ce(p,e);let f=p.parent&&p.parent.type==="BinaryExpression",m=p.parent&&p.parent.type==="UnaryExpression",x=p.parent&&p.parent.type==="ConditionalExpression",b=p.parent&&p.parent.type==="CallExpression"&&p.parent.callee&&p.parent.callee.object&&p.parent.callee.object.name===fe&&p.parent.callee.property.name==="get";p.type==="Identifier"&&(f||m||x)&&!b&&Ve(p)},CallExpression(p,d,f){p.callee.type==="Identifier"&&(p.callee.parent=p),p.arguments.forEach(m=>{m.type==="Identifier"&&(m.parent=p)}),(p.callee.type==="ArrowFunctionExpression"||p.callee.type==="FunctionExpression")&&f(p.callee,{parent:p}),ve(p,e),p.type==="CallExpression"&&(p.callee.type==="MemberExpression"&&f(p.callee,{parent:p}),p.arguments.forEach(m=>f(m,{parent:p})))},BinaryExpression(p,d,f){p.left.type==="Identifier"&&(p.left.parent=p),p.right.type==="Identifier"&&(p.right.parent=p),f(p.left,{parent:p}),f(p.right,{parent:p})},LogicalExpression(p,d,f){p.left.type==="Identifier"&&(p.left.parent=p),p.right.type==="Identifier"&&(p.right.parent=p),f(p.left,{parent:p}),f(p.right,{parent:p})},UnaryExpression(p,d,f){p.argument.type==="Identifier"&&(p.argument.parent=p),f(p.argument,{parent:p})},MemberExpression(p,d,f){p.object&&p.object.type==="Identifier"&&(p.object.parent=p),p.property&&p.property.type==="Identifier"&&(p.property.parent=p),ge(p,"",e),p.type==="CallExpression"?p.arguments.forEach(m=>f(m,{parent:p})):p.object&&f(p.object,{parent:p})},AwaitExpression(p,d,f){p.argument&&(p.argument._insideAwait=!0,f(p.argument,{parent:p}),p.argument.type==="Identifier"&&p.argument._wasInsideAwait&&Object.assign(p,p.argument))},ArrowFunctionExpression(p,d,f){if(p.body)if(p.body.type==="BlockStatement"){let m=[];p.body.body.forEach(x=>{e.enterHoistingScope(),f(x,{parent:p.body,insideIIFE:!0});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),p.body.body=m}else f(p.body,{parent:p,insideIIFE:!0})},FunctionExpression(p,d,f){if(p.body&&p.body.type==="BlockStatement"){let m=[];p.body.body.forEach(x=>{e.enterHoistingScope(),f(x,{parent:p.body,insideIIFE:!0});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),p.body.body=m}},SwitchStatement(p,d,f){p.discriminant&&(p.discriminant.parent=p,f(p.discriminant,{parent:p})),p.cases&&p.cases.forEach(m=>{m.parent=p,f(m,{parent:p})})},SwitchCase(p,d,f){if(p.test&&(p.test.parent=p,f(p.test,{parent:p})),p.consequent){let m=[];p.consequent.forEach(x=>{e.enterHoistingScope(),x.parent=p,f(x,{parent:p});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),p.consequent=m}},AssignmentExpression(p,d,f){if(d.insideIIFE){if(p.left.type==="Identifier"){let[m]=e.getVariable(p.left.name);if(m===p.left.name&&!e.isContextBound(p.left.name)){f(p.right,{parent:p});return}}Nn(p,e)}}}));let l=ke(r.id.name,e),c=!o&&r.init&&r.init.type==="MemberExpression"&&r.init.computed&&r.init.property&&(r.init.property.type==="Literal"||r.init.property.type==="MemberExpression");if(r.init?.property?.type==="MemberExpression"&&(r.init.property._indexTransformed||(rr(r.init.property,e),r.init.property._indexTransformed=!0)),a==="var"){let p=e.getCurrentHoistingScope();if(p){for(let d of p)if(d.type==="VariableDeclaration")for(let f of d.declarations){if(!f.init||f.init.type!=="CallExpression")continue;let m=f.init.callee;if(m?.type!=="MemberExpression")continue;let x,b=m.property?.name;if(m.object?.type==="Identifier"?x=m.object.name:m.object?.type==="MemberExpression"&&m.object.property?.name&&(x=m.object.property.name),x&&b){let w=`${x}.${b}`;g_.includes(w)&&(f.init={type:"ArrowFunctionExpression",params:[],body:f.init,expression:!0,async:!1})}}}}let u;r.init?s||o?u=r.init:a==="var"?u=S.createInitVarCall(l,r.init):u=S.createInitCall(l,c?r.init.object:r.init,c?r.init.property:void 0):u=S.createIdentifier("undefined");let h=S.createExpressionStatement(S.createAssignmentExpression(l,u));if(o){let p=r.init.object.name,d=ke(p,e),f=r.init.property.value,m={type:"MemberExpression",object:S.createGetCall(d,0),property:{type:"Literal",value:f},computed:!0};h.expression.right=S.createCallExpression(S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("init")),[l,m])}s&&(e.pushScope("fn"),Ne(r.init.body,e,{IfStatement(p,d,f){d.pushScope("if"),p.test&&Ho(p.test,d),f(p.consequent,d),p.alternate&&(d.pushScope("els"),f(p.alternate,d),d.popScope()),d.popScope()},VariableDeclaration(p,d){Ko(p,d)},Identifier(p,d){Ce(p,d)},AssignmentExpression(p,d){Nn(p,d)},SwitchStatement(p,d,f){p.discriminant.parent=p,f(p.discriminant,d),p.cases.forEach(m=>{m.parent=p,f(m,d)})},SwitchCase(p,d,f){p.test&&(p.test.parent=p,f(p.test,d));let m=[];p.consequent.forEach(x=>{d.enterHoistingScope(),f(x,d);let b=d.exitHoistingScope();m.push(...b),m.push(x)}),p.consequent=m},BlockStatement(p,d,f){let m=[];p.body.forEach(x=>{d.enterHoistingScope(),f(x,d);let b=d.exitHoistingScope();m.push(...b),m.push(x)}),p.body=m}}),e.popScope()),Object.assign(t,h)})}function V_(t,e,r){if(e.setSuppressHoisting(!0),t.init&&t.init.type==="VariableDeclaration"){let s=t.init.declarations[0],a=s.id.name;e.addLoopVariable(a,a),t.init={type:"VariableDeclaration",kind:t.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:s.init}]},s.init&&Ne(s.init,e,{Identifier(o,l){!e.isLoopVariable(o.name)&&!o.computed&&(e.pushScope("for"),Ce(o,l),o.type==="Identifier"&&(e.isContextBound(o.name)&&o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===o||(o.computed=!0,Ve(o))),e.popScope())},MemberExpression(o,l,c){e.pushScope("for"),ge(o,"",e),e.popScope(),o.type==="MemberExpression"&&o.object&&(o.object.type!=="Identifier"||!e.isContextBound(o.object.name))&&c(o.object,l)},CallExpression(o,l,c){o.callee.parent=o,c(o.callee,l);for(let u of o.arguments)c(u,l)}})}t.test&&Ne(t.test,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),Ce(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,Ve(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),ge(s,"",e),e.popScope(),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){s.callee.parent=s,o(s.callee,a);for(let l of s.arguments)o(l,a)}}),t.update&&Ne(t.update,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),Ce(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,Ve(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),ge(s,"",e),e.popScope(),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){s.callee.parent=s,o(s.callee,a);for(let l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);let n=e.getNextLoopGuardName(),i=Es(n);if(e.addHoistedStatement(i.counterDecl),e.pushScope("for"),r(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(i.guardCheck),t.init&&t.init.type==="VariableDeclaration"){let s=t.init.declarations[0];e.removeLoopVariable(s.id.name)}}function j_(t,e,r){e.setSuppressHoisting(!0),t.test&&Ne(t.test,e,{Identifier(s,a){s.computed||(Ce(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,Ve(s))))},MemberExpression(s,a,o){ge(s,"",e),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){if(s.callee.parent=s,o(s.callee,a),ve(s,a),s.arguments)for(let l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);let n=e.getNextLoopGuardName(),i=Es(n);e.addHoistedStatement(i.counterDecl),e.pushScope("whl"),r(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(i.guardCheck)}function Ho(t,e){Ne(t,e,{MemberExpression(r,n,i){r.object&&r.object.type==="Identifier"&&!e.isContextBound(r.object.name)&&!r.computed&&(r.object.parent=r,i(r.object,n)),ge(r,"",e)},CallExpression(r,n){ve(r,n)},BinaryExpression(r,n,i){r.left.type==="Identifier"&&(r.left.parent=r),r.right.type==="Identifier"&&(r.right.parent=r),i(r.left,n),i(r.right,n)},LogicalExpression(r,n,i){r.left.type==="Identifier"&&(r.left.parent=r),r.right.type==="Identifier"&&(r.right.parent=r),i(r.left,n),i(r.right,n)},UnaryExpression(r,n,i){r.argument.type==="Identifier"&&(r.argument.parent=r),i(r.argument,n)},Identifier(r,n){let i=r.parent,s=i&&i.type==="UnaryExpression",a=i&&i.type==="BinaryExpression",o=i&&i.type==="LogicalExpression",l=i&&i.type==="ConditionalExpression";Ce(r,n),r.type==="Identifier"&&(s||a||o||l)&&(i&&i.type==="CallExpression"&&i.callee&&i.callee.object&&i.callee.object.name===fe&&i.callee.property?.name==="get"||Ve(r));let c=e.getCurrentScopeType()==="if";e.isContextBound(r.name)&&!e.isRootParam(r.name)&&c&&Ve(r)}})}function $_(t,e,r){t.test&&(e.pushScope("if"),Ho(t.test,e),e.popScope()),e.pushScope("if"),r(t.consequent,e),e.popScope(),t.alternate&&(e.pushScope("els"),r(t.alternate,e),e.popScope())}function W_(t,e){let r=e.getCurrentScopeType();if(t.argument){if(t.argument.type==="ArrayExpression")t.argument.elements=t.argument.elements.map(n=>n.type==="Identifier"?e.isContextBound(n.name)&&!e.isRootParam(n.name)?S.createGetCall(n,0):$i(n.name,e):n.type==="MemberExpression"?n.object&&n.object.type==="MemberExpression"&&n.object.object&&n.object.object.type==="Identifier"&&n.object.object.name==="$"&&n.object.property&&["const","let","var","params"].includes(n.object.property.name)?S.createGetCall(n,0):(ge(n,"",e),n):((n.type==="BinaryExpression"||n.type==="LogicalExpression"||n.type==="ConditionalExpression"||n.type==="CallExpression"||n.type==="UnaryExpression")&&Ne(n,e,{Identifier(i,s){Ce(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(Ve(i),i._arrayAccessed=!0)},MemberExpression(i){ge(i,"",e)},CallExpression(i,s,a){(i.callee.type==="ArrowFunctionExpression"||i.callee.type==="FunctionExpression")&&a(i.callee,s),ve(i,s),i.type==="CallExpression"&&i.arguments.forEach(o=>a(o,s))},BinaryExpression(i,s,a){a(i.left,s),a(i.right,s)}}),n)),t.argument={type:"ArrayExpression",elements:[t.argument]};else if(t.argument.type==="ObjectExpression")t.argument.properties=t.argument.properties.map(n=>n.shorthand?e.isContextBound(n.value.name)?n:(e.getVariable(n.value.name),{type:"Property",key:S.createIdentifier(n.key.name),value:ke(n.value.name,e),kind:"init",method:!1,shorthand:!1,computed:!1}):(n.value&&n.value.type==="Identifier"&&(e.isContextBound(n.value.name)&&!e.isRootParam(n.value.name)||e.isContextBound(n.value.name)||(n.value=ke(n.value.name,e))),n));else if(t.argument.type==="Identifier")Ce(t.argument,e),t.argument.type==="Identifier"&&Ve(t.argument);else if(t.argument.type==="MemberExpression"){if(t.argument.object.type==="Identifier"&&!e.isContextBound(t.argument.object.name)&&!e.isLoopVariable(t.argument.object.name)&&!(t.argument.computed&&e.isLocalSeriesVar(t.argument.object.name)))Ce(t.argument.object,e);else if(t.argument.computed&&t.argument.object.type==="MemberExpression"){let n=t.argument.object;for(;n.object&&n.object.type==="MemberExpression";)n=n.object;n.object?.type==="Identifier"&&e.isUdtInstance(n.object.name)&&ge(t.argument,"",e)}}if(r==="fn"){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=S.createArrayAccess(t.argument,0):t.argument.type==="MemberExpression"?t.argument.computed&&t.argument.object.type==="CallExpression"?ge(t.argument,"",e):t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)?t.argument.computed?ge(t.argument,"",e):t.argument._indexTransformed||(rr(t.argument,e),t.argument._indexTransformed=!0):t.argument.computed&&t.argument.object.type==="Identifier"&&e.isLocalSeriesVar(t.argument.object.name)&&ge(t.argument,"",e):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression"||t.argument.type==="UnaryExpression"||t.argument.type==="AssignmentExpression")&&Ne(t.argument,e,{Identifier(i,s){Ce(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(Ve(i),i._arrayAccessed=!0)},MemberExpression(i){ge(i,"",e)},AssignmentExpression(i,s){Nn(i,s)},CallExpression(i,s,a){(i.callee.type==="ArrowFunctionExpression"||i.callee.type==="FunctionExpression")&&a(i.callee,s),ve(i,s),i.type==="CallExpression"&&i.arguments.forEach(o=>a(o,s))},BinaryExpression(i,s,a){a(i.left,s),a(i.right,s)},ArrowFunctionExpression(i,s,a){if(i.body)if(i.body.type==="BlockStatement"){let o=[];i.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.body.body=o}else a(i.body,s)},FunctionExpression(i,s,a){if(i.body&&i.body.type==="BlockStatement"){let o=[];i.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.body.body=o}},SwitchStatement(i,s,a){i.discriminant.parent=i,a(i.discriminant,s),i.cases.forEach(o=>{o.parent=i,a(o,s)})},SwitchCase(i,s,a){i.test&&(i.test.parent=i,a(i.test,s));let o=[];i.consequent.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.consequent=o},BlockStatement(i,s,a){let o=[];i.body.forEach(l=>{s.enterHoistingScope(),a(l,s);let c=s.exitHoistingScope();o.push(...c),o.push(l)}),i.body=o}});let n=S.createCallExpression(S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("precision")),[t.argument]);t.argument=n}}}function U_(t,e,r){let n=S.createVariableDeclaration("$$",S.createCallExpression(S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("peekCtx")),[]));if(n._skipTransformation=!0,e.addLoopVariable("$$","$$"),t.body&&t.body.type==="BlockStatement"){t.body.body.unshift(n),e.pushScope("fn"),t.params.forEach(l=>{l.type==="Identifier"&&e.addLocalSeriesVar(l.name)});let i=t.id?.name,s=i?.startsWith("$M_")?i.slice(3):i,a=s?e.getFunctionParamUdtTypes(s):void 0,o={};if(a)for(let[l,c]of Object.entries(a))o[l]=e.getVariableUdtType(l),e.markVariableAsUdtInstance(l,c);if(r(t.body,e),t.params.forEach(l=>{l.type==="Identifier"&&e.removeLocalSeriesVar(l.name)}),a)for(let l of Object.keys(a)){e.unmarkVariableAsUdtInstance(l);let c=o[l];c!==void 0&&e.markVariableAsUdtInstance(l,c)}e.popScope()}}function q_(t){let e={...I,LineComment:()=>{}};function r(o){return o?o.type==="Identifier"?o.name:o.type==="CallExpression"&&o.callee?.type==="MemberExpression"&&o.callee.object?.name==="$"&&o.callee.property?.name==="get"&&o.arguments?.[0]?.type==="Identifier"?o.arguments[0].name:null:null}let n=new Map;mt(t,{FunctionDeclaration(o){o.id?.name&&n.set(o.id.name,o)}},e);function i(o){let l=!1,c={...e,FunctionDeclaration:()=>{},FunctionExpression:()=>{},ArrowFunctionExpression:()=>{}};return mt(o,{AwaitExpression(){l=!0}},c),l}let s=!0,a=0;for(;s&&a<20;){s=!1,a++,mt(t,{ArrowFunctionExpression(c){!c.async&&i(c.body)&&(c.async=!0,s=!0)},FunctionExpression(c){!c.async&&i(c.body)&&(c.async=!0,s=!0)}},e);let o=[];mt(t,{CallExpression(c){!c._asyncWrapped&&(c.callee?.type==="ArrowFunctionExpression"||c.callee?.type==="FunctionExpression")&&c.callee.async===!0&&o.push(c)}},e);for(let c of o){let u={};for(let h of Object.keys(c))u[h]=c[h];u._asyncWrapped=!0;for(let h of Object.keys(c))delete c[h];c.type="AwaitExpression",c.argument=u,s=!0}let l=new Set;for(let[c,u]of n)i(u.body)&&(u.async||(u.async=!0,s=!0),l.add(c));if(l.size>0){let c=[];mt(t,{CallExpression(u){if(!u._asyncWrapped&&u.callee?.type==="MemberExpression"&&u.callee.object?.name==="$"&&u.callee.property?.name==="call"&&u.arguments?.length>0){let h=r(u.arguments[0]);h&&l.has(h)&&c.push(u)}}},e);for(let u of c){let h={};for(let p of Object.keys(u))h[p]=u[p];h._asyncWrapped=!0;for(let p of Object.keys(u))delete u[p];u.type="AwaitExpression",u.argument=h,s=!0}}}}var z_={"==":"__eq","===":"__eq","!=":"__neq","!==":"__neq","<":"__lt","<=":"__le",">":"__gt",">=":"__ge"},K_=new Set(["<","<=",">",">="]);function H_(t,e){if(t._skipCompare)return!0;for(let r=0;r<e.length-1;r++){let n=e[r],i=e[r+1];if(n.type==="ForStatement"&&(i===n.test||i===n.update)||(n.type==="WhileStatement"||n.type==="DoWhileStatement")&&i===n.test)return!0}return!1}function G_(t){let e={...I,LineComment:()=>{}};Wo(t,{BinaryExpression(r,n,i){let s=z_[r.operator];if(!s||K_.has(r.operator)&&H_(r,i))return;let a=S.createMathCompareCall(s,r.left,r.right);a._transformed=!0,Object.assign(r,a)}},e)}function Y_(t,e,r,n={debug:!1,ln:!1},i=[]){let s=a=>{if(!n.debug||!a.loc||!i.length)return null;let o=a.loc.start.line-1;if(o>=0&&o<i.length){let l=i[o].trim();if(l)return{type:"LineComment",value:`${n.ln?` [Line ${a.loc.start.line}]`:""} ${l}`}}return null};Ne(t,e,{Program(a,o,l){let c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);let h=o.exitHoistingScope(),p=s(u);p&&c.push(p),c.push(...h),c.push(u)}),a.body=c},BlockStatement(a,o,l){let c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);let h=o.exitHoistingScope(),p=s(u);p&&c.push(p),c.push(...h),c.push(u)}),a.body=c},ReturnStatement(a,o,l){a.argument&&a.argument.type!=="ArrayExpression"&&a.argument.type!=="ObjectExpression"&&a.argument.type!=="Identifier"&&a.argument.type!=="MemberExpression"&&o.getCurrentScopeType()!=="fn"&&l(a.argument,o),W_(a,o)},VariableDeclaration(a,o){Ko(a,o)},Identifier(a,o){Ce(a,o)},CallExpression(a,o,l){a.callee&&(a.callee.type==="ArrowFunctionExpression"||a.callee.type==="FunctionExpression")?l(a.callee,o):a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&(a.callee.object.parent=a.callee,l(a.callee.object,o)),ve(a,o)},ArrowFunctionExpression(a,o,l){a.body&&l(a.body,o)},FunctionExpression(a,o,l){a.body&&l(a.body,o)},ForOfStatement(a,o,l){if(a.left&&a.left.type==="VariableDeclaration"){a.left._skipTransformation=!0;let h=a.left.declarations[0];h.id.type==="Identifier"?o.addLoopVariable(h.id.name,h.id.name):h.id.type==="ArrayPattern"&&h.id.elements.forEach(p=>{p.type==="Identifier"&&o.addLoopVariable(p.name,p.name)})}if(a.right){a.right.type==="Identifier"?(Ce(a.right,o),a.right.type==="Identifier"&&Ve(a.right)):l(a.right,o);let h=a.left&&a.left.type==="VariableDeclaration"&&a.left.declarations[0].id.type==="ArrayPattern"?"entries":"iter",p={...a.right},d=S.createCallExpression(S.createMemberExpression(S.createIdentifier("$"),S.createIdentifier(h),!1),[p]);Object.assign(a.right,d)}let c=o.getNextLoopGuardName(),u=Es(c);if(o.addHoistedStatement(u.counterDecl),a.body&&l(a.body,o),a.body&&a.body.type==="BlockStatement"&&a.body.body.unshift(u.guardCheck),a.left&&a.left.type==="VariableDeclaration"){let h=a.left.declarations[0];h.id.type==="Identifier"?o.removeLoopVariable(h.id.name):h.id.type==="ArrayPattern"&&h.id.elements.forEach(p=>{p.type==="Identifier"&&o.removeLoopVariable(p.name)})}},ForInStatement(a,o,l){a.left&&a.left.type==="VariableDeclaration"&&(a.left._skipTransformation=!0),a.right&&a.right.type==="Identifier"?(Ce(a.right,o),a.right.type==="Identifier"&&Ve(a.right)):a.right&&l(a.right,o),a.body&&l(a.body,o)},MemberExpression(a,o,l){a.object&&(a.object.type==="CallExpression"||a.object.type==="MemberExpression")&&(a.object.parent=a,l(a.object,o)),a.object&&a.object.type==="Identifier"&&!o.isContextBound(a.object.name)&&(a.object.parent=a,l(a.object,o)),ge(a,r,o)},AssignmentExpression(a,o,l){if(Nn(a,o),a.type==="CallExpression"&&a.arguments){let c=u=>{u&&(u.type==="CallExpression"&&u.callee&&(u.callee.type==="ArrowFunctionExpression"||u.callee.type==="FunctionExpression")&&l(u.callee,o),u.type==="BinaryExpression"&&(c(u.left),c(u.right)))};a.arguments.forEach(u=>c(u))}},FunctionDeclaration(a,o,l){U_(a,o,l)},ForStatement(a,o,l){V_(a,o,l)},WhileStatement(a,o,l){j_(a,o,l)},IfStatement(a,o,l){$_(a,o,l)},SwitchStatement(a,o,l){a.discriminant.parent=a,l(a.discriminant,o),a.cases.forEach(c=>{c.parent=a,l(c,o)})},SwitchCase(a,o,l){a.test&&(a.test.parent=a,l(a.test,o));let c=[];a.consequent.forEach(u=>{o.enterHoistingScope(),l(u,o);let h=o.exitHoistingScope();c.push(...h),c.push(u)}),a.consequent=c},AwaitExpression(a,o,l){a.argument&&(a.argument._insideAwait=!0,l(a.argument,o),a.argument.type==="Identifier"&&a.argument._wasInsideAwait===!0&&(a.type="Identifier",a.name=a.argument.name,a.argument._wasHoisted&&(a._wasHoisted=a.argument._wasHoisted),delete a.argument))}})}var _={NUMBER:"NUMBER",STRING:"STRING",BOOLEAN:"BOOLEAN",IDENTIFIER:"IDENTIFIER",KEYWORD:"KEYWORD",OPERATOR:"OPERATOR",LPAREN:"LPAREN",RPAREN:"RPAREN",LBRACKET:"LBRACKET",RBRACKET:"RBRACKET",LBRACE:"LBRACE",RBRACE:"RBRACE",COMMA:"COMMA",DOT:"DOT",COLON:"COLON",SEMICOLON:"SEMICOLON",INDENT:"INDENT",DEDENT:"DEDENT",NEWLINE:"NEWLINE",COMMENT:"COMMENT",EOF:"EOF"},Z_=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","import","export","method","extends","enum"]),X_=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"],Ui=class{constructor(e,r,n,i,s=0,a=null){this.type=e,this.value=r,this.line=n,this.column=i,this.indent=s,this.raw=a}},Q_=Object.defineProperty,J_=(t,e,r)=>e in t?Q_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_t=(t,e,r)=>J_(t,typeof e!="symbol"?e+"":e,r),qi=class{constructor(e){_t(this,"source"),_t(this,"pos"),_t(this,"line"),_t(this,"column"),_t(this,"tokens"),_t(this,"indentStack"),_t(this,"atLineStart"),_t(this,"parenDepth"),_t(this,"bracketDepth"),_t(this,"braceDepth"),this.source=e,this.pos=0,this.line=1,this.column=1,this.tokens=[],this.indentStack=[0],this.atLineStart=!0,this.parenDepth=0,this.bracketDepth=0,this.braceDepth=0}tokenize(){for(;this.pos<this.source.length;){let e=this.peek();if(e==="\\r"){this.advance();continue}if(e===`\n`){this.handleNewline();continue}if(this.atLineStart&&e!==`\n`){this.handleIndentation(),this.atLineStart=!1;continue}if(e===" "||e===" "){this.advance();continue}if(this.pos>=this.source.length)break;if(e==="/"&&this.peek(1)==="/"){this.readComment();continue}if(e===\'"\'||e==="\'"){this.readString();continue}if(e==="#"){this.readColorLiteral();continue}if(this.isDigit(e)){this.readNumber();continue}if(this.isIdentifierStart(e)){this.readIdentifier();continue}if(!this.readOperatorOrPunctuation())throw new Error(`Unexpected character \'${e}\' at ${this.line}:${this.column}`)}for(;this.indentStack.length>1;)this.indentStack.pop(),this.addToken(_.DEDENT,"",this.getCurrentIndent());return this.addToken(_.EOF,""),this.tokens}handleNewline(){this.parenDepth===0&&this.bracketDepth===0&&this.braceDepth===0&&(this.addToken(_.NEWLINE,`\n`),this.atLineStart=!0),this.advance(),this.line++,this.column=1}handleIndentation(){let e=0,r=0;for(this.pos;this.pos<this.source.length;){let i=this.peek();if(i===" ")r++,this.advance();else if(i===" ")e++,this.advance();else break}if(this.peek()===`\n`||this.peek()==="\\r"||this.peek()==="\\0"||(e+=Math.floor(r/4),this.isContinuationFromPrevToken()))return;let n=this.indentStack[this.indentStack.length-1];if(e>n)this.indentStack.push(e),this.addToken(_.INDENT,"",e);else if(e<n){for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>e;)this.indentStack.pop(),this.addToken(_.DEDENT,"",this.indentStack[this.indentStack.length-1]);if(this.indentStack[this.indentStack.length-1]!==e)throw new Error(`Indentation error at ${this.line}:${this.column} - misaligned dedent`)}}isContinuationFromPrevToken(){for(let e=this.tokens.length-1;e>=0;e--){let r=this.tokens[e];if(!(r.type===_.NEWLINE||r.type===_.COMMENT))return r.type===_.OPERATOR?r.value!=="=>":r.type===_.COMMA||r.type===_.COLON||r.type===_.KEYWORD&&(r.value==="and"||r.value==="or")}return!1}readComment(){this.column;let e="";for(this.advance(),this.advance();this.pos<this.source.length&&this.peek()!==`\n`;)e+=this.advance();this.addToken(_.COMMENT,e.trim())}readString(){let e=this.advance(),r=this.column-1,n="";for(;this.pos<this.source.length&&this.peek()!==e;)if(this.peek()==="\\\\"){this.advance();let i=this.advance();switch(i){case"n":n+=`\n`;break;case"t":n+=" ";break;case"r":n+="\\r";break;case"\\\\":n+="\\\\";break;case e:n+=e;break;default:n+=i}}else n+=this.advance();if(this.peek()!==e)throw new Error(`Unterminated string at ${this.line}:${r}`);this.advance(),this.addToken(_.STRING,n)}readColorLiteral(){let e=this.column,r="#";for(this.advance();this.pos<this.source.length&&r.length<9;){let n=this.peek();if(n>="0"&&n<="9"||n>="A"&&n<="F"||n>="a"&&n<="f")r+=this.advance();else break}if(r.length!==7&&r.length!==9)throw new Error(`Invalid color literal \'${r}\' at ${this.line}:${e}`);this.addToken(_.STRING,r)}readNumber(){this.column;let e="",r=!1;for(this.peek()==="."&&this.isDigit(this.peek(1))&&(r=!0,e+=this.advance());this.pos<this.source.length;){let n=this.peek();if(this.isDigit(n))e+=this.advance();else if(n==="."&&!r){let i=this.peek(1);if(this.isDigit(i)||!this.isIdentifierStart(i)){if(r=!0,e+=this.advance(),!this.isDigit(this.peek()))break}else break}else break}if(this.pos<this.source.length){let n=this.peek();if(n==="e"||n==="E"){let i=this.peek(1);if(this.isDigit(i))for(e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance();else if(i==="+"||i==="-"){let s=this.peek(2);if(this.isDigit(s))for(e+=this.advance(),e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance()}}}this.addToken(_.NUMBER,parseFloat(e),null,e)}readIdentifier(){this.column;let e="";for(;this.pos<this.source.length&&this.isIdentifierChar(this.peek());)e+=this.advance();Z_.has(e)?this.addToken(_.KEYWORD,e):e==="true"||e==="false"?this.addToken(_.BOOLEAN,e==="true"):this.addToken(_.IDENTIFIER,e)}readOperatorOrPunctuation(){let e=this.peek(),r=this.peek(1),n=e+r;if(X_.includes(n))return this.advance(),this.advance(),this.addToken(_.OPERATOR,n),!0;if("+-*/%<>=!?".includes(e))return this.advance(),this.addToken(_.OPERATOR,e),!0;switch(e){case"(":return this.parenDepth++,this.advance(),this.addToken(_.LPAREN,e),!0;case")":return this.parenDepth--,this.advance(),this.addToken(_.RPAREN,e),!0;case"[":return this.bracketDepth++,this.advance(),this.addToken(_.LBRACKET,e),!0;case"]":return this.bracketDepth--,this.advance(),this.addToken(_.RBRACKET,e),!0;case"{":return this.braceDepth++,this.advance(),this.addToken(_.LBRACE,e),!0;case"}":return this.braceDepth--,this.advance(),this.addToken(_.RBRACE,e),!0;case",":return this.advance(),this.addToken(_.COMMA,e),!0;case".":return this.isDigit(this.peek(1))?(this.readNumber(),!0):(this.advance(),this.addToken(_.DOT,e),!0);case":":return this.advance(),this.addToken(_.COLON,e),!0;case";":return this.advance(),this.addToken(_.SEMICOLON,e),!0}return!1}peek(e=0){let r=this.pos+e;return r<this.source.length?this.source[r]:"\\0"}advance(){let e=this.source[this.pos++];return this.column++,e}skipWhitespaceInline(){if(!this.atLineStart)for(;this.pos<this.source.length&&(this.peek()===" "||this.peek()===" ");)this.advance()}isDigit(e){return e>="0"&&e<="9"}isIdentifierStart(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e==="_"}isIdentifierChar(e){return this.isIdentifierStart(e)||this.isDigit(e)}getCurrentIndent(){return this.indentStack[this.indentStack.length-1]}addToken(e,r,n=null,i=null){let s=new Ui(e,r,this.line,this.column,n!==null?n:this.getCurrentIndent(),i);this.tokens.push(s)}},e0=Object.defineProperty,t0=(t,e,r)=>e in t?e0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ye=(t,e,r)=>t0(t,typeof e!="symbol"?e+"":e,r),ie=class{constructor(e){this.type=e}},zi=class extends ie{constructor(e){super("Program"),this.body=e}},qe=class extends ie{constructor(e){super("ExpressionStatement"),this.expression=e}},At=(t=>(t.VAR="var",t.LET="let",t.CONST="const",t))(At||{}),ut=class extends ie{constructor(e,r="let"){super("VariableDeclaration"),this.declarations=e,this.kind=r}},rt=class extends ie{constructor(e,r,n=null){super("VariableDeclarator"),this.id=e,this.init=r,this.varType=n}},kn=class extends ie{constructor(e,r,n,i=null){super("FunctionDeclaration"),this.id=e,this.params=r,this.body=n,this.returnType=i}},Ki=class extends ie{constructor(e,r){super("TypeDefinition"),this.name=e,this.fields=r}},Hi=class extends ie{constructor(e,r,n=null){super("IfStatement"),this.test=e,this.consequent=r,this.alternate=n,Ye(this,"_line")}},In=class extends ie{constructor(e,r,n,i){super("ForStatement"),this.init=e,this.test=r,this.update=n,this.body=i,Ye(this,"isForIn")}},Gi=class extends ie{constructor(e,r){super("WhileStatement"),this.test=e,this.body=r}},vt=class extends ie{constructor(e){super("BlockStatement"),this.body=e}},An=class extends ie{constructor(e){super("ReturnStatement"),this.argument=e}},be=class extends ie{constructor(e){super("Identifier"),this.name=e,Ye(this,"varType"),Ye(this,"returnType"),Ye(this,"isMethod")}},Tt=class extends ie{constructor(e,r=null){super("Literal"),this.value=e,this.raw=r}},pt=class extends ie{constructor(e,r,n){super("BinaryExpression"),this.operator=e,this.left=r,this.right=n}},Tn=class extends ie{constructor(e,r,n=!0){super("UnaryExpression"),this.operator=e,this.argument=r,this.prefix=n}},Gt=class extends ie{constructor(e,r,n){super("AssignmentExpression"),this.operator=e,this.left=r,this.right=n}},Dn=class extends ie{constructor(e,r,n=!1){super("UpdateExpression"),this.operator=e,this.argument=r,this.prefix=n}},Yi=class extends ie{constructor(e,r){super("CallExpression"),this.callee=e,this.args=r,Ye(this,"arguments"),this.callee=e,this.arguments=r}},Mn=class extends ie{constructor(e,r,n=!1){super("MemberExpression"),this.object=e,this.property=r,this.computed=n}},wt=class extends ie{constructor(e,r,n){super("ConditionalExpression"),this.test=e,this.consequent=r,this.alternate=n,Ye(this,"needsIIFE"),Ye(this,"consequentStmts"),Ye(this,"alternateStmts")}},Zi=class extends ie{constructor(e){super("ArrayExpression"),this.elements=e}},Pn=class extends ie{constructor(e){super("ObjectExpression"),this.properties=e}},Rn=class extends ie{constructor(e,r){super("Property"),this.key=e,this.value=r,Ye(this,"kind"),Ye(this,"method"),Ye(this,"shorthand"),Ye(this,"computed"),this.kind="init",this.method=!1,this.shorthand=!1,this.computed=!1}},Fn=class extends ie{constructor(e){super("ArrayPattern"),this.elements=e}},Bn=class extends ie{constructor(e,r){super("AssignmentPattern"),this.left=e,this.right=r}},Xi=class extends ie{constructor(e,r){super("SwitchExpression"),this.discriminant=e,this.cases=r}},Qi=class extends ie{constructor(e,r,n){super("SwitchCase"),this.test=e,this.consequent=r,this.statements=n,this.statements=n}},r0=Object.defineProperty,n0=(t,e,r)=>e in t?r0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hr=(t,e,r)=>n0(t,typeof e!="symbol"?e+"":e,r),Go=class Ji{constructor(e){hr(this,"tokens"),hr(this,"pos"),hr(this,"functionNames",new Set),hr(this,"paramScopes",[]),hr(this,"noLineContinuation",!1),this.tokens=e,this.pos=0}peek(e=0){return this.tokens[this.pos+e]||this.tokens[this.tokens.length-1]}isCurrentFunctionParam(e){for(let r of this.paramScopes)if(r.has(e))return!0;return!1}advance(){return this.tokens[this.pos++]}match(e,r=null){let n=this.peek();return!(n.type!==e||r!==null&&n.value!==r)}expect(e,r=null){let n=this.peek();if(n.type!==e)throw new Error(`Expected ${e} but got ${n.type} at ${n.line}:${n.column}`);if(r!==null&&n.value!==r)throw new Error(`Expected \'${r}\' but got \'${n.value}\' at ${n.line}:${n.column}`);return this.advance()}expectIdentifierOrContextual(){let e=this.peek();if(e.type===_.IDENTIFIER)return this.advance();if(e.type===_.KEYWORD&&Ji.CONTEXTUAL_KEYWORDS.has(e.value))return this.advance();throw new Error(`Expected ${_.IDENTIFIER} but got ${e.type} at ${e.line}:${e.column}`)}matchEx(e,r=null,n=!1){if(!n)return this.match(e,r);let i=0,s=this.peek(i);if(s.type===_.NEWLINE&&this.noLineContinuation||(s.type===_.NEWLINE&&(i++,s=this.peek(i),s.type===_.INDENT&&(i++,s=this.peek(i))),s.type!==e)||r!==null&&s.value!==r)return!1;for(let a=0;a<i;a++)this.advance();return!0}peekOperatorEx(e){let r=0,n=this.peek(r),i=!1;if(n.type===_.NEWLINE){if(this.noLineContinuation)return null;r++,n=this.peek(r),n.type===_.INDENT&&(i=!0,r++,n=this.peek(r))}if(n.type!==_.OPERATOR||!e.includes(n.value)||i&&(n.value==="+"||n.value==="-"))return null;for(let s=0;s<r;s++)this.advance();return n.value}skipNewlines(e=!1){for(;this.match(_.NEWLINE)||this.match(_.COMMENT);)this.advance();e&&this.match(_.INDENT)&&this.advance()}parse(){let e=[];for(;!this.match(_.EOF);){if(this.skipNewlines(),this.match(_.DEDENT)){this.advance();continue}if(this.match(_.EOF))break;let r=this.parseStatement();r&&e.push(r),this.skipNewlines()}return new zi(e)}parseStatement(e=!0){this.skipNewlines();let r=this.peek().line;if(this.match(_.COMMENT))return this.advance(),null;let n;if(this.match(_.KEYWORD,"enum"))n=this.parseEnumDefinition();else if(this.match(_.KEYWORD,"type"))n=this.parseTypeDefinition();else if(this.match(_.KEYWORD,"var")||this.match(_.KEYWORD,"varip"))n=this.parseVarDeclaration();else if(this.match(_.KEYWORD,"method"))n=this.parseMethodDeclaration();else if(this.isFunctionDeclaration())n=this.parseFunctionDeclaration();else if(this.match(_.KEYWORD,"if"))n=this.parseIfStatement();else if(this.match(_.KEYWORD,"for"))n=this.parseForStatement();else if(this.match(_.KEYWORD,"while"))n=this.parseWhileStatement();else if(this.match(_.KEYWORD,"break")||this.match(_.KEYWORD,"continue")){let i=this.advance().value;n=new qe(new be(i))}else this.isTupleDestructuring()?n=this.parseTupleDestructuring():this.peek().type===_.IDENTIFIER&&this.isTypedVarDeclaration()&&(n=this.parseTypedVarDeclaration());if(!n){let i=this.parseExpression();if(this.match(_.OPERATOR)){let s=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(s)){this.advance(),this.skipNewlines(!0);let a=this.parseExpression();s==="="&&i.type==="Identifier"?n=new ut([new rt(i,a)],At.LET):n=new qe(new Gt(s===":="?"=":s,i,a))}else n=new qe(i)}else n=new qe(i)}if(n&&(n._line=r,e&&this.match(_.COMMA)&&this.peek().line===r)){let i=[n];for(;this.match(_.COMMA)&&this.peek().line===r;){this.advance(),this.skipNewlines(!0);let s=this.parseStatement(!1);s&&i.push(s)}return new vt(i)}return n}isFunctionDeclaration(){let e=this.pos;try{let r=0;if(this.peek(r).type===_.IDENTIFIER&&this.peek(r+1).type===_.IDENTIFIER&&r++,this.peek(r).type!==_.IDENTIFIER||(r++,this.peek(r).type!==_.LPAREN))return!1;r++;let n=1;for(;n>0&&this.peek(r).type!==_.EOF;)this.peek(r).type===_.LPAREN&&n++,this.peek(r).type===_.RPAREN&&n--,r++;for(;this.peek(r).type===_.NEWLINE;)r++;return this.peek(r).type===_.OPERATOR&&this.peek(r).value==="=>"}finally{this.pos=e}}parseTypeExpression(){let e=this.expect(_.IDENTIFIER).value;for(;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(_.OPERATOR,"<")){this.advance();let r=[];for(r.push(this.parseTypeExpression());this.match(_.COMMA);)this.advance(),this.skipNewlines(),r.push(this.parseTypeExpression());return this.expect(_.OPERATOR,">"),e+"<"+r.join(", ")+">"}return this.match(_.LBRACKET)&&this.peek(1).type===_.RBRACKET?(this.advance(),this.advance(),"array<"+e+">"):e}parseEnumDefinition(){this.expect(_.KEYWORD,"enum");let e=this.expect(_.IDENTIFIER).value;this.skipNewlines(),this.expect(_.INDENT);let r=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){if(this.match(_.COMMENT)){this.advance();continue}let s=this.expectIdentifierOrContextual().value,a=null;this.match(_.OPERATOR,"=")&&(this.advance(),a=this.expect(_.STRING).value),r.push({name:s,title:a}),this.skipNewlines()}this.match(_.DEDENT)&&this.advance();let n=r.map(s=>new Rn(new be(s.name),new Tt(s.title!==null?s.title:s.name))),i=new Pn(n);return new ut([new rt(new be(e),i)],At.CONST)}parseTypeDefinition(){this.expect(_.KEYWORD,"type");let e=this.expect(_.IDENTIFIER).value;this.match(_.OPERATOR,"=>")&&this.advance(),this.skipNewlines(),this.expect(_.INDENT);let r=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let n=this.parseTypeExpression(),i=this.expectIdentifierOrContextual().value,s=null;this.match(_.OPERATOR,"=")&&(this.advance(),this.skipNewlines(),s=this.parseExpression()),r.push({type:n,name:i,defaultValue:s}),this.skipNewlines()}return this.match(_.DEDENT)&&this.advance(),new Ki(e,r)}parseVarDeclaration(){let e=this.advance().value,r=null,n=null;if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.LBRACKET&&this.peek(2).type===_.RBRACKET)r=this.advance().value,this.advance(),r+="[]",this.advance(),n=this.expectIdentifierOrContextual().value;else if(this.peek().type===_.IDENTIFIER&&(this.peek(1).type===_.DOT||this.peek(1).type===_.IDENTIFIER||this.peek(1).type===_.OPERATOR&&this.peek(1).value==="<")){for(r=this.advance().value;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)this.advance(),r+="."+this.advance().value;if(this.match(_.LBRACKET)&&this.peek(1).type===_.RBRACKET)this.advance(),this.advance(),r+="[]",n=this.expectIdentifierOrContextual().value;else if(this.match(_.OPERATOR,"<")){for(this.advance(),r+="<";!this.match(_.OPERATOR,">");)if(this.match(_.IDENTIFIER))for(r+=this.advance().value;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)r+=".",this.advance(),r+=this.advance().value;else if(this.match(_.COMMA))r+=this.advance().value,this.skipNewlines();else break;this.match(_.OPERATOR,">")&&(r+=">",this.advance()),n=this.expectIdentifierOrContextual().value}else n=this.expectIdentifierOrContextual().value}else if(this.peek().type===_.IDENTIFIER)n=this.advance().value;else throw new Error(`Expected identifier after ${e} at ${this.peek().line}:${this.peek().column}`);this.functionNames.has(n)&&(n=n+"_var"),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let i=this.parseExpression(),s=new be(n);r&&(s.varType=r);let a=[new rt(s,i,r)];for(;this.match(_.COMMA)&&this.peek(1).type===_.KEYWORD&&(this.peek(1).value==="var"||this.peek(1).value==="varip");){this.advance();let o=this.parseVarDeclaration();a.push(...o.declarations)}return new ut(a,e)}isTypedVarDeclaration(){let e=0;if(this.peek(e).type!==_.IDENTIFIER)return!1;for(e++;this.peek(e).type===_.DOT&&this.peek(e+1).type===_.IDENTIFIER;)e+=2;if(this.peek(e).type===_.LBRACKET&&this.peek(e+1).type===_.RBRACKET)return e+=2,this.peek(e).type!==_.IDENTIFIER?!1:(e++,this.peek(e).type===_.OPERATOR&&this.peek(e).value==="=");if(this.peek(e).type===_.OPERATOR&&this.peek(e).value==="<"){e++;let r=1;for(;r>0&&this.peek(e).type!==_.EOF;)this.peek(e).type===_.OPERATOR&&this.peek(e).value==="<"?r++:this.peek(e).type===_.OPERATOR&&this.peek(e).value===">"&&r--,e++;return this.peek(e).type!==_.IDENTIFIER?!1:(e++,this.peek(e).type===_.OPERATOR&&this.peek(e).value==="=")}if(this.peek(e).type!==_.IDENTIFIER)return!1;for(e++;this.peek(e).type===_.IDENTIFIER;)e++;return this.peek(e).type===_.OPERATOR&&this.peek(e).value==="="}parseTypedVarDeclaration(){let e=this.advance().value;for(;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(_.LBRACKET)&&this.peek(1).type===_.RBRACKET)this.advance(),this.advance(),e+="[]";else if(this.match(_.OPERATOR,"<")){for(this.advance(),e+="<";!this.match(_.OPERATOR,">");)if(this.match(_.IDENTIFIER))for(e+=this.advance().value;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)e+=".",this.advance(),e+=this.advance().value;else if(this.match(_.COMMA))e+=this.advance().value,this.skipNewlines();else break;this.match(_.OPERATOR,">")&&(e+=">",this.advance())}else for(;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER;)e+=" "+this.advance().value;let r=this.expectIdentifierOrContextual().value;this.functionNames.has(r)&&(r=r+"_var"),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let n=this.parseExpression(),i=new be(r);i.varType=e;let s=[new rt(i,n,e)];for(;this.match(_.COMMA)&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type===_.OPERATOR&&this.peek(2).value==="=";){this.advance(),this.skipNewlines(!0);let a=this.expectIdentifierOrContextual().value;this.functionNames.has(a)&&(a=a+"_var"),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let o=this.parseExpression(),l=new be(a);l.varType=e,s.push(new rt(l,o,e))}return new ut(s,At.LET)}parseFunctionDeclaration(){let e=null;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&(e=this.advance().value);let r=this.expect(_.IDENTIFIER).value;this.functionNames.add(r),this.expect(_.LPAREN);let n=[];for(;!this.match(_.RPAREN)&&(this.skipNewlines(),!this.match(_.RPAREN));){let o=null;for(;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type!==_.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.OPERATOR&&this.peek(1).value==="<"){let u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.LBRACKET&&this.peek(2).type===_.RBRACKET){let u=this.parseTypeExpression();o=o?o+" "+u:u}let l=this.expectIdentifierOrContextual().value,c=new be(l);if(o&&(c.varType=o),this.match(_.OPERATOR,"=")){this.advance(),this.skipNewlines();let u=this.parseExpression();n.push(new Bn(c,u))}else n.push(c);this.match(_.COMMA)&&this.advance()}this.expect(_.RPAREN),this.skipNewlines(),this.expect(_.OPERATOR,"=>"),this.skipNewlines();let i=new Set;for(let o of n){let l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&i.add(l.name)}this.paramScopes.push(i);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}let a=new be(r);return e&&(a.returnType=e),new kn(a,n,s,e)}parseMethodDeclaration(){this.expect(_.KEYWORD,"method");let e=null;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type===_.LPAREN&&(e=this.advance().value);let r=this.expectIdentifierOrContextual().value;this.expect(_.LPAREN);let n=[];for(;!this.match(_.RPAREN)&&(this.skipNewlines(),!this.match(_.RPAREN));){let o=null;for(;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type!==_.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.OPERATOR&&this.peek(1).value==="<"){let u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.LBRACKET&&this.peek(2).type===_.RBRACKET){let u=this.parseTypeExpression();o=o?o+" "+u:u}let l=this.expectIdentifierOrContextual().value,c=new be(l);if(o&&(c.varType=o),this.match(_.OPERATOR,"=")){this.advance(),this.skipNewlines();let u=this.parseExpression();n.push(new Bn(c,u))}else n.push(c);this.match(_.COMMA)&&this.advance()}this.expect(_.RPAREN),this.skipNewlines(),this.expect(_.OPERATOR,"=>"),this.skipNewlines();let i=new Set;for(let o of n){let l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&i.add(l.name)}this.paramScopes.push(i);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}let a=new be(r);return e&&(a.returnType=e),a.isMethod=!0,new kn(a,n,s,e)}parseFunctionBody(){let e=[];if(!this.match(_.INDENT)){let r=this.parseExpression();return new vt([new An(r)])}for(this.advance();!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let r=this.parseStatementOrSequence();Array.isArray(r)?e.push(...r):r&&e.push(r)}return this.match(_.DEDENT)&&this.advance(),e.length>0&&this._addImplicitReturn(e),new vt(e)}_addImplicitReturn(e){let r=e[e.length-1];r.type==="ExpressionStatement"?e[e.length-1]=new An(r.expression):r.type==="IfStatement"&&this._addImplicitReturnToIf(r)}_addImplicitReturnToIf(e){e.consequent&&e.consequent.type==="BlockStatement"&&e.consequent.body.length>0&&this._addImplicitReturn(e.consequent.body),e.alternate&&(e.alternate.type==="IfStatement"?this._addImplicitReturnToIf(e.alternate):e.alternate.type==="BlockStatement"&&e.alternate.body.length>0&&this._addImplicitReturn(e.alternate.body))}parseStatementOrSequence(){this.pos;let e=this.peek().line;if(this.match(_.KEYWORD,"if")){let n=this.parseIfStatement();return n&&(n._line=e),n}if(this.match(_.KEYWORD,"for"))return this.parseForStatement();if(this.match(_.KEYWORD,"while"))return this.parseWhileStatement();if(this.match(_.KEYWORD,"break")||this.match(_.KEYWORD,"continue")){let n=this.advance().value;return new qe(new be(n))}if(this.match(_.KEYWORD,"var")||this.match(_.KEYWORD,"varip"))return this.parseVarDeclaration();if(this.isTupleDestructuring())return this.parseTupleDestructuring();if(this.peek().type===_.IDENTIFIER&&this.isTypedVarDeclaration()){let n=this.parseTypedVarDeclaration();if(this.match(_.COMMA)&&this.peek(1).type===_.IDENTIFIER){let i=[n];for(;this.match(_.COMMA);)if(this.advance(),this.skipNewlines(!0),this.peek().type===_.IDENTIFIER&&this.isTypedVarDeclaration())i.push(this.parseTypedVarDeclaration());else{let s=this.parseExpression();if(this.match(_.OPERATOR)){let a=this.peek().value;if(["=",":="].includes(a)){this.advance(),this.skipNewlines(!0);let o=this.parseExpression();a==="="&&s.type==="Identifier"?i.push(new ut([new rt(s,o)],At.LET)):i.push(new qe(new Gt(a===":="?"=":a,s,o)))}}break}return i}return n}let r=[];for(;;){let n=this.parseExpression();if(this.match(_.OPERATOR)){let i=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(i)){this.advance(),this.skipNewlines(!0);let s=this.parseExpression();if(i==="="&&n.type==="Identifier"?r.push(new ut([new rt(n,s)],At.LET)):r.push(new qe(new Gt(i===":="?"=":i,n,s))),this.match(_.COMMA)){this.advance(),this.skipNewlines();continue}break}else{if(r.length>0)r.push(new qe(n));else return new qe(n);break}}else if(this.match(_.COMMA)){r.push(new qe(n)),this.advance(),this.skipNewlines();continue}else{if(r.length>0)r.push(new qe(n));else return new qe(n);break}}return r.length>1?r:r.length===1?r[0]:null}parseIfStatement(){this.expect(_.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines();let r=this.parseBlock(),n=null;return this.skipNewlines(),this.match(_.KEYWORD,"else")&&(this.advance(),this.skipNewlines(),this.match(_.KEYWORD,"if")?n=this.parseIfStatement():n=this.parseBlock()),new Hi(e,r,n)}parseForStatement(){this.expect(_.KEYWORD,"for");let e=null,r=!1;if(this.match(_.LBRACKET)){this.advance();let n=[];for(;!this.match(_.RBRACKET);)this.skipNewlines(),n.push(new be(this.expectIdentifierOrContextual().value)),this.match(_.COMMA)&&this.advance();this.expect(_.RBRACKET),e=new Fn(n),r=!0}else{let n=this.expectIdentifierOrContextual().value;e=new be(n)}if(this.match(_.KEYWORD,"in")){this.advance();let n=this.parseExpression();this.skipNewlines();let i=this.parseBlock(),s=new ut([new rt(e,n)],At.CONST),a=new In(s,null,null,i);return a.isForIn=!0,a}else{if(r)throw new Error(`Range-based for loops don\'t support destructuring at ${this.peek().line}:${this.peek().column}`);this.expect(_.OPERATOR,"=");let n=this.parseExpression();this.expect(_.KEYWORD,"to");let i=this.parseExpression(),s=null;this.match(_.KEYWORD,"by")&&(this.advance(),s=this.parseExpression()),this.skipNewlines();let a=this.parseBlock(),o=new ut([new rt(e,n)],At.LET),l=new pt("<=",n,i),c=new wt(l,new pt("<=",e,i),new pt(">=",e,i)),u;return s?u=new wt(l,new Gt("+=",e,s),new Gt("-=",e,s)):u=new wt(l,new Dn("++",e),new Dn("--",e)),new In(o,c,u,a)}}parseWhileStatement(){this.expect(_.KEYWORD,"while");let e=this.parseExpression();this.skipNewlines();let r=this.parseBlock();return new Gi(e,r)}parseBlock(){if(!this.match(_.INDENT)){let n=this.parseStatement();return new vt(n?[n]:[])}let e=this.peek().indent;this.advance();let r=[];for(;!this.match(_.EOF);){if(this.skipNewlines(),this.match(_.DEDENT)){if(this.peek().indent<e)break;this.advance();continue}if(this.match(_.EOF))break;let n=this.parseStatement();n&&r.push(n)}return this.match(_.DEDENT)&&this.peek().indent<e&&this.advance(),new vt(r)}isTupleDestructuring(){if(!this.match(_.LBRACKET))return!1;let e=1;for(;;){for(;this.peek(e).type===_.NEWLINE;)e++;if(this.peek(e).type!==_.IDENTIFIER)return!1;for(e++;this.peek(e).type===_.NEWLINE;)e++;if(this.peek(e).type===_.RBRACKET){e++;break}else if(this.peek(e).type===_.COMMA){e++;continue}else return!1}for(;this.peek(e).type===_.NEWLINE;)e++;return this.peek(e).type===_.OPERATOR&&this.peek(e).value==="="}parseTupleDestructuring(){this.expect(_.LBRACKET);let e=[];for(;!this.match(_.RBRACKET);){this.skipNewlines();let n=this.expectIdentifierOrContextual().value;this.functionNames.has(n)&&(n=n+"_var"),e.push(new be(n)),this.match(_.COMMA)&&this.advance()}this.expect(_.RBRACKET),this.skipNewlines(),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let r=this.parseExpression();return new ut([new rt(new Fn(e),r)],At.CONST)}parseExpression(){return this.parseTernary()}parseTernary(){let e=this.parseLogicalOr();if(this.matchEx(_.OPERATOR,"?",!0)){this.advance(),this.skipNewlines(!0);let r=this.parseExpression();this.matchEx(_.COLON,null,!0)?this.advance():this.expect(_.COLON),this.skipNewlines(!0);let n=this.parseExpression();return new wt(e,r,n)}return e}parseLogicalOr(){let e=this.parseLogicalAnd();for(;this.matchEx(_.KEYWORD,"or",!0)||this.peekOperatorEx(["||"]);){this.advance(),this.skipNewlines(!0);let r=this.parseLogicalAnd();e=new pt("||",e,r)}return e}parseLogicalAnd(){let e=this.parseEquality();for(;this.matchEx(_.KEYWORD,"and",!0)||this.peekOperatorEx(["&&"]);){this.advance(),this.skipNewlines(!0);let r=this.parseEquality();e=new pt("&&",e,r)}return e}parseEquality(){let e=this.parseComparison();for(;this.peekOperatorEx(["==","!="]);){let r=this.advance().value;this.skipNewlines(!0);let n=this.parseComparison();e=new pt(r,e,n)}return e}parseComparison(){let e=this.parseAdditive();for(;this.peekOperatorEx(["<",">","<=",">="]);){let r=this.advance().value;this.skipNewlines(!0);let n=this.parseAdditive();e=new pt(r,e,n)}return e}parseAdditive(){let e=this.parseMultiplicative();for(;this.peekOperatorEx(["+","-"]);){let r=this.advance().value;this.skipNewlines(!0);let n=this.parseMultiplicative();e=new pt(r,e,n)}return e}parseMultiplicative(){let e=this.parseUnary();for(;this.peekOperatorEx(["*","/","%"]);){let r=this.advance().value;this.skipNewlines(!0);let n=this.parseUnary();e=new pt(r,e,n)}return e}parseUnary(){if(this.match(_.OPERATOR)){let e=this.peek().value;if(["+","-","!"].includes(e))return this.advance(),this.skipNewlines(),new Tn(e,this.parseUnary())}return this.match(_.KEYWORD,"not")?(this.advance(),this.skipNewlines(),new Tn("!",this.parseUnary())):this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match(_.OPERATOR,"<")){let r=this.pos;this.advance();let n=1,i=!0,s="",a=new Set(["float","int","string","bool","color","line","label","box","linefill","table"]);for(;n>0&&!this.match(_.EOF);)if(this.match(_.OPERATOR,"<"))n++,this.advance();else if(this.match(_.OPERATOR,">"))n--,this.advance();else if(this.match(_.IDENTIFIER)||this.match(_.COMMA)||this.match(_.DOT))n===1&&this.match(_.IDENTIFIER)&&s===""&&(s=this.peek().value),this.advance();else{i=!1,this.pos=r;break}if(i&&e.type==="MemberExpression"&&e.property.name==="new"&&(e.object.name==="array"||e.object.name==="matrix")&&a.has(s)&&(e.property=new be("new_"+s)),i&&this.match(_.LPAREN)){e=this.parseCallExpression(e);continue}else{if(i)continue;break}}else if(this.match(_.LPAREN))e=this.parseCallExpression(e);else if(this.match(_.DOT)){this.advance(),this.skipNewlines();let r=this.peek();if(r.type!==_.IDENTIFIER&&r.type!==_.KEYWORD)throw new Error(`Expected property name but got ${r.type} at ${r.line}:${r.column}`);this.advance(),e=new Mn(e,new be(r.value),!1)}else if(this.match(_.LBRACKET)){if(this.isTupleDestructuring())break;this.advance(),this.skipNewlines();let r=this.parseExpression();this.expect(_.RBRACKET),e=new Mn(e,r,!0)}else break;return e}parseCallExpression(e){this.expect(_.LPAREN);let r=[],n=[];for(;!this.match(_.RPAREN)&&(this.skipNewlines(),!this.match(_.RPAREN));){if((this.peek().type===_.IDENTIFIER||this.peek().type===_.KEYWORD)&&this.peek(1).type===_.OPERATOR&&this.peek(1).value==="="){let i=this.advance().value;this.advance(),this.skipNewlines();let s=this.parseExpression();n.push(new Rn(new be(i),s))}else r.push(this.parseExpression());this.match(_.COMMA)&&this.advance(),this.skipNewlines()}return this.expect(_.RPAREN),n.length>0&&r.push(new Pn(n)),new Yi(e,r)}parsePrimary(){let e=this.peek();if(this.match(_.NUMBER)){let r=this.advance();return new Tt(r.value,r.raw)}if(this.match(_.STRING)){let r=this.advance();return new Tt(r.value)}if(this.match(_.BOOLEAN)){let r=this.advance();return new Tt(r.value)}if(this.match(_.IDENTIFIER)||e.type===_.KEYWORD&&Ji.CONTEXTUAL_KEYWORDS.has(e.value)){let r=this.advance().value;return this.functionNames.has(r)&&this.peek().type!==_.LPAREN&&!this.isCurrentFunctionParam(r)&&(r=r+"_var"),new be(r)}if(this.match(_.LBRACKET))return this.parseArrayLiteral();if(this.match(_.LPAREN)){this.advance(),this.skipNewlines();let r=this.parseExpression();return this.skipNewlines(),this.expect(_.RPAREN),r}if(this.match(_.KEYWORD,"if"))return this.parseIfExpression();if(this.match(_.KEYWORD,"switch"))return this.parseSwitchExpression();if(this.match(_.KEYWORD,"for"))return this.parseForExpression();if(this.match(_.KEYWORD,"while"))return this.parseWhileExpression();throw new Error(`Unexpected token ${e.type} \'${e.value}\' at ${e.line}:${e.column}`)}parseArrayLiteral(){this.expect(_.LBRACKET);let e=[];for(;!this.match(_.RBRACKET)&&(this.skipNewlines(),!this.match(_.RBRACKET));)e.push(this.parseExpression()),this.match(_.COMMA)&&this.advance(),this.skipNewlines();return this.expect(_.RBRACKET),new Zi(e)}parseIfExpression(){this.expect(_.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines(),this.expect(_.INDENT);let r=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let a=this.parseStatement();a&&r.push(a)}this.advance();let n=[];if(this.match(_.KEYWORD,"else"))if(this.advance(),this.skipNewlines(),this.match(_.KEYWORD,"if")){let a=this.parseIfExpression();if(this.needsIIFE(r,n)){let o=new wt(e,new vt(r),a);return o.needsIIFE=!0,o.consequentStmts=r,o.alternateExpr=a,o}else return new wt(e,this.getBlockValue(r),a)}else{for(this.expect(_.INDENT);!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let a=this.parseStatement();a&&n.push(a)}this.advance()}if(this.needsIIFE(r,n)){let a=new wt(e,new vt(r),new vt(n));return a.needsIIFE=!0,a.consequentStmts=r,a.alternateStmts=n,a}let i=this.getBlockValue(r),s=n.length>0?this.getBlockValue(n):new Tt(null);return new wt(e,i,s)}needsIIFE(e,r){if(e.length>1||r.length>1)return!0;let n=i=>i.some(s=>s.type==="IfStatement"||s.type==="ForStatement"||s.type==="WhileStatement"||s.type==="BlockStatement");return n(e)||n(r)}parseSwitchExpression(){this.expect(_.KEYWORD,"switch");let e=null;!this.match(_.NEWLINE)&&!this.match(_.INDENT)&&(e=this.parseExpression()),this.skipNewlines(),this.expect(_.INDENT);let r=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let n=null;this.match(_.OPERATOR,"=>")||(n=this.parseExpression()),this.expect(_.OPERATOR,"=>"),this.skipNewlines();let i=[];if(this.match(_.INDENT)){for(this.advance();!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let a=this.parseStatement();a&&i.push(a)}this.advance()}else{this.noLineContinuation=!0;let a=this.parseStatement();this.noLineContinuation=!1,a&&i.push(a)}let s=this.getBlockValue(i);r.push(new Qi(n,s,i)),this.skipNewlines()}return this.advance(),new Xi(e,r)}parseForExpression(){let e=this.parseForStatement();return e.isExpression=!0,e}parseWhileExpression(){let e=this.parseWhileStatement();return e.isExpression=!0,e}getBlockValue(e){if(e.length===0)return new Tt(null);let r=e[e.length-1];return r.type==="ExpressionStatement"?r.expression:r.type==="VariableDeclaration"&&r.declarations.length>0?r.declarations[0].id:new Tt(null)}};hr(Go,"CONTEXTUAL_KEYWORDS",new Set(["type","method","enum"]));var i0=Go,s0=Object.defineProperty,a0=(t,e,r)=>e in t?s0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,It=(t,e,r)=>a0(t,typeof e!="symbol"?e+"":e,r),o0=new Set(ws),es=class{constructor(e={}){It(this,"indent"),It(this,"indentStr"),It(this,"output"),It(this,"sourceCode"),It(this,"sourceLines"),It(this,"lastCommentedLine"),It(this,"includeSourceComments"),It(this,"paramRenameCounter"),It(this,"functionParams"),this.indent=0,this.indentStr=e.indentStr||" ",this.output=[],this.sourceCode=e.sourceCode||null,this.sourceLines=this.sourceCode?this.sourceCode.split(`\n`):[],this.lastCommentedLine=-1,this.includeSourceComments=e.includeSourceComments||!1,this.paramRenameCounter=0,this.functionParams=new Map}generate(e){if(this.output=[],this.indent=0,this.lastCommentedLine=-1,this.functionParams=new Map,e.type==="Program")this.preProcessAST(e),this.generateProgram(e);else throw new Error(`Expected Program node, got ${e.type}`);return this.output.join("")}preProcessAST(e){this.collectFunctionParams(e),this.renameConflictingVariables(e)}renameConflictingVariables(e){let r=new Map;this.collectConflictingVarNames(e,r),r.size>0&&this.renameVariableRefsInAST(e,r)}isReservedName(e){return!!e&&(__.has(e)||ha.has(e))}collectConflictingVarNames(e,r){if(!(!e||typeof e!="object")){if(e.type==="VariableDeclaration"){for(let n of e.declarations)if(n.id?.type==="Identifier"&&this.isReservedName(n.id.name)&&!r.has(n.id.name)&&r.set(n.id.name,`${n.id.name}_$${this.paramRenameCounter++}`),n.id?.type==="ArrayPattern")for(let i of n.id.elements)i?.type==="Identifier"&&this.isReservedName(i.name)&&!r.has(i.name)&&r.set(i.name,`${i.name}_$${this.paramRenameCounter++}`)}(e.type==="AssignmentExpression"||e.type==="ReassignmentExpression")&&e.left?.type==="Identifier"&&this.isReservedName(e.left.name)&&!r.has(e.left.name)&&r.set(e.left.name,`${e.left.name}_$${this.paramRenameCounter++}`),e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"&&!e.id.isMethod&&this.isReservedName(e.id.name)&&!r.has(e.id.name)&&r.set(e.id.name,`${e.id.name}_$${this.paramRenameCounter++}`);for(let n of Object.keys(e)){if(n==="type")continue;let i=e[n];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.collectConflictingVarNames(s,r);else i&&typeof i=="object"&&i.type&&this.collectConflictingVarNames(i,r)}}}renameVariableRefsInAST(e,r){if(!(!e||typeof e!="object")){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&r.has(e.callee.name)?ha.has(e.callee.name)&&(e.callee.name=r.get(e.callee.name)):this.renameVariableRefsInAST(e.callee,r),e.arguments)for(let n of e.arguments)this.renameVariableRefsInAST(n,r);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&r.has(e.object.name))return;if(!e.computed&&e.property?.type==="Identifier"&&r.has(e.property.name)){this.renameVariableRefsInAST(e.object,r);return}this.renameVariableRefsInAST(e.object,r),e.computed&&this.renameVariableRefsInAST(e.property,r);return}if(e.type==="Property"){this.renameVariableRefsInAST(e.value,r);return}if(e.type==="Identifier"&&r.has(e.name)){e.name=r.get(e.name);return}for(let n of Object.keys(e)){if(n==="type")continue;let i=e[n];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameVariableRefsInAST(s,r);else i&&typeof i=="object"&&i.type&&this.renameVariableRefsInAST(i,r)}}}collectFunctionParams(e){if(!(!e||typeof e!="object")){if(e.type==="FunctionDeclaration"&&e.id?.name){let r=[];for(let n of e.params)n.type==="Identifier"?r.push(n.name):n.type==="AssignmentPattern"&&n.left?.name&&r.push(n.left.name);this.functionParams.set(e.id.name,r)}if(Array.isArray(e.body))for(let r of e.body)this.collectFunctionParams(r);else e.body&&typeof e.body=="object"&&this.collectFunctionParams(e.body)}}writeSourceComment(e,r=null){if(!this.sourceLines.length)return;let n=r||e,i=[];for(let s=e-1;s<n&&s<this.sourceLines.length;s++)if(s>this.lastCommentedLine){let a=this.sourceLines[s].trim();a&&!a.startsWith("//@")&&!a.startsWith("//")&&i.push(this.sourceLines[s])}if(i.length>0){for(let s of i)this.write(this.indentStr.repeat(this.indent)),this.write("/// "),this.write(s.trimEnd()),this.write(`\n`);this.lastCommentedLine=Math.max(this.lastCommentedLine,n-1)}}write(e){this.output.push(e)}writeLine(e=""){e?this.output.push(this.indentStr.repeat(this.indent)+e+`\n`):this.output.push(`\n`)}increaseIndent(){this.indent++}decreaseIndent(){this.indent--}generateProgram(e){for(let r=0;r<e.body.length;r++)if(this.generateStatement(e.body[r]),r<e.body.length-1){let n=e.body[r],i=e.body[r+1];(n.type==="FunctionDeclaration"||n.type==="TypeDefinition")&&(i.type==="FunctionDeclaration"||i.type==="TypeDefinition")&&this.writeLine()}}generateStatement(e){switch(this.includeSourceComments&&e._line&&this.sourceLines.length>0&&this.writeSourceComment(e._line),e.type){case"FunctionDeclaration":return this.generateFunctionDeclaration(e);case"VariableDeclaration":return this.generateVariableDeclaration(e);case"ExpressionStatement":return this.generateExpressionStatement(e);case"IfStatement":return this.generateIfStatement(e);case"ForStatement":return this.generateForStatement(e);case"WhileStatement":return this.generateWhileStatement(e);case"ReturnStatement":return this.generateReturnStatement(e);case"BlockStatement":return this.generateBlockStatement(e);case"TypeDefinition":return this.generateTypeDefinition(e);default:throw new Error(`Unknown statement type: ${e.type}`)}}generateTypeDefinition(e){if(this.write(this.indentStr.repeat(this.indent)),this.write(`const ${e.name} = Type({`),e.fields.length>0){this.write(" ");for(let r=0;r<e.fields.length;r++){let n=e.fields[r];n.defaultValue?(this.write(`${n.name}: [\'${n.type}\', `),this.generateExpression(n.defaultValue),this.write("]")):this.write(`${n.name}: \'${n.type}\'`),r<e.fields.length-1&&this.write(", ")}this.write(" ")}this.write(`});\n`)}renameIdentifiersInAST(e,r){if(!(!e||typeof e!="object")){if(e.type==="Identifier"&&r.has(e.name)){e.name=r.get(e.name);return}if(e.type!=="FunctionDeclaration")for(let n of Object.keys(e)){if(n==="type")continue;let i=e[n];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameIdentifiersInAST(s,r);else i&&typeof i=="object"&&i.type&&this.renameIdentifiersInAST(i,r)}}}renameParamRefsInBody(e,r){if(!(!e||typeof e!="object")&&e.type!=="FunctionDeclaration"){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&r.has(e.callee.name)||this.renameParamRefsInBody(e.callee,r),e.arguments)for(let n of e.arguments)this.renameParamRefsInBody(n,r);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&r.has(e.object.name))return;this.renameParamRefsInBody(e.object,r),e.computed&&this.renameParamRefsInBody(e.property,r);return}if(e.type==="Property"){this.renameParamRefsInBody(e.value,r);return}if(e.type==="Identifier"&&r.has(e.name)){e.name=r.get(e.name);return}for(let n of Object.keys(e)){if(n==="type")continue;let i=e[n];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameParamRefsInBody(s,r);else i&&typeof i=="object"&&i.type&&this.renameParamRefsInBody(i,r)}}}generateFunctionDeclaration(e){this.write(this.indentStr.repeat(this.indent));let r=e.id.isMethod,n=new Map;for(let c of e.params){let u=c.type==="AssignmentPattern"?c.left.name:c.name;if(u&&o0.has(u)){let h=`${u}_$${this.paramRenameCounter++}`;n.set(u,h)}}let i=c=>c.type==="Identifier"&&c.name==="this"||c.type==="AssignmentPattern"&&c.left?.name==="this",s=new Map;if(r&&e.params.length>0&&i(e.params[0])&&s.set("this","self"),n.size>0||s.size>0){for(let c of e.params){let u=c.type==="AssignmentPattern"?c.left:c;if(u?.type==="Identifier"){let h=n.get(u.name)??s.get(u.name);h&&(u.name=h)}c.type==="AssignmentPattern"&&c.right&&(n.size>0&&this.renameParamRefsInBody(c.right,n),s.size>0&&this.renameIdentifiersInAST(c.right,s))}n.size>0&&this.renameParamRefsInBody(e.body,n),s.size>0&&this.renameIdentifiersInAST(e.body,s)}let a=r?`$M_${e.id.name}`:e.id.name;this.write("function "),this.write(a),this.write("(");let o=e.params;for(let c=0;c<o.length;c++){let u=o[c];u.type==="Identifier"?this.write(u.name):u.type==="AssignmentPattern"&&(this.write(u.left.name),this.write(" = "),this.generateExpression(u.right)),c<o.length-1&&this.write(", ")}this.write(") "),this.generateBlockStatement(e.body,!1),this.write(`\n`),r&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${a}.__pineMethod__ = true;\n`));let l=[];for(let c=0;c<e.params.length;c++){let u=e.params[c],h=u.type==="AssignmentPattern"?u.left?.name:u.name;if(r&&c===0&&h==="self")continue;let p=u.type==="AssignmentPattern"?u.left?.varType:u.varType;h&&p&&l.push([h,p])}if(l.length>0){this.write(this.indentStr.repeat(this.indent));let c=l.map(([u,h])=>`${JSON.stringify(u)}: ${JSON.stringify(h)}`).join(", ");this.write(`${a}.__pineParamTypes__ = {${c}};\n`)}}generateVariableDeclaration(e){let r=e.kind==="var"||e.kind==="varip"?"var":"let";for(let n=0;n<e.declarations.length;n++){let i=e.declarations[n];if(i.init&&i.init.type==="ConditionalExpression"&&i.init.needsIIFE){let o=i.id.type==="Identifier"?i.id.name:null;if(o){this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" "),this.write(o),this.write(`;\n`),this.generateIfStatementWithAssignment(i.init,o);continue}}if(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" "),i.id.type==="Identifier")this.write(i.id.name);else if(i.id.type==="ArrayPattern"){let o=new Set;this.write("[");for(let l=0;l<i.id.elements.length;l++){let c=i.id.elements[l].name;if(o.has(c)){let u=`${c}${this.paramRenameCounter++}`;i.id.elements[l].name=u,c=u}o.add(c),this.write(c),l<i.id.elements.length-1&&this.write(", ")}this.write("]")}i.init&&(this.write(" = "),this.generateExpression(i.init)),this.write(`;\n`);let s=i.id?.varType,a=i.id?.type==="Identifier"?i.id.name:null;a&&typeof s=="string"&&/^[A-Za-z_$][\\w$]*$/.test(s)&&s[0]===s[0].toUpperCase()&&(this.write(this.indentStr.repeat(this.indent)),this.write(`"__pineUdtVar:${a}=${s}";\n`))}}generateExpressionStatement(e){if(e.expression.type==="SwitchExpression"&&e.expression.discriminant===null){this.write(this.indentStr.repeat(this.indent)),this.generateSwitchAsIfElse(e.expression),this.write(`\n`);return}this.write(this.indentStr.repeat(this.indent)),this.generateExpression(e.expression),this.write(`;\n`)}generateIfStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(") "),this.generateBlockStatement(e.consequent,!1),e.alternate?(this.write(" else "),e.alternate.type==="IfStatement"?this.generateIfStatement(e.alternate):this.generateBlockStatement(e.alternate,!1)):this.write(`\n`)}generateIfStatementWithAssignment(e,r){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequentStmts)for(let n=0;n<e.consequentStmts.length;n++){let i=e.consequentStmts[n];n===e.consequentStmts.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternateExpr)this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(e.alternateExpr),this.write(`;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");else if(e.alternateStmts&&e.alternateStmts.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.alternateStmts.length;n++){let i=e.alternateStmts[n];n===e.alternateStmts.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}")}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");this.write(`\n`)}generateNestedIfWithAssignments(e,r){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let n=0;n<e.consequent.body.length;n++){let i=e.consequent.body[n];n===e.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternate)if(e.alternate.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.alternate.test),this.write(`) {\n`),this.indent++,e.alternate.consequent.type==="BlockStatement"&&e.alternate.consequent.body.length>0)for(let n=0;n<e.alternate.consequent.body.length;n++){let i=e.alternate.consequent.body[n];n===e.alternate.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternatesWithAssignments(e.alternate.alternate,r)}else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.alternate.body.length;n++){let i=e.alternate.body[n];n===e.alternate.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`);else this.write(`\n`)}generateNestedIfAlternatesWithAssignments(e,r){if(e)if(e.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let n=0;n<e.consequent.body.length;n++){let i=e.consequent.body[n];n===e.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternatesWithAssignments(e.alternate,r)}else if(e.type==="BlockStatement"&&e.body.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.body.length;n++){let i=e.body[n];n===e.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}generateForStatement(e){if(this.write(this.indentStr.repeat(this.indent)),e.isForIn){if(this.write("for ("),e.init&&e.init.type==="VariableDeclaration"){let r=e.init.declarations[0];if(this.write(`${e.init.kind} `),r.id.type==="Identifier")this.write(r.id.name);else if(r.id.type==="ArrayPattern"){let n=new Set;this.write("[");for(let i=0;i<r.id.elements.length;i++){let s=r.id.elements[i].name;if(n.has(s)){let a=`${s}${this.paramRenameCounter++}`;r.id.elements[i].name=a,s=a}n.add(s),this.write(s),i<r.id.elements.length-1&&this.write(", ")}this.write("]")}this.write(" of "),this.generateExpression(r.init)}this.write(") "),this.generateBlockStatement(e.body,!1);return}if(this.write("for ("),e.init)if(e.init.type==="VariableDeclaration"){let r=e.init.declarations[0];this.write(`${e.init.kind} ${r.id.name}`),r.init&&(this.write(" = "),this.generateExpression(r.init))}else this.generateExpression(e.init);this.write("; "),e.test&&this.generateExpression(e.test),this.write("; "),e.update&&(e.update.type==="AssignmentExpression"?(this.generateExpression(e.update.left),this.write(` ${e.update.operator} `),this.generateExpression(e.update.right)):this.generateExpression(e.update)),this.write(") "),this.generateBlockStatement(e.body,!1)}generateWhileStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("while ("),this.generateExpression(e.test),this.write(") "),this.generateBlockStatement(e.body,!1)}generateReturnStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("return"),e.argument&&(this.write(" "),this.generateExpression(e.argument)),this.write(`;\n`)}generateBlockStatement(e,r=!0){this.write(`{\n`),r?this.increaseIndent():this.indent++;for(let n of e.body)this.generateStatement(n);r?this.decreaseIndent():this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),r&&this.write(`\n`)}generateExpression(e){switch(e.type){case"Identifier":return this.write(e.name);case"Literal":return this.generateLiteral(e);case"BinaryExpression":case"LogicalExpression":return this.generateBinaryExpression(e);case"UnaryExpression":return this.generateUnaryExpression(e);case"AssignmentExpression":return this.generateAssignmentExpression(e);case"UpdateExpression":return this.generateUpdateExpression(e);case"CallExpression":return this.generateCallExpression(e);case"MemberExpression":return this.generateMemberExpression(e);case"ConditionalExpression":return this.generateConditionalExpression(e);case"ArrayExpression":return this.generateArrayExpression(e);case"ObjectExpression":return this.generateObjectExpression(e);case"SwitchExpression":return this.generateSwitchExpression(e);case"SequenceExpression":return this.generateSequenceExpression(e);case"ForStatement":return this.generateLoopAsExpression(e,"for");case"WhileStatement":return this.generateLoopAsExpression(e,"while");default:throw new Error(`Unknown expression type: ${e.type}`)}}generateLiteral(e){if(typeof e.value=="string"){let r=e.value.replace(/\\\\/g,"\\\\\\\\").replace(/\'/g,"\\\\\'").replace(/\\n/g,"\\\\n").replace(/\\r/g,"\\\\r").replace(/\\t/g,"\\\\t");this.write(`\'${r}\'`)}else if(e.value===null)this.write("null");else{let r=String(e.value);typeof e.raw=="string"&&e.raw.includes(".")&&!/[.eE]/.test(r)?this.write(r+".0"):this.write(r)}}generateBinaryExpression(e){let r=this.getPrecedence(e);this.getPrecedence(e.left)<r?(this.write("("),this.generateExpression(e.left),this.write(")")):this.generateExpression(e.left),this.write(" ");let n=e.operator;n==="and"?n="&&":n==="or"&&(n="||"),this.write(n),this.write(" ");let i=this.getPrecedence(e.right),s=i<r;i===r&&(n==="-"||n==="/"||n==="%")&&(s=!0),s?(this.write("("),this.generateExpression(e.right),this.write(")")):this.generateExpression(e.right)}generateUnaryExpression(e){let r=e.operator;r==="not"&&(r="!"),this.write(r),this.getPrecedence(e.argument)<15||e.argument.type==="UnaryExpression"&&(r==="-"||r==="+")&&(e.argument.operator==="-"||e.argument.operator==="+")?(this.write("("),this.generateExpression(e.argument),this.write(")")):this.generateExpression(e.argument)}generateAssignmentExpression(e){this.generateExpression(e.left),this.write(" ");let r=e.operator;r===":="&&(r="="),this.write(r),this.write(" "),this.generateExpression(e.right)}generateUpdateExpression(e){e.prefix?(this.write(e.operator),this.generateExpression(e.argument)):(this.generateExpression(e.argument),this.write(e.operator))}generateCallExpression(e){this.getPrecedence(e.callee)<19?(this.write("("),this.generateExpression(e.callee),this.write(")")):this.generateExpression(e.callee),this.write("(");let r=e.callee?.type==="Identifier"?e.callee.name:null,n=r?this.functionParams.get(r):null,i=e.arguments.length>0?e.arguments[e.arguments.length-1]:null;if(i?.type==="ObjectExpression"&&n){let s=e.arguments.slice(0,-1),a=new Map;for(let u of i.properties){let h=u.key?.name||u.key?.value;h&&a.set(h,u.value)}let o=[],l=-1;for(let u=0;u<n.length;u++)u<s.length?(o.push(s[u]),l=u):a.has(n[u])?(o.push(a.get(n[u])),l=u):o.push(null);let c=o.slice(0,l+1);for(let u=0;u<c.length;u++)c[u]===null?this.write("undefined"):this.generateExpression(c[u]),u<c.length-1&&this.write(", ")}else for(let s=0;s<e.arguments.length;s++){let a=e.arguments[s];a.type==="AssignmentExpression"&&a.operator==="="?this.generateExpression(a.right):this.generateExpression(a),s<e.arguments.length-1&&this.write(", ")}this.write(")")}generateMemberExpression(e){this.getPrecedence(e.object)<19?(this.write("("),this.generateExpression(e.object),this.write(")")):this.generateExpression(e.object),e.computed?(this.write("["),this.generateExpression(e.property),this.write("]")):(this.write("."),this.generateExpression(e.property))}generateConditionalExpression(e){if(e.needsIIFE){this.generateIIFEConditional(e);return}this.write("("),this.generateExpression(e.test),this.write(" ? "),this.generateExpression(e.consequent),this.write(" : "),this.generateExpression(e.alternate),this.write(")")}generateIIFEConditional(e){this.write(`(() => {\n`),this.indent++,this.generateIIFEIfBlock(e),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateIIFEIfBlock(e){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequentStmts)for(let r=0;r<e.consequentStmts.length;r++){let n=e.consequentStmts[r];r===e.consequentStmts.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternateExpr)this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(e.alternateExpr),this.write(`;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");else if(e.alternateStmts&&e.alternateStmts.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.alternateStmts.length;r++){let n=e.alternateStmts[r];r===e.alternateStmts.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}")}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");this.write(`\n`)}generateNestedIfWithReturns(e){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let r=0;r<e.consequent.body.length;r++){let n=e.consequent.body[r];r===e.consequent.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternate)if(e.alternate.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.alternate.test),this.write(`) {\n`),this.indent++,e.alternate.consequent.type==="BlockStatement"&&e.alternate.consequent.body.length>0)for(let r=0;r<e.alternate.consequent.body.length;r++){let n=e.alternate.consequent.body[r];r===e.alternate.consequent.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternates(e.alternate.alternate)}else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.alternate.body.length;r++){let n=e.alternate.body[r];r===e.alternate.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`);else this.write(`\n`)}generateNestedIfAlternates(e){if(e)if(e.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let r=0;r<e.consequent.body.length;r++){let n=e.consequent.body[r];r===e.consequent.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternates(e.alternate)}else if(e.type==="BlockStatement"&&e.body.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.body.length;r++){let n=e.body[r];r===e.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}generateNestedIfAsExpression(e){if(e.type==="IfStatement"){if(this.write("("),this.generateExpression(e.test),this.write(" ? "),e.consequent.type==="BlockStatement"&&e.consequent.body.length>0){let r=e.consequent.body[e.consequent.body.length-1];r.type==="ExpressionStatement"?this.generateExpression(r.expression):r.type==="IfStatement"&&this.generateNestedIfAsExpression(r)}if(this.write(" : "),e.alternate)if(e.alternate.type==="IfStatement")this.generateNestedIfAsExpression(e.alternate);else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){let r=e.alternate.body[e.alternate.body.length-1];r.type==="ExpressionStatement"&&this.generateExpression(r.expression)}else this.write("false");else this.write("false");this.write(")")}}generateArrayExpression(e){this.write("[");for(let r=0;r<e.elements.length;r++)this.generateExpression(e.elements[r]),r<e.elements.length-1&&this.write(", ");this.write("]")}generateObjectExpression(e){this.write("{");for(let r=0;r<e.properties.length;r++){let n=e.properties[r];n.key.type==="Identifier"?this.write(n.key.name):this.generateExpression(n.key),this.write(": "),this.generateExpression(n.value),r<e.properties.length-1&&this.write(", ")}this.write("}")}generateSwitchExpression(e){if(e.discriminant===null){this.generateSwitchAsIfElseIIFE(e);return}this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write("switch ("),this.generateExpression(e.discriminant),this.write(`) {\n`),this.indent++;for(let r of e.cases){if(this.write(this.indentStr.repeat(this.indent)),r.test?(this.write("case "),this.generateExpression(r.test),this.write(`:\n`)):this.write(`default:\n`),this.indent++,r.statements&&r.statements.length>0){let n=r.statements[r.statements.length-1];if(n.type==="ExpressionStatement"||n.type==="VariableDeclaration"){for(let i=0;i<r.statements.length-1;i++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(r.statements[i]);this.write(this.indentStr.repeat(this.indent)),this.write("return "),n.type==="ExpressionStatement"?this.generateExpression(n.expression):this.generateExpression(r.consequent),this.write(`;\n`)}else{for(let i=0;i<r.statements.length;i++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(r.statements[i]);this.write(this.indentStr.repeat(this.indent)),this.write(`return null;\n`)}}else this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.consequent),this.write(`;\n`);this.indent--}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSwitchAsIfElseIIFE(e){this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent));for(let r=0;r<e.cases.length;r++){let n=e.cases[r];if(n.test?(r===0?this.write("if ("):this.write(" else if ("),this.generateExpression(n.test),this.write(`) {\n`)):r>0?this.write(` else {\n`):this.write(`{\n`),this.indent++,n.statements&&n.statements.length>0){let i=n.statements[n.statements.length-1];if(i.type==="ExpressionStatement"||i.type==="VariableDeclaration"){for(let s=0;s<n.statements.length-1;s++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(n.statements[s]);this.write(this.indentStr.repeat(this.indent)),this.write("return "),i.type==="ExpressionStatement"?this.generateExpression(i.expression):this.generateExpression(n.consequent),this.write(`;\n`)}else{for(let s of n.statements)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(s);this.write(this.indentStr.repeat(this.indent)),this.write(`return null;\n`)}}else this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.consequent),this.write(`;\n`);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),r>=e.cases.length-1&&this.write(`\n`)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSwitchAsIfElse(e){for(let r=0;r<e.cases.length;r++){let n=e.cases[r];if(n.test?(r===0?this.write("if ("):this.write(" else if ("),this.generateExpression(n.test),this.write(`) {\n`)):r>0?this.write(` else {\n`):this.write(`{\n`),this.indent++,n.statements&&n.statements.length>0)for(let i of n.statements)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(i);else this.write(this.indentStr.repeat(this.indent)),this.generateExpression(n.consequent),this.write(`;\n`);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),r<e.cases.length-1||this.write(`\n`)}}generateLoopAsExpression(e,r){this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`let __result;\n`);let n=e.body;if(n&&n.body&&n.body.length>0){let i=n.body.length-1,s=n.body[i];s.type==="ExpressionStatement"&&(n.body[i]={type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:{type:"Identifier",name:"__result"},right:s.expression},_line:s._line})}r==="for"?this.generateForStatement(e):this.generateWhileStatement(e),this.write(this.indentStr.repeat(this.indent)),this.write(`return __result;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSequenceExpression(e){this.write("(");for(let r=0;r<e.expressions.length;r++)this.generateExpression(e.expressions[r]),r<e.expressions.length-1&&this.write(", ");this.write(")")}getPrecedence(e){switch(e.type){case"Literal":case"Identifier":case"ArrayExpression":case"ObjectExpression":return 20;case"CallExpression":case"MemberExpression":return 19;case"UnaryExpression":case"UpdateExpression":return 15;case"BinaryExpression":case"LogicalExpression":switch(e.operator){case"*":case"/":case"%":return 13;case"+":case"-":return 12;case"<":case"<=":case">":case">=":return 10;case"==":case"!=":return 9;case"and":case"&&":return 5;case"or":case"||":return 4;default:return 0}case"ConditionalExpression":return 3;case"AssignmentExpression":case"AssignmentPattern":return 2;case"SequenceExpression":return 1;default:return 0}}};function Yo(t){let e=/^\\s*\\/\\/\\s*@version\\s*=\\s*(\\d+)\\s*$/im,r=t.match(e);return r&&r[1]?parseInt(r[1],10):null}function Ss(t,e={}){let r=Yo(t);if(r===null)return{success:!1,version:null,error:"Pine Script version not found. Please add //@version=X comment to your script."};if(r<5)return{success:!1,version:r,error:`Pine Script version ${r} is not supported. Only version 5 and above are supported.`};try{let n=new qi(t).tokenize(),i=new i0(n).parse(),s={...e,sourceCode:t},a=new es(s).generate(i);return{success:!0,version:r,code:a,ast:i,tokens:n}}catch(n){return{success:!1,version:r,error:n.message,stack:n.stack}}}var l0=new Set(["security_lower_tf","security"]),Zo=new Set(["type","loc","start","end","range","parent","leadingComments","trailingComments"]);function c0(t){if(!t||t.type!=="CallExpression")return!1;let e=t.callee;return!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="request"||e.property?.type!=="Identifier"?!1:l0.has(e.property.name)}function u0(t){let e=t?.arguments?.[2];return e?.type==="Identifier"&&typeof e.name=="string"?e.name:null}function p0(t){let e=[],r=new WeakSet;function n(i,s){if(!i||typeof i!="object"||r.has(i))return;r.add(i);let a=s.concat([i]);c0(i)&&e.push({call:i,path:a});for(let o of Object.keys(i)){if(Zo.has(o))continue;let l=i[o];if(Array.isArray(l))for(let c of l)n(c,a);else l&&typeof l=="object"&&n(l,a)}}return n(t,[]),e}function ts(t){return t?t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="FunctionDeclaration":!1}function Et(t,e,r){if(r>=e.length-1)return t;let n=e[r+1];switch(t.type){case"BlockStatement":{let i=t.body.indexOf(n);if(i<0)return t;let s=t.body.slice(0,i);return s.push(Et(n,e,r+1)),{...t,body:s}}case"IfStatement":return n===t.test?{...t,test:Et(n,e,r+1),consequent:{type:"BlockStatement",body:[]},alternate:null}:n===t.consequent?{...t,consequent:Et(n,e,r+1),alternate:null}:n===t.alternate?{...t,alternate:Et(n,e,r+1)}:t;case"ForStatement":case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return n===t.body?{...t,body:Et(n,e,r+1)}:t;case"SwitchStatement":{let i=t.cases.indexOf(n);if(i>=0){let s=t.cases.slice(0,i);return s.push(Et(n,e,r+1)),{...t,cases:s}}return t}case"SwitchCase":{let i=t.consequent.indexOf(n);if(i>=0){let s=t.consequent.slice(0,i);return s.push(Et(n,e,r+1)),{...t,consequent:s}}return t}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":return n===t.body?{...t,body:Et(n,e,r+1)}:t;default:return t}}function h0(t){if(!t||t.type!=="CallExpression")return null;let e=t.callee;if(!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="$"||e.property?.type!=="Identifier"||e.property.name!=="call")return null;let r=t.arguments?.[0];return r?.type==="Identifier"&&typeof r.name=="string"?r.name:null}function d0(t,e,r){let n=t.body||[];for(let i=0;i<n.length;i++){let s=n[i];if(s!==r&&f0(s,e))return i}return-1}function f0(t,e){let r=!1,n=new WeakSet;function i(s){if(!(r||!s||typeof s!="object")&&!n.has(s)){if(n.add(s),h0(s)===e){r=!0;return}for(let a of Object.keys(s)){if(Zo.has(a))continue;let o=s[a];if(Array.isArray(o))for(let l of o)i(l);else o&&typeof o=="object"&&i(o)}}}return i(t),r}function m0(t,e){let r=-1;for(let p=1;p<e.length;p++)if(ts(e[p])){r=p;break}if(r<0)return null;let n=e[r];for(let p=r+1;p<e.length;p++)if(ts(e[p]))return null;if(n.type!=="FunctionDeclaration"||!n.id?.name)return null;let i=n.id.name,s=e.slice(r),a=Et(n,s,0),o=d0(t,i,n);if(o<0)return null;let l=t.body||[],c=l.indexOf(n);if(c<0)return null;let u=[],h=Math.max(o,c);for(let p=0;p<=h;p++){let d=l[p];u.push(d===n?a:d)}return u}function y0(t,e){let r={type:"Program",sourceType:"module",body:[{type:"ExpressionStatement",expression:{type:"ArrowFunctionExpression",async:!!t.async,params:t.params,body:{type:"BlockStatement",body:e}}}]},n=`var _r = ${bs(r)}\n; return _r;`;return new Function("",n)()}function g0(t){let e={};if(!t||t.type!=="Program"||!Array.isArray(t.body)||t.body.length===0)return e;let r=t.body[0],n=null;if(r.type==="ExpressionStatement"){let s=r.expression;s&&(s.type==="ArrowFunctionExpression"||s.type==="FunctionExpression")&&(n=s)}else r.type==="FunctionDeclaration"&&(n=r);if(!n||n.body?.type!=="BlockStatement")return e;let i=p0(n.body);for(let{call:s,path:a}of i){let o=u0(s);if(!o||o in e)continue;let l=a.some(h=>ts(h)),c=null;if(l)c=m0(n.body,a);else{let h=Et(n.body,a,0);c=h&&h.body?h.body:[]}if(!c||c.length===0)continue;let u=y0(n,c);e[o]=u}return e}function _0(t){if(typeof t=="function")return t.toString();{let e=Yo(t);if(e===null)return t;if(e>=5){let r=Ss(t);if(r.success)return r.code;throw new Error(`Failed to transpile Pine Script version ${e}: ${r.error}`)}else throw new Error(`Unsupported Pine Script version ${e}. Only version 5 and above are supported.`)}}function x0(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});let{debug:r}=e,n=_0(t);n=S_(n);let i=r?n.split(`\n`):[],s=_s(n,{ecmaVersion:"latest",sourceType:"module",locations:r});C_(s),v_(s),b_(s);let a=new Vi;I_(s,a),N_(s,a);let o=T_(s,a)||"";if(O_(s),Y_(s,a,o,e,i),G_(s),q_(s),s.type==="Program"&&s.body.length>0){let d=s.body[0],f=d?.expression||d;f.body?.type==="BlockStatement"&&f.body.body.unshift({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"__maxLoops"},init:{type:"LogicalExpression",operator:"||",left:{type:"MemberExpression",object:{type:"Identifier",name:"$"},property:{type:"Identifier",name:"__maxLoops"},computed:!1},right:{type:"Literal",value:5e5}}}]})}let l=c_||xs||void 0,c=Object.assign({},l,{LineComment(d,f){f.write("//"+d.value)}}),u=bs(s,{generator:c,comments:r}),h=typeof process<"u"&&process?.env?.PINETS_DISABLE_LTF_SLICING==="1"?{}:g0(s),p=new Function("",`var _r = ${u}\n; return _r;`)(this);return h&&Object.keys(h).length>0&&(p._ltfSlices=h),p}var Xo=new Set(["open","high","low","close","hl2","hlc3","ohlc4","hlcc4","volume"]),da={"":["defval","title","tooltip","inline","group","display","active"],bool:["defval","title","tooltip","inline","group","confirm","display","active"],color:["defval","title","tooltip","inline","group","confirm","display","active"],enum:["defval","title","options","tooltip","inline","group","confirm","display","active"],price:["defval","title","tooltip","inline","group","confirm","display","active"],session:["defval","title","options","tooltip","inline","group","confirm","display","active"],source:["defval","title","tooltip","inline","group","display","active","confirm"],string:["defval","title","options","tooltip","inline","group","confirm","display","active"],symbol:["defval","title","tooltip","inline","group","confirm","display","active"],text_area:["defval","title","tooltip","group","confirm","display","active"],time:["defval","title","tooltip","inline","group","confirm","display","active"],timeframe:["defval","title","options","tooltip","inline","group","confirm","display","active"]},b0={bool:"bool",color:"color",enum:"enum",float:"float",int:"int",price:"price",session:"session",source:"source",string:"string",symbol:"symbol",text_area:"text_area",time:"time",timeframe:"timeframe"};function v0(t){if(typeof t!="string")return[];let e=Ss(t);if(!e.success||!e.ast)return[];let r=w0(e.ast),n=E0(e.ast),i=[],s=new Set;return Dt(e.ast,a=>{let o=S0(a,r,n);if(o){if(o.varId!==void 0){if(s.has(o.varId)){console.warn(`[Indicator] duplicate input variable "${o.varId}" \\u2014 first declaration wins for .input access`);return}s.add(o.varId)}i.push(o)}}),i}function w0(t){let e=new Map;return Dt(t,r=>{if(r.type==="VariableDeclaration")for(let n of r.declarations??[]){let i=n?.id?.name,s=n?.init;if(!i||!s||s.type!=="ObjectExpression"||!(s.properties??[]).every(a=>a.value?.type==="Literal"&&typeof a.value.value=="string")||s.properties.length===0)return;for(let a of s.properties)e.set(`${i}.${a.key.name}`,a.value.value)}}),e}function E0(t){let e=new Map;return Dt(t,r=>{if(r.type==="VariableDeclaration")for(let n of r.declarations??[])n?.id?.type==="Identifier"&&n.init&&!e.has(n.id.name)&&e.set(n.id.name,n.init)}),e}function S0(t,e,r){if(t.type!=="VariableDeclaration")return null;for(let n of t.declarations??[]){let i=n?.init;if(!i||i.type!=="CallExpression")continue;let s=i.callee,a=null;if(s?.type==="MemberExpression"&&s.object?.type==="Identifier"&&s.object.name==="input"&&s.property?.type==="Identifier"?a=s.property.name:s?.type==="Identifier"&&s.name==="input"&&(a=""),a===null||a!==""&&!(a==="int"||a==="float")&&!(a in da))continue;let o=i.arguments??[],l=o[o.length-1],c=l?.type==="ObjectExpression",u=c?o.slice(0,-1):o.slice(),h=c?l.properties??[]:[],p={};a==="int"||a==="float"?C0(u,h,p):Qo(da[a],u,p);for(let x of h)x.type!=="Property"||!x.key?.name||(p[x.key.name]=x.value);let d={};for(let x of Object.keys(p))d[x]=ln(p[x],e,r);let f=a===""?N0(d.defval):b0[a];if(!f)continue;let m={type:f,defval:d.defval};return n.id?.type==="Identifier"&&typeof n.id.name=="string"&&(m.varId=n.id.name),d.title!==void 0&&(m.title=String(d.title)),d.tooltip!==void 0&&(m.tooltip=String(d.tooltip)),d.group!==void 0&&(m.group=String(d.group)),d.inline!==void 0&&(m.inline=String(d.inline)),d.confirm!==void 0&&(m.confirm=!!d.confirm),d.active!==void 0&&(m.active=!!d.active),d.display!==void 0&&(m.display=k0(d.display)),d.options!==void 0&&Array.isArray(d.options)&&(m.options=d.options),typeof d.minval=="number"&&(m.minval=d.minval),typeof d.maxval=="number"&&(m.maxval=d.maxval),typeof d.step=="number"&&(m.step=d.step),m}return null}function C0(t,e,r){let n=new Set(e.map(i=>i.key?.name).filter(Boolean)).has("options")||t[2]?.type==="ArrayExpression"?["defval","title","options","tooltip","inline","group","confirm","display","active"]:["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display","active"];Qo(n,t,r)}function Qo(t,e,r){for(let n=0;n<e.length&&n<t.length;n++){let i=t[n];r[i]===void 0&&(r[i]=e[n])}}function ln(t,e,r,n=new Set){if(t!=null)switch(t.type){case"Literal":return t.value;case"Identifier":if(Xo.has(t.name))return t.name;if(r?.has(t.name)&&!n.has(t.name)){n.add(t.name);let i=ln(r.get(t.name),e,r,n);if(n.delete(t.name),i!==void 0)return i}return t.name;case"MemberExpression":{let i=t.object?.type==="Identifier"?t.object.name:null,s=t.property?.type==="Identifier"?t.property.name:null;if(i&&s){let a=`${i}.${s}`;return e.has(a)?e.get(a):i==="display"?s:a}return}case"CallExpression":{let i=t.callee;if(i?.type==="MemberExpression"&&i.object?.type==="Identifier"&&i.object.name==="color"&&i.property?.type==="Identifier"){let s=i.property.name,a=(t.arguments??[]).map(l=>ln(l,e,r,n)),o=l=>Math.max(0,Math.min(1,l));if(s==="rgb"){let[l,c,u,h]=a;if(typeof l=="number"&&typeof c=="number"&&typeof u=="number"){let p=o(1-(typeof h=="number"?h:0)/100);return mi(l,c,u,p)}}else if(s==="new"){let l=Ha(a[0]),c=a[1];if(l&&typeof c=="number")return mi(l[0],l[1],l[2],o(1-c/100))}}return}case"ArrayExpression":return(t.elements??[]).map(i=>ln(i,e,r,n));case"UnaryExpression":return t.operator==="-"&&t.argument?.type==="Literal"&&typeof t.argument.value=="number"?-t.argument.value:void 0;default:return}}function N0(t){return typeof t=="boolean"?"bool":typeof t=="number"?Number.isInteger(t)?"int":"float":typeof t=="string"?Xo.has(t)?"source":t.startsWith("#")?"color":"string":null}function k0(t){if(typeof t!="string")return;let e=t.startsWith("display.")?t.slice(8):t;if(e==="none"||e==="data_window"||e==="status_line"||e==="all")return e}function Dt(t,e){if(!(!t||typeof t!="object")){if(e(t),Array.isArray(t.body))for(let r of t.body)Dt(r,e);else t.body&&Dt(t.body,e);if(Array.isArray(t.consequent))for(let r of t.consequent)Dt(r,e);else t.consequent&&Dt(t.consequent,e);if(t.alternate&&Dt(t.alternate,e),Array.isArray(t.declarations))for(let r of t.declarations)Dt(r,e)}}function Jo(t,e,r,n,i="key"){let s={},a=new Map;for(let o of t)a.set(o.key,o),s[o.key]=n&&o.key in n?n[o.key]:o.defval;for(let o of t)for(let l of o.aliases??[])!l||a.has(l)||a.set(l,o);return{proxy:new Proxy(s,{get(o,l){if(typeof l=="symbol")return o[l];let c=a.get(l);return c?o[c.key]:o[l]},set(o,l,c){if(typeof l!="string")return!1;let u=a.get(l);if(!u)throw new Error(`[${e}] unknown ${i} "${l}". Known: ${[...a.keys()].join(", ")||"(none)"}`);return I0(u,c,e),o[u.key]=c,r?.(u.key),!0},deleteProperty(o,l){throw new Error(`[${e}] cannot delete "${String(l)}" \\u2014 keys are fixed by the script\'s source.`)},defineProperty(){throw new Error(`[${e}] cannot define new properties \\u2014 keys are fixed by the script\'s source.`)},ownKeys(o){return Reflect.ownKeys(o)},getOwnPropertyDescriptor(o,l){return Reflect.getOwnPropertyDescriptor(o,l)},has(o,l){return typeof l=="string"&&a.has(l)}}),values:s,entryByKey:a}}function I0(t,e,r){let n=t.key;switch(t.type){case"int":if(typeof e!="number"||!Number.isInteger(e))throw new TypeError(`[${r}] "${n}" expects an int; got ${pr(e)}`);break;case"float":case"price":case"time":if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`[${r}] "${n}" expects a number; got ${pr(e)}`);break;case"bool":if(typeof e!="boolean")throw new TypeError(`[${r}] "${n}" expects a boolean; got ${pr(e)}`);break;case"string":case"session":case"symbol":case"timeframe":case"text_area":case"color":case"enum":case"source":if(typeof e!="string")throw new TypeError(`[${r}] "${n}" expects a string; got ${pr(e)}`);break}if(t.options&&!t.options.some(i=>A0(i,e)))throw new RangeError(`[${r}] "${n}" value ${pr(e)} is not one of: ${t.options.map(pr).join(", ")}`);if(typeof e=="number"){if(typeof t.minval=="number"&&e<t.minval)throw new RangeError(`[${r}] "${n}" value ${e} is below minval ${t.minval}`);if(typeof t.maxval=="number"&&e>t.maxval)throw new RangeError(`[${r}] "${n}" value ${e} is above maxval ${t.maxval}`)}}function A0(t,e){return t===e?!0:typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<1e-12:!1}function pr(t){return t===null?"null":typeof t=="string"?JSON.stringify(t):String(t)}function T0(t,e){let r=new Map,n=[];for(let a of t){let o=a.varId??a.title;if(!o)continue;let l=a.title&&a.title!==o?[a.title]:void 0;r.set(o,a),n.push({key:o,type:a.type,defval:a.defval,options:a.options,minval:a.minval,maxval:a.maxval,aliases:l})}let{proxy:i,values:s}=Jo(n,"Indicator.input",e,void 0,"input key");return{proxy:i,values:s,metaByKey:r}}var el=[{name:"title",type:"string",defval:"",mutable:!1,appliesTo:"both"},{name:"shorttitle",type:"string",defval:"",mutable:!1,appliesTo:"both"},{name:"overlay",type:"bool",defval:!1,mutable:!0,appliesTo:"both"},{name:"format",type:"enum",defval:"inherit",options:["inherit","price","volume","percent","mintick"],mutable:!0,appliesTo:"both"},{name:"precision",type:"int",defval:10,minval:0,maxval:16,mutable:!0,appliesTo:"both"},{name:"scale",type:"enum",defval:"right",options:["right","left","none"],mutable:!0,appliesTo:"both"},{name:"max_bars_back",type:"int",defval:0,minval:0,maxval:5e3,mutable:!0,appliesTo:"both"},{name:"explicit_plot_zorder",type:"bool",defval:!1,mutable:!0,appliesTo:"both"},{name:"max_lines_count",type:"int",defval:50,minval:1,maxval:500,mutable:!0,appliesTo:"both"},{name:"max_labels_count",type:"int",defval:50,minval:1,maxval:500,mutable:!0,appliesTo:"both"},{name:"max_boxes_count",type:"int",defval:50,minval:1,maxval:500,mutable:!0,appliesTo:"both"},{name:"calc_bars_count",type:"int",defval:0,minval:0,mutable:!0,appliesTo:"both"},{name:"max_polylines_count",type:"int",defval:50,minval:1,maxval:100,mutable:!0,appliesTo:"both"},{name:"dynamic_requests",type:"bool",defval:!0,mutable:!0,appliesTo:"both",version:6},{name:"behind_chart",type:"bool",defval:!0,mutable:!0,appliesTo:"both",version:6}],tl=[...el.filter(t=>t.appliesTo==="both").map(t=>({...t,appliesTo:"indicator"})),{name:"timeframe",type:"string",defval:"",mutable:!0,appliesTo:"indicator"},{name:"timeframe_gaps",type:"bool",defval:!0,mutable:!0,appliesTo:"indicator"}],rl=[...el.filter(t=>t.appliesTo==="both").map(t=>({...t,appliesTo:"strategy"})),{name:"pyramiding",type:"int",defval:0,minval:0,mutable:!0,appliesTo:"strategy"},{name:"calc_on_order_fills",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"},{name:"calc_on_every_tick",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"},{name:"backtest_fill_limits_assumption",type:"int",defval:0,minval:0,mutable:!0,appliesTo:"strategy"},{name:"default_qty_type",type:"enum",defval:"fixed",options:["fixed","cash","percent_of_equity"],mutable:!0,appliesTo:"strategy"},{name:"default_qty_value",type:"float",defval:1,minval:0,mutable:!0,appliesTo:"strategy"},{name:"initial_capital",type:"float",defval:1e6,minval:0,mutable:!0,appliesTo:"strategy"},{name:"currency",type:"enum",defval:"USD",options:["AED","ARS","AUD","BDT","BHD","BRL","BTC","CAD","CHF","CLP","CNY","COP","CZK","DKK","EGP","ETH","EUR","GBP","HKD","HUF","IDR","ILS","INR","ISK","JPY","KES","KRW","KWD","LKR","MAD","MXN","MYR","NGN","NOK","NONE","NZD","PEN","PHP","PKR","PLN","QAR","RON","RSD","RUB","SAR","SEK","SGD","THB","TND","TRY","TWD","USD","USDT","VES","VND","ZAR"],mutable:!0,appliesTo:"strategy"},{name:"slippage",type:"int",defval:0,minval:0,mutable:!0,appliesTo:"strategy"},{name:"commission_type",type:"enum",defval:"percent",options:["percent","cash_per_contract","cash_per_order"],mutable:!0,appliesTo:"strategy"},{name:"commission_value",type:"float",defval:0,minval:0,mutable:!0,appliesTo:"strategy"},{name:"process_orders_on_close",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"},{name:"close_entries_rule",type:"enum",defval:"FIFO",options:["FIFO","ANY"],mutable:!0,appliesTo:"strategy"},{name:"margin_long",type:"float",defval:100,minval:0,maxval:100,mutable:!0,appliesTo:"strategy"},{name:"margin_short",type:"float",defval:100,minval:0,maxval:100,mutable:!0,appliesTo:"strategy"},{name:"risk_free_rate",type:"float",defval:2,mutable:!0,appliesTo:"strategy"},{name:"use_bar_magnifier",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"},{name:"fill_orders_on_standard_ohlc",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"}];function D0(t){return t==="strategy"?rl:tl}function M0(t){return typeof t=="string"?P0(t):typeof t=="function"?R0(t):{type:null,args:{}}}function P0(t){let e=Ss(t);if(!e.success||!e.ast)return{type:null,args:{}};let r=null;return Ln(e.ast,n=>{if(r||n.type!=="ExpressionStatement"&&n.type!=="VariableDeclaration")return;let i=n.type==="ExpressionStatement"?n.expression:n.declarations?.[0]?.init;if(!i||i.type!=="CallExpression")return;let s=i.callee;s?.type==="Identifier"&&(s.name!=="indicator"&&s.name!=="strategy"||(r={type:s.name,args:il(i.arguments??[],nl(s.name))}))}),r??{type:null,args:{}}}function R0(t){let e;try{e=_s(`(${t.toString()})`,{ecmaVersion:"latest"})}catch{return{type:null,args:{}}}let r=null;return Ln(e,n=>{if(r||n.type!=="CallExpression")return;let i=n.callee;i?.type==="Identifier"&&(i.name!=="indicator"&&i.name!=="strategy"||(r={type:i.name,args:il(n.arguments??[],nl(i.name))}))}),r??{type:null,args:{}}}function nl(t){return t==="strategy"?rl:tl}function il(t,e){let r={},n=t[t.length-1],i=n?.type==="ObjectExpression",s=i?t.slice(0,-1):t.slice();for(let a=0;a<s.length&&a<e.length;a++){let o=e[a].name;r[o]=rs(s[a])}if(i)for(let a of n.properties??[])a.type!=="Property"||!a.key?.name||(r[a.key.name]=rs(a.value));return r}function rs(t){if(t!=null)switch(t.type){case"Literal":return t.value;case"Identifier":return t.name;case"MemberExpression":{let e=t;for(;e?.type==="MemberExpression";)e=e.property;return e?.type==="Identifier"?e.name:void 0}case"UnaryExpression":return t.operator==="-"&&t.argument?.type==="Literal"&&typeof t.argument.value=="number"?-t.argument.value:void 0;case"ArrayExpression":return(t.elements??[]).map(rs);default:return}}function Ln(t,e){if(!(!t||typeof t!="object")){e(t);for(let r of Object.keys(t)){let n=t[r];if(!(r==="loc"||r==="range"||r==="start"||r==="end"))if(Array.isArray(n))for(let i of n)Ln(i,e);else n&&typeof n=="object"&&typeof n.type=="string"&&Ln(n,e)}}}function F0(t,e,r){let n=new Map,i=[];for(let o of t)n.set(o.name,o),o.mutable&&i.push({key:o.name,type:o.type,defval:o.defval,options:o.options,minval:o.minval,maxval:o.maxval});let{proxy:s,values:a}=Jo(i,"Indicator.prop",r,e);return{proxy:s,values:a,propByName:n}}var B0=Object.defineProperty,L0=(t,e,r)=>e in t?B0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ge=(t,e,r)=>L0(t,typeof e!="symbol"?e+"":e,r),Qt=class t{constructor(e,r={}){Ge(this,"source"),Ge(this,"inputs"),Ge(this,"_prepared",null),Ge(this,"_inputMeta",null),Ge(this,"_inputValues",{}),Ge(this,"_explicitOverrides",new Set),Ge(this,"_inputProxy",null),Ge(this,"_propMeta",null),Ge(this,"_propValues",{}),Ge(this,"_propProxy",null),Ge(this,"_declarationType",null),Ge(this,"_sourcePropArgs",{}),Ge(this,"_explicitPropOverrides",new Set),this.source=e,this.inputs=r,Object.defineProperty(this,"input",{get:()=>this._getInputProxy(),set:()=>{throw new Error(\'[Indicator] .input cannot be replaced \\u2014 mutate individual keys (e.g. ind.input["My Title"] = 20).\')},enumerable:!0,configurable:!1}),Object.defineProperty(this,"prop",{get:()=>this._getPropProxy(),set:()=>{throw new Error(\'[Indicator] .prop cannot be replaced \\u2014 mutate individual keys (e.g. ind.prop["initial_capital"] = 50000).\')},enumerable:!0,configurable:!1})}static from(e){return e instanceof t?e:new t(e)}prepare(e={}){if(this._prepared)return this._prepared;let r=x0(this.source,{debug:!!e.debug,ln:e.ln}),n=O0(r),i=r._ltfSlices;return this._prepared={fn:r,inputs:this.getRuntimeInputs(),usesVisibleRange:n,ltfSlices:i},this._prepared}usesVisibleRange(){return this.prepare().usesVisibleRange}getRuntimeInputs(){let e={...this.inputs??{}};if(this._inputMeta)for(let r of this._explicitOverrides)e[r]=this._inputValues[r];return e}getInputsMeta(){return this._ensureInputsScanned(),this._inputMeta}getPropsMeta(){return this._ensurePropsScanned(),this._propMeta}getRuntimePropOverrides(){let e={};if(this._propMeta)for(let r of this._explicitPropOverrides)e[r]=this._propValues[r];return e}getDeclarationType(){return this._ensurePropsScanned(),this._declarationType}_ensureInputsScanned(){if(this._inputMeta)return;this._inputMeta=v0(this.source);for(let r of this._inputMeta)r.type==="color"&&r.defval!==void 0&&(r.defval=Ip(r.defval));let e=T0(this._inputMeta,r=>this._explicitOverrides.add(r));this._inputValues=e.values,this._inputProxy=e.proxy}_getInputProxy(){return this._ensureInputsScanned(),this._inputProxy}_ensurePropsScanned(){if(this._propMeta)return;let e=M0(this.source);this._declarationType=e.type,this._sourcePropArgs=e.args,this._propMeta=D0(e.type);let r=F0(this._propMeta,this._sourcePropArgs,n=>this._explicitPropOverrides.add(n));this._propValues=r.values,this._propProxy=r.proxy}_getPropProxy(){return this._ensurePropsScanned(),this._propProxy}};function O0(t){let e=t.toString();return y_.some(r=>{let n=r.replace(/\\./g,"\\\\.");return new RegExp(`\\\\b${n}\\\\b`).test(e)})}var V0=Object.defineProperty,j0=(t,e,r)=>e in t?V0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ae=(t,e,r)=>j0(t,typeof e!="symbol"?e+"":e,r),fa={1:6e4,3:18e4,5:3e5,15:9e5,30:18e5,60:36e5,120:72e5,180:108e5,240:144e5,"4H":144e5,"1D":864e5,D:864e5,"1W":6048e5,W:6048e5,"1M":30*864e5,M:30*864e5};function $0(t){return t?fa[t]??fa[t.toUpperCase()]??864e5:864e5}var Wt=class{constructor(e,r,n,i,s,a){this.source=e,this.tickerId=r,this.timeframe=n,this.limit=i,this.sDate=s,this.eDate=a,ae(this,"data",[]),ae(this,"open",[]),ae(this,"high",[]),ae(this,"low",[]),ae(this,"close",[]),ae(this,"volume",[]),ae(this,"hl2",[]),ae(this,"hlc3",[]),ae(this,"ohlc4",[]),ae(this,"hlcc4",[]),ae(this,"openTime",[]),ae(this,"closeTime",[]),ae(this,"_readyPromise",null),ae(this,"_ready",!1),ae(this,"_debugSettings",{ln:!1,debug:!1}),ae(this,"_transpiledCode",null),ae(this,"_currentIndicator",null),ae(this,"_isSecondaryContext",!1),ae(this,"_syminfo"),ae(this,"_chartTimezone",null),ae(this,"_maxLoops",5e5),ae(this,"_alertMode","realtime"),ae(this,"_viewportLeft"),ae(this,"_viewportRight"),ae(this,"_usesVisibleRange",!1),ae(this,"_lastRunViewport",{}),ae(this,"_lastResult",null),ae(this,"_lastPineTSCode",null),this._readyPromise=new Promise(o=>{this.loadMarketData(e,r,n,i,s,a).then(l=>{let c=l;this.data=c;let u=c.map(C=>C.open),h=c.map(C=>C.close),p=c.map(C=>C.high),d=c.map(C=>C.low),f=c.map(C=>C.volume),m=c.map(C=>(C.high+C.low+C.close)/3),x=c.map(C=>(C.high+C.low)/2),b=c.map(C=>(C.high+C.low+C.open+C.close)/4),w=c.map(C=>(C.high+C.low+C.close+C.close)/4),v=c.map(C=>C.openTime),E=$0(this.timeframe),A=c.map(C=>C.closeTime!=null?C.closeTime:C.openTime+E);this.open=u,this.close=h,this.high=p,this.low=d,this.volume=f,this.hl2=x,this.hlc3=m,this.ohlc4=b,this.hlcc4=w,this.openTime=v,this.closeTime=A,e&&e.getSymbolInfo?e.getSymbolInfo(r).then(C=>{this._syminfo=C,this._ready=!0,o(!0)}).catch(C=>{console.warn("Failed to get symbol info, using default values:",C),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}get transpiledCode(){return this._transpiledCode}markAsSecondary(){this._isSecondaryContext=!0}setTimezone(e){this._chartTimezone=e}setMaxLoops(e){this._maxLoops=e}setAlertMode(e){this._alertMode=e}setVisibleRange(e,r){this._viewportLeft=e,this._viewportRight=r}usesVisibleRange(){return this._usesVisibleRange}get visibleRangeLeft(){return this._viewportLeft}get visibleRangeRight(){return this._viewportRight}async update(e){let r=e??this._lastPineTSCode;if(!r)throw new Error("pine.update(): pineTSCode is required on the first call.");let n=this._lastResult===null,i=this._viewportLeft!==this._lastRunViewport.left||this._viewportRight!==this._lastRunViewport.right;return n||this._usesVisibleRange&&i?(this._lastPineTSCode=r,this._lastRunViewport={left:this._viewportLeft,right:this._viewportRight},this._lastResult=await this.run(r),this._lastResult):this._lastResult}setDebugSettings({ln:e,debug:r}){this._debugSettings.ln=e,this._debugSettings.debug=r}async loadMarketData(e,r,n,i,s,a){return Array.isArray(e)?e:e.getMarketData(r,n,i,s,a)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,r,n){let i=Qt.from(e);if(this._currentIndicator=i,n&&n>0){let s=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(i,r,n,s)}else return this._runComplete(i,r)}stream(e,r={}){let{live:n=!0,interval:i=1e3}=r,s=r.pageSize||this.data.length,a=Qt.from(e);this._currentIndicator=a;let o={data:[],error:[],warning:[],alert:[]},l=!1,c=(p,...d)=>{o[p]&&o[p].forEach(f=>f(...d))},u=(p,d)=>{o[p]||(o[p]=[]),o[p].push(d)},h=()=>{l=!0};return(async()=>{try{n&&typeof this.eDate<"u"&&(this.eDate=Math.max(this.eDate,Date.now()));let p=!Array.isArray(this.source)&&n,d=this._runPaginated(a,void 0,s,p);for await(let f of d){if(l)break;if(f===null){await new Promise(m=>setTimeout(m,i));continue}if(c("data",f),f.warnings&&f.warnings.length>0){for(let m of f.warnings)c("warning",m);f.warnings.length=0}if(f.alerts&&f.alerts.length>0){for(let m of f.alerts)c("alert",m);f.alerts.length=0}if(p&&!l){let m=f.marketData[f.idx],x=m&&m.closeTime<Date.now(),b=f.idx>=f.marketData.length-1;(!x||b)&&await new Promise(w=>setTimeout(w,i))}}}catch(p){c("error",p)}})(),{on:u,stop:h}}async runPretranspiled(e,r={},n){await this.ready(),n||(n=this.data.length);let i=this._initializeContext(null,r,this._isSecondaryContext);this._transpiledCode=e;let s=e._ltfSlices;return s&&(i._ltfTruncatedBodies=s),await this._executeIterations(i,e,this.data.length-n,this.data.length),i}async _runComplete(e,r){await this.ready(),r||(r=this.data.length);let n=e.prepare(this._debugSettings);this._usesVisibleRange=n.usesVisibleRange;let i=this._initializeContext(e.source??null,n.inputs,this._isSecondaryContext);this._transpiledCode=n.fn,n.ltfSlices&&(i._ltfTruncatedBodies=n.ltfSlices);let s=this.data.length-r,a=this.data.length;return a-s>1?(await this._executeIterations(i,n.fn,s,a-1),i._varSnapshot=this._snapshotVarState(i),await this._executeIterations(i,n.fn,a-1,a)):await this._executeIterations(i,n.fn,s,a),i}async*_runPaginated(e,r,n,i=!1){await this.ready(),r||(r=this.data.length);let s=e.prepare(this._debugSettings);this._usesVisibleRange=s.usesVisibleRange;let a=this._initializeContext(e.source??null,s.inputs,this._isSecondaryContext);this._transpiledCode=s.fn,s.ltfSlices&&(a._ltfTruncatedBodies=s.ltfSlices);let o=this.data.length-r,l=null;for(;;){let c=this.data.length,u=c-o;if(u>0){let m=Math.min(u,n),x=this._getResultLength(a.result),b=o+m;i&&b>=c&&m>1?(await this._executeIterations(a,this._transpiledCode,o,b-1),l=this._snapshotVarState(a),await this._executeIterations(a,this._transpiledCode,b-1,b)):i&&b>=c&&m===1?await this._executeIterations(a,this._transpiledCode,o,b):await this._executeIterations(a,this._transpiledCode,o,b),o+=m,yield this._createPageContext(a,x);continue}if(!i||Array.isArray(this.source))break;let h=Date.now(),{newCandles:p,updatedLastCandle:d}=await this._updateMarketData(),f=Date.now()-h;if(p===0&&!d){yield null;continue}if(p===0&&d&&f<1e3&&await new Promise(m=>setTimeout(m,1e3-f)),a.dataVersion++,a.length=this.data.length,this._restoreVarState(a,l),Array.isArray(a.result))a.result.pop();else if(typeof a.result=="object"&&a.result!==null)for(let m in a.result)Array.isArray(a.result[m])&&a.result[m].pop();a.data.close.data.pop(),a.data.open.data.pop(),a.data.high.data.pop(),a.data.low.data.pop(),a.data.volume.data.pop(),a.data.hl2.data.pop(),a.data.hlc3.data.pop(),a.data.ohlc4.data.pop(),a.data.hlcc4.data.pop(),a.data.openTime.data.pop(),a.data.closeTime&&a.data.closeTime.data.pop(),a.data.bar_index.data.pop(),o=this.data.length-(p+1),a.rollbackDrawings(o),p>0&&(l=null),a.pine.barstate.setLive()}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){let r=Object.keys(e);if(r.length>0&&Array.isArray(e[r[0]]))return e[r[0]].length}return 0}_createPageContext(e,r){let n=new Js({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,fullContext:e,inputs:e.inputs});if(n.pineTSCode=e.pineTSCode,n.idx=e.idx,Array.isArray(e.result))n.result=e.result.slice(r);else if(typeof e.result=="object"&&e.result!==null){n.result={};for(let i in e.result)Array.isArray(e.result[i])?n.result[i]=e.result[i].slice(r):n.result[i]=e.result[i]}else n.result=e.result;return n.plots={...e.plots},n.warnings=e.warnings,n.alerts=e.alerts,n}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};let r=this.source,n=this.data.length-1,i=this.data[n].openTime;try{let s=await r.getMarketData(this.tickerId,this.timeframe,void 0,i,e);if(!s||s.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let l=0;l<s.length;l++){let c=s[l];c.openTime===i?(this._replaceCandle(n,c),a=!0):c.openTime>i&&(this._appendCandle(c),o++)}return{newCandles:o,updatedLastCandle:a}}catch(s){return console.error("Error updating market data:",s),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,r){this.data[e]=r,this.open[e]=r.open,this.close[e]=r.close,this.high[e]=r.high,this.low[e]=r.low,this.volume[e]=r.volume,this.hl2[e]=(r.high+r.low)/2,this.hlc3[e]=(r.high+r.low+r.close)/3,this.ohlc4[e]=(r.high+r.low+r.open+r.close)/4,this.hlcc4[e]=(r.high+r.low+r.close+r.close)/4,this.openTime[e]=r.openTime,this.closeTime[e]=r.closeTime}_appendCandle(e){this.data.push(e),this.open.push(e.open),this.close.push(e.close),this.high.push(e.high),this.low.push(e.low),this.volume.push(e.volume),this.hl2.push((e.high+e.low)/2),this.hlc3.push((e.high+e.low+e.close)/3),this.ohlc4.push((e.high+e.low+e.open+e.close)/4),this.hlcc4.push((e.high+e.low+e.close+e.close)/4),this.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}async updateTail(e){if(this.data.length===0||Array.isArray(this.source))return!1;let{newCandles:r,updatedLastCandle:n}=await this._updateMarketData();if(r===0&&!n)return!1;let i=e._varSnapshot;if(i?this._restoreVarState(e,i):this._removeLastResult(e),Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let o in e.result)Array.isArray(e.result[o])&&e.result[o].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop(),e.dataVersion=(e.dataVersion||0)+1,e.length=this.data.length;let s=this.data.length-(r+1);e.rollbackDrawings(s);let a=this.data.length;return s<a-1?(await this._executeIterations(e,this._transpiledCode,s,a-1),e._varSnapshot=this._snapshotVarState(e),await this._executeIterations(e,this._transpiledCode,a-1,a)):await this._executeIterations(e,this._transpiledCode,s,a),!0}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let i in e.result)Array.isArray(e.result[i])&&e.result[i].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop();let r=["const","var","let","params"],n=i=>{for(let s of r)if(i[s])for(let a in i[s]){let o=i[s][a];o instanceof y?o.data.pop():Array.isArray(o)&&o.pop()}};n(e),e.lctx&&e.lctx.forEach(i=>n(i))}_snapshotVarState(e){let r=["const","var","let","params"],n={main:{},lctx:[]},i=s=>{let a={};for(let o of r)if(s[o]){a[o]={};for(let l in s[o]){let c=s[o][l];if(c instanceof y){let u=c.data.length,h=u>0?c.data[u-1]:void 0;a[o][l]={len:u,lastVal:h}}}}return a};if(n.main=i(e),e.lctx){let s=[];e.lctx.forEach(a=>s.push(i(a))),n.lctx=s}return n.strategy=jf(e.strategy),n.resultLength=this._getResultLength(e.result),n.dataLength=e.data.close?.data?.length??0,n}_restoreVarState(e,r){if(!r)return;let n=["const","var","let","params"],i=(s,a)=>{for(let o of n)if(!(!a[o]||!s[o]))for(let l in a[o]){let c=s[o][l],u=a[o][l];c instanceof y&&u&&typeof u.len=="number"&&(c.data.length>u.len&&(c.data.length=u.len),u.len>0&&u.lastVal!==void 0&&(c.data[u.len-1]=u.lastVal))}};if(i(e,r.main),e.lctx&&r.lctx){let s=0;e.lctx.forEach(a=>{r.lctx[s]&&i(a,r.lctx[s]),s++})}$f(e.strategy,r.strategy)}_initializeContext(e,r={},n=!1){let i=new Js({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:r});i.pine.syminfo=this._syminfo;let s=Lr(String(this.tickerId??"")).modifier;return i.chartStyle=s==="heikinashi"?"heikinashi":"standard",this._syminfo&&s==="heikinashi"&&(i.pine.syminfo={...this._syminfo,tickerid:vi(String(this._syminfo.tickerid??this.tickerId),"heikinashi")}),this._chartTimezone&&(i.chartTimezone=this._chartTimezone),i.viewportLeft=this._viewportLeft,i.viewportRight=this._viewportRight,i.__maxLoops=this._maxLoops,i._alertMode=this._alertMode,i._propOverrides=this._currentIndicator?.getRuntimePropOverrides()??{},i.pineTSCode=e,i.isSecondaryContext=n,i.data.close=new y([]),i.data.open=new y([]),i.data.high=new y([]),i.data.low=new y([]),i.data.volume=new y([]),i.data.hl2=new y([]),i.data.hlc3=new y([]),i.data.ohlc4=new y([]),i.data.hlcc4=new y([]),i.data.openTime=new y([]),i.data.closeTime=new y([]),i.length=this.data.length,i}async _executeIterations(e,r,n,i){let s=["const","var","let","params"];for(let a=n;a<i;a++){if(e.idx=a,e._execTick=(e._execTick||0)+1,e.data.close.data.push(this.close[a]),e.data.open.data.push(this.open[a]),e.data.high.data.push(this.high[a]),e.data.low.data.push(this.low[a]),e.data.volume.data.push(this.volume[a]),e.data.hl2.data.push(this.hl2[a]),e.data.hlc3.data.push(this.hlc3[a]),e.data.ohlc4.data.push(this.ohlc4[a]),e.data.hlcc4.data.push(this.hlcc4[a]),e.data.openTime.data.push(this.openTime[a]),e.data.closeTime.data.push(this.closeTime[a]),e.data.bar_index.data.push(a),e.strategy){Df(e),Ef(e),ri(e,"open");let c=Mf(e);c&&ri(e,"extreme"),Tf(e,"intrabar"),c||ri(e,"extreme"),Pf(e)}let o=await r(e);if(typeof o=="object"){typeof e.result!="object"&&(e.result={});for(let c in o){e.result[c]===void 0&&(e.result[c]=[]);let u;o[c]instanceof y?u=o[c].get(0):Array.isArray(o[c])?u=o[c][o[c].length-1]:u=o[c],e.result[c].push(u)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(o);for(let c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();let l=c=>{for(let u of s)if(c[u])for(let h in c[u]){let p=c[u][h];if(p instanceof y){let d=p.get(0);p.data.push(d)}else if(Array.isArray(p)){let d=p[p.length-1];p.push(d)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}e.strategy&&Rf(e)}},ma={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},Fr={"1S":1,"5S":5,"10S":10,"15S":15,"30S":30,1:60,3:180,5:300,15:900,30:1800,45:2700,60:3600,120:7200,180:10800,240:14400,D:86400,W:604800,M:2592e3};function Br(t,e,r=1){if(e==="month"){let i=new Date(t);return Date.UTC(i.getUTCFullYear(),i.getUTCMonth()+r,1,i.getUTCHours(),i.getUTCMinutes(),i.getUTCSeconds(),i.getUTCMilliseconds())}let n={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+r*n[e]}function St(t,e,r){let[n,i,s]=t.split("-").map(Number),[a,o]=e.split(":").map(Number),l=Date.UTC(n,i-1,s,a,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:r,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(l)),u=b=>parseInt(c.find(w=>w.type===b).value,10),h=u("year"),p=u("month"),d=u("day"),f=u("hour");f===24&&(f=0);let m=u("minute"),x=Date.UTC(h,p-1,d,f,m,0,0)-l;return l-x}function ya(t,e,r,n,i=1){if(e==="24x7")return Br(t,n,i);let s=e.split("-")[1];if(!s||s.length!==4)return Br(t,n,i);let a=s.slice(0,2),o=s.slice(2,4),l=`${a}:${o}`,c=ga(t,r);if(n==="second"||n==="minute"||n==="hour"){let u=t+i*{second:1e3,minute:6e4,hour:36e5}[n],h=St(c,l,r);return Math.min(u,h)}if(n==="day")return St(c,l,r);if(n==="week"){let u=new Date(t).getUTCDay(),h=u<=5?5-u:5-u+7,p=t+h*864e5,d=ga(p,r);return St(d,l,r)}if(n==="month"){let u=new Date(t),h=u.getUTCFullYear(),p=u.getUTCMonth()+i,d=new Date(Date.UTC(h,p,1)),f=new Date(d.getTime()-864e5);for(;f.getUTCDay()===0||f.getUTCDay()===6;)f.setUTCDate(f.getUTCDate()-1);let m=f.toISOString().split("T")[0];return St(m,l,r)}return Br(t,n,i)}function ga(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function W0(t){for(let e=0;e<t.length-1;e++)t[e].closeTime=t[e+1].openTime;t.length>0&&(t[t.length-1].closeTime=t[t.length-1].closeTime+1)}var U0=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function q0(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;let r=Fr[t];if(!r)return null;let n=U0.filter(i=>i!=="W"&&i!=="M"&&e.has(i)&&Fr[i]<r&&r%Fr[i]===0);return n.length===0?null:n[n.length-1]}function sl(t,e){if(t==="W"||t==="M")return 1/0;let r=Fr[t],n=Fr[e];return!r||!n||n===0?1/0:r/n}function z0(t,e,r){if(t.length===0)return[];if(e==="W")return H0(t);if(e==="M")return G0(t);let n=sl(e,r);return K0(t,n)}function K0(t,e){if(t.length===0)return[];let r=[],n=[t[0]],i=Y0(t),s=i>0?i*1.5:0;for(let a=1;a<t.length;a++){let o=t[a].openTime-t[a-1].openTime;(s>0&&o>s||n.length>=e)&&(r.push(On(n)),n=[]),n.push(t[a])}return n.length>0&&r.push(On(n)),r}function H0(t){let e=[],r=[],n="";for(let i of t){let s=Z0(i.openTime);s!==n&&r.length>0&&(e.push(r),r=[]),n=s,r.push(i)}return r.length>0&&e.push(r),e.map(On)}function G0(t){let e=[],r=[],n="";for(let i of t){let s=new Date(i.openTime),a=`${s.getUTCFullYear()}-${s.getUTCMonth()}`;a!==n&&r.length>0&&(e.push(r),r=[]),n=a,r.push(i)}return r.length>0&&e.push(r),e.map(On)}function On(t){let e=t[0],r=t[t.length-1],n=e.high,i=e.low,s=0,a=0,o=0,l=0,c=0;for(let u=0;u<t.length;u++){let h=t[u];h.high>n&&(n=h.high),h.low<i&&(i=h.low),s+=h.volume,a+=h.quoteAssetVolume,o+=h.numberOfTrades,l+=h.takerBuyBaseAssetVolume,c+=h.takerBuyQuoteAssetVolume}return{openTime:e.openTime,open:e.open,high:n,low:i,close:r.close,volume:s,closeTime:r.closeTime,quoteAssetVolume:a,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function Y0(t){if(t.length<2)return 0;let e=Math.min(t.length-1,20),r=1/0;for(let n=0;n<e;n++){let i=t[n+1].openTime-t[n].openTime;i>0&&i<r&&(r=i)}return r===1/0?0:r}function Z0(t){let e=new Date(t),r=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-r);let n=new Date(Date.UTC(e.getUTCFullYear(),0,1)),i=Math.ceil(((e.getTime()-n.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${i}`}var X0=Object.defineProperty,Q0=(t,e,r)=>e in t?X0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Jr=(t,e,r)=>Q0(t,typeof e!="symbol"?e+"":e,r),en={"1s":"1S","5s":"5S","10s":"10S","15s":"15S","30s":"30S","1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1D":"D","1W":"W","1M":"M","4H":"240",D:"D",W:"W",M:"M"};function J0(t){if(en[t]!==void 0)return en[t];let e=t.toLowerCase();return en[e]!==void 0?en[e]:/^\\d+$/.test(t)?t:/^\\d+S$/i.test(t)?t.toUpperCase():t}var jr=class{constructor(e){Jr(this,"_configured"),Jr(this,"_requiresApiKey"),Jr(this,"_providerName"),Jr(this,"_aggregationSubTimeframe",null),this._requiresApiKey=e.requiresApiKey,this._providerName=e.providerName,this._configured=!e.requiresApiKey}ensureConfigured(){if(!this._configured)throw new Error(`${this._providerName} requires configuration before use. Call Provider.${this._providerName}.configure({ apiKey: \'...\' }) or instantiate directly: new ${this._providerName}Provider({ apiKey: \'...\' })`)}configure(e){this._configured=!0}get isConfigured(){return this._configured}normalizeCloseTime(e){W0(e)}setAggregationSubTimeframe(e){this._aggregationSubTimeframe=e}getSupportedTimeframes(){return new Set(["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"])}async getMarketData(e,r,n,i,s){e=Ot(e);let a=J0(r),o=this.getSupportedTimeframes();if(o.has(a))return this._getMarketDataNative(e,a,n,i,s);let l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:q0(a,o);if(!c)return console.error(`${this._providerName}: Timeframe \'${r}\' is not supported and no valid sub-timeframe found for aggregation.`),[];let u=this._computeSubLimit(a,c,n),h=await this._getMarketDataNative(e,c,u,i,s);if(h.length===0)return[];let p=z0(h,a,c);return n&&n>0&&p.length>n?p.slice(p.length-n):p}_computeSubLimit(e,r,n){if(!n)return;let i=sl(e,r);return i===1/0?e==="W"?n*7+14:e==="M"?n*31+31:n*30:Math.ceil(n*i)+Math.ceil(i)}},ex=Object.defineProperty,tx=(t,e,r)=>e in t?ex(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Vn=(t,e,r)=>tx(t,typeof e!="symbol"?e+"":e,r),ci="https://api.binance.com/api/v3",_a="https://api.binance.us/api/v3",tn={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",45:null,60:"1h",120:"2h",180:null,240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"},ns=class{constructor(e=300*1e3){Vn(this,"cache"),Vn(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([r,n])=>n!==void 0).map(([r,n])=>`${r}:${n}`).join("|")}get(e){let r=this.generateKey(e),n=this.cache.get(r);return n?Date.now()-n.timestamp>this.cacheDuration?(this.cache.delete(r),null):n.data:null}set(e,r){let n=this.generateKey(e);this.cache.set(n,{data:r,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){let e=Date.now();for(let[r,n]of this.cache.entries())e-n.timestamp>this.cacheDuration&&this.cache.delete(r)}},is=class extends jr{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),Vn(this,"cacheManager"),Vn(this,"activeApiUrl",null),this.cacheManager=new ns(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{let e=new AbortController,r=setTimeout(()=>e.abort(),5e3),n=await fetch(`${ci}/ping`,{signal:e.signal});if(clearTimeout(r),n.ok)return this.activeApiUrl=ci,this.activeApiUrl}catch{}try{let e=new AbortController,r=setTimeout(()=>e.abort(),5e3),n=await fetch(`${_a}/ping`,{signal:e.signal});if(clearTimeout(r),n.ok)return this.activeApiUrl=_a,this.activeApiUrl}catch{}return ci}async _fetchRawChunk(e,r,n,i,s){let a=tn[r.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${r}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${a}`;n&&(o+=`&limit=${Math.min(n,1e3)}`),i&&(o+=`&startTime=${i}`),s&&(o+=`&endTime=${s}`);let l=await fetch(o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return(await l.json()).map(c=>({openTime:parseInt(c[0]),open:parseFloat(c[1]),high:parseFloat(c[2]),low:parseFloat(c[3]),close:parseFloat(c[4]),volume:parseFloat(c[5]),closeTime:parseInt(c[6]),quoteAssetVolume:parseFloat(c[7]),numberOfTrades:parseInt(c[8]),takerBuyBaseAssetVolume:parseFloat(c[9]),takerBuyQuoteAssetVolume:parseFloat(c[10]),ignore:c[11]}))}async getMarketDataInterval(e,r,n,i){try{let s=tn[r.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${r}`),[];let a=[],o=n,l=i,c=ma[s];if(!c)return console.error(`Duration not defined for interval: ${s}`),[];for(;o<l;){let u=Math.min(o+1e3*c,l),h=await this._fetchRawChunk(e,r,1e3,o,u);if(h.length===0)break;a=a.concat(h),o=h[h.length-1].closeTime+1}return this.normalizeCloseTime(a),a}catch(s){return console.error("Error in getMarketDataInterval:",s),[]}}async getMarketDataBackwards(e,r,n,i){let s=n,a=[],o=i,l=0,c=Math.ceil(n/1e3)+5;for(;s>0&&l<c;){l++;let u=Math.min(s,1e3),h=await this._fetchRawChunk(e,r,u,void 0,o);if(h.length===0||(a=h.concat(a),s-=h.length,o=h[0].openTime-1,h.length<u))break}return this.normalizeCloseTime(a),a}getSupportedTimeframes(){return new Set(["1","3","5","15","30","60","120","240","D","W","M"])}async _getMarketDataNative(e,r,n,i,s){try{let a=s!==void 0,o={tickerId:e,timeframe:r,limit:n,sDate:i,eDate:s};if(a){let c=this.cacheManager.get(o);if(c)return c}if(!tn[r.toUpperCase()])return console.error(`Unsupported timeframe: ${r}`),[];if(this.shouldPaginate(r,n,i,s)){if(i&&s){let c=await this.getMarketDataInterval(e,r,i,s),u=n?c.slice(0,n):c;return this.cacheManager.set(o,u),u}else if(n&&n>1e3){let c=await this.getMarketDataBackwards(e,r,n,s);return this.cacheManager.set(o,c),c}}let l=await this._fetchRawChunk(e,r,n,i,s);return this.normalizeCloseTime(l),a&&this.cacheManager.set(o,l),l}catch(a){return console.error("Error in binance.klines:",a),[]}}shouldPaginate(e,r,n,i){if(r&&r>1e3)return!0;if(n&&i){let s=tn[e.toUpperCase()],a=ma[s];if(a)return Math.ceil((i-n)/a)>1e3}return!1}async getSymbolInfo(e){e=Ot(e);try{let r="crypto",n=await this.getBaseUrl(),i=e,s="";e.endsWith(".P")?(r="futures",i=e.replace(".P",""),n="https://fapi.binance.com/fapi/v1",s="Perpetual"):e.includes("_")&&(r="futures",i=e,n="https://dapi.binance.com/dapi/v1",s="Delivery");let a=r==="crypto"?`${n}/exchangeInfo?symbol=${i}`:`${n}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;let c=r==="futures"?l.find(v=>v.symbol===i):l[0];if(!c)return console.error(`Symbol ${i} not found in exchange info`),null;let u=c.filters?.find(v=>v.filterType==="PRICE_FILTER"),h=c.filters?.find(v=>v.filterType==="LOT_SIZE"),p=u?parseFloat(u.tickSize):.01,d=h?parseFloat(h.minQty):0,f=Math.round(1/p),m=c.baseAsset,x=c.quoteAsset,b=s?` ${s}`:"",w=`${m} / ${x}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:m,description:w,type:r,main_tickerid:`BINANCE:${e}`,current_contract:s,isin:"",basecurrency:m,currency:x,timezone:"Etc/UTC",country:"",mintick:p,pricescale:f,minmove:1,pointvalue:c.contractSize||1,mincontract:d,session:"24x7",volumetype:"base",expiration_date:c.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(r){return console.error("Error in binance.exchangeInfo:",r),null}}},rx=Object.defineProperty,nx=(t,e,r)=>e in t?rx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Er=(t,e,r)=>nx(t,typeof e!="symbol"?e+"":e,r),ix="https://financialmodelingprep.com",xa=new Set(["USD","EUR","GBP","JPY","CHF","AUD","CAD","NZD","SEK","NOK","DKK","SGD","HKD","KRW","MXN","ZAR","TRY","BRL","INR","CNY","PLN","CZK","HUF","ILS","THB","TWD","PHP","IDR","MYR","RUB","CLP","COP"]),ba={"1D":{endpoint:"/stable/historical-price-eod/full",type:"daily"},D:{endpoint:"/stable/historical-price-eod/full",type:"daily"},1:{endpoint:"/stable/historical-chart/1min",interval:"1min",type:"intraday"},5:{endpoint:"/stable/historical-chart/5min",interval:"5min",type:"intraday"},15:{endpoint:"/stable/historical-chart/15min",interval:"15min",type:"intraday"},30:{endpoint:"/stable/historical-chart/30min",interval:"30min",type:"intraday"},60:{endpoint:"/stable/historical-chart/1hour",interval:"1hour",type:"intraday"},240:{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"},"4H":{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"}},va={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",NYSEArca:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",PNK:"America/New_York",TSX:"America/Toronto",TSXV:"America/Toronto",LSE:"Europe/London",EURONEXT:"Europe/Paris",XETRA:"Europe/Berlin",JPX:"Asia/Tokyo",HKSE:"Asia/Hong_Kong",SSE:"Asia/Shanghai",SHZ:"Asia/Shanghai",ASX:"Australia/Sydney",NSE:"Asia/Kolkata",BSE:"Asia/Kolkata",KRX:"Asia/Seoul",CRYPTO:"Etc/UTC"},wa={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",NYSEArca:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",PNK:"0930-1600",TSX:"0930-1600",TSXV:"0930-1600",LSE:"0800-1630",EURONEXT:"0900-1730",XETRA:"0900-1730",JPX:"0900-1530",HKSE:"0930-1600",SSE:"0930-1500",SHZ:"0930-1500",ASX:"1000-1600",NSE:"0915-1530",BSE:"0915-1530",KRX:"0900-1530",CRYPTO:"24x7"},sx={daily:{periodType:"day",multiplier:1},"1min":{periodType:"minute",multiplier:1},"5min":{periodType:"minute",multiplier:5},"15min":{periodType:"minute",multiplier:15},"30min":{periodType:"minute",multiplier:30},"1hour":{periodType:"hour",multiplier:1},"4hour":{periodType:"hour",multiplier:4}},ss=class extends jr{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),Er(this,"_apiKey",null),Er(this,"_baseUrl",ix),Er(this,"_profileCache",new Map),Er(this,"_symbolInfoCache",new Map),Er(this,"_mintickCache",new Map),e?.apiKey&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,e.baseUrl&&(this._baseUrl=e.baseUrl)}getSupportedTimeframes(){return new Set(["1","5","15","30","60","240","D"])}async _getMarketDataNative(e,r,n,i,s){this.ensureConfigured();try{let a=r.toUpperCase(),o=ba[a]||ba[r];if(!o)return console.error(`FMP: Unsupported timeframe: ${r}`),[];let l;if(o.type==="intraday"?l=await this._fetchIntradayData(e,o.endpoint,o.interval,i,s,n):l=await this._fetchDailyData(e,i,s,n),l.length>0&&!this._mintickCache.has(e)){let c=this._estimateMintick(l);c!==void 0&&this._mintickCache.set(e,c)}return l}catch(a){return console.error("Error in FMPProvider.getMarketData:",a),[]}}async _fetchDailyData(e,r,n,i){let s=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;r&&(s+=`&from=${this._msToDateStr(r)}`),n&&(s+=`&to=${this._msToDateStr(n)}`);let a=await fetch(s);if(!a.ok){let h=await a.text();throw new Error(`FMP HTTP ${a.status}: ${h}`)}let o=await a.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();let l=i&&i>0&&i<o.length?o.slice(o.length-i):o,{session:c,timezone:u}=await this._resolveSessionInfo(e);return l.map(h=>{let p=this._dateStrToMs(h.date),d=ya(p,c,u,"day");return{openTime:p,open:h.open,high:h.high,low:h.low,close:h.close,volume:h.volume,closeTime:d,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,r,n,i,s,a){let o=`${this._baseUrl}${r}?symbol=${e}&apikey=${this._apiKey}`;i&&(o+=`&from=${this._msToDateStr(i)}`),s&&(o+=`&to=${this._msToDateStr(s)}`);let l=await fetch(o);if(!l.ok){let m=await l.text();if(l.status===403||m.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${n}) requires a paid plan. Use daily timeframe (\'D\') with a free API key, or upgrade at https://financialmodelingprep.com/`),[];throw new Error(`FMP HTTP ${l.status}: ${m}`)}let c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();let u=a&&a>0&&a<c.length?c.slice(c.length-a):c,{periodType:h,multiplier:p}=sx[n]||{periodType:"minute",multiplier:1},{session:d,timezone:f}=await this._resolveSessionInfo(e);return u.map(m=>{let x=this._dateTimeStrToMs(m.date),b=ya(x,d,f,h,p);return{openTime:x,open:m.open,high:m.high,low:m.low,close:m.close,volume:m.volume,closeTime:b,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async getSymbolInfo(e){if(this.ensureConfigured(),e=Ot(e),this._symbolInfoCache.has(e))return this._symbolInfoCache.get(e);try{let r=await this._fetchProfile(e),n="stock";r?.isEtf?n="etf":r?.isFund?n="fund":this._isForex(e)?n="forex":this._isCrypto(e)&&(n="crypto");let i=r?.exchange||(n==="crypto"?"CRYPTO":n==="forex"?"FX":""),s=n==="crypto"||n==="forex"?"Etc/UTC":va[i]||"America/New_York",a=n==="crypto"?"24x7":n==="forex"?"0000-0000":wa[i]||"0930-1600",o=r?.currency||(this._isForex(e)?e.slice(3,6):"USD"),l=this._isForex(e)?e.slice(0,3):r?.currency||"USD",c=this._mintickCache.get(e)??.01,u=Math.round(1/c),h=Math.round(c*u),p={ticker:r?.symbol||e,tickerid:`${i}:${r?.symbol||e}`,prefix:i,root:r?.symbol||e,description:r?.companyName||e,type:n,main_tickerid:`${i}:${r?.symbol||e}`,current_contract:"",isin:r?.isin||"",basecurrency:l,currency:o,timezone:s,country:r?.country||"",mintick:c,pricescale:u,minmove:h,pointvalue:1,mincontract:0,session:a,volumetype:"base",expiration_date:0,employees:r&&parseInt(r.fullTimeEmployees)||0,industry:r?.industry||"",sector:r?.sector||"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0};return this._mintickCache.has(e)&&this._symbolInfoCache.set(e,p),p}catch(r){return console.error("Error in FMPProvider.getSymbolInfo:",r),null}}_estimateMintick(e){let r=[];for(let o=0;o<e.length;o++){let l=e[o],c=Math.abs(l.close-l.open),u=Math.abs(l.high-l.low);if(c>0&&r.push(c),u>0&&r.push(u),o>0){let h=Math.abs(l.close-e[o-1].close);h>0&&r.push(h)}}if(r.length===0)return;let n=Math.min(...r),i=Math.floor(Math.log10(n)),s=n/10**i,a=(Math.floor(s+1e-12)<5?1:10)*10**i;return a>=1?.01:a}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);let r=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,n=await fetch(r);if(!n.ok)return null;let i=await n.json();if(!Array.isArray(i)||i.length===0)return null;let s=i[0];return this._profileCache.set(e,s),s}async _resolveSessionInfo(e){try{let r=await this._fetchProfile(e);if(r){let n=r.exchange||"",i=this._isCrypto(e),s=i?"Etc/UTC":va[n]||"America/New_York";return{session:i?"24x7":wa[n]||"0930-1600",timezone:s}}}catch{}return{session:"0930-1600",timezone:"America/New_York"}}_msToDateStr(e){return new Date(e).toISOString().split("T")[0]}_dateStrToMs(e){return new Date(e+"T00:00:00Z").getTime()}_dateTimeStrToMs(e){return new Date(e.replace(" ","T")+"Z").getTime()}_isForex(e){return/^[A-Z]{6}$/.test(e)&&xa.has(e.slice(0,3))&&xa.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}},ax=Object.defineProperty,ox=(t,e,r)=>e in t?ax(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zt=(t,e,r)=>ox(t,typeof e!="symbol"?e+"":e,r),lx="https://data.alpaca.markets",cx="https://paper-api.alpaca.markets/v2",ux="https://api.alpaca.markets/v2",ui=1e4,Ea={1:"1Min",3:"3Min",5:"5Min",15:"15Min",30:"30Min",60:"1Hour",120:"2Hour",240:"4Hour","4H":"4Hour","1D":"1Day",D:"1Day","1W":"1Week",W:"1Week","1M":"1Month",M:"1Month"},px={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",ARCA:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",CRYPTO:"Etc/UTC"},hx={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},dx={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"},as=class extends jr{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),zt(this,"_apiKey",null),zt(this,"_apiSecret",null),zt(this,"_dataUrl",lx),zt(this,"_tradingUrl",cx),zt(this,"_feed",null),zt(this,"_assetCache",new Map),zt(this,"_calendarCache",new Map),e?.apiKey&&e?.apiSecret&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,this._apiSecret=e.apiSecret,e.feed&&(this._feed=e.feed),e.dataUrl&&(this._dataUrl=e.dataUrl),e.tradingUrl?this._tradingUrl=e.tradingUrl:e.paper===!1&&(this._tradingUrl=ux)}_headers(){return{"APCA-API-KEY-ID":this._apiKey,"APCA-API-SECRET-KEY":this._apiSecret}}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,r,n,i,s){this.ensureConfigured();try{let a=this._resolveTimeframe(r);if(!a)return console.error(`Alpaca: Unsupported timeframe: ${r}`),[];let o=this._isCrypto(e),l=await this._fetchAllBars(e,a,o,i,s,n);if(l.length===0)return[];let{periodType:c,multiplier:u}=this._parseAlpacaTimeframe(a);if(o)return this._convertBarsCrypto(l,c,u);let h=l[0].t.slice(0,10),p=l[l.length-1].t.slice(0,10),d=this._addDaysToDate(p,40);return await this._ensureCalendar(h,d),this._convertBarsStock(l,c,u)}catch(a){return console.error("Error in AlpacaProvider.getMarketData:",a),[]}}async _fetchAllBars(e,r,n,i,s,a){let o=[],l=null,c=a||1/0,u=Math.min(a||ui,ui);do{let h=this._buildBarsUrl(e,r,n,i,s,u,l),p=await fetch(h,{headers:this._headers()});if(!p.ok){let m=await p.text();throw new Error(`Alpaca HTTP ${p.status}: ${m}`)}let d=await p.json(),f=Object.keys(d.bars||{})[0];if(!f||!d.bars[f]||(o.push(...d.bars[f]),l=d.next_page_token,o.length>=c))break}while(l);return a&&a>0&&o.length>a?o.slice(0,a):o}_buildBarsUrl(e,r,n,i,s,a,o){let l=n?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",r),c.set("sort","asc"),i&&c.set("start",new Date(i).toISOString()),s&&c.set("end",new Date(s).toISOString()),a&&c.set("limit",String(Math.min(a,ui))),o&&c.set("page_token",o),!n&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured(),e=Ot(e);try{let r=await this._fetchAsset(e);if(!r)return console.error(`Alpaca: Symbol ${e} not found`),null;let n=r.exchange||"",i=r.class==="crypto",s=i?"Etc/UTC":px[n]||"America/New_York",a=i?"24x7":hx[n]||"0930-1600",o="stock";i&&(o="crypto");let l=i&&e.split("/")[1]||"USD",c=i?e.split("/")[0]||e:l,u=r.price_increment?parseFloat(r.price_increment):.01,h=Math.round(1/u);return{ticker:r.symbol,tickerid:`${n}:${r.symbol}`,prefix:n,root:i?e.split("/")[0]:r.symbol,description:r.name||r.symbol,type:o,main_tickerid:`${n}:${r.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:s,country:i?"":"US",mintick:u,pricescale:h,minmove:1,pointvalue:1,mincontract:r.min_order_size?parseFloat(r.min_order_size):0,session:a,volumetype:"base",expiration_date:0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(r){return console.error("Error in AlpacaProvider.getSymbolInfo:",r),null}}_convertBarsCrypto(e,r,n){return e.map((i,s,a)=>{let o=new Date(i.t).getTime(),l=s<a.length-1?new Date(a[s+1].t).getTime():Br(o,r,n);return this._toKline(i,o,l)})}_convertBarsStock(e,r,n){let i="America/New_York";return e.map(s=>{let a=new Date(s.t).getTime(),o=s.t.slice(0,10),l;if(r==="day"){let c=this._calendarCache.get(o),u=c?c.close:"16:00";l=St(o,u,i)}else if(r==="minute"||r==="hour"){let c=a+n*{minute:6e4,hour:36e5}[r],u=this._calendarCache.get(o),h=u?u.close:"16:00",p=St(o,h,i);l=Math.min(c,p)}else r==="week"?l=this._weeklyCloseFromCalendar(o,i):r==="month"?l=this._monthlyCloseFromCalendar(o,i):l=Br(a,r,n);return this._toKline(s,a,l)})}_toKline(e,r,n){return{openTime:r,open:e.o,high:e.h,low:e.l,close:e.c,volume:e.v,closeTime:n,quoteAssetVolume:0,numberOfTrades:e.n,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}}_weeklyCloseFromCalendar(e,r){let n=new Date(e+"T00:00:00Z"),i=n.getUTCDay(),s=i<=5?5-i:5-i+7;for(let l=s;l>=0;l--){let c=n.getTime()+l*864e5,u=new Date(c).toISOString().split("T")[0],h=this._calendarCache.get(u);if(h)return St(u,h.close,r)}let a=n.getTime()+s*864e5,o=new Date(a).toISOString().split("T")[0];return St(o,"16:00",r)}_monthlyCloseFromCalendar(e,r){let[n,i]=e.split("-").map(Number),s=new Date(Date.UTC(n,i,0)).getUTCDate();for(let o=s;o>=1;o--){let l=`${n}-${String(i).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return St(l,c.close,r)}let a=new Date(Date.UTC(n,i,0));for(;a.getUTCDay()===0||a.getUTCDay()===6;)a.setUTCDate(a.getUTCDate()-1);return St(a.toISOString().split("T")[0],"16:00",r)}async _ensureCalendar(e,r){if(this._calendarCache.has(e)&&this._calendarCache.has(r))return;let n=`${this._tradingUrl}/calendar?start=${e}&end=${r}`,i=await fetch(n,{headers:this._headers()});if(!i.ok){console.warn(`Alpaca calendar API returned ${i.status}, falling back to defaults`);return}let s=await i.json();for(let a of s)this._calendarCache.set(a.date,a)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);let r=encodeURIComponent(e),n=`${this._tradingUrl}/assets/${r}`,i=await fetch(n,{headers:this._headers()});if(!i.ok)return null;let s=await i.json();return this._assetCache.set(e,s),s}_parseAlpacaTimeframe(e){let r=e.match(/^(\\d+)(Min|Hour|Day|Week|Month)$/);if(r){let n=parseInt(r[1],10),i=dx[r[2]];if(i)return{periodType:i,multiplier:n}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return Ea[e.toUpperCase()]||Ea[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,r){let n=new Date(e+"T00:00:00Z");return n.setUTCDate(n.getUTCDate()+r),n.toISOString().split("T")[0]}},os=class{async getMarketData(){return[]}},fx=typeof process<"u"&&process.versions&&process.versions.node,jn=null;if(fx)try{jn=new os}catch{jn=null}var nb={Binance:new is,FMP:new ss,Alpaca:new as,...jn?{Mock:jn}:{}};function O(t){return typeof t=="string"?t:void 0}function _e(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function mx(t){let e=new Map,r=!1;for(let i=0;i<t.length;i+=1){let s=t[i].time;e.has(s)&&(r=!0),e.set(s,i)}if(!r)return t;let n=new Set(e.values());return t.filter((i,s)=>n.has(s))}function Gn(t){let e=t??{},r=e.fullContext??e,n=r.indicator??r.strategy?.config??{},i={title:O(n.title)??"Indicator",overlay:n.overlay===!0,precision:_e(n.precision),shorttitle:O(n.shorttitle),format:O(n.format)},s=r.plots??{},a=Object.entries(s).map(([l,c])=>{let u=c??{},h=u.options??{};return{key:l,title:O(u.title),style:O(h.style),options:h,data:Array.isArray(u.data)?mx(u.data):[],plot1:O(u.plot1)??O(h.plot1),plot2:O(u.plot2)??O(h.plot2)}}),o=r.strategy?yx(r.strategy):void 0;return{meta:i,plots:a,...o?{trades:o}:{}}}function yx(t){let e=[],r=Array.isArray(t.closedtrades)?t.closedtrades:[],n=Array.isArray(t.opentrades)?t.opentrades:[];for(let i of[...r,...n]){let s=i??{},a=_e(s.entry_price),o=_e(s.entry_time),l=_e(s.size);a===void 0||o===void 0||l===void 0||l===0||e.push({id:O(s.id)??`trade_${e.length}`,entry_id:O(s.entry_id)??"",entry_price:a,entry_time:o,entry_comment:O(s.entry_comment),exit_id:O(s.exit_id),exit_price:_e(s.exit_price),exit_time:_e(s.exit_time),exit_comment:O(s.exit_comment),size:l,status:s.status==="closed"?"closed":"open"})}return e}var gx={line:"line",style_line:"line",style_linebr:"line",style_area:"area",style_areabr:"area",style_stepline:"step",style_steplinebr:"step",style_stepline_diamond:"step",style_histogram:"histogram",style_columns:"columns",style_circles:"circles",style_cross:"cross",shape:"markers",char:"markers",bar:"bar",candle:"candle",background:"background",barcolor:"barcolor",hline:"hline",fill:"fill",drawing_line:"drawing_line",drawing_box:"drawing_box",label:"label",drawing_polyline:"drawing_polyline",linefill:"linefill",table:"table"};function al(t){return t==null||t===""?"line":gx[t]??"line"}function _x(t){if(typeof t!="string")return!1;let e=t.trim();if(!e)return!1;let r=e.toLowerCase();if(r==="na"||r==="nan")return!1;let n=/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})$/.exec(e);return!(n&&parseInt(n[1]??"ff",16)===0||/rgba?\\([^)]*,\\s*0(?:\\.0+)?\\s*\\)$/.test(e))}function re(t,e){return _x(t)?t.trim():e}function Cs(t){let e=t.title.trim().toLowerCase().replace(/\\s+/g,"-");return`${t.instanceId}:${t.kind}:${e}#${t.ordinal}`}var Ns="#2962ff";var xx=new Map;function P(t,e){xx.set(t,e)}function bx(t,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">${t}</svg>`}function me(t,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">${t}</svg>`}var $=bx;P("style-candles",$(\'<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"/>\'));P("style-bars",$(\'<path d="M4.5 2.5v11M2.5 5h2M4.5 11h2"/><path d="M11.5 2.5v11M9.5 4.5h2M11.5 10.5h2"/>\'));P("style-line",$(\'<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/>\'));P("style-area",$(\'<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"/>\'));P("style-baseline",$(\'<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"/>\'));P("style-heikinashi",$(\'<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"/>\'));P("indicators",$(\'<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"/>\'));P("undo",$(\'<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"/>\'));P("redo",$(\'<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"/>\'));P("objects",$(\'<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"/>\'));P("clock",$(\'<circle cx="8" cy="8" r="6.2"/><path d="M8 4.8V8l2.4 1.6"/>\'));P("datawindow",$(\'<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"/>\'));P("camera",$(\'<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"/>\'));P("gear",$(\'<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"/>\'));P("search",$(\'<circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3.5 3.5"/>\'));P("bell",$(\'<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"/>\'));P("market-open",me(\'<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"/>\'));P("market-pre",me(\'<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="m16 6-4 4-4-4"/><path d="M16 18a4 4 0 0 0-8 0"/>\'));P("market-post",me(\'<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 18-4-4-4 4"/><path d="M16 6a4 4 0 0 0-8 0"/>\'));P("market-closed",me(\'<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>\'));P("market-holiday",me(\'<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"/>\'));P("chevron-right",$(\'<path d="m6 3.5 4.5 4.5L6 12.5"/>\'));P("chevron-down",$(\'<path d="M3.5 6 8 10.5 12.5 6"/>\'));P("chevron-up",$(\'<path d="M3.5 10 8 5.5 12.5 10"/>\'));P("chevrons-right",$(\'<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"/>\'));P("chevrons-left",$(\'<path d="M12 3.5 7.5 8l4.5 4.5"/><path d="M7.5 3.5 3 8l4.5 4.5"/>\'));P("check",$(\'<path d="m2.8 8.4 3.4 3.4 7-7.6"/>\'));P("close",$(\'<path d="m3.8 3.8 8.4 8.4M12.2 3.8l-8.4 8.4"/>\'));P("eye",$(\'<path d="M1.5 8s2.5-4.2 6.5-4.2S14.5 8 14.5 8 12 12.2 8 12.2 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="1.8"/>\'));P("eye-off",$(\'<path d="M1.5 8s2.5-4.2 6.5-4.2S14.5 8 14.5 8 12 12.2 8 12.2 1.5 8 1.5 8z" opacity="0.45"/><path d="m3 13 10-10"/>\'));P("lock",$(\'<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"/>\'));P("unlock",$(\'<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"/>\'));P("trash",$(\'<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"/>\'));P("group",$(\'<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"/>\'));P("ungroup",$(\'<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"/>\'));P("clone",$(\'<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"/>\'));P("arrow-up",$(\'<path d="M8 13.2V3M4.2 6.8 8 3l3.8 3.8"/>\'));P("arrow-down",$(\'<path d="M8 2.8V13M4.2 9.2 8 13l3.8-3.8"/>\'));P("move-vertical",$(\'<path d="M8 2.5v11M5 5.5 8 2.5l3 3M5 10.5l3 3 3-3"/>\'));P("move",$(\'<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"/>\'));P("pen",$(\'<path d="m10.8 2.2 3 3-8 8-3.6.6.6-3.6z"/><path d="m9.2 3.8 3 3"/>\'));P("wave",$(\'<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"/>\'));P("folder-plus",$(\'<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"/>\'));P("folder-minus",$(\'<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"/>\'));P("collapse",$(\'<path d="M3 8h10"/>\'));P("expand",$(\'<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"/>\'));P("maximize",$(\'<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"/>\'));P("restore",$(\'<path d="M6.2 2.5v3.7H2.5M9.8 13.5V9.8h3.7M13.5 6.2H9.8V2.5M2.5 9.8h3.7v3.7"/>\'));P("star",$(\'<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"/>\'));P("star-filled",$(\'<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"\'));P("grip",$(\'<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"\'));P("kebab",$(\'<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"\'));P("reset",$(\'<rect x="6" y="6" width="4" height="4" rx="0.8"/><path d="M2.2 8a5.8 5.8 0 1 0 1.9-4.3L2.2 5.3"/><path d="M2.2 2.2v3.1h3.1"/>\'));P("pane-collapse",$(\'<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"/>\'));P("pane-expand",$(\'<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"/>\'));P("cursor",me(\'<path d="M5 3l6 16 2-6 6-2z"/>\',\'fill="currentColor" stroke="none"\'));P("ruler",me(\'<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"/>\'));P("magnet",me(\'<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"/>\'));P("eraser",me(\'<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"/>\'));P("pen-lock",me(\'<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"/>\'));P("brush",me(\'<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"/>\'));P("bucket",me(\'<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"/>\'));P("type",me(\'<path d="M5 6V4.5h14V6"/><path d="M12 4.5v15"/><path d="M9.5 19.5h5"/>\'));P("bold",me(\'<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"\'));P("italic",me(\'<path d="M15 5h-5M14 19H9M14.5 5 10 19"/>\',\'stroke-width="2.2"\'));P("price-delta",me(\'<path d="M12 4v16"/><path d="M8 8l4-4 4 4"/><path d="M8 16l4 4 4-4"/>\'));P("date-delta",me(\'<path d="M4 12h16"/><path d="M8 8l-4 4 4 4"/><path d="M16 8l4 4-4 4"/>\'));P("bring-front",me(\'<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"/>\'));P("send-back",me(\'<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"/>\'));P("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>\');P("bands",me(\'<path d="M3 6h18"/><path d="M3 18h18"/><path d="M3 12h18" stroke-dasharray="3 3"/>\'));P("dedekind",me(\'<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"/>\'));P("sonic",me(\'<circle cx="15" cy="12" r="4"/><circle cx="12" cy="12" r="2.5"/><path d="M8 5v14"/>\'));P("supersonic",me(\'<circle cx="16" cy="12" r="3.5"/><path d="M6 12 15 6M6 12 15 18"/>\'));var Yn=class{constructor(){$s(this,"ordinals",new Map)}next(e,r,n){let i=`${r}:${n.trim().toLowerCase()}`,s=this.ordinals.get(i)??0;return this.ordinals.set(i,s+1),Cs({instanceId:e,kind:r,title:n,ordinal:s})}};function br(t){let e=t.data;if(e.length===0)return[];let r=e[e.length-1]?.value;return Array.isArray(r)?r:[]}function he(t){if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(t&&typeof t=="object"){let e=t;if(Array.isArray(e.data)){let r=typeof e.offset=="number"?e.offset:0,n=e.data[e.data.length-1-r];return typeof n=="number"&&Number.isFinite(n)?n:void 0}}}function Zn(t){let e=(O(t)??"").toLowerCase();return e==="bt"||e.includes("time")?"bar_time":"bar_index"}function ol(t){let e=(O(t)??"none").toLowerCase();return e==="b"||e==="both"?"both":e==="l"||e==="left"?"left":e==="r"||e==="right"?"right":"none"}function Is(t){let e=(O(t)??"").toLowerCase();return e.includes("dot")?"dotted":e.includes("dash")?"dashed":"solid"}function ll(t){if(t===void 0)return{invisible:!1};if(t===null)return{invisible:!0};if(typeof t=="number")return{invisible:!0};if(typeof t=="string"){if(t==="")return{invisible:!1};let e=re(t);return e?{color:e,invisible:!1}:{invisible:!0}}return{invisible:!0}}function ks(t,e){let r=he(t.x1),n=he(t.y1),i=he(t.x2),s=he(t.y2);if(r===void 0||n===void 0||i===void 0||s===void 0)return null;let a=(O(t.style)??"").toLowerCase(),o=a==="style_arrow_left"||a==="style_arrow_both",l=a==="style_arrow_right"||a==="style_arrow_both",{color:c,invisible:u}=ll(t.color);return{id:e,paneId:"unrouted",xloc:Zn(t.xloc),x1:r,y1:n,x2:i,y2:s,extend:ol(t.extend),color:c,invisible:u,width:Math.max(1,he(t.width)??1),style:Is(t.style),arrowLeft:o,arrowRight:l,overlay:t.force_overlay===!0}}function cl(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=ks(i,r.next(e,"line",String(i.id??n.length)));s&&n.push(s)}return n}function ul(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=i.line1,a=i.line2;if(!s||!a)continue;let o=r.next(e,"linefill",String(i.id??n.length)),l=ks(s,`${o}:a`),c=ks(a,`${o}:b`);!l||!c||n.push({id:o,paneId:"unrouted",line1:l,line2:c,color:re(i.color),overlay:i.force_overlay===!0})}return n}function pl(t){return t<=0?"auto":t<=9?"tiny":t<=12?"small":t<=17?"normal":t<=28?"large":"huge"}function vx(t){if(typeof t=="number"&&Number.isFinite(t))return pl(t);let e=(O(t)??"").toLowerCase();return e==="tiny"||e==="small"||e==="normal"||e==="large"||e==="huge"?e:"auto"}function As(t){let e=(O(t)??"").toLowerCase();return e==="left"||e==="right"?e:"center"}function hl(t){let e=(O(t)??"").toLowerCase();return e==="top"||e==="bottom"?e:"center"}function Ts(t){return(O(t)??"").toLowerCase().includes("mono")?"monospace":"default"}function dl(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=he(i.left),a=he(i.top),o=he(i.right),l=he(i.bottom);if(s===void 0||a===void 0||o===void 0||l===void 0)continue;let c=(O(i.text_formatting)??"").toLowerCase(),u=O(i.text);n.push({id:r.next(e,"box",String(i.id??n.length)),paneId:"unrouted",xloc:Zn(i.xloc),left:s,top:a,right:o,bottom:l,extend:ol(i.extend),bgColor:re(i.bgcolor),borderColor:re(i.border_color),borderWidth:Math.max(0,he(i.border_width)??1),borderStyle:Is(i.border_style),text:u&&u.length>0?u:void 0,textColor:re(i.text_color),textSize:vx(i.text_size),hAlign:As(i.text_halign),vAlign:hl(i.text_valign),wrap:(O(i.text_wrap)??"").toLowerCase().includes("auto"),fontFamily:Ts(i.text_font_family),bold:c.includes("bold"),italic:c.includes("italic"),overlay:i.force_overlay===!0})}return n}var wx=["label_up","label_down","label_left","label_right","label_center","label_lower_left","label_lower_right","label_upper_left","label_upper_right","circle","square","diamond","flag","arrowup","arrowdown","triangleup","triangledown","cross","xcross","text_outline","none"];function Ex(t){let e=(O(t)??"").toLowerCase().replace(/^style_/,"");return wx.includes(e)?e:"label_down"}function Sx(t){let e=(O(t)??"").toLowerCase();return e==="ab"||e.includes("above")?"abovebar":e==="bl"||e.includes("below")?"belowbar":"price"}function fl(t){if(typeof t=="number"&&Number.isFinite(t))return pl(t);let e=(O(t)??"").toLowerCase();return e==="auto"||e==="tiny"||e==="small"||e==="large"||e==="huge"?e:"normal"}function ml(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=he(i.x),a=Sx(i.yloc),o=he(i.y);if(s===void 0||a==="price"&&o===void 0)continue;let l=O(i.text),c=O(i.tooltip),{color:u,invisible:h}=ll(i.color);n.push({id:r.next(e,"label",String(i.id??n.length)),paneId:"unrouted",xloc:Zn(i.xloc),x:s,y:o??0,yloc:a,text:l&&l.length>0?l:void 0,style:Ex(i.style),color:u,noFill:h,textColor:re(i.textcolor),size:fl(i.size),textAlign:As(i.textalign),tooltip:c&&c.length>0?c:void 0,fontFamily:Ts(i.text_font_family),overlay:i.force_overlay===!0})}return n}function yl(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=Array.isArray(i.points)?i.points:[],a=Zn(i.xloc),o=[];for(let c of s){let u=he(c.price),h=he(c.index),p=he(c.time),d=a==="bar_time"?p:h,f=a==="bar_time"?h:p,m,x;if(d!==void 0)m=d,x=a;else if(f!==void 0)m=f,x=a==="bar_time"?"bar_index":"bar_time";else continue;u!==void 0&&o.push({xloc:x,x:m,price:u})}if(o.length<2)continue;let l=(O(i.line_style)??"").toLowerCase();n.push({id:r.next(e,"polyline",String(i.id??n.length)),paneId:"unrouted",points:o,curved:i.curved===!0,closed:i.closed===!0,lineColor:re(i.line_color),fillColor:re(i.fill_color),lineWidth:Math.max(1,he(i.line_width)??1),lineStyle:Is(i.line_style),arrowLeft:l==="style_arrow_left"||l==="style_arrow_both",arrowRight:l==="style_arrow_right"||l==="style_arrow_both",overlay:i.force_overlay===!0})}return n}var Cx=["top_left","top_center","top_right","middle_left","middle_center","middle_right","bottom_left","bottom_center","bottom_right"];function Nx(t){let e=(O(t)??"").toLowerCase();return Cx.includes(e)?e:"top_right"}function kx(t){if(!t||typeof t!="object")return null;let e=t,r=O(e.text),n=O(e.tooltip),i=(O(e.text_formatting)??"").toLowerCase();return{text:r&&r.length>0?r:void 0,textColor:re(e.text_color),bgColor:re(e.bgcolor),hAlign:As(e.text_halign),vAlign:hl(e.text_valign),textSize:fl(e.text_size),fontFamily:Ts(e.text_font_family),tooltip:n&&n.length>0?n:void 0,bold:i.includes("bold"),italic:i.includes("italic"),merged:e._merged===!0}}function Ix(t){if(!Array.isArray(t))return[];let e=[];for(let r of t){if(!r||typeof r!="object")continue;let n=r,i=he(n.startCol??n.start_column??n.startColumn),s=he(n.startRow??n.start_row),a=he(n.endCol??n.end_column??n.endColumn),o=he(n.endRow??n.end_row);i===void 0||s===void 0||a===void 0||o===void 0||e.push({startCol:Math.min(Math.round(i),Math.round(a)),startRow:Math.min(Math.round(s),Math.round(o)),endCol:Math.max(Math.round(i),Math.round(a)),endRow:Math.max(Math.round(s),Math.round(o))})}return e}function gl(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let a=(Array.isArray(i.cells)?i.cells:[]).map(o=>(Array.isArray(o)?o:[]).map(l=>kx(l)));n.push({id:r.next(e,"table",String(i.id??n.length)),paneId:"unrouted",position:Nx(i.position),columns:Math.max(0,Math.round(he(i.columns)??0)),rows:Math.max(0,Math.round(he(i.rows)??0)),bgColor:re(i.bgcolor),frameColor:re(i.frame_color),frameWidth:Math.max(0,he(i.frame_width)??0),borderColor:re(i.border_color),borderWidth:Math.max(0,he(i.border_width)??0),cells:a,merges:Ix(i.merges)})}return n}var _l=Ns;function xl(t,e){let r=new Yn,n=[],i=[],s=[],a=[],o=[],l=[],c=[],u=[],h=[],p=[],d=[],f=[],m=new Map,x=[];for(let v of t.plots){let E=al(v.style),A=v.title??v.key;switch(E){case"skip":break;case"barcolor":for(let C of v.data){let D=re(C.options?.color);D&&f.push({time:C.time,color:D})}break;case"fill":x.push(v);break;case"hline":{let C=Lx(v,A,e,r);C&&o.push(C);break}case"background":a.push(...Ox(v,A,e,r));break;case"drawing_line":l.push(...cl(v,e,r));break;case"drawing_box":c.push(...dl(v,e,r));break;case"label":u.push(...ml(v,e,r));break;case"drawing_polyline":h.push(...yl(v,e,r));break;case"linefill":p.push(...ul(v,e,r));break;case"table":d.push(...gl(v,e,r));break;case"markers":u.push(...Vx(v,e,r));break;default:{let C=r.next(e,E,A);m.set(v.key,C),i.push(Tx(E,v,C,A))}}}for(let v of x){let E=v.plot1?m.get(v.plot1):void 0,A=v.plot2?m.get(v.plot2):void 0;if(!E||!A){n.push(`fill "${v.key}" references unknown plots (${v.plot1??"?"}/${v.plot2??"?"})`);continue}s.push({id:r.next(e,"fill",v.title??v.key),paneId:"unrouted",fromSeriesId:E,toSeriesId:A,...Bx(v)})}let b=t.trades?Ax(t.trades):[];return{model:{id:e,title:t.meta.title,overlay:t.meta.overlay,paneHint:t.meta.overlay?"price":"new",series:i,fills:s,backgrounds:a,priceLines:o,lines:l,boxes:c,labels:u,polylines:h,linefills:p,tables:d,barColors:f.length?f:void 0,trades:b.length?b:void 0,inputs:[],inputValues:{}},warnings:n}}function Ax(t){let e=new Map,r=n=>{let i=`${n.time}|${n.side}|${n.label??""}`,s=e.get(i);if(!s){e.set(i,n);return}s.qty=(s.qty??0)+(n.qty??0),n.kind==="entry"&&s.kind==="exit"&&(s.kind="entry",s.price=n.price,s.tradeId=n.tradeId)};for(let n of t){let i=n.size>0,s=Math.abs(n.size);r({time:n.entry_time,price:n.entry_price,side:i?"buy":"sell",kind:"entry",label:n.entry_comment??n.entry_id,qty:s,tradeId:n.id}),n.status==="closed"&&n.exit_time!=null&&n.exit_price!=null&&r({time:n.exit_time,price:n.exit_price,side:i?"sell":"buy",kind:"exit",label:n.exit_comment??n.exit_id,qty:s,tradeId:n.id})}return[...e.values()].sort((n,i)=>n.time-i.time)}function Tx(t,e,r,n){if(t==="candle"||t==="bar"){let c={id:r,title:n,paneId:"unrouted",kind:t,bars:Rx(e)},u=Dx(e);return u&&(c.barColors=u),c}let i=t,s=re(Fx(e)),a=O(e.options.display),o=a==="none"||a==="data_window"||!s,l=_e(e.options.linewidth)??(i==="line"||i==="step"?2:1);return{id:r,title:n,paneId:"unrouted",kind:i,points:Px(Mx(e),_e(e.options.offset)),style:{color:s??_l,width:l,lineStyle:vl(e.options.linestyle)??"solid"},visible:!o}}function Dx(t){let e=!1,r=t.data.map(n=>{let i=n.options??{},s=re(i.color),a=re(i.wickcolor),o=re(i.bordercolor);return!s&&!a&&!o?null:(e=!0,{color:s,wickColor:a,borderColor:o})});return e?r:void 0}function Mx(t){return t.data.map(e=>{let r=typeof e.value=="number"&&Number.isFinite(e.value)?e.value:null,n=re(e.options?.color);return n?{time:e.time,value:r,color:n}:{time:e.time,value:r}})}function bl(t){let e=[];for(let r=1;r<t.length;r+=1){let n=t[r].time-t[r-1].time;n>0&&e.push(n)}return e.length===0?0:(e.sort((r,n)=>r-n),e[e.length>>1]??0)}function Px(t,e){if(!e)return t;let r=e*bl(t);return r?t.map(n=>({...n,time:n.time+r})):t}function Rx(t){let e=[];for(let r of t.data){let n=r.value;!Array.isArray(n)||n.length<4||e.push({time:r.time,open:n[0]??0,high:n[1]??0,low:n[2]??0,close:n[3]??0})}return e}function Fx(t){for(let e of t.data)if(typeof e.options?.color=="string"&&e.options.color)return e.options.color;return O(t.options.color)}function Bx(t){if(t.options.gradient===!0||t.data.some(s=>s.options&&(typeof s.options.top_color=="string"||typeof s.options.bottom_color=="string")))return{gradient:t.data.map(a=>{let o=a.options??{},l=_e(o.top_value),c=_e(o.bottom_value),u=typeof o.top_color=="string"?o.top_color:void 0,h=typeof o.bottom_color=="string"?o.bottom_color:void 0;return l===void 0||c===void 0||!u&&!h?null:{topValue:l,bottomValue:c,topColor:u??"rgba(0,0,0,0)",bottomColor:h??"rgba(0,0,0,0)"}})};let r=t.data.map(s=>re(s.options?.color)??null),n=new Set(r.filter(s=>s!==null)),i=r.some(s=>s===null);return n.size===0?{color:re(t.options.color)}:n.size===1&&!i?{color:[...n][0]}:{colors:r}}function Lx(t,e,r,n){let i;for(let s of t.data)if(typeof s.value=="number"&&Number.isFinite(s.value)){i=s.value;break}return i===void 0?null:{id:n.next(r,"hline",e),paneId:"unrouted",price:i,color:re(t.options.color),lineStyle:vl(t.options.linestyle),title:e,width:_e(t.options.linewidth)}}function vl(t){let e=O(t)?.replace(/^(hline\\.style_|plot\\.linestyle_|linestyle_|style_)/,"");return e==="dashed"||e==="dotted"?e:void 0}function Ox(t,e,r,n){let i=[],s=t.data,a=s.length>1?(s[1]?.time??0)-(s[0]?.time??0):0,o=0;for(;o<s.length;){let l=s[o],c=re(l.options?.color);if(l.value===!0&&c){let u=l.time,h=l.time,p=o;for(;p+1<s.length;){let d=s[p+1];if(d.value===!0&&re(d.options?.color)===c)h=d.time,p+=1;else break}i.push({id:n.next(r,"background",e),paneId:"unrouted",from:u,to:h+a,color:c}),o=p+1}else o+=1}return i}function Vx(t,e,r){let n=_e(t.options.offset),i=n?n*bl(t.data):0,s=[];for(let a of t.data){let o=a.value,l=typeof o=="number"&&Number.isFinite(o);if(o!==!0&&!l)continue;let c=a.options??t.options,u=O(c.text)??O(t.options.text);s.push({id:r.next(e,"label",`${t.key}#${s.length}`),paneId:"unrouted",xloc:"bar_time",x:a.time+i,y:l?o:0,yloc:jx(O(c.location)??O(t.options.location)),text:u&&u.trim().length>0?u:void 0,style:$x(O(c.shape)??O(t.options.shape)),color:re(c.color)??re(t.options.color)??_l,textColor:re(c.textcolor)??re(t.options.textcolor),size:Wx(O(c.size)??O(t.options.size)),textAlign:"center",fontFamily:"default"})}return s}function jx(t){let e=(t??"").toLowerCase();return e==="absolute"?"price":e==="top"?"top":e==="bottom"?"bottom":e.includes("below")?"belowbar":"abovebar"}function $x(t){switch((t??"").toLowerCase().replace(/^shape_/,"").replace(/_/g,"")){case"diamond":return"diamond";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"labelup":return"label_up";case"labeldown":return"label_down";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"square":return"square";case"cross":return"cross";case"xcross":return"xcross";case"flag":return"flag";default:return"circle"}}function Wx(t){let e=(t??"").toLowerCase();return e==="tiny"||e==="small"||e==="large"||e==="huge"||e==="normal"?e:"small"}function Ux(t){switch(t){case"int":return"int";case"float":return"float";case"bool":return"bool";case"source":return"source";case"color":return"color";case"price":return"price";case"time":return"time";case"session":return"session";case"timeframe":return"timeframe";case"symbol":return"symbol";case"text_area":return"text_area";default:return"string"}}function qx(t){return t==="int"||t==="float"||t==="price"||t==="time"}var wl={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#F23645",silver:"#B2B5BE",teal:"#089981",white:"#FFFFFF",yellow:"#FDD835"};function zx(t){let e=t.trim().toLowerCase().replace(/^color\\./,"");return wl[e]??t}function Kx(t){if(typeof t!="string")return;let e=/^color\\.([a-z]+)$/i.exec(t.trim());return e?wl[e[1].toLowerCase()]:void 0}function Hx(t){return(t.type==="string"||t.type==null)&&Kx(t.defval)!==void 0}function Gx(t,e){if(e==="bool")return!!t;if(qx(e))return typeof t=="number"?t:Number(t)||0;let r=typeof t=="string"?t:t==null?"":String(t);return e==="color"?zx(r):r}function El(t){return t.map((e,r)=>{let n=Hx(e)?"color":Ux(e.type);return{key:e.varId??e.title??`input${r}`,title:e.title??e.varId??`Input ${r+1}`,type:n,defval:Gx(e.defval,n),min:e.minval,max:e.maxval,step:e.step,options:Array.isArray(e.options)?e.options.map(i=>String(i)):void 0,group:e.group,inline:e.inline,tooltip:e.tooltip}})}function Cl(t,e){let r=El(Qt.from(t).getInputsMeta()),n=/overlay\\s*[:=]\\s*true/.test(t),i=t.match(/(?:indicator|strategy)\\(\\s*["\']([^"\']+)["\']/)?.[1]??"Indicator",s=/chart\\.(left|right)_visible_bar(_time)?\\b/.test(t);return{language:"pine",inputs:r,meta:{title:i,overlay:n},reactsToViewport:s,token:{source:t,instanceId:e}}}function Ds(t,e,r){let n=JSON.stringify(r);return(t.lastKey!==n||!t.lastInd)&&(t.lastInd=new Qt(e,r),t.lastKey=n),t.lastInd}async function Nl(t){let{ind:e,bars:r,market:n,visibleRange:i,prepared:s,instanceId:a,inputs:o,fetchSeries:l}=t,c=Ms(r),u={getMarketData:(f,m,x,b,w)=>Il(f,m,n)?Promise.resolve(c):Al(l,f,m,x,b,w),getSymbolInfo:async f=>Dl(n,f)},h=new Wt(u,Ps(n),n.timeframe,c.length);await h.ready(),i&&h.setVisibleRange(i.left,i.right);let p=await h.run(e),d=typeof h.usesVisibleRange=="function"?h.usesVisibleRange():!1;return{model:kl(p,a,s,o,r[0]?.time),alerts:(p.alerts??[]).map(Ml),warnings:(p.warnings??[]).map(Pl),reactsToViewport:d,ctx:p}}function kl(t,e,r,n,i){let{model:s}=xl(Gn(t),e);return s.inputs=r.inputs,s.inputValues={...Zx(r.inputs),...n},i!=null&&(s.anchorTime=i),s}function Ms(t){return t.map(e=>({openTime:e.time,open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume??0}))}function Ps(t){return t.chartStyle==="heikinashi"?`${t.symbol};heikinashi`:t.symbol}function Il(t,e,r){return(t==null||t===Ps(r))&&(e==null||e===r.timeframe)}async function Al(t,e,r,n,i,s){if(!t||!e||!r)return[];let a=await t(e,r,{from:i,to:s,limit:n});return Ms(a)}function Yx(t,e,r){let n="",i=!1;return{markDirty:()=>{i=!0},getMarketData:async(s,a,o,l,c)=>{if(!Il(s,a,e()))return Al(r,s,a,o,l,c);let u=Ms(t());if(l==null)return u;let h=u.filter(f=>(f.openTime??0)>=l),p=h[h.length-1],d=p?`${h.length}|${p.openTime}|${p.close}|${p.high}|${p.low}|${p.volume}`:"";return!i&&d===n?[]:(i=!1,n=d,h)},getSymbolInfo:async s=>Dl(e(),s)}}function Tl(t){let e=t.bars(),r=Ds(t.cache,t.token.source,t.inputs),n=e[0]?.time,i=Math.max(1,e.length),s=Yx(t.bars,t.market,t.fetchSeries),a=new Wt(s,Ps(t.market()),t.market().timeframe,i);t.visibleRange&&a.setVisibleRange(t.visibleRange.left,t.visibleRange.right);let o=a.stream(r,{live:!0,interval:1e3,pageSize:i}),l=!1,c=null;return o.on("data",u=>{if(!l){c=u;try{t.onModel(kl(u,t.token.instanceId,t.prepared,t.inputs,n))}catch(h){t.onError?.(h instanceof Error?h:new Error(String(h)))}}}),o.on("alert",u=>t.onAlert?.(Ml(u))),o.on("warning",u=>t.onWarning?.(Pl(u))),o.on("error",u=>t.onError?.(u instanceof Error?u:new Error(String(u)))),{stop:()=>{l=!0,o.stop()},setVisibleRange:(u,h)=>{a.setVisibleRange(u,h),s.markDirty()},markDirty:()=>s.markDirty(),lastCtx:()=>c}}function Dl(t,e){let r=e&&e.split(";")[0];return r&&r!==t.symbol?Sl({symbol:r,timeframe:t.timeframe}):Sl(t)}function Sl(t){if(t.symbolInfo)return t.symbolInfo;let e=t.symbol,r=e.replace(/(USDT|USDC|USD|PERP|BUSD)$/i,"")||e;return{ticker:e,tickerid:e,main_tickerid:e,description:e,prefix:"",root:e,type:"crypto",basecurrency:r,currency:"USD",timezone:"UTC",session:"regular",mintick:.01,minmove:1,pointvalue:1,pricescale:100}}function Zx(t){let e={};for(let r of t)e[r.key]=r.defval;return e}function Ml(t){return{id:String(t.id??""),message:String(t.message??""),title:t.title,time:Number(t.time??0),barIndex:Number(t.bar_index??0),freq:t.freq}}function Pl(t){return{message:String(t.message??""),method:t.method,bar:Number(t.bar??0)}}var Qe=t=>_e(t)??0;function Rl(t){if(t==null||typeof t!="object")return;let e=t;return{position:Qe(e.position_size),avgPrice:Qe(e.position_avg_price),equity:Qe(e.equity),openPnl:Qe(e.openprofit),netPnl:Qe(e.netprofit),grossProfit:Qe(e.grossprofit),grossLoss:Qe(e.grossloss),wins:Qe(e.wintrades),losses:Qe(e.losstrades),even:Qe(e.eventrades),maxDrawdown:Qe(e.max_drawdown),maxRunup:Qe(e.max_runup),initialCapital:Qe(e.initial_capital)}}function Fl(t){if(t==null||typeof t!="object")return[];let e=t,r=[];for(let n of[...Array.isArray(e.closedtrades)?e.closedtrades:[],...Array.isArray(e.opentrades)?e.opentrades:[]]){let i=n??{},s=_e(i.entry_price),a=_e(i.entry_time),o=_e(i.size);if(s===void 0||a===void 0||o===void 0||o===0)continue;let l=_e(i.exit_price),c=_e(i.exit_time);r.push({id:O(i.id)??`trade_${r.length}`,side:o>0?"long":"short",qty:Math.abs(o),entry:{id:O(i.entry_id)??"",time:a,price:s,...O(i.entry_comment)!==void 0?{comment:O(i.entry_comment)}:{}},...l!==void 0&&c!==void 0?{exit:{id:O(i.exit_id)??"",time:c,price:l,...O(i.exit_comment)!==void 0?{comment:O(i.exit_comment)}:{}}}:{},open:i.status!=="closed"})}return r}function Bl(t){try{return structuredClone(t)}catch{return}}function Xx(t){let e=Array.isArray(t)?t:t!=null&&typeof t=="object"&&Array.isArray(t.data)?t.data:null;return Bl(e?e[e.length-1]:t)}function Qx(t){return t.replace(/^glb\\d+_/,"")}function Rs(t,e){if(t)for(let[r,n]of Object.entries(t)){if(r.startsWith("_"))continue;let i=Xx(n);i!==void 0&&(e[Qx(r)]=i)}}function Ll(t,e,r){let n=t??{},i=n.fullContext??n,s=p=>!r||r.includes(p),a=s("meta")||s("plots")?Gn(t):null,o={};if(a&&s("plots"))for(let p of a.plots)p.key.startsWith("__")||(o[p.key]=p.data.map(d=>({time:d.time,value:Bl(d.value)??null})));let l={};s("variables")&&(Rs(i.const,l),Rs(i.var,l),Rs(i.let,l));let c=s("strategy")?Rl(i.strategy):void 0,u=s("trades")&&i.strategy?Fl(i.strategy):void 0,h=typeof i.idx=="number"?i.idx:typeof i.length=="number"?i.length-1:-1;return{language:"pine",phase:e,barIndex:h,meta:a&&s("meta")?{title:a.meta.title,overlay:a.meta.overlay,precision:a.meta.precision,shorttitle:a.meta.shorttitle}:{title:"",overlay:!1},plots:o,variables:l,...c?{strategy:c}:{},...u&&u.length>0?{trades:u}:{},warnings:s("warnings")?(i.warnings??[]).map(p=>({message:String(p.message??""),method:typeof p.method=="string"?p.method:void 0,bar:Number(p.bar??0)})):[]}}var Ol=self,De=t=>Ol.postMessage(t),qt=new Map,Bs=new Map,Jx=0,Vl=(t,e,r)=>new Promise((n,i)=>{let s=++Jx;Bs.set(s,{resolve:n,reject:i}),De({kind:"fetchSeries",reqId:s,symbol:t,timeframe:e,range:r})});function Xn(t){t.chain=t.chain.then(()=>tb(t))}function eb(t,e){let r=t.bars[t.bars.length-1];r&&e.time===r.time?t.bars[t.bars.length-1]=e:(!r||e.time>r.time)&&t.bars.push(e)}function Fs(t){t.stream?.stop(),t.stream=null,!(t.stopped||t.bars.length===0)&&(t.stream=Tl({token:t.prepared.token,cache:t.cache,prepared:t.prepared,inputs:t.inputs,bars:()=>t.bars,market:()=>t.market,fetchSeries:Vl,visibleRange:t.visibleRange,onModel:e=>{t.stopped||De({kind:"model",sessionId:t.id,model:e})},onAlert:e=>De({kind:"alert",sessionId:t.id,alert:e}),onWarning:e=>De({kind:"warning",sessionId:t.id,warning:e}),onError:e=>De({kind:"error",sessionId:t.id,message:e.message})}))}async function tb(t){if(!t.stopped)try{let e=t.prepared.token,r=await Nl({ind:Ds(t.cache,e.source,t.inputs),bars:t.bars,market:t.market,visibleRange:t.visibleRange,prepared:t.prepared,instanceId:e.instanceId,inputs:t.inputs,fetchSeries:Vl});if(t.stopped)return;De({kind:"reactsToViewport",sessionId:t.id,value:r.reactsToViewport});for(let n of r.alerts)De({kind:"alert",sessionId:t.id,alert:n});for(let n of r.warnings)De({kind:"warning",sessionId:t.id,warning:n});t.lastCtx=r.ctx,De({kind:"model",sessionId:t.id,model:r.model}),De({kind:"done",sessionId:t.id})}catch(e){De({kind:"error",sessionId:t.id,message:e instanceof Error?e.message:String(e)})}}Ol.addEventListener("message",t=>{let e=t.data;switch(e.kind){case"prepare":try{De({kind:"prepared",reqId:e.reqId,prepared:Cl(e.source,e.instanceId)})}catch(r){De({kind:"prepared",reqId:e.reqId,error:r instanceof Error?r.message:String(r)})}return;case"execute":{let r={id:e.sessionId,mode:e.mode??"static",prepared:e.prepared,market:e.market,bars:e.bars,inputs:e.inputs,visibleRange:e.visibleRange,cache:{},stopped:!1,deferred:e.historyState==="backfill",chain:Promise.resolve(),stream:null,lastCtx:null};if(qt.set(r.id,r),r.mode==="live"){r.deferred||Fs(r);return}r.deferred?De({kind:"done",sessionId:r.id}):Xn(r);return}case"update":{let r=qt.get(e.sessionId);if(!r)return;if(r.inputs={...r.inputs,...e.inputs},r.mode==="live"){r.deferred||Fs(r);return}r.deferred?De({kind:"done",sessionId:r.id}):Xn(r);return}case"setVisibleRange":{let r=qt.get(e.sessionId);if(!r)return;if(r.visibleRange=e.range,r.mode==="live"){r.stream?.setVisibleRange(e.range.left,e.range.right);return}r.deferred?De({kind:"done",sessionId:r.id}):Xn(r);return}case"notifyBars":{let r=qt.get(e.sessionId);if(!r||r.mode==="live")return;r.bars=e.bars,r.deferred=!1,Xn(r);return}case"bars":{let r=qt.get(e.sessionId);if(!r||r.mode!=="live")return;if(e.restart){r.bars=e.bars,r.deferred=!1,Fs(r);return}for(let n of e.bars)eb(r,n);return}case"getContext":{let r=qt.get(e.sessionId),n=r?r.mode==="live"?r.stream?.lastCtx()??null:r.lastCtx:null,i=!r||r.stopped?"idle":r.mode==="live"?"streaming":"idle";De({kind:"contextResult",reqId:e.reqId,snapshot:n==null?null:Ll(n,i,e.select)});return}case"stop":{let r=qt.get(e.sessionId);r&&(r.stopped=!0,r.stream?.stop()),qt.delete(e.sessionId);return}case"fetchSeriesResult":{let r=Bs.get(e.reqId);if(!r)return;Bs.delete(e.reqId),e.error?r.reject(new Error(e.error)):r.resolve(e.bars??[]);return}}});})();\n';
|
|
1345
|
+
var worker_default = '"use strict";(()=>{var ql=Object.defineProperty;var zl=(t,e,r)=>e in t?ql(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Ws=(t,e,r)=>zl(t,typeof e!="symbol"?e+"":e,r);function Kl(t){return e=>new q(e.array.map(r=>Math.abs(r)),e.type,t)}function Hl(t){return e=>{let r=0,n=0;for(let i of e.array){let s=Number(i);isNaN(s)||(n++,r+=(s-r)/n)}return n===0?NaN:t.precision(r)}}function Gl(t){return(e,r)=>{let n=e.array,i=0,s=n.length-1;for(;i<=s;){let a=Math.floor((i+s)/2),o=n[a];if(o===r)return a;o<r?i=a+1:s=a-1}return-1}}function Yl(t){return(e,r)=>{let n=e.array,i=0,s=n.length;for(;i<s;){let a=Math.floor((i+s)/2);n[a]<r?i=a+1:s=a}return i<n.length&&n[i]===r?i:i-1}}function Zl(t){return(e,r)=>{let n=e.array,i=0,s=n.length;for(;i<s;){let a=Math.floor((i+s)/2);n[a]<=r?i=a+1:s=a}return i>0&&n[i-1]===r?i-1:i}}function Xl(t){return e=>{e.array.length=0}}function Ql(t){return(e,r)=>(e.array.push(...r.array),e)}function Jl(t){return e=>new q([...e.array],e.type,t)}function ec(t){return(e,r,n=!0)=>{let i=e.array,s=r.array;if(i.length!==s.length)return NaN;let a=0,o=0,l=0,c=[];for(let f=0;f<i.length;f++){let m=Number(i[f]),x=Number(s[f]);!isNaN(m)&&m!==null&&m!==void 0&&!isNaN(x)&&x!==null&&x!==void 0&&(a+=m,o+=x,l++,c.push(f))}if(l===0)return NaN;let u=a/l,h=o/l,p=0;for(let f of c){let m=Number(i[f]),x=Number(s[f]);p+=(m-u)*(x-h)}let d=n?l:l-1;return d<=0?NaN:t.precision(p/d)}}function tc(t){return e=>e.array.every(r=>!isNaN(r)&&r)}function rc(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?z.int:z.float:t.every(e=>typeof e=="string")?z.string:t.every(e=>typeof e=="boolean")?z.bool:z.any}function it(t){return typeof t=="number"?Number.isInteger(t)?z.int:z.float:typeof t=="string"?z.string:typeof t=="boolean"?z.bool:z.any}function $r(t,e){if(typeof t=="number"&&isNaN(t)||e===z.any)return!0;switch(e){case z.int:return Number.isInteger(t)||isNaN(t);case z.float:return typeof t=="number";case z.string:return typeof t=="string";case z.bool:return typeof t=="boolean";case z.box:case z.label:case z.line:case z.linefill:case z.table:case z.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function nc(t){return(e,r,n=0,i)=>{let s=e.array.length,a=i!==void 0?Math.min(i,s):s;for(let o=n;o<a;o++){if(!$r(r,e.type))throw new Error(`Cannot call \'array.fill\' with argument \'value\'=\'${r}\'. An argument of \'literal ${typeof r}\' type was used but a \'${e.type}\' is expected.`);e.array[o]=typeof r=="number"?t.precision(r):r}}}function ic(t){return e=>e.array.length>0?e.array[0]:t.NA}function sc(t){return(e,r)=>(r<0&&(r=e.array.length+r),r<0||r>=e.array.length?(t.warn(`Index ${r} is out of bounds, array size is ${e.array.length}.`,"array.get"),NaN):e.array[r])}function ac(t){return(e,r)=>e.array.includes(r)}function oc(t){return(e,r)=>typeof r=="number"&&r!==r?e.array.findIndex(n=>typeof n=="number"&&n!==n):e.array.indexOf(r)}function lc(t){return(e,r,n)=>{if(!$r(n,e.type))throw new Error(`Cannot call \'array.insert\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);if(r<0&&(r=e.array.length+r),r<0||r>e.array.length){t.warn(`Index ${r} is out of bounds, array size is ${e.array.length}.`,"array.insert");return}e.array.splice(r,0,n)}}function cc(t){return(e,r=",")=>e.array.join(r)}function uc(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function pc(t){return(e,r)=>e.array.lastIndexOf(r)}function hc(t){return(e,r=0)=>{let n=e.array;if(n.length===0)return t.NA;if(r===0){let i=n[0];for(let s=1;s<n.length;s++)n[s]>i&&(i=n[s]);return i??t.NA}return[...n].sort((i,s)=>s-i)[r]??t.NA}}function dc(t){return e=>{let r=e.array;if(r.length===0)return NaN;let n=new Array(r.length);for(let s=0;s<r.length;s++)n[s]=r[s];n.sort((s,a)=>s-a);let i=Math.floor(n.length/2);return n.length%2!==0?n[i]:(n[i-1]+n[i])/2}}function fc(t){return(e,r=0)=>{let n=e.array;if(n.length===0)return t.NA;if(r===0){let i=n[0];for(let s=1;s<n.length;s++)n[s]<i&&(i=n[s]);return i??t.NA}return[...n].sort((i,s)=>i-s)[r]??t.NA}}function mc(t){return e=>{if(e.array.length===0)return NaN;let r=new Map,n=0;for(let s of e.array){let a=(r.get(s)||0)+1;r.set(s,a),a>n&&(n=a)}let i=[];for(let[s,a]of r)a===n&&i.push(s);return i.sort((s,a)=>typeof s=="number"&&typeof a=="number"?s-a:typeof s=="string"&&typeof a=="string"?s<a?-1:s>a?1:0:0),i[0]}}function yc(t){return(e,r)=>{let n=e.array,i=n.length;if(i===0)return NaN;let s=new Array(i);for(let c=0;c<i;c++){let u=Number(n[c]);if(isNaN(u)||u===null||u===void 0)return NaN;s[c]=u}s.sort((c,u)=>c-u),r<0&&(r=0),r>100&&(r=100);let a=r/100*i-.5;if(a<=0)return t.precision(s[0]);if(a>=i-1)return t.precision(s[i-1]);let o=Math.floor(a),l=a-o;return t.precision(s[o]*(1-l)+s[o+1]*l)}}function gc(t){return(e,r)=>{let n=e.array,i=n.length;if(i===0)return NaN;let s=new Array;for(let o=0;o<i;o++){let l=Number(n[o]);!isNaN(l)&&l!==null&&l!==void 0&&s.push(l)}if(s.length===0)return NaN;s.sort((o,l)=>o-l),r<0&&(r=0),r>100&&(r=100);let a=Math.ceil(r/100*i);return a<=0?s[0]:a>s.length?NaN:s[a-1]}}function _c(t){return(e,r)=>{if(e.array.length===0)return NaN;let n=Math.floor(r);if(n<0||n>=e.array.length)return NaN;let i=Number(e.array[n]);if(isNaN(i)||i===null||i===void 0)return NaN;let s=0;for(let o of e.array){let l=Number(o);!isNaN(l)&&l!==null&&l!==void 0&&l<i&&s++}let a=e.array.length-1;return a<=0?NaN:s/a*100}}function xc(t){return e=>e.array.pop()}function bc(t){return(e,r)=>{if(!$r(r,e.type))throw new Error(`Cannot call \'array.push\' with argument \'value\'=\'${r}\'. An argument of \'literal ${typeof r}\' type was used but a \'${e.type}\' is expected.`);e.array.push(typeof r=="number"?t.precision(r):r)}}function vc(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function wc(t){return(e,r)=>(r<0&&(r=e.array.length+r),r<0||r>=e.array.length?(t.warn(`Index ${r} is out of bounds, array size is ${e.array.length}.`,"array.remove"),NaN):e.array.splice(r,1)[0])}function Ec(t){return e=>{e.array.reverse()}}function Sc(t){return(e,r,n)=>{if(!$r(n,e.type))throw new Error(`Cannot call \'array.set\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);if(r<0&&(r=e.array.length+r),r<0||r>=e.array.length){t.warn(`Index ${r} is out of bounds, array size is ${e.array.length}.`,"array.set");return}e.array[r]=typeof n=="number"?t.precision(n):n}}function Cc(t){return e=>e.array.shift()}function Nc(t){return e=>e.array.length}function kc(t){return(e,r,n)=>{let i=n!==void 0?n:void 0;return new q(e.array.slice(r,i),e.type,t)}}function Ic(t){return e=>e.array.some(r=>!isNaN(r)&&r)}var mr=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(mr||{}),Ca=(t=>(t.AED="AED",t.ARS="ARS",t.AUD="AUD",t.BDT="BDT",t.BHD="BHD",t.BRL="BRL",t.BTC="BTC",t.CAD="CAD",t.CHF="CHF",t.CLP="CLP",t.CNY="CNY",t.COP="COP",t.CZK="CZK",t.DKK="DKK",t.EGP="EGP",t.ETH="ETH",t.EUR="EUR",t.GBP="GBP",t.HKD="HKD",t.HUF="HUF",t.IDR="IDR",t.ILS="ILS",t.INR="INR",t.ISK="ISK",t.JPY="JPY",t.KES="KES",t.KRW="KRW",t.KWD="KWD",t.LKR="LKR",t.MAD="MAD",t.MXN="MXN",t.MYR="MYR",t.NGN="NGN",t.NOK="NOK",t.NONE="NONE",t.NZD="NZD",t.PEN="PEN",t.PHP="PHP",t.PKR="PKR",t.PLN="PLN",t.QAR="QAR",t.RON="RON",t.RSD="RSD",t.RUB="RUB",t.SAR="SAR",t.SEK="SEK",t.SGD="SGD",t.THB="THB",t.TND="TND",t.TRY="TRY",t.TWD="TWD",t.USD="USD",t.USDT="USDT",t.VES="VES",t.VND="VND",t.ZAR="ZAR",t))(Ca||{}),Na=(t=>(t[t.sunday=1]="sunday",t[t.monday=2]="monday",t[t.tuesday=3]="tuesday",t[t.wednesday=4]="wednesday",t[t.thursday=5]="thursday",t[t.friday=6]="friday",t[t.saturday=7]="saturday",t))(Na||{}),ka=(t=>(t.all="all",t.data_window="data_window",t.none="none",t.pane="pane",t.price_scale="price_scale",t.status_line="status_line",t))(ka||{}),Ia=(t=>(t.flag="shape_flag",t.arrowdown="shape_arrow_down",t.arrowup="shape_arrow_up",t.circle="shape_circle",t.cross="shape_cross",t.diamond="shape_diamond",t.labeldown="shape_label_down",t.labelup="shape_label_up",t.square="shape_square",t.triangledown="shape_triangle_down",t.triangleup="shape_triangle_up",t.xcross="shape_xcross",t))(Ia||{}),Aa=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(Aa||{}),Ta=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(Ta||{}),Da=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(Da||{}),Ac=(t=>(t.linestyle_dashed="linestyle_dashed",t.linestyle_dotted="linestyle_dotted",t.linestyle_solid="linestyle_solid",t.style_area="style_area",t.style_areabr="style_areabr",t.style_circles="style_circles",t.style_columns="style_columns",t.style_cross="style_cross",t.style_histogram="style_histogram",t.style_line="style_line",t.style_linebr="style_linebr",t.style_stepline="style_stepline",t.style_stepline_diamond="style_stepline_diamond",t.style_steplinebr="style_steplinebr",t))(Ac||{}),Ma=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(Ma||{}),Pa=(t=>(t.bar_index="bi",t.bar_time="bt",t))(Pa||{}),Ra=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(Ra||{}),Fa=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(Fa||{}),Ba=(t=>(t.align_bottom="bottom",t.align_top="top",t.align_left="left",t.align_center="center",t.align_right="right",t.wrap_auto="auto",t.wrap_none="none",t.format_bold="bold",t.format_italic="italic",t.format_none="none",t))(Ba||{}),La=(t=>(t.family_default="default",t.family_monospace="monospace",t))(La||{}),Oa=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(Oa||{}),Va=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(Va||{}),ja=(t=>(t.actual="earnings_actual",t.estimate="earnings_estimate",t.standardized="earnings_standardized",t.future_eps="earnings_future_eps",t.future_period_end_time="earnings_future_period_end_time",t.future_revenue="earnings_future_revenue",t.future_time="earnings_future_time",t))(ja||{}),$a=(t=>(t.gross="dividends_gross",t.net="dividends_net",t.future_amount="dividends_future_amount",t.future_ex_date="dividends_future_ex_date",t.future_pay_date="dividends_future_pay_date",t))($a||{}),Wa=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(Wa||{}),Ua=(t=>(t.top_left="top_left",t.top_center="top_center",t.top_right="top_right",t.middle_left="middle_left",t.middle_center="middle_center",t.middle_right="middle_right",t.bottom_left="bottom_left",t.bottom_center="bottom_center",t.bottom_right="bottom_right",t))(Ua||{}),qa=(t=>(t.left="left",t.none="none",t.right="right",t))(qa||{}),za=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(za||{}),Tc={order:mr,currency:Ca,dayofweek:Na,display:ka,shape:Ia,location:Aa,size:Ta,format:Da,barmerge:Ma,xloc:Pa,yloc:Ra,extend:Fa,text:Ba,font:La,adjustment:Oa,backadjustment:Va,earnings:ja,dividends:$a,splits:Wa,position:Ua,scale:qa,settlement_as_close:za};function Dc(t){return(e,r=mr.ascending)=>{e.array.sort((n,i)=>{let s=isNaN(n)?1/0:n,a=isNaN(i)?1/0:i;return r===mr.ascending?s-a:a-s})}}function Mc(t){return(e,r=mr.ascending)=>{let n=e.array.map((i,s)=>s);return n.sort((i,s)=>{let a=isNaN(e.array[i])?1/0:e.array[i],o=isNaN(e.array[s])?1/0:e.array[s];return r===mr.ascending?a-o:o-a}),new q(n,z.int,t)}}function Pc(t){return e=>{let r=t.array.avg(e),n=t.array.stdev(e);return isNaN(n)?new q(e.array.map(()=>NaN),z.int,t):n===0?new q(e.array.map(()=>1),z.int,t):new q(e.array.map(i=>(i-r)/n),z.int,t)}}function Rc(t){return(e,r=!0)=>{let n=e.array,i=n.length;if(i===0)return NaN;let s=0,a=0,o=0;for(let u=0;u<i;u++){let h=Number(n[u]);!isNaN(h)&&h!==null&&h!==void 0&&(s+=h,a+=h*h,o++)}if(o===0)return NaN;let l=s/o,c=a/o-l*l;return c<0?NaN:(!r&&o>1&&(c=c*o/(o-1)),!r&&o===1?0:t.precision(Math.sqrt(c)))}}function Fc(t){return e=>t.precision(e.array.reduce((r,n)=>{let i=Number(n);return isNaN(i)?r:r+i},0))}function Bc(t){return(e,r)=>{if(!$r(r,e.type))throw new Error(`Cannot call \'array.unshift\' with argument \'value\'=\'${r}\'. An argument of \'literal ${typeof r}\' type was used but a \'${e.type}\' is expected.`);e.array.unshift(typeof r=="number"?t.precision(r):r)}}function Lc(t){return(e,r=!0)=>{let n=0,i=0;for(let l of e.array){let c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(n+=c,i++)}if(i===0)return NaN;let s=n/i,a=0;for(let l of e.array){let c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(a+=(c-s)*(c-s))}let o=r?i:i-1;return o<=0?NaN:t.precision(a/o)}}var Oc=Object.defineProperty,Vc=(t,e,r)=>e in t?Oc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Y=(t,e,r)=>Vc(t,typeof e!="symbol"?e+"":e,r),z=(t=>(t.any="",t.box="box",t.bool="bool",t.color="color",t.float="float",t.int="int",t.label="label",t.line="line",t.linefill="linefill",t.string="string",t.table="table",t))(z||{}),q=class{constructor(e,r,n){this.array=e,this.type=r,this.context=n,Y(this,"_abs"),Y(this,"_avg"),Y(this,"_binary_search"),Y(this,"_binary_search_leftmost"),Y(this,"_binary_search_rightmost"),Y(this,"_clear"),Y(this,"_concat"),Y(this,"_copy"),Y(this,"_covariance"),Y(this,"_every"),Y(this,"_fill"),Y(this,"_first"),Y(this,"_get"),Y(this,"_includes"),Y(this,"_indexof"),Y(this,"_insert"),Y(this,"_join"),Y(this,"_last"),Y(this,"_lastindexof"),Y(this,"_max"),Y(this,"_median"),Y(this,"_min"),Y(this,"_mode"),Y(this,"_percentile_linear_interpolation"),Y(this,"_percentile_nearest_rank"),Y(this,"_percentrank"),Y(this,"_pop"),Y(this,"_push"),Y(this,"_range"),Y(this,"_remove"),Y(this,"_reverse"),Y(this,"_set"),Y(this,"_shift"),Y(this,"_size"),Y(this,"_slice"),Y(this,"_some"),Y(this,"_sort"),Y(this,"_sort_indices"),Y(this,"_standardize"),Y(this,"_stdev"),Y(this,"_sum"),Y(this,"_unshift"),Y(this,"_variance"),this._abs=Kl(this.context),this._avg=Hl(this.context),this._binary_search=Gl(this.context),this._binary_search_leftmost=Yl(this.context),this._binary_search_rightmost=Zl(this.context),this._clear=Xl(this.context),this._concat=Ql(this.context),this._copy=Jl(this.context),this._covariance=ec(this.context),this._every=tc(this.context),this._fill=nc(this.context),this._first=ic(this.context),this._get=sc(this.context),this._includes=ac(this.context),this._indexof=oc(this.context),this._insert=lc(this.context),this._join=cc(this.context),this._last=uc(this.context),this._lastindexof=pc(this.context),this._max=hc(this.context),this._median=dc(this.context),this._min=fc(this.context),this._mode=mc(this.context),this._percentile_linear_interpolation=yc(this.context),this._percentile_nearest_rank=gc(this.context),this._percentrank=_c(this.context),this._pop=xc(this.context),this._push=bc(this.context),this._range=vc(this.context),this._remove=wc(this.context),this._reverse=Ec(this.context),this._set=Sc(this.context),this._shift=Cc(this.context),this._size=Nc(this.context),this._slice=kc(this.context),this._some=Ic(this.context),this._sort=Dc(this.context),this._sort_indices=Mc(this.context),this._standardize=Pc(this.context),this._stdev=Rc(this.context),this._sum=Fc(this.context),this._unshift=Bc(this.context),this._variance=Lc(this.context)}toString(){return"["+this.array.toString().replace(/,/g,", ")+"]"}[Symbol.iterator](){return this.array[Symbol.iterator]()}abs(...e){return this._abs(this,...e)}avg(...e){return this._avg(this,...e)}binary_search(...e){return this._binary_search(this,...e)}binary_search_leftmost(...e){return this._binary_search_leftmost(this,...e)}binary_search_rightmost(...e){return this._binary_search_rightmost(this,...e)}clear(...e){return this._clear(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}covariance(...e){return this._covariance(this,...e)}every(...e){return this._every(this,...e)}fill(...e){return this._fill(this,...e)}first(...e){return this._first(this,...e)}get(...e){return this._get(this,...e)}includes(...e){return this._includes(this,...e)}indexof(...e){return this._indexof(this,...e)}insert(...e){return this._insert(this,...e)}join(...e){return this._join(this,...e)}last(...e){return this._last(this,...e)}lastindexof(...e){return this._lastindexof(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}percentile_linear_interpolation(...e){return this._percentile_linear_interpolation(this,...e)}percentile_nearest_rank(...e){return this._percentile_nearest_rank(this,...e)}percentrank(...e){return this._percentrank(this,...e)}pop(...e){return this._pop(this,...e)}push(...e){return this._push(this,...e)}range(...e){return this._range(this,...e)}remove(...e){return this._remove(this,...e)}reverse(...e){return this._reverse(this,...e)}set(...e){return this._set(this,...e)}shift(...e){return this._shift(this,...e)}size(...e){return this._size(this,...e)}slice(...e){return this._slice(this,...e)}some(...e){return this._some(this,...e)}sort(...e){return this._sort(this,...e)}sort_indices(...e){return this._sort_indices(this,...e)}standardize(...e){return this._standardize(this,...e)}stdev(...e){return this._stdev(this,...e)}sum(...e){return this._sum(this,...e)}unshift(...e){return this._unshift(this,...e)}variance(...e){return this._variance(this,...e)}};function jc(t){return(...e)=>new q([...e],rc(e),t)}function $c(t){return(e,r)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;if(r===void 0){let i=n?Array(n).fill(0):[];return new q(i,z.any,t)}return new q(Array(n).fill(t.precision(r||0)),it(r||0),t)}}function Wc(t){return(e=0,r=!1)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.bool,t)}}function Uc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.box,t)}}function qc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.color,t)}}function zc(t){return(e=0,r=NaN)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(t.precision(r)),z.float,t)}}function Kc(t){return(e=0,r=0)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(t.precision(r)),z.int,t)}}function Hc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.label,t)}}function Gc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.line,t)}}function Yc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.linefill,t)}}function Zc(t){return(e=0,r="")=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.string,t)}}function Xc(t){return(e=0,r=null)=>{let n=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new q(Array(n).fill(r),z.table,t)}}var y=class t{constructor(e,r=0){this.data=e,this.offset=r}get(e){let r=this.offset+e;Number.isInteger(r)||(r=Math.trunc(r));let n=this.data.length-1-r;return n<0||n>=this.data.length?NaN:this.data[n]}set(e,r){let n=this.data.length-1-(this.offset+e);n>=0&&n<this.data.length&&(this.data[n]=r)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof t?e:Array.isArray(e)?new t(e):e!=null&&typeof e=="object"&&"__value"in e&&e.__value instanceof t?e.__value:new t([e])}};function Qc(t){return(e,r=0)=>y.from(e).get(r)}var pi=class{constructor(e){this.context=e,this.abs=(r,...n)=>r.abs(...n),this.avg=(r,...n)=>r.avg(...n),this.binary_search=(r,...n)=>r.binary_search(...n),this.binary_search_leftmost=(r,...n)=>r.binary_search_leftmost(...n),this.binary_search_rightmost=(r,...n)=>r.binary_search_rightmost(...n),this.clear=(r,...n)=>r.clear(...n),this.concat=(r,...n)=>r.concat(...n),this.copy=(r,...n)=>r.copy(...n),this.covariance=(r,...n)=>r.covariance(...n),this.every=(r,...n)=>r.every(...n),this.fill=(r,...n)=>r.fill(...n),this.first=(r,...n)=>r.first(...n),this.from=jc(e),this.get=(r,...n)=>r.get(...n),this.includes=(r,...n)=>r.includes(...n),this.indexof=(r,...n)=>r.indexof(...n),this.insert=(r,...n)=>r.insert(...n),this.join=(r,...n)=>r.join(...n),this.last=(r,...n)=>r.last(...n),this.lastindexof=(r,...n)=>r.lastindexof(...n),this.max=(r,...n)=>r.max(...n),this.median=(r,...n)=>r.median(...n),this.min=(r,...n)=>r.min(...n),this.mode=(r,...n)=>r.mode(...n),this.new=$c(e),this.new_bool=Wc(e),this.new_box=Uc(e),this.new_color=qc(e),this.new_float=zc(e),this.new_int=Kc(e),this.new_label=Hc(e),this.new_line=Gc(e),this.new_linefill=Yc(e),this.new_string=Zc(e),this.new_table=Xc(e),this.param=Qc(),this.percentile_linear_interpolation=(r,...n)=>r.percentile_linear_interpolation(...n),this.percentile_nearest_rank=(r,...n)=>r.percentile_nearest_rank(...n),this.percentrank=(r,...n)=>r.percentrank(...n),this.pop=(r,...n)=>r.pop(...n),this.push=(r,...n)=>r.push(...n),this.range=(r,...n)=>r.range(...n),this.remove=(r,...n)=>r.remove(...n),this.reverse=(r,...n)=>r.reverse(...n),this.set=(r,...n)=>r.set(...n),this.shift=(r,...n)=>r.shift(...n),this.size=(r,...n)=>r.size(...n),this.slice=(r,...n)=>r.slice(...n),this.some=(r,...n)=>r.some(...n),this.sort=(r,...n)=>r.sort(...n),this.sort_indices=(r,...n)=>r.sort_indices(...n),this.standardize=(r,...n)=>r.standardize(...n),this.stdev=(r,...n)=>r.stdev(...n),this.sum=(r,...n)=>r.sum(...n),this.unshift=(r,...n)=>r.unshift(...n),this.variance=(r,...n)=>r.variance(...n)}};function Jc(t){return e=>{e.map.clear()}}function eu(t){return(e,r)=>e.map.has(r)}function tu(t){return e=>{let r=new cn(t);return r.map=new Map(e.map),r}}function ru(t){return(e,r)=>{let n=e.map.get(r);return n===void 0?NaN:n}}function nu(t){return e=>{let r=Array.from(e.map.keys()),n=it(r[0]);return new q(r,n,t)}}function iu(t){return(e,r,n)=>{let i=e.map.get(r);return e.map.set(r,n),i===void 0?NaN:i}}function su(t){return(e,r)=>{for(let[n,i]of r.map)e.map.set(n,i)}}function au(t){return(e,r)=>{let n=e.map.get(r);return e.map.delete(r)?n:NaN}}function ou(t){return e=>e.map.size}function lu(t){return e=>{let r=Array.from(e.map.values()),n=it(r[0]);return new q(r,n,t)}}var cu=Object.defineProperty,uu=(t,e,r)=>e in t?cu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ot=(t,e,r)=>uu(t,typeof e!="symbol"?e+"":e,r),cn=class{constructor(e){this.context=e,ot(this,"map"),ot(this,"_clear"),ot(this,"_contains"),ot(this,"_copy"),ot(this,"_get"),ot(this,"_keys"),ot(this,"_put"),ot(this,"_put_all"),ot(this,"_remove"),ot(this,"_size"),ot(this,"_values"),this.map=new Map,this._clear=Jc(this.context),this._contains=eu(this.context),this._copy=tu(this.context),this._get=ru(this.context),this._keys=nu(this.context),this._put=iu(this.context),this._put_all=su(this.context),this._remove=au(this.context),this._size=ou(this.context),this._values=lu(this.context)}toString(){return`PineMapObject(${this.map.size})`}clear(...e){return this._clear(this,...e)}contains(...e){return this._contains(this,...e)}copy(...e){return this._copy(this,...e)}get(...e){return this._get(this,...e)}keys(...e){return this._keys(this,...e)}put(...e){return this._put(this,...e)}put_all(...e){return this._put_all(this,...e)}remove(...e){return this._remove(this,...e)}size(...e){return this._size(this,...e)}values(...e){return this._values(this,...e)}};function pu(t){return()=>new cn(t)}function hu(t){return(e,r=0)=>y.from(e).get(r)}var hi=class{constructor(e){this.context=e,this.clear=(r,...n)=>r.clear(...n),this.contains=(r,...n)=>r.contains(...n),this.copy=(r,...n)=>r.copy(...n),this.get=(r,...n)=>r.get(...n),this.keys=(r,...n)=>r.keys(...n),this.new=pu(e),this.param=hu(),this.put=(r,...n)=>r.put(...n),this.put_all=(r,...n)=>r.put_all(...n),this.remove=(r,...n)=>r.remove(...n),this.size=(r,...n)=>r.size(...n),this.values=(r,...n)=>r.values(...n)}};function du(t){return(e,r,n)=>{let i=e.matrix.length,s=[];if(n&&(n instanceof q?s=n.array:Array.isArray(n)?s=n:s=[n]),i===0){for(let l=0;l<s.length;l++){let c=s[l];c instanceof y&&(c=c.get(0)),e.matrix.push([c])}return}let a=e.matrix[0].length,o=r!==void 0?r:a;for(let l=0;l<i;l++){let c=l<s.length?s[l]:NaN;c instanceof y&&(c=c.get(0)),e.matrix[l].splice(o,0,c)}}}function fu(t){return(e,r,n)=>{let i=e.matrix.length,s=[];if(n)if(n instanceof q)s=n.array;else if(Array.isArray(n))s=n;else if(n instanceof y){let c=n.get(0);Array.isArray(c)?s=c:s=[c]}else s=[n];let a=i>0?e.matrix[0].length:s.length,o=r!==void 0?r:i,l=[];for(let c=0;c<a;c++)if(c<s.length){let u=s[c];u instanceof y&&(u=u.get(0)),l.push(u)}else l.push(NaN);e.matrix.splice(o,0,l)}}function mu(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length;if(n===0)return NaN;let i=0,s=0;for(let a=0;a<r;a++)for(let o=0;o<n;o++){let l=e.matrix[a][o];isNaN(l)||(i+=l,s++)}return s===0?NaN:i/s}}function yu(t){return(e,r)=>{let n=e.matrix.length,i=n>0?e.matrix[0].length:0;if(r<0||r>=i){t.warn(`Column index ${r} is out of bounds, matrix has ${i} columns.`,"matrix.col");let o=n>0?it(e.matrix[0][0]):"float";return new q([],o,t)}let s=[];for(let o=0;o<n;o++)s.push(e.matrix[o][r]);let a=it(s[0]);return new q(s,a,t)}}function gu(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function _u(t){return(e,r)=>{let n=e.matrix.length,i=r.matrix.length;if(n===0){for(let o=0;o<i;o++)e.matrix.push([...r.matrix[o]]);return}let s=e.matrix[0].length,a=i>0?r.matrix[0].length:0;if(s!==a&&i>0){console.error(`matrix.concat: Column count mismatch ${s} vs ${a}`);return}for(let o=0;o<i;o++)e.matrix.push([...r.matrix[o]])}}function xu(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0,i=new te(r,n,NaN,t);return i.matrix=e.matrix.map(s=>[...s]),i}}function bu(t){let e=t.length;if(e===0)return 0;if(e===1)return t[0][0];if(e===2)return t[0][0]*t[1][1]-t[0][1]*t[1][0];let r=t.map(i=>[...i]),n=1;for(let i=0;i<e;i++){let s=i;for(;s<e&&r[s][i]===0;)s++;if(s===e)return 0;s!==i&&([r[i],r[s]]=[r[s],r[i]],n*=-1),n*=r[i][i];for(let a=i+1;a<e;a++){let o=r[a][i]/r[i][i];for(let l=i;l<e;l++)r[a][l]-=o*r[i][l]}}return n}function vu(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0;return r!==n?NaN:bu(e.matrix)}}function wu(t){return(e,r)=>{let n=e.matrix.length;if(n===0)return new te(0,0,NaN,t);let i=e.matrix[0].length,s=new te(n,i,NaN,t);if(r instanceof te)for(let a=0;a<n;a++)for(let o=0;o<i;o++){let l=e.matrix[a][o],c=r.matrix[a]&&r.matrix[a][o]!==void 0?r.matrix[a][o]:NaN;s.matrix[a][o]=l-c}else{let a=r;for(let o=0;o<n;o++)for(let l=0;l<i;l++)s.matrix[o][l]=e.matrix[o][l]-a}return s}}function Eu(t){let e=t.length;if(e!==2)return Array(e).fill(NaN);let r=t[0][0],n=t[0][1],i=t[1][0],s=t[1][1],a=r+s,o=r*s-n*i,l=a*a-4*o;if(l<0)return[NaN,NaN];let c=(a+Math.sqrt(l))/2,u=(a-Math.sqrt(l))/2;return[c,u]}function Su(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n){let a=it(e.matrix[0][0]);return new q([],a,t)}let i=Eu(e.matrix),s=it(i[0]);return new q(i,s,t)}}function Cu(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n)return new te(0,0,NaN,t);let i=new te(r,n,0,t);for(let s=0;s<r;s++)i.matrix[s][s]=1;return i}}function Nu(t){return e=>{let r=e.matrix.length;return r===0?0:r*e.matrix[0].length}}function ku(t){return(e,r,n,i,s,a)=>{let o=e.matrix.length;if(o===0)return;let l=e.matrix[0].length,c=n!==void 0?n:0,u=i!==void 0?i:o,h=s!==void 0?s:0,p=a!==void 0?a:l;for(let d=c;d<u&&!(d>=o);d++)for(let f=h;f<p&&!(f>=l);f++)e.matrix[d][f]=r}}function Iu(t){return(e,r,n)=>{let i=e.matrix.length,s=i>0?e.matrix[0].length:0;if(r<0||r>=i)return t.warn(`Row index ${r} is out of bounds, matrix has ${i} rows.`,"matrix.get"),NaN;if(n<0||n>=s)return t.warn(`Column index ${n} is out of bounds, matrix has ${s} columns.`,"matrix.get"),NaN;let a=e.matrix[r][n];return a===void 0?NaN:a}}function rn(t){let e=t.length;if(e===0)return[];let r=new Array(e);for(let i=0;i<e;i++){r[i]=new Array(2*e);for(let s=0;s<e;s++)r[i][s]=t[i][s];for(let s=0;s<e;s++)r[i][e+s]=i===s?1:0}for(let i=0;i<e;i++){let s=Math.abs(r[i][i]),a=i;for(let l=i+1;l<e;l++){let c=Math.abs(r[l][i]);c>s&&(s=c,a=l)}if(s<1e-14)return t.map(l=>l.map(()=>NaN));if(a!==i){let l=r[i];r[i]=r[a],r[a]=l}let o=r[i][i];for(let l=i;l<2*e;l++)r[i][l]/=o;for(let l=0;l<e;l++){if(l===i)continue;let c=r[l][i];if(c!==0)for(let u=i;u<2*e;u++)r[l][u]-=c*r[i][u]}}let n=new Array(e);for(let i=0;i<e;i++){n[i]=new Array(e);for(let s=0;s<e;s++)n[i][s]=r[i][e+s]}return n}function Au(t){return e=>{let r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n)return new te(r,n,NaN,t);let i=rn(e.matrix),s=new te(r,n,NaN,t);return s.matrix=i,s}}function Tu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(i+s!==r-1&&e.matrix[i][s]!==0)return!1;return!0}}function Du(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(e.matrix[s][i]!==-e.matrix[i][s])return!1;return!0}}function Mu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;for(let i=0;i<r;i++)for(let s=0;s<n;s++){let a=e.matrix[i][s];if(a!==0&&a!==1)return!1}return!0}}function Pu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(i!==s&&e.matrix[i][s]!==0)return!1;return!0}}function Ru(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(i===s){if(e.matrix[i][s]!==1)return!1}else if(e.matrix[i][s]!==0)return!1;return!0}}function Fu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;return r===n}}function Bu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;for(let i=0;i<r;i++){let s=0;for(let a=0;a<n;a++){let o=e.matrix[i][a];if(o<0)return!1;s+=o}if(Math.abs(s-1)>1e-10)return!1}return!0}}function Lu(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;for(let i=0;i<r;i++)for(let s=0;s<i;s++)if(e.matrix[i][s]!==e.matrix[s][i])return!1;return!0}}function Ou(t){return e=>{let r=e.matrix.length;if(r===0)return!1;let n=e.matrix[0].length;if(r!==n)return!1;let i=!0,s=!0;for(let a=0;a<r;a++)for(let o=0;o<n;o++)a>o&&e.matrix[a][o]!==0&&(i=!1),a<o&&e.matrix[a][o]!==0&&(s=!1);return i||s}}function Vu(t){return e=>{let r=e.matrix.length;if(r===0)return!0;let n=e.matrix[0].length;for(let i=0;i<r;i++)for(let s=0;s<n;s++)if(e.matrix[i][s]!==0)return!1;return!0}}function ju(t){return(e,r)=>{let n=e.matrix.length,i=n>0?e.matrix[0].length:0,s=r.matrix.length,a=s>0?r.matrix[0].length:0,o=n*s,l=i*a,c=new te(o,l,NaN,t);for(let u=0;u<n;u++)for(let h=0;h<i;h++){let p=e.matrix[u][h];for(let d=0;d<s;d++)for(let f=0;f<a;f++){let m=r.matrix[d][f];c.matrix[u*s+d][h*a+f]=p*m}}return c}}function $u(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length,i=-1/0,s=!1;for(let a=0;a<r;a++)for(let o=0;o<n;o++){let l=e.matrix[a][o];isNaN(l)||(l>i&&(i=l),s=!0)}return s?i:NaN}}function Wu(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length,i=[];for(let a=0;a<r;a++)for(let o=0;o<n;o++){let l=e.matrix[a][o];isNaN(l)||i.push(l)}if(i.length===0)return NaN;i.sort((a,o)=>a-o);let s=Math.floor(i.length/2);return i.length%2!==0?i[s]:(i[s-1]+i[s])/2}}function Uu(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length,i=1/0,s=!1;for(let a=0;a<r;a++)for(let o=0;o<n;o++){let l=e.matrix[a][o];isNaN(l)||(l<i&&(i=l),s=!0)}return s?i:NaN}}function qu(t){return e=>{let r=e.matrix.length;if(r===0)return NaN;let n=e.matrix[0].length,i=new Map,s=0,a=NaN;for(let o=0;o<r;o++)for(let l=0;l<n;l++){let c=e.matrix[o][l];if(!isNaN(c)){let u=(i.get(c)||0)+1;i.set(c,u),u>s?(s=u,a=c):u===s&&c<a&&(a=c)}}return a}}function zu(t){return(e,r)=>{let n=e.matrix.length,i=n>0?e.matrix[0].length:0;if(r instanceof te){let s=r.matrix.length,a=s>0?r.matrix[0].length:0;if(i!==s)return new te(0,0,NaN,t);let o=new te(n,a,0,t);for(let l=0;l<n;l++)for(let c=0;c<a;c++){let u=0;for(let h=0;h<i;h++)u+=e.matrix[l][h]*r.matrix[h][c];o.matrix[l][c]=u}return o}else if(r instanceof q||Array.isArray(r.array||r)){let s=r.array||r;if(i!==s.length)return new q([],"float",t);let a=[];for(let o=0;o<n;o++){let l=0;for(let c=0;c<i;c++)l+=e.matrix[o][c]*s[c];a.push(l)}return new q(a,"float",t)}else{let s=r,a=new te(n,i,NaN,t);for(let o=0;o<n;o++)for(let l=0;l<i;l++)a.matrix[o][l]=e.matrix[o][l]*s;return a}}}function Ku(t){return e=>{let r=e.matrix.length;if(r===0)return new te(0,0,NaN,t);let n=e.matrix[0].length;if(r===n){let u=rn(e.matrix),h=new te(r,n,NaN,t);return h.matrix=u,h}let i=u=>{let h=u.length,p=u[0].length,d=new Array(p);for(let f=0;f<p;f++){d[f]=new Array(h);for(let m=0;m<h;m++)d[f][m]=u[m][f]}return d},s=(u,h)=>{let p=u.length,d=u[0].length,f=h[0].length,m=new Array(p);for(let x=0;x<p;x++){m[x]=new Array(f).fill(0);for(let b=0;b<d;b++){let w=u[x][b];if(w!==0)for(let v=0;v<f;v++)m[x][v]+=w*h[b][v]}}return m},a=e.matrix,o=i(a),l;if(r>n){let u=s(o,a),h=rn(u);l=s(h,o)}else{let u=s(a,o),h=rn(u);l=s(o,h)}let c=new te(n,r,NaN,t);return c.matrix=l,c}}function Hu(t){return(e,r)=>{let n=e.matrix.length,i=n>0?e.matrix[0].length:0;if(n!==i)return new te(0,0,NaN,t);let s=new te(n,i,0,t);for(let l=0;l<n;l++)s.matrix[l][l]=1;let a=new te(n,i,NaN,t);for(let l=0;l<n;l++)a.matrix[l]=[...e.matrix[l]];let o=Math.floor(r);if(o<0)return new te(n,i,NaN,t);for(;o>0;){if(o%2===1){let c=new te(n,i,0,t);for(let u=0;u<n;u++)for(let h=0;h<i;h++){let p=0;for(let d=0;d<n;d++)p+=s.matrix[u][d]*a.matrix[d][h];c.matrix[u][h]=p}s=c}let l=new te(n,i,0,t);for(let c=0;c<n;c++)for(let u=0;u<i;u++){let h=0;for(let p=0;p<n;p++)h+=a.matrix[c][p]*a.matrix[p][u];l.matrix[c][u]=h}a=l,o=Math.floor(o/2)}return s}}function Gu(t){return e=>{let r=e.matrix.length;if(r===0)return 0;let n=e.matrix[0].length,i=e.matrix.map(a=>[...a]),s=0;for(let a=0;a<n&&s<r;a++){let o=s;for(;o<r&&Math.abs(i[o][a])<1e-10;)o++;if(o<r){[i[s],i[o]]=[i[o],i[s]];let l=i[s][a];for(let c=a;c<n;c++)i[s][c]/=l;for(let c=0;c<r;c++)if(c!==s){let u=i[c][a];for(let h=a;h<n;h++)i[c][h]-=u*i[s][h]}s++}}return s}}function Yu(t){return(e,r)=>{let n=e.matrix.length;if(n===0){let a=it(e.matrix[0][0]);return new q([],a,t)}let i=[];for(let a=0;a<n;a++){let o=e.matrix[a].splice(r,1);i.push(o[0])}let s=it(i[0]);return new q(i,s,t)}}function Zu(t){return(e,r)=>{let n=e.matrix.splice(r,1),i=it(n[0][0]);return new q(n[0]||[],i,t)}}function Xu(t){return(e,r,n)=>{let i=e.matrix.length,s=i>0?e.matrix[0].length:0,a=r*n,o=[];for(let u=0;u<i;u++)for(let h=0;h<s;h++)o.push(e.matrix[u][h]);for(;o.length<a;)o.push(NaN);o.length>a&&(o.length=a);let l=[],c=0;for(let u=0;u<r;u++){let h=[];for(let p=0;p<n;p++)h.push(o[c++]);l.push(h)}e.matrix=l}}function Qu(t){return e=>{e.matrix.reverse();for(let r of e.matrix)r.reverse()}}function Ju(t){return(e,r)=>{let n=e.matrix.length;if(r<0||r>=n){t.warn(`Row index ${r} is out of bounds, matrix has ${n} rows.`,"matrix.row");let s=n>0?it(e.matrix[0][0]):"float";return new q([],s,t)}let i=it(e.matrix[r][0]);return new q([...e.matrix[r]],i,t)}}function ep(t){return e=>e.matrix.length}function tp(t){return(e,r,n,i)=>{let s=e.matrix.length,a=s>0?e.matrix[0].length:0;if(r<0||r>=s){t.warn(`Row index ${r} is out of bounds, matrix has ${s} rows.`,"matrix.set");return}if(n<0||n>=a){t.warn(`Column index ${n} is out of bounds, matrix has ${a} columns.`,"matrix.set");return}e.matrix[r][n]=i}}function rp(t){return(e,r=0,n="asc")=>{e.matrix.length!==0&&e.matrix.sort((i,s)=>{let a=i[r],o=s[r];return a<o?n==="asc"?-1:1:a>o?n==="asc"?1:-1:0})}}function np(t){return(e,r,n,i,s)=>{let a=n-r,o=s-i,l=new te(a,o,NaN,t);for(let c=0;c<a;c++){let u=r+c;if(u>=e.matrix.length)break;for(let h=0;h<o;h++){let p=i+h;if(p>=e.matrix[u].length)break;l.matrix[c][h]=e.matrix[u][p]}}return l}}function ip(t){return(e,r)=>{let n=e.matrix.length;if(n===0)return new te(0,0,NaN,t);let i=e.matrix[0].length,s=new te(n,i,NaN,t);if(r instanceof te)for(let a=0;a<n;a++)for(let o=0;o<i;o++){let l=e.matrix[a][o],c=r.matrix[a]&&r.matrix[a][o]!==void 0?r.matrix[a][o]:NaN;s.matrix[a][o]=l+c}else{let a=r;for(let o=0;o<n;o++)for(let l=0;l<i;l++)s.matrix[o][l]=e.matrix[o][l]+a}return s}}function sp(t){return(e,r,n)=>{let i=e.matrix.length;for(let s=0;s<i;s++){let a=e.matrix[s][r];e.matrix[s][r]=e.matrix[s][n],e.matrix[s][n]=a}}}function ap(t){return(e,r,n)=>{let i=e.matrix[r];e.matrix[r]=e.matrix[n],e.matrix[n]=i}}function op(t){return e=>{let r=e.matrix.length;if(r===0)return 0;let n=e.matrix[0].length,i=Math.min(r,n),s=0;for(let a=0;a<i;a++)s+=e.matrix[a][a];return s}}function lp(t){return e=>{let r=e.matrix.length;if(r===0)return new te(0,0,NaN,t);let n=e.matrix[0].length,i=new te(n,r,NaN,t);for(let s=0;s<r;s++)for(let a=0;a<n;a++)i.matrix[a][s]=e.matrix[s][a];return i}}var cp=Object.defineProperty,up=(t,e,r)=>e in t?cp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,U=(t,e,r)=>up(t,typeof e!="symbol"?e+"":e,r),te=class{constructor(e=0,r=0,n=NaN,i){if(this.context=i,U(this,"matrix"),U(this,"_add_col"),U(this,"_add_row"),U(this,"_avg"),U(this,"_col"),U(this,"_columns"),U(this,"_concat"),U(this,"_copy"),U(this,"_det"),U(this,"_diff"),U(this,"_eigenvalues"),U(this,"_eigenvectors"),U(this,"_elements_count"),U(this,"_fill"),U(this,"_get"),U(this,"_inv"),U(this,"_is_antidiagonal"),U(this,"_is_antisymmetric"),U(this,"_is_binary"),U(this,"_is_diagonal"),U(this,"_is_identity"),U(this,"_is_square"),U(this,"_is_stochastic"),U(this,"_is_symmetric"),U(this,"_is_triangular"),U(this,"_is_zero"),U(this,"_kron"),U(this,"_max"),U(this,"_median"),U(this,"_min"),U(this,"_mode"),U(this,"_mult"),U(this,"_pinv"),U(this,"_pow"),U(this,"_rank"),U(this,"_remove_col"),U(this,"_remove_row"),U(this,"_reshape"),U(this,"_reverse"),U(this,"_row"),U(this,"_rows"),U(this,"_set"),U(this,"_sort"),U(this,"_submatrix"),U(this,"_sum"),U(this,"_swap_columns"),U(this,"_swap_rows"),U(this,"_trace"),U(this,"_transpose"),this.matrix=[],e>0&&r>0)for(let s=0;s<e;s++)this.matrix.push(Array(r).fill(n));this._add_col=du(this.context),this._add_row=fu(this.context),this._avg=mu(this.context),this._col=yu(this.context),this._columns=gu(this.context),this._concat=_u(this.context),this._copy=xu(this.context),this._det=vu(this.context),this._diff=wu(this.context),this._eigenvalues=Su(this.context),this._eigenvectors=Cu(this.context),this._elements_count=Nu(this.context),this._fill=ku(this.context),this._get=Iu(this.context),this._inv=Au(this.context),this._is_antidiagonal=Tu(this.context),this._is_antisymmetric=Du(this.context),this._is_binary=Mu(this.context),this._is_diagonal=Pu(this.context),this._is_identity=Ru(this.context),this._is_square=Fu(this.context),this._is_stochastic=Bu(this.context),this._is_symmetric=Lu(this.context),this._is_triangular=Ou(this.context),this._is_zero=Vu(this.context),this._kron=ju(this.context),this._max=$u(this.context),this._median=Wu(this.context),this._min=Uu(this.context),this._mode=qu(this.context),this._mult=zu(this.context),this._pinv=Ku(this.context),this._pow=Hu(this.context),this._rank=Gu(this.context),this._remove_col=Yu(this.context),this._remove_row=Zu(this.context),this._reshape=Xu(this.context),this._reverse=Qu(this.context),this._row=Ju(this.context),this._rows=ep(this.context),this._set=tp(this.context),this._sort=rp(this.context),this._submatrix=np(this.context),this._sum=ip(this.context),this._swap_columns=sp(this.context),this._swap_rows=ap(this.context),this._trace=op(this.context),this._transpose=lp(this.context)}toString(){let e="";for(let r=0;r<this.matrix.length;r++)e+=e===""?"":`\n`,e+="["+this.matrix[r].join(", ")+"]";return e}add_col(...e){return this._add_col(this,...e)}add_row(...e){return this._add_row(this,...e)}avg(...e){return this._avg(this,...e)}col(...e){return this._col(this,...e)}columns(...e){return this._columns(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}det(...e){return this._det(this,...e)}diff(...e){return this._diff(this,...e)}eigenvalues(...e){return this._eigenvalues(this,...e)}eigenvectors(...e){return this._eigenvectors(this,...e)}elements_count(...e){return this._elements_count(this,...e)}fill(...e){return this._fill(this,...e)}get(...e){return this._get(this,...e)}inv(...e){return this._inv(this,...e)}is_antidiagonal(...e){return this._is_antidiagonal(this,...e)}is_antisymmetric(...e){return this._is_antisymmetric(this,...e)}is_binary(...e){return this._is_binary(this,...e)}is_diagonal(...e){return this._is_diagonal(this,...e)}is_identity(...e){return this._is_identity(this,...e)}is_square(...e){return this._is_square(this,...e)}is_stochastic(...e){return this._is_stochastic(this,...e)}is_symmetric(...e){return this._is_symmetric(this,...e)}is_triangular(...e){return this._is_triangular(this,...e)}is_zero(...e){return this._is_zero(this,...e)}kron(...e){return this._kron(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}mult(...e){return this._mult(this,...e)}pinv(...e){return this._pinv(this,...e)}pow(...e){return this._pow(this,...e)}rank(...e){return this._rank(this,...e)}remove_col(...e){return this._remove_col(this,...e)}remove_row(...e){return this._remove_row(this,...e)}reshape(...e){return this._reshape(this,...e)}reverse(...e){return this._reverse(this,...e)}row(...e){return this._row(this,...e)}rows(...e){return this._rows(this,...e)}set(...e){return this._set(this,...e)}sort(...e){return this._sort(this,...e)}submatrix(...e){return this._submatrix(this,...e)}sum(...e){return this._sum(this,...e)}swap_columns(...e){return this._swap_columns(this,...e)}swap_rows(...e){return this._swap_rows(this,...e)}trace(...e){return this._trace(this,...e)}transpose(...e){return this._transpose(this,...e)}};function lt(t){return(e,r,n)=>new te(e,r,n,t)}function pp(t){return(e,r=0)=>y.from(e).get(r)}var di=class{constructor(e){this.context=e,this.add_col=(r,...n)=>r.add_col(...n),this.add_row=(r,...n)=>r.add_row(...n),this.avg=(r,...n)=>r.avg(...n),this.col=(r,...n)=>r.col(...n),this.columns=(r,...n)=>r.columns(...n),this.concat=(r,...n)=>r.concat(...n),this.copy=(r,...n)=>r.copy(...n),this.det=(r,...n)=>r.det(...n),this.diff=(r,...n)=>r.diff(...n),this.eigenvalues=(r,...n)=>r.eigenvalues(...n),this.eigenvectors=(r,...n)=>r.eigenvectors(...n),this.elements_count=(r,...n)=>r.elements_count(...n),this.fill=(r,...n)=>r.fill(...n),this.get=(r,...n)=>r.get(...n),this.inv=(r,...n)=>r.inv(...n),this.is_antidiagonal=(r,...n)=>r.is_antidiagonal(...n),this.is_antisymmetric=(r,...n)=>r.is_antisymmetric(...n),this.is_binary=(r,...n)=>r.is_binary(...n),this.is_diagonal=(r,...n)=>r.is_diagonal(...n),this.is_identity=(r,...n)=>r.is_identity(...n),this.is_square=(r,...n)=>r.is_square(...n),this.is_stochastic=(r,...n)=>r.is_stochastic(...n),this.is_symmetric=(r,...n)=>r.is_symmetric(...n),this.is_triangular=(r,...n)=>r.is_triangular(...n),this.is_zero=(r,...n)=>r.is_zero(...n),this.kron=(r,...n)=>r.kron(...n),this.max=(r,...n)=>r.max(...n),this.median=(r,...n)=>r.median(...n),this.min=(r,...n)=>r.min(...n),this.mode=(r,...n)=>r.mode(...n),this.mult=(r,...n)=>r.mult(...n),this.new=lt(e),this.param=pp(),this.pinv=(r,...n)=>r.pinv(...n),this.pow=(r,...n)=>r.pow(...n),this.rank=(r,...n)=>r.rank(...n),this.remove_col=(r,...n)=>r.remove_col(...n),this.remove_row=(r,...n)=>r.remove_row(...n),this.reshape=(r,...n)=>r.reshape(...n),this.reverse=(r,...n)=>r.reverse(...n),this.row=(r,...n)=>r.row(...n),this.rows=(r,...n)=>r.rows(...n),this.set=(r,...n)=>r.set(...n),this.sort=(r,...n)=>r.sort(...n),this.submatrix=(r,...n)=>r.submatrix(...n),this.sum=(r,...n)=>r.sum(...n),this.swap_columns=(r,...n)=>r.swap_columns(...n),this.swap_rows=(r,...n)=>r.swap_rows(...n),this.trace=(r,...n)=>r.trace(...n),this.transpose=(r,...n)=>r.transpose(...n),this.new_float=lt(e),this.new_int=lt(e),this.new_string=lt(e),this.new_bool=lt(e),this.new_color=lt(e),this.new_line=lt(e),this.new_label=lt(e),this.new_box=lt(e),this.new_linefill=lt(e),this.new_table=lt(e)}},hp=Object.defineProperty,dp=(t,e,r)=>e in t?hp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fp=(t,e,r)=>dp(t,typeof e!="symbol"?e+"":e,r),fi=class{constructor(e){this.context=e,fp(this,"_live",!1)}setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.length-1}get isrealtime(){return this.context.idx===this.context.length-1}get isconfirmed(){return this.context.data.closeTime.data[this.context.idx]<=Date.now()}get islastconfirmedhistory(){let e=this.context.idx,r=this.context.length;if(e===r-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===r-2){let n=this.context.marketData?.[r-1]?.closeTime;return n!==void 0?n>Date.now():!1}return!1}},mp=Object.defineProperty,yp=(t,e,r)=>e in t?mp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gp=(t,e,r)=>yp(t,typeof e!="symbol"?e+"":e,r),Lt=class t{constructor(e,r,n){this._definition=e,this.context=r,gp(this,"_udt");for(let i in e)this[i]=e[i];this._udt=n}get __def__(){return this._definition}copy(){return new t(this.__def__,this.context,this._udt)}toString(){let e={};for(let r in this.__def__){let n=this[r];n!=null&&typeof n=="object"&&typeof n.toString=="function"&&!(n instanceof Array)?e[r]=n.toString():e[r]=n}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(r=>`"${r}":${String(e[r])}`).join(",")+"}"}}},_p=Object.defineProperty,xp=(t,e,r)=>e in t?_p(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ei=(t,e,r)=>xp(t,typeof e!="symbol"?e+"":e,r),Oe=class t{constructor(e,r,n){ei(this,"time"),ei(this,"index"),ei(this,"price"),this.time=e,this.index=r,this.price=n}copy(){return new t(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}};function bp(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}var Us={series:t=>t instanceof y||typeof t=="number"||typeof t=="string"||typeof t=="boolean",string:t=>typeof t=="string",color:t=>typeof t=="string"||t===null||typeof t=="number"&&isNaN(t)||t instanceof y,number:t=>typeof t=="number",boolean:t=>typeof t=="boolean",array:t=>Array.isArray(t),object:t=>typeof t=="object",point:t=>t instanceof Oe,primitive:t=>typeof t===null||typeof t!="object"&&typeof t!="function",function:t=>typeof t=="function",undefined:t=>t===void 0,null:t=>t===null,NaN:t=>isNaN(t),any:()=>!0,remaining_options:t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof y)&&!(t instanceof Oe)&&!bp(t)};function ht(t){let e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function le(t,e,r,n){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);let i={},s={},a=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){let l=t[o];if(Us.remaining_options(l)){s=l;break}let c=e.map((u,h)=>a[h]?u[o]:void 0);for(let u=0;u<c.length;u++){let h=c[u];if(h===void 0){a[u]=!1;continue}let p=r[h];if(typeof l=="number"&&isNaN(l)&&(p==="number"||p==="series"))i[h]=l;else{let d=Us[r[h]];typeof d=="function"&&d(l)?i[h]=l:a[u]=!1}}}return{...i,...s,...n}}function N(t,e,r){let n=r.value;return typeof n!="function"||(r.value=function(...i){return this&&this.context&&this.context.isSecondaryContext?null:n.apply(this,i)}),r}var Ka=Object.defineProperty,vp=Object.getOwnPropertyDescriptor,wp=(t,e,r)=>e in t?Ka(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ha=(t,e,r,n)=>{for(var i=n>1?void 0:n?vp(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&Ka(e,r,i),i},dr=(t,e,r)=>wp(t,typeof e!="symbol"?e+"":e,r),Ep=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],Sp={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},Cp=["title","shorttitle","overlay","format","precision","scale","max_bars_back","timeframe","timeframe_gaps","explicit_plot_zorder","max_lines_count","max_labels_count","max_boxes_count","calc_bars_count","max_polylines_count","dynamic_requests","behind_chart"],Np={title:"string",shorttitle:"string",overlay:"boolean",format:"string",precision:"number",scale:"string",max_bars_back:"number",timeframe:"string",timeframe_gaps:"boolean",explicit_plot_zorder:"boolean",max_lines_count:"number",max_labels_count:"number",max_boxes_count:"number",calc_bars_count:"number",max_polylines_count:"number",dynamic_requests:"boolean",behind_chart:"boolean"};function kp(t){return le(t,Cp,Np)}var Ze=class t{get __value(){return NaN}param(e,r=0){return y.from(e).get(r)}any(e){if(e instanceof t)return!0;let r=y.from(e).get(0);return r instanceof t||r==null?!0:typeof r=="number"?r!==r:!1}},sr={freq_all:"alert.freq_all",freq_once_per_bar:"alert.freq_once_per_bar",freq_once_per_bar_close:"alert.freq_once_per_bar_close"},un=class{constructor(e){this.context=e,dr(this,"_firedKeys",new Set),dr(this,"_fallbackCounter",0),dr(this,"_fallbackLastExecTick",-1)}get freq_all(){return sr.freq_all}get freq_once_per_bar(){return sr.freq_once_per_bar}get freq_once_per_bar_close(){return sr.freq_once_per_bar_close}param(e,r,n){return y.from(e).get(0)}any(e,r,n){let i=y.from(e).get(0),s=r?y.from(r).get(0):sr.freq_once_per_bar,a;if(n&&typeof n=="object"&&n.__callsiteId)a=n.__callsiteId;else{let u=this.context._execTick||0;u!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=u),a=`alert_${this._fallbackCounter++}`}let o=this.context.idx,l=this.context.pine?.barstate?.isrealtime??o===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;let c=`${a}:${o}`;if(s===sr.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(s===sr.freq_once_per_bar_close){if(!(this.context.pine?.barstate?.isconfirmed??!0)||this._firedKeys.has(c))return;this._firedKeys.add(c)}this.context.alerts.push({type:"alert",id:a,message:i,freq:s,bar_index:o,time:this.context.data.openTime?.data?.[o]??0})}};Ha([N],un.prototype,"any",1);var pn=class{constructor(e){this.context=e,dr(this,"_acCounter",0),dr(this,"_acLastExecTick",-1),dr(this,"_acFiredKeys",new Set)}extractPlotOptions(e){let r={};for(let n in e)r[n]=y.from(e[n]).get(0);return r}indicator(...e){let r=e.map(s=>s instanceof y?s.get(0):s),n=kp(r),i={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"points",max_bars_back:0,timeframe:"",timeframe_gaps:!0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,max_polylines_count:50,dynamic_requests:!1,behind_chart:!0};return this.context.indicator={...i,...n,...this.context._propOverrides??{}},this.context.indicator}get bar_index(){return this.context.idx}na(e){let r=y.from(e).get(0);return r==null||typeof r=="number"&&isNaN(r)}nz(e,r=0){let n=y.from(e).get(0),i=y.from(r).get(0);return n==null||typeof n=="number"&&isNaN(n)?i:n}fixnan(e){let r=y.from(e);for(let n=0;n<r.length;n++){let i=r.get(n);if(!isNaN(i))return i}return NaN}alertcondition(e,r,n){let i=y.from(e).get(0),s=this.context.idx,a=this.context._execTick||0;a!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=a);let o=`alertcondition_${this._acCounter++}`;if(!i)return;let l=this.context.pine?.barstate?.isrealtime??s===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;let c=`${o}:${s}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);let u=r?y.from(r).get(0):"",h=n?y.from(n).get(0):"";this.context.alerts.push({type:"alertcondition",id:o,title:u,message:h,bar_index:s,time:this.context.data.openTime?.data?.[s]??0})}error(...e){console.error("error called but is currently not implemented",e)}max_bars_back(e,r){}timestamp(...e){let r=e.map(i=>i instanceof y?i.get(0):i),n=le(r,Ep,Sp);if(n.year!==void 0){let i=n.year,s=n.month,a=n.day,o=n.hour||0,l=n.minute||0,c=n.second||0,u=n.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(u,i,s,a,o,l,c)}if(n.dateString!==void 0){let i=n.dateString.trim();if(/[Zz]$/.test(i)||/[+-]\\d{2}:?\\d{2}$/.test(i))return new Date(i).getTime();let s=i.includes("T")?i+"Z":i.replace(/\\s+/,"T")+"Z",a=new Date(s);if(!isNaN(a.getTime())){let o=this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(o,a.getUTCFullYear(),a.getUTCMonth()+1,a.getUTCDate(),a.getUTCHours(),a.getUTCMinutes(),a.getUTCSeconds())}return new Date(i).getTime()}return NaN}_timestampFromComponents(e,r,n,i,s,a,o){let l=new Date(Date.UTC(r,n-1,i,s,a,o));r>=0&&r<100&&l.setUTCFullYear(r);let c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();let u=c.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(u){let h=u[1]==="+"?1:-1,p=parseInt(u[2],10),d=parseInt(u[3]||"0",10),f=h*(p*60+d)*60*1e3;return l.getTime()-f}try{return this._timestampFromIANA(e,r,n,i,s,a,o)}catch{return l.getTime()}}_timestampFromIANA(e,r,n,i,s,a,o){let l=new Date(Date.UTC(r,n-1,i,s,a,o));r>=0&&r<100&&l.setUTCFullYear(r);let c=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(l),u=v=>parseInt(c.find(E=>E.type===v)?.value||"0",10),h=u("year"),p=u("month"),d=u("day"),f=u("hour");f===24&&(f=0);let m=u("minute"),x=u("second"),b=new Date(Date.UTC(h,p-1,d,f,m,x));h>=0&&h<100&&b.setUTCFullYear(h);let w=b.getTime()-l.getTime();return l.getTime()-w}bool(e){let r=y.from(e).get(0);return!isNaN(r)&&r!==0}int(e){let r=y.from(e).get(0);if(typeof r!="number")throw new Error(`Cannot call "int" with argument "x"="${r}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.trunc(r)}float(e){let r=y.from(e).get(0);if(typeof r!="number")throw new Error(`Cannot call "float" with argument "x"="${r}". An argument of "literal string" type was used but a "const float" is expected.`);return r}string(e){return y.from(e).get(0).toString()}Type(e){let r=Object.keys(e),n={};for(let s of r){let a=e[s];a instanceof y&&(a=a.data),Array.isArray(a)&&(a[0],n[s]=a[1])}let i={new:function(...s){let a={},o=null;if(s.length>0){let l=s[s.length-1];if(l&&typeof l=="object"&&!(l instanceof y)&&!Array.isArray(l)&&!(l instanceof Lt)){let c=Object.keys(l);c.length>0&&c.some(u=>r.includes(u))&&(o=l,s=s.slice(0,-1))}}for(let l=0;l<r.length;l++){let c=r[l];o&&c in o?a[c]=o[c]:l<s.length?a[c]=s[l]:c in n&&(a[c]=y.from(n[c]).get(0))}return new Lt(a,this.context,i)},copy:function(s){return new Lt(s.__def__,this.context,i)},_fieldDefaults:n,_definitionKeys:r};return i}};Ha([N],pn.prototype,"alertcondition",1);function Kt(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){let r=t.slice(1);return r.length===6?[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16),1]:r.length===8?[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16),parseInt(r.slice(6,8),16)/255]:null}let e=t.match(/rgba?\\(\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*([\\d.]+))?\\s*\\)/);return e?[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),e[4]?parseFloat(e[4]):1]:null}function Ip(t,e,r,n){let i=Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0"),s=Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0"),a=Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");if(n>=1)return`#${i}${s}${a}`.toUpperCase();let o=Math.round(Math.max(0,Math.min(255,n*255))).toString(16).padStart(2,"0");return`#${i}${s}${a}${o}`.toUpperCase()}var xe={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#F23645",silver:"#B2B5BE",teal:"#089981",white:"#FFFFFF",yellow:"#FDD835"};function Ga(t){if(typeof t!="string")return null;let e=t.trim(),r=e.startsWith("color.")?e.slice(6):e;return Object.prototype.hasOwnProperty.call(xe,r)&&(e=xe[r]),Kt(e)}function mi(t,e,r,n){let i=s=>Math.round(Math.max(0,Math.min(255,s))).toString(16).padStart(2,"0");return`#${i(t)}${i(e)}${i(r)}${i(n*255)}`.toUpperCase()}function Ap(t){let e=Ga(t);return e?mi(e[0],e[1],e[2],e[3]):t}function gt(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}var yi=class{constructor(e){this.context=e}any(e){let r=y.from(e).get(0);return typeof r=="number"&&isNaN(r)?null:r}param(e,r=0){return y.from(e).get(r)}new(e,r){if(e=gt(e),!e||typeof e!="string")return e;if(typeof r=="number"&&isNaN(r)&&(r=void 0),e.startsWith("#")){let n=e.slice(1),i=n.length===8?n.slice(0,6):n;return r!=null?`#${i}${Math.round(255/100*(100-r)).toString(16).padStart(2,"0").toUpperCase()}`:`#${n}`}else{let n=xe[e];if(n)return r!=null?`#${n.slice(1)}${Math.round(255/100*(100-r)).toString(16).padStart(2,"0").toUpperCase()}`:n;let i=e.match(/rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)(?:\\s*,\\s*([\\d.]+))?\\s*\\)/);if(i){let s=i[1],a=i[2],o=i[3];if(r!=null){let l=parseInt(s).toString(16).padStart(2,"0"),c=parseInt(a).toString(16).padStart(2,"0"),u=parseInt(o).toString(16).padStart(2,"0"),h=Math.round(255/100*(100-r)).toString(16).padStart(2,"0").toUpperCase();return`#${l}${c}${u}${h}`}return e}return r!=null?`rgba(${e}, ${(100-r)/100})`:e}}rgb(e,r,n,i){return typeof i=="number"&&isNaN(i)&&(i=void 0),i!=null?`rgba(${e}, ${r}, ${n}, ${(100-i)/100})`:`rgb(${e}, ${r}, ${n})`}from_gradient(e,r,n,i,s){if(e=gt(e),r=gt(r),n=gt(n),i=gt(i),s=gt(s),e==null||typeof e=="number"&&isNaN(e)||r==null||typeof r=="number"&&isNaN(r)||n==null||typeof n=="number"&&isNaN(n)||i==null||typeof i=="number"&&isNaN(i)||s==null||typeof s=="number"&&isNaN(s))return;let a=0;n!==r&&(a=(e-r)/(n-r)),a=Math.max(0,Math.min(1,a));let o=Kt(typeof i=="string"?i:"#000000")||[0,0,0,1],l=Kt(typeof s=="string"?s:"#FFFFFF")||[255,255,255,1],c=o[0]+(l[0]-o[0])*a,u=o[1]+(l[1]-o[1])*a,h=o[2]+(l[2]-o[2])*a,p=o[3]+(l[3]-o[3])*a;return Ip(c,u,h,p)}r(e){if(e=gt(e),!e||typeof e!="string")return NaN;let r=Kt(e);return r?r[0]:NaN}g(e){if(e=gt(e),!e||typeof e!="string")return NaN;let r=Kt(e);return r?r[1]:NaN}b(e){if(e=gt(e),!e||typeof e!="string")return NaN;let r=Kt(e);return r?r[2]:NaN}t(e){if(e=gt(e),!e||typeof e!="string")return NaN;let r=Kt(e);return r?Math.round(100-r[3]*100):NaN}aqua(){return xe.aqua}black(){return xe.black}blue(){return xe.blue}fuchsia(){return xe.fuchsia}gray(){return xe.gray}green(){return xe.green}lime(){return xe.lime}maroon(){return xe.maroon}navy(){return xe.navy}olive(){return xe.olive}orange(){return xe.orange}purple(){return xe.purple}red(){return xe.red}silver(){return xe.silver}teal(){return xe.teal}white(){return xe.white}yellow(){return xe.yellow}},Tp=Object.defineProperty,Dp=(t,e,r)=>e in t?Tp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hn=(t,e,r)=>Dp(t,typeof e!="symbol"?e+"":e,r);function gi(t){if(!t)return"";let e=t.trim().toUpperCase();return e==="1D"||e==="D"?"D":e==="1W"||e==="W"?"W":e==="1M"||e==="M"?"M":e}function _i(t,e){let r=Mp(e);if(e==="M"){let o=new Date(t);return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),1)}if(e==="W"){let o=new Date(t),l=o.getUTCDay(),c=l===0?6:l-1;return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),o.getUTCDate()-c)}if(e==="D"||r>=1440)return Math.floor(t/864e5)*864e5;let n=r*6e4,i=Math.floor(t/864e5)*864e5,s=t-i,a=Math.floor(s/n)*n;return i+a}function Mp(t){if(t==="D")return 1440;if(t==="W")return 10080;if(t==="M")return 43200;let e=parseInt(t,10);return isNaN(e)?1440:e}function Zt(t,e){let r=e.trim();if(r==="UTC"||r==="GMT"||r==="Etc/UTC"){let i=new Date(t);return{year:i.getUTCFullYear(),month:i.getUTCMonth()+1,day:i.getUTCDate(),hour:i.getUTCHours(),minute:i.getUTCMinutes(),second:i.getUTCSeconds(),dayOfWeek:i.getUTCDay()}}let n=r.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(n){let i=n[1]==="+"?1:-1,s=parseInt(n[2],10),a=parseInt(n[3]||"0",10),o=i*(s*60+a)*60*1e3,l=new Date(t+o);return{year:l.getUTCFullYear(),month:l.getUTCMonth()+1,day:l.getUTCDate(),hour:l.getUTCHours(),minute:l.getUTCMinutes(),second:l.getUTCSeconds(),dayOfWeek:l.getUTCDay()}}try{let i=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",weekday:"short",hour12:!1}).formatToParts(new Date(t)),s=c=>parseInt(i.find(u=>u.type===c)?.value||"0",10),a=s("hour");a===24&&(a=0);let o=i.find(c=>c.type==="weekday")?.value||"Sun",l={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:s("year"),month:s("month"),day:s("day"),hour:a,minute:s("minute"),second:s("second"),dayOfWeek:l[o]??0}}catch{let i=new Date(t);return{year:i.getUTCFullYear(),month:i.getUTCMonth()+1,day:i.getUTCDate(),hour:i.getUTCHours(),minute:i.getUTCMinutes(),second:i.getUTCSeconds(),dayOfWeek:i.getUTCDay()}}}function Pp(t,e,r){let n=new Date(Date.UTC(t,e-1,r)),i=n.getUTCDay()||7;n.setUTCDate(n.getUTCDate()+4-i);let s=new Date(Date.UTC(n.getUTCFullYear(),0,1));return Math.ceil(((n.getTime()-s.getTime())/864e5+1)/7)}var Rp=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],Fp={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"},dn=class{constructor(e,r="openTime"){hn(this,"context"),hn(this,"dataField"),this.context=e,this.dataField=r}get __value(){return this.context.data[this.dataField]}param(e,r=0){return y.from(e).get(r)}any(...e){let r=e.map(p=>p instanceof y?p.get(0):p),n=le(r,Rp,Fp),i=n.bars_back??0,s=n.timeframe||"",a=this.context.data[this.dataField],o=y.from(a).get(i);if(isNaN(o)||o==null)return NaN;let l=this.context.timeframe||"",c=gi(s),u=gi(l),h;if(!c||c===u?h=o:h=_i(o,c),n.session!==void 0&&n.session!==""){let p=n.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(h,n.session,p)?h:NaN}return h}_isInSession(e,r,n){let i=r.match(/^(\\d{2})(\\d{2})-(\\d{2})(\\d{2})$/);if(!i)return!0;let s=parseInt(i[1],10),a=parseInt(i[2],10),o=parseInt(i[3],10),l=parseInt(i[4],10),c=Zt(e,n),u=c.hour,h=c.minute,p=u*60+h,d=s*60+a,f=o*60+l;return d<=f?p>=d&&p<f:p>=d||p<f}},Bp=[[],["time"],["time","timezone"]],Lp={time:"number",timezone:"string"},xt=class{constructor(e,r){hn(this,"context"),hn(this,"extractor"),this.context=e,this.extractor=r}get __value(){let e=y.from(this.context.data.openTime).get(0);if(isNaN(e))return NaN;let r=this.context.pine?.syminfo?.timezone||"UTC",n=Zt(e,r);return this.extractor(n)}param(e,r=0){return y.from(e).get(r)}any(...e){let r=e.map(o=>o instanceof y?o.get(0):o);if(r.length===0)return this.__value;let n=le(r,Bp,Lp),i=n.time;if(i===void 0||isNaN(i))return NaN;let s=n.timezone||this.context.pine?.syminfo?.timezone||"UTC",a=Zt(i,s);return this.extractor(a)}},Ft={dayofmonth:t=>t.day,dayofweek:t=>t.dayOfWeek===0?1:t.dayOfWeek+1,hour:t=>t.hour,minute:t=>t.minute,month:t=>t.month,second:t=>t.second,weekofyear:t=>Pp(t.year,t.month,t.day),year:t=>t.year},ls=new Set(["open","high","low","close","hl2","hlc3","ohlc4","hlcc4","volume"]);function Ya(t,e){if(!ls.has(e))return;let r=t?.data?.[e];if(r!=null)return y.from(r).get(0)}var Op=[["defval","title","tooltip","inline","group","display"],["defval","title","tooltip","group","confirm","display"],["defval","title","tooltip","inline","group","confirm","display"],["defval","title","options","tooltip","inline","group","confirm","display"],["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display"]],Vp={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function Ke(t){let e,r=t[t.length-1];r&&typeof r=="object"&&Object.prototype.hasOwnProperty.call(r,"__varId")&&(e=r.__varId,t=t.slice(0,-1));let n=le(t,Op,Vp);return e!==void 0&&(n.__varId=e),n}function Xe(t,e){return e.__varId&&t.inputs&&t.inputs[e.__varId]!==void 0?t.inputs[e.__varId]:e.title&&t.inputs&&t.inputs[e.title]!==void 0?t.inputs[e.title]:e.defval}function jp(t){return(...e)=>{let r=Ke(e),n=Xe(t,r);if(typeof n=="string"&&typeof r.defval=="number"){let i=Ya(t,n);if(i!==void 0)return i}return n}}function $p(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Wp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Up(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function qp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function zp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Kp(t){return(e,r=0)=>y.from(e).get(r)}function Hp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Gp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Yp(t){return(...e)=>{let r=Ke(e),n=Xe(t,r);if(typeof n=="string"){let i=Ya(t,n);return i!==void 0?i:r.defval}return n}}function Zp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Xp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Qp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function Jp(t){return(...e)=>{let r=Ke(e);return Xe(t,r)}}function eh(t){return(...e)=>Ke(e).defval}var th=Object.defineProperty,rh=(t,e,r)=>e in t?th(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Be=(t,e,r)=>rh(t,typeof e!="symbol"?e+"":e,r),nh={any:jp,bool:$p,color:Wp,enum:Up,float:qp,int:zp,param:Kp,price:Hp,session:Gp,source:Yp,string:Zp,symbol:Xp,text_area:Qp,time:Jp,timeframe:eh},xi=class{constructor(e){this.context=e,Be(this,"any"),Be(this,"bool"),Be(this,"color"),Be(this,"enum"),Be(this,"float"),Be(this,"int"),Be(this,"param"),Be(this,"price"),Be(this,"session"),Be(this,"source"),Be(this,"string"),Be(this,"symbol"),Be(this,"text_area"),Be(this,"time"),Be(this,"timeframe"),Object.entries(nh).forEach(([r,n])=>{this[r]=n(e)})}};function ih(t){return e=>Math.abs(y.from(e).get(0))}function sh(t){return e=>Math.acos(y.from(e).get(0))}function ah(t){return e=>Math.asin(y.from(e).get(0))}function oh(t){return e=>Math.atan(y.from(e).get(0))}function lh(t){return(...e)=>{let r=e.map(n=>y.from(n).get(0));return r.reduce((n,i)=>n+i,0)/r.length}}function ch(t){return e=>Math.ceil(y.from(e).get(0))}function uh(t){return e=>Math.cos(y.from(e).get(0))}function ph(t){return()=>Math.E}function hh(t){return e=>Math.exp(y.from(e).get(0))}function dh(t){return e=>Math.floor(y.from(e).get(0))}function fh(t){return e=>Math.log(y.from(e).get(0))}function mh(t){return e=>Math.log(y.from(e).get(0))}function yh(t){return e=>Math.log10(y.from(e).get(0))}function gh(t){return(...e)=>{let r=e.map(n=>y.from(n).get(0));return Math.max(...r)}}function _h(t){return(...e)=>{let r=e.map(n=>y.from(n).get(0));return Math.min(...r)}}function xh(t){return(e,r,n)=>typeof e=="string"?e:e instanceof y?r?new y(e.data,e.offset+r):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[n]||(t.params[n]=[]),Array.isArray(e)?new y(e,r||0):(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,new y(t.params[n],r||0)))}function bh(t){return()=>1.618033988749895}function vh(t){return()=>Math.PI}function wh(t){return(e,r)=>Math.pow(y.from(e).get(0),y.from(r).get(0))}function Eh(t){return()=>Math.random()}function ti(t){return t!==t?NaN:Math.sign(t)*Math.round(Math.abs(t))}function Sh(t){return(e,r)=>{let n=y.from(e).get(0);if(r==null)return ti(n);let i=y.from(r).get(0);if(i===0)return ti(n);let s=Math.pow(10,i);return ti(n*s)/s}}function Ch(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Nh(t){return()=>.6180339887498948}function kh(t){return e=>Math.sign(y.from(e).get(0))}function Ih(t){return e=>Math.sin(y.from(e).get(0))}function Ah(t){return e=>Math.sqrt(y.from(e).get(0))}function Th(t){return(e,r)=>{let n=y.from(r).get(0),i=y.from(e),s=0;for(let a=0;a<n;a++){let o=i.get(a);s+=o}return s}}function Dh(t){return e=>Math.tan(y.from(e).get(0))}function Mh(t){return e=>{let r=y.from(e).get(0);return r==null||Number.isNaN(r)?NaN:r*(180/Math.PI)}}function Ph(t){return e=>{let r=y.from(e).get(0);return r==null||Number.isNaN(r)?NaN:r*(Math.PI/180)}}function Rh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10:n===i}}function Fh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10?!0:n>i:n>=i}}function Bh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10?!1:n>i:n>i}}function Lh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n!="number"||typeof i!="number"?n/i:isNaN(n)||isNaN(i)?NaN:Math.trunc(n/i)}}function Oh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10?!0:n<i:n<=i}}function Vh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)<1e-10?!1:n<i:n<i}}function jh(t){return(e,r)=>{let n=y.from(e).get(0),i=y.from(r).get(0);return typeof n=="number"&&typeof i=="number"?isNaN(n)||isNaN(i)?NaN:Math.abs(n-i)>=1e-10:n!==i}}var $h=Object.defineProperty,Wh=(t,e,r)=>e in t?$h(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Z=(t,e,r)=>Wh(t,typeof e!="symbol"?e+"":e,r),Uh={abs:ih,acos:sh,asin:ah,atan:oh,avg:lh,ceil:ch,cos:uh,e:ph,exp:hh,floor:dh,ln:fh,log:mh,log10:yh,max:gh,min:_h,param:xh,phi:bh,pi:vh,pow:wh,random:Eh,round:Sh,round_to_mintick:Ch,rphi:Nh,sign:kh,sin:Ih,sqrt:Ah,sum:Th,tan:Dh,todegrees:Mh,toradians:Ph,__eq:Rh,__ge:Fh,__gt:Bh,__idiv:Lh,__le:Oh,__lt:Vh,__neq:jh},bi=class{constructor(e){this.context=e,Z(this,"_cache",{}),Z(this,"abs"),Z(this,"acos"),Z(this,"asin"),Z(this,"atan"),Z(this,"avg"),Z(this,"ceil"),Z(this,"cos"),Z(this,"e"),Z(this,"exp"),Z(this,"floor"),Z(this,"ln"),Z(this,"log"),Z(this,"log10"),Z(this,"max"),Z(this,"min"),Z(this,"param"),Z(this,"phi"),Z(this,"pi"),Z(this,"pow"),Z(this,"random"),Z(this,"round"),Z(this,"round_to_mintick"),Z(this,"rphi"),Z(this,"sign"),Z(this,"sin"),Z(this,"sqrt"),Z(this,"sum"),Z(this,"tan"),Z(this,"todegrees"),Z(this,"toradians"),Z(this,"__eq"),Z(this,"__ge"),Z(this,"__gt"),Z(this,"__idiv"),Z(this,"__le"),Z(this,"__lt"),Z(this,"__neq"),Object.entries(Uh).forEach(([r,n])=>{this[r]=n(e)})}};function qh(t){return(e,r,n)=>{t.params[n]||(t.params[n]=[]);let i;if(e instanceof y)i=e.get(r||0);else if(Array.isArray(e)){let s=e.some(o=>o instanceof y),a=e.every(o=>!(o instanceof y)&&!Array.isArray(o));(s||a)&&e.length>=1?i=e.map(o=>o instanceof y?o.get(0):o):i=y.from(e).get(r||0)}else i=e;return t.params[n].length===0?t.params[n].push(i):t.params[n][t.params[n].length-1]=i,t._requestParamSources||(t._requestParamSources={}),t._requestParamSources[n]=e,[i,n]}}var zh=new Set(["heikinashi","standard"]);function Lr(t){if(typeof t!="string")return{symbol:t,modifier:null};let e=t.lastIndexOf(";");if(e<=0||e===t.length-1)return{symbol:t,modifier:null};let r=t.slice(e+1).toLowerCase();return zh.has(r)?{symbol:t.slice(0,e),modifier:r}:{symbol:t,modifier:null}}function Ot(t){return Lr(t).symbol}function vi(t,e){return`${Ot(t)};${e}`}var yr=["1","3","5","15","30","45","60","120","180","240","D","W","M"],Kr={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function fn(t){if(yr.includes(t))return t;if(Kr[t])return Kr[t];let e=t.toLowerCase();if(Kr[e])return Kr[e];let r=t.toUpperCase();return yr.includes(r)?r:t}function qs(t,e,r,n,i=!1,s=!1){for(let a=0;a<r.length;a++)if(r[a]<=t&&t<n[a])return i||s||e>=n[a]?a:a-1;return-1}function zs(t,e,r,n,i=!1,s,a=!1){for(let o=r.length-1;o>=0;o--){if(n[o]<=e&&r[o]>=t){let l=s&&e>s;if(a&&i)for(let c=0;c<r.length;c++){if(r[c]>=t&&r[c]<e)return c;if(r[c]>=e)break}if(l&&i&&!a)for(let c=0;c<r.length;c++){if(r[c]>=t&&r[c]<e)return c;if(r[c]>=e)break}return o}if(n[o]<t)break}return-1}var Ks=[["symbol","timeframe","expression"],["symbol","timeframe","expression","gaps"],["symbol","timeframe","expression","gaps","lookahead"],["symbol","timeframe","expression","gaps","lookahead","ignore_invalid_symbol"],["symbol","timeframe","expression","gaps","lookahead","ignore_invalid_symbol","currency"],["symbol","timeframe","expression","gaps","lookahead","ignore_invalid_symbol","currency","calc_bars_count"]],Kh={symbol:"series",timeframe:"series",expression:"any",gaps:"series",lookahead:"series",ignore_invalid_symbol:"series",currency:"series",calc_bars_count:"series"};function cs(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function Hh(t,e){return t.map(r=>cs(r)?(e.push(r[1]),r[0]):(e.push(void 0),r))}function ar(t){return cs(t)?t[0]:t}function Gh(t,e,r,n){let i=e[e.length-1].indexOf(t);if(i>=0&&i<r.length&&r[i]!==void 0)return r[i];if(cs(n))return n[1]}function wi(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(wi):t}function Yh(t){return async(...e)=>{let r=[],n=Hh(e,r),i=le(n,Ks,Kh),s=ar(i.symbol),a=ar(i.timeframe),o=ar(i.expression),l=ar(i.gaps),c=ar(i.lookahead),u=s instanceof y?s.get(0):s,h=typeof t.tickerId=="string"&&t.tickerId.includes(":")?t.tickerId.split(":")[1]:t.tickerId,p=typeof h=="string"?Lr(h):{symbol:h,modifier:null},d=p.modifier==="standard"?null:p.modifier,f=u===""?t.tickerId:u,m=typeof f=="string"&&f.includes(":")?f.split(":")[1]:f,x=a instanceof y?a.get(0):a,b=x===""?t.timeframe:typeof x=="string"?x:String(x??""),w=o,v=Gh("expression",Ks,r,i.expression),E=l,A=c,C=E===!0||E==="gaps_on",D=A===!0||A==="lookahead_on",j=(()=>{let Ae=ar(i.calc_bars_count);return typeof Ae=="number"&&Ae>0?Ae:void 0})();if(t.isSecondaryContext){let Ae=wi(w);return Array.isArray(Ae)?[Ae]:Ae}let k=yr.indexOf(fn(t.timeframe)),V=yr.indexOf(fn(b));if(k==-1||V==-1)throw new Error("Invalid timeframe");let T=typeof m=="string"?Lr(m):{symbol:m,modifier:null},W=T.modifier==="standard"?null:T.modifier,R=!m||m===""||T.symbol===p.symbol&&W===d;if(k===V&&R){let Ae=wi(w);return Array.isArray(Ae)?[Ae]:Ae}let M=k>V,H=y.from(t.data.openTime).get(0),ee=y.from(t.data.closeTime).get(0),we=t.idx===t.length-1&&ee>Date.now(),se=`${m}_${b}_${v}`,Fe=`${se}_prevIdx`;if(t.cache[se]){let Ae=t.cache[se];t.dataVersion>Ae.dataVersion&&(await Ae.pineTS.updateTail(Ae.context),Ae.dataVersion=t.dataVersion);let wr=Ae.context,zr=M?zs(H,ee,wr.data.openTime.data,wr.data.closeTime.data,D,t.eDate,C):qs(H,ee,wr.data.openTime.data,wr.data.closeTime.data,D,we);if(zr==-1)return NaN;let ir=wr.params[v][zr];if(!M&&C){let $s=t.cache[Fe];return $s!==void 0&&$s===zr?NaN:(t.cache[Fe]=zr,Array.isArray(ir)?[ir]:ir)}return Array.isArray(ir)?[ir]:ir}let vr=1e3*60*60*24*30,Os=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),$l=j?void 0:Os?Os-vr:void 0,Wl=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),qr=new Wt(t.source,m,b,j,$l,Wl);qr.markAsSecondary();let Vs=typeof v=="string"?v:"",Ul=Vs.match(/p\\d+$/)?.[0]??Vs,js=t._ltfTruncatedBodies?.[Ul],nr=js?await qr.runPretranspiled(js):await qr.run(t.pineTSCode);t.cache[se]={pineTS:qr,context:nr,dataVersion:t.dataVersion};let Qn=M?zs(H,ee,nr.data.openTime.data,nr.data.closeTime.data,D,t.eDate,C):qs(H,ee,nr.data.openTime.data,nr.data.closeTime.data,D,we);if(Qn==-1)return NaN;let Jn=nr.params[v][Qn];return!M&&C?(t.cache[Fe]=Qn,NaN):Array.isArray(Jn)?[Jn]:Jn}}var Hs=[["symbol","timeframe","expression"],["symbol","timeframe","expression","ignore_invalid_symbol"],["symbol","timeframe","expression","ignore_invalid_symbol","currency"],["symbol","timeframe","expression","ignore_invalid_symbol","currency","ignore_invalid_timeframe"],["symbol","timeframe","expression","ignore_invalid_symbol","currency","ignore_invalid_timeframe","calc_bars_count"]],Zh={symbol:"series",timeframe:"series",expression:"any",ignore_invalid_symbol:"series",currency:"series",ignore_invalid_timeframe:"series",calc_bars_count:"series"};function us(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function Xh(t,e){return t.map(r=>us(r)?(e.push(r[1]),r[0]):(e.push(void 0),r))}function or(t){return us(t)?t[0]:t}function Qh(t,e,r,n){let i=e[e.length-1].indexOf(t);if(i>=0&&i<r.length&&r[i]!==void 0)return r[i];if(us(n))return n[1]}function lr(t){return typeof t=="number"?z.float:typeof t=="boolean"?z.bool:typeof t=="string"?z.string:z.any}var Za={open:t=>t.open,high:t=>t.high,low:t=>t.low,close:t=>t.close,volume:t=>t.volume,hl2:t=>(t.high+t.low)/2,hlc3:t=>(t.high+t.low+t.close)/3,ohlc4:t=>(t.high+t.low+t.open+t.close)/4,hlcc4:t=>(t.high+t.low+t.close+t.close)/4,time:t=>t.openTime,openTime:t=>t.openTime,closeTime:t=>t.closeTime};function Ei(t,e){if(!(t instanceof y))return null;let r=e?.data;if(!r)return null;for(let n of Object.keys(Za))if(t===r[n])return n;return null}function Jh(t,e){if(t instanceof y&&(t=t.get(0)),!(t instanceof Lt))return null;let r=t._udt;if(!r||!r._fieldDefaults||!Array.isArray(r._definitionKeys))return null;let n=r._definitionKeys;if(n.length===0)return null;let i=[];for(let s of n){if(!(s in r._fieldDefaults))return null;let a=r._fieldDefaults[s],o=Ei(a,e);if(o===null)return null;i.push(o)}return{kind:"udt",builtinNames:i,fieldNames:n,udt:r}}function ed(t,e){if(t===void 0)return null;if(Array.isArray(t)){let n=[];for(let i of t){let s=Ei(i,e);if(s===null)return null;n.push(s)}return n.length>0?{kind:"tuple",builtinNames:n}:null}let r=Ei(t,e);return r!==null?{kind:"series",builtinNames:[r]}:Jh(t,e)}async function Gs(t,e,r,n,i,s){let a=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),o=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),l=new Wt(t.source,e,r,n,a,o);l.markAsSecondary(),await l.ready();let c=l.openTime,u=l.closeTime,h=l.data,p=i.builtinNames.map(f=>Za[f]),d;if(i.kind==="series")d=h.map(f=>p[0](f));else if(i.kind==="tuple")d=h.map(f=>p.map(m=>m(f)));else{let f=i.fieldNames,m=i.udt;d=h.map(x=>{let b={};for(let w=0;w<f.length;w++)b[f[w]]=p[w](x);return new Lt(b,t,m)})}return{data:{openTime:{data:c},closeTime:{data:u}},params:{[s]:d}}}function td(t){return async(...e)=>{let r=[],n=Xh(e,r),i=le(n,Hs,Zh),s=or(i.symbol),a=or(i.timeframe),o=or(i.expression),l=s instanceof y?s.get(0):s,c=l===""?t.tickerId:l,u=typeof c=="string"&&c.includes(":")?c.split(":")[1]:c,h=a instanceof y?a.get(0):a,p=h===""?t.timeframe:typeof h=="string"?h:String(h??""),d=o,f=Qh("expression",Hs,r,i.expression);or(i.ignore_invalid_symbol);let m=or(i.ignore_invalid_timeframe),x=(()=>{let M=or(i.calc_bars_count);return typeof M=="number"&&M>0?M:void 0})();if(t.isSecondaryContext)return Array.isArray(d)?[d.map(M=>new q([M],lr(M),t))]:new q([d],lr(d),t);let b=yr.indexOf(fn(t.timeframe)),w=yr.indexOf(fn(p));if(b===-1||w===-1){if(m)return NaN;throw new Error("Invalid timeframe")}if(w>b){if(m)return NaN;throw new Error(`Timeframe ${p} is not lower than or equal to chart timeframe ${t.timeframe}`)}if(w===b)return Array.isArray(d)?[d.map(M=>new q([M],lr(M),t))]:new q([d],lr(d),t);let v=`${u}_${p}_${f}_lower`,E=t._requestParamSources?.[f],A=ed(E,t);if(!t.cache[v])if(A!==null){let M=await Gs(t,u,p,x,A,f);t.cache[v]={pineTS:null,context:M,dataVersion:t.dataVersion,_fastPath:!0,_fastPathArgs:{builtinExpr:A}}}else{let M=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),H=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),ee=new Wt(t.source,u,p,x,M,H);ee.markAsSecondary();let we=typeof f=="string"?f:"",se=we.match(/p\\d+$/)?.[0]??we,Fe=t._ltfTruncatedBodies?.[se],vr;Fe?vr=await ee.runPretranspiled(Fe):vr=await ee.run(t.pineTSCode),t.cache[v]={pineTS:ee,context:vr,dataVersion:t.dataVersion}}let C=t.cache[v];if(t.dataVersion>C.dataVersion)if(C._fastPath){let M=await Gs(t,u,p,x,C._fastPathArgs.builtinExpr,f);C.context=M,C.dataVersion=t.dataVersion}else await C.pineTS.updateTail(C.context),C.dataVersion=t.dataVersion;let D=C.context,j=y.from(t.data.openTime).get(0),k=y.from(t.data.closeTime).get(0),V=D.data.openTime.data,T=D.data.closeTime.data,W=D.params[f];if(!W)return Array.isArray(d)?[d.map(()=>new q([],z.float,t))]:new q([],z.float,t);let R=[];for(let M=0;M<V.length;M++){let H=V[M];if(!(T[M]<=j)){if(H>=k)break;H>=j&&H<k&&R.push(W[M])}}if(R.length>0&&Array.isArray(R[0])){let M=R[0].length,H=[];for(let ee=0;ee<M;ee++){let we=R.map(Fe=>Fe[ee]),se=we.length>0?lr(we[0]):z.float;H.push(new q(we,se,t))}return[H]}else{let M=R.length>0?lr(R[0]):z.float;return new q(R,M,t)}}}var rd=Object.defineProperty,nd=(t,e,r)=>e in t?rd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Hr=(t,e,r)=>nd(t,typeof e!="symbol"?e+"":e,r),id={param:qh,security:Yh,security_lower_tf:td},Si=class{constructor(e){this.context=e,Hr(this,"_cache",{}),Hr(this,"param"),Hr(this,"security"),Hr(this,"security_lower_tf"),Object.entries(id).forEach(([r,n])=>{this[r]=n(e)})}};function sd(t){return e=>{t.taState||(t.taState={});let r=e||"accdist";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),o=t.get(t.data.volume,0);if(isNaN(i)||isNaN(s)||isNaN(a)||isNaN(o))return n.currentCumulativeSum=n.prevCumulativeSum,t.precision(n.prevCumulativeSum);let l=s-a,c=0;l!==0&&(c=(i-a-(s-i))/l*o);let u=n.prevCumulativeSum+c;return n.currentCumulativeSum=u,t.precision(u)}}function ad(t){return(e,r,n,i,s)=>{let a=y.from(r).get(0),o=y.from(n).get(0),l=y.from(i).get(0);t.taState||(t.taState={});let c=s||`alma_${a}_${o}_${l}`;if(!t.taState[c]){let m=o*(a-1),x=a/l,b=[],w=0;for(let v=0;v<a;v++){let E=Math.exp(-Math.pow(v-m,2)/(2*x*x));b.push(E),w+=E}for(let v=0;v<b.length;v++)b[v]/=w;t.taState[c]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weights:b}}let u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.prevWindow=[...u.currentWindow],u.prevCallCount=u.currentCallCount),u.lastIdx=t.idx);let h=y.from(e).get(0),p=[...u.prevWindow];for(p.unshift(h);p.length>a;)p.pop();let d=u.prevCallCount+1;if(p.length<a&&(d>=a||t.idx>=a-1)){let m=y.from(e);for(;p.length<a;)p.push(m.get(p.length))}if(u.currentWindow=p,u.currentCallCount=d,p.length<a)return NaN;let f=0;for(let m=0;m<a;m++)f+=u.weights[m]*p[a-1-m];return t.precision(f)}}function od(t){return(e,r)=>{let n=y.from(e).get(0);t.taState||(t.taState={});let i=r||`atr_${n}`;t.taState[i]||(t.taState[i]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});let s=t.taState[i];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevAtr=s.currentAtr,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);let a=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(l))return NaN;let c=t.idx>0?t.get(t.data.close,1):null,u;if(c!==null&&!isNaN(c)){let m=a-o,x=Math.abs(a-c),b=Math.abs(o-c);u=Math.max(m,x,b)}else u=a-o;let h=s.prevInitCount,p=s.prevInitSum,d=s.prevAtr;if(h<n){if(p+=u,h++,s.currentInitSum=p,s.currentInitCount=h,h===n){let m=p/n;return s.currentAtr=m,t.precision(m)}return NaN}let f=(d*(n-1)+u)/n;return s.currentAtr=f,t.precision(f)}}function ld(t){return(e,r)=>{t.taState||(t.taState={});let n=r||"barssince";t.taState[n]||(t.taState[n]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});let i=t.taState[n];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevLastTrueIndex=i.currentLastTrueIndex),i.lastIdx=t.idx);let s=y.from(e).get(0),a=i.prevLastTrueIndex;return s&&(a=t.idx),i.currentLastTrueIndex=a,a===null?NaN:t.idx-a}}function cd(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`bb_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];let u=[...l.prevWindow],h=l.prevSum;for(u.unshift(c),h+=c;u.length>s;){let b=u.pop();h-=b}if(u.length<s&&t.idx>=s-1){let b=y.from(e);for(;u.length<s;){let w=b.get(u.length);if(isNaN(w))break;u.push(w),h+=w}}if(l.currentWindow=u,l.currentSum=h,u.length<s)return[[NaN,NaN,NaN]];let p=h/s,d=0;for(let b=0;b<s;b++)d+=Math.pow(u[b]-p,2);let f=Math.sqrt(d/s),m=p+a*f,x=p-a*f;return[[t.precision(p),t.precision(m),t.precision(x)]]}}function ud(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`bbw_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;let u=[...l.prevWindow],h=l.prevSum;for(u.unshift(c),h+=c;u.length>s;){let w=u.pop();h-=w}if(u.length<s&&t.idx>=s-1){let w=y.from(e);for(;u.length<s;){let v=w.get(u.length);if(isNaN(v))break;u.push(v),h+=v}}if(l.currentWindow=u,l.currentSum=h,u.length<s)return NaN;let p=h/s,d=0;for(let w=0;w<s;w++){let v=u[w]-p;d+=v*v}let f=d/s,m=Math.sqrt(f),x=a*m;if(p===0)return t.precision(0);let b=2*x/p*100;return t.precision(b)}}function pd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`cci_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0);if(isNaN(o))return NaN;let l=[...a.prevWindow],c=a.prevSum;for(l.unshift(o),c+=o;l.length>i;){let m=l.pop();c-=m}let u=a.prevCallCount+1;if(l.length<i&&(u>=i||t.idx>=i-1)){let m=y.from(e);for(;l.length<i;){let x=m.get(l.length);if(isNaN(x))break;l.push(x),c+=x}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=u,l.length<i)return NaN;let h=c/i,p=0;for(let m=0;m<i;m++)p+=Math.abs(l[m]-h);let d=p/i;if(d===0)return 0;let f=(o-h)/(.015*d);return t.precision(f)}}function hd(t){return(e,r=1,n)=>{typeof r=="string"&&(n=r,r=1);let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`change_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i+1;)l.pop();let c=a.prevCallCount+1;if(l.length<i+1&&(c>=i+1||t.idx>=i)){let h=y.from(e);for(;l.length<i+1;)l.push(h.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=i)return NaN;let u=o-l[i];return t.precision(u)}}function dd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`cmo_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevGainsWindow=[...a.currentGainsWindow],a.prevLossesWindow=[...a.currentLossesWindow],a.prevGainsSum=a.currentGainsSum,a.prevLossesSum=a.currentLossesSum),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;let c=o-l,u=c>=0?c:0,h=c>=0?0:-c,p=[...a.prevGainsWindow],d=[...a.prevLossesWindow],f=a.prevGainsSum,m=a.prevLossesSum;if(p.unshift(u),d.unshift(h),f+=u,m+=h,p.length<i)return a.currentGainsWindow=p,a.currentLossesWindow=d,a.currentGainsSum=f,a.currentLossesSum=m,NaN;if(p.length>i){let w=p.pop(),v=d.pop();f-=w,m-=v}a.currentGainsWindow=p,a.currentLossesWindow=d,a.currentGainsSum=f,a.currentLossesSum=m;let x=f+m;if(x===0)return t.precision(0);let b=100*(f-m)/x;return t.precision(b)}}function fd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e),a=0,o=!1;for(let u=0;u<i;u++){let h=s.get(u);if(isNaN(h)){o=!0;break}a+=h}if(o)return NaN;let l=0;for(let u=0;u<i;u++){let h=s.get(u);l+=h*(u+1)}if(a===0)return NaN;let c=-l/a;return t.precision(c)}}function md(t){return(e,r,n,i)=>{let s=y.from(n).get(0),a=y.from(e),o=y.from(r);if(t.idx<s-1)return NaN;let l=0,c=0,u=0,h=0,p=0,d=0;for(let w=0;w<s;w++){let v=a.get(w),E=o.get(w);isNaN(v)||isNaN(E)||(l+=v,c+=E,u+=v*E,h+=v*v,p+=E*E,d++)}if(d<2)return NaN;let f=d*u-l*c,m=d*h-l*l,x=d*p-c*c;if(m<=0||x<=0)return t.precision(0);let b=f/Math.sqrt(m*x);return t.precision(b)}}function yd(t){return(e,r,n)=>{let i=y.from(e),s=y.from(r),a=i.get(0),o=s.get(0),l=i.get(1),c=s.get(1);if(isNaN(a)||isNaN(o)||isNaN(l)||isNaN(c))return!1;let u=a>o&&l<=c,h=a<o&&l>=c;return u||h}}function gd(t){return(e,r)=>{let n=y.from(e),i=y.from(r),s=n.get(0),a=i.get(0),o=n.get(1),l=i.get(1);return o<=l&&s>a}}function _d(t){return(e,r)=>{let n=y.from(e),i=y.from(r),s=n.get(0),a=i.get(0),o=n.get(1),l=i.get(1);return o>=l&&s<a}}function xd(t){return(e,r)=>{t.taState||(t.taState={});let n=r||"cum";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let i=t.taState[n];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevCumulativeSum=i.currentCumulativeSum),i.lastIdx=t.idx);let s=y.from(e).get(0);if(isNaN(s))return i.currentCumulativeSum=i.prevCumulativeSum,t.precision(i.prevCumulativeSum);let a=i.prevCumulativeSum+s;return i.currentCumulativeSum=a,t.precision(a)}}function bd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`dev_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0)||0,l=[...a.prevWindow],c=a.prevSum;for(l.unshift(o),c+=o;l.length>i;){let f=l.pop();c-=f}let u=a.prevCallCount+1;if(l.length<i&&(u>=i||t.idx>=i-1)){let f=y.from(e);for(;l.length<i;){let m=f.get(l.length);l.push(m),c+=m}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=u,l.length<i)return NaN;let h=c/i,p=0;for(let f=0;f<i;f++)p+=Math.abs(l[f]-h);let d=p/i;return t.precision(d)}}function vd(t){return(e,r,n)=>{let i=y.from(e).get(0),s=y.from(r).get(0);t.taState||(t.taState={});let a=n||`dmi_${i}_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevTrInitSum:0,prevPlusInitSum:0,prevMinusInitSum:0,prevInitCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,prevDxInitSum:0,prevAdxInitCount:0,prevADX:NaN,currentTrInitSum:0,currentPlusInitSum:0,currentMinusInitSum:0,currentInitCount:0,currentSmoothedTR:NaN,currentSmoothedPlus:NaN,currentSmoothedMinus:NaN,currentDxInitSum:0,currentAdxInitCount:0,currentADX:NaN});let o=t.taState[a];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrInitSum=o.currentTrInitSum,o.prevPlusInitSum=o.currentPlusInitSum,o.prevMinusInitSum=o.currentMinusInitSum,o.prevInitCount=o.currentInitCount,o.prevSmoothedTR=o.currentSmoothedTR,o.prevSmoothedPlus=o.currentSmoothedPlus,o.prevSmoothedMinus=o.currentSmoothedMinus,o.prevDxInitSum=o.currentDxInitSum,o.prevAdxInitCount=o.currentAdxInitCount,o.prevADX=o.currentADX),o.lastIdx=t.idx);let l=t.get(t.data.high,0),c=t.get(t.data.low,0),u=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(u))return[[NaN,NaN,NaN]];let h=t.idx>0?t.get(t.data.high,1):NaN,p=t.idx>0?t.get(t.data.low,1):NaN,d=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(h))return[[NaN,NaN,NaN]];let f=Math.max(l-c,Math.abs(l-d),Math.abs(c-d)),m=l-h,x=p-c,b=m>x&&m>0?m:0,w=x>m&&x>0?x:0,v=o.prevInitCount,E=o.prevTrInitSum,A=o.prevPlusInitSum,C=o.prevMinusInitSum,D=o.prevSmoothedTR,j=o.prevSmoothedPlus,k=o.prevSmoothedMinus;if(v++,v<=i)E+=f,A+=b,C+=w,v===i&&(D=E/i,j=A/i,k=C/i);else{let se=1/i;D=se*f+(1-se)*D,j=se*b+(1-se)*j,k=se*w+(1-se)*k}if(o.currentInitCount=v,o.currentTrInitSum=E,o.currentPlusInitSum=A,o.currentMinusInitSum=C,o.currentSmoothedTR=D,o.currentSmoothedPlus=j,o.currentSmoothedMinus=k,v<i)return[[NaN,NaN,NaN]];let V=D===0?0:100*j/D,T=D===0?0:100*k/D,W=V+T,R=W===0?0:100*Math.abs(V-T)/W,M=o.prevAdxInitCount,H=o.prevDxInitSum,ee=o.prevADX,we=NaN;if(M++,M<=s)H+=R,M===s&&(ee=H/s,we=ee);else{let se=1/s;ee=se*R+(1-se)*ee,we=ee}return o.currentAdxInitCount=M,o.currentDxInitSum=H,o.currentADX=ee,[[t.precision(V),t.precision(T),t.precision(we)]]}}function wd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`ema_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevEma=a.currentEma,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);let o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=a.prevInitCount,c=a.prevInitSum,u=a.prevEma;if(l<i){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===i){let d=c/i;return a.currentEma=d,t.precision(d)}return NaN}let h=2/(i+1),p=o*h+u*(1-h);return a.currentEma=p,t.precision(p)}}function Ed(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);for(let a=0;a<i;a++){let o=s.get(a),l=s.get(a+1);if(isNaN(o)||isNaN(l)||o>=l)return!1}return!0}}function Sd(t){return(e,r,n)=>{typeof r=="string"&&n===void 0&&(n=r,r=e,e=t.data.high);let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`highest_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let p=y.from(e);for(;l.length<i;)l.push(p.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.filter(p=>!isNaN(p)&&p!==void 0);if(u.length===0)return NaN;let h=Math.max(...u);return t.precision(h)}}function Cd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=-1/0,o=NaN;for(let l=0;l<i;l++){let c=s.get(l);isNaN(c)||(isNaN(o)||c>a)&&(a=c,o=-l)}return o}}function Nd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=Math.floor(i/2),a=Math.floor(Math.sqrt(i)),o=t.pine.ta.wma,l=o(e,s,n?`${n}_wma1`:void 0),c=o(e,i,n?`${n}_wma2`:void 0);if(isNaN(l)||isNaN(c))return NaN;t.taState||(t.taState={});let u=n||`hma_raw_${i}`;t.taState[u]||(t.taState[u]={lastIdx:-1,prevValues:[],currentValues:[]});let h=t.taState[u];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.prevValues=[...h.currentValues]),h.lastIdx=t.idx);let p=2*l-c,d=[...h.prevValues];d.unshift(p),d.length>a+1&&d.pop(),h.currentValues=d;let f=n?`${n}_hma_final`:`hma_final_${i}`;t.taState[f]||(t.taState[f]={lastIdx:-1,prevWindow:[],currentWindow:[]});let m=t.taState[f];t.idx>m.lastIdx&&(m.lastIdx>=0&&(m.prevWindow=[...m.currentWindow]),m.lastIdx=t.idx);let x=[...m.prevWindow];if(x.unshift(p),x.length<a)return m.currentWindow=x,NaN;for(;x.length>a;)x.pop();m.currentWindow=x;let b=0,w=0;for(let E=0;E<a;E++){let A=a-E;b+=x[E]*A,w+=A}let v=b/w;return t.precision(v)}}function kd(t){return e=>{let r=t.get(t.data.close,0),n=t.get(t.data.high,0),i=t.get(t.data.low,0),s=t.get(t.data.volume,0);if(isNaN(r)||isNaN(n)||isNaN(i)||isNaN(s))return NaN;let a=(n-i)*s;if(a===0)return t.precision(0);let o=(2*r-n-i)/a;return t.precision(o)}}function Id(t){return(e,r,n,i,s)=>{let a=y.from(r).get(0),o=y.from(n).get(0),l=!0;typeof i=="string"?s=i:i!==void 0&&(l=y.from(i).get(0));let c,u=t.get(t.data.high,0),h=t.get(t.data.low,0);if(l){let E=t.get(t.data.close,1);isNaN(E)?c=NaN:c=Math.max(u-h,Math.abs(u-E),Math.abs(h-E))}else c=u-h;let p=y.from(e).get(0);t.taState||(t.taState={});let d=s||`kc_${a}_${o}_${l}`;t.taState[d]||(t.taState[d]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});let f=t.taState[d];t.idx>f.lastIdx&&(f.lastIdx>=0&&(f.basisState={...f.currentBasisState},f.rangeState={...f.currentRangeState}),f.lastIdx=t.idx);let m=(E,A,C,D)=>{if(isNaN(C))return Object.assign(A,E),A.prevEma!==null?A.prevEma:NaN;let j=E.initCount,k=E.initSum,V=E.prevEma;if(j<D){if(k+=C,j++,A.initSum=k,A.initCount=j,A.prevEma=V,j===D){let R=k/D;return A.prevEma=R,R}return NaN}let T=2/(D+1),W=C*T+V*(1-T);return A.prevEma=W,A.initSum=k,A.initCount=j,W},x=m(f.basisState,f.currentBasisState,p,a),b=m(f.rangeState,f.currentRangeState,c,a);if(isNaN(x)||isNaN(b))return[[NaN,NaN,NaN]];let w=x+b*o,v=x-b*o;return[[t.precision(x),t.precision(w),t.precision(v)]]}}function Ad(t){return(e,r,n,i,s)=>{let a=y.from(r).get(0),o=y.from(n).get(0),l=!0;typeof i=="string"?s=i:i!==void 0&&(l=y.from(i).get(0)),t.taState||(t.taState={});let c=s||`kcw_${a}_${o}_${l}`;t.taState[c]||(t.taState[c]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});let u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.basisState={...u.currentBasisState},u.rangeState={...u.currentRangeState}),u.lastIdx=t.idx);let h=(v,E,A,C)=>{if(isNaN(A))return Object.assign(E,v),E.prevEma!==null?E.prevEma:NaN;let D=v.initCount,j=v.initSum,k=v.prevEma;if(D<C){if(j+=A,D++,E.initSum=j,E.initCount=D,E.prevEma=k,D===C){let W=j/C;return E.prevEma=W,W}return NaN}let V=2/(C+1),T=A*V+k*(1-V);return E.prevEma=T,E.initSum=j,E.initCount=D,T},p,d=t.get(t.data.high,0),f=t.get(t.data.low,0);if(l){let v=t.get(t.data.close,1);isNaN(v)?p=NaN:p=Math.max(d-f,Math.abs(d-v),Math.abs(f-v))}else p=d-f;let m=y.from(e).get(0),x=h(u.basisState,u.currentBasisState,m,a),b=h(u.rangeState,u.currentRangeState,p,a);if(isNaN(x)||isNaN(b))return NaN;if(x===0)return t.precision(0);let w=2*b*o/x;return t.precision(w)}}function Td(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`linreg_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);let c=y.from(e).get(0),u=[...l.prevWindow];for(u.unshift(c);u.length>s;)u.pop();let h=l.prevCallCount+1;if(u.length<s&&(h>=s||t.idx>=s-1)){let E=y.from(e);for(;u.length<s;)u.push(E.get(u.length))}if(l.currentWindow=u,l.currentCallCount=h,u.length<s)return NaN;let p=0,d=0,f=0,m=0,x=s;for(let E=0;E<s;E++){let A=s-1-E,C=u[E];p+=A,d+=C,f+=A*C,m+=A*A}let b=x*m-p*p;if(b===0)return NaN;let w=(x*f-p*d)/b,v=(d-w*p)/x+w*(s-1-a);return t.precision(v)}}function Dd(t){return(e,r,n)=>{typeof r=="string"&&n===void 0&&(n=r,r=e,e=t.data.low);let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`lowest_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let p=y.from(e);for(;l.length<i;)l.push(p.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.filter(p=>!isNaN(p)&&p!==void 0);if(u.length===0)return NaN;let h=Math.min(...u);return t.precision(h)}}function Md(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=1/0,o=NaN;for(let l=0;l<i;l++){let c=s.get(l);isNaN(c)||(isNaN(o)||c<a)&&(a=c,o=-l)}return o}}function Pd(t){return(e,r,n,i,s)=>{let a=y.from(r).get(0),o=y.from(n).get(0),l=y.from(i).get(0),c=s||`macd_${a}_${o}_${l}`,u=`${c}_fast`,h=`${c}_slow`,p=`${c}_signal`,d=t.pine.ta.ema(e,a,u),f=t.pine.ta.ema(e,o,h),m=NaN;!isNaN(d)&&!isNaN(f)&&(m=d-f);let x=NaN;isNaN(m)||(x=t.pine.ta.ema(m,l,p));let b=NaN;return!isNaN(m)&&!isNaN(x)&&(b=m-x),[[t.precision(m),t.precision(x),t.precision(b)]]}}function Rd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`median_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let d=y.from(e);for(;l.length<i;)l.push(d.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.slice().sort((d,f)=>d-f),h=Math.floor(i/2),p=i%2===0?(u[h-1]+u[h])/2:u[h];return t.precision(p)}}function Fd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`mfi_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevUpperWindow=[...a.currentUpperWindow],a.prevLowerWindow=[...a.currentLowerWindow],a.prevUpperSum=a.currentUpperSum,a.prevLowerSum=a.currentLowerSum),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(e).get(1),c=t.get(t.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;let u=isNaN(l)?NaN:o-l,h=c*(u<=0?0:o),p=c*(u>=0?0:o),d=[...a.prevUpperWindow],f=[...a.prevLowerWindow],m=a.prevUpperSum,x=a.prevLowerSum;if(d.unshift(h),f.unshift(p),m+=h,x+=p,d.length<i)return a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=x,NaN;if(d.length>i){let w=d.pop(),v=f.pop();m-=w,x-=v}if(a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=x,x===0)return t.precision(100);if(m===0)return t.precision(0);let b=100-100/(1+m/x);return t.precision(b)}}function Bd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=new Map;for(let c=0;c<i;c++){let u=s.get(c);isNaN(u)||a.set(u,(a.get(u)||0)+1)}if(a.size===0)return NaN;let o=NaN,l=-1;for(let[c,u]of a.entries())u>l?(l=u,o=c):u===l&&c<o&&(o=c);return o}}function Ld(t){return(e,r,n)=>{let i=y.from(r).get(0);return t.pine.ta.change(e,i,n)}}function Od(t){return e=>{t.taState||(t.taState={});let r=e||"nvi";t.taState[r]||(t.taState[r]={lastIdx:-1,committedNVI:1,tentativeNVI:1});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.committedNVI=n.tentativeNVI),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(i)?0:i,c=isNaN(s)?0:s,u=isNaN(a)?0:a,h=isNaN(o)?0:o,p=n.committedNVI;if(!(l===0||c===0)&&u<h){let d=(l-c)/c;p=p+d*p}return n.tentativeNVI=p,t.precision(p)}}function Vd(t){return()=>{t.taState||(t.taState={});let e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});let r=t.taState[e];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedOBV=r.tentativeOBV),r.lastIdx=t.idx);let n=t.get(t.data.close,0),i=t.get(t.data.volume,0),s=t.get(t.data.close,1);if(isNaN(s))return r.tentativeOBV=0,t.precision(0);let a=r.committedOBV;return n>s?a+=i:n<s&&(a-=i),r.tentativeOBV=a,t.precision(a)}}function jd(t){return(e,r,n)=>e instanceof y?r?new y(e.data,e.offset+r):e:(t.params[n]||(t.params[n]=[]),Array.isArray(e)?new y(e,r||0):(t.params[n].length===0?t.params[n].push(e):t.params[n][t.params[n].length-1]=e,new y(t.params[n],r||0)))}function $d(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0),o=y.from(e);if(t.idx<s-1)return NaN;let l=[];for(let f=0;f<s;f++){let m=o.get(f);if(isNaN(m))return NaN;l.push(m)}l.sort((f,m)=>f-m);let c=a/100*s-.5;c<0&&(c=0),c>s-1&&(c=s-1);let u=Math.floor(c),h=Math.ceil(c);if(u===h)return t.precision(l[u]);let p=c-u,d=l[u]+p*(l[h]-l[u]);return t.precision(d)}}function Wd(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0),o=y.from(e);if(t.idx<s-1)return NaN;let l=[];for(let u=0;u<s;u++){let h=o.get(u);isNaN(h)||l.push(h)}if(l.length===0)return NaN;l.sort((u,h)=>u-h);let c=Math.ceil(a/100*l.length)-1;return c<0&&(c=0),c>=l.length&&(c=l.length-1),t.precision(l[c])}}function Ud(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);if(t.idx<i)return NaN;let a=s.get(0);if(isNaN(a))return NaN;let o=0,l=0;for(let c=1;c<=i;c++){let u=s.get(c);isNaN(u)||(l++,u<=a&&o++)}return l===0?NaN:t.precision(o/l*100)}}function qd(t,e,r){let n=new Array(t.length).fill(NaN);for(let i=e+r;i<t.length;i++){let s=t[i-r],a=!0;for(let o=1;o<=e;o++)if(t[i-r-o]>=s){a=!1;break}if(a){for(let o=1;o<=r;o++)if(t[i-r+o]>=s){a=!1;break}}a&&(n[i]=s)}return n}function zd(t){return(e,r,n,i)=>{typeof n=="string"&&(n=r,r=e,e=t.data.high);let s=y.from(r).get(0),a=y.from(n).get(0),o=y.from(e).toArray(),l=qd(o,s,a),c=t.idx;return t.precision(l[c])}}function Kd(t,e,r){let n=new Array(t.length).fill(NaN);for(let i=e+r;i<t.length;i++){let s=t[i-r],a=!0;for(let o=1;o<=e;o++)if(t[i-r-o]<=s){a=!1;break}if(a){for(let o=1;o<=r;o++)if(t[i-r+o]<=s){a=!1;break}}a&&(n[i]=s)}return n}function Hd(t){return(e,r,n,i)=>{typeof n=="string"&&(n=r,r=e,e=t.data.low);let s=y.from(r).get(0),a=y.from(n).get(0),o=y.from(e).toArray(),l=Kd(o,s,a),c=t.idx;return t.precision(l[c])}}function Gd(t){return e=>{t.taState||(t.taState={});let r=e||"pvi";t.taState[r]||(t.taState[r]={lastIdx:-1,committedPVI:1,tentativePVI:1});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.committedPVI=n.tentativePVI),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(i)?0:i,c=isNaN(s)?0:s,u=isNaN(a)?0:a,h=isNaN(o)?0:o,p=n.committedPVI;if(!(l===0||c===0)&&u>h){let d=(l-c)/c;p=p+d*p}return n.tentativePVI=p,t.precision(p)}}function Yd(t){return e=>{t.taState||(t.taState={});let r=e||"pvt";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=n.prevCumulativeSum;if(!isNaN(i)&&!isNaN(s)&&!isNaN(a)&&s!==0){let l=(i-s)/s*a;o+=l}return n.currentCumulativeSum=o,t.precision(o)}}function Zd(t){return(e,r,n)=>{let i=t.pine.ta.highest(e,r,(n||"range")+"_h"),s=t.pine.ta.lowest(e,r,(n||"range")+"_l");return isNaN(i)||isNaN(s)?NaN:t.precision(i-s)}}function Xd(t){return(e,r,n)=>{let i=y.from(r).get(0),s=y.from(e);for(let a=0;a<i;a++){let o=s.get(a),l=s.get(a+1);if(isNaN(o)||isNaN(l)||o<=l)return!1}return!0}}function Qd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`rma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevRma=a.currentRma,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);let o=y.from(e).get(0)||0,l=a.prevInitCount,c=a.prevInitSum,u=a.prevRma;if(l<i){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===i){let d=c/i;return a.currentRma=d,t.precision(d)}return NaN}let h=1/i,p=o*h+u*(1-h);return a.currentRma=p,t.precision(p)}}function Jd(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`roc_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i+1;)l.pop();let c=a.prevCallCount+1;if(l.length<i+1&&(c>=i+1||t.idx>=i)){let p=y.from(e);for(;l.length<i+1;)l.push(p.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=i)return NaN;let u=l[i],h=(o-u)/u*100;return t.precision(h)}}function ef(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`rsi_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevPrevValue=a.currentPrevValue,a.prevAvgGain=a.currentAvgGain,a.prevAvgLoss=a.currentAvgLoss,a.prevInitGains=[...a.currentInitGains],a.prevInitLosses=[...a.currentInitLosses]),a.lastIdx=t.idx);let o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=a.prevPrevValue;if(l===null||isNaN(l))return a.currentPrevValue=o,a.currentInitGains=[...a.prevInitGains],a.currentInitLosses=[...a.prevInitLosses],a.currentAvgGain=a.prevAvgGain,a.currentAvgLoss=a.prevAvgLoss,NaN;let c=a.prevAvgGain,u=a.prevAvgLoss,h=[...a.prevInitGains],p=[...a.prevInitLosses],d=o-l,f=d>0?d:0,m=d<0?-d:0;if(h.length<i){if(h.push(f),p.push(m),a.currentInitGains=h,a.currentInitLosses=p,a.currentPrevValue=o,h.length===i){c=h.reduce((w,v)=>w+v,0)/i,u=p.reduce((w,v)=>w+v,0)/i,a.currentAvgGain=c,a.currentAvgLoss=u;let b=u===0?100:100-100/(1+c/u);return t.precision(b)}return NaN}c=(c*(i-1)+f)/i,u=(u*(i-1)+m)/i,a.currentAvgGain=c,a.currentAvgLoss=u,a.currentPrevValue=o;let x=u===0?100:100-100/(1+c/u);return t.precision(x)}}function tf(t){return(e,r,n,i)=>{let s=y.from(e).get(0),a=y.from(r).get(0),o=y.from(n).get(0);t.taState||(t.taState={});let l=i||`sar_${s}_${a}_${o}`;t.taState[l]||(t.taState[l]={lastIdx:-1,prevResult:NaN,prevMaxMin:NaN,prevAcceleration:NaN,prevIsBelow:!1,prevBarIndex:0,currentResult:NaN,currentMaxMin:NaN,currentAcceleration:NaN,currentIsBelow:!1,currentBarIndex:0});let c=t.taState[l];t.idx>c.lastIdx&&(c.lastIdx>=0&&(c.prevResult=c.currentResult,c.prevMaxMin=c.currentMaxMin,c.prevAcceleration=c.currentAcceleration,c.prevIsBelow=c.currentIsBelow,c.prevBarIndex=c.currentBarIndex),c.lastIdx=t.idx);let u=c.prevResult,h=c.prevMaxMin,p=c.prevAcceleration,d=c.prevIsBelow,f=c.prevBarIndex,m=t.get(t.data.high,0),x=t.get(t.data.low,0),b=t.get(t.data.close,0),w=t.get(t.data.close,1),v=t.get(t.data.high,1),E=t.get(t.data.low,1),A=t.get(t.data.high,2),C=t.get(t.data.low,2);if(isNaN(m)||isNaN(x)||isNaN(b))return c.currentResult=u,c.currentMaxMin=h,c.currentAcceleration=p,c.currentIsBelow=d,c.currentBarIndex=f,NaN;let D=!1;return f===1&&(b>w?(d=!0,h=m,u=E):(d=!1,h=x,u=v),D=!0,p=s),f>=1&&(u=u+p*(h-u),d?u>x&&(D=!0,d=!1,u=Math.max(m,h),h=x,p=s):u<m&&(D=!0,d=!0,u=Math.min(x,h),h=m,p=s),D||(d?m>h&&(h=m,p=Math.min(p+a,o)):x<h&&(h=x,p=Math.min(p+a,o))),d?(u=Math.min(u,E),f>1&&(u=Math.min(u,C))):(u=Math.max(u,v),f>1&&(u=Math.max(u,A)))),f++,c.currentResult=u,c.currentMaxMin=h,c.currentAcceleration=p,c.currentIsBelow=d,c.currentBarIndex=f,f<=1?NaN:t.precision(u)}}function rf(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`sma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1,u=!1;if(l.length<i&&(c>=i||t.idx>=i-1)){let m=y.from(e);for(;l.length<i;)l.push(m.get(l.length));u=!0}let h,p=o==null||Number.isNaN(o),d=!Number.isNaN(a.prevSum)&&!p&&!u;if(d){let m=a.prevSum+o;if(a.prevWindow.length>=i){let x=a.prevWindow[a.prevWindow.length-1];x==null||Number.isNaN(x)?d=!1:m-=x}d&&(h=m)}if(!d){h=0;let m=!1;for(let x of l){if(x==null||Number.isNaN(x)){m=!0;break}h+=x}m&&(h=NaN)}if(a.currentWindow=l,a.currentSum=h,a.currentCallCount=c,l.length<i)return NaN;let f=h/i;return t.precision(f)}}function nf(t){return(e,r,n=!0,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`stdev_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum,l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);let c=y.from(e).get(0);if(c==null||isNaN(c))return NaN;let u=[...l.prevWindow],h=l.prevSum;for(u.unshift(c),h+=c;u.length>s;){let b=u.pop();h-=b}let p=l.prevCallCount+1;if(u.length<s&&(p>=s||t.idx>=s-1)){let b=y.from(e);for(;u.length<s;){let w=b.get(u.length);if(w==null||isNaN(w))break;u.push(w),h+=w}}if(l.currentWindow=u,l.currentSum=h,l.currentCallCount=p,u.length<s)return NaN;let d=h/s,f=0;for(let b=0;b<s;b++)f+=Math.pow(u[b]-d,2);let m=a?s:s-1,x=Math.sqrt(f/m);return t.precision(x)}}function sf(t){return(e,r,n,i,s)=>{let a=y.from(i).get(0);t.taState||(t.taState={});let o=s||`stoch_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow]),l.lastIdx=t.idx);let c=y.from(e).get(0),u=y.from(r).get(0),h=y.from(n).get(0);if(isNaN(c)||isNaN(u)||isNaN(h))return l.currentHighWindow=[...l.prevHighWindow],l.currentLowWindow=[...l.prevLowWindow],NaN;let p=[...l.prevHighWindow],d=[...l.prevLowWindow];if(p.unshift(u),d.unshift(h),p.length>a&&(p.pop(),d.pop()),l.currentHighWindow=p,l.currentLowWindow=d,p.length<a)return NaN;let f=p[0],m=d[0];for(let w=1;w<a;w++)p[w]>f&&(f=p[w]),d[w]<m&&(m=d[w]);let x=f-m;if(x===0)return NaN;let b=100*(c-m)/x;return t.precision(b)}}function af(t){return(e,r,n)=>{let i=y.from(e).get(0),s=y.from(r).get(0);t.taState||(t.taState={});let a=n||`supertrend_${i}_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevTrSum:0,prevAtrValue:NaN,prevAtrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,currentTrSum:0,currentAtrValue:NaN,currentAtrCount:0,currentLowerBand:NaN,currentUpperBand:NaN,currentSuperTrend:NaN,currentDirection:NaN});let o=t.taState[a];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrSum=o.currentTrSum,o.prevAtrValue=o.currentAtrValue,o.prevAtrCount=o.currentAtrCount,o.prevLowerBand=o.currentLowerBand,o.prevUpperBand=o.currentUpperBand,o.prevSuperTrend=o.currentSuperTrend,o.prevDirection=o.currentDirection),o.lastIdx=t.idx);let l=t.get(t.data.high,0),c=t.get(t.data.low,0),u=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(u))return[[NaN,NaN]];let h=(l+c)/2,p=t.idx>0?t.get(t.data.close,1):NaN,d;isNaN(p)?d=l-c:d=Math.max(l-c,Math.abs(l-p),Math.abs(c-p));let f=o.prevAtrCount,m=o.prevTrSum,x=o.prevAtrValue;f++,f<=s?(m+=d,f===s&&(x=m/s)):x=(x*(s-1)+d)/s;let b=x;if(o.currentAtrCount=f,o.currentTrSum=m,o.currentAtrValue=x,isNaN(b))return[[NaN,NaN]];let w=h+i*b,v=h-i*b,E=isNaN(o.prevLowerBand)?0:o.prevLowerBand,A=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||v>E||p<E||(v=E),isNaN(o.prevUpperBand)||w<A||p>A||(w=A);let C,D,j=o.prevSuperTrend;return f===s?C=1:j===o.prevUpperBand?C=u>w?-1:1:C=u<v?1:-1,D=C===-1?v:w,o.currentLowerBand=v,o.currentUpperBand=w,o.currentSuperTrend=D,o.currentDirection=C,[[t.precision(D),C]]}}function of(t){return(e,r)=>{let n=[1,2,2,1],i=6;t.taState||(t.taState={});let s=r||"swma";t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],currentWindow:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>4;)l.pop();if(l.length<4&&t.idx>=3){let u=y.from(e);for(;l.length<4;)l.push(u.get(l.length))}if(a.currentWindow=l,l.length<4)return NaN;let c=0;for(let u=0;u<4;u++)c+=n[u]*l[3-u];return c/=i,t.precision(c)}}function lf(t){return(e,r)=>{let n=!0;typeof e=="string"||e!==void 0&&(n=y.from(e).get(0));let i=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.close,1);if(isNaN(a))return n?t.precision(i-s):NaN;let o=Math.max(i-s,Math.abs(i-a),Math.abs(s-a));return t.precision(o)}}function cf(t){return(e,r,n,i)=>{let s=y.from(r).get(0),a=y.from(n).get(0);t.taState||(t.taState={});let o=i||`tsi_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevSource:NaN,prevEma1PcValue:NaN,prevEma1PcCount:0,prevEma1PcSum:0,prevEma2PcValue:NaN,prevEma2PcCount:0,prevEma2PcSum:0,prevEma1AbsValue:NaN,prevEma1AbsCount:0,prevEma1AbsSum:0,prevEma2AbsValue:NaN,prevEma2AbsCount:0,prevEma2AbsSum:0,currentSource:NaN,currentEma1PcValue:NaN,currentEma1PcCount:0,currentEma1PcSum:0,currentEma2PcValue:NaN,currentEma2PcCount:0,currentEma2PcSum:0,currentEma1AbsValue:NaN,currentEma1AbsCount:0,currentEma1AbsSum:0,currentEma2AbsValue:NaN,currentEma2AbsCount:0,currentEma2AbsSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevSource=l.currentSource,l.prevEma1PcValue=l.currentEma1PcValue,l.prevEma1PcCount=l.currentEma1PcCount,l.prevEma1PcSum=l.currentEma1PcSum,l.prevEma2PcValue=l.currentEma2PcValue,l.prevEma2PcCount=l.currentEma2PcCount,l.prevEma2PcSum=l.currentEma2PcSum,l.prevEma1AbsValue=l.currentEma1AbsValue,l.prevEma1AbsCount=l.currentEma1AbsCount,l.prevEma1AbsSum=l.currentEma1AbsSum,l.prevEma2AbsValue=l.currentEma2AbsValue,l.prevEma2AbsCount=l.currentEma2AbsCount,l.prevEma2AbsSum=l.currentEma2AbsSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return NaN;let u=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(u))return NaN;let h=Math.abs(u),p=2/(a+1),d=2/(s+1),f=2/(a+1),m=2/(s+1),x=l.prevEma1PcCount,b=l.prevEma1PcSum,w=l.prevEma1PcValue;x++,x<=a?(b+=u,x===a&&(w=b/a)):w=u*p+w*(1-p);let v=l.prevEma1AbsCount,E=l.prevEma1AbsSum,A=l.prevEma1AbsValue;if(v++,v<=a?(E+=h,v===a&&(A=E/a)):A=h*f+A*(1-f),isNaN(w)||isNaN(A))return l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=w,l.currentEma1AbsCount=v,l.currentEma1AbsSum=E,l.currentEma1AbsValue=A,NaN;let C=l.prevEma2PcCount,D=l.prevEma2PcSum,j=l.prevEma2PcValue;C++,C<=s?(D+=w,C===s&&(j=D/s)):j=w*d+j*(1-d);let k=l.prevEma2AbsCount,V=l.prevEma2AbsSum,T=l.prevEma2AbsValue;if(k++,k<=s?(V+=A,k===s&&(T=V/s)):T=A*m+T*(1-m),l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=w,l.currentEma1AbsCount=v,l.currentEma1AbsSum=E,l.currentEma1AbsValue=A,l.currentEma2PcCount=C,l.currentEma2PcSum=D,l.currentEma2PcValue=j,l.currentEma2AbsCount=k,l.currentEma2AbsSum=V,l.currentEma2AbsValue=T,isNaN(j)||isNaN(T))return NaN;if(T===0)return t.precision(0);let W=j/T;return t.precision(W)}}function uf(t){return(e,r,n,i)=>{t.taState||(t.taState={});let s=i||"valuewhen";t.taState[s]||(t.taState[s]={lastIdx:-1,prevValues:[],currentValues:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevValues=[...a.currentValues]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(r).get(0),c=y.from(n).get(0),u=[...a.prevValues];if(o&&u.push(l),a.currentValues=u,isNaN(c)||c<0)return NaN;let h=u.length-1-c;if(h<0)return NaN;let p=u[h];return typeof p=="number"?t.precision(p):p}}function pf(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`variance_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let f=y.from(e);for(;l.length<i;)l.push(f.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=0,h=0;for(let f=0;f<i;f++)u+=l[f],h+=l[f]*l[f];let p=u/i,d=h/i-p*p;return t.precision(d)}}function hf(t){return(e,r)=>{t.taState||(t.taState={});let n=r||"vwap";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentLastSessionDate:null});let i=t.taState[n];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevCumulativePV=i.currentCumulativePV,i.prevCumulativeVolume=i.currentCumulativeVolume,i.prevLastSessionDate=i.currentLastSessionDate),i.lastIdx=t.idx);let s=y.from(e).get(0),a=y.from(t.data.volume).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.timezone||"UTC",c=Zt(o,l),u=`${c.year}-${String(c.month).padStart(2,"0")}-${String(c.day).padStart(2,"0")}`,h=i.prevCumulativePV,p=i.prevCumulativeVolume,d=i.prevLastSessionDate;if(d!==u&&(h=0,p=0,d=u),h+=s*a,p+=a,i.currentCumulativePV=h,i.currentCumulativeVolume=p,i.currentLastSessionDate=d,p===0)return NaN;let f=h/p;return t.precision(f)}}function df(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`vwma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevVolumeWindow:[],currentWindow:[],currentVolumeWindow:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevVolumeWindow=[...a.currentVolumeWindow]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=t.get(t.data.volume,0),c=[...a.prevWindow],u=[...a.prevVolumeWindow];for(c.unshift(o),u.unshift(l);c.length>i;)c.pop(),u.pop();if(c.length<i&&t.idx>=i-1){let f=y.from(e),m=y.from(t.data.volume);for(;c.length<i;)c.push(f.get(c.length)),u.push(m.get(u.length))}if(a.currentWindow=c,a.currentVolumeWindow=u,c.length<i)return NaN;let h=0,p=0;for(let f=0;f<i;f++)h+=c[f]*u[f],p+=u[f];let d=h/p;return t.precision(d)}}function ff(t){return e=>{t.taState||(t.taState={});let r=e||"wad";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),o=t.get(t.data.close,1);if(isNaN(i)||isNaN(s)||isNaN(a))return n.currentCumulativeSum=n.prevCumulativeSum,t.precision(n.prevCumulativeSum);let l=0;if(!isNaN(o)){let u=Math.max(s,o),h=Math.min(a,o),p=i-o;p>0?l=i-h:p<0&&(l=i-u)}let c=n.prevCumulativeSum+l;return n.currentCumulativeSum=c,t.precision(c)}}function mf(t){return(e,r,n)=>{let i=y.from(r).get(0);t.taState||(t.taState={});let s=n||`wma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let d=y.from(e);for(;l.length<i;)l.push(d.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=0,h=0;for(let d=0;d<i;d++){let f=i-d;u+=l[d]*f,h+=f}let p=u/h;return t.precision(p)}}function yf(t){return(e,r)=>{let n=y.from(e).get(0);t.taState||(t.taState={});let i=r||`wpr_${n}`;t.taState[i]||(t.taState[i]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});let s=t.taState[i];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevHighWindow=[...s.currentHighWindow],s.prevLowWindow=[...s.currentLowWindow]),s.lastIdx=t.idx);let a=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(l))return s.currentHighWindow=[...s.prevHighWindow],s.currentLowWindow=[...s.prevLowWindow],NaN;let c=[...s.prevHighWindow],u=[...s.prevLowWindow];if(c.unshift(a),u.unshift(o),c.length>n&&(c.pop(),u.pop()),s.currentHighWindow=c,s.currentLowWindow=u,c.length<n)return NaN;let h=c[0],p=u[0];for(let m=1;m<n;m++)c[m]>h&&(h=c[m]),u[m]<p&&(p=u[m]);let d=h-p;if(d===0)return t.precision(0);let f=(h-l)/d*-100;return t.precision(f)}}function gf(t){return e=>{let r=t.get(t.data.close,0),n=t.get(t.data.open,0),i=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(r)||isNaN(n)||isNaN(i)||isNaN(s)||isNaN(a))return NaN;let o=i-s;if(o===0)return t.precision(0);let l=(r-n)/o*a;return t.precision(l)}}var _f=Object.defineProperty,xf=(t,e,r)=>e in t?_f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,F=(t,e,r)=>xf(t,typeof e!="symbol"?e+"":e,r),bf={accdist:sd,alma:ad,atr:od,barssince:ld,bb:cd,bbw:ud,cci:pd,change:hd,cmo:dd,cog:fd,correlation:md,cross:yd,crossover:gd,crossunder:_d,cum:xd,dev:bd,dmi:vd,ema:wd,falling:Ed,highest:Sd,highestbars:Cd,hma:Nd,iii:kd,kc:Id,kcw:Ad,linreg:Td,lowest:Dd,lowestbars:Md,macd:Pd,median:Rd,mfi:Fd,mode:Bd,mom:Ld,nvi:Od,obv:Vd,param:jd,percentile_linear_interpolation:$d,percentile_nearest_rank:Wd,percentrank:Ud,pivothigh:zd,pivotlow:Hd,pvi:Gd,pvt:Yd,range:Zd,rising:Xd,rma:Qd,roc:Jd,rsi:ef,sar:tf,sma:rf,stdev:nf,stoch:sf,supertrend:af,swma:of,tr:lf,tsi:cf,valuewhen:uf,variance:pf,vwap:hf,vwma:df,wad:ff,wma:mf,wpr:yf,wvad:gf},Ci=class{constructor(e){this.context=e,F(this,"accdist"),F(this,"alma"),F(this,"atr"),F(this,"barssince"),F(this,"bb"),F(this,"bbw"),F(this,"cci"),F(this,"change"),F(this,"cmo"),F(this,"cog"),F(this,"correlation"),F(this,"cross"),F(this,"crossover"),F(this,"crossunder"),F(this,"cum"),F(this,"dev"),F(this,"dmi"),F(this,"ema"),F(this,"falling"),F(this,"highest"),F(this,"highestbars"),F(this,"hma"),F(this,"iii"),F(this,"kc"),F(this,"kcw"),F(this,"linreg"),F(this,"lowest"),F(this,"lowestbars"),F(this,"macd"),F(this,"median"),F(this,"mfi"),F(this,"mode"),F(this,"mom"),F(this,"nvi"),F(this,"obv"),F(this,"param"),F(this,"percentile_linear_interpolation"),F(this,"percentile_nearest_rank"),F(this,"percentrank"),F(this,"pivothigh"),F(this,"pivotlow"),F(this,"pvi"),F(this,"pvt"),F(this,"range"),F(this,"rising"),F(this,"rma"),F(this,"roc"),F(this,"rsi"),F(this,"sar"),F(this,"sma"),F(this,"stdev"),F(this,"stoch"),F(this,"supertrend"),F(this,"swma"),F(this,"tr"),F(this,"tsi"),F(this,"valuewhen"),F(this,"variance"),F(this,"vwap"),F(this,"vwma"),F(this,"wad"),F(this,"wma"),F(this,"wpr"),F(this,"wvad"),Object.entries(bf).forEach(([r,n])=>{this[r]=n(e)})}};function vf(t){if(t.length===0)return{};if(typeof t[0]=="object"&&t[0]!==null)return t[0];let e={};typeof t[0]=="string"&&(e.title=t[0]);let r=null;for(let n=1;n<t.length;n++){let i=t[n];typeof i=="string"?e.shorttitle===void 0&&(e.shorttitle=i):typeof i=="object"&&i!==null&&(r=i)}return r&&Object.assign(e,r),e}function Cr(t,e,r){if(!r||r<=0||!Number.isFinite(t)||t===e)return t;let n=t/r,i=1e-9;return t>e?Math.ceil(n-i)*r:Math.floor(n+i)*r}function mn(t,e,r,n){return Math.abs(t)*e*n*r/100}function wf(t,e){let r=t.strategy,n=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of $n(r)){let a=s.dir===1?e-s.entry_price:s.entry_price-e;i+=a*s.qty*n}return r.initial_capital+r.netprofit+i}function Ef(t,e){let r=t.strategy,n=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of r.opentrades){let a=Math.sign(s.size)===1?r.config.margin_long??100:r.config.margin_short??100;i+=mn(s.size,e,a,n)}return i}function ps(t,e,r,n){let i=t.strategy,s=i.config.default_qty_type||"fixed",a=i.config.default_qty_value||1;typeof s=="function"&&(s=s()),typeof a=="function"&&(a=a());let o=1e6,l=u=>Math.floor(u*o)/o;if(e!=null)return l(Math.abs(e));let c;switch(s){case"fixed":c=a;break;case"cash":c=a/n;break;case"percent_of_equity":{c=i.equity*a/100/n;break}default:c=a}return l(c)}function Sf(t){if(!t.strategy)return;let e=t.strategy,{pending_orders:r}=e,n=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.pointvalue??1;for(let c of e.opentrades){let u=Math.abs(c.size),h=c.size>0,p=c.commission??0,d=h?(c.entry_price-s)*u*l:(i-c.entry_price)*u*l,f=h?(i-c.entry_price)*u*l:(c.entry_price-s)*u*l,m=Math.max(0,d)+p,x=Math.max(0,f-p);m>(c.max_drawdown??0)&&(c.max_drawdown=m),x>(c.max_runup??0)&&(c.max_runup=x)}yn(t,n);for(let c of r){if(c.status!=="pending"||(c.category??"entry")==="exit"||c.bar>=t.idx)continue;let u=!1,h=n;switch(c.type){case"market":u=!0,h=n;break;case"limit":if(c.limit!==void 0){let p=Vt(c.direction);(p===1&&s<=c.limit||p===-1&&i>=c.limit)&&(u=!0,h=c.limit)}break;case"stop":if(c.stop!==void 0){let p=Vt(c.direction);(p===1&&i>=c.stop||p===-1&&s<=c.stop)&&(u=!0,h=c.stop)}break}if(u){if(Nf(e,c)){c.status="cancelled";continue}let p=Vt(c.direction);h=Ni(t,p,h);let d=p===1?e.config.margin_long??100:e.config.margin_short??100;{let f=e.position_size,m=Math.sign(f),x=m!==0&&m!==p,b=x?Math.max(0,c.qty-Math.abs(f)):c.qty;if(b>0){let w=t.pine?.syminfo?.pointvalue??1,v=0;m===p&&(v=Ef(t,n));let E=e.equity-v;if(mn(b,h,d,w)>E){let A=Math.min(Math.abs(f),c.qty);x&&A>0?(Yt(t,A,h,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=h,c.fill_bar=t.idx,c.fill_time=o):c.status="cancelled";continue}}}If(t,c,h,o),c.status="filled",c.fill_price=h,c.fill_bar=t.idx,c.fill_time=o}}e.pending_orders=r.filter(c=>c.status==="pending"),yn(t,a),Vf(t)}function Vt(t){return typeof t=="number"?t:t==="long"?1:t==="short"?-1:0}function Xa(t,e,r,n){let i=e.config.commission_type??"percent",s=e.config.commission_value??0;if(!s||s===0)return 0;let a=t.pine?.syminfo?.pointvalue??1;switch(i){case"percent":return Math.abs(r)*n*a*(s/100);case"cash_per_contract":return Math.abs(r)*s;case"cash_per_order":return s;default:return 0}}function Ni(t,e,r){let n=t.strategy.config.slippage??0;if(!n||n===0)return r;let i=t.pine?.syminfo?.mintick??.01,s=n*i;return e===1?r+s:r-s}function Qa(t){let e=Math.abs(t.position_size);e>t.max_contracts_held_all&&(t.max_contracts_held_all=e),t.position_size>t.max_contracts_held_long&&(t.max_contracts_held_long=t.position_size),-t.position_size>t.max_contracts_held_short&&(t.max_contracts_held_short=-t.position_size)}function Cf(t,e){let r=t.config.pyramiding??1,n=0;for(let i of t.opentrades)Math.sign(i.size)===e&&n++;return n>=r}function Nf(t,e){if(t.risk_halted)return!0;let r=t.risk_rules,n=e.direction;if(r.allow_entry_in&&(r.allow_entry_in==="long"&&n===-1||r.allow_entry_in==="short"&&n===1))return!0;if(r.max_position_size!==void 0){let i=t.position_size+n*e.qty;if(Math.abs(i)>r.max_position_size)return!0}return!1}function kf(t){if(t.risk_halted)return;let e=t.risk_rules;if(e.max_drawdown){let r=e.max_drawdown.type==="percent_of_equity"?e.max_drawdown.value/100*t.equity_peak:e.max_drawdown.value;if(t.max_drawdown>=r){t.risk_halted=!0;return}}if(e.max_intraday_loss){let r=e.max_intraday_loss.type==="percent_of_equity"?e.max_intraday_loss.value/100*t.initial_capital:e.max_intraday_loss.value;if(t.grossloss>=r){t.risk_halted=!0;return}}if(e.max_cons_loss_days){let r=0;for(let n=t.closedtrades.length-1;n>=0&&(t.closedtrades[n].profit??0)<0;n--)r++;r>=e.max_cons_loss_days.count&&(t.risk_halted=!0)}}function Gr(t,e,r,n,i,s,a,o){let l=t.strategy,c=l.opentrades.length+l.closedtrades.length,u=l.config.commission_type??"percent",h=o&&u==="cash_per_order",p=Xa(t,l,n,i),d=h?p/2:p,f={id:`trade_${c}`,entry_id:e,entry_comment:a??e,entry_price:i,_bracket_entry:i,entry_bar_index:t.idx,entry_time:s,size:r*n,commission:d,max_drawdown:0,max_runup:0,status:"open"};l.opentrades.push(f),l._first_entry_price===void 0&&(l._first_entry_price=i),(l._ledger_entries??(l._ledger_entries=[])).push({entry_id:e,entry_price:i,entry_time:s,entry_bar_index:t.idx,entry_comment:f.entry_comment,qty:n,commission:d}),d>0&&(l.netprofit-=d,l.grossloss+=d);let m=y.from(t.data.high).get(0),x=y.from(t.data.low).get(0),b=t.pine?.syminfo?.mintick??.01,w=r===1?x:m,v=r===1?m:x;for(let k of l.pending_orders){if((k.category??"entry")!=="exit"||k.from_entry&&k.from_entry!==e)continue;let V;k.stop!==void 0?V=k.stop:k.loss!==void 0&&(V=r===1?i-k.loss*b:i+k.loss*b);let T;k.limit!==void 0?T=k.limit:k.profit!==void 0&&(T=r===1?i+k.profit*b:i-k.profit*b),r===1?(V!==void 0&&V>w&&(w=V),T!==void 0&&T<v&&(v=T)):(V!==void 0&&V<w&&(w=V),T!==void 0&&T>v&&(v=T))}let E=t.pine?.syminfo?.pointvalue??1,A=r===1?(i-w)*n*E:(w-i)*n*E,C=r===1?(v-i)*n*E:(i-v)*n*E;f.max_drawdown=Math.max(0,A)+d,f.max_runup=Math.max(0,C-d);let D=l.position_size,j=D+f.size;if(D===0)l.position_size=j,l.position_avg_price=i,l.position_entry_name=e;else if(Math.sign(D)===Math.sign(j)){let k=Math.abs(D)*l.position_avg_price+n*i,V=Math.abs(j);l.position_avg_price=k/V,l.position_size=j}Qa(l)}function If(t,e,r,n){let i=t.strategy,s=Vt(e.direction),a=i.position_size,o=Math.sign(a);if(o===1&&s===-1||o===-1&&s===1){let l=Math.min(Math.abs(a),e.qty),c=e.qty-l,u=c>0;if(Yt(t,l,r,n,{exitId:e.id,exitComment:e.comment,isImplicitReversal:u}),c>0){let h=e._base_qty;h!==void 0&&c>h+1e-9?(Gr(t,e.id,s,h,r,n,e.comment,!0),Gr(t,e.id,s,c-h,r,n,e.comment,!0)):Gr(t,e.id,s,c,r,n,e.comment,!0)}}else Gr(t,e.id,s,e.qty,r,n,e.comment)}function Af(t,e,r){let n=[],i=r,s=t._ledger_entries??[];for(let a of s){if(i<=1e-9)break;if(a.entry_id!==e.entry_id||a.qty<=1e-9)continue;let o=Math.min(a.qty,i),l=a.qty>0?a.commission*(o/a.qty):0;n.push({qty:o,entry_price:a.entry_price,entry_time:a.entry_time,entry_bar_index:a.entry_bar_index,entry_comment:a.entry_comment,commission:l}),a.qty-=o,a.commission-=l,i-=o}if(t._ledger_entries=s.filter(a=>a.qty>1e-9),i>1e-9){let a=Math.abs(e.size);n.push({qty:i,entry_price:e.entry_price,entry_time:e.entry_time,entry_bar_index:e.entry_bar_index,entry_comment:e.entry_comment,commission:a>0?(e.commission??0)*(i/a):0})}return n}function Yt(t,e,r,n,i){let s=t.strategy,a=t.pine?.syminfo?.pointvalue??1,o=e,l=[...s.opentrades];s.opentrades=[];for(let p of l){if(o<=0){s.opentrades.push(p);continue}let d=Math.abs(p.size),f=Math.min(d,o),m=Math.sign(p.size),x=b=>{let w=s.config.commission_type??"percent",v=i?.isImplicitReversal&&w==="cash_per_order",E=Xa(t,s,b,r),A=v?E/2:E,C=Af(s,p,b);for(let D of C){let j=A*(D.qty/b),k=(m===1?r-D.entry_price:D.entry_price-r)*D.qty*a,V={id:`trade_${s.opentrades.length+s.closedtrades.length+l.length}`,entry_id:p.entry_id,entry_comment:D.entry_comment,entry_price:D.entry_price,_bracket_entry:p._bracket_entry,entry_bar_index:D.entry_bar_index,entry_time:D.entry_time,size:m*D.qty,commission:D.commission+j,max_drawdown:p.max_drawdown,max_runup:p.max_runup,status:"closed",exit_price:r,exit_bar_index:t.idx,exit_time:n,exit_id:i?.exitId??p.exit_id,exit_comment:i?.exitComment??p.exit_comment,profit:k-D.commission-j};i?.triggerKind==="loss"&&(V.max_runup=0),i?.triggerKind==="profit"&&(V.max_drawdown=D.commission),s.netprofit+=k-j,s.grossloss-=D.commission,V.profit>0?(s.grossprofit+=V.profit,s.wintrades++,s.wintrades_total_profit+=V.profit):V.profit<0?(s.grossloss+=Math.abs(V.profit),s.losstrades++,s.losstrades_total_loss+=Math.abs(V.profit)):s.eventrades++,s.closedtrades.push(V)}};if(f>=d-1e-9)p.status="closed",p.exit_price=r,p.exit_bar_index=t.idx,p.exit_time=n,x(d),o-=f;else{x(f);let b=(p.commission??0)*(f/d);p.size=m*(d-f),p.commission=(p.commission??0)-b,s.opentrades.push(p),o=0}}kf(s);let c=s.position_size,u=Math.sign(c)*e,h=c-u;if(Math.abs(h)<1e-9&&(h=0),s.position_size=h,Qa(s),h===0)s.position_avg_price=NaN,s.position_entry_name="";else if(s.opentrades.length>0){let p=0,d=0;for(let f of $n(s))p+=f.qty*f.entry_price,d+=f.qty;s.position_avg_price=p/d,s.position_entry_name=s.opentrades[0].entry_id}}function $n(t){let e=t._ledger_entries??[],r=Math.sign(t.position_size)||1;return e.length>0?e.map(n=>({qty:n.qty,entry_price:n.entry_price,commission:n.commission,dir:r})):t.opentrades.map(n=>({qty:Math.abs(n.size),entry_price:n.entry_price,commission:n.commission??0,dir:Math.sign(n.size)}))}function yn(t,e){let r=t.strategy,n=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of $n(r)){let a=s.dir===1?e-s.entry_price:s.entry_price-e;i+=a*s.qty*n}r.openprofit=i,r.equity=r.initial_capital+r.netprofit+i}function Tf(t,e,r){let n=t.strategy,i=t.pine?.syminfo?.pointvalue??1,s=n.initial_capital+n.netprofit,a=0;for(let f of $n(n))a+=f.commission;let o=s+a;o>n.equity_peak&&(n.equity_peak=o),s<n.equity_trough&&(n.equity_trough=s);let l=n.position_size,c=n.position_avg_price,u=0,h=0;if(l!==0&&Number.isFinite(c)){let f=l>0?r:e,m=l>0?e:r;u=l*(c-f)*i,h=l*(m-c)*i}let p=n.equity_peak-s+u;if(p>n.max_drawdown&&(n.max_drawdown=p,n.equity_at_drawdown_peak=n.equity_peak,n.equity_peak>0)){let f=100*p/n.equity_peak;f>n.max_drawdown_percent_value&&(n.max_drawdown_percent_value=f)}let d=s-n.equity_trough+h;if(d>n.max_runup&&(n.max_runup=d,n.equity_at_runup_peak=s+h,n.equity_at_runup_peak>0)){let f=100*d/n.equity_at_runup_peak;f>n.max_runup_percent_value&&(n.max_runup_percent_value=f)}}function Ys(t,e,r,n,i,s,a){let o=t.strategy;if(a!==void 0){let p=[],d=[];for(let m of o.opentrades)m.id===a?p.push(m):d.push(m);if(p.length===0)return;let f=Math.abs(p[0].size);o.opentrades=[...p,...d],Yt(t,Math.min(r,f),n,i,s);return}if(!e||e===""){Yt(t,r,n,i,s);return}let l=[],c=[];for(let p of o.opentrades)p.entry_id===e?l.push(p):c.push(p);let u=l.reduce((p,d)=>p+Math.abs(d.size),0);if(u===0)return;let h=Math.min(r,u);o.opentrades=[...l,...c],Yt(t,h,n,i,s)}function Df(t,e="intrabar"){if(!t.strategy)return;let r=t.strategy;if(r.pending_orders.length===0)return;let n=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.mintick??.01;for(let c of r.pending_orders){if(c.status!=="pending"||(c.category??"entry")!=="exit")continue;let u=r.opentrades.filter(T=>!c.from_entry||T.entry_id===c.from_entry);if(c._intended_trade_ids){let T=new Set(c._intended_trade_ids);u=u.filter(W=>T.has(W.id))}if(u.length===0){e==="intrabar"&&(c.status="cancelled");continue}let h=u.reduce((T,W)=>T+Math.abs(W.size),0),p=Math.sign(u[0].size);if(c.type==="market"&&c.profit===void 0&&c.loss===void 0&&c.limit===void 0&&c.stop===void 0&&c.trail_price===void 0&&c.trail_points===void 0){if(e==="open"||c.bar>=t.idx)continue;let T=c.immediately?a:n;T=Ni(t,-p,T);let W=h;c.qty&&c.qty>0?W=Math.min(c.qty,h):c.qty_percent&&c.qty_percent>0&&(W=h*(c.qty_percent/100)),Ys(t,c.from_entry,W,T,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=T,c.fill_bar=t.idx,c.fill_time=o;continue}let d=0;for(let T of u)d+=Math.abs(T.size)*T.entry_price;let f=d/h,m=p===1,x=c.limit,b=c.stop;c._isPersistent||(b!==void 0&&((m?b<f:b>f)||(b=void 0)),x!==void 0&&((m?x>f:x<f)||(x=void 0))),c._attachedAtReversal&&!c._isPersistent&&(c.limit!==void 0&&(x=void 0),c.stop!==void 0&&(b=void 0));let w=!1;if(e==="intrabar"&&!c.trail_armed&&(c.trail_price!==void 0||c.trail_points!==void 0)){let T;c.trail_price!==void 0?T=c.trail_price:c.trail_points!==void 0&&(T=m?f+c.trail_points*l:f-c.trail_points*l),T!==void 0&&(m?i>=T:s<=T)&&(c.trail_armed=!0,c.trail_peak=m?i:s,w=!0)}let v=Math.abs(i-n)<=Math.abs(n-s),E=m?v:!v,A=[],C=[],D=r._mc_exit_lock,j=D&&D.bar===t.idx;for(let T of u){if(j&&T.id!==D.tradeId)continue;let W=T._bracket_entry??T.entry_price,R=Math.abs(T.size),M=x;M===void 0&&c.profit!==void 0&&(M=m?W+c.profit*l:W-c.profit*l);let H=b;H===void 0&&c.loss!==void 0&&(H=m?W-c.loss*l:W+c.loss*l);let ee=M!==void 0&&(e==="open"?m?n>=M:n<=M:m?i>=M:s<=M),we=H!==void 0&&(e==="open"?m?n<=H:n>=H:m?s<=H:i>=H),se=null;if(ee&&we?se=E?"profit":"loss":ee?se="profit":we&&(se="loss"),se==="loss"){let Fe=m?n<=H:n>=H;!m&&Fe&&T.entry_bar_index===t.idx?ee&&(se="profit"):C.push({qty:R,price:Fe?n:H,kind:"loss",tradeId:T.id})}if(se==="profit"){let Fe=m?n>=M:n<=M;A.push({qty:R,price:Fe?n:M,kind:"profit",tradeId:T.id})}}A.sort((T,W)=>m?T.price-W.price:W.price-T.price),C.sort((T,W)=>m?W.price-T.price:T.price-W.price);let k=null;if(e==="intrabar"&&!j&&c.trail_armed&&c.trail_offset!==void 0){let T=()=>{m?c.trail_peak=Math.max(c.trail_peak??-1/0,i):c.trail_peak=Math.min(c.trail_peak??1/0,s)},W=()=>m?c.trail_peak-c.trail_offset*l:c.trail_peak+c.trail_offset*l,R=M=>{k={qty:1/0,price:M,kind:"trailing"}};if(w){let M=W();E?(m?s<=M:i>=M)&&R(M):(m?a<=M:a>=M)&&R(M)}else if(E){T();let M=W();(m?s<=M:i>=M)&&R(M)}else{let M=W();if(m?s<=M:i>=M)R(M);else{T();let H=W();(m?a<=H:a>=H)&&R(H)}}}let V=E?[...A,...C,...k?[k]:[]]:[...C,...k?[k]:[],...A];if(V.length>0){let T=h;c.qty&&c.qty>0?T=Math.min(c.qty,h):c.qty_percent&&c.qty_percent>0&&(T=h*(c.qty_percent/100));let W=()=>r.opentrades.filter(H=>!c.from_entry||H.entry_id===c.from_entry).reduce((H,ee)=>H+Math.abs(ee.size),0),R=NaN,M=!1;for(let H of V){if(T<=1e-9)break;let ee=W();if(ee<=1e-9)break;let we=Math.min(H.qty===1/0?ee:H.qty,T,ee),se=Ni(t,-p,H.price),Fe=H.kind==="profit"?c.comment_profit??c.comment:H.kind==="loss"?c.comment_loss??c.comment:c.comment_trailing??c.comment;Ys(t,c.from_entry,we,se,o,{triggerKind:H.kind,exitId:c.id,exitComment:Fe},H.tradeId),T-=we,R=se,M=!0}M&&(W()<=1e-9||T<=1e-9)&&(c.status="filled",c.fill_price=R,c.fill_bar=t.idx,c.fill_time=o)}}r.pending_orders=r.pending_orders.filter(c=>c.status==="pending"),yn(t,a)}function Mf(t){let e=t.strategy;if(!e)return;let r=e._pending_close_mc;if(r&&(e._pending_close_mc=null,!(e.opentrades.length===0||Math.sign(e.position_size)!==r.dir)&&(Yt(t,Math.min(r.qty,Math.abs(e.position_size)),r.price,r.time,{exitId:"Margin call",exitComment:"Margin call"}),Math.abs(e.position_size)>1e-9))){for(let n of e.pending_orders)n.status==="pending"&&(n.category??"entry")==="entry"&&!n._isReversalEntry&&Vt(n.direction)===r.dir&&(n.status="cancelled");e.pending_orders=e.pending_orders.filter(n=>n.status==="pending")}}function Pf(t){let e=t.strategy,r=Math.sign(e?.position_size??0);if(r===0)return!1;let n=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=Math.abs(i-n)<=Math.abs(n-s);return r===1?!a:a}function ri(t,e="extreme"){let r=t.strategy;if(!r||r.opentrades.length===0)return;let n=Math.sign(r.position_size);if(n===0)return;let i=n===1?r.config.margin_long??100:r.config.margin_short??100,s=y.from(t.data.open).get(0),a=y.from(t.data.high).get(0),o=y.from(t.data.low).get(0),l=y.from(t.data.close).get(0),c=y.from(t.data.openTime).get(0),u=t.pine?.syminfo?.pointvalue??1,h=e==="open"?s:e==="close"?l:n===1?o:a,p=Math.abs(r.position_size),d=wf(t,h),f=mn(p,h,i,u);if(d<f){let m=f-d,x=i/100,b=m/(h*u*x),w=Math.min(p,4*b),v=[...r.opentrades],E=v[0],A=Math.abs(E.size),C=E.entry_price;if(Yt(t,w,h,c,{exitId:"Margin call",exitComment:"Margin call"}),e==="extreme"&&w>=A-1e-9&&Math.abs(r.position_size)>1e-9){let j=mn(A,h,i,u),k=A*(h-C)*n*u,V=m-j+k;if(V>0){let T=y.from(t.data.close).get(0),W=(M=>Math.trunc(M*1e6)/1e6)(V/(h*u*x)),R=Math.min(Math.abs(r.position_size),4*W);R>1e-9&&(r._pending_close_mc={qty:R,price:T,time:c,dir:n})}}let D=v.find(j=>j.status==="open");r._mc_exit_lock={bar:t.idx,tradeId:D?.id??null}}}function Rf(t){if(!t.strategy)return;let e=t.strategy,r=y.from(t.data.high).get(0),n=y.from(t.data.low).get(0),i=y.from(t.data.close).get(0);yn(t,i),Tf(t,r,n);let s=y.from(t.data.openTime).get(0);if(Number.isFinite(s)){let a=new Date(s),o=a.getUTCFullYear()*12+a.getUTCMonth(),l=e._monthly_equity??(e._monthly_equity=[]);e._last_month_key===o&&l.length>0?l[l.length-1]=e.equity:(l.push(e.equity),e._last_month_key=o)}}function Ff(t){let e=t?.strategy;if(!e)return;e.cagr=Lf(t),Of(t);let r=e._monthly_equity??[],n=[e.initial_capital,...r],i=[];for(let d=1;d<n.length;d++){let f=n[d-1];f!==0&&Number.isFinite(f)&&Number.isFinite(n[d])&&i.push(n[d]/f-1)}if(i.length<2){e.sharpe_ratio=0,e.sortino_ratio=0;return}let s=(e.config.risk_free_rate??2)/100/12,a=i.length,o=i.reduce((d,f)=>d+f,0)/a,l=o-s,c=i.reduce((d,f)=>d+(f-o)**2,0)/a,u=Math.sqrt(c),h=i.reduce((d,f)=>d+Math.min(0,f-s)**2,0)/a,p=Math.sqrt(h);e.sharpe_ratio=u>0?l/u:0,e.sortino_ratio=p>0?l/p:0}var Bf=1440*60*1e3;function Lf(t){let e=t?.strategy;if(!e)return NaN;let r=t?.marketData;if(!Array.isArray(r)||r.length===0)return NaN;let n=r[0]?.openTime,i=r[r.length-1]?.openTime;if(!Number.isFinite(n)||!Number.isFinite(i))return NaN;let s=e.initial_capital??0,a=s+(e.netprofit??0),o=(i-n)/Bf;if(o<1||!Number.isFinite(s)||!Number.isFinite(a)||s===0)return NaN;let l=o/365;return 100*(Math.pow(a/s,1/l)-1)}function Of(t){let e=t?.strategy;if(!e)return;let r=e._first_entry_price,n=t?.marketData,i=Array.isArray(n)&&n.length>0?n[n.length-1]?.close:NaN;if(!Number.isFinite(r)||!Number.isFinite(i)||r===0){e.buy_and_hold_pnl=NaN,e.buy_and_hold_per_gain=NaN,e.strategy_outperformance=NaN;return}let s=r,a=(i-s)/s;e.buy_and_hold_per_gain=a*100,e.buy_and_hold_pnl=(e.initial_capital??0)*a,e.strategy_outperformance=(e.netprofit??0)-e.buy_and_hold_pnl}function Vf(t){t.strategy}function jf(t,e){let r={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"right",pyramiding:1,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:"fixed",default_qty_value:1,initial_capital:1e6,currency:"USD",slippage:0,commission_type:"percent",commission_value:0,margin_long:100,margin_short:100,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,max_polylines_count:50,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,...e,...t._propOverrides??{}},n=r.initial_capital;t.strategy={config:r,opentrades:[],closedtrades:[],pending_orders:[],position_size:0,position_avg_price:NaN,position_entry_name:"",initial_capital:n,account_currency:r.currency||"USD",equity:n,netprofit:0,grossprofit:0,grossloss:0,openprofit:0,max_drawdown:0,max_runup:0,equity_peak:n,equity_trough:n,equity_at_runup_peak:n,equity_at_drawdown_peak:n,max_drawdown_percent_value:0,max_runup_percent_value:0,sharpe_ratio:0,sortino_ratio:0,cagr:NaN,buy_and_hold_pnl:NaN,buy_and_hold_per_gain:NaN,strategy_outperformance:NaN,_first_entry_price:void 0,_monthly_equity:[],_last_month_key:-1,wintrades:0,losstrades:0,eventrades:0,wintrades_total_profit:0,losstrades_total_loss:0,max_contracts_held_all:0,max_contracts_held_long:0,max_contracts_held_short:0,risk_rules:{},risk_halted:!1,_exit_call_history:new Map,_exit_fallback_counter:0,_exit_fallback_last_bar:-1}}function Nr(t){if(Array.isArray(t))return t.map(Nr);if(t instanceof Map){let e=new Map;return t.forEach((r,n)=>e.set(n,Nr(r))),e}if(t!==null&&typeof t=="object"){let e={};for(let r of Object.keys(t))e[r]=Nr(t[r]);return e}return t}function $f(t){if(!t)return null;let e={};for(let r of Object.keys(t))r==="config"||r==="closedtrades"||(e[r]=Nr(t[r]));return{fields:e,closedtradesLength:t.closedtrades.length}}function Wf(t,e){if(!(!t||!e)){for(let r of Object.keys(t))r==="config"||r==="closedtrades"||Object.prototype.hasOwnProperty.call(e.fields,r)||delete t[r];t.closedtrades.length>e.closedtradesLength&&(t.closedtrades.length=e.closedtradesLength);for(let r of Object.keys(e.fields))t[r]=Nr(e.fields[r])}}function Uf(t){return(...e)=>{let r=vf(e);return t.strategy?t.strategy.config={...t.strategy.config,...r,...t._propOverrides??{}}:jf(t,r),t.strategy.config}}var qf=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],zf={id:"string",direction:"series",qty:"series",limit:"series",stop:"series",oca_name:"string",oca_type:"string",comment:"string",alert_message:"string",disable_alert:"boolean"};function Kf(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.order() called before strategy() declaration");let r=le(e,qf,zf),n=w=>w==null||typeof w=="string"||typeof w=="number"||typeof w=="boolean"?w:typeof w=="function"?w():w instanceof y?w.get(0):Array.isArray(w)?w[w.length-1]:typeof w=="object"&&w.get!==void 0?w.get(0):w,i=n(r.id),s=n(r.direction),a=n(r.qty),o=n(r.limit),l=n(r.stop),c=n(r.oca_name),u=n(r.oca_type),h=n(r.comment),p=Vt(s),d=y.from(t.data.close).get(0),f=ps(t,a,p,d),m="market";o!==void 0&&l!==void 0?m="stop-limit":o!==void 0?m="limit":l!==void 0&&(m="stop");let x=y.from(t.data.openTime).get(0),b={id:i,direction:p,qty:f,type:m,limit:o,stop:l,bar:t.idx,time:x,status:"pending",oca_name:c,oca_type:u,comment:h};return t.strategy.pending_orders.push(b),b}}function Hf(t){return(e,r)=>y.from(e).get(r||0)}function Gf(t){return()=>{let e=(t.strategy?.opentrades??[]).slice(),r=p=>e[Number(p)],n=()=>{let p=t.marketData;return Array.isArray(p)&&t.idx>=0&&t.idx<p.length?p[t.idx]?.close??NaN:NaN},i={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},s=t.pine?.syminfo?.pointvalue??1,a=(p,d)=>{let f=t.strategy?.config,m=f?.commission_type??"percent",x=f?.commission_value??0;if(!x)return 0;let b=Math.abs(p.size);switch(m){case"percent":return b*d*s*(x/100);case"cash_per_contract":return b*x;case"cash_per_order":return x;default:return 0}},o=p=>Math.abs(p.size)*p.entry_price*s+(p.commission??0);i.profit=p=>{let d=r(p);if(!d)return NaN;let f=n();return Number.isFinite(f)?(Math.sign(d.size)===1?f-d.entry_price:d.entry_price-f)*Math.abs(d.size)*s-(d.commission??0)-a(d,f):NaN},i.profit_percent=p=>{let d=r(p);if(!d)return NaN;let f=i.profit(p);if(!Number.isFinite(f))return NaN;let m=o(d);return m>0?100*f/m:NaN},i.size=p=>r(p)?.size??NaN,i.commission=p=>r(p)?.commission??NaN,i.entry_price=p=>r(p)?.entry_price??NaN,i.entry_bar_index=p=>r(p)?.entry_bar_index??NaN,i.entry_id=p=>r(p)?.entry_id??"",i.entry_comment=p=>r(p)?.entry_comment??r(p)?.entry_id??"",i.entry_time=p=>r(p)?.entry_time??NaN,i.max_drawdown=p=>r(p)?.max_drawdown??0,i.max_drawdown_percent=p=>{let d=r(p);if(!d||!d.max_drawdown)return 0;let f=o(d);return f>0?100*d.max_drawdown/f:0},i.max_runup=p=>r(p)?.max_runup??0,i.max_runup_percent=p=>{let d=r(p);if(!d||!d.max_runup)return 0;let f=o(d);return f>0?100*d.max_runup/f:0};let l=t.strategy,c=l?.config?.margin_long??100,u=l?.config?.margin_short??100,h=c!==100||u!==100;if(!l||l.opentrades.length===0||!h)i.capital_held=NaN;else{let p=0;for(let d of l.opentrades){let f=Math.abs(d.size)*d.entry_price,m=d.size>0?c:u;p+=f*(m/100)}i.capital_held=p}return i}}function Yf(t){return()=>{let e=(t.strategy?.closedtrades??[]).slice(),r=a=>e[Number(a)],n={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},i=t.pine?.syminfo?.pointvalue??1,s=a=>{let o=Math.abs(a.size)*a.entry_price*i,l=(a.commission??0)/2;return o+l};return n.profit=a=>r(a)?.profit??NaN,n.profit_percent=a=>{let o=r(a);if(!o||o.profit===void 0)return NaN;let l=s(o);return l>0?100*o.profit/l:NaN},n.size=a=>r(a)?.size??NaN,n.commission=a=>r(a)?.commission??NaN,n.entry_price=a=>r(a)?.entry_price??NaN,n.entry_bar_index=a=>r(a)?.entry_bar_index??NaN,n.entry_id=a=>r(a)?.entry_id??"",n.entry_comment=a=>r(a)?.entry_comment??r(a)?.entry_id??"",n.entry_time=a=>r(a)?.entry_time??NaN,n.exit_price=a=>r(a)?.exit_price??NaN,n.exit_bar_index=a=>r(a)?.exit_bar_index??NaN,n.exit_id=a=>r(a)?.exit_id??"",n.exit_comment=a=>r(a)?.exit_comment??r(a)?.exit_id??"",n.exit_time=a=>r(a)?.exit_time??NaN,n.max_drawdown=a=>r(a)?.max_drawdown??0,n.max_drawdown_percent=a=>{let o=r(a);if(!o||!o.max_drawdown)return 0;let l=s(o);return l>0?100*o.max_drawdown/l:0},n.max_runup=a=>r(a)?.max_runup??0,n.max_runup_percent=a=>{let o=r(a);if(!o||!o.max_runup)return 0;let l=s(o);return l>0?100*o.max_runup/l:0},n.first_index=0,n}}function Zf(t){return()=>t.strategy?.netprofit??0}function Xf(t){return()=>t.strategy?.position_size??0}function Qf(t){return()=>{let e=t.strategy;return!e||e.position_size===0?NaN:e.position_avg_price}}function Jf(t){return()=>t.strategy?.equity??t.strategy?.config?.initial_capital??1e4}function em(t){return()=>"long"}function tm(t){return()=>"short"}function rm(t){return()=>"cash"}function nm(t){return()=>"percent_of_equity"}function im(t){return()=>"fixed"}function sm(t){return()=>t.strategy?.openprofit??0}function am(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.openprofit/e.initial_capital}}function om(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.netprofit/e.initial_capital}}function lm(t){return()=>t.strategy?.grossprofit??0}function cm(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossprofit/e.initial_capital}}function um(t){return()=>t.strategy?.grossloss??0}function pm(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossloss/e.initial_capital}}function hm(t){return()=>t.strategy?.wintrades??0}function dm(t){return()=>t.strategy?.losstrades??0}function fm(t){return()=>t.strategy?.eventrades??0}function mm(t){return()=>{let e=t.strategy;return!e||!e.closedtrades||e.closedtrades.length===0?NaN:e.netprofit/e.closedtrades.length}}function ym(t){return()=>{let e=t.strategy;if(!e||!e.closedtrades||e.closedtrades.length===0)return NaN;let r=0;for(let n of e.closedtrades){let i=Math.abs(n.size)*n.entry_price;i>0&&(r+=100*(n.profit??0)/i)}return r/e.closedtrades.length}}function gm(t){return()=>{let e=t.strategy;return!e||e.wintrades===0?NaN:e.wintrades_total_profit/e.wintrades}}function _m(t){return()=>{let e=t.strategy;if(!e||e.wintrades===0)return NaN;let r=0;for(let n of e.closedtrades)if((n.profit??0)>0){let i=Math.abs(n.size)*n.entry_price;i>0&&(r+=100*(n.profit??0)/i)}return r/e.wintrades}}function xm(t){return()=>{let e=t.strategy;return!e||e.losstrades===0?NaN:e.losstrades_total_loss/e.losstrades}}function bm(t){return()=>{let e=t.strategy;if(!e||e.losstrades===0)return NaN;let r=0;for(let n of e.closedtrades)if((n.profit??0)<0){let i=Math.abs(n.size)*n.entry_price;i>0&&(r+=100*(n.profit??0)/i)}return r/e.losstrades}}function vm(t){return()=>t.strategy?.max_drawdown??0}function wm(t){return()=>{let e=t.strategy;return e?e.max_drawdown_percent_value??0:0}}function Em(t){return()=>t.strategy?.max_runup??0}function Sm(t){return()=>{let e=t.strategy;return e?e.max_runup_percent_value??0:0}}function Cm(t){return()=>t.strategy?.max_contracts_held_all??0}function Nm(t){return()=>t.strategy?.max_contracts_held_long??0}function km(t){return()=>t.strategy?.max_contracts_held_short??0}function Im(t){return()=>t.strategy?.position_entry_name??""}function Am(t){return()=>t.strategy?.initial_capital??0}function Tm(t){return()=>t.strategy?.account_currency??"USD"}function Dm(t){return()=>{let e=t.strategy;if(!e||e.position_size===0)return NaN;let r=e.position_avg_price;if(!Number.isFinite(r))return NaN;let n=Math.sign(e.position_size),i=n===1?e.config.margin_long??100:e.config.margin_short??100;if(i>=100)return NaN;let s=Math.abs(e.position_size),a=t.pine?.syminfo?.pointvalue??1,o=((e.initial_capital??0)+(e.netprofit??0))/(a*s)-n*r,l=i/100-n,c=o/l,u=t.pine?.syminfo?.mintick??.01;return n===1?Math.floor(c/u)*u:Math.ceil(c/u)*u}}var Mm=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],Pm={id:"string",direction:"series",qty:"series",limit:"series",stop:"series",oca_name:"string",oca_type:"string",comment:"string",alert_message:"string",disable_alert:"boolean"};function Rm(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.entry() called before strategy() declaration");let r=le(e,Mm,Pm),n=k=>k==null||typeof k=="string"||typeof k=="number"||typeof k=="boolean"?k:typeof k=="function"?k():k instanceof y?k.get(0):Array.isArray(k)?k[k.length-1]:typeof k=="object"&&k.get!==void 0?k.get(0):k,i=n(r.id),s=n(r.direction),a=n(r.qty),o=n(r.limit),l=n(r.stop),c=n(r.oca_name),u=n(r.oca_type),h=n(r.comment),p=Vt(s),d=t.strategy,f=d.position_size;for(let k of d.pending_orders)k.bar===t.idx&&k.category==="entry"&&k.type==="market"&&(f+=Vt(k.direction)*k.qty);if(Math.sign(f)===p&&f!==0&&Cf(d,p))return;let m=y.from(t.data.close).get(0),x=ps(t,a,p,m),b=f!==0&&Math.sign(f)!==p,w=b?Math.abs(f)+x:x,v="market";o!==void 0&&l!==void 0?v="stop-limit":o!==void 0?v="limit":l!==void 0&&(v="stop");let E=t.pine?.syminfo?.mintick??0,A=o!==void 0?Cr(o,m,E):void 0,C=l!==void 0?Cr(l,m,E):void 0,D=y.from(t.data.openTime).get(0),j={id:i,direction:p,qty:w,type:v,limit:A,stop:C,bar:t.idx,time:D,status:"pending",category:"entry",oca_name:c,oca_type:u,comment:h,_isReversalEntry:b,_base_qty:x};d.pending_orders.push(j)}}var Fm=[["id","from_entry","qty","qty_percent","profit","limit","loss","stop","trail_price","trail_points","trail_offset","oca_name","comment","comment_profit","comment_loss","comment_trailing","alert_message","alert_profit","alert_loss","alert_trailing","disable_alert"]],Bm={id:"string",from_entry:"string",qty:"series",qty_percent:"series",profit:"series",limit:"series",loss:"series",stop:"series",trail_price:"series",trail_points:"series",trail_offset:"series",oca_name:"string",comment:"string",comment_profit:"string",comment_loss:"string",comment_trailing:"string",alert_message:"string",alert_profit:"string",alert_loss:"string",alert_trailing:"string",disable_alert:"boolean"};function Lm(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.exit() called before strategy() declaration");let r=ht(e);if(r===void 0){let R=t.strategy;R._exit_fallback_last_bar!==t.idx&&(R._exit_fallback_counter=0,R._exit_fallback_last_bar=t.idx),r=`exit_raw_${R._exit_fallback_counter++}`}let n=le(e,Fm,Bm),i=R=>R==null||typeof R=="string"||typeof R=="number"||typeof R=="boolean"?R:typeof R=="function"?R():R instanceof y?R.get(0):Array.isArray(R)?R[R.length-1]:typeof R=="object"&&R.get!==void 0?R.get(0):R,s=i(n.id),a=i(n.from_entry),o=i(n.qty),l=i(n.qty_percent),c=i(n.profit),u=i(n.limit),h=i(n.loss),p=i(n.stop),d=i(n.trail_price),f=i(n.trail_points),m=i(n.trail_offset),x=t.pine?.syminfo?.mintick??0,b=y.from(t.data.close).get(0),w=u!==void 0?Cr(u,b,x):void 0,v=p!==void 0?Cr(p,b,x):void 0,E=d!==void 0?Cr(d,b,x):void 0,A=a??"",C=!!(A?t.strategy.pending_orders.find(R=>R.category==="entry"&&R.id===A&&R.status==="pending"):t.strategy.pending_orders.find(R=>R.category==="entry"&&R.status==="pending"))?._isReversalEntry,D=t.strategy._exit_call_history,j=D.get(r),k=j!==void 0&&j===t.idx-1;D.set(r,t.idx);let V={id:s??"exit",direction:0,qty:o!==void 0?Math.abs(Number(o)):0,qty_percent:l,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:A,profit:c,loss:h,limit:w,stop:v,trail_price:E,trail_points:f,trail_offset:m,oca_name:i(n.oca_name),comment:i(n.comment),comment_profit:i(n.comment_profit),comment_loss:i(n.comment_loss),comment_trailing:i(n.comment_trailing),alert_message:i(n.alert_message),alert_profit:i(n.alert_profit),alert_loss:i(n.alert_loss),alert_trailing:i(n.alert_trailing),disable_alert:i(n.disable_alert),trail_armed:!1,trail_peak:NaN,_attachedAtReversal:C,_isPersistent:k,_callsiteId:r},T=V.id,W=t.strategy.pending_orders;for(let R=W.length-1;R>=0;R--){let M=W[R];M.category==="exit"&&M.id===T&&(M.from_entry??"")===(V.from_entry??"")&&M.status==="pending"&&(M.trail_armed&&(V.trail_armed=!0,V.trail_peak=M.trail_peak),W.splice(R,1))}W.push(V)}}var Om=[["id","comment","qty","qty_percent","alert_message","immediately","disable_alert"]],Vm={id:"string",comment:"string",qty:"series",qty_percent:"series",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function jm(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close() called before strategy() declaration");let r=le(e,Om,Vm),n=r.id;if(n==null||!t.strategy.opentrades.some(o=>o.entry_id===n))return;let i=o=>(o.category??"entry")==="exit"&&(o.profit!==void 0||o.loss!==void 0||o.limit!==void 0||o.stop!==void 0||o.trail_price!==void 0||o.trail_points!==void 0),s=t.strategy.pending_orders;for(let o of s)i(o)&&(o.from_entry??"")===n&&o.status==="pending"&&(o.status="cancelled");t.strategy.pending_orders=s.filter(o=>o.status==="pending");let a={id:`close_${n}`,direction:0,qty:0,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:n,qty_percent:r.qty_percent,comment:r.comment,alert_message:r.alert_message,immediately:r.immediately===!0,disable_alert:r.disable_alert,_intended_trade_ids:t.strategy.opentrades.filter(o=>o.entry_id===n).map(o=>o.id)};r.qty!==void 0&&(a.qty=Math.abs(Number(r.qty))),t.strategy.pending_orders.push(a)}}var $m=[["comment","alert_message","immediately","disable_alert"]],Wm={comment:"string",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function Um(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close_all() called before strategy() declaration");let r=le(e,$m,Wm);if(t.strategy.opentrades.length===0)return;let n=a=>(a.category??"entry")==="exit"&&(a.profit!==void 0||a.loss!==void 0||a.limit!==void 0||a.stop!==void 0||a.trail_price!==void 0||a.trail_points!==void 0),i=t.strategy.pending_orders;for(let a of i)n(a)&&a.status==="pending"&&(a.status="cancelled");t.strategy.pending_orders=i.filter(a=>a.status==="pending");let s={id:"close_all",direction:0,qty:0,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:"",comment:r.comment,alert_message:r.alert_message,immediately:r.immediately===!0,disable_alert:r.disable_alert,_intended_trade_ids:t.strategy.opentrades.map(a=>a.id)};t.strategy.pending_orders.push(s)}}var qm=[["id","immediately"]],zm={id:"string",immediately:"boolean"};function Km(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.cancel() called before strategy() declaration");let r=le(e,qm,zm).id;r!=null&&(t.strategy.pending_orders=t.strategy.pending_orders.filter(n=>!(n.status==="pending"&&n.id===r)))}}function Hm(t){return()=>{if(!t.strategy)throw new Error("strategy.cancel_all() called before strategy() declaration");t.strategy.pending_orders=t.strategy.pending_orders.filter(e=>!(e.status==="pending"&&(e.category??"entry")==="entry"))}}function Gm(t){return{allow_entry_in:e=>{t.strategy&&(t.strategy.risk_rules.allow_entry_in=e)},max_cons_loss_days:(e,r)=>{t.strategy&&(t.strategy.risk_rules.max_cons_loss_days={count:e,alert_message:r})},max_drawdown:(e,r,n)=>{t.strategy&&(t.strategy.risk_rules.max_drawdown={value:e,type:r})},max_intraday_filled_orders:(e,r)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_filled_orders={count:e,alert_message:r})},max_intraday_loss:(e,r,n)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_loss={value:e,type:r})},max_position_size:e=>{t.strategy&&(t.strategy.risk_rules.max_position_size=e)}}}function Ym(t){return e=>{let r=t.strategy,n=t.pine?.syminfo?.currency,i=r?.account_currency??"USD";return n&&n!==i?NaN:e}}function Zm(t){return e=>{let r=t.strategy,n=t.pine?.syminfo?.currency,i=r?.account_currency??"USD";return n&&n!==i?NaN:e}}function Xm(t){return e=>t.strategy?ps(t,void 0,1,e):0}var Qm={any:Uf,order:Kf,param:Hf,opentrades:Gf,closedtrades:Yf,netprofit:Zf,position_size:Xf,position_avg_price:Qf,equity:Jf,long:em,short:tm,cash:rm,percent_of_equity:nm,fixed:im,openprofit:sm,openprofit_percent:am,netprofit_percent:om,grossprofit:lm,grossprofit_percent:cm,grossloss:um,grossloss_percent:pm,wintrades:hm,losstrades:dm,eventrades:fm,avg_trade:mm,avg_trade_percent:ym,avg_winning_trade:gm,avg_winning_trade_percent:_m,avg_losing_trade:xm,avg_losing_trade_percent:bm,max_drawdown:vm,max_drawdown_percent:wm,max_runup:Em,max_runup_percent:Sm,max_contracts_held_all:Cm,max_contracts_held_long:Nm,max_contracts_held_short:km,position_entry_name:Im,initial_capital:Am,account_currency:Tm,margin_liquidation_price:Dm,entry:Rm,exit:Lm,close:jm,close_all:Um,cancel:Km,cancel_all:Hm,convert_to_account:Ym,convert_to_symbol:Zm,default_entry_qty:Xm},Jm={long:"long",short:"short",all:"all"},ey={none:"none",cancel:"cancel",reduce:"reduce"},ty={percent:"percent",cash_per_order:"cash_per_order",cash_per_contract:"cash_per_contract"},ki=class{constructor(e){this.context=e,Object.entries(Qm).forEach(([n,i])=>{this[n]=i(e)}),this.direction=()=>Jm,this.oca=()=>ey,this.commission=()=>ty;let r=Gm(e);this.risk=()=>r}};function ry(t,e){let r=e.trim();if(r==="UTC"||r==="GMT"||r==="Etc/UTC")return 0;let n=r.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(n){let a=n[1]==="+"?1:-1,o=parseInt(n[2],10),l=parseInt(n[3]||"0",10);return a*(o*60+l)}let i=Zt(t,e),s=new Date(Date.UTC(i.year,i.month-1,i.day,i.hour,i.minute,i.second));return Math.round((s.getTime()-t)/6e4)}function ny(t,e){let r=e>=0?"+":"-",n=s=>String(Math.floor(Math.abs(s))).padStart(2,"0"),i=r+n(e/60)+":"+n(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${i}]`}var Ii=class{constructor(e){this.context=e}logFormat(e,...r){return e.replace(/{(\\d+)}/g,(n,i)=>r[i])}param(e,r=0,n){return y.from(e).get(r)}_formatTimestamp(){let e=this.context.data.openTime.data[this.context.idx],r=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",n=ry(e,r);return ny(e,n)}warning(e,...r){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...r)}`)}error(e,...r){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...r)}`)}info(e,...r){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...r)}`)}},iy=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],sy=["January","February","March","April","May","June","July","August","September","October","November","December"],ay=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],oy=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],He=(t,e)=>String(t).padStart(e,"0"),Ai=class{constructor(e){this.context=e}param(e,r=0,n){return y.from(e).get(r)}tostring(e,r){if(typeof e!="number"||isNaN(e)||!r)return String(e);if(r==="mintick"){let i=this.context.pine?.syminfo?.mintick||.01,s=Math.max(0,-Math.floor(Math.log10(i)));return e.toFixed(s)}if(r==="integer")return String(Math.round(e));if(r==="percent")return(e*100).toFixed(2)+"%";if(r==="price"){let i=this.context.pine?.syminfo?.mintick||.01,s=Math.max(0,-Math.floor(Math.log10(i)));return e.toFixed(s)}if(r==="volume")return String(Math.round(e));let n=r.indexOf(".");if(n>=0){let i=r.substring(n+1).length;return e.toFixed(i)}return r.includes("#")||r.includes("0")?String(Math.round(e)):String(e)}tonumber(e){return Number(e)}lower(e){return String(e).toLowerCase()}upper(e){return String(e).toUpperCase()}trim(e){return String(e).trim()}repeat(e,r,n=""){return Array(r).fill(e).join(n||"")}replace_all(e,r,n){return String(e).replaceAll(r,n)}replace(e,r,n,i=0){let s=String(e),a=String(r),o=String(n),l=Math.floor(Number(i))||0;if(a==="")return s;let c=0,u=0;for(;;){let h=s.indexOf(a,c);if(h===-1)return s;if(u===l)return s.substring(0,h)+o+s.substring(h+a.length);u++,c=h+a.length}}contains(e,r){return String(e).includes(r)}endswith(e,r){return String(e).endsWith(r)}startswith(e,r){return String(e).startsWith(r)}pos(e,r){let n=String(e).indexOf(r);return n===-1?NaN:n}length(e){return String(e).length}match(e,r){return String(e).match(new RegExp(r))}split(e,r){return new q(String(e).split(r),z.string,this.context)}substring(e,r,n){return String(e).substring(r,n)}format_time(e,r="yyyy-MM-dd\'T\'HH:mm:ssZ",n){if(e==null||typeof e=="number"&&isNaN(e))return"NaN";let i=Number(e),s=n||this.context.pine?.syminfo?.timezone||"UTC",a=Zt(i,s),o=Date.UTC(a.year,a.month-1,a.day,a.hour,a.minute,a.second),l=Math.round((o-i)/6e4),c=Date.UTC(a.year,0,1),u=Math.floor((o-c)/864e5)+1,h=a.hour%12===0?12:a.hour%12,p="",d=0;for(;d<r.length;){let f=r[d];if(f==="\'"){if(r[d+1]==="\'"){p+="\'",d+=2;continue}let m=r.indexOf("\'",d+1);if(m===-1){p+=r.substring(d+1);break}p+=r.substring(d+1,m),d=m+1;continue}if(f>="a"&&f<="z"||f>="A"&&f<="Z"){let m=1;for(;r[d+m]===f;)m++;switch(d+=m,f){case"y":p+=m===2?He(a.year%100,2):m>=4?He(a.year,4):String(a.year);break;case"M":m>=4?p+=sy[a.month-1]:m===3?p+=iy[a.month-1]:m===2?p+=He(a.month,2):p+=String(a.month);break;case"d":p+=m===2?He(a.day,2):String(a.day);break;case"D":p+=m>=3?He(u,3):m===2?He(u,2):String(u);break;case"E":p+=m>=4?oy[a.dayOfWeek]:ay[a.dayOfWeek];break;case"a":p+=a.hour<12?"AM":"PM";break;case"h":p+=m===2?He(h,2):String(h);break;case"H":p+=m===2?He(a.hour,2):String(a.hour);break;case"m":p+=m===2?He(a.minute,2):String(a.minute);break;case"s":p+=m===2?He(a.second,2):String(a.second);break;case"S":{let x=i-Math.floor(i/1e3)*1e3;p+=He(x,3).substring(0,m);break}case"Z":{let x=l>=0?"+":"-",b=Math.abs(l);p+=`${x}${He(Math.floor(b/60),2)}${He(b%60,2)}`;break}default:p+=f.repeat(m)}continue}p+=f,d++}return p}format(e,...r){return e.replace(/\\{(\\d+)(?:,number,([^}]+))?\\}/g,(n,i,s)=>{let a=r[i];return s&&typeof a=="number"&&!isNaN(a)?this.tostring(a,s):String(a)})}},ly=Object.defineProperty,cy=(t,e,r)=>e in t?ly(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,uy=(t,e,r)=>cy(t,typeof e!="symbol"?e+"":e,r),Yr={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1M":"M"};function Zs(t){if(!t||/^\\d+$/.test(t))return t;if(Yr[t])return Yr[t];let e=t.toLowerCase();if(Yr[e])return Yr[e];if(t.length===1){let n=t.toUpperCase();if(["D","W","M","S"].includes(n))return n}let r=t.slice(-1).toUpperCase();if(["D","W","M","S"].includes(r)){let n=parseInt(t);if(!isNaN(n))return n+r}return t}var Ti=class{constructor(e){this.context=e,uy(this,"_normalized",null)}param(e,r=0,n){return y.from(e).get(r)}get normalized(){return this._normalized===null&&(this._normalized=Zs(this.context.timeframe)),this._normalized}get unit(){return this.normalized.slice(-1).toUpperCase()}get main_period(){return this.normalized}get period(){return this.normalized}get multiplier(){let e=parseInt(this.normalized);return isNaN(e)?1:e}get isdwm(){return["D","W","M"].includes(this.unit)}get isdaily(){return this.unit==="D"}get isweekly(){return this.unit==="W"}get ismonthly(){return this.unit==="M"}get isseconds(){return this.unit==="S"}get isminutes(){return/^\\d+$/.test(this.normalized)}get isintraday(){return!this.isdwm}change(e){let r=typeof e=="function"?e():e,n=r instanceof y?r.get(0):r,i=gi(n||"");if(!i)return!1;let s=y.from(this.context.data.openTime).get(0),a=y.from(this.context.data.openTime).get(1);if(isNaN(s)||isNaN(a))return!1;let o=_i(s,i),l=_i(a,i);return o!==l}from_seconds(e){return e<60?Math.ceil(e/5)*5+"S":e<3600*24?Math.ceil(e/60):e<=3600*24*7*52?e%(3600*24*7)===0?Math.ceil(e/604800)+"W":Math.ceil(e/(3600*24))+"D":"12M"}in_seconds(e){e==null?e=this.normalized:e=Zs(e);let r=e.slice(-1).toUpperCase(),n=parseInt(e);return r==="S"?isNaN(n)?1:n:r==="D"?(isNaN(n)?1:n)*60*60*24:r==="W"?(isNaN(n)?1:n)*60*60*24*7:r==="M"?(isNaN(n)?1:n)*60*60*24*30:isNaN(n)?0:n*60}},py=Object.defineProperty,hy=Object.getOwnPropertyDescriptor,bt=(t,e,r,n)=>{for(var i=n>1?void 0:n?hy(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&py(e,r,i),i},dy=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],fy=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],my={series:"series",title:"string",char:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},yy=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],gy=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],_y=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],xy=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],Xs=["color","offset","editable","show_last","title","display","force_overlay"],by=["price","title","color","linestyle","linewidth","editable","display"],vy=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],wy={series:"series",title:"string",color:"color",linewidth:"number",style:"string",trackprice:"boolean",histbase:"number",offset:"number",join:"bool",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Ey={series:"series",title:"string",style:"string",location:"string",color:"color",offset:"number",text:"string",textcolor:"color",editable:"boolean",size:"string",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Sy={series:"series",title:"string",colorup:"color",colordown:"color",offset:"number",minheight:"number",maxheight:"number",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Cy={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Ny={open:"series",high:"series",low:"series",close:"series",title:"string",color:"color",wickcolor:"color",bordercolor:"color",editable:"boolean",show_last:"number",display:"string",format:"string",precision:"number",force_overlay:"boolean"},Qs={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},ky={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},Iy={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"},dt=class{constructor(e){this.context=e}_resolvePlotKey(e,r){if(e){let n=this.context.plots[e];return!n||!r||n._callsiteId===r?e:e+r}return r||"plot"}extractPlotOptions(e){let r={};for(let n in e)r[n]=y.from(e[n]).get(0);return r}get linestyle_dashed(){return"linestyle_dashed"}get linestyle_dotted(){return"linestyle_dotted"}get linestyle_solid(){return"linestyle_solid"}get style_area(){return"style_area"}get style_areabr(){return"style_areabr"}get style_circles(){return"style_circles"}get style_columns(){return"style_columns"}get style_cross(){return"style_cross"}get style_histogram(){return"style_histogram"}get style_line(){return"style_line"}get style_linebr(){return"style_linebr"}get style_stepline(){return"style_stepline"}get style_stepline_diamond(){return"style_stepline_diamond"}get style_steplinebr(){return"style_steplinebr"}param(e,r=0,n){return y.from(e).get(r)}plotchar(...e){let r=ht(e),n=le(e,fy,my),{series:i,title:s,...a}=n,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,r);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:s,_plotKey:l,_callsiteId:r});let c=y.from(i).get(0);return this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:c,options:{char:o.char,color:o.color,textcolor:o.textcolor,location:o.location,size:o.size,offset:o.offset}}),this.context.plots[l]}any(...e){let r=ht(e),n=le(e,dy,wy),{series:i,title:s,...a}=n,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,r),c="color"in a;if(!this.context.plots[l]){let d=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:d},title:s,_plotKey:l,_callsiteId:r}}let u=y.from(i).get(0),h=o.color;typeof h=="function"&&(h=h());let p={color:c?typeof h=="string"?h:void 0:h||"#2962ff"};return"offset"in a&&(p.offset=o.offset),this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:u,options:p}),this.context.plots[l]}plotshape(...e){let r=ht(e),n=le(e,yy,Ey),{series:i,title:s,...a}=n,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,r);if(!this.context.plots[l]){let u=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,style:"shape",shape:o.style,overlay:u},title:s,_plotKey:l,_callsiteId:r}}let c=y.from(i).get(0);return this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:c,options:o?.location==="absolute"||c?{text:o.text,textcolor:o.textcolor,color:o.color,offset:o.offset,shape:o.style,location:o.location,size:o.size}:void 0}),this.context.plots[l]}plotarrow(...e){let r=ht(e),n=le(e,gy,Sy),{series:i,title:s,...a}=n,o=y.from(i).get(0),l=this.extractPlotOptions(a),c=this._resolvePlotKey(s,r);if(!this.context.plots[c]){let u=l.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[c]={data:[],options:{...l,style:"shape",overlay:u},title:s,_plotKey:c,_callsiteId:r}}return this.context.plots[c].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:o,options:typeof o=="number"&&!isNaN(o)&&o!==0?{text:void 0,textcolor:void 0,color:o>0?l.colorup:l.colordown,offset:l.offset,shape:o>0?"shape_arrow_up":"shape_arrow_down",location:o>0?"BelowBar":"AboveBar",height:l.maxheight}:void 0}),this.context.plots[c]}plotbar(...e){let r=ht(e),n=le(e,_y,Cy),{open:i,high:s,low:a,close:o,title:l,...c}=n,u=this.extractPlotOptions(c),h=this._resolvePlotKey(l,r);if(!this.context.plots[h]){let d=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[h]={data:[],options:{...u,style:"bar",overlay:d},title:l,_plotKey:h,_callsiteId:r}}let p=[y.from(i).get(0),y.from(s).get(0),y.from(a).get(0),y.from(o).get(0)];this.context.plots[h].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:p,options:{color:u.color}})}plotcandle(...e){let r=ht(e),n=le(e,xy,Ny),{open:i,high:s,low:a,close:o,title:l,...c}=n,u=this.extractPlotOptions(c),h=this._resolvePlotKey(l,r);if(!this.context.plots[h]){let d=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[h]={data:[],options:{...u,style:"candle",overlay:d},title:l,_plotKey:h,_callsiteId:r}}let p=[y.from(i).get(0),y.from(s).get(0),y.from(a).get(0),y.from(o).get(0)];return this.context.plots[h].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:p,options:{color:u.color,wickcolor:u.wickcolor,bordercolor:u.bordercolor}}),this.context.plots[h]}bgcolor(...e){let r=ht(e),n=le(e,Xs,Qs),{title:i,...s}=n,a=this.extractPlotOptions(s),o=this._resolvePlotKey(i,r);if(!this.context.plots[o]){let l=a.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...a,style:"background",overlay:l},title:i,_plotKey:o,_callsiteId:r}}this.context.plots[o].data.push({title:i,time:this.context.marketData[this.context.idx].openTime,value:a.color&&a.color!=="na"&&a?.color.toString()!=="NaN",options:{color:a.color}})}barcolor(...e){let r=ht(e),n=le(e,Xs,Qs),{title:i,...s}=n,a=this.extractPlotOptions(s),o=this._resolvePlotKey(i,r);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...a,style:"barcolor"},title:i,_plotKey:o,_callsiteId:r}),this.context.plots[o].data.push({title:i,time:this.context.marketData[this.context.idx].openTime,value:a.color&&a.color!=="na"&&a?.color.toString()!=="NaN",options:{color:a.color}}),this.context.plots[o]}};bt([N],dt.prototype,"plotchar",1),bt([N],dt.prototype,"any",1),bt([N],dt.prototype,"plotshape",1),bt([N],dt.prototype,"plotarrow",1),bt([N],dt.prototype,"plotbar",1),bt([N],dt.prototype,"plotcandle",1),bt([N],dt.prototype,"bgcolor",1),bt([N],dt.prototype,"barcolor",1);var gn=class{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,r=0,n){return y.from(e).get(r)}any(...e){let r=ht(e),n=le(e,by,ky),{price:i,title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u}=n,h=[i,{title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u,style:"hline"}];return r&&h.push({__callsiteId:r}),this.context.pine.plot.any(...h)}};bt([N],gn.prototype,"any",1);var _n=class{constructor(e){this.context=e}param(e,r=0,n){return y.from(e).get(r)}any(...e){let r=ht(e),n=e.length>=6&&typeof e[2]=="number",i=!n&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(n||i!==null){let s=e[0],a=e[1],o=i?y.from(i.top_value).get(0):e[2],l=i?y.from(i.bottom_value).get(0):e[3],c=i?y.from(i.top_color).get(0):e[4],u=i?y.from(i.bottom_color).get(0):e[5],h=i?i.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,p=s?._plotKey||s?.title,d=a?._plotKey||a?.title,f=h||"fill",m=this.context.plots[f];m&&r&&m._callsiteId!==r&&(f=r),this.context.plots[f]||(this.context.plots[f]={title:h||"Fill",plot1:p,plot2:d,data:[],options:{plot1:p,plot2:d,style:"fill",gradient:!0},_plotKey:f,_callsiteId:r}),this.context.plots[f].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{top_value:o,bottom_value:l,top_color:c,bottom_color:u}})}else{let s=le(e,vy,Iy),{plot1:a,plot2:o,color:l,title:c,editable:u,show_last:h,fillgaps:p,display:d}=s,f=c||"fill",m=this.context.plots[f];m&&r&&m._callsiteId!==r&&(f=r);let x=y.from(l).get(0);if(!this.context.plots[f]){let b=a?._plotKey||a?.title,w=o?._plotKey||o?.title;this.context.plots[f]={title:c||"Fill",plot1:b,plot2:w,data:[],options:{plot1:b,plot2:w,color:x,editable:u,show_last:h,fillgaps:p,display:d,style:"fill"},_plotKey:f,_callsiteId:r}}this.context.plots[f].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:x}})}}};bt([N],_n.prototype,"any",1);var Ay=Object.defineProperty,Ty=(t,e,r)=>e in t?Ay(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Dy=(t,e,r)=>Ty(t,typeof e!="symbol"?e+"":e,r),Di=class{constructor(e){this.context=e,Dy(this,"point");let r=this.context,n=i=>i==null?i:typeof i=="object"&&Array.isArray(i.data)&&typeof i.get=="function"?i.get(0):typeof i=="function"?i():i;this.point={new(i,s,a){return new Oe(n(i),n(s),n(a)??NaN)},from_index(i,s){return new Oe(void 0,n(i),n(s))},from_time(i,s){return new Oe(n(i),void 0,n(s))},copy(i){return i.copy()},now(i){let s=r.idx,a=r.marketData[s]?.openTime;return new Oe(a,s,n(i))}}}param(e,r=0,n){return y.from(e).get(r)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){let e=this.context?.chartStyle;return e==null||e==="standard"}is_heikinashi(){return this.context?.chartStyle==="heikinashi"}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}},My=Object.defineProperty,Py=(t,e,r)=>e in t?My(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Te=(t,e,r)=>Py(t,typeof e!="symbol"?e+"":e,r),Ry=0,kr=class t{constructor(e,r,n="",i="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",h="",p="default",d=!1){Te(this,"id"),Te(this,"x"),Te(this,"y"),Te(this,"text"),Te(this,"xloc"),Te(this,"yloc"),Te(this,"color"),Te(this,"style"),Te(this,"textcolor"),Te(this,"size"),Te(this,"textalign"),Te(this,"tooltip"),Te(this,"text_font_family"),Te(this,"force_overlay"),Te(this,"_deleted"),Te(this,"_helper"),Te(this,"_createdAtBar",-1),this.id=Ry++,this.x=e,this.y=r,this.text=n,this.xloc=i,this.yloc=s,this.color=a,this.style=o,this.textcolor=l,this.size=c,this.textalign=u,this.tooltip=h,this.text_font_family=p,this.force_overlay=d,this._deleted=!1,this._helper=null}set_x(e){this._helper?this._helper.set_x(this,e):this._deleted||(this.x=e)}set_y(e){this._helper?this._helper.set_y(this,e):this._deleted||(this.y=e)}set_xy(e,r){this._helper?this._helper.set_xy(this,e,r):this._deleted||(this.x=e,this.y=r)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_textcolor(e){this._helper?this._helper.set_textcolor(this,e):this._deleted||(this.textcolor=e)}set_size(e){this._helper?this._helper.set_size(this,e):this._deleted||(this.size=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_textalign(e){this._helper?this._helper.set_textalign(this,e):this._deleted||(this.textalign=e)}set_tooltip(e){this._helper?this._helper.set_tooltip(this,e):this._deleted||(this.tooltip=e)}set_xloc(e){this._helper?this._helper.set_xloc(this,e):this._deleted||(this.xloc=e)}set_yloc(e){this._helper?this._helper.set_yloc(this,e):this._deleted||(this.yloc=e)}set_point(e){this._helper&&this._helper.set_point(this,e)}set_text_font_family(e){this._deleted||(this.text_font_family=e)}get_x(){return this.x}get_y(){return this.y}get_text(){return this.text}delete(){this._deleted=!0}copy(){return new t(this.x,this.y,this.text,this.xloc,this.yloc,this.color,this.style,this.textcolor,this.size,this.textalign,this.tooltip,this.text_font_family,this.force_overlay)}toPlotData(){return{id:this.id,x:this.x,y:this.y,text:this.text,xloc:this.xloc,yloc:this.yloc,color:this.color,style:this.style,textcolor:this.textcolor,size:this.size,textalign:this.textalign,tooltip:this.tooltip,text_font_family:this.text_font_family,force_overlay:this.force_overlay,_deleted:this._deleted}}},Ja=Object.defineProperty,Fy=Object.getOwnPropertyDescriptor,By=(t,e,r)=>e in t?Ja(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Me=(t,e,r,n)=>{for(var i=n>1?void 0:n?Fy(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&Ja(e,r,i),i},Ly=(t,e,r)=>By(t,typeof e!="symbol"?e+"":e,r),Oy=[["x","y","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"],["point","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay"]],Vy={x:"number",y:"number",text:"string",xloc:"string",yloc:"string",color:"color",style:"string",textcolor:"color",size:"string",textalign:"string",tooltip:"string",text_font_family:"string",force_overlay:"boolean",point:"point"},Ee=class{constructor(e){this.context=e,Ly(this,"_labels",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._labels=this._labels.filter(s=>!s._deleted);let r=this._labels.map(s=>s.toPlotData()),n=r.filter(s=>!s.force_overlay),i=r.filter(s=>s.force_overlay);this.context.plots.__labels__.data=[{time:e,value:n,options:{style:"label"}}],i.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:i,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof Ze)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){let r=e.get(0);return typeof r=="number"&&isNaN(r)?null:r}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,r,n="",i="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",h="",p="default",d=!1){let f=new kr(e,r,this._resolve(n),this._resolve(i),this._resolve(s),this._resolve(a),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(u),this._resolve(h),this._resolve(p),d);return f._helper=this,f._createdAtBar=this.context.idx,this._labels.push(f),this._enforceMaxCount(),f}_enforceMaxCount(){let e=this.context.indicator?.max_labels_count??50,r=this._labels.filter(n=>!n._deleted);if(r.length>e){let n=r.length-e,i=0;for(let s of this._labels){if(i>=n)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let r=le(e,Oy,Vy),n,i,s=r.xloc;if(r.point instanceof Oe){let a=r.point,o=a.index!==void 0&&!(typeof a.index=="number"&&isNaN(a.index)),l=a.time!==void 0&&!(typeof a.time=="number"&&isNaN(a.time));o?(n=a.index,s=s||"bi"):l?(n=a.time,s=s||"bt"):(n=0,s=s||"bi"),i=a.price}else n=this._resolve(r.x),i=this._resolve(r.y);return this._createLabel(n,i,r.text,s,r.yloc,r.color,r.style,r.textcolor,r.size,r.textalign,r.tooltip,r.text_font_family,r.force_overlay)}any(...e){if(e.length===1){let r=e[0];if(r==null||r instanceof Ze||typeof r=="number"&&isNaN(r))return null;if(r instanceof kr)return r;if(r instanceof y){let n=r.get(0);if(n==null||typeof n=="number"&&isNaN(n))return null;if(n instanceof kr)return n}return null}return this.new(...e)}set_x(e,r){e&&!e._deleted&&(e.x=r)}set_y(e,r){e&&!e._deleted&&(e.y=r)}set_xy(e,r,n){e&&!e._deleted&&(e.x=r,e.y=n)}set_text(e,r){e&&!e._deleted&&(e.text=r)}set_color(e,r){e&&!e._deleted&&(e.color=r)}set_textcolor(e,r){e&&!e._deleted&&(e.textcolor=r)}set_size(e,r){e&&!e._deleted&&(e.size=r)}set_style(e,r){e&&!e._deleted&&(e.style=r)}set_textalign(e,r){e&&!e._deleted&&(e.textalign=r)}set_tooltip(e,r){e&&!e._deleted&&(e.tooltip=r)}set_xloc(e,r){e&&!e._deleted&&(e.xloc=r)}set_yloc(e,r){e&&!e._deleted&&(e.yloc=r)}set_point(e,r){if(e&&!e._deleted&&r){let n=r.index!==void 0&&!(typeof r.index=="number"&&isNaN(r.index)),i=r.time!==void 0&&!(typeof r.time=="number"&&isNaN(r.time));n?(e.x=r.index,e.xloc="bi"):i&&(e.x=r.time,e.xloc="bt"),e.y=r.price}}get_x(e){return e?e.x:NaN}get_y(e){return e?e.y:NaN}get_text(e){return e?e.text:""}copy(e){if(!e)return;let r=e.copy();return r._helper=this,r._createdAtBar=this.context.idx,this._labels.push(r),this._enforceMaxCount(),r}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(r=>r._createdAtBar<e),this.syncToPlot()}get style_label_down(){return"style_label_down"}get style_label_up(){return"style_label_up"}get style_label_left(){return"style_label_left"}get style_label_right(){return"style_label_right"}get style_label_lower_left(){return"style_label_lower_left"}get style_label_lower_right(){return"style_label_lower_right"}get style_label_upper_left(){return"style_label_upper_left"}get style_label_upper_right(){return"style_label_upper_right"}get style_label_center(){return"style_label_center"}get style_circle(){return"style_circle"}get style_square(){return"style_square"}get style_diamond(){return"style_diamond"}get style_flag(){return"style_flag"}get style_arrowup(){return"style_arrowup"}get style_arrowdown(){return"style_arrowdown"}get style_cross(){return"style_cross"}get style_xcross(){return"style_xcross"}get style_triangleup(){return"style_triangleup"}get style_triangledown(){return"style_triangledown"}get style_none(){return"style_none"}get style_text_outline(){return"style_text_outline"}};Me([N],Ee.prototype,"new",1),Me([N],Ee.prototype,"set_x",1),Me([N],Ee.prototype,"set_y",1),Me([N],Ee.prototype,"set_xy",1),Me([N],Ee.prototype,"set_text",1),Me([N],Ee.prototype,"set_color",1),Me([N],Ee.prototype,"set_textcolor",1),Me([N],Ee.prototype,"set_size",1),Me([N],Ee.prototype,"set_style",1),Me([N],Ee.prototype,"set_textalign",1),Me([N],Ee.prototype,"set_tooltip",1),Me([N],Ee.prototype,"set_xloc",1),Me([N],Ee.prototype,"set_yloc",1),Me([N],Ee.prototype,"set_point",1),Me([N],Ee.prototype,"copy",1),Me([N],Ee.prototype,"delete",1);var jy=Object.defineProperty,$y=(t,e,r)=>e in t?jy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$e=(t,e,r)=>$y(t,typeof e!="symbol"?e+"":e,r),Wy=0,Ir=class t{constructor(e,r,n,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){$e(this,"id"),$e(this,"x1"),$e(this,"y1"),$e(this,"x2"),$e(this,"y2"),$e(this,"xloc"),$e(this,"extend"),$e(this,"color"),$e(this,"style"),$e(this,"width"),$e(this,"force_overlay"),$e(this,"_deleted"),$e(this,"_helper"),$e(this,"_createdAtBar",-1),this.id=Wy++,this.x1=e,this.y1=r,this.x2=n,this.y2=i,this.xloc=s,this.extend=a,this.color=o,this.style=l,this.width=c,this.force_overlay=u,this._deleted=!1,this._helper=null}set_x1(e){this._helper?this._helper.set_x1(this,e):this._deleted||(this.x1=e)}set_y1(e){this._helper?this._helper.set_y1(this,e):this._deleted||(this.y1=e)}set_x2(e){this._helper?this._helper.set_x2(this,e):this._deleted||(this.x2=e)}set_y2(e){this._helper?this._helper.set_y2(this,e):this._deleted||(this.y2=e)}set_xy1(e,r){this._helper?this._helper.set_xy1(this,e,r):this._deleted||(this.x1=e,this.y1=r)}set_xy2(e,r){this._helper?this._helper.set_xy2(this,e,r):this._deleted||(this.x2=e,this.y2=r)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_width(e){this._helper?this._helper.set_width(this,e):this._deleted||(this.width=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_xloc(e,r,n){this._helper?this._helper.set_xloc(this,e,r,n):this._deleted||(this.x1=e,this.x2=r,this.xloc=n)}set_first_point(e){this._helper&&this._helper.set_first_point(this,e)}set_second_point(e){this._helper&&this._helper.set_second_point(this,e)}get_x1(){return this.x1}get_y1(){return this.y1}get_x2(){return this.x2}get_y2(){return this.y2}get_price(e){return this._helper?this._helper.get_price(this,e):NaN}delete(){this._deleted=!0}copy(){return new t(this.x1,this.y1,this.x2,this.y2,this.xloc,this.extend,this.color,this.style,this.width,this.force_overlay)}toPlotData(){return{id:this.id,x1:this.x1,y1:this.y1,x2:this.x2,y2:this.y2,xloc:this.xloc,extend:this.extend,color:this.color,style:this.style,width:this.width,force_overlay:this.force_overlay,_deleted:this._deleted}}},eo=Object.defineProperty,Uy=Object.getOwnPropertyDescriptor,qy=(t,e,r)=>e in t?eo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Pe=(t,e,r,n)=>{for(var i=n>1?void 0:n?Uy(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&eo(e,r,i),i},zy=(t,e,r)=>qy(t,typeof e!="symbol"?e+"":e,r),Ky=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],Hy={x1:"number",y1:"number",x2:"number",y2:"number",xloc:"string",extend:"string",color:"color",style:"string",width:"number",force_overlay:"boolean",first_point:"point",second_point:"point"},Se=class{constructor(e){this.context=e,zy(this,"_lines",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__lines__||(this.context.plots.__lines__={title:"__lines__",data:[],options:{style:"drawing_line",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._lines=this._lines.filter(s=>!s._deleted);let r=this._lines.map(s=>s.toPlotData()),n=r.filter(s=>!s.force_overlay),i=r.filter(s=>s.force_overlay);this.context.plots.__lines__.data=[{time:e,value:n,options:{style:"drawing_line"}}],i.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:i,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e){let r=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),n=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return r?{x:e.index,xloc:"bi"}:n?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Ze?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){let r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r}_createLine(e,r,n,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){let h=new Ir(e,r,n,i,s,this._resolve(a),this._resolveColor(o),this._resolve(l),this._resolve(c)||1,u);return h._helper=this,h._createdAtBar=this.context.idx,this._lines.push(h),this._enforceMaxCount(),h}_enforceMaxCount(){let e=this.context.indicator?.max_lines_count??50,r=this._lines.filter(n=>!n._deleted);if(r.length>e){let n=r.length-e,i=0;for(let s of this._lines){if(i>=n)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let r=le(e,Ky,Hy),n,i,s,a,o=r.xloc;if(r.first_point instanceof Oe){let l=r.first_point,c=r.second_point,u=this._resolvePoint(l);n=u.x,i=l.price,o=o||u.xloc,c instanceof Oe?(s=this._resolvePoint(c).x,a=c.price):(s=0,a=NaN)}else n=this._resolve(r.x1),i=this._resolve(r.y1),s=this._resolve(r.x2),a=this._resolve(r.y2);return this._createLine(n,i,s,a,o,r.extend,r.color,r.style,r.width,r.force_overlay)}any(...e){if(e.length===1){let r=e[0];if(r==null||r instanceof Ze||typeof r=="number"&&isNaN(r))return null;if(r instanceof Ir)return r;if(r instanceof y){let n=r.get(0);if(n==null||typeof n=="number"&&isNaN(n))return null;if(n instanceof Ir)return n}return null}return this.new(...e)}set_x1(e,r){e&&!e._deleted&&(e.x1=this._resolve(r))}set_y1(e,r){e&&!e._deleted&&(e.y1=this._resolve(r))}set_x2(e,r){e&&!e._deleted&&(e.x2=this._resolve(r))}set_y2(e,r){e&&!e._deleted&&(e.y2=this._resolve(r))}set_xy1(e,r,n){e&&!e._deleted&&(e.x1=this._resolve(r),e.y1=this._resolve(n))}set_xy2(e,r,n){e&&!e._deleted&&(e.x2=this._resolve(r),e.y2=this._resolve(n))}set_color(e,r){e&&!e._deleted&&(e.color=this._resolveColor(r))}set_width(e,r){e&&!e._deleted&&(e.width=this._resolve(r)||1)}set_style(e,r){e&&!e._deleted&&(e.style=this._resolve(r))}set_extend(e,r){e&&!e._deleted&&(e.extend=this._resolve(r))}set_xloc(e,r,n,i){e&&!e._deleted&&(e.x1=r,e.x2=n,e.xloc=i)}set_first_point(e,r){if(e&&!e._deleted&&r){let n=this._resolvePoint(r);e.x1=n.x,e.y1=r.price,e.xloc=n.xloc}}set_second_point(e,r){if(e&&!e._deleted&&r){let n=this._resolvePoint(r);e.x2=n.x,e.y2=r.price,e.xloc=n.xloc}}get_x1(e){return e?e.x1:NaN}get_y1(e){return e?e.y1:NaN}get_x2(e){return e?e.x2:NaN}get_y2(e){return e?e.y2:NaN}get_price(e,r){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;let n=e.x2-e.x1;return n===0?e.y1:e.y1+(r-e.x1)/n*(e.y2-e.y1)}copy(e){if(!e)return;let r=e.copy();return r._helper=this,r._createdAtBar=this.context.idx,this._lines.push(r),this._enforceMaxCount(),r}delete(e){e&&(e._deleted=!0)}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(r=>r._createdAtBar<e),this.syncToPlot()}get style_solid(){return"style_solid"}get style_dotted(){return"style_dotted"}get style_dashed(){return"style_dashed"}get style_arrow_left(){return"style_arrow_left"}get style_arrow_right(){return"style_arrow_right"}get style_arrow_both(){return"style_arrow_both"}};Pe([N],Se.prototype,"new",1),Pe([N],Se.prototype,"set_x1",1),Pe([N],Se.prototype,"set_y1",1),Pe([N],Se.prototype,"set_x2",1),Pe([N],Se.prototype,"set_y2",1),Pe([N],Se.prototype,"set_xy1",1),Pe([N],Se.prototype,"set_xy2",1),Pe([N],Se.prototype,"set_color",1),Pe([N],Se.prototype,"set_width",1),Pe([N],Se.prototype,"set_style",1),Pe([N],Se.prototype,"set_extend",1),Pe([N],Se.prototype,"set_xloc",1),Pe([N],Se.prototype,"set_first_point",1),Pe([N],Se.prototype,"set_second_point",1),Pe([N],Se.prototype,"copy",1),Pe([N],Se.prototype,"delete",1);var Gy=Object.defineProperty,Yy=(t,e,r)=>e in t?Gy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,de=(t,e,r)=>Yy(t,typeof e!="symbol"?e+"":e,r),Zy=0,Ar=class t{constructor(e,r,n,i,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",h="",p="#000000",d="auto",f="center",m="center",x="wrap_none",b="default",w="format_none",v=!1){de(this,"id"),de(this,"left"),de(this,"top"),de(this,"right"),de(this,"bottom"),de(this,"xloc"),de(this,"extend"),de(this,"border_color"),de(this,"border_style"),de(this,"border_width"),de(this,"bgcolor"),de(this,"text"),de(this,"text_color"),de(this,"text_size"),de(this,"text_halign"),de(this,"text_valign"),de(this,"text_wrap"),de(this,"text_font_family"),de(this,"text_formatting"),de(this,"force_overlay"),de(this,"_deleted"),de(this,"_helper"),de(this,"_createdAtBar",-1),this.id=Zy++,this.left=e,this.top=r,this.right=n,this.bottom=i,this.xloc=s,this.extend=a,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=u,this.text=h,this.text_color=p,this.text_size=d,this.text_halign=f,this.text_valign=m,this.text_wrap=x,this.text_font_family=b,this.text_formatting=w,this.force_overlay=v,this._deleted=!1,this._helper=null}set_left(e){this._helper?this._helper.set_left(this,e):this._deleted||(this.left=e)}set_right(e){this._helper?this._helper.set_right(this,e):this._deleted||(this.right=e)}set_top(e){this._helper?this._helper.set_top(this,e):this._deleted||(this.top=e)}set_bottom(e){this._helper?this._helper.set_bottom(this,e):this._deleted||(this.bottom=e)}set_lefttop(e,r){this._helper?this._helper.set_lefttop(this,e,r):this._deleted||(this.left=e,this.top=r)}set_rightbottom(e,r){this._helper?this._helper.set_rightbottom(this,e,r):this._deleted||(this.right=e,this.bottom=r)}set_top_left_point(e){this._helper&&this._helper.set_top_left_point(this,e)}set_bottom_right_point(e){this._helper&&this._helper.set_bottom_right_point(this,e)}set_xloc(e,r,n){this._helper?this._helper.set_xloc(this,e,r,n):this._deleted||(this.left=e,this.right=r,this.xloc=n)}set_bgcolor(e){this._helper?this._helper.set_bgcolor(this,e):this._deleted||(this.bgcolor=e)}set_border_color(e){this._helper?this._helper.set_border_color(this,e):this._deleted||(this.border_color=e)}set_border_width(e){this._helper?this._helper.set_border_width(this,e):this._deleted||(this.border_width=e)}set_border_style(e){this._helper?this._helper.set_border_style(this,e):this._deleted||(this.border_style=e)}set_extend(e){this._helper?this._helper.set_extend(this,e):this._deleted||(this.extend=e)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_text_color(e){this._helper?this._helper.set_text_color(this,e):this._deleted||(this.text_color=e)}set_text_size(e){this._helper?this._helper.set_text_size(this,e):this._deleted||(this.text_size=e)}set_text_halign(e){this._helper?this._helper.set_text_halign(this,e):this._deleted||(this.text_halign=e)}set_text_valign(e){this._helper?this._helper.set_text_valign(this,e):this._deleted||(this.text_valign=e)}set_text_wrap(e){this._helper?this._helper.set_text_wrap(this,e):this._deleted||(this.text_wrap=e)}set_text_font_family(e){this._helper?this._helper.set_text_font_family(this,e):this._deleted||(this.text_font_family=e)}set_text_formatting(e){this._helper?this._helper.set_text_formatting(this,e):this._deleted||(this.text_formatting=e)}get_left(){return this.left}get_right(){return this.right}get_top(){return this.top}get_bottom(){return this.bottom}delete(){this._deleted=!0}toPlotData(){return{id:this.id,left:this.left,top:this.top,right:this.right,bottom:this.bottom,xloc:this.xloc,extend:this.extend,border_color:this.border_color,border_style:this.border_style,border_width:this.border_width,bgcolor:this.bgcolor,text:this.text,text_color:this.text_color,text_size:this.text_size,text_halign:this.text_halign,text_valign:this.text_valign,text_wrap:this.text_wrap,text_font_family:this.text_font_family,text_formatting:this.text_formatting,force_overlay:this.force_overlay,_deleted:this._deleted}}copy(){return new t(this.left,this.top,this.right,this.bottom,this.xloc,this.extend,this.border_color,this.border_style,this.border_width,this.bgcolor,this.text,this.text_color,this.text_size,this.text_halign,this.text_valign,this.text_wrap,this.text_font_family,this.text_formatting,this.force_overlay)}},to=Object.defineProperty,Xy=Object.getOwnPropertyDescriptor,Qy=(t,e,r)=>e in t?to(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ce=(t,e,r,n)=>{for(var i=n>1?void 0:n?Xy(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&to(e,r,i),i},Jy=(t,e,r)=>Qy(t,typeof e!="symbol"?e+"":e,r),eg=[["left","top","right","bottom","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"],["top_left","bottom_right","border_color","border_width","border_style","extend","xloc","bgcolor","text","text_size","text_color","text_halign","text_valign","text_wrap","text_font_family","force_overlay"]],tg={left:"number",top:"number",right:"number",bottom:"number",top_left:"point",bottom_right:"point",border_color:"color",border_width:"number",border_style:"string",extend:"string",xloc:"string",bgcolor:"color",text:"string",text_size:"string",text_color:"color",text_halign:"string",text_valign:"string",text_wrap:"string",text_font_family:"string",force_overlay:"boolean"},oe=class{constructor(e){this.context=e,Jy(this,"_boxes",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__boxes__||(this.context.plots.__boxes__={title:"__boxes__",data:[],options:{style:"drawing_box",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._boxes=this._boxes.filter(s=>!s._deleted);let r=this._boxes.map(s=>s.toPlotData()),n=r.filter(s=>!s.force_overlay),i=r.filter(s=>s.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:n,options:{style:"drawing_box"}}],i.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:i,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e){let r=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),n=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return r?{x:e.index,xloc:"bi"}:n?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Ze?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,r){let n=this._resolve(e);return n==null?n:typeof n=="number"&&isNaN(n)?NaN:n||r}_createBox(e,r,n,i,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",h="",p="#000000",d="auto",f="center",m="center",x="wrap_none",b="default",w="format_none",v=!1){let E=new Ar(e,r,n,i,s,this._resolve(a),this._resolveColor(o,"#2962ff"),this._resolve(l)||"style_solid",this._resolve(c)??1,this._resolveColor(u,"#2962ff"),this._resolve(h)||"",this._resolveColor(p,"#000000"),this._resolve(d)||"auto",this._resolve(f)||"center",this._resolve(m)||"center",this._resolve(x)||"wrap_none",this._resolve(b)||"default",this._resolve(w)||"format_none",v);return E._helper=this,E._createdAtBar=this.context.idx,this._boxes.push(E),this._enforceMaxCount(),E}_enforceMaxCount(){let e=this.context.indicator?.max_boxes_count??50,r=this._boxes.filter(n=>!n._deleted);if(r.length>e){let n=r.length-e,i=0;for(let s of this._boxes){if(i>=n)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let r=le(e,eg,tg),n,i,s,a,o=r.xloc;if(r.top_left instanceof Oe){let l=r.top_left,c=r.bottom_right,u=this._resolvePoint(l);n=u.x,i=l.price,o=o||u.xloc,c instanceof Oe?(s=this._resolvePoint(c).x,a=c.price):(s=0,a=NaN)}else n=this._resolve(r.left),i=this._resolve(r.top),s=this._resolve(r.right),a=this._resolve(r.bottom);return this._createBox(n,i,s,a,o,r.extend,r.border_color,r.border_style,r.border_width,r.bgcolor,r.text,r.text_color,r.text_size,r.text_halign,r.text_valign,r.text_wrap,r.text_font_family,void 0,r.force_overlay)}any(...e){if(e.length===1){let r=e[0];if(r==null||r instanceof Ze||typeof r=="number"&&isNaN(r))return null;if(r instanceof Ar)return r;if(r instanceof y){let n=r.get(0);if(n==null||typeof n=="number"&&isNaN(n))return null;if(n instanceof Ar)return n}return null}return this.new(...e)}set_left(e,r){e&&!e._deleted&&(e.left=this._resolve(r))}set_right(e,r){e&&!e._deleted&&(e.right=this._resolve(r))}set_top(e,r){e&&!e._deleted&&(e.top=this._resolve(r))}set_bottom(e,r){e&&!e._deleted&&(e.bottom=this._resolve(r))}set_lefttop(e,r,n){e&&!e._deleted&&(e.left=this._resolve(r),e.top=this._resolve(n))}set_rightbottom(e,r,n){e&&!e._deleted&&(e.right=this._resolve(r),e.bottom=this._resolve(n))}set_top_left_point(e,r){if(e&&!e._deleted&&r){let n=this._resolvePoint(r);e.left=n.x,e.top=r.price,e.xloc=n.xloc}}set_bottom_right_point(e,r){if(e&&!e._deleted&&r){let n=this._resolvePoint(r);e.right=n.x,e.bottom=r.price,e.xloc=n.xloc}}set_xloc(e,r,n,i){e&&!e._deleted&&(e.left=this._resolve(r),e.right=this._resolve(n),e.xloc=this._resolve(i))}set_bgcolor(e,r){e&&!e._deleted&&(e.bgcolor=this._resolve(r))}set_border_color(e,r){e&&!e._deleted&&(e.border_color=this._resolve(r))}set_border_width(e,r){e&&!e._deleted&&(e.border_width=this._resolve(r)??1)}set_border_style(e,r){e&&!e._deleted&&(e.border_style=this._resolve(r))}set_extend(e,r){e&&!e._deleted&&(e.extend=this._resolve(r))}set_text(e,r){e&&!e._deleted&&(e.text=this._resolve(r)||"")}set_text_color(e,r){e&&!e._deleted&&(e.text_color=this._resolve(r))}set_text_size(e,r){e&&!e._deleted&&(e.text_size=this._resolve(r))}set_text_halign(e,r){e&&!e._deleted&&(e.text_halign=this._resolve(r))}set_text_valign(e,r){e&&!e._deleted&&(e.text_valign=this._resolve(r))}set_text_wrap(e,r){e&&!e._deleted&&(e.text_wrap=this._resolve(r))}set_text_font_family(e,r){e&&!e._deleted&&(e.text_font_family=this._resolve(r))}set_text_formatting(e,r){e&&!e._deleted&&(e.text_formatting=this._resolve(r))}get_left(e){return e?e.left:NaN}get_right(e){return e?e.right:NaN}get_top(e){return e?e.top:NaN}get_bottom(e){return e?e.bottom:NaN}copy(e){if(!e)return;let r=e.copy();return r._helper=this,r._createdAtBar=this.context.idx,this._boxes.push(r),this._enforceMaxCount(),r}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(r=>r._createdAtBar<e),this.syncToPlot()}};ce([N],oe.prototype,"new",1),ce([N],oe.prototype,"set_left",1),ce([N],oe.prototype,"set_right",1),ce([N],oe.prototype,"set_top",1),ce([N],oe.prototype,"set_bottom",1),ce([N],oe.prototype,"set_lefttop",1),ce([N],oe.prototype,"set_rightbottom",1),ce([N],oe.prototype,"set_top_left_point",1),ce([N],oe.prototype,"set_bottom_right_point",1),ce([N],oe.prototype,"set_xloc",1),ce([N],oe.prototype,"set_bgcolor",1),ce([N],oe.prototype,"set_border_color",1),ce([N],oe.prototype,"set_border_width",1),ce([N],oe.prototype,"set_border_style",1),ce([N],oe.prototype,"set_extend",1),ce([N],oe.prototype,"set_text",1),ce([N],oe.prototype,"set_text_color",1),ce([N],oe.prototype,"set_text_size",1),ce([N],oe.prototype,"set_text_halign",1),ce([N],oe.prototype,"set_text_valign",1),ce([N],oe.prototype,"set_text_wrap",1),ce([N],oe.prototype,"set_text_font_family",1),ce([N],oe.prototype,"set_text_formatting",1),ce([N],oe.prototype,"copy",1),ce([N],oe.prototype,"delete",1);var rg=Object.defineProperty,ng=(t,e,r)=>e in t?rg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cr=(t,e,r)=>ng(t,typeof e!="symbol"?e+"":e,r),ig=0,xn=class{constructor(e,r,n){cr(this,"id"),cr(this,"line1"),cr(this,"line2"),cr(this,"color"),cr(this,"_deleted"),cr(this,"_createdAtBar",-1),this.id=ig++,this.line1=e,this.line2=r,this.color=n,this._deleted=!1}get_line1(){return this.line1}get_line2(){return this.line2}set_color(e){this._deleted||(typeof e=="function"&&(e=e()),e&&typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"&&(e=e.get(0)),this.color=e||"")}delete(){this._deleted=!0}toPlotData(){let e=n=>n?{id:n.id,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,xloc:n.xloc,extend:n.extend,color:n.color,style:n.style,width:n.width,_deleted:n._deleted}:null,r=!!(this.line1?.force_overlay||this.line2?.force_overlay);return{id:this.id,line1:e(this.line1),line2:e(this.line2),color:this.color,force_overlay:r,_deleted:this._deleted}}},ro=Object.defineProperty,sg=Object.getOwnPropertyDescriptor,ag=(t,e,r)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ni=(t,e,r,n)=>{for(var i=n>1?void 0:n?sg(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&ro(e,r,i),i},og=(t,e,r)=>ag(t,typeof e!="symbol"?e+"":e,r),fr=class{constructor(e){this.context=e,og(this,"_linefills",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._linefills=this._linefills.filter(s=>!s._deleted);let r=this._linefills.map(s=>s.toPlotData()),n=r.filter(s=>!s.force_overlay),i=r.filter(s=>s.force_overlay);this.context.plots.__linefills__.data=[{time:e,value:n,options:{style:"linefill"}}],i.length>0?this.context.plots.__linefills_overlay__={title:"__linefills_overlay__",data:[{time:e,value:i,options:{style:"linefill"}}],options:{style:"linefill",overlay:!0}}:delete this.context.plots.__linefills_overlay__}_resolve(e){return e==null?e:e instanceof Ze?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){let r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r}new(e,r,n){let i=this._resolve(e),s=this._resolve(r),a=n&&typeof n=="object"&&!Array.isArray(n)&&"color"in n?n.color:n,o=this._resolveColor(a);if(i&&s){let c=i.id,u=s.id;for(let h of this._linefills){if(h._deleted)continue;let p=h.line1?.id,d=h.line2?.id;if(p===c&&d===u||p===u&&d===c)return h.color=o,h._createdAtBar=this.context.idx,h}}let l=new xn(i,s,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),l}any(...e){if(e.length===1){let r=e[0];return r==null||r instanceof Ze||typeof r=="number"&&isNaN(r)?null:r instanceof xn?r:null}return this.new(e[0],e[1],e[2])}set_color(e,r){e&&!e._deleted&&(e.color=this._resolveColor(r))}get_line1(e){return e?e.line1:void 0}get_line2(e){return e?e.line2:void 0}delete(e){e&&(e._deleted=!0)}get all(){return this._linefills.filter(e=>!e._deleted)}rollbackFromBar(e){this._linefills=this._linefills.filter(r=>r._createdAtBar<e),this.syncToPlot()}};ni([N],fr.prototype,"new",1),ni([N],fr.prototype,"set_color",1),ni([N],fr.prototype,"delete",1);var lg=Object.defineProperty,cg=(t,e,r)=>e in t?lg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Je=(t,e,r)=>cg(t,typeof e!="symbol"?e+"":e,r),ug=0,Tr=class{constructor(e,r=!1,n=!1,i="bi",s="#2962ff",a="",o="style_solid",l=1,c=!1){Je(this,"id"),Je(this,"points"),Je(this,"curved"),Je(this,"closed"),Je(this,"xloc"),Je(this,"line_color"),Je(this,"fill_color"),Je(this,"line_style"),Je(this,"line_width"),Je(this,"force_overlay"),Je(this,"_deleted"),Je(this,"_createdAtBar",-1),this.id=ug++,this.points=e,this.curved=r,this.closed=n,this.xloc=i,this.line_color=s,this.fill_color=a,this.line_style=o,this.line_width=l,this.force_overlay=c,this._deleted=!1}delete(){this._deleted=!0}toPlotData(){return{id:this.id,points:this.points.map(e=>({time:e.time,index:e.index,price:e.price})),curved:this.curved,closed:this.closed,xloc:this.xloc,line_color:this.line_color,fill_color:this.fill_color,line_style:this.line_style,line_width:this.line_width,force_overlay:this.force_overlay,_deleted:this._deleted}}},no=Object.defineProperty,pg=Object.getOwnPropertyDescriptor,hg=(t,e,r)=>e in t?no(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Js=(t,e,r,n)=>{for(var i=n>1?void 0:n?pg(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&no(e,r,i),i},dg=(t,e,r)=>hg(t,typeof e!="symbol"?e+"":e,r),Or=class{constructor(e){this.context=e,dg(this,"_polylines",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__polylines__||(this.context.plots.__polylines__={title:"__polylines__",data:[],options:{style:"drawing_polyline",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._polylines=this._polylines.filter(r=>!r._deleted),this.context.plots.__polylines__.data=[{time:e,value:this._polylines.map(r=>r.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof Ze?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,r){let n=this._resolve(e);return n==null?n:typeof n=="number"&&isNaN(n)?NaN:n||r}_extractPoints(e){let r=this._resolve(e),n=r&&r.array?r.array:r;return Array.isArray(n)?n.filter(i=>i instanceof Oe):[]}new(...e){let r,n=!1,i=!1,s="bi",a="#2962ff",o="",l="style_solid",c=1,u=!1,h=(b,w)=>Object.prototype.hasOwnProperty.call(b,w),p=b=>{h(b,"curved")&&(n=b.curved),h(b,"closed")&&(i=b.closed),h(b,"xloc")&&(s=b.xloc),h(b,"line_color")&&(a=b.line_color),h(b,"fill_color")&&(o=b.fill_color),h(b,"line_style")&&(l=b.line_style),h(b,"line_width")&&(c=b.line_width),h(b,"force_overlay")&&(u=b.force_overlay)},d=e.length>=1?e[e.length-1]:null,f=e.length>=2&&d&&typeof d=="object"&&!Array.isArray(d)&&!(d instanceof y)&&!(d instanceof Oe);if(e.length===1&&d&&typeof d=="object"&&!Array.isArray(d)&&"points"in d)r=d.points,p(d);else{let b=f?e.slice(0,-1):e;r=b[0],b.length>1&&(n=b[1]),b.length>2&&(i=b[2]),b.length>3&&(s=b[3]),b.length>4&&(a=b[4]),b.length>5&&(o=b[5]),b.length>6&&(l=b[6]),b.length>7&&(c=b[7]),b.length>8&&(u=b[8]),f&&p(d)}let m=this._extractPoints(r),x=new Tr(m,this._resolve(n)??!1,this._resolve(i)??!1,this._resolve(s)||"bi",this._resolveColor(a,"#2962ff"),this._resolveColor(o,""),this._resolve(l)||"style_solid",this._resolve(c)||1,this._resolve(u)??!1);return x._createdAtBar=this.context.idx,this._polylines.push(x),this._enforceMaxCount(),x}_enforceMaxCount(){let e=this.context.indicator?.max_polylines_count??50,r=this._polylines.filter(n=>!n._deleted);if(r.length>e){let n=r.length-e,i=0;for(let s of this._polylines){if(i>=n)break;s._deleted||(s._deleted=!0,i++)}}}any(...e){if(e.length===1){let r=e[0];if(r==null||r instanceof Ze||typeof r=="number"&&isNaN(r))return null;if(r instanceof Tr)return r;if(r instanceof y){let n=r.get(0);if(n==null||typeof n=="number"&&isNaN(n))return null;if(n instanceof Tr)return n}return null}return this.new(...e)}delete(e){e&&(e._deleted=!0)}get all(){return this._polylines.filter(e=>!e._deleted)}rollbackFromBar(e){this._polylines=this._polylines.filter(r=>r._createdAtBar<e),this.syncToPlot()}};Js([N],Or.prototype,"new",1),Js([N],Or.prototype,"delete",1);var fg=Object.defineProperty,mg=(t,e,r)=>e in t?fg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e,r)=>mg(t,typeof e!="symbol"?e+"":e,r),yg=0,bn=class{constructor(e="top_right",r=1,n=1,i="",s="",a=0,o="",l=0,c=!1){We(this,"id"),We(this,"position"),We(this,"columns"),We(this,"rows"),We(this,"bgcolor"),We(this,"frame_color"),We(this,"frame_width"),We(this,"border_color"),We(this,"border_width"),We(this,"force_overlay"),We(this,"_deleted"),We(this,"cells"),We(this,"merges"),We(this,"_helper"),this.id=yg++,this.position=e,this.columns=r,this.rows=n,this.bgcolor=i,this.frame_color=s,this.frame_width=a,this.border_color=o,this.border_width=l,this.force_overlay=c,this._deleted=!1,this.merges=[],this.cells=[];for(let u=0;u<n;u++){this.cells[u]=[];for(let h=0;h<r;h++)this.cells[u][h]=null}}delete(){this._deleted=!0}toPlotData(){let e=this.cells.map(r=>r.map(n=>n?{...n}:null));return{id:this.id,position:this.position,columns:this.columns,rows:this.rows,bgcolor:this.bgcolor,frame_color:this.frame_color,frame_width:this.frame_width,border_color:this.border_color,border_width:this.border_width,force_overlay:this.force_overlay,_deleted:this._deleted,cells:e,merges:this.merges.map(r=>({...r}))}}setCell(e,r,n){if(r<0||r>=this.rows||e<0||e>=this.columns)return;let i=this.cells[r][e];if(i&&i._merged&&i._merge_parent){let[a,o]=i._merge_parent;if(a===e&&o===r)i._merged=!1,i._merge_parent=void 0;else{this.setCell(a,o,n);return}}let s=i||this._defaultCell();Object.assign(s,n),this.cells[r][e]=s}getCell(e,r){return r<0||r>=this.rows||e<0||e>=this.columns?null:this.cells[r][e]}clearCell(e,r){r<0||r>=this.rows||e<0||e>=this.columns||(this.cells[r][e]=null)}_setHelper(e){this._helper=e}cell(...e){return this._helper.cell(this,...e)}clear(...e){return this._helper.clear(this,...e)}merge_cells(...e){return this._helper.merge_cells(this,...e)}cell_set_text(...e){return this._helper.cell_set_text(this,...e)}cell_set_bgcolor(...e){return this._helper.cell_set_bgcolor(this,...e)}cell_set_text_color(...e){return this._helper.cell_set_text_color(this,...e)}cell_set_text_size(...e){return this._helper.cell_set_text_size(this,...e)}cell_set_height(...e){return this._helper.cell_set_height(this,...e)}cell_set_width(...e){return this._helper.cell_set_width(this,...e)}cell_set_tooltip(...e){return this._helper.cell_set_tooltip(this,...e)}cell_set_text_halign(...e){return this._helper.cell_set_text_halign(this,...e)}cell_set_text_valign(...e){return this._helper.cell_set_text_valign(this,...e)}cell_set_text_font_family(...e){return this._helper.cell_set_text_font_family(this,...e)}set_position(...e){return this._helper.set_position(this,...e)}set_bgcolor(...e){return this._helper.set_bgcolor(this,...e)}set_border_color(...e){return this._helper.set_border_color(this,...e)}set_border_width(...e){return this._helper.set_border_width(this,...e)}set_frame_color(...e){return this._helper.set_frame_color(this,...e)}set_frame_width(...e){return this._helper.set_frame_width(this,...e)}_defaultCell(){return{text:"",width:0,height:0,text_color:"#000000",text_halign:"center",text_valign:"center",text_size:"normal",bgcolor:"",tooltip:"",text_font_family:"default",_merged:!1,_merge_parent:null}}},io=Object.defineProperty,gg=Object.getOwnPropertyDescriptor,_g=(t,e,r)=>e in t?io(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ye=(t,e,r,n)=>{for(var i=n>1?void 0:n?gg(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(n?a(e,r,i):a(i))||i);return n&&i&&io(e,r,i),i},xg=(t,e,r)=>_g(t,typeof e!="symbol"?e+"":e,r),ue=class{constructor(e){this.context=e,xg(this,"_tables",[])}param(e,r=0,n){return y.from(e).get(r)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._tables=this._tables.filter(r=>!r._deleted),this.context.plots.__tables__.data=[{time:e,value:this._tables.map(r=>r.toPlotData()),options:{style:"table"}}]}_resolve(e){return e==null?e:typeof e=="object"&&"__value"in e?e.__value:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}new(...e){let r="top_right",n=1,i=1,s="",a="",o=0,l="",c=0,u=!1,h=e[e.length-1];if(h&&typeof h=="object"&&!Array.isArray(h)&&("bgcolor"in h||"frame_color"in h||"border_color"in h||"position"in h||"columns"in h||"rows"in h)){let d=h,f=e.slice(0,-1);r=f[0]??d.position??r,n=f[1]??d.columns??n,i=f[2]??d.rows??i,s=d.bgcolor??s,a=d.frame_color??a,o=d.frame_width??o,l=d.border_color??l,c=d.border_width??c,u=d.force_overlay??u}else r=e[0]??r,n=e[1]??n,i=e[2]??i,s=e[3]??s,a=e[4]??a,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u;let p=new bn(this._resolve(r)||"top_right",this._resolve(n)||1,this._resolve(i)||1,this._resolve(s)||"",this._resolve(a)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(u)??!1);return p._setHelper(this),this._tables.push(p),p}any(...e){if(e.length===1){let r=e[0];return r==null||typeof r=="object"&&"__value"in r||typeof r=="number"&&isNaN(r)?null:r instanceof bn?r:null}return this.new(...e)}cell(...e){let r,n,i,s="",a=0,o=0,l="#000000",c="center",u="center",h="normal",p="",d="",f="default",m=e[e.length-1];if(m&&typeof m=="object"&&!Array.isArray(m)&&("text"in m||"bgcolor"in m||"text_color"in m||"text_size"in m||"text_halign"in m||"tooltip"in m||"column"in m||"row"in m||"height"in m||"width"in m||"text_valign"in m||"text_font_family"in m)){let v=m,E=e.slice(0,-1);r=E[0],n=E.length>1?E[1]:v.column??0,i=E.length>2?E[2]:v.row??0,s=E[3]??v.text??s,a=E[4]??v.width??a,o=E[5]??v.height??o,l=E[6]??v.text_color??l,c=E[7]??v.text_halign??c,u=E[8]??v.text_valign??u,h=E[9]??v.text_size??h,p=E[10]??v.bgcolor??p,d=E[11]??v.tooltip??d,f=E[12]??v.text_font_family??f}else r=e[0],n=e[1]??0,i=e[2]??0,s=e[3]??s,a=e[4]??a,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u,h=e[9]??h,p=e[10]??p,d=e[11]??d,f=e[12]??f;let x=this._resolve(r);if(!x||x._deleted)return;let b=this._resolve(n)??0,w=this._resolve(i)??0;x.setCell(b,w,{text:this._resolveText(this._resolve(s)),width:this._resolve(a)||0,height:this._resolve(o)||0,text_color:this._resolve(l)||"#000000",text_halign:this._resolve(c)||"center",text_valign:this._resolve(u)||"center",text_size:this._resolve(h)||"normal",bgcolor:this._resolve(p)||"",tooltip:this._resolveText(this._resolve(d)),text_font_family:this._resolve(f)||"default"})}delete(e){e&&(e._deleted=!0)}clear(...e){let r,n,i,s,a,o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){let d=o;r=e[0],n=e.length>2?e[1]:d.start_column??0,i=e.length>3?e[2]:d.start_row??0,s=d.end_column??(e.length>4?e[3]:n),a=d.end_row??(e.length>5?e[4]:i)}else r=e[0],n=e[1]??0,i=e[2]??0,s=e[3]??n,a=e[4]??i;let l=this._resolve(r);if(!l||l._deleted)return;let c=this._resolve(n)??0,u=this._resolve(i)??0,h=this._resolve(s)??c,p=this._resolve(a)??u;for(let d=u;d<=p;d++)for(let f=c;f<=h;f++)l.clearCell(f,d)}merge_cells(...e){let r,n,i,s,a,o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){let d=o;r=e[0],n=e.length>2?e[1]:d.start_column??0,i=e.length>3?e[2]:d.start_row??0,s=d.end_column??(e.length>4?e[3]:0),a=d.end_row??(e.length>5?e[4]:0)}else r=e[0],n=e[1]??0,i=e[2]??0,s=e[3]??0,a=e[4]??0;let l=this._resolve(r);if(!l||l._deleted)return;let c=this._resolve(n)??0,u=this._resolve(i)??0,h=this._resolve(s)??0,p=this._resolve(a)??0;for(let d=u;d<=p;d++)for(let f=c;f<=h;f++)d===u&&f===c||l.setCell(f,d,{_merged:!0,_merge_parent:[c,u]});l.merges.push({startCol:c,startRow:u,endCol:h,endRow:p})}cell_set_text(e,r,n,i){this._setCellProp(e,r,n,"text",i,!0)}cell_set_bgcolor(e,r,n,i){this._setCellProp(e,r,n,"bgcolor",i)}cell_set_text_color(e,r,n,i){this._setCellProp(e,r,n,"text_color",i)}cell_set_text_size(e,r,n,i){this._setCellProp(e,r,n,"text_size",i)}cell_set_height(e,r,n,i){this._setCellProp(e,r,n,"height",i)}cell_set_width(e,r,n,i){this._setCellProp(e,r,n,"width",i)}cell_set_tooltip(e,r,n,i){this._setCellProp(e,r,n,"tooltip",i,!0)}cell_set_text_halign(e,r,n,i){this._setCellProp(e,r,n,"text_halign",i)}cell_set_text_valign(e,r,n,i){this._setCellProp(e,r,n,"text_valign",i)}cell_set_text_font_family(e,r,n,i){this._setCellProp(e,r,n,"text_font_family",i)}set_position(e,r){let n=this._resolve(e);!n||n._deleted||(n.position=this._resolve(r)||n.position)}set_bgcolor(e,r){let n=this._resolve(e);!n||n._deleted||(n.bgcolor=this._resolve(r)||"")}set_border_color(e,r){let n=this._resolve(e);!n||n._deleted||(n.border_color=this._resolve(r)||"")}set_border_width(e,r){let n=this._resolve(e);!n||n._deleted||(n.border_width=this._resolve(r)||0)}set_frame_color(e,r){let n=this._resolve(e);!n||n._deleted||(n.frame_color=this._resolve(r)||"")}set_frame_width(e,r){let n=this._resolve(e);!n||n._deleted||(n.frame_width=this._resolve(r)||0)}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,r,n,i,s,a=!1){let o=this._resolve(e);if(!o||o._deleted)return;let l=this._resolve(r)??0,c=this._resolve(n)??0,u=this._resolve(s);o.setCell(l,c,{[i]:a?this._resolveText(u):u})}_resolveText(e){return e==null||e!==e?"":String(e)}};ye([N],ue.prototype,"new",1),ye([N],ue.prototype,"cell",1),ye([N],ue.prototype,"delete",1),ye([N],ue.prototype,"clear",1),ye([N],ue.prototype,"merge_cells",1),ye([N],ue.prototype,"cell_set_text",1),ye([N],ue.prototype,"cell_set_bgcolor",1),ye([N],ue.prototype,"cell_set_text_color",1),ye([N],ue.prototype,"cell_set_text_size",1),ye([N],ue.prototype,"cell_set_height",1),ye([N],ue.prototype,"cell_set_width",1),ye([N],ue.prototype,"cell_set_tooltip",1),ye([N],ue.prototype,"cell_set_text_halign",1),ye([N],ue.prototype,"cell_set_text_valign",1),ye([N],ue.prototype,"cell_set_text_font_family",1),ye([N],ue.prototype,"set_position",1),ye([N],ue.prototype,"set_bgcolor",1),ye([N],ue.prototype,"set_border_color",1),ye([N],ue.prototype,"set_border_width",1),ye([N],ue.prototype,"set_frame_color",1),ye([N],ue.prototype,"set_frame_width",1);var Mi=class{constructor(e){this.context=e}param(e,r=0,n){return typeof e=="string"?e:y.from(e).get(r)}inherit(e,r){let n=this._coerce(e),i=Ot(this._coerce(r)),{modifier:s}=Lr(n);return s&&s!=="standard"?vi(i,s):i}new(e,r,n,i,s,a){let o=this._coerce(e),l=this._coerce(r);return o?l?`${o}:${l}`:o:l}modify(e,r,n,i,s){return this._coerce(e)}standard(e){return e==null?Ot(this.context?.pine?.syminfo?.tickerid||this.context?.tickerId||""):Ot(this._coerce(e))}heikinashi(e){return vi(this._coerce(e),"heikinashi")}renko(e,r,n,i,s){return this._coerce(e)}kagi(e,r){return this._coerce(e)}linebreak(e,r){return this._coerce(e)}pointfigure(e,r,n,i,s){return this._coerce(e)}_coerce(e){if(e==null)return"";if(e instanceof y){let r=e.get(0);return r==null?"":String(r)}return typeof e=="number"&&isNaN(e)?"":String(e)}},bg=Object.defineProperty,vg=(t,e,r)=>e in t?bg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,G=(t,e,r)=>vg(t,typeof e!="symbol"?e+"":e,r),Pi=class nn{constructor({marketData:e,source:r,tickerId:n,timeframe:i,limit:s,sDate:a,eDate:o,fullContext:l,inputs:c}){G(this,"data",{open:new y([]),high:new y([]),low:new y([]),close:new y([]),volume:new y([]),hl2:new y([]),hlc3:new y([]),ohlc4:new y([]),hlcc4:new y([]),bar_index:new y([])}),G(this,"indicator"),G(this,"cache",{}),G(this,"taState",{}),G(this,"strategy"),G(this,"isSecondaryContext",!1),G(this,"chartTimezone",null),G(this,"chartStyle","standard"),G(this,"dataVersion",0),G(this,"__maxLoops",5e5),G(this,"NA",NaN),G(this,"warnings",[]),G(this,"alerts",[]),G(this,"_alertMode","realtime"),G(this,"_propOverrides",{}),G(this,"_execTick",0),G(this,"lang"),G(this,"length",0),G(this,"_drawingHelpers",[]),G(this,"pine"),G(this,"idx",0),G(this,"params",{}),G(this,"const",{}),G(this,"var",{}),G(this,"let",{}),G(this,"lctx",new Map),G(this,"result"),G(this,"plots",{}),G(this,"marketData"),G(this,"source"),G(this,"tickerId"),G(this,"timeframe",""),G(this,"limit"),G(this,"sDate"),G(this,"eDate"),G(this,"fullContext"),G(this,"viewportLeft"),G(this,"viewportRight"),G(this,"pineTSCode"),G(this,"inputs",{}),G(this,"_callStack",[]),G(this,"_pathStack",[]),this.marketData=e,this.source=r,this.tickerId=n,this.timeframe=i,this.limit=s,this.sDate=a,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};let u=new pn(this),h={Type:u.Type.bind(u),na:new Ze,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),alert:new un(this),error:u.error.bind(u),max_bars_back:u.max_bars_back.bind(u),timestamp:u.timestamp.bind(u),time:new dn(this,"openTime"),time_close:new dn(this,"closeTime"),dayofmonth:new xt(this,Ft.dayofmonth),dayofweek:new xt(this,Ft.dayofweek),hour:new xt(this,Ft.hour),minute:new xt(this,Ft.minute),month:new xt(this,Ft.month),second:new xt(this,Ft.second),weekofyear:new xt(this,Ft.weekofyear),year:new xt(this,Ft.year),bool:u.bool.bind(u),int:u.int.bind(u),float:u.float.bind(u),string:u.string.bind(u)},p=this;this.pine={input:new xi(this),ta:new Ci(this),math:new bi(this),request:new Si(this),array:new pi(this),map:new hi(this),matrix:new di(this),ticker:new Mi(this),strategy:new ki(this),syminfo:null,timeframe:new Ti(this),barstate:new fi(this),get bar_index(){return p.data.bar_index},get last_bar_index(){return p.data.close.length-1},get last_bar_time(){let k=p.marketData;return Array.isArray(k)&&k.length>0?k[k.length-1].openTime:p.data.openTime.get(0)},get timenow(){return new Date().getTime()},get time_tradingday(){let k=y.from(p.data.closeTime).get(0);if(isNaN(k))return NaN;let V=p.pine?.syminfo?.timezone||"UTC",T=Zt(k,V);return Date.UTC(T.year,T.month-1,T.day,0,0,0)},get inputs(){return p.inputs},log:new Ii(this),str:new Ai(this),...h,...Tc};let d=h.dayofweek;Object.assign(d,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=d;let f=new dt(this),m=new gn(this),x=new _n(this);this.bindContextObject(f,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(f,["any","param","linestyle_dashed","linestyle_dotted","linestyle_solid","style_area","style_areabr","style_circles","style_columns","style_cross","style_histogram","style_line","style_linebr","style_stepline","style_stepline_diamond","style_steplinebr"],"plot"),this.bindContextObject(m,["any","style_dashed","style_solid","style_dotted","param"],"hline"),this.bindContextObject(x,["any","param"],"fill");let b=new Di(this);this.pine.chart={param:b.param.bind(b),bg_color:b.bg_color.bind(b),fg_color:b.fg_color.bind(b),get is_standard(){return b.is_standard()},get is_heikinashi(){return b.is_heikinashi()},get is_kagi(){return b.is_kagi()},get is_linebreak(){return b.is_linebreak()},get is_pnf(){return b.is_pnf()},get is_range(){return b.is_range()},get is_renko(){return b.is_renko()},point:b.point,get left_visible_bar_time(){if(p.viewportLeft!==void 0)return p.viewportLeft;let k=p.marketData;return Array.isArray(k)&&k.length>0?k[0].openTime:NaN},get right_visible_bar_time(){if(p.viewportRight!==void 0)return p.viewportRight;let k=p.marketData;return Array.isArray(k)&&k.length>0?k[k.length-1].openTime:NaN}};let w=new Ee(this);this.bindContextObject(w,["any","new","param","set_x","set_y","set_xy","set_text","set_color","set_textcolor","set_size","set_style","set_textalign","set_tooltip","set_point","set_xloc","set_yloc","get_x","get_y","get_text","copy","delete","style_label_down","style_label_up","style_label_left","style_label_right","style_label_lower_left","style_label_lower_right","style_label_upper_left","style_label_upper_right","style_label_center","style_circle","style_square","style_diamond","style_flag","style_arrowup","style_arrowdown","style_cross","style_xcross","style_triangleup","style_triangledown","style_none","style_text_outline"],"label"),Object.defineProperty(this.pine.label,"all",{get:()=>w.all});let v=new Se(this);this.bindContextObject(v,["any","new","param","set_x1","set_y1","set_x2","set_y2","set_xy1","set_xy2","set_color","set_width","set_style","set_extend","set_xloc","set_first_point","set_second_point","get_x1","get_y1","get_x2","get_y2","get_price","copy","delete","style_solid","style_dotted","style_dashed","style_arrow_left","style_arrow_right","style_arrow_both"],"line"),Object.defineProperty(this.pine.line,"all",{get:()=>v.all});let E=new oe(this);this.bindContextObject(E,["any","new","param","copy","delete","set_left","set_right","set_top","set_bottom","set_lefttop","set_rightbottom","set_top_left_point","set_bottom_right_point","set_bgcolor","set_border_color","set_border_width","set_border_style","set_extend","set_xloc","set_text","set_text_color","set_text_size","set_text_halign","set_text_valign","set_text_wrap","set_text_font_family","set_text_formatting","get_left","get_right","get_top","get_bottom"],"box"),Object.defineProperty(this.pine.box,"all",{get:()=>E.all});let A=new fr(this);this.bindContextObject(A,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>A.all});let C=new Or(this);this.bindContextObject(C,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>C.all});let D=new ue(this);this.bindContextObject(D,["any","new","param","cell","delete","clear","merge_cells","cell_set_text","cell_set_bgcolor","cell_set_text_color","cell_set_text_size","cell_set_height","cell_set_width","cell_set_tooltip","cell_set_text_halign","cell_set_text_valign","cell_set_text_font_family","set_position","set_bgcolor","set_border_color","set_border_width","set_frame_color","set_frame_width"],"table"),Object.defineProperty(this.pine.table,"all",{get:()=>D.all}),this._drawingHelpers=[w,v,E,A,C,D];let j=new yi(this);this.bindContextObject(j,["any","param","new","rgb","from_gradient","r","g","b","t","aqua","black","blue","fuchsia","gray","green","lime","maroon","navy","olive","orange","purple","red","silver","teal","white","yellow"],"color")}warn(e,r){this.warnings.push({message:e,method:r,bar:this.idx})}rollbackDrawings(e){for(let r of this._drawingHelpers)r.rollbackFromBar(e)}bindContextObject(e,r,n=""){n&&!this.pine[n]&&(this.pine[n]={});let i=n?this.pine[n]:this.pine;for(let s of r)typeof e[s]=="function"?i[s]=e[s].bind(e):i[s]=e[s]}init(e,r,n=0){let i;return r instanceof y?i=r.get(0):Array.isArray(r)?Array.isArray(r[0])?i=r[0]:i=r[r.length-1+n]:i=r,e?e instanceof y?(e.data[e.data.length-1]=i,e):Array.isArray(e)?(e[e.length-1]=i,new y(e)):new y([i]):new y([i])}initVar(e,r){if(e)return e;if(typeof r=="function"&&(r=r()),r instanceof Lt){let i=r.__def__;for(let s in i)typeof r[s]=="function"&&(r[s]=r[s]())}let n;return r instanceof y?n=r.get(0):Array.isArray(r)?Array.isArray(r[0])?n=r[0]:n=this.precision(r[r.length-1]):n=this.precision(r),new y([n])}precision(e,r=10){let n=r===10?nn.PRECISION_EPSILON:10**r;return typeof e=="number"?Math.round(e*n)/n:e}param(e,r,n){return typeof e=="string"?e:e instanceof y?r?new y(e.data,e.offset+r):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[n]||(this.params[n]=[]),Array.isArray(e)?new y(e,r||0):(this.params[n].length===0?this.params[n].push(e):this.params[n][this.params[n].length-1]=e,new y(this.params[n],r||0)))}get(e,r){if(typeof r=="number"&&!Number.isInteger(r)&&(r=Math.trunc(r)),e instanceof y)return e.get(r);if(Array.isArray(e)){let n=e.length-1-r;return n<0||n>=e.length?NaN:e[n]}return e}set(e,r){if(e instanceof y){e.set(0,typeof r=="number"?this.precision(r):r);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=r:e.push(r);return}}iter(e){return e==null?[]:Array.isArray(e.array)?e.array:e.map instanceof Map?e.map:e}entries(e){return e==null?[].entries():Array.isArray(e.array)?e.array.entries():e.map instanceof Map?e.map.entries():Array.isArray(e)||typeof e.entries=="function"?e.entries():[].entries()}pushId(e){let r=this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:"",n=r?r+"|"+e:e;this._callStack.push(e),this._pathStack.push(n)}popId(){this._callStack.pop(),this._pathStack.pop()}peekId(){return this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:""}peekCtx(){let e=this.peekId();if(!e)return this;let r=this.lctx.get(e);return r||(r={id:e,let:{},const:{},var:{}},this.lctx.set(e,r)),r}call(e,r,...n){this.pushId(r);try{return e(...n)}finally{this.popId()}}get math(){return this._showDeprecationWarning("const math = context.math","const { math, ta, input } = context.pine"),this.pine.math}get ta(){return this._showDeprecationWarning("const ta = context.ta","const { ta, math, input } = context.pine"),this.pine.ta}get input(){return this._showDeprecationWarning("const input = context.input","const { input, math, ta } = context.pine"),this.pine.input}get request(){return this._showDeprecationWarning("const request = context.request","const { request, math, ta } = context.pine"),this.pine.request}get array(){return this._showDeprecationWarning("const array = context.array","const { array, math, ta } = context.pine"),this.pine.array}get core(){return this._showDeprecationWarning("context.core.*","context.pine (e.g., const { na, plotchar, color, plot, nz } = context.pine)"),{na:this.pine.na,fill:this.pine.fill,plotchar:this.pine.plotchar,plotshape:this.pine.plotshape,plotarrow:this.pine.plotarrow,color:this.pine.color,plot:this.pine.plot,nz:this.pine.nz}}_showDeprecationWarning(e,r){let n=`${e}->${r}`;nn._deprecationWarningsShown.has(n)||(nn._deprecationWarningsShown.add(n),typeof window<"u"?console.warn("%c[WARNING]%c %s syntax is deprecated. Use %s instead. This will be removed in a future version.","color: #FFA500; font-weight: bold;","color: #FFA500;",e,r):console.warn(`\\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${r} instead. This will be removed in a future version.\\x1B[0m`))}};G(Pi,"_deprecationWarningsShown",new Set),G(Pi,"PRECISION_EPSILON",10**10);var ea=Pi,wg=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,7,9,32,4,318,1,78,5,71,10,50,3,123,2,54,14,32,10,3,1,11,3,46,10,8,0,46,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,3,0,158,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,68,8,2,0,3,0,2,3,2,4,2,0,15,1,83,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,7,19,58,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,199,7,137,9,54,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,55,9,266,3,10,1,2,0,49,6,4,4,14,10,5350,0,7,14,11465,27,2343,9,87,9,39,4,60,6,26,9,535,9,470,0,2,54,8,3,82,0,12,1,19628,1,4178,9,519,45,3,22,543,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,101,0,161,6,10,9,357,0,62,13,499,13,245,1,2,9,233,0,3,0,8,1,6,0,475,6,110,6,6,9,4759,9,787719,239],so=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,13,10,2,14,2,6,2,1,2,10,2,14,2,6,2,1,4,51,13,310,10,21,11,7,25,5,2,41,2,8,70,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,7,25,39,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,39,27,10,22,251,41,7,1,17,5,57,28,11,0,9,21,43,17,47,20,28,22,13,52,58,1,3,0,14,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,20,1,64,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,31,9,2,0,3,0,2,37,2,0,26,0,2,0,45,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,38,6,186,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,19,72,200,32,32,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,24,43,261,18,16,0,2,12,2,33,125,0,80,921,103,110,18,195,2637,96,16,1071,18,5,26,3994,6,582,6842,29,1763,568,8,30,18,78,18,29,19,47,17,3,32,20,6,18,433,44,212,63,33,24,3,24,45,74,6,0,67,12,65,1,2,0,15,4,10,7381,42,31,98,114,8702,3,2,6,2,1,2,290,16,0,30,2,3,0,15,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,1845,30,7,5,262,61,147,44,11,6,17,0,322,29,19,43,485,27,229,29,3,0,208,30,2,2,2,1,2,6,3,4,10,1,225,6,2,3,2,1,2,14,2,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42719,33,4381,3,5773,3,7472,16,621,2467,541,1507,4938,6,8489],Eg="\\u200C\\u200D\\xB7\\u0300-\\u036F\\u0387\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u0669\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u06F0-\\u06F9\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07C0-\\u07C9\\u07EB-\\u07F3\\u07FD\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0859-\\u085B\\u0897-\\u089F\\u08CA-\\u08E1\\u08E3-\\u0903\\u093A-\\u093C\\u093E-\\u094F\\u0951-\\u0957\\u0962\\u0963\\u0966-\\u096F\\u0981-\\u0983\\u09BC\\u09BE-\\u09C4\\u09C7\\u09C8\\u09CB-\\u09CD\\u09D7\\u09E2\\u09E3\\u09E6-\\u09EF\\u09FE\\u0A01-\\u0A03\\u0A3C\\u0A3E-\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A66-\\u0A71\\u0A75\\u0A81-\\u0A83\\u0ABC\\u0ABE-\\u0AC5\\u0AC7-\\u0AC9\\u0ACB-\\u0ACD\\u0AE2\\u0AE3\\u0AE6-\\u0AEF\\u0AFA-\\u0AFF\\u0B01-\\u0B03\\u0B3C\\u0B3E-\\u0B44\\u0B47\\u0B48\\u0B4B-\\u0B4D\\u0B55-\\u0B57\\u0B62\\u0B63\\u0B66-\\u0B6F\\u0B82\\u0BBE-\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCD\\u0BD7\\u0BE6-\\u0BEF\\u0C00-\\u0C04\\u0C3C\\u0C3E-\\u0C44\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0C66-\\u0C6F\\u0C81-\\u0C83\\u0CBC\\u0CBE-\\u0CC4\\u0CC6-\\u0CC8\\u0CCA-\\u0CCD\\u0CD5\\u0CD6\\u0CE2\\u0CE3\\u0CE6-\\u0CEF\\u0CF3\\u0D00-\\u0D03\\u0D3B\\u0D3C\\u0D3E-\\u0D44\\u0D46-\\u0D48\\u0D4A-\\u0D4D\\u0D57\\u0D62\\u0D63\\u0D66-\\u0D6F\\u0D81-\\u0D83\\u0DCA\\u0DCF-\\u0DD4\\u0DD6\\u0DD8-\\u0DDF\\u0DE6-\\u0DEF\\u0DF2\\u0DF3\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0E50-\\u0E59\\u0EB1\\u0EB4-\\u0EBC\\u0EC8-\\u0ECE\\u0ED0-\\u0ED9\\u0F18\\u0F19\\u0F20-\\u0F29\\u0F35\\u0F37\\u0F39\\u0F3E\\u0F3F\\u0F71-\\u0F84\\u0F86\\u0F87\\u0F8D-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102B-\\u103E\\u1040-\\u1049\\u1056-\\u1059\\u105E-\\u1060\\u1062-\\u1064\\u1067-\\u106D\\u1071-\\u1074\\u1082-\\u108D\\u108F-\\u109D\\u135D-\\u135F\\u1369-\\u1371\\u1712-\\u1715\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B4-\\u17D3\\u17DD\\u17E0-\\u17E9\\u180B-\\u180D\\u180F-\\u1819\\u18A9\\u1920-\\u192B\\u1930-\\u193B\\u1946-\\u194F\\u19D0-\\u19DA\\u1A17-\\u1A1B\\u1A55-\\u1A5E\\u1A60-\\u1A7C\\u1A7F-\\u1A89\\u1A90-\\u1A99\\u1AB0-\\u1ABD\\u1ABF-\\u1ADD\\u1AE0-\\u1AEB\\u1B00-\\u1B04\\u1B34-\\u1B44\\u1B50-\\u1B59\\u1B6B-\\u1B73\\u1B80-\\u1B82\\u1BA1-\\u1BAD\\u1BB0-\\u1BB9\\u1BE6-\\u1BF3\\u1C24-\\u1C37\\u1C40-\\u1C49\\u1C50-\\u1C59\\u1CD0-\\u1CD2\\u1CD4-\\u1CE8\\u1CED\\u1CF4\\u1CF7-\\u1CF9\\u1DC0-\\u1DFF\\u200C\\u200D\\u203F\\u2040\\u2054\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2D7F\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\u30FB\\uA620-\\uA629\\uA66F\\uA674-\\uA67D\\uA69E\\uA69F\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA823-\\uA827\\uA82C\\uA880\\uA881\\uA8B4-\\uA8C5\\uA8D0-\\uA8D9\\uA8E0-\\uA8F1\\uA8FF-\\uA909\\uA926-\\uA92D\\uA947-\\uA953\\uA980-\\uA983\\uA9B3-\\uA9C0\\uA9D0-\\uA9D9\\uA9E5\\uA9F0-\\uA9F9\\uAA29-\\uAA36\\uAA43\\uAA4C\\uAA4D\\uAA50-\\uAA59\\uAA7B-\\uAA7D\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uAAEB-\\uAAEF\\uAAF5\\uAAF6\\uABE3-\\uABEA\\uABEC\\uABED\\uABF0-\\uABF9\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE2F\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF10-\\uFF19\\uFF3F\\uFF65",ao="\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0560-\\u0588\\u05D0-\\u05EA\\u05EF-\\u05F2\\u0620-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u0860-\\u086A\\u0870-\\u0887\\u0889-\\u088F\\u08A0-\\u08C9\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u09FC\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0AF9\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58-\\u0C5A\\u0C5C\\u0C5D\\u0C60\\u0C61\\u0C80\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDC-\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D04-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D54-\\u0D56\\u0D5F-\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E86-\\u0E8A\\u0E8C-\\u0EA3\\u0EA5\\u0EA7-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F5\\u13F8-\\u13FD\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F8\\u1700-\\u1711\\u171F-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1878\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4C\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1C80-\\u1C8A\\u1C90-\\u1CBA\\u1CBD-\\u1CBF\\u1CE9-\\u1CEC\\u1CEE-\\u1CF3\\u1CF5\\u1CF6\\u1CFA\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2118-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2160-\\u2188\\u2C00-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u309B-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312F\\u3131-\\u318E\\u31A0-\\u31BF\\u31F0-\\u31FF\\u3400-\\u4DBF\\u4E00-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6EF\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA7DC\\uA7F1-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA8FD\\uA8FE\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB69\\uAB70-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC",ii={3:"abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",5:"class enum extends super const export import",6:"enum",strict:"implements interface let package private protected public static yield",strictBind:"eval arguments"},si="break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this",Sg={5:si,"5module":si+" export import",6:si+" const class extends export import super"},oo=/^in(stanceof)?$/,Cg=new RegExp("["+ao+"]"),Ng=new RegExp("["+ao+Eg+"]");function Ri(t,e){for(var r=65536,n=0;n<e.length;n+=2){if(r+=e[n],r>t)return!1;if(r+=e[n+1],r>=t)return!0}return!1}function Nt(t,e){return t<65?t===36:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&Cg.test(String.fromCharCode(t)):e===!1?!1:Ri(t,so)}function jt(t,e){return t<48?t===36:t<58?!0:t<65?!1:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&Ng.test(String.fromCharCode(t)):e===!1?!1:Ri(t,so)||Ri(t,wg)}var J=function(t,e){e===void 0&&(e={}),this.label=t,this.keyword=e.keyword,this.beforeExpr=!!e.beforeExpr,this.startsExpr=!!e.startsExpr,this.isLoop=!!e.isLoop,this.isAssign=!!e.isAssign,this.prefix=!!e.prefix,this.postfix=!!e.postfix,this.binop=e.binop||null,this.updateContext=null};function et(t,e){return new J(t,{beforeExpr:!0,binop:e})}var tt={beforeExpr:!0},Ue={startsExpr:!0},hs={};function Q(t,e){return e===void 0&&(e={}),e.keyword=t,hs[t]=new J(t,e)}var g={num:new J("num",Ue),regexp:new J("regexp",Ue),string:new J("string",Ue),name:new J("name",Ue),privateId:new J("privateId",Ue),eof:new J("eof"),bracketL:new J("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new J("]"),braceL:new J("{",{beforeExpr:!0,startsExpr:!0}),braceR:new J("}"),parenL:new J("(",{beforeExpr:!0,startsExpr:!0}),parenR:new J(")"),comma:new J(",",tt),semi:new J(";",tt),colon:new J(":",tt),dot:new J("."),question:new J("?",tt),questionDot:new J("?."),arrow:new J("=>",tt),template:new J("template"),invalidTemplate:new J("invalidTemplate"),ellipsis:new J("...",tt),backQuote:new J("`",Ue),dollarBraceL:new J("${",{beforeExpr:!0,startsExpr:!0}),eq:new J("=",{beforeExpr:!0,isAssign:!0}),assign:new J("_=",{beforeExpr:!0,isAssign:!0}),incDec:new J("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new J("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:et("||",1),logicalAND:et("&&",2),bitwiseOR:et("|",3),bitwiseXOR:et("^",4),bitwiseAND:et("&",5),equality:et("==/!=/===/!==",6),relational:et("</>/<=/>=",7),bitShift:et("<</>>/>>>",8),plusMin:new J("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:et("%",10),star:et("*",10),slash:et("/",10),starstar:new J("**",{beforeExpr:!0}),coalesce:et("??",1),_break:Q("break"),_case:Q("case",tt),_catch:Q("catch"),_continue:Q("continue"),_debugger:Q("debugger"),_default:Q("default",tt),_do:Q("do",{isLoop:!0,beforeExpr:!0}),_else:Q("else",tt),_finally:Q("finally"),_for:Q("for",{isLoop:!0}),_function:Q("function",Ue),_if:Q("if"),_return:Q("return",tt),_switch:Q("switch"),_throw:Q("throw",tt),_try:Q("try"),_var:Q("var"),_const:Q("const"),_while:Q("while",{isLoop:!0}),_with:Q("with"),_new:Q("new",{beforeExpr:!0,startsExpr:!0}),_this:Q("this",Ue),_super:Q("super",Ue),_class:Q("class",Ue),_extends:Q("extends",tt),_export:Q("export"),_import:Q("import",Ue),_null:Q("null",Ue),_true:Q("true",Ue),_false:Q("false",Ue),_in:Q("in",{beforeExpr:!0,binop:7}),_instanceof:Q("instanceof",{beforeExpr:!0,binop:7}),_typeof:Q("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:Q("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:Q("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},ze=/\\r\\n?|\\n|\\u2028|\\u2029/,kg=new RegExp(ze.source,"g");function gr(t){return t===10||t===13||t===8232||t===8233}function lo(t,e,r){r===void 0&&(r=t.length);for(var n=e;n<r;n++){var i=t.charCodeAt(n);if(gr(i))return n<r-1&&i===13&&t.charCodeAt(n+1)===10?n+2:n+1}return-1}var co=/[\\u1680\\u2000-\\u200a\\u202f\\u205f\\u3000\\ufeff]/,Re=/(?:\\s|\\/\\/.*|\\/\\*[^]*?\\*\\/)*/g,uo=Object.prototype,Ig=uo.hasOwnProperty,Ag=uo.toString,_r=Object.hasOwn||(function(t,e){return Ig.call(t,e)}),ta=Array.isArray||(function(t){return Ag.call(t)==="[object Array]"}),ra=Object.create(null);function Bt(t){return ra[t]||(ra[t]=new RegExp("^(?:"+t.replace(/ /g,"|")+")$"))}function Mt(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(t&1023)+56320))}var Tg=/(?:[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF])/,Vr=function(t,e){this.line=t,this.column=e};Vr.prototype.offset=function(t){return new Vr(this.line,this.column+t)};var Wn=function(t,e,r){this.start=e,this.end=r,t.sourceFile!==null&&(this.source=t.sourceFile)};function po(t,e){for(var r=1,n=0;;){var i=lo(t,n,e);if(i<0)return new Vr(r,e-n);++r,n=i}}var Fi={ecmaVersion:null,sourceType:"script",onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowAwaitOutsideFunction:null,allowSuperOutsideMethod:null,allowHashBang:!1,checkPrivateFields:!0,locations:!1,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1},na=!1;function Dg(t){var e={};for(var r in Fi)e[r]=t&&_r(t,r)?t[r]:Fi[r];if(e.ecmaVersion==="latest"?e.ecmaVersion=1e8:e.ecmaVersion==null?(!na&&typeof console=="object"&&console.warn&&(na=!0,console.warn(`Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.`)),e.ecmaVersion=11):e.ecmaVersion>=2015&&(e.ecmaVersion-=2009),e.allowReserved==null&&(e.allowReserved=e.ecmaVersion<5),(!t||t.allowHashBang==null)&&(e.allowHashBang=e.ecmaVersion>=14),ta(e.onToken)){var n=e.onToken;e.onToken=function(i){return n.push(i)}}if(ta(e.onComment)&&(e.onComment=Mg(e,e.onComment)),e.sourceType==="commonjs"&&e.allowAwaitOutsideFunction)throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs");return e}function Mg(t,e){return function(r,n,i,s,a,o){var l={type:r?"Block":"Line",value:n,start:i,end:s};t.locations&&(l.loc=new Wn(this,a,o)),t.ranges&&(l.range=[i,s]),e.push(l)}}var Xt=1,Jt=2,ds=4,ho=8,fs=16,fo=32,Un=64,mo=128,er=256,Wr=512,yo=1024,qn=Xt|Jt|er;function ms(t,e){return Jt|(t?ds:0)|(e?ho:0)}var vn=0,ys=1,Rt=2,go=3,_o=4,xo=5,Ie=function(t,e,r){this.options=t=Dg(t),this.sourceFile=t.sourceFile,this.keywords=Bt(Sg[t.ecmaVersion>=6?6:t.sourceType==="module"?"5module":5]);var n="";t.allowReserved!==!0&&(n=ii[t.ecmaVersion>=6?6:t.ecmaVersion===5?5:3],t.sourceType==="module"&&(n+=" await")),this.reservedWords=Bt(n);var i=(n?n+" ":"")+ii.strict;this.reservedWordsStrict=Bt(i),this.reservedWordsStrictBind=Bt(i+" "+ii.strictBind),this.input=String(e),this.containsEsc=!1,r?(this.pos=r,this.lineStart=this.input.lastIndexOf(`\n`,r-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(ze).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=g.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule=t.sourceType==="module",this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.potentialArrowInForAwait=!1,this.yieldPos=this.awaitPos=this.awaitIdentPos=0,this.labels=[],this.undefinedExports=Object.create(null),this.pos===0&&t.allowHashBang&&this.input.slice(0,2)==="#!"&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(this.options.sourceType==="commonjs"?Jt:Xt),this.regexpState=null,this.privateNameStack=[]},st={inFunction:{configurable:!0},inGenerator:{configurable:!0},inAsync:{configurable:!0},canAwait:{configurable:!0},allowReturn:{configurable:!0},allowSuper:{configurable:!0},allowDirectSuper:{configurable:!0},treatFunctionsAsVar:{configurable:!0},allowNewDotTarget:{configurable:!0},allowUsing:{configurable:!0},inClassStaticBlock:{configurable:!0}};Ie.prototype.parse=function(){var t=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(t)};st.inFunction.get=function(){return(this.currentVarScope().flags&Jt)>0};st.inGenerator.get=function(){return(this.currentVarScope().flags&ho)>0};st.inAsync.get=function(){return(this.currentVarScope().flags&ds)>0};st.canAwait.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],r=e.flags;if(r&(er|Wr))return!1;if(r&Jt)return(r&ds)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction};st.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&Xt)};st.allowSuper.get=function(){var t=this.currentThisScope(),e=t.flags;return(e&Un)>0||this.options.allowSuperOutsideMethod};st.allowDirectSuper.get=function(){return(this.currentThisScope().flags&mo)>0};st.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())};st.allowNewDotTarget.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],r=e.flags;if(r&(er|Wr)||r&Jt&&!(r&fs))return!0}return!1};st.allowUsing.get=function(){var t=this.currentScope(),e=t.flags;return!(e&yo||!this.inModule&&e&Xt)};st.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&er)>0};Ie.extend=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];for(var r=this,n=0;n<t.length;n++)r=t[n](r);return r};Ie.parse=function(t,e){return new this(e,t).parse()};Ie.parseExpressionAt=function(t,e,r){var n=new this(r,t,e);return n.nextToken(),n.parseExpression()};Ie.tokenizer=function(t,e){return new this(e,t)};Object.defineProperties(Ie.prototype,st);var je=Ie.prototype,Pg=/^(?:\'((?:\\\\[^]|[^\'\\\\])*?)\'|"((?:\\\\[^]|[^"\\\\])*?)")/;je.strictDirective=function(t){if(this.options.ecmaVersion<5)return!1;for(;;){Re.lastIndex=t,t+=Re.exec(this.input)[0].length;var e=Pg.exec(this.input.slice(t));if(!e)return!1;if((e[1]||e[2])==="use strict"){Re.lastIndex=t+e[0].length;var r=Re.exec(this.input),n=r.index+r[0].length,i=this.input.charAt(n);return i===";"||i==="}"||ze.test(r[0])&&!(/[(`.[+\\-/*%<>=,?^&]/.test(i)||i==="!"&&this.input.charAt(n+1)==="=")}t+=e[0].length,Re.lastIndex=t,t+=Re.exec(this.input)[0].length,this.input[t]===";"&&t++}};je.eat=function(t){return this.type===t?(this.next(),!0):!1};je.isContextual=function(t){return this.type===g.name&&this.value===t&&!this.containsEsc};je.eatContextual=function(t){return this.isContextual(t)?(this.next(),!0):!1};je.expectContextual=function(t){this.eatContextual(t)||this.unexpected()};je.canInsertSemicolon=function(){return this.type===g.eof||this.type===g.braceR||ze.test(this.input.slice(this.lastTokEnd,this.start))};je.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0};je.semicolon=function(){!this.eat(g.semi)&&!this.insertSemicolon()&&this.unexpected()};je.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0};je.expect=function(t){this.eat(t)||this.unexpected()};je.unexpected=function(t){this.raise(t??this.start,"Unexpected token")};var zn=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};je.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element");var r=e?t.parenthesizedAssign:t.parenthesizedBind;r>-1&&this.raiseRecoverable(r,e?"Assigning to rvalue":"Parenthesized pattern")}};je.checkExpressionErrors=function(t,e){if(!t)return!1;var r=t.shorthandAssign,n=t.doubleProto;if(!e)return r>=0||n>=0;r>=0&&this.raise(r,"Shorthand property assignments are valid only in destructuring patterns"),n>=0&&this.raiseRecoverable(n,"Redefinition of __proto__ property")};je.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos<this.awaitPos)&&this.raise(this.yieldPos,"Yield expression cannot be a default value"),this.awaitPos&&this.raise(this.awaitPos,"Await expression cannot be a default value")};je.isSimpleAssignTarget=function(t){return t.type==="ParenthesizedExpression"?this.isSimpleAssignTarget(t.expression):t.type==="Identifier"||t.type==="MemberExpression"};var L=Ie.prototype;L.parseTopLevel=function(t){var e=Object.create(null);for(t.body||(t.body=[]);this.type!==g.eof;){var r=this.parseStatement(null,!0,e);t.body.push(r)}if(this.inModule)for(var n=0,i=Object.keys(this.undefinedExports);n<i.length;n+=1){var s=i[n];this.raiseRecoverable(this.undefinedExports[s].start,"Export \'"+s+"\' is not defined")}return this.adaptDirectivePrologue(t.body),this.next(),t.sourceType=this.options.sourceType==="commonjs"?"script":this.options.sourceType,this.finishNode(t,"Program")};var gs={kind:"loop"},Rg={kind:"switch"};L.isLet=function(t){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;Re.lastIndex=this.pos;var e=Re.exec(this.input),r=this.pos+e[0].length,n=this.fullCharCodeAt(r);if(n===91||n===92)return!0;if(t)return!1;if(n===123)return!0;if(Nt(n)){var i=r;do r+=n<=65535?1:2;while(jt(n=this.fullCharCodeAt(r)));if(n===92)return!0;var s=this.input.slice(i,r);if(!oo.test(s))return!0}return!1};L.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;Re.lastIndex=this.pos;var t=Re.exec(this.input),e=this.pos+t[0].length,r;return!ze.test(this.input.slice(this.pos,e))&&this.input.slice(e,e+8)==="function"&&(e+8===this.input.length||!(jt(r=this.fullCharCodeAt(e+8))||r===92))};L.isUsingKeyword=function(t,e){if(this.options.ecmaVersion<17||!this.isContextual(t?"await":"using"))return!1;Re.lastIndex=this.pos;var r=Re.exec(this.input),n=this.pos+r[0].length;if(ze.test(this.input.slice(this.pos,n)))return!1;if(t){var i=n+5,s;if(this.input.slice(n,i)!=="using"||i===this.input.length||jt(s=this.fullCharCodeAt(i))||s===92)return!1;Re.lastIndex=i;var a=Re.exec(this.input);if(n=i+a[0].length,a&&ze.test(this.input.slice(i,n)))return!1}var o=this.fullCharCodeAt(n);if(!Nt(o)&&o!==92)return!1;var l=n;do n+=o<=65535?1:2;while(jt(o=this.fullCharCodeAt(n)));if(o===92)return!0;var c=this.input.slice(l,n);return!(oo.test(c)||e&&c==="of")};L.isAwaitUsing=function(t){return this.isUsingKeyword(!0,t)};L.isUsing=function(t){return this.isUsingKeyword(!1,t)};L.parseStatement=function(t,e,r){var n=this.type,i=this.startNode(),s;switch(this.isLet(t)&&(n=g._var,s="let"),n){case g._break:case g._continue:return this.parseBreakContinueStatement(i,n.keyword);case g._debugger:return this.parseDebuggerStatement(i);case g._do:return this.parseDoStatement(i);case g._for:return this.parseForStatement(i);case g._function:return t&&(this.strict||t!=="if"&&t!=="label")&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(i,!1,!t);case g._class:return t&&this.unexpected(),this.parseClass(i,!0);case g._if:return this.parseIfStatement(i);case g._return:return this.parseReturnStatement(i);case g._switch:return this.parseSwitchStatement(i);case g._throw:return this.parseThrowStatement(i);case g._try:return this.parseTryStatement(i);case g._const:case g._var:return s=s||this.value,t&&s!=="var"&&this.unexpected(),this.parseVarStatement(i,s);case g._while:return this.parseWhileStatement(i);case g._with:return this.parseWithStatement(i);case g.braceL:return this.parseBlock(!0,i);case g.semi:return this.parseEmptyStatement(i);case g._export:case g._import:if(this.options.ecmaVersion>10&&n===g._import){Re.lastIndex=this.pos;var a=Re.exec(this.input),o=this.pos+a[0].length,l=this.input.charCodeAt(o);if(l===40||l===46)return this.parseExpressionStatement(i,this.parseExpression())}return this.options.allowImportExportEverywhere||(e||this.raise(this.start,"\'import\' and \'export\' may only appear at the top level"),this.inModule||this.raise(this.start,"\'import\' and \'export\' may appear only with \'sourceType: module\'")),n===g._import?this.parseImport(i):this.parseExport(i,r);default:if(this.isAsyncFunction())return t&&this.unexpected(),this.next(),this.parseFunctionStatement(i,!0,!t);var c=this.isAwaitUsing(!1)?"await using":this.isUsing(!1)?"using":null;if(c)return this.allowUsing||this.raise(this.start,"Using declaration cannot appear in the top level when source type is `script` or in the bare case statement"),c==="await using"&&(this.canAwait||this.raise(this.start,"Await using cannot appear outside of async function"),this.next()),this.next(),this.parseVar(i,!1,c),this.semicolon(),this.finishNode(i,"VariableDeclaration");var u=this.value,h=this.parseExpression();return n===g.name&&h.type==="Identifier"&&this.eat(g.colon)?this.parseLabeledStatement(i,u,h,t):this.parseExpressionStatement(i,h)}};L.parseBreakContinueStatement=function(t,e){var r=e==="break";this.next(),this.eat(g.semi)||this.insertSemicolon()?t.label=null:this.type!==g.name?this.unexpected():(t.label=this.parseIdent(),this.semicolon());for(var n=0;n<this.labels.length;++n){var i=this.labels[n];if((t.label==null||i.name===t.label.name)&&(i.kind!=null&&(r||i.kind==="loop")||t.label&&r))break}return n===this.labels.length&&this.raise(t.start,"Unsyntactic "+e),this.finishNode(t,r?"BreakStatement":"ContinueStatement")};L.parseDebuggerStatement=function(t){return this.next(),this.semicolon(),this.finishNode(t,"DebuggerStatement")};L.parseDoStatement=function(t){return this.next(),this.labels.push(gs),t.body=this.parseStatement("do"),this.labels.pop(),this.expect(g._while),t.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(g.semi):this.semicolon(),this.finishNode(t,"DoWhileStatement")};L.parseForStatement=function(t){this.next();var e=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(gs),this.enterScope(0),this.expect(g.parenL),this.type===g.semi)return e>-1&&this.unexpected(e),this.parseFor(t,null);var r=this.isLet();if(this.type===g._var||this.type===g._const||r){var n=this.startNode(),i=r?"let":this.value;return this.next(),this.parseVar(n,!0,i),this.finishNode(n,"VariableDeclaration"),this.parseForAfterInit(t,n,e)}var s=this.isContextual("let"),a=!1,o=this.isUsing(!0)?"using":this.isAwaitUsing(!0)?"await using":null;if(o){var l=this.startNode();return this.next(),o==="await using"&&(this.canAwait||this.raise(this.start,"Await using cannot appear outside of async function"),this.next()),this.parseVar(l,!0,o),this.finishNode(l,"VariableDeclaration"),this.parseForAfterInit(t,l,e)}var c=this.containsEsc,u=new zn,h=this.start,p=e>-1?this.parseExprSubscripts(u,"await"):this.parseExpression(!0,u);return this.type===g._in||(a=this.options.ecmaVersion>=6&&this.isContextual("of"))?(e>-1?(this.type===g._in&&this.unexpected(e),t.await=!0):a&&this.options.ecmaVersion>=8&&(p.start===h&&!c&&p.type==="Identifier"&&p.name==="async"?this.unexpected():this.options.ecmaVersion>=9&&(t.await=!1)),s&&a&&this.raise(p.start,"The left-hand side of a for-of loop may not start with \'let\'."),this.toAssignable(p,!1,u),this.checkLValPattern(p),this.parseForIn(t,p)):(this.checkExpressionErrors(u,!0),e>-1&&this.unexpected(e),this.parseFor(t,p))};L.parseForAfterInit=function(t,e,r){return(this.type===g._in||this.options.ecmaVersion>=6&&this.isContextual("of"))&&e.declarations.length===1?(this.options.ecmaVersion>=9&&(this.type===g._in?r>-1&&this.unexpected(r):t.await=r>-1),this.parseForIn(t,e)):(r>-1&&this.unexpected(r),this.parseFor(t,e))};L.parseFunctionStatement=function(t,e,r){return this.next(),this.parseFunction(t,Dr|(r?0:Bi),!1,e)};L.parseIfStatement=function(t){return this.next(),t.test=this.parseParenExpression(),t.consequent=this.parseStatement("if"),t.alternate=this.eat(g._else)?this.parseStatement("if"):null,this.finishNode(t,"IfStatement")};L.parseReturnStatement=function(t){return this.allowReturn||this.raise(this.start,"\'return\' outside of function"),this.next(),this.eat(g.semi)||this.insertSemicolon()?t.argument=null:(t.argument=this.parseExpression(),this.semicolon()),this.finishNode(t,"ReturnStatement")};L.parseSwitchStatement=function(t){this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(g.braceL),this.labels.push(Rg),this.enterScope(yo);for(var e,r=!1;this.type!==g.braceR;)if(this.type===g._case||this.type===g._default){var n=this.type===g._case;e&&this.finishNode(e,"SwitchCase"),t.cases.push(e=this.startNode()),e.consequent=[],this.next(),n?e.test=this.parseExpression():(r&&this.raiseRecoverable(this.lastTokStart,"Multiple default clauses"),r=!0,e.test=null),this.expect(g.colon)}else e||this.unexpected(),e.consequent.push(this.parseStatement(null));return this.exitScope(),e&&this.finishNode(e,"SwitchCase"),this.next(),this.labels.pop(),this.finishNode(t,"SwitchStatement")};L.parseThrowStatement=function(t){return this.next(),ze.test(this.input.slice(this.lastTokEnd,this.start))&&this.raise(this.lastTokEnd,"Illegal newline after throw"),t.argument=this.parseExpression(),this.semicolon(),this.finishNode(t,"ThrowStatement")};var Fg=[];L.parseCatchClauseParam=function(){var t=this.parseBindingAtom(),e=t.type==="Identifier";return this.enterScope(e?fo:0),this.checkLValPattern(t,e?_o:Rt),this.expect(g.parenR),t};L.parseTryStatement=function(t){if(this.next(),t.block=this.parseBlock(),t.handler=null,this.type===g._catch){var e=this.startNode();this.next(),this.eat(g.parenL)?e.param=this.parseCatchClauseParam():(this.options.ecmaVersion<10&&this.unexpected(),e.param=null,this.enterScope(0)),e.body=this.parseBlock(!1),this.exitScope(),t.handler=this.finishNode(e,"CatchClause")}return t.finalizer=this.eat(g._finally)?this.parseBlock():null,!t.handler&&!t.finalizer&&this.raise(t.start,"Missing catch or finally clause"),this.finishNode(t,"TryStatement")};L.parseVarStatement=function(t,e,r){return this.next(),this.parseVar(t,!1,e,r),this.semicolon(),this.finishNode(t,"VariableDeclaration")};L.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(gs),t.body=this.parseStatement("while"),this.labels.pop(),this.finishNode(t,"WhileStatement")};L.parseWithStatement=function(t){return this.strict&&this.raise(this.start,"\'with\' in strict mode"),this.next(),t.object=this.parseParenExpression(),t.body=this.parseStatement("with"),this.finishNode(t,"WithStatement")};L.parseEmptyStatement=function(t){return this.next(),this.finishNode(t,"EmptyStatement")};L.parseLabeledStatement=function(t,e,r,n){for(var i=0,s=this.labels;i<s.length;i+=1){var a=s[i];a.name===e&&this.raise(r.start,"Label \'"+e+"\' is already declared")}for(var o=this.type.isLoop?"loop":this.type===g._switch?"switch":null,l=this.labels.length-1;l>=0;l--){var c=this.labels[l];if(c.statementStart===t.start)c.statementStart=this.start,c.kind=o;else break}return this.labels.push({name:e,kind:o,statementStart:this.start}),t.body=this.parseStatement(n?n.indexOf("label")===-1?n+"label":n:"label"),this.labels.pop(),t.label=r,this.finishNode(t,"LabeledStatement")};L.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")};L.parseBlock=function(t,e,r){for(t===void 0&&(t=!0),e===void 0&&(e=this.startNode()),e.body=[],this.expect(g.braceL),t&&this.enterScope(0);this.type!==g.braceR;){var n=this.parseStatement(null);e.body.push(n)}return r&&(this.strict=!1),this.next(),t&&this.exitScope(),this.finishNode(e,"BlockStatement")};L.parseFor=function(t,e){return t.init=e,this.expect(g.semi),t.test=this.type===g.semi?null:this.parseExpression(),this.expect(g.semi),t.update=this.type===g.parenR?null:this.parseExpression(),this.expect(g.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,"ForStatement")};L.parseForIn=function(t,e){var r=this.type===g._in;return this.next(),e.type==="VariableDeclaration"&&e.declarations[0].init!=null&&(!r||this.options.ecmaVersion<8||this.strict||e.kind!=="var"||e.declarations[0].id.type!=="Identifier")&&this.raise(e.start,(r?"for-in":"for-of")+" loop variable declaration may not have an initializer"),t.left=e,t.right=r?this.parseExpression():this.parseMaybeAssign(),this.expect(g.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,r?"ForInStatement":"ForOfStatement")};L.parseVar=function(t,e,r,n){for(t.declarations=[],t.kind=r;;){var i=this.startNode();if(this.parseVarId(i,r),this.eat(g.eq)?i.init=this.parseMaybeAssign(e):!n&&r==="const"&&!(this.type===g._in||this.options.ecmaVersion>=6&&this.isContextual("of"))?this.unexpected():!n&&(r==="using"||r==="await using")&&this.options.ecmaVersion>=17&&this.type!==g._in&&!this.isContextual("of")?this.raise(this.lastTokEnd,"Missing initializer in "+r+" declaration"):!n&&i.id.type!=="Identifier"&&!(e&&(this.type===g._in||this.isContextual("of")))?this.raise(this.lastTokEnd,"Complex binding patterns require an initialization value"):i.init=null,t.declarations.push(this.finishNode(i,"VariableDeclarator")),!this.eat(g.comma))break}return t};L.parseVarId=function(t,e){t.id=e==="using"||e==="await using"?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(t.id,e==="var"?ys:Rt,!1)};var Dr=1,Bi=2,bo=4;L.parseFunction=function(t,e,r,n,i){this.initFunction(t),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!n)&&(this.type===g.star&&e&Bi&&this.unexpected(),t.generator=this.eat(g.star)),this.options.ecmaVersion>=8&&(t.async=!!n),e&Dr&&(t.id=e&bo&&this.type!==g.name?null:this.parseIdent(),t.id&&!(e&Bi)&&this.checkLValSimple(t.id,this.strict||t.generator||t.async?this.treatFunctionsAsVar?ys:Rt:go));var s=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(ms(t.async,t.generator)),e&Dr||(t.id=this.type===g.name?this.parseIdent():null),this.parseFunctionParams(t),this.parseFunctionBody(t,r,!1,i),this.yieldPos=s,this.awaitPos=a,this.awaitIdentPos=o,this.finishNode(t,e&Dr?"FunctionDeclaration":"FunctionExpression")};L.parseFunctionParams=function(t){this.expect(g.parenL),t.params=this.parseBindingList(g.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()};L.parseClass=function(t,e){this.next();var r=this.strict;this.strict=!0,this.parseClassId(t,e),this.parseClassSuper(t);var n=this.enterClassBody(),i=this.startNode(),s=!1;for(i.body=[],this.expect(g.braceL);this.type!==g.braceR;){var a=this.parseClassElement(t.superClass!==null);a&&(i.body.push(a),a.type==="MethodDefinition"&&a.kind==="constructor"?(s&&this.raiseRecoverable(a.start,"Duplicate constructor in the same class"),s=!0):a.key&&a.key.type==="PrivateIdentifier"&&Bg(n,a)&&this.raiseRecoverable(a.key.start,"Identifier \'#"+a.key.name+"\' has already been declared"))}return this.strict=r,this.next(),t.body=this.finishNode(i,"ClassBody"),this.exitClassBody(),this.finishNode(t,e?"ClassDeclaration":"ClassExpression")};L.parseClassElement=function(t){if(this.eat(g.semi))return null;var e=this.options.ecmaVersion,r=this.startNode(),n="",i=!1,s=!1,a="method",o=!1;if(this.eatContextual("static")){if(e>=13&&this.eat(g.braceL))return this.parseClassStaticBlock(r),r;this.isClassElementNameStart()||this.type===g.star?o=!0:n="static"}if(r.static=o,!n&&e>=8&&this.eatContextual("async")&&((this.isClassElementNameStart()||this.type===g.star)&&!this.canInsertSemicolon()?s=!0:n="async"),!n&&(e>=9||!s)&&this.eat(g.star)&&(i=!0),!n&&!s&&!i){var l=this.value;(this.eatContextual("get")||this.eatContextual("set"))&&(this.isClassElementNameStart()?a=l:n=l)}if(n?(r.computed=!1,r.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),r.key.name=n,this.finishNode(r.key,"Identifier")):this.parseClassElementName(r),e<13||this.type===g.parenL||a!=="method"||i||s){var c=!r.static&&wn(r,"constructor"),u=c&&t;c&&a!=="method"&&this.raise(r.key.start,"Constructor can\'t have get/set modifier"),r.kind=c?"constructor":a,this.parseClassMethod(r,i,s,u)}else this.parseClassField(r);return r};L.isClassElementNameStart=function(){return this.type===g.name||this.type===g.privateId||this.type===g.num||this.type===g.string||this.type===g.bracketL||this.type.keyword};L.parseClassElementName=function(t){this.type===g.privateId?(this.value==="constructor"&&this.raise(this.start,"Classes can\'t have an element named \'#constructor\'"),t.computed=!1,t.key=this.parsePrivateIdent()):this.parsePropertyName(t)};L.parseClassMethod=function(t,e,r,n){var i=t.key;t.kind==="constructor"?(e&&this.raise(i.start,"Constructor can\'t be a generator"),r&&this.raise(i.start,"Constructor can\'t be an async method")):t.static&&wn(t,"prototype")&&this.raise(i.start,"Classes may not have a static property named prototype");var s=t.value=this.parseMethod(e,r,n);return t.kind==="get"&&s.params.length!==0&&this.raiseRecoverable(s.start,"getter should have no params"),t.kind==="set"&&s.params.length!==1&&this.raiseRecoverable(s.start,"setter should have exactly one param"),t.kind==="set"&&s.params[0].type==="RestElement"&&this.raiseRecoverable(s.params[0].start,"Setter cannot use rest params"),this.finishNode(t,"MethodDefinition")};L.parseClassField=function(t){return wn(t,"constructor")?this.raise(t.key.start,"Classes can\'t have a field named \'constructor\'"):t.static&&wn(t,"prototype")&&this.raise(t.key.start,"Classes can\'t have a static field named \'prototype\'"),this.eat(g.eq)?(this.enterScope(Wr|Un),t.value=this.parseMaybeAssign(),this.exitScope()):t.value=null,this.semicolon(),this.finishNode(t,"PropertyDefinition")};L.parseClassStaticBlock=function(t){t.body=[];var e=this.labels;for(this.labels=[],this.enterScope(er|Un);this.type!==g.braceR;){var r=this.parseStatement(null);t.body.push(r)}return this.next(),this.exitScope(),this.labels=e,this.finishNode(t,"StaticBlock")};L.parseClassId=function(t,e){this.type===g.name?(t.id=this.parseIdent(),e&&this.checkLValSimple(t.id,Rt,!1)):(e===!0&&this.unexpected(),t.id=null)};L.parseClassSuper=function(t){t.superClass=this.eat(g._extends)?this.parseExprSubscripts(null,!1):null};L.enterClassBody=function(){var t={declared:Object.create(null),used:[]};return this.privateNameStack.push(t),t.declared};L.exitClassBody=function(){var t=this.privateNameStack.pop(),e=t.declared,r=t.used;if(this.options.checkPrivateFields)for(var n=this.privateNameStack.length,i=n===0?null:this.privateNameStack[n-1],s=0;s<r.length;++s){var a=r[s];_r(e,a.name)||(i?i.used.push(a):this.raiseRecoverable(a.start,"Private field \'#"+a.name+"\' must be declared in an enclosing class"))}};function Bg(t,e){var r=e.key.name,n=t[r],i="true";return e.type==="MethodDefinition"&&(e.kind==="get"||e.kind==="set")&&(i=(e.static?"s":"i")+e.kind),n==="iget"&&i==="iset"||n==="iset"&&i==="iget"||n==="sget"&&i==="sset"||n==="sset"&&i==="sget"?(t[r]="true",!1):n?!0:(t[r]=i,!1)}function wn(t,e){var r=t.computed,n=t.key;return!r&&(n.type==="Identifier"&&n.name===e||n.type==="Literal"&&n.value===e)}L.parseExportAllDeclaration=function(t,e){return this.options.ecmaVersion>=11&&(this.eatContextual("as")?(t.exported=this.parseModuleExportName(),this.checkExport(e,t.exported,this.lastTokStart)):t.exported=null),this.expectContextual("from"),this.type!==g.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ExportAllDeclaration")};L.parseExport=function(t,e){if(this.next(),this.eat(g.star))return this.parseExportAllDeclaration(t,e);if(this.eat(g._default))return this.checkExport(e,"default",this.lastTokStart),t.declaration=this.parseExportDefaultDeclaration(),this.finishNode(t,"ExportDefaultDeclaration");if(this.shouldParseExportStatement())t.declaration=this.parseExportDeclaration(t),t.declaration.type==="VariableDeclaration"?this.checkVariableExport(e,t.declaration.declarations):this.checkExport(e,t.declaration.id,t.declaration.id.start),t.specifiers=[],t.source=null,this.options.ecmaVersion>=16&&(t.attributes=[]);else{if(t.declaration=null,t.specifiers=this.parseExportSpecifiers(e),this.eatContextual("from"))this.type!==g.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause());else{for(var r=0,n=t.specifiers;r<n.length;r+=1){var i=n[r];this.checkUnreserved(i.local),this.checkLocalExport(i.local),i.local.type==="Literal"&&this.raise(i.local.start,"A string literal cannot be used as an exported binding without `from`.")}t.source=null,this.options.ecmaVersion>=16&&(t.attributes=[])}this.semicolon()}return this.finishNode(t,"ExportNamedDeclaration")};L.parseExportDeclaration=function(t){return this.parseStatement(null)};L.parseExportDefaultDeclaration=function(){var t;if(this.type===g._function||(t=this.isAsyncFunction())){var e=this.startNode();return this.next(),t&&this.next(),this.parseFunction(e,Dr|bo,!1,t)}else if(this.type===g._class){var r=this.startNode();return this.parseClass(r,"nullableID")}else{var n=this.parseMaybeAssign();return this.semicolon(),n}};L.checkExport=function(t,e,r){t&&(typeof e!="string"&&(e=e.type==="Identifier"?e.name:e.value),_r(t,e)&&this.raiseRecoverable(r,"Duplicate export \'"+e+"\'"),t[e]=!0)};L.checkPatternExport=function(t,e){var r=e.type;if(r==="Identifier")this.checkExport(t,e,e.start);else if(r==="ObjectPattern")for(var n=0,i=e.properties;n<i.length;n+=1){var s=i[n];this.checkPatternExport(t,s)}else if(r==="ArrayPattern")for(var a=0,o=e.elements;a<o.length;a+=1){var l=o[a];l&&this.checkPatternExport(t,l)}else r==="Property"?this.checkPatternExport(t,e.value):r==="AssignmentPattern"?this.checkPatternExport(t,e.left):r==="RestElement"&&this.checkPatternExport(t,e.argument)};L.checkVariableExport=function(t,e){if(t)for(var r=0,n=e;r<n.length;r+=1){var i=n[r];this.checkPatternExport(t,i.id)}};L.shouldParseExportStatement=function(){return this.type.keyword==="var"||this.type.keyword==="const"||this.type.keyword==="class"||this.type.keyword==="function"||this.isLet()||this.isAsyncFunction()};L.parseExportSpecifier=function(t){var e=this.startNode();return e.local=this.parseModuleExportName(),e.exported=this.eatContextual("as")?this.parseModuleExportName():e.local,this.checkExport(t,e.exported,e.exported.start),this.finishNode(e,"ExportSpecifier")};L.parseExportSpecifiers=function(t){var e=[],r=!0;for(this.expect(g.braceL);!this.eat(g.braceR);){if(r)r=!1;else if(this.expect(g.comma),this.afterTrailingComma(g.braceR))break;e.push(this.parseExportSpecifier(t))}return e};L.parseImport=function(t){return this.next(),this.type===g.string?(t.specifiers=Fg,t.source=this.parseExprAtom()):(t.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),t.source=this.type===g.string?this.parseExprAtom():this.unexpected()),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ImportDeclaration")};L.parseImportSpecifier=function(){var t=this.startNode();return t.imported=this.parseModuleExportName(),this.eatContextual("as")?t.local=this.parseIdent():(this.checkUnreserved(t.imported),t.local=t.imported),this.checkLValSimple(t.local,Rt),this.finishNode(t,"ImportSpecifier")};L.parseImportDefaultSpecifier=function(){var t=this.startNode();return t.local=this.parseIdent(),this.checkLValSimple(t.local,Rt),this.finishNode(t,"ImportDefaultSpecifier")};L.parseImportNamespaceSpecifier=function(){var t=this.startNode();return this.next(),this.expectContextual("as"),t.local=this.parseIdent(),this.checkLValSimple(t.local,Rt),this.finishNode(t,"ImportNamespaceSpecifier")};L.parseImportSpecifiers=function(){var t=[],e=!0;if(this.type===g.name&&(t.push(this.parseImportDefaultSpecifier()),!this.eat(g.comma)))return t;if(this.type===g.star)return t.push(this.parseImportNamespaceSpecifier()),t;for(this.expect(g.braceL);!this.eat(g.braceR);){if(e)e=!1;else if(this.expect(g.comma),this.afterTrailingComma(g.braceR))break;t.push(this.parseImportSpecifier())}return t};L.parseWithClause=function(){var t=[];if(!this.eat(g._with))return t;this.expect(g.braceL);for(var e={},r=!0;!this.eat(g.braceR);){if(r)r=!1;else if(this.expect(g.comma),this.afterTrailingComma(g.braceR))break;var n=this.parseImportAttribute(),i=n.key.type==="Identifier"?n.key.name:n.key.value;_r(e,i)&&this.raiseRecoverable(n.key.start,"Duplicate attribute key \'"+i+"\'"),e[i]=!0,t.push(n)}return t};L.parseImportAttribute=function(){var t=this.startNode();return t.key=this.type===g.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never"),this.expect(g.colon),this.type!==g.string&&this.unexpected(),t.value=this.parseExprAtom(),this.finishNode(t,"ImportAttribute")};L.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===g.string){var t=this.parseLiteral(this.value);return Tg.test(t.value)&&this.raise(t.start,"An export name cannot include a lone surrogate."),t}return this.parseIdent(!0)};L.adaptDirectivePrologue=function(t){for(var e=0;e<t.length&&this.isDirectiveCandidate(t[e]);++e)t[e].directive=t[e].expression.raw.slice(1,-1)};L.isDirectiveCandidate=function(t){return this.options.ecmaVersion>=5&&t.type==="ExpressionStatement"&&t.expression.type==="Literal"&&typeof t.expression.value=="string"&&(this.input[t.start]===\'"\'||this.input[t.start]==="\'")};var at=Ie.prototype;at.toAssignable=function(t,e,r){if(this.options.ecmaVersion>=6&&t)switch(t.type){case"Identifier":this.inAsync&&t.name==="await"&&this.raise(t.start,"Cannot use \'await\' as identifier inside an async function");break;case"ObjectPattern":case"ArrayPattern":case"AssignmentPattern":case"RestElement":break;case"ObjectExpression":t.type="ObjectPattern",r&&this.checkPatternErrors(r,!0);for(var n=0,i=t.properties;n<i.length;n+=1){var s=i[n];this.toAssignable(s,e),s.type==="RestElement"&&(s.argument.type==="ArrayPattern"||s.argument.type==="ObjectPattern")&&this.raise(s.argument.start,"Unexpected token")}break;case"Property":t.kind!=="init"&&this.raise(t.key.start,"Object pattern can\'t contain getter or setter"),this.toAssignable(t.value,e);break;case"ArrayExpression":t.type="ArrayPattern",r&&this.checkPatternErrors(r,!0),this.toAssignableList(t.elements,e);break;case"SpreadElement":t.type="RestElement",this.toAssignable(t.argument,e),t.argument.type==="AssignmentPattern"&&this.raise(t.argument.start,"Rest elements cannot have a default value");break;case"AssignmentExpression":t.operator!=="="&&this.raise(t.left.end,"Only \'=\' operator can be used for specifying default value."),t.type="AssignmentPattern",delete t.operator,this.toAssignable(t.left,e);break;case"ParenthesizedExpression":this.toAssignable(t.expression,e,r);break;case"ChainExpression":this.raiseRecoverable(t.start,"Optional chaining cannot appear in left-hand side");break;case"MemberExpression":if(!e)break;default:this.raise(t.start,"Assigning to rvalue")}else r&&this.checkPatternErrors(r,!0);return t};at.toAssignableList=function(t,e){for(var r=t.length,n=0;n<r;n++){var i=t[n];i&&this.toAssignable(i,e)}if(r){var s=t[r-1];this.options.ecmaVersion===6&&e&&s&&s.type==="RestElement"&&s.argument.type!=="Identifier"&&this.unexpected(s.argument.start)}return t};at.parseSpread=function(t){var e=this.startNode();return this.next(),e.argument=this.parseMaybeAssign(!1,t),this.finishNode(e,"SpreadElement")};at.parseRestBinding=function(){var t=this.startNode();return this.next(),this.options.ecmaVersion===6&&this.type!==g.name&&this.unexpected(),t.argument=this.parseBindingAtom(),this.finishNode(t,"RestElement")};at.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case g.bracketL:var t=this.startNode();return this.next(),t.elements=this.parseBindingList(g.bracketR,!0,!0),this.finishNode(t,"ArrayPattern");case g.braceL:return this.parseObj(!0)}return this.parseIdent()};at.parseBindingList=function(t,e,r,n){for(var i=[],s=!0;!this.eat(t);)if(s?s=!1:this.expect(g.comma),e&&this.type===g.comma)i.push(null);else{if(r&&this.afterTrailingComma(t))break;if(this.type===g.ellipsis){var a=this.parseRestBinding();this.parseBindingListItem(a),i.push(a),this.type===g.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.expect(t);break}else i.push(this.parseAssignableListItem(n))}return i};at.parseAssignableListItem=function(t){var e=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(e),e};at.parseBindingListItem=function(t){return t};at.parseMaybeDefault=function(t,e,r){if(r=r||this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(g.eq))return r;var n=this.startNodeAt(t,e);return n.left=r,n.right=this.parseMaybeAssign(),this.finishNode(n,"AssignmentPattern")};at.checkLValSimple=function(t,e,r){e===void 0&&(e=vn);var n=e!==vn;switch(t.type){case"Identifier":this.strict&&this.reservedWordsStrictBind.test(t.name)&&this.raiseRecoverable(t.start,(n?"Binding ":"Assigning to ")+t.name+" in strict mode"),n&&(e===Rt&&t.name==="let"&&this.raiseRecoverable(t.start,"let is disallowed as a lexically bound name"),r&&(_r(r,t.name)&&this.raiseRecoverable(t.start,"Argument name clash"),r[t.name]=!0),e!==xo&&this.declareName(t.name,e,t.start));break;case"ChainExpression":this.raiseRecoverable(t.start,"Optional chaining cannot appear in left-hand side");break;case"MemberExpression":n&&this.raiseRecoverable(t.start,"Binding member expression");break;case"ParenthesizedExpression":return n&&this.raiseRecoverable(t.start,"Binding parenthesized expression"),this.checkLValSimple(t.expression,e,r);default:this.raise(t.start,(n?"Binding":"Assigning to")+" rvalue")}};at.checkLValPattern=function(t,e,r){switch(e===void 0&&(e=vn),t.type){case"ObjectPattern":for(var n=0,i=t.properties;n<i.length;n+=1){var s=i[n];this.checkLValInnerPattern(s,e,r)}break;case"ArrayPattern":for(var a=0,o=t.elements;a<o.length;a+=1){var l=o[a];l&&this.checkLValInnerPattern(l,e,r)}break;default:this.checkLValSimple(t,e,r)}};at.checkLValInnerPattern=function(t,e,r){switch(e===void 0&&(e=vn),t.type){case"Property":this.checkLValInnerPattern(t.value,e,r);break;case"AssignmentPattern":this.checkLValPattern(t.left,e,r);break;case"RestElement":this.checkLValPattern(t.argument,e,r);break;default:this.checkLValPattern(t,e,r)}};var ct=function(t,e,r,n,i){this.token=t,this.isExpr=!!e,this.preserveSpace=!!r,this.override=n,this.generator=!!i},pe={b_stat:new ct("{",!1),b_expr:new ct("{",!0),b_tmpl:new ct("${",!1),p_stat:new ct("(",!1),p_expr:new ct("(",!0),q_tmpl:new ct("`",!0,!0,function(t){return t.tryReadTemplateToken()}),f_stat:new ct("function",!1),f_expr:new ct("function",!0),f_expr_gen:new ct("function",!0,!1,null,!0),f_gen:new ct("function",!1,!1,null,!0)},xr=Ie.prototype;xr.initialContext=function(){return[pe.b_stat]};xr.curContext=function(){return this.context[this.context.length-1]};xr.braceIsBlock=function(t){var e=this.curContext();return e===pe.f_expr||e===pe.f_stat?!0:t===g.colon&&(e===pe.b_stat||e===pe.b_expr)?!e.isExpr:t===g._return||t===g.name&&this.exprAllowed?ze.test(this.input.slice(this.lastTokEnd,this.start)):t===g._else||t===g.semi||t===g.eof||t===g.parenR||t===g.arrow?!0:t===g.braceL?e===pe.b_stat:t===g._var||t===g._const||t===g.name?!1:!this.exprAllowed};xr.inGeneratorContext=function(){for(var t=this.context.length-1;t>=1;t--){var e=this.context[t];if(e.token==="function")return e.generator}return!1};xr.updateContext=function(t){var e,r=this.type;r.keyword&&t===g.dot?this.exprAllowed=!1:(e=r.updateContext)?e.call(this,t):this.exprAllowed=r.beforeExpr};xr.overrideContext=function(t){this.curContext()!==t&&(this.context[this.context.length-1]=t)};g.parenR.updateContext=g.braceR.updateContext=function(){if(this.context.length===1){this.exprAllowed=!0;return}var t=this.context.pop();t===pe.b_stat&&this.curContext().token==="function"&&(t=this.context.pop()),this.exprAllowed=!t.isExpr};g.braceL.updateContext=function(t){this.context.push(this.braceIsBlock(t)?pe.b_stat:pe.b_expr),this.exprAllowed=!0};g.dollarBraceL.updateContext=function(){this.context.push(pe.b_tmpl),this.exprAllowed=!0};g.parenL.updateContext=function(t){var e=t===g._if||t===g._for||t===g._with||t===g._while;this.context.push(e?pe.p_stat:pe.p_expr),this.exprAllowed=!0};g.incDec.updateContext=function(){};g._function.updateContext=g._class.updateContext=function(t){t.beforeExpr&&t!==g._else&&!(t===g.semi&&this.curContext()!==pe.p_stat)&&!(t===g._return&&ze.test(this.input.slice(this.lastTokEnd,this.start)))&&!((t===g.colon||t===g.braceL)&&this.curContext()===pe.b_stat)?this.context.push(pe.f_expr):this.context.push(pe.f_stat),this.exprAllowed=!1};g.colon.updateContext=function(){this.curContext().token==="function"&&this.context.pop(),this.exprAllowed=!0};g.backQuote.updateContext=function(){this.curContext()===pe.q_tmpl?this.context.pop():this.context.push(pe.q_tmpl),this.exprAllowed=!1};g.star.updateContext=function(t){if(t===g._function){var e=this.context.length-1;this.context[e]===pe.f_expr?this.context[e]=pe.f_expr_gen:this.context[e]=pe.f_gen}this.exprAllowed=!0};g.name.updateContext=function(t){var e=!1;this.options.ecmaVersion>=6&&t!==g.dot&&(this.value==="of"&&!this.exprAllowed||this.value==="yield"&&this.inGeneratorContext())&&(e=!0),this.exprAllowed=e};var K=Ie.prototype;K.checkPropClash=function(t,e,r){if(!(this.options.ecmaVersion>=9&&t.type==="SpreadElement")&&!(this.options.ecmaVersion>=6&&(t.computed||t.method||t.shorthand))){var n=t.key,i;switch(n.type){case"Identifier":i=n.name;break;case"Literal":i=String(n.value);break;default:return}var s=t.kind;if(this.options.ecmaVersion>=6){i==="__proto__"&&s==="init"&&(e.proto&&(r?r.doubleProto<0&&(r.doubleProto=n.start):this.raiseRecoverable(n.start,"Redefinition of __proto__ property")),e.proto=!0);return}i="$"+i;var a=e[i];if(a){var o;s==="init"?o=this.strict&&a.init||a.get||a.set:o=a.init||a[s],o&&this.raiseRecoverable(n.start,"Redefinition of property")}else a=e[i]={init:!1,get:!1,set:!1};a[s]=!0}};K.parseExpression=function(t,e){var r=this.start,n=this.startLoc,i=this.parseMaybeAssign(t,e);if(this.type===g.comma){var s=this.startNodeAt(r,n);for(s.expressions=[i];this.eat(g.comma);)s.expressions.push(this.parseMaybeAssign(t,e));return this.finishNode(s,"SequenceExpression")}return i};K.parseMaybeAssign=function(t,e,r){if(this.isContextual("yield")){if(this.inGenerator)return this.parseYield(t);this.exprAllowed=!1}var n=!1,i=-1,s=-1,a=-1;e?(i=e.parenthesizedAssign,s=e.trailingComma,a=e.doubleProto,e.parenthesizedAssign=e.trailingComma=-1):(e=new zn,n=!0);var o=this.start,l=this.startLoc;(this.type===g.parenL||this.type===g.name)&&(this.potentialArrowAt=this.start,this.potentialArrowInForAwait=t==="await");var c=this.parseMaybeConditional(t,e);if(r&&(c=r.call(this,c,o,l)),this.type.isAssign){var u=this.startNodeAt(o,l);return u.operator=this.value,this.type===g.eq&&(c=this.toAssignable(c,!1,e)),n||(e.parenthesizedAssign=e.trailingComma=e.doubleProto=-1),e.shorthandAssign>=c.start&&(e.shorthandAssign=-1),this.type===g.eq?this.checkLValPattern(c):this.checkLValSimple(c),u.left=c,this.next(),u.right=this.parseMaybeAssign(t),a>-1&&(e.doubleProto=a),this.finishNode(u,"AssignmentExpression")}else n&&this.checkExpressionErrors(e,!0);return i>-1&&(e.parenthesizedAssign=i),s>-1&&(e.trailingComma=s),c};K.parseMaybeConditional=function(t,e){var r=this.start,n=this.startLoc,i=this.parseExprOps(t,e);if(this.checkExpressionErrors(e))return i;if(this.eat(g.question)){var s=this.startNodeAt(r,n);return s.test=i,s.consequent=this.parseMaybeAssign(),this.expect(g.colon),s.alternate=this.parseMaybeAssign(t),this.finishNode(s,"ConditionalExpression")}return i};K.parseExprOps=function(t,e){var r=this.start,n=this.startLoc,i=this.parseMaybeUnary(e,!1,!1,t);return this.checkExpressionErrors(e)||i.start===r&&i.type==="ArrowFunctionExpression"?i:this.parseExprOp(i,r,n,-1,t)};K.parseExprOp=function(t,e,r,n,i){var s=this.type.binop;if(s!=null&&(!i||this.type!==g._in)&&s>n){var a=this.type===g.logicalOR||this.type===g.logicalAND,o=this.type===g.coalesce;o&&(s=g.logicalAND.binop);var l=this.value;this.next();var c=this.start,u=this.startLoc,h=this.parseExprOp(this.parseMaybeUnary(null,!1,!1,i),c,u,s,i),p=this.buildBinary(e,r,t,h,l,a||o);return(a&&this.type===g.coalesce||o&&(this.type===g.logicalOR||this.type===g.logicalAND))&&this.raiseRecoverable(this.start,"Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"),this.parseExprOp(p,e,r,n,i)}return t};K.buildBinary=function(t,e,r,n,i,s){n.type==="PrivateIdentifier"&&this.raise(n.start,"Private identifier can only be left side of binary expression");var a=this.startNodeAt(t,e);return a.left=r,a.operator=i,a.right=n,this.finishNode(a,s?"LogicalExpression":"BinaryExpression")};K.parseMaybeUnary=function(t,e,r,n){var i=this.start,s=this.startLoc,a;if(this.isContextual("await")&&this.canAwait)a=this.parseAwait(n),e=!0;else if(this.type.prefix){var o=this.startNode(),l=this.type===g.incDec;o.operator=this.value,o.prefix=!0,this.next(),o.argument=this.parseMaybeUnary(null,!0,l,n),this.checkExpressionErrors(t,!0),l?this.checkLValSimple(o.argument):this.strict&&o.operator==="delete"&&vo(o.argument)?this.raiseRecoverable(o.start,"Deleting local variable in strict mode"):o.operator==="delete"&&Li(o.argument)?this.raiseRecoverable(o.start,"Private fields can not be deleted"):e=!0,a=this.finishNode(o,l?"UpdateExpression":"UnaryExpression")}else if(!e&&this.type===g.privateId)(n||this.privateNameStack.length===0)&&this.options.checkPrivateFields&&this.unexpected(),a=this.parsePrivateIdent(),this.type!==g._in&&this.unexpected();else{if(a=this.parseExprSubscripts(t,n),this.checkExpressionErrors(t))return a;for(;this.type.postfix&&!this.canInsertSemicolon();){var c=this.startNodeAt(i,s);c.operator=this.value,c.prefix=!1,c.argument=a,this.checkLValSimple(a),this.next(),a=this.finishNode(c,"UpdateExpression")}}if(!r&&this.eat(g.starstar))if(e)this.unexpected(this.lastTokStart);else return this.buildBinary(i,s,a,this.parseMaybeUnary(null,!1,!1,n),"**",!1);else return a};function vo(t){return t.type==="Identifier"||t.type==="ParenthesizedExpression"&&vo(t.expression)}function Li(t){return t.type==="MemberExpression"&&t.property.type==="PrivateIdentifier"||t.type==="ChainExpression"&&Li(t.expression)||t.type==="ParenthesizedExpression"&&Li(t.expression)}K.parseExprSubscripts=function(t,e){var r=this.start,n=this.startLoc,i=this.parseExprAtom(t,e);if(i.type==="ArrowFunctionExpression"&&this.input.slice(this.lastTokStart,this.lastTokEnd)!==")")return i;var s=this.parseSubscripts(i,r,n,!1,e);return t&&s.type==="MemberExpression"&&(t.parenthesizedAssign>=s.start&&(t.parenthesizedAssign=-1),t.parenthesizedBind>=s.start&&(t.parenthesizedBind=-1),t.trailingComma>=s.start&&(t.trailingComma=-1)),s};K.parseSubscripts=function(t,e,r,n,i){for(var s=this.options.ecmaVersion>=8&&t.type==="Identifier"&&t.name==="async"&&this.lastTokEnd===t.end&&!this.canInsertSemicolon()&&t.end-t.start===5&&this.potentialArrowAt===t.start,a=!1;;){var o=this.parseSubscript(t,e,r,n,s,a,i);if(o.optional&&(a=!0),o===t||o.type==="ArrowFunctionExpression"){if(a){var l=this.startNodeAt(e,r);l.expression=o,o=this.finishNode(l,"ChainExpression")}return o}t=o}};K.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(g.arrow)};K.parseSubscriptAsyncArrow=function(t,e,r,n){return this.parseArrowExpression(this.startNodeAt(t,e),r,!0,n)};K.parseSubscript=function(t,e,r,n,i,s,a){var o=this.options.ecmaVersion>=11,l=o&&this.eat(g.questionDot);n&&l&&this.raise(this.lastTokStart,"Optional chaining cannot appear in the callee of new expressions");var c=this.eat(g.bracketL);if(c||l&&this.type!==g.parenL&&this.type!==g.backQuote||this.eat(g.dot)){var u=this.startNodeAt(e,r);u.object=t,c?(u.property=this.parseExpression(),this.expect(g.bracketR)):this.type===g.privateId&&t.type!=="Super"?u.property=this.parsePrivateIdent():u.property=this.parseIdent(this.options.allowReserved!=="never"),u.computed=!!c,o&&(u.optional=l),t=this.finishNode(u,"MemberExpression")}else if(!n&&this.eat(g.parenL)){var h=new zn,p=this.yieldPos,d=this.awaitPos,f=this.awaitIdentPos;this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0;var m=this.parseExprList(g.parenR,this.options.ecmaVersion>=8,!1,h);if(i&&!l&&this.shouldParseAsyncArrow())return this.checkPatternErrors(h,!1),this.checkYieldAwaitInDefaultParams(),this.awaitIdentPos>0&&this.raise(this.awaitIdentPos,"Cannot use \'await\' as identifier inside an async function"),this.yieldPos=p,this.awaitPos=d,this.awaitIdentPos=f,this.parseSubscriptAsyncArrow(e,r,m,a);this.checkExpressionErrors(h,!0),this.yieldPos=p||this.yieldPos,this.awaitPos=d||this.awaitPos,this.awaitIdentPos=f||this.awaitIdentPos;var x=this.startNodeAt(e,r);x.callee=t,x.arguments=m,o&&(x.optional=l),t=this.finishNode(x,"CallExpression")}else if(this.type===g.backQuote){(l||s)&&this.raise(this.start,"Optional chaining cannot appear in the tag of tagged template expressions");var b=this.startNodeAt(e,r);b.tag=t,b.quasi=this.parseTemplate({isTagged:!0}),t=this.finishNode(b,"TaggedTemplateExpression")}return t};K.parseExprAtom=function(t,e,r){this.type===g.slash&&this.readRegexp();var n,i=this.potentialArrowAt===this.start;switch(this.type){case g._super:return this.allowSuper||this.raise(this.start,"\'super\' keyword outside a method"),n=this.startNode(),this.next(),this.type===g.parenL&&!this.allowDirectSuper&&this.raise(n.start,"super() call outside constructor of a subclass"),this.type!==g.dot&&this.type!==g.bracketL&&this.type!==g.parenL&&this.unexpected(),this.finishNode(n,"Super");case g._this:return n=this.startNode(),this.next(),this.finishNode(n,"ThisExpression");case g.name:var s=this.start,a=this.startLoc,o=this.containsEsc,l=this.parseIdent(!1);if(this.options.ecmaVersion>=8&&!o&&l.name==="async"&&!this.canInsertSemicolon()&&this.eat(g._function))return this.overrideContext(pe.f_expr),this.parseFunction(this.startNodeAt(s,a),0,!1,!0,e);if(i&&!this.canInsertSemicolon()){if(this.eat(g.arrow))return this.parseArrowExpression(this.startNodeAt(s,a),[l],!1,e);if(this.options.ecmaVersion>=8&&l.name==="async"&&this.type===g.name&&!o&&(!this.potentialArrowInForAwait||this.value!=="of"||this.containsEsc))return l=this.parseIdent(!1),(this.canInsertSemicolon()||!this.eat(g.arrow))&&this.unexpected(),this.parseArrowExpression(this.startNodeAt(s,a),[l],!0,e)}return l;case g.regexp:var c=this.value;return n=this.parseLiteral(c.value),n.regex={pattern:c.pattern,flags:c.flags},n;case g.num:case g.string:return this.parseLiteral(this.value);case g._null:case g._true:case g._false:return n=this.startNode(),n.value=this.type===g._null?null:this.type===g._true,n.raw=this.type.keyword,this.next(),this.finishNode(n,"Literal");case g.parenL:var u=this.start,h=this.parseParenAndDistinguishExpression(i,e);return t&&(t.parenthesizedAssign<0&&!this.isSimpleAssignTarget(h)&&(t.parenthesizedAssign=u),t.parenthesizedBind<0&&(t.parenthesizedBind=u)),h;case g.bracketL:return n=this.startNode(),this.next(),n.elements=this.parseExprList(g.bracketR,!0,!0,t),this.finishNode(n,"ArrayExpression");case g.braceL:return this.overrideContext(pe.b_expr),this.parseObj(!1,t);case g._function:return n=this.startNode(),this.next(),this.parseFunction(n,0);case g._class:return this.parseClass(this.startNode(),!1);case g._new:return this.parseNew();case g.backQuote:return this.parseTemplate();case g._import:return this.options.ecmaVersion>=11?this.parseExprImport(r):this.unexpected();default:return this.parseExprAtomDefault()}};K.parseExprAtomDefault=function(){this.unexpected()};K.parseExprImport=function(t){var e=this.startNode();if(this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword import"),this.next(),this.type===g.parenL&&!t)return this.parseDynamicImport(e);if(this.type===g.dot){var r=this.startNodeAt(e.start,e.loc&&e.loc.start);return r.name="import",e.meta=this.finishNode(r,"Identifier"),this.parseImportMeta(e)}else this.unexpected()};K.parseDynamicImport=function(t){if(this.next(),t.source=this.parseMaybeAssign(),this.options.ecmaVersion>=16)this.eat(g.parenR)?t.options=null:(this.expect(g.comma),this.afterTrailingComma(g.parenR)?t.options=null:(t.options=this.parseMaybeAssign(),this.eat(g.parenR)||(this.expect(g.comma),this.afterTrailingComma(g.parenR)||this.unexpected())));else if(!this.eat(g.parenR)){var e=this.start;this.eat(g.comma)&&this.eat(g.parenR)?this.raiseRecoverable(e,"Trailing comma is not allowed in import()"):this.unexpected(e)}return this.finishNode(t,"ImportExpression")};K.parseImportMeta=function(t){this.next();var e=this.containsEsc;return t.property=this.parseIdent(!0),t.property.name!=="meta"&&this.raiseRecoverable(t.property.start,"The only valid meta property for import is \'import.meta\'"),e&&this.raiseRecoverable(t.start,"\'import.meta\' must not contain escaped characters"),this.options.sourceType!=="module"&&!this.options.allowImportExportEverywhere&&this.raiseRecoverable(t.start,"Cannot use \'import.meta\' outside a module"),this.finishNode(t,"MetaProperty")};K.parseLiteral=function(t){var e=this.startNode();return e.value=t,e.raw=this.input.slice(this.start,this.end),e.raw.charCodeAt(e.raw.length-1)===110&&(e.bigint=e.value!=null?e.value.toString():e.raw.slice(0,-1).replace(/_/g,"")),this.next(),this.finishNode(e,"Literal")};K.parseParenExpression=function(){this.expect(g.parenL);var t=this.parseExpression();return this.expect(g.parenR),t};K.shouldParseArrow=function(t){return!this.canInsertSemicolon()};K.parseParenAndDistinguishExpression=function(t,e){var r=this.start,n=this.startLoc,i,s=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var a=this.start,o=this.startLoc,l=[],c=!0,u=!1,h=new zn,p=this.yieldPos,d=this.awaitPos,f;for(this.yieldPos=0,this.awaitPos=0;this.type!==g.parenR;)if(c?c=!1:this.expect(g.comma),s&&this.afterTrailingComma(g.parenR,!0)){u=!0;break}else if(this.type===g.ellipsis){f=this.start,l.push(this.parseParenItem(this.parseRestBinding())),this.type===g.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element");break}else l.push(this.parseMaybeAssign(!1,h,this.parseParenItem));var m=this.lastTokEnd,x=this.lastTokEndLoc;if(this.expect(g.parenR),t&&this.shouldParseArrow(l)&&this.eat(g.arrow))return this.checkPatternErrors(h,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=p,this.awaitPos=d,this.parseParenArrowList(r,n,l,e);(!l.length||u)&&this.unexpected(this.lastTokStart),f&&this.unexpected(f),this.checkExpressionErrors(h,!0),this.yieldPos=p||this.yieldPos,this.awaitPos=d||this.awaitPos,l.length>1?(i=this.startNodeAt(a,o),i.expressions=l,this.finishNodeAt(i,"SequenceExpression",m,x)):i=l[0]}else i=this.parseParenExpression();if(this.options.preserveParens){var b=this.startNodeAt(r,n);return b.expression=i,this.finishNode(b,"ParenthesizedExpression")}else return i};K.parseParenItem=function(t){return t};K.parseParenArrowList=function(t,e,r,n){return this.parseArrowExpression(this.startNodeAt(t,e),r,!1,n)};var Lg=[];K.parseNew=function(){this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword new");var t=this.startNode();if(this.next(),this.options.ecmaVersion>=6&&this.type===g.dot){var e=this.startNodeAt(t.start,t.loc&&t.loc.start);e.name="new",t.meta=this.finishNode(e,"Identifier"),this.next();var r=this.containsEsc;return t.property=this.parseIdent(!0),t.property.name!=="target"&&this.raiseRecoverable(t.property.start,"The only valid meta property for new is \'new.target\'"),r&&this.raiseRecoverable(t.start,"\'new.target\' must not contain escaped characters"),this.allowNewDotTarget||this.raiseRecoverable(t.start,"\'new.target\' can only be used in functions and class static block"),this.finishNode(t,"MetaProperty")}var n=this.start,i=this.startLoc;return t.callee=this.parseSubscripts(this.parseExprAtom(null,!1,!0),n,i,!0,!1),this.eat(g.parenL)?t.arguments=this.parseExprList(g.parenR,this.options.ecmaVersion>=8,!1):t.arguments=Lg,this.finishNode(t,"NewExpression")};K.parseTemplateElement=function(t){var e=t.isTagged,r=this.startNode();return this.type===g.invalidTemplate?(e||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),r.value={raw:this.value.replace(/\\r\\n?/g,`\n`),cooked:null}):r.value={raw:this.input.slice(this.start,this.end).replace(/\\r\\n?/g,`\n`),cooked:this.value},this.next(),r.tail=this.type===g.backQuote,this.finishNode(r,"TemplateElement")};K.parseTemplate=function(t){t===void 0&&(t={});var e=t.isTagged;e===void 0&&(e=!1);var r=this.startNode();this.next(),r.expressions=[];var n=this.parseTemplateElement({isTagged:e});for(r.quasis=[n];!n.tail;)this.type===g.eof&&this.raise(this.pos,"Unterminated template literal"),this.expect(g.dollarBraceL),r.expressions.push(this.parseExpression()),this.expect(g.braceR),r.quasis.push(n=this.parseTemplateElement({isTagged:e}));return this.next(),this.finishNode(r,"TemplateLiteral")};K.isAsyncProp=function(t){return!t.computed&&t.key.type==="Identifier"&&t.key.name==="async"&&(this.type===g.name||this.type===g.num||this.type===g.string||this.type===g.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===g.star)&&!ze.test(this.input.slice(this.lastTokEnd,this.start))};K.parseObj=function(t,e){var r=this.startNode(),n=!0,i={};for(r.properties=[],this.next();!this.eat(g.braceR);){if(n)n=!1;else if(this.expect(g.comma),this.options.ecmaVersion>=5&&this.afterTrailingComma(g.braceR))break;var s=this.parseProperty(t,e);t||this.checkPropClash(s,i,e),r.properties.push(s)}return this.finishNode(r,t?"ObjectPattern":"ObjectExpression")};K.parseProperty=function(t,e){var r=this.startNode(),n,i,s,a;if(this.options.ecmaVersion>=9&&this.eat(g.ellipsis))return t?(r.argument=this.parseIdent(!1),this.type===g.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.finishNode(r,"RestElement")):(r.argument=this.parseMaybeAssign(!1,e),this.type===g.comma&&e&&e.trailingComma<0&&(e.trailingComma=this.start),this.finishNode(r,"SpreadElement"));this.options.ecmaVersion>=6&&(r.method=!1,r.shorthand=!1,(t||e)&&(s=this.start,a=this.startLoc),t||(n=this.eat(g.star)));var o=this.containsEsc;return this.parsePropertyName(r),!t&&!o&&this.options.ecmaVersion>=8&&!n&&this.isAsyncProp(r)?(i=!0,n=this.options.ecmaVersion>=9&&this.eat(g.star),this.parsePropertyName(r)):i=!1,this.parsePropertyValue(r,t,n,i,s,a,e,o),this.finishNode(r,"Property")};K.parseGetterSetter=function(t){var e=t.key.name;this.parsePropertyName(t),t.value=this.parseMethod(!1),t.kind=e;var r=t.kind==="get"?0:1;if(t.value.params.length!==r){var n=t.value.start;t.kind==="get"?this.raiseRecoverable(n,"getter should have no params"):this.raiseRecoverable(n,"setter should have exactly one param")}else t.kind==="set"&&t.value.params[0].type==="RestElement"&&this.raiseRecoverable(t.value.params[0].start,"Setter cannot use rest params")};K.parsePropertyValue=function(t,e,r,n,i,s,a,o){(r||n)&&this.type===g.colon&&this.unexpected(),this.eat(g.colon)?(t.value=e?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,a),t.kind="init"):this.options.ecmaVersion>=6&&this.type===g.parenL?(e&&this.unexpected(),t.method=!0,t.value=this.parseMethod(r,n),t.kind="init"):!e&&!o&&this.options.ecmaVersion>=5&&!t.computed&&t.key.type==="Identifier"&&(t.key.name==="get"||t.key.name==="set")&&this.type!==g.comma&&this.type!==g.braceR&&this.type!==g.eq?((r||n)&&this.unexpected(),this.parseGetterSetter(t)):this.options.ecmaVersion>=6&&!t.computed&&t.key.type==="Identifier"?((r||n)&&this.unexpected(),this.checkUnreserved(t.key),t.key.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=i),e?t.value=this.parseMaybeDefault(i,s,this.copyNode(t.key)):this.type===g.eq&&a?(a.shorthandAssign<0&&(a.shorthandAssign=this.start),t.value=this.parseMaybeDefault(i,s,this.copyNode(t.key))):t.value=this.copyNode(t.key),t.kind="init",t.shorthand=!0):this.unexpected()};K.parsePropertyName=function(t){if(this.options.ecmaVersion>=6){if(this.eat(g.bracketL))return t.computed=!0,t.key=this.parseMaybeAssign(),this.expect(g.bracketR),t.key;t.computed=!1}return t.key=this.type===g.num||this.type===g.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never")};K.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)};K.parseMethod=function(t,e,r){var n=this.startNode(),i=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.initFunction(n),this.options.ecmaVersion>=6&&(n.generator=t),this.options.ecmaVersion>=8&&(n.async=!!e),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(ms(e,n.generator)|Un|(r?mo:0)),this.expect(g.parenL),n.params=this.parseBindingList(g.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(n,!1,!0,!1),this.yieldPos=i,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(n,"FunctionExpression")};K.parseArrowExpression=function(t,e,r,n){var i=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.enterScope(ms(r,!1)|fs),this.initFunction(t),this.options.ecmaVersion>=8&&(t.async=!!r),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,t.params=this.toAssignableList(e,!0),this.parseFunctionBody(t,!0,!1,n),this.yieldPos=i,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(t,"ArrowFunctionExpression")};K.parseFunctionBody=function(t,e,r,n){var i=e&&this.type!==g.braceL,s=this.strict,a=!1;if(i)t.body=this.parseMaybeAssign(n),t.expression=!0,this.checkParams(t,!1);else{var o=this.options.ecmaVersion>=7&&!this.isSimpleParamList(t.params);(!s||o)&&(a=this.strictDirective(this.end),a&&o&&this.raiseRecoverable(t.start,"Illegal \'use strict\' directive in function with non-simple parameter list"));var l=this.labels;this.labels=[],a&&(this.strict=!0),this.checkParams(t,!s&&!a&&!e&&!r&&this.isSimpleParamList(t.params)),this.strict&&t.id&&this.checkLValSimple(t.id,xo),t.body=this.parseBlock(!1,void 0,a&&!s),t.expression=!1,this.adaptDirectivePrologue(t.body.body),this.labels=l}this.exitScope()};K.isSimpleParamList=function(t){for(var e=0,r=t;e<r.length;e+=1){var n=r[e];if(n.type!=="Identifier")return!1}return!0};K.checkParams=function(t,e){for(var r=Object.create(null),n=0,i=t.params;n<i.length;n+=1){var s=i[n];this.checkLValInnerPattern(s,ys,e?null:r)}};K.parseExprList=function(t,e,r,n){for(var i=[],s=!0;!this.eat(t);){if(s)s=!1;else if(this.expect(g.comma),e&&this.afterTrailingComma(t))break;var a=void 0;r&&this.type===g.comma?a=null:this.type===g.ellipsis?(a=this.parseSpread(n),n&&this.type===g.comma&&n.trailingComma<0&&(n.trailingComma=this.start)):a=this.parseMaybeAssign(!1,n),i.push(a)}return i};K.checkUnreserved=function(t){var e=t.start,r=t.end,n=t.name;if(this.inGenerator&&n==="yield"&&this.raiseRecoverable(e,"Cannot use \'yield\' as identifier inside a generator"),this.inAsync&&n==="await"&&this.raiseRecoverable(e,"Cannot use \'await\' as identifier inside an async function"),!(this.currentThisScope().flags&qn)&&n==="arguments"&&this.raiseRecoverable(e,"Cannot use \'arguments\' in class field initializer"),this.inClassStaticBlock&&(n==="arguments"||n==="await")&&this.raise(e,"Cannot use "+n+" in class static initialization block"),this.keywords.test(n)&&this.raise(e,"Unexpected keyword \'"+n+"\'"),!(this.options.ecmaVersion<6&&this.input.slice(e,r).indexOf("\\\\")!==-1)){var i=this.strict?this.reservedWordsStrict:this.reservedWords;i.test(n)&&(!this.inAsync&&n==="await"&&this.raiseRecoverable(e,"Cannot use keyword \'await\' outside an async function"),this.raiseRecoverable(e,"The keyword \'"+n+"\' is reserved"))}};K.parseIdent=function(t){var e=this.parseIdentNode();return this.next(!!t),this.finishNode(e,"Identifier"),t||(this.checkUnreserved(e),e.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=e.start)),e};K.parseIdentNode=function(){var t=this.startNode();return this.type===g.name?t.name=this.value:this.type.keyword?(t.name=this.type.keyword,(t.name==="class"||t.name==="function")&&(this.lastTokEnd!==this.lastTokStart+1||this.input.charCodeAt(this.lastTokStart)!==46)&&this.context.pop(),this.type=g.name):this.unexpected(),t};K.parsePrivateIdent=function(){var t=this.startNode();return this.type===g.privateId?t.name=this.value:this.unexpected(),this.next(),this.finishNode(t,"PrivateIdentifier"),this.options.checkPrivateFields&&(this.privateNameStack.length===0?this.raise(t.start,"Private field \'#"+t.name+"\' must be declared in an enclosing class"):this.privateNameStack[this.privateNameStack.length-1].used.push(t)),t};K.parseYield=function(t){this.yieldPos||(this.yieldPos=this.start);var e=this.startNode();return this.next(),this.type===g.semi||this.canInsertSemicolon()||this.type!==g.star&&!this.type.startsExpr?(e.delegate=!1,e.argument=null):(e.delegate=this.eat(g.star),e.argument=this.parseMaybeAssign(t)),this.finishNode(e,"YieldExpression")};K.parseAwait=function(t){this.awaitPos||(this.awaitPos=this.start);var e=this.startNode();return this.next(),e.argument=this.parseMaybeUnary(null,!0,!1,t),this.finishNode(e,"AwaitExpression")};var En=Ie.prototype;En.raise=function(t,e){var r=po(this.input,t);e+=" ("+r.line+":"+r.column+")",this.sourceFile&&(e+=" in "+this.sourceFile);var n=new SyntaxError(e);throw n.pos=t,n.loc=r,n.raisedAt=this.pos,n};En.raiseRecoverable=En.raise;En.curPosition=function(){if(this.options.locations)return new Vr(this.curLine,this.pos-this.lineStart)};var Ut=Ie.prototype,Og=function(t){this.flags=t,this.var=[],this.lexical=[],this.functions=[]};Ut.enterScope=function(t){this.scopeStack.push(new Og(t))};Ut.exitScope=function(){this.scopeStack.pop()};Ut.treatFunctionsAsVarInScope=function(t){return t.flags&Jt||!this.inModule&&t.flags&Xt};Ut.declareName=function(t,e,r){var n=!1;if(e===Rt){var i=this.currentScope();n=i.lexical.indexOf(t)>-1||i.functions.indexOf(t)>-1||i.var.indexOf(t)>-1,i.lexical.push(t),this.inModule&&i.flags&Xt&&delete this.undefinedExports[t]}else if(e===_o){var s=this.currentScope();s.lexical.push(t)}else if(e===go){var a=this.currentScope();this.treatFunctionsAsVar?n=a.lexical.indexOf(t)>-1:n=a.lexical.indexOf(t)>-1||a.var.indexOf(t)>-1,a.functions.push(t)}else for(var o=this.scopeStack.length-1;o>=0;--o){var l=this.scopeStack[o];if(l.lexical.indexOf(t)>-1&&!(l.flags&fo&&l.lexical[0]===t)||!this.treatFunctionsAsVarInScope(l)&&l.functions.indexOf(t)>-1){n=!0;break}if(l.var.push(t),this.inModule&&l.flags&Xt&&delete this.undefinedExports[t],l.flags&qn)break}n&&this.raiseRecoverable(r,"Identifier \'"+t+"\' has already been declared")};Ut.checkLocalExport=function(t){this.scopeStack[0].lexical.indexOf(t.name)===-1&&this.scopeStack[0].var.indexOf(t.name)===-1&&(this.undefinedExports[t.name]=t)};Ut.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]};Ut.currentVarScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(qn|Wr|er))return e}};Ut.currentThisScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(qn|Wr|er)&&!(e.flags&fs))return e}};var Kn=function(t,e,r){this.type="",this.start=e,this.end=0,t.options.locations&&(this.loc=new Wn(t,r)),t.options.directSourceFile&&(this.sourceFile=t.options.directSourceFile),t.options.ranges&&(this.range=[e,0])},Ur=Ie.prototype;Ur.startNode=function(){return new Kn(this,this.start,this.startLoc)};Ur.startNodeAt=function(t,e){return new Kn(this,t,e)};function wo(t,e,r,n){return t.type=e,t.end=r,this.options.locations&&(t.loc.end=n),this.options.ranges&&(t.range[1]=r),t}Ur.finishNode=function(t,e){return wo.call(this,t,e,this.lastTokEnd,this.lastTokEndLoc)};Ur.finishNodeAt=function(t,e,r,n){return wo.call(this,t,e,r,n)};Ur.copyNode=function(t){var e=new Kn(this,t.start,this.startLoc);for(var r in t)e[r]=t[r];return e};var Vg="Berf Beria_Erfe Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sidetic Sidt Sunu Sunuwar Tai_Yo Tayo Todhri Todr Tolong_Siki Tols Tulu_Tigalari Tutg Unknown Zzzz",Eo="ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS",So=Eo+" Extended_Pictographic",Co=So,No=Co+" EBase EComp EMod EPres ExtPict",ko=No,jg=ko,$g={9:Eo,10:So,11:Co,12:No,13:ko,14:jg},Wg="Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji",Ug={9:"",10:"",11:"",12:"",13:"",14:Wg},ia="Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu",Io="Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb",Ao=Io+" Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd",To=Ao+" Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho",Do=To+" Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi",Mo=Do+" Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith",qg=Mo+" "+Vg,zg={9:Io,10:Ao,11:To,12:Do,13:Mo,14:qg},Po={};function Kg(t){var e=Po[t]={binary:Bt($g[t]+" "+ia),binaryOfStrings:Bt(Ug[t]),nonBinary:{General_Category:Bt(ia),Script:Bt(zg[t])}};e.nonBinary.Script_Extensions=e.nonBinary.Script,e.nonBinary.gc=e.nonBinary.General_Category,e.nonBinary.sc=e.nonBinary.Script,e.nonBinary.scx=e.nonBinary.Script_Extensions}for(Zr=0,ai=[9,10,11,12,13,14];Zr<ai.length;Zr+=1)sa=ai[Zr],Kg(sa);var sa,Zr,ai,B=Ie.prototype,Sn=function(t,e){this.parent=t,this.base=e||this};Sn.prototype.separatedFrom=function(t){for(var e=this;e;e=e.parent)for(var r=t;r;r=r.parent)if(e.base===r.base&&e!==r)return!0;return!1};Sn.prototype.sibling=function(){return new Sn(this.parent,this.base)};var kt=function(t){this.parser=t,this.validFlags="gim"+(t.options.ecmaVersion>=6?"uy":"")+(t.options.ecmaVersion>=9?"s":"")+(t.options.ecmaVersion>=13?"d":"")+(t.options.ecmaVersion>=15?"v":""),this.unicodeProperties=Po[t.options.ecmaVersion>=14?14:t.options.ecmaVersion],this.source="",this.flags="",this.start=0,this.switchU=!1,this.switchV=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue="",this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=Object.create(null),this.backReferenceNames=[],this.branchID=null};kt.prototype.reset=function(t,e,r){var n=r.indexOf("v")!==-1,i=r.indexOf("u")!==-1;this.start=t|0,this.source=e+"",this.flags=r,n&&this.parser.options.ecmaVersion>=15?(this.switchU=!0,this.switchV=!0,this.switchN=!0):(this.switchU=i&&this.parser.options.ecmaVersion>=6,this.switchV=!1,this.switchN=i&&this.parser.options.ecmaVersion>=9)};kt.prototype.raise=function(t){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+t)};kt.prototype.at=function(t,e){e===void 0&&(e=!1);var r=this.source,n=r.length;if(t>=n)return-1;var i=r.charCodeAt(t);if(!(e||this.switchU)||i<=55295||i>=57344||t+1>=n)return i;var s=r.charCodeAt(t+1);return s>=56320&&s<=57343?(i<<10)+s-56613888:i};kt.prototype.nextIndex=function(t,e){e===void 0&&(e=!1);var r=this.source,n=r.length;if(t>=n)return n;var i=r.charCodeAt(t),s;return!(e||this.switchU)||i<=55295||i>=57344||t+1>=n||(s=r.charCodeAt(t+1))<56320||s>57343?t+1:t+2};kt.prototype.current=function(t){return t===void 0&&(t=!1),this.at(this.pos,t)};kt.prototype.lookahead=function(t){return t===void 0&&(t=!1),this.at(this.nextIndex(this.pos,t),t)};kt.prototype.advance=function(t){t===void 0&&(t=!1),this.pos=this.nextIndex(this.pos,t)};kt.prototype.eat=function(t,e){return e===void 0&&(e=!1),this.current(e)===t?(this.advance(e),!0):!1};kt.prototype.eatChars=function(t,e){e===void 0&&(e=!1);for(var r=this.pos,n=0,i=t;n<i.length;n+=1){var s=i[n],a=this.at(r,e);if(a===-1||a!==s)return!1;r=this.nextIndex(r,e)}return this.pos=r,!0};B.validateRegExpFlags=function(t){for(var e=t.validFlags,r=t.flags,n=!1,i=!1,s=0;s<r.length;s++){var a=r.charAt(s);e.indexOf(a)===-1&&this.raise(t.start,"Invalid regular expression flag"),r.indexOf(a,s+1)>-1&&this.raise(t.start,"Duplicate regular expression flag"),a==="u"&&(n=!0),a==="v"&&(i=!0)}this.options.ecmaVersion>=15&&n&&i&&this.raise(t.start,"Invalid regular expression flag")};function Hg(t){for(var e in t)return!0;return!1}B.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&Hg(t.groupNames)&&(t.switchN=!0,this.regexp_pattern(t))};B.regexp_pattern=function(t){t.pos=0,t.lastIntValue=0,t.lastStringValue="",t.lastAssertionIsQuantifiable=!1,t.numCapturingParens=0,t.maxBackReference=0,t.groupNames=Object.create(null),t.backReferenceNames.length=0,t.branchID=null,this.regexp_disjunction(t),t.pos!==t.source.length&&(t.eat(41)&&t.raise("Unmatched \')\'"),(t.eat(93)||t.eat(125))&&t.raise("Lone quantifier brackets")),t.maxBackReference>t.numCapturingParens&&t.raise("Invalid escape");for(var e=0,r=t.backReferenceNames;e<r.length;e+=1){var n=r[e];t.groupNames[n]||t.raise("Invalid named capture referenced")}};B.regexp_disjunction=function(t){var e=this.options.ecmaVersion>=16;for(e&&(t.branchID=new Sn(t.branchID,null)),this.regexp_alternative(t);t.eat(124);)e&&(t.branchID=t.branchID.sibling()),this.regexp_alternative(t);e&&(t.branchID=t.branchID.parent),this.regexp_eatQuantifier(t,!0)&&t.raise("Nothing to repeat"),t.eat(123)&&t.raise("Lone quantifier brackets")};B.regexp_alternative=function(t){for(;t.pos<t.source.length&&this.regexp_eatTerm(t););};B.regexp_eatTerm=function(t){return this.regexp_eatAssertion(t)?(t.lastAssertionIsQuantifiable&&this.regexp_eatQuantifier(t)&&t.switchU&&t.raise("Invalid quantifier"),!0):(t.switchU?this.regexp_eatAtom(t):this.regexp_eatExtendedAtom(t))?(this.regexp_eatQuantifier(t),!0):!1};B.regexp_eatAssertion=function(t){var e=t.pos;if(t.lastAssertionIsQuantifiable=!1,t.eat(94)||t.eat(36))return!0;if(t.eat(92)){if(t.eat(66)||t.eat(98))return!0;t.pos=e}if(t.eat(40)&&t.eat(63)){var r=!1;if(this.options.ecmaVersion>=9&&(r=t.eat(60)),t.eat(61)||t.eat(33))return this.regexp_disjunction(t),t.eat(41)||t.raise("Unterminated group"),t.lastAssertionIsQuantifiable=!r,!0}return t.pos=e,!1};B.regexp_eatQuantifier=function(t,e){return e===void 0&&(e=!1),this.regexp_eatQuantifierPrefix(t,e)?(t.eat(63),!0):!1};B.regexp_eatQuantifierPrefix=function(t,e){return t.eat(42)||t.eat(43)||t.eat(63)||this.regexp_eatBracedQuantifier(t,e)};B.regexp_eatBracedQuantifier=function(t,e){var r=t.pos;if(t.eat(123)){var n=0,i=-1;if(this.regexp_eatDecimalDigits(t)&&(n=t.lastIntValue,t.eat(44)&&this.regexp_eatDecimalDigits(t)&&(i=t.lastIntValue),t.eat(125)))return i!==-1&&i<n&&!e&&t.raise("numbers out of order in {} quantifier"),!0;t.switchU&&!e&&t.raise("Incomplete quantifier"),t.pos=r}return!1};B.regexp_eatAtom=function(t){return this.regexp_eatPatternCharacters(t)||t.eat(46)||this.regexp_eatReverseSolidusAtomEscape(t)||this.regexp_eatCharacterClass(t)||this.regexp_eatUncapturingGroup(t)||this.regexp_eatCapturingGroup(t)};B.regexp_eatReverseSolidusAtomEscape=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatAtomEscape(t))return!0;t.pos=e}return!1};B.regexp_eatUncapturingGroup=function(t){var e=t.pos;if(t.eat(40)){if(t.eat(63)){if(this.options.ecmaVersion>=16){var r=this.regexp_eatModifiers(t),n=t.eat(45);if(r||n){for(var i=0;i<r.length;i++){var s=r.charAt(i);r.indexOf(s,i+1)>-1&&t.raise("Duplicate regular expression modifiers")}if(n){var a=this.regexp_eatModifiers(t);!r&&!a&&t.current()===58&&t.raise("Invalid regular expression modifiers");for(var o=0;o<a.length;o++){var l=a.charAt(o);(a.indexOf(l,o+1)>-1||r.indexOf(l)>-1)&&t.raise("Duplicate regular expression modifiers")}}}}if(t.eat(58)){if(this.regexp_disjunction(t),t.eat(41))return!0;t.raise("Unterminated group")}}t.pos=e}return!1};B.regexp_eatCapturingGroup=function(t){if(t.eat(40)){if(this.options.ecmaVersion>=9?this.regexp_groupSpecifier(t):t.current()===63&&t.raise("Invalid group"),this.regexp_disjunction(t),t.eat(41))return t.numCapturingParens+=1,!0;t.raise("Unterminated group")}return!1};B.regexp_eatModifiers=function(t){for(var e="",r=0;(r=t.current())!==-1&&Gg(r);)e+=Mt(r),t.advance();return e};function Gg(t){return t===105||t===109||t===115}B.regexp_eatExtendedAtom=function(t){return t.eat(46)||this.regexp_eatReverseSolidusAtomEscape(t)||this.regexp_eatCharacterClass(t)||this.regexp_eatUncapturingGroup(t)||this.regexp_eatCapturingGroup(t)||this.regexp_eatInvalidBracedQuantifier(t)||this.regexp_eatExtendedPatternCharacter(t)};B.regexp_eatInvalidBracedQuantifier=function(t){return this.regexp_eatBracedQuantifier(t,!0)&&t.raise("Nothing to repeat"),!1};B.regexp_eatSyntaxCharacter=function(t){var e=t.current();return Ro(e)?(t.lastIntValue=e,t.advance(),!0):!1};function Ro(t){return t===36||t>=40&&t<=43||t===46||t===63||t>=91&&t<=94||t>=123&&t<=125}B.regexp_eatPatternCharacters=function(t){for(var e=t.pos,r=0;(r=t.current())!==-1&&!Ro(r);)t.advance();return t.pos!==e};B.regexp_eatExtendedPatternCharacter=function(t){var e=t.current();return e!==-1&&e!==36&&!(e>=40&&e<=43)&&e!==46&&e!==63&&e!==91&&e!==94&&e!==124?(t.advance(),!0):!1};B.regexp_groupSpecifier=function(t){if(t.eat(63)){this.regexp_eatGroupName(t)||t.raise("Invalid group");var e=this.options.ecmaVersion>=16,r=t.groupNames[t.lastStringValue];if(r)if(e)for(var n=0,i=r;n<i.length;n+=1){var s=i[n];s.separatedFrom(t.branchID)||t.raise("Duplicate capture group name")}else t.raise("Duplicate capture group name");e?(r||(t.groupNames[t.lastStringValue]=[])).push(t.branchID):t.groupNames[t.lastStringValue]=!0}};B.regexp_eatGroupName=function(t){if(t.lastStringValue="",t.eat(60)){if(this.regexp_eatRegExpIdentifierName(t)&&t.eat(62))return!0;t.raise("Invalid capture group name")}return!1};B.regexp_eatRegExpIdentifierName=function(t){if(t.lastStringValue="",this.regexp_eatRegExpIdentifierStart(t)){for(t.lastStringValue+=Mt(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=Mt(t.lastIntValue);return!0}return!1};B.regexp_eatRegExpIdentifierStart=function(t){var e=t.pos,r=this.options.ecmaVersion>=11,n=t.current(r);return t.advance(r),n===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,r)&&(n=t.lastIntValue),Yg(n)?(t.lastIntValue=n,!0):(t.pos=e,!1)};function Yg(t){return Nt(t,!0)||t===36||t===95}B.regexp_eatRegExpIdentifierPart=function(t){var e=t.pos,r=this.options.ecmaVersion>=11,n=t.current(r);return t.advance(r),n===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,r)&&(n=t.lastIntValue),Zg(n)?(t.lastIntValue=n,!0):(t.pos=e,!1)};function Zg(t){return jt(t,!0)||t===36||t===95||t===8204||t===8205}B.regexp_eatAtomEscape=function(t){return this.regexp_eatBackReference(t)||this.regexp_eatCharacterClassEscape(t)||this.regexp_eatCharacterEscape(t)||t.switchN&&this.regexp_eatKGroupName(t)?!0:(t.switchU&&(t.current()===99&&t.raise("Invalid unicode escape"),t.raise("Invalid escape")),!1)};B.regexp_eatBackReference=function(t){var e=t.pos;if(this.regexp_eatDecimalEscape(t)){var r=t.lastIntValue;if(t.switchU)return r>t.maxBackReference&&(t.maxBackReference=r),!0;if(r<=t.numCapturingParens)return!0;t.pos=e}return!1};B.regexp_eatKGroupName=function(t){if(t.eat(107)){if(this.regexp_eatGroupName(t))return t.backReferenceNames.push(t.lastStringValue),!0;t.raise("Invalid named reference")}return!1};B.regexp_eatCharacterEscape=function(t){return this.regexp_eatControlEscape(t)||this.regexp_eatCControlLetter(t)||this.regexp_eatZero(t)||this.regexp_eatHexEscapeSequence(t)||this.regexp_eatRegExpUnicodeEscapeSequence(t,!1)||!t.switchU&&this.regexp_eatLegacyOctalEscapeSequence(t)||this.regexp_eatIdentityEscape(t)};B.regexp_eatCControlLetter=function(t){var e=t.pos;if(t.eat(99)){if(this.regexp_eatControlLetter(t))return!0;t.pos=e}return!1};B.regexp_eatZero=function(t){return t.current()===48&&!Hn(t.lookahead())?(t.lastIntValue=0,t.advance(),!0):!1};B.regexp_eatControlEscape=function(t){var e=t.current();return e===116?(t.lastIntValue=9,t.advance(),!0):e===110?(t.lastIntValue=10,t.advance(),!0):e===118?(t.lastIntValue=11,t.advance(),!0):e===102?(t.lastIntValue=12,t.advance(),!0):e===114?(t.lastIntValue=13,t.advance(),!0):!1};B.regexp_eatControlLetter=function(t){var e=t.current();return Fo(e)?(t.lastIntValue=e%32,t.advance(),!0):!1};function Fo(t){return t>=65&&t<=90||t>=97&&t<=122}B.regexp_eatRegExpUnicodeEscapeSequence=function(t,e){e===void 0&&(e=!1);var r=t.pos,n=e||t.switchU;if(t.eat(117)){if(this.regexp_eatFixedHexDigits(t,4)){var i=t.lastIntValue;if(n&&i>=55296&&i<=56319){var s=t.pos;if(t.eat(92)&&t.eat(117)&&this.regexp_eatFixedHexDigits(t,4)){var a=t.lastIntValue;if(a>=56320&&a<=57343)return t.lastIntValue=(i-55296)*1024+(a-56320)+65536,!0}t.pos=s,t.lastIntValue=i}return!0}if(n&&t.eat(123)&&this.regexp_eatHexDigits(t)&&t.eat(125)&&Xg(t.lastIntValue))return!0;n&&t.raise("Invalid unicode escape"),t.pos=r}return!1};function Xg(t){return t>=0&&t<=1114111}B.regexp_eatIdentityEscape=function(t){if(t.switchU)return this.regexp_eatSyntaxCharacter(t)?!0:t.eat(47)?(t.lastIntValue=47,!0):!1;var e=t.current();return e!==99&&(!t.switchN||e!==107)?(t.lastIntValue=e,t.advance(),!0):!1};B.regexp_eatDecimalEscape=function(t){t.lastIntValue=0;var e=t.current();if(e>=49&&e<=57){do t.lastIntValue=10*t.lastIntValue+(e-48),t.advance();while((e=t.current())>=48&&e<=57);return!0}return!1};var Bo=0,Pt=1,nt=2;B.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(Qg(e))return t.lastIntValue=-1,t.advance(),Pt;var r=!1;if(t.switchU&&this.options.ecmaVersion>=9&&((r=e===80)||e===112)){t.lastIntValue=-1,t.advance();var n;if(t.eat(123)&&(n=this.regexp_eatUnicodePropertyValueExpression(t))&&t.eat(125))return r&&n===nt&&t.raise("Invalid property name"),n;t.raise("Invalid property name")}return Bo};function Qg(t){return t===100||t===68||t===115||t===83||t===119||t===87}B.regexp_eatUnicodePropertyValueExpression=function(t){var e=t.pos;if(this.regexp_eatUnicodePropertyName(t)&&t.eat(61)){var r=t.lastStringValue;if(this.regexp_eatUnicodePropertyValue(t)){var n=t.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(t,r,n),Pt}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var i=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,i)}return Bo};B.regexp_validateUnicodePropertyNameAndValue=function(t,e,r){_r(t.unicodeProperties.nonBinary,e)||t.raise("Invalid property name"),t.unicodeProperties.nonBinary[e].test(r)||t.raise("Invalid property value")};B.regexp_validateUnicodePropertyNameOrValue=function(t,e){if(t.unicodeProperties.binary.test(e))return Pt;if(t.switchV&&t.unicodeProperties.binaryOfStrings.test(e))return nt;t.raise("Invalid property name")};B.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";Lo(e=t.current());)t.lastStringValue+=Mt(e),t.advance();return t.lastStringValue!==""};function Lo(t){return Fo(t)||t===95}B.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";Jg(e=t.current());)t.lastStringValue+=Mt(e),t.advance();return t.lastStringValue!==""};function Jg(t){return Lo(t)||Hn(t)}B.regexp_eatLoneUnicodePropertyNameOrValue=function(t){return this.regexp_eatUnicodePropertyValue(t)};B.regexp_eatCharacterClass=function(t){if(t.eat(91)){var e=t.eat(94),r=this.regexp_classContents(t);return t.eat(93)||t.raise("Unterminated character class"),e&&r===nt&&t.raise("Negated character class may contain strings"),!0}return!1};B.regexp_classContents=function(t){return t.current()===93?Pt:t.switchV?this.regexp_classSetExpression(t):(this.regexp_nonEmptyClassRanges(t),Pt)};B.regexp_nonEmptyClassRanges=function(t){for(;this.regexp_eatClassAtom(t);){var e=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassAtom(t)){var r=t.lastIntValue;t.switchU&&(e===-1||r===-1)&&t.raise("Invalid character class"),e!==-1&&r!==-1&&e>r&&t.raise("Range out of order in character class")}}};B.regexp_eatClassAtom=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatClassEscape(t))return!0;if(t.switchU){var r=t.current();(r===99||jo(r))&&t.raise("Invalid class escape"),t.raise("Invalid escape")}t.pos=e}var n=t.current();return n!==93?(t.lastIntValue=n,t.advance(),!0):!1};B.regexp_eatClassEscape=function(t){var e=t.pos;if(t.eat(98))return t.lastIntValue=8,!0;if(t.switchU&&t.eat(45))return t.lastIntValue=45,!0;if(!t.switchU&&t.eat(99)){if(this.regexp_eatClassControlLetter(t))return!0;t.pos=e}return this.regexp_eatCharacterClassEscape(t)||this.regexp_eatCharacterEscape(t)};B.regexp_classSetExpression=function(t){var e=Pt,r;if(!this.regexp_eatClassSetRange(t))if(r=this.regexp_eatClassSetOperand(t)){r===nt&&(e=nt);for(var n=t.pos;t.eatChars([38,38]);){if(t.current()!==38&&(r=this.regexp_eatClassSetOperand(t))){r!==nt&&(e=Pt);continue}t.raise("Invalid character in character class")}if(n!==t.pos)return e;for(;t.eatChars([45,45]);)this.regexp_eatClassSetOperand(t)||t.raise("Invalid character in character class");if(n!==t.pos)return e}else t.raise("Invalid character in character class");for(;;)if(!this.regexp_eatClassSetRange(t)){if(r=this.regexp_eatClassSetOperand(t),!r)return e;r===nt&&(e=nt)}};B.regexp_eatClassSetRange=function(t){var e=t.pos;if(this.regexp_eatClassSetCharacter(t)){var r=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassSetCharacter(t)){var n=t.lastIntValue;return r!==-1&&n!==-1&&r>n&&t.raise("Range out of order in character class"),!0}t.pos=e}return!1};B.regexp_eatClassSetOperand=function(t){return this.regexp_eatClassSetCharacter(t)?Pt:this.regexp_eatClassStringDisjunction(t)||this.regexp_eatNestedClass(t)};B.regexp_eatNestedClass=function(t){var e=t.pos;if(t.eat(91)){var r=t.eat(94),n=this.regexp_classContents(t);if(t.eat(93))return r&&n===nt&&t.raise("Negated character class may contain strings"),n;t.pos=e}if(t.eat(92)){var i=this.regexp_eatCharacterClassEscape(t);if(i)return i;t.pos=e}return null};B.regexp_eatClassStringDisjunction=function(t){var e=t.pos;if(t.eatChars([92,113])){if(t.eat(123)){var r=this.regexp_classStringDisjunctionContents(t);if(t.eat(125))return r}else t.raise("Invalid escape");t.pos=e}return null};B.regexp_classStringDisjunctionContents=function(t){for(var e=this.regexp_classString(t);t.eat(124);)this.regexp_classString(t)===nt&&(e=nt);return e};B.regexp_classString=function(t){for(var e=0;this.regexp_eatClassSetCharacter(t);)e++;return e===1?Pt:nt};B.regexp_eatClassSetCharacter=function(t){var e=t.pos;if(t.eat(92))return this.regexp_eatCharacterEscape(t)||this.regexp_eatClassSetReservedPunctuator(t)?!0:t.eat(98)?(t.lastIntValue=8,!0):(t.pos=e,!1);var r=t.current();return r<0||r===t.lookahead()&&e_(r)||t_(r)?!1:(t.advance(),t.lastIntValue=r,!0)};function e_(t){return t===33||t>=35&&t<=38||t>=42&&t<=44||t===46||t>=58&&t<=64||t===94||t===96||t===126}function t_(t){return t===40||t===41||t===45||t===47||t>=91&&t<=93||t>=123&&t<=125}B.regexp_eatClassSetReservedPunctuator=function(t){var e=t.current();return r_(e)?(t.lastIntValue=e,t.advance(),!0):!1};function r_(t){return t===33||t===35||t===37||t===38||t===44||t===45||t>=58&&t<=62||t===64||t===96||t===126}B.regexp_eatClassControlLetter=function(t){var e=t.current();return Hn(e)||e===95?(t.lastIntValue=e%32,t.advance(),!0):!1};B.regexp_eatHexEscapeSequence=function(t){var e=t.pos;if(t.eat(120)){if(this.regexp_eatFixedHexDigits(t,2))return!0;t.switchU&&t.raise("Invalid escape"),t.pos=e}return!1};B.regexp_eatDecimalDigits=function(t){var e=t.pos,r=0;for(t.lastIntValue=0;Hn(r=t.current());)t.lastIntValue=10*t.lastIntValue+(r-48),t.advance();return t.pos!==e};function Hn(t){return t>=48&&t<=57}B.regexp_eatHexDigits=function(t){var e=t.pos,r=0;for(t.lastIntValue=0;Oo(r=t.current());)t.lastIntValue=16*t.lastIntValue+Vo(r),t.advance();return t.pos!==e};function Oo(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function Vo(t){return t>=65&&t<=70?10+(t-65):t>=97&&t<=102?10+(t-97):t-48}B.regexp_eatLegacyOctalEscapeSequence=function(t){if(this.regexp_eatOctalDigit(t)){var e=t.lastIntValue;if(this.regexp_eatOctalDigit(t)){var r=t.lastIntValue;e<=3&&this.regexp_eatOctalDigit(t)?t.lastIntValue=e*64+r*8+t.lastIntValue:t.lastIntValue=e*8+r}else t.lastIntValue=e;return!0}return!1};B.regexp_eatOctalDigit=function(t){var e=t.current();return jo(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)};function jo(t){return t>=48&&t<=55}B.regexp_eatFixedHexDigits=function(t,e){var r=t.pos;t.lastIntValue=0;for(var n=0;n<e;++n){var i=t.current();if(!Oo(i))return t.pos=r,!1;t.lastIntValue=16*t.lastIntValue+Vo(i),t.advance()}return!0};var _s=function(t){this.type=t.type,this.value=t.value,this.start=t.start,this.end=t.end,t.options.locations&&(this.loc=new Wn(t,t.startLoc,t.endLoc)),t.options.ranges&&(this.range=[t.start,t.end])},X=Ie.prototype;X.next=function(t){!t&&this.type.keyword&&this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword "+this.type.keyword),this.options.onToken&&this.options.onToken(new _s(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()};X.getToken=function(){return this.next(),new _s(this)};typeof Symbol<"u"&&(X[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===g.eof,value:e}}}});X.nextToken=function(){var t=this.curContext();if((!t||!t.preserveSpace)&&this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length)return this.finishToken(g.eof);if(t.override)return t.override(this);this.readToken(this.fullCharCodeAtPos())};X.readToken=function(t){return Nt(t,this.options.ecmaVersion>=6)||t===92?this.readWord():this.getTokenFromCode(t)};X.fullCharCodeAt=function(t){var e=this.input.charCodeAt(t);if(e<=55295||e>=56320)return e;var r=this.input.charCodeAt(t+1);return r<=56319||r>=57344?e:(e<<10)+r-56613888};X.fullCharCodeAtPos=function(){return this.fullCharCodeAt(this.pos)};X.skipBlockComment=function(){var t=this.options.onComment&&this.curPosition(),e=this.pos,r=this.input.indexOf("*/",this.pos+=2);if(r===-1&&this.raise(this.pos-2,"Unterminated comment"),this.pos=r+2,this.options.locations)for(var n=void 0,i=e;(n=lo(this.input,i,this.pos))>-1;)++this.curLine,i=this.lineStart=n;this.options.onComment&&this.options.onComment(!0,this.input.slice(e+2,r),e,this.pos,t,this.curPosition())};X.skipLineComment=function(t){for(var e=this.pos,r=this.options.onComment&&this.curPosition(),n=this.input.charCodeAt(this.pos+=t);this.pos<this.input.length&&!gr(n);)n=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(e+t,this.pos),e,this.pos,r,this.curPosition())};X.skipSpace=function(){e:for(;this.pos<this.input.length;){var t=this.input.charCodeAt(this.pos);switch(t){case 32:case 160:++this.pos;break;case 13:this.input.charCodeAt(this.pos+1)===10&&++this.pos;case 10:case 8232:case 8233:++this.pos,this.options.locations&&(++this.curLine,this.lineStart=this.pos);break;case 47:switch(this.input.charCodeAt(this.pos+1)){case 42:this.skipBlockComment();break;case 47:this.skipLineComment(2);break;default:break e}break;default:if(t>8&&t<14||t>=5760&&co.test(String.fromCharCode(t)))++this.pos;else break e}}};X.finishToken=function(t,e){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var r=this.type;this.type=t,this.value=e,this.updateContext(r)};X.readToken_dot=function(){var t=this.input.charCodeAt(this.pos+1);if(t>=48&&t<=57)return this.readNumber(!0);var e=this.input.charCodeAt(this.pos+2);return this.options.ecmaVersion>=6&&t===46&&e===46?(this.pos+=3,this.finishToken(g.ellipsis)):(++this.pos,this.finishToken(g.dot))};X.readToken_slash=function(){var t=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):t===61?this.finishOp(g.assign,2):this.finishOp(g.slash,1)};X.readToken_mult_modulo_exp=function(t){var e=this.input.charCodeAt(this.pos+1),r=1,n=t===42?g.star:g.modulo;return this.options.ecmaVersion>=7&&t===42&&e===42&&(++r,n=g.starstar,e=this.input.charCodeAt(this.pos+2)),e===61?this.finishOp(g.assign,r+1):this.finishOp(n,r)};X.readToken_pipe_amp=function(t){var e=this.input.charCodeAt(this.pos+1);if(e===t){if(this.options.ecmaVersion>=12){var r=this.input.charCodeAt(this.pos+2);if(r===61)return this.finishOp(g.assign,3)}return this.finishOp(t===124?g.logicalOR:g.logicalAND,2)}return e===61?this.finishOp(g.assign,2):this.finishOp(t===124?g.bitwiseOR:g.bitwiseAND,1)};X.readToken_caret=function(){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(g.assign,2):this.finishOp(g.bitwiseXOR,1)};X.readToken_plus_min=function(t){var e=this.input.charCodeAt(this.pos+1);return e===t?e===45&&!this.inModule&&this.input.charCodeAt(this.pos+2)===62&&(this.lastTokEnd===0||ze.test(this.input.slice(this.lastTokEnd,this.pos)))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(g.incDec,2):e===61?this.finishOp(g.assign,2):this.finishOp(g.plusMin,1)};X.readToken_lt_gt=function(t){var e=this.input.charCodeAt(this.pos+1),r=1;return e===t?(r=t===62&&this.input.charCodeAt(this.pos+2)===62?3:2,this.input.charCodeAt(this.pos+r)===61?this.finishOp(g.assign,r+1):this.finishOp(g.bitShift,r)):e===33&&t===60&&!this.inModule&&this.input.charCodeAt(this.pos+2)===45&&this.input.charCodeAt(this.pos+3)===45?(this.skipLineComment(4),this.skipSpace(),this.nextToken()):(e===61&&(r=2),this.finishOp(g.relational,r))};X.readToken_eq_excl=function(t){var e=this.input.charCodeAt(this.pos+1);return e===61?this.finishOp(g.equality,this.input.charCodeAt(this.pos+2)===61?3:2):t===61&&e===62&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(g.arrow)):this.finishOp(t===61?g.eq:g.prefix,1)};X.readToken_question=function(){var t=this.options.ecmaVersion;if(t>=11){var e=this.input.charCodeAt(this.pos+1);if(e===46){var r=this.input.charCodeAt(this.pos+2);if(r<48||r>57)return this.finishOp(g.questionDot,2)}if(e===63){if(t>=12){var n=this.input.charCodeAt(this.pos+2);if(n===61)return this.finishOp(g.assign,3)}return this.finishOp(g.coalesce,2)}}return this.finishOp(g.question,1)};X.readToken_numberSign=function(){var t=this.options.ecmaVersion,e=35;if(t>=13&&(++this.pos,e=this.fullCharCodeAtPos(),Nt(e,!0)||e===92))return this.finishToken(g.privateId,this.readWord1());this.raise(this.pos,"Unexpected character \'"+Mt(e)+"\'")};X.getTokenFromCode=function(t){switch(t){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(g.parenL);case 41:return++this.pos,this.finishToken(g.parenR);case 59:return++this.pos,this.finishToken(g.semi);case 44:return++this.pos,this.finishToken(g.comma);case 91:return++this.pos,this.finishToken(g.bracketL);case 93:return++this.pos,this.finishToken(g.bracketR);case 123:return++this.pos,this.finishToken(g.braceL);case 125:return++this.pos,this.finishToken(g.braceR);case 58:return++this.pos,this.finishToken(g.colon);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(g.backQuote);case 48:var e=this.input.charCodeAt(this.pos+1);if(e===120||e===88)return this.readRadixNumber(16);if(this.options.ecmaVersion>=6){if(e===111||e===79)return this.readRadixNumber(8);if(e===98||e===66)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(t);case 47:return this.readToken_slash();case 37:case 42:return this.readToken_mult_modulo_exp(t);case 124:case 38:return this.readToken_pipe_amp(t);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(t);case 60:case 62:return this.readToken_lt_gt(t);case 61:case 33:return this.readToken_eq_excl(t);case 63:return this.readToken_question();case 126:return this.finishOp(g.prefix,1);case 35:return this.readToken_numberSign()}this.raise(this.pos,"Unexpected character \'"+Mt(t)+"\'")};X.finishOp=function(t,e){var r=this.input.slice(this.pos,this.pos+e);return this.pos+=e,this.finishToken(t,r)};X.readRegexp=function(){for(var t,e,r=this.pos;;){this.pos>=this.input.length&&this.raise(r,"Unterminated regular expression");var n=this.input.charAt(this.pos);if(ze.test(n)&&this.raise(r,"Unterminated regular expression"),t)t=!1;else{if(n==="[")e=!0;else if(n==="]"&&e)e=!1;else if(n==="/"&&!e)break;t=n==="\\\\"}++this.pos}var i=this.input.slice(r,this.pos);++this.pos;var s=this.pos,a=this.readWord1();this.containsEsc&&this.unexpected(s);var o=this.regexpState||(this.regexpState=new kt(this));o.reset(r,i,a),this.validateRegExpFlags(o),this.validateRegExpPattern(o);var l=null;try{l=new RegExp(i,a)}catch{}return this.finishToken(g.regexp,{pattern:i,flags:a,value:l})};X.readInt=function(t,e,r){for(var n=this.options.ecmaVersion>=12&&e===void 0,i=r&&this.input.charCodeAt(this.pos)===48,s=this.pos,a=0,o=0,l=0,c=e??1/0;l<c;++l,++this.pos){var u=this.input.charCodeAt(this.pos),h=void 0;if(n&&u===95){i&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed in legacy octal numeric literals"),o===95&&this.raiseRecoverable(this.pos,"Numeric separator must be exactly one underscore"),l===0&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed at the first of digits"),o=u;continue}if(u>=97?h=u-97+10:u>=65?h=u-65+10:u>=48&&u<=57?h=u-48:h=1/0,h>=t)break;o=u,a=a*t+h}return n&&o===95&&this.raiseRecoverable(this.pos-1,"Numeric separator is not allowed at the last of digits"),this.pos===s||e!=null&&this.pos-s!==e?null:a};function n_(t,e){return e?parseInt(t,8):parseFloat(t.replace(/_/g,""))}function $o(t){return typeof BigInt!="function"?null:BigInt(t.replace(/_/g,""))}X.readRadixNumber=function(t){var e=this.pos;this.pos+=2;var r=this.readInt(t);return r==null&&this.raise(this.start+2,"Expected number in radix "+t),this.options.ecmaVersion>=11&&this.input.charCodeAt(this.pos)===110?(r=$o(this.input.slice(e,this.pos)),++this.pos):Nt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(g.num,r)};X.readNumber=function(t){var e=this.pos;!t&&this.readInt(10,void 0,!0)===null&&this.raise(e,"Invalid number");var r=this.pos-e>=2&&this.input.charCodeAt(e)===48;r&&this.strict&&this.raise(e,"Invalid number");var n=this.input.charCodeAt(this.pos);if(!r&&!t&&this.options.ecmaVersion>=11&&n===110){var i=$o(this.input.slice(e,this.pos));return++this.pos,Nt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(g.num,i)}r&&/[89]/.test(this.input.slice(e,this.pos))&&(r=!1),n===46&&!r&&(++this.pos,this.readInt(10),n=this.input.charCodeAt(this.pos)),(n===69||n===101)&&!r&&(n=this.input.charCodeAt(++this.pos),(n===43||n===45)&&++this.pos,this.readInt(10)===null&&this.raise(e,"Invalid number")),Nt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var s=n_(this.input.slice(e,this.pos),r);return this.finishToken(g.num,s)};X.readCodePoint=function(){var t=this.input.charCodeAt(this.pos),e;if(t===123){this.options.ecmaVersion<6&&this.unexpected();var r=++this.pos;e=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,e>1114111&&this.invalidStringToken(r,"Code point out of bounds")}else e=this.readHexChar(4);return e};X.readString=function(t){for(var e="",r=++this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated string constant");var n=this.input.charCodeAt(this.pos);if(n===t)break;n===92?(e+=this.input.slice(r,this.pos),e+=this.readEscapedChar(!1),r=this.pos):n===8232||n===8233?(this.options.ecmaVersion<10&&this.raise(this.start,"Unterminated string constant"),++this.pos,this.options.locations&&(this.curLine++,this.lineStart=this.pos)):(gr(n)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return e+=this.input.slice(r,this.pos++),this.finishToken(g.string,e)};var Wo={};X.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t===Wo)this.readInvalidTemplateToken();else throw t}this.inTemplateElement=!1};X.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw Wo;this.raise(t,e)};X.readTmplToken=function(){for(var t="",e=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var r=this.input.charCodeAt(this.pos);if(r===96||r===36&&this.input.charCodeAt(this.pos+1)===123)return this.pos===this.start&&(this.type===g.template||this.type===g.invalidTemplate)?r===36?(this.pos+=2,this.finishToken(g.dollarBraceL)):(++this.pos,this.finishToken(g.backQuote)):(t+=this.input.slice(e,this.pos),this.finishToken(g.template,t));if(r===92)t+=this.input.slice(e,this.pos),t+=this.readEscapedChar(!0),e=this.pos;else if(gr(r)){switch(t+=this.input.slice(e,this.pos),++this.pos,r){case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:t+=`\n`;break;default:t+=String.fromCharCode(r);break}this.options.locations&&(++this.curLine,this.lineStart=this.pos),e=this.pos}else++this.pos}};X.readInvalidTemplateToken=function(){for(;this.pos<this.input.length;this.pos++)switch(this.input[this.pos]){case"\\\\":++this.pos;break;case"$":if(this.input[this.pos+1]!=="{")break;case"`":return this.finishToken(g.invalidTemplate,this.input.slice(this.start,this.pos));case"\\r":this.input[this.pos+1]===`\n`&&++this.pos;case`\n`:case"\\u2028":case"\\u2029":++this.curLine,this.lineStart=this.pos+1;break}this.raise(this.start,"Unterminated template")};X.readEscapedChar=function(t){var e=this.input.charCodeAt(++this.pos);switch(++this.pos,e){case 110:return`\n`;case 114:return"\\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return Mt(this.readCodePoint());case 116:return" ";case 98:return"\\b";case 118:return"\\v";case 102:return"\\f";case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"";case 56:case 57:if(this.strict&&this.invalidStringToken(this.pos-1,"Invalid escape sequence"),t){var r=this.pos-1;this.invalidStringToken(r,"Invalid escape sequence in template string")}default:if(e>=48&&e<=55){var n=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],i=parseInt(n,8);return i>255&&(n=n.slice(0,-1),i=parseInt(n,8)),this.pos+=n.length-1,e=this.input.charCodeAt(this.pos),(n!=="0"||e===56||e===57)&&(this.strict||t)&&this.invalidStringToken(this.pos-1-n.length,t?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(i)}return gr(e)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),""):String.fromCharCode(e)}};X.readHexChar=function(t){var e=this.pos,r=this.readInt(16,t);return r===null&&this.invalidStringToken(e,"Bad character escape sequence"),r};X.readWord1=function(){this.containsEsc=!1;for(var t="",e=!0,r=this.pos,n=this.options.ecmaVersion>=6;this.pos<this.input.length;){var i=this.fullCharCodeAtPos();if(jt(i,n))this.pos+=i<=65535?1:2;else if(i===92){this.containsEsc=!0,t+=this.input.slice(r,this.pos);var s=this.pos;this.input.charCodeAt(++this.pos)!==117&&this.invalidStringToken(this.pos,"Expecting Unicode escape sequence \\\\uXXXX"),++this.pos;var a=this.readCodePoint();(e?Nt:jt)(a,n)||this.invalidStringToken(s,"Invalid Unicode escape"),t+=Mt(a),r=this.pos}else break;e=!1}return t+this.input.slice(r,this.pos)};X.readWord=function(){var t=this.readWord1(),e=g.name;return this.keywords.test(t)&&(e=hs[t]),this.finishToken(e,t)};var i_="8.16.0";Ie.acorn={Parser:Ie,version:i_,defaultOptions:Fi,Position:Vr,SourceLocation:Wn,getLineInfo:po,Node:Kn,TokenType:J,tokTypes:g,keywordTypes:hs,TokContext:ct,tokContexts:pe,isIdentifierChar:jt,isIdentifierStart:Nt,Token:_s,isNewLine:gr,lineBreak:ze,lineBreakG:kg,nonASCIIwhitespace:co};function xs(t,e){return Ie.parse(t,e)}var{stringify:s_}=JSON;if(!String.prototype.repeat)throw new Error("String.prototype.repeat is undefined, see https://github.com/davidbonnet/astring#installation");if(!String.prototype.endsWith)throw new Error("String.prototype.endsWith is undefined, see https://github.com/davidbonnet/astring#installation");var Xr={"||":2,"??":3,"&&":4,"|":5,"^":6,"&":7,"==":8,"!=":8,"===":8,"!==":8,"<":9,">":9,"<=":9,">=":9,in:9,instanceof:9,"<<":10,">>":10,">>>":10,"+":11,"-":11,"*":12,"%":12,"/":12,"**":13},ft=17,a_={ArrayExpression:20,TaggedTemplateExpression:20,ThisExpression:20,Identifier:20,PrivateIdentifier:20,Literal:18,TemplateLiteral:20,Super:20,SequenceExpression:20,MemberExpression:19,ChainExpression:19,CallExpression:19,NewExpression:19,ArrowFunctionExpression:ft,ClassExpression:ft,FunctionExpression:ft,ObjectExpression:ft,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function ur(t,e){let{generator:r}=t;if(t.write("("),e!=null&&e.length>0){r[e[0].type](e[0],t);let{length:n}=e;for(let i=1;i<n;i++){let s=e[i];t.write(", "),r[s.type](s,t)}}t.write(")")}function Uo(t,e,r,n){let i=t.expressionsPrecedence[e.type];if(i===ft)return!0;let s=t.expressionsPrecedence[r.type];return i!==s?!n&&i===15&&s===14&&r.operator==="**"||i<s:i!==13&&i!==14?!1:e.operator==="**"&&r.operator==="**"?!n:i===13&&s===13&&(e.operator==="??"||r.operator==="??")?!0:n?Xr[e.operator]<=Xr[r.operator]:Xr[e.operator]<Xr[r.operator]}function Qr(t,e,r,n){let{generator:i}=t;Uo(t,e,r,n)?(t.write("("),i[e.type](e,t),t.write(")")):i[e.type](e,t)}function o_(t,e,r,n){let i=e.split(`\n`),s=i.length-1;if(t.write(i[0].trim()),s>0){t.write(n);for(let a=1;a<s;a++)t.write(r+i[a].trim()+n);t.write(r+i[s].trim())}}function Le(t,e,r,n){let{length:i}=e;for(let s=0;s<i;s++){let a=e[s];t.write(r),a.type[0]==="L"?t.write("// "+a.value.trim()+`\n`,a):(t.write("/*"),o_(t,a.value,r,n),t.write("*/"+n))}}function l_(t){let e=t;for(;e!=null;){let{type:r}=e;if(r[0]==="C"&&r[1]==="a")return!0;if(r[0]==="M"&&r[1]==="e"&&r[2]==="m")e=e.object;else return!1}}function oi(t,e){let{generator:r}=t,{declarations:n}=e;t.write(e.kind+" ");let{length:i}=n;if(i>0){r.VariableDeclarator(n[0],t);for(let s=1;s<i;s++)t.write(", "),r.VariableDeclarator(n[s],t)}}var aa,oa,la,ca,ua,pa,bs={Program(t,e){let r=e.indent.repeat(e.indentLevel),{lineEnd:n,writeComments:i}=e;i&&t.comments!=null&&Le(e,t.comments,r,n);let s=t.body,{length:a}=s;for(let o=0;o<a;o++){let l=s[o];i&&l.comments!=null&&Le(e,l.comments,r,n),e.write(r),this[l.type](l,e),e.write(n)}i&&t.trailingComments!=null&&Le(e,t.trailingComments,r,n)},BlockStatement:pa=function(t,e){let r=e.indent.repeat(e.indentLevel++),{lineEnd:n,writeComments:i}=e,s=r+e.indent;e.write("{");let a=t.body;if(a!=null&&a.length>0){e.write(n),i&&t.comments!=null&&Le(e,t.comments,s,n);let{length:o}=a;for(let l=0;l<o;l++){let c=a[l];i&&c.comments!=null&&Le(e,c.comments,s,n),e.write(s),this[c.type](c,e),e.write(n)}e.write(r)}else i&&t.comments!=null&&(e.write(n),Le(e,t.comments,s,n),e.write(r));i&&t.trailingComments!=null&&Le(e,t.trailingComments,s,n),e.write("}"),e.indentLevel--},ClassBody:pa,StaticBlock(t,e){e.write("static "),this.BlockStatement(t,e)},EmptyStatement(t,e){e.write(";")},ExpressionStatement(t,e){let r=e.expressionsPrecedence[t.expression.type];r===ft||r===3&&t.expression.left.type[0]==="O"?(e.write("("),this[t.expression.type](t.expression,e),e.write(")")):this[t.expression.type](t.expression,e),e.write(";")},IfStatement(t,e){e.write("if ("),this[t.test.type](t.test,e),e.write(") "),this[t.consequent.type](t.consequent,e),t.alternate!=null&&(e.write(" else "),this[t.alternate.type](t.alternate,e))},LabeledStatement(t,e){this[t.label.type](t.label,e),e.write(": "),this[t.body.type](t.body,e)},BreakStatement(t,e){e.write("break"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},ContinueStatement(t,e){e.write("continue"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},WithStatement(t,e){e.write("with ("),this[t.object.type](t.object,e),e.write(") "),this[t.body.type](t.body,e)},SwitchStatement(t,e){let r=e.indent.repeat(e.indentLevel++),{lineEnd:n,writeComments:i}=e;e.indentLevel++;let s=r+e.indent,a=s+e.indent;e.write("switch ("),this[t.discriminant.type](t.discriminant,e),e.write(") {"+n);let{cases:o}=t,{length:l}=o;for(let c=0;c<l;c++){let u=o[c];i&&u.comments!=null&&Le(e,u.comments,s,n),u.test?(e.write(s+"case "),this[u.test.type](u.test,e),e.write(":"+n)):e.write(s+"default:"+n);let{consequent:h}=u,{length:p}=h;for(let d=0;d<p;d++){let f=h[d];i&&f.comments!=null&&Le(e,f.comments,a,n),e.write(a),this[f.type](f,e),e.write(n)}}e.indentLevel-=2,e.write(r+"}")},ReturnStatement(t,e){e.write("return"),t.argument&&(e.write(" "),this[t.argument.type](t.argument,e)),e.write(";")},ThrowStatement(t,e){e.write("throw "),this[t.argument.type](t.argument,e),e.write(";")},TryStatement(t,e){if(e.write("try "),this[t.block.type](t.block,e),t.handler){let{handler:r}=t;r.param==null?e.write(" catch "):(e.write(" catch ("),this[r.param.type](r.param,e),e.write(") ")),this[r.body.type](r.body,e)}t.finalizer&&(e.write(" finally "),this[t.finalizer.type](t.finalizer,e))},WhileStatement(t,e){e.write("while ("),this[t.test.type](t.test,e),e.write(") "),this[t.body.type](t.body,e)},DoWhileStatement(t,e){e.write("do "),this[t.body.type](t.body,e),e.write(" while ("),this[t.test.type](t.test,e),e.write(");")},ForStatement(t,e){if(e.write("for ("),t.init!=null){let{init:r}=t;r.type[0]==="V"?oi(e,r):this[r.type](r,e)}e.write("; "),t.test&&this[t.test.type](t.test,e),e.write("; "),t.update&&this[t.update.type](t.update,e),e.write(") "),this[t.body.type](t.body,e)},ForInStatement:aa=function(t,e){e.write(`for ${t.await?"await ":""}(`);let{left:r}=t;r.type[0]==="V"?oi(e,r):this[r.type](r,e),e.write(t.type[3]==="I"?" in ":" of "),this[t.right.type](t.right,e),e.write(") "),this[t.body.type](t.body,e)},ForOfStatement:aa,DebuggerStatement(t,e){e.write("debugger;",t)},FunctionDeclaration:oa=function(t,e){e.write((t.async?"async ":"")+(t.generator?"function* ":"function ")+(t.id?t.id.name:""),t),ur(e,t.params),e.write(" "),this[t.body.type](t.body,e)},FunctionExpression:oa,VariableDeclaration(t,e){oi(e,t),e.write(";")},VariableDeclarator(t,e){this[t.id.type](t.id,e),t.init!=null&&(e.write(" = "),this[t.init.type](t.init,e))},ClassDeclaration(t,e){if(e.write("class "+(t.id?`${t.id.name} `:""),t),t.superClass){e.write("extends ");let{superClass:r}=t,{type:n}=r,i=e.expressionsPrecedence[n];(n[0]!=="C"||n[1]!=="l"||n[5]!=="E")&&(i===ft||i<e.expressionsPrecedence.ClassExpression)?(e.write("("),this[t.superClass.type](r,e),e.write(")")):this[r.type](r,e),e.write(" ")}this.ClassBody(t.body,e)},ImportDeclaration(t,e){e.write("import ");let{specifiers:r,attributes:n}=t,{length:i}=r,s=0;if(i>0){for(;s<i;){s>0&&e.write(", ");let a=r[s],o=a.type[6];if(o==="D")e.write(a.local.name,a),s++;else if(o==="N")e.write("* as "+a.local.name,a),s++;else break}if(s<i){for(e.write("{");;){let a=r[s],{name:o}=a.imported;if(e.write(o,a),o!==a.local.name&&e.write(" as "+a.local.name),++s<i)e.write(", ");else break}e.write("}")}e.write(" from ")}if(this.Literal(t.source,e),n&&n.length>0){e.write(" with { ");for(let a=0;a<n.length;a++)this.ImportAttribute(n[a],e),a<n.length-1&&e.write(", ");e.write(" }")}e.write(";")},ImportAttribute(t,e){this.Identifier(t.key,e),e.write(": "),this.Literal(t.value,e)},ImportExpression(t,e){e.write("import("),this[t.source.type](t.source,e),e.write(")")},ExportDefaultDeclaration(t,e){e.write("export default "),this[t.declaration.type](t.declaration,e),e.expressionsPrecedence[t.declaration.type]!=null&&t.declaration.type[0]!=="F"&&e.write(";")},ExportNamedDeclaration(t,e){if(e.write("export "),t.declaration)this[t.declaration.type](t.declaration,e);else{e.write("{");let{specifiers:r}=t,{length:n}=r;if(n>0)for(let i=0;;){let s=r[i],{name:a}=s.local;if(e.write(a,s),a!==s.exported.name&&e.write(" as "+s.exported.name),++i<n)e.write(", ");else break}if(e.write("}"),t.source&&(e.write(" from "),this.Literal(t.source,e)),t.attributes&&t.attributes.length>0){e.write(" with { ");for(let i=0;i<t.attributes.length;i++)this.ImportAttribute(t.attributes[i],e),i<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")}},ExportAllDeclaration(t,e){if(t.exported!=null?e.write("export * as "+t.exported.name+" from "):e.write("export * from "),this.Literal(t.source,e),t.attributes&&t.attributes.length>0){e.write(" with { ");for(let r=0;r<t.attributes.length;r++)this.ImportAttribute(t.attributes[r],e),r<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")},MethodDefinition(t,e){t.static&&e.write("static ");let r=t.kind[0];(r==="g"||r==="s")&&e.write(t.kind+" "),t.value.async&&e.write("async "),t.value.generator&&e.write("*"),t.computed?(e.write("["),this[t.key.type](t.key,e),e.write("]")):this[t.key.type](t.key,e),ur(e,t.value.params),e.write(" "),this[t.value.body.type](t.value.body,e)},ClassExpression(t,e){this.ClassDeclaration(t,e)},ArrowFunctionExpression(t,e){e.write(t.async?"async ":"",t);let{params:r}=t;r!=null&&(r.length===1&&r[0].type[0]==="I"?e.write(r[0].name,r[0]):ur(e,t.params)),e.write(" => "),t.body.type[0]==="O"?(e.write("("),this.ObjectExpression(t.body,e),e.write(")")):this[t.body.type](t.body,e)},ThisExpression(t,e){e.write("this",t)},Super(t,e){e.write("super",t)},RestElement:la=function(t,e){e.write("..."),this[t.argument.type](t.argument,e)},SpreadElement:la,YieldExpression(t,e){e.write(t.delegate?"yield*":"yield"),t.argument&&(e.write(" "),this[t.argument.type](t.argument,e))},AwaitExpression(t,e){e.write("await ",t),Qr(e,t.argument,t)},TemplateLiteral(t,e){let{quasis:r,expressions:n}=t;e.write("`");let{length:i}=n;for(let a=0;a<i;a++){let o=n[a],l=r[a];e.write(l.value.raw,l),e.write("${"),this[o.type](o,e),e.write("}")}let s=r[r.length-1];e.write(s.value.raw,s),e.write("`")},TemplateElement(t,e){e.write(t.value.raw,t)},TaggedTemplateExpression(t,e){Qr(e,t.tag,t),this[t.quasi.type](t.quasi,e)},ArrayExpression:ua=function(t,e){if(e.write("["),t.elements.length>0){let{elements:r}=t,{length:n}=r;for(let i=0;;){let s=r[i];if(s!=null&&this[s.type](s,e),++i<n)e.write(", ");else{s==null&&e.write(", ");break}}}e.write("]")},ArrayPattern:ua,ObjectExpression(t,e){let r=e.indent.repeat(e.indentLevel++),{lineEnd:n,writeComments:i}=e,s=r+e.indent;if(e.write("{"),t.properties.length>0){e.write(n),i&&t.comments!=null&&Le(e,t.comments,s,n);let a=","+n,{properties:o}=t,{length:l}=o;for(let c=0;;){let u=o[c];if(i&&u.comments!=null&&Le(e,u.comments,s,n),e.write(s),this[u.type](u,e),++c<l)e.write(a);else break}e.write(n),i&&t.trailingComments!=null&&Le(e,t.trailingComments,s,n),e.write(r+"}")}else i?t.comments!=null?(e.write(n),Le(e,t.comments,s,n),t.trailingComments!=null&&Le(e,t.trailingComments,s,n),e.write(r+"}")):t.trailingComments!=null?(e.write(n),Le(e,t.trailingComments,s,n),e.write(r+"}")):e.write("}"):e.write("}");e.indentLevel--},Property(t,e){t.method||t.kind[0]!=="i"?this.MethodDefinition(t,e):(t.shorthand||(t.computed?(e.write("["),this[t.key.type](t.key,e),e.write("]")):this[t.key.type](t.key,e),e.write(": ")),this[t.value.type](t.value,e))},PropertyDefinition(t,e){if(t.static&&e.write("static "),t.computed&&e.write("["),this[t.key.type](t.key,e),t.computed&&e.write("]"),t.value==null){t.key.type[0]!=="F"&&e.write(";");return}e.write(" = "),this[t.value.type](t.value,e),e.write(";")},ObjectPattern(t,e){if(e.write("{"),t.properties.length>0){let{properties:r}=t,{length:n}=r;for(let i=0;this[r[i].type](r[i],e),++i<n;)e.write(", ")}e.write("}")},SequenceExpression(t,e){ur(e,t.expressions)},UnaryExpression(t,e){if(t.prefix){let{operator:r,argument:n,argument:{type:i}}=t;e.write(r);let s=Uo(e,n,t);!s&&(r.length>1||i[0]==="U"&&(i[1]==="n"||i[1]==="p")&&n.prefix&&n.operator[0]===r&&(r==="+"||r==="-"))&&e.write(" "),s?(e.write(r.length>1?" (":"("),this[i](n,e),e.write(")")):this[i](n,e)}else this[t.argument.type](t.argument,e),e.write(t.operator)},UpdateExpression(t,e){t.prefix?(e.write(t.operator),this[t.argument.type](t.argument,e)):(this[t.argument.type](t.argument,e),e.write(t.operator))},AssignmentExpression(t,e){this[t.left.type](t.left,e),e.write(" "+t.operator+" "),this[t.right.type](t.right,e)},AssignmentPattern(t,e){this[t.left.type](t.left,e),e.write(" = "),this[t.right.type](t.right,e)},BinaryExpression:ca=function(t,e){let r=t.operator==="in";r&&e.write("("),Qr(e,t.left,t,!1),e.write(" "+t.operator+" "),Qr(e,t.right,t,!0),r&&e.write(")")},LogicalExpression:ca,ConditionalExpression(t,e){let{test:r}=t,n=e.expressionsPrecedence[r.type];n===ft||n<=e.expressionsPrecedence.ConditionalExpression?(e.write("("),this[r.type](r,e),e.write(")")):this[r.type](r,e),e.write(" ? "),this[t.consequent.type](t.consequent,e),e.write(" : "),this[t.alternate.type](t.alternate,e)},NewExpression(t,e){e.write("new ");let r=e.expressionsPrecedence[t.callee.type];r===ft||r<e.expressionsPrecedence.CallExpression||l_(t.callee)?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),ur(e,t.arguments)},CallExpression(t,e){let r=e.expressionsPrecedence[t.callee.type];r===ft||r<e.expressionsPrecedence.CallExpression?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),t.optional&&e.write("?."),ur(e,t.arguments)},ChainExpression(t,e){this[t.expression.type](t.expression,e)},MemberExpression(t,e){let r=e.expressionsPrecedence[t.object.type];r===ft||r<e.expressionsPrecedence.MemberExpression?(e.write("("),this[t.object.type](t.object,e),e.write(")")):this[t.object.type](t.object,e),t.computed?(t.optional&&e.write("?."),e.write("["),this[t.property.type](t.property,e),e.write("]")):(t.optional?e.write("?."):e.write("."),this[t.property.type](t.property,e))},MetaProperty(t,e){e.write(t.meta.name+"."+t.property.name,t)},Identifier(t,e){e.write(t.name,t)},PrivateIdentifier(t,e){e.write(`#${t.name}`,t)},Literal(t,e){t.raw!=null?e.write(t.raw,t):t.regex!=null?this.RegExpLiteral(t,e):t.bigint!=null?e.write(t.bigint+"n",t):e.write(s_(t.value),t)},RegExpLiteral(t,e){let{regex:r}=t;e.write(`/${r.pattern}/${r.flags}`,t)}},c_={},u_=bs,Oi=class{constructor(e){let r=e??c_;this.output="",r.output!=null?(this.output=r.output,this.write=this.writeToStream):this.output="",this.generator=r.generator!=null?r.generator:bs,this.expressionsPrecedence=r.expressionsPrecedence!=null?r.expressionsPrecedence:a_,this.indent=r.indent!=null?r.indent:" ",this.lineEnd=r.lineEnd!=null?r.lineEnd:`\n`,this.indentLevel=r.startingIndentLevel!=null?r.startingIndentLevel:0,this.writeComments=r.comments?r.comments:!1,r.sourceMap!=null&&(this.write=r.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=r.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`\n`).length-1,this.mapping={original:null,generated:this,name:void 0,source:r.sourceMap.file||r.sourceMap._file})}write(e){this.output+=e}writeToStream(e){this.output.write(e)}writeAndMap(e,r){this.output+=e,this.map(e,r)}writeToStreamAndMap(e,r){this.output.write(e),this.map(e,r)}map(e,r){if(r!=null){let{type:s}=r;if(s[0]==="L"&&s[2]==="n"){this.column=0,this.line++;return}if(r.loc!=null){let{mapping:a}=this;a.original=r.loc.start,a.name=r.name,this.sourceMap.addMapping(a)}if(s[0]==="T"&&s[8]==="E"||s[0]==="L"&&s[1]==="i"&&typeof r.value=="string"){let{length:a}=e,{column:o,line:l}=this;for(let c=0;c<a;c++)e[c]===`\n`?(o=0,l++):o++;this.column=o,this.line=l;return}}let{length:n}=e,{lineEnd:i}=this;n>0&&(this.lineEndSize>0&&(i.length===1?e[n-1]===i:e.endsWith(i))?(this.line+=this.lineEndSize,this.column=0):this.column+=n)}toString(){return this.output}};function vs(t,e){let r=new Oi(e);return r.generator[t.type](t,r),r.output}var p_=Object.defineProperty,h_=(t,e,r)=>e in t?p_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ne=(t,e,r)=>h_(t,typeof e!="symbol"?e+"":e,r),d_=new Set(["Infinity","NaN","undefined","null","true","false"]),f_=new Set(["Math","Array","Object","String","Number","Boolean","Date","RegExp","Error","JSON","Promise","Set","Map","WeakSet","WeakMap","Symbol","BigInt","Proxy","Reflect","console","isNaN","isFinite","parseInt","parseFloat","encodeURI","decodeURI","encodeURIComponent","decodeURIComponent"]),Vi=class{constructor(){ne(this,"scopes",[]),ne(this,"scopeTypes",[]),ne(this,"scopeCounts",new Map),ne(this,"contextBoundVars",new Set),ne(this,"arrayPatternElements",new Set),ne(this,"rootParams",new Set),ne(this,"localSeriesVars",new Set),ne(this,"varKinds",new Map),ne(this,"loopVars",new Set),ne(this,"loopVarNames",new Map),ne(this,"paramIdCounter",0),ne(this,"cacheIdCounter",0),ne(this,"tempVarCounter",0),ne(this,"taCallIdCounter",0),ne(this,"userCallIdCounter",0),ne(this,"plotCallIdCounter",0),ne(this,"alertCallIdCounter",0),ne(this,"loopGuardCounter",0),ne(this,"hoistingStack",[]),ne(this,"suppressHoisting",!1),ne(this,"reservedNames",new Set),ne(this,"userFunctions",new Set),ne(this,"userMethods",new Set),ne(this,"regularUserFunctions",new Set),ne(this,"udtTypeNames",new Map),ne(this,"udtInstances",new Map),ne(this,"functionReturnTypes",new Map),ne(this,"functionReturnTupleTypes",new Map),ne(this,"functionParamUdtTypes",new Map),this.pushScope("glb")}get nextParamIdArg(){return{type:"Identifier",name:`\'p${this.paramIdCounter++}\'`}}get nextCacheIdArg(){return{type:"Identifier",name:`\'cache_${this.cacheIdCounter++}\'`}}getNextTACallId(){return{type:"Literal",value:`_ta${this.taCallIdCounter++}`}}getNextUserCallId(){return{type:"Literal",value:`_fn${this.userCallIdCounter++}`}}getNextPlotCallId(){return{type:"Literal",value:`#${this.plotCallIdCounter++}`}}getNextAlertCallId(){return{type:"Literal",value:`alert_${this.alertCallIdCounter++}`}}getNextLoopGuardName(){return`__lg${this.loopGuardCounter++}`}pushScope(e){this.scopes.push(new Map),this.scopeTypes.push(e),this.scopeCounts.set(e,(this.scopeCounts.get(e)||0)+1)}popScope(){this.scopes.pop(),this.scopeTypes.pop()}getCurrentScopeType(){return this.scopeTypes[this.scopeTypes.length-1]}isInsideFunctionScope(){for(let e=this.scopeTypes.length-1;e>=0;e--)if(this.scopeTypes[e]==="fn")return!0;return!1}getCurrentScopeCount(){return this.scopeCounts.get(this.getCurrentScopeType())||1}addLocalSeriesVar(e){this.localSeriesVars.add(e)}removeLocalSeriesVar(e){this.localSeriesVars.delete(e)}isLocalSeriesVar(e){return this.localSeriesVars.has(e)}addUdtTypeName(e,r={}){this.udtTypeNames.set(e,r)}isUdtTypeName(e){return this.udtTypeNames.has(e)}getUdtTypeFields(e){return this.udtTypeNames.get(e)}markVariableAsUdtInstance(e,r){this.udtInstances.set(e,r)}getVariableUdtType(e){return this.udtInstances.get(e)}isUdtInstance(e){return this.udtInstances.has(e)}setFunctionReturnType(e,r){let n=this.functionReturnTypes.get(e);if(n&&n!==r){this.functionReturnTypes.delete(e);return}this.functionReturnTypes.set(e,r)}getFunctionReturnType(e){return this.functionReturnTypes.get(e)}setFunctionReturnTupleType(e,r){let n=this.functionReturnTupleTypes.get(e);if(n&&(n.length!==r.length||n.some((i,s)=>i!==r[s]))){this.functionReturnTupleTypes.delete(e);return}this.functionReturnTupleTypes.set(e,r)}getFunctionReturnTupleType(e){return this.functionReturnTupleTypes.get(e)}setFunctionParamUdtTypes(e,r){this.functionParamUdtTypes.set(e,r)}getFunctionParamUdtTypes(e){return this.functionParamUdtTypes.get(e)}unmarkVariableAsUdtInstance(e){this.udtInstances.delete(e)}addContextBoundVar(e,r=!1){this.contextBoundVars.add(e),r&&this.rootParams.add(e)}removeContextBoundVar(e){this.contextBoundVars.has(e)&&(this.contextBoundVars.delete(e),this.rootParams.has(e)&&this.rootParams.delete(e))}addArrayPatternElement(e){this.arrayPatternElements.add(e)}isContextBound(e){return d_.has(e)||f_.has(e)?!1:this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,r){this.loopVars.add(e),this.loopVarNames.set(e,r)}removeLoopVariable(e){this.loopVars.delete(e),this.loopVarNames.delete(e)}getLoopVariableName(e){return this.loopVarNames.get(e)}isLoopVariable(e){return this.loopVars.has(e)}addReservedName(e){this.reservedNames.add(e)}addUserFunction(e){this.userFunctions.add(e)}isUserFunction(e){return this.userFunctions.has(e)}addUserMethod(e){this.userMethods.add(e)}isUserMethod(e){return this.userMethods.has(e)}addRegularUserFunction(e){this.regularUserFunctions.add(e)}isRegularUserFunction(e){return this.regularUserFunctions.has(e)}addVariable(e,r){if(this.isContextBound(e))return e;let n=this.scopes[this.scopes.length-1],i=this.scopeTypes[this.scopeTypes.length-1],s=this.scopeCounts.get(i)||1,a=`${i}${s}_${e}`;return n.set(e,a),this.varKinds.set(a,r),a}getVariable(e){if(this.loopVars.has(e)){let r=this.loopVarNames.get(e);if(r)return[r,"let"]}if(this.isContextBound(e))return[e,"let"];for(let r=this.scopes.length-1;r>=0;r--){let n=this.scopes[r];if(n.has(e)){let i=n.get(e),s=this.varKinds.get(i)||"let";return[i,s]}}return[e,"let"]}isVariableInFunctionScope(e){for(let r=this.scopes.length-1;r>=0;r--)if(this.scopes[r].has(e)){for(let n=0;n<=r;n++)if(this.scopeTypes[n]==="fn")return!0;return!1}return!1}generateTempVar(){return`temp_${++this.tempVarCounter}`}enterHoistingScope(){this.hoistingStack.push([])}exitHoistingScope(){return this.hoistingStack.pop()||[]}addHoistedStatement(e){this.hoistingStack.length>0&&!this.suppressHoisting&&this.hoistingStack[this.hoistingStack.length-1].push(e)}addOuterHoistedStatement(e){if(this.hoistingStack.length>0&&!this.suppressHoisting){let r=Math.min(1,this.hoistingStack.length-1);this.hoistingStack[r].push(e)}}getCurrentHoistingScope(){return this.hoistingStack.length===0?null:this.hoistingStack[this.hoistingStack.length-1]}setSuppressHoisting(e){this.suppressHoisting=e}shouldSuppressHoisting(){return this.suppressHoisting}hasVariableInScope(e){if(this.reservedNames.has(e))return!0;for(let r=this.scopes.length-1;r>=0;r--)if(this.scopes[r].has(e))return!0;return!!(this.contextBoundVars.has(e)||this.loopVars.has(e)||this.localSeriesVars.has(e))}generateParamId(){let e=`p${this.paramIdCounter++}`;for(;this.hasVariableInScope(e);)e=`p${this.paramIdCounter++}`;let r=this.scopes[this.scopes.length-1];return r&&r.set(e,e),e}};function mt(t,e,r,n,i){r||(r=I),(function s(a,o,l){var c=l||a.type;zo(r,c,a,o,s),e[c]&&e[c](a,o)})(t,n,i)}function qo(t,e,r,n,i){var s=[];r||(r=I),(function a(o,l,c){var u=c||o.type,h=o!==s[s.length-1];h&&s.push(o),zo(r,u,o,l,a),e[u]&&e[u](o,l||s,s),h&&s.pop()})(t,n,i)}function Ne(t,e,r,n,i){var s=r?m_(r,n||void 0):n;(function a(o,l,c){s[c||o.type](o,l,a)})(t,e,i)}function m_(t,e){var r=Object.create(e||I);for(var n in t)r[n]=t[n];return r}function ws(t,e,r){r(t,e)}function tr(t,e,r){}function zo(t,e,r,n,i){if(t[e]==null)throw new Error("No walker function defined for node type "+e);t[e](r,n,i)}var I={};I.Program=I.BlockStatement=I.StaticBlock=function(t,e,r){for(var n=0,i=t.body;n<i.length;n+=1){var s=i[n];r(s,e,"Statement")}};I.Statement=ws;I.EmptyStatement=tr;I.ExpressionStatement=I.ParenthesizedExpression=I.ChainExpression=function(t,e,r){return r(t.expression,e,"Expression")};I.IfStatement=function(t,e,r){r(t.test,e,"Expression"),r(t.consequent,e,"Statement"),t.alternate&&r(t.alternate,e,"Statement")};I.LabeledStatement=function(t,e,r){return r(t.body,e,"Statement")};I.BreakStatement=I.ContinueStatement=tr;I.WithStatement=function(t,e,r){r(t.object,e,"Expression"),r(t.body,e,"Statement")};I.SwitchStatement=function(t,e,r){r(t.discriminant,e,"Expression");for(var n=0,i=t.cases;n<i.length;n+=1){var s=i[n];r(s,e)}};I.SwitchCase=function(t,e,r){t.test&&r(t.test,e,"Expression");for(var n=0,i=t.consequent;n<i.length;n+=1){var s=i[n];r(s,e,"Statement")}};I.ReturnStatement=I.YieldExpression=I.AwaitExpression=function(t,e,r){t.argument&&r(t.argument,e,"Expression")};I.ThrowStatement=I.SpreadElement=function(t,e,r){return r(t.argument,e,"Expression")};I.TryStatement=function(t,e,r){r(t.block,e,"Statement"),t.handler&&r(t.handler,e),t.finalizer&&r(t.finalizer,e,"Statement")};I.CatchClause=function(t,e,r){t.param&&r(t.param,e,"Pattern"),r(t.body,e,"Statement")};I.WhileStatement=I.DoWhileStatement=function(t,e,r){r(t.test,e,"Expression"),r(t.body,e,"Statement")};I.ForStatement=function(t,e,r){t.init&&r(t.init,e,"ForInit"),t.test&&r(t.test,e,"Expression"),t.update&&r(t.update,e,"Expression"),r(t.body,e,"Statement")};I.ForInStatement=I.ForOfStatement=function(t,e,r){r(t.left,e,"ForInit"),r(t.right,e,"Expression"),r(t.body,e,"Statement")};I.ForInit=function(t,e,r){t.type==="VariableDeclaration"?r(t,e):r(t,e,"Expression")};I.DebuggerStatement=tr;I.FunctionDeclaration=function(t,e,r){return r(t,e,"Function")};I.VariableDeclaration=function(t,e,r){for(var n=0,i=t.declarations;n<i.length;n+=1){var s=i[n];r(s,e)}};I.VariableDeclarator=function(t,e,r){r(t.id,e,"Pattern"),t.init&&r(t.init,e,"Expression")};I.Function=function(t,e,r){t.id&&r(t.id,e,"Pattern");for(var n=0,i=t.params;n<i.length;n+=1){var s=i[n];r(s,e,"Pattern")}r(t.body,e,t.expression?"Expression":"Statement")};I.Pattern=function(t,e,r){t.type==="Identifier"?r(t,e,"VariablePattern"):t.type==="MemberExpression"?r(t,e,"MemberPattern"):r(t,e)};I.VariablePattern=tr;I.MemberPattern=ws;I.RestElement=function(t,e,r){return r(t.argument,e,"Pattern")};I.ArrayPattern=function(t,e,r){for(var n=0,i=t.elements;n<i.length;n+=1){var s=i[n];s&&r(s,e,"Pattern")}};I.ObjectPattern=function(t,e,r){for(var n=0,i=t.properties;n<i.length;n+=1){var s=i[n];s.type==="Property"?(s.computed&&r(s.key,e,"Expression"),r(s.value,e,"Pattern")):s.type==="RestElement"&&r(s.argument,e,"Pattern")}};I.Expression=ws;I.ThisExpression=I.Super=I.MetaProperty=tr;I.ArrayExpression=function(t,e,r){for(var n=0,i=t.elements;n<i.length;n+=1){var s=i[n];s&&r(s,e,"Expression")}};I.ObjectExpression=function(t,e,r){for(var n=0,i=t.properties;n<i.length;n+=1){var s=i[n];r(s,e)}};I.FunctionExpression=I.ArrowFunctionExpression=I.FunctionDeclaration;I.SequenceExpression=function(t,e,r){for(var n=0,i=t.expressions;n<i.length;n+=1){var s=i[n];r(s,e,"Expression")}};I.TemplateLiteral=function(t,e,r){for(var n=0,i=t.quasis;n<i.length;n+=1){var s=i[n];r(s,e)}for(var a=0,o=t.expressions;a<o.length;a+=1){var l=o[a];r(l,e,"Expression")}};I.TemplateElement=tr;I.UnaryExpression=I.UpdateExpression=function(t,e,r){r(t.argument,e,"Expression")};I.BinaryExpression=I.LogicalExpression=function(t,e,r){r(t.left,e,"Expression"),r(t.right,e,"Expression")};I.AssignmentExpression=I.AssignmentPattern=function(t,e,r){r(t.left,e,"Pattern"),r(t.right,e,"Expression")};I.ConditionalExpression=function(t,e,r){r(t.test,e,"Expression"),r(t.consequent,e,"Expression"),r(t.alternate,e,"Expression")};I.NewExpression=I.CallExpression=function(t,e,r){if(r(t.callee,e,"Expression"),t.arguments)for(var n=0,i=t.arguments;n<i.length;n+=1){var s=i[n];r(s,e,"Expression")}};I.MemberExpression=function(t,e,r){r(t.object,e,"Expression"),t.computed&&r(t.property,e,"Expression")};I.ExportNamedDeclaration=I.ExportDefaultDeclaration=function(t,e,r){if(t.declaration&&r(t.declaration,e,t.type==="ExportNamedDeclaration"||t.declaration.id?"Statement":"Expression"),t.source&&r(t.source,e,"Expression"),t.attributes)for(var n=0,i=t.attributes;n<i.length;n+=1){var s=i[n];r(s,e)}};I.ExportAllDeclaration=function(t,e,r){if(t.exported&&r(t.exported,e),r(t.source,e,"Expression"),t.attributes)for(var n=0,i=t.attributes;n<i.length;n+=1){var s=i[n];r(s,e)}};I.ImportAttribute=function(t,e,r){r(t.value,e,"Expression")};I.ImportDeclaration=function(t,e,r){for(var n=0,i=t.specifiers;n<i.length;n+=1){var s=i[n];r(s,e)}if(r(t.source,e,"Expression"),t.attributes)for(var a=0,o=t.attributes;a<o.length;a+=1){var l=o[a];r(l,e)}};I.ImportExpression=function(t,e,r){r(t.source,e,"Expression"),t.options&&r(t.options,e,"Expression")};I.ImportSpecifier=I.ImportDefaultSpecifier=I.ImportNamespaceSpecifier=I.Identifier=I.PrivateIdentifier=I.Literal=tr;I.TaggedTemplateExpression=function(t,e,r){r(t.tag,e,"Expression"),r(t.quasi,e,"Expression")};I.ClassDeclaration=I.ClassExpression=function(t,e,r){return r(t,e,"Class")};I.Class=function(t,e,r){t.id&&r(t.id,e,"Pattern"),t.superClass&&r(t.superClass,e,"Expression"),r(t.body,e)};I.ClassBody=function(t,e,r){for(var n=0,i=t.body;n<i.length;n+=1){var s=i[n];r(s,e)}};I.MethodDefinition=I.PropertyDefinition=I.Property=function(t,e,r){t.computed&&r(t.key,e,"Expression"),t.value&&r(t.value,e,"Expression")};var fe="$",S={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,r=!1){return{type:"MemberExpression",object:t,property:e,computed:r}},createContextIdentifier(){return this.createIdentifier("$")},createLocalContextIdentifier(){return this.createIdentifier("$$")},createContextVariableReference(t,e){let r=this.createContextIdentifier(),n=this.createIdentifier(t),i=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(r,n,!1),i,!1)},createLocalContextVariableReference(t,e){let r=this.createLocalContextIdentifier(),n=this.createIdentifier(t),i=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(r,n,!1),i,!1)},createDynamicContextVariableReference(t,e){let r=this.createContextIdentifier(),n=this.createIdentifier(t);return this.createMemberExpression(this.createMemberExpression(r,n,!1),e,!0)},createContextVariableAccess0(t,e){let r=this.createContextVariableReference(t,e);return this.createGetCall(r,0)},createDynamicContextVariableAccess0(t,e){let r=this.createDynamicContextVariableReference(t,e);return this.createGetCall(r,0)},createArrayAccess(t,e){let r=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,r,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,r="="){return{type:"AssignmentExpression",operator:r,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,r){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),i=[t,e];return r&&i.push(r),this.createCallExpression(n,i)},createInitVarCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("initVar"),!1),n=[t,e];return this.createCallExpression(r,n)},createGetCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),n=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(r,[t,n])},createSetCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(r,[t,e])},createMathEqCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),n=this.createMemberExpression(r,this.createIdentifier("math"),!1),i=this.createMemberExpression(n,this.createIdentifier("__eq"),!1);return this.createCallExpression(i,[t,e])},createMathNeqCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),n=this.createMemberExpression(r,this.createIdentifier("math"),!1),i=this.createMemberExpression(n,this.createIdentifier("__neq"),!1);return this.createCallExpression(i,[t,e])},createMathCompareCall(t,e,r){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),i=this.createMemberExpression(n,this.createIdentifier("math"),!1),s=this.createMemberExpression(i,this.createIdentifier(t),!1);return this.createCallExpression(s,[e,r])},createMathIntDivCall(t,e){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),n=this.createMemberExpression(r,this.createIdentifier("math"),!1),i=this.createMemberExpression(n,this.createIdentifier("__idiv"),!1);return this.createCallExpression(i,[t,e])},createWrapperFunction(t){return{type:"FunctionDeclaration",id:null,params:[this.createIdentifier("context")],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:t}]}}},createVariableDeclaration(t,e){return{type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:this.createIdentifier(t),init:e}]}},createAwaitExpression(t){return{type:"AwaitExpression",argument:t}}},$t=["ta","math","request","array","input","color","ticker","strategy"],yt=["hline","plot","fill","label","line","box","linefill","polyline","table","na","alert","time","time_close","dayofmonth","dayofweek","hour","minute","month","second","weekofyear","year"],y_=["request.security","request.security_lower_tf"],g_=["chart.left_visible_bar_time","chart.right_visible_bar_time"],ha=["plot","hline","fill","strategy.exit"],__=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],x_=new Set([...$t,"fill","plot","hline","label","line","size","extend","display","format","location","shape","text","xloc","yloc","linefill","polyline","box","table","map","matrix","chart","alert","barstate","syminfo","timeframe","strategy","log","str"]),da=new Set(["await","debugger","default","delete","extends","finally","function","implements","instanceof","interface","let","new","package","private","protected","public","static","super","throw","typeof","void","with","yield"]),Ko=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],Es=[...$t,"plotchar","plotshape","plotarrow","plotbar","plotcandle","plot","bgcolor","barcolor","hline","fill","indicator","library","alertcondition","alert","error","max_bars_back","fixnan","na","nz","timestamp","str","box","line","label","table","chart","linefill","polyline","map","matrix","log","Type","bool","int","float","string","timeframe","syminfo","barstate","bar_index","last_bar_index","last_bar_time","inputs","time","time_close","time_tradingday","dayofmonth","hour","minute","month","second","weekofyear","year","order","currency","display","shape","location","size","format","dayofweek","xloc","yloc","text","font","extend","position","barmerge","adjustment","backadjustment","earnings","dividends","splits"],b_=["na","nz","plot","plotchar","color","hline","fill"];function v_(t){let e=null,r=fe;if(t.type==="Program"&&t.body.length>0){let d=t.body[0];if(d.type==="ExpressionStatement"&&(d.expression.type==="ArrowFunctionExpression"||d.expression.type==="FunctionExpression")){let f=d.expression;f.body.type==="BlockStatement"&&(e=f.body.body,f.params.length>0&&f.params[0].type==="Identifier"&&(r=f.params[0].name))}}if(!e)return;let n=new Set,i=new Set,s=d=>{d.type==="Identifier"?n.add(d.name):d.type==="ObjectPattern"?d.properties.forEach(f=>s(f.value)):d.type==="ArrayPattern"&&d.elements.forEach(f=>{f&&s(f)})};Ne(t,{},{VariableDeclarator(d,f,m){s(d.id),d.init&&m(d.init,f)},FunctionDeclaration(d,f,m){s(d.id);for(let x of d.params)x&&x.type==="AssignmentPattern"&&x.right&&m(x.right,f);m(d.body,f)},Identifier(d,f,m){i.add(d.name)},MemberExpression(d,f,m){m(d.object,f),d.computed&&m(d.property,f)},Property(d,f,m){d.computed&&m(d.key,f),m(d.value,f)}}),e.forEach(d=>{d.type==="VariableDeclaration"?d.declarations.forEach(f=>s(f.id)):d.type==="FunctionDeclaration"&&s(d.id)});let a=Ko,o=Es,l=a.filter(d=>!n.has(d)),c=o.filter(d=>!n.has(d)),u=l.filter(d=>i.has(d)),h=c.filter(d=>i.has(d)),p=[];u.length>0&&p.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:u.map(d=>({type:"Property",key:{type:"Identifier",name:d},value:{type:"Identifier",name:d},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:r},property:{type:"Identifier",name:"data"},computed:!1}}]}),h.length>0&&p.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:h.map(d=>({type:"Property",key:{type:"Identifier",name:d},value:{type:"Identifier",name:d},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:r},property:{type:"Identifier",name:"pine"},computed:!1}}]}),p.length>0&&e.unshift(...p)}function w_(t){let e=null,r=fe;if(t.type==="Program"&&t.body.length>0){let o=t.body[0];if(o.type==="ExpressionStatement"&&(o.expression.type==="ArrowFunctionExpression"||o.expression.type==="FunctionExpression")){let l=o.expression;l.body.type==="BlockStatement"&&(e=l.body.body,l.params.length>0&&l.params[0].type==="Identifier"&&(r=l.params[0].name))}}if(!e)return;let n=new Set(Ko),i=new Set(Es),s=new Set(b_),a=new Map;e.forEach(o=>{o.type==="VariableDeclaration"&&o.declarations.forEach(l=>{if(l.init&&l.init.type==="MemberExpression"&&l.init.object.type==="Identifier"&&l.init.object.name===r&&l.init.property.type==="Identifier"){let c=l.init.property.name,u=null;if(c==="data"?u=n:c==="pine"?u=i:c==="core"&&(u=s),u&&l.id.type==="ObjectPattern")l.id.properties.forEach(h=>{if(h.type==="Property"&&h.key.type==="Identifier"&&h.value.type==="Identifier"){let p=h.key.name,d=h.value.name;u.has(p)&&p!==d&&(a.set(d,p),h.value.name=p,h.shorthand=!0)}});else if(l.id.type==="Identifier"&&$t.includes(c)){let h=c,p=l.id.name;h!==p&&(a.set(p,h),l.id.name=h)}}})}),a.size>0&&Ne(t,{},{Identifier(o){a.has(o.name)&&(o.name=a.get(o.name))},MemberExpression(o,l,c){c(o.object,l),o.computed&&c(o.property,l)},Property(o,l,c){o.computed&&c(o.key,l),c(o.value,l)}})}function E_(t){try{let e=xs(t,{ecmaVersion:"latest",sourceType:"module"});if(e.type==="Program"&&e.body.length===1){let r=e.body[0];if(r.type==="ExpressionStatement"){let n=r.expression;if(n.type==="ArrowFunctionExpression"||n.type==="FunctionExpression")return{isWrapped:!0,isAsync:n.async||!1,functionNode:n}}if(r.type==="FunctionDeclaration")return{isWrapped:!0,isAsync:r.async||!1,functionNode:r}}return{isWrapped:!1,isAsync:!1}}catch{return{isWrapped:!1,isAsync:!1}}}function S_(t){return t.async=!0,vs(t)}function C_(t){t=t.trim();let{isWrapped:e,isAsync:r,functionNode:n}=E_(t);return e&&n?r?t:S_(n):`async (context) => {\n${t}\n}`}function N_(t){Ne(t,null,{VariableDeclaration(e,r,n){e.declarations&&e.declarations.length>0&&e.declarations.forEach(i=>{if(i.init&&i.init.type==="ArrowFunctionExpression"&&i.init.start!==0){let s={type:"FunctionDeclaration",id:i.id,params:i.init.params,body:i.init.body.type==="BlockStatement"?i.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:i.init.body}]},async:i.init.async,generator:!1};Object.assign(e,s)}}),e.body&&e.body.body&&e.body.body.forEach(i=>n(i,r))}})}function k_(t,e){mt(t,{VariableDeclaration(n){for(let i of n.declarations)if(!(i.id?.type!=="Identifier"||!i.init)&&i.init.type==="CallExpression"&&i.init.callee?.type==="Identifier"&&i.init.callee.name==="Type"&&i.init.arguments?.length===1&&i.init.arguments[0]?.type==="ObjectExpression"){let s={};for(let a of i.init.arguments[0].properties)a.type!=="Property"||a.key?.type!=="Identifier"||(a.value?.type==="ArrayExpression"&&a.value.elements?.[0]?.type==="Literal"?s[a.key.name]=String(a.value.elements[0].value):a.value?.type==="Literal"&&(s[a.key.name]=String(a.value.value)));e.addUdtTypeName(i.id.name,s)}}});let r=!0;for(;r;)r=!1,mt(t,{FunctionDeclaration(n){if(!n.id?.name)return;let i=n.id.name;if(e.getFunctionReturnType(i)||e.getFunctionReturnTupleType(i))return;let s=I_(n.body);if(s.length===0)return;if(s.every(l=>l.type==="ArrayExpression")){let l=s[0].elements.length;if(l>0&&s.every(c=>c.elements.length===l)){let c=[],u=!0;for(let h=0;h<l;h++){let p=s.map(f=>Mr(f.elements[h],e)),d=p[0];if(!p.every(f=>f===d)){u=!1;break}c.push(d)}if(u&&c.some(h=>!!h)){e.setFunctionReturnTupleType(i,c),r=!0;return}}}let a=s.map(l=>Mr(l,e)),o=a[0];!o||!a.every(l=>l===o)||(e.setFunctionReturnType(i,o),r=!0)}});mt(t,{VariableDeclaration(n){for(let i of n.declarations)if(i.init){if(i.id?.type==="Identifier"){let s=Mr(i.init,e);s&&e.markVariableAsUdtInstance(i.id.name,s);continue}if(i.id?.type==="ArrayPattern"&&i.init.type==="CallExpression"&&i.init.callee?.type==="Identifier"){let s=e.getFunctionReturnTupleType(i.init.callee.name);if(!s)continue;i.id.elements?.forEach((a,o)=>{if(!a||a.type!=="Identifier")return;let l=s[o];l&&e.markVariableAsUdtInstance(a.name,l)})}}},ExpressionStatement(n){let i=n.expression;if(i?.type==="Literal"&&typeof i.value=="string"&&i.value.startsWith("__pineUdtVar:")){let s=i.value.match(/^__pineUdtVar:([A-Za-z_$][\\w$]*)=([A-Za-z_$][\\w$]*)$/);if(s){let[,a,o]=s;e.isUdtTypeName(o)&&e.markVariableAsUdtInstance(a,o)}}}}),mt(t,{ExpressionStatement(n){let i=n.expression;if(!i||i.type!=="AssignmentExpression"||i.operator!=="=")return;let s=i.left;if(s?.type!=="MemberExpression"||s.computed||s.property?.type!=="Identifier"||s.property.name!=="__pineParamTypes__"||s.object?.type!=="Identifier"||i.right?.type!=="ObjectExpression")return;let a=s.object.name,o=a.startsWith("$M_")?a.slice(3):a,l={};for(let c of i.right.properties){if(c.type!=="Property")continue;let u;if(c.key?.type==="Identifier"?u=c.key.name:c.key?.type==="Literal"&&typeof c.key.value=="string"&&(u=c.key.value),!u||c.value?.type!=="Literal"||typeof c.value.value!="string")continue;let h=c.value.value.split(/\\s+/).pop();e.isUdtTypeName(h)&&(l[u]=h)}Object.keys(l).length>0&&e.setFunctionParamUdtTypes(o,l)}})}function I_(t){let e=[];if(!t)return e;function r(n){if(!(!n||typeof n!="object")&&!(n.type==="FunctionDeclaration"||n.type==="FunctionExpression"||n.type==="ArrowFunctionExpression")){if(n.type==="ReturnStatement"&&n.argument){e.push(n.argument);return}for(let i of Object.keys(n)){if(i==="type")continue;let s=n[i];Array.isArray(s)?s.forEach(r):s&&typeof s=="object"&&s.type&&r(s)}}}return r(t),e}function Mr(t,e){if(t){if(t.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&!t.callee.computed&&t.callee.object?.type==="Identifier"&&t.callee.property?.type==="Identifier"&&(t.callee.property.name==="new"||t.callee.property.name==="copy")&&e.isUdtTypeName(t.callee.object.name))return t.callee.object.name;if(t.type==="CallExpression"&&t.callee?.type==="Identifier"){let r=e.getFunctionReturnType(t.callee.name);if(r)return r}if(t.type==="ConditionalExpression"){let r=Mr(t.consequent,e),n=Mr(t.alternate,e);if(r&&r===n)return r}}}function A_(t,e){mt(t,{VariableDeclaration(r){r.declarations.forEach(n=>{let i=n.init&&n.init.type==="MemberExpression"&&n.init.object&&(n.init.object.name==="context"||n.init.object.name===fe||n.init.object.name==="context2"),s=n.init&&n.init.type==="MemberExpression"&&n.init.object?.object&&(n.init.object.object.name==="context"||n.init.object.object.name===fe||n.init.object.object.name==="context2");(i||s)&&(n.id.name&&e.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(a=>{a.key.name&&e.addContextBoundVar(a.key.name)}))})}})}function T_(t,e,r=!1){t.params.forEach(n=>{n.type==="Identifier"&&r&&e.addContextBoundVar(n.name,r)})}function D_(t,e){let r;return qo(t,{FunctionDeclaration(n){n.id&&n.id.name&&(e.addReservedName(n.id.name),e.addUserFunction(n.id.name),n.id.name.startsWith("$M_")||e.addRegularUserFunction(n.id.name))},ExpressionStatement(n){let i=n.expression;if(i&&i.type==="AssignmentExpression"&&i.operator==="="&&i.left?.type==="MemberExpression"&&i.left.property?.name==="__pineMethod__"&&i.left.object?.type==="Identifier"&&i.right?.value===!0){let s=i.left.object.name,a=s.startsWith("$M_")?s.slice(3):s;e.addUserMethod(a),e.addUserFunction(a)}},ArrowFunctionExpression(n){let i=n.start===0;i&&n.params&&n.params.length>0&&(r=n.params[0].name,n.params[0].name=fe),T_(n,e,i)},VariableDeclaration(n,i){let s=i.length>1?i[i.length-2]:null,a=s&&(s.type==="ForOfStatement"||s.type==="ForInStatement")&&s.left===n;n.declarations.forEach(o=>{if(o.id.type==="Identifier")e.addReservedName(o.id.name);else if(o.id.type==="ObjectPattern")o.id.properties.forEach(l=>{l.key&&l.key.type==="Identifier"&&e.addReservedName(l.key.name)});else if(o.id.type==="ArrayPattern"){if(o.id.elements?.forEach(p=>{p&&p.type==="Identifier"&&e.addReservedName(p.name)}),a)return;let l=e.generateTempVar(),c={type:"VariableDeclaration",kind:n.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:l},init:o.init}]},u=c.declarations[0].init;u&&u.type==="CallExpression"&&(u.callee.type==="ArrowFunctionExpression"||u.callee.type==="FunctionExpression")&&mt(u.callee.body,{ReturnStatement(p){p.argument&&p.argument.type==="ArrayExpression"&&(p.argument={type:"ArrayExpression",elements:[p.argument]})}}),o.id.elements?.forEach(p=>{p.type==="Identifier"&&e.addArrayPatternElement(p.name)});let h=o.id.elements.map((p,d)=>({type:"VariableDeclaration",kind:n.kind,declarations:[{type:"VariableDeclarator",id:p,init:{type:"MemberExpression",object:{type:"Identifier",name:l},property:{type:"Literal",value:d},computed:!0}}]}));Object.assign(n,{type:"BlockStatement",body:[c,...h]})}})},ForStatement(n){}}),r}var M_=Object.defineProperty,P_=(t,e,r)=>e in t?M_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,R_=(t,e,r)=>P_(t,typeof e!="symbol"?e+"":e,r),F_=new Set(["bar_index","last_bar_index","time","time_close","timenow","year","month","weekofyear","dayofmonth","dayofweek","hour","minute","second"]),B_=new Set(["input.int","math.floor","math.ceil","array.size","matrix.rows","matrix.columns","str.length","timestamp","ta.barssince","ta.highestbars","ta.lowestbars"]);function L_(t){return t&&t.type==="Literal"&&typeof t.value=="number"&&Number.isInteger(t.value)&&!(typeof t.raw=="string"&&/[.eE]/.test(t.raw))}function O_(t){return t?t.type==="Identifier"?t.name:t.type==="MemberExpression"&&!t.computed&&t.object?.type==="Identifier"&&t.property?.type==="Identifier"?`${t.object.name}.${t.property.name}`:null:null}var ji=class{constructor(){R_(this,"stack",[new Map])}push(){this.stack.push(new Map)}pop(){this.stack.length>1&&this.stack.pop()}set(e,r){this.stack[this.stack.length-1].set(e,r)}get(e){for(let r=this.stack.length-1;r>=0;r--){let n=this.stack[r].get(e);if(n!==void 0)return n}}assign(e,r){for(let n=this.stack.length-1;n>=0;n--)if(this.stack[n].has(e)){let i=this.stack[n].get(e);this.stack[n].set(e,i==="int"&&r==="int"?"int":"notint");return}this.stack[this.stack.length-1].set(e,r)}};function V_(t,e){let r=new ji;function n(s){if(!s||typeof s!="object")return"notint";switch(s.type){case"Literal":return typeof s.value=="number"&&L_(s)?"int":"notint";case"Identifier":return F_.has(s.name)?"int":r.get(s.name)??"notint";case"UnaryExpression":return s.operator==="-"||s.operator==="+"?n(s.argument):(n(s.argument),"notint");case"BinaryExpression":{let a=n(s.left),o=n(s.right),l=a==="int"&&o==="int";if(s.operator==="/"){if(l){let c=S.createMathIntDivCall(s.left,s.right);return Object.assign(s,c),"int"}return"notint"}return(s.operator==="+"||s.operator==="-"||s.operator==="*"||s.operator==="%")&&l?"int":"notint"}case"ConditionalExpression":{n(s.test);let a=n(s.consequent),o=n(s.alternate);return a==="int"&&o==="int"?"int":"notint"}case"LogicalExpression":return n(s.left),n(s.right),"notint";case"CallExpression":{s.callee?.type==="MemberExpression"&&n(s.callee.object);for(let o of s.arguments||[])n(o);let a=O_(s.callee);return a&&B_.has(a)?"int":"notint"}case"MemberExpression":return n(s.object),s.computed&&n(s.property),"notint";case"VariableDeclaration":{for(let a of s.declarations||[]){let o=a.init?n(a.init):"notint";a.id?.type==="Identifier"&&r.set(a.id.name,o)}return"notint"}case"AssignmentExpression":{let a=n(s.right);return s.left?.type==="Identifier"?r.assign(s.left.name,a):n(s.left),a}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":{r.push();for(let a of s.params||[]){let o=a.type==="AssignmentPattern"?a.left:a;o?.type==="Identifier"&&r.set(o.name,"notint")}return n(s.body),r.pop(),"notint"}default:return i(s),"notint"}}function i(s){for(let a in s){if(a==="type"||a==="start"||a==="end"||a==="loc"||a==="raw")continue;let o=s[a];if(Array.isArray(o))for(let l of o)l&&typeof l.type=="string"&&n(l);else o&&typeof o.type=="string"&&n(o)}}n(t)}var Cn={type:"Identifier",name:"undefined"};function Pr(t,e){let r={type:"Identifier",name:`\'${e}\'`};if(!t.isInsideFunctionScope())return r;let[n]=t.getVariable("$$");return n?{type:"BinaryExpression",operator:"+",left:S.createMemberExpression(S.createLocalContextIdentifier(),S.createIdentifier("id")),right:r}:r}function ke(t,e){let[r,n]=e.getVariable(t);if((r.match(/^fn\\d+_/)||e.isVariableInFunctionScope(t))&&t!=="$$"){let[i]=e.getVariable("$$");if(i)return S.createLocalContextVariableReference(n,r)}return S.createContextVariableReference(n,r)}function $i(t,e){let r=ke(t,e);return S.createGetCall(r,0)}function rr(t,e){if(t.computed&&t.property.type==="Identifier"){if(e.isLoopVariable(t.property.name)){if(t.object.type==="Identifier"&&!e.isLoopVariable(t.object.name)){if(e.isLocalSeriesVar(t.object.name)){let r=S.createIdentifier(t.object.name);r._skipTransformation=!0;let n=S.createGetCall(r,t.property);Object.assign(t,n),t._indexTransformed=!0;return}if(!e.isContextBound(t.object.name)){let r=ke(t.object.name,e),n=S.createGetCall(r,t.property);Object.assign(t,n),t._indexTransformed=!0}}return}if(!e.isContextBound(t.property.name))if(e.isLocalSeriesVar(t.property.name)){let r=S.createIdentifier(t.property.name);r._skipTransformation=!0,t.property=S.createGetCall(r,0)}else t.property=ke(t.property.name,e),t.property=S.createGetCall(t.property,0)}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(e.isLocalSeriesVar(t.object.name)){let r=S.createIdentifier(t.object.name);r._skipTransformation=!0;let n=S.createGetCall(r,t.property);Object.assign(t,n),t._indexTransformed=!0;return}if(e.isContextBound(t.object.name)||(t.object=ke(t.object.name,e)),t.property.type==="MemberExpression"){let r=t.property;r._indexTransformed||(rr(r,e),r._indexTransformed=!0)}}t.computed&&t.property.type!=="Identifier"&&t.property.type!=="MemberExpression"&&!t._indexTransformed&&(t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression")&&(t.property=Ct(t.property,e))}function Ve(t,e){let r=S.createGetCall(S.createIdentifier(t.name),0);t.start!==void 0&&(r.start=t.start),t.end!==void 0&&(r.end=t.end),r._indexTransformed=!0,Object.assign(t,r)}function Ce(t,e){if(!t._skipTransformation&&t.name!==fe){if(yt.includes(t.name)&&e.isContextBound(t.name)){let p=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,d=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&!t.parent.computed;if(!p&&!d){let f={type:"MemberExpression",object:{type:"Identifier",name:t.name},property:{type:"Identifier",name:"__value"},computed:!1},m=S.createGetCall(f,0);Object.assign(t,m),delete t.name;return}}if(t.name==="Math"||t.name==="NaN"||t.name==="undefined"||t.name==="Infinity"||t.name==="null"||t.name.startsWith("\'")&&t.name.endsWith("\'")||t.name.startsWith(\'"\')&&t.name.endsWith(\'"\')||t.name.startsWith("`")&&t.name.endsWith("`")||e.isLoopVariable(t.name))return;let r=!1;if(t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t)){let p=t.parent.callee;if(p.type==="MemberExpression"&&p.object&&p.object.name===fe&&["get","set","init","param","call"].includes(p.property.name)){let d=t.parent.arguments.indexOf(t);p.property.name==="call"?d>=2&&(r=!0):d===0&&(r=!0)}else{let d=p.type==="MemberExpression"&&p.object&&p.object.type==="Identifier"&&$t.includes(p.object.name);p.type==="MemberExpression"&&!d?r=!1:r=!0}}let n=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&e.isContextBound(t.name),i=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.property.name==="param";t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left;let s=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,a=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.object===t,o=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.property===t&&t.parent.parent&&t.parent.parent.type==="CallExpression"&&t.parent.parent.callee&&t.parent.parent.callee.type==="MemberExpression"&&e.isContextBound(t.parent.parent.callee.object.name);if(n||i||r||o||s){if(s||t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.object&&t.parent.callee.object.name===fe&&t.parent.callee.property.name==="call"&&t.parent.arguments[0]===t||e.isLocalSeriesVar(t.name)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;let p=ke(t.name,e);Object.assign(t,p);return}let l=e.isContextBound(t.name)&&!e.isRootParam(t.name);if(l){let p=t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t),d=t.parent&&t.parent.type==="SwitchStatement"&&t.parent.discriminant===t,f=t.parent&&t.parent.type==="SwitchCase"&&t.parent.test===t;if(!p&&!d&&!f)return}if(e.isLocalSeriesVar(t.name)){if(!a){let p=S.createIdentifier(t.name),d=S.createGetCall(p,0);Object.assign(t,d)}return}let[c,u]=e.getVariable(t.name),h;if(l)h=S.createIdentifier(t.name);else{if(c===t.name&&!e.isContextBound(t.name))return;h=ke(t.name,e)}if(a)Object.assign(t,h);else{let p=S.createGetCall(h,0);Object.assign(t,p)}}}function ge(t,e,r){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;if(t.computed&&t.object&&t.object.type==="CallExpression"&&!t._historyTransformed){t.object._transformed||ve(t.object,r);let l=r.generateParamId(),c={type:"CallExpression",callee:S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("param")),arguments:[t.object,Cn,Pr(r,l)],_transformed:!0,_isParamCall:!0},u=S.createGetCall(c,t.property);u._transformed=!0,u._historyTransformed=!0,Object.assign(t,u),delete t.object,delete t.property,delete t.computed;return}if(t.object&&t.object.type==="Identifier"&&$t.includes(t.object.name)&&r.isContextBound(t.object.name)&&!t.computed){let l=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,c=t.parent&&(t.parent.type==="VariableDeclarator"&&(t.parent.id.type==="ArrayPattern"||t.parent.id.type==="ObjectPattern")||t.parent.type==="AssignmentExpression"&&(t.parent.left.type==="ArrayPattern"||t.parent.left.type==="ObjectPattern")||t.parent.type==="Property");if(!l&&!c){let u={type:"CallExpression",callee:{type:"MemberExpression",object:t.object,property:t.property,computed:!1},arguments:[],_transformed:!1};t.start!==void 0&&(u.start=t.start),t.end!==void 0&&(u.end=t.end),Object.assign(t,u);return}}if(!t.computed&&t.object&&t.object.type==="Identifier"&&r.isLocalSeriesVar(t.object.name)){let l=S.createIdentifier(t.object.name);l._skipTransformation=!0,t.object=S.createGetCall(l,0);return}let n=r.getCurrentScopeType()=="if",i=r.getCurrentScopeType()=="els",s=r.getCurrentScopeType()=="for";if(!n&&!i&&!s&&t.object&&t.object.type==="Identifier"&&r.isContextBound(t.object.name)&&!r.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(rr(t,r),t._indexTransformed=!0);let a=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&(t.object.object.object.name===fe||t.object.object.object.name==="$$"),o=t.object&&t.object.type==="Identifier"&&r.isContextBound(t.object.name);if(t.computed&&(a||o)){if(t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left===t)return;t.object.type==="Identifier"&&yt.includes(t.object.name)&&r.isContextBound(t.object.name)&&(t.object={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1});let l=S.createGetCall(t.object,t.property);t.start&&(l.start=t.start),t.end&&(l.end=t.end),Object.assign(t,l),delete t.object,delete t.property,delete t.computed;return}if(t.computed&&t.object&&t.object.type==="MemberExpression"){let l=t.object;for(;l.object&&l.object.type==="MemberExpression";)l=l.object;if(l.object&&l.object.type==="Identifier"&&r.isUdtInstance(l.object.name)){let c=l.object.name,u=r.isLocalSeriesVar(c)?(()=>{let p=S.createIdentifier(c);return p._skipTransformation=!0,p})():ke(c,r);l.object=S.createGetCall(u,t.property);let h=t.object;Object.assign(t,h),delete t.computed;return}}}function Rr(t,e){if(t.type==="Identifier"){if(yt.includes(t.name)&&e.isContextBound(t.name)){let s=t.name;return Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:s},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name,t}if(e.isLoopVariable(t.name))return t;if(e.isRootParam(t.name)){let[s,a]=e.getVariable(t.name);return S.createContextVariableReference(a,s)}if(e.isContextBound(t.name))return t;let[r,n]=e.getVariable(t.name),i=r!==t.name;return e.isLocalSeriesVar(t.name)&&!i?t:i?ke(t.name,e):r===t.name&&!e.isContextBound(t.name)?t:ke(t.name,e)}return t}function Ct(t,e,r=""){switch(t.type){case"BinaryExpression":return sn(t,e,r);case"LogicalExpression":return an(t,e,r);case"MemberExpression":{let n=!t.computed&&t.object.type==="Identifier"&&yt.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&yt.includes(t.object.name)&&e.isContextBound(t.object.name)){let a={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1};return S.createGetCall(a,t.property)}let i=t.object.type==="Identifier"&&!n?Rr(t.object,e):t.object,s=i;if(!t.computed&&t.object.type==="Identifier"&&!n){let[a]=e.getVariable(t.object.name);a!==t.object.name&&!e.isLoopVariable(t.object.name)&&(s=S.createGetCall(i,0))}return{type:"MemberExpression",object:s,property:t.property,computed:t.computed}}case"Identifier":{if(e.isLoopVariable(t.name)||t.parent&&t.parent.type==="MemberExpression"&&t.parent.property===t)return t;let n=Rr(t,e);return n.type==="Identifier"&&(n.name==="NaN"||n.name==="undefined"||n.name==="Infinity"||n.name==="null"||n.name==="Math")?n:S.createGetCall(n,0)}case"UnaryExpression":return on(t,e,r);case"ConditionalExpression":{let n=Ct(t.test,e,r),i=Ct(t.consequent,e,r),s=Ct(t.alternate,e,r);return{type:"ConditionalExpression",test:n,consequent:i,alternate:s,start:t.start,end:t.end}}}return t}function sn(t,e,r){let n=Ct(t.left,e,r),i=Ct(t.right,e,r),s={type:"BinaryExpression",operator:t.operator,left:n,right:i,start:t.start,end:t.end};return Ne(s,e,{CallExpression(a,o){a._transformed||ve(a,o)},MemberExpression(a){ge(a,"",e)}}),s}function an(t,e,r){let n=Ct(t.left,e,r),i=Ct(t.right,e,r),s={type:"LogicalExpression",operator:t.operator,left:n,right:i,start:t.start,end:t.end};return Ne(s,e,{CallExpression(a,o){a._transformed||ve(a,o)}}),s}function li(t,e,r){Ne(t,{parent:t,inNamespaceCall:!1},{Identifier(a,o,l){if(a.name=="NaN")return;if(yt.includes(a.name)&&e.isContextBound(a.name)){if(o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===a&&!o.parent.computed)return;let u={type:"MemberExpression",object:{type:"Identifier",name:a.name},property:{type:"Identifier",name:"__value"},computed:!1},h=S.createGetCall(u,0);Object.assign(a,h),delete a.name;return}a.parent=o.parent,Ce(a,e);let c=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||c)&&(a.type==="MemberExpression"?rr(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===fe&&a.parent.callee.property.name==="get"||Ve(a)))},MemberExpression(a,o,l){ge(a,"",e),a.object&&l(a.object,{parent:a,inNamespaceCall:o.inNamespaceCall})},ConditionalExpression(a,o,l){let c={...o,parent:a};a.test&&l(a.test,c),a.consequent&&l(a.consequent,c),a.alternate&&l(a.alternate,c)},BinaryExpression(a,o,l){let c={...o,parent:a};l(a.left,c),l(a.right,c)},LogicalExpression(a,o,l){let c={...o,parent:a};l(a.left,c),l(a.right,c)},UnaryExpression(a,o,l){let c={...o,parent:a};l(a.argument,c)},CallExpression(a,o,l){let c=a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&a.callee.object.type==="Identifier"&&e.isContextBound(a.callee.object.name);ve(a,e),a.arguments.forEach(u=>l(u,{parent:a,inNamespaceCall:c||o.inNamespaceCall}))}});let n=S.createMemberExpression(S.createIdentifier(r),S.createIdentifier("param")),i=e.generateParamId(),s={type:"CallExpression",callee:n,arguments:[t,Cn,Pr(e,i)],_transformed:!0,_isParamCall:!0};if(!e.shouldSuppressHoisting()){let a=i;e.addLocalSeriesVar(a);let o=S.createVariableDeclaration(a,s);return e.addHoistedStatement(o),S.createIdentifier(a)}return s}function on(t,e,r){let n=Ct(t.argument,e,r),i={type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:n,start:t.start,end:t.end};return Ne(i,e,{CallExpression(s,a){s._transformed||ve(s,a)},MemberExpression(s){ge(s,"",e)}}),i}function Ht(t,e,r){switch(t?.type){case"BinaryExpression":t=sn(t,r,e);break;case"LogicalExpression":t=an(t,r,e);break;case"ConditionalExpression":return li(t,r,e);case"UnaryExpression":t=on(t,r,e);break;case"ArrayExpression":t.elements=t.elements.map(c=>{if(c.type==="Identifier"){if(r.isContextBound(c.name)&&!r.isRootParam(c.name))return c;if(r.isLocalSeriesVar(c.name)){let u=S.createIdentifier(c.name);return S.createGetCall(u,0)}return $i(c.name,r)}return c.type==="CallExpression"?(ve(c,r),c):c.type==="BinaryExpression"?sn(c,r,e):c.type==="LogicalExpression"?an(c,r,e):c.type==="ConditionalExpression"?li(c,r,e):c.type==="UnaryExpression"?on(c,r,e):(c.type==="MemberExpression"&&ge(c,e,r),c)});break}let n=t.type==="MemberExpression"&&t.computed&&t.property,i=t.type==="MemberExpression"&&!t.computed;if(n){if(t.object&&t.object.type==="MemberExpression"){let f=t.object;for(;f.object&&f.object.type==="MemberExpression";)f=f.object;if(f.object?.type==="Identifier"&&r.isUdtInstance(f.object.name)){let m=f.object.name,x=r.isLocalSeriesVar(m)?(()=>{let b=S.createIdentifier(m);return b._skipTransformation=!0,b})():ke(m,r);return f.object=S.createGetCall(x,t.property),t.object}}if(t.object.type==="CallExpression")ve(t.object,r);else if(t.object.type==="MemberExpression"){ge(t.object,"",r);let f=t.object;for(;f&&f.type==="MemberExpression"&&f.object;){if(f.object.type==="Identifier"){let m=f.object,[x]=r.getVariable(m.name);x!==m.name&&!r.isContextBound(m.name)&&!r.isRootParam(m.name)&&!r.isLoopVariable(m.name)&&!r.isLocalSeriesVar(m.name)&&!yt.includes(m.name)&&!$t.includes(m.name)&&(f.object=$i(m.name,r));break}f=f.object}}else t.object.type==="BinaryExpression"?t.object=sn(t.object,r,e):t.object.type==="LogicalExpression"?t.object=an(t.object,r,e):t.object.type==="ConditionalExpression"?t.object=li(t.object,r,e):t.object.type==="UnaryExpression"&&(t.object=on(t.object,r,e));let c=t.object.type==="Identifier"&&r.isContextBound(t.object.name)&&!r.isRootParam(t.object.name)?t.object:Rr(t.object,r),u;t.property.type==="Identifier"&&!r.isContextBound(t.property.name)&&!r.isLoopVariable(t.property.name)?u=S.createGetCall(Rr(t.property,r),0):t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression"?u=Ct(t.property,r,e):u=t.property;let h=S.createMemberExpression(S.createIdentifier(e),S.createIdentifier("param")),p=r.generateParamId(),d={type:"CallExpression",callee:h,arguments:[c,u,Pr(r,p)],_transformed:!0,_isParamCall:!0};if(!r.shouldSuppressHoisting()){let f=p;r.addLocalSeriesVar(f);let m=S.createVariableDeclaration(f,d);return r.addHoistedStatement(m),S.createIdentifier(f)}return d}if(i){if(t.object.type==="Identifier"&&$t.includes(t.object.name)&&r.isContextBound(t.object.name)&&!t.computed){let c=t.object.name,u={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:t.property.name},computed:!1},arguments:[],_transformed:!0};c==="ta"&&u.arguments.push(r.getNextTACallId());let h=r.generateTempVar();r.addLocalSeriesVar(h);let p=S.createVariableDeclaration(h,u);return r.addOuterHoistedStatement(p),Object.assign(t,S.createIdentifier(h)),t}if(t.object.type==="Identifier"){let c=t.object.name,[u,h]=r.getVariable(c);if(u!==c&&!r.isLoopVariable(c)){let p=ke(c,r),d=S.createGetCall(p,0);t.object=d}else if(r.isLocalSeriesVar(c)){let p=S.createIdentifier(c);p._skipTransformation=!0,t.object=S.createGetCall(p,0)}}else t.object.type==="MemberExpression"?Ht(t.object,e,r):t.object.type==="CallExpression"&&(t.object._transformed||ve(t.object,r))}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(c=>c.value.name?r.isContextBound(c.value.name)||r.isLocalSeriesVar(c.value.name)||r.isLoopVariable(c.value.name)?{type:"Property",key:{type:"Identifier",name:c.key.name},value:S.createIdentifier(c.value.name),kind:"init",method:!1,shorthand:!1,computed:!1}:{type:"Property",key:{type:"Identifier",name:c.key.name},value:ke(c.value.name,r),kind:"init",method:!1,shorthand:!1,computed:!1}:(c.value.type!=="Literal"&&(c.value=Ht(c.value,e,r)),c))),t.type==="Identifier"){if(yt.includes(t.name)&&r.isContextBound(t.name)){let c=t.name;Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name}else if(r.isContextBound(t.name)&&!r.isRootParam(t.name)){let c=S.createMemberExpression(S.createIdentifier(e),S.createIdentifier("param")),u=r.generateParamId(),h={type:"CallExpression",callee:c,arguments:[t,Cn,Pr(r,u)],_transformed:!0,_isParamCall:!0};if(!r.shouldSuppressHoisting()){let p=u;r.addLocalSeriesVar(p);let d=S.createVariableDeclaration(p,h);return r.addHoistedStatement(d),S.createIdentifier(p)}return h}}t?.type==="CallExpression"&&ve(t,r);let s=S.createMemberExpression(S.createIdentifier(e),S.createIdentifier("param")),a=t.type==="Identifier"?Rr(t,r):t,o=r.generateParamId(),l={type:"CallExpression",callee:s,arguments:[a,Cn,Pr(r,o)],_transformed:!0,_isParamCall:!0};if(!r.shouldSuppressHoisting()){let c=o;r.addLocalSeriesVar(c);let u=S.createVariableDeclaration(c,l);return r.addHoistedStatement(u),S.createIdentifier(c)}return l}function Sr(t){if(!t)return!1;if(Ho(t))return!0;if(t.type==="MemberExpression")return Sr(t.object);if(t.type==="ChainExpression")return Sr(t.expression);if(t.type==="CallExpression"){let e=t.callee;if(e?.type==="MemberExpression")return Sr(e.object);if(e?.type==="ChainExpression")return Sr(e.expression)}return!1}function Ho(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function Wi(t,e,r){t&&(t.type==="Identifier"?(t.parent=e,Ce(t,r)):t.type==="MemberExpression"?Wi(t.object,t,r):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&Wi(t.callee.object,t.callee,r),t._transformed||ve(t,r)))}function ve(t,e,r){if(t._transformed)return;t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&($t.includes(t.callee.name)||yt.includes(t.callee.name))&&e.isContextBound(t.callee.name)&&(t.callee=S.createMemberExpression(t.callee,S.createIdentifier("any")));let n=t.callee&&t.callee.type==="MemberExpression"&&t.callee.object&&t.callee.object.type==="Identifier"&&(e.isContextBound(t.callee.object.name)||t.callee.object.name==="math"||t.callee.object.name==="ta");if(n){if(t.callee.object.name===fe&&["get","init","param"].includes(t.callee.property.name))return;let i=t.callee.object.name,s=[];t.arguments.forEach(p=>{if(p._isParamCall){s.push(p);return}s.push(Ht(p,i,e))}),t.arguments=s;let a=t.callee.property.name,o=`${i}.${a}`;if(ha.includes(i)||ha.includes(o)){let p=e.getNextPlotCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:p,kind:"init",computed:!1,shorthand:!1}]})}if(i==="input"&&t._varId!==void 0&&t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__varId"},value:{type:"Literal",value:t._varId},kind:"init",computed:!1,shorthand:!1}]}),i==="alert"){let p=e.getNextAlertCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:p,kind:"init",computed:!1,shorthand:!1}]})}if(i==="ta")if(e.getCurrentScopeType()==="fn"){let p=e.getNextTACallId(),[d]=e.getVariable("$$"),f;d?f=S.createMemberExpression(S.createLocalContextIdentifier(),S.createIdentifier("id")):f=S.createLiteral("");let m={type:"BinaryExpression",operator:"+",left:f,right:p};t.arguments.push(m)}else t.arguments.push(e.getNextTACallId());let l=t.callee.property.name,c=`${i}.${l}`,u=y_.includes(c),h=t._insideAwait===!0;if(u&&!h){let p=Object.assign({},t),d=S.createAwaitExpression(p);Object.assign(t,d)}if(!e.shouldSuppressHoisting()){let p=e.generateTempVar();e.addLocalSeriesVar(p);let d=t._insideAwait===!0,f=Object.assign({},t);d&&(f=S.createAwaitExpression(f));let m=S.createVariableDeclaration(p,f);e.addHoistedStatement(m);let x=S.createIdentifier(p);Object.assign(t,x),t._wasHoisted=!0,t._wasInsideAwait=d;return}t._transformed=!0}else if(t.callee&&t.callee.type==="Identifier"){if(t.arguments=t.arguments.map(i=>i._isParamCall?i:Ht(i,fe,e)),!e.isContextBound(t.callee.name)){let i=e.getNextUserCallId(),s=S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("call")),a=t.callee.name,o=t.callee;e.isUserMethod(a)&&!e.isRegularUserFunction(a)&&(o=S.createIdentifier(`$M_${a}`),o._skipTransformation=!0);let l=[o,i,...t.arguments];t.callee=s,t.arguments=l}t._transformed=!0}if(!n&&t.callee&&t.callee.type==="MemberExpression"){let i=t.callee.property.name,s=e.isUserFunction(i),a=t.callee.object,o=a.type==="Identifier"&&e.isLocalSeriesVar(a.name),l=a.type==="MemberExpression",c=e.isUserMethod(i),u=!!a.name&&e.isUdtInstance(a.name);if(s&&c&&!e.isContextBound(i)&&!o&&!l&&u){let h=t.callee.object;t.callee.property;let p=t.arguments.map(w=>w._isParamCall?w:Ht(w,fe,e)),d=h;h.type==="Identifier"?d=Ht(h,fe,e):h.type==="CallExpression"&&(ve(h,e),d=Ht(h,fe,e));let f=S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("call")),m=e.getNextUserCallId(),x=S.createIdentifier(`$M_${i}`);x._skipTransformation=!0;let b=[x,m,d,...p];t.callee=f,t.arguments=b,t._transformed=!0;return}t.callee.object.type==="Identifier"?Ce(t.callee.object,e):Wi(t.callee.object,t.callee,e)}if(t.arguments.forEach(i=>{Ne(i,{parent:t},{Identifier(s,a,o){s.parent=a.parent,Ce(s,e);let l=s.parent&&s.parent.type==="BinaryExpression";(s.parent&&s.parent.type==="ConditionalExpression"||l)&&(s.type==="MemberExpression"?rr(s,e):s.type==="Identifier"&&(s.parent&&s.parent.type==="CallExpression"&&s.parent.callee&&s.parent.callee.object&&s.parent.callee.object.name===fe&&s.parent.callee.property.name==="get"||Ve(s)))},BinaryExpression(s,a,o){let l={...a,parent:s};o(s.left,l),o(s.right,l)},LogicalExpression(s,a,o){let l={...a,parent:s};o(s.left,l),o(s.right,l)},UnaryExpression(s,a,o){let l={...a,parent:s};o(s.argument,l)},CallExpression(s,a,o){s.callee&&s.callee.type==="MemberExpression"&&s.callee.object&&(s.callee.object.parent=s.callee,o(s.callee.object,{parent:s.callee})),s._transformed||ve(s,e)},MemberExpression(s,a,o){ge(s,"",e),s.object&&o(s.object,{parent:s})}})}),t.callee&&t.callee.type==="MemberExpression"){let i=t.callee.object,s=Ho(i),a=i?.type==="MemberExpression"&&Sr(i);if(s||a){let o=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:o},t.optional=!0}}}function Ss(t){let e={type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:t},init:{type:"Literal",value:0}}]},r={type:"IfStatement",test:{type:"BinaryExpression",operator:">",_skipCompare:!0,left:{type:"UpdateExpression",operator:"++",prefix:!0,argument:{type:"Identifier",name:t}},right:{type:"Identifier",name:"__maxLoops"}},consequent:{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[{type:"Literal",value:`Loop exceeded maximum iterations (${t})`}]}},alternate:null};return{counterDecl:e,guardCheck:r}}function Nn(t,e){let r=null;if(t.left.type==="Identifier")r=ke(t.left.name,e);else if(t.left.type==="MemberExpression"&&t.left.computed){if(t.left.object.type==="Identifier"){let n=t.left.object.name,[i,s]=e.getVariable(n),a=i!==n,o=e.isContextBound(n);(a||o)&&!e.isLoopVariable(n)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(r=ke(n,e))}}else if(t.left.type==="MemberExpression"&&!t.left.computed){let n=null,i=t.left;for(;i.type==="MemberExpression"&&!i.computed;){if(i.object.type==="Identifier"){n=i;break}i=i.object}if(n){let s=n.object.name,[a,o]=e.getVariable(s);if(a!==s&&!e.isLoopVariable(s)){let l=ke(s,e),c=S.createGetCall(l,0);n.object=c}else if(e.isLocalSeriesVar(s)){let l=S.createIdentifier(s);l._skipTransformation=!0,n.object=S.createGetCall(l,0)}}}if(Ne(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(n,i,s){let a=i.parent&&i.parent.type==="MemberExpression"&&!i.parent.computed&&i.parent.object===n;if(yt.includes(n.name)&&e.isContextBound(n.name)&&!a){let m={type:"MemberExpression",object:{type:"Identifier",name:n.name},property:{type:"Identifier",name:"__value"},computed:!1},x=S.createGetCall(m,0);Object.assign(n,x),delete n.name;return}n.parent=i.parent,Ce(n,e);let o=n.parent&&n.parent.type==="BinaryExpression",l=n.parent&&n.parent.type==="ConditionalExpression",c=e.isContextBound(n.name)&&!e.isRootParam(n.name),u=n.parent&&n.parent.type==="MemberExpression"&&n.parent.computed&&n.parent.object===n,h=n.parent&&n.parent._isParamCall,p=n.parent&&n.parent.type==="MemberExpression",d=n.name==="NaN",f=n.parent&&n.parent.type==="CallExpression"&&n.parent.callee&&n.parent.callee.object&&n.parent.callee.object.name===fe&&n.parent.callee.property.name==="get";(c||l||o)&&(n.type==="MemberExpression"?rr(n,e):n.type==="Identifier"&&!p&&!u&&!h&&!d&&!f&&Ve(n))},MemberExpression(n,i,s){ge(n,"",e),n.type==="CallExpression"?n.arguments.forEach(a=>s(a,{parent:n,inNamespaceCall:i.inNamespaceCall})):n.object&&s(n.object,{parent:n,inNamespaceCall:i.inNamespaceCall})},CallExpression(n,i,s){let a=n.callee&&n.callee.type==="MemberExpression"&&n.callee.object&&n.callee.object.type==="Identifier"&&e.isContextBound(n.callee.object.name);ve(n,e),n.type==="CallExpression"&&(n.callee.type==="MemberExpression"&&s(n.callee,{parent:n,inNamespaceCall:a||i.inNamespaceCall}),n.arguments.forEach(o=>s(o,{parent:n,inNamespaceCall:a||i.inNamespaceCall})))}}),r){let n=t.right;if(t.operator!=="="){let s=t.operator.replace("=",""),a=S.createGetCall(r,0);n={type:"BinaryExpression",operator:s,left:a,right:t.right,start:t.start,end:t.end}}let i=S.createSetCall(r,n);t.start&&(i.start=t.start),t.end&&(i.end=t.end),Object.assign(t,i)}}function Go(t,e){t._skipTransformation||t.declarations.forEach(r=>{if(r.init?.type==="CallExpression"&&r.id?.type==="Identifier"){let p=r.init.callee;(p?.type==="MemberExpression"&&p.object?.type==="Identifier"&&p.object.name==="input"||p?.type==="Identifier"&&p.name==="input")&&(r.init._varId=r.id.name)}if(r.init&&r.init.type==="Identifier"&&yt.includes(r.init.name)&&e.isContextBound(r.init.name)){let p=r.init.name;Object.assign(r.init,{type:"MemberExpression",object:{type:"Identifier",name:p},property:{type:"Identifier",name:"__value"},computed:!1}),delete r.init.name}let n=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===fe||r.init.object.name==="context2"),i=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===fe||r.init.object.object.name==="context2"),s=r.init&&r.init.type==="ArrowFunctionExpression";if(n){r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),r.init.object.name=fe;return}if(i){r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),r.init.object.object.name=fe;return}e.addVariable(r.id.name,t.kind);let a=t.kind,o=e.isArrayPatternElement(r.id.name)&&r.init&&r.init.type==="MemberExpression"&&r.init.computed;r.init&&!s&&!o&&(r.init.type==="CallExpression"&&r.init.callee.type==="MemberExpression"&&r.init.callee.object&&r.init.callee.object.type==="Identifier"&&e.isContextBound(r.init.callee.object.name)?ve(r.init,e):Ne(r.init,{parent:r.init},{Identifier(p,d){p.parent=d.parent,Ce(p,e);let f=p.parent&&p.parent.type==="BinaryExpression",m=p.parent&&p.parent.type==="UnaryExpression",x=p.parent&&p.parent.type==="ConditionalExpression",b=p.parent&&p.parent.type==="CallExpression"&&p.parent.callee&&p.parent.callee.object&&p.parent.callee.object.name===fe&&p.parent.callee.property.name==="get";p.type==="Identifier"&&(f||m||x)&&!b&&Ve(p)},CallExpression(p,d,f){p.callee.type==="Identifier"&&(p.callee.parent=p),p.arguments.forEach(m=>{m.type==="Identifier"&&(m.parent=p)}),(p.callee.type==="ArrowFunctionExpression"||p.callee.type==="FunctionExpression")&&f(p.callee,{parent:p}),ve(p,e),p.type==="CallExpression"&&(p.callee.type==="MemberExpression"&&f(p.callee,{parent:p}),p.arguments.forEach(m=>f(m,{parent:p})))},BinaryExpression(p,d,f){p.left.type==="Identifier"&&(p.left.parent=p),p.right.type==="Identifier"&&(p.right.parent=p),f(p.left,{parent:p}),f(p.right,{parent:p})},LogicalExpression(p,d,f){p.left.type==="Identifier"&&(p.left.parent=p),p.right.type==="Identifier"&&(p.right.parent=p),f(p.left,{parent:p}),f(p.right,{parent:p})},UnaryExpression(p,d,f){p.argument.type==="Identifier"&&(p.argument.parent=p),f(p.argument,{parent:p})},MemberExpression(p,d,f){p.object&&p.object.type==="Identifier"&&(p.object.parent=p),p.property&&p.property.type==="Identifier"&&(p.property.parent=p),ge(p,"",e),p.type==="CallExpression"?p.arguments.forEach(m=>f(m,{parent:p})):p.object&&f(p.object,{parent:p})},AwaitExpression(p,d,f){p.argument&&(p.argument._insideAwait=!0,f(p.argument,{parent:p}),p.argument.type==="Identifier"&&p.argument._wasInsideAwait&&Object.assign(p,p.argument))},ArrowFunctionExpression(p,d,f){if(p.body)if(p.body.type==="BlockStatement"){let m=[];p.body.body.forEach(x=>{e.enterHoistingScope(),f(x,{parent:p.body,insideIIFE:!0});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),p.body.body=m}else f(p.body,{parent:p,insideIIFE:!0})},FunctionExpression(p,d,f){if(p.body&&p.body.type==="BlockStatement"){let m=[];p.body.body.forEach(x=>{e.enterHoistingScope(),f(x,{parent:p.body,insideIIFE:!0});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),p.body.body=m}},SwitchStatement(p,d,f){p.discriminant&&(p.discriminant.parent=p,f(p.discriminant,{parent:p})),p.cases&&p.cases.forEach(m=>{m.parent=p,f(m,{parent:p})})},SwitchCase(p,d,f){if(p.test&&(p.test.parent=p,f(p.test,{parent:p})),p.consequent){let m=[];p.consequent.forEach(x=>{e.enterHoistingScope(),x.parent=p,f(x,{parent:p});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),p.consequent=m}},AssignmentExpression(p,d,f){if(d.insideIIFE){if(p.left.type==="Identifier"){let[m]=e.getVariable(p.left.name);if(m===p.left.name&&!e.isContextBound(p.left.name)){f(p.right,{parent:p});return}}Nn(p,e)}}}));let l=ke(r.id.name,e),c=!o&&r.init&&r.init.type==="MemberExpression"&&r.init.computed&&r.init.property&&(r.init.property.type==="Literal"||r.init.property.type==="MemberExpression");if(r.init?.property?.type==="MemberExpression"&&(r.init.property._indexTransformed||(rr(r.init.property,e),r.init.property._indexTransformed=!0)),a==="var"){let p=e.getCurrentHoistingScope();if(p){for(let d of p)if(d.type==="VariableDeclaration")for(let f of d.declarations){if(!f.init||f.init.type!=="CallExpression")continue;let m=f.init.callee;if(m?.type!=="MemberExpression")continue;let x,b=m.property?.name;if(m.object?.type==="Identifier"?x=m.object.name:m.object?.type==="MemberExpression"&&m.object.property?.name&&(x=m.object.property.name),x&&b){let w=`${x}.${b}`;__.includes(w)&&(f.init={type:"ArrowFunctionExpression",params:[],body:f.init,expression:!0,async:!1})}}}}let u;r.init?s||o?u=r.init:a==="var"?u=S.createInitVarCall(l,r.init):u=S.createInitCall(l,c?r.init.object:r.init,c?r.init.property:void 0):u=S.createIdentifier("undefined");let h=S.createExpressionStatement(S.createAssignmentExpression(l,u));if(o){let p=r.init.object.name,d=ke(p,e),f=r.init.property.value,m={type:"MemberExpression",object:S.createGetCall(d,0),property:{type:"Literal",value:f},computed:!0};h.expression.right=S.createCallExpression(S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("init")),[l,m])}s&&(e.pushScope("fn"),Ne(r.init.body,e,{IfStatement(p,d,f){d.pushScope("if"),p.test&&Yo(p.test,d),f(p.consequent,d),p.alternate&&(d.pushScope("els"),f(p.alternate,d),d.popScope()),d.popScope()},VariableDeclaration(p,d){Go(p,d)},Identifier(p,d){Ce(p,d)},AssignmentExpression(p,d){Nn(p,d)},SwitchStatement(p,d,f){p.discriminant.parent=p,f(p.discriminant,d),p.cases.forEach(m=>{m.parent=p,f(m,d)})},SwitchCase(p,d,f){p.test&&(p.test.parent=p,f(p.test,d));let m=[];p.consequent.forEach(x=>{d.enterHoistingScope(),f(x,d);let b=d.exitHoistingScope();m.push(...b),m.push(x)}),p.consequent=m},BlockStatement(p,d,f){let m=[];p.body.forEach(x=>{d.enterHoistingScope(),f(x,d);let b=d.exitHoistingScope();m.push(...b),m.push(x)}),p.body=m}}),e.popScope()),Object.assign(t,h)})}function j_(t,e,r){if(e.setSuppressHoisting(!0),t.init&&t.init.type==="VariableDeclaration"){let s=t.init.declarations[0],a=s.id.name;e.addLoopVariable(a,a),t.init={type:"VariableDeclaration",kind:t.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:s.init}]},s.init&&Ne(s.init,e,{Identifier(o,l){!e.isLoopVariable(o.name)&&!o.computed&&(e.pushScope("for"),Ce(o,l),o.type==="Identifier"&&(e.isContextBound(o.name)&&o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===o||(o.computed=!0,Ve(o))),e.popScope())},MemberExpression(o,l,c){e.pushScope("for"),ge(o,"",e),e.popScope(),o.type==="MemberExpression"&&o.object&&(o.object.type!=="Identifier"||!e.isContextBound(o.object.name))&&c(o.object,l)},CallExpression(o,l,c){o.callee.parent=o,c(o.callee,l);for(let u of o.arguments)c(u,l)}})}t.test&&Ne(t.test,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),Ce(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,Ve(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),ge(s,"",e),e.popScope(),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){s.callee.parent=s,o(s.callee,a);for(let l of s.arguments)o(l,a)}}),t.update&&Ne(t.update,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),Ce(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,Ve(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),ge(s,"",e),e.popScope(),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){s.callee.parent=s,o(s.callee,a);for(let l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);let n=e.getNextLoopGuardName(),i=Ss(n);if(e.addHoistedStatement(i.counterDecl),e.pushScope("for"),r(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(i.guardCheck),t.init&&t.init.type==="VariableDeclaration"){let s=t.init.declarations[0];e.removeLoopVariable(s.id.name)}}function $_(t,e,r){e.setSuppressHoisting(!0),t.test&&Ne(t.test,e,{Identifier(s,a){s.computed||(Ce(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,Ve(s))))},MemberExpression(s,a,o){ge(s,"",e),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){if(s.callee.parent=s,o(s.callee,a),ve(s,a),s.arguments)for(let l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);let n=e.getNextLoopGuardName(),i=Ss(n);e.addHoistedStatement(i.counterDecl),e.pushScope("whl"),r(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(i.guardCheck)}function Yo(t,e){Ne(t,e,{MemberExpression(r,n,i){r.object&&r.object.type==="Identifier"&&!e.isContextBound(r.object.name)&&!r.computed&&(r.object.parent=r,i(r.object,n)),ge(r,"",e)},CallExpression(r,n){ve(r,n)},BinaryExpression(r,n,i){r.left.type==="Identifier"&&(r.left.parent=r),r.right.type==="Identifier"&&(r.right.parent=r),i(r.left,n),i(r.right,n)},LogicalExpression(r,n,i){r.left.type==="Identifier"&&(r.left.parent=r),r.right.type==="Identifier"&&(r.right.parent=r),i(r.left,n),i(r.right,n)},UnaryExpression(r,n,i){r.argument.type==="Identifier"&&(r.argument.parent=r),i(r.argument,n)},Identifier(r,n){let i=r.parent,s=i&&i.type==="UnaryExpression",a=i&&i.type==="BinaryExpression",o=i&&i.type==="LogicalExpression",l=i&&i.type==="ConditionalExpression";Ce(r,n),r.type==="Identifier"&&(s||a||o||l)&&(i&&i.type==="CallExpression"&&i.callee&&i.callee.object&&i.callee.object.name===fe&&i.callee.property?.name==="get"||Ve(r));let c=e.getCurrentScopeType()==="if";e.isContextBound(r.name)&&!e.isRootParam(r.name)&&c&&Ve(r)}})}function W_(t,e,r){t.test&&(e.pushScope("if"),Yo(t.test,e),e.popScope()),e.pushScope("if"),r(t.consequent,e),e.popScope(),t.alternate&&(e.pushScope("els"),r(t.alternate,e),e.popScope())}function U_(t,e){let r=e.getCurrentScopeType();if(t.argument){if(t.argument.type==="ArrayExpression")t.argument.elements=t.argument.elements.map(n=>n.type==="Identifier"?e.isContextBound(n.name)&&!e.isRootParam(n.name)?S.createGetCall(n,0):$i(n.name,e):n.type==="MemberExpression"?n.object&&n.object.type==="MemberExpression"&&n.object.object&&n.object.object.type==="Identifier"&&n.object.object.name==="$"&&n.object.property&&["const","let","var","params"].includes(n.object.property.name)?S.createGetCall(n,0):(ge(n,"",e),n):((n.type==="BinaryExpression"||n.type==="LogicalExpression"||n.type==="ConditionalExpression"||n.type==="CallExpression"||n.type==="UnaryExpression")&&Ne(n,e,{Identifier(i,s){Ce(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(Ve(i),i._arrayAccessed=!0)},MemberExpression(i){ge(i,"",e)},CallExpression(i,s,a){(i.callee.type==="ArrowFunctionExpression"||i.callee.type==="FunctionExpression")&&a(i.callee,s),ve(i,s),i.type==="CallExpression"&&i.arguments.forEach(o=>a(o,s))},BinaryExpression(i,s,a){a(i.left,s),a(i.right,s)}}),n)),t.argument={type:"ArrayExpression",elements:[t.argument]};else if(t.argument.type==="ObjectExpression")t.argument.properties=t.argument.properties.map(n=>n.shorthand?e.isContextBound(n.value.name)?n:(e.getVariable(n.value.name),{type:"Property",key:S.createIdentifier(n.key.name),value:ke(n.value.name,e),kind:"init",method:!1,shorthand:!1,computed:!1}):(n.value&&n.value.type==="Identifier"&&(e.isContextBound(n.value.name)&&!e.isRootParam(n.value.name)||e.isContextBound(n.value.name)||(n.value=ke(n.value.name,e))),n));else if(t.argument.type==="Identifier")Ce(t.argument,e),t.argument.type==="Identifier"&&Ve(t.argument);else if(t.argument.type==="MemberExpression"){if(t.argument.object.type==="Identifier"&&!e.isContextBound(t.argument.object.name)&&!e.isLoopVariable(t.argument.object.name)&&!(t.argument.computed&&e.isLocalSeriesVar(t.argument.object.name)))Ce(t.argument.object,e);else if(t.argument.computed&&t.argument.object.type==="MemberExpression"){let n=t.argument.object;for(;n.object&&n.object.type==="MemberExpression";)n=n.object;n.object?.type==="Identifier"&&e.isUdtInstance(n.object.name)&&ge(t.argument,"",e)}}if(r==="fn"){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=S.createArrayAccess(t.argument,0):t.argument.type==="MemberExpression"?t.argument.computed&&t.argument.object.type==="CallExpression"?ge(t.argument,"",e):t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)?t.argument.computed?ge(t.argument,"",e):t.argument._indexTransformed||(rr(t.argument,e),t.argument._indexTransformed=!0):t.argument.computed&&t.argument.object.type==="Identifier"&&e.isLocalSeriesVar(t.argument.object.name)&&ge(t.argument,"",e):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression"||t.argument.type==="UnaryExpression"||t.argument.type==="AssignmentExpression")&&Ne(t.argument,e,{Identifier(i,s){Ce(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(Ve(i),i._arrayAccessed=!0)},MemberExpression(i){ge(i,"",e)},AssignmentExpression(i,s){Nn(i,s)},CallExpression(i,s,a){(i.callee.type==="ArrowFunctionExpression"||i.callee.type==="FunctionExpression")&&a(i.callee,s),ve(i,s),i.type==="CallExpression"&&i.arguments.forEach(o=>a(o,s))},BinaryExpression(i,s,a){a(i.left,s),a(i.right,s)},ArrowFunctionExpression(i,s,a){if(i.body)if(i.body.type==="BlockStatement"){let o=[];i.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.body.body=o}else a(i.body,s)},FunctionExpression(i,s,a){if(i.body&&i.body.type==="BlockStatement"){let o=[];i.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.body.body=o}},SwitchStatement(i,s,a){i.discriminant.parent=i,a(i.discriminant,s),i.cases.forEach(o=>{o.parent=i,a(o,s)})},SwitchCase(i,s,a){i.test&&(i.test.parent=i,a(i.test,s));let o=[];i.consequent.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.consequent=o},BlockStatement(i,s,a){let o=[];i.body.forEach(l=>{s.enterHoistingScope(),a(l,s);let c=s.exitHoistingScope();o.push(...c),o.push(l)}),i.body=o}});let n=S.createCallExpression(S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("precision")),[t.argument]);t.argument=n}}}function q_(t,e,r){let n=S.createVariableDeclaration("$$",S.createCallExpression(S.createMemberExpression(S.createContextIdentifier(),S.createIdentifier("peekCtx")),[]));if(n._skipTransformation=!0,e.addLoopVariable("$$","$$"),t.body&&t.body.type==="BlockStatement"){t.body.body.unshift(n),e.pushScope("fn"),t.params.forEach(l=>{l.type==="Identifier"&&e.addLocalSeriesVar(l.name)});let i=t.id?.name,s=i?.startsWith("$M_")?i.slice(3):i,a=s?e.getFunctionParamUdtTypes(s):void 0,o={};if(a)for(let[l,c]of Object.entries(a))o[l]=e.getVariableUdtType(l),e.markVariableAsUdtInstance(l,c);if(r(t.body,e),t.params.forEach(l=>{l.type==="Identifier"&&e.removeLocalSeriesVar(l.name)}),a)for(let l of Object.keys(a)){e.unmarkVariableAsUdtInstance(l);let c=o[l];c!==void 0&&e.markVariableAsUdtInstance(l,c)}e.popScope()}}function z_(t){let e={...I,LineComment:()=>{}};function r(o){return o?o.type==="Identifier"?o.name:o.type==="CallExpression"&&o.callee?.type==="MemberExpression"&&o.callee.object?.name==="$"&&o.callee.property?.name==="get"&&o.arguments?.[0]?.type==="Identifier"?o.arguments[0].name:null:null}let n=new Map;mt(t,{FunctionDeclaration(o){o.id?.name&&n.set(o.id.name,o)}},e);function i(o){let l=!1,c={...e,FunctionDeclaration:()=>{},FunctionExpression:()=>{},ArrowFunctionExpression:()=>{}};return mt(o,{AwaitExpression(){l=!0}},c),l}let s=!0,a=0;for(;s&&a<20;){s=!1,a++,mt(t,{ArrowFunctionExpression(c){!c.async&&i(c.body)&&(c.async=!0,s=!0)},FunctionExpression(c){!c.async&&i(c.body)&&(c.async=!0,s=!0)}},e);let o=[];mt(t,{CallExpression(c){!c._asyncWrapped&&(c.callee?.type==="ArrowFunctionExpression"||c.callee?.type==="FunctionExpression")&&c.callee.async===!0&&o.push(c)}},e);for(let c of o){let u={};for(let h of Object.keys(c))u[h]=c[h];u._asyncWrapped=!0;for(let h of Object.keys(c))delete c[h];c.type="AwaitExpression",c.argument=u,s=!0}let l=new Set;for(let[c,u]of n)i(u.body)&&(u.async||(u.async=!0,s=!0),l.add(c));if(l.size>0){let c=[];mt(t,{CallExpression(u){if(!u._asyncWrapped&&u.callee?.type==="MemberExpression"&&u.callee.object?.name==="$"&&u.callee.property?.name==="call"&&u.arguments?.length>0){let h=r(u.arguments[0]);h&&l.has(h)&&c.push(u)}}},e);for(let u of c){let h={};for(let p of Object.keys(u))h[p]=u[p];h._asyncWrapped=!0;for(let p of Object.keys(u))delete u[p];u.type="AwaitExpression",u.argument=h,s=!0}}}}var K_={"==":"__eq","===":"__eq","!=":"__neq","!==":"__neq","<":"__lt","<=":"__le",">":"__gt",">=":"__ge"},H_=new Set(["<","<=",">",">="]);function G_(t,e){if(t._skipCompare)return!0;for(let r=0;r<e.length-1;r++){let n=e[r],i=e[r+1];if(n.type==="ForStatement"&&(i===n.test||i===n.update)||(n.type==="WhileStatement"||n.type==="DoWhileStatement")&&i===n.test)return!0}return!1}function Y_(t){let e={...I,LineComment:()=>{}};qo(t,{BinaryExpression(r,n,i){let s=K_[r.operator];if(!s||H_.has(r.operator)&&G_(r,i))return;let a=S.createMathCompareCall(s,r.left,r.right);a._transformed=!0,Object.assign(r,a)}},e)}function Z_(t,e,r,n={debug:!1,ln:!1},i=[]){let s=a=>{if(!n.debug||!a.loc||!i.length)return null;let o=a.loc.start.line-1;if(o>=0&&o<i.length){let l=i[o].trim();if(l)return{type:"LineComment",value:`${n.ln?` [Line ${a.loc.start.line}]`:""} ${l}`}}return null};Ne(t,e,{Program(a,o,l){let c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);let h=o.exitHoistingScope(),p=s(u);p&&c.push(p),c.push(...h),c.push(u)}),a.body=c},BlockStatement(a,o,l){let c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);let h=o.exitHoistingScope(),p=s(u);p&&c.push(p),c.push(...h),c.push(u)}),a.body=c},ReturnStatement(a,o,l){a.argument&&a.argument.type!=="ArrayExpression"&&a.argument.type!=="ObjectExpression"&&a.argument.type!=="Identifier"&&a.argument.type!=="MemberExpression"&&o.getCurrentScopeType()!=="fn"&&l(a.argument,o),U_(a,o)},VariableDeclaration(a,o){Go(a,o)},Identifier(a,o){Ce(a,o)},CallExpression(a,o,l){a.callee&&(a.callee.type==="ArrowFunctionExpression"||a.callee.type==="FunctionExpression")?l(a.callee,o):a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&(a.callee.object.parent=a.callee,l(a.callee.object,o)),ve(a,o)},ArrowFunctionExpression(a,o,l){a.body&&l(a.body,o)},FunctionExpression(a,o,l){a.body&&l(a.body,o)},ForOfStatement(a,o,l){if(a.left&&a.left.type==="VariableDeclaration"){a.left._skipTransformation=!0;let h=a.left.declarations[0];h.id.type==="Identifier"?o.addLoopVariable(h.id.name,h.id.name):h.id.type==="ArrayPattern"&&h.id.elements.forEach(p=>{p.type==="Identifier"&&o.addLoopVariable(p.name,p.name)})}if(a.right){a.right.type==="Identifier"?(Ce(a.right,o),a.right.type==="Identifier"&&Ve(a.right)):l(a.right,o);let h=a.left&&a.left.type==="VariableDeclaration"&&a.left.declarations[0].id.type==="ArrayPattern"?"entries":"iter",p={...a.right},d=S.createCallExpression(S.createMemberExpression(S.createIdentifier("$"),S.createIdentifier(h),!1),[p]);Object.assign(a.right,d)}let c=o.getNextLoopGuardName(),u=Ss(c);if(o.addHoistedStatement(u.counterDecl),a.body&&l(a.body,o),a.body&&a.body.type==="BlockStatement"&&a.body.body.unshift(u.guardCheck),a.left&&a.left.type==="VariableDeclaration"){let h=a.left.declarations[0];h.id.type==="Identifier"?o.removeLoopVariable(h.id.name):h.id.type==="ArrayPattern"&&h.id.elements.forEach(p=>{p.type==="Identifier"&&o.removeLoopVariable(p.name)})}},ForInStatement(a,o,l){a.left&&a.left.type==="VariableDeclaration"&&(a.left._skipTransformation=!0),a.right&&a.right.type==="Identifier"?(Ce(a.right,o),a.right.type==="Identifier"&&Ve(a.right)):a.right&&l(a.right,o),a.body&&l(a.body,o)},MemberExpression(a,o,l){a.object&&(a.object.type==="CallExpression"||a.object.type==="MemberExpression")&&(a.object.parent=a,l(a.object,o)),a.object&&a.object.type==="Identifier"&&!o.isContextBound(a.object.name)&&(a.object.parent=a,l(a.object,o)),ge(a,r,o)},AssignmentExpression(a,o,l){if(Nn(a,o),a.type==="CallExpression"&&a.arguments){let c=u=>{u&&(u.type==="CallExpression"&&u.callee&&(u.callee.type==="ArrowFunctionExpression"||u.callee.type==="FunctionExpression")&&l(u.callee,o),u.type==="BinaryExpression"&&(c(u.left),c(u.right)))};a.arguments.forEach(u=>c(u))}},FunctionDeclaration(a,o,l){q_(a,o,l)},ForStatement(a,o,l){j_(a,o,l)},WhileStatement(a,o,l){$_(a,o,l)},IfStatement(a,o,l){W_(a,o,l)},SwitchStatement(a,o,l){a.discriminant.parent=a,l(a.discriminant,o),a.cases.forEach(c=>{c.parent=a,l(c,o)})},SwitchCase(a,o,l){a.test&&(a.test.parent=a,l(a.test,o));let c=[];a.consequent.forEach(u=>{o.enterHoistingScope(),l(u,o);let h=o.exitHoistingScope();c.push(...h),c.push(u)}),a.consequent=c},AwaitExpression(a,o,l){a.argument&&(a.argument._insideAwait=!0,l(a.argument,o),a.argument.type==="Identifier"&&a.argument._wasInsideAwait===!0&&(a.type="Identifier",a.name=a.argument.name,a.argument._wasHoisted&&(a._wasHoisted=a.argument._wasHoisted),delete a.argument))}})}var _={NUMBER:"NUMBER",STRING:"STRING",BOOLEAN:"BOOLEAN",IDENTIFIER:"IDENTIFIER",KEYWORD:"KEYWORD",OPERATOR:"OPERATOR",LPAREN:"LPAREN",RPAREN:"RPAREN",LBRACKET:"LBRACKET",RBRACKET:"RBRACKET",LBRACE:"LBRACE",RBRACE:"RBRACE",COMMA:"COMMA",DOT:"DOT",COLON:"COLON",SEMICOLON:"SEMICOLON",INDENT:"INDENT",DEDENT:"DEDENT",NEWLINE:"NEWLINE",COMMENT:"COMMENT",EOF:"EOF"},X_=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","import","export","method","extends","enum"]),Q_=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"],Ui=class{constructor(e,r,n,i,s=0,a=null){this.type=e,this.value=r,this.line=n,this.column=i,this.indent=s,this.raw=a}},J_=Object.defineProperty,e0=(t,e,r)=>e in t?J_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_t=(t,e,r)=>e0(t,typeof e!="symbol"?e+"":e,r),qi=class{constructor(e){_t(this,"source"),_t(this,"pos"),_t(this,"line"),_t(this,"column"),_t(this,"tokens"),_t(this,"indentStack"),_t(this,"atLineStart"),_t(this,"parenDepth"),_t(this,"bracketDepth"),_t(this,"braceDepth"),this.source=e,this.pos=0,this.line=1,this.column=1,this.tokens=[],this.indentStack=[0],this.atLineStart=!0,this.parenDepth=0,this.bracketDepth=0,this.braceDepth=0}tokenize(){for(;this.pos<this.source.length;){let e=this.peek();if(e==="\\r"){this.advance();continue}if(e===`\n`){this.handleNewline();continue}if(this.atLineStart&&e!==`\n`){this.handleIndentation(),this.atLineStart=!1;continue}if(e===" "||e===" "){this.advance();continue}if(this.pos>=this.source.length)break;if(e==="/"&&this.peek(1)==="/"){this.readComment();continue}if(e===\'"\'||e==="\'"){this.readString();continue}if(e==="#"){this.readColorLiteral();continue}if(this.isDigit(e)){this.readNumber();continue}if(this.isIdentifierStart(e)){this.readIdentifier();continue}if(!this.readOperatorOrPunctuation())throw new Error(`Unexpected character \'${e}\' at ${this.line}:${this.column}`)}for(;this.indentStack.length>1;)this.indentStack.pop(),this.addToken(_.DEDENT,"",this.getCurrentIndent());return this.addToken(_.EOF,""),this.tokens}handleNewline(){this.parenDepth===0&&this.bracketDepth===0&&this.braceDepth===0&&(this.addToken(_.NEWLINE,`\n`),this.atLineStart=!0),this.advance(),this.line++,this.column=1}handleIndentation(){let e=0,r=0;for(this.pos;this.pos<this.source.length;){let i=this.peek();if(i===" ")r++,this.advance();else if(i===" ")e++,this.advance();else break}if(this.peek()===`\n`||this.peek()==="\\r"||this.peek()==="\\0"||(e+=Math.floor(r/4),this.isContinuationFromPrevToken()))return;let n=this.indentStack[this.indentStack.length-1];if(e>n)this.indentStack.push(e),this.addToken(_.INDENT,"",e);else if(e<n){for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>e;)this.indentStack.pop(),this.addToken(_.DEDENT,"",this.indentStack[this.indentStack.length-1]);if(this.indentStack[this.indentStack.length-1]!==e)throw new Error(`Indentation error at ${this.line}:${this.column} - misaligned dedent`)}}isContinuationFromPrevToken(){for(let e=this.tokens.length-1;e>=0;e--){let r=this.tokens[e];if(!(r.type===_.NEWLINE||r.type===_.COMMENT))return r.type===_.OPERATOR?r.value!=="=>":r.type===_.COMMA||r.type===_.COLON||r.type===_.KEYWORD&&(r.value==="and"||r.value==="or")}return!1}readComment(){this.column;let e="";for(this.advance(),this.advance();this.pos<this.source.length&&this.peek()!==`\n`;)e+=this.advance();this.addToken(_.COMMENT,e.trim())}readString(){let e=this.advance(),r=this.column-1,n="";for(;this.pos<this.source.length&&this.peek()!==e;)if(this.peek()==="\\\\"){this.advance();let i=this.advance();switch(i){case"n":n+=`\n`;break;case"t":n+=" ";break;case"r":n+="\\r";break;case"\\\\":n+="\\\\";break;case e:n+=e;break;default:n+=i}}else n+=this.advance();if(this.peek()!==e)throw new Error(`Unterminated string at ${this.line}:${r}`);this.advance(),this.addToken(_.STRING,n)}readColorLiteral(){let e=this.column,r="#";for(this.advance();this.pos<this.source.length&&r.length<9;){let n=this.peek();if(n>="0"&&n<="9"||n>="A"&&n<="F"||n>="a"&&n<="f")r+=this.advance();else break}if(r.length!==7&&r.length!==9)throw new Error(`Invalid color literal \'${r}\' at ${this.line}:${e}`);this.addToken(_.STRING,r)}readNumber(){this.column;let e="",r=!1;for(this.peek()==="."&&this.isDigit(this.peek(1))&&(r=!0,e+=this.advance());this.pos<this.source.length;){let n=this.peek();if(this.isDigit(n))e+=this.advance();else if(n==="."&&!r){let i=this.peek(1);if(this.isDigit(i)||!this.isIdentifierStart(i)){if(r=!0,e+=this.advance(),!this.isDigit(this.peek()))break}else break}else break}if(this.pos<this.source.length){let n=this.peek();if(n==="e"||n==="E"){let i=this.peek(1);if(this.isDigit(i))for(e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance();else if(i==="+"||i==="-"){let s=this.peek(2);if(this.isDigit(s))for(e+=this.advance(),e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance()}}}this.addToken(_.NUMBER,parseFloat(e),null,e)}readIdentifier(){this.column;let e="";for(;this.pos<this.source.length&&this.isIdentifierChar(this.peek());)e+=this.advance();X_.has(e)?this.addToken(_.KEYWORD,e):e==="true"||e==="false"?this.addToken(_.BOOLEAN,e==="true"):this.addToken(_.IDENTIFIER,e)}readOperatorOrPunctuation(){let e=this.peek(),r=this.peek(1),n=e+r;if(Q_.includes(n))return this.advance(),this.advance(),this.addToken(_.OPERATOR,n),!0;if("+-*/%<>=!?".includes(e))return this.advance(),this.addToken(_.OPERATOR,e),!0;switch(e){case"(":return this.parenDepth++,this.advance(),this.addToken(_.LPAREN,e),!0;case")":return this.parenDepth--,this.advance(),this.addToken(_.RPAREN,e),!0;case"[":return this.bracketDepth++,this.advance(),this.addToken(_.LBRACKET,e),!0;case"]":return this.bracketDepth--,this.advance(),this.addToken(_.RBRACKET,e),!0;case"{":return this.braceDepth++,this.advance(),this.addToken(_.LBRACE,e),!0;case"}":return this.braceDepth--,this.advance(),this.addToken(_.RBRACE,e),!0;case",":return this.advance(),this.addToken(_.COMMA,e),!0;case".":return this.isDigit(this.peek(1))?(this.readNumber(),!0):(this.advance(),this.addToken(_.DOT,e),!0);case":":return this.advance(),this.addToken(_.COLON,e),!0;case";":return this.advance(),this.addToken(_.SEMICOLON,e),!0}return!1}peek(e=0){let r=this.pos+e;return r<this.source.length?this.source[r]:"\\0"}advance(){let e=this.source[this.pos++];return this.column++,e}skipWhitespaceInline(){if(!this.atLineStart)for(;this.pos<this.source.length&&(this.peek()===" "||this.peek()===" ");)this.advance()}isDigit(e){return e>="0"&&e<="9"}isIdentifierStart(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e==="_"}isIdentifierChar(e){return this.isIdentifierStart(e)||this.isDigit(e)}getCurrentIndent(){return this.indentStack[this.indentStack.length-1]}addToken(e,r,n=null,i=null){let s=new Ui(e,r,this.line,this.column,n!==null?n:this.getCurrentIndent(),i);this.tokens.push(s)}},t0=Object.defineProperty,r0=(t,e,r)=>e in t?t0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ye=(t,e,r)=>r0(t,typeof e!="symbol"?e+"":e,r),ie=class{constructor(e){this.type=e}},zi=class extends ie{constructor(e){super("Program"),this.body=e}},qe=class extends ie{constructor(e){super("ExpressionStatement"),this.expression=e}},At=(t=>(t.VAR="var",t.LET="let",t.CONST="const",t))(At||{}),ut=class extends ie{constructor(e,r="let"){super("VariableDeclaration"),this.declarations=e,this.kind=r}},rt=class extends ie{constructor(e,r,n=null){super("VariableDeclarator"),this.id=e,this.init=r,this.varType=n}},kn=class extends ie{constructor(e,r,n,i=null){super("FunctionDeclaration"),this.id=e,this.params=r,this.body=n,this.returnType=i}},Ki=class extends ie{constructor(e,r){super("TypeDefinition"),this.name=e,this.fields=r}},Hi=class extends ie{constructor(e,r,n=null){super("IfStatement"),this.test=e,this.consequent=r,this.alternate=n,Ye(this,"_line")}},In=class extends ie{constructor(e,r,n,i){super("ForStatement"),this.init=e,this.test=r,this.update=n,this.body=i,Ye(this,"isForIn")}},Gi=class extends ie{constructor(e,r){super("WhileStatement"),this.test=e,this.body=r}},vt=class extends ie{constructor(e){super("BlockStatement"),this.body=e}},An=class extends ie{constructor(e){super("ReturnStatement"),this.argument=e}},be=class extends ie{constructor(e){super("Identifier"),this.name=e,Ye(this,"varType"),Ye(this,"returnType"),Ye(this,"isMethod")}},Tt=class extends ie{constructor(e,r=null){super("Literal"),this.value=e,this.raw=r}},pt=class extends ie{constructor(e,r,n){super("BinaryExpression"),this.operator=e,this.left=r,this.right=n}},Tn=class extends ie{constructor(e,r,n=!0){super("UnaryExpression"),this.operator=e,this.argument=r,this.prefix=n}},Gt=class extends ie{constructor(e,r,n){super("AssignmentExpression"),this.operator=e,this.left=r,this.right=n}},Dn=class extends ie{constructor(e,r,n=!1){super("UpdateExpression"),this.operator=e,this.argument=r,this.prefix=n}},Yi=class extends ie{constructor(e,r){super("CallExpression"),this.callee=e,this.args=r,Ye(this,"arguments"),this.callee=e,this.arguments=r}},Mn=class extends ie{constructor(e,r,n=!1){super("MemberExpression"),this.object=e,this.property=r,this.computed=n}},wt=class extends ie{constructor(e,r,n){super("ConditionalExpression"),this.test=e,this.consequent=r,this.alternate=n,Ye(this,"needsIIFE"),Ye(this,"consequentStmts"),Ye(this,"alternateStmts")}},Zi=class extends ie{constructor(e){super("ArrayExpression"),this.elements=e}},Pn=class extends ie{constructor(e){super("ObjectExpression"),this.properties=e}},Rn=class extends ie{constructor(e,r){super("Property"),this.key=e,this.value=r,Ye(this,"kind"),Ye(this,"method"),Ye(this,"shorthand"),Ye(this,"computed"),this.kind="init",this.method=!1,this.shorthand=!1,this.computed=!1}},Fn=class extends ie{constructor(e){super("ArrayPattern"),this.elements=e}},Bn=class extends ie{constructor(e,r){super("AssignmentPattern"),this.left=e,this.right=r}},Xi=class extends ie{constructor(e,r){super("SwitchExpression"),this.discriminant=e,this.cases=r}},Qi=class extends ie{constructor(e,r,n){super("SwitchCase"),this.test=e,this.consequent=r,this.statements=n,this.statements=n}},n0=Object.defineProperty,i0=(t,e,r)=>e in t?n0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hr=(t,e,r)=>i0(t,typeof e!="symbol"?e+"":e,r),Zo=class Ji{constructor(e){hr(this,"tokens"),hr(this,"pos"),hr(this,"functionNames",new Set),hr(this,"paramScopes",[]),hr(this,"noLineContinuation",!1),this.tokens=e,this.pos=0}peek(e=0){return this.tokens[this.pos+e]||this.tokens[this.tokens.length-1]}isCurrentFunctionParam(e){for(let r of this.paramScopes)if(r.has(e))return!0;return!1}advance(){return this.tokens[this.pos++]}match(e,r=null){let n=this.peek();return!(n.type!==e||r!==null&&n.value!==r)}expect(e,r=null){let n=this.peek();if(n.type!==e)throw new Error(`Expected ${e} but got ${n.type} at ${n.line}:${n.column}`);if(r!==null&&n.value!==r)throw new Error(`Expected \'${r}\' but got \'${n.value}\' at ${n.line}:${n.column}`);return this.advance()}expectIdentifierOrContextual(){let e=this.peek();if(e.type===_.IDENTIFIER)return this.advance();if(e.type===_.KEYWORD&&Ji.CONTEXTUAL_KEYWORDS.has(e.value))return this.advance();throw new Error(`Expected ${_.IDENTIFIER} but got ${e.type} at ${e.line}:${e.column}`)}matchEx(e,r=null,n=!1){if(!n)return this.match(e,r);let i=0,s=this.peek(i);if(s.type===_.NEWLINE&&this.noLineContinuation||(s.type===_.NEWLINE&&(i++,s=this.peek(i),s.type===_.INDENT&&(i++,s=this.peek(i))),s.type!==e)||r!==null&&s.value!==r)return!1;for(let a=0;a<i;a++)this.advance();return!0}peekOperatorEx(e){let r=0,n=this.peek(r),i=!1;if(n.type===_.NEWLINE){if(this.noLineContinuation)return null;r++,n=this.peek(r),n.type===_.INDENT&&(i=!0,r++,n=this.peek(r))}if(n.type!==_.OPERATOR||!e.includes(n.value)||i&&(n.value==="+"||n.value==="-"))return null;for(let s=0;s<r;s++)this.advance();return n.value}skipNewlines(e=!1){for(;this.match(_.NEWLINE)||this.match(_.COMMENT);)this.advance();e&&this.match(_.INDENT)&&this.advance()}parse(){let e=[];for(;!this.match(_.EOF);){if(this.skipNewlines(),this.match(_.DEDENT)){this.advance();continue}if(this.match(_.EOF))break;let r=this.parseStatement();r&&e.push(r),this.skipNewlines()}return new zi(e)}parseStatement(e=!0){this.skipNewlines();let r=this.peek().line;if(this.match(_.COMMENT))return this.advance(),null;let n;if(this.match(_.KEYWORD,"enum"))n=this.parseEnumDefinition();else if(this.match(_.KEYWORD,"type"))n=this.parseTypeDefinition();else if(this.match(_.KEYWORD,"var")||this.match(_.KEYWORD,"varip"))n=this.parseVarDeclaration();else if(this.match(_.KEYWORD,"method"))n=this.parseMethodDeclaration();else if(this.isFunctionDeclaration())n=this.parseFunctionDeclaration();else if(this.match(_.KEYWORD,"if"))n=this.parseIfStatement();else if(this.match(_.KEYWORD,"for"))n=this.parseForStatement();else if(this.match(_.KEYWORD,"while"))n=this.parseWhileStatement();else if(this.match(_.KEYWORD,"break")||this.match(_.KEYWORD,"continue")){let i=this.advance().value;n=new qe(new be(i))}else this.isTupleDestructuring()?n=this.parseTupleDestructuring():this.peek().type===_.IDENTIFIER&&this.isTypedVarDeclaration()&&(n=this.parseTypedVarDeclaration());if(!n){let i=this.parseExpression();if(this.match(_.OPERATOR)){let s=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(s)){this.advance(),this.skipNewlines(!0);let a=this.parseExpression();s==="="&&i.type==="Identifier"?n=new ut([new rt(i,a)],At.LET):n=new qe(new Gt(s===":="?"=":s,i,a))}else n=new qe(i)}else n=new qe(i)}if(n&&(n._line=r,e&&this.match(_.COMMA)&&this.peek().line===r)){let i=[n];for(;this.match(_.COMMA)&&this.peek().line===r;){this.advance(),this.skipNewlines(!0);let s=this.parseStatement(!1);s&&i.push(s)}return new vt(i)}return n}isFunctionDeclaration(){let e=this.pos;try{let r=0;if(this.peek(r).type===_.IDENTIFIER&&this.peek(r+1).type===_.IDENTIFIER&&r++,this.peek(r).type!==_.IDENTIFIER||(r++,this.peek(r).type!==_.LPAREN))return!1;r++;let n=1;for(;n>0&&this.peek(r).type!==_.EOF;)this.peek(r).type===_.LPAREN&&n++,this.peek(r).type===_.RPAREN&&n--,r++;for(;this.peek(r).type===_.NEWLINE;)r++;return this.peek(r).type===_.OPERATOR&&this.peek(r).value==="=>"}finally{this.pos=e}}parseTypeExpression(){let e=this.expect(_.IDENTIFIER).value;for(;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(_.OPERATOR,"<")){this.advance();let r=[];for(r.push(this.parseTypeExpression());this.match(_.COMMA);)this.advance(),this.skipNewlines(),r.push(this.parseTypeExpression());return this.expect(_.OPERATOR,">"),e+"<"+r.join(", ")+">"}return this.match(_.LBRACKET)&&this.peek(1).type===_.RBRACKET?(this.advance(),this.advance(),"array<"+e+">"):e}parseEnumDefinition(){this.expect(_.KEYWORD,"enum");let e=this.expect(_.IDENTIFIER).value;this.skipNewlines(),this.expect(_.INDENT);let r=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){if(this.match(_.COMMENT)){this.advance();continue}let s=this.expectIdentifierOrContextual().value,a=null;this.match(_.OPERATOR,"=")&&(this.advance(),a=this.expect(_.STRING).value),r.push({name:s,title:a}),this.skipNewlines()}this.match(_.DEDENT)&&this.advance();let n=r.map(s=>new Rn(new be(s.name),new Tt(s.title!==null?s.title:s.name))),i=new Pn(n);return new ut([new rt(new be(e),i)],At.CONST)}parseTypeDefinition(){this.expect(_.KEYWORD,"type");let e=this.expect(_.IDENTIFIER).value;this.match(_.OPERATOR,"=>")&&this.advance(),this.skipNewlines(),this.expect(_.INDENT);let r=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let n=this.parseTypeExpression(),i=this.expectIdentifierOrContextual().value,s=null;this.match(_.OPERATOR,"=")&&(this.advance(),this.skipNewlines(),s=this.parseExpression()),r.push({type:n,name:i,defaultValue:s}),this.skipNewlines()}return this.match(_.DEDENT)&&this.advance(),new Ki(e,r)}parseVarDeclaration(){let e=this.advance().value,r=null,n=null;if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.LBRACKET&&this.peek(2).type===_.RBRACKET)r=this.advance().value,this.advance(),r+="[]",this.advance(),n=this.expectIdentifierOrContextual().value;else if(this.peek().type===_.IDENTIFIER&&(this.peek(1).type===_.DOT||this.peek(1).type===_.IDENTIFIER||this.peek(1).type===_.OPERATOR&&this.peek(1).value==="<")){for(r=this.advance().value;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)this.advance(),r+="."+this.advance().value;if(this.match(_.LBRACKET)&&this.peek(1).type===_.RBRACKET)this.advance(),this.advance(),r+="[]",n=this.expectIdentifierOrContextual().value;else if(this.match(_.OPERATOR,"<")){for(this.advance(),r+="<";!this.match(_.OPERATOR,">");)if(this.match(_.IDENTIFIER))for(r+=this.advance().value;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)r+=".",this.advance(),r+=this.advance().value;else if(this.match(_.COMMA))r+=this.advance().value,this.skipNewlines();else break;this.match(_.OPERATOR,">")&&(r+=">",this.advance()),n=this.expectIdentifierOrContextual().value}else n=this.expectIdentifierOrContextual().value}else if(this.peek().type===_.IDENTIFIER)n=this.advance().value;else throw new Error(`Expected identifier after ${e} at ${this.peek().line}:${this.peek().column}`);this.functionNames.has(n)&&(n=n+"_var"),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let i=this.parseExpression(),s=new be(n);r&&(s.varType=r);let a=[new rt(s,i,r)];for(;this.match(_.COMMA)&&this.peek(1).type===_.KEYWORD&&(this.peek(1).value==="var"||this.peek(1).value==="varip");){this.advance();let o=this.parseVarDeclaration();a.push(...o.declarations)}return new ut(a,e)}isTypedVarDeclaration(){let e=0;if(this.peek(e).type!==_.IDENTIFIER)return!1;for(e++;this.peek(e).type===_.DOT&&this.peek(e+1).type===_.IDENTIFIER;)e+=2;if(this.peek(e).type===_.LBRACKET&&this.peek(e+1).type===_.RBRACKET)return e+=2,this.peek(e).type!==_.IDENTIFIER?!1:(e++,this.peek(e).type===_.OPERATOR&&this.peek(e).value==="=");if(this.peek(e).type===_.OPERATOR&&this.peek(e).value==="<"){e++;let r=1;for(;r>0&&this.peek(e).type!==_.EOF;)this.peek(e).type===_.OPERATOR&&this.peek(e).value==="<"?r++:this.peek(e).type===_.OPERATOR&&this.peek(e).value===">"&&r--,e++;return this.peek(e).type!==_.IDENTIFIER?!1:(e++,this.peek(e).type===_.OPERATOR&&this.peek(e).value==="=")}if(this.peek(e).type!==_.IDENTIFIER)return!1;for(e++;this.peek(e).type===_.IDENTIFIER;)e++;return this.peek(e).type===_.OPERATOR&&this.peek(e).value==="="}parseTypedVarDeclaration(){let e=this.advance().value;for(;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(_.LBRACKET)&&this.peek(1).type===_.RBRACKET)this.advance(),this.advance(),e+="[]";else if(this.match(_.OPERATOR,"<")){for(this.advance(),e+="<";!this.match(_.OPERATOR,">");)if(this.match(_.IDENTIFIER))for(e+=this.advance().value;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)e+=".",this.advance(),e+=this.advance().value;else if(this.match(_.COMMA))e+=this.advance().value,this.skipNewlines();else break;this.match(_.OPERATOR,">")&&(e+=">",this.advance())}else for(;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER;)e+=" "+this.advance().value;let r=this.expectIdentifierOrContextual().value;this.functionNames.has(r)&&(r=r+"_var"),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let n=this.parseExpression(),i=new be(r);i.varType=e;let s=[new rt(i,n,e)];for(;this.match(_.COMMA)&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type===_.OPERATOR&&this.peek(2).value==="=";){this.advance(),this.skipNewlines(!0);let a=this.expectIdentifierOrContextual().value;this.functionNames.has(a)&&(a=a+"_var"),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let o=this.parseExpression(),l=new be(a);l.varType=e,s.push(new rt(l,o,e))}return new ut(s,At.LET)}parseFunctionDeclaration(){let e=null;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&(e=this.advance().value);let r=this.expect(_.IDENTIFIER).value;this.functionNames.add(r),this.expect(_.LPAREN);let n=[];for(;!this.match(_.RPAREN)&&(this.skipNewlines(),!this.match(_.RPAREN));){let o=null;for(;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type!==_.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.OPERATOR&&this.peek(1).value==="<"){let u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.LBRACKET&&this.peek(2).type===_.RBRACKET){let u=this.parseTypeExpression();o=o?o+" "+u:u}let l=this.expectIdentifierOrContextual().value,c=new be(l);if(o&&(c.varType=o),this.match(_.OPERATOR,"=")){this.advance(),this.skipNewlines();let u=this.parseExpression();n.push(new Bn(c,u))}else n.push(c);this.match(_.COMMA)&&this.advance()}this.expect(_.RPAREN),this.skipNewlines(),this.expect(_.OPERATOR,"=>"),this.skipNewlines();let i=new Set;for(let o of n){let l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&i.add(l.name)}this.paramScopes.push(i);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}let a=new be(r);return e&&(a.returnType=e),new kn(a,n,s,e)}parseMethodDeclaration(){this.expect(_.KEYWORD,"method");let e=null;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type===_.LPAREN&&(e=this.advance().value);let r=this.expectIdentifierOrContextual().value;this.expect(_.LPAREN);let n=[];for(;!this.match(_.RPAREN)&&(this.skipNewlines(),!this.match(_.RPAREN));){let o=null;for(;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type!==_.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.OPERATOR&&this.peek(1).value==="<"){let u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.LBRACKET&&this.peek(2).type===_.RBRACKET){let u=this.parseTypeExpression();o=o?o+" "+u:u}let l=this.expectIdentifierOrContextual().value,c=new be(l);if(o&&(c.varType=o),this.match(_.OPERATOR,"=")){this.advance(),this.skipNewlines();let u=this.parseExpression();n.push(new Bn(c,u))}else n.push(c);this.match(_.COMMA)&&this.advance()}this.expect(_.RPAREN),this.skipNewlines(),this.expect(_.OPERATOR,"=>"),this.skipNewlines();let i=new Set;for(let o of n){let l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&i.add(l.name)}this.paramScopes.push(i);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}let a=new be(r);return e&&(a.returnType=e),a.isMethod=!0,new kn(a,n,s,e)}parseFunctionBody(){let e=[];if(!this.match(_.INDENT)){let r=this.parseExpression();return new vt([new An(r)])}for(this.advance();!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let r=this.parseStatementOrSequence();Array.isArray(r)?e.push(...r):r&&e.push(r)}return this.match(_.DEDENT)&&this.advance(),e.length>0&&this._addImplicitReturn(e),new vt(e)}_addImplicitReturn(e){let r=e[e.length-1];r.type==="ExpressionStatement"?e[e.length-1]=new An(r.expression):r.type==="IfStatement"&&this._addImplicitReturnToIf(r)}_addImplicitReturnToIf(e){e.consequent&&e.consequent.type==="BlockStatement"&&e.consequent.body.length>0&&this._addImplicitReturn(e.consequent.body),e.alternate&&(e.alternate.type==="IfStatement"?this._addImplicitReturnToIf(e.alternate):e.alternate.type==="BlockStatement"&&e.alternate.body.length>0&&this._addImplicitReturn(e.alternate.body))}parseStatementOrSequence(){this.pos;let e=this.peek().line;if(this.match(_.KEYWORD,"if")){let n=this.parseIfStatement();return n&&(n._line=e),n}if(this.match(_.KEYWORD,"for"))return this.parseForStatement();if(this.match(_.KEYWORD,"while"))return this.parseWhileStatement();if(this.match(_.KEYWORD,"break")||this.match(_.KEYWORD,"continue")){let n=this.advance().value;return new qe(new be(n))}if(this.match(_.KEYWORD,"var")||this.match(_.KEYWORD,"varip"))return this.parseVarDeclaration();if(this.isTupleDestructuring())return this.parseTupleDestructuring();if(this.peek().type===_.IDENTIFIER&&this.isTypedVarDeclaration()){let n=this.parseTypedVarDeclaration();if(this.match(_.COMMA)&&this.peek(1).type===_.IDENTIFIER){let i=[n];for(;this.match(_.COMMA);)if(this.advance(),this.skipNewlines(!0),this.peek().type===_.IDENTIFIER&&this.isTypedVarDeclaration())i.push(this.parseTypedVarDeclaration());else{let s=this.parseExpression();if(this.match(_.OPERATOR)){let a=this.peek().value;if(["=",":="].includes(a)){this.advance(),this.skipNewlines(!0);let o=this.parseExpression();a==="="&&s.type==="Identifier"?i.push(new ut([new rt(s,o)],At.LET)):i.push(new qe(new Gt(a===":="?"=":a,s,o)))}}break}return i}return n}let r=[];for(;;){let n=this.parseExpression();if(this.match(_.OPERATOR)){let i=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(i)){this.advance(),this.skipNewlines(!0);let s=this.parseExpression();if(i==="="&&n.type==="Identifier"?r.push(new ut([new rt(n,s)],At.LET)):r.push(new qe(new Gt(i===":="?"=":i,n,s))),this.match(_.COMMA)){this.advance(),this.skipNewlines();continue}break}else{if(r.length>0)r.push(new qe(n));else return new qe(n);break}}else if(this.match(_.COMMA)){r.push(new qe(n)),this.advance(),this.skipNewlines();continue}else{if(r.length>0)r.push(new qe(n));else return new qe(n);break}}return r.length>1?r:r.length===1?r[0]:null}parseIfStatement(){this.expect(_.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines();let r=this.parseBlock(),n=null;return this.skipNewlines(),this.match(_.KEYWORD,"else")&&(this.advance(),this.skipNewlines(),this.match(_.KEYWORD,"if")?n=this.parseIfStatement():n=this.parseBlock()),new Hi(e,r,n)}parseForStatement(){this.expect(_.KEYWORD,"for");let e=null,r=!1;if(this.match(_.LBRACKET)){this.advance();let n=[];for(;!this.match(_.RBRACKET);)this.skipNewlines(),n.push(new be(this.expectIdentifierOrContextual().value)),this.match(_.COMMA)&&this.advance();this.expect(_.RBRACKET),e=new Fn(n),r=!0}else{let n=this.expectIdentifierOrContextual().value;e=new be(n)}if(this.match(_.KEYWORD,"in")){this.advance();let n=this.parseExpression();this.skipNewlines();let i=this.parseBlock(),s=new ut([new rt(e,n)],At.CONST),a=new In(s,null,null,i);return a.isForIn=!0,a}else{if(r)throw new Error(`Range-based for loops don\'t support destructuring at ${this.peek().line}:${this.peek().column}`);this.expect(_.OPERATOR,"=");let n=this.parseExpression();this.expect(_.KEYWORD,"to");let i=this.parseExpression(),s=null;this.match(_.KEYWORD,"by")&&(this.advance(),s=this.parseExpression()),this.skipNewlines();let a=this.parseBlock(),o=new ut([new rt(e,n)],At.LET),l=new pt("<=",n,i),c=new wt(l,new pt("<=",e,i),new pt(">=",e,i)),u;return s?u=new wt(l,new Gt("+=",e,s),new Gt("-=",e,s)):u=new wt(l,new Dn("++",e),new Dn("--",e)),new In(o,c,u,a)}}parseWhileStatement(){this.expect(_.KEYWORD,"while");let e=this.parseExpression();this.skipNewlines();let r=this.parseBlock();return new Gi(e,r)}parseBlock(){if(!this.match(_.INDENT)){let n=this.parseStatement();return new vt(n?[n]:[])}let e=this.peek().indent;this.advance();let r=[];for(;!this.match(_.EOF);){if(this.skipNewlines(),this.match(_.DEDENT)){if(this.peek().indent<e)break;this.advance();continue}if(this.match(_.EOF))break;let n=this.parseStatement();n&&r.push(n)}return this.match(_.DEDENT)&&this.peek().indent<e&&this.advance(),new vt(r)}isTupleDestructuring(){if(!this.match(_.LBRACKET))return!1;let e=1;for(;;){for(;this.peek(e).type===_.NEWLINE;)e++;if(this.peek(e).type!==_.IDENTIFIER)return!1;for(e++;this.peek(e).type===_.NEWLINE;)e++;if(this.peek(e).type===_.RBRACKET){e++;break}else if(this.peek(e).type===_.COMMA){e++;continue}else return!1}for(;this.peek(e).type===_.NEWLINE;)e++;return this.peek(e).type===_.OPERATOR&&this.peek(e).value==="="}parseTupleDestructuring(){this.expect(_.LBRACKET);let e=[];for(;!this.match(_.RBRACKET);){this.skipNewlines();let n=this.expectIdentifierOrContextual().value;this.functionNames.has(n)&&(n=n+"_var"),e.push(new be(n)),this.match(_.COMMA)&&this.advance()}this.expect(_.RBRACKET),this.skipNewlines(),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let r=this.parseExpression();return new ut([new rt(new Fn(e),r)],At.CONST)}parseExpression(){return this.parseTernary()}parseTernary(){let e=this.parseLogicalOr();if(this.matchEx(_.OPERATOR,"?",!0)){this.advance(),this.skipNewlines(!0);let r=this.parseExpression();this.matchEx(_.COLON,null,!0)?this.advance():this.expect(_.COLON),this.skipNewlines(!0);let n=this.parseExpression();return new wt(e,r,n)}return e}parseLogicalOr(){let e=this.parseLogicalAnd();for(;this.matchEx(_.KEYWORD,"or",!0)||this.peekOperatorEx(["||"]);){this.advance(),this.skipNewlines(!0);let r=this.parseLogicalAnd();e=new pt("||",e,r)}return e}parseLogicalAnd(){let e=this.parseEquality();for(;this.matchEx(_.KEYWORD,"and",!0)||this.peekOperatorEx(["&&"]);){this.advance(),this.skipNewlines(!0);let r=this.parseEquality();e=new pt("&&",e,r)}return e}parseEquality(){let e=this.parseComparison();for(;this.peekOperatorEx(["==","!="]);){let r=this.advance().value;this.skipNewlines(!0);let n=this.parseComparison();e=new pt(r,e,n)}return e}parseComparison(){let e=this.parseAdditive();for(;this.peekOperatorEx(["<",">","<=",">="]);){let r=this.advance().value;this.skipNewlines(!0);let n=this.parseAdditive();e=new pt(r,e,n)}return e}parseAdditive(){let e=this.parseMultiplicative();for(;this.peekOperatorEx(["+","-"]);){let r=this.advance().value;this.skipNewlines(!0);let n=this.parseMultiplicative();e=new pt(r,e,n)}return e}parseMultiplicative(){let e=this.parseUnary();for(;this.peekOperatorEx(["*","/","%"]);){let r=this.advance().value;this.skipNewlines(!0);let n=this.parseUnary();e=new pt(r,e,n)}return e}parseUnary(){if(this.match(_.OPERATOR)){let e=this.peek().value;if(["+","-","!"].includes(e))return this.advance(),this.skipNewlines(),new Tn(e,this.parseUnary())}return this.match(_.KEYWORD,"not")?(this.advance(),this.skipNewlines(),new Tn("!",this.parseUnary())):this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match(_.OPERATOR,"<")){let r=this.pos;this.advance();let n=1,i=!0,s="",a=new Set(["float","int","string","bool","color","line","label","box","linefill","table"]);for(;n>0&&!this.match(_.EOF);)if(this.match(_.OPERATOR,"<"))n++,this.advance();else if(this.match(_.OPERATOR,">"))n--,this.advance();else if(this.match(_.IDENTIFIER)||this.match(_.COMMA)||this.match(_.DOT))n===1&&this.match(_.IDENTIFIER)&&s===""&&(s=this.peek().value),this.advance();else{i=!1,this.pos=r;break}if(i&&e.type==="MemberExpression"&&e.property.name==="new"&&(e.object.name==="array"||e.object.name==="matrix")&&a.has(s)&&(e.property=new be("new_"+s)),i&&this.match(_.LPAREN)){e=this.parseCallExpression(e);continue}else{if(i)continue;break}}else if(this.match(_.LPAREN))e=this.parseCallExpression(e);else if(this.match(_.DOT)){this.advance(),this.skipNewlines();let r=this.peek();if(r.type!==_.IDENTIFIER&&r.type!==_.KEYWORD)throw new Error(`Expected property name but got ${r.type} at ${r.line}:${r.column}`);this.advance(),e=new Mn(e,new be(r.value),!1)}else if(this.match(_.LBRACKET)){if(this.isTupleDestructuring())break;this.advance(),this.skipNewlines();let r=this.parseExpression();this.expect(_.RBRACKET),e=new Mn(e,r,!0)}else break;return e}parseCallExpression(e){this.expect(_.LPAREN);let r=[],n=[];for(;!this.match(_.RPAREN)&&(this.skipNewlines(),!this.match(_.RPAREN));){if((this.peek().type===_.IDENTIFIER||this.peek().type===_.KEYWORD)&&this.peek(1).type===_.OPERATOR&&this.peek(1).value==="="){let i=this.advance().value;this.advance(),this.skipNewlines();let s=this.parseExpression();n.push(new Rn(new be(i),s))}else r.push(this.parseExpression());this.match(_.COMMA)&&this.advance(),this.skipNewlines()}return this.expect(_.RPAREN),n.length>0&&r.push(new Pn(n)),new Yi(e,r)}parsePrimary(){let e=this.peek();if(this.match(_.NUMBER)){let r=this.advance();return new Tt(r.value,r.raw)}if(this.match(_.STRING)){let r=this.advance();return new Tt(r.value)}if(this.match(_.BOOLEAN)){let r=this.advance();return new Tt(r.value)}if(this.match(_.IDENTIFIER)||e.type===_.KEYWORD&&Ji.CONTEXTUAL_KEYWORDS.has(e.value)){let r=this.advance().value;return this.functionNames.has(r)&&this.peek().type!==_.LPAREN&&!this.isCurrentFunctionParam(r)&&(r=r+"_var"),new be(r)}if(this.match(_.LBRACKET))return this.parseArrayLiteral();if(this.match(_.LPAREN)){this.advance(),this.skipNewlines();let r=this.parseExpression();return this.skipNewlines(),this.expect(_.RPAREN),r}if(this.match(_.KEYWORD,"if"))return this.parseIfExpression();if(this.match(_.KEYWORD,"switch"))return this.parseSwitchExpression();if(this.match(_.KEYWORD,"for"))return this.parseForExpression();if(this.match(_.KEYWORD,"while"))return this.parseWhileExpression();throw new Error(`Unexpected token ${e.type} \'${e.value}\' at ${e.line}:${e.column}`)}parseArrayLiteral(){this.expect(_.LBRACKET);let e=[];for(;!this.match(_.RBRACKET)&&(this.skipNewlines(),!this.match(_.RBRACKET));)e.push(this.parseExpression()),this.match(_.COMMA)&&this.advance(),this.skipNewlines();return this.expect(_.RBRACKET),new Zi(e)}parseIfExpression(){this.expect(_.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines(),this.expect(_.INDENT);let r=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let a=this.parseStatement();a&&r.push(a)}this.advance();let n=[];if(this.match(_.KEYWORD,"else"))if(this.advance(),this.skipNewlines(),this.match(_.KEYWORD,"if")){let a=this.parseIfExpression();if(this.needsIIFE(r,n)){let o=new wt(e,new vt(r),a);return o.needsIIFE=!0,o.consequentStmts=r,o.alternateExpr=a,o}else return new wt(e,this.getBlockValue(r),a)}else{for(this.expect(_.INDENT);!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let a=this.parseStatement();a&&n.push(a)}this.advance()}if(this.needsIIFE(r,n)){let a=new wt(e,new vt(r),new vt(n));return a.needsIIFE=!0,a.consequentStmts=r,a.alternateStmts=n,a}let i=this.getBlockValue(r),s=n.length>0?this.getBlockValue(n):new Tt(null);return new wt(e,i,s)}needsIIFE(e,r){if(e.length>1||r.length>1)return!0;let n=i=>i.some(s=>s.type==="IfStatement"||s.type==="ForStatement"||s.type==="WhileStatement"||s.type==="BlockStatement");return n(e)||n(r)}parseSwitchExpression(){this.expect(_.KEYWORD,"switch");let e=null;!this.match(_.NEWLINE)&&!this.match(_.INDENT)&&(e=this.parseExpression()),this.skipNewlines(),this.expect(_.INDENT);let r=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let n=null;this.match(_.OPERATOR,"=>")||(n=this.parseExpression()),this.expect(_.OPERATOR,"=>"),this.skipNewlines();let i=[];if(this.match(_.INDENT)){for(this.advance();!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let a=this.parseStatement();a&&i.push(a)}this.advance()}else{this.noLineContinuation=!0;let a=this.parseStatement();this.noLineContinuation=!1,a&&i.push(a)}let s=this.getBlockValue(i);r.push(new Qi(n,s,i)),this.skipNewlines()}return this.advance(),new Xi(e,r)}parseForExpression(){let e=this.parseForStatement();return e.isExpression=!0,e}parseWhileExpression(){let e=this.parseWhileStatement();return e.isExpression=!0,e}getBlockValue(e){if(e.length===0)return new Tt(null);let r=e[e.length-1];return r.type==="ExpressionStatement"?r.expression:r.type==="VariableDeclaration"&&r.declarations.length>0?r.declarations[0].id:new Tt(null)}};hr(Zo,"CONTEXTUAL_KEYWORDS",new Set(["type","method","enum"]));var s0=Zo,a0=Object.defineProperty,o0=(t,e,r)=>e in t?a0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,It=(t,e,r)=>o0(t,typeof e!="symbol"?e+"":e,r),l0=new Set(Es),es=class{constructor(e={}){It(this,"indent"),It(this,"indentStr"),It(this,"output"),It(this,"sourceCode"),It(this,"sourceLines"),It(this,"lastCommentedLine"),It(this,"includeSourceComments"),It(this,"paramRenameCounter"),It(this,"functionParams"),this.indent=0,this.indentStr=e.indentStr||" ",this.output=[],this.sourceCode=e.sourceCode||null,this.sourceLines=this.sourceCode?this.sourceCode.split(`\n`):[],this.lastCommentedLine=-1,this.includeSourceComments=e.includeSourceComments||!1,this.paramRenameCounter=0,this.functionParams=new Map}generate(e){if(this.output=[],this.indent=0,this.lastCommentedLine=-1,this.functionParams=new Map,e.type==="Program")this.preProcessAST(e),this.generateProgram(e);else throw new Error(`Expected Program node, got ${e.type}`);return this.output.join("")}preProcessAST(e){this.collectFunctionParams(e),this.renameConflictingVariables(e)}renameConflictingVariables(e){let r=new Map;this.collectConflictingVarNames(e,r),r.size>0&&this.renameVariableRefsInAST(e,r)}isReservedName(e){return!!e&&(x_.has(e)||da.has(e))}collectConflictingVarNames(e,r){if(!(!e||typeof e!="object")){if(e.type==="VariableDeclaration"){for(let n of e.declarations)if(n.id?.type==="Identifier"&&this.isReservedName(n.id.name)&&!r.has(n.id.name)&&r.set(n.id.name,`${n.id.name}_$${this.paramRenameCounter++}`),n.id?.type==="ArrayPattern")for(let i of n.id.elements)i?.type==="Identifier"&&this.isReservedName(i.name)&&!r.has(i.name)&&r.set(i.name,`${i.name}_$${this.paramRenameCounter++}`)}(e.type==="AssignmentExpression"||e.type==="ReassignmentExpression")&&e.left?.type==="Identifier"&&this.isReservedName(e.left.name)&&!r.has(e.left.name)&&r.set(e.left.name,`${e.left.name}_$${this.paramRenameCounter++}`),e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"&&!e.id.isMethod&&this.isReservedName(e.id.name)&&!r.has(e.id.name)&&r.set(e.id.name,`${e.id.name}_$${this.paramRenameCounter++}`);for(let n of Object.keys(e)){if(n==="type")continue;let i=e[n];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.collectConflictingVarNames(s,r);else i&&typeof i=="object"&&i.type&&this.collectConflictingVarNames(i,r)}}}renameVariableRefsInAST(e,r){if(!(!e||typeof e!="object")){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&r.has(e.callee.name)?da.has(e.callee.name)&&(e.callee.name=r.get(e.callee.name)):this.renameVariableRefsInAST(e.callee,r),e.arguments)for(let n of e.arguments)this.renameVariableRefsInAST(n,r);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&r.has(e.object.name))return;if(!e.computed&&e.property?.type==="Identifier"&&r.has(e.property.name)){this.renameVariableRefsInAST(e.object,r);return}this.renameVariableRefsInAST(e.object,r),e.computed&&this.renameVariableRefsInAST(e.property,r);return}if(e.type==="Property"){this.renameVariableRefsInAST(e.value,r);return}if(e.type==="Identifier"&&r.has(e.name)){e.name=r.get(e.name);return}for(let n of Object.keys(e)){if(n==="type")continue;let i=e[n];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameVariableRefsInAST(s,r);else i&&typeof i=="object"&&i.type&&this.renameVariableRefsInAST(i,r)}}}collectFunctionParams(e){if(!(!e||typeof e!="object")){if(e.type==="FunctionDeclaration"&&e.id?.name){let r=[];for(let n of e.params)n.type==="Identifier"?r.push(n.name):n.type==="AssignmentPattern"&&n.left?.name&&r.push(n.left.name);this.functionParams.set(e.id.name,r)}if(Array.isArray(e.body))for(let r of e.body)this.collectFunctionParams(r);else e.body&&typeof e.body=="object"&&this.collectFunctionParams(e.body)}}writeSourceComment(e,r=null){if(!this.sourceLines.length)return;let n=r||e,i=[];for(let s=e-1;s<n&&s<this.sourceLines.length;s++)if(s>this.lastCommentedLine){let a=this.sourceLines[s].trim();a&&!a.startsWith("//@")&&!a.startsWith("//")&&i.push(this.sourceLines[s])}if(i.length>0){for(let s of i)this.write(this.indentStr.repeat(this.indent)),this.write("/// "),this.write(s.trimEnd()),this.write(`\n`);this.lastCommentedLine=Math.max(this.lastCommentedLine,n-1)}}write(e){this.output.push(e)}writeLine(e=""){e?this.output.push(this.indentStr.repeat(this.indent)+e+`\n`):this.output.push(`\n`)}increaseIndent(){this.indent++}decreaseIndent(){this.indent--}generateProgram(e){for(let r=0;r<e.body.length;r++)if(this.generateStatement(e.body[r]),r<e.body.length-1){let n=e.body[r],i=e.body[r+1];(n.type==="FunctionDeclaration"||n.type==="TypeDefinition")&&(i.type==="FunctionDeclaration"||i.type==="TypeDefinition")&&this.writeLine()}}generateStatement(e){switch(this.includeSourceComments&&e._line&&this.sourceLines.length>0&&this.writeSourceComment(e._line),e.type){case"FunctionDeclaration":return this.generateFunctionDeclaration(e);case"VariableDeclaration":return this.generateVariableDeclaration(e);case"ExpressionStatement":return this.generateExpressionStatement(e);case"IfStatement":return this.generateIfStatement(e);case"ForStatement":return this.generateForStatement(e);case"WhileStatement":return this.generateWhileStatement(e);case"ReturnStatement":return this.generateReturnStatement(e);case"BlockStatement":return this.generateBlockStatement(e);case"TypeDefinition":return this.generateTypeDefinition(e);default:throw new Error(`Unknown statement type: ${e.type}`)}}generateTypeDefinition(e){if(this.write(this.indentStr.repeat(this.indent)),this.write(`const ${e.name} = Type({`),e.fields.length>0){this.write(" ");for(let r=0;r<e.fields.length;r++){let n=e.fields[r];n.defaultValue?(this.write(`${n.name}: [\'${n.type}\', `),this.generateExpression(n.defaultValue),this.write("]")):this.write(`${n.name}: \'${n.type}\'`),r<e.fields.length-1&&this.write(", ")}this.write(" ")}this.write(`});\n`)}renameIdentifiersInAST(e,r){if(!(!e||typeof e!="object")){if(e.type==="Identifier"&&r.has(e.name)){e.name=r.get(e.name);return}if(e.type!=="FunctionDeclaration")for(let n of Object.keys(e)){if(n==="type")continue;let i=e[n];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameIdentifiersInAST(s,r);else i&&typeof i=="object"&&i.type&&this.renameIdentifiersInAST(i,r)}}}renameParamRefsInBody(e,r){if(!(!e||typeof e!="object")&&e.type!=="FunctionDeclaration"){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&r.has(e.callee.name)||this.renameParamRefsInBody(e.callee,r),e.arguments)for(let n of e.arguments)this.renameParamRefsInBody(n,r);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&r.has(e.object.name))return;this.renameParamRefsInBody(e.object,r),e.computed&&this.renameParamRefsInBody(e.property,r);return}if(e.type==="Property"){this.renameParamRefsInBody(e.value,r);return}if(e.type==="Identifier"&&r.has(e.name)){e.name=r.get(e.name);return}for(let n of Object.keys(e)){if(n==="type")continue;let i=e[n];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameParamRefsInBody(s,r);else i&&typeof i=="object"&&i.type&&this.renameParamRefsInBody(i,r)}}}generateFunctionDeclaration(e){this.write(this.indentStr.repeat(this.indent));let r=e.id.isMethod,n=new Map;for(let c of e.params){let u=c.type==="AssignmentPattern"?c.left.name:c.name;if(u&&l0.has(u)){let h=`${u}_$${this.paramRenameCounter++}`;n.set(u,h)}}let i=c=>c.type==="Identifier"&&c.name==="this"||c.type==="AssignmentPattern"&&c.left?.name==="this",s=new Map;if(r&&e.params.length>0&&i(e.params[0])&&s.set("this","self"),n.size>0||s.size>0){for(let c of e.params){let u=c.type==="AssignmentPattern"?c.left:c;if(u?.type==="Identifier"){let h=n.get(u.name)??s.get(u.name);h&&(u.name=h)}c.type==="AssignmentPattern"&&c.right&&(n.size>0&&this.renameParamRefsInBody(c.right,n),s.size>0&&this.renameIdentifiersInAST(c.right,s))}n.size>0&&this.renameParamRefsInBody(e.body,n),s.size>0&&this.renameIdentifiersInAST(e.body,s)}let a=r?`$M_${e.id.name}`:e.id.name;this.write("function "),this.write(a),this.write("(");let o=e.params;for(let c=0;c<o.length;c++){let u=o[c];u.type==="Identifier"?this.write(u.name):u.type==="AssignmentPattern"&&(this.write(u.left.name),this.write(" = "),this.generateExpression(u.right)),c<o.length-1&&this.write(", ")}this.write(") "),this.generateBlockStatement(e.body,!1),this.write(`\n`),r&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${a}.__pineMethod__ = true;\n`));let l=[];for(let c=0;c<e.params.length;c++){let u=e.params[c],h=u.type==="AssignmentPattern"?u.left?.name:u.name;if(r&&c===0&&h==="self")continue;let p=u.type==="AssignmentPattern"?u.left?.varType:u.varType;h&&p&&l.push([h,p])}if(l.length>0){this.write(this.indentStr.repeat(this.indent));let c=l.map(([u,h])=>`${JSON.stringify(u)}: ${JSON.stringify(h)}`).join(", ");this.write(`${a}.__pineParamTypes__ = {${c}};\n`)}}generateVariableDeclaration(e){let r=e.kind==="var"||e.kind==="varip"?"var":"let";for(let n=0;n<e.declarations.length;n++){let i=e.declarations[n];if(i.init&&i.init.type==="ConditionalExpression"&&i.init.needsIIFE){let o=i.id.type==="Identifier"?i.id.name:null;if(o){this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" "),this.write(o),this.write(`;\n`),this.generateIfStatementWithAssignment(i.init,o);continue}}if(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" "),i.id.type==="Identifier")this.write(i.id.name);else if(i.id.type==="ArrayPattern"){let o=new Set;this.write("[");for(let l=0;l<i.id.elements.length;l++){let c=i.id.elements[l].name;if(o.has(c)){let u=`${c}${this.paramRenameCounter++}`;i.id.elements[l].name=u,c=u}o.add(c),this.write(c),l<i.id.elements.length-1&&this.write(", ")}this.write("]")}i.init&&(this.write(" = "),this.generateExpression(i.init)),this.write(`;\n`);let s=i.id?.varType,a=i.id?.type==="Identifier"?i.id.name:null;a&&typeof s=="string"&&/^[A-Za-z_$][\\w$]*$/.test(s)&&s[0]===s[0].toUpperCase()&&(this.write(this.indentStr.repeat(this.indent)),this.write(`"__pineUdtVar:${a}=${s}";\n`))}}generateExpressionStatement(e){if(e.expression.type==="SwitchExpression"&&e.expression.discriminant===null){this.write(this.indentStr.repeat(this.indent)),this.generateSwitchAsIfElse(e.expression),this.write(`\n`);return}this.write(this.indentStr.repeat(this.indent)),this.generateExpression(e.expression),this.write(`;\n`)}generateIfStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(") "),this.generateBlockStatement(e.consequent,!1),e.alternate?(this.write(" else "),e.alternate.type==="IfStatement"?this.generateIfStatement(e.alternate):this.generateBlockStatement(e.alternate,!1)):this.write(`\n`)}generateIfStatementWithAssignment(e,r){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequentStmts)for(let n=0;n<e.consequentStmts.length;n++){let i=e.consequentStmts[n];n===e.consequentStmts.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternateExpr)this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(e.alternateExpr),this.write(`;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");else if(e.alternateStmts&&e.alternateStmts.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.alternateStmts.length;n++){let i=e.alternateStmts[n];n===e.alternateStmts.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}")}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");this.write(`\n`)}generateNestedIfWithAssignments(e,r){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let n=0;n<e.consequent.body.length;n++){let i=e.consequent.body[n];n===e.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternate)if(e.alternate.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.alternate.test),this.write(`) {\n`),this.indent++,e.alternate.consequent.type==="BlockStatement"&&e.alternate.consequent.body.length>0)for(let n=0;n<e.alternate.consequent.body.length;n++){let i=e.alternate.consequent.body[n];n===e.alternate.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternatesWithAssignments(e.alternate.alternate,r)}else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.alternate.body.length;n++){let i=e.alternate.body[n];n===e.alternate.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`);else this.write(`\n`)}generateNestedIfAlternatesWithAssignments(e,r){if(e)if(e.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let n=0;n<e.consequent.body.length;n++){let i=e.consequent.body[n];n===e.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternatesWithAssignments(e.alternate,r)}else if(e.type==="BlockStatement"&&e.body.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.body.length;n++){let i=e.body[n];n===e.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,r):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(r),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}generateForStatement(e){if(this.write(this.indentStr.repeat(this.indent)),e.isForIn){if(this.write("for ("),e.init&&e.init.type==="VariableDeclaration"){let r=e.init.declarations[0];if(this.write(`${e.init.kind} `),r.id.type==="Identifier")this.write(r.id.name);else if(r.id.type==="ArrayPattern"){let n=new Set;this.write("[");for(let i=0;i<r.id.elements.length;i++){let s=r.id.elements[i].name;if(n.has(s)){let a=`${s}${this.paramRenameCounter++}`;r.id.elements[i].name=a,s=a}n.add(s),this.write(s),i<r.id.elements.length-1&&this.write(", ")}this.write("]")}this.write(" of "),this.generateExpression(r.init)}this.write(") "),this.generateBlockStatement(e.body,!1);return}if(this.write("for ("),e.init)if(e.init.type==="VariableDeclaration"){let r=e.init.declarations[0];this.write(`${e.init.kind} ${r.id.name}`),r.init&&(this.write(" = "),this.generateExpression(r.init))}else this.generateExpression(e.init);this.write("; "),e.test&&this.generateExpression(e.test),this.write("; "),e.update&&(e.update.type==="AssignmentExpression"?(this.generateExpression(e.update.left),this.write(` ${e.update.operator} `),this.generateExpression(e.update.right)):this.generateExpression(e.update)),this.write(") "),this.generateBlockStatement(e.body,!1)}generateWhileStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("while ("),this.generateExpression(e.test),this.write(") "),this.generateBlockStatement(e.body,!1)}generateReturnStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("return"),e.argument&&(this.write(" "),this.generateExpression(e.argument)),this.write(`;\n`)}generateBlockStatement(e,r=!0){this.write(`{\n`),r?this.increaseIndent():this.indent++;for(let n of e.body)this.generateStatement(n);r?this.decreaseIndent():this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),r&&this.write(`\n`)}generateExpression(e){switch(e.type){case"Identifier":return this.write(e.name);case"Literal":return this.generateLiteral(e);case"BinaryExpression":case"LogicalExpression":return this.generateBinaryExpression(e);case"UnaryExpression":return this.generateUnaryExpression(e);case"AssignmentExpression":return this.generateAssignmentExpression(e);case"UpdateExpression":return this.generateUpdateExpression(e);case"CallExpression":return this.generateCallExpression(e);case"MemberExpression":return this.generateMemberExpression(e);case"ConditionalExpression":return this.generateConditionalExpression(e);case"ArrayExpression":return this.generateArrayExpression(e);case"ObjectExpression":return this.generateObjectExpression(e);case"SwitchExpression":return this.generateSwitchExpression(e);case"SequenceExpression":return this.generateSequenceExpression(e);case"ForStatement":return this.generateLoopAsExpression(e,"for");case"WhileStatement":return this.generateLoopAsExpression(e,"while");default:throw new Error(`Unknown expression type: ${e.type}`)}}generateLiteral(e){if(typeof e.value=="string"){let r=e.value.replace(/\\\\/g,"\\\\\\\\").replace(/\'/g,"\\\\\'").replace(/\\n/g,"\\\\n").replace(/\\r/g,"\\\\r").replace(/\\t/g,"\\\\t");this.write(`\'${r}\'`)}else if(e.value===null)this.write("null");else{let r=String(e.value);typeof e.raw=="string"&&e.raw.includes(".")&&!/[.eE]/.test(r)?this.write(r+".0"):this.write(r)}}generateBinaryExpression(e){let r=this.getPrecedence(e);this.getPrecedence(e.left)<r?(this.write("("),this.generateExpression(e.left),this.write(")")):this.generateExpression(e.left),this.write(" ");let n=e.operator;n==="and"?n="&&":n==="or"&&(n="||"),this.write(n),this.write(" ");let i=this.getPrecedence(e.right),s=i<r;i===r&&(n==="-"||n==="/"||n==="%")&&(s=!0),s?(this.write("("),this.generateExpression(e.right),this.write(")")):this.generateExpression(e.right)}generateUnaryExpression(e){let r=e.operator;r==="not"&&(r="!"),this.write(r),this.getPrecedence(e.argument)<15||e.argument.type==="UnaryExpression"&&(r==="-"||r==="+")&&(e.argument.operator==="-"||e.argument.operator==="+")?(this.write("("),this.generateExpression(e.argument),this.write(")")):this.generateExpression(e.argument)}generateAssignmentExpression(e){this.generateExpression(e.left),this.write(" ");let r=e.operator;r===":="&&(r="="),this.write(r),this.write(" "),this.generateExpression(e.right)}generateUpdateExpression(e){e.prefix?(this.write(e.operator),this.generateExpression(e.argument)):(this.generateExpression(e.argument),this.write(e.operator))}generateCallExpression(e){this.getPrecedence(e.callee)<19?(this.write("("),this.generateExpression(e.callee),this.write(")")):this.generateExpression(e.callee),this.write("(");let r=e.callee?.type==="Identifier"?e.callee.name:null,n=r?this.functionParams.get(r):null,i=e.arguments.length>0?e.arguments[e.arguments.length-1]:null;if(i?.type==="ObjectExpression"&&n){let s=e.arguments.slice(0,-1),a=new Map;for(let u of i.properties){let h=u.key?.name||u.key?.value;h&&a.set(h,u.value)}let o=[],l=-1;for(let u=0;u<n.length;u++)u<s.length?(o.push(s[u]),l=u):a.has(n[u])?(o.push(a.get(n[u])),l=u):o.push(null);let c=o.slice(0,l+1);for(let u=0;u<c.length;u++)c[u]===null?this.write("undefined"):this.generateExpression(c[u]),u<c.length-1&&this.write(", ")}else for(let s=0;s<e.arguments.length;s++){let a=e.arguments[s];a.type==="AssignmentExpression"&&a.operator==="="?this.generateExpression(a.right):this.generateExpression(a),s<e.arguments.length-1&&this.write(", ")}this.write(")")}generateMemberExpression(e){this.getPrecedence(e.object)<19?(this.write("("),this.generateExpression(e.object),this.write(")")):this.generateExpression(e.object),e.computed?(this.write("["),this.generateExpression(e.property),this.write("]")):(this.write("."),this.generateExpression(e.property))}generateConditionalExpression(e){if(e.needsIIFE){this.generateIIFEConditional(e);return}this.write("("),this.generateExpression(e.test),this.write(" ? "),this.generateExpression(e.consequent),this.write(" : "),this.generateExpression(e.alternate),this.write(")")}generateIIFEConditional(e){this.write(`(() => {\n`),this.indent++,this.generateIIFEIfBlock(e),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateIIFEIfBlock(e){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequentStmts)for(let r=0;r<e.consequentStmts.length;r++){let n=e.consequentStmts[r];r===e.consequentStmts.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternateExpr)this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(e.alternateExpr),this.write(`;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");else if(e.alternateStmts&&e.alternateStmts.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.alternateStmts.length;r++){let n=e.alternateStmts[r];r===e.alternateStmts.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}")}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");this.write(`\n`)}generateNestedIfWithReturns(e){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let r=0;r<e.consequent.body.length;r++){let n=e.consequent.body[r];r===e.consequent.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternate)if(e.alternate.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.alternate.test),this.write(`) {\n`),this.indent++,e.alternate.consequent.type==="BlockStatement"&&e.alternate.consequent.body.length>0)for(let r=0;r<e.alternate.consequent.body.length;r++){let n=e.alternate.consequent.body[r];r===e.alternate.consequent.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternates(e.alternate.alternate)}else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.alternate.body.length;r++){let n=e.alternate.body[r];r===e.alternate.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`);else this.write(`\n`)}generateNestedIfAlternates(e){if(e)if(e.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let r=0;r<e.consequent.body.length;r++){let n=e.consequent.body[r];r===e.consequent.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternates(e.alternate)}else if(e.type==="BlockStatement"&&e.body.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.body.length;r++){let n=e.body[r];r===e.body.length-1?n.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.expression),this.write(`;\n`)):n.type==="IfStatement"?this.generateNestedIfWithReturns(n):this.generateStatement(n):this.generateStatement(n)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}generateNestedIfAsExpression(e){if(e.type==="IfStatement"){if(this.write("("),this.generateExpression(e.test),this.write(" ? "),e.consequent.type==="BlockStatement"&&e.consequent.body.length>0){let r=e.consequent.body[e.consequent.body.length-1];r.type==="ExpressionStatement"?this.generateExpression(r.expression):r.type==="IfStatement"&&this.generateNestedIfAsExpression(r)}if(this.write(" : "),e.alternate)if(e.alternate.type==="IfStatement")this.generateNestedIfAsExpression(e.alternate);else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){let r=e.alternate.body[e.alternate.body.length-1];r.type==="ExpressionStatement"&&this.generateExpression(r.expression)}else this.write("false");else this.write("false");this.write(")")}}generateArrayExpression(e){this.write("[");for(let r=0;r<e.elements.length;r++)this.generateExpression(e.elements[r]),r<e.elements.length-1&&this.write(", ");this.write("]")}generateObjectExpression(e){this.write("{");for(let r=0;r<e.properties.length;r++){let n=e.properties[r];n.key.type==="Identifier"?this.write(n.key.name):this.generateExpression(n.key),this.write(": "),this.generateExpression(n.value),r<e.properties.length-1&&this.write(", ")}this.write("}")}generateSwitchExpression(e){if(e.discriminant===null){this.generateSwitchAsIfElseIIFE(e);return}this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write("switch ("),this.generateExpression(e.discriminant),this.write(`) {\n`),this.indent++;for(let r of e.cases){if(this.write(this.indentStr.repeat(this.indent)),r.test?(this.write("case "),this.generateExpression(r.test),this.write(`:\n`)):this.write(`default:\n`),this.indent++,r.statements&&r.statements.length>0){let n=r.statements[r.statements.length-1];if(n.type==="ExpressionStatement"||n.type==="VariableDeclaration"){for(let i=0;i<r.statements.length-1;i++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(r.statements[i]);this.write(this.indentStr.repeat(this.indent)),this.write("return "),n.type==="ExpressionStatement"?this.generateExpression(n.expression):this.generateExpression(r.consequent),this.write(`;\n`)}else{for(let i=0;i<r.statements.length;i++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(r.statements[i]);this.write(this.indentStr.repeat(this.indent)),this.write(`return null;\n`)}}else this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.consequent),this.write(`;\n`);this.indent--}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSwitchAsIfElseIIFE(e){this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent));for(let r=0;r<e.cases.length;r++){let n=e.cases[r];if(n.test?(r===0?this.write("if ("):this.write(" else if ("),this.generateExpression(n.test),this.write(`) {\n`)):r>0?this.write(` else {\n`):this.write(`{\n`),this.indent++,n.statements&&n.statements.length>0){let i=n.statements[n.statements.length-1];if(i.type==="ExpressionStatement"||i.type==="VariableDeclaration"){for(let s=0;s<n.statements.length-1;s++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(n.statements[s]);this.write(this.indentStr.repeat(this.indent)),this.write("return "),i.type==="ExpressionStatement"?this.generateExpression(i.expression):this.generateExpression(n.consequent),this.write(`;\n`)}else{for(let s of n.statements)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(s);this.write(this.indentStr.repeat(this.indent)),this.write(`return null;\n`)}}else this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.consequent),this.write(`;\n`);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),r>=e.cases.length-1&&this.write(`\n`)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSwitchAsIfElse(e){for(let r=0;r<e.cases.length;r++){let n=e.cases[r];if(n.test?(r===0?this.write("if ("):this.write(" else if ("),this.generateExpression(n.test),this.write(`) {\n`)):r>0?this.write(` else {\n`):this.write(`{\n`),this.indent++,n.statements&&n.statements.length>0)for(let i of n.statements)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(i);else this.write(this.indentStr.repeat(this.indent)),this.generateExpression(n.consequent),this.write(`;\n`);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),r<e.cases.length-1||this.write(`\n`)}}generateLoopAsExpression(e,r){this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`let __result;\n`);let n=e.body;if(n&&n.body&&n.body.length>0){let i=n.body.length-1,s=n.body[i];s.type==="ExpressionStatement"&&(n.body[i]={type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:{type:"Identifier",name:"__result"},right:s.expression},_line:s._line})}r==="for"?this.generateForStatement(e):this.generateWhileStatement(e),this.write(this.indentStr.repeat(this.indent)),this.write(`return __result;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSequenceExpression(e){this.write("(");for(let r=0;r<e.expressions.length;r++)this.generateExpression(e.expressions[r]),r<e.expressions.length-1&&this.write(", ");this.write(")")}getPrecedence(e){switch(e.type){case"Literal":case"Identifier":case"ArrayExpression":case"ObjectExpression":return 20;case"CallExpression":case"MemberExpression":return 19;case"UnaryExpression":case"UpdateExpression":return 15;case"BinaryExpression":case"LogicalExpression":switch(e.operator){case"*":case"/":case"%":return 13;case"+":case"-":return 12;case"<":case"<=":case">":case">=":return 10;case"==":case"!=":return 9;case"and":case"&&":return 5;case"or":case"||":return 4;default:return 0}case"ConditionalExpression":return 3;case"AssignmentExpression":case"AssignmentPattern":return 2;case"SequenceExpression":return 1;default:return 0}}};function Xo(t){let e=/^\\s*\\/\\/\\s*@version\\s*=\\s*(\\d+)\\s*$/im,r=t.match(e);return r&&r[1]?parseInt(r[1],10):null}function Cs(t,e={}){let r=Xo(t);if(r===null)return{success:!1,version:null,error:"Pine Script version not found. Please add //@version=X comment to your script."};if(r<5)return{success:!1,version:r,error:`Pine Script version ${r} is not supported. Only version 5 and above are supported.`};try{let n=new qi(t).tokenize(),i=new s0(n).parse(),s={...e,sourceCode:t},a=new es(s).generate(i);return{success:!0,version:r,code:a,ast:i,tokens:n}}catch(n){return{success:!1,version:r,error:n.message,stack:n.stack}}}var c0=new Set(["security_lower_tf","security"]),Qo=new Set(["type","loc","start","end","range","parent","leadingComments","trailingComments"]);function u0(t){if(!t||t.type!=="CallExpression")return!1;let e=t.callee;return!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="request"||e.property?.type!=="Identifier"?!1:c0.has(e.property.name)}function p0(t){let e=t?.arguments?.[2];return e?.type==="Identifier"&&typeof e.name=="string"?e.name:null}function h0(t){let e=[],r=new WeakSet;function n(i,s){if(!i||typeof i!="object"||r.has(i))return;r.add(i);let a=s.concat([i]);u0(i)&&e.push({call:i,path:a});for(let o of Object.keys(i)){if(Qo.has(o))continue;let l=i[o];if(Array.isArray(l))for(let c of l)n(c,a);else l&&typeof l=="object"&&n(l,a)}}return n(t,[]),e}function ts(t){return t?t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="FunctionDeclaration":!1}function Et(t,e,r){if(r>=e.length-1)return t;let n=e[r+1];switch(t.type){case"BlockStatement":{let i=t.body.indexOf(n);if(i<0)return t;let s=t.body.slice(0,i);return s.push(Et(n,e,r+1)),{...t,body:s}}case"IfStatement":return n===t.test?{...t,test:Et(n,e,r+1),consequent:{type:"BlockStatement",body:[]},alternate:null}:n===t.consequent?{...t,consequent:Et(n,e,r+1),alternate:null}:n===t.alternate?{...t,alternate:Et(n,e,r+1)}:t;case"ForStatement":case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return n===t.body?{...t,body:Et(n,e,r+1)}:t;case"SwitchStatement":{let i=t.cases.indexOf(n);if(i>=0){let s=t.cases.slice(0,i);return s.push(Et(n,e,r+1)),{...t,cases:s}}return t}case"SwitchCase":{let i=t.consequent.indexOf(n);if(i>=0){let s=t.consequent.slice(0,i);return s.push(Et(n,e,r+1)),{...t,consequent:s}}return t}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":return n===t.body?{...t,body:Et(n,e,r+1)}:t;default:return t}}function d0(t){if(!t||t.type!=="CallExpression")return null;let e=t.callee;if(!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="$"||e.property?.type!=="Identifier"||e.property.name!=="call")return null;let r=t.arguments?.[0];return r?.type==="Identifier"&&typeof r.name=="string"?r.name:null}function f0(t,e,r){let n=t.body||[];for(let i=0;i<n.length;i++){let s=n[i];if(s!==r&&m0(s,e))return i}return-1}function m0(t,e){let r=!1,n=new WeakSet;function i(s){if(!(r||!s||typeof s!="object")&&!n.has(s)){if(n.add(s),d0(s)===e){r=!0;return}for(let a of Object.keys(s)){if(Qo.has(a))continue;let o=s[a];if(Array.isArray(o))for(let l of o)i(l);else o&&typeof o=="object"&&i(o)}}}return i(t),r}function y0(t,e){let r=-1;for(let p=1;p<e.length;p++)if(ts(e[p])){r=p;break}if(r<0)return null;let n=e[r];for(let p=r+1;p<e.length;p++)if(ts(e[p]))return null;if(n.type!=="FunctionDeclaration"||!n.id?.name)return null;let i=n.id.name,s=e.slice(r),a=Et(n,s,0),o=f0(t,i,n);if(o<0)return null;let l=t.body||[],c=l.indexOf(n);if(c<0)return null;let u=[],h=Math.max(o,c);for(let p=0;p<=h;p++){let d=l[p];u.push(d===n?a:d)}return u}function g0(t,e){let r={type:"Program",sourceType:"module",body:[{type:"ExpressionStatement",expression:{type:"ArrowFunctionExpression",async:!!t.async,params:t.params,body:{type:"BlockStatement",body:e}}}]},n=`var _r = ${vs(r)}\n; return _r;`;return new Function("",n)()}function _0(t){let e={};if(!t||t.type!=="Program"||!Array.isArray(t.body)||t.body.length===0)return e;let r=t.body[0],n=null;if(r.type==="ExpressionStatement"){let s=r.expression;s&&(s.type==="ArrowFunctionExpression"||s.type==="FunctionExpression")&&(n=s)}else r.type==="FunctionDeclaration"&&(n=r);if(!n||n.body?.type!=="BlockStatement")return e;let i=h0(n.body);for(let{call:s,path:a}of i){let o=p0(s);if(!o||o in e)continue;let l=a.some(h=>ts(h)),c=null;if(l)c=y0(n.body,a);else{let h=Et(n.body,a,0);c=h&&h.body?h.body:[]}if(!c||c.length===0)continue;let u=g0(n,c);e[o]=u}return e}function x0(t){if(typeof t=="function")return t.toString();{let e=Xo(t);if(e===null)return t;if(e>=5){let r=Cs(t);if(r.success)return r.code;throw new Error(`Failed to transpile Pine Script version ${e}: ${r.error}`)}else throw new Error(`Unsupported Pine Script version ${e}. Only version 5 and above are supported.`)}}function b0(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});let{debug:r}=e,n=x0(t);n=C_(n);let i=r?n.split(`\n`):[],s=xs(n,{ecmaVersion:"latest",sourceType:"module",locations:r});N_(s),w_(s),v_(s);let a=new Vi;A_(s,a),k_(s,a);let o=D_(s,a)||"";if(V_(s),Z_(s,a,o,e,i),Y_(s),z_(s),s.type==="Program"&&s.body.length>0){let d=s.body[0],f=d?.expression||d;f.body?.type==="BlockStatement"&&f.body.body.unshift({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"__maxLoops"},init:{type:"LogicalExpression",operator:"||",left:{type:"MemberExpression",object:{type:"Identifier",name:"$"},property:{type:"Identifier",name:"__maxLoops"},computed:!1},right:{type:"Literal",value:5e5}}}]})}let l=u_||bs||void 0,c=Object.assign({},l,{LineComment(d,f){f.write("//"+d.value)}}),u=vs(s,{generator:c,comments:r}),h=typeof process<"u"&&process?.env?.PINETS_DISABLE_LTF_SLICING==="1"?{}:_0(s),p=new Function("",`var _r = ${u}\n; return _r;`)(this);return h&&Object.keys(h).length>0&&(p._ltfSlices=h),p}var fa={"":["defval","title","tooltip","inline","group","display","active"],bool:["defval","title","tooltip","inline","group","confirm","display","active"],color:["defval","title","tooltip","inline","group","confirm","display","active"],enum:["defval","title","options","tooltip","inline","group","confirm","display","active"],price:["defval","title","tooltip","inline","group","confirm","display","active"],session:["defval","title","options","tooltip","inline","group","confirm","display","active"],source:["defval","title","tooltip","inline","group","display","active","confirm"],string:["defval","title","options","tooltip","inline","group","confirm","display","active"],symbol:["defval","title","tooltip","inline","group","confirm","display","active"],text_area:["defval","title","tooltip","group","confirm","display","active"],time:["defval","title","tooltip","inline","group","confirm","display","active"],timeframe:["defval","title","options","tooltip","inline","group","confirm","display","active"]},v0={bool:"bool",color:"color",enum:"enum",float:"float",int:"int",price:"price",session:"session",source:"source",string:"string",symbol:"symbol",text_area:"text_area",time:"time",timeframe:"timeframe"};function w0(t){if(typeof t!="string")return[];let e=Cs(t);if(!e.success||!e.ast)return[];let r=E0(e.ast),n=S0(e.ast),i=[],s=new Set;return Dt(e.ast,a=>{let o=C0(a,r,n);if(o){if(o.varId!==void 0){if(s.has(o.varId)){console.warn(`[Indicator] duplicate input variable "${o.varId}" \\u2014 first declaration wins for .input access`);return}s.add(o.varId)}i.push(o)}}),i}function E0(t){let e=new Map;return Dt(t,r=>{if(r.type==="VariableDeclaration")for(let n of r.declarations??[]){let i=n?.id?.name,s=n?.init;if(!i||!s||s.type!=="ObjectExpression"||!(s.properties??[]).every(a=>a.value?.type==="Literal"&&typeof a.value.value=="string")||s.properties.length===0)return;for(let a of s.properties)e.set(`${i}.${a.key.name}`,a.value.value)}}),e}function S0(t){let e=new Map;return Dt(t,r=>{if(r.type==="VariableDeclaration")for(let n of r.declarations??[])n?.id?.type==="Identifier"&&n.init&&!e.has(n.id.name)&&e.set(n.id.name,n.init)}),e}function C0(t,e,r){if(t.type!=="VariableDeclaration")return null;for(let n of t.declarations??[]){let i=n?.init;if(!i||i.type!=="CallExpression")continue;let s=i.callee,a=null;if(s?.type==="MemberExpression"&&s.object?.type==="Identifier"&&s.object.name==="input"&&s.property?.type==="Identifier"?a=s.property.name:s?.type==="Identifier"&&s.name==="input"&&(a=""),a===null||a!==""&&!(a==="int"||a==="float")&&!(a in fa))continue;let o=i.arguments??[],l=o[o.length-1],c=l?.type==="ObjectExpression",u=c?o.slice(0,-1):o.slice(),h=c?l.properties??[]:[],p={};a==="int"||a==="float"?N0(u,h,p):Jo(fa[a],u,p);for(let x of h)x.type!=="Property"||!x.key?.name||(p[x.key.name]=x.value);let d={};for(let x of Object.keys(p))d[x]=ln(p[x],e,r);let f=a===""?k0(d.defval):v0[a];if(!f)continue;let m={type:f,defval:d.defval};return n.id?.type==="Identifier"&&typeof n.id.name=="string"&&(m.varId=n.id.name),d.title!==void 0&&(m.title=String(d.title)),d.tooltip!==void 0&&(m.tooltip=String(d.tooltip)),d.group!==void 0&&(m.group=String(d.group)),d.inline!==void 0&&(m.inline=String(d.inline)),d.confirm!==void 0&&(m.confirm=!!d.confirm),d.active!==void 0&&(m.active=!!d.active),d.display!==void 0&&(m.display=I0(d.display)),d.options!==void 0&&Array.isArray(d.options)&&(m.options=d.options),typeof d.minval=="number"&&(m.minval=d.minval),typeof d.maxval=="number"&&(m.maxval=d.maxval),typeof d.step=="number"&&(m.step=d.step),m}return null}function N0(t,e,r){let n=new Set(e.map(i=>i.key?.name).filter(Boolean)).has("options")||t[2]?.type==="ArrayExpression"?["defval","title","options","tooltip","inline","group","confirm","display","active"]:["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display","active"];Jo(n,t,r)}function Jo(t,e,r){for(let n=0;n<e.length&&n<t.length;n++){let i=t[n];r[i]===void 0&&(r[i]=e[n])}}function ln(t,e,r,n=new Set){if(t!=null)switch(t.type){case"Literal":return t.value;case"Identifier":if(ls.has(t.name))return t.name;if(r?.has(t.name)&&!n.has(t.name)){n.add(t.name);let i=ln(r.get(t.name),e,r,n);if(n.delete(t.name),i!==void 0)return i}return t.name;case"MemberExpression":{let i=t.object?.type==="Identifier"?t.object.name:null,s=t.property?.type==="Identifier"?t.property.name:null;if(i&&s){let a=`${i}.${s}`;return e.has(a)?e.get(a):i==="display"?s:a}return}case"CallExpression":{let i=t.callee;if(i?.type==="MemberExpression"&&i.object?.type==="Identifier"&&i.object.name==="color"&&i.property?.type==="Identifier"){let s=i.property.name,a=(t.arguments??[]).map(l=>ln(l,e,r,n)),o=l=>Math.max(0,Math.min(1,l));if(s==="rgb"){let[l,c,u,h]=a;if(typeof l=="number"&&typeof c=="number"&&typeof u=="number"){let p=o(1-(typeof h=="number"?h:0)/100);return mi(l,c,u,p)}}else if(s==="new"){let l=Ga(a[0]),c=a[1];if(l&&typeof c=="number")return mi(l[0],l[1],l[2],o(1-c/100))}}return}case"ArrayExpression":return(t.elements??[]).map(i=>ln(i,e,r,n));case"UnaryExpression":return t.operator==="-"&&t.argument?.type==="Literal"&&typeof t.argument.value=="number"?-t.argument.value:void 0;default:return}}function k0(t){return typeof t=="boolean"?"bool":typeof t=="number"?Number.isInteger(t)?"int":"float":typeof t=="string"?ls.has(t)?"source":t.startsWith("#")?"color":"string":null}function I0(t){if(typeof t!="string")return;let e=t.startsWith("display.")?t.slice(8):t;if(e==="none"||e==="data_window"||e==="status_line"||e==="all")return e}function Dt(t,e){if(!(!t||typeof t!="object")){if(e(t),Array.isArray(t.body))for(let r of t.body)Dt(r,e);else t.body&&Dt(t.body,e);if(Array.isArray(t.consequent))for(let r of t.consequent)Dt(r,e);else t.consequent&&Dt(t.consequent,e);if(t.alternate&&Dt(t.alternate,e),Array.isArray(t.declarations))for(let r of t.declarations)Dt(r,e)}}function el(t,e,r,n,i="key"){let s={},a=new Map;for(let o of t)a.set(o.key,o),s[o.key]=n&&o.key in n?n[o.key]:o.defval;for(let o of t)for(let l of o.aliases??[])!l||a.has(l)||a.set(l,o);return{proxy:new Proxy(s,{get(o,l){if(typeof l=="symbol")return o[l];let c=a.get(l);return c?o[c.key]:o[l]},set(o,l,c){if(typeof l!="string")return!1;let u=a.get(l);if(!u)throw new Error(`[${e}] unknown ${i} "${l}". Known: ${[...a.keys()].join(", ")||"(none)"}`);return A0(u,c,e),o[u.key]=c,r?.(u.key),!0},deleteProperty(o,l){throw new Error(`[${e}] cannot delete "${String(l)}" \\u2014 keys are fixed by the script\'s source.`)},defineProperty(){throw new Error(`[${e}] cannot define new properties \\u2014 keys are fixed by the script\'s source.`)},ownKeys(o){return Reflect.ownKeys(o)},getOwnPropertyDescriptor(o,l){return Reflect.getOwnPropertyDescriptor(o,l)},has(o,l){return typeof l=="string"&&a.has(l)}}),values:s,entryByKey:a}}function A0(t,e,r){let n=t.key;switch(t.type){case"int":if(typeof e!="number"||!Number.isInteger(e))throw new TypeError(`[${r}] "${n}" expects an int; got ${pr(e)}`);break;case"float":case"price":case"time":if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`[${r}] "${n}" expects a number; got ${pr(e)}`);break;case"bool":if(typeof e!="boolean")throw new TypeError(`[${r}] "${n}" expects a boolean; got ${pr(e)}`);break;case"string":case"session":case"symbol":case"timeframe":case"text_area":case"color":case"enum":case"source":if(typeof e!="string")throw new TypeError(`[${r}] "${n}" expects a string; got ${pr(e)}`);break}if(t.options&&!t.options.some(i=>T0(i,e)))throw new RangeError(`[${r}] "${n}" value ${pr(e)} is not one of: ${t.options.map(pr).join(", ")}`);if(typeof e=="number"){if(typeof t.minval=="number"&&e<t.minval)throw new RangeError(`[${r}] "${n}" value ${e} is below minval ${t.minval}`);if(typeof t.maxval=="number"&&e>t.maxval)throw new RangeError(`[${r}] "${n}" value ${e} is above maxval ${t.maxval}`)}}function T0(t,e){return t===e?!0:typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<1e-12:!1}function pr(t){return t===null?"null":typeof t=="string"?JSON.stringify(t):String(t)}function D0(t,e){let r=new Map,n=[];for(let a of t){let o=a.varId??a.title;if(!o)continue;let l=a.title&&a.title!==o?[a.title]:void 0;r.set(o,a),n.push({key:o,type:a.type,defval:a.defval,options:a.options,minval:a.minval,maxval:a.maxval,aliases:l})}let{proxy:i,values:s}=el(n,"Indicator.input",e,void 0,"input key");return{proxy:i,values:s,metaByKey:r}}var tl=[{name:"title",type:"string",defval:"",mutable:!1,appliesTo:"both"},{name:"shorttitle",type:"string",defval:"",mutable:!1,appliesTo:"both"},{name:"overlay",type:"bool",defval:!1,mutable:!0,appliesTo:"both"},{name:"format",type:"enum",defval:"inherit",options:["inherit","price","volume","percent","mintick"],mutable:!0,appliesTo:"both"},{name:"precision",type:"int",defval:10,minval:0,maxval:16,mutable:!0,appliesTo:"both"},{name:"scale",type:"enum",defval:"right",options:["right","left","none"],mutable:!0,appliesTo:"both"},{name:"max_bars_back",type:"int",defval:0,minval:0,maxval:5e3,mutable:!0,appliesTo:"both"},{name:"explicit_plot_zorder",type:"bool",defval:!1,mutable:!0,appliesTo:"both"},{name:"max_lines_count",type:"int",defval:50,minval:1,maxval:500,mutable:!0,appliesTo:"both"},{name:"max_labels_count",type:"int",defval:50,minval:1,maxval:500,mutable:!0,appliesTo:"both"},{name:"max_boxes_count",type:"int",defval:50,minval:1,maxval:500,mutable:!0,appliesTo:"both"},{name:"calc_bars_count",type:"int",defval:0,minval:0,mutable:!0,appliesTo:"both"},{name:"max_polylines_count",type:"int",defval:50,minval:1,maxval:100,mutable:!0,appliesTo:"both"},{name:"dynamic_requests",type:"bool",defval:!0,mutable:!0,appliesTo:"both",version:6},{name:"behind_chart",type:"bool",defval:!0,mutable:!0,appliesTo:"both",version:6}],rl=[...tl.filter(t=>t.appliesTo==="both").map(t=>({...t,appliesTo:"indicator"})),{name:"timeframe",type:"string",defval:"",mutable:!0,appliesTo:"indicator"},{name:"timeframe_gaps",type:"bool",defval:!0,mutable:!0,appliesTo:"indicator"}],nl=[...tl.filter(t=>t.appliesTo==="both").map(t=>({...t,appliesTo:"strategy"})),{name:"pyramiding",type:"int",defval:0,minval:0,mutable:!0,appliesTo:"strategy"},{name:"calc_on_order_fills",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"},{name:"calc_on_every_tick",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"},{name:"backtest_fill_limits_assumption",type:"int",defval:0,minval:0,mutable:!0,appliesTo:"strategy"},{name:"default_qty_type",type:"enum",defval:"fixed",options:["fixed","cash","percent_of_equity"],mutable:!0,appliesTo:"strategy"},{name:"default_qty_value",type:"float",defval:1,minval:0,mutable:!0,appliesTo:"strategy"},{name:"initial_capital",type:"float",defval:1e6,minval:0,mutable:!0,appliesTo:"strategy"},{name:"currency",type:"enum",defval:"USD",options:["AED","ARS","AUD","BDT","BHD","BRL","BTC","CAD","CHF","CLP","CNY","COP","CZK","DKK","EGP","ETH","EUR","GBP","HKD","HUF","IDR","ILS","INR","ISK","JPY","KES","KRW","KWD","LKR","MAD","MXN","MYR","NGN","NOK","NONE","NZD","PEN","PHP","PKR","PLN","QAR","RON","RSD","RUB","SAR","SEK","SGD","THB","TND","TRY","TWD","USD","USDT","VES","VND","ZAR"],mutable:!0,appliesTo:"strategy"},{name:"slippage",type:"int",defval:0,minval:0,mutable:!0,appliesTo:"strategy"},{name:"commission_type",type:"enum",defval:"percent",options:["percent","cash_per_contract","cash_per_order"],mutable:!0,appliesTo:"strategy"},{name:"commission_value",type:"float",defval:0,minval:0,mutable:!0,appliesTo:"strategy"},{name:"process_orders_on_close",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"},{name:"close_entries_rule",type:"enum",defval:"FIFO",options:["FIFO","ANY"],mutable:!0,appliesTo:"strategy"},{name:"margin_long",type:"float",defval:100,minval:0,maxval:100,mutable:!0,appliesTo:"strategy"},{name:"margin_short",type:"float",defval:100,minval:0,maxval:100,mutable:!0,appliesTo:"strategy"},{name:"risk_free_rate",type:"float",defval:2,mutable:!0,appliesTo:"strategy"},{name:"use_bar_magnifier",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"},{name:"fill_orders_on_standard_ohlc",type:"bool",defval:!1,mutable:!0,appliesTo:"strategy"}];function M0(t){return t==="strategy"?nl:rl}function P0(t){return typeof t=="string"?R0(t):typeof t=="function"?F0(t):{type:null,args:{}}}function R0(t){let e=Cs(t);if(!e.success||!e.ast)return{type:null,args:{}};let r=null;return Ln(e.ast,n=>{if(r||n.type!=="ExpressionStatement"&&n.type!=="VariableDeclaration")return;let i=n.type==="ExpressionStatement"?n.expression:n.declarations?.[0]?.init;if(!i||i.type!=="CallExpression")return;let s=i.callee;s?.type==="Identifier"&&(s.name!=="indicator"&&s.name!=="strategy"||(r={type:s.name,args:sl(i.arguments??[],il(s.name))}))}),r??{type:null,args:{}}}function F0(t){let e;try{e=xs(`(${t.toString()})`,{ecmaVersion:"latest"})}catch{return{type:null,args:{}}}let r=null;return Ln(e,n=>{if(r||n.type!=="CallExpression")return;let i=n.callee;i?.type==="Identifier"&&(i.name!=="indicator"&&i.name!=="strategy"||(r={type:i.name,args:sl(n.arguments??[],il(i.name))}))}),r??{type:null,args:{}}}function il(t){return t==="strategy"?nl:rl}function sl(t,e){let r={},n=t[t.length-1],i=n?.type==="ObjectExpression",s=i?t.slice(0,-1):t.slice();for(let a=0;a<s.length&&a<e.length;a++){let o=e[a].name;r[o]=rs(s[a])}if(i)for(let a of n.properties??[])a.type!=="Property"||!a.key?.name||(r[a.key.name]=rs(a.value));return r}function rs(t){if(t!=null)switch(t.type){case"Literal":return t.value;case"Identifier":return t.name;case"MemberExpression":{let e=t;for(;e?.type==="MemberExpression";)e=e.property;return e?.type==="Identifier"?e.name:void 0}case"UnaryExpression":return t.operator==="-"&&t.argument?.type==="Literal"&&typeof t.argument.value=="number"?-t.argument.value:void 0;case"ArrayExpression":return(t.elements??[]).map(rs);default:return}}function Ln(t,e){if(!(!t||typeof t!="object")){e(t);for(let r of Object.keys(t)){let n=t[r];if(!(r==="loc"||r==="range"||r==="start"||r==="end"))if(Array.isArray(n))for(let i of n)Ln(i,e);else n&&typeof n=="object"&&typeof n.type=="string"&&Ln(n,e)}}}function B0(t,e,r){let n=new Map,i=[];for(let o of t)n.set(o.name,o),o.mutable&&i.push({key:o.name,type:o.type,defval:o.defval,options:o.options,minval:o.minval,maxval:o.maxval});let{proxy:s,values:a}=el(i,"Indicator.prop",r,e);return{proxy:s,values:a,propByName:n}}var L0=Object.defineProperty,O0=(t,e,r)=>e in t?L0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ge=(t,e,r)=>O0(t,typeof e!="symbol"?e+"":e,r),Qt=class t{constructor(e,r={}){Ge(this,"source"),Ge(this,"inputs"),Ge(this,"_prepared",null),Ge(this,"_inputMeta",null),Ge(this,"_inputValues",{}),Ge(this,"_explicitOverrides",new Set),Ge(this,"_inputProxy",null),Ge(this,"_propMeta",null),Ge(this,"_propValues",{}),Ge(this,"_propProxy",null),Ge(this,"_declarationType",null),Ge(this,"_sourcePropArgs",{}),Ge(this,"_explicitPropOverrides",new Set),this.source=e,this.inputs=r,Object.defineProperty(this,"input",{get:()=>this._getInputProxy(),set:()=>{throw new Error(\'[Indicator] .input cannot be replaced \\u2014 mutate individual keys (e.g. ind.input["My Title"] = 20).\')},enumerable:!0,configurable:!1}),Object.defineProperty(this,"prop",{get:()=>this._getPropProxy(),set:()=>{throw new Error(\'[Indicator] .prop cannot be replaced \\u2014 mutate individual keys (e.g. ind.prop["initial_capital"] = 50000).\')},enumerable:!0,configurable:!1})}static from(e){return e instanceof t?e:new t(e)}prepare(e={}){if(this._prepared)return this._prepared;let r=b0(this.source,{debug:!!e.debug,ln:e.ln}),n=V0(r),i=r._ltfSlices;return this._prepared={fn:r,inputs:this.getRuntimeInputs(),usesVisibleRange:n,ltfSlices:i},this._prepared}usesVisibleRange(){return this.prepare().usesVisibleRange}getRuntimeInputs(){let e={...this.inputs??{}};if(this._inputMeta)for(let r of this._explicitOverrides)e[r]=this._inputValues[r];return e}getInputsMeta(){return this._ensureInputsScanned(),this._inputMeta}getPropsMeta(){return this._ensurePropsScanned(),this._propMeta}getRuntimePropOverrides(){let e={};if(this._propMeta)for(let r of this._explicitPropOverrides)e[r]=this._propValues[r];return e}getDeclarationType(){return this._ensurePropsScanned(),this._declarationType}_ensureInputsScanned(){if(this._inputMeta)return;this._inputMeta=w0(this.source);for(let r of this._inputMeta)r.type==="color"&&r.defval!==void 0&&(r.defval=Ap(r.defval));let e=D0(this._inputMeta,r=>this._explicitOverrides.add(r));this._inputValues=e.values,this._inputProxy=e.proxy}_getInputProxy(){return this._ensureInputsScanned(),this._inputProxy}_ensurePropsScanned(){if(this._propMeta)return;let e=P0(this.source);this._declarationType=e.type,this._sourcePropArgs=e.args,this._propMeta=M0(e.type);let r=B0(this._propMeta,this._sourcePropArgs,n=>this._explicitPropOverrides.add(n));this._propValues=r.values,this._propProxy=r.proxy}_getPropProxy(){return this._ensurePropsScanned(),this._propProxy}};function V0(t){let e=t.toString();return g_.some(r=>{let n=r.replace(/\\./g,"\\\\.");return new RegExp(`\\\\b${n}\\\\b`).test(e)})}var j0=Object.defineProperty,$0=(t,e,r)=>e in t?j0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ae=(t,e,r)=>$0(t,typeof e!="symbol"?e+"":e,r),ma={1:6e4,3:18e4,5:3e5,15:9e5,30:18e5,60:36e5,120:72e5,180:108e5,240:144e5,"4H":144e5,"1D":864e5,D:864e5,"1W":6048e5,W:6048e5,"1M":30*864e5,M:30*864e5};function W0(t){return t?ma[t]??ma[t.toUpperCase()]??864e5:864e5}var Wt=class{constructor(e,r,n,i,s,a){this.source=e,this.tickerId=r,this.timeframe=n,this.limit=i,this.sDate=s,this.eDate=a,ae(this,"data",[]),ae(this,"open",[]),ae(this,"high",[]),ae(this,"low",[]),ae(this,"close",[]),ae(this,"volume",[]),ae(this,"hl2",[]),ae(this,"hlc3",[]),ae(this,"ohlc4",[]),ae(this,"hlcc4",[]),ae(this,"openTime",[]),ae(this,"closeTime",[]),ae(this,"_readyPromise",null),ae(this,"_ready",!1),ae(this,"_debugSettings",{ln:!1,debug:!1}),ae(this,"_transpiledCode",null),ae(this,"_currentIndicator",null),ae(this,"_isSecondaryContext",!1),ae(this,"_syminfo"),ae(this,"_chartTimezone",null),ae(this,"_maxLoops",5e5),ae(this,"_alertMode","realtime"),ae(this,"_viewportLeft"),ae(this,"_viewportRight"),ae(this,"_usesVisibleRange",!1),ae(this,"_lastRunViewport",{}),ae(this,"_lastResult",null),ae(this,"_lastPineTSCode",null),this._readyPromise=new Promise(o=>{this.loadMarketData(e,r,n,i,s,a).then(l=>{let c=l;this.data=c;let u=c.map(C=>C.open),h=c.map(C=>C.close),p=c.map(C=>C.high),d=c.map(C=>C.low),f=c.map(C=>C.volume),m=c.map(C=>(C.high+C.low+C.close)/3),x=c.map(C=>(C.high+C.low)/2),b=c.map(C=>(C.high+C.low+C.open+C.close)/4),w=c.map(C=>(C.high+C.low+C.close+C.close)/4),v=c.map(C=>C.openTime),E=W0(this.timeframe),A=c.map(C=>C.closeTime!=null?C.closeTime:C.openTime+E);this.open=u,this.close=h,this.high=p,this.low=d,this.volume=f,this.hl2=x,this.hlc3=m,this.ohlc4=b,this.hlcc4=w,this.openTime=v,this.closeTime=A,e&&e.getSymbolInfo?e.getSymbolInfo(r).then(C=>{this._syminfo=C,this._ready=!0,o(!0)}).catch(C=>{console.warn("Failed to get symbol info, using default values:",C),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}get transpiledCode(){return this._transpiledCode}markAsSecondary(){this._isSecondaryContext=!0}setTimezone(e){this._chartTimezone=e}setMaxLoops(e){this._maxLoops=e}setAlertMode(e){this._alertMode=e}setVisibleRange(e,r){this._viewportLeft=e,this._viewportRight=r}usesVisibleRange(){return this._usesVisibleRange}get visibleRangeLeft(){return this._viewportLeft}get visibleRangeRight(){return this._viewportRight}async update(e){let r=e??this._lastPineTSCode;if(!r)throw new Error("pine.update(): pineTSCode is required on the first call.");let n=this._lastResult===null,i=this._viewportLeft!==this._lastRunViewport.left||this._viewportRight!==this._lastRunViewport.right;return n||this._usesVisibleRange&&i?(this._lastPineTSCode=r,this._lastRunViewport={left:this._viewportLeft,right:this._viewportRight},this._lastResult=await this.run(r),this._lastResult):this._lastResult}setDebugSettings({ln:e,debug:r}){this._debugSettings.ln=e,this._debugSettings.debug=r}async loadMarketData(e,r,n,i,s,a){return Array.isArray(e)?e:e.getMarketData(r,n,i,s,a)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,r,n){let i=Qt.from(e);if(this._currentIndicator=i,n&&n>0){let s=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(i,r,n,s)}else return this._runComplete(i,r)}stream(e,r={}){let{live:n=!0,interval:i=1e3}=r,s=r.pageSize||this.data.length,a=Qt.from(e);this._currentIndicator=a;let o={data:[],error:[],warning:[],alert:[]},l=!1,c=(p,...d)=>{o[p]&&o[p].forEach(f=>f(...d))},u=(p,d)=>{o[p]||(o[p]=[]),o[p].push(d)},h=()=>{l=!0};return(async()=>{try{n&&typeof this.eDate<"u"&&(this.eDate=Math.max(this.eDate,Date.now()));let p=!Array.isArray(this.source)&&n,d=this._runPaginated(a,void 0,s,p);for await(let f of d){if(l)break;if(f===null){await new Promise(m=>setTimeout(m,i));continue}if(c("data",f),f.warnings&&f.warnings.length>0){for(let m of f.warnings)c("warning",m);f.warnings.length=0}if(f.alerts&&f.alerts.length>0){for(let m of f.alerts)c("alert",m);f.alerts.length=0}if(p&&!l){let m=f.marketData[f.idx],x=m&&m.closeTime<Date.now(),b=f.idx>=f.marketData.length-1;(!x||b)&&await new Promise(w=>setTimeout(w,i))}}}catch(p){c("error",p)}})(),{on:u,stop:h}}async runPretranspiled(e,r={},n){await this.ready(),n||(n=this.data.length);let i=this._initializeContext(null,r,this._isSecondaryContext);this._transpiledCode=e;let s=e._ltfSlices;return s&&(i._ltfTruncatedBodies=s),await this._executeIterations(i,e,this.data.length-n,this.data.length),i}async _runComplete(e,r){await this.ready(),r||(r=this.data.length);let n=e.prepare(this._debugSettings);this._usesVisibleRange=n.usesVisibleRange;let i=this._initializeContext(e.source??null,n.inputs,this._isSecondaryContext);this._transpiledCode=n.fn,n.ltfSlices&&(i._ltfTruncatedBodies=n.ltfSlices);let s=this.data.length-r,a=this.data.length;return a-s>1?(await this._executeIterations(i,n.fn,s,a-1),i._varSnapshot=this._snapshotVarState(i),await this._executeIterations(i,n.fn,a-1,a)):await this._executeIterations(i,n.fn,s,a),i}async*_runPaginated(e,r,n,i=!1){await this.ready(),r||(r=this.data.length);let s=e.prepare(this._debugSettings);this._usesVisibleRange=s.usesVisibleRange;let a=this._initializeContext(e.source??null,s.inputs,this._isSecondaryContext);this._transpiledCode=s.fn,s.ltfSlices&&(a._ltfTruncatedBodies=s.ltfSlices);let o=this.data.length-r,l=null;for(;;){let c=this.data.length,u=c-o;if(u>0){let m=Math.min(u,n),x=this._getResultLength(a.result),b=o+m;i&&b>=c&&m>1?(await this._executeIterations(a,this._transpiledCode,o,b-1),l=this._snapshotVarState(a),await this._executeIterations(a,this._transpiledCode,b-1,b)):i&&b>=c&&m===1?await this._executeIterations(a,this._transpiledCode,o,b):await this._executeIterations(a,this._transpiledCode,o,b),o+=m,yield this._createPageContext(a,x);continue}if(!i||Array.isArray(this.source))break;let h=Date.now(),{newCandles:p,updatedLastCandle:d}=await this._updateMarketData(),f=Date.now()-h;if(p===0&&!d){yield null;continue}if(p===0&&d&&f<1e3&&await new Promise(m=>setTimeout(m,1e3-f)),a.dataVersion++,a.length=this.data.length,this._restoreVarState(a,l),Array.isArray(a.result))a.result.pop();else if(typeof a.result=="object"&&a.result!==null)for(let m in a.result)Array.isArray(a.result[m])&&a.result[m].pop();a.data.close.data.pop(),a.data.open.data.pop(),a.data.high.data.pop(),a.data.low.data.pop(),a.data.volume.data.pop(),a.data.hl2.data.pop(),a.data.hlc3.data.pop(),a.data.ohlc4.data.pop(),a.data.hlcc4.data.pop(),a.data.openTime.data.pop(),a.data.closeTime&&a.data.closeTime.data.pop(),a.data.bar_index.data.pop(),o=this.data.length-(p+1),a.rollbackDrawings(o),p>0&&(l=null),a.pine.barstate.setLive()}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){let r=Object.keys(e);if(r.length>0&&Array.isArray(e[r[0]]))return e[r[0]].length}return 0}_createPageContext(e,r){let n=new ea({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,fullContext:e,inputs:e.inputs});if(n.pineTSCode=e.pineTSCode,n.idx=e.idx,Array.isArray(e.result))n.result=e.result.slice(r);else if(typeof e.result=="object"&&e.result!==null){n.result={};for(let i in e.result)Array.isArray(e.result[i])?n.result[i]=e.result[i].slice(r):n.result[i]=e.result[i]}else n.result=e.result;return n.plots={...e.plots},n.warnings=e.warnings,n.alerts=e.alerts,n}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};let r=this.source,n=this.data.length-1,i=this.data[n].openTime;try{let s=await r.getMarketData(this.tickerId,this.timeframe,void 0,i,e);if(!s||s.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let l=0;l<s.length;l++){let c=s[l];c.openTime===i?(this._replaceCandle(n,c),a=!0):c.openTime>i&&(this._appendCandle(c),o++)}return{newCandles:o,updatedLastCandle:a}}catch(s){return console.error("Error updating market data:",s),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,r){this.data[e]=r,this.open[e]=r.open,this.close[e]=r.close,this.high[e]=r.high,this.low[e]=r.low,this.volume[e]=r.volume,this.hl2[e]=(r.high+r.low)/2,this.hlc3[e]=(r.high+r.low+r.close)/3,this.ohlc4[e]=(r.high+r.low+r.open+r.close)/4,this.hlcc4[e]=(r.high+r.low+r.close+r.close)/4,this.openTime[e]=r.openTime,this.closeTime[e]=r.closeTime}_appendCandle(e){this.data.push(e),this.open.push(e.open),this.close.push(e.close),this.high.push(e.high),this.low.push(e.low),this.volume.push(e.volume),this.hl2.push((e.high+e.low)/2),this.hlc3.push((e.high+e.low+e.close)/3),this.ohlc4.push((e.high+e.low+e.open+e.close)/4),this.hlcc4.push((e.high+e.low+e.close+e.close)/4),this.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}async updateTail(e){if(this.data.length===0||Array.isArray(this.source))return!1;let{newCandles:r,updatedLastCandle:n}=await this._updateMarketData();if(r===0&&!n)return!1;let i=e._varSnapshot;if(i?this._restoreVarState(e,i):this._removeLastResult(e),Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let o in e.result)Array.isArray(e.result[o])&&e.result[o].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop(),e.dataVersion=(e.dataVersion||0)+1,e.length=this.data.length;let s=this.data.length-(r+1);e.rollbackDrawings(s);let a=this.data.length;return s<a-1?(await this._executeIterations(e,this._transpiledCode,s,a-1),e._varSnapshot=this._snapshotVarState(e),await this._executeIterations(e,this._transpiledCode,a-1,a)):await this._executeIterations(e,this._transpiledCode,s,a),!0}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let i in e.result)Array.isArray(e.result[i])&&e.result[i].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop();let r=["const","var","let","params"],n=i=>{for(let s of r)if(i[s])for(let a in i[s]){let o=i[s][a];o instanceof y?o.data.pop():Array.isArray(o)&&o.pop()}};n(e),e.lctx&&e.lctx.forEach(i=>n(i))}_snapshotVarState(e){let r=["const","var","let","params"],n={main:{},lctx:[]},i=s=>{let a={};for(let o of r)if(s[o]){a[o]={};for(let l in s[o]){let c=s[o][l];if(c instanceof y){let u=c.data.length,h=u>0?c.data[u-1]:void 0;a[o][l]={len:u,lastVal:h}}}}return a};if(n.main=i(e),e.lctx){let s=[];e.lctx.forEach(a=>s.push(i(a))),n.lctx=s}return n.strategy=$f(e.strategy),n.resultLength=this._getResultLength(e.result),n.dataLength=e.data.close?.data?.length??0,n}_restoreVarState(e,r){if(!r)return;let n=["const","var","let","params"],i=(s,a)=>{for(let o of n)if(!(!a[o]||!s[o]))for(let l in a[o]){let c=s[o][l],u=a[o][l];c instanceof y&&u&&typeof u.len=="number"&&(c.data.length>u.len&&(c.data.length=u.len),u.len>0&&u.lastVal!==void 0&&(c.data[u.len-1]=u.lastVal))}};if(i(e,r.main),e.lctx&&r.lctx){let s=0;e.lctx.forEach(a=>{r.lctx[s]&&i(a,r.lctx[s]),s++})}Wf(e.strategy,r.strategy)}_initializeContext(e,r={},n=!1){let i=new ea({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:r});i.pine.syminfo=this._syminfo;let s=Lr(String(this.tickerId??"")).modifier;return i.chartStyle=s==="heikinashi"?"heikinashi":"standard",this._syminfo&&s==="heikinashi"&&(i.pine.syminfo={...this._syminfo,tickerid:vi(String(this._syminfo.tickerid??this.tickerId),"heikinashi")}),this._chartTimezone&&(i.chartTimezone=this._chartTimezone),i.viewportLeft=this._viewportLeft,i.viewportRight=this._viewportRight,i.__maxLoops=this._maxLoops,i._alertMode=this._alertMode,i._propOverrides=this._currentIndicator?.getRuntimePropOverrides()??{},i.pineTSCode=e,i.isSecondaryContext=n,i.data.close=new y([]),i.data.open=new y([]),i.data.high=new y([]),i.data.low=new y([]),i.data.volume=new y([]),i.data.hl2=new y([]),i.data.hlc3=new y([]),i.data.ohlc4=new y([]),i.data.hlcc4=new y([]),i.data.openTime=new y([]),i.data.closeTime=new y([]),i.length=this.data.length,i}async _executeIterations(e,r,n,i){let s=["const","var","let","params"];for(let a=n;a<i;a++){if(e.idx=a,e._execTick=(e._execTick||0)+1,e.data.close.data.push(this.close[a]),e.data.open.data.push(this.open[a]),e.data.high.data.push(this.high[a]),e.data.low.data.push(this.low[a]),e.data.volume.data.push(this.volume[a]),e.data.hl2.data.push(this.hl2[a]),e.data.hlc3.data.push(this.hlc3[a]),e.data.ohlc4.data.push(this.ohlc4[a]),e.data.hlcc4.data.push(this.hlcc4[a]),e.data.openTime.data.push(this.openTime[a]),e.data.closeTime.data.push(this.closeTime[a]),e.data.bar_index.data.push(a),e.strategy){Mf(e),Sf(e),ri(e,"open");let c=Pf(e);c&&ri(e,"extreme"),Df(e,"intrabar"),c||ri(e,"extreme"),Rf(e)}let o=await r(e);if(typeof o=="object"){typeof e.result!="object"&&(e.result={});for(let c in o){e.result[c]===void 0&&(e.result[c]=[]);let u;o[c]instanceof y?u=o[c].get(0):Array.isArray(o[c])?u=o[c][o[c].length-1]:u=o[c],e.result[c].push(u)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(o);for(let c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();let l=c=>{for(let u of s)if(c[u])for(let h in c[u]){let p=c[u][h];if(p instanceof y){let d=p.get(0);p.data.push(d)}else if(Array.isArray(p)){let d=p[p.length-1];p.push(d)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}e.strategy&&Ff(e)}},ya={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},Fr={"1S":1,"5S":5,"10S":10,"15S":15,"30S":30,1:60,3:180,5:300,15:900,30:1800,45:2700,60:3600,120:7200,180:10800,240:14400,D:86400,W:604800,M:2592e3};function Br(t,e,r=1){if(e==="month"){let i=new Date(t);return Date.UTC(i.getUTCFullYear(),i.getUTCMonth()+r,1,i.getUTCHours(),i.getUTCMinutes(),i.getUTCSeconds(),i.getUTCMilliseconds())}let n={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+r*n[e]}function St(t,e,r){let[n,i,s]=t.split("-").map(Number),[a,o]=e.split(":").map(Number),l=Date.UTC(n,i-1,s,a,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:r,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(l)),u=b=>parseInt(c.find(w=>w.type===b).value,10),h=u("year"),p=u("month"),d=u("day"),f=u("hour");f===24&&(f=0);let m=u("minute"),x=Date.UTC(h,p-1,d,f,m,0,0)-l;return l-x}function ga(t,e,r,n,i=1){if(e==="24x7")return Br(t,n,i);let s=e.split("-")[1];if(!s||s.length!==4)return Br(t,n,i);let a=s.slice(0,2),o=s.slice(2,4),l=`${a}:${o}`,c=_a(t,r);if(n==="second"||n==="minute"||n==="hour"){let u=t+i*{second:1e3,minute:6e4,hour:36e5}[n],h=St(c,l,r);return Math.min(u,h)}if(n==="day")return St(c,l,r);if(n==="week"){let u=new Date(t).getUTCDay(),h=u<=5?5-u:5-u+7,p=t+h*864e5,d=_a(p,r);return St(d,l,r)}if(n==="month"){let u=new Date(t),h=u.getUTCFullYear(),p=u.getUTCMonth()+i,d=new Date(Date.UTC(h,p,1)),f=new Date(d.getTime()-864e5);for(;f.getUTCDay()===0||f.getUTCDay()===6;)f.setUTCDate(f.getUTCDate()-1);let m=f.toISOString().split("T")[0];return St(m,l,r)}return Br(t,n,i)}function _a(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function U0(t){for(let e=0;e<t.length-1;e++)t[e].closeTime=t[e+1].openTime;t.length>0&&(t[t.length-1].closeTime=t[t.length-1].closeTime+1)}var q0=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function z0(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;let r=Fr[t];if(!r)return null;let n=q0.filter(i=>i!=="W"&&i!=="M"&&e.has(i)&&Fr[i]<r&&r%Fr[i]===0);return n.length===0?null:n[n.length-1]}function al(t,e){if(t==="W"||t==="M")return 1/0;let r=Fr[t],n=Fr[e];return!r||!n||n===0?1/0:r/n}function K0(t,e,r){if(t.length===0)return[];if(e==="W")return G0(t);if(e==="M")return Y0(t);let n=al(e,r);return H0(t,n)}function H0(t,e){if(t.length===0)return[];let r=[],n=[t[0]],i=Z0(t),s=i>0?i*1.5:0;for(let a=1;a<t.length;a++){let o=t[a].openTime-t[a-1].openTime;(s>0&&o>s||n.length>=e)&&(r.push(On(n)),n=[]),n.push(t[a])}return n.length>0&&r.push(On(n)),r}function G0(t){let e=[],r=[],n="";for(let i of t){let s=X0(i.openTime);s!==n&&r.length>0&&(e.push(r),r=[]),n=s,r.push(i)}return r.length>0&&e.push(r),e.map(On)}function Y0(t){let e=[],r=[],n="";for(let i of t){let s=new Date(i.openTime),a=`${s.getUTCFullYear()}-${s.getUTCMonth()}`;a!==n&&r.length>0&&(e.push(r),r=[]),n=a,r.push(i)}return r.length>0&&e.push(r),e.map(On)}function On(t){let e=t[0],r=t[t.length-1],n=e.high,i=e.low,s=0,a=0,o=0,l=0,c=0;for(let u=0;u<t.length;u++){let h=t[u];h.high>n&&(n=h.high),h.low<i&&(i=h.low),s+=h.volume,a+=h.quoteAssetVolume,o+=h.numberOfTrades,l+=h.takerBuyBaseAssetVolume,c+=h.takerBuyQuoteAssetVolume}return{openTime:e.openTime,open:e.open,high:n,low:i,close:r.close,volume:s,closeTime:r.closeTime,quoteAssetVolume:a,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function Z0(t){if(t.length<2)return 0;let e=Math.min(t.length-1,20),r=1/0;for(let n=0;n<e;n++){let i=t[n+1].openTime-t[n].openTime;i>0&&i<r&&(r=i)}return r===1/0?0:r}function X0(t){let e=new Date(t),r=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-r);let n=new Date(Date.UTC(e.getUTCFullYear(),0,1)),i=Math.ceil(((e.getTime()-n.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${i}`}var Q0=Object.defineProperty,J0=(t,e,r)=>e in t?Q0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Jr=(t,e,r)=>J0(t,typeof e!="symbol"?e+"":e,r),en={"1s":"1S","5s":"5S","10s":"10S","15s":"15S","30s":"30S","1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","1d":"D","1w":"W","1D":"D","1W":"W","1M":"M","4H":"240",D:"D",W:"W",M:"M"};function ex(t){if(en[t]!==void 0)return en[t];let e=t.toLowerCase();return en[e]!==void 0?en[e]:/^\\d+$/.test(t)?t:/^\\d+S$/i.test(t)?t.toUpperCase():t}var jr=class{constructor(e){Jr(this,"_configured"),Jr(this,"_requiresApiKey"),Jr(this,"_providerName"),Jr(this,"_aggregationSubTimeframe",null),this._requiresApiKey=e.requiresApiKey,this._providerName=e.providerName,this._configured=!e.requiresApiKey}ensureConfigured(){if(!this._configured)throw new Error(`${this._providerName} requires configuration before use. Call Provider.${this._providerName}.configure({ apiKey: \'...\' }) or instantiate directly: new ${this._providerName}Provider({ apiKey: \'...\' })`)}configure(e){this._configured=!0}get isConfigured(){return this._configured}normalizeCloseTime(e){U0(e)}setAggregationSubTimeframe(e){this._aggregationSubTimeframe=e}getSupportedTimeframes(){return new Set(["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"])}async getMarketData(e,r,n,i,s){e=Ot(e);let a=ex(r),o=this.getSupportedTimeframes();if(o.has(a))return this._getMarketDataNative(e,a,n,i,s);let l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:z0(a,o);if(!c)return console.error(`${this._providerName}: Timeframe \'${r}\' is not supported and no valid sub-timeframe found for aggregation.`),[];let u=this._computeSubLimit(a,c,n),h=await this._getMarketDataNative(e,c,u,i,s);if(h.length===0)return[];let p=K0(h,a,c);return n&&n>0&&p.length>n?p.slice(p.length-n):p}_computeSubLimit(e,r,n){if(!n)return;let i=al(e,r);return i===1/0?e==="W"?n*7+14:e==="M"?n*31+31:n*30:Math.ceil(n*i)+Math.ceil(i)}},tx=Object.defineProperty,rx=(t,e,r)=>e in t?tx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Vn=(t,e,r)=>rx(t,typeof e!="symbol"?e+"":e,r),ci="https://api.binance.com/api/v3",xa="https://api.binance.us/api/v3",tn={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",45:null,60:"1h",120:"2h",180:null,240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"},ns=class{constructor(e=300*1e3){Vn(this,"cache"),Vn(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([r,n])=>n!==void 0).map(([r,n])=>`${r}:${n}`).join("|")}get(e){let r=this.generateKey(e),n=this.cache.get(r);return n?Date.now()-n.timestamp>this.cacheDuration?(this.cache.delete(r),null):n.data:null}set(e,r){let n=this.generateKey(e);this.cache.set(n,{data:r,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){let e=Date.now();for(let[r,n]of this.cache.entries())e-n.timestamp>this.cacheDuration&&this.cache.delete(r)}},is=class extends jr{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),Vn(this,"cacheManager"),Vn(this,"activeApiUrl",null),this.cacheManager=new ns(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{let e=new AbortController,r=setTimeout(()=>e.abort(),5e3),n=await fetch(`${ci}/ping`,{signal:e.signal});if(clearTimeout(r),n.ok)return this.activeApiUrl=ci,this.activeApiUrl}catch{}try{let e=new AbortController,r=setTimeout(()=>e.abort(),5e3),n=await fetch(`${xa}/ping`,{signal:e.signal});if(clearTimeout(r),n.ok)return this.activeApiUrl=xa,this.activeApiUrl}catch{}return ci}async _fetchRawChunk(e,r,n,i,s){let a=tn[r.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${r}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${a}`;n&&(o+=`&limit=${Math.min(n,1e3)}`),i&&(o+=`&startTime=${i}`),s&&(o+=`&endTime=${s}`);let l=await fetch(o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return(await l.json()).map(c=>({openTime:parseInt(c[0]),open:parseFloat(c[1]),high:parseFloat(c[2]),low:parseFloat(c[3]),close:parseFloat(c[4]),volume:parseFloat(c[5]),closeTime:parseInt(c[6]),quoteAssetVolume:parseFloat(c[7]),numberOfTrades:parseInt(c[8]),takerBuyBaseAssetVolume:parseFloat(c[9]),takerBuyQuoteAssetVolume:parseFloat(c[10]),ignore:c[11]}))}async getMarketDataInterval(e,r,n,i){try{let s=tn[r.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${r}`),[];let a=[],o=n,l=i,c=ya[s];if(!c)return console.error(`Duration not defined for interval: ${s}`),[];for(;o<l;){let u=Math.min(o+1e3*c,l),h=await this._fetchRawChunk(e,r,1e3,o,u);if(h.length===0)break;a=a.concat(h),o=h[h.length-1].closeTime+1}return this.normalizeCloseTime(a),a}catch(s){return console.error("Error in getMarketDataInterval:",s),[]}}async getMarketDataBackwards(e,r,n,i){let s=n,a=[],o=i,l=0,c=Math.ceil(n/1e3)+5;for(;s>0&&l<c;){l++;let u=Math.min(s,1e3),h=await this._fetchRawChunk(e,r,u,void 0,o);if(h.length===0||(a=h.concat(a),s-=h.length,o=h[0].openTime-1,h.length<u))break}return this.normalizeCloseTime(a),a}getSupportedTimeframes(){return new Set(["1","3","5","15","30","60","120","240","D","W","M"])}async _getMarketDataNative(e,r,n,i,s){try{let a=s!==void 0,o={tickerId:e,timeframe:r,limit:n,sDate:i,eDate:s};if(a){let c=this.cacheManager.get(o);if(c)return c}if(!tn[r.toUpperCase()])return console.error(`Unsupported timeframe: ${r}`),[];if(this.shouldPaginate(r,n,i,s)){if(i&&s){let c=await this.getMarketDataInterval(e,r,i,s),u=n?c.slice(0,n):c;return this.cacheManager.set(o,u),u}else if(n&&n>1e3){let c=await this.getMarketDataBackwards(e,r,n,s);return this.cacheManager.set(o,c),c}}let l=await this._fetchRawChunk(e,r,n,i,s);return this.normalizeCloseTime(l),a&&this.cacheManager.set(o,l),l}catch(a){return console.error("Error in binance.klines:",a),[]}}shouldPaginate(e,r,n,i){if(r&&r>1e3)return!0;if(n&&i){let s=tn[e.toUpperCase()],a=ya[s];if(a)return Math.ceil((i-n)/a)>1e3}return!1}async getSymbolInfo(e){e=Ot(e);try{let r="crypto",n=await this.getBaseUrl(),i=e,s="";e.endsWith(".P")?(r="futures",i=e.replace(".P",""),n="https://fapi.binance.com/fapi/v1",s="Perpetual"):e.includes("_")&&(r="futures",i=e,n="https://dapi.binance.com/dapi/v1",s="Delivery");let a=r==="crypto"?`${n}/exchangeInfo?symbol=${i}`:`${n}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;let c=r==="futures"?l.find(v=>v.symbol===i):l[0];if(!c)return console.error(`Symbol ${i} not found in exchange info`),null;let u=c.filters?.find(v=>v.filterType==="PRICE_FILTER"),h=c.filters?.find(v=>v.filterType==="LOT_SIZE"),p=u?parseFloat(u.tickSize):.01,d=h?parseFloat(h.minQty):0,f=Math.round(1/p),m=c.baseAsset,x=c.quoteAsset,b=s?` ${s}`:"",w=`${m} / ${x}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:m,description:w,type:r,main_tickerid:`BINANCE:${e}`,current_contract:s,isin:"",basecurrency:m,currency:x,timezone:"Etc/UTC",country:"",mintick:p,pricescale:f,minmove:1,pointvalue:c.contractSize||1,mincontract:d,session:"24x7",volumetype:"base",expiration_date:c.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(r){return console.error("Error in binance.exchangeInfo:",r),null}}},nx=Object.defineProperty,ix=(t,e,r)=>e in t?nx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Er=(t,e,r)=>ix(t,typeof e!="symbol"?e+"":e,r),sx="https://financialmodelingprep.com",ba=new Set(["USD","EUR","GBP","JPY","CHF","AUD","CAD","NZD","SEK","NOK","DKK","SGD","HKD","KRW","MXN","ZAR","TRY","BRL","INR","CNY","PLN","CZK","HUF","ILS","THB","TWD","PHP","IDR","MYR","RUB","CLP","COP"]),va={"1D":{endpoint:"/stable/historical-price-eod/full",type:"daily"},D:{endpoint:"/stable/historical-price-eod/full",type:"daily"},1:{endpoint:"/stable/historical-chart/1min",interval:"1min",type:"intraday"},5:{endpoint:"/stable/historical-chart/5min",interval:"5min",type:"intraday"},15:{endpoint:"/stable/historical-chart/15min",interval:"15min",type:"intraday"},30:{endpoint:"/stable/historical-chart/30min",interval:"30min",type:"intraday"},60:{endpoint:"/stable/historical-chart/1hour",interval:"1hour",type:"intraday"},240:{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"},"4H":{endpoint:"/stable/historical-chart/4hour",interval:"4hour",type:"intraday"}},wa={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",NYSEArca:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",PNK:"America/New_York",TSX:"America/Toronto",TSXV:"America/Toronto",LSE:"Europe/London",EURONEXT:"Europe/Paris",XETRA:"Europe/Berlin",JPX:"Asia/Tokyo",HKSE:"Asia/Hong_Kong",SSE:"Asia/Shanghai",SHZ:"Asia/Shanghai",ASX:"Australia/Sydney",NSE:"Asia/Kolkata",BSE:"Asia/Kolkata",KRX:"Asia/Seoul",CRYPTO:"Etc/UTC"},Ea={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",NYSEArca:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",PNK:"0930-1600",TSX:"0930-1600",TSXV:"0930-1600",LSE:"0800-1630",EURONEXT:"0900-1730",XETRA:"0900-1730",JPX:"0900-1530",HKSE:"0930-1600",SSE:"0930-1500",SHZ:"0930-1500",ASX:"1000-1600",NSE:"0915-1530",BSE:"0915-1530",KRX:"0900-1530",CRYPTO:"24x7"},ax={daily:{periodType:"day",multiplier:1},"1min":{periodType:"minute",multiplier:1},"5min":{periodType:"minute",multiplier:5},"15min":{periodType:"minute",multiplier:15},"30min":{periodType:"minute",multiplier:30},"1hour":{periodType:"hour",multiplier:1},"4hour":{periodType:"hour",multiplier:4}},ss=class extends jr{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),Er(this,"_apiKey",null),Er(this,"_baseUrl",sx),Er(this,"_profileCache",new Map),Er(this,"_symbolInfoCache",new Map),Er(this,"_mintickCache",new Map),e?.apiKey&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,e.baseUrl&&(this._baseUrl=e.baseUrl)}getSupportedTimeframes(){return new Set(["1","5","15","30","60","240","D"])}async _getMarketDataNative(e,r,n,i,s){this.ensureConfigured();try{let a=r.toUpperCase(),o=va[a]||va[r];if(!o)return console.error(`FMP: Unsupported timeframe: ${r}`),[];let l;if(o.type==="intraday"?l=await this._fetchIntradayData(e,o.endpoint,o.interval,i,s,n):l=await this._fetchDailyData(e,i,s,n),l.length>0&&!this._mintickCache.has(e)){let c=this._estimateMintick(l);c!==void 0&&this._mintickCache.set(e,c)}return l}catch(a){return console.error("Error in FMPProvider.getMarketData:",a),[]}}async _fetchDailyData(e,r,n,i){let s=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;r&&(s+=`&from=${this._msToDateStr(r)}`),n&&(s+=`&to=${this._msToDateStr(n)}`);let a=await fetch(s);if(!a.ok){let h=await a.text();throw new Error(`FMP HTTP ${a.status}: ${h}`)}let o=await a.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();let l=i&&i>0&&i<o.length?o.slice(o.length-i):o,{session:c,timezone:u}=await this._resolveSessionInfo(e);return l.map(h=>{let p=this._dateStrToMs(h.date),d=ga(p,c,u,"day");return{openTime:p,open:h.open,high:h.high,low:h.low,close:h.close,volume:h.volume,closeTime:d,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,r,n,i,s,a){let o=`${this._baseUrl}${r}?symbol=${e}&apikey=${this._apiKey}`;i&&(o+=`&from=${this._msToDateStr(i)}`),s&&(o+=`&to=${this._msToDateStr(s)}`);let l=await fetch(o);if(!l.ok){let m=await l.text();if(l.status===403||m.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${n}) requires a paid plan. Use daily timeframe (\'D\') with a free API key, or upgrade at https://financialmodelingprep.com/`),[];throw new Error(`FMP HTTP ${l.status}: ${m}`)}let c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();let u=a&&a>0&&a<c.length?c.slice(c.length-a):c,{periodType:h,multiplier:p}=ax[n]||{periodType:"minute",multiplier:1},{session:d,timezone:f}=await this._resolveSessionInfo(e);return u.map(m=>{let x=this._dateTimeStrToMs(m.date),b=ga(x,d,f,h,p);return{openTime:x,open:m.open,high:m.high,low:m.low,close:m.close,volume:m.volume,closeTime:b,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async getSymbolInfo(e){if(this.ensureConfigured(),e=Ot(e),this._symbolInfoCache.has(e))return this._symbolInfoCache.get(e);try{let r=await this._fetchProfile(e),n="stock";r?.isEtf?n="etf":r?.isFund?n="fund":this._isForex(e)?n="forex":this._isCrypto(e)&&(n="crypto");let i=r?.exchange||(n==="crypto"?"CRYPTO":n==="forex"?"FX":""),s=n==="crypto"||n==="forex"?"Etc/UTC":wa[i]||"America/New_York",a=n==="crypto"?"24x7":n==="forex"?"0000-0000":Ea[i]||"0930-1600",o=r?.currency||(this._isForex(e)?e.slice(3,6):"USD"),l=this._isForex(e)?e.slice(0,3):r?.currency||"USD",c=this._mintickCache.get(e)??.01,u=Math.round(1/c),h=Math.round(c*u),p={ticker:r?.symbol||e,tickerid:`${i}:${r?.symbol||e}`,prefix:i,root:r?.symbol||e,description:r?.companyName||e,type:n,main_tickerid:`${i}:${r?.symbol||e}`,current_contract:"",isin:r?.isin||"",basecurrency:l,currency:o,timezone:s,country:r?.country||"",mintick:c,pricescale:u,minmove:h,pointvalue:1,mincontract:0,session:a,volumetype:"base",expiration_date:0,employees:r&&parseInt(r.fullTimeEmployees)||0,industry:r?.industry||"",sector:r?.sector||"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0};return this._mintickCache.has(e)&&this._symbolInfoCache.set(e,p),p}catch(r){return console.error("Error in FMPProvider.getSymbolInfo:",r),null}}_estimateMintick(e){let r=[];for(let o=0;o<e.length;o++){let l=e[o],c=Math.abs(l.close-l.open),u=Math.abs(l.high-l.low);if(c>0&&r.push(c),u>0&&r.push(u),o>0){let h=Math.abs(l.close-e[o-1].close);h>0&&r.push(h)}}if(r.length===0)return;let n=Math.min(...r),i=Math.floor(Math.log10(n)),s=n/10**i,a=(Math.floor(s+1e-12)<5?1:10)*10**i;return a>=1?.01:a}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);let r=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,n=await fetch(r);if(!n.ok)return null;let i=await n.json();if(!Array.isArray(i)||i.length===0)return null;let s=i[0];return this._profileCache.set(e,s),s}async _resolveSessionInfo(e){try{let r=await this._fetchProfile(e);if(r){let n=r.exchange||"",i=this._isCrypto(e),s=i?"Etc/UTC":wa[n]||"America/New_York";return{session:i?"24x7":Ea[n]||"0930-1600",timezone:s}}}catch{}return{session:"0930-1600",timezone:"America/New_York"}}_msToDateStr(e){return new Date(e).toISOString().split("T")[0]}_dateStrToMs(e){return new Date(e+"T00:00:00Z").getTime()}_dateTimeStrToMs(e){return new Date(e.replace(" ","T")+"Z").getTime()}_isForex(e){return/^[A-Z]{6}$/.test(e)&&ba.has(e.slice(0,3))&&ba.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}},ox=Object.defineProperty,lx=(t,e,r)=>e in t?ox(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zt=(t,e,r)=>lx(t,typeof e!="symbol"?e+"":e,r),cx="https://data.alpaca.markets",ux="https://paper-api.alpaca.markets/v2",px="https://api.alpaca.markets/v2",ui=1e4,Sa={1:"1Min",3:"3Min",5:"5Min",15:"15Min",30:"30Min",60:"1Hour",120:"2Hour",240:"4Hour","4H":"4Hour","1D":"1Day",D:"1Day","1W":"1Week",W:"1Week","1M":"1Month",M:"1Month"},hx={NASDAQ:"America/New_York",NYSE:"America/New_York",AMEX:"America/New_York",ARCA:"America/New_York",BATS:"America/New_York",OTC:"America/New_York",CRYPTO:"Etc/UTC"},dx={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},fx={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"},as=class extends jr{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),zt(this,"_apiKey",null),zt(this,"_apiSecret",null),zt(this,"_dataUrl",cx),zt(this,"_tradingUrl",ux),zt(this,"_feed",null),zt(this,"_assetCache",new Map),zt(this,"_calendarCache",new Map),e?.apiKey&&e?.apiSecret&&this.configure(e)}configure(e){super.configure(e),this._apiKey=e.apiKey,this._apiSecret=e.apiSecret,e.feed&&(this._feed=e.feed),e.dataUrl&&(this._dataUrl=e.dataUrl),e.tradingUrl?this._tradingUrl=e.tradingUrl:e.paper===!1&&(this._tradingUrl=px)}_headers(){return{"APCA-API-KEY-ID":this._apiKey,"APCA-API-SECRET-KEY":this._apiSecret}}getSupportedTimeframes(){return new Set(["1","3","5","15","30","45","60","120","180","240","D","W","M"])}async _getMarketDataNative(e,r,n,i,s){this.ensureConfigured();try{let a=this._resolveTimeframe(r);if(!a)return console.error(`Alpaca: Unsupported timeframe: ${r}`),[];let o=this._isCrypto(e),l=await this._fetchAllBars(e,a,o,i,s,n);if(l.length===0)return[];let{periodType:c,multiplier:u}=this._parseAlpacaTimeframe(a);if(o)return this._convertBarsCrypto(l,c,u);let h=l[0].t.slice(0,10),p=l[l.length-1].t.slice(0,10),d=this._addDaysToDate(p,40);return await this._ensureCalendar(h,d),this._convertBarsStock(l,c,u)}catch(a){return console.error("Error in AlpacaProvider.getMarketData:",a),[]}}async _fetchAllBars(e,r,n,i,s,a){let o=[],l=null,c=a||1/0,u=Math.min(a||ui,ui);do{let h=this._buildBarsUrl(e,r,n,i,s,u,l),p=await fetch(h,{headers:this._headers()});if(!p.ok){let m=await p.text();throw new Error(`Alpaca HTTP ${p.status}: ${m}`)}let d=await p.json(),f=Object.keys(d.bars||{})[0];if(!f||!d.bars[f]||(o.push(...d.bars[f]),l=d.next_page_token,o.length>=c))break}while(l);return a&&a>0&&o.length>a?o.slice(0,a):o}_buildBarsUrl(e,r,n,i,s,a,o){let l=n?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",r),c.set("sort","asc"),i&&c.set("start",new Date(i).toISOString()),s&&c.set("end",new Date(s).toISOString()),a&&c.set("limit",String(Math.min(a,ui))),o&&c.set("page_token",o),!n&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured(),e=Ot(e);try{let r=await this._fetchAsset(e);if(!r)return console.error(`Alpaca: Symbol ${e} not found`),null;let n=r.exchange||"",i=r.class==="crypto",s=i?"Etc/UTC":hx[n]||"America/New_York",a=i?"24x7":dx[n]||"0930-1600",o="stock";i&&(o="crypto");let l=i&&e.split("/")[1]||"USD",c=i?e.split("/")[0]||e:l,u=r.price_increment?parseFloat(r.price_increment):.01,h=Math.round(1/u);return{ticker:r.symbol,tickerid:`${n}:${r.symbol}`,prefix:n,root:i?e.split("/")[0]:r.symbol,description:r.name||r.symbol,type:o,main_tickerid:`${n}:${r.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:s,country:i?"":"US",mintick:u,pricescale:h,minmove:1,pointvalue:1,mincontract:r.min_order_size?parseFloat(r.min_order_size):0,session:a,volumetype:"base",expiration_date:0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(r){return console.error("Error in AlpacaProvider.getSymbolInfo:",r),null}}_convertBarsCrypto(e,r,n){return e.map((i,s,a)=>{let o=new Date(i.t).getTime(),l=s<a.length-1?new Date(a[s+1].t).getTime():Br(o,r,n);return this._toKline(i,o,l)})}_convertBarsStock(e,r,n){let i="America/New_York";return e.map(s=>{let a=new Date(s.t).getTime(),o=s.t.slice(0,10),l;if(r==="day"){let c=this._calendarCache.get(o),u=c?c.close:"16:00";l=St(o,u,i)}else if(r==="minute"||r==="hour"){let c=a+n*{minute:6e4,hour:36e5}[r],u=this._calendarCache.get(o),h=u?u.close:"16:00",p=St(o,h,i);l=Math.min(c,p)}else r==="week"?l=this._weeklyCloseFromCalendar(o,i):r==="month"?l=this._monthlyCloseFromCalendar(o,i):l=Br(a,r,n);return this._toKline(s,a,l)})}_toKline(e,r,n){return{openTime:r,open:e.o,high:e.h,low:e.l,close:e.c,volume:e.v,closeTime:n,quoteAssetVolume:0,numberOfTrades:e.n,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}}_weeklyCloseFromCalendar(e,r){let n=new Date(e+"T00:00:00Z"),i=n.getUTCDay(),s=i<=5?5-i:5-i+7;for(let l=s;l>=0;l--){let c=n.getTime()+l*864e5,u=new Date(c).toISOString().split("T")[0],h=this._calendarCache.get(u);if(h)return St(u,h.close,r)}let a=n.getTime()+s*864e5,o=new Date(a).toISOString().split("T")[0];return St(o,"16:00",r)}_monthlyCloseFromCalendar(e,r){let[n,i]=e.split("-").map(Number),s=new Date(Date.UTC(n,i,0)).getUTCDate();for(let o=s;o>=1;o--){let l=`${n}-${String(i).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return St(l,c.close,r)}let a=new Date(Date.UTC(n,i,0));for(;a.getUTCDay()===0||a.getUTCDay()===6;)a.setUTCDate(a.getUTCDate()-1);return St(a.toISOString().split("T")[0],"16:00",r)}async _ensureCalendar(e,r){if(this._calendarCache.has(e)&&this._calendarCache.has(r))return;let n=`${this._tradingUrl}/calendar?start=${e}&end=${r}`,i=await fetch(n,{headers:this._headers()});if(!i.ok){console.warn(`Alpaca calendar API returned ${i.status}, falling back to defaults`);return}let s=await i.json();for(let a of s)this._calendarCache.set(a.date,a)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);let r=encodeURIComponent(e),n=`${this._tradingUrl}/assets/${r}`,i=await fetch(n,{headers:this._headers()});if(!i.ok)return null;let s=await i.json();return this._assetCache.set(e,s),s}_parseAlpacaTimeframe(e){let r=e.match(/^(\\d+)(Min|Hour|Day|Week|Month)$/);if(r){let n=parseInt(r[1],10),i=fx[r[2]];if(i)return{periodType:i,multiplier:n}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return Sa[e.toUpperCase()]||Sa[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,r){let n=new Date(e+"T00:00:00Z");return n.setUTCDate(n.getUTCDate()+r),n.toISOString().split("T")[0]}},os=class{async getMarketData(){return[]}},mx=typeof process<"u"&&process.versions&&process.versions.node,jn=null;if(mx)try{jn=new os}catch{jn=null}var ib={Binance:new is,FMP:new ss,Alpaca:new as,...jn?{Mock:jn}:{}};function O(t){return typeof t=="string"?t:void 0}function _e(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function yx(t){let e=new Map,r=!1;for(let i=0;i<t.length;i+=1){let s=t[i].time;e.has(s)&&(r=!0),e.set(s,i)}if(!r)return t;let n=new Set(e.values());return t.filter((i,s)=>n.has(s))}function Gn(t){let e=t??{},r=e.fullContext??e,n=r.indicator??r.strategy?.config??{},i={title:O(n.title)??"Indicator",overlay:n.overlay===!0,precision:_e(n.precision),shorttitle:O(n.shorttitle),format:O(n.format)},s=r.plots??{},a=Object.entries(s).map(([l,c])=>{let u=c??{},h=u.options??{};return{key:l,title:O(u.title),style:O(h.style),options:h,data:Array.isArray(u.data)?yx(u.data):[],plot1:O(u.plot1)??O(h.plot1),plot2:O(u.plot2)??O(h.plot2)}}),o=r.strategy?gx(r.strategy):void 0;return{meta:i,plots:a,...o?{trades:o}:{}}}function gx(t){let e=[],r=Array.isArray(t.closedtrades)?t.closedtrades:[],n=Array.isArray(t.opentrades)?t.opentrades:[];for(let i of[...r,...n]){let s=i??{},a=_e(s.entry_price),o=_e(s.entry_time),l=_e(s.size);a===void 0||o===void 0||l===void 0||l===0||e.push({id:O(s.id)??`trade_${e.length}`,entry_id:O(s.entry_id)??"",entry_price:a,entry_time:o,entry_comment:O(s.entry_comment),exit_id:O(s.exit_id),exit_price:_e(s.exit_price),exit_time:_e(s.exit_time),exit_comment:O(s.exit_comment),size:l,status:s.status==="closed"?"closed":"open"})}return e}var _x={line:"line",style_line:"line",style_linebr:"line",style_area:"area",style_areabr:"area",style_stepline:"step",style_steplinebr:"step",style_stepline_diamond:"step",style_histogram:"histogram",style_columns:"columns",style_circles:"circles",style_cross:"cross",shape:"markers",char:"markers",bar:"bar",candle:"candle",background:"background",barcolor:"barcolor",hline:"hline",fill:"fill",drawing_line:"drawing_line",drawing_box:"drawing_box",label:"label",drawing_polyline:"drawing_polyline",linefill:"linefill",table:"table"};function ol(t){return t==null||t===""?"line":_x[t]??"line"}function xx(t){if(typeof t!="string")return!1;let e=t.trim();if(!e)return!1;let r=e.toLowerCase();if(r==="na"||r==="nan")return!1;let n=/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})$/.exec(e);return!(n&&parseInt(n[1]??"ff",16)===0||/rgba?\\([^)]*,\\s*0(?:\\.0+)?\\s*\\)$/.test(e))}function re(t,e){return xx(t)?t.trim():e}function Ns(t){let e=t.title.trim().toLowerCase().replace(/\\s+/g,"-");return`${t.instanceId}:${t.kind}:${e}#${t.ordinal}`}var ks="#2962ff";var bx=new Map;function P(t,e){bx.set(t,e)}function vx(t,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">${t}</svg>`}function me(t,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">${t}</svg>`}var $=vx;P("style-candles",$(\'<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"/>\'));P("style-bars",$(\'<path d="M4.5 2.5v11M2.5 5h2M4.5 11h2"/><path d="M11.5 2.5v11M9.5 4.5h2M11.5 10.5h2"/>\'));P("style-line",$(\'<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/>\'));P("style-area",$(\'<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"/>\'));P("style-baseline",$(\'<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"/>\'));P("style-heikinashi",$(\'<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"/>\'));P("indicators",$(\'<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"/>\'));P("undo",$(\'<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"/>\'));P("redo",$(\'<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"/>\'));P("objects",$(\'<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"/>\'));P("clock",$(\'<circle cx="8" cy="8" r="6.2"/><path d="M8 4.8V8l2.4 1.6"/>\'));P("datawindow",$(\'<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"/>\'));P("camera",$(\'<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"/>\'));P("gear",$(\'<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"/>\'));P("search",$(\'<circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3.5 3.5"/>\'));P("bell",$(\'<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"/>\'));P("market-open",me(\'<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"/>\'));P("market-pre",me(\'<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="m16 6-4 4-4-4"/><path d="M16 18a4 4 0 0 0-8 0"/>\'));P("market-post",me(\'<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 18-4-4-4 4"/><path d="M16 6a4 4 0 0 0-8 0"/>\'));P("market-closed",me(\'<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>\'));P("market-holiday",me(\'<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"/>\'));P("chevron-right",$(\'<path d="m6 3.5 4.5 4.5L6 12.5"/>\'));P("chevron-down",$(\'<path d="M3.5 6 8 10.5 12.5 6"/>\'));P("chevron-up",$(\'<path d="M3.5 10 8 5.5 12.5 10"/>\'));P("chevrons-right",$(\'<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"/>\'));P("chevrons-left",$(\'<path d="M12 3.5 7.5 8l4.5 4.5"/><path d="M7.5 3.5 3 8l4.5 4.5"/>\'));P("check",$(\'<path d="m2.8 8.4 3.4 3.4 7-7.6"/>\'));P("close",$(\'<path d="m3.8 3.8 8.4 8.4M12.2 3.8l-8.4 8.4"/>\'));P("eye",$(\'<path d="M1.5 8s2.5-4.2 6.5-4.2S14.5 8 14.5 8 12 12.2 8 12.2 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="1.8"/>\'));P("eye-off",$(\'<path d="M1.5 8s2.5-4.2 6.5-4.2S14.5 8 14.5 8 12 12.2 8 12.2 1.5 8 1.5 8z" opacity="0.45"/><path d="m3 13 10-10"/>\'));P("lock",$(\'<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"/>\'));P("unlock",$(\'<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"/>\'));P("trash",$(\'<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"/>\'));P("group",$(\'<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"/>\'));P("ungroup",$(\'<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"/>\'));P("clone",$(\'<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"/>\'));P("arrow-up",$(\'<path d="M8 13.2V3M4.2 6.8 8 3l3.8 3.8"/>\'));P("arrow-down",$(\'<path d="M8 2.8V13M4.2 9.2 8 13l3.8-3.8"/>\'));P("move-vertical",$(\'<path d="M8 2.5v11M5 5.5 8 2.5l3 3M5 10.5l3 3 3-3"/>\'));P("move",$(\'<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"/>\'));P("pen",$(\'<path d="m10.8 2.2 3 3-8 8-3.6.6.6-3.6z"/><path d="m9.2 3.8 3 3"/>\'));P("wave",$(\'<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"/>\'));P("folder-plus",$(\'<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"/>\'));P("folder-minus",$(\'<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"/>\'));P("collapse",$(\'<path d="M3 8h10"/>\'));P("expand",$(\'<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"/>\'));P("maximize",$(\'<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"/>\'));P("restore",$(\'<path d="M6.2 2.5v3.7H2.5M9.8 13.5V9.8h3.7M13.5 6.2H9.8V2.5M2.5 9.8h3.7v3.7"/>\'));P("star",$(\'<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"/>\'));P("star-filled",$(\'<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"\'));P("grip",$(\'<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"\'));P("kebab",$(\'<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"\'));P("reset",$(\'<rect x="6" y="6" width="4" height="4" rx="0.8"/><path d="M2.2 8a5.8 5.8 0 1 0 1.9-4.3L2.2 5.3"/><path d="M2.2 2.2v3.1h3.1"/>\'));P("pane-collapse",$(\'<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"/>\'));P("pane-expand",$(\'<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"/>\'));P("cursor",me(\'<path d="M5 3l6 16 2-6 6-2z"/>\',\'fill="currentColor" stroke="none"\'));P("ruler",me(\'<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"/>\'));P("magnet",me(\'<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"/>\'));P("eraser",me(\'<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"/>\'));P("pen-lock",me(\'<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"/>\'));P("brush",me(\'<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"/>\'));P("bucket",me(\'<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"/>\'));P("type",me(\'<path d="M5 6V4.5h14V6"/><path d="M12 4.5v15"/><path d="M9.5 19.5h5"/>\'));P("bold",me(\'<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"\'));P("italic",me(\'<path d="M15 5h-5M14 19H9M14.5 5 10 19"/>\',\'stroke-width="2.2"\'));P("price-delta",me(\'<path d="M12 4v16"/><path d="M8 8l4-4 4 4"/><path d="M8 16l4 4 4-4"/>\'));P("date-delta",me(\'<path d="M4 12h16"/><path d="M8 8l-4 4 4 4"/><path d="M16 8l4 4-4 4"/>\'));P("bring-front",me(\'<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"/>\'));P("send-back",me(\'<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"/>\'));P("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>\');P("bands",me(\'<path d="M3 6h18"/><path d="M3 18h18"/><path d="M3 12h18" stroke-dasharray="3 3"/>\'));P("dedekind",me(\'<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"/>\'));P("sonic",me(\'<circle cx="15" cy="12" r="4"/><circle cx="12" cy="12" r="2.5"/><path d="M8 5v14"/>\'));P("supersonic",me(\'<circle cx="16" cy="12" r="3.5"/><path d="M6 12 15 6M6 12 15 18"/>\'));var Yn=class{constructor(){Ws(this,"ordinals",new Map)}next(e,r,n){let i=`${r}:${n.trim().toLowerCase()}`,s=this.ordinals.get(i)??0;return this.ordinals.set(i,s+1),Ns({instanceId:e,kind:r,title:n,ordinal:s})}};function br(t){let e=t.data;if(e.length===0)return[];let r=e[e.length-1]?.value;return Array.isArray(r)?r:[]}function he(t){if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(t&&typeof t=="object"){let e=t;if(Array.isArray(e.data)){let r=typeof e.offset=="number"?e.offset:0,n=e.data[e.data.length-1-r];return typeof n=="number"&&Number.isFinite(n)?n:void 0}}}function Zn(t){let e=(O(t)??"").toLowerCase();return e==="bt"||e.includes("time")?"bar_time":"bar_index"}function ll(t){let e=(O(t)??"none").toLowerCase();return e==="b"||e==="both"?"both":e==="l"||e==="left"?"left":e==="r"||e==="right"?"right":"none"}function As(t){let e=(O(t)??"").toLowerCase();return e.includes("dot")?"dotted":e.includes("dash")?"dashed":"solid"}function cl(t){if(t===void 0)return{invisible:!1};if(t===null)return{invisible:!0};if(typeof t=="number")return{invisible:!0};if(typeof t=="string"){if(t==="")return{invisible:!1};let e=re(t);return e?{color:e,invisible:!1}:{invisible:!0}}return{invisible:!0}}function Is(t,e){let r=he(t.x1),n=he(t.y1),i=he(t.x2),s=he(t.y2);if(r===void 0||n===void 0||i===void 0||s===void 0)return null;let a=(O(t.style)??"").toLowerCase(),o=a==="style_arrow_left"||a==="style_arrow_both",l=a==="style_arrow_right"||a==="style_arrow_both",{color:c,invisible:u}=cl(t.color);return{id:e,paneId:"unrouted",xloc:Zn(t.xloc),x1:r,y1:n,x2:i,y2:s,extend:ll(t.extend),color:c,invisible:u,width:Math.max(1,he(t.width)??1),style:As(t.style),arrowLeft:o,arrowRight:l,overlay:t.force_overlay===!0}}function ul(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=Is(i,r.next(e,"line",String(i.id??n.length)));s&&n.push(s)}return n}function pl(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=i.line1,a=i.line2;if(!s||!a)continue;let o=r.next(e,"linefill",String(i.id??n.length)),l=Is(s,`${o}:a`),c=Is(a,`${o}:b`);!l||!c||n.push({id:o,paneId:"unrouted",line1:l,line2:c,color:re(i.color),overlay:i.force_overlay===!0})}return n}function hl(t){return t<=0?"auto":t<=9?"tiny":t<=12?"small":t<=17?"normal":t<=28?"large":"huge"}function wx(t){if(typeof t=="number"&&Number.isFinite(t))return hl(t);let e=(O(t)??"").toLowerCase();return e==="tiny"||e==="small"||e==="normal"||e==="large"||e==="huge"?e:"auto"}function Ts(t){let e=(O(t)??"").toLowerCase();return e==="left"||e==="right"?e:"center"}function dl(t){let e=(O(t)??"").toLowerCase();return e==="top"||e==="bottom"?e:"center"}function Ds(t){return(O(t)??"").toLowerCase().includes("mono")?"monospace":"default"}function fl(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=he(i.left),a=he(i.top),o=he(i.right),l=he(i.bottom);if(s===void 0||a===void 0||o===void 0||l===void 0)continue;let c=(O(i.text_formatting)??"").toLowerCase(),u=O(i.text);n.push({id:r.next(e,"box",String(i.id??n.length)),paneId:"unrouted",xloc:Zn(i.xloc),left:s,top:a,right:o,bottom:l,extend:ll(i.extend),bgColor:re(i.bgcolor),borderColor:re(i.border_color),borderWidth:Math.max(0,he(i.border_width)??1),borderStyle:As(i.border_style),text:u&&u.length>0?u:void 0,textColor:re(i.text_color),textSize:wx(i.text_size),hAlign:Ts(i.text_halign),vAlign:dl(i.text_valign),wrap:(O(i.text_wrap)??"").toLowerCase().includes("auto"),fontFamily:Ds(i.text_font_family),bold:c.includes("bold"),italic:c.includes("italic"),overlay:i.force_overlay===!0})}return n}var Ex=["label_up","label_down","label_left","label_right","label_center","label_lower_left","label_lower_right","label_upper_left","label_upper_right","circle","square","diamond","flag","arrowup","arrowdown","triangleup","triangledown","cross","xcross","text_outline","none"];function Sx(t){let e=(O(t)??"").toLowerCase().replace(/^style_/,"");return Ex.includes(e)?e:"label_down"}function Cx(t){let e=(O(t)??"").toLowerCase();return e==="ab"||e.includes("above")?"abovebar":e==="bl"||e.includes("below")?"belowbar":"price"}function ml(t){if(typeof t=="number"&&Number.isFinite(t))return hl(t);let e=(O(t)??"").toLowerCase();return e==="auto"||e==="tiny"||e==="small"||e==="large"||e==="huge"?e:"normal"}function yl(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=he(i.x),a=Cx(i.yloc),o=he(i.y);if(s===void 0||a==="price"&&o===void 0)continue;let l=O(i.text),c=O(i.tooltip),{color:u,invisible:h}=cl(i.color);n.push({id:r.next(e,"label",String(i.id??n.length)),paneId:"unrouted",xloc:Zn(i.xloc),x:s,y:o??0,yloc:a,text:l&&l.length>0?l:void 0,style:Sx(i.style),color:u,noFill:h,textColor:re(i.textcolor),size:ml(i.size),textAlign:Ts(i.textalign),tooltip:c&&c.length>0?c:void 0,fontFamily:Ds(i.text_font_family),overlay:i.force_overlay===!0})}return n}function gl(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let s=Array.isArray(i.points)?i.points:[],a=Zn(i.xloc),o=[];for(let c of s){let u=he(c.price),h=he(c.index),p=he(c.time),d=a==="bar_time"?p:h,f=a==="bar_time"?h:p,m,x;if(d!==void 0)m=d,x=a;else if(f!==void 0)m=f,x=a==="bar_time"?"bar_index":"bar_time";else continue;u!==void 0&&o.push({xloc:x,x:m,price:u})}if(o.length<2)continue;let l=(O(i.line_style)??"").toLowerCase();n.push({id:r.next(e,"polyline",String(i.id??n.length)),paneId:"unrouted",points:o,curved:i.curved===!0,closed:i.closed===!0,lineColor:re(i.line_color),fillColor:re(i.fill_color),lineWidth:Math.max(1,he(i.line_width)??1),lineStyle:As(i.line_style),arrowLeft:l==="style_arrow_left"||l==="style_arrow_both",arrowRight:l==="style_arrow_right"||l==="style_arrow_both",overlay:i.force_overlay===!0})}return n}var Nx=["top_left","top_center","top_right","middle_left","middle_center","middle_right","bottom_left","bottom_center","bottom_right"];function kx(t){let e=(O(t)??"").toLowerCase();return Nx.includes(e)?e:"top_right"}function Ix(t){if(!t||typeof t!="object")return null;let e=t,r=O(e.text),n=O(e.tooltip),i=(O(e.text_formatting)??"").toLowerCase();return{text:r&&r.length>0?r:void 0,textColor:re(e.text_color),bgColor:re(e.bgcolor),hAlign:Ts(e.text_halign),vAlign:dl(e.text_valign),textSize:ml(e.text_size),fontFamily:Ds(e.text_font_family),tooltip:n&&n.length>0?n:void 0,bold:i.includes("bold"),italic:i.includes("italic"),merged:e._merged===!0}}function Ax(t){if(!Array.isArray(t))return[];let e=[];for(let r of t){if(!r||typeof r!="object")continue;let n=r,i=he(n.startCol??n.start_column??n.startColumn),s=he(n.startRow??n.start_row),a=he(n.endCol??n.end_column??n.endColumn),o=he(n.endRow??n.end_row);i===void 0||s===void 0||a===void 0||o===void 0||e.push({startCol:Math.min(Math.round(i),Math.round(a)),startRow:Math.min(Math.round(s),Math.round(o)),endCol:Math.max(Math.round(i),Math.round(a)),endRow:Math.max(Math.round(s),Math.round(o))})}return e}function _l(t,e,r){let n=[];for(let i of br(t)){if(i._deleted===!0)continue;let a=(Array.isArray(i.cells)?i.cells:[]).map(o=>(Array.isArray(o)?o:[]).map(l=>Ix(l)));n.push({id:r.next(e,"table",String(i.id??n.length)),paneId:"unrouted",position:kx(i.position),columns:Math.max(0,Math.round(he(i.columns)??0)),rows:Math.max(0,Math.round(he(i.rows)??0)),bgColor:re(i.bgcolor),frameColor:re(i.frame_color),frameWidth:Math.max(0,he(i.frame_width)??0),borderColor:re(i.border_color),borderWidth:Math.max(0,he(i.border_width)??0),cells:a,merges:Ax(i.merges)})}return n}var xl=ks;function bl(t,e){let r=new Yn,n=[],i=[],s=[],a=[],o=[],l=[],c=[],u=[],h=[],p=[],d=[],f=[],m=new Map,x=[];for(let v of t.plots){let E=ol(v.style),A=v.title??v.key;switch(E){case"skip":break;case"barcolor":for(let C of v.data){let D=re(C.options?.color);D&&f.push({time:C.time,color:D})}break;case"fill":x.push(v);break;case"hline":{let C=Ox(v,A,e,r);C&&o.push(C);break}case"background":a.push(...Vx(v,A,e,r));break;case"drawing_line":l.push(...ul(v,e,r));break;case"drawing_box":c.push(...fl(v,e,r));break;case"label":u.push(...yl(v,e,r));break;case"drawing_polyline":h.push(...gl(v,e,r));break;case"linefill":p.push(...pl(v,e,r));break;case"table":d.push(..._l(v,e,r));break;case"markers":u.push(...jx(v,e,r));break;default:{let C=r.next(e,E,A);m.set(v.key,C),i.push(Dx(E,v,C,A))}}}for(let v of x){let E=v.plot1?m.get(v.plot1):void 0,A=v.plot2?m.get(v.plot2):void 0;if(!E||!A){n.push(`fill "${v.key}" references unknown plots (${v.plot1??"?"}/${v.plot2??"?"})`);continue}s.push({id:r.next(e,"fill",v.title??v.key),paneId:"unrouted",fromSeriesId:E,toSeriesId:A,...Lx(v)})}let b=t.trades?Tx(t.trades):[];return{model:{id:e,title:t.meta.title,overlay:t.meta.overlay,paneHint:t.meta.overlay?"price":"new",series:i,fills:s,backgrounds:a,priceLines:o,lines:l,boxes:c,labels:u,polylines:h,linefills:p,tables:d,barColors:f.length?f:void 0,trades:b.length?b:void 0,inputs:[],inputValues:{}},warnings:n}}function Tx(t){let e=new Map,r=n=>{let i=`${n.time}|${n.side}|${n.label??""}`,s=e.get(i);if(!s){e.set(i,n);return}s.qty=(s.qty??0)+(n.qty??0),n.kind==="entry"&&s.kind==="exit"&&(s.kind="entry",s.price=n.price,s.tradeId=n.tradeId)};for(let n of t){let i=n.size>0,s=Math.abs(n.size);r({time:n.entry_time,price:n.entry_price,side:i?"buy":"sell",kind:"entry",label:n.entry_comment??n.entry_id,qty:s,tradeId:n.id}),n.status==="closed"&&n.exit_time!=null&&n.exit_price!=null&&r({time:n.exit_time,price:n.exit_price,side:i?"sell":"buy",kind:"exit",label:n.exit_comment??n.exit_id,qty:s,tradeId:n.id})}return[...e.values()].sort((n,i)=>n.time-i.time)}function Dx(t,e,r,n){if(t==="candle"||t==="bar"){let c={id:r,title:n,paneId:"unrouted",kind:t,bars:Fx(e)},u=Mx(e);return u&&(c.barColors=u),c}let i=t,s=re(Bx(e)),a=O(e.options.display),o=a==="none"||a==="data_window"||!s,l=_e(e.options.linewidth)??(i==="line"||i==="step"?2:1);return{id:r,title:n,paneId:"unrouted",kind:i,points:Rx(Px(e),_e(e.options.offset)),style:{color:s??xl,width:l,lineStyle:wl(e.options.linestyle)??"solid"},visible:!o}}function Mx(t){let e=!1,r=t.data.map(n=>{let i=n.options??{},s=re(i.color),a=re(i.wickcolor),o=re(i.bordercolor);return!s&&!a&&!o?null:(e=!0,{color:s,wickColor:a,borderColor:o})});return e?r:void 0}function Px(t){return t.data.map(e=>{let r=typeof e.value=="number"&&Number.isFinite(e.value)?e.value:null,n=re(e.options?.color);return n?{time:e.time,value:r,color:n}:{time:e.time,value:r}})}function vl(t){let e=[];for(let r=1;r<t.length;r+=1){let n=t[r].time-t[r-1].time;n>0&&e.push(n)}return e.length===0?0:(e.sort((r,n)=>r-n),e[e.length>>1]??0)}function Rx(t,e){if(!e)return t;let r=e*vl(t);return r?t.map(n=>({...n,time:n.time+r})):t}function Fx(t){let e=[];for(let r of t.data){let n=r.value;!Array.isArray(n)||n.length<4||e.push({time:r.time,open:n[0]??0,high:n[1]??0,low:n[2]??0,close:n[3]??0})}return e}function Bx(t){for(let e of t.data)if(typeof e.options?.color=="string"&&e.options.color)return e.options.color;return O(t.options.color)}function Lx(t){if(t.options.gradient===!0||t.data.some(s=>s.options&&(typeof s.options.top_color=="string"||typeof s.options.bottom_color=="string")))return{gradient:t.data.map(a=>{let o=a.options??{},l=_e(o.top_value),c=_e(o.bottom_value),u=typeof o.top_color=="string"?o.top_color:void 0,h=typeof o.bottom_color=="string"?o.bottom_color:void 0;return l===void 0||c===void 0||!u&&!h?null:{topValue:l,bottomValue:c,topColor:u??"rgba(0,0,0,0)",bottomColor:h??"rgba(0,0,0,0)"}})};let r=t.data.map(s=>re(s.options?.color)??null),n=new Set(r.filter(s=>s!==null)),i=r.some(s=>s===null);return n.size===0?{color:re(t.options.color)}:n.size===1&&!i?{color:[...n][0]}:{colors:r}}function Ox(t,e,r,n){let i;for(let s of t.data)if(typeof s.value=="number"&&Number.isFinite(s.value)){i=s.value;break}return i===void 0?null:{id:n.next(r,"hline",e),paneId:"unrouted",price:i,color:re(t.options.color),lineStyle:wl(t.options.linestyle),title:e,width:_e(t.options.linewidth)}}function wl(t){let e=O(t)?.replace(/^(hline\\.style_|plot\\.linestyle_|linestyle_|style_)/,"");return e==="dashed"||e==="dotted"?e:void 0}function Vx(t,e,r,n){let i=[],s=t.data,a=s.length>1?(s[1]?.time??0)-(s[0]?.time??0):0,o=0;for(;o<s.length;){let l=s[o],c=re(l.options?.color);if(l.value===!0&&c){let u=l.time,h=l.time,p=o;for(;p+1<s.length;){let d=s[p+1];if(d.value===!0&&re(d.options?.color)===c)h=d.time,p+=1;else break}i.push({id:n.next(r,"background",e),paneId:"unrouted",from:u,to:h+a,color:c}),o=p+1}else o+=1}return i}function jx(t,e,r){let n=_e(t.options.offset),i=n?n*vl(t.data):0,s=[];for(let a of t.data){let o=a.value,l=typeof o=="number"&&Number.isFinite(o);if(o!==!0&&!l)continue;let c=a.options??t.options,u=O(c.text)??O(t.options.text);s.push({id:r.next(e,"label",`${t.key}#${s.length}`),paneId:"unrouted",xloc:"bar_time",x:a.time+i,y:l?o:0,yloc:$x(O(c.location)??O(t.options.location)),text:u&&u.trim().length>0?u:void 0,style:Wx(O(c.shape)??O(t.options.shape)),color:re(c.color)??re(t.options.color)??xl,textColor:re(c.textcolor)??re(t.options.textcolor),size:Ux(O(c.size)??O(t.options.size)),textAlign:"center",fontFamily:"default"})}return s}function $x(t){let e=(t??"").toLowerCase();return e==="absolute"?"price":e==="top"?"top":e==="bottom"?"bottom":e.includes("below")?"belowbar":"abovebar"}function Wx(t){switch((t??"").toLowerCase().replace(/^shape_/,"").replace(/_/g,"")){case"diamond":return"diamond";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"labelup":return"label_up";case"labeldown":return"label_down";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"square":return"square";case"cross":return"cross";case"xcross":return"xcross";case"flag":return"flag";default:return"circle"}}function Ux(t){let e=(t??"").toLowerCase();return e==="tiny"||e==="small"||e==="large"||e==="huge"||e==="normal"?e:"small"}function qx(t){switch(t){case"int":return"int";case"float":return"float";case"bool":return"bool";case"source":return"source";case"color":return"color";case"price":return"price";case"time":return"time";case"session":return"session";case"timeframe":return"timeframe";case"symbol":return"symbol";case"text_area":return"text_area";default:return"string"}}function zx(t){return t==="int"||t==="float"||t==="price"||t==="time"}var El={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#F23645",silver:"#B2B5BE",teal:"#089981",white:"#FFFFFF",yellow:"#FDD835"};function Kx(t){let e=t.trim().toLowerCase().replace(/^color\\./,"");return El[e]??t}function Hx(t){if(typeof t!="string")return;let e=/^color\\.([a-z]+)$/i.exec(t.trim());return e?El[e[1].toLowerCase()]:void 0}function Gx(t){return(t.type==="string"||t.type==null)&&Hx(t.defval)!==void 0}function Yx(t,e){if(e==="bool")return!!t;if(zx(e))return typeof t=="number"?t:Number(t)||0;let r=typeof t=="string"?t:t==null?"":String(t);return e==="color"?Kx(r):r}function Sl(t){return t.map((e,r)=>{let n=Gx(e)?"color":qx(e.type);return{key:e.varId??e.title??`input${r}`,title:e.title??e.varId??`Input ${r+1}`,type:n,defval:Yx(e.defval,n),min:e.minval,max:e.maxval,step:e.step,options:Array.isArray(e.options)?e.options.map(i=>String(i)):void 0,group:e.group,inline:e.inline,tooltip:e.tooltip}})}function Nl(t,e){let r=Sl(Qt.from(t).getInputsMeta()),n=/overlay\\s*[:=]\\s*true/.test(t),i=t.match(/(?:indicator|strategy)\\(\\s*["\']([^"\']+)["\']/)?.[1]??"Indicator",s=/chart\\.(left|right)_visible_bar(_time)?\\b/.test(t);return{language:"pine",inputs:r,meta:{title:i,overlay:n},reactsToViewport:s,token:{source:t,instanceId:e}}}function Ms(t,e,r){let n=JSON.stringify(r);return(t.lastKey!==n||!t.lastInd)&&(t.lastInd=new Qt(e,r),t.lastKey=n),t.lastInd}async function kl(t){let{ind:e,bars:r,market:n,visibleRange:i,prepared:s,instanceId:a,inputs:o,fetchSeries:l}=t,c=Ps(r),u={getMarketData:(f,m,x,b,w)=>Al(f,m,n)?Promise.resolve(c):Tl(l,f,m,x,b,w),getSymbolInfo:async f=>Ml(n,f)},h=new Wt(u,Rs(n),n.timeframe,c.length);await h.ready(),i&&h.setVisibleRange(i.left,i.right);let p=await h.run(e),d=typeof h.usesVisibleRange=="function"?h.usesVisibleRange():!1;return{model:Il(p,a,s,o,r[0]?.time),alerts:(p.alerts??[]).map(Pl),warnings:(p.warnings??[]).map(Rl),reactsToViewport:d,ctx:p}}function Il(t,e,r,n,i){let{model:s}=bl(Gn(t),e);return s.inputs=r.inputs,s.inputValues={...Xx(r.inputs),...n},i!=null&&(s.anchorTime=i),s}function Ps(t){return t.map(e=>({openTime:e.time,open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume??0}))}function Rs(t){return t.chartStyle==="heikinashi"?`${t.symbol};heikinashi`:t.symbol}function Al(t,e,r){return(t==null||t===Rs(r))&&(e==null||e===r.timeframe)}async function Tl(t,e,r,n,i,s){if(!t||!e||!r)return[];let a=await t(e,r,{from:i,to:s,limit:n});return Ps(a)}function Zx(t,e,r){let n="",i=!1;return{markDirty:()=>{i=!0},getMarketData:async(s,a,o,l,c)=>{if(!Al(s,a,e()))return Tl(r,s,a,o,l,c);let u=Ps(t());if(l==null)return u;let h=u.filter(f=>(f.openTime??0)>=l),p=h[h.length-1],d=p?`${h.length}|${p.openTime}|${p.close}|${p.high}|${p.low}|${p.volume}`:"";return!i&&d===n?[]:(i=!1,n=d,h)},getSymbolInfo:async s=>Ml(e(),s)}}function Dl(t){let e=t.bars(),r=Ms(t.cache,t.token.source,t.inputs),n=e[0]?.time,i=Math.max(1,e.length),s=Zx(t.bars,t.market,t.fetchSeries),a=new Wt(s,Rs(t.market()),t.market().timeframe,i);t.visibleRange&&a.setVisibleRange(t.visibleRange.left,t.visibleRange.right);let o=a.stream(r,{live:!0,interval:1e3,pageSize:i}),l=!1,c=null;return o.on("data",u=>{if(!l){c=u;try{t.onModel(Il(u,t.token.instanceId,t.prepared,t.inputs,n))}catch(h){t.onError?.(h instanceof Error?h:new Error(String(h)))}}}),o.on("alert",u=>t.onAlert?.(Pl(u))),o.on("warning",u=>t.onWarning?.(Rl(u))),o.on("error",u=>t.onError?.(u instanceof Error?u:new Error(String(u)))),{stop:()=>{l=!0,o.stop()},setVisibleRange:(u,h)=>{a.setVisibleRange(u,h),s.markDirty()},markDirty:()=>s.markDirty(),lastCtx:()=>c}}function Ml(t,e){let r=e&&e.split(";")[0];return r&&r!==t.symbol?Cl({symbol:r,timeframe:t.timeframe}):Cl(t)}function Cl(t){if(t.symbolInfo)return t.symbolInfo;let e=t.symbol,r=e.replace(/(USDT|USDC|USD|PERP|BUSD)$/i,"")||e;return{ticker:e,tickerid:e,main_tickerid:e,description:e,prefix:"",root:e,type:"crypto",basecurrency:r,currency:"USD",timezone:"UTC",session:"regular",mintick:.01,minmove:1,pointvalue:1,pricescale:100}}function Xx(t){let e={};for(let r of t)e[r.key]=r.defval;return e}function Pl(t){return{id:String(t.id??""),message:String(t.message??""),title:t.title,time:Number(t.time??0),barIndex:Number(t.bar_index??0),freq:t.freq}}function Rl(t){return{message:String(t.message??""),method:t.method,bar:Number(t.bar??0)}}var Qe=t=>_e(t)??0;function Fl(t){if(t==null||typeof t!="object")return;let e=t;return{position:Qe(e.position_size),avgPrice:Qe(e.position_avg_price),equity:Qe(e.equity),openPnl:Qe(e.openprofit),netPnl:Qe(e.netprofit),grossProfit:Qe(e.grossprofit),grossLoss:Qe(e.grossloss),wins:Qe(e.wintrades),losses:Qe(e.losstrades),even:Qe(e.eventrades),maxDrawdown:Qe(e.max_drawdown),maxRunup:Qe(e.max_runup),initialCapital:Qe(e.initial_capital)}}function Bl(t){if(t==null||typeof t!="object")return[];let e=t,r=[];for(let n of[...Array.isArray(e.closedtrades)?e.closedtrades:[],...Array.isArray(e.opentrades)?e.opentrades:[]]){let i=n??{},s=_e(i.entry_price),a=_e(i.entry_time),o=_e(i.size);if(s===void 0||a===void 0||o===void 0||o===0)continue;let l=_e(i.exit_price),c=_e(i.exit_time);r.push({id:O(i.id)??`trade_${r.length}`,side:o>0?"long":"short",qty:Math.abs(o),entry:{id:O(i.entry_id)??"",time:a,price:s,...O(i.entry_comment)!==void 0?{comment:O(i.entry_comment)}:{}},...l!==void 0&&c!==void 0?{exit:{id:O(i.exit_id)??"",time:c,price:l,...O(i.exit_comment)!==void 0?{comment:O(i.exit_comment)}:{}}}:{},open:i.status!=="closed"})}return r}function Ll(t){try{return structuredClone(t)}catch{return}}function Qx(t){let e=Array.isArray(t)?t:t!=null&&typeof t=="object"&&Array.isArray(t.data)?t.data:null;return Ll(e?e[e.length-1]:t)}function Jx(t){return t.replace(/^glb\\d+_/,"")}function Fs(t,e){if(t)for(let[r,n]of Object.entries(t)){if(r.startsWith("_"))continue;let i=Qx(n);i!==void 0&&(e[Jx(r)]=i)}}function Ol(t,e,r){let n=t??{},i=n.fullContext??n,s=p=>!r||r.includes(p),a=s("meta")||s("plots")?Gn(t):null,o={};if(a&&s("plots"))for(let p of a.plots)p.key.startsWith("__")||(o[p.key]=p.data.map(d=>({time:d.time,value:Ll(d.value)??null})));let l={};s("variables")&&(Fs(i.const,l),Fs(i.var,l),Fs(i.let,l));let c=s("strategy")?Fl(i.strategy):void 0,u=s("trades")&&i.strategy?Bl(i.strategy):void 0,h=typeof i.idx=="number"?i.idx:typeof i.length=="number"?i.length-1:-1;return{language:"pine",phase:e,barIndex:h,meta:a&&s("meta")?{title:a.meta.title,overlay:a.meta.overlay,precision:a.meta.precision,shorttitle:a.meta.shorttitle}:{title:"",overlay:!1},plots:o,variables:l,...c?{strategy:c}:{},...u&&u.length>0?{trades:u}:{},warnings:s("warnings")?(i.warnings??[]).map(p=>({message:String(p.message??""),method:typeof p.method=="string"?p.method:void 0,bar:Number(p.bar??0)})):[]}}var Vl=self,De=t=>Vl.postMessage(t),qt=new Map,Ls=new Map,eb=0,jl=(t,e,r)=>new Promise((n,i)=>{let s=++eb;Ls.set(s,{resolve:n,reject:i}),De({kind:"fetchSeries",reqId:s,symbol:t,timeframe:e,range:r})});function Xn(t){t.chain=t.chain.then(()=>rb(t))}function tb(t,e){let r=t.bars[t.bars.length-1];r&&e.time===r.time?t.bars[t.bars.length-1]=e:(!r||e.time>r.time)&&t.bars.push(e)}function Bs(t){t.stream?.stop(),t.stream=null,!(t.stopped||t.bars.length===0)&&(t.stream=Dl({token:t.prepared.token,cache:t.cache,prepared:t.prepared,inputs:t.inputs,bars:()=>t.bars,market:()=>t.market,fetchSeries:jl,visibleRange:t.visibleRange,onModel:e=>{t.stopped||De({kind:"model",sessionId:t.id,model:e})},onAlert:e=>De({kind:"alert",sessionId:t.id,alert:e}),onWarning:e=>De({kind:"warning",sessionId:t.id,warning:e}),onError:e=>De({kind:"error",sessionId:t.id,message:e.message})}))}async function rb(t){if(!t.stopped)try{let e=t.prepared.token,r=await kl({ind:Ms(t.cache,e.source,t.inputs),bars:t.bars,market:t.market,visibleRange:t.visibleRange,prepared:t.prepared,instanceId:e.instanceId,inputs:t.inputs,fetchSeries:jl});if(t.stopped)return;De({kind:"reactsToViewport",sessionId:t.id,value:r.reactsToViewport});for(let n of r.alerts)De({kind:"alert",sessionId:t.id,alert:n});for(let n of r.warnings)De({kind:"warning",sessionId:t.id,warning:n});t.lastCtx=r.ctx,De({kind:"model",sessionId:t.id,model:r.model}),De({kind:"done",sessionId:t.id})}catch(e){De({kind:"error",sessionId:t.id,message:e instanceof Error?e.message:String(e)})}}Vl.addEventListener("message",t=>{let e=t.data;switch(e.kind){case"prepare":try{De({kind:"prepared",reqId:e.reqId,prepared:Nl(e.source,e.instanceId)})}catch(r){De({kind:"prepared",reqId:e.reqId,error:r instanceof Error?r.message:String(r)})}return;case"execute":{let r={id:e.sessionId,mode:e.mode??"static",prepared:e.prepared,market:e.market,bars:e.bars,inputs:e.inputs,visibleRange:e.visibleRange,cache:{},stopped:!1,deferred:e.historyState==="backfill",chain:Promise.resolve(),stream:null,lastCtx:null};if(qt.set(r.id,r),r.mode==="live"){r.deferred||Bs(r);return}r.deferred?De({kind:"done",sessionId:r.id}):Xn(r);return}case"update":{let r=qt.get(e.sessionId);if(!r)return;if(r.inputs={...r.inputs,...e.inputs},r.mode==="live"){r.deferred||Bs(r);return}r.deferred?De({kind:"done",sessionId:r.id}):Xn(r);return}case"setVisibleRange":{let r=qt.get(e.sessionId);if(!r)return;if(r.visibleRange=e.range,r.mode==="live"){r.stream?.setVisibleRange(e.range.left,e.range.right);return}r.deferred?De({kind:"done",sessionId:r.id}):Xn(r);return}case"notifyBars":{let r=qt.get(e.sessionId);if(!r||r.mode==="live")return;r.bars=e.bars,r.deferred=!1,Xn(r);return}case"bars":{let r=qt.get(e.sessionId);if(!r||r.mode!=="live")return;if(e.restart){r.bars=e.bars,r.deferred=!1,Bs(r);return}for(let n of e.bars)tb(r,n);return}case"getContext":{let r=qt.get(e.sessionId),n=r?r.mode==="live"?r.stream?.lastCtx()??null:r.lastCtx:null,i=!r||r.stopped?"idle":r.mode==="live"?"streaming":"idle";De({kind:"contextResult",reqId:e.reqId,snapshot:n==null?null:Ol(n,i,e.select)});return}case"stop":{let r=qt.get(e.sessionId);r&&(r.stopped=!0,r.stream?.stop()),qt.delete(e.sessionId);return}case"fetchSeriesResult":{let r=Ls.get(e.reqId);if(!r)return;Ls.delete(e.reqId),e.error?r.reject(new Error(e.error)):r.resolve(e.bars??[]);return}}});})();\n';
|
|
1346
1346
|
|
|
1347
1347
|
// src/pinets-worker/PineWorkerEngine.ts
|
|
1348
1348
|
function spawnWorker(workerUrl) {
|