pinets 0.9.22 → 0.9.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +1,36 @@
1
- function La(t){return e=>new F(e.array.map(i=>Math.abs(i)),e.type,t)}function Ba(t){return e=>{let i=0,r=0;for(const n of e.array){const s=Number(n);isNaN(s)||(r++,i+=(s-i)/r)}return r===0?NaN:t.precision(i)}}function Fa(t){return(e,i)=>{const r=e.array;let n=0,s=r.length-1;for(;n<=s;){const a=Math.floor((n+s)/2),o=r[a];if(o===i)return a;o<i?n=a+1:s=a-1}return-1}}function Wa(t){return(e,i)=>{const r=e.array;let n=0,s=r.length;for(;n<s;){const a=Math.floor((n+s)/2);r[a]<i?n=a+1:s=a}return n<r.length&&r[n]===i?n:n-1}}function Ua(t){return(e,i)=>{const r=e.array;let n=0,s=r.length;for(;n<s;){const a=Math.floor((n+s)/2);r[a]<=i?n=a+1:s=a}return n>0&&r[n-1]===i?n-1:n}}function qa(t){return e=>{e.array.length=0}}function za(t){return(e,i)=>(e.array.push(...i.array),e)}function Ka(t){return e=>new F([...e.array],e.type,t)}function Ha(t){return(e,i,r=!0)=>{const n=e.array,s=i.array;if(n.length!==s.length)return NaN;let a=0,o=0,l=0;const c=[];for(let d=0;d<n.length;d++){const m=Number(n[d]),x=Number(s[d]);!isNaN(m)&&m!==null&&m!==void 0&&!isNaN(x)&&x!==null&&x!==void 0&&(a+=m,o+=x,l++,c.push(d))}if(l===0)return NaN;const u=a/l,p=o/l;let h=0;for(const d of c){const m=Number(n[d]),x=Number(s[d]);h+=(m-u)*(x-p)}const f=r?l:l-1;return f<=0?NaN:t.precision(h/f)}}function Ga(t){return e=>e.array.every(i=>!isNaN(i)&&i)}function Ya(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?L.int:L.float:t.every(e=>typeof e=="string")?L.string:t.every(e=>typeof e=="boolean")?L.bool:L.any}function Ge(t){return typeof t=="number"?Number.isInteger(t)?L.int:L.float:typeof t=="string"?L.string:typeof t=="boolean"?L.bool:L.any}function vi(t,e){if(typeof t=="number"&&isNaN(t)||e===L.any)return!0;switch(e){case L.int:return Number.isInteger(t)||isNaN(t);case L.float:return typeof t=="number";case L.string:return typeof t=="string";case L.bool:return typeof t=="boolean";case L.box:case L.label:case L.line:case L.linefill:case L.table:case L.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function Xa(t){return(e,i,r=0,n)=>{const s=e.array.length,a=n!==void 0?Math.min(n,s):s;for(let o=r;o<a;o++){if(!vi(i,e.type))throw new Error(`Cannot call 'array.fill' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array[o]=typeof i=="number"?t.precision(i):i}}}function Za(t){return e=>e.array.length>0?e.array[0]:t.NA}function Qa(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.get"),NaN):e.array[i])}function Ja(t){return(e,i)=>e.array.includes(i)}function eo(t){return(e,i)=>typeof i=="number"&&i!==i?e.array.findIndex(r=>typeof r=="number"&&r!==r):e.array.indexOf(i)}function to(t){return(e,i,r)=>{if(!vi(r,e.type))throw new Error(`Cannot call 'array.insert' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.insert");return}e.array.splice(i,0,r)}}function io(t){return(e,i=",")=>e.array.join(i)}function ro(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function no(t){return(e,i)=>e.array.lastIndexOf(i)}function so(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let n=r[0];for(let s=1;s<r.length;s++)r[s]>n&&(n=r[s]);return n??t.NA}return[...r].sort((n,s)=>s-n)[i]??t.NA}}function ao(t){return e=>{const i=e.array;if(i.length===0)return NaN;const r=new Array(i.length);for(let s=0;s<i.length;s++)r[s]=i[s];r.sort((s,a)=>s-a);const n=Math.floor(r.length/2);return r.length%2!==0?r[n]:(r[n-1]+r[n])/2}}function oo(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let n=r[0];for(let s=1;s<r.length;s++)r[s]<n&&(n=r[s]);return n??t.NA}return[...r].sort((n,s)=>n-s)[i]??t.NA}}function lo(t){return e=>{if(e.array.length===0)return NaN;const i=new Map;let r=0;for(const s of e.array){const a=(i.get(s)||0)+1;i.set(s,a),a>r&&(r=a)}const n=[];for(const[s,a]of i)a===r&&n.push(s);return n.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),n[0]}}function co(t){return(e,i)=>{const r=e.array,n=r.length;if(n===0)return NaN;const s=new Array(n);for(let c=0;c<n;c++){const u=Number(r[c]);if(isNaN(u)||u===null||u===void 0)return NaN;s[c]=u}s.sort((c,u)=>c-u),i<0&&(i=0),i>100&&(i=100);const a=i/100*n-.5;if(a<=0)return t.precision(s[0]);if(a>=n-1)return t.precision(s[n-1]);const o=Math.floor(a),l=a-o;return t.precision(s[o]*(1-l)+s[o+1]*l)}}function uo(t){return(e,i)=>{const r=e.array,n=r.length;if(n===0)return NaN;const s=new Array;for(let o=0;o<n;o++){const l=Number(r[o]);!isNaN(l)&&l!==null&&l!==void 0&&s.push(l)}if(s.length===0)return NaN;s.sort((o,l)=>o-l),i<0&&(i=0),i>100&&(i=100);const a=Math.ceil(i/100*n);return a<=0?s[0]:a>s.length?NaN:s[a-1]}}function ho(t){return(e,i)=>{if(e.array.length===0)return NaN;const r=Math.floor(i);if(r<0||r>=e.array.length)return NaN;const n=Number(e.array[r]);if(isNaN(n)||n===null||n===void 0)return NaN;let s=0;for(const o of e.array){const l=Number(o);!isNaN(l)&&l!==null&&l!==void 0&&l<n&&s++}const a=e.array.length-1;return a<=0?NaN:s/a*100}}function po(t){return e=>e.array.pop()}function fo(t){return(e,i)=>{if(!vi(i,e.type))throw new Error(`Cannot call 'array.push' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.push(typeof i=="number"?t.precision(i):i)}}function mo(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function yo(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.remove"),NaN):e.array.splice(i,1)[0])}function _o(t){return e=>{e.array.reverse()}}function go(t){return(e,i,r)=>{if(!vi(r,e.type))throw new Error(`Cannot call 'array.set' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>=e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.set");return}e.array[i]=typeof r=="number"?t.precision(r):r}}function xo(t){return e=>e.array.shift()}function bo(t){return e=>e.array.length}function vo(t){return(e,i,r)=>{const n=r!==void 0?r:void 0;return new F(e.array.slice(i,n),e.type,t)}}function wo(t){return e=>e.array.some(i=>!isNaN(i)&&i)}var ei=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(ei||{}),es=(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))(es||{}),ts=(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))(ts||{}),is=(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))(is||{}),rs=(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))(rs||{}),ns=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(ns||{}),ss=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(ss||{}),as=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(as||{}),So=(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))(So||{}),os=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(os||{}),ls=(t=>(t.bar_index="bi",t.bar_time="bt",t))(ls||{}),cs=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(cs||{}),us=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(us||{}),hs=(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))(hs||{}),ps=(t=>(t.family_default="default",t.family_monospace="monospace",t))(ps||{}),fs=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(fs||{}),ds=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(ds||{}),ms=(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))(ms||{}),ys=(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))(ys||{}),_s=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(_s||{}),gs=(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))(gs||{}),xs=(t=>(t.left="left",t.none="none",t.right="right",t))(xs||{}),bs=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(bs||{});const Eo={order:ei,currency:es,dayofweek:ts,display:is,shape:rs,location:ns,size:ss,format:as,barmerge:os,xloc:ls,yloc:cs,extend:us,text:hs,font:ps,adjustment:fs,backadjustment:ds,earnings:ms,dividends:ys,splits:_s,position:gs,scale:xs,settlement_as_close:bs};function No(t){return(e,i=ei.ascending)=>{e.array.sort((r,n)=>{let s=isNaN(r)?1/0:r,a=isNaN(n)?1/0:n;return i===ei.ascending?s-a:a-s})}}function Co(t){return(e,i=ei.ascending)=>{const r=e.array.map((n,s)=>s);return r.sort((n,s)=>{const a=isNaN(e.array[n])?1/0:e.array[n],o=isNaN(e.array[s])?1/0:e.array[s];return i===ei.ascending?a-o:o-a}),new F(r,L.int,t)}}function Io(t){return e=>{const i=t.array.avg(e),r=t.array.stdev(e);return isNaN(r)?new F(e.array.map(()=>NaN),L.int,t):r===0?new F(e.array.map(()=>1),L.int,t):new F(e.array.map(n=>(n-i)/r),L.int,t)}}function ko(t){return(e,i=!0)=>{const r=e.array,n=r.length;if(n===0)return NaN;let s=0,a=0,o=0;for(let u=0;u<n;u++){const p=Number(r[u]);!isNaN(p)&&p!==null&&p!==void 0&&(s+=p,a+=p*p,o++)}if(o===0)return NaN;const l=s/o;let c=a/o-l*l;return c<0?NaN:(!i&&o>1&&(c=c*o/(o-1)),!i&&o===1?0:t.precision(Math.sqrt(c)))}}function To(t){return e=>t.precision(e.array.reduce((i,r)=>{const n=Number(r);return isNaN(n)?i:i+n},0))}function Ao(t){return(e,i)=>{if(!vi(i,e.type))throw new Error(`Cannot call 'array.unshift' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.unshift(typeof i=="number"?t.precision(i):i)}}function Po(t){return(e,i=!0)=>{let r=0,n=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(r+=c,n++)}if(n===0)return NaN;const s=r/n;let a=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(a+=(c-s)*(c-s))}const o=i?n:n-1;return o<=0?NaN:t.precision(a/o)}}var Do=Object.defineProperty,Mo=(t,e,i)=>e in t?Do(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,W=(t,e,i)=>Mo(t,typeof e!="symbol"?e+"":e,i),L=(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))(L||{});class F{constructor(e,i,r){this.array=e,this.type=i,this.context=r,W(this,"_abs"),W(this,"_avg"),W(this,"_binary_search"),W(this,"_binary_search_leftmost"),W(this,"_binary_search_rightmost"),W(this,"_clear"),W(this,"_concat"),W(this,"_copy"),W(this,"_covariance"),W(this,"_every"),W(this,"_fill"),W(this,"_first"),W(this,"_get"),W(this,"_includes"),W(this,"_indexof"),W(this,"_insert"),W(this,"_join"),W(this,"_last"),W(this,"_lastindexof"),W(this,"_max"),W(this,"_median"),W(this,"_min"),W(this,"_mode"),W(this,"_percentile_linear_interpolation"),W(this,"_percentile_nearest_rank"),W(this,"_percentrank"),W(this,"_pop"),W(this,"_push"),W(this,"_range"),W(this,"_remove"),W(this,"_reverse"),W(this,"_set"),W(this,"_shift"),W(this,"_size"),W(this,"_slice"),W(this,"_some"),W(this,"_sort"),W(this,"_sort_indices"),W(this,"_standardize"),W(this,"_stdev"),W(this,"_sum"),W(this,"_unshift"),W(this,"_variance"),this._abs=La(this.context),this._avg=Ba(this.context),this._binary_search=Fa(this.context),this._binary_search_leftmost=Wa(this.context),this._binary_search_rightmost=Ua(this.context),this._clear=qa(this.context),this._concat=za(this.context),this._copy=Ka(this.context),this._covariance=Ha(this.context),this._every=Ga(this.context),this._fill=Xa(this.context),this._first=Za(this.context),this._get=Qa(this.context),this._includes=Ja(this.context),this._indexof=eo(this.context),this._insert=to(this.context),this._join=io(this.context),this._last=ro(this.context),this._lastindexof=no(this.context),this._max=so(this.context),this._median=ao(this.context),this._min=oo(this.context),this._mode=lo(this.context),this._percentile_linear_interpolation=co(this.context),this._percentile_nearest_rank=uo(this.context),this._percentrank=ho(this.context),this._pop=po(this.context),this._push=fo(this.context),this._range=mo(this.context),this._remove=yo(this.context),this._reverse=_o(this.context),this._set=go(this.context),this._shift=xo(this.context),this._size=bo(this.context),this._slice=vo(this.context),this._some=wo(this.context),this._sort=No(this.context),this._sort_indices=Co(this.context),this._standardize=Io(this.context),this._stdev=ko(this.context),this._sum=To(this.context),this._unshift=Ao(this.context),this._variance=Po(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 Ro(t){return(...e)=>new F([...e],Ya(e),t)}function Oo(t){return(e,i)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;if(i===void 0){const n=r?Array(r).fill(0):[];return new F(n,L.any,t)}return new F(Array(r).fill(t.precision(i||0)),Ge(i||0),t)}}function $o(t){return(e=0,i=!1)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(i),L.bool,t)}}function Vo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(i),L.box,t)}}function jo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(i),L.color,t)}}function Lo(t){return(e=0,i=NaN)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(t.precision(i)),L.float,t)}}function Bo(t){return(e=0,i=0)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(t.precision(i)),L.int,t)}}function Fo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(i),L.label,t)}}function Wo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(i),L.line,t)}}function Uo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(i),L.linefill,t)}}function qo(t){return(e=0,i="")=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(i),L.string,t)}}function zo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new F(Array(r).fill(i),L.table,t)}}class y{constructor(e,i=0){this.data=e,this.offset=i}get(e){const i=this.data.length-1-(this.offset+e);return i<0||i>=this.data.length?NaN:this.data[i]}set(e,i){const r=this.data.length-1-(this.offset+e);r>=0&&r<this.data.length&&(this.data[r]=i)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof y?e:Array.isArray(e)?new y(e):e!=null&&typeof e=="object"&&"__value"in e&&e.__value instanceof y?e.__value:new y([e])}}function Ko(t){return(e,i=0)=>y.from(e).get(i)}class Ho{constructor(e){this.context=e,this.abs=(i,...r)=>i.abs(...r),this.avg=(i,...r)=>i.avg(...r),this.binary_search=(i,...r)=>i.binary_search(...r),this.binary_search_leftmost=(i,...r)=>i.binary_search_leftmost(...r),this.binary_search_rightmost=(i,...r)=>i.binary_search_rightmost(...r),this.clear=(i,...r)=>i.clear(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.covariance=(i,...r)=>i.covariance(...r),this.every=(i,...r)=>i.every(...r),this.fill=(i,...r)=>i.fill(...r),this.first=(i,...r)=>i.first(...r),this.from=Ro(e),this.get=(i,...r)=>i.get(...r),this.includes=(i,...r)=>i.includes(...r),this.indexof=(i,...r)=>i.indexof(...r),this.insert=(i,...r)=>i.insert(...r),this.join=(i,...r)=>i.join(...r),this.last=(i,...r)=>i.last(...r),this.lastindexof=(i,...r)=>i.lastindexof(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.new=Oo(e),this.new_bool=$o(e),this.new_box=Vo(e),this.new_color=jo(e),this.new_float=Lo(e),this.new_int=Bo(e),this.new_label=Fo(e),this.new_line=Wo(e),this.new_linefill=Uo(e),this.new_string=qo(e),this.new_table=zo(e),this.param=Ko(),this.percentile_linear_interpolation=(i,...r)=>i.percentile_linear_interpolation(...r),this.percentile_nearest_rank=(i,...r)=>i.percentile_nearest_rank(...r),this.percentrank=(i,...r)=>i.percentrank(...r),this.pop=(i,...r)=>i.pop(...r),this.push=(i,...r)=>i.push(...r),this.range=(i,...r)=>i.range(...r),this.remove=(i,...r)=>i.remove(...r),this.reverse=(i,...r)=>i.reverse(...r),this.set=(i,...r)=>i.set(...r),this.shift=(i,...r)=>i.shift(...r),this.size=(i,...r)=>i.size(...r),this.slice=(i,...r)=>i.slice(...r),this.some=(i,...r)=>i.some(...r),this.sort=(i,...r)=>i.sort(...r),this.sort_indices=(i,...r)=>i.sort_indices(...r),this.standardize=(i,...r)=>i.standardize(...r),this.stdev=(i,...r)=>i.stdev(...r),this.sum=(i,...r)=>i.sum(...r),this.unshift=(i,...r)=>i.unshift(...r),this.variance=(i,...r)=>i.variance(...r)}}function Go(t){return e=>{e.map.clear()}}function Yo(t){return(e,i)=>e.map.has(i)}function Xo(t){return e=>{const i=new vs(t);return i.map=new Map(e.map),i}}function Zo(t){return(e,i)=>{const r=e.map.get(i);return r===void 0?NaN:r}}function Qo(t){return e=>{const i=Array.from(e.map.keys()),r=Ge(i[0]);return new F(i,r,t)}}function Jo(t){return(e,i,r)=>{const n=e.map.get(i);return e.map.set(i,r),n===void 0?NaN:n}}function el(t){return(e,i)=>{for(const[r,n]of i.map)e.map.set(r,n)}}function tl(t){return(e,i)=>{const r=e.map.get(i);return e.map.delete(i)?r:NaN}}function il(t){return e=>e.map.size}function rl(t){return e=>{const i=Array.from(e.map.values()),r=Ge(i[0]);return new F(i,r,t)}}var nl=Object.defineProperty,sl=(t,e,i)=>e in t?nl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ze=(t,e,i)=>sl(t,typeof e!="symbol"?e+"":e,i);class vs{constructor(e){this.context=e,Ze(this,"map"),Ze(this,"_clear"),Ze(this,"_contains"),Ze(this,"_copy"),Ze(this,"_get"),Ze(this,"_keys"),Ze(this,"_put"),Ze(this,"_put_all"),Ze(this,"_remove"),Ze(this,"_size"),Ze(this,"_values"),this.map=new Map,this._clear=Go(this.context),this._contains=Yo(this.context),this._copy=Xo(this.context),this._get=Zo(this.context),this._keys=Qo(this.context),this._put=Jo(this.context),this._put_all=el(this.context),this._remove=tl(this.context),this._size=il(this.context),this._values=rl(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 al(t){return()=>new vs(t)}function ol(t){return(e,i=0)=>y.from(e).get(i)}class ll{constructor(e){this.context=e,this.clear=(i,...r)=>i.clear(...r),this.contains=(i,...r)=>i.contains(...r),this.copy=(i,...r)=>i.copy(...r),this.get=(i,...r)=>i.get(...r),this.keys=(i,...r)=>i.keys(...r),this.new=al(e),this.param=ol(),this.put=(i,...r)=>i.put(...r),this.put_all=(i,...r)=>i.put_all(...r),this.remove=(i,...r)=>i.remove(...r),this.size=(i,...r)=>i.size(...r),this.values=(i,...r)=>i.values(...r)}}function cl(t){return(e,i,r)=>{const n=e.matrix.length;let s=[];if(r&&(r instanceof F?s=r.array:Array.isArray(r)?s=r:s=[r]),n===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}const a=e.matrix[0].length,o=i!==void 0?i:a;for(let l=0;l<n;l++){let c=l<s.length?s[l]:NaN;c instanceof y&&(c=c.get(0)),e.matrix[l].splice(o,0,c)}}}function ul(t){return(e,i,r)=>{const n=e.matrix.length;let s=[];if(r)if(r instanceof F)s=r.array;else if(Array.isArray(r))s=r;else if(r instanceof y){const c=r.get(0);Array.isArray(c)?s=c:s=[c]}else s=[r];const a=n>0?e.matrix[0].length:s.length,o=i!==void 0?i:n,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 hl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;if(r===0)return NaN;let n=0,s=0;for(let a=0;a<i;a++)for(let o=0;o<r;o++){const l=e.matrix[a][o];isNaN(l)||(n+=l,s++)}return s===0?NaN:n/s}}function pl(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(i<0||i>=n){t.warn(`Column index ${i} is out of bounds, matrix has ${n} columns.`,"matrix.col");const o=r>0?Ge(e.matrix[0][0]):"float";return new F([],o,t)}const s=[];for(let o=0;o<r;o++)s.push(e.matrix[o][i]);const a=Ge(s[0]);return new F(s,a,t)}}function fl(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function dl(t){return(e,i)=>{const r=e.matrix.length,n=i.matrix.length;if(r===0){for(let o=0;o<n;o++)e.matrix.push([...i.matrix[o]]);return}const s=e.matrix[0].length,a=n>0?i.matrix[0].length:0;if(s!==a&&n>0){console.error(`matrix.concat: Column count mismatch ${s} vs ${a}`);return}for(let o=0;o<n;o++)e.matrix.push([...i.matrix[o]])}}function ml(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0,n=new Z(i,r,NaN,t);return n.matrix=e.matrix.map(s=>[...s]),n}}function yl(t){const 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];const i=t.map(n=>[...n]);let r=1;for(let n=0;n<e;n++){let s=n;for(;s<e&&i[s][n]===0;)s++;if(s===e)return 0;s!==n&&([i[n],i[s]]=[i[s],i[n]],r*=-1),r*=i[n][n];for(let a=n+1;a<e;a++){const o=i[a][n]/i[n][n];for(let l=n;l<e;l++)i[a][l]-=o*i[n][l]}}return r}function _l(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;return i!==r?NaN:yl(e.matrix)}}function gl(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new Z(0,0,NaN,t);const n=e.matrix[0].length,s=new Z(r,n,NaN,t);if(i instanceof Z)for(let a=0;a<r;a++)for(let o=0;o<n;o++){const l=e.matrix[a][o],c=i.matrix[a]&&i.matrix[a][o]!==void 0?i.matrix[a][o]:NaN;s.matrix[a][o]=l-c}else{const a=i;for(let o=0;o<r;o++)for(let l=0;l<n;l++)s.matrix[o][l]=e.matrix[o][l]-a}return s}}function xl(t){const e=t.length;if(e!==2)return Array(e).fill(NaN);const i=t[0][0],r=t[0][1],n=t[1][0],s=t[1][1],a=i+s,o=i*s-r*n,l=a*a-4*o;if(l<0)return[NaN,NaN];const c=(a+Math.sqrt(l))/2,u=(a-Math.sqrt(l))/2;return[c,u]}function bl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r){const a=Ge(e.matrix[0][0]);return new F([],a,t)}const n=xl(e.matrix),s=Ge(n[0]);return new F(n,s,t)}}function vl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new Z(0,0,NaN,t);const n=new Z(i,r,0,t);for(let s=0;s<i;s++)n.matrix[s][s]=1;return n}}function wl(t){return e=>{const i=e.matrix.length;return i===0?0:i*e.matrix[0].length}}function Sl(t){return(e,i,r,n,s,a)=>{const o=e.matrix.length;if(o===0)return;const l=e.matrix[0].length,c=r!==void 0?r:0,u=n!==void 0?n:o,p=s!==void 0?s:0,h=a!==void 0?a:l;for(let f=c;f<u&&!(f>=o);f++)for(let d=p;d<h&&!(d>=l);d++)e.matrix[f][d]=i}}function El(t){return(e,i,r)=>{const n=e.matrix.length,s=n>0?e.matrix[0].length:0;if(i<0||i>=n)return t.warn(`Row index ${i} is out of bounds, matrix has ${n} rows.`,"matrix.get"),NaN;if(r<0||r>=s)return t.warn(`Column index ${r} is out of bounds, matrix has ${s} columns.`,"matrix.get"),NaN;const a=e.matrix[i][r];return a===void 0?NaN:a}}function Mi(t){const e=t.length;if(e===0)return[];const i=new Array(e);for(let n=0;n<e;n++){i[n]=new Array(2*e);for(let s=0;s<e;s++)i[n][s]=t[n][s];for(let s=0;s<e;s++)i[n][e+s]=n===s?1:0}for(let n=0;n<e;n++){let s=Math.abs(i[n][n]),a=n;for(let l=n+1;l<e;l++){const c=Math.abs(i[l][n]);c>s&&(s=c,a=l)}if(s<1e-14)return t.map(l=>l.map(()=>NaN));if(a!==n){const l=i[n];i[n]=i[a],i[a]=l}const o=i[n][n];for(let l=n;l<2*e;l++)i[n][l]/=o;for(let l=0;l<e;l++){if(l===n)continue;const c=i[l][n];if(c!==0)for(let u=n;u<2*e;u++)i[l][u]-=c*i[n][u]}}const r=new Array(e);for(let n=0;n<e;n++){r[n]=new Array(e);for(let s=0;s<e;s++)r[n][s]=i[n][e+s]}return r}function Nl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new Z(i,r,NaN,t);const n=Mi(e.matrix),s=new Z(i,r,NaN,t);return s.matrix=n,s}}function Cl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let s=0;s<r;s++)if(n+s!==i-1&&e.matrix[n][s]!==0)return!1;return!0}}function Il(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let s=0;s<r;s++)if(e.matrix[s][n]!==-e.matrix[n][s])return!1;return!0}}function kl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let n=0;n<i;n++)for(let s=0;s<r;s++){const a=e.matrix[n][s];if(a!==0&&a!==1)return!1}return!0}}function Tl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let s=0;s<r;s++)if(n!==s&&e.matrix[n][s]!==0)return!1;return!0}}function Al(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let s=0;s<r;s++)if(n===s){if(e.matrix[n][s]!==1)return!1}else if(e.matrix[n][s]!==0)return!1;return!0}}function Pl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;return i===r}}function Dl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let n=0;n<i;n++){let s=0;for(let a=0;a<r;a++){const o=e.matrix[n][a];if(o<0)return!1;s+=o}if(Math.abs(s-1)>1e-10)return!1}return!0}}function Ml(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let s=0;s<n;s++)if(e.matrix[n][s]!==e.matrix[s][n])return!1;return!0}}function Rl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;let n=!0,s=!0;for(let a=0;a<i;a++)for(let o=0;o<r;o++)a>o&&e.matrix[a][o]!==0&&(n=!1),a<o&&e.matrix[a][o]!==0&&(s=!1);return n||s}}function Ol(t){return e=>{const i=e.matrix.length;if(i===0)return!0;const r=e.matrix[0].length;for(let n=0;n<i;n++)for(let s=0;s<r;s++)if(e.matrix[n][s]!==0)return!1;return!0}}function $l(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0,s=i.matrix.length,a=s>0?i.matrix[0].length:0,o=r*s,l=n*a,c=new Z(o,l,NaN,t);for(let u=0;u<r;u++)for(let p=0;p<n;p++){const h=e.matrix[u][p];for(let f=0;f<s;f++)for(let d=0;d<a;d++){const m=i.matrix[f][d];c.matrix[u*s+f][p*a+d]=h*m}}return c}}function Vl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let n=-1/0,s=!1;for(let a=0;a<i;a++)for(let o=0;o<r;o++){const l=e.matrix[a][o];isNaN(l)||(l>n&&(n=l),s=!0)}return s?n:NaN}}function jl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,n=[];for(let a=0;a<i;a++)for(let o=0;o<r;o++){const l=e.matrix[a][o];isNaN(l)||n.push(l)}if(n.length===0)return NaN;n.sort((a,o)=>a-o);const s=Math.floor(n.length/2);return n.length%2!==0?n[s]:(n[s-1]+n[s])/2}}function Ll(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let n=1/0,s=!1;for(let a=0;a<i;a++)for(let o=0;o<r;o++){const l=e.matrix[a][o];isNaN(l)||(l<n&&(n=l),s=!0)}return s?n:NaN}}function Bl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,n=new Map;let s=0,a=NaN;for(let o=0;o<i;o++)for(let l=0;l<r;l++){const c=e.matrix[o][l];if(!isNaN(c)){const u=(n.get(c)||0)+1;n.set(c,u),u>s?(s=u,a=c):u===s&&c<a&&(a=c)}}return a}}function Fl(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(i instanceof Z){const s=i.matrix.length,a=s>0?i.matrix[0].length:0;if(n!==s)return new Z(0,0,NaN,t);const o=new Z(r,a,0,t);for(let l=0;l<r;l++)for(let c=0;c<a;c++){let u=0;for(let p=0;p<n;p++)u+=e.matrix[l][p]*i.matrix[p][c];o.matrix[l][c]=u}return o}else if(i instanceof F||Array.isArray(i.array||i)){const s=i.array||i;if(n!==s.length)return new F([],"float",t);const a=[];for(let o=0;o<r;o++){let l=0;for(let c=0;c<n;c++)l+=e.matrix[o][c]*s[c];a.push(l)}return new F(a,"float",t)}else{const s=i,a=new Z(r,n,NaN,t);for(let o=0;o<r;o++)for(let l=0;l<n;l++)a.matrix[o][l]=e.matrix[o][l]*s;return a}}}function Wl(t){return e=>{const i=e.matrix.length;if(i===0)return new Z(0,0,NaN,t);const r=e.matrix[0].length;if(i===r){const u=Mi(e.matrix),p=new Z(i,r,NaN,t);return p.matrix=u,p}const n=u=>{const p=u.length,h=u[0].length,f=new Array(h);for(let d=0;d<h;d++){f[d]=new Array(p);for(let m=0;m<p;m++)f[d][m]=u[m][d]}return f},s=(u,p)=>{const h=u.length,f=u[0].length,d=p[0].length,m=new Array(h);for(let x=0;x<h;x++){m[x]=new Array(d).fill(0);for(let b=0;b<f;b++){const v=u[x][b];if(v!==0)for(let w=0;w<d;w++)m[x][w]+=v*p[b][w]}}return m},a=e.matrix,o=n(a);let l;if(i>r){const u=s(o,a),p=Mi(u);l=s(p,o)}else{const u=s(a,o),p=Mi(u);l=s(o,p)}const c=new Z(r,i,NaN,t);return c.matrix=l,c}}function Ul(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n)return new Z(0,0,NaN,t);let s=new Z(r,n,0,t);for(let l=0;l<r;l++)s.matrix[l][l]=1;let a=new Z(r,n,NaN,t);for(let l=0;l<r;l++)a.matrix[l]=[...e.matrix[l]];let o=Math.floor(i);if(o<0)return new Z(r,n,NaN,t);for(;o>0;){if(o%2===1){const c=new Z(r,n,0,t);for(let u=0;u<r;u++)for(let p=0;p<n;p++){let h=0;for(let f=0;f<r;f++)h+=s.matrix[u][f]*a.matrix[f][p];c.matrix[u][p]=h}s=c}const l=new Z(r,n,0,t);for(let c=0;c<r;c++)for(let u=0;u<n;u++){let p=0;for(let h=0;h<r;h++)p+=a.matrix[c][h]*a.matrix[h][u];l.matrix[c][u]=p}a=l,o=Math.floor(o/2)}return s}}function ql(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,n=e.matrix.map(a=>[...a]);let s=0;for(let a=0;a<r&&s<i;a++){let o=s;for(;o<i&&Math.abs(n[o][a])<1e-10;)o++;if(o<i){[n[s],n[o]]=[n[o],n[s]];const l=n[s][a];for(let c=a;c<r;c++)n[s][c]/=l;for(let c=0;c<i;c++)if(c!==s){const u=n[c][a];for(let p=a;p<r;p++)n[c][p]-=u*n[s][p]}s++}}return s}}function zl(t){return(e,i)=>{const r=e.matrix.length;if(r===0){const a=Ge(e.matrix[0][0]);return new F([],a,t)}const n=[];for(let a=0;a<r;a++){const o=e.matrix[a].splice(i,1);n.push(o[0])}const s=Ge(n[0]);return new F(n,s,t)}}function Kl(t){return(e,i)=>{const r=e.matrix.splice(i,1),n=Ge(r[0][0]);return new F(r[0]||[],n,t)}}function Hl(t){return(e,i,r)=>{const n=e.matrix.length,s=n>0?e.matrix[0].length:0,a=i*r,o=[];for(let u=0;u<n;u++)for(let p=0;p<s;p++)o.push(e.matrix[u][p]);for(;o.length<a;)o.push(NaN);o.length>a&&(o.length=a);const l=[];let c=0;for(let u=0;u<i;u++){const p=[];for(let h=0;h<r;h++)p.push(o[c++]);l.push(p)}e.matrix=l}}function Gl(t){return e=>{e.matrix.reverse();for(const i of e.matrix)i.reverse()}}function Yl(t){return(e,i)=>{const r=e.matrix.length;if(i<0||i>=r){t.warn(`Row index ${i} is out of bounds, matrix has ${r} rows.`,"matrix.row");const s=r>0?Ge(e.matrix[0][0]):"float";return new F([],s,t)}const n=Ge(e.matrix[i][0]);return new F([...e.matrix[i]],n,t)}}function Xl(t){return e=>e.matrix.length}function Zl(t){return(e,i,r,n)=>{const s=e.matrix.length,a=s>0?e.matrix[0].length:0;if(i<0||i>=s){t.warn(`Row index ${i} is out of bounds, matrix has ${s} rows.`,"matrix.set");return}if(r<0||r>=a){t.warn(`Column index ${r} is out of bounds, matrix has ${a} columns.`,"matrix.set");return}e.matrix[i][r]=n}}function Ql(t){return(e,i=0,r="asc")=>{e.matrix.length!==0&&e.matrix.sort((n,s)=>{const a=n[i],o=s[i];return a<o?r==="asc"?-1:1:a>o?r==="asc"?1:-1:0})}}function Jl(t){return(e,i,r,n,s)=>{const a=r-i,o=s-n,l=new Z(a,o,NaN,t);for(let c=0;c<a;c++){const u=i+c;if(u>=e.matrix.length)break;for(let p=0;p<o;p++){const h=n+p;if(h>=e.matrix[u].length)break;l.matrix[c][p]=e.matrix[u][h]}}return l}}function ec(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new Z(0,0,NaN,t);const n=e.matrix[0].length,s=new Z(r,n,NaN,t);if(i instanceof Z)for(let a=0;a<r;a++)for(let o=0;o<n;o++){const l=e.matrix[a][o],c=i.matrix[a]&&i.matrix[a][o]!==void 0?i.matrix[a][o]:NaN;s.matrix[a][o]=l+c}else{const a=i;for(let o=0;o<r;o++)for(let l=0;l<n;l++)s.matrix[o][l]=e.matrix[o][l]+a}return s}}function tc(t){return(e,i,r)=>{const n=e.matrix.length;for(let s=0;s<n;s++){const a=e.matrix[s][i];e.matrix[s][i]=e.matrix[s][r],e.matrix[s][r]=a}}}function ic(t){return(e,i,r)=>{const n=e.matrix[i];e.matrix[i]=e.matrix[r],e.matrix[r]=n}}function rc(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,n=Math.min(i,r);let s=0;for(let a=0;a<n;a++)s+=e.matrix[a][a];return s}}function nc(t){return e=>{const i=e.matrix.length;if(i===0)return new Z(0,0,NaN,t);const r=e.matrix[0].length,n=new Z(r,i,NaN,t);for(let s=0;s<i;s++)for(let a=0;a<r;a++)n.matrix[a][s]=e.matrix[s][a];return n}}var sc=Object.defineProperty,ac=(t,e,i)=>e in t?sc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,j=(t,e,i)=>ac(t,typeof e!="symbol"?e+"":e,i);class Z{constructor(e=0,i=0,r=NaN,n){if(this.context=n,j(this,"matrix"),j(this,"_add_col"),j(this,"_add_row"),j(this,"_avg"),j(this,"_col"),j(this,"_columns"),j(this,"_concat"),j(this,"_copy"),j(this,"_det"),j(this,"_diff"),j(this,"_eigenvalues"),j(this,"_eigenvectors"),j(this,"_elements_count"),j(this,"_fill"),j(this,"_get"),j(this,"_inv"),j(this,"_is_antidiagonal"),j(this,"_is_antisymmetric"),j(this,"_is_binary"),j(this,"_is_diagonal"),j(this,"_is_identity"),j(this,"_is_square"),j(this,"_is_stochastic"),j(this,"_is_symmetric"),j(this,"_is_triangular"),j(this,"_is_zero"),j(this,"_kron"),j(this,"_max"),j(this,"_median"),j(this,"_min"),j(this,"_mode"),j(this,"_mult"),j(this,"_pinv"),j(this,"_pow"),j(this,"_rank"),j(this,"_remove_col"),j(this,"_remove_row"),j(this,"_reshape"),j(this,"_reverse"),j(this,"_row"),j(this,"_rows"),j(this,"_set"),j(this,"_sort"),j(this,"_submatrix"),j(this,"_sum"),j(this,"_swap_columns"),j(this,"_swap_rows"),j(this,"_trace"),j(this,"_transpose"),this.matrix=[],e>0&&i>0)for(let s=0;s<e;s++)this.matrix.push(Array(i).fill(r));this._add_col=cl(this.context),this._add_row=ul(this.context),this._avg=hl(this.context),this._col=pl(this.context),this._columns=fl(this.context),this._concat=dl(this.context),this._copy=ml(this.context),this._det=_l(this.context),this._diff=gl(this.context),this._eigenvalues=bl(this.context),this._eigenvectors=vl(this.context),this._elements_count=wl(this.context),this._fill=Sl(this.context),this._get=El(this.context),this._inv=Nl(this.context),this._is_antidiagonal=Cl(this.context),this._is_antisymmetric=Il(this.context),this._is_binary=kl(this.context),this._is_diagonal=Tl(this.context),this._is_identity=Al(this.context),this._is_square=Pl(this.context),this._is_stochastic=Dl(this.context),this._is_symmetric=Ml(this.context),this._is_triangular=Rl(this.context),this._is_zero=Ol(this.context),this._kron=$l(this.context),this._max=Vl(this.context),this._median=jl(this.context),this._min=Ll(this.context),this._mode=Bl(this.context),this._mult=Fl(this.context),this._pinv=Wl(this.context),this._pow=Ul(this.context),this._rank=ql(this.context),this._remove_col=zl(this.context),this._remove_row=Kl(this.context),this._reshape=Hl(this.context),this._reverse=Gl(this.context),this._row=Yl(this.context),this._rows=Xl(this.context),this._set=Zl(this.context),this._sort=Ql(this.context),this._submatrix=Jl(this.context),this._sum=ec(this.context),this._swap_columns=tc(this.context),this._swap_rows=ic(this.context),this._trace=rc(this.context),this._transpose=nc(this.context)}toString(){let e="";for(let i=0;i<this.matrix.length;i++)e+=e===""?"":`
2
- `,e+="["+this.matrix[i].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 Qe(t){return(e,i,r)=>new Z(e,i,r,t)}function oc(t){return(e,i=0)=>y.from(e).get(i)}class lc{constructor(e){this.context=e,this.add_col=(i,...r)=>i.add_col(...r),this.add_row=(i,...r)=>i.add_row(...r),this.avg=(i,...r)=>i.avg(...r),this.col=(i,...r)=>i.col(...r),this.columns=(i,...r)=>i.columns(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.det=(i,...r)=>i.det(...r),this.diff=(i,...r)=>i.diff(...r),this.eigenvalues=(i,...r)=>i.eigenvalues(...r),this.eigenvectors=(i,...r)=>i.eigenvectors(...r),this.elements_count=(i,...r)=>i.elements_count(...r),this.fill=(i,...r)=>i.fill(...r),this.get=(i,...r)=>i.get(...r),this.inv=(i,...r)=>i.inv(...r),this.is_antidiagonal=(i,...r)=>i.is_antidiagonal(...r),this.is_antisymmetric=(i,...r)=>i.is_antisymmetric(...r),this.is_binary=(i,...r)=>i.is_binary(...r),this.is_diagonal=(i,...r)=>i.is_diagonal(...r),this.is_identity=(i,...r)=>i.is_identity(...r),this.is_square=(i,...r)=>i.is_square(...r),this.is_stochastic=(i,...r)=>i.is_stochastic(...r),this.is_symmetric=(i,...r)=>i.is_symmetric(...r),this.is_triangular=(i,...r)=>i.is_triangular(...r),this.is_zero=(i,...r)=>i.is_zero(...r),this.kron=(i,...r)=>i.kron(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.mult=(i,...r)=>i.mult(...r),this.new=Qe(e),this.param=oc(),this.pinv=(i,...r)=>i.pinv(...r),this.pow=(i,...r)=>i.pow(...r),this.rank=(i,...r)=>i.rank(...r),this.remove_col=(i,...r)=>i.remove_col(...r),this.remove_row=(i,...r)=>i.remove_row(...r),this.reshape=(i,...r)=>i.reshape(...r),this.reverse=(i,...r)=>i.reverse(...r),this.row=(i,...r)=>i.row(...r),this.rows=(i,...r)=>i.rows(...r),this.set=(i,...r)=>i.set(...r),this.sort=(i,...r)=>i.sort(...r),this.submatrix=(i,...r)=>i.submatrix(...r),this.sum=(i,...r)=>i.sum(...r),this.swap_columns=(i,...r)=>i.swap_columns(...r),this.swap_rows=(i,...r)=>i.swap_rows(...r),this.trace=(i,...r)=>i.trace(...r),this.transpose=(i,...r)=>i.transpose(...r),this.new_float=Qe(e),this.new_int=Qe(e),this.new_string=Qe(e),this.new_bool=Qe(e),this.new_color=Qe(e),this.new_line=Qe(e),this.new_label=Qe(e),this.new_box=Qe(e),this.new_linefill=Qe(e),this.new_table=Qe(e)}}var cc=Object.defineProperty,uc=(t,e,i)=>e in t?cc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,hc=(t,e,i)=>uc(t,typeof e!="symbol"?e+"":e,i);class pc{constructor(e){this.context=e,hc(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(){const e=this.context.idx,i=this.context.length;if(e===i-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===i-2){const r=this.context.marketData?.[i-1]?.closeTime;return r!==void 0?r>Date.now():!1}return!1}}var fc=Object.defineProperty,dc=(t,e,i)=>e in t?fc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,mc=(t,e,i)=>dc(t,typeof e!="symbol"?e+"":e,i);class It{constructor(e,i,r){this._definition=e,this.context=i,mc(this,"_udt");for(let n in e)this[n]=e[n];this._udt=r}get __def__(){return this._definition}copy(){return new It(this.__def__,this.context,this._udt)}toString(){const e={};for(let i in this.__def__){const r=this[i];r!=null&&typeof r=="object"&&typeof r.toString=="function"&&!(r instanceof Array)?e[i]=r.toString():e[i]=r}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(i=>`"${i}":${String(e[i])}`).join(",")+"}"}}}var yc=Object.defineProperty,_c=(t,e,i)=>e in t?yc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ar=(t,e,i)=>_c(t,typeof e!="symbol"?e+"":e,i);class Ie{constructor(e,i,r){ar(this,"time"),ar(this,"index"),ar(this,"price"),this.time=e,this.index=i,this.price=r}copy(){return new Ie(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}}function gc(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}const nn={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 Ie,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 Ie)&&!gc(t)};function et(t){const e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function te(t,e,i,r){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);const n={};let s={};const a=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){const l=t[o];if(nn.remaining_options(l)){s=l;break}const c=e.map((u,p)=>a[p]?u[o]:void 0);for(let u=0;u<c.length;u++){const p=c[u];if(p===void 0){a[u]=!1;continue}const h=i[p];if(typeof l=="number"&&isNaN(l)&&(h==="number"||h==="series"))n[p]=l;else{const f=nn[i[p]];typeof f=="function"&&f(l)?n[p]=l:a[u]=!1}}}return{...n,...s,...r}}function C(t,e,i){const r=i.value;return typeof r!="function"||(i.value=function(...n){return this&&this.context&&this.context.isSecondaryContext?null:r.apply(this,n)}),i}var ws=Object.defineProperty,xc=Object.getOwnPropertyDescriptor,bc=(t,e,i)=>e in t?ws(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ss=(t,e,i,r)=>{for(var n=r>1?void 0:r?xc(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=(r?a(e,i,n):a(n))||n);return r&&n&&ws(e,i,n),n},Qt=(t,e,i)=>bc(t,typeof e!="symbol"?e+"":e,i);const vc=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],wc={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},Sc=["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"],Ec={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 Nc(t){return te(t,Sc,Ec)}class Re{get __value(){return NaN}param(e,i=0){return y.from(e).get(i)}any(e){if(e instanceof Re)return!0;const i=y.from(e).get(0);return i instanceof Re||i==null?!0:typeof i=="number"?i!==i:!1}}const Ut={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"};class Es{constructor(e){this.context=e,Qt(this,"_firedKeys",new Set),Qt(this,"_fallbackCounter",0),Qt(this,"_fallbackLastExecTick",-1)}get freq_all(){return Ut.freq_all}get freq_once_per_bar(){return Ut.freq_once_per_bar}get freq_once_per_bar_close(){return Ut.freq_once_per_bar_close}param(e,i,r){return y.from(e).get(0)}any(e,i,r){const n=y.from(e).get(0),s=i?y.from(i).get(0):Ut.freq_once_per_bar;let a;if(r&&typeof r=="object"&&r.__callsiteId)a=r.__callsiteId;else{const u=this.context._execTick||0;u!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=u),a=`alert_${this._fallbackCounter++}`}const o=this.context.idx,l=this.context.pine?.barstate?.isrealtime??o===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${a}:${o}`;if(s===Ut.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(s===Ut.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:n,freq:s,bar_index:o,time:this.context.data.openTime?.data?.[o]??0})}}Ss([C],Es.prototype,"any",1);class Ns{constructor(e){this.context=e,Qt(this,"_acCounter",0),Qt(this,"_acLastExecTick",-1),Qt(this,"_acFiredKeys",new Set)}extractPlotOptions(e){const i={};for(let r in e)i[r]=y.from(e[r]).get(0);return i}indicator(...e){const i=e.map(s=>s instanceof y?s.get(0):s),r=Nc(i),n={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={...n,...r,...this.context._propOverrides??{}},this.context.indicator}get bar_index(){return this.context.idx}na(e){const i=y.from(e).get(0);return i==null||typeof i=="number"&&isNaN(i)}nz(e,i=0){const r=y.from(e).get(0),n=y.from(i).get(0);return r==null||typeof r=="number"&&isNaN(r)?n:r}fixnan(e){const i=y.from(e);for(let r=0;r<i.length;r++){const n=i.get(r);if(!isNaN(n))return n}return NaN}alertcondition(e,i,r){const n=y.from(e).get(0),s=this.context.idx,a=this.context._execTick||0;a!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=a);const o=`alertcondition_${this._acCounter++}`;if(!n)return;const l=this.context.pine?.barstate?.isrealtime??s===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${o}:${s}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);const u=i?y.from(i).get(0):"",p=r?y.from(r).get(0):"";this.context.alerts.push({type:"alertcondition",id:o,title:u,message:p,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,i){}timestamp(...e){const i=e.map(n=>n instanceof y?n.get(0):n),r=te(i,vc,wc);if(r.year!==void 0){const n=r.year,s=r.month,a=r.day,o=r.hour||0,l=r.minute||0,c=r.second||0,u=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(u,n,s,a,o,l,c)}if(r.dateString!==void 0){const n=r.dateString.trim();if(/[Zz]$/.test(n)||/[+-]\d{2}:?\d{2}$/.test(n))return new Date(n).getTime();const s=n.includes("T")?n+"Z":n.replace(/\s+/,"T")+"Z",a=new Date(s);if(!isNaN(a.getTime())){const 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(n).getTime()}return NaN}_timestampFromComponents(e,i,r,n,s,a,o){const l=new Date(Date.UTC(i,r-1,n,s,a,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();const u=c.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(u){const p=u[1]==="+"?1:-1,h=parseInt(u[2],10),f=parseInt(u[3]||"0",10),d=p*(h*60+f)*60*1e3;return l.getTime()-d}try{return this._timestampFromIANA(e,i,r,n,s,a,o)}catch{return l.getTime()}}_timestampFromIANA(e,i,r,n,s,a,o){const l=new Date(Date.UTC(i,r-1,n,s,a,o));i>=0&&i<100&&l.setUTCFullYear(i);const 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=w=>parseInt(c.find(S=>S.type===w)?.value||"0",10),p=u("year"),h=u("month"),f=u("day");let d=u("hour");d===24&&(d=0);const m=u("minute"),x=u("second"),b=new Date(Date.UTC(p,h-1,f,d,m,x));p>=0&&p<100&&b.setUTCFullYear(p);const v=b.getTime()-l.getTime();return l.getTime()-v}bool(e){const i=y.from(e).get(0);return!isNaN(i)&&i!==0}int(e){const i=y.from(e).get(0);if(typeof i!="number")throw new Error(`Cannot call "int" with argument "x"="${i}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.trunc(i)}float(e){const i=y.from(e).get(0);if(typeof i!="number")throw new Error(`Cannot call "float" with argument "x"="${i}". An argument of "literal string" type was used but a "const float" is expected.`);return i}string(e){return y.from(e).get(0).toString()}Type(e){const i=Object.keys(e),r={};for(const s of i){let a=e[s];a instanceof y&&(a=a.data),Array.isArray(a)&&(a[0],r[s]=a[1])}const n={new:function(...s){const a={};let o=null;if(s.length>0){const l=s[s.length-1];if(l&&typeof l=="object"&&!(l instanceof y)&&!Array.isArray(l)&&!(l instanceof It)){const c=Object.keys(l);c.length>0&&c.some(u=>i.includes(u))&&(o=l,s=s.slice(0,-1))}}for(let l=0;l<i.length;l++){const c=i[l];o&&c in o?a[c]=o[c]:l<s.length?a[c]=s[l]:c in r&&(a[c]=y.from(r[c]).get(0))}return new It(a,this.context,n)},copy:function(s){return new It(s.__def__,this.context,n)},_fieldDefaults:r,_definitionKeys:i};return n}}Ss([C],Ns.prototype,"alertcondition",1);function qt(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){const i=t.slice(1);return i.length===6?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),1]:i.length===8?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),parseInt(i.slice(6,8),16)/255]:null}const 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 Cc(t,e,i,r){const n=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,i))).toString(16).padStart(2,"0");if(r>=1)return`#${n}${s}${a}`.toUpperCase();const o=Math.round(Math.max(0,Math.min(255,r*255))).toString(16).padStart(2,"0");return`#${n}${s}${a}${o}`.toUpperCase()}const de={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 rt(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}class Ic{constructor(e){this.context=e}any(e){const i=y.from(e).get(0);return typeof i=="number"&&isNaN(i)?null:i}param(e,i=0){return y.from(e).get(i)}new(e,i){if(e=rt(e),!e||typeof e!="string")return e;if(typeof i=="number"&&isNaN(i)&&(i=void 0),e.startsWith("#")){const r=e.slice(1),n=r.length===8?r.slice(0,6):r;return i!=null?`#${n}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:`#${r}`}else{const r=de[e];if(r)return i!=null?`#${r.slice(1)}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:r;const n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*([\d.]+))?\s*\)/);if(n){const s=n[1],a=n[2],o=n[3];if(i!=null){const l=parseInt(s).toString(16).padStart(2,"0"),c=parseInt(a).toString(16).padStart(2,"0"),u=parseInt(o).toString(16).padStart(2,"0"),p=Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase();return`#${l}${c}${u}${p}`}return e}return i!=null?`rgba(${e}, ${(100-i)/100})`:e}}rgb(e,i,r,n){return typeof n=="number"&&isNaN(n)&&(n=void 0),n!=null?`rgba(${e}, ${i}, ${r}, ${(100-n)/100})`:`rgb(${e}, ${i}, ${r})`}from_gradient(e,i,r,n,s){if(e=rt(e),i=rt(i),r=rt(r),n=rt(n),s=rt(s),e==null||typeof e=="number"&&isNaN(e)||i==null||typeof i=="number"&&isNaN(i)||r==null||typeof r=="number"&&isNaN(r)||n==null||typeof n=="number"&&isNaN(n)||s==null||typeof s=="number"&&isNaN(s))return;let a=0;r!==i&&(a=(e-i)/(r-i)),a=Math.max(0,Math.min(1,a));const o=qt(typeof n=="string"?n:"#000000")||[0,0,0,1],l=qt(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,p=o[2]+(l[2]-o[2])*a,h=o[3]+(l[3]-o[3])*a;return Cc(c,u,p,h)}r(e){if(e=rt(e),!e||typeof e!="string")return NaN;const i=qt(e);return i?i[0]:NaN}g(e){if(e=rt(e),!e||typeof e!="string")return NaN;const i=qt(e);return i?i[1]:NaN}b(e){if(e=rt(e),!e||typeof e!="string")return NaN;const i=qt(e);return i?i[2]:NaN}t(e){if(e=rt(e),!e||typeof e!="string")return NaN;const i=qt(e);return i?Math.round(100-i[3]*100):NaN}aqua(){return de.aqua}black(){return de.black}blue(){return de.blue}fuchsia(){return de.fuchsia}gray(){return de.gray}green(){return de.green}lime(){return de.lime}maroon(){return de.maroon}navy(){return de.navy}olive(){return de.olive}orange(){return de.orange}purple(){return de.purple}red(){return de.red}silver(){return de.silver}teal(){return de.teal}white(){return de.white}yellow(){return de.yellow}}var kc=Object.defineProperty,Tc=(t,e,i)=>e in t?kc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Bi=(t,e,i)=>Tc(t,typeof e!="symbol"?e+"":e,i);function _r(t){if(!t)return"";const e=t.trim().toUpperCase();return e==="1D"||e==="D"?"D":e==="1W"||e==="W"?"W":e==="1M"||e==="M"?"M":e}function gr(t,e){const i=Ac(e);if(e==="M"){const o=new Date(t);return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),1)}if(e==="W"){const 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"||i>=1440)return Math.floor(t/864e5)*864e5;const r=i*6e4,n=Math.floor(t/864e5)*864e5,s=t-n,a=Math.floor(s/r)*r;return n+a}function Ac(t){if(t==="D")return 1440;if(t==="W")return 10080;if(t==="M")return 43200;const e=parseInt(t,10);return isNaN(e)?1440:e}function Rt(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC"){const n=new Date(t);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),dayOfWeek:n.getUTCDay()}}const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const n=r[1]==="+"?1:-1,s=parseInt(r[2],10),a=parseInt(r[3]||"0",10),o=n*(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{const n=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(n.find(u=>u.type===c)?.value||"0",10);let a=s("hour");a===24&&(a=0);const o=n.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{const n=new Date(t);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),dayOfWeek:n.getUTCDay()}}}function Pc(t,e,i){const r=new Date(Date.UTC(t,e-1,i)),n=r.getUTCDay()||7;r.setUTCDate(r.getUTCDate()+4-n);const s=new Date(Date.UTC(r.getUTCFullYear(),0,1));return Math.ceil(((r.getTime()-s.getTime())/864e5+1)/7)}const Dc=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],Mc={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"};class sn{constructor(e,i="openTime"){Bi(this,"context"),Bi(this,"dataField"),this.context=e,this.dataField=i}get __value(){return this.context.data[this.dataField]}param(e,i=0){return y.from(e).get(i)}any(...e){const i=e.map(h=>h instanceof y?h.get(0):h),r=te(i,Dc,Mc),n=r.bars_back??0,s=r.timeframe||"",a=this.context.data[this.dataField],o=y.from(a).get(n);if(isNaN(o)||o==null)return NaN;const l=this.context.timeframe||"",c=_r(s),u=_r(l);let p;if(!c||c===u?p=o:p=gr(o,c),r.session!==void 0&&r.session!==""){const h=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(p,r.session,h)?p:NaN}return p}_isInSession(e,i,r){const n=i.match(/^(\d{2})(\d{2})-(\d{2})(\d{2})$/);if(!n)return!0;const s=parseInt(n[1],10),a=parseInt(n[2],10),o=parseInt(n[3],10),l=parseInt(n[4],10),c=Rt(e,r),u=c.hour,p=c.minute,h=u*60+p,f=s*60+a,d=o*60+l;return f<=d?h>=f&&h<d:h>=f||h<d}}const Rc=[[],["time"],["time","timezone"]],Oc={time:"number",timezone:"string"};class vt{constructor(e,i){Bi(this,"context"),Bi(this,"extractor"),this.context=e,this.extractor=i}get __value(){const e=y.from(this.context.data.openTime).get(0);if(isNaN(e))return NaN;const i=this.context.pine?.syminfo?.timezone||"UTC",r=Rt(e,i);return this.extractor(r)}param(e,i=0){return y.from(e).get(i)}any(...e){const i=e.map(o=>o instanceof y?o.get(0):o);if(i.length===0)return this.__value;const r=te(i,Rc,Oc),n=r.time;if(n===void 0||isNaN(n))return NaN;const s=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",a=Rt(n,s);return this.extractor(a)}}const wt={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=>Pc(t.year,t.month,t.day),year:t=>t.year},$c=[["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"]],Vc={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function $e(t){return te(t,$c,Vc)}function Be(t,e){return e.title&&t.inputs&&t.inputs[e.title]!==void 0?t.inputs[e.title]:e.defval}function jc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Lc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Bc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Fc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Wc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Uc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function qc(t){return(e,i=0)=>y.from(e).get(i)}function zc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Kc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Hc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Gc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Yc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Xc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Zc(t){return(...e)=>{const i=$e(e);return Be(t,i)}}function Qc(t){return(...e)=>$e(e).defval}var Jc=Object.defineProperty,eu=(t,e,i)=>e in t?Jc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ne=(t,e,i)=>eu(t,typeof e!="symbol"?e+"":e,i);const tu={any:jc,bool:Lc,color:Bc,enum:Fc,float:Wc,int:Uc,param:qc,price:zc,session:Kc,source:Hc,string:Gc,symbol:Yc,text_area:Xc,time:Zc,timeframe:Qc};class iu{constructor(e){this.context=e,Ne(this,"any"),Ne(this,"bool"),Ne(this,"color"),Ne(this,"enum"),Ne(this,"float"),Ne(this,"int"),Ne(this,"param"),Ne(this,"price"),Ne(this,"session"),Ne(this,"source"),Ne(this,"string"),Ne(this,"symbol"),Ne(this,"text_area"),Ne(this,"time"),Ne(this,"timeframe"),Object.entries(tu).forEach(([i,r])=>{this[i]=r(e)})}}function ru(t){return e=>Math.abs(y.from(e).get(0))}function nu(t){return e=>Math.acos(y.from(e).get(0))}function su(t){return e=>Math.asin(y.from(e).get(0))}function au(t){return e=>Math.atan(y.from(e).get(0))}function ou(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return i.reduce((r,n)=>r+n,0)/i.length}}function lu(t){return e=>Math.ceil(y.from(e).get(0))}function cu(t){return e=>Math.cos(y.from(e).get(0))}function uu(t){return()=>Math.E}function hu(t){return e=>Math.exp(y.from(e).get(0))}function pu(t){return e=>Math.floor(y.from(e).get(0))}function fu(t){return e=>Math.log(y.from(e).get(0))}function du(t){return e=>Math.log(y.from(e).get(0))}function mu(t){return e=>Math.log10(y.from(e).get(0))}function yu(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return Math.max(...i)}}function _u(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return Math.min(...i)}}function gu(t){return(e,i,r)=>typeof e=="string"?e:e instanceof y?i?new y(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new y(t.params[r],i||0)))}function xu(t){return()=>1.618033988749895}function bu(t){return()=>Math.PI}function vu(t){return(e,i)=>Math.pow(y.from(e).get(0),y.from(i).get(0))}function wu(t){return()=>Math.random()}function or(t){return t!==t?NaN:Math.sign(t)*Math.round(Math.abs(t))}function Su(t){return(e,i)=>{const r=y.from(e).get(0);if(i==null)return or(r);const n=y.from(i).get(0);if(n===0)return or(r);const s=Math.pow(10,n);return or(r*s)/s}}function Eu(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Nu(t){return()=>.6180339887498948}function Cu(t){return e=>Math.sign(y.from(e).get(0))}function Iu(t){return e=>Math.sin(y.from(e).get(0))}function ku(t){return e=>Math.sqrt(y.from(e).get(0))}function Tu(t){return(e,i)=>{const r=y.from(i).get(0),n=y.from(e);let s=0;for(let a=0;a<r;a++){const o=n.get(a);s+=o}return s}}function Au(t){return e=>Math.tan(y.from(e).get(0))}function Pu(t){return e=>{const i=y.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(180/Math.PI)}}function Du(t){return e=>{const i=y.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(Math.PI/180)}}function Mu(t){return(e,i)=>{const r=y.from(e).get(0),n=y.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)||isNaN(n)?!1:Math.abs(r-n)<1e-9:r===n}}function Ru(t){return(e,i)=>{const r=y.from(e).get(0),n=y.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)||isNaN(n)?!1:Math.abs(r-n)>=1e-9:r!==n}}var Ou=Object.defineProperty,$u=(t,e,i)=>e in t?Ou(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,G=(t,e,i)=>$u(t,typeof e!="symbol"?e+"":e,i);const Vu={abs:ru,acos:nu,asin:su,atan:au,avg:ou,ceil:lu,cos:cu,e:uu,exp:hu,floor:pu,ln:fu,log:du,log10:mu,max:yu,min:_u,param:gu,phi:xu,pi:bu,pow:vu,random:wu,round:Su,round_to_mintick:Eu,rphi:Nu,sign:Cu,sin:Iu,sqrt:ku,sum:Tu,tan:Au,todegrees:Pu,toradians:Du,__eq:Mu,__neq:Ru};class ju{constructor(e){this.context=e,G(this,"_cache",{}),G(this,"abs"),G(this,"acos"),G(this,"asin"),G(this,"atan"),G(this,"avg"),G(this,"ceil"),G(this,"cos"),G(this,"e"),G(this,"exp"),G(this,"floor"),G(this,"ln"),G(this,"log"),G(this,"log10"),G(this,"max"),G(this,"min"),G(this,"param"),G(this,"phi"),G(this,"pi"),G(this,"pow"),G(this,"random"),G(this,"round"),G(this,"round_to_mintick"),G(this,"rphi"),G(this,"sign"),G(this,"sin"),G(this,"sqrt"),G(this,"sum"),G(this,"tan"),G(this,"todegrees"),G(this,"toradians"),G(this,"__eq"),G(this,"__neq"),Object.entries(Vu).forEach(([i,r])=>{this[i]=r(e)})}}function Lu(t){return(e,i,r)=>{t.params[r]||(t.params[r]=[]);let n;if(e instanceof y)n=e.get(i||0);else if(Array.isArray(e)){const s=e.some(o=>o instanceof y),a=e.every(o=>!(o instanceof y)&&!Array.isArray(o));(s||a)&&e.length>=1?n=e.map(o=>o instanceof y?o.get(0):o):n=y.from(e).get(i||0)}else n=e;return t.params[r].length===0?t.params[r].push(n):t.params[r][t.params[r].length-1]=n,t._requestParamSources||(t._requestParamSources={}),t._requestParamSources[r]=e,[n,r]}}const ti=["1","3","5","15","30","45","60","120","180","240","D","W","M"],Ni={"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 Fi(t){if(ti.includes(t))return t;if(Ni[t])return Ni[t];const e=t.toLowerCase();if(Ni[e])return Ni[e];const i=t.toUpperCase();return ti.includes(i)?i:t}function an(t,e,i,r,n=!1,s=!1){for(let a=0;a<i.length;a++)if(i[a]<=t&&t<r[a])return n||s||e>=r[a]?a:a-1;return-1}function on(t,e,i,r,n=!1,s,a=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=e&&i[o]>=t){const l=s&&e>s;if(a&&n)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}if(l&&n&&!a)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}return o}if(r[o]<t)break}return-1}const ln=[["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"]],Bu={symbol:"series",timeframe:"series",expression:"any",gaps:"series",lookahead:"series",ignore_invalid_symbol:"series",currency:"series",calc_bars_count:"series"};function Or(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function Fu(t,e){return t.map(i=>Or(i)?(e.push(i[1]),i[0]):(e.push(void 0),i))}function zt(t){return Or(t)?t[0]:t}function Wu(t,e,i,r){const n=e[e.length-1].indexOf(t);if(n>=0&&n<i.length&&i[n]!==void 0)return i[n];if(Or(r))return r[1]}function xr(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(xr):t}function Uu(t){return async(...e)=>{const i=[],r=Fu(e,i),n=te(r,ln,Bu),s=zt(n.symbol),a=zt(n.timeframe),o=zt(n.expression),l=zt(n.gaps),c=zt(n.lookahead),u=s instanceof y?s.get(0):s,p=u===""?t.tickerId:u,h=typeof p=="string"&&p.includes(":")?p.split(":")[1]:p,f=a instanceof y?a.get(0):a,d=f===""?t.timeframe:typeof f=="string"?f:String(f??""),m=o,x=Wu("expression",ln,i,n.expression),b=l,v=c,w=b===!0||b==="gaps_on",S=v===!0||v==="lookahead_on",T=(()=>{const _e=zt(n.calc_bars_count);return typeof _e=="number"&&_e>0?_e:void 0})();if(t.isSecondaryContext){const _e=xr(m);return Array.isArray(_e)?[_e]:_e}const N=ti.indexOf(Fi(t.timeframe)),R=ti.indexOf(Fi(d));if(N==-1||R==-1)throw new Error("Invalid timeframe");const V=typeof t.tickerId=="string"&&t.tickerId.includes(":")?t.tickerId.split(":")[1]:t.tickerId;if(N===R&&(!h||h===""||h===V)){const _e=xr(m);return Array.isArray(_e)?[_e]:_e}const k=N>R,A=y.from(t.data.openTime).get(0),O=y.from(t.data.closeTime).get(0),z=t.idx===t.length-1&&O>Date.now(),$=`${h}_${d}_${x}`,q=`${$}_prevIdx`;if(t.cache[$]){const _e=t.cache[$];t.dataVersion>_e.dataVersion&&(await _e.pineTS.updateTail(_e.context),_e.dataVersion=t.dataVersion);const si=_e.context,Ei=k?on(A,O,si.data.openTime.data,si.data.closeTime.data,S,t.eDate,w):an(A,O,si.data.openTime.data,si.data.closeTime.data,S,z);if(Ei==-1)return NaN;const Wt=si.params[x][Ei];if(!k&&w){const rn=t.cache[q];return rn!==void 0&&rn===Ei?NaN:(t.cache[q]=Ei,Array.isArray(Wt)?[Wt]:Wt)}return Array.isArray(Wt)?[Wt]:Wt}const Ae=1e3*60*60*24*30,fe=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),Fe=T?void 0:fe?fe-Ae:void 0,Ee=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),pt=new Jr(t.source,h,d,T,Fe,Ee);pt.markAsSecondary();const Bt=typeof x=="string"?x:"",ja=Bt.match(/p\d+$/)?.[0]??Bt,tn=t._ltfTruncatedBodies?.[ja],Ft=tn?await pt.runPretranspiled(tn):await pt.run(t.pineTSCode);t.cache[$]={pineTS:pt,context:Ft,dataVersion:t.dataVersion};const nr=k?on(A,O,Ft.data.openTime.data,Ft.data.closeTime.data,S,t.eDate,w):an(A,O,Ft.data.openTime.data,Ft.data.closeTime.data,S,z);if(nr==-1)return NaN;const sr=Ft.params[x][nr];return!k&&w?(t.cache[q]=nr,NaN):Array.isArray(sr)?[sr]:sr}}const cn=[["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"]],qu={symbol:"series",timeframe:"series",expression:"any",ignore_invalid_symbol:"series",currency:"series",ignore_invalid_timeframe:"series",calc_bars_count:"series"};function $r(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function zu(t,e){return t.map(i=>$r(i)?(e.push(i[1]),i[0]):(e.push(void 0),i))}function Kt(t){return $r(t)?t[0]:t}function Ku(t,e,i,r){const n=e[e.length-1].indexOf(t);if(n>=0&&n<i.length&&i[n]!==void 0)return i[n];if($r(r))return r[1]}function Ht(t){return typeof t=="number"?L.float:typeof t=="boolean"?L.bool:typeof t=="string"?L.string:L.any}const Cs={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 br(t,e){if(!(t instanceof y))return null;const i=e?.data;if(!i)return null;for(const r of Object.keys(Cs))if(t===i[r])return r;return null}function Hu(t,e){if(t instanceof y&&(t=t.get(0)),!(t instanceof It))return null;const i=t._udt;if(!i||!i._fieldDefaults||!Array.isArray(i._definitionKeys))return null;const r=i._definitionKeys;if(r.length===0)return null;const n=[];for(const s of r){if(!(s in i._fieldDefaults))return null;const a=i._fieldDefaults[s],o=br(a,e);if(o===null)return null;n.push(o)}return{kind:"udt",builtinNames:n,fieldNames:r,udt:i}}function Gu(t,e){if(t===void 0)return null;if(Array.isArray(t)){const r=[];for(const n of t){const s=br(n,e);if(s===null)return null;r.push(s)}return r.length>0?{kind:"tuple",builtinNames:r}:null}const i=br(t,e);return i!==null?{kind:"series",builtinNames:[i]}:Hu(t,e)}async function un(t,e,i,r,n,s){const 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 Jr(t.source,e,i,r,a,o);l.markAsSecondary(),await l.ready();const c=l.openTime,u=l.closeTime,p=l.data,h=n.builtinNames.map(d=>Cs[d]);let f;if(n.kind==="series")f=p.map(d=>h[0](d));else if(n.kind==="tuple")f=p.map(d=>h.map(m=>m(d)));else{const d=n.fieldNames,m=n.udt;f=p.map(x=>{const b={};for(let v=0;v<d.length;v++)b[d[v]]=h[v](x);return new It(b,t,m)})}return{data:{openTime:{data:c},closeTime:{data:u}},params:{[s]:f}}}function Yu(t){return async(...e)=>{const i=[],r=zu(e,i),n=te(r,cn,qu),s=Kt(n.symbol),a=Kt(n.timeframe),o=Kt(n.expression),l=s instanceof y?s.get(0):s,c=l===""?t.tickerId:l,u=typeof c=="string"&&c.includes(":")?c.split(":")[1]:c,p=a instanceof y?a.get(0):a,h=p===""?t.timeframe:typeof p=="string"?p:String(p??""),f=o,d=Ku("expression",cn,i,n.expression);Kt(n.ignore_invalid_symbol);const m=Kt(n.ignore_invalid_timeframe),x=(()=>{const q=Kt(n.calc_bars_count);return typeof q=="number"&&q>0?q:void 0})();if(t.isSecondaryContext)return Array.isArray(f)?[f.map(q=>new F([q],Ht(q),t))]:new F([f],Ht(f),t);const b=ti.indexOf(Fi(t.timeframe)),v=ti.indexOf(Fi(h));if(b===-1||v===-1){if(m)return NaN;throw new Error("Invalid timeframe")}if(v>b){if(m)return NaN;throw new Error(`Timeframe ${h} is not lower than or equal to chart timeframe ${t.timeframe}`)}if(v===b)return Array.isArray(f)?[f.map(q=>new F([q],Ht(q),t))]:new F([f],Ht(f),t);const w=`${u}_${h}_${d}_lower`,S=t._requestParamSources?.[d],T=Gu(S,t);if(!t.cache[w])if(T!==null){const q=await un(t,u,h,x,T,d);t.cache[w]={pineTS:null,context:q,dataVersion:t.dataVersion,_fastPath:!0,_fastPathArgs:{builtinExpr:T}}}else{const q=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),Ae=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),fe=new Jr(t.source,u,h,x,q,Ae);fe.markAsSecondary();const Fe=typeof d=="string"?d:"",Ee=Fe.match(/p\d+$/)?.[0]??Fe,pt=t._ltfTruncatedBodies?.[Ee];let Bt;pt?Bt=await fe.runPretranspiled(pt):Bt=await fe.run(t.pineTSCode),t.cache[w]={pineTS:fe,context:Bt,dataVersion:t.dataVersion}}const N=t.cache[w];if(t.dataVersion>N.dataVersion)if(N._fastPath){const q=await un(t,u,h,x,N._fastPathArgs.builtinExpr,d);N.context=q,N.dataVersion=t.dataVersion}else await N.pineTS.updateTail(N.context),N.dataVersion=t.dataVersion;const R=N.context,V=y.from(t.data.openTime).get(0),k=y.from(t.data.closeTime).get(0),A=R.data.openTime.data,O=R.data.closeTime.data,z=R.params[d];if(!z)return Array.isArray(f)?[f.map(()=>new F([],L.float,t))]:new F([],L.float,t);const $=[];for(let q=0;q<A.length;q++){const Ae=A[q];if(!(O[q]<=V)){if(Ae>=k)break;Ae>=V&&Ae<k&&$.push(z[q])}}if($.length>0&&Array.isArray($[0])){const q=$[0].length,Ae=[];for(let fe=0;fe<q;fe++){const Fe=$.map(pt=>pt[fe]),Ee=Fe.length>0?Ht(Fe[0]):L.float;Ae.push(new F(Fe,Ee,t))}return[Ae]}else{const q=$.length>0?Ht($[0]):L.float;return new F($,q,t)}}}var Xu=Object.defineProperty,Zu=(t,e,i)=>e in t?Xu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ci=(t,e,i)=>Zu(t,typeof e!="symbol"?e+"":e,i);const Qu={param:Lu,security:Uu,security_lower_tf:Yu};class Ju{constructor(e){this.context=e,Ci(this,"_cache",{}),Ci(this,"param"),Ci(this,"security"),Ci(this,"security_lower_tf"),Object.entries(Qu).forEach(([i,r])=>{this[i]=r(e)})}}function eh(t){return e=>{t.taState||(t.taState={});const i=e||"accdist";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=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(n)||isNaN(s)||isNaN(a)||isNaN(o))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);const l=s-a;let c=0;l!==0&&(c=(n-a-(s-n))/l*o);const u=r.prevCumulativeSum+c;return r.currentCumulativeSum=u,t.precision(u)}}function th(t){return(e,i,r,n,s)=>{const a=y.from(i).get(0),o=y.from(r).get(0),l=y.from(n).get(0);t.taState||(t.taState={});const c=s||`alma_${a}_${o}_${l}`;if(!t.taState[c]){const m=o*(a-1),x=a/l,b=[];let v=0;for(let w=0;w<a;w++){const S=Math.exp(-Math.pow(w-m,2)/(2*x*x));b.push(S),v+=S}for(let w=0;w<b.length;w++)b[w]/=v;t.taState[c]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weights:b}}const u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.prevWindow=[...u.currentWindow],u.prevCallCount=u.currentCallCount),u.lastIdx=t.idx);const p=y.from(e).get(0),h=[...u.prevWindow];for(h.unshift(p);h.length>a;)h.pop();const f=u.prevCallCount+1;if(h.length<a&&(f>=a||t.idx>=a-1)){const m=y.from(e);for(;h.length<a;)h.push(m.get(h.length))}if(u.currentWindow=h,u.currentCallCount=f,h.length<a)return NaN;let d=0;for(let m=0;m<a;m++)d+=u.weights[m]*h[a-1-m];return t.precision(d)}}function ih(t){return(e,i)=>{const r=y.from(e).get(0);t.taState||(t.taState={});const n=i||`atr_${r}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});const s=t.taState[n];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevAtr=s.currentAtr,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);const 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;const c=t.idx>0?t.get(t.data.close,1):null;let u;if(c!==null&&!isNaN(c)){const m=a-o,x=Math.abs(a-c),b=Math.abs(o-c);u=Math.max(m,x,b)}else u=a-o;let p=s.prevInitCount,h=s.prevInitSum,f=s.prevAtr;if(p<r){if(h+=u,p++,s.currentInitSum=h,s.currentInitCount=p,p===r){const m=h/r;return s.currentAtr=m,t.precision(m)}return NaN}const d=(f*(r-1)+u)/r;return s.currentAtr=d,t.precision(d)}}function rh(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"barssince";t.taState[r]||(t.taState[r]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevLastTrueIndex=n.currentLastTrueIndex),n.lastIdx=t.idx);const s=y.from(e).get(0);let a=n.prevLastTrueIndex;return s&&(a=t.idx),n.currentLastTrueIndex=a,a===null?NaN:t.idx-a}}function nh(t){return(e,i,r,n)=>{const s=y.from(i).get(0),a=y.from(r).get(0);t.taState||(t.taState={});const o=n||`bb_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];const u=[...l.prevWindow];let p=l.prevSum;for(u.unshift(c),p+=c;u.length>s;){const b=u.pop();p-=b}if(u.length<s&&t.idx>=s-1){const b=y.from(e);for(;u.length<s;){const v=b.get(u.length);if(isNaN(v))break;u.push(v),p+=v}}if(l.currentWindow=u,l.currentSum=p,u.length<s)return[[NaN,NaN,NaN]];const h=p/s;let f=0;for(let b=0;b<s;b++)f+=Math.pow(u[b]-h,2);const d=Math.sqrt(f/s),m=h+a*d,x=h-a*d;return[[t.precision(h),t.precision(m),t.precision(x)]]}}function sh(t){return(e,i,r,n)=>{const s=y.from(i).get(0),a=y.from(r).get(0);t.taState||(t.taState={});const o=n||`bbw_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;const u=[...l.prevWindow];let p=l.prevSum;for(u.unshift(c),p+=c;u.length>s;){const v=u.pop();p-=v}if(u.length<s&&t.idx>=s-1){const v=y.from(e);for(;u.length<s;){const w=v.get(u.length);if(isNaN(w))break;u.push(w),p+=w}}if(l.currentWindow=u,l.currentSum=p,u.length<s)return NaN;const h=p/s;let f=0;for(let v=0;v<s;v++){const w=u[v]-h;f+=w*w}const d=f/s,m=Math.sqrt(d),x=a*m;if(h===0)return t.precision(0);const b=2*x/h*100;return t.precision(b)}}function ah(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`cci_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const 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);const o=y.from(e).get(0);if(isNaN(o))return NaN;const l=[...a.prevWindow];let c=a.prevSum;for(l.unshift(o),c+=o;l.length>n;){const m=l.pop();c-=m}const u=a.prevCallCount+1;if(l.length<n&&(u>=n||t.idx>=n-1)){const m=y.from(e);for(;l.length<n;){const 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<n)return NaN;const p=c/n;let h=0;for(let m=0;m<n;m++)h+=Math.abs(l[m]-p);const f=h/n;if(f===0)return 0;const d=(o-p)/(.015*f);return t.precision(d)}}function oh(t){return(e,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`change_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);const o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>n+1;)l.pop();const c=a.prevCallCount+1;if(l.length<n+1&&(c>=n+1||t.idx>=n)){const p=y.from(e);for(;l.length<n+1;)l.push(p.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=n)return NaN;const u=o-l[n];return t.precision(u)}}function lh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`cmo_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0});const 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);const o=y.from(e).get(0),l=y.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;const c=o-l,u=c>=0?c:0,p=c>=0?0:-c,h=[...a.prevGainsWindow],f=[...a.prevLossesWindow];let d=a.prevGainsSum,m=a.prevLossesSum;if(h.unshift(u),f.unshift(p),d+=u,m+=p,h.length<n)return a.currentGainsWindow=h,a.currentLossesWindow=f,a.currentGainsSum=d,a.currentLossesSum=m,NaN;if(h.length>n){const v=h.pop(),w=f.pop();d-=v,m-=w}a.currentGainsWindow=h,a.currentLossesWindow=f,a.currentGainsSum=d,a.currentLossesSum=m;const x=d+m;if(x===0)return t.precision(0);const b=100*(d-m)/x;return t.precision(b)}}function ch(t){return(e,i,r)=>{const n=y.from(i).get(0),s=y.from(e);let a=0,o=!1;for(let u=0;u<n;u++){const p=s.get(u);if(isNaN(p)){o=!0;break}a+=p}if(o)return NaN;let l=0;for(let u=0;u<n;u++){const p=s.get(u);l+=p*(u+1)}if(a===0)return NaN;const c=-l/a;return t.precision(c)}}function uh(t){return(e,i,r,n)=>{const s=y.from(r).get(0),a=y.from(e),o=y.from(i);if(t.idx<s-1)return NaN;let l=0,c=0,u=0,p=0,h=0,f=0;for(let v=0;v<s;v++){const w=a.get(v),S=o.get(v);isNaN(w)||isNaN(S)||(l+=w,c+=S,u+=w*S,p+=w*w,h+=S*S,f++)}if(f<2)return NaN;const d=f*u-l*c,m=f*p-l*l,x=f*h-c*c;if(m<=0||x<=0)return t.precision(0);const b=d/Math.sqrt(m*x);return t.precision(b)}}function hh(t){return(e,i,r)=>{const n=y.from(e),s=y.from(i),a=n.get(0),o=s.get(0),l=n.get(1),c=s.get(1);if(isNaN(a)||isNaN(o)||isNaN(l)||isNaN(c))return!1;const u=a>o&&l<=c,p=a<o&&l>=c;return u||p}}function ph(t){return(e,i)=>{const r=y.from(e),n=y.from(i),s=r.get(0),a=n.get(0),o=r.get(1),l=n.get(1);return o<=l&&s>a}}function fh(t){return(e,i)=>{const r=y.from(e),n=y.from(i),s=r.get(0),a=n.get(0),o=r.get(1),l=n.get(1);return o>=l&&s<a}}function dh(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"cum";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);const s=y.from(e).get(0);if(isNaN(s))return n.currentCumulativeSum=n.prevCumulativeSum,t.precision(n.prevCumulativeSum);const a=n.prevCumulativeSum+s;return n.currentCumulativeSum=a,t.precision(a)}}function mh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`dev_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const 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);const o=y.from(e).get(0)||0,l=[...a.prevWindow];let c=a.prevSum;for(l.unshift(o),c+=o;l.length>n;){const d=l.pop();c-=d}const u=a.prevCallCount+1;if(l.length<n&&(u>=n||t.idx>=n-1)){const d=y.from(e);for(;l.length<n;){const m=d.get(l.length);l.push(m),c+=m}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=u,l.length<n)return NaN;const p=c/n;let h=0;for(let d=0;d<n;d++)h+=Math.abs(l[d]-p);const f=h/n;return t.precision(f)}}function yh(t){return(e,i,r)=>{const n=y.from(e).get(0),s=y.from(i).get(0);t.taState||(t.taState={});const a=r||`dmi_${n}_${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});const 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);const 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]];const p=t.idx>0?t.get(t.data.high,1):NaN,h=t.idx>0?t.get(t.data.low,1):NaN,f=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(p))return[[NaN,NaN,NaN]];const d=Math.max(l-c,Math.abs(l-f),Math.abs(c-f)),m=l-p,x=h-c,b=m>x&&m>0?m:0,v=x>m&&x>0?x:0;let w=o.prevInitCount,S=o.prevTrInitSum,T=o.prevPlusInitSum,N=o.prevMinusInitSum,R=o.prevSmoothedTR,V=o.prevSmoothedPlus,k=o.prevSmoothedMinus;if(w++,w<=n)S+=d,T+=b,N+=v,w===n&&(R=S/n,V=T/n,k=N/n);else{const Ee=1/n;R=Ee*d+(1-Ee)*R,V=Ee*b+(1-Ee)*V,k=Ee*v+(1-Ee)*k}if(o.currentInitCount=w,o.currentTrInitSum=S,o.currentPlusInitSum=T,o.currentMinusInitSum=N,o.currentSmoothedTR=R,o.currentSmoothedPlus=V,o.currentSmoothedMinus=k,w<n)return[[NaN,NaN,NaN]];const A=R===0?0:100*V/R,O=R===0?0:100*k/R,z=A+O,$=z===0?0:100*Math.abs(A-O)/z;let q=o.prevAdxInitCount,Ae=o.prevDxInitSum,fe=o.prevADX,Fe=NaN;if(q++,q<=s)Ae+=$,q===s&&(fe=Ae/s,Fe=fe);else{const Ee=1/s;fe=Ee*$+(1-Ee)*fe,Fe=fe}return o.currentAdxInitCount=q,o.currentDxInitSum=Ae,o.currentADX=fe,[[t.precision(A),t.precision(O),t.precision(Fe)]]}}function _h(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`ema_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});const 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);const 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<n){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===n){const f=c/n;return a.currentEma=f,t.precision(f)}return NaN}const p=2/(n+1),h=o*p+u*(1-p);return a.currentEma=h,t.precision(h)}}function gh(t){return(e,i,r)=>{const n=y.from(i).get(0),s=y.from(e);for(let a=0;a<n;a++){const o=s.get(a),l=s.get(a+1);if(isNaN(o)||isNaN(l)||o>=l)return!1}return!0}}function xh(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.high);const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`highest_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);const o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=a.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const h=y.from(e);for(;l.length<n;)l.push(h.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<n)return NaN;const u=l.filter(h=>!isNaN(h)&&h!==void 0);if(u.length===0)return NaN;const p=Math.max(...u);return t.precision(p)}}function bh(t){return(e,i,r)=>{const n=y.from(i).get(0),s=y.from(e);if(t.idx<n-1)return NaN;let a=-1/0,o=NaN;for(let l=0;l<n;l++){const c=s.get(l);isNaN(c)||(isNaN(o)||c>a)&&(a=c,o=-l)}return o}}function vh(t){return(e,i,r)=>{const n=y.from(i).get(0),s=Math.floor(n/2),a=Math.floor(Math.sqrt(n)),o=t.pine.ta.wma,l=o(e,s,r?`${r}_wma1`:void 0),c=o(e,n,r?`${r}_wma2`:void 0);if(isNaN(l)||isNaN(c))return NaN;t.taState||(t.taState={});const u=r||`hma_raw_${n}`;t.taState[u]||(t.taState[u]={lastIdx:-1,prevValues:[],currentValues:[]});const p=t.taState[u];t.idx>p.lastIdx&&(p.lastIdx>=0&&(p.prevValues=[...p.currentValues]),p.lastIdx=t.idx);const h=2*l-c,f=[...p.prevValues];f.unshift(h),f.length>a+1&&f.pop(),p.currentValues=f;const d=r?`${r}_hma_final`:`hma_final_${n}`;t.taState[d]||(t.taState[d]={lastIdx:-1,prevWindow:[],currentWindow:[]});const m=t.taState[d];t.idx>m.lastIdx&&(m.lastIdx>=0&&(m.prevWindow=[...m.currentWindow]),m.lastIdx=t.idx);const x=[...m.prevWindow];if(x.unshift(h),x.length<a)return m.currentWindow=x,NaN;for(;x.length>a;)x.pop();m.currentWindow=x;let b=0,v=0;for(let S=0;S<a;S++){const T=a-S;b+=x[S]*T,v+=T}const w=b/v;return t.precision(w)}}function wh(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.high,0),n=t.get(t.data.low,0),s=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(s))return NaN;const a=(r-n)*s;if(a===0)return t.precision(0);const o=(2*i-r-n)/a;return t.precision(o)}}function Sh(t){return(e,i,r,n,s)=>{const a=y.from(i).get(0),o=y.from(r).get(0);let l=!0;typeof n=="string"?s=n:n!==void 0&&(l=y.from(n).get(0));let c;const u=t.get(t.data.high,0),p=t.get(t.data.low,0);if(l){const S=t.get(t.data.close,1);isNaN(S)?c=NaN:c=Math.max(u-p,Math.abs(u-S),Math.abs(p-S))}else c=u-p;const h=y.from(e).get(0);t.taState||(t.taState={});const f=s||`kc_${a}_${o}_${l}`;t.taState[f]||(t.taState[f]={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}});const d=t.taState[f];t.idx>d.lastIdx&&(d.lastIdx>=0&&(d.basisState={...d.currentBasisState},d.rangeState={...d.currentRangeState}),d.lastIdx=t.idx);const m=(S,T,N,R)=>{if(isNaN(N))return Object.assign(T,S),T.prevEma!==null?T.prevEma:NaN;let V=S.initCount,k=S.initSum,A=S.prevEma;if(V<R){if(k+=N,V++,T.initSum=k,T.initCount=V,T.prevEma=A,V===R){const $=k/R;return T.prevEma=$,$}return NaN}const O=2/(R+1),z=N*O+A*(1-O);return T.prevEma=z,T.initSum=k,T.initCount=V,z},x=m(d.basisState,d.currentBasisState,h,a),b=m(d.rangeState,d.currentRangeState,c,a);if(isNaN(x)||isNaN(b))return[[NaN,NaN,NaN]];const v=x+b*o,w=x-b*o;return[[t.precision(x),t.precision(v),t.precision(w)]]}}function Eh(t){return(e,i,r,n,s)=>{const a=y.from(i).get(0),o=y.from(r).get(0);let l=!0;typeof n=="string"?s=n:n!==void 0&&(l=y.from(n).get(0)),t.taState||(t.taState={});const 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}});const u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.basisState={...u.currentBasisState},u.rangeState={...u.currentRangeState}),u.lastIdx=t.idx);const p=(w,S,T,N)=>{if(isNaN(T))return Object.assign(S,w),S.prevEma!==null?S.prevEma:NaN;let R=w.initCount,V=w.initSum,k=w.prevEma;if(R<N){if(V+=T,R++,S.initSum=V,S.initCount=R,S.prevEma=k,R===N){const z=V/N;return S.prevEma=z,z}return NaN}const A=2/(N+1),O=T*A+k*(1-A);return S.prevEma=O,S.initSum=V,S.initCount=R,O};let h;const f=t.get(t.data.high,0),d=t.get(t.data.low,0);if(l){const w=t.get(t.data.close,1);isNaN(w)?h=NaN:h=Math.max(f-d,Math.abs(f-w),Math.abs(d-w))}else h=f-d;const m=y.from(e).get(0),x=p(u.basisState,u.currentBasisState,m,a),b=p(u.rangeState,u.currentRangeState,h,a);if(isNaN(x)||isNaN(b))return NaN;if(x===0)return t.precision(0);const v=2*b*o/x;return t.precision(v)}}function Nh(t){return(e,i,r,n)=>{const s=y.from(i).get(0),a=y.from(r).get(0);t.taState||(t.taState={});const o=n||`linreg_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=y.from(e).get(0),u=[...l.prevWindow];for(u.unshift(c);u.length>s;)u.pop();const p=l.prevCallCount+1;if(u.length<s&&(p>=s||t.idx>=s-1)){const S=y.from(e);for(;u.length<s;)u.push(S.get(u.length))}if(l.currentWindow=u,l.currentCallCount=p,u.length<s)return NaN;let h=0,f=0,d=0,m=0;const x=s;for(let S=0;S<s;S++){const T=s-1-S,N=u[S];h+=T,f+=N,d+=T*N,m+=T*T}const b=x*m-h*h;if(b===0)return NaN;const v=(x*d-h*f)/b,w=(f-v*h)/x+v*(s-1-a);return t.precision(w)}}function Ch(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.low);const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`lowest_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);const o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=a.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const h=y.from(e);for(;l.length<n;)l.push(h.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<n)return NaN;const u=l.filter(h=>!isNaN(h)&&h!==void 0);if(u.length===0)return NaN;const p=Math.min(...u);return t.precision(p)}}function Ih(t){return(e,i,r)=>{const n=y.from(i).get(0),s=y.from(e);if(t.idx<n-1)return NaN;let a=1/0,o=NaN;for(let l=0;l<n;l++){const c=s.get(l);isNaN(c)||(isNaN(o)||c<a)&&(a=c,o=-l)}return o}}function kh(t){return(e,i,r,n,s)=>{const a=y.from(i).get(0),o=y.from(r).get(0),l=y.from(n).get(0),c=s||`macd_${a}_${o}_${l}`,u=`${c}_fast`,p=`${c}_slow`,h=`${c}_signal`,f=t.pine.ta.ema(e,a,u),d=t.pine.ta.ema(e,o,p);let m=NaN;!isNaN(f)&&!isNaN(d)&&(m=f-d);let x=NaN;isNaN(m)||(x=t.pine.ta.ema(m,l,h));let b=NaN;return!isNaN(m)&&!isNaN(x)&&(b=m-x),[[t.precision(m),t.precision(x),t.precision(b)]]}}function Th(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`median_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);const o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=a.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const f=y.from(e);for(;l.length<n;)l.push(f.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<n)return NaN;const u=l.slice().sort((f,d)=>f-d),p=Math.floor(n/2),h=n%2===0?(u[p-1]+u[p])/2:u[p];return t.precision(h)}}function Ah(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`mfi_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});const 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);const 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;const u=isNaN(l)?NaN:o-l,p=c*(u<=0?0:o),h=c*(u>=0?0:o),f=[...a.prevUpperWindow],d=[...a.prevLowerWindow];let m=a.prevUpperSum,x=a.prevLowerSum;if(f.unshift(p),d.unshift(h),m+=p,x+=h,f.length<n)return a.currentUpperWindow=f,a.currentLowerWindow=d,a.currentUpperSum=m,a.currentLowerSum=x,NaN;if(f.length>n){const v=f.pop(),w=d.pop();m-=v,x-=w}if(a.currentUpperWindow=f,a.currentLowerWindow=d,a.currentUpperSum=m,a.currentLowerSum=x,x===0)return t.precision(100);if(m===0)return t.precision(0);const b=100-100/(1+m/x);return t.precision(b)}}function Ph(t){return(e,i,r)=>{const n=y.from(i).get(0),s=y.from(e);if(t.idx<n-1)return NaN;const a=new Map;for(let c=0;c<n;c++){const 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(const[c,u]of a.entries())u>l?(l=u,o=c):u===l&&c<o&&(o=c);return o}}function Dh(t){return(e,i,r)=>{const n=y.from(i).get(0);return t.pine.ta.change(e,n,r)}}function Mh(t){return e=>{t.taState||(t.taState={});const i=e||"nvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedNVI:1,tentativeNVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedNVI=r.tentativeNVI),r.lastIdx=t.idx);const n=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(n)?0:n,c=isNaN(s)?0:s,u=isNaN(a)?0:a,p=isNaN(o)?0:o;let h=r.committedNVI;if(!(l===0||c===0)&&u<p){const f=(l-c)/c;h=h+f*h}return r.tentativeNVI=h,t.precision(h)}}function Rh(t){return()=>{t.taState||(t.taState={});const e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});const i=t.taState[e];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.committedOBV=i.tentativeOBV),i.lastIdx=t.idx);const r=t.get(t.data.close,0),n=t.get(t.data.volume,0),s=t.get(t.data.close,1);if(isNaN(s))return i.tentativeOBV=0,t.precision(0);let a=i.committedOBV;return r>s?a+=n:r<s&&(a-=n),i.tentativeOBV=a,t.precision(a)}}function Oh(t){return(e,i,r)=>e instanceof y?i?new y(e.data,e.offset+i):e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new y(t.params[r],i||0)))}function $h(t){return(e,i,r,n)=>{const s=y.from(i).get(0),a=y.from(r).get(0),o=y.from(e);if(t.idx<s-1)return NaN;const l=[];for(let d=0;d<s;d++){const m=o.get(d);if(isNaN(m))return NaN;l.push(m)}l.sort((d,m)=>d-m);let c=a/100*s-.5;c<0&&(c=0),c>s-1&&(c=s-1);const u=Math.floor(c),p=Math.ceil(c);if(u===p)return t.precision(l[u]);const h=c-u,f=l[u]+h*(l[p]-l[u]);return t.precision(f)}}function Vh(t){return(e,i,r,n)=>{const s=y.from(i).get(0),a=y.from(r).get(0),o=y.from(e);if(t.idx<s-1)return NaN;const l=[];for(let u=0;u<s;u++){const p=o.get(u);isNaN(p)||l.push(p)}if(l.length===0)return NaN;l.sort((u,p)=>u-p);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 jh(t){return(e,i,r)=>{const n=y.from(i).get(0),s=y.from(e);if(t.idx<n)return NaN;const a=s.get(0);if(isNaN(a))return NaN;let o=0,l=0;for(let c=1;c<=n;c++){const u=s.get(c);isNaN(u)||(l++,u<=a&&o++)}return l===0?NaN:t.precision(o/l*100)}}function Lh(t,e,i){const r=new Array(t.length).fill(NaN);for(let n=e+i;n<t.length;n++){const s=t[n-i];let a=!0;for(let o=1;o<=e;o++)if(t[n-i-o]>=s){a=!1;break}if(a){for(let o=1;o<=i;o++)if(t[n-i+o]>=s){a=!1;break}}a&&(r[n]=s)}return r}function Bh(t){return(e,i,r,n)=>{typeof r=="string"&&(r=i,i=e,e=t.data.high);const s=y.from(i).get(0),a=y.from(r).get(0),o=y.from(e).toArray(),l=Lh(o,s,a),c=t.idx;return t.precision(l[c])}}function Fh(t,e,i){const r=new Array(t.length).fill(NaN);for(let n=e+i;n<t.length;n++){const s=t[n-i];let a=!0;for(let o=1;o<=e;o++)if(t[n-i-o]<=s){a=!1;break}if(a){for(let o=1;o<=i;o++)if(t[n-i+o]<=s){a=!1;break}}a&&(r[n]=s)}return r}function Wh(t){return(e,i,r,n)=>{typeof r=="string"&&(r=i,i=e,e=t.data.low);const s=y.from(i).get(0),a=y.from(r).get(0),o=y.from(e).toArray(),l=Fh(o,s,a),c=t.idx;return t.precision(l[c])}}function Uh(t){return e=>{t.taState||(t.taState={});const i=e||"pvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedPVI:1,tentativePVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedPVI=r.tentativePVI),r.lastIdx=t.idx);const n=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(n)?0:n,c=isNaN(s)?0:s,u=isNaN(a)?0:a,p=isNaN(o)?0:o;let h=r.committedPVI;if(!(l===0||c===0)&&u>p){const f=(l-c)/c;h=h+f*h}return r.tentativePVI=h,t.precision(h)}}function qh(t){return e=>{t.taState||(t.taState={});const i=e||"pvt";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0);let o=r.prevCumulativeSum;if(!isNaN(n)&&!isNaN(s)&&!isNaN(a)&&s!==0){const l=(n-s)/s*a;o+=l}return r.currentCumulativeSum=o,t.precision(o)}}function zh(t){return(e,i,r)=>{const n=t.pine.ta.highest(e,i,(r||"range")+"_h"),s=t.pine.ta.lowest(e,i,(r||"range")+"_l");return isNaN(n)||isNaN(s)?NaN:t.precision(n-s)}}function Kh(t){return(e,i,r)=>{const n=y.from(i).get(0),s=y.from(e);for(let a=0;a<n;a++){const o=s.get(a),l=s.get(a+1);if(isNaN(o)||isNaN(l)||o<=l)return!1}return!0}}function Hh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`rma_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});const 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);const o=y.from(e).get(0)||0;let l=a.prevInitCount,c=a.prevInitSum,u=a.prevRma;if(l<n){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===n){const f=c/n;return a.currentRma=f,t.precision(f)}return NaN}const p=1/n,h=o*p+u*(1-p);return a.currentRma=h,t.precision(h)}}function Gh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`roc_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);const o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>n+1;)l.pop();const c=a.prevCallCount+1;if(l.length<n+1&&(c>=n+1||t.idx>=n)){const h=y.from(e);for(;l.length<n+1;)l.push(h.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=n)return NaN;const u=l[n],p=(o-u)/u*100;return t.precision(p)}}function Yh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`rsi_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});const 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);const o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;const 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;const p=[...a.prevInitGains],h=[...a.prevInitLosses],f=o-l,d=f>0?f:0,m=f<0?-f:0;if(p.length<n){if(p.push(d),h.push(m),a.currentInitGains=p,a.currentInitLosses=h,a.currentPrevValue=o,p.length===n){c=p.reduce((v,w)=>v+w,0)/n,u=h.reduce((v,w)=>v+w,0)/n,a.currentAvgGain=c,a.currentAvgLoss=u;const b=u===0?100:100-100/(1+c/u);return t.precision(b)}return NaN}c=(c*(n-1)+d)/n,u=(u*(n-1)+m)/n,a.currentAvgGain=c,a.currentAvgLoss=u,a.currentPrevValue=o;const x=u===0?100:100-100/(1+c/u);return t.precision(x)}}function Xh(t){return(e,i,r,n)=>{const s=y.from(e).get(0),a=y.from(i).get(0),o=y.from(r).get(0);t.taState||(t.taState={});const l=n||`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});const 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,p=c.prevMaxMin,h=c.prevAcceleration,f=c.prevIsBelow,d=c.prevBarIndex;const m=t.get(t.data.high,0),x=t.get(t.data.low,0),b=t.get(t.data.close,0),v=t.get(t.data.close,1),w=t.get(t.data.high,1),S=t.get(t.data.low,1),T=t.get(t.data.high,2),N=t.get(t.data.low,2);if(isNaN(m)||isNaN(x)||isNaN(b))return c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=f,c.currentBarIndex=d,NaN;let R=!1;return d===1&&(b>v?(f=!0,p=m,u=S):(f=!1,p=x,u=w),R=!0,h=s),d>=1&&(u=u+h*(p-u),f?u>x&&(R=!0,f=!1,u=Math.max(m,p),p=x,h=s):u<m&&(R=!0,f=!0,u=Math.min(x,p),p=m,h=s),R||(f?m>p&&(p=m,h=Math.min(h+a,o)):x<p&&(p=x,h=Math.min(h+a,o))),f?(u=Math.min(u,S),d>1&&(u=Math.min(u,N))):(u=Math.max(u,w),d>1&&(u=Math.max(u,T)))),d++,c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=f,c.currentBarIndex=d,d<=1?NaN:t.precision(u)}}function Zh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`sma_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const 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);const o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=a.prevCallCount+1;let u=!1;if(l.length<n&&(c>=n||t.idx>=n-1)){const m=y.from(e);for(;l.length<n;)l.push(m.get(l.length));u=!0}let p;const h=o==null||Number.isNaN(o);let f=!Number.isNaN(a.prevSum)&&!h&&!u;if(f){let m=a.prevSum+o;if(a.prevWindow.length>=n){const x=a.prevWindow[a.prevWindow.length-1];x==null||Number.isNaN(x)?f=!1:m-=x}f&&(p=m)}if(!f){p=0;let m=!1;for(const x of l){if(x==null||Number.isNaN(x)){m=!0;break}p+=x}m&&(p=NaN)}if(a.currentWindow=l,a.currentSum=p,a.currentCallCount=c,l.length<n)return NaN;const d=p/n;return t.precision(d)}}function Qh(t){return(e,i,r=!0,n)=>{const s=y.from(i).get(0),a=y.from(r).get(0);t.taState||(t.taState={});const o=n||`stdev_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const 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);const c=y.from(e).get(0);if(c==null||isNaN(c))return NaN;const u=[...l.prevWindow];let p=l.prevSum;for(u.unshift(c),p+=c;u.length>s;){const b=u.pop();p-=b}const h=l.prevCallCount+1;if(u.length<s&&(h>=s||t.idx>=s-1)){const b=y.from(e);for(;u.length<s;){const v=b.get(u.length);if(v==null||isNaN(v))break;u.push(v),p+=v}}if(l.currentWindow=u,l.currentSum=p,l.currentCallCount=h,u.length<s)return NaN;const f=p/s;let d=0;for(let b=0;b<s;b++)d+=Math.pow(u[b]-f,2);const m=a?s:s-1,x=Math.sqrt(d/m);return t.precision(x)}}function Jh(t){return(e,i,r,n,s)=>{const a=y.from(n).get(0);t.taState||(t.taState={});const o=s||`stoch_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow]),l.lastIdx=t.idx);const c=y.from(e).get(0),u=y.from(i).get(0),p=y.from(r).get(0);if(isNaN(c)||isNaN(u)||isNaN(p))return l.currentHighWindow=[...l.prevHighWindow],l.currentLowWindow=[...l.prevLowWindow],NaN;const h=[...l.prevHighWindow],f=[...l.prevLowWindow];if(h.unshift(u),f.unshift(p),h.length>a&&(h.pop(),f.pop()),l.currentHighWindow=h,l.currentLowWindow=f,h.length<a)return NaN;let d=h[0],m=f[0];for(let v=1;v<a;v++)h[v]>d&&(d=h[v]),f[v]<m&&(m=f[v]);const x=d-m;if(x===0)return NaN;const b=100*(c-m)/x;return t.precision(b)}}function ep(t){return(e,i,r)=>{const n=y.from(e).get(0),s=y.from(i).get(0);t.taState||(t.taState={});const a=r||`supertrend_${n}_${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});const 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);const 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]];const p=(l+c)/2,h=t.idx>0?t.get(t.data.close,1):NaN;let f;isNaN(h)?f=l-c:f=Math.max(l-c,Math.abs(l-h),Math.abs(c-h));let d=o.prevAtrCount,m=o.prevTrSum,x=o.prevAtrValue;d++,d<=s?(m+=f,d===s&&(x=m/s)):x=(x*(s-1)+f)/s;const b=x;if(o.currentAtrCount=d,o.currentTrSum=m,o.currentAtrValue=x,isNaN(b))return[[NaN,NaN]];let v=p+n*b,w=p-n*b;const S=isNaN(o.prevLowerBand)?0:o.prevLowerBand,T=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||w>S||h<S||(w=S),isNaN(o.prevUpperBand)||v<T||h>T||(v=T);let N,R;const V=o.prevSuperTrend;return d===s?N=1:V===o.prevUpperBand?N=u>v?-1:1:N=u<w?1:-1,R=N===-1?w:v,o.currentLowerBand=w,o.currentUpperBand=v,o.currentSuperTrend=R,o.currentDirection=N,[[t.precision(R),N]]}}function tp(t){return(e,i)=>{const r=[1,2,2,1],n=6;t.taState||(t.taState={});const s=i||"swma";t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],currentWindow:[]});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow]),a.lastIdx=t.idx);const 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){const 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+=r[u]*l[3-u];return c/=n,t.precision(c)}}function ip(t){return(e,i)=>{let r=!0;typeof e=="string"||e!==void 0&&(r=y.from(e).get(0));const n=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.close,1);if(isNaN(a))return r?t.precision(n-s):NaN;const o=Math.max(n-s,Math.abs(n-a),Math.abs(s-a));return t.precision(o)}}function rp(t){return(e,i,r,n)=>{const s=y.from(i).get(0),a=y.from(r).get(0);t.taState||(t.taState={});const o=n||`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});const 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);const c=y.from(e).get(0);if(isNaN(c))return NaN;const u=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(u))return NaN;const p=Math.abs(u),h=2/(a+1),f=2/(s+1),d=2/(a+1),m=2/(s+1);let x=l.prevEma1PcCount,b=l.prevEma1PcSum,v=l.prevEma1PcValue;x++,x<=a?(b+=u,x===a&&(v=b/a)):v=u*h+v*(1-h);let w=l.prevEma1AbsCount,S=l.prevEma1AbsSum,T=l.prevEma1AbsValue;if(w++,w<=a?(S+=p,w===a&&(T=S/a)):T=p*d+T*(1-d),isNaN(v)||isNaN(T))return l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=w,l.currentEma1AbsSum=S,l.currentEma1AbsValue=T,NaN;let N=l.prevEma2PcCount,R=l.prevEma2PcSum,V=l.prevEma2PcValue;N++,N<=s?(R+=v,N===s&&(V=R/s)):V=v*f+V*(1-f);let k=l.prevEma2AbsCount,A=l.prevEma2AbsSum,O=l.prevEma2AbsValue;if(k++,k<=s?(A+=T,k===s&&(O=A/s)):O=T*m+O*(1-m),l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=w,l.currentEma1AbsSum=S,l.currentEma1AbsValue=T,l.currentEma2PcCount=N,l.currentEma2PcSum=R,l.currentEma2PcValue=V,l.currentEma2AbsCount=k,l.currentEma2AbsSum=A,l.currentEma2AbsValue=O,isNaN(V)||isNaN(O))return NaN;if(O===0)return t.precision(0);const z=V/O;return t.precision(z)}}function np(t){return(e,i,r,n)=>{t.taState||(t.taState={});const s=n||"valuewhen";t.taState[s]||(t.taState[s]={lastIdx:-1,prevValues:[],currentValues:[]});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevValues=[...a.currentValues]),a.lastIdx=t.idx);const o=y.from(e).get(0),l=y.from(i).get(0),c=y.from(r).get(0),u=[...a.prevValues];if(o&&u.push(l),a.currentValues=u,isNaN(c)||c<0)return NaN;const p=u.length-1-c;if(p<0)return NaN;const h=u[p];return typeof h=="number"?t.precision(h):h}}function sp(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`variance_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);const o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=a.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const d=y.from(e);for(;l.length<n;)l.push(d.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<n)return NaN;let u=0,p=0;for(let d=0;d<n;d++)u+=l[d],p+=l[d]*l[d];const h=u/n,f=p/n-h*h;return t.precision(f)}}function ap(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"vwap";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentLastSessionDate:null});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativePV=n.currentCumulativePV,n.prevCumulativeVolume=n.currentCumulativeVolume,n.prevLastSessionDate=n.currentLastSessionDate),n.lastIdx=t.idx);const 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=Rt(o,l),u=`${c.year}-${String(c.month).padStart(2,"0")}-${String(c.day).padStart(2,"0")}`;let p=n.prevCumulativePV,h=n.prevCumulativeVolume,f=n.prevLastSessionDate;if(f!==u&&(p=0,h=0,f=u),p+=s*a,h+=a,n.currentCumulativePV=p,n.currentCumulativeVolume=h,n.currentLastSessionDate=f,h===0)return NaN;const d=p/h;return t.precision(d)}}function op(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`vwma_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevVolumeWindow:[],currentWindow:[],currentVolumeWindow:[]});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevVolumeWindow=[...a.currentVolumeWindow]),a.lastIdx=t.idx);const 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>n;)c.pop(),u.pop();if(c.length<n&&t.idx>=n-1){const d=y.from(e),m=y.from(t.data.volume);for(;c.length<n;)c.push(d.get(c.length)),u.push(m.get(u.length))}if(a.currentWindow=c,a.currentVolumeWindow=u,c.length<n)return NaN;let p=0,h=0;for(let d=0;d<n;d++)p+=c[d]*u[d],h+=u[d];const f=p/h;return t.precision(f)}}function lp(t){return e=>{t.taState||(t.taState={});const i=e||"wad";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=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(n)||isNaN(s)||isNaN(a))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=0;if(!isNaN(o)){const u=Math.max(s,o),p=Math.min(a,o),h=n-o;h>0?l=n-p:h<0&&(l=n-u)}const c=r.prevCumulativeSum+l;return r.currentCumulativeSum=c,t.precision(c)}}function cp(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const s=r||`wma_${n}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);const o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=a.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const f=y.from(e);for(;l.length<n;)l.push(f.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<n)return NaN;let u=0,p=0;for(let f=0;f<n;f++){const d=n-f;u+=l[f]*d,p+=d}const h=u/p;return t.precision(h)}}function up(t){return(e,i)=>{const r=y.from(e).get(0);t.taState||(t.taState={});const n=i||`wpr_${r}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const s=t.taState[n];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevHighWindow=[...s.currentHighWindow],s.prevLowWindow=[...s.currentLowWindow]),s.lastIdx=t.idx);const 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;const c=[...s.prevHighWindow],u=[...s.prevLowWindow];if(c.unshift(a),u.unshift(o),c.length>r&&(c.pop(),u.pop()),s.currentHighWindow=c,s.currentLowWindow=u,c.length<r)return NaN;let p=c[0],h=u[0];for(let m=1;m<r;m++)c[m]>p&&(p=c[m]),u[m]<h&&(h=u[m]);const f=p-h;if(f===0)return t.precision(0);const d=(p-l)/f*-100;return t.precision(d)}}function hp(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.open,0),n=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(s)||isNaN(a))return NaN;const o=n-s;if(o===0)return t.precision(0);const l=(i-r)/o*a;return t.precision(l)}}var pp=Object.defineProperty,fp=(t,e,i)=>e in t?pp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,P=(t,e,i)=>fp(t,typeof e!="symbol"?e+"":e,i);const dp={accdist:eh,alma:th,atr:ih,barssince:rh,bb:nh,bbw:sh,cci:ah,change:oh,cmo:lh,cog:ch,correlation:uh,cross:hh,crossover:ph,crossunder:fh,cum:dh,dev:mh,dmi:yh,ema:_h,falling:gh,highest:xh,highestbars:bh,hma:vh,iii:wh,kc:Sh,kcw:Eh,linreg:Nh,lowest:Ch,lowestbars:Ih,macd:kh,median:Th,mfi:Ah,mode:Ph,mom:Dh,nvi:Mh,obv:Rh,param:Oh,percentile_linear_interpolation:$h,percentile_nearest_rank:Vh,percentrank:jh,pivothigh:Bh,pivotlow:Wh,pvi:Uh,pvt:qh,range:zh,rising:Kh,rma:Hh,roc:Gh,rsi:Yh,sar:Xh,sma:Zh,stdev:Qh,stoch:Jh,supertrend:ep,swma:tp,tr:ip,tsi:rp,valuewhen:np,variance:sp,vwap:ap,vwma:op,wad:lp,wma:cp,wpr:up,wvad:hp};class mp{constructor(e){this.context=e,P(this,"accdist"),P(this,"alma"),P(this,"atr"),P(this,"barssince"),P(this,"bb"),P(this,"bbw"),P(this,"cci"),P(this,"change"),P(this,"cmo"),P(this,"cog"),P(this,"correlation"),P(this,"cross"),P(this,"crossover"),P(this,"crossunder"),P(this,"cum"),P(this,"dev"),P(this,"dmi"),P(this,"ema"),P(this,"falling"),P(this,"highest"),P(this,"highestbars"),P(this,"hma"),P(this,"iii"),P(this,"kc"),P(this,"kcw"),P(this,"linreg"),P(this,"lowest"),P(this,"lowestbars"),P(this,"macd"),P(this,"median"),P(this,"mfi"),P(this,"mode"),P(this,"mom"),P(this,"nvi"),P(this,"obv"),P(this,"param"),P(this,"percentile_linear_interpolation"),P(this,"percentile_nearest_rank"),P(this,"percentrank"),P(this,"pivothigh"),P(this,"pivotlow"),P(this,"pvi"),P(this,"pvt"),P(this,"range"),P(this,"rising"),P(this,"rma"),P(this,"roc"),P(this,"rsi"),P(this,"sar"),P(this,"sma"),P(this,"stdev"),P(this,"stoch"),P(this,"supertrend"),P(this,"swma"),P(this,"tr"),P(this,"tsi"),P(this,"valuewhen"),P(this,"variance"),P(this,"vwap"),P(this,"vwma"),P(this,"wad"),P(this,"wma"),P(this,"wpr"),P(this,"wvad"),Object.entries(dp).forEach(([i,r])=>{this[i]=r(e)})}}function yp(t){if(t.length===0)return{};if(typeof t[0]=="object"&&t[0]!==null)return t[0];const e={};typeof t[0]=="string"&&(e.title=t[0]);let i=null;for(let r=1;r<t.length;r++){const n=t[r];typeof n=="string"?e.shorttitle===void 0&&(e.shorttitle=n):typeof n=="object"&&n!==null&&(i=n)}return i&&Object.assign(e,i),e}function ci(t,e,i){if(!i||i<=0||!Number.isFinite(t)||t===e)return t;const r=t/i,n=1e-9;return t>e?Math.ceil(r-n)*i:Math.floor(r+n)*i}function Vr(t,e,i,r){return Math.abs(t)*e*r*i/100}function _p(t,e){const i=t.strategy,r=t.pine?.syminfo?.pointvalue??1;let n=0;for(const s of i.opentrades){const a=Math.sign(s.size)===1?e-s.entry_price:s.entry_price-e;n+=a*Math.abs(s.size)*r}return i.initial_capital+i.netprofit+n}function gp(t,e){const i=t.strategy,r=t.pine?.syminfo?.pointvalue??1;let n=0;for(const s of i.opentrades){const a=Math.sign(s.size)===1?i.config.margin_long??100:i.config.margin_short??100;n+=Vr(s.size,e,a,r)}return n}function jr(t,e,i,r){const n=t.strategy;let s=n.config.default_qty_type||"fixed",a=n.config.default_qty_value||1;typeof s=="function"&&(s=s()),typeof a=="function"&&(a=a());const 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/r;break;case"percent_of_equity":{c=n.equity*a/100/r;break}default:c=a}return l(c)}function xp(t){if(!t.strategy)return;const e=t.strategy,{pending_orders:i}=e,r=y.from(t.data.open).get(0),n=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(const c of e.opentrades){const u=Math.abs(c.size),p=c.size>0,h=c.commission??0,f=p?(c.entry_price-s)*u*l:(n-c.entry_price)*u*l,d=p?(n-c.entry_price)*u*l:(c.entry_price-s)*u*l,m=Math.max(0,f)+h,x=Math.max(0,d-h);m>(c.max_drawdown??0)&&(c.max_drawdown=m),x>(c.max_runup??0)&&(c.max_runup=x)}Wi(t,r);for(const c of i){if(c.status!=="pending"||(c.category??"entry")==="exit"||c.bar>=t.idx)continue;let u=!1,p=r;switch(c.type){case"market":u=!0,p=r;break;case"limit":if(c.limit!==void 0){const h=Jt(c.direction);(h===1&&s<=c.limit||h===-1&&n>=c.limit)&&(u=!0,p=c.limit)}break;case"stop":if(c.stop!==void 0){const h=Jt(c.direction);(h===1&&n>=c.stop||h===-1&&s<=c.stop)&&(u=!0,p=c.stop)}break}if(u){if(vp(e,c)){c.status="cancelled";continue}const h=Jt(c.direction);p=wr(t,h,p);const f=h===1?e.config.margin_long??100:e.config.margin_short??100;{const d=e.position_size,m=Math.sign(d),x=m!==0&&m!==h,b=x?Math.max(0,c.qty-Math.abs(d)):c.qty;if(b>0){const v=t.pine?.syminfo?.pointvalue??1;let w=0;m===h&&(w=gp(t,r));const S=e.equity-w;if(Vr(b,p,f,v)>S){const T=Math.min(Math.abs(d),c.qty);x&&T>0?(gi(t,T,p,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=p,c.fill_bar=t.idx,c.fill_time=o):c.status="cancelled";continue}}}Sp(t,c,p,o),c.status="filled",c.fill_price=p,c.fill_bar=t.idx,c.fill_time=o}}e.pending_orders=i.filter(c=>c.status==="pending"),Wi(t,a),kp(t)}function Jt(t){return typeof t=="number"?t:t==="long"?1:t==="short"?-1:0}function vr(t,e,i,r){const n=e.config.commission_type??"percent",s=e.config.commission_value??0;if(!s||s===0)return 0;const a=t.pine?.syminfo?.pointvalue??1;switch(n){case"percent":return Math.abs(i)*r*a*(s/100);case"cash_per_contract":return Math.abs(i)*s;case"cash_per_order":return s;default:return 0}}function wr(t,e,i){const r=t.strategy.config.slippage??0;if(!r||r===0)return i;const n=t.pine?.syminfo?.mintick??.01,s=r*n;return e===1?i+s:i-s}function Is(t){const 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 bp(t,e){const i=t.config.pyramiding??1;let r=0;for(const n of t.opentrades)Math.sign(n.size)===e&&r++;return r>=i}function vp(t,e){if(t.risk_halted)return!0;const i=t.risk_rules,r=e.direction;if(i.allow_entry_in&&(i.allow_entry_in==="long"&&r===-1||i.allow_entry_in==="short"&&r===1))return!0;if(i.max_position_size!==void 0){const n=t.position_size+r*e.qty;if(Math.abs(n)>i.max_position_size)return!0}return!1}function wp(t){if(t.risk_halted)return;const e=t.risk_rules;if(e.max_drawdown){const i=e.max_drawdown.type==="percent_of_equity"?e.max_drawdown.value/100*t.equity_peak:e.max_drawdown.value;if(t.max_drawdown>=i){t.risk_halted=!0;return}}if(e.max_intraday_loss){const i=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>=i){t.risk_halted=!0;return}}if(e.max_cons_loss_days){let i=0;for(let r=t.closedtrades.length-1;r>=0&&(t.closedtrades[r].profit??0)<0;r--)i++;i>=e.max_cons_loss_days.count&&(t.risk_halted=!0)}}function hn(t,e,i,r,n,s,a,o){const l=t.strategy,c=l.opentrades.length+l.closedtrades.length,u=l.config.commission_type??"percent",p=o&&u==="cash_per_order",h=vr(t,l,r,n),f=p?h/2:h,d={id:`trade_${c}`,entry_id:e,entry_comment:a??e,entry_price:n,entry_bar_index:t.idx,entry_time:s,size:i*r,commission:f,max_drawdown:0,max_runup:0,status:"open"};l.opentrades.push(d),f>0&&(l.netprofit-=f,l.grossloss+=f);const m=y.from(t.data.high).get(0),x=y.from(t.data.low).get(0),b=t.pine?.syminfo?.mintick??.01;let v=i===1?x:m,w=i===1?m:x;for(const k of l.pending_orders){if((k.category??"entry")!=="exit"||k.from_entry&&k.from_entry!==e)continue;let A;k.stop!==void 0?A=k.stop:k.loss!==void 0&&(A=i===1?n-k.loss*b:n+k.loss*b);let O;k.limit!==void 0?O=k.limit:k.profit!==void 0&&(O=i===1?n+k.profit*b:n-k.profit*b),i===1?(A!==void 0&&A>v&&(v=A),O!==void 0&&O<w&&(w=O)):(A!==void 0&&A<v&&(v=A),O!==void 0&&O>w&&(w=O))}const S=t.pine?.syminfo?.pointvalue??1,T=i===1?(n-v)*r*S:(v-n)*r*S,N=i===1?(w-n)*r*S:(n-w)*r*S;d.max_drawdown=Math.max(0,T)+f,d.max_runup=Math.max(0,N-f);const R=l.position_size,V=R+d.size;if(R===0)l.position_size=V,l.position_avg_price=n,l.position_entry_name=e;else if(Math.sign(R)===Math.sign(V)){const k=Math.abs(R)*l.position_avg_price+r*n,A=Math.abs(V);l.position_avg_price=k/A,l.position_size=V}Is(l)}function Sp(t,e,i,r){const n=t.strategy,s=Jt(e.direction),a=n.position_size,o=Math.sign(a);if(o===1&&s===-1||o===-1&&s===1){const l=Math.min(Math.abs(a),e.qty),c=e.qty-l,u=c>0;gi(t,l,i,r,{exitId:e.id,exitComment:e.comment,isImplicitReversal:u}),c>0&&hn(t,e.id,s,c,i,r,e.comment,!0)}else hn(t,e.id,s,e.qty,i,r,e.comment)}function gi(t,e,i,r,n){const s=t.strategy,a=t.pine?.syminfo?.pointvalue??1;let o=e;const l=[...s.opentrades];s.opentrades=[];for(const h of l){if(o<=0){s.opentrades.push(h);continue}const f=Math.abs(h.size),d=Math.min(f,o),m=Math.sign(h.size);if(d>=f){h.status="closed",h.exit_price=i,h.exit_bar_index=t.idx,h.exit_time=r;const x=(m===1?i-h.entry_price:h.entry_price-i)*f*a,b=h.commission??0,v=s.config.commission_type??"percent",w=n?.isImplicitReversal&&v==="cash_per_order",S=vr(t,s,f,i),T=w?S/2:S;h.commission=b+T,n?.triggerKind==="loss"&&(h.max_runup=0),n?.triggerKind==="profit"&&(h.max_drawdown=b),n?.exitId!==void 0&&(h.exit_id=n.exitId),n?.exitComment!==void 0&&(h.exit_comment=n.exitComment),h.profit=x-h.commission;const N=x-T;s.netprofit+=N,s.grossloss-=b,h.profit>0?(s.grossprofit+=h.profit,s.wintrades++,s.wintrades_total_profit+=h.profit):h.profit<0?(s.grossloss+=Math.abs(h.profit),s.losstrades++,s.losstrades_total_loss+=Math.abs(h.profit)):s.eventrades++,s.closedtrades.push(h),o-=d}else{const x=s.opentrades.length+s.closedtrades.length,b=(m===1?i-h.entry_price:h.entry_price-i)*d*a,v=(h.commission??0)*(d/f),w=s.config.commission_type??"percent",S=n?.isImplicitReversal&&w==="cash_per_order",T=vr(t,s,d,i),N=S?T/2:T,R=v+N,V={...h,id:`trade_${x}`,size:m*d,status:"closed",exit_price:i,exit_bar_index:t.idx,exit_time:r,commission:R,profit:b-R,exit_id:n?.exitId??h.exit_id,exit_comment:n?.exitComment??h.exit_comment};n?.triggerKind==="loss"&&(V.max_runup=0),n?.triggerKind==="profit"&&(V.max_drawdown=v);const k=b-N;s.netprofit+=k,s.grossloss-=v,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),h.size=m*(f-d),h.commission=(h.commission??0)-v,s.opentrades.push(h),o=0}}wp(s);const c=s.position_size,u=Math.sign(c)*e,p=c-u;if(s.position_size=p,Is(s),p===0)s.position_avg_price=NaN,s.position_entry_name="";else if(s.opentrades.length>0){let h=0,f=0;for(const d of s.opentrades){const m=Math.abs(d.size);h+=m*d.entry_price,f+=m}s.position_avg_price=h/f,s.position_entry_name=s.opentrades[0].entry_id}}function Wi(t,e){const i=t.strategy,r=t.pine?.syminfo?.pointvalue??1;let n=0;for(const s of i.opentrades){const a=Math.abs(s.size),o=Math.sign(s.size)===1?e-s.entry_price:s.entry_price-e;n+=o*a*r}i.openprofit=n,i.equity=i.initial_capital+i.netprofit+n}function Ep(t,e,i){const r=t.strategy,n=t.pine?.syminfo?.pointvalue??1,s=r.initial_capital+r.netprofit;let a=0;for(const d of r.opentrades)a+=d.commission??0;const o=s+a;o>r.equity_peak&&(r.equity_peak=o),s<r.equity_trough&&(r.equity_trough=s);const l=r.position_size,c=r.position_avg_price;let u=0,p=0;if(l!==0&&Number.isFinite(c)){const d=l>0?i:e,m=l>0?e:i;u=l*(c-d)*n,p=l*(m-c)*n}const h=r.equity_peak-s+u;if(h>r.max_drawdown&&(r.max_drawdown=h,r.equity_at_drawdown_peak=r.equity_peak,r.equity_peak>0)){const d=100*h/r.equity_peak;d>r.max_drawdown_percent_value&&(r.max_drawdown_percent_value=d)}const f=s-r.equity_trough+p;if(f>r.max_runup&&(r.max_runup=f,r.equity_at_runup_peak=s+p,r.equity_at_runup_peak>0)){const d=100*f/r.equity_at_runup_peak;d>r.max_runup_percent_value&&(r.max_runup_percent_value=d)}}function pn(t,e,i,r,n,s){const a=t.strategy;if(!e||e===""){gi(t,i,r,n,s);return}const o=[],l=[];for(const p of a.opentrades)p.entry_id===e?o.push(p):l.push(p);const c=o.reduce((p,h)=>p+Math.abs(h.size),0);if(c===0)return;const u=Math.min(i,c);a.opentrades=[...o,...l],gi(t,u,r,n,s)}function Np(t){if(!t.strategy)return;const e=t.strategy;if(e.pending_orders.length===0)return;const i=y.from(t.data.open).get(0),r=y.from(t.data.high).get(0),n=y.from(t.data.low).get(0),s=y.from(t.data.close).get(0),a=y.from(t.data.openTime).get(0),o=t.pine?.syminfo?.mintick??.01;for(const l of e.pending_orders){if(l.status!=="pending"||(l.category??"entry")!=="exit")continue;let c=e.opentrades.filter(A=>!l.from_entry||A.entry_id===l.from_entry);if(l._intended_trade_ids){const A=new Set(l._intended_trade_ids);c=c.filter(O=>A.has(O.id))}if(c.length===0){l.status="cancelled";continue}const u=c.reduce((A,O)=>A+Math.abs(O.size),0),p=Math.sign(c[0].size);if(l.type==="market"&&l.profit===void 0&&l.loss===void 0&&l.limit===void 0&&l.stop===void 0&&l.trail_price===void 0&&l.trail_points===void 0){if(l.bar>=t.idx)continue;let A=l.immediately?s:i;A=wr(t,-p,A);let O=u;l.qty&&l.qty>0?O=Math.min(l.qty,u):l.qty_percent&&l.qty_percent>0&&(O=u*(l.qty_percent/100)),pn(t,l.from_entry,O,A,a,{exitId:l.id,exitComment:l.comment}),l.status="filled",l.fill_price=A,l.fill_bar=t.idx,l.fill_time=a;continue}let h=0;for(const A of c)h+=Math.abs(A.size)*A.entry_price;const f=h/u,d=p===1;let m;l.limit!==void 0?m=l.limit:l.profit!==void 0&&(m=d?f+l.profit*o:f-l.profit*o);let x;l.stop!==void 0?x=l.stop:l.loss!==void 0&&(x=d?f-l.loss*o:f+l.loss*o),l._isPersistent||(x!==void 0&&((d?x<f:x>f)||(x=void 0)),m!==void 0&&((d?m>f:m<f)||(m=void 0))),l._attachedAtReversal&&!l._isPersistent&&(l.limit!==void 0&&(m=void 0),l.stop!==void 0&&(x=void 0));let b=!1;if(!l.trail_armed&&(l.trail_price!==void 0||l.trail_points!==void 0)){let A;l.trail_price!==void 0?A=l.trail_price:l.trail_points!==void 0&&(A=d?f+l.trail_points*o:f-l.trail_points*o),A!==void 0&&(d?r>=A:n<=A)&&(l.trail_armed=!0,l.trail_peak=d?r:n,b=!0)}const v=Math.abs(r-i)<=Math.abs(i-n),w=d?v:!v;let S=!1,T=NaN,N=null;const R=()=>{S||x===void 0||(d?n<=x:r>=x)&&(S=!0,T=(d?i<=x:i>=x)?i:x,N="loss")},V=()=>{if(S||!l.trail_armed||l.trail_offset===void 0)return;const A=()=>{d?l.trail_peak=Math.max(l.trail_peak??-1/0,r):l.trail_peak=Math.min(l.trail_peak??1/0,n)},O=()=>d?l.trail_peak-l.trail_offset*o:l.trail_peak+l.trail_offset*o;if(b){const z=O();w?(d?n<=z:r>=z)&&(S=!0,T=z,N="trailing"):(d?s<z:s>z)&&(S=!0,T=z,N="trailing");return}if(w){A();const z=O();(d?n<=z:r>=z)&&(S=!0,T=z,N="trailing")}else{const z=O();if(d?n<=z:r>=z){S=!0,T=z,N="trailing";return}A();const $=O();(d?s<$:s>$)&&(S=!0,T=$,N="trailing")}},k=()=>{S||m===void 0||(d?r>=m:n<=m)&&(S=!0,T=(d?i>=m:i<=m)?i:m,N="profit")};if(w?(k(),R(),V()):(R(),V(),k()),S){const A=wr(t,-p,T);let O=u;l.qty&&l.qty>0?O=Math.min(l.qty,u):l.qty_percent&&l.qty_percent>0&&(O=u*(l.qty_percent/100));const z=N==="profit"?l.comment_profit??l.comment:N==="loss"?l.comment_loss??l.comment:N==="trailing"?l.comment_trailing??l.comment:l.comment;pn(t,l.from_entry,O,A,a,{triggerKind:N,exitId:l.id,exitComment:z}),l.status="filled",l.fill_price=A,l.fill_bar=t.idx,l.fill_time=a}}e.pending_orders=e.pending_orders.filter(l=>l.status==="pending"),Wi(t,s)}function Cp(t){const e=t.strategy;if(!e||e.opentrades.length===0)return;const i=Math.sign(e.position_size);if(i===0)return;const r=i===1?e.config.margin_long??100:e.config.margin_short??100,n=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=y.from(t.data.openTime).get(0),o=t.pine?.syminfo?.pointvalue??1,l=i===1?s:n,c=Math.abs(e.position_size),u=_p(t,l),p=Vr(c,l,r,o);if(u<p){const h=p-u,f=Math.floor(h/(l*o)*1e5)/1e5,d=Math.min(c,4*f);gi(t,d,l,a,{exitId:"Margin call",exitComment:"Margin call"})}}function Ip(t){if(!t.strategy)return;const e=y.from(t.data.high).get(0),i=y.from(t.data.low).get(0),r=y.from(t.data.close).get(0);Wi(t,r),Ep(t,e,i)}function kp(t){t.strategy}function Tp(t,e){const i={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??{}},r=i.initial_capital;t.strategy={config:i,opentrades:[],closedtrades:[],pending_orders:[],position_size:0,position_avg_price:NaN,position_entry_name:"",initial_capital:r,account_currency:i.currency||"USD",equity:r,netprofit:0,grossprofit:0,grossloss:0,openprofit:0,max_drawdown:0,max_runup:0,equity_peak:r,equity_trough:r,equity_at_runup_peak:r,equity_at_drawdown_peak:r,max_drawdown_percent_value:0,max_runup_percent_value:0,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 Ap(t){return(...e)=>{const i=yp(e);return t.strategy?t.strategy.config={...t.strategy.config,...i,...t._propOverrides??{}}:Tp(t,i),t.strategy.config}}const Pp=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],Dp={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 Mp(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.order() called before strategy() declaration");const i=te(e,Pp,Dp),r=v=>v==null||typeof v=="string"||typeof v=="number"||typeof v=="boolean"?v:typeof v=="function"?v():v instanceof y?v.get(0):Array.isArray(v)?v[v.length-1]:typeof v=="object"&&v.get!==void 0?v.get(0):v,n=r(i.id),s=r(i.direction),a=r(i.qty),o=r(i.limit),l=r(i.stop),c=r(i.oca_name),u=r(i.oca_type),p=r(i.comment),h=Jt(s),f=y.from(t.data.close).get(0),d=jr(t,a,h,f);let m="market";o!==void 0&&l!==void 0?m="stop-limit":o!==void 0?m="limit":l!==void 0&&(m="stop");const x=y.from(t.data.openTime).get(0),b={id:n,direction:h,qty:d,type:m,limit:o,stop:l,bar:t.idx,time:x,status:"pending",oca_name:c,oca_type:u,comment:p};return t.strategy.pending_orders.push(b),b}}function Rp(t){return(e,i)=>y.from(e).get(i||0)}function Op(t){return()=>{const e=(t.strategy?.opentrades??[]).slice(),i=h=>e[Number(h)],r=()=>{const h=t.marketData;return Array.isArray(h)&&t.idx>=0&&t.idx<h.length?h[t.idx]?.close??NaN:NaN},n={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},s=t.pine?.syminfo?.pointvalue??1,a=(h,f)=>{const d=t.strategy?.config,m=d?.commission_type??"percent",x=d?.commission_value??0;if(!x)return 0;const b=Math.abs(h.size);switch(m){case"percent":return b*f*s*(x/100);case"cash_per_contract":return b*x;case"cash_per_order":return x;default:return 0}},o=h=>Math.abs(h.size)*h.entry_price*s+(h.commission??0);n.profit=h=>{const f=i(h);if(!f)return NaN;const d=r();return Number.isFinite(d)?(Math.sign(f.size)===1?d-f.entry_price:f.entry_price-d)*Math.abs(f.size)*s-(f.commission??0)-a(f,d):NaN},n.profit_percent=h=>{const f=i(h);if(!f)return NaN;const d=n.profit(h);if(!Number.isFinite(d))return NaN;const m=o(f);return m>0?100*d/m:NaN},n.size=h=>i(h)?.size??NaN,n.commission=h=>i(h)?.commission??NaN,n.entry_price=h=>i(h)?.entry_price??NaN,n.entry_bar_index=h=>i(h)?.entry_bar_index??NaN,n.entry_id=h=>i(h)?.entry_id??"",n.entry_comment=h=>i(h)?.entry_comment??i(h)?.entry_id??"",n.entry_time=h=>i(h)?.entry_time??NaN,n.max_drawdown=h=>i(h)?.max_drawdown??0,n.max_drawdown_percent=h=>{const f=i(h);if(!f||!f.max_drawdown)return 0;const d=o(f);return d>0?100*f.max_drawdown/d:0},n.max_runup=h=>i(h)?.max_runup??0,n.max_runup_percent=h=>{const f=i(h);if(!f||!f.max_runup)return 0;const d=o(f);return d>0?100*f.max_runup/d:0};const l=t.strategy,c=l?.config?.margin_long??100,u=l?.config?.margin_short??100,p=c!==100||u!==100;if(!l||l.opentrades.length===0||!p)n.capital_held=NaN;else{let h=0;for(const f of l.opentrades){const d=Math.abs(f.size)*f.entry_price,m=f.size>0?c:u;h+=d*(m/100)}n.capital_held=h}return n}}function $p(t){return()=>{const e=(t.strategy?.closedtrades??[]).slice(),i=a=>e[Number(a)],r={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},n=t.pine?.syminfo?.pointvalue??1,s=a=>{const o=Math.abs(a.size)*a.entry_price*n,l=(a.commission??0)/2;return o+l};return r.profit=a=>i(a)?.profit??NaN,r.profit_percent=a=>{const o=i(a);if(!o||o.profit===void 0)return NaN;const l=s(o);return l>0?100*o.profit/l:NaN},r.size=a=>i(a)?.size??NaN,r.commission=a=>i(a)?.commission??NaN,r.entry_price=a=>i(a)?.entry_price??NaN,r.entry_bar_index=a=>i(a)?.entry_bar_index??NaN,r.entry_id=a=>i(a)?.entry_id??"",r.entry_comment=a=>i(a)?.entry_comment??i(a)?.entry_id??"",r.entry_time=a=>i(a)?.entry_time??NaN,r.exit_price=a=>i(a)?.exit_price??NaN,r.exit_bar_index=a=>i(a)?.exit_bar_index??NaN,r.exit_id=a=>i(a)?.exit_id??"",r.exit_comment=a=>i(a)?.exit_comment??i(a)?.exit_id??"",r.exit_time=a=>i(a)?.exit_time??NaN,r.max_drawdown=a=>i(a)?.max_drawdown??0,r.max_drawdown_percent=a=>{const o=i(a);if(!o||!o.max_drawdown)return 0;const l=s(o);return l>0?100*o.max_drawdown/l:0},r.max_runup=a=>i(a)?.max_runup??0,r.max_runup_percent=a=>{const o=i(a);if(!o||!o.max_runup)return 0;const l=s(o);return l>0?100*o.max_runup/l:0},r.first_index=0,r}}function Vp(t){return()=>t.strategy?.netprofit??0}function jp(t){return()=>t.strategy?.position_size??0}function Lp(t){return()=>{const e=t.strategy;return!e||e.position_size===0?NaN:e.position_avg_price}}function Bp(t){return()=>t.strategy?.equity??t.strategy?.config?.initial_capital??1e4}function Fp(t){return()=>"long"}function Wp(t){return()=>"short"}function Up(t){return()=>"cash"}function qp(t){return()=>"percent_of_equity"}function zp(t){return()=>"fixed"}function Kp(t){return()=>t.strategy?.openprofit??0}function Hp(t){return()=>{const e=t.strategy;return!e||!e.initial_capital?0:100*e.openprofit/e.initial_capital}}function Gp(t){return()=>{const e=t.strategy;return!e||!e.initial_capital?0:100*e.netprofit/e.initial_capital}}function Yp(t){return()=>t.strategy?.grossprofit??0}function Xp(t){return()=>{const e=t.strategy;return!e||!e.initial_capital?0:100*e.grossprofit/e.initial_capital}}function Zp(t){return()=>t.strategy?.grossloss??0}function Qp(t){return()=>{const e=t.strategy;return!e||!e.initial_capital?0:100*e.grossloss/e.initial_capital}}function Jp(t){return()=>t.strategy?.wintrades??0}function ef(t){return()=>t.strategy?.losstrades??0}function tf(t){return()=>t.strategy?.eventrades??0}function rf(t){return()=>{const e=t.strategy;return!e||!e.closedtrades||e.closedtrades.length===0?NaN:e.netprofit/e.closedtrades.length}}function nf(t){return()=>{const e=t.strategy;if(!e||!e.closedtrades||e.closedtrades.length===0)return NaN;let i=0;for(const r of e.closedtrades){const n=Math.abs(r.size)*r.entry_price;n>0&&(i+=100*(r.profit??0)/n)}return i/e.closedtrades.length}}function sf(t){return()=>{const e=t.strategy;return!e||e.wintrades===0?NaN:e.wintrades_total_profit/e.wintrades}}function af(t){return()=>{const e=t.strategy;if(!e||e.wintrades===0)return NaN;let i=0;for(const r of e.closedtrades)if((r.profit??0)>0){const n=Math.abs(r.size)*r.entry_price;n>0&&(i+=100*(r.profit??0)/n)}return i/e.wintrades}}function of(t){return()=>{const e=t.strategy;return!e||e.losstrades===0?NaN:e.losstrades_total_loss/e.losstrades}}function lf(t){return()=>{const e=t.strategy;if(!e||e.losstrades===0)return NaN;let i=0;for(const r of e.closedtrades)if((r.profit??0)<0){const n=Math.abs(r.size)*r.entry_price;n>0&&(i+=100*(r.profit??0)/n)}return i/e.losstrades}}function cf(t){return()=>t.strategy?.max_drawdown??0}function uf(t){return()=>{const e=t.strategy;return e?e.max_drawdown_percent_value??0:0}}function hf(t){return()=>t.strategy?.max_runup??0}function pf(t){return()=>{const e=t.strategy;return e?e.max_runup_percent_value??0:0}}function ff(t){return()=>t.strategy?.max_contracts_held_all??0}function df(t){return()=>t.strategy?.max_contracts_held_long??0}function mf(t){return()=>t.strategy?.max_contracts_held_short??0}function yf(t){return()=>t.strategy?.position_entry_name??""}function _f(t){return()=>t.strategy?.initial_capital??0}function gf(t){return()=>t.strategy?.account_currency??"USD"}function xf(t){return()=>{const e=t.strategy;if(!e||e.position_size===0)return NaN;const i=e.position_avg_price;if(!Number.isFinite(i))return NaN;const r=Math.sign(e.position_size),n=r===1?e.config.margin_long??100:e.config.margin_short??100;if(n>=100)return NaN;const s=Math.abs(e.position_size),a=t.pine?.syminfo?.pointvalue??1,o=((e.initial_capital??0)+(e.netprofit??0))/(a*s)-r*i,l=n/100-r,c=o/l,u=t.pine?.syminfo?.mintick??.01;return r===1?Math.floor(c/u)*u:Math.ceil(c/u)*u}}const bf=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],vf={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 wf(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.entry() called before strategy() declaration");const i=te(e,bf,vf),r=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,n=r(i.id),s=r(i.direction),a=r(i.qty),o=r(i.limit),l=r(i.stop),c=r(i.oca_name),u=r(i.oca_type),p=r(i.comment),h=Jt(s),f=t.strategy,d=f.position_size;if(Math.sign(d)===h&&d!==0&&bp(f,h))return;const m=y.from(t.data.close).get(0),x=jr(t,a,h,m),b=d!==0&&Math.sign(d)!==h,v=b?Math.abs(d)+x:x;let w="market";o!==void 0&&l!==void 0?w="stop-limit":o!==void 0?w="limit":l!==void 0&&(w="stop");const S=t.pine?.syminfo?.mintick??0,T=o!==void 0?ci(o,m,S):void 0,N=l!==void 0?ci(l,m,S):void 0,R=y.from(t.data.openTime).get(0),V={id:n,direction:h,qty:v,type:w,limit:T,stop:N,bar:t.idx,time:R,status:"pending",category:"entry",oca_name:c,oca_type:u,comment:p,_isReversalEntry:b};f.pending_orders.push(V)}}const Sf=[["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"]],Ef={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 Nf(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.exit() called before strategy() declaration");let i=et(e);if(i===void 0){const $=t.strategy;$._exit_fallback_last_bar!==t.idx&&($._exit_fallback_counter=0,$._exit_fallback_last_bar=t.idx),i=`exit_raw_${$._exit_fallback_counter++}`}const r=te(e,Sf,Ef),n=$=>$==null||typeof $=="string"||typeof $=="number"||typeof $=="boolean"?$:typeof $=="function"?$():$ instanceof y?$.get(0):Array.isArray($)?$[$.length-1]:typeof $=="object"&&$.get!==void 0?$.get(0):$,s=n(r.id),a=n(r.from_entry),o=n(r.qty),l=n(r.qty_percent),c=n(r.profit),u=n(r.limit),p=n(r.loss),h=n(r.stop),f=n(r.trail_price),d=n(r.trail_points),m=n(r.trail_offset),x=t.pine?.syminfo?.mintick??0,b=y.from(t.data.close).get(0),v=u!==void 0?ci(u,b,x):void 0,w=h!==void 0?ci(h,b,x):void 0,S=f!==void 0?ci(f,b,x):void 0,T=a??"",N=!!(T?t.strategy.pending_orders.find($=>$.category==="entry"&&$.id===T&&$.status==="pending"):t.strategy.pending_orders.find($=>$.category==="entry"&&$.status==="pending"))?._isReversalEntry,R=t.strategy._exit_call_history,V=R.get(i),k=V!==void 0&&V===t.idx-1;R.set(i,t.idx);const A={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:T,profit:c,loss:p,limit:v,stop:w,trail_price:S,trail_points:d,trail_offset:m,oca_name:n(r.oca_name),comment:n(r.comment),comment_profit:n(r.comment_profit),comment_loss:n(r.comment_loss),comment_trailing:n(r.comment_trailing),alert_message:n(r.alert_message),alert_profit:n(r.alert_profit),alert_loss:n(r.alert_loss),alert_trailing:n(r.alert_trailing),disable_alert:n(r.disable_alert),trail_armed:!1,trail_peak:NaN,_attachedAtReversal:N,_isPersistent:k,_callsiteId:i},O=A.id,z=t.strategy.pending_orders;for(let $=z.length-1;$>=0;$--){const q=z[$];q.category==="exit"&&q.id===O&&(q.from_entry??"")===(A.from_entry??"")&&q.status==="pending"&&(q.trail_armed&&(A.trail_armed=!0,A.trail_peak=q.trail_peak),z.splice($,1))}z.push(A)}}const Cf=[["id","comment","qty","qty_percent","alert_message","immediately","disable_alert"]],If={id:"string",comment:"string",qty:"series",qty_percent:"series",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function kf(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close() called before strategy() declaration");const i=te(e,Cf,If),r=i.id;if(r==null||!t.strategy.opentrades.some(o=>o.entry_id===r))return;const n=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(const o of s)n(o)&&(o.from_entry??"")===r&&o.status==="pending"&&(o.status="cancelled");t.strategy.pending_orders=s.filter(o=>o.status==="pending");const a={id:`close_${r}`,direction:0,qty:0,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:r,qty_percent:i.qty_percent,comment:i.comment,alert_message:i.alert_message,immediately:i.immediately===!0,disable_alert:i.disable_alert,_intended_trade_ids:t.strategy.opentrades.filter(o=>o.entry_id===r).map(o=>o.id)};i.qty!==void 0&&(a.qty=Math.abs(Number(i.qty))),t.strategy.pending_orders.push(a)}}const Tf=[["comment","alert_message","immediately","disable_alert"]],Af={comment:"string",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function Pf(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close_all() called before strategy() declaration");const i=te(e,Tf,Af);if(t.strategy.opentrades.length===0)return;const r=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),n=t.strategy.pending_orders;for(const a of n)r(a)&&a.status==="pending"&&(a.status="cancelled");t.strategy.pending_orders=n.filter(a=>a.status==="pending");const 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:i.comment,alert_message:i.alert_message,immediately:i.immediately===!0,disable_alert:i.disable_alert,_intended_trade_ids:t.strategy.opentrades.map(a=>a.id)};t.strategy.pending_orders.push(s)}}const Df=[["id","immediately"]],Mf={id:"string",immediately:"boolean"};function Rf(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.cancel() called before strategy() declaration");const i=te(e,Df,Mf).id;i!=null&&(t.strategy.pending_orders=t.strategy.pending_orders.filter(r=>!(r.status==="pending"&&r.id===i)))}}function Of(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 $f(t){return{allow_entry_in:e=>{t.strategy&&(t.strategy.risk_rules.allow_entry_in=e)},max_cons_loss_days:(e,i)=>{t.strategy&&(t.strategy.risk_rules.max_cons_loss_days={count:e,alert_message:i})},max_drawdown:(e,i,r)=>{t.strategy&&(t.strategy.risk_rules.max_drawdown={value:e,type:i})},max_intraday_filled_orders:(e,i)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_filled_orders={count:e,alert_message:i})},max_intraday_loss:(e,i,r)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_loss={value:e,type:i})},max_position_size:e=>{t.strategy&&(t.strategy.risk_rules.max_position_size=e)}}}function Vf(t){return e=>{const i=t.strategy,r=t.pine?.syminfo?.currency,n=i?.account_currency??"USD";return r&&r!==n?NaN:e}}function jf(t){return e=>{const i=t.strategy,r=t.pine?.syminfo?.currency,n=i?.account_currency??"USD";return r&&r!==n?NaN:e}}function Lf(t){return e=>t.strategy?jr(t,void 0,1,e):0}const Bf={any:Ap,order:Mp,param:Rp,opentrades:Op,closedtrades:$p,netprofit:Vp,position_size:jp,position_avg_price:Lp,equity:Bp,long:Fp,short:Wp,cash:Up,percent_of_equity:qp,fixed:zp,openprofit:Kp,openprofit_percent:Hp,netprofit_percent:Gp,grossprofit:Yp,grossprofit_percent:Xp,grossloss:Zp,grossloss_percent:Qp,wintrades:Jp,losstrades:ef,eventrades:tf,avg_trade:rf,avg_trade_percent:nf,avg_winning_trade:sf,avg_winning_trade_percent:af,avg_losing_trade:of,avg_losing_trade_percent:lf,max_drawdown:cf,max_drawdown_percent:uf,max_runup:hf,max_runup_percent:pf,max_contracts_held_all:ff,max_contracts_held_long:df,max_contracts_held_short:mf,position_entry_name:yf,initial_capital:_f,account_currency:gf,margin_liquidation_price:xf,entry:wf,exit:Nf,close:kf,close_all:Pf,cancel:Rf,cancel_all:Of,convert_to_account:Vf,convert_to_symbol:jf,default_entry_qty:Lf},Ff={long:"long",short:"short",all:"all"},Wf={none:"none",cancel:"cancel",reduce:"reduce"},Uf={percent:"percent",cash_per_order:"cash_per_order",cash_per_contract:"cash_per_contract"};class qf{constructor(e){this.context=e,Object.entries(Bf).forEach(([r,n])=>{this[r]=n(e)}),this.direction=()=>Ff,this.oca=()=>Wf,this.commission=()=>Uf;const i=$f(e);this.risk=()=>i}}function zf(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC")return 0;const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const a=r[1]==="+"?1:-1,o=parseInt(r[2],10),l=parseInt(r[3]||"0",10);return a*(o*60+l)}const n=Rt(t,e),s=new Date(Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second));return Math.round((s.getTime()-t)/6e4)}function Kf(t,e){const i=e>=0?"+":"-",r=s=>String(Math.floor(Math.abs(s))).padStart(2,"0"),n=i+r(e/60)+":"+r(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${n}]`}class Hf{constructor(e){this.context=e}logFormat(e,...i){return e.replace(/{(\d+)}/g,(r,n)=>i[n])}param(e,i=0,r){return y.from(e).get(i)}_formatTimestamp(){const e=this.context.data.openTime.data[this.context.idx],i=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",r=zf(e,i);return Kf(e,r)}warning(e,...i){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}error(e,...i){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}info(e,...i){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}}const Gf=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Yf=["January","February","March","April","May","June","July","August","September","October","November","December"],Xf=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Zf=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Ve=(t,e)=>String(t).padStart(e,"0");class Qf{constructor(e){this.context=e}param(e,i=0,r){return y.from(e).get(i)}tostring(e,i){if(typeof e!="number"||isNaN(e)||!i)return String(e);if(i==="mintick"){const n=this.context.pine?.syminfo?.mintick||.01,s=Math.max(0,-Math.floor(Math.log10(n)));return e.toFixed(s)}if(i==="integer")return String(Math.round(e));if(i==="percent")return(e*100).toFixed(2)+"%";if(i==="price"){const n=this.context.pine?.syminfo?.mintick||.01,s=Math.max(0,-Math.floor(Math.log10(n)));return e.toFixed(s)}if(i==="volume")return String(Math.round(e));const r=i.indexOf(".");if(r>=0){const n=i.substring(r+1).length;return e.toFixed(n)}return i.includes("#")||i.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,i,r=""){return Array(i).fill(e).join(r||"")}replace_all(e,i,r){return String(e).replaceAll(i,r)}replace(e,i,r,n=0){const s=String(e),a=String(i),o=String(r),l=Math.floor(Number(n))||0;if(a==="")return s;let c=0,u=0;for(;;){const p=s.indexOf(a,c);if(p===-1)return s;if(u===l)return s.substring(0,p)+o+s.substring(p+a.length);u++,c=p+a.length}}contains(e,i){return String(e).includes(i)}endswith(e,i){return String(e).endsWith(i)}startswith(e,i){return String(e).startsWith(i)}pos(e,i){const r=String(e).indexOf(i);return r===-1?NaN:r}length(e){return String(e).length}match(e,i){return String(e).match(new RegExp(i))}split(e,i){return new F(String(e).split(i),L.string,this.context)}substring(e,i,r){return String(e).substring(i,r)}format_time(e,i="yyyy-MM-dd'T'HH:mm:ssZ",r){if(e==null||typeof e=="number"&&isNaN(e))return"NaN";const n=Number(e),s=r||this.context.pine?.syminfo?.timezone||"UTC",a=Rt(n,s),o=Date.UTC(a.year,a.month-1,a.day,a.hour,a.minute,a.second),l=Math.round((o-n)/6e4),c=Date.UTC(a.year,0,1),u=Math.floor((o-c)/864e5)+1,p=a.hour%12===0?12:a.hour%12;let h="",f=0;for(;f<i.length;){const d=i[f];if(d==="'"){if(i[f+1]==="'"){h+="'",f+=2;continue}const m=i.indexOf("'",f+1);if(m===-1){h+=i.substring(f+1);break}h+=i.substring(f+1,m),f=m+1;continue}if(d>="a"&&d<="z"||d>="A"&&d<="Z"){let m=1;for(;i[f+m]===d;)m++;switch(f+=m,d){case"y":h+=m===2?Ve(a.year%100,2):m>=4?Ve(a.year,4):String(a.year);break;case"M":m>=4?h+=Yf[a.month-1]:m===3?h+=Gf[a.month-1]:m===2?h+=Ve(a.month,2):h+=String(a.month);break;case"d":h+=m===2?Ve(a.day,2):String(a.day);break;case"D":h+=m>=3?Ve(u,3):m===2?Ve(u,2):String(u);break;case"E":h+=m>=4?Zf[a.dayOfWeek]:Xf[a.dayOfWeek];break;case"a":h+=a.hour<12?"AM":"PM";break;case"h":h+=m===2?Ve(p,2):String(p);break;case"H":h+=m===2?Ve(a.hour,2):String(a.hour);break;case"m":h+=m===2?Ve(a.minute,2):String(a.minute);break;case"s":h+=m===2?Ve(a.second,2):String(a.second);break;case"S":{const x=n-Math.floor(n/1e3)*1e3;h+=Ve(x,3).substring(0,m);break}case"Z":{const x=l>=0?"+":"-",b=Math.abs(l);h+=`${x}${Ve(Math.floor(b/60),2)}${Ve(b%60,2)}`;break}default:h+=d.repeat(m)}continue}h+=d,f++}return h}format(e,...i){return e.replace(/\{(\d+)(?:,number,([^}]+))?\}/g,(r,n,s)=>{const a=i[n];return s&&typeof a=="number"&&!isNaN(a)?this.tostring(a,s):String(a)})}}var Jf=Object.defineProperty,ed=(t,e,i)=>e in t?Jf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,td=(t,e,i)=>ed(t,typeof e!="symbol"?e+"":e,i);const Ii={"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(!t||/^\d+$/.test(t))return t;if(Ii[t])return Ii[t];const e=t.toLowerCase();if(Ii[e])return Ii[e];if(t.length===1){const r=t.toUpperCase();if(["D","W","M","S"].includes(r))return r}const i=t.slice(-1).toUpperCase();if(["D","W","M","S"].includes(i)){const r=parseInt(t);if(!isNaN(r))return r+i}return t}class id{constructor(e){this.context=e,td(this,"_normalized",null)}param(e,i=0,r){return y.from(e).get(i)}get normalized(){return this._normalized===null&&(this._normalized=fn(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(){const 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){const i=typeof e=="function"?e():e,r=i instanceof y?i.get(0):i,n=_r(r||"");if(!n)return!1;const 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;const o=gr(s,n),l=gr(a,n);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=fn(e);const i=e.slice(-1).toUpperCase(),r=parseInt(e);return i==="S"?isNaN(r)?1:r:i==="D"?(isNaN(r)?1:r)*60*60*24:i==="W"?(isNaN(r)?1:r)*60*60*24*7:i==="M"?(isNaN(r)?1:r)*60*60*24*30:isNaN(r)?0:r*60}}var rd=Object.defineProperty,nd=Object.getOwnPropertyDescriptor,at=(t,e,i,r)=>{for(var n=r>1?void 0:r?nd(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=(r?a(e,i,n):a(n))||n);return r&&n&&rd(e,i,n),n};const sd=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],ad=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],od={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"},ld=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],cd=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],ud=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],hd=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],dn=["color","offset","editable","show_last","title","display","force_overlay"],pd=["price","title","color","linestyle","linewidth","editable","display"],fd=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],dd={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"},md={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"},yd={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"},_d={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"},gd={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"},mn={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},xd={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},bd={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"};class yt{constructor(e){this.context=e}_resolvePlotKey(e,i){if(e){const r=this.context.plots[e];return!r||!i||r._callsiteId===i?e:e+i}return i||"plot"}extractPlotOptions(e){const i={};for(let r in e)i[r]=y.from(e[r]).get(0);return i}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,i=0,r){return y.from(e).get(i)}plotchar(...e){const i=et(e),r=te(e,ad,od),{series:n,title:s,...a}=r,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,i);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:s,_plotKey:l,_callsiteId:i});const c=y.from(n).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){const i=et(e),r=te(e,sd,dd),{series:n,title:s,...a}=r,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,i),c="color"in a;if(!this.context.plots[l]){const f=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:f},title:s,_plotKey:l,_callsiteId:i}}const u=y.from(n).get(0);let p=o.color;typeof p=="function"&&(p=p());const h={color:c?typeof p=="string"?p:void 0:p||"#2962ff"};return"offset"in a&&(h.offset=o.offset),this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:u,options:h}),this.context.plots[l]}plotshape(...e){const i=et(e),r=te(e,ld,md),{series:n,title:s,...a}=r,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,i);if(!this.context.plots[l]){const 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:i}}const c=y.from(n).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){const i=et(e),r=te(e,cd,yd),{series:n,title:s,...a}=r,o=y.from(n).get(0),l=this.extractPlotOptions(a),c=this._resolvePlotKey(s,i);if(!this.context.plots[c]){const 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:i}}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){const i=et(e),r=te(e,ud,_d),{open:n,high:s,low:a,close:o,title:l,...c}=r,u=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...u,style:"bar",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const h=[y.from(n).get(0),y.from(s).get(0),y.from(a).get(0),y.from(o).get(0)];this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:h,options:{color:u.color}})}plotcandle(...e){const i=et(e),r=te(e,hd,gd),{open:n,high:s,low:a,close:o,title:l,...c}=r,u=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...u,style:"candle",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const h=[y.from(n).get(0),y.from(s).get(0),y.from(a).get(0),y.from(o).get(0)];return this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:h,options:{color:u.color,wickcolor:u.wickcolor,bordercolor:u.bordercolor}}),this.context.plots[p]}bgcolor(...e){const i=et(e),r=te(e,dn,mn),{title:n,...s}=r,a=this.extractPlotOptions(s),o=this._resolvePlotKey(n,i);if(!this.context.plots[o]){const l=a.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...a,style:"background",overlay:l},title:n,_plotKey:o,_callsiteId:i}}this.context.plots[o].data.push({title:n,time:this.context.marketData[this.context.idx].openTime,value:a.color&&a.color!=="na"&&a?.color.toString()!=="NaN",options:{color:a.color}})}barcolor(...e){const i=et(e),r=te(e,dn,mn),{title:n,...s}=r,a=this.extractPlotOptions(s),o=this._resolvePlotKey(n,i);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...a,style:"barcolor"},title:n,_plotKey:o,_callsiteId:i}),this.context.plots[o].data.push({title:n,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]}}at([C],yt.prototype,"plotchar",1),at([C],yt.prototype,"any",1),at([C],yt.prototype,"plotshape",1),at([C],yt.prototype,"plotarrow",1),at([C],yt.prototype,"plotbar",1),at([C],yt.prototype,"plotcandle",1),at([C],yt.prototype,"bgcolor",1),at([C],yt.prototype,"barcolor",1);class ks{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,i=0,r){return y.from(e).get(i)}any(...e){const i=et(e),r=te(e,pd,xd),{price:n,title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u}=r,p=[n,{title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u,style:"hline"}];return i&&p.push({__callsiteId:i}),this.context.pine.plot.any(...p)}}at([C],ks.prototype,"any",1);class Ts{constructor(e){this.context=e}param(e,i=0,r){return y.from(e).get(i)}any(...e){const i=et(e),r=e.length>=6&&typeof e[2]=="number",n=!r&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(r||n!==null){const s=e[0],a=e[1],o=n?y.from(n.top_value).get(0):e[2],l=n?y.from(n.bottom_value).get(0):e[3],c=n?y.from(n.top_color).get(0):e[4],u=n?y.from(n.bottom_color).get(0):e[5],p=n?n.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,h=s?._plotKey||s?.title,f=a?._plotKey||a?.title;let d=p||"fill";const m=this.context.plots[d];m&&i&&m._callsiteId!==i&&(d=i),this.context.plots[d]||(this.context.plots[d]={title:p||"Fill",plot1:h,plot2:f,data:[],options:{plot1:h,plot2:f,style:"fill",gradient:!0},_plotKey:d,_callsiteId:i}),this.context.plots[d].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{const s=te(e,fd,bd),{plot1:a,plot2:o,color:l,title:c,editable:u,show_last:p,fillgaps:h,display:f}=s;let d=c||"fill";const m=this.context.plots[d];m&&i&&m._callsiteId!==i&&(d=i);const x=y.from(l).get(0);if(!this.context.plots[d]){const b=a?._plotKey||a?.title,v=o?._plotKey||o?.title;this.context.plots[d]={title:c||"Fill",plot1:b,plot2:v,data:[],options:{plot1:b,plot2:v,color:x,editable:u,show_last:p,fillgaps:h,display:f,style:"fill"},_plotKey:d,_callsiteId:i}}this.context.plots[d].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:x}})}}}at([C],Ts.prototype,"any",1);var vd=Object.defineProperty,wd=(t,e,i)=>e in t?vd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Sd=(t,e,i)=>wd(t,typeof e!="symbol"?e+"":e,i);class Ed{constructor(e){this.context=e,Sd(this,"point");const i=this.context;this.point={new(r,n,s){return new Ie(r,n,s??NaN)},from_index(r,n){return new Ie(void 0,r,n)},from_time(r,n){return new Ie(r,void 0,n)},copy(r){return r.copy()},now(r){const n=i.idx,s=i.marketData[n]?.openTime;return new Ie(s,n,r)}}}param(e,i=0,r){return y.from(e).get(i)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){return!0}is_heikinashi(){return!1}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}}var Nd=Object.defineProperty,Cd=(t,e,i)=>e in t?Nd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ge=(t,e,i)=>Cd(t,typeof e!="symbol"?e+"":e,i);let Id=0;class ui{constructor(e,i,r="",n="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",p="",h="default",f=!1){ge(this,"id"),ge(this,"x"),ge(this,"y"),ge(this,"text"),ge(this,"xloc"),ge(this,"yloc"),ge(this,"color"),ge(this,"style"),ge(this,"textcolor"),ge(this,"size"),ge(this,"textalign"),ge(this,"tooltip"),ge(this,"text_font_family"),ge(this,"force_overlay"),ge(this,"_deleted"),ge(this,"_helper"),ge(this,"_createdAtBar",-1),this.id=Id++,this.x=e,this.y=i,this.text=r,this.xloc=n,this.yloc=s,this.color=a,this.style=o,this.textcolor=l,this.size=c,this.textalign=u,this.tooltip=p,this.text_font_family=h,this.force_overlay=f,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,i){this._helper?this._helper.set_xy(this,e,i):this._deleted||(this.x=e,this.y=i)}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 ui(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}}}var As=Object.defineProperty,kd=Object.getOwnPropertyDescriptor,Td=(t,e,i)=>e in t?As(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ve=(t,e,i,r)=>{for(var n=r>1?void 0:r?kd(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=(r?a(e,i,n):a(n))||n);return r&&n&&As(e,i,n),n},Ad=(t,e,i)=>Td(t,typeof e!="symbol"?e+"":e,i);const Pd=[["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"]],Dd={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"};class xe{constructor(e){this.context=e,Ad(this,"_labels",[])}param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._labels.filter(s=>!s._deleted).map(s=>s.toPlotData()),r=i.filter(s=>!s.force_overlay),n=i.filter(s=>s.force_overlay);this.context.plots.__labels__.data=[{time:e,value:r,options:{style:"label"}}],n.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:n,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof Re)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){const i=e.get(0);return typeof i=="number"&&isNaN(i)?null:i}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,i,r="",n="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",p="",h="default",f=!1){const d=new ui(e,i,this._resolve(r),this._resolve(n),this._resolve(s),this._resolve(a),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(u),this._resolve(p),this._resolve(h),f);return d._helper=this,d._createdAtBar=this.context.idx,this._labels.push(d),this._enforceMaxCount(),this.syncToPlot(),d}_enforceMaxCount(){const e=this.context.indicator?.max_labels_count??50,i=this._labels.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const s of this._labels){if(n>=r)break;s._deleted||(s._deleted=!0,n++)}}}new(...e){const i=te(e,Pd,Dd);let r,n,s=i.xloc;if(i.point instanceof Ie){const a=i.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?(r=a.index,s=s||"bi"):l?(r=a.time,s=s||"bt"):(r=0,s=s||"bi"),n=a.price}else r=i.x,n=i.y;return this._createLabel(r,n,i.text,s,i.yloc,i.color,i.style,i.textcolor,i.size,i.textalign,i.tooltip,i.text_font_family,i.force_overlay)}any(...e){if(e.length===1){const i=e[0];if(i==null||i instanceof Re||typeof i=="number"&&isNaN(i))return null;if(i instanceof ui)return i;if(i instanceof y){const r=i.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof ui)return r}return null}return this.new(...e)}set_x(e,i){e&&!e._deleted&&(e.x=i)}set_y(e,i){e&&!e._deleted&&(e.y=i)}set_xy(e,i,r){e&&!e._deleted&&(e.x=i,e.y=r)}set_text(e,i){e&&!e._deleted&&(e.text=i)}set_color(e,i){e&&!e._deleted&&(e.color=i)}set_textcolor(e,i){e&&!e._deleted&&(e.textcolor=i)}set_size(e,i){e&&!e._deleted&&(e.size=i)}set_style(e,i){e&&!e._deleted&&(e.style=i)}set_textalign(e,i){e&&!e._deleted&&(e.textalign=i)}set_tooltip(e,i){e&&!e._deleted&&(e.tooltip=i)}set_xloc(e,i){e&&!e._deleted&&(e.xloc=i)}set_yloc(e,i){e&&!e._deleted&&(e.yloc=i)}set_point(e,i){if(e&&!e._deleted&&i){const r=i.index!==void 0&&!(typeof i.index=="number"&&isNaN(i.index)),n=i.time!==void 0&&!(typeof i.time=="number"&&isNaN(i.time));r?(e.x=i.index,e.xloc="bi"):n&&(e.x=i.time,e.xloc="bt"),e.y=i.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;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._labels.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(i=>i._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"}}ve([C],xe.prototype,"new",1),ve([C],xe.prototype,"set_x",1),ve([C],xe.prototype,"set_y",1),ve([C],xe.prototype,"set_xy",1),ve([C],xe.prototype,"set_text",1),ve([C],xe.prototype,"set_color",1),ve([C],xe.prototype,"set_textcolor",1),ve([C],xe.prototype,"set_size",1),ve([C],xe.prototype,"set_style",1),ve([C],xe.prototype,"set_textalign",1),ve([C],xe.prototype,"set_tooltip",1),ve([C],xe.prototype,"set_xloc",1),ve([C],xe.prototype,"set_yloc",1),ve([C],xe.prototype,"set_point",1),ve([C],xe.prototype,"copy",1),ve([C],xe.prototype,"delete",1);var Md=Object.defineProperty,Rd=(t,e,i)=>e in t?Md(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Pe=(t,e,i)=>Rd(t,typeof e!="symbol"?e+"":e,i);let Od=0;class hi{constructor(e,i,r,n,s="bi",a="none",o="",l="style_solid",c=1,u=!1){Pe(this,"id"),Pe(this,"x1"),Pe(this,"y1"),Pe(this,"x2"),Pe(this,"y2"),Pe(this,"xloc"),Pe(this,"extend"),Pe(this,"color"),Pe(this,"style"),Pe(this,"width"),Pe(this,"force_overlay"),Pe(this,"_deleted"),Pe(this,"_helper"),Pe(this,"_createdAtBar",-1),this.id=Od++,this.x1=e,this.y1=i,this.x2=r,this.y2=n,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,i){this._helper?this._helper.set_xy1(this,e,i):this._deleted||(this.x1=e,this.y1=i)}set_xy2(e,i){this._helper?this._helper.set_xy2(this,e,i):this._deleted||(this.x2=e,this.y2=i)}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,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.x1=e,this.x2=i,this.xloc=r)}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 hi(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}}}var Ps=Object.defineProperty,$d=Object.getOwnPropertyDescriptor,Vd=(t,e,i)=>e in t?Ps(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,we=(t,e,i,r)=>{for(var n=r>1?void 0:r?$d(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=(r?a(e,i,n):a(n))||n);return r&&n&&Ps(e,i,n),n},jd=(t,e,i)=>Vd(t,typeof e!="symbol"?e+"":e,i);const Ld=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],Bd={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"};class be{constructor(e){this.context=e,jd(this,"_lines",[])}param(e,i=0,r){return y.from(e).get(i)}_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();const e=this.context.marketData[0]?.openTime||0,i=this._lines.filter(s=>!s._deleted).map(s=>s.toPlotData()),r=i.filter(s=>!s.force_overlay),n=i.filter(s=>s.force_overlay);this.context.plots.__lines__.data=[{time:e,value:r,options:{style:"drawing_line"}}],n.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:n,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e){const i=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),r=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return i?{x:e.index,xloc:"bi"}:r?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Re?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){const i=this._resolve(e);return i==null?i:typeof i=="number"&&isNaN(i)?NaN:i}_createLine(e,i,r,n,s="bi",a="none",o="",l="style_solid",c=1,u=!1){const p=new hi(e,i,r,n,s,this._resolve(a),this._resolveColor(o),this._resolve(l),this._resolve(c)||1,u);return p._helper=this,p._createdAtBar=this.context.idx,this._lines.push(p),this._enforceMaxCount(),this.syncToPlot(),p}_enforceMaxCount(){const e=this.context.indicator?.max_lines_count??50,i=this._lines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const s of this._lines){if(n>=r)break;s._deleted||(s._deleted=!0,n++)}}}new(...e){const i=te(e,Ld,Bd);let r,n,s,a,o=i.xloc;if(i.first_point instanceof Ie){const l=i.first_point,c=i.second_point,u=this._resolvePoint(l);r=u.x,n=l.price,o=o||u.xloc,c instanceof Ie?(s=this._resolvePoint(c).x,a=c.price):(s=0,a=NaN)}else r=i.x1,n=i.y1,s=i.x2,a=i.y2;return this._createLine(r,n,s,a,o,i.extend,i.color,i.style,i.width,i.force_overlay)}any(...e){if(e.length===1){const i=e[0];if(i==null||i instanceof Re||typeof i=="number"&&isNaN(i))return null;if(i instanceof hi)return i;if(i instanceof y){const r=i.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof hi)return r}return null}return this.new(...e)}set_x1(e,i){e&&!e._deleted&&(e.x1=this._resolve(i))}set_y1(e,i){e&&!e._deleted&&(e.y1=this._resolve(i))}set_x2(e,i){e&&!e._deleted&&(e.x2=this._resolve(i))}set_y2(e,i){e&&!e._deleted&&(e.y2=this._resolve(i))}set_xy1(e,i,r){e&&!e._deleted&&(e.x1=this._resolve(i),e.y1=this._resolve(r))}set_xy2(e,i,r){e&&!e._deleted&&(e.x2=this._resolve(i),e.y2=this._resolve(r))}set_color(e,i){e&&!e._deleted&&(e.color=this._resolveColor(i))}set_width(e,i){e&&!e._deleted&&(e.width=this._resolve(i)||1)}set_style(e,i){e&&!e._deleted&&(e.style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_xloc(e,i,r,n){e&&!e._deleted&&(e.x1=i,e.x2=r,e.xloc=n)}set_first_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x1=r.x,e.y1=i.price,e.xloc=r.xloc}}set_second_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x2=r.x,e.y2=i.price,e.xloc=r.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,i){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;const r=e.x2-e.x1;return r===0?e.y1:e.y1+(i-e.x1)/r*(e.y2-e.y1)}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._lines.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(i=>i._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"}}we([C],be.prototype,"new",1),we([C],be.prototype,"set_x1",1),we([C],be.prototype,"set_y1",1),we([C],be.prototype,"set_x2",1),we([C],be.prototype,"set_y2",1),we([C],be.prototype,"set_xy1",1),we([C],be.prototype,"set_xy2",1),we([C],be.prototype,"set_color",1),we([C],be.prototype,"set_width",1),we([C],be.prototype,"set_style",1),we([C],be.prototype,"set_extend",1),we([C],be.prototype,"set_xloc",1),we([C],be.prototype,"set_first_point",1),we([C],be.prototype,"set_second_point",1),we([C],be.prototype,"copy",1),we([C],be.prototype,"delete",1);var Fd=Object.defineProperty,Wd=(t,e,i)=>e in t?Fd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ne=(t,e,i)=>Wd(t,typeof e!="symbol"?e+"":e,i);let Ud=0;class pi{constructor(e,i,r,n,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",p="",h="#000000",f="auto",d="center",m="center",x="wrap_none",b="default",v="format_none",w=!1){ne(this,"id"),ne(this,"left"),ne(this,"top"),ne(this,"right"),ne(this,"bottom"),ne(this,"xloc"),ne(this,"extend"),ne(this,"border_color"),ne(this,"border_style"),ne(this,"border_width"),ne(this,"bgcolor"),ne(this,"text"),ne(this,"text_color"),ne(this,"text_size"),ne(this,"text_halign"),ne(this,"text_valign"),ne(this,"text_wrap"),ne(this,"text_font_family"),ne(this,"text_formatting"),ne(this,"force_overlay"),ne(this,"_deleted"),ne(this,"_helper"),ne(this,"_createdAtBar",-1),this.id=Ud++,this.left=e,this.top=i,this.right=r,this.bottom=n,this.xloc=s,this.extend=a,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=u,this.text=p,this.text_color=h,this.text_size=f,this.text_halign=d,this.text_valign=m,this.text_wrap=x,this.text_font_family=b,this.text_formatting=v,this.force_overlay=w,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,i){this._helper?this._helper.set_lefttop(this,e,i):this._deleted||(this.left=e,this.top=i)}set_rightbottom(e,i){this._helper?this._helper.set_rightbottom(this,e,i):this._deleted||(this.right=e,this.bottom=i)}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,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.left=e,this.right=i,this.xloc=r)}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 pi(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)}}var Ds=Object.defineProperty,qd=Object.getOwnPropertyDescriptor,zd=(t,e,i)=>e in t?Ds(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ie=(t,e,i,r)=>{for(var n=r>1?void 0:r?qd(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=(r?a(e,i,n):a(n))||n);return r&&n&&Ds(e,i,n),n},Kd=(t,e,i)=>zd(t,typeof e!="symbol"?e+"":e,i);const Hd=[["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"]],Gd={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"};class ee{constructor(e){this.context=e,Kd(this,"_boxes",[])}param(e,i=0,r){return y.from(e).get(i)}_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();const e=this.context.marketData[0]?.openTime||0,i=this._boxes.filter(s=>!s._deleted).map(s=>s.toPlotData()),r=i.filter(s=>!s.force_overlay),n=i.filter(s=>s.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:r,options:{style:"drawing_box"}}],n.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:n,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e){const i=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),r=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return i?{x:e.index,xloc:"bi"}:r?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof Re?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r||i}_createBox(e,i,r,n,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",p="",h="#000000",f="auto",d="center",m="center",x="wrap_none",b="default",v="format_none",w=!1){const S=new pi(e,i,r,n,s,this._resolve(a),this._resolveColor(o,"#2962ff"),this._resolve(l)||"style_solid",this._resolve(c)??1,this._resolveColor(u,"#2962ff"),this._resolve(p)||"",this._resolveColor(h,"#000000"),this._resolve(f)||"auto",this._resolve(d)||"center",this._resolve(m)||"center",this._resolve(x)||"wrap_none",this._resolve(b)||"default",this._resolve(v)||"format_none",w);return S._helper=this,S._createdAtBar=this.context.idx,this._boxes.push(S),this._enforceMaxCount(),this.syncToPlot(),S}_enforceMaxCount(){const e=this.context.indicator?.max_boxes_count??50,i=this._boxes.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const s of this._boxes){if(n>=r)break;s._deleted||(s._deleted=!0,n++)}}}new(...e){const i=te(e,Hd,Gd);let r,n,s,a,o=i.xloc;if(i.top_left instanceof Ie){const l=i.top_left,c=i.bottom_right,u=this._resolvePoint(l);r=u.x,n=l.price,o=o||u.xloc,c instanceof Ie?(s=this._resolvePoint(c).x,a=c.price):(s=0,a=NaN)}else r=this._resolve(i.left),n=this._resolve(i.top),s=this._resolve(i.right),a=this._resolve(i.bottom);return this._createBox(r,n,s,a,o,i.extend,i.border_color,i.border_style,i.border_width,i.bgcolor,i.text,i.text_color,i.text_size,i.text_halign,i.text_valign,i.text_wrap,i.text_font_family,void 0,i.force_overlay)}any(...e){if(e.length===1){const i=e[0];if(i==null||i instanceof Re||typeof i=="number"&&isNaN(i))return null;if(i instanceof pi)return i;if(i instanceof y){const r=i.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof pi)return r}return null}return this.new(...e)}set_left(e,i){e&&!e._deleted&&(e.left=this._resolve(i))}set_right(e,i){e&&!e._deleted&&(e.right=this._resolve(i))}set_top(e,i){e&&!e._deleted&&(e.top=this._resolve(i))}set_bottom(e,i){e&&!e._deleted&&(e.bottom=this._resolve(i))}set_lefttop(e,i,r){e&&!e._deleted&&(e.left=this._resolve(i),e.top=this._resolve(r))}set_rightbottom(e,i,r){e&&!e._deleted&&(e.right=this._resolve(i),e.bottom=this._resolve(r))}set_top_left_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.left=r.x,e.top=i.price,e.xloc=r.xloc}}set_bottom_right_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.right=r.x,e.bottom=i.price,e.xloc=r.xloc}}set_xloc(e,i,r,n){e&&!e._deleted&&(e.left=this._resolve(i),e.right=this._resolve(r),e.xloc=this._resolve(n))}set_bgcolor(e,i){e&&!e._deleted&&(e.bgcolor=this._resolve(i))}set_border_color(e,i){e&&!e._deleted&&(e.border_color=this._resolve(i))}set_border_width(e,i){e&&!e._deleted&&(e.border_width=this._resolve(i)??1)}set_border_style(e,i){e&&!e._deleted&&(e.border_style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_text(e,i){e&&!e._deleted&&(e.text=this._resolve(i)||"")}set_text_color(e,i){e&&!e._deleted&&(e.text_color=this._resolve(i))}set_text_size(e,i){e&&!e._deleted&&(e.text_size=this._resolve(i))}set_text_halign(e,i){e&&!e._deleted&&(e.text_halign=this._resolve(i))}set_text_valign(e,i){e&&!e._deleted&&(e.text_valign=this._resolve(i))}set_text_wrap(e,i){e&&!e._deleted&&(e.text_wrap=this._resolve(i))}set_text_font_family(e,i){e&&!e._deleted&&(e.text_font_family=this._resolve(i))}set_text_formatting(e,i){e&&!e._deleted&&(e.text_formatting=this._resolve(i))}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;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._boxes.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(i=>i._createdAtBar<e),this.syncToPlot()}}ie([C],ee.prototype,"new",1),ie([C],ee.prototype,"set_left",1),ie([C],ee.prototype,"set_right",1),ie([C],ee.prototype,"set_top",1),ie([C],ee.prototype,"set_bottom",1),ie([C],ee.prototype,"set_lefttop",1),ie([C],ee.prototype,"set_rightbottom",1),ie([C],ee.prototype,"set_top_left_point",1),ie([C],ee.prototype,"set_bottom_right_point",1),ie([C],ee.prototype,"set_xloc",1),ie([C],ee.prototype,"set_bgcolor",1),ie([C],ee.prototype,"set_border_color",1),ie([C],ee.prototype,"set_border_width",1),ie([C],ee.prototype,"set_border_style",1),ie([C],ee.prototype,"set_extend",1),ie([C],ee.prototype,"set_text",1),ie([C],ee.prototype,"set_text_color",1),ie([C],ee.prototype,"set_text_size",1),ie([C],ee.prototype,"set_text_halign",1),ie([C],ee.prototype,"set_text_valign",1),ie([C],ee.prototype,"set_text_wrap",1),ie([C],ee.prototype,"set_text_font_family",1),ie([C],ee.prototype,"set_text_formatting",1),ie([C],ee.prototype,"copy",1),ie([C],ee.prototype,"delete",1);var Yd=Object.defineProperty,Xd=(t,e,i)=>e in t?Yd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Gt=(t,e,i)=>Xd(t,typeof e!="symbol"?e+"":e,i);let Zd=0;class yn{constructor(e,i,r){Gt(this,"id"),Gt(this,"line1"),Gt(this,"line2"),Gt(this,"color"),Gt(this,"_deleted"),Gt(this,"_createdAtBar",-1),this.id=Zd++,this.line1=e,this.line2=i,this.color=r,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(){const e=r=>r?{id:r.id,x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2,xloc:r.xloc,extend:r.extend,color:r.color,style:r.style,width:r.width,_deleted:r._deleted}:null,i=!!(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:i,_deleted:this._deleted}}}var Ms=Object.defineProperty,Qd=Object.getOwnPropertyDescriptor,Jd=(t,e,i)=>e in t?Ms(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,lr=(t,e,i,r)=>{for(var n=r>1?void 0:r?Qd(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=(r?a(e,i,n):a(n))||n);return r&&n&&Ms(e,i,n),n},em=(t,e,i)=>Jd(t,typeof e!="symbol"?e+"":e,i);class Ri{constructor(e){this.context=e,em(this,"_linefills",[])}param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._linefills.filter(s=>!s._deleted).map(s=>s.toPlotData()),r=i.filter(s=>!s.force_overlay),n=i.filter(s=>s.force_overlay);this.context.plots.__linefills__.data=[{time:e,value:r,options:{style:"linefill"}}],n.length>0?this.context.plots.__linefills_overlay__={title:"__linefills_overlay__",data:[{time:e,value:n,options:{style:"linefill"}}],options:{style:"linefill",overlay:!0}}:delete this.context.plots.__linefills_overlay__}_resolve(e){return e==null?e:e instanceof Re?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){const i=this._resolve(e);return i==null?i:typeof i=="number"&&isNaN(i)?NaN:i}new(e,i,r){const n=this._resolve(e),s=this._resolve(i),a=r&&typeof r=="object"&&!Array.isArray(r)&&"color"in r?r.color:r,o=this._resolveColor(a);if(n&&s){const c=n.id,u=s.id;for(const p of this._linefills){if(p._deleted)continue;const h=p.line1?.id,f=p.line2?.id;if(h===c&&f===u||h===u&&f===c)return p.color=o,p._createdAtBar=this.context.idx,this.syncToPlot(),p}}const l=new yn(n,s,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),this.syncToPlot(),l}any(...e){if(e.length===1){const i=e[0];return i==null||i instanceof Re||typeof i=="number"&&isNaN(i)?null:i instanceof yn?i:null}return this.new(e[0],e[1],e[2])}set_color(e,i){e&&!e._deleted&&(e.color=this._resolveColor(i))}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(i=>i._createdAtBar<e),this.syncToPlot()}}lr([C],Ri.prototype,"new",1),lr([C],Ri.prototype,"set_color",1),lr([C],Ri.prototype,"delete",1);var tm=Object.defineProperty,im=(t,e,i)=>e in t?tm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,We=(t,e,i)=>im(t,typeof e!="symbol"?e+"":e,i);let rm=0;class cr{constructor(e,i=!1,r=!1,n="bi",s="#2962ff",a="",o="style_solid",l=1,c=!1){We(this,"id"),We(this,"points"),We(this,"curved"),We(this,"closed"),We(this,"xloc"),We(this,"line_color"),We(this,"fill_color"),We(this,"line_style"),We(this,"line_width"),We(this,"force_overlay"),We(this,"_deleted"),We(this,"_createdAtBar",-1),this.id=rm++,this.points=e,this.curved=i,this.closed=r,this.xloc=n,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}}}var Rs=Object.defineProperty,nm=Object.getOwnPropertyDescriptor,sm=(t,e,i)=>e in t?Rs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,_n=(t,e,i,r)=>{for(var n=r>1?void 0:r?nm(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=(r?a(e,i,n):a(n))||n);return r&&n&&Rs(e,i,n),n},am=(t,e,i)=>sm(t,typeof e!="symbol"?e+"":e,i);class Sr{constructor(e){this.context=e,am(this,"_polylines",[])}param(e,i=0,r){return y.from(e).get(i)}_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();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__polylines__.data=[{time:e,value:this._polylines.filter(i=>!i._deleted).map(i=>i.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof Re?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r||i}_extractPoints(e){let i=this._resolve(e);const r=i&&i.array?i.array:i;return Array.isArray(r)?r.filter(n=>n instanceof Ie):[]}new(...e){let i,r=!1,n=!1,s="bi",a="#2962ff",o="",l="style_solid",c=1,u=!1;const p=(b,v)=>Object.prototype.hasOwnProperty.call(b,v),h=b=>{p(b,"curved")&&(r=b.curved),p(b,"closed")&&(n=b.closed),p(b,"xloc")&&(s=b.xloc),p(b,"line_color")&&(a=b.line_color),p(b,"fill_color")&&(o=b.fill_color),p(b,"line_style")&&(l=b.line_style),p(b,"line_width")&&(c=b.line_width),p(b,"force_overlay")&&(u=b.force_overlay)},f=e.length>=1?e[e.length-1]:null,d=e.length>=2&&f&&typeof f=="object"&&!Array.isArray(f)&&!(f instanceof y)&&!(f instanceof Ie);if(e.length===1&&f&&typeof f=="object"&&!Array.isArray(f)&&"points"in f)i=f.points,h(f);else{const b=d?e.slice(0,-1):e;i=b[0],b.length>1&&(r=b[1]),b.length>2&&(n=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]),d&&h(f)}const m=this._extractPoints(i),x=new cr(m,this._resolve(r)??!1,this._resolve(n)??!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(),this.syncToPlot(),x}_enforceMaxCount(){const e=this.context.indicator?.max_polylines_count??50,i=this._polylines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const s of this._polylines){if(n>=r)break;s._deleted||(s._deleted=!0,n++)}}}any(...e){if(e.length===1){const i=e[0];if(i==null||i instanceof Re||typeof i=="number"&&isNaN(i))return null;if(i instanceof cr)return i;if(i instanceof y){const r=i.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof cr)return r}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(i=>i._createdAtBar<e),this.syncToPlot()}}_n([C],Sr.prototype,"new",1),_n([C],Sr.prototype,"delete",1);var om=Object.defineProperty,lm=(t,e,i)=>e in t?om(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,De=(t,e,i)=>lm(t,typeof e!="symbol"?e+"":e,i);let cm=0;class gn{constructor(e="top_right",i=1,r=1,n="",s="",a=0,o="",l=0,c=!1){De(this,"id"),De(this,"position"),De(this,"columns"),De(this,"rows"),De(this,"bgcolor"),De(this,"frame_color"),De(this,"frame_width"),De(this,"border_color"),De(this,"border_width"),De(this,"force_overlay"),De(this,"_deleted"),De(this,"cells"),De(this,"merges"),De(this,"_helper"),this.id=cm++,this.position=e,this.columns=i,this.rows=r,this.bgcolor=n,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<r;u++){this.cells[u]=[];for(let p=0;p<i;p++)this.cells[u][p]=null}}delete(){this._deleted=!0}toPlotData(){const e=this.cells.map(i=>i.map(r=>r?{...r}: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(i=>({...i}))}}setCell(e,i,r){if(i<0||i>=this.rows||e<0||e>=this.columns)return;const n=this.cells[i][e];if(n&&n._merged&&n._merge_parent){const[a,o]=n._merge_parent;if(a===e&&o===i)n._merged=!1,n._merge_parent=void 0;else{this.setCell(a,o,r);return}}const s=n||this._defaultCell();Object.assign(s,r),this.cells[i][e]=s}getCell(e,i){return i<0||i>=this.rows||e<0||e>=this.columns?null:this.cells[i][e]}clearCell(e,i){i<0||i>=this.rows||e<0||e>=this.columns||(this.cells[i][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}}}var Os=Object.defineProperty,um=Object.getOwnPropertyDescriptor,hm=(t,e,i)=>e in t?Os(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,oe=(t,e,i,r)=>{for(var n=r>1?void 0:r?um(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=(r?a(e,i,n):a(n))||n);return r&&n&&Os(e,i,n),n},pm=(t,e,i)=>hm(t,typeof e!="symbol"?e+"":e,i);class ae{constructor(e){this.context=e,pm(this,"_tables",[])}param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__tables__.data=[{time:e,value:this._tables.filter(i=>!i._deleted).map(i=>i.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 i="top_right",r=1,n=1,s="",a="",o=0,l="",c=0,u=!1;const p=e[e.length-1];if(p&&typeof p=="object"&&!Array.isArray(p)&&("bgcolor"in p||"frame_color"in p||"border_color"in p||"position"in p||"columns"in p||"rows"in p)){const f=p,d=e.slice(0,-1);i=d[0]??f.position??i,r=d[1]??f.columns??r,n=d[2]??f.rows??n,s=f.bgcolor??s,a=f.frame_color??a,o=f.frame_width??o,l=f.border_color??l,c=f.border_width??c,u=f.force_overlay??u}else i=e[0]??i,r=e[1]??r,n=e[2]??n,s=e[3]??s,a=e[4]??a,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u;const h=new gn(this._resolve(i)||"top_right",this._resolve(r)||1,this._resolve(n)||1,this._resolve(s)||"",this._resolve(a)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(u)??!1);return h._setHelper(this),this._tables.push(h),this.syncToPlot(),h}any(...e){if(e.length===1){const i=e[0];return i==null||typeof i=="object"&&"__value"in i||typeof i=="number"&&isNaN(i)?null:i instanceof gn?i:null}return this.new(...e)}cell(...e){let i,r,n,s="",a=0,o=0,l="#000000",c="center",u="center",p="normal",h="",f="",d="default";const 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)){const w=m,S=e.slice(0,-1);i=S[0],r=S.length>1?S[1]:w.column??0,n=S.length>2?S[2]:w.row??0,s=S[3]??w.text??s,a=S[4]??w.width??a,o=S[5]??w.height??o,l=S[6]??w.text_color??l,c=S[7]??w.text_halign??c,u=S[8]??w.text_valign??u,p=S[9]??w.text_size??p,h=S[10]??w.bgcolor??h,f=S[11]??w.tooltip??f,d=S[12]??w.text_font_family??d}else i=e[0],r=e[1]??0,n=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,p=e[9]??p,h=e[10]??h,f=e[11]??f,d=e[12]??d;const x=this._resolve(i);if(!x||x._deleted)return;const b=this._resolve(r)??0,v=this._resolve(n)??0;x.setCell(b,v,{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(p)||"normal",bgcolor:this._resolve(h)||"",tooltip:this._resolveText(this._resolve(f)),text_font_family:this._resolve(d)||"default"}),this.syncToPlot()}delete(e){e&&(e._deleted=!0)}clear(...e){let i,r,n,s,a;const 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)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,n=e.length>3?e[2]:f.start_row??0,s=f.end_column??(e.length>4?e[3]:r),a=f.end_row??(e.length>5?e[4]:n)}else i=e[0],r=e[1]??0,n=e[2]??0,s=e[3]??r,a=e[4]??n;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,u=this._resolve(n)??0,p=this._resolve(s)??c,h=this._resolve(a)??u;for(let f=u;f<=h;f++)for(let d=c;d<=p;d++)l.clearCell(d,f);this.syncToPlot()}merge_cells(...e){let i,r,n,s,a;const 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)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,n=e.length>3?e[2]:f.start_row??0,s=f.end_column??(e.length>4?e[3]:0),a=f.end_row??(e.length>5?e[4]:0)}else i=e[0],r=e[1]??0,n=e[2]??0,s=e[3]??0,a=e[4]??0;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,u=this._resolve(n)??0,p=this._resolve(s)??0,h=this._resolve(a)??0;for(let f=u;f<=h;f++)for(let d=c;d<=p;d++)f===u&&d===c||l.setCell(d,f,{_merged:!0,_merge_parent:[c,u]});l.merges.push({startCol:c,startRow:u,endCol:p,endRow:h}),this.syncToPlot()}cell_set_text(e,i,r,n){this._setCellProp(e,i,r,"text",n,!0)}cell_set_bgcolor(e,i,r,n){this._setCellProp(e,i,r,"bgcolor",n)}cell_set_text_color(e,i,r,n){this._setCellProp(e,i,r,"text_color",n)}cell_set_text_size(e,i,r,n){this._setCellProp(e,i,r,"text_size",n)}cell_set_height(e,i,r,n){this._setCellProp(e,i,r,"height",n)}cell_set_width(e,i,r,n){this._setCellProp(e,i,r,"width",n)}cell_set_tooltip(e,i,r,n){this._setCellProp(e,i,r,"tooltip",n,!0)}cell_set_text_halign(e,i,r,n){this._setCellProp(e,i,r,"text_halign",n)}cell_set_text_valign(e,i,r,n){this._setCellProp(e,i,r,"text_valign",n)}cell_set_text_font_family(e,i,r,n){this._setCellProp(e,i,r,"text_font_family",n)}set_position(e,i){const r=this._resolve(e);!r||r._deleted||(r.position=this._resolve(i)||r.position,this.syncToPlot())}set_bgcolor(e,i){const r=this._resolve(e);!r||r._deleted||(r.bgcolor=this._resolve(i)||"",this.syncToPlot())}set_border_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_color=this._resolve(i)||"",this.syncToPlot())}set_border_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_width=this._resolve(i)||0,this.syncToPlot())}set_frame_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_color=this._resolve(i)||"",this.syncToPlot())}set_frame_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_width=this._resolve(i)||0,this.syncToPlot())}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,i,r,n,s,a=!1){const o=this._resolve(e);if(!o||o._deleted)return;const l=this._resolve(i)??0,c=this._resolve(r)??0,u=this._resolve(s);o.setCell(l,c,{[n]:a?this._resolveText(u):u}),this.syncToPlot()}_resolveText(e){return e==null||e!==e?"":String(e)}}oe([C],ae.prototype,"new",1),oe([C],ae.prototype,"cell",1),oe([C],ae.prototype,"delete",1),oe([C],ae.prototype,"clear",1),oe([C],ae.prototype,"merge_cells",1),oe([C],ae.prototype,"cell_set_text",1),oe([C],ae.prototype,"cell_set_bgcolor",1),oe([C],ae.prototype,"cell_set_text_color",1),oe([C],ae.prototype,"cell_set_text_size",1),oe([C],ae.prototype,"cell_set_height",1),oe([C],ae.prototype,"cell_set_width",1),oe([C],ae.prototype,"cell_set_tooltip",1),oe([C],ae.prototype,"cell_set_text_halign",1),oe([C],ae.prototype,"cell_set_text_valign",1),oe([C],ae.prototype,"cell_set_text_font_family",1),oe([C],ae.prototype,"set_position",1),oe([C],ae.prototype,"set_bgcolor",1),oe([C],ae.prototype,"set_border_color",1),oe([C],ae.prototype,"set_border_width",1),oe([C],ae.prototype,"set_frame_color",1),oe([C],ae.prototype,"set_frame_width",1);class fm{constructor(e){this.context=e}param(e,i=0,r){return typeof e=="string"?e:y.from(e).get(i)}inherit(e,i){return this._coerce(i)}new(e,i,r,n,s,a){const o=this._coerce(e),l=this._coerce(i);return o?l?`${o}:${l}`:o:l}modify(e,i,r,n,s){return this._coerce(e)}standard(e){return e==null?this.context?.pine?.syminfo?.tickerid||this.context?.tickerId||"":this._coerce(e)}heikinashi(e){return this._coerce(e)}renko(e,i,r,n,s){return this._coerce(e)}kagi(e,i){return this._coerce(e)}linebreak(e,i){return this._coerce(e)}pointfigure(e,i,r,n,s){return this._coerce(e)}_coerce(e){if(e==null)return"";if(e instanceof y){const i=e.get(0);return i==null?"":String(i)}return typeof e=="number"&&isNaN(e)?"":String(e)}}var dm=Object.defineProperty,mm=(t,e,i)=>e in t?dm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,U=(t,e,i)=>mm(t,typeof e!="symbol"?e+"":e,i);const Er=class Oi{constructor({marketData:e,source:i,tickerId:r,timeframe:n,limit:s,sDate:a,eDate:o,fullContext:l,inputs:c}){U(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([])}),U(this,"indicator"),U(this,"cache",{}),U(this,"taState",{}),U(this,"strategy"),U(this,"isSecondaryContext",!1),U(this,"chartTimezone",null),U(this,"dataVersion",0),U(this,"__maxLoops",5e5),U(this,"NA",NaN),U(this,"warnings",[]),U(this,"alerts",[]),U(this,"_alertMode","realtime"),U(this,"_propOverrides",{}),U(this,"_execTick",0),U(this,"lang"),U(this,"length",0),U(this,"_drawingHelpers",[]),U(this,"pine"),U(this,"idx",0),U(this,"params",{}),U(this,"const",{}),U(this,"var",{}),U(this,"let",{}),U(this,"lctx",new Map),U(this,"result"),U(this,"plots",{}),U(this,"marketData"),U(this,"source"),U(this,"tickerId"),U(this,"timeframe",""),U(this,"limit"),U(this,"sDate"),U(this,"eDate"),U(this,"fullContext"),U(this,"viewportLeft"),U(this,"viewportRight"),U(this,"pineTSCode"),U(this,"inputs",{}),U(this,"_callStack",[]),U(this,"_pathStack",[]),this.marketData=e,this.source=i,this.tickerId=r,this.timeframe=n,this.limit=s,this.sDate=a,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};const u=new Ns(this),p={Type:u.Type.bind(u),na:new Re,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),alert:new Es(this),error:u.error.bind(u),max_bars_back:u.max_bars_back.bind(u),timestamp:u.timestamp.bind(u),time:new sn(this,"openTime"),time_close:new sn(this,"closeTime"),dayofmonth:new vt(this,wt.dayofmonth),dayofweek:new vt(this,wt.dayofweek),hour:new vt(this,wt.hour),minute:new vt(this,wt.minute),month:new vt(this,wt.month),second:new vt(this,wt.second),weekofyear:new vt(this,wt.weekofyear),year:new vt(this,wt.year),bool:u.bool.bind(u),int:u.int.bind(u),float:u.float.bind(u),string:u.string.bind(u)},h=this;this.pine={input:new iu(this),ta:new mp(this),math:new ju(this),request:new Ju(this),array:new Ho(this),map:new ll(this),matrix:new lc(this),ticker:new fm(this),strategy:new qf(this),syminfo:null,timeframe:new id(this),barstate:new pc(this),get bar_index(){return h.data.bar_index},get last_bar_index(){return h.data.close.length-1},get last_bar_time(){const k=h.marketData;return Array.isArray(k)&&k.length>0?k[k.length-1].openTime:h.data.openTime.get(0)},get timenow(){return new Date().getTime()},get time_tradingday(){const k=y.from(h.data.closeTime).get(0);if(isNaN(k))return NaN;const A=h.pine?.syminfo?.timezone||"UTC",O=Rt(k,A);return Date.UTC(O.year,O.month-1,O.day,0,0,0)},get inputs(){return h.inputs},log:new Hf(this),str:new Qf(this),...p,...Eo};const f=p.dayofweek;Object.assign(f,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=f;const d=new yt(this),m=new ks(this),x=new Ts(this);this.bindContextObject(d,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(d,["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");const b=new Ed(this);this.pine.chart={param:b.param.bind(b),bg_color:b.bg_color.bind(b),fg_color:b.fg_color.bind(b),is_standard:b.is_standard.bind(b),is_heikinashi:b.is_heikinashi.bind(b),is_kagi:b.is_kagi.bind(b),is_linebreak:b.is_linebreak.bind(b),is_pnf:b.is_pnf.bind(b),is_range:b.is_range.bind(b),is_renko:b.is_renko.bind(b),point:b.point,get left_visible_bar_time(){if(h.viewportLeft!==void 0)return h.viewportLeft;const k=h.marketData;return Array.isArray(k)&&k.length>0?k[0].openTime:NaN},get right_visible_bar_time(){if(h.viewportRight!==void 0)return h.viewportRight;const k=h.marketData;return Array.isArray(k)&&k.length>0?k[k.length-1].openTime:NaN}};const v=new xe(this);this.bindContextObject(v,["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:()=>v.all});const w=new be(this);this.bindContextObject(w,["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:()=>w.all});const S=new ee(this);this.bindContextObject(S,["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:()=>S.all});const T=new Ri(this);this.bindContextObject(T,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>T.all});const N=new Sr(this);this.bindContextObject(N,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>N.all});const R=new ae(this);this.bindContextObject(R,["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:()=>R.all}),this._drawingHelpers=[v,w,S,T,N,R];const V=new Ic(this);this.bindContextObject(V,["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,i){this.warnings.push({message:e,method:i,bar:this.idx})}rollbackDrawings(e){for(const i of this._drawingHelpers)i.rollbackFromBar(e)}bindContextObject(e,i,r=""){r&&!this.pine[r]&&(this.pine[r]={});const n=r?this.pine[r]:this.pine;for(const s of i)typeof e[s]=="function"?n[s]=e[s].bind(e):n[s]=e[s]}init(e,i,r=0){let n;return i instanceof y?n=i.get(0):Array.isArray(i)?Array.isArray(i[0])?n=i[0]:n=i[i.length-1+r]:n=i,e?e instanceof y?(e.data[e.data.length-1]=n,e):Array.isArray(e)?(e[e.length-1]=n,new y(e)):new y([n]):new y([n])}initVar(e,i){if(e)return e;if(typeof i=="function"&&(i=i()),i instanceof It){const n=i.__def__;for(const s in n)typeof i[s]=="function"&&(i[s]=i[s]())}let r;return i instanceof y?r=i.get(0):Array.isArray(i)?Array.isArray(i[0])?r=i[0]:r=this.precision(i[i.length-1]):r=this.precision(i),new y([r])}precision(e,i=10){const r=i===10?Oi.PRECISION_EPSILON:10**i;return typeof e=="number"?Math.round(e*r)/r:e}param(e,i,r){return typeof e=="string"?e:e instanceof y?i?new y(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[r]||(this.params[r]=[]),Array.isArray(e)?new y(e,i||0):(this.params[r].length===0?this.params[r].push(e):this.params[r][this.params[r].length-1]=e,new y(this.params[r],i||0)))}get(e,i){if(e instanceof y)return e.get(i);if(Array.isArray(e)){const r=e.length-1-i;return r<0||r>=e.length?NaN:e[r]}return e}set(e,i){if(e instanceof y){e.set(0,typeof i=="number"?this.precision(i):i);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=i:e.push(i);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){const i=this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:"",r=i?i+"|"+e:e;this._callStack.push(e),this._pathStack.push(r)}popId(){this._callStack.pop(),this._pathStack.pop()}peekId(){return this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:""}peekCtx(){const e=this.peekId();if(!e)return this;let i=this.lctx.get(e);return i||(i={id:e,let:{},const:{},var:{}},this.lctx.set(e,i)),i}call(e,i,...r){this.pushId(i);try{return e(...r)}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,i){const r=`${e}->${i}`;Oi._deprecationWarningsShown.has(r)||(Oi._deprecationWarningsShown.add(r),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,i):console.warn(`\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}};U(Er,"_deprecationWarningsShown",new Set),U(Er,"PRECISION_EPSILON",10**10);let xn=Er;var ym=[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],$s=[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],_m="\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",Vs="\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",ur={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"},hr="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",gm={5:hr,"5module":hr+" export import",6:hr+" const class extends export import super"},js=/^in(stanceof)?$/,xm=new RegExp("["+Vs+"]"),bm=new RegExp("["+Vs+_m+"]");function Nr(t,e){for(var i=65536,r=0;r<e.length;r+=2){if(i+=e[r],i>t)return!1;if(i+=e[r+1],i>=t)return!0}return!1}function ut(t,e){return t<65?t===36:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&xm.test(String.fromCharCode(t)):e===!1?!1:Nr(t,$s)}function kt(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&&bm.test(String.fromCharCode(t)):e===!1?!1:Nr(t,$s)||Nr(t,ym)}var Y=function(e,i){i===void 0&&(i={}),this.label=e,this.keyword=i.keyword,this.beforeExpr=!!i.beforeExpr,this.startsExpr=!!i.startsExpr,this.isLoop=!!i.isLoop,this.isAssign=!!i.isAssign,this.prefix=!!i.prefix,this.postfix=!!i.postfix,this.binop=i.binop||null,this.updateContext=null};function Ue(t,e){return new Y(t,{beforeExpr:!0,binop:e})}var qe={beforeExpr:!0},Me={startsExpr:!0},Lr={};function H(t,e){return e===void 0&&(e={}),e.keyword=t,Lr[t]=new Y(t,e)}var _={num:new Y("num",Me),regexp:new Y("regexp",Me),string:new Y("string",Me),name:new Y("name",Me),privateId:new Y("privateId",Me),eof:new Y("eof"),bracketL:new Y("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new Y("]"),braceL:new Y("{",{beforeExpr:!0,startsExpr:!0}),braceR:new Y("}"),parenL:new Y("(",{beforeExpr:!0,startsExpr:!0}),parenR:new Y(")"),comma:new Y(",",qe),semi:new Y(";",qe),colon:new Y(":",qe),dot:new Y("."),question:new Y("?",qe),questionDot:new Y("?."),arrow:new Y("=>",qe),template:new Y("template"),invalidTemplate:new Y("invalidTemplate"),ellipsis:new Y("...",qe),backQuote:new Y("`",Me),dollarBraceL:new Y("${",{beforeExpr:!0,startsExpr:!0}),eq:new Y("=",{beforeExpr:!0,isAssign:!0}),assign:new Y("_=",{beforeExpr:!0,isAssign:!0}),incDec:new Y("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new Y("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:Ue("||",1),logicalAND:Ue("&&",2),bitwiseOR:Ue("|",3),bitwiseXOR:Ue("^",4),bitwiseAND:Ue("&",5),equality:Ue("==/!=/===/!==",6),relational:Ue("</>/<=/>=",7),bitShift:Ue("<</>>/>>>",8),plusMin:new Y("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:Ue("%",10),star:Ue("*",10),slash:Ue("/",10),starstar:new Y("**",{beforeExpr:!0}),coalesce:Ue("??",1),_break:H("break"),_case:H("case",qe),_catch:H("catch"),_continue:H("continue"),_debugger:H("debugger"),_default:H("default",qe),_do:H("do",{isLoop:!0,beforeExpr:!0}),_else:H("else",qe),_finally:H("finally"),_for:H("for",{isLoop:!0}),_function:H("function",Me),_if:H("if"),_return:H("return",qe),_switch:H("switch"),_throw:H("throw",qe),_try:H("try"),_var:H("var"),_const:H("const"),_while:H("while",{isLoop:!0}),_with:H("with"),_new:H("new",{beforeExpr:!0,startsExpr:!0}),_this:H("this",Me),_super:H("super",Me),_class:H("class",Me),_extends:H("extends",qe),_export:H("export"),_import:H("import",Me),_null:H("null",Me),_true:H("true",Me),_false:H("false",Me),_in:H("in",{beforeExpr:!0,binop:7}),_instanceof:H("instanceof",{beforeExpr:!0,binop:7}),_typeof:H("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:H("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:H("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},Oe=/\r\n?|\n|\u2028|\u2029/,vm=new RegExp(Oe.source,"g");function ii(t){return t===10||t===13||t===8232||t===8233}function Ls(t,e,i){i===void 0&&(i=t.length);for(var r=e;r<i;r++){var n=t.charCodeAt(r);if(ii(n))return r<i-1&&n===13&&t.charCodeAt(r+1)===10?r+2:r+1}return-1}var Bs=/[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/,Se=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,Fs=Object.prototype,wm=Fs.hasOwnProperty,Sm=Fs.toString,ri=Object.hasOwn||(function(t,e){return wm.call(t,e)}),bn=Array.isArray||(function(t){return Sm.call(t)==="[object Array]"}),vn=Object.create(null);function Ct(t){return vn[t]||(vn[t]=new RegExp("^(?:"+t.replace(/ /g,"|")+")$"))}function gt(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(t&1023)+56320))}var Em=/(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/,xi=function(e,i){this.line=e,this.column=i};xi.prototype.offset=function(e){return new xi(this.line,this.column+e)};var Qi=function(e,i,r){this.start=i,this.end=r,e.sourceFile!==null&&(this.source=e.sourceFile)};function Ws(t,e){for(var i=1,r=0;;){var n=Ls(t,r,e);if(n<0)return new xi(i,e-r);++i,r=n}}var Cr={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},wn=!1;function Nm(t){var e={};for(var i in Cr)e[i]=t&&ri(t,i)?t[i]:Cr[i];if(e.ecmaVersion==="latest"?e.ecmaVersion=1e8:e.ecmaVersion==null?(!wn&&typeof console=="object"&&console.warn&&(wn=!0,console.warn(`Since Acorn 8.0.0, options.ecmaVersion is required.
3
- Defaulting 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),bn(e.onToken)){var r=e.onToken;e.onToken=function(n){return r.push(n)}}if(bn(e.onComment)&&(e.onComment=Cm(e,e.onComment)),e.sourceType==="commonjs"&&e.allowAwaitOutsideFunction)throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs");return e}function Cm(t,e){return function(i,r,n,s,a,o){var l={type:i?"Block":"Line",value:r,start:n,end:s};t.locations&&(l.loc=new Qi(this,a,o)),t.ranges&&(l.range=[n,s]),e.push(l)}}var Ot=1,$t=2,Br=4,Us=8,Fr=16,qs=32,Ji=64,zs=128,Vt=256,wi=512,Ks=1024,er=Ot|$t|Vt;function Wr(t,e){return $t|(t?Br:0)|(e?Us:0)}var Ui=0,Ur=1,bt=2,Hs=3,Gs=4,Ys=5,pe=function(e,i,r){this.options=e=Nm(e),this.sourceFile=e.sourceFile,this.keywords=Ct(gm[e.ecmaVersion>=6?6:e.sourceType==="module"?"5module":5]);var n="";e.allowReserved!==!0&&(n=ur[e.ecmaVersion>=6?6:e.ecmaVersion===5?5:3],e.sourceType==="module"&&(n+=" await")),this.reservedWords=Ct(n);var s=(n?n+" ":"")+ur.strict;this.reservedWordsStrict=Ct(s),this.reservedWordsStrictBind=Ct(s+" "+ur.strictBind),this.input=String(i),this.containsEsc=!1,r?(this.pos=r,this.lineStart=this.input.lastIndexOf(`
4
- `,r-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(Oe).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=_.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=e.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&&e.allowHashBang&&this.input.slice(0,2)==="#!"&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(this.options.sourceType==="commonjs"?$t:Ot),this.regexpState=null,this.privateNameStack=[]},Ye={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}};pe.prototype.parse=function(){var e=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(e)};Ye.inFunction.get=function(){return(this.currentVarScope().flags&$t)>0};Ye.inGenerator.get=function(){return(this.currentVarScope().flags&Us)>0};Ye.inAsync.get=function(){return(this.currentVarScope().flags&Br)>0};Ye.canAwait.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],i=e.flags;if(i&(Vt|wi))return!1;if(i&$t)return(i&Br)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction};Ye.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&Ot)};Ye.allowSuper.get=function(){var t=this.currentThisScope(),e=t.flags;return(e&Ji)>0||this.options.allowSuperOutsideMethod};Ye.allowDirectSuper.get=function(){return(this.currentThisScope().flags&zs)>0};Ye.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())};Ye.allowNewDotTarget.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],i=e.flags;if(i&(Vt|wi)||i&$t&&!(i&Fr))return!0}return!1};Ye.allowUsing.get=function(){var t=this.currentScope(),e=t.flags;return!(e&Ks||!this.inModule&&e&Ot)};Ye.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&Vt)>0};pe.extend=function(){for(var e=[],i=arguments.length;i--;)e[i]=arguments[i];for(var r=this,n=0;n<e.length;n++)r=e[n](r);return r};pe.parse=function(e,i){return new this(i,e).parse()};pe.parseExpressionAt=function(e,i,r){var n=new this(r,e,i);return n.nextToken(),n.parseExpression()};pe.tokenizer=function(e,i){return new this(i,e)};Object.defineProperties(pe.prototype,Ye);var Te=pe.prototype,Im=/^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;Te.strictDirective=function(t){if(this.options.ecmaVersion<5)return!1;for(;;){Se.lastIndex=t,t+=Se.exec(this.input)[0].length;var e=Im.exec(this.input.slice(t));if(!e)return!1;if((e[1]||e[2])==="use strict"){Se.lastIndex=t+e[0].length;var i=Se.exec(this.input),r=i.index+i[0].length,n=this.input.charAt(r);return n===";"||n==="}"||Oe.test(i[0])&&!(/[(`.[+\-/*%<>=,?^&]/.test(n)||n==="!"&&this.input.charAt(r+1)==="=")}t+=e[0].length,Se.lastIndex=t,t+=Se.exec(this.input)[0].length,this.input[t]===";"&&t++}};Te.eat=function(t){return this.type===t?(this.next(),!0):!1};Te.isContextual=function(t){return this.type===_.name&&this.value===t&&!this.containsEsc};Te.eatContextual=function(t){return this.isContextual(t)?(this.next(),!0):!1};Te.expectContextual=function(t){this.eatContextual(t)||this.unexpected()};Te.canInsertSemicolon=function(){return this.type===_.eof||this.type===_.braceR||Oe.test(this.input.slice(this.lastTokEnd,this.start))};Te.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0};Te.semicolon=function(){!this.eat(_.semi)&&!this.insertSemicolon()&&this.unexpected()};Te.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0};Te.expect=function(t){this.eat(t)||this.unexpected()};Te.unexpected=function(t){this.raise(t??this.start,"Unexpected token")};var tr=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};Te.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element");var i=e?t.parenthesizedAssign:t.parenthesizedBind;i>-1&&this.raiseRecoverable(i,e?"Assigning to rvalue":"Parenthesized pattern")}};Te.checkExpressionErrors=function(t,e){if(!t)return!1;var i=t.shorthandAssign,r=t.doubleProto;if(!e)return i>=0||r>=0;i>=0&&this.raise(i,"Shorthand property assignments are valid only in destructuring patterns"),r>=0&&this.raiseRecoverable(r,"Redefinition of __proto__ property")};Te.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")};Te.isSimpleAssignTarget=function(t){return t.type==="ParenthesizedExpression"?this.isSimpleAssignTarget(t.expression):t.type==="Identifier"||t.type==="MemberExpression"};var M=pe.prototype;M.parseTopLevel=function(t){var e=Object.create(null);for(t.body||(t.body=[]);this.type!==_.eof;){var i=this.parseStatement(null,!0,e);t.body.push(i)}if(this.inModule)for(var r=0,n=Object.keys(this.undefinedExports);r<n.length;r+=1){var s=n[r];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 qr={kind:"loop"},km={kind:"switch"};M.isLet=function(t){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;Se.lastIndex=this.pos;var e=Se.exec(this.input),i=this.pos+e[0].length,r=this.fullCharCodeAt(i);if(r===91||r===92)return!0;if(t)return!1;if(r===123)return!0;if(ut(r)){var n=i;do i+=r<=65535?1:2;while(kt(r=this.fullCharCodeAt(i)));if(r===92)return!0;var s=this.input.slice(n,i);if(!js.test(s))return!0}return!1};M.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;Se.lastIndex=this.pos;var t=Se.exec(this.input),e=this.pos+t[0].length,i;return!Oe.test(this.input.slice(this.pos,e))&&this.input.slice(e,e+8)==="function"&&(e+8===this.input.length||!(kt(i=this.fullCharCodeAt(e+8))||i===92))};M.isUsingKeyword=function(t,e){if(this.options.ecmaVersion<17||!this.isContextual(t?"await":"using"))return!1;Se.lastIndex=this.pos;var i=Se.exec(this.input),r=this.pos+i[0].length;if(Oe.test(this.input.slice(this.pos,r)))return!1;if(t){var n=r+5,s;if(this.input.slice(r,n)!=="using"||n===this.input.length||kt(s=this.fullCharCodeAt(n))||s===92)return!1;Se.lastIndex=n;var a=Se.exec(this.input);if(r=n+a[0].length,a&&Oe.test(this.input.slice(n,r)))return!1}var o=this.fullCharCodeAt(r);if(!ut(o)&&o!==92)return!1;var l=r;do r+=o<=65535?1:2;while(kt(o=this.fullCharCodeAt(r)));if(o===92)return!0;var c=this.input.slice(l,r);return!(js.test(c)||e&&c==="of")};M.isAwaitUsing=function(t){return this.isUsingKeyword(!0,t)};M.isUsing=function(t){return this.isUsingKeyword(!1,t)};M.parseStatement=function(t,e,i){var r=this.type,n=this.startNode(),s;switch(this.isLet(t)&&(r=_._var,s="let"),r){case _._break:case _._continue:return this.parseBreakContinueStatement(n,r.keyword);case _._debugger:return this.parseDebuggerStatement(n);case _._do:return this.parseDoStatement(n);case _._for:return this.parseForStatement(n);case _._function:return t&&(this.strict||t!=="if"&&t!=="label")&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(n,!1,!t);case _._class:return t&&this.unexpected(),this.parseClass(n,!0);case _._if:return this.parseIfStatement(n);case _._return:return this.parseReturnStatement(n);case _._switch:return this.parseSwitchStatement(n);case _._throw:return this.parseThrowStatement(n);case _._try:return this.parseTryStatement(n);case _._const:case _._var:return s=s||this.value,t&&s!=="var"&&this.unexpected(),this.parseVarStatement(n,s);case _._while:return this.parseWhileStatement(n);case _._with:return this.parseWithStatement(n);case _.braceL:return this.parseBlock(!0,n);case _.semi:return this.parseEmptyStatement(n);case _._export:case _._import:if(this.options.ecmaVersion>10&&r===_._import){Se.lastIndex=this.pos;var a=Se.exec(this.input),o=this.pos+a[0].length,l=this.input.charCodeAt(o);if(l===40||l===46)return this.parseExpressionStatement(n,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'")),r===_._import?this.parseImport(n):this.parseExport(n,i);default:if(this.isAsyncFunction())return t&&this.unexpected(),this.next(),this.parseFunctionStatement(n,!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(n,!1,c),this.semicolon(),this.finishNode(n,"VariableDeclaration");var u=this.value,p=this.parseExpression();return r===_.name&&p.type==="Identifier"&&this.eat(_.colon)?this.parseLabeledStatement(n,u,p,t):this.parseExpressionStatement(n,p)}};M.parseBreakContinueStatement=function(t,e){var i=e==="break";this.next(),this.eat(_.semi)||this.insertSemicolon()?t.label=null:this.type!==_.name?this.unexpected():(t.label=this.parseIdent(),this.semicolon());for(var r=0;r<this.labels.length;++r){var n=this.labels[r];if((t.label==null||n.name===t.label.name)&&(n.kind!=null&&(i||n.kind==="loop")||t.label&&i))break}return r===this.labels.length&&this.raise(t.start,"Unsyntactic "+e),this.finishNode(t,i?"BreakStatement":"ContinueStatement")};M.parseDebuggerStatement=function(t){return this.next(),this.semicolon(),this.finishNode(t,"DebuggerStatement")};M.parseDoStatement=function(t){return this.next(),this.labels.push(qr),t.body=this.parseStatement("do"),this.labels.pop(),this.expect(_._while),t.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(_.semi):this.semicolon(),this.finishNode(t,"DoWhileStatement")};M.parseForStatement=function(t){this.next();var e=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(qr),this.enterScope(0),this.expect(_.parenL),this.type===_.semi)return e>-1&&this.unexpected(e),this.parseFor(t,null);var i=this.isLet();if(this.type===_._var||this.type===_._const||i){var r=this.startNode(),n=i?"let":this.value;return this.next(),this.parseVar(r,!0,n),this.finishNode(r,"VariableDeclaration"),this.parseForAfterInit(t,r,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 tr,p=this.start,h=e>-1?this.parseExprSubscripts(u,"await"):this.parseExpression(!0,u);return this.type===_._in||(a=this.options.ecmaVersion>=6&&this.isContextual("of"))?(e>-1?(this.type===_._in&&this.unexpected(e),t.await=!0):a&&this.options.ecmaVersion>=8&&(h.start===p&&!c&&h.type==="Identifier"&&h.name==="async"?this.unexpected():this.options.ecmaVersion>=9&&(t.await=!1)),s&&a&&this.raise(h.start,"The left-hand side of a for-of loop may not start with 'let'."),this.toAssignable(h,!1,u),this.checkLValPattern(h),this.parseForIn(t,h)):(this.checkExpressionErrors(u,!0),e>-1&&this.unexpected(e),this.parseFor(t,h))};M.parseForAfterInit=function(t,e,i){return(this.type===_._in||this.options.ecmaVersion>=6&&this.isContextual("of"))&&e.declarations.length===1?(this.options.ecmaVersion>=9&&(this.type===_._in?i>-1&&this.unexpected(i):t.await=i>-1),this.parseForIn(t,e)):(i>-1&&this.unexpected(i),this.parseFor(t,e))};M.parseFunctionStatement=function(t,e,i){return this.next(),this.parseFunction(t,fi|(i?0:Ir),!1,e)};M.parseIfStatement=function(t){return this.next(),t.test=this.parseParenExpression(),t.consequent=this.parseStatement("if"),t.alternate=this.eat(_._else)?this.parseStatement("if"):null,this.finishNode(t,"IfStatement")};M.parseReturnStatement=function(t){return this.allowReturn||this.raise(this.start,"'return' outside of function"),this.next(),this.eat(_.semi)||this.insertSemicolon()?t.argument=null:(t.argument=this.parseExpression(),this.semicolon()),this.finishNode(t,"ReturnStatement")};M.parseSwitchStatement=function(t){this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(_.braceL),this.labels.push(km),this.enterScope(Ks);for(var e,i=!1;this.type!==_.braceR;)if(this.type===_._case||this.type===_._default){var r=this.type===_._case;e&&this.finishNode(e,"SwitchCase"),t.cases.push(e=this.startNode()),e.consequent=[],this.next(),r?e.test=this.parseExpression():(i&&this.raiseRecoverable(this.lastTokStart,"Multiple default clauses"),i=!0,e.test=null),this.expect(_.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")};M.parseThrowStatement=function(t){return this.next(),Oe.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 Tm=[];M.parseCatchClauseParam=function(){var t=this.parseBindingAtom(),e=t.type==="Identifier";return this.enterScope(e?qs:0),this.checkLValPattern(t,e?Gs:bt),this.expect(_.parenR),t};M.parseTryStatement=function(t){if(this.next(),t.block=this.parseBlock(),t.handler=null,this.type===_._catch){var e=this.startNode();this.next(),this.eat(_.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(_._finally)?this.parseBlock():null,!t.handler&&!t.finalizer&&this.raise(t.start,"Missing catch or finally clause"),this.finishNode(t,"TryStatement")};M.parseVarStatement=function(t,e,i){return this.next(),this.parseVar(t,!1,e,i),this.semicolon(),this.finishNode(t,"VariableDeclaration")};M.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(qr),t.body=this.parseStatement("while"),this.labels.pop(),this.finishNode(t,"WhileStatement")};M.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")};M.parseEmptyStatement=function(t){return this.next(),this.finishNode(t,"EmptyStatement")};M.parseLabeledStatement=function(t,e,i,r){for(var n=0,s=this.labels;n<s.length;n+=1){var a=s[n];a.name===e&&this.raise(i.start,"Label '"+e+"' is already declared")}for(var o=this.type.isLoop?"loop":this.type===_._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(r?r.indexOf("label")===-1?r+"label":r:"label"),this.labels.pop(),t.label=i,this.finishNode(t,"LabeledStatement")};M.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")};M.parseBlock=function(t,e,i){for(t===void 0&&(t=!0),e===void 0&&(e=this.startNode()),e.body=[],this.expect(_.braceL),t&&this.enterScope(0);this.type!==_.braceR;){var r=this.parseStatement(null);e.body.push(r)}return i&&(this.strict=!1),this.next(),t&&this.exitScope(),this.finishNode(e,"BlockStatement")};M.parseFor=function(t,e){return t.init=e,this.expect(_.semi),t.test=this.type===_.semi?null:this.parseExpression(),this.expect(_.semi),t.update=this.type===_.parenR?null:this.parseExpression(),this.expect(_.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,"ForStatement")};M.parseForIn=function(t,e){var i=this.type===_._in;return this.next(),e.type==="VariableDeclaration"&&e.declarations[0].init!=null&&(!i||this.options.ecmaVersion<8||this.strict||e.kind!=="var"||e.declarations[0].id.type!=="Identifier")&&this.raise(e.start,(i?"for-in":"for-of")+" loop variable declaration may not have an initializer"),t.left=e,t.right=i?this.parseExpression():this.parseMaybeAssign(),this.expect(_.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,i?"ForInStatement":"ForOfStatement")};M.parseVar=function(t,e,i,r){for(t.declarations=[],t.kind=i;;){var n=this.startNode();if(this.parseVarId(n,i),this.eat(_.eq)?n.init=this.parseMaybeAssign(e):!r&&i==="const"&&!(this.type===_._in||this.options.ecmaVersion>=6&&this.isContextual("of"))?this.unexpected():!r&&(i==="using"||i==="await using")&&this.options.ecmaVersion>=17&&this.type!==_._in&&!this.isContextual("of")?this.raise(this.lastTokEnd,"Missing initializer in "+i+" declaration"):!r&&n.id.type!=="Identifier"&&!(e&&(this.type===_._in||this.isContextual("of")))?this.raise(this.lastTokEnd,"Complex binding patterns require an initialization value"):n.init=null,t.declarations.push(this.finishNode(n,"VariableDeclarator")),!this.eat(_.comma))break}return t};M.parseVarId=function(t,e){t.id=e==="using"||e==="await using"?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(t.id,e==="var"?Ur:bt,!1)};var fi=1,Ir=2,Xs=4;M.parseFunction=function(t,e,i,r,n){this.initFunction(t),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!r)&&(this.type===_.star&&e&Ir&&this.unexpected(),t.generator=this.eat(_.star)),this.options.ecmaVersion>=8&&(t.async=!!r),e&fi&&(t.id=e&Xs&&this.type!==_.name?null:this.parseIdent(),t.id&&!(e&Ir)&&this.checkLValSimple(t.id,this.strict||t.generator||t.async?this.treatFunctionsAsVar?Ur:bt:Hs));var s=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(Wr(t.async,t.generator)),e&fi||(t.id=this.type===_.name?this.parseIdent():null),this.parseFunctionParams(t),this.parseFunctionBody(t,i,!1,n),this.yieldPos=s,this.awaitPos=a,this.awaitIdentPos=o,this.finishNode(t,e&fi?"FunctionDeclaration":"FunctionExpression")};M.parseFunctionParams=function(t){this.expect(_.parenL),t.params=this.parseBindingList(_.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()};M.parseClass=function(t,e){this.next();var i=this.strict;this.strict=!0,this.parseClassId(t,e),this.parseClassSuper(t);var r=this.enterClassBody(),n=this.startNode(),s=!1;for(n.body=[],this.expect(_.braceL);this.type!==_.braceR;){var a=this.parseClassElement(t.superClass!==null);a&&(n.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"&&Am(r,a)&&this.raiseRecoverable(a.key.start,"Identifier '#"+a.key.name+"' has already been declared"))}return this.strict=i,this.next(),t.body=this.finishNode(n,"ClassBody"),this.exitClassBody(),this.finishNode(t,e?"ClassDeclaration":"ClassExpression")};M.parseClassElement=function(t){if(this.eat(_.semi))return null;var e=this.options.ecmaVersion,i=this.startNode(),r="",n=!1,s=!1,a="method",o=!1;if(this.eatContextual("static")){if(e>=13&&this.eat(_.braceL))return this.parseClassStaticBlock(i),i;this.isClassElementNameStart()||this.type===_.star?o=!0:r="static"}if(i.static=o,!r&&e>=8&&this.eatContextual("async")&&((this.isClassElementNameStart()||this.type===_.star)&&!this.canInsertSemicolon()?s=!0:r="async"),!r&&(e>=9||!s)&&this.eat(_.star)&&(n=!0),!r&&!s&&!n){var l=this.value;(this.eatContextual("get")||this.eatContextual("set"))&&(this.isClassElementNameStart()?a=l:r=l)}if(r?(i.computed=!1,i.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),i.key.name=r,this.finishNode(i.key,"Identifier")):this.parseClassElementName(i),e<13||this.type===_.parenL||a!=="method"||n||s){var c=!i.static&&qi(i,"constructor"),u=c&&t;c&&a!=="method"&&this.raise(i.key.start,"Constructor can't have get/set modifier"),i.kind=c?"constructor":a,this.parseClassMethod(i,n,s,u)}else this.parseClassField(i);return i};M.isClassElementNameStart=function(){return this.type===_.name||this.type===_.privateId||this.type===_.num||this.type===_.string||this.type===_.bracketL||this.type.keyword};M.parseClassElementName=function(t){this.type===_.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)};M.parseClassMethod=function(t,e,i,r){var n=t.key;t.kind==="constructor"?(e&&this.raise(n.start,"Constructor can't be a generator"),i&&this.raise(n.start,"Constructor can't be an async method")):t.static&&qi(t,"prototype")&&this.raise(n.start,"Classes may not have a static property named prototype");var s=t.value=this.parseMethod(e,i,r);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")};M.parseClassField=function(t){return qi(t,"constructor")?this.raise(t.key.start,"Classes can't have a field named 'constructor'"):t.static&&qi(t,"prototype")&&this.raise(t.key.start,"Classes can't have a static field named 'prototype'"),this.eat(_.eq)?(this.enterScope(wi|Ji),t.value=this.parseMaybeAssign(),this.exitScope()):t.value=null,this.semicolon(),this.finishNode(t,"PropertyDefinition")};M.parseClassStaticBlock=function(t){t.body=[];var e=this.labels;for(this.labels=[],this.enterScope(Vt|Ji);this.type!==_.braceR;){var i=this.parseStatement(null);t.body.push(i)}return this.next(),this.exitScope(),this.labels=e,this.finishNode(t,"StaticBlock")};M.parseClassId=function(t,e){this.type===_.name?(t.id=this.parseIdent(),e&&this.checkLValSimple(t.id,bt,!1)):(e===!0&&this.unexpected(),t.id=null)};M.parseClassSuper=function(t){t.superClass=this.eat(_._extends)?this.parseExprSubscripts(null,!1):null};M.enterClassBody=function(){var t={declared:Object.create(null),used:[]};return this.privateNameStack.push(t),t.declared};M.exitClassBody=function(){var t=this.privateNameStack.pop(),e=t.declared,i=t.used;if(this.options.checkPrivateFields)for(var r=this.privateNameStack.length,n=r===0?null:this.privateNameStack[r-1],s=0;s<i.length;++s){var a=i[s];ri(e,a.name)||(n?n.used.push(a):this.raiseRecoverable(a.start,"Private field '#"+a.name+"' must be declared in an enclosing class"))}};function Am(t,e){var i=e.key.name,r=t[i],n="true";return e.type==="MethodDefinition"&&(e.kind==="get"||e.kind==="set")&&(n=(e.static?"s":"i")+e.kind),r==="iget"&&n==="iset"||r==="iset"&&n==="iget"||r==="sget"&&n==="sset"||r==="sset"&&n==="sget"?(t[i]="true",!1):r?!0:(t[i]=n,!1)}function qi(t,e){var i=t.computed,r=t.key;return!i&&(r.type==="Identifier"&&r.name===e||r.type==="Literal"&&r.value===e)}M.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!==_.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ExportAllDeclaration")};M.parseExport=function(t,e){if(this.next(),this.eat(_.star))return this.parseExportAllDeclaration(t,e);if(this.eat(_._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!==_.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause());else{for(var i=0,r=t.specifiers;i<r.length;i+=1){var n=r[i];this.checkUnreserved(n.local),this.checkLocalExport(n.local),n.local.type==="Literal"&&this.raise(n.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")};M.parseExportDeclaration=function(t){return this.parseStatement(null)};M.parseExportDefaultDeclaration=function(){var t;if(this.type===_._function||(t=this.isAsyncFunction())){var e=this.startNode();return this.next(),t&&this.next(),this.parseFunction(e,fi|Xs,!1,t)}else if(this.type===_._class){var i=this.startNode();return this.parseClass(i,"nullableID")}else{var r=this.parseMaybeAssign();return this.semicolon(),r}};M.checkExport=function(t,e,i){t&&(typeof e!="string"&&(e=e.type==="Identifier"?e.name:e.value),ri(t,e)&&this.raiseRecoverable(i,"Duplicate export '"+e+"'"),t[e]=!0)};M.checkPatternExport=function(t,e){var i=e.type;if(i==="Identifier")this.checkExport(t,e,e.start);else if(i==="ObjectPattern")for(var r=0,n=e.properties;r<n.length;r+=1){var s=n[r];this.checkPatternExport(t,s)}else if(i==="ArrayPattern")for(var a=0,o=e.elements;a<o.length;a+=1){var l=o[a];l&&this.checkPatternExport(t,l)}else i==="Property"?this.checkPatternExport(t,e.value):i==="AssignmentPattern"?this.checkPatternExport(t,e.left):i==="RestElement"&&this.checkPatternExport(t,e.argument)};M.checkVariableExport=function(t,e){if(t)for(var i=0,r=e;i<r.length;i+=1){var n=r[i];this.checkPatternExport(t,n.id)}};M.shouldParseExportStatement=function(){return this.type.keyword==="var"||this.type.keyword==="const"||this.type.keyword==="class"||this.type.keyword==="function"||this.isLet()||this.isAsyncFunction()};M.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")};M.parseExportSpecifiers=function(t){var e=[],i=!0;for(this.expect(_.braceL);!this.eat(_.braceR);){if(i)i=!1;else if(this.expect(_.comma),this.afterTrailingComma(_.braceR))break;e.push(this.parseExportSpecifier(t))}return e};M.parseImport=function(t){return this.next(),this.type===_.string?(t.specifiers=Tm,t.source=this.parseExprAtom()):(t.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),t.source=this.type===_.string?this.parseExprAtom():this.unexpected()),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ImportDeclaration")};M.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,bt),this.finishNode(t,"ImportSpecifier")};M.parseImportDefaultSpecifier=function(){var t=this.startNode();return t.local=this.parseIdent(),this.checkLValSimple(t.local,bt),this.finishNode(t,"ImportDefaultSpecifier")};M.parseImportNamespaceSpecifier=function(){var t=this.startNode();return this.next(),this.expectContextual("as"),t.local=this.parseIdent(),this.checkLValSimple(t.local,bt),this.finishNode(t,"ImportNamespaceSpecifier")};M.parseImportSpecifiers=function(){var t=[],e=!0;if(this.type===_.name&&(t.push(this.parseImportDefaultSpecifier()),!this.eat(_.comma)))return t;if(this.type===_.star)return t.push(this.parseImportNamespaceSpecifier()),t;for(this.expect(_.braceL);!this.eat(_.braceR);){if(e)e=!1;else if(this.expect(_.comma),this.afterTrailingComma(_.braceR))break;t.push(this.parseImportSpecifier())}return t};M.parseWithClause=function(){var t=[];if(!this.eat(_._with))return t;this.expect(_.braceL);for(var e={},i=!0;!this.eat(_.braceR);){if(i)i=!1;else if(this.expect(_.comma),this.afterTrailingComma(_.braceR))break;var r=this.parseImportAttribute(),n=r.key.type==="Identifier"?r.key.name:r.key.value;ri(e,n)&&this.raiseRecoverable(r.key.start,"Duplicate attribute key '"+n+"'"),e[n]=!0,t.push(r)}return t};M.parseImportAttribute=function(){var t=this.startNode();return t.key=this.type===_.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never"),this.expect(_.colon),this.type!==_.string&&this.unexpected(),t.value=this.parseExprAtom(),this.finishNode(t,"ImportAttribute")};M.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===_.string){var t=this.parseLiteral(this.value);return Em.test(t.value)&&this.raise(t.start,"An export name cannot include a lone surrogate."),t}return this.parseIdent(!0)};M.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)};M.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 Xe=pe.prototype;Xe.toAssignable=function(t,e,i){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",i&&this.checkPatternErrors(i,!0);for(var r=0,n=t.properties;r<n.length;r+=1){var s=n[r];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",i&&this.checkPatternErrors(i,!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,i);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 i&&this.checkPatternErrors(i,!0);return t};Xe.toAssignableList=function(t,e){for(var i=t.length,r=0;r<i;r++){var n=t[r];n&&this.toAssignable(n,e)}if(i){var s=t[i-1];this.options.ecmaVersion===6&&e&&s&&s.type==="RestElement"&&s.argument.type!=="Identifier"&&this.unexpected(s.argument.start)}return t};Xe.parseSpread=function(t){var e=this.startNode();return this.next(),e.argument=this.parseMaybeAssign(!1,t),this.finishNode(e,"SpreadElement")};Xe.parseRestBinding=function(){var t=this.startNode();return this.next(),this.options.ecmaVersion===6&&this.type!==_.name&&this.unexpected(),t.argument=this.parseBindingAtom(),this.finishNode(t,"RestElement")};Xe.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case _.bracketL:var t=this.startNode();return this.next(),t.elements=this.parseBindingList(_.bracketR,!0,!0),this.finishNode(t,"ArrayPattern");case _.braceL:return this.parseObj(!0)}return this.parseIdent()};Xe.parseBindingList=function(t,e,i,r){for(var n=[],s=!0;!this.eat(t);)if(s?s=!1:this.expect(_.comma),e&&this.type===_.comma)n.push(null);else{if(i&&this.afterTrailingComma(t))break;if(this.type===_.ellipsis){var a=this.parseRestBinding();this.parseBindingListItem(a),n.push(a),this.type===_.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.expect(t);break}else n.push(this.parseAssignableListItem(r))}return n};Xe.parseAssignableListItem=function(t){var e=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(e),e};Xe.parseBindingListItem=function(t){return t};Xe.parseMaybeDefault=function(t,e,i){if(i=i||this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(_.eq))return i;var r=this.startNodeAt(t,e);return r.left=i,r.right=this.parseMaybeAssign(),this.finishNode(r,"AssignmentPattern")};Xe.checkLValSimple=function(t,e,i){e===void 0&&(e=Ui);var r=e!==Ui;switch(t.type){case"Identifier":this.strict&&this.reservedWordsStrictBind.test(t.name)&&this.raiseRecoverable(t.start,(r?"Binding ":"Assigning to ")+t.name+" in strict mode"),r&&(e===bt&&t.name==="let"&&this.raiseRecoverable(t.start,"let is disallowed as a lexically bound name"),i&&(ri(i,t.name)&&this.raiseRecoverable(t.start,"Argument name clash"),i[t.name]=!0),e!==Ys&&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":r&&this.raiseRecoverable(t.start,"Binding member expression");break;case"ParenthesizedExpression":return r&&this.raiseRecoverable(t.start,"Binding parenthesized expression"),this.checkLValSimple(t.expression,e,i);default:this.raise(t.start,(r?"Binding":"Assigning to")+" rvalue")}};Xe.checkLValPattern=function(t,e,i){switch(e===void 0&&(e=Ui),t.type){case"ObjectPattern":for(var r=0,n=t.properties;r<n.length;r+=1){var s=n[r];this.checkLValInnerPattern(s,e,i)}break;case"ArrayPattern":for(var a=0,o=t.elements;a<o.length;a+=1){var l=o[a];l&&this.checkLValInnerPattern(l,e,i)}break;default:this.checkLValSimple(t,e,i)}};Xe.checkLValInnerPattern=function(t,e,i){switch(e===void 0&&(e=Ui),t.type){case"Property":this.checkLValInnerPattern(t.value,e,i);break;case"AssignmentPattern":this.checkLValPattern(t.left,e,i);break;case"RestElement":this.checkLValPattern(t.argument,e,i);break;default:this.checkLValPattern(t,e,i)}};var Je=function(e,i,r,n,s){this.token=e,this.isExpr=!!i,this.preserveSpace=!!r,this.override=n,this.generator=!!s},re={b_stat:new Je("{",!1),b_expr:new Je("{",!0),b_tmpl:new Je("${",!1),p_stat:new Je("(",!1),p_expr:new Je("(",!0),q_tmpl:new Je("`",!0,!0,function(t){return t.tryReadTemplateToken()}),f_stat:new Je("function",!1),f_expr:new Je("function",!0),f_expr_gen:new Je("function",!0,!1,null,!0),f_gen:new Je("function",!1,!1,null,!0)},ni=pe.prototype;ni.initialContext=function(){return[re.b_stat]};ni.curContext=function(){return this.context[this.context.length-1]};ni.braceIsBlock=function(t){var e=this.curContext();return e===re.f_expr||e===re.f_stat?!0:t===_.colon&&(e===re.b_stat||e===re.b_expr)?!e.isExpr:t===_._return||t===_.name&&this.exprAllowed?Oe.test(this.input.slice(this.lastTokEnd,this.start)):t===_._else||t===_.semi||t===_.eof||t===_.parenR||t===_.arrow?!0:t===_.braceL?e===re.b_stat:t===_._var||t===_._const||t===_.name?!1:!this.exprAllowed};ni.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};ni.updateContext=function(t){var e,i=this.type;i.keyword&&t===_.dot?this.exprAllowed=!1:(e=i.updateContext)?e.call(this,t):this.exprAllowed=i.beforeExpr};ni.overrideContext=function(t){this.curContext()!==t&&(this.context[this.context.length-1]=t)};_.parenR.updateContext=_.braceR.updateContext=function(){if(this.context.length===1){this.exprAllowed=!0;return}var t=this.context.pop();t===re.b_stat&&this.curContext().token==="function"&&(t=this.context.pop()),this.exprAllowed=!t.isExpr};_.braceL.updateContext=function(t){this.context.push(this.braceIsBlock(t)?re.b_stat:re.b_expr),this.exprAllowed=!0};_.dollarBraceL.updateContext=function(){this.context.push(re.b_tmpl),this.exprAllowed=!0};_.parenL.updateContext=function(t){var e=t===_._if||t===_._for||t===_._with||t===_._while;this.context.push(e?re.p_stat:re.p_expr),this.exprAllowed=!0};_.incDec.updateContext=function(){};_._function.updateContext=_._class.updateContext=function(t){t.beforeExpr&&t!==_._else&&!(t===_.semi&&this.curContext()!==re.p_stat)&&!(t===_._return&&Oe.test(this.input.slice(this.lastTokEnd,this.start)))&&!((t===_.colon||t===_.braceL)&&this.curContext()===re.b_stat)?this.context.push(re.f_expr):this.context.push(re.f_stat),this.exprAllowed=!1};_.colon.updateContext=function(){this.curContext().token==="function"&&this.context.pop(),this.exprAllowed=!0};_.backQuote.updateContext=function(){this.curContext()===re.q_tmpl?this.context.pop():this.context.push(re.q_tmpl),this.exprAllowed=!1};_.star.updateContext=function(t){if(t===_._function){var e=this.context.length-1;this.context[e]===re.f_expr?this.context[e]=re.f_expr_gen:this.context[e]=re.f_gen}this.exprAllowed=!0};_.name.updateContext=function(t){var e=!1;this.options.ecmaVersion>=6&&t!==_.dot&&(this.value==="of"&&!this.exprAllowed||this.value==="yield"&&this.inGeneratorContext())&&(e=!0),this.exprAllowed=e};var B=pe.prototype;B.checkPropClash=function(t,e,i){if(!(this.options.ecmaVersion>=9&&t.type==="SpreadElement")&&!(this.options.ecmaVersion>=6&&(t.computed||t.method||t.shorthand))){var r=t.key,n;switch(r.type){case"Identifier":n=r.name;break;case"Literal":n=String(r.value);break;default:return}var s=t.kind;if(this.options.ecmaVersion>=6){n==="__proto__"&&s==="init"&&(e.proto&&(i?i.doubleProto<0&&(i.doubleProto=r.start):this.raiseRecoverable(r.start,"Redefinition of __proto__ property")),e.proto=!0);return}n="$"+n;var a=e[n];if(a){var o;s==="init"?o=this.strict&&a.init||a.get||a.set:o=a.init||a[s],o&&this.raiseRecoverable(r.start,"Redefinition of property")}else a=e[n]={init:!1,get:!1,set:!1};a[s]=!0}};B.parseExpression=function(t,e){var i=this.start,r=this.startLoc,n=this.parseMaybeAssign(t,e);if(this.type===_.comma){var s=this.startNodeAt(i,r);for(s.expressions=[n];this.eat(_.comma);)s.expressions.push(this.parseMaybeAssign(t,e));return this.finishNode(s,"SequenceExpression")}return n};B.parseMaybeAssign=function(t,e,i){if(this.isContextual("yield")){if(this.inGenerator)return this.parseYield(t);this.exprAllowed=!1}var r=!1,n=-1,s=-1,a=-1;e?(n=e.parenthesizedAssign,s=e.trailingComma,a=e.doubleProto,e.parenthesizedAssign=e.trailingComma=-1):(e=new tr,r=!0);var o=this.start,l=this.startLoc;(this.type===_.parenL||this.type===_.name)&&(this.potentialArrowAt=this.start,this.potentialArrowInForAwait=t==="await");var c=this.parseMaybeConditional(t,e);if(i&&(c=i.call(this,c,o,l)),this.type.isAssign){var u=this.startNodeAt(o,l);return u.operator=this.value,this.type===_.eq&&(c=this.toAssignable(c,!1,e)),r||(e.parenthesizedAssign=e.trailingComma=e.doubleProto=-1),e.shorthandAssign>=c.start&&(e.shorthandAssign=-1),this.type===_.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 r&&this.checkExpressionErrors(e,!0);return n>-1&&(e.parenthesizedAssign=n),s>-1&&(e.trailingComma=s),c};B.parseMaybeConditional=function(t,e){var i=this.start,r=this.startLoc,n=this.parseExprOps(t,e);if(this.checkExpressionErrors(e))return n;if(this.eat(_.question)){var s=this.startNodeAt(i,r);return s.test=n,s.consequent=this.parseMaybeAssign(),this.expect(_.colon),s.alternate=this.parseMaybeAssign(t),this.finishNode(s,"ConditionalExpression")}return n};B.parseExprOps=function(t,e){var i=this.start,r=this.startLoc,n=this.parseMaybeUnary(e,!1,!1,t);return this.checkExpressionErrors(e)||n.start===i&&n.type==="ArrowFunctionExpression"?n:this.parseExprOp(n,i,r,-1,t)};B.parseExprOp=function(t,e,i,r,n){var s=this.type.binop;if(s!=null&&(!n||this.type!==_._in)&&s>r){var a=this.type===_.logicalOR||this.type===_.logicalAND,o=this.type===_.coalesce;o&&(s=_.logicalAND.binop);var l=this.value;this.next();var c=this.start,u=this.startLoc,p=this.parseExprOp(this.parseMaybeUnary(null,!1,!1,n),c,u,s,n),h=this.buildBinary(e,i,t,p,l,a||o);return(a&&this.type===_.coalesce||o&&(this.type===_.logicalOR||this.type===_.logicalAND))&&this.raiseRecoverable(this.start,"Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"),this.parseExprOp(h,e,i,r,n)}return t};B.buildBinary=function(t,e,i,r,n,s){r.type==="PrivateIdentifier"&&this.raise(r.start,"Private identifier can only be left side of binary expression");var a=this.startNodeAt(t,e);return a.left=i,a.operator=n,a.right=r,this.finishNode(a,s?"LogicalExpression":"BinaryExpression")};B.parseMaybeUnary=function(t,e,i,r){var n=this.start,s=this.startLoc,a;if(this.isContextual("await")&&this.canAwait)a=this.parseAwait(r),e=!0;else if(this.type.prefix){var o=this.startNode(),l=this.type===_.incDec;o.operator=this.value,o.prefix=!0,this.next(),o.argument=this.parseMaybeUnary(null,!0,l,r),this.checkExpressionErrors(t,!0),l?this.checkLValSimple(o.argument):this.strict&&o.operator==="delete"&&Zs(o.argument)?this.raiseRecoverable(o.start,"Deleting local variable in strict mode"):o.operator==="delete"&&kr(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===_.privateId)(r||this.privateNameStack.length===0)&&this.options.checkPrivateFields&&this.unexpected(),a=this.parsePrivateIdent(),this.type!==_._in&&this.unexpected();else{if(a=this.parseExprSubscripts(t,r),this.checkExpressionErrors(t))return a;for(;this.type.postfix&&!this.canInsertSemicolon();){var c=this.startNodeAt(n,s);c.operator=this.value,c.prefix=!1,c.argument=a,this.checkLValSimple(a),this.next(),a=this.finishNode(c,"UpdateExpression")}}if(!i&&this.eat(_.starstar))if(e)this.unexpected(this.lastTokStart);else return this.buildBinary(n,s,a,this.parseMaybeUnary(null,!1,!1,r),"**",!1);else return a};function Zs(t){return t.type==="Identifier"||t.type==="ParenthesizedExpression"&&Zs(t.expression)}function kr(t){return t.type==="MemberExpression"&&t.property.type==="PrivateIdentifier"||t.type==="ChainExpression"&&kr(t.expression)||t.type==="ParenthesizedExpression"&&kr(t.expression)}B.parseExprSubscripts=function(t,e){var i=this.start,r=this.startLoc,n=this.parseExprAtom(t,e);if(n.type==="ArrowFunctionExpression"&&this.input.slice(this.lastTokStart,this.lastTokEnd)!==")")return n;var s=this.parseSubscripts(n,i,r,!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};B.parseSubscripts=function(t,e,i,r,n){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,i,r,s,a,n);if(o.optional&&(a=!0),o===t||o.type==="ArrowFunctionExpression"){if(a){var l=this.startNodeAt(e,i);l.expression=o,o=this.finishNode(l,"ChainExpression")}return o}t=o}};B.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(_.arrow)};B.parseSubscriptAsyncArrow=function(t,e,i,r){return this.parseArrowExpression(this.startNodeAt(t,e),i,!0,r)};B.parseSubscript=function(t,e,i,r,n,s,a){var o=this.options.ecmaVersion>=11,l=o&&this.eat(_.questionDot);r&&l&&this.raise(this.lastTokStart,"Optional chaining cannot appear in the callee of new expressions");var c=this.eat(_.bracketL);if(c||l&&this.type!==_.parenL&&this.type!==_.backQuote||this.eat(_.dot)){var u=this.startNodeAt(e,i);u.object=t,c?(u.property=this.parseExpression(),this.expect(_.bracketR)):this.type===_.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(!r&&this.eat(_.parenL)){var p=new tr,h=this.yieldPos,f=this.awaitPos,d=this.awaitIdentPos;this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0;var m=this.parseExprList(_.parenR,this.options.ecmaVersion>=8,!1,p);if(n&&!l&&this.shouldParseAsyncArrow())return this.checkPatternErrors(p,!1),this.checkYieldAwaitInDefaultParams(),this.awaitIdentPos>0&&this.raise(this.awaitIdentPos,"Cannot use 'await' as identifier inside an async function"),this.yieldPos=h,this.awaitPos=f,this.awaitIdentPos=d,this.parseSubscriptAsyncArrow(e,i,m,a);this.checkExpressionErrors(p,!0),this.yieldPos=h||this.yieldPos,this.awaitPos=f||this.awaitPos,this.awaitIdentPos=d||this.awaitIdentPos;var x=this.startNodeAt(e,i);x.callee=t,x.arguments=m,o&&(x.optional=l),t=this.finishNode(x,"CallExpression")}else if(this.type===_.backQuote){(l||s)&&this.raise(this.start,"Optional chaining cannot appear in the tag of tagged template expressions");var b=this.startNodeAt(e,i);b.tag=t,b.quasi=this.parseTemplate({isTagged:!0}),t=this.finishNode(b,"TaggedTemplateExpression")}return t};B.parseExprAtom=function(t,e,i){this.type===_.slash&&this.readRegexp();var r,n=this.potentialArrowAt===this.start;switch(this.type){case _._super:return this.allowSuper||this.raise(this.start,"'super' keyword outside a method"),r=this.startNode(),this.next(),this.type===_.parenL&&!this.allowDirectSuper&&this.raise(r.start,"super() call outside constructor of a subclass"),this.type!==_.dot&&this.type!==_.bracketL&&this.type!==_.parenL&&this.unexpected(),this.finishNode(r,"Super");case _._this:return r=this.startNode(),this.next(),this.finishNode(r,"ThisExpression");case _.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(_._function))return this.overrideContext(re.f_expr),this.parseFunction(this.startNodeAt(s,a),0,!1,!0,e);if(n&&!this.canInsertSemicolon()){if(this.eat(_.arrow))return this.parseArrowExpression(this.startNodeAt(s,a),[l],!1,e);if(this.options.ecmaVersion>=8&&l.name==="async"&&this.type===_.name&&!o&&(!this.potentialArrowInForAwait||this.value!=="of"||this.containsEsc))return l=this.parseIdent(!1),(this.canInsertSemicolon()||!this.eat(_.arrow))&&this.unexpected(),this.parseArrowExpression(this.startNodeAt(s,a),[l],!0,e)}return l;case _.regexp:var c=this.value;return r=this.parseLiteral(c.value),r.regex={pattern:c.pattern,flags:c.flags},r;case _.num:case _.string:return this.parseLiteral(this.value);case _._null:case _._true:case _._false:return r=this.startNode(),r.value=this.type===_._null?null:this.type===_._true,r.raw=this.type.keyword,this.next(),this.finishNode(r,"Literal");case _.parenL:var u=this.start,p=this.parseParenAndDistinguishExpression(n,e);return t&&(t.parenthesizedAssign<0&&!this.isSimpleAssignTarget(p)&&(t.parenthesizedAssign=u),t.parenthesizedBind<0&&(t.parenthesizedBind=u)),p;case _.bracketL:return r=this.startNode(),this.next(),r.elements=this.parseExprList(_.bracketR,!0,!0,t),this.finishNode(r,"ArrayExpression");case _.braceL:return this.overrideContext(re.b_expr),this.parseObj(!1,t);case _._function:return r=this.startNode(),this.next(),this.parseFunction(r,0);case _._class:return this.parseClass(this.startNode(),!1);case _._new:return this.parseNew();case _.backQuote:return this.parseTemplate();case _._import:return this.options.ecmaVersion>=11?this.parseExprImport(i):this.unexpected();default:return this.parseExprAtomDefault()}};B.parseExprAtomDefault=function(){this.unexpected()};B.parseExprImport=function(t){var e=this.startNode();if(this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword import"),this.next(),this.type===_.parenL&&!t)return this.parseDynamicImport(e);if(this.type===_.dot){var i=this.startNodeAt(e.start,e.loc&&e.loc.start);return i.name="import",e.meta=this.finishNode(i,"Identifier"),this.parseImportMeta(e)}else this.unexpected()};B.parseDynamicImport=function(t){if(this.next(),t.source=this.parseMaybeAssign(),this.options.ecmaVersion>=16)this.eat(_.parenR)?t.options=null:(this.expect(_.comma),this.afterTrailingComma(_.parenR)?t.options=null:(t.options=this.parseMaybeAssign(),this.eat(_.parenR)||(this.expect(_.comma),this.afterTrailingComma(_.parenR)||this.unexpected())));else if(!this.eat(_.parenR)){var e=this.start;this.eat(_.comma)&&this.eat(_.parenR)?this.raiseRecoverable(e,"Trailing comma is not allowed in import()"):this.unexpected(e)}return this.finishNode(t,"ImportExpression")};B.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")};B.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")};B.parseParenExpression=function(){this.expect(_.parenL);var t=this.parseExpression();return this.expect(_.parenR),t};B.shouldParseArrow=function(t){return!this.canInsertSemicolon()};B.parseParenAndDistinguishExpression=function(t,e){var i=this.start,r=this.startLoc,n,s=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var a=this.start,o=this.startLoc,l=[],c=!0,u=!1,p=new tr,h=this.yieldPos,f=this.awaitPos,d;for(this.yieldPos=0,this.awaitPos=0;this.type!==_.parenR;)if(c?c=!1:this.expect(_.comma),s&&this.afterTrailingComma(_.parenR,!0)){u=!0;break}else if(this.type===_.ellipsis){d=this.start,l.push(this.parseParenItem(this.parseRestBinding())),this.type===_.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element");break}else l.push(this.parseMaybeAssign(!1,p,this.parseParenItem));var m=this.lastTokEnd,x=this.lastTokEndLoc;if(this.expect(_.parenR),t&&this.shouldParseArrow(l)&&this.eat(_.arrow))return this.checkPatternErrors(p,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=h,this.awaitPos=f,this.parseParenArrowList(i,r,l,e);(!l.length||u)&&this.unexpected(this.lastTokStart),d&&this.unexpected(d),this.checkExpressionErrors(p,!0),this.yieldPos=h||this.yieldPos,this.awaitPos=f||this.awaitPos,l.length>1?(n=this.startNodeAt(a,o),n.expressions=l,this.finishNodeAt(n,"SequenceExpression",m,x)):n=l[0]}else n=this.parseParenExpression();if(this.options.preserveParens){var b=this.startNodeAt(i,r);return b.expression=n,this.finishNode(b,"ParenthesizedExpression")}else return n};B.parseParenItem=function(t){return t};B.parseParenArrowList=function(t,e,i,r){return this.parseArrowExpression(this.startNodeAt(t,e),i,!1,r)};var Pm=[];B.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===_.dot){var e=this.startNodeAt(t.start,t.loc&&t.loc.start);e.name="new",t.meta=this.finishNode(e,"Identifier"),this.next();var i=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'"),i&&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 r=this.start,n=this.startLoc;return t.callee=this.parseSubscripts(this.parseExprAtom(null,!1,!0),r,n,!0,!1),this.eat(_.parenL)?t.arguments=this.parseExprList(_.parenR,this.options.ecmaVersion>=8,!1):t.arguments=Pm,this.finishNode(t,"NewExpression")};B.parseTemplateElement=function(t){var e=t.isTagged,i=this.startNode();return this.type===_.invalidTemplate?(e||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),i.value={raw:this.value.replace(/\r\n?/g,`
1
+ function Ua(t){return e=>new U(e.array.map(i=>Math.abs(i)),e.type,t)}function qa(t){return e=>{let i=0,r=0;for(const n of e.array){const a=Number(n);isNaN(a)||(r++,i+=(a-i)/r)}return r===0?NaN:t.precision(i)}}function za(t){return(e,i)=>{const r=e.array;let n=0,a=r.length-1;for(;n<=a;){const s=Math.floor((n+a)/2),o=r[s];if(o===i)return s;o<i?n=s+1:a=s-1}return-1}}function Ka(t){return(e,i)=>{const r=e.array;let n=0,a=r.length;for(;n<a;){const s=Math.floor((n+a)/2);r[s]<i?n=s+1:a=s}return n<r.length&&r[n]===i?n:n-1}}function Ha(t){return(e,i)=>{const r=e.array;let n=0,a=r.length;for(;n<a;){const s=Math.floor((n+a)/2);r[s]<=i?n=s+1:a=s}return n>0&&r[n-1]===i?n-1:n}}function Ga(t){return e=>{e.array.length=0}}function Ya(t){return(e,i)=>(e.array.push(...i.array),e)}function Xa(t){return e=>new U([...e.array],e.type,t)}function Qa(t){return(e,i,r=!0)=>{const n=e.array,a=i.array;if(n.length!==a.length)return NaN;let s=0,o=0,l=0;const c=[];for(let d=0;d<n.length;d++){const m=Number(n[d]),x=Number(a[d]);!isNaN(m)&&m!==null&&m!==void 0&&!isNaN(x)&&x!==null&&x!==void 0&&(s+=m,o+=x,l++,c.push(d))}if(l===0)return NaN;const u=s/l,p=o/l;let h=0;for(const d of c){const m=Number(n[d]),x=Number(a[d]);h+=(m-u)*(x-p)}const f=r?l:l-1;return f<=0?NaN:t.precision(h/f)}}function Za(t){return e=>e.array.every(i=>!isNaN(i)&&i)}function Ja(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?F.int:F.float:t.every(e=>typeof e=="string")?F.string:t.every(e=>typeof e=="boolean")?F.bool:F.any}function Ye(t){return typeof t=="number"?Number.isInteger(t)?F.int:F.float:typeof t=="string"?F.string:typeof t=="boolean"?F.bool:F.any}function vi(t,e){if(typeof t=="number"&&isNaN(t)||e===F.any)return!0;switch(e){case F.int:return Number.isInteger(t)||isNaN(t);case F.float:return typeof t=="number";case F.string:return typeof t=="string";case F.bool:return typeof t=="boolean";case F.box:case F.label:case F.line:case F.linefill:case F.table:case F.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function eo(t){return(e,i,r=0,n)=>{const a=e.array.length,s=n!==void 0?Math.min(n,a):a;for(let o=r;o<s;o++){if(!vi(i,e.type))throw new Error(`Cannot call 'array.fill' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array[o]=typeof i=="number"?t.precision(i):i}}}function to(t){return e=>e.array.length>0?e.array[0]:t.NA}function io(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.get"),NaN):e.array[i])}function ro(t){return(e,i)=>e.array.includes(i)}function no(t){return(e,i)=>typeof i=="number"&&i!==i?e.array.findIndex(r=>typeof r=="number"&&r!==r):e.array.indexOf(i)}function so(t){return(e,i,r)=>{if(!vi(r,e.type))throw new Error(`Cannot call 'array.insert' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.insert");return}e.array.splice(i,0,r)}}function ao(t){return(e,i=",")=>e.array.join(i)}function oo(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function lo(t){return(e,i)=>e.array.lastIndexOf(i)}function co(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let n=r[0];for(let a=1;a<r.length;a++)r[a]>n&&(n=r[a]);return n??t.NA}return[...r].sort((n,a)=>a-n)[i]??t.NA}}function uo(t){return e=>{const i=e.array;if(i.length===0)return NaN;const r=new Array(i.length);for(let a=0;a<i.length;a++)r[a]=i[a];r.sort((a,s)=>a-s);const n=Math.floor(r.length/2);return r.length%2!==0?r[n]:(r[n-1]+r[n])/2}}function ho(t){return(e,i=0)=>{const r=e.array;if(r.length===0)return t.NA;if(i===0){let n=r[0];for(let a=1;a<r.length;a++)r[a]<n&&(n=r[a]);return n??t.NA}return[...r].sort((n,a)=>n-a)[i]??t.NA}}function po(t){return e=>{if(e.array.length===0)return NaN;const i=new Map;let r=0;for(const a of e.array){const s=(i.get(a)||0)+1;i.set(a,s),s>r&&(r=s)}const n=[];for(const[a,s]of i)s===r&&n.push(a);return n.sort((a,s)=>typeof a=="number"&&typeof s=="number"?a-s:typeof a=="string"&&typeof s=="string"?a<s?-1:a>s?1:0:0),n[0]}}function fo(t){return(e,i)=>{const r=e.array,n=r.length;if(n===0)return NaN;const a=new Array(n);for(let c=0;c<n;c++){const u=Number(r[c]);if(isNaN(u)||u===null||u===void 0)return NaN;a[c]=u}a.sort((c,u)=>c-u),i<0&&(i=0),i>100&&(i=100);const s=i/100*n-.5;if(s<=0)return t.precision(a[0]);if(s>=n-1)return t.precision(a[n-1]);const o=Math.floor(s),l=s-o;return t.precision(a[o]*(1-l)+a[o+1]*l)}}function mo(t){return(e,i)=>{const r=e.array,n=r.length;if(n===0)return NaN;const a=new Array;for(let o=0;o<n;o++){const l=Number(r[o]);!isNaN(l)&&l!==null&&l!==void 0&&a.push(l)}if(a.length===0)return NaN;a.sort((o,l)=>o-l),i<0&&(i=0),i>100&&(i=100);const s=Math.ceil(i/100*n);return s<=0?a[0]:s>a.length?NaN:a[s-1]}}function yo(t){return(e,i)=>{if(e.array.length===0)return NaN;const r=Math.floor(i);if(r<0||r>=e.array.length)return NaN;const n=Number(e.array[r]);if(isNaN(n)||n===null||n===void 0)return NaN;let a=0;for(const o of e.array){const l=Number(o);!isNaN(l)&&l!==null&&l!==void 0&&l<n&&a++}const s=e.array.length-1;return s<=0?NaN:a/s*100}}function _o(t){return e=>e.array.pop()}function go(t){return(e,i)=>{if(!vi(i,e.type))throw new Error(`Cannot call 'array.push' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.push(typeof i=="number"?t.precision(i):i)}}function xo(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function bo(t){return(e,i)=>(i<0&&(i=e.array.length+i),i<0||i>=e.array.length?(t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.remove"),NaN):e.array.splice(i,1)[0])}function vo(t){return e=>{e.array.reverse()}}function wo(t){return(e,i,r)=>{if(!vi(r,e.type))throw new Error(`Cannot call 'array.set' with argument 'value'='${r}'. An argument of 'literal ${typeof r}' type was used but a '${e.type}' is expected.`);if(i<0&&(i=e.array.length+i),i<0||i>=e.array.length){t.warn(`Index ${i} is out of bounds, array size is ${e.array.length}.`,"array.set");return}e.array[i]=typeof r=="number"?t.precision(r):r}}function So(t){return e=>e.array.shift()}function Eo(t){return e=>e.array.length}function No(t){return(e,i,r)=>{const n=r!==void 0?r:void 0;return new U(e.array.slice(i,n),e.type,t)}}function Co(t){return e=>e.array.some(i=>!isNaN(i)&&i)}var ti=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(ti||{}),rs=(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))(rs||{}),ns=(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))(ns||{}),ss=(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))(ss||{}),as=(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))(as||{}),os=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(os||{}),ls=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(ls||{}),cs=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(cs||{}),Io=(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))(Io||{}),us=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(us||{}),hs=(t=>(t.bar_index="bi",t.bar_time="bt",t))(hs||{}),ps=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(ps||{}),fs=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(fs||{}),ds=(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))(ds||{}),ms=(t=>(t.family_default="default",t.family_monospace="monospace",t))(ms||{}),ys=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(ys||{}),_s=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(_s||{}),gs=(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))(gs||{}),xs=(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))(xs||{}),bs=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(bs||{}),vs=(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))(vs||{}),ws=(t=>(t.left="left",t.none="none",t.right="right",t))(ws||{}),Ss=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(Ss||{});const ko={order:ti,currency:rs,dayofweek:ns,display:ss,shape:as,location:os,size:ls,format:cs,barmerge:us,xloc:hs,yloc:ps,extend:fs,text:ds,font:ms,adjustment:ys,backadjustment:_s,earnings:gs,dividends:xs,splits:bs,position:vs,scale:ws,settlement_as_close:Ss};function To(t){return(e,i=ti.ascending)=>{e.array.sort((r,n)=>{let a=isNaN(r)?1/0:r,s=isNaN(n)?1/0:n;return i===ti.ascending?a-s:s-a})}}function Ao(t){return(e,i=ti.ascending)=>{const r=e.array.map((n,a)=>a);return r.sort((n,a)=>{const s=isNaN(e.array[n])?1/0:e.array[n],o=isNaN(e.array[a])?1/0:e.array[a];return i===ti.ascending?s-o:o-s}),new U(r,F.int,t)}}function Po(t){return e=>{const i=t.array.avg(e),r=t.array.stdev(e);return isNaN(r)?new U(e.array.map(()=>NaN),F.int,t):r===0?new U(e.array.map(()=>1),F.int,t):new U(e.array.map(n=>(n-i)/r),F.int,t)}}function Mo(t){return(e,i=!0)=>{const r=e.array,n=r.length;if(n===0)return NaN;let a=0,s=0,o=0;for(let u=0;u<n;u++){const p=Number(r[u]);!isNaN(p)&&p!==null&&p!==void 0&&(a+=p,s+=p*p,o++)}if(o===0)return NaN;const l=a/o;let c=s/o-l*l;return c<0?NaN:(!i&&o>1&&(c=c*o/(o-1)),!i&&o===1?0:t.precision(Math.sqrt(c)))}}function Do(t){return e=>t.precision(e.array.reduce((i,r)=>{const n=Number(r);return isNaN(n)?i:i+n},0))}function Ro(t){return(e,i)=>{if(!vi(i,e.type))throw new Error(`Cannot call 'array.unshift' with argument 'value'='${i}'. An argument of 'literal ${typeof i}' type was used but a '${e.type}' is expected.`);e.array.unshift(typeof i=="number"?t.precision(i):i)}}function Oo(t){return(e,i=!0)=>{let r=0,n=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(r+=c,n++)}if(n===0)return NaN;const a=r/n;let s=0;for(const l of e.array){const c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(s+=(c-a)*(c-a))}const o=i?n:n-1;return o<=0?NaN:t.precision(s/o)}}var $o=Object.defineProperty,Vo=(t,e,i)=>e in t?$o(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,q=(t,e,i)=>Vo(t,typeof e!="symbol"?e+"":e,i),F=(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))(F||{});class U{constructor(e,i,r){this.array=e,this.type=i,this.context=r,q(this,"_abs"),q(this,"_avg"),q(this,"_binary_search"),q(this,"_binary_search_leftmost"),q(this,"_binary_search_rightmost"),q(this,"_clear"),q(this,"_concat"),q(this,"_copy"),q(this,"_covariance"),q(this,"_every"),q(this,"_fill"),q(this,"_first"),q(this,"_get"),q(this,"_includes"),q(this,"_indexof"),q(this,"_insert"),q(this,"_join"),q(this,"_last"),q(this,"_lastindexof"),q(this,"_max"),q(this,"_median"),q(this,"_min"),q(this,"_mode"),q(this,"_percentile_linear_interpolation"),q(this,"_percentile_nearest_rank"),q(this,"_percentrank"),q(this,"_pop"),q(this,"_push"),q(this,"_range"),q(this,"_remove"),q(this,"_reverse"),q(this,"_set"),q(this,"_shift"),q(this,"_size"),q(this,"_slice"),q(this,"_some"),q(this,"_sort"),q(this,"_sort_indices"),q(this,"_standardize"),q(this,"_stdev"),q(this,"_sum"),q(this,"_unshift"),q(this,"_variance"),this._abs=Ua(this.context),this._avg=qa(this.context),this._binary_search=za(this.context),this._binary_search_leftmost=Ka(this.context),this._binary_search_rightmost=Ha(this.context),this._clear=Ga(this.context),this._concat=Ya(this.context),this._copy=Xa(this.context),this._covariance=Qa(this.context),this._every=Za(this.context),this._fill=eo(this.context),this._first=to(this.context),this._get=io(this.context),this._includes=ro(this.context),this._indexof=no(this.context),this._insert=so(this.context),this._join=ao(this.context),this._last=oo(this.context),this._lastindexof=lo(this.context),this._max=co(this.context),this._median=uo(this.context),this._min=ho(this.context),this._mode=po(this.context),this._percentile_linear_interpolation=fo(this.context),this._percentile_nearest_rank=mo(this.context),this._percentrank=yo(this.context),this._pop=_o(this.context),this._push=go(this.context),this._range=xo(this.context),this._remove=bo(this.context),this._reverse=vo(this.context),this._set=wo(this.context),this._shift=So(this.context),this._size=Eo(this.context),this._slice=No(this.context),this._some=Co(this.context),this._sort=To(this.context),this._sort_indices=Ao(this.context),this._standardize=Po(this.context),this._stdev=Mo(this.context),this._sum=Do(this.context),this._unshift=Ro(this.context),this._variance=Oo(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 jo(t){return(...e)=>new U([...e],Ja(e),t)}function Lo(t){return(e,i)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;if(i===void 0){const n=r?Array(r).fill(0):[];return new U(n,F.any,t)}return new U(Array(r).fill(t.precision(i||0)),Ye(i||0),t)}}function Bo(t){return(e=0,i=!1)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(i),F.bool,t)}}function Fo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(i),F.box,t)}}function Wo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(i),F.color,t)}}function Uo(t){return(e=0,i=NaN)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(t.precision(i)),F.float,t)}}function qo(t){return(e=0,i=0)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(t.precision(i)),F.int,t)}}function zo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(i),F.label,t)}}function Ko(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(i),F.line,t)}}function Ho(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(i),F.linefill,t)}}function Go(t){return(e=0,i="")=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(i),F.string,t)}}function Yo(t){return(e=0,i=null)=>{const r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new U(Array(r).fill(i),F.table,t)}}class y{constructor(e,i=0){this.data=e,this.offset=i}get(e){const i=this.data.length-1-(this.offset+e);return i<0||i>=this.data.length?NaN:this.data[i]}set(e,i){const r=this.data.length-1-(this.offset+e);r>=0&&r<this.data.length&&(this.data[r]=i)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof y?e:Array.isArray(e)?new y(e):e!=null&&typeof e=="object"&&"__value"in e&&e.__value instanceof y?e.__value:new y([e])}}function Xo(t){return(e,i=0)=>y.from(e).get(i)}class Qo{constructor(e){this.context=e,this.abs=(i,...r)=>i.abs(...r),this.avg=(i,...r)=>i.avg(...r),this.binary_search=(i,...r)=>i.binary_search(...r),this.binary_search_leftmost=(i,...r)=>i.binary_search_leftmost(...r),this.binary_search_rightmost=(i,...r)=>i.binary_search_rightmost(...r),this.clear=(i,...r)=>i.clear(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.covariance=(i,...r)=>i.covariance(...r),this.every=(i,...r)=>i.every(...r),this.fill=(i,...r)=>i.fill(...r),this.first=(i,...r)=>i.first(...r),this.from=jo(e),this.get=(i,...r)=>i.get(...r),this.includes=(i,...r)=>i.includes(...r),this.indexof=(i,...r)=>i.indexof(...r),this.insert=(i,...r)=>i.insert(...r),this.join=(i,...r)=>i.join(...r),this.last=(i,...r)=>i.last(...r),this.lastindexof=(i,...r)=>i.lastindexof(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.new=Lo(e),this.new_bool=Bo(e),this.new_box=Fo(e),this.new_color=Wo(e),this.new_float=Uo(e),this.new_int=qo(e),this.new_label=zo(e),this.new_line=Ko(e),this.new_linefill=Ho(e),this.new_string=Go(e),this.new_table=Yo(e),this.param=Xo(),this.percentile_linear_interpolation=(i,...r)=>i.percentile_linear_interpolation(...r),this.percentile_nearest_rank=(i,...r)=>i.percentile_nearest_rank(...r),this.percentrank=(i,...r)=>i.percentrank(...r),this.pop=(i,...r)=>i.pop(...r),this.push=(i,...r)=>i.push(...r),this.range=(i,...r)=>i.range(...r),this.remove=(i,...r)=>i.remove(...r),this.reverse=(i,...r)=>i.reverse(...r),this.set=(i,...r)=>i.set(...r),this.shift=(i,...r)=>i.shift(...r),this.size=(i,...r)=>i.size(...r),this.slice=(i,...r)=>i.slice(...r),this.some=(i,...r)=>i.some(...r),this.sort=(i,...r)=>i.sort(...r),this.sort_indices=(i,...r)=>i.sort_indices(...r),this.standardize=(i,...r)=>i.standardize(...r),this.stdev=(i,...r)=>i.stdev(...r),this.sum=(i,...r)=>i.sum(...r),this.unshift=(i,...r)=>i.unshift(...r),this.variance=(i,...r)=>i.variance(...r)}}function Zo(t){return e=>{e.map.clear()}}function Jo(t){return(e,i)=>e.map.has(i)}function el(t){return e=>{const i=new Es(t);return i.map=new Map(e.map),i}}function tl(t){return(e,i)=>{const r=e.map.get(i);return r===void 0?NaN:r}}function il(t){return e=>{const i=Array.from(e.map.keys()),r=Ye(i[0]);return new U(i,r,t)}}function rl(t){return(e,i,r)=>{const n=e.map.get(i);return e.map.set(i,r),n===void 0?NaN:n}}function nl(t){return(e,i)=>{for(const[r,n]of i.map)e.map.set(r,n)}}function sl(t){return(e,i)=>{const r=e.map.get(i);return e.map.delete(i)?r:NaN}}function al(t){return e=>e.map.size}function ol(t){return e=>{const i=Array.from(e.map.values()),r=Ye(i[0]);return new U(i,r,t)}}var ll=Object.defineProperty,cl=(t,e,i)=>e in t?ll(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ze=(t,e,i)=>cl(t,typeof e!="symbol"?e+"":e,i);class Es{constructor(e){this.context=e,Ze(this,"map"),Ze(this,"_clear"),Ze(this,"_contains"),Ze(this,"_copy"),Ze(this,"_get"),Ze(this,"_keys"),Ze(this,"_put"),Ze(this,"_put_all"),Ze(this,"_remove"),Ze(this,"_size"),Ze(this,"_values"),this.map=new Map,this._clear=Zo(this.context),this._contains=Jo(this.context),this._copy=el(this.context),this._get=tl(this.context),this._keys=il(this.context),this._put=rl(this.context),this._put_all=nl(this.context),this._remove=sl(this.context),this._size=al(this.context),this._values=ol(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 ul(t){return()=>new Es(t)}function hl(t){return(e,i=0)=>y.from(e).get(i)}class pl{constructor(e){this.context=e,this.clear=(i,...r)=>i.clear(...r),this.contains=(i,...r)=>i.contains(...r),this.copy=(i,...r)=>i.copy(...r),this.get=(i,...r)=>i.get(...r),this.keys=(i,...r)=>i.keys(...r),this.new=ul(e),this.param=hl(),this.put=(i,...r)=>i.put(...r),this.put_all=(i,...r)=>i.put_all(...r),this.remove=(i,...r)=>i.remove(...r),this.size=(i,...r)=>i.size(...r),this.values=(i,...r)=>i.values(...r)}}function fl(t){return(e,i,r)=>{const n=e.matrix.length;let a=[];if(r&&(r instanceof U?a=r.array:Array.isArray(r)?a=r:a=[r]),n===0){for(let l=0;l<a.length;l++){let c=a[l];c instanceof y&&(c=c.get(0)),e.matrix.push([c])}return}const s=e.matrix[0].length,o=i!==void 0?i:s;for(let l=0;l<n;l++){let c=l<a.length?a[l]:NaN;c instanceof y&&(c=c.get(0)),e.matrix[l].splice(o,0,c)}}}function dl(t){return(e,i,r)=>{const n=e.matrix.length;let a=[];if(r)if(r instanceof U)a=r.array;else if(Array.isArray(r))a=r;else if(r instanceof y){const c=r.get(0);Array.isArray(c)?a=c:a=[c]}else a=[r];const s=n>0?e.matrix[0].length:a.length,o=i!==void 0?i:n,l=[];for(let c=0;c<s;c++)if(c<a.length){let u=a[c];u instanceof y&&(u=u.get(0)),l.push(u)}else l.push(NaN);e.matrix.splice(o,0,l)}}function ml(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;if(r===0)return NaN;let n=0,a=0;for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||(n+=l,a++)}return a===0?NaN:n/a}}function yl(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(i<0||i>=n){t.warn(`Column index ${i} is out of bounds, matrix has ${n} columns.`,"matrix.col");const o=r>0?Ye(e.matrix[0][0]):"float";return new U([],o,t)}const a=[];for(let o=0;o<r;o++)a.push(e.matrix[o][i]);const s=Ye(a[0]);return new U(a,s,t)}}function _l(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function gl(t){return(e,i)=>{const r=e.matrix.length,n=i.matrix.length;if(r===0){for(let o=0;o<n;o++)e.matrix.push([...i.matrix[o]]);return}const a=e.matrix[0].length,s=n>0?i.matrix[0].length:0;if(a!==s&&n>0){console.error(`matrix.concat: Column count mismatch ${a} vs ${s}`);return}for(let o=0;o<n;o++)e.matrix.push([...i.matrix[o]])}}function xl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0,n=new Z(i,r,NaN,t);return n.matrix=e.matrix.map(a=>[...a]),n}}function bl(t){const 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];const i=t.map(n=>[...n]);let r=1;for(let n=0;n<e;n++){let a=n;for(;a<e&&i[a][n]===0;)a++;if(a===e)return 0;a!==n&&([i[n],i[a]]=[i[a],i[n]],r*=-1),r*=i[n][n];for(let s=n+1;s<e;s++){const o=i[s][n]/i[n][n];for(let l=n;l<e;l++)i[s][l]-=o*i[n][l]}}return r}function vl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;return i!==r?NaN:bl(e.matrix)}}function wl(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new Z(0,0,NaN,t);const n=e.matrix[0].length,a=new Z(r,n,NaN,t);if(i instanceof Z)for(let s=0;s<r;s++)for(let o=0;o<n;o++){const l=e.matrix[s][o],c=i.matrix[s]&&i.matrix[s][o]!==void 0?i.matrix[s][o]:NaN;a.matrix[s][o]=l-c}else{const s=i;for(let o=0;o<r;o++)for(let l=0;l<n;l++)a.matrix[o][l]=e.matrix[o][l]-s}return a}}function Sl(t){const e=t.length;if(e!==2)return Array(e).fill(NaN);const i=t[0][0],r=t[0][1],n=t[1][0],a=t[1][1],s=i+a,o=i*a-r*n,l=s*s-4*o;if(l<0)return[NaN,NaN];const c=(s+Math.sqrt(l))/2,u=(s-Math.sqrt(l))/2;return[c,u]}function El(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r){const s=Ye(e.matrix[0][0]);return new U([],s,t)}const n=Sl(e.matrix),a=Ye(n[0]);return new U(n,a,t)}}function Nl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new Z(0,0,NaN,t);const n=new Z(i,r,0,t);for(let a=0;a<i;a++)n.matrix[a][a]=1;return n}}function Cl(t){return e=>{const i=e.matrix.length;return i===0?0:i*e.matrix[0].length}}function Il(t){return(e,i,r,n,a,s)=>{const o=e.matrix.length;if(o===0)return;const l=e.matrix[0].length,c=r!==void 0?r:0,u=n!==void 0?n:o,p=a!==void 0?a:0,h=s!==void 0?s:l;for(let f=c;f<u&&!(f>=o);f++)for(let d=p;d<h&&!(d>=l);d++)e.matrix[f][d]=i}}function kl(t){return(e,i,r)=>{const n=e.matrix.length,a=n>0?e.matrix[0].length:0;if(i<0||i>=n)return t.warn(`Row index ${i} is out of bounds, matrix has ${n} rows.`,"matrix.get"),NaN;if(r<0||r>=a)return t.warn(`Column index ${r} is out of bounds, matrix has ${a} columns.`,"matrix.get"),NaN;const s=e.matrix[i][r];return s===void 0?NaN:s}}function Ri(t){const e=t.length;if(e===0)return[];const i=new Array(e);for(let n=0;n<e;n++){i[n]=new Array(2*e);for(let a=0;a<e;a++)i[n][a]=t[n][a];for(let a=0;a<e;a++)i[n][e+a]=n===a?1:0}for(let n=0;n<e;n++){let a=Math.abs(i[n][n]),s=n;for(let l=n+1;l<e;l++){const c=Math.abs(i[l][n]);c>a&&(a=c,s=l)}if(a<1e-14)return t.map(l=>l.map(()=>NaN));if(s!==n){const l=i[n];i[n]=i[s],i[s]=l}const o=i[n][n];for(let l=n;l<2*e;l++)i[n][l]/=o;for(let l=0;l<e;l++){if(l===n)continue;const c=i[l][n];if(c!==0)for(let u=n;u<2*e;u++)i[l][u]-=c*i[n][u]}}const r=new Array(e);for(let n=0;n<e;n++){r[n]=new Array(e);for(let a=0;a<e;a++)r[n][a]=i[n][e+a]}return r}function Tl(t){return e=>{const i=e.matrix.length,r=i>0?e.matrix[0].length:0;if(i!==r)return new Z(i,r,NaN,t);const n=Ri(e.matrix),a=new Z(i,r,NaN,t);return a.matrix=n,a}}function Al(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(n+a!==i-1&&e.matrix[n][a]!==0)return!1;return!0}}function Pl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(e.matrix[a][n]!==-e.matrix[n][a])return!1;return!0}}function Ml(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let n=0;n<i;n++)for(let a=0;a<r;a++){const s=e.matrix[n][a];if(s!==0&&s!==1)return!1}return!0}}function Dl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(n!==a&&e.matrix[n][a]!==0)return!1;return!0}}function Rl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(n===a){if(e.matrix[n][a]!==1)return!1}else if(e.matrix[n][a]!==0)return!1;return!0}}function Ol(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;return i===r}}function $l(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;for(let n=0;n<i;n++){let a=0;for(let s=0;s<r;s++){const o=e.matrix[n][s];if(o<0)return!1;a+=o}if(Math.abs(a-1)>1e-10)return!1}return!0}}function Vl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;for(let n=0;n<i;n++)for(let a=0;a<n;a++)if(e.matrix[n][a]!==e.matrix[a][n])return!1;return!0}}function jl(t){return e=>{const i=e.matrix.length;if(i===0)return!1;const r=e.matrix[0].length;if(i!==r)return!1;let n=!0,a=!0;for(let s=0;s<i;s++)for(let o=0;o<r;o++)s>o&&e.matrix[s][o]!==0&&(n=!1),s<o&&e.matrix[s][o]!==0&&(a=!1);return n||a}}function Ll(t){return e=>{const i=e.matrix.length;if(i===0)return!0;const r=e.matrix[0].length;for(let n=0;n<i;n++)for(let a=0;a<r;a++)if(e.matrix[n][a]!==0)return!1;return!0}}function Bl(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0,a=i.matrix.length,s=a>0?i.matrix[0].length:0,o=r*a,l=n*s,c=new Z(o,l,NaN,t);for(let u=0;u<r;u++)for(let p=0;p<n;p++){const h=e.matrix[u][p];for(let f=0;f<a;f++)for(let d=0;d<s;d++){const m=i.matrix[f][d];c.matrix[u*a+f][p*s+d]=h*m}}return c}}function Fl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let n=-1/0,a=!1;for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||(l>n&&(n=l),a=!0)}return a?n:NaN}}function Wl(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,n=[];for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||n.push(l)}if(n.length===0)return NaN;n.sort((s,o)=>s-o);const a=Math.floor(n.length/2);return n.length%2!==0?n[a]:(n[a-1]+n[a])/2}}function Ul(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length;let n=1/0,a=!1;for(let s=0;s<i;s++)for(let o=0;o<r;o++){const l=e.matrix[s][o];isNaN(l)||(l<n&&(n=l),a=!0)}return a?n:NaN}}function ql(t){return e=>{const i=e.matrix.length;if(i===0)return NaN;const r=e.matrix[0].length,n=new Map;let a=0,s=NaN;for(let o=0;o<i;o++)for(let l=0;l<r;l++){const c=e.matrix[o][l];if(!isNaN(c)){const u=(n.get(c)||0)+1;n.set(c,u),u>a?(a=u,s=c):u===a&&c<s&&(s=c)}}return s}}function zl(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(i instanceof Z){const a=i.matrix.length,s=a>0?i.matrix[0].length:0;if(n!==a)return new Z(0,0,NaN,t);const o=new Z(r,s,0,t);for(let l=0;l<r;l++)for(let c=0;c<s;c++){let u=0;for(let p=0;p<n;p++)u+=e.matrix[l][p]*i.matrix[p][c];o.matrix[l][c]=u}return o}else if(i instanceof U||Array.isArray(i.array||i)){const a=i.array||i;if(n!==a.length)return new U([],"float",t);const s=[];for(let o=0;o<r;o++){let l=0;for(let c=0;c<n;c++)l+=e.matrix[o][c]*a[c];s.push(l)}return new U(s,"float",t)}else{const a=i,s=new Z(r,n,NaN,t);for(let o=0;o<r;o++)for(let l=0;l<n;l++)s.matrix[o][l]=e.matrix[o][l]*a;return s}}}function Kl(t){return e=>{const i=e.matrix.length;if(i===0)return new Z(0,0,NaN,t);const r=e.matrix[0].length;if(i===r){const u=Ri(e.matrix),p=new Z(i,r,NaN,t);return p.matrix=u,p}const n=u=>{const p=u.length,h=u[0].length,f=new Array(h);for(let d=0;d<h;d++){f[d]=new Array(p);for(let m=0;m<p;m++)f[d][m]=u[m][d]}return f},a=(u,p)=>{const h=u.length,f=u[0].length,d=p[0].length,m=new Array(h);for(let x=0;x<h;x++){m[x]=new Array(d).fill(0);for(let b=0;b<f;b++){const v=u[x][b];if(v!==0)for(let w=0;w<d;w++)m[x][w]+=v*p[b][w]}}return m},s=e.matrix,o=n(s);let l;if(i>r){const u=a(o,s),p=Ri(u);l=a(p,o)}else{const u=a(s,o),p=Ri(u);l=a(o,p)}const c=new Z(r,i,NaN,t);return c.matrix=l,c}}function Hl(t){return(e,i)=>{const r=e.matrix.length,n=r>0?e.matrix[0].length:0;if(r!==n)return new Z(0,0,NaN,t);let a=new Z(r,n,0,t);for(let l=0;l<r;l++)a.matrix[l][l]=1;let s=new Z(r,n,NaN,t);for(let l=0;l<r;l++)s.matrix[l]=[...e.matrix[l]];let o=Math.floor(i);if(o<0)return new Z(r,n,NaN,t);for(;o>0;){if(o%2===1){const c=new Z(r,n,0,t);for(let u=0;u<r;u++)for(let p=0;p<n;p++){let h=0;for(let f=0;f<r;f++)h+=a.matrix[u][f]*s.matrix[f][p];c.matrix[u][p]=h}a=c}const l=new Z(r,n,0,t);for(let c=0;c<r;c++)for(let u=0;u<n;u++){let p=0;for(let h=0;h<r;h++)p+=s.matrix[c][h]*s.matrix[h][u];l.matrix[c][u]=p}s=l,o=Math.floor(o/2)}return a}}function Gl(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,n=e.matrix.map(s=>[...s]);let a=0;for(let s=0;s<r&&a<i;s++){let o=a;for(;o<i&&Math.abs(n[o][s])<1e-10;)o++;if(o<i){[n[a],n[o]]=[n[o],n[a]];const l=n[a][s];for(let c=s;c<r;c++)n[a][c]/=l;for(let c=0;c<i;c++)if(c!==a){const u=n[c][s];for(let p=s;p<r;p++)n[c][p]-=u*n[a][p]}a++}}return a}}function Yl(t){return(e,i)=>{const r=e.matrix.length;if(r===0){const s=Ye(e.matrix[0][0]);return new U([],s,t)}const n=[];for(let s=0;s<r;s++){const o=e.matrix[s].splice(i,1);n.push(o[0])}const a=Ye(n[0]);return new U(n,a,t)}}function Xl(t){return(e,i)=>{const r=e.matrix.splice(i,1),n=Ye(r[0][0]);return new U(r[0]||[],n,t)}}function Ql(t){return(e,i,r)=>{const n=e.matrix.length,a=n>0?e.matrix[0].length:0,s=i*r,o=[];for(let u=0;u<n;u++)for(let p=0;p<a;p++)o.push(e.matrix[u][p]);for(;o.length<s;)o.push(NaN);o.length>s&&(o.length=s);const l=[];let c=0;for(let u=0;u<i;u++){const p=[];for(let h=0;h<r;h++)p.push(o[c++]);l.push(p)}e.matrix=l}}function Zl(t){return e=>{e.matrix.reverse();for(const i of e.matrix)i.reverse()}}function Jl(t){return(e,i)=>{const r=e.matrix.length;if(i<0||i>=r){t.warn(`Row index ${i} is out of bounds, matrix has ${r} rows.`,"matrix.row");const a=r>0?Ye(e.matrix[0][0]):"float";return new U([],a,t)}const n=Ye(e.matrix[i][0]);return new U([...e.matrix[i]],n,t)}}function ec(t){return e=>e.matrix.length}function tc(t){return(e,i,r,n)=>{const a=e.matrix.length,s=a>0?e.matrix[0].length:0;if(i<0||i>=a){t.warn(`Row index ${i} is out of bounds, matrix has ${a} rows.`,"matrix.set");return}if(r<0||r>=s){t.warn(`Column index ${r} is out of bounds, matrix has ${s} columns.`,"matrix.set");return}e.matrix[i][r]=n}}function ic(t){return(e,i=0,r="asc")=>{e.matrix.length!==0&&e.matrix.sort((n,a)=>{const s=n[i],o=a[i];return s<o?r==="asc"?-1:1:s>o?r==="asc"?1:-1:0})}}function rc(t){return(e,i,r,n,a)=>{const s=r-i,o=a-n,l=new Z(s,o,NaN,t);for(let c=0;c<s;c++){const u=i+c;if(u>=e.matrix.length)break;for(let p=0;p<o;p++){const h=n+p;if(h>=e.matrix[u].length)break;l.matrix[c][p]=e.matrix[u][h]}}return l}}function nc(t){return(e,i)=>{const r=e.matrix.length;if(r===0)return new Z(0,0,NaN,t);const n=e.matrix[0].length,a=new Z(r,n,NaN,t);if(i instanceof Z)for(let s=0;s<r;s++)for(let o=0;o<n;o++){const l=e.matrix[s][o],c=i.matrix[s]&&i.matrix[s][o]!==void 0?i.matrix[s][o]:NaN;a.matrix[s][o]=l+c}else{const s=i;for(let o=0;o<r;o++)for(let l=0;l<n;l++)a.matrix[o][l]=e.matrix[o][l]+s}return a}}function sc(t){return(e,i,r)=>{const n=e.matrix.length;for(let a=0;a<n;a++){const s=e.matrix[a][i];e.matrix[a][i]=e.matrix[a][r],e.matrix[a][r]=s}}}function ac(t){return(e,i,r)=>{const n=e.matrix[i];e.matrix[i]=e.matrix[r],e.matrix[r]=n}}function oc(t){return e=>{const i=e.matrix.length;if(i===0)return 0;const r=e.matrix[0].length,n=Math.min(i,r);let a=0;for(let s=0;s<n;s++)a+=e.matrix[s][s];return a}}function lc(t){return e=>{const i=e.matrix.length;if(i===0)return new Z(0,0,NaN,t);const r=e.matrix[0].length,n=new Z(r,i,NaN,t);for(let a=0;a<i;a++)for(let s=0;s<r;s++)n.matrix[s][a]=e.matrix[a][s];return n}}var cc=Object.defineProperty,uc=(t,e,i)=>e in t?cc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,B=(t,e,i)=>uc(t,typeof e!="symbol"?e+"":e,i);class Z{constructor(e=0,i=0,r=NaN,n){if(this.context=n,B(this,"matrix"),B(this,"_add_col"),B(this,"_add_row"),B(this,"_avg"),B(this,"_col"),B(this,"_columns"),B(this,"_concat"),B(this,"_copy"),B(this,"_det"),B(this,"_diff"),B(this,"_eigenvalues"),B(this,"_eigenvectors"),B(this,"_elements_count"),B(this,"_fill"),B(this,"_get"),B(this,"_inv"),B(this,"_is_antidiagonal"),B(this,"_is_antisymmetric"),B(this,"_is_binary"),B(this,"_is_diagonal"),B(this,"_is_identity"),B(this,"_is_square"),B(this,"_is_stochastic"),B(this,"_is_symmetric"),B(this,"_is_triangular"),B(this,"_is_zero"),B(this,"_kron"),B(this,"_max"),B(this,"_median"),B(this,"_min"),B(this,"_mode"),B(this,"_mult"),B(this,"_pinv"),B(this,"_pow"),B(this,"_rank"),B(this,"_remove_col"),B(this,"_remove_row"),B(this,"_reshape"),B(this,"_reverse"),B(this,"_row"),B(this,"_rows"),B(this,"_set"),B(this,"_sort"),B(this,"_submatrix"),B(this,"_sum"),B(this,"_swap_columns"),B(this,"_swap_rows"),B(this,"_trace"),B(this,"_transpose"),this.matrix=[],e>0&&i>0)for(let a=0;a<e;a++)this.matrix.push(Array(i).fill(r));this._add_col=fl(this.context),this._add_row=dl(this.context),this._avg=ml(this.context),this._col=yl(this.context),this._columns=_l(this.context),this._concat=gl(this.context),this._copy=xl(this.context),this._det=vl(this.context),this._diff=wl(this.context),this._eigenvalues=El(this.context),this._eigenvectors=Nl(this.context),this._elements_count=Cl(this.context),this._fill=Il(this.context),this._get=kl(this.context),this._inv=Tl(this.context),this._is_antidiagonal=Al(this.context),this._is_antisymmetric=Pl(this.context),this._is_binary=Ml(this.context),this._is_diagonal=Dl(this.context),this._is_identity=Rl(this.context),this._is_square=Ol(this.context),this._is_stochastic=$l(this.context),this._is_symmetric=Vl(this.context),this._is_triangular=jl(this.context),this._is_zero=Ll(this.context),this._kron=Bl(this.context),this._max=Fl(this.context),this._median=Wl(this.context),this._min=Ul(this.context),this._mode=ql(this.context),this._mult=zl(this.context),this._pinv=Kl(this.context),this._pow=Hl(this.context),this._rank=Gl(this.context),this._remove_col=Yl(this.context),this._remove_row=Xl(this.context),this._reshape=Ql(this.context),this._reverse=Zl(this.context),this._row=Jl(this.context),this._rows=ec(this.context),this._set=tc(this.context),this._sort=ic(this.context),this._submatrix=rc(this.context),this._sum=nc(this.context),this._swap_columns=sc(this.context),this._swap_rows=ac(this.context),this._trace=oc(this.context),this._transpose=lc(this.context)}toString(){let e="";for(let i=0;i<this.matrix.length;i++)e+=e===""?"":`
2
+ `,e+="["+this.matrix[i].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 Je(t){return(e,i,r)=>new Z(e,i,r,t)}function hc(t){return(e,i=0)=>y.from(e).get(i)}class pc{constructor(e){this.context=e,this.add_col=(i,...r)=>i.add_col(...r),this.add_row=(i,...r)=>i.add_row(...r),this.avg=(i,...r)=>i.avg(...r),this.col=(i,...r)=>i.col(...r),this.columns=(i,...r)=>i.columns(...r),this.concat=(i,...r)=>i.concat(...r),this.copy=(i,...r)=>i.copy(...r),this.det=(i,...r)=>i.det(...r),this.diff=(i,...r)=>i.diff(...r),this.eigenvalues=(i,...r)=>i.eigenvalues(...r),this.eigenvectors=(i,...r)=>i.eigenvectors(...r),this.elements_count=(i,...r)=>i.elements_count(...r),this.fill=(i,...r)=>i.fill(...r),this.get=(i,...r)=>i.get(...r),this.inv=(i,...r)=>i.inv(...r),this.is_antidiagonal=(i,...r)=>i.is_antidiagonal(...r),this.is_antisymmetric=(i,...r)=>i.is_antisymmetric(...r),this.is_binary=(i,...r)=>i.is_binary(...r),this.is_diagonal=(i,...r)=>i.is_diagonal(...r),this.is_identity=(i,...r)=>i.is_identity(...r),this.is_square=(i,...r)=>i.is_square(...r),this.is_stochastic=(i,...r)=>i.is_stochastic(...r),this.is_symmetric=(i,...r)=>i.is_symmetric(...r),this.is_triangular=(i,...r)=>i.is_triangular(...r),this.is_zero=(i,...r)=>i.is_zero(...r),this.kron=(i,...r)=>i.kron(...r),this.max=(i,...r)=>i.max(...r),this.median=(i,...r)=>i.median(...r),this.min=(i,...r)=>i.min(...r),this.mode=(i,...r)=>i.mode(...r),this.mult=(i,...r)=>i.mult(...r),this.new=Je(e),this.param=hc(),this.pinv=(i,...r)=>i.pinv(...r),this.pow=(i,...r)=>i.pow(...r),this.rank=(i,...r)=>i.rank(...r),this.remove_col=(i,...r)=>i.remove_col(...r),this.remove_row=(i,...r)=>i.remove_row(...r),this.reshape=(i,...r)=>i.reshape(...r),this.reverse=(i,...r)=>i.reverse(...r),this.row=(i,...r)=>i.row(...r),this.rows=(i,...r)=>i.rows(...r),this.set=(i,...r)=>i.set(...r),this.sort=(i,...r)=>i.sort(...r),this.submatrix=(i,...r)=>i.submatrix(...r),this.sum=(i,...r)=>i.sum(...r),this.swap_columns=(i,...r)=>i.swap_columns(...r),this.swap_rows=(i,...r)=>i.swap_rows(...r),this.trace=(i,...r)=>i.trace(...r),this.transpose=(i,...r)=>i.transpose(...r),this.new_float=Je(e),this.new_int=Je(e),this.new_string=Je(e),this.new_bool=Je(e),this.new_color=Je(e),this.new_line=Je(e),this.new_label=Je(e),this.new_box=Je(e),this.new_linefill=Je(e),this.new_table=Je(e)}}var fc=Object.defineProperty,dc=(t,e,i)=>e in t?fc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,mc=(t,e,i)=>dc(t,typeof e!="symbol"?e+"":e,i);class yc{constructor(e){this.context=e,mc(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(){const e=this.context.idx,i=this.context.length;if(e===i-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===i-2){const r=this.context.marketData?.[i-1]?.closeTime;return r!==void 0?r>Date.now():!1}return!1}}var _c=Object.defineProperty,gc=(t,e,i)=>e in t?_c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,xc=(t,e,i)=>gc(t,typeof e!="symbol"?e+"":e,i);class It{constructor(e,i,r){this._definition=e,this.context=i,xc(this,"_udt");for(let n in e)this[n]=e[n];this._udt=r}get __def__(){return this._definition}copy(){return new It(this.__def__,this.context,this._udt)}toString(){const e={};for(let i in this.__def__){const r=this[i];r!=null&&typeof r=="object"&&typeof r.toString=="function"&&!(r instanceof Array)?e[i]=r.toString():e[i]=r}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(i=>`"${i}":${String(e[i])}`).join(",")+"}"}}}var bc=Object.defineProperty,vc=(t,e,i)=>e in t?bc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ur=(t,e,i)=>vc(t,typeof e!="symbol"?e+"":e,i);class Ae{constructor(e,i,r){ur(this,"time"),ur(this,"index"),ur(this,"price"),this.time=e,this.index=i,this.price=r}copy(){return new Ae(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}}function wc(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}const ln={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 Ae,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 Ae)&&!wc(t)};function tt(t){const e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function re(t,e,i,r){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);const n={};let a={};const s=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){const l=t[o];if(ln.remaining_options(l)){a=l;break}const c=e.map((u,p)=>s[p]?u[o]:void 0);for(let u=0;u<c.length;u++){const p=c[u];if(p===void 0){s[u]=!1;continue}const h=i[p];if(typeof l=="number"&&isNaN(l)&&(h==="number"||h==="series"))n[p]=l;else{const f=ln[i[p]];typeof f=="function"&&f(l)?n[p]=l:s[u]=!1}}}return{...n,...a,...r}}function C(t,e,i){const r=i.value;return typeof r!="function"||(i.value=function(...n){return this&&this.context&&this.context.isSecondaryContext?null:r.apply(this,n)}),i}var Ns=Object.defineProperty,Sc=Object.getOwnPropertyDescriptor,Ec=(t,e,i)=>e in t?Ns(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Cs=(t,e,i,r)=>{for(var n=r>1?void 0:r?Sc(e,i):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(r?s(e,i,n):s(n))||n);return r&&n&&Ns(e,i,n),n},ei=(t,e,i)=>Ec(t,typeof e!="symbol"?e+"":e,i);const Nc=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],Cc={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},Ic=["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"],kc={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 Tc(t){return re(t,Ic,kc)}class $e{get __value(){return NaN}param(e,i=0){return y.from(e).get(i)}any(e){if(e instanceof $e)return!0;const i=y.from(e).get(0);return i instanceof $e||i==null?!0:typeof i=="number"?i!==i:!1}}const Kt={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"};class Is{constructor(e){this.context=e,ei(this,"_firedKeys",new Set),ei(this,"_fallbackCounter",0),ei(this,"_fallbackLastExecTick",-1)}get freq_all(){return Kt.freq_all}get freq_once_per_bar(){return Kt.freq_once_per_bar}get freq_once_per_bar_close(){return Kt.freq_once_per_bar_close}param(e,i,r){return y.from(e).get(0)}any(e,i,r){const n=y.from(e).get(0),a=i?y.from(i).get(0):Kt.freq_once_per_bar;let s;if(r&&typeof r=="object"&&r.__callsiteId)s=r.__callsiteId;else{const u=this.context._execTick||0;u!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=u),s=`alert_${this._fallbackCounter++}`}const o=this.context.idx,l=this.context.pine?.barstate?.isrealtime??o===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${s}:${o}`;if(a===Kt.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(a===Kt.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:s,message:n,freq:a,bar_index:o,time:this.context.data.openTime?.data?.[o]??0})}}Cs([C],Is.prototype,"any",1);class ks{constructor(e){this.context=e,ei(this,"_acCounter",0),ei(this,"_acLastExecTick",-1),ei(this,"_acFiredKeys",new Set)}extractPlotOptions(e){const i={};for(let r in e)i[r]=y.from(e[r]).get(0);return i}indicator(...e){const i=e.map(a=>a instanceof y?a.get(0):a),r=Tc(i),n={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={...n,...r,...this.context._propOverrides??{}},this.context.indicator}get bar_index(){return this.context.idx}na(e){const i=y.from(e).get(0);return i==null||typeof i=="number"&&isNaN(i)}nz(e,i=0){const r=y.from(e).get(0),n=y.from(i).get(0);return r==null||typeof r=="number"&&isNaN(r)?n:r}fixnan(e){const i=y.from(e);for(let r=0;r<i.length;r++){const n=i.get(r);if(!isNaN(n))return n}return NaN}alertcondition(e,i,r){const n=y.from(e).get(0),a=this.context.idx,s=this.context._execTick||0;s!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=s);const o=`alertcondition_${this._acCounter++}`;if(!n)return;const l=this.context.pine?.barstate?.isrealtime??a===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;const c=`${o}:${a}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);const u=i?y.from(i).get(0):"",p=r?y.from(r).get(0):"";this.context.alerts.push({type:"alertcondition",id:o,title:u,message:p,bar_index:a,time:this.context.data.openTime?.data?.[a]??0})}error(...e){console.error("error called but is currently not implemented",e)}max_bars_back(e,i){}timestamp(...e){const i=e.map(n=>n instanceof y?n.get(0):n),r=re(i,Nc,Cc);if(r.year!==void 0){const n=r.year,a=r.month,s=r.day,o=r.hour||0,l=r.minute||0,c=r.second||0,u=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(u,n,a,s,o,l,c)}if(r.dateString!==void 0){const n=r.dateString.trim();if(/[Zz]$/.test(n)||/[+-]\d{2}:?\d{2}$/.test(n))return new Date(n).getTime();const a=n.includes("T")?n+"Z":n.replace(/\s+/,"T")+"Z",s=new Date(a);if(!isNaN(s.getTime())){const o=this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(o,s.getUTCFullYear(),s.getUTCMonth()+1,s.getUTCDate(),s.getUTCHours(),s.getUTCMinutes(),s.getUTCSeconds())}return new Date(n).getTime()}return NaN}_timestampFromComponents(e,i,r,n,a,s,o){const l=new Date(Date.UTC(i,r-1,n,a,s,o));i>=0&&i<100&&l.setUTCFullYear(i);const c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();const u=c.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(u){const p=u[1]==="+"?1:-1,h=parseInt(u[2],10),f=parseInt(u[3]||"0",10),d=p*(h*60+f)*60*1e3;return l.getTime()-d}try{return this._timestampFromIANA(e,i,r,n,a,s,o)}catch{return l.getTime()}}_timestampFromIANA(e,i,r,n,a,s,o){const l=new Date(Date.UTC(i,r-1,n,a,s,o));i>=0&&i<100&&l.setUTCFullYear(i);const 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=w=>parseInt(c.find(S=>S.type===w)?.value||"0",10),p=u("year"),h=u("month"),f=u("day");let d=u("hour");d===24&&(d=0);const m=u("minute"),x=u("second"),b=new Date(Date.UTC(p,h-1,f,d,m,x));p>=0&&p<100&&b.setUTCFullYear(p);const v=b.getTime()-l.getTime();return l.getTime()-v}bool(e){const i=y.from(e).get(0);return!isNaN(i)&&i!==0}int(e){const i=y.from(e).get(0);if(typeof i!="number")throw new Error(`Cannot call "int" with argument "x"="${i}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.trunc(i)}float(e){const i=y.from(e).get(0);if(typeof i!="number")throw new Error(`Cannot call "float" with argument "x"="${i}". An argument of "literal string" type was used but a "const float" is expected.`);return i}string(e){return y.from(e).get(0).toString()}Type(e){const i=Object.keys(e),r={};for(const a of i){let s=e[a];s instanceof y&&(s=s.data),Array.isArray(s)&&(s[0],r[a]=s[1])}const n={new:function(...a){const s={};let o=null;if(a.length>0){const l=a[a.length-1];if(l&&typeof l=="object"&&!(l instanceof y)&&!Array.isArray(l)&&!(l instanceof It)){const c=Object.keys(l);c.length>0&&c.some(u=>i.includes(u))&&(o=l,a=a.slice(0,-1))}}for(let l=0;l<i.length;l++){const c=i[l];o&&c in o?s[c]=o[c]:l<a.length?s[c]=a[l]:c in r&&(s[c]=y.from(r[c]).get(0))}return new It(s,this.context,n)},copy:function(a){return new It(a.__def__,this.context,n)},_fieldDefaults:r,_definitionKeys:i};return n}}Cs([C],ks.prototype,"alertcondition",1);function Dt(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){const i=t.slice(1);return i.length===6?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),1]:i.length===8?[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),parseInt(i.slice(6,8),16)/255]:null}const 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 Ac(t,e,i,r){const n=Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0"),a=Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0"),s=Math.round(Math.max(0,Math.min(255,i))).toString(16).padStart(2,"0");if(r>=1)return`#${n}${a}${s}`.toUpperCase();const o=Math.round(Math.max(0,Math.min(255,r*255))).toString(16).padStart(2,"0");return`#${n}${a}${s}${o}`.toUpperCase()}const he={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 Ts(t){if(typeof t!="string")return null;let e=t.trim();const i=e.startsWith("color.")?e.slice(6):e;return Object.prototype.hasOwnProperty.call(he,i)&&(e=he[i]),Dt(e)}function wr(t,e,i,r){const n=a=>Math.round(Math.max(0,Math.min(255,a))).toString(16).padStart(2,"0");return`#${n(t)}${n(e)}${n(i)}${n(r*255)}`.toUpperCase()}function Pc(t){const e=Ts(t);return e?wr(e[0],e[1],e[2],e[3]):t}function nt(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}class Mc{constructor(e){this.context=e}any(e){const i=y.from(e).get(0);return typeof i=="number"&&isNaN(i)?null:i}param(e,i=0){return y.from(e).get(i)}new(e,i){if(e=nt(e),!e||typeof e!="string")return e;if(typeof i=="number"&&isNaN(i)&&(i=void 0),e.startsWith("#")){const r=e.slice(1),n=r.length===8?r.slice(0,6):r;return i!=null?`#${n}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:`#${r}`}else{const r=he[e];if(r)return i!=null?`#${r.slice(1)}${Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase()}`:r;const n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*([\d.]+))?\s*\)/);if(n){const a=n[1],s=n[2],o=n[3];if(i!=null){const l=parseInt(a).toString(16).padStart(2,"0"),c=parseInt(s).toString(16).padStart(2,"0"),u=parseInt(o).toString(16).padStart(2,"0"),p=Math.round(255/100*(100-i)).toString(16).padStart(2,"0").toUpperCase();return`#${l}${c}${u}${p}`}return e}return i!=null?`rgba(${e}, ${(100-i)/100})`:e}}rgb(e,i,r,n){return typeof n=="number"&&isNaN(n)&&(n=void 0),n!=null?`rgba(${e}, ${i}, ${r}, ${(100-n)/100})`:`rgb(${e}, ${i}, ${r})`}from_gradient(e,i,r,n,a){if(e=nt(e),i=nt(i),r=nt(r),n=nt(n),a=nt(a),e==null||typeof e=="number"&&isNaN(e)||i==null||typeof i=="number"&&isNaN(i)||r==null||typeof r=="number"&&isNaN(r)||n==null||typeof n=="number"&&isNaN(n)||a==null||typeof a=="number"&&isNaN(a))return;let s=0;r!==i&&(s=(e-i)/(r-i)),s=Math.max(0,Math.min(1,s));const o=Dt(typeof n=="string"?n:"#000000")||[0,0,0,1],l=Dt(typeof a=="string"?a:"#FFFFFF")||[255,255,255,1],c=o[0]+(l[0]-o[0])*s,u=o[1]+(l[1]-o[1])*s,p=o[2]+(l[2]-o[2])*s,h=o[3]+(l[3]-o[3])*s;return Ac(c,u,p,h)}r(e){if(e=nt(e),!e||typeof e!="string")return NaN;const i=Dt(e);return i?i[0]:NaN}g(e){if(e=nt(e),!e||typeof e!="string")return NaN;const i=Dt(e);return i?i[1]:NaN}b(e){if(e=nt(e),!e||typeof e!="string")return NaN;const i=Dt(e);return i?i[2]:NaN}t(e){if(e=nt(e),!e||typeof e!="string")return NaN;const i=Dt(e);return i?Math.round(100-i[3]*100):NaN}aqua(){return he.aqua}black(){return he.black}blue(){return he.blue}fuchsia(){return he.fuchsia}gray(){return he.gray}green(){return he.green}lime(){return he.lime}maroon(){return he.maroon}navy(){return he.navy}olive(){return he.olive}orange(){return he.orange}purple(){return he.purple}red(){return he.red}silver(){return he.silver}teal(){return he.teal}white(){return he.white}yellow(){return he.yellow}}var Dc=Object.defineProperty,Rc=(t,e,i)=>e in t?Dc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Wi=(t,e,i)=>Rc(t,typeof e!="symbol"?e+"":e,i);function Sr(t){if(!t)return"";const e=t.trim().toUpperCase();return e==="1D"||e==="D"?"D":e==="1W"||e==="W"?"W":e==="1M"||e==="M"?"M":e}function Er(t,e){const i=Oc(e);if(e==="M"){const o=new Date(t);return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),1)}if(e==="W"){const 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"||i>=1440)return Math.floor(t/864e5)*864e5;const r=i*6e4,n=Math.floor(t/864e5)*864e5,a=t-n,s=Math.floor(a/r)*r;return n+s}function Oc(t){if(t==="D")return 1440;if(t==="W")return 10080;if(t==="M")return 43200;const e=parseInt(t,10);return isNaN(e)?1440:e}function Vt(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC"){const n=new Date(t);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),dayOfWeek:n.getUTCDay()}}const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const n=r[1]==="+"?1:-1,a=parseInt(r[2],10),s=parseInt(r[3]||"0",10),o=n*(a*60+s)*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{const n=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)),a=c=>parseInt(n.find(u=>u.type===c)?.value||"0",10);let s=a("hour");s===24&&(s=0);const o=n.find(c=>c.type==="weekday")?.value||"Sun",l={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:a("year"),month:a("month"),day:a("day"),hour:s,minute:a("minute"),second:a("second"),dayOfWeek:l[o]??0}}catch{const n=new Date(t);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),dayOfWeek:n.getUTCDay()}}}function $c(t,e,i){const r=new Date(Date.UTC(t,e-1,i)),n=r.getUTCDay()||7;r.setUTCDate(r.getUTCDate()+4-n);const a=new Date(Date.UTC(r.getUTCFullYear(),0,1));return Math.ceil(((r.getTime()-a.getTime())/864e5+1)/7)}const Vc=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],jc={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"};class cn{constructor(e,i="openTime"){Wi(this,"context"),Wi(this,"dataField"),this.context=e,this.dataField=i}get __value(){return this.context.data[this.dataField]}param(e,i=0){return y.from(e).get(i)}any(...e){const i=e.map(h=>h instanceof y?h.get(0):h),r=re(i,Vc,jc),n=r.bars_back??0,a=r.timeframe||"",s=this.context.data[this.dataField],o=y.from(s).get(n);if(isNaN(o)||o==null)return NaN;const l=this.context.timeframe||"",c=Sr(a),u=Sr(l);let p;if(!c||c===u?p=o:p=Er(o,c),r.session!==void 0&&r.session!==""){const h=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(p,r.session,h)?p:NaN}return p}_isInSession(e,i,r){const n=i.match(/^(\d{2})(\d{2})-(\d{2})(\d{2})$/);if(!n)return!0;const a=parseInt(n[1],10),s=parseInt(n[2],10),o=parseInt(n[3],10),l=parseInt(n[4],10),c=Vt(e,r),u=c.hour,p=c.minute,h=u*60+p,f=a*60+s,d=o*60+l;return f<=d?h>=f&&h<d:h>=f||h<d}}const Lc=[[],["time"],["time","timezone"]],Bc={time:"number",timezone:"string"};class wt{constructor(e,i){Wi(this,"context"),Wi(this,"extractor"),this.context=e,this.extractor=i}get __value(){const e=y.from(this.context.data.openTime).get(0);if(isNaN(e))return NaN;const i=this.context.pine?.syminfo?.timezone||"UTC",r=Vt(e,i);return this.extractor(r)}param(e,i=0){return y.from(e).get(i)}any(...e){const i=e.map(o=>o instanceof y?o.get(0):o);if(i.length===0)return this.__value;const r=re(i,Lc,Bc),n=r.time;if(n===void 0||isNaN(n))return NaN;const a=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",s=Vt(n,a);return this.extractor(s)}}const St={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=>$c(t.year,t.month,t.day),year:t=>t.year},Fc=[["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"]],Wc={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function je(t){let e;const i=t[t.length-1];i&&typeof i=="object"&&Object.prototype.hasOwnProperty.call(i,"__varId")&&(e=i.__varId,t=t.slice(0,-1));const r=re(t,Fc,Wc);return e!==void 0&&(r.__varId=e),r}function We(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 Uc(t){return(...e)=>{const i=je(e);return We(t,i)}}function qc(t){return(...e)=>{const i=je(e);return We(t,i)}}function zc(t){return(...e)=>{const i=je(e);return We(t,i)}}function Kc(t){return(...e)=>{const i=je(e);return We(t,i)}}function Hc(t){return(...e)=>{const i=je(e);return We(t,i)}}function Gc(t){return(...e)=>{const i=je(e);return We(t,i)}}function Yc(t){return(e,i=0)=>y.from(e).get(i)}function Xc(t){return(...e)=>{const i=je(e);return We(t,i)}}function Qc(t){return(...e)=>{const i=je(e);return We(t,i)}}function Zc(t){return(...e)=>{const i=je(e);return We(t,i)}}function Jc(t){return(...e)=>{const i=je(e);return We(t,i)}}function eu(t){return(...e)=>{const i=je(e);return We(t,i)}}function tu(t){return(...e)=>{const i=je(e);return We(t,i)}}function iu(t){return(...e)=>{const i=je(e);return We(t,i)}}function ru(t){return(...e)=>je(e).defval}var nu=Object.defineProperty,su=(t,e,i)=>e in t?nu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ke=(t,e,i)=>su(t,typeof e!="symbol"?e+"":e,i);const au={any:Uc,bool:qc,color:zc,enum:Kc,float:Hc,int:Gc,param:Yc,price:Xc,session:Qc,source:Zc,string:Jc,symbol:eu,text_area:tu,time:iu,timeframe:ru};class ou{constructor(e){this.context=e,ke(this,"any"),ke(this,"bool"),ke(this,"color"),ke(this,"enum"),ke(this,"float"),ke(this,"int"),ke(this,"param"),ke(this,"price"),ke(this,"session"),ke(this,"source"),ke(this,"string"),ke(this,"symbol"),ke(this,"text_area"),ke(this,"time"),ke(this,"timeframe"),Object.entries(au).forEach(([i,r])=>{this[i]=r(e)})}}function lu(t){return e=>Math.abs(y.from(e).get(0))}function cu(t){return e=>Math.acos(y.from(e).get(0))}function uu(t){return e=>Math.asin(y.from(e).get(0))}function hu(t){return e=>Math.atan(y.from(e).get(0))}function pu(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return i.reduce((r,n)=>r+n,0)/i.length}}function fu(t){return e=>Math.ceil(y.from(e).get(0))}function du(t){return e=>Math.cos(y.from(e).get(0))}function mu(t){return()=>Math.E}function yu(t){return e=>Math.exp(y.from(e).get(0))}function _u(t){return e=>Math.floor(y.from(e).get(0))}function gu(t){return e=>Math.log(y.from(e).get(0))}function xu(t){return e=>Math.log(y.from(e).get(0))}function bu(t){return e=>Math.log10(y.from(e).get(0))}function vu(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return Math.max(...i)}}function wu(t){return(...e)=>{const i=e.map(r=>y.from(r).get(0));return Math.min(...i)}}function Su(t){return(e,i,r)=>typeof e=="string"?e:e instanceof y?i?new y(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new y(t.params[r],i||0)))}function Eu(t){return()=>1.618033988749895}function Nu(t){return()=>Math.PI}function Cu(t){return(e,i)=>Math.pow(y.from(e).get(0),y.from(i).get(0))}function Iu(t){return()=>Math.random()}function hr(t){return t!==t?NaN:Math.sign(t)*Math.round(Math.abs(t))}function ku(t){return(e,i)=>{const r=y.from(e).get(0);if(i==null)return hr(r);const n=y.from(i).get(0);if(n===0)return hr(r);const a=Math.pow(10,n);return hr(r*a)/a}}function Tu(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Au(t){return()=>.6180339887498948}function Pu(t){return e=>Math.sign(y.from(e).get(0))}function Mu(t){return e=>Math.sin(y.from(e).get(0))}function Du(t){return e=>Math.sqrt(y.from(e).get(0))}function Ru(t){return(e,i)=>{const r=y.from(i).get(0),n=y.from(e);let a=0;for(let s=0;s<r;s++){const o=n.get(s);a+=o}return a}}function Ou(t){return e=>Math.tan(y.from(e).get(0))}function $u(t){return e=>{const i=y.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(180/Math.PI)}}function Vu(t){return e=>{const i=y.from(e).get(0);return i==null||Number.isNaN(i)?NaN:i*(Math.PI/180)}}function ju(t){return(e,i)=>{const r=y.from(e).get(0),n=y.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)||isNaN(n)?!1:Math.abs(r-n)<1e-9:r===n}}function Lu(t){return(e,i)=>{const r=y.from(e).get(0),n=y.from(i).get(0);return typeof r=="number"&&typeof n=="number"?isNaN(r)||isNaN(n)?!1:Math.abs(r-n)>=1e-9:r!==n}}var Bu=Object.defineProperty,Fu=(t,e,i)=>e in t?Bu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Y=(t,e,i)=>Fu(t,typeof e!="symbol"?e+"":e,i);const Wu={abs:lu,acos:cu,asin:uu,atan:hu,avg:pu,ceil:fu,cos:du,e:mu,exp:yu,floor:_u,ln:gu,log:xu,log10:bu,max:vu,min:wu,param:Su,phi:Eu,pi:Nu,pow:Cu,random:Iu,round:ku,round_to_mintick:Tu,rphi:Au,sign:Pu,sin:Mu,sqrt:Du,sum:Ru,tan:Ou,todegrees:$u,toradians:Vu,__eq:ju,__neq:Lu};class Uu{constructor(e){this.context=e,Y(this,"_cache",{}),Y(this,"abs"),Y(this,"acos"),Y(this,"asin"),Y(this,"atan"),Y(this,"avg"),Y(this,"ceil"),Y(this,"cos"),Y(this,"e"),Y(this,"exp"),Y(this,"floor"),Y(this,"ln"),Y(this,"log"),Y(this,"log10"),Y(this,"max"),Y(this,"min"),Y(this,"param"),Y(this,"phi"),Y(this,"pi"),Y(this,"pow"),Y(this,"random"),Y(this,"round"),Y(this,"round_to_mintick"),Y(this,"rphi"),Y(this,"sign"),Y(this,"sin"),Y(this,"sqrt"),Y(this,"sum"),Y(this,"tan"),Y(this,"todegrees"),Y(this,"toradians"),Y(this,"__eq"),Y(this,"__neq"),Object.entries(Wu).forEach(([i,r])=>{this[i]=r(e)})}}function qu(t){return(e,i,r)=>{t.params[r]||(t.params[r]=[]);let n;if(e instanceof y)n=e.get(i||0);else if(Array.isArray(e)){const a=e.some(o=>o instanceof y),s=e.every(o=>!(o instanceof y)&&!Array.isArray(o));(a||s)&&e.length>=1?n=e.map(o=>o instanceof y?o.get(0):o):n=y.from(e).get(i||0)}else n=e;return t.params[r].length===0?t.params[r].push(n):t.params[r][t.params[r].length-1]=n,t._requestParamSources||(t._requestParamSources={}),t._requestParamSources[r]=e,[n,r]}}const ii=["1","3","5","15","30","45","60","120","180","240","D","W","M"],Ni={"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 Ui(t){if(ii.includes(t))return t;if(Ni[t])return Ni[t];const e=t.toLowerCase();if(Ni[e])return Ni[e];const i=t.toUpperCase();return ii.includes(i)?i:t}function un(t,e,i,r,n=!1,a=!1){for(let s=0;s<i.length;s++)if(i[s]<=t&&t<r[s])return n||a||e>=r[s]?s:s-1;return-1}function hn(t,e,i,r,n=!1,a,s=!1){for(let o=i.length-1;o>=0;o--){if(r[o]<=e&&i[o]>=t){const l=a&&e>a;if(s&&n)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}if(l&&n&&!s)for(let c=0;c<i.length;c++){if(i[c]>=t&&i[c]<e)return c;if(i[c]>=e)break}return o}if(r[o]<t)break}return-1}const pn=[["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"]],zu={symbol:"series",timeframe:"series",expression:"any",gaps:"series",lookahead:"series",ignore_invalid_symbol:"series",currency:"series",calc_bars_count:"series"};function Br(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function Ku(t,e){return t.map(i=>Br(i)?(e.push(i[1]),i[0]):(e.push(void 0),i))}function Ht(t){return Br(t)?t[0]:t}function Hu(t,e,i,r){const n=e[e.length-1].indexOf(t);if(n>=0&&n<i.length&&i[n]!==void 0)return i[n];if(Br(r))return r[1]}function Nr(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(Nr):t}function Gu(t){return async(...e)=>{const i=[],r=Ku(e,i),n=re(r,pn,zu),a=Ht(n.symbol),s=Ht(n.timeframe),o=Ht(n.expression),l=Ht(n.gaps),c=Ht(n.lookahead),u=a instanceof y?a.get(0):a,p=u===""?t.tickerId:u,h=typeof p=="string"&&p.includes(":")?p.split(":")[1]:p,f=s instanceof y?s.get(0):s,d=f===""?t.timeframe:typeof f=="string"?f:String(f??""),m=o,x=Hu("expression",pn,i,n.expression),b=l,v=c,w=b===!0||b==="gaps_on",S=v===!0||v==="lookahead_on",A=(()=>{const be=Ht(n.calc_bars_count);return typeof be=="number"&&be>0?be:void 0})();if(t.isSecondaryContext){const be=Nr(m);return Array.isArray(be)?[be]:be}const N=ii.indexOf(Ui(t.timeframe)),P=ii.indexOf(Ui(d));if(N==-1||P==-1)throw new Error("Invalid timeframe");const j=typeof t.tickerId=="string"&&t.tickerId.includes(":")?t.tickerId.split(":")[1]:t.tickerId;if(N===P&&(!h||h===""||h===j)){const be=Nr(m);return Array.isArray(be)?[be]:be}const I=N>P,V=y.from(t.data.openTime).get(0),k=y.from(t.data.closeTime).get(0),L=t.idx===t.length-1&&k>Date.now(),D=`${h}_${d}_${x}`,M=`${D}_prevIdx`;if(t.cache[D]){const be=t.cache[D];t.dataVersion>be.dataVersion&&(await be.pineTS.updateTail(be.context),be.dataVersion=t.dataVersion);const ai=be.context,Ei=I?hn(V,k,ai.data.openTime.data,ai.data.closeTime.data,S,t.eDate,w):un(V,k,ai.data.openTime.data,ai.data.closeTime.data,S,L);if(Ei==-1)return NaN;const zt=ai.params[x][Ei];if(!I&&w){const on=t.cache[M];return on!==void 0&&on===Ei?NaN:(t.cache[M]=Ei,Array.isArray(zt)?[zt]:zt)}return Array.isArray(zt)?[zt]:zt}const K=1e3*60*60*24*30,J=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),_e=A?void 0:J?J-K:void 0,ne=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),Ee=new nn(t.source,h,d,A,_e,ne);Ee.markAsSecondary();const Ut=typeof x=="string"?x:"",Wa=Ut.match(/p\d+$/)?.[0]??Ut,an=t._ltfTruncatedBodies?.[Wa],qt=an?await Ee.runPretranspiled(an):await Ee.run(t.pineTSCode);t.cache[D]={pineTS:Ee,context:qt,dataVersion:t.dataVersion};const lr=I?hn(V,k,qt.data.openTime.data,qt.data.closeTime.data,S,t.eDate,w):un(V,k,qt.data.openTime.data,qt.data.closeTime.data,S,L);if(lr==-1)return NaN;const cr=qt.params[x][lr];return!I&&w?(t.cache[M]=lr,NaN):Array.isArray(cr)?[cr]:cr}}const fn=[["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"]],Yu={symbol:"series",timeframe:"series",expression:"any",ignore_invalid_symbol:"series",currency:"series",ignore_invalid_timeframe:"series",calc_bars_count:"series"};function Fr(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function Xu(t,e){return t.map(i=>Fr(i)?(e.push(i[1]),i[0]):(e.push(void 0),i))}function Gt(t){return Fr(t)?t[0]:t}function Qu(t,e,i,r){const n=e[e.length-1].indexOf(t);if(n>=0&&n<i.length&&i[n]!==void 0)return i[n];if(Fr(r))return r[1]}function Yt(t){return typeof t=="number"?F.float:typeof t=="boolean"?F.bool:typeof t=="string"?F.string:F.any}const As={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 Cr(t,e){if(!(t instanceof y))return null;const i=e?.data;if(!i)return null;for(const r of Object.keys(As))if(t===i[r])return r;return null}function Zu(t,e){if(t instanceof y&&(t=t.get(0)),!(t instanceof It))return null;const i=t._udt;if(!i||!i._fieldDefaults||!Array.isArray(i._definitionKeys))return null;const r=i._definitionKeys;if(r.length===0)return null;const n=[];for(const a of r){if(!(a in i._fieldDefaults))return null;const s=i._fieldDefaults[a],o=Cr(s,e);if(o===null)return null;n.push(o)}return{kind:"udt",builtinNames:n,fieldNames:r,udt:i}}function Ju(t,e){if(t===void 0)return null;if(Array.isArray(t)){const r=[];for(const n of t){const a=Cr(n,e);if(a===null)return null;r.push(a)}return r.length>0?{kind:"tuple",builtinNames:r}:null}const i=Cr(t,e);return i!==null?{kind:"series",builtinNames:[i]}:Zu(t,e)}async function dn(t,e,i,r,n,a){const s=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 nn(t.source,e,i,r,s,o);l.markAsSecondary(),await l.ready();const c=l.openTime,u=l.closeTime,p=l.data,h=n.builtinNames.map(d=>As[d]);let f;if(n.kind==="series")f=p.map(d=>h[0](d));else if(n.kind==="tuple")f=p.map(d=>h.map(m=>m(d)));else{const d=n.fieldNames,m=n.udt;f=p.map(x=>{const b={};for(let v=0;v<d.length;v++)b[d[v]]=h[v](x);return new It(b,t,m)})}return{data:{openTime:{data:c},closeTime:{data:u}},params:{[a]:f}}}function eh(t){return async(...e)=>{const i=[],r=Xu(e,i),n=re(r,fn,Yu),a=Gt(n.symbol),s=Gt(n.timeframe),o=Gt(n.expression),l=a instanceof y?a.get(0):a,c=l===""?t.tickerId:l,u=typeof c=="string"&&c.includes(":")?c.split(":")[1]:c,p=s instanceof y?s.get(0):s,h=p===""?t.timeframe:typeof p=="string"?p:String(p??""),f=o,d=Qu("expression",fn,i,n.expression);Gt(n.ignore_invalid_symbol);const m=Gt(n.ignore_invalid_timeframe),x=(()=>{const M=Gt(n.calc_bars_count);return typeof M=="number"&&M>0?M:void 0})();if(t.isSecondaryContext)return Array.isArray(f)?[f.map(M=>new U([M],Yt(M),t))]:new U([f],Yt(f),t);const b=ii.indexOf(Ui(t.timeframe)),v=ii.indexOf(Ui(h));if(b===-1||v===-1){if(m)return NaN;throw new Error("Invalid timeframe")}if(v>b){if(m)return NaN;throw new Error(`Timeframe ${h} is not lower than or equal to chart timeframe ${t.timeframe}`)}if(v===b)return Array.isArray(f)?[f.map(M=>new U([M],Yt(M),t))]:new U([f],Yt(f),t);const w=`${u}_${h}_${d}_lower`,S=t._requestParamSources?.[d],A=Ju(S,t);if(!t.cache[w])if(A!==null){const M=await dn(t,u,h,x,A,d);t.cache[w]={pineTS:null,context:M,dataVersion:t.dataVersion,_fastPath:!0,_fastPathArgs:{builtinExpr:A}}}else{const M=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),K=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),J=new nn(t.source,u,h,x,M,K);J.markAsSecondary();const _e=typeof d=="string"?d:"",ne=_e.match(/p\d+$/)?.[0]??_e,Ee=t._ltfTruncatedBodies?.[ne];let Ut;Ee?Ut=await J.runPretranspiled(Ee):Ut=await J.run(t.pineTSCode),t.cache[w]={pineTS:J,context:Ut,dataVersion:t.dataVersion}}const N=t.cache[w];if(t.dataVersion>N.dataVersion)if(N._fastPath){const M=await dn(t,u,h,x,N._fastPathArgs.builtinExpr,d);N.context=M,N.dataVersion=t.dataVersion}else await N.pineTS.updateTail(N.context),N.dataVersion=t.dataVersion;const P=N.context,j=y.from(t.data.openTime).get(0),I=y.from(t.data.closeTime).get(0),V=P.data.openTime.data,k=P.data.closeTime.data,L=P.params[d];if(!L)return Array.isArray(f)?[f.map(()=>new U([],F.float,t))]:new U([],F.float,t);const D=[];for(let M=0;M<V.length;M++){const K=V[M];if(!(k[M]<=j)){if(K>=I)break;K>=j&&K<I&&D.push(L[M])}}if(D.length>0&&Array.isArray(D[0])){const M=D[0].length,K=[];for(let J=0;J<M;J++){const _e=D.map(Ee=>Ee[J]),ne=_e.length>0?Yt(_e[0]):F.float;K.push(new U(_e,ne,t))}return[K]}else{const M=D.length>0?Yt(D[0]):F.float;return new U(D,M,t)}}}var th=Object.defineProperty,ih=(t,e,i)=>e in t?th(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ci=(t,e,i)=>ih(t,typeof e!="symbol"?e+"":e,i);const rh={param:qu,security:Gu,security_lower_tf:eh};class nh{constructor(e){this.context=e,Ci(this,"_cache",{}),Ci(this,"param"),Ci(this,"security"),Ci(this,"security_lower_tf"),Object.entries(rh).forEach(([i,r])=>{this[i]=r(e)})}}function sh(t){return e=>{t.taState||(t.taState={});const i=e||"accdist";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.high,0),s=t.get(t.data.low,0),o=t.get(t.data.volume,0);if(isNaN(n)||isNaN(a)||isNaN(s)||isNaN(o))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);const l=a-s;let c=0;l!==0&&(c=(n-s-(a-n))/l*o);const u=r.prevCumulativeSum+c;return r.currentCumulativeSum=u,t.precision(u)}}function ah(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0),l=y.from(n).get(0);t.taState||(t.taState={});const c=a||`alma_${s}_${o}_${l}`;if(!t.taState[c]){const m=o*(s-1),x=s/l,b=[];let v=0;for(let w=0;w<s;w++){const S=Math.exp(-Math.pow(w-m,2)/(2*x*x));b.push(S),v+=S}for(let w=0;w<b.length;w++)b[w]/=v;t.taState[c]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weights:b}}const u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.prevWindow=[...u.currentWindow],u.prevCallCount=u.currentCallCount),u.lastIdx=t.idx);const p=y.from(e).get(0),h=[...u.prevWindow];for(h.unshift(p);h.length>s;)h.pop();const f=u.prevCallCount+1;if(h.length<s&&(f>=s||t.idx>=s-1)){const m=y.from(e);for(;h.length<s;)h.push(m.get(h.length))}if(u.currentWindow=h,u.currentCallCount=f,h.length<s)return NaN;let d=0;for(let m=0;m<s;m++)d+=u.weights[m]*h[s-1-m];return t.precision(d)}}function oh(t){return(e,i)=>{const r=y.from(e).get(0);t.taState||(t.taState={});const n=i||`atr_${r}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});const a=t.taState[n];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevAtr=a.currentAtr,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);const s=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(s)||isNaN(o)||isNaN(l))return NaN;const c=t.idx>0?t.get(t.data.close,1):null;let u;if(c!==null&&!isNaN(c)){const m=s-o,x=Math.abs(s-c),b=Math.abs(o-c);u=Math.max(m,x,b)}else u=s-o;let p=a.prevInitCount,h=a.prevInitSum,f=a.prevAtr;if(p<r){if(h+=u,p++,a.currentInitSum=h,a.currentInitCount=p,p===r){const m=h/r;return a.currentAtr=m,t.precision(m)}return NaN}const d=(f*(r-1)+u)/r;return a.currentAtr=d,t.precision(d)}}function lh(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"barssince";t.taState[r]||(t.taState[r]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevLastTrueIndex=n.currentLastTrueIndex),n.lastIdx=t.idx);const a=y.from(e).get(0);let s=n.prevLastTrueIndex;return a&&(s=t.idx),n.currentLastTrueIndex=s,s===null?NaN:t.idx-s}}function ch(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`bb_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];const u=[...l.prevWindow];let p=l.prevSum;for(u.unshift(c),p+=c;u.length>a;){const b=u.pop();p-=b}if(u.length<a&&t.idx>=a-1){const b=y.from(e);for(;u.length<a;){const v=b.get(u.length);if(isNaN(v))break;u.push(v),p+=v}}if(l.currentWindow=u,l.currentSum=p,u.length<a)return[[NaN,NaN,NaN]];const h=p/a;let f=0;for(let b=0;b<a;b++)f+=Math.pow(u[b]-h,2);const d=Math.sqrt(f/a),m=h+s*d,x=h-s*d;return[[t.precision(h),t.precision(m),t.precision(x)]]}}function uh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`bbw_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);const c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;const u=[...l.prevWindow];let p=l.prevSum;for(u.unshift(c),p+=c;u.length>a;){const v=u.pop();p-=v}if(u.length<a&&t.idx>=a-1){const v=y.from(e);for(;u.length<a;){const w=v.get(u.length);if(isNaN(w))break;u.push(w),p+=w}}if(l.currentWindow=u,l.currentSum=p,u.length<a)return NaN;const h=p/a;let f=0;for(let v=0;v<a;v++){const w=u[v]-h;f+=w*w}const d=f/a,m=Math.sqrt(d),x=s*m;if(h===0)return t.precision(0);const b=2*x/h*100;return t.precision(b)}}function hh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`cci_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevSum=s.currentSum,s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0);if(isNaN(o))return NaN;const l=[...s.prevWindow];let c=s.prevSum;for(l.unshift(o),c+=o;l.length>n;){const m=l.pop();c-=m}const u=s.prevCallCount+1;if(l.length<n&&(u>=n||t.idx>=n-1)){const m=y.from(e);for(;l.length<n;){const x=m.get(l.length);if(isNaN(x))break;l.push(x),c+=x}}if(s.currentWindow=l,s.currentSum=c,s.currentCallCount=u,l.length<n)return NaN;const p=c/n;let h=0;for(let m=0;m<n;m++)h+=Math.abs(l[m]-p);const f=h/n;if(f===0)return 0;const d=(o-p)/(.015*f);return t.precision(d)}}function ph(t){return(e,i=1,r)=>{typeof i=="string"&&(r=i,i=1);const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`change_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n+1;)l.pop();const c=s.prevCallCount+1;if(l.length<n+1&&(c>=n+1||t.idx>=n)){const p=y.from(e);for(;l.length<n+1;)l.push(p.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<=n)return NaN;const u=o-l[n];return t.precision(u)}}function fh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`cmo_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevGainsWindow=[...s.currentGainsWindow],s.prevLossesWindow=[...s.currentLossesWindow],s.prevGainsSum=s.currentGainsSum,s.prevLossesSum=s.currentLossesSum),s.lastIdx=t.idx);const o=y.from(e).get(0),l=y.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;const c=o-l,u=c>=0?c:0,p=c>=0?0:-c,h=[...s.prevGainsWindow],f=[...s.prevLossesWindow];let d=s.prevGainsSum,m=s.prevLossesSum;if(h.unshift(u),f.unshift(p),d+=u,m+=p,h.length<n)return s.currentGainsWindow=h,s.currentLossesWindow=f,s.currentGainsSum=d,s.currentLossesSum=m,NaN;if(h.length>n){const v=h.pop(),w=f.pop();d-=v,m-=w}s.currentGainsWindow=h,s.currentLossesWindow=f,s.currentGainsSum=d,s.currentLossesSum=m;const x=d+m;if(x===0)return t.precision(0);const b=100*(d-m)/x;return t.precision(b)}}function dh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);let s=0,o=!1;for(let u=0;u<n;u++){const p=a.get(u);if(isNaN(p)){o=!0;break}s+=p}if(o)return NaN;let l=0;for(let u=0;u<n;u++){const p=a.get(u);l+=p*(u+1)}if(s===0)return NaN;const c=-l/s;return t.precision(c)}}function mh(t){return(e,i,r,n)=>{const a=y.from(r).get(0),s=y.from(e),o=y.from(i);if(t.idx<a-1)return NaN;let l=0,c=0,u=0,p=0,h=0,f=0;for(let v=0;v<a;v++){const w=s.get(v),S=o.get(v);isNaN(w)||isNaN(S)||(l+=w,c+=S,u+=w*S,p+=w*w,h+=S*S,f++)}if(f<2)return NaN;const d=f*u-l*c,m=f*p-l*l,x=f*h-c*c;if(m<=0||x<=0)return t.precision(0);const b=d/Math.sqrt(m*x);return t.precision(b)}}function yh(t){return(e,i,r)=>{const n=y.from(e),a=y.from(i),s=n.get(0),o=a.get(0),l=n.get(1),c=a.get(1);if(isNaN(s)||isNaN(o)||isNaN(l)||isNaN(c))return!1;const u=s>o&&l<=c,p=s<o&&l>=c;return u||p}}function _h(t){return(e,i)=>{const r=y.from(e),n=y.from(i),a=r.get(0),s=n.get(0),o=r.get(1),l=n.get(1);return o<=l&&a>s}}function gh(t){return(e,i)=>{const r=y.from(e),n=y.from(i),a=r.get(0),s=n.get(0),o=r.get(1),l=n.get(1);return o>=l&&a<s}}function xh(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"cum";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativeSum=n.currentCumulativeSum),n.lastIdx=t.idx);const a=y.from(e).get(0);if(isNaN(a))return n.currentCumulativeSum=n.prevCumulativeSum,t.precision(n.prevCumulativeSum);const s=n.prevCumulativeSum+a;return n.currentCumulativeSum=s,t.precision(s)}}function bh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`dev_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevSum=s.currentSum,s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0)||0,l=[...s.prevWindow];let c=s.prevSum;for(l.unshift(o),c+=o;l.length>n;){const d=l.pop();c-=d}const u=s.prevCallCount+1;if(l.length<n&&(u>=n||t.idx>=n-1)){const d=y.from(e);for(;l.length<n;){const m=d.get(l.length);l.push(m),c+=m}}if(s.currentWindow=l,s.currentSum=c,s.currentCallCount=u,l.length<n)return NaN;const p=c/n;let h=0;for(let d=0;d<n;d++)h+=Math.abs(l[d]-p);const f=h/n;return t.precision(f)}}function vh(t){return(e,i,r)=>{const n=y.from(e).get(0),a=y.from(i).get(0);t.taState||(t.taState={});const s=r||`dmi_${n}_${a}`;t.taState[s]||(t.taState[s]={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});const o=t.taState[s];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);const 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]];const p=t.idx>0?t.get(t.data.high,1):NaN,h=t.idx>0?t.get(t.data.low,1):NaN,f=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(p))return[[NaN,NaN,NaN]];const d=Math.max(l-c,Math.abs(l-f),Math.abs(c-f)),m=l-p,x=h-c,b=m>x&&m>0?m:0,v=x>m&&x>0?x:0;let w=o.prevInitCount,S=o.prevTrInitSum,A=o.prevPlusInitSum,N=o.prevMinusInitSum,P=o.prevSmoothedTR,j=o.prevSmoothedPlus,I=o.prevSmoothedMinus;if(w++,w<=n)S+=d,A+=b,N+=v,w===n&&(P=S/n,j=A/n,I=N/n);else{const ne=1/n;P=ne*d+(1-ne)*P,j=ne*b+(1-ne)*j,I=ne*v+(1-ne)*I}if(o.currentInitCount=w,o.currentTrInitSum=S,o.currentPlusInitSum=A,o.currentMinusInitSum=N,o.currentSmoothedTR=P,o.currentSmoothedPlus=j,o.currentSmoothedMinus=I,w<n)return[[NaN,NaN,NaN]];const V=P===0?0:100*j/P,k=P===0?0:100*I/P,L=V+k,D=L===0?0:100*Math.abs(V-k)/L;let M=o.prevAdxInitCount,K=o.prevDxInitSum,J=o.prevADX,_e=NaN;if(M++,M<=a)K+=D,M===a&&(J=K/a,_e=J);else{const ne=1/a;J=ne*D+(1-ne)*J,_e=J}return o.currentAdxInitCount=M,o.currentDxInitSum=K,o.currentADX=J,[[t.precision(V),t.precision(k),t.precision(_e)]]}}function wh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`ema_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevEma=s.currentEma,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);const o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=s.prevInitCount,c=s.prevInitSum,u=s.prevEma;if(l<n){if(c+=o,l++,s.currentInitSum=c,s.currentInitCount=l,l===n){const f=c/n;return s.currentEma=f,t.precision(f)}return NaN}const p=2/(n+1),h=o*p+u*(1-p);return s.currentEma=h,t.precision(h)}}function Sh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);for(let s=0;s<n;s++){const o=a.get(s),l=a.get(s+1);if(isNaN(o)||isNaN(l)||o>=l)return!1}return!0}}function Eh(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.high);const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`highest_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const h=y.from(e);for(;l.length<n;)l.push(h.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;const u=l.filter(h=>!isNaN(h)&&h!==void 0);if(u.length===0)return NaN;const p=Math.max(...u);return t.precision(p)}}function Nh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n-1)return NaN;let s=-1/0,o=NaN;for(let l=0;l<n;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c>s)&&(s=c,o=-l)}return o}}function Ch(t){return(e,i,r)=>{const n=y.from(i).get(0),a=Math.floor(n/2),s=Math.floor(Math.sqrt(n)),o=t.pine.ta.wma,l=o(e,a,r?`${r}_wma1`:void 0),c=o(e,n,r?`${r}_wma2`:void 0);if(isNaN(l)||isNaN(c))return NaN;t.taState||(t.taState={});const u=r||`hma_raw_${n}`;t.taState[u]||(t.taState[u]={lastIdx:-1,prevValues:[],currentValues:[]});const p=t.taState[u];t.idx>p.lastIdx&&(p.lastIdx>=0&&(p.prevValues=[...p.currentValues]),p.lastIdx=t.idx);const h=2*l-c,f=[...p.prevValues];f.unshift(h),f.length>s+1&&f.pop(),p.currentValues=f;const d=r?`${r}_hma_final`:`hma_final_${n}`;t.taState[d]||(t.taState[d]={lastIdx:-1,prevWindow:[],currentWindow:[]});const m=t.taState[d];t.idx>m.lastIdx&&(m.lastIdx>=0&&(m.prevWindow=[...m.currentWindow]),m.lastIdx=t.idx);const x=[...m.prevWindow];if(x.unshift(h),x.length<s)return m.currentWindow=x,NaN;for(;x.length>s;)x.pop();m.currentWindow=x;let b=0,v=0;for(let S=0;S<s;S++){const A=s-S;b+=x[S]*A,v+=A}const w=b/v;return t.precision(w)}}function Ih(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.high,0),n=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(a))return NaN;const s=(r-n)*a;if(s===0)return t.precision(0);const o=(2*i-r-n)/s;return t.precision(o)}}function kh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0);let l=!0;typeof n=="string"?a=n:n!==void 0&&(l=y.from(n).get(0));let c;const u=t.get(t.data.high,0),p=t.get(t.data.low,0);if(l){const S=t.get(t.data.close,1);isNaN(S)?c=NaN:c=Math.max(u-p,Math.abs(u-S),Math.abs(p-S))}else c=u-p;const h=y.from(e).get(0);t.taState||(t.taState={});const f=a||`kc_${s}_${o}_${l}`;t.taState[f]||(t.taState[f]={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}});const d=t.taState[f];t.idx>d.lastIdx&&(d.lastIdx>=0&&(d.basisState={...d.currentBasisState},d.rangeState={...d.currentRangeState}),d.lastIdx=t.idx);const m=(S,A,N,P)=>{if(isNaN(N))return Object.assign(A,S),A.prevEma!==null?A.prevEma:NaN;let j=S.initCount,I=S.initSum,V=S.prevEma;if(j<P){if(I+=N,j++,A.initSum=I,A.initCount=j,A.prevEma=V,j===P){const D=I/P;return A.prevEma=D,D}return NaN}const k=2/(P+1),L=N*k+V*(1-k);return A.prevEma=L,A.initSum=I,A.initCount=j,L},x=m(d.basisState,d.currentBasisState,h,s),b=m(d.rangeState,d.currentRangeState,c,s);if(isNaN(x)||isNaN(b))return[[NaN,NaN,NaN]];const v=x+b*o,w=x-b*o;return[[t.precision(x),t.precision(v),t.precision(w)]]}}function Th(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0);let l=!0;typeof n=="string"?a=n:n!==void 0&&(l=y.from(n).get(0)),t.taState||(t.taState={});const c=a||`kcw_${s}_${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}});const u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.basisState={...u.currentBasisState},u.rangeState={...u.currentRangeState}),u.lastIdx=t.idx);const p=(w,S,A,N)=>{if(isNaN(A))return Object.assign(S,w),S.prevEma!==null?S.prevEma:NaN;let P=w.initCount,j=w.initSum,I=w.prevEma;if(P<N){if(j+=A,P++,S.initSum=j,S.initCount=P,S.prevEma=I,P===N){const L=j/N;return S.prevEma=L,L}return NaN}const V=2/(N+1),k=A*V+I*(1-V);return S.prevEma=k,S.initSum=j,S.initCount=P,k};let h;const f=t.get(t.data.high,0),d=t.get(t.data.low,0);if(l){const w=t.get(t.data.close,1);isNaN(w)?h=NaN:h=Math.max(f-d,Math.abs(f-w),Math.abs(d-w))}else h=f-d;const m=y.from(e).get(0),x=p(u.basisState,u.currentBasisState,m,s),b=p(u.rangeState,u.currentRangeState,h,s);if(isNaN(x)||isNaN(b))return NaN;if(x===0)return t.precision(0);const v=2*b*o/x;return t.precision(v)}}function Ah(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`linreg_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);const c=y.from(e).get(0),u=[...l.prevWindow];for(u.unshift(c);u.length>a;)u.pop();const p=l.prevCallCount+1;if(u.length<a&&(p>=a||t.idx>=a-1)){const S=y.from(e);for(;u.length<a;)u.push(S.get(u.length))}if(l.currentWindow=u,l.currentCallCount=p,u.length<a)return NaN;let h=0,f=0,d=0,m=0;const x=a;for(let S=0;S<a;S++){const A=a-1-S,N=u[S];h+=A,f+=N,d+=A*N,m+=A*A}const b=x*m-h*h;if(b===0)return NaN;const v=(x*d-h*f)/b,w=(f-v*h)/x+v*(a-1-s);return t.precision(w)}}function Ph(t){return(e,i,r)=>{typeof i=="string"&&r===void 0&&(r=i,i=e,e=t.data.low);const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`lowest_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const h=y.from(e);for(;l.length<n;)l.push(h.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;const u=l.filter(h=>!isNaN(h)&&h!==void 0);if(u.length===0)return NaN;const p=Math.min(...u);return t.precision(p)}}function Mh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n-1)return NaN;let s=1/0,o=NaN;for(let l=0;l<n;l++){const c=a.get(l);isNaN(c)||(isNaN(o)||c<s)&&(s=c,o=-l)}return o}}function Dh(t){return(e,i,r,n,a)=>{const s=y.from(i).get(0),o=y.from(r).get(0),l=y.from(n).get(0),c=a||`macd_${s}_${o}_${l}`,u=`${c}_fast`,p=`${c}_slow`,h=`${c}_signal`,f=t.pine.ta.ema(e,s,u),d=t.pine.ta.ema(e,o,p);let m=NaN;!isNaN(f)&&!isNaN(d)&&(m=f-d);let x=NaN;isNaN(m)||(x=t.pine.ta.ema(m,l,h));let b=NaN;return!isNaN(m)&&!isNaN(x)&&(b=m-x),[[t.precision(m),t.precision(x),t.precision(b)]]}}function Rh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`median_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const f=y.from(e);for(;l.length<n;)l.push(f.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;const u=l.slice().sort((f,d)=>f-d),p=Math.floor(n/2),h=n%2===0?(u[p-1]+u[p])/2:u[p];return t.precision(h)}}function Oh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`mfi_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevUpperWindow=[...s.currentUpperWindow],s.prevLowerWindow=[...s.currentLowerWindow],s.prevUpperSum=s.currentUpperSum,s.prevLowerSum=s.currentLowerSum),s.lastIdx=t.idx);const 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;const u=isNaN(l)?NaN:o-l,p=c*(u<=0?0:o),h=c*(u>=0?0:o),f=[...s.prevUpperWindow],d=[...s.prevLowerWindow];let m=s.prevUpperSum,x=s.prevLowerSum;if(f.unshift(p),d.unshift(h),m+=p,x+=h,f.length<n)return s.currentUpperWindow=f,s.currentLowerWindow=d,s.currentUpperSum=m,s.currentLowerSum=x,NaN;if(f.length>n){const v=f.pop(),w=d.pop();m-=v,x-=w}if(s.currentUpperWindow=f,s.currentLowerWindow=d,s.currentUpperSum=m,s.currentLowerSum=x,x===0)return t.precision(100);if(m===0)return t.precision(0);const b=100-100/(1+m/x);return t.precision(b)}}function $h(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n-1)return NaN;const s=new Map;for(let c=0;c<n;c++){const u=a.get(c);isNaN(u)||s.set(u,(s.get(u)||0)+1)}if(s.size===0)return NaN;let o=NaN,l=-1;for(const[c,u]of s.entries())u>l?(l=u,o=c):u===l&&c<o&&(o=c);return o}}function Vh(t){return(e,i,r)=>{const n=y.from(i).get(0);return t.pine.ta.change(e,n,r)}}function jh(t){return e=>{t.taState||(t.taState={});const i=e||"nvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedNVI:1,tentativeNVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedNVI=r.tentativeNVI),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.close,1),s=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(n)?0:n,c=isNaN(a)?0:a,u=isNaN(s)?0:s,p=isNaN(o)?0:o;let h=r.committedNVI;if(!(l===0||c===0)&&u<p){const f=(l-c)/c;h=h+f*h}return r.tentativeNVI=h,t.precision(h)}}function Lh(t){return()=>{t.taState||(t.taState={});const e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});const i=t.taState[e];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.committedOBV=i.tentativeOBV),i.lastIdx=t.idx);const r=t.get(t.data.close,0),n=t.get(t.data.volume,0),a=t.get(t.data.close,1);if(isNaN(a))return i.tentativeOBV=0,t.precision(0);let s=i.committedOBV;return r>a?s+=n:r<a&&(s-=n),i.tentativeOBV=s,t.precision(s)}}function Bh(t){return(e,i,r)=>e instanceof y?i?new y(e.data,e.offset+i):e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,i||0):(t.params[r].length===0?t.params[r].push(e):t.params[r][t.params[r].length-1]=e,new y(t.params[r],i||0)))}function Fh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e);if(t.idx<a-1)return NaN;const l=[];for(let d=0;d<a;d++){const m=o.get(d);if(isNaN(m))return NaN;l.push(m)}l.sort((d,m)=>d-m);let c=s/100*a-.5;c<0&&(c=0),c>a-1&&(c=a-1);const u=Math.floor(c),p=Math.ceil(c);if(u===p)return t.precision(l[u]);const h=c-u,f=l[u]+h*(l[p]-l[u]);return t.precision(f)}}function Wh(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e);if(t.idx<a-1)return NaN;const l=[];for(let u=0;u<a;u++){const p=o.get(u);isNaN(p)||l.push(p)}if(l.length===0)return NaN;l.sort((u,p)=>u-p);let c=Math.ceil(s/100*l.length)-1;return c<0&&(c=0),c>=l.length&&(c=l.length-1),t.precision(l[c])}}function Uh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);if(t.idx<n)return NaN;const s=a.get(0);if(isNaN(s))return NaN;let o=0,l=0;for(let c=1;c<=n;c++){const u=a.get(c);isNaN(u)||(l++,u<=s&&o++)}return l===0?NaN:t.precision(o/l*100)}}function qh(t,e,i){const r=new Array(t.length).fill(NaN);for(let n=e+i;n<t.length;n++){const a=t[n-i];let s=!0;for(let o=1;o<=e;o++)if(t[n-i-o]>=a){s=!1;break}if(s){for(let o=1;o<=i;o++)if(t[n-i+o]>=a){s=!1;break}}s&&(r[n]=a)}return r}function zh(t){return(e,i,r,n)=>{typeof r=="string"&&(r=i,i=e,e=t.data.high);const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e).toArray(),l=qh(o,a,s),c=t.idx;return t.precision(l[c])}}function Kh(t,e,i){const r=new Array(t.length).fill(NaN);for(let n=e+i;n<t.length;n++){const a=t[n-i];let s=!0;for(let o=1;o<=e;o++)if(t[n-i-o]<=a){s=!1;break}if(s){for(let o=1;o<=i;o++)if(t[n-i+o]<=a){s=!1;break}}s&&(r[n]=a)}return r}function Hh(t){return(e,i,r,n)=>{typeof r=="string"&&(r=i,i=e,e=t.data.low);const a=y.from(i).get(0),s=y.from(r).get(0),o=y.from(e).toArray(),l=Kh(o,a,s),c=t.idx;return t.precision(l[c])}}function Gh(t){return e=>{t.taState||(t.taState={});const i=e||"pvi";t.taState[i]||(t.taState[i]={lastIdx:-1,committedPVI:1,tentativePVI:1});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedPVI=r.tentativePVI),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.close,1),s=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(n)?0:n,c=isNaN(a)?0:a,u=isNaN(s)?0:s,p=isNaN(o)?0:o;let h=r.committedPVI;if(!(l===0||c===0)&&u>p){const f=(l-c)/c;h=h+f*h}return r.tentativePVI=h,t.precision(h)}}function Yh(t){return e=>{t.taState||(t.taState={});const i=e||"pvt";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.close,1),s=t.get(t.data.volume,0);let o=r.prevCumulativeSum;if(!isNaN(n)&&!isNaN(a)&&!isNaN(s)&&a!==0){const l=(n-a)/a*s;o+=l}return r.currentCumulativeSum=o,t.precision(o)}}function Xh(t){return(e,i,r)=>{const n=t.pine.ta.highest(e,i,(r||"range")+"_h"),a=t.pine.ta.lowest(e,i,(r||"range")+"_l");return isNaN(n)||isNaN(a)?NaN:t.precision(n-a)}}function Qh(t){return(e,i,r)=>{const n=y.from(i).get(0),a=y.from(e);for(let s=0;s<n;s++){const o=a.get(s),l=a.get(s+1);if(isNaN(o)||isNaN(l)||o<=l)return!1}return!0}}function Zh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`rma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevRma=s.currentRma,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);const o=y.from(e).get(0)||0;let l=s.prevInitCount,c=s.prevInitSum,u=s.prevRma;if(l<n){if(c+=o,l++,s.currentInitSum=c,s.currentInitCount=l,l===n){const f=c/n;return s.currentRma=f,t.precision(f)}return NaN}const p=1/n,h=o*p+u*(1-p);return s.currentRma=h,t.precision(h)}}function Jh(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`roc_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n+1;)l.pop();const c=s.prevCallCount+1;if(l.length<n+1&&(c>=n+1||t.idx>=n)){const h=y.from(e);for(;l.length<n+1;)l.push(h.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<=n)return NaN;const u=l[n],p=(o-u)/u*100;return t.precision(p)}}function ep(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`rsi_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevPrevValue=s.currentPrevValue,s.prevAvgGain=s.currentAvgGain,s.prevAvgLoss=s.currentAvgLoss,s.prevInitGains=[...s.currentInitGains],s.prevInitLosses=[...s.currentInitLosses]),s.lastIdx=t.idx);const o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;const l=s.prevPrevValue;if(l===null||isNaN(l))return s.currentPrevValue=o,s.currentInitGains=[...s.prevInitGains],s.currentInitLosses=[...s.prevInitLosses],s.currentAvgGain=s.prevAvgGain,s.currentAvgLoss=s.prevAvgLoss,NaN;let c=s.prevAvgGain,u=s.prevAvgLoss;const p=[...s.prevInitGains],h=[...s.prevInitLosses],f=o-l,d=f>0?f:0,m=f<0?-f:0;if(p.length<n){if(p.push(d),h.push(m),s.currentInitGains=p,s.currentInitLosses=h,s.currentPrevValue=o,p.length===n){c=p.reduce((v,w)=>v+w,0)/n,u=h.reduce((v,w)=>v+w,0)/n,s.currentAvgGain=c,s.currentAvgLoss=u;const b=u===0?100:100-100/(1+c/u);return t.precision(b)}return NaN}c=(c*(n-1)+d)/n,u=(u*(n-1)+m)/n,s.currentAvgGain=c,s.currentAvgLoss=u,s.currentPrevValue=o;const x=u===0?100:100-100/(1+c/u);return t.precision(x)}}function tp(t){return(e,i,r,n)=>{const a=y.from(e).get(0),s=y.from(i).get(0),o=y.from(r).get(0);t.taState||(t.taState={});const l=n||`sar_${a}_${s}_${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});const 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,p=c.prevMaxMin,h=c.prevAcceleration,f=c.prevIsBelow,d=c.prevBarIndex;const m=t.get(t.data.high,0),x=t.get(t.data.low,0),b=t.get(t.data.close,0),v=t.get(t.data.close,1),w=t.get(t.data.high,1),S=t.get(t.data.low,1),A=t.get(t.data.high,2),N=t.get(t.data.low,2);if(isNaN(m)||isNaN(x)||isNaN(b))return c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=f,c.currentBarIndex=d,NaN;let P=!1;return d===1&&(b>v?(f=!0,p=m,u=S):(f=!1,p=x,u=w),P=!0,h=a),d>=1&&(u=u+h*(p-u),f?u>x&&(P=!0,f=!1,u=Math.max(m,p),p=x,h=a):u<m&&(P=!0,f=!0,u=Math.min(x,p),p=m,h=a),P||(f?m>p&&(p=m,h=Math.min(h+s,o)):x<p&&(p=x,h=Math.min(h+s,o))),f?(u=Math.min(u,S),d>1&&(u=Math.min(u,N))):(u=Math.max(u,w),d>1&&(u=Math.max(u,A)))),d++,c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=f,c.currentBarIndex=d,d<=1?NaN:t.precision(u)}}function ip(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`sma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevSum=s.currentSum,s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;let u=!1;if(l.length<n&&(c>=n||t.idx>=n-1)){const m=y.from(e);for(;l.length<n;)l.push(m.get(l.length));u=!0}let p;const h=o==null||Number.isNaN(o);let f=!Number.isNaN(s.prevSum)&&!h&&!u;if(f){let m=s.prevSum+o;if(s.prevWindow.length>=n){const x=s.prevWindow[s.prevWindow.length-1];x==null||Number.isNaN(x)?f=!1:m-=x}f&&(p=m)}if(!f){p=0;let m=!1;for(const x of l){if(x==null||Number.isNaN(x)){m=!0;break}p+=x}m&&(p=NaN)}if(s.currentWindow=l,s.currentSum=p,s.currentCallCount=c,l.length<n)return NaN;const d=p/n;return t.precision(d)}}function rp(t){return(e,i,r=!0,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`stdev_${a}_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});const 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);const c=y.from(e).get(0);if(c==null||isNaN(c))return NaN;const u=[...l.prevWindow];let p=l.prevSum;for(u.unshift(c),p+=c;u.length>a;){const b=u.pop();p-=b}const h=l.prevCallCount+1;if(u.length<a&&(h>=a||t.idx>=a-1)){const b=y.from(e);for(;u.length<a;){const v=b.get(u.length);if(v==null||isNaN(v))break;u.push(v),p+=v}}if(l.currentWindow=u,l.currentSum=p,l.currentCallCount=h,u.length<a)return NaN;const f=p/a;let d=0;for(let b=0;b<a;b++)d+=Math.pow(u[b]-f,2);const m=s?a:a-1,x=Math.sqrt(d/m);return t.precision(x)}}function np(t){return(e,i,r,n,a)=>{const s=y.from(n).get(0);t.taState||(t.taState={});const o=a||`stoch_${s}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow]),l.lastIdx=t.idx);const c=y.from(e).get(0),u=y.from(i).get(0),p=y.from(r).get(0);if(isNaN(c)||isNaN(u)||isNaN(p))return l.currentHighWindow=[...l.prevHighWindow],l.currentLowWindow=[...l.prevLowWindow],NaN;const h=[...l.prevHighWindow],f=[...l.prevLowWindow];if(h.unshift(u),f.unshift(p),h.length>s&&(h.pop(),f.pop()),l.currentHighWindow=h,l.currentLowWindow=f,h.length<s)return NaN;let d=h[0],m=f[0];for(let v=1;v<s;v++)h[v]>d&&(d=h[v]),f[v]<m&&(m=f[v]);const x=d-m;if(x===0)return NaN;const b=100*(c-m)/x;return t.precision(b)}}function sp(t){return(e,i,r)=>{const n=y.from(e).get(0),a=y.from(i).get(0);t.taState||(t.taState={});const s=r||`supertrend_${n}_${a}`;t.taState[s]||(t.taState[s]={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});const o=t.taState[s];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);const 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]];const p=(l+c)/2,h=t.idx>0?t.get(t.data.close,1):NaN;let f;isNaN(h)?f=l-c:f=Math.max(l-c,Math.abs(l-h),Math.abs(c-h));let d=o.prevAtrCount,m=o.prevTrSum,x=o.prevAtrValue;d++,d<=a?(m+=f,d===a&&(x=m/a)):x=(x*(a-1)+f)/a;const b=x;if(o.currentAtrCount=d,o.currentTrSum=m,o.currentAtrValue=x,isNaN(b))return[[NaN,NaN]];let v=p+n*b,w=p-n*b;const S=isNaN(o.prevLowerBand)?0:o.prevLowerBand,A=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||w>S||h<S||(w=S),isNaN(o.prevUpperBand)||v<A||h>A||(v=A);let N,P;const j=o.prevSuperTrend;return d===a?N=1:j===o.prevUpperBand?N=u>v?-1:1:N=u<w?1:-1,P=N===-1?w:v,o.currentLowerBand=w,o.currentUpperBand=v,o.currentSuperTrend=P,o.currentDirection=N,[[t.precision(P),N]]}}function ap(t){return(e,i)=>{const r=[1,2,2,1],n=6;t.taState||(t.taState={});const a=i||"swma";t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],currentWindow:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow]),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>4;)l.pop();if(l.length<4&&t.idx>=3){const u=y.from(e);for(;l.length<4;)l.push(u.get(l.length))}if(s.currentWindow=l,l.length<4)return NaN;let c=0;for(let u=0;u<4;u++)c+=r[u]*l[3-u];return c/=n,t.precision(c)}}function op(t){return(e,i)=>{let r=!0;typeof e=="string"||e!==void 0&&(r=y.from(e).get(0));const n=t.get(t.data.high,0),a=t.get(t.data.low,0),s=t.get(t.data.close,1);if(isNaN(s))return r?t.precision(n-a):NaN;const o=Math.max(n-a,Math.abs(n-s),Math.abs(a-s));return t.precision(o)}}function lp(t){return(e,i,r,n)=>{const a=y.from(i).get(0),s=y.from(r).get(0);t.taState||(t.taState={});const o=n||`tsi_${a}_${s}`;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});const 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);const c=y.from(e).get(0);if(isNaN(c))return NaN;const u=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(u))return NaN;const p=Math.abs(u),h=2/(s+1),f=2/(a+1),d=2/(s+1),m=2/(a+1);let x=l.prevEma1PcCount,b=l.prevEma1PcSum,v=l.prevEma1PcValue;x++,x<=s?(b+=u,x===s&&(v=b/s)):v=u*h+v*(1-h);let w=l.prevEma1AbsCount,S=l.prevEma1AbsSum,A=l.prevEma1AbsValue;if(w++,w<=s?(S+=p,w===s&&(A=S/s)):A=p*d+A*(1-d),isNaN(v)||isNaN(A))return l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=w,l.currentEma1AbsSum=S,l.currentEma1AbsValue=A,NaN;let N=l.prevEma2PcCount,P=l.prevEma2PcSum,j=l.prevEma2PcValue;N++,N<=a?(P+=v,N===a&&(j=P/a)):j=v*f+j*(1-f);let I=l.prevEma2AbsCount,V=l.prevEma2AbsSum,k=l.prevEma2AbsValue;if(I++,I<=a?(V+=A,I===a&&(k=V/a)):k=A*m+k*(1-m),l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=w,l.currentEma1AbsSum=S,l.currentEma1AbsValue=A,l.currentEma2PcCount=N,l.currentEma2PcSum=P,l.currentEma2PcValue=j,l.currentEma2AbsCount=I,l.currentEma2AbsSum=V,l.currentEma2AbsValue=k,isNaN(j)||isNaN(k))return NaN;if(k===0)return t.precision(0);const L=j/k;return t.precision(L)}}function cp(t){return(e,i,r,n)=>{t.taState||(t.taState={});const a=n||"valuewhen";t.taState[a]||(t.taState[a]={lastIdx:-1,prevValues:[],currentValues:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevValues=[...s.currentValues]),s.lastIdx=t.idx);const o=y.from(e).get(0),l=y.from(i).get(0),c=y.from(r).get(0),u=[...s.prevValues];if(o&&u.push(l),s.currentValues=u,isNaN(c)||c<0)return NaN;const p=u.length-1-c;if(p<0)return NaN;const h=u[p];return typeof h=="number"?t.precision(h):h}}function up(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`variance_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const d=y.from(e);for(;l.length<n;)l.push(d.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;let u=0,p=0;for(let d=0;d<n;d++)u+=l[d],p+=l[d]*l[d];const h=u/n,f=p/n-h*h;return t.precision(f)}}function hp(t){return(e,i)=>{t.taState||(t.taState={});const r=i||"vwap";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentLastSessionDate:null});const n=t.taState[r];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.prevCumulativePV=n.currentCumulativePV,n.prevCumulativeVolume=n.currentCumulativeVolume,n.prevLastSessionDate=n.currentLastSessionDate),n.lastIdx=t.idx);const a=y.from(e).get(0),s=y.from(t.data.volume).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.timezone||"UTC",c=Vt(o,l),u=`${c.year}-${String(c.month).padStart(2,"0")}-${String(c.day).padStart(2,"0")}`;let p=n.prevCumulativePV,h=n.prevCumulativeVolume,f=n.prevLastSessionDate;if(f!==u&&(p=0,h=0,f=u),p+=a*s,h+=s,n.currentCumulativePV=p,n.currentCumulativeVolume=h,n.currentLastSessionDate=f,h===0)return NaN;const d=p/h;return t.precision(d)}}function pp(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`vwma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevVolumeWindow:[],currentWindow:[],currentVolumeWindow:[]});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevVolumeWindow=[...s.currentVolumeWindow]),s.lastIdx=t.idx);const o=y.from(e).get(0),l=t.get(t.data.volume,0),c=[...s.prevWindow],u=[...s.prevVolumeWindow];for(c.unshift(o),u.unshift(l);c.length>n;)c.pop(),u.pop();if(c.length<n&&t.idx>=n-1){const d=y.from(e),m=y.from(t.data.volume);for(;c.length<n;)c.push(d.get(c.length)),u.push(m.get(u.length))}if(s.currentWindow=c,s.currentVolumeWindow=u,c.length<n)return NaN;let p=0,h=0;for(let d=0;d<n;d++)p+=c[d]*u[d],h+=u[d];const f=p/h;return t.precision(f)}}function fp(t){return e=>{t.taState||(t.taState={});const i=e||"wad";t.taState[i]||(t.taState[i]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});const r=t.taState[i];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);const n=t.get(t.data.close,0),a=t.get(t.data.high,0),s=t.get(t.data.low,0),o=t.get(t.data.close,1);if(isNaN(n)||isNaN(a)||isNaN(s))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=0;if(!isNaN(o)){const u=Math.max(a,o),p=Math.min(s,o),h=n-o;h>0?l=n-p:h<0&&(l=n-u)}const c=r.prevCumulativeSum+l;return r.currentCumulativeSum=c,t.precision(c)}}function dp(t){return(e,i,r)=>{const n=y.from(i).get(0);t.taState||(t.taState={});const a=r||`wma_${n}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});const s=t.taState[a];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevWindow=[...s.currentWindow],s.prevCallCount=s.currentCallCount),s.lastIdx=t.idx);const o=y.from(e).get(0),l=[...s.prevWindow];for(l.unshift(o);l.length>n;)l.pop();const c=s.prevCallCount+1;if(l.length<n&&(c>=n||t.idx>=n-1)){const f=y.from(e);for(;l.length<n;)l.push(f.get(l.length))}if(s.currentWindow=l,s.currentCallCount=c,l.length<n)return NaN;let u=0,p=0;for(let f=0;f<n;f++){const d=n-f;u+=l[f]*d,p+=d}const h=u/p;return t.precision(h)}}function mp(t){return(e,i)=>{const r=y.from(e).get(0);t.taState||(t.taState={});const n=i||`wpr_${r}`;t.taState[n]||(t.taState[n]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});const a=t.taState[n];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevHighWindow=[...a.currentHighWindow],a.prevLowWindow=[...a.currentLowWindow]),a.lastIdx=t.idx);const s=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(s)||isNaN(o)||isNaN(l))return a.currentHighWindow=[...a.prevHighWindow],a.currentLowWindow=[...a.prevLowWindow],NaN;const c=[...a.prevHighWindow],u=[...a.prevLowWindow];if(c.unshift(s),u.unshift(o),c.length>r&&(c.pop(),u.pop()),a.currentHighWindow=c,a.currentLowWindow=u,c.length<r)return NaN;let p=c[0],h=u[0];for(let m=1;m<r;m++)c[m]>p&&(p=c[m]),u[m]<h&&(h=u[m]);const f=p-h;if(f===0)return t.precision(0);const d=(p-l)/f*-100;return t.precision(d)}}function yp(t){return e=>{const i=t.get(t.data.close,0),r=t.get(t.data.open,0),n=t.get(t.data.high,0),a=t.get(t.data.low,0),s=t.get(t.data.volume,0);if(isNaN(i)||isNaN(r)||isNaN(n)||isNaN(a)||isNaN(s))return NaN;const o=n-a;if(o===0)return t.precision(0);const l=(i-r)/o*s;return t.precision(l)}}var _p=Object.defineProperty,gp=(t,e,i)=>e in t?_p(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,R=(t,e,i)=>gp(t,typeof e!="symbol"?e+"":e,i);const xp={accdist:sh,alma:ah,atr:oh,barssince:lh,bb:ch,bbw:uh,cci:hh,change:ph,cmo:fh,cog:dh,correlation:mh,cross:yh,crossover:_h,crossunder:gh,cum:xh,dev:bh,dmi:vh,ema:wh,falling:Sh,highest:Eh,highestbars:Nh,hma:Ch,iii:Ih,kc:kh,kcw:Th,linreg:Ah,lowest:Ph,lowestbars:Mh,macd:Dh,median:Rh,mfi:Oh,mode:$h,mom:Vh,nvi:jh,obv:Lh,param:Bh,percentile_linear_interpolation:Fh,percentile_nearest_rank:Wh,percentrank:Uh,pivothigh:zh,pivotlow:Hh,pvi:Gh,pvt:Yh,range:Xh,rising:Qh,rma:Zh,roc:Jh,rsi:ep,sar:tp,sma:ip,stdev:rp,stoch:np,supertrend:sp,swma:ap,tr:op,tsi:lp,valuewhen:cp,variance:up,vwap:hp,vwma:pp,wad:fp,wma:dp,wpr:mp,wvad:yp};class bp{constructor(e){this.context=e,R(this,"accdist"),R(this,"alma"),R(this,"atr"),R(this,"barssince"),R(this,"bb"),R(this,"bbw"),R(this,"cci"),R(this,"change"),R(this,"cmo"),R(this,"cog"),R(this,"correlation"),R(this,"cross"),R(this,"crossover"),R(this,"crossunder"),R(this,"cum"),R(this,"dev"),R(this,"dmi"),R(this,"ema"),R(this,"falling"),R(this,"highest"),R(this,"highestbars"),R(this,"hma"),R(this,"iii"),R(this,"kc"),R(this,"kcw"),R(this,"linreg"),R(this,"lowest"),R(this,"lowestbars"),R(this,"macd"),R(this,"median"),R(this,"mfi"),R(this,"mode"),R(this,"mom"),R(this,"nvi"),R(this,"obv"),R(this,"param"),R(this,"percentile_linear_interpolation"),R(this,"percentile_nearest_rank"),R(this,"percentrank"),R(this,"pivothigh"),R(this,"pivotlow"),R(this,"pvi"),R(this,"pvt"),R(this,"range"),R(this,"rising"),R(this,"rma"),R(this,"roc"),R(this,"rsi"),R(this,"sar"),R(this,"sma"),R(this,"stdev"),R(this,"stoch"),R(this,"supertrend"),R(this,"swma"),R(this,"tr"),R(this,"tsi"),R(this,"valuewhen"),R(this,"variance"),R(this,"vwap"),R(this,"vwma"),R(this,"wad"),R(this,"wma"),R(this,"wpr"),R(this,"wvad"),Object.entries(xp).forEach(([i,r])=>{this[i]=r(e)})}}function vp(t){if(t.length===0)return{};if(typeof t[0]=="object"&&t[0]!==null)return t[0];const e={};typeof t[0]=="string"&&(e.title=t[0]);let i=null;for(let r=1;r<t.length;r++){const n=t[r];typeof n=="string"?e.shorttitle===void 0&&(e.shorttitle=n):typeof n=="object"&&n!==null&&(i=n)}return i&&Object.assign(e,i),e}function ui(t,e,i){if(!i||i<=0||!Number.isFinite(t)||t===e)return t;const r=t/i,n=1e-9;return t>e?Math.ceil(r-n)*i:Math.floor(r+n)*i}function qi(t,e,i,r){return Math.abs(t)*e*r*i/100}function wp(t,e){const i=t.strategy,r=t.pine?.syminfo?.pointvalue??1;let n=0;for(const a of tr(i)){const s=a.dir===1?e-a.entry_price:a.entry_price-e;n+=s*a.qty*r}return i.initial_capital+i.netprofit+n}function Sp(t,e){const i=t.strategy,r=t.pine?.syminfo?.pointvalue??1;let n=0;for(const a of i.opentrades){const s=Math.sign(a.size)===1?i.config.margin_long??100:i.config.margin_short??100;n+=qi(a.size,e,s,r)}return n}function Wr(t,e,i,r){const n=t.strategy;let a=n.config.default_qty_type||"fixed",s=n.config.default_qty_value||1;typeof a=="function"&&(a=a()),typeof s=="function"&&(s=s());const o=1e6,l=u=>Math.floor(u*o)/o;if(e!=null)return l(Math.abs(e));let c;switch(a){case"fixed":c=s;break;case"cash":c=s/r;break;case"percent_of_equity":{c=n.equity*s/100/r;break}default:c=s}return l(c)}function Ep(t){if(!t.strategy)return;const e=t.strategy,{pending_orders:i}=e,r=y.from(t.data.open).get(0),n=y.from(t.data.high).get(0),a=y.from(t.data.low).get(0),s=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.pointvalue??1;for(const c of e.opentrades){const u=Math.abs(c.size),p=c.size>0,h=c.commission??0,f=p?(c.entry_price-a)*u*l:(n-c.entry_price)*u*l,d=p?(n-c.entry_price)*u*l:(c.entry_price-a)*u*l,m=Math.max(0,f)+h,x=Math.max(0,d-h);m>(c.max_drawdown??0)&&(c.max_drawdown=m),x>(c.max_runup??0)&&(c.max_runup=x)}zi(t,r);for(const c of i){if(c.status!=="pending"||(c.category??"entry")==="exit"||c.bar>=t.idx)continue;let u=!1,p=r;switch(c.type){case"market":u=!0,p=r;break;case"limit":if(c.limit!==void 0){const h=Ot(c.direction);(h===1&&a<=c.limit||h===-1&&n>=c.limit)&&(u=!0,p=c.limit)}break;case"stop":if(c.stop!==void 0){const h=Ot(c.direction);(h===1&&n>=c.stop||h===-1&&a<=c.stop)&&(u=!0,p=c.stop)}break}if(u){if(Cp(e,c)){c.status="cancelled";continue}const h=Ot(c.direction);p=Ir(t,h,p);const f=h===1?e.config.margin_long??100:e.config.margin_short??100;{const d=e.position_size,m=Math.sign(d),x=m!==0&&m!==h,b=x?Math.max(0,c.qty-Math.abs(d)):c.qty;if(b>0){const v=t.pine?.syminfo?.pointvalue??1;let w=0;m===h&&(w=Sp(t,r));const S=e.equity-w;if(qi(b,p,f,v)>S){const A=Math.min(Math.abs(d),c.qty);x&&A>0?($t(t,A,p,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=p,c.fill_bar=t.idx,c.fill_time=o):c.status="cancelled";continue}}}kp(t,c,p,o),c.status="filled",c.fill_price=p,c.fill_bar=t.idx,c.fill_time=o}}e.pending_orders=i.filter(c=>c.status==="pending"),zi(t,s),$p(t)}function Ot(t){return typeof t=="number"?t:t==="long"?1:t==="short"?-1:0}function Ps(t,e,i,r){const n=e.config.commission_type??"percent",a=e.config.commission_value??0;if(!a||a===0)return 0;const s=t.pine?.syminfo?.pointvalue??1;switch(n){case"percent":return Math.abs(i)*r*s*(a/100);case"cash_per_contract":return Math.abs(i)*a;case"cash_per_order":return a;default:return 0}}function Ir(t,e,i){const r=t.strategy.config.slippage??0;if(!r||r===0)return i;const n=t.pine?.syminfo?.mintick??.01,a=r*n;return e===1?i+a:i-a}function Ms(t){const 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 Np(t,e){const i=t.config.pyramiding??1;let r=0;for(const n of t.opentrades)Math.sign(n.size)===e&&r++;return r>=i}function Cp(t,e){if(t.risk_halted)return!0;const i=t.risk_rules,r=e.direction;if(i.allow_entry_in&&(i.allow_entry_in==="long"&&r===-1||i.allow_entry_in==="short"&&r===1))return!0;if(i.max_position_size!==void 0){const n=t.position_size+r*e.qty;if(Math.abs(n)>i.max_position_size)return!0}return!1}function Ip(t){if(t.risk_halted)return;const e=t.risk_rules;if(e.max_drawdown){const i=e.max_drawdown.type==="percent_of_equity"?e.max_drawdown.value/100*t.equity_peak:e.max_drawdown.value;if(t.max_drawdown>=i){t.risk_halted=!0;return}}if(e.max_intraday_loss){const i=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>=i){t.risk_halted=!0;return}}if(e.max_cons_loss_days){let i=0;for(let r=t.closedtrades.length-1;r>=0&&(t.closedtrades[r].profit??0)<0;r--)i++;i>=e.max_cons_loss_days.count&&(t.risk_halted=!0)}}function Ii(t,e,i,r,n,a,s,o){const l=t.strategy,c=l.opentrades.length+l.closedtrades.length,u=l.config.commission_type??"percent",p=o&&u==="cash_per_order",h=Ps(t,l,r,n),f=p?h/2:h,d={id:`trade_${c}`,entry_id:e,entry_comment:s??e,entry_price:n,_bracket_entry:n,entry_bar_index:t.idx,entry_time:a,size:i*r,commission:f,max_drawdown:0,max_runup:0,status:"open"};l.opentrades.push(d),(l._ledger_entries??(l._ledger_entries=[])).push({entry_id:e,entry_price:n,entry_time:a,entry_bar_index:t.idx,entry_comment:d.entry_comment,qty:r,commission:f}),f>0&&(l.netprofit-=f,l.grossloss+=f);const m=y.from(t.data.high).get(0),x=y.from(t.data.low).get(0),b=t.pine?.syminfo?.mintick??.01;let v=i===1?x:m,w=i===1?m:x;for(const I of l.pending_orders){if((I.category??"entry")!=="exit"||I.from_entry&&I.from_entry!==e)continue;let V;I.stop!==void 0?V=I.stop:I.loss!==void 0&&(V=i===1?n-I.loss*b:n+I.loss*b);let k;I.limit!==void 0?k=I.limit:I.profit!==void 0&&(k=i===1?n+I.profit*b:n-I.profit*b),i===1?(V!==void 0&&V>v&&(v=V),k!==void 0&&k<w&&(w=k)):(V!==void 0&&V<v&&(v=V),k!==void 0&&k>w&&(w=k))}const S=t.pine?.syminfo?.pointvalue??1,A=i===1?(n-v)*r*S:(v-n)*r*S,N=i===1?(w-n)*r*S:(n-w)*r*S;d.max_drawdown=Math.max(0,A)+f,d.max_runup=Math.max(0,N-f);const P=l.position_size,j=P+d.size;if(P===0)l.position_size=j,l.position_avg_price=n,l.position_entry_name=e;else if(Math.sign(P)===Math.sign(j)){const I=Math.abs(P)*l.position_avg_price+r*n,V=Math.abs(j);l.position_avg_price=I/V,l.position_size=j}Ms(l)}function kp(t,e,i,r){const n=t.strategy,a=Ot(e.direction),s=n.position_size,o=Math.sign(s);if(o===1&&a===-1||o===-1&&a===1){const l=Math.min(Math.abs(s),e.qty),c=e.qty-l,u=c>0;if($t(t,l,i,r,{exitId:e.id,exitComment:e.comment,isImplicitReversal:u}),c>0){const p=e._base_qty;p!==void 0&&c>p+1e-9?(Ii(t,e.id,a,p,i,r,e.comment,!0),Ii(t,e.id,a,c-p,i,r,e.comment,!0)):Ii(t,e.id,a,c,i,r,e.comment,!0)}}else Ii(t,e.id,a,e.qty,i,r,e.comment)}function Tp(t,e,i){const r=[];let n=i;const a=t._ledger_entries??[];for(const s of a){if(n<=1e-9)break;if(s.entry_id!==e.entry_id||s.qty<=1e-9)continue;const o=Math.min(s.qty,n),l=s.qty>0?s.commission*(o/s.qty):0;r.push({qty:o,entry_price:s.entry_price,entry_time:s.entry_time,entry_bar_index:s.entry_bar_index,entry_comment:s.entry_comment,commission:l}),s.qty-=o,s.commission-=l,n-=o}if(t._ledger_entries=a.filter(s=>s.qty>1e-9),n>1e-9){const s=Math.abs(e.size);r.push({qty:n,entry_price:e.entry_price,entry_time:e.entry_time,entry_bar_index:e.entry_bar_index,entry_comment:e.entry_comment,commission:s>0?(e.commission??0)*(n/s):0})}return r}function $t(t,e,i,r,n){const a=t.strategy,s=t.pine?.syminfo?.pointvalue??1;let o=e;const l=[...a.opentrades];a.opentrades=[];for(const h of l){if(o<=0){a.opentrades.push(h);continue}const f=Math.abs(h.size),d=Math.min(f,o),m=Math.sign(h.size),x=b=>{const v=a.config.commission_type??"percent",w=n?.isImplicitReversal&&v==="cash_per_order",S=Ps(t,a,b,i),A=w?S/2:S,N=Tp(a,h,b);for(const P of N){const j=A*(P.qty/b),I=(m===1?i-P.entry_price:P.entry_price-i)*P.qty*s,V={id:`trade_${a.opentrades.length+a.closedtrades.length+l.length}`,entry_id:h.entry_id,entry_comment:P.entry_comment,entry_price:P.entry_price,_bracket_entry:h._bracket_entry,entry_bar_index:P.entry_bar_index,entry_time:P.entry_time,size:m*P.qty,commission:P.commission+j,max_drawdown:h.max_drawdown,max_runup:h.max_runup,status:"closed",exit_price:i,exit_bar_index:t.idx,exit_time:r,exit_id:n?.exitId??h.exit_id,exit_comment:n?.exitComment??h.exit_comment,profit:I-P.commission-j};n?.triggerKind==="loss"&&(V.max_runup=0),n?.triggerKind==="profit"&&(V.max_drawdown=P.commission),a.netprofit+=I-j,a.grossloss-=P.commission,V.profit>0?(a.grossprofit+=V.profit,a.wintrades++,a.wintrades_total_profit+=V.profit):V.profit<0?(a.grossloss+=Math.abs(V.profit),a.losstrades++,a.losstrades_total_loss+=Math.abs(V.profit)):a.eventrades++,a.closedtrades.push(V)}};if(d>=f-1e-9)h.status="closed",h.exit_price=i,h.exit_bar_index=t.idx,h.exit_time=r,x(f),o-=d;else{x(d);const b=(h.commission??0)*(d/f);h.size=m*(f-d),h.commission=(h.commission??0)-b,a.opentrades.push(h),o=0}}Ip(a);const c=a.position_size,u=Math.sign(c)*e;let p=c-u;if(Math.abs(p)<1e-9&&(p=0),a.position_size=p,Ms(a),p===0)a.position_avg_price=NaN,a.position_entry_name="";else if(a.opentrades.length>0){let h=0,f=0;for(const d of tr(a))h+=d.qty*d.entry_price,f+=d.qty;a.position_avg_price=h/f,a.position_entry_name=a.opentrades[0].entry_id}}function tr(t){const e=t._ledger_entries??[],i=Math.sign(t.position_size)||1;return e.length>0?e.map(r=>({qty:r.qty,entry_price:r.entry_price,commission:r.commission,dir:i})):t.opentrades.map(r=>({qty:Math.abs(r.size),entry_price:r.entry_price,commission:r.commission??0,dir:Math.sign(r.size)}))}function zi(t,e){const i=t.strategy,r=t.pine?.syminfo?.pointvalue??1;let n=0;for(const a of tr(i)){const s=a.dir===1?e-a.entry_price:a.entry_price-e;n+=s*a.qty*r}i.openprofit=n,i.equity=i.initial_capital+i.netprofit+n}function Ap(t,e,i){const r=t.strategy,n=t.pine?.syminfo?.pointvalue??1,a=r.initial_capital+r.netprofit;let s=0;for(const d of tr(r))s+=d.commission;const o=a+s;o>r.equity_peak&&(r.equity_peak=o),a<r.equity_trough&&(r.equity_trough=a);const l=r.position_size,c=r.position_avg_price;let u=0,p=0;if(l!==0&&Number.isFinite(c)){const d=l>0?i:e,m=l>0?e:i;u=l*(c-d)*n,p=l*(m-c)*n}const h=r.equity_peak-a+u;if(h>r.max_drawdown&&(r.max_drawdown=h,r.equity_at_drawdown_peak=r.equity_peak,r.equity_peak>0)){const d=100*h/r.equity_peak;d>r.max_drawdown_percent_value&&(r.max_drawdown_percent_value=d)}const f=a-r.equity_trough+p;if(f>r.max_runup&&(r.max_runup=f,r.equity_at_runup_peak=a+p,r.equity_at_runup_peak>0)){const d=100*f/r.equity_at_runup_peak;d>r.max_runup_percent_value&&(r.max_runup_percent_value=d)}}function mn(t,e,i,r,n,a,s){const o=t.strategy;if(s!==void 0){const h=[],f=[];for(const m of o.opentrades)m.id===s?h.push(m):f.push(m);if(h.length===0)return;const d=Math.abs(h[0].size);o.opentrades=[...h,...f],$t(t,Math.min(i,d),r,n,a);return}if(!e||e===""){$t(t,i,r,n,a);return}const l=[],c=[];for(const h of o.opentrades)h.entry_id===e?l.push(h):c.push(h);const u=l.reduce((h,f)=>h+Math.abs(f.size),0);if(u===0)return;const p=Math.min(i,u);o.opentrades=[...l,...c],$t(t,p,r,n,a)}function Pp(t,e="intrabar"){if(!t.strategy)return;const i=t.strategy;if(i.pending_orders.length===0)return;const r=y.from(t.data.open).get(0),n=y.from(t.data.high).get(0),a=y.from(t.data.low).get(0),s=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.mintick??.01;for(const c of i.pending_orders){if(c.status!=="pending"||(c.category??"entry")!=="exit")continue;let u=i.opentrades.filter(k=>!c.from_entry||k.entry_id===c.from_entry);if(c._intended_trade_ids){const k=new Set(c._intended_trade_ids);u=u.filter(L=>k.has(L.id))}if(u.length===0){e==="intrabar"&&(c.status="cancelled");continue}const p=u.reduce((k,L)=>k+Math.abs(L.size),0),h=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 k=c.immediately?s:r;k=Ir(t,-h,k);let L=p;c.qty&&c.qty>0?L=Math.min(c.qty,p):c.qty_percent&&c.qty_percent>0&&(L=p*(c.qty_percent/100)),mn(t,c.from_entry,L,k,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=k,c.fill_bar=t.idx,c.fill_time=o;continue}let f=0;for(const k of u)f+=Math.abs(k.size)*k.entry_price;const d=f/p,m=h===1;let x=c.limit,b=c.stop;c._isPersistent||(b!==void 0&&((m?b<d:b>d)||(b=void 0)),x!==void 0&&((m?x>d:x<d)||(x=void 0))),c._attachedAtReversal&&!c._isPersistent&&(c.limit!==void 0&&(x=void 0),c.stop!==void 0&&(b=void 0));let v=!1;if(e==="intrabar"&&!c.trail_armed&&(c.trail_price!==void 0||c.trail_points!==void 0)){let k;c.trail_price!==void 0?k=c.trail_price:c.trail_points!==void 0&&(k=m?d+c.trail_points*l:d-c.trail_points*l),k!==void 0&&(m?n>=k:a<=k)&&(c.trail_armed=!0,c.trail_peak=m?n:a,v=!0)}const w=Math.abs(n-r)<=Math.abs(r-a),S=m?w:!w,A=[],N=[],P=i._mc_exit_lock,j=P&&P.bar===t.idx;for(const k of u){if(j&&k.id!==P.tradeId)continue;const L=k._bracket_entry??k.entry_price,D=Math.abs(k.size);let M=x;M===void 0&&c.profit!==void 0&&(M=m?L+c.profit*l:L-c.profit*l);let K=b;K===void 0&&c.loss!==void 0&&(K=m?L-c.loss*l:L+c.loss*l);const J=M!==void 0&&(e==="open"?m?r>=M:r<=M:m?n>=M:a<=M),_e=K!==void 0&&(e==="open"?m?r<=K:r>=K:m?a<=K:n>=K);let ne=null;if(J&&_e?ne=S?"profit":"loss":J?ne="profit":_e&&(ne="loss"),ne==="loss"){const Ee=m?r<=K:r>=K;!m&&Ee&&k.entry_bar_index===t.idx?J&&(ne="profit"):N.push({qty:D,price:Ee?r:K,kind:"loss",tradeId:k.id})}if(ne==="profit"){const Ee=m?r>=M:r<=M;A.push({qty:D,price:Ee?r:M,kind:"profit",tradeId:k.id})}}A.sort((k,L)=>m?k.price-L.price:L.price-k.price),N.sort((k,L)=>m?L.price-k.price:k.price-L.price);let I=null;if(e==="intrabar"&&!j&&c.trail_armed&&c.trail_offset!==void 0){const k=()=>{m?c.trail_peak=Math.max(c.trail_peak??-1/0,n):c.trail_peak=Math.min(c.trail_peak??1/0,a)},L=()=>m?c.trail_peak-c.trail_offset*l:c.trail_peak+c.trail_offset*l,D=M=>{I={qty:1/0,price:M,kind:"trailing"}};if(v){const M=L();S?(m?a<=M:n>=M)&&D(M):(m?s<=M:s>=M)&&D(M)}else if(S){k();const M=L();(m?a<=M:n>=M)&&D(M)}else{const M=L();if(m?a<=M:n>=M)D(M);else{k();const K=L();(m?s<=K:s>=K)&&D(K)}}}const V=S?[...A,...N,...I?[I]:[]]:[...N,...I?[I]:[],...A];if(V.length>0){let k=p;c.qty&&c.qty>0?k=Math.min(c.qty,p):c.qty_percent&&c.qty_percent>0&&(k=p*(c.qty_percent/100));const L=()=>i.opentrades.filter(K=>!c.from_entry||K.entry_id===c.from_entry).reduce((K,J)=>K+Math.abs(J.size),0);let D=NaN,M=!1;for(const K of V){if(k<=1e-9)break;const J=L();if(J<=1e-9)break;const _e=Math.min(K.qty===1/0?J:K.qty,k,J),ne=Ir(t,-h,K.price),Ee=K.kind==="profit"?c.comment_profit??c.comment:K.kind==="loss"?c.comment_loss??c.comment:c.comment_trailing??c.comment;mn(t,c.from_entry,_e,ne,o,{triggerKind:K.kind,exitId:c.id,exitComment:Ee},K.tradeId),k-=_e,D=ne,M=!0}M&&(L()<=1e-9||k<=1e-9)&&(c.status="filled",c.fill_price=D,c.fill_bar=t.idx,c.fill_time=o)}}i.pending_orders=i.pending_orders.filter(c=>c.status==="pending"),zi(t,s)}function Mp(t){const e=t.strategy;if(!e)return;const i=e._pending_close_mc;if(i&&(e._pending_close_mc=null,!(e.opentrades.length===0||Math.sign(e.position_size)!==i.dir)&&($t(t,Math.min(i.qty,Math.abs(e.position_size)),i.price,i.time,{exitId:"Margin call",exitComment:"Margin call"}),Math.abs(e.position_size)>1e-9))){for(const r of e.pending_orders)r.status==="pending"&&(r.category??"entry")==="entry"&&!r._isReversalEntry&&Ot(r.direction)===i.dir&&(r.status="cancelled");e.pending_orders=e.pending_orders.filter(r=>r.status==="pending")}}function Dp(t){const e=t.strategy,i=Math.sign(e?.position_size??0);if(i===0)return!1;const r=y.from(t.data.open).get(0),n=y.from(t.data.high).get(0),a=y.from(t.data.low).get(0),s=Math.abs(n-r)<=Math.abs(r-a);return i===1?!s:s}function pr(t,e="extreme"){const i=t.strategy;if(!i||i.opentrades.length===0)return;const r=Math.sign(i.position_size);if(r===0)return;const n=r===1?i.config.margin_long??100:i.config.margin_short??100,a=y.from(t.data.open).get(0),s=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,p=e==="open"?a:e==="close"?l:r===1?o:s,h=Math.abs(i.position_size),f=wp(t,p),d=qi(h,p,n,u);if(f<d){const m=d-f,x=n/100,b=m/(p*u*x),v=Math.min(h,4*b),w=[...i.opentrades],S=w[0],A=Math.abs(S.size),N=S.entry_price;if($t(t,v,p,c,{exitId:"Margin call",exitComment:"Margin call"}),e==="extreme"&&v>=A-1e-9&&Math.abs(i.position_size)>1e-9){const j=qi(A,p,n,u),I=A*(p-N)*r*u,V=m-j+I;if(V>0){const k=y.from(t.data.close).get(0),L=(M=>Math.trunc(M*1e6)/1e6)(V/(p*u*x)),D=Math.min(Math.abs(i.position_size),4*L);D>1e-9&&(i._pending_close_mc={qty:D,price:k,time:c,dir:r})}}const P=w.find(j=>j.status==="open");i._mc_exit_lock={bar:t.idx,tradeId:P?.id??null}}}function Rp(t){if(!t.strategy)return;const e=t.strategy,i=y.from(t.data.high).get(0),r=y.from(t.data.low).get(0),n=y.from(t.data.close).get(0);zi(t,n),Ap(t,i,r);const a=y.from(t.data.openTime).get(0);if(Number.isFinite(a)){const s=new Date(a),o=s.getUTCFullYear()*12+s.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 Op(t){const e=t?.strategy;if(!e)return;const i=e._monthly_equity??[],r=[e.initial_capital,...i],n=[];for(let f=1;f<r.length;f++){const d=r[f-1];d!==0&&Number.isFinite(d)&&Number.isFinite(r[f])&&n.push(r[f]/d-1)}if(n.length<2){e.sharpe_ratio=0,e.sortino_ratio=0;return}const a=(e.config.risk_free_rate??2)/100/12,s=n.length,o=n.reduce((f,d)=>f+d,0)/s,l=o-a,c=n.reduce((f,d)=>f+(d-o)**2,0)/s,u=Math.sqrt(c),p=n.reduce((f,d)=>f+Math.min(0,d-a)**2,0)/s,h=Math.sqrt(p);e.sharpe_ratio=u>0?l/u:0,e.sortino_ratio=h>0?l/h:0}function $p(t){t.strategy}function Vp(t,e){const i={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??{}},r=i.initial_capital;t.strategy={config:i,opentrades:[],closedtrades:[],pending_orders:[],position_size:0,position_avg_price:NaN,position_entry_name:"",initial_capital:r,account_currency:i.currency||"USD",equity:r,netprofit:0,grossprofit:0,grossloss:0,openprofit:0,max_drawdown:0,max_runup:0,equity_peak:r,equity_trough:r,equity_at_runup_peak:r,equity_at_drawdown_peak:r,max_drawdown_percent_value:0,max_runup_percent_value:0,sharpe_ratio:0,sortino_ratio: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 jp(t){return(...e)=>{const i=vp(e);return t.strategy?t.strategy.config={...t.strategy.config,...i,...t._propOverrides??{}}:Vp(t,i),t.strategy.config}}const Lp=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],Bp={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 Fp(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.order() called before strategy() declaration");const i=re(e,Lp,Bp),r=v=>v==null||typeof v=="string"||typeof v=="number"||typeof v=="boolean"?v:typeof v=="function"?v():v instanceof y?v.get(0):Array.isArray(v)?v[v.length-1]:typeof v=="object"&&v.get!==void 0?v.get(0):v,n=r(i.id),a=r(i.direction),s=r(i.qty),o=r(i.limit),l=r(i.stop),c=r(i.oca_name),u=r(i.oca_type),p=r(i.comment),h=Ot(a),f=y.from(t.data.close).get(0),d=Wr(t,s,h,f);let m="market";o!==void 0&&l!==void 0?m="stop-limit":o!==void 0?m="limit":l!==void 0&&(m="stop");const x=y.from(t.data.openTime).get(0),b={id:n,direction:h,qty:d,type:m,limit:o,stop:l,bar:t.idx,time:x,status:"pending",oca_name:c,oca_type:u,comment:p};return t.strategy.pending_orders.push(b),b}}function Wp(t){return(e,i)=>y.from(e).get(i||0)}function Up(t){return()=>{const e=(t.strategy?.opentrades??[]).slice(),i=h=>e[Number(h)],r=()=>{const h=t.marketData;return Array.isArray(h)&&t.idx>=0&&t.idx<h.length?h[t.idx]?.close??NaN:NaN},n={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},a=t.pine?.syminfo?.pointvalue??1,s=(h,f)=>{const d=t.strategy?.config,m=d?.commission_type??"percent",x=d?.commission_value??0;if(!x)return 0;const b=Math.abs(h.size);switch(m){case"percent":return b*f*a*(x/100);case"cash_per_contract":return b*x;case"cash_per_order":return x;default:return 0}},o=h=>Math.abs(h.size)*h.entry_price*a+(h.commission??0);n.profit=h=>{const f=i(h);if(!f)return NaN;const d=r();return Number.isFinite(d)?(Math.sign(f.size)===1?d-f.entry_price:f.entry_price-d)*Math.abs(f.size)*a-(f.commission??0)-s(f,d):NaN},n.profit_percent=h=>{const f=i(h);if(!f)return NaN;const d=n.profit(h);if(!Number.isFinite(d))return NaN;const m=o(f);return m>0?100*d/m:NaN},n.size=h=>i(h)?.size??NaN,n.commission=h=>i(h)?.commission??NaN,n.entry_price=h=>i(h)?.entry_price??NaN,n.entry_bar_index=h=>i(h)?.entry_bar_index??NaN,n.entry_id=h=>i(h)?.entry_id??"",n.entry_comment=h=>i(h)?.entry_comment??i(h)?.entry_id??"",n.entry_time=h=>i(h)?.entry_time??NaN,n.max_drawdown=h=>i(h)?.max_drawdown??0,n.max_drawdown_percent=h=>{const f=i(h);if(!f||!f.max_drawdown)return 0;const d=o(f);return d>0?100*f.max_drawdown/d:0},n.max_runup=h=>i(h)?.max_runup??0,n.max_runup_percent=h=>{const f=i(h);if(!f||!f.max_runup)return 0;const d=o(f);return d>0?100*f.max_runup/d:0};const l=t.strategy,c=l?.config?.margin_long??100,u=l?.config?.margin_short??100,p=c!==100||u!==100;if(!l||l.opentrades.length===0||!p)n.capital_held=NaN;else{let h=0;for(const f of l.opentrades){const d=Math.abs(f.size)*f.entry_price,m=f.size>0?c:u;h+=d*(m/100)}n.capital_held=h}return n}}function qp(t){return()=>{const e=(t.strategy?.closedtrades??[]).slice(),i=s=>e[Number(s)],r={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},n=t.pine?.syminfo?.pointvalue??1,a=s=>{const o=Math.abs(s.size)*s.entry_price*n,l=(s.commission??0)/2;return o+l};return r.profit=s=>i(s)?.profit??NaN,r.profit_percent=s=>{const o=i(s);if(!o||o.profit===void 0)return NaN;const l=a(o);return l>0?100*o.profit/l:NaN},r.size=s=>i(s)?.size??NaN,r.commission=s=>i(s)?.commission??NaN,r.entry_price=s=>i(s)?.entry_price??NaN,r.entry_bar_index=s=>i(s)?.entry_bar_index??NaN,r.entry_id=s=>i(s)?.entry_id??"",r.entry_comment=s=>i(s)?.entry_comment??i(s)?.entry_id??"",r.entry_time=s=>i(s)?.entry_time??NaN,r.exit_price=s=>i(s)?.exit_price??NaN,r.exit_bar_index=s=>i(s)?.exit_bar_index??NaN,r.exit_id=s=>i(s)?.exit_id??"",r.exit_comment=s=>i(s)?.exit_comment??i(s)?.exit_id??"",r.exit_time=s=>i(s)?.exit_time??NaN,r.max_drawdown=s=>i(s)?.max_drawdown??0,r.max_drawdown_percent=s=>{const o=i(s);if(!o||!o.max_drawdown)return 0;const l=a(o);return l>0?100*o.max_drawdown/l:0},r.max_runup=s=>i(s)?.max_runup??0,r.max_runup_percent=s=>{const o=i(s);if(!o||!o.max_runup)return 0;const l=a(o);return l>0?100*o.max_runup/l:0},r.first_index=0,r}}function zp(t){return()=>t.strategy?.netprofit??0}function Kp(t){return()=>t.strategy?.position_size??0}function Hp(t){return()=>{const e=t.strategy;return!e||e.position_size===0?NaN:e.position_avg_price}}function Gp(t){return()=>t.strategy?.equity??t.strategy?.config?.initial_capital??1e4}function Yp(t){return()=>"long"}function Xp(t){return()=>"short"}function Qp(t){return()=>"cash"}function Zp(t){return()=>"percent_of_equity"}function Jp(t){return()=>"fixed"}function ef(t){return()=>t.strategy?.openprofit??0}function tf(t){return()=>{const e=t.strategy;return!e||!e.initial_capital?0:100*e.openprofit/e.initial_capital}}function rf(t){return()=>{const e=t.strategy;return!e||!e.initial_capital?0:100*e.netprofit/e.initial_capital}}function nf(t){return()=>t.strategy?.grossprofit??0}function sf(t){return()=>{const e=t.strategy;return!e||!e.initial_capital?0:100*e.grossprofit/e.initial_capital}}function af(t){return()=>t.strategy?.grossloss??0}function of(t){return()=>{const e=t.strategy;return!e||!e.initial_capital?0:100*e.grossloss/e.initial_capital}}function lf(t){return()=>t.strategy?.wintrades??0}function cf(t){return()=>t.strategy?.losstrades??0}function uf(t){return()=>t.strategy?.eventrades??0}function hf(t){return()=>{const e=t.strategy;return!e||!e.closedtrades||e.closedtrades.length===0?NaN:e.netprofit/e.closedtrades.length}}function pf(t){return()=>{const e=t.strategy;if(!e||!e.closedtrades||e.closedtrades.length===0)return NaN;let i=0;for(const r of e.closedtrades){const n=Math.abs(r.size)*r.entry_price;n>0&&(i+=100*(r.profit??0)/n)}return i/e.closedtrades.length}}function ff(t){return()=>{const e=t.strategy;return!e||e.wintrades===0?NaN:e.wintrades_total_profit/e.wintrades}}function df(t){return()=>{const e=t.strategy;if(!e||e.wintrades===0)return NaN;let i=0;for(const r of e.closedtrades)if((r.profit??0)>0){const n=Math.abs(r.size)*r.entry_price;n>0&&(i+=100*(r.profit??0)/n)}return i/e.wintrades}}function mf(t){return()=>{const e=t.strategy;return!e||e.losstrades===0?NaN:e.losstrades_total_loss/e.losstrades}}function yf(t){return()=>{const e=t.strategy;if(!e||e.losstrades===0)return NaN;let i=0;for(const r of e.closedtrades)if((r.profit??0)<0){const n=Math.abs(r.size)*r.entry_price;n>0&&(i+=100*(r.profit??0)/n)}return i/e.losstrades}}function _f(t){return()=>t.strategy?.max_drawdown??0}function gf(t){return()=>{const e=t.strategy;return e?e.max_drawdown_percent_value??0:0}}function xf(t){return()=>t.strategy?.max_runup??0}function bf(t){return()=>{const e=t.strategy;return e?e.max_runup_percent_value??0:0}}function vf(t){return()=>t.strategy?.max_contracts_held_all??0}function wf(t){return()=>t.strategy?.max_contracts_held_long??0}function Sf(t){return()=>t.strategy?.max_contracts_held_short??0}function Ef(t){return()=>t.strategy?.position_entry_name??""}function Nf(t){return()=>t.strategy?.initial_capital??0}function Cf(t){return()=>t.strategy?.account_currency??"USD"}function If(t){return()=>{const e=t.strategy;if(!e||e.position_size===0)return NaN;const i=e.position_avg_price;if(!Number.isFinite(i))return NaN;const r=Math.sign(e.position_size),n=r===1?e.config.margin_long??100:e.config.margin_short??100;if(n>=100)return NaN;const a=Math.abs(e.position_size),s=t.pine?.syminfo?.pointvalue??1,o=((e.initial_capital??0)+(e.netprofit??0))/(s*a)-r*i,l=n/100-r,c=o/l,u=t.pine?.syminfo?.mintick??.01;return r===1?Math.floor(c/u)*u:Math.ceil(c/u)*u}}const kf=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],Tf={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 Af(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.entry() called before strategy() declaration");const i=re(e,kf,Tf),r=I=>I==null||typeof I=="string"||typeof I=="number"||typeof I=="boolean"?I:typeof I=="function"?I():I instanceof y?I.get(0):Array.isArray(I)?I[I.length-1]:typeof I=="object"&&I.get!==void 0?I.get(0):I,n=r(i.id),a=r(i.direction),s=r(i.qty),o=r(i.limit),l=r(i.stop),c=r(i.oca_name),u=r(i.oca_type),p=r(i.comment),h=Ot(a),f=t.strategy,d=f.position_size;if(Math.sign(d)===h&&d!==0&&Np(f,h))return;const m=y.from(t.data.close).get(0),x=Wr(t,s,h,m),b=d!==0&&Math.sign(d)!==h,v=b?Math.abs(d)+x:x;let w="market";o!==void 0&&l!==void 0?w="stop-limit":o!==void 0?w="limit":l!==void 0&&(w="stop");const S=t.pine?.syminfo?.mintick??0,A=o!==void 0?ui(o,m,S):void 0,N=l!==void 0?ui(l,m,S):void 0,P=y.from(t.data.openTime).get(0),j={id:n,direction:h,qty:v,type:w,limit:A,stop:N,bar:t.idx,time:P,status:"pending",category:"entry",oca_name:c,oca_type:u,comment:p,_isReversalEntry:b,_base_qty:x};f.pending_orders.push(j)}}const Pf=[["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"]],Mf={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 Df(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.exit() called before strategy() declaration");let i=tt(e);if(i===void 0){const D=t.strategy;D._exit_fallback_last_bar!==t.idx&&(D._exit_fallback_counter=0,D._exit_fallback_last_bar=t.idx),i=`exit_raw_${D._exit_fallback_counter++}`}const r=re(e,Pf,Mf),n=D=>D==null||typeof D=="string"||typeof D=="number"||typeof D=="boolean"?D:typeof D=="function"?D():D instanceof y?D.get(0):Array.isArray(D)?D[D.length-1]:typeof D=="object"&&D.get!==void 0?D.get(0):D,a=n(r.id),s=n(r.from_entry),o=n(r.qty),l=n(r.qty_percent),c=n(r.profit),u=n(r.limit),p=n(r.loss),h=n(r.stop),f=n(r.trail_price),d=n(r.trail_points),m=n(r.trail_offset),x=t.pine?.syminfo?.mintick??0,b=y.from(t.data.close).get(0),v=u!==void 0?ui(u,b,x):void 0,w=h!==void 0?ui(h,b,x):void 0,S=f!==void 0?ui(f,b,x):void 0,A=s??"",N=!!(A?t.strategy.pending_orders.find(D=>D.category==="entry"&&D.id===A&&D.status==="pending"):t.strategy.pending_orders.find(D=>D.category==="entry"&&D.status==="pending"))?._isReversalEntry,P=t.strategy._exit_call_history,j=P.get(i),I=j!==void 0&&j===t.idx-1;P.set(i,t.idx);const V={id:a??"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:p,limit:v,stop:w,trail_price:S,trail_points:d,trail_offset:m,oca_name:n(r.oca_name),comment:n(r.comment),comment_profit:n(r.comment_profit),comment_loss:n(r.comment_loss),comment_trailing:n(r.comment_trailing),alert_message:n(r.alert_message),alert_profit:n(r.alert_profit),alert_loss:n(r.alert_loss),alert_trailing:n(r.alert_trailing),disable_alert:n(r.disable_alert),trail_armed:!1,trail_peak:NaN,_attachedAtReversal:N,_isPersistent:I,_callsiteId:i},k=V.id,L=t.strategy.pending_orders;for(let D=L.length-1;D>=0;D--){const M=L[D];M.category==="exit"&&M.id===k&&(M.from_entry??"")===(V.from_entry??"")&&M.status==="pending"&&(M.trail_armed&&(V.trail_armed=!0,V.trail_peak=M.trail_peak),L.splice(D,1))}L.push(V)}}const Rf=[["id","comment","qty","qty_percent","alert_message","immediately","disable_alert"]],Of={id:"string",comment:"string",qty:"series",qty_percent:"series",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function $f(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close() called before strategy() declaration");const i=re(e,Rf,Of),r=i.id;if(r==null||!t.strategy.opentrades.some(o=>o.entry_id===r))return;const n=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),a=t.strategy.pending_orders;for(const o of a)n(o)&&(o.from_entry??"")===r&&o.status==="pending"&&(o.status="cancelled");t.strategy.pending_orders=a.filter(o=>o.status==="pending");const s={id:`close_${r}`,direction:0,qty:0,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:r,qty_percent:i.qty_percent,comment:i.comment,alert_message:i.alert_message,immediately:i.immediately===!0,disable_alert:i.disable_alert,_intended_trade_ids:t.strategy.opentrades.filter(o=>o.entry_id===r).map(o=>o.id)};i.qty!==void 0&&(s.qty=Math.abs(Number(i.qty))),t.strategy.pending_orders.push(s)}}const Vf=[["comment","alert_message","immediately","disable_alert"]],jf={comment:"string",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function Lf(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close_all() called before strategy() declaration");const i=re(e,Vf,jf);if(t.strategy.opentrades.length===0)return;const r=s=>(s.category??"entry")==="exit"&&(s.profit!==void 0||s.loss!==void 0||s.limit!==void 0||s.stop!==void 0||s.trail_price!==void 0||s.trail_points!==void 0),n=t.strategy.pending_orders;for(const s of n)r(s)&&s.status==="pending"&&(s.status="cancelled");t.strategy.pending_orders=n.filter(s=>s.status==="pending");const a={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:i.comment,alert_message:i.alert_message,immediately:i.immediately===!0,disable_alert:i.disable_alert,_intended_trade_ids:t.strategy.opentrades.map(s=>s.id)};t.strategy.pending_orders.push(a)}}const Bf=[["id","immediately"]],Ff={id:"string",immediately:"boolean"};function Wf(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.cancel() called before strategy() declaration");const i=re(e,Bf,Ff).id;i!=null&&(t.strategy.pending_orders=t.strategy.pending_orders.filter(r=>!(r.status==="pending"&&r.id===i)))}}function Uf(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 qf(t){return{allow_entry_in:e=>{t.strategy&&(t.strategy.risk_rules.allow_entry_in=e)},max_cons_loss_days:(e,i)=>{t.strategy&&(t.strategy.risk_rules.max_cons_loss_days={count:e,alert_message:i})},max_drawdown:(e,i,r)=>{t.strategy&&(t.strategy.risk_rules.max_drawdown={value:e,type:i})},max_intraday_filled_orders:(e,i)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_filled_orders={count:e,alert_message:i})},max_intraday_loss:(e,i,r)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_loss={value:e,type:i})},max_position_size:e=>{t.strategy&&(t.strategy.risk_rules.max_position_size=e)}}}function zf(t){return e=>{const i=t.strategy,r=t.pine?.syminfo?.currency,n=i?.account_currency??"USD";return r&&r!==n?NaN:e}}function Kf(t){return e=>{const i=t.strategy,r=t.pine?.syminfo?.currency,n=i?.account_currency??"USD";return r&&r!==n?NaN:e}}function Hf(t){return e=>t.strategy?Wr(t,void 0,1,e):0}const Gf={any:jp,order:Fp,param:Wp,opentrades:Up,closedtrades:qp,netprofit:zp,position_size:Kp,position_avg_price:Hp,equity:Gp,long:Yp,short:Xp,cash:Qp,percent_of_equity:Zp,fixed:Jp,openprofit:ef,openprofit_percent:tf,netprofit_percent:rf,grossprofit:nf,grossprofit_percent:sf,grossloss:af,grossloss_percent:of,wintrades:lf,losstrades:cf,eventrades:uf,avg_trade:hf,avg_trade_percent:pf,avg_winning_trade:ff,avg_winning_trade_percent:df,avg_losing_trade:mf,avg_losing_trade_percent:yf,max_drawdown:_f,max_drawdown_percent:gf,max_runup:xf,max_runup_percent:bf,max_contracts_held_all:vf,max_contracts_held_long:wf,max_contracts_held_short:Sf,position_entry_name:Ef,initial_capital:Nf,account_currency:Cf,margin_liquidation_price:If,entry:Af,exit:Df,close:$f,close_all:Lf,cancel:Wf,cancel_all:Uf,convert_to_account:zf,convert_to_symbol:Kf,default_entry_qty:Hf},Yf={long:"long",short:"short",all:"all"},Xf={none:"none",cancel:"cancel",reduce:"reduce"},Qf={percent:"percent",cash_per_order:"cash_per_order",cash_per_contract:"cash_per_contract"};class Zf{constructor(e){this.context=e,Object.entries(Gf).forEach(([r,n])=>{this[r]=n(e)}),this.direction=()=>Yf,this.oca=()=>Xf,this.commission=()=>Qf;const i=qf(e);this.risk=()=>i}}function Jf(t,e){const i=e.trim();if(i==="UTC"||i==="GMT"||i==="Etc/UTC")return 0;const r=i.match(/^(?:UTC|GMT)([+-])(\d{1,2})(?::(\d{2}))?$/i);if(r){const s=r[1]==="+"?1:-1,o=parseInt(r[2],10),l=parseInt(r[3]||"0",10);return s*(o*60+l)}const n=Vt(t,e),a=new Date(Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second));return Math.round((a.getTime()-t)/6e4)}function ed(t,e){const i=e>=0?"+":"-",r=a=>String(Math.floor(Math.abs(a))).padStart(2,"0"),n=i+r(e/60)+":"+r(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${n}]`}class td{constructor(e){this.context=e}logFormat(e,...i){return e.replace(/{(\d+)}/g,(r,n)=>i[n])}param(e,i=0,r){return y.from(e).get(i)}_formatTimestamp(){const e=this.context.data.openTime.data[this.context.idx],i=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",r=Jf(e,i);return ed(e,r)}warning(e,...i){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}error(e,...i){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}info(e,...i){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...i)}`)}}const id=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],rd=["January","February","March","April","May","June","July","August","September","October","November","December"],nd=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],sd=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Le=(t,e)=>String(t).padStart(e,"0");class ad{constructor(e){this.context=e}param(e,i=0,r){return y.from(e).get(i)}tostring(e,i){if(typeof e!="number"||isNaN(e)||!i)return String(e);if(i==="mintick"){const n=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(n)));return e.toFixed(a)}if(i==="integer")return String(Math.round(e));if(i==="percent")return(e*100).toFixed(2)+"%";if(i==="price"){const n=this.context.pine?.syminfo?.mintick||.01,a=Math.max(0,-Math.floor(Math.log10(n)));return e.toFixed(a)}if(i==="volume")return String(Math.round(e));const r=i.indexOf(".");if(r>=0){const n=i.substring(r+1).length;return e.toFixed(n)}return i.includes("#")||i.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,i,r=""){return Array(i).fill(e).join(r||"")}replace_all(e,i,r){return String(e).replaceAll(i,r)}replace(e,i,r,n=0){const a=String(e),s=String(i),o=String(r),l=Math.floor(Number(n))||0;if(s==="")return a;let c=0,u=0;for(;;){const p=a.indexOf(s,c);if(p===-1)return a;if(u===l)return a.substring(0,p)+o+a.substring(p+s.length);u++,c=p+s.length}}contains(e,i){return String(e).includes(i)}endswith(e,i){return String(e).endsWith(i)}startswith(e,i){return String(e).startsWith(i)}pos(e,i){const r=String(e).indexOf(i);return r===-1?NaN:r}length(e){return String(e).length}match(e,i){return String(e).match(new RegExp(i))}split(e,i){return new U(String(e).split(i),F.string,this.context)}substring(e,i,r){return String(e).substring(i,r)}format_time(e,i="yyyy-MM-dd'T'HH:mm:ssZ",r){if(e==null||typeof e=="number"&&isNaN(e))return"NaN";const n=Number(e),a=r||this.context.pine?.syminfo?.timezone||"UTC",s=Vt(n,a),o=Date.UTC(s.year,s.month-1,s.day,s.hour,s.minute,s.second),l=Math.round((o-n)/6e4),c=Date.UTC(s.year,0,1),u=Math.floor((o-c)/864e5)+1,p=s.hour%12===0?12:s.hour%12;let h="",f=0;for(;f<i.length;){const d=i[f];if(d==="'"){if(i[f+1]==="'"){h+="'",f+=2;continue}const m=i.indexOf("'",f+1);if(m===-1){h+=i.substring(f+1);break}h+=i.substring(f+1,m),f=m+1;continue}if(d>="a"&&d<="z"||d>="A"&&d<="Z"){let m=1;for(;i[f+m]===d;)m++;switch(f+=m,d){case"y":h+=m===2?Le(s.year%100,2):m>=4?Le(s.year,4):String(s.year);break;case"M":m>=4?h+=rd[s.month-1]:m===3?h+=id[s.month-1]:m===2?h+=Le(s.month,2):h+=String(s.month);break;case"d":h+=m===2?Le(s.day,2):String(s.day);break;case"D":h+=m>=3?Le(u,3):m===2?Le(u,2):String(u);break;case"E":h+=m>=4?sd[s.dayOfWeek]:nd[s.dayOfWeek];break;case"a":h+=s.hour<12?"AM":"PM";break;case"h":h+=m===2?Le(p,2):String(p);break;case"H":h+=m===2?Le(s.hour,2):String(s.hour);break;case"m":h+=m===2?Le(s.minute,2):String(s.minute);break;case"s":h+=m===2?Le(s.second,2):String(s.second);break;case"S":{const x=n-Math.floor(n/1e3)*1e3;h+=Le(x,3).substring(0,m);break}case"Z":{const x=l>=0?"+":"-",b=Math.abs(l);h+=`${x}${Le(Math.floor(b/60),2)}${Le(b%60,2)}`;break}default:h+=d.repeat(m)}continue}h+=d,f++}return h}format(e,...i){return e.replace(/\{(\d+)(?:,number,([^}]+))?\}/g,(r,n,a)=>{const s=i[n];return a&&typeof s=="number"&&!isNaN(s)?this.tostring(s,a):String(s)})}}var od=Object.defineProperty,ld=(t,e,i)=>e in t?od(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,cd=(t,e,i)=>ld(t,typeof e!="symbol"?e+"":e,i);const ki={"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 yn(t){if(!t||/^\d+$/.test(t))return t;if(ki[t])return ki[t];const e=t.toLowerCase();if(ki[e])return ki[e];if(t.length===1){const r=t.toUpperCase();if(["D","W","M","S"].includes(r))return r}const i=t.slice(-1).toUpperCase();if(["D","W","M","S"].includes(i)){const r=parseInt(t);if(!isNaN(r))return r+i}return t}class ud{constructor(e){this.context=e,cd(this,"_normalized",null)}param(e,i=0,r){return y.from(e).get(i)}get normalized(){return this._normalized===null&&(this._normalized=yn(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(){const 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){const i=typeof e=="function"?e():e,r=i instanceof y?i.get(0):i,n=Sr(r||"");if(!n)return!1;const a=y.from(this.context.data.openTime).get(0),s=y.from(this.context.data.openTime).get(1);if(isNaN(a)||isNaN(s))return!1;const o=Er(a,n),l=Er(s,n);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=yn(e);const i=e.slice(-1).toUpperCase(),r=parseInt(e);return i==="S"?isNaN(r)?1:r:i==="D"?(isNaN(r)?1:r)*60*60*24:i==="W"?(isNaN(r)?1:r)*60*60*24*7:i==="M"?(isNaN(r)?1:r)*60*60*24*30:isNaN(r)?0:r*60}}var hd=Object.defineProperty,pd=Object.getOwnPropertyDescriptor,ot=(t,e,i,r)=>{for(var n=r>1?void 0:r?pd(e,i):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(r?s(e,i,n):s(n))||n);return r&&n&&hd(e,i,n),n};const fd=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],dd=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],md={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"},yd=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],_d=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],gd=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],xd=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],_n=["color","offset","editable","show_last","title","display","force_overlay"],bd=["price","title","color","linestyle","linewidth","editable","display"],vd=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],wd={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"},Sd={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"},Ed={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"},Nd={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"},Cd={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"},gn={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},Id={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},kd={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"};class yt{constructor(e){this.context=e}_resolvePlotKey(e,i){if(e){const r=this.context.plots[e];return!r||!i||r._callsiteId===i?e:e+i}return i||"plot"}extractPlotOptions(e){const i={};for(let r in e)i[r]=y.from(e[r]).get(0);return i}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,i=0,r){return y.from(e).get(i)}plotchar(...e){const i=tt(e),r=re(e,dd,md),{series:n,title:a,...s}=r,o=this.extractPlotOptions(s),l=this._resolvePlotKey(a,i);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:a,_plotKey:l,_callsiteId:i});const c=y.from(n).get(0);return this.context.plots[l].data.push({title:a,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){const i=tt(e),r=re(e,fd,wd),{series:n,title:a,...s}=r,o=this.extractPlotOptions(s),l=this._resolvePlotKey(a,i),c="color"in s;if(!this.context.plots[l]){const f=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:f},title:a,_plotKey:l,_callsiteId:i}}const u=y.from(n).get(0);let p=o.color;typeof p=="function"&&(p=p());const h={color:c?typeof p=="string"?p:void 0:p||"#2962ff"};return"offset"in s&&(h.offset=o.offset),this.context.plots[l].data.push({title:a,time:this.context.marketData[this.context.idx].openTime,value:u,options:h}),this.context.plots[l]}plotshape(...e){const i=tt(e),r=re(e,yd,Sd),{series:n,title:a,...s}=r,o=this.extractPlotOptions(s),l=this._resolvePlotKey(a,i);if(!this.context.plots[l]){const u=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,style:"shape",shape:o.style,overlay:u},title:a,_plotKey:l,_callsiteId:i}}const c=y.from(n).get(0);return this.context.plots[l].data.push({title:a,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){const i=tt(e),r=re(e,_d,Ed),{series:n,title:a,...s}=r,o=y.from(n).get(0),l=this.extractPlotOptions(s),c=this._resolvePlotKey(a,i);if(!this.context.plots[c]){const u=l.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[c]={data:[],options:{...l,style:"shape",overlay:u},title:a,_plotKey:c,_callsiteId:i}}return this.context.plots[c].data.push({title:a,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){const i=tt(e),r=re(e,gd,Nd),{open:n,high:a,low:s,close:o,title:l,...c}=r,u=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...u,style:"bar",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const h=[y.from(n).get(0),y.from(a).get(0),y.from(s).get(0),y.from(o).get(0)];this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:h,options:{color:u.color}})}plotcandle(...e){const i=tt(e),r=re(e,xd,Cd),{open:n,high:a,low:s,close:o,title:l,...c}=r,u=this.extractPlotOptions(c),p=this._resolvePlotKey(l,i);if(!this.context.plots[p]){const f=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...u,style:"candle",overlay:f},title:l,_plotKey:p,_callsiteId:i}}const h=[y.from(n).get(0),y.from(a).get(0),y.from(s).get(0),y.from(o).get(0)];return this.context.plots[p].data.push({title:l,time:this.context.marketData[this.context.idx].openTime,value:h,options:{color:u.color,wickcolor:u.wickcolor,bordercolor:u.bordercolor}}),this.context.plots[p]}bgcolor(...e){const i=tt(e),r=re(e,_n,gn),{title:n,...a}=r,s=this.extractPlotOptions(a),o=this._resolvePlotKey(n,i);if(!this.context.plots[o]){const l=s.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...s,style:"background",overlay:l},title:n,_plotKey:o,_callsiteId:i}}this.context.plots[o].data.push({title:n,time:this.context.marketData[this.context.idx].openTime,value:s.color&&s.color!=="na"&&s?.color.toString()!=="NaN",options:{color:s.color}})}barcolor(...e){const i=tt(e),r=re(e,_n,gn),{title:n,...a}=r,s=this.extractPlotOptions(a),o=this._resolvePlotKey(n,i);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...s,style:"barcolor"},title:n,_plotKey:o,_callsiteId:i}),this.context.plots[o].data.push({title:n,time:this.context.marketData[this.context.idx].openTime,value:s.color&&s.color!=="na"&&s?.color.toString()!=="NaN",options:{color:s.color}}),this.context.plots[o]}}ot([C],yt.prototype,"plotchar",1),ot([C],yt.prototype,"any",1),ot([C],yt.prototype,"plotshape",1),ot([C],yt.prototype,"plotarrow",1),ot([C],yt.prototype,"plotbar",1),ot([C],yt.prototype,"plotcandle",1),ot([C],yt.prototype,"bgcolor",1),ot([C],yt.prototype,"barcolor",1);class Ds{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,i=0,r){return y.from(e).get(i)}any(...e){const i=tt(e),r=re(e,bd,Id),{price:n,title:a,color:s,linestyle:o,linewidth:l,editable:c,display:u}=r,p=[n,{title:a,color:s,linestyle:o,linewidth:l,editable:c,display:u,style:"hline"}];return i&&p.push({__callsiteId:i}),this.context.pine.plot.any(...p)}}ot([C],Ds.prototype,"any",1);class Rs{constructor(e){this.context=e}param(e,i=0,r){return y.from(e).get(i)}any(...e){const i=tt(e),r=e.length>=6&&typeof e[2]=="number",n=!r&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(r||n!==null){const a=e[0],s=e[1],o=n?y.from(n.top_value).get(0):e[2],l=n?y.from(n.bottom_value).get(0):e[3],c=n?y.from(n.top_color).get(0):e[4],u=n?y.from(n.bottom_color).get(0):e[5],p=n?n.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,h=a?._plotKey||a?.title,f=s?._plotKey||s?.title;let d=p||"fill";const m=this.context.plots[d];m&&i&&m._callsiteId!==i&&(d=i),this.context.plots[d]||(this.context.plots[d]={title:p||"Fill",plot1:h,plot2:f,data:[],options:{plot1:h,plot2:f,style:"fill",gradient:!0},_plotKey:d,_callsiteId:i}),this.context.plots[d].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{const a=re(e,vd,kd),{plot1:s,plot2:o,color:l,title:c,editable:u,show_last:p,fillgaps:h,display:f}=a;let d=c||"fill";const m=this.context.plots[d];m&&i&&m._callsiteId!==i&&(d=i);const x=y.from(l).get(0);if(!this.context.plots[d]){const b=s?._plotKey||s?.title,v=o?._plotKey||o?.title;this.context.plots[d]={title:c||"Fill",plot1:b,plot2:v,data:[],options:{plot1:b,plot2:v,color:x,editable:u,show_last:p,fillgaps:h,display:f,style:"fill"},_plotKey:d,_callsiteId:i}}this.context.plots[d].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:x}})}}}ot([C],Rs.prototype,"any",1);var Td=Object.defineProperty,Ad=(t,e,i)=>e in t?Td(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Pd=(t,e,i)=>Ad(t,typeof e!="symbol"?e+"":e,i);class Md{constructor(e){this.context=e,Pd(this,"point");const i=this.context;this.point={new(r,n,a){return new Ae(r,n,a??NaN)},from_index(r,n){return new Ae(void 0,r,n)},from_time(r,n){return new Ae(r,void 0,n)},copy(r){return r.copy()},now(r){const n=i.idx,a=i.marketData[n]?.openTime;return new Ae(a,n,r)}}}param(e,i=0,r){return y.from(e).get(i)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){return!0}is_heikinashi(){return!1}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}}var Dd=Object.defineProperty,Rd=(t,e,i)=>e in t?Dd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ve=(t,e,i)=>Rd(t,typeof e!="symbol"?e+"":e,i);let Od=0;class hi{constructor(e,i,r="",n="bi",a="pr",s="",o="style_label_down",l="",c="normal",u="center",p="",h="default",f=!1){ve(this,"id"),ve(this,"x"),ve(this,"y"),ve(this,"text"),ve(this,"xloc"),ve(this,"yloc"),ve(this,"color"),ve(this,"style"),ve(this,"textcolor"),ve(this,"size"),ve(this,"textalign"),ve(this,"tooltip"),ve(this,"text_font_family"),ve(this,"force_overlay"),ve(this,"_deleted"),ve(this,"_helper"),ve(this,"_createdAtBar",-1),this.id=Od++,this.x=e,this.y=i,this.text=r,this.xloc=n,this.yloc=a,this.color=s,this.style=o,this.textcolor=l,this.size=c,this.textalign=u,this.tooltip=p,this.text_font_family=h,this.force_overlay=f,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,i){this._helper?this._helper.set_xy(this,e,i):this._deleted||(this.x=e,this.y=i)}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 hi(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}}}var Os=Object.defineProperty,$d=Object.getOwnPropertyDescriptor,Vd=(t,e,i)=>e in t?Os(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ne=(t,e,i,r)=>{for(var n=r>1?void 0:r?$d(e,i):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(r?s(e,i,n):s(n))||n);return r&&n&&Os(e,i,n),n},jd=(t,e,i)=>Vd(t,typeof e!="symbol"?e+"":e,i);const Ld=[["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"]],Bd={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"};class we{constructor(e){this.context=e,jd(this,"_labels",[])}param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._labels.filter(a=>!a._deleted).map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__labels__.data=[{time:e,value:r,options:{style:"label"}}],n.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:n,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof $e)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){const i=e.get(0);return typeof i=="number"&&isNaN(i)?null:i}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,i,r="",n="bi",a="pr",s="",o="style_label_down",l="",c="normal",u="center",p="",h="default",f=!1){const d=new hi(e,i,this._resolve(r),this._resolve(n),this._resolve(a),this._resolve(s),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(u),this._resolve(p),this._resolve(h),f);return d._helper=this,d._createdAtBar=this.context.idx,this._labels.push(d),this._enforceMaxCount(),this.syncToPlot(),d}_enforceMaxCount(){const e=this.context.indicator?.max_labels_count??50,i=this._labels.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const a of this._labels){if(n>=r)break;a._deleted||(a._deleted=!0,n++)}}}new(...e){const i=re(e,Ld,Bd);let r,n,a=i.xloc;if(i.point instanceof Ae){const s=i.point,o=s.index!==void 0&&!(typeof s.index=="number"&&isNaN(s.index)),l=s.time!==void 0&&!(typeof s.time=="number"&&isNaN(s.time));o?(r=s.index,a=a||"bi"):l?(r=s.time,a=a||"bt"):(r=0,a=a||"bi"),n=s.price}else r=i.x,n=i.y;return this._createLabel(r,n,i.text,a,i.yloc,i.color,i.style,i.textcolor,i.size,i.textalign,i.tooltip,i.text_font_family,i.force_overlay)}any(...e){if(e.length===1){const i=e[0];if(i==null||i instanceof $e||typeof i=="number"&&isNaN(i))return null;if(i instanceof hi)return i;if(i instanceof y){const r=i.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof hi)return r}return null}return this.new(...e)}set_x(e,i){e&&!e._deleted&&(e.x=i)}set_y(e,i){e&&!e._deleted&&(e.y=i)}set_xy(e,i,r){e&&!e._deleted&&(e.x=i,e.y=r)}set_text(e,i){e&&!e._deleted&&(e.text=i)}set_color(e,i){e&&!e._deleted&&(e.color=i)}set_textcolor(e,i){e&&!e._deleted&&(e.textcolor=i)}set_size(e,i){e&&!e._deleted&&(e.size=i)}set_style(e,i){e&&!e._deleted&&(e.style=i)}set_textalign(e,i){e&&!e._deleted&&(e.textalign=i)}set_tooltip(e,i){e&&!e._deleted&&(e.tooltip=i)}set_xloc(e,i){e&&!e._deleted&&(e.xloc=i)}set_yloc(e,i){e&&!e._deleted&&(e.yloc=i)}set_point(e,i){if(e&&!e._deleted&&i){const r=i.index!==void 0&&!(typeof i.index=="number"&&isNaN(i.index)),n=i.time!==void 0&&!(typeof i.time=="number"&&isNaN(i.time));r?(e.x=i.index,e.xloc="bi"):n&&(e.x=i.time,e.xloc="bt"),e.y=i.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;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._labels.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(i=>i._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"}}Ne([C],we.prototype,"new",1),Ne([C],we.prototype,"set_x",1),Ne([C],we.prototype,"set_y",1),Ne([C],we.prototype,"set_xy",1),Ne([C],we.prototype,"set_text",1),Ne([C],we.prototype,"set_color",1),Ne([C],we.prototype,"set_textcolor",1),Ne([C],we.prototype,"set_size",1),Ne([C],we.prototype,"set_style",1),Ne([C],we.prototype,"set_textalign",1),Ne([C],we.prototype,"set_tooltip",1),Ne([C],we.prototype,"set_xloc",1),Ne([C],we.prototype,"set_yloc",1),Ne([C],we.prototype,"set_point",1),Ne([C],we.prototype,"copy",1),Ne([C],we.prototype,"delete",1);var Fd=Object.defineProperty,Wd=(t,e,i)=>e in t?Fd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,De=(t,e,i)=>Wd(t,typeof e!="symbol"?e+"":e,i);let Ud=0;class pi{constructor(e,i,r,n,a="bi",s="none",o="",l="style_solid",c=1,u=!1){De(this,"id"),De(this,"x1"),De(this,"y1"),De(this,"x2"),De(this,"y2"),De(this,"xloc"),De(this,"extend"),De(this,"color"),De(this,"style"),De(this,"width"),De(this,"force_overlay"),De(this,"_deleted"),De(this,"_helper"),De(this,"_createdAtBar",-1),this.id=Ud++,this.x1=e,this.y1=i,this.x2=r,this.y2=n,this.xloc=a,this.extend=s,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,i){this._helper?this._helper.set_xy1(this,e,i):this._deleted||(this.x1=e,this.y1=i)}set_xy2(e,i){this._helper?this._helper.set_xy2(this,e,i):this._deleted||(this.x2=e,this.y2=i)}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,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.x1=e,this.x2=i,this.xloc=r)}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 pi(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}}}var $s=Object.defineProperty,qd=Object.getOwnPropertyDescriptor,zd=(t,e,i)=>e in t?$s(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ce=(t,e,i,r)=>{for(var n=r>1?void 0:r?qd(e,i):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(r?s(e,i,n):s(n))||n);return r&&n&&$s(e,i,n),n},Kd=(t,e,i)=>zd(t,typeof e!="symbol"?e+"":e,i);const Hd=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],Gd={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"};class Se{constructor(e){this.context=e,Kd(this,"_lines",[])}param(e,i=0,r){return y.from(e).get(i)}_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();const e=this.context.marketData[0]?.openTime||0,i=this._lines.filter(a=>!a._deleted).map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__lines__.data=[{time:e,value:r,options:{style:"drawing_line"}}],n.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:n,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e){const i=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),r=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return i?{x:e.index,xloc:"bi"}:r?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof $e?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){const i=this._resolve(e);return i==null?i:typeof i=="number"&&isNaN(i)?NaN:i}_createLine(e,i,r,n,a="bi",s="none",o="",l="style_solid",c=1,u=!1){const p=new pi(e,i,r,n,a,this._resolve(s),this._resolveColor(o),this._resolve(l),this._resolve(c)||1,u);return p._helper=this,p._createdAtBar=this.context.idx,this._lines.push(p),this._enforceMaxCount(),this.syncToPlot(),p}_enforceMaxCount(){const e=this.context.indicator?.max_lines_count??50,i=this._lines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const a of this._lines){if(n>=r)break;a._deleted||(a._deleted=!0,n++)}}}new(...e){const i=re(e,Hd,Gd);let r,n,a,s,o=i.xloc;if(i.first_point instanceof Ae){const l=i.first_point,c=i.second_point,u=this._resolvePoint(l);r=u.x,n=l.price,o=o||u.xloc,c instanceof Ae?(a=this._resolvePoint(c).x,s=c.price):(a=0,s=NaN)}else r=i.x1,n=i.y1,a=i.x2,s=i.y2;return this._createLine(r,n,a,s,o,i.extend,i.color,i.style,i.width,i.force_overlay)}any(...e){if(e.length===1){const i=e[0];if(i==null||i instanceof $e||typeof i=="number"&&isNaN(i))return null;if(i instanceof pi)return i;if(i instanceof y){const r=i.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof pi)return r}return null}return this.new(...e)}set_x1(e,i){e&&!e._deleted&&(e.x1=this._resolve(i))}set_y1(e,i){e&&!e._deleted&&(e.y1=this._resolve(i))}set_x2(e,i){e&&!e._deleted&&(e.x2=this._resolve(i))}set_y2(e,i){e&&!e._deleted&&(e.y2=this._resolve(i))}set_xy1(e,i,r){e&&!e._deleted&&(e.x1=this._resolve(i),e.y1=this._resolve(r))}set_xy2(e,i,r){e&&!e._deleted&&(e.x2=this._resolve(i),e.y2=this._resolve(r))}set_color(e,i){e&&!e._deleted&&(e.color=this._resolveColor(i))}set_width(e,i){e&&!e._deleted&&(e.width=this._resolve(i)||1)}set_style(e,i){e&&!e._deleted&&(e.style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_xloc(e,i,r,n){e&&!e._deleted&&(e.x1=i,e.x2=r,e.xloc=n)}set_first_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x1=r.x,e.y1=i.price,e.xloc=r.xloc}}set_second_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.x2=r.x,e.y2=i.price,e.xloc=r.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,i){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;const r=e.x2-e.x1;return r===0?e.y1:e.y1+(i-e.x1)/r*(e.y2-e.y1)}copy(e){if(!e)return;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._lines.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(i=>i._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"}}Ce([C],Se.prototype,"new",1),Ce([C],Se.prototype,"set_x1",1),Ce([C],Se.prototype,"set_y1",1),Ce([C],Se.prototype,"set_x2",1),Ce([C],Se.prototype,"set_y2",1),Ce([C],Se.prototype,"set_xy1",1),Ce([C],Se.prototype,"set_xy2",1),Ce([C],Se.prototype,"set_color",1),Ce([C],Se.prototype,"set_width",1),Ce([C],Se.prototype,"set_style",1),Ce([C],Se.prototype,"set_extend",1),Ce([C],Se.prototype,"set_xloc",1),Ce([C],Se.prototype,"set_first_point",1),Ce([C],Se.prototype,"set_second_point",1),Ce([C],Se.prototype,"copy",1),Ce([C],Se.prototype,"delete",1);var Yd=Object.defineProperty,Xd=(t,e,i)=>e in t?Yd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,oe=(t,e,i)=>Xd(t,typeof e!="symbol"?e+"":e,i);let Qd=0;class fi{constructor(e,i,r,n,a="bi",s="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",p="",h="#000000",f="auto",d="center",m="center",x="wrap_none",b="default",v="format_none",w=!1){oe(this,"id"),oe(this,"left"),oe(this,"top"),oe(this,"right"),oe(this,"bottom"),oe(this,"xloc"),oe(this,"extend"),oe(this,"border_color"),oe(this,"border_style"),oe(this,"border_width"),oe(this,"bgcolor"),oe(this,"text"),oe(this,"text_color"),oe(this,"text_size"),oe(this,"text_halign"),oe(this,"text_valign"),oe(this,"text_wrap"),oe(this,"text_font_family"),oe(this,"text_formatting"),oe(this,"force_overlay"),oe(this,"_deleted"),oe(this,"_helper"),oe(this,"_createdAtBar",-1),this.id=Qd++,this.left=e,this.top=i,this.right=r,this.bottom=n,this.xloc=a,this.extend=s,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=u,this.text=p,this.text_color=h,this.text_size=f,this.text_halign=d,this.text_valign=m,this.text_wrap=x,this.text_font_family=b,this.text_formatting=v,this.force_overlay=w,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,i){this._helper?this._helper.set_lefttop(this,e,i):this._deleted||(this.left=e,this.top=i)}set_rightbottom(e,i){this._helper?this._helper.set_rightbottom(this,e,i):this._deleted||(this.right=e,this.bottom=i)}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,i,r){this._helper?this._helper.set_xloc(this,e,i,r):this._deleted||(this.left=e,this.right=i,this.xloc=r)}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 fi(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)}}var Vs=Object.defineProperty,Zd=Object.getOwnPropertyDescriptor,Jd=(t,e,i)=>e in t?Vs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,se=(t,e,i,r)=>{for(var n=r>1?void 0:r?Zd(e,i):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(r?s(e,i,n):s(n))||n);return r&&n&&Vs(e,i,n),n},em=(t,e,i)=>Jd(t,typeof e!="symbol"?e+"":e,i);const tm=[["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"]],im={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"};class ie{constructor(e){this.context=e,em(this,"_boxes",[])}param(e,i=0,r){return y.from(e).get(i)}_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();const e=this.context.marketData[0]?.openTime||0,i=this._boxes.filter(a=>!a._deleted).map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:r,options:{style:"drawing_box"}}],n.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:n,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e){const i=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),r=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return i?{x:e.index,xloc:"bi"}:r?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof $e?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r||i}_createBox(e,i,r,n,a="bi",s="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",p="",h="#000000",f="auto",d="center",m="center",x="wrap_none",b="default",v="format_none",w=!1){const S=new fi(e,i,r,n,a,this._resolve(s),this._resolveColor(o,"#2962ff"),this._resolve(l)||"style_solid",this._resolve(c)??1,this._resolveColor(u,"#2962ff"),this._resolve(p)||"",this._resolveColor(h,"#000000"),this._resolve(f)||"auto",this._resolve(d)||"center",this._resolve(m)||"center",this._resolve(x)||"wrap_none",this._resolve(b)||"default",this._resolve(v)||"format_none",w);return S._helper=this,S._createdAtBar=this.context.idx,this._boxes.push(S),this._enforceMaxCount(),this.syncToPlot(),S}_enforceMaxCount(){const e=this.context.indicator?.max_boxes_count??50,i=this._boxes.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const a of this._boxes){if(n>=r)break;a._deleted||(a._deleted=!0,n++)}}}new(...e){const i=re(e,tm,im);let r,n,a,s,o=i.xloc;if(i.top_left instanceof Ae){const l=i.top_left,c=i.bottom_right,u=this._resolvePoint(l);r=u.x,n=l.price,o=o||u.xloc,c instanceof Ae?(a=this._resolvePoint(c).x,s=c.price):(a=0,s=NaN)}else r=this._resolve(i.left),n=this._resolve(i.top),a=this._resolve(i.right),s=this._resolve(i.bottom);return this._createBox(r,n,a,s,o,i.extend,i.border_color,i.border_style,i.border_width,i.bgcolor,i.text,i.text_color,i.text_size,i.text_halign,i.text_valign,i.text_wrap,i.text_font_family,void 0,i.force_overlay)}any(...e){if(e.length===1){const i=e[0];if(i==null||i instanceof $e||typeof i=="number"&&isNaN(i))return null;if(i instanceof fi)return i;if(i instanceof y){const r=i.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof fi)return r}return null}return this.new(...e)}set_left(e,i){e&&!e._deleted&&(e.left=this._resolve(i))}set_right(e,i){e&&!e._deleted&&(e.right=this._resolve(i))}set_top(e,i){e&&!e._deleted&&(e.top=this._resolve(i))}set_bottom(e,i){e&&!e._deleted&&(e.bottom=this._resolve(i))}set_lefttop(e,i,r){e&&!e._deleted&&(e.left=this._resolve(i),e.top=this._resolve(r))}set_rightbottom(e,i,r){e&&!e._deleted&&(e.right=this._resolve(i),e.bottom=this._resolve(r))}set_top_left_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.left=r.x,e.top=i.price,e.xloc=r.xloc}}set_bottom_right_point(e,i){if(e&&!e._deleted&&i){const r=this._resolvePoint(i);e.right=r.x,e.bottom=i.price,e.xloc=r.xloc}}set_xloc(e,i,r,n){e&&!e._deleted&&(e.left=this._resolve(i),e.right=this._resolve(r),e.xloc=this._resolve(n))}set_bgcolor(e,i){e&&!e._deleted&&(e.bgcolor=this._resolve(i))}set_border_color(e,i){e&&!e._deleted&&(e.border_color=this._resolve(i))}set_border_width(e,i){e&&!e._deleted&&(e.border_width=this._resolve(i)??1)}set_border_style(e,i){e&&!e._deleted&&(e.border_style=this._resolve(i))}set_extend(e,i){e&&!e._deleted&&(e.extend=this._resolve(i))}set_text(e,i){e&&!e._deleted&&(e.text=this._resolve(i)||"")}set_text_color(e,i){e&&!e._deleted&&(e.text_color=this._resolve(i))}set_text_size(e,i){e&&!e._deleted&&(e.text_size=this._resolve(i))}set_text_halign(e,i){e&&!e._deleted&&(e.text_halign=this._resolve(i))}set_text_valign(e,i){e&&!e._deleted&&(e.text_valign=this._resolve(i))}set_text_wrap(e,i){e&&!e._deleted&&(e.text_wrap=this._resolve(i))}set_text_font_family(e,i){e&&!e._deleted&&(e.text_font_family=this._resolve(i))}set_text_formatting(e,i){e&&!e._deleted&&(e.text_formatting=this._resolve(i))}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;const i=e.copy();return i._helper=this,i._createdAtBar=this.context.idx,this._boxes.push(i),this._enforceMaxCount(),this.syncToPlot(),i}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(i=>i._createdAtBar<e),this.syncToPlot()}}se([C],ie.prototype,"new",1),se([C],ie.prototype,"set_left",1),se([C],ie.prototype,"set_right",1),se([C],ie.prototype,"set_top",1),se([C],ie.prototype,"set_bottom",1),se([C],ie.prototype,"set_lefttop",1),se([C],ie.prototype,"set_rightbottom",1),se([C],ie.prototype,"set_top_left_point",1),se([C],ie.prototype,"set_bottom_right_point",1),se([C],ie.prototype,"set_xloc",1),se([C],ie.prototype,"set_bgcolor",1),se([C],ie.prototype,"set_border_color",1),se([C],ie.prototype,"set_border_width",1),se([C],ie.prototype,"set_border_style",1),se([C],ie.prototype,"set_extend",1),se([C],ie.prototype,"set_text",1),se([C],ie.prototype,"set_text_color",1),se([C],ie.prototype,"set_text_size",1),se([C],ie.prototype,"set_text_halign",1),se([C],ie.prototype,"set_text_valign",1),se([C],ie.prototype,"set_text_wrap",1),se([C],ie.prototype,"set_text_font_family",1),se([C],ie.prototype,"set_text_formatting",1),se([C],ie.prototype,"copy",1),se([C],ie.prototype,"delete",1);var rm=Object.defineProperty,nm=(t,e,i)=>e in t?rm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Xt=(t,e,i)=>nm(t,typeof e!="symbol"?e+"":e,i);let sm=0;class xn{constructor(e,i,r){Xt(this,"id"),Xt(this,"line1"),Xt(this,"line2"),Xt(this,"color"),Xt(this,"_deleted"),Xt(this,"_createdAtBar",-1),this.id=sm++,this.line1=e,this.line2=i,this.color=r,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(){const e=r=>r?{id:r.id,x1:r.x1,y1:r.y1,x2:r.x2,y2:r.y2,xloc:r.xloc,extend:r.extend,color:r.color,style:r.style,width:r.width,_deleted:r._deleted}:null,i=!!(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:i,_deleted:this._deleted}}}var js=Object.defineProperty,am=Object.getOwnPropertyDescriptor,om=(t,e,i)=>e in t?js(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,fr=(t,e,i,r)=>{for(var n=r>1?void 0:r?am(e,i):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(r?s(e,i,n):s(n))||n);return r&&n&&js(e,i,n),n},lm=(t,e,i)=>om(t,typeof e!="symbol"?e+"":e,i);class Oi{constructor(e){this.context=e,lm(this,"_linefills",[])}param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0,i=this._linefills.filter(a=>!a._deleted).map(a=>a.toPlotData()),r=i.filter(a=>!a.force_overlay),n=i.filter(a=>a.force_overlay);this.context.plots.__linefills__.data=[{time:e,value:r,options:{style:"linefill"}}],n.length>0?this.context.plots.__linefills_overlay__={title:"__linefills_overlay__",data:[{time:e,value:n,options:{style:"linefill"}}],options:{style:"linefill",overlay:!0}}:delete this.context.plots.__linefills_overlay__}_resolve(e){return e==null?e:e instanceof $e?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){const i=this._resolve(e);return i==null?i:typeof i=="number"&&isNaN(i)?NaN:i}new(e,i,r){const n=this._resolve(e),a=this._resolve(i),s=r&&typeof r=="object"&&!Array.isArray(r)&&"color"in r?r.color:r,o=this._resolveColor(s);if(n&&a){const c=n.id,u=a.id;for(const p of this._linefills){if(p._deleted)continue;const h=p.line1?.id,f=p.line2?.id;if(h===c&&f===u||h===u&&f===c)return p.color=o,p._createdAtBar=this.context.idx,this.syncToPlot(),p}}const l=new xn(n,a,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),this.syncToPlot(),l}any(...e){if(e.length===1){const i=e[0];return i==null||i instanceof $e||typeof i=="number"&&isNaN(i)?null:i instanceof xn?i:null}return this.new(e[0],e[1],e[2])}set_color(e,i){e&&!e._deleted&&(e.color=this._resolveColor(i))}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(i=>i._createdAtBar<e),this.syncToPlot()}}fr([C],Oi.prototype,"new",1),fr([C],Oi.prototype,"set_color",1),fr([C],Oi.prototype,"delete",1);var cm=Object.defineProperty,um=(t,e,i)=>e in t?cm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ue=(t,e,i)=>um(t,typeof e!="symbol"?e+"":e,i);let hm=0;class dr{constructor(e,i=!1,r=!1,n="bi",a="#2962ff",s="",o="style_solid",l=1,c=!1){Ue(this,"id"),Ue(this,"points"),Ue(this,"curved"),Ue(this,"closed"),Ue(this,"xloc"),Ue(this,"line_color"),Ue(this,"fill_color"),Ue(this,"line_style"),Ue(this,"line_width"),Ue(this,"force_overlay"),Ue(this,"_deleted"),Ue(this,"_createdAtBar",-1),this.id=hm++,this.points=e,this.curved=i,this.closed=r,this.xloc=n,this.line_color=a,this.fill_color=s,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}}}var Ls=Object.defineProperty,pm=Object.getOwnPropertyDescriptor,fm=(t,e,i)=>e in t?Ls(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,bn=(t,e,i,r)=>{for(var n=r>1?void 0:r?pm(e,i):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(r?s(e,i,n):s(n))||n);return r&&n&&Ls(e,i,n),n},dm=(t,e,i)=>fm(t,typeof e!="symbol"?e+"":e,i);class kr{constructor(e){this.context=e,dm(this,"_polylines",[])}param(e,i=0,r){return y.from(e).get(i)}_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();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__polylines__.data=[{time:e,value:this._polylines.filter(i=>!i._deleted).map(i=>i.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof $e?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,i){const r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r||i}_extractPoints(e){let i=this._resolve(e);const r=i&&i.array?i.array:i;return Array.isArray(r)?r.filter(n=>n instanceof Ae):[]}new(...e){let i,r=!1,n=!1,a="bi",s="#2962ff",o="",l="style_solid",c=1,u=!1;const p=(b,v)=>Object.prototype.hasOwnProperty.call(b,v),h=b=>{p(b,"curved")&&(r=b.curved),p(b,"closed")&&(n=b.closed),p(b,"xloc")&&(a=b.xloc),p(b,"line_color")&&(s=b.line_color),p(b,"fill_color")&&(o=b.fill_color),p(b,"line_style")&&(l=b.line_style),p(b,"line_width")&&(c=b.line_width),p(b,"force_overlay")&&(u=b.force_overlay)},f=e.length>=1?e[e.length-1]:null,d=e.length>=2&&f&&typeof f=="object"&&!Array.isArray(f)&&!(f instanceof y)&&!(f instanceof Ae);if(e.length===1&&f&&typeof f=="object"&&!Array.isArray(f)&&"points"in f)i=f.points,h(f);else{const b=d?e.slice(0,-1):e;i=b[0],b.length>1&&(r=b[1]),b.length>2&&(n=b[2]),b.length>3&&(a=b[3]),b.length>4&&(s=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]),d&&h(f)}const m=this._extractPoints(i),x=new dr(m,this._resolve(r)??!1,this._resolve(n)??!1,this._resolve(a)||"bi",this._resolveColor(s,"#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(),this.syncToPlot(),x}_enforceMaxCount(){const e=this.context.indicator?.max_polylines_count??50,i=this._polylines.filter(r=>!r._deleted);if(i.length>e){const r=i.length-e;let n=0;for(const a of this._polylines){if(n>=r)break;a._deleted||(a._deleted=!0,n++)}}}any(...e){if(e.length===1){const i=e[0];if(i==null||i instanceof $e||typeof i=="number"&&isNaN(i))return null;if(i instanceof dr)return i;if(i instanceof y){const r=i.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof dr)return r}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(i=>i._createdAtBar<e),this.syncToPlot()}}bn([C],kr.prototype,"new",1),bn([C],kr.prototype,"delete",1);var mm=Object.defineProperty,ym=(t,e,i)=>e in t?mm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Re=(t,e,i)=>ym(t,typeof e!="symbol"?e+"":e,i);let _m=0;class vn{constructor(e="top_right",i=1,r=1,n="",a="",s=0,o="",l=0,c=!1){Re(this,"id"),Re(this,"position"),Re(this,"columns"),Re(this,"rows"),Re(this,"bgcolor"),Re(this,"frame_color"),Re(this,"frame_width"),Re(this,"border_color"),Re(this,"border_width"),Re(this,"force_overlay"),Re(this,"_deleted"),Re(this,"cells"),Re(this,"merges"),Re(this,"_helper"),this.id=_m++,this.position=e,this.columns=i,this.rows=r,this.bgcolor=n,this.frame_color=a,this.frame_width=s,this.border_color=o,this.border_width=l,this.force_overlay=c,this._deleted=!1,this.merges=[],this.cells=[];for(let u=0;u<r;u++){this.cells[u]=[];for(let p=0;p<i;p++)this.cells[u][p]=null}}delete(){this._deleted=!0}toPlotData(){const e=this.cells.map(i=>i.map(r=>r?{...r}: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(i=>({...i}))}}setCell(e,i,r){if(i<0||i>=this.rows||e<0||e>=this.columns)return;const n=this.cells[i][e];if(n&&n._merged&&n._merge_parent){const[s,o]=n._merge_parent;if(s===e&&o===i)n._merged=!1,n._merge_parent=void 0;else{this.setCell(s,o,r);return}}const a=n||this._defaultCell();Object.assign(a,r),this.cells[i][e]=a}getCell(e,i){return i<0||i>=this.rows||e<0||e>=this.columns?null:this.cells[i][e]}clearCell(e,i){i<0||i>=this.rows||e<0||e>=this.columns||(this.cells[i][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}}}var Bs=Object.defineProperty,gm=Object.getOwnPropertyDescriptor,xm=(t,e,i)=>e in t?Bs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ue=(t,e,i,r)=>{for(var n=r>1?void 0:r?gm(e,i):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(r?s(e,i,n):s(n))||n);return r&&n&&Bs(e,i,n),n},bm=(t,e,i)=>xm(t,typeof e!="symbol"?e+"":e,i);class ce{constructor(e){this.context=e,bm(this,"_tables",[])}param(e,i=0,r){return y.from(e).get(i)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();const e=this.context.marketData[0]?.openTime||0;this.context.plots.__tables__.data=[{time:e,value:this._tables.filter(i=>!i._deleted).map(i=>i.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 i="top_right",r=1,n=1,a="",s="",o=0,l="",c=0,u=!1;const p=e[e.length-1];if(p&&typeof p=="object"&&!Array.isArray(p)&&("bgcolor"in p||"frame_color"in p||"border_color"in p||"position"in p||"columns"in p||"rows"in p)){const f=p,d=e.slice(0,-1);i=d[0]??f.position??i,r=d[1]??f.columns??r,n=d[2]??f.rows??n,a=f.bgcolor??a,s=f.frame_color??s,o=f.frame_width??o,l=f.border_color??l,c=f.border_width??c,u=f.force_overlay??u}else i=e[0]??i,r=e[1]??r,n=e[2]??n,a=e[3]??a,s=e[4]??s,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u;const h=new vn(this._resolve(i)||"top_right",this._resolve(r)||1,this._resolve(n)||1,this._resolve(a)||"",this._resolve(s)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(u)??!1);return h._setHelper(this),this._tables.push(h),this.syncToPlot(),h}any(...e){if(e.length===1){const i=e[0];return i==null||typeof i=="object"&&"__value"in i||typeof i=="number"&&isNaN(i)?null:i instanceof vn?i:null}return this.new(...e)}cell(...e){let i,r,n,a="",s=0,o=0,l="#000000",c="center",u="center",p="normal",h="",f="",d="default";const 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)){const w=m,S=e.slice(0,-1);i=S[0],r=S.length>1?S[1]:w.column??0,n=S.length>2?S[2]:w.row??0,a=S[3]??w.text??a,s=S[4]??w.width??s,o=S[5]??w.height??o,l=S[6]??w.text_color??l,c=S[7]??w.text_halign??c,u=S[8]??w.text_valign??u,p=S[9]??w.text_size??p,h=S[10]??w.bgcolor??h,f=S[11]??w.tooltip??f,d=S[12]??w.text_font_family??d}else i=e[0],r=e[1]??0,n=e[2]??0,a=e[3]??a,s=e[4]??s,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u,p=e[9]??p,h=e[10]??h,f=e[11]??f,d=e[12]??d;const x=this._resolve(i);if(!x||x._deleted)return;const b=this._resolve(r)??0,v=this._resolve(n)??0;x.setCell(b,v,{text:this._resolveText(this._resolve(a)),width:this._resolve(s)||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(p)||"normal",bgcolor:this._resolve(h)||"",tooltip:this._resolveText(this._resolve(f)),text_font_family:this._resolve(d)||"default"}),this.syncToPlot()}delete(e){e&&(e._deleted=!0)}clear(...e){let i,r,n,a,s;const 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)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,n=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:r),s=f.end_row??(e.length>5?e[4]:n)}else i=e[0],r=e[1]??0,n=e[2]??0,a=e[3]??r,s=e[4]??n;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,u=this._resolve(n)??0,p=this._resolve(a)??c,h=this._resolve(s)??u;for(let f=u;f<=h;f++)for(let d=c;d<=p;d++)l.clearCell(d,f);this.syncToPlot()}merge_cells(...e){let i,r,n,a,s;const 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)){const f=o;i=e[0],r=e.length>2?e[1]:f.start_column??0,n=e.length>3?e[2]:f.start_row??0,a=f.end_column??(e.length>4?e[3]:0),s=f.end_row??(e.length>5?e[4]:0)}else i=e[0],r=e[1]??0,n=e[2]??0,a=e[3]??0,s=e[4]??0;const l=this._resolve(i);if(!l||l._deleted)return;const c=this._resolve(r)??0,u=this._resolve(n)??0,p=this._resolve(a)??0,h=this._resolve(s)??0;for(let f=u;f<=h;f++)for(let d=c;d<=p;d++)f===u&&d===c||l.setCell(d,f,{_merged:!0,_merge_parent:[c,u]});l.merges.push({startCol:c,startRow:u,endCol:p,endRow:h}),this.syncToPlot()}cell_set_text(e,i,r,n){this._setCellProp(e,i,r,"text",n,!0)}cell_set_bgcolor(e,i,r,n){this._setCellProp(e,i,r,"bgcolor",n)}cell_set_text_color(e,i,r,n){this._setCellProp(e,i,r,"text_color",n)}cell_set_text_size(e,i,r,n){this._setCellProp(e,i,r,"text_size",n)}cell_set_height(e,i,r,n){this._setCellProp(e,i,r,"height",n)}cell_set_width(e,i,r,n){this._setCellProp(e,i,r,"width",n)}cell_set_tooltip(e,i,r,n){this._setCellProp(e,i,r,"tooltip",n,!0)}cell_set_text_halign(e,i,r,n){this._setCellProp(e,i,r,"text_halign",n)}cell_set_text_valign(e,i,r,n){this._setCellProp(e,i,r,"text_valign",n)}cell_set_text_font_family(e,i,r,n){this._setCellProp(e,i,r,"text_font_family",n)}set_position(e,i){const r=this._resolve(e);!r||r._deleted||(r.position=this._resolve(i)||r.position,this.syncToPlot())}set_bgcolor(e,i){const r=this._resolve(e);!r||r._deleted||(r.bgcolor=this._resolve(i)||"",this.syncToPlot())}set_border_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_color=this._resolve(i)||"",this.syncToPlot())}set_border_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.border_width=this._resolve(i)||0,this.syncToPlot())}set_frame_color(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_color=this._resolve(i)||"",this.syncToPlot())}set_frame_width(e,i){const r=this._resolve(e);!r||r._deleted||(r.frame_width=this._resolve(i)||0,this.syncToPlot())}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,i,r,n,a,s=!1){const o=this._resolve(e);if(!o||o._deleted)return;const l=this._resolve(i)??0,c=this._resolve(r)??0,u=this._resolve(a);o.setCell(l,c,{[n]:s?this._resolveText(u):u}),this.syncToPlot()}_resolveText(e){return e==null||e!==e?"":String(e)}}ue([C],ce.prototype,"new",1),ue([C],ce.prototype,"cell",1),ue([C],ce.prototype,"delete",1),ue([C],ce.prototype,"clear",1),ue([C],ce.prototype,"merge_cells",1),ue([C],ce.prototype,"cell_set_text",1),ue([C],ce.prototype,"cell_set_bgcolor",1),ue([C],ce.prototype,"cell_set_text_color",1),ue([C],ce.prototype,"cell_set_text_size",1),ue([C],ce.prototype,"cell_set_height",1),ue([C],ce.prototype,"cell_set_width",1),ue([C],ce.prototype,"cell_set_tooltip",1),ue([C],ce.prototype,"cell_set_text_halign",1),ue([C],ce.prototype,"cell_set_text_valign",1),ue([C],ce.prototype,"cell_set_text_font_family",1),ue([C],ce.prototype,"set_position",1),ue([C],ce.prototype,"set_bgcolor",1),ue([C],ce.prototype,"set_border_color",1),ue([C],ce.prototype,"set_border_width",1),ue([C],ce.prototype,"set_frame_color",1),ue([C],ce.prototype,"set_frame_width",1);class vm{constructor(e){this.context=e}param(e,i=0,r){return typeof e=="string"?e:y.from(e).get(i)}inherit(e,i){return this._coerce(i)}new(e,i,r,n,a,s){const o=this._coerce(e),l=this._coerce(i);return o?l?`${o}:${l}`:o:l}modify(e,i,r,n,a){return this._coerce(e)}standard(e){return e==null?this.context?.pine?.syminfo?.tickerid||this.context?.tickerId||"":this._coerce(e)}heikinashi(e){return this._coerce(e)}renko(e,i,r,n,a){return this._coerce(e)}kagi(e,i){return this._coerce(e)}linebreak(e,i){return this._coerce(e)}pointfigure(e,i,r,n,a){return this._coerce(e)}_coerce(e){if(e==null)return"";if(e instanceof y){const i=e.get(0);return i==null?"":String(i)}return typeof e=="number"&&isNaN(e)?"":String(e)}}var wm=Object.defineProperty,Sm=(t,e,i)=>e in t?wm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,z=(t,e,i)=>Sm(t,typeof e!="symbol"?e+"":e,i);const Tr=class $i{constructor({marketData:e,source:i,tickerId:r,timeframe:n,limit:a,sDate:s,eDate:o,fullContext:l,inputs:c}){z(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([])}),z(this,"indicator"),z(this,"cache",{}),z(this,"taState",{}),z(this,"strategy"),z(this,"isSecondaryContext",!1),z(this,"chartTimezone",null),z(this,"dataVersion",0),z(this,"__maxLoops",5e5),z(this,"NA",NaN),z(this,"warnings",[]),z(this,"alerts",[]),z(this,"_alertMode","realtime"),z(this,"_propOverrides",{}),z(this,"_execTick",0),z(this,"lang"),z(this,"length",0),z(this,"_drawingHelpers",[]),z(this,"pine"),z(this,"idx",0),z(this,"params",{}),z(this,"const",{}),z(this,"var",{}),z(this,"let",{}),z(this,"lctx",new Map),z(this,"result"),z(this,"plots",{}),z(this,"marketData"),z(this,"source"),z(this,"tickerId"),z(this,"timeframe",""),z(this,"limit"),z(this,"sDate"),z(this,"eDate"),z(this,"fullContext"),z(this,"viewportLeft"),z(this,"viewportRight"),z(this,"pineTSCode"),z(this,"inputs",{}),z(this,"_callStack",[]),z(this,"_pathStack",[]),this.marketData=e,this.source=i,this.tickerId=r,this.timeframe=n,this.limit=a,this.sDate=s,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};const u=new ks(this),p={Type:u.Type.bind(u),na:new $e,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),alert:new Is(this),error:u.error.bind(u),max_bars_back:u.max_bars_back.bind(u),timestamp:u.timestamp.bind(u),time:new cn(this,"openTime"),time_close:new cn(this,"closeTime"),dayofmonth:new wt(this,St.dayofmonth),dayofweek:new wt(this,St.dayofweek),hour:new wt(this,St.hour),minute:new wt(this,St.minute),month:new wt(this,St.month),second:new wt(this,St.second),weekofyear:new wt(this,St.weekofyear),year:new wt(this,St.year),bool:u.bool.bind(u),int:u.int.bind(u),float:u.float.bind(u),string:u.string.bind(u)},h=this;this.pine={input:new ou(this),ta:new bp(this),math:new Uu(this),request:new nh(this),array:new Qo(this),map:new pl(this),matrix:new pc(this),ticker:new vm(this),strategy:new Zf(this),syminfo:null,timeframe:new ud(this),barstate:new yc(this),get bar_index(){return h.data.bar_index},get last_bar_index(){return h.data.close.length-1},get last_bar_time(){const I=h.marketData;return Array.isArray(I)&&I.length>0?I[I.length-1].openTime:h.data.openTime.get(0)},get timenow(){return new Date().getTime()},get time_tradingday(){const I=y.from(h.data.closeTime).get(0);if(isNaN(I))return NaN;const V=h.pine?.syminfo?.timezone||"UTC",k=Vt(I,V);return Date.UTC(k.year,k.month-1,k.day,0,0,0)},get inputs(){return h.inputs},log:new td(this),str:new ad(this),...p,...ko};const f=p.dayofweek;Object.assign(f,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=f;const d=new yt(this),m=new Ds(this),x=new Rs(this);this.bindContextObject(d,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(d,["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");const b=new Md(this);this.pine.chart={param:b.param.bind(b),bg_color:b.bg_color.bind(b),fg_color:b.fg_color.bind(b),is_standard:b.is_standard.bind(b),is_heikinashi:b.is_heikinashi.bind(b),is_kagi:b.is_kagi.bind(b),is_linebreak:b.is_linebreak.bind(b),is_pnf:b.is_pnf.bind(b),is_range:b.is_range.bind(b),is_renko:b.is_renko.bind(b),point:b.point,get left_visible_bar_time(){if(h.viewportLeft!==void 0)return h.viewportLeft;const I=h.marketData;return Array.isArray(I)&&I.length>0?I[0].openTime:NaN},get right_visible_bar_time(){if(h.viewportRight!==void 0)return h.viewportRight;const I=h.marketData;return Array.isArray(I)&&I.length>0?I[I.length-1].openTime:NaN}};const v=new we(this);this.bindContextObject(v,["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:()=>v.all});const w=new Se(this);this.bindContextObject(w,["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:()=>w.all});const S=new ie(this);this.bindContextObject(S,["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:()=>S.all});const A=new Oi(this);this.bindContextObject(A,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>A.all});const N=new kr(this);this.bindContextObject(N,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>N.all});const P=new ce(this);this.bindContextObject(P,["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:()=>P.all}),this._drawingHelpers=[v,w,S,A,N,P];const j=new Mc(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,i){this.warnings.push({message:e,method:i,bar:this.idx})}rollbackDrawings(e){for(const i of this._drawingHelpers)i.rollbackFromBar(e)}bindContextObject(e,i,r=""){r&&!this.pine[r]&&(this.pine[r]={});const n=r?this.pine[r]:this.pine;for(const a of i)typeof e[a]=="function"?n[a]=e[a].bind(e):n[a]=e[a]}init(e,i,r=0){let n;return i instanceof y?n=i.get(0):Array.isArray(i)?Array.isArray(i[0])?n=i[0]:n=i[i.length-1+r]:n=i,e?e instanceof y?(e.data[e.data.length-1]=n,e):Array.isArray(e)?(e[e.length-1]=n,new y(e)):new y([n]):new y([n])}initVar(e,i){if(e)return e;if(typeof i=="function"&&(i=i()),i instanceof It){const n=i.__def__;for(const a in n)typeof i[a]=="function"&&(i[a]=i[a]())}let r;return i instanceof y?r=i.get(0):Array.isArray(i)?Array.isArray(i[0])?r=i[0]:r=this.precision(i[i.length-1]):r=this.precision(i),new y([r])}precision(e,i=10){const r=i===10?$i.PRECISION_EPSILON:10**i;return typeof e=="number"?Math.round(e*r)/r:e}param(e,i,r){return typeof e=="string"?e:e instanceof y?i?new y(e.data,e.offset+i):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[r]||(this.params[r]=[]),Array.isArray(e)?new y(e,i||0):(this.params[r].length===0?this.params[r].push(e):this.params[r][this.params[r].length-1]=e,new y(this.params[r],i||0)))}get(e,i){if(e instanceof y)return e.get(i);if(Array.isArray(e)){const r=e.length-1-i;return r<0||r>=e.length?NaN:e[r]}return e}set(e,i){if(e instanceof y){e.set(0,typeof i=="number"?this.precision(i):i);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=i:e.push(i);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){const i=this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:"",r=i?i+"|"+e:e;this._callStack.push(e),this._pathStack.push(r)}popId(){this._callStack.pop(),this._pathStack.pop()}peekId(){return this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:""}peekCtx(){const e=this.peekId();if(!e)return this;let i=this.lctx.get(e);return i||(i={id:e,let:{},const:{},var:{}},this.lctx.set(e,i)),i}call(e,i,...r){this.pushId(i);try{return e(...r)}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,i){const r=`${e}->${i}`;$i._deprecationWarningsShown.has(r)||($i._deprecationWarningsShown.add(r),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,i):console.warn(`\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${i} instead. This will be removed in a future version.\x1B[0m`))}};z(Tr,"_deprecationWarningsShown",new Set),z(Tr,"PRECISION_EPSILON",10**10);let wn=Tr;var Em=[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],Fs=[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],Nm="\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",Ws="\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",mr={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"},yr="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",Cm={5:yr,"5module":yr+" export import",6:yr+" const class extends export import super"},Us=/^in(stanceof)?$/,Im=new RegExp("["+Ws+"]"),km=new RegExp("["+Ws+Nm+"]");function Ar(t,e){for(var i=65536,r=0;r<e.length;r+=2){if(i+=e[r],i>t)return!1;if(i+=e[r+1],i>=t)return!0}return!1}function ht(t,e){return t<65?t===36:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&Im.test(String.fromCharCode(t)):e===!1?!1:Ar(t,Fs)}function kt(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&&km.test(String.fromCharCode(t)):e===!1?!1:Ar(t,Fs)||Ar(t,Em)}var X=function(e,i){i===void 0&&(i={}),this.label=e,this.keyword=i.keyword,this.beforeExpr=!!i.beforeExpr,this.startsExpr=!!i.startsExpr,this.isLoop=!!i.isLoop,this.isAssign=!!i.isAssign,this.prefix=!!i.prefix,this.postfix=!!i.postfix,this.binop=i.binop||null,this.updateContext=null};function qe(t,e){return new X(t,{beforeExpr:!0,binop:e})}var ze={beforeExpr:!0},Oe={startsExpr:!0},Ur={};function G(t,e){return e===void 0&&(e={}),e.keyword=t,Ur[t]=new X(t,e)}var _={num:new X("num",Oe),regexp:new X("regexp",Oe),string:new X("string",Oe),name:new X("name",Oe),privateId:new X("privateId",Oe),eof:new X("eof"),bracketL:new X("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new X("]"),braceL:new X("{",{beforeExpr:!0,startsExpr:!0}),braceR:new X("}"),parenL:new X("(",{beforeExpr:!0,startsExpr:!0}),parenR:new X(")"),comma:new X(",",ze),semi:new X(";",ze),colon:new X(":",ze),dot:new X("."),question:new X("?",ze),questionDot:new X("?."),arrow:new X("=>",ze),template:new X("template"),invalidTemplate:new X("invalidTemplate"),ellipsis:new X("...",ze),backQuote:new X("`",Oe),dollarBraceL:new X("${",{beforeExpr:!0,startsExpr:!0}),eq:new X("=",{beforeExpr:!0,isAssign:!0}),assign:new X("_=",{beforeExpr:!0,isAssign:!0}),incDec:new X("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new X("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:qe("||",1),logicalAND:qe("&&",2),bitwiseOR:qe("|",3),bitwiseXOR:qe("^",4),bitwiseAND:qe("&",5),equality:qe("==/!=/===/!==",6),relational:qe("</>/<=/>=",7),bitShift:qe("<</>>/>>>",8),plusMin:new X("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:qe("%",10),star:qe("*",10),slash:qe("/",10),starstar:new X("**",{beforeExpr:!0}),coalesce:qe("??",1),_break:G("break"),_case:G("case",ze),_catch:G("catch"),_continue:G("continue"),_debugger:G("debugger"),_default:G("default",ze),_do:G("do",{isLoop:!0,beforeExpr:!0}),_else:G("else",ze),_finally:G("finally"),_for:G("for",{isLoop:!0}),_function:G("function",Oe),_if:G("if"),_return:G("return",ze),_switch:G("switch"),_throw:G("throw",ze),_try:G("try"),_var:G("var"),_const:G("const"),_while:G("while",{isLoop:!0}),_with:G("with"),_new:G("new",{beforeExpr:!0,startsExpr:!0}),_this:G("this",Oe),_super:G("super",Oe),_class:G("class",Oe),_extends:G("extends",ze),_export:G("export"),_import:G("import",Oe),_null:G("null",Oe),_true:G("true",Oe),_false:G("false",Oe),_in:G("in",{beforeExpr:!0,binop:7}),_instanceof:G("instanceof",{beforeExpr:!0,binop:7}),_typeof:G("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:G("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:G("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},Ve=/\r\n?|\n|\u2028|\u2029/,Tm=new RegExp(Ve.source,"g");function ri(t){return t===10||t===13||t===8232||t===8233}function qs(t,e,i){i===void 0&&(i=t.length);for(var r=e;r<i;r++){var n=t.charCodeAt(r);if(ri(n))return r<i-1&&n===13&&t.charCodeAt(r+1)===10?r+2:r+1}return-1}var zs=/[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/,Ie=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,Ks=Object.prototype,Am=Ks.hasOwnProperty,Pm=Ks.toString,ni=Object.hasOwn||(function(t,e){return Am.call(t,e)}),Sn=Array.isArray||(function(t){return Pm.call(t)==="[object Array]"}),En=Object.create(null);function Ct(t){return En[t]||(En[t]=new RegExp("^(?:"+t.replace(/ /g,"|")+")$"))}function xt(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(t&1023)+56320))}var Mm=/(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/,xi=function(e,i){this.line=e,this.column=i};xi.prototype.offset=function(e){return new xi(this.line,this.column+e)};var ir=function(e,i,r){this.start=i,this.end=r,e.sourceFile!==null&&(this.source=e.sourceFile)};function Hs(t,e){for(var i=1,r=0;;){var n=qs(t,r,e);if(n<0)return new xi(i,e-r);++i,r=n}}var Pr={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},Nn=!1;function Dm(t){var e={};for(var i in Pr)e[i]=t&&ni(t,i)?t[i]:Pr[i];if(e.ecmaVersion==="latest"?e.ecmaVersion=1e8:e.ecmaVersion==null?(!Nn&&typeof console=="object"&&console.warn&&(Nn=!0,console.warn(`Since Acorn 8.0.0, options.ecmaVersion is required.
3
+ Defaulting 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),Sn(e.onToken)){var r=e.onToken;e.onToken=function(n){return r.push(n)}}if(Sn(e.onComment)&&(e.onComment=Rm(e,e.onComment)),e.sourceType==="commonjs"&&e.allowAwaitOutsideFunction)throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs");return e}function Rm(t,e){return function(i,r,n,a,s,o){var l={type:i?"Block":"Line",value:r,start:n,end:a};t.locations&&(l.loc=new ir(this,s,o)),t.ranges&&(l.range=[n,a]),e.push(l)}}var jt=1,Lt=2,qr=4,Gs=8,zr=16,Ys=32,rr=64,Xs=128,Bt=256,wi=512,Qs=1024,nr=jt|Lt|Bt;function Kr(t,e){return Lt|(t?qr:0)|(e?Gs:0)}var Ki=0,Hr=1,vt=2,Zs=3,Js=4,ea=5,ye=function(e,i,r){this.options=e=Dm(e),this.sourceFile=e.sourceFile,this.keywords=Ct(Cm[e.ecmaVersion>=6?6:e.sourceType==="module"?"5module":5]);var n="";e.allowReserved!==!0&&(n=mr[e.ecmaVersion>=6?6:e.ecmaVersion===5?5:3],e.sourceType==="module"&&(n+=" await")),this.reservedWords=Ct(n);var a=(n?n+" ":"")+mr.strict;this.reservedWordsStrict=Ct(a),this.reservedWordsStrictBind=Ct(a+" "+mr.strictBind),this.input=String(i),this.containsEsc=!1,r?(this.pos=r,this.lineStart=this.input.lastIndexOf(`
4
+ `,r-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(Ve).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=_.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=e.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&&e.allowHashBang&&this.input.slice(0,2)==="#!"&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(this.options.sourceType==="commonjs"?Lt:jt),this.regexpState=null,this.privateNameStack=[]},Xe={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}};ye.prototype.parse=function(){var e=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(e)};Xe.inFunction.get=function(){return(this.currentVarScope().flags&Lt)>0};Xe.inGenerator.get=function(){return(this.currentVarScope().flags&Gs)>0};Xe.inAsync.get=function(){return(this.currentVarScope().flags&qr)>0};Xe.canAwait.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],i=e.flags;if(i&(Bt|wi))return!1;if(i&Lt)return(i&qr)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction};Xe.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&jt)};Xe.allowSuper.get=function(){var t=this.currentThisScope(),e=t.flags;return(e&rr)>0||this.options.allowSuperOutsideMethod};Xe.allowDirectSuper.get=function(){return(this.currentThisScope().flags&Xs)>0};Xe.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())};Xe.allowNewDotTarget.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],i=e.flags;if(i&(Bt|wi)||i&Lt&&!(i&zr))return!0}return!1};Xe.allowUsing.get=function(){var t=this.currentScope(),e=t.flags;return!(e&Qs||!this.inModule&&e&jt)};Xe.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&Bt)>0};ye.extend=function(){for(var e=[],i=arguments.length;i--;)e[i]=arguments[i];for(var r=this,n=0;n<e.length;n++)r=e[n](r);return r};ye.parse=function(e,i){return new this(i,e).parse()};ye.parseExpressionAt=function(e,i,r){var n=new this(r,e,i);return n.nextToken(),n.parseExpression()};ye.tokenizer=function(e,i){return new this(i,e)};Object.defineProperties(ye.prototype,Xe);var Me=ye.prototype,Om=/^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;Me.strictDirective=function(t){if(this.options.ecmaVersion<5)return!1;for(;;){Ie.lastIndex=t,t+=Ie.exec(this.input)[0].length;var e=Om.exec(this.input.slice(t));if(!e)return!1;if((e[1]||e[2])==="use strict"){Ie.lastIndex=t+e[0].length;var i=Ie.exec(this.input),r=i.index+i[0].length,n=this.input.charAt(r);return n===";"||n==="}"||Ve.test(i[0])&&!(/[(`.[+\-/*%<>=,?^&]/.test(n)||n==="!"&&this.input.charAt(r+1)==="=")}t+=e[0].length,Ie.lastIndex=t,t+=Ie.exec(this.input)[0].length,this.input[t]===";"&&t++}};Me.eat=function(t){return this.type===t?(this.next(),!0):!1};Me.isContextual=function(t){return this.type===_.name&&this.value===t&&!this.containsEsc};Me.eatContextual=function(t){return this.isContextual(t)?(this.next(),!0):!1};Me.expectContextual=function(t){this.eatContextual(t)||this.unexpected()};Me.canInsertSemicolon=function(){return this.type===_.eof||this.type===_.braceR||Ve.test(this.input.slice(this.lastTokEnd,this.start))};Me.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0};Me.semicolon=function(){!this.eat(_.semi)&&!this.insertSemicolon()&&this.unexpected()};Me.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0};Me.expect=function(t){this.eat(t)||this.unexpected()};Me.unexpected=function(t){this.raise(t??this.start,"Unexpected token")};var sr=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};Me.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element");var i=e?t.parenthesizedAssign:t.parenthesizedBind;i>-1&&this.raiseRecoverable(i,e?"Assigning to rvalue":"Parenthesized pattern")}};Me.checkExpressionErrors=function(t,e){if(!t)return!1;var i=t.shorthandAssign,r=t.doubleProto;if(!e)return i>=0||r>=0;i>=0&&this.raise(i,"Shorthand property assignments are valid only in destructuring patterns"),r>=0&&this.raiseRecoverable(r,"Redefinition of __proto__ property")};Me.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")};Me.isSimpleAssignTarget=function(t){return t.type==="ParenthesizedExpression"?this.isSimpleAssignTarget(t.expression):t.type==="Identifier"||t.type==="MemberExpression"};var $=ye.prototype;$.parseTopLevel=function(t){var e=Object.create(null);for(t.body||(t.body=[]);this.type!==_.eof;){var i=this.parseStatement(null,!0,e);t.body.push(i)}if(this.inModule)for(var r=0,n=Object.keys(this.undefinedExports);r<n.length;r+=1){var a=n[r];this.raiseRecoverable(this.undefinedExports[a].start,"Export '"+a+"' 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 Gr={kind:"loop"},$m={kind:"switch"};$.isLet=function(t){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;Ie.lastIndex=this.pos;var e=Ie.exec(this.input),i=this.pos+e[0].length,r=this.fullCharCodeAt(i);if(r===91||r===92)return!0;if(t)return!1;if(r===123)return!0;if(ht(r)){var n=i;do i+=r<=65535?1:2;while(kt(r=this.fullCharCodeAt(i)));if(r===92)return!0;var a=this.input.slice(n,i);if(!Us.test(a))return!0}return!1};$.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;Ie.lastIndex=this.pos;var t=Ie.exec(this.input),e=this.pos+t[0].length,i;return!Ve.test(this.input.slice(this.pos,e))&&this.input.slice(e,e+8)==="function"&&(e+8===this.input.length||!(kt(i=this.fullCharCodeAt(e+8))||i===92))};$.isUsingKeyword=function(t,e){if(this.options.ecmaVersion<17||!this.isContextual(t?"await":"using"))return!1;Ie.lastIndex=this.pos;var i=Ie.exec(this.input),r=this.pos+i[0].length;if(Ve.test(this.input.slice(this.pos,r)))return!1;if(t){var n=r+5,a;if(this.input.slice(r,n)!=="using"||n===this.input.length||kt(a=this.fullCharCodeAt(n))||a===92)return!1;Ie.lastIndex=n;var s=Ie.exec(this.input);if(r=n+s[0].length,s&&Ve.test(this.input.slice(n,r)))return!1}var o=this.fullCharCodeAt(r);if(!ht(o)&&o!==92)return!1;var l=r;do r+=o<=65535?1:2;while(kt(o=this.fullCharCodeAt(r)));if(o===92)return!0;var c=this.input.slice(l,r);return!(Us.test(c)||e&&c==="of")};$.isAwaitUsing=function(t){return this.isUsingKeyword(!0,t)};$.isUsing=function(t){return this.isUsingKeyword(!1,t)};$.parseStatement=function(t,e,i){var r=this.type,n=this.startNode(),a;switch(this.isLet(t)&&(r=_._var,a="let"),r){case _._break:case _._continue:return this.parseBreakContinueStatement(n,r.keyword);case _._debugger:return this.parseDebuggerStatement(n);case _._do:return this.parseDoStatement(n);case _._for:return this.parseForStatement(n);case _._function:return t&&(this.strict||t!=="if"&&t!=="label")&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(n,!1,!t);case _._class:return t&&this.unexpected(),this.parseClass(n,!0);case _._if:return this.parseIfStatement(n);case _._return:return this.parseReturnStatement(n);case _._switch:return this.parseSwitchStatement(n);case _._throw:return this.parseThrowStatement(n);case _._try:return this.parseTryStatement(n);case _._const:case _._var:return a=a||this.value,t&&a!=="var"&&this.unexpected(),this.parseVarStatement(n,a);case _._while:return this.parseWhileStatement(n);case _._with:return this.parseWithStatement(n);case _.braceL:return this.parseBlock(!0,n);case _.semi:return this.parseEmptyStatement(n);case _._export:case _._import:if(this.options.ecmaVersion>10&&r===_._import){Ie.lastIndex=this.pos;var s=Ie.exec(this.input),o=this.pos+s[0].length,l=this.input.charCodeAt(o);if(l===40||l===46)return this.parseExpressionStatement(n,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'")),r===_._import?this.parseImport(n):this.parseExport(n,i);default:if(this.isAsyncFunction())return t&&this.unexpected(),this.next(),this.parseFunctionStatement(n,!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(n,!1,c),this.semicolon(),this.finishNode(n,"VariableDeclaration");var u=this.value,p=this.parseExpression();return r===_.name&&p.type==="Identifier"&&this.eat(_.colon)?this.parseLabeledStatement(n,u,p,t):this.parseExpressionStatement(n,p)}};$.parseBreakContinueStatement=function(t,e){var i=e==="break";this.next(),this.eat(_.semi)||this.insertSemicolon()?t.label=null:this.type!==_.name?this.unexpected():(t.label=this.parseIdent(),this.semicolon());for(var r=0;r<this.labels.length;++r){var n=this.labels[r];if((t.label==null||n.name===t.label.name)&&(n.kind!=null&&(i||n.kind==="loop")||t.label&&i))break}return r===this.labels.length&&this.raise(t.start,"Unsyntactic "+e),this.finishNode(t,i?"BreakStatement":"ContinueStatement")};$.parseDebuggerStatement=function(t){return this.next(),this.semicolon(),this.finishNode(t,"DebuggerStatement")};$.parseDoStatement=function(t){return this.next(),this.labels.push(Gr),t.body=this.parseStatement("do"),this.labels.pop(),this.expect(_._while),t.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(_.semi):this.semicolon(),this.finishNode(t,"DoWhileStatement")};$.parseForStatement=function(t){this.next();var e=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(Gr),this.enterScope(0),this.expect(_.parenL),this.type===_.semi)return e>-1&&this.unexpected(e),this.parseFor(t,null);var i=this.isLet();if(this.type===_._var||this.type===_._const||i){var r=this.startNode(),n=i?"let":this.value;return this.next(),this.parseVar(r,!0,n),this.finishNode(r,"VariableDeclaration"),this.parseForAfterInit(t,r,e)}var a=this.isContextual("let"),s=!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 sr,p=this.start,h=e>-1?this.parseExprSubscripts(u,"await"):this.parseExpression(!0,u);return this.type===_._in||(s=this.options.ecmaVersion>=6&&this.isContextual("of"))?(e>-1?(this.type===_._in&&this.unexpected(e),t.await=!0):s&&this.options.ecmaVersion>=8&&(h.start===p&&!c&&h.type==="Identifier"&&h.name==="async"?this.unexpected():this.options.ecmaVersion>=9&&(t.await=!1)),a&&s&&this.raise(h.start,"The left-hand side of a for-of loop may not start with 'let'."),this.toAssignable(h,!1,u),this.checkLValPattern(h),this.parseForIn(t,h)):(this.checkExpressionErrors(u,!0),e>-1&&this.unexpected(e),this.parseFor(t,h))};$.parseForAfterInit=function(t,e,i){return(this.type===_._in||this.options.ecmaVersion>=6&&this.isContextual("of"))&&e.declarations.length===1?(this.options.ecmaVersion>=9&&(this.type===_._in?i>-1&&this.unexpected(i):t.await=i>-1),this.parseForIn(t,e)):(i>-1&&this.unexpected(i),this.parseFor(t,e))};$.parseFunctionStatement=function(t,e,i){return this.next(),this.parseFunction(t,di|(i?0:Mr),!1,e)};$.parseIfStatement=function(t){return this.next(),t.test=this.parseParenExpression(),t.consequent=this.parseStatement("if"),t.alternate=this.eat(_._else)?this.parseStatement("if"):null,this.finishNode(t,"IfStatement")};$.parseReturnStatement=function(t){return this.allowReturn||this.raise(this.start,"'return' outside of function"),this.next(),this.eat(_.semi)||this.insertSemicolon()?t.argument=null:(t.argument=this.parseExpression(),this.semicolon()),this.finishNode(t,"ReturnStatement")};$.parseSwitchStatement=function(t){this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(_.braceL),this.labels.push($m),this.enterScope(Qs);for(var e,i=!1;this.type!==_.braceR;)if(this.type===_._case||this.type===_._default){var r=this.type===_._case;e&&this.finishNode(e,"SwitchCase"),t.cases.push(e=this.startNode()),e.consequent=[],this.next(),r?e.test=this.parseExpression():(i&&this.raiseRecoverable(this.lastTokStart,"Multiple default clauses"),i=!0,e.test=null),this.expect(_.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")};$.parseThrowStatement=function(t){return this.next(),Ve.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 Vm=[];$.parseCatchClauseParam=function(){var t=this.parseBindingAtom(),e=t.type==="Identifier";return this.enterScope(e?Ys:0),this.checkLValPattern(t,e?Js:vt),this.expect(_.parenR),t};$.parseTryStatement=function(t){if(this.next(),t.block=this.parseBlock(),t.handler=null,this.type===_._catch){var e=this.startNode();this.next(),this.eat(_.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(_._finally)?this.parseBlock():null,!t.handler&&!t.finalizer&&this.raise(t.start,"Missing catch or finally clause"),this.finishNode(t,"TryStatement")};$.parseVarStatement=function(t,e,i){return this.next(),this.parseVar(t,!1,e,i),this.semicolon(),this.finishNode(t,"VariableDeclaration")};$.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(Gr),t.body=this.parseStatement("while"),this.labels.pop(),this.finishNode(t,"WhileStatement")};$.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")};$.parseEmptyStatement=function(t){return this.next(),this.finishNode(t,"EmptyStatement")};$.parseLabeledStatement=function(t,e,i,r){for(var n=0,a=this.labels;n<a.length;n+=1){var s=a[n];s.name===e&&this.raise(i.start,"Label '"+e+"' is already declared")}for(var o=this.type.isLoop?"loop":this.type===_._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(r?r.indexOf("label")===-1?r+"label":r:"label"),this.labels.pop(),t.label=i,this.finishNode(t,"LabeledStatement")};$.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")};$.parseBlock=function(t,e,i){for(t===void 0&&(t=!0),e===void 0&&(e=this.startNode()),e.body=[],this.expect(_.braceL),t&&this.enterScope(0);this.type!==_.braceR;){var r=this.parseStatement(null);e.body.push(r)}return i&&(this.strict=!1),this.next(),t&&this.exitScope(),this.finishNode(e,"BlockStatement")};$.parseFor=function(t,e){return t.init=e,this.expect(_.semi),t.test=this.type===_.semi?null:this.parseExpression(),this.expect(_.semi),t.update=this.type===_.parenR?null:this.parseExpression(),this.expect(_.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,"ForStatement")};$.parseForIn=function(t,e){var i=this.type===_._in;return this.next(),e.type==="VariableDeclaration"&&e.declarations[0].init!=null&&(!i||this.options.ecmaVersion<8||this.strict||e.kind!=="var"||e.declarations[0].id.type!=="Identifier")&&this.raise(e.start,(i?"for-in":"for-of")+" loop variable declaration may not have an initializer"),t.left=e,t.right=i?this.parseExpression():this.parseMaybeAssign(),this.expect(_.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,i?"ForInStatement":"ForOfStatement")};$.parseVar=function(t,e,i,r){for(t.declarations=[],t.kind=i;;){var n=this.startNode();if(this.parseVarId(n,i),this.eat(_.eq)?n.init=this.parseMaybeAssign(e):!r&&i==="const"&&!(this.type===_._in||this.options.ecmaVersion>=6&&this.isContextual("of"))?this.unexpected():!r&&(i==="using"||i==="await using")&&this.options.ecmaVersion>=17&&this.type!==_._in&&!this.isContextual("of")?this.raise(this.lastTokEnd,"Missing initializer in "+i+" declaration"):!r&&n.id.type!=="Identifier"&&!(e&&(this.type===_._in||this.isContextual("of")))?this.raise(this.lastTokEnd,"Complex binding patterns require an initialization value"):n.init=null,t.declarations.push(this.finishNode(n,"VariableDeclarator")),!this.eat(_.comma))break}return t};$.parseVarId=function(t,e){t.id=e==="using"||e==="await using"?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(t.id,e==="var"?Hr:vt,!1)};var di=1,Mr=2,ta=4;$.parseFunction=function(t,e,i,r,n){this.initFunction(t),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!r)&&(this.type===_.star&&e&Mr&&this.unexpected(),t.generator=this.eat(_.star)),this.options.ecmaVersion>=8&&(t.async=!!r),e&di&&(t.id=e&ta&&this.type!==_.name?null:this.parseIdent(),t.id&&!(e&Mr)&&this.checkLValSimple(t.id,this.strict||t.generator||t.async?this.treatFunctionsAsVar?Hr:vt:Zs));var a=this.yieldPos,s=this.awaitPos,o=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(Kr(t.async,t.generator)),e&di||(t.id=this.type===_.name?this.parseIdent():null),this.parseFunctionParams(t),this.parseFunctionBody(t,i,!1,n),this.yieldPos=a,this.awaitPos=s,this.awaitIdentPos=o,this.finishNode(t,e&di?"FunctionDeclaration":"FunctionExpression")};$.parseFunctionParams=function(t){this.expect(_.parenL),t.params=this.parseBindingList(_.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()};$.parseClass=function(t,e){this.next();var i=this.strict;this.strict=!0,this.parseClassId(t,e),this.parseClassSuper(t);var r=this.enterClassBody(),n=this.startNode(),a=!1;for(n.body=[],this.expect(_.braceL);this.type!==_.braceR;){var s=this.parseClassElement(t.superClass!==null);s&&(n.body.push(s),s.type==="MethodDefinition"&&s.kind==="constructor"?(a&&this.raiseRecoverable(s.start,"Duplicate constructor in the same class"),a=!0):s.key&&s.key.type==="PrivateIdentifier"&&jm(r,s)&&this.raiseRecoverable(s.key.start,"Identifier '#"+s.key.name+"' has already been declared"))}return this.strict=i,this.next(),t.body=this.finishNode(n,"ClassBody"),this.exitClassBody(),this.finishNode(t,e?"ClassDeclaration":"ClassExpression")};$.parseClassElement=function(t){if(this.eat(_.semi))return null;var e=this.options.ecmaVersion,i=this.startNode(),r="",n=!1,a=!1,s="method",o=!1;if(this.eatContextual("static")){if(e>=13&&this.eat(_.braceL))return this.parseClassStaticBlock(i),i;this.isClassElementNameStart()||this.type===_.star?o=!0:r="static"}if(i.static=o,!r&&e>=8&&this.eatContextual("async")&&((this.isClassElementNameStart()||this.type===_.star)&&!this.canInsertSemicolon()?a=!0:r="async"),!r&&(e>=9||!a)&&this.eat(_.star)&&(n=!0),!r&&!a&&!n){var l=this.value;(this.eatContextual("get")||this.eatContextual("set"))&&(this.isClassElementNameStart()?s=l:r=l)}if(r?(i.computed=!1,i.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),i.key.name=r,this.finishNode(i.key,"Identifier")):this.parseClassElementName(i),e<13||this.type===_.parenL||s!=="method"||n||a){var c=!i.static&&Hi(i,"constructor"),u=c&&t;c&&s!=="method"&&this.raise(i.key.start,"Constructor can't have get/set modifier"),i.kind=c?"constructor":s,this.parseClassMethod(i,n,a,u)}else this.parseClassField(i);return i};$.isClassElementNameStart=function(){return this.type===_.name||this.type===_.privateId||this.type===_.num||this.type===_.string||this.type===_.bracketL||this.type.keyword};$.parseClassElementName=function(t){this.type===_.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)};$.parseClassMethod=function(t,e,i,r){var n=t.key;t.kind==="constructor"?(e&&this.raise(n.start,"Constructor can't be a generator"),i&&this.raise(n.start,"Constructor can't be an async method")):t.static&&Hi(t,"prototype")&&this.raise(n.start,"Classes may not have a static property named prototype");var a=t.value=this.parseMethod(e,i,r);return t.kind==="get"&&a.params.length!==0&&this.raiseRecoverable(a.start,"getter should have no params"),t.kind==="set"&&a.params.length!==1&&this.raiseRecoverable(a.start,"setter should have exactly one param"),t.kind==="set"&&a.params[0].type==="RestElement"&&this.raiseRecoverable(a.params[0].start,"Setter cannot use rest params"),this.finishNode(t,"MethodDefinition")};$.parseClassField=function(t){return Hi(t,"constructor")?this.raise(t.key.start,"Classes can't have a field named 'constructor'"):t.static&&Hi(t,"prototype")&&this.raise(t.key.start,"Classes can't have a static field named 'prototype'"),this.eat(_.eq)?(this.enterScope(wi|rr),t.value=this.parseMaybeAssign(),this.exitScope()):t.value=null,this.semicolon(),this.finishNode(t,"PropertyDefinition")};$.parseClassStaticBlock=function(t){t.body=[];var e=this.labels;for(this.labels=[],this.enterScope(Bt|rr);this.type!==_.braceR;){var i=this.parseStatement(null);t.body.push(i)}return this.next(),this.exitScope(),this.labels=e,this.finishNode(t,"StaticBlock")};$.parseClassId=function(t,e){this.type===_.name?(t.id=this.parseIdent(),e&&this.checkLValSimple(t.id,vt,!1)):(e===!0&&this.unexpected(),t.id=null)};$.parseClassSuper=function(t){t.superClass=this.eat(_._extends)?this.parseExprSubscripts(null,!1):null};$.enterClassBody=function(){var t={declared:Object.create(null),used:[]};return this.privateNameStack.push(t),t.declared};$.exitClassBody=function(){var t=this.privateNameStack.pop(),e=t.declared,i=t.used;if(this.options.checkPrivateFields)for(var r=this.privateNameStack.length,n=r===0?null:this.privateNameStack[r-1],a=0;a<i.length;++a){var s=i[a];ni(e,s.name)||(n?n.used.push(s):this.raiseRecoverable(s.start,"Private field '#"+s.name+"' must be declared in an enclosing class"))}};function jm(t,e){var i=e.key.name,r=t[i],n="true";return e.type==="MethodDefinition"&&(e.kind==="get"||e.kind==="set")&&(n=(e.static?"s":"i")+e.kind),r==="iget"&&n==="iset"||r==="iset"&&n==="iget"||r==="sget"&&n==="sset"||r==="sset"&&n==="sget"?(t[i]="true",!1):r?!0:(t[i]=n,!1)}function Hi(t,e){var i=t.computed,r=t.key;return!i&&(r.type==="Identifier"&&r.name===e||r.type==="Literal"&&r.value===e)}$.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!==_.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ExportAllDeclaration")};$.parseExport=function(t,e){if(this.next(),this.eat(_.star))return this.parseExportAllDeclaration(t,e);if(this.eat(_._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!==_.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause());else{for(var i=0,r=t.specifiers;i<r.length;i+=1){var n=r[i];this.checkUnreserved(n.local),this.checkLocalExport(n.local),n.local.type==="Literal"&&this.raise(n.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")};$.parseExportDeclaration=function(t){return this.parseStatement(null)};$.parseExportDefaultDeclaration=function(){var t;if(this.type===_._function||(t=this.isAsyncFunction())){var e=this.startNode();return this.next(),t&&this.next(),this.parseFunction(e,di|ta,!1,t)}else if(this.type===_._class){var i=this.startNode();return this.parseClass(i,"nullableID")}else{var r=this.parseMaybeAssign();return this.semicolon(),r}};$.checkExport=function(t,e,i){t&&(typeof e!="string"&&(e=e.type==="Identifier"?e.name:e.value),ni(t,e)&&this.raiseRecoverable(i,"Duplicate export '"+e+"'"),t[e]=!0)};$.checkPatternExport=function(t,e){var i=e.type;if(i==="Identifier")this.checkExport(t,e,e.start);else if(i==="ObjectPattern")for(var r=0,n=e.properties;r<n.length;r+=1){var a=n[r];this.checkPatternExport(t,a)}else if(i==="ArrayPattern")for(var s=0,o=e.elements;s<o.length;s+=1){var l=o[s];l&&this.checkPatternExport(t,l)}else i==="Property"?this.checkPatternExport(t,e.value):i==="AssignmentPattern"?this.checkPatternExport(t,e.left):i==="RestElement"&&this.checkPatternExport(t,e.argument)};$.checkVariableExport=function(t,e){if(t)for(var i=0,r=e;i<r.length;i+=1){var n=r[i];this.checkPatternExport(t,n.id)}};$.shouldParseExportStatement=function(){return this.type.keyword==="var"||this.type.keyword==="const"||this.type.keyword==="class"||this.type.keyword==="function"||this.isLet()||this.isAsyncFunction()};$.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")};$.parseExportSpecifiers=function(t){var e=[],i=!0;for(this.expect(_.braceL);!this.eat(_.braceR);){if(i)i=!1;else if(this.expect(_.comma),this.afterTrailingComma(_.braceR))break;e.push(this.parseExportSpecifier(t))}return e};$.parseImport=function(t){return this.next(),this.type===_.string?(t.specifiers=Vm,t.source=this.parseExprAtom()):(t.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),t.source=this.type===_.string?this.parseExprAtom():this.unexpected()),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ImportDeclaration")};$.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,vt),this.finishNode(t,"ImportSpecifier")};$.parseImportDefaultSpecifier=function(){var t=this.startNode();return t.local=this.parseIdent(),this.checkLValSimple(t.local,vt),this.finishNode(t,"ImportDefaultSpecifier")};$.parseImportNamespaceSpecifier=function(){var t=this.startNode();return this.next(),this.expectContextual("as"),t.local=this.parseIdent(),this.checkLValSimple(t.local,vt),this.finishNode(t,"ImportNamespaceSpecifier")};$.parseImportSpecifiers=function(){var t=[],e=!0;if(this.type===_.name&&(t.push(this.parseImportDefaultSpecifier()),!this.eat(_.comma)))return t;if(this.type===_.star)return t.push(this.parseImportNamespaceSpecifier()),t;for(this.expect(_.braceL);!this.eat(_.braceR);){if(e)e=!1;else if(this.expect(_.comma),this.afterTrailingComma(_.braceR))break;t.push(this.parseImportSpecifier())}return t};$.parseWithClause=function(){var t=[];if(!this.eat(_._with))return t;this.expect(_.braceL);for(var e={},i=!0;!this.eat(_.braceR);){if(i)i=!1;else if(this.expect(_.comma),this.afterTrailingComma(_.braceR))break;var r=this.parseImportAttribute(),n=r.key.type==="Identifier"?r.key.name:r.key.value;ni(e,n)&&this.raiseRecoverable(r.key.start,"Duplicate attribute key '"+n+"'"),e[n]=!0,t.push(r)}return t};$.parseImportAttribute=function(){var t=this.startNode();return t.key=this.type===_.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never"),this.expect(_.colon),this.type!==_.string&&this.unexpected(),t.value=this.parseExprAtom(),this.finishNode(t,"ImportAttribute")};$.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===_.string){var t=this.parseLiteral(this.value);return Mm.test(t.value)&&this.raise(t.start,"An export name cannot include a lone surrogate."),t}return this.parseIdent(!0)};$.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)};$.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 Qe=ye.prototype;Qe.toAssignable=function(t,e,i){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",i&&this.checkPatternErrors(i,!0);for(var r=0,n=t.properties;r<n.length;r+=1){var a=n[r];this.toAssignable(a,e),a.type==="RestElement"&&(a.argument.type==="ArrayPattern"||a.argument.type==="ObjectPattern")&&this.raise(a.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",i&&this.checkPatternErrors(i,!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,i);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 i&&this.checkPatternErrors(i,!0);return t};Qe.toAssignableList=function(t,e){for(var i=t.length,r=0;r<i;r++){var n=t[r];n&&this.toAssignable(n,e)}if(i){var a=t[i-1];this.options.ecmaVersion===6&&e&&a&&a.type==="RestElement"&&a.argument.type!=="Identifier"&&this.unexpected(a.argument.start)}return t};Qe.parseSpread=function(t){var e=this.startNode();return this.next(),e.argument=this.parseMaybeAssign(!1,t),this.finishNode(e,"SpreadElement")};Qe.parseRestBinding=function(){var t=this.startNode();return this.next(),this.options.ecmaVersion===6&&this.type!==_.name&&this.unexpected(),t.argument=this.parseBindingAtom(),this.finishNode(t,"RestElement")};Qe.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case _.bracketL:var t=this.startNode();return this.next(),t.elements=this.parseBindingList(_.bracketR,!0,!0),this.finishNode(t,"ArrayPattern");case _.braceL:return this.parseObj(!0)}return this.parseIdent()};Qe.parseBindingList=function(t,e,i,r){for(var n=[],a=!0;!this.eat(t);)if(a?a=!1:this.expect(_.comma),e&&this.type===_.comma)n.push(null);else{if(i&&this.afterTrailingComma(t))break;if(this.type===_.ellipsis){var s=this.parseRestBinding();this.parseBindingListItem(s),n.push(s),this.type===_.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.expect(t);break}else n.push(this.parseAssignableListItem(r))}return n};Qe.parseAssignableListItem=function(t){var e=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(e),e};Qe.parseBindingListItem=function(t){return t};Qe.parseMaybeDefault=function(t,e,i){if(i=i||this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(_.eq))return i;var r=this.startNodeAt(t,e);return r.left=i,r.right=this.parseMaybeAssign(),this.finishNode(r,"AssignmentPattern")};Qe.checkLValSimple=function(t,e,i){e===void 0&&(e=Ki);var r=e!==Ki;switch(t.type){case"Identifier":this.strict&&this.reservedWordsStrictBind.test(t.name)&&this.raiseRecoverable(t.start,(r?"Binding ":"Assigning to ")+t.name+" in strict mode"),r&&(e===vt&&t.name==="let"&&this.raiseRecoverable(t.start,"let is disallowed as a lexically bound name"),i&&(ni(i,t.name)&&this.raiseRecoverable(t.start,"Argument name clash"),i[t.name]=!0),e!==ea&&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":r&&this.raiseRecoverable(t.start,"Binding member expression");break;case"ParenthesizedExpression":return r&&this.raiseRecoverable(t.start,"Binding parenthesized expression"),this.checkLValSimple(t.expression,e,i);default:this.raise(t.start,(r?"Binding":"Assigning to")+" rvalue")}};Qe.checkLValPattern=function(t,e,i){switch(e===void 0&&(e=Ki),t.type){case"ObjectPattern":for(var r=0,n=t.properties;r<n.length;r+=1){var a=n[r];this.checkLValInnerPattern(a,e,i)}break;case"ArrayPattern":for(var s=0,o=t.elements;s<o.length;s+=1){var l=o[s];l&&this.checkLValInnerPattern(l,e,i)}break;default:this.checkLValSimple(t,e,i)}};Qe.checkLValInnerPattern=function(t,e,i){switch(e===void 0&&(e=Ki),t.type){case"Property":this.checkLValInnerPattern(t.value,e,i);break;case"AssignmentPattern":this.checkLValPattern(t.left,e,i);break;case"RestElement":this.checkLValPattern(t.argument,e,i);break;default:this.checkLValPattern(t,e,i)}};var et=function(e,i,r,n,a){this.token=e,this.isExpr=!!i,this.preserveSpace=!!r,this.override=n,this.generator=!!a},ae={b_stat:new et("{",!1),b_expr:new et("{",!0),b_tmpl:new et("${",!1),p_stat:new et("(",!1),p_expr:new et("(",!0),q_tmpl:new et("`",!0,!0,function(t){return t.tryReadTemplateToken()}),f_stat:new et("function",!1),f_expr:new et("function",!0),f_expr_gen:new et("function",!0,!1,null,!0),f_gen:new et("function",!1,!1,null,!0)},si=ye.prototype;si.initialContext=function(){return[ae.b_stat]};si.curContext=function(){return this.context[this.context.length-1]};si.braceIsBlock=function(t){var e=this.curContext();return e===ae.f_expr||e===ae.f_stat?!0:t===_.colon&&(e===ae.b_stat||e===ae.b_expr)?!e.isExpr:t===_._return||t===_.name&&this.exprAllowed?Ve.test(this.input.slice(this.lastTokEnd,this.start)):t===_._else||t===_.semi||t===_.eof||t===_.parenR||t===_.arrow?!0:t===_.braceL?e===ae.b_stat:t===_._var||t===_._const||t===_.name?!1:!this.exprAllowed};si.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};si.updateContext=function(t){var e,i=this.type;i.keyword&&t===_.dot?this.exprAllowed=!1:(e=i.updateContext)?e.call(this,t):this.exprAllowed=i.beforeExpr};si.overrideContext=function(t){this.curContext()!==t&&(this.context[this.context.length-1]=t)};_.parenR.updateContext=_.braceR.updateContext=function(){if(this.context.length===1){this.exprAllowed=!0;return}var t=this.context.pop();t===ae.b_stat&&this.curContext().token==="function"&&(t=this.context.pop()),this.exprAllowed=!t.isExpr};_.braceL.updateContext=function(t){this.context.push(this.braceIsBlock(t)?ae.b_stat:ae.b_expr),this.exprAllowed=!0};_.dollarBraceL.updateContext=function(){this.context.push(ae.b_tmpl),this.exprAllowed=!0};_.parenL.updateContext=function(t){var e=t===_._if||t===_._for||t===_._with||t===_._while;this.context.push(e?ae.p_stat:ae.p_expr),this.exprAllowed=!0};_.incDec.updateContext=function(){};_._function.updateContext=_._class.updateContext=function(t){t.beforeExpr&&t!==_._else&&!(t===_.semi&&this.curContext()!==ae.p_stat)&&!(t===_._return&&Ve.test(this.input.slice(this.lastTokEnd,this.start)))&&!((t===_.colon||t===_.braceL)&&this.curContext()===ae.b_stat)?this.context.push(ae.f_expr):this.context.push(ae.f_stat),this.exprAllowed=!1};_.colon.updateContext=function(){this.curContext().token==="function"&&this.context.pop(),this.exprAllowed=!0};_.backQuote.updateContext=function(){this.curContext()===ae.q_tmpl?this.context.pop():this.context.push(ae.q_tmpl),this.exprAllowed=!1};_.star.updateContext=function(t){if(t===_._function){var e=this.context.length-1;this.context[e]===ae.f_expr?this.context[e]=ae.f_expr_gen:this.context[e]=ae.f_gen}this.exprAllowed=!0};_.name.updateContext=function(t){var e=!1;this.options.ecmaVersion>=6&&t!==_.dot&&(this.value==="of"&&!this.exprAllowed||this.value==="yield"&&this.inGeneratorContext())&&(e=!0),this.exprAllowed=e};var W=ye.prototype;W.checkPropClash=function(t,e,i){if(!(this.options.ecmaVersion>=9&&t.type==="SpreadElement")&&!(this.options.ecmaVersion>=6&&(t.computed||t.method||t.shorthand))){var r=t.key,n;switch(r.type){case"Identifier":n=r.name;break;case"Literal":n=String(r.value);break;default:return}var a=t.kind;if(this.options.ecmaVersion>=6){n==="__proto__"&&a==="init"&&(e.proto&&(i?i.doubleProto<0&&(i.doubleProto=r.start):this.raiseRecoverable(r.start,"Redefinition of __proto__ property")),e.proto=!0);return}n="$"+n;var s=e[n];if(s){var o;a==="init"?o=this.strict&&s.init||s.get||s.set:o=s.init||s[a],o&&this.raiseRecoverable(r.start,"Redefinition of property")}else s=e[n]={init:!1,get:!1,set:!1};s[a]=!0}};W.parseExpression=function(t,e){var i=this.start,r=this.startLoc,n=this.parseMaybeAssign(t,e);if(this.type===_.comma){var a=this.startNodeAt(i,r);for(a.expressions=[n];this.eat(_.comma);)a.expressions.push(this.parseMaybeAssign(t,e));return this.finishNode(a,"SequenceExpression")}return n};W.parseMaybeAssign=function(t,e,i){if(this.isContextual("yield")){if(this.inGenerator)return this.parseYield(t);this.exprAllowed=!1}var r=!1,n=-1,a=-1,s=-1;e?(n=e.parenthesizedAssign,a=e.trailingComma,s=e.doubleProto,e.parenthesizedAssign=e.trailingComma=-1):(e=new sr,r=!0);var o=this.start,l=this.startLoc;(this.type===_.parenL||this.type===_.name)&&(this.potentialArrowAt=this.start,this.potentialArrowInForAwait=t==="await");var c=this.parseMaybeConditional(t,e);if(i&&(c=i.call(this,c,o,l)),this.type.isAssign){var u=this.startNodeAt(o,l);return u.operator=this.value,this.type===_.eq&&(c=this.toAssignable(c,!1,e)),r||(e.parenthesizedAssign=e.trailingComma=e.doubleProto=-1),e.shorthandAssign>=c.start&&(e.shorthandAssign=-1),this.type===_.eq?this.checkLValPattern(c):this.checkLValSimple(c),u.left=c,this.next(),u.right=this.parseMaybeAssign(t),s>-1&&(e.doubleProto=s),this.finishNode(u,"AssignmentExpression")}else r&&this.checkExpressionErrors(e,!0);return n>-1&&(e.parenthesizedAssign=n),a>-1&&(e.trailingComma=a),c};W.parseMaybeConditional=function(t,e){var i=this.start,r=this.startLoc,n=this.parseExprOps(t,e);if(this.checkExpressionErrors(e))return n;if(this.eat(_.question)){var a=this.startNodeAt(i,r);return a.test=n,a.consequent=this.parseMaybeAssign(),this.expect(_.colon),a.alternate=this.parseMaybeAssign(t),this.finishNode(a,"ConditionalExpression")}return n};W.parseExprOps=function(t,e){var i=this.start,r=this.startLoc,n=this.parseMaybeUnary(e,!1,!1,t);return this.checkExpressionErrors(e)||n.start===i&&n.type==="ArrowFunctionExpression"?n:this.parseExprOp(n,i,r,-1,t)};W.parseExprOp=function(t,e,i,r,n){var a=this.type.binop;if(a!=null&&(!n||this.type!==_._in)&&a>r){var s=this.type===_.logicalOR||this.type===_.logicalAND,o=this.type===_.coalesce;o&&(a=_.logicalAND.binop);var l=this.value;this.next();var c=this.start,u=this.startLoc,p=this.parseExprOp(this.parseMaybeUnary(null,!1,!1,n),c,u,a,n),h=this.buildBinary(e,i,t,p,l,s||o);return(s&&this.type===_.coalesce||o&&(this.type===_.logicalOR||this.type===_.logicalAND))&&this.raiseRecoverable(this.start,"Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"),this.parseExprOp(h,e,i,r,n)}return t};W.buildBinary=function(t,e,i,r,n,a){r.type==="PrivateIdentifier"&&this.raise(r.start,"Private identifier can only be left side of binary expression");var s=this.startNodeAt(t,e);return s.left=i,s.operator=n,s.right=r,this.finishNode(s,a?"LogicalExpression":"BinaryExpression")};W.parseMaybeUnary=function(t,e,i,r){var n=this.start,a=this.startLoc,s;if(this.isContextual("await")&&this.canAwait)s=this.parseAwait(r),e=!0;else if(this.type.prefix){var o=this.startNode(),l=this.type===_.incDec;o.operator=this.value,o.prefix=!0,this.next(),o.argument=this.parseMaybeUnary(null,!0,l,r),this.checkExpressionErrors(t,!0),l?this.checkLValSimple(o.argument):this.strict&&o.operator==="delete"&&ia(o.argument)?this.raiseRecoverable(o.start,"Deleting local variable in strict mode"):o.operator==="delete"&&Dr(o.argument)?this.raiseRecoverable(o.start,"Private fields can not be deleted"):e=!0,s=this.finishNode(o,l?"UpdateExpression":"UnaryExpression")}else if(!e&&this.type===_.privateId)(r||this.privateNameStack.length===0)&&this.options.checkPrivateFields&&this.unexpected(),s=this.parsePrivateIdent(),this.type!==_._in&&this.unexpected();else{if(s=this.parseExprSubscripts(t,r),this.checkExpressionErrors(t))return s;for(;this.type.postfix&&!this.canInsertSemicolon();){var c=this.startNodeAt(n,a);c.operator=this.value,c.prefix=!1,c.argument=s,this.checkLValSimple(s),this.next(),s=this.finishNode(c,"UpdateExpression")}}if(!i&&this.eat(_.starstar))if(e)this.unexpected(this.lastTokStart);else return this.buildBinary(n,a,s,this.parseMaybeUnary(null,!1,!1,r),"**",!1);else return s};function ia(t){return t.type==="Identifier"||t.type==="ParenthesizedExpression"&&ia(t.expression)}function Dr(t){return t.type==="MemberExpression"&&t.property.type==="PrivateIdentifier"||t.type==="ChainExpression"&&Dr(t.expression)||t.type==="ParenthesizedExpression"&&Dr(t.expression)}W.parseExprSubscripts=function(t,e){var i=this.start,r=this.startLoc,n=this.parseExprAtom(t,e);if(n.type==="ArrowFunctionExpression"&&this.input.slice(this.lastTokStart,this.lastTokEnd)!==")")return n;var a=this.parseSubscripts(n,i,r,!1,e);return t&&a.type==="MemberExpression"&&(t.parenthesizedAssign>=a.start&&(t.parenthesizedAssign=-1),t.parenthesizedBind>=a.start&&(t.parenthesizedBind=-1),t.trailingComma>=a.start&&(t.trailingComma=-1)),a};W.parseSubscripts=function(t,e,i,r,n){for(var a=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,s=!1;;){var o=this.parseSubscript(t,e,i,r,a,s,n);if(o.optional&&(s=!0),o===t||o.type==="ArrowFunctionExpression"){if(s){var l=this.startNodeAt(e,i);l.expression=o,o=this.finishNode(l,"ChainExpression")}return o}t=o}};W.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(_.arrow)};W.parseSubscriptAsyncArrow=function(t,e,i,r){return this.parseArrowExpression(this.startNodeAt(t,e),i,!0,r)};W.parseSubscript=function(t,e,i,r,n,a,s){var o=this.options.ecmaVersion>=11,l=o&&this.eat(_.questionDot);r&&l&&this.raise(this.lastTokStart,"Optional chaining cannot appear in the callee of new expressions");var c=this.eat(_.bracketL);if(c||l&&this.type!==_.parenL&&this.type!==_.backQuote||this.eat(_.dot)){var u=this.startNodeAt(e,i);u.object=t,c?(u.property=this.parseExpression(),this.expect(_.bracketR)):this.type===_.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(!r&&this.eat(_.parenL)){var p=new sr,h=this.yieldPos,f=this.awaitPos,d=this.awaitIdentPos;this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0;var m=this.parseExprList(_.parenR,this.options.ecmaVersion>=8,!1,p);if(n&&!l&&this.shouldParseAsyncArrow())return this.checkPatternErrors(p,!1),this.checkYieldAwaitInDefaultParams(),this.awaitIdentPos>0&&this.raise(this.awaitIdentPos,"Cannot use 'await' as identifier inside an async function"),this.yieldPos=h,this.awaitPos=f,this.awaitIdentPos=d,this.parseSubscriptAsyncArrow(e,i,m,s);this.checkExpressionErrors(p,!0),this.yieldPos=h||this.yieldPos,this.awaitPos=f||this.awaitPos,this.awaitIdentPos=d||this.awaitIdentPos;var x=this.startNodeAt(e,i);x.callee=t,x.arguments=m,o&&(x.optional=l),t=this.finishNode(x,"CallExpression")}else if(this.type===_.backQuote){(l||a)&&this.raise(this.start,"Optional chaining cannot appear in the tag of tagged template expressions");var b=this.startNodeAt(e,i);b.tag=t,b.quasi=this.parseTemplate({isTagged:!0}),t=this.finishNode(b,"TaggedTemplateExpression")}return t};W.parseExprAtom=function(t,e,i){this.type===_.slash&&this.readRegexp();var r,n=this.potentialArrowAt===this.start;switch(this.type){case _._super:return this.allowSuper||this.raise(this.start,"'super' keyword outside a method"),r=this.startNode(),this.next(),this.type===_.parenL&&!this.allowDirectSuper&&this.raise(r.start,"super() call outside constructor of a subclass"),this.type!==_.dot&&this.type!==_.bracketL&&this.type!==_.parenL&&this.unexpected(),this.finishNode(r,"Super");case _._this:return r=this.startNode(),this.next(),this.finishNode(r,"ThisExpression");case _.name:var a=this.start,s=this.startLoc,o=this.containsEsc,l=this.parseIdent(!1);if(this.options.ecmaVersion>=8&&!o&&l.name==="async"&&!this.canInsertSemicolon()&&this.eat(_._function))return this.overrideContext(ae.f_expr),this.parseFunction(this.startNodeAt(a,s),0,!1,!0,e);if(n&&!this.canInsertSemicolon()){if(this.eat(_.arrow))return this.parseArrowExpression(this.startNodeAt(a,s),[l],!1,e);if(this.options.ecmaVersion>=8&&l.name==="async"&&this.type===_.name&&!o&&(!this.potentialArrowInForAwait||this.value!=="of"||this.containsEsc))return l=this.parseIdent(!1),(this.canInsertSemicolon()||!this.eat(_.arrow))&&this.unexpected(),this.parseArrowExpression(this.startNodeAt(a,s),[l],!0,e)}return l;case _.regexp:var c=this.value;return r=this.parseLiteral(c.value),r.regex={pattern:c.pattern,flags:c.flags},r;case _.num:case _.string:return this.parseLiteral(this.value);case _._null:case _._true:case _._false:return r=this.startNode(),r.value=this.type===_._null?null:this.type===_._true,r.raw=this.type.keyword,this.next(),this.finishNode(r,"Literal");case _.parenL:var u=this.start,p=this.parseParenAndDistinguishExpression(n,e);return t&&(t.parenthesizedAssign<0&&!this.isSimpleAssignTarget(p)&&(t.parenthesizedAssign=u),t.parenthesizedBind<0&&(t.parenthesizedBind=u)),p;case _.bracketL:return r=this.startNode(),this.next(),r.elements=this.parseExprList(_.bracketR,!0,!0,t),this.finishNode(r,"ArrayExpression");case _.braceL:return this.overrideContext(ae.b_expr),this.parseObj(!1,t);case _._function:return r=this.startNode(),this.next(),this.parseFunction(r,0);case _._class:return this.parseClass(this.startNode(),!1);case _._new:return this.parseNew();case _.backQuote:return this.parseTemplate();case _._import:return this.options.ecmaVersion>=11?this.parseExprImport(i):this.unexpected();default:return this.parseExprAtomDefault()}};W.parseExprAtomDefault=function(){this.unexpected()};W.parseExprImport=function(t){var e=this.startNode();if(this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword import"),this.next(),this.type===_.parenL&&!t)return this.parseDynamicImport(e);if(this.type===_.dot){var i=this.startNodeAt(e.start,e.loc&&e.loc.start);return i.name="import",e.meta=this.finishNode(i,"Identifier"),this.parseImportMeta(e)}else this.unexpected()};W.parseDynamicImport=function(t){if(this.next(),t.source=this.parseMaybeAssign(),this.options.ecmaVersion>=16)this.eat(_.parenR)?t.options=null:(this.expect(_.comma),this.afterTrailingComma(_.parenR)?t.options=null:(t.options=this.parseMaybeAssign(),this.eat(_.parenR)||(this.expect(_.comma),this.afterTrailingComma(_.parenR)||this.unexpected())));else if(!this.eat(_.parenR)){var e=this.start;this.eat(_.comma)&&this.eat(_.parenR)?this.raiseRecoverable(e,"Trailing comma is not allowed in import()"):this.unexpected(e)}return this.finishNode(t,"ImportExpression")};W.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")};W.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")};W.parseParenExpression=function(){this.expect(_.parenL);var t=this.parseExpression();return this.expect(_.parenR),t};W.shouldParseArrow=function(t){return!this.canInsertSemicolon()};W.parseParenAndDistinguishExpression=function(t,e){var i=this.start,r=this.startLoc,n,a=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var s=this.start,o=this.startLoc,l=[],c=!0,u=!1,p=new sr,h=this.yieldPos,f=this.awaitPos,d;for(this.yieldPos=0,this.awaitPos=0;this.type!==_.parenR;)if(c?c=!1:this.expect(_.comma),a&&this.afterTrailingComma(_.parenR,!0)){u=!0;break}else if(this.type===_.ellipsis){d=this.start,l.push(this.parseParenItem(this.parseRestBinding())),this.type===_.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element");break}else l.push(this.parseMaybeAssign(!1,p,this.parseParenItem));var m=this.lastTokEnd,x=this.lastTokEndLoc;if(this.expect(_.parenR),t&&this.shouldParseArrow(l)&&this.eat(_.arrow))return this.checkPatternErrors(p,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=h,this.awaitPos=f,this.parseParenArrowList(i,r,l,e);(!l.length||u)&&this.unexpected(this.lastTokStart),d&&this.unexpected(d),this.checkExpressionErrors(p,!0),this.yieldPos=h||this.yieldPos,this.awaitPos=f||this.awaitPos,l.length>1?(n=this.startNodeAt(s,o),n.expressions=l,this.finishNodeAt(n,"SequenceExpression",m,x)):n=l[0]}else n=this.parseParenExpression();if(this.options.preserveParens){var b=this.startNodeAt(i,r);return b.expression=n,this.finishNode(b,"ParenthesizedExpression")}else return n};W.parseParenItem=function(t){return t};W.parseParenArrowList=function(t,e,i,r){return this.parseArrowExpression(this.startNodeAt(t,e),i,!1,r)};var Lm=[];W.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===_.dot){var e=this.startNodeAt(t.start,t.loc&&t.loc.start);e.name="new",t.meta=this.finishNode(e,"Identifier"),this.next();var i=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'"),i&&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 r=this.start,n=this.startLoc;return t.callee=this.parseSubscripts(this.parseExprAtom(null,!1,!0),r,n,!0,!1),this.eat(_.parenL)?t.arguments=this.parseExprList(_.parenR,this.options.ecmaVersion>=8,!1):t.arguments=Lm,this.finishNode(t,"NewExpression")};W.parseTemplateElement=function(t){var e=t.isTagged,i=this.startNode();return this.type===_.invalidTemplate?(e||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),i.value={raw:this.value.replace(/\r\n?/g,`
5
5
  `),cooked:null}):i.value={raw:this.input.slice(this.start,this.end).replace(/\r\n?/g,`
6
- `),cooked:this.value},this.next(),i.tail=this.type===_.backQuote,this.finishNode(i,"TemplateElement")};B.parseTemplate=function(t){t===void 0&&(t={});var e=t.isTagged;e===void 0&&(e=!1);var i=this.startNode();this.next(),i.expressions=[];var r=this.parseTemplateElement({isTagged:e});for(i.quasis=[r];!r.tail;)this.type===_.eof&&this.raise(this.pos,"Unterminated template literal"),this.expect(_.dollarBraceL),i.expressions.push(this.parseExpression()),this.expect(_.braceR),i.quasis.push(r=this.parseTemplateElement({isTagged:e}));return this.next(),this.finishNode(i,"TemplateLiteral")};B.isAsyncProp=function(t){return!t.computed&&t.key.type==="Identifier"&&t.key.name==="async"&&(this.type===_.name||this.type===_.num||this.type===_.string||this.type===_.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===_.star)&&!Oe.test(this.input.slice(this.lastTokEnd,this.start))};B.parseObj=function(t,e){var i=this.startNode(),r=!0,n={};for(i.properties=[],this.next();!this.eat(_.braceR);){if(r)r=!1;else if(this.expect(_.comma),this.options.ecmaVersion>=5&&this.afterTrailingComma(_.braceR))break;var s=this.parseProperty(t,e);t||this.checkPropClash(s,n,e),i.properties.push(s)}return this.finishNode(i,t?"ObjectPattern":"ObjectExpression")};B.parseProperty=function(t,e){var i=this.startNode(),r,n,s,a;if(this.options.ecmaVersion>=9&&this.eat(_.ellipsis))return t?(i.argument=this.parseIdent(!1),this.type===_.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.finishNode(i,"RestElement")):(i.argument=this.parseMaybeAssign(!1,e),this.type===_.comma&&e&&e.trailingComma<0&&(e.trailingComma=this.start),this.finishNode(i,"SpreadElement"));this.options.ecmaVersion>=6&&(i.method=!1,i.shorthand=!1,(t||e)&&(s=this.start,a=this.startLoc),t||(r=this.eat(_.star)));var o=this.containsEsc;return this.parsePropertyName(i),!t&&!o&&this.options.ecmaVersion>=8&&!r&&this.isAsyncProp(i)?(n=!0,r=this.options.ecmaVersion>=9&&this.eat(_.star),this.parsePropertyName(i)):n=!1,this.parsePropertyValue(i,t,r,n,s,a,e,o),this.finishNode(i,"Property")};B.parseGetterSetter=function(t){var e=t.key.name;this.parsePropertyName(t),t.value=this.parseMethod(!1),t.kind=e;var i=t.kind==="get"?0:1;if(t.value.params.length!==i){var r=t.value.start;t.kind==="get"?this.raiseRecoverable(r,"getter should have no params"):this.raiseRecoverable(r,"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")};B.parsePropertyValue=function(t,e,i,r,n,s,a,o){(i||r)&&this.type===_.colon&&this.unexpected(),this.eat(_.colon)?(t.value=e?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,a),t.kind="init"):this.options.ecmaVersion>=6&&this.type===_.parenL?(e&&this.unexpected(),t.method=!0,t.value=this.parseMethod(i,r),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!==_.comma&&this.type!==_.braceR&&this.type!==_.eq?((i||r)&&this.unexpected(),this.parseGetterSetter(t)):this.options.ecmaVersion>=6&&!t.computed&&t.key.type==="Identifier"?((i||r)&&this.unexpected(),this.checkUnreserved(t.key),t.key.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=n),e?t.value=this.parseMaybeDefault(n,s,this.copyNode(t.key)):this.type===_.eq&&a?(a.shorthandAssign<0&&(a.shorthandAssign=this.start),t.value=this.parseMaybeDefault(n,s,this.copyNode(t.key))):t.value=this.copyNode(t.key),t.kind="init",t.shorthand=!0):this.unexpected()};B.parsePropertyName=function(t){if(this.options.ecmaVersion>=6){if(this.eat(_.bracketL))return t.computed=!0,t.key=this.parseMaybeAssign(),this.expect(_.bracketR),t.key;t.computed=!1}return t.key=this.type===_.num||this.type===_.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never")};B.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)};B.parseMethod=function(t,e,i){var r=this.startNode(),n=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.initFunction(r),this.options.ecmaVersion>=6&&(r.generator=t),this.options.ecmaVersion>=8&&(r.async=!!e),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(Wr(e,r.generator)|Ji|(i?zs:0)),this.expect(_.parenL),r.params=this.parseBindingList(_.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(r,!1,!0,!1),this.yieldPos=n,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(r,"FunctionExpression")};B.parseArrowExpression=function(t,e,i,r){var n=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.enterScope(Wr(i,!1)|Fr),this.initFunction(t),this.options.ecmaVersion>=8&&(t.async=!!i),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,t.params=this.toAssignableList(e,!0),this.parseFunctionBody(t,!0,!1,r),this.yieldPos=n,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(t,"ArrowFunctionExpression")};B.parseFunctionBody=function(t,e,i,r){var n=e&&this.type!==_.braceL,s=this.strict,a=!1;if(n)t.body=this.parseMaybeAssign(r),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&&!i&&this.isSimpleParamList(t.params)),this.strict&&t.id&&this.checkLValSimple(t.id,Ys),t.body=this.parseBlock(!1,void 0,a&&!s),t.expression=!1,this.adaptDirectivePrologue(t.body.body),this.labels=l}this.exitScope()};B.isSimpleParamList=function(t){for(var e=0,i=t;e<i.length;e+=1){var r=i[e];if(r.type!=="Identifier")return!1}return!0};B.checkParams=function(t,e){for(var i=Object.create(null),r=0,n=t.params;r<n.length;r+=1){var s=n[r];this.checkLValInnerPattern(s,Ur,e?null:i)}};B.parseExprList=function(t,e,i,r){for(var n=[],s=!0;!this.eat(t);){if(s)s=!1;else if(this.expect(_.comma),e&&this.afterTrailingComma(t))break;var a=void 0;i&&this.type===_.comma?a=null:this.type===_.ellipsis?(a=this.parseSpread(r),r&&this.type===_.comma&&r.trailingComma<0&&(r.trailingComma=this.start)):a=this.parseMaybeAssign(!1,r),n.push(a)}return n};B.checkUnreserved=function(t){var e=t.start,i=t.end,r=t.name;if(this.inGenerator&&r==="yield"&&this.raiseRecoverable(e,"Cannot use 'yield' as identifier inside a generator"),this.inAsync&&r==="await"&&this.raiseRecoverable(e,"Cannot use 'await' as identifier inside an async function"),!(this.currentThisScope().flags&er)&&r==="arguments"&&this.raiseRecoverable(e,"Cannot use 'arguments' in class field initializer"),this.inClassStaticBlock&&(r==="arguments"||r==="await")&&this.raise(e,"Cannot use "+r+" in class static initialization block"),this.keywords.test(r)&&this.raise(e,"Unexpected keyword '"+r+"'"),!(this.options.ecmaVersion<6&&this.input.slice(e,i).indexOf("\\")!==-1)){var n=this.strict?this.reservedWordsStrict:this.reservedWords;n.test(r)&&(!this.inAsync&&r==="await"&&this.raiseRecoverable(e,"Cannot use keyword 'await' outside an async function"),this.raiseRecoverable(e,"The keyword '"+r+"' is reserved"))}};B.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};B.parseIdentNode=function(){var t=this.startNode();return this.type===_.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=_.name):this.unexpected(),t};B.parsePrivateIdent=function(){var t=this.startNode();return this.type===_.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};B.parseYield=function(t){this.yieldPos||(this.yieldPos=this.start);var e=this.startNode();return this.next(),this.type===_.semi||this.canInsertSemicolon()||this.type!==_.star&&!this.type.startsExpr?(e.delegate=!1,e.argument=null):(e.delegate=this.eat(_.star),e.argument=this.parseMaybeAssign(t)),this.finishNode(e,"YieldExpression")};B.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 zi=pe.prototype;zi.raise=function(t,e){var i=Ws(this.input,t);e+=" ("+i.line+":"+i.column+")",this.sourceFile&&(e+=" in "+this.sourceFile);var r=new SyntaxError(e);throw r.pos=t,r.loc=i,r.raisedAt=this.pos,r};zi.raiseRecoverable=zi.raise;zi.curPosition=function(){if(this.options.locations)return new xi(this.curLine,this.pos-this.lineStart)};var At=pe.prototype,Dm=function(e){this.flags=e,this.var=[],this.lexical=[],this.functions=[]};At.enterScope=function(t){this.scopeStack.push(new Dm(t))};At.exitScope=function(){this.scopeStack.pop()};At.treatFunctionsAsVarInScope=function(t){return t.flags&$t||!this.inModule&&t.flags&Ot};At.declareName=function(t,e,i){var r=!1;if(e===bt){var n=this.currentScope();r=n.lexical.indexOf(t)>-1||n.functions.indexOf(t)>-1||n.var.indexOf(t)>-1,n.lexical.push(t),this.inModule&&n.flags&Ot&&delete this.undefinedExports[t]}else if(e===Gs){var s=this.currentScope();s.lexical.push(t)}else if(e===Hs){var a=this.currentScope();this.treatFunctionsAsVar?r=a.lexical.indexOf(t)>-1:r=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&qs&&l.lexical[0]===t)||!this.treatFunctionsAsVarInScope(l)&&l.functions.indexOf(t)>-1){r=!0;break}if(l.var.push(t),this.inModule&&l.flags&Ot&&delete this.undefinedExports[t],l.flags&er)break}r&&this.raiseRecoverable(i,"Identifier '"+t+"' has already been declared")};At.checkLocalExport=function(t){this.scopeStack[0].lexical.indexOf(t.name)===-1&&this.scopeStack[0].var.indexOf(t.name)===-1&&(this.undefinedExports[t.name]=t)};At.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]};At.currentVarScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(er|wi|Vt))return e}};At.currentThisScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(er|wi|Vt)&&!(e.flags&Fr))return e}};var ir=function(e,i,r){this.type="",this.start=i,this.end=0,e.options.locations&&(this.loc=new Qi(e,r)),e.options.directSourceFile&&(this.sourceFile=e.options.directSourceFile),e.options.ranges&&(this.range=[i,0])},Si=pe.prototype;Si.startNode=function(){return new ir(this,this.start,this.startLoc)};Si.startNodeAt=function(t,e){return new ir(this,t,e)};function Qs(t,e,i,r){return t.type=e,t.end=i,this.options.locations&&(t.loc.end=r),this.options.ranges&&(t.range[1]=i),t}Si.finishNode=function(t,e){return Qs.call(this,t,e,this.lastTokEnd,this.lastTokEndLoc)};Si.finishNodeAt=function(t,e,i,r){return Qs.call(this,t,e,i,r)};Si.copyNode=function(t){var e=new ir(this,t.start,this.startLoc);for(var i in t)e[i]=t[i];return e};var Mm="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",Js="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",ea=Js+" Extended_Pictographic",ta=ea,ia=ta+" EBase EComp EMod EPres ExtPict",ra=ia,Rm=ra,Om={9:Js,10:ea,11:ta,12:ia,13:ra,14:Rm},$m="Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji",Vm={9:"",10:"",11:"",12:"",13:"",14:$m},Sn="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",na="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",sa=na+" Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd",aa=sa+" Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho",oa=aa+" Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi",la=oa+" Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith",jm=la+" "+Mm,Lm={9:na,10:sa,11:aa,12:oa,13:la,14:jm},ca={};function Bm(t){var e=ca[t]={binary:Ct(Om[t]+" "+Sn),binaryOfStrings:Ct(Vm[t]),nonBinary:{General_Category:Ct(Sn),Script:Ct(Lm[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(var pr=0,En=[9,10,11,12,13,14];pr<En.length;pr+=1){var Fm=En[pr];Bm(Fm)}var D=pe.prototype,Ki=function(e,i){this.parent=e,this.base=i||this};Ki.prototype.separatedFrom=function(e){for(var i=this;i;i=i.parent)for(var r=e;r;r=r.parent)if(i.base===r.base&&i!==r)return!0;return!1};Ki.prototype.sibling=function(){return new Ki(this.parent,this.base)};var ht=function(e){this.parser=e,this.validFlags="gim"+(e.options.ecmaVersion>=6?"uy":"")+(e.options.ecmaVersion>=9?"s":"")+(e.options.ecmaVersion>=13?"d":"")+(e.options.ecmaVersion>=15?"v":""),this.unicodeProperties=ca[e.options.ecmaVersion>=14?14:e.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};ht.prototype.reset=function(e,i,r){var n=r.indexOf("v")!==-1,s=r.indexOf("u")!==-1;this.start=e|0,this.source=i+"",this.flags=r,n&&this.parser.options.ecmaVersion>=15?(this.switchU=!0,this.switchV=!0,this.switchN=!0):(this.switchU=s&&this.parser.options.ecmaVersion>=6,this.switchV=!1,this.switchN=s&&this.parser.options.ecmaVersion>=9)};ht.prototype.raise=function(e){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+e)};ht.prototype.at=function(e,i){i===void 0&&(i=!1);var r=this.source,n=r.length;if(e>=n)return-1;var s=r.charCodeAt(e);if(!(i||this.switchU)||s<=55295||s>=57344||e+1>=n)return s;var a=r.charCodeAt(e+1);return a>=56320&&a<=57343?(s<<10)+a-56613888:s};ht.prototype.nextIndex=function(e,i){i===void 0&&(i=!1);var r=this.source,n=r.length;if(e>=n)return n;var s=r.charCodeAt(e),a;return!(i||this.switchU)||s<=55295||s>=57344||e+1>=n||(a=r.charCodeAt(e+1))<56320||a>57343?e+1:e+2};ht.prototype.current=function(e){return e===void 0&&(e=!1),this.at(this.pos,e)};ht.prototype.lookahead=function(e){return e===void 0&&(e=!1),this.at(this.nextIndex(this.pos,e),e)};ht.prototype.advance=function(e){e===void 0&&(e=!1),this.pos=this.nextIndex(this.pos,e)};ht.prototype.eat=function(e,i){return i===void 0&&(i=!1),this.current(i)===e?(this.advance(i),!0):!1};ht.prototype.eatChars=function(e,i){i===void 0&&(i=!1);for(var r=this.pos,n=0,s=e;n<s.length;n+=1){var a=s[n],o=this.at(r,i);if(o===-1||o!==a)return!1;r=this.nextIndex(r,i)}return this.pos=r,!0};D.validateRegExpFlags=function(t){for(var e=t.validFlags,i=t.flags,r=!1,n=!1,s=0;s<i.length;s++){var a=i.charAt(s);e.indexOf(a)===-1&&this.raise(t.start,"Invalid regular expression flag"),i.indexOf(a,s+1)>-1&&this.raise(t.start,"Duplicate regular expression flag"),a==="u"&&(r=!0),a==="v"&&(n=!0)}this.options.ecmaVersion>=15&&r&&n&&this.raise(t.start,"Invalid regular expression flag")};function Wm(t){for(var e in t)return!0;return!1}D.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&Wm(t.groupNames)&&(t.switchN=!0,this.regexp_pattern(t))};D.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,i=t.backReferenceNames;e<i.length;e+=1){var r=i[e];t.groupNames[r]||t.raise("Invalid named capture referenced")}};D.regexp_disjunction=function(t){var e=this.options.ecmaVersion>=16;for(e&&(t.branchID=new Ki(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")};D.regexp_alternative=function(t){for(;t.pos<t.source.length&&this.regexp_eatTerm(t););};D.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};D.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 i=!1;if(this.options.ecmaVersion>=9&&(i=t.eat(60)),t.eat(61)||t.eat(33))return this.regexp_disjunction(t),t.eat(41)||t.raise("Unterminated group"),t.lastAssertionIsQuantifiable=!i,!0}return t.pos=e,!1};D.regexp_eatQuantifier=function(t,e){return e===void 0&&(e=!1),this.regexp_eatQuantifierPrefix(t,e)?(t.eat(63),!0):!1};D.regexp_eatQuantifierPrefix=function(t,e){return t.eat(42)||t.eat(43)||t.eat(63)||this.regexp_eatBracedQuantifier(t,e)};D.regexp_eatBracedQuantifier=function(t,e){var i=t.pos;if(t.eat(123)){var r=0,n=-1;if(this.regexp_eatDecimalDigits(t)&&(r=t.lastIntValue,t.eat(44)&&this.regexp_eatDecimalDigits(t)&&(n=t.lastIntValue),t.eat(125)))return n!==-1&&n<r&&!e&&t.raise("numbers out of order in {} quantifier"),!0;t.switchU&&!e&&t.raise("Incomplete quantifier"),t.pos=i}return!1};D.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)};D.regexp_eatReverseSolidusAtomEscape=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatAtomEscape(t))return!0;t.pos=e}return!1};D.regexp_eatUncapturingGroup=function(t){var e=t.pos;if(t.eat(40)){if(t.eat(63)){if(this.options.ecmaVersion>=16){var i=this.regexp_eatModifiers(t),r=t.eat(45);if(i||r){for(var n=0;n<i.length;n++){var s=i.charAt(n);i.indexOf(s,n+1)>-1&&t.raise("Duplicate regular expression modifiers")}if(r){var a=this.regexp_eatModifiers(t);!i&&!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||i.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};D.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};D.regexp_eatModifiers=function(t){for(var e="",i=0;(i=t.current())!==-1&&Um(i);)e+=gt(i),t.advance();return e};function Um(t){return t===105||t===109||t===115}D.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)};D.regexp_eatInvalidBracedQuantifier=function(t){return this.regexp_eatBracedQuantifier(t,!0)&&t.raise("Nothing to repeat"),!1};D.regexp_eatSyntaxCharacter=function(t){var e=t.current();return ua(e)?(t.lastIntValue=e,t.advance(),!0):!1};function ua(t){return t===36||t>=40&&t<=43||t===46||t===63||t>=91&&t<=94||t>=123&&t<=125}D.regexp_eatPatternCharacters=function(t){for(var e=t.pos,i=0;(i=t.current())!==-1&&!ua(i);)t.advance();return t.pos!==e};D.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};D.regexp_groupSpecifier=function(t){if(t.eat(63)){this.regexp_eatGroupName(t)||t.raise("Invalid group");var e=this.options.ecmaVersion>=16,i=t.groupNames[t.lastStringValue];if(i)if(e)for(var r=0,n=i;r<n.length;r+=1){var s=n[r];s.separatedFrom(t.branchID)||t.raise("Duplicate capture group name")}else t.raise("Duplicate capture group name");e?(i||(t.groupNames[t.lastStringValue]=[])).push(t.branchID):t.groupNames[t.lastStringValue]=!0}};D.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};D.regexp_eatRegExpIdentifierName=function(t){if(t.lastStringValue="",this.regexp_eatRegExpIdentifierStart(t)){for(t.lastStringValue+=gt(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=gt(t.lastIntValue);return!0}return!1};D.regexp_eatRegExpIdentifierStart=function(t){var e=t.pos,i=this.options.ecmaVersion>=11,r=t.current(i);return t.advance(i),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,i)&&(r=t.lastIntValue),qm(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function qm(t){return ut(t,!0)||t===36||t===95}D.regexp_eatRegExpIdentifierPart=function(t){var e=t.pos,i=this.options.ecmaVersion>=11,r=t.current(i);return t.advance(i),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,i)&&(r=t.lastIntValue),zm(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function zm(t){return kt(t,!0)||t===36||t===95||t===8204||t===8205}D.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)};D.regexp_eatBackReference=function(t){var e=t.pos;if(this.regexp_eatDecimalEscape(t)){var i=t.lastIntValue;if(t.switchU)return i>t.maxBackReference&&(t.maxBackReference=i),!0;if(i<=t.numCapturingParens)return!0;t.pos=e}return!1};D.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};D.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)};D.regexp_eatCControlLetter=function(t){var e=t.pos;if(t.eat(99)){if(this.regexp_eatControlLetter(t))return!0;t.pos=e}return!1};D.regexp_eatZero=function(t){return t.current()===48&&!rr(t.lookahead())?(t.lastIntValue=0,t.advance(),!0):!1};D.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};D.regexp_eatControlLetter=function(t){var e=t.current();return ha(e)?(t.lastIntValue=e%32,t.advance(),!0):!1};function ha(t){return t>=65&&t<=90||t>=97&&t<=122}D.regexp_eatRegExpUnicodeEscapeSequence=function(t,e){e===void 0&&(e=!1);var i=t.pos,r=e||t.switchU;if(t.eat(117)){if(this.regexp_eatFixedHexDigits(t,4)){var n=t.lastIntValue;if(r&&n>=55296&&n<=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=(n-55296)*1024+(a-56320)+65536,!0}t.pos=s,t.lastIntValue=n}return!0}if(r&&t.eat(123)&&this.regexp_eatHexDigits(t)&&t.eat(125)&&Km(t.lastIntValue))return!0;r&&t.raise("Invalid unicode escape"),t.pos=i}return!1};function Km(t){return t>=0&&t<=1114111}D.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};D.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 pa=0,xt=1,Ke=2;D.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(Hm(e))return t.lastIntValue=-1,t.advance(),xt;var i=!1;if(t.switchU&&this.options.ecmaVersion>=9&&((i=e===80)||e===112)){t.lastIntValue=-1,t.advance();var r;if(t.eat(123)&&(r=this.regexp_eatUnicodePropertyValueExpression(t))&&t.eat(125))return i&&r===Ke&&t.raise("Invalid property name"),r;t.raise("Invalid property name")}return pa};function Hm(t){return t===100||t===68||t===115||t===83||t===119||t===87}D.regexp_eatUnicodePropertyValueExpression=function(t){var e=t.pos;if(this.regexp_eatUnicodePropertyName(t)&&t.eat(61)){var i=t.lastStringValue;if(this.regexp_eatUnicodePropertyValue(t)){var r=t.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(t,i,r),xt}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var n=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,n)}return pa};D.regexp_validateUnicodePropertyNameAndValue=function(t,e,i){ri(t.unicodeProperties.nonBinary,e)||t.raise("Invalid property name"),t.unicodeProperties.nonBinary[e].test(i)||t.raise("Invalid property value")};D.regexp_validateUnicodePropertyNameOrValue=function(t,e){if(t.unicodeProperties.binary.test(e))return xt;if(t.switchV&&t.unicodeProperties.binaryOfStrings.test(e))return Ke;t.raise("Invalid property name")};D.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";fa(e=t.current());)t.lastStringValue+=gt(e),t.advance();return t.lastStringValue!==""};function fa(t){return ha(t)||t===95}D.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";Gm(e=t.current());)t.lastStringValue+=gt(e),t.advance();return t.lastStringValue!==""};function Gm(t){return fa(t)||rr(t)}D.regexp_eatLoneUnicodePropertyNameOrValue=function(t){return this.regexp_eatUnicodePropertyValue(t)};D.regexp_eatCharacterClass=function(t){if(t.eat(91)){var e=t.eat(94),i=this.regexp_classContents(t);return t.eat(93)||t.raise("Unterminated character class"),e&&i===Ke&&t.raise("Negated character class may contain strings"),!0}return!1};D.regexp_classContents=function(t){return t.current()===93?xt:t.switchV?this.regexp_classSetExpression(t):(this.regexp_nonEmptyClassRanges(t),xt)};D.regexp_nonEmptyClassRanges=function(t){for(;this.regexp_eatClassAtom(t);){var e=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassAtom(t)){var i=t.lastIntValue;t.switchU&&(e===-1||i===-1)&&t.raise("Invalid character class"),e!==-1&&i!==-1&&e>i&&t.raise("Range out of order in character class")}}};D.regexp_eatClassAtom=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatClassEscape(t))return!0;if(t.switchU){var i=t.current();(i===99||ya(i))&&t.raise("Invalid class escape"),t.raise("Invalid escape")}t.pos=e}var r=t.current();return r!==93?(t.lastIntValue=r,t.advance(),!0):!1};D.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)};D.regexp_classSetExpression=function(t){var e=xt,i;if(!this.regexp_eatClassSetRange(t))if(i=this.regexp_eatClassSetOperand(t)){i===Ke&&(e=Ke);for(var r=t.pos;t.eatChars([38,38]);){if(t.current()!==38&&(i=this.regexp_eatClassSetOperand(t))){i!==Ke&&(e=xt);continue}t.raise("Invalid character in character class")}if(r!==t.pos)return e;for(;t.eatChars([45,45]);)this.regexp_eatClassSetOperand(t)||t.raise("Invalid character in character class");if(r!==t.pos)return e}else t.raise("Invalid character in character class");for(;;)if(!this.regexp_eatClassSetRange(t)){if(i=this.regexp_eatClassSetOperand(t),!i)return e;i===Ke&&(e=Ke)}};D.regexp_eatClassSetRange=function(t){var e=t.pos;if(this.regexp_eatClassSetCharacter(t)){var i=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassSetCharacter(t)){var r=t.lastIntValue;return i!==-1&&r!==-1&&i>r&&t.raise("Range out of order in character class"),!0}t.pos=e}return!1};D.regexp_eatClassSetOperand=function(t){return this.regexp_eatClassSetCharacter(t)?xt:this.regexp_eatClassStringDisjunction(t)||this.regexp_eatNestedClass(t)};D.regexp_eatNestedClass=function(t){var e=t.pos;if(t.eat(91)){var i=t.eat(94),r=this.regexp_classContents(t);if(t.eat(93))return i&&r===Ke&&t.raise("Negated character class may contain strings"),r;t.pos=e}if(t.eat(92)){var n=this.regexp_eatCharacterClassEscape(t);if(n)return n;t.pos=e}return null};D.regexp_eatClassStringDisjunction=function(t){var e=t.pos;if(t.eatChars([92,113])){if(t.eat(123)){var i=this.regexp_classStringDisjunctionContents(t);if(t.eat(125))return i}else t.raise("Invalid escape");t.pos=e}return null};D.regexp_classStringDisjunctionContents=function(t){for(var e=this.regexp_classString(t);t.eat(124);)this.regexp_classString(t)===Ke&&(e=Ke);return e};D.regexp_classString=function(t){for(var e=0;this.regexp_eatClassSetCharacter(t);)e++;return e===1?xt:Ke};D.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 i=t.current();return i<0||i===t.lookahead()&&Ym(i)||Xm(i)?!1:(t.advance(),t.lastIntValue=i,!0)};function Ym(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 Xm(t){return t===40||t===41||t===45||t===47||t>=91&&t<=93||t>=123&&t<=125}D.regexp_eatClassSetReservedPunctuator=function(t){var e=t.current();return Zm(e)?(t.lastIntValue=e,t.advance(),!0):!1};function Zm(t){return t===33||t===35||t===37||t===38||t===44||t===45||t>=58&&t<=62||t===64||t===96||t===126}D.regexp_eatClassControlLetter=function(t){var e=t.current();return rr(e)||e===95?(t.lastIntValue=e%32,t.advance(),!0):!1};D.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};D.regexp_eatDecimalDigits=function(t){var e=t.pos,i=0;for(t.lastIntValue=0;rr(i=t.current());)t.lastIntValue=10*t.lastIntValue+(i-48),t.advance();return t.pos!==e};function rr(t){return t>=48&&t<=57}D.regexp_eatHexDigits=function(t){var e=t.pos,i=0;for(t.lastIntValue=0;da(i=t.current());)t.lastIntValue=16*t.lastIntValue+ma(i),t.advance();return t.pos!==e};function da(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function ma(t){return t>=65&&t<=70?10+(t-65):t>=97&&t<=102?10+(t-97):t-48}D.regexp_eatLegacyOctalEscapeSequence=function(t){if(this.regexp_eatOctalDigit(t)){var e=t.lastIntValue;if(this.regexp_eatOctalDigit(t)){var i=t.lastIntValue;e<=3&&this.regexp_eatOctalDigit(t)?t.lastIntValue=e*64+i*8+t.lastIntValue:t.lastIntValue=e*8+i}else t.lastIntValue=e;return!0}return!1};D.regexp_eatOctalDigit=function(t){var e=t.current();return ya(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)};function ya(t){return t>=48&&t<=55}D.regexp_eatFixedHexDigits=function(t,e){var i=t.pos;t.lastIntValue=0;for(var r=0;r<e;++r){var n=t.current();if(!da(n))return t.pos=i,!1;t.lastIntValue=16*t.lastIntValue+ma(n),t.advance()}return!0};var zr=function(e){this.type=e.type,this.value=e.value,this.start=e.start,this.end=e.end,e.options.locations&&(this.loc=new Qi(e,e.startLoc,e.endLoc)),e.options.ranges&&(this.range=[e.start,e.end])},K=pe.prototype;K.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 zr(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()};K.getToken=function(){return this.next(),new zr(this)};typeof Symbol<"u"&&(K[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===_.eof,value:e}}}});K.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(_.eof);if(t.override)return t.override(this);this.readToken(this.fullCharCodeAtPos())};K.readToken=function(t){return ut(t,this.options.ecmaVersion>=6)||t===92?this.readWord():this.getTokenFromCode(t)};K.fullCharCodeAt=function(t){var e=this.input.charCodeAt(t);if(e<=55295||e>=56320)return e;var i=this.input.charCodeAt(t+1);return i<=56319||i>=57344?e:(e<<10)+i-56613888};K.fullCharCodeAtPos=function(){return this.fullCharCodeAt(this.pos)};K.skipBlockComment=function(){var t=this.options.onComment&&this.curPosition(),e=this.pos,i=this.input.indexOf("*/",this.pos+=2);if(i===-1&&this.raise(this.pos-2,"Unterminated comment"),this.pos=i+2,this.options.locations)for(var r=void 0,n=e;(r=Ls(this.input,n,this.pos))>-1;)++this.curLine,n=this.lineStart=r;this.options.onComment&&this.options.onComment(!0,this.input.slice(e+2,i),e,this.pos,t,this.curPosition())};K.skipLineComment=function(t){for(var e=this.pos,i=this.options.onComment&&this.curPosition(),r=this.input.charCodeAt(this.pos+=t);this.pos<this.input.length&&!ii(r);)r=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(e+t,this.pos),e,this.pos,i,this.curPosition())};K.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&&Bs.test(String.fromCharCode(t)))++this.pos;else break e}}};K.finishToken=function(t,e){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var i=this.type;this.type=t,this.value=e,this.updateContext(i)};K.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(_.ellipsis)):(++this.pos,this.finishToken(_.dot))};K.readToken_slash=function(){var t=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):t===61?this.finishOp(_.assign,2):this.finishOp(_.slash,1)};K.readToken_mult_modulo_exp=function(t){var e=this.input.charCodeAt(this.pos+1),i=1,r=t===42?_.star:_.modulo;return this.options.ecmaVersion>=7&&t===42&&e===42&&(++i,r=_.starstar,e=this.input.charCodeAt(this.pos+2)),e===61?this.finishOp(_.assign,i+1):this.finishOp(r,i)};K.readToken_pipe_amp=function(t){var e=this.input.charCodeAt(this.pos+1);if(e===t){if(this.options.ecmaVersion>=12){var i=this.input.charCodeAt(this.pos+2);if(i===61)return this.finishOp(_.assign,3)}return this.finishOp(t===124?_.logicalOR:_.logicalAND,2)}return e===61?this.finishOp(_.assign,2):this.finishOp(t===124?_.bitwiseOR:_.bitwiseAND,1)};K.readToken_caret=function(){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(_.assign,2):this.finishOp(_.bitwiseXOR,1)};K.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||Oe.test(this.input.slice(this.lastTokEnd,this.pos)))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(_.incDec,2):e===61?this.finishOp(_.assign,2):this.finishOp(_.plusMin,1)};K.readToken_lt_gt=function(t){var e=this.input.charCodeAt(this.pos+1),i=1;return e===t?(i=t===62&&this.input.charCodeAt(this.pos+2)===62?3:2,this.input.charCodeAt(this.pos+i)===61?this.finishOp(_.assign,i+1):this.finishOp(_.bitShift,i)):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&&(i=2),this.finishOp(_.relational,i))};K.readToken_eq_excl=function(t){var e=this.input.charCodeAt(this.pos+1);return e===61?this.finishOp(_.equality,this.input.charCodeAt(this.pos+2)===61?3:2):t===61&&e===62&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(_.arrow)):this.finishOp(t===61?_.eq:_.prefix,1)};K.readToken_question=function(){var t=this.options.ecmaVersion;if(t>=11){var e=this.input.charCodeAt(this.pos+1);if(e===46){var i=this.input.charCodeAt(this.pos+2);if(i<48||i>57)return this.finishOp(_.questionDot,2)}if(e===63){if(t>=12){var r=this.input.charCodeAt(this.pos+2);if(r===61)return this.finishOp(_.assign,3)}return this.finishOp(_.coalesce,2)}}return this.finishOp(_.question,1)};K.readToken_numberSign=function(){var t=this.options.ecmaVersion,e=35;if(t>=13&&(++this.pos,e=this.fullCharCodeAtPos(),ut(e,!0)||e===92))return this.finishToken(_.privateId,this.readWord1());this.raise(this.pos,"Unexpected character '"+gt(e)+"'")};K.getTokenFromCode=function(t){switch(t){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(_.parenL);case 41:return++this.pos,this.finishToken(_.parenR);case 59:return++this.pos,this.finishToken(_.semi);case 44:return++this.pos,this.finishToken(_.comma);case 91:return++this.pos,this.finishToken(_.bracketL);case 93:return++this.pos,this.finishToken(_.bracketR);case 123:return++this.pos,this.finishToken(_.braceL);case 125:return++this.pos,this.finishToken(_.braceR);case 58:return++this.pos,this.finishToken(_.colon);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(_.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(_.prefix,1);case 35:return this.readToken_numberSign()}this.raise(this.pos,"Unexpected character '"+gt(t)+"'")};K.finishOp=function(t,e){var i=this.input.slice(this.pos,this.pos+e);return this.pos+=e,this.finishToken(t,i)};K.readRegexp=function(){for(var t,e,i=this.pos;;){this.pos>=this.input.length&&this.raise(i,"Unterminated regular expression");var r=this.input.charAt(this.pos);if(Oe.test(r)&&this.raise(i,"Unterminated regular expression"),t)t=!1;else{if(r==="[")e=!0;else if(r==="]"&&e)e=!1;else if(r==="/"&&!e)break;t=r==="\\"}++this.pos}var n=this.input.slice(i,this.pos);++this.pos;var s=this.pos,a=this.readWord1();this.containsEsc&&this.unexpected(s);var o=this.regexpState||(this.regexpState=new ht(this));o.reset(i,n,a),this.validateRegExpFlags(o),this.validateRegExpPattern(o);var l=null;try{l=new RegExp(n,a)}catch{}return this.finishToken(_.regexp,{pattern:n,flags:a,value:l})};K.readInt=function(t,e,i){for(var r=this.options.ecmaVersion>=12&&e===void 0,n=i&&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),p=void 0;if(r&&u===95){n&&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?p=u-97+10:u>=65?p=u-65+10:u>=48&&u<=57?p=u-48:p=1/0,p>=t)break;o=u,a=a*t+p}return r&&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 Qm(t,e){return e?parseInt(t,8):parseFloat(t.replace(/_/g,""))}function _a(t){return typeof BigInt!="function"?null:BigInt(t.replace(/_/g,""))}K.readRadixNumber=function(t){var e=this.pos;this.pos+=2;var i=this.readInt(t);return i==null&&this.raise(this.start+2,"Expected number in radix "+t),this.options.ecmaVersion>=11&&this.input.charCodeAt(this.pos)===110?(i=_a(this.input.slice(e,this.pos)),++this.pos):ut(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(_.num,i)};K.readNumber=function(t){var e=this.pos;!t&&this.readInt(10,void 0,!0)===null&&this.raise(e,"Invalid number");var i=this.pos-e>=2&&this.input.charCodeAt(e)===48;i&&this.strict&&this.raise(e,"Invalid number");var r=this.input.charCodeAt(this.pos);if(!i&&!t&&this.options.ecmaVersion>=11&&r===110){var n=_a(this.input.slice(e,this.pos));return++this.pos,ut(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(_.num,n)}i&&/[89]/.test(this.input.slice(e,this.pos))&&(i=!1),r===46&&!i&&(++this.pos,this.readInt(10),r=this.input.charCodeAt(this.pos)),(r===69||r===101)&&!i&&(r=this.input.charCodeAt(++this.pos),(r===43||r===45)&&++this.pos,this.readInt(10)===null&&this.raise(e,"Invalid number")),ut(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var s=Qm(this.input.slice(e,this.pos),i);return this.finishToken(_.num,s)};K.readCodePoint=function(){var t=this.input.charCodeAt(this.pos),e;if(t===123){this.options.ecmaVersion<6&&this.unexpected();var i=++this.pos;e=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,e>1114111&&this.invalidStringToken(i,"Code point out of bounds")}else e=this.readHexChar(4);return e};K.readString=function(t){for(var e="",i=++this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated string constant");var r=this.input.charCodeAt(this.pos);if(r===t)break;r===92?(e+=this.input.slice(i,this.pos),e+=this.readEscapedChar(!1),i=this.pos):r===8232||r===8233?(this.options.ecmaVersion<10&&this.raise(this.start,"Unterminated string constant"),++this.pos,this.options.locations&&(this.curLine++,this.lineStart=this.pos)):(ii(r)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return e+=this.input.slice(i,this.pos++),this.finishToken(_.string,e)};var ga={};K.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t===ga)this.readInvalidTemplateToken();else throw t}this.inTemplateElement=!1};K.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw ga;this.raise(t,e)};K.readTmplToken=function(){for(var t="",e=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var i=this.input.charCodeAt(this.pos);if(i===96||i===36&&this.input.charCodeAt(this.pos+1)===123)return this.pos===this.start&&(this.type===_.template||this.type===_.invalidTemplate)?i===36?(this.pos+=2,this.finishToken(_.dollarBraceL)):(++this.pos,this.finishToken(_.backQuote)):(t+=this.input.slice(e,this.pos),this.finishToken(_.template,t));if(i===92)t+=this.input.slice(e,this.pos),t+=this.readEscapedChar(!0),e=this.pos;else if(ii(i)){switch(t+=this.input.slice(e,this.pos),++this.pos,i){case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:t+=`
7
- `;break;default:t+=String.fromCharCode(i);break}this.options.locations&&(++this.curLine,this.lineStart=this.pos),e=this.pos}else++this.pos}};K.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(_.invalidTemplate,this.input.slice(this.start,this.pos));case"\r":this.input[this.pos+1]===`
6
+ `),cooked:this.value},this.next(),i.tail=this.type===_.backQuote,this.finishNode(i,"TemplateElement")};W.parseTemplate=function(t){t===void 0&&(t={});var e=t.isTagged;e===void 0&&(e=!1);var i=this.startNode();this.next(),i.expressions=[];var r=this.parseTemplateElement({isTagged:e});for(i.quasis=[r];!r.tail;)this.type===_.eof&&this.raise(this.pos,"Unterminated template literal"),this.expect(_.dollarBraceL),i.expressions.push(this.parseExpression()),this.expect(_.braceR),i.quasis.push(r=this.parseTemplateElement({isTagged:e}));return this.next(),this.finishNode(i,"TemplateLiteral")};W.isAsyncProp=function(t){return!t.computed&&t.key.type==="Identifier"&&t.key.name==="async"&&(this.type===_.name||this.type===_.num||this.type===_.string||this.type===_.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===_.star)&&!Ve.test(this.input.slice(this.lastTokEnd,this.start))};W.parseObj=function(t,e){var i=this.startNode(),r=!0,n={};for(i.properties=[],this.next();!this.eat(_.braceR);){if(r)r=!1;else if(this.expect(_.comma),this.options.ecmaVersion>=5&&this.afterTrailingComma(_.braceR))break;var a=this.parseProperty(t,e);t||this.checkPropClash(a,n,e),i.properties.push(a)}return this.finishNode(i,t?"ObjectPattern":"ObjectExpression")};W.parseProperty=function(t,e){var i=this.startNode(),r,n,a,s;if(this.options.ecmaVersion>=9&&this.eat(_.ellipsis))return t?(i.argument=this.parseIdent(!1),this.type===_.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.finishNode(i,"RestElement")):(i.argument=this.parseMaybeAssign(!1,e),this.type===_.comma&&e&&e.trailingComma<0&&(e.trailingComma=this.start),this.finishNode(i,"SpreadElement"));this.options.ecmaVersion>=6&&(i.method=!1,i.shorthand=!1,(t||e)&&(a=this.start,s=this.startLoc),t||(r=this.eat(_.star)));var o=this.containsEsc;return this.parsePropertyName(i),!t&&!o&&this.options.ecmaVersion>=8&&!r&&this.isAsyncProp(i)?(n=!0,r=this.options.ecmaVersion>=9&&this.eat(_.star),this.parsePropertyName(i)):n=!1,this.parsePropertyValue(i,t,r,n,a,s,e,o),this.finishNode(i,"Property")};W.parseGetterSetter=function(t){var e=t.key.name;this.parsePropertyName(t),t.value=this.parseMethod(!1),t.kind=e;var i=t.kind==="get"?0:1;if(t.value.params.length!==i){var r=t.value.start;t.kind==="get"?this.raiseRecoverable(r,"getter should have no params"):this.raiseRecoverable(r,"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")};W.parsePropertyValue=function(t,e,i,r,n,a,s,o){(i||r)&&this.type===_.colon&&this.unexpected(),this.eat(_.colon)?(t.value=e?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,s),t.kind="init"):this.options.ecmaVersion>=6&&this.type===_.parenL?(e&&this.unexpected(),t.method=!0,t.value=this.parseMethod(i,r),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!==_.comma&&this.type!==_.braceR&&this.type!==_.eq?((i||r)&&this.unexpected(),this.parseGetterSetter(t)):this.options.ecmaVersion>=6&&!t.computed&&t.key.type==="Identifier"?((i||r)&&this.unexpected(),this.checkUnreserved(t.key),t.key.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=n),e?t.value=this.parseMaybeDefault(n,a,this.copyNode(t.key)):this.type===_.eq&&s?(s.shorthandAssign<0&&(s.shorthandAssign=this.start),t.value=this.parseMaybeDefault(n,a,this.copyNode(t.key))):t.value=this.copyNode(t.key),t.kind="init",t.shorthand=!0):this.unexpected()};W.parsePropertyName=function(t){if(this.options.ecmaVersion>=6){if(this.eat(_.bracketL))return t.computed=!0,t.key=this.parseMaybeAssign(),this.expect(_.bracketR),t.key;t.computed=!1}return t.key=this.type===_.num||this.type===_.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never")};W.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)};W.parseMethod=function(t,e,i){var r=this.startNode(),n=this.yieldPos,a=this.awaitPos,s=this.awaitIdentPos;return this.initFunction(r),this.options.ecmaVersion>=6&&(r.generator=t),this.options.ecmaVersion>=8&&(r.async=!!e),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(Kr(e,r.generator)|rr|(i?Xs:0)),this.expect(_.parenL),r.params=this.parseBindingList(_.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(r,!1,!0,!1),this.yieldPos=n,this.awaitPos=a,this.awaitIdentPos=s,this.finishNode(r,"FunctionExpression")};W.parseArrowExpression=function(t,e,i,r){var n=this.yieldPos,a=this.awaitPos,s=this.awaitIdentPos;return this.enterScope(Kr(i,!1)|zr),this.initFunction(t),this.options.ecmaVersion>=8&&(t.async=!!i),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,t.params=this.toAssignableList(e,!0),this.parseFunctionBody(t,!0,!1,r),this.yieldPos=n,this.awaitPos=a,this.awaitIdentPos=s,this.finishNode(t,"ArrowFunctionExpression")};W.parseFunctionBody=function(t,e,i,r){var n=e&&this.type!==_.braceL,a=this.strict,s=!1;if(n)t.body=this.parseMaybeAssign(r),t.expression=!0,this.checkParams(t,!1);else{var o=this.options.ecmaVersion>=7&&!this.isSimpleParamList(t.params);(!a||o)&&(s=this.strictDirective(this.end),s&&o&&this.raiseRecoverable(t.start,"Illegal 'use strict' directive in function with non-simple parameter list"));var l=this.labels;this.labels=[],s&&(this.strict=!0),this.checkParams(t,!a&&!s&&!e&&!i&&this.isSimpleParamList(t.params)),this.strict&&t.id&&this.checkLValSimple(t.id,ea),t.body=this.parseBlock(!1,void 0,s&&!a),t.expression=!1,this.adaptDirectivePrologue(t.body.body),this.labels=l}this.exitScope()};W.isSimpleParamList=function(t){for(var e=0,i=t;e<i.length;e+=1){var r=i[e];if(r.type!=="Identifier")return!1}return!0};W.checkParams=function(t,e){for(var i=Object.create(null),r=0,n=t.params;r<n.length;r+=1){var a=n[r];this.checkLValInnerPattern(a,Hr,e?null:i)}};W.parseExprList=function(t,e,i,r){for(var n=[],a=!0;!this.eat(t);){if(a)a=!1;else if(this.expect(_.comma),e&&this.afterTrailingComma(t))break;var s=void 0;i&&this.type===_.comma?s=null:this.type===_.ellipsis?(s=this.parseSpread(r),r&&this.type===_.comma&&r.trailingComma<0&&(r.trailingComma=this.start)):s=this.parseMaybeAssign(!1,r),n.push(s)}return n};W.checkUnreserved=function(t){var e=t.start,i=t.end,r=t.name;if(this.inGenerator&&r==="yield"&&this.raiseRecoverable(e,"Cannot use 'yield' as identifier inside a generator"),this.inAsync&&r==="await"&&this.raiseRecoverable(e,"Cannot use 'await' as identifier inside an async function"),!(this.currentThisScope().flags&nr)&&r==="arguments"&&this.raiseRecoverable(e,"Cannot use 'arguments' in class field initializer"),this.inClassStaticBlock&&(r==="arguments"||r==="await")&&this.raise(e,"Cannot use "+r+" in class static initialization block"),this.keywords.test(r)&&this.raise(e,"Unexpected keyword '"+r+"'"),!(this.options.ecmaVersion<6&&this.input.slice(e,i).indexOf("\\")!==-1)){var n=this.strict?this.reservedWordsStrict:this.reservedWords;n.test(r)&&(!this.inAsync&&r==="await"&&this.raiseRecoverable(e,"Cannot use keyword 'await' outside an async function"),this.raiseRecoverable(e,"The keyword '"+r+"' is reserved"))}};W.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};W.parseIdentNode=function(){var t=this.startNode();return this.type===_.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=_.name):this.unexpected(),t};W.parsePrivateIdent=function(){var t=this.startNode();return this.type===_.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};W.parseYield=function(t){this.yieldPos||(this.yieldPos=this.start);var e=this.startNode();return this.next(),this.type===_.semi||this.canInsertSemicolon()||this.type!==_.star&&!this.type.startsExpr?(e.delegate=!1,e.argument=null):(e.delegate=this.eat(_.star),e.argument=this.parseMaybeAssign(t)),this.finishNode(e,"YieldExpression")};W.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 Gi=ye.prototype;Gi.raise=function(t,e){var i=Hs(this.input,t);e+=" ("+i.line+":"+i.column+")",this.sourceFile&&(e+=" in "+this.sourceFile);var r=new SyntaxError(e);throw r.pos=t,r.loc=i,r.raisedAt=this.pos,r};Gi.raiseRecoverable=Gi.raise;Gi.curPosition=function(){if(this.options.locations)return new xi(this.curLine,this.pos-this.lineStart)};var At=ye.prototype,Bm=function(e){this.flags=e,this.var=[],this.lexical=[],this.functions=[]};At.enterScope=function(t){this.scopeStack.push(new Bm(t))};At.exitScope=function(){this.scopeStack.pop()};At.treatFunctionsAsVarInScope=function(t){return t.flags&Lt||!this.inModule&&t.flags&jt};At.declareName=function(t,e,i){var r=!1;if(e===vt){var n=this.currentScope();r=n.lexical.indexOf(t)>-1||n.functions.indexOf(t)>-1||n.var.indexOf(t)>-1,n.lexical.push(t),this.inModule&&n.flags&jt&&delete this.undefinedExports[t]}else if(e===Js){var a=this.currentScope();a.lexical.push(t)}else if(e===Zs){var s=this.currentScope();this.treatFunctionsAsVar?r=s.lexical.indexOf(t)>-1:r=s.lexical.indexOf(t)>-1||s.var.indexOf(t)>-1,s.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&Ys&&l.lexical[0]===t)||!this.treatFunctionsAsVarInScope(l)&&l.functions.indexOf(t)>-1){r=!0;break}if(l.var.push(t),this.inModule&&l.flags&jt&&delete this.undefinedExports[t],l.flags&nr)break}r&&this.raiseRecoverable(i,"Identifier '"+t+"' has already been declared")};At.checkLocalExport=function(t){this.scopeStack[0].lexical.indexOf(t.name)===-1&&this.scopeStack[0].var.indexOf(t.name)===-1&&(this.undefinedExports[t.name]=t)};At.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]};At.currentVarScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(nr|wi|Bt))return e}};At.currentThisScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(nr|wi|Bt)&&!(e.flags&zr))return e}};var ar=function(e,i,r){this.type="",this.start=i,this.end=0,e.options.locations&&(this.loc=new ir(e,r)),e.options.directSourceFile&&(this.sourceFile=e.options.directSourceFile),e.options.ranges&&(this.range=[i,0])},Si=ye.prototype;Si.startNode=function(){return new ar(this,this.start,this.startLoc)};Si.startNodeAt=function(t,e){return new ar(this,t,e)};function ra(t,e,i,r){return t.type=e,t.end=i,this.options.locations&&(t.loc.end=r),this.options.ranges&&(t.range[1]=i),t}Si.finishNode=function(t,e){return ra.call(this,t,e,this.lastTokEnd,this.lastTokEndLoc)};Si.finishNodeAt=function(t,e,i,r){return ra.call(this,t,e,i,r)};Si.copyNode=function(t){var e=new ar(this,t.start,this.startLoc);for(var i in t)e[i]=t[i];return e};var Fm="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",na="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",sa=na+" Extended_Pictographic",aa=sa,oa=aa+" EBase EComp EMod EPres ExtPict",la=oa,Wm=la,Um={9:na,10:sa,11:aa,12:oa,13:la,14:Wm},qm="Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji",zm={9:"",10:"",11:"",12:"",13:"",14:qm},Cn="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",ca="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",ua=ca+" Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd",ha=ua+" Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho",pa=ha+" Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi",fa=pa+" Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith",Km=fa+" "+Fm,Hm={9:ca,10:ua,11:ha,12:pa,13:fa,14:Km},da={};function Gm(t){var e=da[t]={binary:Ct(Um[t]+" "+Cn),binaryOfStrings:Ct(zm[t]),nonBinary:{General_Category:Ct(Cn),Script:Ct(Hm[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(var _r=0,In=[9,10,11,12,13,14];_r<In.length;_r+=1){var Ym=In[_r];Gm(Ym)}var O=ye.prototype,Yi=function(e,i){this.parent=e,this.base=i||this};Yi.prototype.separatedFrom=function(e){for(var i=this;i;i=i.parent)for(var r=e;r;r=r.parent)if(i.base===r.base&&i!==r)return!0;return!1};Yi.prototype.sibling=function(){return new Yi(this.parent,this.base)};var pt=function(e){this.parser=e,this.validFlags="gim"+(e.options.ecmaVersion>=6?"uy":"")+(e.options.ecmaVersion>=9?"s":"")+(e.options.ecmaVersion>=13?"d":"")+(e.options.ecmaVersion>=15?"v":""),this.unicodeProperties=da[e.options.ecmaVersion>=14?14:e.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};pt.prototype.reset=function(e,i,r){var n=r.indexOf("v")!==-1,a=r.indexOf("u")!==-1;this.start=e|0,this.source=i+"",this.flags=r,n&&this.parser.options.ecmaVersion>=15?(this.switchU=!0,this.switchV=!0,this.switchN=!0):(this.switchU=a&&this.parser.options.ecmaVersion>=6,this.switchV=!1,this.switchN=a&&this.parser.options.ecmaVersion>=9)};pt.prototype.raise=function(e){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+e)};pt.prototype.at=function(e,i){i===void 0&&(i=!1);var r=this.source,n=r.length;if(e>=n)return-1;var a=r.charCodeAt(e);if(!(i||this.switchU)||a<=55295||a>=57344||e+1>=n)return a;var s=r.charCodeAt(e+1);return s>=56320&&s<=57343?(a<<10)+s-56613888:a};pt.prototype.nextIndex=function(e,i){i===void 0&&(i=!1);var r=this.source,n=r.length;if(e>=n)return n;var a=r.charCodeAt(e),s;return!(i||this.switchU)||a<=55295||a>=57344||e+1>=n||(s=r.charCodeAt(e+1))<56320||s>57343?e+1:e+2};pt.prototype.current=function(e){return e===void 0&&(e=!1),this.at(this.pos,e)};pt.prototype.lookahead=function(e){return e===void 0&&(e=!1),this.at(this.nextIndex(this.pos,e),e)};pt.prototype.advance=function(e){e===void 0&&(e=!1),this.pos=this.nextIndex(this.pos,e)};pt.prototype.eat=function(e,i){return i===void 0&&(i=!1),this.current(i)===e?(this.advance(i),!0):!1};pt.prototype.eatChars=function(e,i){i===void 0&&(i=!1);for(var r=this.pos,n=0,a=e;n<a.length;n+=1){var s=a[n],o=this.at(r,i);if(o===-1||o!==s)return!1;r=this.nextIndex(r,i)}return this.pos=r,!0};O.validateRegExpFlags=function(t){for(var e=t.validFlags,i=t.flags,r=!1,n=!1,a=0;a<i.length;a++){var s=i.charAt(a);e.indexOf(s)===-1&&this.raise(t.start,"Invalid regular expression flag"),i.indexOf(s,a+1)>-1&&this.raise(t.start,"Duplicate regular expression flag"),s==="u"&&(r=!0),s==="v"&&(n=!0)}this.options.ecmaVersion>=15&&r&&n&&this.raise(t.start,"Invalid regular expression flag")};function Xm(t){for(var e in t)return!0;return!1}O.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&Xm(t.groupNames)&&(t.switchN=!0,this.regexp_pattern(t))};O.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,i=t.backReferenceNames;e<i.length;e+=1){var r=i[e];t.groupNames[r]||t.raise("Invalid named capture referenced")}};O.regexp_disjunction=function(t){var e=this.options.ecmaVersion>=16;for(e&&(t.branchID=new Yi(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")};O.regexp_alternative=function(t){for(;t.pos<t.source.length&&this.regexp_eatTerm(t););};O.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};O.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 i=!1;if(this.options.ecmaVersion>=9&&(i=t.eat(60)),t.eat(61)||t.eat(33))return this.regexp_disjunction(t),t.eat(41)||t.raise("Unterminated group"),t.lastAssertionIsQuantifiable=!i,!0}return t.pos=e,!1};O.regexp_eatQuantifier=function(t,e){return e===void 0&&(e=!1),this.regexp_eatQuantifierPrefix(t,e)?(t.eat(63),!0):!1};O.regexp_eatQuantifierPrefix=function(t,e){return t.eat(42)||t.eat(43)||t.eat(63)||this.regexp_eatBracedQuantifier(t,e)};O.regexp_eatBracedQuantifier=function(t,e){var i=t.pos;if(t.eat(123)){var r=0,n=-1;if(this.regexp_eatDecimalDigits(t)&&(r=t.lastIntValue,t.eat(44)&&this.regexp_eatDecimalDigits(t)&&(n=t.lastIntValue),t.eat(125)))return n!==-1&&n<r&&!e&&t.raise("numbers out of order in {} quantifier"),!0;t.switchU&&!e&&t.raise("Incomplete quantifier"),t.pos=i}return!1};O.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)};O.regexp_eatReverseSolidusAtomEscape=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatAtomEscape(t))return!0;t.pos=e}return!1};O.regexp_eatUncapturingGroup=function(t){var e=t.pos;if(t.eat(40)){if(t.eat(63)){if(this.options.ecmaVersion>=16){var i=this.regexp_eatModifiers(t),r=t.eat(45);if(i||r){for(var n=0;n<i.length;n++){var a=i.charAt(n);i.indexOf(a,n+1)>-1&&t.raise("Duplicate regular expression modifiers")}if(r){var s=this.regexp_eatModifiers(t);!i&&!s&&t.current()===58&&t.raise("Invalid regular expression modifiers");for(var o=0;o<s.length;o++){var l=s.charAt(o);(s.indexOf(l,o+1)>-1||i.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};O.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};O.regexp_eatModifiers=function(t){for(var e="",i=0;(i=t.current())!==-1&&Qm(i);)e+=xt(i),t.advance();return e};function Qm(t){return t===105||t===109||t===115}O.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)};O.regexp_eatInvalidBracedQuantifier=function(t){return this.regexp_eatBracedQuantifier(t,!0)&&t.raise("Nothing to repeat"),!1};O.regexp_eatSyntaxCharacter=function(t){var e=t.current();return ma(e)?(t.lastIntValue=e,t.advance(),!0):!1};function ma(t){return t===36||t>=40&&t<=43||t===46||t===63||t>=91&&t<=94||t>=123&&t<=125}O.regexp_eatPatternCharacters=function(t){for(var e=t.pos,i=0;(i=t.current())!==-1&&!ma(i);)t.advance();return t.pos!==e};O.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};O.regexp_groupSpecifier=function(t){if(t.eat(63)){this.regexp_eatGroupName(t)||t.raise("Invalid group");var e=this.options.ecmaVersion>=16,i=t.groupNames[t.lastStringValue];if(i)if(e)for(var r=0,n=i;r<n.length;r+=1){var a=n[r];a.separatedFrom(t.branchID)||t.raise("Duplicate capture group name")}else t.raise("Duplicate capture group name");e?(i||(t.groupNames[t.lastStringValue]=[])).push(t.branchID):t.groupNames[t.lastStringValue]=!0}};O.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};O.regexp_eatRegExpIdentifierName=function(t){if(t.lastStringValue="",this.regexp_eatRegExpIdentifierStart(t)){for(t.lastStringValue+=xt(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=xt(t.lastIntValue);return!0}return!1};O.regexp_eatRegExpIdentifierStart=function(t){var e=t.pos,i=this.options.ecmaVersion>=11,r=t.current(i);return t.advance(i),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,i)&&(r=t.lastIntValue),Zm(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function Zm(t){return ht(t,!0)||t===36||t===95}O.regexp_eatRegExpIdentifierPart=function(t){var e=t.pos,i=this.options.ecmaVersion>=11,r=t.current(i);return t.advance(i),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,i)&&(r=t.lastIntValue),Jm(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function Jm(t){return kt(t,!0)||t===36||t===95||t===8204||t===8205}O.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)};O.regexp_eatBackReference=function(t){var e=t.pos;if(this.regexp_eatDecimalEscape(t)){var i=t.lastIntValue;if(t.switchU)return i>t.maxBackReference&&(t.maxBackReference=i),!0;if(i<=t.numCapturingParens)return!0;t.pos=e}return!1};O.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};O.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)};O.regexp_eatCControlLetter=function(t){var e=t.pos;if(t.eat(99)){if(this.regexp_eatControlLetter(t))return!0;t.pos=e}return!1};O.regexp_eatZero=function(t){return t.current()===48&&!or(t.lookahead())?(t.lastIntValue=0,t.advance(),!0):!1};O.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};O.regexp_eatControlLetter=function(t){var e=t.current();return ya(e)?(t.lastIntValue=e%32,t.advance(),!0):!1};function ya(t){return t>=65&&t<=90||t>=97&&t<=122}O.regexp_eatRegExpUnicodeEscapeSequence=function(t,e){e===void 0&&(e=!1);var i=t.pos,r=e||t.switchU;if(t.eat(117)){if(this.regexp_eatFixedHexDigits(t,4)){var n=t.lastIntValue;if(r&&n>=55296&&n<=56319){var a=t.pos;if(t.eat(92)&&t.eat(117)&&this.regexp_eatFixedHexDigits(t,4)){var s=t.lastIntValue;if(s>=56320&&s<=57343)return t.lastIntValue=(n-55296)*1024+(s-56320)+65536,!0}t.pos=a,t.lastIntValue=n}return!0}if(r&&t.eat(123)&&this.regexp_eatHexDigits(t)&&t.eat(125)&&ey(t.lastIntValue))return!0;r&&t.raise("Invalid unicode escape"),t.pos=i}return!1};function ey(t){return t>=0&&t<=1114111}O.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};O.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 _a=0,bt=1,He=2;O.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(ty(e))return t.lastIntValue=-1,t.advance(),bt;var i=!1;if(t.switchU&&this.options.ecmaVersion>=9&&((i=e===80)||e===112)){t.lastIntValue=-1,t.advance();var r;if(t.eat(123)&&(r=this.regexp_eatUnicodePropertyValueExpression(t))&&t.eat(125))return i&&r===He&&t.raise("Invalid property name"),r;t.raise("Invalid property name")}return _a};function ty(t){return t===100||t===68||t===115||t===83||t===119||t===87}O.regexp_eatUnicodePropertyValueExpression=function(t){var e=t.pos;if(this.regexp_eatUnicodePropertyName(t)&&t.eat(61)){var i=t.lastStringValue;if(this.regexp_eatUnicodePropertyValue(t)){var r=t.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(t,i,r),bt}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var n=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,n)}return _a};O.regexp_validateUnicodePropertyNameAndValue=function(t,e,i){ni(t.unicodeProperties.nonBinary,e)||t.raise("Invalid property name"),t.unicodeProperties.nonBinary[e].test(i)||t.raise("Invalid property value")};O.regexp_validateUnicodePropertyNameOrValue=function(t,e){if(t.unicodeProperties.binary.test(e))return bt;if(t.switchV&&t.unicodeProperties.binaryOfStrings.test(e))return He;t.raise("Invalid property name")};O.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";ga(e=t.current());)t.lastStringValue+=xt(e),t.advance();return t.lastStringValue!==""};function ga(t){return ya(t)||t===95}O.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";iy(e=t.current());)t.lastStringValue+=xt(e),t.advance();return t.lastStringValue!==""};function iy(t){return ga(t)||or(t)}O.regexp_eatLoneUnicodePropertyNameOrValue=function(t){return this.regexp_eatUnicodePropertyValue(t)};O.regexp_eatCharacterClass=function(t){if(t.eat(91)){var e=t.eat(94),i=this.regexp_classContents(t);return t.eat(93)||t.raise("Unterminated character class"),e&&i===He&&t.raise("Negated character class may contain strings"),!0}return!1};O.regexp_classContents=function(t){return t.current()===93?bt:t.switchV?this.regexp_classSetExpression(t):(this.regexp_nonEmptyClassRanges(t),bt)};O.regexp_nonEmptyClassRanges=function(t){for(;this.regexp_eatClassAtom(t);){var e=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassAtom(t)){var i=t.lastIntValue;t.switchU&&(e===-1||i===-1)&&t.raise("Invalid character class"),e!==-1&&i!==-1&&e>i&&t.raise("Range out of order in character class")}}};O.regexp_eatClassAtom=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatClassEscape(t))return!0;if(t.switchU){var i=t.current();(i===99||va(i))&&t.raise("Invalid class escape"),t.raise("Invalid escape")}t.pos=e}var r=t.current();return r!==93?(t.lastIntValue=r,t.advance(),!0):!1};O.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)};O.regexp_classSetExpression=function(t){var e=bt,i;if(!this.regexp_eatClassSetRange(t))if(i=this.regexp_eatClassSetOperand(t)){i===He&&(e=He);for(var r=t.pos;t.eatChars([38,38]);){if(t.current()!==38&&(i=this.regexp_eatClassSetOperand(t))){i!==He&&(e=bt);continue}t.raise("Invalid character in character class")}if(r!==t.pos)return e;for(;t.eatChars([45,45]);)this.regexp_eatClassSetOperand(t)||t.raise("Invalid character in character class");if(r!==t.pos)return e}else t.raise("Invalid character in character class");for(;;)if(!this.regexp_eatClassSetRange(t)){if(i=this.regexp_eatClassSetOperand(t),!i)return e;i===He&&(e=He)}};O.regexp_eatClassSetRange=function(t){var e=t.pos;if(this.regexp_eatClassSetCharacter(t)){var i=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassSetCharacter(t)){var r=t.lastIntValue;return i!==-1&&r!==-1&&i>r&&t.raise("Range out of order in character class"),!0}t.pos=e}return!1};O.regexp_eatClassSetOperand=function(t){return this.regexp_eatClassSetCharacter(t)?bt:this.regexp_eatClassStringDisjunction(t)||this.regexp_eatNestedClass(t)};O.regexp_eatNestedClass=function(t){var e=t.pos;if(t.eat(91)){var i=t.eat(94),r=this.regexp_classContents(t);if(t.eat(93))return i&&r===He&&t.raise("Negated character class may contain strings"),r;t.pos=e}if(t.eat(92)){var n=this.regexp_eatCharacterClassEscape(t);if(n)return n;t.pos=e}return null};O.regexp_eatClassStringDisjunction=function(t){var e=t.pos;if(t.eatChars([92,113])){if(t.eat(123)){var i=this.regexp_classStringDisjunctionContents(t);if(t.eat(125))return i}else t.raise("Invalid escape");t.pos=e}return null};O.regexp_classStringDisjunctionContents=function(t){for(var e=this.regexp_classString(t);t.eat(124);)this.regexp_classString(t)===He&&(e=He);return e};O.regexp_classString=function(t){for(var e=0;this.regexp_eatClassSetCharacter(t);)e++;return e===1?bt:He};O.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 i=t.current();return i<0||i===t.lookahead()&&ry(i)||ny(i)?!1:(t.advance(),t.lastIntValue=i,!0)};function ry(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 ny(t){return t===40||t===41||t===45||t===47||t>=91&&t<=93||t>=123&&t<=125}O.regexp_eatClassSetReservedPunctuator=function(t){var e=t.current();return sy(e)?(t.lastIntValue=e,t.advance(),!0):!1};function sy(t){return t===33||t===35||t===37||t===38||t===44||t===45||t>=58&&t<=62||t===64||t===96||t===126}O.regexp_eatClassControlLetter=function(t){var e=t.current();return or(e)||e===95?(t.lastIntValue=e%32,t.advance(),!0):!1};O.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};O.regexp_eatDecimalDigits=function(t){var e=t.pos,i=0;for(t.lastIntValue=0;or(i=t.current());)t.lastIntValue=10*t.lastIntValue+(i-48),t.advance();return t.pos!==e};function or(t){return t>=48&&t<=57}O.regexp_eatHexDigits=function(t){var e=t.pos,i=0;for(t.lastIntValue=0;xa(i=t.current());)t.lastIntValue=16*t.lastIntValue+ba(i),t.advance();return t.pos!==e};function xa(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function ba(t){return t>=65&&t<=70?10+(t-65):t>=97&&t<=102?10+(t-97):t-48}O.regexp_eatLegacyOctalEscapeSequence=function(t){if(this.regexp_eatOctalDigit(t)){var e=t.lastIntValue;if(this.regexp_eatOctalDigit(t)){var i=t.lastIntValue;e<=3&&this.regexp_eatOctalDigit(t)?t.lastIntValue=e*64+i*8+t.lastIntValue:t.lastIntValue=e*8+i}else t.lastIntValue=e;return!0}return!1};O.regexp_eatOctalDigit=function(t){var e=t.current();return va(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)};function va(t){return t>=48&&t<=55}O.regexp_eatFixedHexDigits=function(t,e){var i=t.pos;t.lastIntValue=0;for(var r=0;r<e;++r){var n=t.current();if(!xa(n))return t.pos=i,!1;t.lastIntValue=16*t.lastIntValue+ba(n),t.advance()}return!0};var Yr=function(e){this.type=e.type,this.value=e.value,this.start=e.start,this.end=e.end,e.options.locations&&(this.loc=new ir(e,e.startLoc,e.endLoc)),e.options.ranges&&(this.range=[e.start,e.end])},H=ye.prototype;H.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 Yr(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()};H.getToken=function(){return this.next(),new Yr(this)};typeof Symbol<"u"&&(H[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===_.eof,value:e}}}});H.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(_.eof);if(t.override)return t.override(this);this.readToken(this.fullCharCodeAtPos())};H.readToken=function(t){return ht(t,this.options.ecmaVersion>=6)||t===92?this.readWord():this.getTokenFromCode(t)};H.fullCharCodeAt=function(t){var e=this.input.charCodeAt(t);if(e<=55295||e>=56320)return e;var i=this.input.charCodeAt(t+1);return i<=56319||i>=57344?e:(e<<10)+i-56613888};H.fullCharCodeAtPos=function(){return this.fullCharCodeAt(this.pos)};H.skipBlockComment=function(){var t=this.options.onComment&&this.curPosition(),e=this.pos,i=this.input.indexOf("*/",this.pos+=2);if(i===-1&&this.raise(this.pos-2,"Unterminated comment"),this.pos=i+2,this.options.locations)for(var r=void 0,n=e;(r=qs(this.input,n,this.pos))>-1;)++this.curLine,n=this.lineStart=r;this.options.onComment&&this.options.onComment(!0,this.input.slice(e+2,i),e,this.pos,t,this.curPosition())};H.skipLineComment=function(t){for(var e=this.pos,i=this.options.onComment&&this.curPosition(),r=this.input.charCodeAt(this.pos+=t);this.pos<this.input.length&&!ri(r);)r=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(e+t,this.pos),e,this.pos,i,this.curPosition())};H.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&&zs.test(String.fromCharCode(t)))++this.pos;else break e}}};H.finishToken=function(t,e){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var i=this.type;this.type=t,this.value=e,this.updateContext(i)};H.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(_.ellipsis)):(++this.pos,this.finishToken(_.dot))};H.readToken_slash=function(){var t=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):t===61?this.finishOp(_.assign,2):this.finishOp(_.slash,1)};H.readToken_mult_modulo_exp=function(t){var e=this.input.charCodeAt(this.pos+1),i=1,r=t===42?_.star:_.modulo;return this.options.ecmaVersion>=7&&t===42&&e===42&&(++i,r=_.starstar,e=this.input.charCodeAt(this.pos+2)),e===61?this.finishOp(_.assign,i+1):this.finishOp(r,i)};H.readToken_pipe_amp=function(t){var e=this.input.charCodeAt(this.pos+1);if(e===t){if(this.options.ecmaVersion>=12){var i=this.input.charCodeAt(this.pos+2);if(i===61)return this.finishOp(_.assign,3)}return this.finishOp(t===124?_.logicalOR:_.logicalAND,2)}return e===61?this.finishOp(_.assign,2):this.finishOp(t===124?_.bitwiseOR:_.bitwiseAND,1)};H.readToken_caret=function(){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(_.assign,2):this.finishOp(_.bitwiseXOR,1)};H.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||Ve.test(this.input.slice(this.lastTokEnd,this.pos)))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(_.incDec,2):e===61?this.finishOp(_.assign,2):this.finishOp(_.plusMin,1)};H.readToken_lt_gt=function(t){var e=this.input.charCodeAt(this.pos+1),i=1;return e===t?(i=t===62&&this.input.charCodeAt(this.pos+2)===62?3:2,this.input.charCodeAt(this.pos+i)===61?this.finishOp(_.assign,i+1):this.finishOp(_.bitShift,i)):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&&(i=2),this.finishOp(_.relational,i))};H.readToken_eq_excl=function(t){var e=this.input.charCodeAt(this.pos+1);return e===61?this.finishOp(_.equality,this.input.charCodeAt(this.pos+2)===61?3:2):t===61&&e===62&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(_.arrow)):this.finishOp(t===61?_.eq:_.prefix,1)};H.readToken_question=function(){var t=this.options.ecmaVersion;if(t>=11){var e=this.input.charCodeAt(this.pos+1);if(e===46){var i=this.input.charCodeAt(this.pos+2);if(i<48||i>57)return this.finishOp(_.questionDot,2)}if(e===63){if(t>=12){var r=this.input.charCodeAt(this.pos+2);if(r===61)return this.finishOp(_.assign,3)}return this.finishOp(_.coalesce,2)}}return this.finishOp(_.question,1)};H.readToken_numberSign=function(){var t=this.options.ecmaVersion,e=35;if(t>=13&&(++this.pos,e=this.fullCharCodeAtPos(),ht(e,!0)||e===92))return this.finishToken(_.privateId,this.readWord1());this.raise(this.pos,"Unexpected character '"+xt(e)+"'")};H.getTokenFromCode=function(t){switch(t){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(_.parenL);case 41:return++this.pos,this.finishToken(_.parenR);case 59:return++this.pos,this.finishToken(_.semi);case 44:return++this.pos,this.finishToken(_.comma);case 91:return++this.pos,this.finishToken(_.bracketL);case 93:return++this.pos,this.finishToken(_.bracketR);case 123:return++this.pos,this.finishToken(_.braceL);case 125:return++this.pos,this.finishToken(_.braceR);case 58:return++this.pos,this.finishToken(_.colon);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(_.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(_.prefix,1);case 35:return this.readToken_numberSign()}this.raise(this.pos,"Unexpected character '"+xt(t)+"'")};H.finishOp=function(t,e){var i=this.input.slice(this.pos,this.pos+e);return this.pos+=e,this.finishToken(t,i)};H.readRegexp=function(){for(var t,e,i=this.pos;;){this.pos>=this.input.length&&this.raise(i,"Unterminated regular expression");var r=this.input.charAt(this.pos);if(Ve.test(r)&&this.raise(i,"Unterminated regular expression"),t)t=!1;else{if(r==="[")e=!0;else if(r==="]"&&e)e=!1;else if(r==="/"&&!e)break;t=r==="\\"}++this.pos}var n=this.input.slice(i,this.pos);++this.pos;var a=this.pos,s=this.readWord1();this.containsEsc&&this.unexpected(a);var o=this.regexpState||(this.regexpState=new pt(this));o.reset(i,n,s),this.validateRegExpFlags(o),this.validateRegExpPattern(o);var l=null;try{l=new RegExp(n,s)}catch{}return this.finishToken(_.regexp,{pattern:n,flags:s,value:l})};H.readInt=function(t,e,i){for(var r=this.options.ecmaVersion>=12&&e===void 0,n=i&&this.input.charCodeAt(this.pos)===48,a=this.pos,s=0,o=0,l=0,c=e??1/0;l<c;++l,++this.pos){var u=this.input.charCodeAt(this.pos),p=void 0;if(r&&u===95){n&&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?p=u-97+10:u>=65?p=u-65+10:u>=48&&u<=57?p=u-48:p=1/0,p>=t)break;o=u,s=s*t+p}return r&&o===95&&this.raiseRecoverable(this.pos-1,"Numeric separator is not allowed at the last of digits"),this.pos===a||e!=null&&this.pos-a!==e?null:s};function ay(t,e){return e?parseInt(t,8):parseFloat(t.replace(/_/g,""))}function wa(t){return typeof BigInt!="function"?null:BigInt(t.replace(/_/g,""))}H.readRadixNumber=function(t){var e=this.pos;this.pos+=2;var i=this.readInt(t);return i==null&&this.raise(this.start+2,"Expected number in radix "+t),this.options.ecmaVersion>=11&&this.input.charCodeAt(this.pos)===110?(i=wa(this.input.slice(e,this.pos)),++this.pos):ht(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(_.num,i)};H.readNumber=function(t){var e=this.pos;!t&&this.readInt(10,void 0,!0)===null&&this.raise(e,"Invalid number");var i=this.pos-e>=2&&this.input.charCodeAt(e)===48;i&&this.strict&&this.raise(e,"Invalid number");var r=this.input.charCodeAt(this.pos);if(!i&&!t&&this.options.ecmaVersion>=11&&r===110){var n=wa(this.input.slice(e,this.pos));return++this.pos,ht(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(_.num,n)}i&&/[89]/.test(this.input.slice(e,this.pos))&&(i=!1),r===46&&!i&&(++this.pos,this.readInt(10),r=this.input.charCodeAt(this.pos)),(r===69||r===101)&&!i&&(r=this.input.charCodeAt(++this.pos),(r===43||r===45)&&++this.pos,this.readInt(10)===null&&this.raise(e,"Invalid number")),ht(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var a=ay(this.input.slice(e,this.pos),i);return this.finishToken(_.num,a)};H.readCodePoint=function(){var t=this.input.charCodeAt(this.pos),e;if(t===123){this.options.ecmaVersion<6&&this.unexpected();var i=++this.pos;e=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,e>1114111&&this.invalidStringToken(i,"Code point out of bounds")}else e=this.readHexChar(4);return e};H.readString=function(t){for(var e="",i=++this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated string constant");var r=this.input.charCodeAt(this.pos);if(r===t)break;r===92?(e+=this.input.slice(i,this.pos),e+=this.readEscapedChar(!1),i=this.pos):r===8232||r===8233?(this.options.ecmaVersion<10&&this.raise(this.start,"Unterminated string constant"),++this.pos,this.options.locations&&(this.curLine++,this.lineStart=this.pos)):(ri(r)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return e+=this.input.slice(i,this.pos++),this.finishToken(_.string,e)};var Sa={};H.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t===Sa)this.readInvalidTemplateToken();else throw t}this.inTemplateElement=!1};H.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw Sa;this.raise(t,e)};H.readTmplToken=function(){for(var t="",e=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var i=this.input.charCodeAt(this.pos);if(i===96||i===36&&this.input.charCodeAt(this.pos+1)===123)return this.pos===this.start&&(this.type===_.template||this.type===_.invalidTemplate)?i===36?(this.pos+=2,this.finishToken(_.dollarBraceL)):(++this.pos,this.finishToken(_.backQuote)):(t+=this.input.slice(e,this.pos),this.finishToken(_.template,t));if(i===92)t+=this.input.slice(e,this.pos),t+=this.readEscapedChar(!0),e=this.pos;else if(ri(i)){switch(t+=this.input.slice(e,this.pos),++this.pos,i){case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:t+=`
7
+ `;break;default:t+=String.fromCharCode(i);break}this.options.locations&&(++this.curLine,this.lineStart=this.pos),e=this.pos}else++this.pos}};H.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(_.invalidTemplate,this.input.slice(this.start,this.pos));case"\r":this.input[this.pos+1]===`
8
8
  `&&++this.pos;case`
9
- `:case"\u2028":case"\u2029":++this.curLine,this.lineStart=this.pos+1;break}this.raise(this.start,"Unterminated template")};K.readEscapedChar=function(t){var e=this.input.charCodeAt(++this.pos);switch(++this.pos,e){case 110:return`
10
- `;case 114:return"\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return gt(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 i=this.pos-1;this.invalidStringToken(i,"Invalid escape sequence in template string")}default:if(e>=48&&e<=55){var r=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],n=parseInt(r,8);return n>255&&(r=r.slice(0,-1),n=parseInt(r,8)),this.pos+=r.length-1,e=this.input.charCodeAt(this.pos),(r!=="0"||e===56||e===57)&&(this.strict||t)&&this.invalidStringToken(this.pos-1-r.length,t?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(n)}return ii(e)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),""):String.fromCharCode(e)}};K.readHexChar=function(t){var e=this.pos,i=this.readInt(16,t);return i===null&&this.invalidStringToken(e,"Bad character escape sequence"),i};K.readWord1=function(){this.containsEsc=!1;for(var t="",e=!0,i=this.pos,r=this.options.ecmaVersion>=6;this.pos<this.input.length;){var n=this.fullCharCodeAtPos();if(kt(n,r))this.pos+=n<=65535?1:2;else if(n===92){this.containsEsc=!0,t+=this.input.slice(i,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?ut:kt)(a,r)||this.invalidStringToken(s,"Invalid Unicode escape"),t+=gt(a),i=this.pos}else break;e=!1}return t+this.input.slice(i,this.pos)};K.readWord=function(){var t=this.readWord1(),e=_.name;return this.keywords.test(t)&&(e=Lr[t]),this.finishToken(e,t)};var Jm="8.16.0";pe.acorn={Parser:pe,version:Jm,defaultOptions:Cr,Position:xi,SourceLocation:Qi,getLineInfo:Ws,Node:ir,TokenType:Y,tokTypes:_,keywordTypes:Lr,TokContext:Je,tokContexts:re,isIdentifierChar:kt,isIdentifierStart:ut,Token:zr,isNewLine:ii,lineBreak:Oe,lineBreakG:vm,nonASCIIwhitespace:Bs};function Kr(t,e){return pe.parse(t,e)}const{stringify:ey}=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");const ki={"||":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},tt=17,ty={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:tt,ClassExpression:tt,FunctionExpression:tt,ObjectExpression:tt,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function Yt(t,e){const{generator:i}=t;if(t.write("("),e!=null&&e.length>0){i[e[0].type](e[0],t);const{length:r}=e;for(let n=1;n<r;n++){const s=e[n];t.write(", "),i[s.type](s,t)}}t.write(")")}function xa(t,e,i,r){const n=t.expressionsPrecedence[e.type];if(n===tt)return!0;const s=t.expressionsPrecedence[i.type];return n!==s?!r&&n===15&&s===14&&i.operator==="**"||n<s:n!==13&&n!==14?!1:e.operator==="**"&&i.operator==="**"?!r:n===13&&s===13&&(e.operator==="??"||i.operator==="??")?!0:r?ki[e.operator]<=ki[i.operator]:ki[e.operator]<ki[i.operator]}function Ti(t,e,i,r){const{generator:n}=t;xa(t,e,i,r)?(t.write("("),n[e.type](e,t),t.write(")")):n[e.type](e,t)}function iy(t,e,i,r){const n=e.split(`
11
- `),s=n.length-1;if(t.write(n[0].trim()),s>0){t.write(r);for(let a=1;a<s;a++)t.write(i+n[a].trim()+r);t.write(i+n[s].trim())}}function Ce(t,e,i,r){const{length:n}=e;for(let s=0;s<n;s++){const a=e[s];t.write(i),a.type[0]==="L"?t.write("// "+a.value.trim()+`
12
- `,a):(t.write("/*"),iy(t,a.value,i,r),t.write("*/"+r))}}function ry(t){let e=t;for(;e!=null;){const{type:i}=e;if(i[0]==="C"&&i[1]==="a")return!0;if(i[0]==="M"&&i[1]==="e"&&i[2]==="m")e=e.object;else return!1}}function fr(t,e){const{generator:i}=t,{declarations:r}=e;t.write(e.kind+" ");const{length:n}=r;if(n>0){i.VariableDeclarator(r[0],t);for(let s=1;s<n;s++)t.write(", "),i.VariableDeclarator(r[s],t)}}let Nn,Cn,In,kn,Tn,An;const Hr={Program(t,e){const i=e.indent.repeat(e.indentLevel),{lineEnd:r,writeComments:n}=e;n&&t.comments!=null&&Ce(e,t.comments,i,r);const s=t.body,{length:a}=s;for(let o=0;o<a;o++){const l=s[o];n&&l.comments!=null&&Ce(e,l.comments,i,r),e.write(i),this[l.type](l,e),e.write(r)}n&&t.trailingComments!=null&&Ce(e,t.trailingComments,i,r)},BlockStatement:An=function(t,e){const i=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:n}=e,s=i+e.indent;e.write("{");const a=t.body;if(a!=null&&a.length>0){e.write(r),n&&t.comments!=null&&Ce(e,t.comments,s,r);const{length:o}=a;for(let l=0;l<o;l++){const c=a[l];n&&c.comments!=null&&Ce(e,c.comments,s,r),e.write(s),this[c.type](c,e),e.write(r)}e.write(i)}else n&&t.comments!=null&&(e.write(r),Ce(e,t.comments,s,r),e.write(i));n&&t.trailingComments!=null&&Ce(e,t.trailingComments,s,r),e.write("}"),e.indentLevel--},ClassBody:An,StaticBlock(t,e){e.write("static "),this.BlockStatement(t,e)},EmptyStatement(t,e){e.write(";")},ExpressionStatement(t,e){const i=e.expressionsPrecedence[t.expression.type];i===tt||i===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){const i=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:n}=e;e.indentLevel++;const s=i+e.indent,a=s+e.indent;e.write("switch ("),this[t.discriminant.type](t.discriminant,e),e.write(") {"+r);const{cases:o}=t,{length:l}=o;for(let c=0;c<l;c++){const u=o[c];n&&u.comments!=null&&Ce(e,u.comments,s,r),u.test?(e.write(s+"case "),this[u.test.type](u.test,e),e.write(":"+r)):e.write(s+"default:"+r);const{consequent:p}=u,{length:h}=p;for(let f=0;f<h;f++){const d=p[f];n&&d.comments!=null&&Ce(e,d.comments,a,r),e.write(a),this[d.type](d,e),e.write(r)}}e.indentLevel-=2,e.write(i+"}")},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){const{handler:i}=t;i.param==null?e.write(" catch "):(e.write(" catch ("),this[i.param.type](i.param,e),e.write(") ")),this[i.body.type](i.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){const{init:i}=t;i.type[0]==="V"?fr(e,i):this[i.type](i,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:Nn=function(t,e){e.write(`for ${t.await?"await ":""}(`);const{left:i}=t;i.type[0]==="V"?fr(e,i):this[i.type](i,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:Nn,DebuggerStatement(t,e){e.write("debugger;",t)},FunctionDeclaration:Cn=function(t,e){e.write((t.async?"async ":"")+(t.generator?"function* ":"function ")+(t.id?t.id.name:""),t),Yt(e,t.params),e.write(" "),this[t.body.type](t.body,e)},FunctionExpression:Cn,VariableDeclaration(t,e){fr(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 ");const{superClass:i}=t,{type:r}=i,n=e.expressionsPrecedence[r];(r[0]!=="C"||r[1]!=="l"||r[5]!=="E")&&(n===tt||n<e.expressionsPrecedence.ClassExpression)?(e.write("("),this[t.superClass.type](i,e),e.write(")")):this[i.type](i,e),e.write(" ")}this.ClassBody(t.body,e)},ImportDeclaration(t,e){e.write("import ");const{specifiers:i,attributes:r}=t,{length:n}=i;let s=0;if(n>0){for(;s<n;){s>0&&e.write(", ");const a=i[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<n){for(e.write("{");;){const a=i[s],{name:o}=a.imported;if(e.write(o,a),o!==a.local.name&&e.write(" as "+a.local.name),++s<n)e.write(", ");else break}e.write("}")}e.write(" from ")}if(this.Literal(t.source,e),r&&r.length>0){e.write(" with { ");for(let a=0;a<r.length;a++)this.ImportAttribute(r[a],e),a<r.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("{");const{specifiers:i}=t,{length:r}=i;if(r>0)for(let n=0;;){const s=i[n],{name:a}=s.local;if(e.write(a,s),a!==s.exported.name&&e.write(" as "+s.exported.name),++n<r)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 n=0;n<t.attributes.length;n++)this.ImportAttribute(t.attributes[n],e),n<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 i=0;i<t.attributes.length;i++)this.ImportAttribute(t.attributes[i],e),i<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")},MethodDefinition(t,e){t.static&&e.write("static ");const i=t.kind[0];(i==="g"||i==="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),Yt(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);const{params:i}=t;i!=null&&(i.length===1&&i[0].type[0]==="I"?e.write(i[0].name,i[0]):Yt(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:In=function(t,e){e.write("..."),this[t.argument.type](t.argument,e)},SpreadElement:In,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),Ti(e,t.argument,t)},TemplateLiteral(t,e){const{quasis:i,expressions:r}=t;e.write("`");const{length:n}=r;for(let a=0;a<n;a++){const o=r[a],l=i[a];e.write(l.value.raw,l),e.write("${"),this[o.type](o,e),e.write("}")}const s=i[i.length-1];e.write(s.value.raw,s),e.write("`")},TemplateElement(t,e){e.write(t.value.raw,t)},TaggedTemplateExpression(t,e){Ti(e,t.tag,t),this[t.quasi.type](t.quasi,e)},ArrayExpression:Tn=function(t,e){if(e.write("["),t.elements.length>0){const{elements:i}=t,{length:r}=i;for(let n=0;;){const s=i[n];if(s!=null&&this[s.type](s,e),++n<r)e.write(", ");else{s==null&&e.write(", ");break}}}e.write("]")},ArrayPattern:Tn,ObjectExpression(t,e){const i=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:n}=e,s=i+e.indent;if(e.write("{"),t.properties.length>0){e.write(r),n&&t.comments!=null&&Ce(e,t.comments,s,r);const a=","+r,{properties:o}=t,{length:l}=o;for(let c=0;;){const u=o[c];if(n&&u.comments!=null&&Ce(e,u.comments,s,r),e.write(s),this[u.type](u,e),++c<l)e.write(a);else break}e.write(r),n&&t.trailingComments!=null&&Ce(e,t.trailingComments,s,r),e.write(i+"}")}else n?t.comments!=null?(e.write(r),Ce(e,t.comments,s,r),t.trailingComments!=null&&Ce(e,t.trailingComments,s,r),e.write(i+"}")):t.trailingComments!=null?(e.write(r),Ce(e,t.trailingComments,s,r),e.write(i+"}")):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){const{properties:i}=t,{length:r}=i;for(let n=0;this[i[n].type](i[n],e),++n<r;)e.write(", ")}e.write("}")},SequenceExpression(t,e){Yt(e,t.expressions)},UnaryExpression(t,e){if(t.prefix){const{operator:i,argument:r,argument:{type:n}}=t;e.write(i);const s=xa(e,r,t);!s&&(i.length>1||n[0]==="U"&&(n[1]==="n"||n[1]==="p")&&r.prefix&&r.operator[0]===i&&(i==="+"||i==="-"))&&e.write(" "),s?(e.write(i.length>1?" (":"("),this[n](r,e),e.write(")")):this[n](r,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:kn=function(t,e){const i=t.operator==="in";i&&e.write("("),Ti(e,t.left,t,!1),e.write(" "+t.operator+" "),Ti(e,t.right,t,!0),i&&e.write(")")},LogicalExpression:kn,ConditionalExpression(t,e){const{test:i}=t,r=e.expressionsPrecedence[i.type];r===tt||r<=e.expressionsPrecedence.ConditionalExpression?(e.write("("),this[i.type](i,e),e.write(")")):this[i.type](i,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 ");const i=e.expressionsPrecedence[t.callee.type];i===tt||i<e.expressionsPrecedence.CallExpression||ry(t.callee)?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),Yt(e,t.arguments)},CallExpression(t,e){const i=e.expressionsPrecedence[t.callee.type];i===tt||i<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("?."),Yt(e,t.arguments)},ChainExpression(t,e){this[t.expression.type](t.expression,e)},MemberExpression(t,e){const i=e.expressionsPrecedence[t.object.type];i===tt||i<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(ey(t.value),t)},RegExpLiteral(t,e){const{regex:i}=t;e.write(`/${i.pattern}/${i.flags}`,t)}},ny={},sy=Hr;class ay{constructor(e){const i=e??ny;this.output="",i.output!=null?(this.output=i.output,this.write=this.writeToStream):this.output="",this.generator=i.generator!=null?i.generator:Hr,this.expressionsPrecedence=i.expressionsPrecedence!=null?i.expressionsPrecedence:ty,this.indent=i.indent!=null?i.indent:" ",this.lineEnd=i.lineEnd!=null?i.lineEnd:`
9
+ `:case"\u2028":case"\u2029":++this.curLine,this.lineStart=this.pos+1;break}this.raise(this.start,"Unterminated template")};H.readEscapedChar=function(t){var e=this.input.charCodeAt(++this.pos);switch(++this.pos,e){case 110:return`
10
+ `;case 114:return"\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return xt(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 i=this.pos-1;this.invalidStringToken(i,"Invalid escape sequence in template string")}default:if(e>=48&&e<=55){var r=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],n=parseInt(r,8);return n>255&&(r=r.slice(0,-1),n=parseInt(r,8)),this.pos+=r.length-1,e=this.input.charCodeAt(this.pos),(r!=="0"||e===56||e===57)&&(this.strict||t)&&this.invalidStringToken(this.pos-1-r.length,t?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(n)}return ri(e)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),""):String.fromCharCode(e)}};H.readHexChar=function(t){var e=this.pos,i=this.readInt(16,t);return i===null&&this.invalidStringToken(e,"Bad character escape sequence"),i};H.readWord1=function(){this.containsEsc=!1;for(var t="",e=!0,i=this.pos,r=this.options.ecmaVersion>=6;this.pos<this.input.length;){var n=this.fullCharCodeAtPos();if(kt(n,r))this.pos+=n<=65535?1:2;else if(n===92){this.containsEsc=!0,t+=this.input.slice(i,this.pos);var a=this.pos;this.input.charCodeAt(++this.pos)!==117&&this.invalidStringToken(this.pos,"Expecting Unicode escape sequence \\uXXXX"),++this.pos;var s=this.readCodePoint();(e?ht:kt)(s,r)||this.invalidStringToken(a,"Invalid Unicode escape"),t+=xt(s),i=this.pos}else break;e=!1}return t+this.input.slice(i,this.pos)};H.readWord=function(){var t=this.readWord1(),e=_.name;return this.keywords.test(t)&&(e=Ur[t]),this.finishToken(e,t)};var oy="8.16.0";ye.acorn={Parser:ye,version:oy,defaultOptions:Pr,Position:xi,SourceLocation:ir,getLineInfo:Hs,Node:ar,TokenType:X,tokTypes:_,keywordTypes:Ur,TokContext:et,tokContexts:ae,isIdentifierChar:kt,isIdentifierStart:ht,Token:Yr,isNewLine:ri,lineBreak:Ve,lineBreakG:Tm,nonASCIIwhitespace:zs};function Xr(t,e){return ye.parse(t,e)}const{stringify:ly}=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");const Ti={"||":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},it=17,cy={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:it,ClassExpression:it,FunctionExpression:it,ObjectExpression:it,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function Qt(t,e){const{generator:i}=t;if(t.write("("),e!=null&&e.length>0){i[e[0].type](e[0],t);const{length:r}=e;for(let n=1;n<r;n++){const a=e[n];t.write(", "),i[a.type](a,t)}}t.write(")")}function Ea(t,e,i,r){const n=t.expressionsPrecedence[e.type];if(n===it)return!0;const a=t.expressionsPrecedence[i.type];return n!==a?!r&&n===15&&a===14&&i.operator==="**"||n<a:n!==13&&n!==14?!1:e.operator==="**"&&i.operator==="**"?!r:n===13&&a===13&&(e.operator==="??"||i.operator==="??")?!0:r?Ti[e.operator]<=Ti[i.operator]:Ti[e.operator]<Ti[i.operator]}function Ai(t,e,i,r){const{generator:n}=t;Ea(t,e,i,r)?(t.write("("),n[e.type](e,t),t.write(")")):n[e.type](e,t)}function uy(t,e,i,r){const n=e.split(`
11
+ `),a=n.length-1;if(t.write(n[0].trim()),a>0){t.write(r);for(let s=1;s<a;s++)t.write(i+n[s].trim()+r);t.write(i+n[a].trim())}}function Te(t,e,i,r){const{length:n}=e;for(let a=0;a<n;a++){const s=e[a];t.write(i),s.type[0]==="L"?t.write("// "+s.value.trim()+`
12
+ `,s):(t.write("/*"),uy(t,s.value,i,r),t.write("*/"+r))}}function hy(t){let e=t;for(;e!=null;){const{type:i}=e;if(i[0]==="C"&&i[1]==="a")return!0;if(i[0]==="M"&&i[1]==="e"&&i[2]==="m")e=e.object;else return!1}}function gr(t,e){const{generator:i}=t,{declarations:r}=e;t.write(e.kind+" ");const{length:n}=r;if(n>0){i.VariableDeclarator(r[0],t);for(let a=1;a<n;a++)t.write(", "),i.VariableDeclarator(r[a],t)}}let kn,Tn,An,Pn,Mn,Dn;const Qr={Program(t,e){const i=e.indent.repeat(e.indentLevel),{lineEnd:r,writeComments:n}=e;n&&t.comments!=null&&Te(e,t.comments,i,r);const a=t.body,{length:s}=a;for(let o=0;o<s;o++){const l=a[o];n&&l.comments!=null&&Te(e,l.comments,i,r),e.write(i),this[l.type](l,e),e.write(r)}n&&t.trailingComments!=null&&Te(e,t.trailingComments,i,r)},BlockStatement:Dn=function(t,e){const i=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:n}=e,a=i+e.indent;e.write("{");const s=t.body;if(s!=null&&s.length>0){e.write(r),n&&t.comments!=null&&Te(e,t.comments,a,r);const{length:o}=s;for(let l=0;l<o;l++){const c=s[l];n&&c.comments!=null&&Te(e,c.comments,a,r),e.write(a),this[c.type](c,e),e.write(r)}e.write(i)}else n&&t.comments!=null&&(e.write(r),Te(e,t.comments,a,r),e.write(i));n&&t.trailingComments!=null&&Te(e,t.trailingComments,a,r),e.write("}"),e.indentLevel--},ClassBody:Dn,StaticBlock(t,e){e.write("static "),this.BlockStatement(t,e)},EmptyStatement(t,e){e.write(";")},ExpressionStatement(t,e){const i=e.expressionsPrecedence[t.expression.type];i===it||i===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){const i=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:n}=e;e.indentLevel++;const a=i+e.indent,s=a+e.indent;e.write("switch ("),this[t.discriminant.type](t.discriminant,e),e.write(") {"+r);const{cases:o}=t,{length:l}=o;for(let c=0;c<l;c++){const u=o[c];n&&u.comments!=null&&Te(e,u.comments,a,r),u.test?(e.write(a+"case "),this[u.test.type](u.test,e),e.write(":"+r)):e.write(a+"default:"+r);const{consequent:p}=u,{length:h}=p;for(let f=0;f<h;f++){const d=p[f];n&&d.comments!=null&&Te(e,d.comments,s,r),e.write(s),this[d.type](d,e),e.write(r)}}e.indentLevel-=2,e.write(i+"}")},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){const{handler:i}=t;i.param==null?e.write(" catch "):(e.write(" catch ("),this[i.param.type](i.param,e),e.write(") ")),this[i.body.type](i.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){const{init:i}=t;i.type[0]==="V"?gr(e,i):this[i.type](i,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:kn=function(t,e){e.write(`for ${t.await?"await ":""}(`);const{left:i}=t;i.type[0]==="V"?gr(e,i):this[i.type](i,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:kn,DebuggerStatement(t,e){e.write("debugger;",t)},FunctionDeclaration:Tn=function(t,e){e.write((t.async?"async ":"")+(t.generator?"function* ":"function ")+(t.id?t.id.name:""),t),Qt(e,t.params),e.write(" "),this[t.body.type](t.body,e)},FunctionExpression:Tn,VariableDeclaration(t,e){gr(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 ");const{superClass:i}=t,{type:r}=i,n=e.expressionsPrecedence[r];(r[0]!=="C"||r[1]!=="l"||r[5]!=="E")&&(n===it||n<e.expressionsPrecedence.ClassExpression)?(e.write("("),this[t.superClass.type](i,e),e.write(")")):this[i.type](i,e),e.write(" ")}this.ClassBody(t.body,e)},ImportDeclaration(t,e){e.write("import ");const{specifiers:i,attributes:r}=t,{length:n}=i;let a=0;if(n>0){for(;a<n;){a>0&&e.write(", ");const s=i[a],o=s.type[6];if(o==="D")e.write(s.local.name,s),a++;else if(o==="N")e.write("* as "+s.local.name,s),a++;else break}if(a<n){for(e.write("{");;){const s=i[a],{name:o}=s.imported;if(e.write(o,s),o!==s.local.name&&e.write(" as "+s.local.name),++a<n)e.write(", ");else break}e.write("}")}e.write(" from ")}if(this.Literal(t.source,e),r&&r.length>0){e.write(" with { ");for(let s=0;s<r.length;s++)this.ImportAttribute(r[s],e),s<r.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("{");const{specifiers:i}=t,{length:r}=i;if(r>0)for(let n=0;;){const a=i[n],{name:s}=a.local;if(e.write(s,a),s!==a.exported.name&&e.write(" as "+a.exported.name),++n<r)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 n=0;n<t.attributes.length;n++)this.ImportAttribute(t.attributes[n],e),n<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 i=0;i<t.attributes.length;i++)this.ImportAttribute(t.attributes[i],e),i<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")},MethodDefinition(t,e){t.static&&e.write("static ");const i=t.kind[0];(i==="g"||i==="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),Qt(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);const{params:i}=t;i!=null&&(i.length===1&&i[0].type[0]==="I"?e.write(i[0].name,i[0]):Qt(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:An=function(t,e){e.write("..."),this[t.argument.type](t.argument,e)},SpreadElement:An,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),Ai(e,t.argument,t)},TemplateLiteral(t,e){const{quasis:i,expressions:r}=t;e.write("`");const{length:n}=r;for(let s=0;s<n;s++){const o=r[s],l=i[s];e.write(l.value.raw,l),e.write("${"),this[o.type](o,e),e.write("}")}const a=i[i.length-1];e.write(a.value.raw,a),e.write("`")},TemplateElement(t,e){e.write(t.value.raw,t)},TaggedTemplateExpression(t,e){Ai(e,t.tag,t),this[t.quasi.type](t.quasi,e)},ArrayExpression:Mn=function(t,e){if(e.write("["),t.elements.length>0){const{elements:i}=t,{length:r}=i;for(let n=0;;){const a=i[n];if(a!=null&&this[a.type](a,e),++n<r)e.write(", ");else{a==null&&e.write(", ");break}}}e.write("]")},ArrayPattern:Mn,ObjectExpression(t,e){const i=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:n}=e,a=i+e.indent;if(e.write("{"),t.properties.length>0){e.write(r),n&&t.comments!=null&&Te(e,t.comments,a,r);const s=","+r,{properties:o}=t,{length:l}=o;for(let c=0;;){const u=o[c];if(n&&u.comments!=null&&Te(e,u.comments,a,r),e.write(a),this[u.type](u,e),++c<l)e.write(s);else break}e.write(r),n&&t.trailingComments!=null&&Te(e,t.trailingComments,a,r),e.write(i+"}")}else n?t.comments!=null?(e.write(r),Te(e,t.comments,a,r),t.trailingComments!=null&&Te(e,t.trailingComments,a,r),e.write(i+"}")):t.trailingComments!=null?(e.write(r),Te(e,t.trailingComments,a,r),e.write(i+"}")):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){const{properties:i}=t,{length:r}=i;for(let n=0;this[i[n].type](i[n],e),++n<r;)e.write(", ")}e.write("}")},SequenceExpression(t,e){Qt(e,t.expressions)},UnaryExpression(t,e){if(t.prefix){const{operator:i,argument:r,argument:{type:n}}=t;e.write(i);const a=Ea(e,r,t);!a&&(i.length>1||n[0]==="U"&&(n[1]==="n"||n[1]==="p")&&r.prefix&&r.operator[0]===i&&(i==="+"||i==="-"))&&e.write(" "),a?(e.write(i.length>1?" (":"("),this[n](r,e),e.write(")")):this[n](r,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:Pn=function(t,e){const i=t.operator==="in";i&&e.write("("),Ai(e,t.left,t,!1),e.write(" "+t.operator+" "),Ai(e,t.right,t,!0),i&&e.write(")")},LogicalExpression:Pn,ConditionalExpression(t,e){const{test:i}=t,r=e.expressionsPrecedence[i.type];r===it||r<=e.expressionsPrecedence.ConditionalExpression?(e.write("("),this[i.type](i,e),e.write(")")):this[i.type](i,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 ");const i=e.expressionsPrecedence[t.callee.type];i===it||i<e.expressionsPrecedence.CallExpression||hy(t.callee)?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),Qt(e,t.arguments)},CallExpression(t,e){const i=e.expressionsPrecedence[t.callee.type];i===it||i<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("?."),Qt(e,t.arguments)},ChainExpression(t,e){this[t.expression.type](t.expression,e)},MemberExpression(t,e){const i=e.expressionsPrecedence[t.object.type];i===it||i<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(ly(t.value),t)},RegExpLiteral(t,e){const{regex:i}=t;e.write(`/${i.pattern}/${i.flags}`,t)}},py={},fy=Qr;class dy{constructor(e){const i=e??py;this.output="",i.output!=null?(this.output=i.output,this.write=this.writeToStream):this.output="",this.generator=i.generator!=null?i.generator:Qr,this.expressionsPrecedence=i.expressionsPrecedence!=null?i.expressionsPrecedence:cy,this.indent=i.indent!=null?i.indent:" ",this.lineEnd=i.lineEnd!=null?i.lineEnd:`
13
13
  `,this.indentLevel=i.startingIndentLevel!=null?i.startingIndentLevel:0,this.writeComments=i.comments?i.comments:!1,i.sourceMap!=null&&(this.write=i.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=i.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`
14
- `).length-1,this.mapping={original:null,generated:this,name:void 0,source:i.sourceMap.file||i.sourceMap._file})}write(e){this.output+=e}writeToStream(e){this.output.write(e)}writeAndMap(e,i){this.output+=e,this.map(e,i)}writeToStreamAndMap(e,i){this.output.write(e),this.map(e,i)}map(e,i){if(i!=null){const{type:s}=i;if(s[0]==="L"&&s[2]==="n"){this.column=0,this.line++;return}if(i.loc!=null){const{mapping:a}=this;a.original=i.loc.start,a.name=i.name,this.sourceMap.addMapping(a)}if(s[0]==="T"&&s[8]==="E"||s[0]==="L"&&s[1]==="i"&&typeof i.value=="string"){const{length:a}=e;let{column:o,line:l}=this;for(let c=0;c<a;c++)e[c]===`
15
- `?(o=0,l++):o++;this.column=o,this.line=l;return}}const{length:r}=e,{lineEnd:n}=this;r>0&&(this.lineEndSize>0&&(n.length===1?e[r-1]===n:e.endsWith(n))?(this.line+=this.lineEndSize,this.column=0):this.column+=r)}toString(){return this.output}}function Gr(t,e){const i=new ay(e);return i.generator[t.type](t,i),i.output}var oy=Object.defineProperty,ly=(t,e,i)=>e in t?oy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,X=(t,e,i)=>ly(t,typeof e!="symbol"?e+"":e,i);const cy=new Set(["Infinity","NaN","undefined","null","true","false"]),uy=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"]);class hy{constructor(){X(this,"scopes",[]),X(this,"scopeTypes",[]),X(this,"scopeCounts",new Map),X(this,"contextBoundVars",new Set),X(this,"arrayPatternElements",new Set),X(this,"rootParams",new Set),X(this,"localSeriesVars",new Set),X(this,"varKinds",new Map),X(this,"loopVars",new Set),X(this,"loopVarNames",new Map),X(this,"paramIdCounter",0),X(this,"cacheIdCounter",0),X(this,"tempVarCounter",0),X(this,"taCallIdCounter",0),X(this,"userCallIdCounter",0),X(this,"plotCallIdCounter",0),X(this,"alertCallIdCounter",0),X(this,"loopGuardCounter",0),X(this,"hoistingStack",[]),X(this,"suppressHoisting",!1),X(this,"reservedNames",new Set),X(this,"userFunctions",new Set),X(this,"userMethods",new Set),X(this,"regularUserFunctions",new Set),X(this,"udtTypeNames",new Map),X(this,"udtInstances",new Map),X(this,"functionReturnTypes",new Map),X(this,"functionReturnTupleTypes",new Map),X(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,i={}){this.udtTypeNames.set(e,i)}isUdtTypeName(e){return this.udtTypeNames.has(e)}getUdtTypeFields(e){return this.udtTypeNames.get(e)}markVariableAsUdtInstance(e,i){this.udtInstances.set(e,i)}getVariableUdtType(e){return this.udtInstances.get(e)}isUdtInstance(e){return this.udtInstances.has(e)}setFunctionReturnType(e,i){const r=this.functionReturnTypes.get(e);if(r&&r!==i){this.functionReturnTypes.delete(e);return}this.functionReturnTypes.set(e,i)}getFunctionReturnType(e){return this.functionReturnTypes.get(e)}setFunctionReturnTupleType(e,i){const r=this.functionReturnTupleTypes.get(e);if(r&&(r.length!==i.length||r.some((n,s)=>n!==i[s]))){this.functionReturnTupleTypes.delete(e);return}this.functionReturnTupleTypes.set(e,i)}getFunctionReturnTupleType(e){return this.functionReturnTupleTypes.get(e)}setFunctionParamUdtTypes(e,i){this.functionParamUdtTypes.set(e,i)}getFunctionParamUdtTypes(e){return this.functionParamUdtTypes.get(e)}unmarkVariableAsUdtInstance(e){this.udtInstances.delete(e)}addContextBoundVar(e,i=!1){this.contextBoundVars.add(e),i&&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 cy.has(e)||uy.has(e)?!1:this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,i){this.loopVars.add(e),this.loopVarNames.set(e,i)}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,i){if(this.isContextBound(e))return e;const r=this.scopes[this.scopes.length-1],n=this.scopeTypes[this.scopeTypes.length-1],s=this.scopeCounts.get(n)||1,a=`${n}${s}_${e}`;return r.set(e,a),this.varKinds.set(a,i),a}getVariable(e){if(this.loopVars.has(e)){const i=this.loopVarNames.get(e);if(i)return[i,"let"]}if(this.isContextBound(e))return[e,"let"];for(let i=this.scopes.length-1;i>=0;i--){const r=this.scopes[i];if(r.has(e)){const n=r.get(e),s=this.varKinds.get(n)||"let";return[n,s]}}return[e,"let"]}isVariableInFunctionScope(e){for(let i=this.scopes.length-1;i>=0;i--)if(this.scopes[i].has(e)){for(let r=0;r<=i;r++)if(this.scopeTypes[r]==="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){const i=Math.min(1,this.hoistingStack.length-1);this.hoistingStack[i].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 i=this.scopes.length-1;i>=0;i--)if(this.scopes[i].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++}`;const i=this.scopes[this.scopes.length-1];return i&&i.set(e,e),e}}function He(t,e,i,r,n){i||(i=I),(function s(a,o,l){var c=l||a.type;ba(i,c,a,o,s),e[c]&&e[c](a,o)})(t,r,n)}function py(t,e,i,r,n){var s=[];i||(i=I),(function a(o,l,c){var u=c||o.type,p=o!==s[s.length-1];p&&s.push(o),ba(i,u,o,l,a),e[u]&&e[u](o,l||s,s),p&&s.pop()})(t,r,n)}function ue(t,e,i,r,n){var s=i?fy(i,r||void 0):r;(function a(o,l,c){s[c||o.type](o,l,a)})(t,e,n)}function fy(t,e){var i=Object.create(e||I);for(var r in t)i[r]=t[r];return i}function Yr(t,e,i){i(t,e)}function jt(t,e,i){}function ba(t,e,i,r,n){if(t[e]==null)throw new Error("No walker function defined for node type "+e);t[e](i,r,n)}var I={};I.Program=I.BlockStatement=I.StaticBlock=function(t,e,i){for(var r=0,n=t.body;r<n.length;r+=1){var s=n[r];i(s,e,"Statement")}};I.Statement=Yr;I.EmptyStatement=jt;I.ExpressionStatement=I.ParenthesizedExpression=I.ChainExpression=function(t,e,i){return i(t.expression,e,"Expression")};I.IfStatement=function(t,e,i){i(t.test,e,"Expression"),i(t.consequent,e,"Statement"),t.alternate&&i(t.alternate,e,"Statement")};I.LabeledStatement=function(t,e,i){return i(t.body,e,"Statement")};I.BreakStatement=I.ContinueStatement=jt;I.WithStatement=function(t,e,i){i(t.object,e,"Expression"),i(t.body,e,"Statement")};I.SwitchStatement=function(t,e,i){i(t.discriminant,e,"Expression");for(var r=0,n=t.cases;r<n.length;r+=1){var s=n[r];i(s,e)}};I.SwitchCase=function(t,e,i){t.test&&i(t.test,e,"Expression");for(var r=0,n=t.consequent;r<n.length;r+=1){var s=n[r];i(s,e,"Statement")}};I.ReturnStatement=I.YieldExpression=I.AwaitExpression=function(t,e,i){t.argument&&i(t.argument,e,"Expression")};I.ThrowStatement=I.SpreadElement=function(t,e,i){return i(t.argument,e,"Expression")};I.TryStatement=function(t,e,i){i(t.block,e,"Statement"),t.handler&&i(t.handler,e),t.finalizer&&i(t.finalizer,e,"Statement")};I.CatchClause=function(t,e,i){t.param&&i(t.param,e,"Pattern"),i(t.body,e,"Statement")};I.WhileStatement=I.DoWhileStatement=function(t,e,i){i(t.test,e,"Expression"),i(t.body,e,"Statement")};I.ForStatement=function(t,e,i){t.init&&i(t.init,e,"ForInit"),t.test&&i(t.test,e,"Expression"),t.update&&i(t.update,e,"Expression"),i(t.body,e,"Statement")};I.ForInStatement=I.ForOfStatement=function(t,e,i){i(t.left,e,"ForInit"),i(t.right,e,"Expression"),i(t.body,e,"Statement")};I.ForInit=function(t,e,i){t.type==="VariableDeclaration"?i(t,e):i(t,e,"Expression")};I.DebuggerStatement=jt;I.FunctionDeclaration=function(t,e,i){return i(t,e,"Function")};I.VariableDeclaration=function(t,e,i){for(var r=0,n=t.declarations;r<n.length;r+=1){var s=n[r];i(s,e)}};I.VariableDeclarator=function(t,e,i){i(t.id,e,"Pattern"),t.init&&i(t.init,e,"Expression")};I.Function=function(t,e,i){t.id&&i(t.id,e,"Pattern");for(var r=0,n=t.params;r<n.length;r+=1){var s=n[r];i(s,e,"Pattern")}i(t.body,e,t.expression?"Expression":"Statement")};I.Pattern=function(t,e,i){t.type==="Identifier"?i(t,e,"VariablePattern"):t.type==="MemberExpression"?i(t,e,"MemberPattern"):i(t,e)};I.VariablePattern=jt;I.MemberPattern=Yr;I.RestElement=function(t,e,i){return i(t.argument,e,"Pattern")};I.ArrayPattern=function(t,e,i){for(var r=0,n=t.elements;r<n.length;r+=1){var s=n[r];s&&i(s,e,"Pattern")}};I.ObjectPattern=function(t,e,i){for(var r=0,n=t.properties;r<n.length;r+=1){var s=n[r];s.type==="Property"?(s.computed&&i(s.key,e,"Expression"),i(s.value,e,"Pattern")):s.type==="RestElement"&&i(s.argument,e,"Pattern")}};I.Expression=Yr;I.ThisExpression=I.Super=I.MetaProperty=jt;I.ArrayExpression=function(t,e,i){for(var r=0,n=t.elements;r<n.length;r+=1){var s=n[r];s&&i(s,e,"Expression")}};I.ObjectExpression=function(t,e,i){for(var r=0,n=t.properties;r<n.length;r+=1){var s=n[r];i(s,e)}};I.FunctionExpression=I.ArrowFunctionExpression=I.FunctionDeclaration;I.SequenceExpression=function(t,e,i){for(var r=0,n=t.expressions;r<n.length;r+=1){var s=n[r];i(s,e,"Expression")}};I.TemplateLiteral=function(t,e,i){for(var r=0,n=t.quasis;r<n.length;r+=1){var s=n[r];i(s,e)}for(var a=0,o=t.expressions;a<o.length;a+=1){var l=o[a];i(l,e,"Expression")}};I.TemplateElement=jt;I.UnaryExpression=I.UpdateExpression=function(t,e,i){i(t.argument,e,"Expression")};I.BinaryExpression=I.LogicalExpression=function(t,e,i){i(t.left,e,"Expression"),i(t.right,e,"Expression")};I.AssignmentExpression=I.AssignmentPattern=function(t,e,i){i(t.left,e,"Pattern"),i(t.right,e,"Expression")};I.ConditionalExpression=function(t,e,i){i(t.test,e,"Expression"),i(t.consequent,e,"Expression"),i(t.alternate,e,"Expression")};I.NewExpression=I.CallExpression=function(t,e,i){if(i(t.callee,e,"Expression"),t.arguments)for(var r=0,n=t.arguments;r<n.length;r+=1){var s=n[r];i(s,e,"Expression")}};I.MemberExpression=function(t,e,i){i(t.object,e,"Expression"),t.computed&&i(t.property,e,"Expression")};I.ExportNamedDeclaration=I.ExportDefaultDeclaration=function(t,e,i){if(t.declaration&&i(t.declaration,e,t.type==="ExportNamedDeclaration"||t.declaration.id?"Statement":"Expression"),t.source&&i(t.source,e,"Expression"),t.attributes)for(var r=0,n=t.attributes;r<n.length;r+=1){var s=n[r];i(s,e)}};I.ExportAllDeclaration=function(t,e,i){if(t.exported&&i(t.exported,e),i(t.source,e,"Expression"),t.attributes)for(var r=0,n=t.attributes;r<n.length;r+=1){var s=n[r];i(s,e)}};I.ImportAttribute=function(t,e,i){i(t.value,e,"Expression")};I.ImportDeclaration=function(t,e,i){for(var r=0,n=t.specifiers;r<n.length;r+=1){var s=n[r];i(s,e)}if(i(t.source,e,"Expression"),t.attributes)for(var a=0,o=t.attributes;a<o.length;a+=1){var l=o[a];i(l,e)}};I.ImportExpression=function(t,e,i){i(t.source,e,"Expression"),t.options&&i(t.options,e,"Expression")};I.ImportSpecifier=I.ImportDefaultSpecifier=I.ImportNamespaceSpecifier=I.Identifier=I.PrivateIdentifier=I.Literal=jt;I.TaggedTemplateExpression=function(t,e,i){i(t.tag,e,"Expression"),i(t.quasi,e,"Expression")};I.ClassDeclaration=I.ClassExpression=function(t,e,i){return i(t,e,"Class")};I.Class=function(t,e,i){t.id&&i(t.id,e,"Pattern"),t.superClass&&i(t.superClass,e,"Expression"),i(t.body,e)};I.ClassBody=function(t,e,i){for(var r=0,n=t.body;r<n.length;r+=1){var s=n[r];i(s,e)}};I.MethodDefinition=I.PropertyDefinition=I.Property=function(t,e,i){t.computed&&i(t.key,e,"Expression"),t.value&&i(t.value,e,"Expression")};const se="$",E={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,i=!1){return{type:"MemberExpression",object:t,property:e,computed:i}},createContextIdentifier(){return this.createIdentifier("$")},createLocalContextIdentifier(){return this.createIdentifier("$$")},createContextVariableReference(t,e){const i=this.createContextIdentifier(),r=this.createIdentifier(t),n=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(i,r,!1),n,!1)},createLocalContextVariableReference(t,e){const i=this.createLocalContextIdentifier(),r=this.createIdentifier(t),n=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(i,r,!1),n,!1)},createDynamicContextVariableReference(t,e){const i=this.createContextIdentifier(),r=this.createIdentifier(t);return this.createMemberExpression(this.createMemberExpression(i,r,!1),e,!0)},createContextVariableAccess0(t,e){const i=this.createContextVariableReference(t,e);return this.createGetCall(i,0)},createDynamicContextVariableAccess0(t,e){const i=this.createDynamicContextVariableReference(t,e);return this.createGetCall(i,0)},createArrayAccess(t,e){const i=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,i,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,i="="){return{type:"AssignmentExpression",operator:i,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,i){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),n=[t,e];return i&&n.push(i),this.createCallExpression(r,n)},createInitVarCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("initVar"),!1),r=[t,e];return this.createCallExpression(i,r)},createGetCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),r=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(i,[t,r])},createSetCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(i,[t,e])},createMathEqCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(i,this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__eq"),!1);return this.createCallExpression(n,[t,e])},createMathNeqCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(i,this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__neq"),!1);return this.createCallExpression(n,[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}}},Tt=["ta","math","request","array","input","color","ticker","strategy"],it=["hline","plot","fill","label","line","box","linefill","polyline","table","na","alert","time","time_close","dayofmonth","dayofweek","hour","minute","month","second","weekofyear","year"],dy=["request.security","request.security_lower_tf"],my=["chart.left_visible_bar_time","chart.right_visible_bar_time"],Pn=["plot","hline","fill","strategy.exit"],yy=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],_y=new Set([...Tt,"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"]),Dn=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"]),va=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],Xr=[...Tt,"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"],gy=["na","nz","plot","plotchar","color","hline","fill"];function xy(t){let e=null,i=se;if(t.type==="Program"&&t.body.length>0){const f=t.body[0];if(f.type==="ExpressionStatement"&&(f.expression.type==="ArrowFunctionExpression"||f.expression.type==="FunctionExpression")){const d=f.expression;d.body.type==="BlockStatement"&&(e=d.body.body,d.params.length>0&&d.params[0].type==="Identifier"&&(i=d.params[0].name))}}if(!e)return;const r=new Set,n=new Set,s=f=>{f.type==="Identifier"?r.add(f.name):f.type==="ObjectPattern"?f.properties.forEach(d=>s(d.value)):f.type==="ArrayPattern"&&f.elements.forEach(d=>{d&&s(d)})};ue(t,{},{VariableDeclarator(f,d,m){s(f.id),f.init&&m(f.init,d)},FunctionDeclaration(f,d,m){s(f.id);for(const x of f.params)x&&x.type==="AssignmentPattern"&&x.right&&m(x.right,d);m(f.body,d)},Identifier(f,d,m){n.add(f.name)},MemberExpression(f,d,m){m(f.object,d),f.computed&&m(f.property,d)},Property(f,d,m){f.computed&&m(f.key,d),m(f.value,d)}}),e.forEach(f=>{f.type==="VariableDeclaration"?f.declarations.forEach(d=>s(d.id)):f.type==="FunctionDeclaration"&&s(f.id)});const a=va,o=Xr,l=a.filter(f=>!r.has(f)),c=o.filter(f=>!r.has(f)),u=l.filter(f=>n.has(f)),p=c.filter(f=>n.has(f)),h=[];u.length>0&&h.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:u.map(f=>({type:"Property",key:{type:"Identifier",name:f},value:{type:"Identifier",name:f},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:i},property:{type:"Identifier",name:"data"},computed:!1}}]}),p.length>0&&h.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:p.map(f=>({type:"Property",key:{type:"Identifier",name:f},value:{type:"Identifier",name:f},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:i},property:{type:"Identifier",name:"pine"},computed:!1}}]}),h.length>0&&e.unshift(...h)}function by(t){let e=null,i=se;if(t.type==="Program"&&t.body.length>0){const o=t.body[0];if(o.type==="ExpressionStatement"&&(o.expression.type==="ArrowFunctionExpression"||o.expression.type==="FunctionExpression")){const l=o.expression;l.body.type==="BlockStatement"&&(e=l.body.body,l.params.length>0&&l.params[0].type==="Identifier"&&(i=l.params[0].name))}}if(!e)return;const r=new Set(va),n=new Set(Xr),s=new Set(gy),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===i&&l.init.property.type==="Identifier"){const c=l.init.property.name;let u=null;if(c==="data"?u=r:c==="pine"?u=n:c==="core"&&(u=s),u&&l.id.type==="ObjectPattern")l.id.properties.forEach(p=>{if(p.type==="Property"&&p.key.type==="Identifier"&&p.value.type==="Identifier"){const h=p.key.name,f=p.value.name;u.has(h)&&h!==f&&(a.set(f,h),p.value.name=h,p.shorthand=!0)}});else if(l.id.type==="Identifier"&&Tt.includes(c)){const p=c,h=l.id.name;p!==h&&(a.set(h,p),l.id.name=p)}}})}),a.size>0&&ue(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 vy(t){try{const e=Kr(t,{ecmaVersion:"latest",sourceType:"module"});if(e.type==="Program"&&e.body.length===1){const i=e.body[0];if(i.type==="ExpressionStatement"){const r=i.expression;if(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")return{isWrapped:!0,isAsync:r.async||!1,functionNode:r}}if(i.type==="FunctionDeclaration")return{isWrapped:!0,isAsync:i.async||!1,functionNode:i}}return{isWrapped:!1,isAsync:!1}}catch{return{isWrapped:!1,isAsync:!1}}}function wy(t){return t.async=!0,Gr(t)}function Sy(t){t=t.trim();const{isWrapped:e,isAsync:i,functionNode:r}=vy(t);return e&&r?i?t:wy(r):`async (context) => {
14
+ `).length-1,this.mapping={original:null,generated:this,name:void 0,source:i.sourceMap.file||i.sourceMap._file})}write(e){this.output+=e}writeToStream(e){this.output.write(e)}writeAndMap(e,i){this.output+=e,this.map(e,i)}writeToStreamAndMap(e,i){this.output.write(e),this.map(e,i)}map(e,i){if(i!=null){const{type:a}=i;if(a[0]==="L"&&a[2]==="n"){this.column=0,this.line++;return}if(i.loc!=null){const{mapping:s}=this;s.original=i.loc.start,s.name=i.name,this.sourceMap.addMapping(s)}if(a[0]==="T"&&a[8]==="E"||a[0]==="L"&&a[1]==="i"&&typeof i.value=="string"){const{length:s}=e;let{column:o,line:l}=this;for(let c=0;c<s;c++)e[c]===`
15
+ `?(o=0,l++):o++;this.column=o,this.line=l;return}}const{length:r}=e,{lineEnd:n}=this;r>0&&(this.lineEndSize>0&&(n.length===1?e[r-1]===n:e.endsWith(n))?(this.line+=this.lineEndSize,this.column=0):this.column+=r)}toString(){return this.output}}function Zr(t,e){const i=new dy(e);return i.generator[t.type](t,i),i.output}var my=Object.defineProperty,yy=(t,e,i)=>e in t?my(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Q=(t,e,i)=>yy(t,typeof e!="symbol"?e+"":e,i);const _y=new Set(["Infinity","NaN","undefined","null","true","false"]),gy=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"]);class xy{constructor(){Q(this,"scopes",[]),Q(this,"scopeTypes",[]),Q(this,"scopeCounts",new Map),Q(this,"contextBoundVars",new Set),Q(this,"arrayPatternElements",new Set),Q(this,"rootParams",new Set),Q(this,"localSeriesVars",new Set),Q(this,"varKinds",new Map),Q(this,"loopVars",new Set),Q(this,"loopVarNames",new Map),Q(this,"paramIdCounter",0),Q(this,"cacheIdCounter",0),Q(this,"tempVarCounter",0),Q(this,"taCallIdCounter",0),Q(this,"userCallIdCounter",0),Q(this,"plotCallIdCounter",0),Q(this,"alertCallIdCounter",0),Q(this,"loopGuardCounter",0),Q(this,"hoistingStack",[]),Q(this,"suppressHoisting",!1),Q(this,"reservedNames",new Set),Q(this,"userFunctions",new Set),Q(this,"userMethods",new Set),Q(this,"regularUserFunctions",new Set),Q(this,"udtTypeNames",new Map),Q(this,"udtInstances",new Map),Q(this,"functionReturnTypes",new Map),Q(this,"functionReturnTupleTypes",new Map),Q(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,i={}){this.udtTypeNames.set(e,i)}isUdtTypeName(e){return this.udtTypeNames.has(e)}getUdtTypeFields(e){return this.udtTypeNames.get(e)}markVariableAsUdtInstance(e,i){this.udtInstances.set(e,i)}getVariableUdtType(e){return this.udtInstances.get(e)}isUdtInstance(e){return this.udtInstances.has(e)}setFunctionReturnType(e,i){const r=this.functionReturnTypes.get(e);if(r&&r!==i){this.functionReturnTypes.delete(e);return}this.functionReturnTypes.set(e,i)}getFunctionReturnType(e){return this.functionReturnTypes.get(e)}setFunctionReturnTupleType(e,i){const r=this.functionReturnTupleTypes.get(e);if(r&&(r.length!==i.length||r.some((n,a)=>n!==i[a]))){this.functionReturnTupleTypes.delete(e);return}this.functionReturnTupleTypes.set(e,i)}getFunctionReturnTupleType(e){return this.functionReturnTupleTypes.get(e)}setFunctionParamUdtTypes(e,i){this.functionParamUdtTypes.set(e,i)}getFunctionParamUdtTypes(e){return this.functionParamUdtTypes.get(e)}unmarkVariableAsUdtInstance(e){this.udtInstances.delete(e)}addContextBoundVar(e,i=!1){this.contextBoundVars.add(e),i&&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 _y.has(e)||gy.has(e)?!1:this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,i){this.loopVars.add(e),this.loopVarNames.set(e,i)}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,i){if(this.isContextBound(e))return e;const r=this.scopes[this.scopes.length-1],n=this.scopeTypes[this.scopeTypes.length-1],a=this.scopeCounts.get(n)||1,s=`${n}${a}_${e}`;return r.set(e,s),this.varKinds.set(s,i),s}getVariable(e){if(this.loopVars.has(e)){const i=this.loopVarNames.get(e);if(i)return[i,"let"]}if(this.isContextBound(e))return[e,"let"];for(let i=this.scopes.length-1;i>=0;i--){const r=this.scopes[i];if(r.has(e)){const n=r.get(e),a=this.varKinds.get(n)||"let";return[n,a]}}return[e,"let"]}isVariableInFunctionScope(e){for(let i=this.scopes.length-1;i>=0;i--)if(this.scopes[i].has(e)){for(let r=0;r<=i;r++)if(this.scopeTypes[r]==="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){const i=Math.min(1,this.hoistingStack.length-1);this.hoistingStack[i].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 i=this.scopes.length-1;i>=0;i--)if(this.scopes[i].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++}`;const i=this.scopes[this.scopes.length-1];return i&&i.set(e,e),e}}function Ge(t,e,i,r,n){i||(i=T),(function a(s,o,l){var c=l||s.type;Na(i,c,s,o,a),e[c]&&e[c](s,o)})(t,r,n)}function by(t,e,i,r,n){var a=[];i||(i=T),(function s(o,l,c){var u=c||o.type,p=o!==a[a.length-1];p&&a.push(o),Na(i,u,o,l,s),e[u]&&e[u](o,l||a,a),p&&a.pop()})(t,r,n)}function de(t,e,i,r,n){var a=i?vy(i,r||void 0):r;(function s(o,l,c){a[c||o.type](o,l,s)})(t,e,n)}function vy(t,e){var i=Object.create(e||T);for(var r in t)i[r]=t[r];return i}function Jr(t,e,i){i(t,e)}function Ft(t,e,i){}function Na(t,e,i,r,n){if(t[e]==null)throw new Error("No walker function defined for node type "+e);t[e](i,r,n)}var T={};T.Program=T.BlockStatement=T.StaticBlock=function(t,e,i){for(var r=0,n=t.body;r<n.length;r+=1){var a=n[r];i(a,e,"Statement")}};T.Statement=Jr;T.EmptyStatement=Ft;T.ExpressionStatement=T.ParenthesizedExpression=T.ChainExpression=function(t,e,i){return i(t.expression,e,"Expression")};T.IfStatement=function(t,e,i){i(t.test,e,"Expression"),i(t.consequent,e,"Statement"),t.alternate&&i(t.alternate,e,"Statement")};T.LabeledStatement=function(t,e,i){return i(t.body,e,"Statement")};T.BreakStatement=T.ContinueStatement=Ft;T.WithStatement=function(t,e,i){i(t.object,e,"Expression"),i(t.body,e,"Statement")};T.SwitchStatement=function(t,e,i){i(t.discriminant,e,"Expression");for(var r=0,n=t.cases;r<n.length;r+=1){var a=n[r];i(a,e)}};T.SwitchCase=function(t,e,i){t.test&&i(t.test,e,"Expression");for(var r=0,n=t.consequent;r<n.length;r+=1){var a=n[r];i(a,e,"Statement")}};T.ReturnStatement=T.YieldExpression=T.AwaitExpression=function(t,e,i){t.argument&&i(t.argument,e,"Expression")};T.ThrowStatement=T.SpreadElement=function(t,e,i){return i(t.argument,e,"Expression")};T.TryStatement=function(t,e,i){i(t.block,e,"Statement"),t.handler&&i(t.handler,e),t.finalizer&&i(t.finalizer,e,"Statement")};T.CatchClause=function(t,e,i){t.param&&i(t.param,e,"Pattern"),i(t.body,e,"Statement")};T.WhileStatement=T.DoWhileStatement=function(t,e,i){i(t.test,e,"Expression"),i(t.body,e,"Statement")};T.ForStatement=function(t,e,i){t.init&&i(t.init,e,"ForInit"),t.test&&i(t.test,e,"Expression"),t.update&&i(t.update,e,"Expression"),i(t.body,e,"Statement")};T.ForInStatement=T.ForOfStatement=function(t,e,i){i(t.left,e,"ForInit"),i(t.right,e,"Expression"),i(t.body,e,"Statement")};T.ForInit=function(t,e,i){t.type==="VariableDeclaration"?i(t,e):i(t,e,"Expression")};T.DebuggerStatement=Ft;T.FunctionDeclaration=function(t,e,i){return i(t,e,"Function")};T.VariableDeclaration=function(t,e,i){for(var r=0,n=t.declarations;r<n.length;r+=1){var a=n[r];i(a,e)}};T.VariableDeclarator=function(t,e,i){i(t.id,e,"Pattern"),t.init&&i(t.init,e,"Expression")};T.Function=function(t,e,i){t.id&&i(t.id,e,"Pattern");for(var r=0,n=t.params;r<n.length;r+=1){var a=n[r];i(a,e,"Pattern")}i(t.body,e,t.expression?"Expression":"Statement")};T.Pattern=function(t,e,i){t.type==="Identifier"?i(t,e,"VariablePattern"):t.type==="MemberExpression"?i(t,e,"MemberPattern"):i(t,e)};T.VariablePattern=Ft;T.MemberPattern=Jr;T.RestElement=function(t,e,i){return i(t.argument,e,"Pattern")};T.ArrayPattern=function(t,e,i){for(var r=0,n=t.elements;r<n.length;r+=1){var a=n[r];a&&i(a,e,"Pattern")}};T.ObjectPattern=function(t,e,i){for(var r=0,n=t.properties;r<n.length;r+=1){var a=n[r];a.type==="Property"?(a.computed&&i(a.key,e,"Expression"),i(a.value,e,"Pattern")):a.type==="RestElement"&&i(a.argument,e,"Pattern")}};T.Expression=Jr;T.ThisExpression=T.Super=T.MetaProperty=Ft;T.ArrayExpression=function(t,e,i){for(var r=0,n=t.elements;r<n.length;r+=1){var a=n[r];a&&i(a,e,"Expression")}};T.ObjectExpression=function(t,e,i){for(var r=0,n=t.properties;r<n.length;r+=1){var a=n[r];i(a,e)}};T.FunctionExpression=T.ArrowFunctionExpression=T.FunctionDeclaration;T.SequenceExpression=function(t,e,i){for(var r=0,n=t.expressions;r<n.length;r+=1){var a=n[r];i(a,e,"Expression")}};T.TemplateLiteral=function(t,e,i){for(var r=0,n=t.quasis;r<n.length;r+=1){var a=n[r];i(a,e)}for(var s=0,o=t.expressions;s<o.length;s+=1){var l=o[s];i(l,e,"Expression")}};T.TemplateElement=Ft;T.UnaryExpression=T.UpdateExpression=function(t,e,i){i(t.argument,e,"Expression")};T.BinaryExpression=T.LogicalExpression=function(t,e,i){i(t.left,e,"Expression"),i(t.right,e,"Expression")};T.AssignmentExpression=T.AssignmentPattern=function(t,e,i){i(t.left,e,"Pattern"),i(t.right,e,"Expression")};T.ConditionalExpression=function(t,e,i){i(t.test,e,"Expression"),i(t.consequent,e,"Expression"),i(t.alternate,e,"Expression")};T.NewExpression=T.CallExpression=function(t,e,i){if(i(t.callee,e,"Expression"),t.arguments)for(var r=0,n=t.arguments;r<n.length;r+=1){var a=n[r];i(a,e,"Expression")}};T.MemberExpression=function(t,e,i){i(t.object,e,"Expression"),t.computed&&i(t.property,e,"Expression")};T.ExportNamedDeclaration=T.ExportDefaultDeclaration=function(t,e,i){if(t.declaration&&i(t.declaration,e,t.type==="ExportNamedDeclaration"||t.declaration.id?"Statement":"Expression"),t.source&&i(t.source,e,"Expression"),t.attributes)for(var r=0,n=t.attributes;r<n.length;r+=1){var a=n[r];i(a,e)}};T.ExportAllDeclaration=function(t,e,i){if(t.exported&&i(t.exported,e),i(t.source,e,"Expression"),t.attributes)for(var r=0,n=t.attributes;r<n.length;r+=1){var a=n[r];i(a,e)}};T.ImportAttribute=function(t,e,i){i(t.value,e,"Expression")};T.ImportDeclaration=function(t,e,i){for(var r=0,n=t.specifiers;r<n.length;r+=1){var a=n[r];i(a,e)}if(i(t.source,e,"Expression"),t.attributes)for(var s=0,o=t.attributes;s<o.length;s+=1){var l=o[s];i(l,e)}};T.ImportExpression=function(t,e,i){i(t.source,e,"Expression"),t.options&&i(t.options,e,"Expression")};T.ImportSpecifier=T.ImportDefaultSpecifier=T.ImportNamespaceSpecifier=T.Identifier=T.PrivateIdentifier=T.Literal=Ft;T.TaggedTemplateExpression=function(t,e,i){i(t.tag,e,"Expression"),i(t.quasi,e,"Expression")};T.ClassDeclaration=T.ClassExpression=function(t,e,i){return i(t,e,"Class")};T.Class=function(t,e,i){t.id&&i(t.id,e,"Pattern"),t.superClass&&i(t.superClass,e,"Expression"),i(t.body,e)};T.ClassBody=function(t,e,i){for(var r=0,n=t.body;r<n.length;r+=1){var a=n[r];i(a,e)}};T.MethodDefinition=T.PropertyDefinition=T.Property=function(t,e,i){t.computed&&i(t.key,e,"Expression"),t.value&&i(t.value,e,"Expression")};const le="$",E={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,i=!1){return{type:"MemberExpression",object:t,property:e,computed:i}},createContextIdentifier(){return this.createIdentifier("$")},createLocalContextIdentifier(){return this.createIdentifier("$$")},createContextVariableReference(t,e){const i=this.createContextIdentifier(),r=this.createIdentifier(t),n=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(i,r,!1),n,!1)},createLocalContextVariableReference(t,e){const i=this.createLocalContextIdentifier(),r=this.createIdentifier(t),n=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(i,r,!1),n,!1)},createDynamicContextVariableReference(t,e){const i=this.createContextIdentifier(),r=this.createIdentifier(t);return this.createMemberExpression(this.createMemberExpression(i,r,!1),e,!0)},createContextVariableAccess0(t,e){const i=this.createContextVariableReference(t,e);return this.createGetCall(i,0)},createDynamicContextVariableAccess0(t,e){const i=this.createDynamicContextVariableReference(t,e);return this.createGetCall(i,0)},createArrayAccess(t,e){const i=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,i,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,i="="){return{type:"AssignmentExpression",operator:i,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,i){const r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),n=[t,e];return i&&n.push(i),this.createCallExpression(r,n)},createInitVarCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("initVar"),!1),r=[t,e];return this.createCallExpression(i,r)},createGetCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),r=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(i,[t,r])},createSetCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(i,[t,e])},createMathEqCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(i,this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__eq"),!1);return this.createCallExpression(n,[t,e])},createMathNeqCall(t,e){const i=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(i,this.createIdentifier("math"),!1),n=this.createMemberExpression(r,this.createIdentifier("__neq"),!1);return this.createCallExpression(n,[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}}},Tt=["ta","math","request","array","input","color","ticker","strategy"],rt=["hline","plot","fill","label","line","box","linefill","polyline","table","na","alert","time","time_close","dayofmonth","dayofweek","hour","minute","month","second","weekofyear","year"],wy=["request.security","request.security_lower_tf"],Sy=["chart.left_visible_bar_time","chart.right_visible_bar_time"],Rn=["plot","hline","fill","strategy.exit"],Ey=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],Ny=new Set([...Tt,"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"]),On=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"]),Ca=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],en=[...Tt,"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"],Cy=["na","nz","plot","plotchar","color","hline","fill"];function Iy(t){let e=null,i=le;if(t.type==="Program"&&t.body.length>0){const f=t.body[0];if(f.type==="ExpressionStatement"&&(f.expression.type==="ArrowFunctionExpression"||f.expression.type==="FunctionExpression")){const d=f.expression;d.body.type==="BlockStatement"&&(e=d.body.body,d.params.length>0&&d.params[0].type==="Identifier"&&(i=d.params[0].name))}}if(!e)return;const r=new Set,n=new Set,a=f=>{f.type==="Identifier"?r.add(f.name):f.type==="ObjectPattern"?f.properties.forEach(d=>a(d.value)):f.type==="ArrayPattern"&&f.elements.forEach(d=>{d&&a(d)})};de(t,{},{VariableDeclarator(f,d,m){a(f.id),f.init&&m(f.init,d)},FunctionDeclaration(f,d,m){a(f.id);for(const x of f.params)x&&x.type==="AssignmentPattern"&&x.right&&m(x.right,d);m(f.body,d)},Identifier(f,d,m){n.add(f.name)},MemberExpression(f,d,m){m(f.object,d),f.computed&&m(f.property,d)},Property(f,d,m){f.computed&&m(f.key,d),m(f.value,d)}}),e.forEach(f=>{f.type==="VariableDeclaration"?f.declarations.forEach(d=>a(d.id)):f.type==="FunctionDeclaration"&&a(f.id)});const s=Ca,o=en,l=s.filter(f=>!r.has(f)),c=o.filter(f=>!r.has(f)),u=l.filter(f=>n.has(f)),p=c.filter(f=>n.has(f)),h=[];u.length>0&&h.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:u.map(f=>({type:"Property",key:{type:"Identifier",name:f},value:{type:"Identifier",name:f},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:i},property:{type:"Identifier",name:"data"},computed:!1}}]}),p.length>0&&h.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:p.map(f=>({type:"Property",key:{type:"Identifier",name:f},value:{type:"Identifier",name:f},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:i},property:{type:"Identifier",name:"pine"},computed:!1}}]}),h.length>0&&e.unshift(...h)}function ky(t){let e=null,i=le;if(t.type==="Program"&&t.body.length>0){const o=t.body[0];if(o.type==="ExpressionStatement"&&(o.expression.type==="ArrowFunctionExpression"||o.expression.type==="FunctionExpression")){const l=o.expression;l.body.type==="BlockStatement"&&(e=l.body.body,l.params.length>0&&l.params[0].type==="Identifier"&&(i=l.params[0].name))}}if(!e)return;const r=new Set(Ca),n=new Set(en),a=new Set(Cy),s=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===i&&l.init.property.type==="Identifier"){const c=l.init.property.name;let u=null;if(c==="data"?u=r:c==="pine"?u=n:c==="core"&&(u=a),u&&l.id.type==="ObjectPattern")l.id.properties.forEach(p=>{if(p.type==="Property"&&p.key.type==="Identifier"&&p.value.type==="Identifier"){const h=p.key.name,f=p.value.name;u.has(h)&&h!==f&&(s.set(f,h),p.value.name=h,p.shorthand=!0)}});else if(l.id.type==="Identifier"&&Tt.includes(c)){const p=c,h=l.id.name;p!==h&&(s.set(h,p),l.id.name=p)}}})}),s.size>0&&de(t,{},{Identifier(o){s.has(o.name)&&(o.name=s.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 Ty(t){try{const e=Xr(t,{ecmaVersion:"latest",sourceType:"module"});if(e.type==="Program"&&e.body.length===1){const i=e.body[0];if(i.type==="ExpressionStatement"){const r=i.expression;if(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")return{isWrapped:!0,isAsync:r.async||!1,functionNode:r}}if(i.type==="FunctionDeclaration")return{isWrapped:!0,isAsync:i.async||!1,functionNode:i}}return{isWrapped:!1,isAsync:!1}}catch{return{isWrapped:!1,isAsync:!1}}}function Ay(t){return t.async=!0,Zr(t)}function Py(t){t=t.trim();const{isWrapped:e,isAsync:i,functionNode:r}=Ty(t);return e&&r?i?t:Ay(r):`async (context) => {
16
16
  ${t}
17
- }`}function Ey(t){ue(t,null,{VariableDeclaration(e,i,r){e.declarations&&e.declarations.length>0&&e.declarations.forEach(n=>{if(n.init&&n.init.type==="ArrowFunctionExpression"&&n.init.start!==0){const s={type:"FunctionDeclaration",id:n.id,params:n.init.params,body:n.init.body.type==="BlockStatement"?n.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:n.init.body}]},async:n.init.async,generator:!1};Object.assign(e,s)}}),e.body&&e.body.body&&e.body.body.forEach(n=>r(n,i))}})}function Ny(t,e){He(t,{VariableDeclaration(r){for(const n of r.declarations)if(!(n.id?.type!=="Identifier"||!n.init)&&n.init.type==="CallExpression"&&n.init.callee?.type==="Identifier"&&n.init.callee.name==="Type"&&n.init.arguments?.length===1&&n.init.arguments[0]?.type==="ObjectExpression"){const s={};for(const a of n.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(n.id.name,s)}}});let i=!0;for(;i;)i=!1,He(t,{FunctionDeclaration(r){if(!r.id?.name)return;const n=r.id.name;if(e.getFunctionReturnType(n)||e.getFunctionReturnTupleType(n))return;const s=Cy(r.body);if(s.length===0)return;if(s.every(l=>l.type==="ArrayExpression")){const l=s[0].elements.length;if(l>0&&s.every(c=>c.elements.length===l)){const c=[];let u=!0;for(let p=0;p<l;p++){const h=s.map(d=>di(d.elements[p],e)),f=h[0];if(!h.every(d=>d===f)){u=!1;break}c.push(f)}if(u&&c.some(p=>!!p)){e.setFunctionReturnTupleType(n,c),i=!0;return}}}const a=s.map(l=>di(l,e)),o=a[0];!o||!a.every(l=>l===o)||(e.setFunctionReturnType(n,o),i=!0)}});He(t,{VariableDeclaration(r){for(const n of r.declarations)if(n.init){if(n.id?.type==="Identifier"){const s=di(n.init,e);s&&e.markVariableAsUdtInstance(n.id.name,s);continue}if(n.id?.type==="ArrayPattern"&&n.init.type==="CallExpression"&&n.init.callee?.type==="Identifier"){const s=e.getFunctionReturnTupleType(n.init.callee.name);if(!s)continue;n.id.elements?.forEach((a,o)=>{if(!a||a.type!=="Identifier")return;const l=s[o];l&&e.markVariableAsUdtInstance(a.name,l)})}}},ExpressionStatement(r){const n=r.expression;if(n?.type==="Literal"&&typeof n.value=="string"&&n.value.startsWith("__pineUdtVar:")){const s=n.value.match(/^__pineUdtVar:([A-Za-z_$][\w$]*)=([A-Za-z_$][\w$]*)$/);if(s){const[,a,o]=s;e.isUdtTypeName(o)&&e.markVariableAsUdtInstance(a,o)}}}}),He(t,{ExpressionStatement(r){const n=r.expression;if(!n||n.type!=="AssignmentExpression"||n.operator!=="=")return;const s=n.left;if(s?.type!=="MemberExpression"||s.computed||s.property?.type!=="Identifier"||s.property.name!=="__pineParamTypes__"||s.object?.type!=="Identifier"||n.right?.type!=="ObjectExpression")return;const a=s.object.name,o=a.startsWith("$M_")?a.slice(3):a,l={};for(const c of n.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;const p=c.value.value.split(/\s+/).pop();e.isUdtTypeName(p)&&(l[u]=p)}Object.keys(l).length>0&&e.setFunctionParamUdtTypes(o,l)}})}function Cy(t){const e=[];if(!t)return e;function i(r){if(!(!r||typeof r!="object")&&!(r.type==="FunctionDeclaration"||r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression")){if(r.type==="ReturnStatement"&&r.argument){e.push(r.argument);return}for(const n of Object.keys(r)){if(n==="type")continue;const s=r[n];Array.isArray(s)?s.forEach(i):s&&typeof s=="object"&&s.type&&i(s)}}}return i(t),e}function di(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"){const i=e.getFunctionReturnType(t.callee.name);if(i)return i}if(t.type==="ConditionalExpression"){const i=di(t.consequent,e),r=di(t.alternate,e);if(i&&i===r)return i}}}function Iy(t,e){He(t,{VariableDeclaration(i){i.declarations.forEach(r=>{const n=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===se||r.init.object.name==="context2"),s=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===se||r.init.object.object.name==="context2");(n||s)&&(r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(a=>{a.key.name&&e.addContextBoundVar(a.key.name)}))})}})}function ky(t,e,i=!1){t.params.forEach(r=>{r.type==="Identifier"&&i&&e.addContextBoundVar(r.name,i)})}function Ty(t,e){let i;return py(t,{FunctionDeclaration(r){r.id&&r.id.name&&(e.addReservedName(r.id.name),e.addUserFunction(r.id.name),r.id.name.startsWith("$M_")||e.addRegularUserFunction(r.id.name))},ExpressionStatement(r){const n=r.expression;if(n&&n.type==="AssignmentExpression"&&n.operator==="="&&n.left?.type==="MemberExpression"&&n.left.property?.name==="__pineMethod__"&&n.left.object?.type==="Identifier"&&n.right?.value===!0){const s=n.left.object.name,a=s.startsWith("$M_")?s.slice(3):s;e.addUserMethod(a),e.addUserFunction(a)}},ArrowFunctionExpression(r){const n=r.start===0;n&&r.params&&r.params.length>0&&(i=r.params[0].name,r.params[0].name=se),ky(r,e,n)},VariableDeclaration(r,n){const s=n.length>1?n[n.length-2]:null,a=s&&(s.type==="ForOfStatement"||s.type==="ForInStatement")&&s.left===r;r.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(h=>{h&&h.type==="Identifier"&&e.addReservedName(h.name)}),a)return;const l=e.generateTempVar(),c={type:"VariableDeclaration",kind:r.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")&&He(u.callee.body,{ReturnStatement(h){h.argument&&h.argument.type==="ArrayExpression"&&(h.argument={type:"ArrayExpression",elements:[h.argument]})}}),o.id.elements?.forEach(h=>{h.type==="Identifier"&&e.addArrayPatternElement(h.name)});const p=o.id.elements.map((h,f)=>({type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:h,init:{type:"MemberExpression",object:{type:"Identifier",name:l},property:{type:"Literal",value:f},computed:!0}}]}));Object.assign(r,{type:"BlockStatement",body:[c,...p]})}})},ForStatement(r){}}),i}const Tr={type:"Identifier",name:"undefined"};function $i(t,e){const i={type:"Identifier",name:`'${e}'`};if(!t.isInsideFunctionScope())return i;const[r]=t.getVariable("$$");return r?{type:"BinaryExpression",operator:"+",left:E.createMemberExpression(E.createLocalContextIdentifier(),E.createIdentifier("id")),right:i}:i}function he(t,e){const[i,r]=e.getVariable(t);if((i.match(/^fn\d+_/)||e.isVariableInFunctionScope(t))&&t!=="$$"){const[n]=e.getVariable("$$");if(n)return E.createLocalContextVariableReference(r,i)}return E.createContextVariableReference(r,i)}function Ar(t,e){const i=he(t,e);return E.createGetCall(i,0)}function Lt(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)){const i=E.createIdentifier(t.object.name);i._skipTransformation=!0;const r=E.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(!e.isContextBound(t.object.name)){const i=he(t.object.name,e),r=E.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0}}return}if(!e.isContextBound(t.property.name))if(e.isLocalSeriesVar(t.property.name)){const i=E.createIdentifier(t.property.name);i._skipTransformation=!0,t.property=E.createGetCall(i,0)}else t.property=he(t.property.name,e),t.property=E.createGetCall(t.property,0)}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(e.isLocalSeriesVar(t.object.name)){const i=E.createIdentifier(t.object.name);i._skipTransformation=!0;const r=E.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(e.isContextBound(t.object.name)||(t.object=he(t.object.name,e)),t.property.type==="MemberExpression"){const i=t.property;i._indexTransformed||(Lt(i,e),i._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 ke(t,e){const i=E.createGetCall(E.createIdentifier(t.name),0);t.start!==void 0&&(i.start=t.start),t.end!==void 0&&(i.end=t.end),i._indexTransformed=!0,Object.assign(t,i)}function le(t,e){if(!t._skipTransformation&&t.name!==se){if(it.includes(t.name)&&e.isContextBound(t.name)){const h=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,f=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&!t.parent.computed;if(!h&&!f){const d={type:"MemberExpression",object:{type:"Identifier",name:t.name},property:{type:"Identifier",name:"__value"},computed:!1},m=E.createGetCall(d,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 i=!1;if(t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t)){const h=t.parent.callee;if(h.type==="MemberExpression"&&h.object&&h.object.name===se&&["get","set","init","param","call"].includes(h.property.name)){const f=t.parent.arguments.indexOf(t);h.property.name==="call"?f>=2&&(i=!0):f===0&&(i=!0)}else{const f=h.type==="MemberExpression"&&h.object&&h.object.type==="Identifier"&&Tt.includes(h.object.name);h.type==="MemberExpression"&&!f?i=!1:i=!0}}const r=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&e.isContextBound(t.name),n=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;const 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(r||n||i||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===se&&t.parent.callee.property.name==="call"&&t.parent.arguments[0]===t||e.isLocalSeriesVar(t.name)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;const h=he(t.name,e);Object.assign(t,h);return}const l=e.isContextBound(t.name)&&!e.isRootParam(t.name);if(l){const h=t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t),f=t.parent&&t.parent.type==="SwitchStatement"&&t.parent.discriminant===t,d=t.parent&&t.parent.type==="SwitchCase"&&t.parent.test===t;if(!h&&!f&&!d)return}if(e.isLocalSeriesVar(t.name)){if(!a){const h=E.createIdentifier(t.name),f=E.createGetCall(h,0);Object.assign(t,f)}return}const[c,u]=e.getVariable(t.name);let p;if(l)p=E.createIdentifier(t.name);else{if(c===t.name&&!e.isContextBound(t.name))return;p=he(t.name,e)}if(a)Object.assign(t,p);else{const h=E.createGetCall(p,0);Object.assign(t,h)}}}function ye(t,e,i){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;if(t.object&&t.object.type==="Identifier"&&Tt.includes(t.object.name)&&i.isContextBound(t.object.name)&&!t.computed){const 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){const 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"&&i.isLocalSeriesVar(t.object.name)){const l=E.createIdentifier(t.object.name);l._skipTransformation=!0,t.object=E.createGetCall(l,0);return}const r=i.getCurrentScopeType()=="if",n=i.getCurrentScopeType()=="els",s=i.getCurrentScopeType()=="for";if(!r&&!n&&!s&&t.object&&t.object.type==="Identifier"&&i.isContextBound(t.object.name)&&!i.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(Lt(t,i),t._indexTransformed=!0);const a=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&(t.object.object.object.name===se||t.object.object.object.name==="$$"),o=t.object&&t.object.type==="Identifier"&&i.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"&&it.includes(t.object.name)&&i.isContextBound(t.object.name)&&(t.object={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1});const l=E.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"&&i.isUdtInstance(l.object.name)){const c=l.object.name,u=i.isLocalSeriesVar(c)?(()=>{const h=E.createIdentifier(c);return h._skipTransformation=!0,h})():he(c,i);l.object=E.createGetCall(u,t.property);const p=t.object;Object.assign(t,p),delete t.computed;return}}}function mi(t,e){if(t.type==="Identifier"){if(it.includes(t.name)&&e.isContextBound(t.name)){const 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)){const[s,a]=e.getVariable(t.name);return E.createContextVariableReference(a,s)}if(e.isContextBound(t.name))return t;const[i,r]=e.getVariable(t.name),n=i!==t.name;return e.isLocalSeriesVar(t.name)&&!n?t:n?he(t.name,e):i===t.name&&!e.isContextBound(t.name)?t:he(t.name,e)}return t}function ct(t,e,i=""){switch(t.type){case"BinaryExpression":return Vi(t,e,i);case"LogicalExpression":return ji(t,e,i);case"MemberExpression":{const r=!t.computed&&t.object.type==="Identifier"&&it.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&it.includes(t.object.name)&&e.isContextBound(t.object.name)){const a={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1};return E.createGetCall(a,t.property)}const n=t.object.type==="Identifier"&&!r?mi(t.object,e):t.object;let s=n;if(!t.computed&&t.object.type==="Identifier"&&!r){const[a]=e.getVariable(t.object.name);a!==t.object.name&&!e.isLoopVariable(t.object.name)&&(s=E.createGetCall(n,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;const r=mi(t,e);return r.type==="Identifier"&&(r.name==="NaN"||r.name==="undefined"||r.name==="Infinity"||r.name==="null"||r.name==="Math")?r:E.createGetCall(r,0)}case"UnaryExpression":return Li(t,e,i);case"ConditionalExpression":{const r=ct(t.test,e,i),n=ct(t.consequent,e,i),s=ct(t.alternate,e,i);return{type:"ConditionalExpression",test:r,consequent:n,alternate:s,start:t.start,end:t.end}}}return t}function Vi(t,e,i){const r=ct(t.left,e,i),n=ct(t.right,e,i),s={type:"BinaryExpression",operator:t.operator,left:r,right:n,start:t.start,end:t.end};return ue(s,e,{CallExpression(a,o){a._transformed||ce(a,o)},MemberExpression(a){ye(a,"",e)}}),s}function ji(t,e,i){const r=ct(t.left,e,i),n=ct(t.right,e,i),s={type:"LogicalExpression",operator:t.operator,left:r,right:n,start:t.start,end:t.end};return ue(s,e,{CallExpression(a,o){a._transformed||ce(a,o)}}),s}function dr(t,e,i){ue(t,{parent:t,inNamespaceCall:!1},{Identifier(a,o,l){if(a.name=="NaN")return;if(it.includes(a.name)&&e.isContextBound(a.name)){if(o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===a&&!o.parent.computed)return;const u={type:"MemberExpression",object:{type:"Identifier",name:a.name},property:{type:"Identifier",name:"__value"},computed:!1},p=E.createGetCall(u,0);Object.assign(a,p),delete a.name;return}a.parent=o.parent,le(a,e);const c=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||c)&&(a.type==="MemberExpression"?Lt(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===se&&a.parent.callee.property.name==="get"||ke(a)))},MemberExpression(a,o,l){ye(a,"",e),a.object&&l(a.object,{parent:a,inNamespaceCall:o.inNamespaceCall})},ConditionalExpression(a,o,l){const 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){const c={...o,parent:a};l(a.left,c),l(a.right,c)},LogicalExpression(a,o,l){const c={...o,parent:a};l(a.left,c),l(a.right,c)},UnaryExpression(a,o,l){const c={...o,parent:a};l(a.argument,c)},CallExpression(a,o,l){const c=a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&a.callee.object.type==="Identifier"&&e.isContextBound(a.callee.object.name);ce(a,e),a.arguments.forEach(u=>l(u,{parent:a,inNamespaceCall:c||o.inNamespaceCall}))}});const r=E.createMemberExpression(E.createIdentifier(i),E.createIdentifier("param")),n=e.generateParamId(),s={type:"CallExpression",callee:r,arguments:[t,Tr,$i(e,n)],_transformed:!0,_isParamCall:!0};if(!e.shouldSuppressHoisting()){const a=n;e.addLocalSeriesVar(a);const o=E.createVariableDeclaration(a,s);return e.addHoistedStatement(o),E.createIdentifier(a)}return s}function Li(t,e,i){const r=ct(t.argument,e,i),n={type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:r,start:t.start,end:t.end};return ue(n,e,{CallExpression(s,a){s._transformed||ce(s,a)},MemberExpression(s){ye(s,"",e)}}),n}function Mt(t,e,i){switch(t?.type){case"BinaryExpression":t=Vi(t,i,e);break;case"LogicalExpression":t=ji(t,i,e);break;case"ConditionalExpression":return dr(t,i,e);case"UnaryExpression":t=Li(t,i,e);break;case"ArrayExpression":t.elements=t.elements.map(c=>{if(c.type==="Identifier"){if(i.isContextBound(c.name)&&!i.isRootParam(c.name))return c;if(i.isLocalSeriesVar(c.name)){const u=E.createIdentifier(c.name);return E.createGetCall(u,0)}return Ar(c.name,i)}return c.type==="CallExpression"?(ce(c,i),c):c.type==="BinaryExpression"?Vi(c,i,e):c.type==="LogicalExpression"?ji(c,i,e):c.type==="ConditionalExpression"?dr(c,i,e):c.type==="UnaryExpression"?Li(c,i,e):(c.type==="MemberExpression"&&ye(c,e,i),c)});break}const r=t.type==="MemberExpression"&&t.computed&&t.property,n=t.type==="MemberExpression"&&!t.computed;if(r){if(t.object&&t.object.type==="MemberExpression"){let d=t.object;for(;d.object&&d.object.type==="MemberExpression";)d=d.object;if(d.object?.type==="Identifier"&&i.isUdtInstance(d.object.name)){const m=d.object.name,x=i.isLocalSeriesVar(m)?(()=>{const b=E.createIdentifier(m);return b._skipTransformation=!0,b})():he(m,i);return d.object=E.createGetCall(x,t.property),t.object}}if(t.object.type==="CallExpression")ce(t.object,i);else if(t.object.type==="MemberExpression"){ye(t.object,"",i);let d=t.object;for(;d&&d.type==="MemberExpression"&&d.object;){if(d.object.type==="Identifier"){const m=d.object,[x]=i.getVariable(m.name);x!==m.name&&!i.isContextBound(m.name)&&!i.isRootParam(m.name)&&!i.isLoopVariable(m.name)&&!i.isLocalSeriesVar(m.name)&&!it.includes(m.name)&&!Tt.includes(m.name)&&(d.object=Ar(m.name,i));break}d=d.object}}else t.object.type==="BinaryExpression"?t.object=Vi(t.object,i,e):t.object.type==="LogicalExpression"?t.object=ji(t.object,i,e):t.object.type==="ConditionalExpression"?t.object=dr(t.object,i,e):t.object.type==="UnaryExpression"&&(t.object=Li(t.object,i,e));const c=t.object.type==="Identifier"&&i.isContextBound(t.object.name)&&!i.isRootParam(t.object.name)?t.object:mi(t.object,i);let u;t.property.type==="Identifier"&&!i.isContextBound(t.property.name)&&!i.isLoopVariable(t.property.name)?u=E.createGetCall(mi(t.property,i),0):t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression"?u=ct(t.property,i,e):u=t.property;const p=E.createMemberExpression(E.createIdentifier(e),E.createIdentifier("param")),h=i.generateParamId(),f={type:"CallExpression",callee:p,arguments:[c,u,$i(i,h)],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const d=h;i.addLocalSeriesVar(d);const m=E.createVariableDeclaration(d,f);return i.addHoistedStatement(m),E.createIdentifier(d)}return f}if(n){if(t.object.type==="Identifier"&&Tt.includes(t.object.name)&&i.isContextBound(t.object.name)&&!t.computed){const 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(i.getNextTACallId());const p=i.generateTempVar();i.addLocalSeriesVar(p);const h=E.createVariableDeclaration(p,u);return i.addOuterHoistedStatement(h),Object.assign(t,E.createIdentifier(p)),t}if(t.object.type==="Identifier"){const c=t.object.name,[u,p]=i.getVariable(c);if(u!==c&&!i.isLoopVariable(c)){const h=he(c,i),f=E.createGetCall(h,0);t.object=f}else if(i.isLocalSeriesVar(c)){const h=E.createIdentifier(c);h._skipTransformation=!0,t.object=E.createGetCall(h,0)}}else t.object.type==="MemberExpression"?Mt(t.object,e,i):t.object.type==="CallExpression"&&(t.object._transformed||ce(t.object,i))}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(c=>c.value.name?i.isContextBound(c.value.name)||i.isLocalSeriesVar(c.value.name)||i.isLoopVariable(c.value.name)?{type:"Property",key:{type:"Identifier",name:c.key.name},value:E.createIdentifier(c.value.name),kind:"init",method:!1,shorthand:!1,computed:!1}:{type:"Property",key:{type:"Identifier",name:c.key.name},value:he(c.value.name,i),kind:"init",method:!1,shorthand:!1,computed:!1}:(c.value.type!=="Literal"&&(c.value=Mt(c.value,e,i)),c))),t.type==="Identifier"){if(it.includes(t.name)&&i.isContextBound(t.name)){const 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(i.isContextBound(t.name)&&!i.isRootParam(t.name)){const c=E.createMemberExpression(E.createIdentifier(e),E.createIdentifier("param")),u=i.generateParamId(),p={type:"CallExpression",callee:c,arguments:[t,Tr,$i(i,u)],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const h=u;i.addLocalSeriesVar(h);const f=E.createVariableDeclaration(h,p);return i.addHoistedStatement(f),E.createIdentifier(h)}return p}}t?.type==="CallExpression"&&ce(t,i);const s=E.createMemberExpression(E.createIdentifier(e),E.createIdentifier("param")),a=t.type==="Identifier"?mi(t,i):t,o=i.generateParamId(),l={type:"CallExpression",callee:s,arguments:[a,Tr,$i(i,o)],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const c=o;i.addLocalSeriesVar(c);const u=E.createVariableDeclaration(c,l);return i.addHoistedStatement(u),E.createIdentifier(c)}return l}function li(t){if(!t)return!1;if(wa(t))return!0;if(t.type==="MemberExpression")return li(t.object);if(t.type==="ChainExpression")return li(t.expression);if(t.type==="CallExpression"){const e=t.callee;if(e?.type==="MemberExpression")return li(e.object);if(e?.type==="ChainExpression")return li(e.expression)}return!1}function wa(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function Pr(t,e,i){t&&(t.type==="Identifier"?(t.parent=e,le(t,i)):t.type==="MemberExpression"?Pr(t.object,t,i):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&Pr(t.callee.object,t.callee,i),t._transformed||ce(t,i)))}function ce(t,e,i){if(t._transformed)return;t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&(Tt.includes(t.callee.name)||it.includes(t.callee.name))&&e.isContextBound(t.callee.name)&&(t.callee=E.createMemberExpression(t.callee,E.createIdentifier("any")));const r=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(r){if(t.callee.object.name===se&&["get","init","param"].includes(t.callee.property.name))return;const n=t.callee.object.name,s=[];t.arguments.forEach(h=>{if(h._isParamCall){s.push(h);return}s.push(Mt(h,n,e))}),t.arguments=s;const a=t.callee.property.name,o=`${n}.${a}`;if(Pn.includes(n)||Pn.includes(o)){const h=e.getNextPlotCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:h,kind:"init",computed:!1,shorthand:!1}]})}if(n==="alert"){const h=e.getNextAlertCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:h,kind:"init",computed:!1,shorthand:!1}]})}if(n==="ta")if(e.getCurrentScopeType()==="fn"){const h=e.getNextTACallId(),[f]=e.getVariable("$$");let d;f?d=E.createMemberExpression(E.createLocalContextIdentifier(),E.createIdentifier("id")):d=E.createLiteral("");const m={type:"BinaryExpression",operator:"+",left:d,right:h};t.arguments.push(m)}else t.arguments.push(e.getNextTACallId());const l=t.callee.property.name,c=`${n}.${l}`,u=dy.includes(c),p=t._insideAwait===!0;if(u&&!p){const h=Object.assign({},t),f=E.createAwaitExpression(h);Object.assign(t,f)}if(!e.shouldSuppressHoisting()){const h=e.generateTempVar();e.addLocalSeriesVar(h);const f=t._insideAwait===!0;let d=Object.assign({},t);f&&(d=E.createAwaitExpression(d));const m=E.createVariableDeclaration(h,d);e.addHoistedStatement(m);const x=E.createIdentifier(h);Object.assign(t,x),t._wasHoisted=!0,t._wasInsideAwait=f;return}t._transformed=!0}else if(t.callee&&t.callee.type==="Identifier"){if(t.arguments=t.arguments.map(n=>n._isParamCall?n:Mt(n,se,e)),!e.isContextBound(t.callee.name)){const n=e.getNextUserCallId(),s=E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("call")),a=t.callee.name;let o=t.callee;e.isUserMethod(a)&&!e.isRegularUserFunction(a)&&(o=E.createIdentifier(`$M_${a}`),o._skipTransformation=!0);const l=[o,n,...t.arguments];t.callee=s,t.arguments=l}t._transformed=!0}if(!r&&t.callee&&t.callee.type==="MemberExpression"){const n=t.callee.property.name,s=e.isUserFunction(n),a=t.callee.object,o=a.type==="Identifier"&&e.isLocalSeriesVar(a.name),l=a.type==="MemberExpression",c=e.isUserMethod(n),u=!!a.name&&e.isUdtInstance(a.name);if(s&&c&&!e.isContextBound(n)&&!o&&!l&&u){const p=t.callee.object;t.callee.property;const h=t.arguments.map(v=>v._isParamCall?v:Mt(v,se,e));let f=p;p.type==="Identifier"?f=Mt(p,se,e):p.type==="CallExpression"&&(ce(p,e),f=Mt(p,se,e));const d=E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("call")),m=e.getNextUserCallId(),x=E.createIdentifier(`$M_${n}`);x._skipTransformation=!0;const b=[x,m,f,...h];t.callee=d,t.arguments=b,t._transformed=!0;return}t.callee.object.type==="Identifier"?le(t.callee.object,e):Pr(t.callee.object,t.callee,e)}if(t.arguments.forEach(n=>{ue(n,{parent:t},{Identifier(s,a,o){s.parent=a.parent,le(s,e);const l=s.parent&&s.parent.type==="BinaryExpression";(s.parent&&s.parent.type==="ConditionalExpression"||l)&&(s.type==="MemberExpression"?Lt(s,e):s.type==="Identifier"&&(s.parent&&s.parent.type==="CallExpression"&&s.parent.callee&&s.parent.callee.object&&s.parent.callee.object.name===se&&s.parent.callee.property.name==="get"||ke(s)))},BinaryExpression(s,a,o){const l={...a,parent:s};o(s.left,l),o(s.right,l)},LogicalExpression(s,a,o){const l={...a,parent:s};o(s.left,l),o(s.right,l)},UnaryExpression(s,a,o){const 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||ce(s,e)},MemberExpression(s,a,o){ye(s,"",e),s.object&&o(s.object,{parent:s})}})}),t.callee&&t.callee.type==="MemberExpression"){const n=t.callee.object,s=wa(n),a=n?.type==="MemberExpression"&&li(n);if(s||a){const o=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:o},t.optional=!0}}}function Zr(t){const e={type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:t},init:{type:"Literal",value:0}}]},i={type:"IfStatement",test:{type:"BinaryExpression",operator:">",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:i}}function Hi(t,e){let i=null;if(t.left.type==="Identifier")i=he(t.left.name,e);else if(t.left.type==="MemberExpression"&&t.left.computed){if(t.left.object.type==="Identifier"){const r=t.left.object.name,[n,s]=e.getVariable(r),a=n!==r,o=e.isContextBound(r);(a||o)&&!e.isLoopVariable(r)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(i=he(r,e))}}else if(t.left.type==="MemberExpression"&&!t.left.computed){let r=null,n=t.left;for(;n.type==="MemberExpression"&&!n.computed;){if(n.object.type==="Identifier"){r=n;break}n=n.object}if(r){const s=r.object.name,[a,o]=e.getVariable(s);if(a!==s&&!e.isLoopVariable(s)){const l=he(s,e),c=E.createGetCall(l,0);r.object=c}else if(e.isLocalSeriesVar(s)){const l=E.createIdentifier(s);l._skipTransformation=!0,r.object=E.createGetCall(l,0)}}}if(ue(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(r,n,s){const a=n.parent&&n.parent.type==="MemberExpression"&&!n.parent.computed&&n.parent.object===r;if(it.includes(r.name)&&e.isContextBound(r.name)&&!a){const m={type:"MemberExpression",object:{type:"Identifier",name:r.name},property:{type:"Identifier",name:"__value"},computed:!1},x=E.createGetCall(m,0);Object.assign(r,x),delete r.name;return}r.parent=n.parent,le(r,e);const o=r.parent&&r.parent.type==="BinaryExpression",l=r.parent&&r.parent.type==="ConditionalExpression",c=e.isContextBound(r.name)&&!e.isRootParam(r.name),u=r.parent&&r.parent.type==="MemberExpression"&&r.parent.computed&&r.parent.object===r,p=r.parent&&r.parent._isParamCall,h=r.parent&&r.parent.type==="MemberExpression",f=r.name==="NaN",d=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.object&&r.parent.callee.object.name===se&&r.parent.callee.property.name==="get";(c||l||o)&&(r.type==="MemberExpression"?Lt(r,e):r.type==="Identifier"&&!h&&!u&&!p&&!f&&!d&&ke(r))},MemberExpression(r,n,s){ye(r,"",e),r.type==="CallExpression"?r.arguments.forEach(a=>s(a,{parent:r,inNamespaceCall:n.inNamespaceCall})):r.object&&s(r.object,{parent:r,inNamespaceCall:n.inNamespaceCall})},CallExpression(r,n,s){const a=r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&e.isContextBound(r.callee.object.name);ce(r,e),r.type==="CallExpression"&&(r.callee.type==="MemberExpression"&&s(r.callee,{parent:r,inNamespaceCall:a||n.inNamespaceCall}),r.arguments.forEach(o=>s(o,{parent:r,inNamespaceCall:a||n.inNamespaceCall})))}}),i){let r=t.right;if(t.operator!=="="){const s=t.operator.replace("=",""),a=E.createGetCall(i,0);r={type:"BinaryExpression",operator:s,left:a,right:t.right,start:t.start,end:t.end}}const n=E.createSetCall(i,r);t.start&&(n.start=t.start),t.end&&(n.end=t.end),Object.assign(t,n)}}function Sa(t,e){t._skipTransformation||t.declarations.forEach(i=>{if(i.init&&i.init.type==="Identifier"&&it.includes(i.init.name)&&e.isContextBound(i.init.name)){const h=i.init.name;Object.assign(i.init,{type:"MemberExpression",object:{type:"Identifier",name:h},property:{type:"Identifier",name:"__value"},computed:!1}),delete i.init.name}const r=i.init&&i.init.type==="MemberExpression"&&i.init.object&&(i.init.object.name==="context"||i.init.object.name===se||i.init.object.name==="context2"),n=i.init&&i.init.type==="MemberExpression"&&i.init.object?.object&&(i.init.object.object.name==="context"||i.init.object.object.name===se||i.init.object.object.name==="context2"),s=i.init&&i.init.type==="ArrowFunctionExpression";if(r){i.id.name&&e.addContextBoundVar(i.id.name),i.id.properties&&i.id.properties.forEach(h=>{h.key.name&&e.addContextBoundVar(h.key.name)}),i.init.object.name=se;return}if(n){i.id.name&&e.addContextBoundVar(i.id.name),i.id.properties&&i.id.properties.forEach(h=>{h.key.name&&e.addContextBoundVar(h.key.name)}),i.init.object.object.name=se;return}e.addVariable(i.id.name,t.kind);const a=t.kind,o=e.isArrayPatternElement(i.id.name)&&i.init&&i.init.type==="MemberExpression"&&i.init.computed;i.init&&!s&&!o&&(i.init.type==="CallExpression"&&i.init.callee.type==="MemberExpression"&&i.init.callee.object&&i.init.callee.object.type==="Identifier"&&e.isContextBound(i.init.callee.object.name)?ce(i.init,e):ue(i.init,{parent:i.init},{Identifier(h,f){h.parent=f.parent,le(h,e);const d=h.parent&&h.parent.type==="BinaryExpression",m=h.parent&&h.parent.type==="UnaryExpression",x=h.parent&&h.parent.type==="ConditionalExpression",b=h.parent&&h.parent.type==="CallExpression"&&h.parent.callee&&h.parent.callee.object&&h.parent.callee.object.name===se&&h.parent.callee.property.name==="get";h.type==="Identifier"&&(d||m||x)&&!b&&ke(h)},CallExpression(h,f,d){h.callee.type==="Identifier"&&(h.callee.parent=h),h.arguments.forEach(m=>{m.type==="Identifier"&&(m.parent=h)}),(h.callee.type==="ArrowFunctionExpression"||h.callee.type==="FunctionExpression")&&d(h.callee,{parent:h}),ce(h,e),h.type==="CallExpression"&&(h.callee.type==="MemberExpression"&&d(h.callee,{parent:h}),h.arguments.forEach(m=>d(m,{parent:h})))},BinaryExpression(h,f,d){h.left.type==="Identifier"&&(h.left.parent=h),h.right.type==="Identifier"&&(h.right.parent=h),d(h.left,{parent:h}),d(h.right,{parent:h})},LogicalExpression(h,f,d){h.left.type==="Identifier"&&(h.left.parent=h),h.right.type==="Identifier"&&(h.right.parent=h),d(h.left,{parent:h}),d(h.right,{parent:h})},UnaryExpression(h,f,d){h.argument.type==="Identifier"&&(h.argument.parent=h),d(h.argument,{parent:h})},MemberExpression(h,f,d){h.object&&h.object.type==="Identifier"&&(h.object.parent=h),h.property&&h.property.type==="Identifier"&&(h.property.parent=h),ye(h,"",e),h.type==="CallExpression"?h.arguments.forEach(m=>d(m,{parent:h})):h.object&&d(h.object,{parent:h})},AwaitExpression(h,f,d){h.argument&&(h.argument._insideAwait=!0,d(h.argument,{parent:h}),h.argument.type==="Identifier"&&h.argument._wasInsideAwait&&Object.assign(h,h.argument))},ArrowFunctionExpression(h,f,d){if(h.body)if(h.body.type==="BlockStatement"){const m=[];h.body.body.forEach(x=>{e.enterHoistingScope(),d(x,{parent:h.body,insideIIFE:!0});const b=e.exitHoistingScope();m.push(...b),m.push(x)}),h.body.body=m}else d(h.body,{parent:h,insideIIFE:!0})},FunctionExpression(h,f,d){if(h.body&&h.body.type==="BlockStatement"){const m=[];h.body.body.forEach(x=>{e.enterHoistingScope(),d(x,{parent:h.body,insideIIFE:!0});const b=e.exitHoistingScope();m.push(...b),m.push(x)}),h.body.body=m}},SwitchStatement(h,f,d){h.discriminant&&(h.discriminant.parent=h,d(h.discriminant,{parent:h})),h.cases&&h.cases.forEach(m=>{m.parent=h,d(m,{parent:h})})},SwitchCase(h,f,d){if(h.test&&(h.test.parent=h,d(h.test,{parent:h})),h.consequent){const m=[];h.consequent.forEach(x=>{e.enterHoistingScope(),x.parent=h,d(x,{parent:h});const b=e.exitHoistingScope();m.push(...b),m.push(x)}),h.consequent=m}},AssignmentExpression(h,f,d){if(f.insideIIFE){if(h.left.type==="Identifier"){const[m]=e.getVariable(h.left.name);if(m===h.left.name&&!e.isContextBound(h.left.name)){d(h.right,{parent:h});return}}Hi(h,e)}}}));const l=he(i.id.name,e),c=!o&&i.init&&i.init.type==="MemberExpression"&&i.init.computed&&i.init.property&&(i.init.property.type==="Literal"||i.init.property.type==="MemberExpression");if(i.init?.property?.type==="MemberExpression"&&(i.init.property._indexTransformed||(Lt(i.init.property,e),i.init.property._indexTransformed=!0)),a==="var"){const h=e.getCurrentHoistingScope();if(h){for(const f of h)if(f.type==="VariableDeclaration")for(const d of f.declarations){if(!d.init||d.init.type!=="CallExpression")continue;const m=d.init.callee;if(m?.type!=="MemberExpression")continue;let x;const 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){const v=`${x}.${b}`;yy.includes(v)&&(d.init={type:"ArrowFunctionExpression",params:[],body:d.init,expression:!0,async:!1})}}}}let u;i.init?s||o?u=i.init:a==="var"?u=E.createInitVarCall(l,i.init):u=E.createInitCall(l,c?i.init.object:i.init,c?i.init.property:void 0):u=E.createIdentifier("undefined");const p=E.createExpressionStatement(E.createAssignmentExpression(l,u));if(o){const h=i.init.object.name,f=he(h,e),d=i.init.property.value,m={type:"MemberExpression",object:E.createGetCall(f,0),property:{type:"Literal",value:d},computed:!0};p.expression.right=E.createCallExpression(E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("init")),[l,m])}s&&(e.pushScope("fn"),ue(i.init.body,e,{IfStatement(h,f,d){f.pushScope("if"),h.test&&Ea(h.test,f),d(h.consequent,f),h.alternate&&(f.pushScope("els"),d(h.alternate,f),f.popScope()),f.popScope()},VariableDeclaration(h,f){Sa(h,f)},Identifier(h,f){le(h,f)},AssignmentExpression(h,f){Hi(h,f)},SwitchStatement(h,f,d){h.discriminant.parent=h,d(h.discriminant,f),h.cases.forEach(m=>{m.parent=h,d(m,f)})},SwitchCase(h,f,d){h.test&&(h.test.parent=h,d(h.test,f));const m=[];h.consequent.forEach(x=>{f.enterHoistingScope(),d(x,f);const b=f.exitHoistingScope();m.push(...b),m.push(x)}),h.consequent=m},BlockStatement(h,f,d){const m=[];h.body.forEach(x=>{f.enterHoistingScope(),d(x,f);const b=f.exitHoistingScope();m.push(...b),m.push(x)}),h.body=m}}),e.popScope()),Object.assign(t,p)})}function Ay(t,e,i){if(e.setSuppressHoisting(!0),t.init&&t.init.type==="VariableDeclaration"){const 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&&ue(s.init,e,{Identifier(o,l){!e.isLoopVariable(o.name)&&!o.computed&&(e.pushScope("for"),le(o,l),o.type==="Identifier"&&(e.isContextBound(o.name)&&o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===o||(o.computed=!0,ke(o))),e.popScope())},MemberExpression(o,l,c){e.pushScope("for"),ye(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(const u of o.arguments)c(u,l)}})}t.test&&ue(t.test,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),le(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,ke(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),ye(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(const l of s.arguments)o(l,a)}}),t.update&&ue(t.update,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),le(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,ke(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),ye(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(const l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);const r=e.getNextLoopGuardName(),n=Zr(r);if(e.addHoistedStatement(n.counterDecl),e.pushScope("for"),i(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(n.guardCheck),t.init&&t.init.type==="VariableDeclaration"){const s=t.init.declarations[0];e.removeLoopVariable(s.id.name)}}function Py(t,e,i){e.setSuppressHoisting(!0),t.test&&ue(t.test,e,{Identifier(s,a){s.computed||(le(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,ke(s))))},MemberExpression(s,a,o){ye(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),ce(s,a),s.arguments)for(const l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);const r=e.getNextLoopGuardName(),n=Zr(r);e.addHoistedStatement(n.counterDecl),e.pushScope("whl"),i(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(n.guardCheck)}function Ea(t,e){ue(t,e,{MemberExpression(i,r,n){i.object&&i.object.type==="Identifier"&&!e.isContextBound(i.object.name)&&!i.computed&&(i.object.parent=i,n(i.object,r)),ye(i,"",e)},CallExpression(i,r){ce(i,r)},BinaryExpression(i,r,n){i.left.type==="Identifier"&&(i.left.parent=i),i.right.type==="Identifier"&&(i.right.parent=i),n(i.left,r),n(i.right,r)},LogicalExpression(i,r,n){i.left.type==="Identifier"&&(i.left.parent=i),i.right.type==="Identifier"&&(i.right.parent=i),n(i.left,r),n(i.right,r)},UnaryExpression(i,r,n){i.argument.type==="Identifier"&&(i.argument.parent=i),n(i.argument,r)},Identifier(i,r){const n=i.parent,s=n&&n.type==="UnaryExpression",a=n&&n.type==="BinaryExpression",o=n&&n.type==="LogicalExpression",l=n&&n.type==="ConditionalExpression";le(i,r),i.type==="Identifier"&&(s||a||o||l)&&(n&&n.type==="CallExpression"&&n.callee&&n.callee.object&&n.callee.object.name===se&&n.callee.property?.name==="get"||ke(i));const c=e.getCurrentScopeType()==="if";e.isContextBound(i.name)&&!e.isRootParam(i.name)&&c&&ke(i)}})}function Dy(t,e,i){t.test&&(e.pushScope("if"),Ea(t.test,e),e.popScope()),e.pushScope("if"),i(t.consequent,e),e.popScope(),t.alternate&&(e.pushScope("els"),i(t.alternate,e),e.popScope())}function My(t,e){const i=e.getCurrentScopeType();if(t.argument){if(t.argument.type==="ArrayExpression")t.argument.elements=t.argument.elements.map(r=>r.type==="Identifier"?e.isContextBound(r.name)&&!e.isRootParam(r.name)?E.createGetCall(r,0):Ar(r.name,e):r.type==="MemberExpression"?r.object&&r.object.type==="MemberExpression"&&r.object.object&&r.object.object.type==="Identifier"&&r.object.object.name==="$"&&r.object.property&&["const","let","var","params"].includes(r.object.property.name)?E.createGetCall(r,0):(r.computed&&r.object.type==="Identifier"&&e.isContextBound(r.object.name)&&!e.isRootParam(r.object.name)||ye(r,"",e),r):((r.type==="BinaryExpression"||r.type==="LogicalExpression"||r.type==="ConditionalExpression"||r.type==="CallExpression"||r.type==="UnaryExpression")&&ue(r,e,{Identifier(n,s){le(n,s),n.type==="Identifier"&&!n._arrayAccessed&&(ke(n),n._arrayAccessed=!0)},MemberExpression(n){ye(n,"",e)},CallExpression(n,s,a){(n.callee.type==="ArrowFunctionExpression"||n.callee.type==="FunctionExpression")&&a(n.callee,s),ce(n,s),n.type==="CallExpression"&&n.arguments.forEach(o=>a(o,s))},BinaryExpression(n,s,a){a(n.left,s),a(n.right,s)}}),r)),t.argument={type:"ArrayExpression",elements:[t.argument]};else if(t.argument.type==="ObjectExpression")t.argument.properties=t.argument.properties.map(r=>r.shorthand?e.isContextBound(r.value.name)?r:(e.getVariable(r.value.name),{type:"Property",key:E.createIdentifier(r.key.name),value:he(r.value.name,e),kind:"init",method:!1,shorthand:!1,computed:!1}):(r.value&&r.value.type==="Identifier"&&(e.isContextBound(r.value.name)&&!e.isRootParam(r.value.name)||e.isContextBound(r.value.name)||(r.value=he(r.value.name,e))),r));else if(t.argument.type==="Identifier")le(t.argument,e),t.argument.type==="Identifier"&&ke(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))le(t.argument.object,e);else if(t.argument.computed&&t.argument.object.type==="MemberExpression"){let r=t.argument.object;for(;r.object&&r.object.type==="MemberExpression";)r=r.object;r.object?.type==="Identifier"&&e.isUdtInstance(r.object.name)&&ye(t.argument,"",e)}}if(i==="fn"){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=E.createArrayAccess(t.argument,0):t.argument.type==="MemberExpression"?t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)&&(t.argument._indexTransformed||(Lt(t.argument,e),t.argument._indexTransformed=!0)):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression"||t.argument.type==="UnaryExpression"||t.argument.type==="AssignmentExpression")&&ue(t.argument,e,{Identifier(n,s){le(n,s),n.type==="Identifier"&&!n._arrayAccessed&&(ke(n),n._arrayAccessed=!0)},MemberExpression(n){ye(n,"",e)},AssignmentExpression(n,s){Hi(n,s)},CallExpression(n,s,a){(n.callee.type==="ArrowFunctionExpression"||n.callee.type==="FunctionExpression")&&a(n.callee,s),ce(n,s),n.type==="CallExpression"&&n.arguments.forEach(o=>a(o,s))},BinaryExpression(n,s,a){a(n.left,s),a(n.right,s)},ArrowFunctionExpression(n,s,a){if(n.body)if(n.body.type==="BlockStatement"){const o=[];n.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.body.body=o}else a(n.body,s)},FunctionExpression(n,s,a){if(n.body&&n.body.type==="BlockStatement"){const o=[];n.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.body.body=o}},SwitchStatement(n,s,a){n.discriminant.parent=n,a(n.discriminant,s),n.cases.forEach(o=>{o.parent=n,a(o,s)})},SwitchCase(n,s,a){n.test&&(n.test.parent=n,a(n.test,s));const o=[];n.consequent.forEach(l=>{e.enterHoistingScope(),a(l,s);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.consequent=o},BlockStatement(n,s,a){const o=[];n.body.forEach(l=>{s.enterHoistingScope(),a(l,s);const c=s.exitHoistingScope();o.push(...c),o.push(l)}),n.body=o}});const r=E.createCallExpression(E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("precision")),[t.argument]);t.argument=r}}}function Ry(t,e,i){const r=E.createVariableDeclaration("$$",E.createCallExpression(E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("peekCtx")),[]));if(r._skipTransformation=!0,e.addLoopVariable("$$","$$"),t.body&&t.body.type==="BlockStatement"){t.body.body.unshift(r),e.pushScope("fn"),t.params.forEach(l=>{l.type==="Identifier"&&e.addLocalSeriesVar(l.name)});const n=t.id?.name,s=n?.startsWith("$M_")?n.slice(3):n,a=s?e.getFunctionParamUdtTypes(s):void 0,o={};if(a)for(const[l,c]of Object.entries(a))o[l]=e.getVariableUdtType(l),e.markVariableAsUdtInstance(l,c);if(i(t.body,e),t.params.forEach(l=>{l.type==="Identifier"&&e.removeLocalSeriesVar(l.name)}),a)for(const l of Object.keys(a)){e.unmarkVariableAsUdtInstance(l);const c=o[l];c!==void 0&&e.markVariableAsUdtInstance(l,c)}e.popScope()}}function Oy(t){const e={...I,LineComment:()=>{}};function i(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}const r=new Map;He(t,{FunctionDeclaration(o){o.id?.name&&r.set(o.id.name,o)}},e);function n(o){let l=!1;const c={...e,FunctionDeclaration:()=>{},FunctionExpression:()=>{},ArrowFunctionExpression:()=>{}};return He(o,{AwaitExpression(){l=!0}},c),l}let s=!0,a=0;for(;s&&a<20;){s=!1,a++,He(t,{ArrowFunctionExpression(c){!c.async&&n(c.body)&&(c.async=!0,s=!0)},FunctionExpression(c){!c.async&&n(c.body)&&(c.async=!0,s=!0)}},e);const o=[];He(t,{CallExpression(c){!c._asyncWrapped&&(c.callee?.type==="ArrowFunctionExpression"||c.callee?.type==="FunctionExpression")&&c.callee.async===!0&&o.push(c)}},e);for(const c of o){const u={};for(const p of Object.keys(c))u[p]=c[p];u._asyncWrapped=!0;for(const p of Object.keys(c))delete c[p];c.type="AwaitExpression",c.argument=u,s=!0}const l=new Set;for(const[c,u]of r)n(u.body)&&(u.async||(u.async=!0,s=!0),l.add(c));if(l.size>0){const c=[];He(t,{CallExpression(u){if(!u._asyncWrapped&&u.callee?.type==="MemberExpression"&&u.callee.object?.name==="$"&&u.callee.property?.name==="call"&&u.arguments?.length>0){const p=i(u.arguments[0]);p&&l.has(p)&&c.push(u)}}},e);for(const u of c){const p={};for(const h of Object.keys(u))p[h]=u[h];p._asyncWrapped=!0;for(const h of Object.keys(u))delete u[h];u.type="AwaitExpression",u.argument=p,s=!0}}}}function $y(t){const e={...I,LineComment:()=>{}};He(t,{BinaryExpression(i){if(i.operator==="=="||i.operator==="==="){const r=E.createMathEqCall(i.left,i.right);r._transformed=!0,Object.assign(i,r)}else if(i.operator==="!="||i.operator==="!=="){const r=E.createMathNeqCall(i.left,i.right);r._transformed=!0,Object.assign(i,r)}}},e)}function Vy(t,e,i,r={debug:!1,ln:!1},n=[]){const s=a=>{if(!r.debug||!a.loc||!n.length)return null;const o=a.loc.start.line-1;if(o>=0&&o<n.length){const l=n[o].trim();if(l)return{type:"LineComment",value:`${r.ln?` [Line ${a.loc.start.line}]`:""} ${l}`}}return null};ue(t,e,{Program(a,o,l){const c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);const p=o.exitHoistingScope(),h=s(u);h&&c.push(h),c.push(...p),c.push(u)}),a.body=c},BlockStatement(a,o,l){const c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);const p=o.exitHoistingScope(),h=s(u);h&&c.push(h),c.push(...p),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),My(a,o)},VariableDeclaration(a,o){Sa(a,o)},Identifier(a,o){le(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)),ce(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;const p=a.left.declarations[0];p.id.type==="Identifier"?o.addLoopVariable(p.id.name,p.id.name):p.id.type==="ArrayPattern"&&p.id.elements.forEach(h=>{h.type==="Identifier"&&o.addLoopVariable(h.name,h.name)})}if(a.right){a.right.type==="Identifier"?(le(a.right,o),a.right.type==="Identifier"&&ke(a.right)):l(a.right,o);const p=a.left&&a.left.type==="VariableDeclaration"&&a.left.declarations[0].id.type==="ArrayPattern"?"entries":"iter",h={...a.right},f=E.createCallExpression(E.createMemberExpression(E.createIdentifier("$"),E.createIdentifier(p),!1),[h]);Object.assign(a.right,f)}const c=o.getNextLoopGuardName(),u=Zr(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"){const p=a.left.declarations[0];p.id.type==="Identifier"?o.removeLoopVariable(p.id.name):p.id.type==="ArrayPattern"&&p.id.elements.forEach(h=>{h.type==="Identifier"&&o.removeLoopVariable(h.name)})}},ForInStatement(a,o,l){a.left&&a.left.type==="VariableDeclaration"&&(a.left._skipTransformation=!0),a.right&&a.right.type==="Identifier"?(le(a.right,o),a.right.type==="Identifier"&&ke(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)),ye(a,i,o)},AssignmentExpression(a,o,l){if(Hi(a,o),a.type==="CallExpression"&&a.arguments){const 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){Ry(a,o,l)},ForStatement(a,o,l){Ay(a,o,l)},WhileStatement(a,o,l){Py(a,o,l)},IfStatement(a,o,l){Dy(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));const c=[];a.consequent.forEach(u=>{o.enterHoistingScope(),l(u,o);const p=o.exitHoistingScope();c.push(...p),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))}})}const g={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"},jy=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","import","export","method","extends","enum"]),Ly=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"];class By{constructor(e,i,r,n,s=0){this.type=e,this.value=i,this.line=r,this.column=n,this.indent=s}}var Fy=Object.defineProperty,Wy=(t,e,i)=>e in t?Fy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,nt=(t,e,i)=>Wy(t,typeof e!="symbol"?e+"":e,i);class Uy{constructor(e){nt(this,"source"),nt(this,"pos"),nt(this,"line"),nt(this,"column"),nt(this,"tokens"),nt(this,"indentStack"),nt(this,"atLineStart"),nt(this,"parenDepth"),nt(this,"bracketDepth"),nt(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;){const e=this.peek();if(e==="\r"){this.advance();continue}if(e===`
17
+ }`}function My(t){de(t,null,{VariableDeclaration(e,i,r){e.declarations&&e.declarations.length>0&&e.declarations.forEach(n=>{if(n.init&&n.init.type==="ArrowFunctionExpression"&&n.init.start!==0){const a={type:"FunctionDeclaration",id:n.id,params:n.init.params,body:n.init.body.type==="BlockStatement"?n.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:n.init.body}]},async:n.init.async,generator:!1};Object.assign(e,a)}}),e.body&&e.body.body&&e.body.body.forEach(n=>r(n,i))}})}function Dy(t,e){Ge(t,{VariableDeclaration(r){for(const n of r.declarations)if(!(n.id?.type!=="Identifier"||!n.init)&&n.init.type==="CallExpression"&&n.init.callee?.type==="Identifier"&&n.init.callee.name==="Type"&&n.init.arguments?.length===1&&n.init.arguments[0]?.type==="ObjectExpression"){const a={};for(const s of n.init.arguments[0].properties)s.type!=="Property"||s.key?.type!=="Identifier"||(s.value?.type==="ArrayExpression"&&s.value.elements?.[0]?.type==="Literal"?a[s.key.name]=String(s.value.elements[0].value):s.value?.type==="Literal"&&(a[s.key.name]=String(s.value.value)));e.addUdtTypeName(n.id.name,a)}}});let i=!0;for(;i;)i=!1,Ge(t,{FunctionDeclaration(r){if(!r.id?.name)return;const n=r.id.name;if(e.getFunctionReturnType(n)||e.getFunctionReturnTupleType(n))return;const a=Ry(r.body);if(a.length===0)return;if(a.every(l=>l.type==="ArrayExpression")){const l=a[0].elements.length;if(l>0&&a.every(c=>c.elements.length===l)){const c=[];let u=!0;for(let p=0;p<l;p++){const h=a.map(d=>mi(d.elements[p],e)),f=h[0];if(!h.every(d=>d===f)){u=!1;break}c.push(f)}if(u&&c.some(p=>!!p)){e.setFunctionReturnTupleType(n,c),i=!0;return}}}const s=a.map(l=>mi(l,e)),o=s[0];!o||!s.every(l=>l===o)||(e.setFunctionReturnType(n,o),i=!0)}});Ge(t,{VariableDeclaration(r){for(const n of r.declarations)if(n.init){if(n.id?.type==="Identifier"){const a=mi(n.init,e);a&&e.markVariableAsUdtInstance(n.id.name,a);continue}if(n.id?.type==="ArrayPattern"&&n.init.type==="CallExpression"&&n.init.callee?.type==="Identifier"){const a=e.getFunctionReturnTupleType(n.init.callee.name);if(!a)continue;n.id.elements?.forEach((s,o)=>{if(!s||s.type!=="Identifier")return;const l=a[o];l&&e.markVariableAsUdtInstance(s.name,l)})}}},ExpressionStatement(r){const n=r.expression;if(n?.type==="Literal"&&typeof n.value=="string"&&n.value.startsWith("__pineUdtVar:")){const a=n.value.match(/^__pineUdtVar:([A-Za-z_$][\w$]*)=([A-Za-z_$][\w$]*)$/);if(a){const[,s,o]=a;e.isUdtTypeName(o)&&e.markVariableAsUdtInstance(s,o)}}}}),Ge(t,{ExpressionStatement(r){const n=r.expression;if(!n||n.type!=="AssignmentExpression"||n.operator!=="=")return;const a=n.left;if(a?.type!=="MemberExpression"||a.computed||a.property?.type!=="Identifier"||a.property.name!=="__pineParamTypes__"||a.object?.type!=="Identifier"||n.right?.type!=="ObjectExpression")return;const s=a.object.name,o=s.startsWith("$M_")?s.slice(3):s,l={};for(const c of n.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;const p=c.value.value.split(/\s+/).pop();e.isUdtTypeName(p)&&(l[u]=p)}Object.keys(l).length>0&&e.setFunctionParamUdtTypes(o,l)}})}function Ry(t){const e=[];if(!t)return e;function i(r){if(!(!r||typeof r!="object")&&!(r.type==="FunctionDeclaration"||r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression")){if(r.type==="ReturnStatement"&&r.argument){e.push(r.argument);return}for(const n of Object.keys(r)){if(n==="type")continue;const a=r[n];Array.isArray(a)?a.forEach(i):a&&typeof a=="object"&&a.type&&i(a)}}}return i(t),e}function mi(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"){const i=e.getFunctionReturnType(t.callee.name);if(i)return i}if(t.type==="ConditionalExpression"){const i=mi(t.consequent,e),r=mi(t.alternate,e);if(i&&i===r)return i}}}function Oy(t,e){Ge(t,{VariableDeclaration(i){i.declarations.forEach(r=>{const n=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===le||r.init.object.name==="context2"),a=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===le||r.init.object.object.name==="context2");(n||a)&&(r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(s=>{s.key.name&&e.addContextBoundVar(s.key.name)}))})}})}function $y(t,e,i=!1){t.params.forEach(r=>{r.type==="Identifier"&&i&&e.addContextBoundVar(r.name,i)})}function Vy(t,e){let i;return by(t,{FunctionDeclaration(r){r.id&&r.id.name&&(e.addReservedName(r.id.name),e.addUserFunction(r.id.name),r.id.name.startsWith("$M_")||e.addRegularUserFunction(r.id.name))},ExpressionStatement(r){const n=r.expression;if(n&&n.type==="AssignmentExpression"&&n.operator==="="&&n.left?.type==="MemberExpression"&&n.left.property?.name==="__pineMethod__"&&n.left.object?.type==="Identifier"&&n.right?.value===!0){const a=n.left.object.name,s=a.startsWith("$M_")?a.slice(3):a;e.addUserMethod(s),e.addUserFunction(s)}},ArrowFunctionExpression(r){const n=r.start===0;n&&r.params&&r.params.length>0&&(i=r.params[0].name,r.params[0].name=le),$y(r,e,n)},VariableDeclaration(r,n){const a=n.length>1?n[n.length-2]:null,s=a&&(a.type==="ForOfStatement"||a.type==="ForInStatement")&&a.left===r;r.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(h=>{h&&h.type==="Identifier"&&e.addReservedName(h.name)}),s)return;const l=e.generateTempVar(),c={type:"VariableDeclaration",kind:r.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")&&Ge(u.callee.body,{ReturnStatement(h){h.argument&&h.argument.type==="ArrayExpression"&&(h.argument={type:"ArrayExpression",elements:[h.argument]})}}),o.id.elements?.forEach(h=>{h.type==="Identifier"&&e.addArrayPatternElement(h.name)});const p=o.id.elements.map((h,f)=>({type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:h,init:{type:"MemberExpression",object:{type:"Identifier",name:l},property:{type:"Literal",value:f},computed:!0}}]}));Object.assign(r,{type:"BlockStatement",body:[c,...p]})}})},ForStatement(r){}}),i}const Rr={type:"Identifier",name:"undefined"};function Vi(t,e){const i={type:"Identifier",name:`'${e}'`};if(!t.isInsideFunctionScope())return i;const[r]=t.getVariable("$$");return r?{type:"BinaryExpression",operator:"+",left:E.createMemberExpression(E.createLocalContextIdentifier(),E.createIdentifier("id")),right:i}:i}function me(t,e){const[i,r]=e.getVariable(t);if((i.match(/^fn\d+_/)||e.isVariableInFunctionScope(t))&&t!=="$$"){const[n]=e.getVariable("$$");if(n)return E.createLocalContextVariableReference(r,i)}return E.createContextVariableReference(r,i)}function Or(t,e){const i=me(t,e);return E.createGetCall(i,0)}function Wt(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)){const i=E.createIdentifier(t.object.name);i._skipTransformation=!0;const r=E.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(!e.isContextBound(t.object.name)){const i=me(t.object.name,e),r=E.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0}}return}if(!e.isContextBound(t.property.name))if(e.isLocalSeriesVar(t.property.name)){const i=E.createIdentifier(t.property.name);i._skipTransformation=!0,t.property=E.createGetCall(i,0)}else t.property=me(t.property.name,e),t.property=E.createGetCall(t.property,0)}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(e.isLocalSeriesVar(t.object.name)){const i=E.createIdentifier(t.object.name);i._skipTransformation=!0;const r=E.createGetCall(i,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(e.isContextBound(t.object.name)||(t.object=me(t.object.name,e)),t.property.type==="MemberExpression"){const i=t.property;i._indexTransformed||(Wt(i,e),i._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=ut(t.property,e))}function Pe(t,e){const i=E.createGetCall(E.createIdentifier(t.name),0);t.start!==void 0&&(i.start=t.start),t.end!==void 0&&(i.end=t.end),i._indexTransformed=!0,Object.assign(t,i)}function pe(t,e){if(!t._skipTransformation&&t.name!==le){if(rt.includes(t.name)&&e.isContextBound(t.name)){const h=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,f=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&!t.parent.computed;if(!h&&!f){const d={type:"MemberExpression",object:{type:"Identifier",name:t.name},property:{type:"Identifier",name:"__value"},computed:!1},m=E.createGetCall(d,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 i=!1;if(t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t)){const h=t.parent.callee;if(h.type==="MemberExpression"&&h.object&&h.object.name===le&&["get","set","init","param","call"].includes(h.property.name)){const f=t.parent.arguments.indexOf(t);h.property.name==="call"?f>=2&&(i=!0):f===0&&(i=!0)}else{const f=h.type==="MemberExpression"&&h.object&&h.object.type==="Identifier"&&Tt.includes(h.object.name);h.type==="MemberExpression"&&!f?i=!1:i=!0}}const r=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&e.isContextBound(t.name),n=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;const a=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,s=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(r||n||i||o||a){if(a||t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.object&&t.parent.callee.object.name===le&&t.parent.callee.property.name==="call"&&t.parent.arguments[0]===t||e.isLocalSeriesVar(t.name)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;const h=me(t.name,e);Object.assign(t,h);return}const l=e.isContextBound(t.name)&&!e.isRootParam(t.name);if(l){const h=t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t),f=t.parent&&t.parent.type==="SwitchStatement"&&t.parent.discriminant===t,d=t.parent&&t.parent.type==="SwitchCase"&&t.parent.test===t;if(!h&&!f&&!d)return}if(e.isLocalSeriesVar(t.name)){if(!s){const h=E.createIdentifier(t.name),f=E.createGetCall(h,0);Object.assign(t,f)}return}const[c,u]=e.getVariable(t.name);let p;if(l)p=E.createIdentifier(t.name);else{if(c===t.name&&!e.isContextBound(t.name))return;p=me(t.name,e)}if(s)Object.assign(t,p);else{const h=E.createGetCall(p,0);Object.assign(t,h)}}}function xe(t,e,i){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;if(t.object&&t.object.type==="Identifier"&&Tt.includes(t.object.name)&&i.isContextBound(t.object.name)&&!t.computed){const 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){const 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"&&i.isLocalSeriesVar(t.object.name)){const l=E.createIdentifier(t.object.name);l._skipTransformation=!0,t.object=E.createGetCall(l,0);return}const r=i.getCurrentScopeType()=="if",n=i.getCurrentScopeType()=="els",a=i.getCurrentScopeType()=="for";if(!r&&!n&&!a&&t.object&&t.object.type==="Identifier"&&i.isContextBound(t.object.name)&&!i.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(Wt(t,i),t._indexTransformed=!0);const s=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&(t.object.object.object.name===le||t.object.object.object.name==="$$"),o=t.object&&t.object.type==="Identifier"&&i.isContextBound(t.object.name);if(t.computed&&(s||o)){if(t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left===t)return;t.object.type==="Identifier"&&rt.includes(t.object.name)&&i.isContextBound(t.object.name)&&(t.object={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1});const l=E.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"&&i.isUdtInstance(l.object.name)){const c=l.object.name,u=i.isLocalSeriesVar(c)?(()=>{const h=E.createIdentifier(c);return h._skipTransformation=!0,h})():me(c,i);l.object=E.createGetCall(u,t.property);const p=t.object;Object.assign(t,p),delete t.computed;return}}}function yi(t,e){if(t.type==="Identifier"){if(rt.includes(t.name)&&e.isContextBound(t.name)){const a=t.name;return Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:a},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name,t}if(e.isLoopVariable(t.name))return t;if(e.isRootParam(t.name)){const[a,s]=e.getVariable(t.name);return E.createContextVariableReference(s,a)}if(e.isContextBound(t.name))return t;const[i,r]=e.getVariable(t.name),n=i!==t.name;return e.isLocalSeriesVar(t.name)&&!n?t:n?me(t.name,e):i===t.name&&!e.isContextBound(t.name)?t:me(t.name,e)}return t}function ut(t,e,i=""){switch(t.type){case"BinaryExpression":return ji(t,e,i);case"LogicalExpression":return Li(t,e,i);case"MemberExpression":{const r=!t.computed&&t.object.type==="Identifier"&&rt.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&rt.includes(t.object.name)&&e.isContextBound(t.object.name)){const s={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1};return E.createGetCall(s,t.property)}const n=t.object.type==="Identifier"&&!r?yi(t.object,e):t.object;let a=n;if(!t.computed&&t.object.type==="Identifier"&&!r){const[s]=e.getVariable(t.object.name);s!==t.object.name&&!e.isLoopVariable(t.object.name)&&(a=E.createGetCall(n,0))}return{type:"MemberExpression",object:a,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;const r=yi(t,e);return r.type==="Identifier"&&(r.name==="NaN"||r.name==="undefined"||r.name==="Infinity"||r.name==="null"||r.name==="Math")?r:E.createGetCall(r,0)}case"UnaryExpression":return Bi(t,e,i);case"ConditionalExpression":{const r=ut(t.test,e,i),n=ut(t.consequent,e,i),a=ut(t.alternate,e,i);return{type:"ConditionalExpression",test:r,consequent:n,alternate:a,start:t.start,end:t.end}}}return t}function ji(t,e,i){const r=ut(t.left,e,i),n=ut(t.right,e,i),a={type:"BinaryExpression",operator:t.operator,left:r,right:n,start:t.start,end:t.end};return de(a,e,{CallExpression(s,o){s._transformed||fe(s,o)},MemberExpression(s){xe(s,"",e)}}),a}function Li(t,e,i){const r=ut(t.left,e,i),n=ut(t.right,e,i),a={type:"LogicalExpression",operator:t.operator,left:r,right:n,start:t.start,end:t.end};return de(a,e,{CallExpression(s,o){s._transformed||fe(s,o)}}),a}function xr(t,e,i){de(t,{parent:t,inNamespaceCall:!1},{Identifier(s,o,l){if(s.name=="NaN")return;if(rt.includes(s.name)&&e.isContextBound(s.name)){if(o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===s&&!o.parent.computed)return;const u={type:"MemberExpression",object:{type:"Identifier",name:s.name},property:{type:"Identifier",name:"__value"},computed:!1},p=E.createGetCall(u,0);Object.assign(s,p),delete s.name;return}s.parent=o.parent,pe(s,e);const c=s.parent&&s.parent.type==="BinaryExpression";(s.parent&&s.parent.type==="ConditionalExpression"||c)&&(s.type==="MemberExpression"?Wt(s,e):s.type==="Identifier"&&(s.parent&&s.parent.type==="CallExpression"&&s.parent.callee&&s.parent.callee.object&&s.parent.callee.object.name===le&&s.parent.callee.property.name==="get"||Pe(s)))},MemberExpression(s,o,l){xe(s,"",e),s.object&&l(s.object,{parent:s,inNamespaceCall:o.inNamespaceCall})},ConditionalExpression(s,o,l){const c={...o,parent:s};s.test&&l(s.test,c),s.consequent&&l(s.consequent,c),s.alternate&&l(s.alternate,c)},BinaryExpression(s,o,l){const c={...o,parent:s};l(s.left,c),l(s.right,c)},LogicalExpression(s,o,l){const c={...o,parent:s};l(s.left,c),l(s.right,c)},UnaryExpression(s,o,l){const c={...o,parent:s};l(s.argument,c)},CallExpression(s,o,l){const c=s.callee&&s.callee.type==="MemberExpression"&&s.callee.object&&s.callee.object.type==="Identifier"&&e.isContextBound(s.callee.object.name);fe(s,e),s.arguments.forEach(u=>l(u,{parent:s,inNamespaceCall:c||o.inNamespaceCall}))}});const r=E.createMemberExpression(E.createIdentifier(i),E.createIdentifier("param")),n=e.generateParamId(),a={type:"CallExpression",callee:r,arguments:[t,Rr,Vi(e,n)],_transformed:!0,_isParamCall:!0};if(!e.shouldSuppressHoisting()){const s=n;e.addLocalSeriesVar(s);const o=E.createVariableDeclaration(s,a);return e.addHoistedStatement(o),E.createIdentifier(s)}return a}function Bi(t,e,i){const r=ut(t.argument,e,i),n={type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:r,start:t.start,end:t.end};return de(n,e,{CallExpression(a,s){a._transformed||fe(a,s)},MemberExpression(a){xe(a,"",e)}}),n}function Rt(t,e,i){switch(t?.type){case"BinaryExpression":t=ji(t,i,e);break;case"LogicalExpression":t=Li(t,i,e);break;case"ConditionalExpression":return xr(t,i,e);case"UnaryExpression":t=Bi(t,i,e);break;case"ArrayExpression":t.elements=t.elements.map(c=>{if(c.type==="Identifier"){if(i.isContextBound(c.name)&&!i.isRootParam(c.name))return c;if(i.isLocalSeriesVar(c.name)){const u=E.createIdentifier(c.name);return E.createGetCall(u,0)}return Or(c.name,i)}return c.type==="CallExpression"?(fe(c,i),c):c.type==="BinaryExpression"?ji(c,i,e):c.type==="LogicalExpression"?Li(c,i,e):c.type==="ConditionalExpression"?xr(c,i,e):c.type==="UnaryExpression"?Bi(c,i,e):(c.type==="MemberExpression"&&xe(c,e,i),c)});break}const r=t.type==="MemberExpression"&&t.computed&&t.property,n=t.type==="MemberExpression"&&!t.computed;if(r){if(t.object&&t.object.type==="MemberExpression"){let d=t.object;for(;d.object&&d.object.type==="MemberExpression";)d=d.object;if(d.object?.type==="Identifier"&&i.isUdtInstance(d.object.name)){const m=d.object.name,x=i.isLocalSeriesVar(m)?(()=>{const b=E.createIdentifier(m);return b._skipTransformation=!0,b})():me(m,i);return d.object=E.createGetCall(x,t.property),t.object}}if(t.object.type==="CallExpression")fe(t.object,i);else if(t.object.type==="MemberExpression"){xe(t.object,"",i);let d=t.object;for(;d&&d.type==="MemberExpression"&&d.object;){if(d.object.type==="Identifier"){const m=d.object,[x]=i.getVariable(m.name);x!==m.name&&!i.isContextBound(m.name)&&!i.isRootParam(m.name)&&!i.isLoopVariable(m.name)&&!i.isLocalSeriesVar(m.name)&&!rt.includes(m.name)&&!Tt.includes(m.name)&&(d.object=Or(m.name,i));break}d=d.object}}else t.object.type==="BinaryExpression"?t.object=ji(t.object,i,e):t.object.type==="LogicalExpression"?t.object=Li(t.object,i,e):t.object.type==="ConditionalExpression"?t.object=xr(t.object,i,e):t.object.type==="UnaryExpression"&&(t.object=Bi(t.object,i,e));const c=t.object.type==="Identifier"&&i.isContextBound(t.object.name)&&!i.isRootParam(t.object.name)?t.object:yi(t.object,i);let u;t.property.type==="Identifier"&&!i.isContextBound(t.property.name)&&!i.isLoopVariable(t.property.name)?u=E.createGetCall(yi(t.property,i),0):t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression"?u=ut(t.property,i,e):u=t.property;const p=E.createMemberExpression(E.createIdentifier(e),E.createIdentifier("param")),h=i.generateParamId(),f={type:"CallExpression",callee:p,arguments:[c,u,Vi(i,h)],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const d=h;i.addLocalSeriesVar(d);const m=E.createVariableDeclaration(d,f);return i.addHoistedStatement(m),E.createIdentifier(d)}return f}if(n){if(t.object.type==="Identifier"&&Tt.includes(t.object.name)&&i.isContextBound(t.object.name)&&!t.computed){const 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(i.getNextTACallId());const p=i.generateTempVar();i.addLocalSeriesVar(p);const h=E.createVariableDeclaration(p,u);return i.addOuterHoistedStatement(h),Object.assign(t,E.createIdentifier(p)),t}if(t.object.type==="Identifier"){const c=t.object.name,[u,p]=i.getVariable(c);if(u!==c&&!i.isLoopVariable(c)){const h=me(c,i),f=E.createGetCall(h,0);t.object=f}else if(i.isLocalSeriesVar(c)){const h=E.createIdentifier(c);h._skipTransformation=!0,t.object=E.createGetCall(h,0)}}else t.object.type==="MemberExpression"?Rt(t.object,e,i):t.object.type==="CallExpression"&&(t.object._transformed||fe(t.object,i))}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(c=>c.value.name?i.isContextBound(c.value.name)||i.isLocalSeriesVar(c.value.name)||i.isLoopVariable(c.value.name)?{type:"Property",key:{type:"Identifier",name:c.key.name},value:E.createIdentifier(c.value.name),kind:"init",method:!1,shorthand:!1,computed:!1}:{type:"Property",key:{type:"Identifier",name:c.key.name},value:me(c.value.name,i),kind:"init",method:!1,shorthand:!1,computed:!1}:(c.value.type!=="Literal"&&(c.value=Rt(c.value,e,i)),c))),t.type==="Identifier"){if(rt.includes(t.name)&&i.isContextBound(t.name)){const 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(i.isContextBound(t.name)&&!i.isRootParam(t.name)){const c=E.createMemberExpression(E.createIdentifier(e),E.createIdentifier("param")),u=i.generateParamId(),p={type:"CallExpression",callee:c,arguments:[t,Rr,Vi(i,u)],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const h=u;i.addLocalSeriesVar(h);const f=E.createVariableDeclaration(h,p);return i.addHoistedStatement(f),E.createIdentifier(h)}return p}}t?.type==="CallExpression"&&fe(t,i);const a=E.createMemberExpression(E.createIdentifier(e),E.createIdentifier("param")),s=t.type==="Identifier"?yi(t,i):t,o=i.generateParamId(),l={type:"CallExpression",callee:a,arguments:[s,Rr,Vi(i,o)],_transformed:!0,_isParamCall:!0};if(!i.shouldSuppressHoisting()){const c=o;i.addLocalSeriesVar(c);const u=E.createVariableDeclaration(c,l);return i.addHoistedStatement(u),E.createIdentifier(c)}return l}function ci(t){if(!t)return!1;if(Ia(t))return!0;if(t.type==="MemberExpression")return ci(t.object);if(t.type==="ChainExpression")return ci(t.expression);if(t.type==="CallExpression"){const e=t.callee;if(e?.type==="MemberExpression")return ci(e.object);if(e?.type==="ChainExpression")return ci(e.expression)}return!1}function Ia(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function $r(t,e,i){t&&(t.type==="Identifier"?(t.parent=e,pe(t,i)):t.type==="MemberExpression"?$r(t.object,t,i):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&$r(t.callee.object,t.callee,i),t._transformed||fe(t,i)))}function fe(t,e,i){if(t._transformed)return;t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&(Tt.includes(t.callee.name)||rt.includes(t.callee.name))&&e.isContextBound(t.callee.name)&&(t.callee=E.createMemberExpression(t.callee,E.createIdentifier("any")));const r=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(r){if(t.callee.object.name===le&&["get","init","param"].includes(t.callee.property.name))return;const n=t.callee.object.name,a=[];t.arguments.forEach(h=>{if(h._isParamCall){a.push(h);return}a.push(Rt(h,n,e))}),t.arguments=a;const s=t.callee.property.name,o=`${n}.${s}`;if(Rn.includes(n)||Rn.includes(o)){const h=e.getNextPlotCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:h,kind:"init",computed:!1,shorthand:!1}]})}if(n==="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}]}),n==="alert"){const h=e.getNextAlertCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:h,kind:"init",computed:!1,shorthand:!1}]})}if(n==="ta")if(e.getCurrentScopeType()==="fn"){const h=e.getNextTACallId(),[f]=e.getVariable("$$");let d;f?d=E.createMemberExpression(E.createLocalContextIdentifier(),E.createIdentifier("id")):d=E.createLiteral("");const m={type:"BinaryExpression",operator:"+",left:d,right:h};t.arguments.push(m)}else t.arguments.push(e.getNextTACallId());const l=t.callee.property.name,c=`${n}.${l}`,u=wy.includes(c),p=t._insideAwait===!0;if(u&&!p){const h=Object.assign({},t),f=E.createAwaitExpression(h);Object.assign(t,f)}if(!e.shouldSuppressHoisting()){const h=e.generateTempVar();e.addLocalSeriesVar(h);const f=t._insideAwait===!0;let d=Object.assign({},t);f&&(d=E.createAwaitExpression(d));const m=E.createVariableDeclaration(h,d);e.addHoistedStatement(m);const x=E.createIdentifier(h);Object.assign(t,x),t._wasHoisted=!0,t._wasInsideAwait=f;return}t._transformed=!0}else if(t.callee&&t.callee.type==="Identifier"){if(t.arguments=t.arguments.map(n=>n._isParamCall?n:Rt(n,le,e)),!e.isContextBound(t.callee.name)){const n=e.getNextUserCallId(),a=E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("call")),s=t.callee.name;let o=t.callee;e.isUserMethod(s)&&!e.isRegularUserFunction(s)&&(o=E.createIdentifier(`$M_${s}`),o._skipTransformation=!0);const l=[o,n,...t.arguments];t.callee=a,t.arguments=l}t._transformed=!0}if(!r&&t.callee&&t.callee.type==="MemberExpression"){const n=t.callee.property.name,a=e.isUserFunction(n),s=t.callee.object,o=s.type==="Identifier"&&e.isLocalSeriesVar(s.name),l=s.type==="MemberExpression",c=e.isUserMethod(n),u=!!s.name&&e.isUdtInstance(s.name);if(a&&c&&!e.isContextBound(n)&&!o&&!l&&u){const p=t.callee.object;t.callee.property;const h=t.arguments.map(v=>v._isParamCall?v:Rt(v,le,e));let f=p;p.type==="Identifier"?f=Rt(p,le,e):p.type==="CallExpression"&&(fe(p,e),f=Rt(p,le,e));const d=E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("call")),m=e.getNextUserCallId(),x=E.createIdentifier(`$M_${n}`);x._skipTransformation=!0;const b=[x,m,f,...h];t.callee=d,t.arguments=b,t._transformed=!0;return}t.callee.object.type==="Identifier"?pe(t.callee.object,e):$r(t.callee.object,t.callee,e)}if(t.arguments.forEach(n=>{de(n,{parent:t},{Identifier(a,s,o){a.parent=s.parent,pe(a,e);const l=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||l)&&(a.type==="MemberExpression"?Wt(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===le&&a.parent.callee.property.name==="get"||Pe(a)))},BinaryExpression(a,s,o){const l={...s,parent:a};o(a.left,l),o(a.right,l)},LogicalExpression(a,s,o){const l={...s,parent:a};o(a.left,l),o(a.right,l)},UnaryExpression(a,s,o){const l={...s,parent:a};o(a.argument,l)},CallExpression(a,s,o){a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&(a.callee.object.parent=a.callee,o(a.callee.object,{parent:a.callee})),a._transformed||fe(a,e)},MemberExpression(a,s,o){xe(a,"",e),a.object&&o(a.object,{parent:a})}})}),t.callee&&t.callee.type==="MemberExpression"){const n=t.callee.object,a=Ia(n),s=n?.type==="MemberExpression"&&ci(n);if(a||s){const o=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:o},t.optional=!0}}}function tn(t){const e={type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:t},init:{type:"Literal",value:0}}]},i={type:"IfStatement",test:{type:"BinaryExpression",operator:">",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:i}}function Xi(t,e){let i=null;if(t.left.type==="Identifier")i=me(t.left.name,e);else if(t.left.type==="MemberExpression"&&t.left.computed){if(t.left.object.type==="Identifier"){const r=t.left.object.name,[n,a]=e.getVariable(r),s=n!==r,o=e.isContextBound(r);(s||o)&&!e.isLoopVariable(r)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(i=me(r,e))}}else if(t.left.type==="MemberExpression"&&!t.left.computed){let r=null,n=t.left;for(;n.type==="MemberExpression"&&!n.computed;){if(n.object.type==="Identifier"){r=n;break}n=n.object}if(r){const a=r.object.name,[s,o]=e.getVariable(a);if(s!==a&&!e.isLoopVariable(a)){const l=me(a,e),c=E.createGetCall(l,0);r.object=c}else if(e.isLocalSeriesVar(a)){const l=E.createIdentifier(a);l._skipTransformation=!0,r.object=E.createGetCall(l,0)}}}if(de(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(r,n,a){const s=n.parent&&n.parent.type==="MemberExpression"&&!n.parent.computed&&n.parent.object===r;if(rt.includes(r.name)&&e.isContextBound(r.name)&&!s){const m={type:"MemberExpression",object:{type:"Identifier",name:r.name},property:{type:"Identifier",name:"__value"},computed:!1},x=E.createGetCall(m,0);Object.assign(r,x),delete r.name;return}r.parent=n.parent,pe(r,e);const o=r.parent&&r.parent.type==="BinaryExpression",l=r.parent&&r.parent.type==="ConditionalExpression",c=e.isContextBound(r.name)&&!e.isRootParam(r.name),u=r.parent&&r.parent.type==="MemberExpression"&&r.parent.computed&&r.parent.object===r,p=r.parent&&r.parent._isParamCall,h=r.parent&&r.parent.type==="MemberExpression",f=r.name==="NaN",d=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.object&&r.parent.callee.object.name===le&&r.parent.callee.property.name==="get";(c||l||o)&&(r.type==="MemberExpression"?Wt(r,e):r.type==="Identifier"&&!h&&!u&&!p&&!f&&!d&&Pe(r))},MemberExpression(r,n,a){xe(r,"",e),r.type==="CallExpression"?r.arguments.forEach(s=>a(s,{parent:r,inNamespaceCall:n.inNamespaceCall})):r.object&&a(r.object,{parent:r,inNamespaceCall:n.inNamespaceCall})},CallExpression(r,n,a){const s=r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&e.isContextBound(r.callee.object.name);fe(r,e),r.type==="CallExpression"&&(r.callee.type==="MemberExpression"&&a(r.callee,{parent:r,inNamespaceCall:s||n.inNamespaceCall}),r.arguments.forEach(o=>a(o,{parent:r,inNamespaceCall:s||n.inNamespaceCall})))}}),i){let r=t.right;if(t.operator!=="="){const a=t.operator.replace("=",""),s=E.createGetCall(i,0);r={type:"BinaryExpression",operator:a,left:s,right:t.right,start:t.start,end:t.end}}const n=E.createSetCall(i,r);t.start&&(n.start=t.start),t.end&&(n.end=t.end),Object.assign(t,n)}}function ka(t,e){t._skipTransformation||t.declarations.forEach(i=>{if(i.init?.type==="CallExpression"&&i.id?.type==="Identifier"){const h=i.init.callee;(h?.type==="MemberExpression"&&h.object?.type==="Identifier"&&h.object.name==="input"||h?.type==="Identifier"&&h.name==="input")&&(i.init._varId=i.id.name)}if(i.init&&i.init.type==="Identifier"&&rt.includes(i.init.name)&&e.isContextBound(i.init.name)){const h=i.init.name;Object.assign(i.init,{type:"MemberExpression",object:{type:"Identifier",name:h},property:{type:"Identifier",name:"__value"},computed:!1}),delete i.init.name}const r=i.init&&i.init.type==="MemberExpression"&&i.init.object&&(i.init.object.name==="context"||i.init.object.name===le||i.init.object.name==="context2"),n=i.init&&i.init.type==="MemberExpression"&&i.init.object?.object&&(i.init.object.object.name==="context"||i.init.object.object.name===le||i.init.object.object.name==="context2"),a=i.init&&i.init.type==="ArrowFunctionExpression";if(r){i.id.name&&e.addContextBoundVar(i.id.name),i.id.properties&&i.id.properties.forEach(h=>{h.key.name&&e.addContextBoundVar(h.key.name)}),i.init.object.name=le;return}if(n){i.id.name&&e.addContextBoundVar(i.id.name),i.id.properties&&i.id.properties.forEach(h=>{h.key.name&&e.addContextBoundVar(h.key.name)}),i.init.object.object.name=le;return}e.addVariable(i.id.name,t.kind);const s=t.kind,o=e.isArrayPatternElement(i.id.name)&&i.init&&i.init.type==="MemberExpression"&&i.init.computed;i.init&&!a&&!o&&(i.init.type==="CallExpression"&&i.init.callee.type==="MemberExpression"&&i.init.callee.object&&i.init.callee.object.type==="Identifier"&&e.isContextBound(i.init.callee.object.name)?fe(i.init,e):de(i.init,{parent:i.init},{Identifier(h,f){h.parent=f.parent,pe(h,e);const d=h.parent&&h.parent.type==="BinaryExpression",m=h.parent&&h.parent.type==="UnaryExpression",x=h.parent&&h.parent.type==="ConditionalExpression",b=h.parent&&h.parent.type==="CallExpression"&&h.parent.callee&&h.parent.callee.object&&h.parent.callee.object.name===le&&h.parent.callee.property.name==="get";h.type==="Identifier"&&(d||m||x)&&!b&&Pe(h)},CallExpression(h,f,d){h.callee.type==="Identifier"&&(h.callee.parent=h),h.arguments.forEach(m=>{m.type==="Identifier"&&(m.parent=h)}),(h.callee.type==="ArrowFunctionExpression"||h.callee.type==="FunctionExpression")&&d(h.callee,{parent:h}),fe(h,e),h.type==="CallExpression"&&(h.callee.type==="MemberExpression"&&d(h.callee,{parent:h}),h.arguments.forEach(m=>d(m,{parent:h})))},BinaryExpression(h,f,d){h.left.type==="Identifier"&&(h.left.parent=h),h.right.type==="Identifier"&&(h.right.parent=h),d(h.left,{parent:h}),d(h.right,{parent:h})},LogicalExpression(h,f,d){h.left.type==="Identifier"&&(h.left.parent=h),h.right.type==="Identifier"&&(h.right.parent=h),d(h.left,{parent:h}),d(h.right,{parent:h})},UnaryExpression(h,f,d){h.argument.type==="Identifier"&&(h.argument.parent=h),d(h.argument,{parent:h})},MemberExpression(h,f,d){h.object&&h.object.type==="Identifier"&&(h.object.parent=h),h.property&&h.property.type==="Identifier"&&(h.property.parent=h),xe(h,"",e),h.type==="CallExpression"?h.arguments.forEach(m=>d(m,{parent:h})):h.object&&d(h.object,{parent:h})},AwaitExpression(h,f,d){h.argument&&(h.argument._insideAwait=!0,d(h.argument,{parent:h}),h.argument.type==="Identifier"&&h.argument._wasInsideAwait&&Object.assign(h,h.argument))},ArrowFunctionExpression(h,f,d){if(h.body)if(h.body.type==="BlockStatement"){const m=[];h.body.body.forEach(x=>{e.enterHoistingScope(),d(x,{parent:h.body,insideIIFE:!0});const b=e.exitHoistingScope();m.push(...b),m.push(x)}),h.body.body=m}else d(h.body,{parent:h,insideIIFE:!0})},FunctionExpression(h,f,d){if(h.body&&h.body.type==="BlockStatement"){const m=[];h.body.body.forEach(x=>{e.enterHoistingScope(),d(x,{parent:h.body,insideIIFE:!0});const b=e.exitHoistingScope();m.push(...b),m.push(x)}),h.body.body=m}},SwitchStatement(h,f,d){h.discriminant&&(h.discriminant.parent=h,d(h.discriminant,{parent:h})),h.cases&&h.cases.forEach(m=>{m.parent=h,d(m,{parent:h})})},SwitchCase(h,f,d){if(h.test&&(h.test.parent=h,d(h.test,{parent:h})),h.consequent){const m=[];h.consequent.forEach(x=>{e.enterHoistingScope(),x.parent=h,d(x,{parent:h});const b=e.exitHoistingScope();m.push(...b),m.push(x)}),h.consequent=m}},AssignmentExpression(h,f,d){if(f.insideIIFE){if(h.left.type==="Identifier"){const[m]=e.getVariable(h.left.name);if(m===h.left.name&&!e.isContextBound(h.left.name)){d(h.right,{parent:h});return}}Xi(h,e)}}}));const l=me(i.id.name,e),c=!o&&i.init&&i.init.type==="MemberExpression"&&i.init.computed&&i.init.property&&(i.init.property.type==="Literal"||i.init.property.type==="MemberExpression");if(i.init?.property?.type==="MemberExpression"&&(i.init.property._indexTransformed||(Wt(i.init.property,e),i.init.property._indexTransformed=!0)),s==="var"){const h=e.getCurrentHoistingScope();if(h){for(const f of h)if(f.type==="VariableDeclaration")for(const d of f.declarations){if(!d.init||d.init.type!=="CallExpression")continue;const m=d.init.callee;if(m?.type!=="MemberExpression")continue;let x;const 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){const v=`${x}.${b}`;Ey.includes(v)&&(d.init={type:"ArrowFunctionExpression",params:[],body:d.init,expression:!0,async:!1})}}}}let u;i.init?a||o?u=i.init:s==="var"?u=E.createInitVarCall(l,i.init):u=E.createInitCall(l,c?i.init.object:i.init,c?i.init.property:void 0):u=E.createIdentifier("undefined");const p=E.createExpressionStatement(E.createAssignmentExpression(l,u));if(o){const h=i.init.object.name,f=me(h,e),d=i.init.property.value,m={type:"MemberExpression",object:E.createGetCall(f,0),property:{type:"Literal",value:d},computed:!0};p.expression.right=E.createCallExpression(E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("init")),[l,m])}a&&(e.pushScope("fn"),de(i.init.body,e,{IfStatement(h,f,d){f.pushScope("if"),h.test&&Ta(h.test,f),d(h.consequent,f),h.alternate&&(f.pushScope("els"),d(h.alternate,f),f.popScope()),f.popScope()},VariableDeclaration(h,f){ka(h,f)},Identifier(h,f){pe(h,f)},AssignmentExpression(h,f){Xi(h,f)},SwitchStatement(h,f,d){h.discriminant.parent=h,d(h.discriminant,f),h.cases.forEach(m=>{m.parent=h,d(m,f)})},SwitchCase(h,f,d){h.test&&(h.test.parent=h,d(h.test,f));const m=[];h.consequent.forEach(x=>{f.enterHoistingScope(),d(x,f);const b=f.exitHoistingScope();m.push(...b),m.push(x)}),h.consequent=m},BlockStatement(h,f,d){const m=[];h.body.forEach(x=>{f.enterHoistingScope(),d(x,f);const b=f.exitHoistingScope();m.push(...b),m.push(x)}),h.body=m}}),e.popScope()),Object.assign(t,p)})}function jy(t,e,i){if(e.setSuppressHoisting(!0),t.init&&t.init.type==="VariableDeclaration"){const a=t.init.declarations[0],s=a.id.name;e.addLoopVariable(s,s),t.init={type:"VariableDeclaration",kind:t.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:s},init:a.init}]},a.init&&de(a.init,e,{Identifier(o,l){!e.isLoopVariable(o.name)&&!o.computed&&(e.pushScope("for"),pe(o,l),o.type==="Identifier"&&(e.isContextBound(o.name)&&o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===o||(o.computed=!0,Pe(o))),e.popScope())},MemberExpression(o,l,c){e.pushScope("for"),xe(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(const u of o.arguments)c(u,l)}})}t.test&&de(t.test,e,{Identifier(a,s){!e.isLoopVariable(a.name)&&!a.computed&&(e.pushScope("for"),pe(a,s),a.type==="Identifier"&&(e.isContextBound(a.name)&&a.parent&&a.parent.type==="MemberExpression"&&a.parent.object===a||(a.computed=!0,Pe(a))),e.popScope())},MemberExpression(a,s,o){e.pushScope("for"),xe(a,"",e),e.popScope(),a.type==="MemberExpression"&&a.object&&(a.object.type!=="Identifier"||!e.isContextBound(a.object.name))&&o(a.object,s)},CallExpression(a,s,o){a.callee.parent=a,o(a.callee,s);for(const l of a.arguments)o(l,s)}}),t.update&&de(t.update,e,{Identifier(a,s){!e.isLoopVariable(a.name)&&!a.computed&&(e.pushScope("for"),pe(a,s),a.type==="Identifier"&&(e.isContextBound(a.name)&&a.parent&&a.parent.type==="MemberExpression"&&a.parent.object===a||(a.computed=!0,Pe(a))),e.popScope())},MemberExpression(a,s,o){e.pushScope("for"),xe(a,"",e),e.popScope(),a.type==="MemberExpression"&&a.object&&(a.object.type!=="Identifier"||!e.isContextBound(a.object.name))&&o(a.object,s)},CallExpression(a,s,o){a.callee.parent=a,o(a.callee,s);for(const l of a.arguments)o(l,s)}}),e.setSuppressHoisting(!1);const r=e.getNextLoopGuardName(),n=tn(r);if(e.addHoistedStatement(n.counterDecl),e.pushScope("for"),i(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(n.guardCheck),t.init&&t.init.type==="VariableDeclaration"){const a=t.init.declarations[0];e.removeLoopVariable(a.id.name)}}function Ly(t,e,i){e.setSuppressHoisting(!0),t.test&&de(t.test,e,{Identifier(a,s){a.computed||(pe(a,s),a.type==="Identifier"&&(e.isContextBound(a.name)&&a.parent&&a.parent.type==="MemberExpression"&&a.parent.object===a||(a.computed=!0,Pe(a))))},MemberExpression(a,s,o){xe(a,"",e),a.type==="MemberExpression"&&a.object&&(a.object.type!=="Identifier"||!e.isContextBound(a.object.name))&&o(a.object,s)},CallExpression(a,s,o){if(a.callee.parent=a,o(a.callee,s),fe(a,s),a.arguments)for(const l of a.arguments)o(l,s)}}),e.setSuppressHoisting(!1);const r=e.getNextLoopGuardName(),n=tn(r);e.addHoistedStatement(n.counterDecl),e.pushScope("whl"),i(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(n.guardCheck)}function Ta(t,e){de(t,e,{MemberExpression(i,r,n){i.object&&i.object.type==="Identifier"&&!e.isContextBound(i.object.name)&&!i.computed&&(i.object.parent=i,n(i.object,r)),xe(i,"",e)},CallExpression(i,r){fe(i,r)},BinaryExpression(i,r,n){i.left.type==="Identifier"&&(i.left.parent=i),i.right.type==="Identifier"&&(i.right.parent=i),n(i.left,r),n(i.right,r)},LogicalExpression(i,r,n){i.left.type==="Identifier"&&(i.left.parent=i),i.right.type==="Identifier"&&(i.right.parent=i),n(i.left,r),n(i.right,r)},UnaryExpression(i,r,n){i.argument.type==="Identifier"&&(i.argument.parent=i),n(i.argument,r)},Identifier(i,r){const n=i.parent,a=n&&n.type==="UnaryExpression",s=n&&n.type==="BinaryExpression",o=n&&n.type==="LogicalExpression",l=n&&n.type==="ConditionalExpression";pe(i,r),i.type==="Identifier"&&(a||s||o||l)&&(n&&n.type==="CallExpression"&&n.callee&&n.callee.object&&n.callee.object.name===le&&n.callee.property?.name==="get"||Pe(i));const c=e.getCurrentScopeType()==="if";e.isContextBound(i.name)&&!e.isRootParam(i.name)&&c&&Pe(i)}})}function By(t,e,i){t.test&&(e.pushScope("if"),Ta(t.test,e),e.popScope()),e.pushScope("if"),i(t.consequent,e),e.popScope(),t.alternate&&(e.pushScope("els"),i(t.alternate,e),e.popScope())}function Fy(t,e){const i=e.getCurrentScopeType();if(t.argument){if(t.argument.type==="ArrayExpression")t.argument.elements=t.argument.elements.map(r=>r.type==="Identifier"?e.isContextBound(r.name)&&!e.isRootParam(r.name)?E.createGetCall(r,0):Or(r.name,e):r.type==="MemberExpression"?r.object&&r.object.type==="MemberExpression"&&r.object.object&&r.object.object.type==="Identifier"&&r.object.object.name==="$"&&r.object.property&&["const","let","var","params"].includes(r.object.property.name)?E.createGetCall(r,0):(r.computed&&r.object.type==="Identifier"&&e.isContextBound(r.object.name)&&!e.isRootParam(r.object.name)||xe(r,"",e),r):((r.type==="BinaryExpression"||r.type==="LogicalExpression"||r.type==="ConditionalExpression"||r.type==="CallExpression"||r.type==="UnaryExpression")&&de(r,e,{Identifier(n,a){pe(n,a),n.type==="Identifier"&&!n._arrayAccessed&&(Pe(n),n._arrayAccessed=!0)},MemberExpression(n){xe(n,"",e)},CallExpression(n,a,s){(n.callee.type==="ArrowFunctionExpression"||n.callee.type==="FunctionExpression")&&s(n.callee,a),fe(n,a),n.type==="CallExpression"&&n.arguments.forEach(o=>s(o,a))},BinaryExpression(n,a,s){s(n.left,a),s(n.right,a)}}),r)),t.argument={type:"ArrayExpression",elements:[t.argument]};else if(t.argument.type==="ObjectExpression")t.argument.properties=t.argument.properties.map(r=>r.shorthand?e.isContextBound(r.value.name)?r:(e.getVariable(r.value.name),{type:"Property",key:E.createIdentifier(r.key.name),value:me(r.value.name,e),kind:"init",method:!1,shorthand:!1,computed:!1}):(r.value&&r.value.type==="Identifier"&&(e.isContextBound(r.value.name)&&!e.isRootParam(r.value.name)||e.isContextBound(r.value.name)||(r.value=me(r.value.name,e))),r));else if(t.argument.type==="Identifier")pe(t.argument,e),t.argument.type==="Identifier"&&Pe(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))pe(t.argument.object,e);else if(t.argument.computed&&t.argument.object.type==="MemberExpression"){let r=t.argument.object;for(;r.object&&r.object.type==="MemberExpression";)r=r.object;r.object?.type==="Identifier"&&e.isUdtInstance(r.object.name)&&xe(t.argument,"",e)}}if(i==="fn"){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=E.createArrayAccess(t.argument,0):t.argument.type==="MemberExpression"?t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)&&(t.argument._indexTransformed||(Wt(t.argument,e),t.argument._indexTransformed=!0)):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression"||t.argument.type==="UnaryExpression"||t.argument.type==="AssignmentExpression")&&de(t.argument,e,{Identifier(n,a){pe(n,a),n.type==="Identifier"&&!n._arrayAccessed&&(Pe(n),n._arrayAccessed=!0)},MemberExpression(n){xe(n,"",e)},AssignmentExpression(n,a){Xi(n,a)},CallExpression(n,a,s){(n.callee.type==="ArrowFunctionExpression"||n.callee.type==="FunctionExpression")&&s(n.callee,a),fe(n,a),n.type==="CallExpression"&&n.arguments.forEach(o=>s(o,a))},BinaryExpression(n,a,s){s(n.left,a),s(n.right,a)},ArrowFunctionExpression(n,a,s){if(n.body)if(n.body.type==="BlockStatement"){const o=[];n.body.body.forEach(l=>{e.enterHoistingScope(),s(l,a);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.body.body=o}else s(n.body,a)},FunctionExpression(n,a,s){if(n.body&&n.body.type==="BlockStatement"){const o=[];n.body.body.forEach(l=>{e.enterHoistingScope(),s(l,a);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.body.body=o}},SwitchStatement(n,a,s){n.discriminant.parent=n,s(n.discriminant,a),n.cases.forEach(o=>{o.parent=n,s(o,a)})},SwitchCase(n,a,s){n.test&&(n.test.parent=n,s(n.test,a));const o=[];n.consequent.forEach(l=>{e.enterHoistingScope(),s(l,a);const c=e.exitHoistingScope();o.push(...c),o.push(l)}),n.consequent=o},BlockStatement(n,a,s){const o=[];n.body.forEach(l=>{a.enterHoistingScope(),s(l,a);const c=a.exitHoistingScope();o.push(...c),o.push(l)}),n.body=o}});const r=E.createCallExpression(E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("precision")),[t.argument]);t.argument=r}}}function Wy(t,e,i){const r=E.createVariableDeclaration("$$",E.createCallExpression(E.createMemberExpression(E.createContextIdentifier(),E.createIdentifier("peekCtx")),[]));if(r._skipTransformation=!0,e.addLoopVariable("$$","$$"),t.body&&t.body.type==="BlockStatement"){t.body.body.unshift(r),e.pushScope("fn"),t.params.forEach(l=>{l.type==="Identifier"&&e.addLocalSeriesVar(l.name)});const n=t.id?.name,a=n?.startsWith("$M_")?n.slice(3):n,s=a?e.getFunctionParamUdtTypes(a):void 0,o={};if(s)for(const[l,c]of Object.entries(s))o[l]=e.getVariableUdtType(l),e.markVariableAsUdtInstance(l,c);if(i(t.body,e),t.params.forEach(l=>{l.type==="Identifier"&&e.removeLocalSeriesVar(l.name)}),s)for(const l of Object.keys(s)){e.unmarkVariableAsUdtInstance(l);const c=o[l];c!==void 0&&e.markVariableAsUdtInstance(l,c)}e.popScope()}}function Uy(t){const e={...T,LineComment:()=>{}};function i(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}const r=new Map;Ge(t,{FunctionDeclaration(o){o.id?.name&&r.set(o.id.name,o)}},e);function n(o){let l=!1;const c={...e,FunctionDeclaration:()=>{},FunctionExpression:()=>{},ArrowFunctionExpression:()=>{}};return Ge(o,{AwaitExpression(){l=!0}},c),l}let a=!0,s=0;for(;a&&s<20;){a=!1,s++,Ge(t,{ArrowFunctionExpression(c){!c.async&&n(c.body)&&(c.async=!0,a=!0)},FunctionExpression(c){!c.async&&n(c.body)&&(c.async=!0,a=!0)}},e);const o=[];Ge(t,{CallExpression(c){!c._asyncWrapped&&(c.callee?.type==="ArrowFunctionExpression"||c.callee?.type==="FunctionExpression")&&c.callee.async===!0&&o.push(c)}},e);for(const c of o){const u={};for(const p of Object.keys(c))u[p]=c[p];u._asyncWrapped=!0;for(const p of Object.keys(c))delete c[p];c.type="AwaitExpression",c.argument=u,a=!0}const l=new Set;for(const[c,u]of r)n(u.body)&&(u.async||(u.async=!0,a=!0),l.add(c));if(l.size>0){const c=[];Ge(t,{CallExpression(u){if(!u._asyncWrapped&&u.callee?.type==="MemberExpression"&&u.callee.object?.name==="$"&&u.callee.property?.name==="call"&&u.arguments?.length>0){const p=i(u.arguments[0]);p&&l.has(p)&&c.push(u)}}},e);for(const u of c){const p={};for(const h of Object.keys(u))p[h]=u[h];p._asyncWrapped=!0;for(const h of Object.keys(u))delete u[h];u.type="AwaitExpression",u.argument=p,a=!0}}}}function qy(t){const e={...T,LineComment:()=>{}};Ge(t,{BinaryExpression(i){if(i.operator==="=="||i.operator==="==="){const r=E.createMathEqCall(i.left,i.right);r._transformed=!0,Object.assign(i,r)}else if(i.operator==="!="||i.operator==="!=="){const r=E.createMathNeqCall(i.left,i.right);r._transformed=!0,Object.assign(i,r)}}},e)}function zy(t,e,i,r={debug:!1,ln:!1},n=[]){const a=s=>{if(!r.debug||!s.loc||!n.length)return null;const o=s.loc.start.line-1;if(o>=0&&o<n.length){const l=n[o].trim();if(l)return{type:"LineComment",value:`${r.ln?` [Line ${s.loc.start.line}]`:""} ${l}`}}return null};de(t,e,{Program(s,o,l){const c=[];s.body.forEach(u=>{o.enterHoistingScope(),l(u,o);const p=o.exitHoistingScope(),h=a(u);h&&c.push(h),c.push(...p),c.push(u)}),s.body=c},BlockStatement(s,o,l){const c=[];s.body.forEach(u=>{o.enterHoistingScope(),l(u,o);const p=o.exitHoistingScope(),h=a(u);h&&c.push(h),c.push(...p),c.push(u)}),s.body=c},ReturnStatement(s,o,l){s.argument&&s.argument.type!=="ArrayExpression"&&s.argument.type!=="ObjectExpression"&&s.argument.type!=="Identifier"&&s.argument.type!=="MemberExpression"&&o.getCurrentScopeType()!=="fn"&&l(s.argument,o),Fy(s,o)},VariableDeclaration(s,o){ka(s,o)},Identifier(s,o){pe(s,o)},CallExpression(s,o,l){s.callee&&(s.callee.type==="ArrowFunctionExpression"||s.callee.type==="FunctionExpression")?l(s.callee,o):s.callee&&s.callee.type==="MemberExpression"&&s.callee.object&&(s.callee.object.parent=s.callee,l(s.callee.object,o)),fe(s,o)},ArrowFunctionExpression(s,o,l){s.body&&l(s.body,o)},FunctionExpression(s,o,l){s.body&&l(s.body,o)},ForOfStatement(s,o,l){if(s.left&&s.left.type==="VariableDeclaration"){s.left._skipTransformation=!0;const p=s.left.declarations[0];p.id.type==="Identifier"?o.addLoopVariable(p.id.name,p.id.name):p.id.type==="ArrayPattern"&&p.id.elements.forEach(h=>{h.type==="Identifier"&&o.addLoopVariable(h.name,h.name)})}if(s.right){s.right.type==="Identifier"?(pe(s.right,o),s.right.type==="Identifier"&&Pe(s.right)):l(s.right,o);const p=s.left&&s.left.type==="VariableDeclaration"&&s.left.declarations[0].id.type==="ArrayPattern"?"entries":"iter",h={...s.right},f=E.createCallExpression(E.createMemberExpression(E.createIdentifier("$"),E.createIdentifier(p),!1),[h]);Object.assign(s.right,f)}const c=o.getNextLoopGuardName(),u=tn(c);if(o.addHoistedStatement(u.counterDecl),s.body&&l(s.body,o),s.body&&s.body.type==="BlockStatement"&&s.body.body.unshift(u.guardCheck),s.left&&s.left.type==="VariableDeclaration"){const p=s.left.declarations[0];p.id.type==="Identifier"?o.removeLoopVariable(p.id.name):p.id.type==="ArrayPattern"&&p.id.elements.forEach(h=>{h.type==="Identifier"&&o.removeLoopVariable(h.name)})}},ForInStatement(s,o,l){s.left&&s.left.type==="VariableDeclaration"&&(s.left._skipTransformation=!0),s.right&&s.right.type==="Identifier"?(pe(s.right,o),s.right.type==="Identifier"&&Pe(s.right)):s.right&&l(s.right,o),s.body&&l(s.body,o)},MemberExpression(s,o,l){s.object&&(s.object.type==="CallExpression"||s.object.type==="MemberExpression")&&(s.object.parent=s,l(s.object,o)),s.object&&s.object.type==="Identifier"&&!o.isContextBound(s.object.name)&&(s.object.parent=s,l(s.object,o)),xe(s,i,o)},AssignmentExpression(s,o,l){if(Xi(s,o),s.type==="CallExpression"&&s.arguments){const 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)))};s.arguments.forEach(u=>c(u))}},FunctionDeclaration(s,o,l){Wy(s,o,l)},ForStatement(s,o,l){jy(s,o,l)},WhileStatement(s,o,l){Ly(s,o,l)},IfStatement(s,o,l){By(s,o,l)},SwitchStatement(s,o,l){s.discriminant.parent=s,l(s.discriminant,o),s.cases.forEach(c=>{c.parent=s,l(c,o)})},SwitchCase(s,o,l){s.test&&(s.test.parent=s,l(s.test,o));const c=[];s.consequent.forEach(u=>{o.enterHoistingScope(),l(u,o);const p=o.exitHoistingScope();c.push(...p),c.push(u)}),s.consequent=c},AwaitExpression(s,o,l){s.argument&&(s.argument._insideAwait=!0,l(s.argument,o),s.argument.type==="Identifier"&&s.argument._wasInsideAwait===!0&&(s.type="Identifier",s.name=s.argument.name,s.argument._wasHoisted&&(s._wasHoisted=s.argument._wasHoisted),delete s.argument))}})}const g={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"},Ky=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","import","export","method","extends","enum"]),Hy=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"];class Gy{constructor(e,i,r,n,a=0){this.type=e,this.value=i,this.line=r,this.column=n,this.indent=a}}var Yy=Object.defineProperty,Xy=(t,e,i)=>e in t?Yy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,st=(t,e,i)=>Xy(t,typeof e!="symbol"?e+"":e,i);class Qy{constructor(e){st(this,"source"),st(this,"pos"),st(this,"line"),st(this,"column"),st(this,"tokens"),st(this,"indentStack"),st(this,"atLineStart"),st(this,"parenDepth"),st(this,"bracketDepth"),st(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;){const e=this.peek();if(e==="\r"){this.advance();continue}if(e===`
18
18
  `){this.handleNewline();continue}if(this.atLineStart&&e!==`
19
19
  `){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(g.DEDENT,"",this.getCurrentIndent());return this.addToken(g.EOF,""),this.tokens}handleNewline(){this.parenDepth===0&&this.bracketDepth===0&&this.braceDepth===0&&(this.addToken(g.NEWLINE,`
20
20
  `),this.atLineStart=!0),this.advance(),this.line++,this.column=1}handleIndentation(){let e=0,i=0;for(this.pos;this.pos<this.source.length;){const n=this.peek();if(n===" ")i++,this.advance();else if(n===" ")e++,this.advance();else break}if(this.peek()===`
21
21
  `||this.peek()==="\r"||this.peek()==="\0"||(e+=Math.floor(i/4),this.isContinuationFromPrevToken()))return;const r=this.indentStack[this.indentStack.length-1];if(e>r)this.indentStack.push(e),this.addToken(g.INDENT,"",e);else if(e<r){for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>e;)this.indentStack.pop(),this.addToken(g.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--){const i=this.tokens[e];if(!(i.type===g.NEWLINE||i.type===g.COMMENT))return i.type===g.OPERATOR?i.value!=="=>":i.type===g.COMMA||i.type===g.COLON||i.type===g.KEYWORD&&(i.value==="and"||i.value==="or")}return!1}readComment(){this.column;let e="";for(this.advance(),this.advance();this.pos<this.source.length&&this.peek()!==`
22
22
  `;)e+=this.advance();this.addToken(g.COMMENT,e.trim())}readString(){const e=this.advance(),i=this.column-1;let r="";for(;this.pos<this.source.length&&this.peek()!==e;)if(this.peek()==="\\"){this.advance();const n=this.advance();switch(n){case"n":r+=`
23
- `;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case e:r+=e;break;default:r+=n}}else r+=this.advance();if(this.peek()!==e)throw new Error(`Unterminated string at ${this.line}:${i}`);this.advance(),this.addToken(g.STRING,r)}readColorLiteral(){const e=this.column;let i="#";for(this.advance();this.pos<this.source.length&&i.length<9;){const r=this.peek();if(r>="0"&&r<="9"||r>="A"&&r<="F"||r>="a"&&r<="f")i+=this.advance();else break}if(i.length!==7&&i.length!==9)throw new Error(`Invalid color literal '${i}' at ${this.line}:${e}`);this.addToken(g.STRING,i)}readNumber(){this.column;let e="",i=!1;for(this.peek()==="."&&this.isDigit(this.peek(1))&&(i=!0,e+=this.advance());this.pos<this.source.length;){const r=this.peek();if(this.isDigit(r))e+=this.advance();else if(r==="."&&!i){const n=this.peek(1);if(this.isDigit(n)||!this.isIdentifierStart(n)){if(i=!0,e+=this.advance(),!this.isDigit(this.peek()))break}else break}else break}if(this.pos<this.source.length){const r=this.peek();if(r==="e"||r==="E"){const n=this.peek(1);if(this.isDigit(n))for(e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance();else if(n==="+"||n==="-"){const 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(g.NUMBER,parseFloat(e))}readIdentifier(){this.column;let e="";for(;this.pos<this.source.length&&this.isIdentifierChar(this.peek());)e+=this.advance();jy.has(e)?this.addToken(g.KEYWORD,e):e==="true"||e==="false"?this.addToken(g.BOOLEAN,e==="true"):this.addToken(g.IDENTIFIER,e)}readOperatorOrPunctuation(){const e=this.peek(),i=this.peek(1),r=e+i;if(Ly.includes(r))return this.advance(),this.advance(),this.addToken(g.OPERATOR,r),!0;if("+-*/%<>=!?".includes(e))return this.advance(),this.addToken(g.OPERATOR,e),!0;switch(e){case"(":return this.parenDepth++,this.advance(),this.addToken(g.LPAREN,e),!0;case")":return this.parenDepth--,this.advance(),this.addToken(g.RPAREN,e),!0;case"[":return this.bracketDepth++,this.advance(),this.addToken(g.LBRACKET,e),!0;case"]":return this.bracketDepth--,this.advance(),this.addToken(g.RBRACKET,e),!0;case"{":return this.braceDepth++,this.advance(),this.addToken(g.LBRACE,e),!0;case"}":return this.braceDepth--,this.advance(),this.addToken(g.RBRACE,e),!0;case",":return this.advance(),this.addToken(g.COMMA,e),!0;case".":return this.isDigit(this.peek(1))?(this.readNumber(),!0):(this.advance(),this.addToken(g.DOT,e),!0);case":":return this.advance(),this.addToken(g.COLON,e),!0;case";":return this.advance(),this.addToken(g.SEMICOLON,e),!0}return!1}peek(e=0){const i=this.pos+e;return i<this.source.length?this.source[i]:"\0"}advance(){const 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,i,r=null){const n=new By(e,i,this.line,this.column,r!==null?r:this.getCurrentIndent());this.tokens.push(n)}}var qy=Object.defineProperty,zy=(t,e,i)=>e in t?qy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Le=(t,e,i)=>zy(t,typeof e!="symbol"?e+"":e,i);class J{constructor(e){this.type=e}}class Ky extends J{constructor(e){super("Program"),this.body=e}}class ze extends J{constructor(e){super("ExpressionStatement"),this.expression=e}}var _t=(t=>(t.VAR="var",t.LET="let",t.CONST="const",t))(_t||{});class ft extends J{constructor(e,i="let"){super("VariableDeclaration"),this.declarations=e,this.kind=i}}class st extends J{constructor(e,i,r=null){super("VariableDeclarator"),this.id=e,this.init=i,this.varType=r}}class Mn extends J{constructor(e,i,r,n=null){super("FunctionDeclaration"),this.id=e,this.params=i,this.body=r,this.returnType=n}}class Hy extends J{constructor(e,i){super("TypeDefinition"),this.name=e,this.fields=i}}class Gy extends J{constructor(e,i,r=null){super("IfStatement"),this.test=e,this.consequent=i,this.alternate=r,Le(this,"_line")}}class Rn extends J{constructor(e,i,r,n){super("ForStatement"),this.init=e,this.test=i,this.update=r,this.body=n,Le(this,"isForIn")}}class Yy extends J{constructor(e,i){super("WhileStatement"),this.test=e,this.body=i}}class St extends J{constructor(e){super("BlockStatement"),this.body=e}}class On extends J{constructor(e){super("ReturnStatement"),this.argument=e}}class me extends J{constructor(e){super("Identifier"),this.name=e,Le(this,"varType"),Le(this,"returnType"),Le(this,"isMethod")}}class Pt extends J{constructor(e,i=null){super("Literal"),this.value=e,this.raw=i}}class dt extends J{constructor(e,i,r){super("BinaryExpression"),this.operator=e,this.left=i,this.right=r}}class $n extends J{constructor(e,i,r=!0){super("UnaryExpression"),this.operator=e,this.argument=i,this.prefix=r}}class ai extends J{constructor(e,i,r){super("AssignmentExpression"),this.operator=e,this.left=i,this.right=r}}class Vn extends J{constructor(e,i,r=!1){super("UpdateExpression"),this.operator=e,this.argument=i,this.prefix=r}}class Xy extends J{constructor(e,i){super("CallExpression"),this.callee=e,this.args=i,Le(this,"arguments"),this.callee=e,this.arguments=i}}class jn extends J{constructor(e,i,r=!1){super("MemberExpression"),this.object=e,this.property=i,this.computed=r}}class Et extends J{constructor(e,i,r){super("ConditionalExpression"),this.test=e,this.consequent=i,this.alternate=r,Le(this,"needsIIFE"),Le(this,"consequentStmts"),Le(this,"alternateStmts")}}class Zy extends J{constructor(e){super("ArrayExpression"),this.elements=e}}class Ln extends J{constructor(e){super("ObjectExpression"),this.properties=e}}class Bn extends J{constructor(e,i){super("Property"),this.key=e,this.value=i,Le(this,"kind"),Le(this,"method"),Le(this,"shorthand"),Le(this,"computed"),this.kind="init",this.method=!1,this.shorthand=!1,this.computed=!1}}class Fn extends J{constructor(e){super("ArrayPattern"),this.elements=e}}class Wn extends J{constructor(e,i){super("AssignmentPattern"),this.left=e,this.right=i}}class Qy extends J{constructor(e,i){super("SwitchExpression"),this.discriminant=e,this.cases=i}}class Jy extends J{constructor(e,i,r){super("SwitchCase"),this.test=e,this.consequent=i,this.statements=r,this.statements=r}}var e_=Object.defineProperty,t_=(t,e,i)=>e in t?e_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Zt=(t,e,i)=>t_(t,typeof e!="symbol"?e+"":e,i);const Na=class Dr{constructor(e){Zt(this,"tokens"),Zt(this,"pos"),Zt(this,"functionNames",new Set),Zt(this,"paramScopes",[]),Zt(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(const i of this.paramScopes)if(i.has(e))return!0;return!1}advance(){return this.tokens[this.pos++]}match(e,i=null){const r=this.peek();return!(r.type!==e||i!==null&&r.value!==i)}expect(e,i=null){const r=this.peek();if(r.type!==e)throw new Error(`Expected ${e} but got ${r.type} at ${r.line}:${r.column}`);if(i!==null&&r.value!==i)throw new Error(`Expected '${i}' but got '${r.value}' at ${r.line}:${r.column}`);return this.advance()}expectIdentifierOrContextual(){const e=this.peek();if(e.type===g.IDENTIFIER)return this.advance();if(e.type===g.KEYWORD&&Dr.CONTEXTUAL_KEYWORDS.has(e.value))return this.advance();throw new Error(`Expected ${g.IDENTIFIER} but got ${e.type} at ${e.line}:${e.column}`)}matchEx(e,i=null,r=!1){if(!r)return this.match(e,i);let n=0,s=this.peek(n);if(s.type===g.NEWLINE&&this.noLineContinuation||(s.type===g.NEWLINE&&(n++,s=this.peek(n),s.type===g.INDENT&&(n++,s=this.peek(n))),s.type!==e)||i!==null&&s.value!==i)return!1;for(let a=0;a<n;a++)this.advance();return!0}peekOperatorEx(e){let i=0,r=this.peek(i),n=!1;if(r.type===g.NEWLINE){if(this.noLineContinuation)return null;i++,r=this.peek(i),r.type===g.INDENT&&(n=!0,i++,r=this.peek(i))}if(r.type!==g.OPERATOR||!e.includes(r.value)||n&&(r.value==="+"||r.value==="-"))return null;for(let s=0;s<i;s++)this.advance();return r.value}skipNewlines(e=!1){for(;this.match(g.NEWLINE)||this.match(g.COMMENT);)this.advance();e&&this.match(g.INDENT)&&this.advance()}parse(){const e=[];for(;!this.match(g.EOF);){if(this.skipNewlines(),this.match(g.DEDENT)){this.advance();continue}if(this.match(g.EOF))break;const i=this.parseStatement();i&&e.push(i),this.skipNewlines()}return new Ky(e)}parseStatement(e=!0){this.skipNewlines();const i=this.peek().line;if(this.match(g.COMMENT))return this.advance(),null;let r;if(this.match(g.KEYWORD,"enum"))r=this.parseEnumDefinition();else if(this.match(g.KEYWORD,"type"))r=this.parseTypeDefinition();else if(this.match(g.KEYWORD,"var")||this.match(g.KEYWORD,"varip"))r=this.parseVarDeclaration();else if(this.match(g.KEYWORD,"method"))r=this.parseMethodDeclaration();else if(this.isFunctionDeclaration())r=this.parseFunctionDeclaration();else if(this.match(g.KEYWORD,"if"))r=this.parseIfStatement();else if(this.match(g.KEYWORD,"for"))r=this.parseForStatement();else if(this.match(g.KEYWORD,"while"))r=this.parseWhileStatement();else if(this.match(g.KEYWORD,"break")||this.match(g.KEYWORD,"continue")){const n=this.advance().value;r=new ze(new me(n))}else this.isTupleDestructuring()?r=this.parseTupleDestructuring():this.peek().type===g.IDENTIFIER&&this.isTypedVarDeclaration()&&(r=this.parseTypedVarDeclaration());if(!r){const n=this.parseExpression();if(this.match(g.OPERATOR)){const s=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(s)){this.advance(),this.skipNewlines(!0);const a=this.parseExpression();s==="="&&n.type==="Identifier"?r=new ft([new st(n,a)],_t.LET):r=new ze(new ai(s===":="?"=":s,n,a))}else r=new ze(n)}else r=new ze(n)}if(r&&(r._line=i,e&&this.match(g.COMMA)&&this.peek().line===i)){const n=[r];for(;this.match(g.COMMA)&&this.peek().line===i;){this.advance(),this.skipNewlines(!0);const s=this.parseStatement(!1);s&&n.push(s)}return new St(n)}return r}isFunctionDeclaration(){const e=this.pos;try{let i=0;if(this.peek(i).type===g.IDENTIFIER&&this.peek(i+1).type===g.IDENTIFIER&&i++,this.peek(i).type!==g.IDENTIFIER||(i++,this.peek(i).type!==g.LPAREN))return!1;i++;let r=1;for(;r>0&&this.peek(i).type!==g.EOF;)this.peek(i).type===g.LPAREN&&r++,this.peek(i).type===g.RPAREN&&r--,i++;for(;this.peek(i).type===g.NEWLINE;)i++;return this.peek(i).type===g.OPERATOR&&this.peek(i).value==="=>"}finally{this.pos=e}}parseTypeExpression(){let e=this.expect(g.IDENTIFIER).value;for(;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(g.OPERATOR,"<")){this.advance();const i=[];for(i.push(this.parseTypeExpression());this.match(g.COMMA);)this.advance(),this.skipNewlines(),i.push(this.parseTypeExpression());return this.expect(g.OPERATOR,">"),e+"<"+i.join(", ")+">"}return this.match(g.LBRACKET)&&this.peek(1).type===g.RBRACKET?(this.advance(),this.advance(),"array<"+e+">"):e}parseEnumDefinition(){this.expect(g.KEYWORD,"enum");const e=this.expect(g.IDENTIFIER).value;this.skipNewlines(),this.expect(g.INDENT);const i=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){if(this.match(g.COMMENT)){this.advance();continue}const s=this.expectIdentifierOrContextual().value;let a=null;this.match(g.OPERATOR,"=")&&(this.advance(),a=this.expect(g.STRING).value),i.push({name:s,title:a}),this.skipNewlines()}this.match(g.DEDENT)&&this.advance();const r=i.map(s=>new Bn(new me(s.name),new Pt(s.title!==null?s.title:s.name))),n=new Ln(r);return new ft([new st(new me(e),n)],_t.CONST)}parseTypeDefinition(){this.expect(g.KEYWORD,"type");const e=this.expect(g.IDENTIFIER).value;this.match(g.OPERATOR,"=>")&&this.advance(),this.skipNewlines(),this.expect(g.INDENT);const i=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const r=this.parseTypeExpression(),n=this.expectIdentifierOrContextual().value;let s=null;this.match(g.OPERATOR,"=")&&(this.advance(),this.skipNewlines(),s=this.parseExpression()),i.push({type:r,name:n,defaultValue:s}),this.skipNewlines()}return this.match(g.DEDENT)&&this.advance(),new Hy(e,i)}parseVarDeclaration(){const e=this.advance().value;let i=null,r=null;if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.LBRACKET&&this.peek(2).type===g.RBRACKET)i=this.advance().value,this.advance(),i+="[]",this.advance(),r=this.expectIdentifierOrContextual().value;else if(this.peek().type===g.IDENTIFIER&&(this.peek(1).type===g.DOT||this.peek(1).type===g.IDENTIFIER||this.peek(1).type===g.OPERATOR&&this.peek(1).value==="<")){for(i=this.advance().value;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)this.advance(),i+="."+this.advance().value;if(this.match(g.LBRACKET)&&this.peek(1).type===g.RBRACKET)this.advance(),this.advance(),i+="[]",r=this.expectIdentifierOrContextual().value;else if(this.match(g.OPERATOR,"<")){for(this.advance(),i+="<";!this.match(g.OPERATOR,">");)if(this.match(g.IDENTIFIER))for(i+=this.advance().value;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)i+=".",this.advance(),i+=this.advance().value;else if(this.match(g.COMMA))i+=this.advance().value,this.skipNewlines();else break;this.match(g.OPERATOR,">")&&(i+=">",this.advance()),r=this.expectIdentifierOrContextual().value}else r=this.expectIdentifierOrContextual().value}else if(this.peek().type===g.IDENTIFIER)r=this.advance().value;else throw new Error(`Expected identifier after ${e} at ${this.peek().line}:${this.peek().column}`);this.functionNames.has(r)&&(r=r+"_var"),this.expect(g.OPERATOR,"="),this.skipNewlines(!0);const n=this.parseExpression(),s=new me(r);i&&(s.varType=i);const a=[new st(s,n,i)];for(;this.match(g.COMMA)&&this.peek(1).type===g.KEYWORD&&(this.peek(1).value==="var"||this.peek(1).value==="varip");){this.advance();const o=this.parseVarDeclaration();a.push(...o.declarations)}return new ft(a,e)}isTypedVarDeclaration(){let e=0;if(this.peek(e).type!==g.IDENTIFIER)return!1;for(e++;this.peek(e).type===g.DOT&&this.peek(e+1).type===g.IDENTIFIER;)e+=2;if(this.peek(e).type===g.LBRACKET&&this.peek(e+1).type===g.RBRACKET)return e+=2,this.peek(e).type!==g.IDENTIFIER?!1:(e++,this.peek(e).type===g.OPERATOR&&this.peek(e).value==="=");if(this.peek(e).type===g.OPERATOR&&this.peek(e).value==="<"){e++;let i=1;for(;i>0&&this.peek(e).type!==g.EOF;)this.peek(e).type===g.OPERATOR&&this.peek(e).value==="<"?i++:this.peek(e).type===g.OPERATOR&&this.peek(e).value===">"&&i--,e++;return this.peek(e).type!==g.IDENTIFIER?!1:(e++,this.peek(e).type===g.OPERATOR&&this.peek(e).value==="=")}if(this.peek(e).type!==g.IDENTIFIER)return!1;for(e++;this.peek(e).type===g.IDENTIFIER;)e++;return this.peek(e).type===g.OPERATOR&&this.peek(e).value==="="}parseTypedVarDeclaration(){let e=this.advance().value;for(;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(g.LBRACKET)&&this.peek(1).type===g.RBRACKET)this.advance(),this.advance(),e+="[]";else if(this.match(g.OPERATOR,"<")){for(this.advance(),e+="<";!this.match(g.OPERATOR,">");)if(this.match(g.IDENTIFIER))for(e+=this.advance().value;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)e+=".",this.advance(),e+=this.advance().value;else if(this.match(g.COMMA))e+=this.advance().value,this.skipNewlines();else break;this.match(g.OPERATOR,">")&&(e+=">",this.advance())}else for(;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER;)e+=" "+this.advance().value;let i=this.expectIdentifierOrContextual().value;this.functionNames.has(i)&&(i=i+"_var"),this.expect(g.OPERATOR,"="),this.skipNewlines(!0);const r=this.parseExpression(),n=new me(i);n.varType=e;const s=[new st(n,r,e)];for(;this.match(g.COMMA)&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type===g.OPERATOR&&this.peek(2).value==="=";){this.advance(),this.skipNewlines(!0);let a=this.expectIdentifierOrContextual().value;this.functionNames.has(a)&&(a=a+"_var"),this.expect(g.OPERATOR,"="),this.skipNewlines(!0);const o=this.parseExpression(),l=new me(a);l.varType=e,s.push(new st(l,o,e))}return new ft(s,_t.LET)}parseFunctionDeclaration(){let e=null;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&(e=this.advance().value);const i=this.expect(g.IDENTIFIER).value;this.functionNames.add(i),this.expect(g.LPAREN);const r=[];for(;!this.match(g.RPAREN)&&(this.skipNewlines(),!this.match(g.RPAREN));){let o=null;for(;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type!==g.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.OPERATOR&&this.peek(1).value==="<"){const u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.LBRACKET&&this.peek(2).type===g.RBRACKET){const u=this.parseTypeExpression();o=o?o+" "+u:u}const l=this.expectIdentifierOrContextual().value,c=new me(l);if(o&&(c.varType=o),this.match(g.OPERATOR,"=")){this.advance(),this.skipNewlines();const u=this.parseExpression();r.push(new Wn(c,u))}else r.push(c);this.match(g.COMMA)&&this.advance()}this.expect(g.RPAREN),this.skipNewlines(),this.expect(g.OPERATOR,"=>"),this.skipNewlines();const n=new Set;for(const o of r){const l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&n.add(l.name)}this.paramScopes.push(n);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}const a=new me(i);return e&&(a.returnType=e),new Mn(a,r,s,e)}parseMethodDeclaration(){this.expect(g.KEYWORD,"method");let e=null;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type===g.LPAREN&&(e=this.advance().value);const i=this.expectIdentifierOrContextual().value;this.expect(g.LPAREN);const r=[];for(;!this.match(g.RPAREN)&&(this.skipNewlines(),!this.match(g.RPAREN));){let o=null;for(;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type!==g.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.OPERATOR&&this.peek(1).value==="<"){const u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.LBRACKET&&this.peek(2).type===g.RBRACKET){const u=this.parseTypeExpression();o=o?o+" "+u:u}const l=this.expectIdentifierOrContextual().value,c=new me(l);if(o&&(c.varType=o),this.match(g.OPERATOR,"=")){this.advance(),this.skipNewlines();const u=this.parseExpression();r.push(new Wn(c,u))}else r.push(c);this.match(g.COMMA)&&this.advance()}this.expect(g.RPAREN),this.skipNewlines(),this.expect(g.OPERATOR,"=>"),this.skipNewlines();const n=new Set;for(const o of r){const l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&n.add(l.name)}this.paramScopes.push(n);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}const a=new me(i);return e&&(a.returnType=e),a.isMethod=!0,new Mn(a,r,s,e)}parseFunctionBody(){const e=[];if(!this.match(g.INDENT)){const i=this.parseExpression();return new St([new On(i)])}for(this.advance();!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const i=this.parseStatementOrSequence();Array.isArray(i)?e.push(...i):i&&e.push(i)}return this.match(g.DEDENT)&&this.advance(),e.length>0&&this._addImplicitReturn(e),new St(e)}_addImplicitReturn(e){const i=e[e.length-1];i.type==="ExpressionStatement"?e[e.length-1]=new On(i.expression):i.type==="IfStatement"&&this._addImplicitReturnToIf(i)}_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;const e=this.peek().line;if(this.match(g.KEYWORD,"if")){const r=this.parseIfStatement();return r&&(r._line=e),r}if(this.match(g.KEYWORD,"for"))return this.parseForStatement();if(this.match(g.KEYWORD,"while"))return this.parseWhileStatement();if(this.match(g.KEYWORD,"break")||this.match(g.KEYWORD,"continue")){const r=this.advance().value;return new ze(new me(r))}if(this.match(g.KEYWORD,"var")||this.match(g.KEYWORD,"varip"))return this.parseVarDeclaration();if(this.isTupleDestructuring())return this.parseTupleDestructuring();if(this.peek().type===g.IDENTIFIER&&this.isTypedVarDeclaration()){const r=this.parseTypedVarDeclaration();if(this.match(g.COMMA)&&this.peek(1).type===g.IDENTIFIER){const n=[r];for(;this.match(g.COMMA);)if(this.advance(),this.skipNewlines(!0),this.peek().type===g.IDENTIFIER&&this.isTypedVarDeclaration())n.push(this.parseTypedVarDeclaration());else{const s=this.parseExpression();if(this.match(g.OPERATOR)){const a=this.peek().value;if(["=",":="].includes(a)){this.advance(),this.skipNewlines(!0);const o=this.parseExpression();a==="="&&s.type==="Identifier"?n.push(new ft([new st(s,o)],_t.LET)):n.push(new ze(new ai(a===":="?"=":a,s,o)))}}break}return n}return r}const i=[];for(;;){const r=this.parseExpression();if(this.match(g.OPERATOR)){const n=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(n)){this.advance(),this.skipNewlines(!0);const s=this.parseExpression();if(n==="="&&r.type==="Identifier"?i.push(new ft([new st(r,s)],_t.LET)):i.push(new ze(new ai(n===":="?"=":n,r,s))),this.match(g.COMMA)){this.advance(),this.skipNewlines();continue}break}else{if(i.length>0)i.push(new ze(r));else return new ze(r);break}}else if(this.match(g.COMMA)){i.push(new ze(r)),this.advance(),this.skipNewlines();continue}else{if(i.length>0)i.push(new ze(r));else return new ze(r);break}}return i.length>1?i:i.length===1?i[0]:null}parseIfStatement(){this.expect(g.KEYWORD,"if");const e=this.parseExpression();this.skipNewlines();const i=this.parseBlock();let r=null;return this.skipNewlines(),this.match(g.KEYWORD,"else")&&(this.advance(),this.skipNewlines(),this.match(g.KEYWORD,"if")?r=this.parseIfStatement():r=this.parseBlock()),new Gy(e,i,r)}parseForStatement(){this.expect(g.KEYWORD,"for");let e=null,i=!1;if(this.match(g.LBRACKET)){this.advance();const r=[];for(;!this.match(g.RBRACKET);)this.skipNewlines(),r.push(new me(this.expectIdentifierOrContextual().value)),this.match(g.COMMA)&&this.advance();this.expect(g.RBRACKET),e=new Fn(r),i=!0}else{const r=this.expectIdentifierOrContextual().value;e=new me(r)}if(this.match(g.KEYWORD,"in")){this.advance();const r=this.parseExpression();this.skipNewlines();const n=this.parseBlock(),s=new ft([new st(e,r)],_t.CONST),a=new Rn(s,null,null,n);return a.isForIn=!0,a}else{if(i)throw new Error(`Range-based for loops don't support destructuring at ${this.peek().line}:${this.peek().column}`);this.expect(g.OPERATOR,"=");const r=this.parseExpression();this.expect(g.KEYWORD,"to");const n=this.parseExpression();let s=null;this.match(g.KEYWORD,"by")&&(this.advance(),s=this.parseExpression()),this.skipNewlines();const a=this.parseBlock(),o=new ft([new st(e,r)],_t.LET),l=new dt("<=",r,n),c=new Et(l,new dt("<=",e,n),new dt(">=",e,n));let u;return s?u=new Et(l,new ai("+=",e,s),new ai("-=",e,s)):u=new Et(l,new Vn("++",e),new Vn("--",e)),new Rn(o,c,u,a)}}parseWhileStatement(){this.expect(g.KEYWORD,"while");const e=this.parseExpression();this.skipNewlines();const i=this.parseBlock();return new Yy(e,i)}parseBlock(){if(!this.match(g.INDENT)){const r=this.parseStatement();return new St(r?[r]:[])}const e=this.peek().indent;this.advance();const i=[];for(;!this.match(g.EOF);){if(this.skipNewlines(),this.match(g.DEDENT)){if(this.peek().indent<e)break;this.advance();continue}if(this.match(g.EOF))break;const r=this.parseStatement();r&&i.push(r)}return this.match(g.DEDENT)&&this.peek().indent<e&&this.advance(),new St(i)}isTupleDestructuring(){if(!this.match(g.LBRACKET))return!1;let e=1;for(;;){for(;this.peek(e).type===g.NEWLINE;)e++;if(this.peek(e).type!==g.IDENTIFIER)return!1;for(e++;this.peek(e).type===g.NEWLINE;)e++;if(this.peek(e).type===g.RBRACKET){e++;break}else if(this.peek(e).type===g.COMMA){e++;continue}else return!1}for(;this.peek(e).type===g.NEWLINE;)e++;return this.peek(e).type===g.OPERATOR&&this.peek(e).value==="="}parseTupleDestructuring(){this.expect(g.LBRACKET);const e=[];for(;!this.match(g.RBRACKET);){this.skipNewlines();let r=this.expectIdentifierOrContextual().value;this.functionNames.has(r)&&(r=r+"_var"),e.push(new me(r)),this.match(g.COMMA)&&this.advance()}this.expect(g.RBRACKET),this.skipNewlines(),this.expect(g.OPERATOR,"="),this.skipNewlines(!0);const i=this.parseExpression();return new ft([new st(new Fn(e),i)],_t.CONST)}parseExpression(){return this.parseTernary()}parseTernary(){let e=this.parseLogicalOr();if(this.matchEx(g.OPERATOR,"?",!0)){this.advance(),this.skipNewlines(!0);const i=this.parseExpression();this.matchEx(g.COLON,null,!0)?this.advance():this.expect(g.COLON),this.skipNewlines(!0);const r=this.parseExpression();return new Et(e,i,r)}return e}parseLogicalOr(){let e=this.parseLogicalAnd();for(;this.matchEx(g.KEYWORD,"or",!0)||this.peekOperatorEx(["||"]);){this.advance(),this.skipNewlines(!0);const i=this.parseLogicalAnd();e=new dt("||",e,i)}return e}parseLogicalAnd(){let e=this.parseEquality();for(;this.matchEx(g.KEYWORD,"and",!0)||this.peekOperatorEx(["&&"]);){this.advance(),this.skipNewlines(!0);const i=this.parseEquality();e=new dt("&&",e,i)}return e}parseEquality(){let e=this.parseComparison();for(;this.peekOperatorEx(["==","!="]);){const i=this.advance().value;this.skipNewlines(!0);const r=this.parseComparison();e=new dt(i,e,r)}return e}parseComparison(){let e=this.parseAdditive();for(;this.peekOperatorEx(["<",">","<=",">="]);){const i=this.advance().value;this.skipNewlines(!0);const r=this.parseAdditive();e=new dt(i,e,r)}return e}parseAdditive(){let e=this.parseMultiplicative();for(;this.peekOperatorEx(["+","-"]);){const i=this.advance().value;this.skipNewlines(!0);const r=this.parseMultiplicative();e=new dt(i,e,r)}return e}parseMultiplicative(){let e=this.parseUnary();for(;this.peekOperatorEx(["*","/","%"]);){const i=this.advance().value;this.skipNewlines(!0);const r=this.parseUnary();e=new dt(i,e,r)}return e}parseUnary(){if(this.match(g.OPERATOR)){const e=this.peek().value;if(["+","-","!"].includes(e))return this.advance(),this.skipNewlines(),new $n(e,this.parseUnary())}return this.match(g.KEYWORD,"not")?(this.advance(),this.skipNewlines(),new $n("!",this.parseUnary())):this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match(g.OPERATOR,"<")){const i=this.pos;this.advance();let r=1,n=!0,s="";const a=new Set(["float","int","string","bool","color","line","label","box","linefill","table"]);for(;r>0&&!this.match(g.EOF);)if(this.match(g.OPERATOR,"<"))r++,this.advance();else if(this.match(g.OPERATOR,">"))r--,this.advance();else if(this.match(g.IDENTIFIER)||this.match(g.COMMA)||this.match(g.DOT))r===1&&this.match(g.IDENTIFIER)&&s===""&&(s=this.peek().value),this.advance();else{n=!1,this.pos=i;break}if(n&&e.type==="MemberExpression"&&e.property.name==="new"&&(e.object.name==="array"||e.object.name==="matrix")&&a.has(s)&&(e.property=new me("new_"+s)),n&&this.match(g.LPAREN)){e=this.parseCallExpression(e);continue}else{if(n)continue;break}}else if(this.match(g.LPAREN))e=this.parseCallExpression(e);else if(this.match(g.DOT)){this.advance(),this.skipNewlines();const i=this.peek();if(i.type!==g.IDENTIFIER&&i.type!==g.KEYWORD)throw new Error(`Expected property name but got ${i.type} at ${i.line}:${i.column}`);this.advance(),e=new jn(e,new me(i.value),!1)}else if(this.match(g.LBRACKET)){if(this.isTupleDestructuring())break;this.advance(),this.skipNewlines();const i=this.parseExpression();this.expect(g.RBRACKET),e=new jn(e,i,!0)}else break;return e}parseCallExpression(e){this.expect(g.LPAREN);const i=[],r=[];for(;!this.match(g.RPAREN)&&(this.skipNewlines(),!this.match(g.RPAREN));){if((this.peek().type===g.IDENTIFIER||this.peek().type===g.KEYWORD)&&this.peek(1).type===g.OPERATOR&&this.peek(1).value==="="){const n=this.advance().value;this.advance(),this.skipNewlines();const s=this.parseExpression();r.push(new Bn(new me(n),s))}else i.push(this.parseExpression());this.match(g.COMMA)&&this.advance(),this.skipNewlines()}return this.expect(g.RPAREN),r.length>0&&i.push(new Ln(r)),new Xy(e,i)}parsePrimary(){const e=this.peek();if(this.match(g.NUMBER)){const i=this.advance();return new Pt(i.value)}if(this.match(g.STRING)){const i=this.advance();return new Pt(i.value)}if(this.match(g.BOOLEAN)){const i=this.advance();return new Pt(i.value)}if(this.match(g.IDENTIFIER)||e.type===g.KEYWORD&&Dr.CONTEXTUAL_KEYWORDS.has(e.value)){let i=this.advance().value;return this.functionNames.has(i)&&this.peek().type!==g.LPAREN&&!this.isCurrentFunctionParam(i)&&(i=i+"_var"),new me(i)}if(this.match(g.LBRACKET))return this.parseArrayLiteral();if(this.match(g.LPAREN)){this.advance(),this.skipNewlines();const i=this.parseExpression();return this.skipNewlines(),this.expect(g.RPAREN),i}if(this.match(g.KEYWORD,"if"))return this.parseIfExpression();if(this.match(g.KEYWORD,"switch"))return this.parseSwitchExpression();if(this.match(g.KEYWORD,"for"))return this.parseForExpression();if(this.match(g.KEYWORD,"while"))return this.parseWhileExpression();throw new Error(`Unexpected token ${e.type} '${e.value}' at ${e.line}:${e.column}`)}parseArrayLiteral(){this.expect(g.LBRACKET);const e=[];for(;!this.match(g.RBRACKET)&&(this.skipNewlines(),!this.match(g.RBRACKET));)e.push(this.parseExpression()),this.match(g.COMMA)&&this.advance(),this.skipNewlines();return this.expect(g.RBRACKET),new Zy(e)}parseIfExpression(){this.expect(g.KEYWORD,"if");const e=this.parseExpression();this.skipNewlines(),this.expect(g.INDENT);const i=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const a=this.parseStatement();a&&i.push(a)}this.advance();let r=[];if(this.match(g.KEYWORD,"else"))if(this.advance(),this.skipNewlines(),this.match(g.KEYWORD,"if")){const a=this.parseIfExpression();if(this.needsIIFE(i,r)){const o=new Et(e,new St(i),a);return o.needsIIFE=!0,o.consequentStmts=i,o.alternateExpr=a,o}else return new Et(e,this.getBlockValue(i),a)}else{for(this.expect(g.INDENT);!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const a=this.parseStatement();a&&r.push(a)}this.advance()}if(this.needsIIFE(i,r)){const a=new Et(e,new St(i),new St(r));return a.needsIIFE=!0,a.consequentStmts=i,a.alternateStmts=r,a}const n=this.getBlockValue(i),s=r.length>0?this.getBlockValue(r):new Pt(null);return new Et(e,n,s)}needsIIFE(e,i){if(e.length>1||i.length>1)return!0;const r=n=>n.some(s=>s.type==="IfStatement"||s.type==="ForStatement"||s.type==="WhileStatement"||s.type==="BlockStatement");return r(e)||r(i)}parseSwitchExpression(){this.expect(g.KEYWORD,"switch");let e=null;!this.match(g.NEWLINE)&&!this.match(g.INDENT)&&(e=this.parseExpression()),this.skipNewlines(),this.expect(g.INDENT);const i=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){let r=null;this.match(g.OPERATOR,"=>")||(r=this.parseExpression()),this.expect(g.OPERATOR,"=>"),this.skipNewlines();const n=[];if(this.match(g.INDENT)){for(this.advance();!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const a=this.parseStatement();a&&n.push(a)}this.advance()}else{this.noLineContinuation=!0;const a=this.parseStatement();this.noLineContinuation=!1,a&&n.push(a)}const s=this.getBlockValue(n);i.push(new Jy(r,s,n)),this.skipNewlines()}return this.advance(),new Qy(e,i)}parseForExpression(){const e=this.parseForStatement();return e.isExpression=!0,e}parseWhileExpression(){const e=this.parseWhileStatement();return e.isExpression=!0,e}getBlockValue(e){if(e.length===0)return new Pt(null);const i=e[e.length-1];return i.type==="ExpressionStatement"?i.expression:i.type==="VariableDeclaration"&&i.declarations.length>0?i.declarations[0].id:new Pt(null)}};Zt(Na,"CONTEXTUAL_KEYWORDS",new Set(["type","method","enum"]));let i_=Na;var r_=Object.defineProperty,n_=(t,e,i)=>e in t?r_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,mt=(t,e,i)=>n_(t,typeof e!="symbol"?e+"":e,i);const s_=new Set(Xr);class a_{constructor(e={}){mt(this,"indent"),mt(this,"indentStr"),mt(this,"output"),mt(this,"sourceCode"),mt(this,"sourceLines"),mt(this,"lastCommentedLine"),mt(this,"includeSourceComments"),mt(this,"paramRenameCounter"),mt(this,"functionParams"),this.indent=0,this.indentStr=e.indentStr||" ",this.output=[],this.sourceCode=e.sourceCode||null,this.sourceLines=this.sourceCode?this.sourceCode.split(`
24
- `):[],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){const i=new Map;this.collectConflictingVarNames(e,i),i.size>0&&this.renameVariableRefsInAST(e,i)}isReservedName(e){return!!e&&(_y.has(e)||Dn.has(e))}collectConflictingVarNames(e,i){if(!(!e||typeof e!="object")){if(e.type==="VariableDeclaration"){for(const r of e.declarations)if(r.id?.type==="Identifier"&&this.isReservedName(r.id.name)&&!i.has(r.id.name)&&i.set(r.id.name,`${r.id.name}_$${this.paramRenameCounter++}`),r.id?.type==="ArrayPattern")for(const n of r.id.elements)n?.type==="Identifier"&&this.isReservedName(n.name)&&!i.has(n.name)&&i.set(n.name,`${n.name}_$${this.paramRenameCounter++}`)}(e.type==="AssignmentExpression"||e.type==="ReassignmentExpression")&&e.left?.type==="Identifier"&&this.isReservedName(e.left.name)&&!i.has(e.left.name)&&i.set(e.left.name,`${e.left.name}_$${this.paramRenameCounter++}`),e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"&&!e.id.isMethod&&this.isReservedName(e.id.name)&&!i.has(e.id.name)&&i.set(e.id.name,`${e.id.name}_$${this.paramRenameCounter++}`);for(const r of Object.keys(e)){if(r==="type")continue;const n=e[r];if(Array.isArray(n))for(const s of n)s&&typeof s=="object"&&this.collectConflictingVarNames(s,i);else n&&typeof n=="object"&&n.type&&this.collectConflictingVarNames(n,i)}}}renameVariableRefsInAST(e,i){if(!(!e||typeof e!="object")){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&i.has(e.callee.name)?Dn.has(e.callee.name)&&(e.callee.name=i.get(e.callee.name)):this.renameVariableRefsInAST(e.callee,i),e.arguments)for(const r of e.arguments)this.renameVariableRefsInAST(r,i);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&i.has(e.object.name))return;if(!e.computed&&e.property?.type==="Identifier"&&i.has(e.property.name)){this.renameVariableRefsInAST(e.object,i);return}this.renameVariableRefsInAST(e.object,i),e.computed&&this.renameVariableRefsInAST(e.property,i);return}if(e.type==="Property"){this.renameVariableRefsInAST(e.value,i);return}if(e.type==="Identifier"&&i.has(e.name)){e.name=i.get(e.name);return}for(const r of Object.keys(e)){if(r==="type")continue;const n=e[r];if(Array.isArray(n))for(const s of n)s&&typeof s=="object"&&this.renameVariableRefsInAST(s,i);else n&&typeof n=="object"&&n.type&&this.renameVariableRefsInAST(n,i)}}}collectFunctionParams(e){if(!(!e||typeof e!="object")){if(e.type==="FunctionDeclaration"&&e.id?.name){const i=[];for(const r of e.params)r.type==="Identifier"?i.push(r.name):r.type==="AssignmentPattern"&&r.left?.name&&i.push(r.left.name);this.functionParams.set(e.id.name,i)}if(Array.isArray(e.body))for(const i of e.body)this.collectFunctionParams(i);else e.body&&typeof e.body=="object"&&this.collectFunctionParams(e.body)}}writeSourceComment(e,i=null){if(!this.sourceLines.length)return;const r=i||e,n=[];for(let s=e-1;s<r&&s<this.sourceLines.length;s++)if(s>this.lastCommentedLine){const a=this.sourceLines[s].trim();a&&!a.startsWith("//@")&&!a.startsWith("//")&&n.push(this.sourceLines[s])}if(n.length>0){for(const s of n)this.write(this.indentStr.repeat(this.indent)),this.write("/// "),this.write(s.trimEnd()),this.write(`
23
+ `;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case e:r+=e;break;default:r+=n}}else r+=this.advance();if(this.peek()!==e)throw new Error(`Unterminated string at ${this.line}:${i}`);this.advance(),this.addToken(g.STRING,r)}readColorLiteral(){const e=this.column;let i="#";for(this.advance();this.pos<this.source.length&&i.length<9;){const r=this.peek();if(r>="0"&&r<="9"||r>="A"&&r<="F"||r>="a"&&r<="f")i+=this.advance();else break}if(i.length!==7&&i.length!==9)throw new Error(`Invalid color literal '${i}' at ${this.line}:${e}`);this.addToken(g.STRING,i)}readNumber(){this.column;let e="",i=!1;for(this.peek()==="."&&this.isDigit(this.peek(1))&&(i=!0,e+=this.advance());this.pos<this.source.length;){const r=this.peek();if(this.isDigit(r))e+=this.advance();else if(r==="."&&!i){const n=this.peek(1);if(this.isDigit(n)||!this.isIdentifierStart(n)){if(i=!0,e+=this.advance(),!this.isDigit(this.peek()))break}else break}else break}if(this.pos<this.source.length){const r=this.peek();if(r==="e"||r==="E"){const n=this.peek(1);if(this.isDigit(n))for(e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance();else if(n==="+"||n==="-"){const a=this.peek(2);if(this.isDigit(a))for(e+=this.advance(),e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance()}}}this.addToken(g.NUMBER,parseFloat(e))}readIdentifier(){this.column;let e="";for(;this.pos<this.source.length&&this.isIdentifierChar(this.peek());)e+=this.advance();Ky.has(e)?this.addToken(g.KEYWORD,e):e==="true"||e==="false"?this.addToken(g.BOOLEAN,e==="true"):this.addToken(g.IDENTIFIER,e)}readOperatorOrPunctuation(){const e=this.peek(),i=this.peek(1),r=e+i;if(Hy.includes(r))return this.advance(),this.advance(),this.addToken(g.OPERATOR,r),!0;if("+-*/%<>=!?".includes(e))return this.advance(),this.addToken(g.OPERATOR,e),!0;switch(e){case"(":return this.parenDepth++,this.advance(),this.addToken(g.LPAREN,e),!0;case")":return this.parenDepth--,this.advance(),this.addToken(g.RPAREN,e),!0;case"[":return this.bracketDepth++,this.advance(),this.addToken(g.LBRACKET,e),!0;case"]":return this.bracketDepth--,this.advance(),this.addToken(g.RBRACKET,e),!0;case"{":return this.braceDepth++,this.advance(),this.addToken(g.LBRACE,e),!0;case"}":return this.braceDepth--,this.advance(),this.addToken(g.RBRACE,e),!0;case",":return this.advance(),this.addToken(g.COMMA,e),!0;case".":return this.isDigit(this.peek(1))?(this.readNumber(),!0):(this.advance(),this.addToken(g.DOT,e),!0);case":":return this.advance(),this.addToken(g.COLON,e),!0;case";":return this.advance(),this.addToken(g.SEMICOLON,e),!0}return!1}peek(e=0){const i=this.pos+e;return i<this.source.length?this.source[i]:"\0"}advance(){const 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,i,r=null){const n=new Gy(e,i,this.line,this.column,r!==null?r:this.getCurrentIndent());this.tokens.push(n)}}var Zy=Object.defineProperty,Jy=(t,e,i)=>e in t?Zy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Fe=(t,e,i)=>Jy(t,typeof e!="symbol"?e+"":e,i);class te{constructor(e){this.type=e}}class e_ extends te{constructor(e){super("Program"),this.body=e}}class Ke extends te{constructor(e){super("ExpressionStatement"),this.expression=e}}var _t=(t=>(t.VAR="var",t.LET="let",t.CONST="const",t))(_t||{});class ft extends te{constructor(e,i="let"){super("VariableDeclaration"),this.declarations=e,this.kind=i}}class at extends te{constructor(e,i,r=null){super("VariableDeclarator"),this.id=e,this.init=i,this.varType=r}}class $n extends te{constructor(e,i,r,n=null){super("FunctionDeclaration"),this.id=e,this.params=i,this.body=r,this.returnType=n}}class t_ extends te{constructor(e,i){super("TypeDefinition"),this.name=e,this.fields=i}}class i_ extends te{constructor(e,i,r=null){super("IfStatement"),this.test=e,this.consequent=i,this.alternate=r,Fe(this,"_line")}}class Vn extends te{constructor(e,i,r,n){super("ForStatement"),this.init=e,this.test=i,this.update=r,this.body=n,Fe(this,"isForIn")}}class r_ extends te{constructor(e,i){super("WhileStatement"),this.test=e,this.body=i}}class Et extends te{constructor(e){super("BlockStatement"),this.body=e}}class jn extends te{constructor(e){super("ReturnStatement"),this.argument=e}}class ge extends te{constructor(e){super("Identifier"),this.name=e,Fe(this,"varType"),Fe(this,"returnType"),Fe(this,"isMethod")}}class Pt extends te{constructor(e,i=null){super("Literal"),this.value=e,this.raw=i}}class dt extends te{constructor(e,i,r){super("BinaryExpression"),this.operator=e,this.left=i,this.right=r}}class Ln extends te{constructor(e,i,r=!0){super("UnaryExpression"),this.operator=e,this.argument=i,this.prefix=r}}class oi extends te{constructor(e,i,r){super("AssignmentExpression"),this.operator=e,this.left=i,this.right=r}}class Bn extends te{constructor(e,i,r=!1){super("UpdateExpression"),this.operator=e,this.argument=i,this.prefix=r}}class n_ extends te{constructor(e,i){super("CallExpression"),this.callee=e,this.args=i,Fe(this,"arguments"),this.callee=e,this.arguments=i}}class Fn extends te{constructor(e,i,r=!1){super("MemberExpression"),this.object=e,this.property=i,this.computed=r}}class Nt extends te{constructor(e,i,r){super("ConditionalExpression"),this.test=e,this.consequent=i,this.alternate=r,Fe(this,"needsIIFE"),Fe(this,"consequentStmts"),Fe(this,"alternateStmts")}}class s_ extends te{constructor(e){super("ArrayExpression"),this.elements=e}}class Wn extends te{constructor(e){super("ObjectExpression"),this.properties=e}}class Un extends te{constructor(e,i){super("Property"),this.key=e,this.value=i,Fe(this,"kind"),Fe(this,"method"),Fe(this,"shorthand"),Fe(this,"computed"),this.kind="init",this.method=!1,this.shorthand=!1,this.computed=!1}}class qn extends te{constructor(e){super("ArrayPattern"),this.elements=e}}class zn extends te{constructor(e,i){super("AssignmentPattern"),this.left=e,this.right=i}}class a_ extends te{constructor(e,i){super("SwitchExpression"),this.discriminant=e,this.cases=i}}class o_ extends te{constructor(e,i,r){super("SwitchCase"),this.test=e,this.consequent=i,this.statements=r,this.statements=r}}var l_=Object.defineProperty,c_=(t,e,i)=>e in t?l_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Jt=(t,e,i)=>c_(t,typeof e!="symbol"?e+"":e,i);const Aa=class Vr{constructor(e){Jt(this,"tokens"),Jt(this,"pos"),Jt(this,"functionNames",new Set),Jt(this,"paramScopes",[]),Jt(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(const i of this.paramScopes)if(i.has(e))return!0;return!1}advance(){return this.tokens[this.pos++]}match(e,i=null){const r=this.peek();return!(r.type!==e||i!==null&&r.value!==i)}expect(e,i=null){const r=this.peek();if(r.type!==e)throw new Error(`Expected ${e} but got ${r.type} at ${r.line}:${r.column}`);if(i!==null&&r.value!==i)throw new Error(`Expected '${i}' but got '${r.value}' at ${r.line}:${r.column}`);return this.advance()}expectIdentifierOrContextual(){const e=this.peek();if(e.type===g.IDENTIFIER)return this.advance();if(e.type===g.KEYWORD&&Vr.CONTEXTUAL_KEYWORDS.has(e.value))return this.advance();throw new Error(`Expected ${g.IDENTIFIER} but got ${e.type} at ${e.line}:${e.column}`)}matchEx(e,i=null,r=!1){if(!r)return this.match(e,i);let n=0,a=this.peek(n);if(a.type===g.NEWLINE&&this.noLineContinuation||(a.type===g.NEWLINE&&(n++,a=this.peek(n),a.type===g.INDENT&&(n++,a=this.peek(n))),a.type!==e)||i!==null&&a.value!==i)return!1;for(let s=0;s<n;s++)this.advance();return!0}peekOperatorEx(e){let i=0,r=this.peek(i),n=!1;if(r.type===g.NEWLINE){if(this.noLineContinuation)return null;i++,r=this.peek(i),r.type===g.INDENT&&(n=!0,i++,r=this.peek(i))}if(r.type!==g.OPERATOR||!e.includes(r.value)||n&&(r.value==="+"||r.value==="-"))return null;for(let a=0;a<i;a++)this.advance();return r.value}skipNewlines(e=!1){for(;this.match(g.NEWLINE)||this.match(g.COMMENT);)this.advance();e&&this.match(g.INDENT)&&this.advance()}parse(){const e=[];for(;!this.match(g.EOF);){if(this.skipNewlines(),this.match(g.DEDENT)){this.advance();continue}if(this.match(g.EOF))break;const i=this.parseStatement();i&&e.push(i),this.skipNewlines()}return new e_(e)}parseStatement(e=!0){this.skipNewlines();const i=this.peek().line;if(this.match(g.COMMENT))return this.advance(),null;let r;if(this.match(g.KEYWORD,"enum"))r=this.parseEnumDefinition();else if(this.match(g.KEYWORD,"type"))r=this.parseTypeDefinition();else if(this.match(g.KEYWORD,"var")||this.match(g.KEYWORD,"varip"))r=this.parseVarDeclaration();else if(this.match(g.KEYWORD,"method"))r=this.parseMethodDeclaration();else if(this.isFunctionDeclaration())r=this.parseFunctionDeclaration();else if(this.match(g.KEYWORD,"if"))r=this.parseIfStatement();else if(this.match(g.KEYWORD,"for"))r=this.parseForStatement();else if(this.match(g.KEYWORD,"while"))r=this.parseWhileStatement();else if(this.match(g.KEYWORD,"break")||this.match(g.KEYWORD,"continue")){const n=this.advance().value;r=new Ke(new ge(n))}else this.isTupleDestructuring()?r=this.parseTupleDestructuring():this.peek().type===g.IDENTIFIER&&this.isTypedVarDeclaration()&&(r=this.parseTypedVarDeclaration());if(!r){const n=this.parseExpression();if(this.match(g.OPERATOR)){const a=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(a)){this.advance(),this.skipNewlines(!0);const s=this.parseExpression();a==="="&&n.type==="Identifier"?r=new ft([new at(n,s)],_t.LET):r=new Ke(new oi(a===":="?"=":a,n,s))}else r=new Ke(n)}else r=new Ke(n)}if(r&&(r._line=i,e&&this.match(g.COMMA)&&this.peek().line===i)){const n=[r];for(;this.match(g.COMMA)&&this.peek().line===i;){this.advance(),this.skipNewlines(!0);const a=this.parseStatement(!1);a&&n.push(a)}return new Et(n)}return r}isFunctionDeclaration(){const e=this.pos;try{let i=0;if(this.peek(i).type===g.IDENTIFIER&&this.peek(i+1).type===g.IDENTIFIER&&i++,this.peek(i).type!==g.IDENTIFIER||(i++,this.peek(i).type!==g.LPAREN))return!1;i++;let r=1;for(;r>0&&this.peek(i).type!==g.EOF;)this.peek(i).type===g.LPAREN&&r++,this.peek(i).type===g.RPAREN&&r--,i++;for(;this.peek(i).type===g.NEWLINE;)i++;return this.peek(i).type===g.OPERATOR&&this.peek(i).value==="=>"}finally{this.pos=e}}parseTypeExpression(){let e=this.expect(g.IDENTIFIER).value;for(;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(g.OPERATOR,"<")){this.advance();const i=[];for(i.push(this.parseTypeExpression());this.match(g.COMMA);)this.advance(),this.skipNewlines(),i.push(this.parseTypeExpression());return this.expect(g.OPERATOR,">"),e+"<"+i.join(", ")+">"}return this.match(g.LBRACKET)&&this.peek(1).type===g.RBRACKET?(this.advance(),this.advance(),"array<"+e+">"):e}parseEnumDefinition(){this.expect(g.KEYWORD,"enum");const e=this.expect(g.IDENTIFIER).value;this.skipNewlines(),this.expect(g.INDENT);const i=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){if(this.match(g.COMMENT)){this.advance();continue}const a=this.expectIdentifierOrContextual().value;let s=null;this.match(g.OPERATOR,"=")&&(this.advance(),s=this.expect(g.STRING).value),i.push({name:a,title:s}),this.skipNewlines()}this.match(g.DEDENT)&&this.advance();const r=i.map(a=>new Un(new ge(a.name),new Pt(a.title!==null?a.title:a.name))),n=new Wn(r);return new ft([new at(new ge(e),n)],_t.CONST)}parseTypeDefinition(){this.expect(g.KEYWORD,"type");const e=this.expect(g.IDENTIFIER).value;this.match(g.OPERATOR,"=>")&&this.advance(),this.skipNewlines(),this.expect(g.INDENT);const i=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const r=this.parseTypeExpression(),n=this.expectIdentifierOrContextual().value;let a=null;this.match(g.OPERATOR,"=")&&(this.advance(),this.skipNewlines(),a=this.parseExpression()),i.push({type:r,name:n,defaultValue:a}),this.skipNewlines()}return this.match(g.DEDENT)&&this.advance(),new t_(e,i)}parseVarDeclaration(){const e=this.advance().value;let i=null,r=null;if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.LBRACKET&&this.peek(2).type===g.RBRACKET)i=this.advance().value,this.advance(),i+="[]",this.advance(),r=this.expectIdentifierOrContextual().value;else if(this.peek().type===g.IDENTIFIER&&(this.peek(1).type===g.DOT||this.peek(1).type===g.IDENTIFIER||this.peek(1).type===g.OPERATOR&&this.peek(1).value==="<")){for(i=this.advance().value;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)this.advance(),i+="."+this.advance().value;if(this.match(g.LBRACKET)&&this.peek(1).type===g.RBRACKET)this.advance(),this.advance(),i+="[]",r=this.expectIdentifierOrContextual().value;else if(this.match(g.OPERATOR,"<")){for(this.advance(),i+="<";!this.match(g.OPERATOR,">");)if(this.match(g.IDENTIFIER))for(i+=this.advance().value;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)i+=".",this.advance(),i+=this.advance().value;else if(this.match(g.COMMA))i+=this.advance().value,this.skipNewlines();else break;this.match(g.OPERATOR,">")&&(i+=">",this.advance()),r=this.expectIdentifierOrContextual().value}else r=this.expectIdentifierOrContextual().value}else if(this.peek().type===g.IDENTIFIER)r=this.advance().value;else throw new Error(`Expected identifier after ${e} at ${this.peek().line}:${this.peek().column}`);this.functionNames.has(r)&&(r=r+"_var"),this.expect(g.OPERATOR,"="),this.skipNewlines(!0);const n=this.parseExpression(),a=new ge(r);i&&(a.varType=i);const s=[new at(a,n,i)];for(;this.match(g.COMMA)&&this.peek(1).type===g.KEYWORD&&(this.peek(1).value==="var"||this.peek(1).value==="varip");){this.advance();const o=this.parseVarDeclaration();s.push(...o.declarations)}return new ft(s,e)}isTypedVarDeclaration(){let e=0;if(this.peek(e).type!==g.IDENTIFIER)return!1;for(e++;this.peek(e).type===g.DOT&&this.peek(e+1).type===g.IDENTIFIER;)e+=2;if(this.peek(e).type===g.LBRACKET&&this.peek(e+1).type===g.RBRACKET)return e+=2,this.peek(e).type!==g.IDENTIFIER?!1:(e++,this.peek(e).type===g.OPERATOR&&this.peek(e).value==="=");if(this.peek(e).type===g.OPERATOR&&this.peek(e).value==="<"){e++;let i=1;for(;i>0&&this.peek(e).type!==g.EOF;)this.peek(e).type===g.OPERATOR&&this.peek(e).value==="<"?i++:this.peek(e).type===g.OPERATOR&&this.peek(e).value===">"&&i--,e++;return this.peek(e).type!==g.IDENTIFIER?!1:(e++,this.peek(e).type===g.OPERATOR&&this.peek(e).value==="=")}if(this.peek(e).type!==g.IDENTIFIER)return!1;for(e++;this.peek(e).type===g.IDENTIFIER;)e++;return this.peek(e).type===g.OPERATOR&&this.peek(e).value==="="}parseTypedVarDeclaration(){let e=this.advance().value;for(;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(g.LBRACKET)&&this.peek(1).type===g.RBRACKET)this.advance(),this.advance(),e+="[]";else if(this.match(g.OPERATOR,"<")){for(this.advance(),e+="<";!this.match(g.OPERATOR,">");)if(this.match(g.IDENTIFIER))for(e+=this.advance().value;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)e+=".",this.advance(),e+=this.advance().value;else if(this.match(g.COMMA))e+=this.advance().value,this.skipNewlines();else break;this.match(g.OPERATOR,">")&&(e+=">",this.advance())}else for(;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER;)e+=" "+this.advance().value;let i=this.expectIdentifierOrContextual().value;this.functionNames.has(i)&&(i=i+"_var"),this.expect(g.OPERATOR,"="),this.skipNewlines(!0);const r=this.parseExpression(),n=new ge(i);n.varType=e;const a=[new at(n,r,e)];for(;this.match(g.COMMA)&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type===g.OPERATOR&&this.peek(2).value==="=";){this.advance(),this.skipNewlines(!0);let s=this.expectIdentifierOrContextual().value;this.functionNames.has(s)&&(s=s+"_var"),this.expect(g.OPERATOR,"="),this.skipNewlines(!0);const o=this.parseExpression(),l=new ge(s);l.varType=e,a.push(new at(l,o,e))}return new ft(a,_t.LET)}parseFunctionDeclaration(){let e=null;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&(e=this.advance().value);const i=this.expect(g.IDENTIFIER).value;this.functionNames.add(i),this.expect(g.LPAREN);const r=[];for(;!this.match(g.RPAREN)&&(this.skipNewlines(),!this.match(g.RPAREN));){let o=null;for(;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type!==g.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.OPERATOR&&this.peek(1).value==="<"){const u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.LBRACKET&&this.peek(2).type===g.RBRACKET){const u=this.parseTypeExpression();o=o?o+" "+u:u}const l=this.expectIdentifierOrContextual().value,c=new ge(l);if(o&&(c.varType=o),this.match(g.OPERATOR,"=")){this.advance(),this.skipNewlines();const u=this.parseExpression();r.push(new zn(c,u))}else r.push(c);this.match(g.COMMA)&&this.advance()}this.expect(g.RPAREN),this.skipNewlines(),this.expect(g.OPERATOR,"=>"),this.skipNewlines();const n=new Set;for(const o of r){const l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&n.add(l.name)}this.paramScopes.push(n);let a;try{a=this.parseFunctionBody()}finally{this.paramScopes.pop()}const s=new ge(i);return e&&(s.returnType=e),new $n(s,r,a,e)}parseMethodDeclaration(){this.expect(g.KEYWORD,"method");let e=null;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type===g.LPAREN&&(e=this.advance().value);const i=this.expectIdentifierOrContextual().value;this.expect(g.LPAREN);const r=[];for(;!this.match(g.RPAREN)&&(this.skipNewlines(),!this.match(g.RPAREN));){let o=null;for(;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type!==g.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.OPERATOR&&this.peek(1).value==="<"){const u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.LBRACKET&&this.peek(2).type===g.RBRACKET){const u=this.parseTypeExpression();o=o?o+" "+u:u}const l=this.expectIdentifierOrContextual().value,c=new ge(l);if(o&&(c.varType=o),this.match(g.OPERATOR,"=")){this.advance(),this.skipNewlines();const u=this.parseExpression();r.push(new zn(c,u))}else r.push(c);this.match(g.COMMA)&&this.advance()}this.expect(g.RPAREN),this.skipNewlines(),this.expect(g.OPERATOR,"=>"),this.skipNewlines();const n=new Set;for(const o of r){const l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&n.add(l.name)}this.paramScopes.push(n);let a;try{a=this.parseFunctionBody()}finally{this.paramScopes.pop()}const s=new ge(i);return e&&(s.returnType=e),s.isMethod=!0,new $n(s,r,a,e)}parseFunctionBody(){const e=[];if(!this.match(g.INDENT)){const i=this.parseExpression();return new Et([new jn(i)])}for(this.advance();!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const i=this.parseStatementOrSequence();Array.isArray(i)?e.push(...i):i&&e.push(i)}return this.match(g.DEDENT)&&this.advance(),e.length>0&&this._addImplicitReturn(e),new Et(e)}_addImplicitReturn(e){const i=e[e.length-1];i.type==="ExpressionStatement"?e[e.length-1]=new jn(i.expression):i.type==="IfStatement"&&this._addImplicitReturnToIf(i)}_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;const e=this.peek().line;if(this.match(g.KEYWORD,"if")){const r=this.parseIfStatement();return r&&(r._line=e),r}if(this.match(g.KEYWORD,"for"))return this.parseForStatement();if(this.match(g.KEYWORD,"while"))return this.parseWhileStatement();if(this.match(g.KEYWORD,"break")||this.match(g.KEYWORD,"continue")){const r=this.advance().value;return new Ke(new ge(r))}if(this.match(g.KEYWORD,"var")||this.match(g.KEYWORD,"varip"))return this.parseVarDeclaration();if(this.isTupleDestructuring())return this.parseTupleDestructuring();if(this.peek().type===g.IDENTIFIER&&this.isTypedVarDeclaration()){const r=this.parseTypedVarDeclaration();if(this.match(g.COMMA)&&this.peek(1).type===g.IDENTIFIER){const n=[r];for(;this.match(g.COMMA);)if(this.advance(),this.skipNewlines(!0),this.peek().type===g.IDENTIFIER&&this.isTypedVarDeclaration())n.push(this.parseTypedVarDeclaration());else{const a=this.parseExpression();if(this.match(g.OPERATOR)){const s=this.peek().value;if(["=",":="].includes(s)){this.advance(),this.skipNewlines(!0);const o=this.parseExpression();s==="="&&a.type==="Identifier"?n.push(new ft([new at(a,o)],_t.LET)):n.push(new Ke(new oi(s===":="?"=":s,a,o)))}}break}return n}return r}const i=[];for(;;){const r=this.parseExpression();if(this.match(g.OPERATOR)){const n=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(n)){this.advance(),this.skipNewlines(!0);const a=this.parseExpression();if(n==="="&&r.type==="Identifier"?i.push(new ft([new at(r,a)],_t.LET)):i.push(new Ke(new oi(n===":="?"=":n,r,a))),this.match(g.COMMA)){this.advance(),this.skipNewlines();continue}break}else{if(i.length>0)i.push(new Ke(r));else return new Ke(r);break}}else if(this.match(g.COMMA)){i.push(new Ke(r)),this.advance(),this.skipNewlines();continue}else{if(i.length>0)i.push(new Ke(r));else return new Ke(r);break}}return i.length>1?i:i.length===1?i[0]:null}parseIfStatement(){this.expect(g.KEYWORD,"if");const e=this.parseExpression();this.skipNewlines();const i=this.parseBlock();let r=null;return this.skipNewlines(),this.match(g.KEYWORD,"else")&&(this.advance(),this.skipNewlines(),this.match(g.KEYWORD,"if")?r=this.parseIfStatement():r=this.parseBlock()),new i_(e,i,r)}parseForStatement(){this.expect(g.KEYWORD,"for");let e=null,i=!1;if(this.match(g.LBRACKET)){this.advance();const r=[];for(;!this.match(g.RBRACKET);)this.skipNewlines(),r.push(new ge(this.expectIdentifierOrContextual().value)),this.match(g.COMMA)&&this.advance();this.expect(g.RBRACKET),e=new qn(r),i=!0}else{const r=this.expectIdentifierOrContextual().value;e=new ge(r)}if(this.match(g.KEYWORD,"in")){this.advance();const r=this.parseExpression();this.skipNewlines();const n=this.parseBlock(),a=new ft([new at(e,r)],_t.CONST),s=new Vn(a,null,null,n);return s.isForIn=!0,s}else{if(i)throw new Error(`Range-based for loops don't support destructuring at ${this.peek().line}:${this.peek().column}`);this.expect(g.OPERATOR,"=");const r=this.parseExpression();this.expect(g.KEYWORD,"to");const n=this.parseExpression();let a=null;this.match(g.KEYWORD,"by")&&(this.advance(),a=this.parseExpression()),this.skipNewlines();const s=this.parseBlock(),o=new ft([new at(e,r)],_t.LET),l=new dt("<=",r,n),c=new Nt(l,new dt("<=",e,n),new dt(">=",e,n));let u;return a?u=new Nt(l,new oi("+=",e,a),new oi("-=",e,a)):u=new Nt(l,new Bn("++",e),new Bn("--",e)),new Vn(o,c,u,s)}}parseWhileStatement(){this.expect(g.KEYWORD,"while");const e=this.parseExpression();this.skipNewlines();const i=this.parseBlock();return new r_(e,i)}parseBlock(){if(!this.match(g.INDENT)){const r=this.parseStatement();return new Et(r?[r]:[])}const e=this.peek().indent;this.advance();const i=[];for(;!this.match(g.EOF);){if(this.skipNewlines(),this.match(g.DEDENT)){if(this.peek().indent<e)break;this.advance();continue}if(this.match(g.EOF))break;const r=this.parseStatement();r&&i.push(r)}return this.match(g.DEDENT)&&this.peek().indent<e&&this.advance(),new Et(i)}isTupleDestructuring(){if(!this.match(g.LBRACKET))return!1;let e=1;for(;;){for(;this.peek(e).type===g.NEWLINE;)e++;if(this.peek(e).type!==g.IDENTIFIER)return!1;for(e++;this.peek(e).type===g.NEWLINE;)e++;if(this.peek(e).type===g.RBRACKET){e++;break}else if(this.peek(e).type===g.COMMA){e++;continue}else return!1}for(;this.peek(e).type===g.NEWLINE;)e++;return this.peek(e).type===g.OPERATOR&&this.peek(e).value==="="}parseTupleDestructuring(){this.expect(g.LBRACKET);const e=[];for(;!this.match(g.RBRACKET);){this.skipNewlines();let r=this.expectIdentifierOrContextual().value;this.functionNames.has(r)&&(r=r+"_var"),e.push(new ge(r)),this.match(g.COMMA)&&this.advance()}this.expect(g.RBRACKET),this.skipNewlines(),this.expect(g.OPERATOR,"="),this.skipNewlines(!0);const i=this.parseExpression();return new ft([new at(new qn(e),i)],_t.CONST)}parseExpression(){return this.parseTernary()}parseTernary(){let e=this.parseLogicalOr();if(this.matchEx(g.OPERATOR,"?",!0)){this.advance(),this.skipNewlines(!0);const i=this.parseExpression();this.matchEx(g.COLON,null,!0)?this.advance():this.expect(g.COLON),this.skipNewlines(!0);const r=this.parseExpression();return new Nt(e,i,r)}return e}parseLogicalOr(){let e=this.parseLogicalAnd();for(;this.matchEx(g.KEYWORD,"or",!0)||this.peekOperatorEx(["||"]);){this.advance(),this.skipNewlines(!0);const i=this.parseLogicalAnd();e=new dt("||",e,i)}return e}parseLogicalAnd(){let e=this.parseEquality();for(;this.matchEx(g.KEYWORD,"and",!0)||this.peekOperatorEx(["&&"]);){this.advance(),this.skipNewlines(!0);const i=this.parseEquality();e=new dt("&&",e,i)}return e}parseEquality(){let e=this.parseComparison();for(;this.peekOperatorEx(["==","!="]);){const i=this.advance().value;this.skipNewlines(!0);const r=this.parseComparison();e=new dt(i,e,r)}return e}parseComparison(){let e=this.parseAdditive();for(;this.peekOperatorEx(["<",">","<=",">="]);){const i=this.advance().value;this.skipNewlines(!0);const r=this.parseAdditive();e=new dt(i,e,r)}return e}parseAdditive(){let e=this.parseMultiplicative();for(;this.peekOperatorEx(["+","-"]);){const i=this.advance().value;this.skipNewlines(!0);const r=this.parseMultiplicative();e=new dt(i,e,r)}return e}parseMultiplicative(){let e=this.parseUnary();for(;this.peekOperatorEx(["*","/","%"]);){const i=this.advance().value;this.skipNewlines(!0);const r=this.parseUnary();e=new dt(i,e,r)}return e}parseUnary(){if(this.match(g.OPERATOR)){const e=this.peek().value;if(["+","-","!"].includes(e))return this.advance(),this.skipNewlines(),new Ln(e,this.parseUnary())}return this.match(g.KEYWORD,"not")?(this.advance(),this.skipNewlines(),new Ln("!",this.parseUnary())):this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match(g.OPERATOR,"<")){const i=this.pos;this.advance();let r=1,n=!0,a="";const s=new Set(["float","int","string","bool","color","line","label","box","linefill","table"]);for(;r>0&&!this.match(g.EOF);)if(this.match(g.OPERATOR,"<"))r++,this.advance();else if(this.match(g.OPERATOR,">"))r--,this.advance();else if(this.match(g.IDENTIFIER)||this.match(g.COMMA)||this.match(g.DOT))r===1&&this.match(g.IDENTIFIER)&&a===""&&(a=this.peek().value),this.advance();else{n=!1,this.pos=i;break}if(n&&e.type==="MemberExpression"&&e.property.name==="new"&&(e.object.name==="array"||e.object.name==="matrix")&&s.has(a)&&(e.property=new ge("new_"+a)),n&&this.match(g.LPAREN)){e=this.parseCallExpression(e);continue}else{if(n)continue;break}}else if(this.match(g.LPAREN))e=this.parseCallExpression(e);else if(this.match(g.DOT)){this.advance(),this.skipNewlines();const i=this.peek();if(i.type!==g.IDENTIFIER&&i.type!==g.KEYWORD)throw new Error(`Expected property name but got ${i.type} at ${i.line}:${i.column}`);this.advance(),e=new Fn(e,new ge(i.value),!1)}else if(this.match(g.LBRACKET)){if(this.isTupleDestructuring())break;this.advance(),this.skipNewlines();const i=this.parseExpression();this.expect(g.RBRACKET),e=new Fn(e,i,!0)}else break;return e}parseCallExpression(e){this.expect(g.LPAREN);const i=[],r=[];for(;!this.match(g.RPAREN)&&(this.skipNewlines(),!this.match(g.RPAREN));){if((this.peek().type===g.IDENTIFIER||this.peek().type===g.KEYWORD)&&this.peek(1).type===g.OPERATOR&&this.peek(1).value==="="){const n=this.advance().value;this.advance(),this.skipNewlines();const a=this.parseExpression();r.push(new Un(new ge(n),a))}else i.push(this.parseExpression());this.match(g.COMMA)&&this.advance(),this.skipNewlines()}return this.expect(g.RPAREN),r.length>0&&i.push(new Wn(r)),new n_(e,i)}parsePrimary(){const e=this.peek();if(this.match(g.NUMBER)){const i=this.advance();return new Pt(i.value)}if(this.match(g.STRING)){const i=this.advance();return new Pt(i.value)}if(this.match(g.BOOLEAN)){const i=this.advance();return new Pt(i.value)}if(this.match(g.IDENTIFIER)||e.type===g.KEYWORD&&Vr.CONTEXTUAL_KEYWORDS.has(e.value)){let i=this.advance().value;return this.functionNames.has(i)&&this.peek().type!==g.LPAREN&&!this.isCurrentFunctionParam(i)&&(i=i+"_var"),new ge(i)}if(this.match(g.LBRACKET))return this.parseArrayLiteral();if(this.match(g.LPAREN)){this.advance(),this.skipNewlines();const i=this.parseExpression();return this.skipNewlines(),this.expect(g.RPAREN),i}if(this.match(g.KEYWORD,"if"))return this.parseIfExpression();if(this.match(g.KEYWORD,"switch"))return this.parseSwitchExpression();if(this.match(g.KEYWORD,"for"))return this.parseForExpression();if(this.match(g.KEYWORD,"while"))return this.parseWhileExpression();throw new Error(`Unexpected token ${e.type} '${e.value}' at ${e.line}:${e.column}`)}parseArrayLiteral(){this.expect(g.LBRACKET);const e=[];for(;!this.match(g.RBRACKET)&&(this.skipNewlines(),!this.match(g.RBRACKET));)e.push(this.parseExpression()),this.match(g.COMMA)&&this.advance(),this.skipNewlines();return this.expect(g.RBRACKET),new s_(e)}parseIfExpression(){this.expect(g.KEYWORD,"if");const e=this.parseExpression();this.skipNewlines(),this.expect(g.INDENT);const i=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const s=this.parseStatement();s&&i.push(s)}this.advance();let r=[];if(this.match(g.KEYWORD,"else"))if(this.advance(),this.skipNewlines(),this.match(g.KEYWORD,"if")){const s=this.parseIfExpression();if(this.needsIIFE(i,r)){const o=new Nt(e,new Et(i),s);return o.needsIIFE=!0,o.consequentStmts=i,o.alternateExpr=s,o}else return new Nt(e,this.getBlockValue(i),s)}else{for(this.expect(g.INDENT);!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const s=this.parseStatement();s&&r.push(s)}this.advance()}if(this.needsIIFE(i,r)){const s=new Nt(e,new Et(i),new Et(r));return s.needsIIFE=!0,s.consequentStmts=i,s.alternateStmts=r,s}const n=this.getBlockValue(i),a=r.length>0?this.getBlockValue(r):new Pt(null);return new Nt(e,n,a)}needsIIFE(e,i){if(e.length>1||i.length>1)return!0;const r=n=>n.some(a=>a.type==="IfStatement"||a.type==="ForStatement"||a.type==="WhileStatement"||a.type==="BlockStatement");return r(e)||r(i)}parseSwitchExpression(){this.expect(g.KEYWORD,"switch");let e=null;!this.match(g.NEWLINE)&&!this.match(g.INDENT)&&(e=this.parseExpression()),this.skipNewlines(),this.expect(g.INDENT);const i=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){let r=null;this.match(g.OPERATOR,"=>")||(r=this.parseExpression()),this.expect(g.OPERATOR,"=>"),this.skipNewlines();const n=[];if(this.match(g.INDENT)){for(this.advance();!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){const s=this.parseStatement();s&&n.push(s)}this.advance()}else{this.noLineContinuation=!0;const s=this.parseStatement();this.noLineContinuation=!1,s&&n.push(s)}const a=this.getBlockValue(n);i.push(new o_(r,a,n)),this.skipNewlines()}return this.advance(),new a_(e,i)}parseForExpression(){const e=this.parseForStatement();return e.isExpression=!0,e}parseWhileExpression(){const e=this.parseWhileStatement();return e.isExpression=!0,e}getBlockValue(e){if(e.length===0)return new Pt(null);const i=e[e.length-1];return i.type==="ExpressionStatement"?i.expression:i.type==="VariableDeclaration"&&i.declarations.length>0?i.declarations[0].id:new Pt(null)}};Jt(Aa,"CONTEXTUAL_KEYWORDS",new Set(["type","method","enum"]));let u_=Aa;var h_=Object.defineProperty,p_=(t,e,i)=>e in t?h_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,mt=(t,e,i)=>p_(t,typeof e!="symbol"?e+"":e,i);const f_=new Set(en);class d_{constructor(e={}){mt(this,"indent"),mt(this,"indentStr"),mt(this,"output"),mt(this,"sourceCode"),mt(this,"sourceLines"),mt(this,"lastCommentedLine"),mt(this,"includeSourceComments"),mt(this,"paramRenameCounter"),mt(this,"functionParams"),this.indent=0,this.indentStr=e.indentStr||" ",this.output=[],this.sourceCode=e.sourceCode||null,this.sourceLines=this.sourceCode?this.sourceCode.split(`
24
+ `):[],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){const i=new Map;this.collectConflictingVarNames(e,i),i.size>0&&this.renameVariableRefsInAST(e,i)}isReservedName(e){return!!e&&(Ny.has(e)||On.has(e))}collectConflictingVarNames(e,i){if(!(!e||typeof e!="object")){if(e.type==="VariableDeclaration"){for(const r of e.declarations)if(r.id?.type==="Identifier"&&this.isReservedName(r.id.name)&&!i.has(r.id.name)&&i.set(r.id.name,`${r.id.name}_$${this.paramRenameCounter++}`),r.id?.type==="ArrayPattern")for(const n of r.id.elements)n?.type==="Identifier"&&this.isReservedName(n.name)&&!i.has(n.name)&&i.set(n.name,`${n.name}_$${this.paramRenameCounter++}`)}(e.type==="AssignmentExpression"||e.type==="ReassignmentExpression")&&e.left?.type==="Identifier"&&this.isReservedName(e.left.name)&&!i.has(e.left.name)&&i.set(e.left.name,`${e.left.name}_$${this.paramRenameCounter++}`),e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"&&!e.id.isMethod&&this.isReservedName(e.id.name)&&!i.has(e.id.name)&&i.set(e.id.name,`${e.id.name}_$${this.paramRenameCounter++}`);for(const r of Object.keys(e)){if(r==="type")continue;const n=e[r];if(Array.isArray(n))for(const a of n)a&&typeof a=="object"&&this.collectConflictingVarNames(a,i);else n&&typeof n=="object"&&n.type&&this.collectConflictingVarNames(n,i)}}}renameVariableRefsInAST(e,i){if(!(!e||typeof e!="object")){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&i.has(e.callee.name)?On.has(e.callee.name)&&(e.callee.name=i.get(e.callee.name)):this.renameVariableRefsInAST(e.callee,i),e.arguments)for(const r of e.arguments)this.renameVariableRefsInAST(r,i);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&i.has(e.object.name))return;if(!e.computed&&e.property?.type==="Identifier"&&i.has(e.property.name)){this.renameVariableRefsInAST(e.object,i);return}this.renameVariableRefsInAST(e.object,i),e.computed&&this.renameVariableRefsInAST(e.property,i);return}if(e.type==="Property"){this.renameVariableRefsInAST(e.value,i);return}if(e.type==="Identifier"&&i.has(e.name)){e.name=i.get(e.name);return}for(const r of Object.keys(e)){if(r==="type")continue;const n=e[r];if(Array.isArray(n))for(const a of n)a&&typeof a=="object"&&this.renameVariableRefsInAST(a,i);else n&&typeof n=="object"&&n.type&&this.renameVariableRefsInAST(n,i)}}}collectFunctionParams(e){if(!(!e||typeof e!="object")){if(e.type==="FunctionDeclaration"&&e.id?.name){const i=[];for(const r of e.params)r.type==="Identifier"?i.push(r.name):r.type==="AssignmentPattern"&&r.left?.name&&i.push(r.left.name);this.functionParams.set(e.id.name,i)}if(Array.isArray(e.body))for(const i of e.body)this.collectFunctionParams(i);else e.body&&typeof e.body=="object"&&this.collectFunctionParams(e.body)}}writeSourceComment(e,i=null){if(!this.sourceLines.length)return;const r=i||e,n=[];for(let a=e-1;a<r&&a<this.sourceLines.length;a++)if(a>this.lastCommentedLine){const s=this.sourceLines[a].trim();s&&!s.startsWith("//@")&&!s.startsWith("//")&&n.push(this.sourceLines[a])}if(n.length>0){for(const a of n)this.write(this.indentStr.repeat(this.indent)),this.write("/// "),this.write(a.trimEnd()),this.write(`
25
25
  `);this.lastCommentedLine=Math.max(this.lastCommentedLine,r-1)}}write(e){this.output.push(e)}writeLine(e=""){e?this.output.push(this.indentStr.repeat(this.indent)+e+`
26
26
  `):this.output.push(`
27
27
  `)}increaseIndent(){this.indent++}decreaseIndent(){this.indent--}generateProgram(e){for(let i=0;i<e.body.length;i++)if(this.generateStatement(e.body[i]),i<e.body.length-1){const r=e.body[i],n=e.body[i+1];(r.type==="FunctionDeclaration"||r.type==="TypeDefinition")&&(n.type==="FunctionDeclaration"||n.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 i=0;i<e.fields.length;i++){const r=e.fields[i];r.defaultValue?(this.write(`${r.name}: ['${r.type}', `),this.generateExpression(r.defaultValue),this.write("]")):this.write(`${r.name}: '${r.type}'`),i<e.fields.length-1&&this.write(", ")}this.write(" ")}this.write(`});
28
- `)}renameIdentifiersInAST(e,i){if(!(!e||typeof e!="object")){if(e.type==="Identifier"&&i.has(e.name)){e.name=i.get(e.name);return}if(e.type!=="FunctionDeclaration")for(const r of Object.keys(e)){if(r==="type")continue;const n=e[r];if(Array.isArray(n))for(const s of n)s&&typeof s=="object"&&this.renameIdentifiersInAST(s,i);else n&&typeof n=="object"&&n.type&&this.renameIdentifiersInAST(n,i)}}}renameParamRefsInBody(e,i){if(!(!e||typeof e!="object")&&e.type!=="FunctionDeclaration"){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&i.has(e.callee.name)||this.renameParamRefsInBody(e.callee,i),e.arguments)for(const r of e.arguments)this.renameParamRefsInBody(r,i);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&i.has(e.object.name))return;this.renameParamRefsInBody(e.object,i),e.computed&&this.renameParamRefsInBody(e.property,i);return}if(e.type==="Property"){this.renameParamRefsInBody(e.value,i);return}if(e.type==="Identifier"&&i.has(e.name)){e.name=i.get(e.name);return}for(const r of Object.keys(e)){if(r==="type")continue;const n=e[r];if(Array.isArray(n))for(const s of n)s&&typeof s=="object"&&this.renameParamRefsInBody(s,i);else n&&typeof n=="object"&&n.type&&this.renameParamRefsInBody(n,i)}}}generateFunctionDeclaration(e){this.write(this.indentStr.repeat(this.indent));const i=e.id.isMethod,r=new Map;for(const c of e.params){const u=c.type==="AssignmentPattern"?c.left.name:c.name;if(u&&s_.has(u)){const p=`${u}_$${this.paramRenameCounter++}`;r.set(u,p)}}const n=c=>c.type==="Identifier"&&c.name==="this"||c.type==="AssignmentPattern"&&c.left?.name==="this",s=new Map;if(i&&e.params.length>0&&n(e.params[0])&&s.set("this","self"),r.size>0||s.size>0){for(const c of e.params){const u=c.type==="AssignmentPattern"?c.left:c;if(u?.type==="Identifier"){const p=r.get(u.name)??s.get(u.name);p&&(u.name=p)}c.type==="AssignmentPattern"&&c.right&&(r.size>0&&this.renameParamRefsInBody(c.right,r),s.size>0&&this.renameIdentifiersInAST(c.right,s))}r.size>0&&this.renameParamRefsInBody(e.body,r),s.size>0&&this.renameIdentifiersInAST(e.body,s)}const a=i?`$M_${e.id.name}`:e.id.name;this.write("function "),this.write(a),this.write("(");const o=e.params;for(let c=0;c<o.length;c++){const 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(`
29
- `),i&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${a}.__pineMethod__ = true;
30
- `));const l=[];for(let c=0;c<e.params.length;c++){const u=e.params[c],p=u.type==="AssignmentPattern"?u.left?.name:u.name;if(i&&c===0&&p==="self")continue;const h=u.type==="AssignmentPattern"?u.left?.varType:u.varType;p&&h&&l.push([p,h])}if(l.length>0){this.write(this.indentStr.repeat(this.indent));const c=l.map(([u,p])=>`${JSON.stringify(u)}: ${JSON.stringify(p)}`).join(", ");this.write(`${a}.__pineParamTypes__ = {${c}};
28
+ `)}renameIdentifiersInAST(e,i){if(!(!e||typeof e!="object")){if(e.type==="Identifier"&&i.has(e.name)){e.name=i.get(e.name);return}if(e.type!=="FunctionDeclaration")for(const r of Object.keys(e)){if(r==="type")continue;const n=e[r];if(Array.isArray(n))for(const a of n)a&&typeof a=="object"&&this.renameIdentifiersInAST(a,i);else n&&typeof n=="object"&&n.type&&this.renameIdentifiersInAST(n,i)}}}renameParamRefsInBody(e,i){if(!(!e||typeof e!="object")&&e.type!=="FunctionDeclaration"){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&i.has(e.callee.name)||this.renameParamRefsInBody(e.callee,i),e.arguments)for(const r of e.arguments)this.renameParamRefsInBody(r,i);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&i.has(e.object.name))return;this.renameParamRefsInBody(e.object,i),e.computed&&this.renameParamRefsInBody(e.property,i);return}if(e.type==="Property"){this.renameParamRefsInBody(e.value,i);return}if(e.type==="Identifier"&&i.has(e.name)){e.name=i.get(e.name);return}for(const r of Object.keys(e)){if(r==="type")continue;const n=e[r];if(Array.isArray(n))for(const a of n)a&&typeof a=="object"&&this.renameParamRefsInBody(a,i);else n&&typeof n=="object"&&n.type&&this.renameParamRefsInBody(n,i)}}}generateFunctionDeclaration(e){this.write(this.indentStr.repeat(this.indent));const i=e.id.isMethod,r=new Map;for(const c of e.params){const u=c.type==="AssignmentPattern"?c.left.name:c.name;if(u&&f_.has(u)){const p=`${u}_$${this.paramRenameCounter++}`;r.set(u,p)}}const n=c=>c.type==="Identifier"&&c.name==="this"||c.type==="AssignmentPattern"&&c.left?.name==="this",a=new Map;if(i&&e.params.length>0&&n(e.params[0])&&a.set("this","self"),r.size>0||a.size>0){for(const c of e.params){const u=c.type==="AssignmentPattern"?c.left:c;if(u?.type==="Identifier"){const p=r.get(u.name)??a.get(u.name);p&&(u.name=p)}c.type==="AssignmentPattern"&&c.right&&(r.size>0&&this.renameParamRefsInBody(c.right,r),a.size>0&&this.renameIdentifiersInAST(c.right,a))}r.size>0&&this.renameParamRefsInBody(e.body,r),a.size>0&&this.renameIdentifiersInAST(e.body,a)}const s=i?`$M_${e.id.name}`:e.id.name;this.write("function "),this.write(s),this.write("(");const o=e.params;for(let c=0;c<o.length;c++){const 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(`
29
+ `),i&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${s}.__pineMethod__ = true;
30
+ `));const l=[];for(let c=0;c<e.params.length;c++){const u=e.params[c],p=u.type==="AssignmentPattern"?u.left?.name:u.name;if(i&&c===0&&p==="self")continue;const h=u.type==="AssignmentPattern"?u.left?.varType:u.varType;p&&h&&l.push([p,h])}if(l.length>0){this.write(this.indentStr.repeat(this.indent));const c=l.map(([u,p])=>`${JSON.stringify(u)}: ${JSON.stringify(p)}`).join(", ");this.write(`${s}.__pineParamTypes__ = {${c}};
31
31
  `)}}generateVariableDeclaration(e){const i=e.kind==="var"||e.kind==="varip"?"var":"let";for(let r=0;r<e.declarations.length;r++){const n=e.declarations[r];if(n.init&&n.init.type==="ConditionalExpression"&&n.init.needsIIFE){const o=n.id.type==="Identifier"?n.id.name:null;if(o){this.write(this.indentStr.repeat(this.indent)),this.write(i),this.write(" "),this.write(o),this.write(`;
32
32
  `),this.generateIfStatementWithAssignment(n.init,o);continue}}if(this.write(this.indentStr.repeat(this.indent)),this.write(i),this.write(" "),n.id.type==="Identifier")this.write(n.id.name);else if(n.id.type==="ArrayPattern"){const o=new Set;this.write("[");for(let l=0;l<n.id.elements.length;l++){let c=n.id.elements[l].name;if(o.has(c)){const u=`${c}${this.paramRenameCounter++}`;n.id.elements[l].name=u,c=u}o.add(c),this.write(c),l<n.id.elements.length-1&&this.write(", ")}this.write("]")}n.init&&(this.write(" = "),this.generateExpression(n.init)),this.write(`;
33
- `);const s=n.id?.varType,a=n.id?.type==="Identifier"?n.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}";
33
+ `);const a=n.id?.varType,s=n.id?.type==="Identifier"?n.id.name:null;s&&typeof a=="string"&&/^[A-Za-z_$][\w$]*$/.test(a)&&a[0]===a[0].toUpperCase()&&(this.write(this.indentStr.repeat(this.indent)),this.write(`"__pineUdtVar:${s}=${a}";
34
34
  `))}}generateExpressionStatement(e){if(e.expression.type==="SwitchExpression"&&e.expression.discriminant===null){this.write(this.indentStr.repeat(this.indent)),this.generateSwitchAsIfElse(e.expression),this.write(`
35
35
  `);return}this.write(this.indentStr.repeat(this.indent)),this.generateExpression(e.expression),this.write(`;
36
36
  `)}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(`
@@ -62,10 +62,10 @@ ${t}
62
62
  `)}else this.write(` else {
63
63
  `),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(i),this.write(` = false;
64
64
  `),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}
65
- `)}generateForStatement(e){if(this.write(this.indentStr.repeat(this.indent)),e.isForIn){if(this.write("for ("),e.init&&e.init.type==="VariableDeclaration"){const i=e.init.declarations[0];if(this.write(`${e.init.kind} `),i.id.type==="Identifier")this.write(i.id.name);else if(i.id.type==="ArrayPattern"){const r=new Set;this.write("[");for(let n=0;n<i.id.elements.length;n++){let s=i.id.elements[n].name;if(r.has(s)){const a=`${s}${this.paramRenameCounter++}`;i.id.elements[n].name=a,s=a}r.add(s),this.write(s),n<i.id.elements.length-1&&this.write(", ")}this.write("]")}this.write(" of "),this.generateExpression(i.init)}this.write(") "),this.generateBlockStatement(e.body,!1);return}if(this.write("for ("),e.init)if(e.init.type==="VariableDeclaration"){const i=e.init.declarations[0];this.write(`${e.init.kind} ${i.id.name}`),i.init&&(this.write(" = "),this.generateExpression(i.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(`;
65
+ `)}generateForStatement(e){if(this.write(this.indentStr.repeat(this.indent)),e.isForIn){if(this.write("for ("),e.init&&e.init.type==="VariableDeclaration"){const i=e.init.declarations[0];if(this.write(`${e.init.kind} `),i.id.type==="Identifier")this.write(i.id.name);else if(i.id.type==="ArrayPattern"){const r=new Set;this.write("[");for(let n=0;n<i.id.elements.length;n++){let a=i.id.elements[n].name;if(r.has(a)){const s=`${a}${this.paramRenameCounter++}`;i.id.elements[n].name=s,a=s}r.add(a),this.write(a),n<i.id.elements.length-1&&this.write(", ")}this.write("]")}this.write(" of "),this.generateExpression(i.init)}this.write(") "),this.generateBlockStatement(e.body,!1);return}if(this.write("for ("),e.init)if(e.init.type==="VariableDeclaration"){const i=e.init.declarations[0];this.write(`${e.init.kind} ${i.id.name}`),i.init&&(this.write(" = "),this.generateExpression(i.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(`;
66
66
  `)}generateBlockStatement(e,i=!0){this.write(`{
67
67
  `),i?this.increaseIndent():this.indent++;for(const r of e.body)this.generateStatement(r);i?this.decreaseIndent():this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),i&&this.write(`
68
- `)}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"){const i=e.value.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t");this.write(`'${i}'`)}else e.value===null?this.write("null"):this.write(String(e.value))}generateBinaryExpression(e){const i=this.getPrecedence(e);this.getPrecedence(e.left)<i?(this.write("("),this.generateExpression(e.left),this.write(")")):this.generateExpression(e.left),this.write(" ");let r=e.operator;r==="and"?r="&&":r==="or"&&(r="||"),this.write(r),this.write(" ");const n=this.getPrecedence(e.right);let s=n<i;n===i&&(r==="-"||r==="/"||r==="%")&&(s=!0),s?(this.write("("),this.generateExpression(e.right),this.write(")")):this.generateExpression(e.right)}generateUnaryExpression(e){let i=e.operator;i==="not"&&(i="!"),this.write(i),this.getPrecedence(e.argument)<15||e.argument.type==="UnaryExpression"&&(i==="-"||i==="+")&&(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 i=e.operator;i===":="&&(i="="),this.write(i),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("(");const i=e.callee?.type==="Identifier"?e.callee.name:null,r=i?this.functionParams.get(i):null,n=e.arguments.length>0?e.arguments[e.arguments.length-1]:null;if(n?.type==="ObjectExpression"&&r){const s=e.arguments.slice(0,-1),a=new Map;for(const u of n.properties){const p=u.key?.name||u.key?.value;p&&a.set(p,u.value)}const o=[];let l=-1;for(let u=0;u<r.length;u++)u<s.length?(o.push(s[u]),l=u):a.has(r[u])?(o.push(a.get(r[u])),l=u):o.push(null);const 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++){const 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(`(() => {
68
+ `)}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"){const i=e.value.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t");this.write(`'${i}'`)}else e.value===null?this.write("null"):this.write(String(e.value))}generateBinaryExpression(e){const i=this.getPrecedence(e);this.getPrecedence(e.left)<i?(this.write("("),this.generateExpression(e.left),this.write(")")):this.generateExpression(e.left),this.write(" ");let r=e.operator;r==="and"?r="&&":r==="or"&&(r="||"),this.write(r),this.write(" ");const n=this.getPrecedence(e.right);let a=n<i;n===i&&(r==="-"||r==="/"||r==="%")&&(a=!0),a?(this.write("("),this.generateExpression(e.right),this.write(")")):this.generateExpression(e.right)}generateUnaryExpression(e){let i=e.operator;i==="not"&&(i="!"),this.write(i),this.getPrecedence(e.argument)<15||e.argument.type==="UnaryExpression"&&(i==="-"||i==="+")&&(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 i=e.operator;i===":="&&(i="="),this.write(i),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("(");const i=e.callee?.type==="Identifier"?e.callee.name:null,r=i?this.functionParams.get(i):null,n=e.arguments.length>0?e.arguments[e.arguments.length-1]:null;if(n?.type==="ObjectExpression"&&r){const a=e.arguments.slice(0,-1),s=new Map;for(const u of n.properties){const p=u.key?.name||u.key?.value;p&&s.set(p,u.value)}const o=[];let l=-1;for(let u=0;u<r.length;u++)u<a.length?(o.push(a[u]),l=u):s.has(r[u])?(o.push(s.get(r[u])),l=u):o.push(null);const 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 a=0;a<e.arguments.length;a++){const s=e.arguments[a];s.type==="AssignmentExpression"&&s.operator==="="?this.generateExpression(s.right):this.generateExpression(s),a<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(`(() => {
69
69
  `),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(`) {
70
70
  `),this.indent++,e.consequentStmts)for(let i=0;i<e.consequentStmts.length;i++){const r=e.consequentStmts[i];i===e.consequentStmts.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;
71
71
  `)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternateExpr)this.write(` else {
@@ -106,8 +106,8 @@ ${t}
106
106
  `),this.indent++,this.write(this.indentStr.repeat(this.indent));for(let i=0;i<e.cases.length;i++){const r=e.cases[i];if(r.test?(i===0?this.write("if ("):this.write(" else if ("),this.generateExpression(r.test),this.write(`) {
107
107
  `)):i>0?this.write(` else {
108
108
  `):this.write(`{
109
- `),this.indent++,r.statements&&r.statements.length>0){const n=r.statements[r.statements.length-1];if(n.type==="ExpressionStatement"||n.type==="VariableDeclaration"){for(let s=0;s<r.statements.length-1;s++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(r.statements[s]);this.write(this.indentStr.repeat(this.indent)),this.write("return "),n.type==="ExpressionStatement"?this.generateExpression(n.expression):this.generateExpression(r.consequent),this.write(`;
110
- `)}else{for(const s of r.statements)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(s);this.write(this.indentStr.repeat(this.indent)),this.write(`return null;
109
+ `),this.indent++,r.statements&&r.statements.length>0){const n=r.statements[r.statements.length-1];if(n.type==="ExpressionStatement"||n.type==="VariableDeclaration"){for(let a=0;a<r.statements.length-1;a++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(r.statements[a]);this.write(this.indentStr.repeat(this.indent)),this.write("return "),n.type==="ExpressionStatement"?this.generateExpression(n.expression):this.generateExpression(r.consequent),this.write(`;
110
+ `)}else{for(const a of r.statements)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(a);this.write(this.indentStr.repeat(this.indent)),this.write(`return null;
111
111
  `)}}else this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.consequent),this.write(`;
112
112
  `);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),i>=e.cases.length-1&&this.write(`
113
113
  `)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSwitchAsIfElse(e){for(let i=0;i<e.cases.length;i++){const r=e.cases[i];if(r.test?(i===0?this.write("if ("):this.write(" else if ("),this.generateExpression(r.test),this.write(`) {
@@ -117,9 +117,9 @@ ${t}
117
117
  `);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),i<e.cases.length-1||this.write(`
118
118
  `)}}generateLoopAsExpression(e,i){this.write(`(() => {
119
119
  `),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`let __result;
120
- `);const r=e.body;if(r&&r.body&&r.body.length>0){const n=r.body.length-1,s=r.body[n];s.type==="ExpressionStatement"&&(r.body[n]={type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:{type:"Identifier",name:"__result"},right:s.expression},_line:s._line})}i==="for"?this.generateForStatement(e):this.generateWhileStatement(e),this.write(this.indentStr.repeat(this.indent)),this.write(`return __result;
121
- `),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSequenceExpression(e){this.write("(");for(let i=0;i<e.expressions.length;i++)this.generateExpression(e.expressions[i]),i<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 Ca(t){const e=/^\s*\/\/\s*@version\s*=\s*(\d+)\s*$/im,i=t.match(e);return i&&i[1]?parseInt(i[1],10):null}function Qr(t,e={}){const i=Ca(t);if(i===null)return{success:!1,version:null,error:"Pine Script version not found. Please add //@version=X comment to your script."};if(i<5)return{success:!1,version:i,error:`Pine Script version ${i} is not supported. Only version 5 and above are supported.`};try{const r=new Uy(t).tokenize(),n=new i_(r).parse(),s={...e,sourceCode:t},a=new a_(s).generate(n);return{success:!0,version:i,code:a,ast:n,tokens:r}}catch(r){return{success:!1,version:i,error:r.message,stack:r.stack}}}const o_=new Set(["security_lower_tf","security"]),Ia=new Set(["type","loc","start","end","range","parent","leadingComments","trailingComments"]);function l_(t){if(!t||t.type!=="CallExpression")return!1;const e=t.callee;return!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="request"||e.property?.type!=="Identifier"?!1:o_.has(e.property.name)}function c_(t){const e=t?.arguments?.[2];return e?.type==="Identifier"&&typeof e.name=="string"?e.name:null}function u_(t){const e=[],i=new WeakSet;function r(n,s){if(!n||typeof n!="object"||i.has(n))return;i.add(n);const a=s.concat([n]);l_(n)&&e.push({call:n,path:a});for(const o of Object.keys(n)){if(Ia.has(o))continue;const l=n[o];if(Array.isArray(l))for(const c of l)r(c,a);else l&&typeof l=="object"&&r(l,a)}}return r(t,[]),e}function Mr(t){return t?t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="FunctionDeclaration":!1}function ot(t,e,i){if(i>=e.length-1)return t;const r=e[i+1];switch(t.type){case"BlockStatement":{const n=t.body.indexOf(r);if(n<0)return t;const s=t.body.slice(0,n);return s.push(ot(r,e,i+1)),{...t,body:s}}case"IfStatement":return r===t.test?{...t,test:ot(r,e,i+1),consequent:{type:"BlockStatement",body:[]},alternate:null}:r===t.consequent?{...t,consequent:ot(r,e,i+1),alternate:null}:r===t.alternate?{...t,alternate:ot(r,e,i+1)}:t;case"ForStatement":case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return r===t.body?{...t,body:ot(r,e,i+1)}:t;case"SwitchStatement":{const n=t.cases.indexOf(r);if(n>=0){const s=t.cases.slice(0,n);return s.push(ot(r,e,i+1)),{...t,cases:s}}return t}case"SwitchCase":{const n=t.consequent.indexOf(r);if(n>=0){const s=t.consequent.slice(0,n);return s.push(ot(r,e,i+1)),{...t,consequent:s}}return t}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":return r===t.body?{...t,body:ot(r,e,i+1)}:t;default:return t}}function h_(t){if(!t||t.type!=="CallExpression")return null;const 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;const i=t.arguments?.[0];return i?.type==="Identifier"&&typeof i.name=="string"?i.name:null}function p_(t,e,i){const r=t.body||[];for(let n=0;n<r.length;n++){const s=r[n];if(s!==i&&f_(s,e))return n}return-1}function f_(t,e){let i=!1;const r=new WeakSet;function n(s){if(!(i||!s||typeof s!="object")&&!r.has(s)){if(r.add(s),h_(s)===e){i=!0;return}for(const a of Object.keys(s)){if(Ia.has(a))continue;const o=s[a];if(Array.isArray(o))for(const l of o)n(l);else o&&typeof o=="object"&&n(o)}}}return n(t),i}function d_(t,e){let i=-1;for(let h=1;h<e.length;h++)if(Mr(e[h])){i=h;break}if(i<0)return null;const r=e[i];for(let h=i+1;h<e.length;h++)if(Mr(e[h]))return null;if(r.type!=="FunctionDeclaration"||!r.id?.name)return null;const n=r.id.name,s=e.slice(i),a=ot(r,s,0),o=p_(t,n,r);if(o<0)return null;const l=t.body||[],c=l.indexOf(r);if(c<0)return null;const u=[],p=Math.max(o,c);for(let h=0;h<=p;h++){const f=l[h];u.push(f===r?a:f)}return u}function m_(t,e){const i={type:"Program",sourceType:"module",body:[{type:"ExpressionStatement",expression:{type:"ArrowFunctionExpression",async:!!t.async,params:t.params,body:{type:"BlockStatement",body:e}}}]},r=`var _r = ${Gr(i)}
122
- ; return _r;`;return new Function("",r)()}function y_(t){const e={};if(!t||t.type!=="Program"||!Array.isArray(t.body)||t.body.length===0)return e;const i=t.body[0];let r=null;if(i.type==="ExpressionStatement"){const s=i.expression;s&&(s.type==="ArrowFunctionExpression"||s.type==="FunctionExpression")&&(r=s)}else i.type==="FunctionDeclaration"&&(r=i);if(!r||r.body?.type!=="BlockStatement")return e;const n=u_(r.body);for(const{call:s,path:a}of n){const o=c_(s);if(!o||o in e)continue;const l=a.some(p=>Mr(p));let c=null;if(l)c=d_(r.body,a);else{const p=ot(r.body,a,0);c=p&&p.body?p.body:[]}if(!c||c.length===0)continue;const u=m_(r,c);e[o]=u}return e}function __(t){if(typeof t=="function")return t.toString();{const e=Ca(t);if(e===null)return t;if(e>=5){const i=Qr(t);if(i.success)return i.code;throw new Error(`Failed to transpile Pine Script version ${e}: ${i.error}`)}else throw new Error(`Unsupported Pine Script version ${e}. Only version 5 and above are supported.`)}}function g_(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});const{debug:i}=e;let r=__(t);r=Sy(r);const n=i?r.split(`
123
- `):[],s=Kr(r,{ecmaVersion:"latest",sourceType:"module",locations:i});Ey(s),by(s),xy(s);const a=new hy;Iy(s,a),Ny(s,a);const o=Ty(s,a)||"";if(Vy(s,a,o,e,n),$y(s),Oy(s),s.type==="Program"&&s.body.length>0){const f=s.body[0],d=f?.expression||f;d.body?.type==="BlockStatement"&&d.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}}}]})}const l=sy||Hr||void 0,c=Object.assign({},l,{LineComment(f,d){d.write("//"+f.value)}}),u=Gr(s,{generator:c,comments:i}),p=typeof process<"u"&&process?.env?.PINETS_DISABLE_LTF_SLICING==="1"?{}:y_(s),h=new Function("",`var _r = ${u}
124
- ; return _r;`)(this);return p&&Object.keys(p).length>0&&(h._ltfSlices=p),h}const ka=new Set(["open","high","low","close","hl2","hlc3","ohlc4","hlcc4","volume"]),Un={"":["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"]},x_={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 b_(t){if(typeof t!="string")return[];const e=Qr(t);if(!e.success||!e.ast)return[];const i=v_(e.ast),r=[],n=new Set;return Nt(e.ast,s=>{const a=w_(s,i);if(a){if(a.title!==void 0){if(n.has(a.title)){console.warn(`[Indicator] duplicate input title "${a.title}" \u2014 first declaration wins for .input access`);return}n.add(a.title)}r.push(a)}}),r}function v_(t){const e=new Map;return Nt(t,i=>{if(i.type==="VariableDeclaration")for(const r of i.declarations??[]){const n=r?.id?.name,s=r?.init;if(!n||!s||s.type!=="ObjectExpression"||!(s.properties??[]).every(a=>a.value?.type==="Literal"&&typeof a.value.value=="string")||s.properties.length===0)return;for(const a of s.properties)e.set(`${n}.${a.key.name}`,a.value.value)}}),e}function w_(t,e){if(t.type!=="VariableDeclaration")return null;for(const i of t.declarations??[]){const r=i?.init;if(!r||r.type!=="CallExpression")continue;const n=r.callee;let s=null;if(n?.type==="MemberExpression"&&n.object?.type==="Identifier"&&n.object.name==="input"&&n.property?.type==="Identifier"?s=n.property.name:n?.type==="Identifier"&&n.name==="input"&&(s=""),s===null||s!==""&&!(s==="int"||s==="float")&&!(s in Un))continue;const a=r.arguments??[],o=a[a.length-1],l=o?.type==="ObjectExpression",c=l?a.slice(0,-1):a.slice(),u=l?o.properties??[]:[],p={};s==="int"||s==="float"?S_(c,u,p):Ta(Un[s],c,p);for(const m of u)m.type!=="Property"||!m.key?.name||(p[m.key.name]=m.value);const h={};for(const m of Object.keys(p))h[m]=Aa(p[m],e);const f=s===""?E_(h.defval):x_[s];if(!f)continue;const d={type:f,defval:h.defval};return h.title!==void 0&&(d.title=String(h.title)),h.tooltip!==void 0&&(d.tooltip=String(h.tooltip)),h.group!==void 0&&(d.group=String(h.group)),h.inline!==void 0&&(d.inline=String(h.inline)),h.confirm!==void 0&&(d.confirm=!!h.confirm),h.active!==void 0&&(d.active=!!h.active),h.display!==void 0&&(d.display=N_(h.display)),h.options!==void 0&&Array.isArray(h.options)&&(d.options=h.options),typeof h.minval=="number"&&(d.minval=h.minval),typeof h.maxval=="number"&&(d.maxval=h.maxval),typeof h.step=="number"&&(d.step=h.step),d}return null}function S_(t,e,i){const r=new Set(e.map(n=>n.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"];Ta(r,t,i)}function Ta(t,e,i){for(let r=0;r<e.length&&r<t.length;r++){const n=t[r];i[n]===void 0&&(i[n]=e[r])}}function Aa(t,e){if(t!=null)switch(t.type){case"Literal":return t.value;case"Identifier":return ka.has(t.name),t.name;case"MemberExpression":{const i=t.object?.type==="Identifier"?t.object.name:null,r=t.property?.type==="Identifier"?t.property.name:null;if(i&&r){const n=`${i}.${r}`;return e.has(n)?e.get(n):i==="display"?r:n}return}case"ArrayExpression":return(t.elements??[]).map(i=>Aa(i,e));case"UnaryExpression":return t.operator==="-"&&t.argument?.type==="Literal"&&typeof t.argument.value=="number"?-t.argument.value:void 0;default:return}}function E_(t){return typeof t=="boolean"?"bool":typeof t=="number"?Number.isInteger(t)?"int":"float":typeof t=="string"?ka.has(t)?"source":t.startsWith("#")?"color":"string":null}function N_(t){if(typeof t!="string")return;const e=t.startsWith("display.")?t.slice(8):t;if(e==="none"||e==="data_window"||e==="status_line"||e==="all")return e}function Nt(t,e){if(!(!t||typeof t!="object")){if(e(t),Array.isArray(t.body))for(const i of t.body)Nt(i,e);else t.body&&Nt(t.body,e);if(Array.isArray(t.consequent))for(const i of t.consequent)Nt(i,e);else t.consequent&&Nt(t.consequent,e);if(t.alternate&&Nt(t.alternate,e),Array.isArray(t.declarations))for(const i of t.declarations)Nt(i,e)}}function Pa(t,e,i,r,n="key"){const s={},a=new Map;for(const o of t)a.set(o.key,o),s[o.key]=r&&o.key in r?r[o.key]:o.defval;return{proxy:new Proxy(s,{get(o,l){return o[l]},set(o,l,c){if(typeof l!="string")return!1;const u=a.get(l);if(!u)throw new Error(`[${e}] unknown ${n} "${l}". Known: ${[...a.keys()].join(", ")||"(none)"}`);return C_(u,c,e),o[l]=c,i?.(l),!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"&&l in o}}),values:s,entryByKey:a}}function C_(t,e,i){const r=t.key;switch(t.type){case"int":if(typeof e!="number"||!Number.isInteger(e))throw new TypeError(`[${i}] "${r}" expects an int; got ${Xt(e)}`);break;case"float":case"price":case"time":if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`[${i}] "${r}" expects a number; got ${Xt(e)}`);break;case"bool":if(typeof e!="boolean")throw new TypeError(`[${i}] "${r}" expects a boolean; got ${Xt(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(`[${i}] "${r}" expects a string; got ${Xt(e)}`);break}if(t.options&&!t.options.some(n=>I_(n,e)))throw new RangeError(`[${i}] "${r}" value ${Xt(e)} is not one of: ${t.options.map(Xt).join(", ")}`);if(typeof e=="number"){if(typeof t.minval=="number"&&e<t.minval)throw new RangeError(`[${i}] "${r}" value ${e} is below minval ${t.minval}`);if(typeof t.maxval=="number"&&e>t.maxval)throw new RangeError(`[${i}] "${r}" value ${e} is above maxval ${t.maxval}`)}}function I_(t,e){return t===e?!0:typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<1e-12:!1}function Xt(t){return t===null?"null":typeof t=="string"?JSON.stringify(t):String(t)}function k_(t,e){const i=new Map,r=[];for(const a of t)a.title&&(i.set(a.title,a),r.push({key:a.title,type:a.type,defval:a.defval,options:a.options,minval:a.minval,maxval:a.maxval}));const{proxy:n,values:s}=Pa(r,"Indicator.input",e,void 0,"input title");return{proxy:n,values:s,metaByTitle:i}}const Da=[{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}],Ma=[...Da.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"}],Ra=[...Da.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 T_(t){return t==="strategy"?Ra:Ma}function A_(t){return typeof t=="string"?P_(t):typeof t=="function"?D_(t):{type:null,args:{}}}function P_(t){const e=Qr(t);if(!e.success||!e.ast)return{type:null,args:{}};let i=null;return Gi(e.ast,r=>{if(i||r.type!=="ExpressionStatement"&&r.type!=="VariableDeclaration")return;const n=r.type==="ExpressionStatement"?r.expression:r.declarations?.[0]?.init;if(!n||n.type!=="CallExpression")return;const s=n.callee;s?.type==="Identifier"&&(s.name!=="indicator"&&s.name!=="strategy"||(i={type:s.name,args:$a(n.arguments??[],Oa(s.name))}))}),i??{type:null,args:{}}}function D_(t){let e;try{e=Kr(`(${t.toString()})`,{ecmaVersion:"latest"})}catch{return{type:null,args:{}}}let i=null;return Gi(e,r=>{if(i||r.type!=="CallExpression")return;const n=r.callee;n?.type==="Identifier"&&(n.name!=="indicator"&&n.name!=="strategy"||(i={type:n.name,args:$a(r.arguments??[],Oa(n.name))}))}),i??{type:null,args:{}}}function Oa(t){return t==="strategy"?Ra:Ma}function $a(t,e){const i={},r=t[t.length-1],n=r?.type==="ObjectExpression",s=n?t.slice(0,-1):t.slice();for(let a=0;a<s.length&&a<e.length;a++){const o=e[a].name;i[o]=Rr(s[a])}if(n)for(const a of r.properties??[])a.type!=="Property"||!a.key?.name||(i[a.key.name]=Rr(a.value));return i}function Rr(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(Rr);default:return}}function Gi(t,e){if(!(!t||typeof t!="object")){e(t);for(const i of Object.keys(t)){const r=t[i];if(!(i==="loc"||i==="range"||i==="start"||i==="end"))if(Array.isArray(r))for(const n of r)Gi(n,e);else r&&typeof r=="object"&&typeof r.type=="string"&&Gi(r,e)}}}function M_(t,e,i){const r=new Map,n=[];for(const o of t)r.set(o.name,o),o.mutable&&n.push({key:o.name,type:o.type,defval:o.defval,options:o.options,minval:o.minval,maxval:o.maxval});const{proxy:s,values:a}=Pa(n,"Indicator.prop",i,e);return{proxy:s,values:a,propByName:r}}var R_=Object.defineProperty,O_=(t,e,i)=>e in t?R_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,je=(t,e,i)=>O_(t,typeof e!="symbol"?e+"":e,i);class bi{constructor(e,i={}){je(this,"source"),je(this,"inputs"),je(this,"_prepared",null),je(this,"_inputMeta",null),je(this,"_inputValues",{}),je(this,"_explicitOverrides",new Set),je(this,"_inputProxy",null),je(this,"_propMeta",null),je(this,"_propValues",{}),je(this,"_propProxy",null),je(this,"_declarationType",null),je(this,"_sourcePropArgs",{}),je(this,"_explicitPropOverrides",new Set),this.source=e,this.inputs=i,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 bi?e:new bi(e)}prepare(e={}){if(this._prepared)return this._prepared;const i=g_(this.source,{debug:!!e.debug,ln:e.ln}),r=$_(i),n=i._ltfSlices;return this._prepared={fn:i,inputs:this.getRuntimeInputs(),usesVisibleRange:r,ltfSlices:n},this._prepared}usesVisibleRange(){return this.prepare().usesVisibleRange}getRuntimeInputs(){const e={...this.inputs??{}};if(this._inputMeta)for(const i of this._explicitOverrides)e[i]=this._inputValues[i];return e}getInputsMeta(){return this._ensureInputsScanned(),this._inputMeta}getPropsMeta(){return this._ensurePropsScanned(),this._propMeta}getRuntimePropOverrides(){const e={};if(this._propMeta)for(const i of this._explicitPropOverrides)e[i]=this._propValues[i];return e}getDeclarationType(){return this._ensurePropsScanned(),this._declarationType}_ensureInputsScanned(){if(this._inputMeta)return;this._inputMeta=b_(this.source);const e=k_(this._inputMeta,i=>this._explicitOverrides.add(i));this._inputValues=e.values,this._inputProxy=e.proxy}_getInputProxy(){return this._ensureInputsScanned(),this._inputProxy}_ensurePropsScanned(){if(this._propMeta)return;const e=A_(this.source);this._declarationType=e.type,this._sourcePropArgs=e.args,this._propMeta=T_(e.type);const i=M_(this._propMeta,this._sourcePropArgs,r=>this._explicitPropOverrides.add(r));this._propValues=i.values,this._propProxy=i.proxy}_getPropProxy(){return this._ensurePropsScanned(),this._propProxy}}function $_(t){const e=t.toString();return my.some(i=>{const r=i.replace(/\./g,"\\.");return new RegExp(`\\b${r}\\b`).test(e)})}var V_=Object.defineProperty,j_=(t,e,i)=>e in t?V_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Q=(t,e,i)=>j_(t,typeof e!="symbol"?e+"":e,i);const qn={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 L_(t){return t?qn[t]??qn[t.toUpperCase()]??864e5:864e5}class Jr{constructor(e,i,r,n,s,a){this.source=e,this.tickerId=i,this.timeframe=r,this.limit=n,this.sDate=s,this.eDate=a,Q(this,"data",[]),Q(this,"open",[]),Q(this,"high",[]),Q(this,"low",[]),Q(this,"close",[]),Q(this,"volume",[]),Q(this,"hl2",[]),Q(this,"hlc3",[]),Q(this,"ohlc4",[]),Q(this,"hlcc4",[]),Q(this,"openTime",[]),Q(this,"closeTime",[]),Q(this,"_readyPromise",null),Q(this,"_ready",!1),Q(this,"_debugSettings",{ln:!1,debug:!1}),Q(this,"_transpiledCode",null),Q(this,"_currentIndicator",null),Q(this,"_isSecondaryContext",!1),Q(this,"_syminfo"),Q(this,"_chartTimezone",null),Q(this,"_maxLoops",5e5),Q(this,"_alertMode","realtime"),Q(this,"_viewportLeft"),Q(this,"_viewportRight"),Q(this,"_usesVisibleRange",!1),Q(this,"_lastRunViewport",{}),Q(this,"_lastResult",null),Q(this,"_lastPineTSCode",null),this._readyPromise=new Promise(o=>{this.loadMarketData(e,i,r,n,s,a).then(l=>{const c=l;this.data=c;const u=c.map(N=>N.open),p=c.map(N=>N.close),h=c.map(N=>N.high),f=c.map(N=>N.low),d=c.map(N=>N.volume),m=c.map(N=>(N.high+N.low+N.close)/3),x=c.map(N=>(N.high+N.low)/2),b=c.map(N=>(N.high+N.low+N.open+N.close)/4),v=c.map(N=>(N.high+N.low+N.close+N.close)/4),w=c.map(N=>N.openTime),S=L_(this.timeframe),T=c.map(N=>N.closeTime!=null?N.closeTime:N.openTime+S);this.open=u,this.close=p,this.high=h,this.low=f,this.volume=d,this.hl2=x,this.hlc3=m,this.ohlc4=b,this.hlcc4=v,this.openTime=w,this.closeTime=T,e&&e.getSymbolInfo?e.getSymbolInfo(i).then(N=>{this._syminfo=N,this._ready=!0,o(!0)}).catch(N=>{console.warn("Failed to get symbol info, using default values:",N),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,i){this._viewportLeft=e,this._viewportRight=i}usesVisibleRange(){return this._usesVisibleRange}get visibleRangeLeft(){return this._viewportLeft}get visibleRangeRight(){return this._viewportRight}async update(e){const i=e??this._lastPineTSCode;if(!i)throw new Error("pine.update(): pineTSCode is required on the first call.");const r=this._lastResult===null,n=this._viewportLeft!==this._lastRunViewport.left||this._viewportRight!==this._lastRunViewport.right;return r||this._usesVisibleRange&&n?(this._lastPineTSCode=i,this._lastRunViewport={left:this._viewportLeft,right:this._viewportRight},this._lastResult=await this.run(i),this._lastResult):this._lastResult}setDebugSettings({ln:e,debug:i}){this._debugSettings.ln=e,this._debugSettings.debug=i}async loadMarketData(e,i,r,n,s,a){return Array.isArray(e)?e:e.getMarketData(i,r,n,s,a)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,i,r){const n=bi.from(e);if(this._currentIndicator=n,r&&r>0){const s=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(n,i,r,s)}else return this._runComplete(n,i)}stream(e,i={}){const{live:r=!0,interval:n=1e3}=i,s=i.pageSize||this.data.length,a=bi.from(e);this._currentIndicator=a;const o={data:[],error:[],warning:[],alert:[]};let l=!1;const c=(h,...f)=>{o[h]&&o[h].forEach(d=>d(...f))},u=(h,f)=>{o[h]||(o[h]=[]),o[h].push(f)},p=()=>{l=!0};return(async()=>{try{r&&typeof this.eDate<"u"&&(this.eDate=Math.max(this.eDate,Date.now()));const h=!Array.isArray(this.source)&&r,f=this._runPaginated(a,void 0,s,h);for await(const d of f){if(l)break;if(d===null){await new Promise(m=>setTimeout(m,n));continue}if(c("data",d),d.warnings&&d.warnings.length>0){for(const m of d.warnings)c("warning",m);d.warnings.length=0}if(d.alerts&&d.alerts.length>0){for(const m of d.alerts)c("alert",m);d.alerts.length=0}if(h&&!l){const m=d.marketData[d.idx],x=m&&m.closeTime<Date.now(),b=d.idx>=d.marketData.length-1;(!x||b)&&await new Promise(v=>setTimeout(v,n))}}}catch(h){c("error",h)}})(),{on:u,stop:p}}async runPretranspiled(e,i={},r){await this.ready(),r||(r=this.data.length);const n=this._initializeContext(null,i,this._isSecondaryContext);this._transpiledCode=e;const s=e._ltfSlices;return s&&(n._ltfTruncatedBodies=s),await this._executeIterations(n,e,this.data.length-r,this.data.length),n}async _runComplete(e,i){await this.ready(),i||(i=this.data.length);const r=e.prepare(this._debugSettings);this._usesVisibleRange=r.usesVisibleRange;const n=this._initializeContext(e.source??null,r.inputs,this._isSecondaryContext);this._transpiledCode=r.fn,r.ltfSlices&&(n._ltfTruncatedBodies=r.ltfSlices);const s=this.data.length-i,a=this.data.length;return a-s>1?(await this._executeIterations(n,r.fn,s,a-1),n._varSnapshot=this._snapshotVarState(n),await this._executeIterations(n,r.fn,a-1,a)):await this._executeIterations(n,r.fn,s,a),n}async*_runPaginated(e,i,r,n=!1){await this.ready(),i||(i=this.data.length);const s=e.prepare(this._debugSettings);this._usesVisibleRange=s.usesVisibleRange;const 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-i,l=null;for(;;){const c=this.data.length,u=c-o;if(u>0){const m=Math.min(u,r),x=this._getResultLength(a.result),b=o+m;n&&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)):n&&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(!n||Array.isArray(this.source))break;const p=Date.now(),{newCandles:h,updatedLastCandle:f}=await this._updateMarketData(),d=Date.now()-p;if(h===0&&!f){yield null;continue}if(h===0&&f&&d<1e3&&await new Promise(m=>setTimeout(m,1e3-d)),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-(h+1),a.rollbackDrawings(o),h>0&&(l=null),a.pine.barstate.setLive()}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){const i=Object.keys(e);if(i.length>0&&Array.isArray(e[i[0]]))return e[i[0]].length}return 0}_createPageContext(e,i){const r=new xn({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(r.pineTSCode=e.pineTSCode,r.idx=e.idx,Array.isArray(e.result))r.result=e.result.slice(i);else if(typeof e.result=="object"&&e.result!==null){r.result={};for(let n in e.result)Array.isArray(e.result[n])?r.result[n]=e.result[n].slice(i):r.result[n]=e.result[n]}else r.result=e.result;return r.plots={...e.plots},r.warnings=e.warnings,r.alerts=e.alerts,r}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};const i=this.source,r=this.data.length-1,n=this.data[r].openTime;try{const s=await i.getMarketData(this.tickerId,this.timeframe,void 0,n,e);if(!s||s.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let l=0;l<s.length;l++){const c=s[l];c.openTime===n?(this._replaceCandle(r,c),a=!0):c.openTime>n&&(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,i){this.data[e]=i,this.open[e]=i.open,this.close[e]=i.close,this.high[e]=i.high,this.low[e]=i.low,this.volume[e]=i.volume,this.hl2[e]=(i.high+i.low)/2,this.hlc3[e]=(i.high+i.low+i.close)/3,this.ohlc4[e]=(i.high+i.low+i.open+i.close)/4,this.hlcc4[e]=(i.high+i.low+i.close+i.close)/4,this.openTime[e]=i.openTime,this.closeTime[e]=i.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;const{newCandles:i,updatedLastCandle:r}=await this._updateMarketData();if(i===0&&!r)return!1;const n=e._varSnapshot;if(n?this._restoreVarState(e,n):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;const s=this.data.length-(i+1);e.rollbackDrawings(s);const 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 n in e.result)Array.isArray(e.result[n])&&e.result[n].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();const i=["const","var","let","params"],r=n=>{for(let s of i)if(n[s])for(let a in n[s]){const o=n[s][a];o instanceof y?o.data.pop():Array.isArray(o)&&o.pop()}};r(e),e.lctx&&e.lctx.forEach(n=>r(n))}_snapshotVarState(e){const i=["const","var","let","params"],r={main:{},lctx:[]},n=s=>{const a={};for(const o of i)if(s[o]){a[o]={};for(const l in s[o]){const c=s[o][l];if(c instanceof y){const u=c.data.length,p=u>0?c.data[u-1]:void 0;a[o][l]={len:u,lastVal:p}}}}return a};if(r.main=n(e),e.lctx){const s=[];e.lctx.forEach(a=>s.push(n(a))),r.lctx=s}return r.resultLength=this._getResultLength(e.result),r.dataLength=e.data.close?.data?.length??0,r}_restoreVarState(e,i){if(!i)return;const r=["const","var","let","params"],n=(s,a)=>{for(const o of r)if(!(!a[o]||!s[o]))for(const l in a[o]){const 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(n(e,i.main),e.lctx&&i.lctx){let s=0;e.lctx.forEach(a=>{i.lctx[s]&&n(a,i.lctx[s]),s++})}}_initializeContext(e,i={},r=!1){const n=new xn({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:i});return n.pine.syminfo=this._syminfo,this._chartTimezone&&(n.chartTimezone=this._chartTimezone),n.viewportLeft=this._viewportLeft,n.viewportRight=this._viewportRight,n.__maxLoops=this._maxLoops,n._alertMode=this._alertMode,n._propOverrides=this._currentIndicator?.getRuntimePropOverrides()??{},n.pineTSCode=e,n.isSecondaryContext=r,n.data.close=new y([]),n.data.open=new y([]),n.data.high=new y([]),n.data.low=new y([]),n.data.volume=new y([]),n.data.hl2=new y([]),n.data.hlc3=new y([]),n.data.ohlc4=new y([]),n.data.hlcc4=new y([]),n.data.openTime=new y([]),n.data.closeTime=new y([]),n.length=this.data.length,n}async _executeIterations(e,i,r,n){const s=["const","var","let","params"];for(let a=r;a<n;a++){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&&(xp(e),Np(e),Cp(e),Ip(e));const o=await i(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(const c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();const l=c=>{for(let u of s)if(c[u])for(let p in c[u]){const h=c[u][p];if(h instanceof y){const f=h.get(0);h.data.push(f)}else if(Array.isArray(h)){const f=h[h.length-1];h.push(f)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}}}const zn={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},yi={"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},vg={"1S":{periodType:"second",multiplier:1},"5S":{periodType:"second",multiplier:5},"10S":{periodType:"second",multiplier:10},"15S":{periodType:"second",multiplier:15},"30S":{periodType:"second",multiplier:30},1:{periodType:"minute",multiplier:1},3:{periodType:"minute",multiplier:3},5:{periodType:"minute",multiplier:5},15:{periodType:"minute",multiplier:15},30:{periodType:"minute",multiplier:30},45:{periodType:"minute",multiplier:45},60:{periodType:"hour",multiplier:1},120:{periodType:"hour",multiplier:2},180:{periodType:"hour",multiplier:3},240:{periodType:"hour",multiplier:4},D:{periodType:"day",multiplier:1},W:{periodType:"week",multiplier:1},M:{periodType:"month",multiplier:1}};function _i(t,e,i=1){if(e==="month"){const n=new Date(t);return Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+i,1,n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds())}const r={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+i*r[e]}function lt(t,e,i){const[r,n,s]=t.split("-").map(Number),[a,o]=e.split(":").map(Number),l=Date.UTC(r,n-1,s,a,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:i,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(v=>v.type===b).value,10);let p=u("year"),h=u("month"),f=u("day"),d=u("hour");d===24&&(d=0);let m=u("minute");const x=Date.UTC(p,h-1,f,d,m,0,0)-l;return l-x}function Kn(t,e,i,r,n=1){if(e==="24x7")return _i(t,r,n);const s=e.split("-")[1];if(!s||s.length!==4)return _i(t,r,n);const a=s.slice(0,2),o=s.slice(2,4),l=`${a}:${o}`,c=Hn(t,i);if(r==="second"||r==="minute"||r==="hour"){const u=t+n*{second:1e3,minute:6e4,hour:36e5}[r],p=lt(c,l,i);return Math.min(u,p)}if(r==="day")return lt(c,l,i);if(r==="week"){const u=new Date(t).getUTCDay(),p=u<=5?5-u:5-u+7,h=t+p*864e5,f=Hn(h,i);return lt(f,l,i)}if(r==="month"){const u=new Date(t),p=u.getUTCFullYear(),h=u.getUTCMonth()+n,f=new Date(Date.UTC(p,h,1)),d=new Date(f.getTime()-864e5);for(;d.getUTCDay()===0||d.getUTCDay()===6;)d.setUTCDate(d.getUTCDate()-1);const m=d.toISOString().split("T")[0];return lt(m,l,i)}return _i(t,r,n)}function Hn(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function B_(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)}const F_=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function W_(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;const i=yi[t];if(!i)return null;const r=F_.filter(n=>n!=="W"&&n!=="M"&&e.has(n)&&yi[n]<i&&i%yi[n]===0);return r.length===0?null:r[r.length-1]}function Va(t,e){if(t==="W"||t==="M")return 1/0;const i=yi[t],r=yi[e];return!i||!r||r===0?1/0:i/r}function U_(t,e,i){if(t.length===0)return[];if(e==="W")return z_(t);if(e==="M")return K_(t);const r=Va(e,i);return q_(t,r)}function q_(t,e){if(t.length===0)return[];const i=[];let r=[t[0]];const n=H_(t),s=n>0?n*1.5:0;for(let a=1;a<t.length;a++){const o=t[a].openTime-t[a-1].openTime;(s>0&&o>s||r.length>=e)&&(i.push(Yi(r)),r=[]),r.push(t[a])}return r.length>0&&i.push(Yi(r)),i}function z_(t){const e=[];let i=[],r="";for(const n of t){const s=G_(n.openTime);s!==r&&i.length>0&&(e.push(i),i=[]),r=s,i.push(n)}return i.length>0&&e.push(i),e.map(Yi)}function K_(t){const e=[];let i=[],r="";for(const n of t){const s=new Date(n.openTime),a=`${s.getUTCFullYear()}-${s.getUTCMonth()}`;a!==r&&i.length>0&&(e.push(i),i=[]),r=a,i.push(n)}return i.length>0&&e.push(i),e.map(Yi)}function Yi(t){const e=t[0],i=t[t.length-1];let r=e.high,n=e.low,s=0,a=0,o=0,l=0,c=0;for(let u=0;u<t.length;u++){const p=t[u];p.high>r&&(r=p.high),p.low<n&&(n=p.low),s+=p.volume,a+=p.quoteAssetVolume,o+=p.numberOfTrades,l+=p.takerBuyBaseAssetVolume,c+=p.takerBuyQuoteAssetVolume}return{openTime:e.openTime,open:e.open,high:r,low:n,close:i.close,volume:s,closeTime:i.closeTime,quoteAssetVolume:a,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function H_(t){if(t.length<2)return 0;const e=Math.min(t.length-1,20);let i=1/0;for(let r=0;r<e;r++){const n=t[r+1].openTime-t[r].openTime;n>0&&n<i&&(i=n)}return i===1/0?0:i}function G_(t){const e=new Date(t),i=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-i);const r=new Date(Date.UTC(e.getUTCFullYear(),0,1)),n=Math.ceil(((e.getTime()-r.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${n}`}var Y_=Object.defineProperty,X_=(t,e,i)=>e in t?Y_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ai=(t,e,i)=>X_(t,typeof e!="symbol"?e+"":e,i);const Pi={"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 Z_(t){if(Pi[t]!==void 0)return Pi[t];const e=t.toLowerCase();return Pi[e]!==void 0?Pi[e]:/^\d+$/.test(t)?t:/^\d+S$/i.test(t)?t.toUpperCase():t}class en{constructor(e){Ai(this,"_configured"),Ai(this,"_requiresApiKey"),Ai(this,"_providerName"),Ai(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){B_(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,i,r,n,s){const a=Z_(i),o=this.getSupportedTimeframes();if(o.has(a))return this._getMarketDataNative(e,a,r,n,s);const l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:W_(a,o);if(!c)return console.error(`${this._providerName}: Timeframe '${i}' is not supported and no valid sub-timeframe found for aggregation.`),[];const u=this._computeSubLimit(a,c,r),p=await this._getMarketDataNative(e,c,u,n,s);if(p.length===0)return[];const h=U_(p,a,c);return r&&r>0&&h.length>r?h.slice(h.length-r):h}_computeSubLimit(e,i,r){if(!r)return;const n=Va(e,i);return n===1/0?e==="W"?r*7+14:e==="M"?r*31+31:r*30:Math.ceil(r*n)+Math.ceil(n)}}var Q_=Object.defineProperty,J_=(t,e,i)=>e in t?Q_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Xi=(t,e,i)=>J_(t,typeof e!="symbol"?e+"":e,i);const mr="https://api.binance.com/api/v3",Gn="https://api.binance.us/api/v3",Di={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"};class eg{constructor(e=300*1e3){Xi(this,"cache"),Xi(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([i,r])=>r!==void 0).map(([i,r])=>`${i}:${r}`).join("|")}get(e){const i=this.generateKey(e),r=this.cache.get(i);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(i),null):r.data:null}set(e,i){const r=this.generateKey(e);this.cache.set(r,{data:i,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const e=Date.now();for(const[i,r]of this.cache.entries())e-r.timestamp>this.cacheDuration&&this.cache.delete(i)}}class tg extends en{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),Xi(this,"cacheManager"),Xi(this,"activeApiUrl",null),this.cacheManager=new eg(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${mr}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=mr,this.activeApiUrl}catch{}try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${Gn}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=Gn,this.activeApiUrl}catch{}return mr}async _fetchRawChunk(e,i,r,n,s){const a=Di[i.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${i}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${a}`;r&&(o+=`&limit=${Math.min(r,1e3)}`),n&&(o+=`&startTime=${n}`),s&&(o+=`&endTime=${s}`);const 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,i,r,n){try{const s=Di[i.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${i}`),[];let a=[],o=r;const l=n,c=zn[s];if(!c)return console.error(`Duration not defined for interval: ${s}`),[];for(;o<l;){const u=Math.min(o+1e3*c,l),p=await this._fetchRawChunk(e,i,1e3,o,u);if(p.length===0)break;a=a.concat(p),o=p[p.length-1].closeTime+1}return this.normalizeCloseTime(a),a}catch(s){return console.error("Error in getMarketDataInterval:",s),[]}}async getMarketDataBackwards(e,i,r,n){let s=r,a=[],o=n,l=0;const c=Math.ceil(r/1e3)+5;for(;s>0&&l<c;){l++;const u=Math.min(s,1e3),p=await this._fetchRawChunk(e,i,u,void 0,o);if(p.length===0||(a=p.concat(a),s-=p.length,o=p[0].openTime-1,p.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,i,r,n,s){try{const a=s!==void 0,o={tickerId:e,timeframe:i,limit:r,sDate:n,eDate:s};if(a){const c=this.cacheManager.get(o);if(c)return c}if(!Di[i.toUpperCase()])return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,n,s)){if(n&&s){const c=await this.getMarketDataInterval(e,i,n,s),u=r?c.slice(0,r):c;return this.cacheManager.set(o,u),u}else if(r&&r>1e3){const c=await this.getMarketDataBackwards(e,i,r,s);return this.cacheManager.set(o,c),c}}const l=await this._fetchRawChunk(e,i,r,n,s);return this.normalizeCloseTime(l),a&&this.cacheManager.set(o,l),l}catch(a){return console.error("Error in binance.klines:",a),[]}}shouldPaginate(e,i,r,n){if(i&&i>1e3)return!0;if(r&&n){const s=Di[e.toUpperCase()],a=zn[s];if(a)return Math.ceil((n-r)/a)>1e3}return!1}async getSymbolInfo(e){try{let i="crypto",r=await this.getBaseUrl(),n=e,s="";e.endsWith(".P")?(i="futures",n=e.replace(".P",""),r="https://fapi.binance.com/fapi/v1",s="Perpetual"):e.includes("_")&&(i="futures",n=e,r="https://dapi.binance.com/dapi/v1",s="Delivery");const a=i==="crypto"?`${r}/exchangeInfo?symbol=${n}`:`${r}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;const c=i==="futures"?l.find(w=>w.symbol===n):l[0];if(!c)return console.error(`Symbol ${n} not found in exchange info`),null;const u=c.filters?.find(w=>w.filterType==="PRICE_FILTER"),p=c.filters?.find(w=>w.filterType==="LOT_SIZE"),h=u?parseFloat(u.tickSize):.01,f=p?parseFloat(p.minQty):0,d=Math.round(1/h),m=c.baseAsset,x=c.quoteAsset,b=s?` ${s}`:"",v=`${m} / ${x}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:m,description:v,type:i,main_tickerid:`BINANCE:${e}`,current_contract:s,isin:"",basecurrency:m,currency:x,timezone:"Etc/UTC",country:"",mintick:h,pricescale:d,minmove:1,pointvalue:c.contractSize||1,mincontract:f,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(i){return console.error("Error in binance.exchangeInfo:",i),null}}}var ig=Object.defineProperty,rg=(t,e,i)=>e in t?ig(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,oi=(t,e,i)=>rg(t,typeof e!="symbol"?e+"":e,i);const ng="https://financialmodelingprep.com",Yn=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"]),Xn={"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"}},Zn={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"},Qn={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"},sg={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}};class ag extends en{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),oi(this,"_apiKey",null),oi(this,"_baseUrl",ng),oi(this,"_profileCache",new Map),oi(this,"_symbolInfoCache",new Map),oi(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,i,r,n,s){this.ensureConfigured();try{const a=i.toUpperCase(),o=Xn[a]||Xn[i];if(!o)return console.error(`FMP: Unsupported timeframe: ${i}`),[];let l;if(o.type==="intraday"?l=await this._fetchIntradayData(e,o.endpoint,o.interval,n,s,r):l=await this._fetchDailyData(e,n,s,r),l.length>0&&!this._mintickCache.has(e)){const 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,i,r,n){let s=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;i&&(s+=`&from=${this._msToDateStr(i)}`),r&&(s+=`&to=${this._msToDateStr(r)}`);const a=await fetch(s);if(!a.ok){const p=await a.text();throw new Error(`FMP HTTP ${a.status}: ${p}`)}const o=await a.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();const l=n&&n>0&&n<o.length?o.slice(o.length-n):o,{session:c,timezone:u}=await this._resolveSessionInfo(e);return l.map(p=>{const h=this._dateStrToMs(p.date),f=Kn(h,c,u,"day");return{openTime:h,open:p.open,high:p.high,low:p.low,close:p.close,volume:p.volume,closeTime:f,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,i,r,n,s,a){let o=`${this._baseUrl}${i}?symbol=${e}&apikey=${this._apiKey}`;n&&(o+=`&from=${this._msToDateStr(n)}`),s&&(o+=`&to=${this._msToDateStr(s)}`);const l=await fetch(o);if(!l.ok){const m=await l.text();if(l.status===403||m.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${r}) 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}`)}const c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();const u=a&&a>0&&a<c.length?c.slice(c.length-a):c,{periodType:p,multiplier:h}=sg[r]||{periodType:"minute",multiplier:1},{session:f,timezone:d}=await this._resolveSessionInfo(e);return u.map(m=>{const x=this._dateTimeStrToMs(m.date),b=Kn(x,f,d,p,h);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(),this._symbolInfoCache.has(e))return this._symbolInfoCache.get(e);try{const i=await this._fetchProfile(e);let r="stock";i?.isEtf?r="etf":i?.isFund?r="fund":this._isForex(e)?r="forex":this._isCrypto(e)&&(r="crypto");const n=i?.exchange||(r==="crypto"?"CRYPTO":r==="forex"?"FX":""),s=r==="crypto"||r==="forex"?"Etc/UTC":Zn[n]||"America/New_York",a=r==="crypto"?"24x7":r==="forex"?"0000-0000":Qn[n]||"0930-1600",o=i?.currency||(this._isForex(e)?e.slice(3,6):"USD"),l=this._isForex(e)?e.slice(0,3):i?.currency||"USD",c=this._mintickCache.get(e)??.01,u=Math.round(1/c),p=Math.round(c*u),h={ticker:i?.symbol||e,tickerid:`${n}:${i?.symbol||e}`,prefix:n,root:i?.symbol||e,description:i?.companyName||e,type:r,main_tickerid:`${n}:${i?.symbol||e}`,current_contract:"",isin:i?.isin||"",basecurrency:l,currency:o,timezone:s,country:i?.country||"",mintick:c,pricescale:u,minmove:p,pointvalue:1,mincontract:0,session:a,volumetype:"base",expiration_date:0,employees:i&&parseInt(i.fullTimeEmployees)||0,industry:i?.industry||"",sector:i?.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,h),h}catch(i){return console.error("Error in FMPProvider.getSymbolInfo:",i),null}}_estimateMintick(e){const i=[];for(let o=0;o<e.length;o++){const l=e[o],c=Math.abs(l.close-l.open),u=Math.abs(l.high-l.low);if(c>0&&i.push(c),u>0&&i.push(u),o>0){const p=Math.abs(l.close-e[o-1].close);p>0&&i.push(p)}}if(i.length===0)return;const r=Math.min(...i),n=Math.floor(Math.log10(r)),s=r/10**n,a=(Math.floor(s+1e-12)<5?1:10)*10**n;return a>=1?.01:a}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);const i=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,r=await fetch(i);if(!r.ok)return null;const n=await r.json();if(!Array.isArray(n)||n.length===0)return null;const s=n[0];return this._profileCache.set(e,s),s}async _resolveSessionInfo(e){try{const i=await this._fetchProfile(e);if(i){const r=i.exchange||"",n=this._isCrypto(e),s=n?"Etc/UTC":Zn[r]||"America/New_York";return{session:n?"24x7":Qn[r]||"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)&&Yn.has(e.slice(0,3))&&Yn.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}}var og=Object.defineProperty,lg=(t,e,i)=>e in t?og(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Dt=(t,e,i)=>lg(t,typeof e!="symbol"?e+"":e,i);const cg="https://data.alpaca.markets",ug="https://paper-api.alpaca.markets/v2",hg="https://api.alpaca.markets/v2",yr=1e4,Jn={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"},pg={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"},fg={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},dg={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"};class mg extends en{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),Dt(this,"_apiKey",null),Dt(this,"_apiSecret",null),Dt(this,"_dataUrl",cg),Dt(this,"_tradingUrl",ug),Dt(this,"_feed",null),Dt(this,"_assetCache",new Map),Dt(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=hg)}_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,i,r,n,s){this.ensureConfigured();try{const a=this._resolveTimeframe(i);if(!a)return console.error(`Alpaca: Unsupported timeframe: ${i}`),[];const o=this._isCrypto(e),l=await this._fetchAllBars(e,a,o,n,s,r);if(l.length===0)return[];const{periodType:c,multiplier:u}=this._parseAlpacaTimeframe(a);if(o)return this._convertBarsCrypto(l,c,u);const p=l[0].t.slice(0,10),h=l[l.length-1].t.slice(0,10),f=this._addDaysToDate(h,40);return await this._ensureCalendar(p,f),this._convertBarsStock(l,c,u)}catch(a){return console.error("Error in AlpacaProvider.getMarketData:",a),[]}}async _fetchAllBars(e,i,r,n,s,a){const o=[];let l=null;const c=a||1/0,u=Math.min(a||yr,yr);do{const p=this._buildBarsUrl(e,i,r,n,s,u,l),h=await fetch(p,{headers:this._headers()});if(!h.ok){const m=await h.text();throw new Error(`Alpaca HTTP ${h.status}: ${m}`)}const f=await h.json(),d=Object.keys(f.bars||{})[0];if(!d||!f.bars[d]||(o.push(...f.bars[d]),l=f.next_page_token,o.length>=c))break}while(l);return a&&a>0&&o.length>a?o.slice(0,a):o}_buildBarsUrl(e,i,r,n,s,a,o){const l=r?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",i),c.set("sort","asc"),n&&c.set("start",new Date(n).toISOString()),s&&c.set("end",new Date(s).toISOString()),a&&c.set("limit",String(Math.min(a,yr))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured();try{const i=await this._fetchAsset(e);if(!i)return console.error(`Alpaca: Symbol ${e} not found`),null;const r=i.exchange||"",n=i.class==="crypto",s=n?"Etc/UTC":pg[r]||"America/New_York",a=n?"24x7":fg[r]||"0930-1600";let o="stock";n&&(o="crypto");const l=n&&e.split("/")[1]||"USD",c=n?e.split("/")[0]||e:l,u=i.price_increment?parseFloat(i.price_increment):.01,p=Math.round(1/u);return{ticker:i.symbol,tickerid:`${r}:${i.symbol}`,prefix:r,root:n?e.split("/")[0]:i.symbol,description:i.name||i.symbol,type:o,main_tickerid:`${r}:${i.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:s,country:n?"":"US",mintick:u,pricescale:p,minmove:1,pointvalue:1,mincontract:i.min_order_size?parseFloat(i.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(i){return console.error("Error in AlpacaProvider.getSymbolInfo:",i),null}}_convertBarsCrypto(e,i,r){return e.map((n,s,a)=>{const o=new Date(n.t).getTime(),l=s<a.length-1?new Date(a[s+1].t).getTime():_i(o,i,r);return this._toKline(n,o,l)})}_convertBarsStock(e,i,r){const n="America/New_York";return e.map(s=>{const a=new Date(s.t).getTime(),o=s.t.slice(0,10);let l;if(i==="day"){const c=this._calendarCache.get(o),u=c?c.close:"16:00";l=lt(o,u,n)}else if(i==="minute"||i==="hour"){const c=a+r*{minute:6e4,hour:36e5}[i],u=this._calendarCache.get(o),p=u?u.close:"16:00",h=lt(o,p,n);l=Math.min(c,h)}else i==="week"?l=this._weeklyCloseFromCalendar(o,n):i==="month"?l=this._monthlyCloseFromCalendar(o,n):l=_i(a,i,r);return this._toKline(s,a,l)})}_toKline(e,i,r){return{openTime:i,open:e.o,high:e.h,low:e.l,close:e.c,volume:e.v,closeTime:r,quoteAssetVolume:0,numberOfTrades:e.n,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}}_weeklyCloseFromCalendar(e,i){const r=new Date(e+"T00:00:00Z"),n=r.getUTCDay(),s=n<=5?5-n:5-n+7;for(let l=s;l>=0;l--){const c=r.getTime()+l*864e5,u=new Date(c).toISOString().split("T")[0],p=this._calendarCache.get(u);if(p)return lt(u,p.close,i)}const a=r.getTime()+s*864e5,o=new Date(a).toISOString().split("T")[0];return lt(o,"16:00",i)}_monthlyCloseFromCalendar(e,i){const[r,n]=e.split("-").map(Number),s=new Date(Date.UTC(r,n,0)).getUTCDate();for(let o=s;o>=1;o--){const l=`${r}-${String(n).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return lt(l,c.close,i)}const a=new Date(Date.UTC(r,n,0));for(;a.getUTCDay()===0||a.getUTCDay()===6;)a.setUTCDate(a.getUTCDate()-1);return lt(a.toISOString().split("T")[0],"16:00",i)}async _ensureCalendar(e,i){if(this._calendarCache.has(e)&&this._calendarCache.has(i))return;const r=`${this._tradingUrl}/calendar?start=${e}&end=${i}`,n=await fetch(r,{headers:this._headers()});if(!n.ok){console.warn(`Alpaca calendar API returned ${n.status}, falling back to defaults`);return}const s=await n.json();for(const a of s)this._calendarCache.set(a.date,a)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);const i=encodeURIComponent(e),r=`${this._tradingUrl}/assets/${i}`,n=await fetch(r,{headers:this._headers()});if(!n.ok)return null;const s=await n.json();return this._assetCache.set(e,s),s}_parseAlpacaTimeframe(e){const i=e.match(/^(\d+)(Min|Hour|Day|Week|Month)$/);if(i){const r=parseInt(i[1],10),n=dg[i[2]];if(n)return{periodType:n,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return Jn[e.toUpperCase()]||Jn[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,i){const r=new Date(e+"T00:00:00Z");return r.setUTCDate(r.getUTCDate()+i),r.toISOString().split("T")[0]}}class yg{async getMarketData(){return[]}}const _g=typeof process<"u"&&process.versions&&process.versions.node;let Zi=null;if(_g)try{Zi=new yg}catch{Zi=null}const wg={Binance:new tg,FMP:new ag,Alpaca:new mg,...Zi?{Mock:Zi}:{}};var gg=Object.defineProperty,xg=(t,e,i)=>e in t?gg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,bg=(t,e,i)=>xg(t,typeof e!="symbol"?e+"":e,i);class Sg extends Error{constructor(e,i){super(e),bg(this,"method"),this.name="PineRuntimeError",this.method=i}}export{mg as AlpacaProvider,en as BaseProvider,tg as BinanceProvider,xn as Context,ag as FMPProvider,Ma as INDICATOR_PROPS,bi as Indicator,Sg as PineRuntimeError,Jr as PineTS,wg as Provider,Ra as STRATEGY_PROPS,vg as TIMEFRAME_PERIOD_INFO,yi as TIMEFRAME_SECONDS,U_ as aggregateCandles,_i as computeNextPeriodStart,Kn as computeSessionClose,Va as getAggregationRatio,lt as localTimeToUTC,T_ as propsForDeclaration,W_ as selectSubTimeframe};
120
+ `);const r=e.body;if(r&&r.body&&r.body.length>0){const n=r.body.length-1,a=r.body[n];a.type==="ExpressionStatement"&&(r.body[n]={type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:{type:"Identifier",name:"__result"},right:a.expression},_line:a._line})}i==="for"?this.generateForStatement(e):this.generateWhileStatement(e),this.write(this.indentStr.repeat(this.indent)),this.write(`return __result;
121
+ `),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSequenceExpression(e){this.write("(");for(let i=0;i<e.expressions.length;i++)this.generateExpression(e.expressions[i]),i<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 Pa(t){const e=/^\s*\/\/\s*@version\s*=\s*(\d+)\s*$/im,i=t.match(e);return i&&i[1]?parseInt(i[1],10):null}function rn(t,e={}){const i=Pa(t);if(i===null)return{success:!1,version:null,error:"Pine Script version not found. Please add //@version=X comment to your script."};if(i<5)return{success:!1,version:i,error:`Pine Script version ${i} is not supported. Only version 5 and above are supported.`};try{const r=new Qy(t).tokenize(),n=new u_(r).parse(),a={...e,sourceCode:t},s=new d_(a).generate(n);return{success:!0,version:i,code:s,ast:n,tokens:r}}catch(r){return{success:!1,version:i,error:r.message,stack:r.stack}}}const m_=new Set(["security_lower_tf","security"]),Ma=new Set(["type","loc","start","end","range","parent","leadingComments","trailingComments"]);function y_(t){if(!t||t.type!=="CallExpression")return!1;const e=t.callee;return!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="request"||e.property?.type!=="Identifier"?!1:m_.has(e.property.name)}function __(t){const e=t?.arguments?.[2];return e?.type==="Identifier"&&typeof e.name=="string"?e.name:null}function g_(t){const e=[],i=new WeakSet;function r(n,a){if(!n||typeof n!="object"||i.has(n))return;i.add(n);const s=a.concat([n]);y_(n)&&e.push({call:n,path:s});for(const o of Object.keys(n)){if(Ma.has(o))continue;const l=n[o];if(Array.isArray(l))for(const c of l)r(c,s);else l&&typeof l=="object"&&r(l,s)}}return r(t,[]),e}function jr(t){return t?t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="FunctionDeclaration":!1}function lt(t,e,i){if(i>=e.length-1)return t;const r=e[i+1];switch(t.type){case"BlockStatement":{const n=t.body.indexOf(r);if(n<0)return t;const a=t.body.slice(0,n);return a.push(lt(r,e,i+1)),{...t,body:a}}case"IfStatement":return r===t.test?{...t,test:lt(r,e,i+1),consequent:{type:"BlockStatement",body:[]},alternate:null}:r===t.consequent?{...t,consequent:lt(r,e,i+1),alternate:null}:r===t.alternate?{...t,alternate:lt(r,e,i+1)}:t;case"ForStatement":case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return r===t.body?{...t,body:lt(r,e,i+1)}:t;case"SwitchStatement":{const n=t.cases.indexOf(r);if(n>=0){const a=t.cases.slice(0,n);return a.push(lt(r,e,i+1)),{...t,cases:a}}return t}case"SwitchCase":{const n=t.consequent.indexOf(r);if(n>=0){const a=t.consequent.slice(0,n);return a.push(lt(r,e,i+1)),{...t,consequent:a}}return t}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":return r===t.body?{...t,body:lt(r,e,i+1)}:t;default:return t}}function x_(t){if(!t||t.type!=="CallExpression")return null;const 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;const i=t.arguments?.[0];return i?.type==="Identifier"&&typeof i.name=="string"?i.name:null}function b_(t,e,i){const r=t.body||[];for(let n=0;n<r.length;n++){const a=r[n];if(a!==i&&v_(a,e))return n}return-1}function v_(t,e){let i=!1;const r=new WeakSet;function n(a){if(!(i||!a||typeof a!="object")&&!r.has(a)){if(r.add(a),x_(a)===e){i=!0;return}for(const s of Object.keys(a)){if(Ma.has(s))continue;const o=a[s];if(Array.isArray(o))for(const l of o)n(l);else o&&typeof o=="object"&&n(o)}}}return n(t),i}function w_(t,e){let i=-1;for(let h=1;h<e.length;h++)if(jr(e[h])){i=h;break}if(i<0)return null;const r=e[i];for(let h=i+1;h<e.length;h++)if(jr(e[h]))return null;if(r.type!=="FunctionDeclaration"||!r.id?.name)return null;const n=r.id.name,a=e.slice(i),s=lt(r,a,0),o=b_(t,n,r);if(o<0)return null;const l=t.body||[],c=l.indexOf(r);if(c<0)return null;const u=[],p=Math.max(o,c);for(let h=0;h<=p;h++){const f=l[h];u.push(f===r?s:f)}return u}function S_(t,e){const i={type:"Program",sourceType:"module",body:[{type:"ExpressionStatement",expression:{type:"ArrowFunctionExpression",async:!!t.async,params:t.params,body:{type:"BlockStatement",body:e}}}]},r=`var _r = ${Zr(i)}
122
+ ; return _r;`;return new Function("",r)()}function E_(t){const e={};if(!t||t.type!=="Program"||!Array.isArray(t.body)||t.body.length===0)return e;const i=t.body[0];let r=null;if(i.type==="ExpressionStatement"){const a=i.expression;a&&(a.type==="ArrowFunctionExpression"||a.type==="FunctionExpression")&&(r=a)}else i.type==="FunctionDeclaration"&&(r=i);if(!r||r.body?.type!=="BlockStatement")return e;const n=g_(r.body);for(const{call:a,path:s}of n){const o=__(a);if(!o||o in e)continue;const l=s.some(p=>jr(p));let c=null;if(l)c=w_(r.body,s);else{const p=lt(r.body,s,0);c=p&&p.body?p.body:[]}if(!c||c.length===0)continue;const u=S_(r,c);e[o]=u}return e}function N_(t){if(typeof t=="function")return t.toString();{const e=Pa(t);if(e===null)return t;if(e>=5){const i=rn(t);if(i.success)return i.code;throw new Error(`Failed to transpile Pine Script version ${e}: ${i.error}`)}else throw new Error(`Unsupported Pine Script version ${e}. Only version 5 and above are supported.`)}}function C_(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});const{debug:i}=e;let r=N_(t);r=Py(r);const n=i?r.split(`
123
+ `):[],a=Xr(r,{ecmaVersion:"latest",sourceType:"module",locations:i});My(a),ky(a),Iy(a);const s=new xy;Oy(a,s),Dy(a,s);const o=Vy(a,s)||"";if(zy(a,s,o,e,n),qy(a),Uy(a),a.type==="Program"&&a.body.length>0){const f=a.body[0],d=f?.expression||f;d.body?.type==="BlockStatement"&&d.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}}}]})}const l=fy||Qr||void 0,c=Object.assign({},l,{LineComment(f,d){d.write("//"+f.value)}}),u=Zr(a,{generator:c,comments:i}),p=typeof process<"u"&&process?.env?.PINETS_DISABLE_LTF_SLICING==="1"?{}:E_(a),h=new Function("",`var _r = ${u}
124
+ ; return _r;`)(this);return p&&Object.keys(p).length>0&&(h._ltfSlices=p),h}const Da=new Set(["open","high","low","close","hl2","hlc3","ohlc4","hlcc4","volume"]),Kn={"":["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"]},I_={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 k_(t){if(typeof t!="string")return[];const e=rn(t);if(!e.success||!e.ast)return[];const i=T_(e.ast),r=A_(e.ast),n=[],a=new Set;return gt(e.ast,s=>{const o=P_(s,i,r);if(o){if(o.varId!==void 0){if(a.has(o.varId)){console.warn(`[Indicator] duplicate input variable "${o.varId}" \u2014 first declaration wins for .input access`);return}a.add(o.varId)}n.push(o)}}),n}function T_(t){const e=new Map;return gt(t,i=>{if(i.type==="VariableDeclaration")for(const r of i.declarations??[]){const n=r?.id?.name,a=r?.init;if(!n||!a||a.type!=="ObjectExpression"||!(a.properties??[]).every(s=>s.value?.type==="Literal"&&typeof s.value.value=="string")||a.properties.length===0)return;for(const s of a.properties)e.set(`${n}.${s.key.name}`,s.value.value)}}),e}function A_(t){const e=new Map;return gt(t,i=>{if(i.type==="VariableDeclaration")for(const r of i.declarations??[])r?.id?.type==="Identifier"&&r.init&&!e.has(r.id.name)&&e.set(r.id.name,r.init)}),e}function P_(t,e,i){if(t.type!=="VariableDeclaration")return null;for(const r of t.declarations??[]){const n=r?.init;if(!n||n.type!=="CallExpression")continue;const a=n.callee;let s=null;if(a?.type==="MemberExpression"&&a.object?.type==="Identifier"&&a.object.name==="input"&&a.property?.type==="Identifier"?s=a.property.name:a?.type==="Identifier"&&a.name==="input"&&(s=""),s===null||s!==""&&!(s==="int"||s==="float")&&!(s in Kn))continue;const o=n.arguments??[],l=o[o.length-1],c=l?.type==="ObjectExpression",u=c?o.slice(0,-1):o.slice(),p=c?l.properties??[]:[],h={};s==="int"||s==="float"?M_(u,p,h):Ra(Kn[s],u,h);for(const x of p)x.type!=="Property"||!x.key?.name||(h[x.key.name]=x.value);const f={};for(const x of Object.keys(h))f[x]=Fi(h[x],e,i);const d=s===""?D_(f.defval):I_[s];if(!d)continue;const m={type:d,defval:f.defval};return r.id?.type==="Identifier"&&typeof r.id.name=="string"&&(m.varId=r.id.name),f.title!==void 0&&(m.title=String(f.title)),f.tooltip!==void 0&&(m.tooltip=String(f.tooltip)),f.group!==void 0&&(m.group=String(f.group)),f.inline!==void 0&&(m.inline=String(f.inline)),f.confirm!==void 0&&(m.confirm=!!f.confirm),f.active!==void 0&&(m.active=!!f.active),f.display!==void 0&&(m.display=R_(f.display)),f.options!==void 0&&Array.isArray(f.options)&&(m.options=f.options),typeof f.minval=="number"&&(m.minval=f.minval),typeof f.maxval=="number"&&(m.maxval=f.maxval),typeof f.step=="number"&&(m.step=f.step),m}return null}function M_(t,e,i){const r=new Set(e.map(n=>n.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"];Ra(r,t,i)}function Ra(t,e,i){for(let r=0;r<e.length&&r<t.length;r++){const n=t[r];i[n]===void 0&&(i[n]=e[r])}}function Fi(t,e,i,r=new Set){if(t!=null)switch(t.type){case"Literal":return t.value;case"Identifier":if(Da.has(t.name))return t.name;if(i?.has(t.name)&&!r.has(t.name)){r.add(t.name);const n=Fi(i.get(t.name),e,i,r);if(r.delete(t.name),n!==void 0)return n}return t.name;case"MemberExpression":{const n=t.object?.type==="Identifier"?t.object.name:null,a=t.property?.type==="Identifier"?t.property.name:null;if(n&&a){const s=`${n}.${a}`;return e.has(s)?e.get(s):n==="display"?a:s}return}case"CallExpression":{const n=t.callee;if(n?.type==="MemberExpression"&&n.object?.type==="Identifier"&&n.object.name==="color"&&n.property?.type==="Identifier"){const a=n.property.name,s=(t.arguments??[]).map(l=>Fi(l,e,i,r)),o=l=>Math.max(0,Math.min(1,l));if(a==="rgb"){const[l,c,u,p]=s;if(typeof l=="number"&&typeof c=="number"&&typeof u=="number"){const h=o(1-(typeof p=="number"?p:0)/100);return wr(l,c,u,h)}}else if(a==="new"){const l=Ts(s[0]),c=s[1];if(l&&typeof c=="number")return wr(l[0],l[1],l[2],o(1-c/100))}}return}case"ArrayExpression":return(t.elements??[]).map(n=>Fi(n,e,i,r));case"UnaryExpression":return t.operator==="-"&&t.argument?.type==="Literal"&&typeof t.argument.value=="number"?-t.argument.value:void 0;default:return}}function D_(t){return typeof t=="boolean"?"bool":typeof t=="number"?Number.isInteger(t)?"int":"float":typeof t=="string"?Da.has(t)?"source":t.startsWith("#")?"color":"string":null}function R_(t){if(typeof t!="string")return;const e=t.startsWith("display.")?t.slice(8):t;if(e==="none"||e==="data_window"||e==="status_line"||e==="all")return e}function gt(t,e){if(!(!t||typeof t!="object")){if(e(t),Array.isArray(t.body))for(const i of t.body)gt(i,e);else t.body&&gt(t.body,e);if(Array.isArray(t.consequent))for(const i of t.consequent)gt(i,e);else t.consequent&&gt(t.consequent,e);if(t.alternate&&gt(t.alternate,e),Array.isArray(t.declarations))for(const i of t.declarations)gt(i,e)}}function Oa(t,e,i,r,n="key"){const a={},s=new Map;for(const o of t)s.set(o.key,o),a[o.key]=r&&o.key in r?r[o.key]:o.defval;for(const o of t)for(const l of o.aliases??[])!l||s.has(l)||s.set(l,o);return{proxy:new Proxy(a,{get(o,l){if(typeof l=="symbol")return o[l];const c=s.get(l);return c?o[c.key]:o[l]},set(o,l,c){if(typeof l!="string")return!1;const u=s.get(l);if(!u)throw new Error(`[${e}] unknown ${n} "${l}". Known: ${[...s.keys()].join(", ")||"(none)"}`);return O_(u,c,e),o[u.key]=c,i?.(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"&&s.has(l)}}),values:a,entryByKey:s}}function O_(t,e,i){const r=t.key;switch(t.type){case"int":if(typeof e!="number"||!Number.isInteger(e))throw new TypeError(`[${i}] "${r}" expects an int; got ${Zt(e)}`);break;case"float":case"price":case"time":if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`[${i}] "${r}" expects a number; got ${Zt(e)}`);break;case"bool":if(typeof e!="boolean")throw new TypeError(`[${i}] "${r}" expects a boolean; got ${Zt(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(`[${i}] "${r}" expects a string; got ${Zt(e)}`);break}if(t.options&&!t.options.some(n=>$_(n,e)))throw new RangeError(`[${i}] "${r}" value ${Zt(e)} is not one of: ${t.options.map(Zt).join(", ")}`);if(typeof e=="number"){if(typeof t.minval=="number"&&e<t.minval)throw new RangeError(`[${i}] "${r}" value ${e} is below minval ${t.minval}`);if(typeof t.maxval=="number"&&e>t.maxval)throw new RangeError(`[${i}] "${r}" value ${e} is above maxval ${t.maxval}`)}}function $_(t,e){return t===e?!0:typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<1e-12:!1}function Zt(t){return t===null?"null":typeof t=="string"?JSON.stringify(t):String(t)}function V_(t,e){const i=new Map,r=[];for(const s of t){const o=s.varId??s.title;if(!o)continue;const l=s.title&&s.title!==o?[s.title]:void 0;i.set(o,s),r.push({key:o,type:s.type,defval:s.defval,options:s.options,minval:s.minval,maxval:s.maxval,aliases:l})}const{proxy:n,values:a}=Oa(r,"Indicator.input",e,void 0,"input key");return{proxy:n,values:a,metaByKey:i}}const $a=[{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}],Va=[...$a.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"}],ja=[...$a.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 j_(t){return t==="strategy"?ja:Va}function L_(t){return typeof t=="string"?B_(t):typeof t=="function"?F_(t):{type:null,args:{}}}function B_(t){const e=rn(t);if(!e.success||!e.ast)return{type:null,args:{}};let i=null;return Qi(e.ast,r=>{if(i||r.type!=="ExpressionStatement"&&r.type!=="VariableDeclaration")return;const n=r.type==="ExpressionStatement"?r.expression:r.declarations?.[0]?.init;if(!n||n.type!=="CallExpression")return;const a=n.callee;a?.type==="Identifier"&&(a.name!=="indicator"&&a.name!=="strategy"||(i={type:a.name,args:Ba(n.arguments??[],La(a.name))}))}),i??{type:null,args:{}}}function F_(t){let e;try{e=Xr(`(${t.toString()})`,{ecmaVersion:"latest"})}catch{return{type:null,args:{}}}let i=null;return Qi(e,r=>{if(i||r.type!=="CallExpression")return;const n=r.callee;n?.type==="Identifier"&&(n.name!=="indicator"&&n.name!=="strategy"||(i={type:n.name,args:Ba(r.arguments??[],La(n.name))}))}),i??{type:null,args:{}}}function La(t){return t==="strategy"?ja:Va}function Ba(t,e){const i={},r=t[t.length-1],n=r?.type==="ObjectExpression",a=n?t.slice(0,-1):t.slice();for(let s=0;s<a.length&&s<e.length;s++){const o=e[s].name;i[o]=Lr(a[s])}if(n)for(const s of r.properties??[])s.type!=="Property"||!s.key?.name||(i[s.key.name]=Lr(s.value));return i}function Lr(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(Lr);default:return}}function Qi(t,e){if(!(!t||typeof t!="object")){e(t);for(const i of Object.keys(t)){const r=t[i];if(!(i==="loc"||i==="range"||i==="start"||i==="end"))if(Array.isArray(r))for(const n of r)Qi(n,e);else r&&typeof r=="object"&&typeof r.type=="string"&&Qi(r,e)}}}function W_(t,e,i){const r=new Map,n=[];for(const o of t)r.set(o.name,o),o.mutable&&n.push({key:o.name,type:o.type,defval:o.defval,options:o.options,minval:o.minval,maxval:o.maxval});const{proxy:a,values:s}=Oa(n,"Indicator.prop",i,e);return{proxy:a,values:s,propByName:r}}var U_=Object.defineProperty,q_=(t,e,i)=>e in t?U_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Be=(t,e,i)=>q_(t,typeof e!="symbol"?e+"":e,i);class bi{constructor(e,i={}){Be(this,"source"),Be(this,"inputs"),Be(this,"_prepared",null),Be(this,"_inputMeta",null),Be(this,"_inputValues",{}),Be(this,"_explicitOverrides",new Set),Be(this,"_inputProxy",null),Be(this,"_propMeta",null),Be(this,"_propValues",{}),Be(this,"_propProxy",null),Be(this,"_declarationType",null),Be(this,"_sourcePropArgs",{}),Be(this,"_explicitPropOverrides",new Set),this.source=e,this.inputs=i,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 bi?e:new bi(e)}prepare(e={}){if(this._prepared)return this._prepared;const i=C_(this.source,{debug:!!e.debug,ln:e.ln}),r=z_(i),n=i._ltfSlices;return this._prepared={fn:i,inputs:this.getRuntimeInputs(),usesVisibleRange:r,ltfSlices:n},this._prepared}usesVisibleRange(){return this.prepare().usesVisibleRange}getRuntimeInputs(){const e={...this.inputs??{}};if(this._inputMeta)for(const i of this._explicitOverrides)e[i]=this._inputValues[i];return e}getInputsMeta(){return this._ensureInputsScanned(),this._inputMeta}getPropsMeta(){return this._ensurePropsScanned(),this._propMeta}getRuntimePropOverrides(){const e={};if(this._propMeta)for(const i of this._explicitPropOverrides)e[i]=this._propValues[i];return e}getDeclarationType(){return this._ensurePropsScanned(),this._declarationType}_ensureInputsScanned(){if(this._inputMeta)return;this._inputMeta=k_(this.source);for(const i of this._inputMeta)i.type==="color"&&i.defval!==void 0&&(i.defval=Pc(i.defval));const e=V_(this._inputMeta,i=>this._explicitOverrides.add(i));this._inputValues=e.values,this._inputProxy=e.proxy}_getInputProxy(){return this._ensureInputsScanned(),this._inputProxy}_ensurePropsScanned(){if(this._propMeta)return;const e=L_(this.source);this._declarationType=e.type,this._sourcePropArgs=e.args,this._propMeta=j_(e.type);const i=W_(this._propMeta,this._sourcePropArgs,r=>this._explicitPropOverrides.add(r));this._propValues=i.values,this._propProxy=i.proxy}_getPropProxy(){return this._ensurePropsScanned(),this._propProxy}}function z_(t){const e=t.toString();return Sy.some(i=>{const r=i.replace(/\./g,"\\.");return new RegExp(`\\b${r}\\b`).test(e)})}var K_=Object.defineProperty,H_=(t,e,i)=>e in t?K_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,ee=(t,e,i)=>H_(t,typeof e!="symbol"?e+"":e,i);const Hn={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 G_(t){return t?Hn[t]??Hn[t.toUpperCase()]??864e5:864e5}class nn{constructor(e,i,r,n,a,s){this.source=e,this.tickerId=i,this.timeframe=r,this.limit=n,this.sDate=a,this.eDate=s,ee(this,"data",[]),ee(this,"open",[]),ee(this,"high",[]),ee(this,"low",[]),ee(this,"close",[]),ee(this,"volume",[]),ee(this,"hl2",[]),ee(this,"hlc3",[]),ee(this,"ohlc4",[]),ee(this,"hlcc4",[]),ee(this,"openTime",[]),ee(this,"closeTime",[]),ee(this,"_readyPromise",null),ee(this,"_ready",!1),ee(this,"_debugSettings",{ln:!1,debug:!1}),ee(this,"_transpiledCode",null),ee(this,"_currentIndicator",null),ee(this,"_isSecondaryContext",!1),ee(this,"_syminfo"),ee(this,"_chartTimezone",null),ee(this,"_maxLoops",5e5),ee(this,"_alertMode","realtime"),ee(this,"_viewportLeft"),ee(this,"_viewportRight"),ee(this,"_usesVisibleRange",!1),ee(this,"_lastRunViewport",{}),ee(this,"_lastResult",null),ee(this,"_lastPineTSCode",null),this._readyPromise=new Promise(o=>{this.loadMarketData(e,i,r,n,a,s).then(l=>{const c=l;this.data=c;const u=c.map(N=>N.open),p=c.map(N=>N.close),h=c.map(N=>N.high),f=c.map(N=>N.low),d=c.map(N=>N.volume),m=c.map(N=>(N.high+N.low+N.close)/3),x=c.map(N=>(N.high+N.low)/2),b=c.map(N=>(N.high+N.low+N.open+N.close)/4),v=c.map(N=>(N.high+N.low+N.close+N.close)/4),w=c.map(N=>N.openTime),S=G_(this.timeframe),A=c.map(N=>N.closeTime!=null?N.closeTime:N.openTime+S);this.open=u,this.close=p,this.high=h,this.low=f,this.volume=d,this.hl2=x,this.hlc3=m,this.ohlc4=b,this.hlcc4=v,this.openTime=w,this.closeTime=A,e&&e.getSymbolInfo?e.getSymbolInfo(i).then(N=>{this._syminfo=N,this._ready=!0,o(!0)}).catch(N=>{console.warn("Failed to get symbol info, using default values:",N),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,i){this._viewportLeft=e,this._viewportRight=i}usesVisibleRange(){return this._usesVisibleRange}get visibleRangeLeft(){return this._viewportLeft}get visibleRangeRight(){return this._viewportRight}async update(e){const i=e??this._lastPineTSCode;if(!i)throw new Error("pine.update(): pineTSCode is required on the first call.");const r=this._lastResult===null,n=this._viewportLeft!==this._lastRunViewport.left||this._viewportRight!==this._lastRunViewport.right;return r||this._usesVisibleRange&&n?(this._lastPineTSCode=i,this._lastRunViewport={left:this._viewportLeft,right:this._viewportRight},this._lastResult=await this.run(i),this._lastResult):this._lastResult}setDebugSettings({ln:e,debug:i}){this._debugSettings.ln=e,this._debugSettings.debug=i}async loadMarketData(e,i,r,n,a,s){return Array.isArray(e)?e:e.getMarketData(i,r,n,a,s)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,i,r){const n=bi.from(e);if(this._currentIndicator=n,r&&r>0){const a=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(n,i,r,a)}else return this._runComplete(n,i)}stream(e,i={}){const{live:r=!0,interval:n=1e3}=i,a=i.pageSize||this.data.length,s=bi.from(e);this._currentIndicator=s;const o={data:[],error:[],warning:[],alert:[]};let l=!1;const c=(h,...f)=>{o[h]&&o[h].forEach(d=>d(...f))},u=(h,f)=>{o[h]||(o[h]=[]),o[h].push(f)},p=()=>{l=!0};return(async()=>{try{r&&typeof this.eDate<"u"&&(this.eDate=Math.max(this.eDate,Date.now()));const h=!Array.isArray(this.source)&&r,f=this._runPaginated(s,void 0,a,h);for await(const d of f){if(l)break;if(d===null){await new Promise(m=>setTimeout(m,n));continue}if(c("data",d),d.warnings&&d.warnings.length>0){for(const m of d.warnings)c("warning",m);d.warnings.length=0}if(d.alerts&&d.alerts.length>0){for(const m of d.alerts)c("alert",m);d.alerts.length=0}if(h&&!l){const m=d.marketData[d.idx],x=m&&m.closeTime<Date.now(),b=d.idx>=d.marketData.length-1;(!x||b)&&await new Promise(v=>setTimeout(v,n))}}}catch(h){c("error",h)}})(),{on:u,stop:p}}async runPretranspiled(e,i={},r){await this.ready(),r||(r=this.data.length);const n=this._initializeContext(null,i,this._isSecondaryContext);this._transpiledCode=e;const a=e._ltfSlices;return a&&(n._ltfTruncatedBodies=a),await this._executeIterations(n,e,this.data.length-r,this.data.length),n}async _runComplete(e,i){await this.ready(),i||(i=this.data.length);const r=e.prepare(this._debugSettings);this._usesVisibleRange=r.usesVisibleRange;const n=this._initializeContext(e.source??null,r.inputs,this._isSecondaryContext);this._transpiledCode=r.fn,r.ltfSlices&&(n._ltfTruncatedBodies=r.ltfSlices);const a=this.data.length-i,s=this.data.length;return s-a>1?(await this._executeIterations(n,r.fn,a,s-1),n._varSnapshot=this._snapshotVarState(n),await this._executeIterations(n,r.fn,s-1,s)):await this._executeIterations(n,r.fn,a,s),n}async*_runPaginated(e,i,r,n=!1){await this.ready(),i||(i=this.data.length);const a=e.prepare(this._debugSettings);this._usesVisibleRange=a.usesVisibleRange;const s=this._initializeContext(e.source??null,a.inputs,this._isSecondaryContext);this._transpiledCode=a.fn,a.ltfSlices&&(s._ltfTruncatedBodies=a.ltfSlices);let o=this.data.length-i,l=null;for(;;){const c=this.data.length,u=c-o;if(u>0){const m=Math.min(u,r),x=this._getResultLength(s.result),b=o+m;n&&b>=c&&m>1?(await this._executeIterations(s,this._transpiledCode,o,b-1),l=this._snapshotVarState(s),await this._executeIterations(s,this._transpiledCode,b-1,b)):n&&b>=c&&m===1?await this._executeIterations(s,this._transpiledCode,o,b):await this._executeIterations(s,this._transpiledCode,o,b),o+=m,yield this._createPageContext(s,x);continue}if(!n||Array.isArray(this.source))break;const p=Date.now(),{newCandles:h,updatedLastCandle:f}=await this._updateMarketData(),d=Date.now()-p;if(h===0&&!f){yield null;continue}if(h===0&&f&&d<1e3&&await new Promise(m=>setTimeout(m,1e3-d)),s.dataVersion++,s.length=this.data.length,this._restoreVarState(s,l),Array.isArray(s.result))s.result.pop();else if(typeof s.result=="object"&&s.result!==null)for(let m in s.result)Array.isArray(s.result[m])&&s.result[m].pop();s.data.close.data.pop(),s.data.open.data.pop(),s.data.high.data.pop(),s.data.low.data.pop(),s.data.volume.data.pop(),s.data.hl2.data.pop(),s.data.hlc3.data.pop(),s.data.ohlc4.data.pop(),s.data.hlcc4.data.pop(),s.data.openTime.data.pop(),s.data.closeTime&&s.data.closeTime.data.pop(),s.data.bar_index.data.pop(),o=this.data.length-(h+1),s.rollbackDrawings(o),h>0&&(l=null),s.pine.barstate.setLive()}}_getResultLength(e){if(Array.isArray(e))return e.length;if(typeof e=="object"&&e!==null){const i=Object.keys(e);if(i.length>0&&Array.isArray(e[i[0]]))return e[i[0]].length}return 0}_createPageContext(e,i){const r=new wn({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(r.pineTSCode=e.pineTSCode,r.idx=e.idx,Array.isArray(e.result))r.result=e.result.slice(i);else if(typeof e.result=="object"&&e.result!==null){r.result={};for(let n in e.result)Array.isArray(e.result[n])?r.result[n]=e.result[n].slice(i):r.result[n]=e.result[n]}else r.result=e.result;return r.plots={...e.plots},r.warnings=e.warnings,r.alerts=e.alerts,r}async _updateMarketData(e){if(Array.isArray(this.source))return{newCandles:0,updatedLastCandle:!1};const i=this.source,r=this.data.length-1,n=this.data[r].openTime;try{const a=await i.getMarketData(this.tickerId,this.timeframe,void 0,n,e);if(!a||a.length===0)return{newCandles:0,updatedLastCandle:!1};let s=!1,o=0;for(let l=0;l<a.length;l++){const c=a[l];c.openTime===n?(this._replaceCandle(r,c),s=!0):c.openTime>n&&(this._appendCandle(c),o++)}return{newCandles:o,updatedLastCandle:s}}catch(a){return console.error("Error updating market data:",a),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,i){this.data[e]=i,this.open[e]=i.open,this.close[e]=i.close,this.high[e]=i.high,this.low[e]=i.low,this.volume[e]=i.volume,this.hl2[e]=(i.high+i.low)/2,this.hlc3[e]=(i.high+i.low+i.close)/3,this.ohlc4[e]=(i.high+i.low+i.open+i.close)/4,this.hlcc4[e]=(i.high+i.low+i.close+i.close)/4,this.openTime[e]=i.openTime,this.closeTime[e]=i.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;const{newCandles:i,updatedLastCandle:r}=await this._updateMarketData();if(i===0&&!r)return!1;const n=e._varSnapshot;if(n?this._restoreVarState(e,n):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;const a=this.data.length-(i+1);e.rollbackDrawings(a);const s=this.data.length;return a<s-1?(await this._executeIterations(e,this._transpiledCode,a,s-1),e._varSnapshot=this._snapshotVarState(e),await this._executeIterations(e,this._transpiledCode,s-1,s)):await this._executeIterations(e,this._transpiledCode,a,s),!0}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let n in e.result)Array.isArray(e.result[n])&&e.result[n].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();const i=["const","var","let","params"],r=n=>{for(let a of i)if(n[a])for(let s in n[a]){const o=n[a][s];o instanceof y?o.data.pop():Array.isArray(o)&&o.pop()}};r(e),e.lctx&&e.lctx.forEach(n=>r(n))}_snapshotVarState(e){const i=["const","var","let","params"],r={main:{},lctx:[]},n=a=>{const s={};for(const o of i)if(a[o]){s[o]={};for(const l in a[o]){const c=a[o][l];if(c instanceof y){const u=c.data.length,p=u>0?c.data[u-1]:void 0;s[o][l]={len:u,lastVal:p}}}}return s};if(r.main=n(e),e.lctx){const a=[];e.lctx.forEach(s=>a.push(n(s))),r.lctx=a}return r.resultLength=this._getResultLength(e.result),r.dataLength=e.data.close?.data?.length??0,r}_restoreVarState(e,i){if(!i)return;const r=["const","var","let","params"],n=(a,s)=>{for(const o of r)if(!(!s[o]||!a[o]))for(const l in s[o]){const c=a[o][l],u=s[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(n(e,i.main),e.lctx&&i.lctx){let a=0;e.lctx.forEach(s=>{i.lctx[a]&&n(s,i.lctx[a]),a++})}}_initializeContext(e,i={},r=!1){const n=new wn({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:i});return n.pine.syminfo=this._syminfo,this._chartTimezone&&(n.chartTimezone=this._chartTimezone),n.viewportLeft=this._viewportLeft,n.viewportRight=this._viewportRight,n.__maxLoops=this._maxLoops,n._alertMode=this._alertMode,n._propOverrides=this._currentIndicator?.getRuntimePropOverrides()??{},n.pineTSCode=e,n.isSecondaryContext=r,n.data.close=new y([]),n.data.open=new y([]),n.data.high=new y([]),n.data.low=new y([]),n.data.volume=new y([]),n.data.hl2=new y([]),n.data.hlc3=new y([]),n.data.ohlc4=new y([]),n.data.hlcc4=new y([]),n.data.openTime=new y([]),n.data.closeTime=new y([]),n.length=this.data.length,n}async _executeIterations(e,i,r,n){const a=["const","var","let","params"];for(let s=r;s<n;s++){if(e.idx=s,e._execTick=(e._execTick||0)+1,e.data.close.data.push(this.close[s]),e.data.open.data.push(this.open[s]),e.data.high.data.push(this.high[s]),e.data.low.data.push(this.low[s]),e.data.volume.data.push(this.volume[s]),e.data.hl2.data.push(this.hl2[s]),e.data.hlc3.data.push(this.hlc3[s]),e.data.ohlc4.data.push(this.ohlc4[s]),e.data.hlcc4.data.push(this.hlcc4[s]),e.data.openTime.data.push(this.openTime[s]),e.data.closeTime.data.push(this.closeTime[s]),e.data.bar_index.data.push(s),e.strategy){Mp(e),Ep(e),pr(e,"open");const c=Dp(e);c&&pr(e,"extreme"),Pp(e,"intrabar"),c||pr(e,"extreme"),Rp(e)}const o=await i(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(const c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();const l=c=>{for(let u of a)if(c[u])for(let p in c[u]){const h=c[u][p];if(h instanceof y){const f=h.get(0);h.data.push(f)}else if(Array.isArray(h)){const f=h[h.length-1];h.push(f)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}e.strategy&&Op(e)}}const Gn={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},_i={"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},Ag={"1S":{periodType:"second",multiplier:1},"5S":{periodType:"second",multiplier:5},"10S":{periodType:"second",multiplier:10},"15S":{periodType:"second",multiplier:15},"30S":{periodType:"second",multiplier:30},1:{periodType:"minute",multiplier:1},3:{periodType:"minute",multiplier:3},5:{periodType:"minute",multiplier:5},15:{periodType:"minute",multiplier:15},30:{periodType:"minute",multiplier:30},45:{periodType:"minute",multiplier:45},60:{periodType:"hour",multiplier:1},120:{periodType:"hour",multiplier:2},180:{periodType:"hour",multiplier:3},240:{periodType:"hour",multiplier:4},D:{periodType:"day",multiplier:1},W:{periodType:"week",multiplier:1},M:{periodType:"month",multiplier:1}};function gi(t,e,i=1){if(e==="month"){const n=new Date(t);return Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+i,1,n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds())}const r={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+i*r[e]}function ct(t,e,i){const[r,n,a]=t.split("-").map(Number),[s,o]=e.split(":").map(Number),l=Date.UTC(r,n-1,a,s,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:i,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(v=>v.type===b).value,10);let p=u("year"),h=u("month"),f=u("day"),d=u("hour");d===24&&(d=0);let m=u("minute");const x=Date.UTC(p,h-1,f,d,m,0,0)-l;return l-x}function Yn(t,e,i,r,n=1){if(e==="24x7")return gi(t,r,n);const a=e.split("-")[1];if(!a||a.length!==4)return gi(t,r,n);const s=a.slice(0,2),o=a.slice(2,4),l=`${s}:${o}`,c=Xn(t,i);if(r==="second"||r==="minute"||r==="hour"){const u=t+n*{second:1e3,minute:6e4,hour:36e5}[r],p=ct(c,l,i);return Math.min(u,p)}if(r==="day")return ct(c,l,i);if(r==="week"){const u=new Date(t).getUTCDay(),p=u<=5?5-u:5-u+7,h=t+p*864e5,f=Xn(h,i);return ct(f,l,i)}if(r==="month"){const u=new Date(t),p=u.getUTCFullYear(),h=u.getUTCMonth()+n,f=new Date(Date.UTC(p,h,1)),d=new Date(f.getTime()-864e5);for(;d.getUTCDay()===0||d.getUTCDay()===6;)d.setUTCDate(d.getUTCDate()-1);const m=d.toISOString().split("T")[0];return ct(m,l,i)}return gi(t,r,n)}function Xn(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function Y_(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)}const X_=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function Q_(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;const i=_i[t];if(!i)return null;const r=X_.filter(n=>n!=="W"&&n!=="M"&&e.has(n)&&_i[n]<i&&i%_i[n]===0);return r.length===0?null:r[r.length-1]}function Fa(t,e){if(t==="W"||t==="M")return 1/0;const i=_i[t],r=_i[e];return!i||!r||r===0?1/0:i/r}function Z_(t,e,i){if(t.length===0)return[];if(e==="W")return eg(t);if(e==="M")return tg(t);const r=Fa(e,i);return J_(t,r)}function J_(t,e){if(t.length===0)return[];const i=[];let r=[t[0]];const n=ig(t),a=n>0?n*1.5:0;for(let s=1;s<t.length;s++){const o=t[s].openTime-t[s-1].openTime;(a>0&&o>a||r.length>=e)&&(i.push(Zi(r)),r=[]),r.push(t[s])}return r.length>0&&i.push(Zi(r)),i}function eg(t){const e=[];let i=[],r="";for(const n of t){const a=rg(n.openTime);a!==r&&i.length>0&&(e.push(i),i=[]),r=a,i.push(n)}return i.length>0&&e.push(i),e.map(Zi)}function tg(t){const e=[];let i=[],r="";for(const n of t){const a=new Date(n.openTime),s=`${a.getUTCFullYear()}-${a.getUTCMonth()}`;s!==r&&i.length>0&&(e.push(i),i=[]),r=s,i.push(n)}return i.length>0&&e.push(i),e.map(Zi)}function Zi(t){const e=t[0],i=t[t.length-1];let r=e.high,n=e.low,a=0,s=0,o=0,l=0,c=0;for(let u=0;u<t.length;u++){const p=t[u];p.high>r&&(r=p.high),p.low<n&&(n=p.low),a+=p.volume,s+=p.quoteAssetVolume,o+=p.numberOfTrades,l+=p.takerBuyBaseAssetVolume,c+=p.takerBuyQuoteAssetVolume}return{openTime:e.openTime,open:e.open,high:r,low:n,close:i.close,volume:a,closeTime:i.closeTime,quoteAssetVolume:s,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function ig(t){if(t.length<2)return 0;const e=Math.min(t.length-1,20);let i=1/0;for(let r=0;r<e;r++){const n=t[r+1].openTime-t[r].openTime;n>0&&n<i&&(i=n)}return i===1/0?0:i}function rg(t){const e=new Date(t),i=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-i);const r=new Date(Date.UTC(e.getUTCFullYear(),0,1)),n=Math.ceil(((e.getTime()-r.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${n}`}var ng=Object.defineProperty,sg=(t,e,i)=>e in t?ng(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Pi=(t,e,i)=>sg(t,typeof e!="symbol"?e+"":e,i);const Mi={"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 ag(t){if(Mi[t]!==void 0)return Mi[t];const e=t.toLowerCase();return Mi[e]!==void 0?Mi[e]:/^\d+$/.test(t)?t:/^\d+S$/i.test(t)?t.toUpperCase():t}class sn{constructor(e){Pi(this,"_configured"),Pi(this,"_requiresApiKey"),Pi(this,"_providerName"),Pi(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){Y_(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,i,r,n,a){const s=ag(i),o=this.getSupportedTimeframes();if(o.has(s))return this._getMarketDataNative(e,s,r,n,a);const l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:Q_(s,o);if(!c)return console.error(`${this._providerName}: Timeframe '${i}' is not supported and no valid sub-timeframe found for aggregation.`),[];const u=this._computeSubLimit(s,c,r),p=await this._getMarketDataNative(e,c,u,n,a);if(p.length===0)return[];const h=Z_(p,s,c);return r&&r>0&&h.length>r?h.slice(h.length-r):h}_computeSubLimit(e,i,r){if(!r)return;const n=Fa(e,i);return n===1/0?e==="W"?r*7+14:e==="M"?r*31+31:r*30:Math.ceil(r*n)+Math.ceil(n)}}var og=Object.defineProperty,lg=(t,e,i)=>e in t?og(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ji=(t,e,i)=>lg(t,typeof e!="symbol"?e+"":e,i);const br="https://api.binance.com/api/v3",Qn="https://api.binance.us/api/v3",Di={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"};class cg{constructor(e=300*1e3){Ji(this,"cache"),Ji(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([i,r])=>r!==void 0).map(([i,r])=>`${i}:${r}`).join("|")}get(e){const i=this.generateKey(e),r=this.cache.get(i);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(i),null):r.data:null}set(e,i){const r=this.generateKey(e);this.cache.set(r,{data:i,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const e=Date.now();for(const[i,r]of this.cache.entries())e-r.timestamp>this.cacheDuration&&this.cache.delete(i)}}class ug extends sn{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),Ji(this,"cacheManager"),Ji(this,"activeApiUrl",null),this.cacheManager=new cg(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${br}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=br,this.activeApiUrl}catch{}try{const e=new AbortController,i=setTimeout(()=>e.abort(),5e3),r=await fetch(`${Qn}/ping`,{signal:e.signal});if(clearTimeout(i),r.ok)return this.activeApiUrl=Qn,this.activeApiUrl}catch{}return br}async _fetchRawChunk(e,i,r,n,a){const s=Di[i.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${i}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${s}`;r&&(o+=`&limit=${Math.min(r,1e3)}`),n&&(o+=`&startTime=${n}`),a&&(o+=`&endTime=${a}`);const 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,i,r,n){try{const a=Di[i.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${i}`),[];let s=[],o=r;const l=n,c=Gn[a];if(!c)return console.error(`Duration not defined for interval: ${a}`),[];for(;o<l;){const u=Math.min(o+1e3*c,l),p=await this._fetchRawChunk(e,i,1e3,o,u);if(p.length===0)break;s=s.concat(p),o=p[p.length-1].closeTime+1}return this.normalizeCloseTime(s),s}catch(a){return console.error("Error in getMarketDataInterval:",a),[]}}async getMarketDataBackwards(e,i,r,n){let a=r,s=[],o=n,l=0;const c=Math.ceil(r/1e3)+5;for(;a>0&&l<c;){l++;const u=Math.min(a,1e3),p=await this._fetchRawChunk(e,i,u,void 0,o);if(p.length===0||(s=p.concat(s),a-=p.length,o=p[0].openTime-1,p.length<u))break}return this.normalizeCloseTime(s),s}getSupportedTimeframes(){return new Set(["1","3","5","15","30","60","120","240","D","W","M"])}async _getMarketDataNative(e,i,r,n,a){try{const s=a!==void 0,o={tickerId:e,timeframe:i,limit:r,sDate:n,eDate:a};if(s){const c=this.cacheManager.get(o);if(c)return c}if(!Di[i.toUpperCase()])return console.error(`Unsupported timeframe: ${i}`),[];if(this.shouldPaginate(i,r,n,a)){if(n&&a){const c=await this.getMarketDataInterval(e,i,n,a),u=r?c.slice(0,r):c;return this.cacheManager.set(o,u),u}else if(r&&r>1e3){const c=await this.getMarketDataBackwards(e,i,r,a);return this.cacheManager.set(o,c),c}}const l=await this._fetchRawChunk(e,i,r,n,a);return this.normalizeCloseTime(l),s&&this.cacheManager.set(o,l),l}catch(s){return console.error("Error in binance.klines:",s),[]}}shouldPaginate(e,i,r,n){if(i&&i>1e3)return!0;if(r&&n){const a=Di[e.toUpperCase()],s=Gn[a];if(s)return Math.ceil((n-r)/s)>1e3}return!1}async getSymbolInfo(e){try{let i="crypto",r=await this.getBaseUrl(),n=e,a="";e.endsWith(".P")?(i="futures",n=e.replace(".P",""),r="https://fapi.binance.com/fapi/v1",a="Perpetual"):e.includes("_")&&(i="futures",n=e,r="https://dapi.binance.com/dapi/v1",a="Delivery");const s=i==="crypto"?`${r}/exchangeInfo?symbol=${n}`:`${r}/exchangeInfo`,o=await fetch(s);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;const c=i==="futures"?l.find(w=>w.symbol===n):l[0];if(!c)return console.error(`Symbol ${n} not found in exchange info`),null;const u=c.filters?.find(w=>w.filterType==="PRICE_FILTER"),p=c.filters?.find(w=>w.filterType==="LOT_SIZE"),h=u?parseFloat(u.tickSize):.01,f=p?parseFloat(p.minQty):0,d=Math.round(1/h),m=c.baseAsset,x=c.quoteAsset,b=a?` ${a}`:"",v=`${m} / ${x}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:m,description:v,type:i,main_tickerid:`BINANCE:${e}`,current_contract:a,isin:"",basecurrency:m,currency:x,timezone:"Etc/UTC",country:"",mintick:h,pricescale:d,minmove:1,pointvalue:c.contractSize||1,mincontract:f,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(i){return console.error("Error in binance.exchangeInfo:",i),null}}}var hg=Object.defineProperty,pg=(t,e,i)=>e in t?hg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,li=(t,e,i)=>pg(t,typeof e!="symbol"?e+"":e,i);const fg="https://financialmodelingprep.com",Zn=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"]),Jn={"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"}},es={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"},ts={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"},dg={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}};class mg extends sn{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),li(this,"_apiKey",null),li(this,"_baseUrl",fg),li(this,"_profileCache",new Map),li(this,"_symbolInfoCache",new Map),li(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,i,r,n,a){this.ensureConfigured();try{const s=i.toUpperCase(),o=Jn[s]||Jn[i];if(!o)return console.error(`FMP: Unsupported timeframe: ${i}`),[];let l;if(o.type==="intraday"?l=await this._fetchIntradayData(e,o.endpoint,o.interval,n,a,r):l=await this._fetchDailyData(e,n,a,r),l.length>0&&!this._mintickCache.has(e)){const c=this._estimateMintick(l);c!==void 0&&this._mintickCache.set(e,c)}return l}catch(s){return console.error("Error in FMPProvider.getMarketData:",s),[]}}async _fetchDailyData(e,i,r,n){let a=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;i&&(a+=`&from=${this._msToDateStr(i)}`),r&&(a+=`&to=${this._msToDateStr(r)}`);const s=await fetch(a);if(!s.ok){const p=await s.text();throw new Error(`FMP HTTP ${s.status}: ${p}`)}const o=await s.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();const l=n&&n>0&&n<o.length?o.slice(o.length-n):o,{session:c,timezone:u}=await this._resolveSessionInfo(e);return l.map(p=>{const h=this._dateStrToMs(p.date),f=Yn(h,c,u,"day");return{openTime:h,open:p.open,high:p.high,low:p.low,close:p.close,volume:p.volume,closeTime:f,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,i,r,n,a,s){let o=`${this._baseUrl}${i}?symbol=${e}&apikey=${this._apiKey}`;n&&(o+=`&from=${this._msToDateStr(n)}`),a&&(o+=`&to=${this._msToDateStr(a)}`);const l=await fetch(o);if(!l.ok){const m=await l.text();if(l.status===403||m.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${r}) 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}`)}const c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();const u=s&&s>0&&s<c.length?c.slice(c.length-s):c,{periodType:p,multiplier:h}=dg[r]||{periodType:"minute",multiplier:1},{session:f,timezone:d}=await this._resolveSessionInfo(e);return u.map(m=>{const x=this._dateTimeStrToMs(m.date),b=Yn(x,f,d,p,h);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(),this._symbolInfoCache.has(e))return this._symbolInfoCache.get(e);try{const i=await this._fetchProfile(e);let r="stock";i?.isEtf?r="etf":i?.isFund?r="fund":this._isForex(e)?r="forex":this._isCrypto(e)&&(r="crypto");const n=i?.exchange||(r==="crypto"?"CRYPTO":r==="forex"?"FX":""),a=r==="crypto"||r==="forex"?"Etc/UTC":es[n]||"America/New_York",s=r==="crypto"?"24x7":r==="forex"?"0000-0000":ts[n]||"0930-1600",o=i?.currency||(this._isForex(e)?e.slice(3,6):"USD"),l=this._isForex(e)?e.slice(0,3):i?.currency||"USD",c=this._mintickCache.get(e)??.01,u=Math.round(1/c),p=Math.round(c*u),h={ticker:i?.symbol||e,tickerid:`${n}:${i?.symbol||e}`,prefix:n,root:i?.symbol||e,description:i?.companyName||e,type:r,main_tickerid:`${n}:${i?.symbol||e}`,current_contract:"",isin:i?.isin||"",basecurrency:l,currency:o,timezone:a,country:i?.country||"",mintick:c,pricescale:u,minmove:p,pointvalue:1,mincontract:0,session:s,volumetype:"base",expiration_date:0,employees:i&&parseInt(i.fullTimeEmployees)||0,industry:i?.industry||"",sector:i?.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,h),h}catch(i){return console.error("Error in FMPProvider.getSymbolInfo:",i),null}}_estimateMintick(e){const i=[];for(let o=0;o<e.length;o++){const l=e[o],c=Math.abs(l.close-l.open),u=Math.abs(l.high-l.low);if(c>0&&i.push(c),u>0&&i.push(u),o>0){const p=Math.abs(l.close-e[o-1].close);p>0&&i.push(p)}}if(i.length===0)return;const r=Math.min(...i),n=Math.floor(Math.log10(r)),a=r/10**n,s=(Math.floor(a+1e-12)<5?1:10)*10**n;return s>=1?.01:s}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);const i=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,r=await fetch(i);if(!r.ok)return null;const n=await r.json();if(!Array.isArray(n)||n.length===0)return null;const a=n[0];return this._profileCache.set(e,a),a}async _resolveSessionInfo(e){try{const i=await this._fetchProfile(e);if(i){const r=i.exchange||"",n=this._isCrypto(e),a=n?"Etc/UTC":es[r]||"America/New_York";return{session:n?"24x7":ts[r]||"0930-1600",timezone:a}}}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)&&Zn.has(e.slice(0,3))&&Zn.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}}var yg=Object.defineProperty,_g=(t,e,i)=>e in t?yg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Mt=(t,e,i)=>_g(t,typeof e!="symbol"?e+"":e,i);const gg="https://data.alpaca.markets",xg="https://paper-api.alpaca.markets/v2",bg="https://api.alpaca.markets/v2",vr=1e4,is={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"},vg={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"},wg={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},Sg={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"};class Eg extends sn{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),Mt(this,"_apiKey",null),Mt(this,"_apiSecret",null),Mt(this,"_dataUrl",gg),Mt(this,"_tradingUrl",xg),Mt(this,"_feed",null),Mt(this,"_assetCache",new Map),Mt(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=bg)}_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,i,r,n,a){this.ensureConfigured();try{const s=this._resolveTimeframe(i);if(!s)return console.error(`Alpaca: Unsupported timeframe: ${i}`),[];const o=this._isCrypto(e),l=await this._fetchAllBars(e,s,o,n,a,r);if(l.length===0)return[];const{periodType:c,multiplier:u}=this._parseAlpacaTimeframe(s);if(o)return this._convertBarsCrypto(l,c,u);const p=l[0].t.slice(0,10),h=l[l.length-1].t.slice(0,10),f=this._addDaysToDate(h,40);return await this._ensureCalendar(p,f),this._convertBarsStock(l,c,u)}catch(s){return console.error("Error in AlpacaProvider.getMarketData:",s),[]}}async _fetchAllBars(e,i,r,n,a,s){const o=[];let l=null;const c=s||1/0,u=Math.min(s||vr,vr);do{const p=this._buildBarsUrl(e,i,r,n,a,u,l),h=await fetch(p,{headers:this._headers()});if(!h.ok){const m=await h.text();throw new Error(`Alpaca HTTP ${h.status}: ${m}`)}const f=await h.json(),d=Object.keys(f.bars||{})[0];if(!d||!f.bars[d]||(o.push(...f.bars[d]),l=f.next_page_token,o.length>=c))break}while(l);return s&&s>0&&o.length>s?o.slice(0,s):o}_buildBarsUrl(e,i,r,n,a,s,o){const l=r?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",i),c.set("sort","asc"),n&&c.set("start",new Date(n).toISOString()),a&&c.set("end",new Date(a).toISOString()),s&&c.set("limit",String(Math.min(s,vr))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured();try{const i=await this._fetchAsset(e);if(!i)return console.error(`Alpaca: Symbol ${e} not found`),null;const r=i.exchange||"",n=i.class==="crypto",a=n?"Etc/UTC":vg[r]||"America/New_York",s=n?"24x7":wg[r]||"0930-1600";let o="stock";n&&(o="crypto");const l=n&&e.split("/")[1]||"USD",c=n?e.split("/")[0]||e:l,u=i.price_increment?parseFloat(i.price_increment):.01,p=Math.round(1/u);return{ticker:i.symbol,tickerid:`${r}:${i.symbol}`,prefix:r,root:n?e.split("/")[0]:i.symbol,description:i.name||i.symbol,type:o,main_tickerid:`${r}:${i.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:a,country:n?"":"US",mintick:u,pricescale:p,minmove:1,pointvalue:1,mincontract:i.min_order_size?parseFloat(i.min_order_size):0,session:s,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(i){return console.error("Error in AlpacaProvider.getSymbolInfo:",i),null}}_convertBarsCrypto(e,i,r){return e.map((n,a,s)=>{const o=new Date(n.t).getTime(),l=a<s.length-1?new Date(s[a+1].t).getTime():gi(o,i,r);return this._toKline(n,o,l)})}_convertBarsStock(e,i,r){const n="America/New_York";return e.map(a=>{const s=new Date(a.t).getTime(),o=a.t.slice(0,10);let l;if(i==="day"){const c=this._calendarCache.get(o),u=c?c.close:"16:00";l=ct(o,u,n)}else if(i==="minute"||i==="hour"){const c=s+r*{minute:6e4,hour:36e5}[i],u=this._calendarCache.get(o),p=u?u.close:"16:00",h=ct(o,p,n);l=Math.min(c,h)}else i==="week"?l=this._weeklyCloseFromCalendar(o,n):i==="month"?l=this._monthlyCloseFromCalendar(o,n):l=gi(s,i,r);return this._toKline(a,s,l)})}_toKline(e,i,r){return{openTime:i,open:e.o,high:e.h,low:e.l,close:e.c,volume:e.v,closeTime:r,quoteAssetVolume:0,numberOfTrades:e.n,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}}_weeklyCloseFromCalendar(e,i){const r=new Date(e+"T00:00:00Z"),n=r.getUTCDay(),a=n<=5?5-n:5-n+7;for(let l=a;l>=0;l--){const c=r.getTime()+l*864e5,u=new Date(c).toISOString().split("T")[0],p=this._calendarCache.get(u);if(p)return ct(u,p.close,i)}const s=r.getTime()+a*864e5,o=new Date(s).toISOString().split("T")[0];return ct(o,"16:00",i)}_monthlyCloseFromCalendar(e,i){const[r,n]=e.split("-").map(Number),a=new Date(Date.UTC(r,n,0)).getUTCDate();for(let o=a;o>=1;o--){const l=`${r}-${String(n).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return ct(l,c.close,i)}const s=new Date(Date.UTC(r,n,0));for(;s.getUTCDay()===0||s.getUTCDay()===6;)s.setUTCDate(s.getUTCDate()-1);return ct(s.toISOString().split("T")[0],"16:00",i)}async _ensureCalendar(e,i){if(this._calendarCache.has(e)&&this._calendarCache.has(i))return;const r=`${this._tradingUrl}/calendar?start=${e}&end=${i}`,n=await fetch(r,{headers:this._headers()});if(!n.ok){console.warn(`Alpaca calendar API returned ${n.status}, falling back to defaults`);return}const a=await n.json();for(const s of a)this._calendarCache.set(s.date,s)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);const i=encodeURIComponent(e),r=`${this._tradingUrl}/assets/${i}`,n=await fetch(r,{headers:this._headers()});if(!n.ok)return null;const a=await n.json();return this._assetCache.set(e,a),a}_parseAlpacaTimeframe(e){const i=e.match(/^(\d+)(Min|Hour|Day|Week|Month)$/);if(i){const r=parseInt(i[1],10),n=Sg[i[2]];if(n)return{periodType:n,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return is[e.toUpperCase()]||is[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,i){const r=new Date(e+"T00:00:00Z");return r.setUTCDate(r.getUTCDate()+i),r.toISOString().split("T")[0]}}class Ng{async getMarketData(){return[]}}const Cg=typeof process<"u"&&process.versions&&process.versions.node;let er=null;if(Cg)try{er=new Ng}catch{er=null}const Pg={Binance:new ug,FMP:new mg,Alpaca:new Eg,...er?{Mock:er}:{}};var Ig=Object.defineProperty,kg=(t,e,i)=>e in t?Ig(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Tg=(t,e,i)=>kg(t,typeof e!="symbol"?e+"":e,i);class Mg extends Error{constructor(e,i){super(e),Tg(this,"method"),this.name="PineRuntimeError",this.method=i}}export{Eg as AlpacaProvider,sn as BaseProvider,ug as BinanceProvider,wn as Context,mg as FMPProvider,Va as INDICATOR_PROPS,bi as Indicator,Mg as PineRuntimeError,nn as PineTS,Pg as Provider,ja as STRATEGY_PROPS,Ag as TIMEFRAME_PERIOD_INFO,_i as TIMEFRAME_SECONDS,Z_ as aggregateCandles,gi as computeNextPeriodStart,Yn as computeSessionClose,Fa as getAggregationRatio,ct as localTimeToUTC,j_ as propsForDeclaration,Q_ as selectSubTimeframe};
125
125
  //# sourceMappingURL=pinets.min.browser.es.js.map